@math.gl/core 4.0.0 → 4.1.0-alpha.1

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/dist/classes/base/math-array.d.ts +1 -2
  2. package/dist/classes/base/math-array.js +223 -266
  3. package/dist/classes/base/matrix.d.ts +1 -2
  4. package/dist/classes/base/matrix.js +56 -53
  5. package/dist/classes/base/vector.d.ts +1 -2
  6. package/dist/classes/base/vector.js +125 -135
  7. package/dist/classes/euler.d.ts +2 -3
  8. package/dist/classes/euler.js +464 -533
  9. package/dist/classes/matrix3.d.ts +9 -4
  10. package/dist/classes/matrix3.js +191 -190
  11. package/dist/classes/matrix4.d.ts +8 -4
  12. package/dist/classes/matrix4.js +521 -452
  13. package/dist/classes/pose.d.ts +4 -5
  14. package/dist/classes/pose.js +106 -119
  15. package/dist/classes/quaternion.d.ts +1 -2
  16. package/dist/classes/quaternion.js +261 -233
  17. package/dist/classes/spherical-coordinates.d.ts +3 -4
  18. package/dist/classes/spherical-coordinates.js +142 -147
  19. package/dist/classes/vector2.d.ts +6 -5
  20. package/dist/classes/vector2.js +103 -85
  21. package/dist/classes/vector3.d.ts +6 -5
  22. package/dist/classes/vector3.js +129 -136
  23. package/dist/classes/vector4.d.ts +7 -6
  24. package/dist/classes/vector4.js +108 -114
  25. package/dist/gl-matrix/common.d.ts +0 -1
  26. package/dist/gl-matrix/common.js +38 -6
  27. package/dist/gl-matrix/mat3.d.ts +0 -1
  28. package/dist/gl-matrix/mat3.js +699 -425
  29. package/dist/gl-matrix/mat4.d.ts +0 -1
  30. package/dist/gl-matrix/mat4.js +1879 -1339
  31. package/dist/gl-matrix/quat.d.ts +0 -1
  32. package/dist/gl-matrix/quat.js +655 -257
  33. package/dist/gl-matrix/vec2.d.ts +0 -1
  34. package/dist/gl-matrix/vec2.js +529 -212
  35. package/dist/gl-matrix/vec3.d.ts +0 -1
  36. package/dist/gl-matrix/vec3.js +703 -335
  37. package/dist/gl-matrix/vec4.d.ts +0 -1
  38. package/dist/gl-matrix/vec4.js +579 -293
  39. package/dist/gl-matrix/wip/index.d.ts +3 -4
  40. package/dist/gl-matrix/wip/index.js +5 -1
  41. package/dist/gl-matrix/wip/mat2.d.ts +1 -2
  42. package/dist/gl-matrix/wip/mat2.js +336 -157
  43. package/dist/gl-matrix/wip/mat2d.d.ts +0 -1
  44. package/dist/gl-matrix/wip/mat2d.js +380 -202
  45. package/dist/gl-matrix/wip/quat2.d.ts +0 -1
  46. package/dist/gl-matrix/wip/quat2.js +650 -409
  47. package/dist/index.cjs +60 -100
  48. package/dist/index.cjs.map +7 -0
  49. package/dist/index.d.ts +27 -23
  50. package/dist/index.js +25 -16
  51. package/dist/lib/assert.d.ts +0 -1
  52. package/dist/lib/assert.js +6 -4
  53. package/dist/lib/common.d.ts +2 -3
  54. package/dist/lib/common.js +165 -134
  55. package/dist/lib/gl-matrix-extras.d.ts +0 -1
  56. package/dist/lib/gl-matrix-extras.js +42 -36
  57. package/dist/lib/math-utils.d.ts +0 -1
  58. package/dist/lib/math-utils.js +5 -1
  59. package/dist/lib/validators.d.ts +0 -1
  60. package/dist/lib/validators.js +25 -25
  61. package/package.json +5 -6
  62. package/src/classes/base/math-array.ts +4 -1
  63. package/src/classes/base/matrix.ts +4 -1
  64. package/src/classes/base/vector.ts +4 -1
  65. package/src/classes/euler.ts +4 -1
  66. package/src/classes/matrix3.ts +12 -3
  67. package/src/classes/matrix4.ts +11 -3
  68. package/src/classes/pose.ts +4 -1
  69. package/src/classes/quaternion.ts +4 -1
  70. package/src/classes/spherical-coordinates.ts +4 -1
  71. package/src/classes/vector2.ts +11 -4
  72. package/src/classes/vector3.ts +10 -4
  73. package/src/classes/vector4.ts +9 -4
  74. package/src/gl-matrix/wip/index.js +4 -0
  75. package/src/gl-matrix/wip/mat2.js +4 -0
  76. package/src/gl-matrix/wip/mat2d.js +4 -0
  77. package/src/gl-matrix/wip/quat2.ts +4 -0
  78. package/src/index.ts +10 -2
  79. package/src/lib/assert.ts +4 -0
  80. package/src/lib/common.ts +3 -1
  81. package/src/lib/gl-matrix-extras.ts +4 -0
  82. package/src/lib/gl-matrix.d.ts +4 -0
  83. package/src/lib/math-utils.ts +4 -0
  84. package/src/lib/validators.ts +4 -19
  85. package/dist/classes/base/math-array.d.ts.map +0 -1
  86. package/dist/classes/base/math-array.js.map +0 -1
  87. package/dist/classes/base/matrix.d.ts.map +0 -1
  88. package/dist/classes/base/matrix.js.map +0 -1
  89. package/dist/classes/base/vector.d.ts.map +0 -1
  90. package/dist/classes/base/vector.js.map +0 -1
  91. package/dist/classes/euler.d.ts.map +0 -1
  92. package/dist/classes/euler.js.map +0 -1
  93. package/dist/classes/matrix3.d.ts.map +0 -1
  94. package/dist/classes/matrix3.js.map +0 -1
  95. package/dist/classes/matrix4.d.ts.map +0 -1
  96. package/dist/classes/matrix4.js.map +0 -1
  97. package/dist/classes/pose.d.ts.map +0 -1
  98. package/dist/classes/pose.js.map +0 -1
  99. package/dist/classes/quaternion.d.ts.map +0 -1
  100. package/dist/classes/quaternion.js.map +0 -1
  101. package/dist/classes/spherical-coordinates.d.ts.map +0 -1
  102. package/dist/classes/spherical-coordinates.js.map +0 -1
  103. package/dist/classes/vector2.d.ts.map +0 -1
  104. package/dist/classes/vector2.js.map +0 -1
  105. package/dist/classes/vector3.d.ts.map +0 -1
  106. package/dist/classes/vector3.js.map +0 -1
  107. package/dist/classes/vector4.d.ts.map +0 -1
  108. package/dist/classes/vector4.js.map +0 -1
  109. package/dist/gl-matrix/common.d.ts.map +0 -1
  110. package/dist/gl-matrix/common.js.map +0 -1
  111. package/dist/gl-matrix/mat3.d.ts.map +0 -1
  112. package/dist/gl-matrix/mat3.js.map +0 -1
  113. package/dist/gl-matrix/mat4.d.ts.map +0 -1
  114. package/dist/gl-matrix/mat4.js.map +0 -1
  115. package/dist/gl-matrix/quat.d.ts.map +0 -1
  116. package/dist/gl-matrix/quat.js.map +0 -1
  117. package/dist/gl-matrix/vec2.d.ts.map +0 -1
  118. package/dist/gl-matrix/vec2.js.map +0 -1
  119. package/dist/gl-matrix/vec3.d.ts.map +0 -1
  120. package/dist/gl-matrix/vec3.js.map +0 -1
  121. package/dist/gl-matrix/vec4.d.ts.map +0 -1
  122. package/dist/gl-matrix/vec4.js.map +0 -1
  123. package/dist/gl-matrix/wip/index.d.ts.map +0 -1
  124. package/dist/gl-matrix/wip/index.js.map +0 -1
  125. package/dist/gl-matrix/wip/mat2.d.ts.map +0 -1
  126. package/dist/gl-matrix/wip/mat2.js.map +0 -1
  127. package/dist/gl-matrix/wip/mat2d.d.ts.map +0 -1
  128. package/dist/gl-matrix/wip/mat2d.js.map +0 -1
  129. package/dist/gl-matrix/wip/quat2.d.ts.map +0 -1
  130. package/dist/gl-matrix/wip/quat2.js.map +0 -1
  131. package/dist/gl-matrix/wip/types.d.js +0 -2
  132. package/dist/gl-matrix/wip/types.d.js.map +0 -1
  133. package/dist/index.d.ts.map +0 -1
  134. package/dist/index.js.map +0 -1
  135. package/dist/lib/assert.d.ts.map +0 -1
  136. package/dist/lib/assert.js.map +0 -1
  137. package/dist/lib/common.d.ts.map +0 -1
  138. package/dist/lib/common.js.map +0 -1
  139. package/dist/lib/gl-matrix-extras.d.ts.map +0 -1
  140. package/dist/lib/gl-matrix-extras.js.map +0 -1
  141. package/dist/lib/gl-matrix.d.js +0 -2
  142. package/dist/lib/gl-matrix.d.js.map +0 -1
  143. package/dist/lib/math-utils.d.ts.map +0 -1
  144. package/dist/lib/math-utils.js.map +0 -1
  145. package/dist/lib/validators.d.ts.map +0 -1
  146. package/dist/lib/validators.js.map +0 -1
  147. package/src/gl-matrix/wip/types.d.ts +0 -93
