@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/linalg/Matrix2.ts
CHANGED
|
@@ -1,102 +1,110 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import type { MatrixLike } from "./Matrix.js";
|
|
2
|
+
import SingularMatrixError from "../utility/SingularMatrixError.js";
|
|
3
|
+
import type SquareMatrix from "./SquareMatrix.js";
|
|
4
|
+
import type { Vector2Like } from "./Vector2.js";
|
|
5
|
+
import epsilon from "../utility/epsilon.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Numbers arranged into two columns and two rows.
|
|
8
9
|
* @see [Matrix](https://en.wikipedia.org/wiki/Matrix_(mathematics))
|
|
9
10
|
*/
|
|
10
|
-
export
|
|
11
|
+
export interface Matrix2Like extends MatrixLike {
|
|
12
|
+
/** The value in the first column and first row. */
|
|
13
|
+
0: number;
|
|
14
|
+
|
|
15
|
+
/** The value in the first column and second row. */
|
|
16
|
+
1: number;
|
|
17
|
+
|
|
18
|
+
/** The value in the second column and first row. */
|
|
19
|
+
2: number;
|
|
20
|
+
|
|
21
|
+
/** The value in the second column and second row. */
|
|
22
|
+
3: number;
|
|
23
|
+
}
|
|
11
24
|
|
|
12
25
|
/**
|
|
13
|
-
*
|
|
26
|
+
* Create a 2x2 matrix-like object.
|
|
14
27
|
* @returns A 2x2 matrix-like object.
|
|
15
28
|
*/
|
|
16
|
-
export
|
|
17
|
-
return new Float32Array(4) as Matrix2Like;
|
|
18
|
-
}
|
|
29
|
+
export const createMatrix2Like = () => {
|
|
30
|
+
return new Float32Array(4) as unknown as Matrix2Like;
|
|
31
|
+
};
|
|
19
32
|
|
|
20
33
|
/**
|
|
21
|
-
*
|
|
22
|
-
* angle
|
|
23
|
-
* @param
|
|
24
|
-
* @param out The matrix to store the result in.
|
|
34
|
+
* Create a transformation matrix that represents a rotation by the given angle around the Z-axis.
|
|
35
|
+
* @param r - The angle in radians.
|
|
36
|
+
* @param out - The matrix to store the result in.
|
|
25
37
|
* @returns The transformation matrix.
|
|
26
38
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
27
39
|
*/
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
): T {
|
|
32
|
-
const s: number = Math.sin(radians);
|
|
33
|
-
const c: number = Math.cos(radians);
|
|
40
|
+
export const fromRotation = <T extends Matrix2Like>(r: number, out: T): T => {
|
|
41
|
+
const s = Math.sin(r);
|
|
42
|
+
const c = Math.cos(r);
|
|
34
43
|
|
|
35
44
|
out[0] = c;
|
|
36
45
|
out[1] = s;
|
|
37
46
|
out[2] = -s;
|
|
38
47
|
out[3] = c;
|
|
39
48
|
return out;
|
|
40
|
-
}
|
|
49
|
+
};
|
|
41
50
|
|
|
42
51
|
/**
|
|
43
|
-
*
|
|
44
|
-
* vector.
|
|
45
|
-
* @param
|
|
46
|
-
* @param out The matrix to store the result in.
|
|
52
|
+
* Create a transformation matrix that represents a scaling by the given vector.
|
|
53
|
+
* @param v - The scaling vector.
|
|
54
|
+
* @param out - The matrix to store the result in.
|
|
47
55
|
* @returns The transformation matrix.
|
|
48
56
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
49
57
|
*/
|
|
50
|
-
export
|
|
58
|
+
export const fromScaling = <T extends Matrix2Like>(
|
|
51
59
|
vector: Vector2Like,
|
|
52
60
|
out: T
|
|
53
|
-
): T {
|
|
61
|
+
): T => {
|
|
54
62
|
out[0] = vector[0];
|
|
55
63
|
out[1] = 0;
|
|
56
64
|
out[2] = 0;
|
|
57
65
|
out[3] = vector[1];
|
|
58
66
|
return out;
|
|
59
|
-
}
|
|
67
|
+
};
|
|
60
68
|
|
|
61
69
|
/**
|
|
62
|
-
*
|
|
63
|
-
* @param c0r0 The value in the first column and first row.
|
|
64
|
-
* @param c0r1 The value in the first column and second row.
|
|
65
|
-
* @param c1r0 The value in the second column and first row.
|
|
66
|
-
* @param c1r1 The value in the second column and second row.
|
|
67
|
-
* @param out The matrix to store the result in.
|
|
70
|
+
* Create a two-by-two matrix with the given values.
|
|
71
|
+
* @param c0r0 - The value in the first column and first row.
|
|
72
|
+
* @param c0r1 - The value in the first column and second row.
|
|
73
|
+
* @param c1r0 - The value in the second column and first row.
|
|
74
|
+
* @param c1r1 - The value in the second column and second row.
|
|
75
|
+
* @param out - The matrix to store the result in.
|
|
68
76
|
* @returns The matrix.
|
|
69
77
|
*/
|
|
70
|
-
export
|
|
78
|
+
export const fromValues = <T extends Matrix2Like>(
|
|
71
79
|
c0r0: number,
|
|
72
80
|
c0r1: number,
|
|
73
81
|
c1r0: number,
|
|
74
82
|
c1r1: number,
|
|
75
83
|
out: T
|
|
76
|
-
): T {
|
|
84
|
+
): T => {
|
|
77
85
|
out[0] = c0r0;
|
|
78
86
|
out[1] = c0r1;
|
|
79
87
|
out[2] = c1r0;
|
|
80
88
|
out[3] = c1r1;
|
|
81
89
|
return out;
|
|
82
|
-
}
|
|
90
|
+
};
|
|
83
91
|
|
|
84
92
|
/**
|
|
85
|
-
*
|
|
86
|
-
* @param a The first matrix.
|
|
87
|
-
* @param b The second matrix.
|
|
88
|
-
* @returns Whether the matrices are equivalent.
|
|
93
|
+
* Determine whether or not two matrices are roughly equivalent.
|
|
94
|
+
* @param a - The first matrix.
|
|
95
|
+
* @param b - The second matrix.
|
|
96
|
+
* @returns Whether or not the matrices are equivalent.
|
|
89
97
|
*/
|
|
90
|
-
export
|
|
91
|
-
const a0
|
|
92
|
-
const a1
|
|
93
|
-
const a2
|
|
94
|
-
const a3
|
|
98
|
+
export const equals = (a: Matrix2Like, b: Matrix2Like): boolean => {
|
|
99
|
+
const a0 = a[0];
|
|
100
|
+
const a1 = a[1];
|
|
101
|
+
const a2 = a[2];
|
|
102
|
+
const a3 = a[3];
|
|
95
103
|
|
|
96
|
-
const b0
|
|
97
|
-
const b1
|
|
98
|
-
const b2
|
|
99
|
-
const b3
|
|
104
|
+
const b0 = b[0];
|
|
105
|
+
const b1 = b[1];
|
|
106
|
+
const b2 = b[2];
|
|
107
|
+
const b3 = b[3];
|
|
100
108
|
|
|
101
109
|
return (
|
|
102
110
|
Math.abs(a0 - b0) <= epsilon * Math.max(1, Math.abs(a0), Math.abs(b0)) &&
|
|
@@ -104,188 +112,186 @@ export function equals(a: Matrix2Like, b: Matrix2Like): boolean {
|
|
|
104
112
|
Math.abs(a2 - b2) <= epsilon * Math.max(1, Math.abs(a2), Math.abs(b2)) &&
|
|
105
113
|
Math.abs(a3 - b3) <= epsilon * Math.max(1, Math.abs(a3), Math.abs(b3))
|
|
106
114
|
);
|
|
107
|
-
}
|
|
115
|
+
};
|
|
108
116
|
|
|
109
117
|
/**
|
|
110
|
-
*
|
|
111
|
-
* @param a The first matrix.
|
|
112
|
-
* @param b The second matrix.
|
|
118
|
+
* Determine whether or not two matrices are exactly equivalent.
|
|
119
|
+
* @param a - The first matrix.
|
|
120
|
+
* @param b - The second matrix.
|
|
113
121
|
* @returns Whether the matrices are equivalent.
|
|
114
122
|
*/
|
|
115
|
-
export
|
|
116
|
-
return a[0]
|
|
117
|
-
}
|
|
123
|
+
export const exactEquals = (a: Matrix2Like, b: Matrix2Like): boolean => {
|
|
124
|
+
return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
|
|
125
|
+
};
|
|
118
126
|
|
|
119
127
|
/**
|
|
120
|
-
*
|
|
121
|
-
* @param a The augend.
|
|
122
|
-
* @param b The addend.
|
|
123
|
-
* @param out The matrix to store the result in.
|
|
128
|
+
* Add two matrices.
|
|
129
|
+
* @param a - The augend.
|
|
130
|
+
* @param b - The addend.
|
|
131
|
+
* @param out - The matrix to store the result in.
|
|
124
132
|
* @returns The sum.
|
|
125
133
|
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
126
134
|
*/
|
|
127
|
-
export
|
|
135
|
+
export const add = <T extends Matrix2Like>(
|
|
128
136
|
a: Matrix2Like,
|
|
129
137
|
b: Matrix2Like,
|
|
130
138
|
out: T
|
|
131
|
-
): T {
|
|
139
|
+
): T => {
|
|
132
140
|
out[0] = a[0] + b[0];
|
|
133
141
|
out[1] = a[1] + b[1];
|
|
134
142
|
out[2] = a[2] + b[2];
|
|
135
143
|
out[3] = a[3] + b[3];
|
|
136
144
|
return out;
|
|
137
|
-
}
|
|
145
|
+
};
|
|
138
146
|
|
|
139
147
|
/**
|
|
140
|
-
*
|
|
141
|
-
* @param matrix The matrix.
|
|
142
|
-
* @param out The matrix to store the result in.
|
|
148
|
+
* Calculate the adjugate of a matrix.
|
|
149
|
+
* @param matrix - The matrix.
|
|
150
|
+
* @param out - The matrix to store the result in.
|
|
143
151
|
* @returns The adjugate of the matrix.
|
|
144
152
|
* @see [Adjugate matrix](https://en.wikipedia.org/wiki/Adjugate_matrix)
|
|
145
153
|
*/
|
|
146
|
-
export
|
|
147
|
-
|
|
154
|
+
export const adjoint = <T extends Matrix2Like>(
|
|
155
|
+
matrix: Matrix2Like,
|
|
156
|
+
out: T
|
|
157
|
+
): T => {
|
|
158
|
+
const a0 = matrix[0];
|
|
148
159
|
out[0] = matrix[3];
|
|
149
160
|
out[1] = -matrix[1];
|
|
150
161
|
out[2] = -matrix[2];
|
|
151
162
|
out[3] = a0;
|
|
152
163
|
return out;
|
|
153
|
-
}
|
|
164
|
+
};
|
|
154
165
|
|
|
155
166
|
/**
|
|
156
|
-
*
|
|
157
|
-
* @param matrix The matrix to copy.
|
|
158
|
-
* @param out The matrix to store the result in.
|
|
167
|
+
* Copy the values from one matrix into another.
|
|
168
|
+
* @param matrix - The matrix to copy.
|
|
169
|
+
* @param out - The matrix to store the result in.
|
|
159
170
|
* @returns The copy matrix.
|
|
160
171
|
*/
|
|
161
|
-
export
|
|
172
|
+
export const copy = <T extends Matrix2Like>(matrix: Matrix2Like, out: T): T => {
|
|
162
173
|
out[0] = matrix[0];
|
|
163
174
|
out[1] = matrix[1];
|
|
164
175
|
out[2] = matrix[2];
|
|
165
176
|
out[3] = matrix[3];
|
|
166
177
|
return out;
|
|
167
|
-
}
|
|
178
|
+
};
|
|
168
179
|
|
|
169
180
|
/**
|
|
170
|
-
*
|
|
171
|
-
* @param matrix The matrix.
|
|
181
|
+
* Calculate the Frobenius norm of a matrix.
|
|
182
|
+
* @param matrix - The matrix.
|
|
172
183
|
* @returns The Frobenius norm.
|
|
173
184
|
* @see [Matrix norm](https://en.wikipedia.org/wiki/Matrix_norm)
|
|
174
185
|
*/
|
|
175
|
-
export
|
|
176
|
-
return Math.hypot(
|
|
177
|
-
|
|
178
|
-
matrix[1] as number,
|
|
179
|
-
matrix[2] as number,
|
|
180
|
-
matrix[3] as number
|
|
181
|
-
);
|
|
182
|
-
}
|
|
186
|
+
export const frob = (matrix: Matrix2Like): number => {
|
|
187
|
+
return Math.hypot(matrix[0], matrix[1], matrix[2], matrix[3]);
|
|
188
|
+
};
|
|
183
189
|
|
|
184
190
|
/**
|
|
185
|
-
*
|
|
186
|
-
* @param a The multiplicand.
|
|
187
|
-
* @param b The multiplier.
|
|
188
|
-
* @param out The matrix to store the result in.
|
|
191
|
+
* Multiply one matrix by another.
|
|
192
|
+
* @param a - The multiplicand.
|
|
193
|
+
* @param b - The multiplier.
|
|
194
|
+
* @param out - The matrix to store the result in.
|
|
189
195
|
* @returns The product.
|
|
190
196
|
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
191
197
|
*/
|
|
192
|
-
export
|
|
198
|
+
export const multiply = <T extends Matrix2Like>(
|
|
193
199
|
a: Matrix2Like,
|
|
194
200
|
b: Matrix2Like,
|
|
195
201
|
out: T
|
|
196
|
-
): T {
|
|
197
|
-
const a0
|
|
198
|
-
const a1
|
|
199
|
-
const a2
|
|
200
|
-
const a3
|
|
202
|
+
): T => {
|
|
203
|
+
const a0 = a[0];
|
|
204
|
+
const a1 = a[1];
|
|
205
|
+
const a2 = a[2];
|
|
206
|
+
const a3 = a[3];
|
|
201
207
|
|
|
202
|
-
const b0
|
|
203
|
-
const b1
|
|
204
|
-
const b2
|
|
205
|
-
const b3
|
|
208
|
+
const b0 = b[0];
|
|
209
|
+
const b1 = b[1];
|
|
210
|
+
const b2 = b[2];
|
|
211
|
+
const b3 = b[3];
|
|
206
212
|
|
|
207
213
|
out[0] = a0 * b0 + a2 * b1;
|
|
208
214
|
out[1] = a1 * b0 + a3 * b1;
|
|
209
215
|
out[2] = a0 * b2 + a2 * b3;
|
|
210
216
|
out[3] = a1 * b2 + a3 * b3;
|
|
211
217
|
return out;
|
|
212
|
-
}
|
|
218
|
+
};
|
|
213
219
|
|
|
214
220
|
/**
|
|
215
|
-
*
|
|
216
|
-
* @param matrix The multiplicand.
|
|
217
|
-
* @param scalar The multiplier.
|
|
218
|
-
* @param out The matrix to store the result in.
|
|
221
|
+
* Multiply a matrix by a scalar value.
|
|
222
|
+
* @param matrix - The multiplicand.
|
|
223
|
+
* @param scalar - The multiplier.
|
|
224
|
+
* @param out - The matrix to store the result in.
|
|
219
225
|
* @returns The product.
|
|
220
226
|
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
221
227
|
*/
|
|
222
|
-
export
|
|
228
|
+
export const multiplyScalar = <T extends Matrix2Like>(
|
|
223
229
|
matrix: Matrix2Like,
|
|
224
230
|
scalar: number,
|
|
225
231
|
out: T
|
|
226
|
-
): T {
|
|
232
|
+
): T => {
|
|
227
233
|
out[0] = matrix[0] * scalar;
|
|
228
234
|
out[1] = matrix[1] * scalar;
|
|
229
235
|
out[2] = matrix[2] * scalar;
|
|
230
236
|
out[3] = matrix[3] * scalar;
|
|
231
237
|
return out;
|
|
232
|
-
}
|
|
238
|
+
};
|
|
233
239
|
|
|
234
240
|
/**
|
|
235
|
-
*
|
|
236
|
-
* @param a The augend.
|
|
237
|
-
* @param b The addend.
|
|
238
|
-
* @param scalar The multiplier.
|
|
239
|
-
* @param out The matrix to store the result in.
|
|
241
|
+
* Add a matrix to another after multiplying the other by a scalar.
|
|
242
|
+
* @param a - The augend.
|
|
243
|
+
* @param b - The addend.
|
|
244
|
+
* @param scalar - The multiplier.
|
|
245
|
+
* @param out - The matrix to store the result in.
|
|
240
246
|
* @returns The sum.
|
|
241
247
|
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
242
248
|
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
243
249
|
*/
|
|
244
|
-
export
|
|
250
|
+
export const multiplyScalarAndAdd = <T extends Matrix2Like>(
|
|
245
251
|
a: Matrix2Like,
|
|
246
252
|
b: Matrix2Like,
|
|
247
253
|
scalar: number,
|
|
248
254
|
out: T
|
|
249
|
-
): T {
|
|
255
|
+
): T => {
|
|
250
256
|
out[0] = a[0] + b[0] * scalar;
|
|
251
257
|
out[1] = a[1] + b[1] * scalar;
|
|
252
258
|
out[2] = a[2] + b[2] * scalar;
|
|
253
259
|
out[3] = a[3] + b[3] * scalar;
|
|
254
260
|
return out;
|
|
255
|
-
}
|
|
261
|
+
};
|
|
256
262
|
|
|
257
263
|
/**
|
|
258
|
-
*
|
|
259
|
-
* @param a The minuend.
|
|
260
|
-
* @param b The subtrahend.
|
|
261
|
-
* @param out The matrix to store the result in.
|
|
264
|
+
* Subtract one matrix from another.
|
|
265
|
+
* @param a - The minuend.
|
|
266
|
+
* @param b - The subtrahend.
|
|
267
|
+
* @param out - The matrix to store the result in.
|
|
262
268
|
* @returns The difference.
|
|
263
269
|
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
264
270
|
*/
|
|
265
|
-
export
|
|
271
|
+
export const subtract = <T extends Matrix2Like>(
|
|
266
272
|
a: Matrix2Like,
|
|
267
273
|
b: Matrix2Like,
|
|
268
274
|
out: T
|
|
269
|
-
): T {
|
|
275
|
+
): T => {
|
|
270
276
|
out[0] = a[0] - b[0];
|
|
271
277
|
out[1] = a[1] - b[1];
|
|
272
278
|
out[2] = a[2] - b[2];
|
|
273
279
|
out[3] = a[3] - b[3];
|
|
274
280
|
return out;
|
|
275
|
-
}
|
|
281
|
+
};
|
|
276
282
|
|
|
277
283
|
/**
|
|
278
|
-
*
|
|
279
|
-
* @param matrix The matrix.
|
|
280
|
-
* @param out The matrix to store the result in.
|
|
284
|
+
* Transpose a matrix.
|
|
285
|
+
* @param matrix - The matrix.
|
|
286
|
+
* @param out - The matrix to store the result in.
|
|
281
287
|
* @returns The transpose of the matrix.
|
|
282
288
|
* @see [Transpose](https://en.wikipedia.org/wiki/Transpose)
|
|
283
289
|
*/
|
|
284
|
-
export
|
|
290
|
+
export const transpose = <T extends Matrix2Like>(
|
|
285
291
|
matrix: Matrix2Like,
|
|
286
292
|
out: T
|
|
287
|
-
): T {
|
|
288
|
-
if (out
|
|
293
|
+
): T => {
|
|
294
|
+
if (out === matrix) {
|
|
289
295
|
const a1 = matrix[1];
|
|
290
296
|
out[1] = matrix[2];
|
|
291
297
|
out[2] = a1;
|
|
@@ -296,194 +302,155 @@ export function transpose<T extends Matrix2Like>(
|
|
|
296
302
|
out[3] = matrix[3];
|
|
297
303
|
}
|
|
298
304
|
return out;
|
|
299
|
-
}
|
|
305
|
+
};
|
|
300
306
|
|
|
301
307
|
/**
|
|
302
|
-
*
|
|
303
|
-
* @param matrix
|
|
308
|
+
* Calculate the determinant of a matrix.
|
|
309
|
+
* @param matrix- The matrix.
|
|
304
310
|
* @returns The determinant.
|
|
305
311
|
* @see [Determinant](https://en.wikipedia.org/wiki/Determinant)
|
|
306
312
|
*/
|
|
307
|
-
export
|
|
308
|
-
return
|
|
309
|
-
|
|
310
|
-
(matrix[2] as number) * (matrix[1] as number)
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
+
export const determinant = (matrix: Matrix2Like): number => {
|
|
314
|
+
return matrix[0] * matrix[3] - matrix[2] * matrix[1];
|
|
315
|
+
};
|
|
313
316
|
|
|
314
317
|
/**
|
|
315
|
-
*
|
|
316
|
-
* @param out The matrix to store the result in.
|
|
318
|
+
* Reset a matrix to identity.
|
|
319
|
+
* @param out - The matrix to store the result in.
|
|
317
320
|
* @returns The matrix.
|
|
318
321
|
* @see [Identity matrix](https://en.wikipedia.org/wiki/Identity_matrix)
|
|
319
322
|
*/
|
|
320
|
-
export
|
|
323
|
+
export const identity = <T extends Matrix2Like>(out: T): T => {
|
|
321
324
|
out[0] = 1;
|
|
322
325
|
out[1] = 0;
|
|
323
326
|
out[2] = 0;
|
|
324
327
|
out[3] = 1;
|
|
325
328
|
return out;
|
|
326
|
-
}
|
|
329
|
+
};
|
|
327
330
|
|
|
328
331
|
/**
|
|
329
|
-
*
|
|
330
|
-
* @param matrix The matrix.
|
|
331
|
-
* @param out The matrix to store the result in.
|
|
332
|
+
* Invert a matrix.
|
|
333
|
+
* @param matrix - The matrix.
|
|
334
|
+
* @param out - The matrix to store the result in.
|
|
332
335
|
* @returns The inverted matrix.
|
|
333
336
|
* @see [Invertible matrix](https://en.wikipedia.org/wiki/Invertible_matrix)
|
|
334
337
|
*/
|
|
335
|
-
export
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
338
|
+
export const invert = <T extends Matrix2Like>(
|
|
339
|
+
matrix: Matrix2Like,
|
|
340
|
+
out: T
|
|
341
|
+
): T => {
|
|
342
|
+
const a0 = matrix[0];
|
|
343
|
+
const a1 = matrix[1];
|
|
344
|
+
const a2 = matrix[2];
|
|
345
|
+
const a3 = matrix[3];
|
|
346
|
+
|
|
347
|
+
let det = a0 * a3 - a2 * a1;
|
|
348
|
+
if (!det) {
|
|
343
349
|
throw new SingularMatrixError();
|
|
344
350
|
}
|
|
345
|
-
|
|
351
|
+
det = 1 / det;
|
|
346
352
|
|
|
347
|
-
out[0] = a3 *
|
|
348
|
-
out[1] = -a1 *
|
|
349
|
-
out[2] = -a2 *
|
|
350
|
-
out[3] = a0 *
|
|
353
|
+
out[0] = a3 * det;
|
|
354
|
+
out[1] = -a1 * det;
|
|
355
|
+
out[2] = -a2 * det;
|
|
356
|
+
out[3] = a0 * det;
|
|
351
357
|
return out;
|
|
352
|
-
}
|
|
358
|
+
};
|
|
353
359
|
|
|
354
360
|
/**
|
|
355
|
-
*
|
|
356
|
-
* @param matrix The matrix.
|
|
357
|
-
* @param
|
|
358
|
-
* @param out The matrix to store the result in.
|
|
361
|
+
* Rotate a matrix by the given angle.
|
|
362
|
+
* @param matrix - The matrix.
|
|
363
|
+
* @param r - The angle in radians.
|
|
364
|
+
* @param out - The matrix to store the result in.
|
|
359
365
|
* @returns The rotated matrix.
|
|
360
366
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
361
367
|
*/
|
|
362
|
-
export
|
|
368
|
+
export const rotate = <T extends Matrix2Like>(
|
|
363
369
|
matrix: Matrix2Like,
|
|
364
|
-
|
|
370
|
+
r: number,
|
|
365
371
|
out: T
|
|
366
|
-
): T {
|
|
367
|
-
const a0
|
|
368
|
-
const a1
|
|
369
|
-
const a2
|
|
370
|
-
const a3
|
|
372
|
+
): T => {
|
|
373
|
+
const a0 = matrix[0];
|
|
374
|
+
const a1 = matrix[1];
|
|
375
|
+
const a2 = matrix[2];
|
|
376
|
+
const a3 = matrix[3];
|
|
371
377
|
|
|
372
|
-
const s
|
|
373
|
-
const c
|
|
378
|
+
const s = Math.sin(r);
|
|
379
|
+
const c = Math.cos(r);
|
|
374
380
|
|
|
375
381
|
out[0] = a0 * c + a2 * s;
|
|
376
382
|
out[1] = a1 * c + a3 * s;
|
|
377
383
|
out[2] = a0 * -s + a2 * c;
|
|
378
384
|
out[3] = a1 * -s + a3 * c;
|
|
379
385
|
return out;
|
|
380
|
-
}
|
|
386
|
+
};
|
|
381
387
|
|
|
382
388
|
/**
|
|
383
|
-
*
|
|
384
|
-
* @param matrix The matrix.
|
|
385
|
-
* @param vector The scaling vector.
|
|
386
|
-
* @param out The matrix to store the result in.
|
|
389
|
+
* Scale a matrix by the given vector.
|
|
390
|
+
* @param matrix - The matrix.
|
|
391
|
+
* @param vector - The scaling vector.
|
|
392
|
+
* @param out - The matrix to store the result in.
|
|
387
393
|
* @returns The scaled matrix.
|
|
388
394
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
389
395
|
*/
|
|
390
|
-
export
|
|
396
|
+
export const scale = <T extends Matrix2Like>(
|
|
391
397
|
matrix: Matrix2Like,
|
|
392
398
|
vector: Vector2Like,
|
|
393
399
|
out: T
|
|
394
|
-
): T {
|
|
395
|
-
const v0
|
|
396
|
-
const v1
|
|
400
|
+
): T => {
|
|
401
|
+
const v0 = vector[0];
|
|
402
|
+
const v1 = vector[1];
|
|
397
403
|
|
|
398
404
|
out[0] = matrix[0] * v0;
|
|
399
405
|
out[1] = matrix[1] * v0;
|
|
400
406
|
out[2] = matrix[2] * v1;
|
|
401
407
|
out[3] = matrix[3] * v1;
|
|
402
408
|
return out;
|
|
403
|
-
}
|
|
409
|
+
};
|
|
404
410
|
|
|
405
411
|
/**
|
|
406
412
|
* A two-by-two matrix.
|
|
407
413
|
* @see [Matrix](https://en.wikipedia.org/wiki/Matrix_(mathematics))
|
|
408
414
|
*/
|
|
409
|
-
export default class Matrix2
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
415
|
+
export default class Matrix2
|
|
416
|
+
extends Float32Array
|
|
417
|
+
implements SquareMatrix, Matrix2Like
|
|
418
|
+
{
|
|
419
|
+
/**
|
|
420
|
+
* Create a transformation matrix that represents a rotation by the given angle around the Z-axis.
|
|
421
|
+
* @param r - The angle in radians.
|
|
422
|
+
* @param out - The matrix to store the result in.
|
|
414
423
|
* @returns The transformation matrix.
|
|
415
424
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
416
425
|
*/
|
|
417
|
-
public static fromRotation(radians: number): Matrix2;
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* Creates a transformation matrix that represents a rotation by the given
|
|
421
|
-
* angle around the Z-axis.
|
|
422
|
-
* @param radians The angle in radians.
|
|
423
|
-
* @param out The matrix to store the result in.
|
|
424
|
-
* @returns The transformation matrix.
|
|
425
|
-
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
426
|
-
*/
|
|
427
|
-
public static fromRotation<T extends Matrix2Like>(radians: number, out: T): T;
|
|
428
|
-
|
|
429
426
|
public static fromRotation<T extends Matrix2Like>(
|
|
430
|
-
|
|
431
|
-
out
|
|
427
|
+
r: number,
|
|
428
|
+
out = new Matrix2() as unknown as T
|
|
432
429
|
): T {
|
|
433
|
-
return fromRotation(
|
|
430
|
+
return fromRotation(r, out);
|
|
434
431
|
}
|
|
435
432
|
|
|
436
433
|
/**
|
|
437
|
-
*
|
|
438
|
-
* vector.
|
|
439
|
-
* @param
|
|
434
|
+
* Create a transformation matrix that represents a scaling by the given vector.
|
|
435
|
+
* @param vector - The scaling vector.
|
|
436
|
+
* @param out - The matrix to store the result in.
|
|
440
437
|
* @returns The transformation matrix.
|
|
441
438
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
442
439
|
*/
|
|
443
|
-
public static fromScaling(vector: Vector2Like): Matrix2;
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* Creates a transformation matrix that represents a scaling by the given
|
|
447
|
-
* vector.
|
|
448
|
-
* @param vector The scaling vector.
|
|
449
|
-
* @param out The matrix to store the result in.
|
|
450
|
-
* @returns The transformation matrix.
|
|
451
|
-
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
452
|
-
*/
|
|
453
|
-
public static fromScaling<T extends Matrix2Like>(
|
|
454
|
-
vector: Vector2Like,
|
|
455
|
-
out: T
|
|
456
|
-
): T;
|
|
457
|
-
|
|
458
440
|
public static fromScaling<T extends Matrix2Like>(
|
|
459
441
|
vector: Vector2Like,
|
|
460
|
-
out
|
|
442
|
+
out = new Matrix2() as unknown as T
|
|
461
443
|
): T {
|
|
462
444
|
return fromScaling(vector, out);
|
|
463
445
|
}
|
|
464
446
|
|
|
465
447
|
/**
|
|
466
|
-
*
|
|
467
|
-
* @param c0r0 The value in the first column and first row.
|
|
468
|
-
* @param c0r1 The value in the first column and second row.
|
|
469
|
-
* @param c1r0 The value in the second column and first row.
|
|
470
|
-
* @param c1r1 The value in the second column and second row.
|
|
471
|
-
* @
|
|
472
|
-
*/
|
|
473
|
-
public static fromValues(
|
|
474
|
-
c0r0: number,
|
|
475
|
-
c0r1: number,
|
|
476
|
-
c1r0: number,
|
|
477
|
-
c1r1: number
|
|
478
|
-
): Matrix2;
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* Creates a two-by-two matrix with the given values.
|
|
482
|
-
* @param c0r0 The value in the first column and first row.
|
|
483
|
-
* @param c0r1 The value in the first column and second row.
|
|
484
|
-
* @param c1r0 The value in the second column and first row.
|
|
485
|
-
* @param c1r1 The value in the second column and second row.
|
|
486
|
-
* @param out The matrix to store the result in.
|
|
448
|
+
* Create a two-by-two matrix with the given values.
|
|
449
|
+
* @param c0r0 - The value in the first column and first row.
|
|
450
|
+
* @param c0r1 - The value in the first column and second row.
|
|
451
|
+
* @param c1r0 - The value in the second column and first row.
|
|
452
|
+
* @param c1r1 - The value in the second column and second row.
|
|
453
|
+
* @param out - The matrix to store the result in.
|
|
487
454
|
* @returns The matrix.
|
|
488
455
|
*/
|
|
489
456
|
public static fromValues<T extends Matrix2Like>(
|
|
@@ -491,21 +458,13 @@ export default class Matrix2 extends Float32Array implements SquareMatrix {
|
|
|
491
458
|
c0r1: number,
|
|
492
459
|
c1r0: number,
|
|
493
460
|
c1r1: number,
|
|
494
|
-
out
|
|
495
|
-
): T;
|
|
496
|
-
|
|
497
|
-
public static fromValues<T extends Matrix2Like>(
|
|
498
|
-
c0r0: number,
|
|
499
|
-
c0r1: number,
|
|
500
|
-
c1r0: number,
|
|
501
|
-
c1r1: number,
|
|
502
|
-
out: T = new Matrix2() as T
|
|
461
|
+
out = new Matrix2() as unknown as T
|
|
503
462
|
): T {
|
|
504
463
|
return fromValues(c0r0, c0r1, c1r0, c1r1, out);
|
|
505
464
|
}
|
|
506
465
|
|
|
507
466
|
/**
|
|
508
|
-
*
|
|
467
|
+
* Create a two-by-two identity matrix.
|
|
509
468
|
* @see [Identity matrix](https://en.wikipedia.org/wiki/Identity_matrix)
|
|
510
469
|
*/
|
|
511
470
|
public constructor() {
|
|
@@ -518,6 +477,18 @@ export default class Matrix2 extends Float32Array implements SquareMatrix {
|
|
|
518
477
|
this.height = 2;
|
|
519
478
|
}
|
|
520
479
|
|
|
480
|
+
/** The value in the first column and first row. */
|
|
481
|
+
public 0: number;
|
|
482
|
+
|
|
483
|
+
/** The value in the first column and second row. */
|
|
484
|
+
public 1: number;
|
|
485
|
+
|
|
486
|
+
/** The value in the second column and first row. */
|
|
487
|
+
public 2: number;
|
|
488
|
+
|
|
489
|
+
/** The value in the second column and second row. */
|
|
490
|
+
public 3: number;
|
|
491
|
+
|
|
521
492
|
/** The number of columns in this matrix. */
|
|
522
493
|
public readonly width: 2;
|
|
523
494
|
|
|
@@ -525,8 +496,8 @@ export default class Matrix2 extends Float32Array implements SquareMatrix {
|
|
|
525
496
|
public readonly height: 2;
|
|
526
497
|
|
|
527
498
|
/**
|
|
528
|
-
*
|
|
529
|
-
* @param matrix The other matrix.
|
|
499
|
+
* Determine whether or not this matrix is roughly equivalent to another.
|
|
500
|
+
* @param matrix - The other matrix.
|
|
530
501
|
* @returns Whether the matrices are equivalent.
|
|
531
502
|
*/
|
|
532
503
|
public equals(matrix: Matrix2Like): boolean {
|
|
@@ -534,8 +505,8 @@ export default class Matrix2 extends Float32Array implements SquareMatrix {
|
|
|
534
505
|
}
|
|
535
506
|
|
|
536
507
|
/**
|
|
537
|
-
*
|
|
538
|
-
* @param matrix The other matrix.
|
|
508
|
+
* Determine whether or not this matrix is exactly equivalent to another.
|
|
509
|
+
* @param matrix - The other matrix.
|
|
539
510
|
* @returns Whether the matrices are equivalent.
|
|
540
511
|
*/
|
|
541
512
|
public exactEquals(matrix: Matrix2Like): boolean {
|
|
@@ -543,68 +514,43 @@ export default class Matrix2 extends Float32Array implements SquareMatrix {
|
|
|
543
514
|
}
|
|
544
515
|
|
|
545
516
|
/**
|
|
546
|
-
*
|
|
547
|
-
* @param matrix The other matrix.
|
|
548
|
-
* @
|
|
549
|
-
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
550
|
-
*/
|
|
551
|
-
public add(matrix: Matrix2Like): Matrix2;
|
|
552
|
-
|
|
553
|
-
/**
|
|
554
|
-
* Adds another matrix to this one.
|
|
555
|
-
* @param matrix The other matrix.
|
|
556
|
-
* @param out The matrix to store the result in.
|
|
517
|
+
* Add another matrix to this one.
|
|
518
|
+
* @param matrix - The other matrix.
|
|
519
|
+
* @param out - The matrix to store the result in.
|
|
557
520
|
* @returns The sum of the matrices.
|
|
558
521
|
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
559
522
|
*/
|
|
560
|
-
public add<T extends Matrix2Like>(matrix: Matrix2Like, out: T): T;
|
|
561
|
-
|
|
562
523
|
public add<T extends Matrix2Like>(
|
|
563
524
|
matrix: Matrix2Like,
|
|
564
|
-
out
|
|
525
|
+
out = new Matrix2() as unknown as T
|
|
565
526
|
): T {
|
|
566
527
|
return add(this, matrix, out);
|
|
567
528
|
}
|
|
568
529
|
|
|
569
530
|
/**
|
|
570
|
-
*
|
|
531
|
+
* Calculate the adjugate of this matrix.
|
|
532
|
+
* @param out - The matrix to store the result in.
|
|
571
533
|
* @returns The adjugate of this matrix.
|
|
572
534
|
* @see [Adjugate matrix](https://en.wikipedia.org/wiki/Adjugate_matrix)
|
|
573
535
|
*/
|
|
574
|
-
public adjoint(
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
* Calculates the adjugate of this matrix.
|
|
578
|
-
* @param out The matrix to store the result in.
|
|
579
|
-
* @returns The adjugate of this matrix.
|
|
580
|
-
* @see [Adjugate matrix](https://en.wikipedia.org/wiki/Adjugate_matrix)
|
|
581
|
-
*/
|
|
582
|
-
public adjoint<T extends Matrix2Like>(out: T): T;
|
|
583
|
-
|
|
584
|
-
public adjoint<T extends Matrix2Like>(out: T = new Matrix2() as T): T {
|
|
536
|
+
public adjoint<T extends Matrix2Like>(
|
|
537
|
+
out = new Matrix2() as unknown as T
|
|
538
|
+
): T {
|
|
585
539
|
return adjoint(this, out);
|
|
586
540
|
}
|
|
587
541
|
|
|
588
542
|
/**
|
|
589
|
-
*
|
|
590
|
-
* @
|
|
591
|
-
*/
|
|
592
|
-
public clone(): Matrix2;
|
|
593
|
-
|
|
594
|
-
/**
|
|
595
|
-
* Copies the values from this matrix to another one.
|
|
596
|
-
* @param out The matrix to store the result in.
|
|
543
|
+
* Copy the values from this matrix to another one.
|
|
544
|
+
* @param out - The matrix to store the result in.
|
|
597
545
|
* @returns The copy.
|
|
598
546
|
*/
|
|
599
|
-
public clone<T extends Matrix2Like>(out
|
|
600
|
-
|
|
601
|
-
public clone<T extends Matrix2Like>(out: T = new Matrix2() as T): T {
|
|
547
|
+
public clone<T extends Matrix2Like>(out = new Matrix2() as unknown as T): T {
|
|
602
548
|
return copy(this, out);
|
|
603
549
|
}
|
|
604
550
|
|
|
605
551
|
/**
|
|
606
|
-
*
|
|
607
|
-
* @param matrix The matrix to copy.
|
|
552
|
+
* Copy the values of another matrix into this one.
|
|
553
|
+
* @param matrix - The matrix to copy.
|
|
608
554
|
* @returns This matrix.
|
|
609
555
|
*/
|
|
610
556
|
public copy(matrix: Matrix2Like): this {
|
|
@@ -612,7 +558,7 @@ export default class Matrix2 extends Float32Array implements SquareMatrix {
|
|
|
612
558
|
}
|
|
613
559
|
|
|
614
560
|
/**
|
|
615
|
-
*
|
|
561
|
+
* Get the Frobenius norm of this matrix.
|
|
616
562
|
* @see [Matrix norm](https://en.wikipedia.org/wiki/Matrix_norm)
|
|
617
563
|
*/
|
|
618
564
|
public get frob(): number {
|
|
@@ -620,68 +566,38 @@ export default class Matrix2 extends Float32Array implements SquareMatrix {
|
|
|
620
566
|
}
|
|
621
567
|
|
|
622
568
|
/**
|
|
623
|
-
*
|
|
624
|
-
* @param matrix The other matrix.
|
|
625
|
-
* @
|
|
626
|
-
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
627
|
-
*/
|
|
628
|
-
public multiply(matrix: Matrix2Like): Matrix2;
|
|
629
|
-
|
|
630
|
-
/**
|
|
631
|
-
* Multiplies this matrix by another.
|
|
632
|
-
* @param matrix The other matrix.
|
|
633
|
-
* @param out The matrix to store the result in.
|
|
569
|
+
* Multiply this matrix by another.
|
|
570
|
+
* @param matrix - The other matrix.
|
|
571
|
+
* @param out - The matrix to store the result in.
|
|
634
572
|
* @returns The product of the matrices.
|
|
635
573
|
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
636
574
|
*/
|
|
637
|
-
public multiply<T extends Matrix2Like>(matrix: Matrix2Like, out: T): T;
|
|
638
|
-
|
|
639
575
|
public multiply<T extends Matrix2Like>(
|
|
640
576
|
matrix: Matrix2Like,
|
|
641
|
-
out
|
|
577
|
+
out = new Matrix2() as unknown as T
|
|
642
578
|
): T {
|
|
643
579
|
return multiply(this, matrix, out);
|
|
644
580
|
}
|
|
645
581
|
|
|
646
582
|
/**
|
|
647
|
-
*
|
|
648
|
-
* @param scalar The scalar value.
|
|
649
|
-
* @
|
|
650
|
-
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
651
|
-
*/
|
|
652
|
-
public multiplyScalar(scalar: number): Matrix2;
|
|
653
|
-
|
|
654
|
-
/**
|
|
655
|
-
* Multiplies this matrix by a scalar value.
|
|
656
|
-
* @param scalar The scalar value.
|
|
657
|
-
* @param out The matrix to store the result in.
|
|
583
|
+
* Multiply this matrix by a scalar value.
|
|
584
|
+
* @param scalar - The scalar value.
|
|
585
|
+
* @param out - The matrix to store the result in.
|
|
658
586
|
* @returns The product of the matrix and the scalar value.
|
|
659
587
|
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
660
588
|
*/
|
|
661
|
-
public multiplyScalar<T extends Matrix2Like>(scalar: number, out: T): T;
|
|
662
|
-
|
|
663
589
|
public multiplyScalar<T extends Matrix2Like>(
|
|
664
590
|
scalar: number,
|
|
665
|
-
out
|
|
591
|
+
out = new Matrix2() as unknown as T
|
|
666
592
|
): T {
|
|
667
593
|
return multiplyScalar(this, scalar, out);
|
|
668
594
|
}
|
|
669
595
|
|
|
670
596
|
/**
|
|
671
|
-
*
|
|
672
|
-
* @param matrix The other matrix.
|
|
673
|
-
* @param scalar The scalar.
|
|
674
|
-
* @
|
|
675
|
-
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
676
|
-
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
677
|
-
*/
|
|
678
|
-
public multiplyScalarAndAdd(matrix: Matrix2Like, scalar: number): Matrix2;
|
|
679
|
-
|
|
680
|
-
/**
|
|
681
|
-
* Adds this matrix to another after multiplying the other by a scalar.
|
|
682
|
-
* @param matrix The other matrix.
|
|
683
|
-
* @param scalar The scalar.
|
|
684
|
-
* @param out The matrix to store the result in.
|
|
597
|
+
* Add this matrix to another after multiplying the other by a scalar.
|
|
598
|
+
* @param matrix - The other matrix.
|
|
599
|
+
* @param scalar - The scalar.
|
|
600
|
+
* @param out - The matrix to store the result in.
|
|
685
601
|
* @returns The sum.
|
|
686
602
|
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
687
603
|
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
@@ -689,62 +605,39 @@ export default class Matrix2 extends Float32Array implements SquareMatrix {
|
|
|
689
605
|
public multiplyScalarAndAdd<T extends Matrix2Like>(
|
|
690
606
|
matrix: Matrix2Like,
|
|
691
607
|
scalar: number,
|
|
692
|
-
out
|
|
693
|
-
): T;
|
|
694
|
-
|
|
695
|
-
public multiplyScalarAndAdd<T extends Matrix2Like>(
|
|
696
|
-
matrix: Matrix2Like,
|
|
697
|
-
scalar: number,
|
|
698
|
-
out: T = new Matrix2() as T
|
|
608
|
+
out = new Matrix2() as unknown as T
|
|
699
609
|
): T {
|
|
700
610
|
return multiplyScalarAndAdd(this, matrix, scalar, out);
|
|
701
611
|
}
|
|
702
612
|
|
|
703
613
|
/**
|
|
704
|
-
*
|
|
705
|
-
* @param matrix The other matrix.
|
|
614
|
+
* Subtract another matrix from this one.
|
|
615
|
+
* @param matrix - The other matrix.
|
|
616
|
+
* @param out - The matrix to store the result in.
|
|
706
617
|
* @returns The difference between the matrices.
|
|
707
618
|
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
708
619
|
*/
|
|
709
|
-
public subtract(matrix: Matrix2Like): Matrix2;
|
|
710
|
-
|
|
711
|
-
/**
|
|
712
|
-
* Subtracts another matrix from this one.
|
|
713
|
-
* @param matrix The other matrix.
|
|
714
|
-
* @param out The matrix to store the result in.
|
|
715
|
-
* @returns The difference between the matrices.
|
|
716
|
-
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
717
|
-
*/
|
|
718
|
-
public subtract<T extends Matrix2Like>(matrix: Matrix2Like, out: T): T;
|
|
719
|
-
|
|
720
620
|
public subtract<T extends Matrix2Like>(
|
|
721
621
|
matrix: Matrix2Like,
|
|
722
|
-
out
|
|
622
|
+
out = new Matrix2() as unknown as T
|
|
723
623
|
): T {
|
|
724
624
|
return subtract(this, matrix, out);
|
|
725
625
|
}
|
|
726
626
|
|
|
727
627
|
/**
|
|
728
|
-
*
|
|
628
|
+
* Transpose this matrix.
|
|
629
|
+
* @param out - The matrix to store the result in.
|
|
729
630
|
* @returns The transpose of this matrix.
|
|
730
631
|
* @see [Transpose](https://en.wikipedia.org/wiki/Transpose)
|
|
731
632
|
*/
|
|
732
|
-
public transpose(
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
* Transposes this matrix.
|
|
736
|
-
* @param out The matrix to store the result in.
|
|
737
|
-
* @returns The transpose of this matrix.
|
|
738
|
-
* @see [Transpose](https://en.wikipedia.org/wiki/Transpose)
|
|
739
|
-
*/
|
|
740
|
-
public transpose<T extends Matrix2Like>(out: T): T;
|
|
741
|
-
|
|
742
|
-
public transpose<T extends Matrix2Like>(out: T = new Matrix2() as T): T {
|
|
633
|
+
public transpose<T extends Matrix2Like>(
|
|
634
|
+
out = new Matrix2() as unknown as T
|
|
635
|
+
): T {
|
|
743
636
|
return transpose(this, out);
|
|
744
637
|
}
|
|
745
638
|
|
|
746
639
|
/**
|
|
747
|
-
*
|
|
640
|
+
* Get the determinant of this matrix.
|
|
748
641
|
* @see [Determinant](https://en.wikipedia.org/wiki/Determinant)
|
|
749
642
|
*/
|
|
750
643
|
public get determinant(): number {
|
|
@@ -752,7 +645,7 @@ export default class Matrix2 extends Float32Array implements SquareMatrix {
|
|
|
752
645
|
}
|
|
753
646
|
|
|
754
647
|
/**
|
|
755
|
-
*
|
|
648
|
+
* Reset this matrix to identity.
|
|
756
649
|
* @returns This matrix.
|
|
757
650
|
* @see [Identity matrix](https://en.wikipedia.org/wiki/Identity_matrix)
|
|
758
651
|
*/
|
|
@@ -761,68 +654,39 @@ export default class Matrix2 extends Float32Array implements SquareMatrix {
|
|
|
761
654
|
}
|
|
762
655
|
|
|
763
656
|
/**
|
|
764
|
-
*
|
|
765
|
-
* @
|
|
766
|
-
* @see [Invertible matrix](https://en.wikipedia.org/wiki/Invertible_matrix)
|
|
767
|
-
*/
|
|
768
|
-
public invert(): Matrix2;
|
|
769
|
-
|
|
770
|
-
/**
|
|
771
|
-
* Inverts this matrix.
|
|
772
|
-
* @param out The matrix to store the result in.
|
|
657
|
+
* Invert this matrix.
|
|
658
|
+
* @param out - The matrix to store the result in.
|
|
773
659
|
* @returns The inverted matrix.
|
|
774
660
|
* @see [Invertible matrix](https://en.wikipedia.org/wiki/Invertible_matrix)
|
|
775
661
|
*/
|
|
776
|
-
public invert<T extends Matrix2Like>(out
|
|
777
|
-
|
|
778
|
-
public invert<T extends Matrix2Like>(out: T = new Matrix2() as T): T {
|
|
662
|
+
public invert<T extends Matrix2Like>(out = new Matrix2() as unknown as T): T {
|
|
779
663
|
return invert(this, out);
|
|
780
664
|
}
|
|
781
665
|
|
|
782
666
|
/**
|
|
783
|
-
*
|
|
784
|
-
* @param
|
|
667
|
+
* Rotate this matrix by the given angle.
|
|
668
|
+
* @param r - The angle in radians.
|
|
669
|
+
* @param out - The matrix to store the result in.
|
|
785
670
|
* @returns The rotated matrix.
|
|
786
671
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
787
672
|
*/
|
|
788
|
-
public rotate(radians: number): Matrix2;
|
|
789
|
-
|
|
790
|
-
/**
|
|
791
|
-
* Rotates this matrix by the given angle.
|
|
792
|
-
* @param radians The angle in radians.
|
|
793
|
-
* @param out The matrix to store the result in.
|
|
794
|
-
* @returns The rotated matrix.
|
|
795
|
-
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
796
|
-
*/
|
|
797
|
-
public rotate<T extends Matrix2Like>(radians: number, out: T): T;
|
|
798
|
-
|
|
799
673
|
public rotate<T extends Matrix2Like>(
|
|
800
|
-
|
|
801
|
-
out
|
|
674
|
+
r: number,
|
|
675
|
+
out = new Matrix2() as unknown as T
|
|
802
676
|
): T {
|
|
803
|
-
return rotate(this,
|
|
677
|
+
return rotate(this, r, out);
|
|
804
678
|
}
|
|
805
679
|
|
|
806
680
|
/**
|
|
807
|
-
*
|
|
808
|
-
* @param
|
|
809
|
-
* @
|
|
810
|
-
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
811
|
-
*/
|
|
812
|
-
public scale(v: Vector2Like): Matrix2;
|
|
813
|
-
|
|
814
|
-
/**
|
|
815
|
-
* Scales this matrix by the given vector.
|
|
816
|
-
* @param vector The scaling vector.
|
|
817
|
-
* @param out The matrix to store the result in.
|
|
681
|
+
* Scale this matrix by the given vector.
|
|
682
|
+
* @param vector - The scaling vector.
|
|
683
|
+
* @param out - The matrix to store the result in.
|
|
818
684
|
* @returns The scaled matrix.
|
|
819
685
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
820
686
|
*/
|
|
821
|
-
public scale<T extends Matrix2Like>(vector: Vector2Like, out: T): T;
|
|
822
|
-
|
|
823
687
|
public scale<T extends Matrix2Like>(
|
|
824
688
|
vector: Vector2Like,
|
|
825
|
-
out
|
|
689
|
+
out = new Matrix2() as unknown as T
|
|
826
690
|
): T {
|
|
827
691
|
return scale(this, vector, out);
|
|
828
692
|
}
|