curvy 1.0.7 → 1.0.9
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/curve/cubic2d.d.mts +80 -2
- package/dist/curve/cubic2d.d.ts +80 -2
- package/dist/curve/cubic2d.mjs +9 -26
- package/dist/curve/cubic2d.mjs.map +1 -0
- package/dist/curve/linear2d.d.mts +68 -2
- package/dist/curve/linear2d.d.ts +68 -2
- package/dist/curve/linear2d.mjs +11 -14
- package/dist/curve/linear2d.mjs.map +1 -0
- package/dist/curve/quadratic2d.d.mts +86 -2
- package/dist/curve/quadratic2d.d.ts +86 -2
- package/dist/curve/quadratic2d.mjs +10 -15
- package/dist/curve/quadratic2d.mjs.map +1 -0
- package/dist/interval.d.mts +195 -2
- package/dist/interval.d.ts +195 -2
- package/dist/interval.mjs +9 -12
- package/dist/interval.mjs.map +1 -0
- package/dist/matrix/matrix2x2.d.mts +273 -2
- package/dist/matrix/matrix2x2.d.ts +273 -2
- package/dist/matrix/matrix2x2.mjs +5 -4
- package/dist/matrix/matrix2x2.mjs.map +1 -0
- package/dist/matrix/matrix3x3.d.mts +308 -1
- package/dist/matrix/matrix3x3.d.ts +308 -1
- package/dist/matrix/matrix3x3.mjs +5 -4
- package/dist/matrix/matrix3x3.mjs.map +1 -0
- package/dist/matrix/matrix4x4.d.mts +310 -1
- package/dist/matrix/matrix4x4.d.ts +310 -1
- package/dist/matrix/matrix4x4.mjs +24 -61
- package/dist/matrix/matrix4x4.mjs.map +1 -0
- package/dist/path/cubic2d.d.mts +68 -2
- package/dist/path/cubic2d.d.ts +68 -2
- package/dist/path/cubic2d.mjs +10 -12
- package/dist/path/cubic2d.mjs.map +1 -0
- package/dist/path/linear2d.d.mts +68 -2
- package/dist/path/linear2d.d.ts +68 -2
- package/dist/path/linear2d.mjs +7 -9
- package/dist/path/linear2d.mjs.map +1 -0
- package/dist/path/quadratic2d.d.mts +67 -2
- package/dist/path/quadratic2d.d.ts +67 -2
- package/dist/path/quadratic2d.mjs +9 -13
- package/dist/path/quadratic2d.mjs.map +1 -0
- package/dist/pipe.mjs +1 -0
- package/dist/pipe.mjs.map +1 -0
- package/dist/polynomial/cubic.d.mts +1 -1
- package/dist/polynomial/cubic.d.ts +1 -1
- package/dist/polynomial/cubic.mjs +13 -28
- package/dist/polynomial/cubic.mjs.map +1 -0
- package/dist/polynomial/linear.d.mts +1 -1
- package/dist/polynomial/linear.d.ts +1 -1
- package/dist/polynomial/linear.mjs +2 -1
- package/dist/polynomial/linear.mjs.map +1 -0
- package/dist/polynomial/quadratic.d.mts +2 -2
- package/dist/polynomial/quadratic.d.ts +2 -2
- package/dist/polynomial/quadratic.mjs +5 -2
- package/dist/polynomial/quadratic.mjs.map +1 -0
- package/dist/shared/{curvy.Cps2R_RU.mjs → curvy.BkkW8Tx9.mjs} +11 -29
- package/dist/shared/curvy.BkkW8Tx9.mjs.map +1 -0
- package/dist/shared/{curvy.BzVmUIKm.mjs → curvy.BxdGW9he.mjs} +17 -32
- package/dist/shared/curvy.BxdGW9he.mjs.map +1 -0
- package/dist/shared/{curvy.C2XGH0R0.mjs → curvy.C_sCeg9J.mjs} +15 -24
- package/dist/shared/curvy.C_sCeg9J.mjs.map +1 -0
- package/dist/shared/curvy.Cg8lZVUz.d.ts +688 -0
- package/dist/shared/{curvy.CE4X6_Is.mjs → curvy.DCt1gGII.mjs} +11 -45
- package/dist/shared/curvy.DCt1gGII.mjs.map +1 -0
- package/dist/shared/{curvy.BZ_mTkJe.mjs → curvy.DJ4xO0al.mjs} +9 -6
- package/dist/shared/curvy.DJ4xO0al.mjs.map +1 -0
- package/dist/shared/curvy.DmVFTi0N.mjs +1 -0
- package/dist/shared/curvy.DmVFTi0N.mjs.map +1 -0
- package/dist/shared/curvy.FDaj5rlj.d.mts +688 -0
- package/dist/shared/{curvy.NLeFCr-9.mjs → curvy.lktriTpx.mjs} +19 -42
- package/dist/shared/curvy.lktriTpx.mjs.map +1 -0
- package/dist/shared/{curvy.Ck0of1PI.mjs → curvy.mLFprrGm.mjs} +26 -22
- package/dist/shared/curvy.mLFprrGm.mjs.map +1 -0
- package/dist/shared/{curvy.BDhiZ7He.mjs → curvy.r6f1j287.mjs} +8 -12
- package/dist/shared/curvy.r6f1j287.mjs.map +1 -0
- package/dist/splines/basis2d.d.mts +94 -2
- package/dist/splines/basis2d.d.ts +94 -2
- package/dist/splines/basis2d.mjs +13 -12
- package/dist/splines/basis2d.mjs.map +1 -0
- package/dist/splines/bezier2d.d.mts +136 -2
- package/dist/splines/bezier2d.d.ts +136 -2
- package/dist/splines/bezier2d.mjs +10 -9
- package/dist/splines/bezier2d.mjs.map +1 -0
- package/dist/splines/cardinal2d.d.mts +131 -2
- package/dist/splines/cardinal2d.d.ts +131 -2
- package/dist/splines/cardinal2d.mjs +15 -24
- package/dist/splines/cardinal2d.mjs.map +1 -0
- package/dist/splines/hermite2d.d.mts +94 -3
- package/dist/splines/hermite2d.d.ts +94 -3
- package/dist/splines/hermite2d.mjs +22 -36
- package/dist/splines/hermite2d.mjs.map +1 -0
- package/dist/utils.d.mts +179 -1
- package/dist/utils.d.ts +179 -1
- package/dist/utils.mjs +16 -7
- package/dist/utils.mjs.map +1 -0
- package/dist/vector/vector2.d.mts +259 -1
- package/dist/vector/vector2.d.ts +259 -1
- package/dist/vector/vector2.mjs +4 -2
- package/dist/vector/vector2.mjs.map +1 -0
- package/dist/vector/vector3.d.mts +345 -1
- package/dist/vector/vector3.d.ts +345 -1
- package/dist/vector/vector3.mjs +9 -2
- package/dist/vector/vector3.mjs.map +1 -0
- package/dist/vector/vector4.d.mts +163 -1
- package/dist/vector/vector4.d.ts +163 -1
- package/dist/vector/vector4.mjs +4 -2
- package/dist/vector/vector4.mjs.map +1 -0
- package/package.json +4 -4
- package/dist/shared/curvy.BsHoYJNv.d.ts +0 -155
- package/dist/shared/curvy.NsmY7zcr.d.mts +0 -155
package/dist/interval.d.ts
CHANGED
|
@@ -1,58 +1,251 @@
|
|
|
1
1
|
import { Pipeable } from './pipe.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* A mathematical interval.
|
|
5
|
+
*
|
|
6
|
+
* All fields are readonly and immutable, and all operations create new instances.
|
|
7
|
+
*
|
|
8
|
+
* @since 1.0.0
|
|
9
|
+
*/
|
|
3
10
|
interface Interval extends Pipeable {
|
|
4
11
|
readonly start: number;
|
|
5
12
|
readonly end: number;
|
|
6
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a value is an `Interval`.
|
|
16
|
+
*
|
|
17
|
+
* @param v - The value to check.
|
|
18
|
+
* @returns `true` if the value is an `Interval`, `false` otherwise.
|
|
19
|
+
* @since 1.0.0
|
|
20
|
+
*/
|
|
7
21
|
declare const isInterval: (v: unknown) => v is Interval;
|
|
8
22
|
declare const make: {
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new `Interval` instance.
|
|
25
|
+
*
|
|
26
|
+
* @param point - The point of the interval.
|
|
27
|
+
* @returns A new `Interval` instance.
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
*/
|
|
9
30
|
(point: number): Interval;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new `Interval` instance.
|
|
33
|
+
*
|
|
34
|
+
* @param start - The start of the interval.
|
|
35
|
+
* @param end - The end of the interval.
|
|
36
|
+
* @returns A new `Interval` instance.
|
|
37
|
+
* @since 1.0.0
|
|
38
|
+
*/
|
|
10
39
|
(start: number, end: number): Interval;
|
|
11
40
|
};
|
|
12
41
|
declare const fromSize: {
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new `Interval` instance from a size.
|
|
44
|
+
*
|
|
45
|
+
* @param size - The size of the interval.
|
|
46
|
+
* @returns A new `Interval` instance.
|
|
47
|
+
* @since 1.0.0
|
|
48
|
+
*/
|
|
13
49
|
(size: number): Interval;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new `Interval` instance from a size.
|
|
52
|
+
*
|
|
53
|
+
* @param size - The size of the interval.
|
|
54
|
+
* @param start - The start of the interval.
|
|
55
|
+
* @returns A new `Interval` instance.
|
|
56
|
+
* @since 1.0.0
|
|
57
|
+
*/
|
|
14
58
|
(start: number, size: number): Interval;
|
|
15
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Creates a new `Interval` instance from a minimum and maximum value.
|
|
62
|
+
*
|
|
63
|
+
* @param values - The minimum and maximum values of the interval.
|
|
64
|
+
* @returns A new `Interval` instance.
|
|
65
|
+
* @since 1.0.0
|
|
66
|
+
*/
|
|
16
67
|
declare const fromMinMax: (...values: ReadonlyArray<number>) => Interval;
|
|
68
|
+
/**
|
|
69
|
+
* Calculates the size of an interval.
|
|
70
|
+
*
|
|
71
|
+
* @param interval - The interval to calculate the size of.
|
|
72
|
+
* @returns The size of the interval.
|
|
73
|
+
* @since 1.0.0
|
|
74
|
+
*/
|
|
17
75
|
declare const size: (i: Interval) => number;
|
|
18
76
|
declare const contains: {
|
|
77
|
+
/**
|
|
78
|
+
* Checks if a value is contained within an interval.
|
|
79
|
+
*
|
|
80
|
+
* @param interval - The interval to check.
|
|
81
|
+
* @param value - The value to check.
|
|
82
|
+
* @param options - Options for the check.
|
|
83
|
+
* @returns `true` if the value is contained within the interval, `false` otherwise.
|
|
84
|
+
* @since 1.0.0
|
|
85
|
+
*/
|
|
19
86
|
(interval: Interval, value: number, options?: {
|
|
20
87
|
includeStart?: boolean;
|
|
21
88
|
includeEnd?: boolean;
|
|
22
89
|
}): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Checks if a value is contained within an interval.
|
|
92
|
+
*
|
|
93
|
+
* @param value - The value to check.
|
|
94
|
+
* @param options - Options for the check.
|
|
95
|
+
* @returns A function that takes an interval and returns `true` if the value is contained within the interval, `false` otherwise.
|
|
96
|
+
* @since 1.0.0
|
|
97
|
+
*/
|
|
23
98
|
(value: number, options?: {
|
|
24
99
|
includeStart?: boolean;
|
|
25
100
|
includeEnd?: boolean;
|
|
26
101
|
}): (interval: Interval) => boolean;
|
|
27
102
|
};
|
|
28
103
|
declare const filter: {
|
|
104
|
+
/**
|
|
105
|
+
* Filters a value to be within an interval.
|
|
106
|
+
*
|
|
107
|
+
* @param interval - The interval to filter the value to.
|
|
108
|
+
* @param value - The value to filter.
|
|
109
|
+
* @param options - Options for the filter.
|
|
110
|
+
* @returns The filtered value.
|
|
111
|
+
* @since 1.0.0
|
|
112
|
+
*/
|
|
29
113
|
<V extends ReadonlyArray<number>>(interval: Interval, value: V, options?: {
|
|
30
114
|
includeStart?: boolean;
|
|
31
115
|
includeEnd?: boolean;
|
|
32
116
|
}): V;
|
|
117
|
+
/**
|
|
118
|
+
* Filters a value to be within an interval.
|
|
119
|
+
*
|
|
120
|
+
* @param value - The value to filter.
|
|
121
|
+
* @param options - Options for the filter.
|
|
122
|
+
* @returns A function that takes an interval and returns the filtered value.
|
|
123
|
+
* @since 1.0.0
|
|
124
|
+
*/
|
|
33
125
|
<V extends ReadonlyArray<number>>(value: V, options?: {
|
|
34
126
|
includeStart?: boolean;
|
|
35
127
|
includeEnd?: boolean;
|
|
36
128
|
}): (interval: Interval) => V;
|
|
37
129
|
};
|
|
38
130
|
declare const clamp: {
|
|
131
|
+
/**
|
|
132
|
+
* Clamps a value to be within an interval.
|
|
133
|
+
*
|
|
134
|
+
* @param interval - The interval to clamp the value to.
|
|
135
|
+
* @param value - The value to clamp.
|
|
136
|
+
* @returns The clamped value.
|
|
137
|
+
* @since 1.0.0
|
|
138
|
+
*/
|
|
39
139
|
(interval: Interval, value: number): number;
|
|
140
|
+
/**
|
|
141
|
+
* Clamps a value to be within an interval.
|
|
142
|
+
*
|
|
143
|
+
* @param value - The value to clamp.
|
|
144
|
+
* @returns A function that takes an interval and returns the clamped value.
|
|
145
|
+
* @since 1.0.0
|
|
146
|
+
*/
|
|
40
147
|
(value: number): (interval: Interval) => number;
|
|
148
|
+
/**
|
|
149
|
+
* Clamps an array of values to be within an interval.
|
|
150
|
+
*
|
|
151
|
+
* @param interval - The interval to clamp the values to.
|
|
152
|
+
* @param value - The values to clamp.
|
|
153
|
+
* @returns The clamped values.
|
|
154
|
+
* @since 1.0.0
|
|
155
|
+
*/
|
|
41
156
|
(interval: Interval, value: ReadonlyArray<number>): ReadonlyArray<number>;
|
|
157
|
+
/**
|
|
158
|
+
* Clamps an array of values to be within an interval.
|
|
159
|
+
*
|
|
160
|
+
* @param value - The values to clamp.
|
|
161
|
+
* @returns A function that takes an interval and returns the clamped values.
|
|
162
|
+
* @since 1.0.0
|
|
163
|
+
*/
|
|
42
164
|
(value: ReadonlyArray<number>): (interval: Interval) => ReadonlyArray<number>;
|
|
43
165
|
};
|
|
166
|
+
/**
|
|
167
|
+
* The unit interval, which is the interval [0, 1].
|
|
168
|
+
*
|
|
169
|
+
* @since 1.0.0
|
|
170
|
+
*/
|
|
44
171
|
declare const unit: Interval;
|
|
172
|
+
/**
|
|
173
|
+
* The biunit interval, which is the interval [-1, 1].
|
|
174
|
+
*
|
|
175
|
+
* @since 1.0.0
|
|
176
|
+
*/
|
|
45
177
|
declare const biunit: Interval;
|
|
178
|
+
/**
|
|
179
|
+
* Linearly interpolates a value within an interval.
|
|
180
|
+
*
|
|
181
|
+
* @param interval - The interval to interpolate within.
|
|
182
|
+
* @param t - The interpolation factor, typically between 0 and 1.
|
|
183
|
+
* @returns The interpolated value.
|
|
184
|
+
* @since 1.0.0
|
|
185
|
+
*/
|
|
46
186
|
declare const lerp: (interval: Interval, t: number) => number;
|
|
187
|
+
/**
|
|
188
|
+
* Creates a linear interpolation function for an interval.
|
|
189
|
+
*
|
|
190
|
+
* @param interval - The interval to create the interpolation function for.
|
|
191
|
+
* @returns A function that takes a factor `t` and returns the interpolated value.
|
|
192
|
+
* @since 1.0.0
|
|
193
|
+
*/
|
|
47
194
|
declare const toLerpFn: (interval: Interval) => (t: number) => number;
|
|
195
|
+
/**
|
|
196
|
+
* Normalizes a value within an interval.
|
|
197
|
+
*
|
|
198
|
+
* @param interval - The interval to normalize within.
|
|
199
|
+
* @param x - The value to normalize.
|
|
200
|
+
* @returns The normalized value.
|
|
201
|
+
* @since 1.0.0
|
|
202
|
+
*/
|
|
48
203
|
declare const normalize: (interval: Interval, x: number) => number;
|
|
204
|
+
/**
|
|
205
|
+
* Creates a normalization function for an interval.
|
|
206
|
+
*
|
|
207
|
+
* @param interval - The interval to create the normalization function for.
|
|
208
|
+
* @returns A function that takes a value `x` and returns the normalized value.
|
|
209
|
+
* @since 1.0.0
|
|
210
|
+
*/
|
|
49
211
|
declare const toNormalizeFn: (interval: Interval) => (x: number) => number;
|
|
212
|
+
/**
|
|
213
|
+
* Remaps a value from one interval to another.
|
|
214
|
+
*
|
|
215
|
+
* @param source - The source interval.
|
|
216
|
+
* @param target - The target interval.
|
|
217
|
+
* @param x - The value to remap.
|
|
218
|
+
* @returns The remapped value.
|
|
219
|
+
* @since 1.0.0
|
|
220
|
+
*/
|
|
50
221
|
declare const remap: (source: Interval, target: Interval, x: number) => number;
|
|
222
|
+
/**
|
|
223
|
+
* Creates a remapping function for an interval.
|
|
224
|
+
*
|
|
225
|
+
* @param source - The source interval.
|
|
226
|
+
* @param target - The target interval.
|
|
227
|
+
* @returns A function that takes a value `x` and returns the remapped value.
|
|
228
|
+
* @since 1.0.0
|
|
229
|
+
*/
|
|
51
230
|
declare const toRemapFn: (source: Interval, target: Interval) => (x: number) => number;
|
|
231
|
+
/**
|
|
232
|
+
* Calculates the scale and shift needed to map a source interval to a target interval.
|
|
233
|
+
*
|
|
234
|
+
* @param source - The source interval.
|
|
235
|
+
* @param target - The target interval.
|
|
236
|
+
* @returns An object containing the scale and shift values.
|
|
237
|
+
* @since 1.0.0
|
|
238
|
+
*/
|
|
239
|
+
declare const scaleShift: (source: Interval, target: Interval) => ScaleShift;
|
|
240
|
+
/**
|
|
241
|
+
* The scale and shift needed to map a source interval to a target interval.
|
|
242
|
+
*
|
|
243
|
+
* @since 1.0.0
|
|
244
|
+
*/
|
|
52
245
|
interface ScaleShift {
|
|
53
246
|
readonly scale: number;
|
|
54
247
|
readonly shift: number;
|
|
55
248
|
}
|
|
56
|
-
declare const scaleShift: (source: Interval, target: Interval) => ScaleShift;
|
|
57
249
|
|
|
58
|
-
export {
|
|
250
|
+
export { biunit, clamp, contains, filter, fromMinMax, fromSize, isInterval, lerp, make, normalize, remap, scaleShift, size, toLerpFn, toNormalizeFn, toRemapFn, unit };
|
|
251
|
+
export type { Interval, ScaleShift };
|
package/dist/interval.mjs
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { dual, Pipeable } from './pipe.mjs';
|
|
2
2
|
import { round } from './utils.mjs';
|
|
3
3
|
|
|
4
|
+
var _a;
|
|
4
5
|
const TypeId = Symbol.for("curvy/interval");
|
|
5
6
|
class IntervalImpl extends Pipeable {
|
|
6
|
-
[TypeId] = TypeId;
|
|
7
|
-
start;
|
|
8
|
-
end;
|
|
9
7
|
constructor(start = 0, end = start) {
|
|
10
8
|
super();
|
|
9
|
+
this[_a] = TypeId;
|
|
11
10
|
if (end < start) {
|
|
12
11
|
throw new Error("Interval end must be greater than or equal to start");
|
|
13
12
|
}
|
|
14
13
|
this.start = round(start);
|
|
15
14
|
this.end = round(end);
|
|
16
15
|
}
|
|
17
|
-
get [Symbol.toStringTag]() {
|
|
16
|
+
get [(_a = TypeId, Symbol.toStringTag)]() {
|
|
18
17
|
return `Interval [${this.start}, ${this.end}]`;
|
|
19
18
|
}
|
|
20
19
|
get [Symbol.for("nodejs.util.inspect.custom")]() {
|
|
@@ -41,15 +40,12 @@ const filter$1 = dual(
|
|
|
41
40
|
return value.filter((v) => contains$1(interval, v, options));
|
|
42
41
|
}
|
|
43
42
|
);
|
|
44
|
-
const clamp$1 = dual(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (Array.isArray(value)) {
|
|
48
|
-
return value.map((v) => clamp$1(interval, v));
|
|
49
|
-
}
|
|
50
|
-
return contains$1(interval, value) ? value : value < interval.start ? interval.start : interval.end;
|
|
43
|
+
const clamp$1 = dual(2, (interval, value) => {
|
|
44
|
+
if (Array.isArray(value)) {
|
|
45
|
+
return value.map((v) => clamp$1(interval, v));
|
|
51
46
|
}
|
|
52
|
-
);
|
|
47
|
+
return contains$1(interval, value) ? value : value < interval.start ? interval.start : interval.end;
|
|
48
|
+
});
|
|
53
49
|
const unit$1 = make$1(0, 1);
|
|
54
50
|
const biunit$1 = make$1(-1, 1);
|
|
55
51
|
const lerp$1 = (interval, t) => (1 - t) * interval.start + t * interval.end;
|
|
@@ -87,3 +83,4 @@ const toRemapFn = toRemapFn$1;
|
|
|
87
83
|
const scaleShift = scaleShift$1;
|
|
88
84
|
|
|
89
85
|
export { biunit, clamp, contains, filter, fromMinMax, fromSize, isInterval, lerp, make, normalize, remap, scaleShift, size, toLerpFn, toNormalizeFn, toRemapFn, unit };
|
|
86
|
+
//# sourceMappingURL=interval.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interval.mjs","sources":["../src/interval.internal.ts","../src/interval.ts"],"sourcesContent":["import type { Interval } from './interval'\nimport { Pipeable } from './pipe'\nimport { dual } from './pipe'\nimport { round } from './utils'\n\nconst TypeId: unique symbol = Symbol.for('curvy/interval')\ntype TypeId = typeof TypeId\n\nclass IntervalImpl extends Pipeable implements Interval {\n readonly [TypeId]: TypeId = TypeId\n\n readonly start: number\n readonly end: number\n\n constructor(start = 0, end = start) {\n super()\n\n if (end < start) {\n throw new Error('Interval end must be greater than or equal to start')\n }\n\n this.start = round(start)\n this.end = round(end)\n }\n\n get [Symbol.toStringTag]() {\n return `Interval [${this.start}, ${this.end}]`\n }\n\n get [Symbol.for('nodejs.util.inspect.custom')]() {\n return this[Symbol.toStringTag]\n }\n}\n\nexport const isInterval = (v: unknown): v is Interval =>\n typeof v === 'object' && v !== null && TypeId in v\n\nexport const make = (start: number, end?: number) => new IntervalImpl(start, end ?? start)\n\nexport const fromSize = (a: number, b?: number) => {\n if (b === undefined) {\n return new IntervalImpl(0, a)\n }\n return new IntervalImpl(a, a + b)\n}\n\nexport const fromMinMax = (...values: ReadonlyArray<number>) =>\n new IntervalImpl(Math.min(...values), Math.max(...values))\n\nexport const size = (i: Interval) => Math.abs(i.end - i.start)\n\nexport const contains = dual<\n (\n value: number,\n options?: { includeStart?: boolean; includeEnd?: boolean },\n ) => (interval: Interval) => boolean,\n (\n interval: Interval,\n value: number,\n options?: { includeStart?: boolean; includeEnd?: boolean },\n ) => boolean\n>(\n (args) => isInterval(args[0]),\n (interval: Interval, value: number, { includeStart = true, includeEnd = true } = {}) =>\n (value > interval.start && value < interval.end) ||\n (includeStart && value === interval.start) ||\n (includeEnd && value === interval.end),\n)\n\nexport const filter = dual<\n <V extends ReadonlyArray<number>>(\n value: V,\n options?: { includeStart?: boolean; includeEnd?: boolean },\n ) => (interval: Interval) => V,\n <V extends ReadonlyArray<number>>(\n interval: Interval,\n value: V,\n options?: { includeStart?: boolean; includeEnd?: boolean },\n ) => V\n>(\n (args) => isInterval(args[0]),\n <V extends ReadonlyArray<number>>(\n interval: Interval,\n value: V,\n options?: { includeStart?: boolean; includeEnd?: boolean },\n ): V => {\n return value.filter((v) => contains(interval, v, options)) as unknown as V\n },\n)\n\nexport const clamp = dual<\n <V extends number | ReadonlyArray<number>>(value: V) => (interval: Interval) => V,\n <V extends number | ReadonlyArray<number>>(interval: Interval, value: V) => V\n>(2, <V extends number | ReadonlyArray<number>>(interval: Interval, value: V): V => {\n if (Array.isArray(value)) {\n return value.map((v) => clamp(interval, v)) as unknown as V\n }\n\n return (\n contains(interval, value as number)\n ? (value as number)\n : (value as number) < interval.start\n ? interval.start\n : interval.end\n ) as V\n})\n\nexport const unit = make(0, 1)\n\nexport const biunit = make(-1, 1)\n\nexport const lerp = (interval: Interval, t: number) => (1 - t) * interval.start + t * interval.end\n\nexport const toLerpFn = (interval: Interval) => (t: number) => lerp(interval, t)\n\nexport const normalize = (interval: Interval, x: number) => (x - interval.start) / size(interval)\n\nexport const toNormalizeFn = (interval: Interval) => (x: number) => normalize(interval, x)\n\nexport const remap = (source: Interval, target: Interval, x: number) => {\n return target.start + ((x - source.start) * size(target)) / size(source)\n}\n\nexport const toRemapFn = (source: Interval, target: Interval) => (x: number) =>\n remap(source, target, x)\n\nexport const scaleShift = (source: Interval, target: Interval) => {\n const scale = size(target) / size(source)\n\n return {\n scale,\n shift: target.start - source.start * scale,\n }\n}\n","import * as internal from './interval.internal'\nimport type { Pipeable } from './pipe'\n\n/**\n * A mathematical interval.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 1.0.0\n */\nexport interface Interval extends Pipeable {\n readonly start: number\n readonly end: number\n}\n\n/**\n * Checks if a value is an `Interval`.\n *\n * @param v - The value to check.\n * @returns `true` if the value is an `Interval`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isInterval: (v: unknown) => v is Interval = internal.isInterval\n\nexport const make: {\n /**\n * Creates a new `Interval` instance.\n *\n * @param point - The point of the interval.\n * @returns A new `Interval` instance.\n * @since 1.0.0\n */\n (point: number): Interval\n /**\n * Creates a new `Interval` instance.\n *\n * @param start - The start of the interval.\n * @param end - The end of the interval.\n * @returns A new `Interval` instance.\n * @since 1.0.0\n */\n (start: number, end: number): Interval\n} = internal.make\n\nexport const fromSize: {\n /**\n * Creates a new `Interval` instance from a size.\n *\n * @param size - The size of the interval.\n * @returns A new `Interval` instance.\n * @since 1.0.0\n */\n (size: number): Interval\n /**\n * Creates a new `Interval` instance from a size.\n *\n * @param size - The size of the interval.\n * @param start - The start of the interval.\n * @returns A new `Interval` instance.\n * @since 1.0.0\n */\n (start: number, size: number): Interval\n} = internal.fromSize\n\n/**\n * Creates a new `Interval` instance from a minimum and maximum value.\n *\n * @param values - The minimum and maximum values of the interval.\n * @returns A new `Interval` instance.\n * @since 1.0.0\n */\nexport const fromMinMax: (...values: ReadonlyArray<number>) => Interval = internal.fromMinMax\n\n/**\n * Calculates the size of an interval.\n *\n * @param interval - The interval to calculate the size of.\n * @returns The size of the interval.\n * @since 1.0.0\n */\nexport const size: (i: Interval) => number = internal.size\n\nexport const contains: {\n /**\n * Checks if a value is contained within an interval.\n *\n * @param interval - The interval to check.\n * @param value - The value to check.\n * @param options - Options for the check.\n * @returns `true` if the value is contained within the interval, `false` otherwise.\n * @since 1.0.0\n */\n (\n interval: Interval,\n value: number,\n options?: { includeStart?: boolean; includeEnd?: boolean },\n ): boolean\n /**\n * Checks if a value is contained within an interval.\n *\n * @param value - The value to check.\n * @param options - Options for the check.\n * @returns A function that takes an interval and returns `true` if the value is contained within the interval, `false` otherwise.\n * @since 1.0.0\n */\n (\n value: number,\n options?: { includeStart?: boolean; includeEnd?: boolean },\n ): (interval: Interval) => boolean\n} = internal.contains\n\nexport const filter: {\n /**\n * Filters a value to be within an interval.\n *\n * @param interval - The interval to filter the value to.\n * @param value - The value to filter.\n * @param options - Options for the filter.\n * @returns The filtered value.\n * @since 1.0.0\n */\n <V extends ReadonlyArray<number>>(\n interval: Interval,\n value: V,\n options?: { includeStart?: boolean; includeEnd?: boolean },\n ): V\n /**\n * Filters a value to be within an interval.\n *\n * @param value - The value to filter.\n * @param options - Options for the filter.\n * @returns A function that takes an interval and returns the filtered value.\n * @since 1.0.0\n */\n <V extends ReadonlyArray<number>>(\n value: V,\n options?: { includeStart?: boolean; includeEnd?: boolean },\n ): (interval: Interval) => V\n} = internal.filter\n\nexport const clamp: {\n /**\n * Clamps a value to be within an interval.\n *\n * @param interval - The interval to clamp the value to.\n * @param value - The value to clamp.\n * @returns The clamped value.\n * @since 1.0.0\n */\n (interval: Interval, value: number): number\n /**\n * Clamps a value to be within an interval.\n *\n * @param value - The value to clamp.\n * @returns A function that takes an interval and returns the clamped value.\n * @since 1.0.0\n */\n (value: number): (interval: Interval) => number\n /**\n * Clamps an array of values to be within an interval.\n *\n * @param interval - The interval to clamp the values to.\n * @param value - The values to clamp.\n * @returns The clamped values.\n * @since 1.0.0\n */\n (interval: Interval, value: ReadonlyArray<number>): ReadonlyArray<number>\n /**\n * Clamps an array of values to be within an interval.\n *\n * @param value - The values to clamp.\n * @returns A function that takes an interval and returns the clamped values.\n * @since 1.0.0\n */\n (value: ReadonlyArray<number>): (interval: Interval) => ReadonlyArray<number>\n} = internal.clamp\n\n/**\n * The unit interval, which is the interval [0, 1].\n *\n * @since 1.0.0\n */\nexport const unit: Interval = internal.unit\n\n/**\n * The biunit interval, which is the interval [-1, 1].\n *\n * @since 1.0.0\n */\nexport const biunit: Interval = internal.biunit\n\n/**\n * Linearly interpolates a value within an interval.\n *\n * @param interval - The interval to interpolate within.\n * @param t - The interpolation factor, typically between 0 and 1.\n * @returns The interpolated value.\n * @since 1.0.0\n */\nexport const lerp: (interval: Interval, t: number) => number = internal.lerp\n\n/**\n * Creates a linear interpolation function for an interval.\n *\n * @param interval - The interval to create the interpolation function for.\n * @returns A function that takes a factor `t` and returns the interpolated value.\n * @since 1.0.0\n */\nexport const toLerpFn: (interval: Interval) => (t: number) => number = internal.toLerpFn\n\n/**\n * Normalizes a value within an interval.\n *\n * @param interval - The interval to normalize within.\n * @param x - The value to normalize.\n * @returns The normalized value.\n * @since 1.0.0\n */\nexport const normalize: (interval: Interval, x: number) => number = internal.normalize\n\n/**\n * Creates a normalization function for an interval.\n *\n * @param interval - The interval to create the normalization function for.\n * @returns A function that takes a value `x` and returns the normalized value.\n * @since 1.0.0\n */\nexport const toNormalizeFn: (interval: Interval) => (x: number) => number = internal.toNormalizeFn\n\n/**\n * Remaps a value from one interval to another.\n *\n * @param source - The source interval.\n * @param target - The target interval.\n * @param x - The value to remap.\n * @returns The remapped value.\n * @since 1.0.0\n */\nexport const remap: (source: Interval, target: Interval, x: number) => number = internal.remap\n\n/**\n * Creates a remapping function for an interval.\n *\n * @param source - The source interval.\n * @param target - The target interval.\n * @returns A function that takes a value `x` and returns the remapped value.\n * @since 1.0.0\n */\nexport const toRemapFn: (source: Interval, target: Interval) => (x: number) => number =\n internal.toRemapFn\n\n/**\n * Calculates the scale and shift needed to map a source interval to a target interval.\n *\n * @param source - The source interval.\n * @param target - The target interval.\n * @returns An object containing the scale and shift values.\n * @since 1.0.0\n */\nexport const scaleShift: (source: Interval, target: Interval) => ScaleShift = internal.scaleShift\n\n/**\n * The scale and shift needed to map a source interval to a target interval.\n *\n * @since 1.0.0\n */\nexport interface ScaleShift {\n readonly scale: number\n readonly shift: number\n}\n"],"names":["isInterval","make","fromSize","fromMinMax","size","contains","filter","clamp","unit","biunit","lerp","toLerpFn","normalize","toNormalizeFn","remap","toRemapFn","scaleShift","internal.isInterval","internal.make","internal.fromSize","internal.fromMinMax","internal.size","internal.contains","internal.filter","internal.clamp","internal.unit","internal.biunit","internal.lerp","internal.toLerpFn","internal.normalize","internal.toNormalizeFn","internal.remap","internal.toRemapFn","internal.scaleShift"],"mappings":"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"}
|
|
@@ -5,45 +5,316 @@ import { Vector2 } from '../vector/vector2.mjs';
|
|
|
5
5
|
declare const Matrix2x2TypeId: unique symbol;
|
|
6
6
|
type Matrix2x2TypeId = typeof Matrix2x2TypeId;
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* A type representing the coordinate of a 2D matrix.
|
|
10
|
+
*
|
|
11
|
+
* @since 1.0.0
|
|
12
|
+
*/
|
|
8
13
|
type Matrix2x2Coordinate = TwoDimensionalIndex | TwoDimensionalComponent;
|
|
14
|
+
/**
|
|
15
|
+
* A 2D matrix with 2 rows and 2 columns.
|
|
16
|
+
*
|
|
17
|
+
* All fields are readonly and immutable, and all operations create new instances.
|
|
18
|
+
*
|
|
19
|
+
* @since 1.0.0
|
|
20
|
+
*/
|
|
9
21
|
interface Matrix2x2 extends Pipeable {
|
|
10
22
|
readonly [Matrix2x2TypeId]: Matrix2x2TypeId;
|
|
23
|
+
/**
|
|
24
|
+
* The value in the first row and first column.
|
|
25
|
+
*/
|
|
11
26
|
readonly m00: number;
|
|
27
|
+
/**
|
|
28
|
+
* The value in the first row and second column.
|
|
29
|
+
*/
|
|
12
30
|
readonly m01: number;
|
|
31
|
+
/**
|
|
32
|
+
* The value in the second row and first column.
|
|
33
|
+
*/
|
|
13
34
|
readonly m10: number;
|
|
35
|
+
/**
|
|
36
|
+
* The value in the second row and second column.
|
|
37
|
+
*/
|
|
14
38
|
readonly m11: number;
|
|
15
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Checks if a value is a `Matrix2x2`.
|
|
42
|
+
*
|
|
43
|
+
* @param m - The value to check.
|
|
44
|
+
* @returns `true` if the value is a `Matrix2x2`, `false` otherwise.
|
|
45
|
+
* @since 1.0.0
|
|
46
|
+
*/
|
|
16
47
|
declare const isMatrix2x2: (m: unknown) => m is Matrix2x2;
|
|
17
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Creates a new `Matrix2x2` instance.
|
|
50
|
+
*
|
|
51
|
+
* @param m00 - The value in the first row and first column. Defaults to 0.
|
|
52
|
+
* @param m01 - The value in the first row and second column. Defaults to 0.
|
|
53
|
+
* @param m10 - The value in the second row and first column. Defaults to 0.
|
|
54
|
+
* @param m11 - The value in the second row and second column. Defaults to 0.
|
|
55
|
+
*/
|
|
56
|
+
declare const make: (m00?: number, m01?: number, m10?: number, m11?: number) => Matrix2x2;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new `Matrix2x2` instance from two vectors representing rows.
|
|
59
|
+
*
|
|
60
|
+
* @param v0 - The first row vector.
|
|
61
|
+
* @param v1 - The second row vector.
|
|
62
|
+
* @returns A new `Matrix2x2` instance.
|
|
63
|
+
* @since 1.0.0
|
|
64
|
+
*/
|
|
18
65
|
declare const fromRows: (v0: Vector2, v1: Vector2) => Matrix2x2;
|
|
66
|
+
/**
|
|
67
|
+
* Creates a new `Matrix2x2` instance from two vectors representing columns.
|
|
68
|
+
*
|
|
69
|
+
* @param v0 - The first column vector.
|
|
70
|
+
* @param v1 - The second column vector.
|
|
71
|
+
* @returns A new `Matrix2x2` instance.
|
|
72
|
+
* @since 1.0.0
|
|
73
|
+
*/
|
|
19
74
|
declare const fromColumns: (v0: Vector2, v1: Vector2) => Matrix2x2;
|
|
20
75
|
declare const setRow: {
|
|
76
|
+
/**
|
|
77
|
+
* Sets the specified row of the matrix to the given vector.
|
|
78
|
+
*
|
|
79
|
+
* @param m - The matrix to modify.
|
|
80
|
+
* @param row - The row index (0 or 1).
|
|
81
|
+
* @param v - The vector to set the row to.
|
|
82
|
+
* @returns A new `Matrix2x2` instance with the specified row set to the given vector.
|
|
83
|
+
* @since 1.0.0
|
|
84
|
+
*/
|
|
21
85
|
(m: Matrix2x2, row: Matrix2x2Coordinate, v: Vector2): Matrix2x2;
|
|
86
|
+
/**
|
|
87
|
+
* Sets the specified row of the matrix to the given vector.
|
|
88
|
+
*
|
|
89
|
+
* @param row - The row index (0 or 1).
|
|
90
|
+
* @param v - The vector to set the row to.
|
|
91
|
+
* @returns A function that takes a matrix and returns a new `Matrix2x2` instance with the specified row set to the given vector.
|
|
92
|
+
* @since 1.0.0
|
|
93
|
+
*/
|
|
22
94
|
(row: Matrix2x2Coordinate, v: Vector2): (m: Matrix2x2) => Matrix2x2;
|
|
23
95
|
};
|
|
24
96
|
declare const setColumn: {
|
|
97
|
+
/**
|
|
98
|
+
* Sets the specified column of the matrix to the given vector.
|
|
99
|
+
*
|
|
100
|
+
* @param m - The matrix to modify.
|
|
101
|
+
* @param column - The column index (0 or 1).
|
|
102
|
+
* @param v - The vector to set the column to.
|
|
103
|
+
* @returns A new `Matrix2x2` instance with the specified column set to the given vector.
|
|
104
|
+
* @since 1.0.0
|
|
105
|
+
*/
|
|
25
106
|
(m: Matrix2x2, column: Matrix2x2Coordinate, v: Vector2): Matrix2x2;
|
|
107
|
+
/**
|
|
108
|
+
* Sets the specified column of the matrix to the given vector.
|
|
109
|
+
*
|
|
110
|
+
* @param column - The column index (0 or 1).
|
|
111
|
+
* @param v - The vector to set the column to.
|
|
112
|
+
* @returns A function that takes a matrix and returns a new `Matrix2x2` instance with the specified column set to the given vector.
|
|
113
|
+
* @since 1.0.0
|
|
114
|
+
*/
|
|
26
115
|
(column: Matrix2x2Coordinate, v: Vector2): (m: Matrix2x2) => Matrix2x2;
|
|
27
116
|
};
|
|
117
|
+
/**
|
|
118
|
+
* Calculates the determinant of a 2D matrix.
|
|
119
|
+
*
|
|
120
|
+
* @param m - The matrix to calculate the determinant for.
|
|
121
|
+
* @returns The determinant of the matrix.
|
|
122
|
+
* @since 1.0.0
|
|
123
|
+
*/
|
|
28
124
|
declare const determinant: (m: Matrix2x2) => number;
|
|
29
125
|
declare const vectorProductLeft: {
|
|
126
|
+
/**
|
|
127
|
+
* Calculates the left vector product of a matrix and a vector.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* import * as Matrix2x2 from 'curvy/matrix2x2'
|
|
132
|
+
* import * as Vector2 from 'curvy/vector2'
|
|
133
|
+
*
|
|
134
|
+
* const matrix = Matrix2x2.make(1, 2, 3, 4)
|
|
135
|
+
* const vector = Vector2.make(5, 6)
|
|
136
|
+
*
|
|
137
|
+
* // Performs:
|
|
138
|
+
* // x = 1 * 5 + 2 * 6 = 17
|
|
139
|
+
* // y = 3 * 5 + 4 * 6 = 39
|
|
140
|
+
* const result = Matrix2x2.vectorProductLeft(matrix, vector)
|
|
141
|
+
* ```
|
|
142
|
+
* @param m - The matrix to multiply.
|
|
143
|
+
* @param v - The vector to multiply.
|
|
144
|
+
* @returns The resulting vector after the left vector product.
|
|
145
|
+
* @since 1.0.0
|
|
146
|
+
*/
|
|
30
147
|
(m: Matrix2x2, v: Vector2): Vector2;
|
|
148
|
+
/**
|
|
149
|
+
* Calculates the left vector product of a matrix and a vector.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* import * as Matrix2x2 from 'curvy/matrix2x2'
|
|
154
|
+
* import * as Vector2 from 'curvy/vector2'
|
|
155
|
+
*
|
|
156
|
+
* const matrix = Matrix2x2.make(1, 2, 3, 4)
|
|
157
|
+
* const vector = Vector2.make(5, 6)
|
|
158
|
+
*
|
|
159
|
+
* // Performs:
|
|
160
|
+
* // x = 1 * 5 + 2 * 6 = 17
|
|
161
|
+
* // y = 3 * 5 + 4 * 6 = 39
|
|
162
|
+
* const result = Matrix2x2.vectorProductLeft(vector)(matrix)
|
|
163
|
+
* ```
|
|
164
|
+
* @param v - The vector to multiply.
|
|
165
|
+
* @returns A function that takes a matrix and returns the resulting vector after the left vector product.
|
|
166
|
+
* @since 1.0.0
|
|
167
|
+
*/
|
|
31
168
|
(v: Vector2): (m: Matrix2x2) => Vector2;
|
|
32
169
|
};
|
|
33
170
|
declare const vectorProductRight: {
|
|
171
|
+
/**
|
|
172
|
+
* Calculates the right vector product of a matrix and a vector.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* import * as Matrix2x2 from 'curvy/matrix2x2'
|
|
177
|
+
* import * as Vector2 from 'curvy/vector2'
|
|
178
|
+
*
|
|
179
|
+
* const matrix = Matrix2x2.make(1, 2, 3, 4)
|
|
180
|
+
* const vector = Vector2.make(5, 6)
|
|
181
|
+
*
|
|
182
|
+
* // Performs:
|
|
183
|
+
* // x = 1 * 5 + 3 * 6 = 33
|
|
184
|
+
* // y = 2 * 5 + 4 * 6 = 62
|
|
185
|
+
* const result = Matrix2x2.vectorProductRight(matrix, vector)
|
|
186
|
+
* ```
|
|
187
|
+
* @param m - The matrix to multiply.
|
|
188
|
+
* @param v - The vector to multiply.
|
|
189
|
+
* @returns The resulting vector after the right vector product.
|
|
190
|
+
* @since 1.0.0
|
|
191
|
+
*/
|
|
34
192
|
(m: Matrix2x2, v: Vector2): Vector2;
|
|
193
|
+
/**
|
|
194
|
+
* Calculates the right vector product of a matrix and a vector.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* import * as Matrix2x2 from 'curvy/matrix2x2'
|
|
199
|
+
* import * as Vector2 from 'curvy/vector2'
|
|
200
|
+
*
|
|
201
|
+
* const matrix = Matrix2x2.make(1, 2, 3, 4)
|
|
202
|
+
* const vector = Vector2.make(5, 6)
|
|
203
|
+
*
|
|
204
|
+
* // Performs:
|
|
205
|
+
* // x = 1 * 5 + 3 * 6 = 33
|
|
206
|
+
* // y = 2 * 5 + 4 * 6 = 62
|
|
207
|
+
* const result = Matrix2x2.vectorProductRight(vector)(matrix)
|
|
208
|
+
* ```
|
|
209
|
+
* @param v - The vector to multiply.
|
|
210
|
+
* @returns A function that takes a matrix and returns the resulting vector after the right vector product.
|
|
211
|
+
* @since 1.0.0
|
|
212
|
+
*/
|
|
35
213
|
(v: Vector2): (m: Matrix2x2) => Vector2;
|
|
36
214
|
};
|
|
37
215
|
declare const solveSystem: {
|
|
216
|
+
/**
|
|
217
|
+
* Solves a system of linear equations represented by a matrix and a vector.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* import * as Matrix2x2 from 'curvy/matrix2x2'
|
|
222
|
+
* import * as Vector2 from 'curvy/vector2'
|
|
223
|
+
*
|
|
224
|
+
* const matrix = Matrix2x2.make(1, 2, 3, 4)
|
|
225
|
+
* const vector = Vector2.make(5, 6)
|
|
226
|
+
*
|
|
227
|
+
* // Solves the system of equations:
|
|
228
|
+
* // 1x + 2y = 5
|
|
229
|
+
* // 3x + 4y = 6
|
|
230
|
+
* const result = Matrix2x2.solveSystem(matrix, vector)
|
|
231
|
+
* ```
|
|
232
|
+
* @param m - The matrix representing the coefficients of the system.
|
|
233
|
+
* @param v - The vector representing the constants of the system.
|
|
234
|
+
* @returns The solution vector.
|
|
235
|
+
* @since 1.0.0
|
|
236
|
+
*/
|
|
38
237
|
(m: Matrix2x2, v: Vector2): Vector2;
|
|
238
|
+
/**
|
|
239
|
+
* Solves a system of linear equations represented by a matrix and a vector.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* import * as Matrix2x2 from 'curvy/matrix2x2'
|
|
244
|
+
* import * as Vector2 from 'curvy/vector2'
|
|
245
|
+
*
|
|
246
|
+
* const matrix = Matrix2x2.make(1, 2, 3, 4)
|
|
247
|
+
* const vector = Vector2.make(5, 6)
|
|
248
|
+
*
|
|
249
|
+
* // Solves the system of equations:
|
|
250
|
+
* // 1x + 2y = 5
|
|
251
|
+
* // 3x + 4y = 6
|
|
252
|
+
* const result = Matrix2x2.solveSystem(vector)(matrix)
|
|
253
|
+
* ```
|
|
254
|
+
* @param v - The vector representing the constants of the system.
|
|
255
|
+
* @returns A function that takes a matrix and returns the solution vector.
|
|
256
|
+
* @since 1.0.0
|
|
257
|
+
*/
|
|
39
258
|
(v: Vector2): (m: Matrix2x2) => Vector2;
|
|
40
259
|
};
|
|
260
|
+
/**
|
|
261
|
+
* Returns the rows of a matrix as an array of vectors.
|
|
262
|
+
*
|
|
263
|
+
* @param m - The matrix to convert.
|
|
264
|
+
* @returns An array of vectors representing the rows of the matrix.
|
|
265
|
+
* @since 1.0.0
|
|
266
|
+
*/
|
|
41
267
|
declare const toRows: (m: Matrix2x2) => [Vector2, Vector2];
|
|
268
|
+
/**
|
|
269
|
+
* Returns the columns of a matrix as an array of vectors.
|
|
270
|
+
*
|
|
271
|
+
* @param m - The matrix to convert.
|
|
272
|
+
* @returns An array of vectors representing the columns of the matrix.
|
|
273
|
+
* @since 1.0.0
|
|
274
|
+
*/
|
|
42
275
|
declare const toColumns: (m: Matrix2x2) => [Vector2, Vector2];
|
|
276
|
+
/**
|
|
277
|
+
* Returns the specified row of a matrix as a vector.
|
|
278
|
+
*
|
|
279
|
+
* @param m - The matrix to get the row from.
|
|
280
|
+
* @param row - The row index (0 or 1).
|
|
281
|
+
* @returns A vector representing the specified row of the matrix.
|
|
282
|
+
* @since 1.0.0
|
|
283
|
+
*/
|
|
43
284
|
declare const rowVector: (m: Matrix2x2, row: Matrix2x2Coordinate) => Vector2;
|
|
285
|
+
/**
|
|
286
|
+
* Returns the specified column of a matrix as a vector.
|
|
287
|
+
*
|
|
288
|
+
* @param m - The matrix to get the column from.
|
|
289
|
+
* @param column - The column index (0 or 1).
|
|
290
|
+
* @returns A vector representing the specified column of the matrix.
|
|
291
|
+
* @since 1.0.0
|
|
292
|
+
*/
|
|
44
293
|
declare const columnVector: (m: Matrix2x2, column: Matrix2x2Coordinate) => Vector2;
|
|
294
|
+
/**
|
|
295
|
+
* Transposes a matrix.
|
|
296
|
+
*
|
|
297
|
+
* @param m - The matrix to transpose.
|
|
298
|
+
* @returns A new `Matrix2x2` instance representing the transposed matrix.
|
|
299
|
+
* @since 1.0.0
|
|
300
|
+
*/
|
|
45
301
|
declare const transpose: (m: Matrix2x2) => Matrix2x2;
|
|
302
|
+
/**
|
|
303
|
+
* Reverses the rows of a matrix.
|
|
304
|
+
*
|
|
305
|
+
* @param m - The matrix to reverse the rows of.
|
|
306
|
+
* @returns A new `Matrix2x2` instance with the rows reversed.
|
|
307
|
+
* @since 1.0.0
|
|
308
|
+
*/
|
|
46
309
|
declare const reverseRows: (m: Matrix2x2) => Matrix2x2;
|
|
310
|
+
/**
|
|
311
|
+
* Reverses the columns of a matrix.
|
|
312
|
+
*
|
|
313
|
+
* @param m - The matrix to reverse the columns of.
|
|
314
|
+
* @returns A new `Matrix2x2` instance with the columns reversed.
|
|
315
|
+
* @since 1.0.0
|
|
316
|
+
*/
|
|
47
317
|
declare const reverseColumns: (m: Matrix2x2) => Matrix2x2;
|
|
48
318
|
|
|
49
|
-
export {
|
|
319
|
+
export { columnVector, determinant, fromColumns, fromRows, isMatrix2x2, make, reverseColumns, reverseRows, rowVector, setColumn, setRow, solveSystem, toColumns, toRows, transpose, vectorProductLeft, vectorProductRight };
|
|
320
|
+
export type { Matrix2x2, Matrix2x2Coordinate };
|