curvy 2.0.0-alpha.2 → 2.0.0-alpha.4

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 (63) hide show
  1. package/dist/characteristic/index.d.mts +9 -9
  2. package/dist/characteristic/index.mjs +1 -1
  3. package/dist/curve/index.d.mts +10 -2
  4. package/dist/curve/index.mjs +1 -1
  5. package/dist/interval/index.d.mts +9 -3
  6. package/dist/interval/index.mjs +2 -2
  7. package/dist/matrix/index.d.mts +9 -2
  8. package/dist/path/index.d.mts +15 -223
  9. package/dist/path/index.mjs +6 -6
  10. package/dist/path/index.mjs.map +1 -1
  11. package/dist/polynomial/index.d.mts +9 -2
  12. package/dist/polynomial/index.mjs +2 -2
  13. package/dist/shared/{characteristic-B9nCh_cx.mjs → characteristic-DLlhja-I.mjs} +9 -9
  14. package/dist/shared/{characteristic-B9nCh_cx.mjs.map → characteristic-DLlhja-I.mjs.map} +1 -1
  15. package/dist/shared/{cubic-CpHAx8cC.mjs → cubic-CMonq6bg.mjs} +26 -5
  16. package/dist/shared/cubic-CMonq6bg.mjs.map +1 -0
  17. package/dist/shared/cubic-DkBqcZf-.d.mts +121 -0
  18. package/dist/shared/interval-Bhzeqp8M.d.mts +62 -0
  19. package/dist/shared/{interval-05CR6eBf.mjs → interval-X1EYuf-T.mjs} +2 -2
  20. package/dist/shared/{interval-05CR6eBf.mjs.map → interval-X1EYuf-T.mjs.map} +1 -1
  21. package/dist/shared/interval2d-BMk5UYXD.d.mts +29 -0
  22. package/dist/shared/{interval2d-8IBZnUOq.mjs → interval2d-ca0J1NMr.mjs} +8 -8
  23. package/dist/shared/{interval2d-8IBZnUOq.mjs.map → interval2d-ca0J1NMr.mjs.map} +1 -1
  24. package/dist/shared/matrix4x4-CaytTaB_.d.mts +168 -0
  25. package/dist/shared/{quadratic-CamozcFc.mjs → quadratic-DyeMtvET.mjs} +20 -2
  26. package/dist/shared/quadratic-DyeMtvET.mjs.map +1 -0
  27. package/dist/shared/rationalCubic2d-D-UevGKu.d.mts +60 -0
  28. package/dist/shared/{rationalCubic2d-Bys2Uory.mjs → rationalCubic2d-D658ltUM.mjs} +17 -17
  29. package/dist/shared/{rationalCubic2d-Bys2Uory.mjs.map → rationalCubic2d-D658ltUM.mjs.map} +1 -1
  30. package/dist/shared/rationalCubic2d-MgMSJaAU.d.mts +104 -0
  31. package/dist/shared/{rationalCubic2d-BEgUGSFf.mjs → rationalCubic2d-Vw4qGPZj.mjs} +9 -9
  32. package/dist/shared/{rationalCubic2d-BEgUGSFf.mjs.map → rationalCubic2d-Vw4qGPZj.mjs.map} +1 -1
  33. package/dist/shared/{solution-CrtLfqEq.mjs → solution-3TDATEMn.mjs} +28 -2
  34. package/dist/shared/solution-3TDATEMn.mjs.map +1 -0
  35. package/dist/shared/solution-DInDT2Hq.d.mts +60 -0
  36. package/dist/shared/{vector2-CL1HDdPr.mjs → vector2-CCuJx1rX.mjs} +6 -6
  37. package/dist/shared/{vector2-CL1HDdPr.mjs.map → vector2-CCuJx1rX.mjs.map} +1 -1
  38. package/dist/shared/vector2-euuV_bNQ.d.mts +58 -0
  39. package/dist/shared/vector3-3Xx7GVk7.d.mts +37 -0
  40. package/dist/shared/{vector3-D-tv_aKL.mjs → vector3-C-qgKAjR.mjs} +2 -2
  41. package/dist/shared/{vector3-D-tv_aKL.mjs.map → vector3-C-qgKAjR.mjs.map} +1 -1
  42. package/dist/shared/{vector4-5KbjoHVj.mjs → vector4-BhOKDhD5.mjs} +2 -2
  43. package/dist/shared/{vector4-5KbjoHVj.mjs.map → vector4-BhOKDhD5.mjs.map} +1 -1
  44. package/dist/solution/index.d.mts +7 -2
  45. package/dist/solution/index.mjs +1 -1
  46. package/dist/splines/index.d.mts +37 -606
  47. package/dist/splines/index.mjs +193 -35
  48. package/dist/splines/index.mjs.map +1 -1
  49. package/dist/vector/index.d.mts +10 -3
  50. package/dist/vector/index.mjs +3 -3
  51. package/package.json +1 -1
  52. package/dist/shared/cubic-BajUY0JT.d.mts +0 -1100
  53. package/dist/shared/cubic-CpHAx8cC.mjs.map +0 -1
  54. package/dist/shared/interval-Dy-RMEE3.d.mts +0 -533
  55. package/dist/shared/interval2d-C2id9u31.d.mts +0 -172
  56. package/dist/shared/matrix4x4-Dm_tSiH1.d.mts +0 -1183
  57. package/dist/shared/quadratic-CamozcFc.mjs.map +0 -1
  58. package/dist/shared/rationalCubic2d-B6g97ryJ.d.mts +0 -308
  59. package/dist/shared/rationalCubic2d-DlQfBURs.d.mts +0 -818
  60. package/dist/shared/solution-CrtLfqEq.mjs.map +0 -1
  61. package/dist/shared/solution-sNQ-ZVhN.d.mts +0 -251
  62. package/dist/shared/vector2-DPUY3_eA.d.mts +0 -470
  63. package/dist/shared/vector3-DqeOZtOB.d.mts +0 -703
