curvy 2.0.0-alpha.11 → 2.0.0-alpha.13

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 (42) hide show
  1. package/dist/characteristic/index.mjs +1 -1
  2. package/dist/curve/index.mjs +1 -1
  3. package/dist/curve/rationalCubic2d.d.ts +195 -11
  4. package/dist/interval/index.mjs +1 -1
  5. package/dist/monotonicity/index.d.ts +4 -0
  6. package/dist/monotonicity/index.mjs +2 -0
  7. package/dist/monotonicity/monotonicity.d.ts +80 -0
  8. package/dist/path/index.mjs +16 -387
  9. package/dist/path/index.mjs.map +1 -1
  10. package/dist/path/rationalCubic2d.d.ts +27 -0
  11. package/dist/polynomial/cubic.d.ts +2 -2
  12. package/dist/polynomial/index.mjs +2 -2
  13. package/dist/polynomial/linear.d.ts +7 -7
  14. package/dist/polynomial/quadratic.d.ts +2 -2
  15. package/dist/shared/{characteristic-Hb7F8SBw.mjs → characteristic-BkEr-rr8.mjs} +2 -2
  16. package/dist/shared/{characteristic-Hb7F8SBw.mjs.map → characteristic-BkEr-rr8.mjs.map} +1 -1
  17. package/dist/shared/{cubic-DHJrzZJN.mjs → cubic-BL6dpuHh.mjs} +18 -30
  18. package/dist/shared/cubic-BL6dpuHh.mjs.map +1 -0
  19. package/dist/shared/{interval2d-DPmvk_Qe.mjs → interval2d-AtneyI45.mjs} +1 -1
  20. package/dist/shared/{interval2d-DPmvk_Qe.mjs.map → interval2d-AtneyI45.mjs.map} +1 -1
  21. package/dist/shared/monotonicity-BdebFOtv.mjs +34 -0
  22. package/dist/shared/monotonicity-BdebFOtv.mjs.map +1 -0
  23. package/dist/shared/{quadratic-BZmfZE71.mjs → quadratic-DPrUsFCp.mjs} +9 -9
  24. package/dist/shared/quadratic-DPrUsFCp.mjs.map +1 -0
  25. package/dist/shared/{rationalCubic2d-IroMR6AA.mjs → rationalCubic2d-CeHgpNht.mjs} +373 -79
  26. package/dist/shared/rationalCubic2d-CeHgpNht.mjs.map +1 -0
  27. package/dist/shared/{rationalCubic2d-nN-oSrLr.mjs → rationalCubic2d-H1J2Fjyy.mjs} +404 -23
  28. package/dist/shared/rationalCubic2d-H1J2Fjyy.mjs.map +1 -0
  29. package/dist/shared/{solution-B6KY1E7M.mjs → solution-B2JdOZpe.mjs} +1 -1
  30. package/dist/shared/{solution-B6KY1E7M.mjs.map → solution-B2JdOZpe.mjs.map} +1 -1
  31. package/dist/solution/index.mjs +1 -1
  32. package/dist/splines/index.d.ts +3 -0
  33. package/dist/splines/index.mjs +218 -120
  34. package/dist/splines/index.mjs.map +1 -1
  35. package/dist/splines/linear2d.d.ts +102 -0
  36. package/dist/splines/linear2d.internal.d.ts +2 -0
  37. package/package.json +5 -1
  38. package/dist/polynomial/monotonicity.d.ts +0 -3
  39. package/dist/shared/cubic-DHJrzZJN.mjs.map +0 -1
  40. package/dist/shared/quadratic-BZmfZE71.mjs.map +0 -1
  41. package/dist/shared/rationalCubic2d-IroMR6AA.mjs.map +0 -1
  42. package/dist/shared/rationalCubic2d-nN-oSrLr.mjs.map +0 -1
@@ -1,2 +1,2 @@
1
- import { n as characteristic_exports } from "../shared/characteristic-Hb7F8SBw.mjs";
1
+ import { n as characteristic_exports } from "../shared/characteristic-BkEr-rr8.mjs";
2
2
  export { characteristic_exports as Characteristic };
@@ -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 { _ as quadratic2d_exports, i as rationalCubic2d_exports, s as cubic2d_exports, w as linear2d_exports } from "../shared/rationalCubic2d-CeHgpNht.mjs";
2
2
  export { cubic2d_exports as CubicCurve2d, linear2d_exports as LinearCurve2d, quadratic2d_exports as QuadraticCurve2d, rationalCubic2d_exports as RationalCubicCurve2d };
