@lakuna/umath 2.0.0 → 3.0.1
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/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.js +14 -4
- package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/linalg/DualQuaternion.d.ts +158 -158
- package/dist/linalg/DualQuaternion.d.ts.map +1 -1
- package/dist/linalg/DualQuaternion.js +173 -165
- package/dist/linalg/DualQuaternion.js.map +1 -1
- package/dist/linalg/Matrix.d.ts +24 -24
- package/dist/linalg/Matrix.d.ts.map +1 -1
- package/dist/linalg/Matrix2.d.ts +85 -85
- package/dist/linalg/Matrix2.d.ts.map +1 -1
- package/dist/linalg/Matrix2.js +92 -88
- package/dist/linalg/Matrix2.js.map +1 -1
- package/dist/linalg/Matrix3.d.ts +134 -134
- package/dist/linalg/Matrix3.d.ts.map +1 -1
- package/dist/linalg/Matrix3.js +147 -138
- package/dist/linalg/Matrix3.js.map +1 -1
- package/dist/linalg/Matrix4.d.ts +245 -246
- package/dist/linalg/Matrix4.d.ts.map +1 -1
- package/dist/linalg/Matrix4.js +272 -251
- package/dist/linalg/Matrix4.js.map +1 -1
- package/dist/linalg/Quaternion.d.ts +147 -146
- package/dist/linalg/Quaternion.d.ts.map +1 -1
- package/dist/linalg/Quaternion.js +175 -161
- package/dist/linalg/Quaternion.js.map +1 -1
- package/dist/linalg/SlowMatrix.d.ts +12 -12
- package/dist/linalg/SlowMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowMatrix.js +12 -12
- package/dist/linalg/SlowMatrix.js.map +1 -1
- package/dist/linalg/SlowSquareMatrix.d.ts +7 -7
- package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowSquareMatrix.js +15 -15
- package/dist/linalg/SlowSquareMatrix.js.map +1 -1
- package/dist/linalg/SlowVector.d.ts +77 -77
- package/dist/linalg/SlowVector.d.ts.map +1 -1
- package/dist/linalg/SlowVector.js +153 -153
- package/dist/linalg/SlowVector.js.map +1 -1
- package/dist/linalg/SquareMatrix.d.ts +8 -8
- package/dist/linalg/SquareMatrix.d.ts.map +1 -1
- package/dist/linalg/Vector.d.ts +85 -84
- package/dist/linalg/Vector.d.ts.map +1 -1
- package/dist/linalg/Vector2.d.ts +143 -143
- package/dist/linalg/Vector2.d.ts.map +1 -1
- package/dist/linalg/Vector2.js +145 -143
- package/dist/linalg/Vector2.js.map +1 -1
- package/dist/linalg/Vector3.d.ts +173 -173
- package/dist/linalg/Vector3.d.ts.map +1 -1
- package/dist/linalg/Vector3.js +176 -173
- package/dist/linalg/Vector3.js.map +1 -1
- package/dist/linalg/Vector4.d.ts +137 -137
- package/dist/linalg/Vector4.d.ts.map +1 -1
- package/dist/linalg/Vector4.js +144 -140
- package/dist/linalg/Vector4.js.map +1 -1
- package/dist/types/AxisAngle.d.ts +11 -1
- package/dist/types/AxisAngle.d.ts.map +1 -1
- package/dist/types/FieldOfView.d.ts +2 -2
- package/dist/types/FieldOfView.d.ts.map +1 -1
- package/dist/utility/BigNumber.d.ts +21 -11
- package/dist/utility/BigNumber.d.ts.map +1 -1
- package/dist/utility/BigNumber.js +49 -31
- package/dist/utility/BigNumber.js.map +1 -1
- package/dist/utility/createAxisAngleLike.d.ts.map +1 -1
- package/dist/utility/createAxisAngleLike.js.map +1 -1
- package/package.json +13 -12
- package/src/algorithms/greatestCommonDivisor.ts +19 -7
- package/src/index.ts +21 -14
- package/src/linalg/DualQuaternion.ts +264 -238
- package/src/linalg/Matrix.ts +31 -28
- package/src/linalg/Matrix2.ts +157 -137
- package/src/linalg/Matrix3.ts +222 -191
- package/src/linalg/Matrix4.ts +464 -412
- package/src/linalg/Quaternion.ts +267 -234
- package/src/linalg/SlowMatrix.ts +31 -27
- package/src/linalg/SlowSquareMatrix.ts +19 -18
- package/src/linalg/SlowVector.ts +175 -174
- package/src/linalg/SquareMatrix.ts +9 -9
- package/src/linalg/Vector.ts +91 -89
- package/src/linalg/Vector2.ts +250 -217
- package/src/linalg/Vector3.ts +309 -269
- package/src/linalg/Vector4.ts +246 -206
- package/src/types/AxisAngle.ts +13 -1
- package/src/types/FieldOfView.ts +3 -3
- package/src/utility/BigNumber.ts +71 -38
- package/src/utility/createAxisAngleLike.ts +1 -0
package/src/linalg/Matrix.ts
CHANGED
|
@@ -1,63 +1,54 @@
|
|
|
1
1
|
import type { Matrix4Like } from "./Matrix4.js";
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* An object that could be interpreted as a matrix.
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export type MatrixLike = Record<number, number>;
|
|
8
|
-
|
|
9
3
|
/**
|
|
10
4
|
* A rectangular array of numbers, arranged in rows and columns.
|
|
11
5
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_(mathematics) | Matrix}
|
|
12
6
|
* @public
|
|
13
7
|
*/
|
|
14
8
|
export default interface Matrix extends MatrixLike {
|
|
15
|
-
/** The number of rows in this matrix. */
|
|
16
|
-
height: number;
|
|
17
|
-
|
|
18
|
-
/** The number of columns in this matrix. */
|
|
19
|
-
width: number;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Get the Frobenius norm of this matrix.
|
|
23
|
-
* @see {@link https://en.wikipedia.org/wiki/Matrix_norm | Matrix norm}
|
|
24
|
-
*/
|
|
25
|
-
get frob(): number;
|
|
26
|
-
|
|
27
9
|
/**
|
|
28
10
|
* Add two matrices of the same size.
|
|
29
11
|
* @param matrix - The other matrix.
|
|
30
12
|
* @returns The sum of the matrices.
|
|
31
13
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
|
|
32
14
|
*/
|
|
33
|
-
add(matrix: Matrix4Like)
|
|
15
|
+
add: (matrix: Readonly<Matrix4Like>) => MatrixLike;
|
|
34
16
|
|
|
35
17
|
/**
|
|
36
18
|
* Create a copy of this matrix.
|
|
37
19
|
* @returns A copy of this matrix.
|
|
38
20
|
*/
|
|
39
|
-
clone()
|
|
21
|
+
clone: () => MatrixLike;
|
|
40
22
|
|
|
41
23
|
/**
|
|
42
24
|
* Copy the values of another matrix into this one.
|
|
43
25
|
* @param matrix - The matrix to copy.
|
|
44
26
|
* @returns This matrix.
|
|
45
27
|
*/
|
|
46
|
-
copy(matrix: Matrix4Like)
|
|
28
|
+
copy: (matrix: Readonly<Matrix4Like>) => this;
|
|
47
29
|
|
|
48
30
|
/**
|
|
49
31
|
* Determine whether or not this matrix is roughly equivalent to another.
|
|
50
32
|
* @param matrix - The other matrix.
|
|
51
33
|
* @returns Whether the matrices are equivalent.
|
|
52
34
|
*/
|
|
53
|
-
equals(matrix: Matrix4Like)
|
|
35
|
+
equals: (matrix: Readonly<Matrix4Like>) => boolean;
|
|
54
36
|
|
|
55
37
|
/**
|
|
56
38
|
* Determine whether or not this matrix is exactly equivalent to another.
|
|
57
39
|
* @param matrix - The other matrix.
|
|
58
40
|
* @returns Whether the matrices are equivalent.
|
|
59
41
|
*/
|
|
60
|
-
exactEquals(matrix: Matrix4Like)
|
|
42
|
+
exactEquals: (matrix: Readonly<Matrix4Like>) => boolean;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get the Frobenius norm of this matrix.
|
|
46
|
+
* @see {@link https://en.wikipedia.org/wiki/Matrix_norm | Matrix norm}
|
|
47
|
+
*/
|
|
48
|
+
get frob(): number;
|
|
49
|
+
|
|
50
|
+
/** The number of rows in this matrix. */
|
|
51
|
+
height: number;
|
|
61
52
|
|
|
62
53
|
/**
|
|
63
54
|
* Multiply this matrix by another.
|
|
@@ -65,7 +56,7 @@ export default interface Matrix extends MatrixLike {
|
|
|
65
56
|
* @returns The product of the matrices.
|
|
66
57
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_multiplication | Matrix multiplication}
|
|
67
58
|
*/
|
|
68
|
-
multiply(matrix: Matrix4Like)
|
|
59
|
+
multiply: (matrix: Readonly<Matrix4Like>) => MatrixLike;
|
|
69
60
|
|
|
70
61
|
/**
|
|
71
62
|
* Multiply this matrix by a scalar value.
|
|
@@ -73,7 +64,7 @@ export default interface Matrix extends MatrixLike {
|
|
|
73
64
|
* @returns The product of the matrix and the scalar value.
|
|
74
65
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_multiplication | Matrix multiplication}
|
|
75
66
|
*/
|
|
76
|
-
multiplyScalar(scalar: number)
|
|
67
|
+
multiplyScalar: (scalar: number) => MatrixLike;
|
|
77
68
|
|
|
78
69
|
/**
|
|
79
70
|
* Add this matrix to another after multiplying the other by a scalar.
|
|
@@ -83,7 +74,10 @@ export default interface Matrix extends MatrixLike {
|
|
|
83
74
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
|
|
84
75
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_multiplication | Matrix multiplication}
|
|
85
76
|
*/
|
|
86
|
-
multiplyScalarAndAdd
|
|
77
|
+
multiplyScalarAndAdd: (
|
|
78
|
+
matrix: Readonly<Matrix4Like>,
|
|
79
|
+
scalar: number
|
|
80
|
+
) => MatrixLike;
|
|
87
81
|
|
|
88
82
|
/**
|
|
89
83
|
* Subtract another matrix from this one.
|
|
@@ -91,12 +85,21 @@ export default interface Matrix extends MatrixLike {
|
|
|
91
85
|
* @returns The difference between the matrices.
|
|
92
86
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
|
|
93
87
|
*/
|
|
94
|
-
subtract(matrix: Matrix4Like)
|
|
88
|
+
subtract: (matrix: Readonly<Matrix4Like>) => MatrixLike;
|
|
95
89
|
|
|
96
90
|
/**
|
|
97
91
|
* Transpose this matrix.
|
|
98
92
|
* @returns The transpose of this matrix.
|
|
99
93
|
* @see {@link https://en.wikipedia.org/wiki/Transpose | Transpose}
|
|
100
94
|
*/
|
|
101
|
-
transpose()
|
|
95
|
+
transpose: () => MatrixLike;
|
|
96
|
+
|
|
97
|
+
/** The number of columns in this matrix. */
|
|
98
|
+
width: number;
|
|
102
99
|
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* An object that could be interpreted as a matrix.
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
export type MatrixLike = Record<number, number>;
|
package/src/linalg/Matrix2.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import type { MatrixLike } from "./Matrix.js";
|
|
2
|
+
import type SquareMatrix from "./SquareMatrix.js";
|
|
3
|
+
import type { Vector2Like } from "./Vector2.js";
|
|
4
|
+
|
|
5
|
+
import approxRelative from "../algorithms/approxRelative.js";
|
|
6
|
+
import SingularMatrixError from "../utility/SingularMatrixError.js";
|
|
1
7
|
import {
|
|
2
8
|
add as vector4Add,
|
|
3
9
|
copy as vector4Copy,
|
|
@@ -8,11 +14,6 @@ import {
|
|
|
8
14
|
scaleAndAdd as vector4ScaleAndAdd,
|
|
9
15
|
subtract as vector4Subtract
|
|
10
16
|
} from "./Vector4.js";
|
|
11
|
-
import type { MatrixLike } from "./Matrix.js";
|
|
12
|
-
import SingularMatrixError from "../utility/SingularMatrixError.js";
|
|
13
|
-
import type SquareMatrix from "./SquareMatrix.js";
|
|
14
|
-
import type { Vector2Like } from "./Vector2.js";
|
|
15
|
-
import approxRelative from "../algorithms/approxRelative.js";
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Numbers arranged into two columns and two rows.
|
|
@@ -21,15 +22,19 @@ import approxRelative from "../algorithms/approxRelative.js";
|
|
|
21
22
|
*/
|
|
22
23
|
export interface Matrix2Like extends MatrixLike {
|
|
23
24
|
/** The value in the first column and first row. */
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
24
26
|
0: number;
|
|
25
27
|
|
|
26
28
|
/** The value in the first column and second row. */
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
27
30
|
1: number;
|
|
28
31
|
|
|
29
32
|
/** The value in the second column and first row. */
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
30
34
|
2: number;
|
|
31
35
|
|
|
32
36
|
/** The value in the second column and second row. */
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
33
38
|
3: number;
|
|
34
39
|
}
|
|
35
40
|
|
|
@@ -38,9 +43,9 @@ export interface Matrix2Like extends MatrixLike {
|
|
|
38
43
|
* @returns A two-by-two matrix-like object.
|
|
39
44
|
* @public
|
|
40
45
|
*/
|
|
41
|
-
export const createMatrix2Like = (): Float32Array & Matrix2Like =>
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
export const createMatrix2Like = (): Float32Array & Matrix2Like =>
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
48
|
+
new Float32Array(4) as Float32Array & Matrix2Like;
|
|
44
49
|
|
|
45
50
|
/**
|
|
46
51
|
* Create a two-by-two matrix with the given values.
|
|
@@ -84,7 +89,7 @@ export const fromRotation = <T extends Matrix2Like>(r: number, out: T): T => {
|
|
|
84
89
|
* @public
|
|
85
90
|
*/
|
|
86
91
|
export const fromScaling = <T extends Matrix2Like>(
|
|
87
|
-
vector: Vector2Like
|
|
92
|
+
vector: Readonly<Vector2Like>,
|
|
88
93
|
out: T
|
|
89
94
|
): T => fromValues(vector[0], 0, 0, vector[1], out);
|
|
90
95
|
|
|
@@ -95,7 +100,10 @@ export const fromScaling = <T extends Matrix2Like>(
|
|
|
95
100
|
* @returns Whether or not the matrices are equivalent.
|
|
96
101
|
* @public
|
|
97
102
|
*/
|
|
98
|
-
export const equals = (
|
|
103
|
+
export const equals = (
|
|
104
|
+
a: Readonly<Matrix2Like>,
|
|
105
|
+
b: Readonly<Matrix2Like>
|
|
106
|
+
): boolean =>
|
|
99
107
|
approxRelative(a[0], b[0]) &&
|
|
100
108
|
approxRelative(a[1], b[1]) &&
|
|
101
109
|
approxRelative(a[2], b[2]) &&
|
|
@@ -108,8 +116,10 @@ export const equals = (a: Matrix2Like, b: Matrix2Like): boolean =>
|
|
|
108
116
|
* @returns Whether the matrices are equivalent.
|
|
109
117
|
* @public
|
|
110
118
|
*/
|
|
111
|
-
export const exactEquals: (
|
|
112
|
-
|
|
119
|
+
export const exactEquals: (
|
|
120
|
+
a: Readonly<Matrix2Like>,
|
|
121
|
+
b: Readonly<Matrix2Like>
|
|
122
|
+
) => boolean = vector4ExactEquals;
|
|
113
123
|
|
|
114
124
|
/**
|
|
115
125
|
* Add two matrices.
|
|
@@ -121,8 +131,8 @@ export const exactEquals: (a: Matrix2Like, b: Matrix2Like) => boolean =
|
|
|
121
131
|
* @public
|
|
122
132
|
*/
|
|
123
133
|
export const add: <T extends Matrix2Like>(
|
|
124
|
-
a: Matrix2Like
|
|
125
|
-
b: Matrix2Like
|
|
134
|
+
a: Readonly<Matrix2Like>,
|
|
135
|
+
b: Readonly<Matrix2Like>,
|
|
126
136
|
out: T
|
|
127
137
|
) => T = vector4Add;
|
|
128
138
|
|
|
@@ -135,7 +145,7 @@ export const add: <T extends Matrix2Like>(
|
|
|
135
145
|
* @public
|
|
136
146
|
*/
|
|
137
147
|
export const adjoint = <T extends Matrix2Like>(
|
|
138
|
-
matrix: Matrix2Like
|
|
148
|
+
matrix: Readonly<Matrix2Like>,
|
|
139
149
|
out: T
|
|
140
150
|
): T => fromValues(matrix[3], -matrix[1], -matrix[2], matrix[0], out);
|
|
141
151
|
|
|
@@ -146,8 +156,10 @@ export const adjoint = <T extends Matrix2Like>(
|
|
|
146
156
|
* @returns The copy matrix.
|
|
147
157
|
* @public
|
|
148
158
|
*/
|
|
149
|
-
export const copy: <T extends Matrix2Like>(
|
|
150
|
-
|
|
159
|
+
export const copy: <T extends Matrix2Like>(
|
|
160
|
+
matrix: Readonly<Matrix2Like>,
|
|
161
|
+
out: T
|
|
162
|
+
) => T = vector4Copy;
|
|
151
163
|
|
|
152
164
|
/**
|
|
153
165
|
* Calculate the Frobenius norm of a matrix.
|
|
@@ -156,7 +168,8 @@ export const copy: <T extends Matrix2Like>(matrix: Matrix2Like, out: T) => T =
|
|
|
156
168
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_norm | Matrix norm}
|
|
157
169
|
* @public
|
|
158
170
|
*/
|
|
159
|
-
export const frob: (matrix: Matrix2Like) => number =
|
|
171
|
+
export const frob: (matrix: Readonly<Matrix2Like>) => number =
|
|
172
|
+
vector4GetMagnitude;
|
|
160
173
|
|
|
161
174
|
/**
|
|
162
175
|
* Multiply one matrix by another.
|
|
@@ -168,8 +181,8 @@ export const frob: (matrix: Matrix2Like) => number = vector4GetMagnitude;
|
|
|
168
181
|
* @public
|
|
169
182
|
*/
|
|
170
183
|
export const multiply = <T extends Matrix2Like>(
|
|
171
|
-
a: Matrix2Like
|
|
172
|
-
b: Matrix2Like
|
|
184
|
+
a: Readonly<Matrix2Like>,
|
|
185
|
+
b: Readonly<Matrix2Like>,
|
|
173
186
|
out: T
|
|
174
187
|
): T => {
|
|
175
188
|
const a0 = a[0];
|
|
@@ -201,7 +214,7 @@ export const multiply = <T extends Matrix2Like>(
|
|
|
201
214
|
* @public
|
|
202
215
|
*/
|
|
203
216
|
export const multiplyScalar: <T extends Matrix2Like>(
|
|
204
|
-
matrix: Matrix2Like
|
|
217
|
+
matrix: Readonly<Matrix2Like>,
|
|
205
218
|
scalar: number,
|
|
206
219
|
out: T
|
|
207
220
|
) => T = vector4Scale;
|
|
@@ -218,8 +231,8 @@ export const multiplyScalar: <T extends Matrix2Like>(
|
|
|
218
231
|
* @public
|
|
219
232
|
*/
|
|
220
233
|
export const multiplyScalarAndAdd: <T extends Matrix2Like>(
|
|
221
|
-
a: Matrix2Like
|
|
222
|
-
b: Matrix2Like
|
|
234
|
+
a: Readonly<Matrix2Like>,
|
|
235
|
+
b: Readonly<Matrix2Like>,
|
|
223
236
|
scalar: number,
|
|
224
237
|
out: T
|
|
225
238
|
) => T = vector4ScaleAndAdd;
|
|
@@ -234,8 +247,8 @@ export const multiplyScalarAndAdd: <T extends Matrix2Like>(
|
|
|
234
247
|
* @public
|
|
235
248
|
*/
|
|
236
249
|
export const subtract: <T extends Matrix2Like>(
|
|
237
|
-
a: Matrix2Like
|
|
238
|
-
b: Matrix2Like
|
|
250
|
+
a: Readonly<Matrix2Like>,
|
|
251
|
+
b: Readonly<Matrix2Like>,
|
|
239
252
|
out: T
|
|
240
253
|
) => T = vector4Subtract;
|
|
241
254
|
|
|
@@ -248,7 +261,7 @@ export const subtract: <T extends Matrix2Like>(
|
|
|
248
261
|
* @public
|
|
249
262
|
*/
|
|
250
263
|
export const transpose = <T extends Matrix2Like>(
|
|
251
|
-
matrix: Matrix2Like
|
|
264
|
+
matrix: Readonly<Matrix2Like>,
|
|
252
265
|
out: T
|
|
253
266
|
): T => {
|
|
254
267
|
if (out === matrix) {
|
|
@@ -268,7 +281,7 @@ export const transpose = <T extends Matrix2Like>(
|
|
|
268
281
|
* @see {@link https://en.wikipedia.org/wiki/Determinant | Determinant}
|
|
269
282
|
* @public
|
|
270
283
|
*/
|
|
271
|
-
export const determinant = (matrix: Matrix2Like): number =>
|
|
284
|
+
export const determinant = (matrix: Readonly<Matrix2Like>): number =>
|
|
272
285
|
matrix[0] * matrix[3] - matrix[2] * matrix[1];
|
|
273
286
|
|
|
274
287
|
/**
|
|
@@ -290,7 +303,7 @@ export const identity = <T extends Matrix2Like>(out: T): T =>
|
|
|
290
303
|
* @public
|
|
291
304
|
*/
|
|
292
305
|
export const invert = <T extends Matrix2Like>(
|
|
293
|
-
matrix: Matrix2Like
|
|
306
|
+
matrix: Readonly<Matrix2Like>,
|
|
294
307
|
out: T
|
|
295
308
|
): T => {
|
|
296
309
|
const a0 = matrix[0];
|
|
@@ -317,7 +330,7 @@ export const invert = <T extends Matrix2Like>(
|
|
|
317
330
|
* @public
|
|
318
331
|
*/
|
|
319
332
|
export const rotate = <T extends Matrix2Like>(
|
|
320
|
-
matrix: Matrix2Like
|
|
333
|
+
matrix: Readonly<Matrix2Like>,
|
|
321
334
|
r: number,
|
|
322
335
|
out: T
|
|
323
336
|
): T => {
|
|
@@ -348,8 +361,8 @@ export const rotate = <T extends Matrix2Like>(
|
|
|
348
361
|
* @public
|
|
349
362
|
*/
|
|
350
363
|
export const scale = <T extends Matrix2Like>(
|
|
351
|
-
matrix: Matrix2Like
|
|
352
|
-
vector: Vector2Like
|
|
364
|
+
matrix: Readonly<Matrix2Like>,
|
|
365
|
+
vector: Readonly<Vector2Like>,
|
|
353
366
|
out: T
|
|
354
367
|
): T => {
|
|
355
368
|
const v0 = vector[0];
|
|
@@ -371,8 +384,60 @@ export const scale = <T extends Matrix2Like>(
|
|
|
371
384
|
*/
|
|
372
385
|
export default class Matrix2
|
|
373
386
|
extends Float32Array
|
|
374
|
-
implements
|
|
387
|
+
implements Matrix2Like, SquareMatrix
|
|
375
388
|
{
|
|
389
|
+
/** The value in the first column and first row. */
|
|
390
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
391
|
+
public 0: number;
|
|
392
|
+
|
|
393
|
+
/** The value in the first column and second row. */
|
|
394
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
395
|
+
public 1: number;
|
|
396
|
+
|
|
397
|
+
/** The value in the second column and first row. */
|
|
398
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
399
|
+
public 2: number;
|
|
400
|
+
|
|
401
|
+
/** The value in the second column and second row. */
|
|
402
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
403
|
+
public 3: number;
|
|
404
|
+
|
|
405
|
+
/** The number of rows in this matrix. */
|
|
406
|
+
public readonly height: 2;
|
|
407
|
+
|
|
408
|
+
/** The number of columns in this matrix. */
|
|
409
|
+
public readonly width: 2;
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Get the determinant of this matrix.
|
|
413
|
+
* @see {@link https://en.wikipedia.org/wiki/Determinant | Determinant}
|
|
414
|
+
*/
|
|
415
|
+
public get determinant(): number {
|
|
416
|
+
return determinant(this);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Get the Frobenius norm of this matrix.
|
|
421
|
+
* @see {@link https://en.wikipedia.org/wiki/Matrix_norm | Matrix norm}
|
|
422
|
+
*/
|
|
423
|
+
public get frob(): number {
|
|
424
|
+
return frob(this);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Create a two-by-two identity matrix.
|
|
429
|
+
* @see {@link https://en.wikipedia.org/wiki/Identity_matrix | Identity matrix}
|
|
430
|
+
*/
|
|
431
|
+
public constructor() {
|
|
432
|
+
super(4);
|
|
433
|
+
|
|
434
|
+
this[0] = 1;
|
|
435
|
+
this[3] = 1;
|
|
436
|
+
|
|
437
|
+
this.width = 2;
|
|
438
|
+
this.height = 2;
|
|
439
|
+
}
|
|
440
|
+
|
|
376
441
|
/**
|
|
377
442
|
* Create a transformation matrix that represents a rotation by the given angle around the Z-axis.
|
|
378
443
|
* @param r - The angle in radians.
|
|
@@ -389,7 +454,7 @@ export default class Matrix2
|
|
|
389
454
|
* @returns The transformation matrix.
|
|
390
455
|
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
391
456
|
*/
|
|
392
|
-
public static fromScaling(vector: Vector2Like): Matrix2 {
|
|
457
|
+
public static fromScaling(vector: Readonly<Vector2Like>): Matrix2 {
|
|
393
458
|
return fromScaling(vector, new Matrix2());
|
|
394
459
|
}
|
|
395
460
|
|
|
@@ -410,63 +475,13 @@ export default class Matrix2
|
|
|
410
475
|
return fromValues(c0r0, c0r1, c1r0, c1r1, new Matrix2());
|
|
411
476
|
}
|
|
412
477
|
|
|
413
|
-
/**
|
|
414
|
-
* Create a two-by-two identity matrix.
|
|
415
|
-
* @see {@link https://en.wikipedia.org/wiki/Identity_matrix | Identity matrix}
|
|
416
|
-
*/
|
|
417
|
-
public constructor() {
|
|
418
|
-
super(4);
|
|
419
|
-
|
|
420
|
-
this[0] = 1;
|
|
421
|
-
this[3] = 1;
|
|
422
|
-
|
|
423
|
-
this.width = 2;
|
|
424
|
-
this.height = 2;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
/** The value in the first column and first row. */
|
|
428
|
-
public 0: number;
|
|
429
|
-
|
|
430
|
-
/** The value in the first column and second row. */
|
|
431
|
-
public 1: number;
|
|
432
|
-
|
|
433
|
-
/** The value in the second column and first row. */
|
|
434
|
-
public 2: number;
|
|
435
|
-
|
|
436
|
-
/** The value in the second column and second row. */
|
|
437
|
-
public 3: number;
|
|
438
|
-
|
|
439
|
-
/** The number of columns in this matrix. */
|
|
440
|
-
public readonly width: 2;
|
|
441
|
-
|
|
442
|
-
/** The number of rows in this matrix. */
|
|
443
|
-
public readonly height: 2;
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* Determine whether or not this matrix is roughly equivalent to another.
|
|
447
|
-
* @param matrix - The other matrix.
|
|
448
|
-
* @returns Whether the matrices are equivalent.
|
|
449
|
-
*/
|
|
450
|
-
public equals(matrix: Matrix2Like): boolean {
|
|
451
|
-
return equals(this, matrix);
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* Determine whether or not this matrix is exactly equivalent to another.
|
|
456
|
-
* @param matrix - The other matrix.
|
|
457
|
-
* @returns Whether the matrices are equivalent.
|
|
458
|
-
*/
|
|
459
|
-
public exactEquals(matrix: Matrix2Like): boolean {
|
|
460
|
-
return exactEquals(this, matrix);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
478
|
/**
|
|
464
479
|
* Add another matrix to this one.
|
|
465
480
|
* @param matrix - The other matrix.
|
|
466
481
|
* @returns The sum of the matrices.
|
|
467
482
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
|
|
468
483
|
*/
|
|
469
|
-
public add(matrix: Matrix2Like): Matrix2 {
|
|
484
|
+
public add(matrix: Readonly<Matrix2Like>): Matrix2 {
|
|
470
485
|
return add(this, matrix, new Matrix2());
|
|
471
486
|
}
|
|
472
487
|
|
|
@@ -492,16 +507,44 @@ export default class Matrix2
|
|
|
492
507
|
* @param matrix - The matrix to copy.
|
|
493
508
|
* @returns This matrix.
|
|
494
509
|
*/
|
|
495
|
-
public copy(matrix: Matrix2Like): this {
|
|
510
|
+
public copy(matrix: Readonly<Matrix2Like>): this {
|
|
496
511
|
return copy(matrix, this);
|
|
497
512
|
}
|
|
498
513
|
|
|
499
514
|
/**
|
|
500
|
-
*
|
|
501
|
-
* @
|
|
515
|
+
* Determine whether or not this matrix is roughly equivalent to another.
|
|
516
|
+
* @param matrix - The other matrix.
|
|
517
|
+
* @returns Whether the matrices are equivalent.
|
|
502
518
|
*/
|
|
503
|
-
public
|
|
504
|
-
return
|
|
519
|
+
public equals(matrix: Readonly<Matrix2Like>): boolean {
|
|
520
|
+
return equals(this, matrix);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Determine whether or not this matrix is exactly equivalent to another.
|
|
525
|
+
* @param matrix - The other matrix.
|
|
526
|
+
* @returns Whether the matrices are equivalent.
|
|
527
|
+
*/
|
|
528
|
+
public exactEquals(matrix: Readonly<Matrix2Like>): boolean {
|
|
529
|
+
return exactEquals(this, matrix);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Reset this matrix to identity.
|
|
534
|
+
* @returns This matrix.
|
|
535
|
+
* @see {@link https://en.wikipedia.org/wiki/Identity_matrix | Identity matrix}
|
|
536
|
+
*/
|
|
537
|
+
public identity(): this {
|
|
538
|
+
return identity(this);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Invert this matrix.
|
|
543
|
+
* @returns The inverted matrix.
|
|
544
|
+
* @see {@link https://en.wikipedia.org/wiki/Invertible_matrix | Invertible matrix}
|
|
545
|
+
*/
|
|
546
|
+
public invert(): Matrix2 {
|
|
547
|
+
return invert(this, new Matrix2());
|
|
505
548
|
}
|
|
506
549
|
|
|
507
550
|
/**
|
|
@@ -511,7 +554,7 @@ export default class Matrix2
|
|
|
511
554
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_multiplication | Matrix multiplication}
|
|
512
555
|
* @public
|
|
513
556
|
*/
|
|
514
|
-
public multiply(matrix: Matrix2Like): Matrix2 {
|
|
557
|
+
public multiply(matrix: Readonly<Matrix2Like>): Matrix2 {
|
|
515
558
|
return multiply(this, matrix, new Matrix2());
|
|
516
559
|
}
|
|
517
560
|
|
|
@@ -533,55 +576,13 @@ export default class Matrix2
|
|
|
533
576
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
|
|
534
577
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_multiplication | Matrix multiplication}
|
|
535
578
|
*/
|
|
536
|
-
public multiplyScalarAndAdd(
|
|
579
|
+
public multiplyScalarAndAdd(
|
|
580
|
+
matrix: Readonly<Matrix2Like>,
|
|
581
|
+
scalar: number
|
|
582
|
+
): Matrix2 {
|
|
537
583
|
return multiplyScalarAndAdd(this, matrix, scalar, new Matrix2());
|
|
538
584
|
}
|
|
539
585
|
|
|
540
|
-
/**
|
|
541
|
-
* Subtract another matrix from this one.
|
|
542
|
-
* @param matrix - The other matrix.
|
|
543
|
-
* @returns The difference between the matrices.
|
|
544
|
-
* @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
|
|
545
|
-
*/
|
|
546
|
-
public subtract(matrix: Matrix2Like): Matrix2 {
|
|
547
|
-
return subtract(this, matrix, new Matrix2());
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
/**
|
|
551
|
-
* Transpose this matrix.
|
|
552
|
-
* @returns The transpose of this matrix.
|
|
553
|
-
* @see {@link https://en.wikipedia.org/wiki/Transpose | Transpose}
|
|
554
|
-
*/
|
|
555
|
-
public transpose(): Matrix2 {
|
|
556
|
-
return transpose(this, new Matrix2());
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* Get the determinant of this matrix.
|
|
561
|
-
* @see {@link https://en.wikipedia.org/wiki/Determinant | Determinant}
|
|
562
|
-
*/
|
|
563
|
-
public get determinant(): number {
|
|
564
|
-
return determinant(this);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
/**
|
|
568
|
-
* Reset this matrix to identity.
|
|
569
|
-
* @returns This matrix.
|
|
570
|
-
* @see {@link https://en.wikipedia.org/wiki/Identity_matrix | Identity matrix}
|
|
571
|
-
*/
|
|
572
|
-
public identity(): this {
|
|
573
|
-
return identity(this);
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
/**
|
|
577
|
-
* Invert this matrix.
|
|
578
|
-
* @returns The inverted matrix.
|
|
579
|
-
* @see {@link https://en.wikipedia.org/wiki/Invertible_matrix | Invertible matrix}
|
|
580
|
-
*/
|
|
581
|
-
public invert(): Matrix2 {
|
|
582
|
-
return invert(this, new Matrix2());
|
|
583
|
-
}
|
|
584
|
-
|
|
585
586
|
/**
|
|
586
587
|
* Rotate this matrix by the given angle.
|
|
587
588
|
* @param r - The angle in radians.
|
|
@@ -598,7 +599,26 @@ export default class Matrix2
|
|
|
598
599
|
* @returns The scaled matrix.
|
|
599
600
|
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
600
601
|
*/
|
|
601
|
-
public scale(vector: Vector2Like): Matrix2 {
|
|
602
|
+
public scale(vector: Readonly<Vector2Like>): Matrix2 {
|
|
602
603
|
return scale(this, vector, new Matrix2());
|
|
603
604
|
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Subtract another matrix from this one.
|
|
608
|
+
* @param matrix - The other matrix.
|
|
609
|
+
* @returns The difference between the matrices.
|
|
610
|
+
* @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
|
|
611
|
+
*/
|
|
612
|
+
public subtract(matrix: Readonly<Matrix2Like>): Matrix2 {
|
|
613
|
+
return subtract(this, matrix, new Matrix2());
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Transpose this matrix.
|
|
618
|
+
* @returns The transpose of this matrix.
|
|
619
|
+
* @see {@link https://en.wikipedia.org/wiki/Transpose | Transpose}
|
|
620
|
+
*/
|
|
621
|
+
public transpose(): Matrix2 {
|
|
622
|
+
return transpose(this, new Matrix2());
|
|
623
|
+
}
|
|
604
624
|
}
|