@lakuna/umath 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dist/algorithms/hypergeometricPmf.d.ts.map +1 -1
  2. package/dist/algorithms/hypergeometricPmf.js +5 -1
  3. package/dist/algorithms/hypergeometricPmf.js.map +1 -1
  4. package/dist/algorithms/primeFactorization.d.ts +1 -1
  5. package/dist/algorithms/primeFactorization.d.ts.map +1 -1
  6. package/dist/index.d.ts +0 -3
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +0 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/linalg/DualQuaternion.d.ts +46 -46
  11. package/dist/linalg/DualQuaternion.d.ts.map +1 -1
  12. package/dist/linalg/DualQuaternion.js.map +1 -1
  13. package/dist/linalg/Matrix.d.ts +7 -7
  14. package/dist/linalg/Matrix.d.ts.map +1 -1
  15. package/dist/linalg/Matrix2.d.ts +25 -25
  16. package/dist/linalg/Matrix2.d.ts.map +1 -1
  17. package/dist/linalg/Matrix2.js.map +1 -1
  18. package/dist/linalg/Matrix3.d.ts +35 -35
  19. package/dist/linalg/Matrix3.d.ts.map +1 -1
  20. package/dist/linalg/Matrix3.js.map +1 -1
  21. package/dist/linalg/Matrix4.d.ts +64 -59
  22. package/dist/linalg/Matrix4.d.ts.map +1 -1
  23. package/dist/linalg/Matrix4.js +17 -11
  24. package/dist/linalg/Matrix4.js.map +1 -1
  25. package/dist/linalg/Quaternion.d.ts +50 -48
  26. package/dist/linalg/Quaternion.d.ts.map +1 -1
  27. package/dist/linalg/Quaternion.js +11 -12
  28. package/dist/linalg/Quaternion.js.map +1 -1
  29. package/dist/linalg/SlowMatrix.d.ts +8 -8
  30. package/dist/linalg/SlowMatrix.d.ts.map +1 -1
  31. package/dist/linalg/SlowMatrix.js.map +1 -1
  32. package/dist/linalg/SlowSquareMatrix.d.ts +1 -1
  33. package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
  34. package/dist/linalg/SlowSquareMatrix.js.map +1 -1
  35. package/dist/linalg/SlowVector.d.ts +15 -15
  36. package/dist/linalg/SlowVector.d.ts.map +1 -1
  37. package/dist/linalg/SlowVector.js.map +1 -1
  38. package/dist/linalg/Vector.d.ts +14 -14
  39. package/dist/linalg/Vector.d.ts.map +1 -1
  40. package/dist/linalg/Vector2.d.ts +51 -51
  41. package/dist/linalg/Vector2.d.ts.map +1 -1
  42. package/dist/linalg/Vector2.js.map +1 -1
  43. package/dist/linalg/Vector3.d.ts +60 -60
  44. package/dist/linalg/Vector3.d.ts.map +1 -1
  45. package/dist/linalg/Vector3.js.map +1 -1
  46. package/dist/linalg/Vector4.d.ts +45 -45
  47. package/dist/linalg/Vector4.d.ts.map +1 -1
  48. package/dist/linalg/Vector4.js.map +1 -1
  49. package/dist/utility/BigNumber.d.ts +5 -5
  50. package/dist/utility/BigNumber.d.ts.map +1 -1
  51. package/dist/utility/BigNumber.js +13 -6
  52. package/dist/utility/BigNumber.js.map +1 -1
  53. package/package.json +36 -36
  54. package/src/algorithms/hypergeometricPmf.ts +2 -0
  55. package/src/algorithms/primeFactorization.ts +1 -1
  56. package/src/index.ts +0 -5
  57. package/src/linalg/DualQuaternion.ts +69 -58
  58. package/src/linalg/Matrix.ts +10 -7
  59. package/src/linalg/Matrix2.ts +43 -32
  60. package/src/linalg/Matrix3.ts +53 -41
  61. package/src/linalg/Matrix4.ts +127 -94
  62. package/src/linalg/Quaternion.ts +90 -75
  63. package/src/linalg/SlowMatrix.ts +12 -9
  64. package/src/linalg/SlowSquareMatrix.ts +1 -1
  65. package/src/linalg/SlowVector.ts +16 -16
  66. package/src/linalg/Vector.ts +14 -14
  67. package/src/linalg/Vector2.ts +104 -76
  68. package/src/linalg/Vector3.ts +125 -92
  69. package/src/linalg/Vector4.ts +93 -62
  70. package/src/utility/BigNumber.ts +22 -11
  71. package/dist/types/AxisAngle.d.ts +0 -12
  72. package/dist/types/AxisAngle.d.ts.map +0 -1
  73. package/dist/types/AxisAngle.js +0 -2
  74. package/dist/types/AxisAngle.js.map +0 -1
  75. package/dist/types/FieldOfView.d.ts +0 -15
  76. package/dist/types/FieldOfView.d.ts.map +0 -1
  77. package/dist/types/FieldOfView.js +0 -2
  78. package/dist/types/FieldOfView.js.map +0 -1
  79. package/dist/utility/createAxisAngleLike.d.ts +0 -10
  80. package/dist/utility/createAxisAngleLike.d.ts.map +0 -1
  81. package/dist/utility/createAxisAngleLike.js +0 -10
  82. package/dist/utility/createAxisAngleLike.js.map +0 -1
  83. package/src/types/AxisAngle.ts +0 -13
  84. package/src/types/FieldOfView.ts +0 -17
  85. package/src/utility/createAxisAngleLike.ts +0 -14
