@lakuna/umath 1.3.9 → 1.4.2
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/README.md +1 -1
- package/dist/algorithms/approx.d.ts +9 -0
- package/dist/algorithms/approx.d.ts.map +1 -0
- package/dist/algorithms/approx.js +12 -0
- package/dist/algorithms/approx.js.map +1 -0
- package/dist/algorithms/approxRelative.d.ts +9 -0
- package/dist/algorithms/approxRelative.d.ts.map +1 -0
- package/dist/algorithms/approxRelative.js +12 -0
- package/dist/algorithms/approxRelative.js.map +1 -0
- package/dist/algorithms/combinations.d.ts +2 -1
- package/dist/algorithms/combinations.d.ts.map +1 -1
- package/dist/algorithms/combinations.js +2 -1
- package/dist/algorithms/combinations.js.map +1 -1
- package/dist/algorithms/degreesToRadians.d.ts +3 -2
- package/dist/algorithms/degreesToRadians.d.ts.map +1 -1
- package/dist/algorithms/degreesToRadians.js +5 -3
- package/dist/algorithms/degreesToRadians.js.map +1 -1
- package/dist/algorithms/factorial.d.ts +2 -1
- package/dist/algorithms/factorial.d.ts.map +1 -1
- package/dist/algorithms/factorial.js +2 -1
- package/dist/algorithms/factorial.js.map +1 -1
- package/dist/algorithms/fibonacci.d.ts +2 -1
- package/dist/algorithms/fibonacci.d.ts.map +1 -1
- package/dist/algorithms/fibonacci.js +6 -2
- package/dist/algorithms/fibonacci.js.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.d.ts +4 -2
- package/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.js +5 -2
- package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
- package/dist/algorithms/hypergeometricPmf.d.ts +3 -2
- package/dist/algorithms/hypergeometricPmf.d.ts.map +1 -1
- package/dist/algorithms/hypergeometricPmf.js +3 -2
- package/dist/algorithms/hypergeometricPmf.js.map +1 -1
- package/dist/algorithms/isPrime.d.ts +2 -1
- package/dist/algorithms/isPrime.d.ts.map +1 -1
- package/dist/algorithms/isPrime.js +2 -1
- package/dist/algorithms/isPrime.js.map +1 -1
- package/dist/algorithms/permutations.d.ts +2 -1
- package/dist/algorithms/permutations.d.ts.map +1 -1
- package/dist/algorithms/permutations.js +2 -1
- package/dist/algorithms/permutations.js.map +1 -1
- package/dist/algorithms/primeFactorization.d.ts +2 -1
- package/dist/algorithms/primeFactorization.d.ts.map +1 -1
- package/dist/algorithms/primeFactorization.js +2 -1
- package/dist/algorithms/primeFactorization.js.map +1 -1
- package/dist/algorithms/radiansToDegrees.d.ts +3 -2
- package/dist/algorithms/radiansToDegrees.d.ts.map +1 -1
- package/dist/algorithms/radiansToDegrees.js +5 -3
- package/dist/algorithms/radiansToDegrees.js.map +1 -1
- package/dist/algorithms/summation.d.ts +2 -1
- package/dist/algorithms/summation.d.ts.map +1 -1
- package/dist/algorithms/summation.js +2 -1
- package/dist/algorithms/summation.js.map +1 -1
- package/dist/linalg/DualQuaternion.d.ts +102 -32
- package/dist/linalg/DualQuaternion.d.ts.map +1 -1
- package/dist/linalg/DualQuaternion.js +243 -272
- package/dist/linalg/DualQuaternion.js.map +1 -1
- package/dist/linalg/Matrix.d.ts +14 -10
- package/dist/linalg/Matrix.d.ts.map +1 -1
- package/dist/linalg/Matrix2.d.ts +74 -51
- package/dist/linalg/Matrix2.d.ts.map +1 -1
- package/dist/linalg/Matrix2.js +95 -171
- package/dist/linalg/Matrix2.js.map +1 -1
- package/dist/linalg/Matrix3.d.ts +122 -72
- package/dist/linalg/Matrix3.d.ts.map +1 -1
- package/dist/linalg/Matrix3.js +186 -355
- package/dist/linalg/Matrix3.js.map +1 -1
- package/dist/linalg/Matrix4.d.ts +266 -149
- package/dist/linalg/Matrix4.d.ts.map +1 -1
- package/dist/linalg/Matrix4.js +512 -852
- package/dist/linalg/Matrix4.js.map +1 -1
- package/dist/linalg/Quaternion.d.ts +252 -34
- package/dist/linalg/Quaternion.d.ts.map +1 -1
- package/dist/linalg/Quaternion.js +436 -166
- package/dist/linalg/Quaternion.js.map +1 -1
- package/dist/linalg/SlowMatrix.d.ts +10 -9
- package/dist/linalg/SlowMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowMatrix.js +10 -9
- package/dist/linalg/SlowMatrix.js.map +1 -1
- package/dist/linalg/SlowSquareMatrix.d.ts +10 -9
- package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowSquareMatrix.js +10 -9
- package/dist/linalg/SlowSquareMatrix.js.map +1 -1
- package/dist/linalg/SquareMatrix.d.ts +6 -5
- package/dist/linalg/SquareMatrix.d.ts.map +1 -1
- package/dist/linalg/Vector.d.ts +8 -4
- package/dist/linalg/Vector.d.ts.map +1 -1
- package/dist/linalg/Vector2.d.ts +82 -31
- package/dist/linalg/Vector2.d.ts.map +1 -1
- package/dist/linalg/Vector2.js +112 -154
- package/dist/linalg/Vector2.js.map +1 -1
- package/dist/linalg/Vector3.d.ts +93 -41
- package/dist/linalg/Vector3.d.ts.map +1 -1
- package/dist/linalg/Vector3.js +171 -282
- package/dist/linalg/Vector3.js.map +1 -1
- package/dist/linalg/Vector4.d.ts +71 -21
- package/dist/linalg/Vector4.d.ts.map +1 -1
- package/dist/linalg/Vector4.js +121 -195
- 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 +4 -1
- package/dist/types/FieldOfView.d.ts.map +1 -1
- package/dist/utility/BigNumber.d.ts +4 -1
- package/dist/utility/BigNumber.d.ts.map +1 -1
- package/dist/utility/BigNumber.js +4 -1
- package/dist/utility/BigNumber.js.map +1 -1
- package/dist/utility/MagnitudeError.d.ts +4 -1
- package/dist/utility/MagnitudeError.d.ts.map +1 -1
- package/dist/utility/MagnitudeError.js +4 -1
- package/dist/utility/MagnitudeError.js.map +1 -1
- package/dist/utility/MatrixSizeError.d.ts +4 -1
- package/dist/utility/MatrixSizeError.d.ts.map +1 -1
- package/dist/utility/MatrixSizeError.js +4 -1
- package/dist/utility/MatrixSizeError.js.map +1 -1
- package/dist/utility/PartialMatrixError.d.ts +4 -1
- package/dist/utility/PartialMatrixError.d.ts.map +1 -1
- package/dist/utility/PartialMatrixError.js +4 -1
- package/dist/utility/PartialMatrixError.js.map +1 -1
- package/dist/utility/SingularMatrixError.d.ts +2 -1
- package/dist/utility/SingularMatrixError.d.ts.map +1 -1
- package/dist/utility/SingularMatrixError.js +2 -1
- package/dist/utility/SingularMatrixError.js.map +1 -1
- package/dist/utility/epsilon.d.ts +4 -1
- package/dist/utility/epsilon.d.ts.map +1 -1
- package/dist/utility/epsilon.js +4 -1
- package/dist/utility/epsilon.js.map +1 -1
- package/package.json +11 -11
- package/src/algorithms/approx.ts +12 -0
- package/src/algorithms/approxRelative.ts +12 -0
- package/src/algorithms/combinations.ts +2 -1
- package/src/algorithms/degreesToRadians.ts +6 -3
- package/src/algorithms/factorial.ts +3 -1
- package/src/algorithms/fibonacci.ts +7 -2
- package/src/algorithms/greatestCommonDivisor.ts +9 -4
- package/src/algorithms/hypergeometricPmf.ts +3 -2
- package/src/algorithms/isPrime.ts +2 -1
- package/src/algorithms/permutations.ts +2 -1
- package/src/algorithms/primeFactorization.ts +2 -1
- package/src/algorithms/radiansToDegrees.ts +6 -3
- package/src/algorithms/summation.ts +2 -1
- package/src/linalg/DualQuaternion.ts +424 -289
- package/src/linalg/Matrix.ts +14 -10
- package/src/linalg/Matrix2.ts +141 -188
- package/src/linalg/Matrix3.ts +400 -375
- package/src/linalg/Matrix4.ts +1083 -905
- package/src/linalg/Quaternion.ts +706 -188
- package/src/linalg/SlowMatrix.ts +10 -9
- package/src/linalg/SlowSquareMatrix.ts +10 -9
- package/src/linalg/SquareMatrix.ts +6 -5
- package/src/linalg/Vector.ts +8 -4
- package/src/linalg/Vector2.ts +146 -173
- package/src/linalg/Vector3.ts +293 -326
- package/src/linalg/Vector4.ts +227 -215
- package/src/types/AxisAngle.ts +4 -1
- package/src/types/FieldOfView.ts +4 -1
- package/src/utility/BigNumber.ts +6 -3
- package/src/utility/MagnitudeError.ts +4 -1
- package/src/utility/MatrixSizeError.ts +4 -1
- package/src/utility/PartialMatrixError.ts +4 -1
- package/src/utility/SingularMatrixError.ts +2 -1
- package/src/utility/epsilon.ts +4 -1
package/src/linalg/SlowMatrix.ts
CHANGED
|
@@ -5,7 +5,8 @@ import epsilon from "../utility/epsilon.js";
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* A variable-size matrix.
|
|
8
|
-
* @see
|
|
8
|
+
* @see {@link https://en.wikipedia.org/wiki/Matrix_(mathematics) | Matrix}
|
|
9
|
+
* @public
|
|
9
10
|
*/
|
|
10
11
|
export default class SlowMatrix extends Float32Array implements Matrix {
|
|
11
12
|
/**
|
|
@@ -41,7 +42,7 @@ export default class SlowMatrix extends Float32Array implements Matrix {
|
|
|
41
42
|
|
|
42
43
|
/**
|
|
43
44
|
* Get the Frobenius norm of this matrix.
|
|
44
|
-
* @see
|
|
45
|
+
* @see {@link https://en.wikipedia.org/wiki/Matrix_norm | Matrix norm}
|
|
45
46
|
*/
|
|
46
47
|
public get frob(): number {
|
|
47
48
|
return Math.hypot(...this);
|
|
@@ -51,7 +52,7 @@ export default class SlowMatrix extends Float32Array implements Matrix {
|
|
|
51
52
|
* Add two matrices of the same size.
|
|
52
53
|
* @param matrix - The other matrix.
|
|
53
54
|
* @returns The sum of the matrices.
|
|
54
|
-
* @see
|
|
55
|
+
* @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
|
|
55
56
|
*/
|
|
56
57
|
public add(matrix: MatrixLike): SlowMatrix {
|
|
57
58
|
const matrixWidth = "width" in matrix ? (matrix.width as number) : 1;
|
|
@@ -170,7 +171,7 @@ export default class SlowMatrix extends Float32Array implements Matrix {
|
|
|
170
171
|
* Multiply this matrix by another.
|
|
171
172
|
* @param matrix - The other matrix.
|
|
172
173
|
* @returns The product of the matrices.
|
|
173
|
-
* @see
|
|
174
|
+
* @see {@link https://en.wikipedia.org/wiki/Matrix_multiplication | Matrix multiplication}
|
|
174
175
|
*/
|
|
175
176
|
public multiply(matrix: MatrixLike): SlowMatrix {
|
|
176
177
|
const matrixWidth = "width" in matrix ? (matrix.width as number) : 1;
|
|
@@ -206,7 +207,7 @@ export default class SlowMatrix extends Float32Array implements Matrix {
|
|
|
206
207
|
* Multiply this matrix by a scalar value.
|
|
207
208
|
* @param scalar - The scalar value.
|
|
208
209
|
* @returns The product of the matrix and the scalar value.
|
|
209
|
-
* @see
|
|
210
|
+
* @see {@link https://en.wikipedia.org/wiki/Matrix_multiplication | Matrix multiplication}
|
|
210
211
|
*/
|
|
211
212
|
public multiplyScalar(scalar: number): SlowMatrix {
|
|
212
213
|
const out = this.clone();
|
|
@@ -226,8 +227,8 @@ export default class SlowMatrix extends Float32Array implements Matrix {
|
|
|
226
227
|
* @param matrix - The other matrix.
|
|
227
228
|
* @param scalar - The scalar.
|
|
228
229
|
* @returns The sum.
|
|
229
|
-
* @see
|
|
230
|
-
* @see
|
|
230
|
+
* @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
|
|
231
|
+
* @see {@link https://en.wikipedia.org/wiki/Matrix_multiplication | Matrix multiplication}
|
|
231
232
|
*/
|
|
232
233
|
public multiplyScalarAndAdd(matrix: MatrixLike, scalar: number): SlowMatrix {
|
|
233
234
|
if (!("multiplyScalar" in matrix)) {
|
|
@@ -242,7 +243,7 @@ export default class SlowMatrix extends Float32Array implements Matrix {
|
|
|
242
243
|
* Subtract another matrix from this one.
|
|
243
244
|
* @param matrix - The other matrix.
|
|
244
245
|
* @returns The difference between the matrices.
|
|
245
|
-
* @see
|
|
246
|
+
* @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
|
|
246
247
|
*/
|
|
247
248
|
public subtract(matrix: MatrixLike): SlowMatrix {
|
|
248
249
|
const matrixWidth = "width" in matrix ? (matrix.width as number) : 1;
|
|
@@ -269,7 +270,7 @@ export default class SlowMatrix extends Float32Array implements Matrix {
|
|
|
269
270
|
/**
|
|
270
271
|
* Transpose this matrix.
|
|
271
272
|
* @returns The transpose of this matrix.
|
|
272
|
-
* @see
|
|
273
|
+
* @see {@link https://en.wikipedia.org/wiki/Transpose | Transpose}
|
|
273
274
|
*/
|
|
274
275
|
public transpose(): SlowMatrix {
|
|
275
276
|
const cols: number[][] = [];
|
|
@@ -5,7 +5,8 @@ import type SquareMatrix from "./SquareMatrix.js";
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* A variable-size matrix with the same number of rows and columns.
|
|
8
|
-
* @see
|
|
8
|
+
* @see {@link https://en.wikipedia.org/wiki/Square_matrix | Square matrix}
|
|
9
|
+
* @public
|
|
9
10
|
*/
|
|
10
11
|
export default class SlowSquareMatrix
|
|
11
12
|
extends SlowMatrix
|
|
@@ -14,7 +15,7 @@ export default class SlowSquareMatrix
|
|
|
14
15
|
/**
|
|
15
16
|
* Create a variable-size matrix with the same number of rows and columns from the given columns.
|
|
16
17
|
* @param cols - The columns in the matrix.
|
|
17
|
-
* @see
|
|
18
|
+
* @see {@link https://en.wikipedia.org/wiki/Square_matrix | Square matrix}
|
|
18
19
|
*/
|
|
19
20
|
public constructor(...cols: number[][]) {
|
|
20
21
|
super(...cols);
|
|
@@ -30,7 +31,7 @@ export default class SlowSquareMatrix
|
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* Get the determinant of this matrix.
|
|
33
|
-
* @see
|
|
34
|
+
* @see {@link https://en.wikipedia.org/wiki/Determinant | Determinant}
|
|
34
35
|
*/
|
|
35
36
|
public get determinant(): number {
|
|
36
37
|
if (this.length < 1) {
|
|
@@ -56,7 +57,7 @@ export default class SlowSquareMatrix
|
|
|
56
57
|
/**
|
|
57
58
|
* Calculate the adjugate of this matrix.
|
|
58
59
|
* @returns The adjugate of this matrix.
|
|
59
|
-
* @see
|
|
60
|
+
* @see {@link https://en.wikipedia.org/wiki/Adjugate_matrix | Adjugate matrix}
|
|
60
61
|
*/
|
|
61
62
|
public adjoint(): SlowSquareMatrix {
|
|
62
63
|
return this.cofactor().transpose();
|
|
@@ -84,7 +85,7 @@ export default class SlowSquareMatrix
|
|
|
84
85
|
/**
|
|
85
86
|
* Calculate the cofactor of this matrix.
|
|
86
87
|
* @returns The cofactor.
|
|
87
|
-
* @see
|
|
88
|
+
* @see {@link https://en.wikipedia.org/wiki/Minor_(linear_algebra) | Minor}
|
|
88
89
|
*/
|
|
89
90
|
public cofactor(): SlowSquareMatrix {
|
|
90
91
|
const out: number[][] = [];
|
|
@@ -102,7 +103,7 @@ export default class SlowSquareMatrix
|
|
|
102
103
|
/**
|
|
103
104
|
* Reset this matrix to identity.
|
|
104
105
|
* @returns This matrix.
|
|
105
|
-
* @see
|
|
106
|
+
* @see {@link https://en.wikipedia.org/wiki/Identity_matrix | Identity matrix}
|
|
106
107
|
*/
|
|
107
108
|
public identity(): this {
|
|
108
109
|
for (let i = 0; i < this.width; i++) {
|
|
@@ -117,7 +118,7 @@ export default class SlowSquareMatrix
|
|
|
117
118
|
/**
|
|
118
119
|
* Invert this matrix.
|
|
119
120
|
* @returns The inverted matrix.
|
|
120
|
-
* @see
|
|
121
|
+
* @see {@link https://en.wikipedia.org/wiki/Invertible_matrix | Invertible matrix}
|
|
121
122
|
*/
|
|
122
123
|
public invert(): SlowSquareMatrix {
|
|
123
124
|
const dim = this.width;
|
|
@@ -188,7 +189,7 @@ export default class SlowSquareMatrix
|
|
|
188
189
|
* @param row - The row to remove.
|
|
189
190
|
* @param col - The column to remove.
|
|
190
191
|
* @returns The minor.
|
|
191
|
-
* @see
|
|
192
|
+
* @see {@link https://en.wikipedia.org/wiki/Minor_(linear_algebra) | Minor}
|
|
192
193
|
*/
|
|
193
194
|
public minor(row: number, col: number): number {
|
|
194
195
|
return this.submatrix(row, col).determinant;
|
|
@@ -228,7 +229,7 @@ export default class SlowSquareMatrix
|
|
|
228
229
|
/**
|
|
229
230
|
* Transpose this matrix.
|
|
230
231
|
* @returns The transpose of this matrix.
|
|
231
|
-
* @see
|
|
232
|
+
* @see {@link https://en.wikipedia.org/wiki/Transpose | Transpose}
|
|
232
233
|
*/
|
|
233
234
|
public override transpose(): SlowSquareMatrix {
|
|
234
235
|
const cols: number[][] = [];
|
|
@@ -2,33 +2,34 @@ import type { default as Matrix, MatrixLike } from "./Matrix.js";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A matrix with the same number of rows and columns.
|
|
5
|
-
* @see
|
|
5
|
+
* @see {@link https://en.wikipedia.org/wiki/Square_matrix | Square matrix}
|
|
6
|
+
* @public
|
|
6
7
|
*/
|
|
7
8
|
export default interface SquareMatrix extends Matrix {
|
|
8
9
|
/**
|
|
9
10
|
* Get the determinant of this matrix.
|
|
10
|
-
* @see
|
|
11
|
+
* @see {@link https://en.wikipedia.org/wiki/Determinant | Determinant}
|
|
11
12
|
*/
|
|
12
13
|
get determinant(): number;
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Calculate the adjugate of this matrix.
|
|
16
17
|
* @returns The adjugate of this matrix.
|
|
17
|
-
* @see
|
|
18
|
+
* @see {@link https://en.wikipedia.org/wiki/Adjugate_matrix | Adjugate matrix}
|
|
18
19
|
*/
|
|
19
20
|
adjoint(): MatrixLike;
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Reset this matrix to identity.
|
|
23
24
|
* @returns This matrix.
|
|
24
|
-
* @see
|
|
25
|
+
* @see {@link https://en.wikipedia.org/wiki/Identity_matrix | Identity matrix}
|
|
25
26
|
*/
|
|
26
27
|
identity(): this;
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Invert this matrix.
|
|
30
31
|
* @returns The inverted matrix.
|
|
31
|
-
* @see
|
|
32
|
+
* @see {@link https://en.wikipedia.org/wiki/Invertible_matrix | Invertible matrix}
|
|
32
33
|
*/
|
|
33
34
|
invert(): MatrixLike;
|
|
34
35
|
}
|
package/src/linalg/Vector.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { Vector4Like } from "./Vector4.js";
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* An object that could be interpreted as a vector.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
4
7
|
export type VectorLike = Record<number, number>;
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* A quantity with magnitude and direction.
|
|
8
|
-
* @see
|
|
11
|
+
* @see {@link https://en.wikipedia.org/wiki/Euclidean_vector | Euclidean vector}
|
|
12
|
+
* @public
|
|
9
13
|
*/
|
|
10
14
|
export default interface Vector extends VectorLike {
|
|
11
15
|
/**
|
|
@@ -145,7 +149,7 @@ export default interface Vector extends VectorLike {
|
|
|
145
149
|
/**
|
|
146
150
|
* Normalize this vector.
|
|
147
151
|
* @returns The normalized vector.
|
|
148
|
-
* @see
|
|
152
|
+
* @see {@link https://en.wikipedia.org/wiki/Unit_vector | Unit vector}
|
|
149
153
|
*/
|
|
150
154
|
normalize(): VectorLike;
|
|
151
155
|
|
|
@@ -153,7 +157,7 @@ export default interface Vector extends VectorLike {
|
|
|
153
157
|
* Calculate the dot product of this and another vector.
|
|
154
158
|
* @param vector - The other vector.
|
|
155
159
|
* @returns The dot product.
|
|
156
|
-
* @see
|
|
160
|
+
* @see {@link https://en.wikipedia.org/wiki/Dot_product | Dot product}
|
|
157
161
|
*/
|
|
158
162
|
dot(vector: Vector4Like): number;
|
|
159
163
|
|