curvy 1.0.2 → 1.0.3
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/shared/curvy.BZXFCKQe.mjs +180 -0
- package/dist/splines/basis2d.d.mts +3 -1
- package/dist/splines/basis2d.d.ts +3 -1
- package/dist/splines/basis2d.mjs +4 -2
- package/dist/splines/bezier2d.d.mts +9 -4
- package/dist/splines/bezier2d.d.ts +9 -4
- package/dist/splines/bezier2d.mjs +5 -98
- package/dist/splines/cardinal2d.d.mts +6 -1
- package/dist/splines/cardinal2d.d.ts +6 -1
- package/dist/splines/cardinal2d.mjs +8 -2
- package/dist/splines/hermite2d.d.mts +3 -1
- package/dist/splines/hermite2d.d.ts +3 -1
- package/dist/splines/hermite2d.mjs +4 -2
- package/package.json +1 -1
- package/dist/shared/curvy.DN9ptodP.mjs +0 -55
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { d as dual, P as Pipeable, i as invariant } from './curvy.DLOeble8.mjs';
|
|
2
|
+
import { vectorProductLeft, make as make$3, solveSystem } from '../matrix/matrix4x4.mjs';
|
|
3
|
+
import { fromCurves } from '../path/cubic2d.mjs';
|
|
4
|
+
import { make as make$4 } from '../vector/vector2.mjs';
|
|
5
|
+
import { make as make$2 } from '../vector/vector4.mjs';
|
|
6
|
+
import { fromPolynomials } from '../curve/cubic2d.mjs';
|
|
7
|
+
import { fromVector } from '../polynomial/cubic.mjs';
|
|
8
|
+
|
|
9
|
+
function* toPointQuads(points, stride) {
|
|
10
|
+
let p0;
|
|
11
|
+
let p1;
|
|
12
|
+
let p2;
|
|
13
|
+
let p3;
|
|
14
|
+
for (const point of points) {
|
|
15
|
+
if (p0 === void 0) {
|
|
16
|
+
p0 = point;
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (p1 === void 0) {
|
|
20
|
+
p1 = point;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (p2 === void 0) {
|
|
24
|
+
p2 = point;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
p3 = point;
|
|
28
|
+
yield [p0, p1, p2, p3];
|
|
29
|
+
if (stride === 1) {
|
|
30
|
+
p0 = p1;
|
|
31
|
+
p1 = p2;
|
|
32
|
+
p2 = p3;
|
|
33
|
+
} else if (stride === 2) {
|
|
34
|
+
p0 = p2;
|
|
35
|
+
p1 = p3;
|
|
36
|
+
p2 = void 0;
|
|
37
|
+
} else if (stride === 3) {
|
|
38
|
+
p0 = p3;
|
|
39
|
+
p1 = void 0;
|
|
40
|
+
p2 = void 0;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function* toCurves(points, matrix, stride) {
|
|
45
|
+
for (const [p0, p1, p2, p3] of toPointQuads(points, stride)) {
|
|
46
|
+
yield fromPolynomials(
|
|
47
|
+
fromVector(
|
|
48
|
+
vectorProductLeft(
|
|
49
|
+
matrix,
|
|
50
|
+
make$2(p0.x, p1.x, p2.x, p3.x)
|
|
51
|
+
)
|
|
52
|
+
),
|
|
53
|
+
fromVector(
|
|
54
|
+
vectorProductLeft(
|
|
55
|
+
matrix,
|
|
56
|
+
make$2(p0.y, p1.y, p2.y, p3.y)
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const characteristic$1 = make$3(
|
|
64
|
+
1,
|
|
65
|
+
0,
|
|
66
|
+
0,
|
|
67
|
+
0,
|
|
68
|
+
-3,
|
|
69
|
+
3,
|
|
70
|
+
0,
|
|
71
|
+
0,
|
|
72
|
+
3,
|
|
73
|
+
-6,
|
|
74
|
+
3,
|
|
75
|
+
0,
|
|
76
|
+
-1,
|
|
77
|
+
3,
|
|
78
|
+
-3,
|
|
79
|
+
1
|
|
80
|
+
);
|
|
81
|
+
const Bezier2dTypeId = Symbol("curvy/splines/bezier2d");
|
|
82
|
+
class Bezier2dImpl extends Pipeable {
|
|
83
|
+
[Bezier2dTypeId] = Bezier2dTypeId;
|
|
84
|
+
points;
|
|
85
|
+
constructor(points) {
|
|
86
|
+
invariant(points.length >= 4, "cubic splines requires 4 or more points");
|
|
87
|
+
invariant(
|
|
88
|
+
points.length % 3 === 1,
|
|
89
|
+
"cubic splines requires (n * 3) + 1 points"
|
|
90
|
+
);
|
|
91
|
+
super();
|
|
92
|
+
this.points = points;
|
|
93
|
+
}
|
|
94
|
+
[Symbol.iterator]() {
|
|
95
|
+
return this.points[Symbol.iterator]();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const isCubicBezier2d$1 = (p) => typeof p === "object" && p !== null && Bezier2dTypeId in p;
|
|
99
|
+
const make$1 = (p0, p1, p2, p3) => new Bezier2dImpl([p0, p1, p2, p3]);
|
|
100
|
+
const fromArray$1 = (points) => new Bezier2dImpl(points);
|
|
101
|
+
const append$1 = dual(
|
|
102
|
+
4,
|
|
103
|
+
(p, p1, p2, p3) => new Bezier2dImpl(
|
|
104
|
+
(p instanceof Bezier2dImpl ? p.points : Array.from(p)).concat(p1, p2, p3)
|
|
105
|
+
)
|
|
106
|
+
);
|
|
107
|
+
const fromSpline$1 = (p, matrix, stride) => {
|
|
108
|
+
const points = [];
|
|
109
|
+
let x;
|
|
110
|
+
let y;
|
|
111
|
+
for (const [p0, p1, p2, p3] of toPointQuads(p, stride)) {
|
|
112
|
+
x = solveSystem(
|
|
113
|
+
characteristic$1,
|
|
114
|
+
vectorProductLeft(matrix, make$2(p0.x, p1.x, p2.x, p3.x))
|
|
115
|
+
);
|
|
116
|
+
y = solveSystem(
|
|
117
|
+
characteristic$1,
|
|
118
|
+
vectorProductLeft(matrix, make$2(p0.y, p1.y, p2.y, p3.y))
|
|
119
|
+
);
|
|
120
|
+
points.push(
|
|
121
|
+
make$4(x.x, y.x),
|
|
122
|
+
make$4(x.y, y.y),
|
|
123
|
+
make$4(x.z, y.z)
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
if (x && y) {
|
|
127
|
+
points.push(make$4(x.w, y.w));
|
|
128
|
+
}
|
|
129
|
+
return fromArray$1(points);
|
|
130
|
+
};
|
|
131
|
+
const appendTangentAligned$1 = dual(4, (p, a, p5, p6) => {
|
|
132
|
+
const points = p instanceof Bezier2dImpl ? p.points : Array.from(p);
|
|
133
|
+
const p2 = points[points.length - 2];
|
|
134
|
+
const p3 = points[points.length - 1];
|
|
135
|
+
const p4 = make$4(p3.x + (p3.x - p2.x) * a, p3.y + (p3.y - p2.y) * a);
|
|
136
|
+
return append$1(p, p4, p5, p6);
|
|
137
|
+
});
|
|
138
|
+
const appendCurvatureAligned = dual(
|
|
139
|
+
4,
|
|
140
|
+
(p, a, b, p6) => {
|
|
141
|
+
const points = p instanceof Bezier2dImpl ? p.points : Array.from(p);
|
|
142
|
+
const p1 = points[points.length - 3];
|
|
143
|
+
const p2 = points[points.length - 2];
|
|
144
|
+
const p3 = points[points.length - 1];
|
|
145
|
+
const p4 = make$4(p3.x + (p3.x - p2.x) * a, p3.y + (p3.y - p2.y) * a);
|
|
146
|
+
const p5 = make$4(
|
|
147
|
+
p3.x + (p3.x - p2.x) * (2 * a + a ** 2 + b / 2) + (p1.x - p2.x) * a ** 2,
|
|
148
|
+
p3.y + (p3.y - p2.y) * (2 * a + a ** 2 + b / 2) + (p1.y - p2.y) * a ** 2
|
|
149
|
+
);
|
|
150
|
+
return append$1(p, p4, p5, p6);
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
const appendVelocityAligned$1 = dual(
|
|
154
|
+
3,
|
|
155
|
+
(p, p5, p6) => appendTangentAligned$1(p, 1, p5, p6)
|
|
156
|
+
);
|
|
157
|
+
const appendAccelerationAligned$1 = dual(2, (p, p6) => {
|
|
158
|
+
const points = p instanceof Bezier2dImpl ? p.points : Array.from(p);
|
|
159
|
+
const p1 = points[points.length - 3];
|
|
160
|
+
const p2 = points[points.length - 2];
|
|
161
|
+
const p3 = points[points.length - 1];
|
|
162
|
+
const p4 = make$4(2 * p3.x - p2.x, 2 * p3.y - p2.y);
|
|
163
|
+
const p5 = make$4(p1.x + 4 * (p3.x - p2.x), p1.y + 4 * (p3.y - p2.y));
|
|
164
|
+
return append$1(p, p4, p5, p6);
|
|
165
|
+
});
|
|
166
|
+
const toPath$1 = (p) => fromCurves(...toCurves(p, characteristic$1, 3));
|
|
167
|
+
|
|
168
|
+
const characteristic = characteristic$1;
|
|
169
|
+
const make = make$1;
|
|
170
|
+
const fromArray = fromArray$1;
|
|
171
|
+
const fromSpline = fromSpline$1;
|
|
172
|
+
const isCubicBezier2d = isCubicBezier2d$1;
|
|
173
|
+
const append = append$1;
|
|
174
|
+
const appendTangentAligned = appendTangentAligned$1;
|
|
175
|
+
const appendCurvatureMirrored = appendCurvatureAligned;
|
|
176
|
+
const appendVelocityAligned = appendVelocityAligned$1;
|
|
177
|
+
const appendAccelerationAligned = appendAccelerationAligned$1;
|
|
178
|
+
const toPath = toPath$1;
|
|
179
|
+
|
|
180
|
+
export { fromArray as a, append as b, characteristic as c, appendTangentAligned as d, appendCurvatureMirrored as e, fromSpline as f, appendVelocityAligned as g, appendAccelerationAligned as h, isCubicBezier2d as i, toPath as j, make as m, toCurves as t };
|
|
@@ -2,6 +2,7 @@ import { P as Pipeable } from '../shared/curvy.BN-oFBsc.mjs';
|
|
|
2
2
|
import { Matrix4x4 } from '../matrix/matrix4x4.mjs';
|
|
3
3
|
import { CubicPath2d } from '../path/cubic2d.mjs';
|
|
4
4
|
import { Vector2 } from '../vector/vector2.mjs';
|
|
5
|
+
import { Bezier2d } from './bezier2d.mjs';
|
|
5
6
|
import '../shared/curvy.Bf5TIk31.mjs';
|
|
6
7
|
import '../vector/vector4.mjs';
|
|
7
8
|
import '../matrix/matrix3x3.mjs';
|
|
@@ -32,5 +33,6 @@ declare const prepend: {
|
|
|
32
33
|
};
|
|
33
34
|
declare const withTriplicatedEndpoints: (p: Basis2d) => Basis2d;
|
|
34
35
|
declare const toPath: (p: Basis2d) => CubicPath2d;
|
|
36
|
+
declare const toBezier: (p: Basis2d) => Bezier2d;
|
|
35
37
|
|
|
36
|
-
export { type Basis2d, append, characteristic, fromArray, isBasis2d, make, prepend, toPath, withTriplicatedEndpoints };
|
|
38
|
+
export { type Basis2d, append, characteristic, fromArray, isBasis2d, make, prepend, toBezier, toPath, withTriplicatedEndpoints };
|
|
@@ -2,6 +2,7 @@ import { P as Pipeable } from '../shared/curvy.BN-oFBsc.js';
|
|
|
2
2
|
import { Matrix4x4 } from '../matrix/matrix4x4.js';
|
|
3
3
|
import { CubicPath2d } from '../path/cubic2d.js';
|
|
4
4
|
import { Vector2 } from '../vector/vector2.js';
|
|
5
|
+
import { Bezier2d } from './bezier2d.js';
|
|
5
6
|
import '../shared/curvy.Bf5TIk31.js';
|
|
6
7
|
import '../vector/vector4.js';
|
|
7
8
|
import '../matrix/matrix3x3.js';
|
|
@@ -32,5 +33,6 @@ declare const prepend: {
|
|
|
32
33
|
};
|
|
33
34
|
declare const withTriplicatedEndpoints: (p: Basis2d) => Basis2d;
|
|
34
35
|
declare const toPath: (p: Basis2d) => CubicPath2d;
|
|
36
|
+
declare const toBezier: (p: Basis2d) => Bezier2d;
|
|
35
37
|
|
|
36
|
-
export { type Basis2d, append, characteristic, fromArray, isBasis2d, make, prepend, toPath, withTriplicatedEndpoints };
|
|
38
|
+
export { type Basis2d, append, characteristic, fromArray, isBasis2d, make, prepend, toBezier, toPath, withTriplicatedEndpoints };
|
package/dist/splines/basis2d.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as roundDown, d as dual, P as Pipeable, i as invariant } from '../shared/curvy.DLOeble8.mjs';
|
|
2
2
|
import { make as make$2 } from '../matrix/matrix4x4.mjs';
|
|
3
3
|
import { fromCurves } from '../path/cubic2d.mjs';
|
|
4
|
-
import { t as toCurves } from '../shared/curvy.
|
|
4
|
+
import { t as toCurves, f as fromSpline } from '../shared/curvy.BZXFCKQe.mjs';
|
|
5
5
|
import '../shared/curvy.BrrC9QVB.mjs';
|
|
6
6
|
import '../shared/curvy.BPOevbwG.mjs';
|
|
7
7
|
import '../shared/curvy.B1zfBfvf.mjs';
|
|
@@ -73,6 +73,7 @@ const withTriplicatedEndpoints$1 = (p) => {
|
|
|
73
73
|
]);
|
|
74
74
|
};
|
|
75
75
|
const toPath$1 = (p) => fromCurves(...toCurves(p, characteristic$1, 1));
|
|
76
|
+
const toBezier$1 = (p) => fromSpline(p, characteristic$1, 1);
|
|
76
77
|
|
|
77
78
|
const characteristic = characteristic$1;
|
|
78
79
|
const isBasis2d = isBasis2d$1;
|
|
@@ -82,5 +83,6 @@ const append = append$1;
|
|
|
82
83
|
const prepend = prepend$1;
|
|
83
84
|
const withTriplicatedEndpoints = withTriplicatedEndpoints$1;
|
|
84
85
|
const toPath = toPath$1;
|
|
86
|
+
const toBezier = toBezier$1;
|
|
85
87
|
|
|
86
|
-
export { append, characteristic, fromArray, isBasis2d, make, prepend, toPath, withTriplicatedEndpoints };
|
|
88
|
+
export { append, characteristic, fromArray, isBasis2d, make, prepend, toBezier, toPath, withTriplicatedEndpoints };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { P as Pipeable } from '../shared/curvy.BN-oFBsc.mjs';
|
|
2
|
+
import { Matrix4x4 } from '../matrix/matrix4x4.mjs';
|
|
2
3
|
import { CubicPath2d } from '../path/cubic2d.mjs';
|
|
3
4
|
import { Vector2 } from '../vector/vector2.mjs';
|
|
4
|
-
import '../curve/cubic2d.mjs';
|
|
5
5
|
import '../shared/curvy.Bf5TIk31.mjs';
|
|
6
|
+
import '../vector/vector4.mjs';
|
|
7
|
+
import '../matrix/matrix3x3.mjs';
|
|
8
|
+
import '../vector/vector3.mjs';
|
|
9
|
+
import '../matrix/matrix2x2.mjs';
|
|
10
|
+
import '../curve/cubic2d.mjs';
|
|
6
11
|
import '../interval.mjs';
|
|
7
12
|
import '../shared/curvy.DwHW5Fqt.mjs';
|
|
8
|
-
import '../vector/vector3.mjs';
|
|
9
|
-
import '../vector/vector4.mjs';
|
|
10
13
|
|
|
11
14
|
declare const Bezier2dTypeId: unique symbol;
|
|
12
15
|
type Bezier2dTypeId = typeof Bezier2dTypeId;
|
|
@@ -15,8 +18,10 @@ interface Bezier2d extends Pipeable {
|
|
|
15
18
|
readonly [Bezier2dTypeId]: Bezier2dTypeId;
|
|
16
19
|
[Symbol.iterator](): IterableIterator<Vector2>;
|
|
17
20
|
}
|
|
21
|
+
declare const characteristic: Matrix4x4;
|
|
18
22
|
declare const make: (p0: Vector2, p1: Vector2, p2: Vector2, p3: Vector2) => Bezier2d;
|
|
19
23
|
declare const fromArray: (points: ReadonlyArray<Vector2>) => Bezier2d;
|
|
24
|
+
declare const fromSpline: (points: Iterable<Vector2>, matrix: Matrix4x4, stride: 1 | 2 | 3) => Bezier2d;
|
|
20
25
|
declare const isCubicBezier2d: (p: unknown) => p is Bezier2d;
|
|
21
26
|
declare const append: {
|
|
22
27
|
(p1: Vector2, p2: Vector2, p3: Vector2): (p: Bezier2d) => Bezier2d;
|
|
@@ -40,4 +45,4 @@ declare const appendAccelerationAligned: {
|
|
|
40
45
|
};
|
|
41
46
|
declare const toPath: (p: Bezier2d) => CubicPath2d;
|
|
42
47
|
|
|
43
|
-
export { type Bezier2d, append, appendAccelerationAligned, appendCurvatureMirrored, appendTangentAligned, appendVelocityAligned, fromArray, isCubicBezier2d, make, toPath };
|
|
48
|
+
export { type Bezier2d, append, appendAccelerationAligned, appendCurvatureMirrored, appendTangentAligned, appendVelocityAligned, characteristic, fromArray, fromSpline, isCubicBezier2d, make, toPath };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { P as Pipeable } from '../shared/curvy.BN-oFBsc.js';
|
|
2
|
+
import { Matrix4x4 } from '../matrix/matrix4x4.js';
|
|
2
3
|
import { CubicPath2d } from '../path/cubic2d.js';
|
|
3
4
|
import { Vector2 } from '../vector/vector2.js';
|
|
4
|
-
import '../curve/cubic2d.js';
|
|
5
5
|
import '../shared/curvy.Bf5TIk31.js';
|
|
6
|
+
import '../vector/vector4.js';
|
|
7
|
+
import '../matrix/matrix3x3.js';
|
|
8
|
+
import '../vector/vector3.js';
|
|
9
|
+
import '../matrix/matrix2x2.js';
|
|
10
|
+
import '../curve/cubic2d.js';
|
|
6
11
|
import '../interval.js';
|
|
7
12
|
import '../shared/curvy.CkJRVnqj.js';
|
|
8
|
-
import '../vector/vector3.js';
|
|
9
|
-
import '../vector/vector4.js';
|
|
10
13
|
|
|
11
14
|
declare const Bezier2dTypeId: unique symbol;
|
|
12
15
|
type Bezier2dTypeId = typeof Bezier2dTypeId;
|
|
@@ -15,8 +18,10 @@ interface Bezier2d extends Pipeable {
|
|
|
15
18
|
readonly [Bezier2dTypeId]: Bezier2dTypeId;
|
|
16
19
|
[Symbol.iterator](): IterableIterator<Vector2>;
|
|
17
20
|
}
|
|
21
|
+
declare const characteristic: Matrix4x4;
|
|
18
22
|
declare const make: (p0: Vector2, p1: Vector2, p2: Vector2, p3: Vector2) => Bezier2d;
|
|
19
23
|
declare const fromArray: (points: ReadonlyArray<Vector2>) => Bezier2d;
|
|
24
|
+
declare const fromSpline: (points: Iterable<Vector2>, matrix: Matrix4x4, stride: 1 | 2 | 3) => Bezier2d;
|
|
20
25
|
declare const isCubicBezier2d: (p: unknown) => p is Bezier2d;
|
|
21
26
|
declare const append: {
|
|
22
27
|
(p1: Vector2, p2: Vector2, p3: Vector2): (p: Bezier2d) => Bezier2d;
|
|
@@ -40,4 +45,4 @@ declare const appendAccelerationAligned: {
|
|
|
40
45
|
};
|
|
41
46
|
declare const toPath: (p: Bezier2d) => CubicPath2d;
|
|
42
47
|
|
|
43
|
-
export { type Bezier2d, append, appendAccelerationAligned, appendCurvatureMirrored, appendTangentAligned, appendVelocityAligned, fromArray, isCubicBezier2d, make, toPath };
|
|
48
|
+
export { type Bezier2d, append, appendAccelerationAligned, appendCurvatureMirrored, appendTangentAligned, appendVelocityAligned, characteristic, fromArray, fromSpline, isCubicBezier2d, make, toPath };
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { make as make$3 } from '../vector/vector2.mjs';
|
|
5
|
-
import { t as toCurves } from '../shared/curvy.DN9ptodP.mjs';
|
|
1
|
+
export { b as append, h as appendAccelerationAligned, e as appendCurvatureMirrored, d as appendTangentAligned, g as appendVelocityAligned, c as characteristic, a as fromArray, f as fromSpline, i as isCubicBezier2d, m as make, j as toPath } from '../shared/curvy.BZXFCKQe.mjs';
|
|
2
|
+
import '../shared/curvy.DLOeble8.mjs';
|
|
3
|
+
import '../matrix/matrix4x4.mjs';
|
|
6
4
|
import '../shared/curvy.BrrC9QVB.mjs';
|
|
7
5
|
import '../shared/curvy.BPOevbwG.mjs';
|
|
8
6
|
import '../shared/curvy.B1zfBfvf.mjs';
|
|
9
7
|
import '../shared/curvy.DTco5vku.mjs';
|
|
10
8
|
import '../shared/curvy.DV4S13Cq.mjs';
|
|
9
|
+
import '../path/cubic2d.mjs';
|
|
11
10
|
import '../curve/cubic2d.mjs';
|
|
12
11
|
import '../interval.mjs';
|
|
13
12
|
import '../shared/curvy.DmVFTi0N.mjs';
|
|
@@ -15,100 +14,8 @@ import '../polynomial/cubic.mjs';
|
|
|
15
14
|
import '../shared/curvy.ZjG-q57I.mjs';
|
|
16
15
|
import '../shared/curvy.O57gIOmy.mjs';
|
|
17
16
|
import '../polynomial/quadratic.mjs';
|
|
17
|
+
import '../vector/vector2.mjs';
|
|
18
18
|
import '../curve/linear2d.mjs';
|
|
19
19
|
import '../polynomial/linear.mjs';
|
|
20
20
|
import '../curve/quadratic2d.mjs';
|
|
21
21
|
import '../vector/vector4.mjs';
|
|
22
|
-
|
|
23
|
-
const characteristic = make$2(
|
|
24
|
-
1,
|
|
25
|
-
0,
|
|
26
|
-
0,
|
|
27
|
-
0,
|
|
28
|
-
-3,
|
|
29
|
-
3,
|
|
30
|
-
0,
|
|
31
|
-
0,
|
|
32
|
-
3,
|
|
33
|
-
-6,
|
|
34
|
-
3,
|
|
35
|
-
0,
|
|
36
|
-
-1,
|
|
37
|
-
3,
|
|
38
|
-
-3,
|
|
39
|
-
1
|
|
40
|
-
);
|
|
41
|
-
const Bezier2dTypeId = Symbol("curvy/splines/bezier2d");
|
|
42
|
-
class Bezier2dImpl extends Pipeable {
|
|
43
|
-
[Bezier2dTypeId] = Bezier2dTypeId;
|
|
44
|
-
points;
|
|
45
|
-
constructor(points) {
|
|
46
|
-
invariant(points.length >= 4, "cubic splines requires 4 or more points");
|
|
47
|
-
invariant(
|
|
48
|
-
points.length % 3 === 1,
|
|
49
|
-
"cubic splines requires (n * 3) + 1 points"
|
|
50
|
-
);
|
|
51
|
-
super();
|
|
52
|
-
this.points = points;
|
|
53
|
-
}
|
|
54
|
-
[Symbol.iterator]() {
|
|
55
|
-
return this.points[Symbol.iterator]();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const isCubicBezier2d$1 = (p) => typeof p === "object" && p !== null && Bezier2dTypeId in p;
|
|
59
|
-
const make$1 = (p0, p1, p2, p3) => new Bezier2dImpl([p0, p1, p2, p3]);
|
|
60
|
-
const fromArray$1 = (points) => new Bezier2dImpl(points);
|
|
61
|
-
const append$1 = dual(
|
|
62
|
-
4,
|
|
63
|
-
(p, p1, p2, p3) => new Bezier2dImpl(
|
|
64
|
-
(p instanceof Bezier2dImpl ? p.points : Array.from(p)).concat(p1, p2, p3)
|
|
65
|
-
)
|
|
66
|
-
);
|
|
67
|
-
const appendTangentAligned$1 = dual(4, (p, a, p5, p6) => {
|
|
68
|
-
const points = p instanceof Bezier2dImpl ? p.points : Array.from(p);
|
|
69
|
-
const p2 = points[points.length - 2];
|
|
70
|
-
const p3 = points[points.length - 1];
|
|
71
|
-
const p4 = make$3(p3.x + (p3.x - p2.x) * a, p3.y + (p3.y - p2.y) * a);
|
|
72
|
-
return append$1(p, p4, p5, p6);
|
|
73
|
-
});
|
|
74
|
-
const appendCurvatureAligned = dual(
|
|
75
|
-
4,
|
|
76
|
-
(p, a, b, p6) => {
|
|
77
|
-
const points = p instanceof Bezier2dImpl ? p.points : Array.from(p);
|
|
78
|
-
const p1 = points[points.length - 3];
|
|
79
|
-
const p2 = points[points.length - 2];
|
|
80
|
-
const p3 = points[points.length - 1];
|
|
81
|
-
const p4 = make$3(p3.x + (p3.x - p2.x) * a, p3.y + (p3.y - p2.y) * a);
|
|
82
|
-
const p5 = make$3(
|
|
83
|
-
p3.x + (p3.x - p2.x) * (2 * a + a ** 2 + b / 2) + (p1.x - p2.x) * a ** 2,
|
|
84
|
-
p3.y + (p3.y - p2.y) * (2 * a + a ** 2 + b / 2) + (p1.y - p2.y) * a ** 2
|
|
85
|
-
);
|
|
86
|
-
return append$1(p, p4, p5, p6);
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
const appendVelocityAligned$1 = dual(
|
|
90
|
-
3,
|
|
91
|
-
(p, p5, p6) => appendTangentAligned$1(p, 1, p5, p6)
|
|
92
|
-
);
|
|
93
|
-
const appendAccelerationAligned$1 = dual(2, (p, p6) => {
|
|
94
|
-
const points = p instanceof Bezier2dImpl ? p.points : Array.from(p);
|
|
95
|
-
const p1 = points[points.length - 3];
|
|
96
|
-
const p2 = points[points.length - 2];
|
|
97
|
-
const p3 = points[points.length - 1];
|
|
98
|
-
const p4 = make$3(2 * p3.x - p2.x, 2 * p3.y - p2.y);
|
|
99
|
-
const p5 = make$3(p1.x + 4 * (p3.x - p2.x), p1.y + 4 * (p3.y - p2.y));
|
|
100
|
-
return append$1(p, p4, p5, p6);
|
|
101
|
-
});
|
|
102
|
-
const toPath$1 = (p) => fromCurves(...toCurves(p, characteristic, 3));
|
|
103
|
-
|
|
104
|
-
const make = make$1;
|
|
105
|
-
const fromArray = fromArray$1;
|
|
106
|
-
const isCubicBezier2d = isCubicBezier2d$1;
|
|
107
|
-
const append = append$1;
|
|
108
|
-
const appendTangentAligned = appendTangentAligned$1;
|
|
109
|
-
const appendCurvatureMirrored = appendCurvatureAligned;
|
|
110
|
-
const appendVelocityAligned = appendVelocityAligned$1;
|
|
111
|
-
const appendAccelerationAligned = appendAccelerationAligned$1;
|
|
112
|
-
const toPath = toPath$1;
|
|
113
|
-
|
|
114
|
-
export { append, appendAccelerationAligned, appendCurvatureMirrored, appendTangentAligned, appendVelocityAligned, fromArray, isCubicBezier2d, make, toPath };
|
|
@@ -2,6 +2,7 @@ import { P as Pipeable } from '../shared/curvy.BN-oFBsc.mjs';
|
|
|
2
2
|
import { Matrix4x4 } from '../matrix/matrix4x4.mjs';
|
|
3
3
|
import { CubicPath2d } from '../path/cubic2d.mjs';
|
|
4
4
|
import { Vector2 } from '../vector/vector2.mjs';
|
|
5
|
+
import { Bezier2d } from './bezier2d.mjs';
|
|
5
6
|
import '../shared/curvy.Bf5TIk31.mjs';
|
|
6
7
|
import '../vector/vector4.mjs';
|
|
7
8
|
import '../matrix/matrix3x3.mjs';
|
|
@@ -40,5 +41,9 @@ declare const toPath: {
|
|
|
40
41
|
(scale: number): (c: Cardinal2d) => CubicPath2d;
|
|
41
42
|
(c: Cardinal2d, scale?: number): CubicPath2d;
|
|
42
43
|
};
|
|
44
|
+
declare const toBezier: {
|
|
45
|
+
(p: Cardinal2d): Bezier2d;
|
|
46
|
+
(p: Cardinal2d, scale: number): Bezier2d;
|
|
47
|
+
};
|
|
43
48
|
|
|
44
|
-
export { type Cardinal2d, append, catRomCharacteristic, characteristic, fromArray, isCardinal2d, make, prepend, toPath, withDuplicatedEndpoints, withReflectedEndpoints };
|
|
49
|
+
export { type Cardinal2d, append, catRomCharacteristic, characteristic, fromArray, isCardinal2d, make, prepend, toBezier, toPath, withDuplicatedEndpoints, withReflectedEndpoints };
|
|
@@ -2,6 +2,7 @@ import { P as Pipeable } from '../shared/curvy.BN-oFBsc.js';
|
|
|
2
2
|
import { Matrix4x4 } from '../matrix/matrix4x4.js';
|
|
3
3
|
import { CubicPath2d } from '../path/cubic2d.js';
|
|
4
4
|
import { Vector2 } from '../vector/vector2.js';
|
|
5
|
+
import { Bezier2d } from './bezier2d.js';
|
|
5
6
|
import '../shared/curvy.Bf5TIk31.js';
|
|
6
7
|
import '../vector/vector4.js';
|
|
7
8
|
import '../matrix/matrix3x3.js';
|
|
@@ -40,5 +41,9 @@ declare const toPath: {
|
|
|
40
41
|
(scale: number): (c: Cardinal2d) => CubicPath2d;
|
|
41
42
|
(c: Cardinal2d, scale?: number): CubicPath2d;
|
|
42
43
|
};
|
|
44
|
+
declare const toBezier: {
|
|
45
|
+
(p: Cardinal2d): Bezier2d;
|
|
46
|
+
(p: Cardinal2d, scale: number): Bezier2d;
|
|
47
|
+
};
|
|
43
48
|
|
|
44
|
-
export { type Cardinal2d, append, catRomCharacteristic, characteristic, fromArray, isCardinal2d, make, prepend, toPath, withDuplicatedEndpoints, withReflectedEndpoints };
|
|
49
|
+
export { type Cardinal2d, append, catRomCharacteristic, characteristic, fromArray, isCardinal2d, make, prepend, toBezier, toPath, withDuplicatedEndpoints, withReflectedEndpoints };
|
|
@@ -2,7 +2,7 @@ import { d as dual, P as Pipeable, i as invariant } from '../shared/curvy.DLOebl
|
|
|
2
2
|
import { make as make$2 } from '../matrix/matrix4x4.mjs';
|
|
3
3
|
import { fromCurves } from '../path/cubic2d.mjs';
|
|
4
4
|
import { subtract, scale, add } from '../vector/vector2.mjs';
|
|
5
|
-
import { t as toCurves } from '../shared/curvy.
|
|
5
|
+
import { t as toCurves, f as fromSpline } from '../shared/curvy.BZXFCKQe.mjs';
|
|
6
6
|
import '../shared/curvy.BrrC9QVB.mjs';
|
|
7
7
|
import '../shared/curvy.BPOevbwG.mjs';
|
|
8
8
|
import '../shared/curvy.B1zfBfvf.mjs';
|
|
@@ -101,6 +101,11 @@ const toPath$1 = dual(
|
|
|
101
101
|
)
|
|
102
102
|
)
|
|
103
103
|
);
|
|
104
|
+
const toBezier$1 = (p, scale = 0.5) => fromSpline(
|
|
105
|
+
p,
|
|
106
|
+
scale === 0.5 ? catRomCharacteristic$1 : characteristic$1(scale),
|
|
107
|
+
1
|
|
108
|
+
);
|
|
104
109
|
|
|
105
110
|
const characteristic = characteristic$1;
|
|
106
111
|
const catRomCharacteristic = catRomCharacteristic$1;
|
|
@@ -112,5 +117,6 @@ const prepend = prepend$1;
|
|
|
112
117
|
const withDuplicatedEndpoints = withDuplicatedEndpoints$1;
|
|
113
118
|
const withReflectedEndpoints = withReflectedEndpoints$1;
|
|
114
119
|
const toPath = toPath$1;
|
|
120
|
+
const toBezier = toBezier$1;
|
|
115
121
|
|
|
116
|
-
export { append, catRomCharacteristic, characteristic, fromArray, isCardinal2d, make, prepend, toPath, withDuplicatedEndpoints, withReflectedEndpoints };
|
|
122
|
+
export { append, catRomCharacteristic, characteristic, fromArray, isCardinal2d, make, prepend, toBezier, toPath, withDuplicatedEndpoints, withReflectedEndpoints };
|
|
@@ -2,6 +2,7 @@ import { P as Pipeable } from '../shared/curvy.BN-oFBsc.mjs';
|
|
|
2
2
|
import { Matrix4x4 } from '../matrix/matrix4x4.mjs';
|
|
3
3
|
import { CubicPath2d } from '../path/cubic2d.mjs';
|
|
4
4
|
import { Vector2 } from '../vector/vector2.mjs';
|
|
5
|
+
import { Bezier2d } from './bezier2d.mjs';
|
|
5
6
|
import '../shared/curvy.Bf5TIk31.mjs';
|
|
6
7
|
import '../vector/vector4.mjs';
|
|
7
8
|
import '../matrix/matrix3x3.mjs';
|
|
@@ -27,5 +28,6 @@ declare const append: {
|
|
|
27
28
|
(p: Hermite2d, p1: Vector2, v1: Vector2): Hermite2d;
|
|
28
29
|
};
|
|
29
30
|
declare const toPath: (p: Hermite2d) => CubicPath2d;
|
|
31
|
+
declare const toBezier: (p: Hermite2d) => Bezier2d;
|
|
30
32
|
|
|
31
|
-
export { type Hermite2d, append, characteristic, fromArray, isHermite2d, make, toPath };
|
|
33
|
+
export { type Hermite2d, append, characteristic, fromArray, isHermite2d, make, toBezier, toPath };
|
|
@@ -2,6 +2,7 @@ import { P as Pipeable } from '../shared/curvy.BN-oFBsc.js';
|
|
|
2
2
|
import { Matrix4x4 } from '../matrix/matrix4x4.js';
|
|
3
3
|
import { CubicPath2d } from '../path/cubic2d.js';
|
|
4
4
|
import { Vector2 } from '../vector/vector2.js';
|
|
5
|
+
import { Bezier2d } from './bezier2d.js';
|
|
5
6
|
import '../shared/curvy.Bf5TIk31.js';
|
|
6
7
|
import '../vector/vector4.js';
|
|
7
8
|
import '../matrix/matrix3x3.js';
|
|
@@ -27,5 +28,6 @@ declare const append: {
|
|
|
27
28
|
(p: Hermite2d, p1: Vector2, v1: Vector2): Hermite2d;
|
|
28
29
|
};
|
|
29
30
|
declare const toPath: (p: Hermite2d) => CubicPath2d;
|
|
31
|
+
declare const toBezier: (p: Hermite2d) => Bezier2d;
|
|
30
32
|
|
|
31
|
-
export { type Hermite2d, append, characteristic, fromArray, isHermite2d, make, toPath };
|
|
33
|
+
export { type Hermite2d, append, characteristic, fromArray, isHermite2d, make, toBezier, toPath };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { d as dual, P as Pipeable, i as invariant } from '../shared/curvy.DLOeble8.mjs';
|
|
2
2
|
import { make as make$2 } from '../matrix/matrix4x4.mjs';
|
|
3
3
|
import { fromCurves } from '../path/cubic2d.mjs';
|
|
4
|
-
import { t as toCurves } from '../shared/curvy.
|
|
4
|
+
import { t as toCurves, f as fromSpline } from '../shared/curvy.BZXFCKQe.mjs';
|
|
5
5
|
import '../shared/curvy.BrrC9QVB.mjs';
|
|
6
6
|
import '../shared/curvy.BPOevbwG.mjs';
|
|
7
7
|
import '../shared/curvy.B1zfBfvf.mjs';
|
|
@@ -63,6 +63,7 @@ const append$1 = dual(3, (p, p1, v1) => {
|
|
|
63
63
|
return new Hermite2dImpl(points.concat(p1, v1));
|
|
64
64
|
});
|
|
65
65
|
const toPath$1 = (p) => fromCurves(...toCurves(p, characteristic$1, 2));
|
|
66
|
+
const toBezier$1 = (p) => fromSpline(p, characteristic$1, 2);
|
|
66
67
|
|
|
67
68
|
const characteristic = characteristic$1;
|
|
68
69
|
const make = make$1;
|
|
@@ -70,5 +71,6 @@ const fromArray = fromArray$1;
|
|
|
70
71
|
const isHermite2d = isHermite2d$1;
|
|
71
72
|
const append = append$1;
|
|
72
73
|
const toPath = toPath$1;
|
|
74
|
+
const toBezier = toBezier$1;
|
|
73
75
|
|
|
74
|
-
export { append, characteristic, fromArray, isHermite2d, make, toPath };
|
|
76
|
+
export { append, characteristic, fromArray, isHermite2d, make, toBezier, toPath };
|
package/package.json
CHANGED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { fromPolynomials } from '../curve/cubic2d.mjs';
|
|
2
|
-
import { vectorProductLeft } from '../matrix/matrix4x4.mjs';
|
|
3
|
-
import { fromVector } from '../polynomial/cubic.mjs';
|
|
4
|
-
import { make } from '../vector/vector4.mjs';
|
|
5
|
-
|
|
6
|
-
function* toCurves(points, matrix, stride) {
|
|
7
|
-
let p0;
|
|
8
|
-
let p1;
|
|
9
|
-
let p2;
|
|
10
|
-
let p3;
|
|
11
|
-
for (const point of points) {
|
|
12
|
-
if (p0 === void 0) {
|
|
13
|
-
p0 = point;
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
if (p1 === void 0) {
|
|
17
|
-
p1 = point;
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
if (p2 === void 0) {
|
|
21
|
-
p2 = point;
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
p3 = point;
|
|
25
|
-
yield fromPolynomials(
|
|
26
|
-
fromVector(
|
|
27
|
-
vectorProductLeft(
|
|
28
|
-
matrix,
|
|
29
|
-
make(p0.x, p1.x, p2.x, p3.x)
|
|
30
|
-
)
|
|
31
|
-
),
|
|
32
|
-
fromVector(
|
|
33
|
-
vectorProductLeft(
|
|
34
|
-
matrix,
|
|
35
|
-
make(p0.y, p1.y, p2.y, p3.y)
|
|
36
|
-
)
|
|
37
|
-
)
|
|
38
|
-
);
|
|
39
|
-
if (stride === 1) {
|
|
40
|
-
p0 = p1;
|
|
41
|
-
p1 = p2;
|
|
42
|
-
p2 = p3;
|
|
43
|
-
} else if (stride === 2) {
|
|
44
|
-
p0 = p2;
|
|
45
|
-
p1 = p3;
|
|
46
|
-
p2 = void 0;
|
|
47
|
-
} else if (stride === 3) {
|
|
48
|
-
p0 = p3;
|
|
49
|
-
p1 = void 0;
|
|
50
|
-
p2 = void 0;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export { toCurves as t };
|