@math.gl/core 4.1.0-alpha.9 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -220,6 +220,11 @@ function map(value, func, result) {
220
220
 
221
221
  // dist/classes/base/math-array.js
222
222
  var MathArray = class extends Array {
223
+ // Common methods
224
+ /**
225
+ * Clone the current object
226
+ * @returns a new copy of this object
227
+ */
223
228
  clone() {
224
229
  return new this.constructor().copy(this);
225
230
  }
@@ -239,7 +244,10 @@ var MathArray = class extends Array {
239
244
  return targetObject;
240
245
  }
241
246
  from(arrayOrObject) {
242
- return Array.isArray(arrayOrObject) ? this.copy(arrayOrObject) : this.fromObject(arrayOrObject);
247
+ return Array.isArray(arrayOrObject) ? this.copy(arrayOrObject) : (
248
+ // @ts-ignore
249
+ this.fromObject(arrayOrObject)
250
+ );
243
251
  }
244
252
  to(arrayOrObject) {
245
253
  if (arrayOrObject === this) {
@@ -250,12 +258,14 @@ var MathArray = class extends Array {
250
258
  toTarget(target) {
251
259
  return target ? this.to(target) : this;
252
260
  }
261
+ /** @deprecated */
253
262
  toFloat32Array() {
254
263
  return new Float32Array(this);
255
264
  }
256
265
  toString() {
257
266
  return this.formatString(config);
258
267
  }
268
+ /** Formats string according to options */
259
269
  formatString(opts) {
260
270
  let string = "";
261
271
  for (let i = 0; i < this.ELEMENTS; ++i) {
@@ -285,6 +295,8 @@ var MathArray = class extends Array {
285
295
  }
286
296
  return true;
287
297
  }
298
+ // Modifiers
299
+ /** Negates all values in this object */
288
300
  negate() {
289
301
  for (let i = 0; i < this.ELEMENTS; ++i) {
290
302
  this[i] = -this[i];
@@ -302,12 +314,14 @@ var MathArray = class extends Array {
302
314
  }
303
315
  return this.check();
304
316
  }
317
+ /** Minimal */
305
318
  min(vector) {
306
319
  for (let i = 0; i < this.ELEMENTS; ++i) {
307
320
  this[i] = Math.min(vector[i], this[i]);
308
321
  }
309
322
  return this.check();
310
323
  }
324
+ /** Maximal */
311
325
  max(vector) {
312
326
  for (let i = 0; i < this.ELEMENTS; ++i) {
313
327
  this[i] = Math.max(vector[i], this[i]);
@@ -348,18 +362,25 @@ var MathArray = class extends Array {
348
362
  }
349
363
  return this.check();
350
364
  }
365
+ /**
366
+ * Multiplies all elements by `scale`
367
+ * Note: `Matrix4.multiplyByScalar` only scales its 3x3 "minor"
368
+ */
351
369
  multiplyByScalar(scalar) {
352
370
  for (let i = 0; i < this.ELEMENTS; ++i) {
353
371
  this[i] *= scalar;
354
372
  }
355
373
  return this.check();
356
374
  }
375
+ // Debug checks
376
+ /** Throws an error if array length is incorrect or contains illegal values */
357
377
  check() {
358
378
  if (config.debug && !this.validate()) {
359
379
  throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);
360
380
  }
361
381
  return this;
362
382
  }
383
+ /** Returns false if the array length is incorrect or contains illegal values */
363
384
  validate() {
364
385
  let valid = this.length === this.ELEMENTS;
365
386
  for (let i = 0; i < this.ELEMENTS; ++i) {
@@ -367,39 +388,48 @@ var MathArray = class extends Array {
367
388
  }
368
389
  return valid;
369
390
  }
391
+ // three.js compatibility
392
+ /** @deprecated */
370
393
  sub(a) {
371
394
  return this.subtract(a);
372
395
  }
396
+ /** @deprecated */
373
397
  setScalar(a) {
374
398
  for (let i = 0; i < this.ELEMENTS; ++i) {
375
399
  this[i] = a;
376
400
  }
377
401
  return this.check();
378
402
  }
403
+ /** @deprecated */
379
404
  addScalar(a) {
380
405
  for (let i = 0; i < this.ELEMENTS; ++i) {
381
406
  this[i] += a;
382
407
  }
383
408
  return this.check();
384
409
  }
410
+ /** @deprecated */
385
411
  subScalar(a) {
386
412
  return this.addScalar(-a);
387
413
  }
414
+ /** @deprecated */
388
415
  multiplyScalar(scalar) {
389
416
  for (let i = 0; i < this.ELEMENTS; ++i) {
390
417
  this[i] *= scalar;
391
418
  }
392
419
  return this.check();
393
420
  }
421
+ /** @deprecated */
394
422
  divideScalar(a) {
395
423
  return this.multiplyByScalar(1 / a);
396
424
  }
425
+ /** @deprecated */
397
426
  clampScalar(min4, max4) {
398
427
  for (let i = 0; i < this.ELEMENTS; ++i) {
399
428
  this[i] = Math.min(Math.max(this[i], min4), max4);
400
429
  }
401
430
  return this.check();
402
431
  }
432
+ /** @deprecated */
403
433
  get elements() {
404
434
  return this;
405
435
  }
@@ -439,6 +469,7 @@ function assert(condition, message) {
439
469
 
440
470
  // dist/classes/base/vector.js
441
471
  var Vector = class extends MathArray {
472
+ // ACCESSORS
442
473
  get x() {
443
474
  return this[0];
444
475
  }
@@ -451,12 +482,24 @@ var Vector = class extends MathArray {
451
482
  set y(value) {
452
483
  this[1] = checkNumber(value);
453
484
  }
485
+ /**
486
+ * Returns the length of the vector from the origin to the point described by this vector
487
+ *
488
+ * @note `length` is a reserved word for Arrays, so `v.length()` will return number of elements
489
+ * Instead we provide `len` and `magnitude`
490
+ */
454
491
  len() {
455
492
  return Math.sqrt(this.lengthSquared());
456
493
  }
494
+ /**
495
+ * Returns the length of the vector from the origin to the point described by this vector
496
+ */
457
497
  magnitude() {
458
498
  return this.len();
459
499
  }
500
+ /**
501
+ * Returns the squared length of the vector from the origin to the point described by this vector
502
+ */
460
503
  lengthSquared() {
461
504
  let length5 = 0;
462
505
  for (let i = 0; i < this.ELEMENTS; ++i) {
@@ -464,6 +507,9 @@ var Vector = class extends MathArray {
464
507
  }
465
508
  return length5;
466
509
  }
510
+ /**
511
+ * Returns the squared length of the vector from the origin to the point described by this vector
512
+ */
467
513
  magnitudeSquared() {
468
514
  return this.lengthSquared();
469
515
  }
@@ -485,6 +531,7 @@ var Vector = class extends MathArray {
485
531
  }
486
532
  return checkNumber(product);
487
533
  }
534
+ // MODIFIERS
488
535
  normalize() {
489
536
  const length5 = this.magnitude();
490
537
  if (length5 !== 0) {
@@ -510,6 +557,7 @@ var Vector = class extends MathArray {
510
557
  }
511
558
  return this.check();
512
559
  }
560
+ // THREE.js compatibility
513
561
  lengthSq() {
514
562
  return this.lengthSquared();
515
563
  }
@@ -900,6 +948,7 @@ function vec4_transformMat3(out, a, m) {
900
948
 
901
949
  // dist/classes/vector2.js
902
950
  var Vector2 = class extends Vector {
951
+ // Creates a new, empty vec2
903
952
  constructor(x = 0, y = 0) {
904
953
  super(2);
905
954
  if (isArray(x) && arguments.length === 1) {
@@ -937,22 +986,47 @@ var Vector2 = class extends Vector {
937
986
  object.y = this[1];
938
987
  return object;
939
988
  }
989
+ // Getters/setters
940
990
  get ELEMENTS() {
941
991
  return 2;
942
992
  }
993
+ /**
994
+ * Returns angle from x axis
995
+ * @returns
996
+ */
943
997
  horizontalAngle() {
944
998
  return Math.atan2(this.y, this.x);
945
999
  }
1000
+ /**
1001
+ * Returns angle from y axis
1002
+ * @returns
1003
+ */
946
1004
  verticalAngle() {
947
1005
  return Math.atan2(this.x, this.y);
948
1006
  }
1007
+ // Transforms
1008
+ /**
1009
+ * Transforms as point
1010
+ * @param matrix4
1011
+ * @returns
1012
+ */
949
1013
  transform(matrix4) {
950
1014
  return this.transformAsPoint(matrix4);
951
1015
  }
1016
+ /**
1017
+ * transforms as point (4th component is implicitly 1)
1018
+ * @param matrix4
1019
+ * @returns
1020
+ */
952
1021
  transformAsPoint(matrix4) {
953
1022
  transformMat4(this, this, matrix4);
954
1023
  return this.check();
955
1024
  }
1025
+ /**
1026
+ * transforms as vector (4th component is implicitly 0, ignores translation. slightly faster)
1027
+ * @param matrix4
1028
+ * @returns
1029
+ */
956
1030
  transformAsVector(matrix4) {
957
1031
  vec2_transformMat4AsVector(this, this, matrix4);
958
1032
  return this.check();
@@ -1409,6 +1483,12 @@ var Vector3 = class extends Vector {
1409
1483
  }
1410
1484
  return ZERO;
1411
1485
  }
1486
+ /**
1487
+ * @class
1488
+ * @param x
1489
+ * @param y
1490
+ * @param z
1491
+ */
1412
1492
  constructor(x = 0, y = 0, z = 0) {
1413
1493
  super(-0, -0, -0);
1414
1494
  if (arguments.length === 1 && isArray(x)) {
@@ -1453,6 +1533,7 @@ var Vector3 = class extends Vector {
1453
1533
  object.z = this[2];
1454
1534
  return object;
1455
1535
  }
1536
+ // Getters/setters
1456
1537
  get ELEMENTS() {
1457
1538
  return 3;
1458
1539
  }
@@ -1462,9 +1543,11 @@ var Vector3 = class extends Vector {
1462
1543
  set z(value) {
1463
1544
  this[2] = checkNumber(value);
1464
1545
  }
1546
+ // ACCESSORS
1465
1547
  angle(vector) {
1466
1548
  return angle2(this, vector);
1467
1549
  }
1550
+ // MODIFIERS
1468
1551
  cross(vector) {
1469
1552
  cross2(this, this, vector);
1470
1553
  return this.check();
@@ -1481,13 +1564,17 @@ var Vector3 = class extends Vector {
1481
1564
  rotateZ(this, this, origin, radians2);
1482
1565
  return this.check();
1483
1566
  }
1567
+ // Transforms
1568
+ // transforms as point (4th component is implicitly 1)
1484
1569
  transform(matrix4) {
1485
1570
  return this.transformAsPoint(matrix4);
1486
1571
  }
1572
+ // transforms as point (4th component is implicitly 1)
1487
1573
  transformAsPoint(matrix4) {
1488
1574
  transformMat42(this, this, matrix4);
1489
1575
  return this.check();
1490
1576
  }
1577
+ // transforms as vector (4th component is implicitly 0, ignores translation. slightly faster)
1491
1578
  transformAsVector(matrix4) {
1492
1579
  vec3_transformMat4AsVector(this, this, matrix4);
1493
1580
  return this.check();
@@ -1567,6 +1654,8 @@ var Vector4 = class extends Vector {
1567
1654
  object.w = this[3];
1568
1655
  return object;
1569
1656
  }
1657
+ // Getters/setters
1658
+ /* eslint-disable no-multi-spaces, brace-style, no-return-assign */
1570
1659
  get ELEMENTS() {
1571
1660
  return 4;
1572
1661
  }
@@ -1598,6 +1687,7 @@ var Vector4 = class extends Vector {
1598
1687
  transformQuat(this, this, quaternion);
1599
1688
  return this.check();
1600
1689
  }
1690
+ // three.js compatibility
1601
1691
  applyMatrix4(m) {
1602
1692
  m.transform(this, this);
1603
1693
  return this;
@@ -1606,6 +1696,16 @@ var Vector4 = class extends Vector {
1606
1696
 
1607
1697
  // dist/classes/base/matrix.js
1608
1698
  var Matrix = class extends MathArray {
1699
+ // fromObject(object) {
1700
+ // const array = object.elements;
1701
+ // return this.fromRowMajor(array);
1702
+ // }
1703
+ // toObject(object) {
1704
+ // const array = object.elements;
1705
+ // this.toRowMajor(array);
1706
+ // return object;
1707
+ // }
1708
+ // TODO better override formatString?
1609
1709
  toString() {
1610
1710
  let string = "[";
1611
1711
  if (config.printRowMajor) {
@@ -1627,9 +1727,11 @@ var Matrix = class extends MathArray {
1627
1727
  getElementIndex(row, col) {
1628
1728
  return col * this.RANK + row;
1629
1729
  }
1730
+ // By default assumes row major indices
1630
1731
  getElement(row, col) {
1631
1732
  return this[col * this.RANK + row];
1632
1733
  }
1734
+ // By default assumes row major indices
1633
1735
  setElement(row, col, value) {
1634
1736
  this[col * this.RANK + row] = checkNumber(value);
1635
1737
  return this;
@@ -2219,16 +2321,30 @@ var Matrix3 = class extends Matrix {
2219
2321
  this[8] = array[8];
2220
2322
  return this.check();
2221
2323
  }
2324
+ // Constructors
2222
2325
  identity() {
2223
2326
  return this.copy(IDENTITY_MATRIX);
2224
2327
  }
2328
+ /**
2329
+ *
2330
+ * @param object
2331
+ * @returns self
2332
+ */
2333
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2225
2334
  fromObject(object) {
2226
2335
  return this.check();
2227
2336
  }
2337
+ /** Calculates a 3x3 matrix from the given quaternion
2338
+ * q quat Quaternion to create matrix from
2339
+ */
2228
2340
  fromQuaternion(q) {
2229
2341
  fromQuat(this, q);
2230
2342
  return this.check();
2231
2343
  }
2344
+ /**
2345
+ * accepts column major order, stores in column major order
2346
+ */
2347
+ // eslint-disable-next-line max-params
2232
2348
  set(m00, m10, m20, m01, m11, m21, m02, m12, m22) {
2233
2349
  this[0] = m00;
2234
2350
  this[1] = m10;
@@ -2241,6 +2357,10 @@ var Matrix3 = class extends Matrix {
2241
2357
  this[8] = m22;
2242
2358
  return this.check();
2243
2359
  }
2360
+ /**
2361
+ * accepts row major order, stores as column major
2362
+ */
2363
+ // eslint-disable-next-line max-params
2244
2364
  setRowMajor(m00, m01, m02, m10, m11, m12, m20, m21, m22) {
2245
2365
  this[0] = m00;
2246
2366
  this[1] = m10;
@@ -2253,17 +2373,21 @@ var Matrix3 = class extends Matrix {
2253
2373
  this[8] = m22;
2254
2374
  return this.check();
2255
2375
  }
2376
+ // Accessors
2256
2377
  determinant() {
2257
2378
  return determinant(this);
2258
2379
  }
2380
+ // Modifiers
2259
2381
  transpose() {
2260
2382
  transpose(this, this);
2261
2383
  return this.check();
2262
2384
  }
2385
+ /** Invert a matrix. Note that this can fail if the matrix is not invertible */
2263
2386
  invert() {
2264
2387
  invert(this, this);
2265
2388
  return this.check();
2266
2389
  }
2390
+ // Operations
2267
2391
  multiplyLeft(a) {
2268
2392
  multiply3(this, a, this);
2269
2393
  return this.check();
@@ -2288,6 +2412,7 @@ var Matrix3 = class extends Matrix {
2288
2412
  translate(this, this, vec);
2289
2413
  return this.check();
2290
2414
  }
2415
+ // Transforms
2291
2416
  transform(vector, result) {
2292
2417
  let out;
2293
2418
  switch (vector.length) {
@@ -2306,12 +2431,15 @@ var Matrix3 = class extends Matrix {
2306
2431
  checkVector(out, vector.length);
2307
2432
  return out;
2308
2433
  }
2434
+ /** @deprecated */
2309
2435
  transformVector(vector, result) {
2310
2436
  return this.transform(vector, result);
2311
2437
  }
2438
+ /** @deprecated */
2312
2439
  transformVector2(vector, result) {
2313
2440
  return this.transform(vector, result);
2314
2441
  }
2442
+ /** @deprecated */
2315
2443
  transformVector3(vector, result) {
2316
2444
  return this.transform(vector, result);
2317
2445
  }
@@ -4238,6 +4366,7 @@ var Matrix4 = class extends Matrix {
4238
4366
  this[15] = array[15];
4239
4367
  return this.check();
4240
4368
  }
4369
+ // eslint-disable-next-line max-params
4241
4370
  set(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33) {
4242
4371
  this[0] = m00;
4243
4372
  this[1] = m10;
@@ -4257,6 +4386,8 @@ var Matrix4 = class extends Matrix {
4257
4386
  this[15] = m33;
4258
4387
  return this.check();
4259
4388
  }
4389
+ // accepts row major order, stores as column major
4390
+ // eslint-disable-next-line max-params
4260
4391
  setRowMajor(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
4261
4392
  this[0] = m00;
4262
4393
  this[1] = m10;
@@ -4295,16 +4426,39 @@ var Matrix4 = class extends Matrix {
4295
4426
  result[15] = this[15];
4296
4427
  return result;
4297
4428
  }
4429
+ // Constructors
4430
+ /** Set to identity matrix */
4298
4431
  identity() {
4299
4432
  return this.copy(IDENTITY_MATRIX2);
4300
4433
  }
4434
+ /**
4435
+ *
4436
+ * @param object
4437
+ * @returns self
4438
+ */
4439
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
4301
4440
  fromObject(object) {
4302
4441
  return this.check();
4303
4442
  }
4443
+ /**
4444
+ * Calculates a 4x4 matrix from the given quaternion
4445
+ * @param quaternion Quaternion to create matrix from
4446
+ * @returns self
4447
+ */
4304
4448
  fromQuaternion(quaternion) {
4305
4449
  fromQuat3(this, quaternion);
4306
4450
  return this.check();
4307
4451
  }
4452
+ /**
4453
+ * Generates a frustum matrix with the given bounds
4454
+ * @param view.left - Left bound of the frustum
4455
+ * @param view.right - Right bound of the frustum
4456
+ * @param view.bottom - Bottom bound of the frustum
4457
+ * @param view.top - Top bound of the frustum
4458
+ * @param view.near - Near bound of the frustum
4459
+ * @param view.far - Far bound of the frustum. Can be set to Infinity.
4460
+ * @returns self
4461
+ */
4308
4462
  frustum(view) {
4309
4463
  const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
4310
4464
  if (far === Infinity) {
@@ -4314,16 +4468,45 @@ var Matrix4 = class extends Matrix {
4314
4468
  }
4315
4469
  return this.check();
4316
4470
  }
4471
+ /**
4472
+ * Generates a look-at matrix with the given eye position, focal point,
4473
+ * and up axis
4474
+ * @param view.eye - (vector) Position of the viewer
4475
+ * @param view.center - (vector) Point the viewer is looking at
4476
+ * @param view.up - (vector) Up axis
4477
+ * @returns self
4478
+ */
4317
4479
  lookAt(view) {
4318
4480
  const { eye, center = [0, 0, 0], up = [0, 1, 0] } = view;
4319
4481
  lookAt(this, eye, center, up);
4320
4482
  return this.check();
4321
4483
  }
4484
+ /**
4485
+ * Generates a orthogonal projection matrix with the given bounds
4486
+ * from "traditional" view space parameters
4487
+ * @param view.left - Left bound of the frustum
4488
+ * @param view.right number Right bound of the frustum
4489
+ * @param view.bottom - Bottom bound of the frustum
4490
+ * @param view.top number Top bound of the frustum
4491
+ * @param view.near - Near bound of the frustum
4492
+ * @param view.far number Far bound of the frustum
4493
+ * @returns self
4494
+ */
4322
4495
  ortho(view) {
4323
4496
  const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
4324
4497
  ortho(this, left, right, bottom, top, near, far);
4325
4498
  return this.check();
4326
4499
  }
4500
+ /**
4501
+ * Generates an orthogonal projection matrix with the same parameters
4502
+ * as a perspective matrix (plus focalDistance)
4503
+ * @param view.fovy Vertical field of view in radians
4504
+ * @param view.aspect Aspect ratio. Typically viewport width / viewport height
4505
+ * @param view.focalDistance Distance in the view frustum used for extent calculations
4506
+ * @param view.near Near bound of the frustum
4507
+ * @param view.far Far bound of the frustum
4508
+ * @returns self
4509
+ */
4327
4510
  orthographic(view) {
4328
4511
  const { fovy = DEFAULT_FOVY, aspect = DEFAULT_ASPECT, focalDistance = 1, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
4329
4512
  checkRadians(fovy);
@@ -4339,27 +4522,53 @@ var Matrix4 = class extends Matrix {
4339
4522
  far
4340
4523
  });
4341
4524
  }
4525
+ /**
4526
+ * Generates a perspective projection matrix with the given bounds
4527
+ * @param view.fovy Vertical field of view in radians
4528
+ * @param view.aspect Aspect ratio. typically viewport width/height
4529
+ * @param view.near Near bound of the frustum
4530
+ * @param view.far Far bound of the frustum
4531
+ * @returns self
4532
+ */
4342
4533
  perspective(view) {
4343
4534
  const { fovy = 45 * Math.PI / 180, aspect = 1, near = 0.1, far = 500 } = view;
4344
4535
  checkRadians(fovy);
4345
4536
  perspective(this, fovy, aspect, near, far);
4346
4537
  return this.check();
4347
4538
  }
4539
+ // Accessors
4348
4540
  determinant() {
4349
4541
  return determinant2(this);
4350
4542
  }
4543
+ /**
4544
+ * Extracts the non-uniform scale assuming the matrix is an affine transformation.
4545
+ * The scales are the "lengths" of the column vectors in the upper-left 3x3 matrix.
4546
+ * @param result
4547
+ * @returns self
4548
+ */
4351
4549
  getScale(result = [-0, -0, -0]) {
4352
4550
  result[0] = Math.sqrt(this[0] * this[0] + this[1] * this[1] + this[2] * this[2]);
4353
4551
  result[1] = Math.sqrt(this[4] * this[4] + this[5] * this[5] + this[6] * this[6]);
4354
4552
  result[2] = Math.sqrt(this[8] * this[8] + this[9] * this[9] + this[10] * this[10]);
4355
4553
  return result;
4356
4554
  }
4555
+ /**
4556
+ * Gets the translation portion, assuming the matrix is a affine transformation matrix.
4557
+ * @param result
4558
+ * @returns self
4559
+ */
4357
4560
  getTranslation(result = [-0, -0, -0]) {
4358
4561
  result[0] = this[12];
4359
4562
  result[1] = this[13];
4360
4563
  result[2] = this[14];
4361
4564
  return result;
4362
4565
  }
4566
+ /**
4567
+ * Gets upper left 3x3 pure rotation matrix (non-scaling), assume affine transformation matrix
4568
+ * @param result
4569
+ * @param scaleResult
4570
+ * @returns self
4571
+ */
4363
4572
  getRotation(result, scaleResult) {
4364
4573
  result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
4365
4574
  scaleResult = scaleResult || [-0, -0, -0];
@@ -4385,6 +4594,12 @@ var Matrix4 = class extends Matrix {
4385
4594
  result[15] = 1;
4386
4595
  return result;
4387
4596
  }
4597
+ /**
4598
+ *
4599
+ * @param result
4600
+ * @param scaleResult
4601
+ * @returns self
4602
+ */
4388
4603
  getRotationMatrix3(result, scaleResult) {
4389
4604
  result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0];
4390
4605
  scaleResult = scaleResult || [-0, -0, -0];
@@ -4403,6 +4618,7 @@ var Matrix4 = class extends Matrix {
4403
4618
  result[8] = this[10] * inverseScale2;
4404
4619
  return result;
4405
4620
  }
4621
+ // Modifiers
4406
4622
  transpose() {
4407
4623
  transpose2(this, this);
4408
4624
  return this.check();
@@ -4411,6 +4627,7 @@ var Matrix4 = class extends Matrix {
4411
4627
  invert2(this, this);
4412
4628
  return this.check();
4413
4629
  }
4630
+ // Operations
4414
4631
  multiplyLeft(a) {
4415
4632
  multiply4(this, a, this);
4416
4633
  return this.check();
@@ -4419,33 +4636,68 @@ var Matrix4 = class extends Matrix {
4419
4636
  multiply4(this, this, a);
4420
4637
  return this.check();
4421
4638
  }
4639
+ // Rotates a matrix by the given angle around the X axis
4422
4640
  rotateX(radians2) {
4423
4641
  rotateX2(this, this, radians2);
4424
4642
  return this.check();
4425
4643
  }
4644
+ // Rotates a matrix by the given angle around the Y axis.
4426
4645
  rotateY(radians2) {
4427
4646
  rotateY2(this, this, radians2);
4428
4647
  return this.check();
4429
4648
  }
4649
+ /**
4650
+ * Rotates a matrix by the given angle around the Z axis.
4651
+ * @param radians
4652
+ * @returns self
4653
+ */
4430
4654
  rotateZ(radians2) {
4431
4655
  rotateZ2(this, this, radians2);
4432
4656
  return this.check();
4433
4657
  }
4658
+ /**
4659
+ *
4660
+ * @param param0
4661
+ * @returns self
4662
+ */
4434
4663
  rotateXYZ(angleXYZ) {
4435
4664
  return this.rotateX(angleXYZ[0]).rotateY(angleXYZ[1]).rotateZ(angleXYZ[2]);
4436
4665
  }
4666
+ /**
4667
+ *
4668
+ * @param radians
4669
+ * @param axis
4670
+ * @returns self
4671
+ */
4437
4672
  rotateAxis(radians2, axis) {
4438
4673
  rotate3(this, this, radians2, axis);
4439
4674
  return this.check();
4440
4675
  }
4676
+ /**
4677
+ *
4678
+ * @param factor
4679
+ * @returns self
4680
+ */
4441
4681
  scale(factor) {
4442
4682
  scale4(this, this, Array.isArray(factor) ? factor : [factor, factor, factor]);
4443
4683
  return this.check();
4444
4684
  }
4685
+ /**
4686
+ *
4687
+ * @param vec
4688
+ * @returns self
4689
+ */
4445
4690
  translate(vector) {
4446
4691
  translate2(this, this, vector);
4447
4692
  return this.check();
4448
4693
  }
4694
+ // Transforms
4695
+ /**
4696
+ * Transforms any 2, 3 or 4 element vector. 2 and 3 elements are treated as points
4697
+ * @param vector
4698
+ * @param result
4699
+ * @returns self
4700
+ */
4449
4701
  transform(vector, result) {
4450
4702
  if (vector.length === 4) {
4451
4703
  result = transformMat43(result || [-0, -0, -0, -0], vector, this);
@@ -4454,6 +4706,12 @@ var Matrix4 = class extends Matrix {
4454
4706
  }
4455
4707
  return this.transformAsPoint(vector, result);
4456
4708
  }
4709
+ /**
4710
+ * Transforms any 2 or 3 element array as point (w implicitly 1)
4711
+ * @param vector
4712
+ * @param result
4713
+ * @returns self
4714
+ */
4457
4715
  transformAsPoint(vector, result) {
4458
4716
  const { length: length5 } = vector;
4459
4717
  let out;
@@ -4470,6 +4728,12 @@ var Matrix4 = class extends Matrix {
4470
4728
  checkVector(out, vector.length);
4471
4729
  return out;
4472
4730
  }
4731
+ /**
4732
+ * Transforms any 2 or 3 element array as vector (w implicitly 0)
4733
+ * @param vector
4734
+ * @param result
4735
+ * @returns self
4736
+ */
4473
4737
  transformAsVector(vector, result) {
4474
4738
  let out;
4475
4739
  switch (vector.length) {
@@ -4485,15 +4749,19 @@ var Matrix4 = class extends Matrix {
4485
4749
  checkVector(out, vector.length);
4486
4750
  return out;
4487
4751
  }
4752
+ /** @deprecated */
4488
4753
  transformPoint(vector, result) {
4489
4754
  return this.transformAsPoint(vector, result);
4490
4755
  }
4756
+ /** @deprecated */
4491
4757
  transformVector(vector, result) {
4492
4758
  return this.transformAsPoint(vector, result);
4493
4759
  }
4760
+ /** @deprecated */
4494
4761
  transformDirection(vector, result) {
4495
4762
  return this.transformAsVector(vector, result);
4496
4763
  }
4764
+ // three.js math API compatibility
4497
4765
  makeRotationX(radians2) {
4498
4766
  return this.identity().rotateX(radians2);
4499
4767
  }
@@ -4925,6 +5193,13 @@ var Quaternion = class extends MathArray {
4925
5193
  this[3] = object.w;
4926
5194
  return this.check();
4927
5195
  }
5196
+ /**
5197
+ * Creates a quaternion from the given 3x3 rotation matrix.
5198
+ * NOTE: The resultant quaternion is not normalized, so you should
5199
+ * be sure to renormalize the quaternion yourself where necessary.
5200
+ * @param m
5201
+ * @returns
5202
+ */
4928
5203
  fromMatrix3(m) {
4929
5204
  fromMat3(this, m);
4930
5205
  return this.check();
@@ -4933,13 +5208,21 @@ var Quaternion = class extends MathArray {
4933
5208
  setAxisAngle(this, axis, rad);
4934
5209
  return this.check();
4935
5210
  }
5211
+ /** Set a quat to the identity quaternion */
4936
5212
  identity() {
4937
5213
  identity3(this);
4938
5214
  return this.check();
4939
5215
  }
5216
+ // Set the components of a quat to the given values
5217
+ // set(i, j, k, l) {
5218
+ // quat_set(this, i, j, k, l);
5219
+ // return this.check();
5220
+ // }
5221
+ // Sets a quat from the given angle and rotation axis, then returns it.
4940
5222
  setAxisAngle(axis, rad) {
4941
5223
  return this.fromAxisRotation(axis, rad);
4942
5224
  }
5225
+ // Getters/setters
4943
5226
  get ELEMENTS() {
4944
5227
  return 4;
4945
5228
  }
@@ -4967,35 +5250,72 @@ var Quaternion = class extends MathArray {
4967
5250
  set w(value) {
4968
5251
  this[3] = checkNumber(value);
4969
5252
  }
5253
+ // Calculates the length of a quat
4970
5254
  len() {
4971
5255
  return length4(this);
4972
5256
  }
5257
+ // Calculates the squared length of a quat
4973
5258
  lengthSquared() {
4974
5259
  return squaredLength4(this);
4975
5260
  }
5261
+ // Calculates the dot product of two quat's
5262
+ // @return {Number}
4976
5263
  dot(a) {
4977
5264
  return dot4(this, a);
4978
5265
  }
5266
+ // Gets the rotation axis and angle for a given quaternion.
5267
+ // If a quaternion is created with setAxisAngle, this method will
5268
+ // return the same values as providied in the original parameter
5269
+ // list OR functionally equivalent values.
5270
+ // Example: The quaternion formed by axis [0, 0, 1] and angle -90
5271
+ // is the same as the quaternion formed by [0, 0, 1] and 270.
5272
+ // This method favors the latter.
5273
+ // @return {{[x,y,z], Number}}
5274
+ // getAxisAngle() {
5275
+ // const axis = [];
5276
+ // // const angle = quat_getAxisAngle(axis, this);
5277
+ // return {axis, angle};
5278
+ // }
5279
+ // MODIFIERS
5280
+ // Sets a quaternion to represent the shortest rotation from one vector
5281
+ // to another. Both vectors are assumed to be unit length.
4979
5282
  rotationTo(vectorA, vectorB) {
4980
5283
  rotationTo(this, vectorA, vectorB);
4981
5284
  return this.check();
4982
5285
  }
5286
+ // Sets the specified quaternion with values corresponding to the given axes.
5287
+ // Each axis is a vec3 and is expected to be unit length and perpendicular
5288
+ // to all other specified axes.
5289
+ // setAxes() {
5290
+ // Number
5291
+ // }
5292
+ // Performs a spherical linear interpolation with two control points
5293
+ // sqlerp() {
5294
+ // Number;
5295
+ // }
5296
+ // Adds two quat's
4983
5297
  add(a) {
4984
5298
  add6(this, this, a);
4985
5299
  return this.check();
4986
5300
  }
5301
+ // Calculates the W component of a quat from the X, Y, and Z components.
5302
+ // Any existing W component will be ignored.
4987
5303
  calculateW() {
4988
5304
  calculateW(this, this);
4989
5305
  return this.check();
4990
5306
  }
5307
+ // Calculates the conjugate of a quat If the quaternion is normalized,
5308
+ // this function is faster than quat_invert and produces the same result.
4991
5309
  conjugate() {
4992
5310
  conjugate(this, this);
4993
5311
  return this.check();
4994
5312
  }
5313
+ // Calculates the inverse of a quat
4995
5314
  invert() {
4996
5315
  invert3(this, this);
4997
5316
  return this.check();
4998
5317
  }
5318
+ // Performs a linear interpolation between two quat's
4999
5319
  lerp(a, b, t) {
5000
5320
  if (t === void 0) {
5001
5321
  return this.lerp(this, a, b);
@@ -5003,6 +5323,7 @@ var Quaternion = class extends MathArray {
5003
5323
  lerp5(this, a, b, t);
5004
5324
  return this.check();
5005
5325
  }
5326
+ // Multiplies two quat's
5006
5327
  multiplyRight(a) {
5007
5328
  multiply6(this, this, a);
5008
5329
  return this.check();
@@ -5011,6 +5332,7 @@ var Quaternion = class extends MathArray {
5011
5332
  multiply6(this, a, this);
5012
5333
  return this.check();
5013
5334
  }
5335
+ // Normalize a quat
5014
5336
  normalize() {
5015
5337
  const length5 = this.len();
5016
5338
  const l = length5 > 0 ? 1 / length5 : 0;
@@ -5023,22 +5345,27 @@ var Quaternion = class extends MathArray {
5023
5345
  }
5024
5346
  return this.check();
5025
5347
  }
5348
+ // Rotates a quaternion by the given angle about the X axis
5026
5349
  rotateX(rad) {
5027
5350
  rotateX3(this, this, rad);
5028
5351
  return this.check();
5029
5352
  }
5353
+ // Rotates a quaternion by the given angle about the Y axis
5030
5354
  rotateY(rad) {
5031
5355
  rotateY3(this, this, rad);
5032
5356
  return this.check();
5033
5357
  }
5358
+ // Rotates a quaternion by the given angle about the Z axis
5034
5359
  rotateZ(rad) {
5035
5360
  rotateZ3(this, this, rad);
5036
5361
  return this.check();
5037
5362
  }
5363
+ // Scales a quat by a scalar number
5038
5364
  scale(b) {
5039
5365
  scale6(this, this, b);
5040
5366
  return this.check();
5041
5367
  }
5368
+ // Performs a spherical linear interpolation between two quat
5042
5369
  slerp(arg0, arg1, arg2) {
5043
5370
  let start;
5044
5371
  let target;
@@ -5068,6 +5395,7 @@ var Quaternion = class extends MathArray {
5068
5395
  transformQuat2(result, vector, this);
5069
5396
  return checkVector(result, 4);
5070
5397
  }
5398
+ // THREE.js Math API compatibility
5071
5399
  lengthSq() {
5072
5400
  return this.lengthSquared();
5073
5401
  }
@@ -5086,6 +5414,27 @@ var Quaternion = class extends MathArray {
5086
5414
  var EPSILON2 = 1e-6;
5087
5415
  var EARTH_RADIUS_METERS = 6371e3;
5088
5416
  var SphericalCoordinates = class {
5417
+ // bearing: number;
5418
+ // pitch: number;
5419
+ // altitude: number;
5420
+ // lnglatZ coordinates
5421
+ // longitude: number;
5422
+ // latitude: number;
5423
+ // lng: number;
5424
+ // lat: number;
5425
+ // z: number;
5426
+ /**
5427
+ * Creates a new SphericalCoordinates object
5428
+ * @param options
5429
+ * @param [options.phi] =0 - rotation around X (latitude)
5430
+ * @param [options.theta] =0 - rotation around Y (longitude)
5431
+ * @param [options.radius] =1 - Distance from center
5432
+ * @param [options.bearing]
5433
+ * @param [options.pitch]
5434
+ * @param [options.altitude]
5435
+ * @param [options.radiusScale] =1
5436
+ */
5437
+ // eslint-disable-next-line complexity
5089
5438
  constructor({ phi = 0, theta = 0, radius = 1, bearing, pitch, altitude, radiusScale = EARTH_RADIUS_METERS } = {}) {
5090
5439
  this.phi = phi;
5091
5440
  this.theta = theta;
@@ -5112,6 +5461,8 @@ var SphericalCoordinates = class {
5112
5461
  exactEquals(other) {
5113
5462
  return this.radius === other.radius && this.theta === other.theta && this.phi === other.phi;
5114
5463
  }
5464
+ /* eslint-disable brace-style */
5465
+ // Cartographic (bearing 0 north, pitch 0 look from above)
5115
5466
  get bearing() {
5116
5467
  return 180 - degrees(this.phi);
5117
5468
  }
@@ -5124,6 +5475,10 @@ var SphericalCoordinates = class {
5124
5475
  set pitch(v) {
5125
5476
  this.theta = radians(v);
5126
5477
  }
5478
+ // get pitch() { return 90 - degrees(this.phi); }
5479
+ // set pitch(v) { this.phi = radians(v) + Math.PI / 2; }
5480
+ // get altitude() { return this.radius - 1; } // relative altitude
5481
+ // lnglatZ coordinates
5127
5482
  get longitude() {
5128
5483
  return degrees(this.phi);
5129
5484
  }
@@ -5139,6 +5494,7 @@ var SphericalCoordinates = class {
5139
5494
  get z() {
5140
5495
  return (this.radius - 1) * this.radiusScale;
5141
5496
  }
5497
+ /* eslint-enable brace-style */
5142
5498
  set(radius, phi, theta) {
5143
5499
  this.radius = radius;
5144
5500
  this.phi = phi;
@@ -5171,6 +5527,7 @@ var SphericalCoordinates = class {
5171
5527
  toVector3() {
5172
5528
  return new Vector3(0, 0, this.radius).rotateX({ radians: this.theta }).rotateZ({ radians: this.phi });
5173
5529
  }
5530
+ // restrict phi to be betwee EPS and PI-EPS
5174
5531
  makeSafe() {
5175
5532
  this.phi = Math.max(EPSILON2, Math.min(Math.PI - EPSILON2, this.phi));
5176
5533
  return this;
@@ -5196,6 +5553,7 @@ var RotationOrder;
5196
5553
  RotationOrder2[RotationOrder2["XYZ"] = 5] = "XYZ";
5197
5554
  })(RotationOrder || (RotationOrder = {}));
5198
5555
  var Euler = class extends MathArray {
5556
+ // Constants
5199
5557
  static get ZYX() {
5200
5558
  return RotationOrder.ZYX;
5201
5559
  }
@@ -5229,6 +5587,13 @@ var Euler = class extends MathArray {
5229
5587
  get ELEMENTS() {
5230
5588
  return 4;
5231
5589
  }
5590
+ /**
5591
+ * @class
5592
+ * @param {Number | Number[]} x
5593
+ * @param {Number=} [y]
5594
+ * @param {Number=} [z]
5595
+ * @param {Number=} [order]
5596
+ */
5232
5597
  constructor(x = 0, y = 0, z = 0, order = Euler.DefaultOrder) {
5233
5598
  super(-0, -0, -0, -0);
5234
5599
  if (arguments.length > 0 && Array.isArray(arguments[0])) {
@@ -5252,9 +5617,15 @@ var Euler = class extends MathArray {
5252
5617
  const yaw = Math.atan2(t1, t0);
5253
5618
  return this.set(roll, pitch, yaw, Euler.RollPitchYaw);
5254
5619
  }
5620
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
5255
5621
  fromObject(object) {
5256
5622
  throw new Error("not implemented");
5257
5623
  }
5624
+ // fromQuaternion(q, order) {
5625
+ // this._fromRotationMat[-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
5626
+ // return this.check();
5627
+ // }
5628
+ // If copied array does contain fourth element, preserves currently set order
5258
5629
  copy(array) {
5259
5630
  this[0] = array[0];
5260
5631
  this[1] = array[1];
@@ -5262,6 +5633,8 @@ var Euler = class extends MathArray {
5262
5633
  this[3] = Number.isFinite(array[3]) || this.order;
5263
5634
  return this.check();
5264
5635
  }
5636
+ // Sets the three angles, and optionally sets the rotation order
5637
+ // If order is not specified, preserves currently set order
5265
5638
  set(x = 0, y = 0, z = 0, order) {
5266
5639
  this[0] = x;
5267
5640
  this[1] = y;
@@ -5272,12 +5645,14 @@ var Euler = class extends MathArray {
5272
5645
  validate() {
5273
5646
  return validateOrder(this[3]) && Number.isFinite(this[0]) && Number.isFinite(this[1]) && Number.isFinite(this[2]);
5274
5647
  }
5648
+ // Does not copy the orientation element
5275
5649
  toArray(array = [], offset = 0) {
5276
5650
  array[offset] = this[0];
5277
5651
  array[offset + 1] = this[1];
5278
5652
  array[offset + 2] = this[2];
5279
5653
  return array;
5280
5654
  }
5655
+ // Copies the orientation element
5281
5656
  toArray4(array = [], offset = 0) {
5282
5657
  array[offset] = this[0];
5283
5658
  array[offset + 1] = this[1];
@@ -5291,6 +5666,8 @@ var Euler = class extends MathArray {
5291
5666
  result[2] = this[2];
5292
5667
  return result;
5293
5668
  }
5669
+ /* eslint-disable no-multi-spaces, brace-style, no-return-assign */
5670
+ // x, y, z angle notation (note: only corresponds to axis in XYZ orientation)
5294
5671
  get x() {
5295
5672
  return this[0];
5296
5673
  }
@@ -5309,6 +5686,7 @@ var Euler = class extends MathArray {
5309
5686
  set z(value) {
5310
5687
  this[2] = checkNumber(value);
5311
5688
  }
5689
+ // alpha, beta, gamma angle notation
5312
5690
  get alpha() {
5313
5691
  return this[0];
5314
5692
  }
@@ -5327,6 +5705,7 @@ var Euler = class extends MathArray {
5327
5705
  set gamma(value) {
5328
5706
  this[2] = checkNumber(value);
5329
5707
  }
5708
+ // phi, theta, psi angle notation
5330
5709
  get phi() {
5331
5710
  return this[0];
5332
5711
  }
@@ -5345,6 +5724,7 @@ var Euler = class extends MathArray {
5345
5724
  set psi(value) {
5346
5725
  this[2] = checkNumber(value);
5347
5726
  }
5727
+ // roll, pitch, yaw angle notation
5348
5728
  get roll() {
5349
5729
  return this[0];
5350
5730
  }
@@ -5363,15 +5743,18 @@ var Euler = class extends MathArray {
5363
5743
  set yaw(value) {
5364
5744
  this[2] = checkNumber(value);
5365
5745
  }
5746
+ // rotation order, in all three angle notations
5366
5747
  get order() {
5367
5748
  return this[3];
5368
5749
  }
5369
5750
  set order(value) {
5370
5751
  this[3] = checkOrder(value);
5371
5752
  }
5753
+ // Constructors
5372
5754
  fromVector3(v, order) {
5373
5755
  return this.set(v[0], v[1], v[2], Number.isFinite(order) ? order : this[3]);
5374
5756
  }
5757
+ // TODO - with and without 4th element
5375
5758
  fromArray(array, offset = 0) {
5376
5759
  this[0] = array[0 + offset];
5377
5760
  this[1] = array[1 + offset];
@@ -5381,6 +5764,7 @@ var Euler = class extends MathArray {
5381
5764
  }
5382
5765
  return this.check();
5383
5766
  }
5767
+ // Common ZYX rotation order
5384
5768
  fromRollPitchYaw(roll, pitch, yaw) {
5385
5769
  return this.set(roll, pitch, yaw, RotationOrder.ZYX);
5386
5770
  }
@@ -5388,9 +5772,11 @@ var Euler = class extends MathArray {
5388
5772
  this._fromRotationMatrix(m, order);
5389
5773
  return this.check();
5390
5774
  }
5775
+ // ACCESSORS
5391
5776
  getRotationMatrix(m) {
5392
5777
  return this._getRotationMatrix(m);
5393
5778
  }
5779
+ // TODO - move to Quaternion
5394
5780
  getQuaternion() {
5395
5781
  const q = new Quaternion();
5396
5782
  switch (this[3]) {
@@ -5410,6 +5796,14 @@ var Euler = class extends MathArray {
5410
5796
  throw new Error(ERR_UNKNOWN_ORDER);
5411
5797
  }
5412
5798
  }
5799
+ // INTERNAL METHODS
5800
+ // Conversion from Euler to rotation matrix and from matrix to Euler
5801
+ // Adapted from three.js under MIT license
5802
+ // // WARNING: this discards revolution information -bhouston
5803
+ // reorder(newOrder) {
5804
+ // const q = new Quaternion().setFromEuler(this);
5805
+ // return this.setFromQuaternion(q, newOrder);
5806
+ /* eslint-disable complexity, max-statements, one-var */
5413
5807
  _fromRotationMatrix(m, order = Euler.DefaultOrder) {
5414
5808
  const m11 = m[0], m12 = m[4], m13 = m[8];
5415
5809
  const m21 = m[1], m22 = m[5], m23 = m[9];
@@ -5683,17 +6077,29 @@ var Pose = class {
5683
6077
  const cw = Math.cos(this.yaw);
5684
6078
  return new Matrix4().setRowMajor(
5685
6079
  cw * cp,
6080
+ // 0,0
5686
6081
  -sw * cr + cw * sp * sr,
6082
+ // 0,1
5687
6083
  sw * sr + cw * sp * cr,
6084
+ // 0,2
5688
6085
  this.x,
6086
+ // 0,3
5689
6087
  sw * cp,
6088
+ // 1,0
5690
6089
  cw * cr + sw * sp * sr,
6090
+ // 1,1
5691
6091
  -cw * sr + sw * sp * cr,
6092
+ // 1,2
5692
6093
  this.y,
6094
+ // 1,3
5693
6095
  -sp,
6096
+ // 2,0
5694
6097
  cp * sr,
6098
+ // 2,1
5695
6099
  cp * cr,
6100
+ // 2,2
5696
6101
  this.z,
6102
+ // 2,3
5697
6103
  0,
5698
6104
  0,
5699
6105
  0,