@math.gl/core 3.6.3 → 4.0.0-alpha.2

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 (210) hide show
  1. package/dist/classes/base/math-array.d.ts +5 -4
  2. package/dist/classes/base/math-array.d.ts.map +1 -1
  3. package/dist/{esm/classes → classes}/base/math-array.js +8 -3
  4. package/dist/classes/base/math-array.js.map +1 -0
  5. package/dist/classes/base/matrix.d.ts +2 -2
  6. package/dist/classes/base/matrix.d.ts.map +1 -1
  7. package/dist/{esm/classes → classes}/base/matrix.js +4 -4
  8. package/dist/classes/base/matrix.js.map +1 -0
  9. package/dist/classes/base/vector.d.ts +2 -2
  10. package/dist/classes/base/vector.d.ts.map +1 -1
  11. package/dist/{esm/classes → classes}/base/vector.js +4 -4
  12. package/dist/classes/base/vector.js.map +1 -0
  13. package/dist/classes/euler.d.ts +4 -4
  14. package/dist/classes/euler.d.ts.map +1 -1
  15. package/dist/{esm/classes → classes}/euler.js +6 -6
  16. package/dist/classes/euler.js.map +1 -0
  17. package/dist/classes/matrix3.d.ts +5 -2
  18. package/dist/classes/matrix3.d.ts.map +1 -1
  19. package/dist/{esm/classes → classes}/matrix3.js +20 -20
  20. package/dist/classes/matrix3.js.map +1 -0
  21. package/dist/classes/matrix4.d.ts +2 -2
  22. package/dist/classes/matrix4.d.ts.map +1 -1
  23. package/dist/{esm/classes → classes}/matrix4.js +27 -27
  24. package/dist/classes/matrix4.js.map +1 -0
  25. package/dist/classes/pose.d.ts +4 -4
  26. package/dist/classes/pose.d.ts.map +1 -1
  27. package/dist/{esm/classes → classes}/pose.js +4 -4
  28. package/dist/classes/pose.js.map +1 -0
  29. package/dist/classes/quaternion.d.ts +2 -2
  30. package/dist/classes/quaternion.d.ts.map +1 -1
  31. package/dist/{esm/classes → classes}/quaternion.js +26 -26
  32. package/dist/classes/quaternion.js.map +1 -0
  33. package/dist/classes/spherical-coordinates.d.ts +2 -2
  34. package/dist/classes/spherical-coordinates.d.ts.map +1 -1
  35. package/dist/{esm/classes → classes}/spherical-coordinates.js +5 -5
  36. package/dist/classes/spherical-coordinates.js.map +1 -0
  37. package/dist/classes/vector2.d.ts +2 -2
  38. package/dist/classes/vector2.d.ts.map +1 -1
  39. package/dist/{esm/classes → classes}/vector2.js +10 -10
  40. package/dist/classes/vector2.js.map +1 -0
  41. package/dist/classes/vector3.d.ts +2 -2
  42. package/dist/classes/vector3.d.ts.map +1 -1
  43. package/dist/{esm/classes → classes}/vector3.js +14 -14
  44. package/dist/classes/vector3.js.map +1 -0
  45. package/dist/classes/vector4.d.ts +3 -3
  46. package/dist/classes/vector4.d.ts.map +1 -1
  47. package/dist/{esm/classes → classes}/vector4.js +8 -8
  48. package/dist/classes/vector4.js.map +1 -0
  49. package/dist/gl-matrix/common.d.ts +38 -0
  50. package/dist/gl-matrix/common.d.ts.map +1 -0
  51. package/dist/gl-matrix/common.js +19 -0
  52. package/dist/gl-matrix/common.js.map +1 -0
  53. package/dist/gl-matrix/mat3.d.ts +295 -0
  54. package/dist/gl-matrix/mat3.d.ts.map +1 -0
  55. package/dist/gl-matrix/mat3.js +489 -0
  56. package/dist/gl-matrix/mat3.js.map +1 -0
  57. package/dist/gl-matrix/mat4.d.ts +577 -0
  58. package/dist/gl-matrix/mat4.d.ts.map +1 -0
  59. package/dist/gl-matrix/mat4.js +1455 -0
  60. package/dist/gl-matrix/mat4.js.map +1 -0
  61. package/dist/gl-matrix/quat.d.ts +357 -0
  62. package/dist/gl-matrix/quat.d.ts.map +1 -0
  63. package/dist/gl-matrix/quat.js +315 -0
  64. package/dist/gl-matrix/quat.js.map +1 -0
  65. package/dist/gl-matrix/vec2.d.ts +373 -0
  66. package/dist/gl-matrix/vec2.d.ts.map +1 -0
  67. package/dist/gl-matrix/vec2.js +257 -0
  68. package/dist/gl-matrix/vec2.js.map +1 -0
  69. package/dist/gl-matrix/vec3.d.ts +416 -0
  70. package/dist/gl-matrix/vec3.d.ts.map +1 -0
  71. package/dist/gl-matrix/vec3.js +384 -0
  72. package/dist/gl-matrix/vec3.js.map +1 -0
  73. package/dist/gl-matrix/vec4.d.ts +340 -0
  74. package/dist/gl-matrix/vec4.d.ts.map +1 -0
  75. package/dist/gl-matrix/vec4.js +334 -0
  76. package/dist/gl-matrix/vec4.js.map +1 -0
  77. package/dist/gl-matrix/wip/index.d.ts +5 -0
  78. package/dist/gl-matrix/wip/index.d.ts.map +1 -0
  79. package/dist/gl-matrix/wip/index.js +12 -0
  80. package/dist/gl-matrix/wip/index.js.map +1 -0
  81. package/dist/gl-matrix/wip/mat2.d.ts +229 -0
  82. package/dist/gl-matrix/wip/mat2.d.ts.map +1 -0
  83. package/dist/gl-matrix/wip/mat2.js +208 -0
  84. package/dist/gl-matrix/wip/mat2.js.map +1 -0
  85. package/dist/gl-matrix/wip/mat2d.d.ts +244 -0
  86. package/dist/gl-matrix/wip/mat2d.d.ts.map +1 -0
  87. package/dist/gl-matrix/wip/mat2d.js +251 -0
  88. package/dist/gl-matrix/wip/mat2d.js.map +1 -0
  89. package/dist/gl-matrix/wip/quat2.d.ts +352 -0
  90. package/dist/gl-matrix/wip/quat2.d.ts.map +1 -0
  91. package/dist/gl-matrix/wip/quat2.js +482 -0
  92. package/dist/gl-matrix/wip/quat2.js.map +1 -0
  93. package/dist/gl-matrix/wip/types.d.js +2 -0
  94. package/dist/{esm/lib/gl-matrix.d.js.map → gl-matrix/wip/types.d.js.map} +1 -1
  95. package/dist/index.cjs +3788 -0
  96. package/dist/index.d.ts +15 -14
  97. package/dist/index.d.ts.map +1 -1
  98. package/dist/index.js +17 -0
  99. package/dist/index.js.map +1 -0
  100. package/dist/lib/assert.d.ts +1 -1
  101. package/dist/lib/assert.d.ts.map +1 -1
  102. package/dist/lib/assert.js +6 -0
  103. package/dist/lib/assert.js.map +1 -0
  104. package/dist/lib/common.d.ts +10 -5
  105. package/dist/lib/common.d.ts.map +1 -1
  106. package/dist/{esm/lib → lib}/common.js +11 -9
  107. package/dist/lib/common.js.map +1 -0
  108. package/dist/lib/gl-matrix-extras.js.map +1 -0
  109. package/dist/lib/math-utils.d.ts +24 -27
  110. package/dist/lib/math-utils.d.ts.map +1 -1
  111. package/dist/lib/math-utils.js +25 -0
  112. package/dist/lib/math-utils.js.map +1 -0
  113. package/dist/lib/validators.d.ts +1 -1
  114. package/dist/lib/validators.d.ts.map +1 -1
  115. package/dist/{esm/lib → lib}/validators.js +2 -2
  116. package/dist/lib/validators.js.map +1 -0
  117. package/package.json +6 -6
  118. package/src/classes/base/math-array.ts +16 -8
  119. package/src/classes/base/matrix.ts +7 -4
  120. package/src/classes/base/vector.ts +4 -4
  121. package/src/classes/euler.ts +9 -8
  122. package/src/classes/matrix3.ts +37 -24
  123. package/src/classes/matrix4.ts +48 -29
  124. package/src/classes/pose.ts +4 -4
  125. package/src/classes/quaternion.ts +54 -32
  126. package/src/classes/spherical-coordinates.ts +5 -4
  127. package/src/classes/vector2.ts +13 -9
  128. package/src/classes/vector3.ts +26 -12
  129. package/src/classes/vector4.ts +14 -10
  130. package/src/gl-matrix/common.js +58 -0
  131. package/src/gl-matrix/mat3.js +842 -0
  132. package/src/gl-matrix/mat4.js +2169 -0
  133. package/src/gl-matrix/quat.ts +789 -0
  134. package/src/gl-matrix/vec2.js +629 -0
  135. package/src/gl-matrix/vec3.js +827 -0
  136. package/src/gl-matrix/vec4.js +675 -0
  137. package/src/gl-matrix/wip/index.js +15 -0
  138. package/src/gl-matrix/wip/mat2.js +442 -0
  139. package/src/gl-matrix/wip/mat2d.js +505 -0
  140. package/src/gl-matrix/wip/quat2.ts +886 -0
  141. package/src/gl-matrix/wip/types.d.ts +93 -0
  142. package/src/index.ts +16 -14
  143. package/src/lib/assert.ts +1 -1
  144. package/src/lib/common.ts +31 -19
  145. package/src/lib/math-utils.ts +24 -26
  146. package/src/lib/validators.ts +3 -3
  147. package/dist/es5/classes/base/math-array.js +0 -348
  148. package/dist/es5/classes/base/math-array.js.map +0 -1
  149. package/dist/es5/classes/base/matrix.js +0 -108
  150. package/dist/es5/classes/base/matrix.js.map +0 -1
  151. package/dist/es5/classes/base/vector.js +0 -210
  152. package/dist/es5/classes/base/vector.js.map +0 -1
  153. package/dist/es5/classes/euler.js +0 -654
  154. package/dist/es5/classes/euler.js.map +0 -1
  155. package/dist/es5/classes/matrix3.js +0 -284
  156. package/dist/es5/classes/matrix3.js.map +0 -1
  157. package/dist/es5/classes/matrix4.js +0 -574
  158. package/dist/es5/classes/matrix4.js.map +0 -1
  159. package/dist/es5/classes/pose.js +0 -159
  160. package/dist/es5/classes/pose.js.map +0 -1
  161. package/dist/es5/classes/quaternion.js +0 -323
  162. package/dist/es5/classes/quaternion.js.map +0 -1
  163. package/dist/es5/classes/spherical-coordinates.js +0 -208
  164. package/dist/es5/classes/spherical-coordinates.js.map +0 -1
  165. package/dist/es5/classes/vector2.js +0 -156
  166. package/dist/es5/classes/vector2.js.map +0 -1
  167. package/dist/es5/classes/vector3.js +0 -213
  168. package/dist/es5/classes/vector3.js.map +0 -1
  169. package/dist/es5/classes/vector4.js +0 -185
  170. package/dist/es5/classes/vector4.js.map +0 -1
  171. package/dist/es5/docs/README.md +0 -0
  172. package/dist/es5/index.js +0 -236
  173. package/dist/es5/index.js.map +0 -1
  174. package/dist/es5/lib/assert.js +0 -13
  175. package/dist/es5/lib/assert.js.map +0 -1
  176. package/dist/es5/lib/common.js +0 -255
  177. package/dist/es5/lib/common.js.map +0 -1
  178. package/dist/es5/lib/gl-matrix-extras.js +0 -61
  179. package/dist/es5/lib/gl-matrix-extras.js.map +0 -1
  180. package/dist/es5/lib/gl-matrix.d.js +0 -2
  181. package/dist/es5/lib/math-utils.js +0 -34
  182. package/dist/es5/lib/math-utils.js.map +0 -1
  183. package/dist/es5/lib/validators.js +0 -53
  184. package/dist/es5/lib/validators.js.map +0 -1
  185. package/dist/esm/classes/base/math-array.js.map +0 -1
  186. package/dist/esm/classes/base/matrix.js.map +0 -1
  187. package/dist/esm/classes/base/vector.js.map +0 -1
  188. package/dist/esm/classes/euler.js.map +0 -1
  189. package/dist/esm/classes/matrix3.js.map +0 -1
  190. package/dist/esm/classes/matrix4.js.map +0 -1
  191. package/dist/esm/classes/pose.js.map +0 -1
  192. package/dist/esm/classes/quaternion.js.map +0 -1
  193. package/dist/esm/classes/spherical-coordinates.js.map +0 -1
  194. package/dist/esm/classes/vector2.js.map +0 -1
  195. package/dist/esm/classes/vector3.js.map +0 -1
  196. package/dist/esm/classes/vector4.js.map +0 -1
  197. package/dist/esm/docs/README.md +0 -0
  198. package/dist/esm/index.js +0 -16
  199. package/dist/esm/index.js.map +0 -1
  200. package/dist/esm/lib/assert.js +0 -6
  201. package/dist/esm/lib/assert.js.map +0 -1
  202. package/dist/esm/lib/common.js.map +0 -1
  203. package/dist/esm/lib/gl-matrix-extras.js.map +0 -1
  204. package/dist/esm/lib/math-utils.js +0 -27
  205. package/dist/esm/lib/math-utils.js.map +0 -1
  206. package/dist/esm/lib/validators.js.map +0 -1
  207. package/src/docs/README.md +0 -0
  208. /package/dist/{esm/lib → lib}/gl-matrix-extras.js +0 -0
  209. /package/dist/{esm/lib → lib}/gl-matrix.d.js +0 -0
  210. /package/dist/{es5/lib → lib}/gl-matrix.d.js.map +0 -0
