curvy 2.0.0-alpha.6 → 2.0.0-alpha.7

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 (145) 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/characteristic/index.mjs +1 -1
  4. package/dist/curve/cubic2d.d.ts +215 -0
  5. package/dist/curve/cubic2d.internal.d.ts +2 -0
  6. package/dist/curve/index.d.ts +12 -0
  7. package/dist/curve/index.mjs +1 -1
  8. package/dist/curve/linear2d.d.ts +195 -0
  9. package/dist/curve/linear2d.internal.d.ts +2 -0
  10. package/dist/curve/quadratic2d.d.ts +223 -0
  11. package/dist/curve/quadratic2d.internal.d.ts +2 -0
  12. package/dist/curve/rationalCubic2d.d.ts +241 -0
  13. package/dist/curve/rationalCubic2d.internal.d.ts +2 -0
  14. package/dist/dimensions.d.ts +23 -0
  15. package/dist/interval/index.d.ts +6 -0
  16. package/dist/interval/index.mjs +2 -2
  17. package/dist/interval/interval.d.ts +525 -0
  18. package/dist/interval/interval.internal.d.ts +1 -0
  19. package/dist/interval/interval2d.d.ts +204 -0
  20. package/dist/interval/interval2d.internal.d.ts +2 -0
  21. package/dist/length.d.ts +32 -0
  22. package/dist/matrix/index.d.ts +9 -0
  23. package/dist/matrix/index.mjs +1 -1
  24. package/dist/matrix/index.mjs.map +1 -1
  25. package/dist/matrix/matrix2x2.d.ts +335 -0
  26. package/dist/matrix/matrix2x2.internal.d.ts +2 -0
  27. package/dist/matrix/matrix3x3.d.ts +396 -0
  28. package/dist/matrix/matrix3x3.internal.d.ts +4 -0
  29. package/dist/matrix/matrix4x4.d.ts +439 -0
  30. package/dist/matrix/matrix4x4.internal.d.ts +2 -0
  31. package/dist/number.d.ts +276 -0
  32. package/dist/number.mjs.map +1 -1
  33. package/dist/path/cubic2d.d.ts +262 -0
  34. package/dist/path/cubic2d.internal.d.ts +2 -0
  35. package/dist/path/index.d.ts +12 -0
  36. package/dist/path/index.mjs +413 -4
  37. package/dist/path/index.mjs.map +1 -1
  38. package/dist/path/linear2d.d.ts +245 -0
  39. package/dist/path/linear2d.internal.d.ts +2 -0
  40. package/dist/path/quadratic2d.d.ts +234 -0
  41. package/dist/path/quadratic2d.internal.d.ts +2 -0
  42. package/dist/path/rationalCubic2d.d.ts +116 -0
  43. package/dist/path/rationalCubic2d.internal.d.ts +2 -0
  44. package/dist/path/traits.d.ts +95 -0
  45. package/dist/polynomial/cubic.d.ts +377 -0
  46. package/dist/polynomial/cubic.internal.circular.d.ts +2 -0
  47. package/dist/polynomial/cubic.internal.d.ts +1 -0
  48. package/dist/polynomial/index.d.ts +9 -0
  49. package/dist/polynomial/index.mjs +2 -2
  50. package/dist/polynomial/linear.d.ts +317 -0
  51. package/dist/polynomial/linear.internal.d.ts +2 -0
  52. package/dist/polynomial/monotonicity.d.ts +3 -0
  53. package/dist/polynomial/quadratic.d.ts +371 -0
  54. package/dist/polynomial/quadratic.internal.circular.d.ts +2 -0
  55. package/dist/polynomial/quadratic.internal.d.ts +1 -0
  56. package/dist/polynomial/traits.d.ts +56 -0
  57. package/dist/shared/{characteristic-DLlhja-I.mjs → characteristic-D9yZWCym.mjs} +3 -3
  58. package/dist/shared/characteristic-D9yZWCym.mjs.map +1 -0
  59. package/dist/shared/{cubic-CMonq6bg.mjs → cubic-BK8xjSkd.mjs} +79 -4
  60. package/dist/shared/cubic-BK8xjSkd.mjs.map +1 -0
  61. package/dist/shared/{interval-X1EYuf-T.mjs → interval-CqC3ZIqj.mjs} +40 -1
  62. package/dist/shared/interval-CqC3ZIqj.mjs.map +1 -0
  63. package/dist/shared/{interval2d-ca0J1NMr.mjs → interval2d-BMDmeL1M.mjs} +45 -4
  64. package/dist/shared/interval2d-BMDmeL1M.mjs.map +1 -0
  65. package/dist/shared/{matrix4x4-Ck2WROK-.mjs → matrix4x4-qyRufxfs.mjs} +62 -3
  66. package/dist/shared/matrix4x4-qyRufxfs.mjs.map +1 -0
  67. package/dist/shared/{quadratic-DyeMtvET.mjs → quadratic-CWXIRh42.mjs} +2 -2
  68. package/dist/shared/quadratic-CWXIRh42.mjs.map +1 -0
  69. package/dist/shared/{rationalCubic2d-Vw4qGPZj.mjs → rationalCubic2d-BZvT9s5N.mjs} +218 -5
  70. package/dist/shared/rationalCubic2d-BZvT9s5N.mjs.map +1 -0
  71. package/dist/shared/{rationalCubic2d-D658ltUM.mjs → rationalCubic2d-DaFTrUXw.mjs} +250 -36
  72. package/dist/shared/rationalCubic2d-DaFTrUXw.mjs.map +1 -0
  73. package/dist/shared/{solution-3TDATEMn.mjs → solution-UKGK826h.mjs} +22 -2
  74. package/dist/shared/solution-UKGK826h.mjs.map +1 -0
  75. package/dist/shared/{vector2-CCuJx1rX.mjs → vector2-CWU3cPB2.mjs} +12 -2
  76. package/dist/shared/vector2-CWU3cPB2.mjs.map +1 -0
  77. package/dist/shared/{vector2.internal-DU_E808S.mjs → vector2.internal-BL8hFl1c.mjs} +31 -2
  78. package/dist/shared/vector2.internal-BL8hFl1c.mjs.map +1 -0
  79. package/dist/shared/{vector3-C-qgKAjR.mjs → vector3-DmMm6pX8.mjs} +12 -2
  80. package/dist/shared/vector3-DmMm6pX8.mjs.map +1 -0
  81. package/dist/shared/{vector4-BhOKDhD5.mjs → vector4-oqPPp45j.mjs} +12 -2
  82. package/dist/shared/vector4-oqPPp45j.mjs.map +1 -0
  83. package/dist/shared/{vector4.internal-5XcaX12X.mjs → vector4.internal-BnnTjVIr.mjs} +45 -2
  84. package/dist/shared/vector4.internal-BnnTjVIr.mjs.map +1 -0
  85. package/dist/solution/index.d.ts +1 -0
  86. package/dist/solution/index.mjs +1 -1
  87. package/dist/{shared/solution-Cf_zoKFU.d.mts → solution/solution.d.ts} +64 -71
  88. package/dist/solution/solution.internal.d.ts +2 -0
  89. package/dist/splines/basis2d.d.ts +118 -0
  90. package/dist/splines/basis2d.internal.d.ts +2 -0
  91. package/dist/splines/bezier2d.d.ts +198 -0
  92. package/dist/splines/bezier2d.internal.d.ts +2 -0
  93. package/dist/splines/cardinal2d.d.ts +269 -0
  94. package/dist/splines/cardinal2d.internal.d.ts +2 -0
  95. package/dist/splines/hermite2d.d.ts +113 -0
  96. package/dist/splines/hermite2d.internal.d.ts +2 -0
  97. package/dist/splines/index.d.ts +15 -0
  98. package/dist/splines/index.mjs +62 -8
  99. package/dist/splines/index.mjs.map +1 -1
  100. package/dist/splines/rationalBezier2d.d.ts +144 -0
  101. package/dist/splines/rationalBezier2d.internal.d.ts +2 -0
  102. package/dist/splines/util.d.ts +5 -0
  103. package/dist/utils.d.ts +73 -0
  104. package/dist/vector/index.d.ts +9 -0
  105. package/dist/vector/index.mjs +3 -3
  106. package/dist/vector/vector2.d.ts +449 -0
  107. package/dist/vector/vector2.internal.d.ts +4 -0
  108. package/dist/vector/vector3.d.ts +454 -0
  109. package/dist/vector/vector3.internal.d.ts +2 -0
  110. package/dist/vector/vector4.d.ts +258 -0
  111. package/dist/vector/vector4.internal.d.ts +2 -0
  112. package/package.json +13 -13
  113. package/dist/curve/index.d.mts +0 -2
  114. package/dist/interval/index.d.mts +0 -3
  115. package/dist/matrix/index.d.mts +0 -2
  116. package/dist/number.d.mts +0 -280
  117. package/dist/path/index.d.mts +0 -261
  118. package/dist/polynomial/index.d.mts +0 -2
  119. package/dist/shared/characteristic-DLlhja-I.mjs.map +0 -1
  120. package/dist/shared/cubic-C3ZMAoGj.d.mts +0 -1124
  121. package/dist/shared/cubic-CMonq6bg.mjs.map +0 -1
  122. package/dist/shared/interval-CSntLeSX.d.mts +0 -533
  123. package/dist/shared/interval-X1EYuf-T.mjs.map +0 -1
  124. package/dist/shared/interval2d-D42_0ka1.d.mts +0 -172
  125. package/dist/shared/interval2d-ca0J1NMr.mjs.map +0 -1
  126. package/dist/shared/matrix4x4-Ck2WROK-.mjs.map +0 -1
  127. package/dist/shared/matrix4x4-gy9ejrX2.d.mts +0 -1183
  128. package/dist/shared/quadratic-DyeMtvET.mjs.map +0 -1
  129. package/dist/shared/rationalCubic2d-C1RBShBF.d.mts +0 -818
  130. package/dist/shared/rationalCubic2d-D658ltUM.mjs.map +0 -1
  131. package/dist/shared/rationalCubic2d-DFFvp5S1.d.mts +0 -308
  132. package/dist/shared/rationalCubic2d-Vw4qGPZj.mjs.map +0 -1
  133. package/dist/shared/solution-3TDATEMn.mjs.map +0 -1
  134. package/dist/shared/utils-MCckigYk.d.mts +0 -76
  135. package/dist/shared/vector2-5GyA0jBj.d.mts +0 -470
  136. package/dist/shared/vector2-CCuJx1rX.mjs.map +0 -1
  137. package/dist/shared/vector2.internal-DU_E808S.mjs.map +0 -1
  138. package/dist/shared/vector3-BfOPFZEn.d.mts +0 -703
  139. package/dist/shared/vector3-C-qgKAjR.mjs.map +0 -1
  140. package/dist/shared/vector4-BhOKDhD5.mjs.map +0 -1
  141. package/dist/shared/vector4.internal-5XcaX12X.mjs.map +0 -1
  142. package/dist/solution/index.d.mts +0 -2
  143. package/dist/splines/index.d.mts +0 -858
  144. package/dist/utils.d.mts +0 -2
  145. package/dist/vector/index.d.mts +0 -3