@@ -1 +1 @@
1
- {"version":3,"file":"rationalCubic2d-Bys2Uory.mjs","names":["fromPolynomials","fromCoefficients","LinearPolynomial.make","fromBezierPoints","isLinearCurve2d","derivative","Vector2.make","solve","LinearPolynomial.solve","solveAtX","Solution.match","LinearPolynomial.solveInverse","Solution.none","Solution.one","solveAtY","length","boundingBox","Interval2d.make","LinearPolynomial.range","Interval.unit","isMonotonic","LinearPolynomial.isMonotonic","isIncreasing","LinearPolynomial.isIncreasing","isDecreasing","LinearPolynomial.isDecreasing","fail","asMonotonic","asIncreasing","asDecreasing","fromPolynomials","internal.fromPolynomials","fromCoefficients","internal.fromCoefficients","fromBezierPoints","internal.fromBezierPoints","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.range","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.range","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","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","CubicPolynomial.subdivide","approximateAsCubicCurves","internal.isRationalCubicCurve2d","internal.fromPolynomials","internal.fromBezierPoints","internal.makeMonotonicEasing","internal.solve","internal.solveAtX","internal.solveAtY","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'\nimport * as Interval from '../interval/interval'\nimport { dual, Pipeable } from '../utils'\nimport * as LinearPolynomial from '../polynomial/linear'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits'\nimport * as Solution from '../solution/solution'\nimport * as Vector2 from '../vector/vector2'\nimport type { LinearCurve2d } from './linear2d'\n\nexport const LinearCurve2dTypeId: unique symbol = Symbol('curvy/curve/linear2d')\nexport type LinearCurve2dTypeId = typeof LinearCurve2dTypeId\n\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\nexport const fromPolynomials: (\n c0: LinearPolynomial.LinearPolynomial,\n c1: LinearPolynomial.LinearPolynomial,\n) => LinearCurve2d = (c0, c1) => new LinearCurve2dImpl(c0, c1)\n\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.\nexport const fromBezierPoints: (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\nexport const isLinearCurve2d = (c: unknown): c is LinearCurve2d =>\n typeof c === 'object' && c !== null && LinearCurve2dTypeId in c\n\nexport const derivative = (c: LinearCurve2d) => Vector2.make(c.x.c1, c.y.c1)\n\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.\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\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\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\nexport const boundingBox = (\n c: LinearCurve2d,\n): Interval2d.Interval2d<Interval.Closed, Interval.Closed> =>\n Interval2d.make(\n LinearPolynomial.range(c.x, Interval.unit),\n LinearPolynomial.range(c.y, Interval.unit),\n )\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.\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\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\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\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\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\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'\nimport type { TwoDimensional } from '../dimensions'\nimport type { Closed, Interval } from '../interval/interval'\nimport type { Pipeable } from '../utils'\nimport type { LinearPolynomial } from '../polynomial/linear'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits'\nimport type * as Solution from '../solution/solution'\nimport type { Vector2 } from '../vector/vector2'\nimport type { LinearCurve2dTypeId } from './linear2d.internal'\nimport * as internal from './linear2d.internal'\n\nexport type { Monotonic, Increasing, Decreasing } from '../polynomial/traits'\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 fromBezierPoints: (p0: Vector2, p1: Vector2) => LinearCurve2d =\n internal.fromBezierPoints\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.1.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'\nimport * as Interval from '../interval/interval'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits'\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'\nimport { dual, Pipeable } from '../utils'\nimport * as LinearPolynomial from '../polynomial/linear'\nimport * as QuadraticPolynomial from '../polynomial/quadratic'\nimport * as Solution from '../solution/solution'\nimport * as Vector2 from '../vector/vector2'\nimport * as LinearCurve2d from './linear2d'\nimport type { QuadraticCurve2d } from './quadratic2d'\n\nexport const QuadraticCurve2dTypeId: unique symbol = Symbol('curvy/curve/quadratic2d')\nexport type QuadraticCurve2dTypeId = typeof QuadraticCurve2dTypeId\n\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\nexport const fromPolynomials: (\n c0: QuadraticPolynomial.QuadraticPolynomial,\n c1: QuadraticPolynomial.QuadraticPolynomial,\n) => QuadraticCurve2d = (c0, c1) => new QuadraticCurve2dImpl(c0, c1)\n\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\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\nexport const isQuadraticCurve2d = (c: unknown): c is QuadraticCurve2d =>\n typeof c === 'object' && c !== null && QuadraticCurve2dTypeId in c\n\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).\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\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\nexport const derivative = (c: QuadraticCurve2d) =>\n LinearCurve2d.fromPolynomials(\n QuadraticPolynomial.derivative(c.x),\n QuadraticPolynomial.derivative(c.y),\n )\n\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\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\nexport const boundingBox = (\n c: QuadraticCurve2d,\n): Interval2d.Interval2d<Interval.Closed, Interval.Closed> =>\n Interval2d.make(\n QuadraticPolynomial.range(c.x, Interval.unit),\n QuadraticPolynomial.range(c.y, Interval.unit),\n )\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.\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\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\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\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\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\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'\nimport type { TwoDimensional } from '../dimensions'\nimport type { Closed, Interval } from '../interval/interval'\nimport type { Pipeable } from '../utils'\nimport type { QuadraticPolynomial } from '../polynomial/quadratic'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits'\nimport type * as Solution from '../solution/solution'\nimport type { Vector2 } from '../vector/vector2'\nimport type { LinearCurve2d } from './linear2d'\nimport type { QuadraticCurve2dTypeId } from './quadratic2d.internal'\nimport * as internal from './quadratic2d.internal'\n\nexport type { Monotonic, Increasing, Decreasing } from '../polynomial/traits'\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.1.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'\nimport * as Characteristic from '../characteristic/characteristic'\nimport * as Interval from '../interval/interval'\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'\nimport { dual, Pipeable } from '../utils'\nimport * as CubicPolynomial from '../polynomial/cubic'\nimport * as QuadraticPolynomial from '../polynomial/quadratic'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits'\nimport * as Solution from '../solution/solution'\nimport * as Vector2 from '../vector/vector2'\nimport * as Vector4 from '../vector/vector4'\nimport type { CubicCurve2d } from './cubic2d'\nimport * as LinearCurve2d from './linear2d'\nimport * as QuadraticCurve2d from './quadratic2d'\n\nexport const CubicCurve2dTypeId: unique symbol = Symbol('curvy/curve/cubic2d')\nexport type CubicCurve2dTypeId = typeof CubicCurve2dTypeId\n\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\nexport const fromPolynomials: (\n c0: CubicPolynomial.CubicPolynomial,\n c1: CubicPolynomial.CubicPolynomial,\n) => CubicCurve2d = (c0, c1) => new CubicCurve2dImpl(c0, c1)\n\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.\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\nexport const isCubicCurve2d = (c: unknown): c is CubicCurve2d =>\n typeof c === 'object' && c !== null && CubicCurve2dTypeId in c\n\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).\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\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\nexport const derivative = (c: CubicCurve2d) =>\n QuadraticCurve2d.fromPolynomials(CubicPolynomial.derivative(c.x), CubicPolynomial.derivative(c.y))\n\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\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\nexport const boundingBox = (\n c: CubicCurve2d,\n): Interval2d.Interval2d<Interval.Closed, Interval.Closed> =>\n Interval2d.make(\n CubicPolynomial.range(c.x, Interval.unit),\n CubicPolynomial.range(c.y, Interval.unit),\n )\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.\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\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\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\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\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\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'\nimport type { TwoDimensional } from '../dimensions'\nimport type { Closed, Interval } from '../interval/interval'\nimport type { Pipeable } from '../utils'\nimport type { CubicPolynomial } from '../polynomial/cubic'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits'\nimport type * as Solution from '../solution/solution'\nimport type { Vector2 } from '../vector/vector2'\nimport type { CubicCurve2dTypeId } from './cubic2d.internal'\nimport * as internal from './cubic2d.internal'\n\nexport type { Monotonic, Increasing, Decreasing } from '../polynomial/traits'\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.1.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'\nimport * as Interval from '../interval/interval'\nimport { dual, Pipeable } from '../utils'\nimport * as CubicPolynomial from '../polynomial/cubic'\nimport * as Solution from '../solution/solution'\nimport { invariant } from '../utils'\nimport * as Vector2 from '../vector/vector2'\nimport * as Vector4 from '../vector/vector4'\nimport * as CubicCurve2d from './cubic2d'\nimport type { RationalCubicCurve2d } from './rationalCubic2d'\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.\nexport const RationalCurveTraits: unique symbol = Symbol.for('curvy/curve/rationalCubic2d/traits')\nexport type RationalCurveTraits = typeof RationalCurveTraits\n\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\nexport const isRationalCubicCurve2d = (c: unknown): c is RationalCubicCurve2d =>\n typeof c === 'object' && c !== null && RationalCubicCurve2dTypeId in c\n\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.\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.\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\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.\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\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 t = 0.5 by applying `CubicPolynomial.subdivide`\n// independently to each of x, y, w. Equivalent to de Casteljau in Bernstein\n// space but stays in monomial form throughout.\nconst splitAtHalf = (c: RationalCubicCurve2d): [RationalCubicCurve2d, RationalCubicCurve2d] => {\n const [leftX, rightX] = CubicPolynomial.subdivide(c.x, 0.5)\n const [leftY, rightY] = CubicPolynomial.subdivide(c.y, 0.5)\n const [leftW, rightW] = CubicPolynomial.subdivide(c.w, 0.5)\n\n return [\n new RationalCubicCurve2dImpl(leftX, leftY, leftW),\n new RationalCubicCurve2dImpl(rightX, rightY, rightW),\n ]\n}\n\n// Parametric distance at t = 0.5 — how far the candidate polynomial drifts\n// from the true rational at the midpoint. Cheap; adequate for symmetric\n// weight distributions. A multi-sample variant (t = ¼, ½, ¾ max) or a true\n// Hausdorff bound would catch asymmetric divergence better — easy to swap\n// since it's localized here.\nconst midpointError = (c: RationalCubicCurve2d, candidate: CubicCurve2d.CubicCurve2d): number => {\n const w = CubicPolynomial.solve(c.w, 0.5)\n const trueX = CubicPolynomial.solve(c.x, 0.5) / w\n const trueY = CubicPolynomial.solve(c.y, 0.5) / w\n const candX = CubicPolynomial.solve(candidate.x, 0.5)\n const candY = CubicPolynomial.solve(candidate.y, 0.5)\n return Math.hypot(trueX - candX, trueY - candY)\n}\n\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 || midpointError(curr, candidate) <= tolerance) {\n out.push(candidate)\n return\n }\n const [left, right] = splitAtHalf(curr)\n recurse(left, depth + 1)\n recurse(right, depth + 1)\n }\n recurse(c, 0)\n return out\n})\n","import type { Pipeable } from '../utils'\nimport type { CubicPolynomial } from '../polynomial/cubic'\nimport type { Increasing, Monotonic } from '../polynomial/traits'\nimport type * as Solution from '../solution/solution'\nimport type { Vector2, Weighted } from '../vector/vector2'\nimport type { CubicCurve2d } from './cubic2d'\nimport type { RationalCubicCurve2dTypeId, RationalCurveTraits } from './rationalCubic2d.internal'\nimport * as internal from './rationalCubic2d.internal'\n\nexport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits'\nexport { RationalCurveTraits } from './rationalCubic2d.internal'\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.1.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.1.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.1.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.1.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.1.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.1.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.1.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.1.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.1.0\n */\n <XT, YT>(c: RationalCubicCurve2d<XT, YT>, x: number): Solution.AtMostThree<number>\n /** @since 2.1.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.1.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.1.0\n */\n <XT, YT>(c: RationalCubicCurve2d<XT, YT>, y: number): Solution.AtMostThree<number>\n /** @since 2.1.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 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 candidate's midpoint deviates from the true rational midpoint\n * by more than `tolerance`, the segment is split at `t = 0.5` and the\n * procedure recurses on each half. Returns a non-empty array; for a curve\n * that is already polynomial (uniform weights) the result is a single\n * exact segment.\n *\n * @param c - The rational cubic curve to approximate.\n * @param tolerance - Maximum allowed midpoint deviation; must be positive.\n * @returns A sequence of polynomial cubic curves covering the input.\n * @since 2.1.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 midpoint deviation; must be positive.\n * @returns A function that takes a curve and returns its polynomial approximation.\n * @since 2.1.0\n */\n (tolerance: number): (c: RationalCubicCurve2d) => ReadonlyArray<CubicCurve2d>\n} = internal.approximateAsCubicCurves\n"],"mappings":";;;;;;;;;;;AASA,MAAa,sBAAqC,OAAO,uBAAuB;AAGhF,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;;;AAIhB,MAAaA,qBAGS,IAAI,OAAO,IAAI,kBAAkB,IAAI,GAAG;AAE9D,MAAaC,sBACX,IACA,OACG,IAAI,kBAAkBC,OAAsB,GAAG,GAAG,GAAG,EAAE,EAAEA,OAAsB,GAAG,GAAG,GAAG,EAAE,CAAC;AAIhG,MAAaC,sBACX,IACA,OAEA,IAAI,kBACFD,OAAsB,GAAG,GAAG,GAAG,IAAI,GAAG,EAAE,EACxCA,OAAsB,GAAG,GAAG,GAAG,IAAI,GAAG,EAAE,CACzC;AAEH,MAAaE,qBAAmB,MAC9B,OAAO,MAAM,YAAY,MAAM,QAAQ,uBAAuB;AAEhE,MAAaC,gBAAc,MAAqBC,KAAa,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG;AAE5E,MAAaC,UAAQ,KAGnB,IAAI,GAAkB,MACtBD,KAAaE,QAAuB,EAAE,GAAG,EAAE,EAAEA,QAAuB,EAAE,GAAG,EAAE,CAAC,CAC7E;AAMD,MAAaC,aAAW,KAAK,IAAI,GAAkB,MACjDC,MAAeC,eAA8B,EAAE,GAAG,EAAE,EAAE;CACpD,cAAcC;CACd,SAAS,EAAE,OAAO,QAChB,IAAI,KAAK,IAAI,I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sB,EAAE,GAAG,GAAI,GAAG;CAChD,MAAM,QAAQA,QAAsB,UAAU,GAAG,GAAI;CACrD,MAAM,QAAQA,QAAsB,UAAU,GAAG,GAAI;CACrD,OAAO,KAAK,MAAM,QAAQ,OAAO,QAAQ,MAAM;;AAGjD,MAAaS,6BAA2B,KAGtC,IAAI,GAAyB,cAAsB;CACnD,UACE,OAAO,SAAS,UAAU,IAAI,YAAY,GAC1C,6DACD;CAED,MAAM,MAAwC,EAAE;CAChD,MAAM,WAAW,MAA4B,UAAwB;EACnE,MAAM,YAAY,oBAAoB,KAAK;EAC3C,IAAI,SAAS,oBAAoB,cAAc,MAAM,UAAU,IAAI,WAAW;GAC5E,IAAI,KAAK,UAAU;GACnB;;EAEF,MAAM,CAAC,MAAM,SAAS,YAAY,KAAK;EACvC,QAAQ,MAAM,QAAQ,EAAE;EACxB,QAAQ,OAAO,QAAQ,EAAE;;CAE3B,QAAQ,GAAG,EAAE;CACb,OAAO;EACP;;;;;;;;;;;;;;;;;;;;;ACzPF,MAAa,yBACXC;;;;;;;;;;;AAYF,MAAa,kBAIeC;;;;;;;;;;;;;;AAe5B,MAAa,mBAKeC;;;;;;;;;;;;;;;;;;;;;;;AAwB5B,MAAa,sBAGuCC;AAEpD,MAAa,QAmBTC;AAEJ,MAAa,WA0BTC;AAEJ,MAAa,WAyBTC;AAEJ,MAAa,2BAyBTC"}
1
+ {"version":3,"file":"rationalCubic2d-D658ltUM.mjs","names":["fromPolynomials","fromCoefficients","LinearPolynomial.make","fromBezierPoints","isLinearCurve2d","derivative","Vector2.make","solve","LinearPolynomial.solve","solveAtX","Solution.match","LinearPolynomial.solveInverse","Solution.none","Solution.one","solveAtY","length","boundingBox","Interval2d.make","LinearPolynomial.range","Interval.unit","isMonotonic","LinearPolynomial.isMonotonic","isIncreasing","LinearPolynomial.isIncreasing","isDecreasing","LinearPolynomial.isDecreasing","fail","asMonotonic","asIncreasing","asDecreasing","fromPolynomials","internal.fromPolynomials","fromCoefficients","internal.fromCoefficients","fromBezierPoints","internal.fromBezierPoints","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.range","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.range","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","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","CubicPolynomial.subdivide","approximateAsCubicCurves","internal.isRationalCubicCurve2d","internal.fromPolynomials","internal.fromBezierPoints","internal.makeMonotonicEasing","internal.solve","internal.solveAtX","internal.solveAtY","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'\nimport * as Interval from '../interval/interval'\nimport { dual, Pipeable } from '../utils'\nimport * as LinearPolynomial from '../polynomial/linear'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits'\nimport * as Solution from '../solution/solution'\nimport * as Vector2 from '../vector/vector2'\nimport type { LinearCurve2d } from './linear2d'\n\nexport const LinearCurve2dTypeId: unique symbol = Symbol('curvy/curve/linear2d')\nexport type LinearCurve2dTypeId = typeof LinearCurve2dTypeId\n\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\nexport const fromPolynomials: (\n c0: LinearPolynomial.LinearPolynomial,\n c1: LinearPolynomial.LinearPolynomial,\n) => LinearCurve2d = (c0, c1) => new LinearCurve2dImpl(c0, c1)\n\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.\nexport const fromBezierPoints: (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\nexport const isLinearCurve2d = (c: unknown): c is LinearCurve2d =>\n typeof c === 'object' && c !== null && LinearCurve2dTypeId in c\n\nexport const derivative = (c: LinearCurve2d) => Vector2.make(c.x.c1, c.y.c1)\n\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.\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\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\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\nexport const boundingBox = (\n c: LinearCurve2d,\n): Interval2d.Interval2d<Interval.Closed, Interval.Closed> =>\n Interval2d.make(\n LinearPolynomial.range(c.x, Interval.unit),\n LinearPolynomial.range(c.y, Interval.unit),\n )\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.\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\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\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\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\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\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'\nimport type { TwoDimensional } from '../dimensions'\nimport type { Closed, Interval } from '../interval/interval'\nimport type { Pipeable } from '../utils'\nimport type { LinearPolynomial } from '../polynomial/linear'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits'\nimport type * as Solution from '../solution/solution'\nimport type { Vector2 } from '../vector/vector2'\nimport type { LinearCurve2dTypeId } from './linear2d.internal'\nimport * as internal from './linear2d.internal'\n\nexport type { Monotonic, Increasing, Decreasing } from '../polynomial/traits'\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 fromBezierPoints: (p0: Vector2, p1: Vector2) => LinearCurve2d =\n internal.fromBezierPoints\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'\nimport * as Interval from '../interval/interval'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits'\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'\nimport { dual, Pipeable } from '../utils'\nimport * as LinearPolynomial from '../polynomial/linear'\nimport * as QuadraticPolynomial from '../polynomial/quadratic'\nimport * as Solution from '../solution/solution'\nimport * as Vector2 from '../vector/vector2'\nimport * as LinearCurve2d from './linear2d'\nimport type { QuadraticCurve2d } from './quadratic2d'\n\nexport const QuadraticCurve2dTypeId: unique symbol = Symbol('curvy/curve/quadratic2d')\nexport type QuadraticCurve2dTypeId = typeof QuadraticCurve2dTypeId\n\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\nexport const fromPolynomials: (\n c0: QuadraticPolynomial.QuadraticPolynomial,\n c1: QuadraticPolynomial.QuadraticPolynomial,\n) => QuadraticCurve2d = (c0, c1) => new QuadraticCurve2dImpl(c0, c1)\n\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\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\nexport const isQuadraticCurve2d = (c: unknown): c is QuadraticCurve2d =>\n typeof c === 'object' && c !== null && QuadraticCurve2dTypeId in c\n\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).\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\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\nexport const derivative = (c: QuadraticCurve2d) =>\n LinearCurve2d.fromPolynomials(\n QuadraticPolynomial.derivative(c.x),\n QuadraticPolynomial.derivative(c.y),\n )\n\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\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\nexport const boundingBox = (\n c: QuadraticCurve2d,\n): Interval2d.Interval2d<Interval.Closed, Interval.Closed> =>\n Interval2d.make(\n QuadraticPolynomial.range(c.x, Interval.unit),\n QuadraticPolynomial.range(c.y, Interval.unit),\n )\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.\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\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\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\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\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\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'\nimport type { TwoDimensional } from '../dimensions'\nimport type { Closed, Interval } from '../interval/interval'\nimport type { Pipeable } from '../utils'\nimport type { QuadraticPolynomial } from '../polynomial/quadratic'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits'\nimport type * as Solution from '../solution/solution'\nimport type { Vector2 } from '../vector/vector2'\nimport type { LinearCurve2d } from './linear2d'\nimport type { QuadraticCurve2dTypeId } from './quadratic2d.internal'\nimport * as internal from './quadratic2d.internal'\n\nexport type { Monotonic, Increasing, Decreasing } from '../polynomial/traits'\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'\nimport * as Characteristic from '../characteristic/characteristic'\nimport * as Interval from '../interval/interval'\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'\nimport { dual, Pipeable } from '../utils'\nimport * as CubicPolynomial from '../polynomial/cubic'\nimport * as QuadraticPolynomial from '../polynomial/quadratic'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits'\nimport * as Solution from '../solution/solution'\nimport * as Vector2 from '../vector/vector2'\nimport * as Vector4 from '../vector/vector4'\nimport type { CubicCurve2d } from './cubic2d'\nimport * as LinearCurve2d from './linear2d'\nimport * as QuadraticCurve2d from './quadratic2d'\n\nexport const CubicCurve2dTypeId: unique symbol = Symbol('curvy/curve/cubic2d')\nexport type CubicCurve2dTypeId = typeof CubicCurve2dTypeId\n\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\nexport const fromPolynomials: (\n c0: CubicPolynomial.CubicPolynomial,\n c1: CubicPolynomial.CubicPolynomial,\n) => CubicCurve2d = (c0, c1) => new CubicCurve2dImpl(c0, c1)\n\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.\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\nexport const isCubicCurve2d = (c: unknown): c is CubicCurve2d =>\n typeof c === 'object' && c !== null && CubicCurve2dTypeId in c\n\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).\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\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\nexport const derivative = (c: CubicCurve2d) =>\n QuadraticCurve2d.fromPolynomials(CubicPolynomial.derivative(c.x), CubicPolynomial.derivative(c.y))\n\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\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\nexport const boundingBox = (\n c: CubicCurve2d,\n): Interval2d.Interval2d<Interval.Closed, Interval.Closed> =>\n Interval2d.make(\n CubicPolynomial.range(c.x, Interval.unit),\n CubicPolynomial.range(c.y, Interval.unit),\n )\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.\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\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\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\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\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\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'\nimport type { TwoDimensional } from '../dimensions'\nimport type { Closed, Interval } from '../interval/interval'\nimport type { Pipeable } from '../utils'\nimport type { CubicPolynomial } from '../polynomial/cubic'\nimport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits'\nimport type * as Solution from '../solution/solution'\nimport type { Vector2 } from '../vector/vector2'\nimport type { CubicCurve2dTypeId } from './cubic2d.internal'\nimport * as internal from './cubic2d.internal'\n\nexport type { Monotonic, Increasing, Decreasing } from '../polynomial/traits'\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'\nimport * as Interval from '../interval/interval'\nimport { dual, Pipeable } from '../utils'\nimport * as CubicPolynomial from '../polynomial/cubic'\nimport * as Solution from '../solution/solution'\nimport { invariant } from '../utils'\nimport * as Vector2 from '../vector/vector2'\nimport * as Vector4 from '../vector/vector4'\nimport * as CubicCurve2d from './cubic2d'\nimport type { RationalCubicCurve2d } from './rationalCubic2d'\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.\nexport const RationalCurveTraits: unique symbol = Symbol.for('curvy/curve/rationalCubic2d/traits')\nexport type RationalCurveTraits = typeof RationalCurveTraits\n\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\nexport const isRationalCubicCurve2d = (c: unknown): c is RationalCubicCurve2d =>\n typeof c === 'object' && c !== null && RationalCubicCurve2dTypeId in c\n\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.\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.\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\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.\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\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 t = 0.5 by applying `CubicPolynomial.subdivide`\n// independently to each of x, y, w. Equivalent to de Casteljau in Bernstein\n// space but stays in monomial form throughout.\nconst splitAtHalf = (c: RationalCubicCurve2d): [RationalCubicCurve2d, RationalCubicCurve2d] => {\n const [leftX, rightX] = CubicPolynomial.subdivide(c.x, 0.5)\n const [leftY, rightY] = CubicPolynomial.subdivide(c.y, 0.5)\n const [leftW, rightW] = CubicPolynomial.subdivide(c.w, 0.5)\n\n return [\n new RationalCubicCurve2dImpl(leftX, leftY, leftW),\n new RationalCubicCurve2dImpl(rightX, rightY, rightW),\n ]\n}\n\n// Parametric distance at t = 0.5 — how far the candidate polynomial drifts\n// from the true rational at the midpoint. Cheap; adequate for symmetric\n// weight distributions. A multi-sample variant (t = ¼, ½, ¾ max) or a true\n// Hausdorff bound would catch asymmetric divergence better — easy to swap\n// since it's localized here.\nconst midpointError = (c: RationalCubicCurve2d, candidate: CubicCurve2d.CubicCurve2d): number => {\n const w = CubicPolynomial.solve(c.w, 0.5)\n const trueX = CubicPolynomial.solve(c.x, 0.5) / w\n const trueY = CubicPolynomial.solve(c.y, 0.5) / w\n const candX = CubicPolynomial.solve(candidate.x, 0.5)\n const candY = CubicPolynomial.solve(candidate.y, 0.5)\n return Math.hypot(trueX - candX, trueY - candY)\n}\n\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 || midpointError(curr, candidate) <= tolerance) {\n out.push(candidate)\n return\n }\n const [left, right] = splitAtHalf(curr)\n recurse(left, depth + 1)\n recurse(right, depth + 1)\n }\n recurse(c, 0)\n return out\n})\n","import type { Pipeable } from '../utils'\nimport type { CubicPolynomial } from '../polynomial/cubic'\nimport type { Increasing, Monotonic } from '../polynomial/traits'\nimport type * as Solution from '../solution/solution'\nimport type { Vector2, Weighted } from '../vector/vector2'\nimport type { CubicCurve2d } from './cubic2d'\nimport type { RationalCubicCurve2dTypeId, RationalCurveTraits } from './rationalCubic2d.internal'\nimport * as internal from './rationalCubic2d.internal'\n\nexport type { Decreasing, Increasing, Monotonic } from '../polynomial/traits'\nexport { RationalCurveTraits } from './rationalCubic2d.internal'\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 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 candidate's midpoint deviates from the true rational midpoint\n * by more than `tolerance`, the segment is split at `t = 0.5` and the\n * procedure recurses on each half. Returns a non-empty array; for a curve\n * that is already polynomial (uniform weights) the result is a single\n * exact segment.\n *\n * @param c - The rational cubic curve to approximate.\n * @param tolerance - Maximum allowed midpoint deviation; 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 midpoint deviation; 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;AAGhF,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;;;AAIhB,MAAaA,qBAGS,IAAI,OAAO,IAAI,kBAAkB,IAAI,GAAG;AAE9D,MAAaC,sBACX,IACA,OACG,IAAI,kBAAkBC,OAAsB,GAAG,GAAG,GAAG,EAAE,EAAEA,OAAsB,GAAG,GAAG,GAAG,EAAE,CAAC;AAIhG,MAAaC,sBACX,IACA,OAEA,IAAI,kBACFD,OAAsB,GAAG,GAAG,GAAG,IAAI,GAAG,EAAE,EACxCA,OAAsB,GAAG,GAAG,GAAG,IAAI,GAAG,EAAE,CACzC;AAEH,MAAaE,qBAAmB,MAC9B,OAAO,MAAM,YAAY,MAAM,QAAQ,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
+ import { a as TwoDimensional } from "./vector2-euuV_bNQ.mjs";
2
+ import { t as Pipeable } from "./utils-MCckigYk.mjs";
3
+ import { n as QuadraticPolynomial, r as LinearPolynomial, t as CubicPolynomial } from "./cubic-DkBqcZf-.mjs";
4
+
5
+ //#region src/curve/linear2d.internal.d.ts
6
+ declare const LinearCurve2dTypeId: unique symbol;
7
+ type LinearCurve2dTypeId = typeof LinearCurve2dTypeId;
8
+ //#endregion
9
+ //#region src/curve/linear2d.d.ts
10
+ /**
11
+ * A linear curve in 2D space.
12
+ *
13
+ * All fields are readonly and immutable, and all operations create new instances.
14
+ *
15
+ * The two type parameters carry the trait sets of the curve's per-axis
16
+ * polynomials. Refiners like `isMonotonic` lift each axis's monotonicity into
17
+ * the curve's combined trait set.
18
+ *
19
+ * @since 1.0.0
20
+ */
21
+ interface LinearCurve2d<out XTraits = unknown, out YTraits = unknown> extends Pipeable, TwoDimensional<LinearPolynomial<XTraits>, LinearPolynomial<YTraits>> {
22
+ readonly [LinearCurve2dTypeId]: LinearCurve2dTypeId;
23
+ }
24
+ //#endregion
25
+ //#region src/curve/quadratic2d.internal.d.ts
26
+ declare const QuadraticCurve2dTypeId: unique symbol;
27
+ type QuadraticCurve2dTypeId = typeof QuadraticCurve2dTypeId;
28
+ //#endregion
29
+ //#region src/curve/quadratic2d.d.ts
30
+ /**
31
+ * A quadratic curve in 2D space.
32
+ *
33
+ * All fields are readonly and immutable, and all operations create new instances.
34
+ *
35
+ * The two type parameters carry the trait sets of the curve's per-axis
36
+ * polynomials. Refiners check monotonicity over the unit interval `[0, 1]` —
37
+ * the curve's natural parameter domain.
38
+ *
39
+ * @since 1.0.0
40
+ */
41
+ interface QuadraticCurve2d<out XTraits = unknown, out YTraits = unknown> extends Pipeable, TwoDimensional<QuadraticPolynomial<XTraits>, QuadraticPolynomial<YTraits>> {
42
+ readonly [QuadraticCurve2dTypeId]: QuadraticCurve2dTypeId;
43
+ }
44
+ //#endregion
45
+ //#region src/curve/cubic2d.internal.d.ts
46
+ declare const CubicCurve2dTypeId: unique symbol;
47
+ type CubicCurve2dTypeId = typeof CubicCurve2dTypeId;
48
+ //#endregion
49
+ //#region src/curve/cubic2d.d.ts
50
+ /**
51
+ * A cubic curve in 2D space.
52
+ *
53
+ * All fields are readonly and immutable, and all operations create new instances.
54
+ *
55
+ * The two type parameters carry the trait sets of the curve's per-axis
56
+ * polynomials. Refiners check monotonicity over the unit interval `[0, 1]` —
57
+ * the curve's natural parameter domain.
58
+ *
59
+ * @since 1.0.0
60
+ */
61
+ interface CubicCurve2d<out XTraits = unknown, out YTraits = unknown> extends Pipeable, TwoDimensional<CubicPolynomial<XTraits>, CubicPolynomial<YTraits>> {
62
+ readonly [CubicCurve2dTypeId]: CubicCurve2dTypeId;
63
+ }
64
+ //#endregion
65
+ //#region src/curve/rationalCubic2d.internal.d.ts
66
+ declare const RationalCubicCurve2dTypeId: unique symbol;
67
+ type RationalCubicCurve2dTypeId = typeof RationalCubicCurve2dTypeId;
68
+ declare const RationalCurveTraits: unique symbol;
69
+ type RationalCurveTraits = typeof RationalCurveTraits;
70
+ //#endregion
71
+ //#region src/curve/rationalCubic2d.d.ts
72
+ /**
73
+ * A rational cubic curve in 2D space.
74
+ *
75
+ * Represented as three cubic polynomials in the parameter `t`: per-axis
76
+ * numerators `x`, `y`, and a shared denominator `w`. Evaluation is
77
+ * `(x(t)/w(t), y(t)/w(t))` — the projection from homogeneous coordinates
78
+ * back to the plane. With all weights equal at the source (e.g. produced
79
+ * from a non-rational Bézier with unit weights), `w` is constant and the
80
+ * curve coincides with a polynomial cubic.
81
+ *
82
+ * The two type parameters carry per-axis monotonicity trait brands attached
83
+ * to the rational functions `x(t)/w(t)` and `y(t)/w(t)`. Unlike
84
+ * `CubicCurve2d`, traits do not flow through to the underlying polynomials —
85
+ * monotonicity of a ratio of cubics is not the same property as monotonicity
86
+ * of either cubic alone, so the brand lives on the curve itself. Constructors
87
+ * with construction-time monotonicity guarantees (e.g. {@link makeMonotonicEasing})
88
+ * return curves with `Increasing` brands attached, narrowing downstream
89
+ * operations like {@link solveAtX} to single-solution returns.
90
+ *
91
+ * All fields are readonly and immutable, and all operations create new instances.
92
+ *
93
+ * @since 2.0.0
94
+ */
95
+ interface RationalCubicCurve2d<out XTraits = unknown, out YTraits = unknown> extends Pipeable {
96
+ readonly [RationalCubicCurve2dTypeId]: RationalCubicCurve2dTypeId;
97
+ readonly [RationalCurveTraits]: [XTraits, YTraits];
98
+ readonly x: CubicPolynomial;
99
+ readonly y: CubicPolynomial;
100
+ readonly w: CubicPolynomial;
101
+ }
102
+ //#endregion
103
+ export { LinearCurve2d as i, CubicCurve2d as n, QuadraticCurve2d as r, RationalCubicCurve2d as t };
104
+ //# sourceMappingURL=rationalCubic2d-MgMSJaAU.d.mts.map