@@ -1,482 +1,723 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // @ts-nocheck
5
+ /* eslint-disable */
1
6
  import * as glMatrix from './common.js';
2
7
  import * as quat from './quat.js';
3
8
  import * as mat4 from './mat4.js';
9
+ /**
10
+ * Dual Quaternion<br>
11
+ * Format: [real, dual]<br>
12
+ * Quaternion format: XYZW<br>
13
+ * Make sure to have normalized dual quaternions, otherwise the functions may not work as intended.<br>
14
+ * @module quat2
15
+ */
16
+ /**
17
+ * Creates a new identity dual quat
18
+ *
19
+ * @returns {quat2} a new dual quaternion [real -> rotation, dual -> translation]
20
+ */
4
21
  export function create() {
5
- let dq = new glMatrix.ARRAY_TYPE(8);
6
-
7
- if (glMatrix.ARRAY_TYPE != Float32Array) {
8
- dq[0] = 0;
9
- dq[1] = 0;
10
- dq[2] = 0;
11
- dq[4] = 0;
12
- dq[5] = 0;
13
- dq[6] = 0;
14
- dq[7] = 0;
15
- }
16
-
17
- dq[3] = 1;
18
- return dq;
22
+ let dq = new glMatrix.ARRAY_TYPE(8);
23
+ if (glMatrix.ARRAY_TYPE != Float32Array) {
24
+ dq[0] = 0;
25
+ dq[1] = 0;
26
+ dq[2] = 0;
27
+ dq[4] = 0;
28
+ dq[5] = 0;
29
+ dq[6] = 0;
30
+ dq[7] = 0;
31
+ }
32
+ dq[3] = 1;
33
+ return dq;
19
34
  }
35
+ /**
36
+ * Creates a new quat initialized with values from an existing quaternion
37
+ *
38
+ * @param {ReadonlyQuat2} a dual quaternion to clone
39
+ * @returns {quat2} new dual quaternion
40
+ * @function
41
+ */
20
42
  export function clone(a) {
21
- let dq = new glMatrix.ARRAY_TYPE(8);
22
- dq[0] = a[0];
23
- dq[1] = a[1];
24
- dq[2] = a[2];
25
- dq[3] = a[3];
26
- dq[4] = a[4];
27
- dq[5] = a[5];
28
- dq[6] = a[6];
29
- dq[7] = a[7];
30
- return dq;
43
+ let dq = new glMatrix.ARRAY_TYPE(8);
44
+ dq[0] = a[0];
45
+ dq[1] = a[1];
46
+ dq[2] = a[2];
47
+ dq[3] = a[3];
48
+ dq[4] = a[4];
49
+ dq[5] = a[5];
50
+ dq[6] = a[6];
51
+ dq[7] = a[7];
52
+ return dq;
31
53
  }
54
+ /**
55
+ * Creates a new dual quat initialized with the given values
56
+ *
57
+ * @param {Number} x1 X component
58
+ * @param {Number} y1 Y component
59
+ * @param {Number} z1 Z component
60
+ * @param {Number} w1 W component
61
+ * @param {Number} x2 X component
62
+ * @param {Number} y2 Y component
63
+ * @param {Number} z2 Z component
64
+ * @param {Number} w2 W component
65
+ * @returns {quat2} new dual quaternion
66
+ * @function
67
+ */
32
68
  export function fromValues(x1, y1, z1, w1, x2, y2, z2, w2) {
33
- let dq = new glMatrix.ARRAY_TYPE(8);
34
- dq[0] = x1;
35
- dq[1] = y1;
36
- dq[2] = z1;
37
- dq[3] = w1;
38
- dq[4] = x2;
39
- dq[5] = y2;
40
- dq[6] = z2;
41
- dq[7] = w2;
42
- return dq;
69
+ let dq = new glMatrix.ARRAY_TYPE(8);
70
+ dq[0] = x1;
71
+ dq[1] = y1;
72
+ dq[2] = z1;
73
+ dq[3] = w1;
74
+ dq[4] = x2;
75
+ dq[5] = y2;
76
+ dq[6] = z2;
77
+ dq[7] = w2;
78
+ return dq;
43
79
  }
