@lakuna/umath 1.3.5 → 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/dist/algorithms/combinations.d.ts +7 -0
- package/dist/algorithms/combinations.d.ts.map +1 -1
- package/dist/algorithms/combinations.js +7 -0
- 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 +8 -1
- 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 +5 -0
- 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 +2 -0
- 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 +9 -0
- 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 +7 -0
- 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 +7 -0
- package/dist/algorithms/permutations.js.map +1 -1
- package/dist/algorithms/primeFactorization.d.ts +6 -0
- package/dist/algorithms/primeFactorization.d.ts.map +1 -1
- package/dist/algorithms/primeFactorization.js +6 -0
- 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/linalg/DualQuaternion.d.ts +410 -27
- package/dist/linalg/DualQuaternion.d.ts.map +1 -1
- package/dist/linalg/DualQuaternion.js +429 -54
- package/dist/linalg/DualQuaternion.js.map +1 -1
- package/dist/linalg/Matrix.d.ts +67 -0
- package/dist/linalg/Matrix.d.ts.map +1 -1
- package/dist/linalg/Matrix2.d.ts +309 -20
- package/dist/linalg/Matrix2.d.ts.map +1 -1
- package/dist/linalg/Matrix2.js +321 -40
- package/dist/linalg/Matrix2.js.map +1 -1
- package/dist/linalg/Matrix3.d.ts +424 -26
- package/dist/linalg/Matrix3.d.ts.map +1 -1
- package/dist/linalg/Matrix3.js +437 -52
- package/dist/linalg/Matrix3.js.map +1 -1
- package/dist/linalg/Matrix4.d.ts +766 -42
- package/dist/linalg/Matrix4.d.ts.map +1 -1
- package/dist/linalg/Matrix4.js +789 -84
- package/dist/linalg/Matrix4.js.map +1 -1
- package/dist/linalg/Quaternion.d.ts +359 -21
- package/dist/linalg/Quaternion.d.ts.map +1 -1
- package/dist/linalg/Quaternion.js +380 -42
- package/dist/linalg/Quaternion.js.map +1 -1
- package/dist/linalg/SlowMatrix.d.ts +70 -0
- package/dist/linalg/SlowMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowMatrix.js +71 -0
- package/dist/linalg/SlowMatrix.js.map +1 -1
- package/dist/linalg/SlowSquareMatrix.d.ts +55 -0
- package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowSquareMatrix.js +58 -0
- package/dist/linalg/SlowSquareMatrix.js.map +1 -1
- package/dist/linalg/SquareMatrix.d.ts +23 -0
- package/dist/linalg/SquareMatrix.d.ts.map +1 -1
- package/dist/linalg/Vector.d.ts +123 -0
- package/dist/linalg/Vector.d.ts.map +1 -1
- package/dist/linalg/Vector2.d.ts +450 -33
- package/dist/linalg/Vector2.d.ts.map +1 -1
- package/dist/linalg/Vector2.js +480 -66
- package/dist/linalg/Vector2.js.map +1 -1
- package/dist/linalg/Vector3.d.ts +542 -38
- package/dist/linalg/Vector3.d.ts.map +1 -1
- package/dist/linalg/Vector3.js +579 -76
- package/dist/linalg/Vector3.js.map +1 -1
- package/dist/linalg/Vector4.d.ts +416 -30
- package/dist/linalg/Vector4.d.ts.map +1 -1
- package/dist/linalg/Vector4.js +441 -60
- package/dist/linalg/Vector4.js.map +1 -1
- package/dist/types/AxisAngle.d.ts +3 -0
- 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 +36 -0
- package/dist/utility/BigNumber.d.ts.map +1 -1
- package/dist/utility/BigNumber.js +42 -0
- 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 +5 -0
- 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 +1 -1
- package/src/algorithms/combinations.ts +1 -1
- package/src/algorithms/degreesToRadians.ts +1 -1
- package/src/algorithms/factorial.ts +1 -1
- package/src/algorithms/fibonacci.ts +1 -1
- package/src/algorithms/hypergeometricPmf.ts +1 -1
- package/src/algorithms/isPrime.ts +1 -1
- package/src/algorithms/permutations.ts +1 -1
- package/src/algorithms/primeFactorization.ts +1 -1
- package/src/algorithms/radiansToDegrees.ts +1 -1
- package/src/algorithms/summation.ts +1 -1
- package/src/linalg/DualQuaternion.ts +114 -108
- package/src/linalg/Matrix2.ts +82 -69
- package/src/linalg/Matrix3.ts +106 -93
- package/src/linalg/Matrix4.ts +170 -154
- package/src/linalg/Quaternion.ts +95 -91
- package/src/linalg/SlowMatrix.ts +13 -13
- package/src/linalg/SlowSquareMatrix.ts +11 -11
- package/src/linalg/Vector2.ts +129 -115
- package/src/linalg/Vector3.ts +151 -134
- package/src/linalg/Vector4.ts +120 -103
- package/src/utility/BigNumber.ts +7 -7
package/src/linalg/Quaternion.ts
CHANGED
|
@@ -35,9 +35,9 @@ export interface QuaternionLike extends Record<number, number> {
|
|
|
35
35
|
* Create a quaternion-like object.
|
|
36
36
|
* @returns A quaternion-like object.
|
|
37
37
|
*/
|
|
38
|
-
export
|
|
38
|
+
export const createQuaternionLike = () => {
|
|
39
39
|
return new Float32Array(4) as unknown as QuaternionLike;
|
|
40
|
-
}
|
|
40
|
+
};
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Create a quaternion from a three-by-three rotation matrix.
|
|
@@ -46,10 +46,10 @@ export function createQuaternionLike() {
|
|
|
46
46
|
* @returns The quaternion.
|
|
47
47
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
48
48
|
*/
|
|
49
|
-
export
|
|
49
|
+
export const fromMatrix3 = <T extends QuaternionLike>(
|
|
50
50
|
matrix: Matrix3Like,
|
|
51
51
|
out: T
|
|
52
|
-
) {
|
|
52
|
+
): T => {
|
|
53
53
|
const fTrace = matrix[0] + matrix[4] + matrix[8];
|
|
54
54
|
if (fTrace > 0) {
|
|
55
55
|
let fRoot = Math.sqrt(fTrace + 1);
|
|
@@ -89,7 +89,7 @@ export function fromMatrix3<T extends QuaternionLike>(
|
|
|
89
89
|
(matrix[(k * 3 + i) as 6 | 1 | 5] + matrix[(i * 3 + k) as 2 | 3 | 7]) *
|
|
90
90
|
fRoot;
|
|
91
91
|
return out;
|
|
92
|
-
}
|
|
92
|
+
};
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
95
|
* Create a quaternion from equivalent X-Y-Z Tait-Bryan angles
|
|
@@ -100,12 +100,12 @@ export function fromMatrix3<T extends QuaternionLike>(
|
|
|
100
100
|
* @returns The quaternion.
|
|
101
101
|
* @see [Euler angles](https://en.wikipedia.org/wiki/Euler_angles)
|
|
102
102
|
*/
|
|
103
|
-
export
|
|
103
|
+
export const fromEuler = <T extends QuaternionLike>(
|
|
104
104
|
x: number,
|
|
105
105
|
y: number,
|
|
106
106
|
z: number,
|
|
107
107
|
out: T
|
|
108
|
-
) {
|
|
108
|
+
): T => {
|
|
109
109
|
const r = (0.5 * Math.PI) / 180;
|
|
110
110
|
|
|
111
111
|
const x2 = x * r;
|
|
@@ -124,7 +124,7 @@ export function fromEuler<T extends QuaternionLike>(
|
|
|
124
124
|
out[2] = cx * cy * sz - sx * sy * cz;
|
|
125
125
|
out[3] = cx * cy * cz + sx * sy * sz;
|
|
126
126
|
return out;
|
|
127
|
-
}
|
|
127
|
+
};
|
|
128
128
|
|
|
129
129
|
// Stores intermediary values for some functions.
|
|
130
130
|
const intermediary = createMatrix3Like();
|
|
@@ -137,12 +137,12 @@ const intermediary = createMatrix3Like();
|
|
|
137
137
|
* @param out - The quaternion to store the result in.
|
|
138
138
|
* @returns The quaternion.
|
|
139
139
|
*/
|
|
140
|
-
export
|
|
140
|
+
export const fromAxes = <T extends QuaternionLike>(
|
|
141
141
|
view: Vector3Like,
|
|
142
142
|
right: Vector3Like,
|
|
143
143
|
up: Vector3Like,
|
|
144
144
|
out: T
|
|
145
|
-
) {
|
|
145
|
+
): T => {
|
|
146
146
|
intermediary[0] = right[0];
|
|
147
147
|
intermediary[3] = right[1];
|
|
148
148
|
intermediary[6] = right[2];
|
|
@@ -153,20 +153,20 @@ export function fromAxes<T extends QuaternionLike>(
|
|
|
153
153
|
intermediary[5] = -view[1];
|
|
154
154
|
intermediary[8] = -view[2];
|
|
155
155
|
return normalize(fromMatrix3(intermediary, out), out);
|
|
156
|
-
}
|
|
156
|
+
};
|
|
157
157
|
|
|
158
158
|
/**
|
|
159
159
|
* Set a quaternion to the identity.
|
|
160
160
|
* @param out - The quaternion to store the result in.
|
|
161
161
|
* @returns This quaternion.
|
|
162
162
|
*/
|
|
163
|
-
export
|
|
163
|
+
export const identity = <T extends QuaternionLike>(out: T): T => {
|
|
164
164
|
out[0] = 0;
|
|
165
165
|
out[1] = 0;
|
|
166
166
|
out[2] = 0;
|
|
167
167
|
out[3] = 1;
|
|
168
168
|
return out;
|
|
169
|
-
}
|
|
169
|
+
};
|
|
170
170
|
|
|
171
171
|
/**
|
|
172
172
|
* Calculate the axis and angle that represent a quaternion.
|
|
@@ -174,10 +174,10 @@ export function identity<T extends QuaternionLike>(out: T) {
|
|
|
174
174
|
* @param out - The axis and angle to store the result in.
|
|
175
175
|
* @returns The axis and angle.
|
|
176
176
|
*/
|
|
177
|
-
export
|
|
177
|
+
export const getAxisAngle = <T extends AxisAngle>(
|
|
178
178
|
quaternion: QuaternionLike,
|
|
179
179
|
out: T
|
|
180
|
-
) {
|
|
180
|
+
): T => {
|
|
181
181
|
const r = Math.acos(quaternion[3]) * 2;
|
|
182
182
|
const s = Math.sin(r / 2);
|
|
183
183
|
|
|
@@ -187,7 +187,7 @@ export function getAxisAngle<T extends AxisAngle>(
|
|
|
187
187
|
: [1, 0, 0];
|
|
188
188
|
out.angle = r;
|
|
189
189
|
return out;
|
|
190
|
-
}
|
|
190
|
+
};
|
|
191
191
|
|
|
192
192
|
/**
|
|
193
193
|
* Set the axis and angle that represent a quaternion.
|
|
@@ -195,10 +195,10 @@ export function getAxisAngle<T extends AxisAngle>(
|
|
|
195
195
|
* @param out - The quaternion to store the result in.
|
|
196
196
|
* @returns The quaternion.
|
|
197
197
|
*/
|
|
198
|
-
export
|
|
198
|
+
export const setAxisAngle = <T extends QuaternionLike>(
|
|
199
199
|
axisAngle: AxisAngle,
|
|
200
200
|
out: T
|
|
201
|
-
) {
|
|
201
|
+
): T => {
|
|
202
202
|
const r = axisAngle.angle * 0.5;
|
|
203
203
|
const s = Math.sin(r);
|
|
204
204
|
|
|
@@ -207,7 +207,7 @@ export function setAxisAngle<T extends QuaternionLike>(
|
|
|
207
207
|
out[2] = s * axisAngle.axis[2];
|
|
208
208
|
out[3] = Math.cos(r);
|
|
209
209
|
return out;
|
|
210
|
-
}
|
|
210
|
+
};
|
|
211
211
|
|
|
212
212
|
/**
|
|
213
213
|
* Get the angular distance between two unit quaternions.
|
|
@@ -215,10 +215,10 @@ export function setAxisAngle<T extends QuaternionLike>(
|
|
|
215
215
|
* @param b - The second unit quaternion.
|
|
216
216
|
* @returns The angular distance in radians.
|
|
217
217
|
*/
|
|
218
|
-
export
|
|
218
|
+
export const getAngle = (a: QuaternionLike, b: QuaternionLike): number => {
|
|
219
219
|
const dp = dot(a, b);
|
|
220
220
|
return Math.acos(2 * dp * dp - 1);
|
|
221
|
-
}
|
|
221
|
+
};
|
|
222
222
|
|
|
223
223
|
/**
|
|
224
224
|
* Multiply two quaternions.
|
|
@@ -227,11 +227,11 @@ export function getAngle(a: QuaternionLike, b: QuaternionLike) {
|
|
|
227
227
|
* @param out - The quaternion to store the result in.
|
|
228
228
|
* @returns The product.
|
|
229
229
|
*/
|
|
230
|
-
export
|
|
230
|
+
export const multiply = <T extends QuaternionLike>(
|
|
231
231
|
a: QuaternionLike,
|
|
232
232
|
b: QuaternionLike,
|
|
233
233
|
out: T
|
|
234
|
-
) {
|
|
234
|
+
): T => {
|
|
235
235
|
const ax = a[0];
|
|
236
236
|
const ay = a[1];
|
|
237
237
|
const az = a[2];
|
|
@@ -247,7 +247,7 @@ export function multiply<T extends QuaternionLike>(
|
|
|
247
247
|
out[2] = az * bw + aw * bz + ax * by - ay * bx;
|
|
248
248
|
out[3] = aw * bw - ax * bx - ay * by - az * bz;
|
|
249
249
|
return out;
|
|
250
|
-
}
|
|
250
|
+
};
|
|
251
251
|
|
|
252
252
|
/**
|
|
253
253
|
* Rotate a quaternion by the given angle around the X-axis.
|
|
@@ -256,11 +256,11 @@ export function multiply<T extends QuaternionLike>(
|
|
|
256
256
|
* @param out - The quaternion to store the result in.
|
|
257
257
|
* @returns The rotated quaternion.
|
|
258
258
|
*/
|
|
259
|
-
export
|
|
259
|
+
export const rotateX = <T extends QuaternionLike>(
|
|
260
260
|
quaternion: QuaternionLike,
|
|
261
261
|
radians: number,
|
|
262
262
|
out: T
|
|
263
|
-
) {
|
|
263
|
+
): T => {
|
|
264
264
|
const r = radians * 0.5;
|
|
265
265
|
|
|
266
266
|
const ax = quaternion[0];
|
|
@@ -276,7 +276,7 @@ export function rotateX<T extends QuaternionLike>(
|
|
|
276
276
|
out[2] = az * bw - ay * bx;
|
|
277
277
|
out[3] = aw * bw - ax * bx;
|
|
278
278
|
return out;
|
|
279
|
-
}
|
|
279
|
+
};
|
|
280
280
|
|
|
281
281
|
/**
|
|
282
282
|
* Rotate a quaternion by the given angle around the Y-axis.
|
|
@@ -285,11 +285,11 @@ export function rotateX<T extends QuaternionLike>(
|
|
|
285
285
|
* @param out - The quaternion to store the result in.
|
|
286
286
|
* @returns The rotated quaternion.
|
|
287
287
|
*/
|
|
288
|
-
export
|
|
288
|
+
export const rotateY = <T extends QuaternionLike>(
|
|
289
289
|
quaternion: QuaternionLike,
|
|
290
290
|
radians: number,
|
|
291
291
|
out: T
|
|
292
|
-
) {
|
|
292
|
+
): T => {
|
|
293
293
|
const r = radians * 0.5;
|
|
294
294
|
|
|
295
295
|
const ax = quaternion[0];
|
|
@@ -305,7 +305,7 @@ export function rotateY<T extends QuaternionLike>(
|
|
|
305
305
|
out[2] = az * bw + ax * by;
|
|
306
306
|
out[3] = aw * bw - ay * by;
|
|
307
307
|
return out;
|
|
308
|
-
}
|
|
308
|
+
};
|
|
309
309
|
|
|
310
310
|
/**
|
|
311
311
|
* Rotate a quaternion by the given angle around the Z-axis.
|
|
@@ -314,11 +314,11 @@ export function rotateY<T extends QuaternionLike>(
|
|
|
314
314
|
* @param out - The quaternion to store the result in.
|
|
315
315
|
* @returns The rotated quaternion.
|
|
316
316
|
*/
|
|
317
|
-
export
|
|
317
|
+
export const rotateZ = <T extends QuaternionLike>(
|
|
318
318
|
quaternion: QuaternionLike,
|
|
319
319
|
radians: number,
|
|
320
320
|
out: T
|
|
321
|
-
) {
|
|
321
|
+
): T => {
|
|
322
322
|
const r = radians * 0.5;
|
|
323
323
|
|
|
324
324
|
const ax = quaternion[0];
|
|
@@ -334,7 +334,7 @@ export function rotateZ<T extends QuaternionLike>(
|
|
|
334
334
|
out[2] = az * bw + aw * bz;
|
|
335
335
|
out[3] = aw * bw - az * bz;
|
|
336
336
|
return out;
|
|
337
|
-
}
|
|
337
|
+
};
|
|
338
338
|
|
|
339
339
|
/**
|
|
340
340
|
* Calculate the fourth component of a unit quaternion from the first three, ignoring the existing fourth component.
|
|
@@ -342,10 +342,10 @@ export function rotateZ<T extends QuaternionLike>(
|
|
|
342
342
|
* @param out - The quaternion to store the result in.
|
|
343
343
|
* @returns The quaternion.
|
|
344
344
|
*/
|
|
345
|
-
export
|
|
345
|
+
export const calculateW = <T extends QuaternionLike>(
|
|
346
346
|
quaternion: QuaternionLike,
|
|
347
347
|
out: T
|
|
348
|
-
) {
|
|
348
|
+
): T => {
|
|
349
349
|
const x = quaternion[0];
|
|
350
350
|
const y = quaternion[1];
|
|
351
351
|
const z = quaternion[2];
|
|
@@ -355,7 +355,7 @@ export function calculateW<T extends QuaternionLike>(
|
|
|
355
355
|
out[2] = z;
|
|
356
356
|
out[3] = Math.sqrt(Math.abs(1 - x * x - y * y - z * z));
|
|
357
357
|
return out;
|
|
358
|
-
}
|
|
358
|
+
};
|
|
359
359
|
|
|
360
360
|
/**
|
|
361
361
|
* Calculate the exponential of a unit quaternion.
|
|
@@ -363,10 +363,10 @@ export function calculateW<T extends QuaternionLike>(
|
|
|
363
363
|
* @param out - The quaternion to store the result in.
|
|
364
364
|
* @returns The exponential.
|
|
365
365
|
*/
|
|
366
|
-
export
|
|
366
|
+
export const exp = <T extends QuaternionLike>(
|
|
367
367
|
quaternion: QuaternionLike,
|
|
368
368
|
out: T
|
|
369
|
-
) {
|
|
369
|
+
): T => {
|
|
370
370
|
const x = quaternion[0];
|
|
371
371
|
const y = quaternion[1];
|
|
372
372
|
const z = quaternion[2];
|
|
@@ -381,7 +381,7 @@ export function exp<T extends QuaternionLike>(
|
|
|
381
381
|
out[2] = z * s;
|
|
382
382
|
out[3] = et * Math.cos(r);
|
|
383
383
|
return out;
|
|
384
|
-
}
|
|
384
|
+
};
|
|
385
385
|
|
|
386
386
|
/**
|
|
387
387
|
* Calculate the natural logarithm of a unit quaternion.
|
|
@@ -389,10 +389,10 @@ export function exp<T extends QuaternionLike>(
|
|
|
389
389
|
* @param out - The quaternion to store the result in.
|
|
390
390
|
* @returns The natural logarithm.
|
|
391
391
|
*/
|
|
392
|
-
export
|
|
392
|
+
export const ln = <T extends QuaternionLike>(
|
|
393
393
|
quaternion: QuaternionLike,
|
|
394
394
|
out: T
|
|
395
|
-
) {
|
|
395
|
+
): T => {
|
|
396
396
|
const x = quaternion[0];
|
|
397
397
|
const y = quaternion[1];
|
|
398
398
|
const z = quaternion[2];
|
|
@@ -406,7 +406,7 @@ export function ln<T extends QuaternionLike>(
|
|
|
406
406
|
out[2] = z * t;
|
|
407
407
|
out[3] = 0.5 * Math.log(x * x + y * y + z * z + w * w);
|
|
408
408
|
return out;
|
|
409
|
-
}
|
|
409
|
+
};
|
|
410
410
|
|
|
411
411
|
/**
|
|
412
412
|
* Calculate a power of a unit quaternion.
|
|
@@ -415,13 +415,13 @@ export function ln<T extends QuaternionLike>(
|
|
|
415
415
|
* @param out - The quaternion to store the result in.
|
|
416
416
|
* @returns The power.
|
|
417
417
|
*/
|
|
418
|
-
export
|
|
418
|
+
export const pow = <T extends QuaternionLike>(
|
|
419
419
|
quaternion: QuaternionLike,
|
|
420
420
|
scalar: number,
|
|
421
421
|
out: T
|
|
422
|
-
) {
|
|
422
|
+
): T => {
|
|
423
423
|
return exp(scale(ln(quaternion, out), scalar, out), out);
|
|
424
|
-
}
|
|
424
|
+
};
|
|
425
425
|
|
|
426
426
|
/**
|
|
427
427
|
* Perform a spherical linear interpolation between two quaternions.
|
|
@@ -432,12 +432,12 @@ export function pow<T extends QuaternionLike>(
|
|
|
432
432
|
* @returns The interpolated quaternion.
|
|
433
433
|
* @see [Slerp](https://en.wikipedia.org/wiki/Slerp)
|
|
434
434
|
*/
|
|
435
|
-
export
|
|
435
|
+
export const slerp = <T extends QuaternionLike>(
|
|
436
436
|
a: QuaternionLike,
|
|
437
437
|
b: QuaternionLike,
|
|
438
438
|
t: number,
|
|
439
439
|
out: T
|
|
440
|
-
) {
|
|
440
|
+
): T => {
|
|
441
441
|
const ax = a[0];
|
|
442
442
|
const ay = a[1];
|
|
443
443
|
const az = a[2];
|
|
@@ -477,14 +477,14 @@ export function slerp<T extends QuaternionLike>(
|
|
|
477
477
|
out[2] = scale0 * az + scale1 * bz;
|
|
478
478
|
out[3] = scale0 * aw + scale1 * bw;
|
|
479
479
|
return out;
|
|
480
|
-
}
|
|
480
|
+
};
|
|
481
481
|
|
|
482
482
|
/**
|
|
483
483
|
* Set a quaternion to a random unit quaternion.
|
|
484
484
|
* @param out - The quaternion to store the result in.
|
|
485
485
|
* @returns The quaternion.
|
|
486
486
|
*/
|
|
487
|
-
export
|
|
487
|
+
export const random = <T extends QuaternionLike>(out: T): T => {
|
|
488
488
|
const u1 = Math.random();
|
|
489
489
|
const u2 = Math.random();
|
|
490
490
|
const u3 = Math.random();
|
|
@@ -497,7 +497,7 @@ export function random<T extends QuaternionLike>(out: T) {
|
|
|
497
497
|
out[2] = sqrtU1 * Math.sin(2 * Math.PI * u3);
|
|
498
498
|
out[3] = sqrtU1 * Math.cos(2 * Math.PI * u3);
|
|
499
499
|
return out;
|
|
500
|
-
}
|
|
500
|
+
};
|
|
501
501
|
|
|
502
502
|
/**
|
|
503
503
|
* Calculate the inverse of a quaternion. If the quaternion is normalized, the conjugate is the same but faster to calculate.
|
|
@@ -505,10 +505,10 @@ export function random<T extends QuaternionLike>(out: T) {
|
|
|
505
505
|
* @param out - The quaternion to store the result in.
|
|
506
506
|
* @returns The inverse.
|
|
507
507
|
*/
|
|
508
|
-
export
|
|
508
|
+
export const invert = <T extends QuaternionLike>(
|
|
509
509
|
quaternion: QuaternionLike,
|
|
510
510
|
out: T
|
|
511
|
-
) {
|
|
511
|
+
): T => {
|
|
512
512
|
const a0 = quaternion[0];
|
|
513
513
|
const a1 = quaternion[1];
|
|
514
514
|
const a2 = quaternion[2];
|
|
@@ -530,7 +530,7 @@ export function invert<T extends QuaternionLike>(
|
|
|
530
530
|
out[2] = -a2 * invDot;
|
|
531
531
|
out[3] = a3 * invDot;
|
|
532
532
|
return out;
|
|
533
|
-
}
|
|
533
|
+
};
|
|
534
534
|
|
|
535
535
|
/**
|
|
536
536
|
* Calculate the conjugate of a quaternion. If the quaternion is normalized, this is the same as the inverse but faster to calculate.
|
|
@@ -538,16 +538,16 @@ export function invert<T extends QuaternionLike>(
|
|
|
538
538
|
* @param out - The quaternion to store the result in.
|
|
539
539
|
* @returns The conjugate.
|
|
540
540
|
*/
|
|
541
|
-
export
|
|
541
|
+
export const conjugate = <T extends QuaternionLike>(
|
|
542
542
|
quaternion: QuaternionLike,
|
|
543
543
|
out: T
|
|
544
|
-
) {
|
|
544
|
+
): T => {
|
|
545
545
|
out[0] = -quaternion[0];
|
|
546
546
|
out[1] = -quaternion[1];
|
|
547
547
|
out[2] = -quaternion[2];
|
|
548
548
|
out[3] = quaternion[3];
|
|
549
549
|
return out;
|
|
550
|
-
}
|
|
550
|
+
};
|
|
551
551
|
|
|
552
552
|
// Used to store intermediate values for some functions.
|
|
553
553
|
const controlPointOne = createQuaternionLike();
|
|
@@ -564,18 +564,18 @@ const controlPointTwo = createQuaternionLike();
|
|
|
564
564
|
* @returns The interpolated value.
|
|
565
565
|
* @see [Slerp](https://en.wikipedia.org/wiki/Slerp)
|
|
566
566
|
*/
|
|
567
|
-
export
|
|
567
|
+
export const sqlerp = <T extends QuaternionLike>(
|
|
568
568
|
a: QuaternionLike,
|
|
569
569
|
b: QuaternionLike,
|
|
570
570
|
c: QuaternionLike,
|
|
571
571
|
d: QuaternionLike,
|
|
572
572
|
t: number,
|
|
573
573
|
out: T
|
|
574
|
-
) {
|
|
574
|
+
): T => {
|
|
575
575
|
slerp(a, d, t, controlPointOne);
|
|
576
576
|
slerp(b, c, t, controlPointTwo);
|
|
577
577
|
return slerp(controlPointOne, controlPointTwo, 2 * t * (1 - t), out);
|
|
578
|
-
}
|
|
578
|
+
};
|
|
579
579
|
|
|
580
580
|
/**
|
|
581
581
|
* A complex number that is commonly used to describe rotations.
|
|
@@ -592,7 +592,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
592
592
|
public static fromMatrix3<T extends QuaternionLike>(
|
|
593
593
|
matrix: Matrix3Like,
|
|
594
594
|
out = new Quaternion() as unknown as T
|
|
595
|
-
) {
|
|
595
|
+
): T {
|
|
596
596
|
return fromMatrix3(matrix, out);
|
|
597
597
|
}
|
|
598
598
|
|
|
@@ -610,7 +610,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
610
610
|
y: number,
|
|
611
611
|
z: number,
|
|
612
612
|
out = new Quaternion() as unknown as T
|
|
613
|
-
) {
|
|
613
|
+
): T {
|
|
614
614
|
return fromEuler(x, y, z, out);
|
|
615
615
|
}
|
|
616
616
|
|
|
@@ -629,7 +629,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
629
629
|
z: number,
|
|
630
630
|
w: number,
|
|
631
631
|
out = new Quaternion() as unknown as T
|
|
632
|
-
) {
|
|
632
|
+
): T {
|
|
633
633
|
return fromValues(x, y, z, w, out);
|
|
634
634
|
}
|
|
635
635
|
|
|
@@ -646,7 +646,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
646
646
|
right: Vector3Like,
|
|
647
647
|
up: Vector3Like,
|
|
648
648
|
out = new Quaternion() as unknown as T
|
|
649
|
-
) {
|
|
649
|
+
): T {
|
|
650
650
|
return fromAxes(view, right, up, out);
|
|
651
651
|
}
|
|
652
652
|
|
|
@@ -675,7 +675,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
675
675
|
* Set this quaternion to the identity.
|
|
676
676
|
* @returns This quaternion.
|
|
677
677
|
*/
|
|
678
|
-
public identity() {
|
|
678
|
+
public identity(): this {
|
|
679
679
|
return identity(this);
|
|
680
680
|
}
|
|
681
681
|
|
|
@@ -684,7 +684,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
684
684
|
* @param out - The axis and angle to store the result in.
|
|
685
685
|
* @returns The axis and angle.
|
|
686
686
|
*/
|
|
687
|
-
public getAxisAngle<T extends AxisAngle>(out = {} as T) {
|
|
687
|
+
public getAxisAngle<T extends AxisAngle>(out = {} as T): T {
|
|
688
688
|
return getAxisAngle(this, out);
|
|
689
689
|
}
|
|
690
690
|
|
|
@@ -693,7 +693,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
693
693
|
* @param axisAngle - The axis and angle.
|
|
694
694
|
* @returns This quaternion.
|
|
695
695
|
*/
|
|
696
|
-
public setAxisAngle(axisAngle: AxisAngle) {
|
|
696
|
+
public setAxisAngle(axisAngle: AxisAngle): this {
|
|
697
697
|
return setAxisAngle(axisAngle, this);
|
|
698
698
|
}
|
|
699
699
|
|
|
@@ -702,7 +702,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
702
702
|
* @param quaternion - The other unit quaternion.
|
|
703
703
|
* @returns The angular distance in radians.
|
|
704
704
|
*/
|
|
705
|
-
public getAngle(quaternion: QuaternionLike) {
|
|
705
|
+
public getAngle(quaternion: QuaternionLike): number {
|
|
706
706
|
return getAngle(this, quaternion);
|
|
707
707
|
}
|
|
708
708
|
|
|
@@ -715,7 +715,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
715
715
|
public multiply<T extends QuaternionLike>(
|
|
716
716
|
quaternion: QuaternionLike,
|
|
717
717
|
out = new Quaternion() as unknown as T
|
|
718
|
-
) {
|
|
718
|
+
): T {
|
|
719
719
|
return multiply(this, quaternion, out);
|
|
720
720
|
}
|
|
721
721
|
|
|
@@ -728,7 +728,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
728
728
|
public rotateX<T extends QuaternionLike>(
|
|
729
729
|
r: number,
|
|
730
730
|
out = new Quaternion() as unknown as T
|
|
731
|
-
) {
|
|
731
|
+
): T {
|
|
732
732
|
return rotateX(this, r, out);
|
|
733
733
|
}
|
|
734
734
|
|
|
@@ -741,7 +741,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
741
741
|
public rotateY<T extends QuaternionLike>(
|
|
742
742
|
r: number,
|
|
743
743
|
out = new Quaternion() as unknown as T
|
|
744
|
-
) {
|
|
744
|
+
): T {
|
|
745
745
|
return rotateY(this, r, out);
|
|
746
746
|
}
|
|
747
747
|
|
|
@@ -754,7 +754,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
754
754
|
public rotateZ<T extends QuaternionLike>(
|
|
755
755
|
r: number,
|
|
756
756
|
out = new Quaternion() as unknown as T
|
|
757
|
-
) {
|
|
757
|
+
): T {
|
|
758
758
|
return rotateZ(this, r, out);
|
|
759
759
|
}
|
|
760
760
|
|
|
@@ -765,7 +765,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
765
765
|
*/
|
|
766
766
|
public calculateW<T extends QuaternionLike>(
|
|
767
767
|
out = new Quaternion() as unknown as T
|
|
768
|
-
) {
|
|
768
|
+
): T {
|
|
769
769
|
return calculateW(this, out);
|
|
770
770
|
}
|
|
771
771
|
|
|
@@ -774,7 +774,9 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
774
774
|
* @param out - The quaternion to store the result in.
|
|
775
775
|
* @returns The exponential.
|
|
776
776
|
*/
|
|
777
|
-
public exp<T extends QuaternionLike>(
|
|
777
|
+
public exp<T extends QuaternionLike>(
|
|
778
|
+
out = new Quaternion() as unknown as T
|
|
779
|
+
): T {
|
|
778
780
|
return exp(this, out);
|
|
779
781
|
}
|
|
780
782
|
|
|
@@ -783,7 +785,9 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
783
785
|
* @param out - The quaternion to store the result in.
|
|
784
786
|
* @returns The natural logarithm.
|
|
785
787
|
*/
|
|
786
|
-
public ln<T extends QuaternionLike>(
|
|
788
|
+
public ln<T extends QuaternionLike>(
|
|
789
|
+
out = new Quaternion() as unknown as T
|
|
790
|
+
): T {
|
|
787
791
|
return ln(this, out);
|
|
788
792
|
}
|
|
789
793
|
|
|
@@ -796,7 +800,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
796
800
|
public pow<T extends QuaternionLike>(
|
|
797
801
|
scalar: number,
|
|
798
802
|
out = new Quaternion() as unknown as T
|
|
799
|
-
) {
|
|
803
|
+
): T {
|
|
800
804
|
return pow(this, scalar, out);
|
|
801
805
|
}
|
|
802
806
|
|
|
@@ -812,7 +816,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
812
816
|
quaternion: QuaternionLike,
|
|
813
817
|
t: number,
|
|
814
818
|
out = new Quaternion() as unknown as T
|
|
815
|
-
) {
|
|
819
|
+
): T {
|
|
816
820
|
return slerp(this, quaternion, t, out);
|
|
817
821
|
}
|
|
818
822
|
|
|
@@ -820,7 +824,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
820
824
|
* Set this to a random unit quaternion.
|
|
821
825
|
* @returns A random unit quaternion.
|
|
822
826
|
*/
|
|
823
|
-
public random() {
|
|
827
|
+
public random(): this {
|
|
824
828
|
return random(this);
|
|
825
829
|
}
|
|
826
830
|
|
|
@@ -831,7 +835,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
831
835
|
*/
|
|
832
836
|
public invert<T extends QuaternionLike>(
|
|
833
837
|
out = new Quaternion() as unknown as T
|
|
834
|
-
) {
|
|
838
|
+
): T {
|
|
835
839
|
return invert(this, out);
|
|
836
840
|
}
|
|
837
841
|
|
|
@@ -842,7 +846,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
842
846
|
*/
|
|
843
847
|
public conjugate<T extends QuaternionLike>(
|
|
844
848
|
out = new Quaternion() as unknown as T
|
|
845
|
-
) {
|
|
849
|
+
): T {
|
|
846
850
|
return conjugate(this, out);
|
|
847
851
|
}
|
|
848
852
|
|
|
@@ -853,7 +857,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
853
857
|
*/
|
|
854
858
|
public clone<T extends QuaternionLike>(
|
|
855
859
|
out = new Quaternion() as unknown as T
|
|
856
|
-
) {
|
|
860
|
+
): T {
|
|
857
861
|
return copy(this, out);
|
|
858
862
|
}
|
|
859
863
|
|
|
@@ -862,7 +866,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
862
866
|
* @param quaternion - The quaternion to copy.
|
|
863
867
|
* @returns This quaternion.
|
|
864
868
|
*/
|
|
865
|
-
public copy(quaternion: QuaternionLike) {
|
|
869
|
+
public copy(quaternion: QuaternionLike): this {
|
|
866
870
|
return copy(quaternion, this);
|
|
867
871
|
}
|
|
868
872
|
|
|
@@ -875,7 +879,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
875
879
|
public add<T extends QuaternionLike>(
|
|
876
880
|
quaternion: QuaternionLike,
|
|
877
881
|
out = new Quaternion() as unknown as T
|
|
878
|
-
) {
|
|
882
|
+
): T {
|
|
879
883
|
return add(this, quaternion, out);
|
|
880
884
|
}
|
|
881
885
|
|
|
@@ -888,7 +892,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
888
892
|
public scale<T extends QuaternionLike>(
|
|
889
893
|
scalar: number,
|
|
890
894
|
out = new Quaternion() as unknown as T
|
|
891
|
-
) {
|
|
895
|
+
): T {
|
|
892
896
|
return scale(this, scalar, out);
|
|
893
897
|
}
|
|
894
898
|
|
|
@@ -897,7 +901,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
897
901
|
* @param quaternion - The other quaternion.
|
|
898
902
|
* @returns The dot product.
|
|
899
903
|
*/
|
|
900
|
-
public dot(quaternion: QuaternionLike) {
|
|
904
|
+
public dot(quaternion: QuaternionLike): number {
|
|
901
905
|
return dot(this, quaternion);
|
|
902
906
|
}
|
|
903
907
|
|
|
@@ -912,17 +916,17 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
912
916
|
quaternion: QuaternionLike,
|
|
913
917
|
t: number,
|
|
914
918
|
out = new Quaternion() as unknown as T
|
|
915
|
-
) {
|
|
919
|
+
): T {
|
|
916
920
|
return lerp(this, quaternion, t, out);
|
|
917
921
|
}
|
|
918
922
|
|
|
919
923
|
/** Get the magnitude (length) of this quaternion. */
|
|
920
|
-
public get magnitude() {
|
|
924
|
+
public get magnitude(): number {
|
|
921
925
|
return getMagnitude(this);
|
|
922
926
|
}
|
|
923
927
|
|
|
924
928
|
/** Get the squared magnitude (length) of this quaternion. */
|
|
925
|
-
public get squaredMagnitude() {
|
|
929
|
+
public get squaredMagnitude(): number {
|
|
926
930
|
return getSquaredMagnitude(this);
|
|
927
931
|
}
|
|
928
932
|
|
|
@@ -933,7 +937,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
933
937
|
*/
|
|
934
938
|
public normalize<T extends QuaternionLike>(
|
|
935
939
|
out = new Quaternion() as unknown as T
|
|
936
|
-
) {
|
|
940
|
+
): T {
|
|
937
941
|
return normalize(this, out);
|
|
938
942
|
}
|
|
939
943
|
|
|
@@ -942,7 +946,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
942
946
|
* @param quaternion - The other quaternion.
|
|
943
947
|
* @returns Whether or not the quaternions are equivalent.
|
|
944
948
|
*/
|
|
945
|
-
public equals(quaternion: QuaternionLike) {
|
|
949
|
+
public equals(quaternion: QuaternionLike): boolean {
|
|
946
950
|
return equals(this, quaternion);
|
|
947
951
|
}
|
|
948
952
|
|
|
@@ -951,7 +955,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
951
955
|
* @param quaternion - The other quaternion.
|
|
952
956
|
* @returns Whether or not the quaternions are equivalent.
|
|
953
957
|
*/
|
|
954
|
-
public exactEquals(quaternion: QuaternionLike) {
|
|
958
|
+
public exactEquals(quaternion: QuaternionLike): boolean {
|
|
955
959
|
return exactEquals(this, quaternion);
|
|
956
960
|
}
|
|
957
961
|
|
|
@@ -971,7 +975,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
971
975
|
quaternion: QuaternionLike,
|
|
972
976
|
t: number,
|
|
973
977
|
out = new Quaternion() as unknown as T
|
|
974
|
-
) {
|
|
978
|
+
): T {
|
|
975
979
|
return sqlerp(this, a, b, quaternion, t, out);
|
|
976
980
|
}
|
|
977
981
|
}
|