curvy 2.0.0-alpha.11 → 2.0.0-alpha.12

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.
@@ -1,2 +1,2 @@
1
- import { S as linear2d_exports, g as quadratic2d_exports, o as cubic2d_exports, r as rationalCubic2d_exports } from "../shared/rationalCubic2d-IroMR6AA.mjs";
1
+ import { C as linear2d_exports, g as quadratic2d_exports, o as cubic2d_exports, r as rationalCubic2d_exports } from "../shared/rationalCubic2d-D5g3_hTV.mjs";
2
2
  export { cubic2d_exports as CubicCurve2d, linear2d_exports as LinearCurve2d, quadratic2d_exports as QuadraticCurve2d, rationalCubic2d_exports as RationalCubicCurve2d };
@@ -3,381 +3,10 @@ import { Pipeable, dual, invariant } from "../utils.mjs";
3
3
  import { epsEquals } from "../number.mjs";
4
4
  import { p as unit } from "../shared/interval-Dm35Xhy4.mjs";
5
5
  import { o as none, r as isNone, s as one } from "../shared/solution-B6KY1E7M.mjs";
6
- import { d as isIncreasing, n as isDecreasing$1, r as isIncreasing$1, u as isDecreasing } from "../shared/quadratic-BZmfZE71.mjs";
6
+ import { n as isDecreasing, r as isIncreasing } from "../shared/quadratic-BZmfZE71.mjs";
7
7
  import { a as union } from "../shared/interval2d-DPmvk_Qe.mjs";