80
+ /**
81
+ * Creates a new dual quat from the given values (quat and translation)
82
+ *
83
+ * @param {Number} x1 X component
84
+ * @param {Number} y1 Y component
85
+ * @param {Number} z1 Z component
86
+ * @param {Number} w1 W component
87
+ * @param {Number} x2 X component (translation)
88
+ * @param {Number} y2 Y component (translation)
89
+ * @param {Number} z2 Z component (translation)
90
+ * @returns {quat2} new dual quaternion
91
+ * @function
92
+ */
44
93
  export function fromRotationTranslationValues(x1, y1, z1, w1, x2, y2, z2) {
45
- let dq = new glMatrix.ARRAY_TYPE(8);
46
- dq[0] = x1;
47
- dq[1] = y1;
48
- dq[2] = z1;
49
- dq[3] = w1;
50
- let ax = x2 * 0.5,
51
- ay = y2 * 0.5,
52
- az = z2 * 0.5;
53
- dq[4] = ax * w1 + ay * z1 - az * y1;
54
- dq[5] = ay * w1 + az * x1 - ax * z1;
55
- dq[6] = az * w1 + ax * y1 - ay * x1;
56
- dq[7] = -ax * x1 - ay * y1 - az * z1;
57
- return dq;
94
+ let dq = new glMatrix.ARRAY_TYPE(8);
95
+ dq[0] = x1;
96
+ dq[1] = y1;
97
+ dq[2] = z1;
98
+ dq[3] = w1;
99
+ let ax = x2 * 0.5, ay = y2 * 0.5, az = z2 * 0.5;
100
+ dq[4] = ax * w1 + ay * z1 - az * y1;
101
+ dq[5] = ay * w1 + az * x1 - ax * z1;
102
+ dq[6] = az * w1 + ax * y1 - ay * x1;
103
+ dq[7] = -ax * x1 - ay * y1 - az * z1;
104
+ return dq;
58
105
  }
106
+ /**
107
+ * Creates a dual quat from a quaternion and a translation
108
+ *
109
+ * @param {ReadonlyQuat2} dual quaternion receiving operation result
110
+ * @param {ReadonlyQuat} q a normalized quaternion
111
+ * @param {ReadonlyVec3} t translation vector
112
+ * @returns {quat2} dual quaternion receiving operation result
113
+ * @function
114
+ */
59
115
  export function fromRotationTranslation(out, q, t) {
60
- let ax = t[0] * 0.5,
61
- ay = t[1] * 0.5,
62
- az = t[2] * 0.5,
63
- bx = q[0],
64
- by = q[1],
65
- bz = q[2],
66
- bw = q[3];
67
- out[0] = bx;
68
- out[1] = by;
69
- out[2] = bz;
70
- out[3] = bw;
71
- out[4] = ax * bw + ay * bz - az * by;
72
- out[5] = ay * bw + az * bx - ax * bz;
73
- out[6] = az * bw + ax * by - ay * bx;
74
- out[7] = -ax * bx - ay * by - az * bz;
75
- return out;
116
+ let ax = t[0] * 0.5, ay = t[1] * 0.5, az = t[2] * 0.5, bx = q[0], by = q[1], bz = q[2], bw = q[3];
117
+ out[0] = bx;
118
+ out[1] = by;
119
+ out[2] = bz;
120
+ out[3] = bw;
121
+ out[4] = ax * bw + ay * bz - az * by;
122
+ out[5] = ay * bw + az * bx - ax * bz;
123
+ out[6] = az * bw + ax * by - ay * bx;
124
+ out[7] = -ax * bx - ay * by - az * bz;
125
+ return out;
76
126
  }
127
+ /**
128
+ * Creates a dual quat from a translation
129
+ *
130
+ * @param {ReadonlyQuat2} dual quaternion receiving operation result
131
+ * @param {ReadonlyVec3} t translation vector
132
+ * @returns {quat2} dual quaternion receiving operation result
133
+ * @function
134
+ */
77
135
  export function fromTranslation(out, t) {
78
- out[0] = 0;
79
- out[1] = 0;
80
- out[2] = 0;
81
- out[3] = 1;
82
- out[4] = t[0] * 0.5;
83
- out[5] = t[1] * 0.5;
84
- out[6] = t[2] * 0.5;
85
- out[7] = 0;
86
- return out;
136
+ out[0] = 0;
137
+ out[1] = 0;
138
+ out[2] = 0;
139
+ out[3] = 1;
140
+ out[4] = t[0] * 0.5;
141
+ out[5] = t[1] * 0.5;
142
+ out[6] = t[2] * 0.5;
143
+ out[7] = 0;
144
+ return out;
87
145
  }
146
+ /**
147
+ * Creates a dual quat from a quaternion
148
+ *
149
+ * @param {ReadonlyQuat2} dual quaternion receiving operation result
150
+ * @param {ReadonlyQuat} q the quaternion
151
+ * @returns {quat2} dual quaternion receiving operation result
152
+ * @function
153
+ */
88
154
  export function fromRotation(out, q) {
89
- out[0] = q[0];
90
- out[1] = q[1];
91
- out[2] = q[2];
92
- out[3] = q[3];
93
- out[4] = 0;
94
- out[5] = 0;
95
- out[6] = 0;
96
- out[7] = 0;
97
- return out;
155
+ out[0] = q[0];
156
+ out[1] = q[1];
157
+ out[2] = q[2];
158
+ out[3] = q[3];
159
+ out[4] = 0;
160
+ out[5] = 0;
161
+ out[6] = 0;
162
+ out[7] = 0;
163
+ return out;
98
164
  }
165
+ /**
166
+ * Creates a new dual quat from a matrix (4x4)
167
+ *
168
+ * @param {quat2} out the dual quaternion
169
+ * @param {ReadonlyMat4} a the matrix
170
+ * @returns {quat2} dual quat receiving operation result
171
+ * @function
172
+ */
99
173
  export function fromMat4(out, a) {
100
- let outer = quat.create();
101
- mat4.getRotation(outer, a);
102
- let t = new glMatrix.ARRAY_TYPE(3);
103
- mat4.getTranslation(t, a);
104
- fromRotationTranslation(out, outer, t);
105
- return out;
174
+ //TODO Optimize this
175
+ let outer = quat.create();
176
+ mat4.getRotation(outer, a);
177
+ let t = new glMatrix.ARRAY_TYPE(3);
178
+ mat4.getTranslation(t, a);
179
+ fromRotationTranslation(out, outer, t);
180
+ return out;
106
181
  }
182
+ /**
183
+ * Copy the values from one dual quat to another
184
+ *
185
+ * @param {quat2} out the receiving dual quaternion
186
+ * @param {ReadonlyQuat2} a the source dual quaternion
187
+ * @returns {quat2} out
188
+ * @function
189
+ */
107
190
  export function copy(out, a) {
108
- out[0] = a[0];
109
- out[1] = a[1];
110
- out[2] = a[2];
111
- out[3] = a[3];
112
- out[4] = a[4];
113
- out[5] = a[5];
114
- out[6] = a[6];
115
- out[7] = a[7];
116
- return out;
191
+ out[0] = a[0];
192
+ out[1] = a[1];
193
+ out[2] = a[2];
194
+ out[3] = a[3];
195
+ out[4] = a[4];
196
+ out[5] = a[5];
197
+ out[6] = a[6];
198
+ out[7] = a[7];
199
+ return out;
117
200
  }
201
+ /**
202
+ * Set a dual quat to the identity dual quaternion
203
+ *
204
+ * @param {quat2} out the receiving quaternion
205
+ * @returns {quat2} out
206
+ */
118
207
  export function identity(out) {
119
- out[0] = 0;
120
- out[1] = 0;
121
- out[2] = 0;
122
- out[3] = 1;
123
- out[4] = 0;
124
- out[5] = 0;
125
- out[6] = 0;
126
- out[7] = 0;
127
- return out;
208
+ out[0] = 0;
209
+ out[1] = 0;
210
+ out[2] = 0;
211
+ out[3] = 1;
212
+ out[4] = 0;
213
+ out[5] = 0;
214
+ out[6] = 0;
215
+ out[7] = 0;
216
+ return out;
128
217
  }
