@lakuna/umath 1.3.8 → 1.4.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 (163) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +2 -0
  3. package/dist/algorithms/approx.d.ts +9 -0
  4. package/dist/algorithms/approx.d.ts.map +1 -0
  5. package/dist/algorithms/approx.js +12 -0
  6. package/dist/algorithms/approx.js.map +1 -0
  7. package/dist/algorithms/approxRelative.d.ts +9 -0
  8. package/dist/algorithms/approxRelative.d.ts.map +1 -0
  9. package/dist/algorithms/approxRelative.js +12 -0
  10. package/dist/algorithms/approxRelative.js.map +1 -0
  11. package/dist/algorithms/combinations.d.ts +2 -1
  12. package/dist/algorithms/combinations.d.ts.map +1 -1
  13. package/dist/algorithms/combinations.js +2 -1
  14. package/dist/algorithms/combinations.js.map +1 -1
  15. package/dist/algorithms/degreesToRadians.d.ts +3 -2
  16. package/dist/algorithms/degreesToRadians.d.ts.map +1 -1
  17. package/dist/algorithms/degreesToRadians.js +5 -3
  18. package/dist/algorithms/degreesToRadians.js.map +1 -1
  19. package/dist/algorithms/factorial.d.ts +2 -1
  20. package/dist/algorithms/factorial.d.ts.map +1 -1
  21. package/dist/algorithms/factorial.js +2 -1
  22. package/dist/algorithms/factorial.js.map +1 -1
  23. package/dist/algorithms/fibonacci.d.ts +2 -1
  24. package/dist/algorithms/fibonacci.d.ts.map +1 -1
  25. package/dist/algorithms/fibonacci.js +6 -2
  26. package/dist/algorithms/fibonacci.js.map +1 -1
  27. package/dist/algorithms/greatestCommonDivisor.d.ts +4 -2
  28. package/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -1
  29. package/dist/algorithms/greatestCommonDivisor.js +5 -2
  30. package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
  31. package/dist/algorithms/hypergeometricPmf.d.ts +3 -2
  32. package/dist/algorithms/hypergeometricPmf.d.ts.map +1 -1
  33. package/dist/algorithms/hypergeometricPmf.js +3 -2
  34. package/dist/algorithms/hypergeometricPmf.js.map +1 -1
  35. package/dist/algorithms/isPrime.d.ts +2 -1
  36. package/dist/algorithms/isPrime.d.ts.map +1 -1
  37. package/dist/algorithms/isPrime.js +2 -1
  38. package/dist/algorithms/isPrime.js.map +1 -1
  39. package/dist/algorithms/permutations.d.ts +2 -1
  40. package/dist/algorithms/permutations.d.ts.map +1 -1
  41. package/dist/algorithms/permutations.js +2 -1
  42. package/dist/algorithms/permutations.js.map +1 -1
  43. package/dist/algorithms/primeFactorization.d.ts +2 -1
  44. package/dist/algorithms/primeFactorization.d.ts.map +1 -1
  45. package/dist/algorithms/primeFactorization.js +4 -4
  46. package/dist/algorithms/primeFactorization.js.map +1 -1
  47. package/dist/algorithms/radiansToDegrees.d.ts +3 -2
  48. package/dist/algorithms/radiansToDegrees.d.ts.map +1 -1
  49. package/dist/algorithms/radiansToDegrees.js +5 -3
  50. package/dist/algorithms/radiansToDegrees.js.map +1 -1
  51. package/dist/algorithms/summation.d.ts +2 -1
  52. package/dist/algorithms/summation.d.ts.map +1 -1
  53. package/dist/algorithms/summation.js +2 -1
  54. package/dist/algorithms/summation.js.map +1 -1
  55. package/dist/linalg/DualQuaternion.d.ts +102 -32
  56. package/dist/linalg/DualQuaternion.d.ts.map +1 -1
  57. package/dist/linalg/DualQuaternion.js +249 -275
  58. package/dist/linalg/DualQuaternion.js.map +1 -1
  59. package/dist/linalg/Matrix.d.ts +14 -10
  60. package/dist/linalg/Matrix.d.ts.map +1 -1
  61. package/dist/linalg/Matrix2.d.ts +74 -51
  62. package/dist/linalg/Matrix2.d.ts.map +1 -1
  63. package/dist/linalg/Matrix2.js +96 -169
  64. package/dist/linalg/Matrix2.js.map +1 -1
  65. package/dist/linalg/Matrix3.d.ts +122 -72
  66. package/dist/linalg/Matrix3.d.ts.map +1 -1
  67. package/dist/linalg/Matrix3.js +205 -358
  68. package/dist/linalg/Matrix3.js.map +1 -1
  69. package/dist/linalg/Matrix4.d.ts +267 -150
  70. package/dist/linalg/Matrix4.d.ts.map +1 -1
  71. package/dist/linalg/Matrix4.js +553 -864
  72. package/dist/linalg/Matrix4.js.map +1 -1
  73. package/dist/linalg/Quaternion.d.ts +252 -34
  74. package/dist/linalg/Quaternion.d.ts.map +1 -1
  75. package/dist/linalg/Quaternion.js +436 -166
  76. package/dist/linalg/Quaternion.js.map +1 -1
  77. package/dist/linalg/SlowMatrix.d.ts +10 -9
  78. package/dist/linalg/SlowMatrix.d.ts.map +1 -1
  79. package/dist/linalg/SlowMatrix.js +10 -9
  80. package/dist/linalg/SlowMatrix.js.map +1 -1
  81. package/dist/linalg/SlowSquareMatrix.d.ts +10 -9
  82. package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
  83. package/dist/linalg/SlowSquareMatrix.js +10 -9
  84. package/dist/linalg/SlowSquareMatrix.js.map +1 -1
  85. package/dist/linalg/SquareMatrix.d.ts +6 -5
  86. package/dist/linalg/SquareMatrix.d.ts.map +1 -1
  87. package/dist/linalg/Vector.d.ts +8 -4
  88. package/dist/linalg/Vector.d.ts.map +1 -1
  89. package/dist/linalg/Vector2.d.ts +82 -31
  90. package/dist/linalg/Vector2.d.ts.map +1 -1
  91. package/dist/linalg/Vector2.js +112 -154
  92. package/dist/linalg/Vector2.js.map +1 -1
  93. package/dist/linalg/Vector3.d.ts +93 -41
  94. package/dist/linalg/Vector3.d.ts.map +1 -1
  95. package/dist/linalg/Vector3.js +171 -282
  96. package/dist/linalg/Vector3.js.map +1 -1
  97. package/dist/linalg/Vector4.d.ts +71 -21
  98. package/dist/linalg/Vector4.d.ts.map +1 -1
  99. package/dist/linalg/Vector4.js +121 -195
  100. package/dist/linalg/Vector4.js.map +1 -1
  101. package/dist/types/AxisAngle.d.ts +4 -1
  102. package/dist/types/AxisAngle.d.ts.map +1 -1
  103. package/dist/types/FieldOfView.d.ts +4 -1
  104. package/dist/types/FieldOfView.d.ts.map +1 -1
  105. package/dist/utility/BigNumber.d.ts +4 -1
  106. package/dist/utility/BigNumber.d.ts.map +1 -1
  107. package/dist/utility/BigNumber.js +4 -1
  108. package/dist/utility/BigNumber.js.map +1 -1
  109. package/dist/utility/MagnitudeError.d.ts +4 -1
  110. package/dist/utility/MagnitudeError.d.ts.map +1 -1
  111. package/dist/utility/MagnitudeError.js +4 -1
  112. package/dist/utility/MagnitudeError.js.map +1 -1
  113. package/dist/utility/MatrixSizeError.d.ts +4 -1
  114. package/dist/utility/MatrixSizeError.d.ts.map +1 -1
  115. package/dist/utility/MatrixSizeError.js +4 -1
  116. package/dist/utility/MatrixSizeError.js.map +1 -1
  117. package/dist/utility/PartialMatrixError.d.ts +4 -1
  118. package/dist/utility/PartialMatrixError.d.ts.map +1 -1
  119. package/dist/utility/PartialMatrixError.js +4 -1
  120. package/dist/utility/PartialMatrixError.js.map +1 -1
  121. package/dist/utility/SingularMatrixError.d.ts +2 -1
  122. package/dist/utility/SingularMatrixError.d.ts.map +1 -1
  123. package/dist/utility/SingularMatrixError.js +2 -1
  124. package/dist/utility/SingularMatrixError.js.map +1 -1
  125. package/dist/utility/epsilon.d.ts +4 -1
  126. package/dist/utility/epsilon.d.ts.map +1 -1
  127. package/dist/utility/epsilon.js +4 -1
  128. package/dist/utility/epsilon.js.map +1 -1
  129. package/package.json +14 -18
  130. package/src/algorithms/approx.ts +12 -0
  131. package/src/algorithms/approxRelative.ts +12 -0
  132. package/src/algorithms/combinations.ts +2 -1
  133. package/src/algorithms/degreesToRadians.ts +6 -3
  134. package/src/algorithms/factorial.ts +3 -1
  135. package/src/algorithms/fibonacci.ts +7 -2
  136. package/src/algorithms/greatestCommonDivisor.ts +9 -4
  137. package/src/algorithms/hypergeometricPmf.ts +3 -2
  138. package/src/algorithms/isPrime.ts +2 -1
  139. package/src/algorithms/permutations.ts +2 -1
  140. package/src/algorithms/primeFactorization.ts +5 -3
  141. package/src/algorithms/radiansToDegrees.ts +6 -3
  142. package/src/algorithms/summation.ts +2 -1
  143. package/src/linalg/DualQuaternion.ts +430 -292
  144. package/src/linalg/Matrix.ts +14 -10
  145. package/src/linalg/Matrix2.ts +143 -185
  146. package/src/linalg/Matrix3.ts +421 -385
  147. package/src/linalg/Matrix4.ts +1147 -952
  148. package/src/linalg/Quaternion.ts +706 -188
  149. package/src/linalg/SlowMatrix.ts +10 -9
  150. package/src/linalg/SlowSquareMatrix.ts +10 -9
  151. package/src/linalg/SquareMatrix.ts +6 -5
  152. package/src/linalg/Vector.ts +8 -4
  153. package/src/linalg/Vector2.ts +146 -173
  154. package/src/linalg/Vector3.ts +293 -326
  155. package/src/linalg/Vector4.ts +227 -215
  156. package/src/types/AxisAngle.ts +4 -1
  157. package/src/types/FieldOfView.ts +4 -1
  158. package/src/utility/BigNumber.ts +6 -3
  159. package/src/utility/MagnitudeError.ts +4 -1
  160. package/src/utility/MatrixSizeError.ts +4 -1
  161. package/src/utility/PartialMatrixError.ts +4 -1
  162. package/src/utility/SingularMatrixError.ts +2 -1
  163. package/src/utility/epsilon.ts +4 -1
