glmaths 0.0.2 → 0.0.4

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.
@@ -7,20 +7,20 @@ Object.defineProperty(exports, '__esModule', { value: true });
7
7
  * @extends Float32Array
8
8
  */
9
9
  class Vec3 extends Float32Array {
10
- static get zero() { return new Vec3(0, 0, 0); }
11
- static get Zero() { return new Vec3(0, 0, 0); }
12
- static get ZERO() { return new Vec3(0, 0, 0); }
13
- static get one() { return new Vec3(1, 1, 1); }
14
- static get One() { return new Vec3(1, 1, 1); }
15
- static get ONE() { return new Vec3(1, 1, 1); }
16
- static get unitX() { return new Vec3(1, 0, 0); }
17
- static get UnitX() { return new Vec3(1, 0, 0); }
18
- static get unitY() { return new Vec3(0, 1, 0); }
19
- static get UnitY() { return new Vec3(0, 1, 0); }
20
- static get unitZ() { return new Vec3(0, 0, 1); }
21
- static get UnitZ() { return new Vec3(0, 0, 1); }
22
- /**
23
- * Creates a new Vec3
10
+ static get zero() { return vec3(0, 0, 0); }
11
+ static get Zero() { return vec3(0, 0, 0); }
12
+ static get ZERO() { return vec3(0, 0, 0); }
13
+ static get one() { return vec3(1, 1, 1); }
14
+ static get One() { return vec3(1, 1, 1); }
15
+ static get ONE() { return vec3(1, 1, 1); }
16
+ static get unitX() { return vec3(1, 0, 0); }
17
+ static get UnitX() { return vec3(1, 0, 0); }
18
+ static get unitY() { return vec3(0, 1, 0); }
19
+ static get UnitY() { return vec3(0, 1, 0); }
20
+ static get unitZ() { return vec3(0, 0, 1); }
21
+ static get UnitZ() { return vec3(0, 0, 1); }
22
+ /**
23
+ * Creates new vec3
24
24
  *
25
25
  * @param {Number} x X component, defaults to 0
26
26
  * @param {Number} y Y component, defaults to 0
@@ -42,10 +42,10 @@ class Vec3 extends Float32Array {
42
42
  * Adds two vec3's
43
43
  *
44
44
  * @param {Number | Vec3} b the second operand
45
- * @param {Vec3} out the receiving vector, defaults to this
45
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
46
46
  * @returns {Vec3} out
47
47
  */
48
- plus(b, out = index.ALWAYS_COPY ? new Vec3() : this) {
48
+ plus(b, out = index.ALWAYS_COPY ? vec3() : this) {
49
49
  if (typeof b === 'number') {
50
50
  out[0] = this[0] + b;
51
51
  out[1] = this[1] + b;
@@ -62,10 +62,10 @@ class Vec3 extends Float32Array {
62
62
  * Subtracts two vec3's
63
63
  *
64
64
  * @param {Number | Vec3} b the second operand
65
- * @param {Vec3} out the receiving vector, defaults to this
65
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
66
66
  * @returns {Vec3} out
67
67
  */
68
- minus(b, out = index.ALWAYS_COPY ? new Vec3() : this) {
68
+ minus(b, out = index.ALWAYS_COPY ? vec3() : this) {
69
69
  if (typeof b === 'number') {
70
70
  out[0] = this[0] - b;
71
71
  out[1] = this[1] - b;
@@ -82,10 +82,10 @@ class Vec3 extends Float32Array {
82
82
  * Multiplies two vec3's
83
83
  *
84
84
  * @param {Number | Vec3} b the second operand
85
- * @param {Vec3} out the receiving vector, defaults to this
85
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
86
86
  * @returns {Vec3} out
87
87
  */
88
- mult(b, out = index.ALWAYS_COPY ? new Vec3() : this) {
88
+ mult(b, out = index.ALWAYS_COPY ? vec3() : this) {
89
89
  if (typeof b === 'number') {
90
90
  out[0] = this[0] * b;
91
91
  out[1] = this[1] * b;
@@ -102,10 +102,10 @@ class Vec3 extends Float32Array {
102
102
  * Divides two vec3's
103
103
  *
104
104
  * @param {Number | Vec3} b the second operand
105
- * @param {Vec3} out the receiving vector, defaults to this
105
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
106
106
  * @returns {Vec3} out
107
107
  */
108
- div(b, out = index.ALWAYS_COPY ? new Vec3() : this) {
108
+ div(b, out = index.ALWAYS_COPY ? vec3() : this) {
109
109
  if (typeof b === 'number') {
110
110
  out[0] = this[0] / b;
111
111
  out[1] = this[1] / b;
@@ -118,7 +118,7 @@ class Vec3 extends Float32Array {
118
118
  }
119
119
  return out;
120
120
  }
121
- invDiv(b, out = index.ALWAYS_COPY ? new Vec3() : this) {
121
+ invDiv(b, out = index.ALWAYS_COPY ? vec3() : this) {
122
122
  if (typeof b === 'number') {
123
123
  out[0] = b / this[0];
124
124
  out[1] = b / this[1];
@@ -132,18 +132,18 @@ class Vec3 extends Float32Array {
132
132
  return out;
133
133
  }
134
134
  /**
135
- * Negates the components of a vec3
135
+ * Negates the components of this vec3
136
136
  *
137
- * @param {Vec3} out the receiving vector, defaults to this
137
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
138
138
  * @returns {Vec3} out
139
139
  */
140
- negate(out = index.ALWAYS_COPY ? new Vec3() : this) {
140
+ negate(out = index.ALWAYS_COPY ? vec3() : this) {
141
141
  out[0] = -this[0];
142
142
  out[1] = -this[1];
143
143
  out[2] = -this[2];
144
144
  return out;
145
145
  }
146
- unaryPlus(out = index.ALWAYS_COPY ? new Vec3() : this) {
146
+ unaryPlus(out = index.ALWAYS_COPY ? vec3() : this) {
147
147
  if (!out.equals(this)) {
148
148
  out[0] = this[0];
149
149
  out[1] = this[1];
@@ -152,13 +152,13 @@ class Vec3 extends Float32Array {
152
152
  return out;
153
153
  }
154
154
  /**
155
- * Normalizes a vec3
155
+ * Normalizes vec3
156
156
  *
157
157
  * @param {Vec3} v the vector to normalize
158
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
158
+ * @param {Vec3} out the receiving vector, defaults to new vec3
159
159
  * @returns {Vec3} out
160
160
  */
161
- static normalize(v, out = new Vec3()) {
161
+ static normalize(v, out = vec3()) {
162
162
  const x = v[0], y = v[1], z = v[2];
163
163
  let len = x * x + y * y + z * z;
164
164
  if (len > 0)
@@ -169,12 +169,12 @@ class Vec3 extends Float32Array {
169
169
  return out;
170
170
  }
171
171
  /**
172
- * Normalizes a vec3
172
+ * Normalizes this vec3
173
173
  *
174
- * @param {Vec3} out the receiving vector, defaults to this
174
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
175
175
  * @returns {Vec3} out
176
176
  */
177
- normalize(out = index.ALWAYS_COPY ? new Vec3() : this) {
177
+ normalize(out = index.ALWAYS_COPY ? vec3() : this) {
178
178
  const x = this[0], y = this[1], z = this[2];
179
179
  let len = x * x + y * y + z * z;
180
180
  if (len > 0)
@@ -205,7 +205,7 @@ class Vec3 extends Float32Array {
205
205
  return this[0] === b[0] && this[1] === b[1] && this[2] === b[2];
206
206
  }
207
207
  /**
208
- * Calculates the squared length of a vec3
208
+ * Calculates the squared length of vec3
209
209
  *
210
210
  * @returns {Number} squared length of a vector
211
211
  */
@@ -214,7 +214,7 @@ class Vec3 extends Float32Array {
214
214
  return x * x + y * y + z * z;
215
215
  }
216
216
  /**
217
- * Calculates the length of a vec3
217
+ * Calculates the length of vec3
218
218
  *
219
219
  * @returns {Number} length of a vector
220
220
  */
@@ -223,104 +223,104 @@ class Vec3 extends Float32Array {
223
223
  return Math.sqrt(x * x + y * y + z * z);
224
224
  }
225
225
  /**
226
- * Returns a new vec3 with each component floored
226
+ * Returns vec3 with each component floored
227
227
  *
228
228
  * @param {Vec3} v the vector to floor
229
229
  * @returns {Vec3} a new floored vector
230
230
  */
231
- static floor(v, out = new Vec3()) {
231
+ static floor(v, out = vec3()) {
232
232
  out[0] = Math.floor(v[0]);
233
233
  out[1] = Math.floor(v[1]);
234
234
  out[2] = Math.floor(v[2]);
235
235
  return out;
236
236
  }
237
237
  /**
238
- * Returns a new vec3 with each component rounded
238
+ * Returns vec3 with each component rounded
239
239
  *
240
240
  * @param {Vec3} v the vector to round
241
241
  * @returns {Vec3} a new rounded vector
242
242
  */
243
- static round(v, out = new Vec3()) {
243
+ static round(v, out = vec3()) {
244
244
  out[0] = Math.round(v[0]);
245
245
  out[1] = Math.round(v[1]);
246
246
  out[2] = Math.round(v[2]);
247
247
  return out;
248
248
  }
249
249
  /**
250
- * Returns a new vec3 with each component ceiled
250
+ * Returns vec3 with each component ceiled
251
251
  *
252
252
  * @param {Vec3} v the vector to ceil
253
253
  * @returns {Vec3} a new ceiled vector
254
254
  */
255
- static ceil(v, out = new Vec3()) {
255
+ static ceil(v, out = vec3()) {
256
256
  out[0] = Math.ceil(v[0]);
257
257
  out[1] = Math.ceil(v[1]);
258
258
  out[2] = Math.ceil(v[2]);
259
259
  return out;
260
260
  }
261
261
  /**
262
- * Floors each component of a vec3
262
+ * Floors each component of vec3
263
263
  *
264
264
  * @returns {Vec3} this
265
265
  */
266
- floor(out = index.ALWAYS_COPY ? new Vec3() : this) {
266
+ floor(out = index.ALWAYS_COPY ? vec3() : this) {
267
267
  out[0] = Math.floor(this[0]);
268
268
  out[1] = Math.floor(this[1]);
269
269
  out[2] = Math.floor(this[2]);
270
270
  return out;
271
271
  }
272
272
  /**
273
- * Rounds each component of a vec3
273
+ * Rounds each component of vec3
274
274
  *
275
275
  * @returns {Vec3} this
276
276
  */
277
- round(out = index.ALWAYS_COPY ? new Vec3() : this) {
277
+ round(out = index.ALWAYS_COPY ? vec3() : this) {
278
278
  out[0] = Math.round(this[0]);
279
279
  out[1] = Math.round(this[1]);
280
280
  out[2] = Math.round(this[2]);
281
281
  return out;
282
282
  }
283
283
  /**
284
- * Ceils each component of a vec3
284
+ * Ceils each component of vec3
285
285
  *
286
286
  * @returns {Vec3} this
287
287
  */
288
- ceil(out = index.ALWAYS_COPY ? new Vec3() : this) {
288
+ ceil(out = index.ALWAYS_COPY ? vec3() : this) {
289
289
  out[0] = Math.ceil(this[0]);
290
290
  out[1] = Math.ceil(this[1]);
291
291
  out[2] = Math.ceil(this[2]);
292
292
  return out;
293
293
  }
294
294
  /**
295
- * Returns the inverse of a vec3
295
+ * Returns the inverse of vec3
296
296
  *
297
297
  * @param {Vec3} v the source vector
298
298
  * @returns {Vec3} a new inverted vector
299
299
  */
300
- static inverse(v, out = new Vec3()) {
300
+ static inverse(v, out = vec3()) {
301
301
  out[0] = 1.0 / v[0];
302
302
  out[1] = 1.0 / v[1];
303
303
  out[2] = 1.0 / v[2];
304
304
  return out;
305
305
  }
306
306
  /**
307
- * Inverts a vec3 component-wise
307
+ * Inverts vec3 component-wise
308
308
  *
309
309
  * @returns {Vec3} this
310
310
  */
311
- inverse(out = index.ALWAYS_COPY ? new Vec3() : this) {
311
+ inverse(out = index.ALWAYS_COPY ? vec3() : this) {
312
312
  out[0] = 1.0 / this[0];
313
313
  out[1] = 1.0 / this[1];
314
314
  out[2] = 1.0 / this[2];
315
315
  return out;
316
316
  }
317
317
  /**
318
- * Creates a new vec3 initialized with values from a vector
318
+ * Creates vec3 initialized with values from a vector
319
319
  *
320
- * @returns {Vec3} a new Vec3
320
+ * @returns {Vec3} vec3
321
321
  */
322
322
  clone() {
323
- return new Vec3(this[0], this[1], this[2]);
323
+ return vec3(this[0], this[1], this[2]);
324
324
  }
325
325
  /**
326
326
  * Returns a string representation of a vector
@@ -340,7 +340,7 @@ class Vec3 extends Float32Array {
340
340
  const r = index.RANDOM() * 2.0 * Math.PI;
341
341
  const z = index.RANDOM() * 2.0 - 1.0;
342
342
  const zScale = Math.sqrt(1.0 - z * z) * scale;
343
- return new Vec3(Math.cos(r) * zScale, Math.sin(r) * zScale, z * scale);
343
+ return vec3(Math.cos(r) * zScale, Math.sin(r) * zScale, z * scale);
344
344
  }
345
345
  /**
346
346
  * Calculates the angle between two vec3's
@@ -371,10 +371,10 @@ class Vec3 extends Float32Array {
371
371
  *
372
372
  * @param {Vec3} a the first operand
373
373
  * @param {Vec3} b the second operand
374
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
374
+ * @param {Vec3} out the receiving vector, defaults to new vec3
375
375
  * @returns {Vec3} out
376
376
  */
377
- static cross(a, b, out = new Vec3()) {
377
+ static cross(a, b, out = vec3()) {
378
378
  const ax = a[0], ay = a[1], az = a[2];
379
379
  const bx = b[0], by = b[1], bz = b[2];
380
380
  out[0] = ay * bz - az * by;
@@ -414,10 +414,10 @@ class Vec3 extends Float32Array {
414
414
  * @param {Vec3} a the first operand
415
415
  * @param {Vec3} b the second operand
416
416
  * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
417
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
417
+ * @param {Vec3} out the receiving vector, defaults to new vec3
418
418
  * @returns {Vec3} out
419
419
  */
420
- static lerp(a, b, t, out = new Vec3()) {
420
+ static lerp(a, b, t, out = vec3()) {
421
421
  const ax = a[0], ay = a[1], az = a[2];
422
422
  out[0] = ax + (b[0] - ax) * t;
423
423
  out[1] = ay + (b[1] - ay) * t;
@@ -430,10 +430,10 @@ class Vec3 extends Float32Array {
430
430
  * @param {Vec3} a the first operand
431
431
  * @param {Vec3} b the second operand
432
432
  * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
433
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
433
+ * @param {Vec3} out the receiving vector, defaults to new vec3
434
434
  * @returns {Vec3} out
435
435
  */
436
- static slerp(a, b, t, out = new Vec3()) {
436
+ static slerp(a, b, t, out = vec3()) {
437
437
  const angle = Math.acos(Math.min(Math.max(Vec3.dot(a, b), -1), 1));
438
438
  const sinTotal = Math.sin(angle);
439
439
  const ratioA = Math.sin((1 - t) * angle) / sinTotal;
@@ -450,7 +450,7 @@ class Vec3 extends Float32Array {
450
450
  * @param {Vec3} b the second operand
451
451
  * @returns {Vec3} a new vector with the max components
452
452
  */
453
- static max(a, b, out = new Vec3()) {
453
+ static max(a, b, out = vec3()) {
454
454
  out[0] = Math.max(a[0], b[0]);
455
455
  out[1] = Math.max(a[1], b[1]);
456
456
  out[2] = Math.max(a[2], b[2]);
@@ -463,7 +463,7 @@ class Vec3 extends Float32Array {
463
463
  * @param {Vec3} b the second operand
464
464
  * @returns {Vec3} a new vector with the min components
465
465
  */
466
- static min(a, b, out = new Vec3()) {
466
+ static min(a, b, out = vec3()) {
467
467
  out[0] = Math.min(a[0], b[0]);
468
468
  out[1] = Math.min(a[1], b[1]);
469
469
  out[2] = Math.min(a[2], b[2]);
@@ -478,7 +478,7 @@ class Vec3 extends Float32Array {
478
478
  * @param {Vec3} out the receiving vector
479
479
  * @returns {Vec3} out
480
480
  */
481
- static clamp(v, min, max, out = new Vec3()) {
481
+ static clamp(v, min, max, out = vec3()) {
482
482
  const minX = typeof min === 'number' ? min : min[0];
483
483
  const minY = typeof min === 'number' ? min : min[1];
484
484
  const minZ = typeof min === 'number' ? min : min[2];
@@ -499,7 +499,7 @@ class Vec3 extends Float32Array {
499
499
  * @param {Vec3} out the receiving vector
500
500
  * @returns {Vec3} out
501
501
  */
502
- static mix(a, b, t, out = new Vec3()) {
502
+ static mix(a, b, t, out = vec3()) {
503
503
  if (typeof t === 'number') {
504
504
  out[0] = a[0] + (b[0] - a[0]) * t;
505
505
  out[1] = a[1] + (b[1] - a[1]) * t;
@@ -521,7 +521,7 @@ class Vec3 extends Float32Array {
521
521
  * @param {Vec3} out the receiving vector
522
522
  * @returns {Vec3} out
523
523
  */
524
- static smoothstep(edge0, edge1, v, out = new Vec3()) {
524
+ static smoothstep(edge0, edge1, v, out = vec3()) {
525
525
  const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
526
526
  const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
527
527
  const e0z = typeof edge0 === 'number' ? edge0 : edge0[2];
@@ -537,14 +537,14 @@ class Vec3 extends Float32Array {
537
537
  return out;
538
538
  }
539
539
  /**
540
- * Rotates a vec3 around the X axis
540
+ * Rotates vec3 around the X axis
541
541
  *
542
542
  * @param {Vec3} v the vector to rotate
543
543
  * @param {Number} rad the angle of rotation in radians
544
- * @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
544
+ * @param {Vec3} origin the origin of the rotation, defaults to vec3(0, 0, 0)
545
545
  * @returns {Vec3} a new rotated vector
546
546
  */
547
- static rotateX(v, rad, origin = Vec3.zero, out = new Vec3()) {
547
+ static rotateX(v, rad, origin = vec3.zero, out = vec3()) {
548
548
  const p1 = v[1] - origin[1];
549
549
  const p2 = v[2] - origin[2];
550
550
  out[0] = v[0];
@@ -553,13 +553,13 @@ class Vec3 extends Float32Array {
553
553
  return out;
554
554
  }
555
555
  /**
556
- * Rotates a vec3 around the X axis
556
+ * Rotates vec3 around the X axis
557
557
  *
558
558
  * @param {Number} rad the angle of rotation in radians
559
- * @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
559
+ * @param {Vec3} origin the origin of the rotation, defaults to vec3(0, 0, 0)
560
560
  * @returns {Vec3} a rotated vector
561
561
  */
562
- rotateX(rad, origin = Vec3.zero, out = index.ALWAYS_COPY ? new Vec3() : this) {
562
+ rotateX(rad, origin = vec3.zero, out = index.ALWAYS_COPY ? vec3() : this) {
563
563
  const p1 = this[1] - origin[1];
564
564
  const p2 = this[2] - origin[2];
565
565
  out[0] = this[0];
@@ -568,14 +568,14 @@ class Vec3 extends Float32Array {
568
568
  return out;
569
569
  }
570
570
  /**
571
- * Rotates a vec3 around the Y axis
571
+ * Rotates vec3 around the Y axis
572
572
  *
573
573
  * @param {Vec3} v the vector to rotate
574
574
  * @param {Number} rad the angle of rotation in radians
575
- * @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
575
+ * @param {Vec3} origin the origin of the rotation, defaults to vec3(0, 0, 0)
576
576
  * @returns {Vec3} a rotated vector
577
577
  */
578
- static rotateY(v, rad, origin = Vec3.zero, out = new Vec3()) {
578
+ static rotateY(v, rad, origin = vec3.zero, out = vec3()) {
579
579
  const p0 = v[0] - origin[0];
580
580
  const p2 = v[2] - origin[2];
581
581
  out[0] = p2 * Math.sin(rad) + p0 * Math.cos(rad) + origin[0];
@@ -584,12 +584,12 @@ class Vec3 extends Float32Array {
584
584
  return out;
585
585
  }
586
586
  /**
587
- * Rotates a vec3 around the Y axis
587
+ * Rotates vec3 around the Y axis
588
588
  *
589
589
  * @param {Number} rad the angle of rotation in radians
590
- * @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
590
+ * @param {Vec3} origin the origin of the rotation, defaults to vec3(0, 0, 0)
591
591
  */
592
- rotateY(rad, origin = Vec3.zero, out = index.ALWAYS_COPY ? new Vec3() : this) {
592
+ rotateY(rad, origin = vec3.zero, out = index.ALWAYS_COPY ? vec3() : this) {
593
593
  const p0 = this[0] - origin[0];
594
594
  const p2 = this[2] - origin[2];
595
595
  out[0] = p2 * Math.sin(rad) + p0 * Math.cos(rad) + origin[0];
@@ -598,14 +598,14 @@ class Vec3 extends Float32Array {
598
598
  return out;
599
599
  }
600
600
  /**
601
- * Rotates a vec3 around the Z axis
601
+ * Rotates vec3 around the Z axis
602
602
  *
603
603
  * @param {Vec3} v the vector to rotate
604
604
  * @param {Number} rad the angle of rotation in radians
605
605
  * @param {Vec3} origin the origin of the rotation, defaults to ZERO
606
606
  * @returns {Vec3} a new rotated vector
607
607
  */
608
- static rotateZ(v, rad, origin = Vec3.zero, out = new Vec3()) {
608
+ static rotateZ(v, rad, origin = vec3.zero, out = vec3()) {
609
609
  const p0 = v[0] - origin[0];
610
610
  const p1 = v[1] - origin[1];
611
611
  out[0] = p0 * Math.cos(rad) - p1 * Math.sin(rad) + origin[0];
@@ -614,12 +614,12 @@ class Vec3 extends Float32Array {
614
614
  return out;
615
615
  }
616
616
  /**
617
- * Rotates a vec3 around the Z axis
617
+ * Rotates vec3 around the Z axis
618
618
  *
619
619
  * @param {Number} rad the angle of rotation in radians
620
- * @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
620
+ * @param {Vec3} origin the origin of the rotation, defaults to vec3(0, 0, 0)
621
621
  */
622
- rotateZ(rad, origin = Vec3.zero, out = index.ALWAYS_COPY ? new Vec3() : this) {
622
+ rotateZ(rad, origin = vec3.zero, out = index.ALWAYS_COPY ? vec3() : this) {
623
623
  const p0 = this[0] - origin[0];
624
624
  const p1 = this[1] - origin[1];
625
625
  out[0] = p0 * Math.cos(rad) - p1 * Math.sin(rad) + origin[0];
@@ -637,7 +637,7 @@ class Vec3 extends Float32Array {
637
637
  * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
638
638
  * @returns {Vec3} a new vector
639
639
  */
640
- static hermite(a, b, c, d, t, out = new Vec3()) {
640
+ static hermite(a, b, c, d, t, out = vec3()) {
641
641
  const factorTimes2 = t * t;
642
642
  const factor1 = factorTimes2 * (2 * t - 3) + 1;
643
643
  const factor2 = factorTimes2 * (t - 2) + t;
@@ -658,7 +658,7 @@ class Vec3 extends Float32Array {
658
658
  * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
659
659
  * @returns {Vec3} a new vector
660
660
  */
661
- static bezier(a, b, c, d, t, out = new Vec3()) {
661
+ static bezier(a, b, c, d, t, out = vec3()) {
662
662
  const inverseFactor = 1 - t;
663
663
  const inverseFactorTimesTwo = inverseFactor * inverseFactor;
664
664
  const factorTimes2 = t * t;
@@ -677,10 +677,10 @@ class Vec3 extends Float32Array {
677
677
  * @param {Vec3} a the first operand
678
678
  * @param {Vec3} b the second operand
679
679
  * @param {Number} scale the amount to scale b by before adding
680
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
680
+ * @param {Vec3} out the receiving vector, defaults to new vec3
681
681
  * @returns {Vec3} out
682
682
  */
683
- static scaleAndAdd(a, b, scale, out = new Vec3()) {
683
+ static scaleAndAdd(a, b, scale, out = vec3()) {
684
684
  out[0] = a[0] + b[0] * scale;
685
685
  out[1] = a[1] + b[1] * scale;
686
686
  out[2] = a[2] + b[2] * scale;
@@ -691,10 +691,10 @@ class Vec3 extends Float32Array {
691
691
  *
692
692
  * @param {Vec3} I the incident vector
693
693
  * @param {Vec3} N the surface normal
694
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
694
+ * @param {Vec3} out the receiving vector, defaults to new vec3
695
695
  * @returns {Vec3} out
696
696
  */
697
- static reflect(I, N, out = new Vec3()) {
697
+ static reflect(I, N, out = vec3()) {
698
698
  const d = Vec3.dot(N, I) * 2;
699
699
  out[0] = I[0] - d * N[0];
700
700
  out[1] = I[1] - d * N[1];
@@ -707,10 +707,10 @@ class Vec3 extends Float32Array {
707
707
  * @param {Vec3} I the incident vector
708
708
  * @param {Vec3} N the surface normal
709
709
  * @param {Number} eta the ratio of indices of refraction
710
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
710
+ * @param {Vec3} out the receiving vector, defaults to new vec3
711
711
  * @returns {Vec3} out
712
712
  */
713
- static refract(I, N, eta, out = new Vec3()) {
713
+ static refract(I, N, eta, out = vec3()) {
714
714
  const d = Vec3.dot(N, I);
715
715
  const k = 1.0 - eta * eta * (1.0 - d * d);
716
716
  if (k < 0.0) {
@@ -729,10 +729,10 @@ class Vec3 extends Float32Array {
729
729
  * @param {Vec3} N the vector to orient
730
730
  * @param {Vec3} I the incident vector
731
731
  * @param {Vec3} Nref the reference vector
732
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
732
+ * @param {Vec3} out the receiving vector, defaults to new vec3
733
733
  * @returns {Vec3} out
734
734
  */
735
- static faceforward(N, I, Nref, out = new Vec3()) {
735
+ static faceforward(N, I, Nref, out = vec3()) {
736
736
  const d = Vec3.dot(Nref, I);
737
737
  const sign = d < 0 ? 1 : -1;
738
738
  out[0] = N[0] * sign;
@@ -746,10 +746,10 @@ class Vec3 extends Float32Array {
746
746
  * @param {Vec3} p1 the first vertex
747
747
  * @param {Vec3} p2 the second vertex
748
748
  * @param {Vec3} p3 the third vertex
749
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
749
+ * @param {Vec3} out the receiving vector, defaults to new vec3
750
750
  * @returns {Vec3} out
751
751
  */
752
- static triangleNormal(p1, p2, p3, out = new Vec3()) {
752
+ static triangleNormal(p1, p2, p3, out = vec3()) {
753
753
  const e1x = p2[0] - p1[0], e1y = p2[1] - p1[1], e1z = p2[2] - p1[2];
754
754
  const e2x = p3[0] - p1[0], e2y = p3[1] - p1[1], e2z = p3[2] - p1[2];
755
755
  out[0] = e1y * e2z - e1z * e2y;
@@ -769,10 +769,10 @@ class Vec3 extends Float32Array {
769
769
  *
770
770
  * @param {Vec3} a the vector to project
771
771
  * @param {Vec3} b the vector to project onto
772
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
772
+ * @param {Vec3} out the receiving vector, defaults to new vec3
773
773
  * @returns {Vec3} out
774
774
  */
775
- static project(a, b, out = new Vec3()) {
775
+ static project(a, b, out = vec3()) {
776
776
  const d = Vec3.dot(a, b) / Vec3.dot(b, b);
777
777
  out[0] = b[0] * d;
778
778
  out[1] = b[1] * d;
@@ -797,22 +797,22 @@ class Vec3 extends Float32Array {
797
797
  *
798
798
  * @param {Vec3} b the second operand
799
799
  * @param {Number} scale the amount to scale b by before adding
800
- * @param {Vec3} out the receiving vector, defaults to this
800
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
801
801
  * @returns {Vec3} out
802
802
  */
803
- scaleAndAdd(b, scale, out = index.ALWAYS_COPY ? new Vec3() : this) {
803
+ scaleAndAdd(b, scale, out = index.ALWAYS_COPY ? vec3() : this) {
804
804
  out[0] = this[0] + b[0] * scale;
805
805
  out[1] = this[1] + b[1] * scale;
806
806
  out[2] = this[2] + b[2] * scale;
807
807
  return out;
808
808
  }
809
809
  /**
810
- * Returns a vec3 with each component set to its absolute value
810
+ * Returns vec3 with each component set to its absolute value
811
811
  *
812
- * @param {Vec3} out the receiving vector, defaults to this
812
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
813
813
  * @returns {Vec3} out
814
814
  */
815
- abs(out = index.ALWAYS_COPY ? new Vec3() : this) {
815
+ abs(out = index.ALWAYS_COPY ? vec3() : this) {
816
816
  out[0] = Math.abs(this[0]);
817
817
  out[1] = Math.abs(this[1]);
818
818
  out[2] = Math.abs(this[2]);
@@ -823,10 +823,10 @@ class Vec3 extends Float32Array {
823
823
  *
824
824
  * @param {Vec3 | number} min the lower bound (per-component or scalar)
825
825
  * @param {Vec3 | number} max the upper bound (per-component or scalar)
826
- * @param {Vec3} out the receiving vector, defaults to this
826
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
827
827
  * @returns {Vec3} out
828
828
  */
829
- clamp(min, max, out = index.ALWAYS_COPY ? new Vec3() : this) {
829
+ clamp(min, max, out = index.ALWAYS_COPY ? vec3() : this) {
830
830
  const minX = typeof min === 'number' ? min : min[0];
831
831
  const minY = typeof min === 'number' ? min : min[1];
832
832
  const minZ = typeof min === 'number' ? min : min[2];
@@ -843,10 +843,10 @@ class Vec3 extends Float32Array {
843
843
  *
844
844
  * @param {Vec3} b the second operand
845
845
  * @param {Vec3 | number} t interpolation amount (per-component or scalar)
846
- * @param {Vec3} out the receiving vector, defaults to this
846
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
847
847
  * @returns {Vec3} out
848
848
  */
849
- mix(b, t, out = index.ALWAYS_COPY ? new Vec3() : this) {
849
+ mix(b, t, out = index.ALWAYS_COPY ? vec3() : this) {
850
850
  if (typeof t === 'number') {
851
851
  out[0] = this[0] + (b[0] - this[0]) * t;
852
852
  out[1] = this[1] + (b[1] - this[1]) * t;
@@ -863,10 +863,10 @@ class Vec3 extends Float32Array {
863
863
  * Generates a step function by comparing this vector to edge.
864
864
  *
865
865
  * @param {Vec3 | number} edge the edge value (per-component or scalar)
866
- * @param {Vec3} out the receiving vector, defaults to this
866
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
867
867
  * @returns {Vec3} out
868
868
  */
869
- step(edge, out = index.ALWAYS_COPY ? new Vec3() : this) {
869
+ step(edge, out = index.ALWAYS_COPY ? vec3() : this) {
870
870
  if (typeof edge === 'number') {
871
871
  out[0] = this[0] < edge ? 0 : 1;
872
872
  out[1] = this[1] < edge ? 0 : 1;
@@ -884,10 +884,10 @@ class Vec3 extends Float32Array {
884
884
  *
885
885
  * @param {Vec3 | number} edge0 the lower edge (per-component or scalar)
886
886
  * @param {Vec3 | number} edge1 the upper edge (per-component or scalar)
887
- * @param {Vec3} out the receiving vector, defaults to this
887
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
888
888
  * @returns {Vec3} out
889
889
  */
890
- smoothstep(edge0, edge1, out = index.ALWAYS_COPY ? new Vec3() : this) {
890
+ smoothstep(edge0, edge1, out = index.ALWAYS_COPY ? vec3() : this) {
891
891
  const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
892
892
  const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
893
893
  const e0z = typeof edge0 === 'number' ? edge0 : edge0[2];
@@ -905,10 +905,10 @@ class Vec3 extends Float32Array {
905
905
  /**
906
906
  * Returns the fractional part of each component.
907
907
  *
908
- * @param {Vec3} out the receiving vector, defaults to this
908
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
909
909
  * @returns {Vec3} out
910
910
  */
911
- fract(out = index.ALWAYS_COPY ? new Vec3() : this) {
911
+ fract(out = index.ALWAYS_COPY ? vec3() : this) {
912
912
  out[0] = this[0] - Math.floor(this[0]);
913
913
  out[1] = this[1] - Math.floor(this[1]);
914
914
  out[2] = this[2] - Math.floor(this[2]);
@@ -917,10 +917,10 @@ class Vec3 extends Float32Array {
917
917
  /**
918
918
  * Returns the sign of each component (-1, 0, or 1).
919
919
  *
920
- * @param {Vec3} out the receiving vector, defaults to this
920
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
921
921
  * @returns {Vec3} out
922
922
  */
923
- sign(out = index.ALWAYS_COPY ? new Vec3() : this) {
923
+ sign(out = index.ALWAYS_COPY ? vec3() : this) {
924
924
  out[0] = this[0] > 0 ? 1 : this[0] < 0 ? -1 : 0;
925
925
  out[1] = this[1] > 0 ? 1 : this[1] < 0 ? -1 : 0;
926
926
  out[2] = this[2] > 0 ? 1 : this[2] < 0 ? -1 : 0;
@@ -929,10 +929,10 @@ class Vec3 extends Float32Array {
929
929
  /**
930
930
  * Clamps each component to [0, 1].
931
931
  *
932
- * @param {Vec3} out the receiving vector, defaults to this
932
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
933
933
  * @returns {Vec3} out
934
934
  */
935
- saturate(out = index.ALWAYS_COPY ? new Vec3() : this) {
935
+ saturate(out = index.ALWAYS_COPY ? vec3() : this) {
936
936
  out[0] = Math.min(Math.max(this[0], 0), 1);
937
937
  out[1] = Math.min(Math.max(this[1], 0), 1);
938
938
  out[2] = Math.min(Math.max(this[2], 0), 1);
@@ -942,10 +942,10 @@ class Vec3 extends Float32Array {
942
942
  * Transforms this vec3 with a Mat3
943
943
  *
944
944
  * @param {Mat3} m the 3x3 matrix to transform with
945
- * @param {Vec3} out the receiving vector, defaults to this
945
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
946
946
  * @returns {Vec3} out
947
947
  */
948
- transformMat3(m, out = index.ALWAYS_COPY ? new Vec3() : this) {
948
+ transformMat3(m, out = index.ALWAYS_COPY ? vec3() : this) {
949
949
  const x = this[0], y = this[1], z = this[2];
950
950
  out[0] = x * m[0] + y * m[3] + z * m[6];
951
951
  out[1] = x * m[1] + y * m[4] + z * m[7];
@@ -956,10 +956,10 @@ class Vec3 extends Float32Array {
956
956
  * Transforms this vec3 with a Mat4 (as a point, w=1)
957
957
  *
958
958
  * @param {Mat4} m the 4x4 matrix to transform with
959
- * @param {Vec3} out the receiving vector, defaults to this
959
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
960
960
  * @returns {Vec3} out
961
961
  */
962
- transformMat4(m, out = index.ALWAYS_COPY ? new Vec3() : this) {
962
+ transformMat4(m, out = index.ALWAYS_COPY ? vec3() : this) {
963
963
  const x = this[0], y = this[1], z = this[2];
964
964
  let w = m[3] * x + m[7] * y + m[11] * z + m[15];
965
965
  w = w || 1.0;
@@ -972,10 +972,10 @@ class Vec3 extends Float32Array {
972
972
  * Transforms this vec3 with a quaternion
973
973
  *
974
974
  * @param {Quat} q the quaternion to transform with
975
- * @param {Vec3} out the receiving vector, defaults to this
975
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
976
976
  * @returns {Vec3} out
977
977
  */
978
- transformQuat(q, out = index.ALWAYS_COPY ? new Vec3() : this) {
978
+ transformQuat(q, out = index.ALWAYS_COPY ? vec3() : this) {
979
979
  const qx = q[0], qy = q[1], qz = q[2], qw = q[3];
980
980
  const x = this[0], y = this[1], z = this[2];
981
981
  let uvx = qy * z - qz * y, uvy = qz * x - qx * z, uvz = qx * y - qy * x;
@@ -1009,6 +1009,7 @@ Vec3.prototype.neg = Vec3.prototype.negate;
1009
1009
  Vec3.prototype.unaryMinus = Vec3.prototype.negate;
1010
1010
  Vec3.prototype.sqrLen = Vec3.prototype.squaredLength;
1011
1011
  Vec3.prototype.str = Vec3.prototype.toString;
1012
+ Vec3.prototype.normalized = Vec3.prototype.normalize;
1012
1013
  Vec3.prototype.transformMat3x3 = Vec3.prototype.transformMat3;
1013
1014
  Vec3.prototype.transformMat4x4 = Vec3.prototype.transformMat4;
1014
1015
  const createVec3 = (...args) => {
@@ -1033,14 +1034,14 @@ const vec3 = createVec3;
1033
1034
  * @extends Float32Array
1034
1035
  */
1035
1036
  class Vec4 extends Float32Array {
1036
- static get zero() { return new Vec4(0, 0, 0, 0); }
1037
- static get Zero() { return new Vec4(0, 0, 0, 0); }
1038
- static get ZERO() { return new Vec4(0, 0, 0, 0); }
1039
- static get one() { return new Vec4(1, 1, 1, 1); }
1040
- static get One() { return new Vec4(1, 1, 1, 1); }
1041
- static get ONE() { return new Vec4(1, 1, 1, 1); }
1037
+ static get zero() { return vec4(0, 0, 0, 0); }
1038
+ static get Zero() { return vec4(0, 0, 0, 0); }
1039
+ static get ZERO() { return vec4(0, 0, 0, 0); }
1040
+ static get one() { return vec4(1, 1, 1, 1); }
1041
+ static get One() { return vec4(1, 1, 1, 1); }
1042
+ static get ONE() { return vec4(1, 1, 1, 1); }
1042
1043
  /**
1043
- * Creates a new Vec4
1044
+ * Creates a vec4
1044
1045
  *
1045
1046
  * @param {Number} x X component, defaults to 0
1046
1047
  * @param {Number} y Y component, defaults to 0
@@ -1066,10 +1067,10 @@ class Vec4 extends Float32Array {
1066
1067
  * Adds two vec4's
1067
1068
  *
1068
1069
  * @param {Vec4 | Number} b the second operand
1069
- * @param {Vec4} out the receiving vector, defaults to this
1070
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1070
1071
  * @returns {Vec4} out
1071
1072
  */
1072
- plus(b, out = index.ALWAYS_COPY ? new Vec4() : this) {
1073
+ plus(b, out = index.ALWAYS_COPY ? vec4() : this) {
1073
1074
  if (typeof b === 'number') {
1074
1075
  out[0] = this[0] + b;
1075
1076
  out[1] = this[1] + b;
@@ -1088,10 +1089,10 @@ class Vec4 extends Float32Array {
1088
1089
  * Subtracts two vec4's
1089
1090
  *
1090
1091
  * @param {Vec4 | Number} b the second operand
1091
- * @param {Vec4} out the receiving vector, defaults to this
1092
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1092
1093
  * @returns {Vec4} out
1093
1094
  */
1094
- minus(b, out = index.ALWAYS_COPY ? new Vec4() : this) {
1095
+ minus(b, out = index.ALWAYS_COPY ? vec4() : this) {
1095
1096
  if (typeof b === 'number') {
1096
1097
  out[0] = this[0] - b;
1097
1098
  out[1] = this[1] - b;
@@ -1110,10 +1111,10 @@ class Vec4 extends Float32Array {
1110
1111
  * Multiplies two vec4's
1111
1112
  *
1112
1113
  * @param {Vec4 | Number} b the second operand
1113
- * @param {Vec4} out the receiving vector, defaults to this
1114
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1114
1115
  * @returns {Vec4} out
1115
1116
  */
1116
- mult(b, out = index.ALWAYS_COPY ? new Vec4() : this) {
1117
+ mult(b, out = index.ALWAYS_COPY ? vec4() : this) {
1117
1118
  if (typeof b === 'number') {
1118
1119
  out[0] = this[0] * b;
1119
1120
  out[1] = this[1] * b;
@@ -1132,10 +1133,10 @@ class Vec4 extends Float32Array {
1132
1133
  * Divides two vec4's
1133
1134
  *
1134
1135
  * @param {Vec4 | Number} b the second operand
1135
- * @param {Vec4} out the receiving vector, defaults to this
1136
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1136
1137
  * @returns {Vec4} out
1137
1138
  */
1138
- div(b, out = index.ALWAYS_COPY ? new Vec4() : this) {
1139
+ div(b, out = index.ALWAYS_COPY ? vec4() : this) {
1139
1140
  if (typeof b === 'number') {
1140
1141
  out[0] = this[0] / b;
1141
1142
  out[1] = this[1] / b;
@@ -1150,7 +1151,7 @@ class Vec4 extends Float32Array {
1150
1151
  }
1151
1152
  return out;
1152
1153
  }
1153
- invDiv(b, out = index.ALWAYS_COPY ? new Vec4() : this) {
1154
+ invDiv(b, out = index.ALWAYS_COPY ? vec4() : this) {
1154
1155
  if (typeof b === 'number') {
1155
1156
  out[0] = b / this[0];
1156
1157
  out[1] = b / this[1];
@@ -1168,17 +1169,17 @@ class Vec4 extends Float32Array {
1168
1169
  /**
1169
1170
  * Negates the components of a vec4
1170
1171
  *
1171
- * @param {Vec4} out the receiving vector, defaults to this
1172
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1172
1173
  * @returns {Vec4} out
1173
1174
  */
1174
- negate(out = index.ALWAYS_COPY ? new Vec4() : this) {
1175
+ negate(out = index.ALWAYS_COPY ? vec4() : this) {
1175
1176
  out[0] = -this[0];
1176
1177
  out[1] = -this[1];
1177
1178
  out[2] = -this[2];
1178
1179
  out[3] = -this[3];
1179
1180
  return out;
1180
1181
  }
1181
- unaryPlus(out = index.ALWAYS_COPY ? new Vec4() : this) {
1182
+ unaryPlus(out = index.ALWAYS_COPY ? vec4() : this) {
1182
1183
  if (!out.equals(this)) {
1183
1184
  out[0] = this[0];
1184
1185
  out[1] = this[1];
@@ -1190,10 +1191,29 @@ class Vec4 extends Float32Array {
1190
1191
  /**
1191
1192
  * Normalizes a vec4
1192
1193
  *
1193
- * @param {Vec4} out the receiving vector, defaults to this
1194
+ * @param {Vec4} v vector to normalize
1195
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1196
+ * @returns {Vec4} out
1197
+ */
1198
+ static normalize(v, out = vec4()) {
1199
+ const x = v[0], y = v[1], z = v[2], w = v[3];
1200
+ let len = x * x + y * y + z * z + w * w;
1201
+ if (len > 0) {
1202
+ len = 1.0 / Math.sqrt(len);
1203
+ }
1204
+ out[0] = x * len;
1205
+ out[1] = y * len;
1206
+ out[2] = z * len;
1207
+ out[3] = w * len;
1208
+ return out;
1209
+ }
1210
+ /**
1211
+ * Normalizes a vec4
1212
+ *
1213
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1194
1214
  * @returns {Vec4} out
1195
1215
  */
1196
- normalize(out = index.ALWAYS_COPY ? new Vec4() : this) {
1216
+ normalize(out = index.ALWAYS_COPY ? vec4() : this) {
1197
1217
  const x = this[0], y = this[1], z = this[2], w = this[3];
1198
1218
  let len = x * x + y * y + z * z + w * w;
1199
1219
  if (len > 0) {
@@ -1245,10 +1265,10 @@ class Vec4 extends Float32Array {
1245
1265
  /**
1246
1266
  * Math.floor the components of a vec4
1247
1267
  *
1248
- * @param {Vec4} out the receiving vector, defaults to this
1268
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1249
1269
  * @returns {Vec4} out
1250
1270
  */
1251
- floor(out = index.ALWAYS_COPY ? new Vec4() : this) {
1271
+ floor(out = index.ALWAYS_COPY ? vec4() : this) {
1252
1272
  out[0] = Math.floor(this[0]);
1253
1273
  out[1] = Math.floor(this[1]);
1254
1274
  out[2] = Math.floor(this[2]);
@@ -1258,10 +1278,10 @@ class Vec4 extends Float32Array {
1258
1278
  /**
1259
1279
  * Math.round the components of a vec4
1260
1280
  *
1261
- * @param {Vec4} out the receiving vector, defaults to this
1281
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1262
1282
  * @returns {Vec4} out
1263
1283
  */
1264
- round(out = index.ALWAYS_COPY ? new Vec4() : this) {
1284
+ round(out = index.ALWAYS_COPY ? vec4() : this) {
1265
1285
  out[0] = Math.round(this[0]);
1266
1286
  out[1] = Math.round(this[1]);
1267
1287
  out[2] = Math.round(this[2]);
@@ -1271,10 +1291,10 @@ class Vec4 extends Float32Array {
1271
1291
  /**
1272
1292
  * Math.ceil the components of a vec4
1273
1293
  *
1274
- * @param {Vec4} out the receiving vector, defaults to this
1294
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1275
1295
  * @returns {Vec4} out
1276
1296
  */
1277
- ceil(out = index.ALWAYS_COPY ? new Vec4() : this) {
1297
+ ceil(out = index.ALWAYS_COPY ? vec4() : this) {
1278
1298
  out[0] = Math.ceil(this[0]);
1279
1299
  out[1] = Math.ceil(this[1]);
1280
1300
  out[2] = Math.ceil(this[2]);
@@ -1284,10 +1304,10 @@ class Vec4 extends Float32Array {
1284
1304
  /**
1285
1305
  * Returns the inverse of the components of a vec4
1286
1306
  *
1287
- * @param {Vec4} out the receiving vector, defaults to this
1307
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1288
1308
  * @returns {Vec4} out
1289
1309
  */
1290
- inverse(out = index.ALWAYS_COPY ? new Vec4() : this) {
1310
+ inverse(out = index.ALWAYS_COPY ? vec4() : this) {
1291
1311
  out[0] = 1.0 / this[0];
1292
1312
  out[1] = 1.0 / this[1];
1293
1313
  out[2] = 1.0 / this[2];
@@ -1295,12 +1315,12 @@ class Vec4 extends Float32Array {
1295
1315
  return out;
1296
1316
  }
1297
1317
  /**
1298
- * Creates a new vec4 initialized with values from a vector
1318
+ * Creates a vec4 initialized with values from a vector
1299
1319
  *
1300
- * @returns {Vec4} a new vec4
1320
+ * @returns {Vec4} a vec4
1301
1321
  */
1302
1322
  clone() {
1303
- return new Vec4(this[0], this[1], this[2], this[3]);
1323
+ return vec4(this[0], this[1], this[2], this[3]);
1304
1324
  }
1305
1325
  /**
1306
1326
  * Returns a string representation of a vec4
@@ -1314,10 +1334,10 @@ class Vec4 extends Float32Array {
1314
1334
  * Generates a random vector with the given scale
1315
1335
  *
1316
1336
  * @param {Number} scale length of the resulting vector, defaults to 1.0
1317
- * @param {Vec4} out the receiving vector, defaults to new Vec4()
1337
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1318
1338
  * @returns {Vec4} out
1319
1339
  */
1320
- static random(scale = 1.0, out = new Vec4()) {
1340
+ static random(scale = 1.0, out = vec4()) {
1321
1341
  // Marsaglia, George. Choosing a Point from the Surface of a
1322
1342
  // Sphere. Ann. Math. Statist. 43 (1972), no. 2, 645--646.
1323
1343
  // http://projecteuclid.org/euclid.aoms/1177692644;
@@ -1355,10 +1375,10 @@ class Vec4 extends Float32Array {
1355
1375
  * @param {Vec4} u the first operand
1356
1376
  * @param {Vec4} v the second operand
1357
1377
  * @param {Vec4} w the third operand
1358
- * @param {Vec4} out the receiving vector, defaults to new Vec4()
1378
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1359
1379
  * @returns {Vec4} out
1360
1380
  */
1361
- static cross(u, v, w, out = new Vec4()) {
1381
+ static cross(u, v, w, out = vec4()) {
1362
1382
  const A = v[0] * w[1] - v[1] * w[0], B = v[0] * w[2] - v[2] * w[0], C = v[0] * w[3] - v[3] * w[0], D = v[1] * w[2] - v[2] * w[1], E = v[1] * w[3] - v[3] * w[1], F = v[2] * w[3] - v[3] * w[2];
1363
1383
  const G = u[0], H = u[1], I = u[2], J = u[3];
1364
1384
  out[0] = H * F - I * E + J * D;
@@ -1401,10 +1421,10 @@ class Vec4 extends Float32Array {
1401
1421
  * @param {Vec4} a the first operand
1402
1422
  * @param {Vec4} b the second operand
1403
1423
  * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
1404
- * @param {Vec4} out the receiving vector, defaults to new Vec4()
1424
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1405
1425
  * @returns {Vec4} out
1406
1426
  */
1407
- static lerp(a, b, t, out = new Vec4()) {
1427
+ static lerp(a, b, t, out = vec4()) {
1408
1428
  const ax = a[0], ay = a[1], az = a[2], aw = a[3];
1409
1429
  out[0] = ax + (b[0] - ax) * t;
1410
1430
  out[1] = ay + (b[1] - ay) * t;
@@ -1417,10 +1437,10 @@ class Vec4 extends Float32Array {
1417
1437
  *
1418
1438
  * @param {Vec4} a the first operand
1419
1439
  * @param {Vec4} b the second operand
1420
- * @param {Vec4} out the receiving vector, defaults to new Vec4()
1440
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1421
1441
  * @returns {Vec4} out
1422
1442
  */
1423
- static max(a, b, out = new Vec4()) {
1443
+ static max(a, b, out = vec4()) {
1424
1444
  out[0] = Math.max(a[0], b[0]);
1425
1445
  out[1] = Math.max(a[1], b[1]);
1426
1446
  out[2] = Math.max(a[2], b[2]);
@@ -1432,10 +1452,10 @@ class Vec4 extends Float32Array {
1432
1452
  *
1433
1453
  * @param {Vec4} a the first operand
1434
1454
  * @param {Vec4} b the second operand
1435
- * @param {Vec4} out the receiving vector, defaults to new Vec4()
1455
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1436
1456
  * @returns {Vec4} out
1437
1457
  */
1438
- static min(a, b, out = new Vec4()) {
1458
+ static min(a, b, out = vec4()) {
1439
1459
  out[0] = Math.min(a[0], b[0]);
1440
1460
  out[1] = Math.min(a[1], b[1]);
1441
1461
  out[2] = Math.min(a[2], b[2]);
@@ -1451,7 +1471,7 @@ class Vec4 extends Float32Array {
1451
1471
  * @param {Vec4} out the receiving vector
1452
1472
  * @returns {Vec4} out
1453
1473
  */
1454
- static clamp(v, min, max, out = new Vec4()) {
1474
+ static clamp(v, min, max, out = vec4()) {
1455
1475
  const minX = typeof min === 'number' ? min : min[0];
1456
1476
  const minY = typeof min === 'number' ? min : min[1];
1457
1477
  const minZ = typeof min === 'number' ? min : min[2];
@@ -1475,7 +1495,7 @@ class Vec4 extends Float32Array {
1475
1495
  * @param {Vec4} out the receiving vector
1476
1496
  * @returns {Vec4} out
1477
1497
  */
1478
- static mix(a, b, t, out = new Vec4()) {
1498
+ static mix(a, b, t, out = vec4()) {
1479
1499
  if (typeof t === 'number') {
1480
1500
  out[0] = a[0] + (b[0] - a[0]) * t;
1481
1501
  out[1] = a[1] + (b[1] - a[1]) * t;
@@ -1499,7 +1519,7 @@ class Vec4 extends Float32Array {
1499
1519
  * @param {Vec4} out the receiving vector
1500
1520
  * @returns {Vec4} out
1501
1521
  */
1502
- static smoothstep(edge0, edge1, v, out = new Vec4()) {
1522
+ static smoothstep(edge0, edge1, v, out = vec4()) {
1503
1523
  const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
1504
1524
  const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
1505
1525
  const e0z = typeof edge0 === 'number' ? edge0 : edge0[2];
@@ -1526,7 +1546,7 @@ class Vec4 extends Float32Array {
1526
1546
  * @param {Vec4} out the receiving vector
1527
1547
  * @returns {Vec4} out
1528
1548
  */
1529
- scaleAndAdd(b, scale, out = index.ALWAYS_COPY ? new Vec4() : this) {
1549
+ scaleAndAdd(b, scale, out = index.ALWAYS_COPY ? vec4() : this) {
1530
1550
  out[0] = this[0] + b[0] * scale;
1531
1551
  out[1] = this[1] + b[1] * scale;
1532
1552
  out[2] = this[2] + b[2] * scale;
@@ -1539,7 +1559,7 @@ class Vec4 extends Float32Array {
1539
1559
  * @param {Vec4} out the receiving vector
1540
1560
  * @returns {Vec4} out
1541
1561
  */
1542
- abs(out = index.ALWAYS_COPY ? new Vec4() : this) {
1562
+ abs(out = index.ALWAYS_COPY ? vec4() : this) {
1543
1563
  out[0] = Math.abs(this[0]);
1544
1564
  out[1] = Math.abs(this[1]);
1545
1565
  out[2] = Math.abs(this[2]);
@@ -1554,7 +1574,7 @@ class Vec4 extends Float32Array {
1554
1574
  * @param {Vec4} out the receiving vector
1555
1575
  * @returns {Vec4} out
1556
1576
  */
1557
- clamp(min, max, out = index.ALWAYS_COPY ? new Vec4() : this) {
1577
+ clamp(min, max, out = index.ALWAYS_COPY ? vec4() : this) {
1558
1578
  const minX = typeof min === 'number' ? min : min[0];
1559
1579
  const minY = typeof min === 'number' ? min : min[1];
1560
1580
  const minZ = typeof min === 'number' ? min : min[2];
@@ -1577,7 +1597,7 @@ class Vec4 extends Float32Array {
1577
1597
  * @param {Vec4} out the receiving vector
1578
1598
  * @returns {Vec4} out
1579
1599
  */
1580
- mix(b, t, out = index.ALWAYS_COPY ? new Vec4() : this) {
1600
+ mix(b, t, out = index.ALWAYS_COPY ? vec4() : this) {
1581
1601
  if (typeof t === 'number') {
1582
1602
  out[0] = this[0] + (b[0] - this[0]) * t;
1583
1603
  out[1] = this[1] + (b[1] - this[1]) * t;
@@ -1599,7 +1619,7 @@ class Vec4 extends Float32Array {
1599
1619
  * @param {Vec4} out the receiving vector
1600
1620
  * @returns {Vec4} out
1601
1621
  */
1602
- step(edge, out = index.ALWAYS_COPY ? new Vec4() : this) {
1622
+ step(edge, out = index.ALWAYS_COPY ? vec4() : this) {
1603
1623
  if (typeof edge === 'number') {
1604
1624
  out[0] = this[0] < edge ? 0 : 1;
1605
1625
  out[1] = this[1] < edge ? 0 : 1;
@@ -1622,7 +1642,7 @@ class Vec4 extends Float32Array {
1622
1642
  * @param {Vec4} out the receiving vector
1623
1643
  * @returns {Vec4} out
1624
1644
  */
1625
- smoothstep(edge0, edge1, out = index.ALWAYS_COPY ? new Vec4() : this) {
1645
+ smoothstep(edge0, edge1, out = index.ALWAYS_COPY ? vec4() : this) {
1626
1646
  const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
1627
1647
  const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
1628
1648
  const e0z = typeof edge0 === 'number' ? edge0 : edge0[2];
@@ -1647,7 +1667,7 @@ class Vec4 extends Float32Array {
1647
1667
  * @param {Vec4} out the receiving vector
1648
1668
  * @returns {Vec4} out
1649
1669
  */
1650
- fract(out = index.ALWAYS_COPY ? new Vec4() : this) {
1670
+ fract(out = index.ALWAYS_COPY ? vec4() : this) {
1651
1671
  out[0] = this[0] - Math.floor(this[0]);
1652
1672
  out[1] = this[1] - Math.floor(this[1]);
1653
1673
  out[2] = this[2] - Math.floor(this[2]);
@@ -1660,7 +1680,7 @@ class Vec4 extends Float32Array {
1660
1680
  * @param {Vec4} out the receiving vector
1661
1681
  * @returns {Vec4} out
1662
1682
  */
1663
- sign(out = index.ALWAYS_COPY ? new Vec4() : this) {
1683
+ sign(out = index.ALWAYS_COPY ? vec4() : this) {
1664
1684
  out[0] = this[0] > 0 ? 1 : this[0] < 0 ? -1 : 0;
1665
1685
  out[1] = this[1] > 0 ? 1 : this[1] < 0 ? -1 : 0;
1666
1686
  out[2] = this[2] > 0 ? 1 : this[2] < 0 ? -1 : 0;
@@ -1673,7 +1693,7 @@ class Vec4 extends Float32Array {
1673
1693
  * @param {Vec4} out the receiving vector
1674
1694
  * @returns {Vec4} out
1675
1695
  */
1676
- saturate(out = index.ALWAYS_COPY ? new Vec4() : this) {
1696
+ saturate(out = index.ALWAYS_COPY ? vec4() : this) {
1677
1697
  out[0] = Math.min(Math.max(this[0], 0), 1);
1678
1698
  out[1] = Math.min(Math.max(this[1], 0), 1);
1679
1699
  out[2] = Math.min(Math.max(this[2], 0), 1);
@@ -1687,7 +1707,7 @@ class Vec4 extends Float32Array {
1687
1707
  * @param {Vec4} out the receiving vector
1688
1708
  * @returns {Vec4} out
1689
1709
  */
1690
- transformMat4(m, out = index.ALWAYS_COPY ? new Vec4() : this) {
1710
+ transformMat4(m, out = index.ALWAYS_COPY ? vec4() : this) {
1691
1711
  const x = this[0], y = this[1], z = this[2], w = this[3];
1692
1712
  out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
1693
1713
  out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
@@ -1702,7 +1722,7 @@ class Vec4 extends Float32Array {
1702
1722
  * @param {Vec4} out the receiving vector
1703
1723
  * @returns {Vec4} out
1704
1724
  */
1705
- transformQuat(q, out = index.ALWAYS_COPY ? new Vec4() : this) {
1725
+ transformQuat(q, out = index.ALWAYS_COPY ? vec4() : this) {
1706
1726
  const qx = q[0], qy = q[1], qz = q[2], qw = q[3];
1707
1727
  const x = this[0], y = this[1], z = this[2];
1708
1728
  let uvx = qy * z - qz * y, uvy = qz * x - qx * z, uvz = qx * y - qy * x;
@@ -1729,7 +1749,7 @@ class Vec4 extends Float32Array {
1729
1749
  * @param {Vec4} out the receiving vector
1730
1750
  * @returns {Vec4} out
1731
1751
  */
1732
- static scaleAndAdd(a, b, scale, out = new Vec4()) {
1752
+ static scaleAndAdd(a, b, scale, out = vec4()) {
1733
1753
  out[0] = a[0] + b[0] * scale;
1734
1754
  out[1] = a[1] + b[1] * scale;
1735
1755
  out[2] = a[2] + b[2] * scale;
@@ -1753,6 +1773,7 @@ Vec4.prototype.neg = Vec4.prototype.negate;
1753
1773
  Vec4.prototype.unaryMinus = Vec4.prototype.negate;
1754
1774
  Vec4.prototype.sqrLen = Vec4.prototype.squaredLength;
1755
1775
  Vec4.prototype.str = Vec4.prototype.toString;
1776
+ Vec4.prototype.normalized = Vec4.prototype.normalize;
1756
1777
  Vec4.prototype.transformMat4x4 = Vec4.prototype.transformMat4;
1757
1778
  const createVec4 = (...args) => {
1758
1779
  const out = new Vec4();
@@ -1838,12 +1859,12 @@ function defineSwizzles(prototype, N = 4, S = ['xyzw', 'rgba', 'stpq', 'uv']) {
1838
1859
  * @extends Float32Array
1839
1860
  */
1840
1861
  class Vec2 extends Float32Array {
1841
- static get zero() { return new Vec2(0, 0); }
1842
- static get Zero() { return new Vec2(0, 0); }
1843
- static get ZERO() { return new Vec2(0, 0); }
1844
- static get one() { return new Vec2(1, 1); }
1845
- static get One() { return new Vec2(1, 1); }
1846
- static get ONE() { return new Vec2(1, 1); }
1862
+ static get zero() { return vec2(0, 0); }
1863
+ static get Zero() { return vec2(0, 0); }
1864
+ static get ZERO() { return vec2(0, 0); }
1865
+ static get one() { return vec2(1, 1); }
1866
+ static get One() { return vec2(1, 1); }
1867
+ static get ONE() { return vec2(1, 1); }
1847
1868
  /**
1848
1869
  * Creates a new Vec2 initialized with the given values
1849
1870
  *
@@ -1863,10 +1884,10 @@ class Vec2 extends Float32Array {
1863
1884
  * Adds two vec2's
1864
1885
  *
1865
1886
  * @param {Vec2 | Number} b the second operand
1866
- * @param {Vec2} out the receiving vector, defaults to this
1887
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
1867
1888
  * @returns {Vec2} out
1868
1889
  */
1869
- plus(b, out = index.ALWAYS_COPY ? new Vec2() : this) {
1890
+ plus(b, out = index.ALWAYS_COPY ? vec2() : this) {
1870
1891
  if (typeof b === 'number') {
1871
1892
  out[0] = this[0] + b;
1872
1893
  out[1] = this[1] + b;
@@ -1881,10 +1902,10 @@ class Vec2 extends Float32Array {
1881
1902
  * Subtracts vector b from a vector
1882
1903
  *
1883
1904
  * @param {Vec2 | Number} b the second operand
1884
- * @param {Vec2} out the receiving vector, defaults to this
1905
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
1885
1906
  * @returns {Vec2} out
1886
1907
  */
1887
- minus(b, out = index.ALWAYS_COPY ? new Vec2() : this) {
1908
+ minus(b, out = index.ALWAYS_COPY ? vec2() : this) {
1888
1909
  if (typeof b === 'number') {
1889
1910
  out[0] = this[0] - b;
1890
1911
  out[1] = this[1] - b;
@@ -1899,10 +1920,10 @@ class Vec2 extends Float32Array {
1899
1920
  * Multiplies two vec2's component-wise
1900
1921
  *
1901
1922
  * @param {Vec2 | Number} b the second operand
1902
- * @param {Vec2} out the receiving vector, defaults to this
1923
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
1903
1924
  * @returns {Vec2} out
1904
1925
  */
1905
- mult(b, out = index.ALWAYS_COPY ? new Vec2() : this) {
1926
+ mult(b, out = index.ALWAYS_COPY ? vec2() : this) {
1906
1927
  if (typeof b === 'number') {
1907
1928
  out[0] = this[0] * b;
1908
1929
  out[1] = this[1] * b;
@@ -1917,10 +1938,10 @@ class Vec2 extends Float32Array {
1917
1938
  * Divides two vec2's component-wise
1918
1939
  *
1919
1940
  * @param {Vec2 | Number} b the second operand
1920
- * @param {Vec2} out the receiving vector, defaults to this
1941
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
1921
1942
  * @returns {Vec2} out
1922
1943
  */
1923
- div(b, out = index.ALWAYS_COPY ? new Vec2() : this) {
1944
+ div(b, out = index.ALWAYS_COPY ? vec2() : this) {
1924
1945
  if (typeof b === 'number') {
1925
1946
  out[0] = this[0] / b;
1926
1947
  out[1] = this[1] / b;
@@ -1935,10 +1956,10 @@ class Vec2 extends Float32Array {
1935
1956
  * Divides this vector by argument
1936
1957
  *
1937
1958
  * @param {Vec2 | Number} a the first operand
1938
- * @param {Vec2} out the receiving vector, defaults to this
1959
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
1939
1960
  * @returns {Vec2} out
1940
1961
  */
1941
- invDiv(a, out = index.ALWAYS_COPY ? new Vec2() : this) {
1962
+ invDiv(a, out = index.ALWAYS_COPY ? vec2() : this) {
1942
1963
  if (typeof a === 'number') {
1943
1964
  out[0] = a / this[0];
1944
1965
  out[1] = a / this[1];
@@ -1953,10 +1974,10 @@ class Vec2 extends Float32Array {
1953
1974
  * Remainder of this divided by argument
1954
1975
  *
1955
1976
  * @param {Vec2 | Number} a the first operand
1956
- * @param {Vec2} out the receiving vector, defaults to this
1977
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
1957
1978
  * @returns {Vec2} out
1958
1979
  */
1959
- rem(b, out = index.ALWAYS_COPY ? new Vec2() : this) {
1980
+ rem(b, out = index.ALWAYS_COPY ? vec2() : this) {
1960
1981
  if (typeof b === 'number') {
1961
1982
  out[0] = this[0] % b;
1962
1983
  out[1] = this[1] % b;
@@ -1970,15 +1991,15 @@ class Vec2 extends Float32Array {
1970
1991
  /**
1971
1992
  * Negates the components of a vec2
1972
1993
  *
1973
- * @param {Vec2} out the receiving vector, defaults to this
1994
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
1974
1995
  * @returns {Vec2} out
1975
1996
  */
1976
- negate(out = index.ALWAYS_COPY ? new Vec2() : this) {
1997
+ negate(out = index.ALWAYS_COPY ? vec2() : this) {
1977
1998
  out[0] = -this[0];
1978
1999
  out[1] = -this[1];
1979
2000
  return out;
1980
2001
  }
1981
- unaryPlus(out = index.ALWAYS_COPY ? new Vec2() : this) {
2002
+ unaryPlus(out = index.ALWAYS_COPY ? vec2() : this) {
1982
2003
  if (!out.equals(this)) {
1983
2004
  out[0] = this[0];
1984
2005
  out[1] = this[1];
@@ -1986,11 +2007,28 @@ class Vec2 extends Float32Array {
1986
2007
  return out;
1987
2008
  }
1988
2009
  /**
1989
- * Normalize a vector to unit length. Modifies in-place.
2010
+ * Normalize a vector to unit length.
1990
2011
  *
2012
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
1991
2013
  * @returns {Vec2} this
1992
2014
  */
1993
- normalize(out = index.ALWAYS_COPY ? new Vec2() : this) {
2015
+ static normalize(v, out = vec2()) {
2016
+ const x = v[0], y = v[1];
2017
+ let len = x * x + y * y;
2018
+ if (len > 0) {
2019
+ len = 1.0 / Math.sqrt(len);
2020
+ }
2021
+ out[0] = x * len;
2022
+ out[1] = y * len;
2023
+ return out;
2024
+ }
2025
+ /**
2026
+ * Normalize a vector to unit length.
2027
+ *
2028
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2029
+ * @returns {Vec2} this
2030
+ */
2031
+ normalize(out = index.ALWAYS_COPY ? vec2() : this) {
1994
2032
  const x = this[0], y = this[1];
1995
2033
  let len = x * x + y * y;
1996
2034
  if (len > 0) {
@@ -2040,10 +2078,10 @@ class Vec2 extends Float32Array {
2040
2078
  /**
2041
2079
  * Math.floor the components of a vec2
2042
2080
  *
2043
- * @param {Vec2} out the receiving vector, defaults to this
2081
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2044
2082
  * @returns {Vec2} out
2045
2083
  */
2046
- floor(out = index.ALWAYS_COPY ? new Vec2() : this) {
2084
+ floor(out = index.ALWAYS_COPY ? vec2() : this) {
2047
2085
  out[0] = Math.floor(this[0]);
2048
2086
  out[1] = Math.floor(this[1]);
2049
2087
  return out;
@@ -2051,10 +2089,10 @@ class Vec2 extends Float32Array {
2051
2089
  /**
2052
2090
  * Math.round the components of a vec2
2053
2091
  *
2054
- * @param {Vec2} out the receiving vector, defaults to this
2092
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2055
2093
  * @returns {Vec2} out
2056
2094
  */
2057
- round(out = index.ALWAYS_COPY ? new Vec2() : this) {
2095
+ round(out = index.ALWAYS_COPY ? vec2() : this) {
2058
2096
  out[0] = Math.round(this[0]);
2059
2097
  out[1] = Math.round(this[1]);
2060
2098
  return out;
@@ -2062,10 +2100,10 @@ class Vec2 extends Float32Array {
2062
2100
  /**
2063
2101
  * Math.ceil the components of a vec2
2064
2102
  *
2065
- * @param {Vec2} out the receiving vector, defaults to this
2103
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2066
2104
  * @returns {Vec2} out
2067
2105
  */
2068
- ceil(out = index.ALWAYS_COPY ? new Vec2() : this) {
2106
+ ceil(out = index.ALWAYS_COPY ? vec2() : this) {
2069
2107
  out[0] = Math.ceil(this[0]);
2070
2108
  out[1] = Math.ceil(this[1]);
2071
2109
  return out;
@@ -2073,10 +2111,10 @@ class Vec2 extends Float32Array {
2073
2111
  /**
2074
2112
  * Returns the inverse of the components (1/x, 1/y)
2075
2113
  *
2076
- * @param {Vec2} out the receiving vector, defaults to this
2114
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2077
2115
  * @returns {Vec2} out
2078
2116
  */
2079
- inverse(out = index.ALWAYS_COPY ? new Vec2() : this) {
2117
+ inverse(out = index.ALWAYS_COPY ? vec2() : this) {
2080
2118
  out[0] = 1.0 / this[0];
2081
2119
  out[1] = 1.0 / this[1];
2082
2120
  return out;
@@ -2086,16 +2124,16 @@ class Vec2 extends Float32Array {
2086
2124
  *
2087
2125
  * @returns {Vec2} a new Vec2
2088
2126
  */
2089
- clone() { return new Vec2(this[0], this[1]); }
2127
+ clone() { return vec2(this[0], this[1]); }
2090
2128
  /**
2091
2129
  * Rotates a vec2 around an origin point
2092
2130
  *
2093
2131
  * @param {Number} rad the angle of rotation in radians
2094
- * @param {Vec2} origin the origin of the rotation, defaults to ZERO
2095
- * @param {Vec2} out the receiving vector, defaults to this
2132
+ * @param {Vec2} origin the origin of the rotation, defaults to vec2(0, 0)
2133
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2096
2134
  * @returns {Vec2} out
2097
2135
  */
2098
- rotate(rad = 0, origin = Vec2.ZERO, out = index.ALWAYS_COPY ? new Vec2() : this) {
2136
+ rotate(rad = 0, origin = vec2.zero, out = index.ALWAYS_COPY ? vec2() : this) {
2099
2137
  const p0 = this[0] - origin[0];
2100
2138
  const p1 = this[1] - origin[1];
2101
2139
  const sinC = Math.sin(rad);
@@ -2118,7 +2156,7 @@ class Vec2 extends Float32Array {
2118
2156
  * @param {Number} scale length of the resulting vector, defaults to 1.0
2119
2157
  * @returns {Vec2} a new random Vec2
2120
2158
  */
2121
- static random(scale = 1.0, out = new Vec2()) {
2159
+ static random(scale = 1.0, out = vec2()) {
2122
2160
  const angleR = index.RANDOM() * 2.0 * Math.PI;
2123
2161
  out[0] = Math.cos(angleR) * scale;
2124
2162
  out[1] = Math.sin(angleR) * scale;
@@ -2212,7 +2250,7 @@ class Vec2 extends Float32Array {
2212
2250
  * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
2213
2251
  * @returns {Vec2} a new interpolated Vec2
2214
2252
  */
2215
- static lerp(a, b, t, out = new Vec2()) {
2253
+ static lerp(a, b, t, out = vec2()) {
2216
2254
  const a0 = a[0], a1 = a[1];
2217
2255
  out[0] = a0 + (b[0] - a0) * t;
2218
2256
  out[1] = a1 + (b[1] - a1) * t;
@@ -2225,7 +2263,7 @@ class Vec2 extends Float32Array {
2225
2263
  * @param {Vec2} b the second operand
2226
2264
  * @returns {Vec2} a new Vec2 with max components
2227
2265
  */
2228
- static max(a, b, out = new Vec2()) {
2266
+ static max(a, b, out = vec2()) {
2229
2267
  out[0] = Math.max(a[0], b[0]);
2230
2268
  out[1] = Math.max(a[1], b[1]);
2231
2269
  return out;
@@ -2237,7 +2275,7 @@ class Vec2 extends Float32Array {
2237
2275
  * @param {Vec2} b the second operand
2238
2276
  * @returns {Vec2} a new Vec2 with min components
2239
2277
  */
2240
- static min(a, b, out = new Vec2()) {
2278
+ static min(a, b, out = vec2()) {
2241
2279
  out[0] = Math.min(a[0], b[0]);
2242
2280
  out[1] = Math.min(a[1], b[1]);
2243
2281
  return out;
@@ -2250,7 +2288,7 @@ class Vec2 extends Float32Array {
2250
2288
  * @param {Vec2 | Number} max the upper bound
2251
2289
  * @returns {Vec2} a new clamped Vec2
2252
2290
  */
2253
- static clamp(v, min, max, out = new Vec2()) {
2291
+ static clamp(v, min, max, out = vec2()) {
2254
2292
  if (typeof min === 'number' && typeof max === 'number') {
2255
2293
  out[0] = Math.min(Math.max(v[0], min), max);
2256
2294
  out[1] = Math.min(Math.max(v[1], min), max);
@@ -2273,7 +2311,7 @@ class Vec2 extends Float32Array {
2273
2311
  * @param {Vec2 | Number} t interpolation factor (scalar or per-component)
2274
2312
  * @returns {Vec2} a new interpolated Vec2
2275
2313
  */
2276
- static mix(a, b, t, out = new Vec2()) {
2314
+ static mix(a, b, t, out = vec2()) {
2277
2315
  if (typeof t === 'number') {
2278
2316
  out[0] = a[0] + (b[0] - a[0]) * t;
2279
2317
  out[1] = a[1] + (b[1] - a[1]) * t;
@@ -2292,7 +2330,7 @@ class Vec2 extends Float32Array {
2292
2330
  * @param {Vec2} v the source vector
2293
2331
  * @returns {Vec2} a new smoothstepped Vec2
2294
2332
  */
2295
- static smoothstep(edge0, edge1, v, out = new Vec2()) {
2333
+ static smoothstep(edge0, edge1, v, out = vec2()) {
2296
2334
  const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
2297
2335
  const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
2298
2336
  const e1x = typeof edge1 === 'number' ? edge1 : edge1[0];
@@ -2308,10 +2346,10 @@ class Vec2 extends Float32Array {
2308
2346
  *
2309
2347
  * @param {Vec2} b the second operand
2310
2348
  * @param {Number} scale the amount to scale b by before adding
2311
- * @param {Vec2} out the receiving vector, defaults to this
2349
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2312
2350
  * @returns {Vec2} out
2313
2351
  */
2314
- scaleAndAdd(b, scale, out = index.ALWAYS_COPY ? new Vec2() : this) {
2352
+ scaleAndAdd(b, scale, out = index.ALWAYS_COPY ? vec2() : this) {
2315
2353
  out[0] = this[0] + b[0] * scale;
2316
2354
  out[1] = this[1] + b[1] * scale;
2317
2355
  return out;
@@ -2319,10 +2357,10 @@ class Vec2 extends Float32Array {
2319
2357
  /**
2320
2358
  * Component-wise absolute value
2321
2359
  *
2322
- * @param {Vec2} out the receiving vector, defaults to this
2360
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2323
2361
  * @returns {Vec2} out
2324
2362
  */
2325
- abs(out = index.ALWAYS_COPY ? new Vec2() : this) {
2363
+ abs(out = index.ALWAYS_COPY ? vec2() : this) {
2326
2364
  out[0] = Math.abs(this[0]);
2327
2365
  out[1] = Math.abs(this[1]);
2328
2366
  return out;
@@ -2330,10 +2368,10 @@ class Vec2 extends Float32Array {
2330
2368
  /**
2331
2369
  * Component-wise sign
2332
2370
  *
2333
- * @param {Vec2} out the receiving vector, defaults to this
2371
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2334
2372
  * @returns {Vec2} out
2335
2373
  */
2336
- sign(out = index.ALWAYS_COPY ? new Vec2() : this) {
2374
+ sign(out = index.ALWAYS_COPY ? vec2() : this) {
2337
2375
  out[0] = this[0] > 0 ? 1 : this[0] < 0 ? -1 : 0;
2338
2376
  out[1] = this[1] > 0 ? 1 : this[1] < 0 ? -1 : 0;
2339
2377
  return out;
@@ -2341,10 +2379,10 @@ class Vec2 extends Float32Array {
2341
2379
  /**
2342
2380
  * Component-wise fractional part (x - floor(x))
2343
2381
  *
2344
- * @param {Vec2} out the receiving vector, defaults to this
2382
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2345
2383
  * @returns {Vec2} out
2346
2384
  */
2347
- fract(out = index.ALWAYS_COPY ? new Vec2() : this) {
2385
+ fract(out = index.ALWAYS_COPY ? vec2() : this) {
2348
2386
  out[0] = this[0] - Math.floor(this[0]);
2349
2387
  out[1] = this[1] - Math.floor(this[1]);
2350
2388
  return out;
@@ -2354,10 +2392,10 @@ class Vec2 extends Float32Array {
2354
2392
  *
2355
2393
  * @param {Vec2 | Number} min the lower bound
2356
2394
  * @param {Vec2 | Number} max the upper bound
2357
- * @param {Vec2} out the receiving vector, defaults to this
2395
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2358
2396
  * @returns {Vec2} out
2359
2397
  */
2360
- clamp(min, max, out = index.ALWAYS_COPY ? new Vec2() : this) {
2398
+ clamp(min, max, out = index.ALWAYS_COPY ? vec2() : this) {
2361
2399
  if (typeof min === 'number' && typeof max === 'number') {
2362
2400
  out[0] = Math.min(Math.max(this[0], min), max);
2363
2401
  out[1] = Math.min(Math.max(this[1], min), max);
@@ -2375,10 +2413,10 @@ class Vec2 extends Float32Array {
2375
2413
  /**
2376
2414
  * Clamp components to [0, 1]
2377
2415
  *
2378
- * @param {Vec2} out the receiving vector, defaults to this
2416
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2379
2417
  * @returns {Vec2} out
2380
2418
  */
2381
- saturate(out = index.ALWAYS_COPY ? new Vec2() : this) {
2419
+ saturate(out = index.ALWAYS_COPY ? vec2() : this) {
2382
2420
  out[0] = Math.min(Math.max(this[0], 0), 1);
2383
2421
  out[1] = Math.min(Math.max(this[1], 0), 1);
2384
2422
  return out;
@@ -2388,10 +2426,10 @@ class Vec2 extends Float32Array {
2388
2426
  *
2389
2427
  * @param {Vec2} b the second operand
2390
2428
  * @param {Vec2 | Number} t interpolation factor (scalar or per-component)
2391
- * @param {Vec2} out the receiving vector, defaults to this
2429
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2392
2430
  * @returns {Vec2} out
2393
2431
  */
2394
- mix(b, t, out = index.ALWAYS_COPY ? new Vec2() : this) {
2432
+ mix(b, t, out = index.ALWAYS_COPY ? vec2() : this) {
2395
2433
  if (typeof t === 'number') {
2396
2434
  out[0] = this[0] + (b[0] - this[0]) * t;
2397
2435
  out[1] = this[1] + (b[1] - this[1]) * t;
@@ -2406,10 +2444,10 @@ class Vec2 extends Float32Array {
2406
2444
  * Component-wise step function
2407
2445
  *
2408
2446
  * @param {Vec2 | Number} edge the edge threshold
2409
- * @param {Vec2} out the receiving vector, defaults to this
2447
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2410
2448
  * @returns {Vec2} out
2411
2449
  */
2412
- step(edge, out = index.ALWAYS_COPY ? new Vec2() : this) {
2450
+ step(edge, out = index.ALWAYS_COPY ? vec2() : this) {
2413
2451
  if (typeof edge === 'number') {
2414
2452
  out[0] = this[0] < edge ? 0 : 1;
2415
2453
  out[1] = this[1] < edge ? 0 : 1;
@@ -2425,10 +2463,10 @@ class Vec2 extends Float32Array {
2425
2463
  *
2426
2464
  * @param {Vec2 | Number} edge0 the lower edge
2427
2465
  * @param {Vec2 | Number} edge1 the upper edge
2428
- * @param {Vec2} out the receiving vector, defaults to this
2466
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2429
2467
  * @returns {Vec2} out
2430
2468
  */
2431
- smoothstep(edge0, edge1, out = index.ALWAYS_COPY ? new Vec2() : this) {
2469
+ smoothstep(edge0, edge1, out = index.ALWAYS_COPY ? vec2() : this) {
2432
2470
  const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
2433
2471
  const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
2434
2472
  const e1x = typeof edge1 === 'number' ? edge1 : edge1[0];
@@ -2443,10 +2481,10 @@ class Vec2 extends Float32Array {
2443
2481
  * Transforms the vec2 with a Mat2 (column-major 2x2)
2444
2482
  *
2445
2483
  * @param {Mat2} m matrix to transform with
2446
- * @param {Vec2} out the receiving vector, defaults to this
2484
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2447
2485
  * @returns {Vec2} out
2448
2486
  */
2449
- transformMat2(m, out = index.ALWAYS_COPY ? new Vec2() : this) {
2487
+ transformMat2(m, out = index.ALWAYS_COPY ? vec2() : this) {
2450
2488
  const x = this[0], y = this[1];
2451
2489
  out[0] = m[0] * x + m[2] * y;
2452
2490
  out[1] = m[1] * x + m[3] * y;
@@ -2456,10 +2494,10 @@ class Vec2 extends Float32Array {
2456
2494
  * Transforms the vec2 with a Mat2x3 (2D affine transform)
2457
2495
  *
2458
2496
  * @param {Mat2x3} m matrix to transform with
2459
- * @param {Vec2} out the receiving vector, defaults to this
2497
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2460
2498
  * @returns {Vec2} out
2461
2499
  */
2462
- transformMat2x3(m, out = index.ALWAYS_COPY ? new Vec2() : this) {
2500
+ transformMat2x3(m, out = index.ALWAYS_COPY ? vec2() : this) {
2463
2501
  const x = this[0], y = this[1];
2464
2502
  out[0] = m[0] * x + m[2] * y + m[4];
2465
2503
  out[1] = m[1] * x + m[3] * y + m[5];
@@ -2469,10 +2507,10 @@ class Vec2 extends Float32Array {
2469
2507
  * Transforms the vec2 with a Mat3 (column-major 3x3)
2470
2508
  *
2471
2509
  * @param {Mat3} m matrix to transform with
2472
- * @param {Vec2} out the receiving vector, defaults to this
2510
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2473
2511
  * @returns {Vec2} out
2474
2512
  */
2475
- transformMat3(m, out = index.ALWAYS_COPY ? new Vec2() : this) {
2513
+ transformMat3(m, out = index.ALWAYS_COPY ? vec2() : this) {
2476
2514
  const x = this[0], y = this[1];
2477
2515
  out[0] = m[0] * x + m[3] * y + m[6];
2478
2516
  out[1] = m[1] * x + m[4] * y + m[7];
@@ -2482,10 +2520,10 @@ class Vec2 extends Float32Array {
2482
2520
  * Transforms the vec2 with a Mat4 (column-major 4x4)
2483
2521
  *
2484
2522
  * @param {Mat4} m matrix to transform with
2485
- * @param {Vec2} out the receiving vector, defaults to this
2523
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2486
2524
  * @returns {Vec2} out
2487
2525
  */
2488
- transformMat4(m, out = index.ALWAYS_COPY ? new Vec2() : this) {
2526
+ transformMat4(m, out = index.ALWAYS_COPY ? vec2() : this) {
2489
2527
  const x = this[0], y = this[1];
2490
2528
  out[0] = m[0] * x + m[4] * y + m[12];
2491
2529
  out[1] = m[1] * x + m[5] * y + m[13];
@@ -2500,7 +2538,7 @@ class Vec2 extends Float32Array {
2500
2538
  * @param {Vec2} out the receiving vector
2501
2539
  * @returns {Vec2} out
2502
2540
  */
2503
- static scaleAndAdd(a, b, scale, out = new Vec2()) {
2541
+ static scaleAndAdd(a, b, scale, out = vec2()) {
2504
2542
  out[0] = a[0] + b[0] * scale;
2505
2543
  out[1] = a[1] + b[1] * scale;
2506
2544
  return out;
@@ -2513,7 +2551,7 @@ class Vec2 extends Float32Array {
2513
2551
  * @param {Vec2} out the receiving vector
2514
2552
  * @returns {Vec2} out
2515
2553
  */
2516
- static reflect(I, N, out = new Vec2()) {
2554
+ static reflect(I, N, out = vec2()) {
2517
2555
  const d = Vec2.dot(N, I);
2518
2556
  out[0] = I[0] - 2 * d * N[0];
2519
2557
  out[1] = I[1] - 2 * d * N[1];
@@ -2537,6 +2575,7 @@ Vec2.prototype.unaryMinus = Vec2.prototype.negate;
2537
2575
  Vec2.prototype.sqrLen = Vec2.prototype.squaredLength;
2538
2576
  Vec2.prototype.str = Vec2.prototype.toString;
2539
2577
  Vec2.prototype.lerpV = Vec2.prototype.mix;
2578
+ Vec2.prototype.normalized = Vec2.prototype.normalize;
2540
2579
  Vec2.prototype.transformMat2x2 = Vec2.prototype.transformMat2;
2541
2580
  Vec2.prototype.transformMat2d = Vec2.prototype.transformMat2x3;
2542
2581
  Vec2.prototype.transformMat3x3 = Vec2.prototype.transformMat3;
@@ -2563,9 +2602,9 @@ const vec2 = createVec2;
2563
2602
  * @extends Float32Array
2564
2603
  */
2565
2604
  class Mat3 extends Float32Array {
2566
- static get identity() { return new Mat3(1, 0, 0, 0, 1, 0, 0, 0, 1); }
2567
- static get Identity() { return new Mat3(1, 0, 0, 0, 1, 0, 0, 0, 1); }
2568
- static get IDENTITY() { return new Mat3(1, 0, 0, 0, 1, 0, 0, 0, 1); }
2605
+ static get identity() { return mat3(1, 0, 0, 0, 1, 0, 0, 0, 1); }
2606
+ static get Identity() { return mat3(1, 0, 0, 0, 1, 0, 0, 0, 1); }
2607
+ static get IDENTITY() { return mat3(1, 0, 0, 0, 1, 0, 0, 0, 1); }
2569
2608
  /**
2570
2609
  * Create a new mat3 with the given values
2571
2610
  *
@@ -2597,15 +2636,15 @@ class Mat3 extends Float32Array {
2597
2636
  * @returns {Mat3} a new Mat3
2598
2637
  */
2599
2638
  clone() {
2600
- return new Mat3(this[0], this[1], this[2], this[3], this[4], this[5], this[6], this[7], this[8]);
2639
+ return mat3(this[0], this[1], this[2], this[3], this[4], this[5], this[6], this[7], this[8]);
2601
2640
  }
2602
2641
  /**
2603
2642
  * Transposes a mat3
2604
2643
  *
2605
- * @param {Mat3} out the receiving matrix, defaults to this
2644
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
2606
2645
  * @returns {Mat3} out
2607
2646
  */
2608
- transpose(out = index.ALWAYS_COPY ? new Mat3() : this) {
2647
+ transpose(out = index.ALWAYS_COPY ? mat3() : this) {
2609
2648
  if (out.exactEquals(this)) {
2610
2649
  const a01 = this[1], a02 = this[2], a12 = this[5];
2611
2650
  out[1] = this[3];
@@ -2631,10 +2670,10 @@ class Mat3 extends Float32Array {
2631
2670
  /**
2632
2671
  * Inverts a mat3
2633
2672
  *
2634
- * @param {Mat3} out the receiving matrix, defaults to this
2673
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
2635
2674
  * @returns {Mat3|null} out, or null if not invertible
2636
2675
  */
2637
- invert(out = index.ALWAYS_COPY ? new Mat3() : this) {
2676
+ invert(out = index.ALWAYS_COPY ? mat3() : this) {
2638
2677
  const a00 = this[0], a01 = this[1], a02 = this[2];
2639
2678
  const a10 = this[3], a11 = this[4], a12 = this[5];
2640
2679
  const a20 = this[6], a21 = this[7], a22 = this[8];
@@ -2659,10 +2698,10 @@ class Mat3 extends Float32Array {
2659
2698
  /**
2660
2699
  * Calculates the adjugate of a mat3
2661
2700
  *
2662
- * @param {Mat3} out the receiving matrix, defaults to this
2701
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
2663
2702
  * @returns {Mat3} out
2664
2703
  */
2665
- adjoint(out = index.ALWAYS_COPY ? new Mat3() : this) {
2704
+ adjoint(out = index.ALWAYS_COPY ? mat3() : this) {
2666
2705
  const a00 = this[0], a01 = this[1], a02 = this[2];
2667
2706
  const a10 = this[3], a11 = this[4], a12 = this[5];
2668
2707
  const a20 = this[6], a21 = this[7], a22 = this[8];
@@ -2688,7 +2727,7 @@ class Mat3 extends Float32Array {
2688
2727
  const a20 = this[6], a21 = this[7], a22 = this[8];
2689
2728
  return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);
2690
2729
  }
2691
- multiply(b, out = index.ALWAYS_COPY ? new Mat3() : this) {
2730
+ multiply(b, out = index.ALWAYS_COPY ? mat3() : this) {
2692
2731
  if (b instanceof Vec2)
2693
2732
  return b.transformMat3(this);
2694
2733
  if (b instanceof Vec3)
@@ -2714,10 +2753,10 @@ class Mat3 extends Float32Array {
2714
2753
  * Translates a mat3 by the given vector
2715
2754
  *
2716
2755
  * @param {Vec2} v vector to translate by
2717
- * @param {Mat3} out the receiving matrix, defaults to this
2756
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
2718
2757
  * @returns {Mat3} out
2719
2758
  */
2720
- translate(v, out = index.ALWAYS_COPY ? new Mat3() : this) {
2759
+ translate(v, out = index.ALWAYS_COPY ? mat3() : this) {
2721
2760
  const a00 = this[0], a01 = this[1], a02 = this[2];
2722
2761
  const a10 = this[3], a11 = this[4], a12 = this[5];
2723
2762
  const a20 = this[6], a21 = this[7], a22 = this[8];
@@ -2737,10 +2776,10 @@ class Mat3 extends Float32Array {
2737
2776
  * Rotates a mat3 by the given angle
2738
2777
  *
2739
2778
  * @param {Number} rad the angle to rotate the matrix by
2740
- * @param {Mat3} out the receiving matrix, defaults to this
2779
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
2741
2780
  * @returns {Mat3} out
2742
2781
  */
2743
- rotate(rad, out = index.ALWAYS_COPY ? new Mat3() : this) {
2782
+ rotate(rad, out = index.ALWAYS_COPY ? mat3() : this) {
2744
2783
  const a00 = this[0], a01 = this[1], a02 = this[2];
2745
2784
  const a10 = this[3], a11 = this[4], a12 = this[5];
2746
2785
  const a20 = this[6], a21 = this[7], a22 = this[8];
@@ -2760,10 +2799,10 @@ class Mat3 extends Float32Array {
2760
2799
  * Scales a mat3 by the given vector
2761
2800
  *
2762
2801
  * @param {Vec2} v the vector to scale by
2763
- * @param {Mat3} out the receiving matrix, defaults to this
2802
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
2764
2803
  * @returns {Mat3} out
2765
2804
  */
2766
- scale(v, out = index.ALWAYS_COPY ? new Mat3() : this) {
2805
+ scale(v, out = index.ALWAYS_COPY ? mat3() : this) {
2767
2806
  const x = v[0], y = v[1];
2768
2807
  out[0] = x * this[0];
2769
2808
  out[1] = x * this[1];
@@ -2780,10 +2819,10 @@ class Mat3 extends Float32Array {
2780
2819
  * Creates a matrix from a translation vector
2781
2820
  *
2782
2821
  * @param {Vec2} v translation vector
2783
- * @param {Mat3} out the receiving matrix, defaults to new Mat3()
2822
+ * @param {Mat3} out the receiving matrix, defaults to mat3()
2784
2823
  * @returns {Mat3} out
2785
2824
  */
2786
- static fromTranslation(v, out = new Mat3()) {
2825
+ static fromTranslation(v, out = mat3()) {
2787
2826
  out[0] = 1;
2788
2827
  out[1] = 0;
2789
2828
  out[2] = 0;
@@ -2799,10 +2838,10 @@ class Mat3 extends Float32Array {
2799
2838
  * Creates a matrix from a given angle
2800
2839
  *
2801
2840
  * @param {Number} rad the angle to rotate the matrix by
2802
- * @param {Mat3} out the receiving matrix, defaults to new Mat3()
2841
+ * @param {Mat3} out the receiving matrix, defaults to mat3()
2803
2842
  * @returns {Mat3} out
2804
2843
  */
2805
- static fromRotation(rad, out = new Mat3()) {
2844
+ static fromRotation(rad, out = mat3()) {
2806
2845
  const s = Math.sin(rad), c = Math.cos(rad);
2807
2846
  out[0] = c;
2808
2847
  out[1] = s;
@@ -2819,10 +2858,10 @@ class Mat3 extends Float32Array {
2819
2858
  * Creates a matrix from a scaling vector
2820
2859
  *
2821
2860
  * @param {Vec2} v scaling vector
2822
- * @param {Mat3} out the receiving matrix, defaults to new Mat3()
2861
+ * @param {Mat3} out the receiving matrix, defaults to mat3()
2823
2862
  * @returns {Mat3} out
2824
2863
  */
2825
- static fromScaling(v, out = new Mat3()) {
2864
+ static fromScaling(v, out = mat3()) {
2826
2865
  out[0] = v[0];
2827
2866
  out[1] = 0;
2828
2867
  out[2] = 0;
@@ -2838,10 +2877,10 @@ class Mat3 extends Float32Array {
2838
2877
  * Creates a mat3 from a Mat2x3
2839
2878
  *
2840
2879
  * @param {Mat2x3} a the Mat2x3 to convert
2841
- * @param {Mat3} out the receiving matrix, defaults to new Mat3()
2880
+ * @param {Mat3} out the receiving matrix, defaults to mat3()
2842
2881
  * @returns {Mat3} out
2843
2882
  */
2844
- static fromMat2x3(a, out = new Mat3()) {
2883
+ static fromMat2x3(a, out = mat3()) {
2845
2884
  out[0] = a[0];
2846
2885
  out[1] = a[1];
2847
2886
  out[2] = 0;
@@ -2857,10 +2896,10 @@ class Mat3 extends Float32Array {
2857
2896
  * Calculates a mat3 from the given quaternion
2858
2897
  *
2859
2898
  * @param {Quat} q quaternion to create matrix from
2860
- * @param {Mat3} out the receiving matrix, defaults to new Mat3()
2899
+ * @param {Mat3} out the receiving matrix, defaults to mat3()
2861
2900
  * @returns {Mat3} out
2862
2901
  */
2863
- static fromQuat(q, out = new Mat3()) {
2902
+ static fromQuat(q, out = mat3()) {
2864
2903
  const x = q[0], y = q[1], z = q[2], w = q[3];
2865
2904
  const x2 = x + x, y2 = y + y, z2 = z + z;
2866
2905
  const xx = x * x2, yx = y * x2, yy = y * y2;
@@ -2881,10 +2920,10 @@ class Mat3 extends Float32Array {
2881
2920
  * Calculates a mat3 normal matrix (transpose inverse) from a mat4
2882
2921
  *
2883
2922
  * @param {Mat4} a the source mat4 to derive the normal matrix from
2884
- * @param {Mat3} out the receiving matrix, defaults to new Mat3()
2923
+ * @param {Mat3} out the receiving matrix, defaults to mat3()
2885
2924
  * @returns {Mat3|null} out, or null if not invertible
2886
2925
  */
2887
- static normalFromMat4(a, out = new Mat3()) {
2926
+ static normalFromMat4(a, out = mat3()) {
2888
2927
  const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
2889
2928
  const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
2890
2929
  const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
@@ -2920,10 +2959,10 @@ class Mat3 extends Float32Array {
2920
2959
  * Copies the upper-left 3x3 values of a mat4 into a mat3
2921
2960
  *
2922
2961
  * @param {Mat4} a the source mat4
2923
- * @param {Mat3} out the receiving matrix, defaults to new Mat3()
2962
+ * @param {Mat3} out the receiving matrix, defaults to mat3()
2924
2963
  * @returns {Mat3} out
2925
2964
  */
2926
- static fromMat4(a, out = new Mat3()) {
2965
+ static fromMat4(a, out = mat3()) {
2927
2966
  out[0] = a[0];
2928
2967
  out[1] = a[1];
2929
2968
  out[2] = a[2];
@@ -2940,10 +2979,10 @@ class Mat3 extends Float32Array {
2940
2979
  *
2941
2980
  * @param {Number} width width of the projection
2942
2981
  * @param {Number} height height of the projection
2943
- * @param {Mat3} out the receiving matrix, defaults to new Mat3()
2982
+ * @param {Mat3} out the receiving matrix, defaults to mat3()
2944
2983
  * @returns {Mat3} out
2945
2984
  */
2946
- static projection(width, height, out = new Mat3()) {
2985
+ static projection(width, height, out = mat3()) {
2947
2986
  out[0] = 2 / width;
2948
2987
  out[1] = 0;
2949
2988
  out[2] = 0;
@@ -2969,10 +3008,10 @@ class Mat3 extends Float32Array {
2969
3008
  * Adds two mat3's
2970
3009
  *
2971
3010
  * @param {Mat3} b the second operand
2972
- * @param {Mat3} out the receiving matrix, defaults to this
3011
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
2973
3012
  * @returns {Mat3} out
2974
3013
  */
2975
- plus(b, out = index.ALWAYS_COPY ? new Mat3() : this) {
3014
+ plus(b, out = index.ALWAYS_COPY ? mat3() : this) {
2976
3015
  out[0] = this[0] + b[0];
2977
3016
  out[1] = this[1] + b[1];
2978
3017
  out[2] = this[2] + b[2];
@@ -2988,10 +3027,10 @@ class Mat3 extends Float32Array {
2988
3027
  * Subtracts matrix b from this
2989
3028
  *
2990
3029
  * @param {Mat3} b the second operand
2991
- * @param {Mat3} out the receiving matrix, defaults to this
3030
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
2992
3031
  * @returns {Mat3} out
2993
3032
  */
2994
- minus(b, out = index.ALWAYS_COPY ? new Mat3() : this) {
3033
+ minus(b, out = index.ALWAYS_COPY ? mat3() : this) {
2995
3034
  out[0] = this[0] - b[0];
2996
3035
  out[1] = this[1] - b[1];
2997
3036
  out[2] = this[2] - b[2];
@@ -3007,10 +3046,10 @@ class Mat3 extends Float32Array {
3007
3046
  * Multiplies each element of a mat3 by a scalar number
3008
3047
  *
3009
3048
  * @param {Number} b amount to scale the matrix's elements by
3010
- * @param {Mat3} out the receiving matrix, defaults to this
3049
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
3011
3050
  * @returns {Mat3} out
3012
3051
  */
3013
- scaleScalar(b, out = index.ALWAYS_COPY ? new Mat3() : this) {
3052
+ scaleScalar(b, out = index.ALWAYS_COPY ? mat3() : this) {
3014
3053
  out[0] = this[0] * b;
3015
3054
  out[1] = this[1] * b;
3016
3055
  out[2] = this[2] * b;
@@ -3027,10 +3066,10 @@ class Mat3 extends Float32Array {
3027
3066
  *
3028
3067
  * @param {Mat3} b the second operand
3029
3068
  * @param {Number} scale the amount to scale b's elements by before adding
3030
- * @param {Mat3} out the receiving matrix, defaults to this
3069
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
3031
3070
  * @returns {Mat3} out
3032
3071
  */
3033
- multiplyScalarAndAdd(b, scale, out = index.ALWAYS_COPY ? new Mat3() : this) {
3072
+ multiplyScalarAndAdd(b, scale, out = index.ALWAYS_COPY ? mat3() : this) {
3034
3073
  out[0] = this[0] + b[0] * scale;
3035
3074
  out[1] = this[1] + b[1] * scale;
3036
3075
  out[2] = this[2] + b[2] * scale;
@@ -3090,7 +3129,7 @@ Mat3.prototype.mult = Mat3.prototype.multiply;
3090
3129
  Mat3.prototype.times = Mat3.prototype.multiply;
3091
3130
  Mat3.prototype.str = Mat3.prototype.toString;
3092
3131
  Mat3.prototype.multiplyScalar = Mat3.prototype.scaleScalar;
3093
- const mat3 = Object.assign((...args) => {
3132
+ const createMat3 = (...args) => {
3094
3133
  const out = new Mat3();
3095
3134
  let i = 0;
3096
3135
  for (const a of args) {
@@ -3101,7 +3140,9 @@ const mat3 = Object.assign((...args) => {
3101
3140
  out[i++] = v;
3102
3141
  }
3103
3142
  return out;
3104
- }, Mat3);
3143
+ };
3144
+ Object.setPrototypeOf(createMat3, Mat3);
3145
+ const mat3 = createMat3;
3105
3146
  const mat3x3 = mat3;
3106
3147
 
3107
3148
  var _a;
@@ -3110,9 +3151,9 @@ var _a;
3110
3151
  * @extends Float32Array
3111
3152
  */
3112
3153
  class Mat4 extends Float32Array {
3113
- static get identity() { return new _a(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
3114
- static get Identity() { return new _a(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
3115
- static get IDENTITY() { return new _a(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
3154
+ static get identity() { return mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
3155
+ static get Identity() { return mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
3156
+ static get IDENTITY() { return mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
3116
3157
  /**
3117
3158
  * Creates a new 4x4 matrix
3118
3159
  *
@@ -3158,15 +3199,15 @@ class Mat4 extends Float32Array {
3158
3199
  * @returns {Mat4} a new 4x4 matrix
3159
3200
  */
3160
3201
  clone() {
3161
- return new _a(this[0], this[1], this[2], this[3], this[4], this[5], this[6], this[7], this[8], this[9], this[10], this[11], this[12], this[13], this[14], this[15]);
3202
+ return mat4(this[0], this[1], this[2], this[3], this[4], this[5], this[6], this[7], this[8], this[9], this[10], this[11], this[12], this[13], this[14], this[15]);
3162
3203
  }
3163
3204
  /**
3164
3205
  * Transposes a mat4
3165
3206
  *
3166
- * @param {Mat4} out the receiving matrix, defaults to this
3207
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3167
3208
  * @returns {Mat4} out
3168
3209
  */
3169
- transpose(out = index.ALWAYS_COPY ? new _a() : this) {
3210
+ transpose(out = index.ALWAYS_COPY ? mat4() : this) {
3170
3211
  if (out.exactEquals(this)) {
3171
3212
  const a01 = this[1], a02 = this[2], a03 = this[3];
3172
3213
  const a12 = this[6], a13 = this[7], a23 = this[11];
@@ -3206,10 +3247,10 @@ class Mat4 extends Float32Array {
3206
3247
  /**
3207
3248
  * Inverts a mat4
3208
3249
  *
3209
- * @param {Mat4} out the receiving matrix, defaults to this
3250
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3210
3251
  * @returns {Mat4} out
3211
3252
  */
3212
- invert(out = index.ALWAYS_COPY ? new _a() : this) {
3253
+ invert(out = index.ALWAYS_COPY ? mat4() : this) {
3213
3254
  const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3];
3214
3255
  const a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7];
3215
3256
  const a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11];
@@ -3251,10 +3292,10 @@ class Mat4 extends Float32Array {
3251
3292
  /**
3252
3293
  * Calculates the adjugate of a mat4
3253
3294
  *
3254
- * @param {Mat4} out the receiving matrix, defaults to this
3295
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3255
3296
  * @returns {Mat4} out
3256
3297
  */
3257
- adjoint(out = index.ALWAYS_COPY ? new _a() : this) {
3298
+ adjoint(out = index.ALWAYS_COPY ? mat4() : this) {
3258
3299
  const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3];
3259
3300
  const a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7];
3260
3301
  const a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11];
@@ -3306,7 +3347,7 @@ class Mat4 extends Float32Array {
3306
3347
  (a01 * a13 - a03 * a11) * (a20 * a32 - a22 * a30) +
3307
3348
  (a02 * a13 - a03 * a12) * (a20 * a31 - a21 * a30));
3308
3349
  }
3309
- multiply(b, out = index.ALWAYS_COPY ? new _a() : this) {
3350
+ multiply(b, out = index.ALWAYS_COPY ? mat4() : this) {
3310
3351
  if (b instanceof Vec2)
3311
3352
  return b.transformMat4(this);
3312
3353
  if (b instanceof Vec3)
@@ -3352,10 +3393,10 @@ class Mat4 extends Float32Array {
3352
3393
  * Translates a mat4 by the given Vec3
3353
3394
  *
3354
3395
  * @param {Vec3} v vector to translate by
3355
- * @param {Mat4} out the receiving matrix, defaults to this
3396
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3356
3397
  * @returns {Mat4} out
3357
3398
  */
3358
- translate(v, out = index.ALWAYS_COPY ? new _a() : this) {
3399
+ translate(v, out = index.ALWAYS_COPY ? mat4() : this) {
3359
3400
  const x = v[0], y = v[1], z = v[2];
3360
3401
  if (out.exactEquals(this)) {
3361
3402
  out[12] = this[0] * x + this[4] * y + this[8] * z + this[12];
@@ -3390,10 +3431,10 @@ class Mat4 extends Float32Array {
3390
3431
  * Scales a mat4 by the dimensions in the given Vec3 not using vectorization
3391
3432
  *
3392
3433
  * @param {Vec3} v the Vec3 to scale the matrix by
3393
- * @param {Mat4} out the receiving matrix, defaults to this
3434
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3394
3435
  * @returns {Mat4} out
3395
3436
  */
3396
- scale(v, out = index.ALWAYS_COPY ? new _a() : this) {
3437
+ scale(v, out = index.ALWAYS_COPY ? mat4() : this) {
3397
3438
  const x = v[0], y = v[1], z = v[2];
3398
3439
  out[0] = this[0] * x;
3399
3440
  out[1] = this[1] * x;
@@ -3418,10 +3459,10 @@ class Mat4 extends Float32Array {
3418
3459
  *
3419
3460
  * @param {Number} rad the angle to rotate the matrix by
3420
3461
  * @param {Vec3} axis the axis to rotate around
3421
- * @param {Mat4} out the receiving matrix, defaults to this
3462
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3422
3463
  * @returns {Mat4} out
3423
3464
  */
3424
- rotate(rad, axis, out = index.ALWAYS_COPY ? new _a() : this) {
3465
+ rotate(rad, axis, out = index.ALWAYS_COPY ? mat4() : this) {
3425
3466
  let x = axis[0], y = axis[1], z = axis[2];
3426
3467
  let len = Math.sqrt(x * x + y * y + z * z);
3427
3468
  if (len < index.EPSILON)
@@ -3459,10 +3500,10 @@ class Mat4 extends Float32Array {
3459
3500
  * Rotates a mat4 by the given angle around the X axis
3460
3501
  *
3461
3502
  * @param {Number} rad the angle to rotate the matrix by
3462
- * @param {Mat4} out the receiving matrix, defaults to this
3503
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3463
3504
  * @returns {Mat4} out
3464
3505
  */
3465
- rotateX(rad, out = index.ALWAYS_COPY ? new _a() : this) {
3506
+ rotateX(rad, out = index.ALWAYS_COPY ? mat4() : this) {
3466
3507
  const s = Math.sin(rad), c = Math.cos(rad);
3467
3508
  const a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7];
3468
3509
  const a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11];
@@ -3490,10 +3531,10 @@ class Mat4 extends Float32Array {
3490
3531
  * Rotates a mat4 by the given angle around the Y axis
3491
3532
  *
3492
3533
  * @param {Number} rad the angle to rotate the matrix by
3493
- * @param {Mat4} out the receiving matrix, defaults to this
3534
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3494
3535
  * @returns {Mat4} out
3495
3536
  */
3496
- rotateY(rad, out = index.ALWAYS_COPY ? new _a() : this) {
3537
+ rotateY(rad, out = index.ALWAYS_COPY ? mat4() : this) {
3497
3538
  const s = Math.sin(rad), c = Math.cos(rad);
3498
3539
  const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3];
3499
3540
  const a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11];
@@ -3521,10 +3562,10 @@ class Mat4 extends Float32Array {
3521
3562
  * Rotates a mat4 by the given angle around the Z axis
3522
3563
  *
3523
3564
  * @param {Number} rad the angle to rotate the matrix by
3524
- * @param {Mat4} out the receiving matrix, defaults to this
3565
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3525
3566
  * @returns {Mat4} out
3526
3567
  */
3527
- rotateZ(rad, out = index.ALWAYS_COPY ? new _a() : this) {
3568
+ rotateZ(rad, out = index.ALWAYS_COPY ? mat4() : this) {
3528
3569
  const s = Math.sin(rad), c = Math.cos(rad);
3529
3570
  const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3];
3530
3571
  const a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7];
@@ -3680,10 +3721,10 @@ class Mat4 extends Float32Array {
3680
3721
  * Creates a matrix from a vector translation
3681
3722
  *
3682
3723
  * @param {Vec3} v translation vector
3683
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3724
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3684
3725
  * @returns {Mat4} out
3685
3726
  */
3686
- static fromTranslation(v, out = new _a()) {
3727
+ static fromTranslation(v, out = mat4()) {
3687
3728
  out[0] = out[5] = out[10] = out[15] = 1;
3688
3729
  out[1] = out[2] = out[3] = out[4] = out[6] = out[7] = out[8] = out[9] = out[11] = 0;
3689
3730
  out[12] = v[0];
@@ -3695,10 +3736,10 @@ class Mat4 extends Float32Array {
3695
3736
  * Creates a matrix from a vector scaling
3696
3737
  *
3697
3738
  * @param {Vec3} v scaling vector
3698
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3739
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3699
3740
  * @returns {Mat4} out
3700
3741
  */
3701
- static fromScaling(v, out = new _a()) {
3742
+ static fromScaling(v, out = mat4()) {
3702
3743
  out[0] = v[0];
3703
3744
  out[5] = v[1];
3704
3745
  out[10] = v[2];
@@ -3711,10 +3752,10 @@ class Mat4 extends Float32Array {
3711
3752
  *
3712
3753
  * @param {Number} rad the angle to rotate the matrix by
3713
3754
  * @param {Vec3} axis the axis to rotate around
3714
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3755
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3715
3756
  * @returns {Mat4} out
3716
3757
  */
3717
- static fromRotation(rad, axis, out = new _a()) {
3758
+ static fromRotation(rad, axis, out = mat4()) {
3718
3759
  let x = axis[0], y = axis[1], z = axis[2];
3719
3760
  let len = Math.sqrt(x * x + y * y + z * z);
3720
3761
  if (len < index.EPSILON)
@@ -3744,10 +3785,10 @@ class Mat4 extends Float32Array {
3744
3785
  * Creates a matrix from the given angle around the X axis
3745
3786
  *
3746
3787
  * @param {Number} rad the angle to rotate the matrix by
3747
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3788
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3748
3789
  * @returns {Mat4} out
3749
3790
  */
3750
- static fromXRotation(rad, out = new _a()) {
3791
+ static fromXRotation(rad, out = mat4()) {
3751
3792
  const s = Math.sin(rad), c = Math.cos(rad);
3752
3793
  out[0] = 1;
3753
3794
  out[1] = out[2] = out[3] = out[4] = out[7] = out[8] = out[11] = out[12] = out[13] = out[14] = 0;
@@ -3762,10 +3803,10 @@ class Mat4 extends Float32Array {
3762
3803
  * Creates a matrix from the given angle around the Y axis
3763
3804
  *
3764
3805
  * @param {Number} rad the angle to rotate the matrix by
3765
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3806
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3766
3807
  * @returns {Mat4} out
3767
3808
  */
3768
- static fromYRotation(rad, out = new _a()) {
3809
+ static fromYRotation(rad, out = mat4()) {
3769
3810
  const s = Math.sin(rad), c = Math.cos(rad);
3770
3811
  out[0] = c;
3771
3812
  out[1] = out[3] = out[4] = out[6] = out[7] = out[9] = out[11] = out[12] = out[13] = out[14] = 0;
@@ -3779,10 +3820,10 @@ class Mat4 extends Float32Array {
3779
3820
  * Creates a matrix from the given angle around the Z axis
3780
3821
  *
3781
3822
  * @param {Number} rad the angle to rotate the matrix by
3782
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3823
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3783
3824
  * @returns {Mat4} out
3784
3825
  */
3785
- static fromZRotation(rad, out = new _a()) {
3826
+ static fromZRotation(rad, out = mat4()) {
3786
3827
  const s = Math.sin(rad), c = Math.cos(rad);
3787
3828
  out[0] = c;
3788
3829
  out[1] = s;
@@ -3797,10 +3838,10 @@ class Mat4 extends Float32Array {
3797
3838
  *
3798
3839
  * @param {Quat} q rotation quaternion
3799
3840
  * @param {Vec3} v translation vector
3800
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3841
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3801
3842
  * @returns {Mat4} out
3802
3843
  */
3803
- static fromRotationTranslation(q, v, out = new _a()) {
3844
+ static fromRotationTranslation(q, v, out = mat4()) {
3804
3845
  const x = q[0], y = q[1], z = q[2], w = q[3];
3805
3846
  const x2 = x + x, y2 = y + y, z2 = z + z;
3806
3847
  const xx = x * x2, xy = x * y2, xz = x * z2;
@@ -3828,10 +3869,10 @@ class Mat4 extends Float32Array {
3828
3869
  * @param {Quat} q rotation quaternion
3829
3870
  * @param {Vec3} v translation vector
3830
3871
  * @param {Vec3} s scaling vector
3831
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3872
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3832
3873
  * @returns {Mat4} out
3833
3874
  */
3834
- static fromRotationTranslationScale(q, v, s, out = new _a()) {
3875
+ static fromRotationTranslationScale(q, v, s, out = mat4()) {
3835
3876
  const x = q[0], y = q[1], z = q[2], w = q[3];
3836
3877
  const x2 = x + x, y2 = y + y, z2 = z + z;
3837
3878
  const xx = x * x2, xy = x * y2, xz = x * z2;
@@ -3861,10 +3902,10 @@ class Mat4 extends Float32Array {
3861
3902
  * @param {Vec3} v translation vector
3862
3903
  * @param {Vec3} s scaling vector
3863
3904
  * @param {Vec3} o the origin vector
3864
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3905
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3865
3906
  * @returns {Mat4} out
3866
3907
  */
3867
- static fromRotationTranslationScaleOrigin(q, v, s, o, out = new _a()) {
3908
+ static fromRotationTranslationScaleOrigin(q, v, s, o, out = mat4()) {
3868
3909
  const x = q[0], y = q[1], z = q[2], w = q[3];
3869
3910
  const x2 = x + x, y2 = y + y, z2 = z + z;
3870
3911
  const xx = x * x2, xy = x * y2, xz = x * z2;
@@ -3901,10 +3942,10 @@ class Mat4 extends Float32Array {
3901
3942
  * Calculates a 4x4 matrix from the given quaternion
3902
3943
  *
3903
3944
  * @param {Quat} q quaternion to create matrix from
3904
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3945
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3905
3946
  * @returns {Mat4} out
3906
3947
  */
3907
- static fromQuat(q, out = new _a()) {
3948
+ static fromQuat(q, out = mat4()) {
3908
3949
  const x = q[0], y = q[1], z = q[2], w = q[3];
3909
3950
  const x2 = x + x, y2 = y + y, z2 = z + z;
3910
3951
  const xx = x * x2, yx = y * x2, yy = y * y2;
@@ -3932,10 +3973,10 @@ class Mat4 extends Float32Array {
3932
3973
  * @param {Number} top top bound of the frustum
3933
3974
  * @param {Number} near near bound of the frustum
3934
3975
  * @param {Number} far far bound of the frustum
3935
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3976
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3936
3977
  * @returns {Mat4} out
3937
3978
  */
3938
- static frustum(left, right, bottom, top, near, far, out = new _a()) {
3979
+ static frustum(left, right, bottom, top, near, far, out = mat4()) {
3939
3980
  const rl = 1 / (right - left);
3940
3981
  const tb = 1 / (top - bottom);
3941
3982
  const nf = 1 / (near - far);
@@ -3959,10 +4000,10 @@ class Mat4 extends Float32Array {
3959
4000
  * @param {Number} aspect aspect ratio, typically viewport width / height
3960
4001
  * @param {Number} near near bound of the frustum
3961
4002
  * @param {Number | null} far far bound of the frustum, can be null or Infinity
3962
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
4003
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3963
4004
  * @returns {Mat4} out
3964
4005
  */
3965
- static perspectiveNO(fovy, aspect, near, far, out = new _a()) {
4006
+ static perspectiveNO(fovy, aspect, near, far, out = mat4()) {
3966
4007
  const f = 1.0 / Math.tan(fovy / 2);
3967
4008
  const lh = index.LEFT_HANDED;
3968
4009
  out[0] = f / aspect;
@@ -3989,10 +4030,10 @@ class Mat4 extends Float32Array {
3989
4030
  * @param {Number} aspect aspect ratio, typically viewport width / height
3990
4031
  * @param {Number} near near bound of the frustum
3991
4032
  * @param {Number | null} far far bound of the frustum, can be null or Infinity
3992
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
4033
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3993
4034
  * @returns {Mat4} out
3994
4035
  */
3995
- static perspectiveZO(fovy, aspect, near, far, out = new _a()) {
4036
+ static perspectiveZO(fovy, aspect, near, far, out = mat4()) {
3996
4037
  const f = 1.0 / Math.tan(fovy / 2);
3997
4038
  const lh = index.LEFT_HANDED;
3998
4039
  out[0] = f / aspect;
@@ -4026,10 +4067,10 @@ class Mat4 extends Float32Array {
4026
4067
  * @param {Object} fov object containing upDegrees, downDegrees, leftDegrees, rightDegrees
4027
4068
  * @param {Number} near near bound of the frustum
4028
4069
  * @param {Number} far far bound of the frustum
4029
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
4070
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
4030
4071
  * @returns {Mat4} out
4031
4072
  */
4032
- static perspectiveFromFieldOfView(fov, near, far, out = new _a()) {
4073
+ static perspectiveFromFieldOfView(fov, near, far, out = mat4()) {
4033
4074
  const upTan = Math.tan((fov.upDegrees * Math.PI) / 180.0);
4034
4075
  const downTan = Math.tan((fov.downDegrees * Math.PI) / 180.0);
4035
4076
  const leftTan = Math.tan((fov.leftDegrees * Math.PI) / 180.0);
@@ -4066,10 +4107,10 @@ class Mat4 extends Float32Array {
4066
4107
  * @param {Number} top top bound of the frustum
4067
4108
  * @param {Number} near near bound of the frustum
4068
4109
  * @param {Number} far far bound of the frustum
4069
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
4110
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
4070
4111
  * @returns {Mat4} out
4071
4112
  */
4072
- static orthoNO(left, right, bottom, top, near, far, out = new _a()) {
4113
+ static orthoNO(left, right, bottom, top, near, far, out = mat4()) {
4073
4114
  const lr = 1 / (left - right);
4074
4115
  const bt = 1 / (bottom - top);
4075
4116
  const nf = 1 / (near - far);
@@ -4103,10 +4144,10 @@ class Mat4 extends Float32Array {
4103
4144
  * @param {Number} top top bound of the frustum
4104
4145
  * @param {Number} near near bound of the frustum
4105
4146
  * @param {Number} far far bound of the frustum
4106
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
4147
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
4107
4148
  * @returns {Mat4} out
4108
4149
  */
4109
- static orthoZO(left, right, bottom, top, near, far, out = new _a()) {
4150
+ static orthoZO(left, right, bottom, top, near, far, out = mat4()) {
4110
4151
  const lr = 1 / (left - right);
4111
4152
  const bt = 1 / (bottom - top);
4112
4153
  const nf = 1 / (near - far);
@@ -4136,10 +4177,10 @@ class Mat4 extends Float32Array {
4136
4177
  * @param {Vec3} eye position of the viewer
4137
4178
  * @param {Vec3} center point the viewer is looking at
4138
4179
  * @param {Vec3} up vector pointing up
4139
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
4180
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
4140
4181
  * @returns {Mat4} out
4141
4182
  */
4142
- static lookAt(eye, center, up, out = new _a()) {
4183
+ static lookAt(eye, center, up, out = mat4()) {
4143
4184
  let x0, x1, x2, y0, y1, y2, z0, z1, z2, len;
4144
4185
  const eyex = eye[0], eyey = eye[1], eyez = eye[2];
4145
4186
  const upx = up[0], upy = up[1], upz = up[2];
@@ -4231,10 +4272,10 @@ class Mat4 extends Float32Array {
4231
4272
  * @param {Vec3} eye position of the viewer
4232
4273
  * @param {Vec3} target point the viewer is looking at
4233
4274
  * @param {Vec3} up vector pointing up
4234
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
4275
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
4235
4276
  * @returns {Mat4} out
4236
4277
  */
4237
- static targetTo(eye, target, up, out = new _a()) {
4278
+ static targetTo(eye, target, up, out = mat4()) {
4238
4279
  const eyex = eye[0], eyey = eye[1], eyez = eye[2];
4239
4280
  const upx = up[0], upy = up[1], upz = up[2];
4240
4281
  let z0, z1, z2;
@@ -4293,7 +4334,7 @@ class Mat4 extends Float32Array {
4293
4334
  * @param {Mat4} out the receiving matrix, defaults to a new Mat4
4294
4335
  * @returns {Mat4} out
4295
4336
  */
4296
- static infinitePerspective(fovy, aspect, near, out = new _a()) {
4337
+ static infinitePerspective(fovy, aspect, near, out = mat4()) {
4297
4338
  const f = 1.0 / Math.tan(fovy / 2);
4298
4339
  const lh = index.LEFT_HANDED;
4299
4340
  out[0] = f / aspect;
@@ -4350,7 +4391,7 @@ class Mat4 extends Float32Array {
4350
4391
  const a10 = model[4], a11 = model[5], a12 = model[6], a13 = model[7];
4351
4392
  const a20 = model[8], a21 = model[9], a22 = model[10], a23 = model[11];
4352
4393
  const a30 = model[12], a31 = model[13], a32 = model[14], a33 = model[15];
4353
- const pm = new _a();
4394
+ const pm = mat4();
4354
4395
  let b0 = proj[0], b1 = proj[1], b2 = proj[2], b3 = proj[3];
4355
4396
  pm[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
4356
4397
  pm[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
@@ -4408,10 +4449,10 @@ class Mat4 extends Float32Array {
4408
4449
  * Adds two mat4's
4409
4450
  *
4410
4451
  * @param {Mat4} b the second operand
4411
- * @param {Mat4} out the receiving matrix, defaults to this
4452
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
4412
4453
  * @returns {Mat4} out
4413
4454
  */
4414
- plus(b, out = index.ALWAYS_COPY ? new _a() : this) {
4455
+ plus(b, out = index.ALWAYS_COPY ? mat4() : this) {
4415
4456
  out[0] = this[0] + b[0];
4416
4457
  out[1] = this[1] + b[1];
4417
4458
  out[2] = this[2] + b[2];
@@ -4434,10 +4475,10 @@ class Mat4 extends Float32Array {
4434
4475
  * Subtracts matrix b from a mat4
4435
4476
  *
4436
4477
  * @param {Mat4} b the second operand
4437
- * @param {Mat4} out the receiving matrix, defaults to this
4478
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
4438
4479
  * @returns {Mat4} out
4439
4480
  */
4440
- minus(b, out = index.ALWAYS_COPY ? new _a() : this) {
4481
+ minus(b, out = index.ALWAYS_COPY ? mat4() : this) {
4441
4482
  out[0] = this[0] - b[0];
4442
4483
  out[1] = this[1] - b[1];
4443
4484
  out[2] = this[2] - b[2];
@@ -4460,10 +4501,10 @@ class Mat4 extends Float32Array {
4460
4501
  * Multiplies each element of a mat4 by a scalar number
4461
4502
  *
4462
4503
  * @param {Number} b amount to scale the matrix's elements by
4463
- * @param {Mat4} out the receiving matrix, defaults to this
4504
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
4464
4505
  * @returns {Mat4} out
4465
4506
  */
4466
- scaleScalar(b, out = index.ALWAYS_COPY ? new _a() : this) {
4507
+ scaleScalar(b, out = index.ALWAYS_COPY ? mat4() : this) {
4467
4508
  out[0] = this[0] * b;
4468
4509
  out[1] = this[1] * b;
4469
4510
  out[2] = this[2] * b;
@@ -4487,10 +4528,10 @@ class Mat4 extends Float32Array {
4487
4528
  *
4488
4529
  * @param {Mat4} b the second operand
4489
4530
  * @param {Number} scale the amount to scale b's elements by before adding
4490
- * @param {Mat4} out the receiving matrix, defaults to this
4531
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
4491
4532
  * @returns {Mat4} out
4492
4533
  */
4493
- multiplyScalarAndAdd(b, scale, out = index.ALWAYS_COPY ? new _a() : this) {
4534
+ multiplyScalarAndAdd(b, scale, out = index.ALWAYS_COPY ? mat4() : this) {
4494
4535
  out[0] = this[0] + b[0] * scale;
4495
4536
  out[1] = this[1] + b[1] * scale;
4496
4537
  out[2] = this[2] + b[2] * scale;
@@ -4554,7 +4595,7 @@ Mat4.prototype.mult = Mat4.prototype.multiply;
4554
4595
  Mat4.prototype.times = Mat4.prototype.multiply;
4555
4596
  Mat4.prototype.str = Mat4.prototype.toString;
4556
4597
  Mat4.prototype.multiplyScalar = Mat4.prototype.scaleScalar;
4557
- const mat4 = Object.assign((...args) => {
4598
+ const createMat4 = (...args) => {
4558
4599
  const out = new Mat4();
4559
4600
  let i = 0;
4560
4601
  for (const a of args) {
@@ -4565,7 +4606,9 @@ const mat4 = Object.assign((...args) => {
4565
4606
  out[i++] = v;
4566
4607
  }
4567
4608
  return out;
4568
- }, Mat4);
4609
+ };
4610
+ Object.setPrototypeOf(createMat4, Mat4);
4611
+ const mat4 = createMat4;
4569
4612
  const mat4x4 = mat4;
4570
4613
 
4571
4614
  /**
@@ -4573,9 +4616,9 @@ const mat4x4 = mat4;
4573
4616
  * @extends Vec4
4574
4617
  */
4575
4618
  class Quat extends Float32Array {
4576
- static get identity() { return new Quat(0, 0, 0, 1); }
4577
- static get Identity() { return new Quat(0, 0, 0, 1); }
4578
- static get IDENTITY() { return new Quat(0, 0, 0, 1); }
4619
+ static get identity() { return quat(0, 0, 0, 1); }
4620
+ static get Identity() { return quat(0, 0, 0, 1); }
4621
+ static get IDENTITY() { return quat(0, 0, 0, 1); }
4579
4622
  /**
4580
4623
  * Creates a new quaternion
4581
4624
  *
@@ -4595,10 +4638,10 @@ class Quat extends Float32Array {
4595
4638
  * Calculates the Hamilton product of two quaternions
4596
4639
  *
4597
4640
  * @param {Quat} b the second operand
4598
- * @param {Quat} out the receiving quaternion, defaults to this
4641
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4599
4642
  * @returns {Quat} out
4600
4643
  */
4601
- multiply(b, out = index.ALWAYS_COPY ? new Quat() : this) {
4644
+ multiply(b, out = index.ALWAYS_COPY ? quat() : this) {
4602
4645
  if (typeof b === 'number') {
4603
4646
  out[0] = this[0] * b;
4604
4647
  out[1] = this[1] * b;
@@ -4636,7 +4679,7 @@ class Quat extends Float32Array {
4636
4679
  *
4637
4680
  * @param {Vec3} axis the axis around which to rotate
4638
4681
  * @param {Number} rad the angle in radians
4639
- * @param {Quat} out the receiving quaternion, defaults to this
4682
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4640
4683
  * @returns {Quat} out
4641
4684
  */
4642
4685
  setAxisAngle(axis, rad, out = index.ALWAYS_COPY ? quat() : this) {
@@ -4691,7 +4734,7 @@ class Quat extends Float32Array {
4691
4734
  * Rotates a quaternion by the given angle about the X axis
4692
4735
  *
4693
4736
  * @param {Number} rad angle in radians to rotate
4694
- * @param {Quat} out the receiving quaternion, defaults to this
4737
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4695
4738
  * @returns {Quat} out
4696
4739
  */
4697
4740
  rotateX(rad, out = index.ALWAYS_COPY ? quat() : this) {
@@ -4708,7 +4751,7 @@ class Quat extends Float32Array {
4708
4751
  * Rotates a quaternion by the given angle about the Y axis
4709
4752
  *
4710
4753
  * @param {Number} rad angle in radians to rotate
4711
- * @param {Quat} out the receiving quaternion, defaults to this
4754
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4712
4755
  * @returns {Quat} out
4713
4756
  */
4714
4757
  rotateY(rad, out = index.ALWAYS_COPY ? quat() : this) {
@@ -4725,7 +4768,7 @@ class Quat extends Float32Array {
4725
4768
  * Rotates a quaternion by the given angle about the Z axis
4726
4769
  *
4727
4770
  * @param {Number} rad angle in radians to rotate
4728
- * @param {Quat} out the receiving quaternion, defaults to this
4771
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4729
4772
  * @returns {Quat} out
4730
4773
  */
4731
4774
  rotateZ(rad, out = index.ALWAYS_COPY ? quat() : this) {
@@ -4768,7 +4811,7 @@ class Quat extends Float32Array {
4768
4811
  /**
4769
4812
  * Calculates the exponential of the unit quaternion
4770
4813
  *
4771
- * @param {Quat} out the receiving quaternion, defaults to this
4814
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4772
4815
  * @returns {Quat} out
4773
4816
  */
4774
4817
  exp(out = index.ALWAYS_COPY ? quat() : this) {
@@ -4802,7 +4845,7 @@ class Quat extends Float32Array {
4802
4845
  /**
4803
4846
  * Calculates the natural logarithm of the unit quaternion
4804
4847
  *
4805
- * @param {Quat} out the receiving quaternion, defaults to this
4848
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4806
4849
  * @returns {Quat} out
4807
4850
  */
4808
4851
  ln(out = index.ALWAYS_COPY ? quat() : this) {
@@ -4876,7 +4919,7 @@ class Quat extends Float32Array {
4876
4919
  *
4877
4920
  * @param {Quat} b the second operand
4878
4921
  * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
4879
- * @param {Quat} out the receiving quaternion, defaults to this
4922
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4880
4923
  * @returns {Quat} out
4881
4924
  */
4882
4925
  slerp(b, t, out = index.ALWAYS_COPY ? quat() : this) {
@@ -4955,7 +4998,7 @@ class Quat extends Float32Array {
4955
4998
  /**
4956
4999
  * Calculates the inverse of a quaternion
4957
5000
  *
4958
- * @param {Quat} out the receiving quaternion, defaults to this
5001
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4959
5002
  * @returns {Quat} out
4960
5003
  */
4961
5004
  invert(out = index.ALWAYS_COPY ? quat() : this) {
@@ -4986,7 +5029,7 @@ class Quat extends Float32Array {
4986
5029
  /**
4987
5030
  * Calculates the conjugate of a quaternion
4988
5031
  *
4989
- * @param {Quat} out the receiving quaternion, defaults to this
5032
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4990
5033
  * @returns {Quat} out
4991
5034
  */
4992
5035
  conjugate(out = index.ALWAYS_COPY ? quat() : this) {
@@ -5207,11 +5250,12 @@ class Quat extends Float32Array {
5207
5250
  /**
5208
5251
  * Normalizes a quaternion
5209
5252
  *
5210
- * @param {Quat} out the receiving vector, defaults to this
5253
+ * @param {Quat} q the quaternion to normalize
5254
+ * @param {Quat} out the receiving vector, defaults to new quat()
5211
5255
  * @returns {Quat} out
5212
5256
  */
5213
- normalize(out = index.ALWAYS_COPY ? new Quat() : this) {
5214
- const x = this[0], y = this[1], z = this[2], w = this[3];
5257
+ static normalize(q, out = quat()) {
5258
+ const x = q[0], y = q[1], z = q[2], w = q[3];
5215
5259
  let len = x * x + y * y + z * z + w * w;
5216
5260
  if (len > 0) {
5217
5261
  len = 1.0 / Math.sqrt(len);
@@ -5222,6 +5266,15 @@ class Quat extends Float32Array {
5222
5266
  out[3] = w * len;
5223
5267
  return out;
5224
5268
  }
5269
+ /**
5270
+ * Normalizes a quaternion
5271
+ *
5272
+ * @param {Quat} out the receiving vector, defaults to new quat()
5273
+ * @returns {Quat} out
5274
+ */
5275
+ normalize(out = index.ALWAYS_COPY ? quat() : this) {
5276
+ return Quat.normalize(this, out);
5277
+ }
5225
5278
  /**
5226
5279
  * Creates a quaternion that looks along the given direction vector
5227
5280
  *
@@ -5230,7 +5283,7 @@ class Quat extends Float32Array {
5230
5283
  * @param {Quat} out the receiving quaternion, defaults to quat()
5231
5284
  * @returns {Quat} out
5232
5285
  */
5233
- static quatLookAt(direction, up, out = new Quat()) {
5286
+ static quatLookAt(direction, up, out = quat()) {
5234
5287
  const f = vec3(direction[0], direction[1], direction[2]).normalize();
5235
5288
  const s = Vec3.cross(f, up).normalize();
5236
5289
  const u = Vec3.cross(s, f);
@@ -5350,7 +5403,10 @@ Quat.prototype.mul = Quat.prototype.multiply;
5350
5403
  Quat.prototype.scale = Quat.prototype.multiply;
5351
5404
  Quat.prototype.times = Quat.prototype.multiply;
5352
5405
  Quat.prototype.str = Quat.prototype.toString;
5353
- const quat = Object.assign((x = 0, y = 0, z = 0, w = 1) => new Quat(x, y, z, w), Quat);
5406
+ Quat.prototype.normalized = Quat.prototype.normalize;
5407
+ const createQuat = (x = 0, y = 0, z = 0, w = 1) => new Quat(x, y, z, w);
5408
+ Object.setPrototypeOf(createQuat, Quat);
5409
+ const quat = createQuat;
5354
5410
 
5355
5411
  /**
5356
5412
  * Dual Quaternion for rigid body transformations (rotation + translation)
@@ -5358,9 +5414,9 @@ const quat = Object.assign((x = 0, y = 0, z = 0, w = 1) => new Quat(x, y, z, w),
5358
5414
  * @extends Float32Array
5359
5415
  */
5360
5416
  class Quat2 extends Float32Array {
5361
- static get identity() { return new Quat2(0, 0, 0, 1, 0, 0, 0, 0); }
5362
- static get Identity() { return new Quat2(0, 0, 0, 1, 0, 0, 0, 0); }
5363
- static get IDENTITY() { return new Quat2(0, 0, 0, 1, 0, 0, 0, 0); }
5417
+ static get identity() { return quat2(0, 0, 0, 1, 0, 0, 0, 0); }
5418
+ static get Identity() { return quat2(0, 0, 0, 1, 0, 0, 0, 0); }
5419
+ static get IDENTITY() { return quat2(0, 0, 0, 1, 0, 0, 0, 0); }
5364
5420
  /**
5365
5421
  * Creates a new dual quaternion
5366
5422
  *
@@ -5379,11 +5435,11 @@ class Quat2 extends Float32Array {
5379
5435
  * Multiply two dual quaternions
5380
5436
  *
5381
5437
  * @param {Quat2} b the second operand
5382
- * @param {Quat2} out the receiving dual quaternion, defaults to this
5438
+ * @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
5383
5439
  * @returns {Quat2} out
5384
5440
  */
5385
5441
  // @ts-ignore
5386
- this.multiply = (b, out = index.ALWAYS_COPY ? new Quat2() : this) => {
5442
+ this.multiply = (b, out = index.ALWAYS_COPY ? quat2() : this) => {
5387
5443
  const ax0 = this[0], ay0 = this[1], az0 = this[2], aw0 = this[3];
5388
5444
  const bx1 = b[4], by1 = b[5], bz1 = b[6], bw1 = b[7];
5389
5445
  const ax1 = this[4], ay1 = this[5], az1 = this[6], aw1 = this[7];
@@ -5485,7 +5541,7 @@ class Quat2 extends Float32Array {
5485
5541
  * @param {Quat2} out the receiving dual quaternion, defaults to quat2()
5486
5542
  * @returns {Quat2} out
5487
5543
  */
5488
- static fromRotationTranslation(q, t, out = new Quat2()) {
5544
+ static fromRotationTranslation(q, t, out = quat2()) {
5489
5545
  const ax = t[0] * 0.5, ay = t[1] * 0.5, az = t[2] * 0.5;
5490
5546
  const bx = q[0], by = q[1], bz = q[2], bw = q[3];
5491
5547
  out[0] = bx;
@@ -5505,7 +5561,7 @@ class Quat2 extends Float32Array {
5505
5561
  * @param {Quat2} out the receiving dual quaternion, defaults to quat2()
5506
5562
  * @returns {Quat2} out
5507
5563
  */
5508
- static fromTranslation(t, out = new Quat2()) {
5564
+ static fromTranslation(t, out = quat2()) {
5509
5565
  out[0] = 0;
5510
5566
  out[1] = 0;
5511
5567
  out[2] = 0;
@@ -5523,7 +5579,7 @@ class Quat2 extends Float32Array {
5523
5579
  * @param {Quat2} out the receiving dual quaternion, defaults to quat2()
5524
5580
  * @returns {Quat2} out
5525
5581
  */
5526
- static fromRotation(q, out = new Quat2()) {
5582
+ static fromRotation(q, out = quat2()) {
5527
5583
  out[0] = q[0];
5528
5584
  out[1] = q[1];
5529
5585
  out[2] = q[2];
@@ -5541,7 +5597,7 @@ class Quat2 extends Float32Array {
5541
5597
  * @param {Quat2} out the receiving dual quaternion, defaults to quat2()
5542
5598
  * @returns {Quat2} out
5543
5599
  */
5544
- static fromMat4(m, out = new Quat2()) {
5600
+ static fromMat4(m, out = quat2()) {
5545
5601
  const r = m.getRotation();
5546
5602
  const t = m.getTranslation();
5547
5603
  return Quat2.fromRotationTranslation(r, t, out);
@@ -5552,16 +5608,16 @@ class Quat2 extends Float32Array {
5552
5608
  * @returns {Quat2} a new dual quaternion
5553
5609
  */
5554
5610
  clone() {
5555
- return new Quat2(this[0], this[1], this[2], this[3], this[4], this[5], this[6], this[7]);
5611
+ return quat2(this[0], this[1], this[2], this[3], this[4], this[5], this[6], this[7]);
5556
5612
  }
5557
5613
  /**
5558
5614
  * Translate by a Vec3
5559
5615
  *
5560
5616
  * @param {Vec3} v the translation vector
5561
- * @param {Quat2} out the receiving dual quaternion, defaults to this
5617
+ * @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
5562
5618
  * @returns {Quat2} out
5563
5619
  */
5564
- translate(v, out = index.ALWAYS_COPY ? new Quat2() : this) {
5620
+ translate(v, out = index.ALWAYS_COPY ? quat2() : this) {
5565
5621
  const ax1 = this[0], ay1 = this[1], az1 = this[2], aw1 = this[3];
5566
5622
  const bx1 = v[0] * 0.5, by1 = v[1] * 0.5, bz1 = v[2] * 0.5;
5567
5623
  const ax2 = this[4], ay2 = this[5], az2 = this[6], aw2 = this[7];
@@ -5578,10 +5634,10 @@ class Quat2 extends Float32Array {
5578
5634
  /**
5579
5635
  * Calculates the conjugate of a dual quaternion
5580
5636
  *
5581
- * @param {Quat2} out the receiving dual quaternion, defaults to this
5637
+ * @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
5582
5638
  * @returns {Quat2} out
5583
5639
  */
5584
- conjugate(out = index.ALWAYS_COPY ? new Quat2() : this) {
5640
+ conjugate(out = index.ALWAYS_COPY ? quat2() : this) {
5585
5641
  out[0] = -this[0];
5586
5642
  out[1] = -this[1];
5587
5643
  out[2] = -this[2];
@@ -5595,10 +5651,10 @@ class Quat2 extends Float32Array {
5595
5651
  /**
5596
5652
  * Calculates the inverse of a dual quaternion
5597
5653
  *
5598
- * @param {Quat2} out the receiving dual quaternion, defaults to this
5654
+ * @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
5599
5655
  * @returns {Quat2} out
5600
5656
  */
5601
- invert(out = index.ALWAYS_COPY ? new Quat2() : this) {
5657
+ invert(out = index.ALWAYS_COPY ? quat2() : this) {
5602
5658
  const sqlen = this.squaredLength();
5603
5659
  out[0] = -this[0] / sqlen;
5604
5660
  out[1] = -this[1] / sqlen;
@@ -5630,16 +5686,17 @@ class Quat2 extends Float32Array {
5630
5686
  /**
5631
5687
  * Normalize the dual quaternion
5632
5688
  *
5633
- * @param {Quat2} out the receiving dual quaternion, defaults to this
5689
+ * @param {Quat2} q the quaternion to normalize
5690
+ * @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
5634
5691
  * @returns {Quat2} out
5635
5692
  */
5636
- normalize(out = index.ALWAYS_COPY ? new Quat2() : this) {
5637
- let magnitude = this.squaredLength();
5693
+ static normalize(q, out = quat2()) {
5694
+ let magnitude = q.squaredLength();
5638
5695
  if (magnitude > 0) {
5639
5696
  magnitude = Math.sqrt(magnitude);
5640
- const a0 = this[0] / magnitude, a1 = this[1] / magnitude;
5641
- const a2 = this[2] / magnitude, a3 = this[3] / magnitude;
5642
- const b0 = this[4], b1 = this[5], b2 = this[6], b3 = this[7];
5697
+ const a0 = q[0] / magnitude, a1 = q[1] / magnitude;
5698
+ const a2 = q[2] / magnitude, a3 = q[3] / magnitude;
5699
+ const b0 = q[4], b1 = q[5], b2 = q[6], b3 = q[7];
5643
5700
  const a_dot_b = a0 * b0 + a1 * b1 + a2 * b2 + a3 * b3;
5644
5701
  out[0] = a0;
5645
5702
  out[1] = a1;
@@ -5652,6 +5709,15 @@ class Quat2 extends Float32Array {
5652
5709
  }
5653
5710
  return out;
5654
5711
  }
5712
+ /**
5713
+ * Normalize the dual quaternion
5714
+ *
5715
+ * @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
5716
+ * @returns {Quat2} out
5717
+ */
5718
+ normalize(out = index.ALWAYS_COPY ? quat2() : this) {
5719
+ return Quat2.normalize(this, out);
5720
+ }
5655
5721
  /**
5656
5722
  * Dot product of the real parts of two dual quaternions
5657
5723
  *
@@ -5671,7 +5737,7 @@ class Quat2 extends Float32Array {
5671
5737
  * @param {Quat2} out the receiving dual quaternion, defaults to quat2()
5672
5738
  * @returns {Quat2} out
5673
5739
  */
5674
- static lerp(a, b, t, out = new Quat2()) {
5740
+ static lerp(a, b, t, out = quat2()) {
5675
5741
  const mt = 1 - t;
5676
5742
  if (Quat2.dot(a, b) < 0)
5677
5743
  t = -t;
@@ -5689,10 +5755,10 @@ class Quat2 extends Float32Array {
5689
5755
  * Adds two dual quaternions
5690
5756
  *
5691
5757
  * @param {Quat2} b the second operand
5692
- * @param {Quat2} out the receiving dual quaternion, defaults to this
5758
+ * @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
5693
5759
  * @returns {Quat2} out
5694
5760
  */
5695
- plus(b, out = index.ALWAYS_COPY ? new Quat2() : this) {
5761
+ plus(b, out = index.ALWAYS_COPY ? quat2() : this) {
5696
5762
  out[0] = this[0] + b[0];
5697
5763
  out[1] = this[1] + b[1];
5698
5764
  out[2] = this[2] + b[2];
@@ -5707,10 +5773,10 @@ class Quat2 extends Float32Array {
5707
5773
  * Scales a dual quaternion by a scalar
5708
5774
  *
5709
5775
  * @param {Number} s the scalar to scale by
5710
- * @param {Quat2} out the receiving dual quaternion, defaults to this
5776
+ * @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
5711
5777
  * @returns {Quat2} out
5712
5778
  */
5713
- scale(s, out = index.ALWAYS_COPY ? new Quat2() : this) {
5779
+ scale(s, out = index.ALWAYS_COPY ? quat2() : this) {
5714
5780
  out[0] = this[0] * s;
5715
5781
  out[1] = this[1] * s;
5716
5782
  out[2] = this[2] * s;
@@ -5772,17 +5838,20 @@ class Quat2 extends Float32Array {
5772
5838
  }
5773
5839
  // @aliases
5774
5840
  Quat2.prototype.sqrLen = Quat2.prototype.squaredLength;
5841
+ Quat2.prototype.normalized = Quat2.prototype.normalize;
5775
5842
  Quat2.prototype.str = Quat2.prototype.toString;
5776
5843
  Quat2.prototype.add = Quat2.prototype.plus;
5777
- const quat2 = Object.assign((x1 = 0, y1 = 0, z1 = 0, w1 = 1, x2 = 0, y2 = 0, z2 = 0, w2 = 0) => new Quat2(x1, y1, z1, w1, x2, y2, z2, w2), Quat2);
5844
+ const createQuat2 = (x1 = 0, y1 = 0, z1 = 0, w1 = 1, x2 = 0, y2 = 0, z2 = 0, w2 = 0) => new Quat2(x1, y1, z1, w1, x2, y2, z2, w2);
5845
+ Object.setPrototypeOf(createQuat2, Quat2);
5846
+ const quat2 = createQuat2;
5778
5847
 
5779
5848
  /** 2x2 Matrix in column-major order
5780
5849
  * @extends Float32Array
5781
5850
  */
5782
5851
  class Mat2 extends Float32Array {
5783
- static get identity() { return new Mat2(1, 0, 0, 1); }
5784
- static get Identity() { return new Mat2(1, 0, 0, 1); }
5785
- static get IDENTITY() { return new Mat2(1, 0, 0, 1); }
5852
+ static get identity() { return mat2(1, 0, 0, 1); }
5853
+ static get Identity() { return mat2(1, 0, 0, 1); }
5854
+ static get IDENTITY() { return mat2(1, 0, 0, 1); }
5786
5855
  /**
5787
5856
  * Creates a new Mat2
5788
5857
  *
@@ -5804,15 +5873,15 @@ class Mat2 extends Float32Array {
5804
5873
  * @returns {Mat2} a new Mat2
5805
5874
  */
5806
5875
  clone() {
5807
- return new Mat2(this[0], this[1], this[2], this[3]);
5876
+ return mat2(this[0], this[1], this[2], this[3]);
5808
5877
  }
5809
5878
  /**
5810
5879
  * Transposes a mat2
5811
5880
  *
5812
- * @param {Mat2} out the receiving matrix, defaults to this
5881
+ * @param {Mat2} out the receiving matrix, defaults to new mat2()
5813
5882
  * @returns {Mat2} out
5814
5883
  */
5815
- transpose(out = index.ALWAYS_COPY ? new Mat2() : this) {
5884
+ transpose(out = index.ALWAYS_COPY ? mat2() : this) {
5816
5885
  if (out.exactEquals(this)) {
5817
5886
  const tmp = out[1];
5818
5887
  out[1] = out[2];
@@ -5829,10 +5898,10 @@ class Mat2 extends Float32Array {
5829
5898
  /**
5830
5899
  * Inverts a mat2
5831
5900
  *
5832
- * @param {Mat2} out the receiving matrix, defaults to this
5901
+ * @param {Mat2} out the receiving matrix, defaults to new mat2()
5833
5902
  * @returns {Mat2} out or null if the matrix is not invertible
5834
5903
  */
5835
- invert(out = index.ALWAYS_COPY ? new Mat2() : this) {
5904
+ invert(out = index.ALWAYS_COPY ? mat2() : this) {
5836
5905
  const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3];
5837
5906
  // Calculate the determinant
5838
5907
  let det = a0 * a3 - a2 * a1;
@@ -5848,10 +5917,10 @@ class Mat2 extends Float32Array {
5848
5917
  /**
5849
5918
  * Calculates the adjugate of a mat2
5850
5919
  *
5851
- * @param {Mat2} out the receiving matrix, defaults to this
5920
+ * @param {Mat2} out the receiving matrix, defaults to new mat2()
5852
5921
  * @returns {Mat2} out
5853
5922
  */
5854
- adjoint(out = index.ALWAYS_COPY ? new Mat2() : this) {
5923
+ adjoint(out = index.ALWAYS_COPY ? mat2() : this) {
5855
5924
  let a0 = this[0];
5856
5925
  out[0] = this[3];
5857
5926
  out[1] = -this[1];
@@ -5871,10 +5940,10 @@ class Mat2 extends Float32Array {
5871
5940
  * Rotates a mat2 by the given angle
5872
5941
  *
5873
5942
  * @param {Number} rad the angle to rotate the matrix by
5874
- * @param {Mat2} out the receiving matrix, defaults to this
5943
+ * @param {Mat2} out the receiving matrix, defaults to new mat2()
5875
5944
  * @returns {Mat2} out
5876
5945
  */
5877
- rotate(rad, out = index.ALWAYS_COPY ? new Mat2() : this) {
5946
+ rotate(rad, out = index.ALWAYS_COPY ? mat2() : this) {
5878
5947
  const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3];
5879
5948
  const s = Math.sin(rad), c = Math.cos(rad);
5880
5949
  out[0] = a0 * c + a2 * s;
@@ -5887,10 +5956,10 @@ class Mat2 extends Float32Array {
5887
5956
  * Scales a mat2 by the dimensions in the given Vec2
5888
5957
  *
5889
5958
  * @param {Vec2} v the Vec2 to scale the matrix by
5890
- * @param {Mat2} out the receiving matrix, defaults to this
5959
+ * @param {Mat2} out the receiving matrix, defaults to new mat2()
5891
5960
  * @returns {Mat2} out
5892
5961
  */
5893
- scale(v, out = index.ALWAYS_COPY ? new Mat2() : this) {
5962
+ scale(v, out = index.ALWAYS_COPY ? mat2() : this) {
5894
5963
  const v0 = v[0], v1 = v[1];
5895
5964
  out[0] = this[0] * v0;
5896
5965
  out[1] = this[1] * v0;
@@ -5902,10 +5971,10 @@ class Mat2 extends Float32Array {
5902
5971
  * Creates a Mat2 from a given angle
5903
5972
  *
5904
5973
  * @param {Number} rad the angle to rotate the matrix by
5905
- * @param {Mat2} out the receiving matrix, defaults to new Mat2()
5974
+ * @param {Mat2} out the receiving matrix, defaults to mat2()
5906
5975
  * @returns {Mat2} out
5907
5976
  */
5908
- static fromRotation(rad, out = new Mat2()) {
5977
+ static fromRotation(rad, out = mat2()) {
5909
5978
  const s = Math.sin(rad), c = Math.cos(rad);
5910
5979
  out[0] = c;
5911
5980
  out[1] = s;
@@ -5917,10 +5986,10 @@ class Mat2 extends Float32Array {
5917
5986
  * Creates a Mat2 from a scaling vector
5918
5987
  *
5919
5988
  * @param {Vec2} v scaling vector
5920
- * @param {Mat2} out the receiving matrix, defaults to new Mat2()
5989
+ * @param {Mat2} out the receiving matrix, defaults to mat2()
5921
5990
  * @returns {Mat2} out
5922
5991
  */
5923
- static fromScaling(v, out = new Mat2()) {
5992
+ static fromScaling(v, out = mat2()) {
5924
5993
  out[0] = v[0];
5925
5994
  out[1] = out[2] = 0;
5926
5995
  out[3] = v[1];
@@ -5948,7 +6017,7 @@ class Mat2 extends Float32Array {
5948
6017
  * @param {Mat2} D the diagonal matrix
5949
6018
  * @param {Mat2} U the upper triangular matrix
5950
6019
  */
5951
- LDU(L = new Mat2(), D = new Mat2(), U = new Mat2()) {
6020
+ LDU(L = mat2(), D = mat2(), U = mat2()) {
5952
6021
  L[2] = this[2] / this[0];
5953
6022
  U[0] = this[0];
5954
6023
  U[1] = this[1];
@@ -5959,10 +6028,10 @@ class Mat2 extends Float32Array {
5959
6028
  * Adds two Mat2's
5960
6029
  *
5961
6030
  * @param {Mat2} b the second operand
5962
- * @param {Mat2} out the receiving matrix, defaults to this
6031
+ * @param {Mat2} out the receiving matrix, defaults to new mat2()
5963
6032
  * @returns {Mat2} out
5964
6033
  */
5965
- plus(b, out = index.ALWAYS_COPY ? new Mat2() : this) {
6034
+ plus(b, out = index.ALWAYS_COPY ? mat2() : this) {
5966
6035
  out[0] = this[0] + b[0];
5967
6036
  out[1] = this[1] + b[1];
5968
6037
  out[2] = this[2] + b[2];
@@ -5973,17 +6042,17 @@ class Mat2 extends Float32Array {
5973
6042
  * Subtracts matrix b from a mat2
5974
6043
  *
5975
6044
  * @param {Mat2} b the second operand
5976
- * @param {Mat2} out the receiving matrix, defaults to this
6045
+ * @param {Mat2} out the receiving matrix, defaults to new mat2()
5977
6046
  * @returns {Mat2} out
5978
6047
  */
5979
- minus(b, out = index.ALWAYS_COPY ? new Mat2() : this) {
6048
+ minus(b, out = index.ALWAYS_COPY ? mat2() : this) {
5980
6049
  out[0] = this[0] - b[0];
5981
6050
  out[1] = this[1] - b[1];
5982
6051
  out[2] = this[2] - b[2];
5983
6052
  out[3] = this[3] - b[3];
5984
6053
  return out;
5985
6054
  }
5986
- multiply(b, out = index.ALWAYS_COPY ? new Mat2() : this) {
6055
+ multiply(b, out = index.ALWAYS_COPY ? mat2() : this) {
5987
6056
  if (b instanceof Vec2)
5988
6057
  return b.transformMat2(this);
5989
6058
  const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3];
@@ -6017,10 +6086,10 @@ class Mat2 extends Float32Array {
6017
6086
  * Multiplies each element of a mat2 by a scalar value
6018
6087
  *
6019
6088
  * @param {Number} b amount to scale the matrix's elements by
6020
- * @param {Mat2} out the receiving matrix, defaults to this
6089
+ * @param {Mat2} out the receiving matrix, defaults to new mat2()
6021
6090
  * @returns {Mat2} out
6022
6091
  */
6023
- scaleScalar(b, out = index.ALWAYS_COPY ? new Mat2() : this) {
6092
+ scaleScalar(b, out = index.ALWAYS_COPY ? mat2() : this) {
6024
6093
  out[0] = this[0] * b;
6025
6094
  out[1] = this[1] * b;
6026
6095
  out[2] = this[2] * b;
@@ -6057,9 +6126,9 @@ const mat2x2 = mat2;
6057
6126
  * @extends Float32Array
6058
6127
  */
6059
6128
  class Mat2x3 extends Float32Array {
6060
- static get identity() { return new Mat2x3(1, 0, 0, 1, 0, 0); }
6061
- static get Identity() { return new Mat2x3(1, 0, 0, 1, 0, 0); }
6062
- static get IDENTITY() { return new Mat2x3(1, 0, 0, 1, 0, 0); }
6129
+ static get identity() { return mat2x3(1, 0, 0, 1, 0, 0); }
6130
+ static get Identity() { return mat2x3(1, 0, 0, 1, 0, 0); }
6131
+ static get IDENTITY() { return mat2x3(1, 0, 0, 1, 0, 0); }
6063
6132
  /**
6064
6133
  * Creates a new Mat2x3
6065
6134
  *
@@ -6082,10 +6151,10 @@ class Mat2x3 extends Float32Array {
6082
6151
  /**
6083
6152
  * Inverts a mat2x3
6084
6153
  *
6085
- * @param {Mat2x3} out the receiving matrix, defaults to this
6154
+ * @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
6086
6155
  * @returns {Mat2x3} out or null if the matrix is not invertible
6087
6156
  */
6088
- invert(out = index.ALWAYS_COPY ? new Mat2x3() : this) {
6157
+ invert(out = index.ALWAYS_COPY ? mat2x3() : this) {
6089
6158
  const aa = this[0], ab = this[1], ac = this[2], ad = this[3];
6090
6159
  const atx = this[4], aty = this[5];
6091
6160
  let det = aa * ad - ab * ac;
@@ -6112,10 +6181,10 @@ class Mat2x3 extends Float32Array {
6112
6181
  * Rotates a mat2x3 by the given angle
6113
6182
  *
6114
6183
  * @param {Number} rad the angle to rotate the matrix by
6115
- * @param {Mat2x3} out the receiving matrix, defaults to this
6184
+ * @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
6116
6185
  * @returns {Mat2x3} out
6117
6186
  */
6118
- rotate(rad, out = index.ALWAYS_COPY ? new Mat2x3() : this) {
6187
+ rotate(rad, out = index.ALWAYS_COPY ? mat2x3() : this) {
6119
6188
  const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3], a4 = this[4], a5 = this[5];
6120
6189
  const s = Math.sin(rad);
6121
6190
  const c = Math.cos(rad);
@@ -6131,10 +6200,10 @@ class Mat2x3 extends Float32Array {
6131
6200
  * Scales a mat2x3 by the dimensions in the given Vec2
6132
6201
  *
6133
6202
  * @param {Vec2} v the Vec2 to scale the matrix by
6134
- * @param {Mat2x3} out the receiving matrix, defaults to this
6203
+ * @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
6135
6204
  * @returns {Mat2x3} out
6136
6205
  */
6137
- scale(v, out = index.ALWAYS_COPY ? new Mat2x3() : this) {
6206
+ scale(v, out = index.ALWAYS_COPY ? mat2x3() : this) {
6138
6207
  const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3], a4 = this[4], a5 = this[5];
6139
6208
  const v0 = v[0], v1 = v[1];
6140
6209
  out[0] = a0 * v0;
@@ -6149,10 +6218,10 @@ class Mat2x3 extends Float32Array {
6149
6218
  * Translates a mat2x3 by the dimensions in the given Vec2
6150
6219
  *
6151
6220
  * @param {Vec2} v the Vec2 to translate the matrix by
6152
- * @param {Mat2x3} out the receiving matrix, defaults to this
6221
+ * @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
6153
6222
  * @returns {Mat2x3} out
6154
6223
  */
6155
- translate(v, out = index.ALWAYS_COPY ? new Mat2x3() : this) {
6224
+ translate(v, out = index.ALWAYS_COPY ? mat2x3() : this) {
6156
6225
  const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3], a4 = this[4], a5 = this[5];
6157
6226
  const v0 = v[0], v1 = v[1];
6158
6227
  out[0] = a0;
@@ -6167,10 +6236,10 @@ class Mat2x3 extends Float32Array {
6167
6236
  * Creates a Mat2x3 from a given angle
6168
6237
  *
6169
6238
  * @param {Number} rad the angle to rotate the matrix by
6170
- * @param {Mat2x3} out the receiving matrix, defaults to new Mat2x3()
6239
+ * @param {Mat2x3} out the receiving matrix, defaults to mat2x3()
6171
6240
  * @returns {Mat2x3} out
6172
6241
  */
6173
- static fromRotation(rad, out = new Mat2x3()) {
6242
+ static fromRotation(rad, out = mat2x3()) {
6174
6243
  const s = Math.sin(rad), c = Math.cos(rad);
6175
6244
  out[0] = c;
6176
6245
  out[1] = s;
@@ -6183,10 +6252,10 @@ class Mat2x3 extends Float32Array {
6183
6252
  * Creates a Mat2x3 from a scaling vector
6184
6253
  *
6185
6254
  * @param {Vec2} v scaling vector
6186
- * @param {Mat2x3} out the receiving matrix, defaults to new Mat2x3()
6255
+ * @param {Mat2x3} out the receiving matrix, defaults to mat2x3()
6187
6256
  * @returns {Mat2x3} out
6188
6257
  */
6189
- static fromScaling(v, out = new Mat2x3()) {
6258
+ static fromScaling(v, out = mat2x3()) {
6190
6259
  out[0] = v[0];
6191
6260
  out[1] = out[2] = 0;
6192
6261
  out[3] = v[1];
@@ -6197,10 +6266,10 @@ class Mat2x3 extends Float32Array {
6197
6266
  * Creates a Mat2x3 from a translation vector
6198
6267
  *
6199
6268
  * @param {Vec2} v translation vector
6200
- * @param {Mat2x3} out the receiving matrix, defaults to new Mat2x3()
6269
+ * @param {Mat2x3} out the receiving matrix, defaults to mat2x3()
6201
6270
  * @returns {Mat2x3} out
6202
6271
  */
6203
- static fromTranslation(v, out = new Mat2x3()) {
6272
+ static fromTranslation(v, out = mat2x3()) {
6204
6273
  out[0] = out[3] = 1;
6205
6274
  out[1] = out[2] = 0;
6206
6275
  out[4] = v[0];
@@ -6227,10 +6296,10 @@ class Mat2x3 extends Float32Array {
6227
6296
  * Adds two Mat2x3's
6228
6297
  *
6229
6298
  * @param {Mat2x3} b the second operand
6230
- * @param {Mat2x3} out the receiving matrix, defaults to this
6299
+ * @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
6231
6300
  * @returns {Mat2x3} out
6232
6301
  */
6233
- plus(b, out = index.ALWAYS_COPY ? new Mat2x3() : this) {
6302
+ plus(b, out = index.ALWAYS_COPY ? mat2x3() : this) {
6234
6303
  out[0] = this[0] + b[0];
6235
6304
  out[1] = this[1] + b[1];
6236
6305
  out[2] = this[2] + b[2];
@@ -6243,10 +6312,10 @@ class Mat2x3 extends Float32Array {
6243
6312
  * Subtracts matrix b from a mat2x3
6244
6313
  *
6245
6314
  * @param {Mat2x3} b the second operand
6246
- * @param {Mat2x3} out the receiving matrix, defaults to this
6315
+ * @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
6247
6316
  * @returns {Mat2x3} out
6248
6317
  */
6249
- minus(b, out = index.ALWAYS_COPY ? new Mat2x3() : this) {
6318
+ minus(b, out = index.ALWAYS_COPY ? mat2x3() : this) {
6250
6319
  out[0] = this[0] - b[0];
6251
6320
  out[1] = this[1] - b[1];
6252
6321
  out[2] = this[2] - b[2];
@@ -6255,7 +6324,7 @@ class Mat2x3 extends Float32Array {
6255
6324
  out[5] = this[5] - b[5];
6256
6325
  return out;
6257
6326
  }
6258
- multiply(b, out = index.ALWAYS_COPY ? new Mat2x3() : this) {
6327
+ multiply(b, out = index.ALWAYS_COPY ? mat2x3() : this) {
6259
6328
  if (b instanceof Vec2)
6260
6329
  return b.transformMat2x3(this);
6261
6330
  const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3], a4 = this[4], a5 = this[5];
@@ -6292,10 +6361,10 @@ class Mat2x3 extends Float32Array {
6292
6361
  * Multiplies each element of a mat2x3 by a scalar value
6293
6362
  *
6294
6363
  * @param {Number} b amount to scale the matrix's elements by
6295
- * @param {Mat2x3} out the receiving matrix, defaults to this
6364
+ * @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
6296
6365
  * @returns {Mat2x3} out
6297
6366
  */
6298
- scaleScalar(b, out = index.ALWAYS_COPY ? new Mat2x3() : this) {
6367
+ scaleScalar(b, out = index.ALWAYS_COPY ? mat2x3() : this) {
6299
6368
  out[0] = this[0] * b;
6300
6369
  out[1] = this[1] * b;
6301
6370
  out[2] = this[2] * b;
@@ -6310,7 +6379,7 @@ class Mat2x3 extends Float32Array {
6310
6379
  * @returns {Mat2x3} a new Mat2x3
6311
6380
  */
6312
6381
  clone() {
6313
- return new Mat2x3(this[0], this[1], this[2], this[3], this[4], this[5]);
6382
+ return mat2x3(this[0], this[1], this[2], this[3], this[4], this[5]);
6314
6383
  }
6315
6384
  }
6316
6385
  // @aliases
@@ -6322,7 +6391,20 @@ Mat2x3.prototype.mult = Mat2x3.prototype.multiply;
6322
6391
  Mat2x3.prototype.times = Mat2x3.prototype.multiply;
6323
6392
  Mat2x3.prototype.str = Mat2x3.prototype.toString;
6324
6393
  Mat2x3.prototype.multiplyScalar = Mat2x3.prototype.scaleScalar;
6325
- const mat2x3 = Object.assign((a = 0, b = 0, c = 0, d = 0, tx = 0, ty = 0) => new Mat2x3(a, b, c, d, tx, ty), Mat2x3);
6394
+ const createMat2x3 = (...args) => {
6395
+ const out = new Mat2x3();
6396
+ let i = 0;
6397
+ for (const a of args) {
6398
+ if (typeof a === 'number')
6399
+ out[i++] = a;
6400
+ else
6401
+ for (const v of a)
6402
+ out[i++] = v;
6403
+ }
6404
+ return out;
6405
+ };
6406
+ Object.setPrototypeOf(createMat2x3, Mat2x3);
6407
+ const mat2x3 = createMat2x3;
6326
6408
  const mat2d = mat2x3;
6327
6409
 
6328
6410
  function makeArr(a) {