@math.gl/core 3.6.3 → 4.0.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 (135) hide show
  1. package/dist/classes/base/math-array.d.ts +3 -3
  2. package/dist/classes/base/math-array.d.ts.map +1 -1
  3. package/dist/{esm/classes → classes}/base/math-array.js +3 -2
  4. package/dist/classes/base/math-array.js.map +1 -0
  5. package/dist/classes/base/matrix.d.ts.map +1 -1
  6. package/dist/{esm/classes → classes}/base/matrix.js +3 -3
  7. package/dist/classes/base/matrix.js.map +1 -0
  8. package/dist/{esm/classes → classes}/base/vector.js +3 -3
  9. package/dist/classes/base/vector.js.map +1 -0
  10. package/dist/classes/euler.d.ts +1 -1
  11. package/dist/classes/euler.d.ts.map +1 -1
  12. package/dist/{esm/classes → classes}/euler.js +4 -4
  13. package/dist/classes/euler.js.map +1 -0
  14. package/dist/classes/matrix3.d.ts +1 -1
  15. package/dist/classes/matrix3.d.ts.map +1 -1
  16. package/dist/{esm/classes → classes}/matrix3.js +4 -4
  17. package/dist/classes/matrix3.js.map +1 -0
  18. package/dist/classes/matrix4.d.ts +1 -1
  19. package/dist/classes/matrix4.d.ts.map +1 -1
  20. package/dist/{esm/classes → classes}/matrix4.js +3 -3
  21. package/dist/classes/matrix4.js.map +1 -0
  22. package/dist/classes/pose.d.ts +1 -1
  23. package/dist/classes/pose.d.ts.map +1 -1
  24. package/dist/{esm/classes → classes}/pose.js +3 -3
  25. package/dist/classes/pose.js.map +1 -0
  26. package/dist/classes/quaternion.d.ts +1 -1
  27. package/dist/classes/quaternion.d.ts.map +1 -1
  28. package/dist/{esm/classes → classes}/quaternion.js +3 -3
  29. package/dist/classes/quaternion.js.map +1 -0
  30. package/dist/classes/spherical-coordinates.d.ts +3 -3
  31. package/dist/classes/spherical-coordinates.d.ts.map +1 -1
  32. package/dist/{esm/classes → classes}/spherical-coordinates.js +3 -3
  33. package/dist/classes/spherical-coordinates.js.map +1 -0
  34. package/dist/classes/vector2.d.ts.map +1 -1
  35. package/dist/{esm/classes → classes}/vector2.js +4 -4
  36. package/dist/classes/vector2.js.map +1 -0
  37. package/dist/classes/vector3.d.ts.map +1 -1
  38. package/dist/{esm/classes → classes}/vector3.js +4 -4
  39. package/dist/classes/vector3.js.map +1 -0
  40. package/dist/classes/vector4.d.ts +1 -1
  41. package/dist/classes/vector4.d.ts.map +1 -1
  42. package/dist/{esm/classes → classes}/vector4.js +4 -4
  43. package/dist/classes/vector4.js.map +1 -0
  44. package/dist/{es5/docs → docs}/README.md +0 -0
  45. package/dist/index.cjs +2335 -0
  46. package/dist/index.js +16 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/{esm/lib → lib}/assert.js +0 -0
  49. package/dist/lib/assert.js.map +1 -0
  50. package/dist/lib/common.d.ts +1 -1
  51. package/dist/lib/common.d.ts.map +1 -1
  52. package/dist/{esm/lib → lib}/common.js +3 -7
  53. package/dist/lib/common.js.map +1 -0
  54. package/dist/{esm/lib → lib}/gl-matrix-extras.js +0 -0
  55. package/dist/lib/gl-matrix-extras.js.map +1 -0
  56. package/dist/{esm/lib → lib}/gl-matrix.d.js +0 -0
  57. package/dist/{es5/lib → lib}/gl-matrix.d.js.map +0 -0
  58. package/dist/{esm/lib → lib}/math-utils.js +0 -0
  59. package/dist/lib/math-utils.js.map +1 -0
  60. package/dist/lib/validators.d.ts +1 -1
  61. package/dist/lib/validators.d.ts.map +1 -1
  62. package/dist/{esm/lib → lib}/validators.js +1 -1
  63. package/dist/lib/validators.js.map +1 -0
  64. package/package.json +7 -6
  65. package/src/classes/base/math-array.ts +10 -6
  66. package/src/classes/base/matrix.ts +1 -1
  67. package/src/classes/base/vector.ts +1 -1
  68. package/src/classes/euler.ts +4 -4
  69. package/src/classes/matrix3.ts +8 -4
  70. package/src/classes/matrix4.ts +7 -2
  71. package/src/classes/quaternion.ts +6 -4
  72. package/src/classes/spherical-coordinates.ts +2 -1
  73. package/src/classes/vector2.ts +1 -0
  74. package/src/classes/vector3.ts +1 -0
  75. package/src/classes/vector4.ts +6 -4
  76. package/src/lib/common.ts +3 -7
  77. package/src/lib/validators.ts +2 -2
  78. package/dist/es5/classes/base/math-array.js +0 -348
  79. package/dist/es5/classes/base/math-array.js.map +0 -1
  80. package/dist/es5/classes/base/matrix.js +0 -108
  81. package/dist/es5/classes/base/matrix.js.map +0 -1
  82. package/dist/es5/classes/base/vector.js +0 -210
  83. package/dist/es5/classes/base/vector.js.map +0 -1
  84. package/dist/es5/classes/euler.js +0 -654
  85. package/dist/es5/classes/euler.js.map +0 -1
  86. package/dist/es5/classes/matrix3.js +0 -284
  87. package/dist/es5/classes/matrix3.js.map +0 -1
  88. package/dist/es5/classes/matrix4.js +0 -574
  89. package/dist/es5/classes/matrix4.js.map +0 -1
  90. package/dist/es5/classes/pose.js +0 -159
  91. package/dist/es5/classes/pose.js.map +0 -1
  92. package/dist/es5/classes/quaternion.js +0 -323
  93. package/dist/es5/classes/quaternion.js.map +0 -1
  94. package/dist/es5/classes/spherical-coordinates.js +0 -208
  95. package/dist/es5/classes/spherical-coordinates.js.map +0 -1
  96. package/dist/es5/classes/vector2.js +0 -156
  97. package/dist/es5/classes/vector2.js.map +0 -1
  98. package/dist/es5/classes/vector3.js +0 -213
  99. package/dist/es5/classes/vector3.js.map +0 -1
  100. package/dist/es5/classes/vector4.js +0 -185
  101. package/dist/es5/classes/vector4.js.map +0 -1
  102. package/dist/es5/index.js +0 -236
  103. package/dist/es5/index.js.map +0 -1
  104. package/dist/es5/lib/assert.js +0 -13
  105. package/dist/es5/lib/assert.js.map +0 -1
  106. package/dist/es5/lib/common.js +0 -255
  107. package/dist/es5/lib/common.js.map +0 -1
  108. package/dist/es5/lib/gl-matrix-extras.js +0 -61
  109. package/dist/es5/lib/gl-matrix-extras.js.map +0 -1
  110. package/dist/es5/lib/gl-matrix.d.js +0 -2
  111. package/dist/es5/lib/math-utils.js +0 -34
  112. package/dist/es5/lib/math-utils.js.map +0 -1
  113. package/dist/es5/lib/validators.js +0 -53
  114. package/dist/es5/lib/validators.js.map +0 -1
  115. package/dist/esm/classes/base/math-array.js.map +0 -1
  116. package/dist/esm/classes/base/matrix.js.map +0 -1
  117. package/dist/esm/classes/base/vector.js.map +0 -1
  118. package/dist/esm/classes/euler.js.map +0 -1
  119. package/dist/esm/classes/matrix3.js.map +0 -1
  120. package/dist/esm/classes/matrix4.js.map +0 -1
  121. package/dist/esm/classes/pose.js.map +0 -1
  122. package/dist/esm/classes/quaternion.js.map +0 -1
  123. package/dist/esm/classes/spherical-coordinates.js.map +0 -1
  124. package/dist/esm/classes/vector2.js.map +0 -1
  125. package/dist/esm/classes/vector3.js.map +0 -1
  126. package/dist/esm/classes/vector4.js.map +0 -1
  127. package/dist/esm/docs/README.md +0 -0
  128. package/dist/esm/index.js +0 -16
  129. package/dist/esm/index.js.map +0 -1
  130. package/dist/esm/lib/assert.js.map +0 -1
  131. package/dist/esm/lib/common.js.map +0 -1
  132. package/dist/esm/lib/gl-matrix-extras.js.map +0 -1
  133. package/dist/esm/lib/gl-matrix.d.js.map +0 -1
  134. package/dist/esm/lib/math-utils.js.map +0 -1
  135. package/dist/esm/lib/validators.js.map +0 -1