@@ -66,7 +66,10 @@ export const fromValues = <T extends Vector4Like>(
66
66
  * @returns Whether or not the vectors are equivalent.
67
67
  * @public
68
68
  */
69
- export const equals = (a: Vector4Like, b: Vector4Like): boolean =>
69
+ export const equals = (
70
+ a: Readonly<Vector4Like>,
71
+ b: Readonly<Vector4Like>
72
+ ): boolean =>
70
73
  approxRelative(a[0], b[0]) &&
71
74
  approxRelative(a[1], b[1]) &&
72
75
  approxRelative(a[2], b[2]) &&
@@ -79,8 +82,10 @@ export const equals = (a: Vector4Like, b: Vector4Like): boolean =>
79
82
  * @returns Whether or not the vectors are equivalent.
80
83
  * @public
81
84
  */
82
- export const exactEquals = (a: Vector4Like, b: Vector4Like): boolean =>
83
- a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
85
+ export const exactEquals = (
86
+ a: Readonly<Vector4Like>,
87
+ b: Readonly<Vector4Like>
88
+ ): boolean => a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
84
89
 
85
90
  /**
86
91
  * Add two vectors.
@@ -91,8 +96,8 @@ export const exactEquals = (a: Vector4Like, b: Vector4Like): boolean =>
91
96
  * @public
92
97
  */
93
98
  export const add = <T extends Vector4Like>(
94
- a: Vector4Like,
95
- b: Vector4Like,
99
+ a: Readonly<Vector4Like>,
100
+ b: Readonly<Vector4Like>,
96
101
  out: T
97
102
  ): T => fromValues(a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3], out);
98
103
 
@@ -103,8 +108,10 @@ export const add = <T extends Vector4Like>(
103
108
  * @returns The copy.
104
109
  * @public
105
110
  */
106
- export const copy = <T extends Vector4Like>(vector: Vector4Like, out: T): T =>
107
- fromValues(vector[0], vector[1], vector[2], vector[3], out);
111
+ export const copy = <T extends Vector4Like>(
112
+ vector: Readonly<Vector4Like>,
113
+ out: T
114
+ ): T => fromValues(vector[0], vector[1], vector[2], vector[3], out);
108
115
 
109
116
  /**
110
117
  * Multiply two vectors.
@@ -115,8 +122,8 @@ export const copy = <T extends Vector4Like>(vector: Vector4Like, out: T): T =>
115
122
  * @public
116
123
  */
117
124
  export const multiply = <T extends Vector4Like>(
118
- a: Vector4Like,
119
- b: Vector4Like,
125
+ a: Readonly<Vector4Like>,
126
+ b: Readonly<Vector4Like>,
120
127
  out: T
121
128
  ): T => fromValues(a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3], out);
122
129
 
