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
|
@@ -5,6 +5,7 @@ import type { Pipeable } from '../utils.ts';
|
|
|
5
5
|
import type { CubicPolynomial } from '../polynomial/cubic.ts';
|
|
6
6
|
import type { Decreasing, Increasing, Monotonic } from '../polynomial/traits.ts';
|
|
7
7
|
import type * as Solution from '../solution/solution.ts';
|
|
8
|
+
import type { Affine2d } from '../transform/affine2d.ts';
|
|
8
9
|
import type { Vector2, Weighted } from '../vector/vector2.ts';
|
|
9
10
|
import type { CubicCurve2d } from './cubic2d.ts';
|
|
10
11
|
import type { RationalCubicCurve2dTypeId, RationalCurveTraits } from './rationalCubic2d.internal.ts';
|
|
@@ -24,10 +25,10 @@ export { RationalCurveTraits } from './rationalCubic2d.internal.ts';
|
|
|
24
25
|
* to the rational functions `x(t)/w(t)` and `y(t)/w(t)`. Unlike
|
|
25
26
|
* `CubicCurve2d`, traits do not flow through to the underlying polynomials —
|
|
26
27
|
* monotonicity of a ratio of cubics is not the same property as monotonicity
|
|
27
|
-
* of either cubic alone, so the brand lives on the curve itself.
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
28
|
+
* of either cubic alone, so the brand lives on the curve itself. Brands are
|
|
29
|
+
* attached after construction via the {@link asMonotonic}, {@link asIncreasing},
|
|
30
|
+
* and {@link asDecreasing} families, which verify the property rigorously
|
|
31
|
+
* (Bernstein sign convexity on the derivative-numerator quartic).
|
|
31
32
|
*
|
|
32
33
|
* All fields are readonly and immutable, and all operations create new instances.
|
|
33
34
|
*
|
|
@@ -59,43 +60,63 @@ export declare const isRationalCubicCurve2d: (c: unknown) => c is RationalCubicC
|
|
|
59
60
|
* @since 2.0.0
|
|
60
61
|
*/
|
|
61
62
|
export declare const fromPolynomials: (x: CubicPolynomial, y: CubicPolynomial, w: CubicPolynomial) => RationalCubicCurve2d;
|
|
63
|
+
export declare const fromBezierPoints: {
|
|
64
|
+
/**
|
|
65
|
+
* Creates a new `RationalCubicCurve2d` from four weighted cubic Bézier
|
|
66
|
+
* control points. The four control points are lifted to homogeneous form
|
|
67
|
+
* `(w·x, w·y, w)` and the cubic Bernstein basis is expanded into per-channel
|
|
68
|
+
* monomial coefficients, yielding the curve's `x`, `y`, and `w` polynomials.
|
|
69
|
+
*
|
|
70
|
+
* @param p0 - The first weighted control point (curve start).
|
|
71
|
+
* @param p1 - The second weighted control point (start handle).
|
|
72
|
+
* @param p2 - The third weighted control point (end handle).
|
|
73
|
+
* @param p3 - The fourth weighted control point (curve end).
|
|
74
|
+
* @returns A new `RationalCubicCurve2d` instance.
|
|
75
|
+
* @since 2.0.0
|
|
76
|
+
*/
|
|
77
|
+
(p0: Weighted, p1: Weighted, p2: Weighted, p3: Weighted): RationalCubicCurve2d;
|
|
78
|
+
/**
|
|
79
|
+
* Creates a new `RationalCubicCurve2d` from two interior weighted Bézier
|
|
80
|
+
* handles, with endpoints pinned at `(0, 0, w=1)` and `(1, 1, w=1)`.
|
|
81
|
+
*
|
|
82
|
+
* Rational analog of CSS's `cubic-bezier(x1, y1, x2, y2)`: same fixed
|
|
83
|
+
* endpoints, same two interior handles, plus per-handle weights for true
|
|
84
|
+
* rational shapes (the polynomial case is recovered with unit weights).
|
|
85
|
+
* The curve interpolates `(0, 0)` at `t = 0` and `(1, 1)` at `t = 1`.
|
|
86
|
+
*
|
|
87
|
+
* @param p1 - The second weighted control point (start handle).
|
|
88
|
+
* @param p2 - The third weighted control point (end handle).
|
|
89
|
+
* @returns A new `RationalCubicCurve2d` instance with pinned endpoints.
|
|
90
|
+
* @since 2.0.0
|
|
91
|
+
*/
|
|
92
|
+
(p1: Weighted, p2: Weighted): RationalCubicCurve2d;
|
|
93
|
+
};
|
|
62
94
|
/**
|
|
63
|
-
* Creates a
|
|
64
|
-
*
|
|
65
|
-
* `(
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* For input slope combinations that the default Gregory-Delbourgo
|
|
87
|
-
* construction cannot accommodate (typically when one slope is large while
|
|
88
|
-
* the other is small), construction throws. Useful operating range is
|
|
89
|
-
* roughly `m₀, m₁ ∈ [0, 2]` with `m₀ + m₁ ≲ 3`; smoothstep (`0, 0`) and
|
|
90
|
-
* linear (`1, 1`) fall out as special cases.
|
|
91
|
-
*
|
|
92
|
-
* @param startSlope - The easing function's slope at the start (`dy/dx` at `x = 0`); must be finite and non-negative.
|
|
93
|
-
* @param endSlope - The easing function's slope at the end (`dy/dx` at `x = 1`); must be finite and non-negative.
|
|
94
|
-
* @returns A monotone-by-construction rational cubic easing curve.
|
|
95
|
-
* @throws When slopes are negative, non-finite, or produce a non-monotonic curve under the default construction.
|
|
95
|
+
* Creates a rational cubic easing curve from endpoint slopes and signed
|
|
96
|
+
* curvatures. The result interpolates `(0, 0)` and `(1, 1)` with `x(t) = t`
|
|
97
|
+
* pinned linearly; the y-axis projection `y(t) = Y(t)/W(t)` uses a cubic
|
|
98
|
+
* numerator over a quadratic denominator, giving six free parameters that
|
|
99
|
+
* exactly match the six endpoint constraints (two values, two slopes, two
|
|
100
|
+
* curvatures).
|
|
101
|
+
*
|
|
102
|
+
* Curvatures are the signed differential-geometric curvatures `κ = y''(x) /
|
|
103
|
+
* (1 + y'(x)²)^(3/2)` — the parameterization-invariant "bend" of the easing
|
|
104
|
+
* graph. Positive κ is concave-up. Smoothstep is `(0, 0, 6, -6)`; linear is
|
|
105
|
+
* `(1, 1, 0, 0)` (taken as a redundant-system special case).
|
|
106
|
+
*
|
|
107
|
+
* Monotonicity is not enforced. Callers needing the `Increasing` brand for
|
|
108
|
+
* narrowed inverse-solve returns should follow construction with
|
|
109
|
+
* {@link asIncreasing}, which verifies monotonicity rigorously.
|
|
110
|
+
*
|
|
111
|
+
* @param startSlope - The easing function's slope at the start (`dy/dx` at `x = 0`).
|
|
112
|
+
* @param endSlope - The easing function's slope at the end (`dy/dx` at `x = 1`).
|
|
113
|
+
* @param startCurvature - The signed differential curvature at the start.
|
|
114
|
+
* @param endCurvature - The signed differential curvature at the end.
|
|
115
|
+
* @returns A rational cubic easing curve.
|
|
116
|
+
* @throws When inputs are non-finite, the constraint system is singular, or the resulting denominator vanishes on `[0, 1]`.
|
|
96
117
|
* @since 2.0.0
|
|
97
118
|
*/
|
|
98
|
-
export declare const
|
|
119
|
+
export declare const fromSlopesAndCurvatures: (startSlope: number, endSlope: number, startCurvature: number, endCurvature: number) => RationalCubicCurve2d;
|
|
99
120
|
export declare const solve: {
|
|
100
121
|
/**
|
|
101
122
|
* Evaluates the rational cubic curve at parameter `t`. Returns
|
|
@@ -116,6 +137,24 @@ export declare const solve: {
|
|
|
116
137
|
*/
|
|
117
138
|
(t: number): (c: RationalCubicCurve2d) => Vector2;
|
|
118
139
|
};
|
|
140
|
+
/**
|
|
141
|
+
* Evaluates the curve at `t = 0` in closed form — `(c.x.c0 / c.w.c0, c.y.c0 / c.w.c0)`.
|
|
142
|
+
*
|
|
143
|
+
* @param c - The rational cubic curve.
|
|
144
|
+
* @returns The point at the start of the curve's parameter domain.
|
|
145
|
+
* @since 2.0.0
|
|
146
|
+
*/
|
|
147
|
+
export declare const startPoint: (c: RationalCubicCurve2d) => Vector2;
|
|
148
|
+
/**
|
|
149
|
+
* Evaluates the curve at `t = 1` in closed form. Both numerator and denominator
|
|
150
|
+
* Horner evaluations at `t = 1` collapse to the sum of their monomial
|
|
151
|
+
* coefficients, so the projection is `(Σxᵢ / Σwᵢ, Σyᵢ / Σwᵢ)`.
|
|
152
|
+
*
|
|
153
|
+
* @param c - The rational cubic curve.
|
|
154
|
+
* @returns The point at the end of the curve's parameter domain.
|
|
155
|
+
* @since 2.0.0
|
|
156
|
+
*/
|
|
157
|
+
export declare const endPoint: (c: RationalCubicCurve2d) => Vector2;
|
|
119
158
|
export declare const solveAtX: {
|
|
120
159
|
/**
|
|
121
160
|
* Evaluates the curve's y values at a given x. Because the curve's x axis
|
|
@@ -391,6 +430,29 @@ export declare const asIncreasing: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) =>
|
|
|
391
430
|
* @since 2.0.0
|
|
392
431
|
*/
|
|
393
432
|
export declare const asDecreasing: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => RationalCubicCurve2d<XT & Decreasing, YT & Decreasing>;
|
|
433
|
+
export declare const transform: {
|
|
434
|
+
/**
|
|
435
|
+
* Applies an `Affine2d` transform to a `RationalCubicCurve2d`, returning a
|
|
436
|
+
* new curve whose image is the affine image of the original. The denominator
|
|
437
|
+
* polynomial is preserved; each numerator pulls in a translation term
|
|
438
|
+
* weighted by the denominator so the projected curve matches `A · R(s) + t`
|
|
439
|
+
* pointwise.
|
|
440
|
+
*
|
|
441
|
+
* @param c - The rational cubic curve.
|
|
442
|
+
* @param a - The affine transform.
|
|
443
|
+
* @returns The transformed rational cubic curve.
|
|
444
|
+
* @since 2.0.0
|
|
445
|
+
*/
|
|
446
|
+
(c: RationalCubicCurve2d, a: Affine2d): RationalCubicCurve2d;
|
|
447
|
+
/**
|
|
448
|
+
* Applies an `Affine2d` transform to a `RationalCubicCurve2d`.
|
|
449
|
+
*
|
|
450
|
+
* @param a - The affine transform.
|
|
451
|
+
* @returns A function that takes a `RationalCubicCurve2d` and returns the transformed curve.
|
|
452
|
+
* @since 2.0.0
|
|
453
|
+
*/
|
|
454
|
+
(a: Affine2d): (c: RationalCubicCurve2d) => RationalCubicCurve2d;
|
|
455
|
+
};
|
|
394
456
|
export declare const approximateAsCubicCurves: {
|
|
395
457
|
/**
|
|
396
458
|
* Approximates the rational cubic as a sequence of polynomial cubic curves
|
package/dist/interval/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as interval2d_exports } from "../shared/interval2d-
|
|
1
|
+
import { c as interval_exports } from "../shared/interval-Dcqpo73t.mjs";
|
|
2
|
+
import { n as interval2d_exports } from "../shared/interval2d-C2Pk66-2.mjs";
|
|
3
3
|
export { interval_exports as Interval, interval2d_exports as Interval2d };
|
package/dist/matrix/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "../shared/chunk-25Hzd3z8.mjs";
|
|
2
|
-
import { A as
|
|
2
|
+
import { A as fromRows$2, B as toRows$2, C as transpose$3, D as determinant$2, E as columnVector$2, F as rowVector$2, H as vectorProductLeft$2, I as setColumn$2, L as setRow$2, M as make$2, N as reverseColumns$2, O as equals$2, P as reverseRows$2, R as solveSystem$2, S as toRows$3, T as vectorProductRight$3, U as vectorProductRight$2, V as transpose$2, _ as rowVector$3, a as fromColumns$3, b as solveSystem$3, c as inverse$1, d as isMatrix3x3$1, f as make$3, g as reverseRows$3, h as reverseColumns$3, i as equals$3, j as isMatrix2x2$1, k as fromColumns$2, l as inverseUnsafe$1, m as multiply$1, n as columnVector$3, o as fromRows$3, p as minor$1, r as determinant$3, s as identity$1, t as asInvertible$1, u as isInvertible$1, v as setColumn$3, w as vectorProductLeft$3, x as toColumns$3, y as setRow$3, z as toColumns$2 } from "../shared/matrix3x3.internal-Cod-r7H3.mjs";
|
|
3
|
+
import { r as matrix4x4_exports } from "../shared/matrix4x4-BrqgYZCD.mjs";
|
|
3
4
|
//#region src/matrix/matrix2x2.ts
|
|
4
5
|
var matrix2x2_exports = /* @__PURE__ */ __exportAll({
|
|
5
6
|
columnVector: () => columnVector$1,
|
|
@@ -131,14 +132,20 @@ const reverseColumns$1 = reverseColumns$2;
|
|
|
131
132
|
//#endregion
|
|
132
133
|
//#region src/matrix/matrix3x3.ts
|
|
133
134
|
var matrix3x3_exports = /* @__PURE__ */ __exportAll({
|
|
135
|
+
asInvertible: () => asInvertible,
|
|
134
136
|
columnVector: () => columnVector,
|
|
135
137
|
determinant: () => determinant,
|
|
136
138
|
equals: () => equals,
|
|
137
139
|
fromColumns: () => fromColumns,
|
|
138
140
|
fromRows: () => fromRows,
|
|
141
|
+
identity: () => identity,
|
|
142
|
+
inverse: () => inverse,
|
|
143
|
+
inverseUnsafe: () => inverseUnsafe,
|
|
144
|
+
isInvertible: () => isInvertible,
|
|
139
145
|
isMatrix3x3: () => isMatrix3x3,
|
|
140
146
|
make: () => make,
|
|
141
147
|
minor: () => minor,
|
|
148
|
+
multiply: () => multiply,
|
|
142
149
|
reverseColumns: () => reverseColumns,
|
|
143
150
|
reverseRows: () => reverseRows,
|
|
144
151
|
rowVector: () => rowVector,
|
|
@@ -261,6 +268,45 @@ const reverseRows = reverseRows$3;
|
|
|
261
268
|
* @since 1.0.0
|
|
262
269
|
*/
|
|
263
270
|
const reverseColumns = reverseColumns$3;
|
|
271
|
+
/**
|
|
272
|
+
* The 3x3 identity matrix.
|
|
273
|
+
*
|
|
274
|
+
* @since 2.0.0
|
|
275
|
+
*/
|
|
276
|
+
const identity = identity$1;
|
|
277
|
+
const multiply = multiply$1;
|
|
278
|
+
const inverse = inverse$1;
|
|
279
|
+
/**
|
|
280
|
+
* Returns the inverse of a `Matrix3x3`. Throws when the matrix is singular
|
|
281
|
+
* (determinant approximately zero). Useful when you've already validated
|
|
282
|
+
* invertibility out-of-band and want the unwrapped matrix directly; otherwise
|
|
283
|
+
* prefer {@link inverse}.
|
|
284
|
+
*
|
|
285
|
+
* @param m - The matrix to invert.
|
|
286
|
+
* @returns The inverse matrix.
|
|
287
|
+
* @throws If `m` is singular.
|
|
288
|
+
* @since 2.0.0
|
|
289
|
+
*/
|
|
290
|
+
const inverseUnsafe = inverseUnsafe$1;
|
|
291
|
+
/**
|
|
292
|
+
* Type-narrowing predicate: refines a `Matrix3x3<T>` to
|
|
293
|
+
* `Matrix3x3<T & Invertible>` when the matrix's determinant is non-zero
|
|
294
|
+
* (within the default absolute tolerance).
|
|
295
|
+
*
|
|
296
|
+
* @param m - The matrix to check.
|
|
297
|
+
* @returns `true` when `m` is invertible.
|
|
298
|
+
* @since 2.0.0
|
|
299
|
+
*/
|
|
300
|
+
const isInvertible = isInvertible$1;
|
|
301
|
+
/**
|
|
302
|
+
* Asserts that the matrix is invertible, throwing on a singular matrix.
|
|
303
|
+
*
|
|
304
|
+
* @param m - The matrix to assert against.
|
|
305
|
+
* @returns The same matrix, typed with the `Invertible` brand.
|
|
306
|
+
* @throws When `m` is singular.
|
|
307
|
+
* @since 2.0.0
|
|
308
|
+
*/
|
|
309
|
+
const asInvertible = asInvertible$1;
|
|
264
310
|
//#endregion
|
|
265
311
|
export { matrix2x2_exports as Matrix2x2, matrix3x3_exports as Matrix3x3, matrix4x4_exports as Matrix4x4 };
|
|
266
312
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["internal.isMatrix2x2","equals","internal.equals","make","internal.make","fromRows","internal.fromRows","fromColumns","internal.fromColumns","setRow","internal.setRow","setColumn","internal.setColumn","determinant","internal.determinant","vectorProductLeft","internal.vectorProductLeft","vectorProductRight","internal.vectorProductRight","solveSystem","internal.solveSystem","toRows","internal.toRows","toColumns","internal.toColumns","rowVector","internal.rowVector","columnVector","internal.columnVector","transpose","internal.transpose","reverseRows","internal.reverseRows","reverseColumns","internal.reverseColumns","internal.isMatrix3x3","internal.equals","internal.make","internal.fromRows","internal.fromColumns","internal.setRow","internal.setColumn","internal.determinant","internal.minor","internal.vectorProductLeft","internal.vectorProductRight","internal.solveSystem","internal.toRows","internal.toColumns","internal.rowVector","internal.columnVector","internal.transpose","internal.reverseRows","internal.reverseColumns"],"sources":["../../src/matrix/matrix2x2.ts","../../src/matrix/matrix3x3.ts"],"sourcesContent":["import type { TwoDimensionalComponent, TwoDimensionalIndex } from '../dimensions.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport type { Matrix2x2TypeId } from './matrix2x2.internal.ts'\nimport * as internal from './matrix2x2.internal.ts'\n\n/**\n * A type representing the coordinate of a 2D matrix.\n *\n * @since 1.0.0\n */\nexport type Matrix2x2Coordinate = TwoDimensionalIndex | TwoDimensionalComponent\n\n/**\n * A 2D matrix with 2 rows and 2 columns.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 1.0.0\n */\nexport interface Matrix2x2 extends Pipeable {\n readonly [Matrix2x2TypeId]: Matrix2x2TypeId\n\n /**\n * The value in the first row and first column.\n */\n readonly m00: number\n /**\n * The value in the first row and second column.\n */\n readonly m01: number\n /**\n * The value in the second row and first column.\n */\n readonly m10: number\n /**\n * The value in the second row and second column.\n */\n readonly m11: number\n}\n\n/**\n * Checks if a value is a `Matrix2x2`.\n *\n * @param m - The value to check.\n * @returns `true` if the value is a `Matrix2x2`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isMatrix2x2: (m: unknown) => m is Matrix2x2 = internal.isMatrix2x2\n\nexport const equals: {\n /**\n * Checks if two `Matrix2x2` 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: Matrix2x2, b: Matrix2x2): boolean\n /**\n * Checks if two `Matrix2x2` 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: Matrix2x2): (a: Matrix2x2) => boolean\n} = internal.equals\n\n/**\n * Creates a new `Matrix2x2` instance.\n *\n * @param m00 - The value in the first row and first column. Defaults to 0.\n * @param m01 - The value in the first row and second column. Defaults to 0.\n * @param m10 - The value in the second row and first column. Defaults to 0.\n * @param m11 - The value in the second row and second column. Defaults to 0.\n */\nexport const make: (m00?: number, m01?: number, m10?: number, m11?: number) => Matrix2x2 =\n internal.make\n\n/**\n * Creates a new `Matrix2x2` instance from two vectors representing rows.\n *\n * @param v0 - The first row vector.\n * @param v1 - The second row vector.\n * @returns A new `Matrix2x2` instance.\n * @since 1.0.0\n */\nexport const fromRows: (v0: Vector2, v1: Vector2) => Matrix2x2 = internal.fromRows\n\n/**\n * Creates a new `Matrix2x2` instance from two vectors representing columns.\n *\n * @param v0 - The first column vector.\n * @param v1 - The second column vector.\n * @returns A new `Matrix2x2` instance.\n * @since 1.0.0\n */\nexport const fromColumns: (v0: Vector2, v1: Vector2) => Matrix2x2 = internal.fromColumns\n\nexport const setRow: {\n /**\n * Sets the specified row of the matrix to the given vector.\n *\n * @param m - The matrix to modify.\n * @param row - The row index (0 or 1).\n * @param v - The vector to set the row to.\n * @returns A new `Matrix2x2` instance with the specified row set to the given vector.\n * @since 1.0.0\n */\n (m: Matrix2x2, row: Matrix2x2Coordinate, v: Vector2): Matrix2x2\n /**\n * Sets the specified row of the matrix to the given vector.\n *\n * @param row - The row index (0 or 1).\n * @param v - The vector to set the row to.\n * @returns A function that takes a matrix and returns a new `Matrix2x2` instance with the specified row set to the given vector.\n * @since 1.0.0\n */\n (row: Matrix2x2Coordinate, v: Vector2): (m: Matrix2x2) => Matrix2x2\n} = internal.setRow\n\nexport const setColumn: {\n /**\n * Sets the specified column of the matrix to the given vector.\n *\n * @param m - The matrix to modify.\n * @param column - The column index (0 or 1).\n * @param v - The vector to set the column to.\n * @returns A new `Matrix2x2` instance with the specified column set to the given vector.\n * @since 1.0.0\n */\n (m: Matrix2x2, column: Matrix2x2Coordinate, v: Vector2): Matrix2x2\n /**\n * Sets the specified column of the matrix to the given vector.\n *\n * @param column - The column index (0 or 1).\n * @param v - The vector to set the column to.\n * @returns A function that takes a matrix and returns a new `Matrix2x2` instance with the specified column set to the given vector.\n * @since 1.0.0\n */\n (column: Matrix2x2Coordinate, v: Vector2): (m: Matrix2x2) => Matrix2x2\n} = internal.setColumn\n\n/**\n * Calculates the determinant of a 2D matrix.\n *\n * @param m - The matrix to calculate the determinant for.\n * @returns The determinant of the matrix.\n * @since 1.0.0\n */\nexport const determinant: (m: Matrix2x2) => number = internal.determinant\n\nexport const vectorProductLeft: {\n /**\n * Calculates the left vector product of a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix2x2 from 'curvy/matrix2x2'\n * import * as Vector2 from 'curvy/vector2'\n *\n * const matrix = Matrix2x2.make(1, 2, 3, 4)\n * const vector = Vector2.make(5, 6)\n *\n * // Performs:\n * // x = 1 * 5 + 2 * 6 = 17\n * // y = 3 * 5 + 4 * 6 = 39\n * const result = Matrix2x2.vectorProductLeft(matrix, vector)\n * ```\n * @param m - The matrix to multiply.\n * @param v - The vector to multiply.\n * @returns The resulting vector after the left vector product.\n * @since 1.0.0\n */\n (m: Matrix2x2, v: Vector2): Vector2\n /**\n * Calculates the left vector product of a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix2x2 from 'curvy/matrix2x2'\n * import * as Vector2 from 'curvy/vector2'\n *\n * const matrix = Matrix2x2.make(1, 2, 3, 4)\n * const vector = Vector2.make(5, 6)\n *\n * // Performs:\n * // x = 1 * 5 + 2 * 6 = 17\n * // y = 3 * 5 + 4 * 6 = 39\n * const result = Matrix2x2.vectorProductLeft(vector)(matrix)\n * ```\n * @param v - The vector to multiply.\n * @returns A function that takes a matrix and returns the resulting vector after the left vector product.\n * @since 1.0.0\n */\n (v: Vector2): (m: Matrix2x2) => Vector2\n} = internal.vectorProductLeft\n\nexport const vectorProductRight: {\n /**\n * Calculates the right vector product of a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix2x2 from 'curvy/matrix2x2'\n * import * as Vector2 from 'curvy/vector2'\n *\n * const matrix = Matrix2x2.make(1, 2, 3, 4)\n * const vector = Vector2.make(5, 6)\n *\n * // Performs:\n * // x = 1 * 5 + 3 * 6 = 33\n * // y = 2 * 5 + 4 * 6 = 62\n * const result = Matrix2x2.vectorProductRight(matrix, vector)\n * ```\n * @param m - The matrix to multiply.\n * @param v - The vector to multiply.\n * @returns The resulting vector after the right vector product.\n * @since 1.0.0\n */\n (m: Matrix2x2, v: Vector2): Vector2\n /**\n * Calculates the right vector product of a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix2x2 from 'curvy/matrix2x2'\n * import * as Vector2 from 'curvy/vector2'\n *\n * const matrix = Matrix2x2.make(1, 2, 3, 4)\n * const vector = Vector2.make(5, 6)\n *\n * // Performs:\n * // x = 1 * 5 + 3 * 6 = 33\n * // y = 2 * 5 + 4 * 6 = 62\n * const result = Matrix2x2.vectorProductRight(vector)(matrix)\n * ```\n * @param v - The vector to multiply.\n * @returns A function that takes a matrix and returns the resulting vector after the right vector product.\n * @since 1.0.0\n */\n (v: Vector2): (m: Matrix2x2) => Vector2\n} = internal.vectorProductRight\n\nexport const solveSystem: {\n /**\n * Solves a system of linear equations represented by a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix2x2 from 'curvy/matrix2x2'\n * import * as Vector2 from 'curvy/vector2'\n *\n * const matrix = Matrix2x2.make(1, 2, 3, 4)\n * const vector = Vector2.make(5, 6)\n *\n * // Solves the system of equations:\n * // 1x + 2y = 5\n * // 3x + 4y = 6\n * const result = Matrix2x2.solveSystem(matrix, vector)\n * ```\n * @param m - The matrix representing the coefficients of the system.\n * @param v - The vector representing the constants of the system.\n * @returns The solution vector.\n * @since 1.0.0\n */\n (m: Matrix2x2, v: Vector2): Vector2\n /**\n * Solves a system of linear equations represented by a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix2x2 from 'curvy/matrix2x2'\n * import * as Vector2 from 'curvy/vector2'\n *\n * const matrix = Matrix2x2.make(1, 2, 3, 4)\n * const vector = Vector2.make(5, 6)\n *\n * // Solves the system of equations:\n * // 1x + 2y = 5\n * // 3x + 4y = 6\n * const result = Matrix2x2.solveSystem(vector)(matrix)\n * ```\n * @param v - The vector representing the constants of the system.\n * @returns A function that takes a matrix and returns the solution vector.\n * @since 1.0.0\n */\n (v: Vector2): (m: Matrix2x2) => Vector2\n} = internal.solveSystem\n\n/**\n * Returns the rows of a matrix 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: Matrix2x2) => [Vector2, Vector2] = internal.toRows\n\n/**\n * Returns the columns of a matrix 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: Matrix2x2) => [Vector2, Vector2] = internal.toColumns\n\n/**\n * Returns the specified row of a matrix as a vector.\n *\n * @param m - The matrix to get the row from.\n * @param row - The row index (0 or 1).\n * @returns A vector representing the specified row of the matrix.\n * @since 1.0.0\n */\nexport const rowVector: (m: Matrix2x2, row: Matrix2x2Coordinate) => Vector2 = internal.rowVector\n\n/**\n * Returns the specified column of a matrix as a vector.\n *\n * @param m - The matrix to get the column from.\n * @param column - The column index (0 or 1).\n * @returns A vector representing the specified column of the matrix.\n * @since 1.0.0\n */\nexport const columnVector: (m: Matrix2x2, column: Matrix2x2Coordinate) => Vector2 =\n internal.columnVector\n\n/**\n * Transposes a matrix.\n *\n * @param m - The matrix to transpose.\n * @returns A new `Matrix2x2` instance representing the transposed matrix.\n * @since 1.0.0\n */\nexport const transpose: (m: Matrix2x2) => Matrix2x2 = internal.transpose\n\n/**\n * Reverses the rows of a matrix.\n *\n * @param m - The matrix to reverse the rows of.\n * @returns A new `Matrix2x2` instance with the rows reversed.\n * @since 1.0.0\n */\nexport const reverseRows: (m: Matrix2x2) => Matrix2x2 = internal.reverseRows\n\n/**\n * Reverses the columns of a matrix.\n *\n * @param m - The matrix to reverse the columns of.\n * @returns A new `Matrix2x2` instance with the columns reversed.\n * @since 1.0.0\n */\nexport const reverseColumns: (m: Matrix2x2) => Matrix2x2 = internal.reverseColumns\n","import type { ThreeDimensionalComponent, ThreeDimensionalIndex } from '../dimensions.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector3 } from '../vector/vector3.ts'\nimport type { Matrix2x2 } from './matrix2x2.ts'\nimport type { Matrix3x3TypeId } from './matrix3x3.internal.ts'\nimport * as internal from './matrix3x3.internal.ts'\n\n/**\n * A coordinate in a 3x3 matrix.\n *\n * @since 1.0.0\n */\nexport type Matrix3x3Coordinate = ThreeDimensionalIndex | ThreeDimensionalComponent\n\n/**\n * A 3x3 matrix.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 1.0.0\n */\nexport interface Matrix3x3 extends Pipeable {\n readonly [Matrix3x3TypeId]: Matrix3x3TypeId\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 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 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\n/**\n * Checks if a value is a `Matrix3x3`.\n *\n * @param m - The value to check.\n * @returns `true` if the value is a `Matrix3x3`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isMatrix3x3: (m: unknown) => m is Matrix3x3 = internal.isMatrix3x3\n\nexport const equals: {\n /**\n * Checks if two `Matrix3x3` 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: Matrix3x3, b: Matrix3x3): boolean\n /**\n * Checks if two `Matrix3x3` 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: Matrix3x3): (a: Matrix3x3) => boolean\n} = internal.equals\n\n/**\n * Creates a new `Matrix3x3` 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 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 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 * @returns A new `Matrix3x3` instance.\n * @since 1.0.0\n */\nexport const make: (\n m00?: number,\n m01?: number,\n m02?: number,\n m10?: number,\n m11?: number,\n m12?: number,\n m20?: number,\n m21?: number,\n m22?: number,\n) => Matrix3x3 = internal.make\n\n/**\n * Creates a new `Matrix3x3` instance from three 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 * @returns A new `Matrix3x3` instance.\n * @since 1.0.0\n */\nexport const fromRows: (v0: Vector3, v1: Vector3, v2: Vector3) => Matrix3x3 = internal.fromRows\n\n/**\n * Creates a new `Matrix3x3` instance from three 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 * @returns A new `Matrix3x3` instance.\n * @since 1.0.0\n */\nexport const fromColumns: (v0: Vector3, v1: Vector3, v2: Vector3) => Matrix3x3 =\n internal.fromColumns\n\nexport const setRow: {\n /**\n * Sets a row of the matrix to a new vector.\n *\n * @param m - The matrix to set the row of.\n * @param row - The row index to set.\n * @param v - The new vector for the row.\n * @returns A new matrix with the specified row set to the new vector.\n * @since 1.0.0\n */\n (m: Matrix3x3, row: Matrix3x3Coordinate, v: Vector3): Matrix3x3\n /**\n * Sets a row of the matrix to a new vector.\n *\n * @param row - The row index to set.\n * @param v - The new vector for the row.\n * @returns A function that takes a matrix and returns a new matrix with the specified row set to the new vector.\n * @since 1.0.0\n */\n (row: Matrix3x3Coordinate, v: Vector3): (m: Matrix3x3) => Matrix3x3\n} = internal.setRow\n\nexport const setColumn: {\n /**\n * Sets a column of the matrix to a new vector.\n *\n * @param m - The matrix to set the column of.\n * @param column - The column index to set.\n * @param v - The new vector for the column.\n * @returns A new matrix with the specified column set to the new vector.\n * @since 1.0.0\n */\n (m: Matrix3x3, column: Matrix3x3Coordinate, v: Vector3): Matrix3x3\n /**\n * Sets a column of the matrix to a new vector.\n *\n * @param column - The column index to set.\n * @param v - The new vector for the column.\n * @returns A function that takes a matrix and returns a new matrix with the specified column set to the new vector.\n * @since 1.0.0\n */\n (column: Matrix3x3Coordinate, v: Vector3): (m: Matrix3x3) => Matrix3x3\n} = internal.setColumn\n\n/**\n * Calculates the determinant of a 3x3 matrix.\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: Matrix3x3) => number = internal.determinant\n\n/**\n * Calculates the minor of a 3x3 matrix.\n *\n * @param m - The matrix to calculate the minor of.\n * @param row - The row index of the element to calculate the minor for.\n * @param column - The column index of the element to calculate the minor for.\n * @returns The minor of the matrix at the specified row and column.\n * @since 1.0.0\n */\nexport const minor: (\n m: Matrix3x3,\n row: Matrix3x3Coordinate,\n column: Matrix3x3Coordinate,\n) => Matrix2x2 = internal.minor\n\nexport const vectorProductLeft: {\n /**\n * Calculates the left vector product of a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix3x3 from 'curvy/matrix3x3'\n * import * as Vector3 from 'curvy/vector3'\n *\n * const m = Matrix3x3.make(1, 2, 3, 4, 5, 6, 7, 8, 9)\n * const v = Vector3.vector3(10, 11, 12)\n *\n * // Performs:\n * // x = 1 * 10 + 2 * 11 + 3 * 12\n * // y = 4 * 10 + 5 * 11 + 6 * 12\n * // z = 7 * 10 + 8 * 11 + 9 * 12\n * const result = Matrix3x3.vectorProductLeft(m, v)\n * ```\n * @param m - The matrix to calculate the left vector product with.\n * @param v - The vector to calculate the left vector product with.\n * @returns The resulting vector from the left vector product.\n * @since 1.0.0\n */\n (m: Matrix3x3, v: Vector3): Vector3\n /**\n * Calculates the left vector product of a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix3x3 from 'curvy/matrix3x3'\n * import * as Vector3 from 'curvy/vector3'\n *\n * const m = Matrix3x3.make(1, 2, 3, 4, 5, 6, 7, 8, 9)\n * const v = Vector3.vector3(10, 11, 12)\n *\n * // Performs:\n * // x = 1 * 10 + 2 * 11 + 3 * 12\n * // y = 4 * 10 + 5 * 11 + 6 * 12\n * // z = 7 * 10 + 8 * 11 + 9 * 12\n * const result = Matrix3x3.vectorProductLeft(v)(m)\n * ```\n * @param v - The vector to calculate the left vector product with.\n * @returns A function that takes a matrix and returns the resulting vector from the left vector product.\n * @since 1.0.0\n */\n (v: Vector3): (m: Matrix3x3) => Vector3\n} = internal.vectorProductLeft\n\nexport const vectorProductRight: {\n /**\n * Calculates the right vector product of a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix3x3 from 'curvy/matrix3x3'\n * import * as Vector3 from 'curvy/vector3'\n *\n * const m = Matrix3x3.make(1, 2, 3, 4, 5, 6, 7, 8, 9)\n * const v = Vector3.vector3(10, 11, 12)\n *\n * // Performs:\n * // x = 1 * 10 + 4 * 11 + 7 * 12\n * // y = 2 * 10 + 5 * 11 + 8 * 12\n * // z = 3 * 10 + 6 * 11 + 9 * 12\n * const result = Matrix3x3.vectorProductRight(m, v)\n * ```\n * @param m - The matrix to calculate the right vector product with.\n * @param v - The vector to calculate the right vector product with.\n * @returns The resulting vector from the right vector product.\n * @since 1.0.0\n */\n (m: Matrix3x3, v: Vector3): Vector3\n /**\n * Calculates the right vector product of a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix3x3 from 'curvy/matrix3x3'\n * import * as Vector3 from 'curvy/vector3'\n *\n * const m = Matrix3x3.make(1, 2, 3, 4, 5, 6, 7, 8, 9)\n * const v = Vector3.vector3(10, 11, 12)\n *\n * // Performs:\n * // x = 1 * 10 + 4 * 11 + 7 * 12\n * // y = 2 * 10 + 5 * 11 + 8 * 12\n * // z = 3 * 10 + 6 * 11 + 9 * 12\n * const result = Matrix3x3.vectorProductRight(v)(m)\n * ```\n * @param v - The vector to calculate the right vector product with.\n * @returns A function that takes a matrix and returns the resulting vector from the right vector product.\n * @since 1.0.0\n */\n (v: Vector3): (m: Matrix3x3) => Vector3\n} = internal.vectorProductRight\n\nexport const solveSystem: {\n /**\n * Solves a system of equations represented by a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix3x3 from 'curvy/matrix3x3'\n * import * as Vector3 from 'curvy/vector3'\n *\n * const m = Matrix3x3.make(1, 2, 3, 4, 5, 6, 7, 8, 9)\n * const v = Vector3.vector3(10, 11, 12)\n *\n * // Performs:\n * // x = m00 * x + m01 * y + m02 * z\n * // y = m10 * x + m11 * y + m12 * z\n * // z = m20 * x + m21 * y + m22 * z\n * const result = Matrix3x3.solveSystem(m, v)\n * ```\n * @since 1.0.0\n */\n (m: Matrix3x3, v: Vector3): Vector3\n /**\n * Solves a system of equations represented by a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix3x3 from 'curvy/matrix3x3'\n * import * as Vector3 from 'curvy/vector3'\n *\n * const m = Matrix3x3.make(1, 2, 3, 4, 5, 6, 7, 8, 9)\n * const v = Vector3.vector3(10, 11, 12)\n *\n * // Performs:\n * // x = m00 * x + m01 * y + m02 * z\n * // y = m10 * x + m11 * y + m12 * z\n * // z = m20 * x + m21 * y + m22 * z\n * const result = Matrix3x3.solveSystem(v)(m)\n * ```\n * @since 1.0.0\n */\n (v: Vector3): (m: Matrix3x3) => Vector3\n} = internal.solveSystem\n\n/**\n * Returns the rows of a `Matrix3x3` as an array of vectors.\n *\n * @param m - The matrix to get the rows from.\n * @returns An array of vectors representing the rows of the matrix.\n * @since 1.0.0\n */\nexport const toRows: (m: Matrix3x3) => [Vector3, Vector3, Vector3] = internal.toRows as (\n m: Matrix3x3,\n) => [Vector3, Vector3, Vector3]\n\n/**\n * Returns the columns of a `Matrix3x3` as an array of vectors.\n *\n * @param m - The matrix to get the columns from.\n * @returns An array of vectors representing the columns of the matrix.\n * @since 1.0.0\n */\nexport const toColumns: (m: Matrix3x3) => [Vector3, Vector3, Vector3] = internal.toColumns as (\n m: Matrix3x3,\n) => [Vector3, Vector3, Vector3]\n\nexport const rowVector: {\n /**\n * Gets a row vector from the matrix.\n *\n * @param m - The matrix to get the row vector from.\n * @param row - The row index to get the vector from.\n * @returns The row vector at the specified index.\n * @since 1.0.0\n */\n (m: Matrix3x3, row: Matrix3x3Coordinate): Vector3\n /**\n * Gets a row vector from the matrix.\n *\n * @param row - The row index to get the vector from.\n * @returns A function that takes a matrix and returns the row vector at the specified index.\n * @since 1.0.0\n */\n (row: Matrix3x3Coordinate): (m: Matrix3x3) => Vector3\n} = internal.rowVector\n\nexport const columnVector: {\n /**\n * Gets a column vector from the matrix.\n *\n * @param m - The matrix to get the column vector from.\n * @param column - The column index to get the vector from.\n * @returns The column vector at the specified index.\n * @since 1.0.0\n */\n (m: Matrix3x3, column: Matrix3x3Coordinate): Vector3\n /**\n * Gets a column vector from the matrix.\n *\n * @param column - The column index to get the vector from.\n * @returns A function that takes a matrix and returns the column vector at the specified index.\n * @since 1.0.0\n */\n (column: Matrix3x3Coordinate): (m: Matrix3x3) => Vector3\n} = internal.columnVector\n\n/**\n * Transposes a `Matrix3x3`.\n *\n * @param m - The matrix to transpose.\n * @returns A new `Matrix3x3` instance that is the transpose of the input matrix.\n * @since 1.0.0\n */\nexport const transpose: (m: Matrix3x3) => Matrix3x3 = internal.transpose\n\n/**\n * Reverses the rows of a `Matrix3x3`.\n *\n * @param m - The matrix to reverse the rows of.\n * @returns A new `Matrix3x3` instance with the rows reversed.\n * @since 1.0.0\n */\nexport const reverseRows: (m: Matrix3x3) => Matrix3x3 = internal.reverseRows\n\n/**\n * Reverses the columns of a `Matrix3x3`.\n *\n * @param m - The matrix to reverse the columns of.\n * @returns A new `Matrix3x3` instance with the columns reversed.\n * @since 1.0.0\n */\nexport const reverseColumns: (m: Matrix3x3) => Matrix3x3 = internal.reverseColumns\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,cAA8CA;AAE3D,MAAaC,WAoBTC;;;;;;;;;AAUJ,MAAaC,SACXC;;;;;;;;;AAUF,MAAaC,aAAoDC;;;;;;;;;AAUjE,MAAaC,gBAAuDC;AAEpE,MAAaC,WAoBTC;AAEJ,MAAaC,cAoBTC;;;;;;;;AASJ,MAAaC,gBAAwCC;AAErD,MAAaC,sBA4CTC;AAEJ,MAAaC,uBA4CTC;AAEJ,MAAaC,gBA4CTC;;;;;;;;AASJ,MAAaC,WAA+CC;;;;;;;;AAS5D,MAAaC,cAAkDC;;;;;;;;;AAU/D,MAAaC,cAAiEC;;;;;;;;;AAU9E,MAAaC,iBACXC;;;;;;;;AASF,MAAaC,cAAyCC;;;;;;;;AAStD,MAAaC,gBAA2CC;;;;;;;;AASxD,MAAaC,mBAA8CC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AClS3D,MAAa,cAA8CC;AAE3D,MAAa,SAoBTC;;;;;;;;;;;;;;;;AAiBJ,MAAa,OAUIC;;;;;;;;;;AAWjB,MAAa,WAAiEC;;;;;;;;;;AAW9E,MAAa,cACXC;AAEF,MAAa,SAoBTC;AAEJ,MAAa,YAoBTC;;;;;;;;AASJ,MAAa,cAAwCC;;;;;;;;;;AAWrD,MAAa,QAIIC;AAEjB,MAAa,oBA8CTC;AAEJ,MAAa,qBA8CTC;AAEJ,MAAa,cAyCTC;;;;;;;;AASJ,MAAa,SAAwDC;;;;;;;;AAWrE,MAAa,YAA2DC;AAIxE,MAAa,YAkBTC;AAEJ,MAAa,eAkBTC;;;;;;;;AASJ,MAAa,YAAyCC;;;;;;;;AAStD,MAAa,cAA2CC;;;;;;;;AASxD,MAAa,iBAA8CC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["internal.isMatrix2x2","equals","internal.equals","make","internal.make","fromRows","internal.fromRows","fromColumns","internal.fromColumns","setRow","internal.setRow","setColumn","internal.setColumn","determinant","internal.determinant","vectorProductLeft","internal.vectorProductLeft","vectorProductRight","internal.vectorProductRight","solveSystem","internal.solveSystem","toRows","internal.toRows","toColumns","internal.toColumns","rowVector","internal.rowVector","columnVector","internal.columnVector","transpose","internal.transpose","reverseRows","internal.reverseRows","reverseColumns","internal.reverseColumns","internal.isMatrix3x3","internal.equals","internal.make","internal.fromRows","internal.fromColumns","internal.setRow","internal.setColumn","internal.determinant","internal.minor","internal.vectorProductLeft","internal.vectorProductRight","internal.solveSystem","internal.toRows","internal.toColumns","internal.rowVector","internal.columnVector","internal.transpose","internal.reverseRows","internal.reverseColumns","internal.identity","internal.multiply","internal.inverse","internal.inverseUnsafe","internal.isInvertible","internal.asInvertible"],"sources":["../../src/matrix/matrix2x2.ts","../../src/matrix/matrix3x3.ts"],"sourcesContent":["import type { TwoDimensionalComponent, TwoDimensionalIndex } from '../dimensions.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport type { Matrix2x2TypeId } from './matrix2x2.internal.ts'\nimport * as internal from './matrix2x2.internal.ts'\n\n/**\n * A type representing the coordinate of a 2D matrix.\n *\n * @since 1.0.0\n */\nexport type Matrix2x2Coordinate = TwoDimensionalIndex | TwoDimensionalComponent\n\n/**\n * A 2D matrix with 2 rows and 2 columns.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 1.0.0\n */\nexport interface Matrix2x2 extends Pipeable {\n readonly [Matrix2x2TypeId]: Matrix2x2TypeId\n\n /**\n * The value in the first row and first column.\n */\n readonly m00: number\n /**\n * The value in the first row and second column.\n */\n readonly m01: number\n /**\n * The value in the second row and first column.\n */\n readonly m10: number\n /**\n * The value in the second row and second column.\n */\n readonly m11: number\n}\n\n/**\n * Checks if a value is a `Matrix2x2`.\n *\n * @param m - The value to check.\n * @returns `true` if the value is a `Matrix2x2`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isMatrix2x2: (m: unknown) => m is Matrix2x2 = internal.isMatrix2x2\n\nexport const equals: {\n /**\n * Checks if two `Matrix2x2` 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: Matrix2x2, b: Matrix2x2): boolean\n /**\n * Checks if two `Matrix2x2` 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: Matrix2x2): (a: Matrix2x2) => boolean\n} = internal.equals\n\n/**\n * Creates a new `Matrix2x2` instance.\n *\n * @param m00 - The value in the first row and first column. Defaults to 0.\n * @param m01 - The value in the first row and second column. Defaults to 0.\n * @param m10 - The value in the second row and first column. Defaults to 0.\n * @param m11 - The value in the second row and second column. Defaults to 0.\n */\nexport const make: (m00?: number, m01?: number, m10?: number, m11?: number) => Matrix2x2 =\n internal.make\n\n/**\n * Creates a new `Matrix2x2` instance from two vectors representing rows.\n *\n * @param v0 - The first row vector.\n * @param v1 - The second row vector.\n * @returns A new `Matrix2x2` instance.\n * @since 1.0.0\n */\nexport const fromRows: (v0: Vector2, v1: Vector2) => Matrix2x2 = internal.fromRows\n\n/**\n * Creates a new `Matrix2x2` instance from two vectors representing columns.\n *\n * @param v0 - The first column vector.\n * @param v1 - The second column vector.\n * @returns A new `Matrix2x2` instance.\n * @since 1.0.0\n */\nexport const fromColumns: (v0: Vector2, v1: Vector2) => Matrix2x2 = internal.fromColumns\n\nexport const setRow: {\n /**\n * Sets the specified row of the matrix to the given vector.\n *\n * @param m - The matrix to modify.\n * @param row - The row index (0 or 1).\n * @param v - The vector to set the row to.\n * @returns A new `Matrix2x2` instance with the specified row set to the given vector.\n * @since 1.0.0\n */\n (m: Matrix2x2, row: Matrix2x2Coordinate, v: Vector2): Matrix2x2\n /**\n * Sets the specified row of the matrix to the given vector.\n *\n * @param row - The row index (0 or 1).\n * @param v - The vector to set the row to.\n * @returns A function that takes a matrix and returns a new `Matrix2x2` instance with the specified row set to the given vector.\n * @since 1.0.0\n */\n (row: Matrix2x2Coordinate, v: Vector2): (m: Matrix2x2) => Matrix2x2\n} = internal.setRow\n\nexport const setColumn: {\n /**\n * Sets the specified column of the matrix to the given vector.\n *\n * @param m - The matrix to modify.\n * @param column - The column index (0 or 1).\n * @param v - The vector to set the column to.\n * @returns A new `Matrix2x2` instance with the specified column set to the given vector.\n * @since 1.0.0\n */\n (m: Matrix2x2, column: Matrix2x2Coordinate, v: Vector2): Matrix2x2\n /**\n * Sets the specified column of the matrix to the given vector.\n *\n * @param column - The column index (0 or 1).\n * @param v - The vector to set the column to.\n * @returns A function that takes a matrix and returns a new `Matrix2x2` instance with the specified column set to the given vector.\n * @since 1.0.0\n */\n (column: Matrix2x2Coordinate, v: Vector2): (m: Matrix2x2) => Matrix2x2\n} = internal.setColumn\n\n/**\n * Calculates the determinant of a 2D matrix.\n *\n * @param m - The matrix to calculate the determinant for.\n * @returns The determinant of the matrix.\n * @since 1.0.0\n */\nexport const determinant: (m: Matrix2x2) => number = internal.determinant\n\nexport const vectorProductLeft: {\n /**\n * Calculates the left vector product of a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix2x2 from 'curvy/matrix2x2'\n * import * as Vector2 from 'curvy/vector2'\n *\n * const matrix = Matrix2x2.make(1, 2, 3, 4)\n * const vector = Vector2.make(5, 6)\n *\n * // Performs:\n * // x = 1 * 5 + 2 * 6 = 17\n * // y = 3 * 5 + 4 * 6 = 39\n * const result = Matrix2x2.vectorProductLeft(matrix, vector)\n * ```\n * @param m - The matrix to multiply.\n * @param v - The vector to multiply.\n * @returns The resulting vector after the left vector product.\n * @since 1.0.0\n */\n (m: Matrix2x2, v: Vector2): Vector2\n /**\n * Calculates the left vector product of a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix2x2 from 'curvy/matrix2x2'\n * import * as Vector2 from 'curvy/vector2'\n *\n * const matrix = Matrix2x2.make(1, 2, 3, 4)\n * const vector = Vector2.make(5, 6)\n *\n * // Performs:\n * // x = 1 * 5 + 2 * 6 = 17\n * // y = 3 * 5 + 4 * 6 = 39\n * const result = Matrix2x2.vectorProductLeft(vector)(matrix)\n * ```\n * @param v - The vector to multiply.\n * @returns A function that takes a matrix and returns the resulting vector after the left vector product.\n * @since 1.0.0\n */\n (v: Vector2): (m: Matrix2x2) => Vector2\n} = internal.vectorProductLeft\n\nexport const vectorProductRight: {\n /**\n * Calculates the right vector product of a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix2x2 from 'curvy/matrix2x2'\n * import * as Vector2 from 'curvy/vector2'\n *\n * const matrix = Matrix2x2.make(1, 2, 3, 4)\n * const vector = Vector2.make(5, 6)\n *\n * // Performs:\n * // x = 1 * 5 + 3 * 6 = 33\n * // y = 2 * 5 + 4 * 6 = 62\n * const result = Matrix2x2.vectorProductRight(matrix, vector)\n * ```\n * @param m - The matrix to multiply.\n * @param v - The vector to multiply.\n * @returns The resulting vector after the right vector product.\n * @since 1.0.0\n */\n (m: Matrix2x2, v: Vector2): Vector2\n /**\n * Calculates the right vector product of a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix2x2 from 'curvy/matrix2x2'\n * import * as Vector2 from 'curvy/vector2'\n *\n * const matrix = Matrix2x2.make(1, 2, 3, 4)\n * const vector = Vector2.make(5, 6)\n *\n * // Performs:\n * // x = 1 * 5 + 3 * 6 = 33\n * // y = 2 * 5 + 4 * 6 = 62\n * const result = Matrix2x2.vectorProductRight(vector)(matrix)\n * ```\n * @param v - The vector to multiply.\n * @returns A function that takes a matrix and returns the resulting vector after the right vector product.\n * @since 1.0.0\n */\n (v: Vector2): (m: Matrix2x2) => Vector2\n} = internal.vectorProductRight\n\nexport const solveSystem: {\n /**\n * Solves a system of linear equations represented by a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix2x2 from 'curvy/matrix2x2'\n * import * as Vector2 from 'curvy/vector2'\n *\n * const matrix = Matrix2x2.make(1, 2, 3, 4)\n * const vector = Vector2.make(5, 6)\n *\n * // Solves the system of equations:\n * // 1x + 2y = 5\n * // 3x + 4y = 6\n * const result = Matrix2x2.solveSystem(matrix, vector)\n * ```\n * @param m - The matrix representing the coefficients of the system.\n * @param v - The vector representing the constants of the system.\n * @returns The solution vector.\n * @since 1.0.0\n */\n (m: Matrix2x2, v: Vector2): Vector2\n /**\n * Solves a system of linear equations represented by a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix2x2 from 'curvy/matrix2x2'\n * import * as Vector2 from 'curvy/vector2'\n *\n * const matrix = Matrix2x2.make(1, 2, 3, 4)\n * const vector = Vector2.make(5, 6)\n *\n * // Solves the system of equations:\n * // 1x + 2y = 5\n * // 3x + 4y = 6\n * const result = Matrix2x2.solveSystem(vector)(matrix)\n * ```\n * @param v - The vector representing the constants of the system.\n * @returns A function that takes a matrix and returns the solution vector.\n * @since 1.0.0\n */\n (v: Vector2): (m: Matrix2x2) => Vector2\n} = internal.solveSystem\n\n/**\n * Returns the rows of a matrix 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: Matrix2x2) => [Vector2, Vector2] = internal.toRows\n\n/**\n * Returns the columns of a matrix 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: Matrix2x2) => [Vector2, Vector2] = internal.toColumns\n\n/**\n * Returns the specified row of a matrix as a vector.\n *\n * @param m - The matrix to get the row from.\n * @param row - The row index (0 or 1).\n * @returns A vector representing the specified row of the matrix.\n * @since 1.0.0\n */\nexport const rowVector: (m: Matrix2x2, row: Matrix2x2Coordinate) => Vector2 = internal.rowVector\n\n/**\n * Returns the specified column of a matrix as a vector.\n *\n * @param m - The matrix to get the column from.\n * @param column - The column index (0 or 1).\n * @returns A vector representing the specified column of the matrix.\n * @since 1.0.0\n */\nexport const columnVector: (m: Matrix2x2, column: Matrix2x2Coordinate) => Vector2 =\n internal.columnVector\n\n/**\n * Transposes a matrix.\n *\n * @param m - The matrix to transpose.\n * @returns A new `Matrix2x2` instance representing the transposed matrix.\n * @since 1.0.0\n */\nexport const transpose: (m: Matrix2x2) => Matrix2x2 = internal.transpose\n\n/**\n * Reverses the rows of a matrix.\n *\n * @param m - The matrix to reverse the rows of.\n * @returns A new `Matrix2x2` instance with the rows reversed.\n * @since 1.0.0\n */\nexport const reverseRows: (m: Matrix2x2) => Matrix2x2 = internal.reverseRows\n\n/**\n * Reverses the columns of a matrix.\n *\n * @param m - The matrix to reverse the columns of.\n * @returns A new `Matrix2x2` instance with the columns reversed.\n * @since 1.0.0\n */\nexport const reverseColumns: (m: Matrix2x2) => Matrix2x2 = internal.reverseColumns\n","import type { ThreeDimensionalComponent, ThreeDimensionalIndex } from '../dimensions.ts'\nimport type * as Solution from '../solution/solution.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector3 } from '../vector/vector3.ts'\nimport type { Matrix2x2 } from './matrix2x2.ts'\nimport type { Matrix3x3TypeId } from './matrix3x3.internal.ts'\nimport * as internal from './matrix3x3.internal.ts'\nimport type { Invertible, MatrixTraits } from './traits.ts'\n\nexport type { Invertible } from './traits.ts'\n\n/**\n * A coordinate in a 3x3 matrix.\n *\n * @since 1.0.0\n */\nexport type Matrix3x3Coordinate = ThreeDimensionalIndex | ThreeDimensionalComponent\n\n/**\n * A 3x3 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 Matrix3x3<out Traits = unknown> extends Pipeable {\n readonly [Matrix3x3TypeId]: Matrix3x3TypeId\n readonly [MatrixTraits]: Traits\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 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 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\n/**\n * Checks if a value is a `Matrix3x3`.\n *\n * @param m - The value to check.\n * @returns `true` if the value is a `Matrix3x3`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isMatrix3x3: (m: unknown) => m is Matrix3x3 = internal.isMatrix3x3\n\nexport const equals: {\n /**\n * Checks if two `Matrix3x3` 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: Matrix3x3, b: Matrix3x3): boolean\n /**\n * Checks if two `Matrix3x3` 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: Matrix3x3): (a: Matrix3x3) => boolean\n} = internal.equals\n\n/**\n * Creates a new `Matrix3x3` 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 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 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 * @returns A new `Matrix3x3` instance.\n * @since 1.0.0\n */\nexport const make: (\n m00?: number,\n m01?: number,\n m02?: number,\n m10?: number,\n m11?: number,\n m12?: number,\n m20?: number,\n m21?: number,\n m22?: number,\n) => Matrix3x3 = internal.make\n\n/**\n * Creates a new `Matrix3x3` instance from three 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 * @returns A new `Matrix3x3` instance.\n * @since 1.0.0\n */\nexport const fromRows: (v0: Vector3, v1: Vector3, v2: Vector3) => Matrix3x3 = internal.fromRows\n\n/**\n * Creates a new `Matrix3x3` instance from three 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 * @returns A new `Matrix3x3` instance.\n * @since 1.0.0\n */\nexport const fromColumns: (v0: Vector3, v1: Vector3, v2: Vector3) => Matrix3x3 =\n internal.fromColumns\n\nexport const setRow: {\n /**\n * Sets a row of the matrix to a new vector.\n *\n * @param m - The matrix to set the row of.\n * @param row - The row index to set.\n * @param v - The new vector for the row.\n * @returns A new matrix with the specified row set to the new vector.\n * @since 1.0.0\n */\n (m: Matrix3x3, row: Matrix3x3Coordinate, v: Vector3): Matrix3x3\n /**\n * Sets a row of the matrix to a new vector.\n *\n * @param row - The row index to set.\n * @param v - The new vector for the row.\n * @returns A function that takes a matrix and returns a new matrix with the specified row set to the new vector.\n * @since 1.0.0\n */\n (row: Matrix3x3Coordinate, v: Vector3): (m: Matrix3x3) => Matrix3x3\n} = internal.setRow\n\nexport const setColumn: {\n /**\n * Sets a column of the matrix to a new vector.\n *\n * @param m - The matrix to set the column of.\n * @param column - The column index to set.\n * @param v - The new vector for the column.\n * @returns A new matrix with the specified column set to the new vector.\n * @since 1.0.0\n */\n (m: Matrix3x3, column: Matrix3x3Coordinate, v: Vector3): Matrix3x3\n /**\n * Sets a column of the matrix to a new vector.\n *\n * @param column - The column index to set.\n * @param v - The new vector for the column.\n * @returns A function that takes a matrix and returns a new matrix with the specified column set to the new vector.\n * @since 1.0.0\n */\n (column: Matrix3x3Coordinate, v: Vector3): (m: Matrix3x3) => Matrix3x3\n} = internal.setColumn\n\n/**\n * Calculates the determinant of a 3x3 matrix.\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: Matrix3x3) => number = internal.determinant\n\n/**\n * Calculates the minor of a 3x3 matrix.\n *\n * @param m - The matrix to calculate the minor of.\n * @param row - The row index of the element to calculate the minor for.\n * @param column - The column index of the element to calculate the minor for.\n * @returns The minor of the matrix at the specified row and column.\n * @since 1.0.0\n */\nexport const minor: (\n m: Matrix3x3,\n row: Matrix3x3Coordinate,\n column: Matrix3x3Coordinate,\n) => Matrix2x2 = internal.minor\n\nexport const vectorProductLeft: {\n /**\n * Calculates the left vector product of a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix3x3 from 'curvy/matrix3x3'\n * import * as Vector3 from 'curvy/vector3'\n *\n * const m = Matrix3x3.make(1, 2, 3, 4, 5, 6, 7, 8, 9)\n * const v = Vector3.vector3(10, 11, 12)\n *\n * // Performs:\n * // x = 1 * 10 + 2 * 11 + 3 * 12\n * // y = 4 * 10 + 5 * 11 + 6 * 12\n * // z = 7 * 10 + 8 * 11 + 9 * 12\n * const result = Matrix3x3.vectorProductLeft(m, v)\n * ```\n * @param m - The matrix to calculate the left vector product with.\n * @param v - The vector to calculate the left vector product with.\n * @returns The resulting vector from the left vector product.\n * @since 1.0.0\n */\n (m: Matrix3x3, v: Vector3): Vector3\n /**\n * Calculates the left vector product of a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix3x3 from 'curvy/matrix3x3'\n * import * as Vector3 from 'curvy/vector3'\n *\n * const m = Matrix3x3.make(1, 2, 3, 4, 5, 6, 7, 8, 9)\n * const v = Vector3.vector3(10, 11, 12)\n *\n * // Performs:\n * // x = 1 * 10 + 2 * 11 + 3 * 12\n * // y = 4 * 10 + 5 * 11 + 6 * 12\n * // z = 7 * 10 + 8 * 11 + 9 * 12\n * const result = Matrix3x3.vectorProductLeft(v)(m)\n * ```\n * @param v - The vector to calculate the left vector product with.\n * @returns A function that takes a matrix and returns the resulting vector from the left vector product.\n * @since 1.0.0\n */\n (v: Vector3): (m: Matrix3x3) => Vector3\n} = internal.vectorProductLeft\n\nexport const vectorProductRight: {\n /**\n * Calculates the right vector product of a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix3x3 from 'curvy/matrix3x3'\n * import * as Vector3 from 'curvy/vector3'\n *\n * const m = Matrix3x3.make(1, 2, 3, 4, 5, 6, 7, 8, 9)\n * const v = Vector3.vector3(10, 11, 12)\n *\n * // Performs:\n * // x = 1 * 10 + 4 * 11 + 7 * 12\n * // y = 2 * 10 + 5 * 11 + 8 * 12\n * // z = 3 * 10 + 6 * 11 + 9 * 12\n * const result = Matrix3x3.vectorProductRight(m, v)\n * ```\n * @param m - The matrix to calculate the right vector product with.\n * @param v - The vector to calculate the right vector product with.\n * @returns The resulting vector from the right vector product.\n * @since 1.0.0\n */\n (m: Matrix3x3, v: Vector3): Vector3\n /**\n * Calculates the right vector product of a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix3x3 from 'curvy/matrix3x3'\n * import * as Vector3 from 'curvy/vector3'\n *\n * const m = Matrix3x3.make(1, 2, 3, 4, 5, 6, 7, 8, 9)\n * const v = Vector3.vector3(10, 11, 12)\n *\n * // Performs:\n * // x = 1 * 10 + 4 * 11 + 7 * 12\n * // y = 2 * 10 + 5 * 11 + 8 * 12\n * // z = 3 * 10 + 6 * 11 + 9 * 12\n * const result = Matrix3x3.vectorProductRight(v)(m)\n * ```\n * @param v - The vector to calculate the right vector product with.\n * @returns A function that takes a matrix and returns the resulting vector from the right vector product.\n * @since 1.0.0\n */\n (v: Vector3): (m: Matrix3x3) => Vector3\n} = internal.vectorProductRight\n\nexport const solveSystem: {\n /**\n * Solves a system of equations represented by a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix3x3 from 'curvy/matrix3x3'\n * import * as Vector3 from 'curvy/vector3'\n *\n * const m = Matrix3x3.make(1, 2, 3, 4, 5, 6, 7, 8, 9)\n * const v = Vector3.vector3(10, 11, 12)\n *\n * // Performs:\n * // x = m00 * x + m01 * y + m02 * z\n * // y = m10 * x + m11 * y + m12 * z\n * // z = m20 * x + m21 * y + m22 * z\n * const result = Matrix3x3.solveSystem(m, v)\n * ```\n * @since 1.0.0\n */\n (m: Matrix3x3, v: Vector3): Vector3\n /**\n * Solves a system of equations represented by a matrix and a vector.\n *\n * @example\n * ```ts\n * import * as Matrix3x3 from 'curvy/matrix3x3'\n * import * as Vector3 from 'curvy/vector3'\n *\n * const m = Matrix3x3.make(1, 2, 3, 4, 5, 6, 7, 8, 9)\n * const v = Vector3.vector3(10, 11, 12)\n *\n * // Performs:\n * // x = m00 * x + m01 * y + m02 * z\n * // y = m10 * x + m11 * y + m12 * z\n * // z = m20 * x + m21 * y + m22 * z\n * const result = Matrix3x3.solveSystem(v)(m)\n * ```\n * @since 1.0.0\n */\n (v: Vector3): (m: Matrix3x3) => Vector3\n} = internal.solveSystem\n\n/**\n * Returns the rows of a `Matrix3x3` as an array of vectors.\n *\n * @param m - The matrix to get the rows from.\n * @returns An array of vectors representing the rows of the matrix.\n * @since 1.0.0\n */\nexport const toRows: (m: Matrix3x3) => [Vector3, Vector3, Vector3] = internal.toRows as (\n m: Matrix3x3,\n) => [Vector3, Vector3, Vector3]\n\n/**\n * Returns the columns of a `Matrix3x3` as an array of vectors.\n *\n * @param m - The matrix to get the columns from.\n * @returns An array of vectors representing the columns of the matrix.\n * @since 1.0.0\n */\nexport const toColumns: (m: Matrix3x3) => [Vector3, Vector3, Vector3] = internal.toColumns as (\n m: Matrix3x3,\n) => [Vector3, Vector3, Vector3]\n\nexport const rowVector: {\n /**\n * Gets a row vector from the matrix.\n *\n * @param m - The matrix to get the row vector from.\n * @param row - The row index to get the vector from.\n * @returns The row vector at the specified index.\n * @since 1.0.0\n */\n (m: Matrix3x3, row: Matrix3x3Coordinate): Vector3\n /**\n * Gets a row vector from the matrix.\n *\n * @param row - The row index to get the vector from.\n * @returns A function that takes a matrix and returns the row vector at the specified index.\n * @since 1.0.0\n */\n (row: Matrix3x3Coordinate): (m: Matrix3x3) => Vector3\n} = internal.rowVector\n\nexport const columnVector: {\n /**\n * Gets a column vector from the matrix.\n *\n * @param m - The matrix to get the column vector from.\n * @param column - The column index to get the vector from.\n * @returns The column vector at the specified index.\n * @since 1.0.0\n */\n (m: Matrix3x3, column: Matrix3x3Coordinate): Vector3\n /**\n * Gets a column vector from the matrix.\n *\n * @param column - The column index to get the vector from.\n * @returns A function that takes a matrix and returns the column vector at the specified index.\n * @since 1.0.0\n */\n (column: Matrix3x3Coordinate): (m: Matrix3x3) => Vector3\n} = internal.columnVector\n\n/**\n * Transposes a `Matrix3x3`.\n *\n * @param m - The matrix to transpose.\n * @returns A new `Matrix3x3` instance that is the transpose of the input matrix.\n * @since 1.0.0\n */\nexport const transpose: (m: Matrix3x3) => Matrix3x3 = internal.transpose\n\n/**\n * Reverses the rows of a `Matrix3x3`.\n *\n * @param m - The matrix to reverse the rows of.\n * @returns A new `Matrix3x3` instance with the rows reversed.\n * @since 1.0.0\n */\nexport const reverseRows: (m: Matrix3x3) => Matrix3x3 = internal.reverseRows\n\n/**\n * Reverses the columns of a `Matrix3x3`.\n *\n * @param m - The matrix to reverse the columns of.\n * @returns A new `Matrix3x3` instance with the columns reversed.\n * @since 1.0.0\n */\nexport const reverseColumns: (m: Matrix3x3) => Matrix3x3 = internal.reverseColumns\n\n/**\n * The 3x3 identity matrix.\n *\n * @since 2.0.0\n */\nexport const identity: Matrix3x3 = internal.identity\n\nexport const multiply: {\n /**\n * Multiplies two `Matrix3x3` 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 2.0.0\n */\n (a: Matrix3x3, b: Matrix3x3): Matrix3x3\n /**\n * Multiplies two `Matrix3x3` 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 2.0.0\n */\n (b: Matrix3x3): (a: Matrix3x3) => Matrix3x3\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 `Matrix3x3`. 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: Matrix3x3<T>): Solution.One<Matrix3x3<T>>\n /**\n * Returns the inverse of a `Matrix3x3`. 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: Matrix3x3<T>): Solution.AtMostOne<Matrix3x3<T>>\n} = internal.inverse as never\n\n/**\n * Returns the inverse of a `Matrix3x3`. 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: Matrix3x3) => Matrix3x3 = internal.inverseUnsafe\n\n/**\n * Type-narrowing predicate: refines a `Matrix3x3<T>` to\n * `Matrix3x3<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: Matrix3x3<T>) => m is Matrix3x3<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: Matrix3x3<T>) => Matrix3x3<T & Invertible> = internal.asInvertible\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,cAA8CA;AAE3D,MAAaC,WAoBTC;;;;;;;;;AAUJ,MAAaC,SACXC;;;;;;;;;AAUF,MAAaC,aAAoDC;;;;;;;;;AAUjE,MAAaC,gBAAuDC;AAEpE,MAAaC,WAoBTC;AAEJ,MAAaC,cAoBTC;;;;;;;;AASJ,MAAaC,gBAAwCC;AAErD,MAAaC,sBA4CTC;AAEJ,MAAaC,uBA4CTC;AAEJ,MAAaC,gBA4CTC;;;;;;;;AASJ,MAAaC,WAA+CC;;;;;;;;AAS5D,MAAaC,cAAkDC;;;;;;;;;AAU/D,MAAaC,cAAiEC;;;;;;;;;AAU9E,MAAaC,iBACXC;;;;;;;;AASF,MAAaC,cAAyCC;;;;;;;;AAStD,MAAaC,gBAA2CC;;;;;;;;AASxD,MAAaC,mBAA8CC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACxR3D,MAAa,cAA8CC;AAE3D,MAAa,SAoBTC;;;;;;;;;;;;;;;;AAiBJ,MAAa,OAUIC;;;;;;;;;;AAWjB,MAAa,WAAiEC;;;;;;;;;;AAW9E,MAAa,cACXC;AAEF,MAAa,SAoBTC;AAEJ,MAAa,YAoBTC;;;;;;;;AASJ,MAAa,cAAwCC;;;;;;;;;;AAWrD,MAAa,QAIIC;AAEjB,MAAa,oBA8CTC;AAEJ,MAAa,qBA8CTC;AAEJ,MAAa,cAyCTC;;;;;;;;AASJ,MAAa,SAAwDC;;;;;;;;AAWrE,MAAa,YAA2DC;AAIxE,MAAa,YAkBTC;AAEJ,MAAa,eAkBTC;;;;;;;;AASJ,MAAa,YAAyCC;;;;;;;;AAStD,MAAa,cAA2CC;;;;;;;;AASxD,MAAa,iBAA8CC;;;;;;AAO3D,MAAa,WAAsBC;AAEnC,MAAa,WAkBTC;AAMJ,MAAa,UAoBTC;;;;;;;;;;;;AAaJ,MAAa,gBAA6CC;;;;;;;;;;AAW1D,MAAa,eACXC;;;;;;;;;AAUF,MAAa,eAAkEC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { ThreeDimensionalComponent, ThreeDimensionalIndex } from '../dimensions.ts';
|
|
2
|
+
import type * as Solution from '../solution/solution.ts';
|
|
2
3
|
import type { Pipeable } from '../utils.ts';
|
|
3
4
|
import type { Vector3 } from '../vector/vector3.ts';
|
|
4
5
|
import type { Matrix2x2 } from './matrix2x2.ts';
|
|
5
6
|
import type { Matrix3x3TypeId } from './matrix3x3.internal.ts';
|
|
7
|
+
import type { Invertible, MatrixTraits } from './traits.ts';
|
|
8
|
+
export type { Invertible } from './traits.ts';
|
|
6
9
|
/**
|
|
7
10
|
* A coordinate in a 3x3 matrix.
|
|
8
11
|
*
|
|
@@ -14,10 +17,16 @@ export type Matrix3x3Coordinate = ThreeDimensionalIndex | ThreeDimensionalCompon
|
|
|
14
17
|
*
|
|
15
18
|
* All fields are readonly and immutable, and all operations create new instances.
|
|
16
19
|
*
|
|
20
|
+
* The `Traits` type parameter is a phantom marker that accumulates trait
|
|
21
|
+
* brands as the matrix is refined via `isInvertible` / `asInvertible`. The
|
|
22
|
+
* runtime value carries no trait data — `Traits` only flows through the type
|
|
23
|
+
* system to enable tighter return types on operations like {@link inverse}.
|
|
24
|
+
*
|
|
17
25
|
* @since 1.0.0
|
|
18
26
|
*/
|
|
19
|
-
export interface Matrix3x3 extends Pipeable {
|
|
27
|
+
export interface Matrix3x3<out Traits = unknown> extends Pipeable {
|
|
20
28
|
readonly [Matrix3x3TypeId]: Matrix3x3TypeId;
|
|
29
|
+
readonly [MatrixTraits]: Traits;
|
|
21
30
|
/**
|
|
22
31
|
* The value of the first row and first column.
|
|
23
32
|
*/
|
|
@@ -394,3 +403,80 @@ export declare const reverseRows: (m: Matrix3x3) => Matrix3x3;
|
|
|
394
403
|
* @since 1.0.0
|
|
395
404
|
*/
|
|
396
405
|
export declare const reverseColumns: (m: Matrix3x3) => Matrix3x3;
|
|
406
|
+
/**
|
|
407
|
+
* The 3x3 identity matrix.
|
|
408
|
+
*
|
|
409
|
+
* @since 2.0.0
|
|
410
|
+
*/
|
|
411
|
+
export declare const identity: Matrix3x3;
|
|
412
|
+
export declare const multiply: {
|
|
413
|
+
/**
|
|
414
|
+
* Multiplies two `Matrix3x3` instances. Result is `a · b`.
|
|
415
|
+
*
|
|
416
|
+
* @param a - The left-hand matrix.
|
|
417
|
+
* @param b - The right-hand matrix.
|
|
418
|
+
* @returns The product matrix.
|
|
419
|
+
* @since 2.0.0
|
|
420
|
+
*/
|
|
421
|
+
(a: Matrix3x3, b: Matrix3x3): Matrix3x3;
|
|
422
|
+
/**
|
|
423
|
+
* Multiplies two `Matrix3x3` instances. Result is `a · b`.
|
|
424
|
+
*
|
|
425
|
+
* @param b - The right-hand matrix.
|
|
426
|
+
* @returns A function that takes the left-hand matrix and returns the product.
|
|
427
|
+
* @since 2.0.0
|
|
428
|
+
*/
|
|
429
|
+
(b: Matrix3x3): (a: Matrix3x3) => Matrix3x3;
|
|
430
|
+
};
|
|
431
|
+
export declare const inverse: {
|
|
432
|
+
/**
|
|
433
|
+
* Returns the inverse of an `Invertible`-branded `Matrix3x3`. Because the
|
|
434
|
+
* brand guarantees non-singularity, the result is always a single matrix —
|
|
435
|
+
* wrapped in `Solution.One`.
|
|
436
|
+
*
|
|
437
|
+
* @param m - The matrix to invert.
|
|
438
|
+
* @since 2.0.0
|
|
439
|
+
*/
|
|
440
|
+
<T extends Invertible>(m: Matrix3x3<T>): Solution.One<Matrix3x3<T>>;
|
|
441
|
+
/**
|
|
442
|
+
* Returns the inverse of a `Matrix3x3`. Returns `Solution.none` if the
|
|
443
|
+
* matrix is singular (determinant approximately zero). Use {@link asInvertible}
|
|
444
|
+
* or {@link isInvertible} to refine the type and tighten the return to
|
|
445
|
+
* `Solution.One`, or use {@link inverseUnsafe} if you want the throwing form.
|
|
446
|
+
*
|
|
447
|
+
* @param m - The matrix to invert.
|
|
448
|
+
* @since 2.0.0
|
|
449
|
+
*/
|
|
450
|
+
<T>(m: Matrix3x3<T>): Solution.AtMostOne<Matrix3x3<T>>;
|
|
451
|
+
};
|
|
452
|
+
/**
|
|
453
|
+
* Returns the inverse of a `Matrix3x3`. Throws when the matrix is singular
|
|
454
|
+
* (determinant approximately zero). Useful when you've already validated
|
|
455
|
+
* invertibility out-of-band and want the unwrapped matrix directly; otherwise
|
|
456
|
+
* prefer {@link inverse}.
|
|
457
|
+
*
|
|
458
|
+
* @param m - The matrix to invert.
|
|
459
|
+
* @returns The inverse matrix.
|
|
460
|
+
* @throws If `m` is singular.
|
|
461
|
+
* @since 2.0.0
|
|
462
|
+
*/
|
|
463
|
+
export declare const inverseUnsafe: (m: Matrix3x3) => Matrix3x3;
|
|
464
|
+
/**
|
|
465
|
+
* Type-narrowing predicate: refines a `Matrix3x3<T>` to
|
|
466
|
+
* `Matrix3x3<T & Invertible>` when the matrix's determinant is non-zero
|
|
467
|
+
* (within the default absolute tolerance).
|
|
468
|
+
*
|
|
469
|
+
* @param m - The matrix to check.
|
|
470
|
+
* @returns `true` when `m` is invertible.
|
|
471
|
+
* @since 2.0.0
|
|
472
|
+
*/
|
|
473
|
+
export declare const isInvertible: <T>(m: Matrix3x3<T>) => m is Matrix3x3<T & Invertible>;
|
|
474
|
+
/**
|
|
475
|
+
* Asserts that the matrix is invertible, throwing on a singular matrix.
|
|
476
|
+
*
|
|
477
|
+
* @param m - The matrix to assert against.
|
|
478
|
+
* @returns The same matrix, typed with the `Invertible` brand.
|
|
479
|
+
* @throws When `m` is singular.
|
|
480
|
+
* @since 2.0.0
|
|
481
|
+
*/
|
|
482
|
+
export declare const asInvertible: <T>(m: Matrix3x3<T>) => Matrix3x3<T & Invertible>;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { FourDimensionalComponent, FourDimensionalIndex } from '../dimensions.ts';
|
|
2
|
+
import type * as Solution from '../solution/solution.ts';
|
|
2
3
|
import type { Pipeable } from '../utils.ts';
|
|
3
4
|
import type { Vector4 } from '../vector/vector4.ts';
|
|
4
5
|
import type { Matrix3x3 } from './matrix3x3.ts';
|
|
5
6
|
import type { Matrix4x4TypeId } from './matrix4x4.internal.ts';
|
|
7
|
+
import type { Invertible, MatrixTraits } from './traits.ts';
|
|
8
|
+
export type { Invertible } from './traits.ts';
|
|
6
9
|
/**
|
|
7
10
|
* A coordinate in a 4x4 matrix.
|
|
8
11
|
*
|
|
@@ -14,10 +17,16 @@ export type Matrix4x4Coordinate = FourDimensionalIndex | FourDimensionalComponen
|
|
|
14
17
|
*
|
|
15
18
|
* All fields are readonly and immutable, and all operations create new instances.
|
|
16
19
|
*
|
|
20
|
+
* The `Traits` type parameter is a phantom marker that accumulates trait
|
|
21
|
+
* brands as the matrix is refined via `isInvertible` / `asInvertible`. The
|
|
22
|
+
* runtime value carries no trait data — `Traits` only flows through the type
|
|
23
|
+
* system to enable tighter return types on operations like {@link inverse}.
|
|
24
|
+
*
|
|
17
25
|
* @since 1.0.0
|
|
18
26
|
*/
|
|
19
|
-
export interface Matrix4x4 extends Pipeable {
|
|
27
|
+
export interface Matrix4x4<out Traits = unknown> extends Pipeable {
|
|
20
28
|
readonly [Matrix4x4TypeId]: Matrix4x4TypeId;
|
|
29
|
+
readonly [MatrixTraits]: Traits;
|
|
21
30
|
/**
|
|
22
31
|
* The value of the first row and first column.
|
|
23
32
|
*/
|
|
@@ -330,16 +339,58 @@ export declare const multiply: {
|
|
|
330
339
|
*/
|
|
331
340
|
(b: Matrix4x4): (a: Matrix4x4) => Matrix4x4;
|
|
332
341
|
};
|
|
342
|
+
export declare const inverse: {
|
|
343
|
+
/**
|
|
344
|
+
* Returns the inverse of an `Invertible`-branded `Matrix4x4`. Because the
|
|
345
|
+
* brand guarantees non-singularity, the result is always a single matrix —
|
|
346
|
+
* wrapped in `Solution.One`.
|
|
347
|
+
*
|
|
348
|
+
* @param m - The matrix to invert.
|
|
349
|
+
* @since 2.0.0
|
|
350
|
+
*/
|
|
351
|
+
<T extends Invertible>(m: Matrix4x4<T>): Solution.One<Matrix4x4<T>>;
|
|
352
|
+
/**
|
|
353
|
+
* Returns the inverse of a `Matrix4x4`. Returns `Solution.none` if the
|
|
354
|
+
* matrix is singular (determinant approximately zero). Use {@link asInvertible}
|
|
355
|
+
* or {@link isInvertible} to refine the type and tighten the return to
|
|
356
|
+
* `Solution.One`, or use {@link inverseUnsafe} if you want the throwing form.
|
|
357
|
+
*
|
|
358
|
+
* @param m - The matrix to invert.
|
|
359
|
+
* @since 2.0.0
|
|
360
|
+
*/
|
|
361
|
+
<T>(m: Matrix4x4<T>): Solution.AtMostOne<Matrix4x4<T>>;
|
|
362
|
+
};
|
|
333
363
|
/**
|
|
334
|
-
* Returns the inverse of a `Matrix4x4`.
|
|
335
|
-
*
|
|
336
|
-
*
|
|
364
|
+
* Returns the inverse of a `Matrix4x4`. Throws when the matrix is singular
|
|
365
|
+
* (determinant approximately zero). Useful when you've already validated
|
|
366
|
+
* invertibility out-of-band and want the unwrapped matrix directly; otherwise
|
|
367
|
+
* prefer {@link inverse}.
|
|
337
368
|
*
|
|
338
369
|
* @param m - The matrix to invert.
|
|
339
370
|
* @returns The inverse matrix.
|
|
340
|
-
* @
|
|
371
|
+
* @throws If `m` is singular.
|
|
372
|
+
* @since 2.0.0
|
|
373
|
+
*/
|
|
374
|
+
export declare const inverseUnsafe: (m: Matrix4x4) => Matrix4x4;
|
|
375
|
+
/**
|
|
376
|
+
* Type-narrowing predicate: refines a `Matrix4x4<T>` to
|
|
377
|
+
* `Matrix4x4<T & Invertible>` when the matrix's determinant is non-zero
|
|
378
|
+
* (within the default absolute tolerance).
|
|
379
|
+
*
|
|
380
|
+
* @param m - The matrix to check.
|
|
381
|
+
* @returns `true` when `m` is invertible.
|
|
382
|
+
* @since 2.0.0
|
|
383
|
+
*/
|
|
384
|
+
export declare const isInvertible: <T>(m: Matrix4x4<T>) => m is Matrix4x4<T & Invertible>;
|
|
385
|
+
/**
|
|
386
|
+
* Asserts that the matrix is invertible, throwing on a singular matrix.
|
|
387
|
+
*
|
|
388
|
+
* @param m - The matrix to assert against.
|
|
389
|
+
* @returns The same matrix, typed with the `Invertible` brand.
|
|
390
|
+
* @throws When `m` is singular.
|
|
391
|
+
* @since 2.0.0
|
|
341
392
|
*/
|
|
342
|
-
export declare const
|
|
393
|
+
export declare const asInvertible: <T>(m: Matrix4x4<T>) => Matrix4x4<T & Invertible>;
|
|
343
394
|
export declare const solveSystem: {
|
|
344
395
|
/**
|
|
345
396
|
* Solves a system of linear equations represented by a `Matrix4x4` and a `Vector4`.
|