@vertexvis/geometry 1.0.2-canary.8 → 1.0.2-canary.9

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.cjs CHANGED
@@ -259,10 +259,10 @@ function fromValues(
259
259
  m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
260
260
  /* eslint-disable prettier/prettier */
261
261
  return [
262
- m11, m21, m31, m41,
263
- m12, m22, m32, m42,
264
- m13, m23, m33, m43,
265
- m14, m24, m34, m44,
262
+ m11, m12, m13, m14,
263
+ m21, m22, m23, m24,
264
+ m31, m32, m33, m34,
265
+ m41, m42, m43, m44,
266
266
  ];
267
267
  /* eslint-enable prettier/prettier */
268
268
  }
@@ -332,9 +332,9 @@ function makeRotation(rotation) {
332
332
  var wx = w * x2, wy = w * y2, wz = w * z2;
333
333
  /* eslint-disable prettier/prettier */
334
334
  return [
335
- 1 - (yy + zz), xy + wz, xz - wy, 0,
336
- xy - wz, 1 - (xx + zz), yz + wx, 0,
337
- xz + wy, yz - wx, 1 - (xx + yy), 0,
335
+ 1 - (yy + zz), xy - wz, xz + wy, 0,
336
+ xy + wz, 1 - (xx + zz), yz - wx, 0,
337
+ xz - wy, yz + wx, 1 - (xx + yy), 0,
338
338
  0, 0, 0, 1
339
339
  ];
340
340
  /* eslint-enable prettier/prettier */
@@ -364,33 +364,33 @@ function makeScale(scale) {
364
364
  /* eslint-enable prettier/prettier */
365
365
  }
366
366
  /**
367
- * Creates a matrix that has translation, rotation and scale applied to it.
367
+ * Creates a matrix that has translation, rotation, and scale applied to it.
368
368
  *
369
369
  * @param translation The translation applied to the matrix.
370
370
  * @param rotation The rotation applied to the matrix.
371
371
  * @param scale The scale applied to the matrix.
372
- * @returns A transformed matrix.
372
+ * @returns A transformed matrix in column-major form.
373
373
  */
374
374
  function makeTRS(translation, rotation, scale) {
375
375
  var t = makeTranslation(translation);
376
- var r = makeRotation(rotation);
376
+ var r = transpose(makeRotation(rotation));
377
377
  var s = makeScale(scale);
378
- return multiply$2(multiply$2(t, r), s);
378
+ return multiply$2(s, multiply$2(r, t));
379
379
  }
380
380
  /**
381
381
  * Returns a matrix that has the basis components (upper left 3x3 matrix) set to
382
382
  * the following x, y, and z axis.
383
383
  *
384
384
  * ```
385
- * x.x y.x z.x 0
386
- * x.y y.y z.y 0
387
- * x.z y.z z.z 0
385
+ * x.x x.y x.z 0
386
+ * y.x y.y y.z 0
387
+ * z.x z.y z.z 0
388
388
  * 0 0 0 0
389
389
  * ```
390
390
  *
391
- * @param x The x axis to set.
392
- * @param y The y axis to set.
393
- * @param z The z axis to set.
391
+ * @param x The x-axis to set.
392
+ * @param y The y-axis to set.
393
+ * @param z The z-axis to set.
394
394
  * @returns A matrix with its basis components populated.
395
395
  */
396
396
  function makeBasis(x, y, z) {
@@ -403,30 +403,6 @@ function makeBasis(x, y, z) {
403
403
  ];
404
404
  /* eslint-enable prettier/prettier */
405
405
  }
406
- /**
407
- * Creates a rotation matrix that is rotated around a given axis by the given
408
- * angle.
409
- *
410
- * @param axis The axis of rotation.
411
- * @param radians The angle of rotation.
412
- * @returns A rotation matrix.
413
- */
414
- function makeRotationAxis(axis, radians) {
415
- var c = Math.cos(radians);
416
- var s = Math.sin(radians);
417
- var t = 1 - c;
418
- var x = axis.x, y = axis.y, z = axis.z;
419
- var tx = t * x;
420
- var ty = t * y;
421
- /* eslint-disable prettier/prettier */
422
- return [
423
- tx * x + c, tx * y + s * z, tx * z - s * y, 0,
424
- tx * y - s * z, ty * y + c, ty * z + s * x, 0,
425
- tx * z + s * y, ty * z - s * x, t * z * z + c, 0,
426
- 0, 0, 0, 1
427
- ];
428
- /* eslint-enable prettier/prettier */
429
- }
430
406
  /**
431
407
  * Creates a matrix used for [perspective
432
408
  * projections](https://en.wikipedia.org/wiki/3D_projection#Perspective_projection).
@@ -608,24 +584,24 @@ function invert(matrix) {
608
584
  if (!det) {
609
585
  return makeZero();
610
586
  }
611
- det = 1.0 / det;
587
+ var oneOverDet = 1 / det;
612
588
  return [
613
- (a11 * b11 - a12 * b10 + a13 * b09) * det,
614
- (a02 * b10 - a01 * b11 - a03 * b09) * det,
615
- (a31 * b05 - a32 * b04 + a33 * b03) * det,
616
- (a22 * b04 - a21 * b05 - a23 * b03) * det,
617
- (a12 * b08 - a10 * b11 - a13 * b07) * det,
618
- (a00 * b11 - a02 * b08 + a03 * b07) * det,
619
- (a32 * b02 - a30 * b05 - a33 * b01) * det,
620
- (a20 * b05 - a22 * b02 + a23 * b01) * det,
621
- (a10 * b10 - a11 * b08 + a13 * b06) * det,
622
- (a01 * b08 - a00 * b10 - a03 * b06) * det,
623
- (a30 * b04 - a31 * b02 + a33 * b00) * det,
624
- (a21 * b02 - a20 * b04 - a23 * b00) * det,
625
- (a11 * b07 - a10 * b09 - a12 * b06) * det,
626
- (a00 * b09 - a01 * b07 + a02 * b06) * det,
627
- (a31 * b01 - a30 * b03 - a32 * b00) * det,
628
- (a20 * b03 - a21 * b01 + a22 * b00) * det,
589
+ (a11 * b11 - a12 * b10 + a13 * b09) * oneOverDet,
590
+ (a02 * b10 - a01 * b11 - a03 * b09) * oneOverDet,
591
+ (a31 * b05 - a32 * b04 + a33 * b03) * oneOverDet,
592
+ (a22 * b04 - a21 * b05 - a23 * b03) * oneOverDet,
593
+ (a12 * b08 - a10 * b11 - a13 * b07) * oneOverDet,
594
+ (a00 * b11 - a02 * b08 + a03 * b07) * oneOverDet,
595
+ (a32 * b02 - a30 * b05 - a33 * b01) * oneOverDet,
596
+ (a20 * b05 - a22 * b02 + a23 * b01) * oneOverDet,
597
+ (a10 * b10 - a11 * b08 + a13 * b06) * oneOverDet,
598
+ (a01 * b08 - a00 * b10 - a03 * b06) * oneOverDet,
599
+ (a30 * b04 - a31 * b02 + a33 * b00) * oneOverDet,
600
+ (a21 * b02 - a20 * b04 - a23 * b00) * oneOverDet,
601
+ (a11 * b07 - a10 * b09 - a12 * b06) * oneOverDet,
602
+ (a00 * b09 - a01 * b07 + a02 * b06) * oneOverDet,
603
+ (a31 * b01 - a30 * b03 - a32 * b00) * oneOverDet,
604
+ (a20 * b03 - a21 * b01 + a22 * b00) * oneOverDet,
629
605
  ];
630
606
  }
631
607
  /**
@@ -660,49 +636,37 @@ function lookAt(m, position, target, up) {
660
636
  var res = tslib.__spreadArray([], m, true);
661
637
  /* eslint-disable prettier/prettier */
662
638
  res[0] = x.x;
663
- res[4] = y.x;
664
- res[8] = z.x;
665
639
  res[1] = x.y;
666
- res[5] = y.y;
667
- res[9] = z.y;
668
640
  res[2] = x.z;
641
+ res[4] = y.x;
642
+ res[5] = y.y;
669
643
  res[6] = y.z;
644
+ res[8] = z.x;
645
+ res[9] = z.y;
670
646
  res[10] = z.z;
671
647
  /* eslint-enable prettier/prettier */
672
648
  return res;
673
649
  }
