@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,842 @@
1
+ import * as glMatrix from './common.js';
2
+
3
+ /**
4
+ * 3x3 Matrix
5
+ * @module mat3
6
+ */
7
+
8
+ /**
9
+ * Creates a new identity mat3
10
+ *
11
+ * @returns {mat3} a new 3x3 matrix
12
+ */
13
+ export function create() {
14
+ const out = new glMatrix.ARRAY_TYPE(9);
15
+ if (glMatrix.ARRAY_TYPE != Float32Array) {
16
+ out[1] = 0;
17
+ out[2] = 0;
18
+ out[3] = 0;
19
+ out[5] = 0;
20
+ out[6] = 0;
21
+ out[7] = 0;
22
+ }
23
+ out[0] = 1;
24
+ out[4] = 1;
25
+ out[8] = 1;
26
+ return out;
27
+ }
28
+
29
+ /**
30
+ * Copies the upper-left 3x3 values into the given mat3.
31
+ *
32
+ * @param {mat3} out the receiving 3x3 matrix
33
+ * @param {ReadonlyMat4} a the source 4x4 matrix
34
+ * @returns {mat3} out
35
+ */
36
+ export function fromMat4(out, a) {
37
+ out[0] = a[0];
38
+ out[1] = a[1];
39
+ out[2] = a[2];
40
+ out[3] = a[4];
41
+ out[4] = a[5];
42
+ out[5] = a[6];
43
+ out[6] = a[8];
44
+ out[7] = a[9];
45
+ out[8] = a[10];
46
+ return out;
47
+ }
48
+
49
+ /**
50
+ * Creates a new mat3 initialized with values from an existing matrix
51
+ *
52
+ * @param {ReadonlyMat3} a matrix to clone
53
+ * @returns {mat3} a new 3x3 matrix
54
+ */
55
+ export function clone(a) {
56
+ const out = new glMatrix.ARRAY_TYPE(9);
57
+ out[0] = a[0];
58
+ out[1] = a[1];
59
+ out[2] = a[2];
60
+ out[3] = a[3];
61
+ out[4] = a[4];
62
+ out[5] = a[5];
63
+ out[6] = a[6];
64
+ out[7] = a[7];
65
+ out[8] = a[8];
66
+ return out;
67
+ }
68
+
69
+ /**
70
+ * Copy the values from one mat3 to another
71
+ *
72
+ * @param {mat3} out the receiving matrix
73
+ * @param {ReadonlyMat3} a the source matrix
74
+ * @returns {mat3} out
75
+ */
76
+ export function copy(out, a) {
77
+ out[0] = a[0];
78
+ out[1] = a[1];
79
+ out[2] = a[2];
80
+ out[3] = a[3];
81
+ out[4] = a[4];
82
+ out[5] = a[5];
83
+ out[6] = a[6];
84
+ out[7] = a[7];
85
+ out[8] = a[8];
86
+ return out;
87
+ }
88
+
89
+ /**
90
+ * Create a new mat3 with the given values
91
+ *
92
+ * @param {Number} m00 Component in column 0, row 0 position (index 0)
93
+ * @param {Number} m01 Component in column 0, row 1 position (index 1)
94
+ * @param {Number} m02 Component in column 0, row 2 position (index 2)
95
+ * @param {Number} m10 Component in column 1, row 0 position (index 3)
96
+ * @param {Number} m11 Component in column 1, row 1 position (index 4)
97
+ * @param {Number} m12 Component in column 1, row 2 position (index 5)
98
+ * @param {Number} m20 Component in column 2, row 0 position (index 6)
99
+ * @param {Number} m21 Component in column 2, row 1 position (index 7)
100
+ * @param {Number} m22 Component in column 2, row 2 position (index 8)
101
+ * @returns {mat3} A new mat3
102
+ */
103
+ export function fromValues(m00, m01, m02, m10, m11, m12, m20, m21, m22) {
104
+ const out = new glMatrix.ARRAY_TYPE(9);
105
+ out[0] = m00;
106
+ out[1] = m01;
107
+ out[2] = m02;
108
+ out[3] = m10;
109
+ out[4] = m11;
110
+ out[5] = m12;
111
+ out[6] = m20;
112
+ out[7] = m21;
113
+ out[8] = m22;
114
+ return out;
115
+ }
116
+
117
+ /**
118
+ * Set the components of a mat3 to the given values
119
+ *
120
+ * @param {mat3} out the receiving matrix
121
+ * @param {Number} m00 Component in column 0, row 0 position (index 0)
122
+ * @param {Number} m01 Component in column 0, row 1 position (index 1)
123
+ * @param {Number} m02 Component in column 0, row 2 position (index 2)
124
+ * @param {Number} m10 Component in column 1, row 0 position (index 3)
125
+ * @param {Number} m11 Component in column 1, row 1 position (index 4)
126
+ * @param {Number} m12 Component in column 1, row 2 position (index 5)
127
+ * @param {Number} m20 Component in column 2, row 0 position (index 6)
128
+ * @param {Number} m21 Component in column 2, row 1 position (index 7)
129
+ * @param {Number} m22 Component in column 2, row 2 position (index 8)
130
+ * @returns {mat3} out
131
+ */
132
+ export function set(out, m00, m01, m02, m10, m11, m12, m20, m21, m22) {
133
+ out[0] = m00;
134
+ out[1] = m01;
135
+ out[2] = m02;
136
+ out[3] = m10;
137
+ out[4] = m11;
138
+ out[5] = m12;
139
+ out[6] = m20;
140
+ out[7] = m21;
141
+ out[8] = m22;
142
+ return out;
143
+ }
144
+
145
+ /**
146
+ * Set a mat3 to the identity matrix
147
+ *
148
+ * @param {mat3} out the receiving matrix
149
+ * @returns {mat3} out
150
+ */
151
+ export function identity(out) {
152
+ out[0] = 1;
153
+ out[1] = 0;
154
+ out[2] = 0;
155
+ out[3] = 0;
156
+ out[4] = 1;
157
+ out[5] = 0;
158
+ out[6] = 0;
159
+ out[7] = 0;
160
+ out[8] = 1;
161
+ return out;
162
+ }
163
+
164
+ /**
165
+ * Transpose the values of a mat3
166
+ *
167
+ * @param {mat3} out the receiving matrix
168
+ * @param {ReadonlyMat3} a the source matrix
169
+ * @returns {mat3} out
170
+ */
171
+ export function transpose(out, a) {
172
+ // If we are transposing ourselves we can skip a few steps but have to cache some values
173
+ if (out === a) {
174
+ const a01 = a[1];
175
+ const a02 = a[2];
176
+ const a12 = a[5];
177
+ out[1] = a[3];
178
+ out[2] = a[6];
179
+ out[3] = a01;
180
+ out[5] = a[7];
181
+ out[6] = a02;
182
+ out[7] = a12;
183
+ } else {
184
+ out[0] = a[0];
185
+ out[1] = a[3];
186
+ out[2] = a[6];
187
+ out[3] = a[1];
188
+ out[4] = a[4];
189
+ out[5] = a[7];
190
+ out[6] = a[2];
191
+ out[7] = a[5];
192
+ out[8] = a[8];
193
+ }
194
+
195
+ return out;
196
+ }
197
+
198
+ /**
199
+ * Inverts a mat3
200
+ *
201
+ * @param {mat3} out the receiving matrix
202
+ * @param {ReadonlyMat3} a the source matrix
203
+ * @returns {mat3} out
204
+ */
205
+ export function invert(out, a) {
206
+ const a00 = a[0];
207
+ const a01 = a[1];
208
+ const a02 = a[2];
209
+ const a10 = a[3];
210
+ const a11 = a[4];
211
+ const a12 = a[5];
212
+ const a20 = a[6];
213
+ const a21 = a[7];
214
+ const a22 = a[8];
215
+
216
+ const b01 = a22 * a11 - a12 * a21;
217
+ const b11 = -a22 * a10 + a12 * a20;
218
+ const b21 = a21 * a10 - a11 * a20;
219
+
220
+ // Calculate the determinant
221
+ let det = a00 * b01 + a01 * b11 + a02 * b21;
222
+
223
+ if (!det) {
224
+ return null;
225
+ }
226
+ det = 1.0 / det;
227
+
228
+ out[0] = b01 * det;
229
+ out[1] = (-a22 * a01 + a02 * a21) * det;
230
+ out[2] = (a12 * a01 - a02 * a11) * det;
231
+ out[3] = b11 * det;
232
+ out[4] = (a22 * a00 - a02 * a20) * det;
233
+ out[5] = (-a12 * a00 + a02 * a10) * det;
234
+ out[6] = b21 * det;
235
+ out[7] = (-a21 * a00 + a01 * a20) * det;
236
+ out[8] = (a11 * a00 - a01 * a10) * det;
237
+ return out;
238
+ }
239
+
240
+ /**
241
+ * Calculates the adjugate of a mat3
242
+ *
243
+ * @param {mat3} out the receiving matrix
244
+ * @param {ReadonlyMat3} a the source matrix
245
+ * @returns {mat3} out
246
+ */
247
+ export function adjoint(out, a) {
248
+ const a00 = a[0];
249
+ const a01 = a[1];
250
+ const a02 = a[2];
251
+ const a10 = a[3];
252
+ const a11 = a[4];
253
+ const a12 = a[5];
254
+ const a20 = a[6];
255
+ const a21 = a[7];
256
+ const a22 = a[8];
257
+
258
+ out[0] = a11 * a22 - a12 * a21;
259
+ out[1] = a02 * a21 - a01 * a22;
260
+ out[2] = a01 * a12 - a02 * a11;
261
+ out[3] = a12 * a20 - a10 * a22;
262
+ out[4] = a00 * a22 - a02 * a20;
263
+ out[5] = a02 * a10 - a00 * a12;
264
+ out[6] = a10 * a21 - a11 * a20;
265
+ out[7] = a01 * a20 - a00 * a21;
266
+ out[8] = a00 * a11 - a01 * a10;
267
+ return out;
268
+ }
269
+
270
+ /**
271
+ * Calculates the determinant of a mat3
272
+ *
273
+ * @param {ReadonlyMat3} a the source matrix
274
+ * @returns {Number} determinant of a
275
+ */
276
+ export function determinant(a) {
277
+ const a00 = a[0];
278
+ const a01 = a[1];
279
+ const a02 = a[2];
280
+ const a10 = a[3];
281
+ const a11 = a[4];
282
+ const a12 = a[5];
283
+ const a20 = a[6];
284
+ const a21 = a[7];
285
+ const a22 = a[8];
286
+
287
+ return (
288
+ a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20)
289
+ );
290
+ }
291
+
292
+ /**
293
+ * Multiplies two mat3's
294
+ *
295
+ * @param {mat3} out the receiving matrix
296
+ * @param {ReadonlyMat3} a the first operand
297
+ * @param {ReadonlyMat3} b the second operand
298
+ * @returns {mat3} out
299
+ */
300
+ export function multiply(out, a, b) {
301
+ const a00 = a[0];
302
+ const a01 = a[1];
303
+ const a02 = a[2];
304
+ const a10 = a[3];
305
+ const a11 = a[4];
306
+ const a12 = a[5];
307
+ const a20 = a[6];
308
+ const a21 = a[7];
309
+ const a22 = a[8];
310
+
311
+ const b00 = b[0];
312
+ const b01 = b[1];
313
+ const b02 = b[2];
314
+ const b10 = b[3];
315
+ const b11 = b[4];
316
+ const b12 = b[5];
317
+ const b20 = b[6];
318
+ const b21 = b[7];
319
+ const b22 = b[8];
320
+
321
+ out[0] = b00 * a00 + b01 * a10 + b02 * a20;
322
+ out[1] = b00 * a01 + b01 * a11 + b02 * a21;
323
+ out[2] = b00 * a02 + b01 * a12 + b02 * a22;
324
+
325
+ out[3] = b10 * a00 + b11 * a10 + b12 * a20;
326
+ out[4] = b10 * a01 + b11 * a11 + b12 * a21;
327
+ out[5] = b10 * a02 + b11 * a12 + b12 * a22;
328
+
329
+ out[6] = b20 * a00 + b21 * a10 + b22 * a20;
330
+ out[7] = b20 * a01 + b21 * a11 + b22 * a21;
331
+ out[8] = b20 * a02 + b21 * a12 + b22 * a22;
332
+ return out;
333
+ }
334
+
335
+ /**
336
+ * Translate a mat3 by the given vector
337
+ *
338
+ * @param {mat3} out the receiving matrix
339
+ * @param {ReadonlyMat3} a the matrix to translate
340
+ * @param {ReadonlyVec2} v vector to translate by
341
+ * @returns {mat3} out
342
+ */
343
+ export function translate(out, a, v) {
344
+ const a00 = a[0];
345
+ const a01 = a[1];
346
+ const a02 = a[2];
347
+ const a10 = a[3];
348
+ const a11 = a[4];
349
+ const a12 = a[5];
350
+ const a20 = a[6];
351
+ const a21 = a[7];
352
+ const a22 = a[8];
353
+ const x = v[0];
354
+ const y = v[1];
355
+
356
+ out[0] = a00;
357
+ out[1] = a01;
358
+ out[2] = a02;
359
+
360
+ out[3] = a10;
361
+ out[4] = a11;
362
+ out[5] = a12;
363
+
364
+ out[6] = x * a00 + y * a10 + a20;
365
+ out[7] = x * a01 + y * a11 + a21;
366
+ out[8] = x * a02 + y * a12 + a22;
367
+ return out;
368
+ }
369
+
370
+ /**
371
+ * Rotates a mat3 by the given angle
372
+ *
373
+ * @param {mat3} out the receiving matrix
374
+ * @param {ReadonlyMat3} a the matrix to rotate
375
+ * @param {Number} rad the angle to rotate the matrix by
376
+ * @returns {mat3} out
377
+ */
378
+ export function rotate(out, a, rad) {
379
+ const a00 = a[0];
380
+ const a01 = a[1];
381
+ const a02 = a[2];
382
+ const a10 = a[3];
383
+ const a11 = a[4];
384
+ const a12 = a[5];
385
+ const a20 = a[6];
386
+ const a21 = a[7];
387
+ const a22 = a[8];
388
+ const s = Math.sin(rad);
389
+ const c = Math.cos(rad);
390
+
391
+ out[0] = c * a00 + s * a10;
392
+ out[1] = c * a01 + s * a11;
393
+ out[2] = c * a02 + s * a12;
394
+
395
+ out[3] = c * a10 - s * a00;
396
+ out[4] = c * a11 - s * a01;
397
+ out[5] = c * a12 - s * a02;
398
+
399
+ out[6] = a20;
400
+ out[7] = a21;
401
+ out[8] = a22;
402
+ return out;
403
+ }
404
+
405
+ /**
406
+ * Scales the mat3 by the dimensions in the given vec2
407
+ *
408
+ * @param {mat3} out the receiving matrix
409
+ * @param {ReadonlyMat3} a the matrix to scale
410
+ * @param {ReadonlyVec2} v the vec2 to scale the matrix by
411
+ * @returns {mat3} out
412
+ **/
413
+ export function scale(out, a, v) {
414
+ const x = v[0];
415
+ const y = v[1];
416
+
417
+ out[0] = x * a[0];
418
+ out[1] = x * a[1];
419
+ out[2] = x * a[2];
420
+
421
+ out[3] = y * a[3];
422
+ out[4] = y * a[4];
423
+ out[5] = y * a[5];
424
+
425
+ out[6] = a[6];
426
+ out[7] = a[7];
427
+ out[8] = a[8];
428
+ return out;
429
+ }
430
+
431
+ /**
432
+ * Creates a matrix from a vector translation
433
+ * This is equivalent to (but much faster than):
434
+ *
435
+ * mat3.identity(dest);
436
+ * mat3.translate(dest, dest, vec);
437
+ *
438
+ * @param {mat3} out mat3 receiving operation result
439
+ * @param {ReadonlyVec2} v Translation vector
440
+ * @returns {mat3} out
441
+ */
442
+ export function fromTranslation(out, v) {
443
+ out[0] = 1;
444
+ out[1] = 0;
445
+ out[2] = 0;
446
+ out[3] = 0;
447
+ out[4] = 1;
448
+ out[5] = 0;
449
+ out[6] = v[0];
450
+ out[7] = v[1];
451
+ out[8] = 1;
452
+ return out;
453
+ }
454
+
455
+ /**
456
+ * Creates a matrix from a given angle
457
+ * This is equivalent to (but much faster than):
458
+ *
459
+ * mat3.identity(dest);
460
+ * mat3.rotate(dest, dest, rad);
461
+ *
462
+ * @param {mat3} out mat3 receiving operation result
463
+ * @param {Number} rad the angle to rotate the matrix by
464
+ * @returns {mat3} out
465
+ */
466
+ export function fromRotation(out, rad) {
467
+ const s = Math.sin(rad);
468
+ const c = Math.cos(rad);
469
+
470
+ out[0] = c;
471
+ out[1] = s;
472
+ out[2] = 0;
473
+
474
+ out[3] = -s;
475
+ out[4] = c;
476
+ out[5] = 0;
477
+
478
+ out[6] = 0;
479
+ out[7] = 0;
480
+ out[8] = 1;
481
+ return out;
482
+ }
483
+
484
+ /**
485
+ * Creates a matrix from a vector scaling
486
+ * This is equivalent to (but much faster than):
487
+ *
488
+ * mat3.identity(dest);
489
+ * mat3.scale(dest, dest, vec);
490
+ *
491
+ * @param {mat3} out mat3 receiving operation result
492
+ * @param {ReadonlyVec2} v Scaling vector
493
+ * @returns {mat3} out
494
+ */
495
+ export function fromScaling(out, v) {
496
+ out[0] = v[0];
497
+ out[1] = 0;
498
+ out[2] = 0;
499
+
500
+ out[3] = 0;
501
+ out[4] = v[1];
502
+ out[5] = 0;
503
+
504
+ out[6] = 0;
505
+ out[7] = 0;
506
+ out[8] = 1;
507
+ return out;
508
+ }
509
+
510
+ /**
511
+ * Copies the values from a mat2d into a mat3
512
+ *
513
+ * @param {mat3} out the receiving matrix
514
+ * @param {ReadonlyMat2d} a the matrix to copy
515
+ * @returns {mat3} out
516
+ **/
517
+ export function fromMat2d(out, a) {
518
+ out[0] = a[0];
519
+ out[1] = a[1];
520
+ out[2] = 0;
521
+
522
+ out[3] = a[2];
523
+ out[4] = a[3];
524
+ out[5] = 0;
525
+
526
+ out[6] = a[4];
527
+ out[7] = a[5];
528
+ out[8] = 1;
529
+ return out;
530
+ }
531
+
532
+ /**
533
+ * Calculates a 3x3 matrix from the given quaternion
534
+ *
535
+ * @param {mat3} out mat3 receiving operation result
536
+ * @param {ReadonlyQuat} q Quaternion to create matrix from
537
+ *
538
+ * @returns {mat3} out
539
+ */
540
+ export function fromQuat(out, q) {
541
+ const x = q[0];
542
+ const y = q[1];
543
+ const z = q[2];
544
+ const w = q[3];
545
+ const x2 = x + x;
546
+ const y2 = y + y;
547
+ const z2 = z + z;
548
+
549
+ const xx = x * x2;
550
+ const yx = y * x2;
551
+ const yy = y * y2;
552
+ const zx = z * x2;
553
+ const zy = z * y2;
554
+ const zz = z * z2;
555
+ const wx = w * x2;
556
+ const wy = w * y2;
557
+ const wz = w * z2;
558
+
559
+ out[0] = 1 - yy - zz;
560
+ out[3] = yx - wz;
561
+ out[6] = zx + wy;
562
+
563
+ out[1] = yx + wz;
564
+ out[4] = 1 - xx - zz;
565
+ out[7] = zy - wx;
566
+
567
+ out[2] = zx - wy;
568
+ out[5] = zy + wx;
569
+ out[8] = 1 - xx - yy;
570
+
571
+ return out;
572
+ }
573
+
574
+ /**
575
+ * Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix
576
+ *
577
+ * @param {mat3} out mat3 receiving operation result
578
+ * @param {ReadonlyMat4} a Mat4 to derive the normal matrix from
579
+ *
580
+ * @returns {mat3} out
581
+ */
582
+ export function normalFromMat4(out, a) {
583
+ const a00 = a[0];
584
+ const a01 = a[1];
585
+ const a02 = a[2];
586
+ const a03 = a[3];
587
+ const a10 = a[4];
588
+ const a11 = a[5];
589
+ const a12 = a[6];
590
+ const a13 = a[7];
591
+ const a20 = a[8];
592
+ const a21 = a[9];
593
+ const a22 = a[10];
594
+ const a23 = a[11];
595
+ const a30 = a[12];
596
+ const a31 = a[13];
597
+ const a32 = a[14];
598
+ const a33 = a[15];
599
+
600
+ const b00 = a00 * a11 - a01 * a10;
601
+ const b01 = a00 * a12 - a02 * a10;
602
+ const b02 = a00 * a13 - a03 * a10;
603
+ const b03 = a01 * a12 - a02 * a11;
604
+ const b04 = a01 * a13 - a03 * a11;
605
+ const b05 = a02 * a13 - a03 * a12;
606
+ const b06 = a20 * a31 - a21 * a30;
607
+ const b07 = a20 * a32 - a22 * a30;
608
+ const b08 = a20 * a33 - a23 * a30;
609
+ const b09 = a21 * a32 - a22 * a31;
610
+ const b10 = a21 * a33 - a23 * a31;
611
+ const b11 = a22 * a33 - a23 * a32;
612
+
613
+ // Calculate the determinant
614
+ let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
615
+
616
+ if (!det) {
617
+ return null;
618
+ }
619
+ det = 1.0 / det;
620
+
621
+ out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
622
+ out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
623
+ out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
624
+
625
+ out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
626
+ out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
627
+ out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
628
+
629
+ out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
630
+ out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
631
+ out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
632
+
633
+ return out;
634
+ }
635
+
636
+ /**
637
+ * Generates a 2D projection matrix with the given bounds
638
+ *
639
+ * @param {mat3} out mat3 frustum matrix will be written into
640
+ * @param {number} width Width of your gl context
641
+ * @param {number} height Height of gl context
642
+ * @returns {mat3} out
643
+ */
644
+ export function projection(out, width, height) {
645
+ out[0] = 2 / width;
646
+ out[1] = 0;
647
+ out[2] = 0;
648
+ out[3] = 0;
649
+ out[4] = -2 / height;
650
+ out[5] = 0;
651
+ out[6] = -1;
652
+ out[7] = 1;
653
+ out[8] = 1;
654
+ return out;
655
+ }
656
+
657
+ /**
658
+ * Returns a string representation of a mat3
659
+ *
660
+ * @param {ReadonlyMat3} a matrix to represent as a string
661
+ * @returns {String} string representation of the matrix
662
+ */
663
+ export function str(a) {
664
+ return `mat3(${a[0]}, ${a[1]}, ${a[2]}, ${a[3]}, ${a[4]}, ${a[5]}, ${a[6]}, ${a[7]}, ${a[8]})`;
665
+ }
666
+
667
+ /**
668
+ * Returns Frobenius norm of a mat3
669
+ *
670
+ * @param {ReadonlyMat3} a the matrix to calculate Frobenius norm of
671
+ * @returns {Number} Frobenius norm
672
+ */
673
+ export function frob(a) {
674
+ return Math.sqrt(
675
+ a[0] * a[0] +
676
+ a[1] * a[1] +
677
+ a[2] * a[2] +
678
+ a[3] * a[3] +
679
+ a[4] * a[4] +
680
+ a[5] * a[5] +
681
+ a[6] * a[6] +
682
+ a[7] * a[7] +
683
+ a[8] * a[8]
684
+ );
685
+ }
686
+
687
+ /**
688
+ * Adds two mat3's
689
+ *
690
+ * @param {mat3} out the receiving matrix
691
+ * @param {ReadonlyMat3} a the first operand
692
+ * @param {ReadonlyMat3} b the second operand
693
+ * @returns {mat3} out
694
+ */
695
+ export function add(out, a, b) {
696
+ out[0] = a[0] + b[0];
697
+ out[1] = a[1] + b[1];
698
+ out[2] = a[2] + b[2];
699
+ out[3] = a[3] + b[3];
700
+ out[4] = a[4] + b[4];
701
+ out[5] = a[5] + b[5];
702
+ out[6] = a[6] + b[6];
703
+ out[7] = a[7] + b[7];
704
+ out[8] = a[8] + b[8];
705
+ return out;
706
+ }
707
+
708
+ /**
709
+ * Subtracts matrix b from matrix a
710
+ *
711
+ * @param {mat3} out the receiving matrix
712
+ * @param {ReadonlyMat3} a the first operand
713
+ * @param {ReadonlyMat3} b the second operand
714
+ * @returns {mat3} out
715
+ */
716
+ export function subtract(out, a, b) {
717
+ out[0] = a[0] - b[0];
718
+ out[1] = a[1] - b[1];
719
+ out[2] = a[2] - b[2];
720
+ out[3] = a[3] - b[3];
721
+ out[4] = a[4] - b[4];
722
+ out[5] = a[5] - b[5];
723
+ out[6] = a[6] - b[6];
724
+ out[7] = a[7] - b[7];
725
+ out[8] = a[8] - b[8];
726
+ return out;
727
+ }
728
+
729
+ /**
730
+ * Multiply each element of the matrix by a scalar.
731
+ *
732
+ * @param {mat3} out the receiving matrix
733
+ * @param {ReadonlyMat3} a the matrix to scale
734
+ * @param {Number} b amount to scale the matrix's elements by
735
+ * @returns {mat3} out
736
+ */
737
+ export function multiplyScalar(out, a, b) {
738
+ out[0] = a[0] * b;
739
+ out[1] = a[1] * b;
740
+ out[2] = a[2] * b;
741
+ out[3] = a[3] * b;
742
+ out[4] = a[4] * b;
743
+ out[5] = a[5] * b;
744
+ out[6] = a[6] * b;
745
+ out[7] = a[7] * b;
746
+ out[8] = a[8] * b;
747
+ return out;
748
+ }
749
+
750
+ /**
751
+ * Adds two mat3's after multiplying each element of the second operand by a scalar value.
752
+ *
753
+ * @param {mat3} out the receiving vector
754
+ * @param {ReadonlyMat3} a the first operand
755
+ * @param {ReadonlyMat3} b the second operand
756
+ * @param {Number} scale the amount to scale b's elements by before adding
757
+ * @returns {mat3} out
758
+ */
759
+ export function multiplyScalarAndAdd(out, a, b, scale) {
760
+ out[0] = a[0] + b[0] * scale;
761
+ out[1] = a[1] + b[1] * scale;
762
+ out[2] = a[2] + b[2] * scale;
763
+ out[3] = a[3] + b[3] * scale;
764
+ out[4] = a[4] + b[4] * scale;
765
+ out[5] = a[5] + b[5] * scale;
766
+ out[6] = a[6] + b[6] * scale;
767
+ out[7] = a[7] + b[7] * scale;
768
+ out[8] = a[8] + b[8] * scale;
769
+ return out;
770
+ }
771
+
772
+ /**
773
+ * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
774
+ *
775
+ * @param {ReadonlyMat3} a The first matrix.
776
+ * @param {ReadonlyMat3} b The second matrix.
777
+ * @returns {Boolean} True if the matrices are equal, false otherwise.
778
+ */
779
+ export function exactEquals(a, b) {
780
+ return (
781
+ a[0] === b[0] &&
782
+ a[1] === b[1] &&
783
+ a[2] === b[2] &&
784
+ a[3] === b[3] &&
785
+ a[4] === b[4] &&
786
+ a[5] === b[5] &&
787
+ a[6] === b[6] &&
788
+ a[7] === b[7] &&
789
+ a[8] === b[8]
790
+ );
791
+ }
792
+
793
+ /**
794
+ * Returns whether or not the matrices have approximately the same elements in the same position.
795
+ *
796
+ * @param {ReadonlyMat3} a The first matrix.
797
+ * @param {ReadonlyMat3} b The second matrix.
798
+ * @returns {Boolean} True if the matrices are equal, false otherwise.
799
+ */
800
+ export function equals(a, b) {
801
+ const a0 = a[0];
802
+ const a1 = a[1];
803
+ const a2 = a[2];
804
+ const a3 = a[3];
805
+ const a4 = a[4];
806
+ const a5 = a[5];
807
+ const a6 = a[6];
808
+ const a7 = a[7];
809
+ const a8 = a[8];
810
+ const b0 = b[0];
811
+ const b1 = b[1];
812
+ const b2 = b[2];
813
+ const b3 = b[3];
814
+ const b4 = b[4];
815
+ const b5 = b[5];
816
+ const b6 = b[6];
817
+ const b7 = b[7];
818
+ const b8 = b[8];
819
+ return (
820
+ Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
821
+ Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
822
+ Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&
823
+ Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) &&
824
+ Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) &&
825
+ Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) &&
826
+ Math.abs(a6 - b6) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) &&
827
+ Math.abs(a7 - b7) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) &&
828
+ Math.abs(a8 - b8) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8))
829
+ );
830
+ }
831
+
832
+ /**
833
+ * Alias for {@link mat3.multiply}
834
+ * @function
835
+ */
836
+ export const mul = multiply;
837
+
838
+ /**
839
+ * Alias for {@link mat3.subtract}
840
+ * @function
841
+ */
842
+ export const sub = subtract;