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