lecodes-cli 0.1.3 → 0.1.6

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