curvy 2.0.0-alpha.4 → 2.0.0-alpha.5

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 (64) hide show
  1. package/dist/characteristic/{index.d.mts → characteristic.d.ts} +9 -17
  2. package/dist/characteristic/index.d.ts +1 -0
  3. package/dist/curve/cubic2d.d.ts +219 -0
  4. package/dist/curve/index.d.ts +12 -0
  5. package/dist/curve/linear2d.d.ts +199 -0
  6. package/dist/curve/quadratic2d.d.ts +227 -0
  7. package/dist/curve/rationalCubic2d.d.ts +200 -0
  8. package/dist/dimensions.d.ts +23 -0
  9. package/dist/interval/index.d.ts +6 -0
  10. package/dist/interval/interval.d.ts +525 -0
  11. package/dist/interval/interval2d.d.ts +167 -0
  12. package/dist/length.d.ts +32 -0
  13. package/dist/matrix/index.d.ts +9 -0
  14. package/dist/matrix/matrix2x2.d.ts +339 -0
  15. package/dist/matrix/matrix3x3.d.ts +400 -0
  16. package/dist/matrix/matrix4x4.d.ts +443 -0
  17. package/dist/number.d.ts +276 -0
  18. package/dist/path/cubic2d.d.ts +155 -0
  19. package/dist/path/index.d.ts +12 -0
  20. package/dist/path/linear2d.d.ts +135 -0
  21. package/dist/path/quadratic2d.d.ts +127 -0
  22. package/dist/path/rationalCubic2d.d.ts +120 -0
  23. package/dist/path/traits.d.ts +31 -0
  24. package/dist/polynomial/cubic.d.ts +381 -0
  25. package/dist/polynomial/index.d.ts +9 -0
  26. package/dist/polynomial/linear.d.ts +321 -0
  27. package/dist/polynomial/monotonicity.d.ts +3 -0
  28. package/dist/polynomial/quadratic.d.ts +375 -0
  29. package/dist/polynomial/traits.d.ts +56 -0
  30. package/dist/solution/index.d.ts +3 -0
  31. package/dist/solution/solution.d.ts +264 -0
  32. package/dist/splines/basis2d.d.ts +122 -0
  33. package/dist/splines/bezier2d.d.ts +202 -0
  34. package/dist/splines/cardinal2d.d.ts +273 -0
  35. package/dist/splines/hermite2d.d.ts +117 -0
  36. package/dist/splines/index.d.ts +15 -0
  37. package/dist/splines/rationalBezier2d.d.ts +148 -0
  38. package/dist/splines/util.d.ts +5 -0
  39. package/dist/utils.d.ts +73 -0
  40. package/dist/vector/index.d.ts +9 -0
  41. package/dist/vector/vector2.d.ts +446 -0
  42. package/dist/vector/vector3.d.ts +449 -0
  43. package/dist/vector/vector4.d.ts +253 -0
  44. package/package.json +13 -13
  45. package/dist/curve/index.d.mts +0 -10
  46. package/dist/interval/index.d.mts +0 -9
  47. package/dist/matrix/index.d.mts +0 -9
  48. package/dist/number.d.mts +0 -280
  49. package/dist/path/index.d.mts +0 -53
  50. package/dist/polynomial/index.d.mts +0 -9
  51. package/dist/shared/cubic-DkBqcZf-.d.mts +0 -121
  52. package/dist/shared/interval-Bhzeqp8M.d.mts +0 -62
  53. package/dist/shared/interval2d-BMk5UYXD.d.mts +0 -29
  54. package/dist/shared/matrix4x4-CaytTaB_.d.mts +0 -168
  55. package/dist/shared/rationalCubic2d-D-UevGKu.d.mts +0 -60
  56. package/dist/shared/rationalCubic2d-MgMSJaAU.d.mts +0 -104
  57. package/dist/shared/solution-DInDT2Hq.d.mts +0 -60
  58. package/dist/shared/utils-MCckigYk.d.mts +0 -76
  59. package/dist/shared/vector2-euuV_bNQ.d.mts +0 -58
  60. package/dist/shared/vector3-3Xx7GVk7.d.mts +0 -37
  61. package/dist/solution/index.d.mts +0 -7
  62. package/dist/splines/index.d.mts +0 -132
  63. package/dist/utils.d.mts +0 -2
  64. package/dist/vector/index.d.mts +0 -10
