curvy 0.3.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/LICENSE.md +21 -0
  2. package/dist/curve/cubic2d.d.mts +27 -0
  3. package/dist/curve/cubic2d.d.ts +27 -0
  4. package/dist/curve/cubic2d.mjs +85 -0
  5. package/dist/curve/linear2d.d.mts +27 -0
  6. package/dist/curve/linear2d.d.ts +27 -0
  7. package/dist/curve/linear2d.mjs +46 -0
  8. package/dist/curve/quadratic2d.d.mts +27 -0
  9. package/dist/curve/quadratic2d.d.ts +27 -0
  10. package/dist/curve/quadratic2d.mjs +74 -0
  11. package/dist/interval.d.mts +58 -0
  12. package/dist/interval.d.ts +58 -0
  13. package/dist/interval.mjs +88 -0
  14. package/dist/matrix/matrix2x2.d.mts +49 -0
  15. package/dist/matrix/matrix2x2.d.ts +49 -0
  16. package/dist/matrix/matrix2x2.mjs +23 -0
  17. package/dist/matrix/matrix3x3.d.mts +63 -0
  18. package/dist/matrix/matrix3x3.d.ts +63 -0
  19. package/dist/matrix/matrix3x3.mjs +26 -0
  20. package/dist/matrix/matrix4x4.d.mts +72 -0
  21. package/dist/matrix/matrix4x4.d.ts +72 -0
  22. package/dist/matrix/matrix4x4.mjs +214 -0
  23. package/dist/path/cubic2d.d.mts +29 -0
  24. package/dist/path/cubic2d.d.ts +29 -0
  25. package/dist/path/cubic2d.mjs +60 -0
  26. package/dist/path/linear2d.d.mts +29 -0
  27. package/dist/path/linear2d.d.ts +29 -0
  28. package/dist/path/linear2d.mjs +54 -0
  29. package/dist/path/quadratic2d.d.mts +29 -0
  30. package/dist/path/quadratic2d.d.ts +29 -0
  31. package/dist/path/quadratic2d.mjs +60 -0
  32. package/dist/polynomial/cubic.d.mts +7 -0
  33. package/dist/polynomial/cubic.d.ts +7 -0
  34. package/dist/polynomial/cubic.mjs +139 -0
  35. package/dist/polynomial/linear.d.mts +7 -0
  36. package/dist/polynomial/linear.d.ts +7 -0
  37. package/dist/polynomial/linear.mjs +19 -0
  38. package/dist/polynomial/quadratic.d.mts +7 -0
  39. package/dist/polynomial/quadratic.d.ts +7 -0
  40. package/dist/polynomial/quadratic.mjs +22 -0
  41. package/dist/shared/curvy.BAW_cKLu.mjs +123 -0
  42. package/dist/shared/curvy.BN-oFBsc.d.mts +26 -0
  43. package/dist/shared/curvy.BN-oFBsc.d.ts +26 -0
  44. package/dist/shared/curvy.Bxxwly94.d.mts +144 -0
  45. package/dist/shared/curvy.C-sUk7ux.mjs +119 -0
  46. package/dist/shared/curvy.CLzGuqek.mjs +124 -0
  47. package/dist/shared/curvy.CO0Wclt0.d.ts +144 -0
  48. package/dist/shared/curvy.CT38g_II.d.mts +22 -0
  49. package/dist/shared/curvy.CT38g_II.d.ts +22 -0
  50. package/dist/shared/curvy.ChkqgKuv.mjs +119 -0
  51. package/dist/shared/curvy.Cty3LrOR.mjs +70 -0
  52. package/dist/shared/curvy.D7bhnwZy.mjs +52 -0
  53. package/dist/shared/curvy.DOLqYbKE.mjs +48 -0
  54. package/dist/shared/curvy.DgRsieUW.mjs +76 -0
  55. package/dist/shared/curvy.DmVFTi0N.mjs +34 -0
  56. package/dist/splines/bezier2d.d.mts +35 -0
  57. package/dist/splines/bezier2d.d.ts +35 -0
  58. package/dist/splines/bezier2d.mjs +122 -0
  59. package/dist/vector/vector2.d.mts +37 -0
  60. package/dist/vector/vector2.d.ts +37 -0
  61. package/dist/vector/vector2.mjs +16 -0
  62. package/dist/vector/vector3.d.mts +38 -0
  63. package/dist/vector/vector3.d.ts +38 -0
  64. package/dist/vector/vector3.mjs +16 -0
  65. package/dist/vector/vector4.d.mts +39 -0
  66. package/dist/vector/vector4.d.ts +39 -0
  67. package/dist/vector/vector4.mjs +16 -0
  68. package/package.json +78 -37
  69. package/dist/axis.cjs +0 -14
  70. package/dist/axis.d.cts +0 -20
  71. package/dist/axis.d.mts +0 -20
  72. package/dist/axis.d.ts +0 -20
  73. package/dist/axis.mjs +0 -3
  74. package/dist/convert.cjs +0 -74
  75. package/dist/convert.d.cts +0 -6
  76. package/dist/convert.d.mts +0 -6
  77. package/dist/convert.d.ts +0 -6
  78. package/dist/convert.mjs +0 -68
  79. package/dist/curve.cjs +0 -365
  80. package/dist/curve.d.cts +0 -20
  81. package/dist/curve.d.mts +0 -20
  82. package/dist/curve.d.ts +0 -20
  83. package/dist/curve.mjs +0 -354
  84. package/dist/shared/curvy.262f6070.cjs +0 -16
  85. package/dist/shared/curvy.7876e09e.mjs +0 -323
  86. package/dist/shared/curvy.9cd8b44c.mjs +0 -13
  87. package/dist/shared/curvy.db103082.cjs +0 -335
  88. package/dist/shared/curvy.df73166c.d.cts +0 -38
  89. package/dist/shared/curvy.df73166c.d.mts +0 -38
  90. package/dist/shared/curvy.df73166c.d.ts +0 -38
  91. package/dist/splines.cjs +0 -150
  92. package/dist/splines.d.cts +0 -27
  93. package/dist/splines.d.mts +0 -27
  94. package/dist/splines.d.ts +0 -27
  95. package/dist/splines.mjs +0 -138
