@math.gl/core 4.0.0 → 4.0.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 (124) hide show
  1. package/dist/classes/base/math-array.d.ts +1 -2
  2. package/dist/classes/base/math-array.js +220 -266
  3. package/dist/classes/base/matrix.d.ts +1 -2
  4. package/dist/classes/base/matrix.js +52 -53
  5. package/dist/classes/base/vector.d.ts +1 -2
  6. package/dist/classes/base/vector.js +121 -135
  7. package/dist/classes/euler.d.ts +2 -3
  8. package/dist/classes/euler.js +462 -533
  9. package/dist/classes/matrix3.d.ts +2 -3
  10. package/dist/classes/matrix3.js +185 -190
  11. package/dist/classes/matrix4.d.ts +1 -2
  12. package/dist/classes/matrix4.js +516 -452
  13. package/dist/classes/pose.d.ts +4 -5
  14. package/dist/classes/pose.js +104 -119
  15. package/dist/classes/quaternion.d.ts +1 -2
  16. package/dist/classes/quaternion.js +257 -233
  17. package/dist/classes/spherical-coordinates.d.ts +3 -4
  18. package/dist/classes/spherical-coordinates.js +138 -147
  19. package/dist/classes/vector2.d.ts +1 -2
  20. package/dist/classes/vector2.js +101 -85
  21. package/dist/classes/vector3.d.ts +1 -2
  22. package/dist/classes/vector3.js +125 -136
  23. package/dist/classes/vector4.d.ts +2 -3
  24. package/dist/classes/vector4.js +106 -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 +2 -1
  41. package/dist/gl-matrix/wip/mat2.d.ts +0 -1
  42. package/dist/gl-matrix/wip/mat2.js +333 -157
  43. package/dist/gl-matrix/wip/mat2d.d.ts +0 -1
  44. package/dist/gl-matrix/wip/mat2d.js +377 -202
  45. package/dist/gl-matrix/wip/quat2.d.ts +0 -1
  46. package/dist/gl-matrix/wip/quat2.js +647 -409
  47. package/dist/index.cjs +60 -100
  48. package/dist/index.cjs.map +7 -0
  49. package/dist/index.d.ts +21 -22
  50. package/dist/index.js +23 -16
  51. package/dist/lib/assert.d.ts +0 -1
  52. package/dist/lib/assert.js +3 -4
  53. package/dist/lib/common.d.ts +2 -3
  54. package/dist/lib/common.js +163 -134
  55. package/dist/lib/gl-matrix-extras.d.ts +0 -1
  56. package/dist/lib/gl-matrix-extras.js +39 -36
  57. package/dist/lib/math-utils.d.ts +0 -1
  58. package/dist/lib/math-utils.js +2 -1
  59. package/dist/lib/validators.d.ts +0 -1
  60. package/dist/lib/validators.js +22 -25
  61. package/package.json +5 -6
  62. package/src/classes/matrix3.ts +1 -1
  63. package/dist/classes/base/math-array.d.ts.map +0 -1
  64. package/dist/classes/base/math-array.js.map +0 -1
  65. package/dist/classes/base/matrix.d.ts.map +0 -1
  66. package/dist/classes/base/matrix.js.map +0 -1
  67. package/dist/classes/base/vector.d.ts.map +0 -1
  68. package/dist/classes/base/vector.js.map +0 -1
  69. package/dist/classes/euler.d.ts.map +0 -1
  70. package/dist/classes/euler.js.map +0 -1
  71. package/dist/classes/matrix3.d.ts.map +0 -1
  72. package/dist/classes/matrix3.js.map +0 -1
  73. package/dist/classes/matrix4.d.ts.map +0 -1
  74. package/dist/classes/matrix4.js.map +0 -1
  75. package/dist/classes/pose.d.ts.map +0 -1
  76. package/dist/classes/pose.js.map +0 -1
  77. package/dist/classes/quaternion.d.ts.map +0 -1
  78. package/dist/classes/quaternion.js.map +0 -1
  79. package/dist/classes/spherical-coordinates.d.ts.map +0 -1
  80. package/dist/classes/spherical-coordinates.js.map +0 -1
  81. package/dist/classes/vector2.d.ts.map +0 -1
  82. package/dist/classes/vector2.js.map +0 -1
  83. package/dist/classes/vector3.d.ts.map +0 -1
  84. package/dist/classes/vector3.js.map +0 -1
  85. package/dist/classes/vector4.d.ts.map +0 -1
  86. package/dist/classes/vector4.js.map +0 -1
  87. package/dist/gl-matrix/common.d.ts.map +0 -1
  88. package/dist/gl-matrix/common.js.map +0 -1
  89. package/dist/gl-matrix/mat3.d.ts.map +0 -1
  90. package/dist/gl-matrix/mat3.js.map +0 -1
  91. package/dist/gl-matrix/mat4.d.ts.map +0 -1
  92. package/dist/gl-matrix/mat4.js.map +0 -1
  93. package/dist/gl-matrix/quat.d.ts.map +0 -1
  94. package/dist/gl-matrix/quat.js.map +0 -1
  95. package/dist/gl-matrix/vec2.d.ts.map +0 -1
  96. package/dist/gl-matrix/vec2.js.map +0 -1
  97. package/dist/gl-matrix/vec3.d.ts.map +0 -1
  98. package/dist/gl-matrix/vec3.js.map +0 -1
  99. package/dist/gl-matrix/vec4.d.ts.map +0 -1
  100. package/dist/gl-matrix/vec4.js.map +0 -1
  101. package/dist/gl-matrix/wip/index.d.ts.map +0 -1
  102. package/dist/gl-matrix/wip/index.js.map +0 -1
  103. package/dist/gl-matrix/wip/mat2.d.ts.map +0 -1
  104. package/dist/gl-matrix/wip/mat2.js.map +0 -1
  105. package/dist/gl-matrix/wip/mat2d.d.ts.map +0 -1
  106. package/dist/gl-matrix/wip/mat2d.js.map +0 -1
  107. package/dist/gl-matrix/wip/quat2.d.ts.map +0 -1
  108. package/dist/gl-matrix/wip/quat2.js.map +0 -1
  109. package/dist/gl-matrix/wip/types.d.js +0 -2
  110. package/dist/gl-matrix/wip/types.d.js.map +0 -1
  111. package/dist/index.d.ts.map +0 -1
  112. package/dist/index.js.map +0 -1
  113. package/dist/lib/assert.d.ts.map +0 -1
  114. package/dist/lib/assert.js.map +0 -1
  115. package/dist/lib/common.d.ts.map +0 -1
  116. package/dist/lib/common.js.map +0 -1
  117. package/dist/lib/gl-matrix-extras.d.ts.map +0 -1
  118. package/dist/lib/gl-matrix-extras.js.map +0 -1
  119. package/dist/lib/gl-matrix.d.js +0 -2
  120. package/dist/lib/gl-matrix.d.js.map +0 -1
  121. package/dist/lib/math-utils.d.ts.map +0 -1
  122. package/dist/lib/math-utils.js.map +0 -1
  123. package/dist/lib/validators.d.ts.map +0 -1
  124. package/dist/lib/validators.js.map +0 -1
