curvy 2.0.0-alpha.13 → 2.0.0-alpha.15
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/cubic2d.d.ts +92 -3
- package/dist/curve/curve2d.d.ts +81 -0
- package/dist/curve/index.mjs +1 -1
- package/dist/curve/linear2d.d.ts +113 -3
- package/dist/curve/quadratic2d.d.ts +92 -3
- package/dist/curve/rationalCubic2d.d.ts +100 -38
- package/dist/interval/index.mjs +2 -2
- package/dist/matrix/index.mjs +47 -1
- package/dist/matrix/index.mjs.map +1 -1
- package/dist/matrix/matrix3x3.d.ts +87 -1
- package/dist/matrix/matrix4x4.d.ts +57 -6
- package/dist/matrix/traits.d.ts +34 -0
- package/dist/monotonicity/index.mjs +1 -1
- package/dist/monotonicity/monotonicity.d.ts +25 -0
- package/dist/number.d.ts +53 -0
- package/dist/number.mjs +56 -1
- package/dist/number.mjs.map +1 -1
- package/dist/path/cubic2d.d.ts +22 -0
- package/dist/path/index.mjs +25 -149
- package/dist/path/index.mjs.map +1 -1
- package/dist/path/linear2d.d.ts +24 -0
- package/dist/path/path2d.d.ts +54 -0
- package/dist/path/quadratic2d.d.ts +22 -0
- package/dist/path/rationalCubic2d.d.ts +21 -0
- package/dist/polynomial/index.mjs +2 -2
- package/dist/shared/affine2d-Dvna84gc.mjs +332 -0
- package/dist/shared/affine2d-Dvna84gc.mjs.map +1 -0
- package/dist/shared/{characteristic-BkEr-rr8.mjs → characteristic--7nC4Q_a.mjs} +4 -5
- package/dist/shared/characteristic--7nC4Q_a.mjs.map +1 -0
- package/dist/shared/{cubic-BL6dpuHh.mjs → cubic-BiGuAnZ0.mjs} +56 -27
- package/dist/shared/cubic-BiGuAnZ0.mjs.map +1 -0
- package/dist/shared/{interval-Dm35Xhy4.mjs → interval-Dcqpo73t.mjs} +5 -5
- package/dist/shared/interval-Dcqpo73t.mjs.map +1 -0
- package/dist/shared/{interval2d-AtneyI45.mjs → interval2d-C2Pk66-2.mjs} +3 -3
- package/dist/shared/{interval2d-AtneyI45.mjs.map → interval2d-C2Pk66-2.mjs.map} +1 -1
- package/dist/shared/matrix3x3.internal-Cod-r7H3.mjs +233 -0
- package/dist/shared/matrix3x3.internal-Cod-r7H3.mjs.map +1 -0
- package/dist/shared/{matrix4x4-BWmf4lZM.mjs → matrix4x4-BrqgYZCD.mjs} +72 -223
- package/dist/shared/matrix4x4-BrqgYZCD.mjs.map +1 -0
- package/dist/shared/monotonicity-DNxBoC7F.mjs +64 -0
- package/dist/shared/monotonicity-DNxBoC7F.mjs.map +1 -0
- package/dist/shared/{quadratic-DPrUsFCp.mjs → quadratic-BmMqkvxx.mjs} +2 -2
- package/dist/shared/{quadratic-DPrUsFCp.mjs.map → quadratic-BmMqkvxx.mjs.map} +1 -1
- package/dist/shared/{rationalCubic2d-H1J2Fjyy.mjs → rationalCubic2d-CZiP8nIq.mjs} +282 -326
- package/dist/shared/rationalCubic2d-CZiP8nIq.mjs.map +1 -0
- package/dist/shared/{rationalCubic2d-CeHgpNht.mjs → rationalCubic2d-gM7VeiiT.mjs} +585 -125
- package/dist/shared/rationalCubic2d-gM7VeiiT.mjs.map +1 -0
- package/dist/shared/{solution-B2JdOZpe.mjs → solution-BW0BBMXI.mjs} +22 -6
- package/dist/shared/solution-BW0BBMXI.mjs.map +1 -0
- package/dist/shared/{vector2-CSkaMXvp.mjs → vector2-DuA3EmfL.mjs} +5 -3
- package/dist/shared/vector2-DuA3EmfL.mjs.map +1 -0
- package/dist/shared/{vector2.internal-DP1nTBdS.mjs → vector2.internal-rPnW0RCx.mjs} +10 -5
- package/dist/shared/vector2.internal-rPnW0RCx.mjs.map +1 -0
- package/dist/shared/{vector3-CR2LPV03.mjs → vector3-oxtggkDp.mjs} +2 -2
- package/dist/shared/{vector3-CR2LPV03.mjs.map → vector3-oxtggkDp.mjs.map} +1 -1
- package/dist/shared/vector3.internal-CfWHl9SG.mjs +135 -0
- package/dist/shared/vector3.internal-CfWHl9SG.mjs.map +1 -0
- package/dist/shared/{vector4-PO_7EYd-.mjs → vector4-DGHuCvTV.mjs} +2 -2
- package/dist/shared/{vector4-PO_7EYd-.mjs.map → vector4-DGHuCvTV.mjs.map} +1 -1
- package/dist/shared/vector4.internal-DH5DzNYO.mjs +116 -0
- package/dist/shared/vector4.internal-DH5DzNYO.mjs.map +1 -0
- package/dist/solution/index.mjs +1 -1
- package/dist/solution/solution.d.ts +16 -0
- package/dist/splines/basis2d.d.ts +64 -0
- package/dist/splines/bezier2d.d.ts +72 -0
- package/dist/splines/cardinal2d.d.ts +78 -0
- package/dist/splines/hermite2d.d.ts +76 -0
- package/dist/splines/index.mjs +109 -15
- package/dist/splines/index.mjs.map +1 -1
- package/dist/splines/linear2d.d.ts +65 -0
- package/dist/splines/rationalBezier2d.d.ts +76 -0
- package/dist/transform/affine2d.d.ts +339 -0
- package/dist/transform/affine2d.internal.d.ts +2 -0
- package/dist/transform/index.d.ts +3 -0
- package/dist/transform/index.mjs +2 -0
- package/dist/transform/traits.d.ts +19 -0
- package/dist/vector/index.mjs +3 -3
- package/dist/vector/vector2.d.ts +49 -0
- package/package.json +5 -1
- package/dist/shared/characteristic-BkEr-rr8.mjs.map +0 -1
- package/dist/shared/cubic-BL6dpuHh.mjs.map +0 -1
- package/dist/shared/interval-Dm35Xhy4.mjs.map +0 -1
- package/dist/shared/matrix4x4-BWmf4lZM.mjs.map +0 -1
- package/dist/shared/monotonicity-BdebFOtv.mjs +0 -34
- package/dist/shared/monotonicity-BdebFOtv.mjs.map +0 -1
- package/dist/shared/rationalCubic2d-CeHgpNht.mjs.map +0 -1
- package/dist/shared/rationalCubic2d-H1J2Fjyy.mjs.map +0 -1
- package/dist/shared/solution-B2JdOZpe.mjs.map +0 -1
- package/dist/shared/vector2-CSkaMXvp.mjs.map +0 -1
- package/dist/shared/vector2.internal-DP1nTBdS.mjs.map +0 -1
- package/dist/shared/vector4.internal-BJ1QN2Ck.mjs +0 -246
- package/dist/shared/vector4.internal-BJ1QN2Ck.mjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-25Hzd3z8.mjs";
|
|
2
|
-
import { A as
|
|
2
|
+
import { A as transpose$1, C as scale$1, D as setY$1, E as setX$1, M as weightedEquals$1, N as withWeight$1, O as softmax$1, S as normalize$1, T as setTheta$1, _ as makeWeighted$1, a as equals$1, b as mapX$1, c as getTheta$1, d as hadamard$1, f as isVector2$1, g as make$1, h as magnitude$1, i as dot$1, j as unweighted$1, k as subtract$1, l as getX$1, m as liftWithWeight$1, n as components$1, o as fromPolar$1, p as isWeighted$1, r as cross$1, s as fromTuple$1, t as add$1, u as getY$1, v as mapR$1, w as setR$1, x as mapY$1, y as mapTheta$1 } from "./vector2.internal-rPnW0RCx.mjs";
|
|
3
3
|
//#region src/vector/vector2.ts
|
|
4
4
|
var vector2_exports = /* @__PURE__ */ __exportAll({
|
|
5
5
|
add: () => add,
|
|
@@ -16,6 +16,7 @@ var vector2_exports = /* @__PURE__ */ __exportAll({
|
|
|
16
16
|
hadamard: () => hadamard,
|
|
17
17
|
isVector2: () => isVector2,
|
|
18
18
|
isWeighted: () => isWeighted,
|
|
19
|
+
liftWithWeight: () => liftWithWeight,
|
|
19
20
|
magnitude: () => magnitude,
|
|
20
21
|
make: () => make,
|
|
21
22
|
makeWeighted: () => makeWeighted,
|
|
@@ -74,6 +75,7 @@ const withWeight = withWeight$1;
|
|
|
74
75
|
* @since 2.0.0
|
|
75
76
|
*/
|
|
76
77
|
const unweighted = unweighted$1;
|
|
78
|
+
const liftWithWeight = liftWithWeight$1;
|
|
77
79
|
const weightedEquals = weightedEquals$1;
|
|
78
80
|
const equals = equals$1;
|
|
79
81
|
const make = make$1;
|
|
@@ -200,6 +202,6 @@ const getTheta = getTheta$1;
|
|
|
200
202
|
const setTheta = setTheta$1;
|
|
201
203
|
const mapTheta = mapTheta$1;
|
|
202
204
|
//#endregion
|
|
203
|
-
export {
|
|
205
|
+
export { magnitude as a, scale as c, liftWithWeight as i, subtract as l, cross as n, make as o, isVector2 as r, makeWeighted as s, add as t, vector2_exports as u };
|
|
204
206
|
|
|
205
|
-
//# sourceMappingURL=vector2-
|
|
207
|
+
//# sourceMappingURL=vector2-DuA3EmfL.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector2-DuA3EmfL.mjs","names":["internal.isVector2","internal.isWeighted","internal.makeWeighted","internal.withWeight","internal.unweighted","internal.liftWithWeight","internal.weightedEquals","internal.equals","internal.make","internal.fromTuple","internal.transpose","internal.fromPolar","internal.magnitude","internal.normalize","internal.dot","internal.cross","internal.components","internal.softmax","internal.add","internal.subtract","internal.hadamard","internal.scale","internal.getX","internal.setX","internal.mapX","internal.getY","internal.setY","internal.mapY","internal.setR","internal.mapR","internal.getTheta","internal.setTheta","internal.mapTheta"],"sources":["../../src/vector/vector2.ts"],"sourcesContent":["import type { TwoDimensional } from '../dimensions.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector2TypeId, WeightedVector2TypeId } from './vector2.internal.ts'\nimport * as internal from './vector2.internal.ts'\n\n/**\n * A 2D vector.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 1.0.0\n */\nexport interface Vector2 extends Pipeable, TwoDimensional<number> {\n readonly [Vector2TypeId]: Vector2TypeId\n}\n\n/**\n * A 2D point with an associated positive scalar weight.\n *\n * Used by rational primitives (e.g. `RationalBezier2d`) where each control\n * point carries an influence weight. The interface is structurally distinct\n * from `Vector2` — its brand prevents accidental use with vector arithmetic\n * (`add`, `subtract`, `scale`, etc.) where weighted operations are not\n * well-defined.\n *\n * Construct via {@link makeWeighted} (from raw components) or\n * {@link withWeight} (from an existing `Vector2`).\n *\n * @since 2.0.0\n */\nexport interface Weighted extends Pipeable {\n readonly [WeightedVector2TypeId]: WeightedVector2TypeId\n readonly x: number\n readonly y: number\n readonly weight: number\n}\n\n/**\n * Checks if a value is a `Vector2`.\n *\n * @param v - The value to check.\n * @returns `true` if the value is a `Vector2`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isVector2: (v: unknown) => v is Vector2 = internal.isVector2\n\n/**\n * Checks if a value is a `Vector2.Weighted`.\n *\n * @param v - The value to check.\n * @returns `true` if the value is a `Vector2.Weighted`, `false` otherwise.\n * @since 2.0.0\n */\nexport const isWeighted: (v: unknown) => v is Weighted = internal.isWeighted\n\n/**\n * Creates a new `Vector2.Weighted` from raw components. The weight must be\n * finite and positive.\n *\n * @param x - The x component.\n * @param y - The y component.\n * @param weight - The positive scalar weight.\n * @returns A new `Vector2.Weighted` instance.\n * @since 2.0.0\n */\nexport const makeWeighted: (x: number, y: number, weight: number) => Weighted =\n internal.makeWeighted\n\nexport const withWeight: {\n /**\n * Promotes a `Vector2` to a `Vector2.Weighted` by attaching the given\n * positive scalar weight.\n *\n * @param v - The point to weight.\n * @param weight - The positive scalar weight.\n * @returns A new `Vector2.Weighted` instance.\n * @since 2.0.0\n */\n (v: Vector2, weight: number): Weighted\n /**\n * Promotes a `Vector2` to a `Vector2.Weighted` by attaching the given\n * positive scalar weight.\n *\n * @param weight - The positive scalar weight.\n * @returns A function that takes a `Vector2` and returns a weighted point.\n * @since 2.0.0\n */\n (weight: number): (v: Vector2) => Weighted\n} = internal.withWeight\n\n/**\n * Strips the weight from a `Vector2.Weighted`, returning the underlying point.\n *\n * @param w - The weighted point.\n * @returns A new `Vector2` instance with the same x and y components.\n * @since 2.0.0\n */\nexport const unweighted: (w: Weighted) => Vector2 = internal.unweighted\n\nexport const liftWithWeight: {\n /**\n * Lifts a `Vector2 → Vector2` function to operate on `Vector2.Weighted` by\n * applying the function to the position and preserving the input's weight.\n *\n * Designed as the bridge between point-only utilities (e.g. {@link setR},\n * `Vector2.add(offset)`) and weighted-spline mappers like\n * `RationalBezier2d.mapPoints`. The default of \"preserve weight\" is the safe\n * choice for the common case — translating, rotating, or scaling positions\n * on a curve like a conic arc shouldn't silently collapse the curve's\n * geometry-defining weights to a uniform value.\n *\n * @param fn - The position-only function to lift.\n * @returns A function from `Weighted` to `Weighted` that preserves weight.\n * @since 2.0.0\n */\n (fn: (v: Vector2) => Vector2): (w: Weighted) => Weighted\n /**\n * Lifts a `Vector2 → Vector2` function to operate on `Vector2.Weighted`,\n * replacing the input's weight with the given value.\n *\n * @param fn - The position-only function to lift.\n * @param weight - The positive scalar weight to attach to each output.\n * @returns A function from `Weighted` to `Weighted` that overrides weight.\n * @since 2.0.0\n */\n (fn: (v: Vector2) => Vector2, weight: number): (w: Weighted) => Weighted\n /**\n * Applies a `Vector2 → Vector2` function to the position of a\n * `Vector2.Weighted`, preserving the input's weight.\n *\n * @param w - The weighted point to transform.\n * @param fn - The position-only function to apply.\n * @returns A new `Vector2.Weighted` with the function applied to position and the original weight.\n * @since 2.0.0\n */\n (w: Weighted, fn: (v: Vector2) => Vector2): Weighted\n /**\n * Applies a `Vector2 → Vector2` function to the position of a\n * `Vector2.Weighted`, replacing the weight with the given value.\n *\n * @param w - The weighted point to transform.\n * @param fn - The position-only function to apply.\n * @param weight - The positive scalar weight to attach to the output.\n * @returns A new `Vector2.Weighted` with the function applied to position and the overridden weight.\n * @since 2.0.0\n */\n (w: Weighted, fn: (v: Vector2) => Vector2, weight: number): Weighted\n} = internal.liftWithWeight\n\nexport const weightedEquals: {\n /**\n * Checks if two `Vector2.Weighted` instances are approximately equal —\n * point components and weight all within the default absolute tolerance.\n *\n * @param a - The first weighted point.\n * @param b - The second weighted point.\n * @returns `true` when components and weight are within tolerance.\n * @since 2.0.0\n */\n (a: Weighted, b: Weighted): boolean\n /**\n * Checks if two `Vector2.Weighted` instances are approximately equal.\n *\n * @param b - The second weighted point.\n * @returns A function that takes the first weighted point and returns the comparison result.\n * @since 2.0.0\n */\n (b: Weighted): (a: Weighted) => boolean\n} = internal.weightedEquals\n\nexport const equals: {\n /**\n * Checks if two `Vector2` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns `true` when each pair of components is within tolerance.\n * @since 1.1.0\n */\n (a: Vector2, b: Vector2): boolean\n /**\n * Checks if two `Vector2` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the comparison result.\n * @since 1.1.0\n */\n (b: Vector2): (a: Vector2) => boolean\n} = internal.equals\n\nexport const make: {\n /**\n * Creates a new `Vector2` instance.\n *\n * @param xy - The x and y components of the vector.\n * @returns A new `Vector2` instance.\n * @since 1.0.0\n */\n (xy: number): Vector2\n /**\n * Creates a new `Vector2` instance.\n *\n * @param x - The x component of the vector.\n * @param y - The y component of the vector.\n * @returns A new `Vector2` instance.\n * @since 1.0.0\n */\n (x: number, y: number): Vector2\n} = internal.make\n\n/**\n * Creates a new `Vector2` instance from a `[x, y]` tuple. Inverse of\n * {@link components}.\n *\n * @param t - The `[x, y]` tuple.\n * @returns A new `Vector2` instance.\n * @since 2.0.0\n */\nexport const fromTuple: (t: readonly [number, number]) => Vector2 = internal.fromTuple\n\n/**\n * Transposes a 2-tuple of items into one or more `Vector2`s, one per channel\n * extracted by the projection function. See {@link Vector4.transpose} for the\n * full operation description; this is the 2-component analog.\n *\n * @param inputs - Exactly two items of any type.\n * @param project - A function returning a fixed-arity tuple of numbers — one per output channel.\n * @returns A tuple of `Vector2`s with the same arity as the projection's return tuple.\n * @since 2.0.0\n */\nexport const transpose: <T, const Channels extends ReadonlyArray<number>>(\n inputs: readonly [T, T],\n project: (item: T) => Channels,\n) => { readonly [K in keyof Channels]: Vector2 } = internal.transpose\n\n/**\n * Creates a new `Vector2` instance from polar coordinates.\n *\n * @param r - The radius.\n * @param theta - The angle, in radians.\n * @returns A new `Vector2` instance.\n * @since 1.0.0\n */\nexport const fromPolar: (r: number, theta: number) => Vector2 = internal.fromPolar\n\n/**\n * Calculates the magnitude of a `Vector2`.\n *\n * @param vector - The vector to calculate the magnitude of.\n * @returns The magnitude of the vector.\n * @since 1.0.0\n */\nexport const magnitude: (vector: Vector2) => number = internal.magnitude\n\n/**\n * Normalizes a `Vector2`.\n *\n * @param vector - The vector to normalize.\n * @returns A new `Vector2` instance with the same direction and a magnitude of 1.\n * @since 1.0.0\n */\nexport const normalize: (vector: Vector2) => Vector2 = internal.normalize\n\nexport const dot: {\n /**\n * Calculates the dot product of two `Vector2` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns The dot product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector2, b: Vector2): number\n /**\n * Calculates the dot product of two `Vector2` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the dot product.\n * @since 1.0.0\n */\n (b: Vector2): (a: Vector2) => number\n} = internal.dot\n\nexport const cross: {\n /**\n * Calculates the cross product of two `Vector2` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns The cross product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector2, b: Vector2): number\n /**\n * Calculates the cross product of two `Vector2` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the cross product.\n * @since 1.0.0\n */\n (b: Vector2): (a: Vector2) => number\n} = internal.cross\n\n/**\n * Returns the components of a `Vector2` as an array.\n *\n * @param r - The radius.\n * @param theta - The angle, in radians.\n * @returns A new `Vector2` instance.\n * @since 1.0.0\n */\nexport const components: (v: Vector2) => [number, number] = internal.components\n\n/**\n * Applies the softmax function to a `Vector2`.\n *\n * @param v - The vector to apply the softmax function to.\n * @returns A new `Vector2` instance with the softmax applied.\n * @since 1.0.0\n */\nexport const softmax: (v: Vector2) => Vector2 = internal.softmax\n\n/**\n * Creates a zero vector.\n *\n * @returns A new `Vector2` instance with both components set to 0.\n * @since 1.0.0\n */\nexport const zero = make(0)\n\n/**\n * Creates a unit vector.\n *\n * @returns A new `Vector2` instance with both components set to 1.\n * @since 1.0.0\n */\nexport const unit = make(1)\n\nexport const add: {\n /**\n * Adds two `Vector2` instances together.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector2` instance representing the sum of the two vectors.\n * @since 1.0.0\n */\n (a: Vector2, b: Vector2): Vector2\n /**\n * Adds two `Vector2` instances together.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the sum.\n * @since 1.0.0\n */\n (b: Vector2): (a: Vector2) => Vector2\n} = internal.add\n\nexport const subtract: {\n /**\n * Subtracts one `Vector2` instance from another.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector2` instance representing the difference of the two vectors.\n * @since 1.0.0\n */\n (a: Vector2, b: Vector2): Vector2\n /**\n * Subtracts one `Vector2` instance from another.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the difference.\n * @since 1.0.0\n */\n (b: Vector2): (a: Vector2) => Vector2\n} = internal.subtract\n\nexport const hadamard: {\n /**\n * Performs the Hadamard product of two `Vector2` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector2` instance representing the Hadamard product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector2, b: Vector2): Vector2\n /**\n * Performs the Hadamard product of two `Vector2` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the Hadamard product.\n * @since 1.0.0\n */\n (b: Vector2): (a: Vector2) => Vector2\n} = internal.hadamard\n\nexport const scale: {\n /**\n * Scales a `Vector2` by a scalar value.\n *\n * @param s - The scalar value to scale by.\n * @returns A function that takes a vector and returns the scaled vector.\n * @since 1.0.0\n */\n (s: number): (v: Vector2) => Vector2\n /**\n * Scales a `Vector2` by a scalar value.\n *\n * @param v - The vector to scale.\n * @param s - The scalar value to scale by.\n * @returns A new `Vector2` instance representing the scaled vector.\n * @since 1.0.0\n */\n (v: Vector2, s: number): Vector2\n} = internal.scale\n\n/**\n * Gets the x component of a `Vector2`.\n *\n * @param v - The vector to get the x component from.\n * @returns The x component of the vector.\n * @since 1.0.0\n */\nexport const getX: (v: Vector2) => number = internal.getX\n\nexport const setX: {\n /**\n * Sets the x component of a `Vector2`.\n *\n * @param v - The vector to set the x component of.\n * @param x - The new x component.\n * @returns A new `Vector2` instance with the updated x component.\n * @since 1.0.0\n */\n (v: Vector2, x: number): Vector2\n /**\n * Sets the x component of a `Vector2`.\n *\n * @param x - The new x component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 1.0.0\n */\n (x: number): (v: Vector2) => Vector2\n} = internal.setX\n\nexport const mapX: {\n /**\n * Returns a new `Vector2` with the x component replaced by `f(v.x)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the x component.\n * @returns A new `Vector2` with the updated x.\n * @since 2.0.0\n */\n (v: Vector2, f: (x: number) => number): Vector2\n /**\n * Returns a new `Vector2` with the x component replaced by `f(v.x)`.\n *\n * @param f - The function to apply to the x component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (x: number) => number): (v: Vector2) => Vector2\n} = internal.mapX\n\n/**\n * Gets the y component of a `Vector2`.\n *\n * @param v - The vector to get the y component from.\n * @returns The y component of the vector.\n * @since 1.0.0\n */\nexport const getY: (v: Vector2) => number = internal.getY\n\nexport const setY: {\n /**\n * Sets the y component of a `Vector2`.\n *\n * @param v - The vector to set the y component of.\n * @param y - The new y component.\n * @returns A new `Vector2` instance with the updated y component.\n * @since 1.0.0\n */\n (v: Vector2, y: number): Vector2\n /**\n * Sets the y component of a `Vector2`.\n *\n * @param y - The new y component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 1.0.0\n */\n (y: number): (v: Vector2) => Vector2\n} = internal.setY\n\nexport const mapY: {\n /**\n * Returns a new `Vector2` with the y component replaced by `f(v.y)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the y component.\n * @returns A new `Vector2` with the updated y.\n * @since 2.0.0\n */\n (v: Vector2, f: (y: number) => number): Vector2\n /**\n * Returns a new `Vector2` with the y component replaced by `f(v.y)`.\n *\n * @param f - The function to apply to the y component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (y: number) => number): (v: Vector2) => Vector2\n} = internal.mapY\n\n/**\n * Gets the radius of a `Vector2`.\n *\n * @param v - The vector to get the radius from.\n * @returns The radius of the vector.\n * @since 1.0.0\n */\nexport const getR: (v: Vector2) => number = magnitude\n\nexport const setR: {\n /**\n * Sets the radius of a `Vector2`.\n *\n * @param v - The vector to set the radius of.\n * @param r - The new radius.\n * @returns A new `Vector2` instance with the updated radius.\n * @since 1.0.0\n */\n (v: Vector2, r: number): Vector2\n /**\n * Sets the radius of a `Vector2`.\n *\n * @param r - The new radius.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 1.0.0\n */\n (r: number): (v: Vector2) => Vector2\n} = internal.setR\n\nexport const mapR: {\n /**\n * Returns a new `Vector2` with the radius replaced by `f(magnitude(v))`,\n * preserving the angle.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the radius.\n * @returns A new `Vector2` with the updated radius.\n * @since 2.0.0\n */\n (v: Vector2, f: (r: number) => number): Vector2\n /**\n * Returns a new `Vector2` with the radius replaced by `f(magnitude(v))`,\n * preserving the angle.\n *\n * @param f - The function to apply to the radius.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (r: number) => number): (v: Vector2) => Vector2\n} = internal.mapR\n\n/**\n * Gets the angle of a `Vector2`.\n *\n * @param v - The vector to get the angle from.\n * @returns The angle of the vector in radians.\n * @since 1.0.0\n */\nexport const getTheta: (v: Vector2) => number = internal.getTheta\n\nexport const setTheta: {\n /**\n * Sets the angle of a `Vector2`.\n *\n * @param v - The vector to set the angle of.\n * @param theta - The new angle, in radians.\n * @returns A new `Vector2` instance with the updated angle.\n * @since 1.0.0\n */\n (v: Vector2, theta: number): Vector2\n /**\n * Sets the angle of a `Vector2`.\n *\n * @param theta - The new angle, in radians.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 1.0.0\n */\n (theta: number): (v: Vector2) => Vector2\n} = internal.setTheta\n\nexport const mapTheta: {\n /**\n * Returns a new `Vector2` with the angle replaced by `f(getTheta(v))`,\n * preserving the radius.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the angle (in radians).\n * @returns A new `Vector2` with the updated angle.\n * @since 2.0.0\n */\n (v: Vector2, f: (theta: number) => number): Vector2\n /**\n * Returns a new `Vector2` with the angle replaced by `f(getTheta(v))`,\n * preserving the radius.\n *\n * @param f - The function to apply to the angle (in radians).\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (theta: number) => number): (v: Vector2) => Vector2\n} = internal.mapTheta\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAa,YAA0CA;;;;;;;;AASvD,MAAa,aAA4CC;;;;;;;;;;;AAYzD,MAAa,eACXC;AAEF,MAAa,aAoBTC;;;;;;;;AASJ,MAAa,aAAuCC;AAEpD,MAAa,iBAgDTC;AAEJ,MAAa,iBAmBTC;AAEJ,MAAa,SAoBTC;AAEJ,MAAa,OAkBTC;;;;;;;;;AAUJ,MAAa,YAAuDC;;;;;;;;;;;AAYpE,MAAa,YAGsCC;;;;;;;;;AAUnD,MAAa,YAAmDC;;;;;;;;AAShE,MAAa,YAAyCC;;;;;;;;AAStD,MAAa,YAA0CC;AAEvD,MAAa,MAkBTC;AAEJ,MAAa,QAkBTC;;;;;;;;;AAUJ,MAAa,aAA+CC;;;;;;;;AAS5D,MAAa,UAAmCC;;;;;;;AAQhD,MAAa,OAAO,KAAK,EAAE;;;;;;;AAQ3B,MAAa,OAAO,KAAK,EAAE;AAE3B,MAAa,MAkBTC;AAEJ,MAAa,WAkBTC;AAEJ,MAAa,WAkBTC;AAEJ,MAAa,QAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+B;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAoBTC;;;;;;;;AASJ,MAAa,WAAmCC;AAEhD,MAAa,WAkBTC;AAEJ,MAAa,WAoBTC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Pipeable, dual, invariant } from "../utils.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { coincident } from "../number.mjs";
|
|
3
3
|
//#region src/vector/vector2.internal.ts
|
|
4
4
|
const Vector2TypeId = Symbol.for("curvy/vector2");
|
|
5
5
|
const WeightedVector2TypeId = Symbol.for("curvy/vector2/weighted");
|
|
@@ -48,7 +48,7 @@ const isVector2 = (v) => typeof v === "object" && v !== null && Vector2TypeId in
|
|
|
48
48
|
/** @internal */
|
|
49
49
|
const isWeighted = (v) => typeof v === "object" && v !== null && WeightedVector2TypeId in v;
|
|
50
50
|
/** @internal */
|
|
51
|
-
const equals = dual(2, (a, b) =>
|
|
51
|
+
const equals = dual(2, (a, b) => coincident(a.x, b.x) && coincident(a.y, b.y));
|
|
52
52
|
/** @internal */
|
|
53
53
|
const make = (v0, v1 = v0) => new Vector2Impl(v0, v1);
|
|
54
54
|
/** @internal */
|
|
@@ -71,7 +71,12 @@ const withWeight = dual(2, (v, weight) => makeWeighted(v.x, v.y, weight));
|
|
|
71
71
|
/** @internal */
|
|
72
72
|
const unweighted = (w) => make(w.x, w.y);
|
|
73
73
|
/** @internal */
|
|
74
|
-
const
|
|
74
|
+
const liftWithWeight = dual((args) => isWeighted(args[0]), (w, fn, weight) => {
|
|
75
|
+
const r = fn(make(w.x, w.y));
|
|
76
|
+
return makeWeighted(r.x, r.y, weight ?? w.weight);
|
|
77
|
+
});
|
|
78
|
+
/** @internal */
|
|
79
|
+
const weightedEquals = dual(2, (a, b) => coincident(a.x, b.x) && coincident(a.y, b.y) && coincident(a.weight, b.weight));
|
|
75
80
|
/** @internal */
|
|
76
81
|
const fromPolar = (r, theta) => make(r * Math.cos(theta), r * Math.sin(theta));
|
|
77
82
|
/** @internal */
|
|
@@ -136,6 +141,6 @@ const mapTheta = dual(2, (v, f) => {
|
|
|
136
141
|
return make(r * Math.cos(theta), r * Math.sin(theta));
|
|
137
142
|
});
|
|
138
143
|
//#endregion
|
|
139
|
-
export {
|
|
144
|
+
export { transpose as A, scale as C, setY as D, setX as E, weightedEquals as M, withWeight as N, softmax as O, normalize as S, setTheta as T, makeWeighted as _, equals as a, mapX as b, getTheta as c, hadamard as d, isVector2 as f, make as g, magnitude as h, dot as i, unweighted as j, subtract as k, getX as l, liftWithWeight as m, components as n, fromPolar as o, isWeighted as p, cross as r, fromTuple as s, add as t, getY as u, mapR as v, setR as w, mapY as x, mapTheta as y };
|
|
140
145
|
|
|
141
|
-
//# sourceMappingURL=vector2.internal-
|
|
146
|
+
//# sourceMappingURL=vector2.internal-rPnW0RCx.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector2.internal-rPnW0RCx.mjs","names":[],"sources":["../../src/vector/vector2.internal.ts"],"sourcesContent":["import { dual, Pipeable } from '../utils.ts'\nimport { invariant } from '../utils.ts'\nimport { coincident } from '../number.ts'\nimport type { Vector2, Weighted } from './vector2.ts'\n\nexport const Vector2TypeId = Symbol.for('curvy/vector2')\nexport type Vector2TypeId = typeof Vector2TypeId\n\nexport const WeightedVector2TypeId = Symbol.for('curvy/vector2/weighted')\nexport type WeightedVector2TypeId = typeof WeightedVector2TypeId\n\nclass Vector2Impl extends Pipeable implements Vector2 {\n readonly [Vector2TypeId]: Vector2TypeId = Vector2TypeId\n\n readonly x: number\n readonly y: number\n\n constructor(v0 = 0, v1 = 0) {\n super()\n this.x = v0\n this.y = v1\n }\n\n get [0]() {\n return this.x\n }\n\n get [1]() {\n return this.y\n }\n\n get [Symbol.toStringTag]() {\n return `Vector2(${this.x}, ${this.y})`\n }\n\n get [Symbol.for('nodejs.util.inspect.custom')]() {\n return this[Symbol.toStringTag]\n }\n}\n\nclass WeightedImpl extends Pipeable implements Weighted {\n readonly [WeightedVector2TypeId]: WeightedVector2TypeId = WeightedVector2TypeId\n\n readonly x: number\n readonly y: number\n readonly weight: number\n\n constructor(x: number, y: number, weight: number) {\n super()\n this.x = x\n this.y = y\n this.weight = weight\n }\n\n get [Symbol.toStringTag]() {\n return `Vector2.Weighted(${this.x}, ${this.y}, w=${this.weight})`\n }\n\n get [Symbol.for('nodejs.util.inspect.custom')]() {\n return this[Symbol.toStringTag]\n }\n}\n\n/** @internal */\nexport const isVector2 = (v: unknown): v is Vector2 =>\n typeof v === 'object' && v !== null && Vector2TypeId in v\n\n/** @internal */\nexport const isWeighted = (v: unknown): v is Weighted =>\n typeof v === 'object' && v !== null && WeightedVector2TypeId in v\n\n/** @internal */\nexport const equals = dual<\n (b: Vector2) => (a: Vector2) => boolean,\n (a: Vector2, b: Vector2) => boolean\n>(2, (a: Vector2, b: Vector2) => coincident(a.x, b.x) && coincident(a.y, b.y))\n\n/** @internal */\nexport const make = (v0: number, v1 = v0): Vector2 => new Vector2Impl(v0, v1)\n\n/** @internal */\nexport const fromTuple = (t: readonly [number, number]): Vector2 => new Vector2Impl(t[0], t[1])\n\n/** @internal */\nexport const transpose = <T, const Channels extends ReadonlyArray<number>>(\n inputs: readonly [T, T],\n project: (item: T) => Channels,\n): { readonly [K in keyof Channels]: Vector2 } => {\n const a = project(inputs[0])\n const b = project(inputs[1])\n const result: Array<Vector2> = []\n for (let i = 0; i < a.length; i++) {\n result.push(make(a[i] as number, b[i] as number))\n }\n return result as never\n}\n\n/** @internal */\nexport const makeWeighted = (x: number, y: number, weight: number): Weighted => {\n invariant(\n Number.isFinite(weight) && weight > 0,\n 'Vector2.Weighted weight must be positive and finite',\n )\n return new WeightedImpl(x, y, weight)\n}\n\n/** @internal */\nexport const withWeight = dual<\n (weight: number) => (v: Vector2) => Weighted,\n (v: Vector2, weight: number) => Weighted\n>(2, (v: Vector2, weight: number) => makeWeighted(v.x, v.y, weight))\n\n/** @internal */\nexport const unweighted = (w: Weighted): Vector2 => make(w.x, w.y)\n\n/** @internal */\nexport const liftWithWeight = dual(\n (args) => isWeighted(args[0]),\n (w: Weighted, fn: (v: Vector2) => Vector2, weight?: number): Weighted => {\n const r = fn(make(w.x, w.y))\n return makeWeighted(r.x, r.y, weight ?? w.weight)\n },\n)\n\n/** @internal */\nexport const weightedEquals = dual<\n (b: Weighted) => (a: Weighted) => boolean,\n (a: Weighted, b: Weighted) => boolean\n>(\n 2,\n (a: Weighted, b: Weighted) =>\n coincident(a.x, b.x) && coincident(a.y, b.y) && coincident(a.weight, b.weight),\n)\n\n/** @internal */\nexport const fromPolar = (r: number, theta: number) =>\n make(r * Math.cos(theta), r * Math.sin(theta))\n\n/** @internal */\nexport const components = (v: Vector2): [number, number] => [v.x, v.y]\n\n/** @internal */\nexport const magnitude = (vector: Vector2) => Math.hypot(vector.x, vector.y)\n\n/** @internal */\nexport const normalize = (vector: Vector2) => {\n const m = magnitude(vector)\n\n return make(vector.x / m, vector.y / m)\n}\n\n/** @internal */\nexport const dot = dual<(b: Vector2) => (a: Vector2) => number, (a: Vector2, b: Vector2) => number>(\n 2,\n (a: Vector2, b: Vector2) => a.x * b.x + a.y * b.y,\n)\n\n/** @internal */\nexport const cross = dual<\n (b: Vector2) => (a: Vector2) => number,\n (a: Vector2, b: Vector2) => number\n>(2, (a: Vector2, b: Vector2) => a.x * b.y - a.y * b.x)\n\n/** @internal */\nexport const softmax = (v: Vector2) => {\n const max = Math.max(v.x, v.y)\n\n const v0 = Math.exp(v.x - max)\n const v1 = Math.exp(v.y - max)\n\n const sum = v0 + v1\n\n return make(v0 / sum, v1 / sum)\n}\n\n/** @internal */\nexport const add = dual<\n (b: Vector2) => (a: Vector2) => Vector2,\n (a: Vector2, b: Vector2) => Vector2\n>(2, (a: Vector2, b: Vector2) => make(a.x + b.x, a.y + b.y))\n\n/** @internal */\nexport const subtract = dual<\n (b: Vector2) => (a: Vector2) => Vector2,\n (a: Vector2, b: Vector2) => Vector2\n>(2, (a: Vector2, b: Vector2) => make(a.x - b.x, a.y - b.y))\n\n/** @internal */\nexport const hadamard = dual<\n (b: Vector2) => (a: Vector2) => Vector2,\n (a: Vector2, b: Vector2) => Vector2\n>(2, (a: Vector2, b: Vector2) => make(a.x * b.x, a.y * b.y))\n\n/** @internal */\nexport const scale = dual<\n (s: number) => (v: Vector2) => Vector2,\n (v: Vector2, s: number) => Vector2\n>(2, (v: Vector2, s: number) => (s === 1 ? v : make(v.x * s, v.y * s)))\n\n/** @internal */\nexport const getX = (v: Vector2) => v.x\n/** @internal */\nexport const setX = dual<\n (x: number) => (v: Vector2) => Vector2,\n (v: Vector2, x: number) => Vector2\n>(2, (v: Vector2, x: number) => make(x, v.y))\n\n/** @internal */\nexport const mapX = dual<\n (f: (x: number) => number) => (v: Vector2) => Vector2,\n (v: Vector2, f: (x: number) => number) => Vector2\n>(2, (v: Vector2, f: (x: number) => number) => make(f(v.x), v.y))\n\n/** @internal */\nexport const getY = (v: Vector2) => v.y\n/** @internal */\nexport const setY = dual<\n (y: number) => (v: Vector2) => Vector2,\n (v: Vector2, y: number) => Vector2\n>(2, (v: Vector2, y: number) => make(v.x, y))\n\n/** @internal */\nexport const mapY = dual<\n (f: (y: number) => number) => (v: Vector2) => Vector2,\n (v: Vector2, f: (y: number) => number) => Vector2\n>(2, (v: Vector2, f: (y: number) => number) => make(v.x, f(v.y)))\n\n/** @internal */\nexport const setR = dual<\n (r: number) => (v: Vector2) => Vector2,\n (v: Vector2, r: number) => Vector2\n>(2, (v: Vector2, r: number) => scale(r / magnitude(v))(v))\n\n/** @internal */\nexport const mapR = dual<\n (f: (r: number) => number) => (v: Vector2) => Vector2,\n (v: Vector2, f: (r: number) => number) => Vector2\n>(2, (v: Vector2, f: (r: number) => number) => {\n const r = magnitude(v)\n return scale(f(r) / r)(v)\n})\n\n/** @internal */\nexport const getTheta = (v: Vector2) => Math.atan2(v.y, v.x)\n/** @internal */\nexport const setTheta = dual<\n (theta: number) => (v: Vector2) => Vector2,\n (v: Vector2, theta: number) => Vector2\n>(2, (v: Vector2, theta: number) => {\n const r = magnitude(v)\n return make(r * Math.cos(theta), r * Math.sin(theta))\n})\n\n/** @internal */\nexport const mapTheta = dual<\n (f: (theta: number) => number) => (v: Vector2) => Vector2,\n (v: Vector2, f: (theta: number) => number) => Vector2\n>(2, (v: Vector2, f: (theta: number) => number) => {\n const r = magnitude(v)\n const theta = f(Math.atan2(v.y, v.x))\n return make(r * Math.cos(theta), r * Math.sin(theta))\n})\n"],"mappings":"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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-25Hzd3z8.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { A as setZ$1, C as normalize$1, D as setTheta$1, E as setR$1, M as subtract$1, N as transpose$1, O as setX$1, S as mapZ$1, T as setPhi$1, _ as mapPhi$1, a as equals$1, b as mapX$1, c as getPhi$1, d as getY$1, f as getZ$1, g as make$1, h as magnitude$1, i as dot$1, j as softmax$1, k as setY$1, l as getTheta$1, m as isVector3$1, n as components$1, o as fromSpherical$1, p as hadamard$1, r as cross$1, s as fromTuple$1, t as add$1, u as getX$1, v as mapR$1, w as scale$1, x as mapY$1, y as mapTheta$1 } from "./vector3.internal-CfWHl9SG.mjs";
|
|
3
3
|
//#region src/vector/vector3.ts
|
|
4
4
|
var vector3_exports = /* @__PURE__ */ __exportAll({
|
|
5
5
|
add: () => add,
|
|
@@ -223,4 +223,4 @@ const mapPhi = mapPhi$1;
|
|
|
223
223
|
//#endregion
|
|
224
224
|
export { vector3_exports as n, make as t };
|
|
225
225
|
|
|
226
|
-
//# sourceMappingURL=vector3-
|
|
226
|
+
//# sourceMappingURL=vector3-oxtggkDp.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector3-CR2LPV03.mjs","names":["internal.isVector3","internal.equals","internal.make","internal.fromTuple","internal.transpose","internal.fromSpherical","internal.magnitude","internal.normalize","internal.dot","internal.cross","internal.components","internal.softmax","internal.add","internal.subtract","internal.hadamard","internal.scale","internal.getX","internal.setX","internal.mapX","internal.getY","internal.setY","internal.mapY","internal.getZ","internal.setZ","internal.mapZ","internal.setR","internal.mapR","internal.getTheta","internal.setTheta","internal.mapTheta","internal.getPhi","internal.setPhi","internal.mapPhi"],"sources":["../../src/vector/vector3.ts"],"sourcesContent":["import type { ThreeDimensional } from '../dimensions.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector3TypeId } from './vector3.internal.ts'\nimport * as internal from './vector3.internal.ts'\n\n/**\n * A 3D vector.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 1.0.0\n */\nexport interface Vector3 extends Pipeable, ThreeDimensional<number> {\n readonly [Vector3TypeId]: Vector3TypeId\n}\n\n/**\n * Checks if a value is a `Vector3`.\n *\n * @param v - The value to check.\n * @returns `true` if the value is a `Vector3`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isVector3: (v: unknown) => v is Vector3 = internal.isVector3\n\nexport const equals: {\n /**\n * Checks if two `Vector3` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns `true` when each pair of components is within tolerance.\n * @since 1.1.0\n */\n (a: Vector3, b: Vector3): boolean\n /**\n * Checks if two `Vector3` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the comparison result.\n * @since 1.1.0\n */\n (b: Vector3): (a: Vector3) => boolean\n} = internal.equals\n\nexport const make: {\n /**\n * Creates a new `Vector3` instance.\n *\n * @param xyz - The x, y, and z components of the vector.\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\n (xyz: number): Vector3\n /**\n * Creates a new `Vector3` instance.\n *\n * @param x - The x component of the vector.\n * @param yz - The y and z components of the vector.\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\n (x: number, yz: number): Vector3\n /**\n * Creates a new `Vector3` instance.\n *\n * @param x - The x component of the vector.\n * @param y - The y component of the vector.\n * @param z - The z component of the vector.\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\n (x: number, y: number, z: number): Vector3\n} = internal.make\n\n/**\n * Creates a new `Vector3` instance from a `[x, y, z]` tuple. Inverse of\n * {@link components}.\n *\n * @param t - The `[x, y, z]` tuple.\n * @returns A new `Vector3` instance.\n * @since 2.0.0\n */\nexport const fromTuple: (t: readonly [number, number, number]) => Vector3 = internal.fromTuple\n\n/**\n * Transposes a 3-tuple of items into one or more `Vector3`s, one per channel\n * extracted by the projection function. See {@link Vector4.transpose} for the\n * full operation description; this is the 3-component analog.\n *\n * @param inputs - Exactly three items of any type.\n * @param project - A function returning a fixed-arity tuple of numbers — one per output channel.\n * @returns A tuple of `Vector3`s with the same arity as the projection's return tuple.\n * @since 2.0.0\n */\nexport const transpose: <T, const Channels extends ReadonlyArray<number>>(\n inputs: readonly [T, T, T],\n project: (item: T) => Channels,\n) => { readonly [K in keyof Channels]: Vector3 } = internal.transpose\n\n/**\n * Creates a new `Vector3` instance from spherical coordinates.\n *\n * @param r - The radius.\n * @param theta - The polar angle, in radians. Ranges from 0 to π\n * @param phi - The azimuthal angle, in radians. Ranges from 0 to 2π\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\nexport const fromSpherical: (r: number, theta: number, phi: number) => Vector3 =\n internal.fromSpherical\n\n/**\n * Calculates the magnitude of a `Vector3`.\n *\n * @param vector - The vector to calculate the magnitude of.\n * @returns The magnitude of the vector.\n * @since 1.0.0\n */\nexport const magnitude: (vector: Vector3) => number = internal.magnitude\n\n/**\n * Calculates the length of a `Vector3`.\n *\n * @param vector - The vector to calculate the length of.\n * @returns The length of the vector.\n * @see {@link magnitude}\n * @since 1.0.0\n */\nexport const length: (vector: Vector3) => number = magnitude\n\n/**\n * Normalizes a `Vector3`.\n *\n * @param vector - The vector to normalize.\n * @returns A new `Vector3` instance with the same direction as the input vector, but with a magnitude of 1.\n * @since 1.0.0\n */\nexport const normalize: (vector: Vector3) => Vector3 = internal.normalize\n\nexport const dot: {\n /**\n * Calculates the dot product of two `Vector3` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns The dot product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): number\n /**\n * Calculates the dot product of two `Vector3` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the dot product.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => number\n} = internal.dot\n\nexport const cross: {\n /**\n * Calculates the cross product of two `Vector3` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector3` instance representing the cross product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Calculates the cross product of two `Vector3` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the cross product.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.cross\n\n/**\n * Returns the components of a `Vector3` as an array.\n *\n * @param v - The vector to get the components of.\n * @returns An array containing the x, y, and z components of the vector.\n * @since 1.0.0\n */\nexport const components: (v: Vector3) => [number, number, number] = internal.components\n\n/**\n * Calculates the softmax of a `Vector3`.\n *\n * @param v - The vector to calculate the softmax of.\n * @returns A new `Vector3` instance representing the softmax of the input vector.\n * @since 1.0.0\n */\nexport const softmax: (v: Vector3) => Vector3 = internal.softmax\n\n/**\n * Creates a zero vector.\n *\n * @since 1.0.0\n */\nexport const zero = make(0)\n\n/**\n * Creates a unit vector.\n *\n * @since 1.0.0\n */\nexport const unit = make(1)\n\n/**\n * Creates a unit vector in the x direction.\n *\n * @since 1.0.0\n */\nexport const unitX = make(1, 0, 0)\n\n/**\n * Creates a unit vector in the y direction.\n *\n * @since 1.0.0\n */\nexport const unitY = make(0, 1, 0)\n\n/**\n * Creates a unit vector in the z direction.\n *\n * @since 1.0.0\n */\nexport const unitZ = make(0, 0, 1)\n\nexport const add: {\n /**\n * Adds two `Vector3` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector3` instance representing the sum of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Adds two `Vector3` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the sum.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.add\n\nexport const subtract: {\n /**\n * Subtracts one `Vector3` instance from another.\n *\n * @param a - The vector to subtract from.\n * @param b - The vector to subtract.\n * @returns A new `Vector3` instance representing the difference of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Subtracts one `Vector3` instance from another.\n *\n * @param b - The vector to subtract.\n * @returns A function that takes the first vector and returns the difference.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.subtract\n\nexport const hadamard: {\n /**\n * Calculates the Hadamard product of two `Vector3` instances.\n *\n * The Hadamard product is an element-wise multiplication of two vectors.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector3` instance representing the Hadamard product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Calculates the Hadamard product of two `Vector3` instances.\n *\n * The Hadamard product is an element-wise multiplication of two vectors.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the Hadamard product.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.hadamard\n\nexport const scale: {\n /**\n * Scales a `Vector3` instance by a scalar value.\n *\n * @param s - The scalar value to scale by.\n * @return A function that takes a vector and returns the scaled vector.\n * @since 1.0.0\n */\n (s: number): (v: Vector3) => Vector3\n /**\n * Scales a `Vector3` instance by a scalar value.\n *\n * @param s - The scalar value to scale by.\n * @param v - The vector to scale.\n * @returns A new `Vector3` instance representing the scaled vector.\n * @since 1.0.0\n */\n (v: Vector3, s: number): Vector3\n} = internal.scale\n\n/**\n * Gets the x component of a `Vector3`.\n *\n * @param v - The vector to get the x component of.\n * @returns The x component of the vector.\n * @since 1.0.0\n */\nexport const getX: (v: Vector3) => number = internal.getX\n\nexport const setX: {\n /**\n * Sets the x component of a `Vector3`.\n *\n * @param v - The vector to set the x component of.\n * @param x - The new x component.\n * @returns A new `Vector3` instance with the updated x component.\n * @since 1.0.0\n */\n (v: Vector3, x: number): Vector3\n /**\n * Sets the x component of a `Vector3`.\n *\n * @param x - The new x component.\n * @returns A function that takes the vector and returns a new `Vector3` instance with the updated x component.\n * @since 1.0.0\n */\n (x: number): (v: Vector3) => Vector3\n} = internal.setX\n\nexport const mapX: {\n /**\n * Returns a new `Vector3` with the x component replaced by `f(v.x)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the x component.\n * @returns A new `Vector3` with the updated x.\n * @since 2.0.0\n */\n (v: Vector3, f: (x: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the x component replaced by `f(v.x)`.\n *\n * @param f - The function to apply to the x component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (x: number) => number): (v: Vector3) => Vector3\n} = internal.mapX\n\n/**\n * Gets the y component of a `Vector3`.\n *\n * @param v - The vector of which to get the y component.\n * @returns The y component of the vector.\n * @since 1.0.0\n */\nexport const getY: (v: Vector3) => number = internal.getY\n\nexport const setY: {\n /**\n * Sets the y component of a `Vector3`.\n *\n * @param v - The vector of which to set the y component.\n * @param y - The new y component.\n * @returns A new `Vector3` instance with the updated y component.\n * @since 1.0.0\n */\n (v: Vector3, y: number): Vector3\n /**\n * Sets the y component of a `Vector3`.\n *\n * @param y - The new y component.\n * @returns A function that takes the vector and returns a new `Vector3` instance with the updated y component.\n * @since 1.0.0\n */\n (y: number): (v: Vector3) => Vector3\n} = internal.setY\n\nexport const mapY: {\n /**\n * Returns a new `Vector3` with the y component replaced by `f(v.y)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the y component.\n * @returns A new `Vector3` with the updated y.\n * @since 2.0.0\n */\n (v: Vector3, f: (y: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the y component replaced by `f(v.y)`.\n *\n * @param f - The function to apply to the y component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (y: number) => number): (v: Vector3) => Vector3\n} = internal.mapY\n\n/**\n * Gets the z component of a `Vector3`.\n *\n * @param v - The vector of which to get the z component.\n * @returns The z component of the vector.\n * @since 1.0.0\n */\nexport const getZ: (v: Vector3) => number = internal.getZ\n\nexport const setZ: {\n /**\n * Sets the z component of a `Vector3`.\n *\n * @param v - The vector of which to set the z component.\n * @param z - The new z component.\n * @returns A new `Vector3` instance with the updated z component.\n * @since 1.0.0\n */\n (v: Vector3, z: number): Vector3\n /**\n * Sets the z component of a `Vector3`.\n *\n * @param z - The new z component.\n * @returns A function that takes the vector and returns a new `Vector3` instance with the updated z component.\n * @since 1.0.0\n */\n (z: number): (v: Vector3) => Vector3\n} = internal.setZ\n\nexport const mapZ: {\n /**\n * Returns a new `Vector3` with the z component replaced by `f(v.z)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the z component.\n * @returns A new `Vector3` with the updated z.\n * @since 2.0.0\n */\n (v: Vector3, f: (z: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the z component replaced by `f(v.z)`.\n *\n * @param f - The function to apply to the z component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (z: number) => number): (v: Vector3) => Vector3\n} = internal.mapZ\n\n/**\n * Gets the radius of a `Vector3`.\n *\n * @param v - The vector of which to get the radius.\n * @returns The radius of the vector.\n * @since 1.0.0\n */\nexport const getR: (v: Vector3) => number = magnitude\n\nexport const setR: {\n /**\n * Sets the radius of a `Vector3`.\n *\n * @param v - The vector of which to set the radius.\n * @param r - The new radius.\n * @returns A new `Vector3` instance with the updated radius.\n * @since 1.0.0\n */\n (v: Vector3, r: number): Vector3\n /**\n * Sets the radius of a `Vector3`.\n *\n * @param r - The new radius.\n * @returns A function that takes the vector and returns the updated vector.\n * @since 1.0.0\n */\n (r: number): (v: Vector3) => Vector3\n} = internal.setR\n\nexport const mapR: {\n /**\n * Returns a new `Vector3` with the radius replaced by `f(magnitude(v))`,\n * preserving direction.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the radius.\n * @returns A new `Vector3` with the updated radius.\n * @since 2.0.0\n */\n (v: Vector3, f: (r: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the radius replaced by `f(magnitude(v))`,\n * preserving direction.\n *\n * @param f - The function to apply to the radius.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (r: number) => number): (v: Vector3) => Vector3\n} = internal.mapR\n\n/**\n * Gets the polar angle (theta) of a `Vector3`.\n *\n * @param v - The vector of which to get the polar angle.\n * @returns The polar angle of the vector.\n * @since 1.0.0\n */\nexport const getTheta: (v: Vector3) => number = internal.getTheta\n\nexport const setTheta: {\n /**\n * Sets the polar angle (theta) of a `Vector3`.\n *\n * @param v - The vector of which to set the polar angle.\n * @param theta - The new polar angle.\n * @returns A new `Vector3` instance with the updated polar angle.\n * @since 1.0.0\n */\n (v: Vector3, theta: number): Vector3\n /**\n * Sets the polar angle (theta) of a `Vector3`.\n *\n * @param theta - The new polar angle.\n * @returns A function that takes the vector and returns the updated vector.\n * @since 1.0.0\n */\n (theta: number): (v: Vector3) => Vector3\n} = internal.setTheta\n\nexport const mapTheta: {\n /**\n * Returns a new `Vector3` with the polar angle replaced by\n * `f(getTheta(v))`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the polar angle (in radians).\n * @returns A new `Vector3` with the updated polar angle.\n * @since 2.0.0\n */\n (v: Vector3, f: (theta: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the polar angle replaced by\n * `f(getTheta(v))`.\n *\n * @param f - The function to apply to the polar angle (in radians).\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (theta: number) => number): (v: Vector3) => Vector3\n} = internal.mapTheta\n\n/**\n * Gets the azimuthal angle (phi) of a `Vector3`.\n *\n * @param v - The vector of which to get the azimuthal angle.\n * @returns The azimuthal angle of the vector.\n * @since 1.0.0\n */\nexport const getPhi: (v: Vector3) => number = internal.getPhi\n\nexport const setPhi: {\n /**\n * Sets the azimuthal angle (phi) of a `Vector3`.\n *\n * @param v - The vector of which to set the azimuthal angle.\n * @param phi - The new azimuthal angle.\n * @returns A new `Vector3` instance with the updated azimuthal angle.\n * @since 1.0.0\n */\n (v: Vector3, phi: number): Vector3\n /**\n * Sets the azimuthal angle (phi) of a `Vector3`.\n *\n * @param phi - The new azimuthal angle.\n * @returns A function that takes the vector and returns the updated vector.\n * @since 1.0.0\n */\n (phi: number): (v: Vector3) => Vector3\n} = internal.setPhi\n\nexport const mapPhi: {\n /**\n * Returns a new `Vector3` with the azimuthal angle replaced by\n * `f(getPhi(v))`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the azimuthal angle (in radians).\n * @returns A new `Vector3` with the updated azimuthal angle.\n * @since 2.0.0\n */\n (v: Vector3, f: (phi: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the azimuthal angle replaced by\n * `f(getPhi(v))`.\n *\n * @param f - The function to apply to the azimuthal angle (in radians).\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (phi: number) => number): (v: Vector3) => Vector3\n} = internal.mapPhi\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,YAA0CA;AAEvD,MAAa,SAoBTC;AAEJ,MAAa,OA4BTC;;;;;;;;;AAUJ,MAAa,YAA+DC;;;;;;;;;;;AAY5E,MAAa,YAGsCC;;;;;;;;;;AAWnD,MAAa,gBACXC;;;;;;;;AASF,MAAa,YAAyCC;;;;;;;;;AAUtD,MAAa,SAAsC;;;;;;;;AASnD,MAAa,YAA0CC;AAEvD,MAAa,MAkBTC;AAEJ,MAAa,QAkBTC;;;;;;;;AASJ,MAAa,aAAuDC;;;;;;;;AASpE,MAAa,UAAmCC;;;;;;AAOhD,MAAa,OAAO,KAAK,EAAE;;;;;;AAO3B,MAAa,OAAO,KAAK,EAAE;;;;;;AAO3B,MAAa,QAAQ,KAAK,GAAG,GAAG,EAAE;;;;;;AAOlC,MAAa,QAAQ,KAAK,GAAG,GAAG,EAAE;;;;;;AAOlC,MAAa,QAAQ,KAAK,GAAG,GAAG,EAAE;AAElC,MAAa,MAkBTC;AAEJ,MAAa,WAkBTC;AAEJ,MAAa,WAsBTC;AAEJ,MAAa,QAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+B;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAoBTC;;;;;;;;AASJ,MAAa,WAAmCC;AAEhD,MAAa,WAkBTC;AAEJ,MAAa,WAoBTC;;;;;;;;AASJ,MAAa,SAAiCC;AAE9C,MAAa,SAkBTC;AAEJ,MAAa,SAoBTC"}
|
|
1
|
+
{"version":3,"file":"vector3-oxtggkDp.mjs","names":["internal.isVector3","internal.equals","internal.make","internal.fromTuple","internal.transpose","internal.fromSpherical","internal.magnitude","internal.normalize","internal.dot","internal.cross","internal.components","internal.softmax","internal.add","internal.subtract","internal.hadamard","internal.scale","internal.getX","internal.setX","internal.mapX","internal.getY","internal.setY","internal.mapY","internal.getZ","internal.setZ","internal.mapZ","internal.setR","internal.mapR","internal.getTheta","internal.setTheta","internal.mapTheta","internal.getPhi","internal.setPhi","internal.mapPhi"],"sources":["../../src/vector/vector3.ts"],"sourcesContent":["import type { ThreeDimensional } from '../dimensions.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector3TypeId } from './vector3.internal.ts'\nimport * as internal from './vector3.internal.ts'\n\n/**\n * A 3D vector.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 1.0.0\n */\nexport interface Vector3 extends Pipeable, ThreeDimensional<number> {\n readonly [Vector3TypeId]: Vector3TypeId\n}\n\n/**\n * Checks if a value is a `Vector3`.\n *\n * @param v - The value to check.\n * @returns `true` if the value is a `Vector3`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isVector3: (v: unknown) => v is Vector3 = internal.isVector3\n\nexport const equals: {\n /**\n * Checks if two `Vector3` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns `true` when each pair of components is within tolerance.\n * @since 1.1.0\n */\n (a: Vector3, b: Vector3): boolean\n /**\n * Checks if two `Vector3` instances are approximately equal within the\n * default absolute tolerance ({@link EPSILON}).\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the comparison result.\n * @since 1.1.0\n */\n (b: Vector3): (a: Vector3) => boolean\n} = internal.equals\n\nexport const make: {\n /**\n * Creates a new `Vector3` instance.\n *\n * @param xyz - The x, y, and z components of the vector.\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\n (xyz: number): Vector3\n /**\n * Creates a new `Vector3` instance.\n *\n * @param x - The x component of the vector.\n * @param yz - The y and z components of the vector.\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\n (x: number, yz: number): Vector3\n /**\n * Creates a new `Vector3` instance.\n *\n * @param x - The x component of the vector.\n * @param y - The y component of the vector.\n * @param z - The z component of the vector.\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\n (x: number, y: number, z: number): Vector3\n} = internal.make\n\n/**\n * Creates a new `Vector3` instance from a `[x, y, z]` tuple. Inverse of\n * {@link components}.\n *\n * @param t - The `[x, y, z]` tuple.\n * @returns A new `Vector3` instance.\n * @since 2.0.0\n */\nexport const fromTuple: (t: readonly [number, number, number]) => Vector3 = internal.fromTuple\n\n/**\n * Transposes a 3-tuple of items into one or more `Vector3`s, one per channel\n * extracted by the projection function. See {@link Vector4.transpose} for the\n * full operation description; this is the 3-component analog.\n *\n * @param inputs - Exactly three items of any type.\n * @param project - A function returning a fixed-arity tuple of numbers — one per output channel.\n * @returns A tuple of `Vector3`s with the same arity as the projection's return tuple.\n * @since 2.0.0\n */\nexport const transpose: <T, const Channels extends ReadonlyArray<number>>(\n inputs: readonly [T, T, T],\n project: (item: T) => Channels,\n) => { readonly [K in keyof Channels]: Vector3 } = internal.transpose\n\n/**\n * Creates a new `Vector3` instance from spherical coordinates.\n *\n * @param r - The radius.\n * @param theta - The polar angle, in radians. Ranges from 0 to π\n * @param phi - The azimuthal angle, in radians. Ranges from 0 to 2π\n * @returns A new `Vector3` instance.\n * @since 1.0.0\n */\nexport const fromSpherical: (r: number, theta: number, phi: number) => Vector3 =\n internal.fromSpherical\n\n/**\n * Calculates the magnitude of a `Vector3`.\n *\n * @param vector - The vector to calculate the magnitude of.\n * @returns The magnitude of the vector.\n * @since 1.0.0\n */\nexport const magnitude: (vector: Vector3) => number = internal.magnitude\n\n/**\n * Calculates the length of a `Vector3`.\n *\n * @param vector - The vector to calculate the length of.\n * @returns The length of the vector.\n * @see {@link magnitude}\n * @since 1.0.0\n */\nexport const length: (vector: Vector3) => number = magnitude\n\n/**\n * Normalizes a `Vector3`.\n *\n * @param vector - The vector to normalize.\n * @returns A new `Vector3` instance with the same direction as the input vector, but with a magnitude of 1.\n * @since 1.0.0\n */\nexport const normalize: (vector: Vector3) => Vector3 = internal.normalize\n\nexport const dot: {\n /**\n * Calculates the dot product of two `Vector3` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns The dot product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): number\n /**\n * Calculates the dot product of two `Vector3` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the dot product.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => number\n} = internal.dot\n\nexport const cross: {\n /**\n * Calculates the cross product of two `Vector3` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector3` instance representing the cross product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Calculates the cross product of two `Vector3` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the cross product.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.cross\n\n/**\n * Returns the components of a `Vector3` as an array.\n *\n * @param v - The vector to get the components of.\n * @returns An array containing the x, y, and z components of the vector.\n * @since 1.0.0\n */\nexport const components: (v: Vector3) => [number, number, number] = internal.components\n\n/**\n * Calculates the softmax of a `Vector3`.\n *\n * @param v - The vector to calculate the softmax of.\n * @returns A new `Vector3` instance representing the softmax of the input vector.\n * @since 1.0.0\n */\nexport const softmax: (v: Vector3) => Vector3 = internal.softmax\n\n/**\n * Creates a zero vector.\n *\n * @since 1.0.0\n */\nexport const zero = make(0)\n\n/**\n * Creates a unit vector.\n *\n * @since 1.0.0\n */\nexport const unit = make(1)\n\n/**\n * Creates a unit vector in the x direction.\n *\n * @since 1.0.0\n */\nexport const unitX = make(1, 0, 0)\n\n/**\n * Creates a unit vector in the y direction.\n *\n * @since 1.0.0\n */\nexport const unitY = make(0, 1, 0)\n\n/**\n * Creates a unit vector in the z direction.\n *\n * @since 1.0.0\n */\nexport const unitZ = make(0, 0, 1)\n\nexport const add: {\n /**\n * Adds two `Vector3` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector3` instance representing the sum of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Adds two `Vector3` instances.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the sum.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.add\n\nexport const subtract: {\n /**\n * Subtracts one `Vector3` instance from another.\n *\n * @param a - The vector to subtract from.\n * @param b - The vector to subtract.\n * @returns A new `Vector3` instance representing the difference of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Subtracts one `Vector3` instance from another.\n *\n * @param b - The vector to subtract.\n * @returns A function that takes the first vector and returns the difference.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.subtract\n\nexport const hadamard: {\n /**\n * Calculates the Hadamard product of two `Vector3` instances.\n *\n * The Hadamard product is an element-wise multiplication of two vectors.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector3` instance representing the Hadamard product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector3, b: Vector3): Vector3\n /**\n * Calculates the Hadamard product of two `Vector3` instances.\n *\n * The Hadamard product is an element-wise multiplication of two vectors.\n *\n * @param b - The second vector.\n * @returns A function that takes the first vector and returns the Hadamard product.\n * @since 1.0.0\n */\n (b: Vector3): (a: Vector3) => Vector3\n} = internal.hadamard\n\nexport const scale: {\n /**\n * Scales a `Vector3` instance by a scalar value.\n *\n * @param s - The scalar value to scale by.\n * @return A function that takes a vector and returns the scaled vector.\n * @since 1.0.0\n */\n (s: number): (v: Vector3) => Vector3\n /**\n * Scales a `Vector3` instance by a scalar value.\n *\n * @param s - The scalar value to scale by.\n * @param v - The vector to scale.\n * @returns A new `Vector3` instance representing the scaled vector.\n * @since 1.0.0\n */\n (v: Vector3, s: number): Vector3\n} = internal.scale\n\n/**\n * Gets the x component of a `Vector3`.\n *\n * @param v - The vector to get the x component of.\n * @returns The x component of the vector.\n * @since 1.0.0\n */\nexport const getX: (v: Vector3) => number = internal.getX\n\nexport const setX: {\n /**\n * Sets the x component of a `Vector3`.\n *\n * @param v - The vector to set the x component of.\n * @param x - The new x component.\n * @returns A new `Vector3` instance with the updated x component.\n * @since 1.0.0\n */\n (v: Vector3, x: number): Vector3\n /**\n * Sets the x component of a `Vector3`.\n *\n * @param x - The new x component.\n * @returns A function that takes the vector and returns a new `Vector3` instance with the updated x component.\n * @since 1.0.0\n */\n (x: number): (v: Vector3) => Vector3\n} = internal.setX\n\nexport const mapX: {\n /**\n * Returns a new `Vector3` with the x component replaced by `f(v.x)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the x component.\n * @returns A new `Vector3` with the updated x.\n * @since 2.0.0\n */\n (v: Vector3, f: (x: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the x component replaced by `f(v.x)`.\n *\n * @param f - The function to apply to the x component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (x: number) => number): (v: Vector3) => Vector3\n} = internal.mapX\n\n/**\n * Gets the y component of a `Vector3`.\n *\n * @param v - The vector of which to get the y component.\n * @returns The y component of the vector.\n * @since 1.0.0\n */\nexport const getY: (v: Vector3) => number = internal.getY\n\nexport const setY: {\n /**\n * Sets the y component of a `Vector3`.\n *\n * @param v - The vector of which to set the y component.\n * @param y - The new y component.\n * @returns A new `Vector3` instance with the updated y component.\n * @since 1.0.0\n */\n (v: Vector3, y: number): Vector3\n /**\n * Sets the y component of a `Vector3`.\n *\n * @param y - The new y component.\n * @returns A function that takes the vector and returns a new `Vector3` instance with the updated y component.\n * @since 1.0.0\n */\n (y: number): (v: Vector3) => Vector3\n} = internal.setY\n\nexport const mapY: {\n /**\n * Returns a new `Vector3` with the y component replaced by `f(v.y)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the y component.\n * @returns A new `Vector3` with the updated y.\n * @since 2.0.0\n */\n (v: Vector3, f: (y: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the y component replaced by `f(v.y)`.\n *\n * @param f - The function to apply to the y component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (y: number) => number): (v: Vector3) => Vector3\n} = internal.mapY\n\n/**\n * Gets the z component of a `Vector3`.\n *\n * @param v - The vector of which to get the z component.\n * @returns The z component of the vector.\n * @since 1.0.0\n */\nexport const getZ: (v: Vector3) => number = internal.getZ\n\nexport const setZ: {\n /**\n * Sets the z component of a `Vector3`.\n *\n * @param v - The vector of which to set the z component.\n * @param z - The new z component.\n * @returns A new `Vector3` instance with the updated z component.\n * @since 1.0.0\n */\n (v: Vector3, z: number): Vector3\n /**\n * Sets the z component of a `Vector3`.\n *\n * @param z - The new z component.\n * @returns A function that takes the vector and returns a new `Vector3` instance with the updated z component.\n * @since 1.0.0\n */\n (z: number): (v: Vector3) => Vector3\n} = internal.setZ\n\nexport const mapZ: {\n /**\n * Returns a new `Vector3` with the z component replaced by `f(v.z)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the z component.\n * @returns A new `Vector3` with the updated z.\n * @since 2.0.0\n */\n (v: Vector3, f: (z: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the z component replaced by `f(v.z)`.\n *\n * @param f - The function to apply to the z component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (z: number) => number): (v: Vector3) => Vector3\n} = internal.mapZ\n\n/**\n * Gets the radius of a `Vector3`.\n *\n * @param v - The vector of which to get the radius.\n * @returns The radius of the vector.\n * @since 1.0.0\n */\nexport const getR: (v: Vector3) => number = magnitude\n\nexport const setR: {\n /**\n * Sets the radius of a `Vector3`.\n *\n * @param v - The vector of which to set the radius.\n * @param r - The new radius.\n * @returns A new `Vector3` instance with the updated radius.\n * @since 1.0.0\n */\n (v: Vector3, r: number): Vector3\n /**\n * Sets the radius of a `Vector3`.\n *\n * @param r - The new radius.\n * @returns A function that takes the vector and returns the updated vector.\n * @since 1.0.0\n */\n (r: number): (v: Vector3) => Vector3\n} = internal.setR\n\nexport const mapR: {\n /**\n * Returns a new `Vector3` with the radius replaced by `f(magnitude(v))`,\n * preserving direction.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the radius.\n * @returns A new `Vector3` with the updated radius.\n * @since 2.0.0\n */\n (v: Vector3, f: (r: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the radius replaced by `f(magnitude(v))`,\n * preserving direction.\n *\n * @param f - The function to apply to the radius.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (r: number) => number): (v: Vector3) => Vector3\n} = internal.mapR\n\n/**\n * Gets the polar angle (theta) of a `Vector3`.\n *\n * @param v - The vector of which to get the polar angle.\n * @returns The polar angle of the vector.\n * @since 1.0.0\n */\nexport const getTheta: (v: Vector3) => number = internal.getTheta\n\nexport const setTheta: {\n /**\n * Sets the polar angle (theta) of a `Vector3`.\n *\n * @param v - The vector of which to set the polar angle.\n * @param theta - The new polar angle.\n * @returns A new `Vector3` instance with the updated polar angle.\n * @since 1.0.0\n */\n (v: Vector3, theta: number): Vector3\n /**\n * Sets the polar angle (theta) of a `Vector3`.\n *\n * @param theta - The new polar angle.\n * @returns A function that takes the vector and returns the updated vector.\n * @since 1.0.0\n */\n (theta: number): (v: Vector3) => Vector3\n} = internal.setTheta\n\nexport const mapTheta: {\n /**\n * Returns a new `Vector3` with the polar angle replaced by\n * `f(getTheta(v))`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the polar angle (in radians).\n * @returns A new `Vector3` with the updated polar angle.\n * @since 2.0.0\n */\n (v: Vector3, f: (theta: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the polar angle replaced by\n * `f(getTheta(v))`.\n *\n * @param f - The function to apply to the polar angle (in radians).\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (theta: number) => number): (v: Vector3) => Vector3\n} = internal.mapTheta\n\n/**\n * Gets the azimuthal angle (phi) of a `Vector3`.\n *\n * @param v - The vector of which to get the azimuthal angle.\n * @returns The azimuthal angle of the vector.\n * @since 1.0.0\n */\nexport const getPhi: (v: Vector3) => number = internal.getPhi\n\nexport const setPhi: {\n /**\n * Sets the azimuthal angle (phi) of a `Vector3`.\n *\n * @param v - The vector of which to set the azimuthal angle.\n * @param phi - The new azimuthal angle.\n * @returns A new `Vector3` instance with the updated azimuthal angle.\n * @since 1.0.0\n */\n (v: Vector3, phi: number): Vector3\n /**\n * Sets the azimuthal angle (phi) of a `Vector3`.\n *\n * @param phi - The new azimuthal angle.\n * @returns A function that takes the vector and returns the updated vector.\n * @since 1.0.0\n */\n (phi: number): (v: Vector3) => Vector3\n} = internal.setPhi\n\nexport const mapPhi: {\n /**\n * Returns a new `Vector3` with the azimuthal angle replaced by\n * `f(getPhi(v))`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the azimuthal angle (in radians).\n * @returns A new `Vector3` with the updated azimuthal angle.\n * @since 2.0.0\n */\n (v: Vector3, f: (phi: number) => number): Vector3\n /**\n * Returns a new `Vector3` with the azimuthal angle replaced by\n * `f(getPhi(v))`.\n *\n * @param f - The function to apply to the azimuthal angle (in radians).\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (phi: number) => number): (v: Vector3) => Vector3\n} = internal.mapPhi\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,YAA0CA;AAEvD,MAAa,SAoBTC;AAEJ,MAAa,OA4BTC;;;;;;;;;AAUJ,MAAa,YAA+DC;;;;;;;;;;;AAY5E,MAAa,YAGsCC;;;;;;;;;;AAWnD,MAAa,gBACXC;;;;;;;;AASF,MAAa,YAAyCC;;;;;;;;;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"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Pipeable, dual } from "../utils.mjs";
|
|
2
|
+
import { coincident } from "../number.mjs";
|
|
3
|
+
//#region src/vector/vector3.internal.ts
|
|
4
|
+
const Vector3TypeId = Symbol.for("curvy/vector3");
|
|
5
|
+
var Vector3Impl = class extends Pipeable {
|
|
6
|
+
[Vector3TypeId] = Vector3TypeId;
|
|
7
|
+
x;
|
|
8
|
+
y;
|
|
9
|
+
z;
|
|
10
|
+
constructor(v0 = 0, v1 = 0, v2 = 0) {
|
|
11
|
+
super();
|
|
12
|
+
this.x = v0;
|
|
13
|
+
this.y = v1;
|
|
14
|
+
this.z = v2;
|
|
15
|
+
}
|
|
16
|
+
get [0]() {
|
|
17
|
+
return this.x;
|
|
18
|
+
}
|
|
19
|
+
get [1]() {
|
|
20
|
+
return this.y;
|
|
21
|
+
}
|
|
22
|
+
get [2]() {
|
|
23
|
+
return this.z;
|
|
24
|
+
}
|
|
25
|
+
get [Symbol.toStringTag]() {
|
|
26
|
+
return `Vector3(${this.x}, ${this.y}, ${this.z})`;
|
|
27
|
+
}
|
|
28
|
+
get [Symbol.for("nodejs.util.inspect.custom")]() {
|
|
29
|
+
return this[Symbol.toStringTag];
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/** @internal */
|
|
33
|
+
const isVector3 = (v) => typeof v === "object" && v !== null && Vector3TypeId in v;
|
|
34
|
+
/** @internal */
|
|
35
|
+
const equals = dual(2, (a, b) => coincident(a.x, b.x) && coincident(a.y, b.y) && coincident(a.z, b.z));
|
|
36
|
+
/** @internal */
|
|
37
|
+
const make = (v0, v1 = v0, v2 = v1) => new Vector3Impl(v0, v1, v2);
|
|
38
|
+
/** @internal */
|
|
39
|
+
const fromTuple = (t) => new Vector3Impl(t[0], t[1], t[2]);
|
|
40
|
+
/** @internal */
|
|
41
|
+
const transpose = (inputs, project) => {
|
|
42
|
+
const a = project(inputs[0]);
|
|
43
|
+
const b = project(inputs[1]);
|
|
44
|
+
const c = project(inputs[2]);
|
|
45
|
+
const result = [];
|
|
46
|
+
for (let i = 0; i < a.length; i++) result.push(make(a[i], b[i], c[i]));
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
/** @internal */
|
|
50
|
+
const fromSpherical = (r, theta, phi) => new Vector3Impl(r * Math.sin(theta) * Math.cos(phi), r * Math.sin(theta) * Math.sin(phi), r * Math.cos(theta));
|
|
51
|
+
/** @internal */
|
|
52
|
+
const magnitude = (vector) => Math.hypot(vector.x, vector.y, vector.z);
|
|
53
|
+
/** @internal */
|
|
54
|
+
const normalize = (vector) => {
|
|
55
|
+
const m = magnitude(vector);
|
|
56
|
+
return make(vector.x / m, vector.y / m, vector.z / m);
|
|
57
|
+
};
|
|
58
|
+
/** @internal */
|
|
59
|
+
const dot = dual(2, (a, b) => a.x * b.x + a.y * b.y + a.z * b.z);
|
|
60
|
+
/** @internal */
|
|
61
|
+
const cross = dual(2, (a, b) => {
|
|
62
|
+
return make(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
|
|
63
|
+
});
|
|
64
|
+
/** @internal */
|
|
65
|
+
const components = (v) => [
|
|
66
|
+
v.x,
|
|
67
|
+
v.y,
|
|
68
|
+
v.z
|
|
69
|
+
];
|
|
70
|
+
/** @internal */
|
|
71
|
+
const softmax = (v) => {
|
|
72
|
+
const max = Math.max(v.x, v.y, v.z);
|
|
73
|
+
const v0 = Math.exp(v.x - max);
|
|
74
|
+
const v1 = Math.exp(v.y - max);
|
|
75
|
+
const v2 = Math.exp(v.z - max);
|
|
76
|
+
const sum = v0 + v1 + v2;
|
|
77
|
+
return make(v0 / sum, v1 / sum, v2 / sum);
|
|
78
|
+
};
|
|
79
|
+
/** @internal */
|
|
80
|
+
const add = dual(2, (a, b) => make(a.x + b.x, a.y + b.y, a.z + b.z));
|
|
81
|
+
/** @internal */
|
|
82
|
+
const subtract = dual(2, (a, b) => make(a.x - b.x, a.y - b.y, a.z - b.z));
|
|
83
|
+
/** @internal */
|
|
84
|
+
const hadamard = dual(2, (a, b) => make(a.x * b.x, a.y * b.y, a.z * b.z));
|
|
85
|
+
/** @internal */
|
|
86
|
+
const scale = dual(2, (v, s) => s === 1 ? v : make(v.x * s, v.y * s, v.z * s));
|
|
87
|
+
/** @internal */
|
|
88
|
+
const getX = (v) => v.x;
|
|
89
|
+
/** @internal */
|
|
90
|
+
const setX = dual(2, (v, x) => make(x, v.y, v.z));
|
|
91
|
+
/** @internal */
|
|
92
|
+
const mapX = dual(2, (v, f) => make(f(v.x), v.y, v.z));
|
|
93
|
+
/** @internal */
|
|
94
|
+
const getY = (v) => v.y;
|
|
95
|
+
/** @internal */
|
|
96
|
+
const setY = dual(2, (v, y) => make(v.x, y, v.z));
|
|
97
|
+
/** @internal */
|
|
98
|
+
const mapY = dual(2, (v, f) => make(v.x, f(v.y), v.z));
|
|
99
|
+
/** @internal */
|
|
100
|
+
const getZ = (v) => v.z;
|
|
101
|
+
/** @internal */
|
|
102
|
+
const setZ = dual(2, (v, z) => make(v.x, v.y, z));
|
|
103
|
+
/** @internal */
|
|
104
|
+
const mapZ = dual(2, (v, f) => make(v.x, v.y, f(v.z)));
|
|
105
|
+
/** @internal */
|
|
106
|
+
const setR = dual(2, (v, r) => scale(r / magnitude(v))(v));
|
|
107
|
+
/** @internal */
|
|
108
|
+
const mapR = dual(2, (v, f) => {
|
|
109
|
+
const r = magnitude(v);
|
|
110
|
+
return scale(f(r) / r)(v);
|
|
111
|
+
});
|
|
112
|
+
/** @internal */
|
|
113
|
+
const getTheta = (v) => Math.acos(v.z / magnitude(v));
|
|
114
|
+
/** @internal */
|
|
115
|
+
const setTheta = dual(2, (v, theta) => {
|
|
116
|
+
const r = magnitude(v);
|
|
117
|
+
const phi = Math.atan2(v.y, v.x);
|
|
118
|
+
const sinTheta = Math.sin(theta);
|
|
119
|
+
return make(r * sinTheta * Math.cos(phi), r * sinTheta * Math.sin(phi), r * Math.cos(theta));
|
|
120
|
+
});
|
|
121
|
+
/** @internal */
|
|
122
|
+
const mapTheta = dual(2, (v, f) => setTheta(v, f(getTheta(v))));
|
|
123
|
+
/** @internal */
|
|
124
|
+
const getPhi = (v) => Math.atan2(v.y, v.x);
|
|
125
|
+
/** @internal */
|
|
126
|
+
const setPhi = dual(2, (v, phi) => {
|
|
127
|
+
const rho = Math.hypot(v.x, v.y);
|
|
128
|
+
return make(rho * Math.cos(phi), rho * Math.sin(phi), v.z);
|
|
129
|
+
});
|
|
130
|
+
/** @internal */
|
|
131
|
+
const mapPhi = dual(2, (v, f) => setPhi(v, f(getPhi(v))));
|
|
132
|
+
//#endregion
|
|
133
|
+
export { setZ as A, normalize as C, setTheta as D, setR as E, subtract as M, transpose as N, setX as O, mapZ as S, setPhi as T, mapPhi as _, equals as a, mapX as b, getPhi as c, getY as d, getZ as f, make as g, magnitude as h, dot as i, softmax as j, setY as k, getTheta as l, isVector3 as m, components as n, fromSpherical as o, hadamard as p, cross as r, fromTuple as s, add as t, getX as u, mapR as v, scale as w, mapY as x, mapTheta as y };
|
|
134
|
+
|
|
135
|
+
//# sourceMappingURL=vector3.internal-CfWHl9SG.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector3.internal-CfWHl9SG.mjs","names":[],"sources":["../../src/vector/vector3.internal.ts"],"sourcesContent":["import { dual, Pipeable } from '../utils.ts'\nimport { coincident } from '../number.ts'\nimport type { Vector3 } from './vector3.ts'\n\nexport const Vector3TypeId: unique symbol = Symbol.for('curvy/vector3')\nexport type Vector3TypeId = typeof Vector3TypeId\n\nclass Vector3Impl extends Pipeable implements Vector3 {\n readonly [Vector3TypeId]: Vector3TypeId = Vector3TypeId\n\n readonly x: number\n readonly y: number\n readonly z: number\n\n constructor(v0 = 0, v1 = 0, v2 = 0) {\n super()\n this.x = v0\n this.y = v1\n this.z = v2\n }\n\n get [0]() {\n return this.x\n }\n\n get [1]() {\n return this.y\n }\n\n get [2]() {\n return this.z\n }\n\n get [Symbol.toStringTag]() {\n return `Vector3(${this.x}, ${this.y}, ${this.z})`\n }\n\n get [Symbol.for('nodejs.util.inspect.custom')]() {\n return this[Symbol.toStringTag]\n }\n}\n\n/** @internal */\nexport const isVector3 = (v: unknown): v is Vector3 =>\n typeof v === 'object' && v !== null && Vector3TypeId in v\n\n/** @internal */\nexport const equals = dual<\n (b: Vector3) => (a: Vector3) => boolean,\n (a: Vector3, b: Vector3) => boolean\n>(\n 2,\n (a: Vector3, b: Vector3) => coincident(a.x, b.x) && coincident(a.y, b.y) && coincident(a.z, b.z),\n)\n\n/** @internal */\nexport const make = (v0: number, v1 = v0, v2 = v1): Vector3 => new Vector3Impl(v0, v1, v2)\n\n/** @internal */\nexport const fromTuple = (t: readonly [number, number, number]): Vector3 =>\n new Vector3Impl(t[0], t[1], t[2])\n\n/** @internal */\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 } => {\n const a = project(inputs[0])\n const b = project(inputs[1])\n const c = project(inputs[2])\n const result: Array<Vector3> = []\n for (let i = 0; i < a.length; i++) {\n result.push(make(a[i] as number, b[i] as number, c[i] as number))\n }\n return result as never\n}\n\n/** @internal */\nexport const fromSpherical = (r: number, theta: number, phi: number) =>\n new Vector3Impl(\n r * Math.sin(theta) * Math.cos(phi),\n r * Math.sin(theta) * Math.sin(phi),\n r * Math.cos(theta),\n )\n\n/** @internal */\nexport const magnitude = (vector: Vector3) => Math.hypot(vector.x, vector.y, vector.z)\n\n/** @internal */\nexport const normalize = (vector: Vector3) => {\n const m = magnitude(vector)\n\n return make(vector.x / m, vector.y / m, vector.z / m)\n}\n\n/** @internal */\nexport const dot = dual<(b: Vector3) => (a: Vector3) => number, (a: Vector3, b: Vector3) => number>(\n 2,\n (a: Vector3, b: Vector3) => a.x * b.x + a.y * b.y + a.z * b.z,\n)\n\n/** @internal */\nexport const cross = dual<\n (b: Vector3) => (a: Vector3) => Vector3,\n (a: Vector3, b: Vector3) => Vector3\n>(2, (a: Vector3, b: Vector3) => {\n const x = a.y * b.z - a.z * b.y\n const y = a.z * b.x - a.x * b.z\n const z = a.x * b.y - a.y * b.x\n\n return make(x, y, z)\n})\n\n/** @internal */\nexport const components: (v: Vector3) => [number, number, number] = (v: Vector3) => [v.x, v.y, v.z]\n\n/** @internal */\nexport const softmax = (v: Vector3) => {\n const max = Math.max(v.x, v.y, v.z)\n\n const v0 = Math.exp(v.x - max)\n const v1 = Math.exp(v.y - max)\n const v2 = Math.exp(v.z - max)\n\n const sum = v0 + v1 + v2\n\n return make(v0 / sum, v1 / sum, v2 / sum)\n}\n\n/** @internal */\nexport const add = dual<\n (b: Vector3) => (a: Vector3) => Vector3,\n (a: Vector3, b: Vector3) => Vector3\n>(2, (a: Vector3, b: Vector3) => make(a.x + b.x, a.y + b.y, a.z + b.z))\n\n/** @internal */\nexport const subtract = dual<\n (b: Vector3) => (a: Vector3) => Vector3,\n (a: Vector3, b: Vector3) => Vector3\n>(2, (a: Vector3, b: Vector3) => make(a.x - b.x, a.y - b.y, a.z - b.z))\n\n/** @internal */\nexport const hadamard = dual<\n (b: Vector3) => (a: Vector3) => Vector3,\n (a: Vector3, b: Vector3) => Vector3\n>(2, (a: Vector3, b: Vector3) => make(a.x * b.x, a.y * b.y, a.z * b.z))\n\n/** @internal */\nexport const scale = dual<\n (s: number) => (v: Vector3) => Vector3,\n (v: Vector3, s: number) => Vector3\n>(2, (v: Vector3, s: number) => (s === 1 ? v : make(v.x * s, v.y * s, v.z * s)))\n\n/** @internal */\nexport const getX: (v: Vector3) => number = (v: Vector3) => v.x\n/** @internal */\nexport const setX = dual<\n (x: number) => (v: Vector3) => Vector3,\n (v: Vector3, x: number) => Vector3\n>(2, (v: Vector3, x: number) => make(x, v.y, v.z))\n\n/** @internal */\nexport const mapX = dual<\n (f: (x: number) => number) => (v: Vector3) => Vector3,\n (v: Vector3, f: (x: number) => number) => Vector3\n>(2, (v: Vector3, f: (x: number) => number) => make(f(v.x), v.y, v.z))\n\n/** @internal */\nexport const getY: (v: Vector3) => number = (v: Vector3) => v.y\n/** @internal */\nexport const setY = dual<\n (y: number) => (v: Vector3) => Vector3,\n (v: Vector3, y: number) => Vector3\n>(2, (v: Vector3, y: number) => make(v.x, y, v.z))\n\n/** @internal */\nexport const mapY = dual<\n (f: (y: number) => number) => (v: Vector3) => Vector3,\n (v: Vector3, f: (y: number) => number) => Vector3\n>(2, (v: Vector3, f: (y: number) => number) => make(v.x, f(v.y), v.z))\n\n/** @internal */\nexport const getZ: (v: Vector3) => number = (v: Vector3) => v.z\n/** @internal */\nexport const setZ = dual<\n (z: number) => (v: Vector3) => Vector3,\n (v: Vector3, z: number) => Vector3\n>(2, (v: Vector3, z: number) => make(v.x, v.y, z))\n\n/** @internal */\nexport const mapZ = dual<\n (f: (z: number) => number) => (v: Vector3) => Vector3,\n (v: Vector3, f: (z: number) => number) => Vector3\n>(2, (v: Vector3, f: (z: number) => number) => make(v.x, v.y, f(v.z)))\n\n/** @internal */\nexport const setR = dual<\n (r: number) => (v: Vector3) => Vector3,\n (v: Vector3, r: number) => Vector3\n>(2, (v: Vector3, r: number) => scale(r / magnitude(v))(v))\n\n/** @internal */\nexport const mapR = dual<\n (f: (r: number) => number) => (v: Vector3) => Vector3,\n (v: Vector3, f: (r: number) => number) => Vector3\n>(2, (v: Vector3, f: (r: number) => number) => {\n const r = magnitude(v)\n return scale(f(r) / r)(v)\n})\n\n/** @internal */\nexport const getTheta = (v: Vector3) => Math.acos(v.z / magnitude(v))\n/** @internal */\nexport const setTheta = dual<\n (theta: number) => (v: Vector3) => Vector3,\n (v: Vector3, theta: number) => Vector3\n>(2, (v: Vector3, theta: number) => {\n const r = magnitude(v)\n const phi = Math.atan2(v.y, v.x)\n const sinTheta = Math.sin(theta)\n return make(r * sinTheta * Math.cos(phi), r * sinTheta * Math.sin(phi), r * Math.cos(theta))\n})\n\n/** @internal */\nexport const mapTheta = dual<\n (f: (theta: number) => number) => (v: Vector3) => Vector3,\n (v: Vector3, f: (theta: number) => number) => Vector3\n>(2, (v: Vector3, f: (theta: number) => number) => setTheta(v, f(getTheta(v))))\n\n/** @internal */\nexport const getPhi = (v: Vector3) => Math.atan2(v.y, v.x)\n// setPhi rotates only in the xy plane: preserve z and the xy-projection\n// length ρ = r·sin(θ) = hypot(v.x, v.y). That keeps both r and θ invariant.\n/** @internal */\nexport const setPhi = dual<\n (phi: number) => (v: Vector3) => Vector3,\n (v: Vector3, phi: number) => Vector3\n>(2, (v: Vector3, phi: number) => {\n const rho = Math.hypot(v.x, v.y)\n return make(rho * Math.cos(phi), rho * Math.sin(phi), v.z)\n})\n\n/** @internal */\nexport const mapPhi = dual<\n (f: (phi: number) => number) => (v: Vector3) => Vector3,\n (v: Vector3, f: (phi: number) => number) => Vector3\n>(2, (v: Vector3, f: (phi: number) => number) => setPhi(v, f(getPhi(v))))\n"],"mappings":"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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-25Hzd3z8.mjs";
|
|
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-
|
|
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-DH5DzNYO.mjs";
|
|
3
3
|
//#region src/vector/vector4.ts
|
|
4
4
|
var vector4_exports = /* @__PURE__ */ __exportAll({
|
|
5
5
|
add: () => add,
|
|
@@ -168,4 +168,4 @@ const mapW = mapW$1;
|
|
|
168
168
|
//#endregion
|
|
169
169
|
export { transpose as n, vector4_exports as r, make as t };
|
|
170
170
|
|
|
171
|
-
//# sourceMappingURL=vector4-
|
|
171
|
+
//# sourceMappingURL=vector4-DGHuCvTV.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector4-PO_7EYd-.mjs","names":["internal.isVector4","internal.equals","internal.make","internal.fromTuple","internal.transpose","internal.magnitude","internal.normalize","internal.dot","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.getW","internal.setW","internal.mapW"],"sources":["../../src/vector/vector4.ts"],"sourcesContent":["import type { FourDimensional } from '../dimensions.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector4TypeId } from './vector4.internal.ts'\nimport * as internal from './vector4.internal.ts'\n\n/**\n * A 4D vector.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 1.0.0\n */\nexport interface Vector4 extends Pipeable, FourDimensional<number> {\n readonly [Vector4TypeId]: Vector4TypeId\n}\n\n/**\n * Checks if a value is a `Vector4`.\n *\n * @param v - The value to check.\n * @returns `true` if the value is a `Vector4`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isVector4: (v: unknown) => v is Vector4 = internal.isVector4\n\nexport const equals: {\n /**\n * Checks if two `Vector4` 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: Vector4, b: Vector4): boolean\n /**\n * Checks if two `Vector4` 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: Vector4): (a: Vector4) => boolean\n} = internal.equals\n\nexport const make: {\n /**\n * Creates a new `Vector4` instance.\n *\n * @param xyzw - The x, y, z, and w components of the vector.\n * @returns A new `Vector4` instance.\n * @since 1.0.0\n */\n (xyzw: number): Vector4\n /**\n * Creates a new `Vector4` instance.\n *\n * @param x - The x component of the vector.\n * @param yzw - The y, z, and w components of the vector.\n * @returns A new `Vector4` instance.\n * @since 1.0.0\n */\n (x: number, yzw: number): Vector4\n /**\n * Creates a new `Vector4` instance.\n *\n * @param x - The x component of the vector.\n * @param y - The y component of the vector.\n * @param zw - The z and w components of the vector.\n * @returns A new `Vector4` instance.\n * @since 1.0.0\n */\n (x: number, y: number, zw: number): Vector4\n /**\n * Creates a new `Vector4` 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 * @param w - The w component of the vector.\n * @returns A new `Vector4` instance.\n * @since 1.0.0\n */\n (x: number, y: number, z: number, w: number): Vector4\n} = internal.make\n\n/**\n * Creates a new `Vector4` instance from a `[x, y, z, w]` tuple. Inverse of\n * {@link components}.\n *\n * @param t - The `[x, y, z, w]` tuple.\n * @returns A new `Vector4` instance.\n * @since 2.0.0\n */\nexport const fromTuple: (t: readonly [number, number, number, number]) => Vector4 =\n internal.fromTuple\n\n/**\n * Transposes a 4-tuple of items into one or more `Vector4`s, one per channel\n * extracted by the projection function.\n *\n * For each output channel, takes the corresponding number from each of the\n * four projected items and packs them into a `Vector4` — the data-layout\n * transformation NumPy calls a transpose, FP calls `unzip`, GPUs call a\n * gather, and DSP people inexplicably call deinterleaving.\n *\n * The projection's return-tuple arity determines the number of output\n * vectors, and that arity is preserved in the return type.\n *\n * @example\n * ```ts\n * // Pack the x and y coordinates of four control points into two Vector4s.\n * const [xs, ys] = Vector4.transpose(\n * [p0, p1, p2, p3],\n * (p) => [p.x, p.y],\n * )\n * ```\n *\n * @param inputs - Exactly four 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 `Vector4`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, T],\n project: (item: T) => Channels,\n) => { readonly [K in keyof Channels]: Vector4 } = internal.transpose\n\n/**\n * Gets the magnitude of a `Vector4`.\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: Vector4) => number = internal.magnitude\n\n/**\n * Normalizes a `Vector4`.\n *\n * @param vector - The vector to normalize.\n * @returns A new `Vector4` 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: Vector4) => Vector4 = internal.normalize\n\nexport const dot: {\n /**\n * Computes the dot product of two `Vector4` 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: Vector4, b: Vector4): number\n /**\n * Computes the dot product of a `Vector4` instance and another vector.\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: Vector4): (a: Vector4) => number\n} = internal.dot\n\n/**\n * Returns the components of a `Vector4` as an array.\n *\n * @param v - The vector to get the components of.\n * @returns An array containing the x, y, z, and w components of the vector.\n * @since 1.0.0\n */\nexport const components: (v: Vector4) => [number, number, number, number] = internal.components\n\n/**\n * Applies the softmax function to a `Vector4`.\n *\n * @param v - The vector to calculate the softmax of.\n * @returns A new `Vector4` instance representing the softmax of the input vector.\n */\nexport const softmax: (v: Vector4) => Vector4 = 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\nexport const add: {\n /**\n * Adds two `Vector4` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector4` instance representing the sum of the two vectors.\n * @since 1.0.0\n */\n (a: Vector4, b: Vector4): Vector4\n\n /**\n * Adds a `Vector4` instance to another vector.\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: Vector4): (a: Vector4) => Vector4\n} = internal.add\n\nexport const subtract: {\n /**\n * Subtracts one `Vector4` instance from another.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector4` instance representing the difference of the two vectors.\n * @since 1.0.0\n */\n (a: Vector4, b: Vector4): Vector4\n /**\n * Subtracts a `Vector4` instance from another vector.\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: Vector4): (a: Vector4) => Vector4\n} = internal.subtract\n\nexport const hadamard: {\n /**\n * Computes the Hadamard product of two `Vector4` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector4` instance representing the Hadamard product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector4, b: Vector4): Vector4\n /**\n * Computes the Hadamard product of a `Vector4` instance and another vector.\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: Vector4): (a: Vector4) => Vector4\n} = internal.hadamard\n\nexport const scale: {\n /**\n * Scales a `Vector4` by a scalar.\n *\n * @param s - The scalar to scale the vector by.\n * @returns A function that takes the vector and returns the scaled vector.\n * @since 1.0.0\n */\n (s: number): (v: Vector4) => Vector4\n /**\n * Scales a `Vector4` by a scalar.\n *\n * @param s - The scalar to scale the vector by.\n * @param v - The vector to scale.\n * @returns A new `Vector4` instance representing the scaled vector.\n * @since 1.0.0\n */\n (v: Vector4, s: number): Vector4\n} = internal.scale\n\n/**\n * Gets the x component of a `Vector4`.\n *\n * @param v - The vector to get the x component of.\n * @returns The x component of the vector.\n * @since 2.0.0\n */\nexport const getX: (v: Vector4) => number = internal.getX\n\nexport const setX: {\n /**\n * Sets the x component of a `Vector4`.\n *\n * @param v - The vector to set the x component of.\n * @param x - The new x component.\n * @returns A new `Vector4` instance with the updated x component.\n * @since 2.0.0\n */\n (v: Vector4, x: number): Vector4\n /**\n * Sets the x component of a `Vector4`.\n *\n * @param x - The new x component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (x: number): (v: Vector4) => Vector4\n} = internal.setX\n\nexport const mapX: {\n /**\n * Returns a new `Vector4` 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 `Vector4` with the updated x.\n * @since 2.0.0\n */\n (v: Vector4, f: (x: number) => number): Vector4\n /**\n * Returns a new `Vector4` 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: Vector4) => Vector4\n} = internal.mapX\n\n/**\n * Gets the y component of a `Vector4`.\n *\n * @param v - The vector to get the y component of.\n * @returns The y component of the vector.\n * @since 2.0.0\n */\nexport const getY: (v: Vector4) => number = internal.getY\n\nexport const setY: {\n /**\n * Sets the y component of a `Vector4`.\n *\n * @param v - The vector to set the y component of.\n * @param y - The new y component.\n * @returns A new `Vector4` instance with the updated y component.\n * @since 2.0.0\n */\n (v: Vector4, y: number): Vector4\n /**\n * Sets the y component of a `Vector4`.\n *\n * @param y - The new y component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (y: number): (v: Vector4) => Vector4\n} = internal.setY\n\nexport const mapY: {\n /**\n * Returns a new `Vector4` 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 `Vector4` with the updated y.\n * @since 2.0.0\n */\n (v: Vector4, f: (y: number) => number): Vector4\n /**\n * Returns a new `Vector4` 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: Vector4) => Vector4\n} = internal.mapY\n\n/**\n * Gets the z component of a `Vector4`.\n *\n * @param v - The vector to get the z component of.\n * @returns The z component of the vector.\n * @since 2.0.0\n */\nexport const getZ: (v: Vector4) => number = internal.getZ\n\nexport const setZ: {\n /**\n * Sets the z component of a `Vector4`.\n *\n * @param v - The vector to set the z component of.\n * @param z - The new z component.\n * @returns A new `Vector4` instance with the updated z component.\n * @since 2.0.0\n */\n (v: Vector4, z: number): Vector4\n /**\n * Sets the z component of a `Vector4`.\n *\n * @param z - The new z component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (z: number): (v: Vector4) => Vector4\n} = internal.setZ\n\nexport const mapZ: {\n /**\n * Returns a new `Vector4` 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 `Vector4` with the updated z.\n * @since 2.0.0\n */\n (v: Vector4, f: (z: number) => number): Vector4\n /**\n * Returns a new `Vector4` 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: Vector4) => Vector4\n} = internal.mapZ\n\n/**\n * Gets the w component of a `Vector4`.\n *\n * @param v - The vector to get the w component of.\n * @returns The w component of the vector.\n * @since 2.0.0\n */\nexport const getW: (v: Vector4) => number = internal.getW\n\nexport const setW: {\n /**\n * Sets the w component of a `Vector4`.\n *\n * @param v - The vector to set the w component of.\n * @param w - The new w component.\n * @returns A new `Vector4` instance with the updated w component.\n * @since 2.0.0\n */\n (v: Vector4, w: number): Vector4\n /**\n * Sets the w component of a `Vector4`.\n *\n * @param w - The new w component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (w: number): (v: Vector4) => Vector4\n} = internal.setW\n\nexport const mapW: {\n /**\n * Returns a new `Vector4` with the w component replaced by `f(v.w)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the w component.\n * @returns A new `Vector4` with the updated w.\n * @since 2.0.0\n */\n (v: Vector4, f: (w: number) => number): Vector4\n /**\n * Returns a new `Vector4` with the w component replaced by `f(v.w)`.\n *\n * @param f - The function to apply to the w component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (w: number) => number): (v: Vector4) => Vector4\n} = internal.mapW\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,YAA0CA;AAEvD,MAAa,SAoBTC;AAEJ,MAAa,OAuCTC;;;;;;;;;AAUJ,MAAa,YACXC;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BF,MAAa,YAGsCC;;;;;;;;AASnD,MAAa,YAAyCC;;;;;;;;AAStD,MAAa,YAA0CC;AAEvD,MAAa,MAkBTC;;;;;;;;AASJ,MAAa,aAA+DC;;;;;;;AAQ5E,MAAa,UAAmCC;;;;;;AAOhD,MAAa,OAAO,KAAK,EAAE;;;;;;AAO3B,MAAa,OAAO,KAAK,EAAE;AAE3B,MAAa,MAmBTC;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+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC"}
|
|
1
|
+
{"version":3,"file":"vector4-DGHuCvTV.mjs","names":["internal.isVector4","internal.equals","internal.make","internal.fromTuple","internal.transpose","internal.magnitude","internal.normalize","internal.dot","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.getW","internal.setW","internal.mapW"],"sources":["../../src/vector/vector4.ts"],"sourcesContent":["import type { FourDimensional } from '../dimensions.ts'\nimport type { Pipeable } from '../utils.ts'\nimport type { Vector4TypeId } from './vector4.internal.ts'\nimport * as internal from './vector4.internal.ts'\n\n/**\n * A 4D vector.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 1.0.0\n */\nexport interface Vector4 extends Pipeable, FourDimensional<number> {\n readonly [Vector4TypeId]: Vector4TypeId\n}\n\n/**\n * Checks if a value is a `Vector4`.\n *\n * @param v - The value to check.\n * @returns `true` if the value is a `Vector4`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isVector4: (v: unknown) => v is Vector4 = internal.isVector4\n\nexport const equals: {\n /**\n * Checks if two `Vector4` 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: Vector4, b: Vector4): boolean\n /**\n * Checks if two `Vector4` 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: Vector4): (a: Vector4) => boolean\n} = internal.equals\n\nexport const make: {\n /**\n * Creates a new `Vector4` instance.\n *\n * @param xyzw - The x, y, z, and w components of the vector.\n * @returns A new `Vector4` instance.\n * @since 1.0.0\n */\n (xyzw: number): Vector4\n /**\n * Creates a new `Vector4` instance.\n *\n * @param x - The x component of the vector.\n * @param yzw - The y, z, and w components of the vector.\n * @returns A new `Vector4` instance.\n * @since 1.0.0\n */\n (x: number, yzw: number): Vector4\n /**\n * Creates a new `Vector4` instance.\n *\n * @param x - The x component of the vector.\n * @param y - The y component of the vector.\n * @param zw - The z and w components of the vector.\n * @returns A new `Vector4` instance.\n * @since 1.0.0\n */\n (x: number, y: number, zw: number): Vector4\n /**\n * Creates a new `Vector4` 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 * @param w - The w component of the vector.\n * @returns A new `Vector4` instance.\n * @since 1.0.0\n */\n (x: number, y: number, z: number, w: number): Vector4\n} = internal.make\n\n/**\n * Creates a new `Vector4` instance from a `[x, y, z, w]` tuple. Inverse of\n * {@link components}.\n *\n * @param t - The `[x, y, z, w]` tuple.\n * @returns A new `Vector4` instance.\n * @since 2.0.0\n */\nexport const fromTuple: (t: readonly [number, number, number, number]) => Vector4 =\n internal.fromTuple\n\n/**\n * Transposes a 4-tuple of items into one or more `Vector4`s, one per channel\n * extracted by the projection function.\n *\n * For each output channel, takes the corresponding number from each of the\n * four projected items and packs them into a `Vector4` — the data-layout\n * transformation NumPy calls a transpose, FP calls `unzip`, GPUs call a\n * gather, and DSP people inexplicably call deinterleaving.\n *\n * The projection's return-tuple arity determines the number of output\n * vectors, and that arity is preserved in the return type.\n *\n * @example\n * ```ts\n * // Pack the x and y coordinates of four control points into two Vector4s.\n * const [xs, ys] = Vector4.transpose(\n * [p0, p1, p2, p3],\n * (p) => [p.x, p.y],\n * )\n * ```\n *\n * @param inputs - Exactly four 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 `Vector4`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, T],\n project: (item: T) => Channels,\n) => { readonly [K in keyof Channels]: Vector4 } = internal.transpose\n\n/**\n * Gets the magnitude of a `Vector4`.\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: Vector4) => number = internal.magnitude\n\n/**\n * Normalizes a `Vector4`.\n *\n * @param vector - The vector to normalize.\n * @returns A new `Vector4` 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: Vector4) => Vector4 = internal.normalize\n\nexport const dot: {\n /**\n * Computes the dot product of two `Vector4` 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: Vector4, b: Vector4): number\n /**\n * Computes the dot product of a `Vector4` instance and another vector.\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: Vector4): (a: Vector4) => number\n} = internal.dot\n\n/**\n * Returns the components of a `Vector4` as an array.\n *\n * @param v - The vector to get the components of.\n * @returns An array containing the x, y, z, and w components of the vector.\n * @since 1.0.0\n */\nexport const components: (v: Vector4) => [number, number, number, number] = internal.components\n\n/**\n * Applies the softmax function to a `Vector4`.\n *\n * @param v - The vector to calculate the softmax of.\n * @returns A new `Vector4` instance representing the softmax of the input vector.\n */\nexport const softmax: (v: Vector4) => Vector4 = 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\nexport const add: {\n /**\n * Adds two `Vector4` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector4` instance representing the sum of the two vectors.\n * @since 1.0.0\n */\n (a: Vector4, b: Vector4): Vector4\n\n /**\n * Adds a `Vector4` instance to another vector.\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: Vector4): (a: Vector4) => Vector4\n} = internal.add\n\nexport const subtract: {\n /**\n * Subtracts one `Vector4` instance from another.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector4` instance representing the difference of the two vectors.\n * @since 1.0.0\n */\n (a: Vector4, b: Vector4): Vector4\n /**\n * Subtracts a `Vector4` instance from another vector.\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: Vector4): (a: Vector4) => Vector4\n} = internal.subtract\n\nexport const hadamard: {\n /**\n * Computes the Hadamard product of two `Vector4` instances.\n *\n * @param a - The first vector.\n * @param b - The second vector.\n * @returns A new `Vector4` instance representing the Hadamard product of the two vectors.\n * @since 1.0.0\n */\n (a: Vector4, b: Vector4): Vector4\n /**\n * Computes the Hadamard product of a `Vector4` instance and another vector.\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: Vector4): (a: Vector4) => Vector4\n} = internal.hadamard\n\nexport const scale: {\n /**\n * Scales a `Vector4` by a scalar.\n *\n * @param s - The scalar to scale the vector by.\n * @returns A function that takes the vector and returns the scaled vector.\n * @since 1.0.0\n */\n (s: number): (v: Vector4) => Vector4\n /**\n * Scales a `Vector4` by a scalar.\n *\n * @param s - The scalar to scale the vector by.\n * @param v - The vector to scale.\n * @returns A new `Vector4` instance representing the scaled vector.\n * @since 1.0.0\n */\n (v: Vector4, s: number): Vector4\n} = internal.scale\n\n/**\n * Gets the x component of a `Vector4`.\n *\n * @param v - The vector to get the x component of.\n * @returns The x component of the vector.\n * @since 2.0.0\n */\nexport const getX: (v: Vector4) => number = internal.getX\n\nexport const setX: {\n /**\n * Sets the x component of a `Vector4`.\n *\n * @param v - The vector to set the x component of.\n * @param x - The new x component.\n * @returns A new `Vector4` instance with the updated x component.\n * @since 2.0.0\n */\n (v: Vector4, x: number): Vector4\n /**\n * Sets the x component of a `Vector4`.\n *\n * @param x - The new x component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (x: number): (v: Vector4) => Vector4\n} = internal.setX\n\nexport const mapX: {\n /**\n * Returns a new `Vector4` 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 `Vector4` with the updated x.\n * @since 2.0.0\n */\n (v: Vector4, f: (x: number) => number): Vector4\n /**\n * Returns a new `Vector4` 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: Vector4) => Vector4\n} = internal.mapX\n\n/**\n * Gets the y component of a `Vector4`.\n *\n * @param v - The vector to get the y component of.\n * @returns The y component of the vector.\n * @since 2.0.0\n */\nexport const getY: (v: Vector4) => number = internal.getY\n\nexport const setY: {\n /**\n * Sets the y component of a `Vector4`.\n *\n * @param v - The vector to set the y component of.\n * @param y - The new y component.\n * @returns A new `Vector4` instance with the updated y component.\n * @since 2.0.0\n */\n (v: Vector4, y: number): Vector4\n /**\n * Sets the y component of a `Vector4`.\n *\n * @param y - The new y component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (y: number): (v: Vector4) => Vector4\n} = internal.setY\n\nexport const mapY: {\n /**\n * Returns a new `Vector4` 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 `Vector4` with the updated y.\n * @since 2.0.0\n */\n (v: Vector4, f: (y: number) => number): Vector4\n /**\n * Returns a new `Vector4` 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: Vector4) => Vector4\n} = internal.mapY\n\n/**\n * Gets the z component of a `Vector4`.\n *\n * @param v - The vector to get the z component of.\n * @returns The z component of the vector.\n * @since 2.0.0\n */\nexport const getZ: (v: Vector4) => number = internal.getZ\n\nexport const setZ: {\n /**\n * Sets the z component of a `Vector4`.\n *\n * @param v - The vector to set the z component of.\n * @param z - The new z component.\n * @returns A new `Vector4` instance with the updated z component.\n * @since 2.0.0\n */\n (v: Vector4, z: number): Vector4\n /**\n * Sets the z component of a `Vector4`.\n *\n * @param z - The new z component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (z: number): (v: Vector4) => Vector4\n} = internal.setZ\n\nexport const mapZ: {\n /**\n * Returns a new `Vector4` 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 `Vector4` with the updated z.\n * @since 2.0.0\n */\n (v: Vector4, f: (z: number) => number): Vector4\n /**\n * Returns a new `Vector4` 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: Vector4) => Vector4\n} = internal.mapZ\n\n/**\n * Gets the w component of a `Vector4`.\n *\n * @param v - The vector to get the w component of.\n * @returns The w component of the vector.\n * @since 2.0.0\n */\nexport const getW: (v: Vector4) => number = internal.getW\n\nexport const setW: {\n /**\n * Sets the w component of a `Vector4`.\n *\n * @param v - The vector to set the w component of.\n * @param w - The new w component.\n * @returns A new `Vector4` instance with the updated w component.\n * @since 2.0.0\n */\n (v: Vector4, w: number): Vector4\n /**\n * Sets the w component of a `Vector4`.\n *\n * @param w - The new w component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (w: number): (v: Vector4) => Vector4\n} = internal.setW\n\nexport const mapW: {\n /**\n * Returns a new `Vector4` with the w component replaced by `f(v.w)`.\n *\n * @param v - The vector to update.\n * @param f - The function to apply to the w component.\n * @returns A new `Vector4` with the updated w.\n * @since 2.0.0\n */\n (v: Vector4, f: (w: number) => number): Vector4\n /**\n * Returns a new `Vector4` with the w component replaced by `f(v.w)`.\n *\n * @param f - The function to apply to the w component.\n * @returns A function that takes a vector and returns the updated vector.\n * @since 2.0.0\n */\n (f: (w: number) => number): (v: Vector4) => Vector4\n} = internal.mapW\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,YAA0CA;AAEvD,MAAa,SAoBTC;AAEJ,MAAa,OAuCTC;;;;;;;;;AAUJ,MAAa,YACXC;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BF,MAAa,YAGsCC;;;;;;;;AASnD,MAAa,YAAyCC;;;;;;;;AAStD,MAAa,YAA0CC;AAEvD,MAAa,MAkBTC;;;;;;;;AASJ,MAAa,aAA+DC;;;;;;;AAQ5E,MAAa,UAAmCC;;;;;;AAOhD,MAAa,OAAO,KAAK,EAAE;;;;;;AAO3B,MAAa,OAAO,KAAK,EAAE;AAE3B,MAAa,MAmBTC;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+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;AAEJ,MAAa,OAkBTC"}
|