@lakuna/umath 1.3.4 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +7 -9
- package/dist/algorithms/combinations.d.ts +7 -0
- package/dist/algorithms/combinations.d.ts.map +1 -1
- package/dist/algorithms/combinations.js +8 -1
- package/dist/algorithms/combinations.js.map +1 -1
- package/dist/algorithms/degreesToRadians.d.ts +7 -0
- package/dist/algorithms/degreesToRadians.d.ts.map +1 -1
- package/dist/algorithms/degreesToRadians.js +7 -0
- package/dist/algorithms/degreesToRadians.js.map +1 -1
- package/dist/algorithms/factorial.d.ts +6 -0
- package/dist/algorithms/factorial.d.ts.map +1 -1
- package/dist/algorithms/factorial.js +15 -5
- package/dist/algorithms/factorial.js.map +1 -1
- package/dist/algorithms/fibonacci.d.ts +6 -1
- package/dist/algorithms/fibonacci.d.ts.map +1 -1
- package/dist/algorithms/fibonacci.js +6 -1
- package/dist/algorithms/fibonacci.js.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.d.ts +14 -0
- package/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.js +7 -9
- package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
- package/dist/algorithms/hypergeometricPmf.d.ts +9 -0
- package/dist/algorithms/hypergeometricPmf.d.ts.map +1 -1
- package/dist/algorithms/hypergeometricPmf.js +10 -1
- package/dist/algorithms/hypergeometricPmf.js.map +1 -1
- package/dist/algorithms/isPrime.d.ts +6 -0
- package/dist/algorithms/isPrime.d.ts.map +1 -1
- package/dist/algorithms/isPrime.js +8 -1
- package/dist/algorithms/isPrime.js.map +1 -1
- package/dist/algorithms/permutations.d.ts +7 -0
- package/dist/algorithms/permutations.d.ts.map +1 -1
- package/dist/algorithms/permutations.js +8 -1
- package/dist/algorithms/permutations.js.map +1 -1
- package/dist/algorithms/primeFactorization.d.ts +7 -1
- package/dist/algorithms/primeFactorization.d.ts.map +1 -1
- package/dist/algorithms/primeFactorization.js +10 -3
- package/dist/algorithms/primeFactorization.js.map +1 -1
- package/dist/algorithms/radiansToDegrees.d.ts +7 -0
- package/dist/algorithms/radiansToDegrees.d.ts.map +1 -1
- package/dist/algorithms/radiansToDegrees.js +7 -0
- package/dist/algorithms/radiansToDegrees.js.map +1 -1
- package/dist/algorithms/summation.d.ts +8 -0
- package/dist/algorithms/summation.d.ts.map +1 -1
- package/dist/algorithms/summation.js +9 -0
- package/dist/algorithms/summation.js.map +1 -1
- package/dist/index.d.ts +32 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -27
- package/dist/index.js.map +1 -1
- package/dist/linalg/DualQuaternion.d.ts +460 -83
- package/dist/linalg/DualQuaternion.d.ts.map +1 -1
- package/dist/linalg/DualQuaternion.js +514 -133
- package/dist/linalg/DualQuaternion.js.map +1 -1
- package/dist/linalg/Matrix.d.ts +80 -12
- package/dist/linalg/Matrix.d.ts.map +1 -1
- package/dist/linalg/Matrix2.d.ts +337 -52
- package/dist/linalg/Matrix2.d.ts.map +1 -1
- package/dist/linalg/Matrix2.js +345 -61
- package/dist/linalg/Matrix2.js.map +1 -1
- package/dist/linalg/Matrix3.d.ts +470 -72
- package/dist/linalg/Matrix3.d.ts.map +1 -1
- package/dist/linalg/Matrix3.js +488 -94
- package/dist/linalg/Matrix3.js.map +1 -1
- package/dist/linalg/Matrix4.d.ts +842 -137
- package/dist/linalg/Matrix4.d.ts.map +1 -1
- package/dist/linalg/Matrix4.js +896 -175
- package/dist/linalg/Matrix4.js.map +1 -1
- package/dist/linalg/Quaternion.d.ts +395 -70
- package/dist/linalg/Quaternion.d.ts.map +1 -1
- package/dist/linalg/Quaternion.js +416 -70
- package/dist/linalg/Quaternion.js.map +1 -1
- package/dist/linalg/SlowMatrix.d.ts +79 -9
- package/dist/linalg/SlowMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowMatrix.js +147 -27
- package/dist/linalg/SlowMatrix.js.map +1 -1
- package/dist/linalg/SlowSquareMatrix.d.ts +58 -3
- package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowSquareMatrix.js +111 -21
- package/dist/linalg/SlowSquareMatrix.js.map +1 -1
- package/dist/linalg/SquareMatrix.d.ts +26 -3
- package/dist/linalg/SquareMatrix.d.ts.map +1 -1
- package/dist/linalg/Vector.d.ts +148 -24
- package/dist/linalg/Vector.d.ts.map +1 -1
- package/dist/linalg/Vector2.d.ts +484 -84
- package/dist/linalg/Vector2.d.ts.map +1 -1
- package/dist/linalg/Vector2.js +487 -71
- package/dist/linalg/Vector2.js.map +1 -1
- package/dist/linalg/Vector3.d.ts +582 -98
- package/dist/linalg/Vector3.d.ts.map +1 -1
- package/dist/linalg/Vector3.js +625 -134
- package/dist/linalg/Vector3.js.map +1 -1
- package/dist/linalg/Vector4.d.ts +450 -75
- package/dist/linalg/Vector4.d.ts.map +1 -1
- package/dist/linalg/Vector4.js +447 -62
- package/dist/linalg/Vector4.js.map +1 -1
- package/dist/types/AxisAngle.d.ts +4 -1
- package/dist/types/AxisAngle.d.ts.map +1 -1
- package/dist/types/FieldOfView.d.ts +5 -0
- package/dist/types/FieldOfView.d.ts.map +1 -1
- package/dist/utility/BigNumber.d.ts +41 -8
- package/dist/utility/BigNumber.d.ts.map +1 -1
- package/dist/utility/BigNumber.js +47 -5
- package/dist/utility/BigNumber.js.map +1 -1
- package/dist/utility/MagnitudeError.d.ts +5 -0
- package/dist/utility/MagnitudeError.d.ts.map +1 -1
- package/dist/utility/MagnitudeError.js +6 -1
- package/dist/utility/MagnitudeError.js.map +1 -1
- package/dist/utility/MatrixSizeError.d.ts +5 -0
- package/dist/utility/MatrixSizeError.d.ts.map +1 -1
- package/dist/utility/MatrixSizeError.js +5 -0
- package/dist/utility/MatrixSizeError.js.map +1 -1
- package/dist/utility/PartialMatrixError.d.ts +5 -0
- package/dist/utility/PartialMatrixError.d.ts.map +1 -1
- package/dist/utility/PartialMatrixError.js +5 -0
- package/dist/utility/PartialMatrixError.js.map +1 -1
- package/dist/utility/SingularMatrixError.d.ts +8 -0
- package/dist/utility/SingularMatrixError.d.ts.map +1 -1
- package/dist/utility/SingularMatrixError.js +8 -0
- package/dist/utility/SingularMatrixError.js.map +1 -1
- package/dist/utility/epsilon.d.ts +1 -0
- package/dist/utility/epsilon.d.ts.map +1 -1
- package/dist/utility/epsilon.js +1 -0
- package/dist/utility/epsilon.js.map +1 -1
- package/package.json +20 -51
- package/src/algorithms/combinations.ts +4 -4
- package/src/algorithms/degreesToRadians.ts +3 -3
- package/src/algorithms/factorial.ts +13 -8
- package/src/algorithms/fibonacci.ts +3 -3
- package/src/algorithms/greatestCommonDivisor.ts +15 -19
- package/src/algorithms/hypergeometricPmf.ts +5 -6
- package/src/algorithms/isPrime.ts +4 -4
- package/src/algorithms/permutations.ts +4 -4
- package/src/algorithms/primeFactorization.ts +9 -9
- package/src/algorithms/radiansToDegrees.ts +3 -3
- package/src/algorithms/summation.ts +5 -5
- package/src/index.ts +35 -33
- package/src/linalg/DualQuaternion.ts +558 -804
- package/src/linalg/Matrix.ts +35 -36
- package/src/linalg/Matrix2.ts +277 -413
- package/src/linalg/Matrix3.ts +532 -737
- package/src/linalg/Matrix4.ts +1078 -1604
- package/src/linalg/Quaternion.ts +415 -690
- package/src/linalg/SlowMatrix.ts +118 -69
- package/src/linalg/SlowSquareMatrix.ts +85 -56
- package/src/linalg/SquareMatrix.ts +7 -7
- package/src/linalg/Vector.ts +71 -70
- package/src/linalg/Vector2.ts +380 -576
- package/src/linalg/Vector3.ts +544 -840
- package/src/linalg/Vector4.ts +383 -549
- package/src/types/AxisAngle.ts +1 -1
- package/src/utility/BigNumber.ts +33 -42
- package/src/utility/MagnitudeError.ts +4 -4
- package/src/utility/MatrixSizeError.ts +2 -3
- package/src/utility/PartialMatrixError.ts +2 -3
- package/src/utility/SingularMatrixError.ts +2 -2
- package/src/utility/epsilon.ts +1 -4
- package/dist/types/IntegerRepresentation.d.ts +0 -2
- package/dist/types/IntegerRepresentation.d.ts.map +0 -1
- package/dist/types/IntegerRepresentation.js +0 -2
- package/dist/types/IntegerRepresentation.js.map +0 -1
- package/src/types/IntegerRepresentation.ts +0 -2
package/src/types/AxisAngle.ts
CHANGED
package/src/utility/BigNumber.ts
CHANGED
|
@@ -1,33 +1,22 @@
|
|
|
1
|
-
import greatestCommonDivisor from "
|
|
2
|
-
import type { IntegerRepresentation } from "#IntegerRepresentation";
|
|
1
|
+
import greatestCommonDivisor from "../algorithms/greatestCommonDivisor.js";
|
|
3
2
|
|
|
4
3
|
/** A number with no maximum precise size. */
|
|
5
4
|
export default class BigNumber {
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @param
|
|
9
|
-
|
|
10
|
-
public constructor(source?: IntegerRepresentation);
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Creates a number from a fraction.
|
|
14
|
-
* @param dividend The dividend of the fraction.
|
|
15
|
-
* @param divisor The divisor of the fraction.
|
|
6
|
+
* Create a number.
|
|
7
|
+
* @param dividend - The dividend of the number.
|
|
8
|
+
* @param divisor - The divisor of the number.
|
|
16
9
|
*/
|
|
17
10
|
public constructor(
|
|
18
|
-
dividend
|
|
19
|
-
divisor
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
public constructor(
|
|
23
|
-
dividend: IntegerRepresentation = 0,
|
|
24
|
-
divisor: IntegerRepresentation = 1
|
|
11
|
+
dividend: bigint | boolean | number | string = 0,
|
|
12
|
+
divisor: bigint | boolean | number | string = 1
|
|
25
13
|
) {
|
|
26
|
-
|
|
27
|
-
this.divisor = BigInt(divisor);
|
|
28
|
-
if (!this.divisor) {
|
|
14
|
+
if (divisor === 0) {
|
|
29
15
|
throw new Error("Cannot divide by zero.");
|
|
30
16
|
}
|
|
17
|
+
|
|
18
|
+
this.dividend = BigInt(dividend);
|
|
19
|
+
this.divisor = BigInt(divisor);
|
|
31
20
|
this.simplify();
|
|
32
21
|
}
|
|
33
22
|
|
|
@@ -37,16 +26,19 @@ export default class BigNumber {
|
|
|
37
26
|
/** The divisor of this fraction. */
|
|
38
27
|
public divisor: bigint;
|
|
39
28
|
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Simplify this fraction.
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
private simplify() {
|
|
34
|
+
// Switch signs such that only the dividend can be negative.
|
|
43
35
|
if (this.divisor < 0) {
|
|
44
36
|
this.dividend = -this.dividend;
|
|
45
37
|
this.divisor = -this.divisor;
|
|
46
38
|
}
|
|
47
39
|
|
|
48
40
|
// Divide both by their greatest common divisor.
|
|
49
|
-
const gcd
|
|
41
|
+
const gcd = greatestCommonDivisor(this.dividend, this.divisor);
|
|
50
42
|
if (gcd > 1) {
|
|
51
43
|
this.dividend /= gcd;
|
|
52
44
|
this.divisor /= gcd;
|
|
@@ -54,11 +46,11 @@ export default class BigNumber {
|
|
|
54
46
|
}
|
|
55
47
|
|
|
56
48
|
/**
|
|
57
|
-
*
|
|
58
|
-
* @param n The other number.
|
|
49
|
+
* Add a number to this number.
|
|
50
|
+
* @param n - The other number.
|
|
59
51
|
* @returns This number.
|
|
60
52
|
*/
|
|
61
|
-
public add(n:
|
|
53
|
+
public add(n: bigint | boolean | number | string | BigNumber): this {
|
|
62
54
|
if (n instanceof BigNumber) {
|
|
63
55
|
this.dividend = this.dividend * n.divisor + n.dividend * this.divisor;
|
|
64
56
|
this.divisor *= n.divisor;
|
|
@@ -71,11 +63,11 @@ export default class BigNumber {
|
|
|
71
63
|
}
|
|
72
64
|
|
|
73
65
|
/**
|
|
74
|
-
*
|
|
75
|
-
* @param n The other number.
|
|
66
|
+
* Subtract a number from this number.
|
|
67
|
+
* @param n - The other number.
|
|
76
68
|
* @returns This number.
|
|
77
69
|
*/
|
|
78
|
-
public subtract(n:
|
|
70
|
+
public subtract(n: bigint | boolean | number | string | BigNumber): this {
|
|
79
71
|
if (n instanceof BigNumber) {
|
|
80
72
|
this.dividend = this.dividend * n.divisor - n.dividend * this.divisor;
|
|
81
73
|
this.divisor *= n.divisor;
|
|
@@ -88,11 +80,11 @@ export default class BigNumber {
|
|
|
88
80
|
}
|
|
89
81
|
|
|
90
82
|
/**
|
|
91
|
-
*
|
|
92
|
-
* @param n The other number.
|
|
83
|
+
* Multiply this number by a number.
|
|
84
|
+
* @param n - The other number.
|
|
93
85
|
* @returns This number.
|
|
94
86
|
*/
|
|
95
|
-
public multiply(n:
|
|
87
|
+
public multiply(n: bigint | boolean | number | string | BigNumber): this {
|
|
96
88
|
if (n instanceof BigNumber) {
|
|
97
89
|
this.dividend *= n.dividend;
|
|
98
90
|
this.divisor *= n.divisor;
|
|
@@ -105,11 +97,11 @@ export default class BigNumber {
|
|
|
105
97
|
}
|
|
106
98
|
|
|
107
99
|
/**
|
|
108
|
-
*
|
|
109
|
-
* @param n The other number.
|
|
100
|
+
* Divide this number by a number.
|
|
101
|
+
* @param n - The other number.
|
|
110
102
|
* @returns This number.
|
|
111
103
|
*/
|
|
112
|
-
public divide(n:
|
|
104
|
+
public divide(n: bigint | boolean | number | string | BigNumber): this {
|
|
113
105
|
if (n instanceof BigNumber) {
|
|
114
106
|
this.dividend *= n.divisor;
|
|
115
107
|
this.divisor *= n.dividend;
|
|
@@ -122,8 +114,7 @@ export default class BigNumber {
|
|
|
122
114
|
}
|
|
123
115
|
|
|
124
116
|
/**
|
|
125
|
-
*
|
|
126
|
-
* precision.
|
|
117
|
+
* Convert this number to a regular `number`. Might result in loss of precision.
|
|
127
118
|
* @returns This number as a `number`.
|
|
128
119
|
*/
|
|
129
120
|
public toNumber(): number {
|
|
@@ -134,10 +125,10 @@ export default class BigNumber {
|
|
|
134
125
|
}
|
|
135
126
|
|
|
136
127
|
/**
|
|
137
|
-
*
|
|
128
|
+
* Convert this number to a string.
|
|
138
129
|
* @returns A string representation of this number.
|
|
139
130
|
*/
|
|
140
|
-
public toString()
|
|
141
|
-
return `${this.dividend}/${this.divisor}`;
|
|
131
|
+
public toString() {
|
|
132
|
+
return `${this.dividend.toLocaleString()}/${this.divisor.toLocaleString()}`;
|
|
142
133
|
}
|
|
143
134
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/** An error resulting from using a vector that is too small. */
|
|
1
|
+
/** An error resulting from using a vector that is too small or too large. */
|
|
2
2
|
export default class MagnitudeError extends Error {
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @param message The message of the error.
|
|
4
|
+
* Create an error resulting from using a vector that is too small or too large.
|
|
5
|
+
* @param message - The message of the error.
|
|
6
6
|
*/
|
|
7
|
-
public constructor(message = "The vector is too small.") {
|
|
7
|
+
public constructor(message = "The vector is too small or too large.") {
|
|
8
8
|
super(message);
|
|
9
9
|
this.name = "MagnitudeError";
|
|
10
10
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/** An error resulting from trying to use a matrix that is the wrong size. */
|
|
2
2
|
export default class PartialMatrixError extends Error {
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @param message The message of the error.
|
|
4
|
+
* Create an error resulting from trying to use a matrix that is the wrong size.
|
|
5
|
+
* @param message - The message of the error.
|
|
7
6
|
*/
|
|
8
7
|
public constructor(message = "Invalid matrix dimensions.") {
|
|
9
8
|
super(message);
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/** An error resulting from creating a matrix that isn't a perfect rectangle. */
|
|
2
2
|
export default class PartialMatrixError extends Error {
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @param message The message of the error.
|
|
4
|
+
* Create an error resulting from creating a matrix that isn't a perfect rectangle.
|
|
5
|
+
* @param message - The message of the error.
|
|
7
6
|
*/
|
|
8
7
|
public constructor(message = "The matrix is not rectangular.") {
|
|
9
8
|
super(message);
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export default class SingularMatrixError extends Error {
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @param message The message of the error.
|
|
7
|
+
* Create an error resulting from trying to invert a singular matrix.
|
|
8
|
+
* @param message - The message of the error.
|
|
9
9
|
*/
|
|
10
10
|
public constructor(message = "The matrix cannot be inverted.") {
|
|
11
11
|
super(message);
|
package/src/utility/epsilon.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IntegerRepresentation.d.ts","sourceRoot":"","sources":["../../src/types/IntegerRepresentation.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IntegerRepresentation.js","sourceRoot":"","sources":["../../src/types/IntegerRepresentation.ts"],"names":[],"mappings":""}
|