curvy 1.0.9 → 2.0.0-alpha.10

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 (204) hide show
  1. package/dist/characteristic/characteristic.d.ts +80 -0
  2. package/dist/characteristic/index.d.ts +1 -0
  3. package/dist/characteristic/index.mjs +2 -0
  4. package/dist/curve/cubic2d.d.ts +133 -27
  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 +2 -0
  8. package/dist/curve/linear2d.d.ts +125 -24
  9. package/dist/curve/linear2d.internal.d.ts +2 -0
  10. package/dist/curve/quadratic2d.d.ts +134 -28
  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 +3 -0
  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 +267 -0
  24. package/dist/matrix/index.mjs.map +1 -0
  25. package/dist/matrix/matrix2x2.d.ts +44 -29
  26. package/dist/matrix/matrix2x2.internal.d.ts +2 -0
  27. package/dist/matrix/matrix3x3.d.ts +64 -38
  28. package/dist/matrix/matrix3x3.internal.d.ts +4 -0
  29. package/dist/matrix/matrix4x4.d.ts +92 -34
  30. package/dist/matrix/matrix4x4.internal.d.ts +2 -0
  31. package/dist/number.d.ts +276 -0
  32. package/dist/number.mjs +140 -0
  33. package/dist/number.mjs.map +1 -0
  34. package/dist/path/cubic2d.d.ts +192 -25
  35. package/dist/path/cubic2d.internal.d.ts +2 -0
  36. package/dist/path/index.d.ts +12 -0
  37. package/dist/path/index.mjs +734 -0
  38. package/dist/path/index.mjs.map +1 -0
  39. package/dist/path/linear2d.d.ts +175 -25
  40. package/dist/path/linear2d.internal.d.ts +2 -0
  41. package/dist/path/quadratic2d.d.ts +165 -26
  42. package/dist/path/quadratic2d.internal.d.ts +2 -0
  43. package/dist/path/rationalCubic2d.d.ts +116 -0
  44. package/dist/path/rationalCubic2d.internal.d.ts +2 -0
  45. package/dist/path/traits.d.ts +95 -0
  46. package/dist/polynomial/cubic.d.ts +377 -7
  47. package/dist/polynomial/cubic.internal.circular.d.ts +2 -0
  48. package/dist/polynomial/cubic.internal.d.ts +1 -0
  49. package/dist/polynomial/index.d.ts +9 -0
  50. package/dist/polynomial/index.mjs +3 -0
  51. package/dist/polynomial/linear.d.ts +317 -7
  52. package/dist/polynomial/linear.internal.d.ts +2 -0
  53. package/dist/polynomial/monotonicity.d.ts +3 -0
  54. package/dist/polynomial/quadratic.d.ts +371 -7
  55. package/dist/polynomial/quadratic.internal.circular.d.ts +2 -0
  56. package/dist/polynomial/quadratic.internal.d.ts +1 -0
  57. package/dist/polynomial/traits.d.ts +56 -0
  58. package/dist/shared/characteristic-B0VEB_OA.mjs +104 -0
  59. package/dist/shared/characteristic-B0VEB_OA.mjs.map +1 -0
  60. package/dist/shared/chunk-25Hzd3z8.mjs +13 -0
  61. package/dist/shared/cubic-NEn7E6V_.mjs +575 -0
  62. package/dist/shared/cubic-NEn7E6V_.mjs.map +1 -0
  63. package/dist/shared/interval-CqC3ZIqj.mjs +460 -0
  64. package/dist/shared/interval-CqC3ZIqj.mjs.map +1 -0
  65. package/dist/shared/interval2d-C0eduE-V.mjs +149 -0
  66. package/dist/shared/interval2d-C0eduE-V.mjs.map +1 -0
  67. package/dist/shared/matrix4x4-BWmf4lZM.mjs +499 -0
  68. package/dist/shared/matrix4x4-BWmf4lZM.mjs.map +1 -0
  69. package/dist/shared/quadratic-Dlxqo2V1.mjs +348 -0
  70. package/dist/shared/quadratic-Dlxqo2V1.mjs.map +1 -0
  71. package/dist/shared/rationalCubic2d-3S5K69Jy.mjs +909 -0
  72. package/dist/shared/rationalCubic2d-3S5K69Jy.mjs.map +1 -0
  73. package/dist/shared/rationalCubic2d-CJY-feGw.mjs +508 -0
  74. package/dist/shared/rationalCubic2d-CJY-feGw.mjs.map +1 -0
  75. package/dist/shared/solution-UKGK826h.mjs +352 -0
  76. package/dist/shared/solution-UKGK826h.mjs.map +1 -0
  77. package/dist/shared/vector2-CSkaMXvp.mjs +205 -0
  78. package/dist/shared/vector2-CSkaMXvp.mjs.map +1 -0
  79. package/dist/shared/vector2.internal-DP1nTBdS.mjs +141 -0
  80. package/dist/shared/vector2.internal-DP1nTBdS.mjs.map +1 -0
  81. package/dist/shared/vector3-CR2LPV03.mjs +226 -0
  82. package/dist/shared/vector3-CR2LPV03.mjs.map +1 -0
  83. package/dist/shared/vector4-PO_7EYd-.mjs +171 -0
  84. package/dist/shared/vector4-PO_7EYd-.mjs.map +1 -0
  85. package/dist/shared/vector4.internal-BJ1QN2Ck.mjs +246 -0
  86. package/dist/shared/vector4.internal-BJ1QN2Ck.mjs.map +1 -0
  87. package/dist/solution/index.d.ts +1 -0
  88. package/dist/solution/index.mjs +2 -0
  89. package/dist/solution/solution.d.ts +264 -0
  90. package/dist/solution/solution.internal.d.ts +2 -0
  91. package/dist/splines/basis2d.d.ts +26 -38
  92. package/dist/splines/basis2d.internal.d.ts +2 -0
  93. package/dist/splines/bezier2d.d.ts +61 -45
  94. package/dist/splines/bezier2d.internal.d.ts +2 -0
  95. package/dist/splines/cardinal2d.d.ts +179 -88
  96. package/dist/splines/cardinal2d.internal.d.ts +2 -0
  97. package/dist/splines/hermite2d.d.ts +25 -36
  98. package/dist/splines/hermite2d.internal.d.ts +2 -0
  99. package/dist/splines/index.d.ts +15 -0
  100. package/dist/splines/index.mjs +946 -0
  101. package/dist/splines/index.mjs.map +1 -0
  102. package/dist/splines/rationalBezier2d.d.ts +144 -0
  103. package/dist/splines/rationalBezier2d.internal.d.ts +2 -0
  104. package/dist/splines/util.d.ts +5 -0
  105. package/dist/utils.d.ts +54 -186
  106. package/dist/utils.mjs +88 -52
  107. package/dist/utils.mjs.map +1 -1
  108. package/dist/vector/index.d.ts +9 -0
  109. package/dist/vector/index.mjs +4 -0
  110. package/dist/vector/vector2.d.ts +238 -33
  111. package/dist/vector/vector2.internal.d.ts +4 -0
  112. package/dist/vector/vector3.d.ts +198 -41
  113. package/dist/vector/vector3.internal.d.ts +2 -0
  114. package/dist/vector/vector4.d.ts +260 -23
  115. package/dist/vector/vector4.internal.d.ts +2 -0
  116. package/package.json +48 -91
  117. package/dist/curve/cubic2d.d.mts +0 -109
  118. package/dist/curve/cubic2d.mjs +0 -80
  119. package/dist/curve/cubic2d.mjs.map +0 -1
  120. package/dist/curve/linear2d.d.mts +0 -94
  121. package/dist/curve/linear2d.mjs +0 -46
  122. package/dist/curve/linear2d.mjs.map +0 -1
  123. package/dist/curve/quadratic2d.d.mts +0 -117
  124. package/dist/curve/quadratic2d.mjs +0 -82
  125. package/dist/curve/quadratic2d.mjs.map +0 -1
  126. package/dist/interval.d.mts +0 -251
  127. package/dist/interval.d.ts +0 -251
  128. package/dist/interval.mjs +0 -86
  129. package/dist/interval.mjs.map +0 -1
  130. package/dist/matrix/matrix2x2.d.mts +0 -320
  131. package/dist/matrix/matrix2x2.mjs +0 -25
  132. package/dist/matrix/matrix2x2.mjs.map +0 -1
  133. package/dist/matrix/matrix3x3.d.mts +0 -370
  134. package/dist/matrix/matrix3x3.mjs +0 -28
  135. package/dist/matrix/matrix3x3.mjs.map +0 -1
  136. package/dist/matrix/matrix4x4.d.mts +0 -381
  137. package/dist/matrix/matrix4x4.mjs +0 -178
  138. package/dist/matrix/matrix4x4.mjs.map +0 -1
  139. package/dist/path/cubic2d.d.mts +0 -95
  140. package/dist/path/cubic2d.mjs +0 -60
  141. package/dist/path/cubic2d.mjs.map +0 -1
  142. package/dist/path/linear2d.d.mts +0 -95
  143. package/dist/path/linear2d.mjs +0 -53
  144. package/dist/path/linear2d.mjs.map +0 -1
  145. package/dist/path/quadratic2d.d.mts +0 -95
  146. package/dist/path/quadratic2d.mjs +0 -57
  147. package/dist/path/quadratic2d.mjs.map +0 -1
  148. package/dist/pipe.d.mts +0 -58
  149. package/dist/pipe.d.ts +0 -58
  150. package/dist/pipe.mjs +0 -92
  151. package/dist/pipe.mjs.map +0 -1
  152. package/dist/polynomial/cubic.d.mts +0 -7
  153. package/dist/polynomial/cubic.mjs +0 -133
  154. package/dist/polynomial/cubic.mjs.map +0 -1
  155. package/dist/polynomial/linear.d.mts +0 -7
  156. package/dist/polynomial/linear.mjs +0 -24
  157. package/dist/polynomial/linear.mjs.map +0 -1
  158. package/dist/polynomial/quadratic.d.mts +0 -7
  159. package/dist/polynomial/quadratic.mjs +0 -27
  160. package/dist/polynomial/quadratic.mjs.map +0 -1
  161. package/dist/shared/curvy.Bf5TIk31.d.mts +0 -22
  162. package/dist/shared/curvy.Bf5TIk31.d.ts +0 -22
  163. package/dist/shared/curvy.BkkW8Tx9.mjs +0 -102
  164. package/dist/shared/curvy.BkkW8Tx9.mjs.map +0 -1
  165. package/dist/shared/curvy.BxdGW9he.mjs +0 -116
  166. package/dist/shared/curvy.BxdGW9he.mjs.map +0 -1
  167. package/dist/shared/curvy.C_sCeg9J.mjs +0 -66
  168. package/dist/shared/curvy.C_sCeg9J.mjs.map +0 -1
  169. package/dist/shared/curvy.Cg8lZVUz.d.ts +0 -688
  170. package/dist/shared/curvy.DCt1gGII.mjs +0 -147
  171. package/dist/shared/curvy.DCt1gGII.mjs.map +0 -1
  172. package/dist/shared/curvy.DJ4xO0al.mjs +0 -63
  173. package/dist/shared/curvy.DJ4xO0al.mjs.map +0 -1
  174. package/dist/shared/curvy.DmVFTi0N.mjs +0 -35
  175. package/dist/shared/curvy.DmVFTi0N.mjs.map +0 -1
  176. package/dist/shared/curvy.FDaj5rlj.d.mts +0 -688
  177. package/dist/shared/curvy.lktriTpx.mjs +0 -101
  178. package/dist/shared/curvy.lktriTpx.mjs.map +0 -1
  179. package/dist/shared/curvy.mLFprrGm.mjs +0 -85
  180. package/dist/shared/curvy.mLFprrGm.mjs.map +0 -1
  181. package/dist/shared/curvy.r6f1j287.mjs +0 -76
  182. package/dist/shared/curvy.r6f1j287.mjs.map +0 -1
  183. package/dist/splines/basis2d.d.mts +0 -130
  184. package/dist/splines/basis2d.mjs +0 -90
  185. package/dist/splines/basis2d.mjs.map +0 -1
  186. package/dist/splines/bezier2d.d.mts +0 -182
  187. package/dist/splines/bezier2d.mjs +0 -23
  188. package/dist/splines/bezier2d.mjs.map +0 -1
  189. package/dist/splines/cardinal2d.d.mts +0 -178
  190. package/dist/splines/cardinal2d.mjs +0 -114
  191. package/dist/splines/cardinal2d.mjs.map +0 -1
  192. package/dist/splines/hermite2d.d.mts +0 -124
  193. package/dist/splines/hermite2d.mjs +0 -63
  194. package/dist/splines/hermite2d.mjs.map +0 -1
  195. package/dist/utils.d.mts +0 -205
  196. package/dist/vector/vector2.d.mts +0 -324
  197. package/dist/vector/vector2.mjs +0 -30
  198. package/dist/vector/vector2.mjs.map +0 -1
  199. package/dist/vector/vector3.d.mts +0 -417
  200. package/dist/vector/vector3.mjs +0 -38
  201. package/dist/vector/vector3.mjs.map +0 -1
  202. package/dist/vector/vector4.d.mts +0 -205
  203. package/dist/vector/vector4.mjs +0 -20
  204. package/dist/vector/vector4.mjs.map +0 -1