@@ -0,0 +1,789 @@
1
+ // @eslint-disable
2
+ // @ts-nocheck
3
+
4
+ import * as glMatrix from './common.js';
5
+ import * as mat3 from './mat3.js';
6
+ import * as vec3 from './vec3.js';
7
+ import * as vec4 from './vec4.js';
8
+
9
+ // const glMatrix: {EPSILON = 0.000001};
10
+
11
+ /**
12
+ * Quaternion in the format XYZW
13
+ * @module quat
14
+ */
15
+
16
+ /**
17
+ * Creates a new identity quat
18
+ *
19
+ * @returns {quat} a new quaternion
20
+ */
21
+ export function create() {
22
+ const out = new glMatrix.ARRAY_TYPE(4);
23
+ if (glMatrix.ARRAY_TYPE != Float32Array) {
24
+ out[0] = 0;
25
+ out[1] = 0;
26
+ out[2] = 0;
27
+ }
28
+ out[3] = 1;
29
+ return out;
30
+ }
31
+
32
+ /**
33
+ * Set a quat to the identity quaternion
34
+ *
35
+ * @param {quat} out the receiving quaternion
36
+ * @returns {quat} out
37
+ */
38
+ export function identity(out) {
39
+ out[0] = 0;
40
+ out[1] = 0;
41
+ out[2] = 0;
42
+ out[3] = 1;
43
+ return out;
44
+ }
45
+
46
+ /**
47
+ * Sets a quat from the given angle and rotation axis,
48
+ * then returns it.
49
+ *
50
+ * @param {quat} out the receiving quaternion
51
+ * @param {ReadonlyVec3} axis the axis around which to rotate
52
+ * @param {Number} rad the angle in radians
53
+ * @returns {quat} out
54
+ **/
55
+ export function setAxisAngle(out, axis, rad) {
56
+ rad = rad * 0.5;
57
+ const s = Math.sin(rad);
58
+ out[0] = s * axis[0];
59
+ out[1] = s * axis[1];
60
+ out[2] = s * axis[2];
61
+ out[3] = Math.cos(rad);
62
+ return out;
63
+ }
64
+
65
+ /**
66
+ * Gets the rotation axis and angle for a given
67
+ * quaternion. If a quaternion is created with
68
+ * setAxisAngle, this method will return the same
69
+ * values as providied in the original parameter list
70
+ * OR functionally equivalent values.
71
+ * Example: The quaternion formed by axis [0, 0, 1] and
72
+ * angle -90 is the same as the quaternion formed by
73
+ * [0, 0, 1] and 270. This method favors the latter.
74
+ * @param {vec3} out_axis Vector receiving the axis of rotation
75
+ * @param {ReadonlyQuat} q Quaternion to be decomposed
76
+ * @return {Number} Angle, in radians, of the rotation
77
+ */
78
+ export function getAxisAngle(out_axis, q) {
79
+ const rad = Math.acos(q[3]) * 2.0;
80
+ const s = Math.sin(rad / 2.0);
81
+ if (s > glMatrix.EPSILON) {
82
+ out_axis[0] = q[0] / s;
83
+ out_axis[1] = q[1] / s;
84
+ out_axis[2] = q[2] / s;
85
+ } else {
86
+ // If s is zero, return any axis (no rotation - axis does not matter)
87
+ out_axis[0] = 1;
88
+ out_axis[1] = 0;
89
+ out_axis[2] = 0;
90
+ }
91
+ return rad;
92
+ }
93
+
94
+ /**
95
+ * Gets the angular distance between two unit quaternions
96
+ *
97
+ * @param {ReadonlyQuat} a Origin unit quaternion
98
+ * @param {ReadonlyQuat} b Destination unit quaternion
99
+ * @return {Number} Angle, in radians, between the two quaternions
100
+ */
101
+ export function getAngle(a, b) {
102
+ const dotproduct = dot(a, b);
103
+
104
+ return Math.acos(2 * dotproduct * dotproduct - 1);
105
+ }
106
+
107
+ /**
108
+ * Multiplies two quat's
109
+ *
110
+ * @param {quat} out the receiving quaternion
111
+ * @param {ReadonlyQuat} a the first operand
112
+ * @param {ReadonlyQuat} b the second operand
113
+ * @returns {quat} out
114
+ */
115
+ export function multiply(out, a, b) {
116
+ const ax = a[0];
117
+ const ay = a[1];
118
+ const az = a[2];
119
+ const aw = a[3];
120
+ const bx = b[0];
121
+ const by = b[1];
122
+ const bz = b[2];
123
+ const bw = b[3];
124
+
125
+ out[0] = ax * bw + aw * bx + ay * bz - az * by;
126
+ out[1] = ay * bw + aw * by + az * bx - ax * bz;
127
+ out[2] = az * bw + aw * bz + ax * by - ay * bx;
128
+ out[3] = aw * bw - ax * bx - ay * by - az * bz;
129
+ return out;
130
+ }
131
+
132
+ /**
133
+ * Rotates a quaternion by the given angle about the X axis
134
+ *
135
+ * @param {quat} out quat receiving operation result
136
+ * @param {ReadonlyQuat} a quat to rotate
137
+ * @param {number} rad angle (in radians) to rotate
138
+ * @returns {quat} out
139
+ */
140
+ export function rotateX(out, a, rad) {
141
+ rad *= 0.5;
142
+
143
+ const ax = a[0];
144
+ const ay = a[1];
145
+ const az = a[2];
146
+ const aw = a[3];
147
+ const bx = Math.sin(rad);
148
+ const bw = Math.cos(rad);
149
+
150
+ out[0] = ax * bw + aw * bx;
151
+ out[1] = ay * bw + az * bx;
152
+ out[2] = az * bw - ay * bx;
153
+ out[3] = aw * bw - ax * bx;
154
+ return out;
155
+ }
156
+
157
+ /**
158
+ * Rotates a quaternion by the given angle about the Y axis
159
+ *
160
+ * @param {quat} out quat receiving operation result
161
+ * @param {ReadonlyQuat} a quat to rotate
162
+ * @param {number} rad angle (in radians) to rotate
163
+ * @returns {quat} out
164
+ */
165
+ export function rotateY(out, a, rad) {
166
+ rad *= 0.5;
167
+
168
+ const ax = a[0];
169
+ const ay = a[1];
170
+ const az = a[2];
171
+ const aw = a[3];
172
+ const by = Math.sin(rad);
173
+ const bw = Math.cos(rad);
174
+
175
+ out[0] = ax * bw - az * by;
176
+ out[1] = ay * bw + aw * by;
177
+ out[2] = az * bw + ax * by;
178
+ out[3] = aw * bw - ay * by;
179
+ return out;
180
+ }
181
+
182
+ /**
183
+ * Rotates a quaternion by the given angle about the Z axis
184
+ *
185
+ * @param {quat} out quat receiving operation result
186
+ * @param {ReadonlyQuat} a quat to rotate
187
+ * @param {number} rad angle (in radians) to rotate
188
+ * @returns {quat} out
189
+ */
190
+ export function rotateZ(out, a, rad) {
191
+ rad *= 0.5;
192
+
193
+ const ax = a[0];
194
+ const ay = a[1];
195
+ const az = a[2];
196
+ const aw = a[3];
197
+ const bz = Math.sin(rad);
198
+ const bw = Math.cos(rad);
199
+
200
+ out[0] = ax * bw + ay * bz;
201
+ out[1] = ay * bw - ax * bz;
202
+ out[2] = az * bw + aw * bz;
203
+ out[3] = aw * bw - az * bz;
204
+ return out;
205
+ }
206
+
207
+ /**
208
+ * Calculates the W component of a quat from the X, Y, and Z components.
209
+ * Assumes that quaternion is 1 unit in length.
210
+ * Any existing W component will be ignored.
211
+ *
212
+ * @param {quat} out the receiving quaternion
213
+ * @param {ReadonlyQuat} a quat to calculate W component of
214
+ * @returns {quat} out
215
+ */
216
+ export function calculateW(out, a) {
217
+ const x = a[0];
218
+ const y = a[1];
219
+ const z = a[2];
220
+
221
+ out[0] = x;
222
+ out[1] = y;
223
+ out[2] = z;
224
+ out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));
225
+ return out;
226
+ }
227
+
228
+ /**
229
+ * Calculate the exponential of a unit quaternion.
230
+ *
231
+ * @param {quat} out the receiving quaternion
232
+ * @param {ReadonlyQuat} a quat to calculate the exponential of
233
+ * @returns {quat} out
234
+ */
235
+ export function exp(out, a) {
236
+ const x = a[0];
237
+ const y = a[1];
238
+ const z = a[2];
239
+ const w = a[3];
240
+
241
+ const r = Math.sqrt(x * x + y * y + z * z);
242
+ const et = Math.exp(w);
243
+ const s = r > 0 ? (et * Math.sin(r)) / r : 0;
244
+
245
+ out[0] = x * s;
246
+ out[1] = y * s;
247
+ out[2] = z * s;
248
+ out[3] = et * Math.cos(r);
249
+
250
+ return out;
251
+ }
252
+
253
+ /**
254
+ * Calculate the natural logarithm of a unit quaternion.
255
+ *
256
+ * @param {quat} out the receiving quaternion
257
+ * @param {ReadonlyQuat} a quat to calculate the exponential of
258
+ * @returns {quat} out
259
+ */
260
+ export function ln(out, a) {
261
+ const x = a[0];
262
+ const y = a[1];
263
+ const z = a[2];
264
+ const w = a[3];
265
+
266
+ const r = Math.sqrt(x * x + y * y + z * z);
267
+ const t = r > 0 ? Math.atan2(r, w) / r : 0;
268
+
269
+ out[0] = x * t;
270
+ out[1] = y * t;
271
+ out[2] = z * t;
272
+ out[3] = 0.5 * Math.log(x * x + y * y + z * z + w * w);
273
+
274
+ return out;
275
+ }
276
+
277
+ /**
278
+ * Calculate the scalar power of a unit quaternion.
279
+ *
280
+ * @param {quat} out the receiving quaternion
281
+ * @param {ReadonlyQuat} a quat to calculate the exponential of
282
+ * @param {Number} b amount to scale the quaternion by
283
+ * @returns {quat} out
284
+ */
285
+ export function pow(out, a, b) {
286
+ ln(out, a);
287
+ scale(out, out, b);
288
+ exp(out, out);
289
+ return out;
290
+ }
291
+
292
+ /**
293
+ * Performs a spherical linear interpolation between two quat
294
+ *
295
+ * @param {quat} out the receiving quaternion
296
+ * @param {ReadonlyQuat} a the first operand
297
+ * @param {ReadonlyQuat} b the second operand
298
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
299
+ * @returns {quat} out
300
+ */
301
+ export function slerp(out, a, b, t) {
302
+ // benchmarks:
303
+ // http://jsperf.com/quaternion-slerp-implementations
304
+ const ax = a[0];
305
+ const ay = a[1];
306
+ const az = a[2];
307
+ const aw = a[3];
308
+ let bx = b[0];
309
+ let by = b[1];
310
+ let bz = b[2];
311
+ let bw = b[3];
312
+
313
+ let cosom;
314
+ let omega;
315
+ let scale0;
316
+ let scale1;
317
+ let sinom;
318
+
319
+ // calc cosine
320
+ cosom = ax * bx + ay * by + az * bz + aw * bw;
321
+ // adjust signs (if necessary)
322
+ if (cosom < 0.0) {
323
+ cosom = -cosom;
324
+ bx = -bx;
325
+ by = -by;
326
+ bz = -bz;
327
+ bw = -bw;
328
+ }
329
+ // calculate coefficients
330
+ if (1.0 - cosom > glMatrix.EPSILON) {
331
+ // standard case (slerp)
332
+ omega = Math.acos(cosom);
333
+ sinom = Math.sin(omega);
334
+ scale0 = Math.sin((1.0 - t) * omega) / sinom;
335
+ scale1 = Math.sin(t * omega) / sinom;
336
+ } else {
337
+ // "from" and "to" quaternions are very close
338
+ // ... so we can do a linear interpolation
339
+ scale0 = 1.0 - t;
340
+ scale1 = t;
341
+ }
342
+ // calculate final values
343
+ out[0] = scale0 * ax + scale1 * bx;
344
+ out[1] = scale0 * ay + scale1 * by;
345
+ out[2] = scale0 * az + scale1 * bz;
346
+ out[3] = scale0 * aw + scale1 * bw;
347
+
348
+ return out;
349
+ }
350
+
351
+ /**
352
+ * Generates a random unit quaternion
353
+ *
354
+ * @param {quat} out the receiving quaternion
355
+ * @returns {quat} out
356
+ */
357
+ // export function random(out) {
358
+ // // Implementation of http://planning.cs.uiuc.edu/node198.html
359
+ // // TODO: Calling random 3 times is probably not the fastest solution
360
+ // let u1 = glMatrix.RANDOM();
361
+ // let u2 = glMatrix.RANDOM();
362
+ // let u3 = glMatrix.RANDOM();
363
+
364
+ // let sqrt1MinusU1 = Math.sqrt(1 - u1);
365
+ // let sqrtU1 = Math.sqrt(u1);
366
+
367
+ // out[0] = sqrt1MinusU1 * Math.sin(2.0 * Math.PI * u2);
368
+ // out[1] = sqrt1MinusU1 * Math.cos(2.0 * Math.PI * u2);
369
+ // out[2] = sqrtU1 * Math.sin(2.0 * Math.PI * u3);
370
+ // out[3] = sqrtU1 * Math.cos(2.0 * Math.PI * u3);
371
+ // return out;
372
+ // }
373
+
374
+ /**
375
+ * Calculates the inverse of a quat
376
+ *
377
+ * @param {quat} out the receiving quaternion
378
+ * @param {ReadonlyQuat} a quat to calculate inverse of
379
+ * @returns {quat} out
380
+ */
381
+ export function invert(out, a) {
382
+ const a0 = a[0];
383
+ const a1 = a[1];
384
+ const a2 = a[2];
385
+ const a3 = a[3];
386
+ const dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
387
+ const invDot = dot ? 1.0 / dot : 0;
388
+
389
+ // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0
390
+
391
+ out[0] = -a0 * invDot;
392
+ out[1] = -a1 * invDot;
393
+ out[2] = -a2 * invDot;
394
+ out[3] = a3 * invDot;
395
+ return out;
396
+ }
397
+
398
+ /**
399
+ * Calculates the conjugate of a quat
400
+ * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
401
+ *
402
+ * @param {quat} out the receiving quaternion
403
+ * @param {ReadonlyQuat} a quat to calculate conjugate of
404
+ * @returns {quat} out
405
+ */
406
+ export function conjugate(out, a) {
407
+ out[0] = -a[0];
408
+ out[1] = -a[1];
409
+ out[2] = -a[2];
410
+ out[3] = a[3];
411
+ return out;
412
+ }
413
+
414
+ /**
415
+ * Creates a quaternion from the given 3x3 rotation matrix.
416
+ *
417
+ * NOTE: The resultant quaternion is not normalized, so you should be sure
418
+ * to renormalize the quaternion yourself where necessary.
419
+ *
420
+ * @param {quat} out the receiving quaternion
421
+ * @param {ReadonlyMat3} m rotation matrix
422
+ * @returns {quat} out
423
+ * @function
424
+ */
425
+ export function fromMat3(out, m) {
426
+ // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
427
+ // article "Quaternion Calculus and Fast Animation".
428
+ const fTrace = m[0] + m[4] + m[8];
429
+ let fRoot;
430
+
431
+ if (fTrace > 0.0) {
432
+ // |w| > 1/2, may as well choose w > 1/2
433
+ fRoot = Math.sqrt(fTrace + 1.0); // 2w
434
+ out[3] = 0.5 * fRoot;
435
+ fRoot = 0.5 / fRoot; // 1/(4w)
436
+ out[0] = (m[5] - m[7]) * fRoot;
437
+ out[1] = (m[6] - m[2]) * fRoot;
438
+ out[2] = (m[1] - m[3]) * fRoot;
439
+ } else {
440
+ // |w| <= 1/2
441
+ let i = 0;
442
+ if (m[4] > m[0]) i = 1;
443
+ if (m[8] > m[i * 3 + i]) i = 2;
444
+ const j = (i + 1) % 3;
445
+ const k = (i + 2) % 3;
446
+
447
+ fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);
448
+ out[i] = 0.5 * fRoot;
449
+ fRoot = 0.5 / fRoot;
450
+ out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
451
+ out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
452
+ out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
453
+ }
454
+
455
+ return out;
456
+ }
457
+
458
+ /**
459
+ * Creates a quaternion from the given euler angle x, y, z using the provided intrinsic order for the conversion.
460
+ *
461
+ * @param {quat} out the receiving quaternion
462
+ * @param {Number} x Angle to rotate around X axis in degrees.
463
+ * @param {Number} y Angle to rotate around Y axis in degrees.
464
+ * @param {Number} z Angle to rotate around Z axis in degrees.
465
+ * @param {'zyx'|'xyz'|'yxz'|'yzx'|'zxy'|'zyx'} order Intrinsic order for conversion, default is zyx.
466
+ * @returns {quat} out
467
+ * @function
468
+ */
469
+ // export function fromEuler(out, x, y, z, order = glMatrix.ANGLE_ORDER) {
470
+ // let halfToRad = Math.PI / 360;
471
+ // x *= halfToRad;
472
+ // z *= halfToRad;
473
+ // y *= halfToRad;
474
+
475
+ // let sx = Math.sin(x);
476
+ // let cx = Math.cos(x);
477
+ // let sy = Math.sin(y);
478
+ // let cy = Math.cos(y);
479
+ // let sz = Math.sin(z);
480
+ // let cz = Math.cos(z);
481
+
482
+ // switch (order) {
483
+ // case "xyz":
484
+ // out[0] = sx * cy * cz + cx * sy * sz;
485
+ // out[1] = cx * sy * cz - sx * cy * sz;
486
+ // out[2] = cx * cy * sz + sx * sy * cz;
487
+ // out[3] = cx * cy * cz - sx * sy * sz;
488
+ // break;
489
+
490
+ // case "xzy":
491
+ // out[0] = sx * cy * cz - cx * sy * sz;
492
+ // out[1] = cx * sy * cz - sx * cy * sz;
493
+ // out[2] = cx * cy * sz + sx * sy * cz;
494
+ // out[3] = cx * cy * cz + sx * sy * sz;
495
+ // break;
496
+
497
+ // case "yxz":
498
+ // out[0] = sx * cy * cz + cx * sy * sz;
499
+ // out[1] = cx * sy * cz - sx * cy * sz;
500
+ // out[2] = cx * cy * sz - sx * sy * cz;
501
+ // out[3] = cx * cy * cz + sx * sy * sz;
502
+ // break;
503
+
504
+ // case "yzx":
505
+ // out[0] = sx * cy * cz + cx * sy * sz;
506
+ // out[1] = cx * sy * cz + sx * cy * sz;
507
+ // out[2] = cx * cy * sz - sx * sy * cz;
508
+ // out[3] = cx * cy * cz - sx * sy * sz;
509
+ // break;
510
+
511
+ // case "zxy":
512
+ // out[0] = sx * cy * cz - cx * sy * sz;
513
+ // out[1] = cx * sy * cz + sx * cy * sz;
514
+ // out[2] = cx * cy * sz + sx * sy * cz;
515
+ // out[3] = cx * cy * cz - sx * sy * sz;
516
+ // break;
517
+
518
+ // case "zyx":
519
+ // out[0] = sx * cy * cz - cx * sy * sz;
520
+ // out[1] = cx * sy * cz + sx * cy * sz;
521
+ // out[2] = cx * cy * sz - sx * sy * cz;
522
+ // out[3] = cx * cy * cz + sx * sy * sz;
523
+ // break;
524
+
525
+ // default:
526
+ // throw new Error('Unknown angle order ' + order);
527
+ // }
528
+
529
+ // return out;
530
+ // }
531
+
532
+ /**
533
+ * Returns a string representation of a quaternion
534
+ *
535
+ * @param {ReadonlyQuat} a vector to represent as a string
536
+ * @returns {String} string representation of the vector
537
+ */
538
+ export function str(a) {
539
+ return `quat(${a[0]}, ${a[1]}, ${a[2]}, ${a[3]})`;
540
+ }
541
+
542
+ /**
543
+ * Creates a new quat initialized with values from an existing quaternion
544
+ *
545
+ * @param {ReadonlyQuat} a quaternion to clone
546
+ * @returns {quat} a new quaternion
547
+ * @function
548
+ */
549
+ export const clone = vec4.clone;
550
+
551
+ /**
552
+ * Creates a new quat initialized with the given values
553
+ *
554
+ * @param {Number} x X component
555
+ * @param {Number} y Y component
556
+ * @param {Number} z Z component
557
+ * @param {Number} w W component
558
+ * @returns {quat} a new quaternion
559
+ * @function
560
+ */
561
+ export const fromValues = vec4.fromValues;
562
+
563
+ /**
564
+ * Copy the values from one quat to another
565
+ *
566
+ * @param {quat} out the receiving quaternion
567
+ * @param {ReadonlyQuat} a the source quaternion
568
+ * @returns {quat} out
569
+ * @function
570
+ */
571
+ export const copy = vec4.copy;
572
+
573
+ /**
574
+ * Set the components of a quat to the given values
575
+ *
576
+ * @param {quat} out the receiving quaternion
577
+ * @param {Number} x X component
578
+ * @param {Number} y Y component
579
+ * @param {Number} z Z component
580
+ * @param {Number} w W component
581
+ * @returns {quat} out
582
+ * @function
583
+ */
584
+ export const set = vec4.set;
585
+
586
+ /**
587
+ * Adds two quat's
588
+ *
589
+ * @param {quat} out the receiving quaternion
590
+ * @param {ReadonlyQuat} a the first operand
591
+ * @param {ReadonlyQuat} b the second operand
592
+ * @returns {quat} out
593
+ * @function
594
+ */
595
+ export const add = vec4.add;
596
+
597
+ /**
598
+ * Alias for {@link quat.multiply}
599
+ * @function
600
+ */
601
+ export const mul = multiply;
602
+
603
+ /**
604
+ * Scales a quat by a scalar number
605
+ *
606
+ * @param {quat} out the receiving vector
607
+ * @param {ReadonlyQuat} a the vector to scale
608
+ * @param {Number} b amount to scale the vector by
609
+ * @returns {quat} out
610
+ * @function
611
+ */
612
+ export const scale = vec4.scale;
613
+
614
+ /**
615
+ * Calculates the dot product of two quat's
616
+ *
617
+ * @param {ReadonlyQuat} a the first operand
618
+ * @param {ReadonlyQuat} b the second operand
619
+ * @returns {Number} dot product of a and b
620
+ * @function
621
+ */
622
+ export const dot = vec4.dot;
623
+
624
+ /**
625
+ * Performs a linear interpolation between two quat's
626
+ *
627
+ * @param {quat} out the receiving quaternion
628
+ * @param {ReadonlyQuat} a the first operand
629
+ * @param {ReadonlyQuat} b the second operand
630
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
631
+ * @returns {quat} out
632
+ * @function
633
+ */
634
+ export const lerp = vec4.lerp;
635
+
636
+ /**
637
+ * Calculates the length of a quat
638
+ *
639
+ * @param {ReadonlyQuat} a vector to calculate length of
640
+ * @returns {Number} length of a
641
+ */
642
+ export const length = vec4.length;
643
+
644
+ /**
645
+ * Alias for {@link quat.length}
646
+ * @function
647
+ */
648
+ export const len = length;
649
+
650
+ /**
651
+ * Calculates the squared length of a quat
652
+ *
653
+ * @param {ReadonlyQuat} a vector to calculate squared length of
654
+ * @returns {Number} squared length of a
655
+ * @function
656
+ */
657
+ export const squaredLength = vec4.squaredLength;
658
+
659
+ /**
660
+ * Alias for {@link quat.squaredLength}
661
+ * @function
662
+ */
663
+ export const sqrLen = squaredLength;
664
+
665
+ /**
666
+ * Normalize a quat
667
+ *
668
+ * @param {quat} out the receiving quaternion
669
+ * @param {ReadonlyQuat} a quaternion to normalize
670
+ * @returns {quat} out
671
+ * @function
672
+ */
673
+ export const normalize = vec4.normalize;
674
+
675
+ /**
676
+ * Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===)
677
+ *
678
+ * @param {ReadonlyQuat} a The first quaternion.
679
+ * @param {ReadonlyQuat} b The second quaternion.
680
+ * @returns {Boolean} True if the vectors are equal, false otherwise.
681
+ */
682
+ export const exactEquals = vec4.exactEquals;
683
+
684
+ /**
685
+ * Returns whether or not the quaternions point approximately to the same direction.
686
+ *
687
+ * Both quaternions are assumed to be unit length.
688
+ *
689
+ * @param {ReadonlyQuat} a The first unit quaternion.
690
+ * @param {ReadonlyQuat} b The second unit quaternion.
691
+ * @returns {Boolean} True if the quaternions are equal, false otherwise.
692
+ */
693
+ export function equals(a, b) {
694
+ return Math.abs(vec4.dot(a, b)) >= 1 - glMatrix.EPSILON;
695
+ }
696
+
697
+ /**
698
+ * Sets a quaternion to represent the shortest rotation from one
699
+ * vector to another.
700
+ *
701
+ * Both vectors are assumed to be unit length.
702
+ *
703
+ * @param {quat} out the receiving quaternion.
704
+ * @param {ReadonlyVec3} a the initial vector
705
+ * @param {ReadonlyVec3} b the destination vector
706
+ * @returns {quat} out
707
+ */
708
+ export const rotationTo = (function () {
709
+ const tmpvec3 = vec3.create();
710
+ const xUnitVec3 = vec3.fromValues(1, 0, 0);
711
+ const yUnitVec3 = vec3.fromValues(0, 1, 0);
712
+
713
+ return function (out, a, b) {
714
+ const dot = vec3.dot(a, b);
715
+ if (dot < -0.999999) {
716
+ vec3.cross(tmpvec3, xUnitVec3, a);
717
+ if (vec3.len(tmpvec3) < 0.000001) vec3.cross(tmpvec3, yUnitVec3, a);
718
+ vec3.normalize(tmpvec3, tmpvec3);
719
+ setAxisAngle(out, tmpvec3, Math.PI);
720
+ return out;
721
+ } else if (dot > 0.999999) {
722
+ out[0] = 0;
723
+ out[1] = 0;
724
+ out[2] = 0;
725
+ out[3] = 1;
726
+ return out;
727
+ }
728
+ vec3.cross(tmpvec3, a, b);
729
+ out[0] = tmpvec3[0];
730
+ out[1] = tmpvec3[1];
731
+ out[2] = tmpvec3[2];
732
+ out[3] = 1 + dot;
733
+ return normalize(out, out);
734
+ };
735
+ })();
736
+
737
+ /**
738
+ * Performs a spherical linear interpolation with two control points
739
+ *
740
+ * @param {quat} out the receiving quaternion
741
+ * @param {ReadonlyQuat} a the first operand
742
+ * @param {ReadonlyQuat} b the second operand
743
+ * @param {ReadonlyQuat} c the third operand
744
+ * @param {ReadonlyQuat} d the fourth operand
745
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
746
+ * @returns {quat} out
747
+ */
748
+ export const sqlerp = (function () {
749
+ const temp1 = create();
750
+ const temp2 = create();
751
+
752
+ return function (out, a, b, c, d, t) {
753
+ slerp(temp1, a, d, t);
754
+ slerp(temp2, b, c, t);
755
+ slerp(out, temp1, temp2, 2 * t * (1 - t));
756
+
757
+ return out;
758
+ };
759
+ })();
760
+
761
+ /**
762
+ * Sets the specified quaternion with values corresponding to the given
763
+ * axes. Each axis is a vec3 and is expected to be unit length and
764
+ * perpendicular to all other specified axes.
765
+ *
766
+ * @param {ReadonlyVec3} view the vector representing the viewing direction
767
+ * @param {ReadonlyVec3} right the vector representing the local "right" direction
768
+ * @param {ReadonlyVec3} up the vector representing the local "up" direction
769
+ * @returns {quat} out
770
+ */
771
+ export const setAxes = (function () {
772
+ const matr = mat3.create();
773
+
774
+ return function (out, view, right, up) {
775
+ matr[0] = right[0];
776
+ matr[3] = right[1];
777
+ matr[6] = right[2];
778
+
779
+ matr[1] = up[0];
780
+ matr[4] = up[1];
781
+ matr[7] = up[2];
782
+
783
+ matr[2] = -view[0];
784
+ matr[5] = -view[1];
785
+ matr[8] = -view[2];
786
+
787
+ return normalize(out, fromMat3(out, matr));
788
+ };
789
+ })();