@math.gl/core 4.2.0-alpha.6 → 5.0.0-alpha.2
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/dist/classes/base/math-array.d.ts +0 -18
- package/dist/classes/base/math-array.d.ts.map +1 -1
- package/dist/classes/base/math-array.js +0 -51
- package/dist/classes/base/math-array.js.map +1 -1
- package/dist/classes/base/vector.d.ts.map +1 -1
- package/dist/classes/base/vector.js +4 -2
- package/dist/classes/base/vector.js.map +1 -1
- package/dist/classes/euler-types.d.ts +10 -0
- package/dist/classes/euler-types.d.ts.map +1 -0
- package/dist/classes/euler-types.js +5 -0
- package/dist/classes/euler-types.js.map +1 -0
- package/dist/classes/euler.d.ts +4 -36
- package/dist/classes/euler.d.ts.map +1 -1
- package/dist/classes/euler.js +8 -102
- package/dist/classes/euler.js.map +1 -1
- package/dist/classes/matrix3.d.ts +2 -8
- package/dist/classes/matrix3.d.ts.map +1 -1
- package/dist/classes/matrix3.js +5 -16
- package/dist/classes/matrix3.js.map +1 -1
- package/dist/classes/matrix4.d.ts +7 -6
- package/dist/classes/matrix4.d.ts.map +1 -1
- package/dist/classes/matrix4.js +8 -12
- package/dist/classes/matrix4.js.map +1 -1
- package/dist/classes/quaternion.d.ts +7 -6
- package/dist/classes/quaternion.d.ts.map +1 -1
- package/dist/classes/quaternion.js +25 -17
- package/dist/classes/quaternion.js.map +1 -1
- package/dist/classes/spherical-coordinates.d.ts +3 -4
- package/dist/classes/spherical-coordinates.d.ts.map +1 -1
- package/dist/classes/spherical-coordinates.js +10 -8
- package/dist/classes/spherical-coordinates.js.map +1 -1
- package/dist/gl-matrix/quat.js +3 -3
- package/dist/gl-matrix/quat.js.map +1 -1
- package/dist/gl-matrix/vec2.js +1 -1
- package/dist/gl-matrix/vec2.js.map +1 -1
- package/dist/gl-matrix/vec3.js +1 -1
- package/dist/gl-matrix/vec3.js.map +1 -1
- package/dist/gl-matrix/vec4.js +1 -1
- package/dist/gl-matrix/vec4.js.map +1 -1
- package/dist/index.cjs +223 -2554
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +2 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -17
- package/dist/index.js.map +1 -1
- package/dist/lib/common.d.ts +0 -30
- package/dist/lib/common.d.ts.map +1 -1
- package/dist/lib/common.js +0 -42
- package/dist/lib/common.js.map +1 -1
- package/dist/lib/validators.d.ts +0 -1
- package/dist/lib/validators.d.ts.map +1 -1
- package/dist/lib/validators.js +0 -8
- package/dist/lib/validators.js.map +1 -1
- package/dist/mat3.cjs +543 -0
- package/dist/mat3.cjs.map +6 -0
- package/dist/mat3.d.ts +2 -0
- package/dist/mat3.d.ts.map +1 -0
- package/dist/mat3.js +5 -0
- package/dist/mat3.js.map +1 -0
- package/dist/mat4.cjs +1497 -0
- package/dist/mat4.cjs.map +6 -0
- package/dist/mat4.d.ts +2 -0
- package/dist/mat4.d.ts.map +1 -0
- package/dist/mat4.js +5 -0
- package/dist/mat4.js.map +1 -0
- package/dist/quat.cjs +532 -0
- package/dist/quat.cjs.map +6 -0
- package/dist/quat.d.ts +2 -0
- package/dist/quat.d.ts.map +1 -0
- package/dist/quat.js +5 -0
- package/dist/quat.js.map +1 -0
- package/dist/vec2.cjs +328 -0
- package/dist/vec2.cjs.map +6 -0
- package/dist/vec2.d.ts +2 -0
- package/dist/vec2.d.ts.map +1 -0
- package/dist/vec2.js +5 -0
- package/dist/vec2.js.map +1 -0
- package/dist/vec3.cjs +459 -0
- package/dist/vec3.cjs.map +6 -0
- package/dist/vec3.d.ts +2 -0
- package/dist/vec3.d.ts.map +1 -0
- package/dist/vec3.js +5 -0
- package/dist/vec3.js.map +1 -0
- package/dist/vec4.cjs +398 -0
- package/dist/vec4.cjs.map +6 -0
- package/dist/vec4.d.ts +2 -0
- package/dist/vec4.d.ts.map +1 -0
- package/dist/vec4.js +5 -0
- package/dist/vec4.js.map +1 -0
- package/package.json +33 -3
- package/src/classes/base/math-array.ts +0 -61
- package/src/classes/base/vector.ts +4 -2
- package/src/classes/euler-types.ts +14 -0
- package/src/classes/euler.ts +13 -108
- package/src/classes/matrix3.ts +16 -22
- package/src/classes/matrix4.ts +27 -15
- package/src/classes/quaternion.ts +28 -44
- package/src/classes/spherical-coordinates.ts +12 -10
- package/src/gl-matrix/quat.ts +3 -3
- package/src/gl-matrix/vec2.ts +1 -1
- package/src/gl-matrix/vec3.ts +1 -1
- package/src/gl-matrix/vec4.ts +1 -1
- package/src/index.ts +1 -25
- package/src/lib/common.ts +0 -48
- package/src/lib/validators.ts +0 -12
- package/src/mat3.ts +5 -0
- package/src/mat4.ts +5 -0
- package/src/quat.ts +5 -0
- package/src/vec2.ts +5 -0
- package/src/vec3.ts +5 -0
- package/src/vec4.ts +5 -0
package/src/classes/euler.ts
CHANGED
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
// Copyright (c) 2017 Uber Technologies, Inc.
|
|
5
5
|
|
|
6
6
|
import {MathArray} from './base/math-array';
|
|
7
|
-
import {Quaternion} from './quaternion';
|
|
8
7
|
import {NumericArray} from '@math.gl/types';
|
|
8
|
+
import type {EulerRotationOrder} from './euler-types';
|
|
9
9
|
|
|
10
10
|
import {clamp} from '../lib/common';
|
|
11
11
|
import {checkNumber} from '../lib/validators';
|
|
12
|
+
import {fromQuat as mat4_fromQuat} from '../gl-matrix/mat4';
|
|
13
|
+
|
|
14
|
+
export type {EulerLike, EulerRotationOrder} from './euler-types';
|
|
12
15
|
|
|
13
16
|
// Internal constants
|
|
14
17
|
const ERR_UNKNOWN_ORDER = 'Unknown Euler angle order';
|
|
15
18
|
const ALMOST_ONE = 0.99999;
|
|
16
19
|
|
|
17
|
-
/** Order in which Euler rotations are applied. */
|
|
18
|
-
export type EulerRotationOrder = 'zyx' | 'yxz' | 'xzy' | 'zxy' | 'yzx' | 'xyz';
|
|
19
|
-
|
|
20
20
|
enum RotationOrderIndex {
|
|
21
21
|
ZYX = 0,
|
|
22
22
|
YXZ = 1,
|
|
@@ -35,57 +35,7 @@ const ROTATION_ORDER_INDICES: Record<EulerRotationOrder, RotationOrderIndex> = {
|
|
|
35
35
|
xyz: RotationOrderIndex.XYZ
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
const ROTATION_ORDERS = {
|
|
39
|
-
ZYX: 'zyx',
|
|
40
|
-
YXZ: 'yxz',
|
|
41
|
-
XZY: 'xzy',
|
|
42
|
-
ZXY: 'zxy',
|
|
43
|
-
YZX: 'yzx',
|
|
44
|
-
XYZ: 'xyz'
|
|
45
|
-
} as const;
|
|
46
|
-
|
|
47
38
|
export class Euler extends MathArray {
|
|
48
|
-
// Constants
|
|
49
|
-
/** @deprecated Pass the string `'zyx'` directly. */
|
|
50
|
-
static get ZYX(): EulerRotationOrder {
|
|
51
|
-
return 'zyx';
|
|
52
|
-
}
|
|
53
|
-
/** @deprecated Pass the string `'yxz'` directly. */
|
|
54
|
-
static get YXZ(): EulerRotationOrder {
|
|
55
|
-
return 'yxz';
|
|
56
|
-
}
|
|
57
|
-
/** @deprecated Pass the string `'xzy'` directly. */
|
|
58
|
-
static get XZY(): EulerRotationOrder {
|
|
59
|
-
return 'xzy';
|
|
60
|
-
}
|
|
61
|
-
/** @deprecated Pass the string `'zxy'` directly. */
|
|
62
|
-
static get ZXY(): EulerRotationOrder {
|
|
63
|
-
return 'zxy';
|
|
64
|
-
}
|
|
65
|
-
/** @deprecated Pass the string `'yzx'` directly. */
|
|
66
|
-
static get YZX(): EulerRotationOrder {
|
|
67
|
-
return 'yzx';
|
|
68
|
-
}
|
|
69
|
-
/** @deprecated Pass the string `'xyz'` directly. */
|
|
70
|
-
static get XYZ(): EulerRotationOrder {
|
|
71
|
-
return 'xyz';
|
|
72
|
-
}
|
|
73
|
-
/** @deprecated Pass the string `'zyx'` directly. */
|
|
74
|
-
static get RollPitchYaw(): EulerRotationOrder {
|
|
75
|
-
return 'zyx';
|
|
76
|
-
}
|
|
77
|
-
/** @deprecated Pass the string `'zyx'` directly. */
|
|
78
|
-
static get DefaultOrder(): EulerRotationOrder {
|
|
79
|
-
return 'zyx';
|
|
80
|
-
}
|
|
81
|
-
/** @deprecated Pass an {@link EulerRotationOrder} string directly. */
|
|
82
|
-
static get RotationOrders(): typeof ROTATION_ORDERS {
|
|
83
|
-
return ROTATION_ORDERS;
|
|
84
|
-
}
|
|
85
|
-
/** @deprecated Euler rotation orders are already represented as strings. */
|
|
86
|
-
static rotationOrder(order: EulerRotationOrder): EulerRotationOrder {
|
|
87
|
-
return order;
|
|
88
|
-
}
|
|
89
39
|
get ELEMENTS(): number {
|
|
90
40
|
return 4;
|
|
91
41
|
}
|
|
@@ -110,20 +60,9 @@ export class Euler extends MathArray {
|
|
|
110
60
|
}
|
|
111
61
|
}
|
|
112
62
|
|
|
113
|
-
fromQuaternion(quaternion: Readonly<NumericArray
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
const t0 = -2 * (ysqr + z * z) + 1;
|
|
117
|
-
const t1 = +2 * (x * y + w * z);
|
|
118
|
-
let t2 = -2 * (x * z - w * y);
|
|
119
|
-
const t3 = +2 * (y * z + w * x);
|
|
120
|
-
const t4 = -2 * (x * x + ysqr) + 1;
|
|
121
|
-
t2 = t2 > 1 ? 1 : t2;
|
|
122
|
-
t2 = t2 < -1 ? -1 : t2;
|
|
123
|
-
const roll = Math.atan2(t3, t4);
|
|
124
|
-
const pitch = Math.asin(t2);
|
|
125
|
-
const yaw = Math.atan2(t1, t0);
|
|
126
|
-
return this.set(roll, pitch, yaw, 'zyx');
|
|
63
|
+
fromQuaternion(quaternion: Readonly<NumericArray>, order: EulerRotationOrder = this.order): this {
|
|
64
|
+
const matrix = mat4_fromQuat(new Array<number>(16), quaternion);
|
|
65
|
+
return this.fromRotationMatrix(matrix, order);
|
|
127
66
|
}
|
|
128
67
|
|
|
129
68
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -307,36 +246,17 @@ export class Euler extends MathArray {
|
|
|
307
246
|
return this.set(roll, pitch, yaw, 'zyx');
|
|
308
247
|
}
|
|
309
248
|
|
|
310
|
-
fromRotationMatrix(m: Readonly<NumericArray>, order: EulerRotationOrder =
|
|
249
|
+
fromRotationMatrix(m: Readonly<NumericArray>, order: EulerRotationOrder = this.order): this {
|
|
311
250
|
this._fromRotationMatrix(m, order);
|
|
312
251
|
return this.check();
|
|
313
252
|
}
|
|
314
253
|
|
|
315
254
|
// ACCESSORS
|
|
316
255
|
|
|
317
|
-
getRotationMatrix(
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
// TODO - move to Quaternion
|
|
322
|
-
getQuaternion(): Quaternion {
|
|
323
|
-
const q = new Quaternion();
|
|
324
|
-
switch (this[3]) {
|
|
325
|
-
case RotationOrderIndex.XYZ:
|
|
326
|
-
return q.rotateX(this[0]).rotateY(this[1]).rotateZ(this[2]);
|
|
327
|
-
case RotationOrderIndex.YXZ:
|
|
328
|
-
return q.rotateY(this[1]).rotateX(this[0]).rotateZ(this[2]);
|
|
329
|
-
case RotationOrderIndex.ZXY:
|
|
330
|
-
return q.rotateZ(this[2]).rotateX(this[0]).rotateY(this[1]);
|
|
331
|
-
case RotationOrderIndex.ZYX:
|
|
332
|
-
return q.rotateZ(this[2]).rotateY(this[1]).rotateX(this[0]);
|
|
333
|
-
case RotationOrderIndex.YZX:
|
|
334
|
-
return q.rotateY(this[1]).rotateZ(this[2]).rotateX(this[0]);
|
|
335
|
-
case RotationOrderIndex.XZY:
|
|
336
|
-
return q.rotateX(this[0]).rotateZ(this[2]).rotateY(this[1]);
|
|
337
|
-
default:
|
|
338
|
-
throw new Error(ERR_UNKNOWN_ORDER);
|
|
339
|
-
}
|
|
256
|
+
getRotationMatrix(
|
|
257
|
+
result: NumericArray = [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0]
|
|
258
|
+
): NumericArray {
|
|
259
|
+
return this._getRotationMatrix(result);
|
|
340
260
|
}
|
|
341
261
|
|
|
342
262
|
// INTERNAL METHODS
|
|
@@ -347,7 +267,7 @@ export class Euler extends MathArray {
|
|
|
347
267
|
// const q = new Quaternion().setFromEuler(this);
|
|
348
268
|
// return this.setFromQuaternion(q, newOrder);
|
|
349
269
|
/* eslint-disable complexity, max-statements, one-var */
|
|
350
|
-
_fromRotationMatrix(m: Readonly<NumericArray>, order: EulerRotationOrder =
|
|
270
|
+
_fromRotationMatrix(m: Readonly<NumericArray>, order: EulerRotationOrder = this.order): this {
|
|
351
271
|
// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
|
|
352
272
|
const m11 = m[0],
|
|
353
273
|
m12 = m[4],
|
|
@@ -549,21 +469,6 @@ export class Euler extends MathArray {
|
|
|
549
469
|
te[15] = 1;
|
|
550
470
|
return te;
|
|
551
471
|
}
|
|
552
|
-
|
|
553
|
-
toQuaternion(): Quaternion {
|
|
554
|
-
// Abbreviations for the various angular functions
|
|
555
|
-
const cy = Math.cos(this.yaw * 0.5);
|
|
556
|
-
const sy = Math.sin(this.yaw * 0.5);
|
|
557
|
-
const cr = Math.cos(this.roll * 0.5);
|
|
558
|
-
const sr = Math.sin(this.roll * 0.5);
|
|
559
|
-
const cp = Math.cos(this.pitch * 0.5);
|
|
560
|
-
const sp = Math.sin(this.pitch * 0.5);
|
|
561
|
-
const w = cy * cr * cp + sy * sr * sp;
|
|
562
|
-
const x = cy * sr * cp - sy * cr * sp;
|
|
563
|
-
const y = cy * cr * sp + sy * sr * cp;
|
|
564
|
-
const z = sy * cr * cp - cy * sr * sp;
|
|
565
|
-
return new Quaternion(x, y, z, w);
|
|
566
|
-
}
|
|
567
472
|
}
|
|
568
473
|
|
|
569
474
|
// HELPER FUNCTIONS
|
package/src/classes/matrix3.ts
CHANGED
|
@@ -65,17 +65,11 @@ export class Matrix3 extends Matrix {
|
|
|
65
65
|
return INDICES;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
constructor(array?: Readonly<NumericArray>)
|
|
69
|
-
/** @deprecated */
|
|
70
|
-
constructor(...args: number[]);
|
|
71
|
-
|
|
72
|
-
constructor(array?: number | Readonly<NumericArray>, ...args: number[]) {
|
|
68
|
+
constructor(array?: Readonly<NumericArray>) {
|
|
73
69
|
// PERF NOTE: initialize elements as double precision numbers
|
|
74
70
|
super(-0, -0, -0, -0, -0, -0, -0, -0, -0);
|
|
75
71
|
if (arguments.length === 1 && Array.isArray(array)) {
|
|
76
72
|
this.copy(array);
|
|
77
|
-
} else if (args.length > 0) {
|
|
78
|
-
this.copy([array as number, ...args]);
|
|
79
73
|
} else {
|
|
80
74
|
this.identity();
|
|
81
75
|
}
|
|
@@ -119,6 +113,21 @@ export class Matrix3 extends Matrix {
|
|
|
119
113
|
return this.check();
|
|
120
114
|
}
|
|
121
115
|
|
|
116
|
+
/** Sets this matrix from the upper-left 3x3 elements of a 4x4 matrix. */
|
|
117
|
+
fromMatrix4(matrix4: Readonly<NumericArray>): this {
|
|
118
|
+
return this.set(
|
|
119
|
+
matrix4[0],
|
|
120
|
+
matrix4[1],
|
|
121
|
+
matrix4[2],
|
|
122
|
+
matrix4[4],
|
|
123
|
+
matrix4[5],
|
|
124
|
+
matrix4[6],
|
|
125
|
+
matrix4[8],
|
|
126
|
+
matrix4[9],
|
|
127
|
+
matrix4[10]
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
122
131
|
/**
|
|
123
132
|
* accepts column major order, stores in column major order
|
|
124
133
|
*/
|
|
@@ -240,21 +249,6 @@ export class Matrix3 extends Matrix {
|
|
|
240
249
|
checkVector(out, vector.length);
|
|
241
250
|
return out;
|
|
242
251
|
}
|
|
243
|
-
|
|
244
|
-
/** @deprecated */
|
|
245
|
-
transformVector(vector: Readonly<NumericArray>, result?: NumericArray): NumericArray {
|
|
246
|
-
return this.transform(vector, result);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/** @deprecated */
|
|
250
|
-
transformVector2(vector: Readonly<NumericArray>, result?: NumericArray): NumericArray {
|
|
251
|
-
return this.transform(vector, result);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/** @deprecated */
|
|
255
|
-
transformVector3(vector: Readonly<NumericArray>, result?: NumericArray): NumericArray {
|
|
256
|
-
return this.transform(vector, result);
|
|
257
|
-
}
|
|
258
252
|
}
|
|
259
253
|
|
|
260
254
|
let ZERO_MATRIX3: Matrix3 | null;
|
package/src/classes/matrix4.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import {NumericArray, NumericArray16} from '@math.gl/types';
|
|
7
7
|
import {Matrix} from './base/matrix';
|
|
8
|
+
import type {Matrix3Like} from './matrix3';
|
|
8
9
|
import {checkVector} from '../lib/validators';
|
|
9
10
|
|
|
10
11
|
/* eslint-disable camelcase */
|
|
@@ -240,6 +241,32 @@ export class Matrix4 extends Matrix {
|
|
|
240
241
|
return this.check();
|
|
241
242
|
}
|
|
242
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Sets this matrix from a 3x3 matrix, with zero translation.
|
|
246
|
+
* @param matrix3 - 3x3 matrix in column-major order.
|
|
247
|
+
* @returns This matrix.
|
|
248
|
+
*/
|
|
249
|
+
fromMatrix3(matrix3: Readonly<Matrix3Like>): this {
|
|
250
|
+
return this.set(
|
|
251
|
+
matrix3[0],
|
|
252
|
+
matrix3[1],
|
|
253
|
+
matrix3[2],
|
|
254
|
+
0,
|
|
255
|
+
matrix3[3],
|
|
256
|
+
matrix3[4],
|
|
257
|
+
matrix3[5],
|
|
258
|
+
0,
|
|
259
|
+
matrix3[6],
|
|
260
|
+
matrix3[7],
|
|
261
|
+
matrix3[8],
|
|
262
|
+
0,
|
|
263
|
+
0,
|
|
264
|
+
0,
|
|
265
|
+
0,
|
|
266
|
+
1
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
243
270
|
/**
|
|
244
271
|
* Generates a frustum matrix with the given bounds
|
|
245
272
|
* @param view.left - Left bound of the frustum
|
|
@@ -608,21 +635,6 @@ export class Matrix4 extends Matrix {
|
|
|
608
635
|
return out;
|
|
609
636
|
}
|
|
610
637
|
|
|
611
|
-
/** @deprecated */
|
|
612
|
-
transformPoint(vector: Readonly<NumericArray>, result?: NumericArray): NumericArray {
|
|
613
|
-
return this.transformAsPoint(vector, result);
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
/** @deprecated */
|
|
617
|
-
transformVector(vector: Readonly<NumericArray>, result?: NumericArray): NumericArray {
|
|
618
|
-
return this.transformAsPoint(vector, result);
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
/** @deprecated */
|
|
622
|
-
transformDirection(vector: Readonly<NumericArray>, result?: NumericArray): NumericArray {
|
|
623
|
-
return this.transformAsVector(vector, result);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
638
|
// three.js math API compatibility
|
|
627
639
|
|
|
628
640
|
makeRotationX(radians: number): this {
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
import {NumericArray} from '@math.gl/types';
|
|
7
7
|
import {MathArray} from './base/math-array';
|
|
8
|
-
import {checkNumber
|
|
9
|
-
import {
|
|
8
|
+
import {checkNumber} from '../lib/validators';
|
|
9
|
+
import type {EulerLike} from './euler-types';
|
|
10
10
|
// @ts-ignore gl-matrix types...
|
|
11
11
|
import {
|
|
12
12
|
fromMat3 as quat_fromMat3,
|
|
@@ -29,11 +29,6 @@ import {
|
|
|
29
29
|
scale as quat_scale,
|
|
30
30
|
slerp as quat_slerp
|
|
31
31
|
} from '../gl-matrix/quat';
|
|
32
|
-
// @ts-ignore gl-matrix types...
|
|
33
|
-
import {transformQuat as vec4_transformQuat} from '../gl-matrix/vec4';
|
|
34
|
-
|
|
35
|
-
const IDENTITY_QUATERNION = [0, 0, 0, 1] as const;
|
|
36
|
-
|
|
37
32
|
export class Quaternion extends MathArray {
|
|
38
33
|
constructor(x: number | Readonly<NumericArray> = 0, y = 0, z = 0, w = 1) {
|
|
39
34
|
// PERF NOTE: initialize elements as double precision numbers
|
|
@@ -82,6 +77,31 @@ export class Quaternion extends MathArray {
|
|
|
82
77
|
return this.check();
|
|
83
78
|
}
|
|
84
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Sets this quaternion from Euler angles.
|
|
82
|
+
* @param euler - Euler angles and rotation order.
|
|
83
|
+
* @returns This quaternion.
|
|
84
|
+
*/
|
|
85
|
+
fromEuler(euler: Readonly<EulerLike>): this {
|
|
86
|
+
this.identity();
|
|
87
|
+
switch (euler.order) {
|
|
88
|
+
case 'xyz':
|
|
89
|
+
return this.rotateX(euler.x).rotateY(euler.y).rotateZ(euler.z);
|
|
90
|
+
case 'yxz':
|
|
91
|
+
return this.rotateY(euler.y).rotateX(euler.x).rotateZ(euler.z);
|
|
92
|
+
case 'zxy':
|
|
93
|
+
return this.rotateZ(euler.z).rotateX(euler.x).rotateY(euler.y);
|
|
94
|
+
case 'zyx':
|
|
95
|
+
return this.rotateZ(euler.z).rotateY(euler.y).rotateX(euler.x);
|
|
96
|
+
case 'yzx':
|
|
97
|
+
return this.rotateY(euler.y).rotateZ(euler.z).rotateX(euler.x);
|
|
98
|
+
case 'xzy':
|
|
99
|
+
return this.rotateX(euler.x).rotateZ(euler.z).rotateY(euler.y);
|
|
100
|
+
default:
|
|
101
|
+
throw new Error('Unknown Euler angle order');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
85
105
|
fromAxisRotation(axis: Readonly<NumericArray>, rad: number): this {
|
|
86
106
|
quat_setAxisAngle(this, axis, rad);
|
|
87
107
|
return this.check();
|
|
@@ -272,41 +292,13 @@ export class Quaternion extends MathArray {
|
|
|
272
292
|
|
|
273
293
|
slerp(target: Readonly<NumericArray>, ratio: number): this;
|
|
274
294
|
slerp(start: Readonly<NumericArray>, target: Readonly<NumericArray>, ratio: number): this;
|
|
275
|
-
slerp(params: {
|
|
276
|
-
start: Readonly<NumericArray>;
|
|
277
|
-
target: Readonly<NumericArray>;
|
|
278
|
-
ratio: number;
|
|
279
|
-
}): this;
|
|
280
|
-
|
|
281
295
|
// Performs a spherical linear interpolation between two quat
|
|
282
|
-
slerp(
|
|
283
|
-
arg0:
|
|
284
|
-
| Readonly<NumericArray>
|
|
285
|
-
| {
|
|
286
|
-
start: Readonly<NumericArray>;
|
|
287
|
-
target: Readonly<NumericArray>;
|
|
288
|
-
ratio: number;
|
|
289
|
-
},
|
|
290
|
-
arg1?: Readonly<NumericArray> | number,
|
|
291
|
-
arg2?: number
|
|
292
|
-
): this {
|
|
296
|
+
slerp(arg0: Readonly<NumericArray>, arg1?: Readonly<NumericArray> | number, arg2?: number): this {
|
|
293
297
|
let start: Readonly<NumericArray>;
|
|
294
298
|
let target: Readonly<NumericArray>;
|
|
295
299
|
let ratio: number;
|
|
296
300
|
// eslint-disable-next-line prefer-rest-params
|
|
297
301
|
switch (arguments.length) {
|
|
298
|
-
case 1: // Deprecated signature ({start, target, ratio})
|
|
299
|
-
// eslint-disable-next-line prefer-rest-params
|
|
300
|
-
({
|
|
301
|
-
start = IDENTITY_QUATERNION,
|
|
302
|
-
target,
|
|
303
|
-
ratio
|
|
304
|
-
} = arg0 as {
|
|
305
|
-
start: Readonly<NumericArray>;
|
|
306
|
-
target: Readonly<NumericArray>;
|
|
307
|
-
ratio: number;
|
|
308
|
-
});
|
|
309
|
-
break;
|
|
310
302
|
case 2: // THREE.js compatibility signature (target, ration)
|
|
311
303
|
start = this; // eslint-disable-line
|
|
312
304
|
target = arg0 as Readonly<NumericArray>;
|
|
@@ -322,14 +314,6 @@ export class Quaternion extends MathArray {
|
|
|
322
314
|
return this.check();
|
|
323
315
|
}
|
|
324
316
|
|
|
325
|
-
transformVector4(
|
|
326
|
-
vector: Readonly<NumericArray>,
|
|
327
|
-
result: NumericArray = new Vector4()
|
|
328
|
-
): NumericArray {
|
|
329
|
-
vec4_transformQuat(result, vector, this);
|
|
330
|
-
return checkVector(result, 4);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
317
|
// THREE.js Math API compatibility
|
|
334
318
|
lengthSq(): number {
|
|
335
319
|
return this.lengthSquared();
|
|
@@ -4,11 +4,8 @@
|
|
|
4
4
|
// Copyright (c) 2017 Uber Technologies, Inc.
|
|
5
5
|
|
|
6
6
|
// Adaptation of THREE.js Spherical class, under MIT license
|
|
7
|
-
import {
|
|
8
|
-
import {Vector3} from './vector3';
|
|
7
|
+
import type {Vector3Like} from './vector3';
|
|
9
8
|
import {formatValue, equals, config, degrees, radians, clamp} from '../lib/common';
|
|
10
|
-
// @ts-ignore gl-matrix types...
|
|
11
|
-
import * as vec3 from '../gl-matrix/vec3';
|
|
12
9
|
|
|
13
10
|
type SphericalCoordinatesOptions = {
|
|
14
11
|
phi?: number;
|
|
@@ -174,8 +171,8 @@ export class SphericalCoordinates {
|
|
|
174
171
|
return this.check();
|
|
175
172
|
}
|
|
176
173
|
|
|
177
|
-
fromVector3(v: Readonly<
|
|
178
|
-
this.radius =
|
|
174
|
+
fromVector3(v: Readonly<Vector3Like>): this {
|
|
175
|
+
this.radius = Math.hypot(v[0], v[1], v[2]);
|
|
179
176
|
if (this.radius > 0) {
|
|
180
177
|
this.theta = Math.atan2(v[0], v[1]); // equator angle around y-up axis
|
|
181
178
|
this.phi = Math.acos(clamp(v[2] / this.radius, -1, 1)); // polar angle
|
|
@@ -183,10 +180,15 @@ export class SphericalCoordinates {
|
|
|
183
180
|
return this.check();
|
|
184
181
|
}
|
|
185
182
|
|
|
186
|
-
toVector3():
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
183
|
+
toVector3(result: Vector3Like = [-0, -0, -0]): Vector3Like {
|
|
184
|
+
const sinTheta = Math.sin(this.theta);
|
|
185
|
+
const cosTheta = Math.cos(this.theta);
|
|
186
|
+
const sinPhi = Math.sin(this.phi);
|
|
187
|
+
const cosPhi = Math.cos(this.phi);
|
|
188
|
+
result[0] = this.radius * sinTheta * sinPhi;
|
|
189
|
+
result[1] = -this.radius * sinTheta * cosPhi;
|
|
190
|
+
result[2] = this.radius * cosTheta;
|
|
191
|
+
return result;
|
|
190
192
|
}
|
|
191
193
|
|
|
192
194
|
// restrict phi to be betwee EPS and PI-EPS
|
package/src/gl-matrix/quat.ts
CHANGED
|
@@ -705,7 +705,7 @@ export function equals(a, b) {
|
|
|
705
705
|
* @param {ReadonlyVec3} b the destination vector
|
|
706
706
|
* @returns {quat} out
|
|
707
707
|
*/
|
|
708
|
-
export const rotationTo = (function () {
|
|
708
|
+
export const rotationTo = /* @__PURE__ */ (function () {
|
|
709
709
|
const tmpvec3 = vec3.create();
|
|
710
710
|
const xUnitVec3 = vec3.fromValues(1, 0, 0);
|
|
711
711
|
const yUnitVec3 = vec3.fromValues(0, 1, 0);
|
|
@@ -745,7 +745,7 @@ export const rotationTo = (function () {
|
|
|
745
745
|
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
746
746
|
* @returns {quat} out
|
|
747
747
|
*/
|
|
748
|
-
export const sqlerp = (function () {
|
|
748
|
+
export const sqlerp = /* @__PURE__ */ (function () {
|
|
749
749
|
const temp1 = create();
|
|
750
750
|
const temp2 = create();
|
|
751
751
|
|
|
@@ -768,7 +768,7 @@ export const sqlerp = (function () {
|
|
|
768
768
|
* @param {ReadonlyVec3} up the vector representing the local "up" direction
|
|
769
769
|
* @returns {quat} out
|
|
770
770
|
*/
|
|
771
|
-
export const setAxes = (function () {
|
|
771
|
+
export const setAxes = /* @__PURE__ */ (function () {
|
|
772
772
|
const matr = mat3.create();
|
|
773
773
|
|
|
774
774
|
return function (out, view, right, up) {
|
package/src/gl-matrix/vec2.ts
CHANGED
|
@@ -597,7 +597,7 @@ export const sqrLen = squaredLength;
|
|
|
597
597
|
* @returns {Array} a
|
|
598
598
|
* @function
|
|
599
599
|
*/
|
|
600
|
-
export const forEach = (function () {
|
|
600
|
+
export const forEach = /* @__PURE__ */ (function () {
|
|
601
601
|
const vec = create();
|
|
602
602
|
|
|
603
603
|
return function (a, stride, offset, count, fn, arg) {
|
package/src/gl-matrix/vec3.ts
CHANGED
|
@@ -792,7 +792,7 @@ export const sqrLen = squaredLength;
|
|
|
792
792
|
* @returns {Array} a
|
|
793
793
|
* @function
|
|
794
794
|
*/
|
|
795
|
-
export const forEach = (function () {
|
|
795
|
+
export const forEach = /* @__PURE__ */ (function () {
|
|
796
796
|
const vec = create();
|
|
797
797
|
|
|
798
798
|
return function (a, stride, offset, count, fn, arg) {
|
package/src/gl-matrix/vec4.ts
CHANGED
|
@@ -638,7 +638,7 @@ export const sqrLen = squaredLength;
|
|
|
638
638
|
* @returns {Array} a
|
|
639
639
|
* @function
|
|
640
640
|
*/
|
|
641
|
-
export const forEach = (function () {
|
|
641
|
+
export const forEach = /* @__PURE__ */ (function () {
|
|
642
642
|
const vec = create();
|
|
643
643
|
|
|
644
644
|
return function (a, stride, offset, count, fn, arg) {
|
package/src/index.ts
CHANGED
|
@@ -41,7 +41,7 @@ export type {Matrix4Like} from './classes/matrix4';
|
|
|
41
41
|
export {SphericalCoordinates} from './classes/spherical-coordinates';
|
|
42
42
|
export {Pose} from './classes/pose';
|
|
43
43
|
export {Euler} from './classes/euler';
|
|
44
|
-
export type {EulerRotationOrder} from './classes/euler';
|
|
44
|
+
export type {EulerLike, EulerRotationOrder} from './classes/euler-types';
|
|
45
45
|
|
|
46
46
|
export * as _MathUtils from './lib/math-utils';
|
|
47
47
|
|
|
@@ -64,31 +64,7 @@ export {
|
|
|
64
64
|
// math.gl "GLSL"-style functions
|
|
65
65
|
radians,
|
|
66
66
|
degrees,
|
|
67
|
-
sin,
|
|
68
|
-
cos,
|
|
69
|
-
tan,
|
|
70
|
-
asin,
|
|
71
|
-
acos,
|
|
72
|
-
atan,
|
|
73
67
|
clamp,
|
|
74
68
|
lerp,
|
|
75
69
|
withEpsilon
|
|
76
70
|
} from './lib/common';
|
|
77
|
-
|
|
78
|
-
// DEPRECATED
|
|
79
|
-
export {SphericalCoordinates as _SphericalCoordinates} from './classes/spherical-coordinates';
|
|
80
|
-
export {Pose as _Pose} from './classes/pose';
|
|
81
|
-
export {Euler as _Euler} from './classes/euler';
|
|
82
|
-
|
|
83
|
-
/** @deprecated Use Matrix3 */
|
|
84
|
-
export * as mat3 from './gl-matrix/mat3';
|
|
85
|
-
/** @deprecated Use Matrix4 */
|
|
86
|
-
export * as mat4 from './gl-matrix/mat4';
|
|
87
|
-
/** @deprecated Use Quaterinion */
|
|
88
|
-
export * as quat from './gl-matrix/quat';
|
|
89
|
-
/** @deprecated UseVector */
|
|
90
|
-
export * as vec2 from './gl-matrix/vec2';
|
|
91
|
-
/** @deprecated Use Vector3 */
|
|
92
|
-
export * as vec3 from './gl-matrix/vec3';
|
|
93
|
-
/** @deprecated Use Vector4 */
|
|
94
|
-
export * as vec4 from './gl-matrix/vec4';
|
package/src/lib/common.ts
CHANGED
|
@@ -189,54 +189,6 @@ function negativePiToPi(angle: number): number {
|
|
|
189
189
|
return zeroToTwoPi(angle + PI) - PI;
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
/**
|
|
193
|
-
* "GLSL equivalent" of `Math.sin`: Works on single values and vectors
|
|
194
|
-
* @deprecated
|
|
195
|
-
*/
|
|
196
|
-
export function sin(radians: number | NumericArray, result?: NumericArray): number | NumericArray {
|
|
197
|
-
return map(radians, angle => Math.sin(angle), result);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* "GLSL equivalent" of `Math.cos`: Works on single values and vectors
|
|
202
|
-
* @deprecated
|
|
203
|
-
*/
|
|
204
|
-
export function cos(radians: number | NumericArray, result?: NumericArray): number | NumericArray {
|
|
205
|
-
return map(radians, angle => Math.cos(angle), result);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* "GLSL equivalent" of `Math.tan`: Works on single values and vectors
|
|
210
|
-
* @deprecated
|
|
211
|
-
*/
|
|
212
|
-
export function tan(radians: number | NumericArray, result?: NumericArray): number | NumericArray {
|
|
213
|
-
return map(radians, angle => Math.tan(angle), result);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* "GLSL equivalent" of `Math.asin`: Works on single values and vectors
|
|
218
|
-
* @deprecated
|
|
219
|
-
*/
|
|
220
|
-
export function asin(radians: number | NumericArray, result?: NumericArray): number | NumericArray {
|
|
221
|
-
return map(radians, angle => Math.asin(angle), result);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* "GLSL equivalent" of `Math.acos`: Works on single values and vectors
|
|
226
|
-
* @deprecated
|
|
227
|
-
*/
|
|
228
|
-
export function acos(radians: number | NumericArray, result?: NumericArray): number | NumericArray {
|
|
229
|
-
return map(radians, angle => Math.acos(angle), result);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* "GLSL equivalent" of `Math.atan`: Works on single values and vectors
|
|
234
|
-
* @deprecated
|
|
235
|
-
*/
|
|
236
|
-
export function atan(radians: number | NumericArray, result?: NumericArray): number | NumericArray {
|
|
237
|
-
return map(radians, angle => Math.atan(angle), result);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
192
|
/**
|
|
241
193
|
* GLSL style value clamping: Works on single values and vectors
|
|
242
194
|
*/
|
package/src/lib/validators.ts
CHANGED
|
@@ -35,15 +35,3 @@ export function checkVector<T extends NumericArray>(
|
|
|
35
35
|
}
|
|
36
36
|
return v;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
const map: Record<string, boolean> = {};
|
|
40
|
-
|
|
41
|
-
export function deprecated(method: string, version: string): void {
|
|
42
|
-
if (!map[method]) {
|
|
43
|
-
map[method] = true;
|
|
44
|
-
// biome-ignore lint/suspicious/noConsole: deprecations are intentionally reported to users.
|
|
45
|
-
console.warn(
|
|
46
|
-
`${method} has been removed in version ${version}, see upgrade guide for more information`
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
}
|
package/src/mat3.ts
ADDED
package/src/mat4.ts
ADDED
package/src/quat.ts
ADDED
package/src/vec2.ts
ADDED
package/src/vec3.ts
ADDED