curvy 2.0.0-alpha.13 → 2.0.0-alpha.14
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/characteristic/index.mjs +1 -1
- package/dist/curve/cubic2d.d.ts +102 -3
- package/dist/curve/curve2d.d.ts +81 -0
- package/dist/curve/index.mjs +1 -1
- package/dist/curve/linear2d.d.ts +122 -3
- package/dist/curve/quadratic2d.d.ts +103 -3
- package/dist/curve/rationalCubic2d.d.ts +100 -38
- package/dist/interval/index.mjs +2 -2
- package/dist/matrix/index.mjs +47 -1
- package/dist/matrix/index.mjs.map +1 -1
- package/dist/matrix/matrix3x3.d.ts +87 -1
- package/dist/matrix/matrix4x4.d.ts +57 -6
- package/dist/matrix/traits.d.ts +34 -0
- package/dist/monotonicity/index.mjs +1 -1
- package/dist/monotonicity/monotonicity.d.ts +25 -0
- package/dist/number.d.ts +53 -0
- package/dist/number.mjs +56 -1
- package/dist/number.mjs.map +1 -1
- package/dist/path/cubic2d.d.ts +22 -0
- package/dist/path/index.mjs +25 -149
- package/dist/path/index.mjs.map +1 -1
- package/dist/path/linear2d.d.ts +24 -0
- package/dist/path/path2d.d.ts +54 -0
- package/dist/path/quadratic2d.d.ts +22 -0
- package/dist/path/rationalCubic2d.d.ts +21 -0
- package/dist/polynomial/index.mjs +2 -2
- package/dist/shared/affine2d-Dvna84gc.mjs +332 -0
- package/dist/shared/affine2d-Dvna84gc.mjs.map +1 -0
- package/dist/shared/{characteristic-BkEr-rr8.mjs → characteristic--7nC4Q_a.mjs} +4 -5
- package/dist/shared/characteristic--7nC4Q_a.mjs.map +1 -0
- package/dist/shared/{cubic-BL6dpuHh.mjs → cubic-BiGuAnZ0.mjs} +56 -27
- package/dist/shared/cubic-BiGuAnZ0.mjs.map +1 -0
- package/dist/shared/{interval-Dm35Xhy4.mjs → interval-Dcqpo73t.mjs} +5 -5
- package/dist/shared/interval-Dcqpo73t.mjs.map +1 -0
- package/dist/shared/{interval2d-AtneyI45.mjs → interval2d-C2Pk66-2.mjs} +3 -3
- package/dist/shared/{interval2d-AtneyI45.mjs.map → interval2d-C2Pk66-2.mjs.map} +1 -1
- package/dist/shared/matrix3x3.internal-Cod-r7H3.mjs +233 -0
- package/dist/shared/matrix3x3.internal-Cod-r7H3.mjs.map +1 -0
- package/dist/shared/{matrix4x4-BWmf4lZM.mjs → matrix4x4-BrqgYZCD.mjs} +72 -223
- package/dist/shared/matrix4x4-BrqgYZCD.mjs.map +1 -0
- package/dist/shared/monotonicity-DNxBoC7F.mjs +64 -0
- package/dist/shared/monotonicity-DNxBoC7F.mjs.map +1 -0
- package/dist/shared/{quadratic-DPrUsFCp.mjs → quadratic-BmMqkvxx.mjs} +2 -2
- package/dist/shared/{quadratic-DPrUsFCp.mjs.map → quadratic-BmMqkvxx.mjs.map} +1 -1
- package/dist/shared/{rationalCubic2d-CeHgpNht.mjs → rationalCubic2d-CZSwwKtS.mjs} +591 -125
- package/dist/shared/rationalCubic2d-CZSwwKtS.mjs.map +1 -0
- package/dist/shared/{rationalCubic2d-H1J2Fjyy.mjs → rationalCubic2d-bveuGqBZ.mjs} +282 -326
- package/dist/shared/rationalCubic2d-bveuGqBZ.mjs.map +1 -0
- package/dist/shared/{solution-B2JdOZpe.mjs → solution-BW0BBMXI.mjs} +22 -6
- package/dist/shared/solution-BW0BBMXI.mjs.map +1 -0
- package/dist/shared/{vector2-CSkaMXvp.mjs → vector2-DuA3EmfL.mjs} +5 -3
- package/dist/shared/vector2-DuA3EmfL.mjs.map +1 -0
- package/dist/shared/{vector2.internal-DP1nTBdS.mjs → vector2.internal-rPnW0RCx.mjs} +10 -5
- package/dist/shared/vector2.internal-rPnW0RCx.mjs.map +1 -0
- package/dist/shared/{vector3-CR2LPV03.mjs → vector3-oxtggkDp.mjs} +2 -2
- package/dist/shared/{vector3-CR2LPV03.mjs.map → vector3-oxtggkDp.mjs.map} +1 -1
- package/dist/shared/vector3.internal-CfWHl9SG.mjs +135 -0
- package/dist/shared/vector3.internal-CfWHl9SG.mjs.map +1 -0
- package/dist/shared/{vector4-PO_7EYd-.mjs → vector4-DGHuCvTV.mjs} +2 -2
- package/dist/shared/{vector4-PO_7EYd-.mjs.map → vector4-DGHuCvTV.mjs.map} +1 -1
- package/dist/shared/vector4.internal-DH5DzNYO.mjs +116 -0
- package/dist/shared/vector4.internal-DH5DzNYO.mjs.map +1 -0
- package/dist/solution/index.mjs +1 -1
- package/dist/solution/solution.d.ts +16 -0
- package/dist/splines/basis2d.d.ts +64 -0
- package/dist/splines/bezier2d.d.ts +72 -0
- package/dist/splines/cardinal2d.d.ts +78 -0
- package/dist/splines/hermite2d.d.ts +76 -0
- package/dist/splines/index.mjs +109 -15
- package/dist/splines/index.mjs.map +1 -1
- package/dist/splines/linear2d.d.ts +65 -0
- package/dist/splines/rationalBezier2d.d.ts +76 -0
- package/dist/transform/affine2d.d.ts +339 -0
- package/dist/transform/affine2d.internal.d.ts +2 -0
- package/dist/transform/index.d.ts +3 -0
- package/dist/transform/index.mjs +2 -0
- package/dist/transform/traits.d.ts +19 -0
- package/dist/vector/index.mjs +3 -3
- package/dist/vector/vector2.d.ts +49 -0
- package/package.json +5 -1
- package/dist/shared/characteristic-BkEr-rr8.mjs.map +0 -1
- package/dist/shared/cubic-BL6dpuHh.mjs.map +0 -1
- package/dist/shared/interval-Dm35Xhy4.mjs.map +0 -1
- package/dist/shared/matrix4x4-BWmf4lZM.mjs.map +0 -1
- package/dist/shared/monotonicity-BdebFOtv.mjs +0 -34
- package/dist/shared/monotonicity-BdebFOtv.mjs.map +0 -1
- package/dist/shared/rationalCubic2d-CeHgpNht.mjs.map +0 -1
- package/dist/shared/rationalCubic2d-H1J2Fjyy.mjs.map +0 -1
- package/dist/shared/solution-B2JdOZpe.mjs.map +0 -1
- package/dist/shared/vector2-CSkaMXvp.mjs.map +0 -1
- package/dist/shared/vector2.internal-DP1nTBdS.mjs.map +0 -1
- package/dist/shared/vector4.internal-BJ1QN2Ck.mjs +0 -246
- package/dist/shared/vector4.internal-BJ1QN2Ck.mjs.map +0 -1
|
@@ -1,202 +1,9 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-25Hzd3z8.mjs";
|
|
2
2
|
import { Pipeable, dual, invariant } from "../utils.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
function toIndex(input) {
|
|
8
|
-
if (typeof input === "number") {
|
|
9
|
-
invariant(input >= 0 && input <= 3, "Index out of bounds");
|
|
10
|
-
return input;
|
|
11
|
-
}
|
|
12
|
-
if (input === "x") return 0;
|
|
13
|
-
if (input === "y") return 1;
|
|
14
|
-
if (input === "z") return 2;
|
|
15
|
-
if (input === "w") return 3;
|
|
16
|
-
invariant(false, "Invalid component");
|
|
17
|
-
}
|
|
18
|
-
const toTwoDimensionalIndex = toIndex;
|
|
19
|
-
const toThreeDimensionalIndex = toIndex;
|
|
20
|
-
const toFourDimensionalIndex = toIndex;
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/matrix/matrix2x2.internal.ts
|
|
23
|
-
const Matrix2x2TypeId = Symbol.for("curvy/matrix2x2");
|
|
24
|
-
var Matrix2x2Impl = class extends Pipeable {
|
|
25
|
-
[Matrix2x2TypeId] = Matrix2x2TypeId;
|
|
26
|
-
m00;
|
|
27
|
-
m01;
|
|
28
|
-
m10;
|
|
29
|
-
m11;
|
|
30
|
-
constructor(m00 = 0, m01 = 0, m10 = 0, m11 = 0) {
|
|
31
|
-
super();
|
|
32
|
-
this.m00 = m00;
|
|
33
|
-
this.m01 = m01;
|
|
34
|
-
this.m10 = m10;
|
|
35
|
-
this.m11 = m11;
|
|
36
|
-
}
|
|
37
|
-
get [Symbol.toStringTag]() {
|
|
38
|
-
return `Matrix2x2(${this.m00}, ${this.m01}, ${this.m10}, ${this.m11})`;
|
|
39
|
-
}
|
|
40
|
-
get [Symbol.for("nodejs.util.inspect.custom")]() {
|
|
41
|
-
return `Matrix2x2(${this.m00}, ${this.m01}, ${this.m10}, ${this.m11})`;
|
|
42
|
-
}
|
|
43
|
-
[Symbol.hasInstance](m) {
|
|
44
|
-
return isMatrix2x2(m);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
/** @internal */
|
|
48
|
-
const isMatrix2x2 = (m) => typeof m === "object" && m !== null && Matrix2x2TypeId in m;
|
|
49
|
-
/** @internal */
|
|
50
|
-
const equals$3 = dual(2, (a, b) => epsEquals(a.m00, b.m00) && epsEquals(a.m01, b.m01) && epsEquals(a.m10, b.m10) && epsEquals(a.m11, b.m11));
|
|
51
|
-
/** @internal */
|
|
52
|
-
const make$3 = (m00 = 0, m01 = m00, m10 = m01, m11 = m10) => new Matrix2x2Impl(m00, m01, m10, m11);
|
|
53
|
-
/** @internal */
|
|
54
|
-
const fromRows$3 = (v0, v1) => new Matrix2x2Impl(v0.x, v0.y, v1.x, v1.y);
|
|
55
|
-
/** @internal */
|
|
56
|
-
const fromColumns$3 = (v0, v1) => new Matrix2x2Impl(v0.x, v1.x, v0.y, v1.y);
|
|
57
|
-
/** @internal */
|
|
58
|
-
const setRow$3 = dual(3, (m, row, v) => fromRows$3(...toRows$3(m).with(toTwoDimensionalIndex(row), v)));
|
|
59
|
-
/** @internal */
|
|
60
|
-
const setColumn$3 = dual(3, (m, column, v) => fromColumns$3(...toColumns$3(m).with(toTwoDimensionalIndex(column), v)));
|
|
61
|
-
/** @internal */
|
|
62
|
-
const determinant$3 = (m) => m.m00 * m.m11 - m.m01 * m.m10;
|
|
63
|
-
/** @internal */
|
|
64
|
-
const vectorProductLeft$3 = dual(2, (m, v) => make$4(dot(rowVector$3(m, 0), v), dot(rowVector$3(m, 1), v)));
|
|
65
|
-
/** @internal */
|
|
66
|
-
const vectorProductRight$3 = dual(2, (m, v) => make$4(dot(columnVector$3(m, 0), v), dot(columnVector$3(m, 1), v)));
|
|
67
|
-
/** @internal */
|
|
68
|
-
const solveSystem$3 = dual(2, (m, v) => {
|
|
69
|
-
const inverseDeterminant = 1 / determinant$3(m);
|
|
70
|
-
invariant(Number.isFinite(inverseDeterminant), "cannot solve system when coefficient matrix determinant is zero");
|
|
71
|
-
return make$4(determinant$3(setColumn$3(m, 0, v)) * inverseDeterminant, determinant$3(setColumn$3(m, 1, v)) * inverseDeterminant);
|
|
72
|
-
});
|
|
73
|
-
/** @internal */
|
|
74
|
-
const toRows$3 = (m) => [make$4(m.m00, m.m01), make$4(m.m10, m.m11)];
|
|
75
|
-
/** @internal */
|
|
76
|
-
const toColumns$3 = (m) => [make$4(m.m00, m.m10), make$4(m.m01, m.m11)];
|
|
77
|
-
/** @internal */
|
|
78
|
-
const rowVector$3 = dual(2, (m, row) => toRows$3(m)[toTwoDimensionalIndex(row)]);
|
|
79
|
-
/** @internal */
|
|
80
|
-
const columnVector$3 = dual(2, (m, column) => toColumns$3(m)[toTwoDimensionalIndex(column)]);
|
|
81
|
-
/** @internal */
|
|
82
|
-
const transpose$3 = (m) => fromColumns$3(...toRows$3(m));
|
|
83
|
-
/** @internal */
|
|
84
|
-
const reverseRows$3 = (m) => {
|
|
85
|
-
const [r0, r1] = toRows$3(m);
|
|
86
|
-
return fromRows$3(r1, r0);
|
|
87
|
-
};
|
|
88
|
-
/** @internal */
|
|
89
|
-
const reverseColumns$3 = (m) => {
|
|
90
|
-
const [c0, c1] = toColumns$3(m);
|
|
91
|
-
return fromColumns$3(c1, c0);
|
|
92
|
-
};
|
|
93
|
-
//#endregion
|
|
94
|
-
//#region src/matrix/matrix3x3.internal.ts
|
|
95
|
-
const Matrix3x3TypeId = Symbol.for("curvy/matrix3x3");
|
|
96
|
-
var Matrix3x3Impl = class extends Pipeable {
|
|
97
|
-
[Matrix3x3TypeId] = Matrix3x3TypeId;
|
|
98
|
-
m00;
|
|
99
|
-
m01;
|
|
100
|
-
m02;
|
|
101
|
-
m10;
|
|
102
|
-
m11;
|
|
103
|
-
m12;
|
|
104
|
-
m20;
|
|
105
|
-
m21;
|
|
106
|
-
m22;
|
|
107
|
-
constructor(m00 = 0, m01 = 0, m02 = 0, m10 = 0, m11 = 0, m12 = 0, m20 = 0, m21 = 0, m22 = 0) {
|
|
108
|
-
super();
|
|
109
|
-
this.m00 = m00;
|
|
110
|
-
this.m01 = m01;
|
|
111
|
-
this.m02 = m02;
|
|
112
|
-
this.m10 = m10;
|
|
113
|
-
this.m11 = m11;
|
|
114
|
-
this.m12 = m12;
|
|
115
|
-
this.m20 = m20;
|
|
116
|
-
this.m21 = m21;
|
|
117
|
-
this.m22 = m22;
|
|
118
|
-
}
|
|
119
|
-
get [Symbol.toStringTag]() {
|
|
120
|
-
return `Matrix3x3(${this.m00}, ${this.m01}, ${this.m02}, ${this.m10}, ${this.m11}, ${this.m12}, ${this.m20}, ${this.m21}, ${this.m22})`;
|
|
121
|
-
}
|
|
122
|
-
get [Symbol.for("nodejs.util.inspect.custom")]() {
|
|
123
|
-
return `Matrix3x3(${this.m00}, ${this.m01}, ${this.m02}, ${this.m10}, ${this.m11}, ${this.m12}, ${this.m20}, ${this.m21}, ${this.m22})`;
|
|
124
|
-
}
|
|
125
|
-
[Symbol.hasInstance](m) {
|
|
126
|
-
return isMatrix3x3(m);
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
/** @internal */
|
|
130
|
-
const isMatrix3x3 = (m) => typeof m === "object" && m !== null && Matrix3x3TypeId in m;
|
|
131
|
-
/** @internal */
|
|
132
|
-
const equals$2 = dual(2, (a, b) => epsEquals(a.m00, b.m00) && epsEquals(a.m01, b.m01) && epsEquals(a.m02, b.m02) && epsEquals(a.m10, b.m10) && epsEquals(a.m11, b.m11) && epsEquals(a.m12, b.m12) && epsEquals(a.m20, b.m20) && epsEquals(a.m21, b.m21) && epsEquals(a.m22, b.m22));
|
|
133
|
-
/** @internal */
|
|
134
|
-
const make$2 = (m00 = 0, m01 = m00, m02 = m01, m10 = m02, m11 = m10, m12 = m11, m20 = m12, m21 = m20, m22 = m21) => {
|
|
135
|
-
return new Matrix3x3Impl(m00, m01, m02, m10, m11, m12, m20, m21, m22);
|
|
136
|
-
};
|
|
137
|
-
/** @internal */
|
|
138
|
-
const fromRows$2 = (v0, v1, v2) => new Matrix3x3Impl(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, v2.x, v2.y, v2.z);
|
|
139
|
-
/** @internal */
|
|
140
|
-
const fromColumns$2 = (v0, v1, v2) => new Matrix3x3Impl(v0.x, v1.x, v2.x, v0.y, v1.y, v2.y, v0.z, v1.z, v2.z);
|
|
141
|
-
/** @internal */
|
|
142
|
-
const setRow$2 = dual(3, (m, row, v) => fromRows$2(...toRows$2(m).with(toThreeDimensionalIndex(row), v)));
|
|
143
|
-
/** @internal */
|
|
144
|
-
const setColumn$2 = dual(3, (m, column, v) => fromColumns$2(...toColumns$2(m).with(toThreeDimensionalIndex(column), v)));
|
|
145
|
-
/** @internal */
|
|
146
|
-
const determinant$2 = (m) => m.m00 * determinant$3(minor$2(m, 0, 0)) - m.m01 * determinant$3(minor$2(m, 0, 1)) + m.m02 * determinant$3(minor$2(m, 0, 2));
|
|
147
|
-
/** @internal */
|
|
148
|
-
const minor$2 = dual(3, (m, row, column) => {
|
|
149
|
-
const [v0, v1] = toRows$2(m).toSpliced(toThreeDimensionalIndex(row), 1);
|
|
150
|
-
const columnIndex = toThreeDimensionalIndex(column);
|
|
151
|
-
const [m00, m01] = components(v0).toSpliced(columnIndex, 1);
|
|
152
|
-
const [m10, m11] = components(v1).toSpliced(columnIndex, 1);
|
|
153
|
-
return make$3(m00, m01, m10, m11);
|
|
154
|
-
});
|
|
155
|
-
/** @internal */
|
|
156
|
-
const vectorProductLeft$2 = dual(2, (m, v) => {
|
|
157
|
-
const [v0, v1, v2] = toRows$2(m);
|
|
158
|
-
return make$5(dot$1(v0, v), dot$1(v1, v), dot$1(v2, v));
|
|
159
|
-
});
|
|
160
|
-
/** @internal */
|
|
161
|
-
const vectorProductRight$2 = dual(2, (m, v) => {
|
|
162
|
-
const [v0, v1, v2] = toColumns$2(m);
|
|
163
|
-
return make$5(dot$1(v, v0), dot$1(v, v1), dot$1(v, v2));
|
|
164
|
-
});
|
|
165
|
-
/** @internal */
|
|
166
|
-
const solveSystem$2 = dual(2, (m, v) => {
|
|
167
|
-
const inverseDeterminant = 1 / determinant$2(m);
|
|
168
|
-
invariant(Number.isFinite(inverseDeterminant), "cannot solve system when coefficient matrix determinant is zero");
|
|
169
|
-
return make$5(determinant$2(setColumn$2(m, 0, v)) * inverseDeterminant, determinant$2(setColumn$2(m, 1, v)) * inverseDeterminant, determinant$2(setColumn$2(m, 2, v)) * inverseDeterminant);
|
|
170
|
-
});
|
|
171
|
-
/** @internal */
|
|
172
|
-
const toRows$2 = (m) => [
|
|
173
|
-
make$5(m.m00, m.m01, m.m02),
|
|
174
|
-
make$5(m.m10, m.m11, m.m12),
|
|
175
|
-
make$5(m.m20, m.m21, m.m22)
|
|
176
|
-
];
|
|
177
|
-
/** @internal */
|
|
178
|
-
const toColumns$2 = (m) => [
|
|
179
|
-
make$5(m.m00, m.m10, m.m20),
|
|
180
|
-
make$5(m.m01, m.m11, m.m21),
|
|
181
|
-
make$5(m.m02, m.m12, m.m22)
|
|
182
|
-
];
|
|
183
|
-
/** @internal */
|
|
184
|
-
const rowVector$2 = dual(2, (m, row) => toRows$2(m)[toThreeDimensionalIndex(row)]);
|
|
185
|
-
/** @internal */
|
|
186
|
-
const columnVector$2 = dual(2, (m, column) => toColumns$2(m)[toThreeDimensionalIndex(column)]);
|
|
187
|
-
/** @internal */
|
|
188
|
-
const transpose$2 = (m) => fromColumns$2(...toRows$2(m));
|
|
189
|
-
/** @internal */
|
|
190
|
-
const reverseRows$2 = (m) => {
|
|
191
|
-
const [v0, v1, v2] = toRows$2(m);
|
|
192
|
-
return fromRows$2(v2, v1, v0);
|
|
193
|
-
};
|
|
194
|
-
/** @internal */
|
|
195
|
-
const reverseColumns$2 = (m) => {
|
|
196
|
-
const [v0, v1, v2] = toColumns$2(m);
|
|
197
|
-
return fromColumns$2(v2, v1, v0);
|
|
198
|
-
};
|
|
199
|
-
//#endregion
|
|
3
|
+
import { RELATIVE_TOLERANCE, coincident } from "../number.mjs";
|
|
4
|
+
import { n as components, p as make$2, r as dot } from "./vector4.internal-DH5DzNYO.mjs";
|
|
5
|
+
import { W as toFourDimensionalIndex, f as make$3, r as determinant$2 } from "./matrix3x3.internal-Cod-r7H3.mjs";
|
|
6
|
+
import { c as one, s as none } from "./solution-BW0BBMXI.mjs";
|
|
200
7
|
//#region src/matrix/matrix4x4.internal.ts
|
|
201
8
|
const Matrix4x4TypeId = Symbol.for("curvy/matrix4x4");
|
|
202
9
|
var Matrix4x4Impl = class extends Pipeable {
|
|
@@ -249,7 +56,7 @@ var Matrix4x4Impl = class extends Pipeable {
|
|
|
249
56
|
/** @internal */
|
|
250
57
|
const isMatrix4x4$1 = (m) => typeof m === "object" && m !== null && Matrix4x4TypeId in m;
|
|
251
58
|
/** @internal */
|
|
252
|
-
const equals$1 = dual(2, (a, b) =>
|
|
59
|
+
const equals$1 = dual(2, (a, b) => coincident(a.m00, b.m00) && coincident(a.m01, b.m01) && coincident(a.m02, b.m02) && coincident(a.m03, b.m03) && coincident(a.m10, b.m10) && coincident(a.m11, b.m11) && coincident(a.m12, b.m12) && coincident(a.m13, b.m13) && coincident(a.m20, b.m20) && coincident(a.m21, b.m21) && coincident(a.m22, b.m22) && coincident(a.m23, b.m23) && coincident(a.m30, b.m30) && coincident(a.m31, b.m31) && coincident(a.m32, b.m32) && coincident(a.m33, b.m33));
|
|
253
60
|
/**
|
|
254
61
|
* The 4x4 identity matrix.
|
|
255
62
|
* @internal
|
|
@@ -271,27 +78,32 @@ const determinant$1 = (m) => m.m00 * determinant$2(minor$1(m, 0, 0)) - m.m01 * d
|
|
|
271
78
|
const minor$1 = dual(3, (m, row, column) => {
|
|
272
79
|
const [v0, v1, v2] = toRows$1(m).toSpliced(toFourDimensionalIndex(row), 1);
|
|
273
80
|
const columnIndex = toFourDimensionalIndex(column);
|
|
274
|
-
const [m00, m01, m02] = components
|
|
275
|
-
const [m10, m11, m12] = components
|
|
276
|
-
const [m20, m21, m22] = components
|
|
277
|
-
return make$
|
|
81
|
+
const [m00, m01, m02] = components(v0).toSpliced(columnIndex, 1);
|
|
82
|
+
const [m10, m11, m12] = components(v1).toSpliced(columnIndex, 1);
|
|
83
|
+
const [m20, m21, m22] = components(v2).toSpliced(columnIndex, 1);
|
|
84
|
+
return make$3(m00, m01, m02, m10, m11, m12, m20, m21, m22);
|
|
278
85
|
});
|
|
279
86
|
/** @internal */
|
|
280
87
|
const vectorProductLeft$1 = dual(2, (m, v) => {
|
|
281
88
|
const [v0, v1, v2, v3] = toRows$1(m);
|
|
282
|
-
return make$
|
|
89
|
+
return make$2(dot(v0, v), dot(v1, v), dot(v2, v), dot(v3, v));
|
|
283
90
|
});
|
|
284
91
|
/** @internal */
|
|
285
92
|
const vectorProductRight$1 = dual(2, (m, v) => {
|
|
286
93
|
const [v0, v1, v2, v3] = toColumns$1(m);
|
|
287
|
-
return make$
|
|
94
|
+
return make$2(dot(v, v0), dot(v, v1), dot(v, v2), dot(v, v3));
|
|
288
95
|
});
|
|
289
96
|
/** @internal */
|
|
290
97
|
const multiply$1 = dual(2, (a, b) => new Matrix4x4Impl(a.m00 * b.m00 + a.m01 * b.m10 + a.m02 * b.m20 + a.m03 * b.m30, a.m00 * b.m01 + a.m01 * b.m11 + a.m02 * b.m21 + a.m03 * b.m31, a.m00 * b.m02 + a.m01 * b.m12 + a.m02 * b.m22 + a.m03 * b.m32, a.m00 * b.m03 + a.m01 * b.m13 + a.m02 * b.m23 + a.m03 * b.m33, a.m10 * b.m00 + a.m11 * b.m10 + a.m12 * b.m20 + a.m13 * b.m30, a.m10 * b.m01 + a.m11 * b.m11 + a.m12 * b.m21 + a.m13 * b.m31, a.m10 * b.m02 + a.m11 * b.m12 + a.m12 * b.m22 + a.m13 * b.m32, a.m10 * b.m03 + a.m11 * b.m13 + a.m12 * b.m23 + a.m13 * b.m33, a.m20 * b.m00 + a.m21 * b.m10 + a.m22 * b.m20 + a.m23 * b.m30, a.m20 * b.m01 + a.m21 * b.m11 + a.m22 * b.m21 + a.m23 * b.m31, a.m20 * b.m02 + a.m21 * b.m12 + a.m22 * b.m22 + a.m23 * b.m32, a.m20 * b.m03 + a.m21 * b.m13 + a.m22 * b.m23 + a.m23 * b.m33, a.m30 * b.m00 + a.m31 * b.m10 + a.m32 * b.m20 + a.m33 * b.m30, a.m30 * b.m01 + a.m31 * b.m11 + a.m32 * b.m21 + a.m33 * b.m31, a.m30 * b.m02 + a.m31 * b.m12 + a.m32 * b.m22 + a.m33 * b.m32, a.m30 * b.m03 + a.m31 * b.m13 + a.m32 * b.m23 + a.m33 * b.m33));
|
|
98
|
+
const singularityThreshold = (m) => RELATIVE_TOLERANCE * Math.hypot(m.m00, m.m01, m.m02, m.m03) * Math.hypot(m.m10, m.m11, m.m12, m.m13) * Math.hypot(m.m20, m.m21, m.m22, m.m23) * Math.hypot(m.m30, m.m31, m.m32, m.m33);
|
|
291
99
|
/** @internal */
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
100
|
+
const isInvertible$1 = (m) => Math.abs(determinant$1(m)) > singularityThreshold(m);
|
|
101
|
+
/** @internal */
|
|
102
|
+
const asInvertible$1 = (m) => {
|
|
103
|
+
invariant(isInvertible$1(m), "matrix4x4 is not invertible");
|
|
104
|
+
return m;
|
|
105
|
+
};
|
|
106
|
+
const buildInverse = (m, det) => {
|
|
295
107
|
const inv = 1 / det;
|
|
296
108
|
const cof = (row, col) => {
|
|
297
109
|
return ((row + col) % 2 === 0 ? 1 : -1) * determinant$2(minor$1(m, row, col)) * inv;
|
|
@@ -299,24 +111,36 @@ const inverse$1 = (m) => {
|
|
|
299
111
|
return new Matrix4x4Impl(cof(0, 0), cof(1, 0), cof(2, 0), cof(3, 0), cof(0, 1), cof(1, 1), cof(2, 1), cof(3, 1), cof(0, 2), cof(1, 2), cof(2, 2), cof(3, 2), cof(0, 3), cof(1, 3), cof(2, 3), cof(3, 3));
|
|
300
112
|
};
|
|
301
113
|
/** @internal */
|
|
114
|
+
const inverse$1 = (m) => {
|
|
115
|
+
const det = determinant$1(m);
|
|
116
|
+
if (Math.abs(det) <= singularityThreshold(m)) return none;
|
|
117
|
+
return one(buildInverse(m, det));
|
|
118
|
+
};
|
|
119
|
+
/** @internal */
|
|
120
|
+
const inverseUnsafe$1 = (m) => {
|
|
121
|
+
const det = determinant$1(m);
|
|
122
|
+
invariant(Math.abs(det) > singularityThreshold(m), "cannot invert singular matrix");
|
|
123
|
+
return buildInverse(m, det);
|
|
124
|
+
};
|
|
125
|
+
/** @internal */
|
|
302
126
|
const solveSystem$1 = dual(2, (m, v) => {
|
|
303
127
|
const inverseDeterminant = 1 / determinant$1(m);
|
|
304
128
|
invariant(Number.isFinite(inverseDeterminant), "cannot solve system when coefficient matrix determinant is zero");
|
|
305
|
-
return make$
|
|
129
|
+
return make$2(determinant$1(setColumn$1(m, 0, v)) * inverseDeterminant, determinant$1(setColumn$1(m, 1, v)) * inverseDeterminant, determinant$1(setColumn$1(m, 2, v)) * inverseDeterminant, determinant$1(setColumn$1(m, 3, v)) * inverseDeterminant);
|
|
306
130
|
});
|
|
307
131
|
/** @internal */
|
|
308
132
|
const toRows$1 = (m) => [
|
|
309
|
-
make$
|
|
310
|
-
make$
|
|
311
|
-
make$
|
|
312
|
-
make$
|
|
133
|
+
make$2(m.m00, m.m01, m.m02, m.m03),
|
|
134
|
+
make$2(m.m10, m.m11, m.m12, m.m13),
|
|
135
|
+
make$2(m.m20, m.m21, m.m22, m.m23),
|
|
136
|
+
make$2(m.m30, m.m31, m.m32, m.m33)
|
|
313
137
|
];
|
|
314
138
|
/** @internal */
|
|
315
139
|
const toColumns$1 = (m) => [
|
|
316
|
-
make$
|
|
317
|
-
make$
|
|
318
|
-
make$
|
|
319
|
-
make$
|
|
140
|
+
make$2(m.m00, m.m10, m.m20, m.m30),
|
|
141
|
+
make$2(m.m01, m.m11, m.m21, m.m31),
|
|
142
|
+
make$2(m.m02, m.m12, m.m22, m.m32),
|
|
143
|
+
make$2(m.m03, m.m13, m.m23, m.m33)
|
|
320
144
|
];
|
|
321
145
|
/** @internal */
|
|
322
146
|
const rowVector$1 = dual(2, (m, row) => toRows$1(m)[toFourDimensionalIndex(row)]);
|
|
@@ -337,6 +161,7 @@ const reverseColumns$1 = (m) => {
|
|
|
337
161
|
//#endregion
|
|
338
162
|
//#region src/matrix/matrix4x4.ts
|
|
339
163
|
var matrix4x4_exports = /* @__PURE__ */ __exportAll({
|
|
164
|
+
asInvertible: () => asInvertible,
|
|
340
165
|
columnVector: () => columnVector,
|
|
341
166
|
determinant: () => determinant,
|
|
342
167
|
equals: () => equals,
|
|
@@ -344,6 +169,8 @@ var matrix4x4_exports = /* @__PURE__ */ __exportAll({
|
|
|
344
169
|
fromRows: () => fromRows,
|
|
345
170
|
identity: () => identity,
|
|
346
171
|
inverse: () => inverse,
|
|
172
|
+
inverseUnsafe: () => inverseUnsafe,
|
|
173
|
+
isInvertible: () => isInvertible,
|
|
347
174
|
isMatrix4x4: () => isMatrix4x4,
|
|
348
175
|
make: () => make,
|
|
349
176
|
minor: () => minor,
|
|
@@ -440,16 +267,38 @@ const minor = minor$1;
|
|
|
440
267
|
const vectorProductLeft = vectorProductLeft$1;
|
|
441
268
|
const vectorProductRight = vectorProductRight$1;
|
|
442
269
|
const multiply = multiply$1;
|
|
270
|
+
const inverse = inverse$1;
|
|
443
271
|
/**
|
|
444
|
-
* Returns the inverse of a `Matrix4x4`.
|
|
445
|
-
*
|
|
446
|
-
*
|
|
272
|
+
* Returns the inverse of a `Matrix4x4`. Throws when the matrix is singular
|
|
273
|
+
* (determinant approximately zero). Useful when you've already validated
|
|
274
|
+
* invertibility out-of-band and want the unwrapped matrix directly; otherwise
|
|
275
|
+
* prefer {@link inverse}.
|
|
447
276
|
*
|
|
448
277
|
* @param m - The matrix to invert.
|
|
449
278
|
* @returns The inverse matrix.
|
|
450
|
-
* @
|
|
279
|
+
* @throws If `m` is singular.
|
|
280
|
+
* @since 2.0.0
|
|
451
281
|
*/
|
|
452
|
-
const
|
|
282
|
+
const inverseUnsafe = inverseUnsafe$1;
|
|
283
|
+
/**
|
|
284
|
+
* Type-narrowing predicate: refines a `Matrix4x4<T>` to
|
|
285
|
+
* `Matrix4x4<T & Invertible>` when the matrix's determinant is non-zero
|
|
286
|
+
* (within the default absolute tolerance).
|
|
287
|
+
*
|
|
288
|
+
* @param m - The matrix to check.
|
|
289
|
+
* @returns `true` when `m` is invertible.
|
|
290
|
+
* @since 2.0.0
|
|
291
|
+
*/
|
|
292
|
+
const isInvertible = isInvertible$1;
|
|
293
|
+
/**
|
|
294
|
+
* Asserts that the matrix is invertible, throwing on a singular matrix.
|
|
295
|
+
*
|
|
296
|
+
* @param m - The matrix to assert against.
|
|
297
|
+
* @returns The same matrix, typed with the `Invertible` brand.
|
|
298
|
+
* @throws When `m` is singular.
|
|
299
|
+
* @since 2.0.0
|
|
300
|
+
*/
|
|
301
|
+
const asInvertible = asInvertible$1;
|
|
453
302
|
const solveSystem = solveSystem$1;
|
|
454
303
|
/**
|
|
455
304
|
* Returns the rows of a `Matrix4x4` as an array of vectors.
|
|
@@ -494,6 +343,6 @@ const reverseRows = reverseRows$1;
|
|
|
494
343
|
*/
|
|
495
344
|
const reverseColumns = reverseColumns$1;
|
|
496
345
|
//#endregion
|
|
497
|
-
export {
|
|
346
|
+
export { vectorProductLeft as a, multiply as i, make as n, matrix4x4_exports as r, inverseUnsafe as t };
|
|
498
347
|
|
|
499
|
-
//# sourceMappingURL=matrix4x4-
|
|
348
|
+
//# sourceMappingURL=matrix4x4-BrqgYZCD.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrix4x4-BrqgYZCD.mjs","names":["isMatrix4x4","equals","identity","make","fromRows","fromColumns","setRow","toRows","setColumn","toColumns","determinant","matrix3x3.determinant","minor","vector4.components","matrix3x3.make","vectorProductLeft","vector4.make","vector4.dot","vectorProductRight","multiply","isInvertible","asInvertible","inverse","Solution.none","Solution.one","inverseUnsafe","solveSystem","rowVector","columnVector","transpose","reverseRows","reverseColumns","internal.isMatrix4x4","internal.identity","internal.equals","internal.make","internal.fromRows","internal.fromColumns","internal.setRow","internal.setColumn","internal.determinant","internal.minor","internal.vectorProductLeft","internal.vectorProductRight","internal.multiply","internal.inverse","internal.inverseUnsafe","internal.isInvertible","internal.asInvertible","internal.solveSystem","internal.toRows","internal.toColumns","internal.rowVector","internal.columnVector","internal.transpose","internal.reverseRows","internal.reverseColumns"],"sources":["../../src/matrix/matrix4x4.internal.ts","../../src/matrix/matrix4x4.ts"],"sourcesContent":["import { toFourDimensionalIndex } from '../dimensions.ts'\nimport { dual, Pipeable } from '../utils.ts'\nimport { invariant } from '../utils.ts'\nimport { coincident, RELATIVE_TOLERANCE } from '../number.ts'\nimport * as Solution from '../solution/solution.ts'\nimport type { Vector4 } from '../vector/vector4.ts'\nimport * as vector4 from '../vector/vector4.internal.ts'\nimport type { Matrix3x3 } from './matrix3x3.ts'\nimport * as matrix3x3 from './matrix3x3.internal.ts'\nimport type { Matrix4x4, Matrix4x4Coordinate } from './matrix4x4.ts'\nimport type { Invertible } from './traits.ts'\nimport { MatrixTraits } from './traits.ts'\n\nexport const Matrix4x4TypeId: unique symbol = Symbol.for('curvy/matrix4x4')\nexport type Matrix4x4TypeId = typeof Matrix4x4TypeId\n\nclass Matrix4x4Impl extends Pipeable implements Matrix4x4<unknown> {\n readonly [Matrix4x4TypeId]: Matrix4x4TypeId = Matrix4x4TypeId\n declare readonly [MatrixTraits]: unknown\n\n readonly m00: number\n readonly m01: number\n readonly m02: number\n readonly m03: number\n\n readonly m10: number\n readonly m11: number\n readonly m12: number\n readonly m13: number\n\n readonly m20: number\n readonly m21: number\n readonly m22: number\n readonly m23: number\n\n readonly m30: number\n readonly m31: number\n readonly m32: number\n readonly m33: number\n\n constructor(\n m00 = 0,\n m01 = m00,\n m02 = m01,\n m03 = m02,\n m10 = m00,\n m11 = m01,\n m12 = m02,\n m13 = m03,\n m20 = m00,\n m21 = m01,\n m22 = m02,\n m23 = m03,\n m30 = m00,\n m31 = m01,\n m32 = m02,\n m33 = m03,\n ) {\n super()\n\n this.m00 = m00\n this.m01 = m01\n this.m02 = m02\n this.m03 = m03\n this.m10 = m10\n this.m11 = m11\n this.m12 = m12\n this.m13 = m13\n this.m20 = m20\n this.m21 = m21\n this.m22 = m22\n this.m23 = m23\n this.m30 = m30\n this.m31 = m31\n this.m32 = m32\n this.m33 = m33\n }\n\n get [Symbol.toStringTag]() {\n return `Matrix4x4(${this.m00}, ${this.m01}, ${this.m02}, ${this.m03}, ${this.m10}, ${this.m11}, ${this.m12}, ${this.m13}, ${this.m20}, ${this.m21}, ${this.m22}, ${this.m23}, ${this.m30}, ${this.m31}, ${this.m32}, ${this.m33})`\n }\n\n get [Symbol.for('nodejs.util.inspect.custom')]() {\n return `Matrix4x4(${this.m00}, ${this.m01}, ${this.m02}, ${this.m03}, ${this.m10}, ${this.m11}, ${this.m12}, ${this.m13}, ${this.m20}, ${this.m21}, ${this.m22}, ${this.m23}, ${this.m30}, ${this.m31}, ${this.m32}, ${this.m33})`\n }\n\n [Symbol.hasInstance](m: unknown): m is Matrix4x4 {\n return isMatrix4x4(m)\n }\n}\n\n/** @internal */\nexport const isMatrix4x4 = (m: unknown): m is Matrix4x4 =>\n typeof m === 'object' && m !== null && Matrix4x4TypeId in m\n\n/** @internal */\nexport const equals = dual<\n (b: Matrix4x4) => (a: Matrix4x4) => boolean,\n (a: Matrix4x4, b: Matrix4x4) => boolean\n>(\n 2,\n (a: Matrix4x4, b: Matrix4x4) =>\n coincident(a.m00, b.m00) &&\n coincident(a.m01, b.m01) &&\n coincident(a.m02, b.m02) &&\n coincident(a.m03, b.m03) &&\n coincident(a.m10, b.m10) &&\n coincident(a.m11, b.m11) &&\n coincident(a.m12, b.m12) &&\n coincident(a.m13, b.m13) &&\n coincident(a.m20, b.m20) &&\n coincident(a.m21, b.m21) &&\n coincident(a.m22, b.m22) &&\n coincident(a.m23, b.m23) &&\n coincident(a.m30, b.m30) &&\n coincident(a.m31, b.m31) &&\n coincident(a.m32, b.m32) &&\n coincident(a.m33, b.m33),\n)\n\n/**\n * The 4x4 identity matrix.\n * @internal\n */\nexport const identity: Matrix4x4 = new Matrix4x4Impl(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)\n\n// first four arguments are the top row\n/** @internal */\nexport const make = (\n m00 = 0,\n m01 = m00,\n m02 = m01,\n m03 = m02,\n m10 = m00,\n m11 = m01,\n m12 = m02,\n m13 = m03,\n m20 = m00,\n m21 = m01,\n m22 = m02,\n m23 = m03,\n m30 = m00,\n m31 = m01,\n m32 = m02,\n m33 = m03,\n) =>\n new Matrix4x4Impl(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33)\n\n/** @internal */\nexport const fromRows = (v0: Vector4, v1: Vector4, v2: Vector4, v3: Vector4) =>\n new Matrix4x4Impl(\n v0.x,\n v0.y,\n v0.z,\n v0.w,\n v1.x,\n v1.y,\n v1.z,\n v1.w,\n v2.x,\n v2.y,\n v2.z,\n v2.w,\n v3.x,\n v3.y,\n v3.z,\n v3.w,\n )\n\n/** @internal */\nexport const fromColumns = (v0: Vector4, v1: Vector4, v2: Vector4, v3: Vector4) =>\n new Matrix4x4Impl(\n v0.x,\n v1.x,\n v2.x,\n v3.x,\n v0.y,\n v1.y,\n v2.y,\n v3.y,\n v0.z,\n v1.z,\n v2.z,\n v3.z,\n v0.w,\n v1.w,\n v2.w,\n v3.w,\n )\n\n/** @internal */\nexport const setRow = dual<\n (row: Matrix4x4Coordinate, v: Vector4) => (m: Matrix4x4) => Matrix4x4,\n (m: Matrix4x4, row: Matrix4x4Coordinate, v: Vector4) => Matrix4x4\n>(3, (m: Matrix4x4, row: Matrix4x4Coordinate, v: Vector4) =>\n fromRows(\n ...(toRows(m).with(toFourDimensionalIndex(row), v) as [Vector4, Vector4, Vector4, Vector4]),\n ),\n)\n\n/** @internal */\nexport const setColumn = dual<\n (column: Matrix4x4Coordinate, v: Vector4) => (m: Matrix4x4) => Matrix4x4,\n (m: Matrix4x4, column: Matrix4x4Coordinate, v: Vector4) => Matrix4x4\n>(3, (m: Matrix4x4, column: Matrix4x4Coordinate, v: Vector4) =>\n fromColumns(\n ...(toColumns(m).with(toFourDimensionalIndex(column), v) as [\n Vector4,\n Vector4,\n Vector4,\n Vector4,\n ]),\n ),\n)\n\n/** @internal */\nexport const determinant = (m: Matrix4x4) =>\n m.m00 * matrix3x3.determinant(minor(m, 0, 0)) -\n m.m01 * matrix3x3.determinant(minor(m, 0, 1)) +\n m.m02 * matrix3x3.determinant(minor(m, 0, 2)) -\n m.m03 * matrix3x3.determinant(minor(m, 0, 3))\n\n/** @internal */\nexport const minor = dual<\n (row: Matrix4x4Coordinate, column: Matrix4x4Coordinate) => (m: Matrix4x4) => Matrix3x3,\n (m: Matrix4x4, row: Matrix4x4Coordinate, column: Matrix4x4Coordinate) => Matrix3x3\n>(3, (m: Matrix4x4, row: Matrix4x4Coordinate, column: Matrix4x4Coordinate) => {\n const [v0, v1, v2] = toRows(m).toSpliced(toFourDimensionalIndex(row), 1) as [\n Vector4,\n Vector4,\n Vector4,\n ]\n const columnIndex = toFourDimensionalIndex(column)\n const [m00, m01, m02] = vector4.components(v0).toSpliced(columnIndex, 1) as [\n number,\n number,\n number,\n ]\n const [m10, m11, m12] = vector4.components(v1).toSpliced(columnIndex, 1) as [\n number,\n number,\n number,\n ]\n const [m20, m21, m22] = vector4.components(v2).toSpliced(columnIndex, 1) as [\n number,\n number,\n number,\n ]\n\n return matrix3x3.make(m00, m01, m02, m10, m11, m12, m20, m21, m22)\n})\n\n/** @internal */\nexport const vectorProductLeft = dual<\n (v: Vector4) => (m: Matrix4x4) => Vector4,\n (m: Matrix4x4, v: Vector4) => Vector4\n>(2, (m: Matrix4x4, v: Vector4) => {\n const [v0, v1, v2, v3] = toRows(m) as [Vector4, Vector4, Vector4, Vector4]\n return vector4.make(\n vector4.dot(v0, v),\n vector4.dot(v1, v),\n vector4.dot(v2, v),\n vector4.dot(v3, v),\n )\n})\n\n/** @internal */\nexport const vectorProductRight = dual<\n (v: Vector4) => (m: Matrix4x4) => Vector4,\n (m: Matrix4x4, v: Vector4) => Vector4\n>(2, (m: Matrix4x4, v: Vector4) => {\n const [v0, v1, v2, v3] = toColumns(m) as [Vector4, Vector4, Vector4, Vector4]\n\n return vector4.make(\n vector4.dot(v, v0),\n vector4.dot(v, v1),\n vector4.dot(v, v2),\n vector4.dot(v, v3),\n )\n})\n\n/** @internal */\nexport const multiply = dual<\n (b: Matrix4x4) => (a: Matrix4x4) => Matrix4x4,\n (a: Matrix4x4, b: Matrix4x4) => Matrix4x4\n>(\n 2,\n (a: Matrix4x4, b: Matrix4x4) =>\n new Matrix4x4Impl(\n a.m00 * b.m00 + a.m01 * b.m10 + a.m02 * b.m20 + a.m03 * b.m30,\n a.m00 * b.m01 + a.m01 * b.m11 + a.m02 * b.m21 + a.m03 * b.m31,\n a.m00 * b.m02 + a.m01 * b.m12 + a.m02 * b.m22 + a.m03 * b.m32,\n a.m00 * b.m03 + a.m01 * b.m13 + a.m02 * b.m23 + a.m03 * b.m33,\n a.m10 * b.m00 + a.m11 * b.m10 + a.m12 * b.m20 + a.m13 * b.m30,\n a.m10 * b.m01 + a.m11 * b.m11 + a.m12 * b.m21 + a.m13 * b.m31,\n a.m10 * b.m02 + a.m11 * b.m12 + a.m12 * b.m22 + a.m13 * b.m32,\n a.m10 * b.m03 + a.m11 * b.m13 + a.m12 * b.m23 + a.m13 * b.m33,\n a.m20 * b.m00 + a.m21 * b.m10 + a.m22 * b.m20 + a.m23 * b.m30,\n a.m20 * b.m01 + a.m21 * b.m11 + a.m22 * b.m21 + a.m23 * b.m31,\n a.m20 * b.m02 + a.m21 * b.m12 + a.m22 * b.m22 + a.m23 * b.m32,\n a.m20 * b.m03 + a.m21 * b.m13 + a.m22 * b.m23 + a.m23 * b.m33,\n a.m30 * b.m00 + a.m31 * b.m10 + a.m32 * b.m20 + a.m33 * b.m30,\n a.m30 * b.m01 + a.m31 * b.m11 + a.m32 * b.m21 + a.m33 * b.m31,\n a.m30 * b.m02 + a.m31 * b.m12 + a.m32 * b.m22 + a.m33 * b.m32,\n a.m30 * b.m03 + a.m31 * b.m13 + a.m32 * b.m23 + a.m33 * b.m33,\n ),\n)\n\n// Singularity threshold relative to the matrix's own scale, via Hadamard's\n// bound |det| ≤ Π row norms. See the Matrix3x3 counterpart for the rationale.\nconst singularityThreshold = (m: Matrix4x4): number =>\n RELATIVE_TOLERANCE *\n Math.hypot(m.m00, m.m01, m.m02, m.m03) *\n Math.hypot(m.m10, m.m11, m.m12, m.m13) *\n Math.hypot(m.m20, m.m21, m.m22, m.m23) *\n Math.hypot(m.m30, m.m31, m.m32, m.m33)\n\n/** @internal */\nexport const isInvertible = <T>(m: Matrix4x4<T>): m is Matrix4x4<T & Invertible> =>\n Math.abs(determinant(m)) > singularityThreshold(m)\n\n/** @internal */\nexport const asInvertible = <T>(m: Matrix4x4<T>): Matrix4x4<T & Invertible> => {\n invariant(isInvertible(m), 'matrix4x4 is not invertible')\n return m\n}\n\nconst buildInverse = (m: Matrix4x4, det: number): Matrix4x4 => {\n const inv = 1 / det\n // adjugate is the transpose of the cofactor matrix\n const cof = (row: Matrix4x4Coordinate, col: Matrix4x4Coordinate) => {\n const sign = ((row as number) + (col as number)) % 2 === 0 ? 1 : -1\n return sign * matrix3x3.determinant(minor(m, row, col)) * inv\n }\n\n return new Matrix4x4Impl(\n cof(0, 0),\n cof(1, 0),\n cof(2, 0),\n cof(3, 0),\n cof(0, 1),\n cof(1, 1),\n cof(2, 1),\n cof(3, 1),\n cof(0, 2),\n cof(1, 2),\n cof(2, 2),\n cof(3, 2),\n cof(0, 3),\n cof(1, 3),\n cof(2, 3),\n cof(3, 3),\n )\n}\n\n// On `Invertible`-branded matrices the empty branch is provably unreachable,\n// but TS can't see that — the cast at the public overload pairs the type-level\n// promise with the runtime brand check.\n/** @internal */\nexport const inverse = <T>(m: Matrix4x4<T>): Solution.AtMostOne<Matrix4x4<T>> => {\n const det = determinant(m)\n if (Math.abs(det) <= singularityThreshold(m)) {\n return Solution.none\n }\n return Solution.one(buildInverse(m, det) as Matrix4x4<T>)\n}\n\n/** @internal */\nexport const inverseUnsafe = (m: Matrix4x4): Matrix4x4 => {\n const det = determinant(m)\n invariant(Math.abs(det) > singularityThreshold(m), 'cannot invert singular matrix')\n return buildInverse(m, det)\n}\n\n/** @internal */\nexport const solveSystem = dual<\n (v: Vector4) => (m: Matrix4x4) => Vector4,\n (m: Matrix4x4, v: Vector4) => Vector4\n>(2, (m: Matrix4x4, v: Vector4) => {\n const inverseDeterminant = 1 / determinant(m)\n\n invariant(\n Number.isFinite(inverseDeterminant),\n 'cannot solve system when coefficient matrix determinant is zero',\n )\n\n return vector4.make(\n determinant(setColumn(m, 0, v)) * inverseDeterminant,\n determinant(setColumn(m, 1, v)) * inverseDeterminant,\n determinant(setColumn(m, 2, v)) * inverseDeterminant,\n determinant(setColumn(m, 3, v)) * inverseDeterminant,\n )\n})\n\n/** @internal */\nexport const toRows = (m: Matrix4x4) =>\n [\n vector4.make(m.m00, m.m01, m.m02, m.m03),\n vector4.make(m.m10, m.m11, m.m12, m.m13),\n vector4.make(m.m20, m.m21, m.m22, m.m23),\n vector4.make(m.m30, m.m31, m.m32, m.m33),\n ] as const\n\n/** @internal */\nexport const toColumns = (m: Matrix4x4) =>\n [\n vector4.make(m.m00, m.m10, m.m20, m.m30),\n vector4.make(m.m01, m.m11, m.m21, m.m31),\n vector4.make(m.m02, m.m12, m.m22, m.m32),\n vector4.make(m.m03, m.m13, m.m23, m.m33),\n ] as const\n\n/** @internal */\nexport const rowVector = dual<\n (row: Matrix4x4Coordinate) => (m: Matrix4x4) => Vector4,\n (m: Matrix4x4, row: Matrix4x4Coordinate) => Vector4\n>(2, (m: Matrix4x4, row: Matrix4x4Coordinate) => toRows(m)[toFourDimensionalIndex(row)])\n\n/** @internal */\nexport const columnVector = dual<\n (column: Matrix4x4Coordinate) => (m: Matrix4x4) => Vector4,\n (m: Matrix4x4, column: Matrix4x4Coordinate) => Vector4\n>(2, (m: Matrix4x4, column: Matrix4x4Coordinate) => toColumns(m)[toFourDimensionalIndex(column)])\n\n/** @internal */\nexport const transpose = (m: Matrix4x4) => fromColumns(...toRows(m)) as Matrix4x4\n\n/** @internal */\nexport const reverseRows = (m: Matrix4x4) => {\n const [v0, v1, v2, v3] = toRows(m) as [Vector4, Vector4, Vector4, Vector4]\n return fromRows(v3, v2, v1, v0)\n}\n\n/** @internal */\nexport const reverseColumns = (m: Matrix4x4) => {\n const [v0, v1, v2, v3] = toColumns(m) as [Vector4, Vector4, Vector4, Vector4]\n return fromColumns(v3, v2, v1, v0)\n}\n","import type { FourDimensionalComponent, FourDimensionalIndex } from '../dimensions.ts'\nimport type * as Solution from '../solution/solution.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector4 } from '../vector/vector4.ts'\nimport type { Matrix3x3 } from './matrix3x3.ts'\nimport type { Matrix4x4TypeId } from './matrix4x4.internal.ts'\nimport * as internal from './matrix4x4.internal.ts'\nimport type { Invertible, MatrixTraits } from './traits.ts'\n\nexport type { Invertible } from './traits.ts'\n\n/**\n * A coordinate in a 4x4 matrix.\n *\n * @since 1.0.0\n */\nexport type Matrix4x4Coordinate = FourDimensionalIndex | FourDimensionalComponent\n\n/**\n * A 4x4 matrix.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * The `Traits` type parameter is a phantom marker that accumulates trait\n * brands as the matrix is refined via `isInvertible` / `asInvertible`. The\n * runtime value carries no trait data — `Traits` only flows through the type\n * system to enable tighter return types on operations like {@link inverse}.\n *\n * @since 1.0.0\n */\nexport interface Matrix4x4<out Traits = unknown> extends Pipeable {\n readonly [Matrix4x4TypeId]: Matrix4x4TypeId\n readonly [MatrixTraits]: Traits\n\n /**\n * The value of the first row and first column.\n */\n readonly m00: number\n /**\n * The value of the first row and second column.\n */\n readonly m01: number\n /**\n * The value of the first row and third column.\n */\n readonly m02: number\n /**\n * The value of the first row and fourth column.\n */\n readonly m03: number\n /**\n * The value of the second row and first column.\n */\n readonly m10: number\n /**\n * The value of the second row and second column.\n */\n readonly m11: number\n /**\n * The value of the second row and third column.\n */\n readonly m12: number\n /**\n * The value of the second row and fourth column.\n */\n readonly m13: number\n /**\n * The value of the third row and first column.\n */\n readonly m20: number\n /**\n * The value of the third row and second column.\n */\n readonly m21: number\n /**\n * The value of the third row and third column.\n */\n readonly m22: number\n /**\n * The value of the third row and fourth column.\n */\n readonly m23: number\n /**\n * The value of the fourth row and first column.\n */\n readonly m30: number\n /**\n * The value of the fourth row and second column.\n */\n readonly m31: number\n /**\n * The value of the fourth row and third column.\n */\n readonly m32: number\n /**\n * The value of the fourth row and fourth column.\n */\n readonly m33: number\n}\n\n/**\n * Checks if a value is a `Matrix4x4`.\n *\n * @param m - The value to check.\n * @returns `true` if the value is a `Matrix4x4`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isMatrix4x4: (m: unknown) => m is Matrix4x4 = internal.isMatrix4x4\n\n/**\n * The 4x4 identity matrix.\n *\n * @since 1.1.0\n */\nexport const identity: Matrix4x4 = internal.identity\n\nexport const equals: {\n /**\n * Checks if two `Matrix4x4` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param a - The first matrix.\n * @param b - The second matrix.\n * @returns `true` when each pair of components is within tolerance.\n * @since 1.1.0\n */\n (a: Matrix4x4, b: Matrix4x4): boolean\n /**\n * Checks if two `Matrix4x4` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param b - The second matrix.\n * @returns A function that takes the first matrix and returns the comparison result.\n * @since 1.1.0\n */\n (b: Matrix4x4): (a: Matrix4x4) => boolean\n} = internal.equals\n\n/**\n * Creates a new `Matrix4x4` instance.\n *\n * @param m00 - The value of the first row and first column.\n * @param m01 - The value of the first row and second column.\n * @param m02 - The value of the first row and third column.\n * @param m03 - The value of the first row and fourth column.\n * @param m10 - The value of the second row and first column.\n * @param m11 - The value of the second row and second column.\n * @param m12 - The value of the second row and third column.\n * @param m13 - The value of the second row and fourth column.\n * @param m20 - The value of the third row and first column.\n * @param m21 - The value of the third row and second column.\n * @param m22 - The value of the third row and third column.\n * @param m23 - The value of the third row and fourth column.\n * @param m30 - The value of the fourth row and first column.\n * @param m31 - The value of the fourth row and second column.\n * @param m32 - The value of the fourth row and third column.\n * @param m33 - The value of the fourth row and fourth column.\n * @returns A new `Matrix4x4` instance.\n * @since 1.0.0\n */\nexport const make: (\n m00?: number,\n m01?: number,\n m02?: number,\n m03?: number,\n m10?: number,\n m11?: number,\n m12?: number,\n m13?: number,\n m20?: number,\n m21?: number,\n m22?: number,\n m23?: number,\n m30?: number,\n m31?: number,\n m32?: number,\n m33?: number,\n) => Matrix4x4 = internal.make\n\n/**\n * Creates a new `Matrix4x4` instance from four row vectors.\n *\n * @param v0 - The first row vector.\n * @param v1 - The second row vector.\n * @param v2 - The third row vector.\n * @param v3 - The fourth row vector.\n * @returns A new `Matrix4x4` instance.\n * @since 1.0.0\n */\nexport const fromRows: (v0: Vector4, v1: Vector4, v2: Vector4, v3: Vector4) => Matrix4x4 =\n internal.fromRows\n\n/**\n * Creates a new `Matrix4x4` instance from four column vectors.\n *\n * @param v0 - The first column vector.\n * @param v1 - The second column vector.\n * @param v2 - The third column vector.\n * @param v3 - The fourth column vector.\n */\nexport const fromColumns: (v0: Vector4, v1: Vector4, v2: Vector4, v3: Vector4) => Matrix4x4 =\n internal.fromColumns\n\nexport const setRow: {\n /**\n * Sets a row of a `Matrix4x4` to a new vector.\n *\n * @param m - The matrix to modify.\n * @param row - The row to set.\n * @param v - The new vector.\n * @returns A new `Matrix4x4` instance with the specified row set to the new vector.\n * @since 1.0.0\n */\n (m: Matrix4x4, row: Matrix4x4Coordinate, v: Vector4): Matrix4x4\n /**\n * Sets a row of a `Matrix4x4` to a new vector.\n *\n * @param row - The row to set.\n * @param v - The new vector.\n * @returns A function that takes a matrix and returns a new `Matrix4x4` instance with the specified row set to the new vector.\n * @since 1.0.0\n */\n (row: Matrix4x4Coordinate, v: Vector4): (m: Matrix4x4) => Matrix4x4\n} = internal.setRow\n\nexport const setColumn: {\n /**\n * Sets a column of a `Matrix4x4` to a new vector.\n *\n * @param m - The matrix to modify.\n * @param column - The column to set.\n * @param v - The new vector.\n * @returns A new `Matrix4x4` instance with the specified column set to the new vector.\n * @since 1.0.0\n */\n (m: Matrix4x4, column: Matrix4x4Coordinate, v: Vector4): Matrix4x4\n /**\n * Sets a column of a `Matrix4x4` to a new vector.\n *\n * @param column - The column to set.\n * @param v - The new vector.\n * @returns A function that takes a matrix and returns a new `Matrix4x4` instance with the specified column set to the new vector.\n * @since 1.0.0\n */\n (column: Matrix4x4Coordinate, v: Vector4): (m: Matrix4x4) => Matrix4x4\n} = internal.setColumn\n\n/**\n * Calculates the determinant of a `Matrix4x4`.\n *\n * @param m - The matrix to calculate the determinant of.\n * @returns The determinant of the matrix.\n * @since 1.0.0\n */\nexport const determinant: (m: Matrix4x4) => number = internal.determinant\n\n/**\n * Calculates the minor of a `Matrix4x4` at a given row and column.\n *\n * @param m - The matrix to calculate the minor of.\n * @param row - The row to exclude.\n * @param column - The column to exclude.\n * @returns The minor of the matrix at the given row and column.\n */\nexport const minor: (\n m: Matrix4x4,\n row: Matrix4x4Coordinate,\n column: Matrix4x4Coordinate,\n) => Matrix3x3 = internal.minor\n\nexport const vectorProductLeft: {\n /**\n * Calculates the left vector product of a `Matrix4x4` and a `Vector4`.\n *\n * @example\n * ```ts\n * import * as Matrix4x4 from 'curvy/matrix4x4'\n * import * as Vector4 from 'curvy/vector4'\n *\n * const m = Matrix4x4.make(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)\n * const v = Vector4.make(17, 18, 19, 20)\n *\n * // Result:\n * // x = 1 * 17 + 2 * 18 + 3 * 19 + 4 * 20\n * // y = 5 * 17 + 6 * 18 + 7 * 19 + 8 * 20\n * // z = 9 * 17 + 10 * 18 + 11 * 19 + 12 * 20\n * // w = 13 * 17 + 14 * 18 + 15 * 19 + 16 * 20\n * const result = Matrix4x4.vectorProductLeft(m, v)\n * ```\n * @param m - The matrix to multiply.\n * @param v - The vector to multiply.\n * @returns The resulting vector.\n * @since 1.0.0\n */\n (m: Matrix4x4, v: Vector4): Vector4\n /**\n * Calculates the left vector product of a `Matrix4x4` and a `Vector4`.\n *\n * @example\n * ```ts\n * import * as Matrix4x4 from 'curvy/matrix4x4'\n * import * as Vector4 from 'curvy/vector4'\n *\n * const m = Matrix4x4.make(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)\n * const v = Vector4.make(17, 18, 19, 20)\n *\n * // Result:\n * // x = 1 * 17 + 2 * 18 + 3 * 19 + 4 * 20\n * // y = 5 * 17 + 6 * 18 + 7 * 19 + 8 * 20\n * // z = 9 * 17 + 10 * 18 + 11 * 19 + 12 * 20\n * // w = 13 * 17 + 14 * 18 + 15 * 19 + 16 * 20\n * const result = Matrix4x4.vectorProductLeft(v)(m)\n * ```\n * @since 1.0.0\n */\n (v: Vector4): (m: Matrix4x4) => Vector4\n} = internal.vectorProductLeft\n\nexport const vectorProductRight: {\n /**\n * Calculates the right vector product of a `Matrix4x4` and a `Vector4`.\n *\n * @example\n * ```ts\n * import * as Matrix4x4 from 'curvy/matrix4x4'\n * import * as Vector4 from 'curvy/vector4'\n *\n * const m = Matrix4x4.make(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)\n * const v = Vector4.make(17, 18, 19, 20)\n *\n * // Result:\n * // x = 1 * 17 + 5 * 18 + 9 * 19 + 13 * 20\n * // y = 2 * 17 + 6 * 18 + 10 * 19 + 14 * 20\n * // z = 3 * 17 + 7 * 18 + 11 * 19 + 15 * 20\n * // w = 4 * 17 + 8 * 18 + 12 * 19 + 16 * 20\n * const result = Matrix4x4.vectorProductRight(m, v)\n * ```\n * @since 1.0.0\n */\n (m: Matrix4x4, v: Vector4): Vector4\n /**\n * Calculates the right vector product of a `Matrix4x4` and a `Vector4`.\n *\n * @example\n * ```ts\n * import * as Matrix4x4 from 'curvy/matrix4x4'\n * import * as Vector4 from 'curvy/vector4'\n *\n * const m = Matrix4x4.make(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)\n * const v = Vector4.make(17, 18, 19, 20)\n *\n * // Result:\n * // x = 1 * 17 + 5 * 18 + 9 * 19 + 13 * 20\n * // y = 2 * 17 + 6 * 18 + 10 * 19 + 14 * 20\n * // z = 3 * 17 + 7 * 18 + 11 * 19 + 15 * 20\n * // w = 4 * 17 + 8 * 18 + 12 * 19 + 16 * 20\n * const result = Matrix4x4.vectorProductRight(v)(m)\n * ```\n * @since 1.0.0\n */\n (v: Vector4): (m: Matrix4x4) => Vector4\n} = internal.vectorProductRight\n\nexport const multiply: {\n /**\n * Multiplies two `Matrix4x4` instances. Result is `a · b`.\n *\n * @param a - The left-hand matrix.\n * @param b - The right-hand matrix.\n * @returns The product matrix.\n * @since 1.1.0\n */\n (a: Matrix4x4, b: Matrix4x4): Matrix4x4\n /**\n * Multiplies two `Matrix4x4` instances. Result is `a · b`.\n *\n * @param b - The right-hand matrix.\n * @returns A function that takes the left-hand matrix and returns the product.\n * @since 1.1.0\n */\n (b: Matrix4x4): (a: Matrix4x4) => Matrix4x4\n} = internal.multiply\n\n// The implementation always runs the same det/threshold branch. For\n// `Invertible`-branded matrices the empty branch is provably unreachable,\n// but TS can't see that — the cast pairs the type-level promise with the\n// runtime brand check.\nexport const inverse: {\n /**\n * Returns the inverse of an `Invertible`-branded `Matrix4x4`. Because the\n * brand guarantees non-singularity, the result is always a single matrix —\n * wrapped in `Solution.One`.\n *\n * @param m - The matrix to invert.\n * @since 2.0.0\n */\n <T extends Invertible>(m: Matrix4x4<T>): Solution.One<Matrix4x4<T>>\n /**\n * Returns the inverse of a `Matrix4x4`. Returns `Solution.none` if the\n * matrix is singular (determinant approximately zero). Use {@link asInvertible}\n * or {@link isInvertible} to refine the type and tighten the return to\n * `Solution.One`, or use {@link inverseUnsafe} if you want the throwing form.\n *\n * @param m - The matrix to invert.\n * @since 2.0.0\n */\n <T>(m: Matrix4x4<T>): Solution.AtMostOne<Matrix4x4<T>>\n} = internal.inverse as never\n\n/**\n * Returns the inverse of a `Matrix4x4`. Throws when the matrix is singular\n * (determinant approximately zero). Useful when you've already validated\n * invertibility out-of-band and want the unwrapped matrix directly; otherwise\n * prefer {@link inverse}.\n *\n * @param m - The matrix to invert.\n * @returns The inverse matrix.\n * @throws If `m` is singular.\n * @since 2.0.0\n */\nexport const inverseUnsafe: (m: Matrix4x4) => Matrix4x4 = internal.inverseUnsafe\n\n/**\n * Type-narrowing predicate: refines a `Matrix4x4<T>` to\n * `Matrix4x4<T & Invertible>` when the matrix's determinant is non-zero\n * (within the default absolute tolerance).\n *\n * @param m - The matrix to check.\n * @returns `true` when `m` is invertible.\n * @since 2.0.0\n */\nexport const isInvertible: <T>(m: Matrix4x4<T>) => m is Matrix4x4<T & Invertible> =\n internal.isInvertible\n\n/**\n * Asserts that the matrix is invertible, throwing on a singular matrix.\n *\n * @param m - The matrix to assert against.\n * @returns The same matrix, typed with the `Invertible` brand.\n * @throws When `m` is singular.\n * @since 2.0.0\n */\nexport const asInvertible: <T>(m: Matrix4x4<T>) => Matrix4x4<T & Invertible> = internal.asInvertible\n\nexport const solveSystem: {\n /**\n * Solves a system of linear equations represented by a `Matrix4x4` and a `Vector4`.\n *\n * @param m - The matrix representing the coefficients of the equations.\n * @param v - The vector representing the constants of the equations.\n * @returns The solution vector.\n * @since 1.0.0\n */\n (m: Matrix4x4, v: Vector4): Vector4\n /**\n * Solves a system of linear equations represented by a `Matrix4x4` and a `Vector4`.\n *\n * @param v - The vector representing the constants of the equations.\n * @returns A function that takes a matrix and returns the solution vector.\n * @since 1.0.0\n */\n (v: Vector4): (m: Matrix4x4) => Vector4\n} = internal.solveSystem\n\n/**\n * Returns the rows of a `Matrix4x4` as an array of vectors.\n *\n * @param m - The matrix to convert.\n * @returns An array of vectors representing the rows of the matrix.\n * @since 1.0.0\n */\nexport const toRows: (m: Matrix4x4) => [Vector4, Vector4, Vector4, Vector4] = internal.toRows as (\n m: Matrix4x4,\n) => [Vector4, Vector4, Vector4, Vector4]\n\n/**\n * Returns the columns of a `Matrix4x4` as an array of vectors.\n *\n * @param m - The matrix to convert.\n * @returns An array of vectors representing the columns of the matrix.\n * @since 1.0.0\n */\nexport const toColumns: (m: Matrix4x4) => [Vector4, Vector4, Vector4, Vector4] =\n internal.toColumns as (m: Matrix4x4) => [Vector4, Vector4, Vector4, Vector4]\n\nexport const rowVector: {\n /**\n * Returns a row vector from a `Matrix4x4`.\n *\n * @param m - The matrix to get the row vector from.\n * @param row - The row index.\n * @returns The row vector.\n * @since 1.0.0\n */\n (m: Matrix4x4, row: Matrix4x4Coordinate): Vector4\n /**\n * Returns a row vector from a `Matrix4x4`.\n *\n * @param row - The row index.\n * @returns A function that takes a matrix and returns the row vector.\n * @since 1.0.0\n */\n (row: Matrix4x4Coordinate): (m: Matrix4x4) => Vector4\n} = internal.rowVector\n\nexport const columnVector: {\n /**\n * Returns a column vector from a `Matrix4x4`.\n *\n * @param m - The matrix to get the column vector from.\n * @param column - The column index.\n * @returns The column vector.\n * @since 1.0.0\n */\n (m: Matrix4x4, column: Matrix4x4Coordinate): Vector4\n /**\n * Returns a column vector from a `Matrix4x4`.\n *\n * @param column - The column index.\n * @returns A function that takes a matrix and returns the column vector.\n * @since 1.0.0\n */\n (column: Matrix4x4Coordinate): (m: Matrix4x4) => Vector4\n} = internal.columnVector\n\n/**\n * Transposes a `Matrix4x4`.\n *\n * @param m - The matrix to transpose.\n * @returns The transposed matrix.\n * @since 1.0.0\n */\nexport const transpose: (m: Matrix4x4) => Matrix4x4 = internal.transpose\n\n/**\n * Reverses the rows of a `Matrix4x4`.\n *\n * @param m - The matrix to reverse the rows of.\n * @returns The matrix with the rows reversed.\n * @since 1.0.0\n */\nexport const reverseRows: (m: Matrix4x4) => Matrix4x4 = internal.reverseRows\n\n/**\n * Reverses the columns of a `Matrix4x4`.\n *\n * @param m - The matrix to reverse the columns of.\n * @returns The matrix with the columns reversed.\n * @since 1.0.0\n */\nexport const reverseColumns: (m: Matrix4x4) => Matrix4x4 = internal.reverseColumns\n"],"mappings":";;;;;;;AAaA,MAAa,kBAAiC,OAAO,IAAI,kBAAkB;AAG3E,IAAM,gBAAN,cAA4B,SAAuC;CACjE,CAAU,mBAAoC;CAG9C;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CAEA,YACE,MAAM,GACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN;EACA,OAAO;EAEP,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,MAAM;;CAGb,KAAK,OAAO,eAAe;EACzB,OAAO,aAAa,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI;;CAGlO,KAAK,OAA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"./chunk-25Hzd3z8.mjs";
|
|
2
|
+
import "../number.mjs";
|
|
3
|
+
//#region src/monotonicity/monotonicity.ts
|
|
4
|
+
var monotonicity_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
Constant: () => 0,
|
|
6
|
+
Decreasing: () => 2,
|
|
7
|
+
Increasing: () => 1,
|
|
8
|
+
None: () => 3,
|
|
9
|
+
fromComparison: () => fromComparison,
|
|
10
|
+
fromDerivativeRange: () => fromDerivativeRange,
|
|
11
|
+
isStrict: () => isStrict
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* Type-narrowing predicate: refines a `Monotonicity` to `Increasing |
|
|
15
|
+
* Decreasing` — the strict cases that admit a unique inverse.
|
|
16
|
+
*
|
|
17
|
+
* @param m - The monotonicity classification.
|
|
18
|
+
* @returns `true` when `m` is `Increasing` or `Decreasing`.
|
|
19
|
+
* @since 2.0.0
|
|
20
|
+
*/
|
|
21
|
+
const isStrict = (m) => m === 1 || m === 2;
|
|
22
|
+
/**
|
|
23
|
+
* Classifies the monotonicity of a function given its values at two interval
|
|
24
|
+
* endpoints, when the function is known a priori to be monotonic on the
|
|
25
|
+
* spanning interval (e.g. a linear polynomial).
|
|
26
|
+
*
|
|
27
|
+
* @param s0 - The function value at the start of the interval.
|
|
28
|
+
* @param s1 - The function value at the end of the interval.
|
|
29
|
+
* @returns The classification — `Increasing`, `Decreasing`, or `Constant`.
|
|
30
|
+
* @since 2.0.0
|
|
31
|
+
*/
|
|
32
|
+
const fromComparison = (s0, s1) => s0 < s1 ? 1 : s0 > s1 ? 2 : 0;
|
|
33
|
+
/**
|
|
34
|
+
* Classifies monotonicity from the extreme values of a function's derivative
|
|
35
|
+
* over an interval, tolerating rounding noise in the derivative.
|
|
36
|
+
*
|
|
37
|
+
* `min` and `max` must be the true range extremes of the derivative on the
|
|
38
|
+
* interval (for a polynomial derivative: its values at the interval endpoints
|
|
39
|
+
* and at any interior stationary point). Each bound sets its sign-coverage
|
|
40
|
+
* bit only when it exceeds the tolerance, so a derivative that merely grazes
|
|
41
|
+
* zero — or dips past it by an ulp-scale amount that construction arithmetic
|
|
42
|
+
* cannot distinguish from zero — does not register as a crossing.
|
|
43
|
+
*
|
|
44
|
+
* The default tolerance is {@link RELATIVE_TOLERANCE} scaled by the larger
|
|
45
|
+
* bound magnitude, making the classification invariant under scaling of the
|
|
46
|
+
* input data. Derivative values are used rather than derivative *root
|
|
47
|
+
* locations* because values are well-conditioned where roots are not: a root
|
|
48
|
+
* computed from rounded coefficients can land on either side of an interval
|
|
49
|
+
* boundary, while the value it corresponds to stays pinned near zero.
|
|
50
|
+
*
|
|
51
|
+
* @param min - The smallest derivative value attained on the interval.
|
|
52
|
+
* @param max - The largest derivative value attained on the interval.
|
|
53
|
+
* @param tolerance - Absolute threshold below which a derivative value is treated as zero. Defaults to `RELATIVE_TOLERANCE * max(|min|, |max|)`.
|
|
54
|
+
* @returns The sign-coverage classification.
|
|
55
|
+
* @since 2.0.0
|
|
56
|
+
*/
|
|
57
|
+
const fromDerivativeRange = (min, max, tolerance) => {
|
|
58
|
+
const t = tolerance ?? 1e-12 * Math.max(Math.abs(min), Math.abs(max));
|
|
59
|
+
return (max > t ? 1 : 0) | (min < -t ? 2 : 0);
|
|
60
|
+
};
|
|
61
|
+
//#endregion
|
|
62
|
+
export { isStrict as n, monotonicity_exports as r, fromDerivativeRange as t };
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=monotonicity-DNxBoC7F.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monotonicity-DNxBoC7F.mjs","names":[],"sources":["../../src/monotonicity/monotonicity.ts"],"sourcesContent":["import { RELATIVE_TOLERANCE } from '../number.ts'\n\n/**\n * Classification of a function's monotonicity on an interval.\n *\n * Encoded as a 2-bit sign-coverage bitmask of the function's derivative:\n * - bit 0 (`Increasing`) — derivative takes positive values\n * - bit 1 (`Decreasing`) — derivative takes negative values\n *\n * The four states fall out of the encoding:\n *\n * | value | name | derivative on the interval |\n * |-------|--------------|-----------------------------------|\n * | `0` | `Constant` | ≡ 0 |\n * | `1` | `Increasing` | ≥ 0, with at least one `> 0` |\n * | `2` | `Decreasing` | ≤ 0, with at least one `< 0` |\n * | `3` | `None` | crosses zero |\n *\n * The numeric encoding is principled, not arbitrary: the bitwise OR of two\n * adjacent subintervals' classifications gives the classification of their\n * union, which lets monotonicity be computed by recursive subdivision\n * without any custom combine logic.\n *\n * @since 2.0.0\n */\nexport type Monotonicity = 0 | 1 | 2 | 3\n\n/**\n * Subset of {@link Monotonicity} excluding the indeterminate `None` state.\n * Returned by classifiers operating on functions whose derivative cannot\n * change sign on the interval (e.g. linear polynomials, whose derivative is\n * constant).\n *\n * @since 2.0.0\n */\nexport type GuaranteedMonotonicity = 0 | 1 | 2\n\n/**\n * Derivative is identically zero on the interval. The function is constant.\n *\n * @since 2.0.0\n */\nexport const Constant = 0 as const\n\n/**\n * Derivative is non-negative on the interval with at least one strictly\n * positive sample. The function is strictly increasing.\n *\n * @since 2.0.0\n */\nexport const Increasing = 1 as const\n\n/**\n * Derivative is non-positive on the interval with at least one strictly\n * negative sample. The function is strictly decreasing.\n *\n * @since 2.0.0\n */\nexport const Decreasing = 2 as const\n\n/**\n * Derivative crosses zero on the interval. The function has at least one\n * interior extremum and is not monotonic in either direction.\n *\n * @since 2.0.0\n */\nexport const None = 3 as const\n\n/**\n * Type-narrowing predicate: refines a `Monotonicity` to `Increasing |\n * Decreasing` — the strict cases that admit a unique inverse.\n *\n * @param m - The monotonicity classification.\n * @returns `true` when `m` is `Increasing` or `Decreasing`.\n * @since 2.0.0\n */\nexport const isStrict = (m: Monotonicity): m is 1 | 2 => m === Increasing || m === Decreasing\n\n/**\n * Classifies the monotonicity of a function given its values at two interval\n * endpoints, when the function is known a priori to be monotonic on the\n * spanning interval (e.g. a linear polynomial).\n *\n * @param s0 - The function value at the start of the interval.\n * @param s1 - The function value at the end of the interval.\n * @returns The classification — `Increasing`, `Decreasing`, or `Constant`.\n * @since 2.0.0\n */\nexport const fromComparison = (s0: number, s1: number): GuaranteedMonotonicity =>\n s0 < s1 ? Increasing : s0 > s1 ? Decreasing : Constant\n\n/**\n * Classifies monotonicity from the extreme values of a function's derivative\n * over an interval, tolerating rounding noise in the derivative.\n *\n * `min` and `max` must be the true range extremes of the derivative on the\n * interval (for a polynomial derivative: its values at the interval endpoints\n * and at any interior stationary point). Each bound sets its sign-coverage\n * bit only when it exceeds the tolerance, so a derivative that merely grazes\n * zero — or dips past it by an ulp-scale amount that construction arithmetic\n * cannot distinguish from zero — does not register as a crossing.\n *\n * The default tolerance is {@link RELATIVE_TOLERANCE} scaled by the larger\n * bound magnitude, making the classification invariant under scaling of the\n * input data. Derivative values are used rather than derivative *root\n * locations* because values are well-conditioned where roots are not: a root\n * computed from rounded coefficients can land on either side of an interval\n * boundary, while the value it corresponds to stays pinned near zero.\n *\n * @param min - The smallest derivative value attained on the interval.\n * @param max - The largest derivative value attained on the interval.\n * @param tolerance - Absolute threshold below which a derivative value is treated as zero. Defaults to `RELATIVE_TOLERANCE * max(|min|, |max|)`.\n * @returns The sign-coverage classification.\n * @since 2.0.0\n */\nexport const fromDerivativeRange = (min: number, max: number, tolerance?: number): Monotonicity => {\n const t = tolerance ?? RELATIVE_TOLERANCE * Math.max(Math.abs(min), Math.abs(max))\n return ((max > t ? Increasing : Constant) | (min < -t ? Decreasing : Constant)) as Monotonicity\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4EA,MAAa,YAAY,MAAgC,MAAA,KAAoB,MAAA;;;;;;;;;;;AAY7E,MAAa,kBAAkB,IAAY,OACzC,KAAK,KAAA,IAAkB,KAAK,KAAA,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;AA0B9B,MAAa,uBAAuB,KAAa,KAAa,cAAqC;CACjG,MAAM,IAAI,aAAA,QAAkC,KAAK,IAAI,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI,IAAI,CAAC;CAClF,QAAS,MAAM,IAAA,IAAA,MAA8B,MAAM,CAAC,IAAA,IAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-25Hzd3z8.mjs";
|
|
2
|
-
import { $ as
|
|
2
|
+
import { $ as domain$3, At as isIncreasing$2, Bt as toSolver$2, Ct as derivative$2, Dt as fromPoints$2, Et as fromPointSlope$1, Ft as monotonicity$2, It as range$2, J as asIncreasing$3, K as antiderivative$3, Lt as solve$2, Mt as isMonotonic$2, Nt as length$2, Ot as fromVector$2, Pt as make$2, Q as derivative$3, Rt as solveInverse$2, St as coefficients$2, Tt as equals$2, Vt as unitRange$2, X as coefficients$3, Y as asMonotonic$3, Z as curvature$1, _t as unitRange$3, at as isIncreasing$3, bt as asIncreasing$2, ct as length$3, dt as range$3, et as equals$3, ft as roots$1, gt as toSolver$3, ht as toInverseSolver$3, it as isDecreasing$3, jt as isLinearPolynomial$1, kt as isDecreasing$2, lt as make$3, mt as solveInverse$3, nt as fromPoints$3, ot as isMonotonic$3, pt as solve$3, q as asDecreasing$3, rt as fromVector$3, st as isQuadraticPolynomial$1, tt as extreme$1, ut as monotonicity$3, vt as antiderivative$2, wt as domain$2, xt as asMonotonic$2, yt as asDecreasing$2, zt as toInverseSolver$2 } from "./cubic-BiGuAnZ0.mjs";
|
|
3
3
|
//#region src/polynomial/linear.ts
|
|
4
4
|
var linear_exports = /* @__PURE__ */ __exportAll({
|
|
5
5
|
antiderivative: () => antiderivative$1,
|
|
@@ -367,4 +367,4 @@ const curvature = curvature$1;
|
|
|
367
367
|
//#endregion
|
|
368
368
|
export { unitRange$1 as _, make as a, solveInverse as c, isIncreasing$1 as d, isMonotonic$1 as f, solveInverse$1 as g, solve$1 as h, isMonotonic as i, unitRange as l, make$1 as m, isDecreasing as n, quadratic_exports as o, linear_exports as p, isIncreasing as r, solve as s, derivative as t, isDecreasing$1 as u };
|
|
369
369
|
|
|
370
|
-
//# sourceMappingURL=quadratic-
|
|
370
|
+
//# sourceMappingURL=quadratic-BmMqkvxx.mjs.map
|