@math.gl/core 4.0.0 → 4.1.0-alpha.1

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 (147) hide show
  1. package/dist/classes/base/math-array.d.ts +1 -2
  2. package/dist/classes/base/math-array.js +223 -266
  3. package/dist/classes/base/matrix.d.ts +1 -2
  4. package/dist/classes/base/matrix.js +56 -53
  5. package/dist/classes/base/vector.d.ts +1 -2
  6. package/dist/classes/base/vector.js +125 -135
  7. package/dist/classes/euler.d.ts +2 -3
  8. package/dist/classes/euler.js +464 -533
  9. package/dist/classes/matrix3.d.ts +9 -4
  10. package/dist/classes/matrix3.js +191 -190
  11. package/dist/classes/matrix4.d.ts +8 -4
  12. package/dist/classes/matrix4.js +521 -452
  13. package/dist/classes/pose.d.ts +4 -5
  14. package/dist/classes/pose.js +106 -119
  15. package/dist/classes/quaternion.d.ts +1 -2
  16. package/dist/classes/quaternion.js +261 -233
  17. package/dist/classes/spherical-coordinates.d.ts +3 -4
  18. package/dist/classes/spherical-coordinates.js +142 -147
  19. package/dist/classes/vector2.d.ts +6 -5
  20. package/dist/classes/vector2.js +103 -85
  21. package/dist/classes/vector3.d.ts +6 -5
  22. package/dist/classes/vector3.js +129 -136
  23. package/dist/classes/vector4.d.ts +7 -6
  24. package/dist/classes/vector4.js +108 -114
  25. package/dist/gl-matrix/common.d.ts +0 -1
  26. package/dist/gl-matrix/common.js +38 -6
  27. package/dist/gl-matrix/mat3.d.ts +0 -1
  28. package/dist/gl-matrix/mat3.js +699 -425
  29. package/dist/gl-matrix/mat4.d.ts +0 -1
  30. package/dist/gl-matrix/mat4.js +1879 -1339
  31. package/dist/gl-matrix/quat.d.ts +0 -1
  32. package/dist/gl-matrix/quat.js +655 -257
  33. package/dist/gl-matrix/vec2.d.ts +0 -1
  34. package/dist/gl-matrix/vec2.js +529 -212
  35. package/dist/gl-matrix/vec3.d.ts +0 -1
  36. package/dist/gl-matrix/vec3.js +703 -335
  37. package/dist/gl-matrix/vec4.d.ts +0 -1
  38. package/dist/gl-matrix/vec4.js +579 -293
  39. package/dist/gl-matrix/wip/index.d.ts +3 -4
  40. package/dist/gl-matrix/wip/index.js +5 -1
  41. package/dist/gl-matrix/wip/mat2.d.ts +1 -2
  42. package/dist/gl-matrix/wip/mat2.js +336 -157
  43. package/dist/gl-matrix/wip/mat2d.d.ts +0 -1
  44. package/dist/gl-matrix/wip/mat2d.js +380 -202
  45. package/dist/gl-matrix/wip/quat2.d.ts +0 -1
  46. package/dist/gl-matrix/wip/quat2.js +650 -409
  47. package/dist/index.cjs +60 -100
  48. package/dist/index.cjs.map +7 -0
  49. package/dist/index.d.ts +27 -23
  50. package/dist/index.js +25 -16
  51. package/dist/lib/assert.d.ts +0 -1
  52. package/dist/lib/assert.js +6 -4
  53. package/dist/lib/common.d.ts +2 -3
  54. package/dist/lib/common.js +165 -134
  55. package/dist/lib/gl-matrix-extras.d.ts +0 -1
  56. package/dist/lib/gl-matrix-extras.js +42 -36
  57. package/dist/lib/math-utils.d.ts +0 -1
  58. package/dist/lib/math-utils.js +5 -1
  59. package/dist/lib/validators.d.ts +0 -1
  60. package/dist/lib/validators.js +25 -25
  61. package/package.json +5 -6
  62. package/src/classes/base/math-array.ts +4 -1
  63. package/src/classes/base/matrix.ts +4 -1
  64. package/src/classes/base/vector.ts +4 -1
  65. package/src/classes/euler.ts +4 -1
  66. package/src/classes/matrix3.ts +12 -3
  67. package/src/classes/matrix4.ts +11 -3
  68. package/src/classes/pose.ts +4 -1
  69. package/src/classes/quaternion.ts +4 -1
  70. package/src/classes/spherical-coordinates.ts +4 -1
  71. package/src/classes/vector2.ts +11 -4
  72. package/src/classes/vector3.ts +10 -4
  73. package/src/classes/vector4.ts +9 -4
  74. package/src/gl-matrix/wip/index.js +4 -0
  75. package/src/gl-matrix/wip/mat2.js +4 -0
  76. package/src/gl-matrix/wip/mat2d.js +4 -0
  77. package/src/gl-matrix/wip/quat2.ts +4 -0
  78. package/src/index.ts +10 -2
  79. package/src/lib/assert.ts +4 -0
  80. package/src/lib/common.ts +3 -1
  81. package/src/lib/gl-matrix-extras.ts +4 -0
  82. package/src/lib/gl-matrix.d.ts +4 -0
  83. package/src/lib/math-utils.ts +4 -0
  84. package/src/lib/validators.ts +4 -19
  85. package/dist/classes/base/math-array.d.ts.map +0 -1
  86. package/dist/classes/base/math-array.js.map +0 -1
  87. package/dist/classes/base/matrix.d.ts.map +0 -1
  88. package/dist/classes/base/matrix.js.map +0 -1
  89. package/dist/classes/base/vector.d.ts.map +0 -1
  90. package/dist/classes/base/vector.js.map +0 -1
  91. package/dist/classes/euler.d.ts.map +0 -1
  92. package/dist/classes/euler.js.map +0 -1
  93. package/dist/classes/matrix3.d.ts.map +0 -1
  94. package/dist/classes/matrix3.js.map +0 -1
  95. package/dist/classes/matrix4.d.ts.map +0 -1
  96. package/dist/classes/matrix4.js.map +0 -1
  97. package/dist/classes/pose.d.ts.map +0 -1
  98. package/dist/classes/pose.js.map +0 -1
  99. package/dist/classes/quaternion.d.ts.map +0 -1
  100. package/dist/classes/quaternion.js.map +0 -1
  101. package/dist/classes/spherical-coordinates.d.ts.map +0 -1
  102. package/dist/classes/spherical-coordinates.js.map +0 -1
  103. package/dist/classes/vector2.d.ts.map +0 -1
  104. package/dist/classes/vector2.js.map +0 -1
  105. package/dist/classes/vector3.d.ts.map +0 -1
  106. package/dist/classes/vector3.js.map +0 -1
  107. package/dist/classes/vector4.d.ts.map +0 -1
  108. package/dist/classes/vector4.js.map +0 -1
  109. package/dist/gl-matrix/common.d.ts.map +0 -1
  110. package/dist/gl-matrix/common.js.map +0 -1
  111. package/dist/gl-matrix/mat3.d.ts.map +0 -1
  112. package/dist/gl-matrix/mat3.js.map +0 -1
  113. package/dist/gl-matrix/mat4.d.ts.map +0 -1
  114. package/dist/gl-matrix/mat4.js.map +0 -1
  115. package/dist/gl-matrix/quat.d.ts.map +0 -1
  116. package/dist/gl-matrix/quat.js.map +0 -1
  117. package/dist/gl-matrix/vec2.d.ts.map +0 -1
  118. package/dist/gl-matrix/vec2.js.map +0 -1
  119. package/dist/gl-matrix/vec3.d.ts.map +0 -1
  120. package/dist/gl-matrix/vec3.js.map +0 -1
  121. package/dist/gl-matrix/vec4.d.ts.map +0 -1
  122. package/dist/gl-matrix/vec4.js.map +0 -1
  123. package/dist/gl-matrix/wip/index.d.ts.map +0 -1
  124. package/dist/gl-matrix/wip/index.js.map +0 -1
  125. package/dist/gl-matrix/wip/mat2.d.ts.map +0 -1
  126. package/dist/gl-matrix/wip/mat2.js.map +0 -1
  127. package/dist/gl-matrix/wip/mat2d.d.ts.map +0 -1
  128. package/dist/gl-matrix/wip/mat2d.js.map +0 -1
  129. package/dist/gl-matrix/wip/quat2.d.ts.map +0 -1
  130. package/dist/gl-matrix/wip/quat2.js.map +0 -1
  131. package/dist/gl-matrix/wip/types.d.js +0 -2
  132. package/dist/gl-matrix/wip/types.d.js.map +0 -1
  133. package/dist/index.d.ts.map +0 -1
  134. package/dist/index.js.map +0 -1
  135. package/dist/lib/assert.d.ts.map +0 -1
  136. package/dist/lib/assert.js.map +0 -1
  137. package/dist/lib/common.d.ts.map +0 -1
  138. package/dist/lib/common.js.map +0 -1
  139. package/dist/lib/gl-matrix-extras.d.ts.map +0 -1
  140. package/dist/lib/gl-matrix-extras.js.map +0 -1
  141. package/dist/lib/gl-matrix.d.js +0 -2
  142. package/dist/lib/gl-matrix.d.js.map +0 -1
  143. package/dist/lib/math-utils.d.ts.map +0 -1
  144. package/dist/lib/math-utils.js.map +0 -1
  145. package/dist/lib/validators.d.ts.map +0 -1
  146. package/dist/lib/validators.js.map +0 -1
  147. package/src/gl-matrix/wip/types.d.ts +0 -93
