@lakuna/umath 1.1.1 → 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.d.ts.map +1 -1
- package/dist/algorithms/factorial.js +5 -1
- package/dist/algorithms/factorial.js.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
- package/dist/algorithms/hypergeometricPmf.d.ts +2 -0
- package/dist/algorithms/hypergeometricPmf.d.ts.map +1 -0
- package/dist/algorithms/hypergeometricPmf.js +5 -0
- package/dist/algorithms/hypergeometricPmf.js.map +1 -0
- 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 +5 -4
- package/dist/algorithms/summation.js.map +1 -1
- package/dist/index.d.ts +33 -32
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -26
- 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 +5 -1
- package/src/algorithms/greatestCommonDivisor.ts +10 -3
- package/src/algorithms/hypergeometricPmf.ts +19 -0
- package/src/algorithms/permutations.ts +1 -1
- package/src/algorithms/radiansToDegrees.ts +1 -1
- package/src/algorithms/summation.ts +12 -14
- package/src/index.ts +36 -32
- 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/Vector4.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Matrix4Like } from "#
|
|
2
|
-
import type { QuaternionLike } from "#
|
|
3
|
-
import type Vector from "#
|
|
4
|
-
import epsilon from "#
|
|
1
|
+
import type { Matrix4Like } from "#Matrix4";
|
|
2
|
+
import type { QuaternionLike } from "#Quaternion";
|
|
3
|
+
import type Vector from "#Vector";
|
|
4
|
+
import epsilon from "#epsilon";
|
|
5
5
|
|
|
6
6
|
/** A quantity with magnitude and direction in four dimensions. */
|
|
7
7
|
export type Vector4Like = Vector4 | [number, number, number, number];
|
|
@@ -15,7 +15,13 @@ export type Vector4Like = Vector4 | [number, number, 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 Vector4Like>(
|
|
18
|
+
export function fromValues<T extends Vector4Like>(
|
|
19
|
+
x: number,
|
|
20
|
+
y: number,
|
|
21
|
+
z: number,
|
|
22
|
+
w: number,
|
|
23
|
+
out: T
|
|
24
|
+
): T {
|
|
19
25
|
out[0] = x;
|
|
20
26
|
out[1] = y;
|
|
21
27
|
out[2] = z;
|
|
@@ -40,10 +46,12 @@ export function equals(a: Vector4Like, b: Vector4Like): boolean {
|
|
|
40
46
|
const b2: number = b[2];
|
|
41
47
|
const b3: number = b[3];
|
|
42
48
|
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
return (
|
|
50
|
+
Math.abs(a0 - b0) <= epsilon * Math.max(1, Math.abs(a0), Math.abs(b0)) &&
|
|
51
|
+
Math.abs(a1 - b1) <= epsilon * Math.max(1, Math.abs(a1), Math.abs(b1)) &&
|
|
52
|
+
Math.abs(a2 - b2) <= epsilon * Math.max(1, Math.abs(a2), Math.abs(b2)) &&
|
|
53
|
+
Math.abs(a3 - b3) <= epsilon * Math.max(1, Math.abs(a3), Math.abs(b3))
|
|
54
|
+
);
|
|
47
55
|
}
|
|
48
56
|
|
|
49
57
|
/**
|
|
@@ -52,11 +60,8 @@ export function equals(a: Vector4Like, b: Vector4Like): boolean {
|
|
|
52
60
|
* @param b The second vector.
|
|
53
61
|
* @returns Whether the vectors are equivalent.
|
|
54
62
|
*/
|
|
55
|
-
export function exactEquals(a: Vector4Like,b
|
|
56
|
-
return a[0] == b[0]
|
|
57
|
-
&& a[1] == b[1]
|
|
58
|
-
&& a[2] == b[2]
|
|
59
|
-
&& a[3] == b[3];
|
|
63
|
+
export function exactEquals(a: Vector4Like, b: Vector4Like): boolean {
|
|
64
|
+
return a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3];
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
/**
|
|
@@ -66,7 +71,11 @@ export function exactEquals(a: Vector4Like,b : Vector4Like): boolean {
|
|
|
66
71
|
* @param out The vector to store the result in.
|
|
67
72
|
* @returns The sum.
|
|
68
73
|
*/
|
|
69
|
-
export function add<T extends Vector4Like>(
|
|
74
|
+
export function add<T extends Vector4Like>(
|
|
75
|
+
a: Vector4Like,
|
|
76
|
+
b: Vector4Like,
|
|
77
|
+
out: T
|
|
78
|
+
): T {
|
|
70
79
|
out[0] = a[0] + b[0];
|
|
71
80
|
out[1] = a[1] + b[1];
|
|
72
81
|
out[2] = a[2] + b[2];
|
|
@@ -95,7 +104,11 @@ export function copy<T extends Vector4Like>(vector: Vector4Like, out: T): T {
|
|
|
95
104
|
* @param out The vector to store the result in.
|
|
96
105
|
* @returns The product.
|
|
97
106
|
*/
|
|
98
|
-
export function multiply<T extends Vector4Like>(
|
|
107
|
+
export function multiply<T extends Vector4Like>(
|
|
108
|
+
a: Vector4Like,
|
|
109
|
+
b: Vector4Like,
|
|
110
|
+
out: T
|
|
111
|
+
): T {
|
|
99
112
|
out[0] = a[0] * b[0];
|
|
100
113
|
out[1] = a[1] * b[1];
|
|
101
114
|
out[2] = a[2] * b[2];
|
|
@@ -110,7 +123,11 @@ export function multiply<T extends Vector4Like>(a: Vector4Like, b: Vector4Like,
|
|
|
110
123
|
* @param out The vector to store the result in.
|
|
111
124
|
* @returns The quotient.
|
|
112
125
|
*/
|
|
113
|
-
export function divide<T extends Vector4Like>(
|
|
126
|
+
export function divide<T extends Vector4Like>(
|
|
127
|
+
a: Vector4Like,
|
|
128
|
+
b: Vector4Like,
|
|
129
|
+
out: T
|
|
130
|
+
): T {
|
|
114
131
|
out[0] = a[0] / b[0];
|
|
115
132
|
out[1] = a[1] / b[1];
|
|
116
133
|
out[2] = a[2] / b[2];
|
|
@@ -125,7 +142,11 @@ export function divide<T extends Vector4Like>(a: Vector4Like, b: Vector4Like, ou
|
|
|
125
142
|
* @param out The vector to store the result in.
|
|
126
143
|
* @returns The difference.
|
|
127
144
|
*/
|
|
128
|
-
export function subtract<T extends Vector4Like>(
|
|
145
|
+
export function subtract<T extends Vector4Like>(
|
|
146
|
+
a: Vector4Like,
|
|
147
|
+
b: Vector4Like,
|
|
148
|
+
out: T
|
|
149
|
+
): T {
|
|
129
150
|
out[0] = a[0] - b[0];
|
|
130
151
|
out[1] = a[1] - b[1];
|
|
131
152
|
out[2] = a[2] - b[2];
|
|
@@ -182,7 +203,11 @@ export function round<T extends Vector4Like>(vector: Vector4Like, out: T): T {
|
|
|
182
203
|
* @param out The vector to store the result in.
|
|
183
204
|
* @returns The minimum.
|
|
184
205
|
*/
|
|
185
|
-
export function min<T extends Vector4Like>(
|
|
206
|
+
export function min<T extends Vector4Like>(
|
|
207
|
+
a: Vector4Like,
|
|
208
|
+
b: Vector4Like,
|
|
209
|
+
out: T
|
|
210
|
+
): T {
|
|
186
211
|
out[0] = Math.min(a[0], b[0]);
|
|
187
212
|
out[1] = Math.min(a[1], b[1]);
|
|
188
213
|
out[2] = Math.min(a[2], b[2]);
|
|
@@ -197,7 +222,11 @@ export function min<T extends Vector4Like>(a: Vector4Like, b: Vector4Like, out:
|
|
|
197
222
|
* @param out The vector to store the result in.
|
|
198
223
|
* @returns The maximum.
|
|
199
224
|
*/
|
|
200
|
-
export function max<T extends Vector4Like>(
|
|
225
|
+
export function max<T extends Vector4Like>(
|
|
226
|
+
a: Vector4Like,
|
|
227
|
+
b: Vector4Like,
|
|
228
|
+
out: T
|
|
229
|
+
): T {
|
|
201
230
|
out[0] = Math.max(a[0], b[0]);
|
|
202
231
|
out[1] = Math.max(a[1], b[1]);
|
|
203
232
|
out[2] = Math.max(a[2], b[2]);
|
|
@@ -212,7 +241,11 @@ export function max<T extends Vector4Like>(a: Vector4Like, b: Vector4Like, out:
|
|
|
212
241
|
* @param out The vector to store the result in.
|
|
213
242
|
* @returns The product.
|
|
214
243
|
*/
|
|
215
|
-
export function scale<T extends Vector4Like>(
|
|
244
|
+
export function scale<T extends Vector4Like>(
|
|
245
|
+
vector: Vector4Like,
|
|
246
|
+
scalar: number,
|
|
247
|
+
out: T
|
|
248
|
+
): T {
|
|
216
249
|
out[0] = vector[0] * scalar;
|
|
217
250
|
out[1] = vector[1] * scalar;
|
|
218
251
|
out[2] = vector[2] * scalar;
|
|
@@ -228,7 +261,12 @@ export function scale<T extends Vector4Like>(vector: Vector4Like, scalar: number
|
|
|
228
261
|
* @param out The vector to store the result in.
|
|
229
262
|
* @returns The sum.
|
|
230
263
|
*/
|
|
231
|
-
export function scaleAndAdd<T extends Vector4Like>(
|
|
264
|
+
export function scaleAndAdd<T extends Vector4Like>(
|
|
265
|
+
a: Vector4Like,
|
|
266
|
+
b: Vector4Like,
|
|
267
|
+
scalar: number,
|
|
268
|
+
out: T
|
|
269
|
+
): T {
|
|
232
270
|
out[0] = a[0] + b[0] * scalar;
|
|
233
271
|
out[1] = a[1] + b[1] * scalar;
|
|
234
272
|
out[2] = a[2] + b[2] * scalar;
|
|
@@ -327,12 +365,15 @@ export function invert<T extends Vector4Like>(vector: Vector4Like, out: T): T {
|
|
|
327
365
|
* @returns The normalized vector.
|
|
328
366
|
* @see [Unit vector](https://en.wikipedia.org/wiki/Unit_vector)
|
|
329
367
|
*/
|
|
330
|
-
export function normalize<T extends Vector4Like>(
|
|
368
|
+
export function normalize<T extends Vector4Like>(
|
|
369
|
+
vector: Vector4Like,
|
|
370
|
+
out: T
|
|
371
|
+
): T {
|
|
331
372
|
const x: number = vector[0];
|
|
332
373
|
const y: number = vector[1];
|
|
333
374
|
const z: number = vector[2];
|
|
334
375
|
const w: number = vector[3];
|
|
335
|
-
|
|
376
|
+
|
|
336
377
|
let len: number = x * x + y * y + z * z + w * w;
|
|
337
378
|
if (len > 0) {
|
|
338
379
|
len = 1 / Math.sqrt(len);
|
|
@@ -365,7 +406,12 @@ export function dot(a: Vector4Like, b: Vector4Like): number {
|
|
|
365
406
|
* @returns The cross product.
|
|
366
407
|
* @see [Cross product](https://en.wikipedia.org/wiki/Cross_product)
|
|
367
408
|
*/
|
|
368
|
-
export function cross<T extends Vector4Like>(
|
|
409
|
+
export function cross<T extends Vector4Like>(
|
|
410
|
+
a: Vector4Like,
|
|
411
|
+
b: Vector4Like,
|
|
412
|
+
c: Vector4Like,
|
|
413
|
+
out: T
|
|
414
|
+
): T {
|
|
369
415
|
const d = b[0] * c[1] - b[1] * c[0];
|
|
370
416
|
const e = b[0] * c[2] - b[2] * c[0];
|
|
371
417
|
const f = b[0] * c[3] - b[3] * c[0];
|
|
@@ -394,7 +440,12 @@ export function cross<T extends Vector4Like>(a: Vector4Like, b: Vector4Like, c:
|
|
|
394
440
|
* @returns The interpolated vector.
|
|
395
441
|
* @see [Linear interpolation](https://en.wikipedia.org/wiki/Linear_interpolation)
|
|
396
442
|
*/
|
|
397
|
-
export function lerp<T extends Vector4Like>(
|
|
443
|
+
export function lerp<T extends Vector4Like>(
|
|
444
|
+
a: Vector4Like,
|
|
445
|
+
b: Vector4Like,
|
|
446
|
+
t: number,
|
|
447
|
+
out: T
|
|
448
|
+
): T {
|
|
398
449
|
const ax: number = a[0];
|
|
399
450
|
const ay: number = a[1];
|
|
400
451
|
const az: number = a[2];
|
|
@@ -441,7 +492,11 @@ export function random<T extends Vector4Like>(magnitude: number, out: T): T {
|
|
|
441
492
|
* @returns The transformed vector.
|
|
442
493
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
443
494
|
*/
|
|
444
|
-
export function transformMatrix4<T extends Vector4Like>(
|
|
495
|
+
export function transformMatrix4<T extends Vector4Like>(
|
|
496
|
+
vector: Vector4Like,
|
|
497
|
+
matrix: Matrix4Like,
|
|
498
|
+
out: T
|
|
499
|
+
): T {
|
|
445
500
|
const x: number = vector[0];
|
|
446
501
|
const y: number = vector[1];
|
|
447
502
|
const z: number = vector[2];
|
|
@@ -475,7 +530,11 @@ export function zero<T extends Vector4Like>(out: T): T {
|
|
|
475
530
|
* @returns The transformed vector.
|
|
476
531
|
* @see [Quaternion](https://en.wikipedia.org/wiki/Quaternion)
|
|
477
532
|
*/
|
|
478
|
-
export function transformQuaternion<T extends Vector4Like>(
|
|
533
|
+
export function transformQuaternion<T extends Vector4Like>(
|
|
534
|
+
vector: Vector4Like,
|
|
535
|
+
quaternion: QuaternionLike,
|
|
536
|
+
out: T
|
|
537
|
+
): T {
|
|
479
538
|
const x: number = vector[0];
|
|
480
539
|
const y: number = vector[1];
|
|
481
540
|
const z: number = vector[2];
|
|
@@ -489,7 +548,7 @@ export function transformQuaternion<T extends Vector4Like>(vector: Vector4Like,
|
|
|
489
548
|
const iy: number = qw * y + qz * x - qx * z;
|
|
490
549
|
const iz: number = qw * z + qx * y - qy * x;
|
|
491
550
|
const iw: number = -qx * x - qy * y - qz * z;
|
|
492
|
-
|
|
551
|
+
|
|
493
552
|
out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
|
|
494
553
|
out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
|
|
495
554
|
out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
|
|
@@ -521,9 +580,21 @@ export default class Vector4 extends Float32Array implements Vector {
|
|
|
521
580
|
* @param out The vector to store the result in.
|
|
522
581
|
* @returns A new vector.
|
|
523
582
|
*/
|
|
524
|
-
public static fromValues<T extends Vector4Like>(
|
|
525
|
-
|
|
526
|
-
|
|
583
|
+
public static fromValues<T extends Vector4Like>(
|
|
584
|
+
x: number,
|
|
585
|
+
y: number,
|
|
586
|
+
z: number,
|
|
587
|
+
w: number,
|
|
588
|
+
out: T
|
|
589
|
+
): T;
|
|
590
|
+
|
|
591
|
+
public static fromValues<T extends Vector4Like>(
|
|
592
|
+
x: number,
|
|
593
|
+
y: number,
|
|
594
|
+
z: number,
|
|
595
|
+
w: number,
|
|
596
|
+
out: T = new Vector4() as T
|
|
597
|
+
): T {
|
|
527
598
|
return fromValues(x, y, z, w, out);
|
|
528
599
|
}
|
|
529
600
|
|
|
@@ -568,7 +639,10 @@ export default class Vector4 extends Float32Array implements Vector {
|
|
|
568
639
|
*/
|
|
569
640
|
public add<T extends Vector4Like>(vector: Vector4Like, out: T): T;
|
|
570
641
|
|
|
571
|
-
public add<T extends Vector4Like>(
|
|
642
|
+
public add<T extends Vector4Like>(
|
|
643
|
+
vector: Vector4Like,
|
|
644
|
+
out: T = new Vector4() as T
|
|
645
|
+
): T {
|
|
572
646
|
return add(this, vector, out);
|
|
573
647
|
}
|
|
574
648
|
|
|
@@ -584,7 +658,7 @@ export default class Vector4 extends Float32Array implements Vector {
|
|
|
584
658
|
* @returns The copy.
|
|
585
659
|
*/
|
|
586
660
|
public clone<T extends Vector4Like>(out: T): T;
|
|
587
|
-
|
|
661
|
+
|
|
588
662
|
public clone<T extends Vector4Like>(out: T = new Vector4() as T): T {
|
|
589
663
|
return copy(this, out);
|
|
590
664
|
}
|
|
@@ -613,7 +687,10 @@ export default class Vector4 extends Float32Array implements Vector {
|
|
|
613
687
|
*/
|
|
614
688
|
public multiply<T extends Vector4Like>(vector: Vector4Like, out: T): T;
|
|
615
689
|
|
|
616
|
-
public multiply<T extends Vector4Like>(
|
|
690
|
+
public multiply<T extends Vector4Like>(
|
|
691
|
+
vector: Vector4Like,
|
|
692
|
+
out: T = new Vector4() as T
|
|
693
|
+
): T {
|
|
617
694
|
return multiply(this, vector, out);
|
|
618
695
|
}
|
|
619
696
|
|
|
@@ -632,7 +709,10 @@ export default class Vector4 extends Float32Array implements Vector {
|
|
|
632
709
|
*/
|
|
633
710
|
public divide<T extends Vector4Like>(vector: Vector4Like, out: T): T;
|
|
634
711
|
|
|
635
|
-
public divide<T extends Vector4Like>(
|
|
712
|
+
public divide<T extends Vector4Like>(
|
|
713
|
+
vector: Vector4Like,
|
|
714
|
+
out: T = new Vector4() as T
|
|
715
|
+
): T {
|
|
636
716
|
return divide(this, vector, out);
|
|
637
717
|
}
|
|
638
718
|
|
|
@@ -651,7 +731,10 @@ export default class Vector4 extends Float32Array implements Vector {
|
|
|
651
731
|
*/
|
|
652
732
|
public subtract<T extends Vector4Like>(vector: Vector4Like, out: T): T;
|
|
653
733
|
|
|
654
|
-
public subtract<T extends Vector4Like>(
|
|
734
|
+
public subtract<T extends Vector4Like>(
|
|
735
|
+
vector: Vector4Like,
|
|
736
|
+
out: T = new Vector4() as T
|
|
737
|
+
): T {
|
|
655
738
|
return subtract(this, vector, out);
|
|
656
739
|
}
|
|
657
740
|
|
|
@@ -721,7 +804,10 @@ export default class Vector4 extends Float32Array implements Vector {
|
|
|
721
804
|
*/
|
|
722
805
|
public min<T extends Vector4Like>(vector: Vector4Like, out: T): T;
|
|
723
806
|
|
|
724
|
-
public min<T extends Vector4Like>(
|
|
807
|
+
public min<T extends Vector4Like>(
|
|
808
|
+
vector: Vector4Like,
|
|
809
|
+
out: T = new Vector4() as T
|
|
810
|
+
): T {
|
|
725
811
|
return min(this, vector, out);
|
|
726
812
|
}
|
|
727
813
|
|
|
@@ -740,7 +826,10 @@ export default class Vector4 extends Float32Array implements Vector {
|
|
|
740
826
|
*/
|
|
741
827
|
public max<T extends Vector4Like>(vector: Vector4Like, out: T): T;
|
|
742
828
|
|
|
743
|
-
public max<T extends Vector4Like>(
|
|
829
|
+
public max<T extends Vector4Like>(
|
|
830
|
+
vector: Vector4Like,
|
|
831
|
+
out: T = new Vector4() as T
|
|
832
|
+
): T {
|
|
744
833
|
return max(this, vector, out);
|
|
745
834
|
}
|
|
746
835
|
|
|
@@ -759,7 +848,10 @@ export default class Vector4 extends Float32Array implements Vector {
|
|
|
759
848
|
*/
|
|
760
849
|
public scale<T extends Vector4Like>(scalar: number, out: T): T;
|
|
761
850
|
|
|
762
|
-
public scale<T extends Vector4Like>(
|
|
851
|
+
public scale<T extends Vector4Like>(
|
|
852
|
+
scalar: number,
|
|
853
|
+
out: T = new Vector4() as T
|
|
854
|
+
): T {
|
|
763
855
|
return scale(this, scalar, out);
|
|
764
856
|
}
|
|
765
857
|
|
|
@@ -778,9 +870,17 @@ export default class Vector4 extends Float32Array implements Vector {
|
|
|
778
870
|
* @param out The vector to store the result in.
|
|
779
871
|
* @returns The sum.
|
|
780
872
|
*/
|
|
781
|
-
public scaleAndAdd<T extends Vector4Like>(
|
|
782
|
-
|
|
783
|
-
|
|
873
|
+
public scaleAndAdd<T extends Vector4Like>(
|
|
874
|
+
vector: Vector4Like,
|
|
875
|
+
scalar: number,
|
|
876
|
+
out: T
|
|
877
|
+
): T;
|
|
878
|
+
|
|
879
|
+
public scaleAndAdd<T extends Vector4Like>(
|
|
880
|
+
vector: Vector4Like,
|
|
881
|
+
scalar: number,
|
|
882
|
+
out: T = new Vector4() as T
|
|
883
|
+
): T {
|
|
784
884
|
return scaleAndAdd(this, vector, scalar, out);
|
|
785
885
|
}
|
|
786
886
|
|
|
@@ -894,9 +994,17 @@ export default class Vector4 extends Float32Array implements Vector {
|
|
|
894
994
|
* @returns The cross product.
|
|
895
995
|
* @see [Cross product](https://en.wikipedia.org/wiki/Cross_product)
|
|
896
996
|
*/
|
|
897
|
-
public cross<T extends Vector4Like>(
|
|
898
|
-
|
|
899
|
-
|
|
997
|
+
public cross<T extends Vector4Like>(
|
|
998
|
+
a: Vector4Like,
|
|
999
|
+
b: Vector4Like,
|
|
1000
|
+
out: T
|
|
1001
|
+
): T;
|
|
1002
|
+
|
|
1003
|
+
public cross<T extends Vector4Like>(
|
|
1004
|
+
a: Vector4Like,
|
|
1005
|
+
b: Vector4Like,
|
|
1006
|
+
out: T = new Vector4() as T
|
|
1007
|
+
): T {
|
|
900
1008
|
return cross(this, a, b, out);
|
|
901
1009
|
}
|
|
902
1010
|
|
|
@@ -919,7 +1027,11 @@ export default class Vector4 extends Float32Array implements Vector {
|
|
|
919
1027
|
*/
|
|
920
1028
|
public lerp<T extends Vector4Like>(vector: Vector4Like, t: number, out: T): T;
|
|
921
1029
|
|
|
922
|
-
public lerp<T extends Vector4Like>(
|
|
1030
|
+
public lerp<T extends Vector4Like>(
|
|
1031
|
+
vector: Vector4Like,
|
|
1032
|
+
t: number,
|
|
1033
|
+
out: T = new Vector4() as T
|
|
1034
|
+
): T {
|
|
923
1035
|
return lerp(this, vector, t, out);
|
|
924
1036
|
}
|
|
925
1037
|
|
|
@@ -947,9 +1059,15 @@ export default class Vector4 extends Float32Array implements Vector {
|
|
|
947
1059
|
* @returns The transformed vector.
|
|
948
1060
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
949
1061
|
*/
|
|
950
|
-
public transformMatrix4<T extends Vector4Like>(
|
|
951
|
-
|
|
952
|
-
|
|
1062
|
+
public transformMatrix4<T extends Vector4Like>(
|
|
1063
|
+
matrix: Matrix4Like,
|
|
1064
|
+
out: T
|
|
1065
|
+
): T;
|
|
1066
|
+
|
|
1067
|
+
public transformMatrix4<T extends Vector4Like>(
|
|
1068
|
+
matrix: Matrix4Like,
|
|
1069
|
+
out: T = new Vector4() as T
|
|
1070
|
+
): T {
|
|
953
1071
|
return transformMatrix4(this, matrix, out);
|
|
954
1072
|
}
|
|
955
1073
|
|
|
@@ -976,9 +1094,15 @@ export default class Vector4 extends Float32Array implements Vector {
|
|
|
976
1094
|
* @returns The transformed vector.
|
|
977
1095
|
* @see [Quaternion](https://en.wikipedia.org/wiki/Quaternion)
|
|
978
1096
|
*/
|
|
979
|
-
public transformQuaternion<T extends Vector4Like>(
|
|
980
|
-
|
|
981
|
-
|
|
1097
|
+
public transformQuaternion<T extends Vector4Like>(
|
|
1098
|
+
quaternion: QuaternionLike,
|
|
1099
|
+
out: T
|
|
1100
|
+
): T;
|
|
1101
|
+
|
|
1102
|
+
public transformQuaternion<T extends Vector4Like>(
|
|
1103
|
+
quaternion: QuaternionLike,
|
|
1104
|
+
out: T = new Vector4() as T
|
|
1105
|
+
): T {
|
|
982
1106
|
return transformQuaternion(this, quaternion, out);
|
|
983
1107
|
}
|
|
984
1108
|
}
|
package/src/types/AxisAngle.ts
CHANGED
package/src/utility/BigNumber.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import greatestCommonDivisor from "#
|
|
2
|
-
import type { IntegerRepresentation } from "#
|
|
1
|
+
import greatestCommonDivisor from "#greatestCommonDivisor";
|
|
2
|
+
import type { IntegerRepresentation } from "#IntegerRepresentation";
|
|
3
3
|
|
|
4
4
|
/** A number with no maximum precise size. */
|
|
5
5
|
export default class BigNumber {
|
|
@@ -14,12 +14,20 @@ export default class BigNumber {
|
|
|
14
14
|
* @param dividend The dividend of the fraction.
|
|
15
15
|
* @param divisor The divisor of the fraction.
|
|
16
16
|
*/
|
|
17
|
-
public constructor(
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
public constructor(
|
|
18
|
+
dividend?: IntegerRepresentation,
|
|
19
|
+
divisor?: IntegerRepresentation
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
public constructor(
|
|
23
|
+
dividend: IntegerRepresentation = 0,
|
|
24
|
+
divisor: IntegerRepresentation = 1
|
|
25
|
+
) {
|
|
20
26
|
this.dividend = BigInt(dividend);
|
|
21
27
|
this.divisor = BigInt(divisor);
|
|
22
|
-
if (!this.divisor) {
|
|
28
|
+
if (!this.divisor) {
|
|
29
|
+
throw new Error("Cannot divide by zero.");
|
|
30
|
+
}
|
|
23
31
|
this.simplify();
|
|
24
32
|
}
|
|
25
33
|
|
|
@@ -118,7 +126,10 @@ export default class BigNumber {
|
|
|
118
126
|
* @returns This number as a `number`.
|
|
119
127
|
*/
|
|
120
128
|
public toNumber(): number {
|
|
121
|
-
return
|
|
129
|
+
return (
|
|
130
|
+
Number(this.dividend / this.divisor) +
|
|
131
|
+
Number(this.dividend % this.divisor) / Number(this.divisor)
|
|
132
|
+
);
|
|
122
133
|
}
|
|
123
134
|
|
|
124
135
|
/**
|