@lakuna/umath 1.5.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/LICENSE +1 -1
  2. package/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -1
  3. package/dist/algorithms/greatestCommonDivisor.js +14 -4
  4. package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
  5. package/dist/index.d.ts +15 -11
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +6 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/linalg/DualQuaternion.d.ts +131 -154
  10. package/dist/linalg/DualQuaternion.d.ts.map +1 -1
  11. package/dist/linalg/DualQuaternion.js +188 -203
  12. package/dist/linalg/DualQuaternion.js.map +1 -1
  13. package/dist/linalg/Matrix.d.ts +24 -24
  14. package/dist/linalg/Matrix.d.ts.map +1 -1
  15. package/dist/linalg/Matrix2.d.ts +74 -88
  16. package/dist/linalg/Matrix2.d.ts.map +1 -1
  17. package/dist/linalg/Matrix2.js +114 -124
  18. package/dist/linalg/Matrix2.js.map +1 -1
  19. package/dist/linalg/Matrix3.d.ts +118 -139
  20. package/dist/linalg/Matrix3.d.ts.map +1 -1
  21. package/dist/linalg/Matrix3.js +169 -201
  22. package/dist/linalg/Matrix3.js.map +1 -1
  23. package/dist/linalg/Matrix4.d.ts +217 -257
  24. package/dist/linalg/Matrix4.d.ts.map +1 -1
  25. package/dist/linalg/Matrix4.js +310 -374
  26. package/dist/linalg/Matrix4.js.map +1 -1
  27. package/dist/linalg/Quaternion.d.ts +120 -151
  28. package/dist/linalg/Quaternion.d.ts.map +1 -1
  29. package/dist/linalg/Quaternion.js +187 -204
  30. package/dist/linalg/Quaternion.js.map +1 -1
  31. package/dist/linalg/SlowMatrix.d.ts +5 -5
  32. package/dist/linalg/SlowMatrix.d.ts.map +1 -1
  33. package/dist/linalg/SlowMatrix.js +63 -89
  34. package/dist/linalg/SlowMatrix.js.map +1 -1
  35. package/dist/linalg/SlowSquareMatrix.d.ts +6 -6
  36. package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
  37. package/dist/linalg/SlowSquareMatrix.js +15 -15
  38. package/dist/linalg/SlowSquareMatrix.js.map +1 -1
  39. package/dist/linalg/SlowVector.d.ts +165 -0
  40. package/dist/linalg/SlowVector.d.ts.map +1 -0
  41. package/dist/linalg/SlowVector.js +369 -0
  42. package/dist/linalg/SlowVector.js.map +1 -0
  43. package/dist/linalg/SquareMatrix.d.ts +8 -8
  44. package/dist/linalg/SquareMatrix.d.ts.map +1 -1
  45. package/dist/linalg/Vector.d.ts +84 -84
  46. package/dist/linalg/Vector.d.ts.map +1 -1
  47. package/dist/linalg/Vector2.d.ts +115 -137
  48. package/dist/linalg/Vector2.d.ts.map +1 -1
  49. package/dist/linalg/Vector2.js +164 -188
  50. package/dist/linalg/Vector2.js.map +1 -1
  51. package/dist/linalg/Vector3.d.ts +141 -167
  52. package/dist/linalg/Vector3.d.ts.map +1 -1
  53. package/dist/linalg/Vector3.js +200 -237
  54. package/dist/linalg/Vector3.js.map +1 -1
  55. package/dist/linalg/Vector4.d.ts +111 -131
  56. package/dist/linalg/Vector4.d.ts.map +1 -1
  57. package/dist/linalg/Vector4.js +163 -187
  58. package/dist/linalg/Vector4.js.map +1 -1
  59. package/dist/types/AxisAngle.d.ts +2 -2
  60. package/dist/types/AxisAngle.d.ts.map +1 -1
  61. package/dist/types/FieldOfView.d.ts +2 -2
  62. package/dist/types/FieldOfView.d.ts.map +1 -1
  63. package/dist/utility/BigNumber.d.ts +21 -11
  64. package/dist/utility/BigNumber.d.ts.map +1 -1
  65. package/dist/utility/BigNumber.js +42 -31
  66. package/dist/utility/BigNumber.js.map +1 -1
  67. package/dist/utility/MatrixSizeError.d.ts +1 -1
  68. package/dist/utility/MatrixSizeError.d.ts.map +1 -1
  69. package/dist/utility/MatrixSizeError.js +1 -1
  70. package/dist/utility/MatrixSizeError.js.map +1 -1
  71. package/dist/utility/VectorSizeError.d.ts +12 -0
  72. package/dist/utility/VectorSizeError.d.ts.map +1 -0
  73. package/dist/utility/VectorSizeError.js +15 -0
  74. package/dist/utility/VectorSizeError.js.map +1 -0
  75. package/dist/utility/createAxisAngleLike.d.ts +10 -0
  76. package/dist/utility/createAxisAngleLike.d.ts.map +1 -0
  77. package/dist/utility/createAxisAngleLike.js +10 -0
  78. package/dist/utility/createAxisAngleLike.js.map +1 -0
  79. package/package.json +11 -11
  80. package/src/algorithms/greatestCommonDivisor.ts +19 -7
  81. package/src/index.ts +24 -13
  82. package/src/linalg/DualQuaternion.ts +224 -292
  83. package/src/linalg/Matrix.ts +28 -28
  84. package/src/linalg/Matrix2.ts +138 -180
  85. package/src/linalg/Matrix3.ts +211 -286
  86. package/src/linalg/Matrix4.ts +466 -584
  87. package/src/linalg/Quaternion.ts +221 -294
  88. package/src/linalg/SlowMatrix.ts +97 -95
  89. package/src/linalg/SlowSquareMatrix.ts +19 -18
  90. package/src/linalg/SlowVector.ts +450 -0
  91. package/src/linalg/SquareMatrix.ts +9 -9
  92. package/src/linalg/Vector.ts +90 -90
  93. package/src/linalg/Vector2.ts +181 -266
  94. package/src/linalg/Vector3.ts +230 -342
  95. package/src/linalg/Vector4.ts +183 -257
  96. package/src/types/AxisAngle.ts +3 -3
  97. package/src/types/FieldOfView.ts +3 -3
  98. package/src/utility/BigNumber.ts +63 -41
  99. package/src/utility/MatrixSizeError.ts +1 -1
  100. package/src/utility/VectorSizeError.ts +14 -0
  101. package/src/utility/createAxisAngleLike.ts +14 -0