@@ -1,25 +1,32 @@
1
1
  import {
2
2
  type Matrix4Like,
3
- getRotation as getMatrix4Rotation,
4
- getTranslation as getMatrix4Translation
3
+ getScaling as matrix4GetScaling
5
4
  } from "./Matrix4.js";
6
5
  import Quaternion, {
7
6
  type QuaternionLike,
8
- createQuaternionLike,
9
7
  rotateX as quaternionRotateX,
10
8
  rotateY as quaternionRotateY,
11
9
  rotateZ as quaternionRotateZ
12
10
  } from "./Quaternion.js";
13
- import Vector3, { type Vector3Like, createVector3Like } from "./Vector3.js";
11
+ import Vector3, {
12
+ type Vector3Like,
13
+ createVector3Like,
14
+ fromValues as vector3FromValues
15
+ } from "./Vector3.js";
14
16
  import {
15
- dot,
16
- getMagnitude,
17
- getSquaredMagnitude,
18
- copy as xetReal
17
+ copy as vector4Copy,
18
+ dot as vector4Dot,
19
+ fromValues as vector4FromValues,
20
+ getMagnitude as vector4GetMagnitude,
21
+ getSquaredMagnitude as vector4GetSquaredMagnitude
19
22
  } from "./Vector4.js";
23
+ import approxRelative from "../algorithms/approxRelative.js";
20
24
  import epsilon from "../utility/epsilon.js";
21
25
 