@@ -129,8 +136,8 @@ export const multiply = <T extends Vector4Like>(
129
136
  * @public
130
137
  */
131
138
  export const divide = <T extends Vector4Like>(
132
- a: Vector4Like,
133
- b: Vector4Like,
139
+ a: Readonly<Vector4Like>,
140
+ b: Readonly<Vector4Like>,
134
141
  out: T
135
142
  ): T => fromValues(a[0] / b[0], a[1] / b[1], a[2] / b[2], a[3] / b[3], out);
136
143
 
@@ -143,8 +150,8 @@ export const divide = <T extends Vector4Like>(
143
150
  * @public
144
151
  */
145
152
  export const subtract = <T extends Vector4Like>(
146
- a: Vector4Like,
147
- b: Vector4Like,
153
+ a: Readonly<Vector4Like>,
154
+ b: Readonly<Vector4Like>,
148
155
  out: T
149
156
  ): T => fromValues(a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3], out);
150
157
 
@@ -155,7 +162,10 @@ export const subtract = <T extends Vector4Like>(
155
162
  * @returns The absolutized vector.
156
163
  * @public
157
164
  */
158
- export const abs = <T extends Vector4Like>(vector: Vector4Like, out: T): T =>
165
+ export const abs = <T extends Vector4Like>(
166
+ vector: Readonly<Vector4Like>,
167
+ out: T
168
+ ): T =>
159
169
  fromValues(
160
170
  Math.abs(vector[0]),
161
171
  Math.abs(vector[1]),
@@ -171,7 +181,10 @@ export const abs = <T extends Vector4Like>(vector: Vector4Like, out: T): T =>
171
181
  * @returns The rounded vector.
172
182
  * @public
173
183
  */
174
- export const ceil = <T extends Vector4Like>(vector: Vector4Like, out: T): T =>
184
+ export const ceil = <T extends Vector4Like>(
185
+ vector: Readonly<Vector4Like>,
186
+ out: T
187
+ ): T =>
175
188
  fromValues(
176
189
  Math.ceil(vector[0]),
177
190
  Math.ceil(vector[1]),
@@ -187,7 +200,10 @@ export const ceil = <T extends Vector4Like>(vector: Vector4Like, out: T): T =>
187
200
  * @returns The rounded vector.
188
201
  * @public
189
202
  */
190
- export const floor = <T extends Vector4Like>(vector: Vector4Like, out: T): T =>
203
+ export const floor = <T extends Vector4Like>(
204
+ vector: Readonly<Vector4Like>,
205
+ out: T
206
+ ): T =>
191
207
  fromValues(
192
208
  Math.floor(vector[0]),
193
209
  Math.floor(vector[1]),
@@ -203,7 +219,10 @@ export const floor = <T extends Vector4Like>(vector: Vector4Like, out: T): T =>
203
219
  * @returns The rounded vector.
204
220
  * @public
205
221
  */
206
- export const round = <T extends Vector4Like>(vector: Vector4Like, out: T): T =>
222
+ export const round = <T extends Vector4Like>(
223
+ vector: Readonly<Vector4Like>,
224
+ out: T
225
+ ): T =>
207
226
  fromValues(
208
227
  Math.round(vector[0]),
209
228
  Math.round(vector[1]),
@@ -221,8 +240,8 @@ export const round = <T extends Vector4Like>(vector: Vector4Like, out: T): T =>
221
240
  * @public
222
241
  */
223
242
  export const min = <T extends Vector4Like>(
224
- a: Vector4Like,
225
- b: Vector4Like,
243
+ a: Readonly<Vector4Like>,
244
+ b: Readonly<Vector4Like>,
226
245
  out: T
227
246
  ): T =>
228
247
  fromValues(
@@ -242,8 +261,8 @@ export const min = <T extends Vector4Like>(
242
261
  * @public
243
262
  */
244
263
  export const max = <T extends Vector4Like>(
245
- a: Vector4Like,
246
- b: Vector4Like,
264
+ a: Readonly<Vector4Like>,
265
+ b: Readonly<Vector4Like>,
247
266
  out: T
248
267
  ): T =>
249
268
  fromValues(
@@ -263,7 +282,7 @@ export const max = <T extends Vector4Like>(
263
282
  * @public
264
283
  */
265
284
  export const pow = <T extends Vector4Like>(
266
- vector: Vector4Like,
285
+ vector: Readonly<Vector4Like>,
267
286
  scalar: number,
268
287
  out: T
269
288
  ): T =>
@@ -284,7 +303,7 @@ export const pow = <T extends Vector4Like>(
284
303
  * @public
285
304
  */
286
305
  export const scale = <T extends Vector4Like>(
287
- vector: Vector4Like,
306
+ vector: Readonly<Vector4Like>,
288
307
  scalar: number,
289
308
  out: T
290
309
  ): T =>
@@ -306,8 +325,8 @@ export const scale = <T extends Vector4Like>(
306
325
  * @public
307
326
  */
308
327
  export const scaleAndAdd = <T extends Vector4Like>(
309
- a: Vector4Like,
310
- b: Vector4Like,
328
+ a: Readonly<Vector4Like>,
329
+ b: Readonly<Vector4Like>,
311
330
  scalar: number,
312
331
  out: T
313
332
  ): T =>
@@ -327,8 +346,10 @@ export const scaleAndAdd = <T extends Vector4Like>(
327
346
  * @see {@link https://en.wikipedia.org/wiki/Euclidean_distance | Euclidean distance}
328
347
  * @public
329
348
  */
330
- export const distance = (a: Vector4Like, b: Vector4Like): number =>
331
- Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3]);
349
+ export const distance = (
350
+ a: Readonly<Vector4Like>,
351
+ b: Readonly<Vector4Like>
352
+ ): number => Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3]);
332
353
 
333
354
  /**
334
355
  * Calculate the squared Euclidean distance between two vectors.
@@ -338,7 +359,10 @@ export const distance = (a: Vector4Like, b: Vector4Like): number =>
338
359
  * @see {@link https://en.wikipedia.org/wiki/Euclidean_distance | Euclidean distance}
339
360
  * @public
340
361
  */
341
- export const squaredDistance = (a: Vector4Like, b: Vector4Like): number => {
362
+ export const squaredDistance = (
363
+ a: Readonly<Vector4Like>,
364
+ b: Readonly<Vector4Like>
365
+ ): number => {
342
366
  const x = a[0] - b[0];
343
367
  const y = a[1] - b[1];
344
368
  const z = a[2] - b[2];
@@ -352,7 +376,7 @@ export const squaredDistance = (a: Vector4Like, b: Vector4Like): number => {
352
376
  * @returns The magnitude.
353
377
  * @public
354
378
  */
355
- export const getMagnitude = (vector: Vector4Like): number =>
379
+ export const getMagnitude = (vector: Readonly<Vector4Like>): number =>
356
380
  Math.hypot(vector[0], vector[1], vector[2], vector[3]);
357
381
 
358
382
  /**
@@ -361,7 +385,7 @@ export const getMagnitude = (vector: Vector4Like): number =>
361
385
  * @returns The magnitude.
362
386
  * @public
363
387
  */
364
- export const getSquaredMagnitude = (vector: Vector4Like): number => {
388
+ export const getSquaredMagnitude = (vector: Readonly<Vector4Like>): number => {
365
389
  const x = vector[0];
366
390
  const y = vector[1];
367
391
  const z = vector[2];
@@ -376,8 +400,10 @@ export const getSquaredMagnitude = (vector: Vector4Like): number => {
376
400
  * @returns The negated vector.
377
401
  * @public
378
402
  */
379
- export const negate = <T extends Vector4Like>(vector: Vector4Like, out: T): T =>
380
- fromValues(-vector[0], -vector[1], -vector[2], -vector[3], out);
403
+ export const negate = <T extends Vector4Like>(
404
+ vector: Readonly<Vector4Like>,
405
+ out: T
406
+ ): T => fromValues(-vector[0], -vector[1], -vector[2], -vector[3], out);
381
407
 
382
408
  /**
383
409
  * Calculate the multiplicative inverse of the components of a vector.
@@ -386,7 +412,10 @@ export const negate = <T extends Vector4Like>(vector: Vector4Like, out: T): T =>
386
412
  * @returns The inverted vector.
387
413
  * @public
388
414
  */
389
- export const invert = <T extends Vector4Like>(vector: Vector4Like, out: T): T =>
415
+ export const invert = <T extends Vector4Like>(
416
+ vector: Readonly<Vector4Like>,
417
+ out: T
418
+ ): T =>
390
419
  fromValues(1 / vector[0], 1 / vector[1], 1 / vector[2], 1 / vector[3], out);
391
420
 
392
421
  /**
@@ -398,7 +427,7 @@ export const invert = <T extends Vector4Like>(vector: Vector4Like, out: T): T =>
398
427
  * @public
399
428
  */
400
429
  export const normalize = <T extends Vector4Like>(
401
- vector: Vector4Like,
430
+ vector: Readonly<Vector4Like>,
402
431
  out: T
403
432
  ): T => {
404
433
  const x = vector[0];
@@ -422,8 +451,10 @@ export const normalize = <T extends Vector4Like>(
422
451
  * @see {@link https://en.wikipedia.org/wiki/Dot_product | Dot product}
423
452
  * @public
424
453
  */
425
- export const dot = (a: Vector4Like, b: Vector4Like): number =>
426
- a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
454
+ export const dot = (
455
+ a: Readonly<Vector4Like>,
456
+ b: Readonly<Vector4Like>
457
+ ): number => a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
427
458
 
428
459
  /**
429
460
  * Calculate the cross product of three vectors in a four-dimensional space.
@@ -436,9 +467,9 @@ export const dot = (a: Vector4Like, b: Vector4Like): number =>
436
467
  * @public
437
468
  */
438
469
  export const cross = <T extends Vector4Like>(
439
- a: Vector4Like,
440
- b: Vector4Like,
441
- c: Vector4Like,
470
+ a: Readonly<Vector4Like>,
471
+ b: Readonly<Vector4Like>,
472
+ c: Readonly<Vector4Like>,
442
473
  out: T
443
474
  ): T => {
444
475
  const a0 = a[0];
@@ -483,8 +514,8 @@ export const cross = <T extends Vector4Like>(
483
514
  * @public
484
515
  */
485
516
  export const lerp = <T extends Vector4Like>(
486
- a: Vector4Like,
487
- b: Vector4Like,
517
+ a: Readonly<Vector4Like>,
518
+ b: Readonly<Vector4Like>,
488
519
  t: number,
489
520
  out: T
490
521
  ): T => {
@@ -540,8 +571,8 @@ export const random = <T extends Vector4Like>(magnitude: number, out: T): T => {
540
571
  * @public
541
572
  */
542
573
  export const transformMatrix4 = <T extends Vector4Like>(
543
- vector: Vector4Like,
544
- matrix: Matrix4Like,
574
+ vector: Readonly<Vector4Like>,
575
+ matrix: Readonly<Matrix4Like>,
545
576
  out: T
546
577
  ): T => {
547
578
  const x = vector[0];
@@ -578,8 +609,8 @@ export const zero = <T extends Vector4Like>(out: T): T =>
578
609
  * @public
579
610
  */
580
611
  export const transformQuaternion = <T extends Vector4Like>(
581
- vector: Vector4Like,
582
- quaternion: QuaternionLike,
612
+ vector: Readonly<Vector4Like>,
613
+ quaternion: Readonly<QuaternionLike>,
583
614
  out: T
584
615
  ): T => {
585
616
  const x = vector[0];
@@ -685,7 +716,7 @@ export default class Vector4
685
716
  * @param vector - The other vector.
686
717
  * @returns The sum of the vectors.
687
718
  */
688
- public add(vector: Vector4Like): Vector4 {
719
+ public add(vector: Readonly<Vector4Like>): Vector4 {
689
720
  return add(this, vector, new Vector4());
690
721
  }
691
722
 
@@ -710,7 +741,7 @@ export default class Vector4
710
741
  * @param vector - The vector to copy.
711
742
  * @returns This vector.
712
743
  */
713
- public copy(vector: Vector4Like): this {
744
+ public copy(vector: Readonly<Vector4Like>): this {
714
745
  return copy(vector, this);
715
746
  }
716
747
 
@@ -721,7 +752,7 @@ export default class Vector4
721
752
  * @returns The cross product.
722
753
  * @see {@link https://en.wikipedia.org/wiki/Cross_product | Cross product}
723
754
  */
724
- public cross(a: Vector4Like, b: Vector4Like): Vector4 {
755
+ public cross(a: Readonly<Vector4Like>, b: Readonly<Vector4Like>): Vector4 {
725
756
  return cross(this, a, b, new Vector4());
726
757
  }
727
758
 
@@ -731,7 +762,7 @@ export default class Vector4
731
762
  * @returns The distance.
732
763
  * @see {@link https://en.wikipedia.org/wiki/Euclidean_distance | Euclidean distance}
733
764
  */
734
- public distance(vector: Vector4Like): number {
765
+ public distance(vector: Readonly<Vector4Like>): number {
735
766
  return distance(this, vector);
736
767
  }
737
768
 
@@ -740,7 +771,7 @@ export default class Vector4
740
771
  * @param vector - The other vector.
741
772
  * @returns The quotient of the vectors.
742
773
  */
743
- public divide(vector: Vector4Like): Vector4 {
774
+ public divide(vector: Readonly<Vector4Like>): Vector4 {
744
775
  return divide(this, vector, new Vector4());
745
776
  }
746
777
 
@@ -750,7 +781,7 @@ export default class Vector4
750
781
  * @returns The dot product.
751
782
  * @see {@link https://en.wikipedia.org/wiki/Dot_product | Dot product}
752
783
  */
753
- public dot(vector: Vector4Like): number {
784
+ public dot(vector: Readonly<Vector4Like>): number {
754
785
  return dot(this, vector);
755
786
  }
756
787
 
@@ -759,7 +790,7 @@ export default class Vector4
759
790
  * @param vector - The other vector.
760
791
  * @returns Whether or no tthe vectors are equivalent.
761
792
  */
762
- public equals(vector: Vector4Like): boolean {
793
+ public equals(vector: Readonly<Vector4Like>): boolean {
763
794
  return equals(this, vector);
764
795
  }
765
796
 
@@ -768,7 +799,7 @@ export default class Vector4
768
799
  * @param vector - The other vector.
769
800
  * @returns Whether the vectors are equivalent.
770
801
  */
771
- public exactEquals(vector: Vector4Like): boolean {
802
+ public exactEquals(vector: Readonly<Vector4Like>): boolean {
772
803
  return exactEquals(this, vector);
773
804
  }
774
805
 
@@ -795,7 +826,7 @@ export default class Vector4
795
826
  * @returns The interpolated vector.
796
827
  * @see {@link https://en.wikipedia.org/wiki/Linear_interpolation | Linear interpolation}
797
828
  */
798
- public lerp(vector: Vector4Like, t: number): Vector4 {
829
+ public lerp(vector: Readonly<Vector4Like>, t: number): Vector4 {
799
830
  return lerp(this, vector, t, new Vector4());
800
831
  }
801
832
 
@@ -804,7 +835,7 @@ export default class Vector4
804
835
  * @param vector - The other vector.
805
836
  * @returns The maximum.
806
837
  */
807
- public max(vector: Vector4Like): Vector4 {
838
+ public max(vector: Readonly<Vector4Like>): Vector4 {
808
839
  return max(this, vector, new Vector4());
809
840
  }
810
841
 
@@ -813,7 +844,7 @@ export default class Vector4
813
844
  * @param vector - The other vector.
814
845
  * @returns The minimum.
815
846
  */
816
- public min(vector: Vector4Like): Vector4 {
847
+ public min(vector: Readonly<Vector4Like>): Vector4 {
817
848
  return min(this, vector, new Vector4());
818
849
  }
819
850
 
@@ -822,7 +853,7 @@ export default class Vector4
822
853
  * @param vector - The other vector.
823
854
  * @returns The product of the vectors.
824
855
  */
825
- public multiply(vector: Vector4Like): Vector4 {
856
+ public multiply(vector: Readonly<Vector4Like>): Vector4 {
826
857
  return multiply(this, vector, new Vector4());
827
858
  }
828
859
 
@@ -884,7 +915,7 @@ export default class Vector4
884
915
  * @param scalar - The scalar.
885
916
  * @returns The sum.
886
917
  */
887
- public scaleAndAdd(vector: Vector4Like, scalar: number): Vector4 {
918
+ public scaleAndAdd(vector: Readonly<Vector4Like>, scalar: number): Vector4 {
888
919
  return scaleAndAdd(this, vector, scalar, new Vector4());
889
920
  }
890
921
 
@@ -894,7 +925,7 @@ export default class Vector4
894
925
  * @returns The squared distance.
895
926
  * @see {@link https://en.wikipedia.org/wiki/Euclidean_distance | Euclidean distance}
896
927
  */
897
- public squaredDistance(vector: Vector4Like): number {
928
+ public squaredDistance(vector: Readonly<Vector4Like>): number {
898
929
  return squaredDistance(this, vector);
899
930
  }
900
931
 
@@ -903,7 +934,7 @@ export default class Vector4
903
934
  * @param vector - The other vector.
904
935
  * @returns The difference between the vectors.
905
936
  */
906
- public subtract(vector: Vector4Like): Vector4 {
937
+ public subtract(vector: Readonly<Vector4Like>): Vector4 {
907
938
  return subtract(this, vector, new Vector4());
908
939
  }
909
940
 
@@ -913,7 +944,7 @@ export default class Vector4
913
944
  * @returns The transformed vector.
914
945
  * @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
915
946
  */
916
- public transformMatrix4(matrix: Matrix4Like): Vector4 {
947
+ public transformMatrix4(matrix: Readonly<Matrix4Like>): Vector4 {
917
948
  return transformMatrix4(this, matrix, new Vector4());
918
949
  }
919
950
 
@@ -923,7 +954,7 @@ export default class Vector4
923
954
  * @returns The transformed vector.
924
955
  * @see {@link https://en.wikipedia.org/wiki/Quaternion | Quaternion}
925
956
  */
926
- public transformQuaternion(quaternion: QuaternionLike): Vector4 {
957
+ public transformQuaternion(quaternion: Readonly<QuaternionLike>): Vector4 {
927
958
  return transformQuaternion(this, quaternion, new Vector4());
928
959
  }
929
960
 
@@ -28,12 +28,15 @@ export default class BigNumber {
28
28
  * @param dividend - The dividend of the number.
29
29
  * @param divisor - The divisor of the number.
30
30
  */
31
- public constructor(dividend: BigNumberLike = 0, divisor: BigNumberLike = 1) {
31
+ public constructor(
32
+ dividend: Readonly<BigNumberLike> = 0,
33
+ divisor: Readonly<BigNumberLike> = 1
34
+ ) {
32
35
  if (divisor === 0) {
33
36
  throw new Error("Cannot divide by zero.");
34
37
  }
35
38
 
36
- if (dividend instanceof BigNumber) {
39
+ if (BigNumber.is(dividend)) {
37
40
  this.dividend = dividend.dividend;
38
41
  this.divisor = dividend.divisor;
39
42
  this.divide(divisor);
@@ -41,7 +44,7 @@ export default class BigNumber {
41
44
  }
42
45
 
43
46
  this.dividend = BigInt(dividend);
44
- if (divisor instanceof BigNumber) {
47
+ if (BigNumber.is(divisor)) {
45
48
  this.divisor = 1n;
46
49
  this.divide(divisor);
47
50
  return;
@@ -51,13 +54,21 @@ export default class BigNumber {
51
54
  this.simplify();
52
55
  }
53
56
 
57
+ /**
58
+ * Utility function for narrowing `Readonly<BigNumberLike>` to `Readonly<BigNumber>` or `BigIntLike`, since `Readonly` breaks the type narrowing for TypeScript.
59
+ * @internal
60
+ */
61
+ private static is(value: unknown): value is BigNumber | Readonly<BigNumber> {
62
+ return value instanceof BigNumber;
63
+ }
64
+
54
65
  /**
55
66
  * Add a number to this number.
56
67
  * @param n - The other number.
57
68
  * @returns This number.
58
69
  */
59
- public add(n: BigNumberLike): this {
60
- if (n instanceof BigNumber) {
70
+ public add(n: Readonly<BigNumberLike>): this {
71
+ if (BigNumber.is(n)) {
61
72
  this.dividend = this.dividend * n.divisor + n.dividend * this.divisor;
62
73
  this.divisor *= n.divisor;
63
74
  } else {
@@ -73,8 +84,8 @@ export default class BigNumber {
73
84
  * @param n - The other number.
74
85
  * @returns This number.
75
86
  */
76
- public divide(n: BigNumberLike): this {
77
- if (n instanceof BigNumber) {
87
+ public divide(n: Readonly<BigNumberLike>): this {
88
+ if (BigNumber.is(n)) {
78
89
  this.dividend *= n.divisor;
79
90
  this.divisor *= n.dividend;
80
91
  } else {
@@ -90,8 +101,8 @@ export default class BigNumber {
90
101
  * @param n - The other number.
91
102
  * @returns This number.
92
103
  */
93
- public multiply(n: BigNumberLike): this {
94
- if (n instanceof BigNumber) {
104
+ public multiply(n: Readonly<BigNumberLike>): this {
105
+ if (BigNumber.is(n)) {
95
106
  this.dividend *= n.dividend;
96
107
  this.divisor *= n.divisor;
97
108
  } else {
@@ -107,8 +118,8 @@ export default class BigNumber {
107
118
  * @param n - The other number.
108
119
  * @returns This number.
109
120
  */
110
- public subtract(n: BigNumberLike): this {
111
- if (n instanceof BigNumber) {
121
+ public subtract(n: Readonly<BigNumberLike>): this {
122
+ if (BigNumber.is(n)) {
112
123
  this.dividend = this.dividend * n.divisor - n.dividend * this.divisor;
113
124
  this.divisor *= n.divisor;
114
125
  } else {
@@ -1,12 +0,0 @@
1
- import type { Vector3Like } from "../linalg/Vector3.js";
2
- /**
3
- * An axis and an angle to rotate around it.
4
- * @public
5
- */
6
- export default interface AxisAngle {
7
- /** The angle to rotate around the axis by in radians. */
8
- angle: number;
9
- /** The axis to rotate around. */
10
- axis: Vector3Like;
11
- }
12
- //# sourceMappingURL=AxisAngle.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AxisAngle.d.ts","sourceRoot":"","sources":["../../src/types/AxisAngle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD;;;GAGG;AACH,MAAM,CAAC,OAAO,WAAW,SAAS;IACjC,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IAEd,iCAAiC;IACjC,IAAI,EAAE,WAAW,CAAC;CAClB"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=AxisAngle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AxisAngle.js","sourceRoot":"","sources":["../../src/types/AxisAngle.ts"],"names":[],"mappings":""}
@@ -1,15 +0,0 @@
1
- /**
2
- * A field of view.
3
- * @public
4
- */
5
- export default interface FieldOfView {
6
- /** The angle to the bottom of the field of view in degrees. */
7
- downDegrees: number;
8
- /** The angle to the left edge of the field of view in degrees. */
9
- leftDegrees: number;
10
- /** The angle to the right edge of the field of view in degrees. */
11
- rightDegrees: number;
12
- /** The angle to the top of the field of view in degrees. */
13
- upDegrees: number;
14
- }
15
- //# sourceMappingURL=FieldOfView.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FieldOfView.d.ts","sourceRoot":"","sources":["../../src/types/FieldOfView.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,OAAO,WAAW,WAAW;IACnC,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC;IAEpB,kEAAkE;IAClE,WAAW,EAAE,MAAM,CAAC;IAEpB,mEAAmE;IACnE,YAAY,EAAE,MAAM,CAAC;IAErB,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAC;CAClB"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=FieldOfView.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FieldOfView.js","sourceRoot":"","sources":["../../src/types/FieldOfView.ts"],"names":[],"mappings":""}
@@ -1,10 +0,0 @@
1
- import type AxisAngle from "../types/AxisAngle.js";
2
- /**
3
- * Create an empty axis-angle pair.
4
- * @returns An empty axis-angle pair.
5
- * @public
6
- */
7
- export default function createAxisAngleLike(): AxisAngle & {
8
- axis: Float32Array;
9
- };
10
- //# sourceMappingURL=createAxisAngleLike.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAxisAngleLike.d.ts","sourceRoot":"","sources":["../../src/utility/createAxisAngleLike.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AAInD;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,IAAI,SAAS,GAAG;IAC1D,IAAI,EAAE,YAAY,CAAC;CACnB,CAEA"}
@@ -1,10 +0,0 @@
1
- import { createVector3Like } from "../linalg/Vector3.js";
2
- /**
3
- * Create an empty axis-angle pair.
4
- * @returns An empty axis-angle pair.
5
- * @public
6
- */
7
- export default function createAxisAngleLike() {
8
- return { angle: 0, axis: createVector3Like() };
9
- }
10
- //# sourceMappingURL=createAxisAngleLike.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAxisAngleLike.js","sourceRoot":"","sources":["../../src/utility/createAxisAngleLike.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB;IAG1C,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,CAAC;AAChD,CAAC"}
@@ -1,13 +0,0 @@
1
- import type { Vector3Like } from "../linalg/Vector3.js";
2
-
3
- /**
4
- * An axis and an angle to rotate around it.
5
- * @public
6
- */
7
- export default interface AxisAngle {
8
- /** The angle to rotate around the axis by in radians. */
9
- angle: number;
10
-
11
- /** The axis to rotate around. */
12
- axis: Vector3Like;
13
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * A field of view.
3
- * @public
4
- */
5
- export default interface FieldOfView {
6
- /** The angle to the bottom of the field of view in degrees. */
7
- downDegrees: number;
8
-
9
- /** The angle to the left edge of the field of view in degrees. */
10
- leftDegrees: number;
11
-
12
- /** The angle to the right edge of the field of view in degrees. */
13
- rightDegrees: number;
14
-
15
- /** The angle to the top of the field of view in degrees. */
16
- upDegrees: number;
17
- }
@@ -1,14 +0,0 @@
1
- import type AxisAngle from "../types/AxisAngle.js";
2
-
3
- import { createVector3Like } from "../linalg/Vector3.js";
4
-
5
- /**
6
- * Create an empty axis-angle pair.
7
- * @returns An empty axis-angle pair.
8
- * @public
9
- */
10
- export default function createAxisAngleLike(): AxisAngle & {
11
- axis: Float32Array;
12
- } {
13
- return { angle: 0, axis: createVector3Like() };
14
- }