@lakuna/umath 1.3.5 → 1.3.7

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 (141) hide show
  1. package/LICENSE +1 -1
  2. package/dist/algorithms/combinations.d.ts +7 -0
  3. package/dist/algorithms/combinations.d.ts.map +1 -1
  4. package/dist/algorithms/combinations.js +7 -0
  5. package/dist/algorithms/combinations.js.map +1 -1
  6. package/dist/algorithms/degreesToRadians.d.ts +7 -0
  7. package/dist/algorithms/degreesToRadians.d.ts.map +1 -1
  8. package/dist/algorithms/degreesToRadians.js +7 -0
  9. package/dist/algorithms/degreesToRadians.js.map +1 -1
  10. package/dist/algorithms/factorial.d.ts +6 -0
  11. package/dist/algorithms/factorial.d.ts.map +1 -1
  12. package/dist/algorithms/factorial.js +8 -1
  13. package/dist/algorithms/factorial.js.map +1 -1
  14. package/dist/algorithms/fibonacci.d.ts +6 -1
  15. package/dist/algorithms/fibonacci.d.ts.map +1 -1
  16. package/dist/algorithms/fibonacci.js +5 -0
  17. package/dist/algorithms/fibonacci.js.map +1 -1
  18. package/dist/algorithms/greatestCommonDivisor.d.ts +14 -0
  19. package/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -1
  20. package/dist/algorithms/greatestCommonDivisor.js +2 -0
  21. package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
  22. package/dist/algorithms/hypergeometricPmf.d.ts +9 -0
  23. package/dist/algorithms/hypergeometricPmf.d.ts.map +1 -1
  24. package/dist/algorithms/hypergeometricPmf.js +9 -0
  25. package/dist/algorithms/hypergeometricPmf.js.map +1 -1
  26. package/dist/algorithms/isPrime.d.ts +6 -0
  27. package/dist/algorithms/isPrime.d.ts.map +1 -1
  28. package/dist/algorithms/isPrime.js +7 -0
  29. package/dist/algorithms/isPrime.js.map +1 -1
  30. package/dist/algorithms/permutations.d.ts +7 -0
  31. package/dist/algorithms/permutations.d.ts.map +1 -1
  32. package/dist/algorithms/permutations.js +7 -0
  33. package/dist/algorithms/permutations.js.map +1 -1
  34. package/dist/algorithms/primeFactorization.d.ts +6 -0
  35. package/dist/algorithms/primeFactorization.d.ts.map +1 -1
  36. package/dist/algorithms/primeFactorization.js +6 -0
  37. package/dist/algorithms/primeFactorization.js.map +1 -1
  38. package/dist/algorithms/radiansToDegrees.d.ts +7 -0
  39. package/dist/algorithms/radiansToDegrees.d.ts.map +1 -1
  40. package/dist/algorithms/radiansToDegrees.js +7 -0
  41. package/dist/algorithms/radiansToDegrees.js.map +1 -1
  42. package/dist/algorithms/summation.d.ts +8 -0
  43. package/dist/algorithms/summation.d.ts.map +1 -1
  44. package/dist/algorithms/summation.js +9 -0
  45. package/dist/algorithms/summation.js.map +1 -1
  46. package/dist/linalg/DualQuaternion.d.ts +410 -27
  47. package/dist/linalg/DualQuaternion.d.ts.map +1 -1
  48. package/dist/linalg/DualQuaternion.js +429 -54
  49. package/dist/linalg/DualQuaternion.js.map +1 -1
  50. package/dist/linalg/Matrix.d.ts +67 -0
  51. package/dist/linalg/Matrix.d.ts.map +1 -1
  52. package/dist/linalg/Matrix2.d.ts +309 -20
  53. package/dist/linalg/Matrix2.d.ts.map +1 -1
  54. package/dist/linalg/Matrix2.js +321 -40
  55. package/dist/linalg/Matrix2.js.map +1 -1
  56. package/dist/linalg/Matrix3.d.ts +424 -26
  57. package/dist/linalg/Matrix3.d.ts.map +1 -1
  58. package/dist/linalg/Matrix3.js +437 -52
  59. package/dist/linalg/Matrix3.js.map +1 -1
  60. package/dist/linalg/Matrix4.d.ts +766 -42
  61. package/dist/linalg/Matrix4.d.ts.map +1 -1
  62. package/dist/linalg/Matrix4.js +789 -84
  63. package/dist/linalg/Matrix4.js.map +1 -1
  64. package/dist/linalg/Quaternion.d.ts +359 -21
  65. package/dist/linalg/Quaternion.d.ts.map +1 -1
  66. package/dist/linalg/Quaternion.js +380 -42
  67. package/dist/linalg/Quaternion.js.map +1 -1
  68. package/dist/linalg/SlowMatrix.d.ts +70 -0
  69. package/dist/linalg/SlowMatrix.d.ts.map +1 -1
  70. package/dist/linalg/SlowMatrix.js +71 -0
  71. package/dist/linalg/SlowMatrix.js.map +1 -1
  72. package/dist/linalg/SlowSquareMatrix.d.ts +55 -0
  73. package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
  74. package/dist/linalg/SlowSquareMatrix.js +58 -0
  75. package/dist/linalg/SlowSquareMatrix.js.map +1 -1
  76. package/dist/linalg/SquareMatrix.d.ts +23 -0
  77. package/dist/linalg/SquareMatrix.d.ts.map +1 -1
  78. package/dist/linalg/Vector.d.ts +123 -0
  79. package/dist/linalg/Vector.d.ts.map +1 -1
  80. package/dist/linalg/Vector2.d.ts +450 -33
  81. package/dist/linalg/Vector2.d.ts.map +1 -1
  82. package/dist/linalg/Vector2.js +480 -66
  83. package/dist/linalg/Vector2.js.map +1 -1
  84. package/dist/linalg/Vector3.d.ts +542 -38
  85. package/dist/linalg/Vector3.d.ts.map +1 -1
  86. package/dist/linalg/Vector3.js +579 -76
  87. package/dist/linalg/Vector3.js.map +1 -1
  88. package/dist/linalg/Vector4.d.ts +416 -30
  89. package/dist/linalg/Vector4.d.ts.map +1 -1
  90. package/dist/linalg/Vector4.js +441 -60
  91. package/dist/linalg/Vector4.js.map +1 -1
  92. package/dist/types/AxisAngle.d.ts +3 -0
  93. package/dist/types/AxisAngle.d.ts.map +1 -1
  94. package/dist/types/FieldOfView.d.ts +5 -0
  95. package/dist/types/FieldOfView.d.ts.map +1 -1
  96. package/dist/utility/BigNumber.d.ts +36 -0
  97. package/dist/utility/BigNumber.d.ts.map +1 -1
  98. package/dist/utility/BigNumber.js +42 -0
  99. package/dist/utility/BigNumber.js.map +1 -1
  100. package/dist/utility/MagnitudeError.d.ts +5 -0
  101. package/dist/utility/MagnitudeError.d.ts.map +1 -1
  102. package/dist/utility/MagnitudeError.js +5 -0
  103. package/dist/utility/MagnitudeError.js.map +1 -1
  104. package/dist/utility/MatrixSizeError.d.ts +5 -0
  105. package/dist/utility/MatrixSizeError.d.ts.map +1 -1
  106. package/dist/utility/MatrixSizeError.js +5 -0
  107. package/dist/utility/MatrixSizeError.js.map +1 -1
  108. package/dist/utility/PartialMatrixError.d.ts +5 -0
  109. package/dist/utility/PartialMatrixError.d.ts.map +1 -1
  110. package/dist/utility/PartialMatrixError.js +5 -0
  111. package/dist/utility/PartialMatrixError.js.map +1 -1
  112. package/dist/utility/SingularMatrixError.d.ts +8 -0
  113. package/dist/utility/SingularMatrixError.d.ts.map +1 -1
  114. package/dist/utility/SingularMatrixError.js +8 -0
  115. package/dist/utility/SingularMatrixError.js.map +1 -1
  116. package/dist/utility/epsilon.d.ts +1 -0
  117. package/dist/utility/epsilon.d.ts.map +1 -1
  118. package/dist/utility/epsilon.js +1 -0
  119. package/dist/utility/epsilon.js.map +1 -1
  120. package/package.json +1 -1
  121. package/src/algorithms/combinations.ts +1 -1
  122. package/src/algorithms/degreesToRadians.ts +1 -1
  123. package/src/algorithms/factorial.ts +1 -1
  124. package/src/algorithms/fibonacci.ts +1 -1
  125. package/src/algorithms/hypergeometricPmf.ts +1 -1
  126. package/src/algorithms/isPrime.ts +1 -1
  127. package/src/algorithms/permutations.ts +1 -1
  128. package/src/algorithms/primeFactorization.ts +1 -1
  129. package/src/algorithms/radiansToDegrees.ts +1 -1
  130. package/src/algorithms/summation.ts +1 -1
  131. package/src/linalg/DualQuaternion.ts +115 -109
  132. package/src/linalg/Matrix2.ts +83 -70
  133. package/src/linalg/Matrix3.ts +107 -94
  134. package/src/linalg/Matrix4.ts +171 -155
  135. package/src/linalg/Quaternion.ts +96 -92
  136. package/src/linalg/SlowMatrix.ts +13 -13
  137. package/src/linalg/SlowSquareMatrix.ts +11 -11
  138. package/src/linalg/Vector2.ts +130 -116
  139. package/src/linalg/Vector3.ts +152 -135
  140. package/src/linalg/Vector4.ts +121 -104
  141. package/src/utility/BigNumber.ts +7 -7
