@benev/math 0.0.0-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.
Files changed (48) hide show
  1. package/license +23 -0
  2. package/package.json +41 -0
  3. package/readme.md +3 -0
  4. package/s/concepts/angles.ts +74 -0
  5. package/s/concepts/circular.ts +72 -0
  6. package/s/concepts/noise.ts +23 -0
  7. package/s/concepts/quat.ts +131 -0
  8. package/s/concepts/randy.ts +116 -0
  9. package/s/concepts/scalar.ts +224 -0
  10. package/s/concepts/spline.ts +88 -0
  11. package/s/concepts/vec2.ts +392 -0
  12. package/s/concepts/vec3.ts +439 -0
  13. package/s/concepts/vec4.ts +74 -0
  14. package/s/index.ts +12 -0
  15. package/x/concepts/angles.d.ts +29 -0
  16. package/x/concepts/angles.js +62 -0
  17. package/x/concepts/angles.js.map +1 -0
  18. package/x/concepts/circular.d.ts +17 -0
  19. package/x/concepts/circular.js +70 -0
  20. package/x/concepts/circular.js.map +1 -0
  21. package/x/concepts/noise.d.ts +9 -0
  22. package/x/concepts/noise.js +20 -0
  23. package/x/concepts/noise.js.map +1 -0
  24. package/x/concepts/quat.d.ts +35 -0
  25. package/x/concepts/quat.js +110 -0
  26. package/x/concepts/quat.js.map +1 -0
  27. package/x/concepts/randy.d.ts +39 -0
  28. package/x/concepts/randy.js +95 -0
  29. package/x/concepts/randy.js.map +1 -0
  30. package/x/concepts/scalar.d.ts +51 -0
  31. package/x/concepts/scalar.js +219 -0
  32. package/x/concepts/scalar.js.map +1 -0
  33. package/x/concepts/spline.d.ts +9 -0
  34. package/x/concepts/spline.js +59 -0
  35. package/x/concepts/spline.js.map +1 -0
  36. package/x/concepts/vec2.d.ts +114 -0
  37. package/x/concepts/vec2.js +314 -0
  38. package/x/concepts/vec2.js.map +1 -0
  39. package/x/concepts/vec3.d.ts +117 -0
  40. package/x/concepts/vec3.js +357 -0
  41. package/x/concepts/vec3.js.map +1 -0
  42. package/x/concepts/vec4.d.ts +21 -0
  43. package/x/concepts/vec4.js +62 -0
  44. package/x/concepts/vec4.js.map +1 -0
  45. package/x/importmap.json +9 -0
  46. package/x/index.d.ts +10 -0
  47. package/x/index.js +11 -0
  48. package/x/index.js.map +1 -0