@@ -1,557 +1,488 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // Copyright (c) 2017 Uber Technologies, Inc.
1
5
  import { MathArray } from "./base/math-array.js";
2
6
  import { Quaternion } from "./quaternion.js";
3
7
  import { clamp } from "../lib/common.js";
4
8
  import { checkNumber } from "../lib/validators.js";
9
+ // Internal constants
5
10
  const ERR_UNKNOWN_ORDER = 'Unknown Euler angle order';
6
11
  const ALMOST_ONE = 0.99999;
7
12
  var RotationOrder;
8
-
9
13
  (function (RotationOrder) {
10
- RotationOrder[RotationOrder["ZYX"] = 0] = "ZYX";
11
- RotationOrder[RotationOrder["YXZ"] = 1] = "YXZ";
12
- RotationOrder[RotationOrder["XZY"] = 2] = "XZY";
13
- RotationOrder[RotationOrder["ZXY"] = 3] = "ZXY";
14
- RotationOrder[RotationOrder["YZX"] = 4] = "YZX";
15
- RotationOrder[RotationOrder["XYZ"] = 5] = "XYZ";
14
+ RotationOrder[RotationOrder["ZYX"] = 0] = "ZYX";
15
+ RotationOrder[RotationOrder["YXZ"] = 1] = "YXZ";
16
+ RotationOrder[RotationOrder["XZY"] = 2] = "XZY";
17
+ RotationOrder[RotationOrder["ZXY"] = 3] = "ZXY";
18
+ RotationOrder[RotationOrder["YZX"] = 4] = "YZX";
19
+ RotationOrder[RotationOrder["XYZ"] = 5] = "XYZ";
16
20
  })(RotationOrder || (RotationOrder = {}));