@@ -1,8 +1,9 @@
1
1
  import type { Closed } from '../interval/interval.ts';
2
2
  import type { Interval2d } from '../interval/interval2d.ts';
3
+ import type { Monotonicity } from '../monotonicity/monotonicity.ts';
3
4
  import type { Pipeable } from '../utils.ts';
4
5
  import type { CubicPolynomial } from '../polynomial/cubic.ts';
5
- import type { Increasing, Monotonic } from '../polynomial/traits.ts';
6
+ import type { Decreasing, Increasing, Monotonic } from '../polynomial/traits.ts';
6
7
  import type * as Solution from '../solution/solution.ts';
7
8
  import type { Vector2, Weighted } from '../vector/vector2.ts';
8
9
  import type { CubicCurve2d } from './cubic2d.ts';
@@ -191,22 +192,205 @@ export declare const subdivide: {
191
192
  */
192
193
  (t: number): (c: RationalCubicCurve2d) => [RationalCubicCurve2d, RationalCubicCurve2d];
193
194
  };
195
+ export declare const boundingBox: {
196
+ /**
197
+ * Computes a closed axis-aligned bounding box for a rational cubic curve,
198
+ * tight to within `tolerance` per side.
199
+ *
200
+ * Implemented as recursive subdivision: at each leaf the curve segment's
201
+ * loose hull AABB (cheap, always valid) is compared against the segment's
202
+ * endpoint AABB (which the curve provably visits). When the per-side gap
203
+ * between them is ≤ `tolerance`, the leaf returns its hull; otherwise the
204
+ * segment is split at `t = 0.5` and the procedure recurses, unioning the
205
+ * halves.
206
+ *
207
+ * The returned box is provably within `tolerance` of the true tight box on
208
+ * every side, and contains the curve since each leaf hull does. The
209
+ * polynomial cubic case (uniform weights) is handled by a fast path that
210
+ * computes the exact box from per-axis cubic extrema, with no subdivision.
211
+ *
212
+ * @param c - The rational cubic curve.
213
+ * @param tolerance - Maximum allowed slack per side; must be positive.
214
+ * @returns A closed `Interval2d` enclosing the curve, tight to within `tolerance`.
215
+ * @since 2.0.0
216
+ */
217
+ (c: RationalCubicCurve2d, tolerance: number): Interval2d<Closed, Closed>;
218
+ /**
219
+ * Computes a closed axis-aligned bounding box for a rational cubic curve.
220
+ *
221
+ * @param tolerance - Maximum allowed slack per side; must be positive.
222
+ * @returns A function that takes a curve and returns its bounding box.
223
+ * @since 2.0.0
224
+ */
225
+ (tolerance: number): (c: RationalCubicCurve2d) => Interval2d<Closed, Closed>;
226
+ };
227
+ /**
228
+ * Classifies the monotonicity of the curve's `x(t) = X(t)/W(t)` projection on
229
+ * the unit interval `[0, 1]`.
230
+ *
231
+ * Decided via Bernstein sign convexity on the derivative-numerator polynomial
232
+ * `q(t) = X'·W − X·W'`. Since `W² > 0` wherever the curve is well-defined,
233
+ * the sign of `dx/dt` equals the sign of `q`. Although `q` is a difference of
234
+ * degree-5 products, the leading terms cancel and `q` is in fact a quartic —
235
+ * its 5 Bernstein coefficients on `[0, 1]` are evaluated for uniform sign,
236
+ * with de Casteljau subdivision to resolve mixed-sign cases. The procedure is
237
+ * exact except at tangential zeros, where it conservatively reports `None`.
238
+ *
239
+ * Returning `Increasing` or `Decreasing` is the trigger for
240
+ * {@link asMonotonic} / {@link asIncreasing} / {@link asDecreasing}.
241
+ *
242
+ * @param c - The rational cubic curve.
243
+ * @returns The monotonicity of the curve's x projection on `[0, 1]`.
244
+ * @since 2.0.0
245
+ */
246
+ export declare const xMonotonicity: (c: RationalCubicCurve2d) => Monotonicity;
247
+ /**
248
+ * Classifies the monotonicity of the curve's `y(t) = Y(t)/W(t)` projection on
249
+ * the unit interval `[0, 1]`. See {@link xMonotonicity} for the method.
250
+ *
251
+ * @param c - The rational cubic curve.
252
+ * @returns The monotonicity of the curve's y projection on `[0, 1]`.
253
+ * @since 2.0.0
254
+ */
255
+ export declare const yMonotonicity: (c: RationalCubicCurve2d) => Monotonicity;
256
+ /**
257
+ * Type-narrowing predicate: refines the curve's x-axis trait to include
258
+ * `Monotonic` when `x(t)/w(t)` is strictly monotonic on `[0, 1]`. The y-axis
259
+ * trait is unchanged.
260
+ *
261
+ * Use this when only x-axis monotonicity is required (e.g. to make {@link solveAtX}
262
+ * narrow to `AtMostOne` without also asserting y-axis monotonicity).
263
+ *
264
+ * @param c - The rational cubic curve.
265
+ * @returns `true` when the x projection is strictly monotonic on `[0, 1]`.
266
+ * @since 2.0.0
267
+ */
268
+ export declare const isMonotonicX: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => c is RationalCubicCurve2d<XT & Monotonic, YT>;
269
+ /**
270
+ * Type-narrowing predicate: refines the curve's x-axis trait to include
271
+ * `Increasing`.
272
+ *
273
+ * @since 2.0.0
274
+ */
275
+ export declare const isIncreasingX: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => c is RationalCubicCurve2d<XT & Increasing, YT>;
276
+ /**
277
+ * Type-narrowing predicate: refines the curve's x-axis trait to include
278
+ * `Decreasing`.
279
+ *
280
+ * @since 2.0.0
281
+ */
282
+ export declare const isDecreasingX: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => c is RationalCubicCurve2d<XT & Decreasing, YT>;
283
+ /**
284
+ * Type-narrowing predicate: refines the curve's y-axis trait to include
285
+ * `Monotonic`. The x-axis trait is unchanged. y analog of {@link isMonotonicX}.
286
+ *
287
+ * @since 2.0.0
288
+ */
289
+ export declare const isMonotonicY: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => c is RationalCubicCurve2d<XT, YT & Monotonic>;
290
+ /**
291
+ * Type-narrowing predicate: refines the curve's y-axis trait to include
292
+ * `Increasing`.
293
+ *
294
+ * @since 2.0.0
295
+ */
296
+ export declare const isIncreasingY: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => c is RationalCubicCurve2d<XT, YT & Increasing>;
297
+ /**
298
+ * Type-narrowing predicate: refines the curve's y-axis trait to include
299
+ * `Decreasing`.
300
+ *
301
+ * @since 2.0.0
302
+ */
303
+ export declare const isDecreasingY: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => c is RationalCubicCurve2d<XT, YT & Decreasing>;
304
+ /**
305
+ * Type-narrowing predicate: refines both axes' traits to include `Monotonic`
306
+ * when both `x(t)/w(t)` and `y(t)/w(t)` are strictly monotonic on `[0, 1]`.
307
+ *
308
+ * The constant case is excluded — `Monotonic` is the *strict* brand.
309
+ *
310
+ * @param c - The rational cubic curve.
311
+ * @returns `true` when both axes are strictly monotonic on `[0, 1]`.
312
+ * @since 2.0.0
313
+ */
314
+ export declare const isMonotonic: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => c is RationalCubicCurve2d<XT & Monotonic, YT & Monotonic>;
315
+ /**
316
+ * Type-narrowing predicate: refines both axes' traits to include `Increasing`
317
+ * when both `x(t)/w(t)` and `y(t)/w(t)` are strictly increasing on `[0, 1]`.
318
+ *
319
+ * @since 2.0.0
320
+ */
321
+ export declare const isIncreasing: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => c is RationalCubicCurve2d<XT & Increasing, YT & Increasing>;
322
+ /**
323
+ * Type-narrowing predicate: refines both axes' traits to include `Decreasing`
324
+ * when both `x(t)/w(t)` and `y(t)/w(t)` are strictly decreasing on `[0, 1]`.
325
+ *
326
+ * @since 2.0.0
327
+ */
328
+ export declare const isDecreasing: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => c is RationalCubicCurve2d<XT & Decreasing, YT & Decreasing>;
329
+ /**
330
+ * Asserts that the curve is strictly monotonic in x on `[0, 1]`, returning
331
+ * the same curve with the x-axis trait branded `Monotonic`.
332
+ *
333
+ * @param c - The rational cubic curve.
334
+ * @returns The same curve, refined with the `Monotonic` brand on x.
335
+ * @throws When the x projection is not strictly monotonic on `[0, 1]`.
336
+ * @since 2.0.0
337
+ */
338
+ export declare const asMonotonicX: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => RationalCubicCurve2d<XT & Monotonic, YT>;
339
+ /**
340
+ * Asserts that the curve is strictly increasing in x on `[0, 1]`.
341
+ *
342
+ * @since 2.0.0
343
+ */
344
+ export declare const asIncreasingX: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => RationalCubicCurve2d<XT & Increasing, YT>;
345
+ /**
346
+ * Asserts that the curve is strictly decreasing in x on `[0, 1]`.
347
+ *
348
+ * @since 2.0.0
349
+ */
350
+ export declare const asDecreasingX: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => RationalCubicCurve2d<XT & Decreasing, YT>;
351
+ /**
352
+ * Asserts that the curve is strictly monotonic in y on `[0, 1]`. y analog of
353
+ * {@link asMonotonicX}.
354
+ *
355
+ * @since 2.0.0
356
+ */
357
+ export declare const asMonotonicY: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => RationalCubicCurve2d<XT, YT & Monotonic>;
358
+ /**
359
+ * Asserts that the curve is strictly increasing in y on `[0, 1]`.
360
+ *
361
+ * @since 2.0.0
362
+ */
363
+ export declare const asIncreasingY: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => RationalCubicCurve2d<XT, YT & Increasing>;
194
364
  /**
195
- * Computes a closed axis-aligned bounding box for a rational cubic curve from
196
- * its projected control polygon. Looser than the tight extrema-based box used
197
- * by `CubicCurve2d.boundingBox` — finding tight extrema of `x(t)/w(t)` and
198
- * `y(t)/w(t)` requires solving degree-5 polynomials — but always valid: a
199
- * positive-weight rational Bézier curve lies inside the convex hull of its
200
- * projected control points, so the AABB of those points contains the curve.
365
+ * Asserts that the curve is strictly decreasing in y on `[0, 1]`.
201
366
  *
202
- * Suitable for subdivision-based geometric queries, where bound looseness is
203
- * compensated by recursion depth.
367
+ * @since 2.0.0
368
+ */
369
+ export declare const asDecreasingY: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => RationalCubicCurve2d<XT, YT & Decreasing>;
370
+ /**
371
+ * Asserts that the curve is strictly monotonic in both axes on `[0, 1]`,
372
+ * returning the same curve with both axes branded `Monotonic`.
204
373
  *
205
374
  * @param c - The rational cubic curve.
206
- * @returns A closed `Interval2d` enclosing the curve.
375
+ * @returns The same curve, refined with the `Monotonic` brand on both axes.
376
+ * @throws When either axis is not strictly monotonic on `[0, 1]`.
377
+ * @since 2.0.0
378
+ */
379
+ export declare const asMonotonic: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => RationalCubicCurve2d<XT & Monotonic, YT & Monotonic>;
380
+ /**
381
+ * Asserts that the curve is strictly increasing in both axes on `[0, 1]`,
382
+ * returning the same curve with both axes branded `Increasing`.
383
+ *
384
+ * @since 2.0.0
385
+ */
386
+ export declare const asIncreasing: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => RationalCubicCurve2d<XT & Increasing, YT & Increasing>;
387
+ /**
388
+ * Asserts that the curve is strictly decreasing in both axes on `[0, 1]`,
389
+ * returning the same curve with both axes branded `Decreasing`.
390
+ *
207
391
  * @since 2.0.0
208
392
  */