8
- import { C as solve$4, T as solveAtY$4, _ as solve$5, b as boundingBox$4, h as length$5, m as boundingBox$5, v as solveAtX$5, w as solveAtX$4, x as length$4, y as solveAtY$5 } from "../shared/rationalCubic2d-IroMR6AA.mjs";
9
- import { n as rationalCubic2d_exports, r as cubic2d_exports } from "../shared/rationalCubic2d-nN-oSrLr.mjs";
10
- //#region src/path/linear2d.internal.ts
11
- const LinearPath2dTypeId = Symbol("curvy/path/linear2d");
12
- /** @internal */
13
- var LinearPath2dImpl = class extends Pipeable {
14
- [LinearPath2dTypeId] = LinearPath2dTypeId;
15
- curves;
16
- constructor(curves) {
17
- super();
18
- this.curves = curves;
19
- }
20
- [Symbol.iterator]() {
21
- return this.curves[Symbol.iterator]();
22
- }
23
- };
24
- /** @internal */
25
- const isLinearPath2d$1 = (p) => typeof p === "object" && p !== null && LinearPath2dTypeId in p;
26
- /** @internal */
27
- const make$3 = (...curves) => new LinearPath2dImpl(curves);
28
- /** @internal */
29
- const fromArray$3 = (curves) => new LinearPath2dImpl(curves);
30
- /** @internal */
31
- const append$3 = dual(2, (p, c) => fromArray$3([...p, c]));
32
- /** @internal */
33
- const length$3 = (p) => {
34
- let total = 0;
35
- for (const curve of p) total += length$4(curve, unit);
36
- return total;
37
- };
38
- /** @internal */
39
- const solve$3 = dual(2, (p, u) => {
40
- const curves = p instanceof LinearPath2dImpl ? p.curves : [...p];
41
- if (u === 1) return solve$4(curves.at(-1), 1);
42
- const t = u * curves.length;
43
- const i = Math.floor(t);
44
- const curve = curves[i];
45
- return solve$4(curve, t - i);
46
- });
47
- /** @internal */
48
- const toPathData$3 = (p) => {
49
- let result = "";
50
- let prevEndX = NaN;
51
- let prevEndY = NaN;
52
- for (const curve of p) {
53
- const startX = curve.x.c0;
54
- const startY = curve.y.c0;
55
- const endX = curve.x.c0 + curve.x.c1;
56
- const endY = curve.y.c0 + curve.y.c1;
57
- if (!epsEquals(startX, prevEndX) || !epsEquals(startY, prevEndY)) result += ` M ${startX},${startY}`;
58
- result += ` L ${endX},${endY}`;
59
- prevEndX = endX;
60
- prevEndY = endY;
61
- }
62
- return result.slice(1);
63
- };
64
- /** @internal */
65
- const isContinuous$3 = (p) => {
66
- let prevEndX = NaN;
67
- let prevEndY = NaN;
68
- let first = true;
69
- for (const curve of p) {
70
- const startX = curve.x.c0;
71
- const startY = curve.y.c0;
72
- if (!first && (!epsEquals(startX, prevEndX) || !epsEquals(startY, prevEndY))) return false;
73
- prevEndX = curve.x.c0 + curve.x.c1;
74
- prevEndY = curve.y.c0 + curve.y.c1;
75
- first = false;
76
- }
77
- return true;
78
- };
79
- /** @internal */
80
- const asContinuous$3 = (p) => {
81
- invariant(isContinuous$3(p), "linear path is not continuous");
82
- return p;
83
- };
84
- /** @internal */
85
- const isIncreasingX$3 = (p) => {
86
- let prevEnd = Number.NEGATIVE_INFINITY;
87
- for (const c of p) {
88
- if (!isIncreasing(c.x)) return false;
89
- if (c.x.c0 < prevEnd - 1e-10) return false;
90
- prevEnd = c.x.c0 + c.x.c1;
91
- }
92
- return true;
93
- };
94
- /** @internal */
95
- const isDecreasingX$3 = (p) => {
96
- let prevEnd = Number.POSITIVE_INFINITY;
97
- for (const c of p) {
98
- if (!isDecreasing(c.x)) return false;
99
- if (c.x.c0 > prevEnd + 1e-10) return false;
100
- prevEnd = c.x.c0 + c.x.c1;
101
- }
102
- return true;
103
- };
104
- /** @internal */
105
- const isMonotonicX$3 = (p) => isIncreasingX$3(p) || isDecreasingX$3(p);
106
- /** @internal */
107
- const isIncreasingY$3 = (p) => {
108
- let prevEnd = Number.NEGATIVE_INFINITY;
109
- for (const c of p) {
110
- if (!isIncreasing(c.y)) return false;
111
- if (c.y.c0 < prevEnd - 1e-10) return false;
112
- prevEnd = c.y.c0 + c.y.c1;
113
- }
114
- return true;
115
- };
116
- /** @internal */
117
- const isDecreasingY$3 = (p) => {
118
- let prevEnd = Number.POSITIVE_INFINITY;
119
- for (const c of p) {
120
- if (!isDecreasing(c.y)) return false;
121
- if (c.y.c0 > prevEnd + 1e-10) return false;
122
- prevEnd = c.y.c0 + c.y.c1;
123
- }
124
- return true;
125
- };
126
- /** @internal */
127
- const isMonotonicY$3 = (p) => isIncreasingY$3(p) || isDecreasingY$3(p);
128
- /** @internal */
129
- const asIncreasingX$3 = (p) => {
130
- invariant(isIncreasingX$3(p), "linear path is not increasing in x");
131
- return p;
132
- };
133
- /** @internal */
134
- const asDecreasingX$3 = (p) => {
135
- invariant(isDecreasingX$3(p), "linear path is not decreasing in x");
136
- return p;
137
- };
138
- /** @internal */
139
- const asMonotonicX$3 = (p) => {
140
- invariant(isMonotonicX$3(p), "linear path is not monotonic in x");
141
- return p;
142
- };
143
- /** @internal */
144
- const asIncreasingY$3 = (p) => {
145
- invariant(isIncreasingY$3(p), "linear path is not increasing in y");
146
- return p;
147
- };
148
- /** @internal */
149
- const asDecreasingY$3 = (p) => {
150
- invariant(isDecreasingY$3(p), "linear path is not decreasing in y");
151
- return p;
152
- };
153
- /** @internal */
154
- const asMonotonicY$3 = (p) => {
155
- invariant(isMonotonicY$3(p), "linear path is not monotonic in y");
156
- return p;
157
- };
158
- /** @internal */
159
- const solveAtX$3 = dual(2, (p, x) => {
160
- for (const c of p) {
161
- const sx = c.x.c0;
162
- const ex = c.x.c0 + c.x.c1;
163
- const lo = Math.min(sx, ex);
164
- const hi = Math.max(sx, ex);
165
- if (x >= lo - 1e-10 && x <= hi + 1e-10) {
166
- if (epsEquals(x, sx)) return one(c.y.c0);
167
- if (epsEquals(x, ex)) return one(c.y.c0 + c.y.c1);
168
- const sol = solveAtX$4(c, x);
169
- if (!isNone(sol)) return sol;
170
- }
171
- }
172
- return none;
173
- });
174
- /** @internal */
175
- const solveAtY$3 = dual(2, (p, y) => {
176
- for (const c of p) {
177
- const sy = c.y.c0;
178
- const ey = c.y.c0 + c.y.c1;
179
- const lo = Math.min(sy, ey);
180
- const hi = Math.max(sy, ey);
181
- if (y >= lo - 1e-10 && y <= hi + 1e-10) {
182
- if (epsEquals(y, sy)) return one(c.x.c0);
183
- if (epsEquals(y, ey)) return one(c.x.c0 + c.x.c1);
184
- const sol = solveAtY$4(c, y);
185
- if (!isNone(sol)) return sol;
186
- }
187
- }
188
- return none;
189
- });
190
- /** @internal */
191
- const boundingBox$3 = (p) => {
192
- const iter = p[Symbol.iterator]();
193
- let acc = boundingBox$4(iter.next().value);
194
- for (let next = iter.next(); !next.done; next = iter.next()) acc = union(acc, boundingBox$4(next.value));
195
- return acc;
196
- };
197
- //#endregion
198
- //#region src/path/linear2d.ts
199
- var linear2d_exports = /* @__PURE__ */ __exportAll({
200
- append: () => append$2,
201
- asContinuous: () => asContinuous$2,
202
- asDecreasingX: () => asDecreasingX$2,
203
- asDecreasingY: () => asDecreasingY$2,
204
- asIncreasingX: () => asIncreasingX$2,
205
- asIncreasingY: () => asIncreasingY$2,
206
- asMonotonicX: () => asMonotonicX$2,
207
- asMonotonicY: () => asMonotonicY$2,
208
- boundingBox: () => boundingBox$2,
209
- fromArray: () => fromArray$2,
210
- isContinuous: () => isContinuous$2,
211
- isDecreasingX: () => isDecreasingX$2,
212
- isDecreasingY: () => isDecreasingY$2,
213
- isIncreasingX: () => isIncreasingX$2,
214
- isIncreasingY: () => isIncreasingY$2,
215
- isLinearPath2d: () => isLinearPath2d,
216
- isMonotonicX: () => isMonotonicX$2,
217
- isMonotonicY: () => isMonotonicY$2,
218
- length: () => length$2,
219
- make: () => make$2,
220
- solve: () => solve$2,
221
- solveAtX: () => solveAtX$2,
222
- solveAtY: () => solveAtY$2,
223
- toPathData: () => toPathData$2
224
- });
225
- /**
226
- * Creates a new `LinearPath2d` instance from a sequence of curves.
227
- *
228
- * @param curves - The curves to create the path from.
229
- * @returns A new `LinearPath2d` instance.
230
- * @since 2.0.0
231
- */
232
- const make$2 = make$3;
233
- /**
234
- * Creates a new `LinearPath2d` instance from an array of curves.
235
- *
236
- * @param curves - The curves to create the path from.
237
- * @returns A new `LinearPath2d` instance.
238
- * @since 2.0.0
239
- */
240
- const fromArray$2 = fromArray$3;
241
- /**
242
- * Checks if a value is a `LinearPath2d`.
243
- *
244
- * @param p - The value to check.
245
- * @returns `true` if the value is a `LinearPath2d`, `false` otherwise.
246
- * @since 1.0.0
247
- */
248
- const isLinearPath2d = isLinearPath2d$1;
249
- const append$2 = append$3;
250
- /**
251
- * Calculates the length of a linear path.
252
- *
253
- * @param p - The linear path to calculate the length of.
254
- * @returns The length of the linear path.
255
- * @since 1.0.0
256
- */
257
- const length$2 = length$3;
258
- const solve$2 = solve$3;
259
- /**
260
- * Serializes a linear path as an SVG path data string (the value of a `<path>`
261
- * element's `d` attribute), using `M` and `L` commands. Discontinuities between
262
- * curves emit a fresh `M` command.
263
- *
264
- * @param p - The linear path to serialize.
265
- * @returns The SVG path data string.
266
- * @since 2.0.0
267
- */
268
- const toPathData$2 = toPathData$3;
269
- /**
270
- * Type-narrowing predicate: refines `LinearPath2d<T>` to
271
- * `LinearPath2d<T & Continuous>` when adjacent curves connect at their join
272
- * points.
273
- *
274
- * @param p - The linear path to check.
275
- * @returns `true` when the path is continuous (G⁰).
276
- * @since 2.0.0
277
- */
278
- const isContinuous$2 = isContinuous$3;
279
- /**
280
- * Asserts that the linear path is continuous, throwing on failure.
281
- *
282
- * @param p - The linear path to assert against.
283
- * @returns The same path, typed with the `Continuous` brand.
284
- * @throws When the path has a discontinuity between adjacent curves.
285
- * @since 2.0.0
286
- */
287
- const asContinuous$2 = asContinuous$3;
288
- /**
289
- * Type-narrowing predicate: refines `LinearPath2d<T>` to
290
- * `LinearPath2d<T & IncreasingX>` when every segment's x-polynomial is
291
- * strictly increasing and adjacent segments' x-ranges don't overlap.
292
- *
293
- * @since 2.0.0
294
- */
295
- const isIncreasingX$2 = isIncreasingX$3;
296
- /**
297
- * Type-narrowing predicate: refines `LinearPath2d<T>` to
298
- * `LinearPath2d<T & DecreasingX>` when every segment's x-polynomial is
299
- * strictly decreasing and adjacent segments' x-ranges don't overlap.
300
- *
301
- * @since 2.0.0
302
- */
303
- const isDecreasingX$2 = isDecreasingX$3;
304
- /**
305
- * Type-narrowing predicate: refines `LinearPath2d<T>` to
306
- * `LinearPath2d<T & MonotonicX>` when the path is either increasing or
307
- * decreasing in x along its full parameter domain.
308
- *
309
- * @since 2.0.0
310
- */
311
- const isMonotonicX$2 = isMonotonicX$3;
312
- /**
313
- * Type-narrowing predicate: refines `LinearPath2d<T>` to
314
- * `LinearPath2d<T & IncreasingY>`. The y-axis analog of {@link isIncreasingX}.
315
- *
316
- * @since 2.0.0
317
- */
318
- const isIncreasingY$2 = isIncreasingY$3;
319
- /**
320
- * Type-narrowing predicate: refines `LinearPath2d<T>` to
321
- * `LinearPath2d<T & DecreasingY>`. The y-axis analog of {@link isDecreasingX}.
322
- *
323
- * @since 2.0.0
324
- */
325
- const isDecreasingY$2 = isDecreasingY$3;
326
- /**
327
- * Type-narrowing predicate: refines `LinearPath2d<T>` to
328
- * `LinearPath2d<T & MonotonicY>`. The y-axis analog of {@link isMonotonicX}.
329
- *
330
- * @since 2.0.0
331
- */
332
- const isMonotonicY$2 = isMonotonicY$3;
333
- /**
334
- * Asserts that the path is strictly increasing in x, throwing on failure.
335
- *
336
- * @since 2.0.0
337
- */
338
- const asIncreasingX$2 = asIncreasingX$3;
339
- /**
340
- * Asserts that the path is strictly decreasing in x, throwing on failure.
341
- *
342
- * @since 2.0.0
343
- */
344
- const asDecreasingX$2 = asDecreasingX$3;
345
- /**
346
- * Asserts that the path is monotonic in x, throwing on failure.
347
- *
348
- * @since 2.0.0
349
- */
350
- const asMonotonicX$2 = asMonotonicX$3;
351
- /**
352
- * Asserts that the path is strictly increasing in y, throwing on failure.
353
- *
354
- * @since 2.0.0
355
- */
356
- const asIncreasingY$2 = asIncreasingY$3;
357
- /**
358
- * Asserts that the path is strictly decreasing in y, throwing on failure.
359
- *
360
- * @since 2.0.0
361
- */
362
- const asDecreasingY$2 = asDecreasingY$3;
363
- /**
364
- * Asserts that the path is monotonic in y, throwing on failure.
365
- *
366
- * @since 2.0.0
367
- */
368
- const asMonotonicY$2 = asMonotonicY$3;
369
- const solveAtX$2 = solveAtX$3;
370
- const solveAtY$2 = solveAtY$3;
371
- /**
372
- * Computes the axis-aligned bounding box of the path — the smallest closed
373
- * `Box2d` enclosing every segment.
374
- *
375
- * @param p - The linear path.
376
- * @returns A closed `Box2d` enclosing the path.
377
- * @since 2.0.0
378
- */
379
- const boundingBox$2 = boundingBox$3;
380
- //#endregion
8
+ import { _ as solve$2, h as length$2, m as boundingBox$2, v as solveAtX$2, y as solveAtY$2 } from "../shared/rationalCubic2d-D5g3_hTV.mjs";
9
+ import { n as rationalCubic2d_exports, o as linear2d_exports, r as cubic2d_exports } from "../shared/rationalCubic2d-MojACId0.mjs";
381
10
  //#region src/path/quadratic2d.internal.ts