22
- /** A complex number that is commonly used to describe transformations. */
26
+ /**
27
+ * A complex number that is commonly used to describe transformations.
28
+ * @public
29
+ */
23
30
  export interface DualQuaternionLike extends Record<number, number> {
24
31
  /** The first real component of this dual quaternion. */
25
32
  0: number;
@@ -49,8 +56,10 @@ export interface DualQuaternionLike extends Record<number, number> {
49
56
  /**
50
57
  * Create a dual quaternion-like object.
51
58
  * @returns A dual quaternion-like object.
59
+ * @public
52
60
  */
53
- export const createDualQuaternionLike = () => {
61
+ export const createDualQuaternionLike = (): Float32Array &
62
+ DualQuaternionLike => {
54
63
  return new Float32Array(8) as Float32Array & DualQuaternionLike;
55
64
  };
56
65
 
@@ -66,6 +75,7 @@ export const createDualQuaternionLike = () => {
66
75
  * @param w2 - The fourth dual component.
67
76
  * @param out - The dual quaternion to store the result in.
68
77
  * @returns A new dual quaternion.
78
+ * @public
69
79
  */
70
80
  export const fromValues = <T extends DualQuaternionLike>(
71
81
  x1: number,
@@ -94,28 +104,31 @@ export const fromValues = <T extends DualQuaternionLike>(
94
104
  * @param dualQuaternion - The dual quaternion to copy.
95
105
  * @param out - The dual quaternion to store the result in.
96
106
  * @returns The copy.
107
+ * @public
97
108
  */
98
109
  export const copy = <T extends DualQuaternionLike>(
99
110
  dualQuaternion: DualQuaternionLike,
100
111
  out: T
101
- ): T => {
102
- out[0] = dualQuaternion[0];
103
- out[1] = dualQuaternion[1];
104
- out[2] = dualQuaternion[2];
105
- out[3] = dualQuaternion[3];
106
- out[4] = dualQuaternion[4];
107
- out[5] = dualQuaternion[5];
108
- out[6] = dualQuaternion[6];
109
- out[7] = dualQuaternion[7];
110
- return out;
111
- };
112
+ ): T =>
113
+ fromValues(
114
+ dualQuaternion[0],
115
+ dualQuaternion[1],
116
+ dualQuaternion[2],
117
+ dualQuaternion[3],
118
+ dualQuaternion[4],
119
+ dualQuaternion[5],
120
+ dualQuaternion[6],
121
+ dualQuaternion[7],
122
+ out
123
+ );
112
124
 
113
125
  /**
114
- * Create a dual quaternion from the given quaternion and translation.
115
- * @param quaternion - The quaternion.
116
- * @param translation - The translation.
126
+ * Create a dual quaternion from the given rotation and translation.
127
+ * @param quaternion - The rotation quaternion.
128
+ * @param translation - The translation vector.
117
129
  * @param out - The dual quaternion to store the result in.
118
130
  * @returns The dual quaternion.
131
+ * @public
119
132
  */
120
133
  export const fromRotationTranslation = <T extends DualQuaternionLike>(
121
134
  quaternion: QuaternionLike,
@@ -127,80 +140,148 @@ export const fromRotationTranslation = <T extends DualQuaternionLike>(
127
140
  const z = quaternion[2];
128
141
  const w = quaternion[3];
129
142
 
130
- const ax = translation[0] * 0.5;
131
- const ay = translation[1] * 0.5;
132
- const az = translation[2] * 0.5;
133
-
134
- out[0] = x;
135
- out[1] = y;
136
- out[2] = z;
137
- out[3] = w;
138
- out[4] = ax * w + ay * z - az * y;
139
- out[5] = ay * w + az * x - ax * z;
140
- out[6] = az * w + ax * y - ay * x;
141
- out[7] = -ax * x - ay * y - az * z;
142
- return out;
143
+ const ax = translation[0] / 2;
144
+ const ay = translation[1] / 2;
145
+ const az = translation[2] / 2;
146
+
147
+ return fromValues(
148
+ x,
149
+ y,
150
+ z,
151
+ w,
152
+ ax * w + ay * z - az * y,
153
+ ay * w + az * x - ax * z,
154
+ az * w + ax * y - ay * x,
155
+ -ax * x - ay * y - az * z,
156
+ out
157
+ );
143
158
  };
144
159
 
145
160
  /**
146
161
  * Create a dual quaternion from the given translation.
147
- * @param translation - The translation.
162
+ * @param translation - The translation vector.
148
163
  * @param out - The dual quaternion to store the result in.
149
164
  * @returns The dual quaternion.
165
+ * @public
150
166
  */
151
167
  export const fromTranslation = <T extends DualQuaternionLike>(
152
168
  translation: Vector3Like,
153
169
  out: T
154
- ): T => {
155
- out[0] = 0;
156
- out[1] = 0;
157
- out[2] = 0;
158
- out[3] = 1;
159
- out[4] = translation[0] * 0.5;
160
- out[5] = translation[1] * 0.5;
161
- out[6] = translation[2] * 0.5;
162
- out[7] = 0;
163
- return out;
164
- };
170
+ ): T =>
171
+ fromValues(
172
+ 0,
173
+ 0,
174
+ 0,
175
+ 1,
176
+ translation[0] / 2,
177
+ translation[1] / 2,
178
+ translation[2] / 2,
179
+ 0,
180
+ out
181
+ );
165
182
 
166
183
  /**
167
- * Create a dual quaternion from the given quaternion.
168
- * @param quaternion - The quaternion.
184
+ * Create a dual quaternion from the given rotation.
185
+ * @param quaternion - The rotation quaternion.
169
186
  * @param out - The dual quaternion to store the result in.
170
187
  * @returns The dual quaternion.
188
+ * @public
171
189
  */
172
190
  export const fromRotation = <T extends DualQuaternionLike>(
173
191
  quaternion: QuaternionLike,
174
192
  out: T
175
- ): T => {
176
- out[0] = quaternion[0];
177
- out[1] = quaternion[1];
178
- out[2] = quaternion[2];
179
- out[3] = quaternion[3];
180
- out[4] = 0;
181
- out[5] = 0;
182
- out[6] = 0;
183
- out[7] = 0;
184
- return out;
185
- };
193
+ ): T =>
194
+ fromValues(
195
+ quaternion[0],
196
+ quaternion[1],
197
+ quaternion[2],
198
+ quaternion[3],
199
+ 0,
200
+ 0,
201
+ 0,
202
+ 0,
203
+ out
204
+ );
186
205
 
187
206
  // Used to store intermediary values for some functions.
188
- const rotation = createQuaternionLike();
189
- const translation = createVector3Like();
207
+ const iv3 = createVector3Like();
190
208
 
191
209
  /**
192
- * Create a dual quaternion from the given four-by-four matrix.
210
+ * Create a dual quaternion from the given four-by-four matrix. Equivalent to (but faster than) `fromRotationTranslation(getRotation(matrix, createQuaternionLike()), getTranslation(matrix, createVector3Like()), out)`.
193
211
  * @param matrix - The matrix.
194
212
  * @param out - The dual quaternion to store the result in.
195
213
  * @returns The dual quaternion.
214
+ * @public
196
215
  */
197
216
  export const fromMatrix4 = <T extends DualQuaternionLike>(
198
217
  matrix: Matrix4Like,
199
218
  out: T
200
219
  ): T => {
201
- return fromRotationTranslation(
202
- getMatrix4Rotation(matrix, rotation),
203
- getMatrix4Translation(matrix, translation),
220
+ matrix4GetScaling(matrix, iv3);
221
+
222
+ const is1 = 1 / iv3[0];
223
+ const is2 = 1 / iv3[1];
224
+ const is3 = 1 / iv3[2];
225
+
226
+ const sm11 = matrix[0] * is1;
227
+ const sm12 = matrix[1] * is2;
228
+ const sm13 = matrix[2] * is3;
229
+ const sm21 = matrix[4] * is1;
230
+ const sm22 = matrix[5] * is2;
231
+ const sm23 = matrix[6] * is3;
232
+ const sm31 = matrix[8] * is1;
233
+ const sm32 = matrix[9] * is2;
234
+ const sm33 = matrix[10] * is3;
235
+
236
+ const trace = sm11 + sm22 + sm33;
237
+
238
+ // eslint-disable-next-line init-declarations
239
+ let x;
240
+ // eslint-disable-next-line init-declarations
241
+ let y;
242
+ // eslint-disable-next-line init-declarations
243
+ let z;
244
+ // eslint-disable-next-line init-declarations
245
+ let w;
246
+ if (trace > 0) {
247
+ const s = Math.sqrt(trace + 1) * 2;
248
+ x = (sm23 - sm32) / s;
249
+ y = (sm31 - sm13) / s;
250
+ z = (sm12 - sm21) / s;
251
+ w = 0.25 * s;
252
+ } else if (sm11 > sm22 && sm11 > sm33) {
253
+ const s = Math.sqrt(1 + sm11 - sm22 - sm33) * 2;
254
+ x = 0.25 * s;
255
+ y = (sm12 + sm21) / s;
256
+ z = (sm31 + sm13) / s;
257
+ w = (sm23 - sm32) / s;
258
+ } else if (sm22 > sm33) {
259
+ const s = Math.sqrt(1 + sm22 - sm11 - sm33) * 2;
260
+ x = (sm12 + sm21) / s;
261
+ y = 0.25 * s;
262
+ z = (sm23 + sm32) / s;
263
+ w = (sm31 - sm13) / s;
264
+ } else {
265
+ const s = Math.sqrt(1 + sm33 - sm11 - sm22) * 2;
266
+ x = (sm31 + sm13) / s;
267
+ y = (sm23 + sm32) / s;
268
+ z = 0.25 * s;
269
+ w = (sm12 - sm21) / s;
270
+ }
271
+
272
+ const ax = matrix[12] / 2;
273
+ const ay = matrix[13] / 2;
274
+ const az = matrix[14] / 2;
275
+
276
+ return fromValues(
277
+ x,
278
+ y,
279
+ z,
280
+ w,
281
+ ax * w + ay * z - az * y,
282
+ ay * w + az * x - ax * z,
283
+ az * w + ax * y - ay * x,
284
+ -ax * x - ay * y - az * z,
204
285
  out
205
286
  );
206
287
  };
@@ -209,41 +290,60 @@ export const fromMatrix4 = <T extends DualQuaternionLike>(
209
290
  * Set a dual quaternion to the identity dual quaternion.
210
291
  * @param out - The dual quaternion to store the result in.
211
292
  * @returns The identity dual quaternion.
293
+ * @public
212
294
  */
213
- export const identity = <T extends DualQuaternionLike>(out: T): T => {
214
- out[0] = 0;
215
- out[1] = 0;
216
- out[2] = 0;
217
- out[3] = 1;
218
- out[4] = 0;
219
- out[5] = 0;
220
- out[6] = 0;
221
- out[7] = 0;
222
- return out;
223
- };
295
+ export const identity = <T extends DualQuaternionLike>(out: T): T =>
296
+ fromValues(0, 0, 0, 1, 0, 0, 0, 0, out);
297
+
298
+ /**
299
+ * Get the real part of a dual quaternion.
300
+ * @param dualQuaternion - The dual quaternion.
301
+ * @param out - The quaternion to store the result in.
302
+ * @returns The real part.
303
+ * @public
304
+ */
305
+ export const getReal: <T extends QuaternionLike>(
306
+ dualQuaternion: DualQuaternionLike,
307
+ out: T
308
+ ) => T = vector4Copy;
224
309
 
225
310
  /**
226
311
  * Get the dual part of a dual quaternion.
227
312
  * @param dualQuaternion - The dual quaternion.
228
313
  * @param out - The quaternion to store the result in.
229
314
  * @returns The dual part.
315
+ * @public
230
316
  */
231
317
  export const getDual = <T extends QuaternionLike>(
232
318
  dualQuaternion: DualQuaternionLike,
233
319
  out: T
234
- ): T => {
235
- out[0] = dualQuaternion[4];
236
- out[1] = dualQuaternion[5];
237
- out[2] = dualQuaternion[6];
238
- out[3] = dualQuaternion[7];
239
- return out;
240
- };
320
+ ): T =>
321
+ vector4FromValues(
322
+ dualQuaternion[4],
323
+ dualQuaternion[5],
324
+ dualQuaternion[6],
325
+ dualQuaternion[7],
326
+ out
327
+ );
328
+
329
+ /**
330
+ * Set the real part of a dual quaternion.
331
+ * @param quaternion - The quaternion to set as the real part.
332
+ * @param out - The dual quaternion to store the result in.
333
+ * @returns The dual quaternion.
334
+ * @public
335
+ */
336
+ export const setReal: <T extends DualQuaternionLike>(
337
+ quaternion: QuaternionLike,
338
+ out: T
339
+ ) => T = vector4Copy;
241
340
 
242
341
  /**
243
342
  * Set the dual part of a dual quaternion.
244
343
  * @param quaternion - The quaternion to set as the dual part.
245
344
  * @param out - The dual quaternion to store the result in.
246
345
  * @returns The dual quaternion.
346
+ * @public
247
347
  */
248
348
  export const setDual = <T extends DualQuaternionLike>(
249
349
  quaternion: QuaternionLike,
@@ -260,7 +360,8 @@ export const setDual = <T extends DualQuaternionLike>(
260
360
  * Get the translation of a normalized dual quaternion.
261
361
  * @param dualQuaternion - The dual quaternion.
262
362
  * @param out - The vector to store the result in.
263
- * @returns The translation.
363
+ * @returns The translation vector.
364
+ * @public
264
365
  */
265
366
  export const getTranslation = <T extends Vector3Like>(
266
367
  dualQuaternion: DualQuaternionLike,
@@ -275,10 +376,12 @@ export const getTranslation = <T extends Vector3Like>(
275
376
  const bz = -dualQuaternion[2];
276
377
  const bw = dualQuaternion[3];
277
378
 
278
- out[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;
279
- out[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;
280
- out[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;
281
- return out;
379
+ return vector3FromValues(
380
+ (ax * bw + aw * bx + ay * bz - az * by) * 2,
381
+ (ay * bw + aw * by + az * bx - ax * bz) * 2,
382
+ (az * bw + aw * bz + ax * by - ay * bx) * 2,
383
+ out
384
+ );
282
385
  };
283
386
 
284
387
  /**
@@ -287,6 +390,7 @@ export const getTranslation = <T extends Vector3Like>(
287
390
  * @param vector - The vector.
288
391
  * @param out - The dual quaternion to store the result in.
289
392
  * @returns The translated dual quaternion.
393
+ * @public
290
394
  */
291
395
  export const translate = <T extends DualQuaternionLike>(
292
396
  dualQuaternion: DualQuaternionLike,
@@ -298,24 +402,26 @@ export const translate = <T extends DualQuaternionLike>(
298
402
  const az1 = dualQuaternion[2];
299
403
  const aw1 = dualQuaternion[3];
300
404
 
301
- const bx1 = vector[0] * 0.5;
302
- const by1 = vector[1] * 0.5;
303
- const bz1 = vector[2] * 0.5;
405
+ const bx1 = vector[0] / 2;
406
+ const by1 = vector[1] / 2;
407
+ const bz1 = vector[2] / 2;
304
408
 
305
409
  const ax2 = dualQuaternion[4];
306
410
  const ay2 = dualQuaternion[5];
307
411
  const az2 = dualQuaternion[6];
308
412
  const aw2 = dualQuaternion[7];
309
413
 
310
- out[0] = ax1;
311
- out[1] = ay1;
312
- out[2] = az1;
313
- out[3] = aw1;
314
- out[4] = aw1 * bx1 + ay1 * bz1 - az1 * by1 + ax2;
315
- out[5] = aw1 * by1 + az1 * bx1 - ax1 * bz1 + ay2;
316
- out[6] = aw1 * bz1 + ax1 * by1 - ay1 * bx1 + az2;
317
- out[7] = -ax1 * bx1 - ay1 * by1 - az1 * bz1 + aw2;
318
- return out;
414
+ return fromValues(
415
+ ax1,
416
+ ay1,
417
+ az1,
418
+ aw1,
419
+ aw1 * bx1 + ay1 * bz1 - az1 * by1 + ax2,
420
+ aw1 * by1 + az1 * bx1 - ax1 * bz1 + ay2,
421
+ aw1 * bz1 + ax1 * by1 - ay1 * bx1 + az2,
422
+ -ax1 * bx1 - ay1 * by1 - az1 * bz1 + aw2,
423
+ out
424
+ );
319
425
  };
320
426
 
321
427
  /**
@@ -324,6 +430,7 @@ export const translate = <T extends DualQuaternionLike>(
324
430
  * @param radians - The angle to rotate by in radians.
325
431
  * @param out - The dual quaternion to store the result in.
326
432
  * @returns The rotated dual quaternion.
433
+ * @public
327
434
  */
328
435
  export const rotateX = <T extends DualQuaternionLike>(
329
436
  dualQuaternion: DualQuaternionLike,
@@ -365,6 +472,7 @@ export const rotateX = <T extends DualQuaternionLike>(
365
472
  * @param radians - The angle to rotate by in radians.
366
473
  * @param out - The dual quaternion to store the result in.
367
474
  * @returns The rotated dual quaternion.
475
+ * @public
368
476
  */
369
477
  export const rotateY = <T extends DualQuaternionLike>(
370
478
  dualQuaternion: DualQuaternionLike,
@@ -406,6 +514,7 @@ export const rotateY = <T extends DualQuaternionLike>(
406
514
  * @param radians - The angle to rotate by in radians.
407
515
  * @param out - The dual quaternion to store the result in.
408
516
  * @returns The rotated dual quaternion.
517
+ * @public
409
518
  */
410
519
  export const rotateZ = <T extends DualQuaternionLike>(
411
520
  dualQuaternion: DualQuaternionLike,
@@ -442,11 +551,12 @@ export const rotateZ = <T extends DualQuaternionLike>(
442
551
  };
443
552
 
444
553
  /**
445
- * Multiply a dual quaternion by a quaternion.
446
- * @param dualQuaternion - The dual quaternion.
447
- * @param quaternion - The quaternion.
554
+ * Rotate a dual quaternion by a quaternion (using the quaternion as the multiplicand).
555
+ * @param dualQuaternion - The dual quaternion to rotate.
556
+ * @param quaternion - The quaternion to rotate by.
448
557
  * @param out - The dual quaternion to store the result in.
449
558
  * @returns The rotated dual quaternion.
559
+ * @public
450
560
  */
451
561
  export const rotateByQuaternionAppend = <T extends DualQuaternionLike>(
452
562
  dualQuaternion: DualQuaternionLike,
@@ -481,11 +591,12 @@ export const rotateByQuaternionAppend = <T extends DualQuaternionLike>(
481
591
  };
482
592
 
483
593
  /**
484
- * Multiply a quaternion by a dual quaternion.
485
- * @param quaternion - The quaternion.
486
- * @param dualQuaternion - The dual quaternion.
594
+ * Rotate a dual quaternion by a quaternion (using the quaternion as the multiplier).
595
+ * @param quaternion - The quaternion to rotate by.
596
+ * @param dualQuaternion - The dual quaternion to rotate.
487
597
  * @param out - The dual quaternion to store the result in.
488
598
  * @returns The rotated dual quaternion.
599
+ * @public
489
600
  */
490
601
  export const rotateByQuaternionPrepend = <T extends DualQuaternionLike>(
491
602
  quaternion: QuaternionLike,
@@ -526,6 +637,7 @@ export const rotateByQuaternionPrepend = <T extends DualQuaternionLike>(
526
637
  * @param radians - The angle of the rotation in radians.
527
638
  * @param out - The dual quaternion to store the result in.
528
639
  * @returns A normalized dual quaternion.
640
+ * @public
529
641
  */
530
642
  export const rotateAroundAxis = <T extends DualQuaternionLike>(
531
643
  dualQuaternion: DualQuaternionLike,
@@ -533,18 +645,22 @@ export const rotateAroundAxis = <T extends DualQuaternionLike>(
533
645
  radians: number,
534
646
  out: T
535
647
  ): T => {
536
- if (Math.abs(radians) < 0) {
648
+ // Negligible rotation.
649
+ if (Math.abs(radians) < epsilon) {
537
650
  return copy(dualQuaternion, out);
538
651
  }
539
652
 
540
- const axisLength = Math.hypot(axis[0], axis[1], axis[2]);
653
+ const ax = axis[0];
654
+ const ay = axis[1];
655
+ const az = axis[2];
656
+ const axisLength = Math.sqrt(ax * ax + ay * ay + az * az); // `Math.hypot` is slower.
541
657
 
542
- const r = radians * 0.5;
658
+ const r = radians / 2;
543
659
 
544
660
  const s = Math.sin(r);
545
- const bx = (s * axis[0]) / axisLength;
546
- const by = (s * axis[1]) / axisLength;
547
- const bz = (s * axis[2]) / axisLength;
661
+ const bx = (s * ax) / axisLength;
662
+ const by = (s * ay) / axisLength;
663
+ const bz = (s * az) / axisLength;
548
664
  const bw = Math.cos(r);
549
665
 
550
666
  let x = dualQuaternion[0];
@@ -575,22 +691,24 @@ export const rotateAroundAxis = <T extends DualQuaternionLike>(
575
691
  * @param b - The addend.
576
692
  * @param out - The dual quaternion to store the result in.
577
693
  * @returns The sum.
694
+ * @public
578
695
  */
579
696
  export const add = <T extends DualQuaternionLike>(
580
697
  a: DualQuaternionLike,
581
698
  b: DualQuaternionLike,
582
699
  out: T
583
- ): T => {
584
- out[0] = a[0] + b[0];
585
- out[1] = a[1] + b[1];
586
- out[2] = a[2] + b[2];
587
- out[3] = a[3] + b[3];
588
- out[4] = a[4] + b[4];
589
- out[5] = a[5] + b[5];
590
- out[6] = a[6] + b[6];
591
- out[7] = a[7] + b[7];
592
- return out;
593
- };
700
+ ): T =>
701
+ fromValues(
702
+ a[0] + b[0],
703
+ a[1] + b[1],
704
+ a[2] + b[2],
705
+ a[3] + b[3],
706
+ a[4] + b[4],
707
+ a[5] + b[5],
708
+ a[6] + b[6],
709
+ a[7] + b[7],
710
+ out
711
+ );
594
712
 
595
713
  /**
596
714
  * Multiply two dual quaternions.
@@ -598,6 +716,7 @@ export const add = <T extends DualQuaternionLike>(
598
716
  * @param b - The multiplicand.
599
717
  * @param out - The dual quaternion to store the result in.
600
718
  * @returns The product.
719
+ * @public
601
720
  */
602
721
  export const multiply = <T extends DualQuaternionLike>(
603
722
  a: DualQuaternionLike,
@@ -624,79 +743,91 @@ export const multiply = <T extends DualQuaternionLike>(
624
743
  const bz1 = b[6];
625
744
  const bw1 = b[7];
626
745
 
627
- out[0] = ax0 * bw0 + aw0 * bx0 + ay0 * bz0 - az0 * by0;
628
- out[1] = ay0 * bw0 + aw0 * by0 + az0 * bx0 - ax0 * bz0;
629
- out[2] = az0 * bw0 + aw0 * bz0 + ax0 * by0 - ay0 * bx0;
630
- out[3] = aw0 * bw0 - ax0 * bx0 - ay0 * by0 - az0 * bz0;
631
- out[4] =
746
+ return fromValues(
747
+ ax0 * bw0 + aw0 * bx0 + ay0 * bz0 - az0 * by0,
748
+ ay0 * bw0 + aw0 * by0 + az0 * bx0 - ax0 * bz0,
749
+ az0 * bw0 + aw0 * bz0 + ax0 * by0 - ay0 * bx0,
750
+ aw0 * bw0 - ax0 * bx0 - ay0 * by0 - az0 * bz0,
632
751
  ax0 * bw1 +
633
- aw0 * bx1 +
634
- ay0 * bz1 -
635
- az0 * by1 +
636
- ax1 * bw0 +
637
- aw1 * bx0 +
638
- ay1 * bz0 -
639
- az1 * by0;
640
- out[5] =
752
+ aw0 * bx1 +
753
+ ay0 * bz1 -
754
+ az0 * by1 +
755
+ ax1 * bw0 +
756
+ aw1 * bx0 +
757
+ ay1 * bz0 -
758
+ az1 * by0,
641
759
  ay0 * bw1 +
642
- aw0 * by1 +
643
- az0 * bx1 -
644
- ax0 * bz1 +
645
- ay1 * bw0 +
646
- aw1 * by0 +
647
- az1 * bx0 -
648
- ax1 * bz0;
649
- out[6] =
760
+ aw0 * by1 +
761
+ az0 * bx1 -
762
+ ax0 * bz1 +
763
+ ay1 * bw0 +
764
+ aw1 * by0 +
765
+ az1 * bx0 -
766
+ ax1 * bz0,
650
767
  az0 * bw1 +
651
- aw0 * bz1 +
652
- ax0 * by1 -
653
- ay0 * bx1 +
654
- az1 * bw0 +
655
- aw1 * bz0 +
656
- ax1 * by0 -
657
- ay1 * bx0;
658
- out[7] =
768
+ aw0 * bz1 +
769
+ ax0 * by1 -
770
+ ay0 * bx1 +
771
+ az1 * bw0 +
772
+ aw1 * bz0 +
773
+ ax1 * by0 -
774
+ ay1 * bx0,
659
775
  aw0 * bw1 -
660
- ax0 * bx1 -
661
- ay0 * by1 -
662
- az0 * bz1 +
663
- aw1 * bw0 -
664
- ax1 * bx0 -
665
- ay1 * by0 -
666
- az1 * bz0;
667
- return out;
776
+ ax0 * bx1 -
777
+ ay0 * by1 -
778
+ az0 * bz1 +
779
+ aw1 * bw0 -
780
+ ax1 * bx0 -
781
+ ay1 * by0 -
782
+ az1 * bz0,
783
+ out
784
+ );
668
785
  };
669
786
 
670
787
  /**
671
788
  * Multiply a dual quaternion by a scalar.
672
- * @param dualQuaternion - The multiplicand.
673
- * @param scalar - The multiplier.
789
+ * @param dualQuaternion - The multiplicand (dual quaternion).
790
+ * @param scalar - The multiplier (scalar) to scale the dual quaternion by.
674
791
  * @param out - The dual quaternion to store the result in.
675
- * @returns The sum.
792
+ * @returns The product.
793
+ * @public
676
794
  */
677
795
  export const scale = <T extends DualQuaternionLike>(
678
796
  dualQuaternion: DualQuaternionLike,
679
797
  scalar: number,
680
798
  out: T
681
- ): T => {
682
- out[0] = dualQuaternion[0] * scalar;
683
- out[1] = dualQuaternion[1] * scalar;
684
- out[2] = dualQuaternion[2] * scalar;
685
- out[3] = dualQuaternion[3] * scalar;
686
- out[4] = dualQuaternion[4] * scalar;
687
- out[5] = dualQuaternion[5] * scalar;
688
- out[6] = dualQuaternion[6] * scalar;
689
- out[7] = dualQuaternion[7] * scalar;
690
- return out;
691
- };
799
+ ): T =>
800
+ fromValues(
801
+ dualQuaternion[0] * scalar,
802
+ dualQuaternion[1] * scalar,
803
+ dualQuaternion[2] * scalar,
804
+ dualQuaternion[3] * scalar,
805
+ dualQuaternion[4] * scalar,
806
+ dualQuaternion[5] * scalar,
807
+ dualQuaternion[6] * scalar,
808
+ dualQuaternion[7] * scalar,
809
+ out
810
+ );
811
+
812
+ /**
813
+ * Calculate the dot product of two dual quaternions.
814
+ * @param a - The multiplier.
815
+ * @param b - The multiplicand.
816
+ * @returns The dot product.
817
+ * @see {@link https://en.wikipedia.org/wiki/Dot_product | Dot product}
818
+ * @public
819
+ */
820
+ export const dot: (a: DualQuaternionLike, b: DualQuaternionLike) => number =
821
+ vector4Dot;
692
822
 
693
823
  /**
694
824
  * Perform a linear interpolation between two dual quaternions.
695
825
  * @param a - The first dual quaternion.
696
826
  * @param b - The second dual quaternion.
697
827
  * @param t - The interpolation amount in `[0,1]`.
698
- * @param out - The dual quaternion to store the result in.
828
+ * @param out - The dual quaternion to store the result in. Will not always be normalized (most noticeable when `t === 0.5`).
699
829
  * @returns The interpolated value.
830
+ * @public
700
831
  */
701
832
  export const lerp = <T extends DualQuaternionLike>(
702
833
  a: DualQuaternionLike,
@@ -705,24 +836,46 @@ export const lerp = <T extends DualQuaternionLike>(
705
836
  out: T
706
837
  ): T => {
707
838
  const mt = 1 - t;
708
- const it = dot(a, b) < epsilon ? -t : t;
709
-
710
- out[0] = a[0] * mt + b[0] * it;
711
- out[1] = a[1] * mt + b[1] * it;
712
- out[2] = a[2] * mt + b[2] * it;
713
- out[3] = a[3] * mt + b[3] * it;
714
- out[4] = a[4] * mt + b[4] * it;
715
- out[5] = a[5] * mt + b[5] * it;
716
- out[6] = a[6] * mt + b[6] * it;
717
- out[7] = a[7] * mt + b[7] * it;
718
- return out;
839
+ const it = dot(a, b) < 0 ? -t : t;
840
+
841
+ return fromValues(
842
+ a[0] * mt + b[0] * it,
843
+ a[1] * mt + b[1] * it,
844
+ a[2] * mt + b[2] * it,
845
+ a[3] * mt + b[3] * it,
846
+ a[4] * mt + b[4] * it,
847
+ a[5] * mt + b[5] * it,
848
+ a[6] * mt + b[6] * it,
849
+ a[7] * mt + b[7] * it,
850
+ out
851
+ );
719
852
  };
720
853
 
854
+ /**
855
+ * Calculate the magnitude (length) of a dual quaternion.
856
+ * @param dualQuaternion - The dual quaternion.
857
+ * @returns The magnitude.
858
+ * @public
859
+ */
860
+ export const getMagnitude: (dualQuaternion: DualQuaternionLike) => number =
861
+ vector4GetMagnitude;
862
+
863
+ /**
864
+ * Calculate the squared magnitude (length) of a dual quaternion.
865
+ * @param dualQuaternion - The dual quaternion.
866
+ * @returns The squared magnitude.
867
+ * @public
868
+ */
869
+ export const getSquaredMagnitude: (
870
+ dualQuaternion: DualQuaternionLike
871
+ ) => number = vector4GetSquaredMagnitude;
872
+
721
873
  /**
722
874
  * Calculate the inverse of a dual quaternion. If the dual quaternion is normalized, the conjugate is equivalent and faster to calculate.
723
875
  * @param dualQuaternion - The dual quaternion.
724
876
  * @param out - The dual quaternion to store the result in.
725
877
  * @returns The inverse.
878
+ * @public
726
879
  */
727
880
  export const invert = <T extends DualQuaternionLike>(
728
881
  dualQuaternion: DualQuaternionLike,
@@ -730,15 +883,17 @@ export const invert = <T extends DualQuaternionLike>(
730
883
  ): T => {
731
884
  const sqm = getSquaredMagnitude(dualQuaternion);
732
885
 
733
- out[0] = -dualQuaternion[0] / sqm;
734
- out[1] = -dualQuaternion[1] / sqm;
735
- out[2] = -dualQuaternion[2] / sqm;
736
- out[3] = dualQuaternion[3] / sqm;
737
- out[4] = -dualQuaternion[4] / sqm;
738
- out[5] = -dualQuaternion[5] / sqm;
739
- out[6] = -dualQuaternion[6] / sqm;
740
- out[7] = dualQuaternion[7] / sqm;
741
- return out;
886
+ return fromValues(
887
+ -dualQuaternion[0] / sqm,
888
+ -dualQuaternion[1] / sqm,
889
+ -dualQuaternion[2] / sqm,
890
+ dualQuaternion[3] / sqm,
891
+ -dualQuaternion[4] / sqm,
892
+ -dualQuaternion[5] / sqm,
893
+ -dualQuaternion[6] / sqm,
894
+ dualQuaternion[7] / sqm,
895
+ out
896
+ );
742
897
  };
743
898
 
744
899
  /**
@@ -746,57 +901,64 @@ export const invert = <T extends DualQuaternionLike>(
746
901
  * @param dualQuaternion - The dual quaternion.
747
902
  * @param out - The dual quaternion to store the result in.
748
903
  * @returns The conjugate.
904
+ * @public
749
905
  */
750
906
  export const conjugate = <T extends DualQuaternionLike>(
751
907
  dualQuaternion: DualQuaternionLike,
752
908
  out: T
753
- ): T => {
754
- out[0] = -dualQuaternion[0];
755
- out[1] = -dualQuaternion[1];
756
- out[2] = -dualQuaternion[2];
757
- out[3] = dualQuaternion[3];
758
- out[4] = -dualQuaternion[4];
759
- out[5] = -dualQuaternion[5];
760
- out[6] = -dualQuaternion[6];
761
- out[7] = dualQuaternion[7];
762
- return out;
763
- };
909
+ ): T =>
910
+ fromValues(
911
+ -dualQuaternion[0],
912
+ -dualQuaternion[1],
913
+ -dualQuaternion[2],
914
+ dualQuaternion[3],
915
+ -dualQuaternion[4],
916
+ -dualQuaternion[5],
917
+ -dualQuaternion[6],
918
+ dualQuaternion[7],
919
+ out
920
+ );
764
921
 
765
922
  /**
766
923
  * Normalize a dual quaternion.
767
924
  * @param dualQuaternion - The dual quaternion.
768
925
  * @param out - The dual quaternion to store the result in.
769
926
  * @returns The normalized dual quaternion.
927
+ * @public
770
928
  */
771
929
  export const normalize = <T extends DualQuaternionLike>(
772
930
  dualQuaternion: DualQuaternionLike,
773
931
  out: T
774
932
  ): T => {
775
933
  let magnitude = getSquaredMagnitude(dualQuaternion);
776
- if (magnitude > 0) {
777
- magnitude = Math.sqrt(magnitude);
778
-
779
- const a0 = dualQuaternion[0] / magnitude;
780
- const a1 = dualQuaternion[1] / magnitude;
781
- const a2 = dualQuaternion[2] / magnitude;
782
- const a3 = dualQuaternion[3] / magnitude;
783
- const b0 = dualQuaternion[4];
784
- const b1 = dualQuaternion[5];
785
- const b2 = dualQuaternion[6];
786
- const b3 = dualQuaternion[7];
787
-
788
- const aDotB = a0 * b0 + a1 * b1 + a2 * b2 + a3 * b3;
789
-
790
- out[0] = a0;
791
- out[1] = a1;
792
- out[2] = a2;
793
- out[3] = a3;
794
- out[4] = (b0 - a0 * aDotB) / magnitude;
795
- out[5] = (b1 - a1 * aDotB) / magnitude;
796
- out[6] = (b2 - a2 * aDotB) / magnitude;
797
- out[7] = (b3 - a3 * aDotB) / magnitude;
934
+ if (magnitude <= 0) {
935
+ return out;
798
936
  }
799
- return out;
937
+
938
+ magnitude = Math.sqrt(magnitude);
939
+
940
+ const a0 = dualQuaternion[0] / magnitude;
941
+ const a1 = dualQuaternion[1] / magnitude;
942
+ const a2 = dualQuaternion[2] / magnitude;
943
+ const a3 = dualQuaternion[3] / magnitude;
944
+ const b0 = dualQuaternion[4];
945
+ const b1 = dualQuaternion[5];
946
+ const b2 = dualQuaternion[6];
947
+ const b3 = dualQuaternion[7];
948
+
949
+ const aDotB = a0 * b0 + a1 * b1 + a2 * b2 + a3 * b3;
950
+
951
+ return fromValues(
952
+ a0,
953
+ a1,
954
+ a2,
955
+ a3,
956
+ (b0 - a0 * aDotB) / magnitude,
957
+ (b1 - a1 * aDotB) / magnitude,
958
+ (b2 - a2 * aDotB) / magnitude,
959
+ (b3 - a3 * aDotB) / magnitude,
960
+ out
961
+ );
800
962
  };
801
963
 
802
964
  /**
@@ -804,66 +966,42 @@ export const normalize = <T extends DualQuaternionLike>(
804
966
  * @param a - The first dual quaternion.
805
967
  * @param b - The second dual quaternion.
806
968
  * @returns Whether or not the dual quaternions are equivalent.
969
+ * @public
807
970
  */
808
971
  export const exactEquals = (
809
972
  a: DualQuaternionLike,
810
973
  b: DualQuaternionLike
811
- ): boolean => {
812
- return (
813
- a[0] === b[0] &&
814
- a[1] === b[1] &&
815
- a[2] === b[2] &&
816
- a[3] === b[3] &&
817
- a[4] === b[4] &&
818
- a[5] === b[5] &&
819
- a[6] === b[6] &&
820
- a[7] === b[7]
821
- );
822
- };
974
+ ): boolean =>
975
+ a[0] === b[0] &&
976
+ a[1] === b[1] &&
977
+ a[2] === b[2] &&
978
+ a[3] === b[3] &&
979
+ a[4] === b[4] &&
980
+ a[5] === b[5] &&
981
+ a[6] === b[6] &&
982
+ a[7] === b[7];
823
983
 
824
984
  /**
825
985
  * Determine whether or not two dual quaternions are roughly equivalent.
826
986
  * @param a - The first dual quaternion.
827
987
  * @param b - The second dual quaternion.
828
988
  * @returns Whether or not the dual quaternions are equivalent.
989
+ * @public
829
990
  */
830
- export const equals = (
831
- a: DualQuaternionLike,
832
- b: DualQuaternionLike
833
- ): boolean => {
834
- const a0 = a[0];
835
- const a1 = a[1];
836
- const a2 = a[2];
837
- const a3 = a[3];
838
- const a4 = a[4];
839
- const a5 = a[5];
840
- const a6 = a[6];
841
- const a7 = a[7];
842
-
843
- const b0 = b[0];
844
- const b1 = b[1];
845
- const b2 = b[2];
846
- const b3 = b[3];
847
- const b4 = b[4];
848
- const b5 = b[5];
849
- const b6 = b[6];
850
- const b7 = b[7];
851
-
852
- return (
853
- Math.abs(a0 - b0) <= epsilon * Math.max(1, Math.abs(a0), Math.abs(b0)) &&
854
- Math.abs(a1 - b1) <= epsilon * Math.max(1, Math.abs(a1), Math.abs(b1)) &&
855
- Math.abs(a2 - b2) <= epsilon * Math.max(1, Math.abs(a2), Math.abs(b2)) &&
856
- Math.abs(a3 - b3) <= epsilon * Math.max(1, Math.abs(a3), Math.abs(b3)) &&
857
- Math.abs(a4 - b4) <= epsilon * Math.max(1, Math.abs(a4), Math.abs(b4)) &&
858
- Math.abs(a5 - b5) <= epsilon * Math.max(1, Math.abs(a5), Math.abs(b5)) &&
859
- Math.abs(a6 - b6) <= epsilon * Math.max(1, Math.abs(a6), Math.abs(b6)) &&
860
- Math.abs(a7 - b7) <= epsilon * Math.max(1, Math.abs(a7), Math.abs(b7))
861
- );
862
- };
991
+ export const equals = (a: DualQuaternionLike, b: DualQuaternionLike): boolean =>
992
+ approxRelative(a[0], b[0]) &&
993
+ approxRelative(a[1], b[1]) &&
994
+ approxRelative(a[2], b[2]) &&
995
+ approxRelative(a[3], b[3]) &&
996
+ approxRelative(a[4], b[4]) &&
997
+ approxRelative(a[5], b[5]) &&
998
+ approxRelative(a[6], b[6]) &&
999
+ approxRelative(a[7], b[7]);
863
1000
 
864
1001
  /**
865
1002
  * A complex number that is commonly used to describe transformations.
866
- * @see [Dual quaternion](https://en.wikipedia.org/wiki/Dual_quaternion)
1003
+ * @see {@link https://en.wikipedia.org/wiki/Dual_quaternion | Dual quaternion}
1004
+ * @public
867
1005
  */
868
1006
  export default class DualQuaternion
869
1007
  extends Float32Array
@@ -897,9 +1035,9 @@ export default class DualQuaternion
897
1035
  }
898
1036
 
899
1037
  /**
900
- * Create a dual quaternion from the given quaternion and translation.
901
- * @param q - The quaternion.
902
- * @param t - The translation.
1038
+ * Create a dual quaternion from the given rotation and translation.
1039
+ * @param q - The rotation quaternion.
1040
+ * @param t - The translation vector.
903
1041
  * @param out - The dual quaternion to store the result in.
904
1042
  * @returns The dual quaternion.
905
1043
  */
@@ -915,7 +1053,7 @@ export default class DualQuaternion
915
1053
 
916
1054
  /**
917
1055
  * Create a dual quaternion from the given translation.
918
- * @param t - The translation.
1056
+ * @param t - The translation vector.
919
1057
  * @param out - The dual quaternion to store the result in.
920
1058
  * @returns The dual quaternion.
921
1059
  */
@@ -927,8 +1065,8 @@ export default class DualQuaternion
927
1065
  }
928
1066
 
929
1067
  /**
930
- * Create a dual quaternion from the given quaternion.
931
- * @param q - The quaternion.
1068
+ * Create a dual quaternion from the given rotation.
1069
+ * @param q - The rotation quaternion.
932
1070
  * @param out - The dual quaternion to store the result in.
933
1071
  * @returns The dual quaternion.
934
1072
  */
@@ -954,7 +1092,7 @@ export default class DualQuaternion
954
1092
 
955
1093
  /**
956
1094
  * Create an identity dual quaternion.
957
- * @see [Dual quaternion](https://en.wikipedia.org/wiki/Dual_quaternion)
1095
+ * @see {@link https://en.wikipedia.org/wiki/Dual_quaternion | Dual quaternion}
958
1096
  */
959
1097
  public constructor() {
960
1098
  super(8);
@@ -1021,7 +1159,7 @@ export default class DualQuaternion
1021
1159
  public getReal<T extends QuaternionLike = Quaternion>(
1022
1160
  out: T = new Quaternion() as Quaternion & T
1023
1161
  ): T {
1024
- return xetReal(this, out);
1162
+ return getReal(this, out);
1025
1163
  }
1026
1164
 
1027
1165
  /**
@@ -1029,7 +1167,7 @@ export default class DualQuaternion
1029
1167
  * @param q - The quaternion.
1030
1168
  */
1031
1169
  public setReal(q: QuaternionLike): void {
1032
- xetReal(q, this);
1170
+ setReal(q, this);
1033
1171
  }
1034
1172
 
1035
1173
  /**
@@ -1115,11 +1253,11 @@ export default class DualQuaternion
1115
1253
  }
1116
1254
 
1117
1255
  /**
1118
- * Multiply this dual quaternion by a quaternion.
1256
+ * Rotate this dual quaternion by a quaternion (using the quaternion as the multiplicand).
1119
1257
  * @param q - The quaternion.
1120
1258
  * @param out - The dual quaternion to store the result in.
1121
1259
  * @returns The rotated dual quaternion.
1122
- * @see [Quaternion](https://en.wikipedia.org/wiki/Quaternion)
1260
+ * @see {@link https://en.wikipedia.org/wiki/Quaternion | Quaternion}
1123
1261
  */
1124
1262
  public rotateByQuaternionAppend<
1125
1263
  T extends DualQuaternionLike = DualQuaternion
@@ -1128,11 +1266,11 @@ export default class DualQuaternion
1128
1266
  }
1129
1267
 
1130
1268
  /**
1131
- * Multiply a quaternion by this dual quaternion.
1269
+ * Rotate this dual quaternion by a quaternion (using the quaternion as the multiplier).
1132
1270
  * @param q - The quaternion.
1133
1271
  * @param out - The dual quaternion to store the result in.
1134
1272
  * @returns The rotated dual quaternion.
1135
- * @see [Quaternion](https://en.wikipedia.org/wiki/Quaternion)
1273
+ * @see {@link https://en.wikipedia.org/wiki/Quaternion | Quaternion}
1136
1274
  */
1137
1275
  public rotateByQuaternionPrepend<
1138
1276
  T extends DualQuaternionLike = DualQuaternion
@@ -1198,7 +1336,7 @@ export default class DualQuaternion
1198
1336
  * Calculate the dot product of this and another dual quaternion.
1199
1337
  * @param dq - The other dual quaternion.
1200
1338
  * @returns The dot product.
1201
- * @see [Dot product](https://en.wikipedia.org/wiki/Dot_product)
1339
+ * @see {@link https://en.wikipedia.org/wiki/Dot_product | Dot product}
1202
1340
  */
1203
1341
  public dot(dq: DualQuaternionLike): number {
1204
1342
  return dot(this, dq);