curvy 2.0.0-alpha.5 → 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.
- package/dist/characteristic/characteristic.d.ts +3 -3
- package/dist/characteristic/index.d.ts +1 -1
- package/dist/characteristic/index.mjs +1 -1
- package/dist/curve/cubic2d.d.ts +10 -14
- package/dist/curve/cubic2d.internal.d.ts +2 -0
- package/dist/curve/index.d.ts +8 -8
- package/dist/curve/index.mjs +1 -1
- package/dist/curve/linear2d.d.ts +11 -15
- package/dist/curve/linear2d.internal.d.ts +2 -0
- package/dist/curve/quadratic2d.d.ts +11 -15
- package/dist/curve/quadratic2d.internal.d.ts +2 -0
- package/dist/curve/rationalCubic2d.d.ts +63 -22
- package/dist/curve/rationalCubic2d.internal.d.ts +2 -0
- package/dist/interval/index.d.ts +4 -4
- package/dist/interval/index.mjs +2 -2
- package/dist/interval/interval.d.ts +1 -1
- package/dist/interval/interval.internal.d.ts +1 -0
- package/dist/interval/interval2d.d.ts +45 -8
- package/dist/interval/interval2d.internal.d.ts +2 -0
- package/dist/matrix/index.d.ts +6 -6
- package/dist/matrix/index.mjs +1 -1
- package/dist/matrix/index.mjs.map +1 -1
- package/dist/matrix/matrix2x2.d.ts +4 -8
- package/dist/matrix/matrix2x2.internal.d.ts +2 -0
- package/dist/matrix/matrix3x3.d.ts +5 -9
- package/dist/matrix/matrix3x3.internal.d.ts +4 -0
- package/dist/matrix/matrix4x4.d.ts +5 -9
- package/dist/matrix/matrix4x4.internal.d.ts +2 -0
- package/dist/number.mjs.map +1 -1
- package/dist/path/cubic2d.d.ts +119 -12
- package/dist/path/cubic2d.internal.d.ts +2 -0
- package/dist/path/index.d.ts +8 -8
- package/dist/path/index.mjs +413 -4
- package/dist/path/index.mjs.map +1 -1
- package/dist/path/linear2d.d.ts +122 -12
- package/dist/path/linear2d.internal.d.ts +2 -0
- package/dist/path/quadratic2d.d.ts +119 -12
- package/dist/path/quadratic2d.internal.d.ts +2 -0
- package/dist/path/rationalCubic2d.d.ts +5 -9
- package/dist/path/rationalCubic2d.internal.d.ts +2 -0
- package/dist/path/traits.d.ts +64 -0
- package/dist/polynomial/cubic.d.ts +10 -14
- package/dist/polynomial/cubic.internal.circular.d.ts +2 -0
- package/dist/polynomial/cubic.internal.d.ts +1 -0
- package/dist/polynomial/index.d.ts +6 -6
- package/dist/polynomial/index.mjs +2 -2
- package/dist/polynomial/linear.d.ts +9 -13
- package/dist/polynomial/linear.internal.d.ts +2 -0
- package/dist/polynomial/quadratic.d.ts +11 -15
- package/dist/polynomial/quadratic.internal.circular.d.ts +2 -0
- package/dist/polynomial/quadratic.internal.d.ts +1 -0
- package/dist/shared/{characteristic-DLlhja-I.mjs → characteristic-D9yZWCym.mjs} +3 -3
- package/dist/shared/characteristic-D9yZWCym.mjs.map +1 -0
- package/dist/shared/{cubic-CMonq6bg.mjs → cubic-BK8xjSkd.mjs} +79 -4
- package/dist/shared/cubic-BK8xjSkd.mjs.map +1 -0
- package/dist/shared/{interval-X1EYuf-T.mjs → interval-CqC3ZIqj.mjs} +40 -1
- package/dist/shared/interval-CqC3ZIqj.mjs.map +1 -0
- package/dist/shared/{interval2d-ca0J1NMr.mjs → interval2d-BMDmeL1M.mjs} +45 -4
- package/dist/shared/interval2d-BMDmeL1M.mjs.map +1 -0
- package/dist/shared/{matrix4x4-Ck2WROK-.mjs → matrix4x4-qyRufxfs.mjs} +62 -3
- package/dist/shared/matrix4x4-qyRufxfs.mjs.map +1 -0
- package/dist/shared/{quadratic-DyeMtvET.mjs → quadratic-CWXIRh42.mjs} +2 -2
- package/dist/shared/quadratic-CWXIRh42.mjs.map +1 -0
- package/dist/shared/{rationalCubic2d-Vw4qGPZj.mjs → rationalCubic2d-BZvT9s5N.mjs} +218 -5
- package/dist/shared/rationalCubic2d-BZvT9s5N.mjs.map +1 -0
- package/dist/shared/{rationalCubic2d-D658ltUM.mjs → rationalCubic2d-DaFTrUXw.mjs} +250 -36
- package/dist/shared/rationalCubic2d-DaFTrUXw.mjs.map +1 -0
- package/dist/shared/{solution-3TDATEMn.mjs → solution-UKGK826h.mjs} +22 -2
- package/dist/shared/solution-UKGK826h.mjs.map +1 -0
- package/dist/shared/{vector2-CCuJx1rX.mjs → vector2-CWU3cPB2.mjs} +12 -2
- package/dist/shared/vector2-CWU3cPB2.mjs.map +1 -0
- package/dist/shared/{vector2.internal-DU_E808S.mjs → vector2.internal-BL8hFl1c.mjs} +31 -2
- package/dist/shared/vector2.internal-BL8hFl1c.mjs.map +1 -0
- package/dist/shared/{vector3-C-qgKAjR.mjs → vector3-DmMm6pX8.mjs} +12 -2
- package/dist/shared/vector3-DmMm6pX8.mjs.map +1 -0
- package/dist/shared/{vector4-BhOKDhD5.mjs → vector4-oqPPp45j.mjs} +12 -2
- package/dist/shared/vector4-oqPPp45j.mjs.map +1 -0
- package/dist/shared/{vector4.internal-5XcaX12X.mjs → vector4.internal-BnnTjVIr.mjs} +45 -2
- package/dist/shared/vector4.internal-BnnTjVIr.mjs.map +1 -0
- package/dist/solution/index.d.ts +1 -3
- package/dist/solution/index.mjs +1 -1
- package/dist/solution/solution.d.ts +2 -2
- package/dist/solution/solution.internal.d.ts +2 -0
- package/dist/splines/basis2d.d.ts +5 -9
- package/dist/splines/basis2d.internal.d.ts +2 -0
- package/dist/splines/bezier2d.d.ts +6 -10
- package/dist/splines/bezier2d.internal.d.ts +2 -0
- package/dist/splines/cardinal2d.d.ts +5 -9
- package/dist/splines/cardinal2d.internal.d.ts +2 -0
- package/dist/splines/hermite2d.d.ts +5 -9
- package/dist/splines/hermite2d.internal.d.ts +2 -0
- package/dist/splines/index.d.ts +10 -10
- package/dist/splines/index.mjs +62 -8
- package/dist/splines/index.mjs.map +1 -1
- package/dist/splines/rationalBezier2d.d.ts +5 -9
- package/dist/splines/rationalBezier2d.internal.d.ts +2 -0
- package/dist/splines/util.d.ts +3 -3
- package/dist/vector/index.d.ts +6 -6
- package/dist/vector/index.mjs +3 -3
- package/dist/vector/vector2.d.ts +12 -9
- package/dist/vector/vector2.internal.d.ts +4 -0
- package/dist/vector/vector3.d.ts +12 -7
- package/dist/vector/vector3.internal.d.ts +2 -0
- package/dist/vector/vector4.d.ts +12 -7
- package/dist/vector/vector4.internal.d.ts +2 -0
- package/package.json +2 -2
- package/dist/shared/characteristic-DLlhja-I.mjs.map +0 -1
- package/dist/shared/cubic-CMonq6bg.mjs.map +0 -1
- package/dist/shared/interval-X1EYuf-T.mjs.map +0 -1
- package/dist/shared/interval2d-ca0J1NMr.mjs.map +0 -1
- package/dist/shared/matrix4x4-Ck2WROK-.mjs.map +0 -1
- package/dist/shared/quadratic-DyeMtvET.mjs.map +0 -1
- package/dist/shared/rationalCubic2d-D658ltUM.mjs.map +0 -1
- package/dist/shared/rationalCubic2d-Vw4qGPZj.mjs.map +0 -1
- package/dist/shared/solution-3TDATEMn.mjs.map +0 -1
- package/dist/shared/vector2-CCuJx1rX.mjs.map +0 -1
- package/dist/shared/vector2.internal-DU_E808S.mjs.map +0 -1
- package/dist/shared/vector3-C-qgKAjR.mjs.map +0 -1
- package/dist/shared/vector4-BhOKDhD5.mjs.map +0 -1
- package/dist/shared/vector4.internal-5XcaX12X.mjs.map +0 -1
package/dist/number.mjs.map
CHANGED
|
@@ -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"}
|
package/dist/path/cubic2d.d.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import type { Interval2d } from '../interval/interval2d';
|
|
2
|
-
import type { CubicCurve2d } from '../curve/cubic2d';
|
|
3
|
-
import type { Closed } from '../interval/interval';
|
|
4
|
-
import type
|
|
5
|
-
import type {
|
|
6
|
-
|
|
7
|
-
import type {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type CubicPath2dTypeId = typeof CubicPath2dTypeId;
|
|
11
|
-
|
|
12
|
-
export type { Continuous } from './traits';
|
|
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
|
*
|
|
@@ -117,6 +114,116 @@ export declare const isContinuous: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T
|
|
|
117
114
|
* @since 2.0.0
|
|
118
115
|
*/
|
|
119
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
|
+
};
|
|
120
227
|
export declare const solveByDistance: {
|
|
121
228
|
/**
|
|
122
229
|
* Solves a cubic path by normalized arc length. Unlike {@link solve}, which
|
package/dist/path/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import * as LinearPath2dNs from './linear2d';
|
|
2
|
-
import * as QuadraticPath2dNs from './quadratic2d';
|
|
3
|
-
import * as CubicPath2dNs from './cubic2d';
|
|
4
|
-
import * as RationalCubicPath2dNs from './rationalCubic2d';
|
|
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>;
|
|
5
6
|
export { LinearPath2dNs as LinearPath2d };
|
|
6
|
-
export type
|
|
7
|
+
export type QuadraticPath2d<Trait = unknown> = QuadraticPath2dNs.QuadraticPath2d<Trait>;
|
|
7
8
|
export { QuadraticPath2dNs as QuadraticPath2d };
|
|
8
|
-
export type
|
|
9
|
+
export type CubicPath2d<Trait = unknown> = CubicPath2dNs.CubicPath2d<Trait>;
|
|
9
10
|
export { CubicPath2dNs as CubicPath2d };
|
|
10
|
-
export type CubicPath2d = CubicPath2dNs.CubicPath2d;
|
|
11
|
-
export { RationalCubicPath2dNs as RationalCubicPath2d };
|
|
12
11
|
export type RationalCubicPath2d = RationalCubicPath2dNs.RationalCubicPath2d;
|
|
12
|
+
export { RationalCubicPath2dNs as RationalCubicPath2d };
|