@lakuna/umath 1.5.0 → 2.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.
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/linalg/DualQuaternion.d.ts +23 -46
- package/dist/linalg/DualQuaternion.d.ts.map +1 -1
- package/dist/linalg/DualQuaternion.js +47 -70
- package/dist/linalg/DualQuaternion.js.map +1 -1
- package/dist/linalg/Matrix2.d.ts +14 -28
- package/dist/linalg/Matrix2.d.ts.map +1 -1
- package/dist/linalg/Matrix2.js +28 -42
- package/dist/linalg/Matrix2.js.map +1 -1
- package/dist/linalg/Matrix3.d.ts +21 -42
- package/dist/linalg/Matrix3.d.ts.map +1 -1
- package/dist/linalg/Matrix3.js +43 -84
- package/dist/linalg/Matrix3.js.map +1 -1
- package/dist/linalg/Matrix4.d.ts +39 -78
- package/dist/linalg/Matrix4.d.ts.map +1 -1
- package/dist/linalg/Matrix4.js +85 -170
- package/dist/linalg/Matrix4.js.map +1 -1
- package/dist/linalg/Quaternion.d.ts +27 -58
- package/dist/linalg/Quaternion.d.ts.map +1 -1
- package/dist/linalg/Quaternion.js +54 -85
- package/dist/linalg/Quaternion.js.map +1 -1
- package/dist/linalg/SlowMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowMatrix.js +52 -78
- package/dist/linalg/SlowMatrix.js.map +1 -1
- package/dist/linalg/SlowVector.d.ts +165 -0
- package/dist/linalg/SlowVector.d.ts.map +1 -0
- package/dist/linalg/SlowVector.js +369 -0
- package/dist/linalg/SlowVector.js.map +1 -0
- package/dist/linalg/Vector.d.ts +14 -15
- package/dist/linalg/Vector.d.ts.map +1 -1
- package/dist/linalg/Vector2.d.ts +28 -50
- package/dist/linalg/Vector2.d.ts.map +1 -1
- package/dist/linalg/Vector2.js +59 -85
- package/dist/linalg/Vector2.js.map +1 -1
- package/dist/linalg/Vector3.d.ts +32 -58
- package/dist/linalg/Vector3.d.ts.map +1 -1
- package/dist/linalg/Vector3.js +67 -107
- package/dist/linalg/Vector3.js.map +1 -1
- package/dist/linalg/Vector4.d.ts +26 -46
- package/dist/linalg/Vector4.d.ts.map +1 -1
- package/dist/linalg/Vector4.js +54 -82
- package/dist/linalg/Vector4.js.map +1 -1
- package/dist/utility/MatrixSizeError.d.ts +1 -1
- package/dist/utility/MatrixSizeError.d.ts.map +1 -1
- package/dist/utility/MatrixSizeError.js +1 -1
- package/dist/utility/MatrixSizeError.js.map +1 -1
- package/dist/utility/VectorSizeError.d.ts +12 -0
- package/dist/utility/VectorSizeError.d.ts.map +1 -0
- package/dist/utility/VectorSizeError.js +15 -0
- package/dist/utility/VectorSizeError.js.map +1 -0
- package/dist/utility/createAxisAngleLike.d.ts +10 -0
- package/dist/utility/createAxisAngleLike.d.ts.map +1 -0
- package/dist/utility/createAxisAngleLike.js +10 -0
- package/dist/utility/createAxisAngleLike.js.map +1 -0
- package/package.json +1 -3
- package/src/index.ts +7 -0
- package/src/linalg/DualQuaternion.ts +51 -134
- package/src/linalg/Matrix2.ts +30 -81
- package/src/linalg/Matrix3.ts +55 -149
- package/src/linalg/Matrix4.ts +135 -291
- package/src/linalg/Quaternion.ts +60 -151
- package/src/linalg/SlowMatrix.ts +82 -81
- package/src/linalg/SlowVector.ts +449 -0
- package/src/linalg/Vector.ts +14 -16
- package/src/linalg/Vector2.ts +63 -153
- package/src/linalg/Vector3.ts +75 -194
- package/src/linalg/Vector4.ts +60 -143
- package/src/utility/MatrixSizeError.ts +1 -1
- package/src/utility/VectorSizeError.ts +14 -0
- package/src/utility/createAxisAngleLike.ts +13 -0
package/dist/linalg/Vector2.d.ts
CHANGED
|
@@ -326,10 +326,9 @@ export default class Vector2 extends Float32Array implements Vector, Vector2Like
|
|
|
326
326
|
* Create a vector with the given values.
|
|
327
327
|
* @param x - The first component.
|
|
328
328
|
* @param y - The second component.
|
|
329
|
-
* @param out - The vector to store the result in.
|
|
330
329
|
* @returns A new vector.
|
|
331
330
|
*/
|
|
332
|
-
static fromValues
|
|
331
|
+
static fromValues(x: number, y: number): Vector2;
|
|
333
332
|
/**
|
|
334
333
|
* Create a two-dimensional zero vector.
|
|
335
334
|
* @see {@link https://en.wikipedia.org/wiki/Euclidean_vector | Euclidean vector}
|
|
@@ -354,16 +353,14 @@ export default class Vector2 extends Float32Array implements Vector, Vector2Like
|
|
|
354
353
|
/**
|
|
355
354
|
* Add another vector to this one.
|
|
356
355
|
* @param vector - The other vector.
|
|
357
|
-
* @param out - The vector to store the result in.
|
|
358
356
|
* @returns The sum of the vectors.
|
|
359
357
|
*/
|
|
360
|
-
add
|
|
358
|
+
add(vector: Vector2Like): Vector2;
|
|
361
359
|
/**
|
|
362
360
|
* Copy the values from this vector to another one.
|
|
363
|
-
* @param out - The vector to store the result in.
|
|
364
361
|
* @returns The copy.
|
|
365
362
|
*/
|
|
366
|
-
clone
|
|
363
|
+
clone(): Vector2;
|
|
367
364
|
/**
|
|
368
365
|
* Copy the values from another vector into this one.
|
|
369
366
|
* @param vector - The vector to copy.
|
|
@@ -373,84 +370,72 @@ export default class Vector2 extends Float32Array implements Vector, Vector2Like
|
|
|
373
370
|
/**
|
|
374
371
|
* Multiply the components in this vector by the corresponding components in another.
|
|
375
372
|
* @param vector - The other vector.
|
|
376
|
-
* @param out - The vector to store the result in.
|
|
377
373
|
* @returns The product of the vectors.
|
|
378
374
|
*/
|
|
379
|
-
multiply
|
|
375
|
+
multiply(vector: Vector2Like): Vector2;
|
|
380
376
|
/**
|
|
381
377
|
* Divide this vector by another.
|
|
382
378
|
* @param vector - The other vector.
|
|
383
|
-
* @param out - The vector to store the result in.
|
|
384
379
|
* @returns The quotient of the vectors.
|
|
385
380
|
*/
|
|
386
|
-
divide
|
|
381
|
+
divide(vector: Vector2Like): Vector2;
|
|
387
382
|
/**
|
|
388
383
|
* Subtract another vector from this one.
|
|
389
384
|
* @param vector - The other vector.
|
|
390
|
-
* @param out - The vector to store the result in.
|
|
391
385
|
* @returns The difference between the vectors.
|
|
392
386
|
*/
|
|
393
|
-
subtract
|
|
387
|
+
subtract(vector: Vector2Like): Vector2;
|
|
394
388
|
/**
|
|
395
389
|
* Absolutize the components of this vector.
|
|
396
|
-
* @param out - The vector to store the result in.
|
|
397
390
|
* @returns The absolutized vector.
|
|
398
391
|
*/
|
|
399
|
-
abs
|
|
392
|
+
abs(): Vector2;
|
|
400
393
|
/**
|
|
401
394
|
* Round up the components of this vector.
|
|
402
|
-
* @param out - The vector to store the result in.
|
|
403
395
|
* @returns The rounded vector.
|
|
404
396
|
*/
|
|
405
|
-
ceil
|
|
397
|
+
ceil(): Vector2;
|
|
406
398
|
/**
|
|
407
399
|
* Round down the components of this vector.
|
|
408
|
-
* @param out - The vector to store the result in.
|
|
409
400
|
* @returns The rounded vector.
|
|
410
401
|
*/
|
|
411
|
-
floor
|
|
402
|
+
floor(): Vector2;
|
|
412
403
|
/**
|
|
413
404
|
* Round the components of this vector.
|
|
414
|
-
* @param out - The vector to store the result in.
|
|
415
405
|
* @returns The rounded vector.
|
|
416
406
|
*/
|
|
417
|
-
round
|
|
407
|
+
round(): Vector2;
|
|
418
408
|
/**
|
|
419
409
|
* Return the minimum of this and another vector.
|
|
420
410
|
* @param vector - The other vector.
|
|
421
|
-
* @param out - The vector to store the result in.
|
|
422
411
|
* @returns The minimum.
|
|
423
412
|
*/
|
|
424
|
-
min
|
|
413
|
+
min(vector: Vector2Like): Vector2;
|
|
425
414
|
/**
|
|
426
415
|
* Return the maximum of this and another vector.
|
|
427
416
|
* @param vector - The other vector.
|
|
428
|
-
* @param out - The vector to store the result in.
|
|
429
417
|
* @returns The maximum.
|
|
430
418
|
*/
|
|
431
|
-
max
|
|
419
|
+
max(vector: Vector2Like): Vector2;
|
|
432
420
|
/**
|
|
433
421
|
* Raise each component of this vector to the given power.
|
|
434
422
|
* @param scalar - The exponent (power) to raise each component to.
|
|
435
|
-
* @param out - The vector to store the result in.
|
|
436
423
|
* @returns The power (result of the exponentiation).
|
|
437
424
|
*/
|
|
438
|
-
pow
|
|
425
|
+
pow(scalar: number): Vector2;
|
|
439
426
|
/**
|
|
440
427
|
* Scale this vector by a scalar.
|
|
441
428
|
* @param scalar - The scalar.
|
|
442
|
-
* @param out - The vector to store the result in.
|
|
443
429
|
* @returns The scaled vector.
|
|
444
430
|
*/
|
|
445
|
-
scale
|
|
431
|
+
scale(scalar: number): Vector2;
|
|
446
432
|
/**
|
|
447
433
|
* Add another vector to this one after scaling the other by a scalar.
|
|
448
434
|
* @param vector - The other vector.
|
|
449
435
|
* @param scalar - The scalar.
|
|
450
|
-
* @param out - The vector to store the result in.
|
|
451
436
|
* @returns The sum.
|
|
452
437
|
*/
|
|
453
|
-
scaleAndAdd
|
|
438
|
+
scaleAndAdd(vector: Vector2Like, scalar: number): Vector2;
|
|
454
439
|
/**
|
|
455
440
|
* Calculate the Euclidean distance from this vector to another.
|
|
456
441
|
* @param vector - The other vector.
|
|
@@ -465,29 +450,28 @@ export default class Vector2 extends Float32Array implements Vector, Vector2Like
|
|
|
465
450
|
* @see {@link https://en.wikipedia.org/wiki/Euclidean_distance | Euclidean distance}
|
|
466
451
|
*/
|
|
467
452
|
squaredDistance(vector: Vector2Like): number;
|
|
468
|
-
/**
|
|
453
|
+
/** The magnitude (length) of this vector. */
|
|
469
454
|
get magnitude(): number;
|
|
470
|
-
|
|
455
|
+
set magnitude(value: number);
|
|
456
|
+
/** The squared magnitude (length) of this vector. */
|
|
471
457
|
get squaredMagnitude(): number;
|
|
458
|
+
set squaredMagnitude(value: number);
|
|
472
459
|
/**
|
|
473
460
|
* Negate this vector.
|
|
474
|
-
* @param out - The vector to store the result in.
|
|
475
461
|
* @returns The negated vector.
|
|
476
462
|
*/
|
|
477
|
-
negate
|
|
463
|
+
negate(): Vector2;
|
|
478
464
|
/**
|
|
479
465
|
* Calculate the multiplicative inverse of the components of this vector.
|
|
480
|
-
* @param out - The vector to store the result in.
|
|
481
466
|
* @returns The inverted vector.
|
|
482
467
|
*/
|
|
483
|
-
invert
|
|
468
|
+
invert(): Vector2;
|
|
484
469
|
/**
|
|
485
470
|
* Normalize this vector.
|
|
486
|
-
* @param out - The vector to store the result in.
|
|
487
471
|
* @returns The normalized vector.
|
|
488
472
|
* @see {@link https://en.wikipedia.org/wiki/Unit_vector | Unit vector}
|
|
489
473
|
*/
|
|
490
|
-
normalize
|
|
474
|
+
normalize(): Vector2;
|
|
491
475
|
/**
|
|
492
476
|
* Calculate the dot product of this and another vector.
|
|
493
477
|
* @param vector - The other vector.
|
|
@@ -498,20 +482,18 @@ export default class Vector2 extends Float32Array implements Vector, Vector2Like
|
|
|
498
482
|
/**
|
|
499
483
|
* Calculate the cross product of this and another vector.
|
|
500
484
|
* @param vector - The other vector.
|
|
501
|
-
* @param out - The vector to store the result in.
|
|
502
485
|
* @returns The cross product.
|
|
503
486
|
* @see {@link https://en.wikipedia.org/wiki/Cross_product | Cross product}
|
|
504
487
|
*/
|
|
505
|
-
cross
|
|
488
|
+
cross(vector: Vector2Like): Vector3;
|
|
506
489
|
/**
|
|
507
490
|
* Perform a linear interpolation between this and another vector.
|
|
508
491
|
* @param vector - The other vector.
|
|
509
492
|
* @param t - The interpolation amount (in `[0,1]`).
|
|
510
|
-
* @param out - The vector to store the result in.
|
|
511
493
|
* @returns The interpolated vector.
|
|
512
494
|
* @see {@link https://en.wikipedia.org/wiki/Linear_interpolation | Linear interpolation}
|
|
513
495
|
*/
|
|
514
|
-
lerp
|
|
496
|
+
lerp(vector: Vector2Like, t: number): Vector2;
|
|
515
497
|
/**
|
|
516
498
|
* Set this vector to a random value with the given magnitude.
|
|
517
499
|
* @param magnitude - The magnitude.
|
|
@@ -521,35 +503,31 @@ export default class Vector2 extends Float32Array implements Vector, Vector2Like
|
|
|
521
503
|
/**
|
|
522
504
|
* Transform this vector by a two-by-two matrix.
|
|
523
505
|
* @param matrix - The matrix.
|
|
524
|
-
* @param out - The vector to store the result in.
|
|
525
506
|
* @returns The transformed vector.
|
|
526
507
|
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
527
508
|
*/
|
|
528
|
-
transformMatrix2
|
|
509
|
+
transformMatrix2(matrix: Matrix2Like): Vector2;
|
|
529
510
|
/**
|
|
530
511
|
* Transform this vector by a three-by-three matrix.
|
|
531
512
|
* @param matrix - The matrix.
|
|
532
|
-
* @param out - The vector to store the result in.
|
|
533
513
|
* @returns The transformed vector.
|
|
534
514
|
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
535
515
|
*/
|
|
536
|
-
transformMatrix3
|
|
516
|
+
transformMatrix3(matrix: Matrix3Like): Vector2;
|
|
537
517
|
/**
|
|
538
518
|
* Transform this vector by a four-by-four matrix.
|
|
539
519
|
* @param matrix - The matrix.
|
|
540
|
-
* @param out - The vector to store the result in.
|
|
541
520
|
* @returns The transformed vector.
|
|
542
521
|
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
543
522
|
*/
|
|
544
|
-
transformMatrix4
|
|
523
|
+
transformMatrix4(matrix: Matrix4Like): Vector2;
|
|
545
524
|
/**
|
|
546
525
|
* Rotate this vector.
|
|
547
526
|
* @param origin - The origin of the rotation.
|
|
548
527
|
* @param radians - The angle of rotation in radians.
|
|
549
|
-
* @param out - The vector to store the result in.
|
|
550
528
|
* @returns The rotated vector.
|
|
551
529
|
*/
|
|
552
|
-
rotate
|
|
530
|
+
rotate(origin: Vector2Like, radians: number): Vector2;
|
|
553
531
|
/**
|
|
554
532
|
* Get the angle from this to another vector in radians.
|
|
555
533
|
* @param vector - The other vector.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Vector2.d.ts","sourceRoot":"","sources":["../../src/linalg/Vector2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,OAAO,EAAE,EACf,KAAK,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AAC,MAAM,EAAE,WAAW,GAAG,MAAM;IAIzC;;;OAGG;IACI,IAAI,IAAI,IAAI;CAGnB"}
|
package/dist/linalg/Vector2.js
CHANGED
|
@@ -167,11 +167,7 @@ export const scaleAndAdd = (a, b, scalar, out) => fromValues(a[0] + b[0] * scala
|
|
|
167
167
|
* @see {@link https://en.wikipedia.org/wiki/Euclidean_distance | Euclidean distance}
|
|
168
168
|
* @public
|
|
169
169
|
*/
|
|
170
|
-
export const distance = (a, b) =>
|
|
171
|
-
const x = b[0] - a[0];
|
|
172
|
-
const y = b[1] - a[1];
|
|
173
|
-
return Math.sqrt(x * x + y * y); // `Math.hypot` is slower.
|
|
174
|
-
};
|
|
170
|
+
export const distance = (a, b) => Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
175
171
|
/**
|
|
176
172
|
* Calculate the squared Euclidean distance from one vector to another.
|
|
177
173
|
* @param a - The first vector.
|
|
@@ -191,11 +187,7 @@ export const squaredDistance = (a, b) => {
|
|
|
191
187
|
* @returns The magnitude.
|
|
192
188
|
* @public
|
|
193
189
|
*/
|
|
194
|
-
export const getMagnitude = (vector) =>
|
|
195
|
-
const x = vector[0];
|
|
196
|
-
const y = vector[1];
|
|
197
|
-
return Math.sqrt(x * x + y * y); // `Math.hypot` is slower.
|
|
198
|
-
};
|
|
190
|
+
export const getMagnitude = (vector) => Math.hypot(vector[0], vector[1]);
|
|
199
191
|
/**
|
|
200
192
|
* Get the squared magnitude (length) of a vector.
|
|
201
193
|
* @param vector - The vector.
|
|
@@ -357,7 +349,7 @@ export const angle = (a, b) => {
|
|
|
357
349
|
const y1 = a[1];
|
|
358
350
|
const x2 = b[0];
|
|
359
351
|
const y2 = b[1];
|
|
360
|
-
const mp = Math.
|
|
352
|
+
const mp = Math.hypot(x1, y1) * Math.hypot(x2, y2);
|
|
361
353
|
return Math.acos(Math.min(Math.max(mp && (x1 * x2 + y1 * y2) / mp, -1), 1));
|
|
362
354
|
};
|
|
363
355
|
/**
|
|
@@ -377,11 +369,10 @@ export default class Vector2 extends Float32Array {
|
|
|
377
369
|
* Create a vector with the given values.
|
|
378
370
|
* @param x - The first component.
|
|
379
371
|
* @param y - The second component.
|
|
380
|
-
* @param out - The vector to store the result in.
|
|
381
372
|
* @returns A new vector.
|
|
382
373
|
*/
|
|
383
|
-
static fromValues(x, y
|
|
384
|
-
return fromValues(x, y,
|
|
374
|
+
static fromValues(x, y) {
|
|
375
|
+
return fromValues(x, y, new Vector2());
|
|
385
376
|
}
|
|
386
377
|
/**
|
|
387
378
|
* Create a two-dimensional zero vector.
|
|
@@ -413,19 +404,17 @@ export default class Vector2 extends Float32Array {
|
|
|
413
404
|
/**
|
|
414
405
|
* Add another vector to this one.
|
|
415
406
|
* @param vector - The other vector.
|
|
416
|
-
* @param out - The vector to store the result in.
|
|
417
407
|
* @returns The sum of the vectors.
|
|
418
408
|
*/
|
|
419
|
-
add(vector
|
|
420
|
-
return add(this, vector,
|
|
409
|
+
add(vector) {
|
|
410
|
+
return add(this, vector, new Vector2());
|
|
421
411
|
}
|
|
422
412
|
/**
|
|
423
413
|
* Copy the values from this vector to another one.
|
|
424
|
-
* @param out - The vector to store the result in.
|
|
425
414
|
* @returns The copy.
|
|
426
415
|
*/
|
|
427
|
-
clone(
|
|
428
|
-
return copy(this,
|
|
416
|
+
clone() {
|
|
417
|
+
return copy(this, new Vector2());
|
|
429
418
|
}
|
|
430
419
|
/**
|
|
431
420
|
* Copy the values from another vector into this one.
|
|
@@ -438,107 +427,95 @@ export default class Vector2 extends Float32Array {
|
|
|
438
427
|
/**
|
|
439
428
|
* Multiply the components in this vector by the corresponding components in another.
|
|
440
429
|
* @param vector - The other vector.
|
|
441
|
-
* @param out - The vector to store the result in.
|
|
442
430
|
* @returns The product of the vectors.
|
|
443
431
|
*/
|
|
444
|
-
multiply(vector
|
|
445
|
-
return multiply(this, vector,
|
|
432
|
+
multiply(vector) {
|
|
433
|
+
return multiply(this, vector, new Vector2());
|
|
446
434
|
}
|
|
447
435
|
/**
|
|
448
436
|
* Divide this vector by another.
|
|
449
437
|
* @param vector - The other vector.
|
|
450
|
-
* @param out - The vector to store the result in.
|
|
451
438
|
* @returns The quotient of the vectors.
|
|
452
439
|
*/
|
|
453
|
-
divide(vector
|
|
454
|
-
return divide(this, vector,
|
|
440
|
+
divide(vector) {
|
|
441
|
+
return divide(this, vector, new Vector2());
|
|
455
442
|
}
|
|
456
443
|
/**
|
|
457
444
|
* Subtract another vector from this one.
|
|
458
445
|
* @param vector - The other vector.
|
|
459
|
-
* @param out - The vector to store the result in.
|
|
460
446
|
* @returns The difference between the vectors.
|
|
461
447
|
*/
|
|
462
|
-
subtract(vector
|
|
463
|
-
return subtract(this, vector,
|
|
448
|
+
subtract(vector) {
|
|
449
|
+
return subtract(this, vector, new Vector2());
|
|
464
450
|
}
|
|
465
451
|
/**
|
|
466
452
|
* Absolutize the components of this vector.
|
|
467
|
-
* @param out - The vector to store the result in.
|
|
468
453
|
* @returns The absolutized vector.
|
|
469
454
|
*/
|
|
470
|
-
abs(
|
|
471
|
-
return abs(this,
|
|
455
|
+
abs() {
|
|
456
|
+
return abs(this, new Vector2());
|
|
472
457
|
}
|
|
473
458
|
/**
|
|
474
459
|
* Round up the components of this vector.
|
|
475
|
-
* @param out - The vector to store the result in.
|
|
476
460
|
* @returns The rounded vector.
|
|
477
461
|
*/
|
|
478
|
-
ceil(
|
|
479
|
-
return ceil(this,
|
|
462
|
+
ceil() {
|
|
463
|
+
return ceil(this, new Vector2());
|
|
480
464
|
}
|
|
481
465
|
/**
|
|
482
466
|
* Round down the components of this vector.
|
|
483
|
-
* @param out - The vector to store the result in.
|
|
484
467
|
* @returns The rounded vector.
|
|
485
468
|
*/
|
|
486
|
-
floor(
|
|
487
|
-
return floor(this,
|
|
469
|
+
floor() {
|
|
470
|
+
return floor(this, new Vector2());
|
|
488
471
|
}
|
|
489
472
|
/**
|
|
490
473
|
* Round the components of this vector.
|
|
491
|
-
* @param out - The vector to store the result in.
|
|
492
474
|
* @returns The rounded vector.
|
|
493
475
|
*/
|
|
494
|
-
round(
|
|
495
|
-
return round(this,
|
|
476
|
+
round() {
|
|
477
|
+
return round(this, new Vector2());
|
|
496
478
|
}
|
|
497
479
|
/**
|
|
498
480
|
* Return the minimum of this and another vector.
|
|
499
481
|
* @param vector - The other vector.
|
|
500
|
-
* @param out - The vector to store the result in.
|
|
501
482
|
* @returns The minimum.
|
|
502
483
|
*/
|
|
503
|
-
min(vector
|
|
504
|
-
return min(this, vector,
|
|
484
|
+
min(vector) {
|
|
485
|
+
return min(this, vector, new Vector2());
|
|
505
486
|
}
|
|
506
487
|
/**
|
|
507
488
|
* Return the maximum of this and another vector.
|
|
508
489
|
* @param vector - The other vector.
|
|
509
|
-
* @param out - The vector to store the result in.
|
|
510
490
|
* @returns The maximum.
|
|
511
491
|
*/
|
|
512
|
-
max(vector
|
|
513
|
-
return max(this, vector,
|
|
492
|
+
max(vector) {
|
|
493
|
+
return max(this, vector, new Vector2());
|
|
514
494
|
}
|
|
515
495
|
/**
|
|
516
496
|
* Raise each component of this vector to the given power.
|
|
517
497
|
* @param scalar - The exponent (power) to raise each component to.
|
|
518
|
-
* @param out - The vector to store the result in.
|
|
519
498
|
* @returns The power (result of the exponentiation).
|
|
520
499
|
*/
|
|
521
|
-
pow(scalar
|
|
522
|
-
return pow(this, scalar,
|
|
500
|
+
pow(scalar) {
|
|
501
|
+
return pow(this, scalar, new Vector2());
|
|
523
502
|
}
|
|
524
503
|
/**
|
|
525
504
|
* Scale this vector by a scalar.
|
|
526
505
|
* @param scalar - The scalar.
|
|
527
|
-
* @param out - The vector to store the result in.
|
|
528
506
|
* @returns The scaled vector.
|
|
529
507
|
*/
|
|
530
|
-
scale(scalar
|
|
531
|
-
return scale(this, scalar,
|
|
508
|
+
scale(scalar) {
|
|
509
|
+
return scale(this, scalar, new Vector2());
|
|
532
510
|
}
|
|
533
511
|
/**
|
|
534
512
|
* Add another vector to this one after scaling the other by a scalar.
|
|
535
513
|
* @param vector - The other vector.
|
|
536
514
|
* @param scalar - The scalar.
|
|
537
|
-
* @param out - The vector to store the result in.
|
|
538
515
|
* @returns The sum.
|
|
539
516
|
*/
|
|
540
|
-
scaleAndAdd(vector, scalar
|
|
541
|
-
return scaleAndAdd(this, vector, scalar,
|
|
517
|
+
scaleAndAdd(vector, scalar) {
|
|
518
|
+
return scaleAndAdd(this, vector, scalar, new Vector2());
|
|
542
519
|
}
|
|
543
520
|
/**
|
|
544
521
|
* Calculate the Euclidean distance from this vector to another.
|
|
@@ -558,38 +535,41 @@ export default class Vector2 extends Float32Array {
|
|
|
558
535
|
squaredDistance(vector) {
|
|
559
536
|
return squaredDistance(this, vector);
|
|
560
537
|
}
|
|
561
|
-
/**
|
|
538
|
+
/** The magnitude (length) of this vector. */
|
|
562
539
|
get magnitude() {
|
|
563
540
|
return getMagnitude(this);
|
|
564
541
|
}
|
|
565
|
-
|
|
542
|
+
set magnitude(value) {
|
|
543
|
+
scale(normalize(this, this), value, this);
|
|
544
|
+
}
|
|
545
|
+
/** The squared magnitude (length) of this vector. */
|
|
566
546
|
get squaredMagnitude() {
|
|
567
547
|
return getSquaredMagnitude(this);
|
|
568
548
|
}
|
|
549
|
+
set squaredMagnitude(value) {
|
|
550
|
+
this.magnitude = Math.sqrt(value);
|
|
551
|
+
}
|
|
569
552
|
/**
|
|
570
553
|
* Negate this vector.
|
|
571
|
-
* @param out - The vector to store the result in.
|
|
572
554
|
* @returns The negated vector.
|
|
573
555
|
*/
|
|
574
|
-
negate(
|
|
575
|
-
return negate(this,
|
|
556
|
+
negate() {
|
|
557
|
+
return negate(this, new Vector2());
|
|
576
558
|
}
|
|
577
559
|
/**
|
|
578
560
|
* Calculate the multiplicative inverse of the components of this vector.
|
|
579
|
-
* @param out - The vector to store the result in.
|
|
580
561
|
* @returns The inverted vector.
|
|
581
562
|
*/
|
|
582
|
-
invert(
|
|
583
|
-
return invert(this,
|
|
563
|
+
invert() {
|
|
564
|
+
return invert(this, new Vector2());
|
|
584
565
|
}
|
|
585
566
|
/**
|
|
586
567
|
* Normalize this vector.
|
|
587
|
-
* @param out - The vector to store the result in.
|
|
588
568
|
* @returns The normalized vector.
|
|
589
569
|
* @see {@link https://en.wikipedia.org/wiki/Unit_vector | Unit vector}
|
|
590
570
|
*/
|
|
591
|
-
normalize(
|
|
592
|
-
return normalize(this,
|
|
571
|
+
normalize() {
|
|
572
|
+
return normalize(this, new Vector2());
|
|
593
573
|
}
|
|
594
574
|
/**
|
|
595
575
|
* Calculate the dot product of this and another vector.
|
|
@@ -603,23 +583,21 @@ export default class Vector2 extends Float32Array {
|
|
|
603
583
|
/**
|
|
604
584
|
* Calculate the cross product of this and another vector.
|
|
605
585
|
* @param vector - The other vector.
|
|
606
|
-
* @param out - The vector to store the result in.
|
|
607
586
|
* @returns The cross product.
|
|
608
587
|
* @see {@link https://en.wikipedia.org/wiki/Cross_product | Cross product}
|
|
609
588
|
*/
|
|
610
|
-
cross(vector
|
|
611
|
-
return cross(this, vector,
|
|
589
|
+
cross(vector) {
|
|
590
|
+
return cross(this, vector, new Vector3());
|
|
612
591
|
}
|
|
613
592
|
/**
|
|
614
593
|
* Perform a linear interpolation between this and another vector.
|
|
615
594
|
* @param vector - The other vector.
|
|
616
595
|
* @param t - The interpolation amount (in `[0,1]`).
|
|
617
|
-
* @param out - The vector to store the result in.
|
|
618
596
|
* @returns The interpolated vector.
|
|
619
597
|
* @see {@link https://en.wikipedia.org/wiki/Linear_interpolation | Linear interpolation}
|
|
620
598
|
*/
|
|
621
|
-
lerp(vector, t
|
|
622
|
-
return lerp(this, vector, t,
|
|
599
|
+
lerp(vector, t) {
|
|
600
|
+
return lerp(this, vector, t, new Vector2());
|
|
623
601
|
}
|
|
624
602
|
/**
|
|
625
603
|
* Set this vector to a random value with the given magnitude.
|
|
@@ -632,42 +610,38 @@ export default class Vector2 extends Float32Array {
|
|
|
632
610
|
/**
|
|
633
611
|
* Transform this vector by a two-by-two matrix.
|
|
634
612
|
* @param matrix - The matrix.
|
|
635
|
-
* @param out - The vector to store the result in.
|
|
636
613
|
* @returns The transformed vector.
|
|
637
614
|
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
638
615
|
*/
|
|
639
|
-
transformMatrix2(matrix
|
|
640
|
-
return transformMatrix2(this, matrix,
|
|
616
|
+
transformMatrix2(matrix) {
|
|
617
|
+
return transformMatrix2(this, matrix, new Vector2());
|
|
641
618
|
}
|
|
642
619
|
/**
|
|
643
620
|
* Transform this vector by a three-by-three matrix.
|
|
644
621
|
* @param matrix - The matrix.
|
|
645
|
-
* @param out - The vector to store the result in.
|
|
646
622
|
* @returns The transformed vector.
|
|
647
623
|
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
648
624
|
*/
|
|
649
|
-
transformMatrix3(matrix
|
|
650
|
-
return transformMatrix3(this, matrix,
|
|
625
|
+
transformMatrix3(matrix) {
|
|
626
|
+
return transformMatrix3(this, matrix, new Vector2());
|
|
651
627
|
}
|
|
652
628
|
/**
|
|
653
629
|
* Transform this vector by a four-by-four matrix.
|
|
654
630
|
* @param matrix - The matrix.
|
|
655
|
-
* @param out - The vector to store the result in.
|
|
656
631
|
* @returns The transformed vector.
|
|
657
632
|
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
658
633
|
*/
|
|
659
|
-
transformMatrix4(matrix
|
|
660
|
-
return transformMatrix4(this, matrix,
|
|
634
|
+
transformMatrix4(matrix) {
|
|
635
|
+
return transformMatrix4(this, matrix, new Vector2());
|
|
661
636
|
}
|
|
662
637
|
/**
|
|
663
638
|
* Rotate this vector.
|
|
664
639
|
* @param origin - The origin of the rotation.
|
|
665
640
|
* @param radians - The angle of rotation in radians.
|
|
666
|
-
* @param out - The vector to store the result in.
|
|
667
641
|
* @returns The rotated vector.
|
|
668
642
|
*/
|
|
669
|
-
rotate(origin, radians
|
|
670
|
-
return rotate(this, origin, radians,
|
|
643
|
+
rotate(origin, radians) {
|
|
644
|
+
return rotate(this, origin, radians, new Vector2());
|
|
671
645
|
}
|
|
672
646
|
/**
|
|
673
647
|
* Get the angle from this to another vector in radians.
|