@@ -22,9 +22,9 @@ export interface Vector4Like extends VectorLike {
22
22
  * Creates a 4x1 vector-like object.
23
23
  * @returns A 4x1 vector-like object.
24
24
  */
25
- export function createVector4Like() {
26
- return new Float32Array(4) as unknown as Vector4Like;
27
- }
25
+ export const createVector4Like = () => {
26
+ return new Float32Array(4) as Float32Array & Vector4Like;
27
+ };
28
28
 
29
29
  /**
30
30
  * Create a vector with the given values.
@@ -35,19 +35,19 @@ export function createVector4Like() {
35
35
  * @param out - The vector to store the result in.
36
36
  * @returns A new vector.
37
37
  */
38
- export function fromValues<T extends Vector4Like>(
38
+ export const fromValues = <T extends Vector4Like>(
39
39
  x: number,
40
40
  y: number,
41
41
  z: number,
42
42
  w: number,
43
43
  out: T
44
- ) {
44
+ ): T => {
45
45
  out[0] = x;
46
46
  out[1] = y;
47
47
  out[2] = z;
48
48
  out[3] = w;
49
49
  return out;
50
- }
50
+ };
51
51
 
52
52
  /**
53
53
  * Determine whether or not two vectors are roughly equivalent.
@@ -55,7 +55,7 @@ export function fromValues<T extends Vector4Like>(
55
55
  * @param b - The second vector.
56
56
  * @returns Whether or not the vectors are equivalent.
57
57
  */
58
- export function equals(a: Vector4Like, b: Vector4Like) {
58
+ export const equals = (a: Vector4Like, b: Vector4Like): boolean => {
59
59
  const a0 = a[0];
60
60
  const a1 = a[1];
61
61
  const a2 = a[2];
@@ -72,7 +72,7 @@ export function equals(a: Vector4Like, b: Vector4Like) {
72
72
  Math.abs(a2 - b2) <= epsilon * Math.max(1, Math.abs(a2), Math.abs(b2)) &&
73
73
  Math.abs(a3 - b3) <= epsilon * Math.max(1, Math.abs(a3), Math.abs(b3))
74
74
  );
75
- }
75
+ };
76
76
 
77
77
  /**
78
78
  * Determine whether or not two vectors are exactly equivalent.
@@ -80,9 +80,9 @@ export function equals(a: Vector4Like, b: Vector4Like) {
80
80
  * @param b - The second vector.
81
81
  * @returns Whether or not the vectors are equivalent.
82
82
  */
83
- export function exactEquals(a: Vector4Like, b: Vector4Like) {
83
+ export const exactEquals = (a: Vector4Like, b: Vector4Like): boolean => {
84
84
  return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
85
- }
85
+ };
86
86
 
87
87
  /**
88
88
  * Add two vectors.
@@ -91,17 +91,17 @@ export function exactEquals(a: Vector4Like, b: Vector4Like) {
91
91
  * @param out - The vector to store the result in.
92
92
  * @returns The sum.
93
93
  */
94
- export function add<T extends Vector4Like>(
94
+ export const add = <T extends Vector4Like>(
95
95
  a: Vector4Like,
96
96
  b: Vector4Like,
97
97
  out: T
98
- ) {
98
+ ): T => {
99
99
  out[0] = a[0] + b[0];
100
100
  out[1] = a[1] + b[1];
101
101
  out[2] = a[2] + b[2];
102
102
  out[3] = a[3] + b[3];
103
103
  return out;
104
- }
104
+ };
105
105
 
106
106
  /**
107
107
  * Copy the values from one vector to another.
@@ -109,13 +109,13 @@ export function add<T extends Vector4Like>(
109
109
  * @param out - The vector to store the result in.
110
110
  * @returns The copy.
111
111
  */
112
- export function copy<T extends Vector4Like>(vector: Vector4Like, out: T) {
112
+ export const copy = <T extends Vector4Like>(vector: Vector4Like, out: T): T => {
113
113
  out[0] = vector[0];
114
114
  out[1] = vector[1];
115
115
  out[2] = vector[2];
116
116
  out[3] = vector[3];
117
117
  return out;
118
- }
118
+ };
119
119
 
120
120
  /**
121
121
  * Multiply two vectors.
@@ -124,17 +124,17 @@ export function copy<T extends Vector4Like>(vector: Vector4Like, out: T) {
124
124
  * @param out - The vector to store the result in.
125
125
  * @returns The product.
126
126
  */
127
- export function multiply<T extends Vector4Like>(
127
+ export const multiply = <T extends Vector4Like>(
128
128
  a: Vector4Like,
129
129
  b: Vector4Like,
130
130
  out: T
131
- ) {
131
+ ): T => {
132
132
  out[0] = a[0] * b[0];
133
133
  out[1] = a[1] * b[1];
134
134
  out[2] = a[2] * b[2];
135
135
  out[3] = a[3] * b[3];
136
136
  return out;
137
- }
137
+ };
138
138
 
139
139
  /**
140
140
  * Divide two vectors.
@@ -143,17 +143,17 @@ export function multiply<T extends Vector4Like>(
143
143
  * @param out - The vector to store the result in.
144
144
  * @returns The quotient.
145
145
  */
146
- export function divide<T extends Vector4Like>(
146
+ export const divide = <T extends Vector4Like>(
147
147
  a: Vector4Like,
148
148
  b: Vector4Like,
149
149
  out: T
150
- ) {
150
+ ): T => {
151
151
  out[0] = a[0] / b[0];
152
152
  out[1] = a[1] / b[1];
153
153
  out[2] = a[2] / b[2];
154
154
  out[3] = a[3] / b[3];
155
155
  return out;
156
- }
156
+ };
157
157
 
158
158
  /**
159
159
  * Subtract two vectors.
@@ -162,17 +162,17 @@ export function divide<T extends Vector4Like>(
162
162
  * @param out - The vector to store the result in.
163
163
  * @returns The difference.
164
164
  */
165
- export function subtract<T extends Vector4Like>(
165
+ export const subtract = <T extends Vector4Like>(
166
166
  a: Vector4Like,
167
167
  b: Vector4Like,
168
168
  out: T
169
- ): T {
169
+ ): T => {
170
170
  out[0] = a[0] - b[0];
171
171
  out[1] = a[1] - b[1];
172
172
  out[2] = a[2] - b[2];
173
173
  out[3] = a[3] - b[3];
174
174
  return out;
175
- }
175
+ };
176
176
 
177
177
  /**
178
178
  * Round up the components of a vector.
@@ -180,13 +180,13 @@ export function subtract<T extends Vector4Like>(
180
180
  * @param out - The vector to store the result in.
181
181
  * @returns The rounded vector.
182
182
  */
183
- export function ceil<T extends Vector4Like>(vector: Vector4Like, out: T) {
183
+ export const ceil = <T extends Vector4Like>(vector: Vector4Like, out: T): T => {
184
184
  out[0] = Math.ceil(vector[0]);
185
185
  out[1] = Math.ceil(vector[1]);
186
186
  out[2] = Math.ceil(vector[2]);
187
187
  out[3] = Math.ceil(vector[3]);
188
188
  return out;
189
- }
189
+ };
190
190
 
191
191
  /**
192
192
  * Round down the components of a vector.
@@ -194,13 +194,16 @@ export function ceil<T extends Vector4Like>(vector: Vector4Like, out: T) {
194
194
  * @param out - The vector to store the result in.
195
195
  * @returns The rounded vector.
196
196
  */
197
- export function floor<T extends Vector4Like>(vector: Vector4Like, out: T) {
197
+ export const floor = <T extends Vector4Like>(
198
+ vector: Vector4Like,
199
+ out: T
200
+ ): T => {
198
201
  out[0] = Math.floor(vector[0]);
199
202
  out[1] = Math.floor(vector[1]);
200
203
  out[2] = Math.floor(vector[2]);
201
204
  out[3] = Math.floor(vector[3]);
202
205
  return out;
203
- }
206
+ };
204
207
 
205
208
  /**
206
209
  * Round the components of a vector.
@@ -208,13 +211,16 @@ export function floor<T extends Vector4Like>(vector: Vector4Like, out: T) {
208
211
  * @param out - The vector to store the result in.
209
212
  * @returns The rounded vector.
210
213
  */
211
- export function round<T extends Vector4Like>(vector: Vector4Like, out: T) {
214
+ export const round = <T extends Vector4Like>(
215
+ vector: Vector4Like,
216
+ out: T
217
+ ): T => {
212
218
  out[0] = Math.round(vector[0]);
213
219
  out[1] = Math.round(vector[1]);
214
220
  out[2] = Math.round(vector[2]);
215
221
  out[3] = Math.round(vector[3]);
216
222
  return out;
217
- }
223
+ };
218
224
 
219
225
  /**
220
226
  * Return the minimum of two vectors.
@@ -223,17 +229,17 @@ export function round<T extends Vector4Like>(vector: Vector4Like, out: T) {
223
229
  * @param out - The vector to store the result in.
224
230
  * @returns The minimum.
225
231
  */
226
- export function min<T extends Vector4Like>(
232
+ export const min = <T extends Vector4Like>(
227
233
  a: Vector4Like,
228
234
  b: Vector4Like,
229
235
  out: T
230
- ) {
236
+ ): T => {
231
237
  out[0] = Math.min(a[0], b[0]);
232
238
  out[1] = Math.min(a[1], b[1]);
233
239
  out[2] = Math.min(a[2], b[2]);
234
240
  out[3] = Math.min(a[3], b[3]);
235
241
  return out;
236
- }
242
+ };
237
243
 
238
244
  /**
239
245
  * Return the maximum of two vectors.
@@ -242,17 +248,17 @@ export function min<T extends Vector4Like>(
242
248
  * @param out - The vector to store the result in.
243
249
  * @returns The maximum.
244
250
  */
245
- export function max<T extends Vector4Like>(
251
+ export const max = <T extends Vector4Like>(
246
252
  a: Vector4Like,
247
253
  b: Vector4Like,
248
254
  out: T
249
- ) {
255
+ ): T => {
250
256
  out[0] = Math.max(a[0], b[0]);
251
257
  out[1] = Math.max(a[1], b[1]);
252
258
  out[2] = Math.max(a[2], b[2]);
253
259
  out[3] = Math.max(a[3], b[3]);
254
260
  return out;
255
- }
261
+ };
256
262
 
257
263
  /**
258
264
  * Scale a vector by a scalar.
@@ -261,17 +267,17 @@ export function max<T extends Vector4Like>(
261
267
  * @param out - The vector to store the result in.
262
268
  * @returns The product.
263
269
  */
264
- export function scale<T extends Vector4Like>(
270
+ export const scale = <T extends Vector4Like>(
265
271
  vector: Vector4Like,
266
272
  scalar: number,
267
273
  out: T
268
- ) {
274
+ ): T => {
269
275
  out[0] = vector[0] * scalar;
270
276
  out[1] = vector[1] * scalar;
271
277
  out[2] = vector[2] * scalar;
272
278
  out[3] = vector[3] * scalar;
273
279
  return out;
274
- }
280
+ };
275
281
 
276
282
  /**
277
283
  * Add two vectors after scaling the second by a scalar.
@@ -281,18 +287,18 @@ export function scale<T extends Vector4Like>(
281
287
  * @param out - The vector to store the result in.
282
288
  * @returns The sum.
283
289
  */
284
- export function scaleAndAdd<T extends Vector4Like>(
290
+ export const scaleAndAdd = <T extends Vector4Like>(
285
291
  a: Vector4Like,
286
292
  b: Vector4Like,
287
293
  scalar: number,
288
294
  out: T
289
- ) {
295
+ ): T => {
290
296
  out[0] = a[0] + b[0] * scalar;
291
297
  out[1] = a[1] + b[1] * scalar;
292
298
  out[2] = a[2] + b[2] * scalar;
293
299
  out[3] = a[3] + b[3] * scalar;
294
300
  return out;
295
- }
301
+ };
296
302
 
297
303
  /**
298
304
  * Calculate the Euclidean distance between two vectors.
@@ -301,13 +307,13 @@ export function scaleAndAdd<T extends Vector4Like>(
301
307
  * @returns The distance.
302
308
  * @see [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance)
303
309
  */
304
- export function distance(a: Vector4Like, b: Vector4Like) {
310
+ export const distance = (a: Vector4Like, b: Vector4Like): number => {
305
311
  const x = a[0] - b[0];
306
312
  const y = a[1] - b[1];
307
313
  const z = a[2] - b[2];
308
314
  const w = a[3] - b[3];
309
315
  return Math.hypot(x, y, z, w);
310
- }
316
+ };
311
317
 
312
318
  /**
313
319
  * Calculate the squared Euclidean distance between two vectors.
@@ -316,39 +322,39 @@ export function distance(a: Vector4Like, b: Vector4Like) {
316
322
  * @returns The squared distance.
317
323
  * @see [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance)
318
324
  */
319
- export function squaredDistance(a: Vector4Like, b: Vector4Like) {
325
+ export const squaredDistance = (a: Vector4Like, b: Vector4Like): number => {
320
326
  const x = a[0] - b[0];
321
327
  const y = a[1] - b[1];
322
328
  const z = a[2] - b[2];
323
329
  const w = a[3] - b[3];
324
330
  return x * x + y * y + z * z + w * w;
325
- }
331
+ };
326
332
 
327
333
  /**
328
334
  * Calculate the magnitude (length) of a vector.
329
335
  * @param vector - The vector.
330
336
  * @returns The magnitude.
331
337
  */
332
- export function getMagnitude(vector: Vector4Like) {
338
+ export const getMagnitude = (vector: Vector4Like): number => {
333
339
  const x = vector[0];
334
340
  const y = vector[1];
335
341
  const z = vector[2];
336
342
  const w = vector[3];
337
343
  return Math.hypot(x, y, z, w);
338
- }
344
+ };
339
345
 
340
346
  /**
341
347
  * Calculate the squared magnitude (length) of a vector.
342
348
  * @param vector - The vector.
343
349
  * @returns The magnitude.
344
350
  */
345
- export function getSquaredMagnitude(vector: Vector4Like) {
351
+ export const getSquaredMagnitude = (vector: Vector4Like): number => {
346
352
  const x = vector[0];
347
353
  const y = vector[1];
348
354
  const z = vector[2];
349
355
  const w = vector[3];
350
356
  return x * x + y * y + z * z + w * w;
351
- }
357
+ };
352
358
 
353
359
  /**
354
360
  * Negate a vector.
@@ -356,13 +362,16 @@ export function getSquaredMagnitude(vector: Vector4Like) {
356
362
  * @param out - The vector to store the result in.
357
363
  * @returns The negated vector.
358
364
  */
359
- export function negate<T extends Vector4Like>(vector: Vector4Like, out: T) {
365
+ export const negate = <T extends Vector4Like>(
366
+ vector: Vector4Like,
367
+ out: T
368
+ ): T => {
360
369
  out[0] = -vector[0];
361
370
  out[1] = -vector[1];
362
371
  out[2] = -vector[2];
363
372
  out[3] = -vector[3];
364
373
  return out;
365
- }
374
+ };
366
375
 
367
376
  /**
368
377
  * Calculate the multiplicative inverse of the components of a vector.
@@ -370,13 +379,16 @@ export function negate<T extends Vector4Like>(vector: Vector4Like, out: T) {
370
379
  * @param out - The vector to store the result in.
371
380
  * @returns The inverted vector.
372
381
  */
373
- export function invert<T extends Vector4Like>(vector: Vector4Like, out: T) {
382
+ export const invert = <T extends Vector4Like>(
383
+ vector: Vector4Like,
384
+ out: T
385
+ ): T => {
374
386
  out[0] = 1 / vector[0];
375
387
  out[1] = 1 / vector[1];
376
388
  out[2] = 1 / vector[2];
377
389
  out[3] = 1 / vector[3];
378
390
  return out;
379
- }
391
+ };
380
392
 
381
393
  /**
382
394
  * Normalize a vector.
@@ -385,7 +397,10 @@ export function invert<T extends Vector4Like>(vector: Vector4Like, out: T) {
385
397
  * @returns The normalized vector.
386
398
  * @see [Unit vector](https://en.wikipedia.org/wiki/Unit_vector)
387
399
  */
388
- export function normalize<T extends Vector4Like>(vector: Vector4Like, out: T) {
400
+ export const normalize = <T extends Vector4Like>(
401
+ vector: Vector4Like,
402
+ out: T
403
+ ): T => {
389
404
  const x = vector[0];
390
405
  const y = vector[1];
391
406
  const z = vector[2];
@@ -401,7 +416,7 @@ export function normalize<T extends Vector4Like>(vector: Vector4Like, out: T) {
401
416
  out[2] = z * len;
402
417
  out[3] = w * len;
403
418
  return out;
404
- }
419
+ };
405
420
 
406
421
  /**
407
422
  * Calculate the dot product of two vectors.
@@ -410,9 +425,9 @@ export function normalize<T extends Vector4Like>(vector: Vector4Like, out: T) {
410
425
  * @returns The dot product.
411
426
  * @see [Dot product](https://en.wikipedia.org/wiki/Dot_product)
412
427
  */
413
- export function dot(a: Vector4Like, b: Vector4Like) {
428
+ export const dot = (a: Vector4Like, b: Vector4Like): number => {
414
429
  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
415
- }
430
+ };
416
431
 
417
432
  /**
418
433
  * Calculate the cross product of three vectors in a four-dimensional space.
@@ -423,12 +438,12 @@ export function dot(a: Vector4Like, b: Vector4Like) {
423
438
  * @returns The cross product.
424
439
  * @see [Cross product](https://en.wikipedia.org/wiki/Cross_product)
425
440
  */
426
- export function cross<T extends Vector4Like>(
441
+ export const cross = <T extends Vector4Like>(
427
442
  a: Vector4Like,
428
443
  b: Vector4Like,
429
444
  c: Vector4Like,
430
445
  out: T
431
- ) {
446
+ ): T => {
432
447
  const d = b[0] * c[1] - b[1] * c[0];
433
448
  const e = b[0] * c[2] - b[2] * c[0];
434
449
  const f = b[0] * c[3] - b[3] * c[0];
@@ -446,7 +461,7 @@ export function cross<T extends Vector4Like>(
446
461
  out[2] = j * h - k * f + m * d;
447
462
  out[3] = -(j * g) + k * e - l * d;
448
463
  return out;
449
- }
464
+ };
450
465
 
451
466
  /**
452
467
  * Perform a linear interpolation between two vectors.
@@ -457,12 +472,12 @@ export function cross<T extends Vector4Like>(
457
472
  * @returns The interpolated vector.
458
473
  * @see [Linear interpolation](https://en.wikipedia.org/wiki/Linear_interpolation)
459
474
  */
460
- export function lerp<T extends Vector4Like>(
475
+ export const lerp = <T extends Vector4Like>(
461
476
  a: Vector4Like,
462
477
  b: Vector4Like,
463
478
  t: number,
464
479
  out: T
465
- ) {
480
+ ): T => {
466
481
  const ax = a[0];
467
482
  const ay = a[1];
468
483
  const az = a[2];
@@ -473,7 +488,7 @@ export function lerp<T extends Vector4Like>(
473
488
  out[2] = az + t * (b[2] - az);
474
489
  out[3] = aw + t * (b[3] - aw);
475
490
  return out;
476
- }
491
+ };
477
492
 
478
493
  /**
479
494
  * Set this vector to a random value with the given magnitude.
@@ -481,7 +496,7 @@ export function lerp<T extends Vector4Like>(
481
496
  * @param out - The vector to store the result in.
482
497
  * @returns This vector.
483
498
  */
484
- export function random<T extends Vector4Like>(magnitude: number, out: T) {
499
+ export const random = <T extends Vector4Like>(magnitude: number, out: T): T => {
485
500
  const a = Math.random();
486
501
  const v1 = a * 2 - 1;
487
502
  const v2 = (4 * Math.random() - 2) * Math.sqrt(a * -a + a);
@@ -499,7 +514,7 @@ export function random<T extends Vector4Like>(magnitude: number, out: T) {
499
514
  out[2] = magnitude * v3 * d;
500
515
  out[3] = magnitude * v4 * d;
501
516
  return out;
502
- }
517
+ };
503
518
 
504
519
  /**
505
520
  * Transform a vector by a four-by-four matrix.
@@ -509,11 +524,11 @@ export function random<T extends Vector4Like>(magnitude: number, out: T) {
509
524
  * @returns The transformed vector.
510
525
  * @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
511
526
  */
512
- export function transformMatrix4<T extends Vector4Like>(
527
+ export const transformMatrix4 = <T extends Vector4Like>(
513
528
  vector: Vector4Like,
514
529
  matrix: Matrix4Like,
515
530
  out: T
516
- ) {
531
+ ): T => {
517
532
  const x = vector[0];
518
533
  const y = vector[1];
519
534
  const z = vector[2];
@@ -524,20 +539,20 @@ export function transformMatrix4<T extends Vector4Like>(
524
539
  out[2] = matrix[2] * x + matrix[6] * y + matrix[10] * z + matrix[14] * w;
525
540
  out[3] = matrix[3] * x + matrix[7] * y + matrix[11] * z + matrix[15] * w;
526
541
  return out;
527
- }
542
+ };
528
543
 
529
544
  /**
530
545
  * Set a vector to the zero vector.
531
546
  * @param out - The vector to store the result in.
532
547
  * @returns This vector.
533
548
  */
534
- export function zero<T extends Vector4Like>(out: T) {
549
+ export const zero = <T extends Vector4Like>(out: T): T => {
535
550
  out[0] = 0;
536
551
  out[1] = 0;
537
552
  out[2] = 0;
538
553
  out[3] = 0;
539
554
  return out;
540
- }
555
+ };
541
556
 
542
557
  /**
543
558
  * Transform a vector by a quaternion.
@@ -547,11 +562,11 @@ export function zero<T extends Vector4Like>(out: T) {
547
562
  * @returns The transformed vector.
548
563
  * @see [Quaternion](https://en.wikipedia.org/wiki/Quaternion)
549
564
  */
550
- export function transformQuaternion<T extends Vector4Like>(
565
+ export const transformQuaternion = <T extends Vector4Like>(
551
566
  vector: Vector4Like,
552
567
  quaternion: QuaternionLike,
553
568
  out: T
554
- ) {
569
+ ): T => {
555
570
  const x = vector[0];
556
571
  const y = vector[1];
557
572
  const z = vector[2];
@@ -571,7 +586,7 @@ export function transformQuaternion<T extends Vector4Like>(
571
586
  out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
572
587
  out[3] = vector[3];
573
588
  return out;
574
- }
589
+ };
575
590
 
576
591
  /**
577
592
  * A quantity with magnitude and direction in four dimensions.
@@ -596,7 +611,7 @@ export default class Vector4
596
611
  z: number,
597
612
  w: number,
598
613
  out = new Vector4() as unknown as T
599
- ) {
614
+ ): T {
600
615
  return fromValues(x, y, z, w, out);
601
616
  }
602
617
 
@@ -625,7 +640,7 @@ export default class Vector4
625
640
  * @param vector - The other vector.
626
641
  * @returns Whether or no tthe vectors are equivalent.
627
642
  */
628
- public equals(vector: Vector4Like) {
643
+ public equals(vector: Vector4Like): boolean {
629
644
  return equals(this, vector);
630
645
  }
631
646
 
@@ -634,7 +649,7 @@ export default class Vector4
634
649
  * @param vector - The other vector.
635
650
  * @returns Whether the vectors are equivalent.
636
651
  */
637
- public exactEquals(vector: Vector4Like) {
652
+ public exactEquals(vector: Vector4Like): boolean {
638
653
  return exactEquals(this, vector);
639
654
  }
640
655
 
@@ -647,7 +662,7 @@ export default class Vector4
647
662
  public add<T extends Vector4Like>(
648
663
  vector: Vector4Like,
649
664
  out = new Vector4() as unknown as T
650
- ) {
665
+ ): T {
651
666
  return add(this, vector, out);
652
667
  }
653
668
 
@@ -656,7 +671,7 @@ export default class Vector4
656
671
  * @param out - The vector to store the result in.
657
672
  * @returns The copy.
658
673
  */
659
- public clone<T extends Vector4Like>(out = new Vector4() as unknown as T) {
674
+ public clone<T extends Vector4Like>(out = new Vector4() as unknown as T): T {
660
675
  return copy(this, out);
661
676
  }
662
677
 
@@ -665,7 +680,7 @@ export default class Vector4
665
680
  * @param vector - The vector to copy.
666
681
  * @returns This vector.
667
682
  */
668
- public copy(vector: Vector4Like) {
683
+ public copy(vector: Vector4Like): this {
669
684
  return copy(vector, this);
670
685
  }
671
686
 
@@ -678,7 +693,7 @@ export default class Vector4
678
693
  public multiply<T extends Vector4Like>(
679
694
  vector: Vector4Like,
680
695
  out = new Vector4() as unknown as T
681
- ) {
696
+ ): T {
682
697
  return multiply(this, vector, out);
683
698
  }
684
699
 
@@ -691,7 +706,7 @@ export default class Vector4
691
706
  public divide<T extends Vector4Like>(
692
707
  vector: Vector4Like,
693
708
  out = new Vector4() as unknown as T
694
- ) {
709
+ ): T {
695
710
  return divide(this, vector, out);
696
711
  }
697
712
 
@@ -704,7 +719,7 @@ export default class Vector4
704
719
  public subtract<T extends Vector4Like>(
705
720
  vector: Vector4Like,
706
721
  out = new Vector4() as unknown as T
707
- ) {
722
+ ): T {
708
723
  return subtract(this, vector, out);
709
724
  }
710
725
 
@@ -713,7 +728,7 @@ export default class Vector4
713
728
  * @param out - The vector to store the result in.
714
729
  * @returns The rounded vector.
715
730
  */
716
- public ceil<T extends Vector4Like>(out = new Vector4() as unknown as T) {
731
+ public ceil<T extends Vector4Like>(out = new Vector4() as unknown as T): T {
717
732
  return ceil(this, out);
718
733
  }
719
734
 
@@ -722,7 +737,7 @@ export default class Vector4
722
737
  * @param out - The vector to store the result in.
723
738
  * @returns The rounded vector.
724
739
  */
725
- public floor<T extends Vector4Like>(out = new Vector4() as unknown as T) {
740
+ public floor<T extends Vector4Like>(out = new Vector4() as unknown as T): T {
726
741
  return floor(this, out);
727
742
  }
728
743
 
@@ -731,7 +746,7 @@ export default class Vector4
731
746
  * @param out - The vector to store the result in.
732
747
  * @returns The rounded vector.
733
748
  */
734
- public round<T extends Vector4Like>(out = new Vector4() as unknown as T) {
749
+ public round<T extends Vector4Like>(out = new Vector4() as unknown as T): T {
735
750
  return round(this, out);
736
751
  }
737
752
 
@@ -744,7 +759,7 @@ export default class Vector4
744
759
  public min<T extends Vector4Like>(
745
760
  vector: Vector4Like,
746
761
  out = new Vector4() as unknown as T
747
- ) {
762
+ ): T {
748
763
  return min(this, vector, out);
749
764
  }
750
765
 
@@ -757,7 +772,7 @@ export default class Vector4
757
772
  public max<T extends Vector4Like>(
758
773
  vector: Vector4Like,
759
774
  out = new Vector4() as unknown as T
760
- ) {
775
+ ): T {
761
776
  return max(this, vector, out);
762
777
  }
763
778
 
@@ -770,7 +785,7 @@ export default class Vector4
770
785
  public scale<T extends Vector4Like>(
771
786
  scalar: number,
772
787
  out = new Vector4() as unknown as T
773
- ) {
788
+ ): T {
774
789
  return scale(this, scalar, out);
775
790
  }
776
791
 
@@ -785,7 +800,7 @@ export default class Vector4
785
800
  vector: Vector4Like,
786
801
  scalar: number,
787
802
  out = new Vector4() as unknown as T
788
- ) {
803
+ ): T {
789
804
  return scaleAndAdd(this, vector, scalar, out);
790
805
  }
791
806
 
@@ -795,7 +810,7 @@ export default class Vector4
795
810
  * @returns The distance.
796
811
  * @see [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance)
797
812
  */
798
- public distance(vector: Vector4Like) {
813
+ public distance(vector: Vector4Like): number {
799
814
  return distance(this, vector);
800
815
  }
801
816
 
@@ -805,17 +820,17 @@ export default class Vector4
805
820
  * @returns The squared distance.
806
821
  * @see [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance)
807
822
  */
808
- public squaredDistance(vector: Vector4Like) {
823
+ public squaredDistance(vector: Vector4Like): number {
809
824
  return squaredDistance(this, vector);
810
825
  }
811
826
 
812
827
  /** Get the magnitude (length) of this vector. */
813
- public get magnitude() {
828
+ public get magnitude(): number {
814
829
  return getMagnitude(this);
815
830
  }
816
831
 
817
832
  /** Get the squared magnitude (length) of this vector. */
818
- public get squaredMagnitude() {
833
+ public get squaredMagnitude(): number {
819
834
  return getSquaredMagnitude(this);
820
835
  }
821
836
 
@@ -824,7 +839,7 @@ export default class Vector4
824
839
  * @param out - The vector to store the result in.
825
840
  * @returns The negated vector.
826
841
  */
827
- public negate<T extends Vector4Like>(out = new Vector4() as unknown as T) {
842
+ public negate<T extends Vector4Like>(out = new Vector4() as unknown as T): T {
828
843
  return negate(this, out);
829
844
  }
830
845
 
@@ -833,7 +848,7 @@ export default class Vector4
833
848
  * @param out - The vector to store the result in.
834
849
  * @returns The inverted vector.
835
850
  */
836
- public invert<T extends Vector4Like>(out = new Vector4() as unknown as T) {
851
+ public invert<T extends Vector4Like>(out = new Vector4() as unknown as T): T {
837
852
  return invert(this, out);
838
853
  }
839
854
 
@@ -843,7 +858,9 @@ export default class Vector4
843
858
  * @returns The normalized vector.
844
859
  * @see [Unit vector](https://en.wikipedia.org/wiki/Unit_vector)
845
860
  */
846
- public normalize<T extends Vector4Like>(out = new Vector4() as unknown as T) {
861
+ public normalize<T extends Vector4Like>(
862
+ out = new Vector4() as unknown as T
863
+ ): T {
847
864
  return normalize(this, out);
848
865
  }
849
866
 
@@ -853,7 +870,7 @@ export default class Vector4
853
870
  * @returns The dot product.
854
871
  * @see [Dot product](https://en.wikipedia.org/wiki/Dot_product)
855
872
  */
856
- public dot(vector: Vector4Like) {
873
+ public dot(vector: Vector4Like): number {
857
874
  return dot(this, vector);
858
875
  }
859
876
 
@@ -869,7 +886,7 @@ export default class Vector4
869
886
  a: Vector4Like,
870
887
  b: Vector4Like,
871
888
  out = new Vector4() as unknown as T
872
- ) {
889
+ ): T {
873
890
  return cross(this, a, b, out);
874
891
  }
875
892
 
@@ -885,7 +902,7 @@ export default class Vector4
885
902
  vector: Vector4Like,
886
903
  t: number,
887
904
  out = new Vector4() as unknown as T
888
- ) {
905
+ ): T {
889
906
  return lerp(this, vector, t, out);
890
907
  }
891
908
 
@@ -894,7 +911,7 @@ export default class Vector4
894
911
  * @param magnitude - The magnitude.
895
912
  * @returns This vector.
896
913
  */
897
- public random(magnitude = 1) {
914
+ public random(magnitude = 1): this {
898
915
  return random(magnitude, this);
899
916
  }
900
917
 
@@ -908,7 +925,7 @@ export default class Vector4
908
925
  public transformMatrix4<T extends Vector4Like>(
909
926
  matrix: Matrix4Like,
910
927
  out = new Vector4() as unknown as T
911
- ) {
928
+ ): T {
912
929
  return transformMatrix4(this, matrix, out);
913
930
  }
914
931
 
@@ -916,7 +933,7 @@ export default class Vector4
916
933
  * Set this to the zero vector.
917
934
  * @returns This vector.
918
935
  */
919
- public zero() {
936
+ public zero(): this {
920
937
  return zero(this);
921
938
  }
922
939
 
@@ -930,7 +947,7 @@ export default class Vector4
930
947
  public transformQuaternion<T extends Vector4Like>(
931
948
  quaternion: QuaternionLike,
932
949
  out = new Vector4() as unknown as T
933
- ) {
950
+ ): T {
934
951
  return transformQuaternion(this, quaternion, out);
935
952
  }
936
953
  }