@@ -1,384 +1,752 @@
1
+ // @eslint-disable
2
+ // @ts-nocheck
1
3
  import * as glMatrix from './common.js';
4
+ /**
5
+ * 3 Dimensional Vector
6
+ * @module vec3
7
+ */
8
+ /**
9
+ * Creates a new, empty vec3
10
+ *
11
+ * @returns {vec3} a new 3D vector
12
+ */
2
13
  export function create() {
3
- const out = new glMatrix.ARRAY_TYPE(3);
4
-
5
- if (glMatrix.ARRAY_TYPE != Float32Array) {
6
- out[0] = 0;
7
- out[1] = 0;
8
- out[2] = 0;
9
- }
10
-
11
- return out;
12
- }
14
+ const out = new glMatrix.ARRAY_TYPE(3);
15
+ if (glMatrix.ARRAY_TYPE != Float32Array) {
16
+ out[0] = 0;
17
+ out[1] = 0;
18
+ out[2] = 0;
19
+ }
20
+ return out;
21
+ }
22
+ /**
23
+ * Creates a new vec3 initialized with values from an existing vector
24
+ *
25
+ * @param {ReadonlyVec3} a vector to clone
26
+ * @returns {vec3} a new 3D vector
27
+ */
13
28
  export function clone(a) {
14
- const out = new glMatrix.ARRAY_TYPE(3);
15
- out[0] = a[0];
16
- out[1] = a[1];
17
- out[2] = a[2];
18
- return out;
19
- }
29
+ const out = new glMatrix.ARRAY_TYPE(3);
30
+ out[0] = a[0];
31
+ out[1] = a[1];
32
+ out[2] = a[2];
33
+ return out;
34
+ }
35
+ /**
36
+ * Calculates the length of a vec3
37
+ *
38
+ * @param {ReadonlyVec3} a vector to calculate length of
39
+ * @returns {Number} length of a
40
+ */
20
41
  export function length(a) {
21
- const x = a[0];
22
- const y = a[1];
23
- const z = a[2];
24
- return Math.sqrt(x * x + y * y + z * z);
25
- }
42
+ const x = a[0];
43
+ const y = a[1];
44
+ const z = a[2];
45
+ return Math.sqrt(x * x + y * y + z * z);
46
+ }
47
+ /**
48
+ * Creates a new vec3 initialized with the given values
49
+ *
50
+ * @param {Number} x X component
51
+ * @param {Number} y Y component
52
+ * @param {Number} z Z component
53
+ * @returns {vec3} a new 3D vector
54
+ */
26
55
  export function fromValues(x, y, z) {
27
- const out = new glMatrix.ARRAY_TYPE(3);
28
- out[0] = x;
29
- out[1] = y;
30
- out[2] = z;
31
- return out;
32
- }
56
+ const out = new glMatrix.ARRAY_TYPE(3);
57
+ out[0] = x;
58
+ out[1] = y;
59
+ out[2] = z;
60
+ return out;
61
+ }
62
+ /**
63
+ * Copy the values from one vec3 to another
64
+ *
65
+ * @param {vec3} out the receiving vector
66
+ * @param {ReadonlyVec3} a the source vector
67
+ * @returns {vec3} out
68
+ */
33
69
  export function copy(out, a) {
34
- out[0] = a[0];
35
- out[1] = a[1];
36
- out[2] = a[2];
37
- return out;
38
- }
70
+ out[0] = a[0];
71
+ out[1] = a[1];
72
+ out[2] = a[2];
73
+ return out;
74
+ }
75
+ /**
76
+ * Set the components of a vec3 to the given values
77
+ *
78
+ * @param {vec3} out the receiving vector
79
+ * @param {Number} x X component
80
+ * @param {Number} y Y component
81
+ * @param {Number} z Z component
82
+ * @returns {vec3} out
83
+ */
39
84
  export function set(out, x, y, z) {
40
- out[0] = x;
41
- out[1] = y;
42
- out[2] = z;
43
- return out;
44
- }
85
+ out[0] = x;
86
+ out[1] = y;
87
+ out[2] = z;
88
+ return out;
89
+ }
90
+ /**
91
+ * Adds two vec3's
92
+ *
93
+ * @param {vec3} out the receiving vector
94
+ * @param {ReadonlyVec3} a the first operand
95
+ * @param {ReadonlyVec3} b the second operand
96
+ * @returns {vec3} out
97
+ */
45
98
  export function add(out, a, b) {
46
- out[0] = a[0] + b[0];
47
- out[1] = a[1] + b[1];
48
- out[2] = a[2] + b[2];
49
- return out;
50
- }
99
+ out[0] = a[0] + b[0];
100
+ out[1] = a[1] + b[1];
101
+ out[2] = a[2] + b[2];
102
+ return out;
103
+ }
104
+ /**
105
+ * Subtracts vector b from vector a
106
+ *
107
+ * @param {vec3} out the receiving vector
108
+ * @param {ReadonlyVec3} a the first operand
109
+ * @param {ReadonlyVec3} b the second operand
110
+ * @returns {vec3} out
111
+ */
51
112
  export function subtract(out, a, b) {
52
- out[0] = a[0] - b[0];
53
- out[1] = a[1] - b[1];
54
- out[2] = a[2] - b[2];
55
- return out;
56
- }
113
+ out[0] = a[0] - b[0];
114
+ out[1] = a[1] - b[1];
115
+ out[2] = a[2] - b[2];
116
+ return out;
117
+ }
118
+ /**
119
+ * Multiplies two vec3's
120
+ *
121
+ * @param {vec3} out the receiving vector
122
+ * @param {ReadonlyVec3} a the first operand
123
+ * @param {ReadonlyVec3} b the second operand
124
+ * @returns {vec3} out
125
+ */
57
126
  export function multiply(out, a, b) {
58
- out[0] = a[0] * b[0];
59
- out[1] = a[1] * b[1];
60
- out[2] = a[2] * b[2];
61
- return out;
62
- }
127
+ out[0] = a[0] * b[0];
128
+ out[1] = a[1] * b[1];
129
+ out[2] = a[2] * b[2];
130
+ return out;
131
+ }
132
+ /**
133
+ * Divides two vec3's
134
+ *
135
+ * @param {vec3} out the receiving vector
136
+ * @param {ReadonlyVec3} a the first operand
137
+ * @param {ReadonlyVec3} b the second operand
138
+ * @returns {vec3} out
139
+ */
63
140
  export function divide(out, a, b) {
64
- out[0] = a[0] / b[0];
65
- out[1] = a[1] / b[1];
66
- out[2] = a[2] / b[2];
67
- return out;
68
- }
141
+ out[0] = a[0] / b[0];
142
+ out[1] = a[1] / b[1];
143
+ out[2] = a[2] / b[2];
144
+ return out;
145
+ }
146
+ /**
147
+ * Math.ceil the components of a vec3
148
+ *
149
+ * @param {vec3} out the receiving vector
150
+ * @param {ReadonlyVec3} a vector to ceil
151
+ * @returns {vec3} out
152
+ */
69
153
  export function ceil(out, a) {
70
- out[0] = Math.ceil(a[0]);
71
- out[1] = Math.ceil(a[1]);
72
- out[2] = Math.ceil(a[2]);
73
- return out;
74
- }
154
+ out[0] = Math.ceil(a[0]);
155
+ out[1] = Math.ceil(a[1]);
156
+ out[2] = Math.ceil(a[2]);
157
+ return out;
158
+ }
159
+ /**
160
+ * Math.floor the components of a vec3
161
+ *
162
+ * @param {vec3} out the receiving vector
163
+ * @param {ReadonlyVec3} a vector to floor
164
+ * @returns {vec3} out
165
+ */
75
166
  export function floor(out, a) {
76
- out[0] = Math.floor(a[0]);
77
- out[1] = Math.floor(a[1]);
78
- out[2] = Math.floor(a[2]);
79
- return out;
80
- }
167
+ out[0] = Math.floor(a[0]);
168
+ out[1] = Math.floor(a[1]);
169
+ out[2] = Math.floor(a[2]);
170
+ return out;
171
+ }
172
+ /**
173
+ * Returns the minimum of two vec3's
174
+ *
175
+ * @param {vec3} out the receiving vector
176
+ * @param {ReadonlyVec3} a the first operand
177
+ * @param {ReadonlyVec3} b the second operand
178
+ * @returns {vec3} out
179
+ */
81
180
  export function min(out, a, b) {
82
- out[0] = Math.min(a[0], b[0]);
83
- out[1] = Math.min(a[1], b[1]);
84
- out[2] = Math.min(a[2], b[2]);
85
- return out;
86
- }
181
+ out[0] = Math.min(a[0], b[0]);
182
+ out[1] = Math.min(a[1], b[1]);
183
+ out[2] = Math.min(a[2], b[2]);
184
+ return out;
185
+ }
186
+ /**
187
+ * Returns the maximum of two vec3's
188
+ *
189
+ * @param {vec3} out the receiving vector
190
+ * @param {ReadonlyVec3} a the first operand
191
+ * @param {ReadonlyVec3} b the second operand
192
+ * @returns {vec3} out
193
+ */
87
194
  export function max(out, a, b) {
88
- out[0] = Math.max(a[0], b[0]);
89
- out[1] = Math.max(a[1], b[1]);
90
- out[2] = Math.max(a[2], b[2]);
91
- return out;
92
- }
195
+ out[0] = Math.max(a[0], b[0]);
196
+ out[1] = Math.max(a[1], b[1]);
197
+ out[2] = Math.max(a[2], b[2]);
198
+ return out;
199
+ }
200
+ /**
201
+ * symmetric round the components of a vec3
202
+ *
203
+ * @param {vec3} out the receiving vector
204
+ * @param {ReadonlyVec3} a vector to round
205
+ * @returns {vec3} out
206
+ */
93
207
  export function round(out, a) {
94
- out[0] = glMatrix.round(a[0]);
95
- out[1] = glMatrix.round(a[1]);
96
- out[2] = glMatrix.round(a[2]);
97
- return out;
98
- }
208
+ out[0] = glMatrix.round(a[0]);
209
+ out[1] = glMatrix.round(a[1]);
210
+ out[2] = glMatrix.round(a[2]);
211
+ return out;
212
+ }
213
+ /**
214
+ * Scales a vec3 by a scalar number
215
+ *
216
+ * @param {vec3} out the receiving vector
217
+ * @param {ReadonlyVec3} a the vector to scale
218
+ * @param {Number} b amount to scale the vector by
219
+ * @returns {vec3} out
220
+ */
99
221
  export function scale(out, a, b) {
100
- out[0] = a[0] * b;
101
- out[1] = a[1] * b;
102
- out[2] = a[2] * b;
103
- return out;
104
- }
222
+ out[0] = a[0] * b;
223
+ out[1] = a[1] * b;
224
+ out[2] = a[2] * b;
225
+ return out;
226
+ }
227
+ /**
228
+ * Adds two vec3's after scaling the second operand by a scalar value
229
+ *
230
+ * @param {vec3} out the receiving vector
231
+ * @param {ReadonlyVec3} a the first operand
232
+ * @param {ReadonlyVec3} b the second operand
233
+ * @param {Number} scale the amount to scale b by before adding
234
+ * @returns {vec3} out
235
+ */
105
236
  export function scaleAndAdd(out, a, b, scale) {
106
- out[0] = a[0] + b[0] * scale;
107
- out[1] = a[1] + b[1] * scale;
108
- out[2] = a[2] + b[2] * scale;
109
- return out;
110
- }
237
+ out[0] = a[0] + b[0] * scale;
238
+ out[1] = a[1] + b[1] * scale;
239
+ out[2] = a[2] + b[2] * scale;
240
+ return out;
241
+ }
242
+ /**
243
+ * Calculates the euclidian distance between two vec3's
244
+ *
245
+ * @param {ReadonlyVec3} a the first operand
246
+ * @param {ReadonlyVec3} b the second operand
247
+ * @returns {Number} distance between a and b
248
+ */
111
249
  export function distance(a, b) {
112
- const x = b[0] - a[0];
113
- const y = b[1] - a[1];
114
- const z = b[2] - a[2];
115
- return Math.sqrt(x * x + y * y + z * z);
116
- }
250
+ const x = b[0] - a[0];
251
+ const y = b[1] - a[1];
252
+ const z = b[2] - a[2];
253
+ return Math.sqrt(x * x + y * y + z * z);
254
+ }
255
+ /**
256
+ * Calculates the squared euclidian distance between two vec3's
257
+ *
258
+ * @param {ReadonlyVec3} a the first operand
259
+ * @param {ReadonlyVec3} b the second operand
260
+ * @returns {Number} squared distance between a and b
261
+ */
117
262
  export function squaredDistance(a, b) {
118
- const x = b[0] - a[0];
119
- const y = b[1] - a[1];
120
- const z = b[2] - a[2];
121
- return x * x + y * y + z * z;
122
- }
263
+ const x = b[0] - a[0];
264
+ const y = b[1] - a[1];
265
+ const z = b[2] - a[2];
266
+ return x * x + y * y + z * z;
267
+ }
268
+ /**
269
+ * Calculates the squared length of a vec3
270
+ *
271
+ * @param {ReadonlyVec3} a vector to calculate squared length of
272
+ * @returns {Number} squared length of a
273
+ */
123
274
  export function squaredLength(a) {
124
- const x = a[0];
125
- const y = a[1];
126
- const z = a[2];
127
- return x * x + y * y + z * z;
128
- }
275
+ const x = a[0];
276
+ const y = a[1];
277
+ const z = a[2];
278
+ return x * x + y * y + z * z;
279
+ }
280
+ /**
281
+ * Negates the components of a vec3
282
+ *
283
+ * @param {vec3} out the receiving vector
284
+ * @param {ReadonlyVec3} a vector to negate
285
+ * @returns {vec3} out
286
+ */
129
287
  export function negate(out, a) {
130
- out[0] = -a[0];
131
- out[1] = -a[1];
132
- out[2] = -a[2];
133
- return out;
134
- }
288
+ out[0] = -a[0];
289
+ out[1] = -a[1];
290
+ out[2] = -a[2];
291
+ return out;
292
+ }
293
+ /**
294
+ * Returns the inverse of the components of a vec3
295
+ *
296
+ * @param {vec3} out the receiving vector
297
+ * @param {ReadonlyVec3} a vector to invert
298
+ * @returns {vec3} out
299
+ */
135
300
  export function inverse(out, a) {
136
- out[0] = 1.0 / a[0];
137
- out[1] = 1.0 / a[1];
138
- out[2] = 1.0 / a[2];
139
- return out;
140
- }
301
+ out[0] = 1.0 / a[0];
302
+ out[1] = 1.0 / a[1];
303
+ out[2] = 1.0 / a[2];
304
+ return out;
305
+ }
306
+ /**
307
+ * Normalize a vec3
308
+ *
309
+ * @param {vec3} out the receiving vector
310
+ * @param {ReadonlyVec3} a vector to normalize
311
+ * @returns {vec3} out
312
+ */
141
313
  export function normalize(out, a) {
142
- const x = a[0];
143
- const y = a[1];
144
- const z = a[2];
145
- let len = x * x + y * y + z * z;
146
-
147
- if (len > 0) {
148
- len = 1 / Math.sqrt(len);
149
- }
150
-
151
- out[0] = a[0] * len;
152
- out[1] = a[1] * len;
153
- out[2] = a[2] * len;
154
- return out;
155
- }
314
+ const x = a[0];
315
+ const y = a[1];
316
+ const z = a[2];
317
+ let len = x * x + y * y + z * z;
318
+ if (len > 0) {
319
+ // TODO: evaluate use of glm_invsqrt here?
320
+ len = 1 / Math.sqrt(len);
321
+ }
322
+ out[0] = a[0] * len;
323
+ out[1] = a[1] * len;
324
+ out[2] = a[2] * len;
325
+ return out;
326
+ }
327
+ /**
328
+ * Calculates the dot product of two vec3's
329
+ *
330
+ * @param {ReadonlyVec3} a the first operand
331
+ * @param {ReadonlyVec3} b the second operand
332
+ * @returns {Number} dot product of a and b
333
+ */
156
334
  export function dot(a, b) {
157
- return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
158
- }
335
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
336
+ }
337
+ /**
338
+ * Computes the cross product of two vec3's
339
+ *
340
+ * @param {vec3} out the receiving vector
341
+ * @param {ReadonlyVec3} a the first operand
342
+ * @param {ReadonlyVec3} b the second operand
343
+ * @returns {vec3} out
344
+ */
159
345
  export function cross(out, a, b) {
160
- const ax = a[0];
161
- const ay = a[1];
162
- const az = a[2];
163
- const bx = b[0];
164
- const by = b[1];
165
- const bz = b[2];
166
- out[0] = ay * bz - az * by;
167
- out[1] = az * bx - ax * bz;
168
- out[2] = ax * by - ay * bx;
169
- return out;
170
- }
346
+ const ax = a[0];
347
+ const ay = a[1];
348
+ const az = a[2];
349
+ const bx = b[0];
350
+ const by = b[1];
351
+ const bz = b[2];
352
+ out[0] = ay * bz - az * by;
353
+ out[1] = az * bx - ax * bz;
354
+ out[2] = ax * by - ay * bx;
355
+ return out;
356
+ }
357
+ /**
358
+ * Performs a linear interpolation between two vec3's
359
+ *
360
+ * @param {vec3} out the receiving vector
361
+ * @param {ReadonlyVec3} a the first operand
362
+ * @param {ReadonlyVec3} b the second operand
363
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
364
+ * @returns {vec3} out
365
+ */
171
366
  export function lerp(out, a, b, t) {
172
- const ax = a[0];
173
- const ay = a[1];
174
- const az = a[2];
175
- out[0] = ax + t * (b[0] - ax);
176
- out[1] = ay + t * (b[1] - ay);
177
- out[2] = az + t * (b[2] - az);
178
- return out;
179
- }
367
+ const ax = a[0];
368
+ const ay = a[1];
369
+ const az = a[2];
370
+ out[0] = ax + t * (b[0] - ax);
371
+ out[1] = ay + t * (b[1] - ay);
372
+ out[2] = az + t * (b[2] - az);
373
+ return out;
374
+ }
375
+ /**
376
+ * Performs a spherical linear interpolation between two vec3's
377
+ *
378
+ * @param {vec3} out the receiving vector
379
+ * @param {ReadonlyVec3} a the first operand
380
+ * @param {ReadonlyVec3} b the second operand
381
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
382
+ * @returns {vec3} out
383
+ */
180
384
  export function slerp(out, a, b, t) {
181
- const angle = Math.acos(Math.min(Math.max(dot(a, b), -1), 1));
182
- const sinTotal = Math.sin(angle);
183
- const ratioA = Math.sin((1 - t) * angle) / sinTotal;
184
- const ratioB = Math.sin(t * angle) / sinTotal;
185
- out[0] = ratioA * a[0] + ratioB * b[0];
186
- out[1] = ratioA * a[1] + ratioB * b[1];
187
- out[2] = ratioA * a[2] + ratioB * b[2];
188
- return out;
189
- }
385
+ const angle = Math.acos(Math.min(Math.max(dot(a, b), -1), 1));
386
+ const sinTotal = Math.sin(angle);
387
+ const ratioA = Math.sin((1 - t) * angle) / sinTotal;
388
+ const ratioB = Math.sin(t * angle) / sinTotal;
389
+ out[0] = ratioA * a[0] + ratioB * b[0];
390
+ out[1] = ratioA * a[1] + ratioB * b[1];
391
+ out[2] = ratioA * a[2] + ratioB * b[2];
392
+ return out;
393
+ }
394
+ /**
395
+ * Performs a hermite interpolation with two control points
396
+ *
397
+ * @param {vec3} out the receiving vector
398
+ * @param {ReadonlyVec3} a the first operand
399
+ * @param {ReadonlyVec3} b the second operand
400
+ * @param {ReadonlyVec3} c the third operand
401
+ * @param {ReadonlyVec3} d the fourth operand
402
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
403
+ * @returns {vec3} out
404
+ */
190
405
  export function hermite(out, a, b, c, d, t) {
191
- const factorTimes2 = t * t;
192
- const factor1 = factorTimes2 * (2 * t - 3) + 1;
193
- const factor2 = factorTimes2 * (t - 2) + t;
194
- const factor3 = factorTimes2 * (t - 1);
195
- const factor4 = factorTimes2 * (3 - 2 * t);
196
- out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
197
- out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
198
- out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
199
- return out;
200
- }
406
+ const factorTimes2 = t * t;
407
+ const factor1 = factorTimes2 * (2 * t - 3) + 1;
408
+ const factor2 = factorTimes2 * (t - 2) + t;
409
+ const factor3 = factorTimes2 * (t - 1);
410
+ const factor4 = factorTimes2 * (3 - 2 * t);
411
+ out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
412
+ out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
413
+ out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
414
+ return out;
415
+ }
416
+ /**
417
+ * Performs a bezier interpolation with two control points
418
+ *
419
+ * @param {vec3} out the receiving vector
420
+ * @param {ReadonlyVec3} a the first operand
421
+ * @param {ReadonlyVec3} b the second operand
422
+ * @param {ReadonlyVec3} c the third operand
423
+ * @param {ReadonlyVec3} d the fourth operand
424
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
425
+ * @returns {vec3} out
426
+ */
201
427
  export function bezier(out, a, b, c, d, t) {
202
- const inverseFactor = 1 - t;
203
- const inverseFactorTimesTwo = inverseFactor * inverseFactor;
204
- const factorTimes2 = t * t;
205
- const factor1 = inverseFactorTimesTwo * inverseFactor;
206
- const factor2 = 3 * t * inverseFactorTimesTwo;
207
- const factor3 = 3 * factorTimes2 * inverseFactor;
208
- const factor4 = factorTimes2 * t;
209
- out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
210
- out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
211
- out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
212
- return out;
213
- }
428
+ const inverseFactor = 1 - t;
429
+ const inverseFactorTimesTwo = inverseFactor * inverseFactor;
430
+ const factorTimes2 = t * t;
431
+ const factor1 = inverseFactorTimesTwo * inverseFactor;
432
+ const factor2 = 3 * t * inverseFactorTimesTwo;
433
+ const factor3 = 3 * factorTimes2 * inverseFactor;
434
+ const factor4 = factorTimes2 * t;
435
+ out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
436
+ out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
437
+ out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
438
+ return out;
439
+ }
440
+ /**
441
+ * Generates a random vector with the given scale
442
+ *
443
+ * @param {vec3} out the receiving vector
444
+ * @param {Number} [scale] Length of the resulting vector. If omitted, a unit vector will be returned
445
+ * @returns {vec3} out
446
+ */
214
447
  export function random(out, scale) {
215
- scale = scale === undefined ? 1.0 : scale;
216
- const r = glMatrix.RANDOM() * 2.0 * Math.PI;
217
- const z = glMatrix.RANDOM() * 2.0 - 1.0;
218
- const zScale = Math.sqrt(1.0 - z * z) * scale;
219
- out[0] = Math.cos(r) * zScale;
220
- out[1] = Math.sin(r) * zScale;
221
- out[2] = z * scale;
222
- return out;
223
- }
448
+ scale = scale === undefined ? 1.0 : scale;
449
+ const r = glMatrix.RANDOM() * 2.0 * Math.PI;
450
+ const z = glMatrix.RANDOM() * 2.0 - 1.0;
451
+ const zScale = Math.sqrt(1.0 - z * z) * scale;
452
+ out[0] = Math.cos(r) * zScale;
453
+ out[1] = Math.sin(r) * zScale;
454
+ out[2] = z * scale;
455
+ return out;
456
+ }
457
+ /**
458
+ * Transforms the vec3 with a mat4.
459
+ * 4th vector component is implicitly '1'
460
+ *
461
+ * @param {vec3} out the receiving vector
462
+ * @param {ReadonlyVec3} a the vector to transform
463
+ * @param {ReadonlyMat4} m matrix to transform with
464
+ * @returns {vec3} out
465
+ */
224
466
  export function transformMat4(out, a, m) {
225
- const x = a[0];
226
- const y = a[1];
227
- const z = a[2];
228
- let w = m[3] * x + m[7] * y + m[11] * z + m[15];
229
- w = w || 1.0;
230
- out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
231
- out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
232
- out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
233
- return out;
234
- }
467
+ const x = a[0];
468
+ const y = a[1];
469
+ const z = a[2];
470
+ let w = m[3] * x + m[7] * y + m[11] * z + m[15];
471
+ w = w || 1.0;
472
+ out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
473
+ out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
474
+ out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
475
+ return out;
476
+ }
477
+ /**
478
+ * Transforms the vec3 with a mat3.
479
+ *
480
+ * @param {vec3} out the receiving vector
481
+ * @param {ReadonlyVec3} a the vector to transform
482
+ * @param {ReadonlyMat3} m the 3x3 matrix to transform with
483
+ * @returns {vec3} out
484
+ */
235
485
  export function transformMat3(out, a, m) {
236
- const x = a[0];
237
- const y = a[1];
238
- const z = a[2];
239
- out[0] = x * m[0] + y * m[3] + z * m[6];
240
- out[1] = x * m[1] + y * m[4] + z * m[7];
241
- out[2] = x * m[2] + y * m[5] + z * m[8];
242
- return out;
243
- }
486
+ const x = a[0];
487
+ const y = a[1];
488
+ const z = a[2];
489
+ out[0] = x * m[0] + y * m[3] + z * m[6];
490
+ out[1] = x * m[1] + y * m[4] + z * m[7];
491
+ out[2] = x * m[2] + y * m[5] + z * m[8];
492
+ return out;
493
+ }
494
+ /**
495
+ * Transforms the vec3 with a quat
496
+ * Can also be used for dual quaternions. (Multiply it with the real part)
497
+ *
498
+ * @param {vec3} out the receiving vector
499
+ * @param {ReadonlyVec3} a the vector to transform
500
+ * @param {ReadonlyQuat} q quaternion to transform with
501
+ * @returns {vec3} out
502
+ */
244
503
  export function transformQuat(out, a, q) {
245
- const qx = q[0];
246
- const qy = q[1];
247
- const qz = q[2];
248
- const qw = q[3];
249
- const x = a[0];
250
- const y = a[1];
251
- const z = a[2];
252
- let uvx = qy * z - qz * y;
253
- let uvy = qz * x - qx * z;
254
- let uvz = qx * y - qy * x;
255
- let uuvx = qy * uvz - qz * uvy;
256
- let uuvy = qz * uvx - qx * uvz;
257
- let uuvz = qx * uvy - qy * uvx;
258
- const w2 = qw * 2;
259
- uvx *= w2;
260
- uvy *= w2;
261
- uvz *= w2;
262
- uuvx *= 2;
263
- uuvy *= 2;
264
- uuvz *= 2;
265
- out[0] = x + uvx + uuvx;
266
- out[1] = y + uvy + uuvy;
267
- out[2] = z + uvz + uuvz;
268
- return out;
269
- }
504
+ // benchmarks: https://jsperf.com/quaternion-transform-vec3-implementations-fixed
505
+ const qx = q[0];
506
+ const qy = q[1];
507
+ const qz = q[2];
508
+ const qw = q[3];
509
+ const x = a[0];
510
+ const y = a[1];
511
+ const z = a[2];
512
+ // var qvec = [qx, qy, qz];
513
+ // var uv = vec3.cross([], qvec, a);
514
+ let uvx = qy * z - qz * y;
515
+ let uvy = qz * x - qx * z;
516
+ let uvz = qx * y - qy * x;
517
+ // var uuv = vec3.cross([], qvec, uv);
518
+ let uuvx = qy * uvz - qz * uvy;
519
+ let uuvy = qz * uvx - qx * uvz;
520
+ let uuvz = qx * uvy - qy * uvx;
521
+ // vec3.scale(uv, uv, 2 * w);
522
+ const w2 = qw * 2;
523
+ uvx *= w2;
524
+ uvy *= w2;
525
+ uvz *= w2;
526
+ // vec3.scale(uuv, uuv, 2);
527
+ uuvx *= 2;
528
+ uuvy *= 2;
529
+ uuvz *= 2;
530
+ // return vec3.add(out, a, vec3.add(out, uv, uuv));
531
+ out[0] = x + uvx + uuvx;
532
+ out[1] = y + uvy + uuvy;
533
+ out[2] = z + uvz + uuvz;
534
+ return out;
535
+ }
536
+ /**
537
+ * Rotate a 3D vector around the x-axis
538
+ * @param {vec3} out The receiving vec3
539
+ * @param {ReadonlyVec3} a The vec3 point to rotate
540
+ * @param {ReadonlyVec3} b The origin of the rotation
541
+ * @param {Number} rad The angle of rotation in radians
542
+ * @returns {vec3} out
543
+ */
270
544
  export function rotateX(out, a, b, rad) {
271
- const p = [];
272
- const r = [];
273
- p[0] = a[0] - b[0];
274
- p[1] = a[1] - b[1];
275
- p[2] = a[2] - b[2];
276
- r[0] = p[0];
277
- r[1] = p[1] * Math.cos(rad) - p[2] * Math.sin(rad);
278
- r[2] = p[1] * Math.sin(rad) + p[2] * Math.cos(rad);
279
- out[0] = r[0] + b[0];
280
- out[1] = r[1] + b[1];
281
- out[2] = r[2] + b[2];
282
- return out;
283
- }
545
+ const p = [];
546
+ const r = [];
547
+ // Translate point to the origin
548
+ p[0] = a[0] - b[0];
549
+ p[1] = a[1] - b[1];
550
+ p[2] = a[2] - b[2];
551
+ // perform rotation
552
+ r[0] = p[0];
553
+ r[1] = p[1] * Math.cos(rad) - p[2] * Math.sin(rad);
554
+ r[2] = p[1] * Math.sin(rad) + p[2] * Math.cos(rad);
555
+ // translate to correct position
556
+ out[0] = r[0] + b[0];
557
+ out[1] = r[1] + b[1];
558
+ out[2] = r[2] + b[2];
559
+ return out;
560
+ }
561
+ /**
562
+ * Rotate a 3D vector around the y-axis
563
+ * @param {vec3} out The receiving vec3
564
+ * @param {ReadonlyVec3} a The vec3 point to rotate
565
+ * @param {ReadonlyVec3} b The origin of the rotation
566
+ * @param {Number} rad The angle of rotation in radians
567
+ * @returns {vec3} out
568
+ */
284
569
  export function rotateY(out, a, b, rad) {
285
- const p = [];
286
- const r = [];
287
- p[0] = a[0] - b[0];
288
- p[1] = a[1] - b[1];
289
- p[2] = a[2] - b[2];
290
- r[0] = p[2] * Math.sin(rad) + p[0] * Math.cos(rad);
291
- r[1] = p[1];
292
- r[2] = p[2] * Math.cos(rad) - p[0] * Math.sin(rad);
293
- out[0] = r[0] + b[0];
294
- out[1] = r[1] + b[1];
295
- out[2] = r[2] + b[2];
296
- return out;
297
- }
570
+ const p = [];
571
+ const r = [];
572
+ // Translate point to the origin
573
+ p[0] = a[0] - b[0];
574
+ p[1] = a[1] - b[1];
575
+ p[2] = a[2] - b[2];
576
+ // perform rotation
577
+ r[0] = p[2] * Math.sin(rad) + p[0] * Math.cos(rad);
578
+ r[1] = p[1];
579
+ r[2] = p[2] * Math.cos(rad) - p[0] * Math.sin(rad);
580
+ // translate to correct position
581
+ out[0] = r[0] + b[0];
582
+ out[1] = r[1] + b[1];
583
+ out[2] = r[2] + b[2];
584
+ return out;
585
+ }
586
+ /**
587
+ * Rotate a 3D vector around the z-axis
588
+ * @param {vec3} out The receiving vec3
589
+ * @param {ReadonlyVec3} a The vec3 point to rotate
590
+ * @param {ReadonlyVec3} b The origin of the rotation
591
+ * @param {Number} rad The angle of rotation in radians
592
+ * @returns {vec3} out
593
+ */
298
594
  export function rotateZ(out, a, b, rad) {
299
- const p = [];
300
- const r = [];
301
- p[0] = a[0] - b[0];
302
- p[1] = a[1] - b[1];
303
- p[2] = a[2] - b[2];
304
- r[0] = p[0] * Math.cos(rad) - p[1] * Math.sin(rad);
305
- r[1] = p[0] * Math.sin(rad) + p[1] * Math.cos(rad);
306
- r[2] = p[2];
307
- out[0] = r[0] + b[0];
308
- out[1] = r[1] + b[1];
309
- out[2] = r[2] + b[2];
310
- return out;
311
- }
595
+ const p = [];
596
+ const r = [];
597
+ // Translate point to the origin
598
+ p[0] = a[0] - b[0];
599
+ p[1] = a[1] - b[1];
600
+ p[2] = a[2] - b[2];
601
+ // perform rotation
602
+ r[0] = p[0] * Math.cos(rad) - p[1] * Math.sin(rad);
603
+ r[1] = p[0] * Math.sin(rad) + p[1] * Math.cos(rad);
604
+ r[2] = p[2];
605
+ // translate to correct position
606
+ out[0] = r[0] + b[0];
607
+ out[1] = r[1] + b[1];
608
+ out[2] = r[2] + b[2];
609
+ return out;
610
+ }
611
+ /**
612
+ * Get the angle between two 3D vectors
613
+ * @param {ReadonlyVec3} a The first operand
614
+ * @param {ReadonlyVec3} b The second operand
615
+ * @returns {Number} The angle in radians
616
+ */
312
617
  export function angle(a, b) {
313
- const ax = a[0];
314
- const ay = a[1];
315
- const az = a[2];
316
- const bx = b[0];
317
- const by = b[1];
318
- const bz = b[2];
319
- const mag = Math.sqrt((ax * ax + ay * ay + az * az) * (bx * bx + by * by + bz * bz));
320
- const cosine = mag && dot(a, b) / mag;
321
- return Math.acos(Math.min(Math.max(cosine, -1), 1));
322
- }
618
+ const ax = a[0];
619
+ const ay = a[1];
620
+ const az = a[2];
621
+ const bx = b[0];
622
+ const by = b[1];
623
+ const bz = b[2];
624
+ const mag = Math.sqrt((ax * ax + ay * ay + az * az) * (bx * bx + by * by + bz * bz));
625
+ const cosine = mag && dot(a, b) / mag;
626
+ return Math.acos(Math.min(Math.max(cosine, -1), 1));
627
+ }
628
+ /**
629
+ * Set the components of a vec3 to zero
630
+ *
631
+ * @param {vec3} out the receiving vector
632
+ * @returns {vec3} out
633
+ */
323
634
  export function zero(out) {
324
- out[0] = 0.0;
325
- out[1] = 0.0;
326
- out[2] = 0.0;
327
- return out;
328
- }
635
+ out[0] = 0.0;
636
+ out[1] = 0.0;
637
+ out[2] = 0.0;
638
+ return out;
639
+ }
640
+ /**
641
+ * Returns a string representation of a vector
642
+ *
643
+ * @param {ReadonlyVec3} a vector to represent as a string
644
+ * @returns {String} string representation of the vector
645
+ */
329
646
  export function str(a) {
330
- return "vec3(".concat(a[0], ", ").concat(a[1], ", ").concat(a[2], ")");
331
- }
647
+ return `vec3(${a[0]}, ${a[1]}, ${a[2]})`;
648
+ }
649
+ /**
650
+ * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)
651
+ *
652
+ * @param {ReadonlyVec3} a The first vector.
653
+ * @param {ReadonlyVec3} b The second vector.
654
+ * @returns {Boolean} True if the vectors are equal, false otherwise.
655
+ */
332
656
  export function exactEquals(a, b) {
333
- return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
334
- }
657
+ return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
658
+ }
659
+ /**
660
+ * Returns whether or not the vectors have approximately the same elements in the same position.
661
+ *
662
+ * @param {ReadonlyVec3} a The first vector.
663
+ * @param {ReadonlyVec3} b The second vector.
664
+ * @returns {Boolean} True if the vectors are equal, false otherwise.
665
+ */
335
666
  export function equals(a, b) {
336
- const a0 = a[0];
337
- const a1 = a[1];
338
- const a2 = a[2];
339
- const b0 = b[0];
340
- const b1 = b[1];
341
- const b2 = b[2];
342
- 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));
343
- }
667
+ const a0 = a[0];
668
+ const a1 = a[1];
669
+ const a2 = a[2];
670
+ const b0 = b[0];
671
+ const b1 = b[1];
672
+ const b2 = b[2];
673
+ return (Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
674
+ Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
675
+ Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)));
676
+ }
677
+ /**
678
+ * Alias for {@link vec3.subtract}
679
+ * @function
680
+ */
344
681
  export const sub = subtract;