@@ -1,16 +1,17 @@
1
+ import radiansToDegrees from "../algorithms/radiansToDegrees.js";
2
+ import createAxisAngleLike from "../utility/createAxisAngleLike.js";
3
+ import epsilon from "../utility/epsilon.js";
1
4
  import { createMatrix3Like, fromValues as matrix3FromValues } from "./Matrix3.js";
2
5
  import Vector3, { createVector3Like, cross as vector3Cross, dot as vector3Dot, fromValues as vector3FromValues, getMagnitude as vector3GetMagnitude, normalize as vector3Normalize } from "./Vector3.js";
3
6
  import { add as vector4Add, copy as vector4Copy, dot as vector4Dot, exactEquals as vector4ExactEquals, fromValues as vector4FromValues, getMagnitude as vector4GetMagnitude, getSquaredMagnitude as vector4GetSquaredMagnitude, lerp as vector4Lerp, normalize as vector4Normalize, scale as vector4Scale } from "./Vector4.js";
4
- import epsilon from "../utility/epsilon.js";
5
- import radiansToDegrees from "../algorithms/radiansToDegrees.js";
6
7
  /**
7
8
  * Create a quaternion-like object.
8
9
  * @returns A quaternion-like object.
9
10
  * @public
10
11
  */
11
- export const createQuaternionLike = () => {
12
- return new Float32Array(4);
13
- };
12
+ export const createQuaternionLike = () =>
13
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
14
+ new Float32Array(4);
14
15
  /**
15
16
  * Create a quaternion with the given values.
16
17
  * @param x - The first component.
@@ -132,24 +133,34 @@ export const fromMatrix3 = (matrix, out) => {
132
133
  if (m4 > m0) {
133
134
  i = 1;
134
135
  }
136
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
135
137
  if (m8 > matrix[(i * 3 + i)]) {
136
138
  i = 2;
137
139
  }
140
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
138
141
  const j = ((i + 1) % 3);
142
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
139
143
  const k = ((i + 2) % 3);
140
- let fRoot = Math.sqrt(matrix[(i * 3 + i)] -
144
+ let fRoot = Math.sqrt(
145
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
146
+ matrix[(i * 3 + i)] -
147
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
141
148
  matrix[(j * 3 + j)] -
149
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
142
150
  matrix[(k * 3 + k)] +
143
151
  1);
144
152
  out[i] = fRoot / 2;
145
153
  fRoot = 0.5 / fRoot;
146
154
  out[3] =
155
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
147
156
  (matrix[(j * 3 + k)] - matrix[(k * 3 + j)]) *
148
157
  fRoot;
149
158
  out[j] =
159
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
150
160
  (matrix[(j * 3 + i)] + matrix[(i * 3 + j)]) *
151
161
  fRoot;
152
162
  out[k] =
163
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
153
164
  (matrix[(k * 3 + i)] + matrix[(i * 3 + k)]) *
154
165
  fRoot;
155
166
  return out;
@@ -514,7 +525,7 @@ export const exp = (quaternion, out) => {
514
525
  const x = quaternion[0];
515
526
  const y = quaternion[1];
516
527
  const z = quaternion[2];
517
- const r = Math.sqrt(x * x + y * y + z * z); // `Math.hypot` is slower.
528
+ const r = Math.hypot(x, y, z);
518
529
  const et = Math.exp(quaternion[3]);
519
530
  const s = r > 0 ? (et * Math.sin(r)) / r : 0;
520
531
  return fromValues(x * s, y * s, z * s, et * Math.cos(r), out);
@@ -532,7 +543,7 @@ export const ln = (quaternion, out) => {
532
543
  const z = quaternion[2];
533
544
  const w = quaternion[3];
534
545
  const xyz2 = x * x + y * y + z * z;
535
- const r = Math.sqrt(xyz2); // `Math.hypot` is slower.
546
+ const r = Math.sqrt(xyz2);
536
547
  const t = r > 0 ? Math.atan2(r, w) / r : 0;
537
548
  return fromValues(x * t, y * t, z * t, Math.log(xyz2 + w * w) / 2, out);
538
549
  };
@@ -572,9 +583,9 @@ export const slerp = (a, b, t, out) => {
572
583
  bz = -bz;
573
584
  bw = -bw;
574
585
  }
575
- // eslint-disable-next-line init-declarations
586
+ // eslint-disable-next-line @typescript-eslint/init-declarations
576
587
  let scale0;
577
- // eslint-disable-next-line init-declarations
588
+ // eslint-disable-next-line @typescript-eslint/init-declarations
578
589
  let scale1;
579
590
  if (1 - cosom > epsilon) {
580
591
  const omega = Math.acos(cosom);
@@ -682,27 +693,79 @@ export const fromRotationTo = (a, b, out) => {
682
693
  * @public
683
694
  */