@@ -0,0 +1,140 @@
1
+ import { dual } from "./utils.mjs";
2
+ //#region src/number.ts
3
+ const PRECISION = 8;
4
+ /**
5
+ * Default tolerance for approximate equality between floating-point numbers.
6
+ *
7
+ * @since 1.1.0
8
+ */
9
+ const EPSILON = 1e-10;
10
+ /**
11
+ * Approximate equality between two numbers, within an absolute tolerance.
12
+ *
13
+ * @param a - The first value.
14
+ * @param b - The second value.
15
+ * @param eps - The maximum allowed absolute difference. Defaults to {@link EPSILON}.
16
+ * @returns `true` when `|a - b| <= eps`.
17
+ * @since 1.1.0
18
+ */
19
+ function epsEquals(a, b, eps = EPSILON) {
20
+ return Math.abs(a - b) <= eps;
21
+ }
22
+ /**
23
+ * Snaps near-zero values to exactly zero for stable sign tests.
24
+ *
25
+ * @param value - The value to test.
26
+ * @param eps - The threshold below which `value` is considered zero.
27
+ * @returns `0` when `|value| < eps`, otherwise `value` unchanged.
28
+ * @since 1.1.0
29
+ */
30
+ function clampToZero(value, eps) {
31
+ return Math.abs(value) < eps ? 0 : value;
32
+ }
33
+ /**
34
+ * Rounding function that rounds a number to a specified precision.
35
+ *
36
+ * @param value - The number to round.
37
+ * @param precision - The number of decimal places to round to (default is 8).
38
+ * @returns The rounded number.
39
+ * @example
40
+ * ```ts
41
+ * import { round } from 'curvy/utils'
42
+ *
43
+ * const roundedValue = round(1.23456789, 4) // 1.2346
44
+ * const roundedValue2 = round(1.23456789) // 1.23456789
45
+ * ```
46
+ * @since 1.0.0
47
+ */
48
+ function round(value, precision = PRECISION) {
49
+ const scale = 10 ** precision;
50
+ const result = Math.round(value * scale) / scale;
51
+ if (result === 0) return 0;
52
+ return result;
53
+ }
54
+ /**
55
+ * Rounding function that rounds a number down to a specified precision.
56
+ *
57
+ * @param value - The number to round down.
58
+ * @param precision - The number of decimal places to round down to (default is 8).
59
+ * @returns The rounded down number.
60
+ * @example
61
+ * ```ts
62
+ * import { roundDown } from 'curvy/utils'
63
+ *
64
+ * const roundedDownValue = roundDown(1.23456789, 4) // 1.2345
65
+ * const roundedDownValue2 = roundDown(1.23456789) // 1.23456789
66
+ * ```
67
+ * @since 1.0.0
68
+ */
69
+ function roundDown(value, precision = PRECISION) {
70
+ const scale = 10 ** precision;
71
+ const result = Math.floor(value * scale) / scale;
72
+ if (result === 0) return 0;
73
+ return result;
74
+ }
75
+ /**
76
+ * Rounding function that rounds a number up to a specified precision.
77
+ *
78
+ * @param value - The number to round up.
79
+ * @param precision - The number of decimal places to round up to (default is 8).
80
+ * @returns The rounded up number.
81
+ * @example
82
+ * ```ts
83
+ * import { roundUp } from 'curvy/utils'
84
+ *
85
+ * const roundedUpValue = roundUp(1.23456789, 4) // 1.2346
86
+ * const roundedUpValue2 = roundUp(1.23456789) // 1.23456789
87
+ * ```
88
+ * @since 1.0.0
89
+ */
90
+ function roundUp(value, precision = PRECISION) {
91
+ const scale = 10 ** precision;
92
+ const result = Math.ceil(value * scale) / scale;
93
+ if (result === 0) return 0;
94
+ return result;
95
+ }
96
+ const lerp = dual(3, (t, a, b) => b * t + a * (1 - t));
97
+ const normalize = dual(3, (x, a, b) => (x - a) / (b - a));
98
+ const remap = dual(5, (x, x1, x2, y1, y2) => y1 + (x - x1) / (x2 - x1) * (y2 - y1));
99
+ const clamp = dual(3, (value, min, max) => value < min ? min : value > max ? max : value);
100
+ const clip = dual(4, (value, min, max, onClip) => value < min ? onClip : value > max ? onClip : value);
101
+ /**
102
+ * Returns the minimum and maximum of two numbers.
103
+ *
104
+ * @param a - The first number.
105
+ * @param b - The second number.
106
+ * @returns A tuple containing the minimum and maximum values.
107
+ * @example
108
+ * ```ts
109
+ * import { minMax } from 'curvy/utils'
110
+ *
111
+ * const [minValue, maxValue] = minMax(10, 20) // [10, 20]
112
+ * const [minValue2, maxValue2] = minMax(20, 10) // [10, 20]
113
+ * ```
114
+ * @since 1.0.0
115
+ */
116
+ function minMax(a, b) {
117
+ return a < b ? [a, b] : [b, a];
118
+ }
119
+ /**
120
+ * Calculates the modulus of a number.
121
+ *
122
+ * @param n - The number to calculate the modulus of.
123
+ * @param m - The modulus.
124
+ * @returns The modulus of the number.
125
+ * @example
126
+ * ```ts
127
+ * import { mod } from 'curvy/utils'
128
+ *
129
+ * const modulus = mod(10, 3) // 1
130
+ * const modulus2 = mod(-10, 3) // 2
131
+ * ```
132
+ * @since 1.0.0
133
+ */
134
+ function mod(n, m) {
135
+ return (n % m + m) % m;
136
+ }
137
+ //#endregion
138
+ export { EPSILON, clamp, clampToZero, clip, epsEquals, lerp, minMax, mod, normalize, remap, round, roundDown, roundUp };
139
+
140
+ //# sourceMappingURL=number.mjs.map
@@ -0,0 +1 @@
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"}
@@ -1,41 +1,42 @@
1
- import { CubicCurve2d } from '../curve/cubic2d.js';
2
- import { Pipeable } from '../pipe.js';
3
- import { Vector2 } from '../vector/vector2.js';
4
- import '../shared/curvy.Bf5TIk31.js';
5
- import '../interval.js';
6
- import '../shared/curvy.Cg8lZVUz.js';
7
- import '../vector/vector3.js';
8
- import '../vector/vector4.js';
9
-
10
- declare const CubicPath2dTypeId: unique symbol;
11
- type CubicPath2dTypeId = typeof CubicPath2dTypeId;
12
-
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';
13
10
  /**
14
11
  * A cubic path in 2D space.
15
12
  *
16
13
  * All fields are readonly and immutable, and all operations create new instances.
17
14
  *
15
+ * The `Trait` type parameter accumulates trait brands as the path is refined
16
+ * via `isContinuous` / `asContinuous`.
17
+ *
18
18
  * @since 1.0.0
19
19
  */