209
- export declare const boundingBox: (c: RationalCubicCurve2d) => Interval2d<Closed, Closed>;
393
+ export declare const asDecreasing: <XT, YT>(c: RationalCubicCurve2d<XT, YT>) => RationalCubicCurve2d<XT & Decreasing, YT & Decreasing>;
210
394
  export declare const approximateAsCubicCurves: {
211
395
  /**
212
396
  * Approximates the rational cubic as a sequence of polynomial cubic curves
@@ -1,3 +1,3 @@
1
1
  import { s as interval_exports } from "../shared/interval-Dm35Xhy4.mjs";
2
- import { n as interval2d_exports } from "../shared/interval2d-DPmvk_Qe.mjs";
2
+ import { n as interval2d_exports } from "../shared/interval2d-AtneyI45.mjs";
3
3
  export { interval_exports as Interval, interval2d_exports as Interval2d };
@@ -0,0 +1,4 @@
1
+ import * as MonotonicityNs from './monotonicity.ts';
2
+ export type Monotonicity = MonotonicityNs.Monotonicity;
3
+ export type GuaranteedMonotonicity = MonotonicityNs.GuaranteedMonotonicity;
4
+ export { MonotonicityNs as Monotonicity };
@@ -0,0 +1,2 @@
1
+ import { r as monotonicity_exports } from "../shared/monotonicity-BdebFOtv.mjs";
2
+ export { monotonicity_exports as Monotonicity };
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Classification of a function's monotonicity on an interval.
3
+ *
4
+ * Encoded as a 2-bit sign-coverage bitmask of the function's derivative:
5
+ * - bit 0 (`Increasing`) — derivative takes positive values
6
+ * - bit 1 (`Decreasing`) — derivative takes negative values
7
+ *
8
+ * The four states fall out of the encoding:
9
+ *
10
+ * | value | name | derivative on the interval |
11
+ * |-------|--------------|-----------------------------------|
12
+ * | `0` | `Constant` | ≡ 0 |
13
+ * | `1` | `Increasing` | ≥ 0, with at least one `> 0` |
14
+ * | `2` | `Decreasing` | ≤ 0, with at least one `< 0` |
15
+ * | `3` | `None` | crosses zero |
16
+ *
17
+ * The numeric encoding is principled, not arbitrary: the bitwise OR of two
18
+ * adjacent subintervals' classifications gives the classification of their
19
+ * union, which lets monotonicity be computed by recursive subdivision
20
+ * without any custom combine logic.
21
+ *
22
+ * @since 2.0.0
23
+ */
24
+ export type Monotonicity = 0 | 1 | 2 | 3;
25
+ /**
26
+ * Subset of {@link Monotonicity} excluding the indeterminate `None` state.
27
+ * Returned by classifiers operating on functions whose derivative cannot
28
+ * change sign on the interval (e.g. linear polynomials, whose derivative is
29
+ * constant).
30
+ *
31
+ * @since 2.0.0
32
+ */
33
+ export type GuaranteedMonotonicity = 0 | 1 | 2;
34
+ /**
35
+ * Derivative is identically zero on the interval. The function is constant.
36
+ *
37
+ * @since 2.0.0
38
+ */
39
+ export declare const Constant: 0;
40
+ /**
41
+ * Derivative is non-negative on the interval with at least one strictly
42
+ * positive sample. The function is strictly increasing.
43
+ *
44
+ * @since 2.0.0
45
+ */
46
+ export declare const Increasing: 1;
47
+ /**
48
+ * Derivative is non-positive on the interval with at least one strictly
49
+ * negative sample. The function is strictly decreasing.
50
+ *
51
+ * @since 2.0.0
52
+ */
53
+ export declare const Decreasing: 2;
54
+ /**
55
+ * Derivative crosses zero on the interval. The function has at least one
56
+ * interior extremum and is not monotonic in either direction.
57
+ *
58
+ * @since 2.0.0
59
+ */
60
+ export declare const None: 3;
61
+ /**
62
+ * Type-narrowing predicate: refines a `Monotonicity` to `Increasing |
63
+ * Decreasing` — the strict cases that admit a unique inverse.
64
+ *
65
+ * @param m - The monotonicity classification.
66
+ * @returns `true` when `m` is `Increasing` or `Decreasing`.
67
+ * @since 2.0.0
68
+ */
69
+ export declare const isStrict: (m: Monotonicity) => m is 1 | 2;
70
+ /**
71
+ * Classifies the monotonicity of a function given its values at two interval
72
+ * endpoints, when the function is known a priori to be monotonic on the
73
+ * spanning interval (e.g. a linear polynomial).
74
+ *
75
+ * @param s0 - The function value at the start of the interval.
76
+ * @param s1 - The function value at the end of the interval.
77
+ * @returns The classification — `Increasing`, `Decreasing`, or `Constant`.
78
+ * @since 2.0.0
79
+ */
80
+ export declare const fromComparison: (s0: number, s1: number) => GuaranteedMonotonicity;