curvy 2.0.0-alpha.13 → 2.0.0-alpha.14

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 (93) hide show
  1. package/dist/characteristic/index.mjs +1 -1
  2. package/dist/curve/cubic2d.d.ts +102 -3
  3. package/dist/curve/curve2d.d.ts +81 -0
  4. package/dist/curve/index.mjs +1 -1
  5. package/dist/curve/linear2d.d.ts +122 -3
  6. package/dist/curve/quadratic2d.d.ts +103 -3
  7. package/dist/curve/rationalCubic2d.d.ts +100 -38
  8. package/dist/interval/index.mjs +2 -2
  9. package/dist/matrix/index.mjs +47 -1
  10. package/dist/matrix/index.mjs.map +1 -1
  11. package/dist/matrix/matrix3x3.d.ts +87 -1
  12. package/dist/matrix/matrix4x4.d.ts +57 -6
  13. package/dist/matrix/traits.d.ts +34 -0
  14. package/dist/monotonicity/index.mjs +1 -1
  15. package/dist/monotonicity/monotonicity.d.ts +25 -0
  16. package/dist/number.d.ts +53 -0
  17. package/dist/number.mjs +56 -1
  18. package/dist/number.mjs.map +1 -1
  19. package/dist/path/cubic2d.d.ts +22 -0
  20. package/dist/path/index.mjs +25 -149
  21. package/dist/path/index.mjs.map +1 -1
  22. package/dist/path/linear2d.d.ts +24 -0
  23. package/dist/path/path2d.d.ts +54 -0
  24. package/dist/path/quadratic2d.d.ts +22 -0
  25. package/dist/path/rationalCubic2d.d.ts +21 -0
  26. package/dist/polynomial/index.mjs +2 -2
  27. package/dist/shared/affine2d-Dvna84gc.mjs +332 -0
  28. package/dist/shared/affine2d-Dvna84gc.mjs.map +1 -0
  29. package/dist/shared/{characteristic-BkEr-rr8.mjs → characteristic--7nC4Q_a.mjs} +4 -5
  30. package/dist/shared/characteristic--7nC4Q_a.mjs.map +1 -0
  31. package/dist/shared/{cubic-BL6dpuHh.mjs → cubic-BiGuAnZ0.mjs} +56 -27
  32. package/dist/shared/cubic-BiGuAnZ0.mjs.map +1 -0
  33. package/dist/shared/{interval-Dm35Xhy4.mjs → interval-Dcqpo73t.mjs} +5 -5
  34. package/dist/shared/interval-Dcqpo73t.mjs.map +1 -0
  35. package/dist/shared/{interval2d-AtneyI45.mjs → interval2d-C2Pk66-2.mjs} +3 -3
  36. package/dist/shared/{interval2d-AtneyI45.mjs.map → interval2d-C2Pk66-2.mjs.map} +1 -1
  37. package/dist/shared/matrix3x3.internal-Cod-r7H3.mjs +233 -0
  38. package/dist/shared/matrix3x3.internal-Cod-r7H3.mjs.map +1 -0
  39. package/dist/shared/{matrix4x4-BWmf4lZM.mjs → matrix4x4-BrqgYZCD.mjs} +72 -223
  40. package/dist/shared/matrix4x4-BrqgYZCD.mjs.map +1 -0
  41. package/dist/shared/monotonicity-DNxBoC7F.mjs +64 -0
  42. package/dist/shared/monotonicity-DNxBoC7F.mjs.map +1 -0
  43. package/dist/shared/{quadratic-DPrUsFCp.mjs → quadratic-BmMqkvxx.mjs} +2 -2
  44. package/dist/shared/{quadratic-DPrUsFCp.mjs.map → quadratic-BmMqkvxx.mjs.map} +1 -1
  45. package/dist/shared/{rationalCubic2d-CeHgpNht.mjs → rationalCubic2d-CZSwwKtS.mjs} +591 -125
  46. package/dist/shared/rationalCubic2d-CZSwwKtS.mjs.map +1 -0
  47. package/dist/shared/{rationalCubic2d-H1J2Fjyy.mjs → rationalCubic2d-bveuGqBZ.mjs} +282 -326
  48. package/dist/shared/rationalCubic2d-bveuGqBZ.mjs.map +1 -0
  49. package/dist/shared/{solution-B2JdOZpe.mjs → solution-BW0BBMXI.mjs} +22 -6
  50. package/dist/shared/solution-BW0BBMXI.mjs.map +1 -0
  51. package/dist/shared/{vector2-CSkaMXvp.mjs → vector2-DuA3EmfL.mjs} +5 -3
  52. package/dist/shared/vector2-DuA3EmfL.mjs.map +1 -0
  53. package/dist/shared/{vector2.internal-DP1nTBdS.mjs → vector2.internal-rPnW0RCx.mjs} +10 -5
  54. package/dist/shared/vector2.internal-rPnW0RCx.mjs.map +1 -0
  55. package/dist/shared/{vector3-CR2LPV03.mjs → vector3-oxtggkDp.mjs} +2 -2
  56. package/dist/shared/{vector3-CR2LPV03.mjs.map → vector3-oxtggkDp.mjs.map} +1 -1
  57. package/dist/shared/vector3.internal-CfWHl9SG.mjs +135 -0
  58. package/dist/shared/vector3.internal-CfWHl9SG.mjs.map +1 -0
  59. package/dist/shared/{vector4-PO_7EYd-.mjs → vector4-DGHuCvTV.mjs} +2 -2
  60. package/dist/shared/{vector4-PO_7EYd-.mjs.map → vector4-DGHuCvTV.mjs.map} +1 -1
  61. package/dist/shared/vector4.internal-DH5DzNYO.mjs +116 -0
  62. package/dist/shared/vector4.internal-DH5DzNYO.mjs.map +1 -0
  63. package/dist/solution/index.mjs +1 -1
  64. package/dist/solution/solution.d.ts +16 -0
  65. package/dist/splines/basis2d.d.ts +64 -0
  66. package/dist/splines/bezier2d.d.ts +72 -0
  67. package/dist/splines/cardinal2d.d.ts +78 -0
  68. package/dist/splines/hermite2d.d.ts +76 -0
  69. package/dist/splines/index.mjs +109 -15
  70. package/dist/splines/index.mjs.map +1 -1
  71. package/dist/splines/linear2d.d.ts +65 -0
  72. package/dist/splines/rationalBezier2d.d.ts +76 -0
  73. package/dist/transform/affine2d.d.ts +339 -0
  74. package/dist/transform/affine2d.internal.d.ts +2 -0
  75. package/dist/transform/index.d.ts +3 -0
  76. package/dist/transform/index.mjs +2 -0
  77. package/dist/transform/traits.d.ts +19 -0
  78. package/dist/vector/index.mjs +3 -3
  79. package/dist/vector/vector2.d.ts +49 -0
  80. package/package.json +5 -1
  81. package/dist/shared/characteristic-BkEr-rr8.mjs.map +0 -1
  82. package/dist/shared/cubic-BL6dpuHh.mjs.map +0 -1
  83. package/dist/shared/interval-Dm35Xhy4.mjs.map +0 -1
  84. package/dist/shared/matrix4x4-BWmf4lZM.mjs.map +0 -1
  85. package/dist/shared/monotonicity-BdebFOtv.mjs +0 -34
  86. package/dist/shared/monotonicity-BdebFOtv.mjs.map +0 -1
  87. package/dist/shared/rationalCubic2d-CeHgpNht.mjs.map +0 -1
  88. package/dist/shared/rationalCubic2d-H1J2Fjyy.mjs.map +0 -1
  89. package/dist/shared/solution-B2JdOZpe.mjs.map +0 -1
  90. package/dist/shared/vector2-CSkaMXvp.mjs.map +0 -1
  91. package/dist/shared/vector2.internal-DP1nTBdS.mjs.map +0 -1
  92. package/dist/shared/vector4.internal-BJ1QN2Ck.mjs +0 -246
  93. package/dist/shared/vector4.internal-BJ1QN2Ck.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rationalCubic2d-bveuGqBZ.mjs","names":["Interval.unit","Solution.one","Solution.isNone","Solution.none","Interval2d.union","methods","Path2d.makeMethods","LinearCurve2d.Ops","isLinearPath2d","make","fromArray","append","length","solve","toPathData","isContinuous","asContinuous","isIncreasingX","isDecreasingX","isMonotonicX","isIncreasingY","isDecreasingY","isMonotonicY","asIncreasingX","asDecreasingX","asMonotonicX","asIncreasingY","asDecreasingY","asMonotonicY","solveAtX","solveAtY","boundingBox","transform","make","internal.make","fromArray","internal.fromArray","internal.isLinearPath2d","append","internal.append","length","internal.length","solve","internal.solve","toPathData","internal.toPathData","isContinuous","internal.isContinuous","asContinuous","internal.asContinuous","isIncreasingX","internal.isIncreasingX","isDecreasingX","internal.isDecreasingX","isMonotonicX","internal.isMonotonicX","isIncreasingY","internal.isIncreasingY","isDecreasingY","internal.isDecreasingY","isMonotonicY","internal.isMonotonicY","asIncreasingX","internal.asIncreasingX","asDecreasingX","internal.asDecreasingX","asMonotonicX","internal.asMonotonicX","asIncreasingY","internal.asIncreasingY","asDecreasingY","internal.asDecreasingY","asMonotonicY","internal.asMonotonicY","solveAtX","internal.solveAtX","solveAtY","internal.solveAtY","boundingBox","internal.boundingBox","transform","internal.transform","Path2d.makeMethods","CubicCurve2d.Ops","isCubicPath2d","make","fromArray","append","length","solve","toPathData","isContinuous","asContinuous","isIncreasingX","isDecreasingX","isMonotonicX","isIncreasingY","isDecreasingY","isMonotonicY","asIncreasingX","asDecreasingX","asMonotonicX","asIncreasingY","asDecreasingY","asMonotonicY","solveAtX","solveAtY","boundingBox","transform","CubicCurve2d.length","Interval.unit","derivative","cubicCurveInternal.derivative","Interval.make","Vector2.magnitude","QuadraticCurve2d.solve","solveByDistance","Path2d.Path2dImpl","CubicCurve2d.solve","make","internal.make","fromArray","internal.fromArray","internal.isCubicPath2d","append","internal.append","internal.length","solve","internal.solve","internal.toPathData","internal.isContinuous","internal.asContinuous","internal.isIncreasingX","internal.isDecreasingX","internal.isMonotonicX","internal.isIncreasingY","internal.isDecreasingY","internal.isMonotonicY","internal.asIncreasingX","internal.asDecreasingX","internal.asMonotonicX","internal.asIncreasingY","internal.asDecreasingY","internal.asMonotonicY","internal.solveAtX","internal.solveAtY","internal.solveByDistance","boundingBox","internal.boundingBox","transform","internal.transform","isRationalCubicPath2d","make","fromArray","append","solve","RationalCubicCurve2d.solve","boundingBox","RationalCubicCurve2d.boundingBox","Interval2d.union","approximateAsCubicPath","RationalCubicCurve2d.approximateAsCubicCurves","CubicPath2d.fromArray","transform","RationalCubicCurve2d.transform","internal.isRationalCubicPath2d","internal.make","internal.fromArray","internal.append","internal.solve","internal.boundingBox","internal.approximateAsCubicPath","internal.transform"],"sources":["../../src/path/path2d.ts","../../src/path/linear2d.internal.ts","../../src/path/linear2d.ts","../../src/path/cubic2d.internal.ts","../../src/path/cubic2d.ts","../../src/path/rationalCubic2d.internal.ts","../../src/path/rationalCubic2d.ts"],"sourcesContent":["import type { Curve2dOps } from '../curve/curve2d.ts'\nimport * as Interval from '../interval/interval.ts'\nimport * as Interval2d from '../interval/interval2d.ts'\nimport { coincident } from '../number.ts'\nimport * as Solution from '../solution/solution.ts'\nimport type { Affine2d } from '../transform/affine2d.ts'\nimport { dual, Pipeable } from '../utils.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport {\n PathTraits,\n type Continuous,\n type DecreasingX,\n type DecreasingY,\n type IncreasingX,\n type IncreasingY,\n type MonotonicX,\n type MonotonicY,\n} from './traits.ts'\n\n/**\n * Generic 2D path — a sequence of curves of a single kind `C` plus optional\n * trait brands (`Continuous`, `MonotonicX`, etc.) tracking properties of the\n * path as a whole.\n *\n * Each concrete path kind (`LinearPath2d`, `QuadraticPath2d`, `CubicPath2d`)\n * is a `Path2d<TheirCurveKind, Trait>` plus a per-kind `TypeId` slot for\n * cheap runtime identification. The per-kind modules re-export an operation\n * surface derived from {@link makeMethods} over their curve's\n * {@link Curve2dOps}.\n *\n * @since 2.0.0\n */\nexport interface Path2d<C, Trait = unknown> extends Pipeable, Iterable<C> {\n readonly [PathTraits]: Trait\n}\n\n/**\n * Concrete implementation backing every `Path2d<C>`. The per-kind `TypeId`\n * symbol is stamped onto each instance as a dynamic property at the symbol\n * key it identifies, so the existing per-kind `is{Linear,Quadratic,Cubic}Path2d`\n * typeguards continue to work as `TypeId in p` checks.\n *\n * @internal\n */\nexport class Path2dImpl<C> extends Pipeable implements Path2d<C, unknown> {\n declare readonly [PathTraits]: unknown\n readonly curves: ReadonlyArray<C>\n\n constructor(typeId: symbol, curves: ReadonlyArray<C>) {\n super()\n ;(this as unknown as Record<symbol, symbol>)[typeId] = typeId\n this.curves = curves\n }\n\n [Symbol.iterator](): Iterator<C> {\n return this.curves[Symbol.iterator]()\n }\n}\n\n/**\n * Builds the bundle of generic path operations for a curve kind `C`, given\n * that curve's {@link Curve2dOps} and the per-kind `TypeId` symbol. Each\n * polynomial-degree path module calls this once and re-exports the returned\n * functions with curve-narrowed signatures.\n *\n * `ops` and `typeId` are captured by closure, so the returned operations\n * incur no per-call lookup overhead.\n *\n * @since 2.0.0\n */\nexport const makeMethods = <C>(typeId: symbol, ops: Curve2dOps<C>) => {\n const fromArray = (curves: ReadonlyArray<C>): Path2d<C> => new Path2dImpl(typeId, curves)\n\n const make = (...curves: ReadonlyArray<C>): Path2d<C> => fromArray(curves)\n\n const append = dual<(c: C) => (p: Path2d<C>) => Path2d<C>, (p: Path2d<C>, c: C) => Path2d<C>>(\n 2,\n (p: Path2d<C>, c: C) => fromArray([...p, c]),\n )\n\n const length = (p: Path2d<C>): number => {\n let total = 0\n for (const curve of p) {\n total += ops.length(curve, Interval.unit)\n }\n return total\n }\n\n const solve = dual<\n (u: number) => (p: Path2d<C>) => Vector2,\n (p: Path2d<C>, u: number) => Vector2\n >(2, (p: Path2d<C>, u: number) => {\n const curves = p instanceof Path2dImpl ? (p.curves as ReadonlyArray<C>) : [...p]\n if (u === 1) {\n return ops.solve(curves.at(-1) as C, 1)\n }\n const t = u * curves.length\n const i = Math.floor(t)\n return ops.solve(curves[i] as C, t - i)\n })\n\n const toPathData = (p: Path2d<C>): string => {\n let result = ''\n let prevEndX = Number.NaN\n let prevEndY = Number.NaN\n\n for (const curve of p) {\n const start = ops.startPoint(curve)\n const end = ops.endPoint(curve)\n\n if (!coincident(start.x, prevEndX) || !coincident(start.y, prevEndY)) {\n result += ` M ${start.x},${start.y}`\n }\n result += ` ${ops.toPathDataSegment(curve)}`\n\n prevEndX = end.x\n prevEndY = end.y\n }\n\n return result.slice(1)\n }\n\n const isContinuous = <T>(p: Path2d<C, T>): p is Path2d<C, T & Continuous> => {\n let prevEndX = Number.NaN\n let prevEndY = Number.NaN\n let first = true\n\n for (const curve of p) {\n const start = ops.startPoint(curve)\n if (!first && (!coincident(start.x, prevEndX) || !coincident(start.y, prevEndY))) {\n return false\n }\n const end = ops.endPoint(curve)\n prevEndX = end.x\n prevEndY = end.y\n first = false\n }\n return true\n }\n\n // Per-axis monotonicity for the path: every segment's axis polynomial must\n // be strictly monotonic over the unit interval AND adjacent segments' axis\n // ranges must not overlap — a knot that backtracks within the coincidence\n // band counts as continuous rather than as a reversal.\n const isIncreasingX = <T>(p: Path2d<C, T>): p is Path2d<C, T & IncreasingX> => {\n let prevEnd = Number.NEGATIVE_INFINITY\n for (const c of p) {\n if (!ops.isIncreasingX(c)) {\n return false\n }\n const start = ops.startPoint(c).x\n if (start < prevEnd && !coincident(start, prevEnd)) {\n return false\n }\n prevEnd = ops.endPoint(c).x\n }\n return true\n }\n\n const isDecreasingX = <T>(p: Path2d<C, T>): p is Path2d<C, T & DecreasingX> => {\n let prevEnd = Number.POSITIVE_INFINITY\n for (const c of p) {\n if (!ops.isDecreasingX(c)) {\n return false\n }\n const start = ops.startPoint(c).x\n if (start > prevEnd && !coincident(start, prevEnd)) {\n return false\n }\n prevEnd = ops.endPoint(c).x\n }\n return true\n }\n\n const isMonotonicX = <T>(p: Path2d<C, T>): p is Path2d<C, T & MonotonicX> =>\n isIncreasingX(p) || isDecreasingX(p)\n\n const isIncreasingY = <T>(p: Path2d<C, T>): p is Path2d<C, T & IncreasingY> => {\n let prevEnd = Number.NEGATIVE_INFINITY\n for (const c of p) {\n if (!ops.isIncreasingY(c)) {\n return false\n }\n const start = ops.startPoint(c).y\n if (start < prevEnd && !coincident(start, prevEnd)) {\n return false\n }\n prevEnd = ops.endPoint(c).y\n }\n return true\n }\n\n const isDecreasingY = <T>(p: Path2d<C, T>): p is Path2d<C, T & DecreasingY> => {\n let prevEnd = Number.POSITIVE_INFINITY\n for (const c of p) {\n if (!ops.isDecreasingY(c)) {\n return false\n }\n const start = ops.startPoint(c).y\n if (start > prevEnd && !coincident(start, prevEnd)) {\n return false\n }\n prevEnd = ops.endPoint(c).y\n }\n return true\n }\n\n const isMonotonicY = <T>(p: Path2d<C, T>): p is Path2d<C, T & MonotonicY> =>\n isIncreasingY(p) || isDecreasingY(p)\n\n // solveAtX / solveAtY on a monotonic-axis path. Two defenses against float\n // drift at interior knots, where two adjacent segments both bracket the\n // query and the per-curve inverse may return `none` for both:\n // 1. Snap to t=0/t=1 endpoint y when the query is coincident with a\n // segment's start or end — bypasses polynomial inversion at knots.\n // 2. Fall through to the next bracketing segment on `none`. `MonotonicX`/Y\n // admits at most one real solution across the path, so retrying is safe.\n const solveAtX = dual(2, (p: Path2d<C>, x: number): Solution.AtMostOne<number> => {\n for (const c of p) {\n const start = ops.startPoint(c)\n const end = ops.endPoint(c)\n const lo = Math.min(start.x, end.x)\n const hi = Math.max(start.x, end.x)\n if ((x >= lo && x <= hi) || coincident(x, lo) || coincident(x, hi)) {\n if (coincident(x, start.x)) {\n return Solution.one(start.y)\n }\n if (coincident(x, end.x)) {\n return Solution.one(end.y)\n }\n const sol = ops.solveAtX(c, x)\n if (!Solution.isNone(sol)) {\n return sol\n }\n }\n }\n return Solution.none\n })\n\n const solveAtY = dual(2, (p: Path2d<C>, y: number): Solution.AtMostOne<number> => {\n for (const c of p) {\n const start = ops.startPoint(c)\n const end = ops.endPoint(c)\n const lo = Math.min(start.y, end.y)\n const hi = Math.max(start.y, end.y)\n if ((y >= lo && y <= hi) || coincident(y, lo) || coincident(y, hi)) {\n if (coincident(y, start.y)) {\n return Solution.one(start.x)\n }\n if (coincident(y, end.y)) {\n return Solution.one(end.x)\n }\n const sol = ops.solveAtY(c, y)\n if (!Solution.isNone(sol)) {\n return sol\n }\n }\n }\n return Solution.none\n })\n\n const boundingBox = (p: Path2d<C>): Interval2d.Interval2d<Interval.Closed, Interval.Closed> => {\n const iter = p[Symbol.iterator]()\n const first = iter.next()\n let acc = ops.boundingBox(first.value as C)\n for (let next = iter.next(); !next.done; next = iter.next()) {\n acc = Interval2d.union(acc, ops.boundingBox(next.value))\n }\n return acc\n }\n\n // Per-curve transform: the curve-level op already encodes the right\n // coefficient-vs-position split for its degree, so the path-level call is\n // just a map. Trait brands are dropped — affine maps preserve continuity\n // (since image of a connected set is connected) but can flip monotonicity\n // sense (a reflection inverts increasing → decreasing) so the brands must\n // be reasserted on the result if the caller still wants them.\n const transform = dual<\n (a: Affine2d) => (p: Path2d<C>) => Path2d<C>,\n (p: Path2d<C>, a: Affine2d) => Path2d<C>\n >(2, (p: Path2d<C>, a: Affine2d) => {\n const curves: Array<C> = []\n for (const c of p) {\n curves.push(ops.transform(c, a))\n }\n return fromArray(curves)\n })\n\n return {\n fromArray,\n make,\n append,\n length,\n solve,\n toPathData,\n isContinuous,\n isIncreasingX,\n isDecreasingX,\n isMonotonicX,\n isIncreasingY,\n isDecreasingY,\n isMonotonicY,\n solveAtX,\n solveAtY,\n boundingBox,\n transform,\n }\n}\n","import * as LinearCurve2d from '../curve/linear2d.ts'\nimport type { Closed } from '../interval/interval.ts'\nimport type { Interval2d } from '../interval/interval2d.ts'\nimport { invariant } from '../utils.ts'\nimport type { LinearPath2d } from './linear2d.ts'\nimport * as Path2d from './path2d.ts'\nimport {\n type Continuous,\n type DecreasingX,\n type DecreasingY,\n type IncreasingX,\n type IncreasingY,\n type MonotonicX,\n type MonotonicY,\n} from './traits.ts'\n\nexport const LinearPath2dTypeId: unique symbol = Symbol('curvy/path/linear2d')\nexport type LinearPath2dTypeId = typeof LinearPath2dTypeId\n\n// Generic operation surface, built once for LinearCurve2d's Ops.\nconst methods = Path2d.makeMethods(LinearPath2dTypeId, LinearCurve2d.Ops)\n\n/** @internal */\nexport const isLinearPath2d = (p: unknown): p is LinearPath2d =>\n typeof p === 'object' && p !== null && LinearPath2dTypeId in p\n\n/** @internal */\nexport const make = methods.make as (\n ...curves: ReadonlyArray<LinearCurve2d.LinearCurve2d>\n) => LinearPath2d\n\n/** @internal */\nexport const fromArray = methods.fromArray as (\n curves: ReadonlyArray<LinearCurve2d.LinearCurve2d>,\n) => LinearPath2d\n\n/** @internal */\nexport const append = methods.append as never\n\n/** @internal */\nexport const length = methods.length as (p: LinearPath2d) => number\n\n/** @internal */\nexport const solve = methods.solve as never\n\n/** @internal */\nexport const toPathData = methods.toPathData as (p: LinearPath2d) => string\n\n/** @internal */\nexport const isContinuous = methods.isContinuous as unknown as <T>(\n p: LinearPath2d<T>,\n) => p is LinearPath2d<T & Continuous>\n\n/** @internal */\nexport const asContinuous = <T>(p: LinearPath2d<T>): LinearPath2d<T & Continuous> => {\n invariant(isContinuous(p), 'linear path is not continuous')\n return p\n}\n\n/** @internal */\nexport const isIncreasingX = methods.isIncreasingX as unknown as <T>(\n p: LinearPath2d<T>,\n) => p is LinearPath2d<T & IncreasingX>\n\n/** @internal */\nexport const isDecreasingX = methods.isDecreasingX as unknown as <T>(\n p: LinearPath2d<T>,\n) => p is LinearPath2d<T & DecreasingX>\n\n/** @internal */\nexport const isMonotonicX = methods.isMonotonicX as unknown as <T>(\n p: LinearPath2d<T>,\n) => p is LinearPath2d<T & MonotonicX>\n\n/** @internal */\nexport const isIncreasingY = methods.isIncreasingY as unknown as <T>(\n p: LinearPath2d<T>,\n) => p is LinearPath2d<T & IncreasingY>\n\n/** @internal */\nexport const isDecreasingY = methods.isDecreasingY as unknown as <T>(\n p: LinearPath2d<T>,\n) => p is LinearPath2d<T & DecreasingY>\n\n/** @internal */\nexport const isMonotonicY = methods.isMonotonicY as unknown as <T>(\n p: LinearPath2d<T>,\n) => p is LinearPath2d<T & MonotonicY>\n\n/** @internal */\nexport const asIncreasingX = <T>(p: LinearPath2d<T>): LinearPath2d<T & IncreasingX> => {\n invariant(isIncreasingX(p), 'linear path is not increasing in x')\n return p\n}\n\n/** @internal */\nexport const asDecreasingX = <T>(p: LinearPath2d<T>): LinearPath2d<T & DecreasingX> => {\n invariant(isDecreasingX(p), 'linear path is not decreasing in x')\n return p\n}\n\n/** @internal */\nexport const asMonotonicX = <T>(p: LinearPath2d<T>): LinearPath2d<T & MonotonicX> => {\n invariant(isMonotonicX(p), 'linear path is not monotonic in x')\n return p\n}\n\n/** @internal */\nexport const asIncreasingY = <T>(p: LinearPath2d<T>): LinearPath2d<T & IncreasingY> => {\n invariant(isIncreasingY(p), 'linear path is not increasing in y')\n return p\n}\n\n/** @internal */\nexport const asDecreasingY = <T>(p: LinearPath2d<T>): LinearPath2d<T & DecreasingY> => {\n invariant(isDecreasingY(p), 'linear path is not decreasing in y')\n return p\n}\n\n/** @internal */\nexport const asMonotonicY = <T>(p: LinearPath2d<T>): LinearPath2d<T & MonotonicY> => {\n invariant(isMonotonicY(p), 'linear path is not monotonic in y')\n return p\n}\n\n/** @internal */\nexport const solveAtX = methods.solveAtX as never\n\n/** @internal */\nexport const solveAtY = methods.solveAtY as never\n\n/** @internal */\nexport const boundingBox = methods.boundingBox as (p: LinearPath2d) => Interval2d<Closed, Closed>\n\n/** @internal */\nexport const transform = methods.transform as never\n","import type { Interval2d } from '../interval/interval2d.ts'\nimport type { LinearCurve2d } from '../curve/linear2d.ts'\nimport type { Closed } from '../interval/interval.ts'\nimport type * as Solution from '../solution/solution.ts'\nimport type { Affine2d } from '../transform/affine2d.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport type { LinearPath2dTypeId } from './linear2d.internal.ts'\nimport * as internal from './linear2d.internal.ts'\nimport type {\n Continuous,\n DecreasingX,\n DecreasingY,\n IncreasingX,\n IncreasingY,\n MonotonicX,\n MonotonicY,\n PathTraits,\n} from './traits.ts'\n\nexport type {\n Continuous,\n DecreasingX,\n DecreasingY,\n IncreasingX,\n IncreasingY,\n MonotonicX,\n MonotonicY,\n} from './traits.ts'\n\n/**\n * A linear path in 2D space.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * The `Trait` type parameter accumulates trait brands as the path is refined\n * via `isContinuous` / `asContinuous`. A `Continuous` path's `toPathData`\n * skips the per-segment discontinuity check.\n *\n * @since 1.0.0\n */\nexport interface LinearPath2d<out Trait = unknown> extends Pipeable, Iterable<LinearCurve2d> {\n readonly [LinearPath2dTypeId]: LinearPath2dTypeId\n readonly [PathTraits]: Trait\n}\n\n/**\n * Creates a new `LinearPath2d` instance from a sequence of curves.\n *\n * @param curves - The curves to create the path from.\n * @returns A new `LinearPath2d` instance.\n * @since 2.0.0\n */\nexport const make: (...curves: ReadonlyArray<LinearCurve2d>) => LinearPath2d = internal.make\n\n/**\n * Creates a new `LinearPath2d` instance from an array of curves.\n *\n * @param curves - The curves to create the path from.\n * @returns A new `LinearPath2d` instance.\n * @since 2.0.0\n */\nexport const fromArray: (curves: ReadonlyArray<LinearCurve2d>) => LinearPath2d = internal.fromArray\n\n/**\n * Checks if a value is a `LinearPath2d`.\n *\n * @param p - The value to check.\n * @returns `true` if the value is a `LinearPath2d`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isLinearPath2d: (p: unknown) => p is LinearPath2d = internal.isLinearPath2d\n\nexport const append: {\n /**\n * Appends a linear curve to a linear path.\n *\n * @param c - The linear curve to append.\n * @returns A function that takes a linear path and returns a new linear path.\n * @since 1.0.0\n */\n (c: LinearCurve2d): (p: LinearPath2d) => LinearPath2d\n /**\n * Appends a linear curve to a linear path.\n *\n * @param p - The linear path to append to.\n * @param c - The linear curve to append.\n * @returns A new `LinearPath2d` instance with the appended curve.\n * @since 1.0.0\n */\n (p: LinearPath2d, c: LinearCurve2d): LinearPath2d\n} = internal.append\n\n/**\n * Calculates the length of a linear path.\n *\n * @param p - The linear path to calculate the length of.\n * @returns The length of the linear path.\n * @since 1.0.0\n */\nexport const length: (p: LinearPath2d) => number = internal.length\n\nexport const solve: {\n /**\n * Solves a linear path for a given parameter.\n *\n * @param u - The parameter to solve for.\n * @returns A function that takes a linear path and returns the solved point.\n * @since 1.0.0\n */\n (u: number): (p: LinearPath2d) => Vector2\n /**\n * Solves a linear path for a given parameter.\n *\n * @param p - The linear path to solve.\n * @param u - The parameter to solve for.\n * @returns The solved point on the linear path.\n * @since 1.0.0\n */\n (p: LinearPath2d, u: number): Vector2\n} = internal.solve\n\n/**\n * Serializes a linear path as an SVG path data string (the value of a `<path>`\n * element's `d` attribute), using `M` and `L` commands. Discontinuities between\n * curves emit a fresh `M` command.\n *\n * @param p - The linear path to serialize.\n * @returns The SVG path data string.\n * @since 2.0.0\n */\nexport const toPathData: (p: LinearPath2d) => string = internal.toPathData\n\n/**\n * Type-narrowing predicate: refines `LinearPath2d<T>` to\n * `LinearPath2d<T & Continuous>` when adjacent curves connect at their join\n * points.\n *\n * @param p - The linear path to check.\n * @returns `true` when the path is continuous (G⁰).\n * @since 2.0.0\n */\nexport const isContinuous: <T>(p: LinearPath2d<T>) => p is LinearPath2d<T & Continuous> =\n internal.isContinuous\n\n/**\n * Asserts that the linear path is continuous, throwing on failure.\n *\n * @param p - The linear path to assert against.\n * @returns The same path, typed with the `Continuous` brand.\n * @throws When the path has a discontinuity between adjacent curves.\n * @since 2.0.0\n */\nexport const asContinuous: <T>(p: LinearPath2d<T>) => LinearPath2d<T & Continuous> =\n internal.asContinuous\n\n/**\n * Type-narrowing predicate: refines `LinearPath2d<T>` to\n * `LinearPath2d<T & IncreasingX>` when every segment's x-polynomial is\n * strictly increasing and adjacent segments' x-ranges don't overlap.\n *\n * @since 2.0.0\n */\nexport const isIncreasingX: <T>(p: LinearPath2d<T>) => p is LinearPath2d<T & IncreasingX> =\n internal.isIncreasingX\n\n/**\n * Type-narrowing predicate: refines `LinearPath2d<T>` to\n * `LinearPath2d<T & DecreasingX>` when every segment's x-polynomial is\n * strictly decreasing and adjacent segments' x-ranges don't overlap.\n *\n * @since 2.0.0\n */\nexport const isDecreasingX: <T>(p: LinearPath2d<T>) => p is LinearPath2d<T & DecreasingX> =\n internal.isDecreasingX\n\n/**\n * Type-narrowing predicate: refines `LinearPath2d<T>` to\n * `LinearPath2d<T & MonotonicX>` when the path is either increasing or\n * decreasing in x along its full parameter domain.\n *\n * @since 2.0.0\n */\nexport const isMonotonicX: <T>(p: LinearPath2d<T>) => p is LinearPath2d<T & MonotonicX> =\n internal.isMonotonicX\n\n/**\n * Type-narrowing predicate: refines `LinearPath2d<T>` to\n * `LinearPath2d<T & IncreasingY>`. The y-axis analog of {@link isIncreasingX}.\n *\n * @since 2.0.0\n */\nexport const isIncreasingY: <T>(p: LinearPath2d<T>) => p is LinearPath2d<T & IncreasingY> =\n internal.isIncreasingY\n\n/**\n * Type-narrowing predicate: refines `LinearPath2d<T>` to\n * `LinearPath2d<T & DecreasingY>`. The y-axis analog of {@link isDecreasingX}.\n *\n * @since 2.0.0\n */\nexport const isDecreasingY: <T>(p: LinearPath2d<T>) => p is LinearPath2d<T & DecreasingY> =\n internal.isDecreasingY\n\n/**\n * Type-narrowing predicate: refines `LinearPath2d<T>` to\n * `LinearPath2d<T & MonotonicY>`. The y-axis analog of {@link isMonotonicX}.\n *\n * @since 2.0.0\n */\nexport const isMonotonicY: <T>(p: LinearPath2d<T>) => p is LinearPath2d<T & MonotonicY> =\n internal.isMonotonicY\n\n/**\n * Asserts that the path is strictly increasing in x, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asIncreasingX: <T>(p: LinearPath2d<T>) => LinearPath2d<T & IncreasingX> =\n internal.asIncreasingX\n\n/**\n * Asserts that the path is strictly decreasing in x, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asDecreasingX: <T>(p: LinearPath2d<T>) => LinearPath2d<T & DecreasingX> =\n internal.asDecreasingX\n\n/**\n * Asserts that the path is monotonic in x, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asMonotonicX: <T>(p: LinearPath2d<T>) => LinearPath2d<T & MonotonicX> =\n internal.asMonotonicX\n\n/**\n * Asserts that the path is strictly increasing in y, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asIncreasingY: <T>(p: LinearPath2d<T>) => LinearPath2d<T & IncreasingY> =\n internal.asIncreasingY\n\n/**\n * Asserts that the path is strictly decreasing in y, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asDecreasingY: <T>(p: LinearPath2d<T>) => LinearPath2d<T & DecreasingY> =\n internal.asDecreasingY\n\n/**\n * Asserts that the path is monotonic in y, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asMonotonicY: <T>(p: LinearPath2d<T>) => LinearPath2d<T & MonotonicY> =\n internal.asMonotonicY\n\nexport const solveAtX: {\n /**\n * Evaluates the path's y value at a given x. Requires the path to carry the\n * `MonotonicX` brand — without it, an x query could match multiple\n * segments and the return cardinality would be unbounded.\n *\n * Returns `Solution.none` when x falls outside the path's x-range.\n *\n * @param p - A path branded `MonotonicX`.\n * @param x - The x coordinate.\n * @returns The y value at x, or `none` when x is outside the path's range.\n * @since 2.0.0\n */\n <T extends MonotonicX>(p: LinearPath2d<T>, x: number): Solution.AtMostOne<number>\n /** @since 2.0.0 */\n (x: number): <T extends MonotonicX>(p: LinearPath2d<T>) => Solution.AtMostOne<number>\n} = internal.solveAtX as never\n\nexport const solveAtY: {\n /**\n * Evaluates the path's x value at a given y. Requires the path to carry the\n * `MonotonicY` brand. Returns `Solution.none` when y is outside the path's\n * y-range.\n *\n * @param p - A path branded `MonotonicY`.\n * @param y - The y coordinate.\n * @returns The x value at y, or `none` when y is outside the path's range.\n * @since 2.0.0\n */\n <T extends MonotonicY>(p: LinearPath2d<T>, y: number): Solution.AtMostOne<number>\n /** @since 2.0.0 */\n (y: number): <T extends MonotonicY>(p: LinearPath2d<T>) => Solution.AtMostOne<number>\n} = internal.solveAtY as never\n\n/**\n * Computes the axis-aligned bounding box of the path — the smallest closed\n * `Box2d` enclosing every segment.\n *\n * @param p - The linear path.\n * @returns A closed `Box2d` enclosing the path.\n * @since 2.0.0\n */\nexport const boundingBox: (p: LinearPath2d) => Interval2d<Closed, Closed> = internal.boundingBox\n\nexport const transform: {\n /**\n * Applies an `Affine2d` transform to every curve in a `LinearPath2d`,\n * returning a new path whose image is the affine image of the original.\n * Trait brands are dropped — affine maps can flip the sense of monotonicity\n * (a reflection turns `IncreasingX` into `DecreasingX`), so any brands the\n * caller still wants must be reasserted on the result.\n *\n * @param p - The linear path.\n * @param a - The affine transform.\n * @returns A new unbranded `LinearPath2d` whose curves are the affine images of the input's.\n * @since 2.0.0\n */\n (p: LinearPath2d, a: Affine2d): LinearPath2d\n /**\n * Applies an `Affine2d` transform to every curve in a `LinearPath2d`.\n *\n * @param a - The affine transform.\n * @returns A function that takes a `LinearPath2d` and returns the transformed path.\n * @since 2.0.0\n */\n (a: Affine2d): (p: LinearPath2d) => LinearPath2d\n} = internal.transform\n","import * as CubicCurve2d from '../curve/cubic2d.ts'\nimport * as cubicCurveInternal from '../curve/cubic2d.internal.ts'\nimport * as QuadraticCurve2d from '../curve/quadratic2d.ts'\nimport * as Interval from '../interval/interval.ts'\nimport type { Closed } from '../interval/interval.ts'\nimport type { Interval2d } from '../interval/interval2d.ts'\nimport { RELATIVE_TOLERANCE } from '../number.ts'\nimport { dual, invariant } from '../utils.ts'\nimport * as Vector2 from '../vector/vector2.ts'\nimport type { CubicPath2d } from './cubic2d.ts'\nimport * as Path2d from './path2d.ts'\nimport {\n type Continuous,\n type DecreasingX,\n type DecreasingY,\n type IncreasingX,\n type IncreasingY,\n type MonotonicX,\n type MonotonicY,\n} from './traits.ts'\n\nexport const CubicPath2dTypeId: unique symbol = Symbol('curvy/path/cubic2d')\nexport type CubicPath2dTypeId = typeof CubicPath2dTypeId\n\n// Generic operation surface, built once for CubicCurve2d's Ops.\nconst methods = Path2d.makeMethods(CubicPath2dTypeId, CubicCurve2d.Ops)\n\n/** @internal */\nexport const isCubicPath2d = (p: unknown): p is CubicPath2d =>\n typeof p === 'object' && p !== null && CubicPath2dTypeId in p\n\n// The cubic path enforces a non-empty curve list. Wrap the generic factories\n// to check the invariant; the generic builders accept empty arrays as a\n// matter of structural minimality, but the cubic-specific contract is stricter.\n/** @internal */\nexport const make = (...curves: ReadonlyArray<CubicCurve2d.CubicCurve2d>): CubicPath2d => {\n invariant(curves.length > 0, 'cubic path requires at least one curve')\n return methods.make(...curves) as CubicPath2d\n}\n\n/** @internal */\nexport const fromArray = (curves: ReadonlyArray<CubicCurve2d.CubicCurve2d>): CubicPath2d => {\n invariant(curves.length > 0, 'cubic path requires at least one curve')\n return methods.fromArray(curves) as CubicPath2d\n}\n\n/** @internal */\nexport const append = methods.append as never\n\n/** @internal */\nexport const length = methods.length as (p: CubicPath2d) => number\n\n/** @internal */\nexport const solve = methods.solve as never\n\n/** @internal */\nexport const toPathData = methods.toPathData as (p: CubicPath2d) => string\n\n/** @internal */\nexport const isContinuous = methods.isContinuous as unknown as <T>(\n p: CubicPath2d<T>,\n) => p is CubicPath2d<T & Continuous>\n\n/** @internal */\nexport const asContinuous = <T>(p: CubicPath2d<T>): CubicPath2d<T & Continuous> => {\n invariant(isContinuous(p), 'cubic path is not continuous')\n return p\n}\n\n/** @internal */\nexport const isIncreasingX = methods.isIncreasingX as unknown as <T>(\n p: CubicPath2d<T>,\n) => p is CubicPath2d<T & IncreasingX>\n\n/** @internal */\nexport const isDecreasingX = methods.isDecreasingX as unknown as <T>(\n p: CubicPath2d<T>,\n) => p is CubicPath2d<T & DecreasingX>\n\n/** @internal */\nexport const isMonotonicX = methods.isMonotonicX as unknown as <T>(\n p: CubicPath2d<T>,\n) => p is CubicPath2d<T & MonotonicX>\n\n/** @internal */\nexport const isIncreasingY = methods.isIncreasingY as unknown as <T>(\n p: CubicPath2d<T>,\n) => p is CubicPath2d<T & IncreasingY>\n\n/** @internal */\nexport const isDecreasingY = methods.isDecreasingY as unknown as <T>(\n p: CubicPath2d<T>,\n) => p is CubicPath2d<T & DecreasingY>\n\n/** @internal */\nexport const isMonotonicY = methods.isMonotonicY as unknown as <T>(\n p: CubicPath2d<T>,\n) => p is CubicPath2d<T & MonotonicY>\n\n/** @internal */\nexport const asIncreasingX = <T>(p: CubicPath2d<T>): CubicPath2d<T & IncreasingX> => {\n invariant(isIncreasingX(p), 'cubic path is not increasing in x')\n return p\n}\n\n/** @internal */\nexport const asDecreasingX = <T>(p: CubicPath2d<T>): CubicPath2d<T & DecreasingX> => {\n invariant(isDecreasingX(p), 'cubic path is not decreasing in x')\n return p\n}\n\n/** @internal */\nexport const asMonotonicX = <T>(p: CubicPath2d<T>): CubicPath2d<T & MonotonicX> => {\n invariant(isMonotonicX(p), 'cubic path is not monotonic in x')\n return p\n}\n\n/** @internal */\nexport const asIncreasingY = <T>(p: CubicPath2d<T>): CubicPath2d<T & IncreasingY> => {\n invariant(isIncreasingY(p), 'cubic path is not increasing in y')\n return p\n}\n\n/** @internal */\nexport const asDecreasingY = <T>(p: CubicPath2d<T>): CubicPath2d<T & DecreasingY> => {\n invariant(isDecreasingY(p), 'cubic path is not decreasing in y')\n return p\n}\n\n/** @internal */\nexport const asMonotonicY = <T>(p: CubicPath2d<T>): CubicPath2d<T & MonotonicY> => {\n invariant(isMonotonicY(p), 'cubic path is not monotonic in y')\n return p\n}\n\n/** @internal */\nexport const solveAtX = methods.solveAtX as never\n\n/** @internal */\nexport const solveAtY = methods.solveAtY as never\n\n/** @internal */\nexport const boundingBox = methods.boundingBox as (p: CubicPath2d) => Interval2d<Closed, Closed>\n\n/** @internal */\nexport const transform = methods.transform as never\n\n// Cubic-specific arc-length sampling. Cached by path identity since paths are\n// immutable. Lives here rather than in the generic Path2d because the inner\n// Newton iteration uses the cubic-curve derivative directly.\n\n// Cumulative segment lengths cache. lengths[k] = total length through segment k.\nconst cumulativeLengthCache = new WeakMap<CubicPath2d, ReadonlyArray<number>>()\n\nconst getCumulativeLengths = (p: CubicPath2d): ReadonlyArray<number> => {\n let cached = cumulativeLengthCache.get(p)\n if (cached === undefined) {\n const lengths: Array<number> = []\n let total = 0\n for (const curve of p) {\n total += CubicCurve2d.length(curve, Interval.unit)\n lengths.push(total)\n }\n cached = lengths\n cumulativeLengthCache.set(p, cached)\n }\n return cached\n}\n\n// Newton's method to find the local parameter t ∈ [0, 1] within `curve` such\n// that the arc length from 0 to t equals `target`. Each iteration costs one\n// GL32 quadrature plus one velocity eval; converges in 3–5 iterations for\n// well-behaved curves. Falls back to bisection on cusps where speed → 0.\nconst solveCurveByDistance = (\n curve: CubicCurve2d.CubicCurve2d,\n target: number,\n segmentLength: number,\n): number => {\n if (target <= 0) {\n return 0\n }\n if (target >= segmentLength) {\n return 1\n }\n\n const derivative = cubicCurveInternal.derivative(curve)\n\n let t = target / segmentLength\n let lo = 0\n let hi = 1\n\n for (let iter = 0; iter < 16; iter++) {\n const currentLength = CubicCurve2d.length(curve, Interval.make(0, t))\n const error = currentLength - target\n\n // Converged when the remaining arc-length error reaches the noise floor\n // relative to the segment. An absolute criterion demands unreachable\n // precision on long segments (burning every iteration) and stops a step\n // early on short ones.\n if (Math.abs(error) <= RELATIVE_TOLERANCE * segmentLength) {\n return t\n }\n\n if (error > 0) {\n hi = t\n } else {\n lo = t\n }\n\n const speed = Vector2.magnitude(QuadraticCurve2d.solve(derivative, t))\n if (speed === 0) {\n // cusp — bisect instead\n t = (lo + hi) / 2\n continue\n }\n\n const next = t - error / speed\n // bracket-clamp Newton step; if it leaves the bracket, fall back to bisection\n t = next > lo && next < hi ? next : (lo + hi) / 2\n }\n\n return t\n}\n\n/** @internal */\nexport const solveByDistance = dual<\n (s: number) => (p: CubicPath2d) => Vector2.Vector2,\n (p: CubicPath2d, s: number) => Vector2.Vector2\n>(2, (p: CubicPath2d, s: number) => {\n if (s <= 0) {\n return methods.solve(p, 0)\n }\n if (s >= 1) {\n return methods.solve(p, 1)\n }\n\n const lengths = getCumulativeLengths(p)\n const total = lengths[lengths.length - 1] as number\n const target = s * total\n\n // find segment k such that lengths[k-1] ≤ target ≤ lengths[k]\n let k = 0\n while (k < lengths.length - 1 && (lengths[k] as number) < target) {\n k++\n }\n\n const segmentStart = k === 0 ? 0 : (lengths[k - 1] as number)\n const segmentEnd = lengths[k] as number\n const segmentLength = segmentEnd - segmentStart\n const segmentTarget = target - segmentStart\n\n const curves =\n p instanceof Path2d.Path2dImpl ? (p.curves as ReadonlyArray<CubicCurve2d.CubicCurve2d>) : [...p]\n const curve = curves[k] as CubicCurve2d.CubicCurve2d\n const localT = solveCurveByDistance(curve, segmentTarget, segmentLength)\n\n return CubicCurve2d.solve(curve, localT)\n})\n","import type { Interval2d } from '../interval/interval2d.ts'\nimport type { CubicCurve2d } from '../curve/cubic2d.ts'\nimport type { Closed } from '../interval/interval.ts'\nimport type * as Solution from '../solution/solution.ts'\nimport type { Affine2d } from '../transform/affine2d.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport type { CubicPath2dTypeId } from './cubic2d.internal.ts'\nimport * as internal from './cubic2d.internal.ts'\nimport type {\n Continuous,\n DecreasingX,\n DecreasingY,\n IncreasingX,\n IncreasingY,\n MonotonicX,\n MonotonicY,\n PathTraits,\n} from './traits.ts'\n\nexport type {\n Continuous,\n DecreasingX,\n DecreasingY,\n IncreasingX,\n IncreasingY,\n MonotonicX,\n MonotonicY,\n} from './traits.ts'\n\n/**\n * A cubic path in 2D space.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * The `Trait` type parameter accumulates trait brands as the path is refined\n * via `isContinuous` / `asContinuous`.\n *\n * @since 1.0.0\n */\nexport interface CubicPath2d<out Trait = unknown> extends Pipeable, Iterable<CubicCurve2d> {\n readonly [CubicPath2dTypeId]: CubicPath2dTypeId\n readonly [PathTraits]: Trait\n}\n\n/**\n * Creates a new `CubicPath2d` instance from a sequence of curves.\n *\n * @param curves - The curves to create the path from.\n * @returns A new `CubicPath2d` instance.\n * @since 2.0.0\n */\nexport const make: (...curves: ReadonlyArray<CubicCurve2d>) => CubicPath2d = internal.make\n\n/**\n * Creates a new `CubicPath2d` instance from an array of curves.\n *\n * @param curves - The curves to create the path from.\n * @returns A new `CubicPath2d` instance.\n * @since 2.0.0\n */\nexport const fromArray: (curves: ReadonlyArray<CubicCurve2d>) => CubicPath2d = internal.fromArray\n\n/**\n * Checks if a value is a `CubicPath2d`.\n *\n * @param p - The value to check.\n * @returns `true` if the value is a `CubicPath2d`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isCubicPath2d: (p: unknown) => p is CubicPath2d = internal.isCubicPath2d\n\nexport const append: {\n /**\n * Appends a cubic curve to a cubic path.\n *\n * @param c - The cubic curve to append.\n * @returns A function that takes a cubic path and returns a new cubic path.\n * @since 1.0.0\n */\n (c: CubicCurve2d): (p: CubicPath2d) => CubicPath2d\n /**\n * Appends a cubic curve to a cubic path.\n *\n * @param p - The cubic path to append to.\n * @param c - The cubic curve to append.\n * @returns A new cubic path.\n * @since 1.0.0\n */\n (p: CubicPath2d, c: CubicCurve2d): CubicPath2d\n} = internal.append\n\n/**\n * Calculates the length of a cubic path.\n *\n * @param p - The cubic path to calculate the length of.\n * @returns The length of the cubic path.\n * @since 1.0.0\n */\nexport const length: (p: CubicPath2d) => number = internal.length\n\nexport const solve: {\n /**\n * Solves a cubic path for a given parameter.\n *\n * @param u - The parameter to solve for.\n * @returns A function that takes a cubic path and returns the solved vector.\n * @since 1.0.0\n */\n (u: number): (p: CubicPath2d) => Vector2\n /**\n * Solves a cubic path for a given parameter.\n *\n * @param p - The cubic path to solve.\n * @param u - The parameter to solve for.\n * @returns The solved vector.\n * @since 1.0.0\n */\n (p: CubicPath2d, u: number): Vector2\n} = internal.solve\n\n/**\n * Serializes a cubic path as an SVG path data string (the value of a `<path>`\n * element's `d` attribute), using `M` and `C` commands. Discontinuities between\n * curves emit a fresh `M` command.\n *\n * @param p - The cubic path to serialize.\n * @returns The SVG path data string.\n * @since 2.0.0\n */\nexport const toPathData: (p: CubicPath2d) => string = internal.toPathData\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & Continuous>` when adjacent curves connect.\n *\n * @since 2.0.0\n */\nexport const isContinuous: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & Continuous> =\n internal.isContinuous\n\n/**\n * Asserts that the cubic path is continuous, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asContinuous: <T>(p: CubicPath2d<T>) => CubicPath2d<T & Continuous> =\n internal.asContinuous\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & IncreasingX>` when every segment's x-polynomial is\n * strictly increasing on `[0, 1]` and adjacent segments' x-ranges don't\n * overlap.\n *\n * @since 2.0.0\n */\nexport const isIncreasingX: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & IncreasingX> =\n internal.isIncreasingX\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & DecreasingX>`.\n *\n * @since 2.0.0\n */\nexport const isDecreasingX: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & DecreasingX> =\n internal.isDecreasingX\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & MonotonicX>`.\n *\n * @since 2.0.0\n */\nexport const isMonotonicX: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & MonotonicX> =\n internal.isMonotonicX\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & IncreasingY>`.\n *\n * @since 2.0.0\n */\nexport const isIncreasingY: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & IncreasingY> =\n internal.isIncreasingY\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & DecreasingY>`.\n *\n * @since 2.0.0\n */\nexport const isDecreasingY: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & DecreasingY> =\n internal.isDecreasingY\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & MonotonicY>`.\n *\n * @since 2.0.0\n */\nexport const isMonotonicY: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & MonotonicY> =\n internal.isMonotonicY\n\n/**\n * Asserts that the path is strictly increasing in x, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asIncreasingX: <T>(p: CubicPath2d<T>) => CubicPath2d<T & IncreasingX> =\n internal.asIncreasingX\n\n/**\n * Asserts that the path is strictly decreasing in x, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asDecreasingX: <T>(p: CubicPath2d<T>) => CubicPath2d<T & DecreasingX> =\n internal.asDecreasingX\n\n/**\n * Asserts that the path is monotonic in x, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asMonotonicX: <T>(p: CubicPath2d<T>) => CubicPath2d<T & MonotonicX> =\n internal.asMonotonicX\n\n/**\n * Asserts that the path is strictly increasing in y, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asIncreasingY: <T>(p: CubicPath2d<T>) => CubicPath2d<T & IncreasingY> =\n internal.asIncreasingY\n\n/**\n * Asserts that the path is strictly decreasing in y, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asDecreasingY: <T>(p: CubicPath2d<T>) => CubicPath2d<T & DecreasingY> =\n internal.asDecreasingY\n\n/**\n * Asserts that the path is monotonic in y, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asMonotonicY: <T>(p: CubicPath2d<T>) => CubicPath2d<T & MonotonicY> =\n internal.asMonotonicY\n\nexport const solveAtX: {\n /**\n * Evaluates the path's y value at a given x. Requires the path to carry\n * the `MonotonicX` brand. Returns `Solution.none` when x is outside the\n * path's x-range.\n *\n * @param p - A path branded `MonotonicX`.\n * @param x - The x coordinate.\n * @returns The y value at x, or `none` when x is outside the path's range.\n * @since 2.0.0\n */\n <T extends MonotonicX>(p: CubicPath2d<T>, x: number): Solution.AtMostOne<number>\n /** @since 2.0.0 */\n (x: number): <T extends MonotonicX>(p: CubicPath2d<T>) => Solution.AtMostOne<number>\n} = internal.solveAtX as never\n\nexport const solveAtY: {\n /**\n * Evaluates the path's x value at a given y. Requires the path to carry\n * the `MonotonicY` brand. Returns `Solution.none` when y is outside the\n * path's y-range.\n *\n * @param p - A path branded `MonotonicY`.\n * @param y - The y coordinate.\n * @returns The x value at y, or `none` when y is outside the path's range.\n * @since 2.0.0\n */\n <T extends MonotonicY>(p: CubicPath2d<T>, y: number): Solution.AtMostOne<number>\n /** @since 2.0.0 */\n (y: number): <T extends MonotonicY>(p: CubicPath2d<T>) => Solution.AtMostOne<number>\n} = internal.solveAtY as never\n\nexport const solveByDistance: {\n /**\n * Solves a cubic path by normalized arc length. Unlike {@link solve}, which\n * is parameterized by curve `u`, this samples points at constant speed along\n * the path — `s = 0.5` returns the point exactly halfway along the curve by\n * arc length, regardless of how the underlying parameterization stretches.\n *\n * Cumulative segment lengths are cached by path identity so repeated calls\n * with the same path are fast.\n *\n * @param p - The cubic path to sample.\n * @param s - Normalized arc length in `[0, 1]`. Values outside the range are\n * clamped to path endpoints.\n * @returns The point on the path at the given normalized arc length.\n * @since 1.1.0\n */\n (p: CubicPath2d, s: number): Vector2\n /**\n * Solves a cubic path by normalized arc length.\n *\n * @param s - Normalized arc length in `[0, 1]`.\n * @returns A function that takes a cubic path and returns the point at that\n * arc length.\n * @since 1.1.0\n */\n (s: number): (p: CubicPath2d) => Vector2\n} = internal.solveByDistance\n\n/**\n * Computes the axis-aligned bounding box of the path — the smallest closed\n * `Box2d` enclosing every segment.\n *\n * @param p - The cubic path.\n * @returns A closed `Box2d` enclosing the path.\n * @since 2.0.0\n */\nexport const boundingBox: (p: CubicPath2d) => Interval2d<Closed, Closed> = internal.boundingBox\n\nexport const transform: {\n /**\n * Applies an `Affine2d` transform to every curve in a `CubicPath2d`,\n * returning a new path whose image is the affine image of the original.\n * Trait brands are dropped.\n *\n * @param p - The cubic path.\n * @param a - The affine transform.\n * @returns A new unbranded `CubicPath2d` whose curves are the affine images of the input's.\n * @since 2.0.0\n */\n (p: CubicPath2d, a: Affine2d): CubicPath2d\n /**\n * Applies an `Affine2d` transform to every curve in a `CubicPath2d`.\n *\n * @param a - The affine transform.\n * @returns A function that takes a `CubicPath2d` and returns the transformed path.\n * @since 2.0.0\n */\n (a: Affine2d): (p: CubicPath2d) => CubicPath2d\n} = internal.transform\n","import type * as CubicCurve2d from '../curve/cubic2d.ts'\nimport * as RationalCubicCurve2d from '../curve/rationalCubic2d.ts'\nimport type * as Interval from '../interval/interval.ts'\nimport * as Interval2d from '../interval/interval2d.ts'\nimport type * as Affine2d from '../transform/affine2d.ts'\nimport { dual, Pipeable } from '../utils.ts'\nimport { invariant } from '../utils.ts'\nimport type * as Vector2 from '../vector/vector2.ts'\nimport * as CubicPath2d from './cubic2d.ts'\nimport type { RationalCubicPath2d } from './rationalCubic2d.ts'\n\nexport const RationalCubicPath2dTypeId: unique symbol = Symbol('curvy/path/rationalCubic2d')\nexport type RationalCubicPath2dTypeId = typeof RationalCubicPath2dTypeId\n\n/** @internal */\nexport class RationalCubicPath2dImpl extends Pipeable implements RationalCubicPath2d {\n readonly [RationalCubicPath2dTypeId]: RationalCubicPath2dTypeId = RationalCubicPath2dTypeId\n\n readonly curves: ReadonlyArray<RationalCubicCurve2d.RationalCubicCurve2d>\n\n constructor(curves: ReadonlyArray<RationalCubicCurve2d.RationalCubicCurve2d>) {\n invariant(curves.length > 0, 'rational cubic path requires at least one curve')\n super()\n this.curves = curves\n }\n\n [Symbol.iterator](): Iterator<RationalCubicCurve2d.RationalCubicCurve2d> {\n return this.curves[Symbol.iterator]()\n }\n}\n\n/** @internal */\nexport const isRationalCubicPath2d = (p: unknown): p is RationalCubicPath2d =>\n typeof p === 'object' && p !== null && RationalCubicPath2dTypeId in p\n\n/** @internal */\nexport const make = (\n ...curves: ReadonlyArray<RationalCubicCurve2d.RationalCubicCurve2d>\n): RationalCubicPath2d => new RationalCubicPath2dImpl(curves)\n\n/** @internal */\nexport const fromArray = (\n curves: ReadonlyArray<RationalCubicCurve2d.RationalCubicCurve2d>,\n): RationalCubicPath2d => new RationalCubicPath2dImpl(curves)\n\n/** @internal */\nexport const append = dual<\n (c: RationalCubicCurve2d.RationalCubicCurve2d) => (p: RationalCubicPath2d) => RationalCubicPath2d,\n (p: RationalCubicPath2d, c: RationalCubicCurve2d.RationalCubicCurve2d) => RationalCubicPath2d\n>(2, (p, c) => fromArray([...p, c]))\n\n/** @internal */\nexport const solve = dual<\n (u: number) => (p: RationalCubicPath2d) => Vector2.Vector2,\n (p: RationalCubicPath2d, u: number) => Vector2.Vector2\n>(2, (p: RationalCubicPath2d, u: number) => {\n const curves = p instanceof RationalCubicPath2dImpl ? p.curves : [...p]\n\n if (u === 1) {\n const last = curves.at(-1) as RationalCubicCurve2d.RationalCubicCurve2d\n return RationalCubicCurve2d.solve(last, 1)\n }\n\n const t = u * curves.length\n const i = Math.floor(t)\n const curve = curves[i] as RationalCubicCurve2d.RationalCubicCurve2d\n return RationalCubicCurve2d.solve(curve, t - i)\n})\n\n// Path-level bounding box: per-segment box is delegated to the curve module\n// (subdivision + hull union, tight to within `tolerance` per side); the path\n// box is then their union. Since each segment box's slack is ≤ tolerance per\n// side, the unioned box's slack is also ≤ tolerance per side — the same\n// guarantee holds at the path level.\n/** @internal */\nexport const boundingBox = dual<\n (\n tolerance: number,\n ) => (p: RationalCubicPath2d) => Interval2d.Interval2d<Interval.Closed, Interval.Closed>,\n (\n p: RationalCubicPath2d,\n tolerance: number,\n ) => Interval2d.Interval2d<Interval.Closed, Interval.Closed>\n>(2, (p: RationalCubicPath2d, tolerance: number) => {\n const iter = p[Symbol.iterator]()\n const first = iter.next()\n let acc = RationalCubicCurve2d.boundingBox(\n first.value as RationalCubicCurve2d.RationalCubicCurve2d,\n tolerance,\n )\n for (let next = iter.next(); !next.done; next = iter.next()) {\n acc = Interval2d.union(acc, RationalCubicCurve2d.boundingBox(next.value, tolerance))\n }\n return acc\n})\n\n// Path-level approximation: per-segment approximation is delegated to the\n// curve module; we just concat the results. Segment count grows from N\n// (input) to roughly N × k where k depends on weight magnitude and tolerance —\n// uniform-weight segments stay 1:1.\n/** @internal */\nexport const approximateAsCubicPath = dual<\n (tolerance: number) => (p: RationalCubicPath2d) => CubicPath2d.CubicPath2d,\n (p: RationalCubicPath2d, tolerance: number) => CubicPath2d.CubicPath2d\n>(2, (p: RationalCubicPath2d, tolerance: number) => {\n const curves: Array<CubicCurve2d.CubicCurve2d> = []\n for (const segment of p) {\n for (const approx of RationalCubicCurve2d.approximateAsCubicCurves(segment, tolerance)) {\n curves.push(approx)\n }\n }\n return CubicPath2d.fromArray(curves)\n})\n\n/** @internal */\nexport const transform = dual<\n (a: Affine2d.Affine2d) => (p: RationalCubicPath2d) => RationalCubicPath2d,\n (p: RationalCubicPath2d, a: Affine2d.Affine2d) => RationalCubicPath2d\n>(2, (p: RationalCubicPath2d, a: Affine2d.Affine2d) => {\n const curves: Array<RationalCubicCurve2d.RationalCubicCurve2d> = []\n for (const segment of p) {\n curves.push(RationalCubicCurve2d.transform(segment, a))\n }\n return fromArray(curves)\n})\n","import type { RationalCubicCurve2d } from '../curve/rationalCubic2d.ts'\nimport type { Closed } from '../interval/interval.ts'\nimport type { Interval2d } from '../interval/interval2d.ts'\nimport type { Affine2d } from '../transform/affine2d.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport type { CubicPath2d } from './cubic2d.ts'\nimport type { RationalCubicPath2dTypeId } from './rationalCubic2d.internal.ts'\nimport * as internal from './rationalCubic2d.internal.ts'\n\n/**\n * A rational cubic path in 2D space.\n *\n * Holds a non-empty sequence of `RationalCubicCurve2d` segments; iteration\n * yields the segments in order. The path parameter `u ∈ [0, 1]` is mapped\n * uniformly across segments — `u = 0` is the start of the first segment,\n * `u = 1` is the end of the last segment, and intermediate values pick a\n * segment by index and a local parameter within it.\n *\n * Counterpart to `CubicPath2d` for curves whose evaluation includes the\n * homogeneous-to-plane projection.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 2.0.0\n */\nexport interface RationalCubicPath2d extends Pipeable, Iterable<RationalCubicCurve2d> {\n readonly [RationalCubicPath2dTypeId]: RationalCubicPath2dTypeId\n}\n\n/**\n * Checks if a value is a `RationalCubicPath2d`.\n *\n * @param p - The value to check.\n * @returns `true` if the value is a `RationalCubicPath2d`, `false` otherwise.\n * @since 2.0.0\n */\nexport const isRationalCubicPath2d: (p: unknown) => p is RationalCubicPath2d =\n internal.isRationalCubicPath2d\n\n/**\n * Creates a new `RationalCubicPath2d` from a sequence of curves.\n *\n * @param curves - The curves to create the path from.\n * @returns A new `RationalCubicPath2d` instance.\n * @since 2.0.0\n */\nexport const make: (...curves: ReadonlyArray<RationalCubicCurve2d>) => RationalCubicPath2d =\n internal.make\n\n/**\n * Creates a new `RationalCubicPath2d` from an array of curves.\n *\n * @param curves - The curves to create the path from.\n * @returns A new `RationalCubicPath2d` instance.\n * @since 2.0.0\n */\nexport const fromArray: (curves: ReadonlyArray<RationalCubicCurve2d>) => RationalCubicPath2d =\n internal.fromArray\n\nexport const append: {\n /**\n * Appends a curve to a `RationalCubicPath2d`.\n *\n * @param c - The curve to append.\n * @returns A function that takes a path and returns a new path with the appended curve.\n * @since 2.0.0\n */\n (c: RationalCubicCurve2d): (p: RationalCubicPath2d) => RationalCubicPath2d\n /**\n * Appends a curve to a `RationalCubicPath2d`.\n *\n * @param p - The path to append to.\n * @param c - The curve to append.\n * @returns A new path with the appended curve.\n * @since 2.0.0\n */\n (p: RationalCubicPath2d, c: RationalCubicCurve2d): RationalCubicPath2d\n} = internal.append\n\nexport const solve: {\n /**\n * Evaluates the rational cubic path at parameter `u ∈ [0, 1]`.\n *\n * Picks the segment containing `u` (uniform mapping across segments) and\n * delegates to `RationalCubicCurve2d.solve` on that segment with the local\n * parameter.\n *\n * @param p - The path to evaluate.\n * @param u - The path parameter in `[0, 1]`.\n * @returns The point on the path at parameter `u`.\n * @since 2.0.0\n */\n (p: RationalCubicPath2d, u: number): Vector2\n /**\n * Evaluates the rational cubic path at parameter `u ∈ [0, 1]`.\n *\n * @param u - The path parameter in `[0, 1]`.\n * @returns A function that takes a path and returns the point at `u`.\n * @since 2.0.0\n */\n (u: number): (p: RationalCubicPath2d) => Vector2\n} = internal.solve\n\nexport const boundingBox: {\n /**\n * Computes a closed axis-aligned bounding box for a rational cubic path,\n * tight to within `tolerance` per side.\n *\n * Per-segment delegates to `RationalCubicCurve2d.boundingBox(c, tolerance)`\n * — recursive subdivision producing a hull-AABB union tight to within\n * `tolerance` per side. The path box is the union of segment boxes; since\n * each segment box has slack ≤ tolerance per side, so does the union.\n *\n * @param p - The rational cubic path.\n * @param tolerance - Maximum allowed slack per side; must be positive.\n * @returns A closed `Interval2d` enclosing the path, tight to within `tolerance`.\n * @since 2.0.0\n */\n (p: RationalCubicPath2d, tolerance: number): Interval2d<Closed, Closed>\n /**\n * Computes a closed axis-aligned bounding box for a rational cubic path.\n *\n * @param tolerance - Maximum allowed slack per side; must be positive.\n * @returns A function that takes a path and returns its bounding box.\n * @since 2.0.0\n */\n (tolerance: number): (p: RationalCubicPath2d) => Interval2d<Closed, Closed>\n} = internal.boundingBox\n\nexport const approximateAsCubicPath: {\n /**\n * Approximates the rational cubic path as a `CubicPath2d` via per-segment\n * recursive subdivision. Each input segment is split until its midpoint\n * deviates from a polynomial-cubic candidate by at most `tolerance`; the\n * surviving candidates are concatenated into a new path.\n *\n * Lossy in general — only exact when every input segment has uniform\n * weights, in which case segment count is preserved. Tighter tolerance\n * produces more segments.\n *\n * @param p - The rational cubic path to approximate.\n * @param tolerance - Maximum allowed midpoint deviation per segment; must be positive.\n * @returns A new `CubicPath2d` approximating the input.\n * @since 2.0.0\n */\n (p: RationalCubicPath2d, tolerance: number): CubicPath2d\n /**\n * Approximates the rational cubic path as a `CubicPath2d`.\n *\n * @param tolerance - Maximum allowed midpoint deviation per segment; must be positive.\n * @returns A function that takes a rational path and returns its approximation.\n * @since 2.0.0\n */\n (tolerance: number): (p: RationalCubicPath2d) => CubicPath2d\n} = internal.approximateAsCubicPath\n\nexport const transform: {\n /**\n * Applies an `Affine2d` transform to every curve in a `RationalCubicPath2d`,\n * returning a new path whose image is the affine image of the original.\n *\n * @param p - The rational cubic path.\n * @param a - The affine transform.\n * @returns A new `RationalCubicPath2d` whose curves are the affine images of the input's.\n * @since 2.0.0\n */\n (p: RationalCubicPath2d, a: Affine2d): RationalCubicPath2d\n /**\n * Applies an `Affine2d` transform to every curve in a `RationalCubicPath2d`.\n *\n * @param a - The affine transform.\n * @returns A function that takes a `RationalCubicPath2d` and returns the transformed path.\n * @since 2.0.0\n */\n (a: Affine2d): (p: RationalCubicPath2d) => RationalCubicPath2d\n} = internal.transform\n"],"mappings":";;;;;;;;;;;;;;;;;AA4CA,IAAa,aAAb,cAAmC,SAAuC;CAExE;CAEA,YAAY,QAAgB,QAA0B;EACpD,OAAO;EACN,KAA4C,UAAU;EACvD,KAAK,SAAS;;CAGhB,CAAC,OAAO,YAAyB;EAC/B,OAAO,KAAK,OAAO,OAAO,WAAW;;;;;;;;;;;;;;AAezC,MAAa,eAAkB,QAAgB,QAAuB;CACpE,MAAM,aAAa,WAAwC,IAAI,WAAW,QAAQ,OAAO;CAEzF,MAAM,QAAQ,GAAG,WAAwC,UAAU,OAAO;CAE1E,MAAM,SAAS,KACb,I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M,UAAUC,yBAA8C,SAAS,UAAU,EACpF,OAAO,KAAK,OAAO;CAGvB,OAAOC,YAAsB,OAAO;EACpC;;AAGF,MAAaC,cAAY,KAGvB,IAAI,GAAwB,MAAyB;CACrD,MAAM,SAA2D,EAAE;CACnE,KAAK,MAAM,WAAW,GACpB,OAAO,KAAKC,YAA+B,SAAS,EAAE,CAAC;CAEzD,OAAOX,YAAU,OAAO;EACxB;;;;;;;;;;;;;;;;;;;;ACvFF,MAAa,wBACXY;;;;;;;;AASF,MAAa,OACXC;;;;;;;;AASF,MAAa,YACXC;AAEF,MAAa,SAkBTC;AAEJ,MAAa,QAsBTC;AAEJ,MAAa,cAwBTC;AAEJ,MAAa,yBAyBTC;AAEJ,MAAa,YAmBTC"}
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./chunk-25Hzd3z8.mjs";
2
2
  import { Pipeable, dual, invariant } from "../utils.mjs";
3
- import { n as contains } from "./interval-Dm35Xhy4.mjs";
3
+ import { n as contains, r as containsApprox } from "./interval-Dcqpo73t.mjs";
4
4
  //#region src/solution/solution.internal.ts
5
5
  const EMPTY_ITERATOR = { next: () => ({
6
6
  done: true,
@@ -14,9 +14,9 @@ var NoneImpl = class extends Pipeable {
14
14
  }
15
15
  };
16
16
  var OneImpl = class extends Pipeable {
17
- value;
18
17
  _tag = "one";
19
18
  length = 1;
19
+ value;
20
20
  constructor(value) {
21
21
  super();
22
22
  this.value = value;
@@ -26,9 +26,9 @@ var OneImpl = class extends Pipeable {
26
26
  }
27
27
  };
28
28
  var TwoImpl = class extends Pipeable {
29
- values;
30
29
  _tag = "two";
31
30
  length = 2;
31
+ values;
32
32
  constructor(values) {
33
33
  super();
34
34
  this.values = values;
@@ -41,9 +41,9 @@ var TwoImpl = class extends Pipeable {
41
41
  }
42
42
  };
43
43
  var ThreeImpl = class extends Pipeable {
44
- values;
45
44
  _tag = "three";
46
45
  length = 3;
46
+ values;
47
47
  constructor(values) {
48
48
  super();
49
49
  this.values = values;
@@ -157,6 +157,8 @@ const filter$1 = (s, predicate) => {
157
157
  /** @internal */
158
158
  const clip$1 = dual(2, (s, i) => filter$1(s, (v) => contains(i, v)));
159
159
  /** @internal */
160
+ const clipApprox$1 = dual(2, (s, i) => filter$1(s, (v) => containsApprox(i, v)));
161
+ /** @internal */
160
162
  const map$1 = dual(2, (s, f) => {
161
163
  switch (s._tag) {
162
164
  case "none": return s;
@@ -171,6 +173,7 @@ const match$1 = dual(2, (self, matcher) => isNone$1(self) ? matcher.onNone() : m
171
173
  //#region src/solution/solution.ts
172
174
  var solution_exports = /* @__PURE__ */ __exportAll({
173
175
  clip: () => clip,
176
+ clipApprox: () => clipApprox,
174
177
  filter: () => filter,
175
178
  fromArray: () => fromArray,
176
179
  isNone: () => isNone,
@@ -320,6 +323,19 @@ const filter = filter$1;
320
323
  */
321
324
  const clip = clip$1;
322
325
  /**
326
+ * Approximate-containment variant of {@link clip} for post-processing the
327
+ * output of a numerical solver. Retains values within a small absolute
328
+ * tolerance of either boundary even if formally outside — a valid root can
329
+ * land a few ULPs past the boundary due to coefficient roundoff in the
330
+ * solver, and strict {@link clip} would drop it. Endpoint inclusivity is
331
+ * ignored at the EPSILON scale.
332
+ *
333
+ * @param s - The solution to clip.
334
+ * @param i - The interval to retain values approximately within.
335
+ * @since 2.0.0
336
+ */
337
+ const clipApprox = clipApprox$1;
338
+ /**
323
339
  * Maps every value in the solution to a new value. Result cardinality matches
324
340
  * the input.
325
341
  *
@@ -347,6 +363,6 @@ const map = map$1;
347
363
  */
348
364
  const match = match$1;
349
365
  //#endregion
350
- export { match as a, solution_exports as c, map as i, two as l, fromArray as n, none as o, isNone as r, one as s, clip as t };
366
+ export { map as a, one as c, isNone as i, solution_exports as l, clipApprox as n, match as o, fromArray as r, none as s, clip as t, two as u };
351
367
 
352
- //# sourceMappingURL=solution-B2JdOZpe.mjs.map
368
+ //# sourceMappingURL=solution-BW0BBMXI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solution-BW0BBMXI.mjs","names":["none","one","two","three","fromArray","isNone","isSome","valueOrUndefined","last","min","max","unsafeValue","unsafeLast","unsafeMin","unsafeMax","filter","clip","Interval.contains","clipApprox","Interval.containsApprox","map","match","internal.none","internal.one","internal.two","internal.three","internal.fromArray","internal.isNone","internal.isSome","internal.valueOrUndefined","internal.last","internal.min","internal.max","internal.unsafeValue","internal.unsafeLast","internal.unsafeMin","internal.unsafeMax","internal.filter","internal.clip","internal.clipApprox","internal.map","internal.match"],"sources":["../../src/solution/solution.internal.ts","../../src/solution/solution.ts"],"sourcesContent":["import * as Interval from '../interval/interval.ts'\nimport { dual, Pipeable } from '../utils.ts'\nimport type {\n AtMostOne,\n AtMostThree,\n AtMostTwo,\n None,\n One,\n Solution,\n Some,\n Three,\n Two,\n} from './solution.ts'\nimport { invariant } from '../utils.ts'\n\n// Empty iterator — shared across all None instances since None has no data.\nconst EMPTY_ITERATOR: Iterator<never> = {\n next: () => ({ done: true, value: undefined as never }),\n}\n\nclass NoneImpl extends Pipeable implements None {\n readonly _tag = 'none' as const\n readonly length = 0 as const;\n\n [Symbol.iterator](): Iterator<never> {\n return EMPTY_ITERATOR\n }\n}\n\nclass OneImpl<T> extends Pipeable implements One<T> {\n readonly _tag = 'one' as const\n readonly length = 1 as const\n readonly value: T\n\n constructor(value: T) {\n super()\n this.value = value\n }\n\n [Symbol.iterator](): Iterator<T> {\n return [this.value][Symbol.iterator]()\n }\n}\n\nclass TwoImpl<T> extends Pipeable implements Two<T> {\n readonly _tag = 'two' as const\n readonly length = 2 as const\n readonly values: readonly [T, T]\n\n constructor(values: readonly [T, T]) {\n super()\n this.values = values\n }\n\n get value(): T {\n return this.values[0]\n }\n\n [Symbol.iterator](): Iterator<T> {\n return this.values[Symbol.iterator]()\n }\n}\n\nclass ThreeImpl<T> extends Pipeable implements Three<T> {\n readonly _tag = 'three' as const\n readonly length = 3 as const\n readonly values: readonly [T, T, T]\n\n constructor(values: readonly [T, T, T]) {\n super()\n this.values = values\n }\n\n get value(): T {\n return this.values[0]\n }\n\n [Symbol.iterator](): Iterator<T> {\n return this.values[Symbol.iterator]()\n }\n}\n\n/** @internal */\nexport const NONE_INSTANCE: None = new NoneImpl()\n\n/** @internal */\nexport const none: None = NONE_INSTANCE\n\n/** @internal */\nexport const one = <T>(value: T): One<T> => new OneImpl(value)\n\n/** @internal */\nexport const two = <T>(a: T, b: T): Two<T> => new TwoImpl([a, b])\n\n/** @internal */\nexport const three = <T>(a: T, b: T, c: T): Three<T> => new ThreeImpl([a, b, c])\n\n/** @internal */\nexport const fromArray = <T>(arr: ReadonlyArray<T>): Solution<T> => {\n switch (arr.length) {\n case 0:\n return NONE_INSTANCE\n case 1:\n return one(arr[0] as T)\n case 2:\n return two(arr[0] as T, arr[1] as T)\n case 3:\n return three(arr[0] as T, arr[1] as T, arr[2] as T)\n default:\n invariant(false, `Solution can hold at most 3 values, got ${arr.length}`)\n }\n}\n\n/** @internal */\nexport const isNone = <T>(s: Solution<T>): s is None => s._tag === 'none'\n\n/** @internal */\nexport const isSome = <T>(s: Solution<T>): s is Some<T> => s._tag !== 'none'\n\n/** @internal */\nexport const valueOrUndefined = <T>(s: Solution<T>): T | undefined =>\n isNone(s) ? undefined : s.value\n\n/** @internal */\nexport const last: {\n <T>(s: Some<T>): T\n <T>(s: Solution<T>): T | undefined\n} = (<T>(s: Solution<T>): T | undefined => {\n switch (s._tag) {\n case 'none':\n return undefined\n case 'one':\n return s.value\n case 'two':\n return s.values[1]\n case 'three':\n return s.values[2]\n }\n}) as never\n\n/** @internal */\nexport const min: {\n (s: Some<number>): number\n (s: Solution<number>): number | undefined\n} = ((s: Solution<number>): number | undefined => {\n switch (s._tag) {\n case 'none':\n return undefined\n case 'one':\n return s.value\n case 'two':\n return Math.min(s.values[0], s.values[1])\n case 'three':\n return Math.min(s.values[0], s.values[1], s.values[2])\n }\n}) as never\n\n/** @internal */\nexport const max: {\n (s: Some<number>): number\n (s: Solution<number>): number | undefined\n} = ((s: Solution<number>): number | undefined => {\n switch (s._tag) {\n case 'none':\n return undefined\n case 'one':\n return s.value\n case 'two':\n return Math.max(s.values[0], s.values[1])\n case 'three':\n return Math.max(s.values[0], s.values[1], s.values[2])\n }\n}) as never\n\n/** @internal */\nexport const unsafeValue = <T>(s: Solution<T>, message?: string): T => {\n invariant(isSome(s), message ?? 'Solution.unsafeValue on empty Solution')\n return s.value\n}\n\n/** @internal */\nexport const unsafeLast = <T>(s: Solution<T>): T => {\n invariant(isSome(s), 'Solution.unsafeLast on empty Solution')\n return last(s)\n}\n\n/** @internal */\nexport const unsafeMin = (s: Solution<number>): number => {\n invariant(isSome(s), 'Solution.unsafeMin on empty Solution')\n return min(s)\n}\n\n/** @internal */\nexport const unsafeMax = (s: Solution<number>): number => {\n invariant(isSome(s), 'Solution.unsafeMax on empty Solution')\n return max(s)\n}\n\n/** @internal */\nexport const filter = <T>(s: Solution<T>, predicate: (v: T) => boolean): Solution<T> => {\n switch (s._tag) {\n case 'none':\n return s\n case 'one':\n return predicate(s.value) ? s : NONE_INSTANCE\n case 'two': {\n const a = predicate(s.values[0])\n const b = predicate(s.values[1])\n if (a && b) {\n return s\n }\n if (a) {\n return one(s.values[0])\n }\n if (b) {\n return one(s.values[1])\n }\n return NONE_INSTANCE\n }\n case 'three': {\n const survivors: Array<T> = []\n if (predicate(s.values[0])) {\n survivors.push(s.values[0])\n }\n if (predicate(s.values[1])) {\n survivors.push(s.values[1])\n }\n if (predicate(s.values[2])) {\n survivors.push(s.values[2])\n }\n return fromArray(survivors)\n }\n }\n}\n\n/** @internal */\nexport const clip = dual(\n 2,\n (s: Solution<number>, i: Interval.Interval): Solution<number> =>\n filter(s, (v) => Interval.contains(i, v)),\n)\n\n// Approximate-containment variant for post-processing numerical solver\n// output. A valid root from `Polynomial.roots` (etc.) can land a few ULPs\n// past a boundary due to coefficient roundoff in the solver; strict `clip`\n// drops it, this one keeps it. Endpoint inclusivity is ignored — at the\n// EPSILON scale the open/closed distinction loses meaning, mirroring\n// `Interval.containsApprox` semantics.\n/** @internal */\nexport const clipApprox = dual(\n 2,\n (s: Solution<number>, i: Interval.Interval): Solution<number> =>\n filter(s, (v) => Interval.containsApprox(i, v)),\n)\n\n/** @internal */\nexport const map = dual(2, <A, B>(s: Solution<A>, f: (v: A) => B): Solution<B> => {\n switch (s._tag) {\n case 'none':\n return s\n case 'one':\n return one(f(s.value))\n case 'two':\n return two(f(s.values[0]), f(s.values[1]))\n case 'three':\n return three(f(s.values[0]), f(s.values[1]), f(s.values[2]))\n }\n})\n\n/** @internal */\nexport const match = dual(\n 2,\n <T, A, B>(\n self: Solution<T>,\n matcher: { readonly onNone: () => A; readonly onSome: (s: Some<T>) => B },\n ): A | B => (isNone(self) ? matcher.onNone() : matcher.onSome(self)),\n)\n\n// Re-export type aliases that the namespace consumers expect to see at runtime.\n// (Pure type re-exports — no runtime cost.)\nexport type { AtMostOne, AtMostThree, AtMostTwo, None, One, Solution, Some, Three, Two }\n","import type { Interval } from '../interval/interval.ts'\nimport type { Pipeable } from '../utils.ts'\nimport * as internal from './solution.internal.ts'\n\n/**\n * A `Solution<T>` represents the result of an operation that may produce\n * between zero and three values of `T`. It generalizes the zoo of \"0 or 1\",\n * \"0 to 2\", \"0 to 3\" return shapes used throughout curvy under one type, and\n * provides a small namespace of operations (`value`, `last`, `min`, `max`,\n * `filter`, `map`, `match`, …) for working with the result.\n *\n * Each variant carries a `_tag` discriminator and a `length` field, is\n * iterable via `Symbol.iterator` (so existing `for..of` and spread patterns\n * keep working), and is `Pipeable` (so a `Solution` value can be the head of\n * a `pipe` chain).\n *\n * Variant-specific accessors:\n * - `One<T>`, `Two<T>`, and `Three<T>` all expose `.value: T` (the first /\n * primary value).\n * - `Two<T>` and `Three<T>` additionally expose `.values: readonly [T, ...]`\n * for explicit positional access.\n *\n * Operations that return narrower cardinalities (e.g. inverse-solving a\n * monotonic polynomial) use the `AtMost{One,Two,Three}` aliases to express\n * \"this could be empty, but it'll have at most N values.\"\n *\n * @since 2.0.0\n */\nexport type Solution<T> = None | One<T> | Two<T> | Three<T>\n\n/**\n * The empty solution.\n *\n * @since 2.0.0\n */\nexport interface None extends Pipeable, Iterable<never> {\n readonly _tag: 'none'\n readonly length: 0\n}\n\n/** @since 2.0.0 */\nexport interface One<T> extends Pipeable, Iterable<T> {\n readonly _tag: 'one'\n readonly length: 1\n readonly value: T\n}\n\n/** @since 2.0.0 */\nexport interface Two<T> extends Pipeable, Iterable<T> {\n readonly _tag: 'two'\n readonly length: 2\n readonly value: T\n readonly values: readonly [T, T]\n}\n\n/** @since 2.0.0 */\nexport interface Three<T> extends Pipeable, Iterable<T> {\n readonly _tag: 'three'\n readonly length: 3\n readonly value: T\n readonly values: readonly [T, T, T]\n}\n\n/**\n * Any non-empty solution. All `Some<T>` values expose `.value: T` directly —\n * no narrowing required to read the primary value.\n *\n * @since 2.0.0\n */\nexport type Some<T> = One<T> | Two<T> | Three<T>\n\n/**\n * `None | One<T>` — return type of operations that produce at most one value\n * (e.g. inverse-solving a strictly monotonic polynomial).\n *\n * @since 2.0.0\n */\nexport type AtMostOne<T> = None | One<T>\n\n/**\n * `None | One<T> | Two<T>` — return type of operations that produce at most\n * two values (e.g. inverse-solving an unrestricted quadratic polynomial).\n *\n * @since 2.0.0\n */\nexport type AtMostTwo<T> = None | One<T> | Two<T>\n\n/**\n * `None | One<T> | Two<T> | Three<T>` — equivalent to `Solution<T>`.\n *\n * @since 2.0.0\n */\nexport type AtMostThree<T> = Solution<T>\n\n/**\n * The empty solution. Reused across calls — never reallocated.\n *\n * @since 2.0.0\n */\nexport const none: None = internal.none\n\n/**\n * Constructs a single-value solution.\n *\n * @since 2.0.0\n */\nexport const one: <T>(value: T) => One<T> = internal.one\n\n/**\n * Constructs a two-value solution.\n *\n * @since 2.0.0\n */\nexport const two: <T>(a: T, b: T) => Two<T> = internal.two\n\n/**\n * Constructs a three-value solution.\n *\n * @since 2.0.0\n */\nexport const three: <T>(a: T, b: T, c: T) => Three<T> = internal.three\n\n/**\n * Constructs a `Solution<T>` from a runtime array. Throws if the array has\n * more than three elements.\n *\n * @since 2.0.0\n */\nexport const fromArray: <T>(arr: ReadonlyArray<T>) => Solution<T> = internal.fromArray\n\n/**\n * Type-narrowing predicate: refines `Solution<T>` to `None`.\n *\n * @since 2.0.0\n */\nexport const isNone: <T>(s: Solution<T>) => s is None = internal.isNone\n\n/**\n * Type-narrowing predicate: refines `Solution<T>` to `Some<T>` (non-empty).\n * After narrowing, `.value` is directly accessible without further checks.\n *\n * @since 2.0.0\n */\nexport const isSome: <T>(s: Solution<T>) => s is Some<T> = internal.isSome\n\n/**\n * Returns the primary (first) value if the solution is non-empty, or\n * `undefined` if empty. Pair with `.value` access on `Some<T>`-narrowed\n * inputs to avoid the `undefined` possibility.\n *\n * @since 2.0.0\n */\nexport const valueOrUndefined: <T>(s: Solution<T>) => T | undefined = internal.valueOrUndefined\n\n/**\n * Returns the last value in the solution, or `undefined` if empty. When\n * called on a `Some<T>`, the result is guaranteed to be `T`.\n *\n * @since 2.0.0\n */\nexport const last: {\n <T>(s: Some<T>): T\n <T>(s: Solution<T>): T | undefined\n} = internal.last\n\n/**\n * Returns the smallest numeric value in the solution, or `undefined` if empty.\n * When called on a `Some<number>`, the result is guaranteed to be `number`.\n *\n * @since 2.0.0\n */\nexport const min: {\n (s: Some<number>): number\n (s: Solution<number>): number | undefined\n} = internal.min\n\n/**\n * Returns the largest numeric value in the solution, or `undefined` if empty.\n * When called on a `Some<number>`, the result is guaranteed to be `number`.\n *\n * @since 2.0.0\n */\nexport const max: {\n (s: Some<number>): number\n (s: Solution<number>): number | undefined\n} = internal.max\n\n/**\n * Returns the primary value of the solution (i.e. `s.value`). Throws on\n * `None`, optionally with a caller-provided message.\n *\n * Useful when the type system can't prove non-emptiness but you have a domain\n * reason to assert it — e.g. inverting a polynomial you know to be monotonic\n * without going through the trait refiner first:\n *\n * ```ts\n * const x = CubicPolynomial.solveInverse(p, y).pipe(\n * Solution.unsafeValue('expected a monotonic inverse'),\n * )\n * ```\n *\n * @since 2.0.0\n */\nexport const unsafeValue: {\n <T>(s: Solution<T>, message?: string): T\n (message: string): <T>(s: Solution<T>) => T\n} = ((...args: ReadonlyArray<unknown>) => {\n if (args.length >= 1 && typeof args[0] === 'object' && args[0] !== null) {\n return internal.unsafeValue(args[0] as Solution<unknown>, args[1] as string | undefined)\n }\n const message = args[0] as string\n return <T>(s: Solution<T>) => internal.unsafeValue(s, message)\n}) as never\n\n/**\n * Returns the last value in the solution. Throws if empty.\n *\n * @since 2.0.0\n */\nexport const unsafeLast: <T>(s: Solution<T>) => T = internal.unsafeLast\n\n/**\n * Returns the smallest numeric value in the solution. Throws on empty.\n *\n * @since 2.0.0\n */\nexport const unsafeMin: (s: Solution<number>) => number = internal.unsafeMin\n\n/**\n * Returns the largest numeric value in the solution. Throws on empty.\n *\n * @since 2.0.0\n */\nexport const unsafeMax: (s: Solution<number>) => number = internal.unsafeMax\n\n/**\n * Filters the solution by a predicate. Result cardinality is at most that of\n * the input.\n *\n * @since 2.0.0\n */\nexport const filter: <T>(s: Solution<T>, predicate: (v: T) => boolean) => Solution<T> =\n internal.filter\n\n/**\n * Restricts the solution to values contained within an interval. Endpoint\n * inclusivity follows the interval's `kind` — pass an open variant (e.g.\n * `Interval.makeOpen(0, 1)` or `Interval.unitOpen`) for strict containment.\n *\n * @param s - The solution to clip.\n * @param i - The interval to retain values within.\n * @since 2.0.0\n */\nexport const clip: {\n (i: Interval): (s: Solution<number>) => Solution<number>\n (s: Solution<number>, i: Interval): Solution<number>\n} = internal.clip\n\n/**\n * Approximate-containment variant of {@link clip} for post-processing the\n * output of a numerical solver. Retains values within a small absolute\n * tolerance of either boundary even if formally outside — a valid root can\n * land a few ULPs past the boundary due to coefficient roundoff in the\n * solver, and strict {@link clip} would drop it. Endpoint inclusivity is\n * ignored at the EPSILON scale.\n *\n * @param s - The solution to clip.\n * @param i - The interval to retain values approximately within.\n * @since 2.0.0\n */\nexport const clipApprox: {\n (i: Interval): (s: Solution<number>) => Solution<number>\n (s: Solution<number>, i: Interval): Solution<number>\n} = internal.clipApprox\n\n/**\n * Maps every value in the solution to a new value. Result cardinality matches\n * the input.\n *\n * @since 2.0.0\n */\nexport const map: {\n <A, B>(s: Solution<A>, f: (v: A) => B): Solution<B>\n <A, B>(f: (v: A) => B): (s: Solution<A>) => Solution<B>\n} = internal.map\n\n// Drops `None` from the union of the input solution type — used by `match` to\n// give `onSome` a tighter parameter type. Distributive: a `Solution.AtMostOne<T>`\n// becomes `One<T>`; a full `Solution<T>` keeps `Some<T>`.\ntype SomeOf<S> = S extends None ? never : S\n\n/**\n * Pattern matches on a solution, calling `onNone` for the empty case and\n * `onSome` for any non-empty case. The `onSome` parameter is typed against\n * the input's narrowed shape — for an `AtMostOne<T>` input, `onSome` receives\n * `One<T>` and can read `.value` directly.\n *\n * @example\n * ```ts\n * const result = polynomial.pipe(\n * LinearPolynomial.solveInverse(0),\n * Solution.match({\n * onNone: () => null,\n * onSome: ({ value }) => Math.abs(value),\n * }),\n * )\n * ```\n *\n * @since 2.0.0\n */\nexport const match: {\n <S extends Solution<unknown>, A, B>(\n self: S,\n matcher: { readonly onNone: () => A; readonly onSome: (s: SomeOf<S>) => B },\n ): A | B\n <S extends Solution<unknown>, A, B>(matcher: {\n readonly onNone: () => A\n readonly onSome: (s: SomeOf<S>) => B\n }): (self: S) => A | B\n} = internal.match as never\n"],"mappings":";;;;AAgBA,MAAM,iBAAkC,EACtC,aAAa;CAAE,MAAM;CAAM,OAAO,KAAA;CAAoB,GACvD;AAED,IAAM,WAAN,cAAuB,SAAyB;CAC9C,OAAgB;CAChB,SAAkB;CAElB,CAAC,OAAO,YAA6B;EACnC,OAAO;;;AAIX,IAAM,UAAN,cAAyB,SAA2B;CAClD,OAAgB;CAChB,SAAkB;CAClB;CAEA,YAAY,OAAU;EACpB,OAAO;EACP,KAAK,QAAQ;;CAGf,CAAC,OAAO,YAAyB;EAC/B,OAAO,CAAC,KAAK,MAAM,CAAC,OAAO,WAAW;;;AAI1C,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C;;;;;;;AAQxD,MAAa,YAAuDC;;;;;;AAOpE,MAAa,SAA2CC;;;;;;;AAQxD,MAAa,SAA8CC;;;;;;;;AAS3D,MAAa,mBAAyDC;;;;;;;AAQtE,MAAa,OAGTC;;;;;;;AAQJ,MAAa,MAGTC;;;;;;;AAQJ,MAAa,MAGTC;;;;;;;;;;;;;;;;;AAkBJ,MAAa,gBAGP,GAAG,SAAiC;CACxC,IAAI,KAAK,UAAU,KAAK,OAAO,KAAK,OAAO,YAAY,KAAK,OAAO,MACjE,OAAOC,cAAqB,KAAK,IAAyB,KAAK,GAAyB;CAE1F,MAAM,UAAU,KAAK;CACrB,QAAW,MAAmBA,cAAqB,GAAG,QAAQ;;;;;;;AAQhE,MAAa,aAAuCC;;;;;;AAOpD,MAAa,YAA6CC;;;;;;AAO1D,MAAa,YAA6CC;;;;;;;AAQ1D,MAAa,SACXC;;;;;;;;;;AAWF,MAAa,OAGTC;;;;;;;;;;;;;AAcJ,MAAa,aAGTC;;;;;;;AAQJ,MAAa,MAGTC;;;;;;;;;;;;;;;;;;;;AA0BJ,MAAa,QASTC"}
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./chunk-25Hzd3z8.mjs";
2
- import { A as unweighted$1, C as setR$1, D as softmax$1, E as setY$1, M as withWeight$1, O as subtract$1, S as scale$1, T as setX$1, _ as mapR$1, a as equals$1, b as mapY$1, c as getTheta$1, d as hadamard$1, f as isVector2$1, g as makeWeighted$1, h as make$1, i as dot$1, j as weightedEquals$1, k as transpose$1, l as getX$1, m as magnitude$1, n as components$1, o as fromPolar$1, p as isWeighted$1, r as cross$1, s as fromTuple$1, t as add$1, u as getY$1, v as mapTheta$1, w as setTheta$1, x as normalize$1, y as mapX$1 } from "./vector2.internal-DP1nTBdS.mjs";
2
+ import { A as transpose$1, C as scale$1, D as setY$1, E as setX$1, M as weightedEquals$1, N as withWeight$1, O as softmax$1, S as normalize$1, T as setTheta$1, _ as makeWeighted$1, a as equals$1, b as mapX$1, c as getTheta$1, d as hadamard$1, f as isVector2$1, g as make$1, h as magnitude$1, i as dot$1, j as unweighted$1, k as subtract$1, l as getX$1, m as liftWithWeight$1, n as components$1, o as fromPolar$1, p as isWeighted$1, r as cross$1, s as fromTuple$1, t as add$1, u as getY$1, v as mapR$1, w as setR$1, x as mapY$1, y as mapTheta$1 } from "./vector2.internal-rPnW0RCx.mjs";
3
3
  //#region src/vector/vector2.ts
4
4
  var vector2_exports = /* @__PURE__ */ __exportAll({
5
5
  add: () => add,
@@ -16,6 +16,7 @@ var vector2_exports = /* @__PURE__ */ __exportAll({
16
16
  hadamard: () => hadamard,
17
17
  isVector2: () => isVector2,
18
18
  isWeighted: () => isWeighted,
19
+ liftWithWeight: () => liftWithWeight,
19
20
  magnitude: () => magnitude,
20
21
  make: () => make,
21
22
  makeWeighted: () => makeWeighted,
@@ -74,6 +75,7 @@ const withWeight = withWeight$1;
74
75
  * @since 2.0.0
75
76
  */
76
77
  const unweighted = unweighted$1;
78
+ const liftWithWeight = liftWithWeight$1;
77
79
  const weightedEquals = weightedEquals$1;
78
80
  const equals = equals$1;
79
81
  const make = make$1;
@@ -200,6 +202,6 @@ const getTheta = getTheta$1;
200
202
  const setTheta = setTheta$1;
201
203
  const mapTheta = mapTheta$1;
202
204
  //#endregion
203
- export { make as a, subtract as c, magnitude as i, vector2_exports as l, cross as n, makeWeighted as o, isVector2 as r, scale as s, add as t };
205
+ export { magnitude as a, scale as c, liftWithWeight as i, subtract as l, cross as n, make as o, isVector2 as r, makeWeighted as s, add as t, vector2_exports as u };
204
206
 
205
- //# sourceMappingURL=vector2-CSkaMXvp.mjs.map
207
+ //# sourceMappingURL=vector2-DuA3EmfL.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector2-DuA3EmfL.mjs","names":["internal.isVector2","internal.isWeighted","internal.makeWeighted","internal.withWeight","internal.unweighted","internal.liftWithWeight","internal.weightedEquals","internal.equals","internal.make","internal.fromTuple","internal.transpose","internal.fromPolar","internal.magnitude","internal.normalize","internal.dot","internal.cross","internal.components","internal.softmax","internal.add","internal.subtract","internal.hadamard","internal.scale","internal.getX","internal.setX","internal.mapX","internal.getY","internal.setY","internal.mapY","internal.setR","internal.mapR","internal.getTheta","internal.setTheta","internal.mapTheta"],"sources":["../../src/vector/vector2.ts"],"sourcesContent":["import type { TwoDimensional } from '../dimensions.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector2TypeId, WeightedVector2TypeId } from './vector2.internal.ts'\nimport * as internal from './vector2.internal.ts'\n\n/**\n * A 2D vector.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 1.0.0\n */\nexport interface Vector2 extends Pipeable, TwoDimensional<number> {\n readonly [Vector2TypeId]: Vector2TypeId\n}\n\n/**\n * A 2D point with an associated positive scalar weight.\n *\n * Used by rational primitives (e.g. `RationalBezier2d`) where each control\n * point carries an influence weight. The interface is structurally distinct\n * from `Vector2` — its brand prevents accidental use with vector arithmetic\n * (`add`, `subtract`, `scale`, etc.) where weighted operations are not\n * well-defined.\n *\n * Construct via {@link makeWeighted} (from raw components) or\n * {@link withWeight} (from an existing `Vector2`).\n *\n * @since 2.0.0\n */\nexport interface Weighted extends Pipeable {\n readonly [WeightedVector2TypeId]: WeightedVector2TypeId\n readonly x: number\n readonly y: number\n readonly weight: number\n}\n\n/**\n * Checks if a value is a `Vector2`.\n *\n * @param v - The value to check.\n * @returns `true` if the value is a `Vector2`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isVector2: (v: unknown) => v is Vector2 = internal.isVector2\n\n/**\n * Checks if a value is a `Vector2.Weighted`.\n *\n * @param v - The value to check.\n * @returns `true` if the value is a `Vector2.Weighted`, `false` otherwise.\n * @since 2.0.0\n */\nexport const isWeighted: (v: unknown) => v is Weighted = internal.isWeighted\n\n/**\n * Creates a new `Vector2.Weighted` from raw components. The weight must be\n * finite and positive.\n *\n * @param x - The x component.\n * @param y - The y component.\n * @param weight - The positive scalar weight.\n * @returns A new `Vector2.Weighted` instance.\n * @since 2.0.0\n */\nexport const makeWeighted: (x: number, y: number, weight: number) => Weighted =\n internal.makeWeighted\n\nexport const withWeight: {\n /**\n * Promotes a `Vector2` to a `Vector2.Weighted` by attaching the given\n * positive scalar weight.\n *\n * @param v - The point to weight.\n * @param weight - The positive scalar weight.\n * @returns A new `Vector2.Weighted` instance.\n * @since 2.0.0\n */\n (v: Vector2, weight: number): Weighted\n /**\n * Promotes a `Vector2` to a `Vector2.Weighted` by attaching the given\n * positive scalar weight.\n *\n * @param weight - The positive scalar weight.\n * @returns A function that takes a `Vector2` and returns a weighted point.\n * @since 2.0.0\n */\n (weight: number): (v: Vector2) => Weighted\n} = internal.withWeight\n\n/**\n * Strips the weight from a `Vector2.Weighted`, returning the underlying point.\n *\n * @param w - The weighted point.\n * @returns A new `Vector2` instance with the same x and y components.\n * @since 2.0.0\n */\nexport const unweighted: (w: Weighted) => Vector2 = internal.unweighted\n\nexport const liftWithWeight: {\n /**\n * Lifts a `Vector2 → Vector2` function to operate on `Vector2.Weighted` by\n * applying the function to the position and preserving the input's weight.\n *\n * Designed as the bridge between point-only utilities (e.g. {@link setR},\n * `Vector2.add(offset)`) and weighted-spline mappers like\n * `RationalBezier2d.mapPoints`. The default of \"preserve weight\" is the safe\n * choice for the common case — translating, rotating, or scaling positions\n * on a curve like a conic arc shouldn't silently collapse the curve's\n * geometry-defining weights to a uniform value.\n *\n * @param fn - The position-only function to lift.\n * @returns A function from `Weighted` to `Weighted` that preserves weight.\n * @since 2.0.0\n */\n (fn: (v: Vector2) => Vector2): (w: Weighted) => Weighted\n /**\n * Lifts a `Vector2 → Vector2` function to operate on `Vector2.Weighted`,\n * replacing the input's weight with the given value.\n *\n * @param fn - The position-only function to lift.\n * @param weight - The positive scalar weight to attach to each output.\n * @returns A function from `Weighted` to `Weighted` that overrides weight.\n * @since 2.0.0\n */\n (fn: (v: Vector2) => Vector2, weight: number): (w: Weighted) => Weighted\n /**\n * Applies a `Vector2 → Vector2` function to the position of a\n * `Vector2.Weighted`, preserving the input's weight.\n *\n * @param w - The weighted point to transform.\n * @param fn - The position-only function to apply.\n * @returns A new `Vector2.Weighted` with the function applied to position and the original weight.\n * @since 2.0.0\n */\n (w: Weighted, fn: (v: Vector2) => Vector2): Weighted\n /**\n * Applies a `Vector2 → Vector2` function to the position of a\n * `Vector2.Weighted`, replacing the weight with the given value.\n *\n * @param w - The weighted point to transform.\n * @param fn - The position-only function to apply.\n * @param weight - The positive scalar weight to attach to the output.\n * @returns A new `Vector2.Weighted` with the function applied to position and the overridden weight.\n * @since 2.0.0\n */\n (w: Weighted, fn: (v: Vector2) => Vector2, weight: number): Weighted\n} = internal.liftWithWeight\n\nexport const weightedEquals: {\n /**\n * Checks if two `Vector2.Weighted` instances are approximately equal —\n * point components and weight all within the default absolute tolerance.\n *\n * @param a - The first weighted point.\n * @param b - The second weighted point.\n * @returns `true` when components and weight are within tolerance.\n * @since 2.0.0\n */\n (a: Weighted, b: Weighted): boolean\n /**\n * Checks if two `Vector2.Weighted` instances are approximately equal.\n *\n * @param b - The second weighted point.\n * @returns A function that takes the first weighted point and returns the comparison result.\n * @since 2.0.0\n */\n (b: Weighted): (a: Weighted) => boolean\n} = internal.weightedEquals\n\nexport const equals: {\n /**\n * Checks if two `Vector2` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns `true` when each pair of components is within tolerance.\n * @since 1.1.0\n */\n (a: Vector2, b: Vector2): boolean\n /**\n * Checks if two `Vector2` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the comparison result.\n * @since 1.1.0\n */\n (b: Vector2): (a: Vector2) => boolean\n} = internal.equals\n\nexport const make: {\n /**\n * Creates a new `Vector2` instance.\n *\n * @param xy - The x and y components of the vector.\n * @returns A new `Vector2` instance.\n * @since 1.0.0\n */\n (xy: number): Vector2\n /**\n * Creates a new `Vector2` instance.\n *\n * @param x - The x component of the vector.\n * @param y - The y component of the vector.\n * @returns A new `Vector2` instance.\n * @since 1.0.0\n */\n (x: number, y: number): Vector2\n} = internal.make\n\n/**\n * Creates a new `Vector2` instance from a `[x, y]` tuple. Inverse of\n * {@link components}.\n *\n * @param t - The `[x, y]` tuple.\n * @returns A new `Vector2` instance.\n * @since 2.0.0\n */\nexport const fromTuple: (t: readonly [number, number]) => Vector2 = internal.fromTuple\n\n/**\n * Transposes a 2-tuple of items into one or more `Vector2`s, one per channel\n * extracted by the projection function. See {@link Vector4.transpose} for the\n * full operation description; this is the 2-component analog.\n *\n * @param inputs - Exactly two items of any type.\n * @param project - A function returning a fixed-arity tuple of numbers — one per output channel.\n * @returns A tuple of `Vector2`s with the same arity as the projection's return tuple.\n * @since 2.0.0\n */\nexport const transpose: <T, const Channels extends ReadonlyArray<number>>(\n inputs: readonly [T, T],\n project: (item: T) => Channels,\n) => { readonly [K in keyof Channels]: Vector2 } = internal.transpose\n\n/**\n * Creates a new `Vector2` instance from polar coordinates.\n *\n * @param r - The radius.\n * @param theta - The angle, in radians.\n * @returns A new `Vector2` instance.\n * @since 1.0.0\n */\nexport const fromPolar: (r: number, theta: number) => Vector2 = internal.fromPolar\n\n/**\n * Calculates the magnitude of a `Vector2`.\n *\n * @param vector - The vector to calculate the magnitude of.\n * @returns The magnitude of the vector.\n * @since 1.0.0\n */\nexport const magnitude: (vector: Vector2) => number = internal.magnitude\n\n/**\n * Normalizes a `Vector2`.\n *\n * @param vector - The vector to normalize.\n * @returns A new `Vector2` instance with the same direction and a magnitude of 1.\n * @since 1.0.0\n */\nexport const normalize: (vector: Vector2) => Vector2 = internal.normalize\n\nexport const dot: {\n /**\n * Calculates the dot product of two `Vector2` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns The dot product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector2, b: Vector2): number\n /**\n * Calculates the dot product of two `Vector2` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the dot product.\n * @since 1.0.0\n */\n (b: Vector2): (a: Vector2) => number\n} = internal.dot\n\nexport const cross: {\n /**\n * Calculates the cross product of two `Vector2` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns The cross product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector2, b: Vector2): number\n /**\n * Calculates the cross product of two `Vector2` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the cross product.\n * @since 1.0.0\n */\n (b: Vector2): (a: Vector2) => number\n} = internal.cross\n\n/**\n * Returns the components of a `Vector2` as an array.\n *\n * @param r - The radius.\n * @param theta - The angle, in radians.\n * @returns A new `Vector2` instance.\n * @since 1.0.0\n */\nexport const components: (v: Vector2) => [number, number] = internal.components\n\n/**\n * Applies the softmax function to a `Vector2`.\n *\n * @param v - The vector to apply the softmax function to.\n * @returns A new `Vector2` instance with the softmax applied.\n * @since 1.0.0\n */\nexport const softmax: (v: Vector2) => Vector2 = internal.softmax\n\n/**\n * Creates a zero vector.\n *\n * @returns A new `Vector2` instance with both components set to 0.\n * @since 1.0.0\n */\nexport const zero = make(0)\n\n/**\n * Creates a unit vector.\n *\n * @returns A new `Vector2` instance with both components set to 1.\n * @since 1.0.0\n */\nexport const unit = make(1)\n\nexport const add: {\n /**\n * Adds two `Vector2` instances together.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector2` instance representing the sum of the two vectors.\n * @since 1.0.0\n */\n (a: Vector2, b: Vector2): Vector2\n /**\n * Adds two `Vector2` instances together.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the sum.\n * @since 1.0.0\n */\n (b: Vector2): (a: Vector2) => Vector2\n} = internal.add\n\nexport const subtract: {\n /**\n * Subtracts one `Vector2` instance from another.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector2` instance representing the difference of the two vectors.\n * @since 1.0.0\n */\n (a: Vector2, b: Vector2): Vector2\n /**\n * Subtracts one `Vector2` instance from another.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the difference.\n * @since 1.0.0\n */\n (b: Vector2): (a: Vector2) => Vector2\n} = internal.subtract\n\nexport const hadamard: {\n /**\n * Performs the Hadamard product of two `Vector2` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector2` instance representing the Hadamard product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector2, b: Vector2): Vector2\n /**\n * Performs the Hadamard product of two `Vector2` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the Hadamard product.\n * @since 1.0.0\n */\n (b: Vector2): (a: Vector2) => Vector2\n} = internal.hadamard\n\nexport const scale: {\n /**\n * Scales a `Vector2` by a scalar value.\n *\n * @param s - The scalar value to scale by.\n * @returns A function that takes a vector and returns the scaled vector.\n * @since 1.0.0\n */\n (s: number): (v: Vector2) => Vector2\n /**\n * Scales a `Vector2` by a scalar value.\n *\n * @param v - The vector to scale.\n * @param s - The scalar value to scale by.\n * @returns A new `Vector2` instance representing the scaled vector.\n * @since 1.0.0\n */\n (v: Vector2, s: number): Vector2\n} = internal.scale\n\n/**\n * Gets the x component of a `Vector2`.\n *\n * @param v - The vector to get the x component from.\n * @returns The x component of the vector.\n * @since 1.0.0\n */\nexport const getX: (v: Vector2) => number = internal.getX\n\nexport const setX: {\n /**\n * Sets the x component of a `Vector2`.\n *\n * @param v - The vector to set the x component of.\n * @param x - The new x component.\n * @returns A new `Vector2` instance with the updated x component.\n * @since 1.0.0\n */\n (v: Vector2, x: number): Vector2\n /**\n * Sets the x component of a `Vector2`.\n *\n * @param x - The new x component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 1.0.0\n */\n (x: number): (v: Vector2) => Vector2\n} = internal.setX\n\nexport const mapX: {\n /**\n * Returns a new `Vector2` with the x component replaced by `f(v.x)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the x component.\n * @returns A new `Vector2` with the updated x.\n * @since 2.0.0\n */\n (v: Vector2, f: (x: number) => number): Vector2\n /**\n * Returns a new `Vector2` with the x component replaced by `f(v.x)`.\n *\n * @param f - The function to apply to the x component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (x: number) => number): (v: Vector2) => Vector2\n} = internal.mapX\n\n/**\n * Gets the y component of a `Vector2`.\n *\n * @param v - The vector to get the y component from.\n * @returns The y component of the vector.\n * @since 1.0.0\n */\nexport const getY: (v: Vector2) => number = internal.getY\n\nexport const setY: {\n /**\n * Sets the y component of a `Vector2`.\n *\n * @param v - The vector to set the y component of.\n * @param y - The new y component.\n * @returns A new `Vector2` instance with the updated y component.\n * @since 1.0.0\n */\n (v: Vector2, y: number): Vector2\n /**\n * Sets the y component of a `Vector2`.\n *\n * @param y - The new y component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 1.0.0\n */\n (y: number): (v: Vector2) => Vector2\n} = internal.setY\n\nexport const mapY: {\n /**\n * Returns a new `Vector2` with the y component replaced by `f(v.y)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the y component.\n * @returns A new `Vector2` with the updated y.\n * @since 2.0.0\n */\n (v: Vector2, f: (y: number) => number): Vector2\n /**\n * Returns a new `Vector2` with the y component replaced by `f(v.y)`.\n *\n * @param f - The function to apply to the y component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (y: number) => number): (v: Vector2) => Vector2\n} = internal.mapY\n\n/**\n * Gets the radius of a `Vector2`.\n *\n * @param v - The vector to get the radius from.\n * @returns The radius of the vector.\n * @since 1.0.0\n */\nexport const getR: (v: Vector2) => number = magnitude\n\nexport const setR: {\n /**\n * Sets the radius of a `Vector2`.\n *\n * @param v - The vector to set the radius of.\n * @param r - The new radius.\n * @returns A new `Vector2` instance with the updated radius.\n * @since 1.0.0\n */\n (v: Vector2, r: number): Vector2\n /**\n * Sets the radius of a `Vector2`.\n *\n * @param r - The new radius.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 1.0.0\n */\n (r: number): (v: Vector2) => Vector2\n} = internal.setR\n\nexport const mapR: {\n /**\n * Returns a new `Vector2` with the radius replaced by `f(magnitude(v))`,\n * preserving the angle.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the radius.\n * @returns A new `Vector2` with the updated radius.\n * @since 2.0.0\n */\n (v: Vector2, f: (r: number) => number): Vector2\n /**\n * Returns a new `Vector2` with the radius replaced by `f(magnitude(v))`,\n * preserving the angle.\n *\n * @param f - The function to apply to the radius.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (r: number) => number): (v: Vector2) => Vector2\n} = internal.mapR\n\n/**\n * Gets the angle of a `Vector2`.\n *\n * @param v - The vector to get the angle from.\n * @returns The angle of the vector in radians.\n * @since 1.0.0\n */\nexport const getTheta: (v: Vector2) => number = internal.getTheta\n\nexport const setTheta: {\n /**\n * Sets the angle of a `Vector2`.\n *\n * @param v - The vector to set the angle of.\n * @param theta - The new angle, in radians.\n * @returns A new `Vector2` instance with the updated angle.\n * @since 1.0.0\n */\n (v: Vector2, theta: number): Vector2\n /**\n * Sets the angle of a `Vector2`.\n *\n * @param theta - The new angle, in radians.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 1.0.0\n */\n (theta: number): (v: Vector2) => Vector2\n} = internal.setTheta\n\nexport const mapTheta: {\n /**\n * Returns a new `Vector2` with the angle replaced by `f(getTheta(v))`,\n * preserving the radius.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the angle (in radians).\n * @returns A new `Vector2` with the updated angle.\n * @since 2.0.0\n */\n (v: Vector2, f: (theta: number) => number): Vector2\n /**\n * Returns a new `Vector2` with the angle replaced by `f(getTheta(v))`,\n * preserving the radius.\n *\n * @param f - The function to apply to the angle (in radians).\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (theta: number) => number): (v: Vector2) => Vector2\n} = internal.mapTheta\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAa,YAA0CA;;;;;;;;AASvD,MAAa,aAA4CC;;;;;;;;;;;AAYzD,MAAa,eACXC;AAEF,MAAa,aAoBTC;;;;;;;;AASJ,MAAa,aAAuCC;AAEpD,MAAa,iBAgDTC;AAEJ,MAAa,iBAmBTC;AAEJ,MAAa,SAoBTC;AAEJ,MAAa,OAkBTC;;;;;;;;;AAUJ,MAAa,YAAuDC;;;;;;;;;;;AAYpE,MAAa,YAGsCC;;;;;;;;;AAUnD,MAAa,YAAmDC;;;;;;;;AAShE,MAAa,YAAyCC;;;;;;;;AAStD,MAAa,YAA0CC;AAEvD,MAAa,MAkBTC;AAEJ,MAAa,QAkBTC;;;;;;;;;AAUJ,MAAa,aAA+CC;;;;;;;;AAS5D,MAAa,UAAmCC;;;;;;;AAQhD,MAAa,OAAO,KAAK,EAAE;;;;;;;AAQ3B,MAAa,OAAO,KAAK,EAAE;AAE3B,MAAa,MAkBTC;AAEJ,MAAa,WAkBTC;AAEJ,MAAa,WAkBTC;AAEJ,MAAa,QAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+B;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAoBTC;;;;;;;;AASJ,MAAa,WAAmCC;AAEhD,MAAa,WAkBTC;AAEJ,MAAa,WAoBTC"}
@@ -1,5 +1,5 @@
1
1
  import { Pipeable, dual, invariant } from "../utils.mjs";
2
- import { epsEquals } from "../number.mjs";
2
+ import { coincident } from "../number.mjs";
3
3
  //#region src/vector/vector2.internal.ts
4
4
  const Vector2TypeId = Symbol.for("curvy/vector2");
5
5
  const WeightedVector2TypeId = Symbol.for("curvy/vector2/weighted");
@@ -48,7 +48,7 @@ const isVector2 = (v) => typeof v === "object" && v !== null && Vector2TypeId in
48
48
  /** @internal */
49
49
  const isWeighted = (v) => typeof v === "object" && v !== null && WeightedVector2TypeId in v;
50
50
  /** @internal */
51
- const equals = dual(2, (a, b) => epsEquals(a.x, b.x) && epsEquals(a.y, b.y));
51
+ const equals = dual(2, (a, b) => coincident(a.x, b.x) && coincident(a.y, b.y));
52
52
  /** @internal */
53
53
  const make = (v0, v1 = v0) => new Vector2Impl(v0, v1);
54
54
  /** @internal */
@@ -71,7 +71,12 @@ const withWeight = dual(2, (v, weight) => makeWeighted(v.x, v.y, weight));
71
71
  /** @internal */
72
72
  const unweighted = (w) => make(w.x, w.y);
73
73
  /** @internal */
74
- const weightedEquals = dual(2, (a, b) => epsEquals(a.x, b.x) && epsEquals(a.y, b.y) && epsEquals(a.weight, b.weight));
74
+ const liftWithWeight = dual((args) => isWeighted(args[0]), (w, fn, weight) => {
75
+ const r = fn(make(w.x, w.y));
76
+ return makeWeighted(r.x, r.y, weight ?? w.weight);
77
+ });
78
+ /** @internal */
79
+ const weightedEquals = dual(2, (a, b) => coincident(a.x, b.x) && coincident(a.y, b.y) && coincident(a.weight, b.weight));
75
80
  /** @internal */
76
81
  const fromPolar = (r, theta) => make(r * Math.cos(theta), r * Math.sin(theta));
77
82
  /** @internal */
@@ -136,6 +141,6 @@ const mapTheta = dual(2, (v, f) => {
136
141
  return make(r * Math.cos(theta), r * Math.sin(theta));
137
142
  });
138
143
  //#endregion
139
- export { unweighted as A, setR as C, softmax as D, setY as E, withWeight as M, subtract as O, scale as S, setX as T, mapR as _, equals as a, mapY as b, getTheta as c, hadamard as d, isVector2 as f, makeWeighted as g, make as h, dot as i, weightedEquals as j, transpose as k, getX as l, magnitude as m, components as n, fromPolar as o, isWeighted as p, cross as r, fromTuple as s, add as t, getY as u, mapTheta as v, setTheta as w, normalize as x, mapX as y };
144
+ export { transpose as A, scale as C, setY as D, setX as E, weightedEquals as M, withWeight as N, softmax as O, normalize as S, setTheta as T, makeWeighted as _, equals as a, mapX as b, getTheta as c, hadamard as d, isVector2 as f, make as g, magnitude as h, dot as i, unweighted as j, subtract as k, getX as l, liftWithWeight as m, components as n, fromPolar as o, isWeighted as p, cross as r, fromTuple as s, add as t, getY as u, mapR as v, setR as w, mapY as x, mapTheta as y };
140
145
 
141
- //# sourceMappingURL=vector2.internal-DP1nTBdS.mjs.map
146
+ //# sourceMappingURL=vector2.internal-rPnW0RCx.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector2.internal-rPnW0RCx.mjs","names":[],"sources":["../../src/vector/vector2.internal.ts"],"sourcesContent":["import { dual, Pipeable } from '../utils.ts'\nimport { invariant } from '../utils.ts'\nimport { coincident } from '../number.ts'\nimport type { Vector2, Weighted } from './vector2.ts'\n\nexport const Vector2TypeId = Symbol.for('curvy/vector2')\nexport type Vector2TypeId = typeof Vector2TypeId\n\nexport const WeightedVector2TypeId = Symbol.for('curvy/vector2/weighted')\nexport type WeightedVector2TypeId = typeof WeightedVector2TypeId\n\nclass Vector2Impl extends Pipeable implements Vector2 {\n readonly [Vector2TypeId]: Vector2TypeId = Vector2TypeId\n\n readonly x: number\n readonly y: number\n\n constructor(v0 = 0, v1 = 0) {\n super()\n this.x = v0\n this.y = v1\n }\n\n get [0]() {\n return this.x\n }\n\n get [1]() {\n return this.y\n }\n\n get [Symbol.toStringTag]() {\n return `Vector2(${this.x}, ${this.y})`\n }\n\n get [Symbol.for('nodejs.util.inspect.custom')]() {\n return this[Symbol.toStringTag]\n }\n}\n\nclass WeightedImpl extends Pipeable implements Weighted {\n readonly [WeightedVector2TypeId]: WeightedVector2TypeId = WeightedVector2TypeId\n\n readonly x: number\n readonly y: number\n readonly weight: number\n\n constructor(x: number, y: number, weight: number) {\n super()\n this.x = x\n this.y = y\n this.weight = weight\n }\n\n get [Symbol.toStringTag]() {\n return `Vector2.Weighted(${this.x}, ${this.y}, w=${this.weight})`\n }\n\n get [Symbol.for('nodejs.util.inspect.custom')]() {\n return this[Symbol.toStringTag]\n }\n}\n\n/** @internal */\nexport const isVector2 = (v: unknown): v is Vector2 =>\n typeof v === 'object' && v !== null && Vector2TypeId in v\n\n/** @internal */\nexport const isWeighted = (v: unknown): v is Weighted =>\n typeof v === 'object' && v !== null && WeightedVector2TypeId in v\n\n/** @internal */\nexport const equals = dual<\n (b: Vector2) => (a: Vector2) => boolean,\n (a: Vector2, b: Vector2) => boolean\n>(2, (a: Vector2, b: Vector2) => coincident(a.x, b.x) && coincident(a.y, b.y))\n\n/** @internal */\nexport const make = (v0: number, v1 = v0): Vector2 => new Vector2Impl(v0, v1)\n\n/** @internal */\nexport const fromTuple = (t: readonly [number, number]): Vector2 => new Vector2Impl(t[0], t[1])\n\n/** @internal */\nexport const transpose = <T, const Channels extends ReadonlyArray<number>>(\n inputs: readonly [T, T],\n project: (item: T) => Channels,\n): { readonly [K in keyof Channels]: Vector2 } => {\n const a = project(inputs[0])\n const b = project(inputs[1])\n const result: Array<Vector2> = []\n for (let i = 0; i < a.length; i++) {\n result.push(make(a[i] as number, b[i] as number))\n }\n return result as never\n}\n\n/** @internal */\nexport const makeWeighted = (x: number, y: number, weight: number): Weighted => {\n invariant(\n Number.isFinite(weight) && weight > 0,\n 'Vector2.Weighted weight must be positive and finite',\n )\n return new WeightedImpl(x, y, weight)\n}\n\n/** @internal */\nexport const withWeight = dual<\n (weight: number) => (v: Vector2) => Weighted,\n (v: Vector2, weight: number) => Weighted\n>(2, (v: Vector2, weight: number) => makeWeighted(v.x, v.y, weight))\n\n/** @internal */\nexport const unweighted = (w: Weighted): Vector2 => make(w.x, w.y)\n\n/** @internal */\nexport const liftWithWeight = dual(\n (args) => isWeighted(args[0]),\n (w: Weighted, fn: (v: Vector2) => Vector2, weight?: number): Weighted => {\n const r = fn(make(w.x, w.y))\n return makeWeighted(r.x, r.y, weight ?? w.weight)\n },\n)\n\n/** @internal */\nexport const weightedEquals = dual<\n (b: Weighted) => (a: Weighted) => boolean,\n (a: Weighted, b: Weighted) => boolean\n>(\n 2,\n (a: Weighted, b: Weighted) =>\n coincident(a.x, b.x) && coincident(a.y, b.y) && coincident(a.weight, b.weight),\n)\n\n/** @internal */\nexport const fromPolar = (r: number, theta: number) =>\n make(r * Math.cos(theta), r * Math.sin(theta))\n\n/** @internal */\nexport const components = (v: Vector2): [number, number] => [v.x, v.y]\n\n/** @internal */\nexport const magnitude = (vector: Vector2) => Math.hypot(vector.x, vector.y)\n\n/** @internal */\nexport const normalize = (vector: Vector2) => {\n const m = magnitude(vector)\n\n return make(vector.x / m, vector.y / m)\n}\n\n/** @internal */\nexport const dot = dual<(b: Vector2) => (a: Vector2) => number, (a: Vector2, b: Vector2) => number>(\n 2,\n (a: Vector2, b: Vector2) => a.x * b.x + a.y * b.y,\n)\n\n/** @internal */\nexport const cross = dual<\n (b: Vector2) => (a: Vector2) => number,\n (a: Vector2, b: Vector2) => number\n>(2, (a: Vector2, b: Vector2) => a.x * b.y - a.y * b.x)\n\n/** @internal */\nexport const softmax = (v: Vector2) => {\n const max = Math.max(v.x, v.y)\n\n const v0 = Math.exp(v.x - max)\n const v1 = Math.exp(v.y - max)\n\n const sum = v0 + v1\n\n return make(v0 / sum, v1 / sum)\n}\n\n/** @internal */\nexport const add = dual<\n (b: Vector2) => (a: Vector2) => Vector2,\n (a: Vector2, b: Vector2) => Vector2\n>(2, (a: Vector2, b: Vector2) => make(a.x + b.x, a.y + b.y))\n\n/** @internal */\nexport const subtract = dual<\n (b: Vector2) => (a: Vector2) => Vector2,\n (a: Vector2, b: Vector2) => Vector2\n>(2, (a: Vector2, b: Vector2) => make(a.x - b.x, a.y - b.y))\n\n/** @internal */\nexport const hadamard = dual<\n (b: Vector2) => (a: Vector2) => Vector2,\n (a: Vector2, b: Vector2) => Vector2\n>(2, (a: Vector2, b: Vector2) => make(a.x * b.x, a.y * b.y))\n\n/** @internal */\nexport const scale = dual<\n (s: number) => (v: Vector2) => Vector2,\n (v: Vector2, s: number) => Vector2\n>(2, (v: Vector2, s: number) => (s === 1 ? v : make(v.x * s, v.y * s)))\n\n/** @internal */\nexport const getX = (v: Vector2) => v.x\n/** @internal */\nexport const setX = dual<\n (x: number) => (v: Vector2) => Vector2,\n (v: Vector2, x: number) => Vector2\n>(2, (v: Vector2, x: number) => make(x, v.y))\n\n/** @internal */\nexport const mapX = dual<\n (f: (x: number) => number) => (v: Vector2) => Vector2,\n (v: Vector2, f: (x: number) => number) => Vector2\n>(2, (v: Vector2, f: (x: number) => number) => make(f(v.x), v.y))\n\n/** @internal */\nexport const getY = (v: Vector2) => v.y\n/** @internal */\nexport const setY = dual<\n (y: number) => (v: Vector2) => Vector2,\n (v: Vector2, y: number) => Vector2\n>(2, (v: Vector2, y: number) => make(v.x, y))\n\n/** @internal */\nexport const mapY = dual<\n (f: (y: number) => number) => (v: Vector2) => Vector2,\n (v: Vector2, f: (y: number) => number) => Vector2\n>(2, (v: Vector2, f: (y: number) => number) => make(v.x, f(v.y)))\n\n/** @internal */\nexport const setR = dual<\n (r: number) => (v: Vector2) => Vector2,\n (v: Vector2, r: number) => Vector2\n>(2, (v: Vector2, r: number) => scale(r / magnitude(v))(v))\n\n/** @internal */\nexport const mapR = dual<\n (f: (r: number) => number) => (v: Vector2) => Vector2,\n (v: Vector2, f: (r: number) => number) => Vector2\n>(2, (v: Vector2, f: (r: number) => number) => {\n const r = magnitude(v)\n return scale(f(r) / r)(v)\n})\n\n/** @internal */\nexport const getTheta = (v: Vector2) => Math.atan2(v.y, v.x)\n/** @internal */\nexport const setTheta = dual<\n (theta: number) => (v: Vector2) => Vector2,\n (v: Vector2, theta: number) => Vector2\n>(2, (v: Vector2, theta: number) => {\n const r = magnitude(v)\n return make(r * Math.cos(theta), r * Math.sin(theta))\n})\n\n/** @internal */\nexport const mapTheta = dual<\n (f: (theta: number) => number) => (v: Vector2) => Vector2,\n (v: Vector2, f: (theta: number) => number) => Vector2\n>(2, (v: Vector2, f: (theta: number) => number) => {\n const r = magnitude(v)\n const theta = f(Math.atan2(v.y, v.x))\n return make(r * Math.cos(theta), r * Math.sin(theta))\n})\n"],"mappings":";;;AAKA,MAAa,gBAAgB,OAAO,IAAI,gBAAgB;AAGxD,MAA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AE,CAAC;;AAG3D,MAAa,OAAO,KAGlB,IAAI,GAAY,MAA6B;CAC7C,MAAM,IAAI,UAAU,EAAE;CACtB,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE;EACzB;;AAGF,MAAa,YAAY,MAAe,KAAK,MAAM,EAAE,GAAG,EAAE,EAAE;;AAE5D,MAAa,WAAW,KAGtB,IAAI,GAAY,UAAkB;CAClC,MAAM,IAAI,UAAU,EAAE;CACtB,OAAO,KAAK,IAAI,KAAK,IAAI,MAAM,EAAE,IAAI,KAAK,IAAI,MAAM,CAAC;EACrD;;AAGF,MAAa,WAAW,KAGtB,IAAI,GAAY,MAAiC;CACjD,MAAM,IAAI,UAAU,EAAE;CACtB,MAAM,QAAQ,EAAE,KAAK,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC;CACrC,OAAO,KAAK,IAAI,KAAK,IAAI,MAAM,EAAE,IAAI,KAAK,IAAI,MAAM,CAAC;EACrD"}
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./chunk-25Hzd3z8.mjs";
2
- import { $ as setTheta$1, A as dot$1, B as isVector3$1, D as add$1, F as getTheta$1, G as mapTheta$1, H as make$1, I as getX$1, J as mapZ$1, K as mapX$1, L as getY$1, M as fromSpherical$1, N as fromTuple$1, O as components$1, P as getPhi$1, Q as setR$1, R as getZ$1, U as mapPhi$1, V as magnitude$1, W as mapR$1, X as scale$1, Y as normalize$1, Z as setPhi$1, at as transpose$1, et as setX$1, it as subtract$1, j as equals$1, k as cross$1, nt as setZ$1, q as mapY$1, rt as softmax$1, tt as setY$1, z as hadamard$1 } from "./vector4.internal-BJ1QN2Ck.mjs";
2
+ import { A as setZ$1, C as normalize$1, D as setTheta$1, E as setR$1, M as subtract$1, N as transpose$1, O as setX$1, S as mapZ$1, T as setPhi$1, _ as mapPhi$1, a as equals$1, b as mapX$1, c as getPhi$1, d as getY$1, f as getZ$1, g as make$1, h as magnitude$1, i as dot$1, j as softmax$1, k as setY$1, l as getTheta$1, m as isVector3$1, n as components$1, o as fromSpherical$1, p as hadamard$1, r as cross$1, s as fromTuple$1, t as add$1, u as getX$1, v as mapR$1, w as scale$1, x as mapY$1, y as mapTheta$1 } from "./vector3.internal-CfWHl9SG.mjs";
3
3
  //#region src/vector/vector3.ts
4
4
  var vector3_exports = /* @__PURE__ */ __exportAll({
5
5
  add: () => add,
@@ -223,4 +223,4 @@ const mapPhi = mapPhi$1;
223
223
  //#endregion
224
224
  export { vector3_exports as n, make as t };
225
225
 
226
- //# sourceMappingURL=vector3-CR2LPV03.mjs.map
226
+ //# sourceMappingURL=vector3-oxtggkDp.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"vector3-CR2LPV03.mjs","names":["internal.isVector3","internal.equals","internal.make","internal.fromTuple","internal.transpose","internal.fromSpherical","internal.magnitude","internal.normalize","internal.dot","internal.cross","internal.components","internal.softmax","internal.add","internal.subtract","internal.hadamard","internal.scale","internal.getX","internal.setX","internal.mapX","internal.getY","internal.setY","internal.mapY","internal.getZ","internal.setZ","internal.mapZ","internal.setR","internal.mapR","internal.getTheta","internal.setTheta","internal.mapTheta","internal.getPhi","internal.setPhi","internal.mapPhi"],"sources":["../../src/vector/vector3.ts"],"sourcesContent":["import type { ThreeDimensional } from '../dimensions.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector3TypeId } from './vector3.internal.ts'\nimport * as internal from './vector3.internal.ts'\n\n/**\n * A 3D vector.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 1.0.0\n */\nexport interface Vector3 extends Pipeable, ThreeDimensional<number> {\n readonly [Vector3TypeId]: Vector3TypeId\n}\n\n/**\n * Checks if a value is a `Vector3`.\n *\n * @param v - The value to check.\n * @returns `true` if the value is a `Vector3`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isVector3: (v: unknown) => v is Vector3 = internal.isVector3\n\nexport const equals: {\n /**\n * Checks if two `Vector3` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns `true` when each pair of components is within tolerance.\n * @since 1.1.0\n */\n (a: Vector3, b: Vector3): boolean\n /**\n * Checks if two `Vector3` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the comparison result.\n * @since 1.1.0\n */\n (b: Vector3): (a: Vector3) => boolean\n} = internal.equals\n\nexport const make: {\n /**\n * Creates a new `Vector3` instance.\n *\n * @param xyz - The x, y, and z components of the vector.\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\n (xyz: number): Vector3\n /**\n * Creates a new `Vector3` instance.\n *\n * @param x - The x component of the vector.\n * @param yz - The y and z components of the vector.\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\n (x: number, yz: number): Vector3\n /**\n * Creates a new `Vector3` instance.\n *\n * @param x - The x component of the vector.\n * @param y - The y component of the vector.\n * @param z - The z component of the vector.\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\n (x: number, y: number, z: number): Vector3\n} = internal.make\n\n/**\n * Creates a new `Vector3` instance from a `[x, y, z]` tuple. Inverse of\n * {@link components}.\n *\n * @param t - The `[x, y, z]` tuple.\n * @returns A new `Vector3` instance.\n * @since 2.0.0\n */\nexport const fromTuple: (t: readonly [number, number, number]) => Vector3 = internal.fromTuple\n\n/**\n * Transposes a 3-tuple of items into one or more `Vector3`s, one per channel\n * extracted by the projection function. See {@link Vector4.transpose} for the\n * full operation description; this is the 3-component analog.\n *\n * @param inputs - Exactly three items of any type.\n * @param project - A function returning a fixed-arity tuple of numbers — one per output channel.\n * @returns A tuple of `Vector3`s with the same arity as the projection's return tuple.\n * @since 2.0.0\n */\nexport const transpose: <T, const Channels extends ReadonlyArray<number>>(\n inputs: readonly [T, T, T],\n project: (item: T) => Channels,\n) => { readonly [K in keyof Channels]: Vector3 } = internal.transpose\n\n/**\n * Creates a new `Vector3` instance from spherical coordinates.\n *\n * @param r - The radius.\n * @param theta - The polar angle, in radians. Ranges from 0 to π\n * @param phi - The azimuthal angle, in radians. Ranges from 0 to 2π\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\nexport const fromSpherical: (r: number, theta: number, phi: number) => Vector3 =\n internal.fromSpherical\n\n/**\n * Calculates the magnitude of a `Vector3`.\n *\n * @param vector - The vector to calculate the magnitude of.\n * @returns The magnitude of the vector.\n * @since 1.0.0\n */\nexport const magnitude: (vector: Vector3) => number = internal.magnitude\n\n/**\n * Calculates the length of a `Vector3`.\n *\n * @param vector - The vector to calculate the length of.\n * @returns The length of the vector.\n * @see {@link magnitude}\n * @since 1.0.0\n */\nexport const length: (vector: Vector3) => number = magnitude\n\n/**\n * Normalizes a `Vector3`.\n *\n * @param vector - The vector to normalize.\n * @returns A new `Vector3` instance with the same direction as the input vector, but with a magnitude of 1.\n * @since 1.0.0\n */\nexport const normalize: (vector: Vector3) => Vector3 = internal.normalize\n\nexport const dot: {\n /**\n * Calculates the dot product of two `Vector3` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns The dot product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): number\n /**\n * Calculates the dot product of two `Vector3` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the dot product.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => number\n} = internal.dot\n\nexport const cross: {\n /**\n * Calculates the cross product of two `Vector3` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector3` instance representing the cross product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Calculates the cross product of two `Vector3` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the cross product.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.cross\n\n/**\n * Returns the components of a `Vector3` as an array.\n *\n * @param v - The vector to get the components of.\n * @returns An array containing the x, y, and z components of the vector.\n * @since 1.0.0\n */\nexport const components: (v: Vector3) => [number, number, number] = internal.components\n\n/**\n * Calculates the softmax of a `Vector3`.\n *\n * @param v - The vector to calculate the softmax of.\n * @returns A new `Vector3` instance representing the softmax of the input vector.\n * @since 1.0.0\n */\nexport const softmax: (v: Vector3) => Vector3 = internal.softmax\n\n/**\n * Creates a zero vector.\n *\n * @since 1.0.0\n */\nexport const zero = make(0)\n\n/**\n * Creates a unit vector.\n *\n * @since 1.0.0\n */\nexport const unit = make(1)\n\n/**\n * Creates a unit vector in the x direction.\n *\n * @since 1.0.0\n */\nexport const unitX = make(1, 0, 0)\n\n/**\n * Creates a unit vector in the y direction.\n *\n * @since 1.0.0\n */\nexport const unitY = make(0, 1, 0)\n\n/**\n * Creates a unit vector in the z direction.\n *\n * @since 1.0.0\n */\nexport const unitZ = make(0, 0, 1)\n\nexport const add: {\n /**\n * Adds two `Vector3` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector3` instance representing the sum of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Adds two `Vector3` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the sum.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.add\n\nexport const subtract: {\n /**\n * Subtracts one `Vector3` instance from another.\n *\n * @param a - The vector to subtract from.\n * @param b - The vector to subtract.\n * @returns A new `Vector3` instance representing the difference of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Subtracts one `Vector3` instance from another.\n *\n * @param b - The vector to subtract.\n * @returns A function that takes the first vector and returns the difference.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.subtract\n\nexport const hadamard: {\n /**\n * Calculates the Hadamard product of two `Vector3` instances.\n *\n * The Hadamard product is an element-wise multiplication of two vectors.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector3` instance representing the Hadamard product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Calculates the Hadamard product of two `Vector3` instances.\n *\n * The Hadamard product is an element-wise multiplication of two vectors.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the Hadamard product.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.hadamard\n\nexport const scale: {\n /**\n * Scales a `Vector3` instance by a scalar value.\n *\n * @param s - The scalar value to scale by.\n * @return A function that takes a vector and returns the scaled vector.\n * @since 1.0.0\n */\n (s: number): (v: Vector3) => Vector3\n /**\n * Scales a `Vector3` instance by a scalar value.\n *\n * @param s - The scalar value to scale by.\n * @param v - The vector to scale.\n * @returns A new `Vector3` instance representing the scaled vector.\n * @since 1.0.0\n */\n (v: Vector3, s: number): Vector3\n} = internal.scale\n\n/**\n * Gets the x component of a `Vector3`.\n *\n * @param v - The vector to get the x component of.\n * @returns The x component of the vector.\n * @since 1.0.0\n */\nexport const getX: (v: Vector3) => number = internal.getX\n\nexport const setX: {\n /**\n * Sets the x component of a `Vector3`.\n *\n * @param v - The vector to set the x component of.\n * @param x - The new x component.\n * @returns A new `Vector3` instance with the updated x component.\n * @since 1.0.0\n */\n (v: Vector3, x: number): Vector3\n /**\n * Sets the x component of a `Vector3`.\n *\n * @param x - The new x component.\n * @returns A function that takes the vector and returns a new `Vector3` instance with the updated x component.\n * @since 1.0.0\n */\n (x: number): (v: Vector3) => Vector3\n} = internal.setX\n\nexport const mapX: {\n /**\n * Returns a new `Vector3` with the x component replaced by `f(v.x)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the x component.\n * @returns A new `Vector3` with the updated x.\n * @since 2.0.0\n */\n (v: Vector3, f: (x: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the x component replaced by `f(v.x)`.\n *\n * @param f - The function to apply to the x component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (x: number) => number): (v: Vector3) => Vector3\n} = internal.mapX\n\n/**\n * Gets the y component of a `Vector3`.\n *\n * @param v - The vector of which to get the y component.\n * @returns The y component of the vector.\n * @since 1.0.0\n */\nexport const getY: (v: Vector3) => number = internal.getY\n\nexport const setY: {\n /**\n * Sets the y component of a `Vector3`.\n *\n * @param v - The vector of which to set the y component.\n * @param y - The new y component.\n * @returns A new `Vector3` instance with the updated y component.\n * @since 1.0.0\n */\n (v: Vector3, y: number): Vector3\n /**\n * Sets the y component of a `Vector3`.\n *\n * @param y - The new y component.\n * @returns A function that takes the vector and returns a new `Vector3` instance with the updated y component.\n * @since 1.0.0\n */\n (y: number): (v: Vector3) => Vector3\n} = internal.setY\n\nexport const mapY: {\n /**\n * Returns a new `Vector3` with the y component replaced by `f(v.y)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the y component.\n * @returns A new `Vector3` with the updated y.\n * @since 2.0.0\n */\n (v: Vector3, f: (y: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the y component replaced by `f(v.y)`.\n *\n * @param f - The function to apply to the y component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (y: number) => number): (v: Vector3) => Vector3\n} = internal.mapY\n\n/**\n * Gets the z component of a `Vector3`.\n *\n * @param v - The vector of which to get the z component.\n * @returns The z component of the vector.\n * @since 1.0.0\n */\nexport const getZ: (v: Vector3) => number = internal.getZ\n\nexport const setZ: {\n /**\n * Sets the z component of a `Vector3`.\n *\n * @param v - The vector of which to set the z component.\n * @param z - The new z component.\n * @returns A new `Vector3` instance with the updated z component.\n * @since 1.0.0\n */\n (v: Vector3, z: number): Vector3\n /**\n * Sets the z component of a `Vector3`.\n *\n * @param z - The new z component.\n * @returns A function that takes the vector and returns a new `Vector3` instance with the updated z component.\n * @since 1.0.0\n */\n (z: number): (v: Vector3) => Vector3\n} = internal.setZ\n\nexport const mapZ: {\n /**\n * Returns a new `Vector3` with the z component replaced by `f(v.z)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the z component.\n * @returns A new `Vector3` with the updated z.\n * @since 2.0.0\n */\n (v: Vector3, f: (z: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the z component replaced by `f(v.z)`.\n *\n * @param f - The function to apply to the z component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (z: number) => number): (v: Vector3) => Vector3\n} = internal.mapZ\n\n/**\n * Gets the radius of a `Vector3`.\n *\n * @param v - The vector of which to get the radius.\n * @returns The radius of the vector.\n * @since 1.0.0\n */\nexport const getR: (v: Vector3) => number = magnitude\n\nexport const setR: {\n /**\n * Sets the radius of a `Vector3`.\n *\n * @param v - The vector of which to set the radius.\n * @param r - The new radius.\n * @returns A new `Vector3` instance with the updated radius.\n * @since 1.0.0\n */\n (v: Vector3, r: number): Vector3\n /**\n * Sets the radius of a `Vector3`.\n *\n * @param r - The new radius.\n * @returns A function that takes the vector and returns the updated vector.\n * @since 1.0.0\n */\n (r: number): (v: Vector3) => Vector3\n} = internal.setR\n\nexport const mapR: {\n /**\n * Returns a new `Vector3` with the radius replaced by `f(magnitude(v))`,\n * preserving direction.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the radius.\n * @returns A new `Vector3` with the updated radius.\n * @since 2.0.0\n */\n (v: Vector3, f: (r: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the radius replaced by `f(magnitude(v))`,\n * preserving direction.\n *\n * @param f - The function to apply to the radius.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (r: number) => number): (v: Vector3) => Vector3\n} = internal.mapR\n\n/**\n * Gets the polar angle (theta) of a `Vector3`.\n *\n * @param v - The vector of which to get the polar angle.\n * @returns The polar angle of the vector.\n * @since 1.0.0\n */\nexport const getTheta: (v: Vector3) => number = internal.getTheta\n\nexport const setTheta: {\n /**\n * Sets the polar angle (theta) of a `Vector3`.\n *\n * @param v - The vector of which to set the polar angle.\n * @param theta - The new polar angle.\n * @returns A new `Vector3` instance with the updated polar angle.\n * @since 1.0.0\n */\n (v: Vector3, theta: number): Vector3\n /**\n * Sets the polar angle (theta) of a `Vector3`.\n *\n * @param theta - The new polar angle.\n * @returns A function that takes the vector and returns the updated vector.\n * @since 1.0.0\n */\n (theta: number): (v: Vector3) => Vector3\n} = internal.setTheta\n\nexport const mapTheta: {\n /**\n * Returns a new `Vector3` with the polar angle replaced by\n * `f(getTheta(v))`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the polar angle (in radians).\n * @returns A new `Vector3` with the updated polar angle.\n * @since 2.0.0\n */\n (v: Vector3, f: (theta: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the polar angle replaced by\n * `f(getTheta(v))`.\n *\n * @param f - The function to apply to the polar angle (in radians).\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (theta: number) => number): (v: Vector3) => Vector3\n} = internal.mapTheta\n\n/**\n * Gets the azimuthal angle (phi) of a `Vector3`.\n *\n * @param v - The vector of which to get the azimuthal angle.\n * @returns The azimuthal angle of the vector.\n * @since 1.0.0\n */\nexport const getPhi: (v: Vector3) => number = internal.getPhi\n\nexport const setPhi: {\n /**\n * Sets the azimuthal angle (phi) of a `Vector3`.\n *\n * @param v - The vector of which to set the azimuthal angle.\n * @param phi - The new azimuthal angle.\n * @returns A new `Vector3` instance with the updated azimuthal angle.\n * @since 1.0.0\n */\n (v: Vector3, phi: number): Vector3\n /**\n * Sets the azimuthal angle (phi) of a `Vector3`.\n *\n * @param phi - The new azimuthal angle.\n * @returns A function that takes the vector and returns the updated vector.\n * @since 1.0.0\n */\n (phi: number): (v: Vector3) => Vector3\n} = internal.setPhi\n\nexport const mapPhi: {\n /**\n * Returns a new `Vector3` with the azimuthal angle replaced by\n * `f(getPhi(v))`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the azimuthal angle (in radians).\n * @returns A new `Vector3` with the updated azimuthal angle.\n * @since 2.0.0\n */\n (v: Vector3, f: (phi: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the azimuthal angle replaced by\n * `f(getPhi(v))`.\n *\n * @param f - The function to apply to the azimuthal angle (in radians).\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (phi: number) => number): (v: Vector3) => Vector3\n} = internal.mapPhi\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,YAA0CA;AAEvD,MAAa,SAoBTC;AAEJ,MAAa,OA4BTC;;;;;;;;;AAUJ,MAAa,YAA+DC;;;;;;;;;;;AAY5E,MAAa,YAGsCC;;;;;;;;;;AAWnD,MAAa,gBACXC;;;;;;;;AASF,MAAa,YAAyCC;;;;;;;;;AAUtD,MAAa,SAAsC;;;;;;;;AASnD,MAAa,YAA0CC;AAEvD,MAAa,MAkBTC;AAEJ,MAAa,QAkBTC;;;;;;;;AASJ,MAAa,aAAuDC;;;;;;;;AASpE,MAAa,UAAmCC;;;;;;AAOhD,MAAa,OAAO,KAAK,EAAE;;;;;;AAO3B,MAAa,OAAO,KAAK,EAAE;;;;;;AAO3B,MAAa,QAAQ,KAAK,GAAG,GAAG,EAAE;;;;;;AAOlC,MAAa,QAAQ,KAAK,GAAG,GAAG,EAAE;;;;;;AAOlC,MAAa,QAAQ,KAAK,GAAG,GAAG,EAAE;AAElC,MAAa,MAkBTC;AAEJ,MAAa,WAkBTC;AAEJ,MAAa,WAsBTC;AAEJ,MAAa,QAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+B;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAoBTC;;;;;;;;AASJ,MAAa,WAAmCC;AAEhD,MAAa,WAkBTC;AAEJ,MAAa,WAoBTC;;;;;;;;AASJ,MAAa,SAAiCC;AAE9C,MAAa,SAkBTC;AAEJ,MAAa,SAoBTC"}
1
+ {"version":3,"file":"vector3-oxtggkDp.mjs","names":["internal.isVector3","internal.equals","internal.make","internal.fromTuple","internal.transpose","internal.fromSpherical","internal.magnitude","internal.normalize","internal.dot","internal.cross","internal.components","internal.softmax","internal.add","internal.subtract","internal.hadamard","internal.scale","internal.getX","internal.setX","internal.mapX","internal.getY","internal.setY","internal.mapY","internal.getZ","internal.setZ","internal.mapZ","internal.setR","internal.mapR","internal.getTheta","internal.setTheta","internal.mapTheta","internal.getPhi","internal.setPhi","internal.mapPhi"],"sources":["../../src/vector/vector3.ts"],"sourcesContent":["import type { ThreeDimensional } from '../dimensions.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector3TypeId } from './vector3.internal.ts'\nimport * as internal from './vector3.internal.ts'\n\n/**\n * A 3D vector.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 1.0.0\n */\nexport interface Vector3 extends Pipeable, ThreeDimensional<number> {\n readonly [Vector3TypeId]: Vector3TypeId\n}\n\n/**\n * Checks if a value is a `Vector3`.\n *\n * @param v - The value to check.\n * @returns `true` if the value is a `Vector3`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isVector3: (v: unknown) => v is Vector3 = internal.isVector3\n\nexport const equals: {\n /**\n * Checks if two `Vector3` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns `true` when each pair of components is within tolerance.\n * @since 1.1.0\n */\n (a: Vector3, b: Vector3): boolean\n /**\n * Checks if two `Vector3` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the comparison result.\n * @since 1.1.0\n */\n (b: Vector3): (a: Vector3) => boolean\n} = internal.equals\n\nexport const make: {\n /**\n * Creates a new `Vector3` instance.\n *\n * @param xyz - The x, y, and z components of the vector.\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\n (xyz: number): Vector3\n /**\n * Creates a new `Vector3` instance.\n *\n * @param x - The x component of the vector.\n * @param yz - The y and z components of the vector.\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\n (x: number, yz: number): Vector3\n /**\n * Creates a new `Vector3` instance.\n *\n * @param x - The x component of the vector.\n * @param y - The y component of the vector.\n * @param z - The z component of the vector.\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\n (x: number, y: number, z: number): Vector3\n} = internal.make\n\n/**\n * Creates a new `Vector3` instance from a `[x, y, z]` tuple. Inverse of\n * {@link components}.\n *\n * @param t - The `[x, y, z]` tuple.\n * @returns A new `Vector3` instance.\n * @since 2.0.0\n */\nexport const fromTuple: (t: readonly [number, number, number]) => Vector3 = internal.fromTuple\n\n/**\n * Transposes a 3-tuple of items into one or more `Vector3`s, one per channel\n * extracted by the projection function. See {@link Vector4.transpose} for the\n * full operation description; this is the 3-component analog.\n *\n * @param inputs - Exactly three items of any type.\n * @param project - A function returning a fixed-arity tuple of numbers — one per output channel.\n * @returns A tuple of `Vector3`s with the same arity as the projection's return tuple.\n * @since 2.0.0\n */\nexport const transpose: <T, const Channels extends ReadonlyArray<number>>(\n inputs: readonly [T, T, T],\n project: (item: T) => Channels,\n) => { readonly [K in keyof Channels]: Vector3 } = internal.transpose\n\n/**\n * Creates a new `Vector3` instance from spherical coordinates.\n *\n * @param r - The radius.\n * @param theta - The polar angle, in radians. Ranges from 0 to π\n * @param phi - The azimuthal angle, in radians. Ranges from 0 to 2π\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\nexport const fromSpherical: (r: number, theta: number, phi: number) => Vector3 =\n internal.fromSpherical\n\n/**\n * Calculates the magnitude of a `Vector3`.\n *\n * @param vector - The vector to calculate the magnitude of.\n * @returns The magnitude of the vector.\n * @since 1.0.0\n */\nexport const magnitude: (vector: Vector3) => number = internal.magnitude\n\n/**\n * Calculates the length of a `Vector3`.\n *\n * @param vector - The vector to calculate the length of.\n * @returns The length of the vector.\n * @see {@link magnitude}\n * @since 1.0.0\n */\nexport const length: (vector: Vector3) => number = magnitude\n\n/**\n * Normalizes a `Vector3`.\n *\n * @param vector - The vector to normalize.\n * @returns A new `Vector3` instance with the same direction as the input vector, but with a magnitude of 1.\n * @since 1.0.0\n */\nexport const normalize: (vector: Vector3) => Vector3 = internal.normalize\n\nexport const dot: {\n /**\n * Calculates the dot product of two `Vector3` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns The dot product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): number\n /**\n * Calculates the dot product of two `Vector3` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the dot product.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => number\n} = internal.dot\n\nexport const cross: {\n /**\n * Calculates the cross product of two `Vector3` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector3` instance representing the cross product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Calculates the cross product of two `Vector3` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the cross product.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.cross\n\n/**\n * Returns the components of a `Vector3` as an array.\n *\n * @param v - The vector to get the components of.\n * @returns An array containing the x, y, and z components of the vector.\n * @since 1.0.0\n */\nexport const components: (v: Vector3) => [number, number, number] = internal.components\n\n/**\n * Calculates the softmax of a `Vector3`.\n *\n * @param v - The vector to calculate the softmax of.\n * @returns A new `Vector3` instance representing the softmax of the input vector.\n * @since 1.0.0\n */\nexport const softmax: (v: Vector3) => Vector3 = internal.softmax\n\n/**\n * Creates a zero vector.\n *\n * @since 1.0.0\n */\nexport const zero = make(0)\n\n/**\n * Creates a unit vector.\n *\n * @since 1.0.0\n */\nexport const unit = make(1)\n\n/**\n * Creates a unit vector in the x direction.\n *\n * @since 1.0.0\n */\nexport const unitX = make(1, 0, 0)\n\n/**\n * Creates a unit vector in the y direction.\n *\n * @since 1.0.0\n */\nexport const unitY = make(0, 1, 0)\n\n/**\n * Creates a unit vector in the z direction.\n *\n * @since 1.0.0\n */\nexport const unitZ = make(0, 0, 1)\n\nexport const add: {\n /**\n * Adds two `Vector3` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector3` instance representing the sum of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Adds two `Vector3` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the sum.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.add\n\nexport const subtract: {\n /**\n * Subtracts one `Vector3` instance from another.\n *\n * @param a - The vector to subtract from.\n * @param b - The vector to subtract.\n * @returns A new `Vector3` instance representing the difference of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Subtracts one `Vector3` instance from another.\n *\n * @param b - The vector to subtract.\n * @returns A function that takes the first vector and returns the difference.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.subtract\n\nexport const hadamard: {\n /**\n * Calculates the Hadamard product of two `Vector3` instances.\n *\n * The Hadamard product is an element-wise multiplication of two vectors.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector3` instance representing the Hadamard product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Calculates the Hadamard product of two `Vector3` instances.\n *\n * The Hadamard product is an element-wise multiplication of two vectors.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the Hadamard product.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.hadamard\n\nexport const scale: {\n /**\n * Scales a `Vector3` instance by a scalar value.\n *\n * @param s - The scalar value to scale by.\n * @return A function that takes a vector and returns the scaled vector.\n * @since 1.0.0\n */\n (s: number): (v: Vector3) => Vector3\n /**\n * Scales a `Vector3` instance by a scalar value.\n *\n * @param s - The scalar value to scale by.\n * @param v - The vector to scale.\n * @returns A new `Vector3` instance representing the scaled vector.\n * @since 1.0.0\n */\n (v: Vector3, s: number): Vector3\n} = internal.scale\n\n/**\n * Gets the x component of a `Vector3`.\n *\n * @param v - The vector to get the x component of.\n * @returns The x component of the vector.\n * @since 1.0.0\n */\nexport const getX: (v: Vector3) => number = internal.getX\n\nexport const setX: {\n /**\n * Sets the x component of a `Vector3`.\n *\n * @param v - The vector to set the x component of.\n * @param x - The new x component.\n * @returns A new `Vector3` instance with the updated x component.\n * @since 1.0.0\n */\n (v: Vector3, x: number): Vector3\n /**\n * Sets the x component of a `Vector3`.\n *\n * @param x - The new x component.\n * @returns A function that takes the vector and returns a new `Vector3` instance with the updated x component.\n * @since 1.0.0\n */\n (x: number): (v: Vector3) => Vector3\n} = internal.setX\n\nexport const mapX: {\n /**\n * Returns a new `Vector3` with the x component replaced by `f(v.x)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the x component.\n * @returns A new `Vector3` with the updated x.\n * @since 2.0.0\n */\n (v: Vector3, f: (x: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the x component replaced by `f(v.x)`.\n *\n * @param f - The function to apply to the x component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (x: number) => number): (v: Vector3) => Vector3\n} = internal.mapX\n\n/**\n * Gets the y component of a `Vector3`.\n *\n * @param v - The vector of which to get the y component.\n * @returns The y component of the vector.\n * @since 1.0.0\n */\nexport const getY: (v: Vector3) => number = internal.getY\n\nexport const setY: {\n /**\n * Sets the y component of a `Vector3`.\n *\n * @param v - The vector of which to set the y component.\n * @param y - The new y component.\n * @returns A new `Vector3` instance with the updated y component.\n * @since 1.0.0\n */\n (v: Vector3, y: number): Vector3\n /**\n * Sets the y component of a `Vector3`.\n *\n * @param y - The new y component.\n * @returns A function that takes the vector and returns a new `Vector3` instance with the updated y component.\n * @since 1.0.0\n */\n (y: number): (v: Vector3) => Vector3\n} = internal.setY\n\nexport const mapY: {\n /**\n * Returns a new `Vector3` with the y component replaced by `f(v.y)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the y component.\n * @returns A new `Vector3` with the updated y.\n * @since 2.0.0\n */\n (v: Vector3, f: (y: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the y component replaced by `f(v.y)`.\n *\n * @param f - The function to apply to the y component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (y: number) => number): (v: Vector3) => Vector3\n} = internal.mapY\n\n/**\n * Gets the z component of a `Vector3`.\n *\n * @param v - The vector of which to get the z component.\n * @returns The z component of the vector.\n * @since 1.0.0\n */\nexport const getZ: (v: Vector3) => number = internal.getZ\n\nexport const setZ: {\n /**\n * Sets the z component of a `Vector3`.\n *\n * @param v - The vector of which to set the z component.\n * @param z - The new z component.\n * @returns A new `Vector3` instance with the updated z component.\n * @since 1.0.0\n */\n (v: Vector3, z: number): Vector3\n /**\n * Sets the z component of a `Vector3`.\n *\n * @param z - The new z component.\n * @returns A function that takes the vector and returns a new `Vector3` instance with the updated z component.\n * @since 1.0.0\n */\n (z: number): (v: Vector3) => Vector3\n} = internal.setZ\n\nexport const mapZ: {\n /**\n * Returns a new `Vector3` with the z component replaced by `f(v.z)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the z component.\n * @returns A new `Vector3` with the updated z.\n * @since 2.0.0\n */\n (v: Vector3, f: (z: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the z component replaced by `f(v.z)`.\n *\n * @param f - The function to apply to the z component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (z: number) => number): (v: Vector3) => Vector3\n} = internal.mapZ\n\n/**\n * Gets the radius of a `Vector3`.\n *\n * @param v - The vector of which to get the radius.\n * @returns The radius of the vector.\n * @since 1.0.0\n */\nexport const getR: (v: Vector3) => number = magnitude\n\nexport const setR: {\n /**\n * Sets the radius of a `Vector3`.\n *\n * @param v - The vector of which to set the radius.\n * @param r - The new radius.\n * @returns A new `Vector3` instance with the updated radius.\n * @since 1.0.0\n */\n (v: Vector3, r: number): Vector3\n /**\n * Sets the radius of a `Vector3`.\n *\n * @param r - The new radius.\n * @returns A function that takes the vector and returns the updated vector.\n * @since 1.0.0\n */\n (r: number): (v: Vector3) => Vector3\n} = internal.setR\n\nexport const mapR: {\n /**\n * Returns a new `Vector3` with the radius replaced by `f(magnitude(v))`,\n * preserving direction.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the radius.\n * @returns A new `Vector3` with the updated radius.\n * @since 2.0.0\n */\n (v: Vector3, f: (r: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the radius replaced by `f(magnitude(v))`,\n * preserving direction.\n *\n * @param f - The function to apply to the radius.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (r: number) => number): (v: Vector3) => Vector3\n} = internal.mapR\n\n/**\n * Gets the polar angle (theta) of a `Vector3`.\n *\n * @param v - The vector of which to get the polar angle.\n * @returns The polar angle of the vector.\n * @since 1.0.0\n */\nexport const getTheta: (v: Vector3) => number = internal.getTheta\n\nexport const setTheta: {\n /**\n * Sets the polar angle (theta) of a `Vector3`.\n *\n * @param v - The vector of which to set the polar angle.\n * @param theta - The new polar angle.\n * @returns A new `Vector3` instance with the updated polar angle.\n * @since 1.0.0\n */\n (v: Vector3, theta: number): Vector3\n /**\n * Sets the polar angle (theta) of a `Vector3`.\n *\n * @param theta - The new polar angle.\n * @returns A function that takes the vector and returns the updated vector.\n * @since 1.0.0\n */\n (theta: number): (v: Vector3) => Vector3\n} = internal.setTheta\n\nexport const mapTheta: {\n /**\n * Returns a new `Vector3` with the polar angle replaced by\n * `f(getTheta(v))`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the polar angle (in radians).\n * @returns A new `Vector3` with the updated polar angle.\n * @since 2.0.0\n */\n (v: Vector3, f: (theta: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the polar angle replaced by\n * `f(getTheta(v))`.\n *\n * @param f - The function to apply to the polar angle (in radians).\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (theta: number) => number): (v: Vector3) => Vector3\n} = internal.mapTheta\n\n/**\n * Gets the azimuthal angle (phi) of a `Vector3`.\n *\n * @param v - The vector of which to get the azimuthal angle.\n * @returns The azimuthal angle of the vector.\n * @since 1.0.0\n */\nexport const getPhi: (v: Vector3) => number = internal.getPhi\n\nexport const setPhi: {\n /**\n * Sets the azimuthal angle (phi) of a `Vector3`.\n *\n * @param v - The vector of which to set the azimuthal angle.\n * @param phi - The new azimuthal angle.\n * @returns A new `Vector3` instance with the updated azimuthal angle.\n * @since 1.0.0\n */\n (v: Vector3, phi: number): Vector3\n /**\n * Sets the azimuthal angle (phi) of a `Vector3`.\n *\n * @param phi - The new azimuthal angle.\n * @returns A function that takes the vector and returns the updated vector.\n * @since 1.0.0\n */\n (phi: number): (v: Vector3) => Vector3\n} = internal.setPhi\n\nexport const mapPhi: {\n /**\n * Returns a new `Vector3` with the azimuthal angle replaced by\n * `f(getPhi(v))`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the azimuthal angle (in radians).\n * @returns A new `Vector3` with the updated azimuthal angle.\n * @since 2.0.0\n */\n (v: Vector3, f: (phi: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the azimuthal angle replaced by\n * `f(getPhi(v))`.\n *\n * @param f - The function to apply to the azimuthal angle (in radians).\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (phi: number) => number): (v: Vector3) => Vector3\n} = internal.mapPhi\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,YAA0CA;AAEvD,MAAa,SAoBTC;AAEJ,MAAa,OA4BTC;;;;;;;;;AAUJ,MAAa,YAA+DC;;;;;;;;;;;AAY5E,MAAa,YAGsCC;;;;;;;;;;AAWnD,MAAa,gBACXC;;;;;;;;AASF,MAAa,YAAyCC;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