@lakuna/umath 1.0.0 → 1.1.0
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/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/linear/Matrix.d.ts +4 -5
- package/dist/linear/Matrix.d.ts.map +1 -1
- package/dist/linear/SlowMatrix.d.ts +18 -0
- package/dist/linear/SlowMatrix.d.ts.map +1 -0
- package/dist/linear/SlowMatrix.js +126 -0
- package/dist/linear/SlowMatrix.js.map +1 -0
- package/dist/linear/SlowSquareMatrix.d.ts +15 -0
- package/dist/linear/SlowSquareMatrix.d.ts.map +1 -0
- package/dist/linear/SlowSquareMatrix.js +118 -0
- package/dist/linear/SlowSquareMatrix.js.map +1 -0
- package/dist/linear/SquareMatrix.d.ts +1 -0
- package/dist/linear/SquareMatrix.d.ts.map +1 -1
- package/dist/utility/MagnitudeError.d.ts.map +1 -1
- package/dist/utility/MagnitudeError.js +1 -0
- package/dist/utility/MagnitudeError.js.map +1 -1
- package/dist/utility/MatrixSizeError.d.ts +4 -0
- package/dist/utility/MatrixSizeError.d.ts.map +1 -0
- package/dist/utility/MatrixSizeError.js +7 -0
- package/dist/utility/MatrixSizeError.js.map +1 -0
- package/dist/utility/PartialMatrixError.d.ts +4 -0
- package/dist/utility/PartialMatrixError.d.ts.map +1 -0
- package/dist/utility/PartialMatrixError.js +7 -0
- package/dist/utility/PartialMatrixError.js.map +1 -0
- package/package.json +3 -1
- package/src/index.ts +4 -0
- package/src/linear/Matrix.ts +17 -24
- package/src/linear/SlowMatrix.ts +228 -0
- package/src/linear/SlowSquareMatrix.ts +203 -0
- package/src/linear/SquareMatrix.ts +7 -0
- package/src/utility/MagnitudeError.ts +1 -0
- package/src/utility/MatrixSizeError.ts +11 -0
- package/src/utility/PartialMatrixError.ts +11 -0
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export { type Matrix2Like, default as Matrix2 } from "@lakuna/umath/Matrix2";
|
|
|
14
14
|
export { type Matrix3Like, default as Matrix3 } from "@lakuna/umath/Matrix3";
|
|
15
15
|
export { type Matrix4Like, default as Matrix4 } from "@lakuna/umath/Matrix4";
|
|
16
16
|
export { type QuaternionLike, default as Quaternion } from "@lakuna/umath/Quaternion";
|
|
17
|
+
export { default as SlowMatrix } from "@lakuna/umath/SlowMatrix";
|
|
18
|
+
export { default as SlowSquareMatrix } from "@lakuna/umath/SlowSquareMatrix";
|
|
17
19
|
export type { default as SquareMatrix } from "./linear/SquareMatrix.js";
|
|
18
20
|
export type { VectorLike, default as Vector } from "./linear/Vector.js";
|
|
19
21
|
export { type Vector2Like, default as Vector2 } from "@lakuna/umath/Vector2";
|
|
@@ -25,5 +27,7 @@ export type { IntegerRepresentation } from "./types/IntegerRepresentation.js";
|
|
|
25
27
|
export { default as BigNumber } from "./utility/BigNumber.js";
|
|
26
28
|
export { default as epsilon } from "./utility/epsilon.js";
|
|
27
29
|
export { default as MagnitudeError } from "./utility/MagnitudeError.js";
|
|
30
|
+
export { default as MatrixSizeError } from "./utility/MatrixSizeError.js";
|
|
31
|
+
export { default as PartialMatrixError } from "./utility/PartialMatrixError.js";
|
|
28
32
|
export { default as SingularMatrixError } from "./utility/SingularMatrixError.js";
|
|
29
33
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACjE,O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1D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,kCAAkC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,11 +13,15 @@ export { default as Matrix2 } from "@lakuna/umath/Matrix2";
|
|
|
13
13
|
export { default as Matrix3 } from "@lakuna/umath/Matrix3";
|
|
14
14
|
export { default as Matrix4 } from "@lakuna/umath/Matrix4";
|
|
15
15
|
export { default as Quaternion } from "@lakuna/umath/Quaternion";
|
|
16
|
+
export { default as SlowMatrix } from "@lakuna/umath/SlowMatrix";
|
|
17
|
+
export { default as SlowSquareMatrix } from "@lakuna/umath/SlowSquareMatrix";
|
|
16
18
|
export { default as Vector2 } from "@lakuna/umath/Vector2";
|
|
17
19
|
export { default as Vector3 } from "@lakuna/umath/Vector3";
|
|
18
20
|
export { default as Vector4 } from "@lakuna/umath/Vector4";
|
|
19
21
|
export { default as BigNumber } from "./utility/BigNumber.js";
|
|
20
22
|
export { default as epsilon } from "./utility/epsilon.js";
|
|
21
23
|
export { default as MagnitudeError } from "./utility/MagnitudeError.js";
|
|
24
|
+
export { default as MatrixSizeError } from "./utility/MatrixSizeError.js";
|
|
25
|
+
export { default as PartialMatrixError } from "./utility/PartialMatrixError.js";
|
|
22
26
|
export { default as SingularMatrixError } from "./utility/SingularMatrixError.js";
|
|
23
27
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,gB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8B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,kCAAkC,CAAC"}
|
package/dist/linear/Matrix.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
export type MatrixLike = Matrix | ArrayLike<number>;
|
|
2
2
|
export default interface Matrix extends ArrayLike<number> {
|
|
3
|
-
width: number;
|
|
4
3
|
height: number;
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
width: number;
|
|
5
|
+
get frob(): number;
|
|
7
6
|
add(matrix: MatrixLike): Matrix;
|
|
8
|
-
adjoint(): Matrix;
|
|
9
7
|
clone(): Matrix;
|
|
10
8
|
copy(matrix: MatrixLike): this;
|
|
11
|
-
|
|
9
|
+
equals(matrix: MatrixLike): boolean;
|
|
10
|
+
exactEquals(matrix: MatrixLike): boolean;
|
|
12
11
|
multiply(matrix: MatrixLike): Matrix;
|
|
13
12
|
multiplyScalar(scalar: number): Matrix;
|
|
14
13
|
multiplyScalarAndAdd(matrix: MatrixLike, scalar: number): Matrix;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Matrix.d.ts","sourceRoot":"","sources":["../../src/linear/Matrix.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AAMpD,MAAM,CAAC,OAAO,WAAW,MAAO,SAAQ,SAAS,CAAC,MAAM,CAAC;IAExD,
|
|
1
|
+
{"version":3,"file":"Matrix.d.ts","sourceRoot":"","sources":["../../src/linear/Matrix.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AAMpD,MAAM,CAAC,OAAO,WAAW,MAAO,SAAQ,SAAS,CAAC,MAAM,CAAC;IAExD,MAAM,EAAE,MAAM,CAAC;IAGf,KAAK,EAAE,MAAM,CAAC;IAMd,IAAI,IAAI,IAAI,MAAM,CAAC;IAQnB,GAAG,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC;IAMhC,KAAK,IAAI,MAAM,CAAC;IAOhB,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAO/B,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC;IAOpC,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC;IAQzC,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC;IAQrC,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAUvC,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAQjE,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC;IAOrC,SAAS,IAAI,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Matrix } from "@lakuna/umath";
|
|
2
|
+
export default class SlowMatrix extends Float32Array implements Matrix {
|
|
3
|
+
constructor(...cols: Array<Array<number>>);
|
|
4
|
+
readonly height: number;
|
|
5
|
+
readonly width: number;
|
|
6
|
+
get frob(): number;
|
|
7
|
+
add(matrix: Matrix): SlowMatrix;
|
|
8
|
+
clone(): SlowMatrix;
|
|
9
|
+
copy(matrix: Matrix): this;
|
|
10
|
+
equals(matrix: Matrix): boolean;
|
|
11
|
+
exactEquals(matrix: Matrix): boolean;
|
|
12
|
+
multiply(matrix: Matrix): SlowMatrix;
|
|
13
|
+
multiplyScalar(scalar: number): SlowMatrix;
|
|
14
|
+
multiplyScalarAndAdd(matrix: Matrix, scalar: number): SlowMatrix;
|
|
15
|
+
subtract(matrix: Matrix): SlowMatrix;
|
|
16
|
+
transpose(): SlowMatrix;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=SlowMatrix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SlowMatrix.d.ts","sourceRoot":"","sources":["../../src/linear/SlowMatrix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgD,MAAM,eAAe,CAAC;AAM1F,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,YAAa,YAAW,MAAM;gBAKlD,GAAG,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAkBhD,SAAgB,MAAM,EAAE,MAAM,CAAC;IAG/B,SAAgB,KAAK,EAAE,MAAM,CAAC;IAM9B,IAAW,IAAI,IAAI,MAAM,CAExB;IAQM,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU;IAmB/B,KAAK,IAAI,UAAU;IAgBnB,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAmB1B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAmB/B,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAoBpC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU;IA6BpC,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU;IAiB1C,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU;IAUhE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU;IAoBpC,SAAS,IAAI,UAAU;CAU9B"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { PartialMatrixError, epsilon, MatrixSizeError } from "@lakuna/umath";
|
|
2
|
+
export default class SlowMatrix extends Float32Array {
|
|
3
|
+
constructor(...cols) {
|
|
4
|
+
super(cols.flat());
|
|
5
|
+
this.width = cols.length;
|
|
6
|
+
this.height = this.width && cols[0].length;
|
|
7
|
+
if (this.width < 1 || this.height < 1) {
|
|
8
|
+
throw new MatrixSizeError();
|
|
9
|
+
}
|
|
10
|
+
for (let i = 0; i < this.width; i++) {
|
|
11
|
+
if ((cols[i]?.length ?? 0) != this.height) {
|
|
12
|
+
throw new PartialMatrixError();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
height;
|
|
17
|
+
width;
|
|
18
|
+
get frob() {
|
|
19
|
+
return Math.hypot(...this);
|
|
20
|
+
}
|
|
21
|
+
add(matrix) {
|
|
22
|
+
if (this.width != matrix.width || this.height != matrix.height) {
|
|
23
|
+
throw new MatrixSizeError();
|
|
24
|
+
}
|
|
25
|
+
const cols = [];
|
|
26
|
+
for (let x = 0; x < this.width; x++) {
|
|
27
|
+
for (let y = 0; y < this.height; y++) {
|
|
28
|
+
(cols[x] ??= [])[y] = this[x * this.height + y] + matrix[x * matrix.height + y];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return new SlowMatrix(...cols);
|
|
32
|
+
}
|
|
33
|
+
clone() {
|
|
34
|
+
const cols = [];
|
|
35
|
+
for (let x = 0; x < this.width; x++) {
|
|
36
|
+
for (let y = 0; y < this.height; y++) {
|
|
37
|
+
(cols[x] ??= [])[y] = this[x * this.height + y];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return new SlowMatrix(...cols);
|
|
41
|
+
}
|
|
42
|
+
copy(matrix) {
|
|
43
|
+
if (this.width != matrix.width || this.height != matrix.height) {
|
|
44
|
+
throw new MatrixSizeError();
|
|
45
|
+
}
|
|
46
|
+
for (let x = 0; x < this.width; x++) {
|
|
47
|
+
for (let y = 0; y < this.height; y++) {
|
|
48
|
+
this[x * this.width + y] = matrix[x * this.height + y];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
equals(matrix) {
|
|
54
|
+
if (this.width != matrix.width || this.height != matrix.height) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
for (let i = 0; i < this.length; i++) {
|
|
58
|
+
if (Math.abs(this[i] - matrix[i]) > epsilon) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
exactEquals(matrix) {
|
|
65
|
+
if (this.width != matrix.width || this.height != matrix.height) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
for (let i = 0; i < this.length; i++) {
|
|
69
|
+
if (this[i] != matrix[i]) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
multiply(matrix) {
|
|
76
|
+
if (this.width != matrix.height) {
|
|
77
|
+
throw new MatrixSizeError();
|
|
78
|
+
}
|
|
79
|
+
const n = this.height;
|
|
80
|
+
const m = this.width;
|
|
81
|
+
const p = matrix.width;
|
|
82
|
+
const out = [];
|
|
83
|
+
for (let i = 0; i < n; i++) {
|
|
84
|
+
for (let j = 0; j < p; j++) {
|
|
85
|
+
let sum = 0;
|
|
86
|
+
for (let k = 0; k < m; k++) {
|
|
87
|
+
sum += this[k * this.height + i] * matrix[j * matrix.height + k];
|
|
88
|
+
}
|
|
89
|
+
(out[j] ??= [])[i] = sum;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return new SlowMatrix(...out);
|
|
93
|
+
}
|
|
94
|
+
multiplyScalar(scalar) {
|
|
95
|
+
const out = this.clone();
|
|
96
|
+
for (let i = 0; i < out.length; i++) {
|
|
97
|
+
out[i] *= scalar;
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
multiplyScalarAndAdd(matrix, scalar) {
|
|
102
|
+
return this.add(matrix.multiplyScalar(scalar));
|
|
103
|
+
}
|
|
104
|
+
subtract(matrix) {
|
|
105
|
+
if (this.width != matrix.width || this.height != matrix.height) {
|
|
106
|
+
throw new MatrixSizeError();
|
|
107
|
+
}
|
|
108
|
+
const cols = [];
|
|
109
|
+
for (let x = 0; x < this.width; x++) {
|
|
110
|
+
for (let y = 0; y < this.height; y++) {
|
|
111
|
+
(cols[x] ??= [])[y] = this[x * this.height + y] - matrix[x * matrix.height + y];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return new SlowMatrix(...cols);
|
|
115
|
+
}
|
|
116
|
+
transpose() {
|
|
117
|
+
const cols = [];
|
|
118
|
+
for (let x = 0; x < this.width; x++) {
|
|
119
|
+
for (let y = 0; y < this.height; y++) {
|
|
120
|
+
(cols[y] ??= [])[x] = this[x * this.height + y];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return new SlowMatrix(...cols);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=SlowMatrix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SlowMatrix.js","sourceRoot":"","sources":["../../src/linear/SlowMatrix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,kBAAkB,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAM1F,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,YAAY;IAKnD,YAAmB,GAAG,IAA0B;QAC/C,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,IAAK,IAAI,CAAC,CAAC,CAAmB,CAAC,MAAM,CAAC;QAE9D,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACtC,MAAM,IAAI,eAAe,EAAE,CAAC;SAC5B;QAGD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;YACpC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC1C,MAAM,IAAI,kBAAkB,EAAE,CA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G,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACrC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,GAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAY,CAAC;aAC5D;SACD;QAED,OAAO,IAAI,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC;IAChC,CAAC;CACD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type SquareMatrix } from "@lakuna/umath";
|
|
2
|
+
import SlowMatrix from "@lakuna/umath/SlowMatrix";
|
|
3
|
+
export default class SlowSquareMatrix extends SlowMatrix implements SquareMatrix {
|
|
4
|
+
constructor(...cols: Array<Array<number>>);
|
|
5
|
+
get determinant(): number;
|
|
6
|
+
adjoint(): SlowSquareMatrix;
|
|
7
|
+
clone(): SlowSquareMatrix;
|
|
8
|
+
cofactor(): SlowSquareMatrix;
|
|
9
|
+
identity(): this;
|
|
10
|
+
invert(): SlowSquareMatrix;
|
|
11
|
+
minor(row: number, col: number): number;
|
|
12
|
+
submatrix(row: number, col: number): SlowSquareMatrix;
|
|
13
|
+
transpose(): SlowSquareMatrix;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=SlowSquareMatrix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SlowSquareMatrix.d.ts","sourceRoot":"","sources":["../../src/linear/SlowSquareMatrix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAwC,MAAM,eAAe,CAAC;AACxF,OAAO,UAAU,MAAM,0BAA0B,CAAC;AAMlD,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,UAAW,YAAW,YAAY;gBAM5D,GAAG,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAehD,IAAW,WAAW,IAAI,MAAM,CAe/B;IAOM,OAAO,IAAI,gBAAgB;IAQlB,KAAK,IAAI,gBAAgB;IAgBlC,QAAQ,IAAI,gBAAgB;IAgB5B,QAAQ,IAAI,IAAI;IAehB,MAAM,IAAI,gBAAgB;IAoD1B,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAUvC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,gBAAgB;IAyB5C,SAAS,IAAI,gBAAgB;CAU7C"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { MatrixSizeError, SingularMatrixError } from "@lakuna/umath";
|
|
2
|
+
import SlowMatrix from "@lakuna/umath/SlowMatrix";
|
|
3
|
+
export default class SlowSquareMatrix extends SlowMatrix {
|
|
4
|
+
constructor(...cols) {
|
|
5
|
+
super(...cols);
|
|
6
|
+
for (let i = 0; i < this.width; i++) {
|
|
7
|
+
if (cols[i].length != this.height) {
|
|
8
|
+
throw new MatrixSizeError();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
get determinant() {
|
|
13
|
+
if (this.length < 1) {
|
|
14
|
+
throw new MatrixSizeError();
|
|
15
|
+
}
|
|
16
|
+
if (this.length == 1) {
|
|
17
|
+
return this[0] ?? 0;
|
|
18
|
+
}
|
|
19
|
+
let out = 0;
|
|
20
|
+
for (let i = 0; i < this.width; i++) {
|
|
21
|
+
out += this[i * this.height] * (i % 2 ? -1 : 1) * this.minor(0, i);
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
adjoint() {
|
|
26
|
+
return this.cofactor().transpose();
|
|
27
|
+
}
|
|
28
|
+
clone() {
|
|
29
|
+
const cols = [];
|
|
30
|
+
for (let x = 0; x < this.width; x++) {
|
|
31
|
+
for (let y = 0; y < this.height; y++) {
|
|
32
|
+
(cols[x] ??= [])[y] = this[x * this.height + y];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return new SlowSquareMatrix(...cols);
|
|
36
|
+
}
|
|
37
|
+
cofactor() {
|
|
38
|
+
const out = [];
|
|
39
|
+
for (let i = 0; i < this.width; i++) {
|
|
40
|
+
for (let j = 0; j < this.height; j++) {
|
|
41
|
+
(out[j] ??= [])[i] = ((i + j) % 2 ? -1 : 1) * this.minor(i, j);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return new SlowSquareMatrix(...out);
|
|
45
|
+
}
|
|
46
|
+
identity() {
|
|
47
|
+
for (let i = 0; i < this.width; i++) {
|
|
48
|
+
for (let j = 0; j < this.height; j++) {
|
|
49
|
+
this[i * this.height + j] = i == j ? 1 : 0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
invert() {
|
|
55
|
+
const dim = this.width;
|
|
56
|
+
const clone = this.clone();
|
|
57
|
+
const identity = this.clone().identity();
|
|
58
|
+
for (let i = 0; i < dim; i++) {
|
|
59
|
+
let diagonal = clone[i * dim + i];
|
|
60
|
+
if (!diagonal) {
|
|
61
|
+
for (let ii = i + 1; ii < dim; ii++) {
|
|
62
|
+
if (clone[ii * dim + i]) {
|
|
63
|
+
for (let j = 0; j < dim; j++) {
|
|
64
|
+
for (const matrix of [clone, identity]) {
|
|
65
|
+
[matrix[i * dim + j], matrix[ii * dim + j]] = [matrix[ii * dim + j], matrix[i * dim + j]];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
diagonal = clone[i * dim + i];
|
|
72
|
+
if (!diagonal) {
|
|
73
|
+
throw new SingularMatrixError();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (let ii = 0; ii < dim; ii++) {
|
|
77
|
+
if (ii == i) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const temp = clone[ii * dim + i];
|
|
81
|
+
for (let j = 0; j < dim; j++) {
|
|
82
|
+
for (const matrix of [clone, identity]) {
|
|
83
|
+
matrix[ii * dim + j] -= temp * matrix[i * dim + j];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return identity;
|
|
89
|
+
}
|
|
90
|
+
minor(row, col) {
|
|
91
|
+
return this.submatrix(row, col).determinant;
|
|
92
|
+
}
|
|
93
|
+
submatrix(row, col) {
|
|
94
|
+
const cols = [];
|
|
95
|
+
for (let i = 0; i < this.width; i++) {
|
|
96
|
+
if (i == col) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
for (let j = 0; j < this.height; j++) {
|
|
100
|
+
if (j == row) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
(cols[i < col ? i : i - 1] ??= [])[j < row ? j : j - 1] = this[i * this.height + j];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return new SlowSquareMatrix(...cols);
|
|
107
|
+
}
|
|
108
|
+
transpose() {
|
|
109
|
+
const cols = [];
|
|
110
|
+
for (let x = 0; x < this.width; x++) {
|
|
111
|
+
for (let y = 0; y < this.height; y++) {
|
|
112
|
+
(cols[y] ??= [])[x] = this[x * this.height + y];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return new SlowSquareMatrix(...cols);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=SlowSquareMatrix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SlowSquareMatrix.js","sourceRoot":"","sources":["../../src/linear/SlowSquareMatrix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,eAAe,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,UAAU,MAAM,0BAA0B,CAAC;AAMlD,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,UAAU;IAMvD,YAAmB,GAAG,IAA0B;QAC/C,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;QAGf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,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I,GAAyB,EAAE,CAAC;QACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;YACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACrC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,GAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAY,CAAC;aAC5D;SACD;QAED,OAAO,IAAI,gBAAgB,CAAC,GAAG,IAAI,CAAC,CAAC;IACtC,CAAC;CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SquareMatrix.d.ts","sourceRoot":"","sources":["../../src/linear/SquareMatrix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAM5C,MAAM,CAAC,OAAO,WAAW,YAAa,SAAQ,MAAM;IAKnD,IAAI,WAAW,IAAI,MAAM,CAAC;IAO1B,QAAQ,IAAI,IAAI,CAAC;IAOjB,MAAM,IAAI,YAAY,CAAC;CACvB"}
|
|
1
|
+
{"version":3,"file":"SquareMatrix.d.ts","sourceRoot":"","sources":["../../src/linear/SquareMatrix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAM5C,MAAM,CAAC,OAAO,WAAW,YAAa,SAAQ,MAAM;IAKnD,IAAI,WAAW,IAAI,MAAM,CAAC;IAO1B,OAAO,IAAI,MAAM,CAAC;IAOlB,QAAQ,IAAI,IAAI,CAAC;IAOjB,MAAM,IAAI,YAAY,CAAC;CACvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MagnitudeError.d.ts","sourceRoot":"","sources":["../../src/utility/MagnitudeError.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,KAAK;gBAK7B,OAAO,SAA6B;
|
|
1
|
+
{"version":3,"file":"MagnitudeError.d.ts","sourceRoot":"","sources":["../../src/utility/MagnitudeError.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,KAAK;gBAK7B,OAAO,SAA6B;CAIvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MagnitudeError.js","sourceRoot":"","sources":["../../src/utility/MagnitudeError.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,KAAK;IAKhD,YAAmB,OAAO,GAAG,0BAA0B;QACtD,KAAK,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"MagnitudeError.js","sourceRoot":"","sources":["../../src/utility/MagnitudeError.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,KAAK;IAKhD,YAAmB,OAAO,GAAG,0BAA0B;QACtD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC9B,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MatrixSizeError.d.ts","sourceRoot":"","sources":["../../src/utility/MatrixSizeError.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,KAAK;gBAKjC,OAAO,SAA+B;CAIzD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MatrixSizeError.js","sourceRoot":"","sources":["../../src/utility/MatrixSizeError.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,KAAK;IAKpD,YAAmB,OAAO,GAAG,4BAA4B;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAC/B,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PartialMatrixError.d.ts","sourceRoot":"","sources":["../../src/utility/PartialMatrixError.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,KAAK;gBAKjC,OAAO,SAAmC;CAI7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PartialMatrixError.js","sourceRoot":"","sources":["../../src/utility/PartialMatrixError.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,KAAK;IAKpD,YAAmB,OAAO,GAAG,gCAAgC;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IAClC,CAAC;CACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakuna/umath",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A lightweight math library.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"math"
|
|
@@ -53,6 +53,8 @@
|
|
|
53
53
|
"./Matrix3": "./dist/linear/Matrix3.js",
|
|
54
54
|
"./Matrix4": "./dist/linear/Matrix4.js",
|
|
55
55
|
"./Quaternion": "./dist/linear/Quaternion.js",
|
|
56
|
+
"./SlowMatrix": "./dist/linear/SlowMatrix.js",
|
|
57
|
+
"./SlowSquareMatrix": "./dist/linear/SlowSquareMatrix.js",
|
|
56
58
|
"./Vector2": "./dist/linear/Vector2.js",
|
|
57
59
|
"./Vector3": "./dist/linear/Vector3.js",
|
|
58
60
|
"./Vector4": "./dist/linear/Vector4.js"
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,8 @@ export { type Matrix2Like, default as Matrix2 } from "@lakuna/umath/Matrix2";
|
|
|
14
14
|
export { type Matrix3Like, default as Matrix3 } from "@lakuna/umath/Matrix3";
|
|
15
15
|
export { type Matrix4Like, default as Matrix4 } from "@lakuna/umath/Matrix4";
|
|
16
16
|
export { type QuaternionLike, default as Quaternion } from "@lakuna/umath/Quaternion";
|
|
17
|
+
export { default as SlowMatrix } from "@lakuna/umath/SlowMatrix";
|
|
18
|
+
export { default as SlowSquareMatrix } from "@lakuna/umath/SlowSquareMatrix";
|
|
17
19
|
export type { default as SquareMatrix } from "./linear/SquareMatrix.js";
|
|
18
20
|
export type { VectorLike, default as Vector } from "./linear/Vector.js";
|
|
19
21
|
export { type Vector2Like, default as Vector2 } from "@lakuna/umath/Vector2";
|
|
@@ -25,4 +27,6 @@ export type { IntegerRepresentation } from "./types/IntegerRepresentation.js";
|
|
|
25
27
|
export { default as BigNumber } from "./utility/BigNumber.js";
|
|
26
28
|
export { default as epsilon } from "./utility/epsilon.js";
|
|
27
29
|
export { default as MagnitudeError } from "./utility/MagnitudeError.js";
|
|
30
|
+
export { default as MatrixSizeError } from "./utility/MatrixSizeError.js";
|
|
31
|
+
export { default as PartialMatrixError } from "./utility/PartialMatrixError.js";
|
|
28
32
|
export { default as SingularMatrixError } from "./utility/SingularMatrixError.js";
|
package/src/linear/Matrix.ts
CHANGED
|
@@ -9,26 +9,18 @@ export type MatrixLike = Matrix | ArrayLike<number>;
|
|
|
9
9
|
* @see [Matrix](https://en.wikipedia.org/wiki/Matrix_(mathematics))
|
|
10
10
|
*/
|
|
11
11
|
export default interface Matrix extends ArrayLike<number> {
|
|
12
|
-
/** The number of columns in this matrix. */
|
|
13
|
-
width: number;
|
|
14
|
-
|
|
15
12
|
/** The number of rows in this matrix. */
|
|
16
13
|
height: number;
|
|
17
14
|
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
* @param matrix The other matrix.
|
|
21
|
-
* @returns Whether the matrices are equivalent.
|
|
22
|
-
*/
|
|
23
|
-
equals(matrix: MatrixLike): boolean;
|
|
15
|
+
/** The number of columns in this matrix. */
|
|
16
|
+
width: number;
|
|
24
17
|
|
|
25
18
|
/**
|
|
26
|
-
*
|
|
27
|
-
* @
|
|
28
|
-
* @returns Whether the matrices are equivalent.
|
|
19
|
+
* The Frobenius norm of this matrix.
|
|
20
|
+
* @see [Matrix norm](https://en.wikipedia.org/wiki/Matrix_norm)
|
|
29
21
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
get frob(): number;
|
|
23
|
+
|
|
32
24
|
/**
|
|
33
25
|
* Adds two matrices of the same size.
|
|
34
26
|
* @param matrix The other matrix.
|
|
@@ -37,13 +29,6 @@ export default interface Matrix extends ArrayLike<number> {
|
|
|
37
29
|
*/
|
|
38
30
|
add(matrix: MatrixLike): Matrix;
|
|
39
31
|
|
|
40
|
-
/**
|
|
41
|
-
* Calculates the adjugate of this matrix.
|
|
42
|
-
* @returns The adjugate of this matrix.
|
|
43
|
-
* @see [Adjugate matrix](https://en.wikipedia.org/wiki/Adjugate_matrix)
|
|
44
|
-
*/
|
|
45
|
-
adjoint(): Matrix;
|
|
46
|
-
|
|
47
32
|
/**
|
|
48
33
|
* Creates a copy of this matrix.
|
|
49
34
|
* @returns A copy of this matrix.
|
|
@@ -58,10 +43,18 @@ export default interface Matrix extends ArrayLike<number> {
|
|
|
58
43
|
copy(matrix: MatrixLike): this;
|
|
59
44
|
|
|
60
45
|
/**
|
|
61
|
-
*
|
|
62
|
-
* @
|
|
46
|
+
* Determines whether this matrix is roughly equivalent to another.
|
|
47
|
+
* @param matrix The other matrix.
|
|
48
|
+
* @returns Whether the matrices are equivalent.
|
|
63
49
|
*/
|
|
64
|
-
|
|
50
|
+
equals(matrix: MatrixLike): boolean;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Determines whether this matrix is exactly equivalent to another.
|
|
54
|
+
* @param matrix The other matrix.
|
|
55
|
+
* @returns Whether the matrices are equivalent.
|
|
56
|
+
*/
|
|
57
|
+
exactEquals(matrix: MatrixLike): boolean;
|
|
65
58
|
|
|
66
59
|
/**
|
|
67
60
|
* Multiplies this matrix by another.
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { type Matrix, PartialMatrixError, epsilon, MatrixSizeError } from "@lakuna/umath";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A variable-size matrix.
|
|
5
|
+
* @see [Matrix](https://en.wikipedia.org/wiki/Matrix_(mathematics))
|
|
6
|
+
*/
|
|
7
|
+
export default class SlowMatrix extends Float32Array implements Matrix {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a variable-size matrix from the given columns.
|
|
10
|
+
* @param cols The columns in the matrix.
|
|
11
|
+
*/
|
|
12
|
+
public constructor(...cols: Array<Array<number>>) {
|
|
13
|
+
super(cols.flat());
|
|
14
|
+
this.width = cols.length;
|
|
15
|
+
this.height = this.width && (cols[0] as Array<number>).length;
|
|
16
|
+
|
|
17
|
+
if (this.width < 1 || this.height < 1) {
|
|
18
|
+
throw new MatrixSizeError();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Ensure that every column is the same height.
|
|
22
|
+
for (let i = 0; i < this.width; i++) {
|
|
23
|
+
if ((cols[i]?.length ?? 0) != this.height) {
|
|
24
|
+
throw new PartialMatrixError();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The number of rows in this matrix. */
|
|
30
|
+
public readonly height: number;
|
|
31
|
+
|
|
32
|
+
/** The number of columns in this matrix. */
|
|
33
|
+
public readonly width: number;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The Frobenius norm of this matrix.
|
|
37
|
+
* @see [Matrix norm](https://en.wikipedia.org/wiki/Matrix_norm)
|
|
38
|
+
*/
|
|
39
|
+
public get frob(): number {
|
|
40
|
+
return Math.hypot(...this);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Adds two matrices of the same size.
|
|
45
|
+
* @param matrix The other matrix.
|
|
46
|
+
* @returns The sum of the matrices.
|
|
47
|
+
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
48
|
+
*/
|
|
49
|
+
public add(matrix: Matrix): SlowMatrix {
|
|
50
|
+
if (this.width != matrix.width || this.height != matrix.height) {
|
|
51
|
+
throw new MatrixSizeError();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const cols: Array<Array<number>> = [];
|
|
55
|
+
for (let x = 0; x < this.width; x++) {
|
|
56
|
+
for (let y = 0; y < this.height; y++) {
|
|
57
|
+
(cols[x] ??= [])[y] = (this[x * this.height + y] as number) + (matrix[x * matrix.height + y] as number);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return new SlowMatrix(...cols);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Creates a copy of this matrix.
|
|
66
|
+
* @returns A copy of this matrix.
|
|
67
|
+
*/
|
|
68
|
+
public clone(): SlowMatrix {
|
|
69
|
+
const cols: Array<Array<number>> = [];
|
|
70
|
+
for (let x = 0; x < this.width; x++) {
|
|
71
|
+
for (let y = 0; y < this.height; y++) {
|
|
72
|
+
(cols[x] ??= [])[y] = this[x * this.height + y] as number;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return new SlowMatrix(...cols);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Copies the values of another matrix into this one.
|
|
81
|
+
* @param matrix The matrix to copy.
|
|
82
|
+
* @returns This matrix.
|
|
83
|
+
*/
|
|
84
|
+
public copy(matrix: Matrix): this {
|
|
85
|
+
if (this.width != matrix.width || this.height != matrix.height) {
|
|
86
|
+
throw new MatrixSizeError();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
for (let x = 0; x < this.width; x++) {
|
|
90
|
+
for (let y = 0; y < this.height; y++) {
|
|
91
|
+
(this[x * this.width + y] as number) = matrix[x * this.height + y] as number;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Determines whether this matrix is roughly equivalent to another.
|
|
100
|
+
* @param matrix The other matrix.
|
|
101
|
+
* @returns Whether the matrices are equivalent.
|
|
102
|
+
*/
|
|
103
|
+
public equals(matrix: Matrix): boolean {
|
|
104
|
+
if (this.width != matrix.width || this.height != matrix.height) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
for (let i = 0; i < this.length; i++) {
|
|
109
|
+
if (Math.abs((this[i] as number) - (matrix[i] as number)) > epsilon) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Determines whether this matrix is exactly equivalent to another.
|
|
119
|
+
* @param matrix The other matrix.
|
|
120
|
+
* @returns Whether the matrices are equivalent.
|
|
121
|
+
*/
|
|
122
|
+
public exactEquals(matrix: Matrix): boolean {
|
|
123
|
+
if (this.width != matrix.width || this.height != matrix.height) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
for (let i = 0; i < this.length; i++) {
|
|
128
|
+
if (this[i] != matrix[i]) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Multiplies this matrix by another.
|
|
138
|
+
* @param matrix The other matrix.
|
|
139
|
+
* @returns The product of the matrices.
|
|
140
|
+
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
141
|
+
*/
|
|
142
|
+
public multiply(matrix: Matrix): SlowMatrix {
|
|
143
|
+
if (this.width != matrix.height) {
|
|
144
|
+
throw new MatrixSizeError();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const n: number = this.height;
|
|
148
|
+
const m: number = this.width;
|
|
149
|
+
const p: number = matrix.width;
|
|
150
|
+
|
|
151
|
+
const out: Array<Array<number>> = [];
|
|
152
|
+
for (let i = 0; i < n; i++) {
|
|
153
|
+
for (let j = 0; j < p; j++) {
|
|
154
|
+
let sum = 0;
|
|
155
|
+
for (let k = 0; k < m; k++) {
|
|
156
|
+
sum += (this[k * this.height + i] as number) * (matrix[j * matrix.height + k] as number)
|
|
157
|
+
}
|
|
158
|
+
(out[j] ??= [])[i] = sum;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return new SlowMatrix(...out);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Multiplies this matrix by a scalar value.
|
|
167
|
+
* @param scalar The scalar value.
|
|
168
|
+
* @returns The product of the matrix and the scalar value.
|
|
169
|
+
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
170
|
+
*/
|
|
171
|
+
public multiplyScalar(scalar: number): SlowMatrix {
|
|
172
|
+
const out = this.clone();
|
|
173
|
+
for (let i = 0; i < out.length; i++) {
|
|
174
|
+
out[i] *= scalar;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Adds this matrix to another after multiplying the other by a scalar.
|
|
182
|
+
* @param matrix The other matrix.
|
|
183
|
+
* @param scalar The scalar.
|
|
184
|
+
* @returns The sum.
|
|
185
|
+
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
186
|
+
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
187
|
+
*/
|
|
188
|
+
public multiplyScalarAndAdd(matrix: Matrix, scalar: number): SlowMatrix {
|
|
189
|
+
return this.add(matrix.multiplyScalar(scalar));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Subtracts another matrix from this one.
|
|
194
|
+
* @param matrix The other matrix.
|
|
195
|
+
* @returns The difference between the matrices.
|
|
196
|
+
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
197
|
+
*/
|
|
198
|
+
public subtract(matrix: Matrix): SlowMatrix {
|
|
199
|
+
if (this.width != matrix.width || this.height != matrix.height) {
|
|
200
|
+
throw new MatrixSizeError();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const cols: Array<Array<number>> = [];
|
|
204
|
+
for (let x = 0; x < this.width; x++) {
|
|
205
|
+
for (let y = 0; y < this.height; y++) {
|
|
206
|
+
(cols[x] ??= [])[y] = (this[x * this.height + y] as number) - (matrix[x * matrix.height + y] as number);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return new SlowMatrix(...cols);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Transposes this matrix.
|
|
215
|
+
* @returns The transpose of this matrix.
|
|
216
|
+
* @see [Transpose](https://en.wikipedia.org/wiki/Transpose)
|
|
217
|
+
*/
|
|
218
|
+
public transpose(): SlowMatrix {
|
|
219
|
+
const cols: Array<Array<number>> = [];
|
|
220
|
+
for (let x = 0; x < this.width; x++) {
|
|
221
|
+
for (let y = 0; y < this.height; y++) {
|
|
222
|
+
(cols[y] ??= [])[x] = (this[x * this.height + y] as number);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return new SlowMatrix(...cols);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { type SquareMatrix, MatrixSizeError, SingularMatrixError } from "@lakuna/umath";
|
|
2
|
+
import SlowMatrix from "@lakuna/umath/SlowMatrix";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A variable-size matrix with the same number of rows and columns.
|
|
6
|
+
* @see [Square matrix](https://en.wikipedia.org/wiki/Square_matrix)
|
|
7
|
+
*/
|
|
8
|
+
export default class SlowSquareMatrix extends SlowMatrix implements SquareMatrix {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a variable-size matrix with the same number of rows and columns from the given columns.
|
|
11
|
+
* @param cols The columns in the matrix.
|
|
12
|
+
* @see [Square matrix](https://en.wikipedia.org/wiki/Square_matrix)
|
|
13
|
+
*/
|
|
14
|
+
public constructor(...cols: Array<Array<number>>) {
|
|
15
|
+
super(...cols);
|
|
16
|
+
|
|
17
|
+
// Ensure that every column is the same height and that the height is equal to the width.
|
|
18
|
+
for (let i = 0; i < this.width; i++) {
|
|
19
|
+
if ((cols[i] as Array<number>).length != this.height) {
|
|
20
|
+
throw new MatrixSizeError();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The determinant of this matrix.
|
|
27
|
+
* @see [Determinant](https://en.wikipedia.org/wiki/Determinant)
|
|
28
|
+
*/
|
|
29
|
+
public get determinant(): number {
|
|
30
|
+
if (this.length < 1) {
|
|
31
|
+
throw new MatrixSizeError();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (this.length == 1) {
|
|
35
|
+
return this[0] ?? 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let out = 0;
|
|
39
|
+
for (let i = 0; i < this.width; i++) {
|
|
40
|
+
out += (this[i * this.height] as number) * (i % 2 ? -1 : 1) * this.minor(0, i);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Calculates the adjugate of this matrix.
|
|
48
|
+
* @returns The adjugate of this matrix.
|
|
49
|
+
* @see [Adjugate matrix](https://en.wikipedia.org/wiki/Adjugate_matrix)
|
|
50
|
+
*/
|
|
51
|
+
public adjoint(): SlowSquareMatrix {
|
|
52
|
+
return this.cofactor().transpose();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Creates a copy of this matrix.
|
|
57
|
+
* @returns A copy of this matrix.
|
|
58
|
+
*/
|
|
59
|
+
public override clone(): SlowSquareMatrix {
|
|
60
|
+
const cols: Array<Array<number>> = [];
|
|
61
|
+
for (let x = 0; x < this.width; x++) {
|
|
62
|
+
for (let y = 0; y < this.height; y++) {
|
|
63
|
+
(cols[x] ??= [])[y] = this[x * this.height + y] as number;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return new SlowSquareMatrix(...cols);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Calculates the cofactor of this matrix.
|
|
72
|
+
* @returns The cofactor.
|
|
73
|
+
* @see [Minor](https://en.wikipedia.org/wiki/Minor_(linear_algebra))
|
|
74
|
+
*/
|
|
75
|
+
public cofactor(): SlowSquareMatrix {
|
|
76
|
+
const out: Array<Array<number>> = [];
|
|
77
|
+
for (let i = 0; i < this.width; i++) { // col i
|
|
78
|
+
for (let j = 0; j < this.height; j++) { // row j
|
|
79
|
+
(out[j] ??= [])[i] = ((i + j) % 2 ? -1 : 1) * this.minor(i, j);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return new SlowSquareMatrix(...out);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Resets this matrix to identity.
|
|
88
|
+
* @returns This matrix.
|
|
89
|
+
* @see [Identity matrix](https://en.wikipedia.org/wiki/Identity_matrix)
|
|
90
|
+
*/
|
|
91
|
+
public identity(): this {
|
|
92
|
+
for (let i = 0; i < this.width; i++) {
|
|
93
|
+
for (let j = 0; j < this.height; j++) {
|
|
94
|
+
this[i * this.height + j] = i == j ? 1 : 0;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Inverts this matrix.
|
|
103
|
+
* @returns The inverted matrix.
|
|
104
|
+
* @see [Invertible matrix](https://en.wikipedia.org/wiki/Invertible_matrix)
|
|
105
|
+
*/
|
|
106
|
+
public invert(): SlowSquareMatrix {
|
|
107
|
+
const dim: number = this.width;
|
|
108
|
+
|
|
109
|
+
const clone: SlowSquareMatrix = this.clone();
|
|
110
|
+
const identity: SlowSquareMatrix = this.clone().identity();
|
|
111
|
+
|
|
112
|
+
for (let i = 0; i < dim; i++) {
|
|
113
|
+
let diagonal: number = clone[i * dim + i] as number;
|
|
114
|
+
if (!diagonal) {
|
|
115
|
+
for (let ii: number = i + 1; ii < dim; ii++) {
|
|
116
|
+
if (clone[ii * dim + i]) {
|
|
117
|
+
for (let j = 0; j < dim; j++) {
|
|
118
|
+
for (const matrix of [clone, identity]) {
|
|
119
|
+
[matrix[i * dim + j], matrix[ii * dim + j]] = [matrix[ii * dim + j] as number, matrix[i * dim + j] as number];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
diagonal = clone[i * dim + i] as number;
|
|
128
|
+
if (!diagonal) {
|
|
129
|
+
throw new SingularMatrixError();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
for (let ii = 0; ii < dim; ii++) {
|
|
134
|
+
if (ii == i) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const temp: number = clone[ii * dim + i] as number;
|
|
139
|
+
|
|
140
|
+
for (let j = 0; j < dim; j++) {
|
|
141
|
+
for (const matrix of [clone, identity]) {
|
|
142
|
+
matrix[ii * dim + j] -= temp * (matrix[i * dim + j] as number);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return identity;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Calculates the minor of this matrix which results from removing the given row and column.
|
|
153
|
+
* @param row The row to remove.
|
|
154
|
+
* @param col The column to remove.
|
|
155
|
+
* @returns The minor.
|
|
156
|
+
* @see [Minor](https://en.wikipedia.org/wiki/Minor_(linear_algebra))
|
|
157
|
+
*/
|
|
158
|
+
public minor(row: number, col: number): number {
|
|
159
|
+
return this.submatrix(row, col).determinant;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Creates a submatrix by removing the given row and column from this matrix.
|
|
164
|
+
* @param row The row to remove.
|
|
165
|
+
* @param col The column to remove.
|
|
166
|
+
* @returns The submatrix.
|
|
167
|
+
*/
|
|
168
|
+
public submatrix(row: number, col: number): SlowSquareMatrix {
|
|
169
|
+
const cols: Array<Array<number>> = [];
|
|
170
|
+
|
|
171
|
+
for (let i = 0; i < this.width; i++) {
|
|
172
|
+
if (i == col) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
for (let j = 0; j < this.height; j++) {
|
|
177
|
+
if (j == row) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
(cols[i < col ? i : i - 1] ??= [])[j < row ? j : j - 1] = this[i * this.height + j] as number;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return new SlowSquareMatrix(...cols);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Transposes this matrix.
|
|
190
|
+
* @returns The transpose of this matrix.
|
|
191
|
+
* @see [Transpose](https://en.wikipedia.org/wiki/Transpose)
|
|
192
|
+
*/
|
|
193
|
+
public override transpose(): SlowSquareMatrix {
|
|
194
|
+
const cols: Array<Array<number>> = [];
|
|
195
|
+
for (let x = 0; x < this.width; x++) {
|
|
196
|
+
for (let y = 0; y < this.height; y++) {
|
|
197
|
+
(cols[y] ??= [])[x] = (this[x * this.height + y] as number);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return new SlowSquareMatrix(...cols);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -11,6 +11,13 @@ export default interface SquareMatrix extends Matrix {
|
|
|
11
11
|
*/
|
|
12
12
|
get determinant(): number;
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Calculates the adjugate of this matrix.
|
|
16
|
+
* @returns The adjugate of this matrix.
|
|
17
|
+
* @see [Adjugate matrix](https://en.wikipedia.org/wiki/Adjugate_matrix)
|
|
18
|
+
*/
|
|
19
|
+
adjoint(): Matrix;
|
|
20
|
+
|
|
14
21
|
/**
|
|
15
22
|
* Resets this matrix to identity.
|
|
16
23
|
* @returns This matrix.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** An error resulting from trying to use a matrix that is the wrong size. */
|
|
2
|
+
export default class PartialMatrixError extends Error {
|
|
3
|
+
/**
|
|
4
|
+
* Creates an error resulting from trying to use a matrix that is the wrong size.
|
|
5
|
+
* @param message The message of the error.
|
|
6
|
+
*/
|
|
7
|
+
public constructor(message = "Invalid matrix dimensions.") {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "MatrixSizeError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** An error resulting from creating a matrix that isn't a perfect rectangle. */
|
|
2
|
+
export default class PartialMatrixError extends Error {
|
|
3
|
+
/**
|
|
4
|
+
* Creates an error resulting from creating a matrix that isn't a perfect rectangle.
|
|
5
|
+
* @param message The message of the error.
|
|
6
|
+
*/
|
|
7
|
+
public constructor(message = "The matrix is not rectangular.") {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "PartialMatrixError";
|
|
10
|
+
}
|
|
11
|
+
}
|