20
- interface CubicPath2d extends Pipeable, Iterable<CubicCurve2d> {
20
+ export interface CubicPath2d<out Trait = unknown> extends Pipeable, Iterable<CubicCurve2d> {
21
21
  readonly [CubicPath2dTypeId]: CubicPath2dTypeId;
22
+ readonly [PathTraits]: Trait;
22
23
  }
23
24
  /**
24
- * Creates a new `CubicPath2d` instance from curve parameters.
25
+ * Creates a new `CubicPath2d` instance from a sequence of curves.
25
26
  *
26
27
  * @param curves - The curves to create the path from.
27
28
  * @returns A new `CubicPath2d` instance.
28
- * @since 1.0.0
29
+ * @since 2.0.0
29
30
  */
30
- declare const fromCurves: (...curves: ReadonlyArray<CubicCurve2d>) => CubicPath2d;
31
+ export declare const make: (...curves: ReadonlyArray<CubicCurve2d>) => CubicPath2d;
31
32
  /**
32
33
  * Creates a new `CubicPath2d` instance from an array of curves.
33
34
  *
34
35
  * @param curves - The curves to create the path from.
35
36
  * @returns A new `CubicPath2d` instance.
36
- * @since 1.0.0
37
+ * @since 2.0.0
37
38
  */
38
- declare const fromCurveArray: (curves: ReadonlyArray<CubicCurve2d>) => CubicPath2d;
39
+ export declare const fromArray: (curves: ReadonlyArray<CubicCurve2d>) => CubicPath2d;
39
40
  /**
40
41
  * Checks if a value is a `CubicPath2d`.
41
42
  *
@@ -43,8 +44,8 @@ declare const fromCurveArray: (curves: ReadonlyArray<CubicCurve2d>) => CubicPath
43
44
  * @returns `true` if the value is a `CubicPath2d`, `false` otherwise.
44
45
  * @since 1.0.0
45
46
  */
46
- declare const isCubicPath2d: (p: unknown) => p is CubicPath2d;
47
- declare const append: {
47
+ export declare const isCubicPath2d: (p: unknown) => p is CubicPath2d;
48
+ export declare const append: {
48
49
  /**
49
50
  * Appends a cubic curve to a cubic path.
50
51
  *
@@ -70,8 +71,8 @@ declare const append: {
70
71
  * @returns The length of the cubic path.
71
72
  * @since 1.0.0
72
73
  */
73
- declare const length: (p: CubicPath2d) => number;
74
- declare const solve: {
74
+ export declare const length: (p: CubicPath2d) => number;
75
+ export declare const solve: {
75
76
  /**
76
77
  * Solves a cubic path for a given parameter.
77
78
  *
@@ -90,6 +91,172 @@ declare const solve: {
90
91
  */
91
92
  (p: CubicPath2d, u: number): Vector2;
92
93
  };
93
-
94
- export { append, fromCurveArray, fromCurves, isCubicPath2d, length, solve };
95
- export type { CubicPath2d };
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 };