218
+ /**
219
+ * Set the components of a dual quat to the given values
220
+ *
221
+ * @param {quat2} out the receiving quaternion
222
+ * @param {Number} x1 X component
223
+ * @param {Number} y1 Y component
224
+ * @param {Number} z1 Z component
225
+ * @param {Number} w1 W component
226
+ * @param {Number} x2 X component
227
+ * @param {Number} y2 Y component
228
+ * @param {Number} z2 Z component
229
+ * @param {Number} w2 W component
230
+ * @returns {quat2} out
231
+ * @function
232
+ */
129
233
  export function set(out, x1, y1, z1, w1, x2, y2, z2, w2) {
130
- out[0] = x1;
131
- out[1] = y1;
132
- out[2] = z1;
133
- out[3] = w1;
134
- out[4] = x2;
135
- out[5] = y2;
136
- out[6] = z2;
137
- out[7] = w2;
138
- return out;
234
+ out[0] = x1;
235
+ out[1] = y1;
236
+ out[2] = z1;
237
+ out[3] = w1;
238
+ out[4] = x2;
239
+ out[5] = y2;
240
+ out[6] = z2;
241
+ out[7] = w2;
242
+ return out;
139
243
  }
244
+ /**
245
+ * Gets the real part of a dual quat
246
+ * @param {quat} out real part
247
+ * @param {ReadonlyQuat2} a Dual Quaternion
248
+ * @return {quat} real part
249
+ */
140
250
  export const getReal = quat.copy;
251
+ /**
252
+ * Gets the dual part of a dual quat
253
+ * @param {quat} out dual part
254
+ * @param {ReadonlyQuat2} a Dual Quaternion
255
+ * @return {quat} dual part
256
+ */
141
257
  export function getDual(out, a) {
142
- out[0] = a[4];
143
- out[1] = a[5];
144
- out[2] = a[6];
145
- out[3] = a[7];
146
- return out;
258
+ out[0] = a[4];
259
+ out[1] = a[5];
260
+ out[2] = a[6];
261
+ out[3] = a[7];
262
+ return out;
147
263
  }
264
+ /**
265
+ * Set the real component of a dual quat to the given quaternion
266
+ *
267
+ * @param {quat2} out the receiving quaternion
268
+ * @param {ReadonlyQuat} q a quaternion representing the real part
269
+ * @returns {quat2} out
270
+ * @function
271
+ */
148
272
  export const setReal = quat.copy;
273
+ /**
274
+ * Set the dual component of a dual quat to the given quaternion
275
+ *
276
+ * @param {quat2} out the receiving quaternion
277
+ * @param {ReadonlyQuat} q a quaternion representing the dual part
278
+ * @returns {quat2} out
279
+ * @function
280
+ */
149
281
  export function setDual(out, q) {
150
- out[4] = q[0];
151
- out[5] = q[1];
152
- out[6] = q[2];
153
- out[7] = q[3];
154
- return out;
282
+ out[4] = q[0];
283
+ out[5] = q[1];
284
+ out[6] = q[2];
285
+ out[7] = q[3];
286
+ return out;
155
287
  }