684
695
  export default class Quaternion extends Float32Array {
696
+ /** The first component of this quaternion. */
697
+ // eslint-disable-next-line @typescript-eslint/naming-convention
698
+ 0;
699
+ /** The second component of this quaternion. */
700
+ // eslint-disable-next-line @typescript-eslint/naming-convention
701
+ 1;
702
+ /** The third component of this quaternion. */
703
+ // eslint-disable-next-line @typescript-eslint/naming-convention
704
+ 2;
705
+ /** The fourth component of this quaternion. */
706
+ // eslint-disable-next-line @typescript-eslint/naming-convention
707
+ 3;
708
+ /** The axis and angle that represent this quaternion. */
709
+ get axisAngle() {
710
+ return getAxisAngle(this, createAxisAngleLike());
711
+ }
712
+ set axisAngle(value) {
713
+ setAxisAngle(value, this);
714
+ }
715
+ /** Get the magnitude (length) of this quaternion. */
716
+ get magnitude() {
717
+ return getMagnitude(this);
718
+ }
719
+ /** Get the squared magnitude (length) of this quaternion. */
720
+ get squaredMagnitude() {
721
+ return getSquaredMagnitude(this);
722
+ }
685
723
  /**
686
- * Create a quaternion from a three-by-three rotation matrix.
687
- * @param matrix - The matrix.
688
- * @param out - The quaternion to store the result in.
724
+ * Create an identity quaternion.
725
+ * @see {@link https://en.wikipedia.org/wiki/Quaternion | Quaternion}
726
+ */
727
+ constructor() {
728
+ super(4);
729
+ this[3] = 1;
730
+ }
731
+ /**
732
+ * Create a quaternion with values corresponding to the given orthonormal set of vectors.
733
+ * @param view - The vector representing the viewing direction.
734
+ * @param right - The vector representing the local "right" direction.
735
+ * @param up - The vector representing the local "up" direction.
689
736
  * @returns The quaternion.
690
- * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
691
737
  */
692
- static fromMatrix3(matrix, out = new Quaternion()) {
693
- return fromMatrix3(matrix, out);
738
+ static fromAxes(view, right, up) {
739
+ return fromAxes(view, right, up, new Quaternion());
694
740
  }
695
741
  /**
696
742
  * Create a quaternion from equivalent z-y'-x" (intrinsic) Tait-Bryan angles.
697
743
  * @param z - The z (roll) angle.
698
744
  * @param y - The y (pitch) angle.
699
745
  * @param x - The x (yaw) angle.
700
- * @param out - The quaternion to store the result in.
701
746
  * @returns The quaternion.
702
747
  * @see {@link https://en.wikipedia.org/wiki/Euler_angles | Euler angles}
703
748
  */
704
- static fromEuler(z, y, x, out = new Quaternion()) {
705
- return fromEuler(z, y, x, out);
749
+ static fromEuler(z, y, x) {
750
+ return fromEuler(z, y, x, new Quaternion());
751
+ }
752
+ /**
753
+ * Create a quaternion from a three-by-three rotation matrix.
754
+ * @param matrix - The matrix.
755
+ * @returns The quaternion.
756
+ * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
757
+ */
758
+ static fromMatrix3(matrix) {
759
+ return fromMatrix3(matrix, new Quaternion());
760
+ }
761
+ /**
762
+ * Create a unit quaternion that represents the shortest rotation from one unit vector to another.
763
+ * @param a - The first unit vector.
764
+ * @param b - The second unit vector.
765
+ * @returns The unit quaternion.
766
+ */
767
+ static fromRotationTo(a, b) {
768
+ return fromRotationTo(a, b, new Quaternion());
706
769
  }
707
770
  /**
708
771
  * Create a quaternion with the given values.
@@ -710,71 +773,78 @@ export default class Quaternion extends Float32Array {
710
773
  * @param y - The second component.
711
774
  * @param z - The third component.
712
775
  * @param w - The fourth component.
713
- * @param out - The quaternion to store the result in.
714
776
  * @returns A new quaternion.
715
777
  */
716
- static fromValues(x, y, z, w, out = new Quaternion()) {
717
- return fromValues(x, y, z, w, out);
778
+ static fromValues(x, y, z, w) {
779
+ return fromValues(x, y, z, w, new Quaternion());
718
780
  }
719
781
  /**
720
- * Create a quaternion with values corresponding to the given orthonormal set of vectors.
721
- * @param view - The vector representing the viewing direction.
722
- * @param right - The vector representing the local "right" direction.
723
- * @param up - The vector representing the local "up" direction.
724
- * @param out - The quaternion to store the result in.
782
+ * Add two quaternions of the same size.
783
+ * @param quaternion - The other quaternion.
784
+ * @returns The sum of the quaternions.
785
+ */
786
+ add(quaternion) {
787
+ return add(this, quaternion, new Quaternion());
788
+ }
789
+ /**
790
+ * Calculate the fourth component of this unit quaternion from the first three, ignoring the existing fourth component.
725
791
  * @returns The quaternion.
726
792
  */
727
- static fromAxes(view, right, up, out = new Quaternion()) {
728
- return fromAxes(view, right, up, out);
793
+ calculateW() {
794
+ return calculateW(this, new Quaternion());
729
795
  }
730
796
  /**
731
- * Create a unit quaternion that represents the shortest rotation from one unit vector to another.
732
- * @param a - The first unit vector.
733
- * @param b - The second unit vector.
734
- * @param out - The quaternion to store the result in.
735
- * @returns The unit quaternion.
797
+ * Copy the values from this quaternion to another one.
798
+ * @returns The copy.
736
799
  */
737
- static fromRotationTo(a, b, out = new Quaternion()) {
738
- return fromRotationTo(a, b, out);
800
+ clone() {
801
+ return copy(this, new Quaternion());
739
802
  }
740
803
  /**
741
- * Create an identity quaternion.
742
- * @see {@link https://en.wikipedia.org/wiki/Quaternion | Quaternion}
804
+ * Calculate the conjugate of this quaternion. If the quaternion is normalized, this is the same as the inverse but faster to calculate.
805
+ * @returns The conjugate.
743
806
  */
744
- constructor() {
745
- super(4);
746
- this[3] = 1;
807
+ conjugate() {
808
+ return conjugate(this, new Quaternion());
747
809
  }
748
- /** The first component of this quaternion. */
749
- 0;
750
- /** The second component of this quaternion. */
751
- 1;
752
- /** The third component of this quaternion. */
753
- 2;
754
- /** The fourth component of this quaternion. */
755
- 3;
756
810
  /**
757
- * Set this quaternion to the identity.
811
+ * Copy the values of another quaternion into this one.
812
+ * @param quaternion - The quaternion to copy.
758
813
  * @returns This quaternion.
759
814
  */
760
- identity() {
761
- return identity(this);
815
+ copy(quaternion) {
816
+ return copy(quaternion, this);
762
817
  }
763
818
  /**
764
- * Get the axis and angle that represent this quaternion.
765
- * @param out - The axis and angle to store the result in.
766
- * @returns The axis and angle.
819
+ * Calculate the dot product of this and another quaternion.
820
+ * @param quaternion - The other quaternion.
821
+ * @returns The dot product.
767
822
  */
768
- getAxisAngle(out = {}) {
769
- return getAxisAngle(this, out);
823
+ dot(quaternion) {
824
+ return dot(this, quaternion);
770
825
  }
771
826
  /**
772
- * Set the axis and angle that represent this quaternion.
773
- * @param axisAngle - The axis and angle.
774
- * @returns This quaternion.
827
+ * Determine whether or not this quaternion is roughly equivalent to another.
828
+ * @param quaternion - The other quaternion.
829
+ * @returns Whether or not the quaternions are equivalent.
775
830
  */
776
- setAxisAngle(axisAngle) {
777
- return setAxisAngle(axisAngle, this);
831
+ equals(quaternion) {
832
+ return equals(this, quaternion);
833
+ }
834
+ /**
835
+ * Determine whether or not this quaternion is exactly equivalent to another.
836
+ * @param quaternion - The other quaternion.
837
+ * @returns Whether or not the quaternions are equivalent.
838
+ */
839
+ exactEquals(quaternion) {
840
+ return exactEquals(this, quaternion);
841
+ }
842
+ /**
843
+ * Calculate the exponential of this unit quaternion.
844
+ * @returns The exponential.
845
+ */
846
+ exp() {
847
+ return exp(this, new Quaternion());
778
848
  }
779
849
  /**
780
850
  * Get the angular distance between this unit quaternion and another.
@@ -785,84 +855,57 @@ export default class Quaternion extends Float32Array {
785
855
  return getAngle(this, quaternion);
786
856
  }
787
857
  /**
788
- * Multiply this and another quaternion.
789
- * @param quaternion - The other quaternion.
790
- * @param out - The quaternion to store the result in.
791
- * @returns The product.
792
- */
793
- multiply(quaternion, out = new Quaternion()) {
794
- return multiply(this, quaternion, out);
795
- }
796
- /**
797
- * Rotate this quaternion by the given angle around the X-axis.
798
- * @param r - The angle in radians.
799
- * @param out - The quaternion to store the result in.
800
- * @returns The rotated quaternion.
858
+ * Set this quaternion to the identity.
859
+ * @returns This quaternion.
801
860
  */
802
- rotateX(r, out = new Quaternion()) {
803
- return rotateX(this, r, out);
861
+ identity() {
862
+ return identity(this);
804
863
  }
805
864
  /**
806
- * Rotate this quaternion by the given angle around the Y-axis.
807
- * @param r - The angle in radians.
808
- * @param out - The quaternion to store the result in.
809
- * @returns The rotated quaternion.
865
+ * Calculate the inverse of this quaternion. If the quaternion is normalized, the conjugate is the same but faster to calculate.
866
+ * @returns The inverse.
810
867
  */
811
- rotateY(r, out = new Quaternion()) {
812
- return rotateY(this, r, out);
868
+ invert() {
869
+ return invert(this, new Quaternion());
813
870
  }
814
871
  /**
815
- * Rotate this quaternion by the given angle around the Z-axis.
816
- * @param r - The angle in radians.
817
- * @param out - The quaternion to store the result in.
818
- * @returns The rotated quaternion.
872
+ * Perform a linear interpolation between this and another quaternion.
873
+ * @param quaternion - The other quaternion.
874
+ * @param t - The interpolation amount (in `[0,1]`).
875
+ * @returns The interpolated quaternion.
819
876
  */
820
- rotateZ(r, out = new Quaternion()) {
821
- return rotateZ(this, r, out);
877
+ lerp(quaternion, t) {
878
+ return lerp(this, quaternion, t, new Quaternion());
822
879
  }
823
880
  /**
824
- * Calculate the fourth component of this unit quaternion from the first three, ignoring the existing fourth component.
825
- * @param out - The quaternion to store the result in.
826
- * @returns The quaternion.
881
+ * Calculate the natural logarithm of this unit quaternion.
882
+ * @returns The natural logarithm.
827
883
  */
828
- calculateW(out = new Quaternion()) {
829
- return calculateW(this, out);
884
+ ln() {
885
+ return ln(this, new Quaternion());
830
886
  }
831
887
  /**
832
- * Calculate the exponential of this unit quaternion.
833
- * @param out - The quaternion to store the result in.
834
- * @returns The exponential.
888
+ * Multiply this and another quaternion.
889
+ * @param quaternion - The other quaternion.
890
+ * @returns The product.
835
891
  */
836
- exp(out = new Quaternion()) {
837
- return exp(this, out);
892
+ multiply(quaternion) {
893
+ return multiply(this, quaternion, new Quaternion());
838
894
  }
839
895
  /**
840
- * Calculate the natural logarithm of this unit quaternion.
841
- * @param out - The quaternion to store the result in.
842
- * @returns The natural logarithm.
896
+ * Normalize this quaternion.
897
+ * @returns The normalized quaternion.
843
898
  */
844
- ln(out = new Quaternion()) {
845
- return ln(this, out);
899
+ normalize() {
900
+ return normalize(this, new Quaternion());
846
901
  }
847
902
  /**
848
903
  * Calculate a power of this unit quaternion.
849
904
  * @param scalar - The amount to scale the quaternion by.
850
- * @param out - The quaternion to store the result in.
851
905
  * @returns The power.
852
906
  */
853
- pow(scalar, out = new Quaternion()) {
854
- return pow(this, scalar, out);
855
- }
856
- /**
857
- * Perform a spherical linear interpolation between this and another quaternion.
858
- * @param quaternion - The other quaternion.
859
- * @param t - The interpolation amount in `[0,1]`.
860
- * @param out - The quaternion to store the result in.
861
- * @returns The interpolated quaternion.
862
- * @see {@link https://en.wikipedia.org/wiki/Slerp | Slerp}
863
- */
864
- slerp(quaternion, t, out = new Quaternion()) {
865
- return slerp(this, quaternion, t, out);
907
+ pow(scalar) {
908
+ return pow(this, scalar, new Quaternion());
866
909
  }
867
910
  /**
868
911
  * Set this to a random unit quaternion.
@@ -872,104 +915,46 @@ export default class Quaternion extends Float32Array {
872
915
  return random(this);
873
916
  }
874
917
  /**
875
- * Calculate the inverse of this quaternion. If the quaternion is normalized, the conjugate is the same but faster to calculate.
876
- * @param out - The quaternion to store the result in.
877
- * @returns The inverse.
878
- */
879
- invert(out = new Quaternion()) {
880
- return invert(this, out);
881
- }
882
- /**
883
- * Calculate the conjugate of this quaternion. If the quaternion is normalized, this is the same as the inverse but faster to calculate.
884
- * @param out - The quaternion to store the result in.
885
- * @returns The conjugate.
886
- */
887
- conjugate(out = new Quaternion()) {
888
- return conjugate(this, out);
889
- }
890
- /**
891
- * Copy the values from this quaternion to another one.
892
- * @param out - The quaternion to store the result in.
893
- * @returns The copy.
918
+ * Rotate this quaternion by the given angle around the X-axis.
919
+ * @param r - The angle in radians.
920
+ * @returns The rotated quaternion.
894
921
  */
895
- clone(out = new Quaternion()) {
896
- return copy(this, out);
922
+ rotateX(r) {
923
+ return rotateX(this, r, new Quaternion());
897
924
  }
898
925
  /**
899
- * Copy the values of another quaternion into this one.
900
- * @param quaternion - The quaternion to copy.
901
- * @returns This quaternion.
926
+ * Rotate this quaternion by the given angle around the Y-axis.
927
+ * @param r - The angle in radians.
928
+ * @returns The rotated quaternion.
902
929
  */
903
- copy(quaternion) {
904
- return copy(quaternion, this);
930
+ rotateY(r) {
931
+ return rotateY(this, r, new Quaternion());
905
932
  }
906
933
  /**
907
- * Add two quaternions of the same size.
908
- * @param quaternion - The other quaternion.
909
- * @param out - The quaternion to store the result in.
910
- * @returns The sum of the quaternions.
934
+ * Rotate this quaternion by the given angle around the Z-axis.
935
+ * @param r - The angle in radians.
936
+ * @returns The rotated quaternion.
911
937
  */
912
- add(quaternion, out = new Quaternion()) {
913
- return add(this, quaternion, out);
938
+ rotateZ(r) {
939
+ return rotateZ(this, r, new Quaternion());
914
940
  }
915
941
  /**
916
942
  * Scale this quaternion by a scalar.
917
943
  * @param scalar - The scalar.
918
- * @param out - The quaternion to store the result in.
919
944
  * @returns The scaled quaternion.
920
945
  */
921
- scale(scalar, out = new Quaternion()) {
922
- return scale(this, scalar, out);
923
- }
924
- /**
925
- * Calculate the dot product of this and another quaternion.
926
- * @param quaternion - The other quaternion.
927
- * @returns The dot product.
928
- */
929
- dot(quaternion) {
930
- return dot(this, quaternion);
946
+ scale(scalar) {
947
+ return scale(this, scalar, new Quaternion());
931
948
  }
932
949
  /**
933
- * Perform a linear interpolation between this and another quaternion.
950
+ * Perform a spherical linear interpolation between this and another quaternion.
934
951
  * @param quaternion - The other quaternion.
935
- * @param t - The interpolation amount (in `[0,1]`).
936
- * @param out - The quaternion to store the result in.
952
+ * @param t - The interpolation amount in `[0,1]`.
937
953
  * @returns The interpolated quaternion.
954
+ * @see {@link https://en.wikipedia.org/wiki/Slerp | Slerp}
938
955
  */
939
- lerp(quaternion, t, out = new Quaternion()) {
940
- return lerp(this, quaternion, t, out);
941
- }
942
- /** Get the magnitude (length) of this quaternion. */
943
- get magnitude() {
944
- return getMagnitude(this);
945
- }
946
- /** Get the squared magnitude (length) of this quaternion. */
947
- get squaredMagnitude() {
948
- return getSquaredMagnitude(this);
949
- }
950
- /**
951
- * Normalize this quaternion.
952
- * @param out - The quaternion to store the result in.
953
- * @returns The normalized quaternion.
954
- */
955
- normalize(out = new Quaternion()) {
956
- return normalize(this, out);
957
- }
958
- /**
959
- * Determine whether or not this quaternion is roughly equivalent to another.
960
- * @param quaternion - The other quaternion.
961
- * @returns Whether or not the quaternions are equivalent.
962
- */
963
- equals(quaternion) {
964
- return equals(this, quaternion);
965
- }
966
- /**
967
- * Determine whether or not this quaternion is exactly equivalent to another.
968
- * @param quaternion - The other quaternion.
969
- * @returns Whether or not the quaternions are equivalent.
970
- */
971
- exactEquals(quaternion) {
972
- return exactEquals(this, quaternion);
956
+ slerp(quaternion, t) {
957
+ return slerp(this, quaternion, t, new Quaternion());
973
958
  }
974
959
  /**
975
960
  * Perform a spherical linear interpolation with two control points between this and another quaternion.
@@ -977,20 +962,18 @@ export default class Quaternion extends Float32Array {
977
962
  * @param b - The second control point.
978
963
  * @param quaternion - The other quaternion.
979
964
  * @param t - The interpolation amount in `[0,1]`.
980
- * @param out - The quaternion to store the result in.
981
965
  * @returns The interpolated value.
982
966
  * @see {@link https://en.wikipedia.org/wiki/Slerp | Slerp}
983
967
  */
984
- sqlerp(a, b, quaternion, t, out = new Quaternion()) {
985
- return sqlerp(this, a, b, quaternion, t, out);
968
+ sqlerp(a, b, quaternion, t) {
969
+ return sqlerp(this, a, b, quaternion, t, new Quaternion());
986
970
  }
987
971
  /**
988
972
  * Convert this quaternion to equivalent z-y'-x" (intrinsic) Tait-Bryan angles.
989
- * @param out - The vector in which to store the Tait-Bryan angles.
990
973
  * @returns The Tait-Bryan angles in degrees in roll (z), pitch (y'), yaw (x") order.
991
974
  */
992
- toEuler(out = new Vector3()) {
993
- return toEuler(this, out);
975
+ toEuler() {
976
+ return toEuler(this, new Vector3());
994
977
  }
995
978
  }
996
979
  //# sourceMappingURL=Quaternion.js.map