@@ -0,0 +1,276 @@
1
+ /**
2
+ * Default tolerance for approximate equality between floating-point numbers.
3
+ *
4
+ * @since 1.1.0
5
+ */
6
+ export declare const EPSILON = 1e-10;
7
+ /**
8
+ * Approximate equality between two numbers, within an absolute tolerance.
9
+ *
10
+ * @param a - The first value.
11
+ * @param b - The second value.
12
+ * @param eps - The maximum allowed absolute difference. Defaults to {@link EPSILON}.
13
+ * @returns `true` when `|a - b| <= eps`.
14
+ * @since 1.1.0
15
+ */
16
+ export declare function epsEquals(a: number, b: number, eps?: number): boolean;
17
+ /**
18
+ * Snaps near-zero values to exactly zero for stable sign tests.
19
+ *
20
+ * @param value - The value to test.
21
+ * @param eps - The threshold below which `value` is considered zero.
22
+ * @returns `0` when `|value| < eps`, otherwise `value` unchanged.
23
+ * @since 1.1.0
24
+ */
25
+ export declare function clampToZero(value: number, eps: number): number;
26
+ /**
27
+ * Rounding function that rounds a number to a specified precision.
28
+ *
29
+ * @param value - The number to round.
30
+ * @param precision - The number of decimal places to round to (default is 8).
31
+ * @returns The rounded number.
32
+ * @example
33
+ * ```ts
34
+ * import { round } from 'curvy/utils'
35
+ *
36
+ * const roundedValue = round(1.23456789, 4) // 1.2346
37
+ * const roundedValue2 = round(1.23456789) // 1.23456789
38
+ * ```
39
+ * @since 1.0.0
40
+ */
41
+ export declare function round(value: number, precision?: number): number;
42
+ /**
43
+ * Rounding function that rounds a number down to a specified precision.
44
+ *
45
+ * @param value - The number to round down.
46
+ * @param precision - The number of decimal places to round down to (default is 8).
47
+ * @returns The rounded down number.
48
+ * @example
49
+ * ```ts
50
+ * import { roundDown } from 'curvy/utils'
51
+ *
52
+ * const roundedDownValue = roundDown(1.23456789, 4) // 1.2345
53
+ * const roundedDownValue2 = roundDown(1.23456789) // 1.23456789
54
+ * ```
55
+ * @since 1.0.0
56
+ */
57
+ export declare function roundDown(value: number, precision?: number): number;
58
+ /**
59
+ * Rounding function that rounds a number up to a specified precision.
60
+ *
61
+ * @param value - The number to round up.
62
+ * @param precision - The number of decimal places to round up to (default is 8).
63
+ * @returns The rounded up number.
64
+ * @example
65
+ * ```ts
66
+ * import { roundUp } from 'curvy/utils'
67
+ *
68
+ * const roundedUpValue = roundUp(1.23456789, 4) // 1.2346
69
+ * const roundedUpValue2 = roundUp(1.23456789) // 1.23456789
70
+ * ```
71
+ * @since 1.0.0
72
+ */
73
+ export declare function roundUp(value: number, precision?: number): number;
74
+ export declare const lerp: {
75
+ /**
76
+ * Linearly interpolates between two values.
77
+ *
78
+ * @param t - The interpolation factor (between 0 and 1).
79
+ * @param a - The start value.
80
+ * @param b - The end value.
81
+ * @returns The interpolated value.
82
+ * @example
83
+ * ```ts
84
+ * import { lerp } from 'curvy/utils'
85
+ *
86
+ * lerp(0.5, 10, 20) // 15
87
+ * ```
88
+ * @since 1.0.0
89
+ */
90
+ (t: number, a: number, b: number): number;
91
+ /**
92
+ * Linearly interpolates between two values.
93
+ *
94
+ * @param a - The start value.
95
+ * @param b - The end value.
96
+ * @returns A function that takes the interpolation factor and returns the interpolated value.
97
+ * @example
98
+ * ```ts
99
+ * import { lerp } from 'curvy/utils'
100
+ *
101
+ * lerp(10, 20)(0.5) // 15
102
+ * ```
103
+ * @since 1.0.0
104
+ */
105
+ (a: number, b: number): (t: number) => number;
106
+ };
107
+ export declare const normalize: {
108
+ /**
109
+ * Normalizes a value between two bounds to the unit interval.
110
+ *
111
+ * @param x - The value to normalize.
112
+ * @param a - The lower bound.
113
+ * @param b - The upper bound.
114
+ * @returns The normalized value.
115
+ * @example
116
+ * ```ts
117
+ * import { normalize } from 'curvy/utils'
118
+ *
119
+ * normalize(15, 10, 20) // 0.5
120
+ * ```
121
+ * @since 1.0.0
122
+ */
123
+ (x: number, a: number, b: number): number;
124
+ /**
125
+ * Normalizes a value between two bounds to the unit interval.
126
+ *
127
+ * @param a - The lower bound.
128
+ * @param b - The upper bound.
129
+ * @returns A function that takes a value and returns the normalized value.
130
+ * @example
131
+ * ```ts
132
+ * import { normalize } from 'curvy/utils'
133
+ *
134
+ * normalize(10, 20)(15) // 0.5
135
+ * ```
136
+ * @since 1.0.0
137
+ */
138
+ (a: number, b: number): (x: number) => number;
139
+ };
140
+ export declare const remap: {
141
+ /**
142
+ * Remaps a value from one range to another.
143
+ *
144
+ * @param x - The value to remap.
145
+ * @param x1 - The lower bound of the original range.
146
+ * @param x2 - The upper bound of the original range.
147
+ * @param y1 - The lower bound of the new range.
148
+ * @param y2 - The upper bound of the new range.
149
+ * @returns The remapped value.
150
+ * @example
151
+ * ```ts
152
+ * import { remap } from 'curvy/utils'
153
+ *
154
+ * remap(15, 10, 20, 0, 100) // 50
155
+ * ```
156
+ * @since 1.0.0
157
+ */
158
+ (x: number, x1: number, x2: number, y1: number, y2: number): number;
159
+ /**
160
+ * Remaps a value from one range to another.
161
+ *
162
+ * @param x1 - The lower bound of the original range.
163
+ * @param x2 - The upper bound of the original range.
164
+ * @param y1 - The lower bound of the new range.
165
+ * @param y2 - The upper bound of the new range.
166
+ * @returns A function that takes a value and returns the remapped value.
167
+ * @example
168
+ * ```ts
169
+ * import { remap } from 'curvy/utils'
170
+ *
171
+ * remap(10, 20, 0, 100)(15) // 50
172
+ * ```
173
+ * @since 1.0.0
174
+ */
175
+ (x1: number, x2: number, y1: number, y2: number): (x: number) => number;
176
+ };
177
+ export declare const clamp: {
178
+ /**
179
+ * Clamps a value between two bounds.
180
+ *
181
+ * @param value - The value to clamp.
182
+ * @param min - The lower bound.
183
+ * @param max - The upper bound.
184
+ * @returns The clamped value.
185
+ * @example
186
+ * ```ts
187
+ * import { clamp } from 'curvy/utils'
188
+ *
189
+ * clamp(25, 10, 20) // 20
190
+ * ```
191
+ * @since 1.0.0
192
+ */
193
+ (value: number, min: number, max: number): number;
194
+ /**
195
+ * Clamps a value between two bounds.
196
+ *
197
+ * @param min - The lower bound.
198
+ * @param max - The upper bound.
199
+ * @returns A function that takes a value and returns the clamped value.
200
+ * @example
201
+ * ```ts
202
+ * import { clamp } from 'curvy/utils'
203
+ *
204
+ * clamp(10, 20)(25) // 20
205
+ * ```
206
+ * @since 1.0.0
207
+ */
208
+ (min: number, max: number): (value: number) => number;
209
+ };
210
+ export declare const clip: {
211
+ /**
212
+ * Clips a value to a specified range, returning a fallback value if the value is outside the range.
213
+ *
214
+ * @param value - The value to clip.
215
+ * @param min - The lower bound.
216
+ * @param max - The upper bound.
217
+ * @param onClip - The fallback value to return if the value is outside the range.
218
+ * @returns The original value if within range, otherwise the fallback.
219
+ * @example
220
+ * ```ts
221
+ * import { clip } from 'curvy/utils'
222
+ *
223
+ * clip(25, 10, 20, 15) // 15
224
+ * ```
225
+ * @since 1.0.0
226
+ */
227
+ <T>(value: number, min: number, max: number, onClip: T): T | number;
228
+ /**
229
+ * Clips a value to a specified range, returning a fallback value if the value is outside the range.
230
+ *
231
+ * @param min - The lower bound.
232
+ * @param max - The upper bound.
233
+ * @param onClip - The fallback value to return if the value is outside the range.
234
+ * @returns A function that takes a value and returns it if within range, otherwise the fallback.
235
+ * @example
236
+ * ```ts
237
+ * import { clip } from 'curvy/utils'
238
+ *
239
+ * clip(10, 20, 15)(25) // 15
240
+ * ```
241
+ * @since 1.0.0
242
+ */
243
+ <T>(min: number, max: number, onClip: T): (value: number) => T | number;
244
+ };
245
+ /**
246
+ * Returns the minimum and maximum of two numbers.
247
+ *
248
+ * @param a - The first number.
249
+ * @param b - The second number.
250
+ * @returns A tuple containing the minimum and maximum values.
251
+ * @example
252
+ * ```ts
253
+ * import { minMax } from 'curvy/utils'
254
+ *
255
+ * const [minValue, maxValue] = minMax(10, 20) // [10, 20]
256
+ * const [minValue2, maxValue2] = minMax(20, 10) // [10, 20]
257
+ * ```
258
+ * @since 1.0.0
259
+ */
260
+ export declare function minMax(a: number, b: number): [number, number];
261
+ /**
262
+ * Calculates the modulus of a number.
263
+ *
264
+ * @param n - The number to calculate the modulus of.
265
+ * @param m - The modulus.
266
+ * @returns The modulus of the number.
267
+ * @example
268
+ * ```ts
269
+ * import { mod } from 'curvy/utils'
270
+ *
271
+ * const modulus = mod(10, 3) // 1
272
+ * const modulus2 = mod(-10, 3) // 2
273
+ * ```
274
+ * @since 1.0.0
275
+ */
276
+ export declare function mod(n: number, m: number): number;
@@ -1 +1 @@
1
- {"version":3,"file":"number.mjs","names":[],"sources":["../src/number.ts"],"sourcesContent":["import { dual } from './utils'\n\nconst PRECISION = 8\n\n/**\n * Default tolerance for approximate equality between floating-point numbers.\n *\n * @since 1.1.0\n */\nexport const EPSILON = 1e-10\n\n/**\n * Approximate equality between two numbers, within an absolute tolerance.\n *\n * @param a - The first value.\n * @param b - The second value.\n * @param eps - The maximum allowed absolute difference. Defaults to {@link EPSILON}.\n * @returns `true` when `|a - b| <= eps`.\n * @since 1.1.0\n */\nexport function epsEquals(a: number, b: number, eps: number = EPSILON): boolean {\n return Math.abs(a - b) <= eps\n}\n\n/**\n * Snaps near-zero values to exactly zero for stable sign tests.\n *\n * @param value - The value to test.\n * @param eps - The threshold below which `value` is considered zero.\n * @returns `0` when `|value| < eps`, otherwise `value` unchanged.\n * @since 1.1.0\n */\nexport function clampToZero(value: number, eps: number): number {\n return Math.abs(value) < eps ? 0 : value\n}\n\n/**\n * Rounding function that rounds a number to a specified precision.\n *\n * @param value - The number to round.\n * @param precision - The number of decimal places to round to (default is 8).\n * @returns The rounded number.\n * @example\n * ```ts\n * import { round } from 'curvy/utils'\n *\n * const roundedValue = round(1.23456789, 4) // 1.2346\n * const roundedValue2 = round(1.23456789) // 1.23456789\n * ```\n * @since 1.0.0\n */\nexport function round(value: number, precision = PRECISION): number {\n const scale = 10 ** precision\n const result = Math.round(value * scale) / scale\n if (result === 0) {\n return 0\n }\n return result\n}\n\n/**\n * Rounding function that rounds a number down to a specified precision.\n *\n * @param value - The number to round down.\n * @param precision - The number of decimal places to round down to (default is 8).\n * @returns The rounded down number.\n * @example\n * ```ts\n * import { roundDown } from 'curvy/utils'\n *\n * const roundedDownValue = roundDown(1.23456789, 4) // 1.2345\n * const roundedDownValue2 = roundDown(1.23456789) // 1.23456789\n * ```\n * @since 1.0.0\n */\nexport function roundDown(value: number, precision = PRECISION): number {\n const scale = 10 ** precision\n const result = Math.floor(value * scale) / scale\n if (result === 0) {\n return 0\n }\n return result\n}\n\n/**\n * Rounding function that rounds a number up to a specified precision.\n *\n * @param value - The number to round up.\n * @param precision - The number of decimal places to round up to (default is 8).\n * @returns The rounded up number.\n * @example\n * ```ts\n * import { roundUp } from 'curvy/utils'\n *\n * const roundedUpValue = roundUp(1.23456789, 4) // 1.2346\n * const roundedUpValue2 = roundUp(1.23456789) // 1.23456789\n * ```\n * @since 1.0.0\n */\nexport function roundUp(value: number, precision = PRECISION): number {\n const scale = 10 ** precision\n const result = Math.ceil(value * scale) / scale\n if (result === 0) {\n return 0\n }\n return result\n}\n\nexport const lerp: {\n /**\n * Linearly interpolates between two values.\n *\n * @param t - The interpolation factor (between 0 and 1).\n * @param a - The start value.\n * @param b - The end value.\n * @returns The interpolated value.\n * @example\n * ```ts\n * import { lerp } from 'curvy/utils'\n *\n * lerp(0.5, 10, 20) // 15\n * ```\n * @since 1.0.0\n */\n (t: number, a: number, b: number): number\n /**\n * Linearly interpolates between two values.\n *\n * @param a - The start value.\n * @param b - The end value.\n * @returns A function that takes the interpolation factor and returns the interpolated value.\n * @example\n * ```ts\n * import { lerp } from 'curvy/utils'\n *\n * lerp(10, 20)(0.5) // 15\n * ```\n * @since 1.0.0\n */\n (a: number, b: number): (t: number) => number\n} = dual(3, (t: number, a: number, b: number) => b * t + a * (1 - t))\n\nexport const normalize: {\n /**\n * Normalizes a value between two bounds to the unit interval.\n *\n * @param x - The value to normalize.\n * @param a - The lower bound.\n * @param b - The upper bound.\n * @returns The normalized value.\n * @example\n * ```ts\n * import { normalize } from 'curvy/utils'\n *\n * normalize(15, 10, 20) // 0.5\n * ```\n * @since 1.0.0\n */\n (x: number, a: number, b: number): number\n /**\n * Normalizes a value between two bounds to the unit interval.\n *\n * @param a - The lower bound.\n * @param b - The upper bound.\n * @returns A function that takes a value and returns the normalized value.\n * @example\n * ```ts\n * import { normalize } from 'curvy/utils'\n *\n * normalize(10, 20)(15) // 0.5\n * ```\n * @since 1.0.0\n */\n (a: number, b: number): (x: number) => number\n} = dual(3, (x: number, a: number, b: number) => (x - a) / (b - a))\n\nexport const remap: {\n /**\n * Remaps a value from one range to another.\n *\n * @param x - The value to remap.\n * @param x1 - The lower bound of the original range.\n * @param x2 - The upper bound of the original range.\n * @param y1 - The lower bound of the new range.\n * @param y2 - The upper bound of the new range.\n * @returns The remapped value.\n * @example\n * ```ts\n * import { remap } from 'curvy/utils'\n *\n * remap(15, 10, 20, 0, 100) // 50\n * ```\n * @since 1.0.0\n */\n (x: number, x1: number, x2: number, y1: number, y2: number): number\n /**\n * Remaps a value from one range to another.\n *\n * @param x1 - The lower bound of the original range.\n * @param x2 - The upper bound of the original range.\n * @param y1 - The lower bound of the new range.\n * @param y2 - The upper bound of the new range.\n * @returns A function that takes a value and returns the remapped value.\n * @example\n * ```ts\n * import { remap } from 'curvy/utils'\n *\n * remap(10, 20, 0, 100)(15) // 50\n * ```\n * @since 1.0.0\n */\n (x1: number, x2: number, y1: number, y2: number): (x: number) => number\n} = dual(\n 5,\n (x: number, x1: number, x2: number, y1: number, y2: number) =>\n y1 + ((x - x1) / (x2 - x1)) * (y2 - y1),\n)\n\nexport const clamp: {\n /**\n * Clamps a value between two bounds.\n *\n * @param value - The value to clamp.\n * @param min - The lower bound.\n * @param max - The upper bound.\n * @returns The clamped value.\n * @example\n * ```ts\n * import { clamp } from 'curvy/utils'\n *\n * clamp(25, 10, 20) // 20\n * ```\n * @since 1.0.0\n */\n (value: number, min: number, max: number): number\n /**\n * Clamps a value between two bounds.\n *\n * @param min - The lower bound.\n * @param max - The upper bound.\n * @returns A function that takes a value and returns the clamped value.\n * @example\n * ```ts\n * import { clamp } from 'curvy/utils'\n *\n * clamp(10, 20)(25) // 20\n * ```\n * @since 1.0.0\n */\n (min: number, max: number): (value: number) => number\n} = dual(3, (value: number, min: number, max: number) =>\n value < min ? min : value > max ? max : value,\n)\n\nexport const clip: {\n /**\n * Clips a value to a specified range, returning a fallback value if the value is outside the range.\n *\n * @param value - The value to clip.\n * @param min - The lower bound.\n * @param max - The upper bound.\n * @param onClip - The fallback value to return if the value is outside the range.\n * @returns The original value if within range, otherwise the fallback.\n * @example\n * ```ts\n * import { clip } from 'curvy/utils'\n *\n * clip(25, 10, 20, 15) // 15\n * ```\n * @since 1.0.0\n */\n <T>(value: number, min: number, max: number, onClip: T): T | number\n /**\n * Clips a value to a specified range, returning a fallback value if the value is outside the range.\n *\n * @param min - The lower bound.\n * @param max - The upper bound.\n * @param onClip - The fallback value to return if the value is outside the range.\n * @returns A function that takes a value and returns it if within range, otherwise the fallback.\n * @example\n * ```ts\n * import { clip } from 'curvy/utils'\n *\n * clip(10, 20, 15)(25) // 15\n * ```\n * @since 1.0.0\n */\n <T>(min: number, max: number, onClip: T): (value: number) => T | number\n} = dual(4, (value: number, min: number, max: number, onClip: unknown) =>\n value < min ? onClip : value > max ? onClip : value,\n)\n\n/**\n * Returns the minimum and maximum of two numbers.\n *\n * @param a - The first number.\n * @param b - The second number.\n * @returns A tuple containing the minimum and maximum values.\n * @example\n * ```ts\n * import { minMax } from 'curvy/utils'\n *\n * const [minValue, maxValue] = minMax(10, 20) // [10, 20]\n * const [minValue2, maxValue2] = minMax(20, 10) // [10, 20]\n * ```\n * @since 1.0.0\n */\nexport function minMax(a: number, b: number): [number, number] {\n return a < b ? [a, b] : [b, a]\n}\n\n/**\n * Calculates the modulus of a number.\n *\n * @param n - The number to calculate the modulus of.\n * @param m - The modulus.\n * @returns The modulus of the number.\n * @example\n * ```ts\n * import { mod } from 'curvy/utils'\n *\n * const modulus = mod(10, 3) // 1\n * const modulus2 = mod(-10, 3) // 2\n * ```\n * @since 1.0.0\n */\nexport function mod(n: number, m: number): number {\n return ((n % m) + m) % m\n}\n"],"mappings":";;AAEA,MAAM,YAAY;;;;;;AAOlB,MAAa,UAAU;;;;;;;;;;AAWvB,SAAgB,UAAU,GAAW,GAAW,MAAc,SAAkB;CAC9E,OAAO,KAAK,IAAI,IAAI,EAAE,IAAI;;;;;;;;;;AAW5B,SAAgB,YAAY,OAAe,KAAqB;CAC9D,OAAO,KAAK,IAAI,MAAM,GAAG,MAAM,IAAI;;;;;;;;;;;;;;;;;AAkBrC,SAAgB,MAAM,OAAe,YAAY,WAAmB;CAClE,MAAM,QAAQ,MAAM;CACpB,MAAM,SAAS,KAAK,MAAM,QAAQ,MAAM,GAAG;CAC3C,IAAI,WAAW,GACb,OAAO;CAET,OAAO;;;;;;;;;;;;;;;;;AAkBT,SAAgB,UAAU,OAAe,YAAY,WAAmB;CACtE,MAAM,QAAQ,MAAM;CACpB,MAAM,SAAS,KAAK,MAAM,QAAQ,MAAM,GAAG;CAC3C,IAAI,WAAW,GACb,OAAO;CAET,OAAO;;;;;;;;;;;;;;;;;AAkBT,SAAgB,QAAQ,OAAe,YAAY,WAAmB;CACpE,MAAM,QAAQ,MAAM;CACpB,MAAM,SAAS,KAAK,KAAK,QAAQ,MAAM,GAAG;CAC1C,IAAI,WAAW,GACb,OAAO;CAET,OAAO;;AAGT,MAAa,OAgCT,KAAK,IAAI,GAAW,GAAW,MAAc,IAAI,IAAI,KAAK,IAAI,GAAG;AAErE,MAAa,YAgCT,KAAK,IAAI,GAAW,GAAW,OAAe,IAAI,MAAM,IAAI,GAAG;AAEnE,MAAa,QAoCT,KACF,IACC,GAAW,IAAY,IAAY,IAAY,OAC9C,MAAO,IAAI,OAAO,KAAK,OAAQ,KAAK,IACvC;AAED,MAAa,QAgCT,KAAK,IAAI,OAAe,KAAa,QACvC,QAAQ,MAAM,MAAM,QAAQ,MAAM,MAAM,MACzC;AAED,MAAa,OAkCT,KAAK,IAAI,OAAe,KAAa,KAAa,WACpD,QAAQ,MAAM,SAAS,QAAQ,MAAM,SAAS,MAC/C;;;;;;;;;;;;;;;;AAiBD,SAAgB,OAAO,GAAW,GAA6B;CAC7D,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE;;;;;;;;;;;;;;;;;AAkBhC,SAAgB,IAAI,GAAW,GAAmB;CAChD,QAAS,IAAI,IAAK,KAAK"}
1
+ {"version":3,"file":"number.mjs","names":[],"sources":["../src/number.ts"],"sourcesContent":["import { dual } from './utils.ts'\n\nconst PRECISION = 8\n\n/**\n * Default tolerance for approximate equality between floating-point numbers.\n *\n * @since 1.1.0\n */\nexport const EPSILON = 1e-10\n\n/**\n * Approximate equality between two numbers, within an absolute tolerance.\n *\n * @param a - The first value.\n * @param b - The second value.\n * @param eps - The maximum allowed absolute difference. Defaults to {@link EPSILON}.\n * @returns `true` when `|a - b| <= eps`.\n * @since 1.1.0\n */\nexport function epsEquals(a: number, b: number, eps: number = EPSILON): boolean {\n return Math.abs(a - b) <= eps\n}\n\n/**\n * Snaps near-zero values to exactly zero for stable sign tests.\n *\n * @param value - The value to test.\n * @param eps - The threshold below which `value` is considered zero.\n * @returns `0` when `|value| < eps`, otherwise `value` unchanged.\n * @since 1.1.0\n */\nexport function clampToZero(value: number, eps: number): number {\n return Math.abs(value) < eps ? 0 : value\n}\n\n/**\n * Rounding function that rounds a number to a specified precision.\n *\n * @param value - The number to round.\n * @param precision - The number of decimal places to round to (default is 8).\n * @returns The rounded number.\n * @example\n * ```ts\n * import { round } from 'curvy/utils'\n *\n * const roundedValue = round(1.23456789, 4) // 1.2346\n * const roundedValue2 = round(1.23456789) // 1.23456789\n * ```\n * @since 1.0.0\n */\nexport function round(value: number, precision = PRECISION): number {\n const scale = 10 ** precision\n const result = Math.round(value * scale) / scale\n if (result === 0) {\n return 0\n }\n return result\n}\n\n/**\n * Rounding function that rounds a number down to a specified precision.\n *\n * @param value - The number to round down.\n * @param precision - The number of decimal places to round down to (default is 8).\n * @returns The rounded down number.\n * @example\n * ```ts\n * import { roundDown } from 'curvy/utils'\n *\n * const roundedDownValue = roundDown(1.23456789, 4) // 1.2345\n * const roundedDownValue2 = roundDown(1.23456789) // 1.23456789\n * ```\n * @since 1.0.0\n */\nexport function roundDown(value: number, precision = PRECISION): number {\n const scale = 10 ** precision\n const result = Math.floor(value * scale) / scale\n if (result === 0) {\n return 0\n }\n return result\n}\n\n/**\n * Rounding function that rounds a number up to a specified precision.\n *\n * @param value - The number to round up.\n * @param precision - The number of decimal places to round up to (default is 8).\n * @returns The rounded up number.\n * @example\n * ```ts\n * import { roundUp } from 'curvy/utils'\n *\n * const roundedUpValue = roundUp(1.23456789, 4) // 1.2346\n * const roundedUpValue2 = roundUp(1.23456789) // 1.23456789\n * ```\n * @since 1.0.0\n */\nexport function roundUp(value: number, precision = PRECISION): number {\n const scale = 10 ** precision\n const result = Math.ceil(value * scale) / scale\n if (result === 0) {\n return 0\n }\n return result\n}\n\nexport const lerp: {\n /**\n * Linearly interpolates between two values.\n *\n * @param t - The interpolation factor (between 0 and 1).\n * @param a - The start value.\n * @param b - The end value.\n * @returns The interpolated value.\n * @example\n * ```ts\n * import { lerp } from 'curvy/utils'\n *\n * lerp(0.5, 10, 20) // 15\n * ```\n * @since 1.0.0\n */\n (t: number, a: number, b: number): number\n /**\n * Linearly interpolates between two values.\n *\n * @param a - The start value.\n * @param b - The end value.\n * @returns A function that takes the interpolation factor and returns the interpolated value.\n * @example\n * ```ts\n * import { lerp } from 'curvy/utils'\n *\n * lerp(10, 20)(0.5) // 15\n * ```\n * @since 1.0.0\n */\n (a: number, b: number): (t: number) => number\n} = dual(3, (t: number, a: number, b: number) => b * t + a * (1 - t))\n\nexport const normalize: {\n /**\n * Normalizes a value between two bounds to the unit interval.\n *\n * @param x - The value to normalize.\n * @param a - The lower bound.\n * @param b - The upper bound.\n * @returns The normalized value.\n * @example\n * ```ts\n * import { normalize } from 'curvy/utils'\n *\n * normalize(15, 10, 20) // 0.5\n * ```\n * @since 1.0.0\n */\n (x: number, a: number, b: number): number\n /**\n * Normalizes a value between two bounds to the unit interval.\n *\n * @param a - The lower bound.\n * @param b - The upper bound.\n * @returns A function that takes a value and returns the normalized value.\n * @example\n * ```ts\n * import { normalize } from 'curvy/utils'\n *\n * normalize(10, 20)(15) // 0.5\n * ```\n * @since 1.0.0\n */\n (a: number, b: number): (x: number) => number\n} = dual(3, (x: number, a: number, b: number) => (x - a) / (b - a))\n\nexport const remap: {\n /**\n * Remaps a value from one range to another.\n *\n * @param x - The value to remap.\n * @param x1 - The lower bound of the original range.\n * @param x2 - The upper bound of the original range.\n * @param y1 - The lower bound of the new range.\n * @param y2 - The upper bound of the new range.\n * @returns The remapped value.\n * @example\n * ```ts\n * import { remap } from 'curvy/utils'\n *\n * remap(15, 10, 20, 0, 100) // 50\n * ```\n * @since 1.0.0\n */\n (x: number, x1: number, x2: number, y1: number, y2: number): number\n /**\n * Remaps a value from one range to another.\n *\n * @param x1 - The lower bound of the original range.\n * @param x2 - The upper bound of the original range.\n * @param y1 - The lower bound of the new range.\n * @param y2 - The upper bound of the new range.\n * @returns A function that takes a value and returns the remapped value.\n * @example\n * ```ts\n * import { remap } from 'curvy/utils'\n *\n * remap(10, 20, 0, 100)(15) // 50\n * ```\n * @since 1.0.0\n */\n (x1: number, x2: number, y1: number, y2: number): (x: number) => number\n} = dual(\n 5,\n (x: number, x1: number, x2: number, y1: number, y2: number) =>\n y1 + ((x - x1) / (x2 - x1)) * (y2 - y1),\n)\n\nexport const clamp: {\n /**\n * Clamps a value between two bounds.\n *\n * @param value - The value to clamp.\n * @param min - The lower bound.\n * @param max - The upper bound.\n * @returns The clamped value.\n * @example\n * ```ts\n * import { clamp } from 'curvy/utils'\n *\n * clamp(25, 10, 20) // 20\n * ```\n * @since 1.0.0\n */\n (value: number, min: number, max: number): number\n /**\n * Clamps a value between two bounds.\n *\n * @param min - The lower bound.\n * @param max - The upper bound.\n * @returns A function that takes a value and returns the clamped value.\n * @example\n * ```ts\n * import { clamp } from 'curvy/utils'\n *\n * clamp(10, 20)(25) // 20\n * ```\n * @since 1.0.0\n */\n (min: number, max: number): (value: number) => number\n} = dual(3, (value: number, min: number, max: number) =>\n value < min ? min : value > max ? max : value,\n)\n\nexport const clip: {\n /**\n * Clips a value to a specified range, returning a fallback value if the value is outside the range.\n *\n * @param value - The value to clip.\n * @param min - The lower bound.\n * @param max - The upper bound.\n * @param onClip - The fallback value to return if the value is outside the range.\n * @returns The original value if within range, otherwise the fallback.\n * @example\n * ```ts\n * import { clip } from 'curvy/utils'\n *\n * clip(25, 10, 20, 15) // 15\n * ```\n * @since 1.0.0\n */\n <T>(value: number, min: number, max: number, onClip: T): T | number\n /**\n * Clips a value to a specified range, returning a fallback value if the value is outside the range.\n *\n * @param min - The lower bound.\n * @param max - The upper bound.\n * @param onClip - The fallback value to return if the value is outside the range.\n * @returns A function that takes a value and returns it if within range, otherwise the fallback.\n * @example\n * ```ts\n * import { clip } from 'curvy/utils'\n *\n * clip(10, 20, 15)(25) // 15\n * ```\n * @since 1.0.0\n */\n <T>(min: number, max: number, onClip: T): (value: number) => T | number\n} = dual(4, (value: number, min: number, max: number, onClip: unknown) =>\n value < min ? onClip : value > max ? onClip : value,\n)\n\n/**\n * Returns the minimum and maximum of two numbers.\n *\n * @param a - The first number.\n * @param b - The second number.\n * @returns A tuple containing the minimum and maximum values.\n * @example\n * ```ts\n * import { minMax } from 'curvy/utils'\n *\n * const [minValue, maxValue] = minMax(10, 20) // [10, 20]\n * const [minValue2, maxValue2] = minMax(20, 10) // [10, 20]\n * ```\n * @since 1.0.0\n */\nexport function minMax(a: number, b: number): [number, number] {\n return a < b ? [a, b] : [b, a]\n}\n\n/**\n * Calculates the modulus of a number.\n *\n * @param n - The number to calculate the modulus of.\n * @param m - The modulus.\n * @returns The modulus of the number.\n * @example\n * ```ts\n * import { mod } from 'curvy/utils'\n *\n * const modulus = mod(10, 3) // 1\n * const modulus2 = mod(-10, 3) // 2\n * ```\n * @since 1.0.0\n */\nexport function mod(n: number, m: number): number {\n return ((n % m) + m) % m\n}\n"],"mappings":";;AAEA,MAAM,YAAY;;;;;;AAOlB,MAAa,UAAU;;;;;;;;;;AAWvB,SAAgB,UAAU,GAAW,GAAW,MAAc,SAAkB;CAC9E,OAAO,KAAK,IAAI,IAAI,EAAE,IAAI;;;;;;;;;;AAW5B,SAAgB,YAAY,OAAe,KAAqB;CAC9D,OAAO,KAAK,IAAI,MAAM,GAAG,MAAM,IAAI;;;;;;;;;;;;;;;;;AAkBrC,SAAgB,MAAM,OAAe,YAAY,WAAmB;CAClE,MAAM,QAAQ,MAAM;CACpB,MAAM,SAAS,KAAK,MAAM,QAAQ,MAAM,GAAG;CAC3C,IAAI,WAAW,GACb,OAAO;CAET,OAAO;;;;;;;;;;;;;;;;;AAkBT,SAAgB,UAAU,OAAe,YAAY,WAAmB;CACtE,MAAM,QAAQ,MAAM;CACpB,MAAM,SAAS,KAAK,MAAM,QAAQ,MAAM,GAAG;CAC3C,IAAI,WAAW,GACb,OAAO;CAET,OAAO;;;;;;;;;;;;;;;;;AAkBT,SAAgB,QAAQ,OAAe,YAAY,WAAmB;CACpE,MAAM,QAAQ,MAAM;CACpB,MAAM,SAAS,KAAK,KAAK,QAAQ,MAAM,GAAG;CAC1C,IAAI,WAAW,GACb,OAAO;CAET,OAAO;;AAGT,MAAa,OAgCT,KAAK,IAAI,GAAW,GAAW,MAAc,IAAI,IAAI,KAAK,IAAI,GAAG;AAErE,MAAa,YAgCT,KAAK,IAAI,GAAW,GAAW,OAAe,IAAI,MAAM,IAAI,GAAG;AAEnE,MAAa,QAoCT,KACF,IACC,GAAW,IAAY,IAAY,IAAY,OAC9C,MAAO,IAAI,OAAO,KAAK,OAAQ,KAAK,IACvC;AAED,MAAa,QAgCT,KAAK,IAAI,OAAe,KAAa,QACvC,QAAQ,MAAM,MAAM,QAAQ,MAAM,MAAM,MACzC;AAED,MAAa,OAkCT,KAAK,IAAI,OAAe,KAAa,KAAa,WACpD,QAAQ,MAAM,SAAS,QAAQ,MAAM,SAAS,MAC/C;;;;;;;;;;;;;;;;AAiBD,SAAgB,OAAO,GAAW,GAA6B;CAC7D,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE;;;;;;;;;;;;;;;;;AAkBhC,SAAgB,IAAI,GAAW,GAAmB;CAChD,QAAS,IAAI,IAAK,KAAK"}
@@ -0,0 +1,262 @@
1
+ import type { Interval2d } from '../interval/interval2d.ts';
2
+ import type { CubicCurve2d } from '../curve/cubic2d.ts';
3
+ import type { Closed } from '../interval/interval.ts';
4
+ import type * as Solution from '../solution/solution.ts';
5
+ import type { Pipeable } from '../utils.ts';
6
+ import type { Vector2 } from '../vector/vector2.ts';
7
+ import type { CubicPath2dTypeId } from './cubic2d.internal.ts';
8
+ import type { Continuous, DecreasingX, DecreasingY, IncreasingX, IncreasingY, MonotonicX, MonotonicY, PathTraits } from './traits.ts';
9
+ export type { Continuous, DecreasingX, DecreasingY, IncreasingX, IncreasingY, MonotonicX, MonotonicY, } from './traits.ts';
10
+ /**
11
+ * A cubic path in 2D space.
12
+ *
13
+ * All fields are readonly and immutable, and all operations create new instances.
14
+ *
15
+ * The `Trait` type parameter accumulates trait brands as the path is refined
16
+ * via `isContinuous` / `asContinuous`.
17
+ *
18
+ * @since 1.0.0
19
+ */
20
+ export interface CubicPath2d<out Trait = unknown> extends Pipeable, Iterable<CubicCurve2d> {
21
+ readonly [CubicPath2dTypeId]: CubicPath2dTypeId;
22
+ readonly [PathTraits]: Trait;
23
+ }
24
+ /**
25
+ * Creates a new `CubicPath2d` instance from a sequence of curves.
26
+ *
27
+ * @param curves - The curves to create the path from.
28
+ * @returns A new `CubicPath2d` instance.
29
+ * @since 2.0.0
30
+ */
31
+ export declare const make: (...curves: ReadonlyArray<CubicCurve2d>) => CubicPath2d;
32
+ /**
33
+ * Creates a new `CubicPath2d` instance from an array of curves.
34
+ *
35
+ * @param curves - The curves to create the path from.
36
+ * @returns A new `CubicPath2d` instance.
37
+ * @since 2.0.0
38
+ */
39
+ export declare const fromArray: (curves: ReadonlyArray<CubicCurve2d>) => CubicPath2d;
40
+ /**
41
+ * Checks if a value is a `CubicPath2d`.
42
+ *
43
+ * @param p - The value to check.
44
+ * @returns `true` if the value is a `CubicPath2d`, `false` otherwise.
45
+ * @since 1.0.0
46
+ */
47
+ export declare const isCubicPath2d: (p: unknown) => p is CubicPath2d;
48
+ export declare const append: {
49
+ /**
50
+ * Appends a cubic curve to a cubic path.
51
+ *
52
+ * @param c - The cubic curve to append.
53
+ * @returns A function that takes a cubic path and returns a new cubic path.
54
+ * @since 1.0.0
55
+ */
56
+ (c: CubicCurve2d): (p: CubicPath2d) => CubicPath2d;
57
+ /**
58
+ * Appends a cubic curve to a cubic path.
59
+ *
60
+ * @param p - The cubic path to append to.
61
+ * @param c - The cubic curve to append.
62
+ * @returns A new cubic path.
63
+ * @since 1.0.0
64
+ */
65
+ (p: CubicPath2d, c: CubicCurve2d): CubicPath2d;
66
+ };
67
+ /**
68
+ * Calculates the length of a cubic path.
69
+ *
70
+ * @param p - The cubic path to calculate the length of.
71
+ * @returns The length of the cubic path.
72
+ * @since 1.0.0
73
+ */
74
+ export declare const length: (p: CubicPath2d) => number;
75
+ export declare const solve: {
76
+ /**
77
+ * Solves a cubic path for a given parameter.
78
+ *
79
+ * @param u - The parameter to solve for.
80
+ * @returns A function that takes a cubic path and returns the solved vector.
81
+ * @since 1.0.0
82
+ */
83
+ (u: number): (p: CubicPath2d) => Vector2;
84
+ /**
85
+ * Solves a cubic path for a given parameter.
86
+ *
87
+ * @param p - The cubic path to solve.
88
+ * @param u - The parameter to solve for.
89
+ * @returns The solved vector.
90
+ * @since 1.0.0
91
+ */
92
+ (p: CubicPath2d, u: number): Vector2;
93
+ };
94
+ /**
95
+ * Serializes a cubic path as an SVG path data string (the value of a `<path>`
96
+ * element's `d` attribute), using `M` and `C` commands. Discontinuities between
97
+ * curves emit a fresh `M` command.
98
+ *
99
+ * @param p - The cubic path to serialize.
100
+ * @returns The SVG path data string.
101
+ * @since 2.0.0
102
+ */
103
+ export declare const toPathData: (p: CubicPath2d) => string;
104
+ /**
105
+ * Type-narrowing predicate: refines `CubicPath2d<T>` to
106
+ * `CubicPath2d<T & Continuous>` when adjacent curves connect.
107
+ *
108
+ * @since 2.0.0
109
+ */
110
+ export declare const isContinuous: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & Continuous>;
111
+ /**
112
+ * Asserts that the cubic path is continuous, throwing on failure.
113
+ *
114
+ * @since 2.0.0
115
+ */
116
+ export declare const asContinuous: <T>(p: CubicPath2d<T>) => CubicPath2d<T & Continuous>;
117
+ /**
118
+ * Type-narrowing predicate: refines `CubicPath2d<T>` to
119
+ * `CubicPath2d<T & IncreasingX>` when every segment's x-polynomial is
120
+ * strictly increasing on `[0, 1]` and adjacent segments' x-ranges don't
121
+ * overlap.
122
+ *
123
+ * @since 2.0.0
124
+ */
125
+ export declare const isIncreasingX: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & IncreasingX>;
126
+ /**
127
+ * Type-narrowing predicate: refines `CubicPath2d<T>` to
128
+ * `CubicPath2d<T & DecreasingX>`.
129
+ *
130
+ * @since 2.0.0
131
+ */
132
+ export declare const isDecreasingX: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & DecreasingX>;
133
+ /**
134
+ * Type-narrowing predicate: refines `CubicPath2d<T>` to
135
+ * `CubicPath2d<T & MonotonicX>`.
136
+ *
137
+ * @since 2.0.0
138
+ */
139
+ export declare const isMonotonicX: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & MonotonicX>;
140
+ /**
141
+ * Type-narrowing predicate: refines `CubicPath2d<T>` to
142
+ * `CubicPath2d<T & IncreasingY>`.
143
+ *
144
+ * @since 2.0.0
145
+ */
146
+ export declare const isIncreasingY: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & IncreasingY>;
147
+ /**
148
+ * Type-narrowing predicate: refines `CubicPath2d<T>` to
149
+ * `CubicPath2d<T & DecreasingY>`.
150
+ *
151
+ * @since 2.0.0
152
+ */
153
+ export declare const isDecreasingY: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & DecreasingY>;
154
+ /**
155
+ * Type-narrowing predicate: refines `CubicPath2d<T>` to
156
+ * `CubicPath2d<T & MonotonicY>`.
157
+ *
158
+ * @since 2.0.0
159
+ */
160
+ export declare const isMonotonicY: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & MonotonicY>;
161
+ /**
162
+ * Asserts that the path is strictly increasing in x, throwing on failure.
163
+ *
164
+ * @since 2.0.0
165
+ */
166
+ export declare const asIncreasingX: <T>(p: CubicPath2d<T>) => CubicPath2d<T & IncreasingX>;
167
+ /**
168
+ * Asserts that the path is strictly decreasing in x, throwing on failure.
169
+ *
170
+ * @since 2.0.0
171
+ */
172
+ export declare const asDecreasingX: <T>(p: CubicPath2d<T>) => CubicPath2d<T & DecreasingX>;
173
+ /**
174
+ * Asserts that the path is monotonic in x, throwing on failure.
175
+ *
176
+ * @since 2.0.0
177
+ */
178
+ export declare const asMonotonicX: <T>(p: CubicPath2d<T>) => CubicPath2d<T & MonotonicX>;
179
+ /**
180
+ * Asserts that the path is strictly increasing in y, throwing on failure.
181
+ *
182
+ * @since 2.0.0
183
+ */
184
+ export declare const asIncreasingY: <T>(p: CubicPath2d<T>) => CubicPath2d<T & IncreasingY>;
185
+ /**
186
+ * Asserts that the path is strictly decreasing in y, throwing on failure.
187
+ *
188
+ * @since 2.0.0
189
+ */
190
+ export declare const asDecreasingY: <T>(p: CubicPath2d<T>) => CubicPath2d<T & DecreasingY>;
191
+ /**
192
+ * Asserts that the path is monotonic in y, throwing on failure.
193
+ *
194
+ * @since 2.0.0
195
+ */
196
+ export declare const asMonotonicY: <T>(p: CubicPath2d<T>) => CubicPath2d<T & MonotonicY>;
197
+ export declare const solveAtX: {
198
+ /**
199
+ * Evaluates the path's y value at a given x. Requires the path to carry
200
+ * the `MonotonicX` brand. Returns `Solution.none` when x is outside the
201
+ * path's x-range.
202
+ *
203
+ * @param p - A path branded `MonotonicX`.
204
+ * @param x - The x coordinate.
205
+ * @returns The y value at x, or `none` when x is outside the path's range.
206
+ * @since 2.0.0
207
+ */
208
+ <T extends MonotonicX>(p: CubicPath2d<T>, x: number): Solution.AtMostOne<number>;
209
+ /** @since 2.0.0 */
210
+ (x: number): <T extends MonotonicX>(p: CubicPath2d<T>) => Solution.AtMostOne<number>;
211
+ };
212
+ export declare const solveAtY: {
213
+ /**
214
+ * Evaluates the path's x value at a given y. Requires the path to carry
215
+ * the `MonotonicY` brand. Returns `Solution.none` when y is outside the
216
+ * path's y-range.
217
+ *
218
+ * @param p - A path branded `MonotonicY`.
219
+ * @param y - The y coordinate.
220
+ * @returns The x value at y, or `none` when y is outside the path's range.
221
+ * @since 2.0.0
222
+ */
223
+ <T extends MonotonicY>(p: CubicPath2d<T>, y: number): Solution.AtMostOne<number>;
224
+ /** @since 2.0.0 */
225
+ (y: number): <T extends MonotonicY>(p: CubicPath2d<T>) => Solution.AtMostOne<number>;
226
+ };
227
+ export declare const solveByDistance: {
228
+ /**
229
+ * Solves a cubic path by normalized arc length. Unlike {@link solve}, which
230
+ * is parameterized by curve `u`, this samples points at constant speed along
231
+ * the path — `s = 0.5` returns the point exactly halfway along the curve by
232
+ * arc length, regardless of how the underlying parameterization stretches.
233
+ *
234
+ * Cumulative segment lengths are cached by path identity so repeated calls
235
+ * with the same path are fast.
236
+ *
237
+ * @param p - The cubic path to sample.
238
+ * @param s - Normalized arc length in `[0, 1]`. Values outside the range are
239
+ * clamped to path endpoints.
240
+ * @returns The point on the path at the given normalized arc length.
241
+ * @since 1.1.0
242
+ */
243
+ (p: CubicPath2d, s: number): Vector2;
244
+ /**
245
+ * Solves a cubic path by normalized arc length.
246
+ *
247
+ * @param s - Normalized arc length in `[0, 1]`.
248
+ * @returns A function that takes a cubic path and returns the point at that
249
+ * arc length.
250
+ * @since 1.1.0
251
+ */
252
+ (s: number): (p: CubicPath2d) => Vector2;
253
+ };
254
+ /**
255
+ * Computes the axis-aligned bounding box of the path — the smallest closed
256
+ * `Box2d` enclosing every segment.
257
+ *
258
+ * @param p - The cubic path.
259
+ * @returns A closed `Box2d` enclosing the path.
260
+ * @since 2.0.0
261
+ */
262
+ export declare const boundingBox: (p: CubicPath2d) => Interval2d<Closed, Closed>;
@@ -0,0 +1,2 @@
1
+ export declare const CubicPath2dTypeId: unique symbol;
2
+ export type CubicPath2dTypeId = typeof CubicPath2dTypeId;
@@ -0,0 +1,12 @@
1
+ import * as LinearPath2dNs from './linear2d.ts';
2
+ import * as QuadraticPath2dNs from './quadratic2d.ts';
3
+ import * as CubicPath2dNs from './cubic2d.ts';
4
+ import * as RationalCubicPath2dNs from './rationalCubic2d.ts';
5
+ export type LinearPath2d<Trait = unknown> = LinearPath2dNs.LinearPath2d<Trait>;
6
+ export { LinearPath2dNs as LinearPath2d };
7
+ export type QuadraticPath2d<Trait = unknown> = QuadraticPath2dNs.QuadraticPath2d<Trait>;
8
+ export { QuadraticPath2dNs as QuadraticPath2d };
9
+ export type CubicPath2d<Trait = unknown> = CubicPath2dNs.CubicPath2d<Trait>;
10
+ export { CubicPath2dNs as CubicPath2d };
11
+ export type RationalCubicPath2d = RationalCubicPath2dNs.RationalCubicPath2d;
12
+ export { RationalCubicPath2dNs as RationalCubicPath2d };