@@ -0,0 +1,59 @@
1
+ import { Scalar } from "./scalar.js";
2
+ /** resolve a number within a linear spline. */
3
+ export function linear(x, points) {
4
+ if (points.length < 2)
5
+ throw new Error("need at least two points, come on");
6
+ const [first] = points.at(0);
7
+ const [last] = points.at(-1);
8
+ x = Scalar.clamp(x, first, last);
9
+ for (let i = 0; i < points.length - 1; i++) {
10
+ const [x0, y0] = points[i];
11
+ const [x1, y1] = points[i + 1];
12
+ if (x >= x0 && x <= x1) {
13
+ const t = (x - x0) / (x1 - x0);
14
+ return y0 + t * (y1 - y0);
15
+ }
16
+ }
17
+ throw new Error("x is out of bounds, what are you even doing");
18
+ }
19
+ /** resolve a number within a catmull-rom spline, that's all smooth-like. */
20
+ export function catmullRom(x, points) {
21
+ if (points.length < 4)
22
+ throw new Error("need at least four points for this magic");
23
+ x = Scalar.clamp(x);
24
+ // find the segment where 'x' fits
25
+ for (let i = 1; i < points.length - 2; i++) {
26
+ const [x1,] = points[i];
27
+ const [x2,] = points[i + 1];
28
+ if (x >= x1 && x <= x2) {
29
+ const t = (x - x1) / (x2 - x1);
30
+ return helpers.catmullRom(t, points[i - 1], points[i], points[i + 1], points[i + 2]);
31
+ }
32
+ }
33
+ throw new Error("x is out of bounds, try again");
34
+ }
35
+ export const ez = {
36
+ /** simple linear spline where the control points are equally-spaced based on their array indices (x is expected to be between 0 and 1). */
37
+ linear(x, points) {
38
+ if (points.length < 2)
39
+ throw new Error("need at least two points, come on");
40
+ const points2 = points.map((p, index) => [Scalar.clamp(index / (points.length - 1)), p]);
41
+ return linear(Scalar.clamp(x), points2);
42
+ }
43
+ };
44
+ var helpers;
45
+ (function (helpers) {
46
+ /** internal big-brain maths for the catmull-rom implementation */
47
+ function catmullRom(t, [, p0], [, p1], [, p2], [, p3]) {
48
+ const t2 = t * t;
49
+ const t3 = t2 * t;
50
+ // coefficients for the cubic polynomial (Catmull-Rom)
51
+ const a = -0.5 * p0 + 1.5 * p1 - 1.5 * p2 + 0.5 * p3;
52
+ const b = p0 - 2.5 * p1 + 2 * p2 - 0.5 * p3;
53
+ const c = -0.5 * p0 + 0.5 * p2;
54
+ const d = p1;
55
+ return a * t3 + b * t2 + c * t + d;
56
+ }
57
+ helpers.catmullRom = catmullRom;
58
+ })(helpers || (helpers = {}));
59
+ //# sourceMappingURL=spline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spline.js","sourceRoot":"","sources":["../../s/concepts/spline.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAA;AAGlC,+CAA+C;AAC/C,MAAM,UAAU,MAAM,CAAC,CAAS,EAAE,MAAmB;IACpD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;IAErD,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IAC7B,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,CAAA;IAE7B,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;IAEhC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;QAC1B,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;QAE9B,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;YAC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G,CAAC,CAAA;IACnC,CAAC;IAlBe,kBAAU,aAkBzB,CAAA;AACF,CAAC,EAtBS,OAAO,KAAP,OAAO,QAsBhB"}
@@ -0,0 +1,114 @@
1
+ export type Vec2Array = [number, number];
2
+ export type Xy = {
3
+ x: number;
4
+ y: number;
5
+ };
6
+ /** https://github.com/microsoft/TypeScript/issues/5863 */
7
+ type TsHack<T> = {
8
+ new (...a: ConstructorParameters<typeof Vec2>): T;
9
+ };
10
+ export declare class Vec2 implements Xy {
11
+ x: number;
12
+ y: number;
13
+ constructor(x: number, y: number);
14
+ static new<T extends Vec2>(this: TsHack<T>, x: number, y: number): T;
15
+ static zero<T extends Vec2>(this: TsHack<T>): T;
16
+ static all<T extends Vec2>(this: TsHack<T>, value: number): T;
17
+ static array<T extends Vec2>(this: TsHack<T>, v: Vec2Array): T;
18
+ static import<T extends Vec2>(this: TsHack<T>, { x, y }: Xy): T;
19
+ static from(v: Vec2Array | Xy): Vec2;
20
+ static magnitudeSquared(x: number, y: number): number;
21
+ static magnitude(x: number, y: number): number;
22
+ static average(...vectors: Xy[]): Vec2;
23
+ static min(...vecs: Vec2[]): Vec2;
24
+ static max(...vecs: Vec2[]): Vec2;
25
+ clone(): Vec2;
26
+ array(): Vec2Array;
27
+ toString(): string;
28
+ /** mutator */
29
+ set_(x: number, y: number): this;
30
+ /** mutator */
31
+ set({ x, y }: Xy): this;
32
+ magnitudeSquared(): number;
33
+ magnitude(): number;
34
+ rotation(): number;
35
+ equals_(x: number, y: number): boolean;
36
+ equals(...vecs: Xy[]): boolean;
37
+ dot_(x: number, y: number): number;
38
+ dot({ x, y }: Xy): number;
39
+ distanceSquared_(x: number, y: number): number;
40
+ distanceSquared({ x, y }: Xy): number;
41
+ distance_(x: number, y: number): number;
42
+ distance({ x, y }: Xy): number;
43
+ angleBetween_(x: number, y: number): number;
44
+ angleBetween({ x, y }: Xy): number;
45
+ /** mutator */
46
+ normalize(): this;
47
+ /** mutator */
48
+ half(): this;
49
+ /** mutator */
50
+ double(): this;
51
+ /** mutator */
52
+ abs(): this;
53
+ /** mutator */
54
+ rotate(radians: number): this;
55
+ /** mutator */
56
+ perpendicular(): this;
57
+ /** mutator */
58
+ clampMagnitude(max: number): this;
59
+ /** mutator */
60
+ floor(): this;
61
+ /** mutator */
62
+ ceil(): this;
63
+ /** mutator */
64
+ round(): this;
65
+ /** mutator */
66
+ map(fn: (a: number, index: number) => number): this;
67
+ /** mutator */
68
+ clamp(min: number, max: number): this;
69
+ /** mutator */
70
+ negate(): this;
71
+ /** mutator */
72
+ addBy(delta: number): this;
73
+ /** mutator */
74
+ subtractBy(delta: number): this;
75
+ /** mutator */
76
+ multiplyBy(coefficient: number): this;
77
+ /** mutator */
78
+ divideBy(divisor: number): this;
79
+ /** mutator */
80
+ add_(x: number, y: number): this;
81
+ /** mutator */
82
+ add(...vecs: Xy[]): this;
83
+ /** mutator */
84
+ subtract_(x: number, y: number): this;
85
+ /** mutator */
86
+ subtract(...vecs: Xy[]): this;
87
+ /** mutator */
88
+ multiply_(x: number, y: number): this;
89
+ /** mutator */
90
+ multiply(...vecs: Xy[]): this;
91
+ /** mutator */
92
+ divide_(x: number, y: number): this;
93
+ /** mutator */
94
+ divide(...vecs: Xy[]): this;
95
+ /** mutator */
96
+ lerp_(x: number, y: number, fraction: number): this;
97
+ /** mutator */
98
+ lerp({ x, y }: Xy, fraction: number): this;
99
+ approach_(x: number, y: number, speed: number, deltaTime: number, speedLimit?: number): this;
100
+ approach({ x, y }: Xy, speed: number, deltaTime: number, speedLimit?: number): this;
101
+ /** mutator */
102
+ reflect_(x: number, y: number): this;
103
+ /** mutator */
104
+ reflect({ x, y }: Xy): this;
105
+ /** mutator */
106
+ rotateAroundPoint_(x: number, y: number, radians: number): this;
107
+ /** mutator */
108
+ rotateAroundPoint({ x, y }: Vec2, radians: number): this;
109
+ /** mutator */
110
+ smooth_(x: number, y: number, smoothing: number): this;
111
+ /** mutator */
112
+ smooth({ x, y }: Xy, smoothing: number): this;
113
+ }
114
+ export {};
@@ -0,0 +1,314 @@
1
+ import { Scalar } from "./scalar.js";
2
+ export class Vec2 {
3
+ x;
4
+ y;
5
+ constructor(x, y) {
6
+ this.x = x;
7
+ this.y = y;
8
+ }
9
+ ///////////////////////////////////////////////////////////////////////
10
+ static new(x, y) {
11
+ return new this(x, y);
12
+ }
13
+ static zero() {
14
+ return new this(0, 0);
15
+ }
16
+ static all(value) {
17
+ return new this(value, value);
18
+ }
19
+ static array(v) {
20
+ return new this(...v);
21
+ }
22
+ static import({ x, y }) {
23
+ return new this(x, y);
24
+ }
25
+ static from(v) {
26
+ return Array.isArray(v)
27
+ ? this.array(v)
28
+ : this.import(v);
29
+ }
30
+ static magnitudeSquared(x, y) {
31
+ return (x * x) + (y * y);
32
+ }
33
+ static magnitude(x, y) {
34
+ return Math.sqrt(this.magnitudeSquared(x, y));
35
+ }
36
+ static average(...vectors) {
37
+ return this.zero()
38
+ .add(...vectors)
39
+ .divideBy(vectors.length);
40
+ }
41
+ static min(...vecs) {
42
+ return new Vec2(Math.min(...vecs.map(v => v.x)), Math.min(...vecs.map(v => v.y)));
43
+ }
44
+ static max(...vecs) {
45
+ return new Vec2(Math.max(...vecs.map(v => v.x)), Math.max(...vecs.map(v => v.y)));
46
+ }
47
+ ///////////////////////////////////////////////////////////////////////
48
+ clone() {
49
+ return new Vec2(this.x, this.y);
50
+ }
51
+ array() {
52
+ return [this.x, this.y];
53
+ }
54
+ toString() {
55
+ return `(Vec2 x${this.x.toFixed(2)}, y${this.y.toFixed(2)})`;
56
+ }
57
+ /** mutator */
58
+ set_(x, y) {
59
+ this.x = x;
60
+ this.y = y;
61
+ return this;
62
+ }
63
+ /** mutator */
64
+ set({ x, y }) {
65
+ this.x = x;
66
+ this.y = y;
67
+ return this;
68
+ }
69
+ ///////////////////////////////////////////////////////////////////////
70
+ magnitudeSquared() {
71
+ return Vec2.magnitudeSquared(this.x, this.y);
72
+ }
73
+ magnitude() {
74
+ return Vec2.magnitude(this.x, this.y);
75
+ }
76
+ rotation() {
77
+ return Math.atan2(this.y, this.x);
78
+ }
79
+ equals_(x, y) {
80
+ return (this.x === x &&
81
+ this.y === y);
82
+ }
83
+ equals(...vecs) {
84
+ return vecs.every(({ x, y }) => this.equals_(x, y));
85
+ }
86
+ dot_(x, y) {
87
+ return (this.x * x) + (this.y * y);
88
+ }
89
+ dot({ x, y }) {
90
+ return this.dot_(x, y);
91
+ }
92
+ distanceSquared_(x, y) {
93
+ x = this.x - x;
94
+ y = this.y - y;
95
+ return (x * x) + (y * y);
96
+ }
97
+ distanceSquared({ x, y }) {
98
+ return this.distanceSquared_(x, y);
99
+ }
100
+ distance_(x, y) {
101
+ return Math.sqrt(this.distanceSquared_(x, y));
102
+ }
103
+ distance({ x, y }) {
104
+ return this.distance_(x, y);
105
+ }
106
+ angleBetween_(x, y) {
107
+ const dot = this.dot_(x, y);
108
+ const magnitudes = this.magnitude() * Vec2.magnitude(x, y);
109
+ return Math.acos(dot / magnitudes);
110
+ }
111
+ angleBetween({ x, y }) {
112
+ return this.angleBetween_(x, y);
113
+ }
114
+ ///////////////////////////////////////////////////////////////////////
115
+ /** mutator */
116
+ normalize() {
117
+ return this.divideBy(this.magnitude());
118
+ }
119
+ /** mutator */
120
+ half() {
121
+ return this.divideBy(2);
122
+ }
123
+ /** mutator */
124
+ double() {
125
+ return this.multiplyBy(2);
126
+ }
127
+ /** mutator */
128
+ abs() {
129
+ return this.map(x => Math.abs(x));
130
+ }
131
+ /** mutator */
132
+ rotate(radians) {
133
+ const { x, y } = this;
134
+ this.x = (x * Math.cos(radians)) - (y * Math.sin(radians));
135
+ this.y = (x * Math.sin(radians)) + (y * Math.cos(radians));
136
+ return this;
137
+ }
138
+ /** mutator */
139
+ perpendicular() {
140
+ const { x, y } = this;
141
+ this.x = -y;
142
+ this.y = x;
143
+ return this;
144
+ }
145
+ /** mutator */
146
+ clampMagnitude(max) {
147
+ const mag = this.magnitude();
148
+ if (mag > max)
149
+ this.normalize().multiplyBy(max);
150
+ return this;
151
+ }
152
+ /** mutator */
153
+ floor() {
154
+ this.x = Math.floor(this.x);
155
+ this.y = Math.floor(this.y);
156
+ return this;
157
+ }
158
+ /** mutator */
159
+ ceil() {
160
+ this.x = Math.ceil(this.x);
161
+ this.y = Math.ceil(this.y);
162
+ return this;
163
+ }
164
+ /** mutator */
165
+ round() {
166
+ this.x = Math.round(this.x);
167
+ this.y = Math.round(this.y);
168
+ return this;
169
+ }
170
+ /** mutator */
171
+ map(fn) {
172
+ this.x = fn(this.x, 0);
173
+ this.y = fn(this.y, 1);
174
+ return this;
175
+ }
176
+ /** mutator */
177
+ clamp(min, max) {
178
+ const clamp = (val) => Math.max(min, Math.min(max, val));
179
+ return this.map(clamp);
180
+ }
181
+ /** mutator */
182
+ negate() {
183
+ return this.map(a => a * -1);
184
+ }
185
+ /** mutator */
186
+ addBy(delta) {
187
+ this.x += delta;
188
+ this.y += delta;
189
+ return this;
190
+ }
191
+ /** mutator */
192
+ subtractBy(delta) {
193
+ this.x -= delta;
194
+ this.y -= delta;
195
+ return this;
196
+ }
197
+ /** mutator */
198
+ multiplyBy(coefficient) {
199
+ this.x *= coefficient;
200
+ this.y *= coefficient;
201
+ return this;
202
+ }
203
+ /** mutator */
204
+ divideBy(divisor) {
205
+ if (divisor === 0)
206
+ return this;
207
+ this.x /= divisor;
208
+ this.y /= divisor;
209
+ return this;
210
+ }
211
+ ///////////////////////////////////////////////////////////////////////
212
+ /** mutator */
213
+ add_(x, y) {
214
+ this.x += x;
215
+ this.y += y;
216
+ return this;
217
+ }
218
+ /** mutator */
219
+ add(...vecs) {
220
+ for (const { x, y } of vecs)
221
+ this.add_(x, y);
222
+ return this;
223
+ }
224
+ /** mutator */
225
+ subtract_(x, y) {
226
+ this.x -= x;
227
+ this.y -= y;
228
+ return this;
229
+ }
230
+ /** mutator */
231
+ subtract(...vecs) {
232
+ for (const { x, y } of vecs)
233
+ this.subtract_(x, y);
234
+ return this;
235
+ }
236
+ /** mutator */
237
+ multiply_(x, y) {
238
+ this.x *= x;
239
+ this.y *= y;
240
+ return this;
241
+ }
242
+ /** mutator */
243
+ multiply(...vecs) {
244
+ for (const { x, y } of vecs)
245
+ this.multiply_(x, y);
246
+ return this;
247
+ }
248
+ /** mutator */
249
+ divide_(x, y) {
250
+ this.x /= x;
251
+ this.y /= y;
252
+ return this;
253
+ }
254
+ /** mutator */
255
+ divide(...vecs) {
256
+ for (const { x, y } of vecs)
257
+ this.divide_(x, y);
258
+ return this;
259
+ }
260
+ /** mutator */
261
+ lerp_(x, y, fraction) {
262
+ this.x += (x - this.x) * fraction;
263
+ this.y += (y - this.y) * fraction;
264
+ return this;
265
+ }
266
+ /** mutator */
267
+ lerp({ x, y }, fraction) {
268
+ return this.lerp_(x, y, fraction);
269
+ }
270
+ approach_(x, y, speed, deltaTime, speedLimit) {
271
+ this.x = Scalar.approach(this.x, x, speed, deltaTime, speedLimit);
272
+ this.y = Scalar.approach(this.y, y, speed, deltaTime, speedLimit);
273
+ return this;
274
+ }
275
+ approach({ x, y }, speed, deltaTime, speedLimit) {
276
+ return this.approach_(x, y, speed, deltaTime, speedLimit);
277
+ }
278
+ /** mutator */
279
+ reflect_(x, y) {
280
+ const dot = 2 * this.dot_(x, y);
281
+ this.x -= dot * x;
282
+ this.y -= dot * y;
283
+ return this;
284
+ }
285
+ /** mutator */
286
+ reflect({ x, y }) {
287
+ return this.reflect_(x, y);
288
+ }
289
+ /** mutator */
290
+ rotateAroundPoint_(x, y, radians) {
291
+ const dx = this.x - x;
292
+ const dy = this.y - y;
293
+ const cos = Math.cos(radians);
294
+ const sin = Math.sin(radians);
295
+ this.x = cos * dx - sin * dy + x;
296
+ this.y = sin * dx + cos * dy + y;
297
+ return this;
298
+ }
299
+ /** mutator */
300
+ rotateAroundPoint({ x, y }, radians) {
301
+ return this.rotateAroundPoint_(x, y, radians);
302
+ }
303
+ /** mutator */
304
+ smooth_(x, y, smoothing) {
305
+ this.x = Scalar.smooth(this.x, x, smoothing);
306
+ this.y = Scalar.smooth(this.y, y, smoothing);
307
+ return this;
308
+ }
309
+ /** mutator */
310
+ smooth({ x, y }, smoothing) {
311
+ return this.smooth_(x, y, smoothing);
312
+ }
313
+ }
314
+ //# sourceMappingURL=vec2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vec2.js","sourceRoot":"","sources":["../../s/concepts/vec2.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAA;AAQlC,MAAM,OAAO,IAAI;IAER;IACA;IAFR,YACQ,CAAS,EACT,CAAS;QADT,MAAC,GAAD,CAAC,CAAQ;QACT,MAAC,GAAD,CAAC,CAAQ;IACd,CAAC;IAEJ,uEAAuE;IAEvE,MAAM,CAAC,GAAG,CAAkC,CAAS,EAAE,CAAS;QAC/D,OAAO,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACtB,CAAC;IAED,MAAM,CAAC,IAAI;QACV,OAAO,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACtB,CAAC;IAED,MAAM,CAAC,GAAG,CAAkC,KAAa;QACxD,OAAO,IAAI,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IAC9B,CAAC;IAED,MAAM,CAAC,KAAK,CAAkC,CAAY;QACzD,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;IACtB,CAAC;IAED,MAAM,CAAC,MAAM,CAAkC,EAAC,CAAC,EAAE,CAAC,EAAK;QACxD,OAAO,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACtB,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,CAAiB;QAC5B,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;YACtB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;YACf,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAClB,CAAC;IAED,MAAM,CAAC,gBAAgB,C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ACd,MAAM,CAAC,EAAC,CAAC,EAAE,CAAC,EAAK,EAAE,SAAiB;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,CAAA;IACrC,CAAC;CACD"}
@@ -0,0 +1,117 @@
1
+ export type Vec3Array = [number, number, number];
2
+ export type Xyz = {
3
+ x: number;
4
+ y: number;
5
+ z: number;
6
+ };
7
+ /** https://github.com/microsoft/TypeScript/issues/5863 */
8
+ type TsHack<T> = {
9
+ new (...a: ConstructorParameters<typeof Vec3>): T;
10
+ };
11
+ export declare class Vec3 {
12
+ x: number;
13
+ y: number;
14
+ z: number;
15
+ constructor(x: number, y: number, z: number);
16
+ static new<T extends Vec3>(this: TsHack<T>, x: number, y: number, z: number): T;
17
+ static zero<T extends Vec3>(this: TsHack<T>): T;
18
+ static all<T extends Vec3>(this: TsHack<T>, value: number): T;
19
+ static array<T extends Vec3>(this: TsHack<T>, v: Vec3Array): T;
20
+ static import<T extends Vec3>(this: TsHack<T>, { x, y, z }: Xyz): Vec3;
21
+ static from(v: Vec3Array | Xyz): Vec3;
22
+ static magnitudeSquared(x: number, y: number, z: number): number;
23
+ static magnitude(x: number, y: number, z: number): number;
24
+ static average(...vecs: Xyz[]): Vec3;
25
+ static min(...vecs: Vec3[]): Vec3;
26
+ static max(...vecs: Vec3[]): Vec3;
27
+ static hexColor(hex: string): Vec3;
28
+ clone(): Vec3;
29
+ array(): Vec3Array;
30
+ toString(): string;
31
+ set_(x: number, y: number, z: number): this;
32
+ set({ x, y, z }: Xyz): this;
33
+ magnitudeSquared(): number;
34
+ magnitude(): number;
35
+ hexColor(): string;
36
+ equals_(x: number, y: number, z: number): boolean;
37
+ equals(...vecs: Xyz[]): boolean;
38
+ distanceSquared_(x: number, y: number, z: number): number;
39
+ distanceSquared({ x, y, z }: Xyz): number;
40
+ distance_(x: number, y: number, z: number): number;
41
+ distance({ x, y, z }: Xyz): number;
42
+ dot_(x: number, y: number, z: number): number;
43
+ dot({ x, y, z }: Xyz): number;
44
+ inRange_(x: number, y: number, z: number, radius: number): boolean;
45
+ inRange({ x, y, z }: Xyz, radius: number): boolean;
46
+ angleBetween_(x: number, y: number, z: number): number;
47
+ angleBetween({ x, y, z }: Xyz): number;
48
+ /** mutator */
49
+ add_(x: number, y: number, z: number): this;
50
+ /** mutator */
51
+ add(...vecs: Xyz[]): this;
52
+ /** mutator */
53
+ subtract_(x: number, y: number, z: number): this;
54
+ /** mutator */
55
+ subtract(...vecs: Xyz[]): this;
56
+ /** mutator */
57
+ multiply_(x: number, y: number, z: number): this;
58
+ /** mutator */
59
+ multiply(...vecs: Vec3[]): this;
60
+ /** mutator */
61
+ divide_(x: number, y: number, z: number): this;
62
+ /** mutator */
63
+ divide(...vecs: Vec3[]): this;
64
+ /** mutator */
65
+ half(): this;
66
+ /** mutator */
67
+ double(): this;
68
+ /** mutator */
69
+ abs(): this;
70
+ /** mutator */
71
+ map(fn: (a: number, index: number) => number): this;
72
+ /** mutator */
73
+ negate(): this;
74
+ /** mutator */
75
+ addBy(delta: number): this;
76
+ /** mutator */
77
+ multiplyBy(delta: number): this;
78
+ /** mutator */
79
+ divideBy(divisor: number): this;
80
+ /** mutator */
81
+ normalize(): this;
82
+ /** mutator */
83
+ clampMagnitude(max: number): this;
84
+ /** mutator */
85
+ floor(): this;
86
+ /** mutator */
87
+ ceil(): this;
88
+ /** mutator */
89
+ round(): this;
90
+ /** mutator */
91
+ cross_(x2: number, y2: number, z2: number): this;
92
+ /** mutator */
93
+ cross({ x, y, z }: Xyz): this;
94
+ /** mutator */
95
+ lerp_(x: number, y: number, z: number, fraction: number): this;
96
+ /** mutator */
97
+ lerp({ x, y, z }: Xyz, fraction: number): this;
98
+ approach_(x: number, y: number, z: number, speed: number, deltaTime: number, speedLimit?: number): this;
99
+ approach({ x, y, z }: Xyz, speed: number, deltaTime: number, speedLimit?: number): this;
100
+ /** mutator */
101
+ projectOnto_(x: number, y: number, z: number): this;
102
+ /** mutator */
103
+ projectOnto({ x, y, z }: Vec3): this;
104
+ /** mutator */
105
+ reflect_(x: number, y: number, z: number): this;
106
+ /** mutator */
107
+ reflect({ x, y, z }: Xyz): this;
108
+ /** mutator */
109
+ rotateAroundAxis_(ux: number, uy: number, uz: number, angle: number): this;
110
+ /** mutator */
111
+ rotateAroundAxis({ x, y, z }: Xyz, angle: number): this;
112
+ /** mutator */
113
+ smooth_(x: number, y: number, z: number, smoothing: number): this;
114
+ /** mutator */
115
+ smooth({ x, y, z }: Xyz, smoothing: number): this;
116
+ }
117
+ export {};