@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.
Files changed (111) hide show
  1. package/dist/classes/base/math-array.d.ts +0 -18
  2. package/dist/classes/base/math-array.d.ts.map +1 -1
  3. package/dist/classes/base/math-array.js +0 -51
  4. package/dist/classes/base/math-array.js.map +1 -1
  5. package/dist/classes/base/vector.d.ts.map +1 -1
  6. package/dist/classes/base/vector.js +4 -2
  7. package/dist/classes/base/vector.js.map +1 -1
  8. package/dist/classes/euler-types.d.ts +10 -0
  9. package/dist/classes/euler-types.d.ts.map +1 -0
  10. package/dist/classes/euler-types.js +5 -0
  11. package/dist/classes/euler-types.js.map +1 -0
  12. package/dist/classes/euler.d.ts +4 -36
  13. package/dist/classes/euler.d.ts.map +1 -1
  14. package/dist/classes/euler.js +8 -102
  15. package/dist/classes/euler.js.map +1 -1
  16. package/dist/classes/matrix3.d.ts +2 -8
  17. package/dist/classes/matrix3.d.ts.map +1 -1
  18. package/dist/classes/matrix3.js +5 -16
  19. package/dist/classes/matrix3.js.map +1 -1
  20. package/dist/classes/matrix4.d.ts +7 -6
  21. package/dist/classes/matrix4.d.ts.map +1 -1
  22. package/dist/classes/matrix4.js +8 -12
  23. package/dist/classes/matrix4.js.map +1 -1
  24. package/dist/classes/quaternion.d.ts +7 -6
  25. package/dist/classes/quaternion.d.ts.map +1 -1
  26. package/dist/classes/quaternion.js +25 -17
  27. package/dist/classes/quaternion.js.map +1 -1
  28. package/dist/classes/spherical-coordinates.d.ts +3 -4
  29. package/dist/classes/spherical-coordinates.d.ts.map +1 -1
  30. package/dist/classes/spherical-coordinates.js +10 -8
  31. package/dist/classes/spherical-coordinates.js.map +1 -1
  32. package/dist/gl-matrix/quat.js +3 -3
  33. package/dist/gl-matrix/quat.js.map +1 -1
  34. package/dist/gl-matrix/vec2.js +1 -1
  35. package/dist/gl-matrix/vec2.js.map +1 -1
  36. package/dist/gl-matrix/vec3.js +1 -1
  37. package/dist/gl-matrix/vec3.js.map +1 -1
  38. package/dist/gl-matrix/vec4.js +1 -1
  39. package/dist/gl-matrix/vec4.js.map +1 -1
  40. package/dist/index.cjs +223 -2554
  41. package/dist/index.cjs.map +3 -3
  42. package/dist/index.d.ts +2 -17
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +1 -17
  45. package/dist/index.js.map +1 -1
  46. package/dist/lib/common.d.ts +0 -30
  47. package/dist/lib/common.d.ts.map +1 -1
  48. package/dist/lib/common.js +0 -42
  49. package/dist/lib/common.js.map +1 -1
  50. package/dist/lib/validators.d.ts +0 -1
  51. package/dist/lib/validators.d.ts.map +1 -1
  52. package/dist/lib/validators.js +0 -8
  53. package/dist/lib/validators.js.map +1 -1
  54. package/dist/mat3.cjs +543 -0
  55. package/dist/mat3.cjs.map +6 -0
  56. package/dist/mat3.d.ts +2 -0
  57. package/dist/mat3.d.ts.map +1 -0
  58. package/dist/mat3.js +5 -0
  59. package/dist/mat3.js.map +1 -0
  60. package/dist/mat4.cjs +1497 -0
  61. package/dist/mat4.cjs.map +6 -0
  62. package/dist/mat4.d.ts +2 -0
  63. package/dist/mat4.d.ts.map +1 -0
  64. package/dist/mat4.js +5 -0
  65. package/dist/mat4.js.map +1 -0
  66. package/dist/quat.cjs +532 -0
  67. package/dist/quat.cjs.map +6 -0
  68. package/dist/quat.d.ts +2 -0
  69. package/dist/quat.d.ts.map +1 -0
  70. package/dist/quat.js +5 -0
  71. package/dist/quat.js.map +1 -0
  72. package/dist/vec2.cjs +328 -0
  73. package/dist/vec2.cjs.map +6 -0
  74. package/dist/vec2.d.ts +2 -0
  75. package/dist/vec2.d.ts.map +1 -0
  76. package/dist/vec2.js +5 -0
  77. package/dist/vec2.js.map +1 -0
  78. package/dist/vec3.cjs +459 -0
  79. package/dist/vec3.cjs.map +6 -0
  80. package/dist/vec3.d.ts +2 -0
  81. package/dist/vec3.d.ts.map +1 -0
  82. package/dist/vec3.js +5 -0
  83. package/dist/vec3.js.map +1 -0
  84. package/dist/vec4.cjs +398 -0
  85. package/dist/vec4.cjs.map +6 -0
  86. package/dist/vec4.d.ts +2 -0
  87. package/dist/vec4.d.ts.map +1 -0
  88. package/dist/vec4.js +5 -0
  89. package/dist/vec4.js.map +1 -0
  90. package/package.json +33 -3
  91. package/src/classes/base/math-array.ts +0 -61
  92. package/src/classes/base/vector.ts +4 -2
  93. package/src/classes/euler-types.ts +14 -0
  94. package/src/classes/euler.ts +13 -108
  95. package/src/classes/matrix3.ts +16 -22
  96. package/src/classes/matrix4.ts +27 -15
  97. package/src/classes/quaternion.ts +28 -44
  98. package/src/classes/spherical-coordinates.ts +12 -10
  99. package/src/gl-matrix/quat.ts +3 -3
  100. package/src/gl-matrix/vec2.ts +1 -1
  101. package/src/gl-matrix/vec3.ts +1 -1
  102. package/src/gl-matrix/vec4.ts +1 -1
  103. package/src/index.ts +1 -25
  104. package/src/lib/common.ts +0 -48
  105. package/src/lib/validators.ts +0 -12
  106. package/src/mat3.ts +5 -0
  107. package/src/mat4.ts +5 -0
  108. package/src/quat.ts +5 -0
  109. package/src/vec2.ts +5 -0
  110. package/src/vec3.ts +5 -0
  111. package/src/vec4.ts +5 -0