17
-
18
21
  export class Euler extends MathArray {
19
- static get ZYX() {
20
- return RotationOrder.ZYX;
21
- }
22
-
23
- static get YXZ() {
24
- return RotationOrder.YXZ;
25
- }
26
-
27
- static get XZY() {
28
- return RotationOrder.XZY;
29
- }
30
-
31
- static get ZXY() {
32
- return RotationOrder.ZXY;
33
- }
34
-
35
- static get YZX() {
36
- return RotationOrder.YZX;
37
- }
38
-
39
- static get XYZ() {
40
- return RotationOrder.XYZ;
41
- }
42
-
43
- static get RollPitchYaw() {
44
- return RotationOrder.ZYX;
45
- }
46
-
47
- static get DefaultOrder() {
48
- return RotationOrder.ZYX;
49
- }
50
-
51
- static get RotationOrders() {
52
- return RotationOrder;
53
- }
54
-
55
- static rotationOrder(order) {
56
- return RotationOrder[order];
57
- }
58
-
59
- get ELEMENTS() {
60
- return 4;
61
- }
62
-
63
- constructor(x = 0, y = 0, z = 0, order = Euler.DefaultOrder) {
64
- super(-0, -0, -0, -0);
65
-
66
- if (arguments.length > 0 && Array.isArray(arguments[0])) {
67
- this.fromVector3(...arguments);
68
- } else {
69
- this.set(x, y, z, order);
70
- }
71
- }
72
-
73
- fromQuaternion(quaternion) {
74
- const [x, y, z, w] = quaternion;
75
- const ysqr = y * y;
76
- const t0 = -2 * (ysqr + z * z) + 1;
77
- const t1 = +2 * (x * y + w * z);
78
- let t2 = -2 * (x * z - w * y);
79
- const t3 = +2 * (y * z + w * x);
80
- const t4 = -2 * (x * x + ysqr) + 1;
81
- t2 = t2 > 1 ? 1 : t2;
82
- t2 = t2 < -1 ? -1 : t2;
83
- const roll = Math.atan2(t3, t4);
84
- const pitch = Math.asin(t2);
85
- const yaw = Math.atan2(t1, t0);
86
- return this.set(roll, pitch, yaw, Euler.RollPitchYaw);
87
- }
88
-
89
- fromObject(object) {
90
- throw new Error('not implemented');
91
- }
92
-
93
- copy(array) {
94
- this[0] = array[0];
95
- this[1] = array[1];
96
- this[2] = array[2];
97
- this[3] = Number.isFinite(array[3]) || this.order;
98
- return this.check();
99
- }
100
-
101
- set(x = 0, y = 0, z = 0, order) {
102
- this[0] = x;
103
- this[1] = y;
104
- this[2] = z;
105
- this[3] = Number.isFinite(order) ? order : this[3];
106
- return this.check();
107
- }
108
-
109
- validate() {
110
- return validateOrder(this[3]) && Number.isFinite(this[0]) && Number.isFinite(this[1]) && Number.isFinite(this[2]);
111
- }
112
-
113
- toArray(array = [], offset = 0) {
114
- array[offset] = this[0];
115
- array[offset + 1] = this[1];
116
- array[offset + 2] = this[2];
117
- return array;
118
- }
119
-
120
- toArray4(array = [], offset = 0) {
121
- array[offset] = this[0];
122
- array[offset + 1] = this[1];
123
- array[offset + 2] = this[2];
124
- array[offset + 3] = this[3];
125
- return array;
126
- }
127
-
128
- toVector3(result = [-0, -0, -0]) {
129
- result[0] = this[0];
130
- result[1] = this[1];
131
- result[2] = this[2];
132
- return result;
133
- }
134
-
135
- get x() {
136
- return this[0];
137
- }
138
-
139
- set x(value) {
140
- this[0] = checkNumber(value);
141
- }
142
-
143
- get y() {
144
- return this[1];
145
- }
146
-
147
- set y(value) {
148
- this[1] = checkNumber(value);
149
- }
150
-
151
- get z() {
152
- return this[2];
153
- }
154
-
155
- set z(value) {
156
- this[2] = checkNumber(value);
157
- }
158
-
159
- get alpha() {
160
- return this[0];
161
- }
162
-
163
- set alpha(value) {
164
- this[0] = checkNumber(value);
165
- }
166
-
167
- get beta() {
168
- return this[1];
169
- }
170
-
171
- set beta(value) {
172
- this[1] = checkNumber(value);
173
- }
174
-
175
- get gamma() {
176
- return this[2];
177
- }
178
-
179
- set gamma(value) {
180
- this[2] = checkNumber(value);
181
- }
182
-
183
- get phi() {
184
- return this[0];
185
- }
186
-
187
- set phi(value) {
188
- this[0] = checkNumber(value);
189
- }
190
-
191
- get theta() {
192
- return this[1];
193
- }
194
-
195
- set theta(value) {
196
- this[1] = checkNumber(value);
197
- }
198
-
199
- get psi() {
200
- return this[2];
201
- }
202
-
203
- set psi(value) {
204
- this[2] = checkNumber(value);
205
- }
206
-
207
- get roll() {
208
- return this[0];
209
- }
210
-
211
- set roll(value) {
212
- this[0] = checkNumber(value);
213
- }
214
-
215
- get pitch() {
216
- return this[1];
217
- }
218
-
219
- set pitch(value) {
220
- this[1] = checkNumber(value);
221
- }
222
-
223
- get yaw() {
224
- return this[2];
225
- }
226
-
227
- set yaw(value) {
228
- this[2] = checkNumber(value);
229
- }
230
-
231
- get order() {
232
- return this[3];
233
- }
234
-
235
- set order(value) {
236
- this[3] = checkOrder(value);
237
- }
238
-
239
- fromVector3(v, order) {
240
- return this.set(v[0], v[1], v[2], Number.isFinite(order) ? order : this[3]);
241
- }
242
-
243
- fromArray(array, offset = 0) {
244
- this[0] = array[0 + offset];
245
- this[1] = array[1 + offset];
246
- this[2] = array[2 + offset];
247
-
248
- if (array[3] !== undefined) {
249
- this[3] = array[3];
250
- }
251
-
252
- return this.check();
253
- }
254
-
255
- fromRollPitchYaw(roll, pitch, yaw) {
256
- return this.set(roll, pitch, yaw, RotationOrder.ZYX);
257
- }
258
-
259
- fromRotationMatrix(m, order = Euler.DefaultOrder) {
260
- this._fromRotationMatrix(m, order);
261
-
262
- return this.check();
263
- }
264
-
265
- getRotationMatrix(m) {
266
- return this._getRotationMatrix(m);
267
- }
268
-
269
- getQuaternion() {
270
- const q = new Quaternion();
271
-
272
- switch (this[3]) {
273
- case RotationOrder.XYZ:
274
- return q.rotateX(this[0]).rotateY(this[1]).rotateZ(this[2]);
275
-
276
- case RotationOrder.YXZ:
277
- return q.rotateY(this[0]).rotateX(this[1]).rotateZ(this[2]);
278
-
279
- case RotationOrder.ZXY:
280
- return q.rotateZ(this[0]).rotateX(this[1]).rotateY(this[2]);
281
-
282
- case RotationOrder.ZYX:
283
- return q.rotateZ(this[0]).rotateY(this[1]).rotateX(this[2]);
284
-
285
- case RotationOrder.YZX:
286
- return q.rotateY(this[0]).rotateZ(this[1]).rotateX(this[2]);
287
-
288
- case RotationOrder.XZY:
289
- return q.rotateX(this[0]).rotateZ(this[1]).rotateY(this[2]);
290
-
291
- default:
292
- throw new Error(ERR_UNKNOWN_ORDER);
22
+ // Constants
23
+ static get ZYX() {
24
+ return RotationOrder.ZYX;
293
25
  }
294
- }
295
-
296
- _fromRotationMatrix(m, order = Euler.DefaultOrder) {
297
- const m11 = m[0],
298
- m12 = m[4],
299
- m13 = m[8];
300
- const m21 = m[1],
301
- m22 = m[5],
302
- m23 = m[9];
303
- const m31 = m[2],
304
- m32 = m[6],
305
- m33 = m[10];
306
- order = order || this[3];
307
-
308
- switch (order) {
309
- case Euler.XYZ:
310
- this[1] = Math.asin(clamp(m13, -1, 1));
311
-
312
- if (Math.abs(m13) < ALMOST_ONE) {
313
- this[0] = Math.atan2(-m23, m33);
314
- this[2] = Math.atan2(-m12, m11);
315
- } else {
316
- this[0] = Math.atan2(m32, m22);
317
- this[2] = 0;
318
- }
319
-
320
- break;
321
-
322
- case Euler.YXZ:
323
- this[0] = Math.asin(-clamp(m23, -1, 1));
324
-
325
- if (Math.abs(m23) < ALMOST_ONE) {
326
- this[1] = Math.atan2(m13, m33);
327
- this[2] = Math.atan2(m21, m22);
328
- } else {
329
- this[1] = Math.atan2(-m31, m11);
330
- this[2] = 0;
331
- }
332
-
333
- break;
334
-
335
- case Euler.ZXY:
336
- this[0] = Math.asin(clamp(m32, -1, 1));
337
-
338
- if (Math.abs(m32) < ALMOST_ONE) {
339
- this[1] = Math.atan2(-m31, m33);
340
- this[2] = Math.atan2(-m12, m22);
341
- } else {
342
- this[1] = 0;
343
- this[2] = Math.atan2(m21, m11);
344
- }
345
-
346
- break;
347
-
348
- case Euler.ZYX:
349
- this[1] = Math.asin(-clamp(m31, -1, 1));
350
-
351
- if (Math.abs(m31) < ALMOST_ONE) {
352
- this[0] = Math.atan2(m32, m33);
353
- this[2] = Math.atan2(m21, m11);
354
- } else {
355
- this[0] = 0;
356
- this[2] = Math.atan2(-m12, m22);
357
- }
358
-
359
- break;
360
-
361
- case Euler.YZX:
362
- this[2] = Math.asin(clamp(m21, -1, 1));
363
-
364
- if (Math.abs(m21) < ALMOST_ONE) {
365
- this[0] = Math.atan2(-m23, m22);
366
- this[1] = Math.atan2(-m31, m11);
367
- } else {
368
- this[0] = 0;
369
- this[1] = Math.atan2(m13, m33);
370
- }
371
-
372
- break;
373
-
374
- case Euler.XZY:
375
- this[2] = Math.asin(-clamp(m12, -1, 1));
376
-
377
- if (Math.abs(m12) < ALMOST_ONE) {
378
- this[0] = Math.atan2(m32, m22);
379
- this[1] = Math.atan2(m13, m11);
380
- } else {
381
- this[0] = Math.atan2(-m23, m33);
382
- this[1] = 0;
383
- }
384
-
385
- break;
386
-
387
- default:
388
- throw new Error(ERR_UNKNOWN_ORDER);
26
+ static get YXZ() {
27
+ return RotationOrder.YXZ;
28
+ }
29
+ static get XZY() {
30
+ return RotationOrder.XZY;
31
+ }
32
+ static get ZXY() {
33
+ return RotationOrder.ZXY;
34
+ }
35
+ static get YZX() {
36
+ return RotationOrder.YZX;
37
+ }
38
+ static get XYZ() {
39
+ return RotationOrder.XYZ;
40
+ }
41
+ static get RollPitchYaw() {
42
+ return RotationOrder.ZYX;
43
+ }
44
+ static get DefaultOrder() {
45
+ return RotationOrder.ZYX;
46
+ }
47
+ static get RotationOrders() {
48
+ return RotationOrder;
49
+ }
50
+ static rotationOrder(order) {
51
+ return RotationOrder[order];
389
52
  }
390
-
391
- this[3] = order;
392
- return this;
393
- }
394
-
395
- _getRotationMatrix(result) {
396
- const te = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
397
- const x = this.x,
398
- y = this.y,
399
- z = this.z;
400
- const a = Math.cos(x);
401
- const c = Math.cos(y);
402
- const e = Math.cos(z);
403
- const b = Math.sin(x);
404
- const d = Math.sin(y);
405
- const f = Math.sin(z);
406
-
407
- switch (this[3]) {
408
- case Euler.XYZ:
409
- {
410
- const ae = a * e,
411
- af = a * f,
412
- be = b * e,
413
- bf = b * f;
414
- te[0] = c * e;
415
- te[4] = -c * f;
416
- te[8] = d;
417
- te[1] = af + be * d;
418
- te[5] = ae - bf * d;
419
- te[9] = -b * c;
420
- te[2] = bf - ae * d;
421
- te[6] = be + af * d;
422
- te[10] = a * c;
423
- break;
53
+ get ELEMENTS() {
54
+ return 4;
55
+ }
56
+ /**
57
+ * @class
58
+ * @param {Number | Number[]} x
59
+ * @param {Number=} [y]
60
+ * @param {Number=} [z]
61
+ * @param {Number=} [order]
62
+ */
63
+ constructor(x = 0, y = 0, z = 0, order = Euler.DefaultOrder) {
64
+ // PERF NOTE: initialize elements as double precision numbers
65
+ super(-0, -0, -0, -0);
66
+ // eslint-disable-next-line prefer-rest-params
67
+ if (arguments.length > 0 && Array.isArray(arguments[0])) {
68
+ // eslint-disable-next-line prefer-rest-params
69
+ // @ts-expect-error
70
+ this.fromVector3(...arguments);
424
71
  }
425
-
426
- case Euler.YXZ:
427
- {
428
- const ce = c * e,
429
- cf = c * f,
430
- de = d * e,
431
- df = d * f;
432
- te[0] = ce + df * b;
433
- te[4] = de * b - cf;
434
- te[8] = a * d;
435
- te[1] = a * f;
436
- te[5] = a * e;
437
- te[9] = -b;
438
- te[2] = cf * b - de;
439
- te[6] = df + ce * b;
440
- te[10] = a * c;
441
- break;
72
+ else {
73
+ this.set(x, y, z, order);
442
74
  }
443
-
444
- case Euler.ZXY:
445
- {
446
- const ce = c * e,
447
- cf = c * f,
448
- de = d * e,
449
- df = d * f;
450
- te[0] = ce - df * b;
451
- te[4] = -a * f;
452
- te[8] = de + cf * b;
453
- te[1] = cf + de * b;
454
- te[5] = a * e;
455
- te[9] = df - ce * b;
456
- te[2] = -a * d;
457
- te[6] = b;
458
- te[10] = a * c;
459
- break;
75
+ }
76
+ fromQuaternion(quaternion) {
77
+ const [x, y, z, w] = quaternion;
78
+ const ysqr = y * y;
79
+ const t0 = -2 * (ysqr + z * z) + 1;
80
+ const t1 = +2 * (x * y + w * z);
81
+ let t2 = -2 * (x * z - w * y);
82
+ const t3 = +2 * (y * z + w * x);
83
+ const t4 = -2 * (x * x + ysqr) + 1;
84
+ t2 = t2 > 1 ? 1 : t2;
85
+ t2 = t2 < -1 ? -1 : t2;
86
+ const roll = Math.atan2(t3, t4);
87
+ const pitch = Math.asin(t2);
88
+ const yaw = Math.atan2(t1, t0);
89
+ return this.set(roll, pitch, yaw, Euler.RollPitchYaw);
90
+ }
91
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
92
+ fromObject(object) {
93
+ throw new Error('not implemented');
94
+ // return this.set(object.x, object.y, object.z, object.order);
95
+ }
96
+ // fromQuaternion(q, order) {
97
+ // this._fromRotationMat[-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
98
+ // return this.check();
99
+ // }
100
+ // If copied array does contain fourth element, preserves currently set order
101
+ copy(array) {
102
+ this[0] = array[0];
103
+ this[1] = array[1];
104
+ this[2] = array[2];
105
+ // @ts-expect-error
106
+ this[3] = Number.isFinite(array[3]) || this.order;
107
+ return this.check();
108
+ }
109
+ // Sets the three angles, and optionally sets the rotation order
110
+ // If order is not specified, preserves currently set order
111
+ set(x = 0, y = 0, z = 0, order) {
112
+ this[0] = x;
113
+ this[1] = y;
114
+ this[2] = z;
115
+ this[3] = Number.isFinite(order) ? order : this[3];
116
+ return this.check();
117
+ }
118
+ validate() {
119
+ return (validateOrder(this[3]) &&
120
+ Number.isFinite(this[0]) &&
121
+ Number.isFinite(this[1]) &&
122
+ Number.isFinite(this[2]));
123
+ }
124
+ // Does not copy the orientation element
125
+ toArray(array = [], offset = 0) {
126
+ array[offset] = this[0];
127
+ array[offset + 1] = this[1];
128
+ array[offset + 2] = this[2];
129
+ return array;
130
+ }
131
+ // Copies the orientation element
132
+ toArray4(array = [], offset = 0) {
133
+ array[offset] = this[0];
134
+ array[offset + 1] = this[1];
135
+ array[offset + 2] = this[2];
136
+ array[offset + 3] = this[3];
137
+ return array;
138
+ }
139
+ toVector3(result = [-0, -0, -0]) {
140
+ result[0] = this[0];
141
+ result[1] = this[1];
142
+ result[2] = this[2];
143
+ return result;
144
+ }
145
+ /* eslint-disable no-multi-spaces, brace-style, no-return-assign */
146
+ // x, y, z angle notation (note: only corresponds to axis in XYZ orientation)
147
+ get x() {
148
+ return this[0];
149
+ }
150
+ set x(value) {
151
+ this[0] = checkNumber(value);
152
+ }
153
+ get y() {
154
+ return this[1];
155
+ }
156
+ set y(value) {
157
+ this[1] = checkNumber(value);
158
+ }
159
+ get z() {
160
+ return this[2];
161
+ }
162
+ set z(value) {
163
+ this[2] = checkNumber(value);
164
+ }
165
+ // alpha, beta, gamma angle notation
166
+ get alpha() {
167
+ return this[0];
168
+ }
169
+ set alpha(value) {
170
+ this[0] = checkNumber(value);
171
+ }
172
+ get beta() {
173
+ return this[1];
174
+ }
175
+ set beta(value) {
176
+ this[1] = checkNumber(value);
177
+ }
178
+ get gamma() {
179
+ return this[2];
180
+ }
181
+ set gamma(value) {
182
+ this[2] = checkNumber(value);
183
+ }
184
+ // phi, theta, psi angle notation
185
+ get phi() {
186
+ return this[0];
187
+ }
188
+ set phi(value) {
189
+ this[0] = checkNumber(value);
190
+ }
191
+ get theta() {
192
+ return this[1];
193
+ }
194
+ set theta(value) {
195
+ this[1] = checkNumber(value);
196
+ }
197
+ get psi() {
198
+ return this[2];
199
+ }
200
+ set psi(value) {
201
+ this[2] = checkNumber(value);
202
+ }
203
+ // roll, pitch, yaw angle notation
204
+ get roll() {
205
+ return this[0];
206
+ }
207
+ set roll(value) {
208
+ this[0] = checkNumber(value);
209
+ }
210
+ get pitch() {
211
+ return this[1];
212
+ }
213
+ set pitch(value) {
214
+ this[1] = checkNumber(value);
215
+ }
216
+ get yaw() {
217
+ return this[2];
218
+ }
219
+ set yaw(value) {
220
+ this[2] = checkNumber(value);
221
+ }
222
+ // rotation order, in all three angle notations
223
+ get order() {
224
+ return this[3];
225
+ }
226
+ set order(value) {
227
+ this[3] = checkOrder(value);
228
+ }
229
+ // Constructors
230
+ fromVector3(v, order) {
231
+ return this.set(v[0], v[1], v[2], Number.isFinite(order) ? order : this[3]);
232
+ }
233
+ // TODO - with and without 4th element
234
+ fromArray(array, offset = 0) {
235
+ this[0] = array[0 + offset];
236
+ this[1] = array[1 + offset];
237
+ this[2] = array[2 + offset];
238
+ if (array[3] !== undefined) {
239
+ this[3] = array[3];
460
240
  }
461
-
462
- case Euler.ZYX:
463
- {
464
- const ae = a * e,
465
- af = a * f,
466
- be = b * e,
467
- bf = b * f;
468
- te[0] = c * e;
469
- te[4] = be * d - af;
470
- te[8] = ae * d + bf;
471
- te[1] = c * f;
472
- te[5] = bf * d + ae;
473
- te[9] = af * d - be;
474
- te[2] = -d;
475
- te[6] = b * c;
476
- te[10] = a * c;
477
- break;
241
+ return this.check();
242
+ }
243
+ // Common ZYX rotation order
244
+ fromRollPitchYaw(roll, pitch, yaw) {
245
+ return this.set(roll, pitch, yaw, RotationOrder.ZYX);
246
+ }
247
+ fromRotationMatrix(m, order = Euler.DefaultOrder) {
248
+ this._fromRotationMatrix(m, order);
249
+ return this.check();
250
+ }
251
+ // ACCESSORS
252
+ getRotationMatrix(m) {
253
+ return this._getRotationMatrix(m);
254
+ }
255
+ // TODO - move to Quaternion
256
+ getQuaternion() {
257
+ const q = new Quaternion();
258
+ switch (this[3]) {
259
+ case RotationOrder.XYZ:
260
+ return q.rotateX(this[0]).rotateY(this[1]).rotateZ(this[2]);
261
+ case RotationOrder.YXZ:
262
+ return q.rotateY(this[0]).rotateX(this[1]).rotateZ(this[2]);
263
+ case RotationOrder.ZXY:
264
+ return q.rotateZ(this[0]).rotateX(this[1]).rotateY(this[2]);
265
+ case RotationOrder.ZYX:
266
+ return q.rotateZ(this[0]).rotateY(this[1]).rotateX(this[2]);
267
+ case RotationOrder.YZX:
268
+ return q.rotateY(this[0]).rotateZ(this[1]).rotateX(this[2]);
269
+ case RotationOrder.XZY:
270
+ return q.rotateX(this[0]).rotateZ(this[1]).rotateY(this[2]);
271
+ default:
272
+ throw new Error(ERR_UNKNOWN_ORDER);
478
273
  }
479
-
480
- case Euler.YZX:
481
- {
482
- const ac = a * c,
483
- ad = a * d,
484
- bc = b * c,
485
- bd = b * d;
486
- te[0] = c * e;
487
- te[4] = bd - ac * f;
488
- te[8] = bc * f + ad;
489
- te[1] = f;
490
- te[5] = a * e;
491
- te[9] = -b * e;
492
- te[2] = -d * e;
493
- te[6] = ad * f + bc;
494
- te[10] = ac - bd * f;
495
- break;
274
+ }
275
+ // INTERNAL METHODS
276
+ // Conversion from Euler to rotation matrix and from matrix to Euler
277
+ // Adapted from three.js under MIT license
278
+ // // WARNING: this discards revolution information -bhouston
279
+ // reorder(newOrder) {
280
+ // const q = new Quaternion().setFromEuler(this);
281
+ // return this.setFromQuaternion(q, newOrder);
282
+ /* eslint-disable complexity, max-statements, one-var */
283
+ _fromRotationMatrix(m, order = Euler.DefaultOrder) {
284
+ // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
285
+ const m11 = m[0], m12 = m[4], m13 = m[8];
286
+ const m21 = m[1], m22 = m[5], m23 = m[9];
287
+ const m31 = m[2], m32 = m[6], m33 = m[10];
288
+ order = order || this[3];
289
+ switch (order) {
290
+ case Euler.XYZ:
291
+ this[1] = Math.asin(clamp(m13, -1, 1));
292
+ if (Math.abs(m13) < ALMOST_ONE) {
293
+ this[0] = Math.atan2(-m23, m33);
294
+ this[2] = Math.atan2(-m12, m11);
295
+ }
296
+ else {
297
+ this[0] = Math.atan2(m32, m22);
298
+ this[2] = 0;
299
+ }
300
+ break;
301
+ case Euler.YXZ:
302
+ this[0] = Math.asin(-clamp(m23, -1, 1));
303
+ if (Math.abs(m23) < ALMOST_ONE) {
304
+ this[1] = Math.atan2(m13, m33);
305
+ this[2] = Math.atan2(m21, m22);
306
+ }
307
+ else {
308
+ this[1] = Math.atan2(-m31, m11);
309
+ this[2] = 0;
310
+ }
311
+ break;
312
+ case Euler.ZXY:
313
+ this[0] = Math.asin(clamp(m32, -1, 1));
314
+ if (Math.abs(m32) < ALMOST_ONE) {
315
+ this[1] = Math.atan2(-m31, m33);
316
+ this[2] = Math.atan2(-m12, m22);
317
+ }
318
+ else {
319
+ this[1] = 0;
320
+ this[2] = Math.atan2(m21, m11);
321
+ }
322
+ break;
323
+ case Euler.ZYX:
324
+ this[1] = Math.asin(-clamp(m31, -1, 1));
325
+ if (Math.abs(m31) < ALMOST_ONE) {
326
+ this[0] = Math.atan2(m32, m33);
327
+ this[2] = Math.atan2(m21, m11);
328
+ }
329
+ else {
330
+ this[0] = 0;
331
+ this[2] = Math.atan2(-m12, m22);
332
+ }
333
+ break;
334
+ case Euler.YZX:
335
+ this[2] = Math.asin(clamp(m21, -1, 1));
336
+ if (Math.abs(m21) < ALMOST_ONE) {
337
+ this[0] = Math.atan2(-m23, m22);
338
+ this[1] = Math.atan2(-m31, m11);
339
+ }
340
+ else {
341
+ this[0] = 0;
342
+ this[1] = Math.atan2(m13, m33);
343
+ }
344
+ break;
345
+ case Euler.XZY:
346
+ this[2] = Math.asin(-clamp(m12, -1, 1));
347
+ if (Math.abs(m12) < ALMOST_ONE) {
348
+ this[0] = Math.atan2(m32, m22);
349
+ this[1] = Math.atan2(m13, m11);
350
+ }
351
+ else {
352
+ this[0] = Math.atan2(-m23, m33);
353
+ this[1] = 0;
354
+ }
355
+ break;
356
+ default:
357
+ throw new Error(ERR_UNKNOWN_ORDER);
496
358
  }
497
-
498
- case Euler.XZY:
499
- {
500
- const ac = a * c,
501
- ad = a * d,
502
- bc = b * c,
503
- bd = b * d;
504
- te[0] = c * e;
505
- te[4] = -f;
506
- te[8] = d * e;
507
- te[1] = ac * f + bd;
508
- te[5] = a * e;
509
- te[9] = ad * f - bc;
510
- te[2] = bc * f - ad;
511
- te[6] = b * e;
512
- te[10] = bd * f + ac;
513
- break;
359
+ this[3] = order;
360
+ return this;
361
+ }
362
+ _getRotationMatrix(result) {
363
+ const te = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
364
+ const x = this.x, y = this.y, z = this.z;
365
+ const a = Math.cos(x);
366
+ const c = Math.cos(y);
367
+ const e = Math.cos(z);
368
+ const b = Math.sin(x);
369
+ const d = Math.sin(y);
370
+ const f = Math.sin(z);
371
+ switch (this[3]) {
372
+ case Euler.XYZ: {
373
+ const ae = a * e, af = a * f, be = b * e, bf = b * f;
374
+ te[0] = c * e;
375
+ te[4] = -c * f;
376
+ te[8] = d;
377
+ te[1] = af + be * d;
378
+ te[5] = ae - bf * d;
379
+ te[9] = -b * c;
380
+ te[2] = bf - ae * d;
381
+ te[6] = be + af * d;
382
+ te[10] = a * c;
383
+ break;
384
+ }
385
+ case Euler.YXZ: {
386
+ const ce = c * e, cf = c * f, de = d * e, df = d * f;
387
+ te[0] = ce + df * b;
388
+ te[4] = de * b - cf;
389
+ te[8] = a * d;
390
+ te[1] = a * f;
391
+ te[5] = a * e;
392
+ te[9] = -b;
393
+ te[2] = cf * b - de;
394
+ te[6] = df + ce * b;
395
+ te[10] = a * c;
396
+ break;
397
+ }
398
+ case Euler.ZXY: {
399
+ const ce = c * e, cf = c * f, de = d * e, df = d * f;
400
+ te[0] = ce - df * b;
401
+ te[4] = -a * f;
402
+ te[8] = de + cf * b;
403
+ te[1] = cf + de * b;
404
+ te[5] = a * e;
405
+ te[9] = df - ce * b;
406
+ te[2] = -a * d;
407
+ te[6] = b;
408
+ te[10] = a * c;
409
+ break;
410
+ }
411
+ case Euler.ZYX: {
412
+ const ae = a * e, af = a * f, be = b * e, bf = b * f;
413
+ te[0] = c * e;
414
+ te[4] = be * d - af;
415
+ te[8] = ae * d + bf;
416
+ te[1] = c * f;
417
+ te[5] = bf * d + ae;
418
+ te[9] = af * d - be;
419
+ te[2] = -d;
420
+ te[6] = b * c;
421
+ te[10] = a * c;
422
+ break;
423
+ }
424
+ case Euler.YZX: {
425
+ const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
426
+ te[0] = c * e;
427
+ te[4] = bd - ac * f;
428
+ te[8] = bc * f + ad;
429
+ te[1] = f;
430
+ te[5] = a * e;
431
+ te[9] = -b * e;
432
+ te[2] = -d * e;
433
+ te[6] = ad * f + bc;
434
+ te[10] = ac - bd * f;
435
+ break;
436
+ }
437
+ case Euler.XZY: {
438
+ const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
439
+ te[0] = c * e;
440
+ te[4] = -f;
441
+ te[8] = d * e;
442
+ te[1] = ac * f + bd;
443
+ te[5] = a * e;
444
+ te[9] = ad * f - bc;
445
+ te[2] = bc * f - ad;
446
+ te[6] = b * e;
447
+ te[10] = bd * f + ac;
448
+ break;
449
+ }
450
+ default:
451
+ throw new Error(ERR_UNKNOWN_ORDER);
514
452
  }
515
-
516
- default:
517
- throw new Error(ERR_UNKNOWN_ORDER);
453
+ // last column
454
+ te[3] = 0;
455
+ te[7] = 0;
456
+ te[11] = 0;
457
+ // bottom row
458
+ te[12] = 0;
459
+ te[13] = 0;
460
+ te[14] = 0;
461
+ te[15] = 1;
462
+ return te;
463
+ }
464
+ toQuaternion() {
465
+ // Abbreviations for the various angular functions
466
+ const cy = Math.cos(this.yaw * 0.5);
467
+ const sy = Math.sin(this.yaw * 0.5);
468
+ const cr = Math.cos(this.roll * 0.5);
469
+ const sr = Math.sin(this.roll * 0.5);
470
+ const cp = Math.cos(this.pitch * 0.5);
471
+ const sp = Math.sin(this.pitch * 0.5);
472
+ const w = cy * cr * cp + sy * sr * sp;
473
+ const x = cy * sr * cp - sy * cr * sp;
474
+ const y = cy * cr * sp + sy * sr * cp;
475
+ const z = sy * cr * cp - cy * sr * sp;
476
+ return new Quaternion(x, y, z, w);
518
477
  }
519
-
520
- te[3] = 0;
521
- te[7] = 0;
522
- te[11] = 0;
523
- te[12] = 0;
524
- te[13] = 0;
525
- te[14] = 0;
526
- te[15] = 1;
527
- return te;
528
- }
529
-
530
- toQuaternion() {
531
- const cy = Math.cos(this.yaw * 0.5);
532
- const sy = Math.sin(this.yaw * 0.5);
533
- const cr = Math.cos(this.roll * 0.5);
534
- const sr = Math.sin(this.roll * 0.5);
535
- const cp = Math.cos(this.pitch * 0.5);
536
- const sp = Math.sin(this.pitch * 0.5);
537
- const w = cy * cr * cp + sy * sr * sp;
538
- const x = cy * sr * cp - sy * cr * sp;
539
- const y = cy * cr * sp + sy * sr * cp;
540
- const z = sy * cr * cp - cy * sr * sp;
541
- return new Quaternion(x, y, z, w);
542
- }
543
-
544
478
  }
545
-
479
+ // HELPER FUNCTIONS
546
480
  function validateOrder(value) {
547
- return value >= 0 && value < 6;
481
+ return value >= 0 && value < 6;
548
482
  }
549
-
550
483
  function checkOrder(value) {
551
- if (value < 0 && value >= 6) {
552
- throw new Error(ERR_UNKNOWN_ORDER);
553
- }
554
-
555
- return value;
484
+ if (value < 0 && value >= 6) {
485
+ throw new Error(ERR_UNKNOWN_ORDER);
486
+ }
487
+ return value;
556
488
  }
557
- //# sourceMappingURL=euler.js.map