@lakuna/umath 1.2.0 → 1.2.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/dist/algorithms/combinations.js +1 -1
- package/dist/algorithms/combinations.js.map +1 -1
- package/dist/algorithms/degreesToRadians.js +1 -1
- package/dist/algorithms/degreesToRadians.js.map +1 -1
- package/dist/algorithms/factorial.js.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
- package/dist/algorithms/hypergeometricPmf.d.ts.map +1 -1
- package/dist/algorithms/hypergeometricPmf.js +1 -1
- package/dist/algorithms/hypergeometricPmf.js.map +1 -1
- package/dist/algorithms/permutations.js +1 -1
- package/dist/algorithms/permutations.js.map +1 -1
- package/dist/algorithms/radiansToDegrees.js +1 -1
- package/dist/algorithms/radiansToDegrees.js.map +1 -1
- package/dist/algorithms/summation.d.ts.map +1 -1
- package/dist/algorithms/summation.js.map +1 -1
- package/dist/index.d.ts +33 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -27
- package/dist/index.js.map +1 -1
- package/dist/linalg/DualQuaternion.d.ts +3 -3
- package/dist/linalg/DualQuaternion.d.ts.map +1 -1
- package/dist/linalg/DualQuaternion.js +60 -28
- package/dist/linalg/DualQuaternion.js.map +1 -1
- package/dist/linalg/Matrix2.d.ts +3 -8
- package/dist/linalg/Matrix2.d.ts.map +1 -1
- package/dist/linalg/Matrix2.js +9 -12
- package/dist/linalg/Matrix2.js.map +1 -1
- package/dist/linalg/Matrix3.d.ts +5 -15
- package/dist/linalg/Matrix3.d.ts.map +1 -1
- package/dist/linalg/Matrix3.js +23 -23
- package/dist/linalg/Matrix3.js.map +1 -1
- package/dist/linalg/Matrix4.d.ts +5 -5
- package/dist/linalg/Matrix4.d.ts.map +1 -1
- package/dist/linalg/Matrix4.js +45 -40
- package/dist/linalg/Matrix4.js.map +1 -1
- package/dist/linalg/Quaternion.d.ts +3 -3
- package/dist/linalg/Quaternion.d.ts.map +1 -1
- package/dist/linalg/Quaternion.js +16 -9
- package/dist/linalg/Quaternion.js.map +1 -1
- package/dist/linalg/SlowMatrix.d.ts +1 -1
- package/dist/linalg/SlowMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowMatrix.js +12 -6
- package/dist/linalg/SlowMatrix.js.map +1 -1
- package/dist/linalg/SlowSquareMatrix.d.ts +2 -2
- package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowSquareMatrix.js +9 -5
- package/dist/linalg/SlowSquareMatrix.js.map +1 -1
- package/dist/linalg/SquareMatrix.d.ts +1 -1
- package/dist/linalg/SquareMatrix.d.ts.map +1 -1
- package/dist/linalg/Vector2.d.ts +5 -5
- package/dist/linalg/Vector2.d.ts.map +1 -1
- package/dist/linalg/Vector2.js +5 -6
- package/dist/linalg/Vector2.js.map +1 -1
- package/dist/linalg/Vector3.d.ts +4 -4
- package/dist/linalg/Vector3.d.ts.map +1 -1
- package/dist/linalg/Vector3.js +7 -9
- package/dist/linalg/Vector3.js.map +1 -1
- package/dist/linalg/Vector4.d.ts +3 -3
- package/dist/linalg/Vector4.d.ts.map +1 -1
- package/dist/linalg/Vector4.js +6 -9
- package/dist/linalg/Vector4.js.map +1 -1
- package/dist/types/AxisAngle.d.ts +1 -1
- package/dist/types/AxisAngle.d.ts.map +1 -1
- package/dist/utility/BigNumber.d.ts +1 -1
- package/dist/utility/BigNumber.d.ts.map +1 -1
- package/dist/utility/BigNumber.js +3 -2
- package/dist/utility/BigNumber.js.map +1 -1
- package/package.json +37 -6
- package/src/algorithms/combinations.ts +1 -1
- package/src/algorithms/degreesToRadians.ts +1 -1
- package/src/algorithms/factorial.ts +2 -2
- package/src/algorithms/greatestCommonDivisor.ts +10 -3
- package/src/algorithms/hypergeometricPmf.ts +8 -3
- package/src/algorithms/permutations.ts +1 -1
- package/src/algorithms/radiansToDegrees.ts +1 -1
- package/src/algorithms/summation.ts +5 -1
- package/src/index.ts +36 -33
- package/src/linalg/DualQuaternion.ts +409 -116
- package/src/linalg/Matrix.ts +1 -1
- package/src/linalg/Matrix2.ts +159 -63
- package/src/linalg/Matrix3.ts +300 -107
- package/src/linalg/Matrix4.ts +722 -206
- package/src/linalg/Quaternion.ts +311 -80
- package/src/linalg/SlowMatrix.ts +17 -9
- package/src/linalg/SlowSquareMatrix.ts +24 -13
- package/src/linalg/SquareMatrix.ts +1 -1
- package/src/linalg/Vector2.ts +361 -223
- package/src/linalg/Vector3.ts +318 -89
- package/src/linalg/Vector4.ts +177 -53
- package/src/types/AxisAngle.ts +1 -1
- package/src/utility/BigNumber.ts +18 -7
package/src/linalg/Vector2.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Matrix2Like } from "#
|
|
2
|
-
import type { Matrix3Like } from "#
|
|
3
|
-
import type { Matrix4Like } from "#
|
|
4
|
-
import type Vector from "#
|
|
5
|
-
import Vector3, { type Vector3Like } from "#
|
|
6
|
-
import epsilon from "#
|
|
1
|
+
import type { Matrix2Like } from "#Matrix2";
|
|
2
|
+
import type { Matrix3Like } from "#Matrix3";
|
|
3
|
+
import type { Matrix4Like } from "#Matrix4";
|
|
4
|
+
import type Vector from "#Vector";
|
|
5
|
+
import Vector3, { type Vector3Like } from "#Vector3";
|
|
6
|
+
import epsilon from "#epsilon";
|
|
7
7
|
|
|
8
8
|
/** A quantity with magnitude and direction in two dimensions. */
|
|
9
9
|
export type Vector2Like = Vector2 | [number, number];
|
|
@@ -15,7 +15,11 @@ export type Vector2Like = Vector2 | [number, number];
|
|
|
15
15
|
* @param out The vector to store the result in.
|
|
16
16
|
* @returns A new vector.
|
|
17
17
|
*/
|
|
18
|
-
export function fromValues<T extends Vector2Like>(
|
|
18
|
+
export function fromValues<T extends Vector2Like>(
|
|
19
|
+
x: number,
|
|
20
|
+
y: number,
|
|
21
|
+
out: T
|
|
22
|
+
): T {
|
|
19
23
|
out[0] = x;
|
|
20
24
|
out[1] = y;
|
|
21
25
|
return out;
|
|
@@ -34,8 +38,10 @@ export function equals(a: Vector2Like, b: Vector2Like): boolean {
|
|
|
34
38
|
const b0: number = b[0];
|
|
35
39
|
const b1: number = b[1];
|
|
36
40
|
|
|
37
|
-
return
|
|
38
|
-
|
|
41
|
+
return (
|
|
42
|
+
Math.abs(a0 - b0) <= epsilon * Math.max(1, Math.abs(a0), Math.abs(b0)) &&
|
|
43
|
+
Math.abs(a1 - b1) <= epsilon * Math.max(1, Math.abs(a1), Math.abs(b1))
|
|
44
|
+
);
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
/**
|
|
@@ -45,8 +51,7 @@ export function equals(a: Vector2Like, b: Vector2Like): boolean {
|
|
|
45
51
|
* @returns Whether the vectors are equivalent.
|
|
46
52
|
*/
|
|
47
53
|
export function exactEquals(a: Vector2Like, b: Vector2Like): boolean {
|
|
48
|
-
return a[0] == b[0]
|
|
49
|
-
&& a[1] == b[1];
|
|
54
|
+
return a[0] == b[0] && a[1] == b[1];
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
/**
|
|
@@ -56,7 +61,11 @@ export function exactEquals(a: Vector2Like, b: Vector2Like): boolean {
|
|
|
56
61
|
* @param out The vector to store the result in.
|
|
57
62
|
* @returns The sum.
|
|
58
63
|
*/
|
|
59
|
-
export function add<T extends Vector2Like>(
|
|
64
|
+
export function add<T extends Vector2Like>(
|
|
65
|
+
a: Vector2Like,
|
|
66
|
+
b: Vector2Like,
|
|
67
|
+
out: T
|
|
68
|
+
): T {
|
|
60
69
|
out[0] = a[0] + b[0];
|
|
61
70
|
out[1] = a[1] + b[1];
|
|
62
71
|
return out;
|
|
@@ -81,7 +90,11 @@ export function copy<T extends Vector2Like>(vector: Vector2Like, out: T): T {
|
|
|
81
90
|
* @param out The vector to store the result in.
|
|
82
91
|
* @returns The product.
|
|
83
92
|
*/
|
|
84
|
-
export function multiply<T extends Vector2Like>(
|
|
93
|
+
export function multiply<T extends Vector2Like>(
|
|
94
|
+
a: Vector2Like,
|
|
95
|
+
b: Vector2Like,
|
|
96
|
+
out: T
|
|
97
|
+
): T {
|
|
85
98
|
out[0] = a[0] * b[0];
|
|
86
99
|
out[1] = a[1] * b[1];
|
|
87
100
|
return out;
|
|
@@ -94,7 +107,11 @@ export function multiply<T extends Vector2Like>(a: Vector2Like, b: Vector2Like,
|
|
|
94
107
|
* @param out The vector to store the result in.
|
|
95
108
|
* @returns The quotient.
|
|
96
109
|
*/
|
|
97
|
-
export function divide<T extends Vector2Like>(
|
|
110
|
+
export function divide<T extends Vector2Like>(
|
|
111
|
+
a: Vector2Like,
|
|
112
|
+
b: Vector2Like,
|
|
113
|
+
out: T
|
|
114
|
+
): T {
|
|
98
115
|
out[0] = a[0] / b[0];
|
|
99
116
|
out[1] = a[1] / b[1];
|
|
100
117
|
return out;
|
|
@@ -107,7 +124,11 @@ export function divide<T extends Vector2Like>(a: Vector2Like, b: Vector2Like, ou
|
|
|
107
124
|
* @param out The vector to store the result in.
|
|
108
125
|
* @returns The difference.
|
|
109
126
|
*/
|
|
110
|
-
export function subtract<T extends Vector2Like>(
|
|
127
|
+
export function subtract<T extends Vector2Like>(
|
|
128
|
+
a: Vector2Like,
|
|
129
|
+
b: Vector2Like,
|
|
130
|
+
out: T
|
|
131
|
+
): T {
|
|
111
132
|
out[0] = a[0] - b[0];
|
|
112
133
|
out[1] = a[1] - b[1];
|
|
113
134
|
return out;
|
|
@@ -156,7 +177,11 @@ export function round<T extends Vector2Like>(vector: Vector2Like, out: T): T {
|
|
|
156
177
|
* @param out The vector to store the result in.
|
|
157
178
|
* @returns The minimum.
|
|
158
179
|
*/
|
|
159
|
-
export function min<T extends Vector2Like>(
|
|
180
|
+
export function min<T extends Vector2Like>(
|
|
181
|
+
a: Vector2Like,
|
|
182
|
+
b: Vector2Like,
|
|
183
|
+
out: T
|
|
184
|
+
): T {
|
|
160
185
|
out[0] = Math.min(a[0], b[0]);
|
|
161
186
|
out[1] = Math.min(a[1], b[1]);
|
|
162
187
|
return out;
|
|
@@ -169,7 +194,11 @@ export function min<T extends Vector2Like>(a: Vector2Like, b: Vector2Like, out:
|
|
|
169
194
|
* @param out The vector to store the result in.
|
|
170
195
|
* @returns The minimum.
|
|
171
196
|
*/
|
|
172
|
-
export function max<T extends Vector2Like>(
|
|
197
|
+
export function max<T extends Vector2Like>(
|
|
198
|
+
a: Vector2Like,
|
|
199
|
+
b: Vector2Like,
|
|
200
|
+
out: T
|
|
201
|
+
): T {
|
|
173
202
|
out[0] = Math.max(a[0], b[0]);
|
|
174
203
|
out[1] = Math.max(a[1], b[1]);
|
|
175
204
|
return out;
|
|
@@ -182,7 +211,11 @@ export function max<T extends Vector2Like>(a: Vector2Like, b: Vector2Like, out:
|
|
|
182
211
|
* @param out The vector to store the result in.
|
|
183
212
|
* @returns The product.
|
|
184
213
|
*/
|
|
185
|
-
export function scale<T extends Vector2Like>(
|
|
214
|
+
export function scale<T extends Vector2Like>(
|
|
215
|
+
vector: Vector2Like,
|
|
216
|
+
scalar: number,
|
|
217
|
+
out: T
|
|
218
|
+
): T {
|
|
186
219
|
out[0] = vector[0] * scalar;
|
|
187
220
|
out[1] = vector[1] * scalar;
|
|
188
221
|
return out;
|
|
@@ -196,7 +229,12 @@ export function scale<T extends Vector2Like>(vector: Vector2Like, scalar: number
|
|
|
196
229
|
* @param out The vector to store the result in.
|
|
197
230
|
* @returns The sum.
|
|
198
231
|
*/
|
|
199
|
-
export function scaleAndAdd<T extends Vector2Like>(
|
|
232
|
+
export function scaleAndAdd<T extends Vector2Like>(
|
|
233
|
+
a: Vector2Like,
|
|
234
|
+
b: Vector2Like,
|
|
235
|
+
scalar: number,
|
|
236
|
+
out: T
|
|
237
|
+
): T {
|
|
200
238
|
out[0] = a[0] + b[0] * scalar;
|
|
201
239
|
out[1] = a[1] + b[1] * scalar;
|
|
202
240
|
return out;
|
|
@@ -281,10 +319,13 @@ export function invert<T extends Vector2Like>(vector: Vector2Like, out: T): T {
|
|
|
281
319
|
* @returns The normalized vector.
|
|
282
320
|
* @see [Unit vector](https://en.wikipedia.org/wiki/Unit_vector)
|
|
283
321
|
*/
|
|
284
|
-
export function normalize<T extends Vector2Like>(
|
|
322
|
+
export function normalize<T extends Vector2Like>(
|
|
323
|
+
vector: Vector2Like,
|
|
324
|
+
out: T
|
|
325
|
+
): T {
|
|
285
326
|
const x: number = vector[0];
|
|
286
327
|
const y: number = vector[1];
|
|
287
|
-
|
|
328
|
+
|
|
288
329
|
let len: number = x * x + y * y;
|
|
289
330
|
if (len > 0) {
|
|
290
331
|
len = 1 / Math.sqrt(len);
|
|
@@ -314,8 +355,12 @@ export function dot(a: Vector2Like, b: Vector2Like): number {
|
|
|
314
355
|
* @returns The cross product.
|
|
315
356
|
* @see [Cross product](https://en.wikipedia.org/wiki/Cross_product)
|
|
316
357
|
*/
|
|
317
|
-
export function cross<T extends Vector3Like>(
|
|
318
|
-
|
|
358
|
+
export function cross<T extends Vector3Like>(
|
|
359
|
+
a: Vector2Like,
|
|
360
|
+
b: Vector2Like,
|
|
361
|
+
out: T
|
|
362
|
+
): T {
|
|
363
|
+
const z: number = a[0] * b[1] - a[1] * b[0];
|
|
319
364
|
out[0] = 0;
|
|
320
365
|
out[1] = 0;
|
|
321
366
|
out[2] = z;
|
|
@@ -331,7 +376,12 @@ export function cross<T extends Vector3Like>(a: Vector2Like, b: Vector2Like, out
|
|
|
331
376
|
* @returns The interpolated vector.
|
|
332
377
|
* @see [Linear interpolation](https://en.wikipedia.org/wiki/Linear_interpolation)
|
|
333
378
|
*/
|
|
334
|
-
export function lerp<T extends Vector2Like>(
|
|
379
|
+
export function lerp<T extends Vector2Like>(
|
|
380
|
+
a: Vector2Like,
|
|
381
|
+
b: Vector2Like,
|
|
382
|
+
t: number,
|
|
383
|
+
out: T
|
|
384
|
+
): T {
|
|
335
385
|
const ax: number = a[0];
|
|
336
386
|
const ay: number = a[1];
|
|
337
387
|
|
|
@@ -362,7 +412,11 @@ export function random<T extends Vector2Like>(magnitude: number, out: T): T {
|
|
|
362
412
|
* @returns The transformed vector.
|
|
363
413
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
364
414
|
*/
|
|
365
|
-
export function transformMatrix2<T extends Vector2Like>(
|
|
415
|
+
export function transformMatrix2<T extends Vector2Like>(
|
|
416
|
+
vector: Vector2Like,
|
|
417
|
+
matrix: Matrix2Like,
|
|
418
|
+
out: T
|
|
419
|
+
): T {
|
|
366
420
|
const x: number = vector[0];
|
|
367
421
|
const y: number = vector[1];
|
|
368
422
|
|
|
@@ -379,7 +433,11 @@ export function transformMatrix2<T extends Vector2Like>(vector: Vector2Like, mat
|
|
|
379
433
|
* @returns The transformed vector.
|
|
380
434
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
381
435
|
*/
|
|
382
|
-
export function transformMatrix3<T extends Vector2Like>(
|
|
436
|
+
export function transformMatrix3<T extends Vector2Like>(
|
|
437
|
+
vector: Vector2Like,
|
|
438
|
+
matrix: Matrix3Like,
|
|
439
|
+
out: T
|
|
440
|
+
): T {
|
|
383
441
|
const x: number = vector[0] as number;
|
|
384
442
|
const y: number = vector[1] as number;
|
|
385
443
|
|
|
@@ -396,7 +454,11 @@ export function transformMatrix3<T extends Vector2Like>(vector: Vector2Like, mat
|
|
|
396
454
|
* @returns The transformed vector.
|
|
397
455
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
398
456
|
*/
|
|
399
|
-
export function transformMatrix4<T extends Vector2Like>(
|
|
457
|
+
export function transformMatrix4<T extends Vector2Like>(
|
|
458
|
+
vector: Vector2Like,
|
|
459
|
+
matrix: Matrix4Like,
|
|
460
|
+
out: T
|
|
461
|
+
): T {
|
|
400
462
|
const x: number = vector[0] as number;
|
|
401
463
|
const y: number = vector[1] as number;
|
|
402
464
|
|
|
@@ -413,7 +475,12 @@ export function transformMatrix4<T extends Vector2Like>(vector: Vector2Like, mat
|
|
|
413
475
|
* @param out The vector to store the result in.
|
|
414
476
|
* @returns The rotated vector.
|
|
415
477
|
*/
|
|
416
|
-
export function rotate<T extends Vector2Like>(
|
|
478
|
+
export function rotate<T extends Vector2Like>(
|
|
479
|
+
vector: Vector2Like,
|
|
480
|
+
origin: Vector2Like,
|
|
481
|
+
radians: number,
|
|
482
|
+
out: T
|
|
483
|
+
): T {
|
|
417
484
|
const o0: number = origin[0];
|
|
418
485
|
const o1: number = origin[1];
|
|
419
486
|
|
|
@@ -422,7 +489,7 @@ export function rotate<T extends Vector2Like>(vector: Vector2Like, origin: Vecto
|
|
|
422
489
|
|
|
423
490
|
const s: number = Math.sin(radians);
|
|
424
491
|
const c: number = Math.cos(radians);
|
|
425
|
-
|
|
492
|
+
|
|
426
493
|
out[0] = p0 * c - p1 * s + o0;
|
|
427
494
|
out[1] = p0 * s + p1 * c + o1;
|
|
428
495
|
return out;
|
|
@@ -441,7 +508,8 @@ export function angle(a: Vector2Like, b: Vector2Like): number {
|
|
|
441
508
|
const x2: number = b[0];
|
|
442
509
|
const y2: number = b[1];
|
|
443
510
|
|
|
444
|
-
const magnitudeProduct: number =
|
|
511
|
+
const magnitudeProduct: number =
|
|
512
|
+
Math.sqrt(x1 * x1 + y1 * y1) * Math.sqrt(x2 * x2 + y2 * y2);
|
|
445
513
|
const c: number = magnitudeProduct && (x1 * x2 + y1 * y2) / magnitudeProduct;
|
|
446
514
|
return Math.acos(Math.min(Math.max(c, -1), 1));
|
|
447
515
|
}
|
|
@@ -462,43 +530,51 @@ export function zero<T extends Vector2Like>(out: T): T {
|
|
|
462
530
|
* @see [Euclidean vector](https://en.wikipedia.org/wiki/Euclidean_vector)
|
|
463
531
|
*/
|
|
464
532
|
export default class Vector2 extends Float32Array implements Vector {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
533
|
+
/**
|
|
534
|
+
* Creates a vector with the given values.
|
|
535
|
+
* @param x The first component.
|
|
536
|
+
* @param y The second component.
|
|
537
|
+
* @returns A new vector.
|
|
538
|
+
*/
|
|
539
|
+
public static fromValues(x: number, y: number): Vector2;
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Creates a vector with the given values.
|
|
543
|
+
* @param x The first component.
|
|
544
|
+
* @param y The second component.
|
|
545
|
+
* @param out The vector to store the result in.
|
|
546
|
+
* @returns A new vector.
|
|
547
|
+
*/
|
|
548
|
+
public static fromValues<T extends Vector2Like>(
|
|
549
|
+
x: number,
|
|
550
|
+
y: number,
|
|
551
|
+
out: T
|
|
552
|
+
): T;
|
|
553
|
+
|
|
554
|
+
public static fromValues<T extends Vector2Like>(
|
|
555
|
+
x: number,
|
|
556
|
+
y: number,
|
|
557
|
+
out: T = new Vector2() as T
|
|
558
|
+
): T {
|
|
559
|
+
return fromValues(x, y, out);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
487
563
|
* Creates a two-dimensional zero vector.
|
|
488
564
|
* @see [Euclidean vector](https://en.wikipedia.org/wiki/Euclidean_vector)
|
|
489
565
|
*/
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
566
|
+
public constructor() {
|
|
567
|
+
super(2);
|
|
568
|
+
}
|
|
493
569
|
|
|
494
|
-
|
|
570
|
+
/**
|
|
495
571
|
* Determines whether this vector is roughly equivalent to another.
|
|
496
572
|
* @param vector The other vector.
|
|
497
573
|
* @returns Whether the vectors are equivalent.
|
|
498
574
|
*/
|
|
499
575
|
public equals(vector: Vector2Like): boolean {
|
|
500
|
-
|
|
501
|
-
|
|
576
|
+
return equals(this, vector);
|
|
577
|
+
}
|
|
502
578
|
|
|
503
579
|
/**
|
|
504
580
|
* Determines whether this vector is exactly equivalent to another.
|
|
@@ -506,46 +582,49 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
506
582
|
* @returns Whether the vectors are equivalent.
|
|
507
583
|
*/
|
|
508
584
|
public exactEquals(vector: Vector2Like): boolean {
|
|
509
|
-
|
|
510
|
-
|
|
585
|
+
return exactEquals(this, vector);
|
|
586
|
+
}
|
|
511
587
|
|
|
512
|
-
|
|
588
|
+
/**
|
|
513
589
|
* Adds another vector to this one.
|
|
514
590
|
* @param vector The other vector.
|
|
515
591
|
* @returns The sum of the vectors.
|
|
516
592
|
*/
|
|
517
593
|
public add(vector: Vector2Like): Vector2;
|
|
518
594
|
|
|
519
|
-
|
|
595
|
+
/**
|
|
520
596
|
* Adds another vector to this one.
|
|
521
597
|
* @param vector The other vector.
|
|
522
|
-
|
|
598
|
+
* @param out The vector to store the result in.
|
|
523
599
|
* @returns The sum of the vectors.
|
|
524
600
|
*/
|
|
525
601
|
public add<T extends Vector2Like>(vector: Vector2Like, out: T): T;
|
|
526
602
|
|
|
527
|
-
public add<T extends Vector2Like>(
|
|
603
|
+
public add<T extends Vector2Like>(
|
|
604
|
+
vector: Vector2Like,
|
|
605
|
+
out: T = new Vector2() as T
|
|
606
|
+
): T {
|
|
528
607
|
return add(this, vector, out);
|
|
529
608
|
}
|
|
530
609
|
|
|
531
610
|
/**
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
611
|
+
* Creates a copy of this vector.
|
|
612
|
+
* @returns The copy.
|
|
613
|
+
*/
|
|
614
|
+
public clone(): Vector2;
|
|
536
615
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
public clone<T extends Vector2Like>(out: T = new Vector2() as T): T {
|
|
545
|
-
return copy(this, out);
|
|
546
|
-
}
|
|
616
|
+
/**
|
|
617
|
+
* Copies the values from this vector to another one.
|
|
618
|
+
* @param out The vector to store the result in.
|
|
619
|
+
* @returns The copy.
|
|
620
|
+
*/
|
|
621
|
+
public clone<T extends Vector2Like>(out: T): T;
|
|
547
622
|
|
|
548
|
-
|
|
623
|
+
public clone<T extends Vector2Like>(out: T = new Vector2() as T): T {
|
|
624
|
+
return copy(this, out);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/**
|
|
549
628
|
* Copies the values of another vector into this one.
|
|
550
629
|
* @param vector The vector to copy.
|
|
551
630
|
* @returns This vector.
|
|
@@ -554,60 +633,69 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
554
633
|
return copy(vector, this);
|
|
555
634
|
}
|
|
556
635
|
|
|
557
|
-
|
|
636
|
+
/**
|
|
558
637
|
* Multiplies the components in this vector by the corresponding components in another.
|
|
559
638
|
* @param vector The other vector.
|
|
560
639
|
* @returns The product of the vectors.
|
|
561
640
|
*/
|
|
562
641
|
public multiply(vector: Vector2Like): Vector2;
|
|
563
642
|
|
|
564
|
-
|
|
643
|
+
/**
|
|
565
644
|
* Multiplies the components in this vector by the corresponding components in another.
|
|
566
645
|
* @param vector The other vector.
|
|
567
|
-
|
|
646
|
+
* @param out The vector to store the result in.
|
|
568
647
|
* @returns The product of the vectors.
|
|
569
648
|
*/
|
|
570
649
|
public multiply<T extends Vector2Like>(vector: Vector2Like, out: T): T;
|
|
571
650
|
|
|
572
|
-
public multiply<T extends Vector2Like>(
|
|
651
|
+
public multiply<T extends Vector2Like>(
|
|
652
|
+
vector: Vector2Like,
|
|
653
|
+
out: T = new Vector2() as T
|
|
654
|
+
): T {
|
|
573
655
|
return multiply(this, vector, out);
|
|
574
656
|
}
|
|
575
657
|
|
|
576
|
-
|
|
658
|
+
/**
|
|
577
659
|
* Divides this vector by another.
|
|
578
660
|
* @param vector The other vector.
|
|
579
661
|
* @returns The quotient of the vectors.
|
|
580
662
|
*/
|
|
581
663
|
public divide(vector: Vector2Like): Vector2;
|
|
582
664
|
|
|
583
|
-
|
|
665
|
+
/**
|
|
584
666
|
* Divides this vector by another.
|
|
585
667
|
* @param vector The other vector.
|
|
586
|
-
|
|
668
|
+
* @param out The vector to store the result in.
|
|
587
669
|
* @returns The quotient of the vectors.
|
|
588
670
|
*/
|
|
589
671
|
public divide<T extends Vector2Like>(vector: Vector2Like, out: T): T;
|
|
590
672
|
|
|
591
|
-
public divide<T extends Vector2Like>(
|
|
673
|
+
public divide<T extends Vector2Like>(
|
|
674
|
+
vector: Vector2Like,
|
|
675
|
+
out: T = new Vector2() as T
|
|
676
|
+
): T {
|
|
592
677
|
return divide(this, vector, out);
|
|
593
678
|
}
|
|
594
679
|
|
|
595
|
-
|
|
680
|
+
/**
|
|
596
681
|
* Subtracts another vector from this one.
|
|
597
682
|
* @param vector The other vector.
|
|
598
683
|
* @returns The difference between the vectors.
|
|
599
684
|
*/
|
|
600
685
|
public subtract(vector: Vector2Like): Vector2;
|
|
601
686
|
|
|
602
|
-
|
|
687
|
+
/**
|
|
603
688
|
* Subtracts another vector from this one.
|
|
604
689
|
* @param vector The other vector.
|
|
605
|
-
|
|
690
|
+
* @param out The vector to store the result in.
|
|
606
691
|
* @returns The difference between the vectors.
|
|
607
692
|
*/
|
|
608
693
|
public subtract<T extends Vector2Like>(vector: Vector2Like, out: T): T;
|
|
609
694
|
|
|
610
|
-
public subtract<T extends Vector2Like>(
|
|
695
|
+
public subtract<T extends Vector2Like>(
|
|
696
|
+
vector: Vector2Like,
|
|
697
|
+
out: T = new Vector2() as T
|
|
698
|
+
): T {
|
|
611
699
|
return subtract(this, vector, out);
|
|
612
700
|
}
|
|
613
701
|
|
|
@@ -617,16 +705,16 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
617
705
|
*/
|
|
618
706
|
public ceil(): Vector2;
|
|
619
707
|
|
|
620
|
-
|
|
708
|
+
/**
|
|
621
709
|
* Rounds up the components of this vector.
|
|
622
|
-
|
|
710
|
+
* @param out The vector to store the result in.
|
|
623
711
|
* @returns The rounded vector.
|
|
624
712
|
*/
|
|
625
713
|
public ceil<T extends Vector2Like>(out: T): T;
|
|
626
714
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
715
|
+
public ceil<T extends Vector2Like>(out: T = new Vector2() as T): T {
|
|
716
|
+
return ceil(this, out);
|
|
717
|
+
}
|
|
630
718
|
|
|
631
719
|
/**
|
|
632
720
|
* Rounds down the components of this vector.
|
|
@@ -634,16 +722,16 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
634
722
|
*/
|
|
635
723
|
public floor(): Vector2;
|
|
636
724
|
|
|
637
|
-
|
|
725
|
+
/**
|
|
638
726
|
* Rounds down the components of this vector.
|
|
639
|
-
|
|
727
|
+
* @param out The vector to store the result in.
|
|
640
728
|
* @returns The rounded vector.
|
|
641
729
|
*/
|
|
642
730
|
public floor<T extends Vector2Like>(out: T): T;
|
|
643
731
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
732
|
+
public floor<T extends Vector2Like>(out: T = new Vector2() as T): T {
|
|
733
|
+
return floor(this, out);
|
|
734
|
+
}
|
|
647
735
|
|
|
648
736
|
/**
|
|
649
737
|
* Rounds the components of this vector.
|
|
@@ -651,16 +739,16 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
651
739
|
*/
|
|
652
740
|
public round(): Vector2;
|
|
653
741
|
|
|
654
|
-
|
|
742
|
+
/**
|
|
655
743
|
* Rounds the components of this vector.
|
|
656
|
-
|
|
744
|
+
* @param out The vector to store the result in.
|
|
657
745
|
* @returns The rounded vector.
|
|
658
746
|
*/
|
|
659
747
|
public round<T extends Vector2Like>(out: T): T;
|
|
660
748
|
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
749
|
+
public round<T extends Vector2Like>(out: T = new Vector2() as T): T {
|
|
750
|
+
return round(this, out);
|
|
751
|
+
}
|
|
664
752
|
|
|
665
753
|
/**
|
|
666
754
|
* Returns the minimum of this and another vector.
|
|
@@ -669,17 +757,20 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
669
757
|
*/
|
|
670
758
|
public min(vector: Vector2Like): Vector2;
|
|
671
759
|
|
|
672
|
-
|
|
760
|
+
/**
|
|
673
761
|
* Returns the minimum of this and another vector.
|
|
674
762
|
* @param vector The other vector.
|
|
675
|
-
|
|
763
|
+
* @param out The vector to store the result in.
|
|
676
764
|
* @returns The minimum.
|
|
677
765
|
*/
|
|
678
766
|
public min<T extends Vector2Like>(vector: Vector2Like, out: T): T;
|
|
679
767
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
768
|
+
public min<T extends Vector2Like>(
|
|
769
|
+
vector: Vector2Like,
|
|
770
|
+
out: T = new Vector2() as T
|
|
771
|
+
): T {
|
|
772
|
+
return min(this, vector, out);
|
|
773
|
+
}
|
|
683
774
|
|
|
684
775
|
/**
|
|
685
776
|
* Returns the maximum of this and another vector.
|
|
@@ -688,17 +779,20 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
688
779
|
*/
|
|
689
780
|
public max(vector: Vector2Like): Vector2;
|
|
690
781
|
|
|
691
|
-
|
|
782
|
+
/**
|
|
692
783
|
* Returns the maximum of this and another vector.
|
|
693
784
|
* @param vector The other vector.
|
|
694
|
-
|
|
785
|
+
* @param out The vector to store the result in.
|
|
695
786
|
* @returns The maximum.
|
|
696
787
|
*/
|
|
697
788
|
public max<T extends Vector2Like>(vector: Vector2Like, out: T): T;
|
|
698
789
|
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
790
|
+
public max<T extends Vector2Like>(
|
|
791
|
+
vector: Vector2Like,
|
|
792
|
+
out: T = new Vector2() as T
|
|
793
|
+
): T {
|
|
794
|
+
return max(this, vector, out);
|
|
795
|
+
}
|
|
702
796
|
|
|
703
797
|
/**
|
|
704
798
|
* Scales this vector by a scalar.
|
|
@@ -707,17 +801,20 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
707
801
|
*/
|
|
708
802
|
public scale(scalar: number): Vector2;
|
|
709
803
|
|
|
710
|
-
|
|
804
|
+
/**
|
|
711
805
|
* Scales this vector by a scalar.
|
|
712
806
|
* @param scalar The scalar.
|
|
713
|
-
|
|
807
|
+
* @param out The vector to store the result in.
|
|
714
808
|
* @returns The scaled vector.
|
|
715
809
|
*/
|
|
716
810
|
public scale<T extends Vector2Like>(scalar: number, out: T): T;
|
|
717
811
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
812
|
+
public scale<T extends Vector2Like>(
|
|
813
|
+
scalar: number,
|
|
814
|
+
out: T = new Vector2() as T
|
|
815
|
+
): T {
|
|
816
|
+
return scale(this, scalar, out);
|
|
817
|
+
}
|
|
721
818
|
|
|
722
819
|
/**
|
|
723
820
|
* Adds another vector to this one after scaling the other by a scalar.
|
|
@@ -727,18 +824,26 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
727
824
|
*/
|
|
728
825
|
public scaleAndAdd(vector: Vector2Like, scalar: number): Vector2;
|
|
729
826
|
|
|
730
|
-
|
|
827
|
+
/**
|
|
731
828
|
* Adds another vector to this one after scaling the other by a scalar.
|
|
732
829
|
* @param vector The other vector.
|
|
733
830
|
* @param scalar The scalar.
|
|
734
|
-
|
|
831
|
+
* @param out The vector to store the result in.
|
|
735
832
|
* @returns The sum.
|
|
736
833
|
*/
|
|
737
|
-
public scaleAndAdd<T extends Vector2Like>(
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
834
|
+
public scaleAndAdd<T extends Vector2Like>(
|
|
835
|
+
vector: Vector2Like,
|
|
836
|
+
scalar: number,
|
|
837
|
+
out: T
|
|
838
|
+
): T;
|
|
839
|
+
|
|
840
|
+
public scaleAndAdd<T extends Vector2Like>(
|
|
841
|
+
vector: Vector2Like,
|
|
842
|
+
scalar: number,
|
|
843
|
+
out: T = new Vector2() as T
|
|
844
|
+
): T {
|
|
845
|
+
return scaleAndAdd(this, vector, scalar, out);
|
|
846
|
+
}
|
|
742
847
|
|
|
743
848
|
/**
|
|
744
849
|
* Calculates the Euclidean distance from this vector to another.
|
|
@@ -747,8 +852,8 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
747
852
|
* @see [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance)
|
|
748
853
|
*/
|
|
749
854
|
public distance(vector: Vector2Like): number {
|
|
750
|
-
|
|
751
|
-
|
|
855
|
+
return distance(this, vector);
|
|
856
|
+
}
|
|
752
857
|
|
|
753
858
|
/**
|
|
754
859
|
* Calculates the squared Euclidean distance from this vector to another.
|
|
@@ -757,18 +862,18 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
757
862
|
* @see [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance)
|
|
758
863
|
*/
|
|
759
864
|
public squaredDistance(vector: Vector2Like): number {
|
|
760
|
-
|
|
761
|
-
|
|
865
|
+
return squaredDistance(this, vector);
|
|
866
|
+
}
|
|
762
867
|
|
|
763
868
|
/** The magnitude (length) of this vector. */
|
|
764
869
|
public get magnitude(): number {
|
|
765
|
-
|
|
766
|
-
|
|
870
|
+
return getMagnitude(this);
|
|
871
|
+
}
|
|
767
872
|
|
|
768
873
|
/** The squared magnitude (length) of this vector. */
|
|
769
874
|
public get squaredMagnitude(): number {
|
|
770
|
-
|
|
771
|
-
|
|
875
|
+
return getSquaredMagnitude(this);
|
|
876
|
+
}
|
|
772
877
|
|
|
773
878
|
/**
|
|
774
879
|
* Negates this vector.
|
|
@@ -776,52 +881,52 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
776
881
|
*/
|
|
777
882
|
public negate(): Vector2;
|
|
778
883
|
|
|
779
|
-
|
|
884
|
+
/**
|
|
780
885
|
* Negates this vector.
|
|
781
|
-
|
|
886
|
+
* @param out The vector to store the result in.
|
|
782
887
|
* @returns The negated vector.
|
|
783
888
|
*/
|
|
784
889
|
public negate<T extends Vector2Like>(out: T): T;
|
|
785
890
|
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
891
|
+
public negate<T extends Vector2Like>(out: T = new Vector2() as T): T {
|
|
892
|
+
return negate(this, out);
|
|
893
|
+
}
|
|
789
894
|
|
|
790
|
-
|
|
895
|
+
/**
|
|
791
896
|
* Calculates the multiplicative inverse of the components of this vector.
|
|
792
897
|
* @returns The inverted vector.
|
|
793
898
|
*/
|
|
794
899
|
public invert(): Vector2;
|
|
795
900
|
|
|
796
|
-
|
|
901
|
+
/**
|
|
797
902
|
* Calculates the multiplicative inverse of the components of this vector.
|
|
798
|
-
|
|
903
|
+
* @param out The vector to store the result in.
|
|
799
904
|
* @returns The inverted vector.
|
|
800
905
|
*/
|
|
801
906
|
public invert<T extends Vector2Like>(out: T): T;
|
|
802
907
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
908
|
+
public invert<T extends Vector2Like>(out: T = new Vector2() as T): T {
|
|
909
|
+
return invert(this, out);
|
|
910
|
+
}
|
|
806
911
|
|
|
807
|
-
|
|
912
|
+
/**
|
|
808
913
|
* Normalizes this vector.
|
|
809
914
|
* @returns The normalized vector.
|
|
810
915
|
* @see [Unit vector](https://en.wikipedia.org/wiki/Unit_vector)
|
|
811
916
|
*/
|
|
812
917
|
public normalize(): Vector2;
|
|
813
918
|
|
|
814
|
-
|
|
919
|
+
/**
|
|
815
920
|
* Normalizes this vector.
|
|
816
|
-
|
|
921
|
+
* @param out The vector to store the result in.
|
|
817
922
|
* @returns The normalized vector.
|
|
818
923
|
* @see [Unit vector](https://en.wikipedia.org/wiki/Unit_vector)
|
|
819
924
|
*/
|
|
820
925
|
public normalize<T extends Vector2Like>(out: T): T;
|
|
821
926
|
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
927
|
+
public normalize<T extends Vector2Like>(out: T = new Vector2() as T): T {
|
|
928
|
+
return normalize(this, out);
|
|
929
|
+
}
|
|
825
930
|
|
|
826
931
|
/**
|
|
827
932
|
* Calculates the dot product of this and another vector.
|
|
@@ -830,10 +935,10 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
830
935
|
* @see [Dot product](https://en.wikipedia.org/wiki/Dot_product)
|
|
831
936
|
*/
|
|
832
937
|
public dot(vector: Vector2Like): number {
|
|
833
|
-
|
|
834
|
-
|
|
938
|
+
return dot(this, vector);
|
|
939
|
+
}
|
|
835
940
|
|
|
836
|
-
|
|
941
|
+
/**
|
|
837
942
|
* Calculates the cross product of this and another vector.
|
|
838
943
|
* @param vector The other vector.
|
|
839
944
|
* @returns The cross product.
|
|
@@ -841,18 +946,21 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
841
946
|
*/
|
|
842
947
|
public cross(vector: Vector2Like): Vector3;
|
|
843
948
|
|
|
844
|
-
|
|
949
|
+
/**
|
|
845
950
|
* Calculates the cross product of this and another vector.
|
|
846
951
|
* @param vector The other vector.
|
|
847
|
-
|
|
952
|
+
* @param out The vector to store the result in.
|
|
848
953
|
* @returns The cross product.
|
|
849
954
|
* @see [Cross product](https://en.wikipedia.org/wiki/Cross_product)
|
|
850
955
|
*/
|
|
851
956
|
public cross<T extends Vector3Like>(vector: Vector2Like, out: T): T;
|
|
852
957
|
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
958
|
+
public cross<T extends Vector3Like>(
|
|
959
|
+
vector: Vector2Like,
|
|
960
|
+
out: T = new Vector3() as T
|
|
961
|
+
): T {
|
|
962
|
+
return cross(this, vector, out);
|
|
963
|
+
}
|
|
856
964
|
|
|
857
965
|
/**
|
|
858
966
|
* Performs a linear interpolation between this and another vector.
|
|
@@ -863,19 +971,23 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
863
971
|
*/
|
|
864
972
|
public lerp(vector: Vector2Like, t: number): Vector2;
|
|
865
973
|
|
|
866
|
-
|
|
974
|
+
/**
|
|
867
975
|
* Performs a linear interpolation between this and another vector.
|
|
868
976
|
* @param vector The other vector.
|
|
869
977
|
* @param t The interpolation amount (in `[0,1]`).
|
|
870
|
-
|
|
978
|
+
* @param out The vector to store the result in.
|
|
871
979
|
* @returns The interpolated vector.
|
|
872
980
|
* @see [Linear interpolation](https://en.wikipedia.org/wiki/Linear_interpolation)
|
|
873
981
|
*/
|
|
874
982
|
public lerp<T extends Vector2Like>(vector: Vector2Like, t: number, out: T): T;
|
|
875
983
|
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
984
|
+
public lerp<T extends Vector2Like>(
|
|
985
|
+
vector: Vector2Like,
|
|
986
|
+
t: number,
|
|
987
|
+
out: T = new Vector2() as T
|
|
988
|
+
): T {
|
|
989
|
+
return lerp(this, vector, t, out);
|
|
990
|
+
}
|
|
879
991
|
|
|
880
992
|
/**
|
|
881
993
|
* Sets this vector to a random value with the given magnitude.
|
|
@@ -883,8 +995,8 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
883
995
|
* @returns This vector.
|
|
884
996
|
*/
|
|
885
997
|
public random(magnitude = 1): this {
|
|
886
|
-
|
|
887
|
-
|
|
998
|
+
return random(magnitude, this);
|
|
999
|
+
}
|
|
888
1000
|
|
|
889
1001
|
/**
|
|
890
1002
|
* Transforms this vector by a two-by-two matrix.
|
|
@@ -894,20 +1006,26 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
894
1006
|
*/
|
|
895
1007
|
public transformMatrix2(matrix: Matrix2Like): Vector2;
|
|
896
1008
|
|
|
897
|
-
|
|
1009
|
+
/**
|
|
898
1010
|
* Transforms this vector by a two-by-two matrix.
|
|
899
1011
|
* @param matrix The matrix.
|
|
900
|
-
|
|
1012
|
+
* @param out The vector to store the result in.
|
|
901
1013
|
* @returns The transformed vector.
|
|
902
1014
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
903
1015
|
*/
|
|
904
|
-
public transformMatrix2<T extends Vector2Like>(
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
1016
|
+
public transformMatrix2<T extends Vector2Like>(
|
|
1017
|
+
matrix: Matrix2Like,
|
|
1018
|
+
out: T
|
|
1019
|
+
): T;
|
|
1020
|
+
|
|
1021
|
+
public transformMatrix2<T extends Vector2Like>(
|
|
1022
|
+
matrix: Matrix2Like,
|
|
1023
|
+
out: T = new Vector2() as T
|
|
1024
|
+
): T {
|
|
1025
|
+
return transformMatrix2(this, matrix, out);
|
|
1026
|
+
}
|
|
909
1027
|
|
|
910
|
-
|
|
1028
|
+
/**
|
|
911
1029
|
* Transforms this vector by a three-by-three matrix.
|
|
912
1030
|
* @param matrix The matrix.
|
|
913
1031
|
* @returns The transformed vector.
|
|
@@ -915,20 +1033,26 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
915
1033
|
*/
|
|
916
1034
|
public transformMatrix3(matrix: Matrix3Like): Vector2;
|
|
917
1035
|
|
|
918
|
-
|
|
1036
|
+
/**
|
|
919
1037
|
* Transforms this vector by a three-by-three matrix.
|
|
920
1038
|
* @param matrix The matrix.
|
|
921
|
-
|
|
1039
|
+
* @param out The vector to store the result in.
|
|
922
1040
|
* @returns The transformed vector.
|
|
923
1041
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
924
1042
|
*/
|
|
925
|
-
public transformMatrix3<T extends Vector2Like>(
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
1043
|
+
public transformMatrix3<T extends Vector2Like>(
|
|
1044
|
+
matrix: Matrix3Like,
|
|
1045
|
+
out: T
|
|
1046
|
+
): T;
|
|
1047
|
+
|
|
1048
|
+
public transformMatrix3<T extends Vector2Like>(
|
|
1049
|
+
matrix: Matrix3Like,
|
|
1050
|
+
out: T = new Vector2() as T
|
|
1051
|
+
): T {
|
|
1052
|
+
return transformMatrix3(this, matrix, out);
|
|
1053
|
+
}
|
|
930
1054
|
|
|
931
|
-
|
|
1055
|
+
/**
|
|
932
1056
|
* Transforms this vector by a four-by-four matrix.
|
|
933
1057
|
* @param matrix The matrix.
|
|
934
1058
|
* @returns The transformed vector.
|
|
@@ -936,54 +1060,68 @@ export default class Vector2 extends Float32Array implements Vector {
|
|
|
936
1060
|
*/
|
|
937
1061
|
public transformMatrix4(matrix: Matrix4Like): Vector2;
|
|
938
1062
|
|
|
939
|
-
|
|
1063
|
+
/**
|
|
940
1064
|
* Transforms this vector by a four-by-four matrix.
|
|
941
1065
|
* @param matrix The matrix.
|
|
942
|
-
|
|
1066
|
+
* @param out The vector to store the result in.
|
|
943
1067
|
* @returns The transformed vector.
|
|
944
1068
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
945
1069
|
*/
|
|
946
|
-
public transformMatrix4<T extends Vector2Like>(
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
1070
|
+
public transformMatrix4<T extends Vector2Like>(
|
|
1071
|
+
matrix: Matrix4Like,
|
|
1072
|
+
out: T
|
|
1073
|
+
): T;
|
|
1074
|
+
|
|
1075
|
+
public transformMatrix4<T extends Vector2Like>(
|
|
1076
|
+
matrix: Matrix4Like,
|
|
1077
|
+
out: T = new Vector2() as T
|
|
1078
|
+
): T {
|
|
1079
|
+
return transformMatrix4(this, matrix, out);
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
/**
|
|
1083
|
+
* Rotates this vector.
|
|
1084
|
+
* @param origin The origin of the rotation.
|
|
1085
|
+
* @param radians The angle of rotation in radians.
|
|
1086
|
+
* @returns The rotated vector.
|
|
1087
|
+
*/
|
|
1088
|
+
public rotate(origin: Vector2Like, radians: number): Vector2;
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* Rotates this vector.
|
|
1092
|
+
* @param origin The origin of the rotation.
|
|
1093
|
+
* @param radians The angle of rotation in radians.
|
|
1094
|
+
* @param out The vector to store the result in.
|
|
1095
|
+
* @returns The rotated vector.
|
|
1096
|
+
*/
|
|
1097
|
+
public rotate<T extends Vector2Like>(
|
|
1098
|
+
origin: Vector2Like,
|
|
1099
|
+
radians: number,
|
|
1100
|
+
out: T
|
|
1101
|
+
): T;
|
|
1102
|
+
|
|
1103
|
+
public rotate<T extends Vector2Like>(
|
|
1104
|
+
origin: Vector2Like,
|
|
1105
|
+
radians: number,
|
|
1106
|
+
out: T = new Vector2() as T
|
|
1107
|
+
): T {
|
|
1108
|
+
return rotate(this, origin, radians, out);
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
/**
|
|
1112
|
+
* Gets the angle from this to another vector in radians.
|
|
1113
|
+
* @param vector The other vector.
|
|
1114
|
+
* @returns The angular distance.
|
|
1115
|
+
*/
|
|
1116
|
+
public angle(vector: Vector2Like): number {
|
|
1117
|
+
return angle(this, vector);
|
|
1118
|
+
}
|
|
981
1119
|
|
|
982
1120
|
/**
|
|
983
1121
|
* Sets this to the zero vector.
|
|
984
1122
|
* @returns This vector.
|
|
985
1123
|
*/
|
|
986
1124
|
public zero(): this {
|
|
987
|
-
|
|
988
|
-
|
|
1125
|
+
return zero(this);
|
|
1126
|
+
}
|
|
989
1127
|
}
|