@lakuna/umath 2.0.0 → 3.0.1
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/LICENSE +1 -1
- package/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.js +14 -4
- package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/linalg/DualQuaternion.d.ts +158 -158
- package/dist/linalg/DualQuaternion.d.ts.map +1 -1
- package/dist/linalg/DualQuaternion.js +173 -165
- package/dist/linalg/DualQuaternion.js.map +1 -1
- package/dist/linalg/Matrix.d.ts +24 -24
- package/dist/linalg/Matrix.d.ts.map +1 -1
- package/dist/linalg/Matrix2.d.ts +85 -85
- package/dist/linalg/Matrix2.d.ts.map +1 -1
- package/dist/linalg/Matrix2.js +92 -88
- package/dist/linalg/Matrix2.js.map +1 -1
- package/dist/linalg/Matrix3.d.ts +134 -134
- package/dist/linalg/Matrix3.d.ts.map +1 -1
- package/dist/linalg/Matrix3.js +147 -138
- package/dist/linalg/Matrix3.js.map +1 -1
- package/dist/linalg/Matrix4.d.ts +245 -246
- package/dist/linalg/Matrix4.d.ts.map +1 -1
- package/dist/linalg/Matrix4.js +272 -251
- package/dist/linalg/Matrix4.js.map +1 -1
- package/dist/linalg/Quaternion.d.ts +147 -146
- package/dist/linalg/Quaternion.d.ts.map +1 -1
- package/dist/linalg/Quaternion.js +175 -161
- package/dist/linalg/Quaternion.js.map +1 -1
- package/dist/linalg/SlowMatrix.d.ts +12 -12
- package/dist/linalg/SlowMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowMatrix.js +12 -12
- package/dist/linalg/SlowMatrix.js.map +1 -1
- package/dist/linalg/SlowSquareMatrix.d.ts +7 -7
- package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowSquareMatrix.js +15 -15
- package/dist/linalg/SlowSquareMatrix.js.map +1 -1
- package/dist/linalg/SlowVector.d.ts +77 -77
- package/dist/linalg/SlowVector.d.ts.map +1 -1
- package/dist/linalg/SlowVector.js +153 -153
- package/dist/linalg/SlowVector.js.map +1 -1
- package/dist/linalg/SquareMatrix.d.ts +8 -8
- package/dist/linalg/SquareMatrix.d.ts.map +1 -1
- package/dist/linalg/Vector.d.ts +85 -84
- package/dist/linalg/Vector.d.ts.map +1 -1
- package/dist/linalg/Vector2.d.ts +143 -143
- package/dist/linalg/Vector2.d.ts.map +1 -1
- package/dist/linalg/Vector2.js +145 -143
- package/dist/linalg/Vector2.js.map +1 -1
- package/dist/linalg/Vector3.d.ts +173 -173
- package/dist/linalg/Vector3.d.ts.map +1 -1
- package/dist/linalg/Vector3.js +176 -173
- package/dist/linalg/Vector3.js.map +1 -1
- package/dist/linalg/Vector4.d.ts +137 -137
- package/dist/linalg/Vector4.d.ts.map +1 -1
- package/dist/linalg/Vector4.js +144 -140
- package/dist/linalg/Vector4.js.map +1 -1
- package/dist/types/AxisAngle.d.ts +11 -1
- package/dist/types/AxisAngle.d.ts.map +1 -1
- package/dist/types/FieldOfView.d.ts +2 -2
- package/dist/types/FieldOfView.d.ts.map +1 -1
- package/dist/utility/BigNumber.d.ts +21 -11
- package/dist/utility/BigNumber.d.ts.map +1 -1
- package/dist/utility/BigNumber.js +49 -31
- package/dist/utility/BigNumber.js.map +1 -1
- package/dist/utility/createAxisAngleLike.d.ts.map +1 -1
- package/dist/utility/createAxisAngleLike.js.map +1 -1
- package/package.json +13 -12
- package/src/algorithms/greatestCommonDivisor.ts +19 -7
- package/src/index.ts +21 -14
- package/src/linalg/DualQuaternion.ts +264 -238
- package/src/linalg/Matrix.ts +31 -28
- package/src/linalg/Matrix2.ts +157 -137
- package/src/linalg/Matrix3.ts +222 -191
- package/src/linalg/Matrix4.ts +464 -412
- package/src/linalg/Quaternion.ts +267 -234
- package/src/linalg/SlowMatrix.ts +31 -27
- package/src/linalg/SlowSquareMatrix.ts +19 -18
- package/src/linalg/SlowVector.ts +175 -174
- package/src/linalg/SquareMatrix.ts +9 -9
- package/src/linalg/Vector.ts +91 -89
- package/src/linalg/Vector2.ts +250 -217
- package/src/linalg/Vector3.ts +309 -269
- package/src/linalg/Vector4.ts +246 -206
- package/src/types/AxisAngle.ts +13 -1
- package/src/types/FieldOfView.ts +3 -3
- package/src/utility/BigNumber.ts +71 -38
- package/src/utility/createAxisAngleLike.ts +1 -0
package/src/linalg/Vector3.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { default as Vector, VectorLike } from "./Vector.js";
|
|
2
1
|
import type { Matrix3Like } from "./Matrix3.js";
|
|
3
2
|
import type { Matrix4Like } from "./Matrix4.js";
|
|
4
3
|
import type { QuaternionLike } from "./Quaternion.js";
|
|
4
|
+
import type { default as Vector, VectorLike } from "./Vector.js";
|
|
5
|
+
|
|
5
6
|
import approxRelative from "../algorithms/approxRelative.js";
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -10,12 +11,15 @@ import approxRelative from "../algorithms/approxRelative.js";
|
|
|
10
11
|
*/
|
|
11
12
|
export interface Vector3Like extends VectorLike {
|
|
12
13
|
/** The first component of this vector. */
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
13
15
|
0: number;
|
|
14
16
|
|
|
15
17
|
/** The second component of this vector. */
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
16
19
|
1: number;
|
|
17
20
|
|
|
18
21
|
/** The third component of this vector. */
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
19
23
|
2: number;
|
|
20
24
|
}
|
|
21
25
|
|
|
@@ -24,9 +28,9 @@ export interface Vector3Like extends VectorLike {
|
|
|
24
28
|
* @returns A 3x1 vector-like object.
|
|
25
29
|
* @public
|
|
26
30
|
*/
|
|
27
|
-
export const createVector3Like = (): Float32Array & Vector3Like =>
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
export const createVector3Like = (): Float32Array & Vector3Like =>
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
33
|
+
new Float32Array(3) as Float32Array & Vector3Like;
|
|
30
34
|
|
|
31
35
|
/**
|
|
32
36
|
* Create a vector with the given values.
|
|
@@ -56,7 +60,10 @@ export const fromValues = <T extends Vector3Like>(
|
|
|
56
60
|
* @returns Whether or not the vectors are equivalent.
|
|
57
61
|
* @public
|
|
58
62
|
*/
|
|
59
|
-
export const equals = (
|
|
63
|
+
export const equals = (
|
|
64
|
+
a: Readonly<Vector3Like>,
|
|
65
|
+
b: Readonly<Vector3Like>
|
|
66
|
+
): boolean =>
|
|
60
67
|
approxRelative(a[0], b[0]) &&
|
|
61
68
|
approxRelative(a[1], b[1]) &&
|
|
62
69
|
approxRelative(a[2], b[2]);
|
|
@@ -68,8 +75,10 @@ export const equals = (a: Vector3Like, b: Vector3Like): boolean =>
|
|
|
68
75
|
* @returns Whether the vectors are equivalent.
|
|
69
76
|
* @public
|
|
70
77
|
*/
|
|
71
|
-
export const exactEquals = (
|
|
72
|
-
a
|
|
78
|
+
export const exactEquals = (
|
|
79
|
+
a: Readonly<Vector3Like>,
|
|
80
|
+
b: Readonly<Vector3Like>
|
|
81
|
+
): boolean => a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
|
|
73
82
|
|
|
74
83
|
/**
|
|
75
84
|
* Add two vectors.
|
|
@@ -80,8 +89,8 @@ export const exactEquals = (a: Vector3Like, b: Vector3Like): boolean =>
|
|
|
80
89
|
* @public
|
|
81
90
|
*/
|
|
82
91
|
export const add = <T extends Vector3Like>(
|
|
83
|
-
a: Vector3Like
|
|
84
|
-
b: Vector3Like
|
|
92
|
+
a: Readonly<Vector3Like>,
|
|
93
|
+
b: Readonly<Vector3Like>,
|
|
85
94
|
out: T
|
|
86
95
|
): T => fromValues(a[0] + b[0], a[1] + b[1], a[2] + b[2], out);
|
|
87
96
|
|
|
@@ -92,8 +101,10 @@ export const add = <T extends Vector3Like>(
|
|
|
92
101
|
* @returns The copy.
|
|
93
102
|
* @public
|
|
94
103
|
*/
|
|
95
|
-
export const copy = <T extends Vector3Like>(
|
|
96
|
-
|
|
104
|
+
export const copy = <T extends Vector3Like>(
|
|
105
|
+
vector: Readonly<Vector3Like>,
|
|
106
|
+
out: T
|
|
107
|
+
): T => fromValues(vector[0], vector[1], vector[2], out);
|
|
97
108
|
|
|
98
109
|
/**
|
|
99
110
|
* Multiply two vectors.
|
|
@@ -104,8 +115,8 @@ export const copy = <T extends Vector3Like>(vector: Vector3Like, out: T): T =>
|
|
|
104
115
|
* @public
|
|
105
116
|
*/
|
|
106
117
|
export const multiply = <T extends Vector3Like>(
|
|
107
|
-
a: Vector3Like
|
|
108
|
-
b: Vector3Like
|
|
118
|
+
a: Readonly<Vector3Like>,
|
|
119
|
+
b: Readonly<Vector3Like>,
|
|
109
120
|
out: T
|
|
110
121
|
): T => fromValues(a[0] * b[0], a[1] * b[1], a[2] * b[2], out);
|
|
111
122
|
|
|
@@ -118,8 +129,8 @@ export const multiply = <T extends Vector3Like>(
|
|
|
118
129
|
* @public
|
|
119
130
|
*/
|
|
120
131
|
export const divide = <T extends Vector3Like>(
|
|
121
|
-
a: Vector3Like
|
|
122
|
-
b: Vector3Like
|
|
132
|
+
a: Readonly<Vector3Like>,
|
|
133
|
+
b: Readonly<Vector3Like>,
|
|
123
134
|
out: T
|
|
124
135
|
): T => fromValues(a[0] / b[0], a[1] / b[1], a[2] / b[2], out);
|
|
125
136
|
|
|
@@ -132,8 +143,8 @@ export const divide = <T extends Vector3Like>(
|
|
|
132
143
|
* @public
|
|
133
144
|
*/
|
|
134
145
|
export const subtract = <T extends Vector3Like>(
|
|
135
|
-
a: Vector3Like
|
|
136
|
-
b: Vector3Like
|
|
146
|
+
a: Readonly<Vector3Like>,
|
|
147
|
+
b: Readonly<Vector3Like>,
|
|
137
148
|
out: T
|
|
138
149
|
): T => fromValues(a[0] - b[0], a[1] - b[1], a[2] - b[2], out);
|
|
139
150
|
|
|
@@ -144,7 +155,10 @@ export const subtract = <T extends Vector3Like>(
|
|
|
144
155
|
* @returns The absolutized vector.
|
|
145
156
|
* @public
|
|
146
157
|
*/
|
|
147
|
-
export const abs = <T extends Vector3Like>(
|
|
158
|
+
export const abs = <T extends Vector3Like>(
|
|
159
|
+
vector: Readonly<Vector3Like>,
|
|
160
|
+
out: T
|
|
161
|
+
): T =>
|
|
148
162
|
fromValues(
|
|
149
163
|
Math.abs(vector[0]),
|
|
150
164
|
Math.abs(vector[1]),
|
|
@@ -159,7 +173,10 @@ export const abs = <T extends Vector3Like>(vector: Vector3Like, out: T): T =>
|
|
|
159
173
|
* @returns The rounded vector.
|
|
160
174
|
* @public
|
|
161
175
|
*/
|
|
162
|
-
export const ceil = <T extends Vector3Like>(
|
|
176
|
+
export const ceil = <T extends Vector3Like>(
|
|
177
|
+
vector: Readonly<Vector3Like>,
|
|
178
|
+
out: T
|
|
179
|
+
): T =>
|
|
163
180
|
fromValues(
|
|
164
181
|
Math.ceil(vector[0]),
|
|
165
182
|
Math.ceil(vector[1]),
|
|
@@ -174,7 +191,10 @@ export const ceil = <T extends Vector3Like>(vector: Vector3Like, out: T): T =>
|
|
|
174
191
|
* @returns The rounded vector.
|
|
175
192
|
* @public
|
|
176
193
|
*/
|
|
177
|
-
export const floor = <T extends Vector3Like>(
|
|
194
|
+
export const floor = <T extends Vector3Like>(
|
|
195
|
+
vector: Readonly<Vector3Like>,
|
|
196
|
+
out: T
|
|
197
|
+
): T =>
|
|
178
198
|
fromValues(
|
|
179
199
|
Math.floor(vector[0]),
|
|
180
200
|
Math.floor(vector[1]),
|
|
@@ -189,7 +209,10 @@ export const floor = <T extends Vector3Like>(vector: Vector3Like, out: T): T =>
|
|
|
189
209
|
* @returns The rounded vector.
|
|
190
210
|
* @public
|
|
191
211
|
*/
|
|
192
|
-
export const round = <T extends Vector3Like>(
|
|
212
|
+
export const round = <T extends Vector3Like>(
|
|
213
|
+
vector: Readonly<Vector3Like>,
|
|
214
|
+
out: T
|
|
215
|
+
): T =>
|
|
193
216
|
fromValues(
|
|
194
217
|
Math.round(vector[0]),
|
|
195
218
|
Math.round(vector[1]),
|
|
@@ -206,8 +229,8 @@ export const round = <T extends Vector3Like>(vector: Vector3Like, out: T): T =>
|
|
|
206
229
|
* @public
|
|
207
230
|
*/
|
|
208
231
|
export const min = <T extends Vector3Like>(
|
|
209
|
-
a: Vector3Like
|
|
210
|
-
b: Vector3Like
|
|
232
|
+
a: Readonly<Vector3Like>,
|
|
233
|
+
b: Readonly<Vector3Like>,
|
|
211
234
|
out: T
|
|
212
235
|
): T =>
|
|
213
236
|
fromValues(
|
|
@@ -226,8 +249,8 @@ export const min = <T extends Vector3Like>(
|
|
|
226
249
|
* @public
|
|
227
250
|
*/
|
|
228
251
|
export const max = <T extends Vector3Like>(
|
|
229
|
-
a: Vector3Like
|
|
230
|
-
b: Vector3Like
|
|
252
|
+
a: Readonly<Vector3Like>,
|
|
253
|
+
b: Readonly<Vector3Like>,
|
|
231
254
|
out: T
|
|
232
255
|
): T =>
|
|
233
256
|
fromValues(
|
|
@@ -246,7 +269,7 @@ export const max = <T extends Vector3Like>(
|
|
|
246
269
|
* @public
|
|
247
270
|
*/
|
|
248
271
|
export const pow = <T extends Vector3Like>(
|
|
249
|
-
vector: Vector3Like
|
|
272
|
+
vector: Readonly<Vector3Like>,
|
|
250
273
|
scalar: number,
|
|
251
274
|
out: T
|
|
252
275
|
): T =>
|
|
@@ -266,7 +289,7 @@ export const pow = <T extends Vector3Like>(
|
|
|
266
289
|
* @public
|
|
267
290
|
*/
|
|
268
291
|
export const scale = <T extends Vector3Like>(
|
|
269
|
-
vector: Vector3Like
|
|
292
|
+
vector: Readonly<Vector3Like>,
|
|
270
293
|
scalar: number,
|
|
271
294
|
out: T
|
|
272
295
|
): T =>
|
|
@@ -282,8 +305,8 @@ export const scale = <T extends Vector3Like>(
|
|
|
282
305
|
* @public
|
|
283
306
|
*/
|
|
284
307
|
export const scaleAndAdd = <T extends Vector3Like>(
|
|
285
|
-
a: Vector3Like
|
|
286
|
-
b: Vector3Like
|
|
308
|
+
a: Readonly<Vector3Like>,
|
|
309
|
+
b: Readonly<Vector3Like>,
|
|
287
310
|
scalar: number,
|
|
288
311
|
out: T
|
|
289
312
|
): T =>
|
|
@@ -302,8 +325,10 @@ export const scaleAndAdd = <T extends Vector3Like>(
|
|
|
302
325
|
* @see {@link https://en.wikipedia.org/wiki/Euclidean_distance | Euclidean distance}
|
|
303
326
|
* @public
|
|
304
327
|
*/
|
|
305
|
-
export const distance = (
|
|
306
|
-
|
|
328
|
+
export const distance = (
|
|
329
|
+
a: Readonly<Vector3Like>,
|
|
330
|
+
b: Readonly<Vector3Like>
|
|
331
|
+
): number => Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]);
|
|
307
332
|
|
|
308
333
|
/**
|
|
309
334
|
* Calculate the squared Euclidean distance between this vector and another.
|
|
@@ -313,7 +338,10 @@ export const distance = (a: Vector3Like, b: Vector3Like): number =>
|
|
|
313
338
|
* @see {@link https://en.wikipedia.org/wiki/Euclidean_distance | Euclidean distance}
|
|
314
339
|
* @public
|
|
315
340
|
*/
|
|
316
|
-
export const squaredDistance = (
|
|
341
|
+
export const squaredDistance = (
|
|
342
|
+
a: Readonly<Vector3Like>,
|
|
343
|
+
b: Readonly<Vector3Like>
|
|
344
|
+
): number => {
|
|
317
345
|
const x = b[0] - a[0];
|
|
318
346
|
const y = b[1] - a[1];
|
|
319
347
|
const z = b[2] - a[2];
|
|
@@ -326,7 +354,7 @@ export const squaredDistance = (a: Vector3Like, b: Vector3Like): number => {
|
|
|
326
354
|
* @returns The magnitude.
|
|
327
355
|
* @public
|
|
328
356
|
*/
|
|
329
|
-
export const getMagnitude = (vector: Vector3Like): number =>
|
|
357
|
+
export const getMagnitude = (vector: Readonly<Vector3Like>): number =>
|
|
330
358
|
Math.hypot(vector[0], vector[1], vector[2]);
|
|
331
359
|
|
|
332
360
|
/**
|
|
@@ -335,7 +363,7 @@ export const getMagnitude = (vector: Vector3Like): number =>
|
|
|
335
363
|
* @returns The squared magnitude.
|
|
336
364
|
* @public
|
|
337
365
|
*/
|
|
338
|
-
export const getSquaredMagnitude = (vector: Vector3Like): number => {
|
|
366
|
+
export const getSquaredMagnitude = (vector: Readonly<Vector3Like>): number => {
|
|
339
367
|
const x = vector[0];
|
|
340
368
|
const y = vector[1];
|
|
341
369
|
const z = vector[2];
|
|
@@ -349,8 +377,10 @@ export const getSquaredMagnitude = (vector: Vector3Like): number => {
|
|
|
349
377
|
* @returns The negated vector.
|
|
350
378
|
* @public
|
|
351
379
|
*/
|
|
352
|
-
export const negate = <T extends Vector3Like>(
|
|
353
|
-
|
|
380
|
+
export const negate = <T extends Vector3Like>(
|
|
381
|
+
vector: Readonly<Vector3Like>,
|
|
382
|
+
out: T
|
|
383
|
+
): T => fromValues(-vector[0], -vector[1], -vector[2], out);
|
|
354
384
|
|
|
355
385
|
/**
|
|
356
386
|
* Calculate the multiplicative inverse of the components of a vector.
|
|
@@ -359,8 +389,10 @@ export const negate = <T extends Vector3Like>(vector: Vector3Like, out: T): T =>
|
|
|
359
389
|
* @returns The inverted vector.
|
|
360
390
|
* @public
|
|
361
391
|
*/
|
|
362
|
-
export const invert = <T extends Vector3Like>(
|
|
363
|
-
|
|
392
|
+
export const invert = <T extends Vector3Like>(
|
|
393
|
+
vector: Readonly<Vector3Like>,
|
|
394
|
+
out: T
|
|
395
|
+
): T => fromValues(1 / vector[0], 1 / vector[1], 1 / vector[2], out);
|
|
364
396
|
|
|
365
397
|
/**
|
|
366
398
|
* Normalize a vector.
|
|
@@ -371,7 +403,7 @@ export const invert = <T extends Vector3Like>(vector: Vector3Like, out: T): T =>
|
|
|
371
403
|
* @public
|
|
372
404
|
*/
|
|
373
405
|
export const normalize = <T extends Vector3Like>(
|
|
374
|
-
vector: Vector3Like
|
|
406
|
+
vector: Readonly<Vector3Like>,
|
|
375
407
|
out: T
|
|
376
408
|
): T => {
|
|
377
409
|
const x = vector[0];
|
|
@@ -394,8 +426,10 @@ export const normalize = <T extends Vector3Like>(
|
|
|
394
426
|
* @see {@link https://en.wikipedia.org/wiki/Dot_product | Dot product}
|
|
395
427
|
* @public
|
|
396
428
|
*/
|
|
397
|
-
export const dot = (
|
|
398
|
-
a
|
|
429
|
+
export const dot = (
|
|
430
|
+
a: Readonly<Vector3Like>,
|
|
431
|
+
b: Readonly<Vector3Like>
|
|
432
|
+
): number => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
399
433
|
|
|
400
434
|
/**
|
|
401
435
|
* Calculate the cross product of two vectors.
|
|
@@ -407,8 +441,8 @@ export const dot = (a: Vector3Like, b: Vector3Like): number =>
|
|
|
407
441
|
* @public
|
|
408
442
|
*/
|
|
409
443
|
export const cross = <T extends Vector3Like>(
|
|
410
|
-
a: Vector3Like
|
|
411
|
-
b: Vector3Like
|
|
444
|
+
a: Readonly<Vector3Like>,
|
|
445
|
+
b: Readonly<Vector3Like>,
|
|
412
446
|
out: T
|
|
413
447
|
): T => {
|
|
414
448
|
const ax = a[0];
|
|
@@ -438,8 +472,8 @@ export const cross = <T extends Vector3Like>(
|
|
|
438
472
|
* @public
|
|
439
473
|
*/
|
|
440
474
|
export const lerp = <T extends Vector3Like>(
|
|
441
|
-
a: Vector3Like
|
|
442
|
-
b: Vector3Like
|
|
475
|
+
a: Readonly<Vector3Like>,
|
|
476
|
+
b: Readonly<Vector3Like>,
|
|
443
477
|
t: number,
|
|
444
478
|
out: T
|
|
445
479
|
): T => {
|
|
@@ -466,8 +500,8 @@ export const lerp = <T extends Vector3Like>(
|
|
|
466
500
|
* @public
|
|
467
501
|
*/
|
|
468
502
|
export const slerp = <T extends Vector3Like>(
|
|
469
|
-
a: Vector3Like
|
|
470
|
-
b: Vector3Like
|
|
503
|
+
a: Readonly<Vector3Like>,
|
|
504
|
+
b: Readonly<Vector3Like>,
|
|
471
505
|
t: number,
|
|
472
506
|
out: T
|
|
473
507
|
): T => {
|
|
@@ -515,8 +549,8 @@ export const random = <T extends Vector3Like>(magnitude: number, out: T): T => {
|
|
|
515
549
|
* @public
|
|
516
550
|
*/
|
|
517
551
|
export const transformMatrix3 = <T extends Vector3Like>(
|
|
518
|
-
vector: Vector3Like
|
|
519
|
-
matrix: Matrix3Like
|
|
552
|
+
vector: Readonly<Vector3Like>,
|
|
553
|
+
matrix: Readonly<Matrix3Like>,
|
|
520
554
|
out: T
|
|
521
555
|
): T => {
|
|
522
556
|
const x = vector[0];
|
|
@@ -541,8 +575,8 @@ export const transformMatrix3 = <T extends Vector3Like>(
|
|
|
541
575
|
* @public
|
|
542
576
|
*/
|
|
543
577
|
export const transformMatrix4 = <T extends Vector3Like>(
|
|
544
|
-
vector: Vector3Like
|
|
545
|
-
matrix: Matrix4Like
|
|
578
|
+
vector: Readonly<Vector3Like>,
|
|
579
|
+
matrix: Readonly<Matrix4Like>,
|
|
546
580
|
out: T
|
|
547
581
|
): T => {
|
|
548
582
|
const x = vector[0];
|
|
@@ -568,8 +602,8 @@ export const transformMatrix4 = <T extends Vector3Like>(
|
|
|
568
602
|
* @public
|
|
569
603
|
*/
|
|
570
604
|
export const rotateX = <T extends Vector3Like>(
|
|
571
|
-
vector: Vector3Like
|
|
572
|
-
origin: Vector3Like
|
|
605
|
+
vector: Readonly<Vector3Like>,
|
|
606
|
+
origin: Readonly<Vector3Like>,
|
|
573
607
|
r: number,
|
|
574
608
|
out: T
|
|
575
609
|
): T => {
|
|
@@ -595,8 +629,8 @@ export const rotateX = <T extends Vector3Like>(
|
|
|
595
629
|
* @public
|
|
596
630
|
*/
|
|
597
631
|
export const rotateY = <T extends Vector3Like>(
|
|
598
|
-
vector: Vector3Like
|
|
599
|
-
origin: Vector3Like
|
|
632
|
+
vector: Readonly<Vector3Like>,
|
|
633
|
+
origin: Readonly<Vector3Like>,
|
|
600
634
|
r: number,
|
|
601
635
|
out: T
|
|
602
636
|
): T => {
|
|
@@ -622,8 +656,8 @@ export const rotateY = <T extends Vector3Like>(
|
|
|
622
656
|
* @public
|
|
623
657
|
*/
|
|
624
658
|
export const rotateZ = <T extends Vector3Like>(
|
|
625
|
-
vector: Vector3Like
|
|
626
|
-
origin: Vector3Like
|
|
659
|
+
vector: Readonly<Vector3Like>,
|
|
660
|
+
origin: Readonly<Vector3Like>,
|
|
627
661
|
r: number,
|
|
628
662
|
out: T
|
|
629
663
|
): T => {
|
|
@@ -646,7 +680,10 @@ export const rotateZ = <T extends Vector3Like>(
|
|
|
646
680
|
* @returns The angular distance from the first vector to the second.
|
|
647
681
|
* @public
|
|
648
682
|
*/
|
|
649
|
-
export const angle = (
|
|
683
|
+
export const angle = (
|
|
684
|
+
a: Readonly<Vector3Like>,
|
|
685
|
+
b: Readonly<Vector3Like>
|
|
686
|
+
): number => {
|
|
650
687
|
const mag = Math.hypot(a[0], a[1], a[2]) * Math.hypot(b[0], b[1], b[2]);
|
|
651
688
|
return Math.acos(Math.min(Math.max(mag && dot(a, b) / mag, -1), 1));
|
|
652
689
|
};
|
|
@@ -673,10 +710,10 @@ export const zero = <T extends Vector3Like>(out: T): T =>
|
|
|
673
710
|
* @public
|
|
674
711
|
*/
|
|
675
712
|
export const hermite = <T extends Vector3Like>(
|
|
676
|
-
a: Vector3Like
|
|
677
|
-
b: Vector3Like
|
|
678
|
-
c: Vector3Like
|
|
679
|
-
d: Vector3Like
|
|
713
|
+
a: Readonly<Vector3Like>,
|
|
714
|
+
b: Readonly<Vector3Like>,
|
|
715
|
+
c: Readonly<Vector3Like>,
|
|
716
|
+
d: Readonly<Vector3Like>,
|
|
680
717
|
t: number,
|
|
681
718
|
out: T
|
|
682
719
|
): T => {
|
|
@@ -708,10 +745,10 @@ export const hermite = <T extends Vector3Like>(
|
|
|
708
745
|
* @public
|
|
709
746
|
*/
|
|
710
747
|
export const bezier = <T extends Vector3Like>(
|
|
711
|
-
a: Vector3Like
|
|
712
|
-
b: Vector3Like
|
|
713
|
-
c: Vector3Like
|
|
714
|
-
d: Vector3Like
|
|
748
|
+
a: Readonly<Vector3Like>,
|
|
749
|
+
b: Readonly<Vector3Like>,
|
|
750
|
+
c: Readonly<Vector3Like>,
|
|
751
|
+
d: Readonly<Vector3Like>,
|
|
715
752
|
t: number,
|
|
716
753
|
out: T
|
|
717
754
|
): T => {
|
|
@@ -743,8 +780,8 @@ export const bezier = <T extends Vector3Like>(
|
|
|
743
780
|
* @public
|
|
744
781
|
*/
|
|
745
782
|
export const transformQuaternion = <T extends Vector3Like>(
|
|
746
|
-
vector: Vector3Like
|
|
747
|
-
quaternion: QuaternionLike
|
|
783
|
+
vector: Readonly<Vector3Like>,
|
|
784
|
+
quaternion: Readonly<QuaternionLike>,
|
|
748
785
|
out: T
|
|
749
786
|
): T => {
|
|
750
787
|
const x = vector[0];
|
|
@@ -777,6 +814,44 @@ export default class Vector3
|
|
|
777
814
|
extends Float32Array
|
|
778
815
|
implements Vector, Vector3Like
|
|
779
816
|
{
|
|
817
|
+
/** The first component of this vector. */
|
|
818
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
819
|
+
public 0: number;
|
|
820
|
+
|
|
821
|
+
/** The second component of this vector. */
|
|
822
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
823
|
+
public 1: number;
|
|
824
|
+
|
|
825
|
+
/** The third component of this vector. */
|
|
826
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
827
|
+
public 2: number;
|
|
828
|
+
|
|
829
|
+
/** The magnitude (length) of this vector. */
|
|
830
|
+
public get magnitude(): number {
|
|
831
|
+
return getMagnitude(this);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
public set magnitude(value: number) {
|
|
835
|
+
scale(normalize(this, this), value, this);
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/** The squared magnitude (length) of this vector. */
|
|
839
|
+
public get squaredMagnitude(): number {
|
|
840
|
+
return getSquaredMagnitude(this);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
public set squaredMagnitude(value: number) {
|
|
844
|
+
this.magnitude = Math.sqrt(value);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Create a three-dimensional zero vector.
|
|
849
|
+
* @see {@link https://en.wikipedia.org/wiki/Euclidean_vector | Euclidean vector}
|
|
850
|
+
*/
|
|
851
|
+
public constructor() {
|
|
852
|
+
super(3);
|
|
853
|
+
}
|
|
854
|
+
|
|
780
855
|
/**
|
|
781
856
|
* Create a vector with the given values.
|
|
782
857
|
* @param x - The first component.
|
|
@@ -789,47 +864,55 @@ export default class Vector3
|
|
|
789
864
|
}
|
|
790
865
|
|
|
791
866
|
/**
|
|
792
|
-
*
|
|
793
|
-
* @
|
|
867
|
+
* Absolutize the components of this vector.
|
|
868
|
+
* @returns The absolutized vector.
|
|
794
869
|
*/
|
|
795
|
-
public
|
|
796
|
-
|
|
870
|
+
public abs(): Vector3 {
|
|
871
|
+
return abs(this, new Vector3());
|
|
797
872
|
}
|
|
798
873
|
|
|
799
|
-
/** The first component of this vector. */
|
|
800
|
-
public 0: number;
|
|
801
|
-
|
|
802
|
-
/** The second component of this vector. */
|
|
803
|
-
public 1: number;
|
|
804
|
-
|
|
805
|
-
/** The third component of this vector. */
|
|
806
|
-
public 2: number;
|
|
807
|
-
|
|
808
874
|
/**
|
|
809
|
-
*
|
|
875
|
+
* Add two vectors of the same size.
|
|
810
876
|
* @param vector - The other vector.
|
|
811
|
-
* @returns
|
|
877
|
+
* @returns The sum of the vectors.
|
|
812
878
|
*/
|
|
813
|
-
public
|
|
814
|
-
return
|
|
879
|
+
public add(vector: Readonly<Vector3Like>): Vector3 {
|
|
880
|
+
return add(this, vector, new Vector3());
|
|
815
881
|
}
|
|
816
882
|
|
|
817
883
|
/**
|
|
818
|
-
*
|
|
884
|
+
* Get the angle from this vector to another in radians.
|
|
819
885
|
* @param vector - The other vector.
|
|
820
|
-
* @returns
|
|
886
|
+
* @returns The angular distance from this vector to the other.
|
|
821
887
|
*/
|
|
822
|
-
public
|
|
823
|
-
return
|
|
888
|
+
public angle(vector: Readonly<Vector3Like>): number {
|
|
889
|
+
return angle(this, vector);
|
|
824
890
|
}
|
|
825
891
|
|
|
826
892
|
/**
|
|
827
|
-
*
|
|
828
|
-
* @param
|
|
829
|
-
* @
|
|
893
|
+
* Perform a Bézier interpolation with two control points between this vector and another.
|
|
894
|
+
* @param a - The first control point.
|
|
895
|
+
* @param b - The second control point.
|
|
896
|
+
* @param end - The other vector.
|
|
897
|
+
* @param t - The interpolation amount in the range `[0,1]`.
|
|
898
|
+
* @returns The interpolated vector.
|
|
899
|
+
* @see {@link https://en.wikipedia.org/wiki/B%C3%A9zier_curve | Bézier curve}
|
|
830
900
|
*/
|
|
831
|
-
public
|
|
832
|
-
|
|
901
|
+
public bezier(
|
|
902
|
+
a: Readonly<Vector3Like>,
|
|
903
|
+
b: Readonly<Vector3Like>,
|
|
904
|
+
end: Readonly<Vector3Like>,
|
|
905
|
+
t: number
|
|
906
|
+
): Vector3 {
|
|
907
|
+
return bezier(this, a, b, end, t, new Vector3());
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
/**
|
|
911
|
+
* Round up the components of this vector.
|
|
912
|
+
* @returns The rounded vector.
|
|
913
|
+
*/
|
|
914
|
+
public ceil(): Vector3 {
|
|
915
|
+
return ceil(this, new Vector3());
|
|
833
916
|
}
|
|
834
917
|
|
|
835
918
|
/**
|
|
@@ -845,17 +928,28 @@ export default class Vector3
|
|
|
845
928
|
* @param vector - The vector to copy.
|
|
846
929
|
* @returns This vector.
|
|
847
930
|
*/
|
|
848
|
-
public copy(vector: Vector3Like): this {
|
|
931
|
+
public copy(vector: Readonly<Vector3Like>): this {
|
|
849
932
|
return copy(vector, this);
|
|
850
933
|
}
|
|
851
934
|
|
|
852
935
|
/**
|
|
853
|
-
*
|
|
936
|
+
* Calculate the cross product of this and another vector.
|
|
854
937
|
* @param vector - The other vector.
|
|
855
|
-
* @returns The product
|
|
938
|
+
* @returns The cross product.
|
|
939
|
+
* @see {@link https://en.wikipedia.org/wiki/Cross_product | Cross product}
|
|
856
940
|
*/
|
|
857
|
-
public
|
|
858
|
-
return
|
|
941
|
+
public cross(vector: Readonly<Vector3Like>): Vector3 {
|
|
942
|
+
return cross(this, vector, new Vector3());
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* Calculate the Euclidean distance between this vector and another.
|
|
947
|
+
* @param vector - The other vector.
|
|
948
|
+
* @returns The distance.
|
|
949
|
+
* @see {@link https://en.wikipedia.org/wiki/Euclidean_distance | Euclidean distance}
|
|
950
|
+
*/
|
|
951
|
+
public distance(vector: Readonly<Vector3Like>): number {
|
|
952
|
+
return distance(this, vector);
|
|
859
953
|
}
|
|
860
954
|
|
|
861
955
|
/**
|
|
@@ -863,33 +957,36 @@ export default class Vector3
|
|
|
863
957
|
* @param vector - The other vector.
|
|
864
958
|
* @returns The quotient of the vectors.
|
|
865
959
|
*/
|
|
866
|
-
public divide(vector: Vector3Like): Vector3 {
|
|
960
|
+
public divide(vector: Readonly<Vector3Like>): Vector3 {
|
|
867
961
|
return divide(this, vector, new Vector3());
|
|
868
962
|
}
|
|
869
963
|
|
|
870
964
|
/**
|
|
871
|
-
*
|
|
965
|
+
* Calculate the dot product of this and another vector.
|
|
872
966
|
* @param vector - The other vector.
|
|
873
|
-
* @returns The
|
|
967
|
+
* @returns The dot product.
|
|
968
|
+
* @see {@link https://en.wikipedia.org/wiki/Dot_product | Dot product}
|
|
874
969
|
*/
|
|
875
|
-
public
|
|
876
|
-
return
|
|
970
|
+
public dot(vector: Readonly<Vector3Like>): number {
|
|
971
|
+
return dot(this, vector);
|
|
877
972
|
}
|
|
878
973
|
|
|
879
974
|
/**
|
|
880
|
-
*
|
|
881
|
-
* @
|
|
975
|
+
* Determine whether or not this vector is roughly equivalent to another.
|
|
976
|
+
* @param vector - The other vector.
|
|
977
|
+
* @returns Whether or not the vectors are equivalent.
|
|
882
978
|
*/
|
|
883
|
-
public
|
|
884
|
-
return
|
|
979
|
+
public equals(vector: Readonly<Vector3Like>): boolean {
|
|
980
|
+
return equals(this, vector);
|
|
885
981
|
}
|
|
886
982
|
|
|
887
983
|
/**
|
|
888
|
-
*
|
|
889
|
-
* @
|
|
984
|
+
* Determine whether or not this vector is exactly equivalent to another.
|
|
985
|
+
* @param vector - The other vector.
|
|
986
|
+
* @returns Whether or not the vectors are equivalent.
|
|
890
987
|
*/
|
|
891
|
-
public
|
|
892
|
-
return
|
|
988
|
+
public exactEquals(vector: Readonly<Vector3Like>): boolean {
|
|
989
|
+
return exactEquals(this, vector);
|
|
893
990
|
}
|
|
894
991
|
|
|
895
992
|
/**
|
|
@@ -901,95 +998,67 @@ export default class Vector3
|
|
|
901
998
|
}
|
|
902
999
|
|
|
903
1000
|
/**
|
|
904
|
-
*
|
|
905
|
-
* @
|
|
1001
|
+
* Perform a Hermite interpolation with two control points between this vector and another.
|
|
1002
|
+
* @param a - The first control point.
|
|
1003
|
+
* @param b - The second control point.
|
|
1004
|
+
* @param end - The other vector.
|
|
1005
|
+
* @param t - The interpolation amount in the range `[0,1]`.
|
|
1006
|
+
* @returns The interpolated vector.
|
|
1007
|
+
* @see {@link https://en.wikipedia.org/wiki/Hermite_interpolation | Hermite interpolation}
|
|
906
1008
|
*/
|
|
907
|
-
public
|
|
908
|
-
|
|
1009
|
+
public hermite(
|
|
1010
|
+
a: Readonly<Vector3Like>,
|
|
1011
|
+
b: Readonly<Vector3Like>,
|
|
1012
|
+
end: Readonly<Vector3Like>,
|
|
1013
|
+
t: number
|
|
1014
|
+
): Vector3 {
|
|
1015
|
+
return hermite(this, a, b, end, t, new Vector3());
|
|
909
1016
|
}
|
|
910
1017
|
|
|
911
1018
|
/**
|
|
912
|
-
*
|
|
913
|
-
* @
|
|
914
|
-
* @returns The minimum.
|
|
1019
|
+
* Calculate the multiplicative inverse of the components of this vector.
|
|
1020
|
+
* @returns The inverted vector.
|
|
915
1021
|
*/
|
|
916
|
-
public
|
|
917
|
-
return
|
|
1022
|
+
public invert(): Vector3 {
|
|
1023
|
+
return invert(this, new Vector3());
|
|
918
1024
|
}
|
|
919
1025
|
|
|
920
1026
|
/**
|
|
921
|
-
*
|
|
1027
|
+
* Perform a linear interpolation between this and another vector.
|
|
922
1028
|
* @param vector - The other vector.
|
|
923
|
-
* @
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
return max(this, vector, new Vector3());
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
/**
|
|
930
|
-
* Raise each component of this vector to the given power.
|
|
931
|
-
* @param scalar - The exponent (power) to raise each component to.
|
|
932
|
-
* @returns The power (result of the exponentiation).
|
|
933
|
-
*/
|
|
934
|
-
public pow(scalar: number): Vector3 {
|
|
935
|
-
return pow(this, scalar, new Vector3());
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
/**
|
|
939
|
-
* Scale this vector by a scalar.
|
|
940
|
-
* @param scalar - The scalar.
|
|
941
|
-
* @returns The scaled vector.
|
|
1029
|
+
* @param t - The interpolation amount (in `[0,1]`).
|
|
1030
|
+
* @returns The interpolated vector.
|
|
1031
|
+
* @see {@link https://en.wikipedia.org/wiki/Linear_interpolation | Linear interpolation}
|
|
942
1032
|
*/
|
|
943
|
-
public
|
|
944
|
-
return
|
|
1033
|
+
public lerp(vector: Readonly<Vector3Like>, t: number): Vector3 {
|
|
1034
|
+
return lerp(this, vector, t, new Vector3());
|
|
945
1035
|
}
|
|
946
1036
|
|
|
947
1037
|
/**
|
|
948
|
-
*
|
|
1038
|
+
* Return the maximum of this and another vector.
|
|
949
1039
|
* @param vector - The other vector.
|
|
950
|
-
* @
|
|
951
|
-
* @returns The sum.
|
|
1040
|
+
* @returns The maximum.
|
|
952
1041
|
*/
|
|
953
|
-
public
|
|
954
|
-
return
|
|
1042
|
+
public max(vector: Readonly<Vector3Like>): Vector3 {
|
|
1043
|
+
return max(this, vector, new Vector3());
|
|
955
1044
|
}
|
|
956
1045
|
|
|
957
1046
|
/**
|
|
958
|
-
*
|
|
1047
|
+
* Return the minimum of this and another vector.
|
|
959
1048
|
* @param vector - The other vector.
|
|
960
|
-
* @returns The
|
|
961
|
-
* @see {@link https://en.wikipedia.org/wiki/Euclidean_distance | Euclidean distance}
|
|
1049
|
+
* @returns The minimum.
|
|
962
1050
|
*/
|
|
963
|
-
public
|
|
964
|
-
return
|
|
1051
|
+
public min(vector: Readonly<Vector3Like>): Vector3 {
|
|
1052
|
+
return min(this, vector, new Vector3());
|
|
965
1053
|
}
|
|
966
1054
|
|
|
967
1055
|
/**
|
|
968
|
-
*
|
|
1056
|
+
* Multiply this vector by another.
|
|
969
1057
|
* @param vector - The other vector.
|
|
970
|
-
* @returns The
|
|
971
|
-
* @see {@link https://en.wikipedia.org/wiki/Euclidean_distance | Euclidean distance}
|
|
1058
|
+
* @returns The product of the vectors.
|
|
972
1059
|
*/
|
|
973
|
-
public
|
|
974
|
-
return
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
/** The magnitude (length) of this vector. */
|
|
978
|
-
public get magnitude(): number {
|
|
979
|
-
return getMagnitude(this);
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
public set magnitude(value: number) {
|
|
983
|
-
scale(normalize(this, this), value, this);
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
/** The squared magnitude (length) of this vector. */
|
|
987
|
-
public get squaredMagnitude(): number {
|
|
988
|
-
return getSquaredMagnitude(this);
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
public set squaredMagnitude(value: number) {
|
|
992
|
-
this.magnitude = Math.sqrt(value);
|
|
1060
|
+
public multiply(vector: Readonly<Vector3Like>): Vector3 {
|
|
1061
|
+
return multiply(this, vector, new Vector3());
|
|
993
1062
|
}
|
|
994
1063
|
|
|
995
1064
|
/**
|
|
@@ -1000,14 +1069,6 @@ export default class Vector3
|
|
|
1000
1069
|
return negate(this, new Vector3());
|
|
1001
1070
|
}
|
|
1002
1071
|
|
|
1003
|
-
/**
|
|
1004
|
-
* Calculate the multiplicative inverse of the components of this vector.
|
|
1005
|
-
* @returns The inverted vector.
|
|
1006
|
-
*/
|
|
1007
|
-
public invert(): Vector3 {
|
|
1008
|
-
return invert(this, new Vector3());
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
1072
|
/**
|
|
1012
1073
|
* Normalize this vector.
|
|
1013
1074
|
* @returns The normalized vector.
|
|
@@ -1018,34 +1079,12 @@ export default class Vector3
|
|
|
1018
1079
|
}
|
|
1019
1080
|
|
|
1020
1081
|
/**
|
|
1021
|
-
*
|
|
1022
|
-
* @param
|
|
1023
|
-
* @returns The
|
|
1024
|
-
* @see {@link https://en.wikipedia.org/wiki/Dot_product | Dot product}
|
|
1025
|
-
*/
|
|
1026
|
-
public dot(vector: Vector3Like): number {
|
|
1027
|
-
return dot(this, vector);
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
/**
|
|
1031
|
-
* Calculate the cross product of this and another vector.
|
|
1032
|
-
* @param vector - The other vector.
|
|
1033
|
-
* @returns The cross product.
|
|
1034
|
-
* @see {@link https://en.wikipedia.org/wiki/Cross_product | Cross product}
|
|
1035
|
-
*/
|
|
1036
|
-
public cross(vector: Vector3Like): Vector3 {
|
|
1037
|
-
return cross(this, vector, new Vector3());
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
/**
|
|
1041
|
-
* Perform a linear interpolation between this and another vector.
|
|
1042
|
-
* @param vector - The other vector.
|
|
1043
|
-
* @param t - The interpolation amount (in `[0,1]`).
|
|
1044
|
-
* @returns The interpolated vector.
|
|
1045
|
-
* @see {@link https://en.wikipedia.org/wiki/Linear_interpolation | Linear interpolation}
|
|
1082
|
+
* Raise each component of this vector to the given power.
|
|
1083
|
+
* @param scalar - The exponent (power) to raise each component to.
|
|
1084
|
+
* @returns The power (result of the exponentiation).
|
|
1046
1085
|
*/
|
|
1047
|
-
public
|
|
1048
|
-
return
|
|
1086
|
+
public pow(scalar: number): Vector3 {
|
|
1087
|
+
return pow(this, scalar, new Vector3());
|
|
1049
1088
|
}
|
|
1050
1089
|
|
|
1051
1090
|
/**
|
|
@@ -1057,31 +1096,13 @@ export default class Vector3
|
|
|
1057
1096
|
return random(magnitude, this);
|
|
1058
1097
|
}
|
|
1059
1098
|
|
|
1060
|
-
/**
|
|
1061
|
-
* Transform this vector by a three-by-three matrix.
|
|
1062
|
-
* @param matrix - The matrix.
|
|
1063
|
-
* @returns The transformed vector.
|
|
1064
|
-
*/
|
|
1065
|
-
public transformMatrix3(matrix: Matrix3Like): Vector3 {
|
|
1066
|
-
return transformMatrix3(this, matrix, new Vector3());
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
/**
|
|
1070
|
-
* Transform this vector by a four-by-four matrix.
|
|
1071
|
-
* @param matrix - The matrix.
|
|
1072
|
-
* @returns The transformed vector.
|
|
1073
|
-
*/
|
|
1074
|
-
public transformMatrix4(matrix: Matrix4Like): Vector3 {
|
|
1075
|
-
return transformMatrix4(this, matrix, new Vector3());
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
1099
|
/**
|
|
1079
1100
|
* Rotate this vector around the X-axis.
|
|
1080
1101
|
* @param origin - The origin of the rotation.
|
|
1081
1102
|
* @param r - The angle of rotation in radians.
|
|
1082
1103
|
* @returns The rotated vector.
|
|
1083
1104
|
*/
|
|
1084
|
-
public rotateX(origin: Vector3Like
|
|
1105
|
+
public rotateX(origin: Readonly<Vector3Like>, r: number): Vector3 {
|
|
1085
1106
|
return rotateX(this, origin, r, new Vector3());
|
|
1086
1107
|
}
|
|
1087
1108
|
|
|
@@ -1091,7 +1112,7 @@ export default class Vector3
|
|
|
1091
1112
|
* @param r - The angle of rotation in radians.
|
|
1092
1113
|
* @returns The rotated vector.
|
|
1093
1114
|
*/
|
|
1094
|
-
public rotateY(origin: Vector3Like
|
|
1115
|
+
public rotateY(origin: Readonly<Vector3Like>, r: number): Vector3 {
|
|
1095
1116
|
return rotateY(this, origin, r, new Vector3());
|
|
1096
1117
|
}
|
|
1097
1118
|
|
|
@@ -1101,61 +1122,72 @@ export default class Vector3
|
|
|
1101
1122
|
* @param r - The angle of rotation in radians.
|
|
1102
1123
|
* @returns The rotated vector.
|
|
1103
1124
|
*/
|
|
1104
|
-
public rotateZ(origin: Vector3Like
|
|
1125
|
+
public rotateZ(origin: Readonly<Vector3Like>, r: number): Vector3 {
|
|
1105
1126
|
return rotateZ(this, origin, r, new Vector3());
|
|
1106
1127
|
}
|
|
1107
1128
|
|
|
1108
1129
|
/**
|
|
1109
|
-
*
|
|
1130
|
+
* Round the components of this vector.
|
|
1131
|
+
* @returns The rounded vector.
|
|
1132
|
+
*/
|
|
1133
|
+
public round(): Vector3 {
|
|
1134
|
+
return round(this, new Vector3());
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
/**
|
|
1138
|
+
* Scale this vector by a scalar.
|
|
1139
|
+
* @param scalar - The scalar.
|
|
1140
|
+
* @returns The scaled vector.
|
|
1141
|
+
*/
|
|
1142
|
+
public scale(scalar: number): Vector3 {
|
|
1143
|
+
return scale(this, scalar, new Vector3());
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
/**
|
|
1147
|
+
* Add another vector to this one after scaling the other by a scalar.
|
|
1110
1148
|
* @param vector - The other vector.
|
|
1111
|
-
* @
|
|
1149
|
+
* @param scalar - The scalar.
|
|
1150
|
+
* @returns The sum.
|
|
1112
1151
|
*/
|
|
1113
|
-
public
|
|
1114
|
-
return
|
|
1152
|
+
public scaleAndAdd(vector: Readonly<Vector3Like>, scalar: number): Vector3 {
|
|
1153
|
+
return scaleAndAdd(this, vector, scalar, new Vector3());
|
|
1115
1154
|
}
|
|
1116
1155
|
|
|
1117
1156
|
/**
|
|
1118
|
-
*
|
|
1119
|
-
* @
|
|
1157
|
+
* Calculate the squared Euclidean distance between this vector and another.
|
|
1158
|
+
* @param vector - The other vector.
|
|
1159
|
+
* @returns The squared distance.
|
|
1160
|
+
* @see {@link https://en.wikipedia.org/wiki/Euclidean_distance | Euclidean distance}
|
|
1120
1161
|
*/
|
|
1121
|
-
public
|
|
1122
|
-
return
|
|
1162
|
+
public squaredDistance(vector: Readonly<Vector3Like>): number {
|
|
1163
|
+
return squaredDistance(this, vector);
|
|
1123
1164
|
}
|
|
1124
1165
|
|
|
1125
1166
|
/**
|
|
1126
|
-
*
|
|
1127
|
-
* @param
|
|
1128
|
-
* @
|
|
1129
|
-
* @param end - The other vector.
|
|
1130
|
-
* @param t - The interpolation amount in the range `[0,1]`.
|
|
1131
|
-
* @returns The interpolated vector.
|
|
1132
|
-
* @see {@link https://en.wikipedia.org/wiki/Hermite_interpolation | Hermite interpolation}
|
|
1167
|
+
* Subtract another vector from this one.
|
|
1168
|
+
* @param vector - The other vector.
|
|
1169
|
+
* @returns The difference between the vectors.
|
|
1133
1170
|
*/
|
|
1134
|
-
public
|
|
1135
|
-
|
|
1136
|
-
b: Vector3Like,
|
|
1137
|
-
end: Vector3Like,
|
|
1138
|
-
t: number
|
|
1139
|
-
): Vector3 {
|
|
1140
|
-
return hermite(this, a, b, end, t, new Vector3());
|
|
1171
|
+
public subtract(vector: Readonly<Vector3Like>): Vector3 {
|
|
1172
|
+
return subtract(this, vector, new Vector3());
|
|
1141
1173
|
}
|
|
1142
1174
|
|
|
1143
1175
|
/**
|
|
1144
|
-
*
|
|
1145
|
-
* @param
|
|
1146
|
-
* @
|
|
1147
|
-
* @param end - The other vector.
|
|
1148
|
-
* @param t - The interpolation amount in the range `[0,1]`.
|
|
1149
|
-
* @returns The interpolated vector.
|
|
1150
|
-
* @see {@link https://en.wikipedia.org/wiki/B%C3%A9zier_curve | Bézier curve}
|
|
1176
|
+
* Transform this vector by a three-by-three matrix.
|
|
1177
|
+
* @param matrix - The matrix.
|
|
1178
|
+
* @returns The transformed vector.
|
|
1151
1179
|
*/
|
|
1152
|
-
public
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1180
|
+
public transformMatrix3(matrix: Readonly<Matrix3Like>): Vector3 {
|
|
1181
|
+
return transformMatrix3(this, matrix, new Vector3());
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
/**
|
|
1185
|
+
* Transform this vector by a four-by-four matrix.
|
|
1186
|
+
* @param matrix - The matrix.
|
|
1187
|
+
* @returns The transformed vector.
|
|
1188
|
+
*/
|
|
1189
|
+
public transformMatrix4(matrix: Readonly<Matrix4Like>): Vector3 {
|
|
1190
|
+
return transformMatrix4(this, matrix, new Vector3());
|
|
1159
1191
|
}
|
|
1160
1192
|
|
|
1161
1193
|
/**
|
|
@@ -1164,7 +1196,15 @@ export default class Vector3
|
|
|
1164
1196
|
* @returns The transformed vector.
|
|
1165
1197
|
* @see {@link https://en.wikipedia.org/wiki/Quaternion | Quaternion}
|
|
1166
1198
|
*/
|
|
1167
|
-
public transformQuaternion(quaternion: QuaternionLike): Vector3 {
|
|
1199
|
+
public transformQuaternion(quaternion: Readonly<QuaternionLike>): Vector3 {
|
|
1168
1200
|
return transformQuaternion(this, quaternion, new Vector3());
|
|
1169
1201
|
}
|
|
1202
|
+
|
|
1203
|
+
/**
|
|
1204
|
+
* Set this to the zero vector.
|
|
1205
|
+
* @returns This vector.
|
|
1206
|
+
*/
|
|
1207
|
+
public zero(): this {
|
|
1208
|
+
return zero(this);
|
|
1209
|
+
}
|
|
1170
1210
|
}
|