@lakuna/umath 0.0.2 → 0.0.4

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 (147) hide show
  1. package/README.md +41 -1
  2. package/dist/algorithms/combinations.d.ts +2 -0
  3. package/dist/algorithms/combinations.d.ts.map +1 -0
  4. package/dist/algorithms/combinations.js +5 -0
  5. package/dist/algorithms/combinations.js.map +1 -0
  6. package/dist/algorithms/degreesToRadians.d.ts +2 -0
  7. package/dist/algorithms/degreesToRadians.d.ts.map +1 -0
  8. package/dist/algorithms/degreesToRadians.js +4 -0
  9. package/dist/algorithms/degreesToRadians.js.map +1 -0
  10. package/dist/algorithms/factorial.d.ts +2 -0
  11. package/dist/algorithms/factorial.d.ts.map +1 -0
  12. package/dist/algorithms/factorial.js +4 -0
  13. package/dist/algorithms/factorial.js.map +1 -0
  14. package/dist/algorithms/fibonacci.d.ts +2 -0
  15. package/dist/algorithms/fibonacci.d.ts.map +1 -0
  16. package/dist/algorithms/fibonacci.js +9 -0
  17. package/dist/algorithms/fibonacci.js.map +1 -0
  18. package/dist/algorithms/greatestCommonDivisor.d.ts +3 -0
  19. package/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -0
  20. package/dist/algorithms/greatestCommonDivisor.js +13 -0
  21. package/dist/algorithms/greatestCommonDivisor.js.map +1 -0
  22. package/dist/algorithms/isPrime.d.ts +2 -0
  23. package/dist/algorithms/isPrime.d.ts.map +1 -0
  24. package/dist/algorithms/isPrime.js +12 -0
  25. package/dist/algorithms/isPrime.js.map +1 -0
  26. package/dist/algorithms/permutations.d.ts +2 -0
  27. package/dist/algorithms/permutations.d.ts.map +1 -0
  28. package/dist/algorithms/permutations.js +5 -0
  29. package/dist/algorithms/permutations.js.map +1 -0
  30. package/dist/algorithms/primeFactorization.d.ts +2 -0
  31. package/dist/algorithms/primeFactorization.d.ts.map +1 -0
  32. package/dist/algorithms/primeFactorization.js +15 -0
  33. package/dist/algorithms/primeFactorization.js.map +1 -0
  34. package/dist/algorithms/radiansToDegrees.d.ts +2 -0
  35. package/dist/algorithms/radiansToDegrees.d.ts.map +1 -0
  36. package/dist/algorithms/radiansToDegrees.js +4 -0
  37. package/dist/algorithms/radiansToDegrees.js.map +1 -0
  38. package/dist/algorithms/summation.d.ts +2 -0
  39. package/dist/algorithms/summation.d.ts.map +1 -0
  40. package/dist/algorithms/summation.js +7 -0
  41. package/dist/algorithms/summation.js.map +1 -0
  42. package/dist/index.d.ts +28 -1
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +22 -1
  45. package/dist/index.js.map +1 -1
  46. package/dist/linear/DualQuaternion.d.ts +89 -0
  47. package/dist/linear/DualQuaternion.d.ts.map +1 -0
  48. package/dist/linear/DualQuaternion.js +530 -0
  49. package/dist/linear/DualQuaternion.js.map +1 -0
  50. package/dist/linear/Matrix.d.ts +18 -0
  51. package/dist/linear/Matrix.d.ts.map +1 -0
  52. package/dist/linear/Matrix.js +2 -0
  53. package/dist/linear/Matrix.js.map +1 -0
  54. package/dist/linear/Matrix2.d.ts +66 -0
  55. package/dist/linear/Matrix2.d.ts.map +1 -0
  56. package/dist/linear/Matrix2.js +240 -0
  57. package/dist/linear/Matrix2.js.map +1 -0
  58. package/dist/linear/Matrix3.d.ts +91 -0
  59. package/dist/linear/Matrix3.d.ts.map +1 -0
  60. package/dist/linear/Matrix3.js +533 -0
  61. package/dist/linear/Matrix3.js.map +1 -0
  62. package/dist/linear/Matrix4.d.ts +140 -0
  63. package/dist/linear/Matrix4.d.ts.map +1 -0
  64. package/dist/linear/Matrix4.js +1363 -0
  65. package/dist/linear/Matrix4.js.map +1 -0
  66. package/dist/linear/Quaternion.d.ts +80 -0
  67. package/dist/linear/Quaternion.d.ts.map +1 -0
  68. package/dist/linear/Quaternion.js +371 -0
  69. package/dist/linear/Quaternion.js.map +1 -0
  70. package/dist/linear/SquareMatrix.d.ts +7 -0
  71. package/dist/linear/SquareMatrix.d.ts.map +1 -0
  72. package/dist/linear/SquareMatrix.js +2 -0
  73. package/dist/linear/SquareMatrix.js.map +1 -0
  74. package/dist/linear/Vector.d.ts +30 -0
  75. package/dist/linear/Vector.d.ts.map +1 -0
  76. package/dist/linear/Vector.js +2 -0
  77. package/dist/linear/Vector.js.map +1 -0
  78. package/dist/linear/Vector2.d.ts +96 -0
  79. package/dist/linear/Vector2.d.ts.map +1 -0
  80. package/dist/linear/Vector2.js +293 -0
  81. package/dist/linear/Vector2.js.map +1 -0
  82. package/dist/linear/Vector3.d.ts +111 -0
  83. package/dist/linear/Vector3.d.ts.map +1 -0
  84. package/dist/linear/Vector3.js +466 -0
  85. package/dist/linear/Vector3.js.map +1 -0
  86. package/dist/linear/Vector4.d.ts +86 -0
  87. package/dist/linear/Vector4.d.ts.map +1 -0
  88. package/dist/linear/Vector4.js +348 -0
  89. package/dist/linear/Vector4.js.map +1 -0
  90. package/dist/types/AxisAngle.d.ts +6 -0
  91. package/dist/types/AxisAngle.d.ts.map +1 -0
  92. package/dist/types/AxisAngle.js +2 -0
  93. package/dist/types/AxisAngle.js.map +1 -0
  94. package/dist/types/FieldOfView.d.ts +7 -0
  95. package/dist/types/FieldOfView.d.ts.map +1 -0
  96. package/dist/types/FieldOfView.js +2 -0
  97. package/dist/types/FieldOfView.js.map +1 -0
  98. package/dist/types/IntegerRepresentation.d.ts +2 -0
  99. package/dist/types/IntegerRepresentation.d.ts.map +1 -0
  100. package/dist/types/IntegerRepresentation.js +2 -0
  101. package/dist/types/IntegerRepresentation.js.map +1 -0
  102. package/dist/utility/BigNumber.d.ts +15 -0
  103. package/dist/utility/BigNumber.d.ts.map +1 -0
  104. package/dist/utility/BigNumber.js +75 -0
  105. package/dist/utility/BigNumber.js.map +1 -0
  106. package/dist/utility/MagnitudeError.d.ts +4 -0
  107. package/dist/utility/MagnitudeError.d.ts.map +1 -0
  108. package/dist/utility/MagnitudeError.js +6 -0
  109. package/dist/utility/MagnitudeError.js.map +1 -0
  110. package/dist/utility/SingularMatrixError.d.ts +4 -0
  111. package/dist/utility/SingularMatrixError.d.ts.map +1 -0
  112. package/dist/utility/SingularMatrixError.js +6 -0
  113. package/dist/utility/SingularMatrixError.js.map +1 -0
  114. package/dist/utility/epsilon.d.ts +3 -0
  115. package/dist/utility/epsilon.d.ts.map +1 -0
  116. package/dist/utility/epsilon.js +2 -0
  117. package/dist/utility/epsilon.js.map +1 -0
  118. package/package.json +17 -9
  119. package/src/algorithms/combinations.ts +12 -0
  120. package/src/algorithms/degreesToRadians.ts +10 -0
  121. package/src/algorithms/factorial.ts +9 -0
  122. package/src/algorithms/fibonacci.ts +14 -0
  123. package/src/algorithms/greatestCommonDivisor.ts +30 -0
  124. package/src/algorithms/isPrime.ts +20 -0
  125. package/src/algorithms/permutations.ts +12 -0
  126. package/src/algorithms/primeFactorization.ts +21 -0
  127. package/src/algorithms/radiansToDegrees.ts +10 -0
  128. package/src/algorithms/summation.ts +23 -0
  129. package/src/index.ts +28 -1
  130. package/src/linear/DualQuaternion.ts +1213 -0
  131. package/src/linear/Matrix.ts +106 -0
  132. package/src/linear/Matrix2.ts +709 -0
  133. package/src/linear/Matrix3.ts +1194 -0
  134. package/src/linear/Matrix4.ts +2569 -0
  135. package/src/linear/Quaternion.ts +967 -0
  136. package/src/linear/SquareMatrix.ts +27 -0
  137. package/src/linear/Vector.ts +178 -0
  138. package/src/linear/Vector2.ts +979 -0
  139. package/src/linear/Vector3.ts +1320 -0
  140. package/src/linear/Vector4.ts +975 -0
  141. package/src/types/AxisAngle.ts +10 -0
  142. package/src/types/FieldOfView.ts +14 -0
  143. package/src/types/IntegerRepresentation.ts +2 -0
  144. package/src/utility/BigNumber.ts +130 -0
  145. package/src/utility/MagnitudeError.ts +10 -0
  146. package/src/utility/SingularMatrixError.ts +13 -0
  147. package/src/utility/epsilon.ts +2 -0
