curvy 2.0.0-alpha.11 → 2.0.0-alpha.13

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 (42) hide show
  1. package/dist/characteristic/index.mjs +1 -1
  2. package/dist/curve/index.mjs +1 -1
  3. package/dist/curve/rationalCubic2d.d.ts +195 -11
  4. package/dist/interval/index.mjs +1 -1
  5. package/dist/monotonicity/index.d.ts +4 -0
  6. package/dist/monotonicity/index.mjs +2 -0
  7. package/dist/monotonicity/monotonicity.d.ts +80 -0
  8. package/dist/path/index.mjs +16 -387
  9. package/dist/path/index.mjs.map +1 -1
  10. package/dist/path/rationalCubic2d.d.ts +27 -0
  11. package/dist/polynomial/cubic.d.ts +2 -2
  12. package/dist/polynomial/index.mjs +2 -2
  13. package/dist/polynomial/linear.d.ts +7 -7
  14. package/dist/polynomial/quadratic.d.ts +2 -2
  15. package/dist/shared/{characteristic-Hb7F8SBw.mjs → characteristic-BkEr-rr8.mjs} +2 -2
  16. package/dist/shared/{characteristic-Hb7F8SBw.mjs.map → characteristic-BkEr-rr8.mjs.map} +1 -1
  17. package/dist/shared/{cubic-DHJrzZJN.mjs → cubic-BL6dpuHh.mjs} +18 -30
  18. package/dist/shared/cubic-BL6dpuHh.mjs.map +1 -0
  19. package/dist/shared/{interval2d-DPmvk_Qe.mjs → interval2d-AtneyI45.mjs} +1 -1
  20. package/dist/shared/{interval2d-DPmvk_Qe.mjs.map → interval2d-AtneyI45.mjs.map} +1 -1
  21. package/dist/shared/monotonicity-BdebFOtv.mjs +34 -0
  22. package/dist/shared/monotonicity-BdebFOtv.mjs.map +1 -0
  23. package/dist/shared/{quadratic-BZmfZE71.mjs → quadratic-DPrUsFCp.mjs} +9 -9
  24. package/dist/shared/quadratic-DPrUsFCp.mjs.map +1 -0
  25. package/dist/shared/{rationalCubic2d-IroMR6AA.mjs → rationalCubic2d-CeHgpNht.mjs} +373 -79
  26. package/dist/shared/rationalCubic2d-CeHgpNht.mjs.map +1 -0
  27. package/dist/shared/{rationalCubic2d-nN-oSrLr.mjs → rationalCubic2d-H1J2Fjyy.mjs} +404 -23
  28. package/dist/shared/rationalCubic2d-H1J2Fjyy.mjs.map +1 -0
  29. package/dist/shared/{solution-B6KY1E7M.mjs → solution-B2JdOZpe.mjs} +1 -1
  30. package/dist/shared/{solution-B6KY1E7M.mjs.map → solution-B2JdOZpe.mjs.map} +1 -1
  31. package/dist/solution/index.mjs +1 -1
  32. package/dist/splines/index.d.ts +3 -0
  33. package/dist/splines/index.mjs +218 -120
  34. package/dist/splines/index.mjs.map +1 -1
  35. package/dist/splines/linear2d.d.ts +102 -0
  36. package/dist/splines/linear2d.internal.d.ts +2 -0
  37. package/package.json +5 -1
  38. package/dist/polynomial/monotonicity.d.ts +0 -3
  39. package/dist/shared/cubic-DHJrzZJN.mjs.map +0 -1
  40. package/dist/shared/quadratic-BZmfZE71.mjs.map +0 -1
  41. package/dist/shared/rationalCubic2d-IroMR6AA.mjs.map +0 -1
  42. package/dist/shared/rationalCubic2d-nN-oSrLr.mjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"cubic-DHJrzZJN.mjs","names":["equals","make","fromVector","fromPoints","solve","toSolver","solveInverse","Solution.none","Solution.one","toInverseSolver","monotonicity","isMonotonic","isIncreasing","isDecreasing","asMonotonic","asIncreasing","asDecreasing","coefficients","derivative","antiderivative","domain","Interval.make","Solution.isNone","range","Interval.fromMinMax","unitRange","length","Interval.size","fromPoints","make","equals","fromVector","solve","toSolver","solveInverse","Linear.solveInverse","Linear.make","Solution.none","Solution.one","Solution.two","toInverseSolver","coefficients","derivative","roots","Solution.match","Vector2.make","monotonicity","Interval.size","Linear.monotonicity","Interval.contains","Interval.toOpen","isMonotonic","isIncreasing","isDecreasing","asMonotonic","asIncreasing","asDecreasing","domain","Interval.fromMinMax","range","Linear.range","unitRange","Interval.unit","length","Linear.length","Linear.solve","curvature","make","isCubicPolynomial","equals","fromVector","fromPoints","solve","toSolver","solveInverse","Quadratic.solveInverse","Quadratic.make","Solution.fromArray","toInverseSolver","coefficients","derivative","subdivide","roots","extrema","Quadratic.roots","monotonicity","Interval.size","Linear.monotonicity","Linear.make","Quadratic.monotonicity","Interval.filter","Interval.toOpen","isMonotonic","isIncreasing","isDecreasing","asMonotonic","asIncreasing","asDecreasing","domain","Interval.fromMinMax","range","unitRange","Interval.unit","length","Linear.length","Quadratic.length","Interval.scaleShift","Interval.biunit","Quadratic.solve","curvature","Quadratic.derivative","Linear.solve","internal.isCubicPolynomial","internal.equals","internal.make","internal.fromVector","internal.fromPoints","internal.solve","internal.toSolver","internal.solveInverse","internal.toInverseSolver","internal.coefficients","internal.derivative","internal.subdivide","internal.roots","internal.extrema","internal.monotonicity","internal.isMonotonic","internal.isIncreasing","internal.isDecreasing","internal.asMonotonic","internal.asIncreasing","internal.asDecreasing","internal.domain","internal.range","internal.unitRange","internal.length","internal.curvature"],"sources":["../../src/polynomial/quadratic.internal.circular.ts","../../src/polynomial/linear.internal.ts","../../src/polynomial/cubic.internal.circular.ts","../../src/polynomial/monotonicity.ts","../../src/polynomial/quadratic.internal.ts","../../src/length.ts","../../src/polynomial/cubic.internal.ts","../../src/polynomial/cubic.ts"],"sourcesContent":["import { Pipeable } from '../utils.ts'\nimport type { QuadraticPolynomial } from './quadratic.ts'\nimport { PolynomialTraits } from './traits.ts'\n\nexport const QuadraticPolynomialTypeId: unique symbol = Symbol.for('curvy/polynomial/quadratic')\nexport type QuadraticPolynomialTypeId = typeof QuadraticPolynomialTypeId\n\n/** @internal */\nexport class QuadraticPolynomialImpl extends Pipeable implements QuadraticPolynomial<unknown> {\n readonly [QuadraticPolynomialTypeId]: QuadraticPolynomialTypeId = QuadraticPolynomialTypeId\n declare readonly [PolynomialTraits]: unknown\n\n readonly c0: number\n readonly c1: number\n readonly c2: number\n\n constructor(c0 = 0, c1 = 0, c2 = 0) {\n super()\n\n this.c0 = c0\n this.c1 = c1\n this.c2 = c2\n }\n}\n","import * as Interval from '../interval/interval.ts'\nimport { dual, Pipeable } from '../utils.ts'\nimport * as Solution from '../solution/solution.ts'\nimport { invariant } from '../utils.ts'\nimport { epsEquals } from '../number.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport type { LinearPolynomial } from './linear.ts'\nimport type { Decreasing, Increasing, Monotonic } from './traits.ts'\nimport { PolynomialTraits } from './traits.ts'\nimport type { QuadraticPolynomial } from './quadratic.ts'\nimport { QuadraticPolynomialImpl } from './quadratic.internal.circular.ts'\n\nexport const LinearPolynomialTypeId: unique symbol = Symbol.for('curvy/linear')\nexport type LinearPolynomialTypeId = typeof LinearPolynomialTypeId\n\nclass LinearPolynomialImpl extends Pipeable implements LinearPolynomial<unknown> {\n readonly [LinearPolynomialTypeId]: LinearPolynomialTypeId = LinearPolynomialTypeId\n declare readonly [PolynomialTraits]: unknown\n\n readonly c0: number\n readonly c1: number\n\n constructor(c0 = 0, c1 = 0) {\n super()\n\n this.c0 = c0\n this.c1 = c1\n }\n}\n\n/** @internal */\nexport const isLinearPolynomial = (v: unknown): v is LinearPolynomial =>\n typeof v === 'object' && v !== null && LinearPolynomialTypeId in v\n\n/** @internal */\nexport const equals = dual<\n (b: LinearPolynomial) => (a: LinearPolynomial) => boolean,\n (a: LinearPolynomial, b: LinearPolynomial) => boolean\n>(2, (a: LinearPolynomial, b: LinearPolynomial) => epsEquals(a.c0, b.c0) && epsEquals(a.c1, b.c1))\n\n/** @internal */\nexport const make = (c0 = 0, c1 = 0): LinearPolynomial => new LinearPolynomialImpl(c0, c1)\n\n/** @internal */\nexport const fromVector = (v: Vector2) => new LinearPolynomialImpl(v.x, v.y)\n\n/** @internal */\nexport const fromPointSlope = (p: Vector2, slope: number) =>\n new LinearPolynomialImpl(p.y - slope * p.x, slope)\n\n/** @internal */\nexport const fromPoints = (p1: Vector2, p2: Vector2) =>\n fromPointSlope(p1, (p2.y - p1.y) / (p2.x - p1.x))\n\n/** @internal */\nexport const solve = dual<\n (x: number) => (p: LinearPolynomial) => number,\n (p: LinearPolynomial, x: number) => number\n>(2, (p: LinearPolynomial, x: number) => p.c0 + x * p.c1)\n\n/** @internal */\nexport const toSolver = (p: LinearPolynomial) => (x: number) => solve(p, x)\n\n/** @internal */\nexport const solveInverse = dual<\n (y: number) => (p: LinearPolynomial) => Solution.AtMostOne<number>,\n (p: LinearPolynomial, y: number) => Solution.AtMostOne<number>\n>(2, (p: LinearPolynomial, y: number) => {\n if (p.c1 === 0) {\n return Solution.none\n }\n return Solution.one((y - p.c0) / p.c1)\n})\n\n/** @internal */\nexport const toInverseSolver = (p: LinearPolynomial) => (y: number) => solveInverse(p, y)\n\n/** @internal */\nexport const monotonicity = (p: LinearPolynomial) =>\n p.c1 === 0 ? 'constant' : p.c1 > 0 ? 'increasing' : 'decreasing'\n\n/** @internal */\nexport const isMonotonic = <T>(p: LinearPolynomial<T>): p is LinearPolynomial<T & Monotonic> =>\n p.c1 !== 0\n\n/** @internal */\nexport const isIncreasing = <T>(p: LinearPolynomial<T>): p is LinearPolynomial<T & Increasing> =>\n p.c1 > 0\n\n/** @internal */\nexport const isDecreasing = <T>(p: LinearPolynomial<T>): p is LinearPolynomial<T & Decreasing> =>\n p.c1 < 0\n\n/** @internal */\nexport const asMonotonic = <T>(p: LinearPolynomial<T>): LinearPolynomial<T & Monotonic> => {\n invariant(isMonotonic(p), 'linear polynomial is not monotonic')\n return p\n}\n\n/** @internal */\nexport const asIncreasing = <T>(p: LinearPolynomial<T>): LinearPolynomial<T & Increasing> => {\n invariant(isIncreasing(p), 'linear polynomial is not increasing')\n return p\n}\n\n/** @internal */\nexport const asDecreasing = <T>(p: LinearPolynomial<T>): LinearPolynomial<T & Decreasing> => {\n invariant(isDecreasing(p), 'linear polynomial is not decreasing')\n return p\n}\n\n/** @internal */\nexport const coefficients = (p: LinearPolynomial): readonly [number, number] => [p.c0, p.c1]\n\n/** @internal */\nexport const derivative = (p: LinearPolynomial) => p.c1\n\n/** @internal */\nexport const antiderivative = dual<\n (integrationConstant: number) => (p: LinearPolynomial) => QuadraticPolynomial,\n (p: LinearPolynomial, integrationConstant?: number) => QuadraticPolynomial\n>(\n (args) => isLinearPolynomial(args[0]),\n (p: LinearPolynomial, integrationConstant = 0) =>\n new QuadraticPolynomialImpl(integrationConstant, p.c0, p.c1 / 2),\n)\n\n/** @internal */\nexport const domain = dual<\n (range: Interval.Interval) => (p: LinearPolynomial) => Solution.AtMostOne<Interval.Interval>,\n (p: LinearPolynomial, range: Interval.Interval) => Solution.AtMostOne<Interval.Interval>\n>(2, (p: LinearPolynomial, r: Interval.Interval) => {\n if (p.c1 === 0) {\n if (r.start === p.c0 && r.end === p.c0) {\n return Solution.one(Interval.make(Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY))\n }\n return Solution.none\n }\n\n const start = solveInverse(p, r.start)\n const end = solveInverse(p, r.end)\n\n if (Solution.isNone(start) || Solution.isNone(end)) {\n return Solution.none\n }\n\n return Solution.one(Interval.make(start.value, end.value))\n})\n\n/** @internal */\nexport const range = dual<\n (domain: Interval.Interval) => (p: LinearPolynomial) => Interval.Closed,\n (p: LinearPolynomial, domain: Interval.Interval) => Interval.Closed\n>(2, (p: LinearPolynomial, d: Interval.Interval) =>\n Interval.fromMinMax(solve(p, d.start), solve(p, d.end)),\n)\n\n/** @internal */\nexport const unitRange = (p: LinearPolynomial): Interval.Closed =>\n Interval.fromMinMax(p.c0, p.c0 + p.c1)\n\n/** @internal */\nexport const length = dual<\n (domain: Interval.Interval) => (p: LinearPolynomial) => number,\n (p: LinearPolynomial, domain: Interval.Interval) => number\n>(2, (p: LinearPolynomial, d: Interval.Interval) => {\n if (Interval.size(d) === 0) {\n return 0\n }\n\n if (p.c1 === 0) {\n return Interval.size(d)\n }\n\n return Math.sqrt(1 + p.c1 ** 2) * Interval.size(d)\n})\n","import { Pipeable } from '../utils.ts'\nimport type { CubicPolynomial } from './cubic.ts'\nimport { PolynomialTraits } from './traits.ts'\n\nexport const CubicPolynomialTypeId: unique symbol = Symbol.for('curvy/polynomial/cubic')\nexport type CubicPolynomialTypeId = typeof CubicPolynomialTypeId\n\n/** @internal */\nexport class CubicPolynomialImpl extends Pipeable implements CubicPolynomial<unknown> {\n readonly [CubicPolynomialTypeId]: CubicPolynomialTypeId = CubicPolynomialTypeId\n declare readonly [PolynomialTraits]: unknown\n\n readonly c0: number\n readonly c1: number\n readonly c2: number\n readonly c3: number\n\n constructor(c0 = 0, c1 = 0, c2 = 0, c3 = 0) {\n super()\n\n this.c0 = c0\n this.c1 = c1\n this.c2 = c2\n this.c3 = c3\n }\n}\n","export type Monotonicity = 'none' | 'increasing' | 'decreasing' | 'constant'\nexport type GuaranteedMonotonicity = 'increasing' | 'decreasing' | 'constant'\n\nexport function guaranteedMonotonicityFromComparison(\n s0: number,\n s1: number,\n): GuaranteedMonotonicity {\n if (s0 < s1) {\n return 'increasing'\n }\n\n if (s0 > s1) {\n return 'decreasing'\n }\n\n return 'constant'\n}\n","import * as Interval from '../interval/interval.ts'\nimport { dual } from '../utils.ts'\nimport * as Solution from '../solution/solution.ts'\nimport { invariant } from '../utils.ts'\nimport { epsEquals } from '../number.ts'\nimport * as Vector2 from '../vector/vector2.ts'\nimport type { Vector3 } from '../vector/vector3.ts'\nimport type { CubicPolynomial } from './cubic.ts'\nimport { CubicPolynomialImpl } from './cubic.internal.circular.ts'\nimport * as Linear from './linear.internal.ts'\nimport { guaranteedMonotonicityFromComparison, type Monotonicity } from './monotonicity.ts'\nimport type { QuadraticPolynomial } from './quadratic.ts'\nimport {\n QuadraticPolynomialImpl,\n QuadraticPolynomialTypeId,\n} from './quadratic.internal.circular.ts'\nimport type { Decreasing, Increasing, Monotonic } from './traits.ts'\n\n/** @internal */\nexport const fromPoints = (\n p0: Vector2.Vector2,\n p1: Vector2.Vector2,\n p2: Vector2.Vector2,\n): QuadraticPolynomial => {\n // Newton's divided differences, then collected to monomial form.\n const f01 = (p1.y - p0.y) / (p1.x - p0.x)\n const f12 = (p2.y - p1.y) / (p2.x - p1.x)\n const f012 = (f12 - f01) / (p2.x - p0.x)\n\n return new QuadraticPolynomialImpl(\n p0.y - f01 * p0.x + f012 * p0.x * p1.x,\n f01 - f012 * (p0.x + p1.x),\n f012,\n )\n}\n\n/** @internal */\nexport const make = (c0 = 0, c1 = 0, c2 = 0): QuadraticPolynomial =>\n new QuadraticPolynomialImpl(c0, c1, c2)\n\n/** @internal */\nexport const isQuadraticPolynomial = (v: unknown): v is QuadraticPolynomial =>\n typeof v === 'object' && v !== null && QuadraticPolynomialTypeId in v\n\n/** @internal */\nexport const equals = dual<\n (b: QuadraticPolynomial) => (a: QuadraticPolynomial) => boolean,\n (a: QuadraticPolynomial, b: QuadraticPolynomial) => boolean\n>(\n 2,\n (a: QuadraticPolynomial, b: QuadraticPolynomial) =>\n epsEquals(a.c0, b.c0) && epsEquals(a.c1, b.c1) && epsEquals(a.c2, b.c2),\n)\n\n/** @internal */\nexport const fromVector = (v: Vector3) => new QuadraticPolynomialImpl(v.x, v.y, v.z)\n\n/** @internal */\nexport const solve = dual<\n (x: number) => (p: QuadraticPolynomial) => number,\n (p: QuadraticPolynomial, x: number) => number\n>(2, (p: QuadraticPolynomial, x: number) => p.c0 + x * p.c1 + x ** 2 * p.c2)\n\n/** @internal */\nexport const toSolver = (p: QuadraticPolynomial) => (x: number) => solve(p, x)\n\n/** @internal */\nexport const solveInverse: {\n (p: QuadraticPolynomial, y: number): Solution.AtMostTwo<number>\n (y: number): (p: QuadraticPolynomial) => Solution.AtMostTwo<number>\n} = dual<\n (y: number) => (p: QuadraticPolynomial) => Solution.AtMostTwo<number>,\n (p: QuadraticPolynomial, y: number) => Solution.AtMostTwo<number>\n>(2, (p: QuadraticPolynomial, y: number) => {\n // c2 = 0: the polynomial is actually linear in disguise. Defer rather than\n // dividing by zero in the quadratic formula.\n if (p.c2 === 0) {\n return Linear.solveInverse(Linear.make(p.c0, p.c1), y)\n }\n\n const discriminant = p.c1 ** 2 - 4 * p.c2 * (p.c0 - y)\n\n if (discriminant < 0) {\n return Solution.none\n }\n\n if (discriminant === 0) {\n return Solution.one(-p.c1 / (2 * p.c2))\n }\n\n const sqrtDiscriminant = Math.sqrt(discriminant)\n const a = (-p.c1 + sqrtDiscriminant) / (2 * p.c2)\n const b = (-p.c1 - sqrtDiscriminant) / (2 * p.c2)\n return a < b ? Solution.two(a, b) : Solution.two(b, a)\n})\n\n/** @internal */\nexport const toInverseSolver =\n (p: QuadraticPolynomial) =>\n (y: number): Solution.AtMostTwo<number> =>\n solveInverse(p, y)\n\n/** @internal */\nexport const coefficients = (p: QuadraticPolynomial): readonly [number, number, number] => [\n p.c0,\n p.c1,\n p.c2,\n]\n\n/** @internal */\nexport const derivative = (p: QuadraticPolynomial) => Linear.make(p.c1, p.c2 * 2)\n\n/** @internal */\nexport const roots = (p: QuadraticPolynomial) => solveInverse(p, 0)\n\n/** @internal */\nexport const extreme = (p: QuadraticPolynomial) =>\n derivative(p).pipe(\n Linear.solveInverse(0),\n Solution.match({\n onNone: () => null,\n onSome: ({ value: t }) => Vector2.make(t, solve(p, t)),\n }),\n )\n\n/** @internal */\nexport const monotonicity = dual<\n (i: Interval.Interval) => (p: QuadraticPolynomial) => Monotonicity,\n (p: QuadraticPolynomial, i?: Interval.Interval) => Monotonicity\n>(\n (args) => isQuadraticPolynomial(args[0]),\n (p: QuadraticPolynomial, i?: Interval.Interval) => {\n invariant(\n i === undefined || Interval.size(i) > 0,\n 'monotonicity is undefined over a zero-width interval',\n )\n\n if (p.c2 === 0 && p.c1 === 0) {\n return 'constant'\n }\n\n if (p.c2 === 0) {\n return Linear.monotonicity(Linear.make(p.c0, p.c1))\n }\n\n // c2 is non-zero, so the extreme is guaranteed to be non-null\n const e = extreme(p) as Vector2.Vector2\n\n // if there is no interval, or the extreme is within the interval,\n // the monotonicity is none\n if (i === undefined || Interval.contains(Interval.toOpen(i), e.x)) {\n return 'none'\n }\n\n return guaranteedMonotonicityFromComparison(solve(p, i.start), solve(p, i.end))\n },\n)\n\n/** @internal */\nexport const isMonotonic = dual<\n (\n i: Interval.Interval,\n ) => <T>(p: QuadraticPolynomial<T>) => p is QuadraticPolynomial<T & Monotonic>,\n <T>(p: QuadraticPolynomial<T>, i?: Interval.Interval) => p is QuadraticPolynomial<T & Monotonic>\n>((args) => isQuadraticPolynomial(args[0]), ((p: QuadraticPolynomial, i?: Interval.Interval) => {\n const m = monotonicity(p, i as Interval.Interval)\n return m === 'increasing' || m === 'decreasing'\n}) as never)\n\n/** @internal */\nexport const isIncreasing = dual<\n (\n i: Interval.Interval,\n ) => <T>(p: QuadraticPolynomial<T>) => p is QuadraticPolynomial<T & Increasing>,\n <T>(p: QuadraticPolynomial<T>, i?: Interval.Interval) => p is QuadraticPolynomial<T & Increasing>\n>(\n (args) => isQuadraticPolynomial(args[0]),\n ((p: QuadraticPolynomial, i?: Interval.Interval) =>\n monotonicity(p, i as Interval.Interval) === 'increasing') as never,\n)\n\n/** @internal */\nexport const isDecreasing = dual<\n (\n i: Interval.Interval,\n ) => <T>(p: QuadraticPolynomial<T>) => p is QuadraticPolynomial<T & Decreasing>,\n <T>(p: QuadraticPolynomial<T>, i?: Interval.Interval) => p is QuadraticPolynomial<T & Decreasing>\n>(\n (args) => isQuadraticPolynomial(args[0]),\n ((p: QuadraticPolynomial, i?: Interval.Interval) =>\n monotonicity(p, i as Interval.Interval) === 'decreasing') as never,\n)\n\n/** @internal */\nexport const asMonotonic = <T>(\n p: QuadraticPolynomial<T>,\n i?: Interval.Interval,\n): QuadraticPolynomial<T & Monotonic> => {\n invariant(isMonotonic(p, i as Interval.Interval), 'quadratic polynomial is not monotonic')\n return p\n}\n\n/** @internal */\nexport const asIncreasing = <T>(\n p: QuadraticPolynomial<T>,\n i?: Interval.Interval,\n): QuadraticPolynomial<T & Increasing> => {\n invariant(isIncreasing(p, i as Interval.Interval), 'quadratic polynomial is not increasing')\n return p\n}\n\n/** @internal */\nexport const asDecreasing = <T>(\n p: QuadraticPolynomial<T>,\n i?: Interval.Interval,\n): QuadraticPolynomial<T & Decreasing> => {\n invariant(isDecreasing(p, i as Interval.Interval), 'quadratic polynomial is not decreasing')\n return p\n}\n\n/** @internal */\nexport const antiderivative = dual<\n (integrationConstant: number) => (p: QuadraticPolynomial) => CubicPolynomial,\n (p: QuadraticPolynomial, integrationConstant?: number) => CubicPolynomial\n>(\n 2,\n (p: QuadraticPolynomial, integrationConstant = 0) =>\n new CubicPolynomialImpl(integrationConstant, p.c0, p.c1 / 2, p.c2 / 3),\n)\n\n/** @internal */\nexport const domain = dual<\n (range: Interval.Interval) => (p: QuadraticPolynomial) => Solution.AtMostOne<Interval.Interval>,\n (p: QuadraticPolynomial, range: Interval.Interval) => Solution.AtMostOne<Interval.Interval>\n>(2, (p: QuadraticPolynomial, r: Interval.Interval) => {\n const start = solveInverse(p, r.start)\n const end = solveInverse(p, r.end)\n\n if (start.length === 0 && end.length === 0) {\n return Solution.none\n }\n\n return Solution.one(Interval.fromMinMax(...start, ...end))\n})\n\n/** @internal */\nexport const range = dual<\n (domain: Interval.Interval) => (p: QuadraticPolynomial) => Interval.Closed,\n (p: QuadraticPolynomial, domain: Interval.Interval) => Interval.Closed\n>(2, (p: QuadraticPolynomial, d: Interval.Interval) => {\n if (p.c2 === 0) {\n return Linear.range(Linear.make(p.c0, p.c1), d)\n }\n\n const e = extreme(p)\n\n return e !== null && Interval.contains(d, e.x)\n ? Interval.fromMinMax(solve(p, d.start), solve(p, d.end), e.y)\n : Interval.fromMinMax(solve(p, d.start), solve(p, d.end))\n})\n\n/** @internal */\nexport const unitRange = (p: QuadraticPolynomial): Interval.Closed => range(p, Interval.unit)\n\n/** @internal */\nexport const length = dual<\n (domain: Interval.Interval) => (p: QuadraticPolynomial) => number,\n (p: QuadraticPolynomial, domain: Interval.Interval) => number\n>(2, (p: QuadraticPolynomial, dom: Interval.Interval) => {\n if (Interval.size(dom) === 0) {\n return 0\n }\n\n if (p.c2 === 0) {\n return Linear.length(Linear.make(p.c0, p.c1), dom)\n }\n\n const dp = derivative(p)\n\n const derivativeStart = Linear.solve(dp, dom.start)\n const sqrtStart = Math.sqrt(1 + derivativeStart ** 2)\n const evalStart =\n (derivativeStart * sqrtStart + Math.log(Math.abs(derivativeStart + sqrtStart))) / (4 * p.c2)\n\n const derivativeEnd = Linear.solve(dp, dom.end)\n const sqrtEnd = Math.sqrt(1 + derivativeEnd ** 2)\n const evalEnd =\n (derivativeEnd * sqrtEnd + Math.log(Math.abs(derivativeEnd + sqrtEnd))) / (4 * p.c2)\n\n return evalEnd - evalStart\n})\n\n/** @internal */\nexport const curvature = dual<\n (x: number) => (p: QuadraticPolynomial) => number,\n (p: QuadraticPolynomial, x: number) => number\n>(\n 2,\n (p: QuadraticPolynomial, x: number) =>\n Math.abs(2 * p.c2) / (1 + (Linear.solve(derivative(p), x) ** 2) ** 1.5),\n)\n","export const GL32_X0 = 0.9972638618494816\nexport const GL32_X1 = 0.9856115115452684\nexport const GL32_X2 = 0.9647622555875064\nexport const GL32_X3 = 0.9349060759377397\nexport const GL32_X4 = 0.8963211557660521\nexport const GL32_X5 = 0.84936761373257\nexport const GL32_X6 = 0.7944837959679424\nexport const GL32_X7 = 0.7321821187402897\nexport const GL32_X8 = 0.6630442669302152\nexport const GL32_X9 = 0.5877157572407623\nexport const GL32_X10 = 0.5068999089322294\nexport const GL32_X11 = 0.42135127613063533\nexport const GL32_X12 = 0.33186860228212767\nexport const GL32_X13 = 0.23928736225213706\nexport const GL32_X14 = 0.1444719615827965\nexport const GL32_X15 = 0.04830766568773831\nexport const GL32_W0 = 0.007018610009470136\nexport const GL32_W1 = 0.01627439473090571\nexport const GL32_W2 = 0.02539206530926214\nexport const GL32_W3 = 0.03427386291302141\nexport const GL32_W4 = 0.042835898022226704\nexport const GL32_W5 = 0.050998059262376154\nexport const GL32_W6 = 0.05868409347853558\nexport const GL32_W7 = 0.06582222277636195\nexport const GL32_W8 = 0.07234579410884862\nexport const GL32_W9 = 0.07819389578707044\nexport const GL32_W10 = 0.08331192422694672\nexport const GL32_W11 = 0.08765209300440374\nexport const GL32_W12 = 0.0911738786957639\nexport const GL32_W13 = 0.09384439908080454\nexport const GL32_W14 = 0.09563872007927485\nexport const GL32_W15 = 0.09654008851472785\n","import * as Interval from '../interval/interval.ts'\nimport {\n GL32_W0,\n GL32_W1,\n GL32_W2,\n GL32_W3,\n GL32_W4,\n GL32_W5,\n GL32_W6,\n GL32_W7,\n GL32_W8,\n GL32_W9,\n GL32_W10,\n GL32_W11,\n GL32_W12,\n GL32_W13,\n GL32_W14,\n GL32_W15,\n GL32_X0,\n GL32_X1,\n GL32_X2,\n GL32_X3,\n GL32_X4,\n GL32_X5,\n GL32_X6,\n GL32_X7,\n GL32_X8,\n GL32_X9,\n GL32_X10,\n GL32_X11,\n GL32_X12,\n GL32_X13,\n GL32_X14,\n GL32_X15,\n} from '../length.ts'\nimport { dual } from '../utils.ts'\nimport * as Solution from '../solution/solution.ts'\nimport { invariant } from '../utils.ts'\nimport { clampToZero, epsEquals } from '../number.ts'\nimport type * as Vector2 from '../vector/vector2.ts'\nimport type { Vector4 } from '../vector/vector4.ts'\nimport type { CubicPolynomial } from './cubic.ts'\nimport { CubicPolynomialImpl, CubicPolynomialTypeId } from './cubic.internal.circular.ts'\nimport type { Decreasing, Increasing, Monotonic } from './traits.ts'\nimport * as Linear from './linear.internal.ts'\nimport { guaranteedMonotonicityFromComparison, type Monotonicity } from './monotonicity.ts'\nimport * as Quadratic from './quadratic.internal.ts'\n\n/** @internal */\nexport const make = (c0 = 0, c1 = 0, c2 = 0, c3 = 0): CubicPolynomial =>\n new CubicPolynomialImpl(c0, c1, c2, c3)\n\n/** @internal */\nexport const isCubicPolynomial = (v: unknown): v is CubicPolynomial =>\n typeof v === 'object' && v !== null && CubicPolynomialTypeId in v\n\n/** @internal */\nexport const equals = dual<\n (b: CubicPolynomial) => (a: CubicPolynomial) => boolean,\n (a: CubicPolynomial, b: CubicPolynomial) => boolean\n>(\n 2,\n (a: CubicPolynomial, b: CubicPolynomial) =>\n epsEquals(a.c0, b.c0) &&\n epsEquals(a.c1, b.c1) &&\n epsEquals(a.c2, b.c2) &&\n epsEquals(a.c3, b.c3),\n)\n\n/** @internal */\nexport const fromVector = (v: Vector4) => new CubicPolynomialImpl(v.x, v.y, v.z, v.w)\n\n/** @internal */\nexport const fromPoints = (\n p0: Vector2.Vector2,\n p1: Vector2.Vector2,\n p2: Vector2.Vector2,\n p3: Vector2.Vector2,\n): CubicPolynomial => {\n // Newton's divided differences, then collected to monomial form.\n const f01 = (p1.y - p0.y) / (p1.x - p0.x)\n const f12 = (p2.y - p1.y) / (p2.x - p1.x)\n const f23 = (p3.y - p2.y) / (p3.x - p2.x)\n const f012 = (f12 - f01) / (p2.x - p0.x)\n const f123 = (f23 - f12) / (p3.x - p1.x)\n const f0123 = (f123 - f012) / (p3.x - p0.x)\n\n return new CubicPolynomialImpl(\n p0.y - f01 * p0.x + f012 * p0.x * p1.x - f0123 * p0.x * p1.x * p2.x,\n f01 - f012 * (p0.x + p1.x) + f0123 * (p0.x * p1.x + p0.x * p2.x + p1.x * p2.x),\n f012 - f0123 * (p0.x + p1.x + p2.x),\n f0123,\n )\n}\n\n/** @internal */\nexport const solve = dual<\n (x: number) => (p: CubicPolynomial) => number,\n (p: CubicPolynomial, x: number) => number\n>(2, (p: CubicPolynomial, x: number) => p.c0 + x * p.c1 + x ** 2 * p.c2 + x ** 3 * p.c3)\n\n/** @internal */\nexport const toSolver = (p: CubicPolynomial) => (x: number) => solve(p, x)\n\n/** @internal */\nexport const solveInverse = dual<\n (y: number) => (p: CubicPolynomial) => Solution.AtMostThree<number>,\n (p: CubicPolynomial, y: number) => Solution.AtMostThree<number>\n>(2, (self: CubicPolynomial, y: number) => {\n // c3 = 0: the polynomial is actually quadratic-or-less in disguise. Defer to\n // the quadratic solver (which itself handles c2 = 0 by deferring to linear).\n if (self.c3 === 0) {\n return Quadratic.solveInverse(Quadratic.make(self.c0, self.c1, self.c2), y)\n }\n\n const shift = self.c2 / (3 * self.c3)\n\n const d0 = self.c2 ** 2 - 3 * self.c3 * self.c1\n const d1 = 2 * self.c2 ** 3 - 9 * self.c3 * self.c2 * self.c1 + 27 * self.c3 ** 2 * (self.c0 - y)\n\n const p = -d0 / (3 * self.c3 ** 2)\n const q = d1 / (27 * self.c3 ** 3)\n\n const discriminant = clampToZero(-(4 * p ** 3 + 27 * q ** 2), 1e-12)\n\n const roots = new Set<number>()\n\n if (discriminant > 0) {\n const r = 2 * Math.sqrt(-p / 3)\n const theta = Math.acos(((3 * q) / (2 * p)) * Math.sqrt(-3 / p)) / 3\n const offset = (2 * Math.PI) / 3\n\n roots.add(r * Math.cos(theta + offset) - shift)\n roots.add(r * Math.cos(theta) - shift)\n roots.add(r * Math.cos(theta - offset) - shift)\n } else if (discriminant < 0) {\n const u = Math.sqrt(q ** 2 / 4 + p ** 3 / 27)\n\n const u1 = Math.cbrt(-q / 2 + u)\n const u2 = Math.cbrt(-q / 2 - u)\n\n roots.add(u1 + u2 - shift)\n } else if (d0 === 0) {\n roots.add(-shift)\n } else {\n roots.add((9 * self.c3 * (self.c0 - y) - self.c2 * self.c1) / (2 * d0))\n roots.add(\n (4 * self.c3 * self.c2 * self.c1 - 9 * self.c3 ** 2 * (self.c0 - y) - self.c2 ** 3) /\n (self.c3 * d0),\n )\n }\n\n return Solution.fromArray(Array.from(roots).toSorted((a, b) => a - b))\n})\n\n/** @internal */\nexport const toInverseSolver = (p: CubicPolynomial) => (y: number) => solveInverse(p, y)\n\n/** @internal */\nexport const coefficients = (p: CubicPolynomial): readonly [number, number, number, number] => [\n p.c0,\n p.c1,\n p.c2,\n p.c3,\n]\n\n/** @internal */\nexport const derivative = (p: CubicPolynomial) => Quadratic.make(p.c1, p.c2 * 2, p.c3 * 3)\n\n// Subdivides a cubic polynomial at parameter `t ∈ (0, 1)` into two new cubic\n// polynomials. The first polynomial's evaluation on `[0, 1]` matches the\n// original's evaluation on `[0, t]`; the second matches the original's\n// evaluation on `[t, 1]`. Concretely: `left(u) = p(t·u)` and\n// `right(u) = p(t + (1-t)·u)`. The left half is a uniform scale of the input\n// parameter by powers of `t`; the right half is a binomial expansion in\n// `(s + r·u)` with `s = t` and `r = 1 - t`.\n/** @internal */\nexport const subdivide = dual<\n (t: number) => (p: CubicPolynomial) => [CubicPolynomial, CubicPolynomial],\n (p: CubicPolynomial, t: number) => [CubicPolynomial, CubicPolynomial]\n>(2, (p: CubicPolynomial, t: number): [CubicPolynomial, CubicPolynomial] => {\n invariant(t > 0 && t < 1, 'subdivide parameter t must be in the open interval (0, 1)')\n\n const r = 1 - t\n const left = make(p.c0, p.c1 * t, p.c2 * t * t, p.c3 * t * t * t)\n const right = make(\n p.c0 + p.c1 * t + p.c2 * t * t + p.c3 * t * t * t,\n p.c1 * r + 2 * p.c2 * t * r + 3 * p.c3 * t * t * r,\n p.c2 * r * r + 3 * p.c3 * t * r * r,\n p.c3 * r * r * r,\n )\n return [left, right]\n})\n\n/** @internal */\nexport const roots = (p: CubicPolynomial): Solution.AtMostThree<number> => solveInverse(p, 0)\n\n/** @internal */\nexport const extrema = (p: CubicPolynomial): Solution.AtMostTwo<number> =>\n Quadratic.roots(derivative(p))\n\n/** @internal */\nexport const monotonicity = dual<\n (i: Interval.Interval) => (p: CubicPolynomial) => Monotonicity,\n (p: CubicPolynomial, i?: Interval.Interval) => Monotonicity\n>(\n (args) => isCubicPolynomial(args[0]),\n (p: CubicPolynomial, i?: Interval.Interval) => {\n invariant(\n i === undefined || Interval.size(i) > 0,\n 'monotonicity is undefined over a zero-width interval',\n )\n\n // shortcut to check for a horizontal line\n if (p.c3 === 0 && p.c2 === 0 && p.c1 === 0) {\n return 'constant'\n }\n\n // shortcut to check for a non-horizontal line\n if (p.c3 === 0 && p.c2 === 0) {\n return Linear.monotonicity(Linear.make(p.c0, p.c1))\n }\n\n // without an interval, the monotonicity will be none if c3 or c2 are nonzero\n if (i === undefined) {\n return 'none'\n }\n\n if (p.c3 === 0) {\n return Quadratic.monotonicity(Quadratic.make(p.c0, p.c1, p.c2), i)\n }\n\n const e = Interval.filter(Interval.toOpen(i), [...extrema(p)])\n\n if (e.length > 0) {\n return 'none'\n }\n\n return guaranteedMonotonicityFromComparison(solve(p, i.start), solve(p, i.end))\n },\n)\n\n/** @internal */\nexport const isMonotonic = dual<\n (i: Interval.Interval) => <T>(p: CubicPolynomial<T>) => p is CubicPolynomial<T & Monotonic>,\n <T>(p: CubicPolynomial<T>, i?: Interval.Interval) => p is CubicPolynomial<T & Monotonic>\n>((args) => isCubicPolynomial(args[0]), ((p: CubicPolynomial, i?: Interval.Interval) => {\n const m = monotonicity(p, i as Interval.Interval)\n return m === 'increasing' || m === 'decreasing'\n}) as never)\n\n/** @internal */\nexport const isIncreasing = dual<\n (i: Interval.Interval) => <T>(p: CubicPolynomial<T>) => p is CubicPolynomial<T & Increasing>,\n <T>(p: CubicPolynomial<T>, i?: Interval.Interval) => p is CubicPolynomial<T & Increasing>\n>(\n (args) => isCubicPolynomial(args[0]),\n ((p: CubicPolynomial, i?: Interval.Interval) =>\n monotonicity(p, i as Interval.Interval) === 'increasing') as never,\n)\n\n/** @internal */\nexport const isDecreasing = dual<\n (i: Interval.Interval) => <T>(p: CubicPolynomial<T>) => p is CubicPolynomial<T & Decreasing>,\n <T>(p: CubicPolynomial<T>, i?: Interval.Interval) => p is CubicPolynomial<T & Decreasing>\n>(\n (args) => isCubicPolynomial(args[0]),\n ((p: CubicPolynomial, i?: Interval.Interval) =>\n monotonicity(p, i as Interval.Interval) === 'decreasing') as never,\n)\n\n/** @internal */\nexport const asMonotonic = <T>(\n p: CubicPolynomial<T>,\n i?: Interval.Interval,\n): CubicPolynomial<T & Monotonic> => {\n invariant(isMonotonic(p, i as Interval.Interval), 'cubic polynomial is not monotonic')\n return p\n}\n\n/** @internal */\nexport const asIncreasing = <T>(\n p: CubicPolynomial<T>,\n i?: Interval.Interval,\n): CubicPolynomial<T & Increasing> => {\n invariant(isIncreasing(p, i as Interval.Interval), 'cubic polynomial is not increasing')\n return p\n}\n\n/** @internal */\nexport const asDecreasing = <T>(\n p: CubicPolynomial<T>,\n i?: Interval.Interval,\n): CubicPolynomial<T & Decreasing> => {\n invariant(isDecreasing(p, i as Interval.Interval), 'cubic polynomial is not decreasing')\n return p\n}\n\n/** @internal */\nexport const domain = dual<\n (range: Interval.Interval) => (p: CubicPolynomial) => Interval.Interval,\n (p: CubicPolynomial, range: Interval.Interval) => Interval.Interval\n>(2, (p: CubicPolynomial, r: Interval.Interval) =>\n Interval.fromMinMax(...solveInverse(p, r.start), ...solveInverse(p, r.end)),\n)\n\n/** @internal */\nexport const range = dual<\n (domain: Interval.Interval) => (p: CubicPolynomial) => Interval.Closed,\n (p: CubicPolynomial, domain: Interval.Interval) => Interval.Closed\n>(2, (p: CubicPolynomial, d: Interval.Interval) =>\n Interval.fromMinMax(\n solve(p, d.start),\n solve(p, d.end),\n ...Interval.filter(d, [...extrema(p)]).map((e) => solve(p, e)),\n ),\n)\n\n/** @internal */\nexport const unitRange = (p: CubicPolynomial): Interval.Closed => range(p, Interval.unit)\n\n/** @internal */\nexport const length = dual<\n (domain: Interval.Interval) => (p: CubicPolynomial) => number,\n (p: CubicPolynomial, domain: Interval.Interval) => number\n>(2, (p: CubicPolynomial, dom: Interval.Interval) => {\n if (Interval.size(dom) === 0) {\n return 0\n }\n\n if (p.c3 === 0) {\n if (p.c2 === 0) {\n return Linear.length(Linear.make(p.c0, p.c1), dom)\n }\n\n return Quadratic.length(Quadratic.make(p.c0, p.c1, p.c2), dom)\n }\n\n const d = derivative(p)\n\n const { scale, shift } = Interval.scaleShift(Interval.biunit, dom)\n\n return (\n (GL32_W0 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * -GL32_X0) ** 2) +\n GL32_W0 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * GL32_X0) ** 2) +\n GL32_W1 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * -GL32_X1) ** 2) +\n GL32_W1 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * GL32_X1) ** 2) +\n GL32_W2 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * -GL32_X2) ** 2) +\n GL32_W2 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * GL32_X2) ** 2) +\n GL32_W3 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * -GL32_X3) ** 2) +\n GL32_W3 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * GL32_X3) ** 2) +\n GL32_W4 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * -GL32_X4) ** 2) +\n GL32_W4 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * GL32_X4) ** 2) +\n GL32_W5 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * -GL32_X5) ** 2) +\n GL32_W5 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * GL32_X5) ** 2) +\n GL32_W6 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * -GL32_X6) ** 2) +\n GL32_W6 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * GL32_X6) ** 2) +\n GL32_W7 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * -GL32_X7) ** 2) +\n GL32_W7 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * GL32_X7) ** 2) +\n GL32_W8 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * -GL32_X8) ** 2) +\n GL32_W8 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * GL32_X8) ** 2) +\n GL32_W9 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * -GL32_X9) ** 2) +\n GL32_W9 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * GL32_X9) ** 2) +\n GL32_W10 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * -GL32_X10) ** 2) +\n GL32_W10 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * GL32_X10) ** 2) +\n GL32_W11 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * -GL32_X11) ** 2) +\n GL32_W11 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * GL32_X11) ** 2) +\n GL32_W12 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * -GL32_X12) ** 2) +\n GL32_W12 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * GL32_X12) ** 2) +\n GL32_W13 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * -GL32_X13) ** 2) +\n GL32_W13 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * GL32_X13) ** 2) +\n GL32_W14 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * -GL32_X14) ** 2) +\n GL32_W14 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * GL32_X14) ** 2) +\n GL32_W15 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * -GL32_X15) ** 2) +\n GL32_W15 * Math.sqrt(1 + Quadratic.solve(d, shift + scale * GL32_X15) ** 2)) *\n scale\n )\n})\n\n/** @internal */\nexport const curvature = dual(2, (p: CubicPolynomial, x: number) => {\n const d = derivative(p)\n const dd = Quadratic.derivative(d)\n\n return Math.abs(Linear.solve(dd, x)) / (1 + Quadratic.solve(d, x) ** 2) ** 1.5\n})\n","import type { Closed, Interval } from '../interval/interval.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type * as Solution from '../solution/solution.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport type { Vector4 } from '../vector/vector4.ts'\nimport * as internal from './cubic.internal.ts'\nimport type { CubicPolynomialTypeId } from './cubic.internal.circular.ts'\nimport type { Monotonicity } from './monotonicity.ts'\nimport type { QuadraticPolynomial } from './quadratic.ts'\nimport type { Decreasing, Increasing, Monotonic, PolynomialTraits } from './traits.ts'\n\nexport type { Monotonic, Increasing, Decreasing } from './traits.ts'\n\n/**\n * A cubic polynomial.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * The `Traits` type parameter is a phantom marker that accumulates trait\n * brands as the polynomial is refined via `isMonotonic` / `asMonotonic` and\n * friends. A cubic is monotonic only over an interval that avoids both of its\n * extrema (or globally, when c2 = c3 = 0 and c1 ≠ 0).\n *\n * @since 1.0.0\n */\nexport interface CubicPolynomial<out Traits = unknown> extends Pipeable {\n readonly [CubicPolynomialTypeId]: CubicPolynomialTypeId\n readonly [PolynomialTraits]: Traits\n\n /**\n * The coefficient of the x^0 term.\n */\n readonly c0: number\n /**\n * The coefficient of the x^1 term.\n */\n readonly c1: number\n /**\n * The coefficient of the x^2 term.\n */\n readonly c2: number\n /**\n * The coefficient of the x^3 term.\n */\n readonly c3: number\n}\n\n/**\n * Checks if a value is a `CubicPolynomial`.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a `CubicPolynomial`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isCubicPolynomial: (value: unknown) => value is CubicPolynomial =\n internal.isCubicPolynomial\n\nexport const equals: {\n /**\n * Checks if two `CubicPolynomial` instances are approximately equal within\n * the default absolute tolerance ({@link EPSILON}).\n *\n * @param a - The first polynomial.\n * @param b - The second polynomial.\n * @returns `true` when each pair of coefficients is within tolerance.\n * @since 1.1.0\n */\n (a: CubicPolynomial, b: CubicPolynomial): boolean\n /**\n * Checks if two `CubicPolynomial` instances are approximately equal within\n * the default absolute tolerance ({@link EPSILON}).\n *\n * @param b - The second polynomial.\n * @returns A function that takes the first polynomial and returns the comparison result.\n * @since 1.1.0\n */\n (b: CubicPolynomial): (a: CubicPolynomial) => boolean\n} = internal.equals\n\n/**\n * Creates a new `CubicPolynomial` instance.\n *\n * @param c0 - The coefficient of the x^0 term.\n * @param c1 - The coefficient of the x^1 term.\n * @param c2 - The coefficient of the x^2 term.\n * @param c3 - The coefficient of the x^3 term.\n */\nexport const make: (c0: number, c1: number, c2: number, c3: number) => CubicPolynomial =\n internal.make\n\n/**\n * Creates a new `CubicPolynomial` instance from a vector.\n *\n * @param v - The vector to convert.\n * @returns A new `CubicPolynomial` instance.\n * @since 1.0.0\n */\nexport const fromVector: (v: Vector4) => CubicPolynomial = internal.fromVector\n\n/**\n * Creates a new `CubicPolynomial` that interpolates the four given points,\n * treating each `Vector2` as an `(x, y)` pair. The four input `x` values must\n * be distinct.\n *\n * @param p0 - The first point.\n * @param p1 - The second point.\n * @param p2 - The third point.\n * @param p3 - The fourth point.\n * @returns The unique cubic polynomial passing through the four points.\n * @since 2.0.0\n */\nexport const fromPoints: (p0: Vector2, p1: Vector2, p2: Vector2, p3: Vector2) => CubicPolynomial =\n internal.fromPoints\n\nexport const solve: {\n /**\n * Solves a cubic polynomial for a given value of x.\n *\n * @param p - The cubic polynomial to solve.\n * @param x - The value of x to solve for.\n * @returns The result of the polynomial evaluation at x.\n * @since 1.0.0\n */\n (p: CubicPolynomial, x: number): number\n /**\n * Solves a cubic polynomial for a given value of x.\n *\n * @param x - The value of x to solve for.\n * @returns A function that takes a cubic polynomial and returns the result of the polynomial evaluation at x.\n * @since 1.0.0\n */\n (x: number): (p: CubicPolynomial) => number\n} = internal.solve\n\n/**\n * Converts a cubic polynomial to a solver function.\n *\n * @param p - The cubic polynomial to convert.\n * @returns A function that takes a value of x and returns the result of the polynomial evaluation at x.\n * @since 1.0.0\n */\nexport const toSolver: (p: CubicPolynomial) => (x: number) => number = internal.toSolver\n\nexport const solveInverse: {\n /**\n * Solves a monotonic cubic polynomial for a given value of y. Because the\n * polynomial is strictly monotonic, the inverse has at most one solution.\n *\n * @param p - The monotonic cubic polynomial.\n * @param y - The value of y to solve for.\n * @returns Zero or one solutions.\n * @since 2.0.0\n */\n <T extends Monotonic>(p: CubicPolynomial<T>, y: number): Solution.AtMostOne<number>\n /**\n * Solves a cubic polynomial for a given value of y.\n *\n * @param p - The cubic polynomial to solve.\n * @param y - The value of y to solve for.\n * @returns The roots of the polynomial equation p(x) = y.\n * @since 1.0.0\n */\n <T>(p: CubicPolynomial<T>, y: number): Solution.AtMostThree<number>\n /**\n * Solves a cubic polynomial for a given value of y.\n *\n * @param y - The value of y to solve for.\n * @returns A function that takes a cubic polynomial and returns the roots\n * of the polynomial equation p(x) = y. Tightens to `Solution.AtMostOne<number>` for\n * monotonic inputs.\n * @since 1.0.0\n */\n (y: number): {\n <T extends Monotonic>(p: CubicPolynomial<T>): Solution.AtMostOne<number>\n <T>(p: CubicPolynomial<T>): Solution.AtMostThree<number>\n }\n} = internal.solveInverse as never\n\n/**\n * Converts a cubic polynomial to an inverse solver function.\n *\n * @param p - The cubic polynomial to convert.\n * @returns A function that takes a value of y and returns the roots of the polynomial equation p(x) = y.\n * @since 1.0.0\n */\nexport const toInverseSolver: (p: CubicPolynomial) => (y: number) => Solution.AtMostThree<number> =\n internal.toInverseSolver\n\n/**\n * Returns the polynomial's coefficients as a tuple `[c0, c1, c2, c3]`.\n *\n * @param p - The cubic polynomial.\n * @returns The coefficients in monomial order.\n * @since 2.0.0\n */\nexport const coefficients: (p: CubicPolynomial) => readonly [number, number, number, number] =\n internal.coefficients\n\n/**\n * Calculates the derivative of a cubic polynomial.\n *\n * @param p - The cubic polynomial to differentiate.\n * @returns The derivative of the cubic polynomial.\n * @since 1.0.0\n */\nexport const derivative: (p: CubicPolynomial) => QuadraticPolynomial = internal.derivative\n\nexport const subdivide: {\n /**\n * Subdivides a cubic polynomial at parameter `t ∈ (0, 1)` into two new\n * cubic polynomials. The first polynomial's evaluation on `[0, 1]` matches\n * the original's on `[0, t]`; the second matches the original's on\n * `[t, 1]`. Equivalent to de Casteljau subdivision in Bernstein form,\n * performed directly in monomial form.\n *\n * @param p - The cubic polynomial to subdivide.\n * @param t - The split parameter; must be in the open interval `(0, 1)`.\n * @returns A `[left, right]` tuple of cubic polynomials.\n * @since 2.0.0\n */\n (p: CubicPolynomial, t: number): [CubicPolynomial, CubicPolynomial]\n /**\n * Subdivides a cubic polynomial at parameter `t ∈ (0, 1)`.\n *\n * @param t - The split parameter; must be in the open interval `(0, 1)`.\n * @returns A function that takes a polynomial and returns its `[left, right]` halves.\n * @since 2.0.0\n */\n (t: number): (p: CubicPolynomial) => [CubicPolynomial, CubicPolynomial]\n} = internal.subdivide\n\n/**\n * Calculates the roots of a cubic polynomial.\n *\n * @param p - The cubic polynomial to find the roots of.\n * @returns The roots of the cubic polynomial.\n * @since 1.0.0\n */\nexport const roots: (p: CubicPolynomial) => Solution.AtMostThree<number> = internal.roots\n\n/**\n * Calculates the extrema of a cubic polynomial.\n *\n * @param p - The cubic polynomial to find the extrema of.\n * @returns The extrema of the cubic polynomial.\n * @since 1.0.0\n */\nexport const extrema: (p: CubicPolynomial) => Solution.AtMostTwo<number> = internal.extrema\n\nexport const monotonicity: {\n /**\n * Calculates the monotonicity of a cubic polynomial. Throws when the\n * interval has zero width — the question is undefined at a single point.\n *\n * @param p - The cubic polynomial to analyze.\n * @param i - The interval to restrict the analysis to.\n * @returns The monotonicity of the cubic polynomial in the specified interval.\n * @since 1.0.0\n */\n (p: CubicPolynomial, i?: Interval): Monotonicity\n /**\n * Calculates the monotonicity of a cubic polynomial. Throws when the\n * interval has zero width.\n *\n * @param i - The interval to restrict the analysis to.\n * @returns A function that takes a cubic polynomial and returns the\n * monotonicity of the cubic polynomial in the specified interval.\n * @since 1.0.0\n */\n (i: Interval): (p: CubicPolynomial) => Monotonicity\n} = internal.monotonicity\n\n/**\n * Type-narrowing predicate: refines a `CubicPolynomial<T>` to\n * `CubicPolynomial<T & Monotonic>` when the polynomial is strictly monotonic\n * over the given interval (or globally, when no interval is given).\n *\n * @param p - The cubic polynomial to check.\n * @param i - Optional interval over which to check monotonicity.\n * @returns `true` when monotonicity is `'increasing'` or `'decreasing'`.\n * @since 2.0.0\n */\nexport const isMonotonic: {\n <T>(p: CubicPolynomial<T>, i?: Interval): p is CubicPolynomial<T & Monotonic>\n (i: Interval): <T>(p: CubicPolynomial<T>) => p is CubicPolynomial<T & Monotonic>\n} = internal.isMonotonic\n\n/**\n * Type-narrowing predicate: refines to `CubicPolynomial<T & Increasing>`.\n *\n * @since 2.0.0\n */\nexport const isIncreasing: {\n <T>(p: CubicPolynomial<T>, i?: Interval): p is CubicPolynomial<T & Increasing>\n (i: Interval): <T>(p: CubicPolynomial<T>) => p is CubicPolynomial<T & Increasing>\n} = internal.isIncreasing\n\n/**\n * Type-narrowing predicate: refines to `CubicPolynomial<T & Decreasing>`.\n *\n * @since 2.0.0\n */\nexport const isDecreasing: {\n <T>(p: CubicPolynomial<T>, i?: Interval): p is CubicPolynomial<T & Decreasing>\n (i: Interval): <T>(p: CubicPolynomial<T>) => p is CubicPolynomial<T & Decreasing>\n} = internal.isDecreasing\n\n/**\n * Asserts that the cubic polynomial is monotonic, throwing on failure.\n *\n * @param p - The cubic polynomial to assert against.\n * @param i - Optional interval over which to check monotonicity.\n * @returns The same polynomial, typed with the `Monotonic` brand.\n * @throws When the polynomial is not monotonic over the given (or global) interval.\n * @since 2.0.0\n */\nexport const asMonotonic: <T>(\n p: CubicPolynomial<T>,\n i?: Interval,\n) => CubicPolynomial<T & Monotonic> = internal.asMonotonic\n\n/**\n * Asserts that the cubic polynomial is increasing, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asIncreasing: <T>(\n p: CubicPolynomial<T>,\n i?: Interval,\n) => CubicPolynomial<T & Increasing> = internal.asIncreasing\n\n/**\n * Asserts that the cubic polynomial is decreasing, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asDecreasing: <T>(\n p: CubicPolynomial<T>,\n i?: Interval,\n) => CubicPolynomial<T & Decreasing> = internal.asDecreasing\n\nexport const domain: {\n /**\n * Calculates the domain of a cubic polynomial.\n *\n * @param p - The cubic polynomial to analyze.\n * @param range - The range to restrict the analysis to.\n * @returns The domain of the cubic polynomial in the specified range.\n * @since 1.0.0\n */\n (p: CubicPolynomial, range: Interval): Interval\n /**\n * Calculates the domain of a cubic polynomial.\n *\n * @param range - The range to restrict the analysis to.\n * @returns A function that takes a cubic polynomial and returns the domain of the cubic polynomial in the specified range.\n * @since 1.0.0\n */\n (range: Interval): (p: CubicPolynomial) => Interval\n} = internal.domain\n\nexport const range: {\n /**\n * Calculates the range of a cubic polynomial.\n *\n * @param p - The cubic polynomial to analyze.\n * @param domain - The domain to restrict the analysis to.\n * @returns The range of the cubic polynomial in the specified domain.\n * @since 1.0.0\n */\n (p: CubicPolynomial, domain: Interval): Closed\n /**\n * Calculates the range of a cubic polynomial.\n *\n * @param domain - The domain to restrict the analysis to.\n * @returns A function that takes a cubic polynomial and returns the range of the cubic polynomial in the specified domain.\n * @since 1.0.0\n */\n (domain: Interval): (p: CubicPolynomial) => Closed\n} = internal.range\n\n/**\n * Calculates the range of a cubic polynomial over the unit interval `[0, 1]`.\n * Equivalent to `range(p, Interval.unit)` — accounts for up to two interior\n * extrema in `[0, 1]`.\n *\n * @param p - The cubic polynomial.\n * @returns The closed range of the polynomial over `[0, 1]`.\n * @since 2.0.0\n */\nexport const unitRange: (p: CubicPolynomial) => Closed = internal.unitRange\n\nexport const length: {\n /**\n * Calculates the length of a cubic polynomial.\n *\n * @param p - The cubic polynomial to analyze.\n * @param domain - The domain to restrict the analysis to.\n * @returns The length of the cubic polynomial in the specified domain.\n * @since 1.0.0\n */\n (p: CubicPolynomial, domain: Interval): number\n /**\n * Calculates the length of a cubic polynomial.\n *\n * @param domain - The domain to restrict the analysis to.\n * @returns A function that takes a cubic polynomial and returns the length of the cubic polynomial in the specified domain.\n * @since 1.0.0\n */\n (domain: Interval): (p: CubicPolynomial) => number\n} = internal.length\n\nexport const curvature: {\n /**\n * Calculates the curvature of a cubic polynomial.\n *\n * @param p - The cubic polynomial to analyze.\n * @param x - The value of x to calculate the curvature at.\n * @returns The curvature of the cubic polynomial at the specified value of x.\n * @since 1.0.0\n */\n (p: CubicPolynomial, x: number): number\n /**\n * Calculates the curvature of a cubic polynomial.\n *\n * @param x - The value of x to calculate the curvature at.\n * @returns A function that takes a cubic polynomial and returns the curvature of the cubic polynomial at the specified value of x.\n * @since 1.0.0\n */\n (x: number): (p: CubicPolynomial) => number\n} = internal.curvature\n"],"mappings":";;;;;;;AAIA,MAAa,4BAA2C,OAAO,IAAI,6BAA6B;;AAIhG,IAAa,0BAAb,cAA6C,SAAiD;CAC5F,CAAU,6BAAwD;CAGlE;CACA;CACA;CAEA,YAAY,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG;EA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C;;;;;;AAOJ,MAAa,eAGTC;;;;;;;;;;AAWJ,MAAa,cAGyBC;;;;;;AAOtC,MAAa,eAG0BC;;;;;;AAOvC,MAAa,eAG0BC;AAEvC,MAAa,SAkBTC;AAEJ,MAAa,QAkBTC;;;;;;;;;;AAWJ,MAAa,YAA4CC;AAEzD,MAAa,SAkBTC;AAEJ,MAAa,YAkBTC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"quadratic-BZmfZE71.mjs","names":["internal.isLinearPolynomial","equals","internal.equals","make","internal.make","fromVector","internal.fromVector","internal.fromPointSlope","fromPoints","internal.fromPoints","solve","internal.solve","toSolver","internal.toSolver","solveInverse","internal.solveInverse","toInverseSolver","internal.toInverseSolver","monotonicity","internal.monotonicity","isMonotonic","internal.isMonotonic","isIncreasing","internal.isIncreasing","isDecreasing","internal.isDecreasing","asMonotonic","internal.asMonotonic","asIncreasing","internal.asIncreasing","asDecreasing","internal.asDecreasing","coefficients","internal.coefficients","derivative","internal.derivative","antiderivative","internal.antiderivative","domain","internal.domain","range","internal.range","unitRange","internal.unitRange","length","internal.length","internal.isQuadraticPolynomial","internal.equals","internal.make","internal.fromVector","internal.fromPoints","internal.solve","internal.toSolver","internal.solveInverse","internal.toInverseSolver","internal.coefficients","internal.derivative","internal.roots","internal.extreme","internal.monotonicity","internal.isMonotonic","internal.isIncreasing","internal.isDecreasing","internal.asMonotonic","internal.asIncreasing","internal.asDecreasing","internal.antiderivative","internal.domain","internal.range","internal.unitRange","internal.length","internal.curvature"],"sources":["../../src/polynomial/linear.ts","../../src/polynomial/quadratic.ts"],"sourcesContent":["import type { Closed, Interval } from '../interval/interval.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type * as Solution from '../solution/solution.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport type { LinearPolynomialTypeId } from './linear.internal.ts'\nimport * as internal from './linear.internal.ts'\nimport type { GuaranteedMonotonicity } from './monotonicity.ts'\nimport type { QuadraticPolynomial } from './quadratic.ts'\nimport type { Decreasing, Increasing, Monotonic, PolynomialTraits } from './traits.ts'\n\nexport type { Monotonic, Increasing, Decreasing } from './traits.ts'\n\n/**\n * A linear polynomial.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * The `Traits` type parameter is a phantom marker that accumulates trait\n * brands as the polynomial is refined via `isMonotonic` / `asMonotonic` and\n * friends. The runtime value carries no trait data — `Traits` only flows\n * through the type system to enable tighter return types on operations like\n * `solveInverse`.\n *\n * @since 1.0.0\n */\nexport interface LinearPolynomial<out Traits = unknown> extends Pipeable {\n readonly [LinearPolynomialTypeId]: LinearPolynomialTypeId\n readonly [PolynomialTraits]: Traits\n\n /**\n * The coefficient of the x^0 term.\n */\n readonly c0: number\n\n /**\n * The coefficient of the x^1 term.\n */\n readonly c1: number\n}\n\n/**\n * Checks if a value is a `LinearPolynomial`.\n *\n * @param v - The value to check.\n * @returns `true` if the value is a `LinearPolynomial`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isLinearPolynomial: (v: unknown) => v is LinearPolynomial = internal.isLinearPolynomial\n\nexport const equals: {\n /**\n * Checks if two `LinearPolynomial` instances are approximately equal within\n * the default absolute tolerance ({@link EPSILON}).\n *\n * @param a - The first polynomial.\n * @param b - The second polynomial.\n * @returns `true` when each pair of coefficients is within tolerance.\n * @since 1.1.0\n */\n (a: LinearPolynomial, b: LinearPolynomial): boolean\n /**\n * Checks if two `LinearPolynomial` instances are approximately equal within\n * the default absolute tolerance ({@link EPSILON}).\n *\n * @param b - The second polynomial.\n * @returns A function that takes the first polynomial and returns the comparison result.\n * @since 1.1.0\n */\n (b: LinearPolynomial): (a: LinearPolynomial) => boolean\n} = internal.equals\n\n/**\n * Creates a new `LinearPolynomial` instance.\n *\n * @param c0 - The coefficient of the x^0 term. Defaults to 0.\n * @param c1 - The coefficient of the x^1 term. Defaults to 0.\n * @returns A new `LinearPolynomial` instance.\n * @since 1.0.0\n */\nexport const make: (c0?: number, c1?: number) => LinearPolynomial = internal.make\n\n/**\n * Creates a new `LinearPolynomial` instance from a vector.\n *\n * @param v - The vector to create the polynomial from.\n * @returns A new `LinearPolynomial` instance.\n * @since 1.0.0\n */\nexport const fromVector: (v: Vector2) => LinearPolynomial = internal.fromVector\n\n/**\n * Creates a new `LinearPolynomial` instance from a point and slope.\n *\n * @param p - The point on the line.\n * @param slope - The slope of the line.\n * @returns A new `LinearPolynomial` instance.\n * @since 1.0.0\n */\nexport const fromPointSlope: (p: Vector2, slope: number) => LinearPolynomial =\n internal.fromPointSlope\n\n/**\n * Creates a new `LinearPolynomial` instance from two points.\n *\n * @param p1 - The first point.\n * @param p2 - The second point.\n * @returns A new `LinearPolynomial` instance.\n * @since 1.0.0\n */\nexport const fromPoints: (p1: Vector2, p2: Vector2) => LinearPolynomial = internal.fromPoints\n\nexport const solve: {\n /**\n * Solves a linear polynomial for a given value of x.\n *\n * @param p - The linear polynomial to solve.\n * @param x - The value of x to solve for.\n * @returns The result of the polynomial evaluated at x.\n * @since 1.0.0\n */\n (p: LinearPolynomial, x: number): number\n /**\n * Solves a linear polynomial for a given value of x.\n *\n * @param x - The value of x to solve for.\n * @returns A function that takes a `LinearPolynomial` and returns the result of the polynomial evaluated at x.\n * @since 1.0.0\n */\n (x: number): (p: LinearPolynomial) => number\n} = internal.solve\n\n/**\n * Converts a linear polynomial to a solver function.\n *\n * @param p - The linear polynomial to convert.\n * @returns A function that takes a value of x and returns the result of the polynomial evaluated at x.\n * @since 1.0.0\n */\nexport const toSolver: (p: LinearPolynomial) => (x: number) => number = internal.toSolver\n\n// The implementation always runs the same `c1 === 0 ? Solution.none : ...`\n// branch. For `Monotonic`-branded polynomials the empty branch is provably\n// unreachable, but TS can't see that — the cast pairs the type-level promise\n// with the runtime brand check.\nexport const solveInverse: {\n /**\n * Solves a monotonic linear polynomial for a given value of y. Because the\n * polynomial is strictly monotonic, the inverse always has exactly one\n * solution — wrapped in `Solution.One`.\n *\n * @param p - The monotonic linear polynomial to solve.\n * @param y - The value of y to solve for.\n * @since 2.0.0\n */\n <T extends Monotonic>(p: LinearPolynomial<T>, y: number): Solution.One<number>\n /**\n * Solves a linear polynomial for a given value of y. Returns `Solution.none`\n * for constant polynomials (no inverse).\n *\n * @param p - The linear polynomial to solve.\n * @param y - The value of y to solve for.\n * @since 1.0.0\n */\n <T>(p: LinearPolynomial<T>, y: number): Solution.AtMostOne<number>\n /** @since 1.0.0 */\n (y: number): {\n <T extends Monotonic>(p: LinearPolynomial<T>): Solution.One<number>\n <T>(p: LinearPolynomial<T>): Solution.AtMostOne<number>\n }\n} = internal.solveInverse as never\n\n/**\n * Converts a linear polynomial to an inverse solver function.\n *\n * @param p - The linear polynomial to convert.\n * @since 1.0.0\n */\nexport const toInverseSolver: (p: LinearPolynomial) => (y: number) => Solution.AtMostOne<number> =\n internal.toInverseSolver\n\n/**\n * Finds the roots of a linear polynomial.\n *\n * @param p - The linear polynomial to find the roots of.\n * @since 1.0.0\n */\nexport const root: (p: LinearPolynomial) => Solution.AtMostOne<number> = (p) =>\n internal.solveInverse(p, 0)\n\n/**\n * Calculates the monotonicity of a linear polynomial.\n *\n * @param p - The linear polynomial to check.\n * @returns The guaranteed monotonicity of the polynomial.\n * @since 1.0.0\n */\nexport const monotonicity: (p: LinearPolynomial) => GuaranteedMonotonicity = internal.monotonicity\n\n/**\n * Type-narrowing predicate: refines a `LinearPolynomial<T>` to\n * `LinearPolynomial<T & Monotonic>` when the polynomial is strictly monotonic.\n *\n * @param p - The linear polynomial to check.\n * @returns `true` when `monotonicity(p)` is `'increasing'` or `'decreasing'`.\n * @since 2.0.0\n */\nexport const isMonotonic: <T>(p: LinearPolynomial<T>) => p is LinearPolynomial<T & Monotonic> =\n internal.isMonotonic\n\n/**\n * Type-narrowing predicate: refines to `LinearPolynomial<T & Increasing>`.\n *\n * @param p - The linear polynomial to check.\n * @returns `true` when `monotonicity(p)` is `'increasing'`.\n * @since 2.0.0\n */\nexport const isIncreasing: <T>(p: LinearPolynomial<T>) => p is LinearPolynomial<T & Increasing> =\n internal.isIncreasing\n\n/**\n * Type-narrowing predicate: refines to `LinearPolynomial<T & Decreasing>`.\n *\n * @param p - The linear polynomial to check.\n * @returns `true` when `monotonicity(p)` is `'decreasing'`.\n * @since 2.0.0\n */\nexport const isDecreasing: <T>(p: LinearPolynomial<T>) => p is LinearPolynomial<T & Decreasing> =\n internal.isDecreasing\n\n/**\n * Asserts that the linear polynomial is monotonic, throwing on failure.\n *\n * @param p - The linear polynomial to assert against.\n * @returns The same polynomial, typed with the `Monotonic` brand.\n * @throws When `monotonicity(p)` is `'constant'`.\n * @since 2.0.0\n */\nexport const asMonotonic: <T>(p: LinearPolynomial<T>) => LinearPolynomial<T & Monotonic> =\n internal.asMonotonic\n\n/**\n * Asserts that the linear polynomial is increasing, throwing on failure.\n *\n * @param p - The linear polynomial to assert against.\n * @returns The same polynomial, typed with the `Increasing` brand.\n * @throws When `monotonicity(p)` is not `'increasing'`.\n * @since 2.0.0\n */\nexport const asIncreasing: <T>(p: LinearPolynomial<T>) => LinearPolynomial<T & Increasing> =\n internal.asIncreasing\n\n/**\n * Asserts that the linear polynomial is decreasing, throwing on failure.\n *\n * @param p - The linear polynomial to assert against.\n * @returns The same polynomial, typed with the `Decreasing` brand.\n * @throws When `monotonicity(p)` is not `'decreasing'`.\n * @since 2.0.0\n */\nexport const asDecreasing: <T>(p: LinearPolynomial<T>) => LinearPolynomial<T & Decreasing> =\n internal.asDecreasing\n\n/**\n * Returns the polynomial's coefficients as a tuple `[c0, c1]`.\n *\n * @param p - The linear polynomial.\n * @returns The coefficients in monomial order.\n * @since 2.0.0\n */\nexport const coefficients: (p: LinearPolynomial) => readonly [number, number] =\n internal.coefficients\n\n/**\n * Calculates the derivative of a linear polynomial.\n *\n * @param p - The linear polynomial to differentiate.\n * @returns The derivative of the linear polynomial.\n * @since 1.0.0\n */\nexport const derivative: (p: LinearPolynomial) => number = internal.derivative\n\nexport const antiderivative: {\n /**\n * Calculates the antiderivative of a linear polynomial.\n *\n * @param p - The linear polynomial to integrate.\n * @param constant - The constant of integration. Defaults to 0.\n * @returns The antiderivative of the linear polynomial.\n * @since 1.0.0\n */\n (p: LinearPolynomial, constant?: number): QuadraticPolynomial\n /**\n * Calculates the antiderivative of a linear polynomial.\n *\n * @param constant - The constant of integration. Defaults to 0.\n * @returns A function that takes a `LinearPolynomial` and returns the antiderivative of the polynomial.\n * @since 1.0.0\n */\n (constant: number): (p: LinearPolynomial) => QuadraticPolynomial\n} = internal.antiderivative\n\nexport const domain: {\n /**\n * Calculates the domain of a linear polynomial.\n *\n * @param p - The linear polynomial to check.\n * @param range - The range to check against.\n * @returns The domain of the polynomial within the given range.\n * @since 1.0.0\n */\n (p: LinearPolynomial, range: Interval): Solution.AtMostOne<Interval>\n /**\n * Calculates the domain of a linear polynomial.\n *\n * @param range - The range to check against.\n * @returns A function that takes a `LinearPolynomial` and returns the domain of the polynomial within the given range.\n * @since 1.0.0\n */\n (range: Interval): (p: LinearPolynomial) => Solution.AtMostOne<Interval>\n} = internal.domain\n\nexport const range: {\n /**\n * Calculates the range of a linear polynomial.\n *\n * @param p - The linear polynomial to check.\n * @param domain - The domain to check against.\n * @returns The range of the polynomial within the given domain.\n * @since 1.0.0\n */\n (p: LinearPolynomial, domain: Interval): Closed\n /**\n * Calculates the range of a linear polynomial.\n *\n * @param domain - The domain to check against.\n * @returns A function that takes a `LinearPolynomial` and returns the range of the polynomial within the given domain.\n * @since 1.0.0\n */\n (domain: Interval): (p: LinearPolynomial) => Closed\n} = internal.range\n\n/**\n * Calculates the range of a linear polynomial over the unit interval `[0, 1]`.\n * Equivalent to `range(p, Interval.unit)` but without the import and call\n * overhead — directly evaluates the endpoints.\n *\n * @param p - The linear polynomial.\n * @returns The closed range of the polynomial over `[0, 1]`.\n * @since 2.0.0\n */\nexport const unitRange: (p: LinearPolynomial) => Closed = internal.unitRange\n\nexport const length: {\n /**\n * Calculates the length of a linear polynomial within a particular domain `Interval`.\n *\n * @param p - The linear polynomial to analyze.\n * @param domain - The domain to restrict the analysis to.\n * @returns The length of the linear polynomial in the specified domain.\n * @since 1.0.0\n */\n (p: LinearPolynomial, domain: Interval): number\n /**\n * Calculates the length of a linear polynomial within a particular domain `Interval`.\n *\n * @param domain - The domain to restrict the analysis to.\n * @returns A function that takes a `LinearPolynomial` and returns the length of the polynomial in the specified domain.\n * @since 1.0.0\n */\n (domain: Interval): (p: LinearPolynomial) => number\n} = internal.length\n","import type { Closed, Interval } from '../interval/interval.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type * as Solution from '../solution/solution.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport type { Vector3 } from '../vector/vector3.ts'\nimport type { CubicPolynomial } from './cubic.ts'\nimport type { LinearPolynomial } from './linear.ts'\nimport type { Monotonicity } from './monotonicity.ts'\nimport * as internal from './quadratic.internal.ts'\nimport type { QuadraticPolynomialTypeId } from './quadratic.internal.circular.ts'\nimport type { Decreasing, Increasing, Monotonic, PolynomialTraits } from './traits.ts'\n\nexport type { Monotonic, Increasing, Decreasing } from './traits.ts'\n\n/**\n * A quadratic polynomial.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * The `Traits` type parameter is a phantom marker that accumulates trait\n * brands as the polynomial is refined via `isMonotonic` / `asMonotonic` and\n * friends. Refinements may be parameterized by an `Interval` — a quadratic is\n * monotonic on an interval that avoids its extremum, even though it is not\n * monotonic globally.\n *\n * @since 1.0.0\n */\nexport interface QuadraticPolynomial<out Traits = unknown> extends Pipeable {\n readonly [QuadraticPolynomialTypeId]: QuadraticPolynomialTypeId\n readonly [PolynomialTraits]: Traits\n\n /**\n * The coefficient of the x^0 term.\n */\n readonly c0: number\n /**\n * The coefficient of the x^1 term.\n */\n readonly c1: number\n /**\n * The coefficient of the x^2 term.\n */\n readonly c2: number\n}\n\n/**\n * Checks if a value is a `QuadraticPolynomial`.\n *\n * @param v - The value to check.\n * @returns `true` if the value is a `QuadraticPolynomial`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isQuadraticPolynomial: (v: unknown) => v is QuadraticPolynomial =\n internal.isQuadraticPolynomial\n\nexport const equals: {\n /**\n * Checks if two `QuadraticPolynomial` instances are approximately equal\n * within the default absolute tolerance ({@link EPSILON}).\n *\n * @param a - The first polynomial.\n * @param b - The second polynomial.\n * @returns `true` when each pair of coefficients is within tolerance.\n * @since 1.1.0\n */\n (a: QuadraticPolynomial, b: QuadraticPolynomial): boolean\n /**\n * Checks if two `QuadraticPolynomial` instances are approximately equal\n * within the default absolute tolerance ({@link EPSILON}).\n *\n * @param b - The second polynomial.\n * @returns A function that takes the first polynomial and returns the comparison result.\n * @since 1.1.0\n */\n (b: QuadraticPolynomial): (a: QuadraticPolynomial) => boolean\n} = internal.equals\n\n/**\n * Creates a new `QuadraticPolynomial` instance.\n *\n * @param c0 - The coefficient of the x^0 term. Defaults to 0.\n * @param c1 - The coefficient of the x^1 term. Defaults to 0.\n * @param c2 - The coefficient of the x^2 term. Defaults to 1.\n * @returns A new `QuadraticPolynomial` instance.\n * @since 1.0.0\n */\nexport const make: (c0?: number, c1?: number, c2?: number) => QuadraticPolynomial = internal.make\n\n/**\n * Creates a new `QuadraticPolynomial` instance from a vector.\n *\n * @param v - The vector to create the polynomial from.\n * @returns A new `QuadraticPolynomial` instance.\n * @since 1.0.0\n */\nexport const fromVector: (v: Vector3) => QuadraticPolynomial = internal.fromVector\n\n/**\n * Creates a new `QuadraticPolynomial` that interpolates the three given\n * points, treating each `Vector2` as an `(x, y)` pair. The three input `x`\n * values must be distinct.\n *\n * @param p0 - The first point.\n * @param p1 - The second point.\n * @param p2 - The third point.\n * @returns The unique quadratic polynomial passing through the three points.\n * @since 2.0.0\n */\nexport const fromPoints: (p0: Vector2, p1: Vector2, p2: Vector2) => QuadraticPolynomial =\n internal.fromPoints\n\nexport const solve: {\n /**\n * Solves the quadratic polynomial for a given x value.\n *\n * @param p - The quadratic polynomial.\n * @param x - The x value to solve for.\n * @returns The result of the polynomial at the given x value.\n * @since 1.0.0\n */\n (p: QuadraticPolynomial, x: number): number\n /**\n * Solves the quadratic polynomial for a given x value.\n *\n * @param x - The x value to solve for.\n * @returns A function that takes a quadratic polynomial and returns the result of the polynomial at the given x value.\n * @since 1.0.0\n */\n (x: number): (p: QuadraticPolynomial) => number\n} = internal.solve\n\n/**\n * Creates a solver function for the quadratic polynomial.\n *\n * @param p - The quadratic polynomial.\n * @returns A function that takes an x value and returns the result of the polynomial at that x value.\n */\nexport const toSolver: (p: QuadraticPolynomial) => (x: number) => number = internal.toSolver\n\nexport const solveInverse: {\n /**\n * Solves a monotonic quadratic polynomial for a given y value. Because the\n * polynomial is strictly monotonic (either globally, or over the interval\n * the `Monotonic` brand was attached for), the inverse has at most one\n * solution.\n *\n * @param p - The monotonic quadratic polynomial.\n * @param y - The y value to solve for.\n * @returns Zero or one solutions.\n * @since 2.0.0\n */\n <T extends Monotonic>(p: QuadraticPolynomial<T>, y: number): Solution.AtMostOne<number>\n /**\n * Solves the quadratic polynomial for a given y value.\n *\n * @param p - The quadratic polynomial.\n * @param y - The y value to solve for.\n * @returns The solutions to the polynomial at the given y value.\n * @since 1.0.0\n */\n <T>(p: QuadraticPolynomial<T>, y: number): Solution.AtMostTwo<number>\n /**\n * Solves the quadratic polynomial for a given y value.\n *\n * @param y - The y value to solve for.\n * @returns A function that takes a quadratic polynomial and returns the\n * solutions. Tightens to `Solution.AtMostOne<number>` for monotonic inputs.\n * @since 1.0.0\n */\n (y: number): {\n <T extends Monotonic>(p: QuadraticPolynomial<T>): Solution.AtMostOne<number>\n <T>(p: QuadraticPolynomial<T>): Solution.AtMostTwo<number>\n }\n} = internal.solveInverse as never\n\n/**\n * Creates an inverse solver function for the quadratic polynomial.\n *\n * @param p - The quadratic polynomial.\n * @returns A function that takes a y value and returns the solutions to the polynomial at that y value.\n */\nexport const toInverseSolver: (\n p: QuadraticPolynomial,\n) => (y: number) => Solution.AtMostTwo<number> = internal.toInverseSolver\n\n/**\n * Returns the polynomial's coefficients as a tuple `[c0, c1, c2]`.\n *\n * @param p - The quadratic polynomial.\n * @returns The coefficients in monomial order.\n * @since 2.0.0\n */\nexport const coefficients: (p: QuadraticPolynomial) => readonly [number, number, number] =\n internal.coefficients\n\n/**\n * Computes the derivative of the quadratic polynomial.\n *\n * @param p - The quadratic polynomial.\n * @returns The derivative of the polynomial as a linear polynomial.\n * @since 1.0.0\n */\nexport const derivative: (p: QuadraticPolynomial) => LinearPolynomial = internal.derivative\n\n/**\n * Finds the roots of the quadratic polynomial.\n *\n * @param p - The quadratic polynomial.\n * @returns The roots of the polynomial as a tuple of solutions.\n * @since 1.0.0\n */\nexport const roots: (p: QuadraticPolynomial) => Solution.AtMostTwo<number> = internal.roots\n\n/**\n * Finds the extreme point of the quadratic polynomial.\n *\n * @param p - The quadratic polynomial.\n * @returns The extreme point of the polynomial as a solution.\n * @since 1.0.0\n */\nexport const extreme: (p: QuadraticPolynomial) => Vector2 | null = internal.extreme\n\nexport const monotonicity: {\n /**\n * Computes the monotonicity of the quadratic polynomial over a given\n * interval. Throws when the interval has zero width — the question is\n * undefined at a single point.\n *\n * @param p - The quadratic polynomial.\n * @param i - The interval to compute the monotonicity over.\n * @returns The monotonicity of the polynomial over the interval.\n * @since 1.0.0\n */\n (p: QuadraticPolynomial, i?: Interval): Monotonicity\n /**\n * Computes the monotonicity of the quadratic polynomial over a given\n * interval. Throws when the interval has zero width.\n *\n * @param i - The interval to compute the monotonicity over.\n * @returns A function that takes a quadratic polynomial and returns the\n * monotonicity of the polynomial over the interval.\n * @since 1.0.0\n */\n (i: Interval): (p: QuadraticPolynomial) => Monotonicity\n} = internal.monotonicity\n\n/**\n * Type-narrowing predicate: refines a `QuadraticPolynomial<T>` to\n * `QuadraticPolynomial<T & Monotonic>` when the polynomial is strictly\n * monotonic over the given interval (or globally, when no interval is given).\n *\n * @param p - The quadratic polynomial to check.\n * @param i - Optional interval over which to check monotonicity.\n * @returns `true` when monotonicity is `'increasing'` or `'decreasing'`.\n * @since 2.0.0\n */\nexport const isMonotonic: {\n <T>(p: QuadraticPolynomial<T>, i?: Interval): p is QuadraticPolynomial<T & Monotonic>\n (i: Interval): <T>(p: QuadraticPolynomial<T>) => p is QuadraticPolynomial<T & Monotonic>\n} = internal.isMonotonic\n\n/**\n * Type-narrowing predicate: refines to `QuadraticPolynomial<T & Increasing>`.\n *\n * @since 2.0.0\n */\nexport const isIncreasing: {\n <T>(p: QuadraticPolynomial<T>, i?: Interval): p is QuadraticPolynomial<T & Increasing>\n (i: Interval): <T>(p: QuadraticPolynomial<T>) => p is QuadraticPolynomial<T & Increasing>\n} = internal.isIncreasing\n\n/**\n * Type-narrowing predicate: refines to `QuadraticPolynomial<T & Decreasing>`.\n *\n * @since 2.0.0\n */\nexport const isDecreasing: {\n <T>(p: QuadraticPolynomial<T>, i?: Interval): p is QuadraticPolynomial<T & Decreasing>\n (i: Interval): <T>(p: QuadraticPolynomial<T>) => p is QuadraticPolynomial<T & Decreasing>\n} = internal.isDecreasing\n\n/**\n * Asserts that the quadratic polynomial is monotonic, throwing on failure.\n *\n * @param p - The quadratic polynomial to assert against.\n * @param i - Optional interval over which to check monotonicity.\n * @returns The same polynomial, typed with the `Monotonic` brand.\n * @throws When the polynomial is not monotonic over the given (or global) interval.\n * @since 2.0.0\n */\nexport const asMonotonic: <T>(\n p: QuadraticPolynomial<T>,\n i?: Interval,\n) => QuadraticPolynomial<T & Monotonic> = internal.asMonotonic\n\n/**\n * Asserts that the quadratic polynomial is increasing, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asIncreasing: <T>(\n p: QuadraticPolynomial<T>,\n i?: Interval,\n) => QuadraticPolynomial<T & Increasing> = internal.asIncreasing\n\n/**\n * Asserts that the quadratic polynomial is decreasing, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asDecreasing: <T>(\n p: QuadraticPolynomial<T>,\n i?: Interval,\n) => QuadraticPolynomial<T & Decreasing> = internal.asDecreasing\n\nexport const antiderivative: {\n /**\n * Computes the antiderivative of the quadratic polynomial.\n *\n * @param p - The quadratic polynomial.\n * @param constant - The constant of integration. Defaults to 0.\n * @returns The antiderivative of the polynomial as a cubic polynomial.\n * @since 1.0.0\n */\n (p: QuadraticPolynomial, constant?: number): CubicPolynomial\n /**\n * Computes the antiderivative of the quadratic polynomial.\n *\n * @param constant - The constant of integration. Defaults to 0.\n * @returns A function that takes a quadratic polynomial and returns the antiderivative of the polynomial as a cubic polynomial.\n * @since 1.0.0\n */\n (constant: number): (p: QuadraticPolynomial) => CubicPolynomial\n} = internal.antiderivative\n\nexport const domain: {\n /**\n * Computes the domain of the quadratic polynomial over a given range.\n *\n * @param p - The quadratic polynomial.\n * @param range - The range to compute the domain over.\n * @returns The domain of the polynomial over the range.\n * @since 1.0.0\n */\n (p: QuadraticPolynomial, range: Interval): Solution.AtMostOne<Interval>\n /**\n * Computes the domain of the quadratic polynomial over a given range.\n *\n * @param range - The range to compute the domain over.\n * @returns A function that takes a quadratic polynomial and returns the domain of the polynomial over the range.\n * @since 1.0.0\n */\n (range: Interval): (p: QuadraticPolynomial) => Solution.AtMostOne<Interval>\n} = internal.domain\n\nexport const range: {\n /**\n * Computes the range of the quadratic polynomial over a given domain.\n *\n * @param p - The quadratic polynomial.\n * @param domain - The domain to compute the range over.\n * @returns The range of the polynomial over the domain.\n * @since 1.0.0\n */\n (p: QuadraticPolynomial, domain: Interval): Closed\n /**\n * Computes the range of the quadratic polynomial over a given domain.\n *\n * @param domain - The domain to compute the range over.\n * @returns A function that takes a quadratic polynomial and returns the range of the polynomial over the domain.\n * @since 1.0.0\n */\n (domain: Interval): (p: QuadraticPolynomial) => Closed\n} = internal.range\n\n/**\n * Computes the range of the quadratic polynomial over the unit interval\n * `[0, 1]`. Equivalent to `range(p, Interval.unit)` — accounts for any\n * interior extremum in `[0, 1]`.\n *\n * @param p - The quadratic polynomial.\n * @returns The closed range of the polynomial over `[0, 1]`.\n * @since 2.0.0\n */\nexport const unitRange: (p: QuadraticPolynomial) => Closed = internal.unitRange\n\nexport const length: {\n /**\n * Computes the length of the quadratic polynomial over a given interval.\n *\n * @param p - The quadratic polynomial.\n * @param i - The interval to compute the length over.\n * @returns The length of the polynomial over the interval.\n * @since 1.0.0\n */\n (p: QuadraticPolynomial, i: Interval): number\n /**\n * Computes the length of the quadratic polynomial over a given interval.\n *\n * @param i - The interval to compute the length over.\n * @returns A function that takes a quadratic polynomial and returns the length of the polynomial over the interval.\n * @since 1.0.0\n */\n (i: Interval): (p: QuadraticPolynomial) => number\n} = internal.length\n\nexport const curvature: {\n /**\n * Computes the curvature of the quadratic polynomial at a given x value.\n *\n * @param p - The quadratic polynomial.\n * @param x - The x value to compute the curvature at.\n * @returns The curvature of the polynomial at the given x value.\n * @since 1.0.0\n */\n (p: QuadraticPolynomial, x: number): number\n /**\n * Computes the curvature of the quadratic polynomial at a given x value.\n *\n * @param x - The x value to compute the curvature at.\n * @returns A function that takes a quadratic polynomial and returns the curvature of the polynomial at the given x value.\n * @since 1.0.0\n */\n (x: number): (p: QuadraticPolynomial) => number\n} = internal.curvature\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAa,qBAA4DA;AAEzE,MAAaC,WAoBTC;;;;;;;;;AAUJ,MAAaC,SAAuDC;;;;;;;;AASpE,MAAaC,eAA+CC;;;;;;;;;AAU5D,MAAa,iBACXC;;;;;;;;;AAUF,MAAaC,eAA6DC;AAE1E,MAAaC,UAkBTC;;;;;;;;AASJ,MAAaC,aAA2DC;AAMxE,MAAaC,iBAyBTC;;;;;;;AAQJ,MAAaC,oBACXC;;;;;;;AAQF,MAAa,QAA6D,MACxEF,eAAsB,GAAG,EAAE;;;;;;;;AAS7B,MAAaG,iBAAgEC;;;;;;;;;AAU7E,MAAaC,gBACXC;;;;;;;;AASF,MAAaC,iBACXC;;;;;;;;AASF,MAAaC,iBACXC;;;;;;;;;AAUF,MAAaC,gBACXC;;;;;;;;;AAUF,MAAaC,iBACXC;;;;;;;;;AAUF,MAAaC,iBACXC;;;;;;;;AASF,MAAaC,iBACXC;;;;;;;;AASF,MAAaC,eAA8CC;AAE3D,MAAaC,mBAkBTC;AAEJ,MAAaC,WAkBTC;AAEJ,MAAaC,UAkBTC;;;;;;;;;;AAWJ,MAAaC,cAA6CC;AAE1D,MAAaC,WAkBTC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC9TJ,MAAa,wBACXC;AAEF,MAAa,SAoBTC;;;;;;;;;;AAWJ,MAAa,OAAuEC;;;;;;;;AASpF,MAAa,aAAkDC;;;;;;;;;;;;AAa/D,MAAa,aACXC;AAEF,MAAa,QAkBTC;;;;;;;AAQJ,MAAa,WAA8DC;AAE3E,MAAa,eAkCTC;;;;;;;AAQJ,MAAa,kBAEoCC;;;;;;;;AASjD,MAAa,eACXC;;;;;;;;AASF,MAAa,aAA2DC;;;;;;;;AASxE,MAAa,QAAgEC;;;;;;;;AAS7E,MAAa,UAAsDC;AAEnE,MAAa,eAsBTC;;;;;;;;;;;AAYJ,MAAa,cAGTC;;;;;;AAOJ,MAAa,eAGTC;;;;;;AAOJ,MAAa,eAGTC;;;;;;;;;;AAWJ,MAAa,cAG6BC;;;;;;AAO1C,MAAa,eAG8BC;;;;;;AAO3C,MAAa,eAG8BC;AAE3C,MAAa,iBAkBTC;AAEJ,MAAa,SAkBTC;AAEJ,MAAa,QAkBTC;;;;;;;;;;AAWJ,MAAa,YAAgDC;AAE7D,MAAa,SAkBTC;AAEJ,MAAa,YAkBTC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"rationalCubic2d-IroMR6AA.mjs","names":["fromPolynomials","fromCoefficients","LinearPolynomial.make","fromEndpoints","isLinearCurve2d","derivative","Vector2.make","solve","LinearPolynomial.solve","solveAtX","Solution.match","LinearPolynomial.solveInverse","Solution.none","Solution.one","solveAtY","length","boundingBox","Interval2d.make","LinearPolynomial.unitRange","isMonotonic","LinearPolynomial.isMonotonic","isIncreasing","LinearPolynomial.isIncreasing","isDecreasing","LinearPolynomial.isDecreasing","fail","asMonotonic","asIncreasing","asDecreasing","fromPolynomials","internal.fromPolynomials","fromCoefficients","internal.fromCoefficients","internal.fromEndpoints","internal.isLinearCurve2d","derivative","internal.derivative","solve","internal.solve","length","internal.length","boundingBox","internal.boundingBox","solveAtX","internal.solveAtX","solveAtY","internal.solveAtY","isMonotonic","internal.isMonotonic","isIncreasing","internal.isIncreasing","isDecreasing","internal.isDecreasing","asMonotonic","internal.asMonotonic","asIncreasing","internal.asIncreasing","asDecreasing","internal.asDecreasing","fromPolynomials","fromCoefficients","QuadraticPolynomial.make","fromBezierPoints","isQuadraticCurve2d","solve","Vector2.make","QuadraticPolynomial.solve","solveAtX","Solution.clip","QuadraticPolynomial.solveInverse","Interval.unit","Solution.map","solveAtY","derivative","LinearCurve2d.fromPolynomials","QuadraticPolynomial.derivative","length","Interval.size","LinearCurve2d.length","LinearPolynomial.make","Interval.scaleShift","Interval.biunit","Vector2.magnitude","LinearCurve2d.solve","curvature","LinearCurve2d.derivative","Vector2.cross","boundingBox","Interval2d.make","QuadraticPolynomial.unitRange","isMonotonic","QuadraticPolynomial.isMonotonic","isIncreasing","QuadraticPolynomial.isIncreasing","isDecreasing","QuadraticPolynomial.isDecreasing","fail","asMonotonic","asIncreasing","asDecreasing","fromPolynomials","internal.fromPolynomials","fromCoefficients","internal.fromCoefficients","fromBezierPoints","internal.fromBezierPoints","internal.isQuadraticCurve2d","solve","internal.solve","length","internal.length","solveAtX","internal.solveAtX","solveAtY","internal.solveAtY","derivative","internal.derivative","curvature","internal.curvature","boundingBox","internal.boundingBox","isMonotonic","internal.isMonotonic","isIncreasing","internal.isIncreasing","isDecreasing","internal.isDecreasing","asMonotonic","internal.asMonotonic","asIncreasing","internal.asIncreasing","asDecreasing","internal.asDecreasing","fromPolynomials","fromCoefficients","CubicPolynomial.make","fromBezierPoints","Vector4.transpose","Characteristic.apply","Characteristic.cubicBezier","isCubicCurve2d","solve","Vector2.make","CubicPolynomial.solve","solveAtX","Solution.clip","CubicPolynomial.solveInverse","Interval.unit","Solution.map","solveAtY","QuadraticCurve2d.fromPolynomials","CubicPolynomial.derivative","length","Interval.size","QuadraticCurve2d.length","QuadraticPolynomial.make","Interval.scaleShift","Interval.biunit","Vector2.magnitude","QuadraticCurve2d.solve","curvature","LinearCurve2d.solve","QuadraticCurve2d.derivative","Vector2.cross","boundingBox","Interval2d.make","CubicPolynomial.unitRange","isMonotonic","CubicPolynomial.isMonotonic","isIncreasing","CubicPolynomial.isIncreasing","isDecreasing","CubicPolynomial.isDecreasing","asMonotonic","asIncreasing","asDecreasing","fromPolynomials","internal.fromPolynomials","internal.fromCoefficients","fromBezierPoints","internal.fromBezierPoints","internal.isCubicCurve2d","solve","internal.solve","internal.length","solveAtX","internal.solveAtX","solveAtY","internal.solveAtY","internal.curvature","boundingBox","internal.boundingBox","internal.isMonotonic","internal.isIncreasing","internal.isDecreasing","internal.asMonotonic","internal.asIncreasing","internal.asDecreasing","isRationalCubicCurve2d","fromPolynomials","fromBezierPoints","Characteristic.apply","Characteristic.cubicBezier","Vector4.transpose","makeMonotonicEasing","CubicPolynomial.make","CubicPolynomial.roots","Solution.clip","Interval.unitOpen","CubicPolynomial.solve","solve","Vector2.make","solveAtX","Interval.unit","Solution.map","solveAtY","CubicCurve2d.fromBezierPoints","subdivide","CubicPolynomial.subdivide","boundingBox","Interval2d.fromVectors","CubicCurve2d.fromPolynomials","CubicCurve2d.boundingBox","Interval2d.maxDistance","approximateAsCubicCurves","internal.isRationalCubicCurve2d","internal.fromPolynomials","internal.fromBezierPoints","internal.makeMonotonicEasing","internal.solve","internal.solveAtX","internal.solveAtY","internal.subdivide","internal.boundingBox","internal.approximateAsCubicCurves"],"sources":["../../src/curve/linear2d.internal.ts","../../src/curve/linear2d.ts","../../src/curve/quadratic2d.internal.ts","../../src/curve/quadratic2d.ts","../../src/curve/cubic2d.internal.ts","../../src/curve/cubic2d.ts","../../src/curve/rationalCubic2d.internal.ts","../../src/curve/rationalCubic2d.ts"],"sourcesContent":["import * as Interval2d from '../interval/interval2d.ts'\nimport type * as Interval from '../interval/interval.ts'\nimport { dual, Pipeable } from '../utils.ts'\nimport * as LinearPolynomial from '../polynomial/linear.ts'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits.ts'\nimport * as Solution from '../solution/solution.ts'\nimport * as Vector2 from '../vector/vector2.ts'\nimport type { LinearCurve2d } from './linear2d.ts'\n\nexport const LinearCurve2dTypeId: unique symbol = Symbol('curvy/curve/linear2d')\nexport type LinearCurve2dTypeId = typeof LinearCurve2dTypeId\n\n/** @internal */\nexport class LinearCurve2dImpl extends Pipeable implements LinearCurve2d<unknown, unknown> {\n readonly [LinearCurve2dTypeId]: LinearCurve2dTypeId = LinearCurve2dTypeId\n\n readonly x: LinearPolynomial.LinearPolynomial\n readonly y: LinearPolynomial.LinearPolynomial\n\n constructor(c0: LinearPolynomial.LinearPolynomial, c1: LinearPolynomial.LinearPolynomial) {\n super()\n this.x = c0\n this.y = c1\n }\n\n get [0]() {\n return this.x\n }\n\n get [1]() {\n return this.y\n }\n}\n\n/** @internal */\nexport const fromPolynomials: (\n c0: LinearPolynomial.LinearPolynomial,\n c1: LinearPolynomial.LinearPolynomial,\n) => LinearCurve2d = (c0, c1) => new LinearCurve2dImpl(c0, c1)\n\n/** @internal */\nexport const fromCoefficients: (c0: Vector2.Vector2, c1: Vector2.Vector2) => LinearCurve2d = (\n c0,\n c1,\n) => new LinearCurve2dImpl(LinearPolynomial.make(c0.x, c1.x), LinearPolynomial.make(c0.y, c1.y))\n\n// Linear Bernstein basis: B(t) = (1-t)·p0 + t·p1\n// Expanding to monomial form gives c0 = p0, c1 = p1 - p0.\n/** @internal */\nexport const fromEndpoints: (p0: Vector2.Vector2, p1: Vector2.Vector2) => LinearCurve2d = (\n p0,\n p1,\n) =>\n new LinearCurve2dImpl(\n LinearPolynomial.make(p0.x, p1.x - p0.x),\n LinearPolynomial.make(p0.y, p1.y - p0.y),\n )\n\n/** @internal */\nexport const isLinearCurve2d = (c: unknown): c is LinearCurve2d =>\n typeof c === 'object' && c !== null && LinearCurve2dTypeId in c\n\n/** @internal */\nexport const derivative = (c: LinearCurve2d) => Vector2.make(c.x.c1, c.y.c1)\n\n/** @internal */\nexport const solve = dual<\n (t: number) => (c: LinearCurve2d) => Vector2.Vector2,\n (c: LinearCurve2d, t: number) => Vector2.Vector2\n>(2, (c: LinearCurve2d, t: number) =>\n Vector2.make(LinearPolynomial.solve(c.x, t), LinearPolynomial.solve(c.y, t)),\n)\n\n// solveAtX: invert the x polynomial to find t, then evaluate y at t — only\n// returning the result when t lies in the curve's parameter domain [0, 1].\n// A linear curve crosses any vertical line at most once, so the result is\n// always 0 or 1 element.\n/** @internal */\nexport const solveAtX = dual(2, (c: LinearCurve2d, x: number) =>\n Solution.match(LinearPolynomial.solveInverse(c.x, x), {\n onNone: () => Solution.none,\n onSome: ({ value: t }) =>\n t < 0 || t > 1 ? Solution.none : Solution.one(LinearPolynomial.solve(c.y, t)),\n }),\n)\n\n/** @internal */\nexport const solveAtY = dual(2, (c: LinearCurve2d, y: number) =>\n Solution.match(LinearPolynomial.solveInverse(c.y, y), {\n onNone: () => Solution.none,\n onSome: ({ value: t }) =>\n t < 0 || t > 1 ? Solution.none : Solution.one(LinearPolynomial.solve(c.x, t)),\n }),\n)\n\n/** @internal */\nexport const length = dual(\n 2,\n (c: LinearCurve2d, i: Interval.Interval) =>\n Math.sqrt(c.x.c1 ** 2 + c.y.c1 ** 2) * Math.abs(i.end - i.start),\n)\n\n/** @internal */\nexport const boundingBox = (\n c: LinearCurve2d,\n): Interval2d.Interval2d<Interval.Closed, Interval.Closed> =>\n Interval2d.make(LinearPolynomial.unitRange(c.x), LinearPolynomial.unitRange(c.y))\n\n// Combined trait refiners — fan out the polynomial-level check across both\n// axes. For per-axis checks, users can call `LinearPolynomial.isMonotonic(c.x)`\n// directly.\n/** @internal */\nexport const isMonotonic = <XT, YT>(\n c: LinearCurve2d<XT, YT>,\n): c is LinearCurve2d<XT & Monotonic, YT & Monotonic> =>\n LinearPolynomial.isMonotonic(c.x) && LinearPolynomial.isMonotonic(c.y)\n\n/** @internal */\nexport const isIncreasing = <XT, YT>(\n c: LinearCurve2d<XT, YT>,\n): c is LinearCurve2d<XT & Increasing, YT & Increasing> =>\n LinearPolynomial.isIncreasing(c.x) && LinearPolynomial.isIncreasing(c.y)\n\n/** @internal */\nexport const isDecreasing = <XT, YT>(\n c: LinearCurve2d<XT, YT>,\n): c is LinearCurve2d<XT & Decreasing, YT & Decreasing> =>\n LinearPolynomial.isDecreasing(c.x) && LinearPolynomial.isDecreasing(c.y)\n\nconst fail = (m: string): never => {\n throw new Error(m)\n}\n\n/** @internal */\nexport const asMonotonic = <XT, YT>(\n c: LinearCurve2d<XT, YT>,\n): LinearCurve2d<XT & Monotonic, YT & Monotonic> =>\n isMonotonic(c) ? c : fail('linear curve is not monotonic in both axes')\n\n/** @internal */\nexport const asIncreasing = <XT, YT>(\n c: LinearCurve2d<XT, YT>,\n): LinearCurve2d<XT & Increasing, YT & Increasing> =>\n isIncreasing(c) ? c : fail('linear curve is not increasing in both axes')\n\n/** @internal */\nexport const asDecreasing = <XT, YT>(\n c: LinearCurve2d<XT, YT>,\n): LinearCurve2d<XT & Decreasing, YT & Decreasing> =>\n isDecreasing(c) ? c : fail('linear curve is not decreasing in both axes')\n","import type { Interval2d } from '../interval/interval2d.ts'\nimport type { TwoDimensional } from '../dimensions.ts'\nimport type { Closed, Interval } from '../interval/interval.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { LinearPolynomial } from '../polynomial/linear.ts'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits.ts'\nimport type * as Solution from '../solution/solution.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport type { LinearCurve2dTypeId } from './linear2d.internal.ts'\nimport * as internal from './linear2d.internal.ts'\n\nexport type { Monotonic, Increasing, Decreasing } from '../polynomial/traits.ts'\n\n/**\n * A linear curve in 2D space.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * The two type parameters carry the trait sets of the curve's per-axis\n * polynomials. Refiners like `isMonotonic` lift each axis's monotonicity into\n * the curve's combined trait set.\n *\n * @since 1.0.0\n */\nexport interface LinearCurve2d<out XTraits = unknown, out YTraits = unknown>\n extends Pipeable, TwoDimensional<LinearPolynomial<XTraits>, LinearPolynomial<YTraits>> {\n readonly [LinearCurve2dTypeId]: LinearCurve2dTypeId\n}\n\n/**\n * Creates a new `LinearCurve2d` instance from polynomial parameters.\n *\n * @param x - The x polynomial.\n * @param y - The y polynomial.\n * @returns A new `LinearCurve2d` instance.\n * @since 1.0.0\n */\nexport const fromPolynomials: (x: LinearPolynomial, y: LinearPolynomial) => LinearCurve2d =\n internal.fromPolynomials\n\n/**\n * Creates a new `LinearCurve2d` instance from monomial coefficient vectors.\n *\n * Each argument bundles the per-axis coefficient at the given power: `c0`\n * holds the x⁰ term, `c1` holds the x¹ term. The resulting curve evaluates to\n * `c0 + c1·t` per axis.\n *\n * @param c0 - The x⁰ coefficients (x and y).\n * @param c1 - The x¹ coefficients (x and y).\n * @returns A new `LinearCurve2d` instance.\n * @since 2.0.0\n */\nexport const fromCoefficients: (c0: Vector2, c1: Vector2) => LinearCurve2d =\n internal.fromCoefficients\n\n/**\n * Creates a new `LinearCurve2d` instance from a pair of endpoints.\n *\n * `p0` is the curve at `t = 0`, `p1` is the curve at `t = 1`. The\n * implementation converts to the curve's internal monomial form (slope-form\n * polynomial in `t`) in closed form.\n *\n * @param p0 - The curve's start point.\n * @param p1 - The curve's end point.\n * @returns A new `LinearCurve2d` instance whose curve matches the line from `p0` to `p1`.\n * @since 2.0.0\n */\nexport const fromEndpoints: (p0: Vector2, p1: Vector2) => LinearCurve2d = internal.fromEndpoints\n\n/**\n * Checks if a value is a `LinearCurve2d`.\n *\n * @param c - The value to check.\n * @returns `true` if the value is a `LinearCurve2d`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isLinearCurve2d: (c: unknown) => c is LinearCurve2d = internal.isLinearCurve2d\n\n/**\n * Gets the derivative of a linear curve as a vector\n *\n * @param c - The linear curve to get the derivative of.\n * @returns The derivative of the linear curve as a vector.\n * @since 1.0.0\n */\nexport const derivative: (c: LinearCurve2d) => Vector2 = internal.derivative\n\nexport const solve: {\n /**\n * Solves the linear curve for a given parameter t.\n *\n * @param t - The parameter value.\n * @returns A function that takes a linear curve and returns the point on the curve at parameter t.\n * @since 1.0.0\n */\n (t: number): (c: LinearCurve2d) => Vector2\n /**\n * Solves the linear curve for a given parameter t.\n *\n * @param c - The linear curve to solve.\n * @param t - The parameter value.\n * @returns The point on the curve at parameter t.\n * @since 1.0.0\n */\n (c: LinearCurve2d, t: number): Vector2\n} = internal.solve\n\nexport const length: {\n /**\n * Calculates (approximates) the length of a linear curve.\n *\n * @param c - The linear curve to calculate the length of.\n * @param i - The interval to calculate the length over.\n * @returns The length of the linear curve over the given interval.\n * @since 1.0.0\n */\n (c: LinearCurve2d, i: Interval): number\n /**\n * Calculates (approximates) the length of a linear curve.\n *\n * @param i - The interval to calculate the length over.\n * @returns A function that takes a linear curve and returns the length of the linear curve over the given interval.\n * @since 1.0.0\n */\n (i: Interval): (c: LinearCurve2d) => number\n} = internal.length\n\n/**\n * Computes the axis-aligned bounding box of the curve over its parameter\n * domain `[0, 1]`. For a linear curve this is the closed box enclosing the\n * two endpoints.\n *\n * @param c - The linear curve.\n * @returns A closed `Box2d` enclosing the curve.\n * @since 2.0.0\n */\nexport const boundingBox: (c: LinearCurve2d) => Interval2d<Closed, Closed> = internal.boundingBox\n\nexport const solveAtX: {\n /**\n * Evaluates the curve's y value at a given x. A linear curve crosses any\n * vertical line at most once (within the curve's parameter domain `[0, 1]`),\n * so the result is at most one y. Returns the empty tuple when x is outside\n * the curve's range or when the curve's x polynomial is constant.\n *\n * @param c - The linear curve.\n * @param x - The x coordinate.\n * @returns The y value at x, or empty when x is undefined for this curve.\n * @since 2.0.0\n */\n <XT, YT>(c: LinearCurve2d<XT, YT>, x: number): Solution.AtMostOne<number>\n /** @since 2.0.0 */\n (x: number): <XT, YT>(c: LinearCurve2d<XT, YT>) => Solution.AtMostOne<number>\n} = internal.solveAtX as never\n\nexport const solveAtY: {\n /**\n * Evaluates the curve's x value at a given y. A linear curve crosses any\n * horizontal line at most once (within the curve's parameter domain\n * `[0, 1]`), so the result is at most one x.\n *\n * @param c - The linear curve.\n * @param y - The y coordinate.\n * @returns The x value at y, or empty when y is undefined for this curve.\n * @since 2.0.0\n */\n <XT, YT>(c: LinearCurve2d<XT, YT>, y: number): Solution.AtMostOne<number>\n /** @since 2.0.0 */\n (y: number): <XT, YT>(c: LinearCurve2d<XT, YT>) => Solution.AtMostOne<number>\n} = internal.solveAtY as never\n\n/**\n * Type-narrowing predicate: refines both axes' traits to include `Monotonic`\n * when both the x and y polynomials are strictly monotonic. When both axes\n * are monotonic, the curve is invertible in either direction.\n *\n * For checking only one axis, call the polynomial-level refiner directly:\n * `LinearPolynomial.isMonotonic(curve.x)`.\n *\n * @since 2.0.0\n */\nexport const isMonotonic: <XT, YT>(\n c: LinearCurve2d<XT, YT>,\n) => c is LinearCurve2d<XT & Monotonic, YT & Monotonic> = internal.isMonotonic\n\n/**\n * Type-narrowing predicate: refines both axes' traits to include `Increasing`.\n *\n * @since 2.0.0\n */\nexport const isIncreasing: <XT, YT>(\n c: LinearCurve2d<XT, YT>,\n) => c is LinearCurve2d<XT & Increasing, YT & Increasing> = internal.isIncreasing\n\n/**\n * Type-narrowing predicate: refines both axes' traits to include `Decreasing`.\n *\n * @since 2.0.0\n */\nexport const isDecreasing: <XT, YT>(\n c: LinearCurve2d<XT, YT>,\n) => c is LinearCurve2d<XT & Decreasing, YT & Decreasing> = internal.isDecreasing\n\n/**\n * Asserts monotonicity in both axes, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asMonotonic: <XT, YT>(\n c: LinearCurve2d<XT, YT>,\n) => LinearCurve2d<XT & Monotonic, YT & Monotonic> = internal.asMonotonic\n\n/**\n * Asserts that both axes are strictly increasing, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asIncreasing: <XT, YT>(\n c: LinearCurve2d<XT, YT>,\n) => LinearCurve2d<XT & Increasing, YT & Increasing> = internal.asIncreasing\n\n/**\n * Asserts that both axes are strictly decreasing, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asDecreasing: <XT, YT>(\n c: LinearCurve2d<XT, YT>,\n) => LinearCurve2d<XT & Decreasing, YT & Decreasing> = internal.asDecreasing\n","import * as Interval2d from '../interval/interval2d.ts'\nimport * as Interval from '../interval/interval.ts'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits.ts'\nimport {\n GL32_W0,\n GL32_W1,\n GL32_W2,\n GL32_W3,\n GL32_W4,\n GL32_W5,\n GL32_W6,\n GL32_W7,\n GL32_W8,\n GL32_W9,\n GL32_W10,\n GL32_W11,\n GL32_W12,\n GL32_W13,\n GL32_W14,\n GL32_W15,\n GL32_X0,\n GL32_X1,\n GL32_X2,\n GL32_X3,\n GL32_X4,\n GL32_X5,\n GL32_X6,\n GL32_X7,\n GL32_X8,\n GL32_X9,\n GL32_X10,\n GL32_X11,\n GL32_X12,\n GL32_X13,\n GL32_X14,\n GL32_X15,\n} from '../length.ts'\nimport { dual, Pipeable } from '../utils.ts'\nimport * as LinearPolynomial from '../polynomial/linear.ts'\nimport * as QuadraticPolynomial from '../polynomial/quadratic.ts'\nimport * as Solution from '../solution/solution.ts'\nimport * as Vector2 from '../vector/vector2.ts'\nimport * as LinearCurve2d from './linear2d.ts'\nimport type { QuadraticCurve2d } from './quadratic2d.ts'\n\nexport const QuadraticCurve2dTypeId: unique symbol = Symbol('curvy/curve/quadratic2d')\nexport type QuadraticCurve2dTypeId = typeof QuadraticCurve2dTypeId\n\n/** @internal */\nexport class QuadraticCurve2dImpl extends Pipeable implements QuadraticCurve2d<unknown, unknown> {\n readonly [QuadraticCurve2dTypeId]: QuadraticCurve2dTypeId = QuadraticCurve2dTypeId\n\n readonly x: QuadraticPolynomial.QuadraticPolynomial\n readonly y: QuadraticPolynomial.QuadraticPolynomial\n\n constructor(\n c0: QuadraticPolynomial.QuadraticPolynomial,\n c1: QuadraticPolynomial.QuadraticPolynomial,\n ) {\n super()\n this.x = c0\n this.y = c1\n }\n\n get [0]() {\n return this.x\n }\n\n get [1]() {\n return this.y\n }\n}\n\n/** @internal */\nexport const fromPolynomials: (\n c0: QuadraticPolynomial.QuadraticPolynomial,\n c1: QuadraticPolynomial.QuadraticPolynomial,\n) => QuadraticCurve2d = (c0, c1) => new QuadraticCurve2dImpl(c0, c1)\n\n/** @internal */\nexport const fromCoefficients: (\n c0: Vector2.Vector2,\n c1: Vector2.Vector2,\n c2: Vector2.Vector2,\n) => QuadraticCurve2d = (c0, c1, c2) =>\n new QuadraticCurve2dImpl(\n QuadraticPolynomial.make(c0.x, c1.x, c2.x),\n QuadraticPolynomial.make(c0.y, c1.y, c2.y),\n )\n\n// Quadratic Bernstein basis: B(t) = (1-t)²·p0 + 2(1-t)t·p1 + t²·p2\n// Expanding to monomial form gives:\n// c0 = p0\n// c1 = -2p0 + 2p1\n// c2 = p0 - 2p1 + p2\n/** @internal */\nexport const fromBezierPoints: (\n p0: Vector2.Vector2,\n p1: Vector2.Vector2,\n p2: Vector2.Vector2,\n) => QuadraticCurve2d = (p0, p1, p2) =>\n new QuadraticCurve2dImpl(\n QuadraticPolynomial.make(p0.x, -2 * p0.x + 2 * p1.x, p0.x - 2 * p1.x + p2.x),\n QuadraticPolynomial.make(p0.y, -2 * p0.y + 2 * p1.y, p0.y - 2 * p1.y + p2.y),\n )\n\n/** @internal */\nexport const isQuadraticCurve2d = (c: unknown): c is QuadraticCurve2d =>\n typeof c === 'object' && c !== null && QuadraticCurve2dTypeId in c\n\n/** @internal */\nexport const solve = dual<\n (t: number) => (c: QuadraticCurve2d) => Vector2.Vector2,\n (c: QuadraticCurve2d, t: number) => Vector2.Vector2\n>(2, (c: QuadraticCurve2d, t: number) =>\n Vector2.make(QuadraticPolynomial.solve(c.x, t), QuadraticPolynomial.solve(c.y, t)),\n)\n\n// solveAtX: invert the x polynomial to find ts within the unit interval, then\n// evaluate y at each surviving t. Result order matches solveInverse order\n// (t-ascending).\n/** @internal */\nexport const solveAtX = dual(2, (c: QuadraticCurve2d, x: number) => {\n const ts = Solution.clip(QuadraticPolynomial.solveInverse(c.x, x), Interval.unit)\n return Solution.map(ts, (t) => QuadraticPolynomial.solve(c.y, t))\n})\n\n/** @internal */\nexport const solveAtY = dual(2, (c: QuadraticCurve2d, y: number) => {\n const ts = Solution.clip(QuadraticPolynomial.solveInverse(c.y, y), Interval.unit)\n return Solution.map(ts, (t) => QuadraticPolynomial.solve(c.x, t))\n})\n\n/** @internal */\nexport const derivative = (c: QuadraticCurve2d) =>\n LinearCurve2d.fromPolynomials(\n QuadraticPolynomial.derivative(c.x),\n QuadraticPolynomial.derivative(c.y),\n )\n\n/** @internal */\nexport const length = dual(2, (c: QuadraticCurve2d, i: Interval.Interval) => {\n if (Interval.size(i) === 0) {\n return 0\n }\n\n if (c.x.c2 === 0 && c.y.c2 === 0) {\n return LinearCurve2d.length(\n LinearCurve2d.fromPolynomials(\n LinearPolynomial.make(c.x.c0, c.x.c1),\n LinearPolynomial.make(c.y.c0, c.y.c1),\n ),\n i,\n )\n }\n\n const d = derivative(c)\n\n const { scale, shift } = Interval.scaleShift(Interval.biunit, i)\n\n return (\n (GL32_W0 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X0)) +\n GL32_W0 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X0)) +\n GL32_W1 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X1)) +\n GL32_W1 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X1)) +\n GL32_W2 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X2)) +\n GL32_W2 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X2)) +\n GL32_W3 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X3)) +\n GL32_W3 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X3)) +\n GL32_W4 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X4)) +\n GL32_W4 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X4)) +\n GL32_W5 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X5)) +\n GL32_W5 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X5)) +\n GL32_W6 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X6)) +\n GL32_W6 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X6)) +\n GL32_W7 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X7)) +\n GL32_W7 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X7)) +\n GL32_W8 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X8)) +\n GL32_W8 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X8)) +\n GL32_W9 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X9)) +\n GL32_W9 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X9)) +\n GL32_W10 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X10)) +\n GL32_W10 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X10)) +\n GL32_W11 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X11)) +\n GL32_W11 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X11)) +\n GL32_W12 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X12)) +\n GL32_W12 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X12)) +\n GL32_W13 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X13)) +\n GL32_W13 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X13)) +\n GL32_W14 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X14)) +\n GL32_W14 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X14)) +\n GL32_W15 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X15)) +\n GL32_W15 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X15))) *\n scale\n )\n})\n\n/** @internal */\nexport const curvature = dual(2, (c: QuadraticCurve2d, t: number) => {\n const d = derivative(c)\n const v = LinearCurve2d.solve(d, t)\n const a = LinearCurve2d.derivative(d)\n\n const vMag = Vector2.magnitude(v)\n\n if (vMag === 0) {\n return 0\n }\n\n return Math.abs(Vector2.cross(v, a)) / vMag ** 3\n})\n\n/** @internal */\nexport const boundingBox = (\n c: QuadraticCurve2d,\n): Interval2d.Interval2d<Interval.Closed, Interval.Closed> =>\n Interval2d.make(QuadraticPolynomial.unitRange(c.x), QuadraticPolynomial.unitRange(c.y))\n\n// Combined trait refiners — fan out the polynomial-level check across both\n// axes, over the unit interval. For per-axis checks, users can call\n// `QuadraticPolynomial.isMonotonic(c.x, Interval.unit)` directly.\n/** @internal */\nexport const isMonotonic = <XT, YT>(\n c: QuadraticCurve2d<XT, YT>,\n): c is QuadraticCurve2d<XT & Monotonic, YT & Monotonic> =>\n QuadraticPolynomial.isMonotonic(c.x, Interval.unit) &&\n QuadraticPolynomial.isMonotonic(c.y, Interval.unit)\n\n/** @internal */\nexport const isIncreasing = <XT, YT>(\n c: QuadraticCurve2d<XT, YT>,\n): c is QuadraticCurve2d<XT & Increasing, YT & Increasing> =>\n QuadraticPolynomial.isIncreasing(c.x, Interval.unit) &&\n QuadraticPolynomial.isIncreasing(c.y, Interval.unit)\n\n/** @internal */\nexport const isDecreasing = <XT, YT>(\n c: QuadraticCurve2d<XT, YT>,\n): c is QuadraticCurve2d<XT & Decreasing, YT & Decreasing> =>\n QuadraticPolynomial.isDecreasing(c.x, Interval.unit) &&\n QuadraticPolynomial.isDecreasing(c.y, Interval.unit)\n\nconst fail = (m: string): never => {\n throw new Error(m)\n}\n\n/** @internal */\nexport const asMonotonic = <XT, YT>(\n c: QuadraticCurve2d<XT, YT>,\n): QuadraticCurve2d<XT & Monotonic, YT & Monotonic> =>\n isMonotonic(c) ? c : fail('quadratic curve is not monotonic in both axes')\n\n/** @internal */\nexport const asIncreasing = <XT, YT>(\n c: QuadraticCurve2d<XT, YT>,\n): QuadraticCurve2d<XT & Increasing, YT & Increasing> =>\n isIncreasing(c) ? c : fail('quadratic curve is not increasing in both axes')\n\n/** @internal */\nexport const asDecreasing = <XT, YT>(\n c: QuadraticCurve2d<XT, YT>,\n): QuadraticCurve2d<XT & Decreasing, YT & Decreasing> =>\n isDecreasing(c) ? c : fail('quadratic curve is not decreasing in both axes')\n","import type { Interval2d } from '../interval/interval2d.ts'\nimport type { TwoDimensional } from '../dimensions.ts'\nimport type { Closed, Interval } from '../interval/interval.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { QuadraticPolynomial } from '../polynomial/quadratic.ts'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits.ts'\nimport type * as Solution from '../solution/solution.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport type { LinearCurve2d } from './linear2d.ts'\nimport type { QuadraticCurve2dTypeId } from './quadratic2d.internal.ts'\nimport * as internal from './quadratic2d.internal.ts'\n\nexport type { Monotonic, Increasing, Decreasing } from '../polynomial/traits.ts'\n\n/**\n * A quadratic curve in 2D space.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * The two type parameters carry the trait sets of the curve's per-axis\n * polynomials. Refiners check monotonicity over the unit interval `[0, 1]` —\n * the curve's natural parameter domain.\n *\n * @since 1.0.0\n */\nexport interface QuadraticCurve2d<out XTraits = unknown, out YTraits = unknown>\n extends Pipeable, TwoDimensional<QuadraticPolynomial<XTraits>, QuadraticPolynomial<YTraits>> {\n readonly [QuadraticCurve2dTypeId]: QuadraticCurve2dTypeId\n}\n\n/**\n * Creates a new `QuadraticCurve2d` instance from polynomial parameters.\n *\n * @param c0 - The x polynomial.\n * @param c1 - The y polynomial.\n * @returns A new `QuadraticCurve2d` instance.\n * @since 1.0.0\n */\nexport const fromPolynomials: (\n c0: QuadraticPolynomial,\n c1: QuadraticPolynomial,\n) => QuadraticCurve2d = internal.fromPolynomials\n\n/**\n * Creates a new `QuadraticCurve2d` instance from monomial coefficient vectors.\n *\n * Each argument bundles the per-axis coefficient at the given power: `c0`\n * holds the x⁰ term, `c1` holds the x¹ term, and so on. The resulting curve\n * evaluates to `c0 + c1·t + c2·t²` per axis.\n *\n * @param c0 - The x⁰ coefficients (x and y).\n * @param c1 - The x¹ coefficients (x and y).\n * @param c2 - The x² coefficients (x and y).\n * @returns A new `QuadraticCurve2d` instance.\n * @since 2.0.0\n */\nexport const fromCoefficients: (c0: Vector2, c1: Vector2, c2: Vector2) => QuadraticCurve2d =\n internal.fromCoefficients\n\n/**\n * Creates a new `QuadraticCurve2d` instance from quadratic Bézier control\n * points.\n *\n * The three arguments are the Bernstein-basis control points: `p0` and `p2`\n * are the curve's endpoints and `p1` is the off-curve control handle. The\n * implementation converts to the curve's internal monomial form in closed\n * form.\n *\n * @param p0 - The first control point (curve start).\n * @param p1 - The second control point (control handle).\n * @param p2 - The third control point (curve end).\n * @returns A new `QuadraticCurve2d` instance whose curve matches the given Bézier.\n * @since 2.0.0\n */\nexport const fromBezierPoints: (p0: Vector2, p1: Vector2, p2: Vector2) => QuadraticCurve2d =\n internal.fromBezierPoints\n\n/**\n * Checks if a value is a `QuadraticCurve2d`.\n *\n * @param c - The value to check.\n * @returns `true` if the value is a `QuadraticCurve2d`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isQuadraticCurve2d: (c: unknown) => c is QuadraticCurve2d = internal.isQuadraticCurve2d\n\nexport const solve: {\n /**\n * Solves the quadratic curve for a given parameter t.\n *\n * @param t - The parameter value.\n * @returns A function that takes a quadratic curve and returns the point on the curve at parameter t.\n * @since 1.0.0\n */\n (t: number): (c: QuadraticCurve2d) => Vector2\n /**\n * Solves the quadratic curve for a given parameter t.\n *\n * @param c - The quadratic curve to solve.\n * @param t - The parameter value.\n * @returns The point on the curve at parameter t.\n * @since 1.0.0\n */\n (c: QuadraticCurve2d, t: number): Vector2\n} = internal.solve\n\nexport const length: {\n /**\n * Computes the length of the quadratic curve over a given interval.\n *\n * @param c - The quadratic curve to compute the length of.\n * @param i - The interval over which to compute the length.\n * @returns The length of the quadratic curve over the interval.\n * @since 1.0.0\n */\n (c: QuadraticCurve2d, i: Interval): number\n /**\n * Computes the length of the quadratic curve over a given interval.\n *\n * @param i - The interval over which to compute the length.\n * @returns A function that takes a quadratic curve and returns the length of the curve over the interval.\n * @since 1.0.0\n */\n (i: Interval): (c: QuadraticCurve2d) => number\n} = internal.length\n\nexport const solveAtX: {\n /**\n * Evaluates the curve's y values at a given x. Because the x polynomial is\n * `Monotonic`, the inverse has at most one solution — at most one y value.\n *\n * @param c - The quadratic curve.\n * @param x - The x coordinate.\n * @returns Zero or one y values, in t-ascending order.\n * @since 2.0.0\n */\n <XT extends Monotonic, YT>(c: QuadraticCurve2d<XT, YT>, x: number): Solution.AtMostOne<number>\n /**\n * Evaluates the curve's y values at a given x. The result is the y values\n * the curve passes through where x(t) = the given x — up to two solutions\n * for a quadratic curve.\n *\n * @param c - The quadratic curve.\n * @param x - The x coordinate.\n * @returns The y values at x, in t-ascending order.\n * @since 2.0.0\n */\n <XT, YT>(c: QuadraticCurve2d<XT, YT>, x: number): Solution.AtMostTwo<number>\n /** @since 2.0.0 */\n (x: number): {\n <XT extends Monotonic, YT>(c: QuadraticCurve2d<XT, YT>): Solution.AtMostOne<number>\n <XT, YT>(c: QuadraticCurve2d<XT, YT>): Solution.AtMostTwo<number>\n }\n} = internal.solveAtX as never\n\nexport const solveAtY: {\n /**\n * Evaluates the curve's x values at a given y. Because the y polynomial is\n * `Monotonic`, the inverse has at most one solution.\n *\n * @param c - The quadratic curve.\n * @param y - The y coordinate.\n * @returns Zero or one x values, in t-ascending order.\n * @since 2.0.0\n */\n <XT, YT extends Monotonic>(c: QuadraticCurve2d<XT, YT>, y: number): Solution.AtMostOne<number>\n /**\n * Evaluates the curve's x values at a given y. The result is the x values\n * the curve passes through where y(t) = the given y — up to two solutions\n * for a quadratic curve.\n *\n * @param c - The quadratic curve.\n * @param y - The y coordinate.\n * @returns The x values at y, in t-ascending order.\n * @since 2.0.0\n */\n <XT, YT>(c: QuadraticCurve2d<XT, YT>, y: number): Solution.AtMostTwo<number>\n /** @since 2.0.0 */\n (y: number): {\n <XT, YT extends Monotonic>(c: QuadraticCurve2d<XT, YT>): Solution.AtMostOne<number>\n <XT, YT>(c: QuadraticCurve2d<XT, YT>): Solution.AtMostTwo<number>\n }\n} = internal.solveAtY as never\n\n/**\n * Computes the derivative of a quadratic curve.\n *\n * @param c - The quadratic curve to compute the derivative of.\n * @returns The derivative of the quadratic curve as a linear curve.\n * @since 1.0.0\n */\nexport const derivative: (c: QuadraticCurve2d) => LinearCurve2d = internal.derivative\n\nexport const curvature: {\n /**\n * Computes the curvature of the quadratic curve at a given parameter t.\n *\n * @param c - The quadratic curve to compute the curvature for.\n * @param t - The parameter value.\n * @returns The curvature of the quadratic curve at parameter t.\n * @since 1.0.0\n */\n (c: QuadraticCurve2d, t: number): number\n /**\n * Computes the curvature of the quadratic curve at a given parameter t.\n *\n * @param t - The parameter value.\n * @returns A function that takes a quadratic curve and returns the curvature of the curve at parameter t.\n * @since 1.0.0\n */\n (t: number): (c: QuadraticCurve2d) => number\n} = internal.curvature\n\n/**\n * Computes the axis-aligned bounding box of the curve over its parameter\n * domain `[0, 1]`. Accounts for interior extrema, so the box is tight against\n * the curve and not just the control polygon.\n *\n * @param c - The quadratic curve.\n * @returns A closed `Box2d` enclosing the curve.\n * @since 2.0.0\n */\nexport const boundingBox: (c: QuadraticCurve2d) => Interval2d<Closed, Closed> = internal.boundingBox\n\n/**\n * Type-narrowing predicate: refines both axes' traits to include `Monotonic`\n * when both x and y polynomials are monotonic over the unit interval `[0, 1]`.\n *\n * For checking only one axis, call the polynomial-level refiner directly:\n * `QuadraticPolynomial.isMonotonic(curve.x, Interval.unit)`.\n *\n * @since 2.0.0\n */\nexport const isMonotonic: <XT, YT>(\n c: QuadraticCurve2d<XT, YT>,\n) => c is QuadraticCurve2d<XT & Monotonic, YT & Monotonic> = internal.isMonotonic\n\n/** @since 2.0.0 */\nexport const isIncreasing: <XT, YT>(\n c: QuadraticCurve2d<XT, YT>,\n) => c is QuadraticCurve2d<XT & Increasing, YT & Increasing> = internal.isIncreasing\n\n/** @since 2.0.0 */\nexport const isDecreasing: <XT, YT>(\n c: QuadraticCurve2d<XT, YT>,\n) => c is QuadraticCurve2d<XT & Decreasing, YT & Decreasing> = internal.isDecreasing\n\n/** @since 2.0.0 */\nexport const asMonotonic: <XT, YT>(\n c: QuadraticCurve2d<XT, YT>,\n) => QuadraticCurve2d<XT & Monotonic, YT & Monotonic> = internal.asMonotonic\n\n/** @since 2.0.0 */\nexport const asIncreasing: <XT, YT>(\n c: QuadraticCurve2d<XT, YT>,\n) => QuadraticCurve2d<XT & Increasing, YT & Increasing> = internal.asIncreasing\n\n/** @since 2.0.0 */\nexport const asDecreasing: <XT, YT>(\n c: QuadraticCurve2d<XT, YT>,\n) => QuadraticCurve2d<XT & Decreasing, YT & Decreasing> = internal.asDecreasing\n","import * as Interval2d from '../interval/interval2d.ts'\nimport * as Characteristic from '../characteristic/characteristic.ts'\nimport * as Interval from '../interval/interval.ts'\nimport {\n GL32_W0,\n GL32_W1,\n GL32_W2,\n GL32_W3,\n GL32_W4,\n GL32_W5,\n GL32_W6,\n GL32_W7,\n GL32_W8,\n GL32_W9,\n GL32_W10,\n GL32_W11,\n GL32_W12,\n GL32_W13,\n GL32_W14,\n GL32_W15,\n GL32_X0,\n GL32_X1,\n GL32_X2,\n GL32_X3,\n GL32_X4,\n GL32_X5,\n GL32_X6,\n GL32_X7,\n GL32_X8,\n GL32_X9,\n GL32_X10,\n GL32_X11,\n GL32_X12,\n GL32_X13,\n GL32_X14,\n GL32_X15,\n} from '../length.ts'\nimport { dual, Pipeable } from '../utils.ts'\nimport * as CubicPolynomial from '../polynomial/cubic.ts'\nimport * as QuadraticPolynomial from '../polynomial/quadratic.ts'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits.ts'\nimport * as Solution from '../solution/solution.ts'\nimport * as Vector2 from '../vector/vector2.ts'\nimport * as Vector4 from '../vector/vector4.ts'\nimport type { CubicCurve2d } from './cubic2d.ts'\nimport * as LinearCurve2d from './linear2d.ts'\nimport * as QuadraticCurve2d from './quadratic2d.ts'\n\nexport const CubicCurve2dTypeId: unique symbol = Symbol('curvy/curve/cubic2d')\nexport type CubicCurve2dTypeId = typeof CubicCurve2dTypeId\n\n/** @internal */\nexport class CubicCurve2dImpl extends Pipeable implements CubicCurve2d<unknown, unknown> {\n readonly [CubicCurve2dTypeId]: CubicCurve2dTypeId = CubicCurve2dTypeId\n\n readonly x: CubicPolynomial.CubicPolynomial\n readonly y: CubicPolynomial.CubicPolynomial\n\n constructor(c0: CubicPolynomial.CubicPolynomial, c1: CubicPolynomial.CubicPolynomial) {\n super()\n this.x = c0\n this.y = c1\n }\n\n get [0]() {\n return this.x\n }\n\n get [1]() {\n return this.y\n }\n}\n\n/** @internal */\nexport const fromPolynomials: (\n c0: CubicPolynomial.CubicPolynomial,\n c1: CubicPolynomial.CubicPolynomial,\n) => CubicCurve2d = (c0, c1) => new CubicCurve2dImpl(c0, c1)\n\n/** @internal */\nexport const fromCoefficients: (\n c0: Vector2.Vector2,\n c1: Vector2.Vector2,\n c2: Vector2.Vector2,\n c3: Vector2.Vector2,\n) => CubicCurve2d = (c0, c1, c2, c3) =>\n new CubicCurve2dImpl(\n CubicPolynomial.make(c0.x, c1.x, c2.x, c3.x),\n CubicPolynomial.make(c0.y, c1.y, c2.y, c3.y),\n )\n\n// Applies the cubic Bézier characteristic matrix to the per-axis control\n// vectors, producing monomial polynomials. The matrix encodes the cubic\n// Bernstein → monomial expansion `(c₀, c₁, c₂, c₃) = M · (p₀, p₁, p₂, p₃)`\n// for each axis independently.\n/** @internal */\nexport const fromBezierPoints: (\n p0: Vector2.Vector2,\n p1: Vector2.Vector2,\n p2: Vector2.Vector2,\n p3: Vector2.Vector2,\n) => CubicCurve2d = (p0, p1, p2, p3) => {\n const channels = Vector4.transpose([p0, p1, p2, p3], (p) => [p.x, p.y])\n return new CubicCurve2dImpl(...Characteristic.apply(Characteristic.cubicBezier, ...channels))\n}\n\n/** @internal */\nexport const isCubicCurve2d = (c: unknown): c is CubicCurve2d =>\n typeof c === 'object' && c !== null && CubicCurve2dTypeId in c\n\n/** @internal */\nexport const solve = dual<\n (t: number) => (c: CubicCurve2d) => Vector2.Vector2,\n (c: CubicCurve2d, t: number) => Vector2.Vector2\n>(2, (c: CubicCurve2d, t: number) =>\n Vector2.make(CubicPolynomial.solve(c.x, t), CubicPolynomial.solve(c.y, t)),\n)\n\n// solveAtX: invert the x polynomial to find ts within the unit interval, then\n// evaluate y at each surviving t. Result order matches solveInverse order\n// (t-ascending).\n/** @internal */\nexport const solveAtX = dual(2, (c: CubicCurve2d, x: number) => {\n const ts = Solution.clip(CubicPolynomial.solveInverse(c.x, x), Interval.unit)\n return Solution.map(ts, (t) => CubicPolynomial.solve(c.y, t))\n})\n\n/** @internal */\nexport const solveAtY = dual(2, (c: CubicCurve2d, y: number) => {\n const ts = Solution.clip(CubicPolynomial.solveInverse(c.y, y), Interval.unit)\n return Solution.map(ts, (t) => CubicPolynomial.solve(c.x, t))\n})\n\n/** @internal */\nexport const derivative = (c: CubicCurve2d) =>\n QuadraticCurve2d.fromPolynomials(CubicPolynomial.derivative(c.x), CubicPolynomial.derivative(c.y))\n\n/** @internal */\nexport const length = dual(2, (c: CubicCurve2d, i: Interval.Interval) => {\n if (Interval.size(i) === 0) {\n return 0\n }\n\n if (c.x.c3 === 0 && c.y.c3 === 0) {\n return QuadraticCurve2d.length(\n QuadraticCurve2d.fromPolynomials(\n QuadraticPolynomial.make(c.x.c0, c.x.c1, c.x.c2),\n QuadraticPolynomial.make(c.y.c0, c.y.c1, c.y.c2),\n ),\n i,\n )\n }\n\n const d = derivative(c)\n\n const { scale, shift } = Interval.scaleShift(Interval.biunit, i)\n\n return (\n (GL32_W0 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * -GL32_X0)) +\n GL32_W0 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * GL32_X0)) +\n GL32_W1 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * -GL32_X1)) +\n GL32_W1 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * GL32_X1)) +\n GL32_W2 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * -GL32_X2)) +\n GL32_W2 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * GL32_X2)) +\n GL32_W3 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * -GL32_X3)) +\n GL32_W3 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * GL32_X3)) +\n GL32_W4 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * -GL32_X4)) +\n GL32_W4 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * GL32_X4)) +\n GL32_W5 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * -GL32_X5)) +\n GL32_W5 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * GL32_X5)) +\n GL32_W6 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * -GL32_X6)) +\n GL32_W6 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * GL32_X6)) +\n GL32_W7 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * -GL32_X7)) +\n GL32_W7 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * GL32_X7)) +\n GL32_W8 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * -GL32_X8)) +\n GL32_W8 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * GL32_X8)) +\n GL32_W9 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * -GL32_X9)) +\n GL32_W9 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * GL32_X9)) +\n GL32_W10 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * -GL32_X10)) +\n GL32_W10 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * GL32_X10)) +\n GL32_W11 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * -GL32_X11)) +\n GL32_W11 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * GL32_X11)) +\n GL32_W12 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * -GL32_X12)) +\n GL32_W12 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * GL32_X12)) +\n GL32_W13 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * -GL32_X13)) +\n GL32_W13 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * GL32_X13)) +\n GL32_W14 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * -GL32_X14)) +\n GL32_W14 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * GL32_X14)) +\n GL32_W15 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * -GL32_X15)) +\n GL32_W15 * Vector2.magnitude(QuadraticCurve2d.solve(d, shift + scale * GL32_X15))) *\n scale\n )\n})\n\n/** @internal */\nexport const curvature = dual(2, (c: CubicCurve2d, t: number) => {\n const d = derivative(c)\n\n const v = QuadraticCurve2d.solve(d, t)\n const a = LinearCurve2d.solve(QuadraticCurve2d.derivative(d), t)\n\n const vMag = Vector2.magnitude(v)\n\n if (vMag === 0) {\n return 0\n }\n\n return Math.abs(Vector2.cross(v, a)) / vMag ** 3\n})\n\n/** @internal */\nexport const boundingBox = (\n c: CubicCurve2d,\n): Interval2d.Interval2d<Interval.Closed, Interval.Closed> =>\n Interval2d.make(CubicPolynomial.unitRange(c.x), CubicPolynomial.unitRange(c.y))\n\n// Combined trait refiners — fan out the polynomial-level check across both\n// axes, over the unit interval. For per-axis checks, users can call\n// `CubicPolynomial.isMonotonic(c.x, Interval.unit)` directly.\n/** @internal */\nexport const isMonotonic = <XT, YT>(\n c: CubicCurve2d<XT, YT>,\n): c is CubicCurve2d<XT & Monotonic, YT & Monotonic> =>\n CubicPolynomial.isMonotonic(c.x, Interval.unit) && CubicPolynomial.isMonotonic(c.y, Interval.unit)\n\n/** @internal */\nexport const isIncreasing = <XT, YT>(\n c: CubicCurve2d<XT, YT>,\n): c is CubicCurve2d<XT & Increasing, YT & Increasing> =>\n CubicPolynomial.isIncreasing(c.x, Interval.unit) &&\n CubicPolynomial.isIncreasing(c.y, Interval.unit)\n\n/** @internal */\nexport const isDecreasing = <XT, YT>(\n c: CubicCurve2d<XT, YT>,\n): c is CubicCurve2d<XT & Decreasing, YT & Decreasing> =>\n CubicPolynomial.isDecreasing(c.x, Interval.unit) &&\n CubicPolynomial.isDecreasing(c.y, Interval.unit)\n\nconst fail = (m: string): never => {\n throw new Error(m)\n}\n\n/** @internal */\nexport const asMonotonic = <XT, YT>(\n c: CubicCurve2d<XT, YT>,\n): CubicCurve2d<XT & Monotonic, YT & Monotonic> =>\n isMonotonic(c) ? c : fail('cubic curve is not monotonic in both axes')\n\n/** @internal */\nexport const asIncreasing = <XT, YT>(\n c: CubicCurve2d<XT, YT>,\n): CubicCurve2d<XT & Increasing, YT & Increasing> =>\n isIncreasing(c) ? c : fail('cubic curve is not increasing in both axes')\n\n/** @internal */\nexport const asDecreasing = <XT, YT>(\n c: CubicCurve2d<XT, YT>,\n): CubicCurve2d<XT & Decreasing, YT & Decreasing> =>\n isDecreasing(c) ? c : fail('cubic curve is not decreasing in both axes')\n","import type { Interval2d } from '../interval/interval2d.ts'\nimport type { TwoDimensional } from '../dimensions.ts'\nimport type { Closed, Interval } from '../interval/interval.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { CubicPolynomial } from '../polynomial/cubic.ts'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits.ts'\nimport type * as Solution from '../solution/solution.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport type { CubicCurve2dTypeId } from './cubic2d.internal.ts'\nimport * as internal from './cubic2d.internal.ts'\n\nexport type { Monotonic, Increasing, Decreasing } from '../polynomial/traits.ts'\n\n/**\n * A cubic curve in 2D space.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * The two type parameters carry the trait sets of the curve's per-axis\n * polynomials. Refiners check monotonicity over the unit interval `[0, 1]` —\n * the curve's natural parameter domain.\n *\n * @since 1.0.0\n */\nexport interface CubicCurve2d<out XTraits = unknown, out YTraits = unknown>\n extends Pipeable, TwoDimensional<CubicPolynomial<XTraits>, CubicPolynomial<YTraits>> {\n readonly [CubicCurve2dTypeId]: CubicCurve2dTypeId\n}\n\n/**\n * Creates a new `CubicCurve2d` instance from polynomial parameters.\n *\n * @param x - The x polynomial.\n * @param y - The y polynomial.\n * @returns A new `CubicCurve2d` instance.\n * @since 1.0.0\n */\nexport const fromPolynomials: (x: CubicPolynomial, y: CubicPolynomial) => CubicCurve2d =\n internal.fromPolynomials\n\n/**\n * Creates a new `CubicCurve2d` instance from monomial coefficient vectors.\n *\n * Each argument bundles the per-axis coefficient at the given power: `c0`\n * holds the x⁰ term, `c1` holds the x¹ term, and so on. The resulting curve\n * evaluates to `c0 + c1·t + c2·t² + c3·t³` per axis.\n *\n * @param c0 - The x⁰ coefficients (x and y).\n * @param c1 - The x¹ coefficients (x and y).\n * @param c2 - The x² coefficients (x and y).\n * @param c3 - The x³ coefficients (x and y).\n * @returns A new `CubicCurve2d` instance.\n * @since 2.0.0\n */\nexport const fromCoefficients: (\n c0: Vector2,\n c1: Vector2,\n c2: Vector2,\n c3: Vector2,\n) => CubicCurve2d = internal.fromCoefficients\n\n/**\n * Creates a new `CubicCurve2d` instance from cubic Bézier control points.\n *\n * The four arguments are the Bernstein-basis control points: `p0` and `p3` are\n * the curve's endpoints and `p1` and `p2` are the off-curve control handles.\n * The implementation converts to the curve's internal monomial form in closed\n * form.\n *\n * @param p0 - The first control point (curve start).\n * @param p1 - The second control point (start handle).\n * @param p2 - The third control point (end handle).\n * @param p3 - The fourth control point (curve end).\n * @returns A new `CubicCurve2d` instance whose curve matches the given Bézier.\n * @since 2.0.0\n */\nexport const fromBezierPoints: (\n p0: Vector2,\n p1: Vector2,\n p2: Vector2,\n p3: Vector2,\n) => CubicCurve2d = internal.fromBezierPoints\n\n/**\n * Checks if a value is a `CubicCurve2d`.\n *\n * @param c - The value to check.\n * @returns `true` if the value is a `CubicCurve2d`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isCubicCurve2d: (c: unknown) => c is CubicCurve2d = internal.isCubicCurve2d\n\nexport const solve: {\n /**\n * Solves the cubic curve for a given parameter t.\n *\n * @param t - The parameter value.\n * @returns A function that takes a cubic curve and returns the point on the curve at parameter t.\n * @since 1.0.0\n */\n (t: number): (c: CubicCurve2d) => Vector2\n /**\n * Solves the cubic curve for a given parameter t.\n *\n * @param c - The cubic curve to solve.\n * @param t - The parameter value.\n * @returns The point on the curve at parameter t.\n * @since 1.0.0\n */\n (c: CubicCurve2d, t: number): Vector2\n} = internal.solve\n\nexport const length: {\n /**\n * Calculates (approximates) the length of a cubic curve.\n *\n * @param c - The cubic curve to calculate the length of.\n * @param i - The interval over which to calculate the length.\n * @returns The length of the cubic curve.\n * @since 1.0.0\n */\n (c: CubicCurve2d, i: Interval): number\n /**\n * Calculates (approximates) the length of a cubic curve.\n *\n * @param i - The interval over which to calculate the length.\n * @returns A function that takes a cubic curve and returns the length of the cubic curve.\n * @since 1.0.0\n */\n (i: Interval): (c: CubicCurve2d) => number\n} = internal.length\n\nexport const solveAtX: {\n /**\n * Evaluates the curve's y values at a given x. Because the x polynomial is\n * `Monotonic`, the inverse has at most one solution — at most one y value.\n *\n * @param c - The cubic curve.\n * @param x - The x coordinate.\n * @returns Zero or one y values, in t-ascending order.\n * @since 2.0.0\n */\n <XT extends Monotonic, YT>(c: CubicCurve2d<XT, YT>, x: number): Solution.AtMostOne<number>\n /**\n * Evaluates the curve's y values at a given x. The result is the y values\n * the curve passes through where x(t) = the given x — up to three solutions\n * for a cubic curve.\n *\n * @param c - The cubic curve.\n * @param x - The x coordinate.\n * @returns The y values at x, in t-ascending order.\n * @since 2.0.0\n */\n <XT, YT>(c: CubicCurve2d<XT, YT>, x: number): Solution.AtMostThree<number>\n /** @since 2.0.0 */\n (x: number): {\n <XT extends Monotonic, YT>(c: CubicCurve2d<XT, YT>): Solution.AtMostOne<number>\n <XT, YT>(c: CubicCurve2d<XT, YT>): Solution.AtMostThree<number>\n }\n} = internal.solveAtX as never\n\nexport const solveAtY: {\n /**\n * Evaluates the curve's x values at a given y. Because the y polynomial is\n * `Monotonic`, the inverse has at most one solution.\n *\n * @param c - The cubic curve.\n * @param y - The y coordinate.\n * @returns Zero or one x values, in t-ascending order.\n * @since 2.0.0\n */\n <XT, YT extends Monotonic>(c: CubicCurve2d<XT, YT>, y: number): Solution.AtMostOne<number>\n /**\n * Evaluates the curve's x values at a given y. The result is the x values\n * the curve passes through where y(t) = the given y — up to three solutions\n * for a cubic curve.\n *\n * @param c - The cubic curve.\n * @param y - The y coordinate.\n * @returns The x values at y, in t-ascending order.\n * @since 2.0.0\n */\n <XT, YT>(c: CubicCurve2d<XT, YT>, y: number): Solution.AtMostThree<number>\n /** @since 2.0.0 */\n (y: number): {\n <XT, YT extends Monotonic>(c: CubicCurve2d<XT, YT>): Solution.AtMostOne<number>\n <XT, YT>(c: CubicCurve2d<XT, YT>): Solution.AtMostThree<number>\n }\n} = internal.solveAtY as never\n\nexport const curvature: {\n /**\n * Calculates the curvature of a cubic curve at a given parameter.\n *\n * @param c - The cubic curve to calculate the curvature for.\n * @param t - The parameter value.\n * @returns The curvature of the cubic curve at parameter t.\n * @since 1.0.0\n */\n (c: CubicCurve2d, t: number): number\n /**\n * Calculates the curvature of a cubic curve at a given parameter.\n *\n * @param t - The parameter value.\n * @returns A function that takes a cubic curve and returns the curvature of the cubic curve at parameter t.\n * @since 1.0.0\n */\n (t: number): (c: CubicCurve2d) => number\n} = internal.curvature\n\n/**\n * Computes the axis-aligned bounding box of the curve over its parameter\n * domain `[0, 1]`. Accounts for up to two interior extrema per axis, so the\n * box is tight against the curve and not just the control polygon.\n *\n * @param c - The cubic curve.\n * @returns A closed `Box2d` enclosing the curve.\n * @since 2.0.0\n */\nexport const boundingBox: (c: CubicCurve2d) => Interval2d<Closed, Closed> = internal.boundingBox\n\n/**\n * Type-narrowing predicate: refines both axes' traits to include `Monotonic`\n * when both x and y polynomials are monotonic over the unit interval `[0, 1]`.\n *\n * For checking only one axis, call the polynomial-level refiner directly:\n * `CubicPolynomial.isMonotonic(curve.x, Interval.unit)`.\n *\n * @since 2.0.0\n */\nexport const isMonotonic: <XT, YT>(\n c: CubicCurve2d<XT, YT>,\n) => c is CubicCurve2d<XT & Monotonic, YT & Monotonic> = internal.isMonotonic\n\n/** @since 2.0.0 */\nexport const isIncreasing: <XT, YT>(\n c: CubicCurve2d<XT, YT>,\n) => c is CubicCurve2d<XT & Increasing, YT & Increasing> = internal.isIncreasing\n\n/** @since 2.0.0 */\nexport const isDecreasing: <XT, YT>(\n c: CubicCurve2d<XT, YT>,\n) => c is CubicCurve2d<XT & Decreasing, YT & Decreasing> = internal.isDecreasing\n\n/** @since 2.0.0 */\nexport const asMonotonic: <XT, YT>(\n c: CubicCurve2d<XT, YT>,\n) => CubicCurve2d<XT & Monotonic, YT & Monotonic> = internal.asMonotonic\n\n/** @since 2.0.0 */\nexport const asIncreasing: <XT, YT>(\n c: CubicCurve2d<XT, YT>,\n) => CubicCurve2d<XT & Increasing, YT & Increasing> = internal.asIncreasing\n\n/** @since 2.0.0 */\nexport const asDecreasing: <XT, YT>(\n c: CubicCurve2d<XT, YT>,\n) => CubicCurve2d<XT & Decreasing, YT & Decreasing> = internal.asDecreasing\n","import * as Characteristic from '../characteristic/characteristic.ts'\nimport * as Interval from '../interval/interval.ts'\nimport * as Interval2d from '../interval/interval2d.ts'\nimport { dual, Pipeable } from '../utils.ts'\nimport * as CubicPolynomial from '../polynomial/cubic.ts'\nimport * as Solution from '../solution/solution.ts'\nimport { invariant } from '../utils.ts'\nimport * as Vector2 from '../vector/vector2.ts'\nimport * as Vector4 from '../vector/vector4.ts'\nimport * as CubicCurve2d from './cubic2d.ts'\nimport type { RationalCubicCurve2d } from './rationalCubic2d.ts'\n\nexport const RationalCubicCurve2dTypeId: unique symbol = Symbol('curvy/curve/rationalCubic2d')\nexport type RationalCubicCurve2dTypeId = typeof RationalCubicCurve2dTypeId\n\n// Phantom property key carrying the per-axis trait tuple. Unlike `CubicCurve2d`\n// where traits flow through to the underlying polynomials, rational curve\n// traits are properties of the projected rational functions x(t)/w(t) and\n// y(t)/w(t) — not of any individual polynomial — so the brand lives on the\n// curve itself.\n/** @internal */\nexport const RationalCurveTraits: unique symbol = Symbol.for('curvy/curve/rationalCubic2d/traits')\n/** @internal */\nexport type RationalCurveTraits = typeof RationalCurveTraits\n\n/** @internal */\nexport class RationalCubicCurve2dImpl\n extends Pipeable\n implements RationalCubicCurve2d<unknown, unknown>\n{\n readonly [RationalCubicCurve2dTypeId]: RationalCubicCurve2dTypeId = RationalCubicCurve2dTypeId\n declare readonly [RationalCurveTraits]: [unknown, unknown]\n\n readonly x: CubicPolynomial.CubicPolynomial\n readonly y: CubicPolynomial.CubicPolynomial\n readonly w: CubicPolynomial.CubicPolynomial\n\n constructor(\n x: CubicPolynomial.CubicPolynomial,\n y: CubicPolynomial.CubicPolynomial,\n w: CubicPolynomial.CubicPolynomial,\n ) {\n super()\n this.x = x\n this.y = y\n this.w = w\n }\n}\n\n/** @internal */\nexport const isRationalCubicCurve2d = (c: unknown): c is RationalCubicCurve2d =>\n typeof c === 'object' && c !== null && RationalCubicCurve2dTypeId in c\n\n/** @internal */\nexport const fromPolynomials = (\n x: CubicPolynomial.CubicPolynomial,\n y: CubicPolynomial.CubicPolynomial,\n w: CubicPolynomial.CubicPolynomial,\n): RationalCubicCurve2d => new RationalCubicCurve2dImpl(x, y, w)\n\n// Applies the cubic Bézier characteristic matrix in homogeneous space —\n// each control point is lifted to `(w·x, w·y, w)` and the same matrix that\n// drives `CubicCurve2d.fromBezierPoints` runs on each of the three channels\n// independently. The shared `w` polynomial is the projective denominator;\n// at solve time, x(t)/w(t) and y(t)/w(t) project the curve back to the plane.\n//\n// This is Freya Holmér's \"matrix IS the spline\" framing extended to rational:\n// same matrix, three channels instead of two, one projection at the end.\n/** @internal */\nexport const fromBezierPoints = (\n p0: Vector2.Weighted,\n p1: Vector2.Weighted,\n p2: Vector2.Weighted,\n p3: Vector2.Weighted,\n): RationalCubicCurve2d =>\n new RationalCubicCurve2dImpl(\n ...Characteristic.apply(\n Characteristic.cubicBezier,\n // Lift each control point to homogeneous (w·x, w·y, w), then transpose\n // the four lifted CPs into three per-channel Vector4s for the matrix.\n ...Vector4.transpose([p0, p1, p2, p3], (p) => [p.x * p.weight, p.y * p.weight, p.weight]),\n ),\n )\n\n// Gregory-Delbourgo style monotone rational cubic Hermite easing.\n//\n// Construction: rational cubic with *linear* denominator embedded in the 2D\n// pipeline by pinning x(t) = t exactly. With endpoint weights α at t=0 and\n// β at t=1, the Hermite conditions y(0)=0, y(1)=1, y'(0)=m₀, y'(1)=m₁\n// produce a closed-form cubic numerator. Monotonicity of y(t) is then a\n// degree-3 polynomial sign question — verified rigorously with the existing\n// cubic root-finder.\n//\n// The 2D embedding stores three polynomials in cubic form:\n// X(t) = t · Q(t) (quadratic, c3 = 0) so x(t)/w(t) = t\n// Y(t) = cubic numerator\n// W(t) = Q(t) = α + (β-α)·t (linear, c2 = c3 = 0)\n//\n// The α = m₀+1, β = m₁+1 choice is a serviceable heuristic — it makes\n// smoothstep (m₀=m₁=0) and linear (m₀=m₁=1) fall out for free, gives a\n// useful operating range for moderate slopes, and throws cleanly on inputs\n// it can't handle. Finding the optimal α, β formula for a wider input range\n// is a v2 problem.\n/** @internal */\nexport const makeMonotonicEasing = (startSlope: number, endSlope: number): RationalCubicCurve2d => {\n invariant(\n Number.isFinite(startSlope) && startSlope >= 0,\n 'makeMonotonicEasing: startSlope must be finite and ≥ 0',\n )\n invariant(\n Number.isFinite(endSlope) && endSlope >= 0,\n 'makeMonotonicEasing: endSlope must be finite and ≥ 0',\n )\n\n const m0 = startSlope\n const m1 = endSlope\n const alpha = m0 + 1\n const beta = m1 + 1\n\n // Numerator P(t) cubic coefficients, derived from Hermite conditions\n // y(0)=0, y(1)=1, y'(0)=m₀·α/α = m₀, y'(1)=(m₁·β + (β-α))/β = m₁:\n // c0 = 0\n // c1 = m₀·α\n // c2 = β·(2 - m₁) + α·(1 - 2m₀)\n // c3 = β·(m₁ - 1) + α·(m₀ - 1)\n const pC0 = 0\n const pC1 = m0 * alpha\n const pC2 = beta * (2 - m1) + alpha * (1 - 2 * m0)\n const pC3 = beta * (m1 - 1) + alpha * (m0 - 1)\n\n // Denominator Q(t) = α + (β-α)·t — linear, stored as cubic with c2=c3=0.\n const qC0 = alpha\n const qC1 = beta - alpha\n\n // X(t) = t · Q(t) = α·t + (β-α)·t² — quadratic, stored as cubic with c3=0.\n const xC1 = alpha\n const xC2 = beta - alpha\n\n const xPoly = CubicPolynomial.make(0, xC1, xC2, 0)\n const yPoly = CubicPolynomial.make(pC0, pC1, pC2, pC3)\n const wPoly = CubicPolynomial.make(qC0, qC1, 0, 0)\n\n // Verify monotonicity of y(t) = P(t)/Q(t) on (0, 1).\n //\n // sign(y'(t)) = sign(P'·Q - P·Q') (since Q > 0 on [0,1])\n //\n // P' is degree 2, Q is degree 1, Q' is constant — so P'·Q - P·Q' is a\n // degree-3 polynomial. We compute its coefficients and clip the roots to\n // the strict interior (0, 1); any surviving root where the polynomial\n // changes sign means y'(t) crosses zero inside the interval and the curve\n // is not monotonic.\n //\n // q(t) = m₀·α² + 2·α·a·t + (3·α·b + a·(β-α))·t² + 2·b·(β-α)·t³\n // where a = β(2-m₁) + α(1-2m₀), b = β(m₁-1) + α(m₀-1) — i.e. c2 and c3.\n const monoQ = CubicPolynomial.make(\n m0 * alpha * alpha,\n 2 * alpha * pC2,\n 3 * alpha * pC3 + pC2 * (beta - alpha),\n 2 * pC3 * (beta - alpha),\n )\n\n const interiorRoots = monoQ.pipe(CubicPolynomial.roots, Solution.clip(Interval.unitOpen))\n for (const t of interiorRoots) {\n // Check sign on both sides of the root. If the polynomial changes sign\n // across this point, monotonicity is violated.\n const epsilon = 1e-6\n const lo = Math.max(0, t - epsilon)\n const hi = Math.min(1, t + epsilon)\n const signLo = Math.sign(CubicPolynomial.solve(monoQ, lo))\n const signHi = Math.sign(CubicPolynomial.solve(monoQ, hi))\n invariant(\n signLo * signHi >= 0,\n `makeMonotonicEasing: slopes (${m0}, ${m1}) produce a non-monotonic curve with the default Gregory-Delbourgo construction. Try smaller slopes or use a different easing form.`,\n )\n }\n\n return new RationalCubicCurve2dImpl(xPoly, yPoly, wPoly)\n}\n\n/** @internal */\nexport const solve = dual<\n (t: number) => (c: RationalCubicCurve2d) => Vector2.Vector2,\n (c: RationalCubicCurve2d, t: number) => Vector2.Vector2\n>(2, (c: RationalCubicCurve2d, t: number) => {\n const w = CubicPolynomial.solve(c.w, t)\n return Vector2.make(CubicPolynomial.solve(c.x, t) / w, CubicPolynomial.solve(c.y, t) / w)\n})\n\n// Inverse-solve x(t)/w(t) = X by finding roots of X(t) - X·w(t) = 0.\n// Both X(t) and w(t) are cubic in t, so their linear combination is also\n// cubic — solvable with the existing cubic root-finder. Solutions outside\n// the [0, 1] unit interval are discarded; for each surviving t, y(t)/w(t)\n// is evaluated. The brand-aware overload narrows to `AtMostOne` for curves\n// known to be x-monotonic.\n/** @internal */\nexport const solveAtX = dual(\n 2,\n (c: RationalCubicCurve2d, x: number): Solution.Solution<number> =>\n CubicPolynomial.make(\n c.x.c0 - x * c.w.c0,\n c.x.c1 - x * c.w.c1,\n c.x.c2 - x * c.w.c2,\n c.x.c3 - x * c.w.c3,\n ).pipe(\n CubicPolynomial.roots,\n Solution.clip(Interval.unit),\n Solution.map((t) => CubicPolynomial.solve(c.y, t) / CubicPolynomial.solve(c.w, t)),\n ),\n)\n\n/** @internal */\nexport const solveAtY = dual(\n 2,\n (c: RationalCubicCurve2d, y: number): Solution.Solution<number> =>\n CubicPolynomial.make(\n c.y.c0 - y * c.w.c0,\n c.y.c1 - y * c.w.c1,\n c.y.c2 - y * c.w.c2,\n c.y.c3 - y * c.w.c3,\n ).pipe(\n CubicPolynomial.roots,\n Solution.clip(Interval.unit),\n Solution.map((t) => CubicPolynomial.solve(c.x, t) / CubicPolynomial.solve(c.w, t)),\n ),\n)\n\n// Approximation cap. At depth 20 we'd emit up to 2²⁰ ≈ 1M segments for one\n// input curve — well past any sane target — so the cap is really just a guard\n// against pathological tolerances (e.g. tolerance approaching 0).\nconst MAX_APPROX_DEPTH = 20\n\n// Builds the polynomial-cubic candidate for one rational segment by:\n// 1. Inverting Bernstein → monomial on each of x, y, w to recover the four\n// homogeneous Bézier control points (Xᵢ, Yᵢ, Wᵢ).\n// 2. Projecting each CP back to 2D as (Xᵢ/Wᵢ, Yᵢ/Wᵢ).\n// 3. Lifting those 2D CPs back to a polynomial cubic via fromBezierPoints.\n// The result matches the rational at t=0 and t=1 exactly and matches endpoint\n// tangent directions, but interior shape diverges whenever the weights are\n// not all equal.\nconst buildCubicCandidate = (c: RationalCubicCurve2d): CubicCurve2d.CubicCurve2d => {\n const x0 = c.x.c0\n const x1 = c.x.c0 + c.x.c1 / 3\n const x2 = c.x.c0 + (2 * c.x.c1) / 3 + c.x.c2 / 3\n const x3 = c.x.c0 + c.x.c1 + c.x.c2 + c.x.c3\n\n const y0 = c.y.c0\n const y1 = c.y.c0 + c.y.c1 / 3\n const y2 = c.y.c0 + (2 * c.y.c1) / 3 + c.y.c2 / 3\n const y3 = c.y.c0 + c.y.c1 + c.y.c2 + c.y.c3\n\n const w0 = c.w.c0\n const w1 = c.w.c0 + c.w.c1 / 3\n const w2 = c.w.c0 + (2 * c.w.c1) / 3 + c.w.c2 / 3\n const w3 = c.w.c0 + c.w.c1 + c.w.c2 + c.w.c3\n\n return CubicCurve2d.fromBezierPoints(\n Vector2.make(x0 / w0, y0 / w0),\n Vector2.make(x1 / w1, y1 / w1),\n Vector2.make(x2 / w2, y2 / w2),\n Vector2.make(x3 / w3, y3 / w3),\n )\n}\n\n// Splits a rational cubic at parameter `t ∈ (0, 1)` by applying\n// `CubicPolynomial.subdivide` independently to each of x, y, w. Equivalent to\n// de Casteljau on the homogeneous control polygon but stays in monomial form\n// throughout, so no Bernstein round-trip is required.\n/** @internal */\nexport const subdivide = dual<\n (t: number) => (c: RationalCubicCurve2d) => [RationalCubicCurve2d, RationalCubicCurve2d],\n (c: RationalCubicCurve2d, t: number) => [RationalCubicCurve2d, RationalCubicCurve2d]\n>(2, (c: RationalCubicCurve2d, t: number) => {\n const [leftX, rightX] = CubicPolynomial.subdivide(c.x, t)\n const [leftY, rightY] = CubicPolynomial.subdivide(c.y, t)\n const [leftW, rightW] = CubicPolynomial.subdivide(c.w, t)\n\n return [\n new RationalCubicCurve2dImpl(leftX, leftY, leftW),\n new RationalCubicCurve2dImpl(rightX, rightY, rightW),\n ]\n})\n\n// Loose bounding box from the rational's projected Bézier control polygon.\n//\n// Rational Bézier curves with positive weights satisfy the projected\n// convex-hull property: the curve lies inside the convex hull of the four\n// projected 2D control points (Wᵢ⁻¹·Xᵢ, Wᵢ⁻¹·Yᵢ). Their AABB is a strict\n// superset of the hull, so it is a valid (and cheap) bound on the curve.\n//\n// Looser than a true tight box — for that we'd need the extrema of x(t)/w(t)\n// and y(t)/w(t), each a degree-5 root problem — but tight enough for\n// subdivision-based geometric queries, which compensate via depth.\n/** @internal */\nexport const boundingBox = (\n c: RationalCubicCurve2d,\n): Interval2d.Interval2d<Interval.Closed, Interval.Closed> => {\n // Bernstein control points recovered from monomial coefficients — same\n // inversion as `buildCubicCandidate`.\n const x0 = c.x.c0\n const x1 = c.x.c0 + c.x.c1 / 3\n const x2 = c.x.c0 + (2 * c.x.c1) / 3 + c.x.c2 / 3\n const x3 = c.x.c0 + c.x.c1 + c.x.c2 + c.x.c3\n\n const y0 = c.y.c0\n const y1 = c.y.c0 + c.y.c1 / 3\n const y2 = c.y.c0 + (2 * c.y.c1) / 3 + c.y.c2 / 3\n const y3 = c.y.c0 + c.y.c1 + c.y.c2 + c.y.c3\n\n const w0 = c.w.c0\n const w1 = c.w.c0 + c.w.c1 / 3\n const w2 = c.w.c0 + (2 * c.w.c1) / 3 + c.w.c2 / 3\n const w3 = c.w.c0 + c.w.c1 + c.w.c2 + c.w.c3\n\n return Interval2d.fromVectors(\n Vector2.make(x0 / w0, y0 / w0),\n Vector2.make(x1 / w1, y1 / w1),\n Vector2.make(x2 / w2, y2 / w2),\n Vector2.make(x3 / w3, y3 / w3),\n )\n}\n\n// Certified Hausdorff-within-tolerance check between a rational and a\n// candidate polynomial cubic.\n//\n// `approximateAsCubicCurves` uses this as the stopping criterion: when it\n// returns `true`, every point on the rational is provably within `tolerance`\n// of the candidate, and every point on the candidate is within `tolerance` of\n// the rational. When `false`, the rational is subdivided and the procedure\n// recurses.\n//\n// Implementation: for each direction (rational → candidate, candidate →\n// rational), run a depth-first subdivision on the source side. At each\n// piece, compute\n//\n// lower = dist(witness-on-piece, target)\n// upper = min(\n// lower + maxDist(witness, piece.box), // triangle inequality bound\n// maxDist(piece.box, target.box), // box-pair bound\n// )\n//\n// Both upper bounds are provable; their min is too. The triangle bound\n// shrinks proportionally to source box diameter, so it dominates when source\n// and target overlap (which they usually do here — the candidate matches the\n// rational at endpoints and tangents). Early-terminate on the first piece\n// whose `lower` exceeds `tolerance` (definitive miss) or accept whenever\n// every piece's `upper` ≤ tolerance.\n\nconst MAX_HAUSDORFF_DEPTH = 30\n\n// Coarse sample + bisection on the squared-distance derivative. Returns the\n// minimum squared distance from (qx, qy) to a parametric curve described by\n// `eval_`. Stationary points of (P(s) - q) · P'(s) are local extrema of\n// D²(s); 32 coarse samples reliably bracket the global min for cubic-degree\n// curves (which have at most ~5 critical points of squared distance).\nconst closestSquaredDistance = (\n eval_: (s: number) => { px: number; py: number; tx: number; ty: number },\n qx: number,\n qy: number,\n): number => {\n const coarseSamples = 32\n let sBest = 0\n let d2Best = Number.POSITIVE_INFINITY\n for (let i = 0; i <= coarseSamples; i++) {\n const s = i / coarseSamples\n const { px, py } = eval_(s)\n const dx = px - qx\n const dy = py - qy\n const d2 = dx * dx + dy * dy\n if (d2 < d2Best) {\n d2Best = d2\n sBest = s\n }\n }\n const step = 1 / coarseSamples\n let lo = Math.max(0, sBest - step)\n let hi = Math.min(1, sBest + step)\n const gradient = (s: number): number => {\n const { px, py, tx, ty } = eval_(s)\n return (px - qx) * tx + (py - qy) * ty\n }\n if (gradient(lo) > 0 || gradient(hi) < 0) {\n return d2Best\n }\n for (let i = 0; i < 40; i++) {\n const m = 0.5 * (lo + hi)\n if (gradient(m) > 0) {\n hi = m\n } else {\n lo = m\n }\n if (hi - lo < 1e-12) {\n break\n }\n }\n const s = 0.5 * (lo + hi)\n const { px, py } = eval_(s)\n const dx = px - qx\n const dy = py - qy\n const d2 = dx * dx + dy * dy\n return d2 < d2Best ? d2 : d2Best\n}\n\nconst polynomialEval = (c: CubicCurve2d.CubicCurve2d, s: number) => ({\n px: c.x.c0 + s * (c.x.c1 + s * (c.x.c2 + s * c.x.c3)),\n py: c.y.c0 + s * (c.y.c1 + s * (c.y.c2 + s * c.y.c3)),\n tx: c.x.c1 + s * (2 * c.x.c2 + s * 3 * c.x.c3),\n ty: c.y.c1 + s * (2 * c.y.c2 + s * 3 * c.y.c3),\n})\n\n// R(s) = (X(s)/W(s), Y(s)/W(s)) → R'(s) = ((X'W - XW')/W², (Y'W - YW')/W²)\nconst rationalEval = (c: RationalCubicCurve2d, s: number) => {\n const X = c.x.c0 + s * (c.x.c1 + s * (c.x.c2 + s * c.x.c3))\n const Y = c.y.c0 + s * (c.y.c1 + s * (c.y.c2 + s * c.y.c3))\n const W = c.w.c0 + s * (c.w.c1 + s * (c.w.c2 + s * c.w.c3))\n const Xp = c.x.c1 + s * (2 * c.x.c2 + s * 3 * c.x.c3)\n const Yp = c.y.c1 + s * (2 * c.y.c2 + s * 3 * c.y.c3)\n const Wp = c.w.c1 + s * (2 * c.w.c2 + s * 3 * c.w.c3)\n const w2 = W * W\n return {\n px: X / W,\n py: Y / W,\n tx: (Xp * W - X * Wp) / w2,\n ty: (Yp * W - Y * Wp) / w2,\n }\n}\n\nconst maxDistFromPointToBox = (px: number, py: number, box: Interval2d.Interval2d): number => {\n const xLo = Math.min(box.x.start, box.x.end)\n const xHi = Math.max(box.x.start, box.x.end)\n const yLo = Math.min(box.y.start, box.y.end)\n const yHi = Math.max(box.y.start, box.y.end)\n const dx = Math.max(px - xLo, xHi - px)\n const dy = Math.max(py - yLo, yHi - py)\n return Math.hypot(dx, dy)\n}\n\n// Subdivide a polynomial cubic curve at parameter t by subdividing each\n// per-axis polynomial independently — the polynomial split is exact and in\n// monomial form.\nconst subdividePolynomial = (\n c: CubicCurve2d.CubicCurve2d,\n t: number,\n): [CubicCurve2d.CubicCurve2d, CubicCurve2d.CubicCurve2d] => {\n const [leftX, rightX] = CubicPolynomial.subdivide(c.x, t)\n const [leftY, rightY] = CubicPolynomial.subdivide(c.y, t)\n return [CubicCurve2d.fromPolynomials(leftX, leftY), CubicCurve2d.fromPolynomials(rightX, rightY)]\n}\n\ninterface CertifiedPiece {\n box: Interval2d.Interval2d\n witnessX: number\n witnessY: number\n depth: number\n subdivide(): [CertifiedPiece, CertifiedPiece]\n}\n\nconst rationalPiece = (c: RationalCubicCurve2d, depth = 0): CertifiedPiece => {\n const wMid = CubicPolynomial.solve(c.w, 0.5)\n const witnessX = CubicPolynomial.solve(c.x, 0.5) / wMid\n const witnessY = CubicPolynomial.solve(c.y, 0.5) / wMid\n return {\n box: boundingBox(c),\n witnessX,\n witnessY,\n depth,\n subdivide: () => {\n const [left, right] = subdivide(c, 0.5)\n return [rationalPiece(left, depth + 1), rationalPiece(right, depth + 1)]\n },\n }\n}\n\nconst polynomialPiece = (c: CubicCurve2d.CubicCurve2d, depth = 0): CertifiedPiece => {\n const witnessX = CubicPolynomial.solve(c.x, 0.5)\n const witnessY = CubicPolynomial.solve(c.y, 0.5)\n return {\n box: CubicCurve2d.boundingBox(c),\n witnessX,\n witnessY,\n depth,\n subdivide: () => {\n const [left, right] = subdividePolynomial(c, 0.5)\n return [polynomialPiece(left, depth + 1), polynomialPiece(right, depth + 1)]\n },\n }\n}\n\nconst oneSidedWithinTolerance = (\n initialPiece: CertifiedPiece,\n targetBox: Interval2d.Interval2d,\n targetClosestSquared: (qx: number, qy: number) => number,\n tolerance: number,\n): boolean => {\n const tol2 = tolerance * tolerance\n const stack: Array<CertifiedPiece> = [initialPiece]\n while (stack.length > 0) {\n const piece = stack.pop() as CertifiedPiece\n const lower2 = targetClosestSquared(piece.witnessX, piece.witnessY)\n if (lower2 > tol2) {\n return false\n }\n const lower = Math.sqrt(lower2)\n const triangleUpper = lower + maxDistFromPointToBox(piece.witnessX, piece.witnessY, piece.box)\n const boxPairUpper = Interval2d.maxDistance(piece.box, targetBox)\n const upper = triangleUpper < boxPairUpper ? triangleUpper : boxPairUpper\n if (upper <= tolerance) {\n continue\n }\n if (piece.depth >= MAX_HAUSDORFF_DEPTH) {\n return false\n }\n const [left, right] = piece.subdivide()\n stack.push(left, right)\n }\n return true\n}\n\nconst hausdorffWithinTolerance = (\n rational: RationalCubicCurve2d,\n candidate: CubicCurve2d.CubicCurve2d,\n tolerance: number,\n): boolean => {\n // Algebraic fast path: when the denominator polynomial is constant — every\n // weighted Bézier control point shares the same weight, so the rational\n // reduces to a polynomial cubic — `buildCubicCandidate` is exact. The\n // Bernstein → monomial transform produces exact zero higher coefficients\n // for a uniform input (integer cancellation), and `CubicPolynomial.subdivide`\n // preserves constants, so this check holds at every recursion depth.\n //\n // Without this fast path the subdivision Hausdorff would take ~30 levels\n // to certify the coincident-curve case at sub-pixel tolerances, even\n // though the answer is exactly zero.\n if (rational.w.c1 === 0 && rational.w.c2 === 0 && rational.w.c3 === 0) {\n return true\n }\n\n const candidateBox = CubicCurve2d.boundingBox(candidate)\n if (\n !oneSidedWithinTolerance(\n rationalPiece(rational),\n candidateBox,\n (qx, qy) => closestSquaredDistance((s) => polynomialEval(candidate, s), qx, qy),\n tolerance,\n )\n ) {\n return false\n }\n const rationalBox = boundingBox(rational)\n return oneSidedWithinTolerance(\n polynomialPiece(candidate),\n rationalBox,\n (qx, qy) => closestSquaredDistance((s) => rationalEval(rational, s), qx, qy),\n tolerance,\n )\n}\n\n/** @internal */\nexport const approximateAsCubicCurves = dual<\n (tolerance: number) => (c: RationalCubicCurve2d) => ReadonlyArray<CubicCurve2d.CubicCurve2d>,\n (c: RationalCubicCurve2d, tolerance: number) => ReadonlyArray<CubicCurve2d.CubicCurve2d>\n>(2, (c: RationalCubicCurve2d, tolerance: number) => {\n invariant(\n Number.isFinite(tolerance) && tolerance > 0,\n 'approximateAsCubicCurves: tolerance must be finite and > 0',\n )\n\n const out: Array<CubicCurve2d.CubicCurve2d> = []\n const recurse = (curr: RationalCubicCurve2d, depth: number): void => {\n const candidate = buildCubicCandidate(curr)\n if (depth >= MAX_APPROX_DEPTH || hausdorffWithinTolerance(curr, candidate, tolerance)) {\n out.push(candidate)\n return\n }\n const [left, right] = subdivide(curr, 0.5)\n recurse(left, depth + 1)\n recurse(right, depth + 1)\n }\n recurse(c, 0)\n return out\n})\n","import type { Closed } from '../interval/interval.ts'\nimport type { Interval2d } from '../interval/interval2d.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { CubicPolynomial } from '../polynomial/cubic.ts'\nimport type { Increasing, Monotonic } from '../polynomial/traits.ts'\nimport type * as Solution from '../solution/solution.ts'\nimport type { Vector2, Weighted } from '../vector/vector2.ts'\nimport type { CubicCurve2d } from './cubic2d.ts'\nimport type { RationalCubicCurve2dTypeId, RationalCurveTraits } from './rationalCubic2d.internal.ts'\nimport * as internal from './rationalCubic2d.internal.ts'\n\nexport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits.ts'\nexport { RationalCurveTraits } from './rationalCubic2d.internal.ts'\n\n/**\n * A rational cubic curve in 2D space.\n *\n * Represented as three cubic polynomials in the parameter `t`: per-axis\n * numerators `x`, `y`, and a shared denominator `w`. Evaluation is\n * `(x(t)/w(t), y(t)/w(t))` — the projection from homogeneous coordinates\n * back to the plane. With all weights equal at the source (e.g. produced\n * from a non-rational Bézier with unit weights), `w` is constant and the\n * curve coincides with a polynomial cubic.\n *\n * The two type parameters carry per-axis monotonicity trait brands attached\n * to the rational functions `x(t)/w(t)` and `y(t)/w(t)`. Unlike\n * `CubicCurve2d`, traits do not flow through to the underlying polynomials —\n * monotonicity of a ratio of cubics is not the same property as monotonicity\n * of either cubic alone, so the brand lives on the curve itself. Constructors\n * with construction-time monotonicity guarantees (e.g. {@link makeMonotonicEasing})\n * return curves with `Increasing` brands attached, narrowing downstream\n * operations like {@link solveAtX} to single-solution returns.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 2.0.0\n */\nexport interface RationalCubicCurve2d<\n out XTraits = unknown,\n out YTraits = unknown,\n> extends Pipeable {\n readonly [RationalCubicCurve2dTypeId]: RationalCubicCurve2dTypeId\n readonly [RationalCurveTraits]: [XTraits, YTraits]\n readonly x: CubicPolynomial\n readonly y: CubicPolynomial\n readonly w: CubicPolynomial\n}\n\n/**\n * Checks if a value is a `RationalCubicCurve2d`.\n *\n * @param c - The value to check.\n * @returns `true` if the value is a `RationalCubicCurve2d`, `false` otherwise.\n * @since 2.0.0\n */\nexport const isRationalCubicCurve2d: (c: unknown) => c is RationalCubicCurve2d =\n internal.isRationalCubicCurve2d\n\n/**\n * Creates a new `RationalCubicCurve2d` from per-axis numerator polynomials\n * and a shared denominator polynomial.\n *\n * @param x - The x numerator polynomial.\n * @param y - The y numerator polynomial.\n * @param w - The shared denominator polynomial (must be non-zero on `[0, 1]`).\n * @returns A new `RationalCubicCurve2d` instance.\n * @since 2.0.0\n */\nexport const fromPolynomials: (\n x: CubicPolynomial,\n y: CubicPolynomial,\n w: CubicPolynomial,\n) => RationalCubicCurve2d = internal.fromPolynomials\n\n/**\n * Creates a new `RationalCubicCurve2d` from four weighted cubic Bézier\n * control points. The four control points are lifted to homogeneous form\n * `(w·x, w·y, w)` and the cubic Bernstein basis is expanded into per-channel\n * monomial coefficients, yielding the curve's `x`, `y`, and `w` polynomials.\n *\n * @param p0 - The first weighted control point (curve start).\n * @param p1 - The second weighted control point (start handle).\n * @param p2 - The third weighted control point (end handle).\n * @param p3 - The fourth weighted control point (curve end).\n * @returns A new `RationalCubicCurve2d` instance.\n * @since 2.0.0\n */\nexport const fromBezierPoints: (\n p0: Weighted,\n p1: Weighted,\n p2: Weighted,\n p3: Weighted,\n) => RationalCubicCurve2d = internal.fromBezierPoints\n\n/**\n * Creates a guaranteed-monotonic rational cubic easing curve via Gregory-\n * Delbourgo style construction. The result interpolates `(0, 0)` and\n * `(1, 1)` with the given endpoint slopes, with `x(t) = t` pinned linearly\n * and a rational cubic numerator for `y(t)`. Monotonicity of `y(t)` is\n * verified rigorously at construction (degree-3 polynomial sign analysis);\n * the returned curve is branded `<Increasing, Increasing>` so that\n * {@link solveAtX} returns `Solution.AtMostOne<number>` without further\n * trait refinement.\n *\n * For input slope combinations that the default Gregory-Delbourgo\n * construction cannot accommodate (typically when one slope is large while\n * the other is small), construction throws. Useful operating range is\n * roughly `m₀, m₁ ∈ [0, 2]` with `m₀ + m₁ ≲ 3`; smoothstep (`0, 0`) and\n * linear (`1, 1`) fall out as special cases.\n *\n * @param startSlope - The easing function's slope at the start (`dy/dx` at `x = 0`); must be finite and non-negative.\n * @param endSlope - The easing function's slope at the end (`dy/dx` at `x = 1`); must be finite and non-negative.\n * @returns A monotone-by-construction rational cubic easing curve.\n * @throws When slopes are negative, non-finite, or produce a non-monotonic curve under the default construction.\n * @since 2.0.0\n */\nexport const makeMonotonicEasing: (\n startSlope: number,\n endSlope: number,\n) => RationalCubicCurve2d<Increasing, Increasing> = internal.makeMonotonicEasing as never\n\nexport const solve: {\n /**\n * Evaluates the rational cubic curve at parameter `t`. Returns\n * `(x(t)/w(t), y(t)/w(t))` — three Horner evaluations and two divisions.\n *\n * @param c - The curve to evaluate.\n * @param t - The parameter value.\n * @returns The point on the curve at parameter `t`.\n * @since 2.0.0\n */\n (c: RationalCubicCurve2d, t: number): Vector2\n /**\n * Evaluates the rational cubic curve at parameter `t`.\n *\n * @param t - The parameter value.\n * @returns A function that takes a curve and returns the point at `t`.\n * @since 2.0.0\n */\n (t: number): (c: RationalCubicCurve2d) => Vector2\n} = internal.solve\n\nexport const solveAtX: {\n /**\n * Evaluates the curve's y values at a given x. Because the curve's x axis\n * carries the `Monotonic` brand, the inverse has at most one solution.\n *\n * @param c - The rational cubic curve with monotonic x.\n * @param x - The x coordinate.\n * @returns Zero or one y values.\n * @since 2.0.0\n */\n <XT extends Monotonic, YT>(c: RationalCubicCurve2d<XT, YT>, x: number): Solution.AtMostOne<number>\n /**\n * Evaluates the curve's y values at a given x. Up to three solutions —\n * `(X(t) - x·W(t))` is a cubic polynomial in `t`.\n *\n * @param c - The rational cubic curve.\n * @param x - The x coordinate.\n * @returns The y values at x, in t-ascending order.\n * @since 2.0.0\n */\n <XT, YT>(c: RationalCubicCurve2d<XT, YT>, x: number): Solution.AtMostThree<number>\n /** @since 2.0.0 */\n (x: number): {\n <XT extends Monotonic, YT>(c: RationalCubicCurve2d<XT, YT>): Solution.AtMostOne<number>\n <XT, YT>(c: RationalCubicCurve2d<XT, YT>): Solution.AtMostThree<number>\n }\n} = internal.solveAtX as never\n\nexport const solveAtY: {\n /**\n * Evaluates the curve's x values at a given y. Because the curve's y axis\n * carries the `Monotonic` brand, the inverse has at most one solution.\n *\n * @param c - The rational cubic curve with monotonic y.\n * @param y - The y coordinate.\n * @returns Zero or one x values.\n * @since 2.0.0\n */\n <XT, YT extends Monotonic>(c: RationalCubicCurve2d<XT, YT>, y: number): Solution.AtMostOne<number>\n /**\n * Evaluates the curve's x values at a given y. Up to three solutions.\n *\n * @param c - The rational cubic curve.\n * @param y - The y coordinate.\n * @returns The x values at y, in t-ascending order.\n * @since 2.0.0\n */\n <XT, YT>(c: RationalCubicCurve2d<XT, YT>, y: number): Solution.AtMostThree<number>\n /** @since 2.0.0 */\n (y: number): {\n <XT, YT extends Monotonic>(c: RationalCubicCurve2d<XT, YT>): Solution.AtMostOne<number>\n <XT, YT>(c: RationalCubicCurve2d<XT, YT>): Solution.AtMostThree<number>\n }\n} = internal.solveAtY as never\n\nexport const subdivide: {\n /**\n * Subdivides a rational cubic curve at parameter `t ∈ (0, 1)` into two new\n * rational cubic curves. The first curve's evaluation on `[0, 1]` matches\n * the original's on `[0, t]`; the second matches the original's on `[t, 1]`.\n * Equivalent to de Casteljau subdivision on the homogeneous control polygon,\n * but performed directly on the per-axis monomial polynomials.\n *\n * @param c - The rational cubic curve to subdivide.\n * @param t - The split parameter; must be in the open interval `(0, 1)`.\n * @returns A `[left, right]` tuple of rational cubic curves.\n * @since 2.0.0\n */\n (c: RationalCubicCurve2d, t: number): [RationalCubicCurve2d, RationalCubicCurve2d]\n /**\n * Subdivides a rational cubic curve at parameter `t ∈ (0, 1)`.\n *\n * @param t - The split parameter; must be in the open interval `(0, 1)`.\n * @returns A function that takes a curve and returns its `[left, right]` halves.\n * @since 2.0.0\n */\n (t: number): (c: RationalCubicCurve2d) => [RationalCubicCurve2d, RationalCubicCurve2d]\n} = internal.subdivide\n\n/**\n * Computes a closed axis-aligned bounding box for a rational cubic curve from\n * its projected control polygon. Looser than the tight extrema-based box used\n * by `CubicCurve2d.boundingBox` — finding tight extrema of `x(t)/w(t)` and\n * `y(t)/w(t)` requires solving degree-5 polynomials — but always valid: a\n * positive-weight rational Bézier curve lies inside the convex hull of its\n * projected control points, so the AABB of those points contains the curve.\n *\n * Suitable for subdivision-based geometric queries, where bound looseness is\n * compensated by recursion depth.\n *\n * @param c - The rational cubic curve.\n * @returns A closed `Interval2d` enclosing the curve.\n * @since 2.0.0\n */\nexport const boundingBox: (c: RationalCubicCurve2d) => Interval2d<Closed, Closed> =\n internal.boundingBox\n\nexport const approximateAsCubicCurves: {\n /**\n * Approximates the rational cubic as a sequence of polynomial cubic curves\n * via recursive subdivision. At each level a candidate polynomial cubic is\n * built by projecting the segment's homogeneous Bézier control points to\n * 2D; if the symmetric Hausdorff distance between the rational segment and\n * its candidate exceeds `tolerance` (verified via a certified subdivision\n * bound, not a single-point sample), the segment is split at `t = 0.5` and\n * the procedure recurses on each half. Returns a non-empty array; for a\n * curve that is already polynomial (uniform weights) the result is a\n * single exact segment.\n *\n * The Hausdorff guarantee means: every point on the rational lies within\n * `tolerance` of some output segment, and every point on the output lies\n * within `tolerance` of the rational — a true two-sided bound on geometric\n * deviation, not just a parametric error at one sample.\n *\n * @param c - The rational cubic curve to approximate.\n * @param tolerance - Maximum allowed Hausdorff distance; must be positive.\n * @returns A sequence of polynomial cubic curves covering the input.\n * @since 2.0.0\n */\n (c: RationalCubicCurve2d, tolerance: number): ReadonlyArray<CubicCurve2d>\n /**\n * Approximates the rational cubic as a sequence of polynomial cubic curves.\n *\n * @param tolerance - Maximum allowed Hausdorff distance; must be positive.\n * @returns A function that takes a curve and returns its polynomial approximation.\n * @since 2.0.0\n */\n (tolerance: number): (c: RationalCubicCurve2d) => ReadonlyArray<CubicCurve2d>\n} = internal.approximateAsCubicCurves\n"],"mappings":";;;;;;;;;;;AASA,MAAa,sBAAqC,OAAO,uBAAuB;;AAIhF,IAAa,oBAAb,cAAuC,SAAoD;CACzF,CAAU,uBAA4C;CAEtD;CACA;CAEA,YAAY,IAAuC,IAAuC;EACxF,OAAO;EACP,KAAK,IAAI;EACT,KAAK,IAAI;;CAGX,KAAK,KAAK;EACR,OAAO,KAAK;;CAGd,KAAK,KAAK;EACR,OAAO,KAAK;;;;AAKhB,MAAaA,qBAGS,IAAI,OAAO,IAAI,kBAAkB,IAAI,GAAG;;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