@lakuna/umath 0.0.8 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/linear/DualQuaternion.d.ts.map +1 -1
- package/dist/linear/DualQuaternion.js +1 -1
- package/dist/linear/DualQuaternion.js.map +1 -1
- package/dist/linear/Matrix.d.ts +4 -5
- package/dist/linear/Matrix.d.ts.map +1 -1
- package/dist/linear/Quaternion.d.ts +2 -2
- package/dist/linear/Quaternion.d.ts.map +1 -1
- package/dist/linear/Quaternion.js +7 -6
- package/dist/linear/Quaternion.js.map +1 -1
- package/dist/linear/SlowMatrix.d.ts +18 -0
- package/dist/linear/SlowMatrix.d.ts.map +1 -0
- package/dist/linear/SlowMatrix.js +126 -0
- package/dist/linear/SlowMatrix.js.map +1 -0
- package/dist/linear/SlowSquareMatrix.d.ts +15 -0
- package/dist/linear/SlowSquareMatrix.d.ts.map +1 -0
- package/dist/linear/SlowSquareMatrix.js +118 -0
- package/dist/linear/SlowSquareMatrix.js.map +1 -0
- package/dist/linear/SquareMatrix.d.ts +1 -0
- package/dist/linear/SquareMatrix.d.ts.map +1 -1
- package/dist/linear/Vector.d.ts +1 -1
- package/dist/linear/Vector.d.ts.map +1 -1
- package/dist/linear/Vector2.d.ts +3 -3
- package/dist/linear/Vector2.d.ts.map +1 -1
- package/dist/linear/Vector2.js +5 -4
- package/dist/linear/Vector2.js.map +1 -1
- package/dist/linear/Vector3.d.ts +3 -3
- package/dist/linear/Vector3.d.ts.map +1 -1
- package/dist/linear/Vector3.js +3 -3
- package/dist/linear/Vector3.js.map +1 -1
- package/dist/linear/Vector4.d.ts +3 -3
- package/dist/linear/Vector4.d.ts.map +1 -1
- package/dist/linear/Vector4.js +14 -14
- package/dist/linear/Vector4.js.map +1 -1
- package/dist/types/AxisAngle.d.ts.map +1 -1
- package/dist/utility/MagnitudeError.d.ts.map +1 -1
- package/dist/utility/MagnitudeError.js +1 -0
- package/dist/utility/MagnitudeError.js.map +1 -1
- package/dist/utility/MatrixSizeError.d.ts +4 -0
- package/dist/utility/MatrixSizeError.d.ts.map +1 -0
- package/dist/utility/MatrixSizeError.js +7 -0
- package/dist/utility/MatrixSizeError.js.map +1 -0
- package/dist/utility/PartialMatrixError.d.ts +4 -0
- package/dist/utility/PartialMatrixError.d.ts.map +1 -0
- package/dist/utility/PartialMatrixError.js +7 -0
- package/dist/utility/PartialMatrixError.js.map +1 -0
- package/dist/utility/SingularMatrixError.d.ts.map +1 -1
- package/dist/utility/SingularMatrixError.js.map +1 -1
- package/package.json +3 -1
- package/src/index.ts +4 -0
- package/src/linear/DualQuaternion.ts +942 -942
- package/src/linear/Matrix.ts +17 -24
- package/src/linear/Quaternion.ts +766 -763
- package/src/linear/SlowMatrix.ts +228 -0
- package/src/linear/SlowSquareMatrix.ts +203 -0
- package/src/linear/SquareMatrix.ts +7 -0
- package/src/linear/Vector.ts +1 -1
- package/src/linear/Vector2.ts +13 -12
- package/src/linear/Vector3.ts +605 -605
- package/src/linear/Vector4.ts +689 -689
- package/src/types/AxisAngle.ts +4 -4
- package/src/utility/MagnitudeError.ts +8 -7
- package/src/utility/MatrixSizeError.ts +11 -0
- package/src/utility/PartialMatrixError.ts +11 -0
- package/src/utility/SingularMatrixError.ts +7 -7
package/src/linear/Vector3.ts
CHANGED
|
@@ -17,10 +17,10 @@ export type Vector3Like = Vector3 | [number, number, number];
|
|
|
17
17
|
* @returns A new vector.
|
|
18
18
|
*/
|
|
19
19
|
export function fromValues<T extends Vector3Like>(x: number, y: number, z: number, out: T): T {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
out[0] = x;
|
|
21
|
+
out[1] = y;
|
|
22
|
+
out[2] = z;
|
|
23
|
+
return out;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -30,17 +30,17 @@ export function fromValues<T extends Vector3Like>(x: number, y: number, z: numbe
|
|
|
30
30
|
* @returns Whether the vectors are equivalent.
|
|
31
31
|
*/
|
|
32
32
|
export function equals(a: Vector3Like, b: Vector3Like): boolean {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
const a0: number = a[0];
|
|
34
|
+
const a1: number = a[1];
|
|
35
|
+
const a2: number = a[2];
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const b0: number = b[0];
|
|
38
|
+
const b1: number = b[1];
|
|
39
|
+
const b2: number = b[2];
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
return Math.abs(a0 - b0) <= epsilon * Math.max(1, Math.abs(a0), Math.abs(b0))
|
|
42
|
+
&& Math.abs(a1 - b1) <= epsilon * Math.max(1, Math.abs(a1), Math.abs(b1))
|
|
43
|
+
&& Math.abs(a2 - b2) <= epsilon * Math.max(1, Math.abs(a2), Math.abs(b2));
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
@@ -50,9 +50,9 @@ export function equals(a: Vector3Like, b: Vector3Like): boolean {
|
|
|
50
50
|
* @returns Whether the vectors are equivalent.
|
|
51
51
|
*/
|
|
52
52
|
export function exactEquals(a: Vector3Like, b: Vector3Like): boolean {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
return a[0] == b[0]
|
|
54
|
+
&& a[1] == b[1]
|
|
55
|
+
&& a[2] == b[2];
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
@@ -63,10 +63,10 @@ export function exactEquals(a: Vector3Like, b: Vector3Like): boolean {
|
|
|
63
63
|
* @returns The sum.
|
|
64
64
|
*/
|
|
65
65
|
export function add<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out: T): T {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
out[0] = a[0] + b[0];
|
|
67
|
+
out[1] = a[1] + b[1];
|
|
68
|
+
out[2] = a[2] + b[2];
|
|
69
|
+
return out;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
@@ -76,10 +76,10 @@ export function add<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out:
|
|
|
76
76
|
* @returns The copy.
|
|
77
77
|
*/
|
|
78
78
|
export function copy<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
out[0] = vector[0];
|
|
80
|
+
out[1] = vector[1];
|
|
81
|
+
out[2] = vector[2];
|
|
82
|
+
return out;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
/**
|
|
@@ -90,10 +90,10 @@ export function copy<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
|
90
90
|
* @returns The product.
|
|
91
91
|
*/
|
|
92
92
|
export function multiply<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out: T): T {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
out[0] = a[0] * b[0];
|
|
94
|
+
out[1] = a[1] * b[1];
|
|
95
|
+
out[2] = a[2] * b[2];
|
|
96
|
+
return out;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
/**
|
|
@@ -104,10 +104,10 @@ export function multiply<T extends Vector3Like>(a: Vector3Like, b: Vector3Like,
|
|
|
104
104
|
* @returns The quotient.
|
|
105
105
|
*/
|
|
106
106
|
export function divide<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out: T): T {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
out[0] = a[0] / b[0];
|
|
108
|
+
out[1] = a[1] / b[1];
|
|
109
|
+
out[2] = a[2] / b[2];
|
|
110
|
+
return out;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/**
|
|
@@ -118,10 +118,10 @@ export function divide<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, ou
|
|
|
118
118
|
* @returns The difference.
|
|
119
119
|
*/
|
|
120
120
|
export function subtract<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out: T): T {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
out[0] = a[0] - b[0];
|
|
122
|
+
out[1] = a[1] - b[1];
|
|
123
|
+
out[2] = a[2] - b[2];
|
|
124
|
+
return out;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
/**
|
|
@@ -131,10 +131,10 @@ export function subtract<T extends Vector3Like>(a: Vector3Like, b: Vector3Like,
|
|
|
131
131
|
* @returns The rounded vector.
|
|
132
132
|
*/
|
|
133
133
|
export function ceil<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
out[0] = Math.ceil(vector[0]);
|
|
135
|
+
out[1] = Math.ceil(vector[1]);
|
|
136
|
+
out[2] = Math.ceil(vector[2]);
|
|
137
|
+
return out;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
/**
|
|
@@ -144,10 +144,10 @@ export function ceil<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
|
144
144
|
* @returns The rounded vector.
|
|
145
145
|
*/
|
|
146
146
|
export function floor<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
out[0] = Math.floor(vector[0]);
|
|
148
|
+
out[1] = Math.floor(vector[1]);
|
|
149
|
+
out[2] = Math.floor(vector[2]);
|
|
150
|
+
return out;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
/**
|
|
@@ -157,10 +157,10 @@ export function floor<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
|
157
157
|
* @returns The rounded vector.
|
|
158
158
|
*/
|
|
159
159
|
export function round<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
160
|
+
out[0] = Math.round(vector[0]);
|
|
161
|
+
out[1] = Math.round(vector[1]);
|
|
162
|
+
out[2] = Math.round(vector[2]);
|
|
163
|
+
return out;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
/**
|
|
@@ -171,10 +171,10 @@ export function round<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
|
171
171
|
* @returns The minimum.
|
|
172
172
|
*/
|
|
173
173
|
export function min<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out: T): T {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
174
|
+
out[0] = Math.min(a[0], b[0]);
|
|
175
|
+
out[1] = Math.min(a[1], b[1]);
|
|
176
|
+
out[2] = Math.min(a[2], b[2]);
|
|
177
|
+
return out;
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
/**
|
|
@@ -185,10 +185,10 @@ export function min<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out:
|
|
|
185
185
|
* @returns The maximum.
|
|
186
186
|
*/
|
|
187
187
|
export function max<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out: T): T {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
188
|
+
out[0] = Math.max(a[0], b[0]);
|
|
189
|
+
out[1] = Math.max(a[1], b[1]);
|
|
190
|
+
out[2] = Math.max(a[2], b[2]);
|
|
191
|
+
return out;
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
/**
|
|
@@ -199,10 +199,10 @@ export function max<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out:
|
|
|
199
199
|
* @returns The product.
|
|
200
200
|
*/
|
|
201
201
|
export function scale<T extends Vector3Like>(vector: Vector3Like, scalar: number, out: T): T {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
202
|
+
out[0] = vector[0] * scalar;
|
|
203
|
+
out[1] = vector[1] * scalar;
|
|
204
|
+
out[2] = vector[2] * scalar;
|
|
205
|
+
return out;
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
/**
|
|
@@ -214,10 +214,10 @@ export function scale<T extends Vector3Like>(vector: Vector3Like, scalar: number
|
|
|
214
214
|
* @returns The sum.
|
|
215
215
|
*/
|
|
216
216
|
export function scaleAndAdd<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, scalar: number, out: T): T {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
217
|
+
out[0] = a[0] + b[0] * scalar;
|
|
218
|
+
out[1] = a[1] + b[1] * scalar;
|
|
219
|
+
out[2] = a[2] + b[2] * scalar;
|
|
220
|
+
return out;
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
/**
|
|
@@ -228,10 +228,10 @@ export function scaleAndAdd<T extends Vector3Like>(a: Vector3Like, b: Vector3Lik
|
|
|
228
228
|
* @see [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance)
|
|
229
229
|
*/
|
|
230
230
|
export function distance(a: Vector3Like, b: Vector3Like): number {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
231
|
+
const x: number = b[0] - a[0];
|
|
232
|
+
const y: number = b[1] - a[1];
|
|
233
|
+
const z: number = b[2] - a[2];
|
|
234
|
+
return Math.hypot(x, y, z);
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
/**
|
|
@@ -242,10 +242,10 @@ export function distance(a: Vector3Like, b: Vector3Like): number {
|
|
|
242
242
|
* @see [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance)
|
|
243
243
|
*/
|
|
244
244
|
export function squaredDistance(a: Vector3Like, b: Vector3Like): number {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
245
|
+
const x: number = b[0] - a[0];
|
|
246
|
+
const y: number = b[1] - a[1];
|
|
247
|
+
const z: number = b[2] - a[2];
|
|
248
|
+
return x * x + y * y + z * z;
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
/**
|
|
@@ -254,10 +254,10 @@ export function squaredDistance(a: Vector3Like, b: Vector3Like): number {
|
|
|
254
254
|
* @returns The magnitude.
|
|
255
255
|
*/
|
|
256
256
|
export function getMagnitude(vector: Vector3Like): number {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
257
|
+
const x: number = vector[0];
|
|
258
|
+
const y: number = vector[1];
|
|
259
|
+
const z: number = vector[2];
|
|
260
|
+
return Math.hypot(x, y, z);
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
/**
|
|
@@ -266,10 +266,10 @@ export function getMagnitude(vector: Vector3Like): number {
|
|
|
266
266
|
* @returns The squared magnitude.
|
|
267
267
|
*/
|
|
268
268
|
export function getSquaredMagnitude(vector: Vector3Like): number {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
269
|
+
const x: number = vector[0];
|
|
270
|
+
const y: number = vector[1];
|
|
271
|
+
const z: number = vector[2];
|
|
272
|
+
return x * x + y * y + z * z;
|
|
273
273
|
}
|
|
274
274
|
|
|
275
275
|
/**
|
|
@@ -279,10 +279,10 @@ export function getSquaredMagnitude(vector: Vector3Like): number {
|
|
|
279
279
|
* @returns The negated vector.
|
|
280
280
|
*/
|
|
281
281
|
export function negate<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
282
|
+
out[0] = -vector[0];
|
|
283
|
+
out[1] = -vector[1];
|
|
284
|
+
out[2] = -vector[2];
|
|
285
|
+
return out;
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
/**
|
|
@@ -291,11 +291,11 @@ export function negate<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
|
291
291
|
* @param out The vector to store the result in.
|
|
292
292
|
* @returns The inverted vector.
|
|
293
293
|
*/
|
|
294
|
-
export function
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
294
|
+
export function invert<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
295
|
+
out[0] = 1 / vector[0];
|
|
296
|
+
out[1] = 1 / vector[1];
|
|
297
|
+
out[2] = 1 / vector[2];
|
|
298
|
+
return out;
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
/**
|
|
@@ -306,19 +306,19 @@ export function inverse<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
|
306
306
|
* @see [Unit vector](https://en.wikipedia.org/wiki/Unit_vector)
|
|
307
307
|
*/
|
|
308
308
|
export function normalize<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
309
|
+
const x: number = vector[0];
|
|
310
|
+
const y: number = vector[1];
|
|
311
|
+
const z: number = vector[2];
|
|
312
|
+
|
|
313
|
+
let len: number = x * x + y * y + z * z;
|
|
314
|
+
if (len > 0) {
|
|
315
|
+
len = 1 / Math.sqrt(len);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
out[0] = x * len;
|
|
319
|
+
out[1] = y * len;
|
|
320
|
+
out[2] = z * len;
|
|
321
|
+
return out;
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
/**
|
|
@@ -329,7 +329,7 @@ export function normalize<T extends Vector3Like>(vector: Vector3Like, out: T): T
|
|
|
329
329
|
* @see [Dot product](https://en.wikipedia.org/wiki/Dot_product)
|
|
330
330
|
*/
|
|
331
331
|
export function dot(a: Vector3Like, b: Vector3Like): number {
|
|
332
|
-
|
|
332
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
333
333
|
}
|
|
334
334
|
|
|
335
335
|
/**
|
|
@@ -341,18 +341,18 @@ export function dot(a: Vector3Like, b: Vector3Like): number {
|
|
|
341
341
|
* @see [Cross product](https://en.wikipedia.org/wiki/Cross_product)
|
|
342
342
|
*/
|
|
343
343
|
export function cross<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out: T): T {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
344
|
+
const ax: number = a[0];
|
|
345
|
+
const ay: number = a[1];
|
|
346
|
+
const az: number = a[2];
|
|
347
|
+
|
|
348
|
+
const bx: number = b[0];
|
|
349
|
+
const by: number = b[1];
|
|
350
|
+
const bz: number = b[2];
|
|
351
|
+
|
|
352
|
+
out[0] = ay * bz - az * by;
|
|
353
|
+
out[1] = az * bx - ax * bz;
|
|
354
|
+
out[2] = ax * by - ay * bx;
|
|
355
|
+
return out;
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
/**
|
|
@@ -365,14 +365,14 @@ export function cross<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out
|
|
|
365
365
|
* @see [Linear interpolation](https://en.wikipedia.org/wiki/Linear_interpolation)
|
|
366
366
|
*/
|
|
367
367
|
export function lerp<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, t: number, out: T): T {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
368
|
+
const ax: number = a[0];
|
|
369
|
+
const ay: number = a[1];
|
|
370
|
+
const az: number = a[2];
|
|
371
|
+
|
|
372
|
+
out[0] = ax + t * (b[0] - ax);
|
|
373
|
+
out[1] = ay + t * (b[1] - ay);
|
|
374
|
+
out[2] = az + t * (b[2] - az);
|
|
375
|
+
return out;
|
|
376
376
|
}
|
|
377
377
|
|
|
378
378
|
/**
|
|
@@ -382,54 +382,54 @@ export function lerp<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, t: n
|
|
|
382
382
|
* @returns This vector.
|
|
383
383
|
*/
|
|
384
384
|
export function random<T extends Vector3Like>(magnitude: number, out: T): T {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
385
|
+
const r: number = Math.random() * 2 * Math.PI;
|
|
386
|
+
const z: number = Math.random() * 2 - 1;
|
|
387
|
+
const zScale: number = Math.sqrt(1 - z * z) * magnitude;
|
|
388
|
+
|
|
389
|
+
out[0] = Math.cos(r) * zScale;
|
|
390
|
+
out[1] = Math.sin(r) * zScale;
|
|
391
|
+
out[2] = z * magnitude;
|
|
392
|
+
return out;
|
|
393
393
|
}
|
|
394
394
|
|
|
395
395
|
/**
|
|
396
396
|
* Transforms a vector by a three-by-three matrix.
|
|
397
|
-
* @param vector The vector.
|
|
398
|
-
* @param matrix The matrix.
|
|
397
|
+
* @param vector The vector (multiplier).
|
|
398
|
+
* @param matrix The matrix (multiplicand).
|
|
399
399
|
* @param out The vector to store the result in.
|
|
400
400
|
* @returns The transformed vector.
|
|
401
401
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
402
402
|
*/
|
|
403
403
|
export function transformMatrix3<T extends Vector3Like>(vector: Vector3Like, matrix: Matrix3Like, out: T): T {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
404
|
+
const x: number = vector[0];
|
|
405
|
+
const y: number = vector[1];
|
|
406
|
+
const z: number = vector[2];
|
|
407
|
+
|
|
408
|
+
out[0] = x * matrix[0] + y * matrix[3] + z * matrix[6];
|
|
409
|
+
out[1] = x * matrix[1] + y * matrix[4] + z * matrix[7];
|
|
410
|
+
out[2] = x * matrix[2] + y * matrix[5] + z * matrix[8];
|
|
411
|
+
return out;
|
|
412
412
|
}
|
|
413
413
|
|
|
414
414
|
/**
|
|
415
415
|
* Transforms a vector by a four-by-four matrix.
|
|
416
|
-
* @param vector The vector.
|
|
417
|
-
* @param matrix The matrix.
|
|
416
|
+
* @param vector The vector (multiplier).
|
|
417
|
+
* @param matrix The matrix (multiplicand).
|
|
418
418
|
* @param out The vector to store the result in.
|
|
419
419
|
* @returns The transformed vector.
|
|
420
420
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
421
421
|
*/
|
|
422
422
|
export function transformMatrix4<T extends Vector3Like>(vector: Vector3Like, matrix: Matrix4Like, out: T): T {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
423
|
+
const x: number = vector[0];
|
|
424
|
+
const y: number = vector[1];
|
|
425
|
+
const z: number = vector[2];
|
|
426
426
|
|
|
427
|
-
|
|
427
|
+
const w: number = matrix[3] * x + matrix[7] * y + matrix[11] * z + matrix[15] || 1;
|
|
428
428
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
429
|
+
out[0] = (matrix[0] * x + matrix[4] * y + matrix[8] * z + matrix[12]) / w;
|
|
430
|
+
out[1] = (matrix[1] * x + matrix[5] * y + matrix[9] * z + matrix[13]) / w;
|
|
431
|
+
out[2] = (matrix[2] * x + matrix[6] * y + matrix[10] * z + matrix[14]) / w;
|
|
432
|
+
return out;
|
|
433
433
|
}
|
|
434
434
|
|
|
435
435
|
/**
|
|
@@ -441,20 +441,20 @@ export function transformMatrix4<T extends Vector3Like>(vector: Vector3Like, mat
|
|
|
441
441
|
* @returns The rotated vector.
|
|
442
442
|
*/
|
|
443
443
|
export function rotateX<T extends Vector3Like>(vector: Vector3Like, origin: Vector3Like, radians: number, out: T): T {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
444
|
+
const p: Vector3Like = [
|
|
445
|
+
vector[0] - origin[0],
|
|
446
|
+
vector[1] - origin[1],
|
|
447
|
+
vector[2] - origin[2]];
|
|
448
|
+
|
|
449
|
+
const r: Vector3Like = [
|
|
450
|
+
p[0],
|
|
451
|
+
p[1] * Math.cos(radians) - p[2] * Math.sin(radians),
|
|
452
|
+
p[1] * Math.sin(radians) + p[2] * Math.cos(radians)];
|
|
453
|
+
|
|
454
|
+
out[0] = r[0] + origin[0];
|
|
455
|
+
out[1] = r[1] + origin[1];
|
|
456
|
+
out[2] = r[2] + origin[2];
|
|
457
|
+
return out;
|
|
458
458
|
}
|
|
459
459
|
|
|
460
460
|
/**
|
|
@@ -466,20 +466,20 @@ export function rotateX<T extends Vector3Like>(vector: Vector3Like, origin: Vect
|
|
|
466
466
|
* @returns The rotated vector.
|
|
467
467
|
*/
|
|
468
468
|
export function rotateY<T extends Vector3Like>(vector: Vector3Like, origin: Vector3Like, radians: number, out: T): T {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
469
|
+
const p: Vector3Like = [
|
|
470
|
+
vector[0] - origin[0],
|
|
471
|
+
vector[1] - origin[1],
|
|
472
|
+
vector[2] - origin[2]];
|
|
473
|
+
|
|
474
|
+
const r: Vector3Like = [
|
|
475
|
+
p[2] * Math.sin(radians) + p[0] * Math.cos(radians),
|
|
476
|
+
p[1],
|
|
477
|
+
p[2] * Math.cos(radians) - p[0] * Math.sin(radians)];
|
|
478
|
+
|
|
479
|
+
out[0] = r[0] + origin[0];
|
|
480
|
+
out[1] = r[1] + origin[1];
|
|
481
|
+
out[2] = r[2] + origin[2];
|
|
482
|
+
return out;
|
|
483
483
|
}
|
|
484
484
|
|
|
485
485
|
/**
|
|
@@ -491,20 +491,20 @@ export function rotateY<T extends Vector3Like>(vector: Vector3Like, origin: Vect
|
|
|
491
491
|
* @returns The rotated vector.
|
|
492
492
|
*/
|
|
493
493
|
export function rotateZ<T extends Vector3Like>(vector: Vector3Like, origin: Vector3Like, radians: number, out: T): T {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
494
|
+
const p: Vector3Like = [
|
|
495
|
+
vector[0] - origin[0],
|
|
496
|
+
vector[1] - origin[1],
|
|
497
|
+
vector[2] - origin[2]];
|
|
498
|
+
|
|
499
|
+
const r: Vector3Like = [
|
|
500
|
+
p[0] * Math.cos(radians) - p[1] * Math.sin(radians),
|
|
501
|
+
p[0] * Math.sin(radians) + p[1] * Math.cos(radians),
|
|
502
|
+
p[2]];
|
|
503
|
+
|
|
504
|
+
out[0] = r[0] + origin[0];
|
|
505
|
+
out[1] = r[1] + origin[1];
|
|
506
|
+
out[2] = r[2] + origin[2];
|
|
507
|
+
return out;
|
|
508
508
|
}
|
|
509
509
|
|
|
510
510
|
/**
|
|
@@ -514,22 +514,22 @@ export function rotateZ<T extends Vector3Like>(vector: Vector3Like, origin: Vect
|
|
|
514
514
|
* @returns The angular distance from the first vector to the second.
|
|
515
515
|
*/
|
|
516
516
|
export function angle(a: Vector3Like, b: Vector3Like): number {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
517
|
+
const ax: number = a[0];
|
|
518
|
+
const ay: number = a[1];
|
|
519
|
+
const az: number = a[2];
|
|
520
520
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
521
|
+
const bx: number = b[0];
|
|
522
|
+
const by: number = b[1];
|
|
523
|
+
const bz: number = b[2];
|
|
524
524
|
|
|
525
|
-
|
|
526
|
-
|
|
525
|
+
const mag1: number = Math.sqrt(ax * ax + ay * ay + az * az);
|
|
526
|
+
const mag2: number = Math.sqrt(bx * bx + by * by + bz * bz);
|
|
527
527
|
|
|
528
|
-
|
|
528
|
+
const mag: number = mag1 * mag2;
|
|
529
529
|
|
|
530
|
-
|
|
530
|
+
const cosine: number = mag && dot(a, b) / mag;
|
|
531
531
|
|
|
532
|
-
|
|
532
|
+
return Math.acos(Math.min(Math.max(cosine, -1), 1));
|
|
533
533
|
}
|
|
534
534
|
|
|
535
535
|
/**
|
|
@@ -538,10 +538,10 @@ export function angle(a: Vector3Like, b: Vector3Like): number {
|
|
|
538
538
|
* @returns This vector.
|
|
539
539
|
*/
|
|
540
540
|
export function zero<T extends Vector3Like>(out: T): T {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
541
|
+
out[0] = 0;
|
|
542
|
+
out[1] = 0;
|
|
543
|
+
out[2] = 0;
|
|
544
|
+
return out;
|
|
545
545
|
}
|
|
546
546
|
|
|
547
547
|
/**
|
|
@@ -556,17 +556,17 @@ export function zero<T extends Vector3Like>(out: T): T {
|
|
|
556
556
|
* @see [Hermite interpolation](https://en.wikipedia.org/wiki/Hermite_interpolation)
|
|
557
557
|
*/
|
|
558
558
|
export function hermite<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, c: Vector3Like, d: Vector3Like, t: number, out: T): T {
|
|
559
|
-
|
|
559
|
+
const factorTimes2: number = t * t;
|
|
560
560
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
561
|
+
const factor1: number = factorTimes2 * (2 * t - 3) + 1;
|
|
562
|
+
const factor2: number = factorTimes2 * (t - 2) + t;
|
|
563
|
+
const factor3: number = factorTimes2 * (t - 1);
|
|
564
|
+
const factor4: number = factorTimes2 * (3 - 2 * t);
|
|
565
565
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
566
|
+
out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
|
|
567
|
+
out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
|
|
568
|
+
out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
|
|
569
|
+
return out;
|
|
570
570
|
}
|
|
571
571
|
|
|
572
572
|
/**
|
|
@@ -581,19 +581,19 @@ export function hermite<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, c
|
|
|
581
581
|
* @see [Bézier curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve)
|
|
582
582
|
*/
|
|
583
583
|
export function bezier<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, c: Vector3Like, d: Vector3Like, t: number, out: T): T {
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
584
|
+
const inverseFactor: number = 1 - t;
|
|
585
|
+
const inverseFactorTimesTwo: number = inverseFactor * inverseFactor;
|
|
586
|
+
const factorTimes2: number = t * t;
|
|
587
|
+
|
|
588
|
+
const factor1: number = inverseFactorTimesTwo * inverseFactor;
|
|
589
|
+
const factor2: number = 3 * t * inverseFactorTimesTwo;
|
|
590
|
+
const factor3: number = 3 * factorTimes2 * inverseFactor;
|
|
591
|
+
const factor4: number = factorTimes2 * t;
|
|
592
|
+
|
|
593
|
+
out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
|
|
594
|
+
out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
|
|
595
|
+
out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
|
|
596
|
+
return out;
|
|
597
597
|
}
|
|
598
598
|
|
|
599
599
|
/**
|
|
@@ -605,36 +605,36 @@ export function bezier<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, c:
|
|
|
605
605
|
* @see [Quaternion](https://en.wikipedia.org/wiki/Quaternion)
|
|
606
606
|
*/
|
|
607
607
|
export function transformQuaternion<T extends Vector3Like>(vector: Vector3Like, quaternion: QuaternionLike, out: T): T {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
608
|
+
const qx: number = quaternion[0];
|
|
609
|
+
const qy: number = quaternion[1];
|
|
610
|
+
const qz: number = quaternion[2];
|
|
611
|
+
const qw: number = quaternion[3];
|
|
612
|
+
|
|
613
|
+
const x: number = vector[0];
|
|
614
|
+
const y: number = vector[1];
|
|
615
|
+
const z: number = vector[2];
|
|
616
|
+
|
|
617
|
+
let uvx: number = qy * z - qz * y;
|
|
618
|
+
let uvy: number = qz * x - qx * z;
|
|
619
|
+
let uvz: number = qx * y - qy * x;
|
|
620
|
+
|
|
621
|
+
let uuvx: number = qy * uvz - qz * uvy;
|
|
622
|
+
let uuvy: number = qz * uvx - qx * uvz;
|
|
623
|
+
let uuvz: number = qx * uvy - qy * uvx;
|
|
624
|
+
|
|
625
|
+
const w2: number = qw * 2;
|
|
626
|
+
uvx *= w2;
|
|
627
|
+
uvy *= w2;
|
|
628
|
+
uvz *= w2;
|
|
629
|
+
|
|
630
|
+
uuvx *= 2;
|
|
631
|
+
uuvy *= 2;
|
|
632
|
+
uuvz *= 2;
|
|
633
|
+
|
|
634
|
+
out[0] = x + uvx + uuvx;
|
|
635
|
+
out[1] = y + uvy + uuvy;
|
|
636
|
+
out[2] = z + uvz + uuvz;
|
|
637
|
+
return out;
|
|
638
638
|
}
|
|
639
639
|
|
|
640
640
|
/** The unit three-dimensional vector that represents the X-axis. */
|
|
@@ -647,40 +647,40 @@ const yAxis: Vector3Like = new Float32Array([0, 1, 0]) as Vector3Like;
|
|
|
647
647
|
const intermediary: Vector3Like = new Float32Array(3) as Vector3Like;
|
|
648
648
|
|
|
649
649
|
/**
|
|
650
|
-
* Creates a quaternion that represents the shortest rotation from one vector to another.
|
|
650
|
+
* Creates a quaternion that represents the shortest rotation from one unit vector to another.
|
|
651
651
|
* @param a The first vector.
|
|
652
652
|
* @param b The second vector.
|
|
653
653
|
* @param out The quaternion to store the result in.
|
|
654
654
|
* @returns The quaternion.
|
|
655
655
|
*/
|
|
656
656
|
export function rotationTo<T extends QuaternionLike>(a: Vector3Like, b: Vector3Like, out: T): T {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
657
|
+
const dp: number = dot(a, b);
|
|
658
|
+
|
|
659
|
+
if (dp < epsilon - 1) {
|
|
660
|
+
cross(xAxis, a, intermediary);
|
|
661
|
+
if (getMagnitude(intermediary) < epsilon) { cross(yAxis, a, intermediary); }
|
|
662
|
+
normalize(intermediary, intermediary);
|
|
663
|
+
out[0] = intermediary[0];
|
|
664
|
+
out[1] = intermediary[1];
|
|
665
|
+
out[2] = intermediary[2];
|
|
666
|
+
out[3] = 0;
|
|
667
|
+
return out;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
if (dp > 1 - epsilon) {
|
|
671
|
+
out[0] = 0;
|
|
672
|
+
out[1] = 0;
|
|
673
|
+
out[2] = 0;
|
|
674
|
+
out[3] = 1;
|
|
675
|
+
return out;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
cross(a, b, intermediary);
|
|
679
|
+
out[0] = intermediary[0];
|
|
680
|
+
out[1] = intermediary[1];
|
|
681
|
+
out[2] = intermediary[2];
|
|
682
|
+
out[3] = 1 + dp;
|
|
683
|
+
return normalizeVector4(out as Vector4Like, out as Vector4Like) as T;
|
|
684
684
|
}
|
|
685
685
|
|
|
686
686
|
/**
|
|
@@ -688,45 +688,45 @@ export function rotationTo<T extends QuaternionLike>(a: Vector3Like, b: Vector3L
|
|
|
688
688
|
* @see [Euclidean vector](https://en.wikipedia.org/wiki/Euclidean_vector)
|
|
689
689
|
*/
|
|
690
690
|
export default class Vector3 extends Float32Array implements Vector {
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
691
|
+
/**
|
|
692
|
+
* Creates a vector with the given values.
|
|
693
|
+
* @param x The first component.
|
|
694
|
+
* @param y The second component.
|
|
695
|
+
* @param z The third component.
|
|
696
|
+
* @returns A new vector.
|
|
697
|
+
*/
|
|
698
|
+
public static fromValues(x: number, y: number, z: number): Vector3;
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* Creates a vector with the given values.
|
|
702
|
+
* @param x The first component.
|
|
703
|
+
* @param y The second component.
|
|
704
|
+
* @param z The third component.
|
|
705
|
+
* @param out The vector to store the result in.
|
|
706
|
+
* @returns A new vector.
|
|
707
|
+
*/
|
|
708
|
+
public static fromValues<T extends Vector3Like>(x: number, y: number, z: number, out: T): T;
|
|
709
|
+
|
|
710
|
+
public static fromValues<T extends Vector3Like>(x: number, y: number, z: number, out: T = new Vector3() as T): T {
|
|
711
|
+
return fromValues(x, y, z, out);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* Creates a three-dimensional zero vector.
|
|
716
|
+
* @see [Euclidean vector](https://en.wikipedia.org/wiki/Euclidean_vector)
|
|
717
|
+
*/
|
|
718
|
+
public constructor() {
|
|
719
|
+
super(3);
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
723
|
* Determines whether this vector is roughly equivalent to another.
|
|
724
724
|
* @param vector The other vector.
|
|
725
725
|
* @returns Whether the vectors are equivalent.
|
|
726
726
|
*/
|
|
727
727
|
public equals(vector: Vector3Like): boolean {
|
|
728
|
-
|
|
729
|
-
|
|
728
|
+
return equals(this, vector);
|
|
729
|
+
}
|
|
730
730
|
|
|
731
731
|
/**
|
|
732
732
|
* Determines whether this vector is exactly equivalent to another.
|
|
@@ -734,20 +734,20 @@ export default class Vector3 extends Float32Array implements Vector {
|
|
|
734
734
|
* @returns Whether the vectors are equivalent.
|
|
735
735
|
*/
|
|
736
736
|
public exactEquals(vector: Vector3Like): boolean {
|
|
737
|
-
|
|
738
|
-
|
|
737
|
+
return exactEquals(this, vector);
|
|
738
|
+
}
|
|
739
739
|
|
|
740
|
-
|
|
740
|
+
/**
|
|
741
741
|
* Adds two vectors of the same size.
|
|
742
742
|
* @param vector The other vector.
|
|
743
743
|
* @returns The sum of the vectors.
|
|
744
744
|
*/
|
|
745
745
|
public add(vector: Vector3Like): Vector3;
|
|
746
746
|
|
|
747
|
-
|
|
747
|
+
/**
|
|
748
748
|
* Adds two vectors of the same size.
|
|
749
749
|
* @param vector The other vector.
|
|
750
|
-
|
|
750
|
+
* @param out The vector to store the result in.
|
|
751
751
|
* @returns The sum of the vectors.
|
|
752
752
|
*/
|
|
753
753
|
public add<T extends Vector3Like>(vector: Vector3Like, out: T): T;
|
|
@@ -757,23 +757,23 @@ export default class Vector3 extends Float32Array implements Vector {
|
|
|
757
757
|
}
|
|
758
758
|
|
|
759
759
|
/**
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
760
|
+
* Creates a copy of this vector.
|
|
761
|
+
* @returns The copy.
|
|
762
|
+
*/
|
|
763
|
+
public clone(): Vector3;
|
|
764
764
|
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
765
|
+
/**
|
|
766
|
+
* Copies the values from this vector to another one.
|
|
767
|
+
* @param out The vector to store the result in.
|
|
768
|
+
* @returns The copy.
|
|
769
|
+
*/
|
|
770
|
+
public clone<T extends Vector3Like>(out: T): T;
|
|
771
|
+
|
|
772
|
+
public clone<T extends Vector3Like>(out: T = new Vector3() as T): T {
|
|
773
|
+
return copy(this, out);
|
|
774
|
+
}
|
|
775
775
|
|
|
776
|
-
|
|
776
|
+
/**
|
|
777
777
|
* Copies the values of another vector into this one.
|
|
778
778
|
* @param vector The vector to copy.
|
|
779
779
|
* @returns This vector.
|
|
@@ -782,17 +782,17 @@ export default class Vector3 extends Float32Array implements Vector {
|
|
|
782
782
|
return copy(vector, this);
|
|
783
783
|
}
|
|
784
784
|
|
|
785
|
-
|
|
785
|
+
/**
|
|
786
786
|
* Multiplies this vector by another.
|
|
787
787
|
* @param vvector The other vector.
|
|
788
788
|
* @returns The product of the vectors.
|
|
789
789
|
*/
|
|
790
790
|
public multiply(vector: Vector3Like): Vector3;
|
|
791
791
|
|
|
792
|
-
|
|
792
|
+
/**
|
|
793
793
|
* Multiplies this vector by another.
|
|
794
794
|
* @param vector The other vector.
|
|
795
|
-
|
|
795
|
+
* @param out The vector to store the result in.
|
|
796
796
|
* @returns The product of the vectors.
|
|
797
797
|
*/
|
|
798
798
|
public multiply<T extends Vector3Like>(vector: Vector3Like, out: T): T;
|
|
@@ -801,17 +801,17 @@ export default class Vector3 extends Float32Array implements Vector {
|
|
|
801
801
|
return multiply(this, vector, out);
|
|
802
802
|
}
|
|
803
803
|
|
|
804
|
-
|
|
804
|
+
/**
|
|
805
805
|
* Divides this vector by another.
|
|
806
806
|
* @param vector The other vector.
|
|
807
807
|
* @returns The quotient of the vectors.
|
|
808
808
|
*/
|
|
809
809
|
public divide(vector: Vector3Like): Vector3;
|
|
810
810
|
|
|
811
|
-
|
|
811
|
+
/**
|
|
812
812
|
* Divides this vector by another.
|
|
813
813
|
* @param vector The other vector.
|
|
814
|
-
|
|
814
|
+
* @param out The vector to store the result in.
|
|
815
815
|
* @returns The quotient of the vectors.
|
|
816
816
|
*/
|
|
817
817
|
public divide<T extends Vector3Like>(vector: Vector3Like, out: T): T;
|
|
@@ -820,17 +820,17 @@ export default class Vector3 extends Float32Array implements Vector {
|
|
|
820
820
|
return divide(this, vector, out);
|
|
821
821
|
}
|
|
822
822
|
|
|
823
|
-
|
|
823
|
+
/**
|
|
824
824
|
* Subtracts another vector from this one.
|
|
825
825
|
* @param vector The other vector.
|
|
826
826
|
* @returns The difference between the vectors.
|
|
827
827
|
*/
|
|
828
828
|
public subtract(vector: Vector3Like): Vector3;
|
|
829
829
|
|
|
830
|
-
|
|
830
|
+
/**
|
|
831
831
|
* Subtracts another vector from this one.
|
|
832
832
|
* @param vector The other vector.
|
|
833
|
-
|
|
833
|
+
* @param out The vector to store the result in.
|
|
834
834
|
* @returns The difference between the vectors.
|
|
835
835
|
*/
|
|
836
836
|
public subtract<T extends Vector3Like>(vector: Vector3Like, out: T): T;
|
|
@@ -845,16 +845,16 @@ export default class Vector3 extends Float32Array implements Vector {
|
|
|
845
845
|
*/
|
|
846
846
|
public ceil(): Vector3;
|
|
847
847
|
|
|
848
|
-
|
|
848
|
+
/**
|
|
849
849
|
* Rounds up the components of this vector.
|
|
850
|
-
|
|
850
|
+
* @param out The vector to store the result in.
|
|
851
851
|
* @returns The rounded vector.
|
|
852
852
|
*/
|
|
853
853
|
public ceil<T extends Vector3Like>(out: T): T;
|
|
854
854
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
855
|
+
public ceil<T extends Vector3Like>(out: T = new Vector3() as T): T {
|
|
856
|
+
return ceil(this, out);
|
|
857
|
+
}
|
|
858
858
|
|
|
859
859
|
/**
|
|
860
860
|
* Rounds down the components of this vector.
|
|
@@ -862,16 +862,16 @@ export default class Vector3 extends Float32Array implements Vector {
|
|
|
862
862
|
*/
|
|
863
863
|
public floor(): Vector3;
|
|
864
864
|
|
|
865
|
-
|
|
865
|
+
/**
|
|
866
866
|
* Rounds down the components of this vector.
|
|
867
|
-
|
|
867
|
+
* @param out The vector to store the result in.
|
|
868
868
|
* @returns The rounded vector.
|
|
869
869
|
*/
|
|
870
870
|
public floor<T extends Vector3Like>(out: T): T;
|
|
871
871
|
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
872
|
+
public floor<T extends Vector3Like>(out: T = new Vector3() as T): T {
|
|
873
|
+
return floor(this, out);
|
|
874
|
+
}
|
|
875
875
|
|
|
876
876
|
/**
|
|
877
877
|
* Rounds the components of this vector.
|
|
@@ -879,16 +879,16 @@ export default class Vector3 extends Float32Array implements Vector {
|
|
|
879
879
|
*/
|
|
880
880
|
public round(): Vector3;
|
|
881
881
|
|
|
882
|
-
|
|
882
|
+
/**
|
|
883
883
|
* Rounds the components of this vector.
|
|
884
|
-
|
|
884
|
+
* @param out The vector to store the result in.
|
|
885
885
|
* @returns The rounded vector.
|
|
886
886
|
*/
|
|
887
887
|
public round<T extends Vector3Like>(out: T): T;
|
|
888
888
|
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
889
|
+
public round<T extends Vector3Like>(out: T = new Vector3() as T): T {
|
|
890
|
+
return round(this, out);
|
|
891
|
+
}
|
|
892
892
|
|
|
893
893
|
/**
|
|
894
894
|
* Returns the minimum of this and another vector.
|
|
@@ -897,17 +897,17 @@ export default class Vector3 extends Float32Array implements Vector {
|
|
|
897
897
|
*/
|
|
898
898
|
public min(vector: Vector3Like): Vector3;
|
|
899
899
|
|
|
900
|
-
|
|
900
|
+
/**
|
|
901
901
|
* Returns the minimum of this and another vector.
|
|
902
902
|
* @param vector The other vector.
|
|
903
|
-
|
|
903
|
+
* @param out The vector to store the result in.
|
|
904
904
|
* @returns The minimum.
|
|
905
905
|
*/
|
|
906
906
|
public min<T extends Vector3Like>(vector: Vector3Like, out: T): T;
|
|
907
907
|
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
908
|
+
public min<T extends Vector3Like>(vector: Vector3Like, out: T = new Vector3() as T): T {
|
|
909
|
+
return min(this, vector, out);
|
|
910
|
+
}
|
|
911
911
|
|
|
912
912
|
/**
|
|
913
913
|
* Returns the maximum of this and another vector.
|
|
@@ -916,17 +916,17 @@ export default class Vector3 extends Float32Array implements Vector {
|
|
|
916
916
|
*/
|
|
917
917
|
public max(vector: Vector3Like): Vector3;
|
|
918
918
|
|
|
919
|
-
|
|
919
|
+
/**
|
|
920
920
|
* Returns the maximum of this and another vector.
|
|
921
921
|
* @param vector The other vector.
|
|
922
|
-
|
|
922
|
+
* @param out The vector to store the result in.
|
|
923
923
|
* @returns The maximum.
|
|
924
924
|
*/
|
|
925
925
|
public max<T extends Vector3Like>(vector: Vector3Like, out: T): T;
|
|
926
926
|
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
927
|
+
public max<T extends Vector3Like>(vector: Vector3Like, out: T = new Vector3() as T): T {
|
|
928
|
+
return max(this, vector, out);
|
|
929
|
+
}
|
|
930
930
|
|
|
931
931
|
/**
|
|
932
932
|
* Scales this vector by a scalar.
|
|
@@ -935,17 +935,17 @@ export default class Vector3 extends Float32Array implements Vector {
|
|
|
935
935
|
*/
|
|
936
936
|
public scale(scalar: number): Vector3;
|
|
937
937
|
|
|
938
|
-
|
|
938
|
+
/**
|
|
939
939
|
* Scales this vector by a scalar.
|
|
940
940
|
* @param scalar The scalar.
|
|
941
|
-
|
|
941
|
+
* @param out The vector to store the result in.
|
|
942
942
|
* @returns The scaled vector.
|
|
943
943
|
*/
|
|
944
944
|
public scale<T extends Vector3Like>(scalar: number, out: T): T;
|
|
945
945
|
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
946
|
+
public scale<T extends Vector3Like>(scalar: number, out: T = new Vector3() as T): T {
|
|
947
|
+
return scale(this, scalar, out);
|
|
948
|
+
}
|
|
949
949
|
|
|
950
950
|
/**
|
|
951
951
|
* Adds another vector to this one after scaling the other by a scalar.
|
|
@@ -955,48 +955,48 @@ export default class Vector3 extends Float32Array implements Vector {
|
|
|
955
955
|
*/
|
|
956
956
|
public scaleAndAdd(vector: Vector3Like, scalar: number): Vector3;
|
|
957
957
|
|
|
958
|
-
|
|
958
|
+
/**
|
|
959
959
|
* Adds another vector to this one after scaling the other by a scalar.
|
|
960
960
|
* @param vector The other vector.
|
|
961
961
|
* @param scalar The scalar.
|
|
962
|
-
|
|
962
|
+
* @param out The vector to store the result in.
|
|
963
963
|
* @returns The sum.
|
|
964
964
|
*/
|
|
965
965
|
public scaleAndAdd<T extends Vector3Like>(vector: Vector3Like, scalar: number, out: T): T;
|
|
966
966
|
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
967
|
+
public scaleAndAdd<T extends Vector3Like>(vector: Vector3Like, scalar: number, out: T = new Vector3() as T): T {
|
|
968
|
+
return scaleAndAdd(this, vector, scalar, out);
|
|
969
|
+
}
|
|
970
970
|
|
|
971
971
|
/**
|
|
972
972
|
* Calculates the Euclidean distance between this vector and another.
|
|
973
973
|
* @param vector The other vector.
|
|
974
974
|
* @returns The distance.
|
|
975
|
-
|
|
975
|
+
* @see [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance)
|
|
976
976
|
*/
|
|
977
977
|
public distance(vector: Vector3Like): number {
|
|
978
|
-
|
|
979
|
-
|
|
978
|
+
return distance(this, vector);
|
|
979
|
+
}
|
|
980
980
|
|
|
981
981
|
/**
|
|
982
982
|
* Calculates the squared Euclidean distance between this vector and another.
|
|
983
983
|
* @param vector The other vector.
|
|
984
984
|
* @returns The squared distance.
|
|
985
|
-
|
|
985
|
+
* @see [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance)
|
|
986
986
|
*/
|
|
987
987
|
public squaredDistance(vector: Vector3Like): number {
|
|
988
|
-
|
|
989
|
-
|
|
988
|
+
return squaredDistance(this, vector);
|
|
989
|
+
}
|
|
990
990
|
|
|
991
991
|
/** The magnitude (length) of this vector. */
|
|
992
992
|
public get magnitude(): number {
|
|
993
|
-
|
|
994
|
-
|
|
993
|
+
return getMagnitude(this);
|
|
994
|
+
}
|
|
995
995
|
|
|
996
996
|
/** The squared magnitude (length) of this vector. */
|
|
997
997
|
public get squaredMagnitude(): number {
|
|
998
|
-
|
|
999
|
-
|
|
998
|
+
return getSquaredMagnitude(this);
|
|
999
|
+
}
|
|
1000
1000
|
|
|
1001
1001
|
/**
|
|
1002
1002
|
* Negates this vector.
|
|
@@ -1004,106 +1004,106 @@ export default class Vector3 extends Float32Array implements Vector {
|
|
|
1004
1004
|
*/
|
|
1005
1005
|
public negate(): Vector3;
|
|
1006
1006
|
|
|
1007
|
-
|
|
1007
|
+
/**
|
|
1008
1008
|
* Negates this vector.
|
|
1009
|
-
|
|
1009
|
+
* @param out The vector to store the result in.
|
|
1010
1010
|
* @returns The negated vector.
|
|
1011
1011
|
*/
|
|
1012
1012
|
public negate<T extends Vector3Like>(out: T): T;
|
|
1013
1013
|
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1014
|
+
public negate<T extends Vector3Like>(out: T = new Vector3() as T): T {
|
|
1015
|
+
return negate(this, out);
|
|
1016
|
+
}
|
|
1017
1017
|
|
|
1018
|
-
|
|
1018
|
+
/**
|
|
1019
1019
|
* Calculates the multiplicative inverse of the components of this vector.
|
|
1020
1020
|
* @returns The inverted vector.
|
|
1021
1021
|
*/
|
|
1022
|
-
public
|
|
1022
|
+
public invert(): Vector3;
|
|
1023
1023
|
|
|
1024
|
-
|
|
1024
|
+
/**
|
|
1025
1025
|
* Calculates the multiplicative inverse of the components of this vector.
|
|
1026
|
-
|
|
1026
|
+
* @param out The vector to store the result in.
|
|
1027
1027
|
* @returns The inverted vector.
|
|
1028
1028
|
*/
|
|
1029
|
-
public
|
|
1029
|
+
public invert<T extends Vector3Like>(out: T): T;
|
|
1030
1030
|
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1031
|
+
public invert<T extends Vector3Like>(out: T = new Vector3() as T): T {
|
|
1032
|
+
return invert(this, out);
|
|
1033
|
+
}
|
|
1034
1034
|
|
|
1035
|
-
|
|
1035
|
+
/**
|
|
1036
1036
|
* Normalizes this vector.
|
|
1037
1037
|
* @returns The normalized vector.
|
|
1038
|
-
|
|
1038
|
+
* @see [Unit vector](https://en.wikipedia.org/wiki/Unit_vector)
|
|
1039
1039
|
*/
|
|
1040
1040
|
public normalize(): Vector3;
|
|
1041
1041
|
|
|
1042
|
-
|
|
1042
|
+
/**
|
|
1043
1043
|
* Normalizes this vector.
|
|
1044
|
-
|
|
1044
|
+
* @param out The vector to store the result in.
|
|
1045
1045
|
* @returns The normalized vector.
|
|
1046
|
-
|
|
1046
|
+
* @see [Unit vector](https://en.wikipedia.org/wiki/Unit_vector)
|
|
1047
1047
|
*/
|
|
1048
1048
|
public normalize<T extends Vector3Like>(out: T): T;
|
|
1049
1049
|
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1050
|
+
public normalize<T extends Vector3Like>(out: T = new Vector3() as T): T {
|
|
1051
|
+
return normalize(this, out);
|
|
1052
|
+
}
|
|
1053
1053
|
|
|
1054
1054
|
/**
|
|
1055
1055
|
* Calculates the dot product of this and another vector.
|
|
1056
1056
|
* @param vector The other vector.
|
|
1057
1057
|
* @returns The dot product.
|
|
1058
|
-
|
|
1058
|
+
* @see [Dot product](https://en.wikipedia.org/wiki/Dot_product)
|
|
1059
1059
|
*/
|
|
1060
1060
|
public dot(vector: Vector3Like): number {
|
|
1061
|
-
|
|
1062
|
-
|
|
1061
|
+
return dot(this, vector);
|
|
1062
|
+
}
|
|
1063
1063
|
|
|
1064
|
-
|
|
1064
|
+
/**
|
|
1065
1065
|
* Calculates the cross product of this and another vector.
|
|
1066
1066
|
* @param vector The other vector.
|
|
1067
1067
|
* @returns The cross product.
|
|
1068
|
-
|
|
1068
|
+
* @see [Cross product](https://en.wikipedia.org/wiki/Cross_product)
|
|
1069
1069
|
*/
|
|
1070
1070
|
public cross(vector: Vector3Like): Vector3;
|
|
1071
1071
|
|
|
1072
|
-
|
|
1072
|
+
/**
|
|
1073
1073
|
* Calculates the cross product of this and another vector.
|
|
1074
1074
|
* @param vector The other vector.
|
|
1075
|
-
|
|
1075
|
+
* @param out The vector to store the result in.
|
|
1076
1076
|
* @returns The cross product.
|
|
1077
|
-
|
|
1077
|
+
* @see [Cross product](https://en.wikipedia.org/wiki/Cross_product)
|
|
1078
1078
|
*/
|
|
1079
1079
|
public cross<T extends Vector3Like>(vector: Vector3Like, out: T): T;
|
|
1080
1080
|
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1081
|
+
public cross<T extends Vector3Like>(vector: Vector3Like, out: T = new Vector3() as T): T {
|
|
1082
|
+
return cross(this, vector, out);
|
|
1083
|
+
}
|
|
1084
1084
|
|
|
1085
1085
|
/**
|
|
1086
1086
|
* Performs a linear interpolation between this and another vector.
|
|
1087
1087
|
* @param vector The other vector.
|
|
1088
1088
|
* @param t The interpolation amount (in `[0,1]`).
|
|
1089
1089
|
* @returns The interpolated vector.
|
|
1090
|
-
|
|
1090
|
+
* @see [Linear interpolation](https://en.wikipedia.org/wiki/Linear_interpolation)
|
|
1091
1091
|
*/
|
|
1092
1092
|
public lerp(vector: Vector3Like, t: number): Vector3;
|
|
1093
1093
|
|
|
1094
|
-
|
|
1094
|
+
/**
|
|
1095
1095
|
* Performs a linear interpolation between this and another vector.
|
|
1096
1096
|
* @param vector The other vector.
|
|
1097
1097
|
* @param t The interpolation amount (in `[0,1]`).
|
|
1098
|
-
|
|
1098
|
+
* @param out The vector to store the result in.
|
|
1099
1099
|
* @returns The interpolated vector.
|
|
1100
|
-
|
|
1100
|
+
* @see [Linear interpolation](https://en.wikipedia.org/wiki/Linear_interpolation)
|
|
1101
1101
|
*/
|
|
1102
1102
|
public lerp<T extends Vector3Like>(vector: Vector3Like, t: number, out: T): T;
|
|
1103
1103
|
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1104
|
+
public lerp<T extends Vector3Like>(vector: Vector3Like, t: number, out: T = new Vector3() as T): T {
|
|
1105
|
+
return lerp(this, vector, t, out);
|
|
1106
|
+
}
|
|
1107
1107
|
|
|
1108
1108
|
/**
|
|
1109
1109
|
* Sets this vector to a random value with the given magnitude.
|
|
@@ -1111,218 +1111,218 @@ export default class Vector3 extends Float32Array implements Vector {
|
|
|
1111
1111
|
* @returns This vector.
|
|
1112
1112
|
*/
|
|
1113
1113
|
public random(magnitude = 1): this {
|
|
1114
|
-
|
|
1115
|
-
|
|
1114
|
+
return random(magnitude, this);
|
|
1115
|
+
}
|
|
1116
1116
|
|
|
1117
|
-
|
|
1117
|
+
/**
|
|
1118
1118
|
* Transforms this vector by a three-by-three matrix.
|
|
1119
1119
|
* @param matrix The matrix.
|
|
1120
1120
|
* @returns The transformed vector.
|
|
1121
1121
|
*/
|
|
1122
1122
|
public transformMatrix3(matrix: Matrix3Like): Vector3;
|
|
1123
1123
|
|
|
1124
|
-
|
|
1124
|
+
/**
|
|
1125
1125
|
* Transforms this vector by a three-by-three matrix.
|
|
1126
1126
|
* @param matrix The matrix.
|
|
1127
|
-
|
|
1127
|
+
* @param out The vector to store the result in.
|
|
1128
1128
|
* @returns The transformed vector.
|
|
1129
1129
|
*/
|
|
1130
1130
|
public transformMatrix3<T extends Vector3Like>(matrix: Matrix3Like, out: T): T;
|
|
1131
1131
|
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1132
|
+
public transformMatrix3<T extends Vector3Like>(matrix: Matrix3Like, out: T = new Vector3() as T): T {
|
|
1133
|
+
return transformMatrix3(this, matrix, out);
|
|
1134
|
+
}
|
|
1135
1135
|
|
|
1136
|
-
|
|
1136
|
+
/**
|
|
1137
1137
|
* Transforms this vector by a four-by-four matrix.
|
|
1138
1138
|
* @param matrix The matrix.
|
|
1139
1139
|
* @returns The transformed vector.
|
|
1140
1140
|
*/
|
|
1141
1141
|
public transformMatrix4(matrix: Matrix4Like): Vector3;
|
|
1142
1142
|
|
|
1143
|
-
|
|
1143
|
+
/**
|
|
1144
1144
|
* Transforms this vector by a four-by-four matrix.
|
|
1145
1145
|
* @param matrix The matrix.
|
|
1146
|
-
|
|
1146
|
+
* @param out The vector to store the result in.
|
|
1147
1147
|
* @returns The transformed vector.
|
|
1148
1148
|
*/
|
|
1149
1149
|
public transformMatrix4<T extends Vector3Like>(matrix: Matrix4Like, out: T): T;
|
|
1150
1150
|
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1151
|
+
public transformMatrix4<T extends Vector3Like>(matrix: Matrix4Like, out: T = new Vector3() as T): T {
|
|
1152
|
+
return transformMatrix4(this, matrix, out);
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* Rotates this vector around the X-axis.
|
|
1157
|
+
* @param origin The origin of the rotation.
|
|
1158
|
+
* @param radians The angle of rotation in radians.
|
|
1159
|
+
* @returns The rotated vector.
|
|
1160
|
+
*/
|
|
1161
|
+
public rotateX(origin: Vector3Like, radians: number): Vector3;
|
|
1162
|
+
|
|
1163
|
+
/**
|
|
1164
|
+
* Rotates this vector around the X-axis.
|
|
1165
|
+
* @param origin The origin of the rotation.
|
|
1166
|
+
* @param radians The angle of rotation in radians.
|
|
1167
|
+
* @param out The vector to store the result in.
|
|
1168
|
+
* @returns The rotated vector.
|
|
1169
|
+
*/
|
|
1170
|
+
public rotateX<T extends Vector3Like>(origin: Vector3Like, radians: number, out: T): T;
|
|
1171
|
+
|
|
1172
|
+
public rotateX<T extends Vector3Like>(origin: Vector3Like, radians: number, out: T = new Vector3() as T): T {
|
|
1173
|
+
return rotateX(this, origin, radians, out);
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
/**
|
|
1177
|
+
* Rotates this vector around the Y-axis.
|
|
1178
|
+
* @param origin The origin of the rotation.
|
|
1179
|
+
* @param radians The angle of rotation in radians.
|
|
1180
|
+
* @returns The rotated vector.
|
|
1181
|
+
*/
|
|
1182
|
+
public rotateY(origin: Vector3Like, radians: number): Vector3;
|
|
1183
|
+
|
|
1184
|
+
/**
|
|
1185
|
+
* Rotates this vector around the Y-axis.
|
|
1186
|
+
* @param origin The origin of the rotation.
|
|
1187
|
+
* @param radians The angle of rotation in radians.
|
|
1188
|
+
* @param out The vector to store the result in.
|
|
1189
|
+
* @returns The rotated vector.
|
|
1190
|
+
*/
|
|
1191
|
+
public rotateY<T extends Vector3Like>(origin: Vector3Like, radians: number, out: T): T;
|
|
1192
|
+
|
|
1193
|
+
public rotateY<T extends Vector3Like>(origin: Vector3Like, radians: number, out: T = new Vector3() as T): T {
|
|
1194
|
+
return rotateY(this, origin, radians, out);
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
/**
|
|
1198
|
+
* Rotates this vector around the Z-axis.
|
|
1199
|
+
* @param origin The origin of the rotation.
|
|
1200
|
+
* @param radians The angle of rotation in radians.
|
|
1201
|
+
* @returns The rotated vector.
|
|
1202
|
+
*/
|
|
1203
|
+
public rotateZ(origin: Vector3Like, radians: number): Vector3;
|
|
1204
|
+
|
|
1205
|
+
/**
|
|
1206
|
+
* Rotates this vector around the Z-axis.
|
|
1207
|
+
* @param origin The origin of the rotation.
|
|
1208
|
+
* @param radians The angle of rotation in radians.
|
|
1209
|
+
* @param out The vector to store the result in.
|
|
1210
|
+
* @returns The rotated vector.
|
|
1211
|
+
*/
|
|
1212
|
+
public rotateZ<T extends Vector3Like>(origin: Vector3Like, radians: number, out: T): T;
|
|
1213
|
+
|
|
1214
|
+
public rotateZ<T extends Vector3Like>(origin: Vector3Like, radians: number, out: T = new Vector3() as T): T {
|
|
1215
|
+
return rotateZ(this, origin, radians, out);
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
/**
|
|
1219
|
+
* Gets the angle from this vector to another in radians.
|
|
1220
|
+
* @param vector The other vector.
|
|
1221
|
+
* @returns The angular distance from this vector to the other.
|
|
1222
|
+
*/
|
|
1223
|
+
public angle(vector: Vector3Like): number {
|
|
1224
|
+
return angle(this, vector);
|
|
1225
|
+
}
|
|
1226
1226
|
|
|
1227
1227
|
/**
|
|
1228
1228
|
* Sets this to the zero vector.
|
|
1229
1229
|
* @returns This vector.
|
|
1230
1230
|
*/
|
|
1231
1231
|
public zero(): this {
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1232
|
+
return zero(this);
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
/**
|
|
1236
|
+
* Performs a Hermite interpolation with two control points between this vector and another.
|
|
1237
|
+
* @param a The first control point.
|
|
1238
|
+
* @param b The second control point.
|
|
1239
|
+
* @param end The other vector.
|
|
1240
|
+
* @param t The interpolation amount in the range `[0,1]`.
|
|
1241
|
+
* @returns The interpolated vector.
|
|
1242
|
+
* @see [Hermite interpolation](https://en.wikipedia.org/wiki/Hermite_interpolation)
|
|
1243
|
+
*/
|
|
1244
|
+
public hermite(a: Vector3Like, b: Vector3Like, end: Vector3Like, t: number): Vector3;
|
|
1245
|
+
|
|
1246
|
+
/**
|
|
1247
|
+
* Performs a Hermite interpolation with two control points between this vector and another.
|
|
1248
|
+
* @param a The first control point.
|
|
1249
|
+
* @param b The second control point.
|
|
1250
|
+
* @param end The other vector.
|
|
1251
|
+
* @param t The interpolation amount in the range `[0,1]`.
|
|
1252
|
+
* @param out The vector to store the result in.
|
|
1253
|
+
* @returns The interpolated vector.
|
|
1254
|
+
* @see [Hermite interpolation](https://en.wikipedia.org/wiki/Hermite_interpolation)
|
|
1255
|
+
*/
|
|
1256
|
+
public hermite<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, end: Vector3Like, t: number, out: T): T;
|
|
1257
|
+
|
|
1258
|
+
public hermite<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, end: Vector3Like, t: number, out: T = new Vector3() as T): T {
|
|
1259
|
+
return hermite(this, a, b, end, t, out);
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
/**
|
|
1263
|
+
* Performs a Bézier interpolation with two control points between this vector and another.
|
|
1264
|
+
* @param a The first control point.
|
|
1265
|
+
* @param b The second control point.
|
|
1266
|
+
* @param end The other vector.
|
|
1267
|
+
* @param t The interpolation amount in the range `[0,1]`.
|
|
1268
|
+
* @returns The interpolated vector.
|
|
1269
|
+
* @see [Bézier curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve)
|
|
1270
|
+
*/
|
|
1271
|
+
public bezier(a: Vector3Like, b: Vector3Like, end: Vector3Like, t: number): Vector3;
|
|
1272
|
+
|
|
1273
|
+
/**
|
|
1274
|
+
* Performs a Bézier interpolation with two control points between this vector and another.
|
|
1275
|
+
* @param a The first control point.
|
|
1276
|
+
* @param b The second control point.
|
|
1277
|
+
* @param end The other vector.
|
|
1278
|
+
* @param t The interpolation amount in the range `[0,1]`.
|
|
1279
|
+
* @param out The vector to store the result in.
|
|
1280
|
+
* @returns The interpolated vector.
|
|
1281
|
+
* @see [Bézier curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve)
|
|
1282
|
+
*/
|
|
1283
|
+
public bezier<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, end: Vector3Like, t: number, out: T): T;
|
|
1284
|
+
|
|
1285
|
+
public bezier<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, end: Vector3Like, t: number, out: T = new Vector3() as T): T {
|
|
1286
|
+
return bezier(this, a, b, end, t, out);
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
/**
|
|
1290
1290
|
* Transforms this vector by a quaternion.
|
|
1291
1291
|
* @param quaternion The quaternion.
|
|
1292
1292
|
* @returns The transformed vector.
|
|
1293
|
-
|
|
1293
|
+
* @see [Quaternion](https://en.wikipedia.org/wiki/Quaternion)
|
|
1294
1294
|
*/
|
|
1295
1295
|
public transformQuaternion(quaternion: QuaternionLike): Vector3;
|
|
1296
1296
|
|
|
1297
|
-
|
|
1297
|
+
/**
|
|
1298
1298
|
* Transforms this vector by a quaternion.
|
|
1299
1299
|
* @param quaternion The quaternion.
|
|
1300
|
-
|
|
1300
|
+
* @param out The vector to store the result in.
|
|
1301
1301
|
* @returns The transformed vector.
|
|
1302
|
-
|
|
1302
|
+
* @see [Quaternion](https://en.wikipedia.org/wiki/Quaternion)
|
|
1303
1303
|
*/
|
|
1304
1304
|
public transformQuaternion<T extends Vector3Like>(quaternion: QuaternionLike, out: T): T;
|
|
1305
1305
|
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1306
|
+
public transformQuaternion<T extends Vector3Like>(quaternion: QuaternionLike, out: T = new Vector3() as T): T {
|
|
1307
|
+
return transformQuaternion(this, quaternion, out);
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
/**
|
|
1311
|
+
* Creates a quaternion that represents the shortest rotation from this vector to another.
|
|
1312
|
+
* @param vector The other vector.
|
|
1313
|
+
* @returns The rotation.
|
|
1314
|
+
*/
|
|
1315
|
+
public rotationTo(vector: Vector3Like): Quaternion;
|
|
1316
|
+
|
|
1317
|
+
/**
|
|
1318
|
+
* Creates a quaternion that represents the shortest rotation from this unit vector to another.
|
|
1319
|
+
* @param vector The other vector.
|
|
1320
|
+
* @param out The quaternion to store the result in.
|
|
1321
|
+
* @returns The quaternion.
|
|
1322
|
+
*/
|
|
1323
|
+
public rotationTo<T extends QuaternionLike>(vector: Vector3Like, out: T): T;
|
|
1324
|
+
|
|
1325
|
+
public rotationTo<T extends QuaternionLike>(vector: Vector3Like, out: T = new Quaternion() as T): T {
|
|
1326
|
+
return rotationTo(this, vector, out);
|
|
1327
|
+
}
|
|
1328
1328
|
}
|