@@ -0,0 +1,1213 @@
1
+ import Quaternion, { type QuaternionLike, rotateX as quaternionRotateX, rotateY as quaternionRotateY, rotateZ as quaternionRotateZ } from "@lakuna/umath/Quaternion";
2
+ import Vector3, { type Vector3Like } from "@lakuna/umath/Vector3";
3
+ import { copy as xetReal, dot, type Vector4Like, getMagnitude, getSquaredMagnitude } from "@lakuna/umath/Vector4";
4
+ import { getRotation as getMatrix4Rotation, getTranslation as getMatrix4Translation, type Matrix4Like } from "@lakuna/umath/Matrix4";
5
+ import { epsilon } from "@lakuna/umath";
6
+
7
+ /** A complex number that is commonly used to describe transformations. */
8
+ export type DualQuaternionLike = DualQuaternion | [number, number, number, number, number, number, number, number];
9
+
10
+ /**
11
+ * Creates a dual quaternion with the given values.
12
+ * @param x1 The first real component.
13
+ * @param y1 The second real component.
14
+ * @param z1 The third real component.
15
+ * @param w1 The fourth real component.
16
+ * @param x2 The first dual component.
17
+ * @param y2 The second dual component.
18
+ * @param z2 The third dual component.
19
+ * @param w2 The fourth dual component.
20
+ * @param out The dual quaternion to store the result in.
21
+ * @returns A new dual quaternion.
22
+ */
23
+ export function fromValues<T extends DualQuaternionLike>(x1: number, y1: number, z1: number, w1: number, x2: number, y2: number, z2: number, w2: number, out: T): T {
24
+ out[0] = x1;
25
+ out[1] = y1;
26
+ out[2] = z1;
27
+ out[3] = w1;
28
+ out[4] = x2;
29
+ out[5] = y2;
30
+ out[6] = z2;
31
+ out[7] = w2;
32
+ return out;
33
+ }
34
+
35
+ /**
36
+ * Copies the values from one dual quaternion to another.
37
+ * @param dualQuaternion The dual quaternion to copy.
38
+ * @param out The dual quaternion to store the result in.
39
+ * @returns The copy.
40
+ */
41
+ export function copy<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, out: T): T {
42
+ out[0] = dualQuaternion[0];
43
+ out[1] = dualQuaternion[1];
44
+ out[2] = dualQuaternion[2];
45
+ out[3] = dualQuaternion[3];
46
+ out[4] = dualQuaternion[4];
47
+ out[5] = dualQuaternion[5];
48
+ out[6] = dualQuaternion[6];
49
+ out[7] = dualQuaternion[7];
50
+ return out;
51
+ }
52
+
53
+ /**
54
+ * Creates a dual quaternion from the given quaternion and translation.
55
+ * @param quaternion The quaternion.
56
+ * @param translation The translation.
57
+ * @param out The dual quaternion to store the result in.
58
+ * @returns The dual quaternion.
59
+ */
60
+ export function fromRotationTranslation<T extends DualQuaternionLike>(quaternion: QuaternionLike, translation: Vector3Like, out: T): T {
61
+ const x: number = quaternion[0];
62
+ const y: number = quaternion[1];
63
+ const z: number = quaternion[2];
64
+ const w: number = quaternion[3];
65
+
66
+ const ax: number = translation[0] * 0.5;
67
+ const ay: number = translation[1] * 0.5;
68
+ const az: number = translation[2] * 0.5;
69
+
70
+ out[0] = x;
71
+ out[1] = y;
72
+ out[2] = z;
73
+ out[3] = w;
74
+ out[4] = ax * w + ay * z - az * y;
75
+ out[5] = ay * w + az * x - ax * z;
76
+ out[6] = az * w + ax * y - ay * x;
77
+ out[7] = -ax * x - ay * y - az * z;
78
+ return out;
79
+ }
80
+
81
+ /**
82
+ * Creates a dual quaternion from the given translation.
83
+ * @param translation The translation.
84
+ * @param out The dual quaternion to store the result in.
85
+ * @returns The dual quaternion.
86
+ */
87
+ export function fromTranslation<T extends DualQuaternionLike>(translation: Vector3Like, out: T): T {
88
+ out[0] = 0;
89
+ out[1] = 0;
90
+ out[2] = 0;
91
+ out[3] = 0;
92
+ out[4] = translation[0] * 0.5;
93
+ out[5] = translation[1] * 0.5;
94
+ out[6] = translation[2] * 0.5;
95
+ out[7] = 0;
96
+ return out;
97
+ }
98
+
99
+ /**
100
+ * Creates a dual quaternion from the given quaternion.
101
+ * @param quaternion The quaternion.
102
+ * @param out The dual quaternion to store the result in.
103
+ * @returns The dual quaternion.
104
+ */
105
+ export function fromRotation<T extends DualQuaternionLike>(quaternion: QuaternionLike, out: T): T {
106
+ out[0] = quaternion[0];
107
+ out[1] = quaternion[1];
108
+ out[2] = quaternion[2];
109
+ out[3] = quaternion[3];
110
+ out[4] = 0;
111
+ out[5] = 0;
112
+ out[6] = 0;
113
+ out[7] = 0;
114
+ return out;
115
+ }
116
+
117
+ /** A quaternion that is used to store intermediary values for some functions. */
118
+ const rotation: QuaternionLike = new Float32Array(4) as QuaternionLike;
119
+
120
+ /** A vector that is used to store intermediary values for some functions. */
121
+ const translation: Vector3Like = new Float32Array(4) as Vector3Like;
122
+
123
+ /**
124
+ * Creates a dual quaternion from the given four-by-four matrix.
125
+ * @param matrix The matrix.
126
+ * @param out The dual quaternion to store the result in.
127
+ * @returns The dual quaternion.
128
+ */
129
+ export function fromMatrix4<T extends DualQuaternionLike>(matrix: Matrix4Like, out: T): T {
130
+ return fromRotationTranslation(getMatrix4Rotation(matrix, rotation), getMatrix4Translation(matrix, translation), out);
131
+ }
132
+
133
+ /**
134
+ * Sets a dual quaternion to the identity dual quaternion.
135
+ * @param out The dual quaternion to store the result in.
136
+ * @returns The identity dual quaternion.
137
+ */
138
+ export function identity<T extends DualQuaternionLike>(out: T): T {
139
+ out[0] = 0;
140
+ out[1] = 0;
141
+ out[2] = 0;
142
+ out[3] = 1;
143
+ out[4] = 0;
144
+ out[5] = 0;
145
+ out[6] = 0;
146
+ out[7] = 0;
147
+ return out;
148
+ }
149
+
150
+ /**
151
+ * Gets the dual part of a dual quaternion.
152
+ * @param dualQuaternion The dual quaternion.
153
+ * @param out The quaternion to store the result in.
154
+ * @returns The dual part.
155
+ */
156
+ export function getDual<T extends QuaternionLike>(dualQuaternion: DualQuaternionLike, out: T): T {
157
+ out[0] = dualQuaternion[4];
158
+ out[1] = dualQuaternion[5];
159
+ out[2] = dualQuaternion[6];
160
+ out[3] = dualQuaternion[7];
161
+ return out;
162
+ }
163
+
164
+ /**
165
+ * Sets the dual part of a dual quaternion.
166
+ * @param quaternion The quaternion to set as the dual part.
167
+ * @param out The dual quaternion to store the result in.
168
+ * @returns The dual quaternion.
169
+ */
170
+ export function setDual<T extends DualQuaternionLike>(quaternion: QuaternionLike, out: T): T {
171
+ out[4] = quaternion[0];
172
+ out[5] = quaternion[1];
173
+ out[6] = quaternion[2];
174
+ out[7] = quaternion[3];
175
+ return out;
176
+ }
177
+
178
+ /**
179
+ * Gets the translation of a normalized dual quaternion.
180
+ * @param dualQuaternion The dual quaternion.
181
+ * @param out The vector to store the result in.
182
+ * @returns The translation.
183
+ */
184
+ export function getTranslation<T extends Vector3Like>(dualQuaternion: DualQuaternionLike, out: T): T {
185
+ const ax: number = dualQuaternion[4];
186
+ const ay: number = dualQuaternion[5];
187
+ const az: number = dualQuaternion[6];
188
+ const aw: number = dualQuaternion[7];
189
+ const bx: number = -dualQuaternion[0];
190
+ const by: number = -dualQuaternion[1];
191
+ const bz: number = -dualQuaternion[2];
192
+ const bw: number = dualQuaternion[3];
193
+
194
+ out[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;
195
+ out[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;
196
+ out[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;
197
+ return out;
198
+ }
199
+
200
+ /**
201
+ * Translates a dual quaternion by the given vector.
202
+ * @param dualQuaternion The dual quaternion.
203
+ * @param vector The vector.
204
+ * @param out The dual quaternion to store the result in.
205
+ * @returns The translated dual quaternion.
206
+ */
207
+ export function translate<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, vector: Vector3Like, out: T): T {
208
+ const ax1: number = dualQuaternion[0];
209
+ const ay1: number = dualQuaternion[1];
210
+ const az1: number = dualQuaternion[2];
211
+ const aw1: number = dualQuaternion[3];
212
+
213
+ const bx1: number = vector[0] * 0.5;
214
+ const by1: number = vector[1] * 0.5;
215
+ const bz1: number = vector[2] * 0.5;
216
+
217
+ const ax2: number = dualQuaternion[4];
218
+ const ay2: number = dualQuaternion[5];
219
+ const az2: number = dualQuaternion[6];
220
+ const aw2: number = dualQuaternion[7];
221
+
222
+ out[0] = ax1;
223
+ out[1] = ay1;
224
+ out[2] = az1;
225
+ out[3] = aw1;
226
+ out[4] = aw1 * bx1 + ay1 * bz1 - az1 * by1 + ax2;
227
+ out[5] = aw1 * by1 + az1 * bx1 - ax1 * bz1 + ay2;
228
+ out[6] = aw1 * bz1 + ax1 * by1 - ay1 * bx1 + az2;
229
+ out[7] = -ax1 * bx1 - ay1 * by1 - az1 * bz1 + aw2;
230
+ return out;
231
+ }
232
+
233
+ /**
234
+ * Rotates a dual quaternion around the X-axis.
235
+ * @param dualQuaternion The dual quaternion.
236
+ * @param radians The angle to rotate by in radians.
237
+ * @param out The dual quaternion to store the result in.
238
+ * @returns The rotated dual quaternion.
239
+ */
240
+ export function rotateX<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, radians: number, out: T): T {
241
+ let bx = -dualQuaternion[0];
242
+ let by = -dualQuaternion[1];
243
+ let bz = -dualQuaternion[2];
244
+ let bw = dualQuaternion[3];
245
+
246
+ const ax = dualQuaternion[4];
247
+ const ay = dualQuaternion[5];
248
+ const az = dualQuaternion[6];
249
+ const aw = dualQuaternion[7];
250
+
251
+ const ax1 = ax * bw + aw * bx + ay * bz - az * by;
252
+ const ay1 = ay * bw + aw * by + az * bx - ax * bz;
253
+ const az1 = az * bw + aw * bz + ax * by - ay * bx;
254
+ const aw1 = aw * bw - ax * bx - ay * by - az * bz;
255
+
256
+ quaternionRotateX(dualQuaternion as unknown as QuaternionLike, radians, out as unknown as QuaternionLike);
257
+
258
+ bx = out[0];
259
+ by = out[1];
260
+ bz = out[2];
261
+ bw = out[3];
262
+
263
+ out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
264
+ out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
265
+ out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
266
+ out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
267
+ return out;
268
+ }
269
+
270
+ /**
271
+ * Rotates a dual quaternion around the Y-axis.
272
+ * @param dualQuaternion The dual quaternion.
273
+ * @param radians The angle to rotate by in radians.
274
+ * @param out The dual quaternion to store the result in.
275
+ * @returns The rotated dual quaternion.
276
+ */
277
+ export function rotateY<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, radians: number, out: T): T {
278
+ let bx: number = -dualQuaternion[0];
279
+ let by: number = -dualQuaternion[1];
280
+ let bz: number = -dualQuaternion[2];
281
+ let bw: number = dualQuaternion[3];
282
+
283
+ const ax: number = dualQuaternion[4];
284
+ const ay: number = dualQuaternion[5];
285
+ const az: number = dualQuaternion[6];
286
+ const aw: number = dualQuaternion[7];
287
+
288
+ const ax1: number = ax * bw + aw * bx + ay * bz - az * by;
289
+ const ay1: number = ay * bw + aw * by + az * bx - ax * bz;
290
+ const az1: number = az * bw + aw * bz + ax * by - ay * bx;
291
+ const aw1: number = aw * bw - ax * bx - ay * by - az * bz;
292
+
293
+ quaternionRotateY(dualQuaternion as unknown as QuaternionLike, radians, out as unknown as QuaternionLike);
294
+
295
+ bx = out[0];
296
+ by = out[1];
297
+ bz = out[2];
298
+ bw = out[3];
299
+
300
+ out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
301
+ out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
302
+ out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
303
+ out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
304
+ return out;
305
+ }
306
+
307
+ /**
308
+ * Rotates a dual quaternion around the Z-axis.
309
+ * @param dualQuaternion The dual quaternion.
310
+ * @param radians The angle to rotate by in radians.
311
+ * @param out The dual quaternion to store the result in.
312
+ * @returns The rotated dual quaternion.
313
+ */
314
+ export function rotateZ<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, radians: number, out: T): T {
315
+ let bx: number = -dualQuaternion[0];
316
+ let by: number = -dualQuaternion[1];
317
+ let bz: number = -dualQuaternion[2];
318
+ let bw: number = dualQuaternion[3];
319
+
320
+ const ax: number = dualQuaternion[4];
321
+ const ay: number = dualQuaternion[5];
322
+ const az: number = dualQuaternion[6];
323
+ const aw: number = dualQuaternion[7];
324
+
325
+ const ax1: number = ax * bw + aw * bx + ay * bz - az * by;
326
+ const ay1: number = ay * bw + aw * by + az * bx - ax * bz;
327
+ const az1: number = az * bw + aw * bz + ax * by - ay * bx;
328
+ const aw1: number = aw * bw - ax * bx - ay * by - az * bz;
329
+
330
+ quaternionRotateZ(dualQuaternion as unknown as QuaternionLike, radians, out as unknown as QuaternionLike);
331
+
332
+ bx = out[0];
333
+ by = out[1];
334
+ bz = out[2];
335
+ bw = out[3];
336
+
337
+ out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
338
+ out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
339
+ out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
340
+ out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
341
+ return out;
342
+ }
343
+
344
+ /**
345
+ * Multiplies a dual quaternion by a quaternion.
346
+ * @param dualQuaternion The dual quaternion.
347
+ * @param quaternion The quaternion.
348
+ * @param out The dual quaternion to store the result in.
349
+ * @returns The rotated dual quaternion.
350
+ */
351
+ export function rotateByQuaternionAppend<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, quaternion: QuaternionLike, out: T): T {
352
+ const qx: number = quaternion[0];
353
+ const qy: number = quaternion[1];
354
+ const qz: number = quaternion[2];
355
+ const qw: number = quaternion[3];
356
+
357
+ let ax: number = dualQuaternion[0];
358
+ let ay: number = dualQuaternion[1];
359
+ let az: number = dualQuaternion[2];
360
+ let aw: number = dualQuaternion[3];
361
+
362
+ out[0] = ax * qw + aw * qx + ay * qz - az * qy;
363
+ out[1] = ay * qw + aw * qy + az * qx - ax * qz;
364
+ out[2] = az * qw + aw * qz + ax * qy - ay * qx;
365
+ out[3] = aw * qw - ax * qx - ay * qy - az * qz;
366
+
367
+ ax = dualQuaternion[4];
368
+ ay = dualQuaternion[5];
369
+ az = dualQuaternion[6];
370
+ aw = dualQuaternion[7];
371
+
372
+ out[4] = ax * qw + aw * qx + ay * qz - az * qy;
373
+ out[5] = ay * qw + aw * qy + az * qx - ax * qz;
374
+ out[6] = az * qw + aw * qz + ax * qy - ay * qx;
375
+ out[7] = aw * qw - ax * qx - ay * qy - az * qz;
376
+ return out;
377
+ }
378
+
379
+ /**
380
+ * Multiplies a quaternion by a dual quaternion.
381
+ * @param quaternion The quaternion.
382
+ * @param dualQuaternion The dual quaternion.
383
+ * @param out The dual quaternion to store the result in.
384
+ * @returns The rotated dual quaternion.
385
+ */
386
+ export function rotateByQuaternionPrepend<T extends DualQuaternionLike>(quaternion: QuaternionLike, dualQuaternion: DualQuaternionLike, out: T): T {
387
+ const qx: number = quaternion[0];
388
+ const qy: number = quaternion[1];
389
+ const qz: number = quaternion[2];
390
+ const qw: number = quaternion[3];
391
+
392
+ let bx: number = dualQuaternion[0];
393
+ let by: number = dualQuaternion[1];
394
+ let bz: number = dualQuaternion[2];
395
+ let bw: number = dualQuaternion[3];
396
+
397
+ out[0] = qx * bw + qw * bx + qy * bz - qz * by;
398
+ out[1] = qy * bw + qw * by + qz * bx - qx * bz;
399
+ out[2] = qz * bw + qw * bz + qx * by - qy * bx;
400
+ out[3] = qw * bw - qx * bx - qy * by - qz * bz;
401
+
402
+ bx = dualQuaternion[4];
403
+ by = dualQuaternion[5];
404
+ bz = dualQuaternion[6];
405
+ bw = dualQuaternion[7];
406
+
407
+ out[4] = qx * bw + qw * bx + qy * bz - qz * by;
408
+ out[5] = qy * bw + qw * by + qz * bx - qx * bz;
409
+ out[6] = qz * bw + qw * bz + qx * by - qy * bx;
410
+ out[7] = qw * bw - qx * bx - qy * by - qz * bz;
411
+ return out;
412
+ }
413
+
414
+ /**
415
+ * Rotates a dual quaternion around an axis.
416
+ * @param dualQuaternion The dual quaternion.
417
+ * @param axis The axis.
418
+ * @param radians The angle of the rotation in radians.
419
+ * @param out The dual quaternion to store the result in.
420
+ * @returns A normalized dual quaternion.
421
+ */
422
+ export function rotateAroundAxis<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, axis: Vector3Like, radians: number, out: T): T {
423
+ if (Math.abs(radians) < 0) {
424
+ return copy(dualQuaternion, out);
425
+ }
426
+
427
+ const axisLength: number = Math.hypot(axis[0], axis[1], axis[2]);
428
+
429
+ const r: number = radians * 0.5;
430
+
431
+ const s: number = Math.sin(r);
432
+ const bx: number = s * axis[0] / axisLength;
433
+ const by: number = s * axis[1] / axisLength;
434
+ const bz: number = s * axis[2] / axisLength;
435
+ const bw: number = Math.cos(r);
436
+
437
+ let x: number = dualQuaternion[0];
438
+ let y: number = dualQuaternion[1];
439
+ let z: number = dualQuaternion[2];
440
+ let w: number = dualQuaternion[3];
441
+
442
+ out[0] = x * bw + w * bx + y * bz - z * by;
443
+ out[1] = y * bw + w * by + z * bx - x * bz;
444
+ out[2] = z * bw + w * bz + x * by - y * bx;
445
+ out[3] = w * bw - x * bx - y * by - z * bz;
446
+
447
+ x = dualQuaternion[4];
448
+ y = dualQuaternion[5];
449
+ z = dualQuaternion[6];
450
+ w = dualQuaternion[7];
451
+
452
+ out[4] = x * bw + w * bx + y * bz - z * by;
453
+ out[5] = y * bw + w * by + z * bx - x * bz;
454
+ out[6] = z * bw + w * bz + x * by - y * bx;
455
+ out[7] = w * bw - x * bx - y * by - z * bz;
456
+ return out;
457
+ }
458
+
459
+ /**
460
+ * Adds two dual quaternions.
461
+ * @param a The augend.
462
+ * @param b The addend.
463
+ * @param out The dual quaternion to store the result in.
464
+ * @returns The sum.
465
+ */
466
+ export function add<T extends DualQuaternionLike>(a: DualQuaternionLike, b: DualQuaternionLike, out: T): T {
467
+ out[0] = a[0] + b[0];
468
+ out[1] = a[1] + b[1];
469
+ out[2] = a[2] + b[2];
470
+ out[3] = a[3] + b[3];
471
+ out[4] = a[4] + b[4];
472
+ out[5] = a[5] + b[5];
473
+ out[6] = a[6] + b[6];
474
+ out[7] = a[7] + b[7];
475
+ return out;
476
+ }
477
+
478
+ /**
479
+ * Multiplies two dual quaternions.
480
+ * @param a The multiplier.
481
+ * @param b The multiplicand.
482
+ * @param out The dual quaternion to store the result in.
483
+ * @returns The product.
484
+ */
485
+ export function multiply<T extends DualQuaternionLike>(a: DualQuaternionLike, b: DualQuaternionLike, out: T): T {
486
+ const ax0: number = a[0];
487
+ const ay0: number = a[1];
488
+ const az0: number = a[2];
489
+ const aw0: number = a[3];
490
+
491
+ const ax1: number = a[4];
492
+ const ay1: number = a[5];
493
+ const az1: number = a[6];
494
+ const aw1: number = a[7];
495
+
496
+ const bx0: number = b[0];
497
+ const by0: number = b[1];
498
+ const bz0: number = b[2];
499
+ const bw0: number = b[3];
500
+
501
+ const bx1: number = b[4];
502
+ const by1: number = b[5];
503
+ const bz1: number = b[6];
504
+ const bw1: number = b[7];
505
+
506
+ out[0] = ax0 * bw0 + aw0 * bx0 + ay0 * bz0 - az0 * by0;
507
+ out[1] = ay0 * bw0 + aw0 * by0 + az0 * bx0 - ax0 * bz0;
508
+ out[2] = az0 * bw0 + aw0 * bz0 + ax0 * by0 - ay0 * bx0;
509
+ out[3] = aw0 * bw0 - ax0 * bx0 - ay0 * by0 - az0 * bz0;
510
+ out[4] = ax0 * bw1 + aw0 * bx1 + ay0 * bz1 - az0 * by1 + ax1 * bw0 + aw1 * bx0 + ay1 * bz0 - az1 * by0;
511
+ out[5] = ay0 * bw1 + aw0 * by1 + az0 * bx1 - ax0 * bz1 + ay1 * bw0 + aw1 * by0 + az1 * bx0 - ax1 * bz0;
512
+ out[6] = az0 * bw1 + aw0 * bz1 + ax0 * by1 - ay0 * bx1 + az1 * bw0 + aw1 * bz0 + ax1 * by0 - ay1 * bx0;
513
+ out[7] = aw0 * bw1 - ax0 * bx1 - ay0 * by1 - az0 * bz1 + aw1 * bw0 - ax1 * bx0 - ay1 * by0 - az1 * bz0;
514
+ return out;
515
+ }
516
+
517
+ /**
518
+ * Multiplies a dual quaternion by a scalar.
519
+ * @param dualQuaternion The multiplicand.
520
+ * @param scalar The multiplier.
521
+ * @param out The dual quaternion to store the result in.
522
+ * @returns The sum.
523
+ */
524
+ export function scale<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, scalar: number, out: T): T {
525
+ out[0] = dualQuaternion[0] * scalar;
526
+ out[1] = dualQuaternion[1] * scalar;
527
+ out[2] = dualQuaternion[2] * scalar;
528
+ out[3] = dualQuaternion[3] * scalar;
529
+ out[4] = dualQuaternion[4] * scalar;
530
+ out[5] = dualQuaternion[5] * scalar;
531
+ out[6] = dualQuaternion[6] * scalar;
532
+ out[7] = dualQuaternion[7] * scalar;
533
+ return out;
534
+ }
535
+
536
+ /**
537
+ * Performs a linear interpolation between two dual quaternions.
538
+ * @param a The first dual quaternion.
539
+ * @param b The second dual quaternion.
540
+ * @param t The interpolation amount in `[0,1]`.
541
+ * @param out The dual quaternion to store the result in.
542
+ * @returns The interpolated value.
543
+ */
544
+ export function lerp<T extends DualQuaternionLike>(a: DualQuaternionLike, b: DualQuaternionLike, t: number, out: T): T {
545
+ const mt: number = 1 - t;
546
+
547
+ if (dot(a as unknown as Vector4Like, b as unknown as Vector4Like) < epsilon) {
548
+ t = -t;
549
+ }
550
+
551
+ out[0] = a[0] * mt + b[0] * t;
552
+ out[1] = a[1] * mt + b[1] * t;
553
+ out[2] = a[2] * mt + b[2] * t;
554
+ out[3] = a[3] * mt + b[3] * t;
555
+ out[4] = a[4] * mt + b[4] * t;
556
+ out[5] = a[5] * mt + b[5] * t;
557
+ out[6] = a[6] * mt + b[6] * t;
558
+ out[7] = a[7] * mt + b[7] * t;
559
+ return out;
560
+ }
561
+
562
+ /**
563
+ * Calculates the inverse of a dual quaternion. If the dual quaternion is normalized, the conjugate is equivalent and faster to calculate.
564
+ * @param dualQuaternion The dual quaternion.
565
+ * @param out The dual quaternion to store the result in.
566
+ * @returns The inverse.
567
+ */
568
+ export function invert<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, out: T): T {
569
+ const sqm: number = getSquaredMagnitude(dualQuaternion as unknown as Vector4Like);
570
+
571
+ out[0] = -dualQuaternion[0] / sqm;
572
+ out[1] = -dualQuaternion[1] / sqm;
573
+ out[2] = -dualQuaternion[2] / sqm;
574
+ out[3] = dualQuaternion[3] / sqm;
575
+ out[4] = -dualQuaternion[4] / sqm;
576
+ out[5] = -dualQuaternion[5] / sqm;
577
+ out[6] = -dualQuaternion[6] / sqm;
578
+ out[7] = dualQuaternion[7] / sqm;
579
+ return out;
580
+ }
581
+
582
+ /**
583
+ * Calculates the conjugate of a dual quaternion. If the dual quaternion is normalized, this is equivalent to its inverse and faster to calculate.
584
+ * @param dualQuaternion The dual quaternion.
585
+ * @param out The dual quaternion to store the result in.
586
+ * @returns The conjugate.
587
+ */
588
+ export function conjugate<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, out: T): T {
589
+ out[0] = -dualQuaternion[0];
590
+ out[1] = -dualQuaternion[1];
591
+ out[2] = -dualQuaternion[2];
592
+ out[3] = dualQuaternion[3];
593
+ out[4] = -dualQuaternion[4];
594
+ out[5] = -dualQuaternion[5];
595
+ out[6] = -dualQuaternion[6];
596
+ out[7] = dualQuaternion[7];
597
+ return out;
598
+ }
599
+
600
+ /**
601
+ * Normalizes a dual quaternion.
602
+ * @param dualQuaternion The dual quaternion.
603
+ * @param out The dual quaternion to store the result in.
604
+ * @returns The normalized dual quaternion.
605
+ */
606
+ export function normalize<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, out: T): T {
607
+ let magnitude: number = getSquaredMagnitude(dualQuaternion as unknown as Vector4Like);
608
+ if (magnitude > 0) {
609
+ magnitude = Math.sqrt(magnitude);
610
+
611
+ const a0: number = dualQuaternion[0] / magnitude;
612
+ const a1: number = dualQuaternion[1] / magnitude;
613
+ const a2: number = dualQuaternion[2] / magnitude;
614
+ const a3: number = dualQuaternion[3] / magnitude;
615
+ const b0: number = dualQuaternion[4];
616
+ const b1: number = dualQuaternion[5];
617
+ const b2: number = dualQuaternion[6];
618
+ const b3: number = dualQuaternion[7];
619
+
620
+ const a_dot_b: number = a0 * b0 + a1 * b1 + a2 * b2 + a3 * b3;
621
+
622
+ out[0] = a0;
623
+ out[1] = a1;
624
+ out[2] = a2;
625
+ out[3] = a3;
626
+ out[4] = (b0 - a0 * a_dot_b) / magnitude;
627
+ out[5] = (b1 - a1 * a_dot_b) / magnitude;
628
+ out[6] = (b2 - a2 * a_dot_b) / magnitude;
629
+ out[7] = (b3 - a3 * a_dot_b) / magnitude;
630
+ }
631
+ return out;
632
+ }
633
+
634
+ /**
635
+ * Determines whether two dual quaternions are exactly equivalent.
636
+ * @param a The first dual quaternion.
637
+ * @param b The second dual quaternion.
638
+ * @returns Whether the dual quaternions are equivalent.
639
+ */
640
+ export function exactEquals(a: DualQuaternionLike, b: DualQuaternionLike): boolean {
641
+ return a[0] === b[0]
642
+ && a[1] === b[1]
643
+ && a[2] === b[2]
644
+ && a[3] === b[3]
645
+ && a[4] === b[4]
646
+ && a[5] === b[5]
647
+ && a[6] === b[6]
648
+ && a[7] === b[7];
649
+ }
650
+
651
+ /**
652
+ * Determines whether two dual quaternions are roughly equivalent.
653
+ * @param a The first dual quaternion.
654
+ * @param b The second dual quaternion.
655
+ * @returns Whether the dual quaternions are equivalent.
656
+ */
657
+ export function equals(a: DualQuaternionLike, b: DualQuaternionLike): boolean {
658
+ const a0: number = a[0];
659
+ const a1: number = a[1];
660
+ const a2: number = a[2];
661
+ const a3: number = a[3];
662
+ const a4: number = a[4];
663
+ const a5: number = a[5];
664
+ const a6: number = a[6];
665
+ const a7: number = a[7];
666
+
667
+ const b0: number = b[0];
668
+ const b1: number = b[1];
669
+ const b2: number = b[2];
670
+ const b3: number = b[3];
671
+ const b4: number = b[4];
672
+ const b5: number = b[5];
673
+ const b6: number = b[6];
674
+ const b7: number = b[7];
675
+
676
+ return Math.abs(a0 - b0) <= epsilon * Math.max(1, Math.abs(a0), Math.abs(b0))
677
+ && Math.abs(a1 - b1) <= epsilon * Math.max(1, Math.abs(a1), Math.abs(b1))
678
+ && Math.abs(a2 - b2) <= epsilon * Math.max(1, Math.abs(a2), Math.abs(b2))
679
+ && Math.abs(a3 - b3) <= epsilon * Math.max(1, Math.abs(a3), Math.abs(b3))
680
+ && Math.abs(a4 - b4) <= epsilon * Math.max(1, Math.abs(a4), Math.abs(b4))
681
+ && Math.abs(a5 - b5) <= epsilon * Math.max(1, Math.abs(a5), Math.abs(b5))
682
+ && Math.abs(a6 - b6) <= epsilon * Math.max(1, Math.abs(a6), Math.abs(b6))
683
+ && Math.abs(a7 - b7) <= epsilon * Math.max(1, Math.abs(a7), Math.abs(b7));
684
+ }
685
+
686
+ /**
687
+ * A complex number that is commonly used to describe transformations.
688
+ * @see [Dual quaternion](https://en.wikipedia.org/wiki/Dual_quaternion)
689
+ */
690
+ export default class DualQuaternion extends Float32Array {
691
+ /**
692
+ * Creates a dual quaternion with the given values.
693
+ * @param x1 The first real component.
694
+ * @param y1 The second real component.
695
+ * @param z1 The third real component.
696
+ * @param w1 The fourth real component.
697
+ * @param x2 The first dual component.
698
+ * @param y2 The second dual component.
699
+ * @param z2 The third dual component.
700
+ * @param w2 The fourth dual component.
701
+ * @returns A new dual quaternion.
702
+ */
703
+ public static fromValues(x1: number, y1: number, z1: number, w1: number, x2: number, y2: number, z2: number, w2: number): DualQuaternion;
704
+
705
+ /**
706
+ * Creates a dual quaternion with the given values.
707
+ * @param x1 The first real component.
708
+ * @param y1 The second real component.
709
+ * @param z1 The third real component.
710
+ * @param w1 The fourth real component.
711
+ * @param x2 The first dual component.
712
+ * @param y2 The second dual component.
713
+ * @param z2 The third dual component.
714
+ * @param w2 The fourth dual component.
715
+ * @param out The dual quaternion to store the result in.
716
+ * @returns A new dual quaternion.
717
+ */
718
+ public static fromValues<T extends DualQuaternionLike>(x1: number, y1: number, z1: number, w1: number, x2: number, y2: number, z2: number, w2: number, out: T): T;
719
+
720
+ public static fromValues<T extends DualQuaternionLike>(x1: number, y1: number, z1: number, w1: number, x2: number, y2: number, z2: number, w2: number, out: T = new DualQuaternion() as T): T {
721
+ return fromValues(x1, y1, z1, w1, x2, y2, z2, w2, out);
722
+ }
723
+
724
+ /**
725
+ * Creates a dual quaternion from the given quaternion and translation.
726
+ * @param quaternion The quaternion.
727
+ * @param translation The translation.
728
+ * @returns The dual quaternion.
729
+ */
730
+ public static fromRotationTranslation(quaternion: QuaternionLike, translation: Vector3Like): DualQuaternion;
731
+
732
+ /**
733
+ * Creates a dual quaternion from the given quaternion and translation.
734
+ * @param quaternion The quaternion.
735
+ * @param translation The translation.
736
+ * @param out The dual quaternion to store the result in.
737
+ * @returns The dual quaternion.
738
+ */
739
+ public static fromRotationTranslation<T extends DualQuaternionLike>(quaternion: QuaternionLike, translation: Vector3Like, out: T): T;
740
+
741
+ public static fromRotationTranslation<T extends DualQuaternionLike>(quaternion: QuaternionLike, translation: Vector3Like, out: T = new DualQuaternion() as T): T {
742
+ return fromRotationTranslation(quaternion, translation, out);
743
+ }
744
+
745
+ /**
746
+ * Creates a dual quaternion from the given translation.
747
+ * @param translation The translation.
748
+ * @returns The dual quaternion.
749
+ */
750
+ public static fromTranslation(translation: Vector3Like): DualQuaternion;
751
+
752
+ /**
753
+ * Creates a dual quaternion from the given translation.
754
+ * @param translation The translation.
755
+ * @param out The dual quaternion to store the result in.
756
+ * @returns The dual quaternion.
757
+ */
758
+ public static fromTranslation<T extends DualQuaternionLike>(translation: Vector3Like, out: T): T;
759
+
760
+ public static fromTranslation<T extends DualQuaternionLike>(translation: Vector3Like, out: T = new DualQuaternion() as T): T{
761
+ return fromTranslation(translation, out);
762
+ }
763
+
764
+ /**
765
+ * Creates a dual quaternion from the given quaternion.
766
+ * @param quaternion The quaternion.
767
+ * @returns The dual quaternion.
768
+ */
769
+ public static fromRotation(quaternion: QuaternionLike): DualQuaternion;
770
+
771
+ /**
772
+ * Creates a dual quaternion from the given quaternion.
773
+ * @param quaternion The quaternion.
774
+ * @param out The dual quaternion to store the result in.
775
+ * @returns The dual quaternion.
776
+ */
777
+ public static fromRotation<T extends DualQuaternionLike>(quaternion: QuaternionLike, out: T): T;
778
+
779
+ public static fromRotation<T extends DualQuaternionLike>(quaternion: QuaternionLike, out: T = new DualQuaternion() as T): T {
780
+ return fromRotation(quaternion, out);
781
+ }
782
+
783
+ /**
784
+ * Creates a dual quaternion from the given four-by-four matrix.
785
+ * @param matrix The matrix.
786
+ * @returns The dual quaternion.
787
+ */
788
+ public static fromMatrix4(matrix: Matrix4Like): DualQuaternion;
789
+
790
+ /**
791
+ * Creates a dual quaternion from the given four-by-four matrix.
792
+ * @param matrix The matrix.
793
+ * @param out The dual quaternion to store the result in.
794
+ * @returns The dual quaternion.
795
+ */
796
+ public static fromMatrix4<T extends DualQuaternionLike>(matrix: Matrix4Like, out: T): T;
797
+
798
+ public static fromMatrix4<T extends DualQuaternionLike>(matrix: Matrix4Like, out: T = new DualQuaternion() as T): T {
799
+ return fromMatrix4(matrix, out);
800
+ }
801
+
802
+ /**
803
+ * Creates an identity dual quaternion.
804
+ * @see [Dual quaternion](https://en.wikipedia.org/wiki/Dual_quaternion)
805
+ */
806
+ public constructor() {
807
+ super(8);
808
+ this[3] = 1;
809
+ }
810
+
811
+ /**
812
+ * Copies the values from another dual quaternion to this one.
813
+ * @param dualQuaternion The dual quaternion to copy.
814
+ * @returns This dual quaternion.
815
+ */
816
+ public copy(dualQuaternion: DualQuaternionLike): this {
817
+ return copy(dualQuaternion, this);
818
+ }
819
+
820
+ /**
821
+ * Creates a copy of this dual quaternion.
822
+ * @returns The copy.
823
+ */
824
+ public clone(): DualQuaternion;
825
+
826
+ /**
827
+ * Copies the values from this dual quaternion to another one.
828
+ * @param out The dual quaternion to store the result in.
829
+ * @returns The copy.
830
+ */
831
+ public clone<T extends DualQuaternionLike>(out: T): T;
832
+
833
+ public clone<T extends DualQuaternionLike>(out: T = new DualQuaternion() as T): T {
834
+ return copy(this, out);
835
+ }
836
+
837
+ /**
838
+ * Sets this dual quaternion to the identity dual quaternion.
839
+ * @returns The identity dual quaternion.
840
+ */
841
+ public identity(): this {
842
+ return identity(this);
843
+ }
844
+
845
+ /**
846
+ * Gets the real part of this dual quaternion.
847
+ * @returns The real part.
848
+ */
849
+ public getReal(): Quaternion;
850
+
851
+ /**
852
+ * Gets the real part of this dual quaternion.
853
+ * @param out The quaternion to store the result in.
854
+ * @returns The real part.
855
+ */
856
+ public getReal<T extends QuaternionLike>(out: T): T;
857
+
858
+ public getReal<T extends QuaternionLike>(out: T = new Quaternion() as T): T {
859
+ return xetReal(this as unknown as Vector4Like, out as Vector4Like) as T;
860
+ }
861
+
862
+ /**
863
+ * Sets the real part of this dual quaternion.
864
+ * @param quaternion The quaternion.
865
+ */
866
+ public setReal(quaternion: QuaternionLike): void {
867
+ xetReal(quaternion as Vector4Like, this as unknown as Vector4Like);
868
+ }
869
+
870
+ /**
871
+ * Gets the dual part of this dual quaternion.
872
+ * @returns The dual part.
873
+ */
874
+ public getDual(): Quaternion;
875
+
876
+ /**
877
+ * Gets the dual part of this dual quaternion.
878
+ * @param out The quaternion to store the result in.
879
+ * @returns The dual part.
880
+ */
881
+ public getDual<T extends QuaternionLike>(out: T): T;
882
+
883
+ public getDual<T extends QuaternionLike>(out: T = new Quaternion() as T): T {
884
+ return getDual(this, out);
885
+ }
886
+
887
+ /**
888
+ * Sets the real part of this dual quaternion.
889
+ * @param quaternion The quaternion.
890
+ */
891
+ public setDual(quaternion: QuaternionLike): void {
892
+ setDual(quaternion, this);
893
+ }
894
+
895
+ /**
896
+ * Gets the translation of this normalized dual quaternion.
897
+ * @returns The translation.
898
+ */
899
+ public getTranslation(): Vector3;
900
+
901
+ /**
902
+ * Gets the translation of this normalized dual quaternion.
903
+ * @param out The vector to store the result in.
904
+ * @returns The translation.
905
+ */
906
+ public getTranslation<T extends Vector3Like>(out: T): T;
907
+
908
+ public getTranslation<T extends Vector3Like>(out: T = new Vector3() as T): T {
909
+ return getTranslation(this, out);
910
+ }
911
+
912
+ /**
913
+ * Translates this dual quaternion by the given vector.
914
+ * @param vector The vector.
915
+ * @returns The translated dual quaternion.
916
+ */
917
+ public translate(vector: Vector3Like): DualQuaternion;
918
+
919
+ /**
920
+ * Translates this dual quaternion by the given vector.
921
+ * @param vector The vector.
922
+ * @param out The dual quaternion to store the result in.
923
+ * @returns The translated dual quaternion.
924
+ */
925
+ public translate<T extends DualQuaternionLike>(vector: Vector3Like, out: T): T;
926
+
927
+ public translate<T extends DualQuaternionLike>(vector: Vector3Like, out: T = new DualQuaternion() as T): T {
928
+ return translate(this, vector, out);
929
+ }
930
+
931
+ /**
932
+ * Rotates this dual quaternion around the X-axis.
933
+ * @param radians The angle to rotate by in radians.
934
+ * @returns The rotated dual quaternion.
935
+ */
936
+ public rotateX(radians: number): DualQuaternion;
937
+
938
+ /**
939
+ * Rotates this dual quaternion around the X-axis.
940
+ * @param radians The angle to rotate by in radians.
941
+ * @param out The dual quaternion to store the result in.
942
+ * @returns The rotated dual quaternion.
943
+ */
944
+ public rotateX<T extends DualQuaternionLike>(radians: number, out: T): T;
945
+
946
+ public rotateX<T extends DualQuaternionLike>(radians: number, out: T = new DualQuaternion() as T): T {
947
+ return rotateX(this, radians, out);
948
+ }
949
+
950
+ /**
951
+ * Rotates this dual quaternion around the Y-axis.
952
+ * @param radians The angle to rotate by in radians.
953
+ * @returns The rotated dual quaternion.
954
+ */
955
+ public rotateY(radians: number): DualQuaternion;
956
+
957
+ /**
958
+ * Rotates this dual quaternion around the Y-axis.
959
+ * @param radians The angle to rotate by in radians.
960
+ * @param out The dual quaternion to store the result in.
961
+ * @returns The rotated dual quaternion.
962
+ */
963
+ public rotateY<T extends DualQuaternionLike>(radians: number, out: T): T;
964
+
965
+ public rotateY<T extends DualQuaternionLike>(radians: number, out: T = new DualQuaternion() as T): T {
966
+ return rotateY(this, radians, out);
967
+ }
968
+
969
+ /**
970
+ * Rotates this dual quaternion around the Z-axis.
971
+ * @param radians The angle to rotate by in radians.
972
+ * @returns The rotated dual quaternion.
973
+ */
974
+ public rotateZ(radians: number): DualQuaternion;
975
+
976
+ /**
977
+ * Rotates this dual quaternion around the Z-axis.
978
+ * @param radians The angle to rotate by in radians.
979
+ * @param out The dual quaternion to store the result in.
980
+ * @returns The rotated dual quaternion.
981
+ */
982
+ public rotateZ<T extends DualQuaternionLike>(radians: number, out: T): T;
983
+
984
+ public rotateZ<T extends DualQuaternionLike>(radians: number, out: T = new DualQuaternion() as T): T {
985
+ return rotateZ(this, radians, out);
986
+ }
987
+
988
+ /**
989
+ * Multiplies this dual quaternion by a quaternion.
990
+ * @param quaternion The quaternion.
991
+ * @returns The rotated dual quaternion.
992
+ */
993
+ public rotateByQuaternionAppend(quaternion: QuaternionLike): DualQuaternion;
994
+
995
+ /**
996
+ * Multiplies this dual quaternion by a quaternion.
997
+ * @param quaternion The quaternion.
998
+ * @param out The dual quaternion to store the result in.
999
+ * @returns The rotated dual quaternion.
1000
+ */
1001
+ public rotateByQuaternionAppend<T extends DualQuaternionLike>(quaternion: QuaternionLike, out: T): T;
1002
+
1003
+ public rotateByQuaternionAppend<T extends DualQuaternionLike>(quaternion: QuaternionLike, out: T = new DualQuaternion() as T): T {
1004
+ return rotateByQuaternionAppend(this, quaternion, out);
1005
+ }
1006
+
1007
+ /**
1008
+ * Multiplies a quaternion by this dual quaternion.
1009
+ * @param quaternion The quaternion.
1010
+ * @returns The rotated dual quaternion.
1011
+ */
1012
+ public rotateByQuaternionPrepend(quaternion: QuaternionLike): DualQuaternion;
1013
+
1014
+ /**
1015
+ * Multiplies a quaternion by this dual quaternion.
1016
+ * @param quaternion The quaternion.
1017
+ * @param out The dual quaternion to store the result in.
1018
+ * @returns The rotated dual quaternion.
1019
+ */
1020
+ public rotateByQuaternionPrepend<T extends DualQuaternionLike>(quaternion: QuaternionLike, out: T): T;
1021
+
1022
+ public rotateByQuaternionPrepend<T extends DualQuaternionLike>(quaternion: QuaternionLike, out: T = new DualQuaternion() as T): T {
1023
+ return rotateByQuaternionPrepend(quaternion, this, out);
1024
+ }
1025
+
1026
+ /**
1027
+ * Rotates this dual quaternion around an axis.
1028
+ * @param axis The axis.
1029
+ * @param radians The angle of the rotation in radians.
1030
+ * @returns A normalized dual quaternion.
1031
+ */
1032
+ public rotateAroundAxis(axis: Vector3Like, radians: number): DualQuaternion;
1033
+
1034
+ /**
1035
+ * Rotates this dual quaternion around an axis.
1036
+ * @param axis The axis.
1037
+ * @param radians The angle of the rotation in radians.
1038
+ * @param out The dual quaternion to store the result in.
1039
+ * @returns A normalized dual quaternion.
1040
+ */
1041
+ public rotateAroundAxis<T extends DualQuaternionLike>(axis: Vector3Like, radians: number, out: T): T;
1042
+
1043
+ public rotateAroundAxis<T extends DualQuaternionLike>(axis: Vector3Like, radians: number, out: T = new DualQuaternion() as T): T {
1044
+ return rotateAroundAxis(this, axis, radians, out);
1045
+ }
1046
+
1047
+ /**
1048
+ * Adds another dual quaternion to this one.
1049
+ * @param dualQuaternion The other dual quaternion.
1050
+ * @returns The sum.
1051
+ */
1052
+ public add(dualQuaternion: DualQuaternionLike): DualQuaternion;
1053
+
1054
+ /**
1055
+ * Adds another dual quaternion to this one.
1056
+ * @param dualQuaternion The other dual quaternion.
1057
+ * @param out The dual quaternion to store the result in.
1058
+ * @returns The sum.
1059
+ */
1060
+ public add<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, out: T): T;
1061
+
1062
+ public add<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, out: T = new DualQuaternion() as T): T {
1063
+ return add(this, dualQuaternion, out);
1064
+ }
1065
+
1066
+ /**
1067
+ * Multiplies this dual quaternion by another one.
1068
+ * @param dualQuaternion The other dual quaternion.
1069
+ * @returns The product.
1070
+ */
1071
+ public multiply(dualQuaternion: DualQuaternionLike): DualQuaternion;
1072
+
1073
+ /**
1074
+ * Multiplies this dual quaternion by another one.
1075
+ * @param dualQuaternion The other dual quaternion.
1076
+ * @param out The dual quaternion to store the result in.
1077
+ * @returns The product.
1078
+ */
1079
+ public multiply<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, out: T): T;
1080
+
1081
+ public multiply<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, out: T = new DualQuaternion() as T): T {
1082
+ return multiply(this, dualQuaternion, out);
1083
+ }
1084
+
1085
+ /**
1086
+ * Multiplies this dual quaternion by a scalar.
1087
+ * @param scalar The scalar.
1088
+ * @returns The product.
1089
+ */
1090
+ public scale(scalar: number): DualQuaternion;
1091
+
1092
+ /**
1093
+ * Multiplies this dual quaternion by a scalar.
1094
+ * @param scalar The scalar.
1095
+ * @param out The dual quaternion to store the result in.
1096
+ * @returns The product.
1097
+ */
1098
+ public scale<T extends DualQuaternionLike>(scalar: number, out: T): T;
1099
+
1100
+ public scale<T extends DualQuaternionLike>(scalar: number, out: T = new DualQuaternion() as T): T {
1101
+ return scale(this, scalar, out);
1102
+ }
1103
+
1104
+ /**
1105
+ * Calculates the dot product of this and another dual quaternion.
1106
+ * @param dualQuaternion The other dual quaternion.
1107
+ * @returns The dot product.
1108
+ * @see [Dot product](https://en.wikipedia.org/wiki/Dot_product)
1109
+ */
1110
+ public dot(dualQuaternion: DualQuaternionLike): number {
1111
+ return dot(this as unknown as Vector4Like, dualQuaternion as unknown as Vector4Like);
1112
+ }
1113
+
1114
+ /**
1115
+ * Performs a linear interpolation between this and another dual quaternion.
1116
+ * @param dualQuaternion The other dual quaternion.
1117
+ * @param t The interpolation amount in `[0,1]`.
1118
+ * @returns The interpolated value.
1119
+ */
1120
+ public lerp(dualQuaternion: DualQuaternionLike, t: number): DualQuaternion;
1121
+
1122
+ /**
1123
+ * Performs a linear interpolation between this and another dual quaternion.
1124
+ * @param dualQuaternion The other dual quaternion.
1125
+ * @param t The interpolation amount in `[0,1]`.
1126
+ * @param out The dual quaternion to store the result in.
1127
+ * @returns The interpolated value.
1128
+ */
1129
+ public lerp<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, t: number, out: T): T;
1130
+
1131
+ public lerp<T extends DualQuaternionLike>(dualQuaternion: DualQuaternionLike, t: number, out: T = new DualQuaternion() as T): T {
1132
+ return lerp(this, dualQuaternion, t, out);
1133
+ }
1134
+
1135
+ /**
1136
+ * Calculates the inverse of this dual quaternion. If this dual quaternion is normalized, the conjugate is equivalent and faster to calculate.
1137
+ * @returns The inverse.
1138
+ */
1139
+ public invert(): DualQuaternion;
1140
+
1141
+ /**
1142
+ * Calculates the inverse of this dual quaternion. If this dual quaternion is normalized, the conjugate is equivalent and faster to calculate.
1143
+ * @param out The dual quaternion to store the result in.
1144
+ * @returns The inverse.
1145
+ */
1146
+ public invert<T extends DualQuaternionLike>(out: T): T;
1147
+
1148
+ public invert<T extends DualQuaternionLike>(out: T = new DualQuaternion() as T): T {
1149
+ return invert(this, out);
1150
+ }
1151
+
1152
+ /**
1153
+ * Calculates the conjugate of this dual quaternion. If this dual quaternion is normalized, this is equivalent to its inverse and faster to calculate.
1154
+ * @returns The conjugate.
1155
+ */
1156
+ public conjugate(): DualQuaternion;
1157
+
1158
+ /**
1159
+ * Calculates the conjugate of this dual quaternion. If this dual quaternion is normalized, this is equivalent to its inverse and faster to calculate.
1160
+ * @param out The dual quaternion to store the result in.
1161
+ * @returns The conjugate.
1162
+ */
1163
+ public conjugate<T extends DualQuaternionLike>(out: T): T;
1164
+
1165
+ public conjugate<T extends DualQuaternionLike>(out: T = new DualQuaternion() as T): T {
1166
+ return conjugate(this, out);
1167
+ }
1168
+
1169
+ /** The magnitude (length) of this dual quaternion. */
1170
+ public get magnitude(): number {
1171
+ return getMagnitude(this as unknown as Vector4Like);
1172
+ }
1173
+
1174
+ /** The squared magnitude (length) of this dual quaternion. */
1175
+ public get squaredMagnitude(): number {
1176
+ return getSquaredMagnitude(this as unknown as Vector4Like);
1177
+ }
1178
+
1179
+ /**
1180
+ * Normalizes this dual quaternion.
1181
+ * @returns The normalized dual quaternion.
1182
+ */
1183
+ public normalize(): DualQuaternion;
1184
+
1185
+ /**
1186
+ * Normalizes this dual quaternion.
1187
+ * @param out The dual quaternion to store the result in.
1188
+ * @returns The normalized dual quaternion.
1189
+ */
1190
+ public normalize<T extends DualQuaternionLike>(out: T): T;
1191
+
1192
+ public normalize<T extends DualQuaternionLike>(out: T = new DualQuaternion() as T): T {
1193
+ return normalize(this, out);
1194
+ }
1195
+
1196
+ /**
1197
+ * Determines whether this dual quaternion is exactly equivalent to another.
1198
+ * @param dualQuaternion The other dual quaternion.
1199
+ * @returns Whether the dual quaternions are equivalent.
1200
+ */
1201
+ public exactEquals(dualQuaternion: DualQuaternionLike): boolean {
1202
+ return exactEquals(this, dualQuaternion);
1203
+ }
1204
+
1205
+ /**
1206
+ * Determines whether this dual quaternion is roughly equivalent to another.
1207
+ * @param dualQuaternion The other dual quaternion.
1208
+ * @returns Whether the dual quaternions are equivalent.
1209
+ */
1210
+ public equals(dualQuaternion: DualQuaternionLike): boolean {
1211
+ return equals(this, dualQuaternion);
1212
+ }
1213
+ }