@@ -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>): this {
114
- const [x, y, z, w] = quaternion;
115
- const ysqr = y * y;
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 = 'zyx'): this {
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(m: NumericArray): NumericArray {
318
- return this._getRotationMatrix(m);
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 = 'zyx'): this {
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
@@ -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;
@@ -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, checkVector} from '../lib/validators';
9
- import {Vector4} from './vector4';
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 {NumericArray} from '@math.gl/types';
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<NumericArray>): this {
178
- this.radius = vec3.length(v);
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(): Vector3 {
187
- return new Vector3(0, 0, this.radius)
188
- .rotateX({radians: this.theta})
189
- .rotateZ({radians: this.phi});
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
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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
  */
@@ -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
@@ -0,0 +1,5 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export * from './gl-matrix/mat3';
package/src/mat4.ts ADDED
@@ -0,0 +1,5 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export * from './gl-matrix/mat4';
package/src/quat.ts ADDED
@@ -0,0 +1,5 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export * from './gl-matrix/quat';
package/src/vec2.ts ADDED
@@ -0,0 +1,5 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export * from './gl-matrix/vec2';
package/src/vec3.ts ADDED
@@ -0,0 +1,5 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export * from './gl-matrix/vec3';
package/src/vec4.ts ADDED
@@ -0,0 +1,5 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export * from './gl-matrix/vec4';