curvy 1.0.9 → 2.0.0-alpha.2

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 (173) hide show
  1. package/dist/characteristic/index.d.mts +88 -0
  2. package/dist/characteristic/index.mjs +2 -0
  3. package/dist/curve/index.d.mts +2 -0
  4. package/dist/curve/index.mjs +2 -0
  5. package/dist/interval/index.d.mts +3 -0
  6. package/dist/interval/index.mjs +3 -0
  7. package/dist/matrix/index.d.mts +2 -0
  8. package/dist/matrix/index.mjs +267 -0
  9. package/dist/matrix/index.mjs.map +1 -0
  10. package/dist/number.d.mts +280 -0
  11. package/dist/number.mjs +140 -0
  12. package/dist/number.mjs.map +1 -0
  13. package/dist/path/index.d.mts +261 -0
  14. package/dist/path/index.mjs +325 -0
  15. package/dist/path/index.mjs.map +1 -0
  16. package/dist/polynomial/index.d.mts +2 -0
  17. package/dist/polynomial/index.mjs +3 -0
  18. package/dist/shared/characteristic-B9nCh_cx.mjs +104 -0
  19. package/dist/shared/characteristic-B9nCh_cx.mjs.map +1 -0
  20. package/dist/shared/chunk-25Hzd3z8.mjs +13 -0
  21. package/dist/shared/cubic-BajUY0JT.d.mts +1100 -0
  22. package/dist/shared/cubic-CpHAx8cC.mjs +479 -0
  23. package/dist/shared/cubic-CpHAx8cC.mjs.map +1 -0
  24. package/dist/shared/interval-05CR6eBf.mjs +421 -0
  25. package/dist/shared/interval-05CR6eBf.mjs.map +1 -0
  26. package/dist/shared/interval-Dy-RMEE3.d.mts +533 -0
  27. package/dist/shared/interval2d-8IBZnUOq.mjs +108 -0
  28. package/dist/shared/interval2d-8IBZnUOq.mjs.map +1 -0
  29. package/dist/shared/interval2d-C2id9u31.d.mts +172 -0
  30. package/dist/shared/matrix4x4-Ck2WROK-.mjs +440 -0
  31. package/dist/shared/matrix4x4-Ck2WROK-.mjs.map +1 -0
  32. package/dist/shared/matrix4x4-Dm_tSiH1.d.mts +1183 -0
  33. package/dist/shared/quadratic-CamozcFc.mjs +330 -0
  34. package/dist/shared/quadratic-CamozcFc.mjs.map +1 -0
  35. package/dist/shared/rationalCubic2d-B6g97ryJ.d.mts +308 -0
  36. package/dist/shared/rationalCubic2d-BEgUGSFf.mjs +295 -0
  37. package/dist/shared/rationalCubic2d-BEgUGSFf.mjs.map +1 -0
  38. package/dist/shared/rationalCubic2d-Bys2Uory.mjs +695 -0
  39. package/dist/shared/rationalCubic2d-Bys2Uory.mjs.map +1 -0
  40. package/dist/shared/rationalCubic2d-DlQfBURs.d.mts +818 -0
  41. package/dist/shared/solution-CrtLfqEq.mjs +306 -0
  42. package/dist/shared/solution-CrtLfqEq.mjs.map +1 -0
  43. package/dist/shared/solution-sNQ-ZVhN.d.mts +251 -0
  44. package/dist/{pipe.d.mts → shared/utils-MCckigYk.d.mts} +44 -26
  45. package/dist/shared/vector2-CL1HDdPr.mjs +187 -0
  46. package/dist/shared/vector2-CL1HDdPr.mjs.map +1 -0
  47. package/dist/shared/vector2-DPUY3_eA.d.mts +470 -0
  48. package/dist/shared/vector2.internal-DU_E808S.mjs +97 -0
  49. package/dist/shared/vector2.internal-DU_E808S.mjs.map +1 -0
  50. package/dist/shared/vector3-D-tv_aKL.mjs +204 -0
  51. package/dist/shared/vector3-D-tv_aKL.mjs.map +1 -0
  52. package/dist/shared/vector3-DqeOZtOB.d.mts +703 -0
  53. package/dist/shared/vector4-5KbjoHVj.mjs +109 -0
  54. package/dist/shared/vector4-5KbjoHVj.mjs.map +1 -0
  55. package/dist/shared/vector4.internal-5XcaX12X.mjs +163 -0
  56. package/dist/shared/vector4.internal-5XcaX12X.mjs.map +1 -0
  57. package/dist/solution/index.d.mts +2 -0
  58. package/dist/solution/index.mjs +2 -0
  59. package/dist/splines/index.d.mts +701 -0
  60. package/dist/splines/index.mjs +734 -0
  61. package/dist/splines/index.mjs.map +1 -0
  62. package/dist/utils.d.mts +2 -205
  63. package/dist/utils.mjs +88 -52
  64. package/dist/utils.mjs.map +1 -1
  65. package/dist/vector/index.d.mts +3 -0
  66. package/dist/vector/index.mjs +4 -0
  67. package/package.json +49 -92
  68. package/dist/curve/cubic2d.d.mts +0 -109
  69. package/dist/curve/cubic2d.d.ts +0 -109
  70. package/dist/curve/cubic2d.mjs +0 -80
  71. package/dist/curve/cubic2d.mjs.map +0 -1
  72. package/dist/curve/linear2d.d.mts +0 -94
  73. package/dist/curve/linear2d.d.ts +0 -94
  74. package/dist/curve/linear2d.mjs +0 -46
  75. package/dist/curve/linear2d.mjs.map +0 -1
  76. package/dist/curve/quadratic2d.d.mts +0 -117
  77. package/dist/curve/quadratic2d.d.ts +0 -117
  78. package/dist/curve/quadratic2d.mjs +0 -82
  79. package/dist/curve/quadratic2d.mjs.map +0 -1
  80. package/dist/interval.d.mts +0 -251
  81. package/dist/interval.d.ts +0 -251
  82. package/dist/interval.mjs +0 -86
  83. package/dist/interval.mjs.map +0 -1
  84. package/dist/matrix/matrix2x2.d.mts +0 -320
  85. package/dist/matrix/matrix2x2.d.ts +0 -320
  86. package/dist/matrix/matrix2x2.mjs +0 -25
  87. package/dist/matrix/matrix2x2.mjs.map +0 -1
  88. package/dist/matrix/matrix3x3.d.mts +0 -370
  89. package/dist/matrix/matrix3x3.d.ts +0 -370
  90. package/dist/matrix/matrix3x3.mjs +0 -28
  91. package/dist/matrix/matrix3x3.mjs.map +0 -1
  92. package/dist/matrix/matrix4x4.d.mts +0 -381
  93. package/dist/matrix/matrix4x4.d.ts +0 -381
  94. package/dist/matrix/matrix4x4.mjs +0 -178
  95. package/dist/matrix/matrix4x4.mjs.map +0 -1
  96. package/dist/path/cubic2d.d.mts +0 -95
  97. package/dist/path/cubic2d.d.ts +0 -95
  98. package/dist/path/cubic2d.mjs +0 -60
  99. package/dist/path/cubic2d.mjs.map +0 -1
  100. package/dist/path/linear2d.d.mts +0 -95
  101. package/dist/path/linear2d.d.ts +0 -95
  102. package/dist/path/linear2d.mjs +0 -53
  103. package/dist/path/linear2d.mjs.map +0 -1
  104. package/dist/path/quadratic2d.d.mts +0 -95
  105. package/dist/path/quadratic2d.d.ts +0 -95
  106. package/dist/path/quadratic2d.mjs +0 -57
  107. package/dist/path/quadratic2d.mjs.map +0 -1
  108. package/dist/pipe.d.ts +0 -58
  109. package/dist/pipe.mjs +0 -92
  110. package/dist/pipe.mjs.map +0 -1
  111. package/dist/polynomial/cubic.d.mts +0 -7
  112. package/dist/polynomial/cubic.d.ts +0 -7
  113. package/dist/polynomial/cubic.mjs +0 -133
  114. package/dist/polynomial/cubic.mjs.map +0 -1
  115. package/dist/polynomial/linear.d.mts +0 -7
  116. package/dist/polynomial/linear.d.ts +0 -7
  117. package/dist/polynomial/linear.mjs +0 -24
  118. package/dist/polynomial/linear.mjs.map +0 -1
  119. package/dist/polynomial/quadratic.d.mts +0 -7
  120. package/dist/polynomial/quadratic.d.ts +0 -7
  121. package/dist/polynomial/quadratic.mjs +0 -27
  122. package/dist/polynomial/quadratic.mjs.map +0 -1
  123. package/dist/shared/curvy.Bf5TIk31.d.mts +0 -22
  124. package/dist/shared/curvy.Bf5TIk31.d.ts +0 -22
  125. package/dist/shared/curvy.BkkW8Tx9.mjs +0 -102
  126. package/dist/shared/curvy.BkkW8Tx9.mjs.map +0 -1
  127. package/dist/shared/curvy.BxdGW9he.mjs +0 -116
  128. package/dist/shared/curvy.BxdGW9he.mjs.map +0 -1
  129. package/dist/shared/curvy.C_sCeg9J.mjs +0 -66
  130. package/dist/shared/curvy.C_sCeg9J.mjs.map +0 -1
  131. package/dist/shared/curvy.Cg8lZVUz.d.ts +0 -688
  132. package/dist/shared/curvy.DCt1gGII.mjs +0 -147
  133. package/dist/shared/curvy.DCt1gGII.mjs.map +0 -1
  134. package/dist/shared/curvy.DJ4xO0al.mjs +0 -63
  135. package/dist/shared/curvy.DJ4xO0al.mjs.map +0 -1
  136. package/dist/shared/curvy.DmVFTi0N.mjs +0 -35
  137. package/dist/shared/curvy.DmVFTi0N.mjs.map +0 -1
  138. package/dist/shared/curvy.FDaj5rlj.d.mts +0 -688
  139. package/dist/shared/curvy.lktriTpx.mjs +0 -101
  140. package/dist/shared/curvy.lktriTpx.mjs.map +0 -1
  141. package/dist/shared/curvy.mLFprrGm.mjs +0 -85
  142. package/dist/shared/curvy.mLFprrGm.mjs.map +0 -1
  143. package/dist/shared/curvy.r6f1j287.mjs +0 -76
  144. package/dist/shared/curvy.r6f1j287.mjs.map +0 -1
  145. package/dist/splines/basis2d.d.mts +0 -130
  146. package/dist/splines/basis2d.d.ts +0 -130
  147. package/dist/splines/basis2d.mjs +0 -90
  148. package/dist/splines/basis2d.mjs.map +0 -1
  149. package/dist/splines/bezier2d.d.mts +0 -182
  150. package/dist/splines/bezier2d.d.ts +0 -182
  151. package/dist/splines/bezier2d.mjs +0 -23
  152. package/dist/splines/bezier2d.mjs.map +0 -1
  153. package/dist/splines/cardinal2d.d.mts +0 -178
  154. package/dist/splines/cardinal2d.d.ts +0 -178
  155. package/dist/splines/cardinal2d.mjs +0 -114
  156. package/dist/splines/cardinal2d.mjs.map +0 -1
  157. package/dist/splines/hermite2d.d.mts +0 -124
  158. package/dist/splines/hermite2d.d.ts +0 -124
  159. package/dist/splines/hermite2d.mjs +0 -63
  160. package/dist/splines/hermite2d.mjs.map +0 -1
  161. package/dist/utils.d.ts +0 -205
  162. package/dist/vector/vector2.d.mts +0 -324
  163. package/dist/vector/vector2.d.ts +0 -324
  164. package/dist/vector/vector2.mjs +0 -30
  165. package/dist/vector/vector2.mjs.map +0 -1
  166. package/dist/vector/vector3.d.mts +0 -417
  167. package/dist/vector/vector3.d.ts +0 -417
  168. package/dist/vector/vector3.mjs +0 -38
  169. package/dist/vector/vector3.mjs.map +0 -1
  170. package/dist/vector/vector4.d.mts +0 -205
  171. package/dist/vector/vector4.d.ts +0 -205
  172. package/dist/vector/vector4.mjs +0 -20
  173. package/dist/vector/vector4.mjs.map +0 -1
