@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,15 +1,20 @@
1
+ import type AxisAngle from "../types/AxisAngle.js";
2
+
3
+ import radiansToDegrees from "../algorithms/radiansToDegrees.js";
4
+ import createAxisAngleLike from "../utility/createAxisAngleLike.js";
5
+ import epsilon from "../utility/epsilon.js";
1
6
  import {
2
- type Matrix3Like,
3
7
  createMatrix3Like,
4
- fromValues as matrix3FromValues
8
+ fromValues as matrix3FromValues,
9
+ type Matrix3Like
5
10
  } from "./Matrix3.js";
6
11
  import Vector3, {
7
- type Vector3Like,
8
12
  createVector3Like,
9
13
  cross as vector3Cross,
10
14
  dot as vector3Dot,
11
15
  fromValues as vector3FromValues,
12
16
  getMagnitude as vector3GetMagnitude,
17
+ type Vector3Like,
13
18
  normalize as vector3Normalize
14
19
  } from "./Vector3.js";
15
20
  import {
@@ -24,9 +29,6 @@ import {
24
29
  normalize as vector4Normalize,
25
30
  scale as vector4Scale
26
31
  } from "./Vector4.js";
27
- import type AxisAngle from "../types/AxisAngle.js";
28
- import epsilon from "../utility/epsilon.js";
29
- import radiansToDegrees from "../algorithms/radiansToDegrees.js";
30
32
 
31
33
  /**
32
34
  * A complex number that is commonly used to describe rotations.
@@ -35,15 +37,19 @@ import radiansToDegrees from "../algorithms/radiansToDegrees.js";
35
37
  */
36
38
  export interface QuaternionLike extends Record<number, number> {
37
39
  /** The first component of this quaternion. */
40
+ // eslint-disable-next-line @typescript-eslint/naming-convention
38
41
  0: number;
39
42
 
40
43
  /** The second component of this quaternion. */
44
+ // eslint-disable-next-line @typescript-eslint/naming-convention
41
45
  1: number;
42
46
 
43
47
  /** The third component of this quaternion. */
48
+ // eslint-disable-next-line @typescript-eslint/naming-convention
44
49
  2: number;
45
50
 
46
51
  /** The fourth component of this quaternion. */
52
+ // eslint-disable-next-line @typescript-eslint/naming-convention
47
53
  3: number;
48
54
  }
49
55
 
@@ -52,9 +58,9 @@ export interface QuaternionLike extends Record<number, number> {
52
58
  * @returns A quaternion-like object.
53
59
  * @public
54
60
  */
55
- export const createQuaternionLike = (): Float32Array & QuaternionLike => {
56
- return new Float32Array(4) as Float32Array & QuaternionLike;
57
- };
61
+ export const createQuaternionLike = (): Float32Array & QuaternionLike =>
62
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
63
+ new Float32Array(4) as Float32Array & QuaternionLike;
58
64
 
59
65
  /**
60
66
  * Create a quaternion with the given values.
@@ -222,28 +228,37 @@ export const fromMatrix3 = <T extends QuaternionLike>(
222
228
  if (m4 > m0) {
223
229
  i = 1;
224
230
  }
231
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
225
232
  if (m8 > matrix[(i * 3 + i) as 0 | 4]) {
226
233
  i = 2;
227
234
  }
228
- const j = ((i + 1) % 3) as 1 | 2 | 0;
229
- const k = ((i + 2) % 3) as 2 | 0 | 1;
235
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
236
+ const j = ((i + 1) % 3) as 0 | 1 | 2;
237
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
238
+ const k = ((i + 2) % 3) as 0 | 1 | 2;
230
239
 
231
240
  let fRoot: number = Math.sqrt(
241
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
232
242
  matrix[(i * 3 + i) as 0 | 4 | 7] -
233
- matrix[(j * 3 + j) as 4 | 7 | 0] -
234
- matrix[(k * 3 + k) as 7 | 0 | 4] +
243
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
244
+ matrix[(j * 3 + j) as 0 | 4 | 7] -
245
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
246
+ matrix[(k * 3 + k) as 0 | 4 | 7] +
235
247
  1
236
248
  );
237
249
  out[i] = fRoot / 2;
238
250
  fRoot = 0.5 / fRoot;
239
251
  out[3] =
240
- (matrix[(j * 3 + k) as 5 | 6 | 1] - matrix[(k * 3 + j) as 7 | 2 | 3]) *
252
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
253
+ (matrix[(j * 3 + k) as 1 | 5 | 6] - matrix[(k * 3 + j) as 2 | 3 | 7]) *
241
254
  fRoot;
242
255
  out[j] =
243
- (matrix[(j * 3 + i) as 3 | 7 | 2] + matrix[(i * 3 + j) as 1 | 5 | 6]) *
256
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
257
+ (matrix[(j * 3 + i) as 2 | 3 | 7] + matrix[(i * 3 + j) as 1 | 5 | 6]) *
244
258
  fRoot;
245
259
  out[k] =
246
- (matrix[(k * 3 + i) as 6 | 1 | 5] + matrix[(i * 3 + k) as 2 | 3 | 7]) *
260
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
261
+ (matrix[(k * 3 + i) as 1 | 5 | 6] + matrix[(i * 3 + k) as 2 | 3 | 7]) *
247
262
  fRoot;
248
263
  return out;
249
264
  };
@@ -826,7 +841,7 @@ export const exp = <T extends QuaternionLike>(
826
841
  const y = quaternion[1];
827
842
  const z = quaternion[2];
828
843
 
829
- const r = Math.sqrt(x * x + y * y + z * z); // `Math.hypot` is slower.
844
+ const r = Math.hypot(x, y, z);
830
845
  const et = Math.exp(quaternion[3]);
831
846
  const s = r > 0 ? (et * Math.sin(r)) / r : 0;
832
847
 
@@ -850,7 +865,7 @@ export const ln = <T extends QuaternionLike>(
850
865
  const w = quaternion[3];
851
866
 
852
867
  const xyz2 = x * x + y * y + z * z;
853
- const r = Math.sqrt(xyz2); // `Math.hypot` is slower.
868
+ const r = Math.sqrt(xyz2);
854
869
  const t = r > 0 ? Math.atan2(r, w) / r : 0;
855
870
 
856
871
  return fromValues(x * t, y * t, z * t, Math.log(xyz2 + w * w) / 2, out);
@@ -905,9 +920,9 @@ export const slerp = <T extends QuaternionLike>(
905
920
  bw = -bw;
906
921
  }
907
922
 
908
- // eslint-disable-next-line init-declarations
923
+ // eslint-disable-next-line @typescript-eslint/init-declarations
909
924
  let scale0;
910
- // eslint-disable-next-line init-declarations
925
+ // eslint-disable-next-line @typescript-eslint/init-declarations
911
926
  let scale1;
912
927
  if (1 - cosom > epsilon) {
913
928
  const omega = Math.acos(cosom);
@@ -1074,18 +1089,63 @@ export const fromRotationTo = <T extends QuaternionLike>(
1074
1089
  * @public
1075
1090
  */
1076
1091
  export default class Quaternion extends Float32Array implements QuaternionLike {
1092
+ /** The first component of this quaternion. */
1093
+ // eslint-disable-next-line @typescript-eslint/naming-convention
1094
+ public 0: number;
1095
+
1096
+ /** The second component of this quaternion. */
1097
+ // eslint-disable-next-line @typescript-eslint/naming-convention
1098
+ public 1: number;
1099
+
1100
+ /** The third component of this quaternion. */
1101
+ // eslint-disable-next-line @typescript-eslint/naming-convention
1102
+ public 2: number;
1103
+
1104
+ /** The fourth component of this quaternion. */
1105
+ // eslint-disable-next-line @typescript-eslint/naming-convention
1106
+ public 3: number;
1107
+
1108
+ /** The axis and angle that represent this quaternion. */
1109
+ public get axisAngle(): ReturnType<typeof createAxisAngleLike> {
1110
+ return getAxisAngle(this, createAxisAngleLike());
1111
+ }
1112
+
1113
+ public set axisAngle(value: AxisAngle) {
1114
+ setAxisAngle(value, this);
1115
+ }
1116
+
1117
+ /** Get the magnitude (length) of this quaternion. */
1118
+ public get magnitude(): number {
1119
+ return getMagnitude(this);
1120
+ }
1121
+
1122
+ /** Get the squared magnitude (length) of this quaternion. */
1123
+ public get squaredMagnitude(): number {
1124
+ return getSquaredMagnitude(this);
1125
+ }
1126
+
1077
1127
  /**
1078
- * Create a quaternion from a three-by-three rotation matrix.
1079
- * @param matrix - The matrix.
1080
- * @param out - The quaternion to store the result in.
1128
+ * Create an identity quaternion.
1129
+ * @see {@link https://en.wikipedia.org/wiki/Quaternion | Quaternion}
1130
+ */
1131
+ public constructor() {
1132
+ super(4);
1133
+ this[3] = 1;
1134
+ }
1135
+
1136
+ /**
1137
+ * Create a quaternion with values corresponding to the given orthonormal set of vectors.
1138
+ * @param view - The vector representing the viewing direction.
1139
+ * @param right - The vector representing the local "right" direction.
1140
+ * @param up - The vector representing the local "up" direction.
1081
1141
  * @returns The quaternion.
1082
- * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
1083
1142
  */
1084
- public static fromMatrix3<T extends QuaternionLike = Quaternion>(
1085
- matrix: Matrix3Like,
1086
- out: T = new Quaternion() as Quaternion & T
1087
- ): T {
1088
- return fromMatrix3(matrix, out);
1143
+ public static fromAxes(
1144
+ view: Vector3Like,
1145
+ right: Vector3Like,
1146
+ up: Vector3Like
1147
+ ): Quaternion {
1148
+ return fromAxes(view, right, up, new Quaternion());
1089
1149
  }
1090
1150
 
1091
1151
  /**
@@ -1093,17 +1153,31 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
1093
1153
  * @param z - The z (roll) angle.
1094
1154
  * @param y - The y (pitch) angle.
1095
1155
  * @param x - The x (yaw) angle.
1096
- * @param out - The quaternion to store the result in.
1097
1156
  * @returns The quaternion.
1098
1157
  * @see {@link https://en.wikipedia.org/wiki/Euler_angles | Euler angles}
1099
1158
  */
1100
- public static fromEuler<T extends QuaternionLike = Quaternion>(
1101
- z: number,
1102
- y: number,
1103
- x: number,
1104
- out: T = new Quaternion() as Quaternion & T
1105
- ): T {
1106
- return fromEuler(z, y, x, out);
1159
+ public static fromEuler(z: number, y: number, x: number): Quaternion {
1160
+ return fromEuler(z, y, x, new Quaternion());
1161
+ }
1162
+
1163
+ /**
1164
+ * Create a quaternion from a three-by-three rotation matrix.
1165
+ * @param matrix - The matrix.
1166
+ * @returns The quaternion.
1167
+ * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
1168
+ */
1169
+ public static fromMatrix3(matrix: Matrix3Like): Quaternion {
1170
+ return fromMatrix3(matrix, new Quaternion());
1171
+ }
1172
+
1173
+ /**
1174
+ * Create a unit quaternion that represents the shortest rotation from one unit vector to another.
1175
+ * @param a - The first unit vector.
1176
+ * @param b - The second unit vector.
1177
+ * @returns The unit quaternion.
1178
+ */
1179
+ public static fromRotationTo(a: Vector3Like, b: Vector3Like): Quaternion {
1180
+ return fromRotationTo(a, b, new Quaternion());
1107
1181
  }
1108
1182
 
1109
1183
  /**
@@ -1112,358 +1186,216 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
1112
1186
  * @param y - The second component.
1113
1187
  * @param z - The third component.
1114
1188
  * @param w - The fourth component.
1115
- * @param out - The quaternion to store the result in.
1116
1189
  * @returns A new quaternion.
1117
1190
  */
1118
- public static fromValues<T extends QuaternionLike = Quaternion>(
1191
+ public static fromValues(
1119
1192
  x: number,
1120
1193
  y: number,
1121
1194
  z: number,
1122
- w: number,
1123
- out: T = new Quaternion() as Quaternion & T
1124
- ): T {
1125
- return fromValues(x, y, z, w, out);
1195
+ w: number
1196
+ ): Quaternion {
1197
+ return fromValues(x, y, z, w, new Quaternion());
1126
1198
  }
1127
1199
 
1128
1200
  /**
1129
- * Create a quaternion with values corresponding to the given orthonormal set of vectors.
1130
- * @param view - The vector representing the viewing direction.
1131
- * @param right - The vector representing the local "right" direction.
1132
- * @param up - The vector representing the local "up" direction.
1133
- * @param out - The quaternion to store the result in.
1134
- * @returns The quaternion.
1201
+ * Add two quaternions of the same size.
1202
+ * @param quaternion - The other quaternion.
1203
+ * @returns The sum of the quaternions.
1135
1204
  */
1136
- public static fromAxes<T extends QuaternionLike = Quaternion>(
1137
- view: Vector3Like,
1138
- right: Vector3Like,
1139
- up: Vector3Like,
1140
- out: T = new Quaternion() as Quaternion & T
1141
- ): T {
1142
- return fromAxes(view, right, up, out);
1205
+ public add(quaternion: QuaternionLike): Quaternion {
1206
+ return add(this, quaternion, new Quaternion());
1143
1207
  }
1144
1208
 
1145
1209
  /**
1146
- * Create a unit quaternion that represents the shortest rotation from one unit vector to another.
1147
- * @param a - The first unit vector.
1148
- * @param b - The second unit vector.
1149
- * @param out - The quaternion to store the result in.
1150
- * @returns The unit quaternion.
1210
+ * Calculate the fourth component of this unit quaternion from the first three, ignoring the existing fourth component.
1211
+ * @returns The quaternion.
1151
1212
  */
1152
- public static fromRotationTo<T extends QuaternionLike = Quaternion>(
1153
- a: Vector3Like,
1154
- b: Vector3Like,
1155
- out: T = new Quaternion() as Quaternion & T
1156
- ): T {
1157
- return fromRotationTo(a, b, out);
1213
+ public calculateW(): Quaternion {
1214
+ return calculateW(this, new Quaternion());
1158
1215
  }
1159
1216
 
1160
1217
  /**
1161
- * Create an identity quaternion.
1162
- * @see {@link https://en.wikipedia.org/wiki/Quaternion | Quaternion}
1218
+ * Copy the values from this quaternion to another one.
1219
+ * @returns The copy.
1163
1220
  */
1164
- public constructor() {
1165
- super(4);
1166
- this[3] = 1;
1221
+ public clone(): Quaternion {
1222
+ return copy(this, new Quaternion());
1167
1223
  }
1168
1224
 
1169
- /** The first component of this quaternion. */
1170
- public 0: number;
1171
-
1172
- /** The second component of this quaternion. */
1173
- public 1: number;
1174
-
1175
- /** The third component of this quaternion. */
1176
- public 2: number;
1177
-
1178
- /** The fourth component of this quaternion. */
1179
- public 3: number;
1180
-
1181
1225
  /**
1182
- * Set this quaternion to the identity.
1183
- * @returns This quaternion.
1226
+ * Calculate the conjugate of this quaternion. If the quaternion is normalized, this is the same as the inverse but faster to calculate.
1227
+ * @returns The conjugate.
1184
1228
  */
1185
- public identity(): this {
1186
- return identity(this);
1229
+ public conjugate(): Quaternion {
1230
+ return conjugate(this, new Quaternion());
1187
1231
  }
1188
1232
 
1189
1233
  /**
1190
- * Get the axis and angle that represent this quaternion.
1191
- * @param out - The axis and angle to store the result in.
1192
- * @returns The axis and angle.
1234
+ * Copy the values of another quaternion into this one.
1235
+ * @param quaternion - The quaternion to copy.
1236
+ * @returns This quaternion.
1193
1237
  */
1194
- public getAxisAngle<T extends AxisAngle>(out = {} as T): T {
1195
- return getAxisAngle(this, out);
1238
+ public copy(quaternion: QuaternionLike): this {
1239
+ return copy(quaternion, this);
1196
1240
  }
1197
1241
 
1198
1242
  /**
1199
- * Set the axis and angle that represent this quaternion.
1200
- * @param axisAngle - The axis and angle.
1201
- * @returns This quaternion.
1243
+ * Calculate the dot product of this and another quaternion.
1244
+ * @param quaternion - The other quaternion.
1245
+ * @returns The dot product.
1202
1246
  */
1203
- public setAxisAngle(axisAngle: AxisAngle): this {
1204
- return setAxisAngle(axisAngle, this);
1247
+ public dot(quaternion: QuaternionLike): number {
1248
+ return dot(this, quaternion);
1205
1249
  }
1206
1250
 
1207
1251
  /**
1208
- * Get the angular distance between this unit quaternion and another.
1209
- * @param quaternion - The other unit quaternion.
1210
- * @returns The angular distance in radians.
1252
+ * Determine whether or not this quaternion is roughly equivalent to another.
1253
+ * @param quaternion - The other quaternion.
1254
+ * @returns Whether or not the quaternions are equivalent.
1211
1255
  */
1212
- public getAngle(quaternion: QuaternionLike): number {
1213
- return getAngle(this, quaternion);
1256
+ public equals(quaternion: QuaternionLike): boolean {
1257
+ return equals(this, quaternion);
1214
1258
  }
1215
1259
 
1216
1260
  /**
1217
- * Multiply this and another quaternion.
1261
+ * Determine whether or not this quaternion is exactly equivalent to another.
1218
1262
  * @param quaternion - The other quaternion.
1219
- * @param out - The quaternion to store the result in.
1220
- * @returns The product.
1263
+ * @returns Whether or not the quaternions are equivalent.
1221
1264
  */
1222
- public multiply<T extends QuaternionLike = Quaternion>(
1223
- quaternion: QuaternionLike,
1224
- out: T = new Quaternion() as Quaternion & T
1225
- ): T {
1226
- return multiply(this, quaternion, out);
1265
+ public exactEquals(quaternion: QuaternionLike): boolean {
1266
+ return exactEquals(this, quaternion);
1227
1267
  }
1228
1268
 
1229
1269
  /**
1230
- * Rotate this quaternion by the given angle around the X-axis.
1231
- * @param r - The angle in radians.
1232
- * @param out - The quaternion to store the result in.
1233
- * @returns The rotated quaternion.
1270
+ * Calculate the exponential of this unit quaternion.
1271
+ * @returns The exponential.
1234
1272
  */
1235
- public rotateX<T extends QuaternionLike = Quaternion>(
1236
- r: number,
1237
- out: T = new Quaternion() as Quaternion & T
1238
- ): T {
1239
- return rotateX(this, r, out);
1273
+ public exp(): Quaternion {
1274
+ return exp(this, new Quaternion());
1240
1275
  }
1241
1276
 
1242
1277
  /**
1243
- * Rotate this quaternion by the given angle around the Y-axis.
1244
- * @param r - The angle in radians.
1245
- * @param out - The quaternion to store the result in.
1246
- * @returns The rotated quaternion.
1278
+ * Get the angular distance between this unit quaternion and another.
1279
+ * @param quaternion - The other unit quaternion.
1280
+ * @returns The angular distance in radians.
1247
1281
  */
1248
- public rotateY<T extends QuaternionLike = Quaternion>(
1249
- r: number,
1250
- out: T = new Quaternion() as Quaternion & T
1251
- ): T {
1252
- return rotateY(this, r, out);
1282
+ public getAngle(quaternion: QuaternionLike): number {
1283
+ return getAngle(this, quaternion);
1253
1284
  }
1254
1285
 
1255
1286
  /**
1256
- * Rotate this quaternion by the given angle around the Z-axis.
1257
- * @param r - The angle in radians.
1258
- * @param out - The quaternion to store the result in.
1259
- * @returns The rotated quaternion.
1287
+ * Set this quaternion to the identity.
1288
+ * @returns This quaternion.
1260
1289
  */
1261
- public rotateZ<T extends QuaternionLike = Quaternion>(
1262
- r: number,
1263
- out: T = new Quaternion() as Quaternion & T
1264
- ): T {
1265
- return rotateZ(this, r, out);
1290
+ public identity(): this {
1291
+ return identity(this);
1266
1292
  }
1267
1293
 
1268
1294
  /**
1269
- * Calculate the fourth component of this unit quaternion from the first three, ignoring the existing fourth component.
1270
- * @param out - The quaternion to store the result in.
1271
- * @returns The quaternion.
1295
+ * Calculate the inverse of this quaternion. If the quaternion is normalized, the conjugate is the same but faster to calculate.
1296
+ * @returns The inverse.
1272
1297
  */
1273
- public calculateW<T extends QuaternionLike = Quaternion>(
1274
- out: T = new Quaternion() as Quaternion & T
1275
- ): T {
1276
- return calculateW(this, out);
1298
+ public invert(): Quaternion {
1299
+ return invert(this, new Quaternion());
1277
1300
  }
1278
1301
 
1279
1302
  /**
1280
- * Calculate the exponential of this unit quaternion.
1281
- * @param out - The quaternion to store the result in.
1282
- * @returns The exponential.
1303
+ * Perform a linear interpolation between this and another quaternion.
1304
+ * @param quaternion - The other quaternion.
1305
+ * @param t - The interpolation amount (in `[0,1]`).
1306
+ * @returns The interpolated quaternion.
1283
1307
  */
1284
- public exp<T extends QuaternionLike = Quaternion>(
1285
- out: T = new Quaternion() as Quaternion & T
1286
- ): T {
1287
- return exp(this, out);
1308
+ public lerp(quaternion: QuaternionLike, t: number): Quaternion {
1309
+ return lerp(this, quaternion, t, new Quaternion());
1288
1310
  }
1289
1311
 
1290
1312
  /**
1291
1313
  * Calculate the natural logarithm of this unit quaternion.
1292
- * @param out - The quaternion to store the result in.
1293
1314
  * @returns The natural logarithm.
1294
1315
  */
1295
- public ln<T extends QuaternionLike = Quaternion>(
1296
- out: T = new Quaternion() as Quaternion & T
1297
- ): T {
1298
- return ln(this, out);
1299
- }
1300
-
1301
- /**
1302
- * Calculate a power of this unit quaternion.
1303
- * @param scalar - The amount to scale the quaternion by.
1304
- * @param out - The quaternion to store the result in.
1305
- * @returns The power.
1306
- */
1307
- public pow<T extends QuaternionLike = Quaternion>(
1308
- scalar: number,
1309
- out: T = new Quaternion() as Quaternion & T
1310
- ): T {
1311
- return pow(this, scalar, out);
1316
+ public ln(): Quaternion {
1317
+ return ln(this, new Quaternion());
1312
1318
  }
1313
1319
 
1314
1320
  /**
1315
- * Perform a spherical linear interpolation between this and another quaternion.
1321
+ * Multiply this and another quaternion.
1316
1322
  * @param quaternion - The other quaternion.
1317
- * @param t - The interpolation amount in `[0,1]`.
1318
- * @param out - The quaternion to store the result in.
1319
- * @returns The interpolated quaternion.
1320
- * @see {@link https://en.wikipedia.org/wiki/Slerp | Slerp}
1323
+ * @returns The product.
1321
1324
  */
1322
- public slerp<T extends QuaternionLike = Quaternion>(
1323
- quaternion: QuaternionLike,
1324
- t: number,
1325
- out: T = new Quaternion() as Quaternion & T
1326
- ): T {
1327
- return slerp(this, quaternion, t, out);
1325
+ public multiply(quaternion: QuaternionLike): Quaternion {
1326
+ return multiply(this, quaternion, new Quaternion());
1328
1327
  }
1329
1328
 
1330
1329
  /**
1331
- * Set this to a random unit quaternion.
1332
- * @returns A random unit quaternion.
1330
+ * Normalize this quaternion.
1331
+ * @returns The normalized quaternion.
1333
1332
  */
1334
- public random(): this {
1335
- return random(this);
1333
+ public normalize(): Quaternion {
1334
+ return normalize(this, new Quaternion());
1336
1335
  }
1337
1336
 
1338
1337
  /**
1339
- * Calculate the inverse of this quaternion. If the quaternion is normalized, the conjugate is the same but faster to calculate.
1340
- * @param out - The quaternion to store the result in.
1341
- * @returns The inverse.
1338
+ * Calculate a power of this unit quaternion.
1339
+ * @param scalar - The amount to scale the quaternion by.
1340
+ * @returns The power.
1342
1341
  */
1343
- public invert<T extends QuaternionLike = Quaternion>(
1344
- out: T = new Quaternion() as Quaternion & T
1345
- ): T {
1346
- return invert(this, out);
1342
+ public pow(scalar: number): Quaternion {
1343
+ return pow(this, scalar, new Quaternion());
1347
1344
  }
1348
1345
 
1349
1346
  /**
1350
- * Calculate the conjugate of this quaternion. If the quaternion is normalized, this is the same as the inverse but faster to calculate.
1351
- * @param out - The quaternion to store the result in.
1352
- * @returns The conjugate.
1347
+ * Set this to a random unit quaternion.
1348
+ * @returns A random unit quaternion.
1353
1349
  */
1354
- public conjugate<T extends QuaternionLike = Quaternion>(
1355
- out: T = new Quaternion() as Quaternion & T
1356
- ): T {
1357
- return conjugate(this, out);
1350
+ public random(): this {
1351
+ return random(this);
1358
1352
  }
1359
1353
 
1360
1354
  /**
1361
- * Copy the values from this quaternion to another one.
1362
- * @param out - The quaternion to store the result in.
1363
- * @returns The copy.
1355
+ * Rotate this quaternion by the given angle around the X-axis.
1356
+ * @param r - The angle in radians.
1357
+ * @returns The rotated quaternion.
1364
1358
  */
1365
- public clone<T extends QuaternionLike = Quaternion>(
1366
- out: T = new Quaternion() as Quaternion & T
1367
- ): T {
1368
- return copy(this, out);
1359
+ public rotateX(r: number): Quaternion {
1360
+ return rotateX(this, r, new Quaternion());
1369
1361
  }
1370
1362
 
1371
1363
  /**
1372
- * Copy the values of another quaternion into this one.
1373
- * @param quaternion - The quaternion to copy.
1374
- * @returns This quaternion.
1364
+ * Rotate this quaternion by the given angle around the Y-axis.
1365
+ * @param r - The angle in radians.
1366
+ * @returns The rotated quaternion.
1375
1367
  */
1376
- public copy(quaternion: QuaternionLike): this {
1377
- return copy(quaternion, this);
1368
+ public rotateY(r: number): Quaternion {
1369
+ return rotateY(this, r, new Quaternion());
1378
1370
  }
1379
1371
 
1380
1372
  /**
1381
- * Add two quaternions of the same size.
1382
- * @param quaternion - The other quaternion.
1383
- * @param out - The quaternion to store the result in.
1384
- * @returns The sum of the quaternions.
1373
+ * Rotate this quaternion by the given angle around the Z-axis.
1374
+ * @param r - The angle in radians.
1375
+ * @returns The rotated quaternion.
1385
1376
  */
1386
- public add<T extends QuaternionLike = Quaternion>(
1387
- quaternion: QuaternionLike,
1388
- out: T = new Quaternion() as Quaternion & T
1389
- ): T {
1390
- return add(this, quaternion, out);
1377
+ public rotateZ(r: number): Quaternion {
1378
+ return rotateZ(this, r, new Quaternion());
1391
1379
  }
1392
1380
 
1393
1381
  /**
1394
1382
  * Scale this quaternion by a scalar.
1395
1383
  * @param scalar - The scalar.
1396
- * @param out - The quaternion to store the result in.
1397
1384
  * @returns The scaled quaternion.
1398
1385
  */
1399
- public scale<T extends QuaternionLike = Quaternion>(
1400
- scalar: number,
1401
- out: T = new Quaternion() as Quaternion & T
1402
- ): T {
1403
- return scale(this, scalar, out);
1386
+ public scale(scalar: number): Quaternion {
1387
+ return scale(this, scalar, new Quaternion());
1404
1388
  }
1405
1389
 
1406
1390
  /**
1407
- * Calculate the dot product of this and another quaternion.
1408
- * @param quaternion - The other quaternion.
1409
- * @returns The dot product.
1410
- */
1411
- public dot(quaternion: QuaternionLike): number {
1412
- return dot(this, quaternion);
1413
- }
1414
-
1415
- /**
1416
- * Perform a linear interpolation between this and another quaternion.
1391
+ * Perform a spherical linear interpolation between this and another quaternion.
1417
1392
  * @param quaternion - The other quaternion.
1418
- * @param t - The interpolation amount (in `[0,1]`).
1419
- * @param out - The quaternion to store the result in.
1393
+ * @param t - The interpolation amount in `[0,1]`.
1420
1394
  * @returns The interpolated quaternion.
1395
+ * @see {@link https://en.wikipedia.org/wiki/Slerp | Slerp}
1421
1396
  */
1422
- public lerp<T extends QuaternionLike = Quaternion>(
1423
- quaternion: QuaternionLike,
1424
- t: number,
1425
- out: T = new Quaternion() as Quaternion & T
1426
- ): T {
1427
- return lerp(this, quaternion, t, out);
1428
- }
1429
-
1430
- /** Get the magnitude (length) of this quaternion. */
1431
- public get magnitude(): number {
1432
- return getMagnitude(this);
1433
- }
1434
-
1435
- /** Get the squared magnitude (length) of this quaternion. */
1436
- public get squaredMagnitude(): number {
1437
- return getSquaredMagnitude(this);
1438
- }
1439
-
1440
- /**
1441
- * Normalize this quaternion.
1442
- * @param out - The quaternion to store the result in.
1443
- * @returns The normalized quaternion.
1444
- */
1445
- public normalize<T extends QuaternionLike = Quaternion>(
1446
- out: T = new Quaternion() as Quaternion & T
1447
- ): T {
1448
- return normalize(this, out);
1449
- }
1450
-
1451
- /**
1452
- * Determine whether or not this quaternion is roughly equivalent to another.
1453
- * @param quaternion - The other quaternion.
1454
- * @returns Whether or not the quaternions are equivalent.
1455
- */
1456
- public equals(quaternion: QuaternionLike): boolean {
1457
- return equals(this, quaternion);
1458
- }
1459
-
1460
- /**
1461
- * Determine whether or not this quaternion is exactly equivalent to another.
1462
- * @param quaternion - The other quaternion.
1463
- * @returns Whether or not the quaternions are equivalent.
1464
- */
1465
- public exactEquals(quaternion: QuaternionLike): boolean {
1466
- return exactEquals(this, quaternion);
1397
+ public slerp(quaternion: QuaternionLike, t: number): Quaternion {
1398
+ return slerp(this, quaternion, t, new Quaternion());
1467
1399
  }
1468
1400
 
1469
1401
  /**
@@ -1472,28 +1404,23 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
1472
1404
  * @param b - The second control point.
1473
1405
  * @param quaternion - The other quaternion.
1474
1406
  * @param t - The interpolation amount in `[0,1]`.
1475
- * @param out - The quaternion to store the result in.
1476
1407
  * @returns The interpolated value.
1477
1408
  * @see {@link https://en.wikipedia.org/wiki/Slerp | Slerp}
1478
1409
  */
1479
- public sqlerp<T extends QuaternionLike = Quaternion>(
1410
+ public sqlerp(
1480
1411
  a: QuaternionLike,
1481
1412
  b: QuaternionLike,
1482
1413
  quaternion: QuaternionLike,
1483
- t: number,
1484
- out: T = new Quaternion() as Quaternion & T
1485
- ): T {
1486
- return sqlerp(this, a, b, quaternion, t, out);
1414
+ t: number
1415
+ ): Quaternion {
1416
+ return sqlerp(this, a, b, quaternion, t, new Quaternion());
1487
1417
  }
1488
1418
 
1489
1419
  /**
1490
1420
  * Convert this quaternion to equivalent z-y'-x" (intrinsic) Tait-Bryan angles.
1491
- * @param out - The vector in which to store the Tait-Bryan angles.
1492
1421
  * @returns The Tait-Bryan angles in degrees in roll (z), pitch (y'), yaw (x") order.
1493
1422
  */
1494
- public toEuler<T extends Vector3Like = Vector3>(
1495
- out: T = new Vector3() as Vector3 & T
1496
- ): T {
1497
- return toEuler(this, out);
1423
+ public toEuler(): Vector3 {
1424
+ return toEuler(this, new Vector3());
1498
1425
  }
1499
1426
  }