curvy 1.0.8 → 2.0.0-alpha.0
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.d.mts +88 -0
- package/dist/characteristic/index.mjs +2 -0
- package/dist/curve/index.d.mts +2 -0
- package/dist/curve/index.mjs +2 -0
- package/dist/interval/index.d.mts +2 -0
- package/dist/interval/index.mjs +2 -0
- package/dist/matrix/index.d.mts +2 -0
- package/dist/matrix/index.mjs +267 -0
- package/dist/matrix/index.mjs.map +1 -0
- package/dist/number.d.mts +280 -0
- package/dist/number.mjs +140 -0
- package/dist/number.mjs.map +1 -0
- package/dist/path/index.d.mts +241 -0
- package/dist/path/index.mjs +292 -0
- package/dist/path/index.mjs.map +1 -0
- package/dist/polynomial/index.d.mts +2 -0
- package/dist/polynomial/index.mjs +3 -0
- package/dist/shared/characteristic-BGRxcxUH.mjs +104 -0
- package/dist/shared/characteristic-BGRxcxUH.mjs.map +1 -0
- package/dist/shared/chunk-25Hzd3z8.mjs +13 -0
- package/dist/shared/cubic-CYYEUHNm.mjs +479 -0
- package/dist/shared/cubic-CYYEUHNm.mjs.map +1 -0
- package/dist/shared/cubic-Dfn6DB02.d.mts +1099 -0
- package/dist/shared/interval-CCEqzPgA.mjs +376 -0
- package/dist/shared/interval-CCEqzPgA.mjs.map +1 -0
- package/dist/shared/interval-hQDiKqj0.d.mts +494 -0
- package/dist/shared/matrix4x4-Bt_DBlP0.d.mts +1182 -0
- package/dist/shared/matrix4x4-Ck2WROK-.mjs +440 -0
- package/dist/shared/matrix4x4-Ck2WROK-.mjs.map +1 -0
- package/dist/shared/quadratic-DEhuAKuE.mjs +330 -0
- package/dist/shared/quadratic-DEhuAKuE.mjs.map +1 -0
- package/dist/shared/rationalCubic2d-BPLohNuI.d.mts +787 -0
- package/dist/shared/rationalCubic2d-CP4oGpnk.mjs +658 -0
- package/dist/shared/rationalCubic2d-CP4oGpnk.mjs.map +1 -0
- package/dist/shared/rationalCubic2d-CXa7Yren.mjs +278 -0
- package/dist/shared/rationalCubic2d-CXa7Yren.mjs.map +1 -0
- package/dist/shared/rationalCubic2d-D_-XWxcm.d.mts +297 -0
- package/dist/shared/solution-BjoW7ov4.d.mts +251 -0
- package/dist/shared/solution-CbSWzXCn.mjs +306 -0
- package/dist/shared/solution-CbSWzXCn.mjs.map +1 -0
- package/dist/{pipe.d.mts → shared/utils-DqTGyXrP.d.mts} +44 -26
- package/dist/shared/vector2-CL1HDdPr.mjs +187 -0
- package/dist/shared/vector2-CL1HDdPr.mjs.map +1 -0
- package/dist/shared/vector2-TV0UnlxY.d.mts +1168 -0
- package/dist/shared/vector2.internal-DU_E808S.mjs +97 -0
- package/dist/shared/vector2.internal-DU_E808S.mjs.map +1 -0
- package/dist/shared/vector3-D-tv_aKL.mjs +204 -0
- package/dist/shared/vector3-D-tv_aKL.mjs.map +1 -0
- package/dist/shared/vector4-5KbjoHVj.mjs +109 -0
- package/dist/shared/vector4-5KbjoHVj.mjs.map +1 -0
- package/dist/shared/vector4.internal-5XcaX12X.mjs +163 -0
- package/dist/shared/vector4.internal-5XcaX12X.mjs.map +1 -0
- package/dist/solution/index.d.mts +2 -0
- package/dist/solution/index.mjs +2 -0
- package/dist/splines/index.d.mts +701 -0
- package/dist/splines/index.mjs +734 -0
- package/dist/splines/index.mjs.map +1 -0
- package/dist/utils.d.mts +2 -27
- package/dist/utils.mjs +88 -43
- package/dist/utils.mjs.map +1 -0
- package/dist/vector/index.d.mts +2 -0
- package/dist/vector/index.mjs +4 -0
- package/package.json +49 -92
- package/dist/curve/cubic2d.d.mts +0 -31
- package/dist/curve/cubic2d.d.ts +0 -31
- package/dist/curve/cubic2d.mjs +0 -97
- package/dist/curve/linear2d.d.mts +0 -28
- package/dist/curve/linear2d.d.ts +0 -28
- package/dist/curve/linear2d.mjs +0 -49
- package/dist/curve/quadratic2d.d.mts +0 -33
- package/dist/curve/quadratic2d.d.ts +0 -33
- package/dist/curve/quadratic2d.mjs +0 -87
- package/dist/interval.d.mts +0 -58
- package/dist/interval.d.ts +0 -58
- package/dist/interval.mjs +0 -89
- package/dist/matrix/matrix2x2.d.mts +0 -49
- package/dist/matrix/matrix2x2.d.ts +0 -49
- package/dist/matrix/matrix2x2.mjs +0 -24
- package/dist/matrix/matrix3x3.d.mts +0 -63
- package/dist/matrix/matrix3x3.d.ts +0 -63
- package/dist/matrix/matrix3x3.mjs +0 -27
- package/dist/matrix/matrix4x4.d.mts +0 -72
- package/dist/matrix/matrix4x4.d.ts +0 -72
- package/dist/matrix/matrix4x4.mjs +0 -215
- package/dist/path/cubic2d.d.mts +0 -29
- package/dist/path/cubic2d.d.ts +0 -29
- package/dist/path/cubic2d.mjs +0 -62
- package/dist/path/linear2d.d.mts +0 -29
- package/dist/path/linear2d.d.ts +0 -29
- package/dist/path/linear2d.mjs +0 -55
- package/dist/path/quadratic2d.d.mts +0 -30
- package/dist/path/quadratic2d.d.ts +0 -30
- package/dist/path/quadratic2d.mjs +0 -61
- package/dist/pipe.d.ts +0 -58
- package/dist/pipe.mjs +0 -91
- package/dist/polynomial/cubic.d.mts +0 -7
- package/dist/polynomial/cubic.d.ts +0 -7
- package/dist/polynomial/cubic.mjs +0 -148
- package/dist/polynomial/linear.d.mts +0 -7
- package/dist/polynomial/linear.d.ts +0 -7
- package/dist/polynomial/linear.mjs +0 -23
- package/dist/polynomial/quadratic.d.mts +0 -7
- package/dist/polynomial/quadratic.d.ts +0 -7
- package/dist/polynomial/quadratic.mjs +0 -24
- package/dist/shared/curvy.BDhiZ7He.mjs +0 -80
- package/dist/shared/curvy.BZ_mTkJe.mjs +0 -60
- package/dist/shared/curvy.Bf5TIk31.d.mts +0 -22
- package/dist/shared/curvy.Bf5TIk31.d.ts +0 -22
- package/dist/shared/curvy.BsHoYJNv.d.ts +0 -155
- package/dist/shared/curvy.BzVmUIKm.mjs +0 -131
- package/dist/shared/curvy.C2XGH0R0.mjs +0 -75
- package/dist/shared/curvy.CE4X6_Is.mjs +0 -181
- package/dist/shared/curvy.Cps2R_RU.mjs +0 -120
- package/dist/shared/curvy.Cv-wIzDr.mjs +0 -124
- package/dist/shared/curvy.DmVFTi0N.mjs +0 -34
- package/dist/shared/curvy.NsmY7zcr.d.mts +0 -155
- package/dist/shared/curvy.wYJQhFW-.mjs +0 -87
- package/dist/splines/basis2d.d.mts +0 -38
- package/dist/splines/basis2d.d.ts +0 -38
- package/dist/splines/basis2d.mjs +0 -89
- package/dist/splines/bezier2d.d.mts +0 -48
- package/dist/splines/bezier2d.d.ts +0 -48
- package/dist/splines/bezier2d.mjs +0 -22
- package/dist/splines/cardinal2d.d.mts +0 -49
- package/dist/splines/cardinal2d.d.ts +0 -49
- package/dist/splines/cardinal2d.mjs +0 -123
- package/dist/splines/hermite2d.d.mts +0 -33
- package/dist/splines/hermite2d.d.ts +0 -33
- package/dist/splines/hermite2d.mjs +0 -77
- package/dist/utils.d.ts +0 -27
- package/dist/vector/vector2.d.mts +0 -66
- package/dist/vector/vector2.d.ts +0 -66
- package/dist/vector/vector2.mjs +0 -28
- package/dist/vector/vector3.d.mts +0 -77
- package/dist/vector/vector3.d.ts +0 -77
- package/dist/vector/vector3.mjs +0 -32
- package/dist/vector/vector4.d.mts +0 -43
- package/dist/vector/vector4.d.ts +0 -43
- package/dist/vector/vector4.mjs +0 -18
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Pipeable, dual, invariant } from "../utils.mjs";
|
|
2
|
+
import { epsEquals } from "../number.mjs";
|
|
3
|
+
//#region src/vector/vector2.internal.ts
|
|
4
|
+
const Vector2TypeId = Symbol.for("curvy/vector2");
|
|
5
|
+
const WeightedVector2TypeId = Symbol.for("curvy/vector2/weighted");
|
|
6
|
+
var Vector2Impl = class extends Pipeable {
|
|
7
|
+
[Vector2TypeId] = Vector2TypeId;
|
|
8
|
+
x;
|
|
9
|
+
y;
|
|
10
|
+
constructor(v0 = 0, v1 = 0) {
|
|
11
|
+
super();
|
|
12
|
+
this.x = v0;
|
|
13
|
+
this.y = v1;
|
|
14
|
+
}
|
|
15
|
+
get [0]() {
|
|
16
|
+
return this.x;
|
|
17
|
+
}
|
|
18
|
+
get [1]() {
|
|
19
|
+
return this.y;
|
|
20
|
+
}
|
|
21
|
+
get [Symbol.toStringTag]() {
|
|
22
|
+
return `Vector2(${this.x}, ${this.y})`;
|
|
23
|
+
}
|
|
24
|
+
get [Symbol.for("nodejs.util.inspect.custom")]() {
|
|
25
|
+
return this[Symbol.toStringTag];
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var WeightedImpl = class extends Pipeable {
|
|
29
|
+
[WeightedVector2TypeId] = WeightedVector2TypeId;
|
|
30
|
+
x;
|
|
31
|
+
y;
|
|
32
|
+
weight;
|
|
33
|
+
constructor(x, y, weight) {
|
|
34
|
+
super();
|
|
35
|
+
this.x = x;
|
|
36
|
+
this.y = y;
|
|
37
|
+
this.weight = weight;
|
|
38
|
+
}
|
|
39
|
+
get [Symbol.toStringTag]() {
|
|
40
|
+
return `Vector2.Weighted(${this.x}, ${this.y}, w=${this.weight})`;
|
|
41
|
+
}
|
|
42
|
+
get [Symbol.for("nodejs.util.inspect.custom")]() {
|
|
43
|
+
return this[Symbol.toStringTag];
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const isVector2 = (v) => typeof v === "object" && v !== null && Vector2TypeId in v;
|
|
47
|
+
const isWeighted = (v) => typeof v === "object" && v !== null && WeightedVector2TypeId in v;
|
|
48
|
+
const equals = dual(2, (a, b) => epsEquals(a.x, b.x) && epsEquals(a.y, b.y));
|
|
49
|
+
const make = (v0, v1 = v0) => new Vector2Impl(v0, v1);
|
|
50
|
+
const transpose = (inputs, project) => {
|
|
51
|
+
const a = project(inputs[0]);
|
|
52
|
+
const b = project(inputs[1]);
|
|
53
|
+
const result = [];
|
|
54
|
+
for (let i = 0; i < a.length; i++) result.push(make(a[i], b[i]));
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
const makeWeighted = (x, y, weight) => {
|
|
58
|
+
invariant(Number.isFinite(weight) && weight > 0, "Vector2.Weighted weight must be positive and finite");
|
|
59
|
+
return new WeightedImpl(x, y, weight);
|
|
60
|
+
};
|
|
61
|
+
const withWeight = dual(2, (v, weight) => makeWeighted(v.x, v.y, weight));
|
|
62
|
+
const unweighted = (w) => make(w.x, w.y);
|
|
63
|
+
const weightedEquals = dual(2, (a, b) => epsEquals(a.x, b.x) && epsEquals(a.y, b.y) && epsEquals(a.weight, b.weight));
|
|
64
|
+
const fromPolar = (r, theta) => make(r * Math.cos(theta), r * Math.sin(theta));
|
|
65
|
+
const components = (v) => [v.x, v.y];
|
|
66
|
+
const magnitude = (vector) => Math.hypot(vector.x, vector.y);
|
|
67
|
+
const normalize = (vector) => {
|
|
68
|
+
const m = magnitude(vector);
|
|
69
|
+
return make(vector.x / m, vector.y / m);
|
|
70
|
+
};
|
|
71
|
+
const dot = dual(2, (a, b) => a.x * b.x + a.y * b.y);
|
|
72
|
+
const cross = dual(2, (a, b) => a.x * b.y - a.y * b.x);
|
|
73
|
+
const softmax = (v) => {
|
|
74
|
+
const max = Math.max(v.x, v.y);
|
|
75
|
+
const v0 = Math.exp(v.x - max);
|
|
76
|
+
const v1 = Math.exp(v.y - max);
|
|
77
|
+
const sum = v0 + v1;
|
|
78
|
+
return make(v0 / sum, v1 / sum);
|
|
79
|
+
};
|
|
80
|
+
const add = dual(2, (a, b) => make(a.x + b.x, a.y + b.y));
|
|
81
|
+
const subtract = dual(2, (a, b) => make(a.x - b.x, a.y - b.y));
|
|
82
|
+
const hadamard = dual(2, (a, b) => make(a.x * b.x, a.y * b.y));
|
|
83
|
+
const scale = dual(2, (v, s) => s === 1 ? v : make(v.x * s, v.y * s));
|
|
84
|
+
const getX = (v) => v.x;
|
|
85
|
+
const setX = dual(2, (v, x) => make(x, v.y));
|
|
86
|
+
const getY = (v) => v.y;
|
|
87
|
+
const setY = dual(2, (v, y) => make(v.x, y));
|
|
88
|
+
const setR = dual(2, (v, r) => scale(r / magnitude(v))(v));
|
|
89
|
+
const getTheta = (v) => Math.atan2(v.y, v.x);
|
|
90
|
+
const setTheta = dual(2, (v, theta) => {
|
|
91
|
+
const r = magnitude(v);
|
|
92
|
+
return make(r * Math.cos(theta), r * Math.sin(theta));
|
|
93
|
+
});
|
|
94
|
+
//#endregion
|
|
95
|
+
export { subtract as C, withWeight as D, weightedEquals as E, softmax as S, unweighted as T, scale as _, equals as a, setX as b, getX as c, isVector2 as d, isWeighted as f, normalize as g, makeWeighted as h, dot as i, getY as l, make as m, components as n, fromPolar as o, magnitude as p, cross as r, getTheta as s, add as t, hadamard as u, setR as v, transpose as w, setY as x, setTheta as y };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=vector2.internal-DU_E808S.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector2.internal-DU_E808S.mjs","names":[],"sources":["../../src/vector/vector2.internal.ts"],"sourcesContent":["import { dual, Pipeable } from '../utils'\nimport { invariant } from '../utils'\nimport { epsEquals } from '../number'\nimport type { Vector2, Weighted } from './vector2'\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\nexport const isVector2 = (v: unknown): v is Vector2 =>\n typeof v === 'object' && v !== null && Vector2TypeId in v\n\nexport const isWeighted = (v: unknown): v is Weighted =>\n typeof v === 'object' && v !== null && WeightedVector2TypeId in v\n\nexport const equals = dual<\n (b: Vector2) => (a: Vector2) => boolean,\n (a: Vector2, b: Vector2) => boolean\n>(2, (a: Vector2, b: Vector2) => epsEquals(a.x, b.x) && epsEquals(a.y, b.y))\n\nexport const make = (v0: number, v1 = v0): Vector2 => new Vector2Impl(v0, v1)\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 } => {\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\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\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\nexport const unweighted = (w: Weighted): Vector2 => make(w.x, w.y)\n\nexport const weightedEquals = dual<\n (b: Weighted) => (a: Weighted) => boolean,\n (a: Weighted, b: Weighted) => boolean\n>(\n 2,\n (a: Weighted, b: Weighted) =>\n epsEquals(a.x, b.x) && epsEquals(a.y, b.y) && epsEquals(a.weight, b.weight),\n)\n\nexport const fromPolar = (r: number, theta: number) =>\n make(r * Math.cos(theta), r * Math.sin(theta))\n\nexport const components = (v: Vector2): [number, number] => [v.x, v.y]\n\nexport const magnitude = (vector: Vector2) => Math.hypot(vector.x, vector.y)\n\nexport const normalize = (vector: Vector2) => {\n const m = magnitude(vector)\n\n return make(vector.x / m, vector.y / m)\n}\n\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\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\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\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\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\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\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\nexport const getX = (v: Vector2) => v.x\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\nexport const getY = (v: Vector2) => v.y\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\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\nexport const getTheta = (v: Vector2) => Math.atan2(v.y, v.x)\nexport const setTheta = dual<\n (theta: number) => (v: Vector2) => Vector2,\n (v: Vector2, theta: number) => Vector2\n>(2, (v: Vector2, theta: number) => {\n const r = magnitude(v)\n return make(r * Math.cos(theta), r * Math.sin(theta))\n})\n"],"mappings":"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"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-25Hzd3z8.mjs";
|
|
2
|
+
import { A as scale$1, C as getY$1, D as magnitude$1, E as isVector3$1, F as setY$1, I as setZ$1, L as softmax$1, M as setR$1, N as setTheta$1, O as make$1, P as setX$1, R as subtract$1, S as getX$1, T as hadamard$1, _ as dot$1, b as getPhi$1, g as cross$1, h as components$1, j as setPhi$1, k as normalize$1, m as add$1, v as equals$1, w as getZ$1, x as getTheta$1, y as fromSpherical$1, z as transpose$1 } from "./vector4.internal-5XcaX12X.mjs";
|
|
3
|
+
//#region src/vector/vector3.ts
|
|
4
|
+
var vector3_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
add: () => add,
|
|
6
|
+
components: () => components,
|
|
7
|
+
cross: () => cross,
|
|
8
|
+
dot: () => dot,
|
|
9
|
+
equals: () => equals,
|
|
10
|
+
fromSpherical: () => fromSpherical,
|
|
11
|
+
getPhi: () => getPhi,
|
|
12
|
+
getR: () => getR,
|
|
13
|
+
getTheta: () => getTheta,
|
|
14
|
+
getX: () => getX,
|
|
15
|
+
getY: () => getY,
|
|
16
|
+
getZ: () => getZ,
|
|
17
|
+
hadamard: () => hadamard,
|
|
18
|
+
isVector3: () => isVector3,
|
|
19
|
+
length: () => length,
|
|
20
|
+
magnitude: () => magnitude,
|
|
21
|
+
make: () => make,
|
|
22
|
+
normalize: () => normalize,
|
|
23
|
+
scale: () => scale,
|
|
24
|
+
setPhi: () => setPhi,
|
|
25
|
+
setR: () => setR,
|
|
26
|
+
setTheta: () => setTheta,
|
|
27
|
+
setX: () => setX,
|
|
28
|
+
setY: () => setY,
|
|
29
|
+
setZ: () => setZ,
|
|
30
|
+
softmax: () => softmax,
|
|
31
|
+
subtract: () => subtract,
|
|
32
|
+
transpose: () => transpose,
|
|
33
|
+
unit: () => unit,
|
|
34
|
+
unitX: () => unitX,
|
|
35
|
+
unitY: () => unitY,
|
|
36
|
+
unitZ: () => unitZ,
|
|
37
|
+
zero: () => zero
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Checks if a value is a `Vector3`.
|
|
41
|
+
*
|
|
42
|
+
* @param v - The value to check.
|
|
43
|
+
* @returns `true` if the value is a `Vector3`, `false` otherwise.
|
|
44
|
+
* @since 1.0.0
|
|
45
|
+
*/
|
|
46
|
+
const isVector3 = isVector3$1;
|
|
47
|
+
const equals = equals$1;
|
|
48
|
+
const make = make$1;
|
|
49
|
+
/**
|
|
50
|
+
* Transposes a 3-tuple of items into one or more `Vector3`s, one per channel
|
|
51
|
+
* extracted by the projection function. See {@link Vector4.transpose} for the
|
|
52
|
+
* full operation description; this is the 3-component analog.
|
|
53
|
+
*
|
|
54
|
+
* @param inputs - Exactly three items of any type.
|
|
55
|
+
* @param project - A function returning a fixed-arity tuple of numbers — one per output channel.
|
|
56
|
+
* @returns A tuple of `Vector3`s with the same arity as the projection's return tuple.
|
|
57
|
+
* @since 2.1.0
|
|
58
|
+
*/
|
|
59
|
+
const transpose = transpose$1;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a new `Vector3` instance from spherical coordinates.
|
|
62
|
+
*
|
|
63
|
+
* @param r - The radius.
|
|
64
|
+
* @param theta - The polar angle, in radians. Ranges from 0 to π
|
|
65
|
+
* @param phi - The azimuthal angle, in radians. Ranges from 0 to 2π
|
|
66
|
+
* @returns A new `Vector3` instance.
|
|
67
|
+
* @since 1.0.0
|
|
68
|
+
*/
|
|
69
|
+
const fromSpherical = fromSpherical$1;
|
|
70
|
+
/**
|
|
71
|
+
* Calculates the magnitude of a `Vector3`.
|
|
72
|
+
*
|
|
73
|
+
* @param vector - The vector to calculate the magnitude of.
|
|
74
|
+
* @returns The magnitude of the vector.
|
|
75
|
+
* @since 1.0.0
|
|
76
|
+
*/
|
|
77
|
+
const magnitude = magnitude$1;
|
|
78
|
+
/**
|
|
79
|
+
* Calculates the length of a `Vector3`.
|
|
80
|
+
*
|
|
81
|
+
* @param vector - The vector to calculate the length of.
|
|
82
|
+
* @returns The length of the vector.
|
|
83
|
+
* @see {@link magnitude}
|
|
84
|
+
* @since 1.0.0
|
|
85
|
+
*/
|
|
86
|
+
const length = magnitude;
|
|
87
|
+
/**
|
|
88
|
+
* Normalizes a `Vector3`.
|
|
89
|
+
*
|
|
90
|
+
* @param vector - The vector to normalize.
|
|
91
|
+
* @returns A new `Vector3` instance with the same direction as the input vector, but with a magnitude of 1.
|
|
92
|
+
* @since 1.0.0
|
|
93
|
+
*/
|
|
94
|
+
const normalize = normalize$1;
|
|
95
|
+
const dot = dot$1;
|
|
96
|
+
const cross = cross$1;
|
|
97
|
+
/**
|
|
98
|
+
* Returns the components of a `Vector3` as an array.
|
|
99
|
+
*
|
|
100
|
+
* @param v - The vector to get the components of.
|
|
101
|
+
* @returns An array containing the x, y, and z components of the vector.
|
|
102
|
+
* @since 1.0.0
|
|
103
|
+
*/
|
|
104
|
+
const components = components$1;
|
|
105
|
+
/**
|
|
106
|
+
* Calculates the softmax of a `Vector3`.
|
|
107
|
+
*
|
|
108
|
+
* @param v - The vector to calculate the softmax of.
|
|
109
|
+
* @returns A new `Vector3` instance representing the softmax of the input vector.
|
|
110
|
+
* @since 1.0.0
|
|
111
|
+
*/
|
|
112
|
+
const softmax = softmax$1;
|
|
113
|
+
/**
|
|
114
|
+
* Creates a zero vector.
|
|
115
|
+
*
|
|
116
|
+
* @since 1.0.0
|
|
117
|
+
*/
|
|
118
|
+
const zero = make(0);
|
|
119
|
+
/**
|
|
120
|
+
* Creates a unit vector.
|
|
121
|
+
*
|
|
122
|
+
* @since 1.0.0
|
|
123
|
+
*/
|
|
124
|
+
const unit = make(1);
|
|
125
|
+
/**
|
|
126
|
+
* Creates a unit vector in the x direction.
|
|
127
|
+
*
|
|
128
|
+
* @since 1.0.0
|
|
129
|
+
*/
|
|
130
|
+
const unitX = make(1, 0, 0);
|
|
131
|
+
/**
|
|
132
|
+
* Creates a unit vector in the y direction.
|
|
133
|
+
*
|
|
134
|
+
* @since 1.0.0
|
|
135
|
+
*/
|
|
136
|
+
const unitY = make(0, 1, 0);
|
|
137
|
+
/**
|
|
138
|
+
* Creates a unit vector in the z direction.
|
|
139
|
+
*
|
|
140
|
+
* @since 1.0.0
|
|
141
|
+
*/
|
|
142
|
+
const unitZ = make(0, 0, 1);
|
|
143
|
+
const add = add$1;
|
|
144
|
+
const subtract = subtract$1;
|
|
145
|
+
const hadamard = hadamard$1;
|
|
146
|
+
const scale = scale$1;
|
|
147
|
+
/**
|
|
148
|
+
* Gets the x component of a `Vector3`.
|
|
149
|
+
*
|
|
150
|
+
* @param v - The vector to get the x component of.
|
|
151
|
+
* @returns The x component of the vector.
|
|
152
|
+
* @since 1.0.0
|
|
153
|
+
*/
|
|
154
|
+
const getX = getX$1;
|
|
155
|
+
const setX = setX$1;
|
|
156
|
+
/**
|
|
157
|
+
* Gets the y component of a `Vector3`.
|
|
158
|
+
*
|
|
159
|
+
* @param v - The vector of which to get the y component.
|
|
160
|
+
* @returns The y component of the vector.
|
|
161
|
+
* @since 1.0.0
|
|
162
|
+
*/
|
|
163
|
+
const getY = getY$1;
|
|
164
|
+
const setY = setY$1;
|
|
165
|
+
/**
|
|
166
|
+
* Gets the z component of a `Vector3`.
|
|
167
|
+
*
|
|
168
|
+
* @param v - The vector of which to get the z component.
|
|
169
|
+
* @returns The z component of the vector.
|
|
170
|
+
* @since 1.0.0
|
|
171
|
+
*/
|
|
172
|
+
const getZ = getZ$1;
|
|
173
|
+
const setZ = setZ$1;
|
|
174
|
+
/**
|
|
175
|
+
* Gets the radius of a `Vector3`.
|
|
176
|
+
*
|
|
177
|
+
* @param v - The vector of which to get the radius.
|
|
178
|
+
* @returns The radius of the vector.
|
|
179
|
+
* @since 1.0.0
|
|
180
|
+
*/
|
|
181
|
+
const getR = magnitude;
|
|
182
|
+
const setR = setR$1;
|
|
183
|
+
/**
|
|
184
|
+
* Gets the polar angle (theta) of a `Vector3`.
|
|
185
|
+
*
|
|
186
|
+
* @param v - The vector of which to get the polar angle.
|
|
187
|
+
* @returns The polar angle of the vector.
|
|
188
|
+
* @since 1.0.0
|
|
189
|
+
*/
|
|
190
|
+
const getTheta = getTheta$1;
|
|
191
|
+
const setTheta = setTheta$1;
|
|
192
|
+
/**
|
|
193
|
+
* Gets the azimuthal angle (phi) of a `Vector3`.
|
|
194
|
+
*
|
|
195
|
+
* @param v - The vector of which to get the azimuthal angle.
|
|
196
|
+
* @returns The azimuthal angle of the vector.
|
|
197
|
+
* @since 1.0.0
|
|
198
|
+
*/
|
|
199
|
+
const getPhi = getPhi$1;
|
|
200
|
+
const setPhi = setPhi$1;
|
|
201
|
+
//#endregion
|
|
202
|
+
export { vector3_exports as n, make as t };
|
|
203
|
+
|
|
204
|
+
//# sourceMappingURL=vector3-D-tv_aKL.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector3-D-tv_aKL.mjs","names":["internal.isVector3","internal.equals","internal.make","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.getY","internal.setY","internal.getZ","internal.setZ","internal.setR","internal.getTheta","internal.setTheta","internal.getPhi","internal.setPhi"],"sources":["../../src/vector/vector3.ts"],"sourcesContent":["import type { ThreeDimensional } from '../dimensions'\nimport type { Pipeable } from '../utils'\nimport type { Vector3TypeId } from './vector3.internal'\nimport * as internal from './vector3.internal'\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 * 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.1.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\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\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\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\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\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,YAA0CA;AAEvD,MAAa,SAoBTC;AAEJ,MAAa,OA4BTC;;;;;;;;;;;AAYJ,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;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+BC;AAE5C,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,OAA+B;AAE5C,MAAa,OAkBTC;;;;;;;;AASJ,MAAa,WAAmCC;AAEhD,MAAa,WAkBTC;;;;;;;;AASJ,MAAa,SAAiCC;AAE9C,MAAa,SAkBTC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-25Hzd3z8.mjs";
|
|
2
|
+
import { a as hadamard$1, c as make$1, d as softmax$1, f as subtract$1, i as equals$1, l as normalize$1, n as components$1, o as isVector4$1, p as transpose$1, r as dot$1, s as magnitude$1, t as add$1, u as scale$1 } from "./vector4.internal-5XcaX12X.mjs";
|
|
3
|
+
//#region src/vector/vector4.ts
|
|
4
|
+
var vector4_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
add: () => add,
|
|
6
|
+
components: () => components,
|
|
7
|
+
dot: () => dot,
|
|
8
|
+
equals: () => equals,
|
|
9
|
+
hadamard: () => hadamard,
|
|
10
|
+
isVector4: () => isVector4,
|
|
11
|
+
magnitude: () => magnitude,
|
|
12
|
+
make: () => make,
|
|
13
|
+
normalize: () => normalize,
|
|
14
|
+
scale: () => scale,
|
|
15
|
+
softmax: () => softmax,
|
|
16
|
+
subtract: () => subtract,
|
|
17
|
+
transpose: () => transpose,
|
|
18
|
+
unit: () => unit,
|
|
19
|
+
zero: () => zero
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Checks if a value is a `Vector4`.
|
|
23
|
+
*
|
|
24
|
+
* @param v - The value to check.
|
|
25
|
+
* @returns `true` if the value is a `Vector4`, `false` otherwise.
|
|
26
|
+
* @since 1.0.0
|
|
27
|
+
*/
|
|
28
|
+
const isVector4 = isVector4$1;
|
|
29
|
+
const equals = equals$1;
|
|
30
|
+
const make = make$1;
|
|
31
|
+
/**
|
|
32
|
+
* Transposes a 4-tuple of items into one or more `Vector4`s, one per channel
|
|
33
|
+
* extracted by the projection function.
|
|
34
|
+
*
|
|
35
|
+
* For each output channel, takes the corresponding number from each of the
|
|
36
|
+
* four projected items and packs them into a `Vector4` — the data-layout
|
|
37
|
+
* transformation NumPy calls a transpose, FP calls `unzip`, GPUs call a
|
|
38
|
+
* gather, and DSP people inexplicably call deinterleaving.
|
|
39
|
+
*
|
|
40
|
+
* The projection's return-tuple arity determines the number of output
|
|
41
|
+
* vectors, and that arity is preserved in the return type.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* // Pack the x and y coordinates of four control points into two Vector4s.
|
|
46
|
+
* const [xs, ys] = Vector4.transpose(
|
|
47
|
+
* [p0, p1, p2, p3],
|
|
48
|
+
* (p) => [p.x, p.y],
|
|
49
|
+
* )
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @param inputs - Exactly four items of any type.
|
|
53
|
+
* @param project - A function returning a fixed-arity tuple of numbers — one per output channel.
|
|
54
|
+
* @returns A tuple of `Vector4`s with the same arity as the projection's return tuple.
|
|
55
|
+
* @since 2.1.0
|
|
56
|
+
*/
|
|
57
|
+
const transpose = transpose$1;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the magnitude of a `Vector4`.
|
|
60
|
+
*
|
|
61
|
+
* @param vector - The vector to calculate the magnitude of.
|
|
62
|
+
* @returns The magnitude of the vector.
|
|
63
|
+
* @since 1.0.0
|
|
64
|
+
*/
|
|
65
|
+
const magnitude = magnitude$1;
|
|
66
|
+
/**
|
|
67
|
+
* Normalizes a `Vector4`.
|
|
68
|
+
*
|
|
69
|
+
* @param vector - The vector to normalize.
|
|
70
|
+
* @returns A new `Vector4` instance with the same direction as the input vector but with a magnitude of 1.
|
|
71
|
+
* @since 1.0.0
|
|
72
|
+
*/
|
|
73
|
+
const normalize = normalize$1;
|
|
74
|
+
const dot = dot$1;
|
|
75
|
+
/**
|
|
76
|
+
* Returns the components of a `Vector4` as an array.
|
|
77
|
+
*
|
|
78
|
+
* @param v - The vector to get the components of.
|
|
79
|
+
* @returns An array containing the x, y, z, and w components of the vector.
|
|
80
|
+
* @since 1.0.0
|
|
81
|
+
*/
|
|
82
|
+
const components = components$1;
|
|
83
|
+
/**
|
|
84
|
+
* Applies the softmax function to a `Vector4`.
|
|
85
|
+
*
|
|
86
|
+
* @param v - The vector to calculate the softmax of.
|
|
87
|
+
* @returns A new `Vector4` instance representing the softmax of the input vector.
|
|
88
|
+
*/
|
|
89
|
+
const softmax = softmax$1;
|
|
90
|
+
/**
|
|
91
|
+
* Creates a zero vector.
|
|
92
|
+
*
|
|
93
|
+
* @since 1.0.0
|
|
94
|
+
*/
|
|
95
|
+
const zero = make(0);
|
|
96
|
+
/**
|
|
97
|
+
* Creates a unit vector.
|
|
98
|
+
*
|
|
99
|
+
* @since 1.0.0
|
|
100
|
+
*/
|
|
101
|
+
const unit = make(1);
|
|
102
|
+
const add = add$1;
|
|
103
|
+
const subtract = subtract$1;
|
|
104
|
+
const hadamard = hadamard$1;
|
|
105
|
+
const scale = scale$1;
|
|
106
|
+
//#endregion
|
|
107
|
+
export { transpose as n, vector4_exports as r, make as t };
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=vector4-5KbjoHVj.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector4-5KbjoHVj.mjs","names":["internal.isVector4","internal.equals","internal.make","internal.transpose","internal.magnitude","internal.normalize","internal.dot","internal.components","internal.softmax","internal.add","internal.subtract","internal.hadamard","internal.scale"],"sources":["../../src/vector/vector4.ts"],"sourcesContent":["import type { FourDimensional } from '../dimensions'\nimport type { Pipeable } from '../utils'\nimport type { Vector4TypeId } from './vector4.internal'\nimport * as internal from './vector4.internal'\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 * 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.1.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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,YAA0CA;AAEvD,MAAa,SAoBTC;AAEJ,MAAa,OAuCTC;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BJ,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"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { Pipeable, dual } from "../utils.mjs";
|
|
2
|
+
import { epsEquals } 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
|
+
const isVector3 = (v) => typeof v === "object" && v !== null && Vector3TypeId in v;
|
|
33
|
+
const equals$1 = dual(2, (a, b) => epsEquals(a.x, b.x) && epsEquals(a.y, b.y) && epsEquals(a.z, b.z));
|
|
34
|
+
const make$1 = (v0, v1 = v0, v2 = v1) => new Vector3Impl(v0, v1, v2);
|
|
35
|
+
const transpose$1 = (inputs, project) => {
|
|
36
|
+
const a = project(inputs[0]);
|
|
37
|
+
const b = project(inputs[1]);
|
|
38
|
+
const c = project(inputs[2]);
|
|
39
|
+
const result = [];
|
|
40
|
+
for (let i = 0; i < a.length; i++) result.push(make$1(a[i], b[i], c[i]));
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
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));
|
|
44
|
+
const magnitude$1 = (vector) => Math.hypot(vector.x, vector.y, vector.z);
|
|
45
|
+
const normalize$1 = (vector) => {
|
|
46
|
+
const m = magnitude$1(vector);
|
|
47
|
+
return make$1(vector.x / m, vector.y / m, vector.z / m);
|
|
48
|
+
};
|
|
49
|
+
const dot$1 = dual(2, (a, b) => a.x * b.x + a.y * b.y + a.z * b.z);
|
|
50
|
+
const cross = dual(2, (a, b) => {
|
|
51
|
+
return make$1(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
|
|
52
|
+
});
|
|
53
|
+
const components$1 = (v) => [
|
|
54
|
+
v.x,
|
|
55
|
+
v.y,
|
|
56
|
+
v.z
|
|
57
|
+
];
|
|
58
|
+
const softmax$1 = (v) => {
|
|
59
|
+
const max = Math.max(v.x, v.y, v.z);
|
|
60
|
+
const v0 = Math.exp(v.x - max);
|
|
61
|
+
const v1 = Math.exp(v.y - max);
|
|
62
|
+
const v2 = Math.exp(v.z - max);
|
|
63
|
+
const sum = v0 + v1 + v2;
|
|
64
|
+
return make$1(v0 / sum, v1 / sum, v2 / sum);
|
|
65
|
+
};
|
|
66
|
+
const add$1 = dual(2, (a, b) => make$1(a.x + b.x, a.y + b.y, a.z + b.z));
|
|
67
|
+
const subtract$1 = dual(2, (a, b) => make$1(a.x - b.x, a.y - b.y, a.z - b.z));
|
|
68
|
+
const hadamard$1 = dual(2, (a, b) => make$1(a.x * b.x, a.y * b.y, a.z * b.z));
|
|
69
|
+
const scale$1 = dual(2, (v, s) => s === 1 ? v : make$1(v.x * s, v.y * s, v.z * s));
|
|
70
|
+
const getX = (v) => v.x;
|
|
71
|
+
const setX = dual(2, (v, x) => make$1(x, v.y, v.z));
|
|
72
|
+
const getY = (v) => v.y;
|
|
73
|
+
const setY = dual(2, (v, y) => make$1(v.x, y, v.z));
|
|
74
|
+
const getZ = (v) => v.z;
|
|
75
|
+
const setZ = dual(2, (v, z) => make$1(v.x, v.y, z));
|
|
76
|
+
const setR = dual(2, (v, r) => scale$1(r / magnitude$1(v))(v));
|
|
77
|
+
const getTheta = (v) => Math.acos(v.z / magnitude$1(v));
|
|
78
|
+
const setTheta = dual(2, (v, phi) => {
|
|
79
|
+
const m = magnitude$1(v);
|
|
80
|
+
const sinTheta = Math.sin(phi);
|
|
81
|
+
return make$1(m * sinTheta * Math.cos(v.y), m * sinTheta * Math.sin(v.y), m * Math.cos(phi));
|
|
82
|
+
});
|
|
83
|
+
const getPhi = (v) => Math.atan2(v.y, v.x);
|
|
84
|
+
const setPhi = dual(2, (v, theta) => {
|
|
85
|
+
const m = magnitude$1(v);
|
|
86
|
+
return make$1(m * Math.cos(theta), m * Math.sin(theta), v.z);
|
|
87
|
+
});
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/vector/vector4.internal.ts
|
|
90
|
+
const Vector4TypeId = Symbol.for("curvy/vector4");
|
|
91
|
+
var Vector4Impl = class extends Pipeable {
|
|
92
|
+
[Vector4TypeId] = Vector4TypeId;
|
|
93
|
+
x;
|
|
94
|
+
y;
|
|
95
|
+
z;
|
|
96
|
+
w;
|
|
97
|
+
constructor(v0 = 0, v1 = 0, v2 = 0, v3 = 0) {
|
|
98
|
+
super();
|
|
99
|
+
this.x = v0;
|
|
100
|
+
this.y = v1;
|
|
101
|
+
this.z = v2;
|
|
102
|
+
this.w = v3;
|
|
103
|
+
}
|
|
104
|
+
get [0]() {
|
|
105
|
+
return this.x;
|
|
106
|
+
}
|
|
107
|
+
get [1]() {
|
|
108
|
+
return this.y;
|
|
109
|
+
}
|
|
110
|
+
get [2]() {
|
|
111
|
+
return this.z;
|
|
112
|
+
}
|
|
113
|
+
get [3]() {
|
|
114
|
+
return this.w;
|
|
115
|
+
}
|
|
116
|
+
get [Symbol.toStringTag]() {
|
|
117
|
+
return `Vector4(${this.x}, ${this.y}, ${this.z}, ${this.w})`;
|
|
118
|
+
}
|
|
119
|
+
get [Symbol.for("nodejs.util.inspect.custom")]() {
|
|
120
|
+
return this[Symbol.toStringTag];
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const isVector4 = (v) => typeof v === "object" && v !== null && Vector4TypeId in v;
|
|
124
|
+
const equals = dual(2, (a, b) => epsEquals(a.x, b.x) && epsEquals(a.y, b.y) && epsEquals(a.z, b.z) && epsEquals(a.w, b.w));
|
|
125
|
+
const make = (v0, v1 = v0, v2 = v1, v3 = v2) => new Vector4Impl(v0, v1, v2, v3);
|
|
126
|
+
const transpose = (inputs, project) => {
|
|
127
|
+
const a = project(inputs[0]);
|
|
128
|
+
const b = project(inputs[1]);
|
|
129
|
+
const c = project(inputs[2]);
|
|
130
|
+
const d = project(inputs[3]);
|
|
131
|
+
const result = [];
|
|
132
|
+
for (let i = 0; i < a.length; i++) result.push(make(a[i], b[i], c[i], d[i]));
|
|
133
|
+
return result;
|
|
134
|
+
};
|
|
135
|
+
const magnitude = (vector) => Math.hypot(vector.x, vector.y, vector.z, vector.w);
|
|
136
|
+
const normalize = (vector) => {
|
|
137
|
+
const m = magnitude(vector);
|
|
138
|
+
return make(vector.x / m, vector.y / m, vector.z / m, vector.w / m);
|
|
139
|
+
};
|
|
140
|
+
const dot = dual(2, (a, b) => a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w);
|
|
141
|
+
const components = (v) => [
|
|
142
|
+
v.x,
|
|
143
|
+
v.y,
|
|
144
|
+
v.z,
|
|
145
|
+
v.w
|
|
146
|
+
];
|
|
147
|
+
const softmax = (v) => {
|
|
148
|
+
const max = Math.max(v.x, v.y, v.z, v.w);
|
|
149
|
+
const v0 = Math.exp(v.x - max);
|
|
150
|
+
const v1 = Math.exp(v.y - max);
|
|
151
|
+
const v2 = Math.exp(v.z - max);
|
|
152
|
+
const v3 = Math.exp(v.w - max);
|
|
153
|
+
const sum = v0 + v1 + v2 + v3;
|
|
154
|
+
return make(v0 / sum, v1 / sum, v2 / sum, v3 / sum);
|
|
155
|
+
};
|
|
156
|
+
const add = dual(2, (a, b) => make(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w));
|
|
157
|
+
const subtract = dual(2, (a, b) => make(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w));
|
|
158
|
+
const hadamard = dual(2, (a, b) => make(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w));
|
|
159
|
+
const scale = dual(2, (v, s) => s === 1 ? v : make(v.x * s, v.y * s, v.z * s, v.w * s));
|
|
160
|
+
//#endregion
|
|
161
|
+
export { scale$1 as A, getY as C, magnitude$1 as D, isVector3 as E, setY as F, setZ as I, softmax$1 as L, setR as M, setTheta as N, make$1 as O, setX as P, subtract$1 as R, getX as S, hadamard$1 as T, dot$1 as _, hadamard as a, getPhi as b, make as c, softmax as d, subtract as f, cross as g, components$1 as h, equals as i, setPhi as j, normalize$1 as k, normalize as l, add$1 as m, components as n, isVector4 as o, transpose as p, dot as r, magnitude as s, add as t, scale as u, equals$1 as v, getZ as w, getTheta as x, fromSpherical as y, transpose$1 as z };
|
|
162
|
+
|
|
163
|
+
//# sourceMappingURL=vector4.internal-5XcaX12X.mjs.map
|