@@ -0,0 +1,734 @@
1
+ import { t as __exportAll } from "../shared/chunk-25Hzd3z8.mjs";
2
+ import { Pipeable, dual, invariant } from "../utils.mjs";
3
+ import { epsEquals } from "../number.mjs";
4
+ import { a as makeWeighted, i as make$10, o as scale, s as subtract, t as add } from "../shared/vector2-CL1HDdPr.mjs";
5
+ import { t as make$11 } from "../shared/vector3-D-tv_aKL.mjs";
6
+ import { n as transpose, t as make$12 } from "../shared/vector4-5KbjoHVj.mjs";
7
+ import { a as vectorProductLeft, i as multiply, t as inverse } from "../shared/matrix4x4-Ck2WROK-.mjs";
8
+ import { o as none, s as one } from "../shared/solution-CrtLfqEq.mjs";
9
+ import { n as fromBezierPoints, s as fromPolynomials } from "../shared/rationalCubic2d-Bys2Uory.mjs";
10
+ import { a as cubicCardinal, i as cubicBezier, o as cubicHermite, r as cubicBasisSpline, t as apply } from "../shared/characteristic-B9nCh_cx.mjs";
11
+ import { i as make$13, t as fromArray$10 } from "../shared/rationalCubic2d-BEgUGSFf.mjs";
12
+ //#region src/splines/rationalBezier2d.internal.ts
13
+ const RationalBezier2dTypeId = Symbol("curvy/splines/rationalBezier2d");
14
+ var RationalBezier2dImpl = class extends Pipeable {
15
+ [RationalBezier2dTypeId] = RationalBezier2dTypeId;
16
+ homogeneous;
17
+ constructor(homogeneous) {
18
+ invariant(homogeneous.length >= 4, "rational cubic splines require 4 or more points");
19
+ invariant(homogeneous.length % 3 === 1, "rational cubic splines require (n * 3) + 1 points");
20
+ super();
21
+ this.homogeneous = homogeneous;
22
+ }
23
+ *[Symbol.iterator]() {
24
+ for (const h of this.homogeneous) yield makeWeighted(h.x / h.z, h.y / h.z, h.z);
25
+ }
26
+ };
27
+ const isRationalBezier2d$1 = (p) => typeof p === "object" && p !== null && RationalBezier2dTypeId in p;
28
+ const lift = (p) => make$11(p.x * p.weight, p.y * p.weight, p.weight);
29
+ const make$9 = (p0, p1, p2, p3) => new RationalBezier2dImpl([
30
+ lift(p0),
31
+ lift(p1),
32
+ lift(p2),
33
+ lift(p3)
34
+ ]);
35
+ const fromArray$9 = (points) => new RationalBezier2dImpl(points.map(lift));
36
+ const fromPoints$1 = (p0, p1, p2, p3) => new RationalBezier2dImpl([
37
+ make$11(p0.x, p0.y, 1),
38
+ make$11(p1.x, p1.y, 1),
39
+ make$11(p2.x, p2.y, 1),
40
+ make$11(p3.x, p3.y, 1)
41
+ ]);
42
+ const fromBezier$1 = (b) => {
43
+ const homogeneous = [];
44
+ for (const p of b) homogeneous.push(make$11(p.x, p.y, 1));
45
+ return new RationalBezier2dImpl(homogeneous);
46
+ };
47
+ const homogeneousOf = (r) => r instanceof RationalBezier2dImpl ? r.homogeneous : Array.from(r, lift);
48
+ const toPath$9 = (r) => {
49
+ const homogeneous = homogeneousOf(r);
50
+ const segmentCount = (homogeneous.length - 1) / 3;
51
+ const curves = [];
52
+ for (let i = 0; i < segmentCount; i++) {
53
+ const base = i * 3;
54
+ const h0 = homogeneous[base];
55
+ const h1 = homogeneous[base + 1];
56
+ const h2 = homogeneous[base + 2];
57
+ const h3 = homogeneous[base + 3];
58
+ curves.push(fromBezierPoints(makeWeighted(h0.x / h0.z, h0.y / h0.z, h0.z), makeWeighted(h1.x / h1.z, h1.y / h1.z, h1.z), makeWeighted(h2.x / h2.z, h2.y / h2.z, h2.z), makeWeighted(h3.x / h3.z, h3.y / h3.z, h3.z)));
59
+ }
60
+ return fromArray$10(curves);
61
+ };
62
+ const subdivide$3 = dual(2, (r, u) => {
63
+ invariant(u > 0 && u < 1, "subdivide parameter u must be in the open interval (0, 1)");
64
+ const homogeneous = homogeneousOf(r);
65
+ const t = u * ((homogeneous.length - 1) / 3);
66
+ const i = Math.floor(t);
67
+ const localT = t - i;
68
+ if (localT === 0) return [new RationalBezier2dImpl(homogeneous.slice(0, i * 3 + 1)), new RationalBezier2dImpl(homogeneous.slice(i * 3))];
69
+ const p0 = homogeneous[i * 3];
70
+ const p1 = homogeneous[i * 3 + 1];
71
+ const p2 = homogeneous[i * 3 + 2];
72
+ const p3 = homogeneous[i * 3 + 3];
73
+ const q0x = p0.x + (p1.x - p0.x) * localT;
74
+ const q0y = p0.y + (p1.y - p0.y) * localT;
75
+ const q0w = p0.z + (p1.z - p0.z) * localT;
76
+ const q1x = p1.x + (p2.x - p1.x) * localT;
77
+ const q1y = p1.y + (p2.y - p1.y) * localT;
78
+ const q1w = p1.z + (p2.z - p1.z) * localT;
79
+ const q2x = p2.x + (p3.x - p2.x) * localT;
80
+ const q2y = p2.y + (p3.y - p2.y) * localT;
81
+ const q2w = p2.z + (p3.z - p2.z) * localT;
82
+ const r0x = q0x + (q1x - q0x) * localT;
83
+ const r0y = q0y + (q1y - q0y) * localT;
84
+ const r0w = q0w + (q1w - q0w) * localT;
85
+ const r1x = q1x + (q2x - q1x) * localT;
86
+ const r1y = q1y + (q2y - q1y) * localT;
87
+ const r1w = q1w + (q2w - q1w) * localT;
88
+ const sx = r0x + (r1x - r0x) * localT;
89
+ const sy = r0y + (r1y - r0y) * localT;
90
+ const sw = r0w + (r1w - r0w) * localT;
91
+ const q0 = make$11(q0x, q0y, q0w);
92
+ const r0 = make$11(r0x, r0y, r0w);
93
+ const sLeft = make$11(sx, sy, sw);
94
+ const sRight = make$11(sx, sy, sw);
95
+ const r1 = make$11(r1x, r1y, r1w);
96
+ const q2 = make$11(q2x, q2y, q2w);
97
+ const leftPoints = [
98
+ ...homogeneous.slice(0, i * 3 + 1),
99
+ q0,
100
+ r0,
101
+ sLeft
102
+ ];
103
+ const rightPoints = [
104
+ sRight,
105
+ r1,
106
+ q2,
107
+ ...homogeneous.slice(i * 3 + 3)
108
+ ];
109
+ return [new RationalBezier2dImpl(leftPoints), new RationalBezier2dImpl(rightPoints)];
110
+ });
111
+ const toBezierPoints = (r) => {
112
+ const homogeneous = homogeneousOf(r);
113
+ const w0 = homogeneous[0].z;
114
+ const points = [];
115
+ for (const h of homogeneous) {
116
+ if (!epsEquals(h.z, w0)) return none;
117
+ points.push(make$10(h.x / h.z, h.y / h.z));
118
+ }
119
+ return one(points);
120
+ };
121
+ //#endregion
122
+ //#region src/splines/util.ts
123
+ function* toPointQuads(points, stride) {
124
+ let p0;
125
+ let p1;
126
+ let p2;
127
+ let p3;
128
+ for (const point of points) {
129
+ if (p0 === void 0) {
130
+ p0 = point;
131
+ continue;
132
+ }
133
+ if (p1 === void 0) {
134
+ p1 = point;
135
+ continue;
136
+ }
137
+ if (p2 === void 0) {
138
+ p2 = point;
139
+ continue;
140
+ }
141
+ p3 = point;
142
+ yield [
143
+ p0,
144
+ p1,
145
+ p2,
146
+ p3
147
+ ];
148
+ if (stride === 1) {
149
+ p0 = p1;
150
+ p1 = p2;
151
+ p2 = p3;
152
+ } else if (stride === 2) {
153
+ p0 = p2;
154
+ p1 = p3;
155
+ p2 = void 0;
156
+ } else if (stride === 3) {
157
+ p0 = p3;
158
+ p1 = void 0;
159
+ p2 = void 0;
160
+ }
161
+ }
162
+ }
163
+ function* toCurves(points, matrix, stride) {
164
+ for (const quad of toPointQuads(points, stride)) yield fromPolynomials(...apply(matrix, ...transpose(quad, (p) => [p.x, p.y])));
165
+ }
166
+ //#endregion
167
+ //#region src/splines/bezier2d.internal.ts
168
+ const characteristicInverse = inverse(cubicBezier);
169
+ const conversionCache = /* @__PURE__ */ new WeakMap();
170
+ const getConversionMatrix = (source) => {
171
+ let combined = conversionCache.get(source);
172
+ if (combined === void 0) {
173
+ combined = multiply(characteristicInverse, source);
174
+ conversionCache.set(source, combined);
175
+ }
176
+ return combined;
177
+ };
178
+ const Bezier2dTypeId = Symbol("curvy/splines/bezier2d");
179
+ var Bezier2dImpl = class extends Pipeable {
180
+ [Bezier2dTypeId] = Bezier2dTypeId;
181
+ points;
182
+ constructor(points) {
183
+ invariant(points.length >= 4, "cubic splines requires 4 or more points");
184
+ invariant(points.length % 3 === 1, "cubic splines requires (n * 3) + 1 points");
185
+ super();
186
+ this.points = points;
187
+ }
188
+ [Symbol.iterator]() {
189
+ return this.points[Symbol.iterator]();
190
+ }
191
+ };
192
+ const isCubicBezier2d$1 = (p) => typeof p === "object" && p !== null && Bezier2dTypeId in p;
193
+ const make$8 = (p0, p1, p2, p3) => new Bezier2dImpl([
194
+ p0,
195
+ p1,
196
+ p2,
197
+ p3
198
+ ]);
199
+ const fromArray$8 = (points) => new Bezier2dImpl(points);
200
+ const append$7 = dual(4, (p, p1, p2, p3) => new Bezier2dImpl((p instanceof Bezier2dImpl ? p.points : Array.from(p)).concat(p1, p2, p3)));
201
+ const fromBasis = (p, matrix, stride) => {
202
+ const conversion = getConversionMatrix(matrix);
203
+ const points = [];
204
+ let x;
205
+ let y;
206
+ for (const [p0, p1, p2, p3] of toPointQuads(p, stride)) {
207
+ x = vectorProductLeft(conversion, make$12(p0.x, p1.x, p2.x, p3.x));
208
+ y = vectorProductLeft(conversion, make$12(p0.y, p1.y, p2.y, p3.y));
209
+ points.push(make$10(x.x, y.x), make$10(x.y, y.y), make$10(x.z, y.z));
210
+ }
211
+ if (x && y) points.push(make$10(x.w, y.w));
212
+ return fromArray$8(points);
213
+ };
214
+ const appendTangentAligned$1 = dual(4, (p, a, p5, p6) => {
215
+ const points = p instanceof Bezier2dImpl ? p.points : Array.from(p);
216
+ const p2 = points[points.length - 2];
217
+ const p3 = points[points.length - 1];
218
+ return append$7(p, make$10(p3.x + (p3.x - p2.x) * a, p3.y + (p3.y - p2.y) * a), p5, p6);
219
+ });
220
+ const appendCurvatureAligned$1 = dual(4, (p, a, b, p6) => {
221
+ const points = p instanceof Bezier2dImpl ? p.points : Array.from(p);
222
+ const p1 = points[points.length - 3];
223
+ const p2 = points[points.length - 2];
224
+ const p3 = points[points.length - 1];
225
+ return append$7(p, make$10(p3.x + (p3.x - p2.x) * a, p3.y + (p3.y - p2.y) * a), make$10(p3.x + (p3.x - p2.x) * (2 * a + a ** 2 + b / 2) + (p1.x - p2.x) * a ** 2, p3.y + (p3.y - p2.y) * (2 * a + a ** 2 + b / 2) + (p1.y - p2.y) * a ** 2), p6);
226
+ });
227
+ const appendVelocityAligned$1 = dual(3, (p, p5, p6) => appendTangentAligned$1(p, 1, p5, p6));
228
+ const appendAccelerationAligned$1 = dual(2, (p, p6) => {
229
+ const points = p instanceof Bezier2dImpl ? p.points : Array.from(p);
230
+ const p1 = points[points.length - 3];
231
+ const p2 = points[points.length - 2];
232
+ const p3 = points[points.length - 1];
233
+ return append$7(p, make$10(2 * p3.x - p2.x, 2 * p3.y - p2.y), make$10(p1.x + 4 * (p3.x - p2.x), p1.y + 4 * (p3.y - p2.y)), p6);
234
+ });
235
+ const toPath$8 = (p) => make$13(...toCurves(p, cubicBezier, 3));
236
+ const fromRational$1 = (r) => {
237
+ const points = toBezierPoints(r);
238
+ if (points._tag === "none") return points;
239
+ return one(new Bezier2dImpl(points.value));
240
+ };
241
+ const subdivide$2 = dual(2, (b, u) => {
242
+ invariant(u > 0 && u < 1, "subdivide parameter u must be in the open interval (0, 1)");
243
+ const points = b instanceof Bezier2dImpl ? b.points : Array.from(b);
244
+ const t = u * ((points.length - 1) / 3);
245
+ const i = Math.floor(t);
246
+ const localT = t - i;
247
+ if (localT === 0) return [new Bezier2dImpl(points.slice(0, i * 3 + 1)), new Bezier2dImpl(points.slice(i * 3))];
248
+ const p0 = points[i * 3];
249
+ const p1 = points[i * 3 + 1];
250
+ const p2 = points[i * 3 + 2];
251
+ const p3 = points[i * 3 + 3];
252
+ const q0x = p0.x + (p1.x - p0.x) * localT;
253
+ const q0y = p0.y + (p1.y - p0.y) * localT;
254
+ const q1x = p1.x + (p2.x - p1.x) * localT;
255
+ const q1y = p1.y + (p2.y - p1.y) * localT;
256
+ const q2x = p2.x + (p3.x - p2.x) * localT;
257
+ const q2y = p2.y + (p3.y - p2.y) * localT;
258
+ const r0x = q0x + (q1x - q0x) * localT;
259
+ const r0y = q0y + (q1y - q0y) * localT;
260
+ const r1x = q1x + (q2x - q1x) * localT;
261
+ const r1y = q1y + (q2y - q1y) * localT;
262
+ const sx = r0x + (r1x - r0x) * localT;
263
+ const sy = r0y + (r1y - r0y) * localT;
264
+ const q0 = make$10(q0x, q0y);
265
+ const r0 = make$10(r0x, r0y);
266
+ const sLeft = make$10(sx, sy);
267
+ const sRight = make$10(sx, sy);
268
+ const r1 = make$10(r1x, r1y);
269
+ const q2 = make$10(q2x, q2y);
270
+ const leftPoints = [
271
+ ...points.slice(0, i * 3 + 1),
272
+ q0,
273
+ r0,
274
+ sLeft
275
+ ];
276
+ const rightPoints = [
277
+ sRight,
278
+ r1,
279
+ q2,
280
+ ...points.slice(i * 3 + 3)
281
+ ];
282
+ return [new Bezier2dImpl(leftPoints), new Bezier2dImpl(rightPoints)];
283
+ });
284
+ //#endregion
285
+ //#region src/splines/bezier2d.ts
286
+ var bezier2d_exports = /* @__PURE__ */ __exportAll({
287
+ append: () => append$6,
288
+ appendAccelerationAligned: () => appendAccelerationAligned,
289
+ appendCurvatureAligned: () => appendCurvatureAligned,
290
+ appendTangentAligned: () => appendTangentAligned,
291
+ appendVelocityAligned: () => appendVelocityAligned,
292
+ fromArray: () => fromArray$7,
293
+ fromRational: () => fromRational,
294
+ isCubicBezier2d: () => isCubicBezier2d,
295
+ make: () => make$7,
296
+ subdivide: () => subdivide$1,
297
+ toPath: () => toPath$7
298
+ });
299
+ /**
300
+ * Creates a new `Bezier2d` instance.
301
+ *
302
+ * @param p0 - The first control point.
303
+ * @param p1 - The second control point.
304
+ * @param p2 - The third control point.
305
+ * @param p3 - The fourth control point.
306
+ * @returns A new `Bezier2d` instance.
307
+ * @since 1.0.0
308
+ */
309
+ const make$7 = make$8;
310
+ /**
311
+ * Creates a new `Bezier2d` instance from an array of control points.
312
+ *
313
+ * @param points - The control points.
314
+ * @returns A new `Bezier2d` instance.
315
+ * @since 1.0.0
316
+ */
317
+ const fromArray$7 = fromArray$8;
318
+ /**
319
+ * Checks if a value is a `Bezier2d`.
320
+ *
321
+ * @param p - The value to check.
322
+ * @returns `true` if the value is a `Bezier2d`, `false` otherwise.
323
+ * @since 1.0.0
324
+ */
325
+ const isCubicBezier2d = isCubicBezier2d$1;
326
+ const append$6 = append$7;
327
+ const appendTangentAligned = appendTangentAligned$1;
328
+ const appendCurvatureAligned = appendCurvatureAligned$1;
329
+ const appendVelocityAligned = appendVelocityAligned$1;
330
+ const appendAccelerationAligned = appendAccelerationAligned$1;
331
+ /**
332
+ * Converts a `Bezier2d` to a `CubicPath2d`.
333
+ *
334
+ * @param p - The `Bezier2d` to convert.
335
+ * @returns A new `CubicPath2d` instance representing the same curve as the `Bezier2d`.
336
+ * @since 1.0.0
337
+ */
338
+ const toPath$7 = toPath$8;
339
+ /**
340
+ * Attempts to lower a `RationalBezier2d` to a non-rational `Bezier2d`.
341
+ *
342
+ * Succeeds with `Solution.one(bezier)` when the rational curve's weights are
343
+ * uniform (the curve is mathematically a polynomial Bézier) and returns
344
+ * `Solution.none` otherwise — the rational curve cannot be represented
345
+ * exactly by a non-rational cubic Bézier.
346
+ *
347
+ * @param r - The rational bezier to convert.
348
+ * @returns Either a `Bezier2d` instance or `Solution.none`.
349
+ * @since 2.1.0
350
+ */
351
+ const fromRational = fromRational$1;
352
+ const subdivide$1 = subdivide$2;
353
+ //#endregion
354
+ //#region src/splines/cardinal2d.internal.ts
355
+ const Cardinal2dTypeId = Symbol.for("curvy/splines/cardinal2d");
356
+ var Cardinal2dImpl = class extends Pipeable {
357
+ [Cardinal2dTypeId] = Cardinal2dTypeId;
358
+ points;
359
+ constructor(points) {
360
+ invariant(points.length >= 2, "cardinal splines requires 2 or more points");
361
+ super();
362
+ this.points = points;
363
+ }
364
+ [Symbol.iterator]() {
365
+ return this.points[Symbol.iterator]();
366
+ }
367
+ };
368
+ const isCardinal2d$1 = (p) => typeof p === "object" && p !== null && Cardinal2dTypeId in p;
369
+ const make$6 = (...points) => new Cardinal2dImpl(points);
370
+ const fromArray$6 = (points) => new Cardinal2dImpl(points);
371
+ const append$5 = dual((args) => isCardinal2d$1(args[0]), (p, ...points) => new Cardinal2dImpl([...p, ...points]));
372
+ const prepend$5 = dual((args) => isCardinal2d$1(args[0]), (p, ...points) => new Cardinal2dImpl([...points, ...p]));
373
+ const withDuplicatedEndpoints$1 = (p) => {
374
+ const points = p instanceof Cardinal2dImpl ? p.points : [...p];
375
+ return new Cardinal2dImpl([
376
+ points[0],
377
+ ...points,
378
+ points[points.length - 1]
379
+ ]);
380
+ };
381
+ const withReflectedEndpoints$1 = dual((args) => isCardinal2d$1(args[0]), (p, scale$1 = 1) => {
382
+ if (scale$1 === 0) return withDuplicatedEndpoints$1(p);
383
+ const points = p instanceof Cardinal2dImpl ? p.points : [...p];
384
+ const p0 = points[0];
385
+ const p1 = points[1];
386
+ const p2 = points[points.length - 2];
387
+ const p3 = points[points.length - 1];
388
+ return new Cardinal2dImpl([
389
+ subtract(p1, p0).pipe(scale(scale$1), add(p0)),
390
+ ...points,
391
+ subtract(p2, p3).pipe(scale(scale$1), add(p3))
392
+ ]);
393
+ });
394
+ const toPath$6 = dual((args) => isCardinal2d$1(args[0]), (p, scale = .5) => make$13(...toCurves(p, cubicCardinal(scale), 1)));
395
+ const toBezier$5 = (p, scale = .5) => fromBasis(p, cubicCardinal(scale), 1);
396
+ //#endregion
397
+ //#region src/splines/cardinal2d.ts
398
+ var cardinal2d_exports = /* @__PURE__ */ __exportAll({
399
+ append: () => append$4,
400
+ fromArray: () => fromArray$5,
401
+ isCardinal2d: () => isCardinal2d,
402
+ make: () => make$5,
403
+ prepend: () => prepend$4,
404
+ toBezier: () => toBezier$4,
405
+ toPath: () => toPath$5,
406
+ withDuplicatedEndpoints: () => withDuplicatedEndpoints,
407
+ withReflectedEndpoints: () => withReflectedEndpoints
408
+ });
409
+ /**
410
+ * Checks if a value is a `Cardinal2d`.
411
+ *
412
+ * @param p - The value to check.
413
+ * @returns `true` if the value is a `Cardinal2d`, `false` otherwise.
414
+ * @since 1.0.0
415
+ */
416
+ const isCardinal2d = isCardinal2d$1;
417
+ /**
418
+ * Creates a new `Cardinal2d` instance.
419
+ *
420
+ * @param p0 - The first control point.
421
+ * @param p1 - The second control point.
422
+ * @param points - The remaining control points.
423
+ * @returns A new `Cardinal2d` instance.
424
+ * @since 1.0.0
425
+ */
426
+ const make$5 = make$6;
427
+ /**
428
+ * Creates a new `Cardinal2d` instance from an array of control points.
429
+ *
430
+ * @param points - The control points.
431
+ * @returns A new `Cardinal2d` instance.
432
+ * @since 1.0.0
433
+ */
434
+ const fromArray$5 = fromArray$6;
435
+ const append$4 = append$5;
436
+ const prepend$4 = prepend$5;
437
+ /**
438
+ * Doubles the endpoints of a `Cardinal2d` spline.
439
+ *
440
+ * @param c - The `Cardinal2d` to duplicate the endpoints of.
441
+ * @returns A new `Cardinal2d` instance with the duplicated endpoints.
442
+ * @since 1.0.0
443
+ */
444
+ const withDuplicatedEndpoints = withDuplicatedEndpoints$1;
445
+ const withReflectedEndpoints = withReflectedEndpoints$1;
446
+ const toPath$5 = toPath$6;
447
+ const toBezier$4 = toBezier$5;
448
+ //#endregion
449
+ //#region src/splines/hermite2d.internal.ts
450
+ const Hermite2dTypeId = Symbol("curvy/splines/hermite2d");
451
+ var Hermite2dImpl = class extends Pipeable {
452
+ [Hermite2dTypeId] = Hermite2dTypeId;
453
+ points;
454
+ constructor(points) {
455
+ invariant(points.length >= 4, "hermite splines requires 4 or more points");
456
+ invariant(points.length % 2 === 0, "hermite splines requires (n * 2) points");
457
+ super();
458
+ this.points = points;
459
+ }
460
+ [Symbol.iterator]() {
461
+ return this.points[Symbol.iterator]();
462
+ }
463
+ };
464
+ const isHermite2d$1 = (p) => typeof p === "object" && p !== null && Hermite2dTypeId in p;
465
+ const make$4 = (p0, v0, p1, v1) => new Hermite2dImpl([
466
+ p0,
467
+ v0,
468
+ p1,
469
+ v1
470
+ ]);
471
+ const fromArray$4 = (points) => new Hermite2dImpl(points);
472
+ const append$3 = dual(3, (p, p1, v1) => {
473
+ return new Hermite2dImpl((p instanceof Hermite2dImpl ? p.points : Array.from(p)).concat(p1, v1));
474
+ });
475
+ const prepend$3 = dual(3, (p, p0, v0) => {
476
+ const points = p instanceof Hermite2dImpl ? p.points : Array.from(p);
477
+ return new Hermite2dImpl([p0, v0].concat(points));
478
+ });
479
+ const toPath$4 = (p) => make$13(...toCurves(p, cubicHermite, 2));
480
+ const toBezier$3 = (p) => fromBasis(p, cubicHermite, 2);
481
+ //#endregion
482
+ //#region src/splines/hermite2d.ts
483
+ var hermite2d_exports = /* @__PURE__ */ __exportAll({
484
+ append: () => append$2,
485
+ fromArray: () => fromArray$3,
486
+ isHermite2d: () => isHermite2d,
487
+ make: () => make$3,
488
+ prepend: () => prepend$2,
489
+ toBezier: () => toBezier$2,
490
+ toPath: () => toPath$3
491
+ });
492
+ /**
493
+ * Checks if a value is a `Hermite2d`.
494
+ *
495
+ * @param p - The value to check.
496
+ * @returns `true` if the value is a `Hermite2d`, `false` otherwise.
497
+ * @since 1.0.0
498
+ */
499
+ const isHermite2d = isHermite2d$1;
500
+ /**
501
+ * Creates a new `Hermite2d` instance.
502
+ *
503
+ * @param p0 - The first control point.
504
+ * @param v0 - The first tangent vector.
505
+ * @param p1 - The second control point.
506
+ * @param v1 - The second tangent vector.
507
+ * @returns A new `Hermite2d` instance.
508
+ * @since 1.0.0
509
+ */
510
+ const make$3 = make$4;
511
+ /**
512
+ * Creates a new `Hermite2d` instance from an array of control points.
513
+ *
514
+ * @param points - The control points.
515
+ * @returns A new `Hermite2d` instance.
516
+ * @since 1.0.0
517
+ */
518
+ const fromArray$3 = fromArray$4;
519
+ const append$2 = append$3;
520
+ const prepend$2 = prepend$3;
521
+ /**
522
+ * Creates a new `CubicPath2d` instance from a `Hermite2d`.
523
+ *
524
+ * @param p - The `Hermite2d` to convert.
525
+ * @returns A new `CubicPath2d` instance.
526
+ * @since 1.0.0
527
+ */
528
+ const toPath$3 = toPath$4;
529
+ /**
530
+ * Converts a `Hermite2d` to a `Bezier2d`.
531
+ *
532
+ * @param p - The `Hermite2d` to convert.
533
+ * @returns A new `Bezier2d` instance.
534
+ * @since 1.0.0
535
+ */
536
+ const toBezier$2 = toBezier$3;
537
+ //#endregion
538
+ //#region src/splines/basis2d.internal.ts
539
+ const Basis2dTypeId = Symbol("curvy/splines/basis2d");
540
+ var Basis2dImpl = class extends Pipeable {
541
+ [Basis2dTypeId] = Basis2dTypeId;
542
+ points;
543
+ constructor(points) {
544
+ invariant(points.length >= 4, "basis splines requires 4 or more points");
545
+ super();
546
+ this.points = points;
547
+ }
548
+ [Symbol.iterator]() {
549
+ return this.points[Symbol.iterator]();
550
+ }
551
+ };
552
+ const isBasis2d$1 = (p) => typeof p === "object" && p !== null && Basis2dTypeId in p;
553
+ const make$2 = (p0, p1, p2, p3) => new Basis2dImpl([
554
+ p0,
555
+ p1,
556
+ p2,
557
+ p3
558
+ ]);
559
+ const fromArray$2 = (points) => new Basis2dImpl(points);
560
+ const append$1 = dual((args) => isBasis2d$1(args[0]), (p, ...points) => new Basis2dImpl([...p, ...points]));
561
+ const prepend$1 = dual((args) => isBasis2d$1(args[0]), (p, ...points) => new Basis2dImpl([...points, ...p]));
562
+ const withTriplicatedEndpoints$1 = (p) => {
563
+ const points = p instanceof Basis2dImpl ? p.points : [...p];
564
+ return new Basis2dImpl([
565
+ points[0],
566
+ points[0],
567
+ ...points,
568
+ points[points.length - 1],
569
+ points[points.length - 1]
570
+ ]);
571
+ };
572
+ const toPath$2 = (p) => make$13(...toCurves(p, cubicBasisSpline, 1));
573
+ const toBezier$1 = (p) => fromBasis(p, cubicBasisSpline, 1);
574
+ //#endregion
575
+ //#region src/splines/basis2d.ts
576
+ var basis2d_exports = /* @__PURE__ */ __exportAll({
577
+ append: () => append,
578
+ fromArray: () => fromArray$1,
579
+ isBasis2d: () => isBasis2d,
580
+ make: () => make$1,
581
+ prepend: () => prepend,
582
+ toBezier: () => toBezier,
583
+ toPath: () => toPath$1,
584
+ withTriplicatedEndpoints: () => withTriplicatedEndpoints
585
+ });
586
+ /**
587
+ * Checks if a value is a `Basis2d`.
588
+ *
589
+ * @param p - The value to check.
590
+ * @returns `true` if the value is a `Basis2d`, `false` otherwise.
591
+ * @since 1.0.0
592
+ */
593
+ const isBasis2d = isBasis2d$1;
594
+ /**
595
+ * Creates a new `Basis2d` instance.
596
+ *
597
+ * @param p0 - The first control point.
598
+ * @param p1 - The second control point.
599
+ * @param p2 - The third control point.
600
+ * @param p3 - The fourth control point.
601
+ * @returns A new `Basis2d` instance.
602
+ * @since 1.0.0
603
+ */
604
+ const make$1 = make$2;
605
+ /**
606
+ * Creates a new `Basis2d` instance from an array of control points.
607
+ *
608
+ * @param points - The control points.
609
+ * @returns A new `Basis2d` instance.
610
+ * @since 1.0.0
611
+ */
612
+ const fromArray$1 = fromArray$2;
613
+ const append = append$1;
614
+ const prepend = prepend$1;
615
+ /**
616
+ * Triplicates the endpoints of a `Basis2d`.
617
+ *
618
+ * This is useful for creating a closed loop spline.
619
+ *
620
+ * @param p - The `Basis2d` to triplicate the endpoints of.
621
+ * @returns A new `Basis2d` instance with the triplicated endpoints.
622
+ * @since 1.0.0
623
+ */
624
+ const withTriplicatedEndpoints = withTriplicatedEndpoints$1;
625
+ /**
626
+ * Creates a new `Path2d` from a `Basis2d`.
627
+ *
628
+ * @param p - The `Basis2d` to convert to a `Path2d`.
629
+ * @returns A new `Path2d` instance.
630
+ * @since 1.0.0
631
+ */
632
+ const toPath$1 = toPath$2;
633
+ /**
634
+ * Converts a `Basis2d` to a `Bezier2d`.
635
+ *
636
+ * @param p - The `Basis2d` to convert.
637
+ * @returns A new `Bezier2d` instance.
638
+ * @since 1.0.0
639
+ */
640
+ const toBezier = toBezier$1;
641
+ //#endregion
642
+ //#region src/splines/rationalBezier2d.ts
643
+ var rationalBezier2d_exports = /* @__PURE__ */ __exportAll({
644
+ fromArray: () => fromArray,
645
+ fromBezier: () => fromBezier,
646
+ fromPoints: () => fromPoints,
647
+ isRationalBezier2d: () => isRationalBezier2d,
648
+ make: () => make,
649
+ subdivide: () => subdivide,
650
+ toPath: () => toPath
651
+ });
652
+ /**
653
+ * Checks if a value is a `RationalBezier2d`.
654
+ *
655
+ * @param p - The value to check.
656
+ * @returns `true` if the value is a `RationalBezier2d`, `false` otherwise.
657
+ * @since 2.1.0
658
+ */
659
+ const isRationalBezier2d = isRationalBezier2d$1;
660
+ /**
661
+ * Creates a new single-segment `RationalBezier2d` from four weighted control points.
662
+ *
663
+ * Equal weights produce a curve coincident with the corresponding polynomial
664
+ * cubic Bézier; unequal weights produce a true rational curve capable of
665
+ * representing conics exactly.
666
+ *
667
+ * @param p0 - The first weighted control point (curve start).
668
+ * @param p1 - The second weighted control point (start handle).
669
+ * @param p2 - The third weighted control point (end handle).
670
+ * @param p3 - The fourth weighted control point (curve end).
671
+ * @returns A new `RationalBezier2d` instance.
672
+ * @since 2.1.0
673
+ */
674
+ const make = make$9;
675
+ /**
676
+ * Creates a new `RationalBezier2d` from an array of weighted control points.
677
+ *
678
+ * The array must contain `(n * 3) + 1` entries to describe `n` joined cubic
679
+ * segments.
680
+ *
681
+ * @param points - The weighted control points.
682
+ * @returns A new `RationalBezier2d` instance.
683
+ * @since 2.1.0
684
+ */
685
+ const fromArray = fromArray$9;
686
+ /**
687
+ * Creates a new single-segment `RationalBezier2d` from four points with all
688
+ * weights equal to one.
689
+ *
690
+ * Convenience constructor for callers who want the rational evaluator but
691
+ * don't yet have non-unit weights — the resulting curve is mathematically
692
+ * equivalent to the corresponding `Bezier2d.make(p0, p1, p2, p3)` and can
693
+ * later be subdivided or recombined using the rational machinery without
694
+ * conversion overhead.
695
+ *
696
+ * @param p0 - The first control point (curve start).
697
+ * @param p1 - The second control point (start handle).
698
+ * @param p2 - The third control point (end handle).
699
+ * @param p3 - The fourth control point (curve end).
700
+ * @returns A new `RationalBezier2d` with unit weights.
701
+ * @since 2.1.0
702
+ */
703
+ const fromPoints = fromPoints$1;
704
+ /**
705
+ * Lifts a non-rational `Bezier2d` into a `RationalBezier2d` by assigning
706
+ * unit weight to every control point. The two curves trace the same path.
707
+ *
708
+ * @param b - The non-rational bezier to lift.
709
+ * @returns A new `RationalBezier2d` with unit weights.
710
+ * @since 2.1.0
711
+ */
712
+ const fromBezier = fromBezier$1;
713
+ /**
714
+ * Converts a `RationalBezier2d` to a `RationalCubicPath2d`.
715
+ *
716
+ * Each segment's four homogeneous control points are expanded into three
717
+ * per-segment monomial cubic polynomials — `x`, `y`, and the shared
718
+ * denominator `w` — yielding a path whose evaluator is three Horner passes
719
+ * plus two divisions per call.
720
+ *
721
+ * Mirrors `Bezier2d.toPath`: spline construction is converted to path
722
+ * evaluation form, and forward evaluation thereafter routes through the
723
+ * path's `solve`.
724
+ *
725
+ * @param r - The rational bezier to convert.
726
+ * @returns A new `RationalCubicPath2d` instance representing the same curve.
727
+ * @since 2.1.0
728
+ */
729
+ const toPath = toPath$9;
730
+ const subdivide = subdivide$3;
731
+ //#endregion
732
+ export { basis2d_exports as Basis2d, bezier2d_exports as Bezier2d, cardinal2d_exports as Cardinal2d, hermite2d_exports as Hermite2d, rationalBezier2d_exports as RationalBezier2d };
733
+
734
+ //# sourceMappingURL=index.mjs.map