package/dist/index.cjs ADDED
@@ -0,0 +1,2335 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+
25
+ // src/index.ts
26
+ var src_exports = {};
27
+ __export(src_exports, {
28
+ Euler: () => Euler,
29
+ Matrix3: () => Matrix3,
30
+ Matrix4: () => Matrix4,
31
+ Pose: () => Pose,
32
+ Quaternion: () => Quaternion,
33
+ SphericalCoordinates: () => SphericalCoordinates,
34
+ Vector2: () => Vector2,
35
+ Vector3: () => Vector3,
36
+ Vector4: () => Vector4,
37
+ _Euler: () => Euler,
38
+ _MathUtils: () => math_utils_default,
39
+ _Pose: () => Pose,
40
+ _SphericalCoordinates: () => SphericalCoordinates,
41
+ acos: () => acos,
42
+ asin: () => asin,
43
+ assert: () => assert,
44
+ atan: () => atan,
45
+ clamp: () => clamp,
46
+ clone: () => clone,
47
+ config: () => config,
48
+ configure: () => configure,
49
+ cos: () => cos,
50
+ degrees: () => degrees,
51
+ equals: () => equals,
52
+ exactEquals: () => exactEquals,
53
+ formatValue: () => formatValue,
54
+ isArray: () => isArray,
55
+ lerp: () => lerp,
56
+ radians: () => radians,
57
+ sin: () => sin,
58
+ tan: () => tan,
59
+ toDegrees: () => toDegrees,
60
+ toRadians: () => toRadians,
61
+ withEpsilon: () => withEpsilon
62
+ });
63
+ module.exports = __toCommonJS(src_exports);
64
+
65
+ // src/lib/common.ts
66
+ var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
67
+ var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
68
+ var config = {
69
+ EPSILON: 1e-12,
70
+ debug: false,
71
+ precision: 4,
72
+ printTypes: false,
73
+ printDegrees: false,
74
+ printRowMajor: true
75
+ };
76
+ function configure(options) {
77
+ Object.assign(config, options);
78
+ return config;
79
+ }
80
+ function formatValue(value, { precision = config.precision } = {}) {
81
+ value = round(value);
82
+ return `${parseFloat(value.toPrecision(precision))}`;
83
+ }
84
+ function isArray(value) {
85
+ return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
86
+ }
87
+ function clone(array) {
88
+ return "clone" in array ? array.clone() : array.slice();
89
+ }
90
+ function toRadians(degrees2) {
91
+ return radians(degrees2);
92
+ }
93
+ function toDegrees(radians2) {
94
+ return degrees(radians2);
95
+ }
96
+ function radians(degrees2, result) {
97
+ return map(degrees2, (degrees3) => degrees3 * DEGREES_TO_RADIANS, result);
98
+ }
99
+ function degrees(radians2, result) {
100
+ return map(radians2, (radians3) => radians3 * RADIANS_TO_DEGREES, result);
101
+ }
102
+ function sin(radians2, result) {
103
+ return map(radians2, (angle2) => Math.sin(angle2), result);
104
+ }
105
+ function cos(radians2, result) {
106
+ return map(radians2, (angle2) => Math.cos(angle2), result);
107
+ }
108
+ function tan(radians2, result) {
109
+ return map(radians2, (angle2) => Math.tan(angle2), result);
110
+ }
111
+ function asin(radians2, result) {
112
+ return map(radians2, (angle2) => Math.asin(angle2), result);
113
+ }
114
+ function acos(radians2, result) {
115
+ return map(radians2, (angle2) => Math.acos(angle2), result);
116
+ }
117
+ function atan(radians2, result) {
118
+ return map(radians2, (angle2) => Math.atan(angle2), result);
119
+ }
120
+ function clamp(value, min, max) {
121
+ return map(value, (value2) => Math.max(min, Math.min(max, value2)));
122
+ }
123
+ function lerp(a, b, t) {
124
+ if (isArray(a)) {
125
+ return a.map((ai, i) => lerp(ai, b[i], t));
126
+ }
127
+ return t * b + (1 - t) * a;
128
+ }
129
+ function equals(a, b, epsilon) {
130
+ const oldEpsilon = config.EPSILON;
131
+ if (epsilon) {
132
+ config.EPSILON = epsilon;
133
+ }
134
+ try {
135
+ if (a === b) {
136
+ return true;
137
+ }
138
+ if (isArray(a) && isArray(b)) {
139
+ if (a.length !== b.length) {
140
+ return false;
141
+ }
142
+ for (let i = 0; i < a.length; ++i) {
143
+ if (!equals(a[i], b[i])) {
144
+ return false;
145
+ }
146
+ }
147
+ return true;
148
+ }
149
+ if (a && a.equals) {
150
+ return a.equals(b);
151
+ }
152
+ if (b && b.equals) {
153
+ return b.equals(a);
154
+ }
155
+ if (typeof a === "number" && typeof b === "number") {
156
+ return Math.abs(a - b) <= config.EPSILON * Math.max(1, Math.abs(a), Math.abs(b));
157
+ }
158
+ return false;
159
+ } finally {
160
+ config.EPSILON = oldEpsilon;
161
+ }
162
+ }
163
+ function exactEquals(a, b) {
164
+ if (a === b) {
165
+ return true;
166
+ }
167
+ if (a && typeof a === "object" && b && typeof b === "object") {
168
+ if (a.constructor !== b.constructor) {
169
+ return false;
170
+ }
171
+ if (a.exactEquals) {
172
+ return a.exactEquals(b);
173
+ }
174
+ }
175
+ if (isArray(a) && isArray(b)) {
176
+ if (a.length !== b.length) {
177
+ return false;
178
+ }
179
+ for (let i = 0; i < a.length; ++i) {
180
+ if (!exactEquals(a[i], b[i])) {
181
+ return false;
182
+ }
183
+ }
184
+ return true;
185
+ }
186
+ return false;
187
+ }
188
+ function withEpsilon(epsilon, func) {
189
+ const oldPrecision = config.EPSILON;
190
+ config.EPSILON = epsilon;
191
+ let value;
192
+ try {
193
+ value = func();
194
+ } finally {
195
+ config.EPSILON = oldPrecision;
196
+ }
197
+ return value;
198
+ }
199
+ function round(value) {
200
+ return Math.round(value / config.EPSILON) * config.EPSILON;
201
+ }
202
+ function duplicateArray(array) {
203
+ return array.clone ? array.clone() : new Array(array.length);
204
+ }
205
+ function map(value, func, result) {
206
+ if (isArray(value)) {
207
+ const array = value;
208
+ result = result || duplicateArray(array);
209
+ for (let i = 0; i < result.length && i < array.length; ++i) {
210
+ const val = typeof value === "number" ? value : value[i];
211
+ result[i] = func(val, i, result);
212
+ }
213
+ return result;
214
+ }
215
+ return func(value);
216
+ }
217
+
218
+ // src/classes/base/math-array.ts
219
+ var MathArray = class extends Array {
220
+ clone() {
221
+ return new this.constructor().copy(this);
222
+ }
223
+ fromArray(array, offset = 0) {
224
+ for (let i = 0; i < this.ELEMENTS; ++i) {
225
+ this[i] = array[i + offset];
226
+ }
227
+ return this.check();
228
+ }
229
+ toArray(targetArray = [], offset = 0) {
230
+ for (let i = 0; i < this.ELEMENTS; ++i) {
231
+ targetArray[offset + i] = this[i];
232
+ }
233
+ return targetArray;
234
+ }
235
+ from(arrayOrObject) {
236
+ return Array.isArray(arrayOrObject) ? this.copy(arrayOrObject) : this.fromObject(arrayOrObject);
237
+ }
238
+ to(arrayOrObject) {
239
+ if (arrayOrObject === this) {
240
+ return this;
241
+ }
242
+ return isArray(arrayOrObject) ? this.toArray(arrayOrObject) : this.toObject(arrayOrObject);
243
+ }
244
+ toTarget(target) {
245
+ return target ? this.to(target) : this;
246
+ }
247
+ toFloat32Array() {
248
+ return new Float32Array(this);
249
+ }
250
+ toString() {
251
+ return this.formatString(config);
252
+ }
253
+ formatString(opts) {
254
+ let string = "";
255
+ for (let i = 0; i < this.ELEMENTS; ++i) {
256
+ string += (i > 0 ? ", " : "") + formatValue(this[i], opts);
257
+ }
258
+ return `${opts.printTypes ? this.constructor.name : ""}[${string}]`;
259
+ }
260
+ equals(array) {
261
+ if (!array || this.length !== array.length) {
262
+ return false;
263
+ }
264
+ for (let i = 0; i < this.ELEMENTS; ++i) {
265
+ if (!equals(this[i], array[i])) {
266
+ return false;
267
+ }
268
+ }
269
+ return true;
270
+ }
271
+ exactEquals(array) {
272
+ if (!array || this.length !== array.length) {
273
+ return false;
274
+ }
275
+ for (let i = 0; i < this.ELEMENTS; ++i) {
276
+ if (this[i] !== array[i]) {
277
+ return false;
278
+ }
279
+ }
280
+ return true;
281
+ }
282
+ negate() {
283
+ for (let i = 0; i < this.ELEMENTS; ++i) {
284
+ this[i] = -this[i];
285
+ }
286
+ return this.check();
287
+ }
288
+ lerp(a, b, t) {
289
+ if (t === void 0) {
290
+ return this.lerp(this, a, b);
291
+ }
292
+ for (let i = 0; i < this.ELEMENTS; ++i) {
293
+ const ai = a[i];
294
+ const endValue = typeof b === "number" ? b : b[i];
295
+ this[i] = ai + t * (endValue - ai);
296
+ }
297
+ return this.check();
298
+ }
299
+ min(vector) {
300
+ for (let i = 0; i < this.ELEMENTS; ++i) {
301
+ this[i] = Math.min(vector[i], this[i]);
302
+ }
303
+ return this.check();
304
+ }
305
+ max(vector) {
306
+ for (let i = 0; i < this.ELEMENTS; ++i) {
307
+ this[i] = Math.max(vector[i], this[i]);
308
+ }
309
+ return this.check();
310
+ }
311
+ clamp(minVector, maxVector) {
312
+ for (let i = 0; i < this.ELEMENTS; ++i) {
313
+ this[i] = Math.min(Math.max(this[i], minVector[i]), maxVector[i]);
314
+ }
315
+ return this.check();
316
+ }
317
+ add(...vectors) {
318
+ for (const vector of vectors) {
319
+ for (let i = 0; i < this.ELEMENTS; ++i) {
320
+ this[i] += vector[i];
321
+ }
322
+ }
323
+ return this.check();
324
+ }
325
+ subtract(...vectors) {
326
+ for (const vector of vectors) {
327
+ for (let i = 0; i < this.ELEMENTS; ++i) {
328
+ this[i] -= vector[i];
329
+ }
330
+ }
331
+ return this.check();
332
+ }
333
+ scale(scale4) {
334
+ if (typeof scale4 === "number") {
335
+ for (let i = 0; i < this.ELEMENTS; ++i) {
336
+ this[i] *= scale4;
337
+ }
338
+ } else {
339
+ for (let i = 0; i < this.ELEMENTS && i < scale4.length; ++i) {
340
+ this[i] *= scale4[i];
341
+ }
342
+ }
343
+ return this.check();
344
+ }
345
+ multiplyByScalar(scalar) {
346
+ for (let i = 0; i < this.ELEMENTS; ++i) {
347
+ this[i] *= scalar;
348
+ }
349
+ return this.check();
350
+ }
351
+ check() {
352
+ if (config.debug && !this.validate()) {
353
+ throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);
354
+ }
355
+ return this;
356
+ }
357
+ validate() {
358
+ let valid = this.length === this.ELEMENTS;
359
+ for (let i = 0; i < this.ELEMENTS; ++i) {
360
+ valid = valid && Number.isFinite(this[i]);
361
+ }
362
+ return valid;
363
+ }
364
+ sub(a) {
365
+ return this.subtract(a);
366
+ }
367
+ setScalar(a) {
368
+ for (let i = 0; i < this.ELEMENTS; ++i) {
369
+ this[i] = a;
370
+ }
371
+ return this.check();
372
+ }
373
+ addScalar(a) {
374
+ for (let i = 0; i < this.ELEMENTS; ++i) {
375
+ this[i] += a;
376
+ }
377
+ return this.check();
378
+ }
379
+ subScalar(a) {
380
+ return this.addScalar(-a);
381
+ }
382
+ multiplyScalar(scalar) {
383
+ for (let i = 0; i < this.ELEMENTS; ++i) {
384
+ this[i] *= scalar;
385
+ }
386
+ return this.check();
387
+ }
388
+ divideScalar(a) {
389
+ return this.multiplyByScalar(1 / a);
390
+ }
391
+ clampScalar(min, max) {
392
+ for (let i = 0; i < this.ELEMENTS; ++i) {
393
+ this[i] = Math.min(Math.max(this[i], min), max);
394
+ }
395
+ return this.check();
396
+ }
397
+ get elements() {
398
+ return this;
399
+ }
400
+ };
401
+
402
+ // src/lib/validators.ts
403
+ function validateVector(v, length3) {
404
+ if (v.length !== length3) {
405
+ return false;
406
+ }
407
+ for (let i = 0; i < v.length; ++i) {
408
+ if (!Number.isFinite(v[i])) {
409
+ return false;
410
+ }
411
+ }
412
+ return true;
413
+ }
414
+ function checkNumber(value) {
415
+ if (!Number.isFinite(value)) {
416
+ throw new Error(`Invalid number ${value}`);
417
+ }
418
+ return value;
419
+ }
420
+ function checkVector(v, length3, callerName = "") {
421
+ if (config.debug && !validateVector(v, length3)) {
422
+ throw new Error(`math.gl: ${callerName} some fields set to invalid numbers'`);
423
+ }
424
+ return v;
425
+ }
426
+
427
+ // src/lib/assert.ts
428
+ function assert(condition, message) {
429
+ if (!condition) {
430
+ throw new Error(`math.gl assertion ${message}`);
431
+ }
432
+ }
433
+
434
+ // src/classes/base/vector.ts
435
+ var Vector = class extends MathArray {
436
+ get x() {
437
+ return this[0];
438
+ }
439
+ set x(value) {
440
+ this[0] = checkNumber(value);
441
+ }
442
+ get y() {
443
+ return this[1];
444
+ }
445
+ set y(value) {
446
+ this[1] = checkNumber(value);
447
+ }
448
+ len() {
449
+ return Math.sqrt(this.lengthSquared());
450
+ }
451
+ magnitude() {
452
+ return this.len();
453
+ }
454
+ lengthSquared() {
455
+ let length3 = 0;
456
+ for (let i = 0; i < this.ELEMENTS; ++i) {
457
+ length3 += this[i] * this[i];
458
+ }
459
+ return length3;
460
+ }
461
+ magnitudeSquared() {
462
+ return this.lengthSquared();
463
+ }
464
+ distance(mathArray) {
465
+ return Math.sqrt(this.distanceSquared(mathArray));
466
+ }
467
+ distanceSquared(mathArray) {
468
+ let length3 = 0;
469
+ for (let i = 0; i < this.ELEMENTS; ++i) {
470
+ const dist = this[i] - mathArray[i];
471
+ length3 += dist * dist;
472
+ }
473
+ return checkNumber(length3);
474
+ }
475
+ dot(mathArray) {
476
+ let product = 0;
477
+ for (let i = 0; i < this.ELEMENTS; ++i) {
478
+ product += this[i] * mathArray[i];
479
+ }
480
+ return checkNumber(product);
481
+ }
482
+ normalize() {
483
+ const length3 = this.magnitude();
484
+ if (length3 !== 0) {
485
+ for (let i = 0; i < this.ELEMENTS; ++i) {
486
+ this[i] /= length3;
487
+ }
488
+ }
489
+ return this.check();
490
+ }
491
+ multiply(...vectors) {
492
+ for (const vector of vectors) {
493
+ for (let i = 0; i < this.ELEMENTS; ++i) {
494
+ this[i] *= vector[i];
495
+ }
496
+ }
497
+ return this.check();
498
+ }
499
+ divide(...vectors) {
500
+ for (const vector of vectors) {
501
+ for (let i = 0; i < this.ELEMENTS; ++i) {
502
+ this[i] /= vector[i];
503
+ }
504
+ }
505
+ return this.check();
506
+ }
507
+ lengthSq() {
508
+ return this.lengthSquared();
509
+ }
510
+ distanceTo(vector) {
511
+ return this.distance(vector);
512
+ }
513
+ distanceToSquared(vector) {
514
+ return this.distanceSquared(vector);
515
+ }
516
+ getComponent(i) {
517
+ assert(i >= 0 && i < this.ELEMENTS, "index is out of range");
518
+ return checkNumber(this[i]);
519
+ }
520
+ setComponent(i, value) {
521
+ assert(i >= 0 && i < this.ELEMENTS, "index is out of range");
522
+ this[i] = value;
523
+ return this.check();
524
+ }
525
+ addVectors(a, b) {
526
+ return this.copy(a).add(b);
527
+ }
528
+ subVectors(a, b) {
529
+ return this.copy(a).subtract(b);
530
+ }
531
+ multiplyVectors(a, b) {
532
+ return this.copy(a).multiply(b);
533
+ }
534
+ addScaledVector(a, b) {
535
+ return this.add(new this.constructor(a).multiplyScalar(b));
536
+ }
537
+ };
538
+
539
+ // src/classes/vector2.ts
540
+ var vec2 = __toESM(require("gl-matrix/vec2"), 1);
541
+
542
+ // src/lib/gl-matrix-extras.ts
543
+ function vec2_transformMat4AsVector(out, a, m) {
544
+ const x = a[0];
545
+ const y = a[1];
546
+ const w = m[3] * x + m[7] * y || 1;
547
+ out[0] = (m[0] * x + m[4] * y) / w;
548
+ out[1] = (m[1] * x + m[5] * y) / w;
549
+ return out;
550
+ }
551
+ function vec3_transformMat4AsVector(out, a, m) {
552
+ const x = a[0];
553
+ const y = a[1];
554
+ const z = a[2];
555
+ const w = m[3] * x + m[7] * y + m[11] * z || 1;
556
+ out[0] = (m[0] * x + m[4] * y + m[8] * z) / w;
557
+ out[1] = (m[1] * x + m[5] * y + m[9] * z) / w;
558
+ out[2] = (m[2] * x + m[6] * y + m[10] * z) / w;
559
+ return out;
560
+ }
561
+ function vec3_transformMat2(out, a, m) {
562
+ const x = a[0];
563
+ const y = a[1];
564
+ out[0] = m[0] * x + m[2] * y;
565
+ out[1] = m[1] * x + m[3] * y;
566
+ out[2] = a[2];
567
+ return out;
568
+ }
569
+ function vec4_transformMat2(out, a, m) {
570
+ const x = a[0];
571
+ const y = a[1];
572
+ out[0] = m[0] * x + m[2] * y;
573
+ out[1] = m[1] * x + m[3] * y;
574
+ out[2] = a[2];
575
+ out[3] = a[3];
576
+ return out;
577
+ }
578
+ function vec4_transformMat3(out, a, m) {
579
+ const x = a[0];
580
+ const y = a[1];
581
+ const z = a[2];
582
+ out[0] = m[0] * x + m[3] * y + m[6] * z;
583
+ out[1] = m[1] * x + m[4] * y + m[7] * z;
584
+ out[2] = m[2] * x + m[5] * y + m[8] * z;
585
+ out[3] = a[3];
586
+ return out;
587
+ }
588
+
589
+ // src/classes/vector2.ts
590
+ var Vector2 = class extends Vector {
591
+ constructor(x = 0, y = 0) {
592
+ super(2);
593
+ if (isArray(x) && arguments.length === 1) {
594
+ this.copy(x);
595
+ } else {
596
+ if (config.debug) {
597
+ checkNumber(x);
598
+ checkNumber(y);
599
+ }
600
+ this[0] = x;
601
+ this[1] = y;
602
+ }
603
+ }
604
+ set(x, y) {
605
+ this[0] = x;
606
+ this[1] = y;
607
+ return this.check();
608
+ }
609
+ copy(array) {
610
+ this[0] = array[0];
611
+ this[1] = array[1];
612
+ return this.check();
613
+ }
614
+ fromObject(object) {
615
+ if (config.debug) {
616
+ checkNumber(object.x);
617
+ checkNumber(object.y);
618
+ }
619
+ this[0] = object.x;
620
+ this[1] = object.y;
621
+ return this.check();
622
+ }
623
+ toObject(object) {
624
+ object.x = this[0];
625
+ object.y = this[1];
626
+ return object;
627
+ }
628
+ get ELEMENTS() {
629
+ return 2;
630
+ }
631
+ horizontalAngle() {
632
+ return Math.atan2(this.y, this.x);
633
+ }
634
+ verticalAngle() {
635
+ return Math.atan2(this.x, this.y);
636
+ }
637
+ transform(matrix4) {
638
+ return this.transformAsPoint(matrix4);
639
+ }
640
+ transformAsPoint(matrix4) {
641
+ vec2.transformMat4(this, this, matrix4);
642
+ return this.check();
643
+ }
644
+ transformAsVector(matrix4) {
645
+ vec2_transformMat4AsVector(this, this, matrix4);
646
+ return this.check();
647
+ }
648
+ transformByMatrix3(matrix3) {
649
+ vec2.transformMat3(this, this, matrix3);
650
+ return this.check();
651
+ }
652
+ transformByMatrix2x3(matrix2x3) {
653
+ vec2.transformMat2d(this, this, matrix2x3);
654
+ return this.check();
655
+ }
656
+ transformByMatrix2(matrix2) {
657
+ vec2.transformMat2(this, this, matrix2);
658
+ return this.check();
659
+ }
660
+ };
661
+
662
+ // src/classes/vector3.ts
663
+ var vec3 = __toESM(require("gl-matrix/vec3"), 1);
664
+ var ORIGIN = [0, 0, 0];
665
+ var ZERO;
666
+ var Vector3 = class extends Vector {
667
+ static get ZERO() {
668
+ if (!ZERO) {
669
+ ZERO = new Vector3(0, 0, 0);
670
+ Object.freeze(ZERO);
671
+ }
672
+ return ZERO;
673
+ }
674
+ constructor(x = 0, y = 0, z = 0) {
675
+ super(-0, -0, -0);
676
+ if (arguments.length === 1 && isArray(x)) {
677
+ this.copy(x);
678
+ } else {
679
+ if (config.debug) {
680
+ checkNumber(x);
681
+ checkNumber(y);
682
+ checkNumber(z);
683
+ }
684
+ this[0] = x;
685
+ this[1] = y;
686
+ this[2] = z;
687
+ }
688
+ }
689
+ set(x, y, z) {
690
+ this[0] = x;
691
+ this[1] = y;
692
+ this[2] = z;
693
+ return this.check();
694
+ }
695
+ copy(array) {
696
+ this[0] = array[0];
697
+ this[1] = array[1];
698
+ this[2] = array[2];
699
+ return this.check();
700
+ }
701
+ fromObject(object) {
702
+ if (config.debug) {
703
+ checkNumber(object.x);
704
+ checkNumber(object.y);
705
+ checkNumber(object.z);
706
+ }
707
+ this[0] = object.x;
708
+ this[1] = object.y;
709
+ this[2] = object.z;
710
+ return this.check();
711
+ }
712
+ toObject(object) {
713
+ object.x = this[0];
714
+ object.y = this[1];
715
+ object.z = this[2];
716
+ return object;
717
+ }
718
+ get ELEMENTS() {
719
+ return 3;
720
+ }
721
+ get z() {
722
+ return this[2];
723
+ }
724
+ set z(value) {
725
+ this[2] = checkNumber(value);
726
+ }
727
+ angle(vector) {
728
+ return vec3.angle(this, vector);
729
+ }
730
+ cross(vector) {
731
+ vec3.cross(this, this, vector);
732
+ return this.check();
733
+ }
734
+ rotateX({ radians: radians2, origin = ORIGIN }) {
735
+ vec3.rotateX(this, this, origin, radians2);
736
+ return this.check();
737
+ }
738
+ rotateY({ radians: radians2, origin = ORIGIN }) {
739
+ vec3.rotateY(this, this, origin, radians2);
740
+ return this.check();
741
+ }
742
+ rotateZ({ radians: radians2, origin = ORIGIN }) {
743
+ vec3.rotateZ(this, this, origin, radians2);
744
+ return this.check();
745
+ }
746
+ transform(matrix4) {
747
+ return this.transformAsPoint(matrix4);
748
+ }
749
+ transformAsPoint(matrix4) {
750
+ vec3.transformMat4(this, this, matrix4);
751
+ return this.check();
752
+ }
753
+ transformAsVector(matrix4) {
754
+ vec3_transformMat4AsVector(this, this, matrix4);
755
+ return this.check();
756
+ }
757
+ transformByMatrix3(matrix3) {
758
+ vec3.transformMat3(this, this, matrix3);
759
+ return this.check();
760
+ }
761
+ transformByMatrix2(matrix2) {
762
+ vec3_transformMat2(this, this, matrix2);
763
+ return this.check();
764
+ }
765
+ transformByQuaternion(quaternion) {
766
+ vec3.transformQuat(this, this, quaternion);
767
+ return this.check();
768
+ }
769
+ };
770
+
771
+ // src/classes/vector4.ts
772
+ var vec4 = __toESM(require("gl-matrix/vec3"), 1);
773
+ var ZERO2;
774
+ var Vector4 = class extends Vector {
775
+ static get ZERO() {
776
+ if (!ZERO2) {
777
+ ZERO2 = new Vector4(0, 0, 0, 0);
778
+ Object.freeze(ZERO2);
779
+ }
780
+ return ZERO2;
781
+ }
782
+ constructor(x = 0, y = 0, z = 0, w = 0) {
783
+ super(-0, -0, -0, -0);
784
+ if (isArray(x) && arguments.length === 1) {
785
+ this.copy(x);
786
+ } else {
787
+ if (config.debug) {
788
+ checkNumber(x);
789
+ checkNumber(y);
790
+ checkNumber(z);
791
+ checkNumber(w);
792
+ }
793
+ this[0] = x;
794
+ this[1] = y;
795
+ this[2] = z;
796
+ this[3] = w;
797
+ }
798
+ }
799
+ set(x, y, z, w) {
800
+ this[0] = x;
801
+ this[1] = y;
802
+ this[2] = z;
803
+ this[3] = w;
804
+ return this.check();
805
+ }
806
+ copy(array) {
807
+ this[0] = array[0];
808
+ this[1] = array[1];
809
+ this[2] = array[2];
810
+ this[3] = array[3];
811
+ return this.check();
812
+ }
813
+ fromObject(object) {
814
+ if (config.debug) {
815
+ checkNumber(object.x);
816
+ checkNumber(object.y);
817
+ checkNumber(object.z);
818
+ checkNumber(object.w);
819
+ }
820
+ this[0] = object.x;
821
+ this[1] = object.y;
822
+ this[2] = object.z;
823
+ this[3] = object.w;
824
+ return this;
825
+ }
826
+ toObject(object) {
827
+ object.x = this[0];
828
+ object.y = this[1];
829
+ object.z = this[2];
830
+ object.w = this[3];
831
+ return object;
832
+ }
833
+ get ELEMENTS() {
834
+ return 4;
835
+ }
836
+ get z() {
837
+ return this[2];
838
+ }
839
+ set z(value) {
840
+ this[2] = checkNumber(value);
841
+ }
842
+ get w() {
843
+ return this[3];
844
+ }
845
+ set w(value) {
846
+ this[3] = checkNumber(value);
847
+ }
848
+ transform(matrix4) {
849
+ vec4.transformMat4(this, this, matrix4);
850
+ return this.check();
851
+ }
852
+ transformByMatrix3(matrix3) {
853
+ vec4_transformMat3(this, this, matrix3);
854
+ return this.check();
855
+ }
856
+ transformByMatrix2(matrix2) {
857
+ vec4_transformMat2(this, this, matrix2);
858
+ return this.check();
859
+ }
860
+ transformByQuaternion(quaternion) {
861
+ vec4.transformQuat(this, this, quaternion);
862
+ return this.check();
863
+ }
864
+ applyMatrix4(m) {
865
+ m.transform(this, this);
866
+ return this;
867
+ }
868
+ };
869
+
870
+ // src/classes/base/matrix.ts
871
+ var Matrix = class extends MathArray {
872
+ toString() {
873
+ let string = "[";
874
+ if (config.printRowMajor) {
875
+ string += "row-major:";
876
+ for (let row = 0; row < this.RANK; ++row) {
877
+ for (let col = 0; col < this.RANK; ++col) {
878
+ string += ` ${this[col * this.RANK + row]}`;
879
+ }
880
+ }
881
+ } else {
882
+ string += "column-major:";
883
+ for (let i = 0; i < this.ELEMENTS; ++i) {
884
+ string += ` ${this[i]}`;
885
+ }
886
+ }
887
+ string += "]";
888
+ return string;
889
+ }
890
+ getElementIndex(row, col) {
891
+ return col * this.RANK + row;
892
+ }
893
+ getElement(row, col) {
894
+ return this[col * this.RANK + row];
895
+ }
896
+ setElement(row, col, value) {
897
+ this[col * this.RANK + row] = checkNumber(value);
898
+ return this;
899
+ }
900
+ getColumn(columnIndex, result = new Array(this.RANK).fill(-0)) {
901
+ const firstIndex = columnIndex * this.RANK;
902
+ for (let i = 0; i < this.RANK; ++i) {
903
+ result[i] = this[firstIndex + i];
904
+ }
905
+ return result;
906
+ }
907
+ setColumn(columnIndex, columnVector) {
908
+ const firstIndex = columnIndex * this.RANK;
909
+ for (let i = 0; i < this.RANK; ++i) {
910
+ this[firstIndex + i] = columnVector[i];
911
+ }
912
+ return this;
913
+ }
914
+ };
915
+
916
+ // src/classes/matrix3.ts
917
+ var mat3 = __toESM(require("gl-matrix/mat3"), 1);
918
+ var vec22 = __toESM(require("gl-matrix/vec2"), 1);
919
+ var vec32 = __toESM(require("gl-matrix/vec3"), 1);
920
+ var INDICES = /* @__PURE__ */ ((INDICES3) => {
921
+ INDICES3[INDICES3["COL0ROW0"] = 0] = "COL0ROW0";
922
+ INDICES3[INDICES3["COL0ROW1"] = 1] = "COL0ROW1";
923
+ INDICES3[INDICES3["COL0ROW2"] = 2] = "COL0ROW2";
924
+ INDICES3[INDICES3["COL1ROW0"] = 3] = "COL1ROW0";
925
+ INDICES3[INDICES3["COL1ROW1"] = 4] = "COL1ROW1";
926
+ INDICES3[INDICES3["COL1ROW2"] = 5] = "COL1ROW2";
927
+ INDICES3[INDICES3["COL2ROW0"] = 6] = "COL2ROW0";
928
+ INDICES3[INDICES3["COL2ROW1"] = 7] = "COL2ROW1";
929
+ INDICES3[INDICES3["COL2ROW2"] = 8] = "COL2ROW2";
930
+ return INDICES3;
931
+ })(INDICES || {});
932
+ var IDENTITY_MATRIX = Object.freeze([1, 0, 0, 0, 1, 0, 0, 0, 1]);
933
+ var Matrix3 = class extends Matrix {
934
+ static get IDENTITY() {
935
+ return getIdentityMatrix();
936
+ }
937
+ static get ZERO() {
938
+ return getZeroMatrix();
939
+ }
940
+ get ELEMENTS() {
941
+ return 9;
942
+ }
943
+ get RANK() {
944
+ return 3;
945
+ }
946
+ get INDICES() {
947
+ return INDICES;
948
+ }
949
+ constructor(array, ...args) {
950
+ super(-0, -0, -0, -0, -0, -0, -0, -0, -0);
951
+ if (arguments.length === 1 && Array.isArray(array)) {
952
+ this.copy(array);
953
+ } else if (args.length > 0) {
954
+ this.copy([array, ...args]);
955
+ } else {
956
+ this.identity();
957
+ }
958
+ }
959
+ copy(array) {
960
+ this[0] = array[0];
961
+ this[1] = array[1];
962
+ this[2] = array[2];
963
+ this[3] = array[3];
964
+ this[4] = array[4];
965
+ this[5] = array[5];
966
+ this[6] = array[6];
967
+ this[7] = array[7];
968
+ this[8] = array[8];
969
+ return this.check();
970
+ }
971
+ identity() {
972
+ return this.copy(IDENTITY_MATRIX);
973
+ }
974
+ fromObject(object) {
975
+ return this.check();
976
+ }
977
+ fromQuaternion(q) {
978
+ mat3.fromQuat(this, q);
979
+ return this.check();
980
+ }
981
+ set(m00, m10, m20, m01, m11, m21, m02, m12, m22) {
982
+ this[0] = m00;
983
+ this[1] = m10;
984
+ this[2] = m20;
985
+ this[3] = m01;
986
+ this[4] = m11;
987
+ this[5] = m21;
988
+ this[6] = m02;
989
+ this[7] = m12;
990
+ this[8] = m22;
991
+ return this.check();
992
+ }
993
+ setRowMajor(m00, m01, m02, m10, m11, m12, m20, m21, m22) {
994
+ this[0] = m00;
995
+ this[1] = m10;
996
+ this[2] = m20;
997
+ this[3] = m01;
998
+ this[4] = m11;
999
+ this[5] = m21;
1000
+ this[6] = m02;
1001
+ this[7] = m12;
1002
+ this[8] = m22;
1003
+ return this.check();
1004
+ }
1005
+ determinant() {
1006
+ return mat3.determinant(this);
1007
+ }
1008
+ transpose() {
1009
+ mat3.transpose(this, this);
1010
+ return this.check();
1011
+ }
1012
+ invert() {
1013
+ mat3.invert(this, this);
1014
+ return this.check();
1015
+ }
1016
+ multiplyLeft(a) {
1017
+ mat3.multiply(this, a, this);
1018
+ return this.check();
1019
+ }
1020
+ multiplyRight(a) {
1021
+ mat3.multiply(this, this, a);
1022
+ return this.check();
1023
+ }
1024
+ rotate(radians2) {
1025
+ mat3.rotate(this, this, radians2);
1026
+ return this.check();
1027
+ }
1028
+ scale(factor) {
1029
+ if (Array.isArray(factor)) {
1030
+ mat3.scale(this, this, factor);
1031
+ } else {
1032
+ mat3.scale(this, this, [factor, factor]);
1033
+ }
1034
+ return this.check();
1035
+ }
1036
+ translate(vec) {
1037
+ mat3.translate(this, this, vec);
1038
+ return this.check();
1039
+ }
1040
+ transform(vector, result) {
1041
+ let out;
1042
+ switch (vector.length) {
1043
+ case 2:
1044
+ out = vec22.transformMat3(result || [-0, -0], vector, this);
1045
+ break;
1046
+ case 3:
1047
+ out = vec32.transformMat3(result || [-0, -0, -0], vector, this);
1048
+ break;
1049
+ case 4:
1050
+ out = vec4_transformMat3(result || [-0, -0, -0, -0], vector, this);
1051
+ break;
1052
+ default:
1053
+ throw new Error("Illegal vector");
1054
+ }
1055
+ checkVector(out, vector.length);
1056
+ return out;
1057
+ }
1058
+ transformVector(vector, result) {
1059
+ return this.transform(vector, result);
1060
+ }
1061
+ transformVector2(vector, result) {
1062
+ return this.transform(vector, result);
1063
+ }
1064
+ transformVector3(vector, result) {
1065
+ return this.transform(vector, result);
1066
+ }
1067
+ };
1068
+ var ZERO_MATRIX3;
1069
+ var IDENTITY_MATRIX3 = null;
1070
+ function getZeroMatrix() {
1071
+ if (!ZERO_MATRIX3) {
1072
+ ZERO_MATRIX3 = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
1073
+ Object.freeze(ZERO_MATRIX3);
1074
+ }
1075
+ return ZERO_MATRIX3;
1076
+ }
1077
+ function getIdentityMatrix() {
1078
+ if (!IDENTITY_MATRIX3) {
1079
+ IDENTITY_MATRIX3 = new Matrix3();
1080
+ Object.freeze(IDENTITY_MATRIX3);
1081
+ }
1082
+ return IDENTITY_MATRIX3;
1083
+ }
1084
+
1085
+ // src/classes/matrix4.ts
1086
+ var mat4 = __toESM(require("gl-matrix/mat4"), 1);
1087
+ var vec23 = __toESM(require("gl-matrix/vec2"), 1);
1088
+ var vec33 = __toESM(require("gl-matrix/vec3"), 1);
1089
+ var vec42 = __toESM(require("gl-matrix/vec4"), 1);
1090
+ var INDICES2 = /* @__PURE__ */ ((INDICES3) => {
1091
+ INDICES3[INDICES3["COL0ROW0"] = 0] = "COL0ROW0";
1092
+ INDICES3[INDICES3["COL0ROW1"] = 1] = "COL0ROW1";
1093
+ INDICES3[INDICES3["COL0ROW2"] = 2] = "COL0ROW2";
1094
+ INDICES3[INDICES3["COL0ROW3"] = 3] = "COL0ROW3";
1095
+ INDICES3[INDICES3["COL1ROW0"] = 4] = "COL1ROW0";
1096
+ INDICES3[INDICES3["COL1ROW1"] = 5] = "COL1ROW1";
1097
+ INDICES3[INDICES3["COL1ROW2"] = 6] = "COL1ROW2";
1098
+ INDICES3[INDICES3["COL1ROW3"] = 7] = "COL1ROW3";
1099
+ INDICES3[INDICES3["COL2ROW0"] = 8] = "COL2ROW0";
1100
+ INDICES3[INDICES3["COL2ROW1"] = 9] = "COL2ROW1";
1101
+ INDICES3[INDICES3["COL2ROW2"] = 10] = "COL2ROW2";
1102
+ INDICES3[INDICES3["COL2ROW3"] = 11] = "COL2ROW3";
1103
+ INDICES3[INDICES3["COL3ROW0"] = 12] = "COL3ROW0";
1104
+ INDICES3[INDICES3["COL3ROW1"] = 13] = "COL3ROW1";
1105
+ INDICES3[INDICES3["COL3ROW2"] = 14] = "COL3ROW2";
1106
+ INDICES3[INDICES3["COL3ROW3"] = 15] = "COL3ROW3";
1107
+ return INDICES3;
1108
+ })(INDICES2 || {});
1109
+ var DEFAULT_FOVY = 45 * Math.PI / 180;
1110
+ var DEFAULT_ASPECT = 1;
1111
+ var DEFAULT_NEAR = 0.1;
1112
+ var DEFAULT_FAR = 500;
1113
+ var IDENTITY_MATRIX2 = Object.freeze([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
1114
+ var Matrix4 = class extends Matrix {
1115
+ static get IDENTITY() {
1116
+ return getIdentityMatrix2();
1117
+ }
1118
+ static get ZERO() {
1119
+ return getZeroMatrix2();
1120
+ }
1121
+ get ELEMENTS() {
1122
+ return 16;
1123
+ }
1124
+ get RANK() {
1125
+ return 4;
1126
+ }
1127
+ get INDICES() {
1128
+ return INDICES2;
1129
+ }
1130
+ constructor(array) {
1131
+ super(-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0);
1132
+ if (arguments.length === 1 && Array.isArray(array)) {
1133
+ this.copy(array);
1134
+ } else {
1135
+ this.identity();
1136
+ }
1137
+ }
1138
+ copy(array) {
1139
+ this[0] = array[0];
1140
+ this[1] = array[1];
1141
+ this[2] = array[2];
1142
+ this[3] = array[3];
1143
+ this[4] = array[4];
1144
+ this[5] = array[5];
1145
+ this[6] = array[6];
1146
+ this[7] = array[7];
1147
+ this[8] = array[8];
1148
+ this[9] = array[9];
1149
+ this[10] = array[10];
1150
+ this[11] = array[11];
1151
+ this[12] = array[12];
1152
+ this[13] = array[13];
1153
+ this[14] = array[14];
1154
+ this[15] = array[15];
1155
+ return this.check();
1156
+ }
1157
+ set(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33) {
1158
+ this[0] = m00;
1159
+ this[1] = m10;
1160
+ this[2] = m20;
1161
+ this[3] = m30;
1162
+ this[4] = m01;
1163
+ this[5] = m11;
1164
+ this[6] = m21;
1165
+ this[7] = m31;
1166
+ this[8] = m02;
1167
+ this[9] = m12;
1168
+ this[10] = m22;
1169
+ this[11] = m32;
1170
+ this[12] = m03;
1171
+ this[13] = m13;
1172
+ this[14] = m23;
1173
+ this[15] = m33;
1174
+ return this.check();
1175
+ }
1176
+ setRowMajor(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
1177
+ this[0] = m00;
1178
+ this[1] = m10;
1179
+ this[2] = m20;
1180
+ this[3] = m30;
1181
+ this[4] = m01;
1182
+ this[5] = m11;
1183
+ this[6] = m21;
1184
+ this[7] = m31;
1185
+ this[8] = m02;
1186
+ this[9] = m12;
1187
+ this[10] = m22;
1188
+ this[11] = m32;
1189
+ this[12] = m03;
1190
+ this[13] = m13;
1191
+ this[14] = m23;
1192
+ this[15] = m33;
1193
+ return this.check();
1194
+ }
1195
+ toRowMajor(result) {
1196
+ result[0] = this[0];
1197
+ result[1] = this[4];
1198
+ result[2] = this[8];
1199
+ result[3] = this[12];
1200
+ result[4] = this[1];
1201
+ result[5] = this[5];
1202
+ result[6] = this[9];
1203
+ result[7] = this[13];
1204
+ result[8] = this[2];
1205
+ result[9] = this[6];
1206
+ result[10] = this[10];
1207
+ result[11] = this[14];
1208
+ result[12] = this[3];
1209
+ result[13] = this[7];
1210
+ result[14] = this[11];
1211
+ result[15] = this[15];
1212
+ return result;
1213
+ }
1214
+ identity() {
1215
+ return this.copy(IDENTITY_MATRIX2);
1216
+ }
1217
+ fromObject(object) {
1218
+ return this.check();
1219
+ }
1220
+ fromQuaternion(quaternion) {
1221
+ mat4.fromQuat(this, quaternion);
1222
+ return this.check();
1223
+ }
1224
+ frustum(view) {
1225
+ const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
1226
+ if (far === Infinity) {
1227
+ computeInfinitePerspectiveOffCenter(this, left, right, bottom, top, near);
1228
+ } else {
1229
+ mat4.frustum(this, left, right, bottom, top, near, far);
1230
+ }
1231
+ return this.check();
1232
+ }
1233
+ lookAt(view) {
1234
+ const { eye, center = [0, 0, 0], up = [0, 1, 0] } = view;
1235
+ mat4.lookAt(this, eye, center, up);
1236
+ return this.check();
1237
+ }
1238
+ ortho(view) {
1239
+ const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
1240
+ mat4.ortho(this, left, right, bottom, top, near, far);
1241
+ return this.check();
1242
+ }
1243
+ orthographic(view) {
1244
+ const {
1245
+ fovy = DEFAULT_FOVY,
1246
+ aspect = DEFAULT_ASPECT,
1247
+ focalDistance = 1,
1248
+ near = DEFAULT_NEAR,
1249
+ far = DEFAULT_FAR
1250
+ } = view;
1251
+ checkRadians(fovy);
1252
+ const halfY = fovy / 2;
1253
+ const top = focalDistance * Math.tan(halfY);
1254
+ const right = top * aspect;
1255
+ return this.ortho({
1256
+ left: -right,
1257
+ right,
1258
+ bottom: -top,
1259
+ top,
1260
+ near,
1261
+ far
1262
+ });
1263
+ }
1264
+ perspective(view) {
1265
+ const { fovy = 45 * Math.PI / 180, aspect = 1, near = 0.1, far = 500 } = view;
1266
+ checkRadians(fovy);
1267
+ mat4.perspective(this, fovy, aspect, near, far);
1268
+ return this.check();
1269
+ }
1270
+ determinant() {
1271
+ return mat4.determinant(this);
1272
+ }
1273
+ getScale(result = [-0, -0, -0]) {
1274
+ result[0] = Math.sqrt(this[0] * this[0] + this[1] * this[1] + this[2] * this[2]);
1275
+ result[1] = Math.sqrt(this[4] * this[4] + this[5] * this[5] + this[6] * this[6]);
1276
+ result[2] = Math.sqrt(this[8] * this[8] + this[9] * this[9] + this[10] * this[10]);
1277
+ return result;
1278
+ }
1279
+ getTranslation(result = [-0, -0, -0]) {
1280
+ result[0] = this[12];
1281
+ result[1] = this[13];
1282
+ result[2] = this[14];
1283
+ return result;
1284
+ }
1285
+ getRotation(result, scaleResult) {
1286
+ result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
1287
+ scaleResult = scaleResult || [-0, -0, -0];
1288
+ const scale4 = this.getScale(scaleResult);
1289
+ const inverseScale0 = 1 / scale4[0];
1290
+ const inverseScale1 = 1 / scale4[1];
1291
+ const inverseScale2 = 1 / scale4[2];
1292
+ result[0] = this[0] * inverseScale0;
1293
+ result[1] = this[1] * inverseScale1;
1294
+ result[2] = this[2] * inverseScale2;
1295
+ result[3] = 0;
1296
+ result[4] = this[4] * inverseScale0;
1297
+ result[5] = this[5] * inverseScale1;
1298
+ result[6] = this[6] * inverseScale2;
1299
+ result[7] = 0;
1300
+ result[8] = this[8] * inverseScale0;
1301
+ result[9] = this[9] * inverseScale1;
1302
+ result[10] = this[10] * inverseScale2;
1303
+ result[11] = 0;
1304
+ result[12] = 0;
1305
+ result[13] = 0;
1306
+ result[14] = 0;
1307
+ result[15] = 1;
1308
+ return result;
1309
+ }
1310
+ getRotationMatrix3(result, scaleResult) {
1311
+ result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0];
1312
+ scaleResult = scaleResult || [-0, -0, -0];
1313
+ const scale4 = this.getScale(scaleResult);
1314
+ const inverseScale0 = 1 / scale4[0];
1315
+ const inverseScale1 = 1 / scale4[1];
1316
+ const inverseScale2 = 1 / scale4[2];
1317
+ result[0] = this[0] * inverseScale0;
1318
+ result[1] = this[1] * inverseScale1;
1319
+ result[2] = this[2] * inverseScale2;
1320
+ result[3] = this[4] * inverseScale0;
1321
+ result[4] = this[5] * inverseScale1;
1322
+ result[5] = this[6] * inverseScale2;
1323
+ result[6] = this[8] * inverseScale0;
1324
+ result[7] = this[9] * inverseScale1;
1325
+ result[8] = this[10] * inverseScale2;
1326
+ return result;
1327
+ }
1328
+ transpose() {
1329
+ mat4.transpose(this, this);
1330
+ return this.check();
1331
+ }
1332
+ invert() {
1333
+ mat4.invert(this, this);
1334
+ return this.check();
1335
+ }
1336
+ multiplyLeft(a) {
1337
+ mat4.multiply(this, a, this);
1338
+ return this.check();
1339
+ }
1340
+ multiplyRight(a) {
1341
+ mat4.multiply(this, this, a);
1342
+ return this.check();
1343
+ }
1344
+ rotateX(radians2) {
1345
+ mat4.rotateX(this, this, radians2);
1346
+ return this.check();
1347
+ }
1348
+ rotateY(radians2) {
1349
+ mat4.rotateY(this, this, radians2);
1350
+ return this.check();
1351
+ }
1352
+ rotateZ(radians2) {
1353
+ mat4.rotateZ(this, this, radians2);
1354
+ return this.check();
1355
+ }
1356
+ rotateXYZ(angleXYZ) {
1357
+ return this.rotateX(angleXYZ[0]).rotateY(angleXYZ[1]).rotateZ(angleXYZ[2]);
1358
+ }
1359
+ rotateAxis(radians2, axis) {
1360
+ mat4.rotate(this, this, radians2, axis);
1361
+ return this.check();
1362
+ }
1363
+ scale(factor) {
1364
+ mat4.scale(this, this, Array.isArray(factor) ? factor : [factor, factor, factor]);
1365
+ return this.check();
1366
+ }
1367
+ translate(vector) {
1368
+ mat4.translate(this, this, vector);
1369
+ return this.check();
1370
+ }
1371
+ transform(vector, result) {
1372
+ if (vector.length === 4) {
1373
+ result = vec42.transformMat4(result || [-0, -0, -0, -0], vector, this);
1374
+ checkVector(result, 4);
1375
+ return result;
1376
+ }
1377
+ return this.transformAsPoint(vector, result);
1378
+ }
1379
+ transformAsPoint(vector, result) {
1380
+ const { length: length3 } = vector;
1381
+ let out;
1382
+ switch (length3) {
1383
+ case 2:
1384
+ out = vec23.transformMat4(result || [-0, -0], vector, this);
1385
+ break;
1386
+ case 3:
1387
+ out = vec33.transformMat4(result || [-0, -0, -0], vector, this);
1388
+ break;
1389
+ default:
1390
+ throw new Error("Illegal vector");
1391
+ }
1392
+ checkVector(out, vector.length);
1393
+ return out;
1394
+ }
1395
+ transformAsVector(vector, result) {
1396
+ let out;
1397
+ switch (vector.length) {
1398
+ case 2:
1399
+ out = vec2_transformMat4AsVector(result || [-0, -0], vector, this);
1400
+ break;
1401
+ case 3:
1402
+ out = vec3_transformMat4AsVector(result || [-0, -0, -0], vector, this);
1403
+ break;
1404
+ default:
1405
+ throw new Error("Illegal vector");
1406
+ }
1407
+ checkVector(out, vector.length);
1408
+ return out;
1409
+ }
1410
+ transformPoint(vector, result) {
1411
+ return this.transformAsPoint(vector, result);
1412
+ }
1413
+ transformVector(vector, result) {
1414
+ return this.transformAsPoint(vector, result);
1415
+ }
1416
+ transformDirection(vector, result) {
1417
+ return this.transformAsVector(vector, result);
1418
+ }
1419
+ makeRotationX(radians2) {
1420
+ return this.identity().rotateX(radians2);
1421
+ }
1422
+ makeTranslation(x, y, z) {
1423
+ return this.identity().translate([x, y, z]);
1424
+ }
1425
+ };
1426
+ var ZERO3;
1427
+ var IDENTITY;
1428
+ function getZeroMatrix2() {
1429
+ if (!ZERO3) {
1430
+ ZERO3 = new Matrix4([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
1431
+ Object.freeze(ZERO3);
1432
+ }
1433
+ return ZERO3;
1434
+ }
1435
+ function getIdentityMatrix2() {
1436
+ if (!IDENTITY) {
1437
+ IDENTITY = new Matrix4();
1438
+ Object.freeze(IDENTITY);
1439
+ }
1440
+ return IDENTITY;
1441
+ }
1442
+ function checkRadians(possiblyDegrees) {
1443
+ if (possiblyDegrees > Math.PI * 2) {
1444
+ throw Error("expected radians");
1445
+ }
1446
+ }
1447
+ function computeInfinitePerspectiveOffCenter(result, left, right, bottom, top, near) {
1448
+ const column0Row0 = 2 * near / (right - left);
1449
+ const column1Row1 = 2 * near / (top - bottom);
1450
+ const column2Row0 = (right + left) / (right - left);
1451
+ const column2Row1 = (top + bottom) / (top - bottom);
1452
+ const column2Row2 = -1;
1453
+ const column2Row3 = -1;
1454
+ const column3Row2 = -2 * near;
1455
+ result[0] = column0Row0;
1456
+ result[1] = 0;
1457
+ result[2] = 0;
1458
+ result[3] = 0;
1459
+ result[4] = 0;
1460
+ result[5] = column1Row1;
1461
+ result[6] = 0;
1462
+ result[7] = 0;
1463
+ result[8] = column2Row0;
1464
+ result[9] = column2Row1;
1465
+ result[10] = column2Row2;
1466
+ result[11] = column2Row3;
1467
+ result[12] = 0;
1468
+ result[13] = 0;
1469
+ result[14] = column3Row2;
1470
+ result[15] = 0;
1471
+ return result;
1472
+ }
1473
+
1474
+ // src/classes/quaternion.ts
1475
+ var quat = __toESM(require("gl-matrix/quat"), 1);
1476
+ var vec43 = __toESM(require("gl-matrix/vec4"), 1);
1477
+ var IDENTITY_QUATERNION = [0, 0, 0, 1];
1478
+ var Quaternion = class extends MathArray {
1479
+ constructor(x = 0, y = 0, z = 0, w = 1) {
1480
+ super(-0, -0, -0, -0);
1481
+ if (Array.isArray(x) && arguments.length === 1) {
1482
+ this.copy(x);
1483
+ } else {
1484
+ this.set(x, y, z, w);
1485
+ }
1486
+ }
1487
+ copy(array) {
1488
+ this[0] = array[0];
1489
+ this[1] = array[1];
1490
+ this[2] = array[2];
1491
+ this[3] = array[3];
1492
+ return this.check();
1493
+ }
1494
+ set(x, y, z, w) {
1495
+ this[0] = x;
1496
+ this[1] = y;
1497
+ this[2] = z;
1498
+ this[3] = w;
1499
+ return this.check();
1500
+ }
1501
+ fromObject(object) {
1502
+ this[0] = object.x;
1503
+ this[1] = object.y;
1504
+ this[2] = object.z;
1505
+ this[3] = object.w;
1506
+ return this.check();
1507
+ }
1508
+ fromMatrix3(m) {
1509
+ quat.fromMat3(this, m);
1510
+ return this.check();
1511
+ }
1512
+ fromAxisRotation(axis, rad) {
1513
+ quat.setAxisAngle(this, axis, rad);
1514
+ return this.check();
1515
+ }
1516
+ identity() {
1517
+ quat.identity(this);
1518
+ return this.check();
1519
+ }
1520
+ setAxisAngle(axis, rad) {
1521
+ return this.fromAxisRotation(axis, rad);
1522
+ }
1523
+ get ELEMENTS() {
1524
+ return 4;
1525
+ }
1526
+ get x() {
1527
+ return this[0];
1528
+ }
1529
+ set x(value) {
1530
+ this[0] = checkNumber(value);
1531
+ }
1532
+ get y() {
1533
+ return this[1];
1534
+ }
1535
+ set y(value) {
1536
+ this[1] = checkNumber(value);
1537
+ }
1538
+ get z() {
1539
+ return this[2];
1540
+ }
1541
+ set z(value) {
1542
+ this[2] = checkNumber(value);
1543
+ }
1544
+ get w() {
1545
+ return this[3];
1546
+ }
1547
+ set w(value) {
1548
+ this[3] = checkNumber(value);
1549
+ }
1550
+ len() {
1551
+ return quat.length(this);
1552
+ }
1553
+ lengthSquared() {
1554
+ return quat.squaredLength(this);
1555
+ }
1556
+ dot(a) {
1557
+ return quat.dot(this, a);
1558
+ }
1559
+ rotationTo(vectorA, vectorB) {
1560
+ quat.rotationTo(this, vectorA, vectorB);
1561
+ return this.check();
1562
+ }
1563
+ add(a) {
1564
+ quat.add(this, this, a);
1565
+ return this.check();
1566
+ }
1567
+ calculateW() {
1568
+ quat.calculateW(this, this);
1569
+ return this.check();
1570
+ }
1571
+ conjugate() {
1572
+ quat.conjugate(this, this);
1573
+ return this.check();
1574
+ }
1575
+ invert() {
1576
+ quat.invert(this, this);
1577
+ return this.check();
1578
+ }
1579
+ lerp(a, b, t) {
1580
+ if (t === void 0) {
1581
+ return this.lerp(this, a, b);
1582
+ }
1583
+ quat.lerp(this, a, b, t);
1584
+ return this.check();
1585
+ }
1586
+ multiplyRight(a) {
1587
+ quat.multiply(this, this, a);
1588
+ return this.check();
1589
+ }
1590
+ multiplyLeft(a) {
1591
+ quat.multiply(this, a, this);
1592
+ return this.check();
1593
+ }
1594
+ normalize() {
1595
+ const length3 = this.len();
1596
+ const l = length3 > 0 ? 1 / length3 : 0;
1597
+ this[0] = this[0] * l;
1598
+ this[1] = this[1] * l;
1599
+ this[2] = this[2] * l;
1600
+ this[3] = this[3] * l;
1601
+ if (length3 === 0) {
1602
+ this[3] = 1;
1603
+ }
1604
+ return this.check();
1605
+ }
1606
+ rotateX(rad) {
1607
+ quat.rotateX(this, this, rad);
1608
+ return this.check();
1609
+ }
1610
+ rotateY(rad) {
1611
+ quat.rotateY(this, this, rad);
1612
+ return this.check();
1613
+ }
1614
+ rotateZ(rad) {
1615
+ quat.rotateZ(this, this, rad);
1616
+ return this.check();
1617
+ }
1618
+ scale(b) {
1619
+ quat.scale(this, this, b);
1620
+ return this.check();
1621
+ }
1622
+ slerp(arg0, arg1, arg2) {
1623
+ let start;
1624
+ let target;
1625
+ let ratio;
1626
+ switch (arguments.length) {
1627
+ case 1:
1628
+ ({
1629
+ start = IDENTITY_QUATERNION,
1630
+ target,
1631
+ ratio
1632
+ } = arg0);
1633
+ break;
1634
+ case 2:
1635
+ start = this;
1636
+ target = arg0;
1637
+ ratio = arg1;
1638
+ break;
1639
+ default:
1640
+ start = arg0;
1641
+ target = arg1;
1642
+ ratio = arg2;
1643
+ }
1644
+ quat.slerp(this, start, target, ratio);
1645
+ return this.check();
1646
+ }
1647
+ transformVector4(vector, result = new Vector4()) {
1648
+ vec43.transformQuat(result, vector, this);
1649
+ return checkVector(result, 4);
1650
+ }
1651
+ lengthSq() {
1652
+ return this.lengthSquared();
1653
+ }
1654
+ setFromAxisAngle(axis, rad) {
1655
+ return this.setAxisAngle(axis, rad);
1656
+ }
1657
+ premultiply(a) {
1658
+ return this.multiplyLeft(a);
1659
+ }
1660
+ multiply(a) {
1661
+ return this.multiplyRight(a);
1662
+ }
1663
+ };
1664
+
1665
+ // src/classes/spherical-coordinates.ts
1666
+ var vec34 = __toESM(require("gl-matrix/vec3"), 1);
1667
+ var EPSILON = 1e-6;
1668
+ var EARTH_RADIUS_METERS = 6371e3;
1669
+ var SphericalCoordinates = class {
1670
+ constructor({
1671
+ phi = 0,
1672
+ theta = 0,
1673
+ radius = 1,
1674
+ bearing,
1675
+ pitch,
1676
+ altitude,
1677
+ radiusScale = EARTH_RADIUS_METERS
1678
+ } = {}) {
1679
+ this.phi = phi;
1680
+ this.theta = theta;
1681
+ this.radius = radius || altitude || 1;
1682
+ this.radiusScale = radiusScale || 1;
1683
+ if (bearing !== void 0) {
1684
+ this.bearing = bearing;
1685
+ }
1686
+ if (pitch !== void 0) {
1687
+ this.pitch = pitch;
1688
+ }
1689
+ this.check();
1690
+ }
1691
+ toString() {
1692
+ return this.formatString(config);
1693
+ }
1694
+ formatString({ printTypes = false }) {
1695
+ const f = formatValue;
1696
+ return `${printTypes ? "Spherical" : ""}[rho:${f(this.radius)},theta:${f(this.theta)},phi:${f(this.phi)}]`;
1697
+ }
1698
+ equals(other) {
1699
+ return equals(this.radius, other.radius) && equals(this.theta, other.theta) && equals(this.phi, other.phi);
1700
+ }
1701
+ exactEquals(other) {
1702
+ return this.radius === other.radius && this.theta === other.theta && this.phi === other.phi;
1703
+ }
1704
+ get bearing() {
1705
+ return 180 - degrees(this.phi);
1706
+ }
1707
+ set bearing(v) {
1708
+ this.phi = Math.PI - radians(v);
1709
+ }
1710
+ get pitch() {
1711
+ return degrees(this.theta);
1712
+ }
1713
+ set pitch(v) {
1714
+ this.theta = radians(v);
1715
+ }
1716
+ get longitude() {
1717
+ return degrees(this.phi);
1718
+ }
1719
+ get latitude() {
1720
+ return degrees(this.theta);
1721
+ }
1722
+ get lng() {
1723
+ return degrees(this.phi);
1724
+ }
1725
+ get lat() {
1726
+ return degrees(this.theta);
1727
+ }
1728
+ get z() {
1729
+ return (this.radius - 1) * this.radiusScale;
1730
+ }
1731
+ set(radius, phi, theta) {
1732
+ this.radius = radius;
1733
+ this.phi = phi;
1734
+ this.theta = theta;
1735
+ return this.check();
1736
+ }
1737
+ clone() {
1738
+ return new SphericalCoordinates().copy(this);
1739
+ }
1740
+ copy(other) {
1741
+ this.radius = other.radius;
1742
+ this.phi = other.phi;
1743
+ this.theta = other.theta;
1744
+ return this.check();
1745
+ }
1746
+ fromLngLatZ([lng, lat, z]) {
1747
+ this.radius = 1 + z / this.radiusScale;
1748
+ this.phi = radians(lat);
1749
+ this.theta = radians(lng);
1750
+ return this.check();
1751
+ }
1752
+ fromVector3(v) {
1753
+ this.radius = vec34.length(v);
1754
+ if (this.radius > 0) {
1755
+ this.theta = Math.atan2(v[0], v[1]);
1756
+ this.phi = Math.acos(clamp(v[2] / this.radius, -1, 1));
1757
+ }
1758
+ return this.check();
1759
+ }
1760
+ toVector3() {
1761
+ return new Vector3(0, 0, this.radius).rotateX({ radians: this.theta }).rotateZ({ radians: this.phi });
1762
+ }
1763
+ makeSafe() {
1764
+ this.phi = Math.max(EPSILON, Math.min(Math.PI - EPSILON, this.phi));
1765
+ return this;
1766
+ }
1767
+ check() {
1768
+ if (!Number.isFinite(this.phi) || !Number.isFinite(this.theta) || !(this.radius > 0)) {
1769
+ throw new Error("SphericalCoordinates: some fields set to invalid numbers");
1770
+ }
1771
+ return this;
1772
+ }
1773
+ };
1774
+
1775
+ // src/classes/euler.ts
1776
+ var ERR_UNKNOWN_ORDER = "Unknown Euler angle order";
1777
+ var ALMOST_ONE = 0.99999;
1778
+ var RotationOrder = /* @__PURE__ */ ((RotationOrder2) => {
1779
+ RotationOrder2[RotationOrder2["ZYX"] = 0] = "ZYX";
1780
+ RotationOrder2[RotationOrder2["YXZ"] = 1] = "YXZ";
1781
+ RotationOrder2[RotationOrder2["XZY"] = 2] = "XZY";
1782
+ RotationOrder2[RotationOrder2["ZXY"] = 3] = "ZXY";
1783
+ RotationOrder2[RotationOrder2["YZX"] = 4] = "YZX";
1784
+ RotationOrder2[RotationOrder2["XYZ"] = 5] = "XYZ";
1785
+ return RotationOrder2;
1786
+ })(RotationOrder || {});
1787
+ var Euler = class extends MathArray {
1788
+ static get ZYX() {
1789
+ return 0 /* ZYX */;
1790
+ }
1791
+ static get YXZ() {
1792
+ return 1 /* YXZ */;
1793
+ }
1794
+ static get XZY() {
1795
+ return 2 /* XZY */;
1796
+ }
1797
+ static get ZXY() {
1798
+ return 3 /* ZXY */;
1799
+ }
1800
+ static get YZX() {
1801
+ return 4 /* YZX */;
1802
+ }
1803
+ static get XYZ() {
1804
+ return 5 /* XYZ */;
1805
+ }
1806
+ static get RollPitchYaw() {
1807
+ return 0 /* ZYX */;
1808
+ }
1809
+ static get DefaultOrder() {
1810
+ return 0 /* ZYX */;
1811
+ }
1812
+ static get RotationOrders() {
1813
+ return RotationOrder;
1814
+ }
1815
+ static rotationOrder(order) {
1816
+ return RotationOrder[order];
1817
+ }
1818
+ get ELEMENTS() {
1819
+ return 4;
1820
+ }
1821
+ constructor(x = 0, y = 0, z = 0, order = Euler.DefaultOrder) {
1822
+ super(-0, -0, -0, -0);
1823
+ if (arguments.length > 0 && Array.isArray(arguments[0])) {
1824
+ this.fromVector3(...arguments);
1825
+ } else {
1826
+ this.set(x, y, z, order);
1827
+ }
1828
+ }
1829
+ fromQuaternion(quaternion) {
1830
+ const [x, y, z, w] = quaternion;
1831
+ const ysqr = y * y;
1832
+ const t0 = -2 * (ysqr + z * z) + 1;
1833
+ const t1 = 2 * (x * y + w * z);
1834
+ let t2 = -2 * (x * z - w * y);
1835
+ const t3 = 2 * (y * z + w * x);
1836
+ const t4 = -2 * (x * x + ysqr) + 1;
1837
+ t2 = t2 > 1 ? 1 : t2;
1838
+ t2 = t2 < -1 ? -1 : t2;
1839
+ const roll = Math.atan2(t3, t4);
1840
+ const pitch = Math.asin(t2);
1841
+ const yaw = Math.atan2(t1, t0);
1842
+ return this.set(roll, pitch, yaw, Euler.RollPitchYaw);
1843
+ }
1844
+ fromObject(object) {
1845
+ throw new Error("not implemented");
1846
+ }
1847
+ copy(array) {
1848
+ this[0] = array[0];
1849
+ this[1] = array[1];
1850
+ this[2] = array[2];
1851
+ this[3] = Number.isFinite(array[3]) || this.order;
1852
+ return this.check();
1853
+ }
1854
+ set(x = 0, y = 0, z = 0, order) {
1855
+ this[0] = x;
1856
+ this[1] = y;
1857
+ this[2] = z;
1858
+ this[3] = Number.isFinite(order) ? order : this[3];
1859
+ return this.check();
1860
+ }
1861
+ validate() {
1862
+ return validateOrder(this[3]) && Number.isFinite(this[0]) && Number.isFinite(this[1]) && Number.isFinite(this[2]);
1863
+ }
1864
+ toArray(array = [], offset = 0) {
1865
+ array[offset] = this[0];
1866
+ array[offset + 1] = this[1];
1867
+ array[offset + 2] = this[2];
1868
+ return array;
1869
+ }
1870
+ toArray4(array = [], offset = 0) {
1871
+ array[offset] = this[0];
1872
+ array[offset + 1] = this[1];
1873
+ array[offset + 2] = this[2];
1874
+ array[offset + 3] = this[3];
1875
+ return array;
1876
+ }
1877
+ toVector3(result = [-0, -0, -0]) {
1878
+ result[0] = this[0];
1879
+ result[1] = this[1];
1880
+ result[2] = this[2];
1881
+ return result;
1882
+ }
1883
+ get x() {
1884
+ return this[0];
1885
+ }
1886
+ set x(value) {
1887
+ this[0] = checkNumber(value);
1888
+ }
1889
+ get y() {
1890
+ return this[1];
1891
+ }
1892
+ set y(value) {
1893
+ this[1] = checkNumber(value);
1894
+ }
1895
+ get z() {
1896
+ return this[2];
1897
+ }
1898
+ set z(value) {
1899
+ this[2] = checkNumber(value);
1900
+ }
1901
+ get alpha() {
1902
+ return this[0];
1903
+ }
1904
+ set alpha(value) {
1905
+ this[0] = checkNumber(value);
1906
+ }
1907
+ get beta() {
1908
+ return this[1];
1909
+ }
1910
+ set beta(value) {
1911
+ this[1] = checkNumber(value);
1912
+ }
1913
+ get gamma() {
1914
+ return this[2];
1915
+ }
1916
+ set gamma(value) {
1917
+ this[2] = checkNumber(value);
1918
+ }
1919
+ get phi() {
1920
+ return this[0];
1921
+ }
1922
+ set phi(value) {
1923
+ this[0] = checkNumber(value);
1924
+ }
1925
+ get theta() {
1926
+ return this[1];
1927
+ }
1928
+ set theta(value) {
1929
+ this[1] = checkNumber(value);
1930
+ }
1931
+ get psi() {
1932
+ return this[2];
1933
+ }
1934
+ set psi(value) {
1935
+ this[2] = checkNumber(value);
1936
+ }
1937
+ get roll() {
1938
+ return this[0];
1939
+ }
1940
+ set roll(value) {
1941
+ this[0] = checkNumber(value);
1942
+ }
1943
+ get pitch() {
1944
+ return this[1];
1945
+ }
1946
+ set pitch(value) {
1947
+ this[1] = checkNumber(value);
1948
+ }
1949
+ get yaw() {
1950
+ return this[2];
1951
+ }
1952
+ set yaw(value) {
1953
+ this[2] = checkNumber(value);
1954
+ }
1955
+ get order() {
1956
+ return this[3];
1957
+ }
1958
+ set order(value) {
1959
+ this[3] = checkOrder(value);
1960
+ }
1961
+ fromVector3(v, order) {
1962
+ return this.set(v[0], v[1], v[2], Number.isFinite(order) ? order : this[3]);
1963
+ }
1964
+ fromArray(array, offset = 0) {
1965
+ this[0] = array[0 + offset];
1966
+ this[1] = array[1 + offset];
1967
+ this[2] = array[2 + offset];
1968
+ if (array[3] !== void 0) {
1969
+ this[3] = array[3];
1970
+ }
1971
+ return this.check();
1972
+ }
1973
+ fromRollPitchYaw(roll, pitch, yaw) {
1974
+ return this.set(roll, pitch, yaw, 0 /* ZYX */);
1975
+ }
1976
+ fromRotationMatrix(m, order = Euler.DefaultOrder) {
1977
+ this._fromRotationMatrix(m, order);
1978
+ return this.check();
1979
+ }
1980
+ getRotationMatrix(m) {
1981
+ return this._getRotationMatrix(m);
1982
+ }
1983
+ getQuaternion() {
1984
+ const q = new Quaternion();
1985
+ switch (this[4]) {
1986
+ case 5 /* XYZ */:
1987
+ return q.rotateX(this[0]).rotateY(this[1]).rotateZ(this[2]);
1988
+ case 1 /* YXZ */:
1989
+ return q.rotateY(this[0]).rotateX(this[1]).rotateZ(this[2]);
1990
+ case 3 /* ZXY */:
1991
+ return q.rotateZ(this[0]).rotateX(this[1]).rotateY(this[2]);
1992
+ case 0 /* ZYX */:
1993
+ return q.rotateZ(this[0]).rotateY(this[1]).rotateX(this[2]);
1994
+ case 4 /* YZX */:
1995
+ return q.rotateY(this[0]).rotateZ(this[1]).rotateX(this[2]);
1996
+ case 2 /* XZY */:
1997
+ return q.rotateX(this[0]).rotateZ(this[1]).rotateY(this[2]);
1998
+ default:
1999
+ throw new Error(ERR_UNKNOWN_ORDER);
2000
+ }
2001
+ }
2002
+ _fromRotationMatrix(m, order = Euler.DefaultOrder) {
2003
+ const m11 = m[0], m12 = m[4], m13 = m[8];
2004
+ const m21 = m[1], m22 = m[5], m23 = m[9];
2005
+ const m31 = m[2], m32 = m[6], m33 = m[10];
2006
+ order = order || this[3];
2007
+ switch (order) {
2008
+ case Euler.XYZ:
2009
+ this[1] = Math.asin(clamp(m13, -1, 1));
2010
+ if (Math.abs(m13) < ALMOST_ONE) {
2011
+ this[0] = Math.atan2(-m23, m33);
2012
+ this[2] = Math.atan2(-m12, m11);
2013
+ } else {
2014
+ this[0] = Math.atan2(m32, m22);
2015
+ this[2] = 0;
2016
+ }
2017
+ break;
2018
+ case Euler.YXZ:
2019
+ this[0] = Math.asin(-clamp(m23, -1, 1));
2020
+ if (Math.abs(m23) < ALMOST_ONE) {
2021
+ this[1] = Math.atan2(m13, m33);
2022
+ this[2] = Math.atan2(m21, m22);
2023
+ } else {
2024
+ this[1] = Math.atan2(-m31, m11);
2025
+ this[2] = 0;
2026
+ }
2027
+ break;
2028
+ case Euler.ZXY:
2029
+ this[0] = Math.asin(clamp(m32, -1, 1));
2030
+ if (Math.abs(m32) < ALMOST_ONE) {
2031
+ this[1] = Math.atan2(-m31, m33);
2032
+ this[2] = Math.atan2(-m12, m22);
2033
+ } else {
2034
+ this[1] = 0;
2035
+ this[2] = Math.atan2(m21, m11);
2036
+ }
2037
+ break;
2038
+ case Euler.ZYX:
2039
+ this[1] = Math.asin(-clamp(m31, -1, 1));
2040
+ if (Math.abs(m31) < ALMOST_ONE) {
2041
+ this[0] = Math.atan2(m32, m33);
2042
+ this[2] = Math.atan2(m21, m11);
2043
+ } else {
2044
+ this[0] = 0;
2045
+ this[2] = Math.atan2(-m12, m22);
2046
+ }
2047
+ break;
2048
+ case Euler.YZX:
2049
+ this[2] = Math.asin(clamp(m21, -1, 1));
2050
+ if (Math.abs(m21) < ALMOST_ONE) {
2051
+ this[0] = Math.atan2(-m23, m22);
2052
+ this[1] = Math.atan2(-m31, m11);
2053
+ } else {
2054
+ this[0] = 0;
2055
+ this[1] = Math.atan2(m13, m33);
2056
+ }
2057
+ break;
2058
+ case Euler.XZY:
2059
+ this[2] = Math.asin(-clamp(m12, -1, 1));
2060
+ if (Math.abs(m12) < ALMOST_ONE) {
2061
+ this[0] = Math.atan2(m32, m22);
2062
+ this[1] = Math.atan2(m13, m11);
2063
+ } else {
2064
+ this[0] = Math.atan2(-m23, m33);
2065
+ this[1] = 0;
2066
+ }
2067
+ break;
2068
+ default:
2069
+ throw new Error(ERR_UNKNOWN_ORDER);
2070
+ }
2071
+ this[3] = order;
2072
+ return this;
2073
+ }
2074
+ _getRotationMatrix(result) {
2075
+ const te = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
2076
+ const x = this.x, y = this.y, z = this.z;
2077
+ const a = Math.cos(x);
2078
+ const c = Math.cos(y);
2079
+ const e = Math.cos(z);
2080
+ const b = Math.sin(x);
2081
+ const d = Math.sin(y);
2082
+ const f = Math.sin(z);
2083
+ switch (this[3]) {
2084
+ case Euler.XYZ: {
2085
+ const ae = a * e, af = a * f, be = b * e, bf = b * f;
2086
+ te[0] = c * e;
2087
+ te[4] = -c * f;
2088
+ te[8] = d;
2089
+ te[1] = af + be * d;
2090
+ te[5] = ae - bf * d;
2091
+ te[9] = -b * c;
2092
+ te[2] = bf - ae * d;
2093
+ te[6] = be + af * d;
2094
+ te[10] = a * c;
2095
+ break;
2096
+ }
2097
+ case Euler.YXZ: {
2098
+ const ce = c * e, cf = c * f, de = d * e, df = d * f;
2099
+ te[0] = ce + df * b;
2100
+ te[4] = de * b - cf;
2101
+ te[8] = a * d;
2102
+ te[1] = a * f;
2103
+ te[5] = a * e;
2104
+ te[9] = -b;
2105
+ te[2] = cf * b - de;
2106
+ te[6] = df + ce * b;
2107
+ te[10] = a * c;
2108
+ break;
2109
+ }
2110
+ case Euler.ZXY: {
2111
+ const ce = c * e, cf = c * f, de = d * e, df = d * f;
2112
+ te[0] = ce - df * b;
2113
+ te[4] = -a * f;
2114
+ te[8] = de + cf * b;
2115
+ te[1] = cf + de * b;
2116
+ te[5] = a * e;
2117
+ te[9] = df - ce * b;
2118
+ te[2] = -a * d;
2119
+ te[6] = b;
2120
+ te[10] = a * c;
2121
+ break;
2122
+ }
2123
+ case Euler.ZYX: {
2124
+ const ae = a * e, af = a * f, be = b * e, bf = b * f;
2125
+ te[0] = c * e;
2126
+ te[4] = be * d - af;
2127
+ te[8] = ae * d + bf;
2128
+ te[1] = c * f;
2129
+ te[5] = bf * d + ae;
2130
+ te[9] = af * d - be;
2131
+ te[2] = -d;
2132
+ te[6] = b * c;
2133
+ te[10] = a * c;
2134
+ break;
2135
+ }
2136
+ case Euler.YZX: {
2137
+ const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
2138
+ te[0] = c * e;
2139
+ te[4] = bd - ac * f;
2140
+ te[8] = bc * f + ad;
2141
+ te[1] = f;
2142
+ te[5] = a * e;
2143
+ te[9] = -b * e;
2144
+ te[2] = -d * e;
2145
+ te[6] = ad * f + bc;
2146
+ te[10] = ac - bd * f;
2147
+ break;
2148
+ }
2149
+ case Euler.XZY: {
2150
+ const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
2151
+ te[0] = c * e;
2152
+ te[4] = -f;
2153
+ te[8] = d * e;
2154
+ te[1] = ac * f + bd;
2155
+ te[5] = a * e;
2156
+ te[9] = ad * f - bc;
2157
+ te[2] = bc * f - ad;
2158
+ te[6] = b * e;
2159
+ te[10] = bd * f + ac;
2160
+ break;
2161
+ }
2162
+ default:
2163
+ throw new Error(ERR_UNKNOWN_ORDER);
2164
+ }
2165
+ te[3] = 0;
2166
+ te[7] = 0;
2167
+ te[11] = 0;
2168
+ te[12] = 0;
2169
+ te[13] = 0;
2170
+ te[14] = 0;
2171
+ te[15] = 1;
2172
+ return te;
2173
+ }
2174
+ toQuaternion() {
2175
+ const cy = Math.cos(this.yaw * 0.5);
2176
+ const sy = Math.sin(this.yaw * 0.5);
2177
+ const cr = Math.cos(this.roll * 0.5);
2178
+ const sr = Math.sin(this.roll * 0.5);
2179
+ const cp = Math.cos(this.pitch * 0.5);
2180
+ const sp = Math.sin(this.pitch * 0.5);
2181
+ const w = cy * cr * cp + sy * sr * sp;
2182
+ const x = cy * sr * cp - sy * cr * sp;
2183
+ const y = cy * cr * sp + sy * sr * cp;
2184
+ const z = sy * cr * cp - cy * sr * sp;
2185
+ return new Quaternion(x, y, z, w);
2186
+ }
2187
+ };
2188
+ function validateOrder(value) {
2189
+ return value >= 0 && value < 6;
2190
+ }
2191
+ function checkOrder(value) {
2192
+ if (value < 0 && value >= 6) {
2193
+ throw new Error(ERR_UNKNOWN_ORDER);
2194
+ }
2195
+ return value;
2196
+ }
2197
+
2198
+ // src/classes/pose.ts
2199
+ var Pose = class {
2200
+ constructor({
2201
+ x = 0,
2202
+ y = 0,
2203
+ z = 0,
2204
+ roll = 0,
2205
+ pitch = 0,
2206
+ yaw = 0,
2207
+ position,
2208
+ orientation
2209
+ } = {}) {
2210
+ if (Array.isArray(position) && position.length === 3) {
2211
+ this.position = new Vector3(position);
2212
+ } else {
2213
+ this.position = new Vector3(x, y, z);
2214
+ }
2215
+ if (Array.isArray(orientation) && orientation.length === 4) {
2216
+ this.orientation = new Euler(orientation, orientation[3]);
2217
+ } else {
2218
+ this.orientation = new Euler(roll, pitch, yaw, Euler.RollPitchYaw);
2219
+ }
2220
+ }
2221
+ get x() {
2222
+ return this.position.x;
2223
+ }
2224
+ set x(value) {
2225
+ this.position.x = value;
2226
+ }
2227
+ get y() {
2228
+ return this.position.y;
2229
+ }
2230
+ set y(value) {
2231
+ this.position.y = value;
2232
+ }
2233
+ get z() {
2234
+ return this.position.z;
2235
+ }
2236
+ set z(value) {
2237
+ this.position.z = value;
2238
+ }
2239
+ get roll() {
2240
+ return this.orientation.roll;
2241
+ }
2242
+ set roll(value) {
2243
+ this.orientation.roll = value;
2244
+ }
2245
+ get pitch() {
2246
+ return this.orientation.pitch;
2247
+ }
2248
+ set pitch(value) {
2249
+ this.orientation.pitch = value;
2250
+ }
2251
+ get yaw() {
2252
+ return this.orientation.yaw;
2253
+ }
2254
+ set yaw(value) {
2255
+ this.orientation.yaw = value;
2256
+ }
2257
+ getPosition() {
2258
+ return this.position;
2259
+ }
2260
+ getOrientation() {
2261
+ return this.orientation;
2262
+ }
2263
+ equals(pose) {
2264
+ if (!pose) {
2265
+ return false;
2266
+ }
2267
+ return this.position.equals(pose.position) && this.orientation.equals(pose.orientation);
2268
+ }
2269
+ exactEquals(pose) {
2270
+ if (!pose) {
2271
+ return false;
2272
+ }
2273
+ return this.position.exactEquals(pose.position) && this.orientation.exactEquals(pose.orientation);
2274
+ }
2275
+ getTransformationMatrix() {
2276
+ const sr = Math.sin(this.roll);
2277
+ const sp = Math.sin(this.pitch);
2278
+ const sw = Math.sin(this.yaw);
2279
+ const cr = Math.cos(this.roll);
2280
+ const cp = Math.cos(this.pitch);
2281
+ const cw = Math.cos(this.yaw);
2282
+ return new Matrix4().setRowMajor(
2283
+ cw * cp,
2284
+ -sw * cr + cw * sp * sr,
2285
+ sw * sr + cw * sp * cr,
2286
+ this.x,
2287
+ sw * cp,
2288
+ cw * cr + sw * sp * sr,
2289
+ -cw * sr + sw * sp * cr,
2290
+ this.y,
2291
+ -sp,
2292
+ cp * sr,
2293
+ cp * cr,
2294
+ this.z,
2295
+ 0,
2296
+ 0,
2297
+ 0,
2298
+ 1
2299
+ );
2300
+ }
2301
+ getTransformationMatrixFromPose(pose) {
2302
+ return new Matrix4().multiplyRight(this.getTransformationMatrix()).multiplyRight(pose.getTransformationMatrix().invert());
2303
+ }
2304
+ getTransformationMatrixToPose(pose) {
2305
+ return new Matrix4().multiplyRight(pose.getTransformationMatrix()).multiplyRight(this.getTransformationMatrix().invert());
2306
+ }
2307
+ };
2308
+
2309
+ // src/lib/math-utils.ts
2310
+ var math_utils_default = {
2311
+ EPSILON1: 0.1,
2312
+ EPSILON2: 0.01,
2313
+ EPSILON3: 1e-3,
2314
+ EPSILON4: 1e-4,
2315
+ EPSILON5: 1e-5,
2316
+ EPSILON6: 1e-6,
2317
+ EPSILON7: 1e-7,
2318
+ EPSILON8: 1e-8,
2319
+ EPSILON9: 1e-9,
2320
+ EPSILON10: 1e-10,
2321
+ EPSILON11: 1e-11,
2322
+ EPSILON12: 1e-12,
2323
+ EPSILON13: 1e-13,
2324
+ EPSILON14: 1e-14,
2325
+ EPSILON15: 1e-15,
2326
+ EPSILON16: 1e-16,
2327
+ EPSILON17: 1e-17,
2328
+ EPSILON18: 1e-18,
2329
+ EPSILON19: 1e-19,
2330
+ EPSILON20: 1e-20,
2331
+ PI_OVER_TWO: Math.PI / 2,
2332
+ PI_OVER_FOUR: Math.PI / 4,
2333
+ PI_OVER_SIX: Math.PI / 6,
2334
+ TWO_PI: Math.PI * 2
2335
+ };