@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.
- package/LICENSE +1 -1
- package/README.md +7 -9
- package/dist/algorithms/combinations.d.ts +7 -0
- package/dist/algorithms/combinations.d.ts.map +1 -1
- package/dist/algorithms/combinations.js +8 -1
- package/dist/algorithms/combinations.js.map +1 -1
- package/dist/algorithms/degreesToRadians.d.ts +7 -0
- package/dist/algorithms/degreesToRadians.d.ts.map +1 -1
- package/dist/algorithms/degreesToRadians.js +7 -0
- package/dist/algorithms/degreesToRadians.js.map +1 -1
- package/dist/algorithms/factorial.d.ts +6 -0
- package/dist/algorithms/factorial.d.ts.map +1 -1
- package/dist/algorithms/factorial.js +15 -5
- package/dist/algorithms/factorial.js.map +1 -1
- package/dist/algorithms/fibonacci.d.ts +6 -1
- package/dist/algorithms/fibonacci.d.ts.map +1 -1
- package/dist/algorithms/fibonacci.js +6 -1
- package/dist/algorithms/fibonacci.js.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.d.ts +14 -0
- package/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.js +7 -9
- package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
- package/dist/algorithms/hypergeometricPmf.d.ts +9 -0
- package/dist/algorithms/hypergeometricPmf.d.ts.map +1 -1
- package/dist/algorithms/hypergeometricPmf.js +10 -1
- package/dist/algorithms/hypergeometricPmf.js.map +1 -1
- package/dist/algorithms/isPrime.d.ts +6 -0
- package/dist/algorithms/isPrime.d.ts.map +1 -1
- package/dist/algorithms/isPrime.js +8 -1
- package/dist/algorithms/isPrime.js.map +1 -1
- package/dist/algorithms/permutations.d.ts +7 -0
- package/dist/algorithms/permutations.d.ts.map +1 -1
- package/dist/algorithms/permutations.js +8 -1
- package/dist/algorithms/permutations.js.map +1 -1
- package/dist/algorithms/primeFactorization.d.ts +7 -1
- package/dist/algorithms/primeFactorization.d.ts.map +1 -1
- package/dist/algorithms/primeFactorization.js +10 -3
- package/dist/algorithms/primeFactorization.js.map +1 -1
- package/dist/algorithms/radiansToDegrees.d.ts +7 -0
- package/dist/algorithms/radiansToDegrees.d.ts.map +1 -1
- package/dist/algorithms/radiansToDegrees.js +7 -0
- package/dist/algorithms/radiansToDegrees.js.map +1 -1
- package/dist/algorithms/summation.d.ts +8 -0
- package/dist/algorithms/summation.d.ts.map +1 -1
- package/dist/algorithms/summation.js +9 -0
- package/dist/algorithms/summation.js.map +1 -1
- package/dist/index.d.ts +32 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -27
- package/dist/index.js.map +1 -1
- package/dist/linalg/DualQuaternion.d.ts +460 -83
- package/dist/linalg/DualQuaternion.d.ts.map +1 -1
- package/dist/linalg/DualQuaternion.js +514 -133
- package/dist/linalg/DualQuaternion.js.map +1 -1
- package/dist/linalg/Matrix.d.ts +80 -12
- package/dist/linalg/Matrix.d.ts.map +1 -1
- package/dist/linalg/Matrix2.d.ts +337 -52
- package/dist/linalg/Matrix2.d.ts.map +1 -1
- package/dist/linalg/Matrix2.js +345 -61
- package/dist/linalg/Matrix2.js.map +1 -1
- package/dist/linalg/Matrix3.d.ts +470 -72
- package/dist/linalg/Matrix3.d.ts.map +1 -1
- package/dist/linalg/Matrix3.js +488 -94
- package/dist/linalg/Matrix3.js.map +1 -1
- package/dist/linalg/Matrix4.d.ts +842 -137
- package/dist/linalg/Matrix4.d.ts.map +1 -1
- package/dist/linalg/Matrix4.js +896 -175
- package/dist/linalg/Matrix4.js.map +1 -1
- package/dist/linalg/Quaternion.d.ts +395 -70
- package/dist/linalg/Quaternion.d.ts.map +1 -1
- package/dist/linalg/Quaternion.js +416 -70
- package/dist/linalg/Quaternion.js.map +1 -1
- package/dist/linalg/SlowMatrix.d.ts +79 -9
- package/dist/linalg/SlowMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowMatrix.js +147 -27
- package/dist/linalg/SlowMatrix.js.map +1 -1
- package/dist/linalg/SlowSquareMatrix.d.ts +58 -3
- package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowSquareMatrix.js +111 -21
- package/dist/linalg/SlowSquareMatrix.js.map +1 -1
- package/dist/linalg/SquareMatrix.d.ts +26 -3
- package/dist/linalg/SquareMatrix.d.ts.map +1 -1
- package/dist/linalg/Vector.d.ts +148 -24
- package/dist/linalg/Vector.d.ts.map +1 -1
- package/dist/linalg/Vector2.d.ts +484 -84
- package/dist/linalg/Vector2.d.ts.map +1 -1
- package/dist/linalg/Vector2.js +487 -71
- package/dist/linalg/Vector2.js.map +1 -1
- package/dist/linalg/Vector3.d.ts +582 -98
- package/dist/linalg/Vector3.d.ts.map +1 -1
- package/dist/linalg/Vector3.js +625 -134
- package/dist/linalg/Vector3.js.map +1 -1
- package/dist/linalg/Vector4.d.ts +450 -75
- package/dist/linalg/Vector4.d.ts.map +1 -1
- package/dist/linalg/Vector4.js +447 -62
- package/dist/linalg/Vector4.js.map +1 -1
- package/dist/types/AxisAngle.d.ts +4 -1
- package/dist/types/AxisAngle.d.ts.map +1 -1
- package/dist/types/FieldOfView.d.ts +5 -0
- package/dist/types/FieldOfView.d.ts.map +1 -1
- package/dist/utility/BigNumber.d.ts +41 -8
- package/dist/utility/BigNumber.d.ts.map +1 -1
- package/dist/utility/BigNumber.js +47 -5
- package/dist/utility/BigNumber.js.map +1 -1
- package/dist/utility/MagnitudeError.d.ts +5 -0
- package/dist/utility/MagnitudeError.d.ts.map +1 -1
- package/dist/utility/MagnitudeError.js +6 -1
- package/dist/utility/MagnitudeError.js.map +1 -1
- package/dist/utility/MatrixSizeError.d.ts +5 -0
- package/dist/utility/MatrixSizeError.d.ts.map +1 -1
- package/dist/utility/MatrixSizeError.js +5 -0
- package/dist/utility/MatrixSizeError.js.map +1 -1
- package/dist/utility/PartialMatrixError.d.ts +5 -0
- package/dist/utility/PartialMatrixError.d.ts.map +1 -1
- package/dist/utility/PartialMatrixError.js +5 -0
- package/dist/utility/PartialMatrixError.js.map +1 -1
- package/dist/utility/SingularMatrixError.d.ts +8 -0
- package/dist/utility/SingularMatrixError.d.ts.map +1 -1
- package/dist/utility/SingularMatrixError.js +8 -0
- package/dist/utility/SingularMatrixError.js.map +1 -1
- package/dist/utility/epsilon.d.ts +1 -0
- package/dist/utility/epsilon.d.ts.map +1 -1
- package/dist/utility/epsilon.js +1 -0
- package/dist/utility/epsilon.js.map +1 -1
- package/package.json +20 -51
- package/src/algorithms/combinations.ts +4 -4
- package/src/algorithms/degreesToRadians.ts +3 -3
- package/src/algorithms/factorial.ts +13 -8
- package/src/algorithms/fibonacci.ts +3 -3
- package/src/algorithms/greatestCommonDivisor.ts +15 -19
- package/src/algorithms/hypergeometricPmf.ts +5 -6
- package/src/algorithms/isPrime.ts +4 -4
- package/src/algorithms/permutations.ts +4 -4
- package/src/algorithms/primeFactorization.ts +9 -9
- package/src/algorithms/radiansToDegrees.ts +3 -3
- package/src/algorithms/summation.ts +5 -5
- package/src/index.ts +35 -33
- package/src/linalg/DualQuaternion.ts +558 -804
- package/src/linalg/Matrix.ts +35 -36
- package/src/linalg/Matrix2.ts +277 -413
- package/src/linalg/Matrix3.ts +532 -737
- package/src/linalg/Matrix4.ts +1078 -1604
- package/src/linalg/Quaternion.ts +415 -690
- package/src/linalg/SlowMatrix.ts +118 -69
- package/src/linalg/SlowSquareMatrix.ts +85 -56
- package/src/linalg/SquareMatrix.ts +7 -7
- package/src/linalg/Vector.ts +71 -70
- package/src/linalg/Vector2.ts +380 -576
- package/src/linalg/Vector3.ts +544 -840
- package/src/linalg/Vector4.ts +383 -549
- package/src/types/AxisAngle.ts +1 -1
- package/src/utility/BigNumber.ts +33 -42
- package/src/utility/MagnitudeError.ts +4 -4
- package/src/utility/MatrixSizeError.ts +2 -3
- package/src/utility/PartialMatrixError.ts +2 -3
- package/src/utility/SingularMatrixError.ts +2 -2
- package/src/utility/epsilon.ts +1 -4
- package/dist/types/IntegerRepresentation.d.ts +0 -2
- package/dist/types/IntegerRepresentation.d.ts.map +0 -1
- package/dist/types/IntegerRepresentation.js +0 -2
- package/dist/types/IntegerRepresentation.js.map +0 -1
- package/src/types/IntegerRepresentation.ts +0 -2
package/src/linalg/Vector2.ts
CHANGED
|
@@ -1,341 +1,358 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
4
|
-
import type
|
|
5
|
-
import
|
|
6
|
-
import epsilon from "
|
|
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
|
|
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
|
-
*
|
|
18
|
+
* Create a 2x1 vector-like object.
|
|
13
19
|
* @returns A 2x1 vector-like object.
|
|
14
20
|
*/
|
|
15
|
-
export
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
43
|
-
const a0
|
|
44
|
-
const a1
|
|
48
|
+
export const equals = (a: Vector2Like, b: Vector2Like): boolean => {
|
|
49
|
+
const a0 = a[0];
|
|
50
|
+
const a1 = a[1];
|
|
45
51
|
|
|
46
|
-
const b0
|
|
47
|
-
const b1
|
|
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
|
-
*
|
|
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
|
|
62
|
-
return a[0]
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* @param
|
|
98
|
-
* @param
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
260
|
-
const x
|
|
261
|
-
const y
|
|
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
|
-
*
|
|
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
|
|
273
|
-
const x
|
|
274
|
-
const y
|
|
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
|
-
*
|
|
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
|
|
284
|
-
const x
|
|
285
|
-
const y
|
|
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
|
-
*
|
|
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
|
|
295
|
-
const x
|
|
296
|
-
const y
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
348
|
+
export const normalize = <T extends Vector2Like>(
|
|
332
349
|
vector: Vector2Like,
|
|
333
350
|
out: T
|
|
334
|
-
): T {
|
|
335
|
-
const x
|
|
336
|
-
const y
|
|
351
|
+
): T => {
|
|
352
|
+
const x = vector[0];
|
|
353
|
+
const y = vector[1];
|
|
337
354
|
|
|
338
|
-
let len
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
384
|
+
export const cross = <T extends Vector3Like>(
|
|
368
385
|
a: Vector2Like,
|
|
369
386
|
b: Vector2Like,
|
|
370
387
|
out: T
|
|
371
|
-
): T {
|
|
372
|
-
const z
|
|
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
|
-
*
|
|
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
|
|
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
|
|
395
|
-
const ay
|
|
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
|
-
*
|
|
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
|
|
409
|
-
const r
|
|
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
|
-
*
|
|
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
|
|
441
|
+
export const transformMatrix2 = <T extends Vector2Like>(
|
|
425
442
|
vector: Vector2Like,
|
|
426
443
|
matrix: Matrix2Like,
|
|
427
444
|
out: T
|
|
428
|
-
): T {
|
|
429
|
-
const x
|
|
430
|
-
const y
|
|
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
|
-
*
|
|
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
|
|
462
|
+
export const transformMatrix3 = <T extends Vector2Like>(
|
|
446
463
|
vector: Vector2Like,
|
|
447
464
|
matrix: Matrix3Like,
|
|
448
465
|
out: T
|
|
449
|
-
): T {
|
|
450
|
-
const x
|
|
451
|
-
const y
|
|
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
|
-
*
|
|
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
|
|
483
|
+
export const transformMatrix4 = <T extends Vector2Like>(
|
|
467
484
|
vector: Vector2Like,
|
|
468
485
|
matrix: Matrix4Like,
|
|
469
486
|
out: T
|
|
470
|
-
): T {
|
|
471
|
-
const x
|
|
472
|
-
const y
|
|
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
|
-
*
|
|
481
|
-
* @param vector The vector.
|
|
482
|
-
* @param origin The origin of the rotation.
|
|
483
|
-
* @param
|
|
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
|
|
504
|
+
export const rotate = <T extends Vector2Like>(
|
|
488
505
|
vector: Vector2Like,
|
|
489
506
|
origin: Vector2Like,
|
|
490
|
-
|
|
507
|
+
r: number,
|
|
491
508
|
out: T
|
|
492
|
-
): T {
|
|
493
|
-
const o0
|
|
494
|
-
const o1
|
|
509
|
+
): T => {
|
|
510
|
+
const o0 = origin[0];
|
|
511
|
+
const o1 = origin[1];
|
|
495
512
|
|
|
496
|
-
const p0
|
|
497
|
-
const p1
|
|
513
|
+
const p0 = vector[0] - o0;
|
|
514
|
+
const p1 = vector[1] - o1;
|
|
498
515
|
|
|
499
|
-
const s
|
|
500
|
-
const c
|
|
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
|
-
*
|
|
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
|
|
514
|
-
const x1
|
|
515
|
-
const y1
|
|
530
|
+
export const angle = (a: Vector2Like, b: Vector2Like): number => {
|
|
531
|
+
const x1 = a[0];
|
|
532
|
+
const y1 = a[1];
|
|
516
533
|
|
|
517
|
-
const x2
|
|
518
|
-
const y2
|
|
534
|
+
const x2 = b[0];
|
|
535
|
+
const y2 = b[1];
|
|
519
536
|
|
|
520
|
-
const magnitudeProduct
|
|
537
|
+
const magnitudeProduct =
|
|
521
538
|
Math.sqrt(x1 * x1 + y1 * y1) * Math.sqrt(x2 * x2 + y2 * y2);
|
|
522
|
-
const c
|
|
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
|
-
*
|
|
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
|
|
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
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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():
|
|
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
|
-
*
|
|
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
|
-
*
|
|
647
|
-
*
|
|
648
|
-
* @param
|
|
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
|
|
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
|
-
*
|
|
671
|
-
* @param vector The other vector.
|
|
672
|
-
* @
|
|
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
|
|
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
|
-
*
|
|
693
|
-
* @param vector The other vector.
|
|
694
|
-
* @
|
|
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
|
|
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
|
-
*
|
|
715
|
-
* @
|
|
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
|
|
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
|
-
*
|
|
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():
|
|
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
|
-
*
|
|
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():
|
|
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
|
-
*
|
|
766
|
-
* @param vector The other vector.
|
|
767
|
-
* @
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
/**
|
|
780
|
+
/** Get the magnitude (length) of this vector. */
|
|
880
781
|
public get magnitude(): number {
|
|
881
782
|
return getMagnitude(this);
|
|
882
783
|
}
|
|
883
784
|
|
|
884
|
-
/**
|
|
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
|
-
*
|
|
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():
|
|
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
|
-
*
|
|
908
|
-
* @
|
|
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
|
|
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
|
-
*
|
|
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(
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
978
|
-
* @param vector The other vector.
|
|
979
|
-
* @param t The interpolation amount (in `[0,1]`).
|
|
980
|
-
* @
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
1014
|
-
* @param matrix The matrix.
|
|
1015
|
-
* @
|
|
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
|
|
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
|
-
*
|
|
1041
|
-
* @param matrix The matrix.
|
|
1042
|
-
* @
|
|
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
|
|
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
|
-
*
|
|
1068
|
-
* @param matrix The matrix.
|
|
1069
|
-
* @
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
936
|
+
* Set this to the zero vector.
|
|
1133
937
|
* @returns This vector.
|
|
1134
938
|
*/
|
|
1135
939
|
public zero(): this {
|