curvy 0.3.3 → 1.0.1
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/LICENSE.md +21 -0
- package/dist/curve/cubic2d.d.mts +31 -0
- package/dist/curve/cubic2d.d.ts +31 -0
- package/dist/curve/cubic2d.mjs +96 -0
- package/dist/curve/linear2d.d.mts +28 -0
- package/dist/curve/linear2d.d.ts +28 -0
- package/dist/curve/linear2d.mjs +48 -0
- package/dist/curve/quadratic2d.d.mts +33 -0
- package/dist/curve/quadratic2d.d.ts +33 -0
- package/dist/curve/quadratic2d.mjs +86 -0
- package/dist/interval.d.mts +58 -0
- package/dist/interval.d.ts +58 -0
- package/dist/interval.mjs +88 -0
- package/dist/matrix/matrix2x2.d.mts +49 -0
- package/dist/matrix/matrix2x2.d.ts +49 -0
- package/dist/matrix/matrix2x2.mjs +23 -0
- package/dist/matrix/matrix3x3.d.mts +63 -0
- package/dist/matrix/matrix3x3.d.ts +63 -0
- package/dist/matrix/matrix3x3.mjs +26 -0
- package/dist/matrix/matrix4x4.d.mts +72 -0
- package/dist/matrix/matrix4x4.d.ts +72 -0
- package/dist/matrix/matrix4x4.mjs +214 -0
- package/dist/path/cubic2d.d.mts +29 -0
- package/dist/path/cubic2d.d.ts +29 -0
- package/dist/path/cubic2d.mjs +60 -0
- package/dist/path/linear2d.d.mts +29 -0
- package/dist/path/linear2d.d.ts +29 -0
- package/dist/path/linear2d.mjs +54 -0
- package/dist/path/quadratic2d.d.mts +30 -0
- package/dist/path/quadratic2d.d.ts +30 -0
- package/dist/path/quadratic2d.mjs +60 -0
- package/dist/polynomial/cubic.d.mts +7 -0
- package/dist/polynomial/cubic.d.ts +7 -0
- package/dist/polynomial/cubic.mjs +147 -0
- package/dist/polynomial/linear.d.mts +7 -0
- package/dist/polynomial/linear.d.ts +7 -0
- package/dist/polynomial/linear.mjs +22 -0
- package/dist/polynomial/quadratic.d.mts +7 -0
- package/dist/polynomial/quadratic.d.ts +7 -0
- package/dist/polynomial/quadratic.mjs +23 -0
- package/dist/shared/curvy.BN-oFBsc.d.mts +26 -0
- package/dist/shared/curvy.BN-oFBsc.d.ts +26 -0
- package/dist/shared/curvy.CT38g_II.d.mts +22 -0
- package/dist/shared/curvy.CT38g_II.d.ts +22 -0
- package/dist/shared/curvy.ChkqgKuv.mjs +119 -0
- package/dist/shared/curvy.CkJRVnqj.d.ts +155 -0
- package/dist/shared/curvy.Cty3LrOR.mjs +70 -0
- package/dist/shared/curvy.D7MEXd5g.mjs +130 -0
- package/dist/shared/curvy.D7bhnwZy.mjs +52 -0
- package/dist/shared/curvy.DB7nQmVs.mjs +79 -0
- package/dist/shared/curvy.DM6AiKbn.mjs +119 -0
- package/dist/shared/curvy.DOSsf40r.mjs +49 -0
- package/dist/shared/curvy.DmVFTi0N.mjs +34 -0
- package/dist/shared/curvy.DwHW5Fqt.d.mts +155 -0
- package/dist/shared/curvy.bvP77ZZm.mjs +123 -0
- package/dist/splines/bezier2d.d.mts +43 -0
- package/dist/splines/bezier2d.d.ts +43 -0
- package/dist/splines/bezier2d.mjs +148 -0
- package/dist/vector/vector2.d.mts +41 -0
- package/dist/vector/vector2.d.ts +41 -0
- package/dist/vector/vector2.mjs +17 -0
- package/dist/vector/vector3.d.mts +38 -0
- package/dist/vector/vector3.d.ts +38 -0
- package/dist/vector/vector3.mjs +16 -0
- package/dist/vector/vector4.d.mts +39 -0
- package/dist/vector/vector4.d.ts +39 -0
- package/dist/vector/vector4.mjs +16 -0
- package/package.json +78 -37
- package/dist/axis.cjs +0 -14
- package/dist/axis.d.cts +0 -20
- package/dist/axis.d.mts +0 -20
- package/dist/axis.d.ts +0 -20
- package/dist/axis.mjs +0 -3
- package/dist/convert.cjs +0 -74
- package/dist/convert.d.cts +0 -6
- package/dist/convert.d.mts +0 -6
- package/dist/convert.d.ts +0 -6
- package/dist/convert.mjs +0 -68
- package/dist/curve.cjs +0 -365
- package/dist/curve.d.cts +0 -20
- package/dist/curve.d.mts +0 -20
- package/dist/curve.d.ts +0 -20
- package/dist/curve.mjs +0 -354
- package/dist/shared/curvy.262f6070.cjs +0 -16
- package/dist/shared/curvy.7876e09e.mjs +0 -323
- package/dist/shared/curvy.9cd8b44c.mjs +0 -13
- package/dist/shared/curvy.db103082.cjs +0 -335
- package/dist/shared/curvy.df73166c.d.cts +0 -38
- package/dist/shared/curvy.df73166c.d.mts +0 -38
- package/dist/shared/curvy.df73166c.d.ts +0 -38
- package/dist/splines.cjs +0 -150
- package/dist/splines.d.cts +0 -27
- package/dist/splines.d.mts +0 -27
- package/dist/splines.d.ts +0 -27
- package/dist/splines.mjs +0 -138
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;
|
package/dist/convert.d.cts
DELETED
|
@@ -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 };
|
package/dist/convert.d.mts
DELETED
|
@@ -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 };
|
package/dist/curve.cjs
DELETED
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const invariant = require('tiny-invariant');
|
|
4
|
-
const axis = require('./shared/curvy.db103082.cjs');
|
|
5
|
-
const util = require('./shared/curvy.262f6070.cjs');
|
|
6
|
-
const splines = require('./splines.cjs');
|
|
7
|
-
|
|
8
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
9
|
-
|
|
10
|
-
const invariant__default = /*#__PURE__*/_interopDefaultCompat(invariant);
|
|
11
|
-
|
|
12
|
-
function createNode(interval) {
|
|
13
|
-
return {
|
|
14
|
-
interval,
|
|
15
|
-
left: null,
|
|
16
|
-
right: null
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
function takeCenterInterval(boundaries) {
|
|
20
|
-
const mid = Math.floor((boundaries.length - 1) / 2);
|
|
21
|
-
const left = mid > 0 ? boundaries.slice(0, mid + 1) : null;
|
|
22
|
-
const right = mid + 1 < boundaries.length - 1 ? boundaries.slice(mid + 1) : null;
|
|
23
|
-
return {
|
|
24
|
-
center: [boundaries[mid], boundaries[mid + 1]],
|
|
25
|
-
left,
|
|
26
|
-
right
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function createIntervalTree(boundaries) {
|
|
30
|
-
const container = createNode([0, 0]);
|
|
31
|
-
const branches = [{ parent: container, direction: "left", boundaries }];
|
|
32
|
-
for (const branch of branches) {
|
|
33
|
-
const { parent, direction, boundaries: boundaries2 } = branch;
|
|
34
|
-
const { center, left, right } = takeCenterInterval(boundaries2);
|
|
35
|
-
const node = createNode(center);
|
|
36
|
-
if (direction === "left") {
|
|
37
|
-
parent.left = node;
|
|
38
|
-
} else {
|
|
39
|
-
parent.right = node;
|
|
40
|
-
}
|
|
41
|
-
if (left !== null) {
|
|
42
|
-
branches.push({ parent: node, direction: "left", boundaries: left });
|
|
43
|
-
}
|
|
44
|
-
if (right !== null) {
|
|
45
|
-
branches.push({ parent: node, direction: "right", boundaries: right });
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
const root = container.left;
|
|
49
|
-
function searchNode(node, query) {
|
|
50
|
-
if (node.interval[0] <= query && node.interval[1] >= query) {
|
|
51
|
-
return node.interval;
|
|
52
|
-
}
|
|
53
|
-
if (node.interval[0] > query && node.left) {
|
|
54
|
-
return searchNode(node.left, query);
|
|
55
|
-
}
|
|
56
|
-
if (node.interval[1] < query && node.right) {
|
|
57
|
-
return searchNode(node.right, query);
|
|
58
|
-
}
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
function search(query) {
|
|
62
|
-
return searchNode(root, query);
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
root,
|
|
66
|
-
search
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function collectPointsOfInterest(axis) {
|
|
71
|
-
const samples = new Set(Array.from({ length: 33 }, (_, i) => i / 32));
|
|
72
|
-
const segmentToNormalized = 1 / axis.segments.length;
|
|
73
|
-
for (const [index, segment] of axis.segments.entries()) {
|
|
74
|
-
samples.add(index * segmentToNormalized);
|
|
75
|
-
samples.add((index + 1) * segmentToNormalized);
|
|
76
|
-
for (const t of segment.extrema) {
|
|
77
|
-
samples.add((index + t) * segmentToNormalized);
|
|
78
|
-
}
|
|
79
|
-
for (const root of segment.roots) {
|
|
80
|
-
samples.add((index + root) * segmentToNormalized);
|
|
81
|
-
}
|
|
82
|
-
for (const root of segment.derivative.roots) {
|
|
83
|
-
samples.add((index + root) * segmentToNormalized);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return Array.from(samples).sort((a, b) => a - b);
|
|
87
|
-
}
|
|
88
|
-
function takeLinearIntegral(x1, x2, y1, y2) {
|
|
89
|
-
const m = (y2 - y1) / (x2 - x1);
|
|
90
|
-
const b = y1 - m * x1;
|
|
91
|
-
const s1 = x1 ** 2 * m / 2 + b * x1;
|
|
92
|
-
const s2 = x2 ** 2 * m / 2 + b * x2;
|
|
93
|
-
return Math.abs(s2 - s1);
|
|
94
|
-
}
|
|
95
|
-
function takePolynomialIntegral(coefficients, start, end) {
|
|
96
|
-
let s1 = 0;
|
|
97
|
-
let s2 = 0;
|
|
98
|
-
for (let i = 0; i < coefficients.length; i++) {
|
|
99
|
-
const power = coefficients.length - i;
|
|
100
|
-
s1 += coefficients[i] * start ** power / power;
|
|
101
|
-
s2 += coefficients[i] * end ** power / power;
|
|
102
|
-
}
|
|
103
|
-
return Math.abs(s2 - s1);
|
|
104
|
-
}
|
|
105
|
-
function* createAxisSampler(key, axis$1) {
|
|
106
|
-
const queue = collectPointsOfInterest(axis$1);
|
|
107
|
-
let totalLength = 0;
|
|
108
|
-
const lengthLookup = /* @__PURE__ */ new Map();
|
|
109
|
-
while (queue.length > 0) {
|
|
110
|
-
const current = queue[0];
|
|
111
|
-
const next = queue[1];
|
|
112
|
-
if (next === void 0) {
|
|
113
|
-
yield current;
|
|
114
|
-
lengthLookup.set(totalLength, current);
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
const segment = axis$1.segments[Math.floor(current * axis$1.segments.length)];
|
|
118
|
-
const currentPosition = axis$1.solvePosition(current);
|
|
119
|
-
const nextPosition = axis$1.solvePosition(next);
|
|
120
|
-
const currentVelocity = axis$1.solveVelocity(current);
|
|
121
|
-
const nextVelocity = axis$1.solveVelocity(next);
|
|
122
|
-
const lutPositionIntegral = takeLinearIntegral(
|
|
123
|
-
current,
|
|
124
|
-
next,
|
|
125
|
-
currentPosition,
|
|
126
|
-
nextPosition
|
|
127
|
-
);
|
|
128
|
-
const curvePositionIntegral = takePolynomialIntegral(
|
|
129
|
-
axis.computeCubicAntiderivative(segment.coefficients, 0),
|
|
130
|
-
current,
|
|
131
|
-
next
|
|
132
|
-
);
|
|
133
|
-
const lutVelocityIntegral = takeLinearIntegral(
|
|
134
|
-
current,
|
|
135
|
-
next,
|
|
136
|
-
currentVelocity,
|
|
137
|
-
nextVelocity
|
|
138
|
-
);
|
|
139
|
-
const curveVelocityIntegral = takePolynomialIntegral(
|
|
140
|
-
segment.derivative.coefficients,
|
|
141
|
-
current,
|
|
142
|
-
next
|
|
143
|
-
);
|
|
144
|
-
const error = Math.max(
|
|
145
|
-
Math.abs(lutPositionIntegral - curvePositionIntegral),
|
|
146
|
-
Math.abs(lutVelocityIntegral - curveVelocityIntegral)
|
|
147
|
-
);
|
|
148
|
-
if (error > 1) {
|
|
149
|
-
queue.splice(1, 0, (current + next) / 2);
|
|
150
|
-
} else {
|
|
151
|
-
yield current;
|
|
152
|
-
lengthLookup.set(totalLength, current);
|
|
153
|
-
totalLength += Math.hypot(current - next, currentPosition - nextPosition);
|
|
154
|
-
queue.shift();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return [
|
|
158
|
-
key,
|
|
159
|
-
{
|
|
160
|
-
length: totalLength,
|
|
161
|
-
lookup: lengthLookup
|
|
162
|
-
}
|
|
163
|
-
];
|
|
164
|
-
}
|
|
165
|
-
function distance(a, b) {
|
|
166
|
-
const deltas = [];
|
|
167
|
-
for (const key of Object.keys(a)) {
|
|
168
|
-
deltas.push(a[key] - b[key]);
|
|
169
|
-
}
|
|
170
|
-
return Math.hypot(...deltas);
|
|
171
|
-
}
|
|
172
|
-
function createSampleBuffer() {
|
|
173
|
-
const values = /* @__PURE__ */ new Map();
|
|
174
|
-
return {
|
|
175
|
-
get size() {
|
|
176
|
-
return values.size;
|
|
177
|
-
},
|
|
178
|
-
add(key, value) {
|
|
179
|
-
if (!values.has(key)) {
|
|
180
|
-
values.set(key, /* @__PURE__ */ new Set());
|
|
181
|
-
}
|
|
182
|
-
values.get(key)?.add(value);
|
|
183
|
-
},
|
|
184
|
-
get(key) {
|
|
185
|
-
return values.get(key);
|
|
186
|
-
},
|
|
187
|
-
remove(key, value) {
|
|
188
|
-
values.get(key)?.delete(value);
|
|
189
|
-
if (values.get(key)?.size === 0) {
|
|
190
|
-
values.delete(key);
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
keys() {
|
|
194
|
-
return Array.from(values.keys());
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
function createLengthLookup({
|
|
199
|
-
length: totalLength,
|
|
200
|
-
lookup
|
|
201
|
-
}) {
|
|
202
|
-
const { search } = createIntervalTree(Array.from(lookup.keys()));
|
|
203
|
-
return (normalized) => {
|
|
204
|
-
invariant__default(normalized >= 0 && normalized <= 1, "Length out of bounds");
|
|
205
|
-
const length = normalized * totalLength;
|
|
206
|
-
const result = search(length);
|
|
207
|
-
invariant__default(result, "Length not found");
|
|
208
|
-
return util.remap(
|
|
209
|
-
length,
|
|
210
|
-
result[0],
|
|
211
|
-
result[1],
|
|
212
|
-
lookup.get(result[0]),
|
|
213
|
-
lookup.get(result[1])
|
|
214
|
-
);
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
function createCurveLengthLookups(axes, positionAt) {
|
|
218
|
-
const lengthLookup = /* @__PURE__ */ new Map();
|
|
219
|
-
const axesLookups = {};
|
|
220
|
-
const sampleBuffer = createSampleBuffer();
|
|
221
|
-
for (const [key, axis] of Object.entries(axes)) {
|
|
222
|
-
const sampler = createAxisSampler(key, axis);
|
|
223
|
-
const first = sampler.next();
|
|
224
|
-
if (first.done) {
|
|
225
|
-
axesLookups[first.value[0]] = createLengthLookup(first.value[1]);
|
|
226
|
-
} else {
|
|
227
|
-
sampleBuffer.add(first.value, sampler);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
let lastPoint = positionAt(0);
|
|
231
|
-
let length = 0;
|
|
232
|
-
lengthLookup.set(0, 0);
|
|
233
|
-
while (sampleBuffer.size > 0) {
|
|
234
|
-
const t = Math.min(...sampleBuffer.keys());
|
|
235
|
-
const point = positionAt(t);
|
|
236
|
-
length = length + distance(lastPoint, point);
|
|
237
|
-
lengthLookup.set(length, t);
|
|
238
|
-
lastPoint = point;
|
|
239
|
-
const samplers = sampleBuffer.get(t);
|
|
240
|
-
for (const sampler of samplers) {
|
|
241
|
-
const next = sampler.next();
|
|
242
|
-
if (next.done) {
|
|
243
|
-
axesLookups[next.value[0]] = createLengthLookup(next.value[1]);
|
|
244
|
-
} else {
|
|
245
|
-
sampleBuffer.add(next.value, sampler);
|
|
246
|
-
}
|
|
247
|
-
sampleBuffer.remove(t, sampler);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return {
|
|
251
|
-
curve: createLengthLookup({ length, lookup: lengthLookup }),
|
|
252
|
-
axes: axesLookups
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
function convertPointsToAxes(points, spline) {
|
|
257
|
-
const axisKeys = Object.keys(points[0]);
|
|
258
|
-
const axisPoints = {};
|
|
259
|
-
for (const key of axisKeys) {
|
|
260
|
-
axisPoints[key] = [];
|
|
261
|
-
}
|
|
262
|
-
for (const point of points) {
|
|
263
|
-
for (const key of axisKeys) {
|
|
264
|
-
invariant__default(key in point, `Point ${point} is missing axis "${key}"`);
|
|
265
|
-
axisPoints[key].push(point[key]);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
const axes = {};
|
|
269
|
-
for (const key of axisKeys) {
|
|
270
|
-
axes[key] = axis.createCurveAxis(spline.chunkCoefficients(axisPoints[key]));
|
|
271
|
-
}
|
|
272
|
-
return axes;
|
|
273
|
-
}
|
|
274
|
-
function createCurve(axes) {
|
|
275
|
-
const axisKeys = Object.keys(axes);
|
|
276
|
-
const solveT = (t, precision = 12) => {
|
|
277
|
-
const rounded = util.round(t);
|
|
278
|
-
invariant__default(
|
|
279
|
-
rounded >= 0 && rounded <= 1,
|
|
280
|
-
`t must be between 0 and 1, got ${rounded}`
|
|
281
|
-
);
|
|
282
|
-
const position = {};
|
|
283
|
-
for (const key of axisKeys) {
|
|
284
|
-
position[key] = util.round(axes[key].solvePosition(rounded), precision);
|
|
285
|
-
}
|
|
286
|
-
return position;
|
|
287
|
-
};
|
|
288
|
-
const lengthLookups = createCurveLengthLookups(axes, solveT);
|
|
289
|
-
const positionAt = (input, normalize = 1, precision = 12) => {
|
|
290
|
-
invariant__default(
|
|
291
|
-
input >= 0 && input <= 1,
|
|
292
|
-
`Input must be between 0 and 1, got ${input}`
|
|
293
|
-
);
|
|
294
|
-
let t = input;
|
|
295
|
-
if (normalize > 0) {
|
|
296
|
-
const denormalizedT = lengthLookups.curve(input);
|
|
297
|
-
if (normalize === 1) {
|
|
298
|
-
t = denormalizedT;
|
|
299
|
-
} else {
|
|
300
|
-
t = (1 - normalize) * input + normalize * denormalizedT;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
return solveT(t, precision);
|
|
304
|
-
};
|
|
305
|
-
const solveAlong = (axis, input, normalize = 1, precision = 12) => {
|
|
306
|
-
invariant__default(
|
|
307
|
-
input >= 0 && input <= 1,
|
|
308
|
-
`Input must be between 0 and 1, got ${input}`
|
|
309
|
-
);
|
|
310
|
-
let t = input;
|
|
311
|
-
if (normalize > 0) {
|
|
312
|
-
const denormalizedT = lengthLookups.axes[axis](input);
|
|
313
|
-
if (normalize === 1) {
|
|
314
|
-
t = denormalizedT;
|
|
315
|
-
} else {
|
|
316
|
-
t = (1 - normalize) * input + normalize * denormalizedT;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return solveT(t, precision);
|
|
320
|
-
};
|
|
321
|
-
const solveWhere = (axis, position, precision = 12) => {
|
|
322
|
-
const curveAxis = axes[axis];
|
|
323
|
-
invariant__default(curveAxis.monotonicity !== "none", "Axis is not monotonic");
|
|
324
|
-
const t = curveAxis.solveT(position, curveAxis.domain)[0];
|
|
325
|
-
invariant__default(
|
|
326
|
-
typeof t === "number",
|
|
327
|
-
`Could not solve for ${axis} = ${position}`
|
|
328
|
-
);
|
|
329
|
-
return positionAt(t, 0, precision);
|
|
330
|
-
};
|
|
331
|
-
return {
|
|
332
|
-
axes,
|
|
333
|
-
positionAt,
|
|
334
|
-
solveAlong,
|
|
335
|
-
solveWhere
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
function createBasisCurve(points, triplicateEndpoints = true) {
|
|
339
|
-
return createCurve(
|
|
340
|
-
convertPointsToAxes(points, splines.splines.basis(triplicateEndpoints))
|
|
341
|
-
);
|
|
342
|
-
}
|
|
343
|
-
function createBezierCurve(points) {
|
|
344
|
-
return createCurve(convertPointsToAxes(points, splines.splines.bezier));
|
|
345
|
-
}
|
|
346
|
-
function createCardinalCurve(points, tension = 0.5, duplicateEndpoints = true) {
|
|
347
|
-
return createCurve(
|
|
348
|
-
convertPointsToAxes(points, splines.splines.cardinal(tension, duplicateEndpoints))
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
function createCatmullRomCurve(points, duplicateEndpoints = true) {
|
|
352
|
-
return createCurve(
|
|
353
|
-
convertPointsToAxes(points, splines.splines.catmullRom(duplicateEndpoints))
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
function createHermiteCurve(points) {
|
|
357
|
-
return createCurve(convertPointsToAxes(points, splines.splines.hermite));
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
exports.createBasisCurve = createBasisCurve;
|
|
361
|
-
exports.createBezierCurve = createBezierCurve;
|
|
362
|
-
exports.createCardinalCurve = createCardinalCurve;
|
|
363
|
-
exports.createCatmullRomCurve = createCatmullRomCurve;
|
|
364
|
-
exports.createCurve = createCurve;
|
|
365
|
-
exports.createHermiteCurve = createHermiteCurve;
|
package/dist/curve.d.cts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { CurveAxis } from './axis.cjs';
|
|
2
|
-
import './shared/curvy.df73166c.cjs';
|
|
3
|
-
|
|
4
|
-
type Point<Axis extends string | number> = Readonly<{
|
|
5
|
-
[A in Axis]: number;
|
|
6
|
-
}>;
|
|
7
|
-
type Curve<Axis extends string | number> = {
|
|
8
|
-
readonly axes: Readonly<Record<Axis, CurveAxis>>;
|
|
9
|
-
readonly positionAt: (input: number, normalize?: number, precision?: number) => Point<Axis>;
|
|
10
|
-
readonly solveAlong: <SolveAxis extends Axis>(axis: SolveAxis, input: number, normalize?: number, precision?: number) => Point<Axis>;
|
|
11
|
-
readonly solveWhere: <SolveAxis extends Axis>(axis: SolveAxis, position: number, precision?: number) => Point<Axis>;
|
|
12
|
-
};
|
|
13
|
-
declare function createCurve<Axis extends string | number>(axes: Record<Axis, CurveAxis>): Curve<Axis>;
|
|
14
|
-
declare function createBasisCurve<Axis extends string | number>(points: ReadonlyArray<Point<Axis>>, triplicateEndpoints?: boolean): Curve<Axis>;
|
|
15
|
-
declare function createBezierCurve<Axis extends string | number>(points: ReadonlyArray<Point<Axis>>): Curve<Axis>;
|
|
16
|
-
declare function createCardinalCurve<Axis extends string | number>(points: ReadonlyArray<Point<Axis>>, tension?: number, duplicateEndpoints?: boolean): Curve<Axis>;
|
|
17
|
-
declare function createCatmullRomCurve<Axis extends string | number>(points: ReadonlyArray<Point<Axis>>, duplicateEndpoints?: boolean): Curve<Axis>;
|
|
18
|
-
declare function createHermiteCurve<Axis extends string | number>(points: ReadonlyArray<Point<Axis>>): Curve<Axis>;
|
|
19
|
-
|
|
20
|
-
export { type Curve, type Point, createBasisCurve, createBezierCurve, createCardinalCurve, createCatmullRomCurve, createCurve, createHermiteCurve };
|
package/dist/curve.d.mts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { CurveAxis } from './axis.mjs';
|
|
2
|
-
import './shared/curvy.df73166c.mjs';
|
|
3
|
-
|
|
4
|
-
type Point<Axis extends string | number> = Readonly<{
|
|
5
|
-
[A in Axis]: number;
|
|
6
|
-
}>;
|
|
7
|
-
type Curve<Axis extends string | number> = {
|
|
8
|
-
readonly axes: Readonly<Record<Axis, CurveAxis>>;
|
|
9
|
-
readonly positionAt: (input: number, normalize?: number, precision?: number) => Point<Axis>;
|
|
10
|
-
readonly solveAlong: <SolveAxis extends Axis>(axis: SolveAxis, input: number, normalize?: number, precision?: number) => Point<Axis>;
|
|
11
|
-
readonly solveWhere: <SolveAxis extends Axis>(axis: SolveAxis, position: number, precision?: number) => Point<Axis>;
|
|
12
|
-
};
|
|
13
|
-
declare function createCurve<Axis extends string | number>(axes: Record<Axis, CurveAxis>): Curve<Axis>;
|
|
14
|
-
declare function createBasisCurve<Axis extends string | number>(points: ReadonlyArray<Point<Axis>>, triplicateEndpoints?: boolean): Curve<Axis>;
|
|
15
|
-
declare function createBezierCurve<Axis extends string | number>(points: ReadonlyArray<Point<Axis>>): Curve<Axis>;
|
|
16
|
-
declare function createCardinalCurve<Axis extends string | number>(points: ReadonlyArray<Point<Axis>>, tension?: number, duplicateEndpoints?: boolean): Curve<Axis>;
|
|
17
|
-
declare function createCatmullRomCurve<Axis extends string | number>(points: ReadonlyArray<Point<Axis>>, duplicateEndpoints?: boolean): Curve<Axis>;
|
|
18
|
-
declare function createHermiteCurve<Axis extends string | number>(points: ReadonlyArray<Point<Axis>>): Curve<Axis>;
|
|
19
|
-
|
|
20
|
-
export { type Curve, type Point, createBasisCurve, createBezierCurve, createCardinalCurve, createCatmullRomCurve, createCurve, createHermiteCurve };
|
package/dist/curve.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { CurveAxis } from './axis.js';
|
|
2
|
-
import './shared/curvy.df73166c.js';
|
|
3
|
-
|
|
4
|
-
type Point<Axis extends string | number> = Readonly<{
|
|
5
|
-
[A in Axis]: number;
|
|
6
|
-
}>;
|
|
7
|
-
type Curve<Axis extends string | number> = {
|
|
8
|
-
readonly axes: Readonly<Record<Axis, CurveAxis>>;
|
|
9
|
-
readonly positionAt: (input: number, normalize?: number, precision?: number) => Point<Axis>;
|
|
10
|
-
readonly solveAlong: <SolveAxis extends Axis>(axis: SolveAxis, input: number, normalize?: number, precision?: number) => Point<Axis>;
|
|
11
|
-
readonly solveWhere: <SolveAxis extends Axis>(axis: SolveAxis, position: number, precision?: number) => Point<Axis>;
|
|
12
|
-
};
|
|
13
|
-
declare function createCurve<Axis extends string | number>(axes: Record<Axis, CurveAxis>): Curve<Axis>;
|
|
14
|
-
declare function createBasisCurve<Axis extends string | number>(points: ReadonlyArray<Point<Axis>>, triplicateEndpoints?: boolean): Curve<Axis>;
|
|
15
|
-
declare function createBezierCurve<Axis extends string | number>(points: ReadonlyArray<Point<Axis>>): Curve<Axis>;
|
|
16
|
-
declare function createCardinalCurve<Axis extends string | number>(points: ReadonlyArray<Point<Axis>>, tension?: number, duplicateEndpoints?: boolean): Curve<Axis>;
|
|
17
|
-
declare function createCatmullRomCurve<Axis extends string | number>(points: ReadonlyArray<Point<Axis>>, duplicateEndpoints?: boolean): Curve<Axis>;
|
|
18
|
-
declare function createHermiteCurve<Axis extends string | number>(points: ReadonlyArray<Point<Axis>>): Curve<Axis>;
|
|
19
|
-
|
|
20
|
-
export { type Curve, type Point, createBasisCurve, createBezierCurve, createCardinalCurve, createCatmullRomCurve, createCurve, createHermiteCurve };
|