curvy 0.3.2 → 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 (93) 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 +81 -38
  69. package/dist/axis.cjs +0 -325
  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 -314
  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 -194
  80. package/dist/curve.d.cts +0 -18
  81. package/dist/curve.d.mts +0 -18
  82. package/dist/curve.d.ts +0 -18
  83. package/dist/curve.mjs +0 -184
  84. package/dist/shared/curvy.262f6070.cjs +0 -16
  85. package/dist/shared/curvy.9cd8b44c.mjs +0 -13
  86. package/dist/shared/curvy.df73166c.d.cts +0 -38
  87. package/dist/shared/curvy.df73166c.d.mts +0 -38
  88. package/dist/shared/curvy.df73166c.d.ts +0 -38
  89. package/dist/splines.cjs +0 -150
  90. package/dist/splines.d.cts +0 -27
  91. package/dist/splines.d.mts +0 -27
  92. package/dist/splines.d.ts +0 -27
  93. package/dist/splines.mjs +0 -138
package/dist/axis.d.mts DELETED
@@ -1,20 +0,0 @@
1
- import { I as Interval, M as Monotonicity, C as CubicPolynomial, a as CubicCoefficients } from './shared/curvy.df73166c.mjs';
2
-
3
- type CurveAxis = {
4
- readonly domain: Interval;
5
- readonly range: Interval;
6
- readonly monotonicity: Monotonicity;
7
- readonly extrema: ReadonlyArray<number>;
8
- readonly segments: ReadonlyArray<CubicPolynomial>;
9
- readonly solvePosition: (t: number) => number;
10
- readonly solveVelocity: (t: number) => number;
11
- readonly solveT: (position: number, domain: Interval) => ReadonlyArray<number>;
12
- };
13
- declare function createCurveAxis(coefficients: ReadonlyArray<CubicCoefficients>): CurveAxis;
14
- declare function createBasisAxis(parameters: ReadonlyArray<number>, triplicateEndpoints?: boolean): CurveAxis;
15
- declare function createBezierAxis(parameters: ReadonlyArray<number>): CurveAxis;
16
- declare function createCardinalAxis(parameters: ReadonlyArray<number>, a?: number, duplicateEndpoints?: boolean): CurveAxis;
17
- declare function createCatmullRomAxis(parameters: ReadonlyArray<number>, duplicateEndpoints?: boolean): CurveAxis;
18
- declare function createHermiteAxis(parameters: ReadonlyArray<number>): CurveAxis;
19
-
20
- export { type CurveAxis, createBasisAxis, createBezierAxis, createCardinalAxis, createCatmullRomAxis, createCurveAxis, createHermiteAxis };
package/dist/axis.d.ts DELETED
@@ -1,20 +0,0 @@
1
- import { I as Interval, M as Monotonicity, C as CubicPolynomial, a as CubicCoefficients } from './shared/curvy.df73166c.js';
2
-
3
- type CurveAxis = {
4
- readonly domain: Interval;
5
- readonly range: Interval;
6
- readonly monotonicity: Monotonicity;
7
- readonly extrema: ReadonlyArray<number>;
8
- readonly segments: ReadonlyArray<CubicPolynomial>;
9
- readonly solvePosition: (t: number) => number;
10
- readonly solveVelocity: (t: number) => number;
11
- readonly solveT: (position: number, domain: Interval) => ReadonlyArray<number>;
12
- };
13
- declare function createCurveAxis(coefficients: ReadonlyArray<CubicCoefficients>): CurveAxis;
14
- declare function createBasisAxis(parameters: ReadonlyArray<number>, triplicateEndpoints?: boolean): CurveAxis;
15
- declare function createBezierAxis(parameters: ReadonlyArray<number>): CurveAxis;
16
- declare function createCardinalAxis(parameters: ReadonlyArray<number>, a?: number, duplicateEndpoints?: boolean): CurveAxis;
17
- declare function createCatmullRomAxis(parameters: ReadonlyArray<number>, duplicateEndpoints?: boolean): CurveAxis;
18
- declare function createHermiteAxis(parameters: ReadonlyArray<number>): CurveAxis;
19
-
20
- export { type CurveAxis, createBasisAxis, createBezierAxis, createCardinalAxis, createCatmullRomAxis, createCurveAxis, createHermiteAxis };
package/dist/axis.mjs DELETED
@@ -1,314 +0,0 @@
1
- import invariant from 'tiny-invariant';
2
- import { splines } from './splines.mjs';
3
-
4
- const UNIT_INTERVAL = [0, 1];
5
- function createLinearPolynomial(coefficients, domain = UNIT_INTERVAL) {
6
- const [a, b] = coefficients;
7
- invariant(domain[0] <= domain[1], "invalid domain");
8
- let root = a === 0 ? null : b === 0 ? 0 : -b / a;
9
- if (root !== null && (root < domain[0] || root > domain[1])) {
10
- root = null;
11
- }
12
- const range = a >= 0 ? [a * domain[0] + b, a * domain[1] + b] : [a * domain[1] + b, a * domain[0] + b];
13
- const solve = (x) => {
14
- invariant(x >= domain[0] && x <= domain[1], "x out of domain");
15
- return a * x + b;
16
- };
17
- const solveInverse = (y) => {
18
- invariant(y >= range[0] && y <= range[1], "y out of range");
19
- return a === 0 ? 0 : (y - b) / a;
20
- };
21
- return {
22
- domain,
23
- range,
24
- monotonicity: a === 0 ? "constant" : a > 0 ? "increasing" : "decreasing",
25
- coefficients,
26
- root,
27
- solve,
28
- solveInverse
29
- };
30
- }
31
- function createQuadraticRootSolver(coefficients, defaultDomain, range) {
32
- const [a, b, c] = coefficients;
33
- if (a !== 0) {
34
- return function solveInverse(y, domain = defaultDomain) {
35
- invariant(domain[0] <= domain[1], "invalid domain");
36
- invariant(y >= range[0] && y <= range[1], "y out of range");
37
- const discriminant = b ** 2 - 4 * a * (c - y);
38
- if (discriminant < 0) {
39
- return [];
40
- }
41
- if (discriminant === 0) {
42
- const root = -b / (2 * a);
43
- return root < domain[0] || root > domain[1] ? [] : [root];
44
- }
45
- const sqrtDiscriminant = Math.sqrt(discriminant);
46
- const denominator = 2 * a;
47
- const left = (-b - sqrtDiscriminant) / denominator;
48
- const right = (-b + sqrtDiscriminant) / denominator;
49
- const leftInDomain = left >= domain[0] && left <= domain[1];
50
- const rightInDomain = right >= domain[0] && right <= domain[1];
51
- if (leftInDomain && rightInDomain) {
52
- return left < right ? [left, right] : [right, left];
53
- }
54
- if (leftInDomain) {
55
- return [left];
56
- }
57
- if (rightInDomain) {
58
- return [right];
59
- }
60
- return [];
61
- };
62
- }
63
- if (b !== 0) {
64
- return function solveInverse(y, domain = defaultDomain) {
65
- invariant(domain[0] <= domain[1], "invalid domain");
66
- invariant(y >= range[0] && y <= range[1], "y out of range");
67
- const root = -(c - y) / b;
68
- return root < domain[0] || root > domain[1] ? [] : [root];
69
- };
70
- }
71
- return function solveInverse() {
72
- return [];
73
- };
74
- }
75
- function createQuadraticPolynomial(coefficients, domain = UNIT_INTERVAL) {
76
- const [a, b, c] = coefficients;
77
- invariant(domain[0] <= domain[1], "invalid domain");
78
- const derivative = createLinearPolynomial([2 * a, b], domain);
79
- const extreme = derivative.root;
80
- const solve = (x) => {
81
- invariant(x >= domain[0] && x <= domain[1], "x out of domain");
82
- return a * x ** 2 + b * x + c;
83
- };
84
- const rangeCandidates = extreme === null ? [solve(domain[0]), solve(domain[1])] : [solve(domain[0]), solve(extreme), solve(domain[1])];
85
- const range = [
86
- Math.min(...rangeCandidates),
87
- Math.max(...rangeCandidates)
88
- ];
89
- const solveInverse = createQuadraticRootSolver(coefficients, domain, range);
90
- const roots = range[0] > 0 || range[1] < 0 ? [] : solveInverse(0);
91
- return {
92
- domain,
93
- range,
94
- coefficients,
95
- monotonicity: a !== 0 ? "none" : b === 0 ? "constant" : b > 0 ? "increasing" : "decreasing",
96
- extreme,
97
- roots,
98
- derivative,
99
- solve,
100
- solveInverse
101
- };
102
- }
103
- const TWO_THIRDS_PI = 2 * Math.PI / 3;
104
- function createCubicRootSolver(coefficients, defaultDomain, range) {
105
- if (coefficients[0] === 0) {
106
- return createQuadraticRootSolver(
107
- [coefficients[1], coefficients[2], coefficients[3]],
108
- defaultDomain,
109
- range
110
- );
111
- }
112
- const oneOverA = 1 / coefficients[0];
113
- const a0 = coefficients[1] * oneOverA;
114
- const a1 = coefficients[2] * oneOverA;
115
- const a2OverThree = a0 / 3;
116
- const q = a1 / 3 - a0 ** 2 / 9;
117
- const r0 = a1 * a0 / 6 - a0 ** 3 / 27;
118
- return function solveInverse(y, domain = defaultDomain) {
119
- invariant(domain[0] <= domain[1], "invalid domain");
120
- invariant(y >= range[0] && y <= range[1], "y out of range");
121
- const a02 = (coefficients[3] - y) * oneOverA;
122
- const r = r0 - a02 * 0.5;
123
- const discriminant = q ** 3 + r ** 2;
124
- if (discriminant > 0) {
125
- const a = Math.cbrt(Math.abs(r) + Math.sqrt(discriminant));
126
- const root = (r < 0 ? q / a - a : a - q / a) - a2OverThree;
127
- return root < domain[0] || root > domain[1] ? [] : [root];
128
- }
129
- const theta = Math.acos(r / Math.sqrt((-q) ** 3)) / 3;
130
- const twoRootQ = 2 * Math.sqrt(-q);
131
- const root1 = twoRootQ * Math.cos(theta - TWO_THIRDS_PI) - a2OverThree;
132
- const root2 = twoRootQ * Math.cos(theta) - a2OverThree;
133
- const root3 = twoRootQ * Math.cos(theta + TWO_THIRDS_PI) - a2OverThree;
134
- const candidates = [root1, root2, root3];
135
- const roots = [];
136
- for (const candidate of candidates) {
137
- if (candidate >= domain[0] && candidate <= domain[1] && !roots.includes(candidate)) {
138
- roots.push(candidate);
139
- }
140
- }
141
- roots.sort((a, b) => a - b);
142
- return roots;
143
- };
144
- }
145
- function getMonotonicity(extrema, derivative, domain) {
146
- if (derivative.coefficients[0] === 0 && derivative.coefficients[1] === 0 && derivative.coefficients[2] === 0) {
147
- return "constant";
148
- }
149
- let hasInnerExtrema = false;
150
- for (const extreme of extrema) {
151
- if (extreme > domain[0] && extreme > domain[1]) {
152
- hasInnerExtrema = true;
153
- break;
154
- }
155
- }
156
- if (hasInnerExtrema) {
157
- return "none";
158
- }
159
- let test = derivative.solve(domain[0]);
160
- if (test === 0) {
161
- test = derivative.solve((domain[0] + domain[1]) * 0.5);
162
- }
163
- return Math.sign(test) > 0 ? "increasing" : "decreasing";
164
- }
165
- function createCubicPolynomial(coefficients, domain = UNIT_INTERVAL) {
166
- invariant(domain[0] <= domain[1], "invalid domain");
167
- const [a, b, c, d] = coefficients;
168
- const derivative = createQuadraticPolynomial([3 * a, 2 * b, c], domain);
169
- const extrema = derivative.roots.length === 1 && derivative.coefficients[0] !== 0 ? [] : derivative.roots;
170
- const solve = (x) => {
171
- invariant(x >= domain[0] && x <= domain[1], "x out of domain");
172
- return a * x ** 3 + b * x ** 2 + c * x + d;
173
- };
174
- const rangeCandidates = [
175
- solve(domain[0]),
176
- ...extrema.map((extreme) => solve(extreme)),
177
- solve(domain[1])
178
- ];
179
- const range = [
180
- Math.min(...rangeCandidates),
181
- Math.max(...rangeCandidates)
182
- ];
183
- const solveInverse = createCubicRootSolver(coefficients, domain, range);
184
- const roots = range[0] > 0 || range[1] < 0 ? [] : solveInverse(0, domain);
185
- const monotonicity = getMonotonicity(extrema, derivative, domain);
186
- return {
187
- domain,
188
- range,
189
- monotonicity,
190
- coefficients,
191
- extrema,
192
- roots,
193
- derivative,
194
- solve,
195
- solveInverse
196
- };
197
- }
198
-
199
- function getCurveExtrema(lookup) {
200
- const extremaLookup = new Map(lookup);
201
- const extremaCandidates = Array.from(extremaLookup.keys());
202
- for (const [index, t] of extremaCandidates.entries()) {
203
- if (index === 0 || index === extremaCandidates.length - 1) {
204
- continue;
205
- }
206
- const previous = extremaLookup.get(extremaCandidates[index - 1]);
207
- const current = extremaLookup.get(t);
208
- const next = extremaLookup.get(extremaCandidates[index + 1]);
209
- if (previous <= current && current < next || previous >= current && current > next) {
210
- extremaLookup.delete(t);
211
- }
212
- }
213
- const extrema = Array.from(extremaLookup.keys());
214
- return extrema;
215
- }
216
- function createCurveAxis(coefficients) {
217
- invariant(coefficients.length > 0, "Curve must have at least one segment");
218
- const segments = [];
219
- const extremaLookup = /* @__PURE__ */ new Map();
220
- let monotonicity = "none";
221
- const normalizedToCurve = coefficients.length;
222
- const curveToNormalized = 1 / coefficients.length;
223
- for (let i = 0; i < coefficients.length; i++) {
224
- const segment = createCubicPolynomial(coefficients[i], UNIT_INTERVAL);
225
- segments.push(segment);
226
- extremaLookup.set(i * curveToNormalized, segment.solve(0));
227
- for (const extreme of segment.extrema) {
228
- extremaLookup.set(
229
- (i + extreme) * curveToNormalized,
230
- segment.solve(extreme)
231
- );
232
- }
233
- if (i === 0) {
234
- monotonicity = segment.monotonicity;
235
- } else if (monotonicity !== segment.monotonicity) {
236
- monotonicity = "none";
237
- }
238
- }
239
- extremaLookup.set(1, segments[segments.length - 1].solve(1));
240
- const extrema = getCurveExtrema(extremaLookup);
241
- const range = [
242
- Math.min(...extremaLookup.values()),
243
- Math.max(...extremaLookup.values())
244
- ];
245
- const getSegmentAndInput = (t) => {
246
- invariant(t >= 0 && t <= 1, "t out of range");
247
- if (t === 1) {
248
- return { segment: segments[segments.length - 1], input: 1 };
249
- }
250
- const curveT = t * normalizedToCurve;
251
- const index = Math.floor(curveT);
252
- const segment = segments[index];
253
- const input = curveT - index;
254
- return { segment, input };
255
- };
256
- const solvePosition = (t) => {
257
- const { segment, input } = getSegmentAndInput(t);
258
- return segment.solve(input);
259
- };
260
- const solveVelocity = (t) => {
261
- const { segment, input } = getSegmentAndInput(t);
262
- return segment.derivative.solve(input);
263
- };
264
- const solveT = (position, domain) => {
265
- invariant(
266
- position >= range[0] && position <= range[1],
267
- "position out of range"
268
- );
269
- invariant(domain[0] <= domain[1], "invalid domain");
270
- const result = [];
271
- for (const [index, segment] of segments.entries()) {
272
- if (position >= segment.range[0] && position <= segment.range[1]) {
273
- const t = segment.solveInverse(position, domain);
274
- for (const tValue of t) {
275
- result.push((index + tValue) * curveToNormalized);
276
- }
277
- }
278
- }
279
- return result;
280
- };
281
- return {
282
- domain: UNIT_INTERVAL,
283
- range,
284
- monotonicity,
285
- extrema,
286
- segments,
287
- solvePosition,
288
- solveVelocity,
289
- solveT
290
- };
291
- }
292
- function createBasisAxis(parameters, triplicateEndpoints = true) {
293
- return createCurveAxis(
294
- splines.basis(triplicateEndpoints).chunkCoefficients(parameters)
295
- );
296
- }
297
- function createBezierAxis(parameters) {
298
- return createCurveAxis(splines.bezier.chunkCoefficients(parameters));
299
- }
300
- function createCardinalAxis(parameters, a = 0.5, duplicateEndpoints = true) {
301
- return createCurveAxis(
302
- splines.cardinal(a, duplicateEndpoints).chunkCoefficients(parameters)
303
- );
304
- }
305
- function createCatmullRomAxis(parameters, duplicateEndpoints = true) {
306
- return createCurveAxis(
307
- splines.catmullRom(duplicateEndpoints).chunkCoefficients(parameters)
308
- );
309
- }
310
- function createHermiteAxis(parameters) {
311
- return createCurveAxis(splines.hermite.chunkCoefficients(parameters));
312
- }
313
-
314
- export { createBasisAxis, createBezierAxis, createCardinalAxis, createCatmullRomAxis, createCurveAxis, createHermiteAxis };
package/dist/convert.cjs DELETED
@@ -1,74 +0,0 @@
1
- 'use strict';
2
-
3
- const invariant = require('tiny-invariant');
4
- const splines = require('./splines.cjs');
5
- const util = require('./shared/curvy.262f6070.cjs');
6
-
7
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
8
-
9
- const invariant__default = /*#__PURE__*/_interopDefaultCompat(invariant);
10
-
11
- function determinant(matrix) {
12
- const size = matrix.length;
13
- invariant__default(
14
- matrix.every((row) => row.length === size),
15
- "matrix must be square"
16
- );
17
- let result = 0;
18
- if (size === 1) {
19
- result = matrix[0][0];
20
- } else if (size === 2) {
21
- result = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
22
- } else {
23
- for (const [columnIndex, value] of matrix[0].entries()) {
24
- const subMatrix = [];
25
- for (const row of matrix.slice(1)) {
26
- const subMatrixRow = [];
27
- for (const [subColumnIndex, subColumnValue] of row.entries()) {
28
- if (subColumnIndex !== columnIndex) {
29
- subMatrixRow.push(subColumnValue);
30
- }
31
- }
32
- subMatrix.push(subMatrixRow);
33
- }
34
- result = result + (-1) ** (columnIndex + 2) * value * determinant(subMatrix);
35
- }
36
- }
37
- return result;
38
- }
39
- function solveLinearSystem(coefficients, solutions) {
40
- const coefficientDeterminant = determinant(coefficients);
41
- invariant__default(
42
- coefficientDeterminant !== 0,
43
- "Cannot solve system of equations when coefficient matrix determinant is zero"
44
- );
45
- const variables = [0, 0, 0, 0];
46
- for (let index = 0; index < solutions.length; index++) {
47
- const solutionMatrix = [];
48
- for (const [rowIndex, row] of coefficients.entries()) {
49
- const solutionMatrixRow = [];
50
- for (const [columnIndex, column] of row.entries()) {
51
- solutionMatrixRow.push(
52
- columnIndex === index ? solutions[rowIndex] : column
53
- );
54
- }
55
- solutionMatrix.push(solutionMatrixRow);
56
- }
57
- variables[index] = determinant(solutionMatrix) / coefficientDeterminant;
58
- }
59
- return variables;
60
- }
61
- function convertScalars(points, sourceSpline, targetSpline) {
62
- const solutions = solveLinearSystem(
63
- targetSpline,
64
- splines.pointsToCoefficients(sourceSpline, points)
65
- );
66
- return [
67
- util.round(solutions[0]),
68
- util.round(solutions[1]),
69
- util.round(solutions[2]),
70
- util.round(solutions[3])
71
- ];
72
- }
73
-
74
- exports.convertScalars = convertScalars;
@@ -1,6 +0,0 @@
1
- import { a as CubicCoefficients } from './shared/curvy.df73166c.cjs';
2
- import { Matrix4x4 } from './splines.cjs';
3
-
4
- declare function convertScalars(points: CubicCoefficients, sourceSpline: Matrix4x4, targetSpline: Matrix4x4): CubicCoefficients;
5
-
6
- export { convertScalars };
@@ -1,6 +0,0 @@
1
- import { a as CubicCoefficients } from './shared/curvy.df73166c.mjs';
2
- import { Matrix4x4 } from './splines.mjs';
3
-
4
- declare function convertScalars(points: CubicCoefficients, sourceSpline: Matrix4x4, targetSpline: Matrix4x4): CubicCoefficients;
5
-
6
- export { convertScalars };
package/dist/convert.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { a as CubicCoefficients } from './shared/curvy.df73166c.js';
2
- import { Matrix4x4 } from './splines.js';
3
-
4
- declare function convertScalars(points: CubicCoefficients, sourceSpline: Matrix4x4, targetSpline: Matrix4x4): CubicCoefficients;
5
-
6
- export { convertScalars };
package/dist/convert.mjs DELETED
@@ -1,68 +0,0 @@
1
- import invariant from 'tiny-invariant';
2
- import { pointsToCoefficients } from './splines.mjs';
3
- import { a as round } from './shared/curvy.9cd8b44c.mjs';
4
-
5
- function determinant(matrix) {
6
- const size = matrix.length;
7
- invariant(
8
- matrix.every((row) => row.length === size),
9
- "matrix must be square"
10
- );
11
- let result = 0;
12
- if (size === 1) {
13
- result = matrix[0][0];
14
- } else if (size === 2) {
15
- result = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
16
- } else {
17
- for (const [columnIndex, value] of matrix[0].entries()) {
18
- const subMatrix = [];
19
- for (const row of matrix.slice(1)) {
20
- const subMatrixRow = [];
21
- for (const [subColumnIndex, subColumnValue] of row.entries()) {
22
- if (subColumnIndex !== columnIndex) {
23
- subMatrixRow.push(subColumnValue);
24
- }
25
- }
26
- subMatrix.push(subMatrixRow);
27
- }
28
- result = result + (-1) ** (columnIndex + 2) * value * determinant(subMatrix);
29
- }
30
- }
31
- return result;
32
- }
33
- function solveLinearSystem(coefficients, solutions) {
34
- const coefficientDeterminant = determinant(coefficients);
35
- invariant(
36
- coefficientDeterminant !== 0,
37
- "Cannot solve system of equations when coefficient matrix determinant is zero"
38
- );
39
- const variables = [0, 0, 0, 0];
40
- for (let index = 0; index < solutions.length; index++) {
41
- const solutionMatrix = [];
42
- for (const [rowIndex, row] of coefficients.entries()) {
43
- const solutionMatrixRow = [];
44
- for (const [columnIndex, column] of row.entries()) {
45
- solutionMatrixRow.push(
46
- columnIndex === index ? solutions[rowIndex] : column
47
- );
48
- }
49
- solutionMatrix.push(solutionMatrixRow);
50
- }
51
- variables[index] = determinant(solutionMatrix) / coefficientDeterminant;
52
- }
53
- return variables;
54
- }
55
- function convertScalars(points, sourceSpline, targetSpline) {
56
- const solutions = solveLinearSystem(
57
- targetSpline,
58
- pointsToCoefficients(sourceSpline, points)
59
- );
60
- return [
61
- round(solutions[0]),
62
- round(solutions[1]),
63
- round(solutions[2]),
64
- round(solutions[3])
65
- ];
66
- }
67
-
68
- export { convertScalars };