@@ -0,0 +1,381 @@
1
+ import type { Closed, Interval } from '../interval/interval';
2
+ import type { Pipeable } from '../utils';
3
+ import type * as Solution from '../solution/solution';
4
+ import type { Vector2 } from '../vector/vector2';
5
+ import type { Vector4 } from '../vector/vector4';
6
+
7
+ import type { Monotonicity } from './monotonicity';
8
+ import type { QuadraticPolynomial } from './quadratic';
9
+ import type { Decreasing, Increasing, Monotonic, PolynomialTraits } from './traits';
10
+
11
+ declare const CubicPolynomialTypeId: unique symbol;
12
+ type CubicPolynomialTypeId = typeof CubicPolynomialTypeId;
13
+
14
+ export type { Monotonic, Increasing, Decreasing } from './traits';
15
+ /**
16
+ * A cubic polynomial.
17
+ *
18
+ * All fields are readonly and immutable, and all operations create new instances.
19
+ *
20
+ * The `Traits` type parameter is a phantom marker that accumulates trait
21
+ * brands as the polynomial is refined via `isMonotonic` / `asMonotonic` and
22
+ * friends. A cubic is monotonic only over an interval that avoids both of its
23
+ * extrema (or globally, when c2 = c3 = 0 and c1 ≠ 0).
24
+ *
25
+ * @since 1.0.0
26
+ */
27
+ export interface CubicPolynomial<out Traits = unknown> extends Pipeable {
28
+ readonly [CubicPolynomialTypeId]: CubicPolynomialTypeId;
29
+ readonly [PolynomialTraits]: Traits;
30
+ /**
31
+ * The coefficient of the x^0 term.
32
+ */
33
+ readonly c0: number;
34
+ /**
35
+ * The coefficient of the x^1 term.
36
+ */
37
+ readonly c1: number;
38
+ /**
39
+ * The coefficient of the x^2 term.
40
+ */
41
+ readonly c2: number;
42
+ /**
43
+ * The coefficient of the x^3 term.
44
+ */
45
+ readonly c3: number;
46
+ }
47
+ /**
48
+ * Checks if a value is a `CubicPolynomial`.
49
+ *
50
+ * @param value - The value to check.
51
+ * @returns `true` if the value is a `CubicPolynomial`, `false` otherwise.
52
+ * @since 1.0.0
53
+ */
54
+ export declare const isCubicPolynomial: (value: unknown) => value is CubicPolynomial;
55
+ export declare const equals: {
56
+ /**
57
+ * Checks if two `CubicPolynomial` instances are approximately equal within
58
+ * the default absolute tolerance ({@link EPSILON}).
59
+ *
60
+ * @param a - The first polynomial.
61
+ * @param b - The second polynomial.
62
+ * @returns `true` when each pair of coefficients is within tolerance.
63
+ * @since 1.1.0
64
+ */
65
+ (a: CubicPolynomial, b: CubicPolynomial): boolean;
66
+ /**
67
+ * Checks if two `CubicPolynomial` instances are approximately equal within
68
+ * the default absolute tolerance ({@link EPSILON}).
69
+ *
70
+ * @param b - The second polynomial.
71
+ * @returns A function that takes the first polynomial and returns the comparison result.
72
+ * @since 1.1.0
73
+ */
74
+ (b: CubicPolynomial): (a: CubicPolynomial) => boolean;
75
+ };
76
+ /**
77
+ * Creates a new `CubicPolynomial` instance.
78
+ *
79
+ * @param c0 - The coefficient of the x^0 term.
80
+ * @param c1 - The coefficient of the x^1 term.
81
+ * @param c2 - The coefficient of the x^2 term.
82
+ * @param c3 - The coefficient of the x^3 term.
83
+ */
84
+ export declare const make: (c0: number, c1: number, c2: number, c3: number) => CubicPolynomial;
85
+ /**
86
+ * Creates a new `CubicPolynomial` instance from a vector.
87
+ *
88
+ * @param v - The vector to convert.
89
+ * @returns A new `CubicPolynomial` instance.
90
+ * @since 1.0.0
91
+ */
92
+ export declare const fromVector: (v: Vector4) => CubicPolynomial;
93
+ /**
94
+ * Creates a new `CubicPolynomial` that interpolates the four given points,
95
+ * treating each `Vector2` as an `(x, y)` pair. The four input `x` values must
96
+ * be distinct.
97
+ *
98
+ * @param p0 - The first point.
99
+ * @param p1 - The second point.
100
+ * @param p2 - The third point.
101
+ * @param p3 - The fourth point.
102
+ * @returns The unique cubic polynomial passing through the four points.
103
+ * @since 2.0.0
104
+ */
105
+ export declare const fromPoints: (p0: Vector2, p1: Vector2, p2: Vector2, p3: Vector2) => CubicPolynomial;
106
+ export declare const solve: {
107
+ /**
108
+ * Solves a cubic polynomial for a given value of x.
109
+ *
110
+ * @param p - The cubic polynomial to solve.
111
+ * @param x - The value of x to solve for.
112
+ * @returns The result of the polynomial evaluation at x.
113
+ * @since 1.0.0
114
+ */
115
+ (p: CubicPolynomial, x: number): number;
116
+ /**
117
+ * Solves a cubic polynomial for a given value of x.
118
+ *
119
+ * @param x - The value of x to solve for.
120
+ * @returns A function that takes a cubic polynomial and returns the result of the polynomial evaluation at x.
121
+ * @since 1.0.0
122
+ */
123
+ (x: number): (p: CubicPolynomial) => number;
124
+ };
125
+ /**
126
+ * Converts a cubic polynomial to a solver function.
127
+ *
128
+ * @param p - The cubic polynomial to convert.
129
+ * @returns A function that takes a value of x and returns the result of the polynomial evaluation at x.
130
+ * @since 1.0.0
131
+ */
132
+ export declare const toSolver: (p: CubicPolynomial) => (x: number) => number;
133
+ export declare const solveInverse: {
134
+ /**
135
+ * Solves a monotonic cubic polynomial for a given value of y. Because the
136
+ * polynomial is strictly monotonic, the inverse has at most one solution.
137
+ *
138
+ * @param p - The monotonic cubic polynomial.
139
+ * @param y - The value of y to solve for.
140
+ * @returns Zero or one solutions.
141
+ * @since 2.0.0
142
+ */
143
+ <T extends Monotonic>(p: CubicPolynomial<T>, y: number): Solution.AtMostOne<number>;
144
+ /**
145
+ * Solves a cubic polynomial for a given value of y.
146
+ *
147
+ * @param p - The cubic polynomial to solve.
148
+ * @param y - The value of y to solve for.
149
+ * @returns The roots of the polynomial equation p(x) = y.
150
+ * @since 1.0.0
151
+ */
152
+ <T>(p: CubicPolynomial<T>, y: number): Solution.AtMostThree<number>;
153
+ /**
154
+ * Solves a cubic polynomial for a given value of y.
155
+ *
156
+ * @param y - The value of y to solve for.
157
+ * @returns A function that takes a cubic polynomial and returns the roots
158
+ * of the polynomial equation p(x) = y. Tightens to `Solution.AtMostOne<number>` for
159
+ * monotonic inputs.
160
+ * @since 1.0.0
161
+ */
162
+ (y: number): {
163
+ <T extends Monotonic>(p: CubicPolynomial<T>): Solution.AtMostOne<number>;
164
+ <T>(p: CubicPolynomial<T>): Solution.AtMostThree<number>;
165
+ };
166
+ };
167
+ /**
168
+ * Converts a cubic polynomial to an inverse solver function.
169
+ *
170
+ * @param p - The cubic polynomial to convert.
171
+ * @returns A function that takes a value of y and returns the roots of the polynomial equation p(x) = y.
172
+ * @since 1.0.0
173
+ */
174
+ export declare const toInverseSolver: (p: CubicPolynomial) => (y: number) => Solution.AtMostThree<number>;
175
+ /**
176
+ * Returns the polynomial's coefficients as a tuple `[c0, c1, c2, c3]`.
177
+ *
178
+ * @param p - The cubic polynomial.
179
+ * @returns The coefficients in monomial order.
180
+ * @since 2.0.0
181
+ */
182
+ export declare const coefficients: (p: CubicPolynomial) => readonly [number, number, number, number];
183
+ /**
184
+ * Calculates the derivative of a cubic polynomial.
185
+ *
186
+ * @param p - The cubic polynomial to differentiate.
187
+ * @returns The derivative of the cubic polynomial.
188
+ * @since 1.0.0
189
+ */
190
+ export declare const derivative: (p: CubicPolynomial) => QuadraticPolynomial;
191
+ export declare const subdivide: {
192
+ /**
193
+ * Subdivides a cubic polynomial at parameter `t ∈ (0, 1)` into two new
194
+ * cubic polynomials. The first polynomial's evaluation on `[0, 1]` matches
195
+ * the original's on `[0, t]`; the second matches the original's on
196
+ * `[t, 1]`. Equivalent to de Casteljau subdivision in Bernstein form,
197
+ * performed directly in monomial form.
198
+ *
199
+ * @param p - The cubic polynomial to subdivide.
200
+ * @param t - The split parameter; must be in the open interval `(0, 1)`.
201
+ * @returns A `[left, right]` tuple of cubic polynomials.
202
+ * @since 2.0.0
203
+ */
204
+ (p: CubicPolynomial, t: number): [CubicPolynomial, CubicPolynomial];
205
+ /**
206
+ * Subdivides a cubic polynomial at parameter `t ∈ (0, 1)`.
207
+ *
208
+ * @param t - The split parameter; must be in the open interval `(0, 1)`.
209
+ * @returns A function that takes a polynomial and returns its `[left, right]` halves.
210
+ * @since 2.0.0
211
+ */
212
+ (t: number): (p: CubicPolynomial) => [CubicPolynomial, CubicPolynomial];
213
+ };
214
+ /**
215
+ * Calculates the roots of a cubic polynomial.
216
+ *
217
+ * @param p - The cubic polynomial to find the roots of.
218
+ * @returns The roots of the cubic polynomial.
219
+ * @since 1.0.0
220
+ */
221
+ export declare const roots: (p: CubicPolynomial) => Solution.AtMostThree<number>;
222
+ /**
223
+ * Calculates the extrema of a cubic polynomial.
224
+ *
225
+ * @param p - The cubic polynomial to find the extrema of.
226
+ * @returns The extrema of the cubic polynomial.
227
+ * @since 1.0.0
228
+ */
229
+ export declare const extrema: (p: CubicPolynomial) => Solution.AtMostTwo<number>;
230
+ export declare const monotonicity: {
231
+ /**
232
+ * Calculates the monotonicity of a cubic polynomial. Throws when the
233
+ * interval has zero width — the question is undefined at a single point.
234
+ *
235
+ * @param p - The cubic polynomial to analyze.
236
+ * @param i - The interval to restrict the analysis to.
237
+ * @returns The monotonicity of the cubic polynomial in the specified interval.
238
+ * @since 1.0.0
239
+ */
240
+ (p: CubicPolynomial, i?: Interval): Monotonicity;
241
+ /**
242
+ * Calculates the monotonicity of a cubic polynomial. Throws when the
243
+ * interval has zero width.
244
+ *
245
+ * @param i - The interval to restrict the analysis to.
246
+ * @returns A function that takes a cubic polynomial and returns the
247
+ * monotonicity of the cubic polynomial in the specified interval.
248
+ * @since 1.0.0
249
+ */
250
+ (i: Interval): (p: CubicPolynomial) => Monotonicity;
251
+ };
252
+ /**
253
+ * Type-narrowing predicate: refines a `CubicPolynomial<T>` to
254
+ * `CubicPolynomial<T & Monotonic>` when the polynomial is strictly monotonic
255
+ * over the given interval (or globally, when no interval is given).
256
+ *
257
+ * @param p - The cubic polynomial to check.
258
+ * @param i - Optional interval over which to check monotonicity.
259
+ * @returns `true` when monotonicity is `'increasing'` or `'decreasing'`.
260
+ * @since 2.0.0
261
+ */
262
+ export declare const isMonotonic: {
263
+ <T>(p: CubicPolynomial<T>, i?: Interval): p is CubicPolynomial<T & Monotonic>;
264
+ (i: Interval): <T>(p: CubicPolynomial<T>) => p is CubicPolynomial<T & Monotonic>;
265
+ };
266
+ /**
267
+ * Type-narrowing predicate: refines to `CubicPolynomial<T & Increasing>`.
268
+ *
269
+ * @since 2.0.0
270
+ */
271
+ export declare const isIncreasing: {
272
+ <T>(p: CubicPolynomial<T>, i?: Interval): p is CubicPolynomial<T & Increasing>;
273
+ (i: Interval): <T>(p: CubicPolynomial<T>) => p is CubicPolynomial<T & Increasing>;
274
+ };
275
+ /**
276
+ * Type-narrowing predicate: refines to `CubicPolynomial<T & Decreasing>`.
277
+ *
278
+ * @since 2.0.0
279
+ */
280
+ export declare const isDecreasing: {
281
+ <T>(p: CubicPolynomial<T>, i?: Interval): p is CubicPolynomial<T & Decreasing>;
282
+ (i: Interval): <T>(p: CubicPolynomial<T>) => p is CubicPolynomial<T & Decreasing>;
283
+ };
284
+ /**
285
+ * Asserts that the cubic polynomial is monotonic, throwing on failure.
286
+ *
287
+ * @param p - The cubic polynomial to assert against.
288
+ * @param i - Optional interval over which to check monotonicity.
289
+ * @returns The same polynomial, typed with the `Monotonic` brand.
290
+ * @throws When the polynomial is not monotonic over the given (or global) interval.
291
+ * @since 2.0.0
292
+ */
293
+ export declare const asMonotonic: <T>(p: CubicPolynomial<T>, i?: Interval) => CubicPolynomial<T & Monotonic>;
294
+ /**
295
+ * Asserts that the cubic polynomial is increasing, throwing on failure.
296
+ *
297
+ * @since 2.0.0
298
+ */
299
+ export declare const asIncreasing: <T>(p: CubicPolynomial<T>, i?: Interval) => CubicPolynomial<T & Increasing>;
300
+ /**
301
+ * Asserts that the cubic polynomial is decreasing, throwing on failure.
302
+ *
303
+ * @since 2.0.0
304
+ */
305
+ export declare const asDecreasing: <T>(p: CubicPolynomial<T>, i?: Interval) => CubicPolynomial<T & Decreasing>;
306
+ export declare const domain: {
307
+ /**
308
+ * Calculates the domain of a cubic polynomial.
309
+ *
310
+ * @param p - The cubic polynomial to analyze.
311
+ * @param range - The range to restrict the analysis to.
312
+ * @returns The domain of the cubic polynomial in the specified range.
313
+ * @since 1.0.0
314
+ */
315
+ (p: CubicPolynomial, range: Interval): Interval;
316
+ /**
317
+ * Calculates the domain of a cubic polynomial.
318
+ *
319
+ * @param range - The range to restrict the analysis to.
320
+ * @returns A function that takes a cubic polynomial and returns the domain of the cubic polynomial in the specified range.
321
+ * @since 1.0.0
322
+ */
323
+ (range: Interval): (p: CubicPolynomial) => Interval;
324
+ };
325
+ export declare const range: {
326
+ /**
327
+ * Calculates the range of a cubic polynomial.
328
+ *
329
+ * @param p - The cubic polynomial to analyze.
330
+ * @param domain - The domain to restrict the analysis to.
331
+ * @returns The range of the cubic polynomial in the specified domain.
332
+ * @since 1.0.0
333
+ */
334
+ (p: CubicPolynomial, domain: Interval): Closed;
335
+ /**
336
+ * Calculates the range of a cubic polynomial.
337
+ *
338
+ * @param domain - The domain to restrict the analysis to.
339
+ * @returns A function that takes a cubic polynomial and returns the range of the cubic polynomial in the specified domain.
340
+ * @since 1.0.0
341
+ */
342
+ (domain: Interval): (p: CubicPolynomial) => Closed;
343
+ };
344
+ export declare const length: {
345
+ /**
346
+ * Calculates the length of a cubic polynomial.
347
+ *
348
+ * @param p - The cubic polynomial to analyze.
349
+ * @param domain - The domain to restrict the analysis to.
350
+ * @returns The length of the cubic polynomial in the specified domain.
351
+ * @since 1.0.0
352
+ */
353
+ (p: CubicPolynomial, domain: Interval): number;
354
+ /**
355
+ * Calculates the length of a cubic polynomial.
356
+ *
357
+ * @param domain - The domain to restrict the analysis to.
358
+ * @returns A function that takes a cubic polynomial and returns the length of the cubic polynomial in the specified domain.
359
+ * @since 1.0.0
360
+ */
361
+ (domain: Interval): (p: CubicPolynomial) => number;
362
+ };
363
+ export declare const curvature: {
364
+ /**
365
+ * Calculates the curvature of a cubic polynomial.
366
+ *
367
+ * @param p - The cubic polynomial to analyze.
368
+ * @param x - The value of x to calculate the curvature at.
369
+ * @returns The curvature of the cubic polynomial at the specified value of x.
370
+ * @since 1.0.0
371
+ */
372
+ (p: CubicPolynomial, x: number): number;
373
+ /**
374
+ * Calculates the curvature of a cubic polynomial.
375
+ *
376
+ * @param x - The value of x to calculate the curvature at.
377
+ * @returns A function that takes a cubic polynomial and returns the curvature of the cubic polynomial at the specified value of x.
378
+ * @since 1.0.0
379
+ */
380
+ (x: number): (p: CubicPolynomial) => number;
381
+ };
@@ -0,0 +1,9 @@
1
+ import * as LinearPolynomialNs from './linear';
2
+ import * as QuadraticPolynomialNs from './quadratic';
3
+ import * as CubicPolynomialNs from './cubic';
4
+ export { LinearPolynomialNs as LinearPolynomial };
5
+ export type LinearPolynomial = LinearPolynomialNs.LinearPolynomial;
6
+ export { QuadraticPolynomialNs as QuadraticPolynomial };
7
+ export type QuadraticPolynomial = QuadraticPolynomialNs.QuadraticPolynomial;
8
+ export { CubicPolynomialNs as CubicPolynomial };
9
+ export type CubicPolynomial = CubicPolynomialNs.CubicPolynomial;