curvy 2.0.0-alpha.7 → 2.0.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/characteristic/index.mjs +1 -1
- package/dist/curve/index.mjs +1 -1
- package/dist/interval/index.mjs +1 -1
- package/dist/matrix/index.mjs +1 -1
- package/dist/path/index.mjs +4 -4
- package/dist/polynomial/index.mjs +2 -2
- package/dist/shared/{characteristic-D9yZWCym.mjs → characteristic-B0VEB_OA.mjs} +3 -3
- package/dist/shared/{characteristic-D9yZWCym.mjs.map → characteristic-B0VEB_OA.mjs.map} +1 -1
- package/dist/shared/{cubic-BK8xjSkd.mjs → cubic-NEn7E6V_.mjs} +2 -2
- package/dist/shared/{cubic-BK8xjSkd.mjs.map → cubic-NEn7E6V_.mjs.map} +1 -1
- package/dist/shared/{interval2d-BMDmeL1M.mjs → interval2d-C0eduE-V.mjs} +2 -2
- package/dist/shared/{interval2d-BMDmeL1M.mjs.map → interval2d-C0eduE-V.mjs.map} +1 -1
- package/dist/shared/{matrix4x4-qyRufxfs.mjs → matrix4x4-BWmf4lZM.mjs} +3 -3
- package/dist/shared/{matrix4x4-qyRufxfs.mjs.map → matrix4x4-BWmf4lZM.mjs.map} +1 -1
- package/dist/shared/{quadratic-CWXIRh42.mjs → quadratic-Dlxqo2V1.mjs} +2 -2
- package/dist/shared/{quadratic-CWXIRh42.mjs.map → quadratic-Dlxqo2V1.mjs.map} +1 -1
- package/dist/shared/{rationalCubic2d-DaFTrUXw.mjs → rationalCubic2d-3S5K69Jy.mjs} +7 -7
- package/dist/shared/{rationalCubic2d-DaFTrUXw.mjs.map → rationalCubic2d-3S5K69Jy.mjs.map} +1 -1
- package/dist/shared/{rationalCubic2d-BZvT9s5N.mjs → rationalCubic2d-CJY-feGw.mjs} +5 -5
- package/dist/shared/{rationalCubic2d-BZvT9s5N.mjs.map → rationalCubic2d-CJY-feGw.mjs.map} +1 -1
- package/dist/shared/{vector2-CWU3cPB2.mjs → vector2-CSkaMXvp.mjs} +10 -2
- package/dist/shared/vector2-CSkaMXvp.mjs.map +1 -0
- package/dist/shared/{vector2.internal-BL8hFl1c.mjs → vector2.internal-DP1nTBdS.mjs} +17 -2
- package/dist/shared/{vector2.internal-BL8hFl1c.mjs.map → vector2.internal-DP1nTBdS.mjs.map} +1 -1
- package/dist/shared/{vector3-DmMm6pX8.mjs → vector3-CR2LPV03.mjs} +14 -2
- package/dist/shared/vector3-CR2LPV03.mjs.map +1 -0
- package/dist/shared/{vector4-oqPPp45j.mjs → vector4-PO_7EYd-.mjs} +54 -2
- package/dist/shared/{vector4-oqPPp45j.mjs.map → vector4-PO_7EYd-.mjs.map} +1 -1
- package/dist/shared/{vector4.internal-BnnTjVIr.mjs → vector4.internal-BJ1QN2Ck.mjs} +55 -15
- package/dist/shared/vector4.internal-BJ1QN2Ck.mjs.map +1 -0
- package/dist/splines/index.mjs +7 -7
- package/dist/vector/index.mjs +3 -3
- package/dist/vector/vector2.d.ts +80 -0
- package/dist/vector/vector3.d.ts +120 -0
- package/dist/vector/vector4.d.ts +184 -0
- package/package.json +1 -1
- package/dist/shared/vector2-CWU3cPB2.mjs.map +0 -1
- package/dist/shared/vector3-DmMm6pX8.mjs.map +0 -1
- package/dist/shared/vector4.internal-BnnTjVIr.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rationalCubic2d-BZvT9s5N.mjs","names":["isCubicPath2d","make","fromArray","append","length","CubicCurve2d.length","Interval.unit","solve","CubicCurve2d.solve","derivative","cubicCurveInternal.derivative","Interval.make","Vector2.magnitude","QuadraticCurve2d.solve","toPathData","isContinuous","asContinuous","isIncreasingX","CubicPolynomial.isIncreasing","isDecreasingX","CubicPolynomial.isDecreasing","isMonotonicX","isIncreasingY","isDecreasingY","isMonotonicY","asIncreasingX","asDecreasingX","asMonotonicX","asIncreasingY","asDecreasingY","asMonotonicY","solveAtX","CubicCurve2d.solveAtX","Solution.none","solveAtY","CubicCurve2d.solveAtY","solveByDistance","boundingBox","CubicCurve2d.boundingBox","Interval2d.union","make","internal.make","fromArray","internal.fromArray","internal.isCubicPath2d","append","internal.append","internal.length","solve","internal.solve","internal.toPathData","internal.isContinuous","internal.asContinuous","internal.isIncreasingX","internal.isDecreasingX","internal.isMonotonicX","internal.isIncreasingY","internal.isDecreasingY","internal.isMonotonicY","internal.asIncreasingX","internal.asDecreasingX","internal.asMonotonicX","internal.asIncreasingY","internal.asDecreasingY","internal.asMonotonicY","internal.solveAtX","internal.solveAtY","internal.solveByDistance","internal.boundingBox","isRationalCubicPath2d","make","fromArray","append","solve","RationalCubicCurve2d.solve","approximateAsCubicPath","RationalCubicCurve2d.approximateAsCubicCurves","CubicPath2d.fromArray","internal.isRationalCubicPath2d","internal.make","internal.fromArray","internal.append","internal.solve","internal.approximateAsCubicPath"],"sources":["../../src/path/cubic2d.internal.ts","../../src/path/cubic2d.ts","../../src/path/rationalCubic2d.internal.ts","../../src/path/rationalCubic2d.ts"],"sourcesContent":["import * as Interval2d from '../interval/interval2d.ts'\nimport * as CubicCurve2d from '../curve/cubic2d.ts'\nimport * as cubicCurveInternal from '../curve/cubic2d.internal.ts'\nimport * as QuadraticCurve2d from '../curve/quadratic2d.ts'\nimport * as Interval from '../interval/interval.ts'\nimport * as CubicPolynomial from '../polynomial/cubic.ts'\nimport * as Solution from '../solution/solution.ts'\nimport { dual, Pipeable } from '../utils.ts'\nimport { invariant } from '../utils.ts'\nimport { EPSILON, epsEquals } from '../number.ts'\nimport * as Vector2 from '../vector/vector2.ts'\nimport type { CubicPath2d } from './cubic2d.ts'\nimport {\n PathTraits,\n type Continuous,\n type DecreasingX,\n type DecreasingY,\n type IncreasingX,\n type IncreasingY,\n type MonotonicX,\n type MonotonicY,\n} from './traits.ts'\n\nexport const CubicPath2dTypeId: unique symbol = Symbol('curvy/path/cubic2d')\nexport type CubicPath2dTypeId = typeof CubicPath2dTypeId\n\n/** @internal */\nexport class CubicPath2dImpl extends Pipeable implements CubicPath2d<unknown> {\n readonly [CubicPath2dTypeId]: CubicPath2dTypeId = CubicPath2dTypeId\n declare readonly [PathTraits]: unknown\n\n readonly curves: ReadonlyArray<CubicCurve2d.CubicCurve2d>\n\n constructor(curves: ReadonlyArray<CubicCurve2d.CubicCurve2d>) {\n invariant(curves.length > 0, 'cubic path requires at least one curve')\n super()\n this.curves = curves\n }\n\n [Symbol.iterator](): Iterator<CubicCurve2d.CubicCurve2d> {\n return this.curves[Symbol.iterator]()\n }\n}\n\n/** @internal */\nexport const isCubicPath2d = (p: unknown): p is CubicPath2d =>\n typeof p === 'object' && p !== null && CubicPath2dTypeId in p\n\n/** @internal */\nexport const make = (...curves: ReadonlyArray<CubicCurve2d.CubicCurve2d>): CubicPath2d =>\n new CubicPath2dImpl(curves)\n\n/** @internal */\nexport const fromArray = (curves: ReadonlyArray<CubicCurve2d.CubicCurve2d>): CubicPath2d =>\n new CubicPath2dImpl(curves)\n\n/** @internal */\nexport const append = dual<\n (c: CubicCurve2d.CubicCurve2d) => (p: CubicPath2d) => CubicPath2d,\n (p: CubicPath2d, c: CubicCurve2d.CubicCurve2d) => CubicPath2d\n>(2, (p: CubicPath2d, c: CubicCurve2d.CubicCurve2d) => fromArray([...p, c]))\n\n/** @internal */\nexport const length = (p: CubicPath2d) => {\n let total = 0\n for (const curve of p) {\n total += CubicCurve2d.length(curve, Interval.unit)\n }\n\n return total\n}\n\n/** @internal */\nexport const solve = dual<\n (u: number) => (p: CubicPath2d) => Vector2.Vector2,\n (p: CubicPath2d, u: number) => Vector2.Vector2\n>(2, (p: CubicPath2d, u: number) => {\n const curves = p instanceof CubicPath2dImpl ? p.curves : [...p]\n\n if (u === 1) {\n const last = curves.at(-1) as CubicCurve2d.CubicCurve2d\n return CubicCurve2d.solve(last, 1)\n }\n\n const t = u * curves.length\n const i = Math.floor(t)\n const curve = curves[i] as CubicCurve2d.CubicCurve2d\n return CubicCurve2d.solve(curve, t - i)\n})\n\n// Cumulative segment lengths cache. lengths[k] = total length through segment k.\n// Cached by path identity since paths are immutable.\nconst cumulativeLengthCache = new WeakMap<CubicPath2d, ReadonlyArray<number>>()\n\nconst getCumulativeLengths = (p: CubicPath2d): ReadonlyArray<number> => {\n let cached = cumulativeLengthCache.get(p)\n if (cached === undefined) {\n const lengths: Array<number> = []\n let total = 0\n for (const curve of p) {\n total += CubicCurve2d.length(curve, Interval.unit)\n lengths.push(total)\n }\n cached = lengths\n cumulativeLengthCache.set(p, cached)\n }\n return cached\n}\n\n// Newton's method to find the local parameter t ∈ [0, 1] within `curve` such\n// that the arc length from 0 to t equals `target`. Each iteration costs one\n// GL32 quadrature plus one velocity eval; converges in 3–5 iterations for\n// well-behaved curves. Falls back to bisection on cusps where speed → 0.\nconst solveCurveByDistance = (\n curve: CubicCurve2d.CubicCurve2d,\n target: number,\n segmentLength: number,\n): number => {\n if (target <= 0) {\n return 0\n }\n if (target >= segmentLength) {\n return 1\n }\n\n const derivative = cubicCurveInternal.derivative(curve)\n\n let t = target / segmentLength\n let lo = 0\n let hi = 1\n\n for (let iter = 0; iter < 16; iter++) {\n const currentLength = CubicCurve2d.length(curve, Interval.make(0, t))\n const error = currentLength - target\n\n if (Math.abs(error) < 1e-10) {\n return t\n }\n\n if (error > 0) {\n hi = t\n } else {\n lo = t\n }\n\n const speed = Vector2.magnitude(QuadraticCurve2d.solve(derivative, t))\n if (speed === 0) {\n // cusp — bisect instead\n t = (lo + hi) / 2\n continue\n }\n\n const next = t - error / speed\n // bracket-clamp Newton step; if it leaves the bracket, fall back to bisection\n t = next > lo && next < hi ? next : (lo + hi) / 2\n }\n\n return t\n}\n\n// Cubic Bernstein basis: P(t) = (1-t)³·p0 + 3(1-t)²t·p1 + 3(1-t)t²·p2 + t³·p3\n// expanded gives c0 = p0, c1 = -3p0 + 3p1, c2 = 3p0 - 6p1 + 3p2, c3 = -p0 + 3p1 - 3p2 + p3,\n// so: p0 = c0, p1 = c0 + c1/3, p2 = c0 + 2c1/3 + c2/3, p3 = c0 + c1 + c2 + c3.\n/** @internal */\nexport const toPathData = (p: CubicPath2d): string => {\n let result = ''\n let prevEndX = Number.NaN\n let prevEndY = Number.NaN\n\n for (const curve of p) {\n const c0x = curve.x.c0\n const c0y = curve.y.c0\n const c1x = curve.x.c1\n const c1y = curve.y.c1\n const c2x = curve.x.c2\n const c2y = curve.y.c2\n const c3x = curve.x.c3\n const c3y = curve.y.c3\n\n const startX = c0x\n const startY = c0y\n const ctrl1X = c0x + c1x / 3\n const ctrl1Y = c0y + c1y / 3\n const ctrl2X = c0x + (2 * c1x) / 3 + c2x / 3\n const ctrl2Y = c0y + (2 * c1y) / 3 + c2y / 3\n const endX = c0x + c1x + c2x + c3x\n const endY = c0y + c1y + c2y + c3y\n\n if (!epsEquals(startX, prevEndX) || !epsEquals(startY, prevEndY)) {\n result += ` M ${startX},${startY}`\n }\n result += ` C ${ctrl1X},${ctrl1Y} ${ctrl2X},${ctrl2Y} ${endX},${endY}`\n\n prevEndX = endX\n prevEndY = endY\n }\n\n return result.slice(1)\n}\n\n/** @internal */\nexport const isContinuous = <T>(p: CubicPath2d<T>): p is CubicPath2d<T & Continuous> => {\n let prevEndX = Number.NaN\n let prevEndY = Number.NaN\n let first = true\n\n for (const curve of p) {\n const startX = curve.x.c0\n const startY = curve.y.c0\n if (!first && (!epsEquals(startX, prevEndX) || !epsEquals(startY, prevEndY))) {\n return false\n }\n prevEndX = curve.x.c0 + curve.x.c1 + curve.x.c2 + curve.x.c3\n prevEndY = curve.y.c0 + curve.y.c1 + curve.y.c2 + curve.y.c3\n first = false\n }\n return true\n}\n\n/** @internal */\nexport const asContinuous = <T>(p: CubicPath2d<T>): CubicPath2d<T & Continuous> => {\n invariant(isContinuous(p), 'cubic path is not continuous')\n return p\n}\n\n// Per-axis monotonicity for the path: every segment's axis polynomial must be\n// strictly monotonic over the unit interval AND adjacent segments' axis\n// ranges must not overlap (modulo EPSILON for float drift).\n/** @internal */\nexport const isIncreasingX = <T>(p: CubicPath2d<T>): p is CubicPath2d<T & IncreasingX> => {\n let prevEnd = Number.NEGATIVE_INFINITY\n for (const c of p) {\n if (!CubicPolynomial.isIncreasing(c.x, Interval.unit)) {\n return false\n }\n if (c.x.c0 < prevEnd - EPSILON) {\n return false\n }\n prevEnd = c.x.c0 + c.x.c1 + c.x.c2 + c.x.c3\n }\n return true\n}\n\n/** @internal */\nexport const isDecreasingX = <T>(p: CubicPath2d<T>): p is CubicPath2d<T & DecreasingX> => {\n let prevEnd = Number.POSITIVE_INFINITY\n for (const c of p) {\n if (!CubicPolynomial.isDecreasing(c.x, Interval.unit)) {\n return false\n }\n if (c.x.c0 > prevEnd + EPSILON) {\n return false\n }\n prevEnd = c.x.c0 + c.x.c1 + c.x.c2 + c.x.c3\n }\n return true\n}\n\n/** @internal */\nexport const isMonotonicX = <T>(p: CubicPath2d<T>): p is CubicPath2d<T & MonotonicX> =>\n isIncreasingX(p) || isDecreasingX(p)\n\n/** @internal */\nexport const isIncreasingY = <T>(p: CubicPath2d<T>): p is CubicPath2d<T & IncreasingY> => {\n let prevEnd = Number.NEGATIVE_INFINITY\n for (const c of p) {\n if (!CubicPolynomial.isIncreasing(c.y, Interval.unit)) {\n return false\n }\n if (c.y.c0 < prevEnd - EPSILON) {\n return false\n }\n prevEnd = c.y.c0 + c.y.c1 + c.y.c2 + c.y.c3\n }\n return true\n}\n\n/** @internal */\nexport const isDecreasingY = <T>(p: CubicPath2d<T>): p is CubicPath2d<T & DecreasingY> => {\n let prevEnd = Number.POSITIVE_INFINITY\n for (const c of p) {\n if (!CubicPolynomial.isDecreasing(c.y, Interval.unit)) {\n return false\n }\n if (c.y.c0 > prevEnd + EPSILON) {\n return false\n }\n prevEnd = c.y.c0 + c.y.c1 + c.y.c2 + c.y.c3\n }\n return true\n}\n\n/** @internal */\nexport const isMonotonicY = <T>(p: CubicPath2d<T>): p is CubicPath2d<T & MonotonicY> =>\n isIncreasingY(p) || isDecreasingY(p)\n\n/** @internal */\nexport const asIncreasingX = <T>(p: CubicPath2d<T>): CubicPath2d<T & IncreasingX> => {\n invariant(isIncreasingX(p), 'cubic path is not increasing in x')\n return p\n}\n\n/** @internal */\nexport const asDecreasingX = <T>(p: CubicPath2d<T>): CubicPath2d<T & DecreasingX> => {\n invariant(isDecreasingX(p), 'cubic path is not decreasing in x')\n return p\n}\n\n/** @internal */\nexport const asMonotonicX = <T>(p: CubicPath2d<T>): CubicPath2d<T & MonotonicX> => {\n invariant(isMonotonicX(p), 'cubic path is not monotonic in x')\n return p\n}\n\n/** @internal */\nexport const asIncreasingY = <T>(p: CubicPath2d<T>): CubicPath2d<T & IncreasingY> => {\n invariant(isIncreasingY(p), 'cubic path is not increasing in y')\n return p\n}\n\n/** @internal */\nexport const asDecreasingY = <T>(p: CubicPath2d<T>): CubicPath2d<T & DecreasingY> => {\n invariant(isDecreasingY(p), 'cubic path is not decreasing in y')\n return p\n}\n\n/** @internal */\nexport const asMonotonicY = <T>(p: CubicPath2d<T>): CubicPath2d<T & MonotonicY> => {\n invariant(isMonotonicY(p), 'cubic path is not monotonic in y')\n return p\n}\n\n/** @internal */\nexport const solveAtX = dual(2, (p: CubicPath2d, x: number): Solution.AtMostOne<number> => {\n for (const c of p) {\n const sx = c.x.c0\n const ex = c.x.c0 + c.x.c1 + c.x.c2 + c.x.c3\n const lo = Math.min(sx, ex)\n const hi = Math.max(sx, ex)\n if (x >= lo - EPSILON && x <= hi + EPSILON) {\n return CubicCurve2d.solveAtX(c, x) as Solution.AtMostOne<number>\n }\n }\n return Solution.none\n})\n\n/** @internal */\nexport const solveAtY = dual(2, (p: CubicPath2d, y: number): Solution.AtMostOne<number> => {\n for (const c of p) {\n const sy = c.y.c0\n const ey = c.y.c0 + c.y.c1 + c.y.c2 + c.y.c3\n const lo = Math.min(sy, ey)\n const hi = Math.max(sy, ey)\n if (y >= lo - EPSILON && y <= hi + EPSILON) {\n return CubicCurve2d.solveAtY(c, y) as Solution.AtMostOne<number>\n }\n }\n return Solution.none\n})\n\n/** @internal */\nexport const solveByDistance = dual<\n (s: number) => (p: CubicPath2d) => Vector2.Vector2,\n (p: CubicPath2d, s: number) => Vector2.Vector2\n>(2, (p: CubicPath2d, s: number) => {\n if (s <= 0) {\n return solve(p, 0)\n }\n if (s >= 1) {\n return solve(p, 1)\n }\n\n const lengths = getCumulativeLengths(p)\n const total = lengths[lengths.length - 1] as number\n const target = s * total\n\n // find segment k such that lengths[k-1] ≤ target ≤ lengths[k]\n let k = 0\n while (k < lengths.length - 1 && (lengths[k] as number) < target) {\n k++\n }\n\n const segmentStart = k === 0 ? 0 : (lengths[k - 1] as number)\n const segmentEnd = lengths[k] as number\n const segmentLength = segmentEnd - segmentStart\n const segmentTarget = target - segmentStart\n\n const curves = p instanceof CubicPath2dImpl ? p.curves : [...p]\n const curve = curves[k] as CubicCurve2d.CubicCurve2d\n const localT = solveCurveByDistance(curve, segmentTarget, segmentLength)\n\n return CubicCurve2d.solve(curve, localT)\n})\n\n/** @internal */\nexport const boundingBox = (\n p: CubicPath2d,\n): Interval2d.Interval2d<Interval.Closed, Interval.Closed> => {\n const iter = p[Symbol.iterator]()\n const first = iter.next()\n let acc = CubicCurve2d.boundingBox(first.value as CubicCurve2d.CubicCurve2d)\n for (let next = iter.next(); !next.done; next = iter.next()) {\n acc = Interval2d.union(acc, CubicCurve2d.boundingBox(next.value))\n }\n return acc\n}\n","import type { Interval2d } from '../interval/interval2d.ts'\nimport type { CubicCurve2d } from '../curve/cubic2d.ts'\nimport type { Closed } from '../interval/interval.ts'\nimport type * as Solution from '../solution/solution.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport type { CubicPath2dTypeId } from './cubic2d.internal.ts'\nimport * as internal from './cubic2d.internal.ts'\nimport type {\n Continuous,\n DecreasingX,\n DecreasingY,\n IncreasingX,\n IncreasingY,\n MonotonicX,\n MonotonicY,\n PathTraits,\n} from './traits.ts'\n\nexport type {\n Continuous,\n DecreasingX,\n DecreasingY,\n IncreasingX,\n IncreasingY,\n MonotonicX,\n MonotonicY,\n} from './traits.ts'\n\n/**\n * A cubic path in 2D space.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * The `Trait` type parameter accumulates trait brands as the path is refined\n * via `isContinuous` / `asContinuous`.\n *\n * @since 1.0.0\n */\nexport interface CubicPath2d<out Trait = unknown> extends Pipeable, Iterable<CubicCurve2d> {\n readonly [CubicPath2dTypeId]: CubicPath2dTypeId\n readonly [PathTraits]: Trait\n}\n\n/**\n * Creates a new `CubicPath2d` instance from a sequence of curves.\n *\n * @param curves - The curves to create the path from.\n * @returns A new `CubicPath2d` instance.\n * @since 2.0.0\n */\nexport const make: (...curves: ReadonlyArray<CubicCurve2d>) => CubicPath2d = internal.make\n\n/**\n * Creates a new `CubicPath2d` instance from an array of curves.\n *\n * @param curves - The curves to create the path from.\n * @returns A new `CubicPath2d` instance.\n * @since 2.0.0\n */\nexport const fromArray: (curves: ReadonlyArray<CubicCurve2d>) => CubicPath2d = internal.fromArray\n\n/**\n * Checks if a value is a `CubicPath2d`.\n *\n * @param p - The value to check.\n * @returns `true` if the value is a `CubicPath2d`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isCubicPath2d: (p: unknown) => p is CubicPath2d = internal.isCubicPath2d\n\nexport const append: {\n /**\n * Appends a cubic curve to a cubic path.\n *\n * @param c - The cubic curve to append.\n * @returns A function that takes a cubic path and returns a new cubic path.\n * @since 1.0.0\n */\n (c: CubicCurve2d): (p: CubicPath2d) => CubicPath2d\n /**\n * Appends a cubic curve to a cubic path.\n *\n * @param p - The cubic path to append to.\n * @param c - The cubic curve to append.\n * @returns A new cubic path.\n * @since 1.0.0\n */\n (p: CubicPath2d, c: CubicCurve2d): CubicPath2d\n} = internal.append\n\n/**\n * Calculates the length of a cubic path.\n *\n * @param p - The cubic path to calculate the length of.\n * @returns The length of the cubic path.\n * @since 1.0.0\n */\nexport const length: (p: CubicPath2d) => number = internal.length\n\nexport const solve: {\n /**\n * Solves a cubic path for a given parameter.\n *\n * @param u - The parameter to solve for.\n * @returns A function that takes a cubic path and returns the solved vector.\n * @since 1.0.0\n */\n (u: number): (p: CubicPath2d) => Vector2\n /**\n * Solves a cubic path for a given parameter.\n *\n * @param p - The cubic path to solve.\n * @param u - The parameter to solve for.\n * @returns The solved vector.\n * @since 1.0.0\n */\n (p: CubicPath2d, u: number): Vector2\n} = internal.solve\n\n/**\n * Serializes a cubic path as an SVG path data string (the value of a `<path>`\n * element's `d` attribute), using `M` and `C` commands. Discontinuities between\n * curves emit a fresh `M` command.\n *\n * @param p - The cubic path to serialize.\n * @returns The SVG path data string.\n * @since 2.0.0\n */\nexport const toPathData: (p: CubicPath2d) => string = internal.toPathData\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & Continuous>` when adjacent curves connect.\n *\n * @since 2.0.0\n */\nexport const isContinuous: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & Continuous> =\n internal.isContinuous\n\n/**\n * Asserts that the cubic path is continuous, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asContinuous: <T>(p: CubicPath2d<T>) => CubicPath2d<T & Continuous> =\n internal.asContinuous\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & IncreasingX>` when every segment's x-polynomial is\n * strictly increasing on `[0, 1]` and adjacent segments' x-ranges don't\n * overlap.\n *\n * @since 2.0.0\n */\nexport const isIncreasingX: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & IncreasingX> =\n internal.isIncreasingX\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & DecreasingX>`.\n *\n * @since 2.0.0\n */\nexport const isDecreasingX: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & DecreasingX> =\n internal.isDecreasingX\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & MonotonicX>`.\n *\n * @since 2.0.0\n */\nexport const isMonotonicX: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & MonotonicX> =\n internal.isMonotonicX\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & IncreasingY>`.\n *\n * @since 2.0.0\n */\nexport const isIncreasingY: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & IncreasingY> =\n internal.isIncreasingY\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & DecreasingY>`.\n *\n * @since 2.0.0\n */\nexport const isDecreasingY: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & DecreasingY> =\n internal.isDecreasingY\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & MonotonicY>`.\n *\n * @since 2.0.0\n */\nexport const isMonotonicY: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & MonotonicY> =\n internal.isMonotonicY\n\n/**\n * Asserts that the path is strictly increasing in x, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asIncreasingX: <T>(p: CubicPath2d<T>) => CubicPath2d<T & IncreasingX> =\n internal.asIncreasingX\n\n/**\n * Asserts that the path is strictly decreasing in x, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asDecreasingX: <T>(p: CubicPath2d<T>) => CubicPath2d<T & DecreasingX> =\n internal.asDecreasingX\n\n/**\n * Asserts that the path is monotonic in x, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asMonotonicX: <T>(p: CubicPath2d<T>) => CubicPath2d<T & MonotonicX> =\n internal.asMonotonicX\n\n/**\n * Asserts that the path is strictly increasing in y, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asIncreasingY: <T>(p: CubicPath2d<T>) => CubicPath2d<T & IncreasingY> =\n internal.asIncreasingY\n\n/**\n * Asserts that the path is strictly decreasing in y, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asDecreasingY: <T>(p: CubicPath2d<T>) => CubicPath2d<T & DecreasingY> =\n internal.asDecreasingY\n\n/**\n * Asserts that the path is monotonic in y, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asMonotonicY: <T>(p: CubicPath2d<T>) => CubicPath2d<T & MonotonicY> =\n internal.asMonotonicY\n\nexport const solveAtX: {\n /**\n * Evaluates the path's y value at a given x. Requires the path to carry\n * the `MonotonicX` brand. Returns `Solution.none` when x is outside the\n * path's x-range.\n *\n * @param p - A path branded `MonotonicX`.\n * @param x - The x coordinate.\n * @returns The y value at x, or `none` when x is outside the path's range.\n * @since 2.0.0\n */\n <T extends MonotonicX>(p: CubicPath2d<T>, x: number): Solution.AtMostOne<number>\n /** @since 2.0.0 */\n (x: number): <T extends MonotonicX>(p: CubicPath2d<T>) => Solution.AtMostOne<number>\n} = internal.solveAtX as never\n\nexport const solveAtY: {\n /**\n * Evaluates the path's x value at a given y. Requires the path to carry\n * the `MonotonicY` brand. Returns `Solution.none` when y is outside the\n * path's y-range.\n *\n * @param p - A path branded `MonotonicY`.\n * @param y - The y coordinate.\n * @returns The x value at y, or `none` when y is outside the path's range.\n * @since 2.0.0\n */\n <T extends MonotonicY>(p: CubicPath2d<T>, y: number): Solution.AtMostOne<number>\n /** @since 2.0.0 */\n (y: number): <T extends MonotonicY>(p: CubicPath2d<T>) => Solution.AtMostOne<number>\n} = internal.solveAtY as never\n\nexport const solveByDistance: {\n /**\n * Solves a cubic path by normalized arc length. Unlike {@link solve}, which\n * is parameterized by curve `u`, this samples points at constant speed along\n * the path — `s = 0.5` returns the point exactly halfway along the curve by\n * arc length, regardless of how the underlying parameterization stretches.\n *\n * Cumulative segment lengths are cached by path identity so repeated calls\n * with the same path are fast.\n *\n * @param p - The cubic path to sample.\n * @param s - Normalized arc length in `[0, 1]`. Values outside the range are\n * clamped to path endpoints.\n * @returns The point on the path at the given normalized arc length.\n * @since 1.1.0\n */\n (p: CubicPath2d, s: number): Vector2\n /**\n * Solves a cubic path by normalized arc length.\n *\n * @param s - Normalized arc length in `[0, 1]`.\n * @returns A function that takes a cubic path and returns the point at that\n * arc length.\n * @since 1.1.0\n */\n (s: number): (p: CubicPath2d) => Vector2\n} = internal.solveByDistance\n\n/**\n * Computes the axis-aligned bounding box of the path — the smallest closed\n * `Box2d` enclosing every segment.\n *\n * @param p - The cubic path.\n * @returns A closed `Box2d` enclosing the path.\n * @since 2.0.0\n */\nexport const boundingBox: (p: CubicPath2d) => Interval2d<Closed, Closed> = internal.boundingBox\n","import type * as CubicCurve2d from '../curve/cubic2d.ts'\nimport * as RationalCubicCurve2d from '../curve/rationalCubic2d.ts'\nimport { dual, Pipeable } from '../utils.ts'\nimport { invariant } from '../utils.ts'\nimport type * as Vector2 from '../vector/vector2.ts'\nimport * as CubicPath2d from './cubic2d.ts'\nimport type { RationalCubicPath2d } from './rationalCubic2d.ts'\n\nexport const RationalCubicPath2dTypeId: unique symbol = Symbol('curvy/path/rationalCubic2d')\nexport type RationalCubicPath2dTypeId = typeof RationalCubicPath2dTypeId\n\n/** @internal */\nexport class RationalCubicPath2dImpl extends Pipeable implements RationalCubicPath2d {\n readonly [RationalCubicPath2dTypeId]: RationalCubicPath2dTypeId = RationalCubicPath2dTypeId\n\n readonly curves: ReadonlyArray<RationalCubicCurve2d.RationalCubicCurve2d>\n\n constructor(curves: ReadonlyArray<RationalCubicCurve2d.RationalCubicCurve2d>) {\n invariant(curves.length > 0, 'rational cubic path requires at least one curve')\n super()\n this.curves = curves\n }\n\n [Symbol.iterator](): Iterator<RationalCubicCurve2d.RationalCubicCurve2d> {\n return this.curves[Symbol.iterator]()\n }\n}\n\n/** @internal */\nexport const isRationalCubicPath2d = (p: unknown): p is RationalCubicPath2d =>\n typeof p === 'object' && p !== null && RationalCubicPath2dTypeId in p\n\n/** @internal */\nexport const make = (\n ...curves: ReadonlyArray<RationalCubicCurve2d.RationalCubicCurve2d>\n): RationalCubicPath2d => new RationalCubicPath2dImpl(curves)\n\n/** @internal */\nexport const fromArray = (\n curves: ReadonlyArray<RationalCubicCurve2d.RationalCubicCurve2d>,\n): RationalCubicPath2d => new RationalCubicPath2dImpl(curves)\n\n/** @internal */\nexport const append = dual<\n (c: RationalCubicCurve2d.RationalCubicCurve2d) => (p: RationalCubicPath2d) => RationalCubicPath2d,\n (p: RationalCubicPath2d, c: RationalCubicCurve2d.RationalCubicCurve2d) => RationalCubicPath2d\n>(2, (p, c) => fromArray([...p, c]))\n\n/** @internal */\nexport const solve = dual<\n (u: number) => (p: RationalCubicPath2d) => Vector2.Vector2,\n (p: RationalCubicPath2d, u: number) => Vector2.Vector2\n>(2, (p: RationalCubicPath2d, u: number) => {\n const curves = p instanceof RationalCubicPath2dImpl ? p.curves : [...p]\n\n if (u === 1) {\n const last = curves.at(-1) as RationalCubicCurve2d.RationalCubicCurve2d\n return RationalCubicCurve2d.solve(last, 1)\n }\n\n const t = u * curves.length\n const i = Math.floor(t)\n const curve = curves[i] as RationalCubicCurve2d.RationalCubicCurve2d\n return RationalCubicCurve2d.solve(curve, t - i)\n})\n\n// Path-level approximation: per-segment approximation is delegated to the\n// curve module; we just concat the results. Segment count grows from N\n// (input) to roughly N × k where k depends on weight magnitude and tolerance —\n// uniform-weight segments stay 1:1.\n/** @internal */\nexport const approximateAsCubicPath = dual<\n (tolerance: number) => (p: RationalCubicPath2d) => CubicPath2d.CubicPath2d,\n (p: RationalCubicPath2d, tolerance: number) => CubicPath2d.CubicPath2d\n>(2, (p: RationalCubicPath2d, tolerance: number) => {\n const curves: Array<CubicCurve2d.CubicCurve2d> = []\n for (const segment of p) {\n for (const approx of RationalCubicCurve2d.approximateAsCubicCurves(segment, tolerance)) {\n curves.push(approx)\n }\n }\n return CubicPath2d.fromArray(curves)\n})\n","import type { RationalCubicCurve2d } from '../curve/rationalCubic2d.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport type { CubicPath2d } from './cubic2d.ts'\nimport type { RationalCubicPath2dTypeId } from './rationalCubic2d.internal.ts'\nimport * as internal from './rationalCubic2d.internal.ts'\n\n/**\n * A rational cubic path in 2D space.\n *\n * Holds a non-empty sequence of `RationalCubicCurve2d` segments; iteration\n * yields the segments in order. The path parameter `u ∈ [0, 1]` is mapped\n * uniformly across segments — `u = 0` is the start of the first segment,\n * `u = 1` is the end of the last segment, and intermediate values pick a\n * segment by index and a local parameter within it.\n *\n * Counterpart to `CubicPath2d` for curves whose evaluation includes the\n * homogeneous-to-plane projection.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 2.0.0\n */\nexport interface RationalCubicPath2d extends Pipeable, Iterable<RationalCubicCurve2d> {\n readonly [RationalCubicPath2dTypeId]: RationalCubicPath2dTypeId\n}\n\n/**\n * Checks if a value is a `RationalCubicPath2d`.\n *\n * @param p - The value to check.\n * @returns `true` if the value is a `RationalCubicPath2d`, `false` otherwise.\n * @since 2.0.0\n */\nexport const isRationalCubicPath2d: (p: unknown) => p is RationalCubicPath2d =\n internal.isRationalCubicPath2d\n\n/**\n * Creates a new `RationalCubicPath2d` from a sequence of curves.\n *\n * @param curves - The curves to create the path from.\n * @returns A new `RationalCubicPath2d` instance.\n * @since 2.0.0\n */\nexport const make: (...curves: ReadonlyArray<RationalCubicCurve2d>) => RationalCubicPath2d =\n internal.make\n\n/**\n * Creates a new `RationalCubicPath2d` from an array of curves.\n *\n * @param curves - The curves to create the path from.\n * @returns A new `RationalCubicPath2d` instance.\n * @since 2.0.0\n */\nexport const fromArray: (curves: ReadonlyArray<RationalCubicCurve2d>) => RationalCubicPath2d =\n internal.fromArray\n\nexport const append: {\n /**\n * Appends a curve to a `RationalCubicPath2d`.\n *\n * @param c - The curve to append.\n * @returns A function that takes a path and returns a new path with the appended curve.\n * @since 2.0.0\n */\n (c: RationalCubicCurve2d): (p: RationalCubicPath2d) => RationalCubicPath2d\n /**\n * Appends a curve to a `RationalCubicPath2d`.\n *\n * @param p - The path to append to.\n * @param c - The curve to append.\n * @returns A new path with the appended curve.\n * @since 2.0.0\n */\n (p: RationalCubicPath2d, c: RationalCubicCurve2d): RationalCubicPath2d\n} = internal.append\n\nexport const solve: {\n /**\n * Evaluates the rational cubic path at parameter `u ∈ [0, 1]`.\n *\n * Picks the segment containing `u` (uniform mapping across segments) and\n * delegates to `RationalCubicCurve2d.solve` on that segment with the local\n * parameter.\n *\n * @param p - The path to evaluate.\n * @param u - The path parameter in `[0, 1]`.\n * @returns The point on the path at parameter `u`.\n * @since 2.0.0\n */\n (p: RationalCubicPath2d, u: number): Vector2\n /**\n * Evaluates the rational cubic path at parameter `u ∈ [0, 1]`.\n *\n * @param u - The path parameter in `[0, 1]`.\n * @returns A function that takes a path and returns the point at `u`.\n * @since 2.0.0\n */\n (u: number): (p: RationalCubicPath2d) => Vector2\n} = internal.solve\n\nexport const approximateAsCubicPath: {\n /**\n * Approximates the rational cubic path as a `CubicPath2d` via per-segment\n * recursive subdivision. Each input segment is split until its midpoint\n * deviates from a polynomial-cubic candidate by at most `tolerance`; the\n * surviving candidates are concatenated into a new path.\n *\n * Lossy in general — only exact when every input segment has uniform\n * weights, in which case segment count is preserved. Tighter tolerance\n * produces more segments.\n *\n * @param p - The rational cubic path to approximate.\n * @param tolerance - Maximum allowed midpoint deviation per segment; must be positive.\n * @returns A new `CubicPath2d` approximating the input.\n * @since 2.0.0\n */\n (p: RationalCubicPath2d, tolerance: number): CubicPath2d\n /**\n * Approximates the rational cubic path as a `CubicPath2d`.\n *\n * @param tolerance - Maximum allowed midpoint deviation per segment; must be positive.\n * @returns A function that takes a rational path and returns its approximation.\n * @since 2.0.0\n */\n (tolerance: number): (p: RationalCubicPath2d) => CubicPath2d\n} = internal.approximateAsCubicPath\n"],"mappings":";;;;;;;;;;AAuBA,MAAa,oBAAmC,OAAO,qBAAqB;;AAI5E,IAAa,kBAAb,cAAqC,SAAyC;CAC5E,CAAU,qBAAwC;CAGlD;CAEA,YAAY,QAAkD;EAC5D,UAAU,OAAO,SAAS,GAAG,yCAAyC;EACtE,OAAO;EACP,KAAK,SAAS;;CAGhB,CAAC,OAAO,YAAiD;EACvD,OAAO,KAAK,OAAO,OAAO,WAAW;;;;AAKzC,MAA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B,OAAO;;AAG7D,MAAaC,eACX,WACwB,IAAI,wBAAwB,OAAO;;AAG7D,MAAaC,WAAS,KAGpB,IAAI,GAAG,MAAMD,YAAU,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;;AAGpC,MAAaE,UAAQ,KAGnB,IAAI,GAAwB,MAAc;CAC1C,MAAM,SAAS,aAAa,0BAA0B,EAAE,SAAS,CAAC,GAAG,EAAE;CAEvE,IAAI,MAAM,GAER,OAAOC,QADM,OAAO,GAAG,GACW,EAAM,EAAE;CAG5C,MAAM,IAAI,IAAI,OAAO;CACrB,MAAM,IAAI,KAAK,MAAM,EAAE;CACvB,MAAM,QAAQ,OAAO;CACrB,OAAOA,QAA2B,OAAO,IAAI,EAAE;EAC/C;;AAOF,MAAaC,2BAAyB,KAGpC,IAAI,GAAwB,cAAsB;CAClD,MAAM,SAA2C,EAAE;CACnD,KAAK,MAAM,WAAW,GACpB,KAAK,MAAM,UAAUC,yBAA8C,SAAS,UAAU,EACpF,OAAO,KAAK,OAAO;CAGvB,OAAOC,YAAsB,OAAO;EACpC;;;;;;;;;;;;;;;;;;AChDF,MAAa,wBACXC;;;;;;;;AASF,MAAa,OACXC;;;;;;;;AASF,MAAa,YACXC;AAEF,MAAa,SAkBTC;AAEJ,MAAa,QAsBTC;AAEJ,MAAa,yBAyBTC"}
|
|
1
|
+
{"version":3,"file":"rationalCubic2d-CJY-feGw.mjs","names":["isCubicPath2d","make","fromArray","append","length","CubicCurve2d.length","Interval.unit","solve","CubicCurve2d.solve","derivative","cubicCurveInternal.derivative","Interval.make","Vector2.magnitude","QuadraticCurve2d.solve","toPathData","isContinuous","asContinuous","isIncreasingX","CubicPolynomial.isIncreasing","isDecreasingX","CubicPolynomial.isDecreasing","isMonotonicX","isIncreasingY","isDecreasingY","isMonotonicY","asIncreasingX","asDecreasingX","asMonotonicX","asIncreasingY","asDecreasingY","asMonotonicY","solveAtX","CubicCurve2d.solveAtX","Solution.none","solveAtY","CubicCurve2d.solveAtY","solveByDistance","boundingBox","CubicCurve2d.boundingBox","Interval2d.union","make","internal.make","fromArray","internal.fromArray","internal.isCubicPath2d","append","internal.append","internal.length","solve","internal.solve","internal.toPathData","internal.isContinuous","internal.asContinuous","internal.isIncreasingX","internal.isDecreasingX","internal.isMonotonicX","internal.isIncreasingY","internal.isDecreasingY","internal.isMonotonicY","internal.asIncreasingX","internal.asDecreasingX","internal.asMonotonicX","internal.asIncreasingY","internal.asDecreasingY","internal.asMonotonicY","internal.solveAtX","internal.solveAtY","internal.solveByDistance","internal.boundingBox","isRationalCubicPath2d","make","fromArray","append","solve","RationalCubicCurve2d.solve","approximateAsCubicPath","RationalCubicCurve2d.approximateAsCubicCurves","CubicPath2d.fromArray","internal.isRationalCubicPath2d","internal.make","internal.fromArray","internal.append","internal.solve","internal.approximateAsCubicPath"],"sources":["../../src/path/cubic2d.internal.ts","../../src/path/cubic2d.ts","../../src/path/rationalCubic2d.internal.ts","../../src/path/rationalCubic2d.ts"],"sourcesContent":["import * as Interval2d from '../interval/interval2d.ts'\nimport * as CubicCurve2d from '../curve/cubic2d.ts'\nimport * as cubicCurveInternal from '../curve/cubic2d.internal.ts'\nimport * as QuadraticCurve2d from '../curve/quadratic2d.ts'\nimport * as Interval from '../interval/interval.ts'\nimport * as CubicPolynomial from '../polynomial/cubic.ts'\nimport * as Solution from '../solution/solution.ts'\nimport { dual, Pipeable } from '../utils.ts'\nimport { invariant } from '../utils.ts'\nimport { EPSILON, epsEquals } from '../number.ts'\nimport * as Vector2 from '../vector/vector2.ts'\nimport type { CubicPath2d } from './cubic2d.ts'\nimport {\n PathTraits,\n type Continuous,\n type DecreasingX,\n type DecreasingY,\n type IncreasingX,\n type IncreasingY,\n type MonotonicX,\n type MonotonicY,\n} from './traits.ts'\n\nexport const CubicPath2dTypeId: unique symbol = Symbol('curvy/path/cubic2d')\nexport type CubicPath2dTypeId = typeof CubicPath2dTypeId\n\n/** @internal */\nexport class CubicPath2dImpl extends Pipeable implements CubicPath2d<unknown> {\n readonly [CubicPath2dTypeId]: CubicPath2dTypeId = CubicPath2dTypeId\n declare readonly [PathTraits]: unknown\n\n readonly curves: ReadonlyArray<CubicCurve2d.CubicCurve2d>\n\n constructor(curves: ReadonlyArray<CubicCurve2d.CubicCurve2d>) {\n invariant(curves.length > 0, 'cubic path requires at least one curve')\n super()\n this.curves = curves\n }\n\n [Symbol.iterator](): Iterator<CubicCurve2d.CubicCurve2d> {\n return this.curves[Symbol.iterator]()\n }\n}\n\n/** @internal */\nexport const isCubicPath2d = (p: unknown): p is CubicPath2d =>\n typeof p === 'object' && p !== null && CubicPath2dTypeId in p\n\n/** @internal */\nexport const make = (...curves: ReadonlyArray<CubicCurve2d.CubicCurve2d>): CubicPath2d =>\n new CubicPath2dImpl(curves)\n\n/** @internal */\nexport const fromArray = (curves: ReadonlyArray<CubicCurve2d.CubicCurve2d>): CubicPath2d =>\n new CubicPath2dImpl(curves)\n\n/** @internal */\nexport const append = dual<\n (c: CubicCurve2d.CubicCurve2d) => (p: CubicPath2d) => CubicPath2d,\n (p: CubicPath2d, c: CubicCurve2d.CubicCurve2d) => CubicPath2d\n>(2, (p: CubicPath2d, c: CubicCurve2d.CubicCurve2d) => fromArray([...p, c]))\n\n/** @internal */\nexport const length = (p: CubicPath2d) => {\n let total = 0\n for (const curve of p) {\n total += CubicCurve2d.length(curve, Interval.unit)\n }\n\n return total\n}\n\n/** @internal */\nexport const solve = dual<\n (u: number) => (p: CubicPath2d) => Vector2.Vector2,\n (p: CubicPath2d, u: number) => Vector2.Vector2\n>(2, (p: CubicPath2d, u: number) => {\n const curves = p instanceof CubicPath2dImpl ? p.curves : [...p]\n\n if (u === 1) {\n const last = curves.at(-1) as CubicCurve2d.CubicCurve2d\n return CubicCurve2d.solve(last, 1)\n }\n\n const t = u * curves.length\n const i = Math.floor(t)\n const curve = curves[i] as CubicCurve2d.CubicCurve2d\n return CubicCurve2d.solve(curve, t - i)\n})\n\n// Cumulative segment lengths cache. lengths[k] = total length through segment k.\n// Cached by path identity since paths are immutable.\nconst cumulativeLengthCache = new WeakMap<CubicPath2d, ReadonlyArray<number>>()\n\nconst getCumulativeLengths = (p: CubicPath2d): ReadonlyArray<number> => {\n let cached = cumulativeLengthCache.get(p)\n if (cached === undefined) {\n const lengths: Array<number> = []\n let total = 0\n for (const curve of p) {\n total += CubicCurve2d.length(curve, Interval.unit)\n lengths.push(total)\n }\n cached = lengths\n cumulativeLengthCache.set(p, cached)\n }\n return cached\n}\n\n// Newton's method to find the local parameter t ∈ [0, 1] within `curve` such\n// that the arc length from 0 to t equals `target`. Each iteration costs one\n// GL32 quadrature plus one velocity eval; converges in 3–5 iterations for\n// well-behaved curves. Falls back to bisection on cusps where speed → 0.\nconst solveCurveByDistance = (\n curve: CubicCurve2d.CubicCurve2d,\n target: number,\n segmentLength: number,\n): number => {\n if (target <= 0) {\n return 0\n }\n if (target >= segmentLength) {\n return 1\n }\n\n const derivative = cubicCurveInternal.derivative(curve)\n\n let t = target / segmentLength\n let lo = 0\n let hi = 1\n\n for (let iter = 0; iter < 16; iter++) {\n const currentLength = CubicCurve2d.length(curve, Interval.make(0, t))\n const error = currentLength - target\n\n if (Math.abs(error) < 1e-10) {\n return t\n }\n\n if (error > 0) {\n hi = t\n } else {\n lo = t\n }\n\n const speed = Vector2.magnitude(QuadraticCurve2d.solve(derivative, t))\n if (speed === 0) {\n // cusp — bisect instead\n t = (lo + hi) / 2\n continue\n }\n\n const next = t - error / speed\n // bracket-clamp Newton step; if it leaves the bracket, fall back to bisection\n t = next > lo && next < hi ? next : (lo + hi) / 2\n }\n\n return t\n}\n\n// Cubic Bernstein basis: P(t) = (1-t)³·p0 + 3(1-t)²t·p1 + 3(1-t)t²·p2 + t³·p3\n// expanded gives c0 = p0, c1 = -3p0 + 3p1, c2 = 3p0 - 6p1 + 3p2, c3 = -p0 + 3p1 - 3p2 + p3,\n// so: p0 = c0, p1 = c0 + c1/3, p2 = c0 + 2c1/3 + c2/3, p3 = c0 + c1 + c2 + c3.\n/** @internal */\nexport const toPathData = (p: CubicPath2d): string => {\n let result = ''\n let prevEndX = Number.NaN\n let prevEndY = Number.NaN\n\n for (const curve of p) {\n const c0x = curve.x.c0\n const c0y = curve.y.c0\n const c1x = curve.x.c1\n const c1y = curve.y.c1\n const c2x = curve.x.c2\n const c2y = curve.y.c2\n const c3x = curve.x.c3\n const c3y = curve.y.c3\n\n const startX = c0x\n const startY = c0y\n const ctrl1X = c0x + c1x / 3\n const ctrl1Y = c0y + c1y / 3\n const ctrl2X = c0x + (2 * c1x) / 3 + c2x / 3\n const ctrl2Y = c0y + (2 * c1y) / 3 + c2y / 3\n const endX = c0x + c1x + c2x + c3x\n const endY = c0y + c1y + c2y + c3y\n\n if (!epsEquals(startX, prevEndX) || !epsEquals(startY, prevEndY)) {\n result += ` M ${startX},${startY}`\n }\n result += ` C ${ctrl1X},${ctrl1Y} ${ctrl2X},${ctrl2Y} ${endX},${endY}`\n\n prevEndX = endX\n prevEndY = endY\n }\n\n return result.slice(1)\n}\n\n/** @internal */\nexport const isContinuous = <T>(p: CubicPath2d<T>): p is CubicPath2d<T & Continuous> => {\n let prevEndX = Number.NaN\n let prevEndY = Number.NaN\n let first = true\n\n for (const curve of p) {\n const startX = curve.x.c0\n const startY = curve.y.c0\n if (!first && (!epsEquals(startX, prevEndX) || !epsEquals(startY, prevEndY))) {\n return false\n }\n prevEndX = curve.x.c0 + curve.x.c1 + curve.x.c2 + curve.x.c3\n prevEndY = curve.y.c0 + curve.y.c1 + curve.y.c2 + curve.y.c3\n first = false\n }\n return true\n}\n\n/** @internal */\nexport const asContinuous = <T>(p: CubicPath2d<T>): CubicPath2d<T & Continuous> => {\n invariant(isContinuous(p), 'cubic path is not continuous')\n return p\n}\n\n// Per-axis monotonicity for the path: every segment's axis polynomial must be\n// strictly monotonic over the unit interval AND adjacent segments' axis\n// ranges must not overlap (modulo EPSILON for float drift).\n/** @internal */\nexport const isIncreasingX = <T>(p: CubicPath2d<T>): p is CubicPath2d<T & IncreasingX> => {\n let prevEnd = Number.NEGATIVE_INFINITY\n for (const c of p) {\n if (!CubicPolynomial.isIncreasing(c.x, Interval.unit)) {\n return false\n }\n if (c.x.c0 < prevEnd - EPSILON) {\n return false\n }\n prevEnd = c.x.c0 + c.x.c1 + c.x.c2 + c.x.c3\n }\n return true\n}\n\n/** @internal */\nexport const isDecreasingX = <T>(p: CubicPath2d<T>): p is CubicPath2d<T & DecreasingX> => {\n let prevEnd = Number.POSITIVE_INFINITY\n for (const c of p) {\n if (!CubicPolynomial.isDecreasing(c.x, Interval.unit)) {\n return false\n }\n if (c.x.c0 > prevEnd + EPSILON) {\n return false\n }\n prevEnd = c.x.c0 + c.x.c1 + c.x.c2 + c.x.c3\n }\n return true\n}\n\n/** @internal */\nexport const isMonotonicX = <T>(p: CubicPath2d<T>): p is CubicPath2d<T & MonotonicX> =>\n isIncreasingX(p) || isDecreasingX(p)\n\n/** @internal */\nexport const isIncreasingY = <T>(p: CubicPath2d<T>): p is CubicPath2d<T & IncreasingY> => {\n let prevEnd = Number.NEGATIVE_INFINITY\n for (const c of p) {\n if (!CubicPolynomial.isIncreasing(c.y, Interval.unit)) {\n return false\n }\n if (c.y.c0 < prevEnd - EPSILON) {\n return false\n }\n prevEnd = c.y.c0 + c.y.c1 + c.y.c2 + c.y.c3\n }\n return true\n}\n\n/** @internal */\nexport const isDecreasingY = <T>(p: CubicPath2d<T>): p is CubicPath2d<T & DecreasingY> => {\n let prevEnd = Number.POSITIVE_INFINITY\n for (const c of p) {\n if (!CubicPolynomial.isDecreasing(c.y, Interval.unit)) {\n return false\n }\n if (c.y.c0 > prevEnd + EPSILON) {\n return false\n }\n prevEnd = c.y.c0 + c.y.c1 + c.y.c2 + c.y.c3\n }\n return true\n}\n\n/** @internal */\nexport const isMonotonicY = <T>(p: CubicPath2d<T>): p is CubicPath2d<T & MonotonicY> =>\n isIncreasingY(p) || isDecreasingY(p)\n\n/** @internal */\nexport const asIncreasingX = <T>(p: CubicPath2d<T>): CubicPath2d<T & IncreasingX> => {\n invariant(isIncreasingX(p), 'cubic path is not increasing in x')\n return p\n}\n\n/** @internal */\nexport const asDecreasingX = <T>(p: CubicPath2d<T>): CubicPath2d<T & DecreasingX> => {\n invariant(isDecreasingX(p), 'cubic path is not decreasing in x')\n return p\n}\n\n/** @internal */\nexport const asMonotonicX = <T>(p: CubicPath2d<T>): CubicPath2d<T & MonotonicX> => {\n invariant(isMonotonicX(p), 'cubic path is not monotonic in x')\n return p\n}\n\n/** @internal */\nexport const asIncreasingY = <T>(p: CubicPath2d<T>): CubicPath2d<T & IncreasingY> => {\n invariant(isIncreasingY(p), 'cubic path is not increasing in y')\n return p\n}\n\n/** @internal */\nexport const asDecreasingY = <T>(p: CubicPath2d<T>): CubicPath2d<T & DecreasingY> => {\n invariant(isDecreasingY(p), 'cubic path is not decreasing in y')\n return p\n}\n\n/** @internal */\nexport const asMonotonicY = <T>(p: CubicPath2d<T>): CubicPath2d<T & MonotonicY> => {\n invariant(isMonotonicY(p), 'cubic path is not monotonic in y')\n return p\n}\n\n/** @internal */\nexport const solveAtX = dual(2, (p: CubicPath2d, x: number): Solution.AtMostOne<number> => {\n for (const c of p) {\n const sx = c.x.c0\n const ex = c.x.c0 + c.x.c1 + c.x.c2 + c.x.c3\n const lo = Math.min(sx, ex)\n const hi = Math.max(sx, ex)\n if (x >= lo - EPSILON && x <= hi + EPSILON) {\n return CubicCurve2d.solveAtX(c, x) as Solution.AtMostOne<number>\n }\n }\n return Solution.none\n})\n\n/** @internal */\nexport const solveAtY = dual(2, (p: CubicPath2d, y: number): Solution.AtMostOne<number> => {\n for (const c of p) {\n const sy = c.y.c0\n const ey = c.y.c0 + c.y.c1 + c.y.c2 + c.y.c3\n const lo = Math.min(sy, ey)\n const hi = Math.max(sy, ey)\n if (y >= lo - EPSILON && y <= hi + EPSILON) {\n return CubicCurve2d.solveAtY(c, y) as Solution.AtMostOne<number>\n }\n }\n return Solution.none\n})\n\n/** @internal */\nexport const solveByDistance = dual<\n (s: number) => (p: CubicPath2d) => Vector2.Vector2,\n (p: CubicPath2d, s: number) => Vector2.Vector2\n>(2, (p: CubicPath2d, s: number) => {\n if (s <= 0) {\n return solve(p, 0)\n }\n if (s >= 1) {\n return solve(p, 1)\n }\n\n const lengths = getCumulativeLengths(p)\n const total = lengths[lengths.length - 1] as number\n const target = s * total\n\n // find segment k such that lengths[k-1] ≤ target ≤ lengths[k]\n let k = 0\n while (k < lengths.length - 1 && (lengths[k] as number) < target) {\n k++\n }\n\n const segmentStart = k === 0 ? 0 : (lengths[k - 1] as number)\n const segmentEnd = lengths[k] as number\n const segmentLength = segmentEnd - segmentStart\n const segmentTarget = target - segmentStart\n\n const curves = p instanceof CubicPath2dImpl ? p.curves : [...p]\n const curve = curves[k] as CubicCurve2d.CubicCurve2d\n const localT = solveCurveByDistance(curve, segmentTarget, segmentLength)\n\n return CubicCurve2d.solve(curve, localT)\n})\n\n/** @internal */\nexport const boundingBox = (\n p: CubicPath2d,\n): Interval2d.Interval2d<Interval.Closed, Interval.Closed> => {\n const iter = p[Symbol.iterator]()\n const first = iter.next()\n let acc = CubicCurve2d.boundingBox(first.value as CubicCurve2d.CubicCurve2d)\n for (let next = iter.next(); !next.done; next = iter.next()) {\n acc = Interval2d.union(acc, CubicCurve2d.boundingBox(next.value))\n }\n return acc\n}\n","import type { Interval2d } from '../interval/interval2d.ts'\nimport type { CubicCurve2d } from '../curve/cubic2d.ts'\nimport type { Closed } from '../interval/interval.ts'\nimport type * as Solution from '../solution/solution.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport type { CubicPath2dTypeId } from './cubic2d.internal.ts'\nimport * as internal from './cubic2d.internal.ts'\nimport type {\n Continuous,\n DecreasingX,\n DecreasingY,\n IncreasingX,\n IncreasingY,\n MonotonicX,\n MonotonicY,\n PathTraits,\n} from './traits.ts'\n\nexport type {\n Continuous,\n DecreasingX,\n DecreasingY,\n IncreasingX,\n IncreasingY,\n MonotonicX,\n MonotonicY,\n} from './traits.ts'\n\n/**\n * A cubic path in 2D space.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * The `Trait` type parameter accumulates trait brands as the path is refined\n * via `isContinuous` / `asContinuous`.\n *\n * @since 1.0.0\n */\nexport interface CubicPath2d<out Trait = unknown> extends Pipeable, Iterable<CubicCurve2d> {\n readonly [CubicPath2dTypeId]: CubicPath2dTypeId\n readonly [PathTraits]: Trait\n}\n\n/**\n * Creates a new `CubicPath2d` instance from a sequence of curves.\n *\n * @param curves - The curves to create the path from.\n * @returns A new `CubicPath2d` instance.\n * @since 2.0.0\n */\nexport const make: (...curves: ReadonlyArray<CubicCurve2d>) => CubicPath2d = internal.make\n\n/**\n * Creates a new `CubicPath2d` instance from an array of curves.\n *\n * @param curves - The curves to create the path from.\n * @returns A new `CubicPath2d` instance.\n * @since 2.0.0\n */\nexport const fromArray: (curves: ReadonlyArray<CubicCurve2d>) => CubicPath2d = internal.fromArray\n\n/**\n * Checks if a value is a `CubicPath2d`.\n *\n * @param p - The value to check.\n * @returns `true` if the value is a `CubicPath2d`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isCubicPath2d: (p: unknown) => p is CubicPath2d = internal.isCubicPath2d\n\nexport const append: {\n /**\n * Appends a cubic curve to a cubic path.\n *\n * @param c - The cubic curve to append.\n * @returns A function that takes a cubic path and returns a new cubic path.\n * @since 1.0.0\n */\n (c: CubicCurve2d): (p: CubicPath2d) => CubicPath2d\n /**\n * Appends a cubic curve to a cubic path.\n *\n * @param p - The cubic path to append to.\n * @param c - The cubic curve to append.\n * @returns A new cubic path.\n * @since 1.0.0\n */\n (p: CubicPath2d, c: CubicCurve2d): CubicPath2d\n} = internal.append\n\n/**\n * Calculates the length of a cubic path.\n *\n * @param p - The cubic path to calculate the length of.\n * @returns The length of the cubic path.\n * @since 1.0.0\n */\nexport const length: (p: CubicPath2d) => number = internal.length\n\nexport const solve: {\n /**\n * Solves a cubic path for a given parameter.\n *\n * @param u - The parameter to solve for.\n * @returns A function that takes a cubic path and returns the solved vector.\n * @since 1.0.0\n */\n (u: number): (p: CubicPath2d) => Vector2\n /**\n * Solves a cubic path for a given parameter.\n *\n * @param p - The cubic path to solve.\n * @param u - The parameter to solve for.\n * @returns The solved vector.\n * @since 1.0.0\n */\n (p: CubicPath2d, u: number): Vector2\n} = internal.solve\n\n/**\n * Serializes a cubic path as an SVG path data string (the value of a `<path>`\n * element's `d` attribute), using `M` and `C` commands. Discontinuities between\n * curves emit a fresh `M` command.\n *\n * @param p - The cubic path to serialize.\n * @returns The SVG path data string.\n * @since 2.0.0\n */\nexport const toPathData: (p: CubicPath2d) => string = internal.toPathData\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & Continuous>` when adjacent curves connect.\n *\n * @since 2.0.0\n */\nexport const isContinuous: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & Continuous> =\n internal.isContinuous\n\n/**\n * Asserts that the cubic path is continuous, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asContinuous: <T>(p: CubicPath2d<T>) => CubicPath2d<T & Continuous> =\n internal.asContinuous\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & IncreasingX>` when every segment's x-polynomial is\n * strictly increasing on `[0, 1]` and adjacent segments' x-ranges don't\n * overlap.\n *\n * @since 2.0.0\n */\nexport const isIncreasingX: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & IncreasingX> =\n internal.isIncreasingX\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & DecreasingX>`.\n *\n * @since 2.0.0\n */\nexport const isDecreasingX: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & DecreasingX> =\n internal.isDecreasingX\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & MonotonicX>`.\n *\n * @since 2.0.0\n */\nexport const isMonotonicX: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & MonotonicX> =\n internal.isMonotonicX\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & IncreasingY>`.\n *\n * @since 2.0.0\n */\nexport const isIncreasingY: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & IncreasingY> =\n internal.isIncreasingY\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & DecreasingY>`.\n *\n * @since 2.0.0\n */\nexport const isDecreasingY: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & DecreasingY> =\n internal.isDecreasingY\n\n/**\n * Type-narrowing predicate: refines `CubicPath2d<T>` to\n * `CubicPath2d<T & MonotonicY>`.\n *\n * @since 2.0.0\n */\nexport const isMonotonicY: <T>(p: CubicPath2d<T>) => p is CubicPath2d<T & MonotonicY> =\n internal.isMonotonicY\n\n/**\n * Asserts that the path is strictly increasing in x, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asIncreasingX: <T>(p: CubicPath2d<T>) => CubicPath2d<T & IncreasingX> =\n internal.asIncreasingX\n\n/**\n * Asserts that the path is strictly decreasing in x, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asDecreasingX: <T>(p: CubicPath2d<T>) => CubicPath2d<T & DecreasingX> =\n internal.asDecreasingX\n\n/**\n * Asserts that the path is monotonic in x, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asMonotonicX: <T>(p: CubicPath2d<T>) => CubicPath2d<T & MonotonicX> =\n internal.asMonotonicX\n\n/**\n * Asserts that the path is strictly increasing in y, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asIncreasingY: <T>(p: CubicPath2d<T>) => CubicPath2d<T & IncreasingY> =\n internal.asIncreasingY\n\n/**\n * Asserts that the path is strictly decreasing in y, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asDecreasingY: <T>(p: CubicPath2d<T>) => CubicPath2d<T & DecreasingY> =\n internal.asDecreasingY\n\n/**\n * Asserts that the path is monotonic in y, throwing on failure.\n *\n * @since 2.0.0\n */\nexport const asMonotonicY: <T>(p: CubicPath2d<T>) => CubicPath2d<T & MonotonicY> =\n internal.asMonotonicY\n\nexport const solveAtX: {\n /**\n * Evaluates the path's y value at a given x. Requires the path to carry\n * the `MonotonicX` brand. Returns `Solution.none` when x is outside the\n * path's x-range.\n *\n * @param p - A path branded `MonotonicX`.\n * @param x - The x coordinate.\n * @returns The y value at x, or `none` when x is outside the path's range.\n * @since 2.0.0\n */\n <T extends MonotonicX>(p: CubicPath2d<T>, x: number): Solution.AtMostOne<number>\n /** @since 2.0.0 */\n (x: number): <T extends MonotonicX>(p: CubicPath2d<T>) => Solution.AtMostOne<number>\n} = internal.solveAtX as never\n\nexport const solveAtY: {\n /**\n * Evaluates the path's x value at a given y. Requires the path to carry\n * the `MonotonicY` brand. Returns `Solution.none` when y is outside the\n * path's y-range.\n *\n * @param p - A path branded `MonotonicY`.\n * @param y - The y coordinate.\n * @returns The x value at y, or `none` when y is outside the path's range.\n * @since 2.0.0\n */\n <T extends MonotonicY>(p: CubicPath2d<T>, y: number): Solution.AtMostOne<number>\n /** @since 2.0.0 */\n (y: number): <T extends MonotonicY>(p: CubicPath2d<T>) => Solution.AtMostOne<number>\n} = internal.solveAtY as never\n\nexport const solveByDistance: {\n /**\n * Solves a cubic path by normalized arc length. Unlike {@link solve}, which\n * is parameterized by curve `u`, this samples points at constant speed along\n * the path — `s = 0.5` returns the point exactly halfway along the curve by\n * arc length, regardless of how the underlying parameterization stretches.\n *\n * Cumulative segment lengths are cached by path identity so repeated calls\n * with the same path are fast.\n *\n * @param p - The cubic path to sample.\n * @param s - Normalized arc length in `[0, 1]`. Values outside the range are\n * clamped to path endpoints.\n * @returns The point on the path at the given normalized arc length.\n * @since 1.1.0\n */\n (p: CubicPath2d, s: number): Vector2\n /**\n * Solves a cubic path by normalized arc length.\n *\n * @param s - Normalized arc length in `[0, 1]`.\n * @returns A function that takes a cubic path and returns the point at that\n * arc length.\n * @since 1.1.0\n */\n (s: number): (p: CubicPath2d) => Vector2\n} = internal.solveByDistance\n\n/**\n * Computes the axis-aligned bounding box of the path — the smallest closed\n * `Box2d` enclosing every segment.\n *\n * @param p - The cubic path.\n * @returns A closed `Box2d` enclosing the path.\n * @since 2.0.0\n */\nexport const boundingBox: (p: CubicPath2d) => Interval2d<Closed, Closed> = internal.boundingBox\n","import type * as CubicCurve2d from '../curve/cubic2d.ts'\nimport * as RationalCubicCurve2d from '../curve/rationalCubic2d.ts'\nimport { dual, Pipeable } from '../utils.ts'\nimport { invariant } from '../utils.ts'\nimport type * as Vector2 from '../vector/vector2.ts'\nimport * as CubicPath2d from './cubic2d.ts'\nimport type { RationalCubicPath2d } from './rationalCubic2d.ts'\n\nexport const RationalCubicPath2dTypeId: unique symbol = Symbol('curvy/path/rationalCubic2d')\nexport type RationalCubicPath2dTypeId = typeof RationalCubicPath2dTypeId\n\n/** @internal */\nexport class RationalCubicPath2dImpl extends Pipeable implements RationalCubicPath2d {\n readonly [RationalCubicPath2dTypeId]: RationalCubicPath2dTypeId = RationalCubicPath2dTypeId\n\n readonly curves: ReadonlyArray<RationalCubicCurve2d.RationalCubicCurve2d>\n\n constructor(curves: ReadonlyArray<RationalCubicCurve2d.RationalCubicCurve2d>) {\n invariant(curves.length > 0, 'rational cubic path requires at least one curve')\n super()\n this.curves = curves\n }\n\n [Symbol.iterator](): Iterator<RationalCubicCurve2d.RationalCubicCurve2d> {\n return this.curves[Symbol.iterator]()\n }\n}\n\n/** @internal */\nexport const isRationalCubicPath2d = (p: unknown): p is RationalCubicPath2d =>\n typeof p === 'object' && p !== null && RationalCubicPath2dTypeId in p\n\n/** @internal */\nexport const make = (\n ...curves: ReadonlyArray<RationalCubicCurve2d.RationalCubicCurve2d>\n): RationalCubicPath2d => new RationalCubicPath2dImpl(curves)\n\n/** @internal */\nexport const fromArray = (\n curves: ReadonlyArray<RationalCubicCurve2d.RationalCubicCurve2d>,\n): RationalCubicPath2d => new RationalCubicPath2dImpl(curves)\n\n/** @internal */\nexport const append = dual<\n (c: RationalCubicCurve2d.RationalCubicCurve2d) => (p: RationalCubicPath2d) => RationalCubicPath2d,\n (p: RationalCubicPath2d, c: RationalCubicCurve2d.RationalCubicCurve2d) => RationalCubicPath2d\n>(2, (p, c) => fromArray([...p, c]))\n\n/** @internal */\nexport const solve = dual<\n (u: number) => (p: RationalCubicPath2d) => Vector2.Vector2,\n (p: RationalCubicPath2d, u: number) => Vector2.Vector2\n>(2, (p: RationalCubicPath2d, u: number) => {\n const curves = p instanceof RationalCubicPath2dImpl ? p.curves : [...p]\n\n if (u === 1) {\n const last = curves.at(-1) as RationalCubicCurve2d.RationalCubicCurve2d\n return RationalCubicCurve2d.solve(last, 1)\n }\n\n const t = u * curves.length\n const i = Math.floor(t)\n const curve = curves[i] as RationalCubicCurve2d.RationalCubicCurve2d\n return RationalCubicCurve2d.solve(curve, t - i)\n})\n\n// Path-level approximation: per-segment approximation is delegated to the\n// curve module; we just concat the results. Segment count grows from N\n// (input) to roughly N × k where k depends on weight magnitude and tolerance —\n// uniform-weight segments stay 1:1.\n/** @internal */\nexport const approximateAsCubicPath = dual<\n (tolerance: number) => (p: RationalCubicPath2d) => CubicPath2d.CubicPath2d,\n (p: RationalCubicPath2d, tolerance: number) => CubicPath2d.CubicPath2d\n>(2, (p: RationalCubicPath2d, tolerance: number) => {\n const curves: Array<CubicCurve2d.CubicCurve2d> = []\n for (const segment of p) {\n for (const approx of RationalCubicCurve2d.approximateAsCubicCurves(segment, tolerance)) {\n curves.push(approx)\n }\n }\n return CubicPath2d.fromArray(curves)\n})\n","import type { RationalCubicCurve2d } from '../curve/rationalCubic2d.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector2 } from '../vector/vector2.ts'\nimport type { CubicPath2d } from './cubic2d.ts'\nimport type { RationalCubicPath2dTypeId } from './rationalCubic2d.internal.ts'\nimport * as internal from './rationalCubic2d.internal.ts'\n\n/**\n * A rational cubic path in 2D space.\n *\n * Holds a non-empty sequence of `RationalCubicCurve2d` segments; iteration\n * yields the segments in order. The path parameter `u ∈ [0, 1]` is mapped\n * uniformly across segments — `u = 0` is the start of the first segment,\n * `u = 1` is the end of the last segment, and intermediate values pick a\n * segment by index and a local parameter within it.\n *\n * Counterpart to `CubicPath2d` for curves whose evaluation includes the\n * homogeneous-to-plane projection.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 2.0.0\n */\nexport interface RationalCubicPath2d extends Pipeable, Iterable<RationalCubicCurve2d> {\n readonly [RationalCubicPath2dTypeId]: RationalCubicPath2dTypeId\n}\n\n/**\n * Checks if a value is a `RationalCubicPath2d`.\n *\n * @param p - The value to check.\n * @returns `true` if the value is a `RationalCubicPath2d`, `false` otherwise.\n * @since 2.0.0\n */\nexport const isRationalCubicPath2d: (p: unknown) => p is RationalCubicPath2d =\n internal.isRationalCubicPath2d\n\n/**\n * Creates a new `RationalCubicPath2d` from a sequence of curves.\n *\n * @param curves - The curves to create the path from.\n * @returns A new `RationalCubicPath2d` instance.\n * @since 2.0.0\n */\nexport const make: (...curves: ReadonlyArray<RationalCubicCurve2d>) => RationalCubicPath2d =\n internal.make\n\n/**\n * Creates a new `RationalCubicPath2d` from an array of curves.\n *\n * @param curves - The curves to create the path from.\n * @returns A new `RationalCubicPath2d` instance.\n * @since 2.0.0\n */\nexport const fromArray: (curves: ReadonlyArray<RationalCubicCurve2d>) => RationalCubicPath2d =\n internal.fromArray\n\nexport const append: {\n /**\n * Appends a curve to a `RationalCubicPath2d`.\n *\n * @param c - The curve to append.\n * @returns A function that takes a path and returns a new path with the appended curve.\n * @since 2.0.0\n */\n (c: RationalCubicCurve2d): (p: RationalCubicPath2d) => RationalCubicPath2d\n /**\n * Appends a curve to a `RationalCubicPath2d`.\n *\n * @param p - The path to append to.\n * @param c - The curve to append.\n * @returns A new path with the appended curve.\n * @since 2.0.0\n */\n (p: RationalCubicPath2d, c: RationalCubicCurve2d): RationalCubicPath2d\n} = internal.append\n\nexport const solve: {\n /**\n * Evaluates the rational cubic path at parameter `u ∈ [0, 1]`.\n *\n * Picks the segment containing `u` (uniform mapping across segments) and\n * delegates to `RationalCubicCurve2d.solve` on that segment with the local\n * parameter.\n *\n * @param p - The path to evaluate.\n * @param u - The path parameter in `[0, 1]`.\n * @returns The point on the path at parameter `u`.\n * @since 2.0.0\n */\n (p: RationalCubicPath2d, u: number): Vector2\n /**\n * Evaluates the rational cubic path at parameter `u ∈ [0, 1]`.\n *\n * @param u - The path parameter in `[0, 1]`.\n * @returns A function that takes a path and returns the point at `u`.\n * @since 2.0.0\n */\n (u: number): (p: RationalCubicPath2d) => Vector2\n} = internal.solve\n\nexport const approximateAsCubicPath: {\n /**\n * Approximates the rational cubic path as a `CubicPath2d` via per-segment\n * recursive subdivision. Each input segment is split until its midpoint\n * deviates from a polynomial-cubic candidate by at most `tolerance`; the\n * surviving candidates are concatenated into a new path.\n *\n * Lossy in general — only exact when every input segment has uniform\n * weights, in which case segment count is preserved. Tighter tolerance\n * produces more segments.\n *\n * @param p - The rational cubic path to approximate.\n * @param tolerance - Maximum allowed midpoint deviation per segment; must be positive.\n * @returns A new `CubicPath2d` approximating the input.\n * @since 2.0.0\n */\n (p: RationalCubicPath2d, tolerance: number): CubicPath2d\n /**\n * Approximates the rational cubic path as a `CubicPath2d`.\n *\n * @param tolerance - Maximum allowed midpoint deviation per segment; must be positive.\n * @returns A function that takes a rational path and returns its approximation.\n * @since 2.0.0\n */\n (tolerance: number): (p: RationalCubicPath2d) => CubicPath2d\n} = internal.approximateAsCubicPath\n"],"mappings":";;;;;;;;;;AAuBA,MAAa,oBAAmC,OAAO,qBAAqB;;AAI5E,IAAa,kBAAb,cAAqC,SAAyC;CAC5E,CAAU,qBAAwC;CAGlD;CAEA,YAAY,QAAkD;EAC5D,UAAU,OAAO,SAAS,GAAG,yCAAyC;EACtE,OAAO;EACP,KAAK,SAAS;;CAGhB,CAAC,OAAO,YAAiD;EACvD,OAAO,KAAK,OAAO,OAAO,WAAW;;;;AAKzC,MAAaA,mBAAiB,MAC5B,O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aC,eACX,WACwB,IAAI,wBAAwB,OAAO;;AAG7D,MAAaC,WAAS,KAGpB,IAAI,GAAG,MAAMD,YAAU,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;;AAGpC,MAAaE,UAAQ,KAGnB,IAAI,GAAwB,MAAc;CAC1C,MAAM,SAAS,aAAa,0BAA0B,EAAE,SAAS,CAAC,GAAG,EAAE;CAEvE,IAAI,MAAM,GAER,OAAOC,QADM,OAAO,GAAG,GACW,EAAM,EAAE;CAG5C,MAAM,IAAI,IAAI,OAAO;CACrB,MAAM,IAAI,KAAK,MAAM,EAAE;CACvB,MAAM,QAAQ,OAAO;CACrB,OAAOA,QAA2B,OAAO,IAAI,EAAE;EAC/C;;AAOF,MAAaC,2BAAyB,KAGpC,IAAI,GAAwB,cAAsB;CAClD,MAAM,SAA2C,EAAE;CACnD,KAAK,MAAM,WAAW,GACpB,KAAK,MAAM,UAAUC,yBAA8C,SAAS,UAAU,EACpF,OAAO,KAAK,OAAO;CAGvB,OAAOC,YAAsB,OAAO;EACpC;;;;;;;;;;;;;;;;;;AChDF,MAAa,wBACXC;;;;;;;;AASF,MAAa,OACXC;;;;;;;;AASF,MAAa,YACXC;AAEF,MAAa,SAkBTC;AAEJ,MAAa,QAsBTC;AAEJ,MAAa,yBAyBTC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-25Hzd3z8.mjs";
|
|
2
|
-
import { C as
|
|
2
|
+
import { A as unweighted$1, C as setR$1, D as softmax$1, E as setY$1, M as withWeight$1, O as subtract$1, S as scale$1, T as setX$1, _ as mapR$1, a as equals$1, b as mapY$1, c as getTheta$1, d as hadamard$1, f as isVector2$1, g as makeWeighted$1, h as make$1, i as dot$1, j as weightedEquals$1, k as transpose$1, l as getX$1, m as magnitude$1, n as components$1, o as fromPolar$1, p as isWeighted$1, r as cross$1, s as fromTuple$1, t as add$1, u as getY$1, v as mapTheta$1, w as setTheta$1, x as normalize$1, y as mapX$1 } from "./vector2.internal-DP1nTBdS.mjs";
|
|
3
3
|
//#region src/vector/vector2.ts
|
|
4
4
|
var vector2_exports = /* @__PURE__ */ __exportAll({
|
|
5
5
|
add: () => add,
|
|
@@ -19,6 +19,10 @@ var vector2_exports = /* @__PURE__ */ __exportAll({
|
|
|
19
19
|
magnitude: () => magnitude,
|
|
20
20
|
make: () => make,
|
|
21
21
|
makeWeighted: () => makeWeighted,
|
|
22
|
+
mapR: () => mapR,
|
|
23
|
+
mapTheta: () => mapTheta,
|
|
24
|
+
mapX: () => mapX,
|
|
25
|
+
mapY: () => mapY,
|
|
22
26
|
normalize: () => normalize,
|
|
23
27
|
scale: () => scale,
|
|
24
28
|
setR: () => setR,
|
|
@@ -164,6 +168,7 @@ const scale = scale$1;
|
|
|
164
168
|
*/
|
|
165
169
|
const getX = getX$1;
|
|
166
170
|
const setX = setX$1;
|
|
171
|
+
const mapX = mapX$1;
|
|
167
172
|
/**
|
|
168
173
|
* Gets the y component of a `Vector2`.
|
|
169
174
|
*
|
|
@@ -173,6 +178,7 @@ const setX = setX$1;
|
|
|
173
178
|
*/
|
|
174
179
|
const getY = getY$1;
|
|
175
180
|
const setY = setY$1;
|
|
181
|
+
const mapY = mapY$1;
|
|
176
182
|
/**
|
|
177
183
|
* Gets the radius of a `Vector2`.
|
|
178
184
|
*
|
|
@@ -182,6 +188,7 @@ const setY = setY$1;
|
|
|
182
188
|
*/
|
|
183
189
|
const getR = magnitude;
|
|
184
190
|
const setR = setR$1;
|
|
191
|
+
const mapR = mapR$1;
|
|
185
192
|
/**
|
|
186
193
|
* Gets the angle of a `Vector2`.
|
|
187
194
|
*
|
|
@@ -191,7 +198,8 @@ const setR = setR$1;
|
|
|
191
198
|
*/
|
|
192
199
|
const getTheta = getTheta$1;
|
|
193
200
|
const setTheta = setTheta$1;
|
|
201
|
+
const mapTheta = mapTheta$1;
|
|
194
202
|
//#endregion
|
|
195
203
|
export { make as a, subtract as c, magnitude as i, vector2_exports as l, cross as n, makeWeighted as o, isVector2 as r, scale as s, add as t };
|
|
196
204
|
|
|
197
|
-
//# sourceMappingURL=vector2-
|
|
205
|
+
//# sourceMappingURL=vector2-CSkaMXvp.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector2-CSkaMXvp.mjs","names":["internal.isVector2","internal.isWeighted","internal.makeWeighted","internal.withWeight","internal.unweighted","internal.weightedEquals","internal.equals","internal.make","internal.fromTuple","internal.transpose","internal.fromPolar","internal.magnitude","internal.normalize","internal.dot","internal.cross","internal.components","internal.softmax","internal.add","internal.subtract","internal.hadamard","internal.scale","internal.getX","internal.setX","internal.mapX","internal.getY","internal.setY","internal.mapY","internal.setR","internal.mapR","internal.getTheta","internal.setTheta","internal.mapTheta"],"sources":["../../src/vector/vector2.ts"],"sourcesContent":["import type { TwoDimensional } from '../dimensions.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector2TypeId, WeightedVector2TypeId } from './vector2.internal.ts'\nimport * as internal from './vector2.internal.ts'\n\n/**\n * A 2D vector.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 1.0.0\n */\nexport interface Vector2 extends Pipeable, TwoDimensional<number> {\n readonly [Vector2TypeId]: Vector2TypeId\n}\n\n/**\n * A 2D point with an associated positive scalar weight.\n *\n * Used by rational primitives (e.g. `RationalBezier2d`) where each control\n * point carries an influence weight. The interface is structurally distinct\n * from `Vector2` — its brand prevents accidental use with vector arithmetic\n * (`add`, `subtract`, `scale`, etc.) where weighted operations are not\n * well-defined.\n *\n * Construct via {@link makeWeighted} (from raw components) or\n * {@link withWeight} (from an existing `Vector2`).\n *\n * @since 2.0.0\n */\nexport interface Weighted extends Pipeable {\n readonly [WeightedVector2TypeId]: WeightedVector2TypeId\n readonly x: number\n readonly y: number\n readonly weight: number\n}\n\n/**\n * Checks if a value is a `Vector2`.\n *\n * @param v - The value to check.\n * @returns `true` if the value is a `Vector2`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isVector2: (v: unknown) => v is Vector2 = internal.isVector2\n\n/**\n * Checks if a value is a `Vector2.Weighted`.\n *\n * @param v - The value to check.\n * @returns `true` if the value is a `Vector2.Weighted`, `false` otherwise.\n * @since 2.0.0\n */\nexport const isWeighted: (v: unknown) => v is Weighted = internal.isWeighted\n\n/**\n * Creates a new `Vector2.Weighted` from raw components. The weight must be\n * finite and positive.\n *\n * @param x - The x component.\n * @param y - The y component.\n * @param weight - The positive scalar weight.\n * @returns A new `Vector2.Weighted` instance.\n * @since 2.0.0\n */\nexport const makeWeighted: (x: number, y: number, weight: number) => Weighted =\n internal.makeWeighted\n\nexport const withWeight: {\n /**\n * Promotes a `Vector2` to a `Vector2.Weighted` by attaching the given\n * positive scalar weight.\n *\n * @param v - The point to weight.\n * @param weight - The positive scalar weight.\n * @returns A new `Vector2.Weighted` instance.\n * @since 2.0.0\n */\n (v: Vector2, weight: number): Weighted\n /**\n * Promotes a `Vector2` to a `Vector2.Weighted` by attaching the given\n * positive scalar weight.\n *\n * @param weight - The positive scalar weight.\n * @returns A function that takes a `Vector2` and returns a weighted point.\n * @since 2.0.0\n */\n (weight: number): (v: Vector2) => Weighted\n} = internal.withWeight\n\n/**\n * Strips the weight from a `Vector2.Weighted`, returning the underlying point.\n *\n * @param w - The weighted point.\n * @returns A new `Vector2` instance with the same x and y components.\n * @since 2.0.0\n */\nexport const unweighted: (w: Weighted) => Vector2 = internal.unweighted\n\nexport const weightedEquals: {\n /**\n * Checks if two `Vector2.Weighted` instances are approximately equal —\n * point components and weight all within the default absolute tolerance.\n *\n * @param a - The first weighted point.\n * @param b - The second weighted point.\n * @returns `true` when components and weight are within tolerance.\n * @since 2.0.0\n */\n (a: Weighted, b: Weighted): boolean\n /**\n * Checks if two `Vector2.Weighted` instances are approximately equal.\n *\n * @param b - The second weighted point.\n * @returns A function that takes the first weighted point and returns the comparison result.\n * @since 2.0.0\n */\n (b: Weighted): (a: Weighted) => boolean\n} = internal.weightedEquals\n\nexport const equals: {\n /**\n * Checks if two `Vector2` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns `true` when each pair of components is within tolerance.\n * @since 1.1.0\n */\n (a: Vector2, b: Vector2): boolean\n /**\n * Checks if two `Vector2` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the comparison result.\n * @since 1.1.0\n */\n (b: Vector2): (a: Vector2) => boolean\n} = internal.equals\n\nexport const make: {\n /**\n * Creates a new `Vector2` instance.\n *\n * @param xy - The x and y components of the vector.\n * @returns A new `Vector2` instance.\n * @since 1.0.0\n */\n (xy: number): Vector2\n /**\n * Creates a new `Vector2` instance.\n *\n * @param x - The x component of the vector.\n * @param y - The y component of the vector.\n * @returns A new `Vector2` instance.\n * @since 1.0.0\n */\n (x: number, y: number): Vector2\n} = internal.make\n\n/**\n * Creates a new `Vector2` instance from a `[x, y]` tuple. Inverse of\n * {@link components}.\n *\n * @param t - The `[x, y]` tuple.\n * @returns A new `Vector2` instance.\n * @since 2.0.0\n */\nexport const fromTuple: (t: readonly [number, number]) => Vector2 = internal.fromTuple\n\n/**\n * Transposes a 2-tuple of items into one or more `Vector2`s, one per channel\n * extracted by the projection function. See {@link Vector4.transpose} for the\n * full operation description; this is the 2-component analog.\n *\n * @param inputs - Exactly two items of any type.\n * @param project - A function returning a fixed-arity tuple of numbers — one per output channel.\n * @returns A tuple of `Vector2`s with the same arity as the projection's return tuple.\n * @since 2.0.0\n */\nexport const transpose: <T, const Channels extends ReadonlyArray<number>>(\n inputs: readonly [T, T],\n project: (item: T) => Channels,\n) => { readonly [K in keyof Channels]: Vector2 } = internal.transpose\n\n/**\n * Creates a new `Vector2` instance from polar coordinates.\n *\n * @param r - The radius.\n * @param theta - The angle, in radians.\n * @returns A new `Vector2` instance.\n * @since 1.0.0\n */\nexport const fromPolar: (r: number, theta: number) => Vector2 = internal.fromPolar\n\n/**\n * Calculates the magnitude of a `Vector2`.\n *\n * @param vector - The vector to calculate the magnitude of.\n * @returns The magnitude of the vector.\n * @since 1.0.0\n */\nexport const magnitude: (vector: Vector2) => number = internal.magnitude\n\n/**\n * Normalizes a `Vector2`.\n *\n * @param vector - The vector to normalize.\n * @returns A new `Vector2` instance with the same direction and a magnitude of 1.\n * @since 1.0.0\n */\nexport const normalize: (vector: Vector2) => Vector2 = internal.normalize\n\nexport const dot: {\n /**\n * Calculates the dot product of two `Vector2` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns The dot product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector2, b: Vector2): number\n /**\n * Calculates the dot product of two `Vector2` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the dot product.\n * @since 1.0.0\n */\n (b: Vector2): (a: Vector2) => number\n} = internal.dot\n\nexport const cross: {\n /**\n * Calculates the cross product of two `Vector2` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns The cross product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector2, b: Vector2): number\n /**\n * Calculates the cross product of two `Vector2` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the cross product.\n * @since 1.0.0\n */\n (b: Vector2): (a: Vector2) => number\n} = internal.cross\n\n/**\n * Returns the components of a `Vector2` as an array.\n *\n * @param r - The radius.\n * @param theta - The angle, in radians.\n * @returns A new `Vector2` instance.\n * @since 1.0.0\n */\nexport const components: (v: Vector2) => [number, number] = internal.components\n\n/**\n * Applies the softmax function to a `Vector2`.\n *\n * @param v - The vector to apply the softmax function to.\n * @returns A new `Vector2` instance with the softmax applied.\n * @since 1.0.0\n */\nexport const softmax: (v: Vector2) => Vector2 = internal.softmax\n\n/**\n * Creates a zero vector.\n *\n * @returns A new `Vector2` instance with both components set to 0.\n * @since 1.0.0\n */\nexport const zero = make(0)\n\n/**\n * Creates a unit vector.\n *\n * @returns A new `Vector2` instance with both components set to 1.\n * @since 1.0.0\n */\nexport const unit = make(1)\n\nexport const add: {\n /**\n * Adds two `Vector2` instances together.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector2` instance representing the sum of the two vectors.\n * @since 1.0.0\n */\n (a: Vector2, b: Vector2): Vector2\n /**\n * Adds two `Vector2` instances together.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the sum.\n * @since 1.0.0\n */\n (b: Vector2): (a: Vector2) => Vector2\n} = internal.add\n\nexport const subtract: {\n /**\n * Subtracts one `Vector2` instance from another.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector2` instance representing the difference of the two vectors.\n * @since 1.0.0\n */\n (a: Vector2, b: Vector2): Vector2\n /**\n * Subtracts one `Vector2` instance from another.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the difference.\n * @since 1.0.0\n */\n (b: Vector2): (a: Vector2) => Vector2\n} = internal.subtract\n\nexport const hadamard: {\n /**\n * Performs the Hadamard product of two `Vector2` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector2` instance representing the Hadamard product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector2, b: Vector2): Vector2\n /**\n * Performs the Hadamard product of two `Vector2` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the Hadamard product.\n * @since 1.0.0\n */\n (b: Vector2): (a: Vector2) => Vector2\n} = internal.hadamard\n\nexport const scale: {\n /**\n * Scales a `Vector2` by a scalar value.\n *\n * @param s - The scalar value to scale by.\n * @returns A function that takes a vector and returns the scaled vector.\n * @since 1.0.0\n */\n (s: number): (v: Vector2) => Vector2\n /**\n * Scales a `Vector2` by a scalar value.\n *\n * @param v - The vector to scale.\n * @param s - The scalar value to scale by.\n * @returns A new `Vector2` instance representing the scaled vector.\n * @since 1.0.0\n */\n (v: Vector2, s: number): Vector2\n} = internal.scale\n\n/**\n * Gets the x component of a `Vector2`.\n *\n * @param v - The vector to get the x component from.\n * @returns The x component of the vector.\n * @since 1.0.0\n */\nexport const getX: (v: Vector2) => number = internal.getX\n\nexport const setX: {\n /**\n * Sets the x component of a `Vector2`.\n *\n * @param v - The vector to set the x component of.\n * @param x - The new x component.\n * @returns A new `Vector2` instance with the updated x component.\n * @since 1.0.0\n */\n (v: Vector2, x: number): Vector2\n /**\n * Sets the x component of a `Vector2`.\n *\n * @param x - The new x component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 1.0.0\n */\n (x: number): (v: Vector2) => Vector2\n} = internal.setX\n\nexport const mapX: {\n /**\n * Returns a new `Vector2` with the x component replaced by `f(v.x)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the x component.\n * @returns A new `Vector2` with the updated x.\n * @since 2.0.0\n */\n (v: Vector2, f: (x: number) => number): Vector2\n /**\n * Returns a new `Vector2` with the x component replaced by `f(v.x)`.\n *\n * @param f - The function to apply to the x component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (x: number) => number): (v: Vector2) => Vector2\n} = internal.mapX\n\n/**\n * Gets the y component of a `Vector2`.\n *\n * @param v - The vector to get the y component from.\n * @returns The y component of the vector.\n * @since 1.0.0\n */\nexport const getY: (v: Vector2) => number = internal.getY\n\nexport const setY: {\n /**\n * Sets the y component of a `Vector2`.\n *\n * @param v - The vector to set the y component of.\n * @param y - The new y component.\n * @returns A new `Vector2` instance with the updated y component.\n * @since 1.0.0\n */\n (v: Vector2, y: number): Vector2\n /**\n * Sets the y component of a `Vector2`.\n *\n * @param y - The new y component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 1.0.0\n */\n (y: number): (v: Vector2) => Vector2\n} = internal.setY\n\nexport const mapY: {\n /**\n * Returns a new `Vector2` with the y component replaced by `f(v.y)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the y component.\n * @returns A new `Vector2` with the updated y.\n * @since 2.0.0\n */\n (v: Vector2, f: (y: number) => number): Vector2\n /**\n * Returns a new `Vector2` with the y component replaced by `f(v.y)`.\n *\n * @param f - The function to apply to the y component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (y: number) => number): (v: Vector2) => Vector2\n} = internal.mapY\n\n/**\n * Gets the radius of a `Vector2`.\n *\n * @param v - The vector to get the radius from.\n * @returns The radius of the vector.\n * @since 1.0.0\n */\nexport const getR: (v: Vector2) => number = magnitude\n\nexport const setR: {\n /**\n * Sets the radius of a `Vector2`.\n *\n * @param v - The vector to set the radius of.\n * @param r - The new radius.\n * @returns A new `Vector2` instance with the updated radius.\n * @since 1.0.0\n */\n (v: Vector2, r: number): Vector2\n /**\n * Sets the radius of a `Vector2`.\n *\n * @param r - The new radius.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 1.0.0\n */\n (r: number): (v: Vector2) => Vector2\n} = internal.setR\n\nexport const mapR: {\n /**\n * Returns a new `Vector2` with the radius replaced by `f(magnitude(v))`,\n * preserving the angle.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the radius.\n * @returns A new `Vector2` with the updated radius.\n * @since 2.0.0\n */\n (v: Vector2, f: (r: number) => number): Vector2\n /**\n * Returns a new `Vector2` with the radius replaced by `f(magnitude(v))`,\n * preserving the angle.\n *\n * @param f - The function to apply to the radius.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (r: number) => number): (v: Vector2) => Vector2\n} = internal.mapR\n\n/**\n * Gets the angle of a `Vector2`.\n *\n * @param v - The vector to get the angle from.\n * @returns The angle of the vector in radians.\n * @since 1.0.0\n */\nexport const getTheta: (v: Vector2) => number = internal.getTheta\n\nexport const setTheta: {\n /**\n * Sets the angle of a `Vector2`.\n *\n * @param v - The vector to set the angle of.\n * @param theta - The new angle, in radians.\n * @returns A new `Vector2` instance with the updated angle.\n * @since 1.0.0\n */\n (v: Vector2, theta: number): Vector2\n /**\n * Sets the angle of a `Vector2`.\n *\n * @param theta - The new angle, in radians.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 1.0.0\n */\n (theta: number): (v: Vector2) => Vector2\n} = internal.setTheta\n\nexport const mapTheta: {\n /**\n * Returns a new `Vector2` with the angle replaced by `f(getTheta(v))`,\n * preserving the radius.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the angle (in radians).\n * @returns A new `Vector2` with the updated angle.\n * @since 2.0.0\n */\n (v: Vector2, f: (theta: number) => number): Vector2\n /**\n * Returns a new `Vector2` with the angle replaced by `f(getTheta(v))`,\n * preserving the radius.\n *\n * @param f - The function to apply to the angle (in radians).\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (theta: number) => number): (v: Vector2) => Vector2\n} = internal.mapTheta\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAa,YAA0CA;;;;;;;;AASvD,MAAa,aAA4CC;;;;;;;;;;;AAYzD,MAAa,eACXC;AAEF,MAAa,aAoBTC;;;;;;;;AASJ,MAAa,aAAuCC;AAEpD,MAAa,iBAmBTC;AAEJ,MAAa,SAoBTC;AAEJ,MAAa,OAkBTC;;;;;;;;;AAUJ,MAAa,YAAuDC;;;;;;;;;;;AAYpE,MAAa,YAGsCC;;;;;;;;;AAUnD,MAAa,YAAmDC;;;;;;;;AAShE,MAAa,YAAyCC;;;;;;;;AAStD,MAAa,YAA0CC;AAEvD,MAAa,MAkBTC;AAEJ,MAAa,QAkBTC;;;;;;;;;AAUJ,MAAa,aAA+CC;;;;;;;;AAS5D,MAAa,UAAmCC;;;;;;;AAQhD,MAAa,OAAO,KAAK,EAAE;;;;;;;AAQ3B,MAAa,OAAO,KAAK,EAAE;AAE3B,MAAa,MAkBTC;AAEJ,MAAa,WAkBTC;AAEJ,MAAa,WAkBTC;AAEJ,MAAa,QAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+B;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAoBTC;;;;;;;;AASJ,MAAa,WAAmCC;AAEhD,MAAa,WAkBTC;AAEJ,MAAa,WAoBTC"}
|
|
@@ -108,19 +108,34 @@ const getX = (v) => v.x;
|
|
|
108
108
|
/** @internal */
|
|
109
109
|
const setX = dual(2, (v, x) => make(x, v.y));
|
|
110
110
|
/** @internal */
|
|
111
|
+
const mapX = dual(2, (v, f) => make(f(v.x), v.y));
|
|
112
|
+
/** @internal */
|
|
111
113
|
const getY = (v) => v.y;
|
|
112
114
|
/** @internal */
|
|
113
115
|
const setY = dual(2, (v, y) => make(v.x, y));
|
|
114
116
|
/** @internal */
|
|
117
|
+
const mapY = dual(2, (v, f) => make(v.x, f(v.y)));
|
|
118
|
+
/** @internal */
|
|
115
119
|
const setR = dual(2, (v, r) => scale(r / magnitude(v))(v));
|
|
116
120
|
/** @internal */
|
|
121
|
+
const mapR = dual(2, (v, f) => {
|
|
122
|
+
const r = magnitude(v);
|
|
123
|
+
return scale(f(r) / r)(v);
|
|
124
|
+
});
|
|
125
|
+
/** @internal */
|
|
117
126
|
const getTheta = (v) => Math.atan2(v.y, v.x);
|
|
118
127
|
/** @internal */
|
|
119
128
|
const setTheta = dual(2, (v, theta) => {
|
|
120
129
|
const r = magnitude(v);
|
|
121
130
|
return make(r * Math.cos(theta), r * Math.sin(theta));
|
|
122
131
|
});
|
|
132
|
+
/** @internal */
|
|
133
|
+
const mapTheta = dual(2, (v, f) => {
|
|
134
|
+
const r = magnitude(v);
|
|
135
|
+
const theta = f(Math.atan2(v.y, v.x));
|
|
136
|
+
return make(r * Math.cos(theta), r * Math.sin(theta));
|
|
137
|
+
});
|
|
123
138
|
//#endregion
|
|
124
|
-
export {
|
|
139
|
+
export { unweighted as A, setR as C, softmax as D, setY as E, withWeight as M, subtract as O, scale as S, setX as T, mapR as _, equals as a, mapY as b, getTheta as c, hadamard as d, isVector2 as f, makeWeighted as g, make as h, dot as i, weightedEquals as j, transpose as k, getX as l, magnitude as m, components as n, fromPolar as o, isWeighted as p, cross as r, fromTuple as s, add as t, getY as u, mapTheta as v, setTheta as w, normalize as x, mapX as y };
|
|
125
140
|
|
|
126
|
-
//# sourceMappingURL=vector2.internal-
|
|
141
|
+
//# sourceMappingURL=vector2.internal-DP1nTBdS.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector2.internal-BL8hFl1c.mjs","names":[],"sources":["../../src/vector/vector2.internal.ts"],"sourcesContent":["import { dual, Pipeable } from '../utils.ts'\nimport { invariant } from '../utils.ts'\nimport { epsEquals } from '../number.ts'\nimport type { Vector2, Weighted } from './vector2.ts'\n\nexport const Vector2TypeId = Symbol.for('curvy/vector2')\nexport type Vector2TypeId = typeof Vector2TypeId\n\nexport const WeightedVector2TypeId = Symbol.for('curvy/vector2/weighted')\nexport type WeightedVector2TypeId = typeof WeightedVector2TypeId\n\nclass Vector2Impl extends Pipeable implements Vector2 {\n readonly [Vector2TypeId]: Vector2TypeId = Vector2TypeId\n\n readonly x: number\n readonly y: number\n\n constructor(v0 = 0, v1 = 0) {\n super()\n this.x = v0\n this.y = v1\n }\n\n get [0]() {\n return this.x\n }\n\n get [1]() {\n return this.y\n }\n\n get [Symbol.toStringTag]() {\n return `Vector2(${this.x}, ${this.y})`\n }\n\n get [Symbol.for('nodejs.util.inspect.custom')]() {\n return this[Symbol.toStringTag]\n }\n}\n\nclass WeightedImpl extends Pipeable implements Weighted {\n readonly [WeightedVector2TypeId]: WeightedVector2TypeId = WeightedVector2TypeId\n\n readonly x: number\n readonly y: number\n readonly weight: number\n\n constructor(x: number, y: number, weight: number) {\n super()\n this.x = x\n this.y = y\n this.weight = weight\n }\n\n get [Symbol.toStringTag]() {\n return `Vector2.Weighted(${this.x}, ${this.y}, w=${this.weight})`\n }\n\n get [Symbol.for('nodejs.util.inspect.custom')]() {\n return this[Symbol.toStringTag]\n }\n}\n\n/** @internal */\nexport const isVector2 = (v: unknown): v is Vector2 =>\n typeof v === 'object' && v !== null && Vector2TypeId in v\n\n/** @internal */\nexport const isWeighted = (v: unknown): v is Weighted =>\n typeof v === 'object' && v !== null && WeightedVector2TypeId in v\n\n/** @internal */\nexport const equals = dual<\n (b: Vector2) => (a: Vector2) => boolean,\n (a: Vector2, b: Vector2) => boolean\n>(2, (a: Vector2, b: Vector2) => epsEquals(a.x, b.x) && epsEquals(a.y, b.y))\n\n/** @internal */\nexport const make = (v0: number, v1 = v0): Vector2 => new Vector2Impl(v0, v1)\n\n/** @internal */\nexport const fromTuple = (t: readonly [number, number]): Vector2 => new Vector2Impl(t[0], t[1])\n\n/** @internal */\nexport const transpose = <T, const Channels extends ReadonlyArray<number>>(\n inputs: readonly [T, T],\n project: (item: T) => Channels,\n): { readonly [K in keyof Channels]: Vector2 } => {\n const a = project(inputs[0])\n const b = project(inputs[1])\n const result: Array<Vector2> = []\n for (let i = 0; i < a.length; i++) {\n result.push(make(a[i] as number, b[i] as number))\n }\n return result as never\n}\n\n/** @internal */\nexport const makeWeighted = (x: number, y: number, weight: number): Weighted => {\n invariant(\n Number.isFinite(weight) && weight > 0,\n 'Vector2.Weighted weight must be positive and finite',\n )\n return new WeightedImpl(x, y, weight)\n}\n\n/** @internal */\nexport const withWeight = dual<\n (weight: number) => (v: Vector2) => Weighted,\n (v: Vector2, weight: number) => Weighted\n>(2, (v: Vector2, weight: number) => makeWeighted(v.x, v.y, weight))\n\n/** @internal */\nexport const unweighted = (w: Weighted): Vector2 => make(w.x, w.y)\n\n/** @internal */\nexport const weightedEquals = dual<\n (b: Weighted) => (a: Weighted) => boolean,\n (a: Weighted, b: Weighted) => boolean\n>(\n 2,\n (a: Weighted, b: Weighted) =>\n epsEquals(a.x, b.x) && epsEquals(a.y, b.y) && epsEquals(a.weight, b.weight),\n)\n\n/** @internal */\nexport const fromPolar = (r: number, theta: number) =>\n make(r * Math.cos(theta), r * Math.sin(theta))\n\n/** @internal */\nexport const components = (v: Vector2): [number, number] => [v.x, v.y]\n\n/** @internal */\nexport const magnitude = (vector: Vector2) => Math.hypot(vector.x, vector.y)\n\n/** @internal */\nexport const normalize = (vector: Vector2) => {\n const m = magnitude(vector)\n\n return make(vector.x / m, vector.y / m)\n}\n\n/** @internal */\nexport const dot = dual<(b: Vector2) => (a: Vector2) => number, (a: Vector2, b: Vector2) => number>(\n 2,\n (a: Vector2, b: Vector2) => a.x * b.x + a.y * b.y,\n)\n\n/** @internal */\nexport const cross = dual<\n (b: Vector2) => (a: Vector2) => number,\n (a: Vector2, b: Vector2) => number\n>(2, (a: Vector2, b: Vector2) => a.x * b.y - a.y * b.x)\n\n/** @internal */\nexport const softmax = (v: Vector2) => {\n const max = Math.max(v.x, v.y)\n\n const v0 = Math.exp(v.x - max)\n const v1 = Math.exp(v.y - max)\n\n const sum = v0 + v1\n\n return make(v0 / sum, v1 / sum)\n}\n\n/** @internal */\nexport const add = dual<\n (b: Vector2) => (a: Vector2) => Vector2,\n (a: Vector2, b: Vector2) => Vector2\n>(2, (a: Vector2, b: Vector2) => make(a.x + b.x, a.y + b.y))\n\n/** @internal */\nexport const subtract = dual<\n (b: Vector2) => (a: Vector2) => Vector2,\n (a: Vector2, b: Vector2) => Vector2\n>(2, (a: Vector2, b: Vector2) => make(a.x - b.x, a.y - b.y))\n\n/** @internal */\nexport const hadamard = dual<\n (b: Vector2) => (a: Vector2) => Vector2,\n (a: Vector2, b: Vector2) => Vector2\n>(2, (a: Vector2, b: Vector2) => make(a.x * b.x, a.y * b.y))\n\n/** @internal */\nexport const scale = dual<\n (s: number) => (v: Vector2) => Vector2,\n (v: Vector2, s: number) => Vector2\n>(2, (v: Vector2, s: number) => (s === 1 ? v : make(v.x * s, v.y * s)))\n\n/** @internal */\nexport const getX = (v: Vector2) => v.x\n/** @internal */\nexport const setX = dual<\n (x: number) => (v: Vector2) => Vector2,\n (v: Vector2, x: number) => Vector2\n>(2, (v: Vector2, x: number) => make(x, v.y))\n\n/** @internal */\nexport const getY = (v: Vector2) => v.y\n/** @internal */\nexport const setY = dual<\n (y: number) => (v: Vector2) => Vector2,\n (v: Vector2, y: number) => Vector2\n>(2, (v: Vector2, y: number) => make(v.x, y))\n\n/** @internal */\nexport const setR = dual<\n (r: number) => (v: Vector2) => Vector2,\n (v: Vector2, r: number) => Vector2\n>(2, (v: Vector2, r: number) => scale(r / magnitude(v))(v))\n\n/** @internal */\nexport const getTheta = (v: Vector2) => Math.atan2(v.y, v.x)\n/** @internal */\nexport const setTheta = dual<\n (theta: number) => (v: Vector2) => Vector2,\n (v: Vector2, theta: number) => Vector2\n>(2, (v: Vector2, theta: number) => {\n const r = magnitude(v)\n return make(r * Math.cos(theta), r * Math.sin(theta))\n})\n"],"mappings":";;;AAKA,MAAa,gBAAgB,OAAO,IAAI,gBAAgB;AAGxD,MAAa,wBAAwB,OAAO,IAAI,yBAAyB;AAGzE,IAAM,cAAN,cAA0B,SAA4B;CACpD,CAAU,iBAAgC;CAE1C;CACA;CAEA,YAAY,KAAK,GAAG,KAAK,GAAG;EAC1B,OAAO;EACP,KAAK,IAAI;EACT,KAAK,IAAI;;CAGX,KAAK,KAAK;EACR,OAAO,KAAK;;CAGd,KAAK,KAAK;EACR,OAAO,KAAK;;CAGd,KAAK,OAAO,eAAe;EACzB,OAAO,WAAW,KAAK,EAAE,IAAI,KAAK,EAAE;;CAGtC,KAAK,OAAO,IAAI,6BAA6B,IAAI;EAC/C,OAAO,KAAK,OAAO;;;AAIvB,IAAM,eAAN,cAA2B,SAA6B;CACtD,CAAU,yBAAgD;CAE1D;CACA;CACA;CAEA,YAAY,GAAW,GAAW,QAAgB;EAChD,OAAO;EACP,KAAK,IAAI;EACT,KAAK,IAAI;EACT,KAAK,SAAS;;CAGhB,KAAK,OAAO,eAAe;EACzB,OAAO,oBAAoB,KAAK,EAAE,IAAI,KAAK,EAAE,MAAM,KAAK,OAAO;;CAGjE,KAAK,OAAO,IAAI,6BAA6B,IAAI;EAC/C,OAAO,KAAK,OAAO;;;;AAKvB,MAAa,aAAa,MACxB,OAAO,MAAM,YAAY,MAAM,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lB,IAAI,GAAY,MAAc,MAAM,IAAI,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC;;AAG3D,MAAa,YAAY,MAAe,KAAK,MAAM,EAAE,GAAG,EAAE,EAAE;;AAE5D,MAAa,WAAW,KAGtB,IAAI,GAAY,UAAkB;CAClC,MAAM,IAAI,UAAU,EAAE;CACtB,OAAO,KAAK,IAAI,KAAK,IAAI,MAAM,EAAE,IAAI,KAAK,IAAI,MAAM,CAAC;EACrD"}
|
|
1
|
+
{"version":3,"file":"vector2.internal-DP1nTBdS.mjs","names":[],"sources":["../../src/vector/vector2.internal.ts"],"sourcesContent":["import { dual, Pipeable } from '../utils.ts'\nimport { invariant } from '../utils.ts'\nimport { epsEquals } from '../number.ts'\nimport type { Vector2, Weighted } from './vector2.ts'\n\nexport const Vector2TypeId = Symbol.for('curvy/vector2')\nexport type Vector2TypeId = typeof Vector2TypeId\n\nexport const WeightedVector2TypeId = Symbol.for('curvy/vector2/weighted')\nexport type WeightedVector2TypeId = typeof WeightedVector2TypeId\n\nclass Vector2Impl extends Pipeable implements Vector2 {\n readonly [Vector2TypeId]: Vector2TypeId = Vector2TypeId\n\n readonly x: number\n readonly y: number\n\n constructor(v0 = 0, v1 = 0) {\n super()\n this.x = v0\n this.y = v1\n }\n\n get [0]() {\n return this.x\n }\n\n get [1]() {\n return this.y\n }\n\n get [Symbol.toStringTag]() {\n return `Vector2(${this.x}, ${this.y})`\n }\n\n get [Symbol.for('nodejs.util.inspect.custom')]() {\n return this[Symbol.toStringTag]\n }\n}\n\nclass WeightedImpl extends Pipeable implements Weighted {\n readonly [WeightedVector2TypeId]: WeightedVector2TypeId = WeightedVector2TypeId\n\n readonly x: number\n readonly y: number\n readonly weight: number\n\n constructor(x: number, y: number, weight: number) {\n super()\n this.x = x\n this.y = y\n this.weight = weight\n }\n\n get [Symbol.toStringTag]() {\n return `Vector2.Weighted(${this.x}, ${this.y}, w=${this.weight})`\n }\n\n get [Symbol.for('nodejs.util.inspect.custom')]() {\n return this[Symbol.toStringTag]\n }\n}\n\n/** @internal */\nexport const isVector2 = (v: unknown): v is Vector2 =>\n typeof v === 'object' && v !== null && Vector2TypeId in v\n\n/** @internal */\nexport const isWeighted = (v: unknown): v is Weighted =>\n typeof v === 'object' && v !== null && WeightedVector2TypeId in v\n\n/** @internal */\nexport const equals = dual<\n (b: Vector2) => (a: Vector2) => boolean,\n (a: Vector2, b: Vector2) => boolean\n>(2, (a: Vector2, b: Vector2) => epsEquals(a.x, b.x) && epsEquals(a.y, b.y))\n\n/** @internal */\nexport const make = (v0: number, v1 = v0): Vector2 => new Vector2Impl(v0, v1)\n\n/** @internal */\nexport const fromTuple = (t: readonly [number, number]): Vector2 => new Vector2Impl(t[0], t[1])\n\n/** @internal */\nexport const transpose = <T, const Channels extends ReadonlyArray<number>>(\n inputs: readonly [T, T],\n project: (item: T) => Channels,\n): { readonly [K in keyof Channels]: Vector2 } => {\n const a = project(inputs[0])\n const b = project(inputs[1])\n const result: Array<Vector2> = []\n for (let i = 0; i < a.length; i++) {\n result.push(make(a[i] as number, b[i] as number))\n }\n return result as never\n}\n\n/** @internal */\nexport const makeWeighted = (x: number, y: number, weight: number): Weighted => {\n invariant(\n Number.isFinite(weight) && weight > 0,\n 'Vector2.Weighted weight must be positive and finite',\n )\n return new WeightedImpl(x, y, weight)\n}\n\n/** @internal */\nexport const withWeight = dual<\n (weight: number) => (v: Vector2) => Weighted,\n (v: Vector2, weight: number) => Weighted\n>(2, (v: Vector2, weight: number) => makeWeighted(v.x, v.y, weight))\n\n/** @internal */\nexport const unweighted = (w: Weighted): Vector2 => make(w.x, w.y)\n\n/** @internal */\nexport const weightedEquals = dual<\n (b: Weighted) => (a: Weighted) => boolean,\n (a: Weighted, b: Weighted) => boolean\n>(\n 2,\n (a: Weighted, b: Weighted) =>\n epsEquals(a.x, b.x) && epsEquals(a.y, b.y) && epsEquals(a.weight, b.weight),\n)\n\n/** @internal */\nexport const fromPolar = (r: number, theta: number) =>\n make(r * Math.cos(theta), r * Math.sin(theta))\n\n/** @internal */\nexport const components = (v: Vector2): [number, number] => [v.x, v.y]\n\n/** @internal */\nexport const magnitude = (vector: Vector2) => Math.hypot(vector.x, vector.y)\n\n/** @internal */\nexport const normalize = (vector: Vector2) => {\n const m = magnitude(vector)\n\n return make(vector.x / m, vector.y / m)\n}\n\n/** @internal */\nexport const dot = dual<(b: Vector2) => (a: Vector2) => number, (a: Vector2, b: Vector2) => number>(\n 2,\n (a: Vector2, b: Vector2) => a.x * b.x + a.y * b.y,\n)\n\n/** @internal */\nexport const cross = dual<\n (b: Vector2) => (a: Vector2) => number,\n (a: Vector2, b: Vector2) => number\n>(2, (a: Vector2, b: Vector2) => a.x * b.y - a.y * b.x)\n\n/** @internal */\nexport const softmax = (v: Vector2) => {\n const max = Math.max(v.x, v.y)\n\n const v0 = Math.exp(v.x - max)\n const v1 = Math.exp(v.y - max)\n\n const sum = v0 + v1\n\n return make(v0 / sum, v1 / sum)\n}\n\n/** @internal */\nexport const add = dual<\n (b: Vector2) => (a: Vector2) => Vector2,\n (a: Vector2, b: Vector2) => Vector2\n>(2, (a: Vector2, b: Vector2) => make(a.x + b.x, a.y + b.y))\n\n/** @internal */\nexport const subtract = dual<\n (b: Vector2) => (a: Vector2) => Vector2,\n (a: Vector2, b: Vector2) => Vector2\n>(2, (a: Vector2, b: Vector2) => make(a.x - b.x, a.y - b.y))\n\n/** @internal */\nexport const hadamard = dual<\n (b: Vector2) => (a: Vector2) => Vector2,\n (a: Vector2, b: Vector2) => Vector2\n>(2, (a: Vector2, b: Vector2) => make(a.x * b.x, a.y * b.y))\n\n/** @internal */\nexport const scale = dual<\n (s: number) => (v: Vector2) => Vector2,\n (v: Vector2, s: number) => Vector2\n>(2, (v: Vector2, s: number) => (s === 1 ? v : make(v.x * s, v.y * s)))\n\n/** @internal */\nexport const getX = (v: Vector2) => v.x\n/** @internal */\nexport const setX = dual<\n (x: number) => (v: Vector2) => Vector2,\n (v: Vector2, x: number) => Vector2\n>(2, (v: Vector2, x: number) => make(x, v.y))\n\n/** @internal */\nexport const mapX = dual<\n (f: (x: number) => number) => (v: Vector2) => Vector2,\n (v: Vector2, f: (x: number) => number) => Vector2\n>(2, (v: Vector2, f: (x: number) => number) => make(f(v.x), v.y))\n\n/** @internal */\nexport const getY = (v: Vector2) => v.y\n/** @internal */\nexport const setY = dual<\n (y: number) => (v: Vector2) => Vector2,\n (v: Vector2, y: number) => Vector2\n>(2, (v: Vector2, y: number) => make(v.x, y))\n\n/** @internal */\nexport const mapY = dual<\n (f: (y: number) => number) => (v: Vector2) => Vector2,\n (v: Vector2, f: (y: number) => number) => Vector2\n>(2, (v: Vector2, f: (y: number) => number) => make(v.x, f(v.y)))\n\n/** @internal */\nexport const setR = dual<\n (r: number) => (v: Vector2) => Vector2,\n (v: Vector2, r: number) => Vector2\n>(2, (v: Vector2, r: number) => scale(r / magnitude(v))(v))\n\n/** @internal */\nexport const mapR = dual<\n (f: (r: number) => number) => (v: Vector2) => Vector2,\n (v: Vector2, f: (r: number) => number) => Vector2\n>(2, (v: Vector2, f: (r: number) => number) => {\n const r = magnitude(v)\n return scale(f(r) / r)(v)\n})\n\n/** @internal */\nexport const getTheta = (v: Vector2) => Math.atan2(v.y, v.x)\n/** @internal */\nexport const setTheta = dual<\n (theta: number) => (v: Vector2) => Vector2,\n (v: Vector2, theta: number) => Vector2\n>(2, (v: Vector2, theta: number) => {\n const r = magnitude(v)\n return make(r * Math.cos(theta), r * Math.sin(theta))\n})\n\n/** @internal */\nexport const mapTheta = dual<\n (f: (theta: number) => number) => (v: Vector2) => Vector2,\n (v: Vector2, f: (theta: number) => number) => Vector2\n>(2, (v: Vector2, f: (theta: number) => number) => {\n const r = magnitude(v)\n const theta = f(Math.atan2(v.y, v.x))\n return make(r * Math.cos(theta), r * Math.sin(theta))\n})\n"],"mappings":";;;AAKA,MAAa,gBAAgB,OAAO,IAAI,gBAAgB;AAGxD,MAAa,wBAAwB,OAAO,IAAI,yBAAyB;AAGzE,IAAM,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kB;CAClC,MAAM,IAAI,UAAU,EAAE;CACtB,OAAO,KAAK,IAAI,KAAK,IAAI,MAAM,EAAE,IAAI,KAAK,IAAI,MAAM,CAAC;EACrD;;AAGF,MAAa,WAAW,KAGtB,IAAI,GAAY,MAAiC;CACjD,MAAM,IAAI,UAAU,EAAE;CACtB,MAAM,QAAQ,EAAE,KAAK,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC;CACrC,OAAO,KAAK,IAAI,KAAK,IAAI,MAAM,EAAE,IAAI,KAAK,IAAI,MAAM,CAAC;EACrD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-25Hzd3z8.mjs";
|
|
2
|
-
import { A as
|
|
2
|
+
import { $ as setTheta$1, A as dot$1, B as isVector3$1, D as add$1, F as getTheta$1, G as mapTheta$1, H as make$1, I as getX$1, J as mapZ$1, K as mapX$1, L as getY$1, M as fromSpherical$1, N as fromTuple$1, O as components$1, P as getPhi$1, Q as setR$1, R as getZ$1, U as mapPhi$1, V as magnitude$1, W as mapR$1, X as scale$1, Y as normalize$1, Z as setPhi$1, at as transpose$1, et as setX$1, it as subtract$1, j as equals$1, k as cross$1, nt as setZ$1, q as mapY$1, rt as softmax$1, tt as setY$1, z as hadamard$1 } from "./vector4.internal-BJ1QN2Ck.mjs";
|
|
3
3
|
//#region src/vector/vector3.ts
|
|
4
4
|
var vector3_exports = /* @__PURE__ */ __exportAll({
|
|
5
5
|
add: () => add,
|
|
@@ -20,6 +20,12 @@ var vector3_exports = /* @__PURE__ */ __exportAll({
|
|
|
20
20
|
length: () => length,
|
|
21
21
|
magnitude: () => magnitude,
|
|
22
22
|
make: () => make,
|
|
23
|
+
mapPhi: () => mapPhi,
|
|
24
|
+
mapR: () => mapR,
|
|
25
|
+
mapTheta: () => mapTheta,
|
|
26
|
+
mapX: () => mapX,
|
|
27
|
+
mapY: () => mapY,
|
|
28
|
+
mapZ: () => mapZ,
|
|
23
29
|
normalize: () => normalize,
|
|
24
30
|
scale: () => scale,
|
|
25
31
|
setPhi: () => setPhi,
|
|
@@ -163,6 +169,7 @@ const scale = scale$1;
|
|
|
163
169
|
*/
|
|
164
170
|
const getX = getX$1;
|
|
165
171
|
const setX = setX$1;
|
|
172
|
+
const mapX = mapX$1;
|
|
166
173
|
/**
|
|
167
174
|
* Gets the y component of a `Vector3`.
|
|
168
175
|
*
|
|
@@ -172,6 +179,7 @@ const setX = setX$1;
|
|
|
172
179
|
*/
|
|
173
180
|
const getY = getY$1;
|
|
174
181
|
const setY = setY$1;
|
|
182
|
+
const mapY = mapY$1;
|
|
175
183
|
/**
|
|
176
184
|
* Gets the z component of a `Vector3`.
|
|
177
185
|
*
|
|
@@ -181,6 +189,7 @@ const setY = setY$1;
|
|
|
181
189
|
*/
|
|
182
190
|
const getZ = getZ$1;
|
|
183
191
|
const setZ = setZ$1;
|
|
192
|
+
const mapZ = mapZ$1;
|
|
184
193
|
/**
|
|
185
194
|
* Gets the radius of a `Vector3`.
|
|
186
195
|
*
|
|
@@ -190,6 +199,7 @@ const setZ = setZ$1;
|
|
|
190
199
|
*/
|
|
191
200
|
const getR = magnitude;
|
|
192
201
|
const setR = setR$1;
|
|
202
|
+
const mapR = mapR$1;
|
|
193
203
|
/**
|
|
194
204
|
* Gets the polar angle (theta) of a `Vector3`.
|
|
195
205
|
*
|
|
@@ -199,6 +209,7 @@ const setR = setR$1;
|
|
|
199
209
|
*/
|
|
200
210
|
const getTheta = getTheta$1;
|
|
201
211
|
const setTheta = setTheta$1;
|
|
212
|
+
const mapTheta = mapTheta$1;
|
|
202
213
|
/**
|
|
203
214
|
* Gets the azimuthal angle (phi) of a `Vector3`.
|
|
204
215
|
*
|
|
@@ -208,7 +219,8 @@ const setTheta = setTheta$1;
|
|
|
208
219
|
*/
|
|
209
220
|
const getPhi = getPhi$1;
|
|
210
221
|
const setPhi = setPhi$1;
|
|
222
|
+
const mapPhi = mapPhi$1;
|
|
211
223
|
//#endregion
|
|
212
224
|
export { vector3_exports as n, make as t };
|
|
213
225
|
|
|
214
|
-
//# sourceMappingURL=vector3-
|
|
226
|
+
//# sourceMappingURL=vector3-CR2LPV03.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector3-CR2LPV03.mjs","names":["internal.isVector3","internal.equals","internal.make","internal.fromTuple","internal.transpose","internal.fromSpherical","internal.magnitude","internal.normalize","internal.dot","internal.cross","internal.components","internal.softmax","internal.add","internal.subtract","internal.hadamard","internal.scale","internal.getX","internal.setX","internal.mapX","internal.getY","internal.setY","internal.mapY","internal.getZ","internal.setZ","internal.mapZ","internal.setR","internal.mapR","internal.getTheta","internal.setTheta","internal.mapTheta","internal.getPhi","internal.setPhi","internal.mapPhi"],"sources":["../../src/vector/vector3.ts"],"sourcesContent":["import type { ThreeDimensional } from '../dimensions.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector3TypeId } from './vector3.internal.ts'\nimport * as internal from './vector3.internal.ts'\n\n/**\n * A 3D vector.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 1.0.0\n */\nexport interface Vector3 extends Pipeable, ThreeDimensional<number> {\n readonly [Vector3TypeId]: Vector3TypeId\n}\n\n/**\n * Checks if a value is a `Vector3`.\n *\n * @param v - The value to check.\n * @returns `true` if the value is a `Vector3`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isVector3: (v: unknown) => v is Vector3 = internal.isVector3\n\nexport const equals: {\n /**\n * Checks if two `Vector3` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns `true` when each pair of components is within tolerance.\n * @since 1.1.0\n */\n (a: Vector3, b: Vector3): boolean\n /**\n * Checks if two `Vector3` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the comparison result.\n * @since 1.1.0\n */\n (b: Vector3): (a: Vector3) => boolean\n} = internal.equals\n\nexport const make: {\n /**\n * Creates a new `Vector3` instance.\n *\n * @param xyz - The x, y, and z components of the vector.\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\n (xyz: number): Vector3\n /**\n * Creates a new `Vector3` instance.\n *\n * @param x - The x component of the vector.\n * @param yz - The y and z components of the vector.\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\n (x: number, yz: number): Vector3\n /**\n * Creates a new `Vector3` instance.\n *\n * @param x - The x component of the vector.\n * @param y - The y component of the vector.\n * @param z - The z component of the vector.\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\n (x: number, y: number, z: number): Vector3\n} = internal.make\n\n/**\n * Creates a new `Vector3` instance from a `[x, y, z]` tuple. Inverse of\n * {@link components}.\n *\n * @param t - The `[x, y, z]` tuple.\n * @returns A new `Vector3` instance.\n * @since 2.0.0\n */\nexport const fromTuple: (t: readonly [number, number, number]) => Vector3 = internal.fromTuple\n\n/**\n * Transposes a 3-tuple of items into one or more `Vector3`s, one per channel\n * extracted by the projection function. See {@link Vector4.transpose} for the\n * full operation description; this is the 3-component analog.\n *\n * @param inputs - Exactly three items of any type.\n * @param project - A function returning a fixed-arity tuple of numbers — one per output channel.\n * @returns A tuple of `Vector3`s with the same arity as the projection's return tuple.\n * @since 2.0.0\n */\nexport const transpose: <T, const Channels extends ReadonlyArray<number>>(\n inputs: readonly [T, T, T],\n project: (item: T) => Channels,\n) => { readonly [K in keyof Channels]: Vector3 } = internal.transpose\n\n/**\n * Creates a new `Vector3` instance from spherical coordinates.\n *\n * @param r - The radius.\n * @param theta - The polar angle, in radians. Ranges from 0 to π\n * @param phi - The azimuthal angle, in radians. Ranges from 0 to 2π\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\nexport const fromSpherical: (r: number, theta: number, phi: number) => Vector3 =\n internal.fromSpherical\n\n/**\n * Calculates the magnitude of a `Vector3`.\n *\n * @param vector - The vector to calculate the magnitude of.\n * @returns The magnitude of the vector.\n * @since 1.0.0\n */\nexport const magnitude: (vector: Vector3) => number = internal.magnitude\n\n/**\n * Calculates the length of a `Vector3`.\n *\n * @param vector - The vector to calculate the length of.\n * @returns The length of the vector.\n * @see {@link magnitude}\n * @since 1.0.0\n */\nexport const length: (vector: Vector3) => number = magnitude\n\n/**\n * Normalizes a `Vector3`.\n *\n * @param vector - The vector to normalize.\n * @returns A new `Vector3` instance with the same direction as the input vector, but with a magnitude of 1.\n * @since 1.0.0\n */\nexport const normalize: (vector: Vector3) => Vector3 = internal.normalize\n\nexport const dot: {\n /**\n * Calculates the dot product of two `Vector3` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns The dot product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): number\n /**\n * Calculates the dot product of two `Vector3` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the dot product.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => number\n} = internal.dot\n\nexport const cross: {\n /**\n * Calculates the cross product of two `Vector3` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector3` instance representing the cross product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Calculates the cross product of two `Vector3` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the cross product.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.cross\n\n/**\n * Returns the components of a `Vector3` as an array.\n *\n * @param v - The vector to get the components of.\n * @returns An array containing the x, y, and z components of the vector.\n * @since 1.0.0\n */\nexport const components: (v: Vector3) => [number, number, number] = internal.components\n\n/**\n * Calculates the softmax of a `Vector3`.\n *\n * @param v - The vector to calculate the softmax of.\n * @returns A new `Vector3` instance representing the softmax of the input vector.\n * @since 1.0.0\n */\nexport const softmax: (v: Vector3) => Vector3 = internal.softmax\n\n/**\n * Creates a zero vector.\n *\n * @since 1.0.0\n */\nexport const zero = make(0)\n\n/**\n * Creates a unit vector.\n *\n * @since 1.0.0\n */\nexport const unit = make(1)\n\n/**\n * Creates a unit vector in the x direction.\n *\n * @since 1.0.0\n */\nexport const unitX = make(1, 0, 0)\n\n/**\n * Creates a unit vector in the y direction.\n *\n * @since 1.0.0\n */\nexport const unitY = make(0, 1, 0)\n\n/**\n * Creates a unit vector in the z direction.\n *\n * @since 1.0.0\n */\nexport const unitZ = make(0, 0, 1)\n\nexport const add: {\n /**\n * Adds two `Vector3` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector3` instance representing the sum of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Adds two `Vector3` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the sum.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.add\n\nexport const subtract: {\n /**\n * Subtracts one `Vector3` instance from another.\n *\n * @param a - The vector to subtract from.\n * @param b - The vector to subtract.\n * @returns A new `Vector3` instance representing the difference of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Subtracts one `Vector3` instance from another.\n *\n * @param b - The vector to subtract.\n * @returns A function that takes the first vector and returns the difference.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.subtract\n\nexport const hadamard: {\n /**\n * Calculates the Hadamard product of two `Vector3` instances.\n *\n * The Hadamard product is an element-wise multiplication of two vectors.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector3` instance representing the Hadamard product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Calculates the Hadamard product of two `Vector3` instances.\n *\n * The Hadamard product is an element-wise multiplication of two vectors.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the Hadamard product.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.hadamard\n\nexport const scale: {\n /**\n * Scales a `Vector3` instance by a scalar value.\n *\n * @param s - The scalar value to scale by.\n * @return A function that takes a vector and returns the scaled vector.\n * @since 1.0.0\n */\n (s: number): (v: Vector3) => Vector3\n /**\n * Scales a `Vector3` instance by a scalar value.\n *\n * @param s - The scalar value to scale by.\n * @param v - The vector to scale.\n * @returns A new `Vector3` instance representing the scaled vector.\n * @since 1.0.0\n */\n (v: Vector3, s: number): Vector3\n} = internal.scale\n\n/**\n * Gets the x component of a `Vector3`.\n *\n * @param v - The vector to get the x component of.\n * @returns The x component of the vector.\n * @since 1.0.0\n */\nexport const getX: (v: Vector3) => number = internal.getX\n\nexport const setX: {\n /**\n * Sets the x component of a `Vector3`.\n *\n * @param v - The vector to set the x component of.\n * @param x - The new x component.\n * @returns A new `Vector3` instance with the updated x component.\n * @since 1.0.0\n */\n (v: Vector3, x: number): Vector3\n /**\n * Sets the x component of a `Vector3`.\n *\n * @param x - The new x component.\n * @returns A function that takes the vector and returns a new `Vector3` instance with the updated x component.\n * @since 1.0.0\n */\n (x: number): (v: Vector3) => Vector3\n} = internal.setX\n\nexport const mapX: {\n /**\n * Returns a new `Vector3` with the x component replaced by `f(v.x)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the x component.\n * @returns A new `Vector3` with the updated x.\n * @since 2.0.0\n */\n (v: Vector3, f: (x: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the x component replaced by `f(v.x)`.\n *\n * @param f - The function to apply to the x component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (x: number) => number): (v: Vector3) => Vector3\n} = internal.mapX\n\n/**\n * Gets the y component of a `Vector3`.\n *\n * @param v - The vector of which to get the y component.\n * @returns The y component of the vector.\n * @since 1.0.0\n */\nexport const getY: (v: Vector3) => number = internal.getY\n\nexport const setY: {\n /**\n * Sets the y component of a `Vector3`.\n *\n * @param v - The vector of which to set the y component.\n * @param y - The new y component.\n * @returns A new `Vector3` instance with the updated y component.\n * @since 1.0.0\n */\n (v: Vector3, y: number): Vector3\n /**\n * Sets the y component of a `Vector3`.\n *\n * @param y - The new y component.\n * @returns A function that takes the vector and returns a new `Vector3` instance with the updated y component.\n * @since 1.0.0\n */\n (y: number): (v: Vector3) => Vector3\n} = internal.setY\n\nexport const mapY: {\n /**\n * Returns a new `Vector3` with the y component replaced by `f(v.y)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the y component.\n * @returns A new `Vector3` with the updated y.\n * @since 2.0.0\n */\n (v: Vector3, f: (y: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the y component replaced by `f(v.y)`.\n *\n * @param f - The function to apply to the y component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (y: number) => number): (v: Vector3) => Vector3\n} = internal.mapY\n\n/**\n * Gets the z component of a `Vector3`.\n *\n * @param v - The vector of which to get the z component.\n * @returns The z component of the vector.\n * @since 1.0.0\n */\nexport const getZ: (v: Vector3) => number = internal.getZ\n\nexport const setZ: {\n /**\n * Sets the z component of a `Vector3`.\n *\n * @param v - The vector of which to set the z component.\n * @param z - The new z component.\n * @returns A new `Vector3` instance with the updated z component.\n * @since 1.0.0\n */\n (v: Vector3, z: number): Vector3\n /**\n * Sets the z component of a `Vector3`.\n *\n * @param z - The new z component.\n * @returns A function that takes the vector and returns a new `Vector3` instance with the updated z component.\n * @since 1.0.0\n */\n (z: number): (v: Vector3) => Vector3\n} = internal.setZ\n\nexport const mapZ: {\n /**\n * Returns a new `Vector3` with the z component replaced by `f(v.z)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the z component.\n * @returns A new `Vector3` with the updated z.\n * @since 2.0.0\n */\n (v: Vector3, f: (z: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the z component replaced by `f(v.z)`.\n *\n * @param f - The function to apply to the z component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (z: number) => number): (v: Vector3) => Vector3\n} = internal.mapZ\n\n/**\n * Gets the radius of a `Vector3`.\n *\n * @param v - The vector of which to get the radius.\n * @returns The radius of the vector.\n * @since 1.0.0\n */\nexport const getR: (v: Vector3) => number = magnitude\n\nexport const setR: {\n /**\n * Sets the radius of a `Vector3`.\n *\n * @param v - The vector of which to set the radius.\n * @param r - The new radius.\n * @returns A new `Vector3` instance with the updated radius.\n * @since 1.0.0\n */\n (v: Vector3, r: number): Vector3\n /**\n * Sets the radius of a `Vector3`.\n *\n * @param r - The new radius.\n * @returns A function that takes the vector and returns the updated vector.\n * @since 1.0.0\n */\n (r: number): (v: Vector3) => Vector3\n} = internal.setR\n\nexport const mapR: {\n /**\n * Returns a new `Vector3` with the radius replaced by `f(magnitude(v))`,\n * preserving direction.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the radius.\n * @returns A new `Vector3` with the updated radius.\n * @since 2.0.0\n */\n (v: Vector3, f: (r: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the radius replaced by `f(magnitude(v))`,\n * preserving direction.\n *\n * @param f - The function to apply to the radius.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (r: number) => number): (v: Vector3) => Vector3\n} = internal.mapR\n\n/**\n * Gets the polar angle (theta) of a `Vector3`.\n *\n * @param v - The vector of which to get the polar angle.\n * @returns The polar angle of the vector.\n * @since 1.0.0\n */\nexport const getTheta: (v: Vector3) => number = internal.getTheta\n\nexport const setTheta: {\n /**\n * Sets the polar angle (theta) of a `Vector3`.\n *\n * @param v - The vector of which to set the polar angle.\n * @param theta - The new polar angle.\n * @returns A new `Vector3` instance with the updated polar angle.\n * @since 1.0.0\n */\n (v: Vector3, theta: number): Vector3\n /**\n * Sets the polar angle (theta) of a `Vector3`.\n *\n * @param theta - The new polar angle.\n * @returns A function that takes the vector and returns the updated vector.\n * @since 1.0.0\n */\n (theta: number): (v: Vector3) => Vector3\n} = internal.setTheta\n\nexport const mapTheta: {\n /**\n * Returns a new `Vector3` with the polar angle replaced by\n * `f(getTheta(v))`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the polar angle (in radians).\n * @returns A new `Vector3` with the updated polar angle.\n * @since 2.0.0\n */\n (v: Vector3, f: (theta: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the polar angle replaced by\n * `f(getTheta(v))`.\n *\n * @param f - The function to apply to the polar angle (in radians).\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (theta: number) => number): (v: Vector3) => Vector3\n} = internal.mapTheta\n\n/**\n * Gets the azimuthal angle (phi) of a `Vector3`.\n *\n * @param v - The vector of which to get the azimuthal angle.\n * @returns The azimuthal angle of the vector.\n * @since 1.0.0\n */\nexport const getPhi: (v: Vector3) => number = internal.getPhi\n\nexport const setPhi: {\n /**\n * Sets the azimuthal angle (phi) of a `Vector3`.\n *\n * @param v - The vector of which to set the azimuthal angle.\n * @param phi - The new azimuthal angle.\n * @returns A new `Vector3` instance with the updated azimuthal angle.\n * @since 1.0.0\n */\n (v: Vector3, phi: number): Vector3\n /**\n * Sets the azimuthal angle (phi) of a `Vector3`.\n *\n * @param phi - The new azimuthal angle.\n * @returns A function that takes the vector and returns the updated vector.\n * @since 1.0.0\n */\n (phi: number): (v: Vector3) => Vector3\n} = internal.setPhi\n\nexport const mapPhi: {\n /**\n * Returns a new `Vector3` with the azimuthal angle replaced by\n * `f(getPhi(v))`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the azimuthal angle (in radians).\n * @returns A new `Vector3` with the updated azimuthal angle.\n * @since 2.0.0\n */\n (v: Vector3, f: (phi: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the azimuthal angle replaced by\n * `f(getPhi(v))`.\n *\n * @param f - The function to apply to the azimuthal angle (in radians).\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (phi: number) => number): (v: Vector3) => Vector3\n} = internal.mapPhi\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,YAA0CA;AAEvD,MAAa,SAoBTC;AAEJ,MAAa,OA4BTC;;;;;;;;;AAUJ,MAAa,YAA+DC;;;;;;;;;;;AAY5E,MAAa,YAGsCC;;;;;;;;;;AAWnD,MAAa,gBACXC;;;;;;;;AASF,MAAa,YAAyCC;;;;;;;;;AAUtD,MAAa,SAAsC;;;;;;;;AASnD,MAAa,YAA0CC;AAEvD,MAAa,MAkBTC;AAEJ,MAAa,QAkBTC;;;;;;;;AASJ,MAAa,aAAuDC;;;;;;;;AASpE,MAAa,UAAmCC;;;;;;AAOhD,MAAa,OAAO,KAAK,EAAE;;;;;;AAO3B,MAAa,OAAO,KAAK,EAAE;;;;;;AAO3B,MAAa,QAAQ,KAAK,GAAG,GAAG,EAAE;;;;;;AAOlC,MAAa,QAAQ,KAAK,GAAG,GAAG,EAAE;;;;;;AAOlC,MAAa,QAAQ,KAAK,GAAG,GAAG,EAAE;AAElC,MAAa,MAkBTC;AAEJ,MAAa,WAkBTC;AAEJ,MAAa,WAsBTC;AAEJ,MAAa,QAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+B;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAoBTC;;;;;;;;AASJ,MAAa,WAAmCC;AAEhD,MAAa,WAkBTC;AAEJ,MAAa,WAoBTC;;;;;;;;AASJ,MAAa,SAAiCC;AAE9C,MAAa,SAkBTC;AAEJ,MAAa,SAoBTC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-25Hzd3z8.mjs";
|
|
2
|
-
import { a as fromTuple$1, c as
|
|
2
|
+
import { C as setZ$1, E as transpose$1, S as setY$1, T as subtract$1, _ as mapZ$1, a as fromTuple$1, b as setW$1, c as getY$1, d as isVector4$1, f as magnitude$1, g as mapY$1, h as mapX$1, i as equals$1, l as getZ$1, m as mapW$1, n as components$1, o as getW$1, p as make$1, r as dot$1, s as getX$1, t as add$1, u as hadamard$1, v as normalize$1, w as softmax$1, x as setX$1, y as scale$1 } from "./vector4.internal-BJ1QN2Ck.mjs";
|
|
3
3
|
//#region src/vector/vector4.ts
|
|
4
4
|
var vector4_exports = /* @__PURE__ */ __exportAll({
|
|
5
5
|
add: () => add,
|
|
@@ -7,12 +7,24 @@ var vector4_exports = /* @__PURE__ */ __exportAll({
|
|
|
7
7
|
dot: () => dot,
|
|
8
8
|
equals: () => equals,
|
|
9
9
|
fromTuple: () => fromTuple,
|
|
10
|
+
getW: () => getW,
|
|
11
|
+
getX: () => getX,
|
|
12
|
+
getY: () => getY,
|
|
13
|
+
getZ: () => getZ,
|
|
10
14
|
hadamard: () => hadamard,
|
|
11
15
|
isVector4: () => isVector4,
|
|
12
16
|
magnitude: () => magnitude,
|
|
13
17
|
make: () => make,
|
|
18
|
+
mapW: () => mapW,
|
|
19
|
+
mapX: () => mapX,
|
|
20
|
+
mapY: () => mapY,
|
|
21
|
+
mapZ: () => mapZ,
|
|
14
22
|
normalize: () => normalize,
|
|
15
23
|
scale: () => scale,
|
|
24
|
+
setW: () => setW,
|
|
25
|
+
setX: () => setX,
|
|
26
|
+
setY: () => setY,
|
|
27
|
+
setZ: () => setZ,
|
|
16
28
|
softmax: () => softmax,
|
|
17
29
|
subtract: () => subtract,
|
|
18
30
|
transpose: () => transpose,
|
|
@@ -113,7 +125,47 @@ const add = add$1;
|
|
|
113
125
|
const subtract = subtract$1;
|
|
114
126
|
const hadamard = hadamard$1;
|
|
115
127
|
const scale = scale$1;
|
|
128
|
+
/**
|
|
129
|
+
* Gets the x component of a `Vector4`.
|
|
130
|
+
*
|
|
131
|
+
* @param v - The vector to get the x component of.
|
|
132
|
+
* @returns The x component of the vector.
|
|
133
|
+
* @since 2.0.0
|
|
134
|
+
*/
|
|
135
|
+
const getX = getX$1;
|
|
136
|
+
const setX = setX$1;
|
|
137
|
+
const mapX = mapX$1;
|
|
138
|
+
/**
|
|
139
|
+
* Gets the y component of a `Vector4`.
|
|
140
|
+
*
|
|
141
|
+
* @param v - The vector to get the y component of.
|
|
142
|
+
* @returns The y component of the vector.
|
|
143
|
+
* @since 2.0.0
|
|
144
|
+
*/
|
|
145
|
+
const getY = getY$1;
|
|
146
|
+
const setY = setY$1;
|
|
147
|
+
const mapY = mapY$1;
|
|
148
|
+
/**
|
|
149
|
+
* Gets the z component of a `Vector4`.
|
|
150
|
+
*
|
|
151
|
+
* @param v - The vector to get the z component of.
|
|
152
|
+
* @returns The z component of the vector.
|
|
153
|
+
* @since 2.0.0
|
|
154
|
+
*/
|
|
155
|
+
const getZ = getZ$1;
|
|
156
|
+
const setZ = setZ$1;
|
|
157
|
+
const mapZ = mapZ$1;
|
|
158
|
+
/**
|
|
159
|
+
* Gets the w component of a `Vector4`.
|
|
160
|
+
*
|
|
161
|
+
* @param v - The vector to get the w component of.
|
|
162
|
+
* @returns The w component of the vector.
|
|
163
|
+
* @since 2.0.0
|
|
164
|
+
*/
|
|
165
|
+
const getW = getW$1;
|
|
166
|
+
const setW = setW$1;
|
|
167
|
+
const mapW = mapW$1;
|
|
116
168
|
//#endregion
|
|
117
169
|
export { transpose as n, vector4_exports as r, make as t };
|
|
118
170
|
|
|
119
|
-
//# sourceMappingURL=vector4-
|
|
171
|
+
//# sourceMappingURL=vector4-PO_7EYd-.mjs.map
|