288
+ /**
289
+ * Gets the translation of a normalized dual quat
290
+ * @param {vec3} out translation
291
+ * @param {ReadonlyQuat2} a Dual Quaternion to be decomposed
292
+ * @return {vec3} translation
293
+ */
156
294
  export function getTranslation(out, a) {
157
- let ax = a[4],
158
- ay = a[5],
159
- az = a[6],
160
- aw = a[7],
161
- bx = -a[0],
162
- by = -a[1],
163
- bz = -a[2],
164
- bw = a[3];
165
- out[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;
166
- out[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;
167
- out[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;
168
- return out;
295
+ let ax = a[4], ay = a[5], az = a[6], aw = a[7], bx = -a[0], by = -a[1], bz = -a[2], bw = a[3];
296
+ out[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;
297
+ out[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;
298
+ out[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;
299
+ return out;
169
300
  }
301
+ /**
302
+ * Translates a dual quat by the given vector
303
+ *
304
+ * @param {quat2} out the receiving dual quaternion
305
+ * @param {ReadonlyQuat2} a the dual quaternion to translate
306
+ * @param {ReadonlyVec3} v vector to translate by
307
+ * @returns {quat2} out
308
+ */
170
309
  export function translate(out, a, v) {
171
- let ax1 = a[0],
172
- ay1 = a[1],
173
- az1 = a[2],
174
- aw1 = a[3],
175
- bx1 = v[0] * 0.5,
176
- by1 = v[1] * 0.5,
177
- bz1 = v[2] * 0.5,
178
- ax2 = a[4],
179
- ay2 = a[5],
180
- az2 = a[6],
181
- aw2 = a[7];
182
- out[0] = ax1;
183
- out[1] = ay1;
184
- out[2] = az1;
185
- out[3] = aw1;
186
- out[4] = aw1 * bx1 + ay1 * bz1 - az1 * by1 + ax2;
187
- out[5] = aw1 * by1 + az1 * bx1 - ax1 * bz1 + ay2;
188
- out[6] = aw1 * bz1 + ax1 * by1 - ay1 * bx1 + az2;
189
- out[7] = -ax1 * bx1 - ay1 * by1 - az1 * bz1 + aw2;
190
- return out;
310
+ let ax1 = a[0], ay1 = a[1], az1 = a[2], aw1 = a[3], bx1 = v[0] * 0.5, by1 = v[1] * 0.5, bz1 = v[2] * 0.5, ax2 = a[4], ay2 = a[5], az2 = a[6], aw2 = a[7];
311
+ out[0] = ax1;
312
+ out[1] = ay1;
313
+ out[2] = az1;
314
+ out[3] = aw1;
315
+ out[4] = aw1 * bx1 + ay1 * bz1 - az1 * by1 + ax2;
316
+ out[5] = aw1 * by1 + az1 * bx1 - ax1 * bz1 + ay2;
317
+ out[6] = aw1 * bz1 + ax1 * by1 - ay1 * bx1 + az2;
318
+ out[7] = -ax1 * bx1 - ay1 * by1 - az1 * bz1 + aw2;
319
+ return out;
191
320
  }
321
+ /**
322
+ * Rotates a dual quat around the X axis
323
+ *
324
+ * @param {quat2} out the receiving dual quaternion
325
+ * @param {ReadonlyQuat2} a the dual quaternion to rotate
326
+ * @param {number} rad how far should the rotation be
327
+ * @returns {quat2} out
328
+ */
192
329
  export function rotateX(out, a, rad) {
193
- let bx = -a[0],
194
- by = -a[1],
195
- bz = -a[2],
196
- bw = a[3],
197
- ax = a[4],
198
- ay = a[5],
199
- az = a[6],
200
- aw = a[7],
201
- ax1 = ax * bw + aw * bx + ay * bz - az * by,
202
- ay1 = ay * bw + aw * by + az * bx - ax * bz,
203
- az1 = az * bw + aw * bz + ax * by - ay * bx,
204
- aw1 = aw * bw - ax * bx - ay * by - az * bz;
205
- quat.rotateX(out, a, rad);
206
- bx = out[0];
207
- by = out[1];
208
- bz = out[2];
209
- bw = out[3];
210
- out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
211
- out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
212
- out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
213
- out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
214
- return out;
330
+ let bx = -a[0], by = -a[1], bz = -a[2], bw = a[3], ax = a[4], ay = a[5], az = a[6], aw = a[7], ax1 = ax * bw + aw * bx + ay * bz - az * by, ay1 = ay * bw + aw * by + az * bx - ax * bz, az1 = az * bw + aw * bz + ax * by - ay * bx, aw1 = aw * bw - ax * bx - ay * by - az * bz;
331
+ quat.rotateX(out, a, rad);
332
+ bx = out[0];
333
+ by = out[1];
334
+ bz = out[2];
335
+ bw = out[3];
336
+ out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
337
+ out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
338
+ out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
339
+ out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
340
+ return out;
215
341
  }
342
+ /**
343
+ * Rotates a dual quat around the Y axis
344
+ *
345
+ * @param {quat2} out the receiving dual quaternion
346
+ * @param {ReadonlyQuat2} a the dual quaternion to rotate
347
+ * @param {number} rad how far should the rotation be
348
+ * @returns {quat2} out
349
+ */
216
350
  export function rotateY(out, a, rad) {
217
- let bx = -a[0],
218
- by = -a[1],
219
- bz = -a[2],
220
- bw = a[3],
221
- ax = a[4],
222
- ay = a[5],
223
- az = a[6],
224
- aw = a[7],
225
- ax1 = ax * bw + aw * bx + ay * bz - az * by,
226
- ay1 = ay * bw + aw * by + az * bx - ax * bz,
227
- az1 = az * bw + aw * bz + ax * by - ay * bx,
228
- aw1 = aw * bw - ax * bx - ay * by - az * bz;
229
- quat.rotateY(out, a, rad);
230
- bx = out[0];
231
- by = out[1];
232
- bz = out[2];
233
- bw = out[3];
234
- out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
235
- out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
236
- out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
237
- out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
238
- return out;
351
+ let bx = -a[0], by = -a[1], bz = -a[2], bw = a[3], ax = a[4], ay = a[5], az = a[6], aw = a[7], ax1 = ax * bw + aw * bx + ay * bz - az * by, ay1 = ay * bw + aw * by + az * bx - ax * bz, az1 = az * bw + aw * bz + ax * by - ay * bx, aw1 = aw * bw - ax * bx - ay * by - az * bz;
352
+ quat.rotateY(out, a, rad);
353
+ bx = out[0];
354
+ by = out[1];
355
+ bz = out[2];
356
+ bw = out[3];
357
+ out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
358
+ out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
359
+ out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
360
+ out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
361
+ return out;
239
362
  }
363
+ /**
364
+ * Rotates a dual quat around the Z axis
365
+ *
366
+ * @param {quat2} out the receiving dual quaternion
367
+ * @param {ReadonlyQuat2} a the dual quaternion to rotate
368
+ * @param {number} rad how far should the rotation be
369
+ * @returns {quat2} out
370
+ */
240
371
  export function rotateZ(out, a, rad) {
241
- let bx = -a[0],
242
- by = -a[1],
243
- bz = -a[2],
244
- bw = a[3],
245
- ax = a[4],
246
- ay = a[5],
247
- az = a[6],
248
- aw = a[7],
249
- ax1 = ax * bw + aw * bx + ay * bz - az * by,
250
- ay1 = ay * bw + aw * by + az * bx - ax * bz,
251
- az1 = az * bw + aw * bz + ax * by - ay * bx,
252
- aw1 = aw * bw - ax * bx - ay * by - az * bz;
253
- quat.rotateZ(out, a, rad);
254
- bx = out[0];
255
- by = out[1];
256
- bz = out[2];
257
- bw = out[3];
258
- out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
259
- out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
260
- out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
261
- out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
262
- return out;
372
+ let bx = -a[0], by = -a[1], bz = -a[2], bw = a[3], ax = a[4], ay = a[5], az = a[6], aw = a[7], ax1 = ax * bw + aw * bx + ay * bz - az * by, ay1 = ay * bw + aw * by + az * bx - ax * bz, az1 = az * bw + aw * bz + ax * by - ay * bx, aw1 = aw * bw - ax * bx - ay * by - az * bz;
373
+ quat.rotateZ(out, a, rad);
374
+ bx = out[0];
375
+ by = out[1];
376
+ bz = out[2];
377
+ bw = out[3];
378
+ out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
379
+ out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
380
+ out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
381
+ out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
382
+ return out;
263
383
  }
384
+ /**
385
+ * Rotates a dual quat by a given quaternion (a * q)
386
+ *
387
+ * @param {quat2} out the receiving dual quaternion
388
+ * @param {ReadonlyQuat2} a the dual quaternion to rotate
389
+ * @param {ReadonlyQuat} q quaternion to rotate by
390
+ * @returns {quat2} out
391
+ */
264
392
  export function rotateByQuatAppend(out, a, q) {
265
- let qx = q[0],
266
- qy = q[1],
267
- qz = q[2],
268
- qw = q[3],
269
- ax = a[0],
270
- ay = a[1],
271
- az = a[2],
272
- aw = a[3];
273
- out[0] = ax * qw + aw * qx + ay * qz - az * qy;
274
- out[1] = ay * qw + aw * qy + az * qx - ax * qz;
275
- out[2] = az * qw + aw * qz + ax * qy - ay * qx;
276
- out[3] = aw * qw - ax * qx - ay * qy - az * qz;
277
- ax = a[4];
278
- ay = a[5];
279
- az = a[6];
280
- aw = a[7];
281
- out[4] = ax * qw + aw * qx + ay * qz - az * qy;
282
- out[5] = ay * qw + aw * qy + az * qx - ax * qz;
283
- out[6] = az * qw + aw * qz + ax * qy - ay * qx;
284
- out[7] = aw * qw - ax * qx - ay * qy - az * qz;
285
- return out;
393
+ let qx = q[0], qy = q[1], qz = q[2], qw = q[3], ax = a[0], ay = a[1], az = a[2], aw = a[3];
394
+ out[0] = ax * qw + aw * qx + ay * qz - az * qy;
395
+ out[1] = ay * qw + aw * qy + az * qx - ax * qz;
396
+ out[2] = az * qw + aw * qz + ax * qy - ay * qx;
397
+ out[3] = aw * qw - ax * qx - ay * qy - az * qz;
398
+ ax = a[4];
399
+ ay = a[5];
400
+ az = a[6];
401
+ aw = a[7];
402
+ out[4] = ax * qw + aw * qx + ay * qz - az * qy;
403
+ out[5] = ay * qw + aw * qy + az * qx - ax * qz;
404
+ out[6] = az * qw + aw * qz + ax * qy - ay * qx;
405
+ out[7] = aw * qw - ax * qx - ay * qy - az * qz;
406
+ return out;
286
407
  }
408
+ /**
409
+ * Rotates a dual quat by a given quaternion (q * a)
410
+ *
411
+ * @param {quat2} out the receiving dual quaternion
412
+ * @param {ReadonlyQuat} q quaternion to rotate by
413
+ * @param {ReadonlyQuat2} a the dual quaternion to rotate
414
+ * @returns {quat2} out
415
+ */
287
416
  export function rotateByQuatPrepend(out, q, a) {
288
- let qx = q[0],
289
- qy = q[1],
290
- qz = q[2],
291
- qw = q[3],
292
- bx = a[0],
293
- by = a[1],
294
- bz = a[2],
295
- bw = a[3];
296
- out[0] = qx * bw + qw * bx + qy * bz - qz * by;
297
- out[1] = qy * bw + qw * by + qz * bx - qx * bz;
298
- out[2] = qz * bw + qw * bz + qx * by - qy * bx;
299
- out[3] = qw * bw - qx * bx - qy * by - qz * bz;
300
- bx = a[4];
301
- by = a[5];
302
- bz = a[6];
303
- bw = a[7];
304
- out[4] = qx * bw + qw * bx + qy * bz - qz * by;
305
- out[5] = qy * bw + qw * by + qz * bx - qx * bz;
306
- out[6] = qz * bw + qw * bz + qx * by - qy * bx;
307
- out[7] = qw * bw - qx * bx - qy * by - qz * bz;
308
- return out;
417
+ let qx = q[0], qy = q[1], qz = q[2], qw = q[3], bx = a[0], by = a[1], bz = a[2], bw = a[3];
418
+ out[0] = qx * bw + qw * bx + qy * bz - qz * by;
419
+ out[1] = qy * bw + qw * by + qz * bx - qx * bz;
420
+ out[2] = qz * bw + qw * bz + qx * by - qy * bx;
421
+ out[3] = qw * bw - qx * bx - qy * by - qz * bz;
422
+ bx = a[4];
423
+ by = a[5];
424
+ bz = a[6];
425
+ bw = a[7];
426
+ out[4] = qx * bw + qw * bx + qy * bz - qz * by;
427
+ out[5] = qy * bw + qw * by + qz * bx - qx * bz;
428
+ out[6] = qz * bw + qw * bz + qx * by - qy * bx;
429
+ out[7] = qw * bw - qx * bx - qy * by - qz * bz;
430
+ return out;
309
431
  }
432
+ /**
433
+ * Rotates a dual quat around a given axis. Does the normalisation automatically
434
+ *
435
+ * @param {quat2} out the receiving dual quaternion
436
+ * @param {ReadonlyQuat2} a the dual quaternion to rotate
437
+ * @param {ReadonlyVec3} axis the axis to rotate around
438
+ * @param {Number} rad how far the rotation should be
439
+ * @returns {quat2} out
440
+ */
310
441
  export function rotateAroundAxis(out, a, axis, rad) {
311
- if (Math.abs(rad) < glMatrix.EPSILON) {
312
- return copy(out, a);
313
- }
314
-
315
- let axisLength = Math.sqrt(axis[0] * axis[0] + axis[1] * axis[1] + axis[2] * axis[2]);
316
- rad = rad * 0.5;
317
- let s = Math.sin(rad);
318
- let bx = s * axis[0] / axisLength;
319
- let by = s * axis[1] / axisLength;
320
- let bz = s * axis[2] / axisLength;
321
- let bw = Math.cos(rad);
322
- let ax1 = a[0],
323
- ay1 = a[1],
324
- az1 = a[2],
325
- aw1 = a[3];
326
- out[0] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
327
- out[1] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
328
- out[2] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
329
- out[3] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
330
- let ax = a[4],
331
- ay = a[5],
332
- az = a[6],
333
- aw = a[7];
334
- out[4] = ax * bw + aw * bx + ay * bz - az * by;
335
- out[5] = ay * bw + aw * by + az * bx - ax * bz;
336
- out[6] = az * bw + aw * bz + ax * by - ay * bx;
337
- out[7] = aw * bw - ax * bx - ay * by - az * bz;
338
- return out;
442
+ //Special case for rad = 0
443
+ if (Math.abs(rad) < glMatrix.EPSILON) {
444
+ return copy(out, a);
445
+ }
446
+ let axisLength = Math.sqrt(axis[0] * axis[0] + axis[1] * axis[1] + axis[2] * axis[2]);
447
+ rad = rad * 0.5;
448
+ let s = Math.sin(rad);
449
+ let bx = (s * axis[0]) / axisLength;
450
+ let by = (s * axis[1]) / axisLength;
451
+ let bz = (s * axis[2]) / axisLength;
452
+ let bw = Math.cos(rad);
453
+ let ax1 = a[0], ay1 = a[1], az1 = a[2], aw1 = a[3];
454
+ out[0] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
455
+ out[1] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
456
+ out[2] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
457
+ out[3] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
458
+ let ax = a[4], ay = a[5], az = a[6], aw = a[7];
459
+ out[4] = ax * bw + aw * bx + ay * bz - az * by;
460
+ out[5] = ay * bw + aw * by + az * bx - ax * bz;
461
+ out[6] = az * bw + aw * bz + ax * by - ay * bx;
462
+ out[7] = aw * bw - ax * bx - ay * by - az * bz;
463
+ return out;
339
464
  }
465
+ /**
466
+ * Adds two dual quat's
467
+ *
468
+ * @param {quat2} out the receiving dual quaternion
469
+ * @param {ReadonlyQuat2} a the first operand
470
+ * @param {ReadonlyQuat2} b the second operand
471
+ * @returns {quat2} out
472
+ * @function
473
+ */
340
474
  export function add(out, a, b) {
341
- out[0] = a[0] + b[0];
342
- out[1] = a[1] + b[1];
343
- out[2] = a[2] + b[2];
344
- out[3] = a[3] + b[3];
345
- out[4] = a[4] + b[4];
346
- out[5] = a[5] + b[5];
347
- out[6] = a[6] + b[6];
348
- out[7] = a[7] + b[7];
349
- return out;
475
+ out[0] = a[0] + b[0];
476
+ out[1] = a[1] + b[1];
477
+ out[2] = a[2] + b[2];
478
+ out[3] = a[3] + b[3];
479
+ out[4] = a[4] + b[4];
480
+ out[5] = a[5] + b[5];
481
+ out[6] = a[6] + b[6];
482
+ out[7] = a[7] + b[7];
483
+ return out;
350
484
  }
485
+ /**
486
+ * Multiplies two dual quat's
487
+ *
488
+ * @param {quat2} out the receiving dual quaternion
489
+ * @param {ReadonlyQuat2} a the first operand
490
+ * @param {ReadonlyQuat2} b the second operand
491
+ * @returns {quat2} out
492
+ */
351
493
  export function multiply(out, a, b) {
352
- let ax0 = a[0],
353
- ay0 = a[1],
354
- az0 = a[2],
355
- aw0 = a[3],
356
- bx1 = b[4],
357
- by1 = b[5],
358
- bz1 = b[6],
359
- bw1 = b[7],
360
- ax1 = a[4],
361
- ay1 = a[5],
362
- az1 = a[6],
363
- aw1 = a[7],
364
- bx0 = b[0],
365
- by0 = b[1],
366
- bz0 = b[2],
367
- bw0 = b[3];
368
- out[0] = ax0 * bw0 + aw0 * bx0 + ay0 * bz0 - az0 * by0;
369
- out[1] = ay0 * bw0 + aw0 * by0 + az0 * bx0 - ax0 * bz0;
370
- out[2] = az0 * bw0 + aw0 * bz0 + ax0 * by0 - ay0 * bx0;
371
- out[3] = aw0 * bw0 - ax0 * bx0 - ay0 * by0 - az0 * bz0;
372
- out[4] = ax0 * bw1 + aw0 * bx1 + ay0 * bz1 - az0 * by1 + ax1 * bw0 + aw1 * bx0 + ay1 * bz0 - az1 * by0;
373
- out[5] = ay0 * bw1 + aw0 * by1 + az0 * bx1 - ax0 * bz1 + ay1 * bw0 + aw1 * by0 + az1 * bx0 - ax1 * bz0;
374
- out[6] = az0 * bw1 + aw0 * bz1 + ax0 * by1 - ay0 * bx1 + az1 * bw0 + aw1 * bz0 + ax1 * by0 - ay1 * bx0;
375
- out[7] = aw0 * bw1 - ax0 * bx1 - ay0 * by1 - az0 * bz1 + aw1 * bw0 - ax1 * bx0 - ay1 * by0 - az1 * bz0;
376
- return out;
494
+ let ax0 = a[0], ay0 = a[1], az0 = a[2], aw0 = a[3], bx1 = b[4], by1 = b[5], bz1 = b[6], bw1 = b[7], ax1 = a[4], ay1 = a[5], az1 = a[6], aw1 = a[7], bx0 = b[0], by0 = b[1], bz0 = b[2], bw0 = b[3];
495
+ out[0] = ax0 * bw0 + aw0 * bx0 + ay0 * bz0 - az0 * by0;
496
+ out[1] = ay0 * bw0 + aw0 * by0 + az0 * bx0 - ax0 * bz0;
497
+ out[2] = az0 * bw0 + aw0 * bz0 + ax0 * by0 - ay0 * bx0;
498
+ out[3] = aw0 * bw0 - ax0 * bx0 - ay0 * by0 - az0 * bz0;
499
+ out[4] =
500
+ ax0 * bw1 + aw0 * bx1 + ay0 * bz1 - az0 * by1 + ax1 * bw0 + aw1 * bx0 + ay1 * bz0 - az1 * by0;
501
+ out[5] =
502
+ ay0 * bw1 + aw0 * by1 + az0 * bx1 - ax0 * bz1 + ay1 * bw0 + aw1 * by0 + az1 * bx0 - ax1 * bz0;
503
+ out[6] =
504
+ az0 * bw1 + aw0 * bz1 + ax0 * by1 - ay0 * bx1 + az1 * bw0 + aw1 * bz0 + ax1 * by0 - ay1 * bx0;
505
+ out[7] =
506
+ aw0 * bw1 - ax0 * bx1 - ay0 * by1 - az0 * bz1 + aw1 * bw0 - ax1 * bx0 - ay1 * by0 - az1 * bz0;
507
+ return out;
377
508
  }
509
+ /**
510
+ * Alias for {@link quat2.multiply}
511
+ * @function
512
+ */
378
513
  export const mul = multiply;
514
+ /**
515
+ * Scales a dual quat by a scalar number
516
+ *
517
+ * @param {quat2} out the receiving dual quat
518
+ * @param {ReadonlyQuat2} a the dual quat to scale
519
+ * @param {Number} b amount to scale the dual quat by
520
+ * @returns {quat2} out
521
+ * @function
522
+ */
379
523
  export function scale(out, a, b) {
380
- out[0] = a[0] * b;
381
- out[1] = a[1] * b;
382
- out[2] = a[2] * b;
383
- out[3] = a[3] * b;
384
- out[4] = a[4] * b;
385
- out[5] = a[5] * b;
386
- out[6] = a[6] * b;
387
- out[7] = a[7] * b;
388
- return out;
524
+ out[0] = a[0] * b;
525
+ out[1] = a[1] * b;
526
+ out[2] = a[2] * b;
527
+ out[3] = a[3] * b;
528
+ out[4] = a[4] * b;
529
+ out[5] = a[5] * b;
530
+ out[6] = a[6] * b;
531
+ out[7] = a[7] * b;
532
+ return out;
389
533
  }
534
+ /**
535
+ * Calculates the dot product of two dual quat's (The dot product of the real parts)
536
+ *
537
+ * @param {ReadonlyQuat2} a the first operand
538
+ * @param {ReadonlyQuat2} b the second operand
539
+ * @returns {Number} dot product of a and b
540
+ * @function
541
+ */
390
542
  export const dot = quat.dot;
543
+ /**
544
+ * Performs a linear interpolation between two dual quats's
545
+ * NOTE: The resulting dual quaternions won't always be normalized (The error is most noticeable when t = 0.5)
546
+ *
547
+ * @param {quat2} out the receiving dual quat
548
+ * @param {ReadonlyQuat2} a the first operand
549
+ * @param {ReadonlyQuat2} b the second operand
550
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
551
+ * @returns {quat2} out
552
+ */
391
553
  export function lerp(out, a, b, t) {
392
- let mt = 1 - t;
393
- if (dot(a, b) < 0) t = -t;
394
- out[0] = a[0] * mt + b[0] * t;
395
- out[1] = a[1] * mt + b[1] * t;
396
- out[2] = a[2] * mt + b[2] * t;
397
- out[3] = a[3] * mt + b[3] * t;
398
- out[4] = a[4] * mt + b[4] * t;
399
- out[5] = a[5] * mt + b[5] * t;
400
- out[6] = a[6] * mt + b[6] * t;
401
- out[7] = a[7] * mt + b[7] * t;
402
- return out;
554
+ let mt = 1 - t;
555
+ if (dot(a, b) < 0)
556
+ t = -t;
557
+ out[0] = a[0] * mt + b[0] * t;
558
+ out[1] = a[1] * mt + b[1] * t;
559
+ out[2] = a[2] * mt + b[2] * t;
560
+ out[3] = a[3] * mt + b[3] * t;
561
+ out[4] = a[4] * mt + b[4] * t;
562
+ out[5] = a[5] * mt + b[5] * t;
563
+ out[6] = a[6] * mt + b[6] * t;
564
+ out[7] = a[7] * mt + b[7] * t;
565
+ return out;
403
566
  }
567
+ /**
568
+ * Calculates the inverse of a dual quat. If they are normalized, conjugate is cheaper
569
+ *
570
+ * @param {quat2} out the receiving dual quaternion
571
+ * @param {ReadonlyQuat2} a dual quat to calculate inverse of
572
+ * @returns {quat2} out
573
+ */
404
574
  export function invert(out, a) {
405
- let sqlen = squaredLength(a);
406
- out[0] = -a[0] / sqlen;
407
- out[1] = -a[1] / sqlen;
408
- out[2] = -a[2] / sqlen;
409
- out[3] = a[3] / sqlen;
410
- out[4] = -a[4] / sqlen;
411
- out[5] = -a[5] / sqlen;
412
- out[6] = -a[6] / sqlen;
413
- out[7] = a[7] / sqlen;
414
- return out;
575
+ let sqlen = squaredLength(a);
576
+ out[0] = -a[0] / sqlen;
577
+ out[1] = -a[1] / sqlen;
578
+ out[2] = -a[2] / sqlen;
579
+ out[3] = a[3] / sqlen;
580
+ out[4] = -a[4] / sqlen;
581
+ out[5] = -a[5] / sqlen;
582
+ out[6] = -a[6] / sqlen;
583
+ out[7] = a[7] / sqlen;
584
+ return out;
415
585
  }
586
+ /**
587
+ * Calculates the conjugate of a dual quat
588
+ * If the dual quaternion is normalized, this function is faster than quat2.inverse and produces the same result.
589
+ *
590
+ * @param {quat2} out the receiving quaternion
591
+ * @param {ReadonlyQuat2} a quat to calculate conjugate of
592
+ * @returns {quat2} out
593
+ */
416
594
  export function conjugate(out, a) {
417
- out[0] = -a[0];
418
- out[1] = -a[1];
419
- out[2] = -a[2];
420
- out[3] = a[3];
421
- out[4] = -a[4];
422
- out[5] = -a[5];
423
- out[6] = -a[6];
424
- out[7] = a[7];
425
- return out;
595
+ out[0] = -a[0];
596
+ out[1] = -a[1];
597
+ out[2] = -a[2];
598
+ out[3] = a[3];
599
+ out[4] = -a[4];
600
+ out[5] = -a[5];
601
+ out[6] = -a[6];
602
+ out[7] = a[7];
603
+ return out;
426
604
  }
605
+ /**
606
+ * Calculates the length of a dual quat
607
+ *
608
+ * @param {ReadonlyQuat2} a dual quat to calculate length of
609
+ * @returns {Number} length of a
610
+ * @function
611
+ */
427
612
  export const length = quat.length;
613
+ /**
614
+ * Alias for {@link quat2.length}
615
+ * @function
616
+ */
428
617
  export const len = length;
618
+ /**
619
+ * Calculates the squared length of a dual quat
620
+ *
621
+ * @param {ReadonlyQuat2} a dual quat to calculate squared length of
622
+ * @returns {Number} squared length of a
623
+ * @function
624
+ */
429
625
  export const squaredLength = quat.squaredLength;
626
+ /**
627
+ * Alias for {@link quat2.squaredLength}
628
+ * @function
629
+ */
430
630
  export const sqrLen = squaredLength;
631
+ /**
632
+ * Normalize a dual quat
633
+ *
634
+ * @param {quat2} out the receiving dual quaternion
635
+ * @param {ReadonlyQuat2} a dual quaternion to normalize
636
+ * @returns {quat2} out
637
+ * @function
638
+ */
431
639
  export function normalize(out, a) {
432
- let magnitude = squaredLength(a);
433
-
434
- if (magnitude > 0) {
435
- magnitude = Math.sqrt(magnitude);
436
- let a0 = a[0] / magnitude;
437
- let a1 = a[1] / magnitude;
438
- let a2 = a[2] / magnitude;
439
- let a3 = a[3] / magnitude;
440
- let b0 = a[4];
441
- let b1 = a[5];
442
- let b2 = a[6];
443
- let b3 = a[7];
444
- let a_dot_b = a0 * b0 + a1 * b1 + a2 * b2 + a3 * b3;
445
- out[0] = a0;
446
- out[1] = a1;
447
- out[2] = a2;
448
- out[3] = a3;
449
- out[4] = (b0 - a0 * a_dot_b) / magnitude;
450
- out[5] = (b1 - a1 * a_dot_b) / magnitude;
451
- out[6] = (b2 - a2 * a_dot_b) / magnitude;
452
- out[7] = (b3 - a3 * a_dot_b) / magnitude;
453
- }
454
-
455
- return out;
640
+ let magnitude = squaredLength(a);
641
+ if (magnitude > 0) {
642
+ magnitude = Math.sqrt(magnitude);
643
+ let a0 = a[0] / magnitude;
644
+ let a1 = a[1] / magnitude;
645
+ let a2 = a[2] / magnitude;
646
+ let a3 = a[3] / magnitude;
647
+ let b0 = a[4];
648
+ let b1 = a[5];
649
+ let b2 = a[6];
650
+ let b3 = a[7];
651
+ let a_dot_b = a0 * b0 + a1 * b1 + a2 * b2 + a3 * b3;
652
+ out[0] = a0;
653
+ out[1] = a1;
654
+ out[2] = a2;
655
+ out[3] = a3;
656
+ out[4] = (b0 - a0 * a_dot_b) / magnitude;
657
+ out[5] = (b1 - a1 * a_dot_b) / magnitude;
658
+ out[6] = (b2 - a2 * a_dot_b) / magnitude;
659
+ out[7] = (b3 - a3 * a_dot_b) / magnitude;
660
+ }
661
+ return out;
456
662
  }
663
+ /**
664
+ * Returns a string representation of a dual quaternion
665
+ *
666
+ * @param {ReadonlyQuat2} a dual quaternion to represent as a string
667
+ * @returns {String} string representation of the dual quat
668
+ */
457
669
  export function str(a) {
458
- return 'quat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ')';
670
+ return ('quat2(' +
671
+ a[0] +
672
+ ', ' +
673
+ a[1] +
674
+ ', ' +
675
+ a[2] +
676
+ ', ' +
677
+ a[3] +
678
+ ', ' +
679
+ a[4] +
680
+ ', ' +
681
+ a[5] +
682
+ ', ' +
683
+ a[6] +
684
+ ', ' +
685
+ a[7] +
686
+ ')');
459
687
  }
688
+ /**
689
+ * Returns whether or not the dual quaternions have exactly the same elements in the same position (when compared with ===)
690
+ *
691
+ * @param {ReadonlyQuat2} a the first dual quaternion.
692
+ * @param {ReadonlyQuat2} b the second dual quaternion.
693
+ * @returns {Boolean} true if the dual quaternions are equal, false otherwise.
694
+ */
460
695
  export function exactEquals(a, b) {
461
- return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5] && a[6] === b[6] && a[7] === b[7];
696
+ return (a[0] === b[0] &&
697
+ a[1] === b[1] &&
698
+ a[2] === b[2] &&
699
+ a[3] === b[3] &&
700
+ a[4] === b[4] &&
701
+ a[5] === b[5] &&
702
+ a[6] === b[6] &&
703
+ a[7] === b[7]);
462
704
  }
705
+ /**
706
+ * Returns whether or not the dual quaternions have approximately the same elements in the same position.
707
+ *
708
+ * @param {ReadonlyQuat2} a the first dual quat.
709
+ * @param {ReadonlyQuat2} b the second dual quat.
710
+ * @returns {Boolean} true if the dual quats are equal, false otherwise.
711
+ */
463
712
  export function equals(a, b) {
464
- let a0 = a[0],
465
- a1 = a[1],
466
- a2 = a[2],
467
- a3 = a[3],
468
- a4 = a[4],
469
- a5 = a[5],
470
- a6 = a[6],
471
- a7 = a[7];
472
- let b0 = b[0],
473
- b1 = b[1],
474
- b2 = b[2],
475
- b3 = b[3],
476
- b4 = b[4],
477
- b5 = b[5],
478
- b6 = b[6],
479
- b7 = b[7];
480
- return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) && Math.abs(a6 - b6) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) && Math.abs(a7 - b7) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7));
713
+ let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], a6 = a[6], a7 = a[7];
714
+ let b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5], b6 = b[6], b7 = b[7];
715
+ return (Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
716
+ Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
717
+ Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&
718
+ Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) &&
719
+ Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) &&
720
+ Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) &&
721
+ Math.abs(a6 - b6) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) &&
722
+ Math.abs(a7 - b7) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)));
481
723
  }
482
- //# sourceMappingURL=quat2.js.map