@lakuna/umath 1.3.4 → 1.3.6

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