674
650
  /**
675
- * Returns a post-multiplied matrix.
651
+ * Returns a post-multiplied matrix equal to ab.
676
652
  */
677
653
  function multiply$2(a, b) {
678
- var ae = a;
679
- var be = b;
680
- var a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
681
- var a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
682
- var a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
683
- var a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
684
- var b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
685
- var b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
686
- var b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
687
- var b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
688
- var mat = makeIdentity();
689
- mat[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
690
- mat[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
691
- mat[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
692
- mat[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
693
- mat[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
694
- mat[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
695
- mat[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
696
- mat[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
697
- mat[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
698
- mat[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
699
- mat[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
700
- mat[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
701
- mat[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
702
- mat[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
703
- mat[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
704
- mat[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
705
- return mat;
654
+ var result = makeIdentity();
655
+ // Consider each row i in the final matrix
656
+ for (var i = 0; i < 4; i++) {
657
+ // Consider each column j in the final matrix
658
+ for (var j = 0; j < 4; j++) {
659
+ // Calculate the value at row i and column j
660
+ var value = 0;
661
+ for (var k = 0; k < 4; k++) {
662
+ // Calculate (ik + kj) and add it to the value
663
+ value += a[i * 4 + k] * b[k * 4 + j];
664
+ }
665
+ var positionInResultingMatrix = 4 * i + j;
666
+ result[positionInResultingMatrix] = value;
667
+ }
668
+ }
669
+ return result;
706
670
  }
707
671
  /**
708
672
  * Returns the [transpose](https://en.wikipedia.org/wiki/Transpose) of the given
@@ -719,32 +683,37 @@ function transpose(matrix) {
719
683
  /* eslint-enable prettier/prettier */
720
684
  }
721
685
  /**
722
- * Multiplies the columns of a matrix by the given vector.
686
+ * Multiplies the columns of a row-major matrix by the given vector.
723
687
  */
724
688
  function scale$4(matrix, scale) {
725
689
  var x = scale.x, y = scale.y, z = scale.z;
726
690
  var m = tslib.__spreadArray([], matrix, true);
727
691
  /* eslint-disable prettier/prettier */
728
692
  m[0] *= x;
729
- m[4] *= y;
730
- m[8] *= z;
731
693
  m[1] *= x;
732
- m[5] *= y;
733
- m[9] *= z;
734
694
  m[2] *= x;
735
- m[6] *= y;
736
- m[10] *= z;
737
695
  m[3] *= x;
696
+ m[4] *= y;
697
+ m[5] *= y;
698
+ m[6] *= y;
738
699
  m[7] *= y;
700
+ m[8] *= z;
701
+ m[9] *= z;
702
+ m[10] *= z;
739
703
  m[11] *= z;
740
704
  /* eslint-enable prettier/prettier */
741
705
  return m;
742
706
  }
743
- function position(matrix, other) {
744
- var m = tslib.__spreadArray([], matrix, true);
745
- m[12] = other[12];
746
- m[13] = other[13];
747
- m[14] = other[14];
707
+ /**
708
+ * Sets the position of the matrix given as the first parameter
709
+ * to the position of the matrix given as the second parameter.
710
+ * Both matrices should have row-major format.
711
+ */
712
+ function position(originalMatrix, matrixWithDesiredPosition) {
713
+ var m = tslib.__spreadArray([], originalMatrix, true);
714
+ m[12] = matrixWithDesiredPosition[12];
715
+ m[13] = matrixWithDesiredPosition[13];
716
+ m[14] = matrixWithDesiredPosition[14];
748
717
  return m;
749
718
  }
750
719
  /**
@@ -756,8 +725,18 @@ function isIdentity(matrix) {
756
725
  }
757
726
  /**
758
727
  * Returns an object representation of a `Matrix4`.
728
+ * @param m A Matrix4 item written in column-major form.
729
+ *
730
+ * @deprecated Use {@link toObjectColumnMajor} or {@link toObjectRowMajor} instead.
759
731
  */
760
732
  function toObject(m) {
733
+ return toObjectColumnMajor(m);
734
+ }
735
+ /**
736
+ * Returns an object representation of a `Matrix4`.
737
+ * @param m A Matrix4 item written in column-major form.
738
+ */
739
+ function toObjectColumnMajor(m) {
761
740
  /* eslint-disable prettier/prettier */
762
741
  return {
763
742
  m11: m[0], m12: m[4], m13: m[8], m14: m[12],
@@ -767,6 +746,20 @@ function toObject(m) {
767
746
  };
768
747
  /* eslint-enable prettier/prettier */
769
748
  }
749
+ /**
750
+ * Returns an object representation of a `Matrix4`.
751
+ * @param m A Matrix4 item written in row-major form.
752
+ */
753
+ function toObjectRowMajor(m) {
754
+ /* eslint-disable prettier/prettier */
755
+ return {
756
+ m11: m[0], m12: m[1], m13: m[2], m14: m[3],
757
+ m21: m[4], m22: m[5], m23: m[6], m24: m[7],
758
+ m31: m[8], m32: m[9], m33: m[10], m34: m[11],
759
+ m41: m[12], m42: m[13], m43: m[14], m44: m[15],
760
+ };
761
+ /* eslint-enable prettier/prettier */
762
+ }
770
763
  /**
771
764
  * A type guard to check if `obj` is of type `Matrix4`.
772
765
  */
@@ -790,7 +783,6 @@ var matrix4 = /*#__PURE__*/Object.freeze({
790
783
  makeOrthographic: makeOrthographic,
791
784
  makePerspective: makePerspective,
792
785
  makeRotation: makeRotation,
793
- makeRotationAxis: makeRotationAxis,
794
786
  makeScale: makeScale,
795
787
  makeTRS: makeTRS,
796
788
  makeTranslation: makeTranslation,
@@ -799,6 +791,8 @@ var matrix4 = /*#__PURE__*/Object.freeze({
799
791
  position: position,
800
792
  scale: scale$4,
801
793
  toObject: toObject,
794
+ toObjectColumnMajor: toObjectColumnMajor,
795
+ toObjectRowMajor: toObjectRowMajor,
802
796
  transpose: transpose
803
797
  });
804
798
 
@@ -849,9 +843,12 @@ function fromDegrees(value) {
849
843
  * @param matrix A pure rotation matrix, unscaled.
850
844
  * @param order The order that the rotations are applied.
851
845
  */
852
- function fromRotationMatrix(matrix, order) {
846
+ function fromRotationMatrix(matrix, order, matrixIsColumnMajor) {
853
847
  if (order === void 0) { order = 'xyz'; }
854
- var m = toObject(matrix);
848
+ if (matrixIsColumnMajor === void 0) { matrixIsColumnMajor = true; }
849
+ var m = matrixIsColumnMajor
850
+ ? toObjectColumnMajor(matrix)
851
+ : toObjectRowMajor(matrix);
855
852
  var x = 0, y = 0, z = 0;
856
853
  if (order === 'xyz') {
857
854
  y = Math.asin(clamp(m.m13, -1, 1));
@@ -1030,55 +1027,47 @@ function fromAxisAngle(axis, radians) {
1030
1027
  * (unscaled).
1031
1028
  */
1032
1029
  function fromMatrixRotation(matrix) {
1033
- var m = toObject(matrix);
1030
+ // Determine the scalars for each vector
1034
1031
  var scale = fromMatrixScale(matrix);
1035
- var is1 = 1 / scale.x;
1036
- var is2 = 1 / scale.y;
1037
- var is3 = 1 / scale.z;
1038
- var sm11 = m.m11 * is1;
1039
- var sm12 = m.m21 * is2;
1040
- var sm13 = m.m31 * is3;
1041
- var sm21 = m.m12 * is1;
1042
- var sm22 = m.m22 * is2;
1043
- var sm23 = m.m32 * is3;
1044
- var sm31 = m.m13 * is1;
1045
- var sm32 = m.m23 * is2;
1046
- var sm33 = m.m33 * is3;
1047
- var trace = sm11 + sm22 + sm33;
1032
+ var oneOverScaleVector = create$a(1 / scale.x, 1 / scale.y, 1 / scale.z);
1033
+ // Scale the matrix
1034
+ var scaledMatrix = scale$4(matrix, oneOverScaleVector);
1035
+ var sM = toObjectRowMajor(scaledMatrix);
1036
+ var trace = sM.m11 + sM.m22 + sM.m33;
1048
1037
  if (trace > 0) {
1049
- var s = Math.sqrt(trace + 1.0) * 2;
1038
+ var s = Math.sqrt(trace + 1) * 2;
1050
1039
  return {
1051
- x: (sm23 - sm32) / s,
1052
- y: (sm31 - sm13) / s,
1053
- z: (sm12 - sm21) / s,
1040
+ x: (sM.m23 - sM.m32) / s,
1041
+ y: (sM.m31 - sM.m13) / s,
1042
+ z: (sM.m12 - sM.m21) / s,
1054
1043
  w: 0.25 * s,
1055
1044
  };
1056
1045
  }
1057
- else if (sm11 > sm22 && sm11 > sm33) {
1058
- var s = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
1046
+ else if (sM.m11 > sM.m22 && sM.m11 > sM.m33) {
1047
+ var s = Math.sqrt(1 + sM.m11 - sM.m22 - sM.m33) * 2;
1059
1048
  return {
1060
1049
  x: 0.25 * s,
1061
- y: (sm12 + sm21) / s,
1062
- z: (sm31 + sm13) / s,
1063
- w: (sm23 - sm32) / s,
1050
+ y: (sM.m12 + sM.m21) / s,
1051
+ z: (sM.m31 + sM.m13) / s,
1052
+ w: (sM.m23 - sM.m32) / s,
1064
1053
  };
1065
1054
  }
1066
- else if (sm22 > sm33) {
1067
- var s = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
1055
+ else if (sM.m22 > sM.m33) {
1056
+ var s = Math.sqrt(1 + sM.m22 - sM.m11 - sM.m33) * 2;
1068
1057
  return {
1069
- x: (sm12 + sm21) / s,
1058
+ x: (sM.m12 + sM.m21) / s,
1070
1059
  y: 0.25 * s,
1071
- z: (sm23 + sm32) / s,
1072
- w: (sm31 - sm13) / s,
1060
+ z: (sM.m23 + sM.m32) / s,
1061
+ w: (sM.m31 - sM.m13) / s,
1073
1062
  };
1074
1063
  }
1075
1064
  else {
1076
- var s = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
1065
+ var s = Math.sqrt(1 + sM.m33 - sM.m11 - sM.m22) * 2;
1077
1066
  return {
1078
- x: (sm31 + sm13) / s,
1079
- y: (sm23 + sm32) / s,
1067
+ x: (sM.m31 + sM.m13) / s,
1068
+ y: (sM.m23 + sM.m32) / s,
1080
1069
  z: 0.25 * s,
1081
- w: (sm12 - sm21) / s,
1070
+ w: (sM.m12 - sM.m21) / s,
1082
1071
  };
1083
1072
  }
1084
1073
  }
@@ -1210,19 +1199,19 @@ function isValid$1(_a) {
1210
1199
  * Returns a vector representing the scale elements of `matrix`.
1211
1200
  */
1212
1201
  function fromMatrixScale(matrix) {
1213
- var m = toObject(matrix);
1202
+ var m = toObjectRowMajor(matrix);
1214
1203
  return {
1215
- x: Math.hypot(m.m11, m.m21, m.m31),
1216
- y: Math.hypot(m.m12, m.m22, m.m32),
1217
- z: Math.hypot(m.m13, m.m23, m.m33),
1204
+ x: Math.hypot(m.m11, m.m12, m.m13),
1205
+ y: Math.hypot(m.m21, m.m22, m.m23),
1206
+ z: Math.hypot(m.m31, m.m32, m.m33),
1218
1207
  };
1219
1208
  }
1220
1209
  /**
1221
1210
  * Returns a vector representing the position elements of `matrix`.
1222
1211
  */
1223
1212
  function fromMatrixPosition(matrix) {
1224
- var m = toObject(matrix);
1225
- return { x: m.m14, y: m.m24, z: m.m34 };
1213
+ var m = toObjectRowMajor(matrix);
1214
+ return { x: m.m41, y: m.m42, z: m.m43 };
1226
1215
  }
1227
1216
  /**
1228
1217
  * Parses a JSON string representation of a Vector3 and returns an object.
@@ -1420,7 +1409,7 @@ function eulerTo(a, b) {
1420
1409
  return dotAB > 1 - 1e-6 ? create$c() : create$c({ x: Math.PI });
1421
1410
  }
1422
1411
  var normalizedQ = normalize$1(create$b(tslib.__assign({ w: 1 + dotAB }, cross(normalizedA, normalizedB))));
1423
- return fromRotationMatrix(makeRotation(normalizedQ));
1412
+ return fromRotationMatrix(makeRotation(normalizedQ), 'xyz', false);
1424
1413
  }
1425
1414
  /**
1426
1415
  * Performs a projection of a `vector` onto `onNormal`.
@@ -1472,9 +1461,21 @@ function rotateAboutAxis(angle, point, axisDirection, axisPosition) {
1472
1461
  }
1473
1462
  }
1474
1463
  /**
1475
- * Returns a vector that is multiplied with a matrix.
1464
+ * Returns a vector that is multiplied with a matrix in column-major form.
1465
+ * @param vector A Vector3 item.
1466
+ * @param m A Matrix4 item written in column-major form.
1467
+ *
1468
+ * @deprecated Use {@link multiplyByTransformMatrixColumnMajor} or {@link multiplyByTransformMatrixRowMajor} instead.
1476
1469
  */
1477
1470
  function transformMatrix$1(vector, m) {
1471
+ return multiplyByTransformMatrixColumnMajor(vector, m);
1472
+ }
1473
+ /**
1474
+ * Returns a vector that is multiplied with a matrix in column-major form.
1475
+ * @param vector A Vector3 item.
1476
+ * @param m A Matrix4 item written in column-major form.
1477
+ */
1478
+ function multiplyByTransformMatrixColumnMajor(vector, m) {
1478
1479
  var x = vector.x, y = vector.y, z = vector.z;
1479
1480
  var w = 1 / (m[3] * x + m[7] * y + m[11] * z + m[15]);
1480
1481
  return {
@@ -1483,6 +1484,20 @@ function transformMatrix$1(vector, m) {
1483
1484
  z: (m[2] * x + m[6] * y + m[10] * z + m[14]) * w,
1484
1485
  };
1485
1486
  }
1487
+ /**
1488
+ * Returns a vector that is multiplied with a matrix in row-major form.
1489
+ * @param vector A Vector3 item.
1490
+ * @param m A Matrix4 item written in row-major form.
1491
+ */
1492
+ function multiplyByTransformMatrixRowMajor(vector, m) {
1493
+ var x = vector.x, y = vector.y, z = vector.z;
1494
+ var w = 1 / (m[12] * x + m[13] * y + m[14] * z + m[15]);
1495
+ return {
1496
+ x: (m[0] * x + m[1] * y + m[2] * z + m[3]) * w,
1497
+ y: (m[4] * x + m[5] * y + m[6] * z + m[7]) * w,
1498
+ z: (m[8] * x + m[9] * y + m[10] * z + m[11]) * w,
1499
+ };
1500
+ }
1486
1501
  /**
1487
1502
  * Euclidean distance between two vectors
1488
1503
  */
@@ -1546,7 +1561,7 @@ function lerp(a, b, t) {
1546
1561
  * @returns A point in world space coordinates.
1547
1562
  */
1548
1563
  function transformNdcToWorldSpace(ndc, worldMatrix, projectionMatrixInverse) {
1549
- return transformMatrix$1(transformMatrix$1(ndc, projectionMatrixInverse), worldMatrix);
1564
+ return multiplyByTransformMatrixColumnMajor(multiplyByTransformMatrixColumnMajor(ndc, projectionMatrixInverse), worldMatrix);
1550
1565
  }
1551
1566
 
1552
1567
  var vector3 = /*#__PURE__*/Object.freeze({
@@ -1575,6 +1590,8 @@ var vector3 = /*#__PURE__*/Object.freeze({
1575
1590
  max: max,
1576
1591
  min: min,
1577
1592
  multiply: multiply,
1593
+ multiplyByTransformMatrixColumnMajor: multiplyByTransformMatrixColumnMajor,
1594
+ multiplyByTransformMatrixRowMajor: multiplyByTransformMatrixRowMajor,
1578
1595
  negate: negate,
1579
1596
  normalize: normalize,
1580
1597
  origin: origin,
@@ -2082,8 +2099,8 @@ function center(line) {
2082
2099
  * @returns A transformed line.
2083
2100
  */
2084
2101
  function transformMatrix(line, matrix) {
2085
- var start = transformMatrix$1(line.start, matrix);
2086
- var end = transformMatrix$1(line.end, matrix);
2102
+ var start = multiplyByTransformMatrixColumnMajor(line.start, matrix);
2103
+ var end = multiplyByTransformMatrixColumnMajor(line.end, matrix);
2087
2104
  return { start: start, end: end };
2088
2105
  }
2089
2106
  /**