@vertexvis/geometry 1.0.2-canary.2 → 1.0.2-canary.20

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/bundle.js CHANGED
@@ -1,5 +1,3 @@
1
- import { __assign, __spreadArray } from 'tslib';
2
-
3
1
  /**
4
2
  * Clamps the given value between `min` and `max`.
5
3
  *
@@ -29,24 +27,22 @@ function lerp$2(a, b, t) {
29
27
  /**
30
28
  * Returns a new `Point` with the given horizontal and vertical position.
31
29
  */
32
- function create$d(x, y) {
33
- if (x === void 0) { x = 0; }
34
- if (y === void 0) { y = 0; }
35
- return { x: x, y: y };
30
+ function create$d(x = 0, y = 0) {
31
+ return { x, y };
36
32
  }
37
33
  /**
38
34
  * Converts a polar coordinate (length and angle) into a Cartesian coordinate.
39
35
  */
40
36
  function polar(length, radians) {
41
- var x = Math.cos(radians) * length;
42
- var y = Math.sin(radians) * length;
37
+ const x = Math.cos(radians) * length;
38
+ const y = Math.sin(radians) * length;
43
39
  return create$d(x, y);
44
40
  }
45
41
  /**
46
42
  * Returns the distance between two points.
47
43
  */
48
44
  function distance$2(a, b) {
49
- var delta = subtract$1(a, b);
45
+ const delta = subtract$1(a, b);
50
46
  return Math.sqrt(delta.x * delta.x + delta.y * delta.y);
51
47
  }
52
48
  /**
@@ -118,7 +114,7 @@ function magnitude$2(pt) {
118
114
  * Transforms a vector into the corresponding normal (unit) vector.
119
115
  */
120
116
  function normalizeVector(pt) {
121
- var magnitudeOfPoint = magnitude$2(pt);
117
+ const magnitudeOfPoint = magnitude$2(pt);
122
118
  if (magnitudeOfPoint === 0) {
123
119
  return create$d(0, 0);
124
120
  }
@@ -136,19 +132,19 @@ function normalDirectionVector(ptA, ptB) {
136
132
  * Returns a vector orthogonal to the vector between the two given points.
137
133
  */
138
134
  function orthogonalVector(ptA, ptB) {
139
- var unitVectorBetweenPoints = normalDirectionVector(ptA, ptB);
135
+ const unitVectorBetweenPoints = normalDirectionVector(ptA, ptB);
140
136
  // Handle vectors that are parallel to the x or y axis
141
137
  if (unitVectorBetweenPoints.x === 0 || unitVectorBetweenPoints.y === 0) {
142
138
  return create$d(-1 * unitVectorBetweenPoints.y, unitVectorBetweenPoints.x);
143
139
  }
144
140
  if (Math.abs(unitVectorBetweenPoints.x) > Math.abs(unitVectorBetweenPoints.y)) {
145
- var vectorXValue = 1 - Math.pow(unitVectorBetweenPoints.x, 2);
146
- var vectorYValue = -1 * unitVectorBetweenPoints.x * unitVectorBetweenPoints.y;
141
+ const vectorXValue = 1 - Math.pow(unitVectorBetweenPoints.x, 2);
142
+ const vectorYValue = -1 * unitVectorBetweenPoints.x * unitVectorBetweenPoints.y;
147
143
  return normalizeVector(create$d(vectorXValue, vectorYValue));
148
144
  }
149
145
  else {
150
- var vectorXValue = -1 * unitVectorBetweenPoints.x * unitVectorBetweenPoints.y;
151
- var vectorYValue = 1 - Math.pow(unitVectorBetweenPoints.y, 2);
146
+ const vectorXValue = -1 * unitVectorBetweenPoints.x * unitVectorBetweenPoints.y;
147
+ const vectorYValue = 1 - Math.pow(unitVectorBetweenPoints.y, 2);
152
148
  return normalizeVector(create$d(vectorXValue, vectorYValue));
153
149
  }
154
150
  }
@@ -159,13 +155,13 @@ function orthogonalVector(ptA, ptB) {
159
155
  * @returns A parsed Point.
160
156
  */
161
157
  function fromJson$5(json) {
162
- var obj = JSON.parse(json);
158
+ const obj = JSON.parse(json);
163
159
  if (Array.isArray(obj)) {
164
- var x = obj[0], y = obj[1];
160
+ const [x, y] = obj;
165
161
  return create$d(x, y);
166
162
  }
167
163
  else {
168
- var x = obj.x, y = obj.y;
164
+ const { x, y } = obj;
169
165
  return create$d(x, y);
170
166
  }
171
167
  }
@@ -197,8 +193,8 @@ var point = /*#__PURE__*/Object.freeze({
197
193
  * @returns An angle in radians.
198
194
  */
199
195
  function fromPoints$1(a, b) {
200
- var delta = subtract$1(b, a);
201
- var theta = Math.atan2(delta.y, delta.x);
196
+ const delta = subtract$1(b, a);
197
+ const theta = Math.atan2(delta.y, delta.x);
202
198
  return theta;
203
199
  }
204
200
  /**
@@ -210,8 +206,8 @@ function fromPoints$1(a, b) {
210
206
  * @deprecated Use {@link fromPoints} instead.
211
207
  */
212
208
  function fromPointsInDegrees(a, b) {
213
- var delta = subtract$1(b, a);
214
- var theta = Math.atan2(delta.y, delta.x);
209
+ const delta = subtract$1(b, a);
210
+ const theta = Math.atan2(delta.y, delta.x);
215
211
  return normalize$2(toDegrees(theta) - 270);
216
212
  }
217
213
  /**
@@ -257,10 +253,10 @@ function fromValues(
257
253
  m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
258
254
  /* eslint-disable prettier/prettier */
259
255
  return [
260
- m11, m21, m31, m41,
261
- m12, m22, m32, m42,
262
- m13, m23, m33, m43,
263
- m14, m24, m34, m44,
256
+ m11, m12, m13, m14,
257
+ m21, m22, m23, m24,
258
+ m31, m32, m33, m34,
259
+ m41, m42, m43, m44,
264
260
  ];
265
261
  /* eslint-enable prettier/prettier */
266
262
  }
@@ -298,7 +294,7 @@ function makeZero() {
298
294
  * @returns A translation matrix.
299
295
  */
300
296
  function makeTranslation(translation) {
301
- var x = translation.x, y = translation.y, z = translation.z;
297
+ const { x, y, z } = translation;
302
298
  /* eslint-disable prettier/prettier */
303
299
  return [
304
300
  1, 0, 0, 0,
@@ -323,16 +319,16 @@ function makeTranslation(translation) {
323
319
  * @returns A rotation matrix.
324
320
  */
325
321
  function makeRotation(rotation) {
326
- var x = rotation.x, y = rotation.y, z = rotation.z, w = rotation.w;
327
- var x2 = x + x, y2 = y + y, z2 = z + z;
328
- var xx = x * x2, xy = x * y2, xz = x * z2;
329
- var yy = y * y2, yz = y * z2, zz = z * z2;
330
- var wx = w * x2, wy = w * y2, wz = w * z2;
322
+ const { x, y, z, w } = rotation;
323
+ const x2 = x + x, y2 = y + y, z2 = z + z;
324
+ const xx = x * x2, xy = x * y2, xz = x * z2;
325
+ const yy = y * y2, yz = y * z2, zz = z * z2;
326
+ const wx = w * x2, wy = w * y2, wz = w * z2;
331
327
  /* eslint-disable prettier/prettier */
332
328
  return [
333
- 1 - (yy + zz), xy + wz, xz - wy, 0,
334
- xy - wz, 1 - (xx + zz), yz + wx, 0,
335
- xz + wy, yz - wx, 1 - (xx + yy), 0,
329
+ 1 - (yy + zz), xy - wz, xz + wy, 0,
330
+ xy + wz, 1 - (xx + zz), yz - wx, 0,
331
+ xz - wy, yz + wx, 1 - (xx + yy), 0,
336
332
  0, 0, 0, 1
337
333
  ];
338
334
  /* eslint-enable prettier/prettier */
@@ -351,7 +347,7 @@ function makeRotation(rotation) {
351
347
  * @returns A scale matrix.
352
348
  */
353
349
  function makeScale(scale) {
354
- var x = scale.x, y = scale.y, z = scale.z;
350
+ const { x, y, z } = scale;
355
351
  /* eslint-disable prettier/prettier */
356
352
  return [
357
353
  x, 0, 0, 0,
@@ -362,33 +358,33 @@ function makeScale(scale) {
362
358
  /* eslint-enable prettier/prettier */
363
359
  }
364
360
  /**
365
- * Creates a matrix that has translation, rotation and scale applied to it.
361
+ * Creates a matrix that has translation, rotation, and scale applied to it.
366
362
  *
367
363
  * @param translation The translation applied to the matrix.
368
364
  * @param rotation The rotation applied to the matrix.
369
365
  * @param scale The scale applied to the matrix.
370
- * @returns A transformed matrix.
366
+ * @returns A transformed matrix in column-major form.
371
367
  */
372
368
  function makeTRS(translation, rotation, scale) {
373
- var t = makeTranslation(translation);
374
- var r = makeRotation(rotation);
375
- var s = makeScale(scale);
376
- return multiply$2(multiply$2(t, r), s);
369
+ const t = makeTranslation(translation);
370
+ const r = transpose(makeRotation(rotation));
371
+ const s = makeScale(scale);
372
+ return multiply$2(s, multiply$2(r, t));
377
373
  }
378
374
  /**
379
375
  * Returns a matrix that has the basis components (upper left 3x3 matrix) set to
380
376
  * the following x, y, and z axis.
381
377
  *
382
378
  * ```
383
- * x.x y.x z.x 0
384
- * x.y y.y z.y 0
385
- * x.z y.z z.z 0
379
+ * x.x x.y x.z 0
380
+ * y.x y.y y.z 0
381
+ * z.x z.y z.z 0
386
382
  * 0 0 0 0
387
383
  * ```
388
384
  *
389
- * @param x The x axis to set.
390
- * @param y The y axis to set.
391
- * @param z The z axis to set.
385
+ * @param x The x-axis to set.
386
+ * @param y The y-axis to set.
387
+ * @param z The z-axis to set.
392
388
  * @returns A matrix with its basis components populated.
393
389
  */
394
390
  function makeBasis(x, y, z) {
@@ -401,30 +397,6 @@ function makeBasis(x, y, z) {
401
397
  ];
402
398
  /* eslint-enable prettier/prettier */
403
399
  }
404
- /**
405
- * Creates a rotation matrix that is rotated around a given axis by the given
406
- * angle.
407
- *
408
- * @param axis The axis of rotation.
409
- * @param radians The angle of rotation.
410
- * @returns A rotation matrix.
411
- */
412
- function makeRotationAxis(axis, radians) {
413
- var c = Math.cos(radians);
414
- var s = Math.sin(radians);
415
- var t = 1 - c;
416
- var x = axis.x, y = axis.y, z = axis.z;
417
- var tx = t * x;
418
- var ty = t * y;
419
- /* eslint-disable prettier/prettier */
420
- return [
421
- tx * x + c, tx * y + s * z, tx * z - s * y, 0,
422
- tx * y - s * z, ty * y + c, ty * z + s * x, 0,
423
- tx * z + s * y, ty * z - s * x, t * z * z + c, 0,
424
- 0, 0, 0, 1
425
- ];
426
- /* eslint-enable prettier/prettier */
427
- }
428
400
  /**
429
401
  * Creates a matrix used for [perspective
430
402
  * projections](https://en.wikipedia.org/wiki/3D_projection#Perspective_projection).
@@ -444,12 +416,12 @@ function makeRotationAxis(axis, radians) {
444
416
  * @returns A matrix representing a view frustum.
445
417
  */
446
418
  function makeFrustum(left, right, top, bottom, near, far) {
447
- var x = (2 * near) / (right - left);
448
- var y = (2 * near) / (top - bottom);
449
- var a = (right + left) / (right - left);
450
- var b = (top + bottom) / (top - bottom);
451
- var c = -(far + near) / (far - near);
452
- var d = (-2 * far * near) / (far - near);
419
+ const x = (2 * near) / (right - left);
420
+ const y = (2 * near) / (top - bottom);
421
+ const a = (right + left) / (right - left);
422
+ const b = (top + bottom) / (top - bottom);
423
+ const c = -(far + near) / (far - near);
424
+ const d = (-2 * far * near) / (far - near);
453
425
  /* eslint-disable prettier/prettier */
454
426
  return [
455
427
  x, 0, 0, 0,
@@ -478,12 +450,12 @@ function makeFrustum(left, right, top, bottom, near, far) {
478
450
  * @returns A matrix.
479
451
  */
480
452
  function makePerspective(near, far, fovY, aspect) {
481
- var ymax = near * Math.tan(toRadians(fovY / 2.0));
482
- var xmax = ymax * aspect;
483
- var left = -xmax;
484
- var right = xmax;
485
- var top = ymax;
486
- var bottom = -ymax;
453
+ const ymax = near * Math.tan(toRadians(fovY / 2.0));
454
+ const xmax = ymax * aspect;
455
+ const left = -xmax;
456
+ const right = xmax;
457
+ const top = ymax;
458
+ const bottom = -ymax;
487
459
  return makeFrustum(left, right, top, bottom, near, far);
488
460
  }
489
461
  /**
@@ -504,12 +476,12 @@ function makePerspective(near, far, fovY, aspect) {
504
476
  * @returns A matrix.
505
477
  */
506
478
  function makeOrthographic(left, right, bottom, top, near, far) {
507
- var w = 1.0 / (right - left);
508
- var h = 1.0 / (top - bottom);
509
- var d = 1.0 / (far - near);
510
- var x = (right + left) * w;
511
- var y = (top + bottom) * h;
512
- var z = (far + near) * d;
479
+ const w = 1.0 / (right - left);
480
+ const h = 1.0 / (top - bottom);
481
+ const d = 1.0 / (far - near);
482
+ const x = (right + left) * w;
483
+ const y = (top + bottom) * h;
484
+ const z = (far + near) * d;
513
485
  /* eslint-disable prettier/prettier */
514
486
  return [
515
487
  2 * w, 0, 0, -x,
@@ -539,12 +511,12 @@ function makeOrthographic(left, right, bottom, top, near, far) {
539
511
  * @returns A matrix.
540
512
  */
541
513
  function makeLookAtView(position, lookAt, up) {
542
- var z = normalize(subtract(position, lookAt));
543
- var x = normalize(cross(up, z));
544
- var y = cross(z, x);
545
- var dotX = -dot$1(x, position);
546
- var dotY = -dot$1(y, position);
547
- var dotZ = -dot$1(z, position);
514
+ const z = normalize(subtract(position, lookAt));
515
+ const x = normalize(cross(up, z));
516
+ const y = cross(z, x);
517
+ const dotX = -dot$1(x, position);
518
+ const dotY = -dot$1(y, position);
519
+ const dotZ = -dot$1(z, position);
548
520
  /* eslint-disable prettier/prettier */
549
521
  return [
550
522
  x.x, y.x, z.x, 0,
@@ -568,9 +540,9 @@ function makeLookAtView(position, lookAt, up) {
568
540
  * @returns A matrix.
569
541
  */
570
542
  function makeLookAt(position, lookAt, up) {
571
- var z = normalize(subtract(position, lookAt));
572
- var x = normalize(cross(up, z));
573
- var y = cross(z, x);
543
+ const z = normalize(subtract(position, lookAt));
544
+ const x = normalize(cross(up, z));
545
+ const y = cross(z, x);
574
546
  /* eslint-disable prettier/prettier */
575
547
  return [
576
548
  x.x, x.y, x.z, 0,
@@ -585,45 +557,45 @@ function makeLookAt(position, lookAt, up) {
585
557
  * zero, then a zero matrix is returned.
586
558
  */
587
559
  function invert(matrix) {
588
- var a00 = matrix[0], a01 = matrix[1], a02 = matrix[2], a03 = matrix[3];
589
- var a10 = matrix[4], a11 = matrix[5], a12 = matrix[6], a13 = matrix[7];
590
- var a20 = matrix[8], a21 = matrix[9], a22 = matrix[10], a23 = matrix[11];
591
- var a30 = matrix[12], a31 = matrix[13], a32 = matrix[14], a33 = matrix[15];
592
- var b00 = a00 * a11 - a01 * a10;
593
- var b01 = a00 * a12 - a02 * a10;
594
- var b02 = a00 * a13 - a03 * a10;
595
- var b03 = a01 * a12 - a02 * a11;
596
- var b04 = a01 * a13 - a03 * a11;
597
- var b05 = a02 * a13 - a03 * a12;
598
- var b06 = a20 * a31 - a21 * a30;
599
- var b07 = a20 * a32 - a22 * a30;
600
- var b08 = a20 * a33 - a23 * a30;
601
- var b09 = a21 * a32 - a22 * a31;
602
- var b10 = a21 * a33 - a23 * a31;
603
- var b11 = a22 * a33 - a23 * a32;
560
+ const a00 = matrix[0], a01 = matrix[1], a02 = matrix[2], a03 = matrix[3];
561
+ const a10 = matrix[4], a11 = matrix[5], a12 = matrix[6], a13 = matrix[7];
562
+ const a20 = matrix[8], a21 = matrix[9], a22 = matrix[10], a23 = matrix[11];
563
+ const a30 = matrix[12], a31 = matrix[13], a32 = matrix[14], a33 = matrix[15];
564
+ const b00 = a00 * a11 - a01 * a10;
565
+ const b01 = a00 * a12 - a02 * a10;
566
+ const b02 = a00 * a13 - a03 * a10;
567
+ const b03 = a01 * a12 - a02 * a11;
568
+ const b04 = a01 * a13 - a03 * a11;
569
+ const b05 = a02 * a13 - a03 * a12;
570
+ const b06 = a20 * a31 - a21 * a30;
571
+ const b07 = a20 * a32 - a22 * a30;
572
+ const b08 = a20 * a33 - a23 * a30;
573
+ const b09 = a21 * a32 - a22 * a31;
574
+ const b10 = a21 * a33 - a23 * a31;
575
+ const b11 = a22 * a33 - a23 * a32;
604
576
  // Calculate the determinant
605
- var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
577
+ const det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
606
578
  if (!det) {
607
579
  return makeZero();
608
580
  }
609
- det = 1.0 / det;
581
+ const oneOverDet = 1 / det;
610
582
  return [
611
- (a11 * b11 - a12 * b10 + a13 * b09) * det,
612
- (a02 * b10 - a01 * b11 - a03 * b09) * det,
613
- (a31 * b05 - a32 * b04 + a33 * b03) * det,
614
- (a22 * b04 - a21 * b05 - a23 * b03) * det,
615
- (a12 * b08 - a10 * b11 - a13 * b07) * det,
616
- (a00 * b11 - a02 * b08 + a03 * b07) * det,
617
- (a32 * b02 - a30 * b05 - a33 * b01) * det,
618
- (a20 * b05 - a22 * b02 + a23 * b01) * det,
619
- (a10 * b10 - a11 * b08 + a13 * b06) * det,
620
- (a01 * b08 - a00 * b10 - a03 * b06) * det,
621
- (a30 * b04 - a31 * b02 + a33 * b00) * det,
622
- (a21 * b02 - a20 * b04 - a23 * b00) * det,
623
- (a11 * b07 - a10 * b09 - a12 * b06) * det,
624
- (a00 * b09 - a01 * b07 + a02 * b06) * det,
625
- (a31 * b01 - a30 * b03 - a32 * b00) * det,
626
- (a20 * b03 - a21 * b01 + a22 * b00) * det,
583
+ (a11 * b11 - a12 * b10 + a13 * b09) * oneOverDet,
584
+ (a02 * b10 - a01 * b11 - a03 * b09) * oneOverDet,
585
+ (a31 * b05 - a32 * b04 + a33 * b03) * oneOverDet,
586
+ (a22 * b04 - a21 * b05 - a23 * b03) * oneOverDet,
587
+ (a12 * b08 - a10 * b11 - a13 * b07) * oneOverDet,
588
+ (a00 * b11 - a02 * b08 + a03 * b07) * oneOverDet,
589
+ (a32 * b02 - a30 * b05 - a33 * b01) * oneOverDet,
590
+ (a20 * b05 - a22 * b02 + a23 * b01) * oneOverDet,
591
+ (a10 * b10 - a11 * b08 + a13 * b06) * oneOverDet,
592
+ (a01 * b08 - a00 * b10 - a03 * b06) * oneOverDet,
593
+ (a30 * b04 - a31 * b02 + a33 * b00) * oneOverDet,
594
+ (a21 * b02 - a20 * b04 - a23 * b00) * oneOverDet,
595
+ (a11 * b07 - a10 * b09 - a12 * b06) * oneOverDet,
596
+ (a00 * b09 - a01 * b07 + a02 * b06) * oneOverDet,
597
+ (a31 * b01 - a30 * b03 - a32 * b00) * oneOverDet,
598
+ (a20 * b03 - a21 * b01 + a22 * b00) * oneOverDet,
627
599
  ];
628
600
  }
629
601
  /**
@@ -637,70 +609,58 @@ function invert(matrix) {
637
609
  * @returns A rotation matrix.
638
610
  */
639
611
  function lookAt(m, position, target, up) {
640
- var z = subtract(position, target);
612
+ let z = subtract(position, target);
641
613
  if (magnitudeSquared(z) === 0) {
642
- z = __assign(__assign({}, z), { z: 1 });
614
+ z = { ...z, z: 1 };
643
615
  }
644
616
  z = normalize(z);
645
- var x = cross(up, z);
617
+ let x = cross(up, z);
646
618
  if (magnitudeSquared(x) === 0) {
647
619
  if (Math.abs(up.z) === 1) {
648
- z = __assign(__assign({}, z), { x: z.x + 0.0001 });
620
+ z = { ...z, x: z.x + 0.0001 };
649
621
  }
650
622
  else {
651
- z = __assign(__assign({}, z), { z: z.z + 0.0001 });
623
+ z = { ...z, z: z.z + 0.0001 };
652
624
  }
653
625
  z = normalize(z);
654
626
  x = cross(up, z);
655
627
  }
656
628
  x = normalize(x);
657
- var y = cross(z, x);
658
- var res = __spreadArray([], m, true);
629
+ const y = cross(z, x);
630
+ const res = [...m];
659
631
  /* eslint-disable prettier/prettier */
660
632
  res[0] = x.x;
661
- res[4] = y.x;
662
- res[8] = z.x;
663
633
  res[1] = x.y;
664
- res[5] = y.y;
665
- res[9] = z.y;
666
634
  res[2] = x.z;
635
+ res[4] = y.x;
636
+ res[5] = y.y;
667
637
  res[6] = y.z;
638
+ res[8] = z.x;
639
+ res[9] = z.y;
668
640
  res[10] = z.z;
669
641
  /* eslint-enable prettier/prettier */
670
642
  return res;
671
643
  }
672
644
  /**
673
- * Returns a post-multiplied matrix.
645
+ * Returns a post-multiplied matrix equal to ab.
674
646
  */
675
647
  function multiply$2(a, b) {
676
- var ae = a;
677
- var be = b;
678
- var a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
679
- var a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
680
- var a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
681
- var a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
682
- var b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
683
- var b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
684
- var b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
685
- var b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
686
- var mat = makeIdentity();
687
- mat[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
688
- mat[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
689
- mat[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
690
- mat[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
691
- mat[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
692
- mat[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
693
- mat[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
694
- mat[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
695
- mat[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
696
- mat[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
697
- mat[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
698
- mat[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
699
- mat[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
700
- mat[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
701
- mat[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
702
- mat[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
703
- return mat;
648
+ const result = makeIdentity();
649
+ // Consider each row i in the final matrix
650
+ for (let i = 0; i < 4; i++) {
651
+ // Consider each column j in the final matrix
652
+ for (let j = 0; j < 4; j++) {
653
+ // Calculate the value at row i and column j
654
+ let value = 0;
655
+ for (let k = 0; k < 4; k++) {
656
+ // Calculate (ik + kj) and add it to the value
657
+ value += a[i * 4 + k] * b[k * 4 + j];
658
+ }
659
+ const positionInResultingMatrix = 4 * i + j;
660
+ result[positionInResultingMatrix] = value;
661
+ }
662
+ }
663
+ return result;
704
664
  }
705
665
  /**
706
666
  * Returns the [transpose](https://en.wikipedia.org/wiki/Transpose) of the given
@@ -717,45 +677,60 @@ function transpose(matrix) {
717
677
  /* eslint-enable prettier/prettier */
718
678
  }
719
679
  /**
720
- * Multiplies the columns of a matrix by the given vector.
680
+ * Multiplies the columns of a row-major matrix by the given vector.
721
681
  */
722
682
  function scale$4(matrix, scale) {
723
- var x = scale.x, y = scale.y, z = scale.z;
724
- var m = __spreadArray([], matrix, true);
683
+ const { x, y, z } = scale;
684
+ const m = [...matrix];
725
685
  /* eslint-disable prettier/prettier */
726
686
  m[0] *= x;
727
- m[4] *= y;
728
- m[8] *= z;
729
687
  m[1] *= x;
730
- m[5] *= y;
731
- m[9] *= z;
732
688
  m[2] *= x;
733
- m[6] *= y;
734
- m[10] *= z;
735
689
  m[3] *= x;
690
+ m[4] *= y;
691
+ m[5] *= y;
692
+ m[6] *= y;
736
693
  m[7] *= y;
694
+ m[8] *= z;
695
+ m[9] *= z;
696
+ m[10] *= z;
737
697
  m[11] *= z;
738
698
  /* eslint-enable prettier/prettier */
739
699
  return m;
740
700
  }
741
- function position(matrix, other) {
742
- var m = __spreadArray([], matrix, true);
743
- m[12] = other[12];
744
- m[13] = other[13];
745
- m[14] = other[14];
701
+ /**
702
+ * Sets the position of the matrix given as the first parameter
703
+ * to the position of the matrix given as the second parameter.
704
+ * Both matrices should have row-major format.
705
+ */
706
+ function position(originalMatrix, matrixWithDesiredPosition) {
707
+ const m = [...originalMatrix];
708
+ m[12] = matrixWithDesiredPosition[12];
709
+ m[13] = matrixWithDesiredPosition[13];
710
+ m[14] = matrixWithDesiredPosition[14];
746
711
  return m;
747
712
  }
748
713
  /**
749
714
  * Returns true if the matrix is an identity matrix.
750
715
  */
751
716
  function isIdentity(matrix) {
752
- var identity = makeIdentity();
753
- return matrix.every(function (v, i) { return v === identity[i]; });
717
+ const identity = makeIdentity();
718
+ return matrix.every((v, i) => v === identity[i]);
754
719
  }
755
720
  /**
756
721
  * Returns an object representation of a `Matrix4`.
722
+ * @param m A Matrix4 item written in column-major form.
723
+ *
724
+ * @deprecated Use {@link toObjectColumnMajor} or {@link toObjectRowMajor} instead.
757
725
  */
758
726
  function toObject(m) {
727
+ return toObjectColumnMajor(m);
728
+ }
729
+ /**
730
+ * Returns an object representation of a `Matrix4`.
731
+ * @param m A Matrix4 item written in column-major form.
732
+ */
733
+ function toObjectColumnMajor(m) {
759
734
  /* eslint-disable prettier/prettier */
760
735
  return {
761
736
  m11: m[0], m12: m[4], m13: m[8], m14: m[12],
@@ -765,6 +740,20 @@ function toObject(m) {
765
740
  };
766
741
  /* eslint-enable prettier/prettier */
767
742
  }
743
+ /**
744
+ * Returns an object representation of a `Matrix4`.
745
+ * @param m A Matrix4 item written in row-major form.
746
+ */
747
+ function toObjectRowMajor(m) {
748
+ /* eslint-disable prettier/prettier */
749
+ return {
750
+ m11: m[0], m12: m[1], m13: m[2], m14: m[3],
751
+ m21: m[4], m22: m[5], m23: m[6], m24: m[7],
752
+ m31: m[8], m32: m[9], m33: m[10], m34: m[11],
753
+ m41: m[12], m42: m[13], m43: m[14], m44: m[15],
754
+ };
755
+ /* eslint-enable prettier/prettier */
756
+ }
768
757
  /**
769
758
  * A type guard to check if `obj` is of type `Matrix4`.
770
759
  */
@@ -788,7 +777,6 @@ var matrix4 = /*#__PURE__*/Object.freeze({
788
777
  makeOrthographic: makeOrthographic,
789
778
  makePerspective: makePerspective,
790
779
  makeRotation: makeRotation,
791
- makeRotationAxis: makeRotationAxis,
792
780
  makeScale: makeScale,
793
781
  makeTRS: makeTRS,
794
782
  makeTranslation: makeTranslation,
@@ -797,6 +785,8 @@ var matrix4 = /*#__PURE__*/Object.freeze({
797
785
  position: position,
798
786
  scale: scale$4,
799
787
  toObject: toObject,
788
+ toObjectColumnMajor: toObjectColumnMajor,
789
+ toObjectRowMajor: toObjectRowMajor,
800
790
  transpose: transpose
801
791
  });
802
792
 
@@ -808,9 +798,8 @@ var matrix4 = /*#__PURE__*/Object.freeze({
808
798
  * @param value The values to populate the Euler angles with.
809
799
  * @returns A set of Euler angles.
810
800
  */
811
- function create$c(value) {
801
+ function create$c(value = {}) {
812
802
  var _a, _b, _c, _d;
813
- if (value === void 0) { value = {}; }
814
803
  return {
815
804
  x: (_a = value.x) !== null && _a !== void 0 ? _a : 0,
816
805
  y: (_b = value.y) !== null && _b !== void 0 ? _b : 0,
@@ -826,14 +815,13 @@ function create$c(value) {
826
815
  * @param value The values to populate the Euler angles with.
827
816
  * @returns A set of Euler angles.
828
817
  */
829
- function fromDegrees(value) {
830
- if (value === void 0) { value = {}; }
831
- var _a = value.x, x = _a === void 0 ? 0 : _a, _b = value.y, y = _b === void 0 ? 0 : _b, _c = value.z, z = _c === void 0 ? 0 : _c, order = value.order;
818
+ function fromDegrees(value = {}) {
819
+ const { x = 0, y = 0, z = 0, order } = value;
832
820
  return create$c({
833
821
  x: toRadians(x),
834
822
  y: toRadians(y),
835
823
  z: toRadians(z),
836
- order: order,
824
+ order,
837
825
  });
838
826
  }
839
827
  /**
@@ -847,10 +835,11 @@ function fromDegrees(value) {
847
835
  * @param matrix A pure rotation matrix, unscaled.
848
836
  * @param order The order that the rotations are applied.
849
837
  */
850
- function fromRotationMatrix(matrix, order) {
851
- if (order === void 0) { order = 'xyz'; }
852
- var m = toObject(matrix);
853
- var x = 0, y = 0, z = 0;
838
+ function fromRotationMatrix(matrix, order = 'xyz', matrixIsColumnMajor = true) {
839
+ const m = matrixIsColumnMajor
840
+ ? toObjectColumnMajor(matrix)
841
+ : toObjectRowMajor(matrix);
842
+ let x = 0, y = 0, z = 0;
854
843
  if (order === 'xyz') {
855
844
  y = Math.asin(clamp(m.m13, -1, 1));
856
845
  if (Math.abs(m.m13) < 0.9999999) {
@@ -917,7 +906,7 @@ function fromRotationMatrix(matrix, order) {
917
906
  y = 0;
918
907
  }
919
908
  }
920
- return { x: x, y: y, z: z, order: order };
909
+ return { x, y, z, order };
921
910
  }
922
911
  /**
923
912
  * Returns a set of Euler angles that was decoded from a JSON string. Supports either
@@ -928,14 +917,14 @@ function fromRotationMatrix(matrix, order) {
928
917
  * @returns A set of Euler angles.
929
918
  */
930
919
  function fromJson$4(json) {
931
- var obj = JSON.parse(json);
920
+ const obj = JSON.parse(json);
932
921
  if (Array.isArray(obj)) {
933
- var x = obj[0], y = obj[1], z = obj[2], _a = obj[3], order = _a === void 0 ? 'xyz' : _a;
934
- return { x: x, y: y, z: z, order: order };
922
+ const [x, y, z, order = 'xyz'] = obj;
923
+ return { x, y, z, order };
935
924
  }
936
925
  else {
937
- var x = obj.x, y = obj.y, z = obj.z, _b = obj.order, order = _b === void 0 ? 'xyz' : _b;
938
- return { x: x, y: y, z: z, order: order };
926
+ const { x, y, z, order = 'xyz' } = obj;
927
+ return { x, y, z, order };
939
928
  }
940
929
  }
941
930
  /**
@@ -943,7 +932,7 @@ function fromJson$4(json) {
943
932
  */
944
933
  function isType$1(obj) {
945
934
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
946
- var o = obj;
935
+ const o = obj;
947
936
  return (o != null &&
948
937
  o.hasOwnProperty('x') &&
949
938
  o.hasOwnProperty('y') &&
@@ -964,9 +953,8 @@ var euler = /*#__PURE__*/Object.freeze({
964
953
  * Returns a new quaternion. If `value` is undefined, then `{x: 0, y: 0, z: 0,
965
954
  * w: 1}` is returned.
966
955
  */
967
- function create$b(value) {
968
- if (value === void 0) { value = {}; }
969
- return __assign({ x: 0, y: 0, z: 0, w: 1 }, value);
956
+ function create$b(value = {}) {
957
+ return { x: 0, y: 0, z: 0, w: 1, ...value };
970
958
  }
971
959
  /**
972
960
  * Parses a JSON string representation of a `Quaternion`.
@@ -975,10 +963,10 @@ function create$b(value) {
975
963
  * @returns A parsed `Quaternion`.
976
964
  */
977
965
  function fromJson$3(json) {
978
- var obj = JSON.parse(json);
966
+ const obj = JSON.parse(json);
979
967
  if (Array.isArray(obj)) {
980
- var x = obj[0], y = obj[1], z = obj[2], w = obj[3];
981
- return create$b({ x: x, y: y, z: z, w: w });
968
+ const [x, y, z, w] = obj;
969
+ return create$b({ x, y, z, w });
982
970
  }
983
971
  else {
984
972
  return create$b(obj);
@@ -1015,80 +1003,72 @@ function scale$3(scalar, q) {
1015
1003
  * @returns A rotated quaternion.
1016
1004
  */
1017
1005
  function fromAxisAngle(axis, radians) {
1018
- var halfAngle = radians / 2;
1019
- var s = Math.sin(halfAngle);
1020
- var x = axis.x * s;
1021
- var y = axis.y * s;
1022
- var z = axis.z * s;
1023
- var w = Math.cos(halfAngle);
1024
- return { x: x, y: y, z: z, w: w };
1006
+ const halfAngle = radians / 2;
1007
+ const s = Math.sin(halfAngle);
1008
+ const x = axis.x * s;
1009
+ const y = axis.y * s;
1010
+ const z = axis.z * s;
1011
+ const w = Math.cos(halfAngle);
1012
+ return { x, y, z, w };
1025
1013
  }
1026
1014
  /**
1027
1015
  * Returns a quaternion using the upper 3x3 of a pure rotation matrix
1028
1016
  * (unscaled).
1029
1017
  */
1030
1018
  function fromMatrixRotation(matrix) {
1031
- var m = toObject(matrix);
1032
- var scale = fromMatrixScale(matrix);
1033
- var is1 = 1 / scale.x;
1034
- var is2 = 1 / scale.y;
1035
- var is3 = 1 / scale.z;
1036
- var sm11 = m.m11 * is1;
1037
- var sm12 = m.m21 * is2;
1038
- var sm13 = m.m31 * is3;
1039
- var sm21 = m.m12 * is1;
1040
- var sm22 = m.m22 * is2;
1041
- var sm23 = m.m32 * is3;
1042
- var sm31 = m.m13 * is1;
1043
- var sm32 = m.m23 * is2;
1044
- var sm33 = m.m33 * is3;
1045
- var trace = sm11 + sm22 + sm33;
1019
+ // Determine the scalars for each vector
1020
+ const scale = fromMatrixScale(matrix);
1021
+ const oneOverScaleVector = create$a(1 / scale.x, 1 / scale.y, 1 / scale.z);
1022
+ // Scale the matrix
1023
+ const scaledMatrix = scale$4(matrix, oneOverScaleVector);
1024
+ const sM = toObjectRowMajor(scaledMatrix);
1025
+ const trace = sM.m11 + sM.m22 + sM.m33;
1046
1026
  if (trace > 0) {
1047
- var s = Math.sqrt(trace + 1.0) * 2;
1027
+ const s = Math.sqrt(trace + 1) * 2;
1048
1028
  return {
1049
- x: (sm23 - sm32) / s,
1050
- y: (sm31 - sm13) / s,
1051
- z: (sm12 - sm21) / s,
1029
+ x: (sM.m23 - sM.m32) / s,
1030
+ y: (sM.m31 - sM.m13) / s,
1031
+ z: (sM.m12 - sM.m21) / s,
1052
1032
  w: 0.25 * s,
1053
1033
  };
1054
1034
  }
1055
- else if (sm11 > sm22 && sm11 > sm33) {
1056
- var s = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
1035
+ else if (sM.m11 > sM.m22 && sM.m11 > sM.m33) {
1036
+ const s = Math.sqrt(1 + sM.m11 - sM.m22 - sM.m33) * 2;
1057
1037
  return {
1058
1038
  x: 0.25 * s,
1059
- y: (sm12 + sm21) / s,
1060
- z: (sm31 + sm13) / s,
1061
- w: (sm23 - sm32) / s,
1039
+ y: (sM.m12 + sM.m21) / s,
1040
+ z: (sM.m31 + sM.m13) / s,
1041
+ w: (sM.m23 - sM.m32) / s,
1062
1042
  };
1063
1043
  }
1064
- else if (sm22 > sm33) {
1065
- var s = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
1044
+ else if (sM.m22 > sM.m33) {
1045
+ const s = Math.sqrt(1 + sM.m22 - sM.m11 - sM.m33) * 2;
1066
1046
  return {
1067
- x: (sm12 + sm21) / s,
1047
+ x: (sM.m12 + sM.m21) / s,
1068
1048
  y: 0.25 * s,
1069
- z: (sm23 + sm32) / s,
1070
- w: (sm31 - sm13) / s,
1049
+ z: (sM.m23 + sM.m32) / s,
1050
+ w: (sM.m31 - sM.m13) / s,
1071
1051
  };
1072
1052
  }
1073
1053
  else {
1074
- var s = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
1054
+ const s = Math.sqrt(1 + sM.m33 - sM.m11 - sM.m22) * 2;
1075
1055
  return {
1076
- x: (sm31 + sm13) / s,
1077
- y: (sm23 + sm32) / s,
1056
+ x: (sM.m31 + sM.m13) / s,
1057
+ y: (sM.m23 + sM.m32) / s,
1078
1058
  z: 0.25 * s,
1079
- w: (sm12 - sm21) / s,
1059
+ w: (sM.m12 - sM.m21) / s,
1080
1060
  };
1081
1061
  }
1082
1062
  }
1083
1063
  function fromEuler(euler) {
1084
- var ex = euler.x, ey = euler.y, ez = euler.z, order = euler.order;
1085
- var c1 = Math.cos(ex / 2);
1086
- var c2 = Math.cos(ey / 2);
1087
- var c3 = Math.cos(ez / 2);
1088
- var s1 = Math.sin(ex / 2);
1089
- var s2 = Math.sin(ey / 2);
1090
- var s3 = Math.sin(ez / 2);
1091
- var x = 0, y = 0, z = 0, w = 0;
1064
+ const { x: ex, y: ey, z: ez, order } = euler;
1065
+ const c1 = Math.cos(ex / 2);
1066
+ const c2 = Math.cos(ey / 2);
1067
+ const c3 = Math.cos(ez / 2);
1068
+ const s1 = Math.sin(ex / 2);
1069
+ const s2 = Math.sin(ey / 2);
1070
+ const s3 = Math.sin(ez / 2);
1071
+ let x = 0, y = 0, z = 0, w = 0;
1092
1072
  switch (order) {
1093
1073
  case 'xyz':
1094
1074
  x = s1 * c2 * c3 + c1 * s2 * s3;
@@ -1127,7 +1107,7 @@ function fromEuler(euler) {
1127
1107
  w = c1 * c2 * c3 + s1 * s2 * s3;
1128
1108
  break;
1129
1109
  }
1130
- return { x: x, y: y, z: z, w: w };
1110
+ return { x, y, z, w };
1131
1111
  }
1132
1112
  /**
1133
1113
  * Multiplies `a` x `b` and returns a new quaternion with the result.
@@ -1146,7 +1126,7 @@ function multiply$1(a, b) {
1146
1126
  */
1147
1127
  function isType(obj) {
1148
1128
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1149
- var o = obj;
1129
+ const o = obj;
1150
1130
  return (o != null &&
1151
1131
  o.hasOwnProperty('x') &&
1152
1132
  o.hasOwnProperty('y') &&
@@ -1168,12 +1148,8 @@ var quaternion = /*#__PURE__*/Object.freeze({
1168
1148
  scale: scale$3
1169
1149
  });
1170
1150
 
1171
- function create$a() {
1151
+ function create$a(...args) {
1172
1152
  var _a, _b, _c, _d, _e, _f;
1173
- var args = [];
1174
- for (var _i = 0; _i < arguments.length; _i++) {
1175
- args[_i] = arguments[_i];
1176
- }
1177
1153
  if (args.length === 1) {
1178
1154
  return {
1179
1155
  x: (_a = args[0].x) !== null && _a !== void 0 ? _a : 0,
@@ -1200,27 +1176,33 @@ function create$a() {
1200
1176
  * Checks if each component of the given vector is populated with a numeric
1201
1177
  * component. A component is invalid if it contains a non-finite or NaN value.
1202
1178
  */
1203
- function isValid$1(_a) {
1204
- var x = _a.x, y = _a.y, z = _a.z;
1205
- return [x, y, z].every(function (v) { return isFinite(v) && !isNaN(v); });
1179
+ function isValid$1({ x, y, z }) {
1180
+ return [x, y, z].every((v) => isFinite(v) && !isNaN(v));
1181
+ }
1182
+ /**
1183
+ * Checks if every component of the given vector is zero.
1184
+ * Useful for detecting potentially problematic camera vectors, for example.
1185
+ */
1186
+ function isZeroVector({ x, y, z }) {
1187
+ return [x, y, z].every((v) => v === 0);
1206
1188
  }
1207
1189
  /**
1208
1190
  * Returns a vector representing the scale elements of `matrix`.
1209
1191
  */
1210
1192
  function fromMatrixScale(matrix) {
1211
- var m = toObject(matrix);
1193
+ const m = toObjectRowMajor(matrix);
1212
1194
  return {
1213
- x: Math.hypot(m.m11, m.m21, m.m31),
1214
- y: Math.hypot(m.m12, m.m22, m.m32),
1215
- z: Math.hypot(m.m13, m.m23, m.m33),
1195
+ x: Math.hypot(m.m11, m.m12, m.m13),
1196
+ y: Math.hypot(m.m21, m.m22, m.m23),
1197
+ z: Math.hypot(m.m31, m.m32, m.m33),
1216
1198
  };
1217
1199
  }
1218
1200
  /**
1219
1201
  * Returns a vector representing the position elements of `matrix`.
1220
1202
  */
1221
1203
  function fromMatrixPosition(matrix) {
1222
- var m = toObject(matrix);
1223
- return { x: m.m14, y: m.m24, z: m.m34 };
1204
+ const m = toObjectRowMajor(matrix);
1205
+ return { x: m.m41, y: m.m42, z: m.m43 };
1224
1206
  }
1225
1207
  /**
1226
1208
  * Parses a JSON string representation of a Vector3 and returns an object.
@@ -1229,13 +1211,13 @@ function fromMatrixPosition(matrix) {
1229
1211
  * @returns A parsed Vector3.
1230
1212
  */
1231
1213
  function fromJson$2(json) {
1232
- var obj = JSON.parse(json);
1214
+ const obj = JSON.parse(json);
1233
1215
  if (Array.isArray(obj)) {
1234
- var x = obj[0], y = obj[1], z = obj[2];
1216
+ const [x, y, z] = obj;
1235
1217
  return create$a(x, y, z);
1236
1218
  }
1237
1219
  else {
1238
- var x = obj.x, y = obj.y, z = obj.z;
1220
+ const { x, y, z } = obj;
1239
1221
  return create$a(x, y, z);
1240
1222
  }
1241
1223
  }
@@ -1246,11 +1228,10 @@ function fromJson$2(json) {
1246
1228
  * @see #toArray()
1247
1229
  * @see #create()
1248
1230
  */
1249
- function fromArray(nums, offset) {
1250
- if (offset === void 0) { offset = 0; }
1251
- var x = nums[offset];
1252
- var y = nums[offset + 1];
1253
- var z = nums[offset + 2];
1231
+ function fromArray(nums, offset = 0) {
1232
+ const x = nums[offset];
1233
+ const y = nums[offset + 1];
1234
+ const z = nums[offset + 2];
1254
1235
  return create$a(x, y, z);
1255
1236
  }
1256
1237
  /**
@@ -1260,8 +1241,7 @@ function fromArray(nums, offset) {
1260
1241
  * @see #fromArray()
1261
1242
  * @see #create()
1262
1243
  */
1263
- function toArray(_a) {
1264
- var x = _a.x, y = _a.y, z = _a.z;
1244
+ function toArray({ x, y, z }) {
1265
1245
  return [x, y, z];
1266
1246
  }
1267
1247
  /**
@@ -1310,7 +1290,7 @@ function origin() {
1310
1290
  * Returns a vector with that will have a magnitude of 1.
1311
1291
  */
1312
1292
  function normalize(vector) {
1313
- var length = magnitude(vector);
1293
+ const length = magnitude(vector);
1314
1294
  return { x: vector.x / length, y: vector.y / length, z: vector.z / length };
1315
1295
  }
1316
1296
  /**
@@ -1347,24 +1327,16 @@ function cross(a, b) {
1347
1327
  /**
1348
1328
  * Returns a vector that is the sum of two vectors.
1349
1329
  */
1350
- function add(a) {
1351
- var vectors = [];
1352
- for (var _i = 1; _i < arguments.length; _i++) {
1353
- vectors[_i - 1] = arguments[_i];
1354
- }
1355
- return vectors.reduce(function (res, next) {
1330
+ function add(a, ...vectors) {
1331
+ return vectors.reduce((res, next) => {
1356
1332
  return { x: res.x + next.x, y: res.y + next.y, z: res.z + next.z };
1357
1333
  }, a);
1358
1334
  }
1359
1335
  /**
1360
1336
  * Returns a vector that is the difference between two vectors.
1361
1337
  */
1362
- function subtract(a) {
1363
- var vectors = [];
1364
- for (var _i = 1; _i < arguments.length; _i++) {
1365
- vectors[_i - 1] = arguments[_i];
1366
- }
1367
- return vectors.reduce(function (res, next) {
1338
+ function subtract(a, ...vectors) {
1339
+ return vectors.reduce((res, next) => {
1368
1340
  return { x: res.x - next.x, y: res.y - next.y, z: res.z - next.z };
1369
1341
  }, a);
1370
1342
  }
@@ -1398,7 +1370,7 @@ function dot$1(a, b) {
1398
1370
  * result is never greater than 180 degrees.
1399
1371
  */
1400
1372
  function angleTo(a, b) {
1401
- var theta = dot$1(a, b) / (magnitude(a) * magnitude(b));
1373
+ const theta = dot$1(a, b) / (magnitude(a) * magnitude(b));
1402
1374
  // Clamp to avoid numerical problems.
1403
1375
  return Math.acos(theta);
1404
1376
  }
@@ -1409,16 +1381,19 @@ function angleTo(a, b) {
1409
1381
  * algorithm described in https://www.xarg.org/proof/quaternion-from-two-vectors/.
1410
1382
  */
1411
1383
  function eulerTo(a, b) {
1412
- var normalizedA = normalize(a);
1413
- var normalizedB = normalize(b);
1414
- var dotDelta = Math.cos(toRadians(1));
1415
- var dotAB = dot$1(normalizedA, normalizedB);
1416
- var vectorsAreParallel = Math.abs(dotAB) > dotDelta;
1384
+ const normalizedA = normalize(a);
1385
+ const normalizedB = normalize(b);
1386
+ const dotDelta = Math.cos(toRadians(1));
1387
+ const dotAB = dot$1(normalizedA, normalizedB);
1388
+ const vectorsAreParallel = Math.abs(dotAB) > dotDelta;
1417
1389
  if (vectorsAreParallel) {
1418
1390
  return dotAB > 1 - 1e-6 ? create$c() : create$c({ x: Math.PI });
1419
1391
  }
1420
- var normalizedQ = normalize$1(create$b(__assign({ w: 1 + dotAB }, cross(normalizedA, normalizedB))));
1421
- return fromRotationMatrix(makeRotation(normalizedQ));
1392
+ const normalizedQ = normalize$1(create$b({
1393
+ w: 1 + dotAB,
1394
+ ...cross(normalizedA, normalizedB),
1395
+ }));
1396
+ return fromRotationMatrix(makeRotation(normalizedQ), 'xyz', false);
1422
1397
  }
1423
1398
  /**
1424
1399
  * Performs a projection of a `vector` onto `onNormal`.
@@ -1448,18 +1423,18 @@ function project(vector, onNormal) {
1448
1423
  */
1449
1424
  function rotateAboutAxis(angle, point, axisDirection, axisPosition) {
1450
1425
  if (angle !== 0) {
1451
- var x = point.x, y = point.y, z = point.z;
1452
- var a = axisPosition.x, b = axisPosition.y, c = axisPosition.z;
1453
- var u = axisDirection.x, v = axisDirection.y, w = axisDirection.z;
1454
- var newX = (a * (v * v + w * w) - u * (b * v + c * w - u * x - v * y - w * z)) *
1426
+ const { x, y, z } = point;
1427
+ const { x: a, y: b, z: c } = axisPosition;
1428
+ const { x: u, y: v, z: w } = axisDirection;
1429
+ const newX = (a * (v * v + w * w) - u * (b * v + c * w - u * x - v * y - w * z)) *
1455
1430
  (1 - Math.cos(angle)) +
1456
1431
  x * Math.cos(angle) +
1457
1432
  (-c * v + b * w - w * y + v * z) * Math.sin(angle);
1458
- var newY = (b * (u * u + w * w) - v * (a * u + c * w - u * x - v * y - w * z)) *
1433
+ const newY = (b * (u * u + w * w) - v * (a * u + c * w - u * x - v * y - w * z)) *
1459
1434
  (1 - Math.cos(angle)) +
1460
1435
  y * Math.cos(angle) +
1461
1436
  (c * u - a * w + w * x - u * z) * Math.sin(angle);
1462
- var newZ = (c * (u * u + v * v) - w * (a * u + b * v - u * x - v * y - w * z)) *
1437
+ const newZ = (c * (u * u + v * v) - w * (a * u + b * v - u * x - v * y - w * z)) *
1463
1438
  (1 - Math.cos(angle)) +
1464
1439
  z * Math.cos(angle) +
1465
1440
  (-b * u + a * v - v * x + u * y) * Math.sin(angle);
@@ -1470,17 +1445,43 @@ function rotateAboutAxis(angle, point, axisDirection, axisPosition) {
1470
1445
  }
1471
1446
  }
1472
1447
  /**
1473
- * Returns a vector that is multiplied with a matrix.
1448
+ * Returns a vector that is multiplied with a matrix in column-major form.
1449
+ * @param vector A Vector3 item.
1450
+ * @param m A Matrix4 item written in column-major form.
1451
+ *
1452
+ * @deprecated Use {@link multiplyByTransformMatrixColumnMajor} or {@link multiplyByTransformMatrixRowMajor} instead.
1474
1453
  */
1475
1454
  function transformMatrix$1(vector, m) {
1476
- var x = vector.x, y = vector.y, z = vector.z;
1477
- var w = 1 / (m[3] * x + m[7] * y + m[11] * z + m[15]);
1455
+ return multiplyByTransformMatrixColumnMajor(vector, m);
1456
+ }
1457
+ /**
1458
+ * Returns a vector that is multiplied with a matrix in column-major form.
1459
+ * @param vector A Vector3 item.
1460
+ * @param m A Matrix4 item written in column-major form.
1461
+ */
1462
+ function multiplyByTransformMatrixColumnMajor(vector, m) {
1463
+ const { x, y, z } = vector;
1464
+ const w = 1 / (m[3] * x + m[7] * y + m[11] * z + m[15]);
1478
1465
  return {
1479
1466
  x: (m[0] * x + m[4] * y + m[8] * z + m[12]) * w,
1480
1467
  y: (m[1] * x + m[5] * y + m[9] * z + m[13]) * w,
1481
1468
  z: (m[2] * x + m[6] * y + m[10] * z + m[14]) * w,
1482
1469
  };
1483
1470
  }
1471
+ /**
1472
+ * Returns a vector that is multiplied with a matrix in row-major form.
1473
+ * @param vector A Vector3 item.
1474
+ * @param m A Matrix4 item written in row-major form.
1475
+ */
1476
+ function multiplyByTransformMatrixRowMajor(vector, m) {
1477
+ const { x, y, z } = vector;
1478
+ const w = 1 / (m[12] * x + m[13] * y + m[14] * z + m[15]);
1479
+ return {
1480
+ x: (m[0] * x + m[1] * y + m[2] * z + m[3]) * w,
1481
+ y: (m[4] * x + m[5] * y + m[6] * z + m[7]) * w,
1482
+ z: (m[8] * x + m[9] * y + m[10] * z + m[11]) * w,
1483
+ };
1484
+ }
1484
1485
  /**
1485
1486
  * Euclidean distance between two vectors
1486
1487
  */
@@ -1492,7 +1493,7 @@ function distance$1(a, b) {
1492
1493
  * distances, this is slightly more efficient than `distanceTo`.
1493
1494
  */
1494
1495
  function distanceSquared$1(a, b) {
1495
- var _a = subtract(a, b), dx = _a.x, dy = _a.y, dz = _a.z;
1496
+ const { x: dx, y: dy, z: dz } = subtract(a, b);
1496
1497
  return dx * dx + dy * dy + dz * dz;
1497
1498
  }
1498
1499
  /**
@@ -1544,7 +1545,7 @@ function lerp(a, b, t) {
1544
1545
  * @returns A point in world space coordinates.
1545
1546
  */
1546
1547
  function transformNdcToWorldSpace(ndc, worldMatrix, projectionMatrixInverse) {
1547
- return transformMatrix$1(transformMatrix$1(ndc, projectionMatrixInverse), worldMatrix);
1548
+ return multiplyByTransformMatrixColumnMajor(multiplyByTransformMatrixColumnMajor(ndc, projectionMatrixInverse), worldMatrix);
1548
1549
  }
1549
1550
 
1550
1551
  var vector3 = /*#__PURE__*/Object.freeze({
@@ -1566,6 +1567,7 @@ var vector3 = /*#__PURE__*/Object.freeze({
1566
1567
  fromMatrixScale: fromMatrixScale,
1567
1568
  isEqual: isEqual$2,
1568
1569
  isValid: isValid$1,
1570
+ isZeroVector: isZeroVector,
1569
1571
  left: left,
1570
1572
  lerp: lerp,
1571
1573
  magnitude: magnitude,
@@ -1573,6 +1575,8 @@ var vector3 = /*#__PURE__*/Object.freeze({
1573
1575
  max: max,
1574
1576
  min: min,
1575
1577
  multiply: multiply,
1578
+ multiplyByTransformMatrixColumnMajor: multiplyByTransformMatrixColumnMajor,
1579
+ multiplyByTransformMatrixRowMajor: multiplyByTransformMatrixRowMajor,
1576
1580
  negate: negate,
1577
1581
  normalize: normalize,
1578
1582
  origin: origin,
@@ -1590,42 +1594,38 @@ var vector3 = /*#__PURE__*/Object.freeze({
1590
1594
  /**
1591
1595
  * Returns a `BoundingBox` with the given min and max points.
1592
1596
  */
1593
- var create$9 = function (min, max) {
1594
- return { min: min, max: max };
1597
+ const create$9 = (min, max) => {
1598
+ return { min, max };
1595
1599
  };
1596
1600
  /**
1597
1601
  * Construct a minimal bounding box for a set of vectors, such that all vectors
1598
1602
  * are contained by the bounding box.
1599
1603
  */
1600
- var fromVectors = function (vectors) {
1601
- return union.apply(void 0, vectors.map(function (v) { return create$9(v, v); }));
1604
+ const fromVectors = (vectors) => {
1605
+ return union(...vectors.map((v) => create$9(v, v)));
1602
1606
  };
1603
1607
  /**
1604
1608
  * Returns the center point of the given `BoundingBox`.
1605
1609
  */
1606
- var center$3 = function (boundingBox) {
1610
+ const center$3 = (boundingBox) => {
1607
1611
  return scale$2(0.5, add(boundingBox.min, boundingBox.max));
1608
1612
  };
1609
1613
  /**
1610
1614
  * Returns the diagonal vector between the `min` and `max` vectors of the
1611
1615
  * given `BoundingBox`.
1612
1616
  */
1613
- var diagonal = function (boundingBox) {
1617
+ const diagonal = (boundingBox) => {
1614
1618
  return subtract(boundingBox.max, boundingBox.min);
1615
1619
  };
1616
1620
  /**
1617
1621
  * Returns a floating-point spatial error tolerance based on the extents of the box.
1618
1622
  */
1619
- var epsilon = function (boundingBox) {
1623
+ const epsilon = (boundingBox) => {
1620
1624
  return (Math.max(Math.max(magnitude(boundingBox.max), magnitude(boundingBox.min)), magnitude(diagonal(boundingBox))) * 1e-6);
1621
1625
  };
1622
- function union(box) {
1623
- var rest = [];
1624
- for (var _i = 1; _i < arguments.length; _i++) {
1625
- rest[_i - 1] = arguments[_i];
1626
- }
1627
- var boxes = __spreadArray([box], rest, true);
1628
- return boxes.reduce(function (a, b) {
1626
+ function union(box, ...rest) {
1627
+ const boxes = [box, ...rest];
1628
+ return boxes.reduce((a, b) => {
1629
1629
  return create$9(min(a.min, b.min), max(a.max, b.max));
1630
1630
  });
1631
1631
  }
@@ -1634,7 +1634,7 @@ function union(box) {
1634
1634
  * Returns the distance between the min and max for the provided
1635
1635
  * bounding box for each axis.
1636
1636
  */
1637
- var lengths = function (box) {
1637
+ const lengths = (box) => {
1638
1638
  return create$a(box.max.x - box.min.x, box.max.y - box.min.y, box.max.z - box.min.z);
1639
1639
  };
1640
1640
  /**
@@ -1642,8 +1642,8 @@ var lengths = function (box) {
1642
1642
  * component. A component is invalid if it contains a non-finite or NaN value.
1643
1643
  */
1644
1644
  function isValid(boundingBox) {
1645
- var maxIsValid = isValid$1(boundingBox.max);
1646
- var minIsValid = isValid$1(boundingBox.min);
1645
+ const maxIsValid = isValid$1(boundingBox.max);
1646
+ const minIsValid = isValid$1(boundingBox.min);
1647
1647
  return maxIsValid && minIsValid;
1648
1648
  }
1649
1649
 
@@ -1662,13 +1662,13 @@ var boundingBox = /*#__PURE__*/Object.freeze({
1662
1662
  /**
1663
1663
  * Returns a `BoundingSphere` that encompasses the provided `BoundingBox`.
1664
1664
  */
1665
- var create$8 = function (boundingBox$1) {
1666
- var boundingBoxCenter = center$3(boundingBox$1);
1667
- var centerToBoundingPlane = subtract(boundingBox$1.max, boundingBoxCenter);
1668
- var radius = magnitude(centerToBoundingPlane);
1669
- var length = Math.max(radius, magnitude(boundingBoxCenter));
1670
- var epsilon = length === 0 ? 1.0 : length * 1e-6;
1671
- return { center: boundingBoxCenter, radius: radius, epsilon: epsilon };
1665
+ const create$8 = (boundingBox$1) => {
1666
+ const boundingBoxCenter = center$3(boundingBox$1);
1667
+ const centerToBoundingPlane = subtract(boundingBox$1.max, boundingBoxCenter);
1668
+ const radius = magnitude(centerToBoundingPlane);
1669
+ const length = Math.max(radius, magnitude(boundingBoxCenter));
1670
+ const epsilon = length === 0 ? 1.0 : length * 1e-6;
1671
+ return { center: boundingBoxCenter, radius, epsilon };
1672
1672
  };
1673
1673
 
1674
1674
  var boundingSphere = /*#__PURE__*/Object.freeze({
@@ -1680,7 +1680,7 @@ var boundingSphere = /*#__PURE__*/Object.freeze({
1680
1680
  * Returns a new `Rectangle` with the given position and size.
1681
1681
  */
1682
1682
  function create$7(x, y, width, height) {
1683
- return { x: x, y: y, width: width, height: height };
1683
+ return { x, y, width, height };
1684
1684
  }
1685
1685
  /**
1686
1686
  * Returns a new `Rectangle` at the origin point and given size.
@@ -1699,10 +1699,10 @@ function fromPointAndDimensions(point, dimensions) {
1699
1699
  * The returned rectangle will always returns a positive width and height.
1700
1700
  */
1701
1701
  function fromPoints(topLeftPt, bottomRightPt) {
1702
- var minX = Math.min(topLeftPt.x, bottomRightPt.x);
1703
- var minY = Math.min(topLeftPt.y, bottomRightPt.y);
1704
- var maxX = Math.max(topLeftPt.x, bottomRightPt.x);
1705
- var maxY = Math.max(topLeftPt.y, bottomRightPt.y);
1702
+ const minX = Math.min(topLeftPt.x, bottomRightPt.x);
1703
+ const minY = Math.min(topLeftPt.y, bottomRightPt.y);
1704
+ const maxX = Math.max(topLeftPt.x, bottomRightPt.x);
1705
+ const maxY = Math.max(topLeftPt.y, bottomRightPt.y);
1706
1706
  return create$7(minX, minY, maxX - minX, maxY - minY);
1707
1707
  }
1708
1708
  /**
@@ -1714,9 +1714,9 @@ function fromPoints(topLeftPt, bottomRightPt) {
1714
1714
  * @see {@link cropFit}
1715
1715
  */
1716
1716
  function containFit$1(to, rect) {
1717
- var scale = Math.min(to.width / rect.width, to.height / rect.height);
1718
- var dimensions$1 = proportionalScale(scale, rect);
1719
- var position = subtract$1(center$2(to), center$1(dimensions$1));
1717
+ const scale = Math.min(to.width / rect.width, to.height / rect.height);
1718
+ const dimensions$1 = proportionalScale(scale, rect);
1719
+ const position = subtract$1(center$2(to), center$1(dimensions$1));
1720
1720
  return fromPointAndDimensions(position, dimensions$1);
1721
1721
  }
1722
1722
  /**
@@ -1728,9 +1728,9 @@ function containFit$1(to, rect) {
1728
1728
  * @see {@link containFit}
1729
1729
  */
1730
1730
  function cropFit$1(to, rect) {
1731
- var scale = Math.max(to.width / rect.width, to.height / rect.height);
1732
- var dimensions$1 = proportionalScale(scale, rect);
1733
- var position = subtract$1(center$2(to), center$1(dimensions$1));
1731
+ const scale = Math.max(to.width / rect.width, to.height / rect.height);
1732
+ const dimensions$1 = proportionalScale(scale, rect);
1733
+ const position = subtract$1(center$2(to), center$1(dimensions$1));
1734
1734
  return fromPointAndDimensions(position, dimensions$1);
1735
1735
  }
1736
1736
  /**
@@ -1742,9 +1742,9 @@ function cropFit$1(to, rect) {
1742
1742
  * @param rect - the rectangle to scale to fit the specified area
1743
1743
  */
1744
1744
  function scaleFit$1(to, rect) {
1745
- var scale = Math.min(Math.sqrt(to / area$1(rect)), 1);
1746
- var dimensions$1 = floor(proportionalScale(scale, rect));
1747
- var position = subtract$1(center$2(rect), center$1(dimensions$1));
1745
+ const scale = Math.min(Math.sqrt(to / area$1(rect)), 1);
1746
+ const dimensions$1 = floor(proportionalScale(scale, rect));
1747
+ const position = subtract$1(center$2(rect), center$1(dimensions$1));
1748
1748
  return fromPointAndDimensions(position, dimensions$1);
1749
1749
  }
1750
1750
  /**
@@ -1763,8 +1763,8 @@ function scale$1(rect, scaleOrScaleX, scaleY) {
1763
1763
  return scale$1(rect, scaleOrScaleX, scaleOrScaleX);
1764
1764
  }
1765
1765
  else {
1766
- var x = rect.x, y = rect.y, width = rect.width, height = rect.height;
1767
- var scaleX = scaleOrScaleX;
1766
+ const { x, y, width, height } = rect;
1767
+ const scaleX = scaleOrScaleX;
1768
1768
  return create$7(x * scaleX, y * scaleY, width * scaleX, height * scaleY);
1769
1769
  }
1770
1770
  }
@@ -1838,12 +1838,8 @@ function pad(rect, padding) {
1838
1838
  * @param rect The rectangle to check against.
1839
1839
  * @param points The points to check.
1840
1840
  */
1841
- function containsPoints(rect) {
1842
- var points = [];
1843
- for (var _i = 1; _i < arguments.length; _i++) {
1844
- points[_i - 1] = arguments[_i];
1845
- }
1846
- return points.every(function (point) {
1841
+ function containsPoints(rect, ...points) {
1842
+ return points.every((point) => {
1847
1843
  return (rect.x <= point.x &&
1848
1844
  rect.x + rect.width >= point.x &&
1849
1845
  rect.y <= point.y &&
@@ -1857,13 +1853,13 @@ function containsPoints(rect) {
1857
1853
  * @returns A parsed Point.
1858
1854
  */
1859
1855
  function fromJson$1(json) {
1860
- var obj = JSON.parse(json);
1856
+ const obj = JSON.parse(json);
1861
1857
  if (Array.isArray(obj)) {
1862
- var x = obj[0], y = obj[1], width = obj[2], height = obj[3];
1858
+ const [x, y, width, height] = obj;
1863
1859
  return create$7(x, y, width, height);
1864
1860
  }
1865
1861
  else {
1866
- var x = obj.x, y = obj.y, width = obj.width, height = obj.height;
1862
+ const { x, y, width, height } = obj;
1867
1863
  return create$7(x, y, width, height);
1868
1864
  }
1869
1865
  }
@@ -1896,27 +1892,27 @@ var rectangle = /*#__PURE__*/Object.freeze({
1896
1892
  * Returns a `Dimensions` with the given width and height.
1897
1893
  *
1898
1894
  */
1899
- var create$6 = function (width, height) {
1900
- return { width: width, height: height };
1895
+ const create$6 = (width, height) => {
1896
+ return { width, height };
1901
1897
  };
1902
1898
  /**
1903
1899
  * Returns a `Dimensions` with the same width and height.
1904
1900
  */
1905
- var square = function (size) {
1901
+ const square = (size) => {
1906
1902
  return create$6(size, size);
1907
1903
  };
1908
1904
  /**
1909
1905
  * Returns `true` if two dimensions have the same width and height. Otherwise
1910
1906
  * `false`.
1911
1907
  */
1912
- var isEqual = function (a, b) {
1908
+ const isEqual = (a, b) => {
1913
1909
  return a.width === b.width && a.height === b.height;
1914
1910
  };
1915
1911
  /**
1916
1912
  * Returns a scaled dimensions, where the width is scaled by `scaleX` and height
1917
1913
  * is scaled by `scaleY`.
1918
1914
  */
1919
- var scale = function (scaleX, scaleY, dimensions) {
1915
+ const scale = (scaleX, scaleY, dimensions) => {
1920
1916
  return {
1921
1917
  width: dimensions.width * scaleX,
1922
1918
  height: dimensions.height * scaleY,
@@ -1925,14 +1921,14 @@ var scale = function (scaleX, scaleY, dimensions) {
1925
1921
  /**
1926
1922
  * Returns a dimension where each length is scaled by `scaleFactor`.
1927
1923
  */
1928
- var proportionalScale = function (scaleFactor, dimensions) {
1924
+ const proportionalScale = (scaleFactor, dimensions) => {
1929
1925
  return scale(scaleFactor, scaleFactor, dimensions);
1930
1926
  };
1931
1927
  /**
1932
1928
  * Returns a `Dimensions` where the lengths of `dimensions` are trimmed to fit
1933
1929
  * into `to`.
1934
1930
  */
1935
- var trim = function (to, dimensions) {
1931
+ const trim = (to, dimensions) => {
1936
1932
  return {
1937
1933
  width: Math.min(to.width, dimensions.width),
1938
1934
  height: Math.min(to.height, dimensions.height),
@@ -1945,9 +1941,9 @@ var trim = function (to, dimensions) {
1945
1941
  *
1946
1942
  * @see #cropFit()
1947
1943
  */
1948
- var containFit = function (to, dimensions) {
1949
- var _a = containFit$1(toRectangle(to), toRectangle(dimensions)), width = _a.width, height = _a.height;
1950
- return { width: width, height: height };
1944
+ const containFit = (to, dimensions) => {
1945
+ const { width, height } = containFit$1(toRectangle(to), toRectangle(dimensions));
1946
+ return { width, height };
1951
1947
  };
1952
1948
  /**
1953
1949
  * Returns a `Dimensions` where the shortest length of `dimensions` will be
@@ -1956,9 +1952,9 @@ var containFit = function (to, dimensions) {
1956
1952
  *
1957
1953
  * @see #containFit()
1958
1954
  */
1959
- var cropFit = function (to, dimensions) {
1960
- var _a = cropFit$1(toRectangle(to), toRectangle(dimensions)), width = _a.width, height = _a.height;
1961
- return { width: width, height: height };
1955
+ const cropFit = (to, dimensions) => {
1956
+ const { width, height } = cropFit$1(toRectangle(to), toRectangle(dimensions));
1957
+ return { width, height };
1962
1958
  };
1963
1959
  /**
1964
1960
  * Returns a `Dimensions` where each side of `dimensions` will be reduced proportionally
@@ -1968,14 +1964,14 @@ var cropFit = function (to, dimensions) {
1968
1964
  * @param to - the maximum area this dimensions can have
1969
1965
  * @param dimensions - the dimensions to scale to fit the specified area
1970
1966
  */
1971
- var scaleFit = function (to, dimensions) {
1972
- var _a = scaleFit$1(to, toRectangle(dimensions)), width = _a.width, height = _a.height;
1973
- return { width: width, height: height };
1967
+ const scaleFit = (to, dimensions) => {
1968
+ const { width, height } = scaleFit$1(to, toRectangle(dimensions));
1969
+ return { width, height };
1974
1970
  };
1975
1971
  /**
1976
1972
  * Returns a `Dimensions` with each length rounded.
1977
1973
  */
1978
- var round = function (dimensions) {
1974
+ const round = (dimensions) => {
1979
1975
  return {
1980
1976
  width: Math.round(dimensions.width),
1981
1977
  height: Math.round(dimensions.height),
@@ -1984,7 +1980,7 @@ var round = function (dimensions) {
1984
1980
  /**
1985
1981
  * Returns a `Dimensions` with each length rounded down.
1986
1982
  */
1987
- var floor = function (dimensions) {
1983
+ const floor = (dimensions) => {
1988
1984
  return {
1989
1985
  width: Math.floor(dimensions.width),
1990
1986
  height: Math.floor(dimensions.height),
@@ -1993,22 +1989,20 @@ var floor = function (dimensions) {
1993
1989
  /**
1994
1990
  * Returns the center point of the given `dimensions`.
1995
1991
  */
1996
- var center$1 = function (dimensions) {
1992
+ const center$1 = (dimensions) => {
1997
1993
  return { x: dimensions.width / 2, y: dimensions.height / 2 };
1998
1994
  };
1999
1995
  /**
2000
1996
  * Returns the aspect ratio of the given `dimensions`, as defined by width over
2001
1997
  * height.
2002
1998
  */
2003
- var aspectRatio = function (_a) {
2004
- var width = _a.width, height = _a.height;
1999
+ const aspectRatio = ({ width, height }) => {
2005
2000
  return width / height;
2006
2001
  };
2007
2002
  /**
2008
2003
  * Returns the area of the given `dimensions`.
2009
2004
  */
2010
- var area = function (_a) {
2011
- var width = _a.width, height = _a.height;
2005
+ const area = ({ width, height }) => {
2012
2006
  return width * height;
2013
2007
  };
2014
2008
  /**
@@ -2017,7 +2011,7 @@ var area = function (_a) {
2017
2011
  * @param ratio - Aspect ratio to fit the provided Dimensions to
2018
2012
  * @param dimensions - Dimensions to fit to the specified ratio
2019
2013
  */
2020
- var fitToRatio = function (ratio, dimensions) {
2014
+ const fitToRatio = (ratio, dimensions) => {
2021
2015
  if (dimensions.width >= dimensions.height * ratio) {
2022
2016
  return create$6(dimensions.height * ratio, dimensions.height);
2023
2017
  }
@@ -2026,8 +2020,7 @@ var fitToRatio = function (ratio, dimensions) {
2026
2020
  /**
2027
2021
  * Converts a dimension to a rectangle, with an optional position.
2028
2022
  */
2029
- function toRectangle(dimensions, position) {
2030
- if (position === void 0) { position = create$d(); }
2023
+ function toRectangle(dimensions, position = create$d()) {
2031
2024
  return fromPointAndDimensions(position, dimensions);
2032
2025
  }
2033
2026
 
@@ -2057,9 +2050,8 @@ var dimensions = /*#__PURE__*/Object.freeze({
2057
2050
  *
2058
2051
  * @param values The values to assign to the line.
2059
2052
  */
2060
- function create$5(values) {
2053
+ function create$5(values = {}) {
2061
2054
  var _a, _b;
2062
- if (values === void 0) { values = {}; }
2063
2055
  return {
2064
2056
  start: (_a = values.start) !== null && _a !== void 0 ? _a : origin(),
2065
2057
  end: (_b = values.end) !== null && _b !== void 0 ? _b : origin(),
@@ -2080,9 +2072,9 @@ function center(line) {
2080
2072
  * @returns A transformed line.
2081
2073
  */
2082
2074
  function transformMatrix(line, matrix) {
2083
- var start = transformMatrix$1(line.start, matrix);
2084
- var end = transformMatrix$1(line.end, matrix);
2085
- return { start: start, end: end };
2075
+ const start = multiplyByTransformMatrixColumnMajor(line.start, matrix);
2076
+ const end = multiplyByTransformMatrixColumnMajor(line.end, matrix);
2077
+ return { start, end };
2086
2078
  }
2087
2079
  /**
2088
2080
  * Euclidean distance between the start and end points of the line.
@@ -2117,62 +2109,56 @@ var line3 = /*#__PURE__*/Object.freeze({
2117
2109
  /**
2118
2110
  * Creates a new matrix. If arguments are undefined, returns an identity matrix.
2119
2111
  */
2120
- var create$4 = function (a, b, c, d, tx, ty) {
2121
- if (a === void 0) { a = 1; }
2122
- if (b === void 0) { b = 0; }
2123
- if (c === void 0) { c = 0; }
2124
- if (d === void 0) { d = 1; }
2125
- if (tx === void 0) { tx = 0; }
2126
- if (ty === void 0) { ty = 0; }
2127
- return { a: a, b: b, c: c, d: d, tx: tx, ty: ty };
2112
+ const create$4 = (a = 1, b = 0, c = 0, d = 1, tx = 0, ty = 0) => {
2113
+ return { a, b, c, d, tx, ty };
2128
2114
  };
2129
2115
  /**
2130
2116
  * Returns an identity matrix.
2131
2117
  */
2132
- var identity = function () {
2118
+ const identity = () => {
2133
2119
  return create$4();
2134
2120
  };
2135
2121
  /**
2136
2122
  * Creates a matrix that is translated by the given `tx` and `ty` values.
2137
2123
  */
2138
- var translation = function (tx, ty) {
2124
+ const translation = (tx, ty) => {
2139
2125
  return translate(tx, ty, identity());
2140
2126
  };
2141
2127
  /**
2142
2128
  * Creates a matrix that is rotated by the given degrees.
2143
2129
  */
2144
- var rotation = function (degrees) {
2130
+ const rotation = (degrees) => {
2145
2131
  return rotate(degrees, identity());
2146
2132
  };
2147
2133
  /**
2148
2134
  * Rotates the given matrix by the given degrees.
2149
2135
  */
2150
- var rotate = function (degrees, matrix) {
2151
- var radians = toRadians(degrees);
2152
- var cos = Math.cos(radians);
2153
- var sin = Math.sin(radians);
2154
- var a = matrix.a * cos + matrix.c * sin;
2155
- var b = matrix.b * cos + matrix.d * sin;
2156
- var c = matrix.a * -sin + matrix.c * cos;
2157
- var d = matrix.b * -sin + matrix.d * cos;
2136
+ const rotate = (degrees, matrix) => {
2137
+ const radians = toRadians(degrees);
2138
+ const cos = Math.cos(radians);
2139
+ const sin = Math.sin(radians);
2140
+ const a = matrix.a * cos + matrix.c * sin;
2141
+ const b = matrix.b * cos + matrix.d * sin;
2142
+ const c = matrix.a * -sin + matrix.c * cos;
2143
+ const d = matrix.b * -sin + matrix.d * cos;
2158
2144
  return create$4(a, b, c, d, matrix.tx, matrix.ty);
2159
2145
  };
2160
2146
  /**
2161
2147
  * Translates the given matrix along the horizontal and vertical axis by the
2162
2148
  * given `dx` and `dy` delta values.
2163
2149
  */
2164
- var translate = function (dx, dy, matrix) {
2165
- var newTx = matrix.a * dx + matrix.c * dy + matrix.tx;
2166
- var newTy = matrix.b * dx + matrix.d * dy + matrix.ty;
2150
+ const translate = (dx, dy, matrix) => {
2151
+ const newTx = matrix.a * dx + matrix.c * dy + matrix.tx;
2152
+ const newTy = matrix.b * dx + matrix.d * dy + matrix.ty;
2167
2153
  return create$4(matrix.a, matrix.b, matrix.c, matrix.d, newTx, newTy);
2168
2154
  };
2169
2155
  /**
2170
2156
  * Returns the result of applying a geometric transformation of a matrix on the
2171
2157
  * given point.
2172
2158
  */
2173
- var transformPoint = function (matrix, pt) {
2174
- var x = matrix.a * pt.x + matrix.c * pt.y + matrix.tx;
2175
- var y = matrix.b * pt.x + matrix.d * pt.y + matrix.ty;
2159
+ const transformPoint = (matrix, pt) => {
2160
+ const x = matrix.a * pt.x + matrix.c * pt.y + matrix.tx;
2161
+ const y = matrix.b * pt.x + matrix.d * pt.y + matrix.ty;
2176
2162
  return create$d(x, y);
2177
2163
  };
2178
2164
 
@@ -2187,11 +2173,7 @@ var matrix = /*#__PURE__*/Object.freeze({
2187
2173
  translation: translation
2188
2174
  });
2189
2175
 
2190
- function create$3() {
2191
- var args = [];
2192
- for (var _i = 0; _i < arguments.length; _i++) {
2193
- args[_i] = arguments[_i];
2194
- }
2176
+ function create$3(...args) {
2195
2177
  if (args.length === 2) {
2196
2178
  return {
2197
2179
  a: args[0].x,
@@ -2241,9 +2223,8 @@ var matrix2 = /*#__PURE__*/Object.freeze({
2241
2223
  * @param values Values to assign to the plane.
2242
2224
  * @returns A new plane.
2243
2225
  */
2244
- function create$2(values) {
2245
- if (values === void 0) { values = {}; }
2246
- return __assign({ normal: origin(), constant: 0 }, values);
2226
+ function create$2(values = {}) {
2227
+ return { normal: origin(), constant: 0, ...values };
2247
2228
  }
2248
2229
  /**
2249
2230
  * Creates a plane from a normal and an arbitrary point on a plane.
@@ -2253,8 +2234,8 @@ function create$2(values) {
2253
2234
  * @returns A new plane.
2254
2235
  */
2255
2236
  function fromNormalAndCoplanarPoint(normal, point) {
2256
- var constant = -dot$1(point, normal);
2257
- return create$2({ normal: normal, constant: constant });
2237
+ const constant = -dot$1(point, normal);
2238
+ return create$2({ normal, constant });
2258
2239
  }
2259
2240
  /**
2260
2241
  * Returns the perpendicular distance from the plane to the given point.
@@ -2276,8 +2257,8 @@ function distanceToPoint(plane, point) {
2276
2257
  * @returns An intersecting point on the plane and line.
2277
2258
  */
2278
2259
  function intersectLine(plane, line) {
2279
- var direction$1 = direction(line);
2280
- var denominator = dot$1(plane.normal, direction$1);
2260
+ const direction$1 = direction(line);
2261
+ const denominator = dot$1(plane.normal, direction$1);
2281
2262
  if (denominator === 0) {
2282
2263
  if (distanceToPoint(plane, line.start) === 0) {
2283
2264
  return line.start;
@@ -2286,7 +2267,7 @@ function intersectLine(plane, line) {
2286
2267
  return undefined;
2287
2268
  }
2288
2269
  }
2289
- var t = -(dot$1(line.start, plane.normal) + plane.constant) / denominator;
2270
+ const t = -(dot$1(line.start, plane.normal) + plane.constant) / denominator;
2290
2271
  if (t < 0 || t > 1) {
2291
2272
  return undefined;
2292
2273
  }
@@ -2302,7 +2283,7 @@ function intersectLine(plane, line) {
2302
2283
  * @returns The projected point.
2303
2284
  */
2304
2285
  function projectPoint(plane, point) {
2305
- var d = distanceToPoint(plane, point);
2286
+ const d = distanceToPoint(plane, point);
2306
2287
  return add(point, scale$2(-d, plane.normal));
2307
2288
  }
2308
2289
 
@@ -2322,9 +2303,8 @@ var plane = /*#__PURE__*/Object.freeze({
2322
2303
  * @param value The values of the ray.
2323
2304
  * @returns A new ray.
2324
2305
  */
2325
- function create$1(value) {
2306
+ function create$1(value = {}) {
2326
2307
  var _a, _b;
2327
- if (value === void 0) { value = {}; }
2328
2308
  return {
2329
2309
  origin: (_a = value.origin) !== null && _a !== void 0 ? _a : origin(),
2330
2310
  direction: (_b = value.direction) !== null && _b !== void 0 ? _b : forward(),
@@ -2350,13 +2330,13 @@ function at(ray, distance) {
2350
2330
  * @returns The distance to the plane, or `undefined` if it cannot be computed.
2351
2331
  */
2352
2332
  function distanceToPlane(ray, plane$1) {
2353
- var d = dot$1(plane$1.normal, ray.direction);
2333
+ const d = dot$1(plane$1.normal, ray.direction);
2354
2334
  if (d === 0) {
2355
2335
  // Ray is on plane.
2356
2336
  return distanceToPoint(plane$1, ray.origin) === 0 ? 0 : undefined;
2357
2337
  }
2358
2338
  else {
2359
- var t = -(dot$1(ray.origin, plane$1.normal) + plane$1.constant) / d;
2339
+ const t = -(dot$1(ray.origin, plane$1.normal) + plane$1.constant) / d;
2360
2340
  // Checks if ray intersects plane.
2361
2341
  return t >= 0 ? t : undefined;
2362
2342
  }
@@ -2371,7 +2351,7 @@ function distanceToPlane(ray, plane$1) {
2371
2351
  * intersect.
2372
2352
  */
2373
2353
  function intersectPlane(ray, plane) {
2374
- var t = distanceToPlane(ray, plane);
2354
+ const t = distanceToPlane(ray, plane);
2375
2355
  return t != null ? at(ray, t) : undefined;
2376
2356
  }
2377
2357
 
@@ -2387,9 +2367,8 @@ var ray = /*#__PURE__*/Object.freeze({
2387
2367
  * Returns a new Vector4. If `value` is undefined, then `{x: 0, y: 0, z: 0,
2388
2368
  * w: 0}` is returned.
2389
2369
  */
2390
- function create(value) {
2391
- if (value === void 0) { value = {}; }
2392
- return __assign({ x: 0, y: 0, z: 0, w: 0 }, value);
2370
+ function create(value = {}) {
2371
+ return { x: 0, y: 0, z: 0, w: 0, ...value };
2393
2372
  }
2394
2373
  /**
2395
2374
  * Parses a JSON string representation of a `Vector4`.
@@ -2398,10 +2377,10 @@ function create(value) {
2398
2377
  * @returns A parsed `Vector4`.
2399
2378
  */
2400
2379
  function fromJson(json) {
2401
- var obj = JSON.parse(json);
2380
+ const obj = JSON.parse(json);
2402
2381
  if (Array.isArray(obj)) {
2403
- var x = obj[0], y = obj[1], z = obj[2], w = obj[3];
2404
- return create({ x: x, y: y, z: z, w: w });
2382
+ const [x, y, z, w] = obj;
2383
+ return create({ x, y, z, w });
2405
2384
  }
2406
2385
  else {
2407
2386
  return create(obj);