682
+ /**
683
+ * Alias for {@link vec3.multiply}
684
+ * @function
685
+ */
345
686
  export const mul = multiply;
687
+ /**
688
+ * Alias for {@link vec3.divide}
689
+ * @function
690
+ */
346
691
  export const div = divide;
692
+ /**
693
+ * Alias for {@link vec3.distance}
694
+ * @function
695
+ */
347
696
  export const dist = distance;
697
+ /**
698
+ * Alias for {@link vec3.squaredDistance}
699
+ * @function
700
+ */
348
701
  export const sqrDist = squaredDistance;
702
+ /**
703
+ * Alias for {@link vec3.length}
704
+ * @function
705
+ */
349
706
  export const len = length;
707
+ /**
708
+ * Alias for {@link vec3.squaredLength}
709
+ * @function
710
+ */
350
711
  export const sqrLen = squaredLength;
351
- export const forEach = function () {
352
- const vec = create();
353
- return function (a, stride, offset, count, fn, arg) {
354
- let i;
355
- let l;
356
-
357
- if (!stride) {
358
- stride = 3;
359
- }
360
-
361
- if (!offset) {
362
- offset = 0;
363
- }
364
-
365
- if (count) {
366
- l = Math.min(count * stride + offset, a.length);
367
- } else {
368
- l = a.length;
369
- }
370
-
371
- for (i = offset; i < l; i += stride) {
372
- vec[0] = a[i];
373
- vec[1] = a[i + 1];
374
- vec[2] = a[i + 2];
375
- fn(vec, vec, arg);
376
- a[i] = vec[0];
377
- a[i + 1] = vec[1];
378
- a[i + 2] = vec[2];
379
- }
380
-
381
- return a;
382
- };
383
- }();
384
- //# sourceMappingURL=vec3.js.map
712
+ /**
713
+ * Perform some operation over an array of vec3s.
714
+ *
715
+ * @param {Array} a the array of vectors to iterate over
716
+ * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
717
+ * @param {Number} offset Number of elements to skip at the beginning of the array
718
+ * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
719
+ * @param {Function} fn Function to call for each vector in the array
720
+ * @param {Object} [arg] additional argument to pass to fn
721
+ * @returns {Array} a
722
+ * @function
723
+ */
724
+ export const forEach = (function () {
725
+ const vec = create();
726
+ return function (a, stride, offset, count, fn, arg) {
727
+ let i;
728
+ let l;
729
+ if (!stride) {
730
+ stride = 3;
731
+ }
732
+ if (!offset) {
733
+ offset = 0;
734
+ }
735
+ if (count) {
736
+ l = Math.min(count * stride + offset, a.length);
737
+ }
738
+ else {
739
+ l = a.length;
740
+ }
741
+ for (i = offset; i < l; i += stride) {
742
+ vec[0] = a[i];
743
+ vec[1] = a[i + 1];
744
+ vec[2] = a[i + 2];
745
+ fn(vec, vec, arg);
746
+ a[i] = vec[0];
747
+ a[i + 1] = vec[1];
748
+ a[i + 2] = vec[2];
749
+ }
750
+ return a;
751
+ };
752
+ })();