382
11
  const QuadraticPath2dTypeId = Symbol("curvy/path/quadratic2d");
383
12
  /** @internal */
@@ -403,17 +32,17 @@ const append$1 = dual(2, (p, c) => fromArray$1([...p, c]));
403
32
  /** @internal */
404
33
  const length$1 = (p) => {
405
34
  let total = 0;
406
- for (const curve of p) total += length$5(curve, unit);
35
+ for (const curve of p) total += length$2(curve, unit);
407
36
  return total;
408
37
  };
409
38
  /** @internal */
410
39
  const solve$1 = dual(2, (p, u) => {
411
40
  const curves = p instanceof QuadraticPath2dImpl ? p.curves : [...p];
412
- if (u === 1) return solve$5(curves.at(-1), 1);
41
+ if (u === 1) return solve$2(curves.at(-1), 1);
413
42
  const t = u * curves.length;
414
43
  const i = Math.floor(t);
415
44
  const curve = curves[i];
416
- return solve$5(curve, t - i);
45
+ return solve$2(curve, t - i);
417
46
  });
418
47
  /** @internal */
419
48
  const toPathData$1 = (p) => {
@@ -464,7 +93,7 @@ const asContinuous$1 = (p) => {
464
93
  const isIncreasingX$1 = (p) => {
465
94
  let prevEnd = Number.NEGATIVE_INFINITY;
466
95
  for (const c of p) {
467
- if (!isIncreasing$1(c.x, unit)) return false;
96
+ if (!isIncreasing(c.x, unit)) return false;
468
97
  if (c.x.c0 < prevEnd - 1e-10) return false;
469
98
  prevEnd = c.x.c0 + c.x.c1 + c.x.c2;
470
99
  }
@@ -474,7 +103,7 @@ const isIncreasingX$1 = (p) => {
474
103
  const isDecreasingX$1 = (p) => {
475
104
  let prevEnd = Number.POSITIVE_INFINITY;
476
105
  for (const c of p) {
477
- if (!isDecreasing$1(c.x, unit)) return false;
106
+ if (!isDecreasing(c.x, unit)) return false;
478
107
  if (c.x.c0 > prevEnd + 1e-10) return false;
479
108
  prevEnd = c.x.c0 + c.x.c1 + c.x.c2;
480
109
  }
@@ -486,7 +115,7 @@ const isMonotonicX$1 = (p) => isIncreasingX$1(p) || isDecreasingX$1(p);
486
115
  const isIncreasingY$1 = (p) => {
487
116
  let prevEnd = Number.NEGATIVE_INFINITY;
488
117
  for (const c of p) {
489
- if (!isIncreasing$1(c.y, unit)) return false;
118
+ if (!isIncreasing(c.y, unit)) return false;
490
119
  if (c.y.c0 < prevEnd - 1e-10) return false;
491
120
  prevEnd = c.y.c0 + c.y.c1 + c.y.c2;
492
121
  }
@@ -496,7 +125,7 @@ const isIncreasingY$1 = (p) => {
496
125
  const isDecreasingY$1 = (p) => {
497
126
  let prevEnd = Number.POSITIVE_INFINITY;
498
127
  for (const c of p) {
499
- if (!isDecreasing$1(c.y, unit)) return false;
128
+ if (!isDecreasing(c.y, unit)) return false;
500
129
  if (c.y.c0 > prevEnd + 1e-10) return false;
501
130
  prevEnd = c.y.c0 + c.y.c1 + c.y.c2;
502
131
  }
@@ -544,7 +173,7 @@ const solveAtX$1 = dual(2, (p, x) => {
544
173
  if (x >= lo - 1e-10 && x <= hi + 1e-10) {
545
174
  if (epsEquals(x, sx)) return one(c.y.c0);
546
175
  if (epsEquals(x, ex)) return one(c.y.c0 + c.y.c1 + c.y.c2);
547
- const sol = solveAtX$5(c, x);
176
+ const sol = solveAtX$2(c, x);
548
177
  if (!isNone(sol)) return sol;
549
178
  }
550
179
  }
@@ -560,7 +189,7 @@ const solveAtY$1 = dual(2, (p, y) => {
560
189
  if (y >= lo - 1e-10 && y <= hi + 1e-10) {
561
190
  if (epsEquals(y, sy)) return one(c.x.c0);
562
191
  if (epsEquals(y, ey)) return one(c.x.c0 + c.x.c1 + c.x.c2);
563
- const sol = solveAtY$5(c, y);
192
+ const sol = solveAtY$2(c, y);
564
193
  if (!isNone(sol)) return sol;
565
194
  }
566
195
  }
@@ -569,8 +198,8 @@ const solveAtY$1 = dual(2, (p, y) => {
569
198
  /** @internal */
570
199
  const boundingBox$1 = (p) => {
571
200
  const iter = p[Symbol.iterator]();
572
- let acc = boundingBox$5(iter.next().value);
573
- for (let next = iter.next(); !next.done; next = iter.next()) acc = union(acc, boundingBox$5(next.value));
201
+ let acc = boundingBox$2(iter.next().value);
202
+ for (let next = iter.next(); !next.done; next = iter.next()) acc = union(acc, boundingBox$2(next.value));
574
203
  return acc;
575
204
  };
576
205
  //#endregion