@@ -1,335 +0,0 @@
1
- 'use strict';
2
-
3
- const invariant = require('tiny-invariant');
4
- const splines = require('../splines.cjs');
5
-
6
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
7
-
8
- const invariant__default = /*#__PURE__*/_interopDefaultCompat(invariant);
9
-
10
- const UNIT_INTERVAL = [0, 1];
11
- function createLinearPolynomial(coefficients, domain = UNIT_INTERVAL) {
12
- const [a, b] = coefficients;
13
- invariant__default(domain[0] <= domain[1], "invalid domain");
14
- let root = a === 0 ? null : b === 0 ? 0 : -b / a;
15
- if (root !== null && (root < domain[0] || root > domain[1])) {
16
- root = null;
17
- }
18
- const range = a >= 0 ? [a * domain[0] + b, a * domain[1] + b] : [a * domain[1] + b, a * domain[0] + b];
19
- const solve = (x) => {
20
- invariant__default(x >= domain[0] && x <= domain[1], "x out of domain");
21
- return a * x + b;
22
- };
23
- const solveInverse = (y) => {
24
- invariant__default(y >= range[0] && y <= range[1], "y out of range");
25
- return a === 0 ? 0 : (y - b) / a;
26
- };
27
- return {
28
- domain,
29
- range,
30
- monotonicity: a === 0 ? "constant" : a > 0 ? "increasing" : "decreasing",
31
- coefficients,
32
- root,
33
- solve,
34
- solveInverse
35
- };
36
- }
37
- function createQuadraticRootSolver(coefficients, defaultDomain, range) {
38
- const [a, b, c] = coefficients;
39
- if (a !== 0) {
40
- return function solveInverse(y, domain = defaultDomain) {
41
- invariant__default(domain[0] <= domain[1], "invalid domain");
42
- invariant__default(y >= range[0] && y <= range[1], "y out of range");
43
- const discriminant = b ** 2 - 4 * a * (c - y);
44
- if (discriminant < 0) {
45
- return [];
46
- }
47
- if (discriminant === 0) {
48
- const root = -b / (2 * a);
49
- return root < domain[0] || root > domain[1] ? [] : [root];
50
- }
51
- const sqrtDiscriminant = Math.sqrt(discriminant);
52
- const denominator = 2 * a;
53
- const left = (-b - sqrtDiscriminant) / denominator;
54
- const right = (-b + sqrtDiscriminant) / denominator;
55
- const leftInDomain = left >= domain[0] && left <= domain[1];
56
- const rightInDomain = right >= domain[0] && right <= domain[1];
57
- if (leftInDomain && rightInDomain) {
58
- return left < right ? [left, right] : [right, left];
59
- }
60
- if (leftInDomain) {
61
- return [left];
62
- }
63
- if (rightInDomain) {
64
- return [right];
65
- }
66
- return [];
67
- };
68
- }
69
- if (b !== 0) {
70
- return function solveInverse(y, domain = defaultDomain) {
71
- invariant__default(domain[0] <= domain[1], "invalid domain");
72
- invariant__default(y >= range[0] && y <= range[1], "y out of range");
73
- const root = -(c - y) / b;
74
- return root < domain[0] || root > domain[1] ? [] : [root];
75
- };
76
- }
77
- return function solveInverse() {
78
- return [];
79
- };
80
- }
81
- function createQuadraticPolynomial(coefficients, domain = UNIT_INTERVAL) {
82
- const [a, b, c] = coefficients;
83
- invariant__default(domain[0] <= domain[1], "invalid domain");
84
- const derivative = createLinearPolynomial([2 * a, b], domain);
85
- const extreme = derivative.root;
86
- const solve = (x) => {
87
- invariant__default(x >= domain[0] && x <= domain[1], "x out of domain");
88
- return a * x ** 2 + b * x + c;
89
- };
90
- const rangeCandidates = extreme === null ? [solve(domain[0]), solve(domain[1])] : [solve(domain[0]), solve(extreme), solve(domain[1])];
91
- const range = [
92
- Math.min(...rangeCandidates),
93
- Math.max(...rangeCandidates)
94
- ];
95
- const solveInverse = createQuadraticRootSolver(coefficients, domain, range);
96
- const roots = range[0] > 0 || range[1] < 0 ? [] : solveInverse(0);
97
- return {
98
- domain,
99
- range,
100
- coefficients,
101
- monotonicity: a !== 0 ? "none" : b === 0 ? "constant" : b > 0 ? "increasing" : "decreasing",
102
- extreme,
103
- roots,
104
- derivative,
105
- solve,
106
- solveInverse
107
- };
108
- }
109
- const TWO_THIRDS_PI = 2 * Math.PI / 3;
110
- function createCubicRootSolver(coefficients, defaultDomain, range) {
111
- if (coefficients[0] === 0) {
112
- return createQuadraticRootSolver(
113
- [coefficients[1], coefficients[2], coefficients[3]],
114
- defaultDomain,
115
- range
116
- );
117
- }
118
- const oneOverA = 1 / coefficients[0];
119
- const a0 = coefficients[1] * oneOverA;
120
- const a1 = coefficients[2] * oneOverA;
121
- const a2OverThree = a0 / 3;
122
- const q = a1 / 3 - a0 ** 2 / 9;
123
- const r0 = a1 * a0 / 6 - a0 ** 3 / 27;
124
- return function solveInverse(y, domain = defaultDomain) {
125
- invariant__default(domain[0] <= domain[1], "invalid domain");
126
- invariant__default(y >= range[0] && y <= range[1], "y out of range");
127
- const a02 = (coefficients[3] - y) * oneOverA;
128
- const r = r0 - a02 * 0.5;
129
- const discriminant = q ** 3 + r ** 2;
130
- if (discriminant > 0) {
131
- const a = Math.cbrt(Math.abs(r) + Math.sqrt(discriminant));
132
- const root = (r < 0 ? q / a - a : a - q / a) - a2OverThree;
133
- return root < domain[0] || root > domain[1] ? [] : [root];
134
- }
135
- const theta = Math.acos(r / Math.sqrt((-q) ** 3)) / 3;
136
- const twoRootQ = 2 * Math.sqrt(-q);
137
- const root1 = twoRootQ * Math.cos(theta - TWO_THIRDS_PI) - a2OverThree;
138
- const root2 = twoRootQ * Math.cos(theta) - a2OverThree;
139
- const root3 = twoRootQ * Math.cos(theta + TWO_THIRDS_PI) - a2OverThree;
140
- const candidates = [root1, root2, root3];
141
- const roots = [];
142
- for (const candidate of candidates) {
143
- if (candidate >= domain[0] && candidate <= domain[1] && !roots.includes(candidate)) {
144
- roots.push(candidate);
145
- }
146
- }
147
- roots.sort((a, b) => a - b);
148
- return roots;
149
- };
150
- }
151
- function getMonotonicity(extrema, derivative, domain) {
152
- if (derivative.coefficients[0] === 0 && derivative.coefficients[1] === 0 && derivative.coefficients[2] === 0) {
153
- return "constant";
154
- }
155
- let hasInnerExtrema = false;
156
- for (const extreme of extrema) {
157
- if (extreme > domain[0] && extreme > domain[1]) {
158
- hasInnerExtrema = true;
159
- break;
160
- }
161
- }
162
- if (hasInnerExtrema) {
163
- return "none";
164
- }
165
- let test = derivative.solve(domain[0]);
166
- if (test === 0) {
167
- test = derivative.solve((domain[0] + domain[1]) * 0.5);
168
- }
169
- return Math.sign(test) > 0 ? "increasing" : "decreasing";
170
- }
171
- function createCubicPolynomial(coefficients, domain = UNIT_INTERVAL) {
172
- invariant__default(domain[0] <= domain[1], "invalid domain");
173
- const [a, b, c, d] = coefficients;
174
- const derivative = createQuadraticPolynomial([3 * a, 2 * b, c], domain);
175
- const extrema = derivative.roots.length === 1 && derivative.coefficients[0] !== 0 ? [] : derivative.roots;
176
- const solve = (x) => {
177
- invariant__default(x >= domain[0] && x <= domain[1], "x out of domain");
178
- return a * x ** 3 + b * x ** 2 + c * x + d;
179
- };
180
- const rangeCandidates = [
181
- solve(domain[0]),
182
- ...extrema.map((extreme) => solve(extreme)),
183
- solve(domain[1])
184
- ];
185
- const range = [
186
- Math.min(...rangeCandidates),
187
- Math.max(...rangeCandidates)
188
- ];
189
- const solveInverse = createCubicRootSolver(coefficients, domain, range);
190
- const roots = range[0] > 0 || range[1] < 0 ? [] : solveInverse(0, domain);
191
- const monotonicity = getMonotonicity(extrema, derivative, domain);
192
- return {
193
- domain,
194
- range,
195
- monotonicity,
196
- coefficients,
197
- extrema,
198
- roots,
199
- derivative,
200
- solve,
201
- solveInverse
202
- };
203
- }
204
- function computeCubicAntiderivative(coefficients, integrationConstant) {
205
- return [
206
- coefficients[0] / 4,
207
- coefficients[1] / 3,
208
- coefficients[2] / 2,
209
- coefficients[3],
210
- integrationConstant
211
- ];
212
- }
213
-
214
- function getCurveExtrema(lookup) {
215
- const extremaLookup = new Map(lookup);
216
- const extremaCandidates = Array.from(extremaLookup.keys());
217
- for (const [index, t] of extremaCandidates.entries()) {
218
- if (index === 0 || index === extremaCandidates.length - 1) {
219
- continue;
220
- }
221
- const previous = extremaLookup.get(extremaCandidates[index - 1]);
222
- const current = extremaLookup.get(t);
223
- const next = extremaLookup.get(extremaCandidates[index + 1]);
224
- if (previous <= current && current < next || previous >= current && current > next) {
225
- extremaLookup.delete(t);
226
- }
227
- }
228
- const extrema = Array.from(extremaLookup.keys());
229
- return extrema;
230
- }
231
- function createCurveAxis(coefficients) {
232
- invariant__default(coefficients.length > 0, "Curve must have at least one segment");
233
- const segments = [];
234
- const extremaLookup = /* @__PURE__ */ new Map();
235
- let monotonicity = "none";
236
- const normalizedToCurve = coefficients.length;
237
- const curveToNormalized = 1 / coefficients.length;
238
- for (let i = 0; i < coefficients.length; i++) {
239
- const segment = createCubicPolynomial(coefficients[i], UNIT_INTERVAL);
240
- segments.push(segment);
241
- extremaLookup.set(i * curveToNormalized, segment.solve(0));
242
- for (const extreme of segment.extrema) {
243
- extremaLookup.set(
244
- (i + extreme) * curveToNormalized,
245
- segment.solve(extreme)
246
- );
247
- }
248
- if (i === 0) {
249
- monotonicity = segment.monotonicity;
250
- } else if (monotonicity !== segment.monotonicity) {
251
- monotonicity = "none";
252
- }
253
- }
254
- extremaLookup.set(1, segments[segments.length - 1].solve(1));
255
- const extrema = getCurveExtrema(extremaLookup);
256
- const range = [
257
- Math.min(...extremaLookup.values()),
258
- Math.max(...extremaLookup.values())
259
- ];
260
- const getSegmentAndInput = (t) => {
261
- invariant__default(t >= 0 && t <= 1, "t out of range");
262
- if (t === 1) {
263
- return { segment: segments[segments.length - 1], input: 1 };
264
- }
265
- const curveT = t * normalizedToCurve;
266
- const index = Math.floor(curveT);
267
- const segment = segments[index];
268
- const input = curveT - index;
269
- return { segment, input };
270
- };
271
- const solvePosition = (t) => {
272
- const { segment, input } = getSegmentAndInput(t);
273
- return segment.solve(input);
274
- };
275
- const solveVelocity = (t) => {
276
- const { segment, input } = getSegmentAndInput(t);
277
- return segment.derivative.solve(input);
278
- };
279
- const solveT = (position, domain) => {
280
- invariant__default(
281
- position >= range[0] && position <= range[1],
282
- "position out of range"
283
- );
284
- invariant__default(domain[0] <= domain[1], "invalid domain");
285
- const result = [];
286
- for (const [index, segment] of segments.entries()) {
287
- if (position >= segment.range[0] && position <= segment.range[1]) {
288
- const t = segment.solveInverse(position, domain);
289
- for (const tValue of t) {
290
- result.push((index + tValue) * curveToNormalized);
291
- }
292
- }
293
- }
294
- return result;
295
- };
296
- return {
297
- domain: UNIT_INTERVAL,
298
- range,
299
- monotonicity,
300
- extrema,
301
- segments,
302
- solvePosition,
303
- solveVelocity,
304
- solveT
305
- };
306
- }
307
- function createBasisAxis(parameters, triplicateEndpoints = true) {
308
- return createCurveAxis(
309
- splines.splines.basis(triplicateEndpoints).chunkCoefficients(parameters)
310
- );
311
- }
312
- function createBezierAxis(parameters) {
313
- return createCurveAxis(splines.splines.bezier.chunkCoefficients(parameters));
314
- }
315
- function createCardinalAxis(parameters, a = 0.5, duplicateEndpoints = true) {
316
- return createCurveAxis(
317
- splines.splines.cardinal(a, duplicateEndpoints).chunkCoefficients(parameters)
318
- );
319
- }
320
- function createCatmullRomAxis(parameters, duplicateEndpoints = true) {
321
- return createCurveAxis(
322
- splines.splines.catmullRom(duplicateEndpoints).chunkCoefficients(parameters)
323
- );
324
- }
325
- function createHermiteAxis(parameters) {
326
- return createCurveAxis(splines.splines.hermite.chunkCoefficients(parameters));
327
- }
328
-
329
- exports.computeCubicAntiderivative = computeCubicAntiderivative;
330
- exports.createBasisAxis = createBasisAxis;
331
- exports.createBezierAxis = createBezierAxis;
332
- exports.createCardinalAxis = createCardinalAxis;
333
- exports.createCatmullRomAxis = createCatmullRomAxis;
334
- exports.createCurveAxis = createCurveAxis;
335
- exports.createHermiteAxis = createHermiteAxis;
@@ -1,38 +0,0 @@
1
- type Monotonicity = 'none' | 'increasing' | 'decreasing' | 'constant';
2
- type Interval = readonly [number, number];
3
- type LinearCoefficients = readonly [number, number];
4
- type LinearPolynomial = {
5
- readonly domain: Interval;
6
- readonly range: Interval;
7
- readonly monotonicity: Monotonicity;
8
- readonly coefficients: LinearCoefficients;
9
- readonly root: number | null;
10
- readonly solve: (x: number) => number;
11
- readonly solveInverse: (y: number) => number;
12
- };
13
- type QuadraticCoefficients = readonly [number, number, number];
14
- type QuadraticPolynomial = {
15
- readonly domain: Interval;
16
- readonly range: Interval;
17
- readonly monotonicity: Monotonicity;
18
- readonly coefficients: QuadraticCoefficients;
19
- readonly extreme: number | null;
20
- readonly roots: ReadonlyArray<number>;
21
- readonly derivative: LinearPolynomial;
22
- readonly solve: (x: number) => number;
23
- readonly solveInverse: (y: number, domain?: Interval) => ReadonlyArray<number>;
24
- };
25
- type CubicCoefficients = readonly [number, number, number, number];
26
- type CubicPolynomial = {
27
- readonly domain: Interval;
28
- readonly range: Interval;
29
- readonly monotonicity: Monotonicity;
30
- readonly coefficients: CubicCoefficients;
31
- readonly extrema: ReadonlyArray<number>;
32
- readonly roots: ReadonlyArray<number>;
33
- readonly derivative: QuadraticPolynomial;
34
- readonly solve: (x: number) => number;
35
- readonly solveInverse: (y: number, domain?: Interval) => ReadonlyArray<number>;
36
- };
37
-
38
- export type { CubicPolynomial as C, Interval as I, Monotonicity as M, CubicCoefficients as a };
@@ -1,38 +0,0 @@
1
- type Monotonicity = 'none' | 'increasing' | 'decreasing' | 'constant';
2
- type Interval = readonly [number, number];
3
- type LinearCoefficients = readonly [number, number];
4
- type LinearPolynomial = {
5
- readonly domain: Interval;
6
- readonly range: Interval;
7
- readonly monotonicity: Monotonicity;
8
- readonly coefficients: LinearCoefficients;
9
- readonly root: number | null;
10
- readonly solve: (x: number) => number;
11
- readonly solveInverse: (y: number) => number;
12
- };
13
- type QuadraticCoefficients = readonly [number, number, number];
14
- type QuadraticPolynomial = {
15
- readonly domain: Interval;
16
- readonly range: Interval;
17
- readonly monotonicity: Monotonicity;
18
- readonly coefficients: QuadraticCoefficients;
19
- readonly extreme: number | null;
20
- readonly roots: ReadonlyArray<number>;
21
- readonly derivative: LinearPolynomial;
22
- readonly solve: (x: number) => number;
23
- readonly solveInverse: (y: number, domain?: Interval) => ReadonlyArray<number>;
24
- };
25
- type CubicCoefficients = readonly [number, number, number, number];
26
- type CubicPolynomial = {
27
- readonly domain: Interval;
28
- readonly range: Interval;
29
- readonly monotonicity: Monotonicity;
30
- readonly coefficients: CubicCoefficients;
31
- readonly extrema: ReadonlyArray<number>;
32
- readonly roots: ReadonlyArray<number>;
33
- readonly derivative: QuadraticPolynomial;
34
- readonly solve: (x: number) => number;
35
- readonly solveInverse: (y: number, domain?: Interval) => ReadonlyArray<number>;
36
- };
37
-
38
- export type { CubicPolynomial as C, Interval as I, Monotonicity as M, CubicCoefficients as a };
@@ -1,38 +0,0 @@
1
- type Monotonicity = 'none' | 'increasing' | 'decreasing' | 'constant';
2
- type Interval = readonly [number, number];
3
- type LinearCoefficients = readonly [number, number];
4
- type LinearPolynomial = {
5
- readonly domain: Interval;
6
- readonly range: Interval;
7
- readonly monotonicity: Monotonicity;
8
- readonly coefficients: LinearCoefficients;
9
- readonly root: number | null;
10
- readonly solve: (x: number) => number;
11
- readonly solveInverse: (y: number) => number;
12
- };
13
- type QuadraticCoefficients = readonly [number, number, number];
14
- type QuadraticPolynomial = {
15
- readonly domain: Interval;
16
- readonly range: Interval;
17
- readonly monotonicity: Monotonicity;
18
- readonly coefficients: QuadraticCoefficients;
19
- readonly extreme: number | null;
20
- readonly roots: ReadonlyArray<number>;
21
- readonly derivative: LinearPolynomial;
22
- readonly solve: (x: number) => number;
23
- readonly solveInverse: (y: number, domain?: Interval) => ReadonlyArray<number>;
24
- };
25
- type CubicCoefficients = readonly [number, number, number, number];
26
- type CubicPolynomial = {
27
- readonly domain: Interval;
28
- readonly range: Interval;
29
- readonly monotonicity: Monotonicity;
30
- readonly coefficients: CubicCoefficients;
31
- readonly extrema: ReadonlyArray<number>;
32
- readonly roots: ReadonlyArray<number>;
33
- readonly derivative: QuadraticPolynomial;
34
- readonly solve: (x: number) => number;
35
- readonly solveInverse: (y: number, domain?: Interval) => ReadonlyArray<number>;
36
- };
37
-
38
- export type { CubicPolynomial as C, Interval as I, Monotonicity as M, CubicCoefficients as a };
package/dist/splines.cjs DELETED
@@ -1,150 +0,0 @@
1
- 'use strict';
2
-
3
- const invariant = require('tiny-invariant');
4
-
5
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
6
-
7
- const invariant__default = /*#__PURE__*/_interopDefaultCompat(invariant);
8
-
9
- function chunkPointsBy(values, stride) {
10
- const chunks = [];
11
- invariant__default(values.length >= 4, "Values must have at least 4 elements");
12
- invariant__default(
13
- stride === 1 || stride === 2 || stride === 3,
14
- "Stride must be 1, 2, or 3"
15
- );
16
- if (stride === 3) {
17
- invariant__default(
18
- values.length % stride === 1,
19
- "Values length must be a multiple of 3 plus 1"
20
- );
21
- } else {
22
- invariant__default(
23
- values.length % stride === 0,
24
- `Values length must be a multiple of ${stride}`
25
- );
26
- }
27
- for (let i = 0; i <= values.length - 4; i += stride) {
28
- chunks.push([
29
- values[i],
30
- values[i + 1],
31
- values[i + 2],
32
- values[i + 3]
33
- ]);
34
- }
35
- return chunks;
36
- }
37
- function pointsToCoefficients(matrix, parameters) {
38
- return [
39
- parameters[0] * matrix[0][0] + parameters[1] * matrix[0][1] + parameters[2] * matrix[0][2] + parameters[3] * matrix[0][3],
40
- parameters[0] * matrix[1][0] + parameters[1] * matrix[1][1] + parameters[2] * matrix[1][2] + parameters[3] * matrix[1][3],
41
- parameters[0] * matrix[2][0] + parameters[1] * matrix[2][1] + parameters[2] * matrix[2][2] + parameters[3] * matrix[2][3],
42
- parameters[0] * matrix[3][0] + parameters[1] * matrix[3][1] + parameters[2] * matrix[3][2] + parameters[3] * matrix[3][3]
43
- ];
44
- }
45
- const bezier = {
46
- matrix: [
47
- [-1, 3, -3, 1],
48
- [3, -6, 3, 0],
49
- [-3, 3, 0, 0],
50
- [1, 0, 0, 0]
51
- ],
52
- chunkCoefficients(parameters) {
53
- const coefficients = [];
54
- for (const chunk of chunkPointsBy(parameters, 3)) {
55
- coefficients.push(pointsToCoefficients(this.matrix, chunk));
56
- }
57
- return coefficients;
58
- }
59
- };
60
- const hermite = {
61
- matrix: [
62
- [2, 1, -2, 1],
63
- [-3, -2, 3, -1],
64
- [0, 1, 0, 0],
65
- [1, 0, 0, 0]
66
- ],
67
- chunkCoefficients(parameters) {
68
- const coefficients = [];
69
- for (const chunk of chunkPointsBy(parameters, 2)) {
70
- coefficients.push(pointsToCoefficients(this.matrix, chunk));
71
- }
72
- return coefficients;
73
- }
74
- };
75
- const cardinal = (a, duplicateEndpoints = true) => ({
76
- matrix: [
77
- [-a, 2 - a, a - 2, a],
78
- [2 * a, a - 3, 3 - 2 * a, -a],
79
- [-a, 0, a, 0],
80
- [0, 1, 0, 0]
81
- ],
82
- chunkCoefficients(parameters) {
83
- const coefficients = [];
84
- for (const chunk of chunkPointsBy(
85
- duplicateEndpoints ? [parameters[0], ...parameters, parameters[parameters.length - 1]] : parameters,
86
- 1
87
- )) {
88
- coefficients.push(pointsToCoefficients(this.matrix, chunk));
89
- }
90
- return coefficients;
91
- }
92
- });
93
- const catmullRom = (duplicateEndpoints = true) => ({
94
- matrix: [
95
- [-0.5, 1.5, -1.5, 0.5],
96
- [1, -2.5, 2, -0.5],
97
- [-0.5, 0, 0.5, 0],
98
- [0, 1, 0, 0]
99
- ],
100
- chunkCoefficients(parameters) {
101
- const coefficients = [];
102
- for (const chunk of chunkPointsBy(
103
- duplicateEndpoints ? [parameters[0], ...parameters, parameters[parameters.length - 1]] : parameters,
104
- 1
105
- )) {
106
- coefficients.push(pointsToCoefficients(this.matrix, chunk));
107
- }
108
- return coefficients;
109
- }
110
- });
111
- const ONE_SIXTH = 1 / 6;
112
- const basis = (triplicateEndpoints = true) => ({
113
- matrix: [
114
- [-ONE_SIXTH, 0.5, -0.5, ONE_SIXTH],
115
- [0.5, -1, 0.5, 0],
116
- [-0.5, 0, 0.5, 0],
117
- [ONE_SIXTH, 4 * ONE_SIXTH, ONE_SIXTH, 0]
118
- ],
119
- chunkCoefficients(parameters) {
120
- const coefficients = [];
121
- for (const chunk of chunkPointsBy(
122
- triplicateEndpoints ? [
123
- parameters[0],
124
- parameters[0],
125
- ...parameters,
126
- parameters[parameters.length - 1],
127
- parameters[parameters.length - 1]
128
- ] : parameters,
129
- 1
130
- )) {
131
- coefficients.push(pointsToCoefficients(this.matrix, chunk));
132
- }
133
- return coefficients;
134
- }
135
- });
136
- const splines = {
137
- basis,
138
- bezier,
139
- cardinal,
140
- catmullRom,
141
- hermite
142
- };
143
-
144
- exports.basis = basis;
145
- exports.bezier = bezier;
146
- exports.cardinal = cardinal;
147
- exports.catmullRom = catmullRom;
148
- exports.hermite = hermite;
149
- exports.pointsToCoefficients = pointsToCoefficients;
150
- exports.splines = splines;
@@ -1,27 +0,0 @@
1
- import { a as CubicCoefficients } from './shared/curvy.df73166c.cjs';
2
-
3
- type Matrix4x4 = readonly [
4
- CubicCoefficients,
5
- CubicCoefficients,
6
- CubicCoefficients,
7
- CubicCoefficients
8
- ];
9
- type Spline = {
10
- matrix: Matrix4x4;
11
- chunkCoefficients: (parameters: ReadonlyArray<number>) => ReadonlyArray<CubicCoefficients>;
12
- };
13
- declare function pointsToCoefficients(matrix: Matrix4x4, parameters: CubicCoefficients): CubicCoefficients;
14
- declare const bezier: Spline;
15
- declare const hermite: Spline;
16
- declare const cardinal: (a: number, duplicateEndpoints?: boolean) => Spline;
17
- declare const catmullRom: (duplicateEndpoints?: boolean) => Spline;
18
- declare const basis: (triplicateEndpoints?: boolean) => Spline;
19
- declare const splines: {
20
- readonly basis: (triplicateEndpoints?: boolean) => Spline;
21
- readonly bezier: Spline;
22
- readonly cardinal: (a: number, duplicateEndpoints?: boolean) => Spline;
23
- readonly catmullRom: (duplicateEndpoints?: boolean) => Spline;
24
- readonly hermite: Spline;
25
- };
26
-
27
- export { type Matrix4x4, type Spline, basis, bezier, cardinal, catmullRom, hermite, pointsToCoefficients, splines };
@@ -1,27 +0,0 @@
1
- import { a as CubicCoefficients } from './shared/curvy.df73166c.mjs';
2
-
3
- type Matrix4x4 = readonly [
4
- CubicCoefficients,
5
- CubicCoefficients,
6
- CubicCoefficients,
7
- CubicCoefficients
8
- ];
9
- type Spline = {
10
- matrix: Matrix4x4;
11
- chunkCoefficients: (parameters: ReadonlyArray<number>) => ReadonlyArray<CubicCoefficients>;
12
- };
13
- declare function pointsToCoefficients(matrix: Matrix4x4, parameters: CubicCoefficients): CubicCoefficients;
14
- declare const bezier: Spline;
15
- declare const hermite: Spline;
16
- declare const cardinal: (a: number, duplicateEndpoints?: boolean) => Spline;
17
- declare const catmullRom: (duplicateEndpoints?: boolean) => Spline;
18
- declare const basis: (triplicateEndpoints?: boolean) => Spline;
19
- declare const splines: {
20
- readonly basis: (triplicateEndpoints?: boolean) => Spline;
21
- readonly bezier: Spline;
22
- readonly cardinal: (a: number, duplicateEndpoints?: boolean) => Spline;
23
- readonly catmullRom: (duplicateEndpoints?: boolean) => Spline;
24
- readonly hermite: Spline;
25
- };
26
-
27
- export { type Matrix4x4, type Spline, basis, bezier, cardinal, catmullRom, hermite, pointsToCoefficients, splines };
package/dist/splines.d.ts DELETED
@@ -1,27 +0,0 @@
1
- import { a as CubicCoefficients } from './shared/curvy.df73166c.js';
2
-
3
- type Matrix4x4 = readonly [
4
- CubicCoefficients,
5
- CubicCoefficients,
6
- CubicCoefficients,
7
- CubicCoefficients
8
- ];
9
- type Spline = {
10
- matrix: Matrix4x4;
11
- chunkCoefficients: (parameters: ReadonlyArray<number>) => ReadonlyArray<CubicCoefficients>;
12
- };
13
- declare function pointsToCoefficients(matrix: Matrix4x4, parameters: CubicCoefficients): CubicCoefficients;
14
- declare const bezier: Spline;
15
- declare const hermite: Spline;
16
- declare const cardinal: (a: number, duplicateEndpoints?: boolean) => Spline;
17
- declare const catmullRom: (duplicateEndpoints?: boolean) => Spline;
18
- declare const basis: (triplicateEndpoints?: boolean) => Spline;
19
- declare const splines: {
20
- readonly basis: (triplicateEndpoints?: boolean) => Spline;
21
- readonly bezier: Spline;
22
- readonly cardinal: (a: number, duplicateEndpoints?: boolean) => Spline;
23
- readonly catmullRom: (duplicateEndpoints?: boolean) => Spline;
24
- readonly hermite: Spline;
25
- };
26
-
27
- export { type Matrix4x4, type Spline, basis, bezier, cardinal, catmullRom, hermite, pointsToCoefficients, splines };