@limitlesspc/std 0.20.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/dist/array.d.ts +209 -0
  4. package/dist/array.js +41 -0
  5. package/dist/async/index.d.ts +48 -0
  6. package/dist/async/index.js +155 -0
  7. package/dist/bytes.d.ts +38 -0
  8. package/dist/bytes.js +35 -0
  9. package/dist/chunk-6F4PWJZI.js +0 -0
  10. package/dist/chunk-C2DS6YRJ.js +1664 -0
  11. package/dist/chunk-DO4NH5XG.js +523 -0
  12. package/dist/chunk-EWSJTMH2.js +68 -0
  13. package/dist/chunk-ILLWUQPY.js +139 -0
  14. package/dist/chunk-LJSF3QBT.js +122 -0
  15. package/dist/chunk-MG5VQSTV.js +89 -0
  16. package/dist/chunk-TMLWLR46.js +12 -0
  17. package/dist/chunk-WBSY6KRH.js +358 -0
  18. package/dist/cmath/index.d.ts +57 -0
  19. package/dist/cmath/index.js +187 -0
  20. package/dist/cmp.d.ts +11 -0
  21. package/dist/cmp.js +12 -0
  22. package/dist/csv.d.ts +3 -0
  23. package/dist/csv.js +16 -0
  24. package/dist/easing.d.ts +37 -0
  25. package/dist/easing.js +157 -0
  26. package/dist/events.d.ts +20 -0
  27. package/dist/events.js +67 -0
  28. package/dist/fn/index.d.ts +66 -0
  29. package/dist/fn/index.js +25 -0
  30. package/dist/gfx/index.d.ts +13 -0
  31. package/dist/gfx/index.js +68 -0
  32. package/dist/iter/index.d.ts +226 -0
  33. package/dist/iter/index.js +65 -0
  34. package/dist/math/index.d.ts +463 -0
  35. package/dist/math/index.js +129 -0
  36. package/dist/object.d.ts +72 -0
  37. package/dist/object.js +24 -0
  38. package/dist/random.d.ts +68 -0
  39. package/dist/random.js +22 -0
  40. package/dist/string/index.d.ts +62 -0
  41. package/dist/string/index.js +98 -0
  42. package/dist/structs/index.d.ts +184 -0
  43. package/dist/structs/index.js +24 -0
  44. package/dist/time/index.d.ts +35 -0
  45. package/dist/time/index.js +84 -0
  46. package/dist/types.d.ts +21 -0
  47. package/dist/types.js +1 -0
  48. package/dist/vec3-D7Wuy2AZ.d.ts +70 -0
  49. package/package.json +111 -0
@@ -0,0 +1,1664 @@
1
+ import {
2
+ random
3
+ } from "./chunk-EWSJTMH2.js";
4
+ import {
5
+ chunk,
6
+ collect,
7
+ filter,
8
+ map,
9
+ range,
10
+ tee
11
+ } from "./chunk-WBSY6KRH.js";
12
+ import {
13
+ pipe,
14
+ reverseCurry
15
+ } from "./chunk-MG5VQSTV.js";
16
+
17
+ // src/math/stats.ts
18
+ function min(iter) {
19
+ let min2 = Number.POSITIVE_INFINITY;
20
+ for (const value of iter) {
21
+ if (value < min2) {
22
+ min2 = value;
23
+ }
24
+ }
25
+ return min2;
26
+ }
27
+ function max(iter) {
28
+ let max2 = Number.NEGATIVE_INFINITY;
29
+ for (const value of iter) {
30
+ if (value > max2) {
31
+ max2 = value;
32
+ }
33
+ }
34
+ return max2;
35
+ }
36
+ function minmax(iter) {
37
+ let min2 = Number.POSITIVE_INFINITY;
38
+ let max2 = Number.NEGATIVE_INFINITY;
39
+ for (const value of iter) {
40
+ if (value < min2) {
41
+ min2 = value;
42
+ }
43
+ if (value > max2) {
44
+ max2 = value;
45
+ }
46
+ }
47
+ return [min2, max2];
48
+ }
49
+ function sum(iter) {
50
+ let total = 0;
51
+ for (const value of iter) {
52
+ total += value;
53
+ }
54
+ return total;
55
+ }
56
+ function product(iter) {
57
+ let total = 1;
58
+ for (const value of iter) {
59
+ total *= value;
60
+ }
61
+ return total;
62
+ }
63
+ function avg(iter) {
64
+ let total = 0;
65
+ let count = 0;
66
+ for (const value of iter) {
67
+ total += value;
68
+ count++;
69
+ }
70
+ return total / count;
71
+ }
72
+ function median(array) {
73
+ const { length } = array;
74
+ if (!length) {
75
+ return 0;
76
+ }
77
+ const sorted = [...array].sort((a, b) => a - b);
78
+ if (length % 2) {
79
+ return sorted[length / 2];
80
+ }
81
+ return (sorted[length / 2 - 1] + sorted[length / 2]) / 2;
82
+ }
83
+ function mode(iter) {
84
+ const counts = /* @__PURE__ */ new Map();
85
+ for (const n of iter) {
86
+ const count = counts.get(n) || 0;
87
+ counts.set(n, count + 1);
88
+ }
89
+ const maxCount = max(counts.values());
90
+ return pipe(
91
+ counts,
92
+ filter(([_, count]) => count === maxCount),
93
+ map(([n]) => n),
94
+ collect
95
+ );
96
+ }
97
+ function variance(iter) {
98
+ const [a, b] = tee(iter);
99
+ const m = avg(a);
100
+ return avg(
101
+ map(b, (n) => {
102
+ const d = n - m;
103
+ return d * d;
104
+ })
105
+ );
106
+ }
107
+ function stddev(iter) {
108
+ return Math.sqrt(variance(iter));
109
+ }
110
+ function meanAbsDev(iter) {
111
+ const [a, b] = tee(iter);
112
+ const m = avg(a);
113
+ return avg(map(b, (n) => n - m));
114
+ }
115
+
116
+ // src/math/funcs.ts
117
+ function isNumber(x) {
118
+ return typeof x === "number" && !Number.isNaN(x);
119
+ }
120
+ function isReal(x) {
121
+ return isNumber(x) && Number.isFinite(x);
122
+ }
123
+ function isInteger(x) {
124
+ return Number.isInteger(x);
125
+ }
126
+ function roundToMultiple(x, n) {
127
+ return Math.floor(x / n) * n;
128
+ }
129
+ function roundToEven(x) {
130
+ return roundToMultiple(x, 2);
131
+ }
132
+ function norm(x, min2, max2) {
133
+ return (x - min2) / (max2 - min2);
134
+ }
135
+ function lerp(min2, max2, norm2) {
136
+ return min2 + (max2 - min2) * norm2;
137
+ }
138
+ function map2(x, fromMin, fromMax, toMin, toMax) {
139
+ return lerp(toMin, toMax, norm(x, fromMin, fromMax));
140
+ }
141
+ function step(x, edge = 0) {
142
+ return x < edge ? 0 : 1;
143
+ }
144
+ function smoothstep(x, min2, max2) {
145
+ x = clamp(norm(x, min2, max2), 0, 1);
146
+ return x * x * (3 - 2 * x);
147
+ }
148
+ function smootherstep(x, min2, max2) {
149
+ x = clamp(norm(x, min2, max2), 0, 1);
150
+ return x * x * x * (x * (x * 6 - 15) + 10);
151
+ }
152
+ function clamp(n, min2, max2) {
153
+ return Math.min(Math.max(n, min2), max2);
154
+ }
155
+ function overlap(min1, max1, min2, max2) {
156
+ [min1, max1] = minmax([min1, max1]);
157
+ [min2, max2] = minmax([min2, max2]);
158
+ const range1 = max1 - min1;
159
+ const range2 = max2 - min2;
160
+ const range3 = Math.max(max1, max2) - Math.min(min1, min2);
161
+ return range1 + range2 - range3;
162
+ }
163
+ function closer(x, a, b) {
164
+ return Math.abs(x - a[0]) < Math.abs(x - b[0]) ? a[1] : b[1];
165
+ }
166
+ function round(n, precision = 0) {
167
+ const factor = 10 ** precision;
168
+ return Math.round(n * factor) / factor;
169
+ }
170
+ function floor(n, precision = 0) {
171
+ const factor = 10 ** precision;
172
+ return Math.floor(n * factor) / factor;
173
+ }
174
+ function ceil(n, precision = 0) {
175
+ const factor = 10 ** precision;
176
+ return Math.ceil(n * factor) / factor;
177
+ }
178
+ function trunc(n, precision = 0) {
179
+ const factor = 10 ** precision;
180
+ return Math.trunc(n * factor) / factor;
181
+ }
182
+ function fract(x) {
183
+ return x - Math.floor(x);
184
+ }
185
+ function closeTo(n, target, precision = 5) {
186
+ return Math.abs(n - target) < 10 ** -precision;
187
+ }
188
+ function factorial(n) {
189
+ let total = 1;
190
+ for (let i = n; i > 1; i--) {
191
+ total *= i;
192
+ }
193
+ return total;
194
+ }
195
+ function log(base, x) {
196
+ return Math.log(x) / Math.log(base);
197
+ }
198
+ var ln = Math.log;
199
+ function gcd(a, b) {
200
+ while (b) {
201
+ const temp = b;
202
+ b = a % b;
203
+ a = temp;
204
+ }
205
+ return a;
206
+ }
207
+ function fibonacci(n) {
208
+ let a = 0;
209
+ let b = 1;
210
+ for (let i = 0; i < n; i++) {
211
+ const temp = a;
212
+ a = b;
213
+ b += temp;
214
+ }
215
+ return a;
216
+ }
217
+ var celsius = (fahrenheit2) => (fahrenheit2 - 32) * (5 / 9);
218
+ var fahrenheit = (celsius2) => celsius2 * (9 / 5) + 32;
219
+ function lineOfBestFit(points) {
220
+ const xs = points.map((p) => p.x);
221
+ const ys = points.map((p) => p.y);
222
+ const meanX = avg(xs);
223
+ const meanY = avg(ys);
224
+ let n = 0;
225
+ let den = 0;
226
+ for (let i = 0; i < points.length; i++) {
227
+ const x = xs[i];
228
+ const y = ys[i];
229
+ n += (x - meanX) * (y - meanY);
230
+ den += (x - meanX) ** 2;
231
+ }
232
+ const m = n / den;
233
+ const b = meanY - m * meanX;
234
+ return [m, b];
235
+ }
236
+ function permutations(n, k) {
237
+ if (k > n) {
238
+ return 0;
239
+ }
240
+ return factorial(n) / factorial(n - k);
241
+ }
242
+ function combinations(n, k) {
243
+ if (k > n) {
244
+ return 0;
245
+ }
246
+ return permutations(n, k) / factorial(k);
247
+ }
248
+ function dot(a, b) {
249
+ const iter1 = a[Symbol.iterator]();
250
+ const iter2 = b[Symbol.iterator]();
251
+ let total = 0;
252
+ while (true) {
253
+ const result1 = iter1.next();
254
+ const result2 = iter2.next();
255
+ if (result1.done && result2.done) {
256
+ break;
257
+ }
258
+ total += (result1.value || 0) * (result2.value || 0);
259
+ }
260
+ return total;
261
+ }
262
+
263
+ // src/iter/repeat.ts
264
+ var repeat = reverseCurry(function* repeat2(iter, n) {
265
+ const values = [];
266
+ for (const i of range(n)) {
267
+ if (i) {
268
+ for (const value of values) {
269
+ yield value;
270
+ }
271
+ } else {
272
+ for (const value of iter) {
273
+ yield value;
274
+ values.push(value);
275
+ }
276
+ }
277
+ }
278
+ });
279
+
280
+ // src/math/matrix/mat.ts
281
+ var Mat = class _Mat extends Float32Array {
282
+ rows;
283
+ constructor(rows, cols = 0) {
284
+ if (typeof rows === "number") {
285
+ super(repeat([0], rows * cols));
286
+ this.rows = rows;
287
+ } else {
288
+ super(rows.flat());
289
+ this.rows = rows.length;
290
+ }
291
+ }
292
+ get cols() {
293
+ return this.length / this.rows;
294
+ }
295
+ toString() {
296
+ return `mat [
297
+ ${pipe(this, chunk(this.cols), collect).map((row) => row.join(" ")).join("\n ")}
298
+ ]`;
299
+ }
300
+ copy() {
301
+ const m = mat(this.rows, this.cols);
302
+ m.set(this);
303
+ return m;
304
+ }
305
+ static random(rows, cols) {
306
+ const m = mat(rows, cols);
307
+ for (let i = 0, { length } = this; i < length; i++) {
308
+ m[i] = random(-1, 1);
309
+ }
310
+ return m;
311
+ }
312
+ eq(m, precision) {
313
+ if (this.rows !== m.rows || this.cols !== m.cols) {
314
+ return false;
315
+ }
316
+ for (let i = 0, { length } = this; i < length; i++) {
317
+ const a = this[i];
318
+ const b = m[i];
319
+ if (!closeTo(a, b, precision)) {
320
+ return false;
321
+ }
322
+ }
323
+ return true;
324
+ }
325
+ add(m) {
326
+ if (this.rows !== m.rows || this.cols !== m.cols) {
327
+ return this;
328
+ }
329
+ for (let i = 0, { length } = this; i < length; i++) {
330
+ this[i] += m[i] || 0;
331
+ }
332
+ return this;
333
+ }
334
+ static add(m1, m2) {
335
+ return m1.copy().add(m2);
336
+ }
337
+ sub(m) {
338
+ if (this.rows !== m.rows || this.cols !== m.cols) {
339
+ return this;
340
+ }
341
+ for (let i = 0, { length } = this; i < length; i++) {
342
+ this[i] -= m[i] || 0;
343
+ }
344
+ return this;
345
+ }
346
+ static sub(m1, m2) {
347
+ return m1.copy().sub(m2);
348
+ }
349
+ mul(m) {
350
+ this.set(_Mat.mul(this, m));
351
+ return this;
352
+ }
353
+ static mul(m1, m2) {
354
+ if (typeof m2 === "number") {
355
+ const { rows: rows2, cols: cols2 } = m1;
356
+ const ans2 = mat(rows2, cols2);
357
+ for (let i = 0, { length } = m1; i < length; i++) {
358
+ ans2[i] = (m1[i] ?? 1) * m2;
359
+ }
360
+ return ans2;
361
+ }
362
+ const ans = mat(m1.rows, m2.cols);
363
+ const { rows, cols } = ans;
364
+ for (let i = 0; i < rows; i++) {
365
+ for (let j = 0; j < cols; j++) {
366
+ let sum2 = 0;
367
+ for (let k = 0; k < m1.cols; k++) {
368
+ sum2 += (m1[i * m1.cols + k] ?? 1) * (m2[k * m2.cols + j] ?? 1);
369
+ }
370
+ ans[i * cols + j] = sum2;
371
+ }
372
+ }
373
+ return ans;
374
+ }
375
+ div(m) {
376
+ return this.mul(1 / m);
377
+ }
378
+ static transpose(m) {
379
+ const { rows, cols } = m;
380
+ const ans = mat(cols, rows);
381
+ for (let i = 0, { length } = this; i < length; i++) {
382
+ for (let j = 0; j < cols; j++) {
383
+ ans[j * cols + i] = m[i * cols + j] || 0;
384
+ }
385
+ }
386
+ return ans;
387
+ }
388
+ };
389
+ function mat(rows, cols = 1) {
390
+ if (typeof rows === "number") {
391
+ return new Mat(rows, cols);
392
+ }
393
+ return new Mat(rows);
394
+ }
395
+
396
+ // src/math/matrix/mat2.ts
397
+ var Mat2 = class _Mat2 extends Float32Array {
398
+ static BYTE_LENGTH = 4 * Float32Array.BYTES_PER_ELEMENT;
399
+ constructor(matrix = [1, 0, 0, 1]) {
400
+ super(matrix);
401
+ }
402
+ toString() {
403
+ const [a, b, c, d] = this;
404
+ return `mat2 [
405
+ ${a} ${b}
406
+ ${c} ${d}
407
+ ]`;
408
+ }
409
+ copy() {
410
+ return mat2(this);
411
+ }
412
+ identity() {
413
+ this.set([1, 0, 0, 1]);
414
+ return this;
415
+ }
416
+ eq(m, precision) {
417
+ for (let i = 0; i < 4; i++) {
418
+ const a = this[i];
419
+ const b = m[i];
420
+ if (!closeTo(a, b, precision)) {
421
+ return false;
422
+ }
423
+ }
424
+ return true;
425
+ }
426
+ add(m) {
427
+ for (let i = 0; i < 4; i++) {
428
+ this[i] += m[i];
429
+ }
430
+ return this;
431
+ }
432
+ static add(m1, m2) {
433
+ return m1.copy().add(m2);
434
+ }
435
+ sub(m) {
436
+ for (let i = 0; i < 4; i++) {
437
+ this[i] -= m[i];
438
+ }
439
+ return this;
440
+ }
441
+ static sub(m1, m2) {
442
+ return m1.copy().sub(m2);
443
+ }
444
+ mul(m) {
445
+ this.set(_Mat2.mul(this, m));
446
+ return this;
447
+ }
448
+ static mul(m1, m2) {
449
+ if (typeof m2 === "number") {
450
+ const ans = mat2();
451
+ for (let i = 0; i < 4; i++) {
452
+ ans[i] *= m2;
453
+ }
454
+ return ans;
455
+ }
456
+ const [a0 = 0, a1 = 0, a2 = 0, a3 = 0] = m1;
457
+ const [b0 = 0, b1 = 0, b2 = 0, b3 = 0] = m2;
458
+ return mat2([
459
+ a0 * b0 + a1 * b2,
460
+ a0 * b1 + a1 * b3,
461
+ a2 * b0 + a3 * b2,
462
+ a2 * b1 + a3 * b3
463
+ ]);
464
+ }
465
+ div(m) {
466
+ return this.mul(1 / m);
467
+ }
468
+ transpose() {
469
+ const [, b = 0, c = 0] = this;
470
+ [this[2], this[1]] = [b, c];
471
+ return this;
472
+ }
473
+ det() {
474
+ const [a = 0, b = 0, c = 0, d = 0] = this;
475
+ return a * d - b * c;
476
+ }
477
+ adj() {
478
+ const [a = 0, b = 0, c = 0, d = 0] = this;
479
+ return mat2([d, -b, -c, a]);
480
+ }
481
+ inv() {
482
+ return this.adj().div(this.det());
483
+ }
484
+ };
485
+ function mat2(matrix) {
486
+ return new Mat2(matrix);
487
+ }
488
+
489
+ // src/math/matrix/mat3.ts
490
+ var Mat3 = class _Mat3 extends Float32Array {
491
+ static BYTE_LENGTH = 9 * Float32Array.BYTES_PER_ELEMENT;
492
+ constructor(matrix = [1, 0, 0, 0, 1, 0, 0, 0, 1]) {
493
+ super(matrix);
494
+ }
495
+ toString() {
496
+ const [a, b, c, d, e, f, g, h, i] = this;
497
+ return `mat3 [
498
+ ${a} ${b} ${c}
499
+ ${d} ${e} ${f}
500
+ ${g} ${h} ${i}
501
+ ]`;
502
+ }
503
+ copy() {
504
+ return mat3(this);
505
+ }
506
+ identity() {
507
+ this.set([1, 0, 0, 0, 1, 0, 0, 0, 1]);
508
+ return this;
509
+ }
510
+ eq(m, precision) {
511
+ for (let i = 0; i < 9; i++) {
512
+ const a = this[i];
513
+ const b = m[i];
514
+ if (!closeTo(a, b, precision)) {
515
+ return false;
516
+ }
517
+ }
518
+ return true;
519
+ }
520
+ add(m) {
521
+ for (let i = 0; i < 9; i++) {
522
+ this[i] += m[i];
523
+ }
524
+ return this;
525
+ }
526
+ static add(m1, m2) {
527
+ return m1.copy().add(m2);
528
+ }
529
+ sub(m) {
530
+ for (let i = 0; i < 9; i++) {
531
+ this[i] -= m[i];
532
+ }
533
+ return this;
534
+ }
535
+ static sub(m1, m2) {
536
+ return m1.copy().sub(m2);
537
+ }
538
+ mul(m) {
539
+ this.set(_Mat3.mul(this, m));
540
+ return this;
541
+ }
542
+ static mul(m1, m2) {
543
+ if (typeof m2 === "number") {
544
+ const ans = mat3(m1);
545
+ for (let i = 0; i < 9; i++) {
546
+ ans[i] *= m2;
547
+ }
548
+ return ans;
549
+ }
550
+ const [
551
+ a0 = 0,
552
+ a1 = 0,
553
+ a2 = 0,
554
+ a3 = 0,
555
+ a4 = 0,
556
+ a5 = 0,
557
+ a6 = 0,
558
+ a7 = 0,
559
+ a8 = 0
560
+ ] = m1;
561
+ const [
562
+ b0 = 0,
563
+ b1 = 0,
564
+ b2 = 0,
565
+ b3 = 0,
566
+ b4 = 0,
567
+ b5 = 0,
568
+ b6 = 0,
569
+ b7 = 0,
570
+ b8 = 0
571
+ ] = m2;
572
+ return mat3([
573
+ a0 * b0 + a1 * b3 + a2 * b6,
574
+ a0 * b1 + a1 * b4 + a2 * b7,
575
+ a0 * b2 + a1 * b5 + a2 * b8,
576
+ a3 * b0 + a4 * b3 + a5 * b6,
577
+ a3 * b1 + a4 * b4 + a5 * b7,
578
+ a3 * b2 + a4 * b5 + a5 * b8,
579
+ a6 * b0 + a7 * b3 + a8 * b6,
580
+ a6 * b1 + a7 * b4 + a8 * b7,
581
+ a6 * b2 + a7 * b5 + a8 * b8
582
+ ]);
583
+ }
584
+ div(m) {
585
+ return this.mul(1 / m);
586
+ }
587
+ transpose() {
588
+ const [, b = 0, c = 0, d = 0, , f = 0, g = 0, h = 0] = this;
589
+ [this[3], this[1]] = [b, d];
590
+ [this[6], this[2]] = [c, g];
591
+ [this[7], this[5]] = [f, h];
592
+ return this;
593
+ }
594
+ det() {
595
+ const [a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0] = this;
596
+ return a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g);
597
+ }
598
+ adj() {
599
+ const [a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0] = this;
600
+ return mat3([
601
+ e * i - f * h,
602
+ -(d * i - f * g),
603
+ d * h - e * g,
604
+ -(b * i - c * h),
605
+ a * i - c * g,
606
+ -(a * h - b * g),
607
+ b * f - c * e,
608
+ -(a * f - c * d),
609
+ a * e - b * d
610
+ ]).transpose();
611
+ }
612
+ inv() {
613
+ return this.adj().div(this.det());
614
+ }
615
+ };
616
+ function mat3(matrix) {
617
+ return new Mat3(matrix);
618
+ }
619
+
620
+ // src/math/matrix/mat4.ts
621
+ var Mat4 = class _Mat4 extends Float32Array {
622
+ constructor(matrix = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]) {
623
+ super(matrix);
624
+ }
625
+ toString() {
626
+ const [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p] = this;
627
+ return `mat4 [
628
+ ${a} ${b} ${c} ${d}
629
+ ${e} ${f} ${g} ${h}
630
+ ${i} ${j} ${k} ${l}
631
+ ${m} ${n} ${o} ${p}
632
+ ]`;
633
+ }
634
+ copy() {
635
+ return mat4(this);
636
+ }
637
+ eq(m, precision) {
638
+ for (let i = 0; i < 16; i++) {
639
+ const a = this[i];
640
+ const b = m[i];
641
+ if (!closeTo(a, b, precision)) {
642
+ return false;
643
+ }
644
+ }
645
+ return true;
646
+ }
647
+ add(m) {
648
+ for (let i = 0; i < 16; i++) {
649
+ this[i] += m[i];
650
+ }
651
+ return this;
652
+ }
653
+ static add(m1, m2) {
654
+ return m1.copy().add(m2);
655
+ }
656
+ sub(m) {
657
+ for (let i = 0; i < 16; i++) {
658
+ this[i] -= m[i];
659
+ }
660
+ return this;
661
+ }
662
+ static sub(m1, m2) {
663
+ return m1.copy().sub(m2);
664
+ }
665
+ mul(m) {
666
+ this.set(_Mat4.mul(this, m));
667
+ return this;
668
+ }
669
+ static mul(m1, m2) {
670
+ if (typeof m2 === "number") {
671
+ const ans = mat4();
672
+ for (let i = 0; i < 16; i++) {
673
+ ans[i] *= m2;
674
+ }
675
+ return ans;
676
+ }
677
+ const [
678
+ a0 = 0,
679
+ a1 = 0,
680
+ a2 = 0,
681
+ a3 = 0,
682
+ a4 = 0,
683
+ a5 = 0,
684
+ a6 = 0,
685
+ a7 = 0,
686
+ a8 = 0,
687
+ a9 = 0,
688
+ a10 = 0,
689
+ a11 = 0,
690
+ a12 = 0,
691
+ a13 = 0,
692
+ a14 = 0,
693
+ a15 = 0
694
+ ] = m1;
695
+ const [
696
+ b0 = 0,
697
+ b1 = 0,
698
+ b2 = 0,
699
+ b3 = 0,
700
+ b4 = 0,
701
+ b5 = 0,
702
+ b6 = 0,
703
+ b7 = 0,
704
+ b8 = 0,
705
+ b9 = 0,
706
+ b10 = 0,
707
+ b11 = 0,
708
+ b12 = 0,
709
+ b13 = 0,
710
+ b14 = 0,
711
+ b15 = 0
712
+ ] = m2;
713
+ return mat4([
714
+ a0 * b0 + a1 * b4 + a2 * b8 + a3 * b12,
715
+ a0 * b1 + a1 * b5 + a2 * b9 + a3 * b13,
716
+ a0 * b2 + a1 * b6 + a2 * b10 + a3 * b14,
717
+ a0 * b3 + a1 * b7 + a2 * b11 + a3 * b15,
718
+ a4 * b0 + a5 * b4 + a6 * b8 + a7 * b12,
719
+ a4 * b1 + a5 * b5 + a6 * b9 + a7 * b13,
720
+ a4 * b2 + a5 * b6 + a6 * b10 + a7 * b14,
721
+ a4 * b3 + a5 * b7 + a6 * b11 + a7 * b15,
722
+ a8 * b0 + a9 * b4 + a10 * b8 + a11 * b12,
723
+ a8 * b1 + a9 * b5 + a10 * b9 + a11 * b13,
724
+ a8 * b2 + a9 * b6 + a10 * b10 + a11 * b14,
725
+ a8 * b3 + a9 * b7 + a10 * b11 + a11 * b15,
726
+ a12 * b0 + a13 * b4 + a14 * b8 + a15 * b12,
727
+ a12 * b1 + a13 * b5 + a14 * b9 + a15 * b13,
728
+ a12 * b2 + a13 * b6 + a14 * b10 + a15 * b14,
729
+ a12 * b3 + a13 * b7 + a14 * b11 + a15 * b15
730
+ ]);
731
+ }
732
+ div(m) {
733
+ return this.mul(1 / m);
734
+ }
735
+ transpose() {
736
+ const [
737
+ ,
738
+ b = 0,
739
+ c = 0,
740
+ d = 0,
741
+ e = 0,
742
+ ,
743
+ g = 0,
744
+ h = 0,
745
+ i = 0,
746
+ j = 0,
747
+ ,
748
+ l = 0,
749
+ m = 0,
750
+ n = 0,
751
+ o = 0
752
+ ] = this;
753
+ [this[4], this[1]] = [b, e];
754
+ [this[8], this[2]] = [c, i];
755
+ [this[12], this[3]] = [d, m];
756
+ [this[9], this[6]] = [g, j];
757
+ [this[13], this[7]] = [h, n];
758
+ [this[14], this[11]] = [l, o];
759
+ return this;
760
+ }
761
+ det() {
762
+ const [
763
+ a = 0,
764
+ b = 0,
765
+ c = 0,
766
+ d = 0,
767
+ e = 0,
768
+ f = 0,
769
+ g = 0,
770
+ h = 0,
771
+ i = 0,
772
+ j = 0,
773
+ k = 0,
774
+ l = 0,
775
+ m = 0,
776
+ n = 0,
777
+ o = 0,
778
+ p = 0
779
+ ] = this;
780
+ return a * mat3([f, g, h, j, k, l, n, o, p]).det() - b * mat3([e, g, h, i, k, l, m, o, p]).det() + c * mat3([e, f, h, i, j, l, m, n, p]).det() - d * mat3([e, f, g, i, j, k, m, n, o]).det();
781
+ }
782
+ adj() {
783
+ const [
784
+ a = 0,
785
+ b = 0,
786
+ c = 0,
787
+ d = 0,
788
+ e = 0,
789
+ f = 0,
790
+ g = 0,
791
+ h = 0,
792
+ i = 0,
793
+ j = 0,
794
+ k = 0,
795
+ l = 0,
796
+ m = 0,
797
+ n = 0,
798
+ o = 0,
799
+ p = 0
800
+ ] = this;
801
+ return mat4([
802
+ mat3([f, g, h, j, k, l, n, o, p]).det(),
803
+ -mat3([e, g, h, i, k, l, m, o, p]).det(),
804
+ mat3([e, f, h, i, j, l, m, n, p]).det(),
805
+ -mat3([e, f, g, i, j, k, m, n, o]).det(),
806
+ -mat3([b, c, d, j, k, l, n, o, p]).det(),
807
+ mat3([a, c, d, i, k, l, m, o, p]).det(),
808
+ -mat3([a, b, d, i, j, l, m, n, p]).det(),
809
+ mat3([a, b, c, i, j, k, m, n, o]).det(),
810
+ mat3([b, c, d, f, g, h, n, o, p]).det(),
811
+ -mat3([a, c, d, e, g, h, m, o, p]).det(),
812
+ mat3([a, b, d, e, f, h, m, n, p]).det(),
813
+ -mat3([a, b, c, e, f, g, m, n, o]).det(),
814
+ -mat3([b, c, d, f, g, h, j, k, l]).det(),
815
+ mat3([a, c, d, e, g, h, i, k, l]).det(),
816
+ -mat3([a, b, d, e, f, h, i, j, l]).det(),
817
+ mat3([a, b, c, e, f, g, i, j, k]).det()
818
+ ]).transpose();
819
+ }
820
+ inv() {
821
+ return this.adj().div(this.det());
822
+ }
823
+ };
824
+ function mat4(matrix) {
825
+ return new Mat4(matrix);
826
+ }
827
+
828
+ // src/math/trig.ts
829
+ var DEG2RAD = Math.PI / 180;
830
+ var degrees = (radians2) => radians2 / DEG2RAD;
831
+ var radians = (degrees2) => degrees2 * DEG2RAD;
832
+
833
+ // src/math/vector/vec2.ts
834
+ var Vec2 = class _Vec2 extends Float32Array {
835
+ static BYTE_LENGTH = 2 * Float32Array.BYTES_PER_ELEMENT;
836
+ constructor(x = 0, y) {
837
+ super([0, 0]);
838
+ if (typeof x === "number") {
839
+ this.x = x;
840
+ this.y = y ?? x;
841
+ } else {
842
+ [this[0] = 0, this[1] = 0] = x;
843
+ }
844
+ }
845
+ /* prettier-ignore */
846
+ get x() {
847
+ return this[0] || 0;
848
+ }
849
+ /* prettier-ignore */
850
+ set x(value) {
851
+ this[0] = value;
852
+ }
853
+ /* prettier-ignore */
854
+ get y() {
855
+ return this[1] || 0;
856
+ }
857
+ /* prettier-ignore */
858
+ set y(value) {
859
+ this[1] = value;
860
+ }
861
+ toString() {
862
+ const [x, y] = this;
863
+ return `vec2 <${x}, ${y}>`;
864
+ }
865
+ copy() {
866
+ return vec2(...this);
867
+ }
868
+ static random(mag = 1) {
869
+ return vec2(1, 0).rotate(random(Math.PI * 2)).setMag(mag);
870
+ }
871
+ eq(x, y) {
872
+ if (typeof x === "number") {
873
+ return this.x === x && this.y === (y ?? x);
874
+ }
875
+ return this.x === x[0] && this.y === x[1];
876
+ }
877
+ add(x, y) {
878
+ if (typeof x === "number") {
879
+ this.x += x;
880
+ this.y += y ?? x;
881
+ } else {
882
+ this.x += x[0];
883
+ this.y += x[1];
884
+ }
885
+ return this;
886
+ }
887
+ static add(v1, x, y) {
888
+ return v1.copy().add(x, y);
889
+ }
890
+ sub(x, y) {
891
+ if (typeof x === "number") {
892
+ this.x -= x;
893
+ this.y -= y ?? x;
894
+ } else {
895
+ this.x -= x[0];
896
+ this.y -= x[1];
897
+ }
898
+ return this;
899
+ }
900
+ static sub(v1, x, y) {
901
+ return v1.copy().sub(x, y);
902
+ }
903
+ mul(x, y) {
904
+ if (typeof x === "number") {
905
+ this.x *= x;
906
+ this.y *= y ?? x;
907
+ } else {
908
+ this.x *= x[0];
909
+ this.y *= x[1];
910
+ }
911
+ return this;
912
+ }
913
+ static mul(v1, x, y) {
914
+ return v1.copy().mul(x, y);
915
+ }
916
+ div(x, y) {
917
+ if (typeof x === "number") {
918
+ this.x *= x;
919
+ this.y *= y ?? x;
920
+ } else {
921
+ this.x *= x[0];
922
+ this.y *= x[1];
923
+ }
924
+ return this;
925
+ }
926
+ static div(v1, x, y) {
927
+ return v1.copy().div(x, y);
928
+ }
929
+ static fma(a, b, c) {
930
+ return vec2(a[0] * b[0] + c[0], a[1] * b[1] + c[1]);
931
+ }
932
+ lt(x) {
933
+ return vec2(this.x < x[0] ? 1 : 0, this.y < x[1] ? 1 : 0);
934
+ }
935
+ lte(x) {
936
+ return vec2(this.x <= x[0] ? 1 : 0, this.y <= x[1] ? 1 : 0);
937
+ }
938
+ gt(x) {
939
+ return vec2(this.x > x[0] ? 1 : 0, this.y > x[1] ? 1 : 0);
940
+ }
941
+ gte(x) {
942
+ return vec2(this.x >= x[0] ? 1 : 0, this.y >= x[1] ? 1 : 0);
943
+ }
944
+ mag() {
945
+ return Math.sqrt(this.magSq());
946
+ }
947
+ setMag(n) {
948
+ return this.normalize().mul(n);
949
+ }
950
+ magSq() {
951
+ const { x, y } = this;
952
+ return x * x + y * y;
953
+ }
954
+ limit(max2) {
955
+ const maxSq = max2 * max2;
956
+ const magSq = this.magSq();
957
+ if (magSq > maxSq) {
958
+ this.setMag(max2);
959
+ }
960
+ return this;
961
+ }
962
+ normalize() {
963
+ const mag = this.mag();
964
+ if (mag !== 0) {
965
+ this.div(mag);
966
+ }
967
+ return this;
968
+ }
969
+ static normalize(v) {
970
+ return v.copy().normalize();
971
+ }
972
+ dist(v) {
973
+ return Math.sqrt(this.distSq(v));
974
+ }
975
+ distSq(v) {
976
+ return _Vec2.sub(v, this).magSq();
977
+ }
978
+ dot(v) {
979
+ return this.x * v[0] + this.y * v[1];
980
+ }
981
+ cross(v) {
982
+ return this.x * v[1] - this.y * v[0];
983
+ }
984
+ lerp(v, norm2) {
985
+ const { x, y } = this;
986
+ this.x = lerp(x, v[0], norm2);
987
+ this.y = lerp(y, v[1], norm2);
988
+ return this;
989
+ }
990
+ static lerp(v1, v2, norm2) {
991
+ return v1.copy().lerp(v2, norm2);
992
+ }
993
+ clamp(min2, max2) {
994
+ const { x, y } = this;
995
+ this.x = clamp(x, min2[0], max2[0]);
996
+ this.y = clamp(y, min2[1], max2[1]);
997
+ return this;
998
+ }
999
+ static clamp(v, min2, max2) {
1000
+ return v.copy().clamp(min2, max2);
1001
+ }
1002
+ perp() {
1003
+ return vec2(this.y, -this.x);
1004
+ }
1005
+ angle() {
1006
+ return Math.atan2(this.y, this.x);
1007
+ }
1008
+ setAngle(a) {
1009
+ const mag = this.mag();
1010
+ this.x = Math.cos(a) * mag;
1011
+ this.y = Math.sin(a) * mag;
1012
+ return this;
1013
+ }
1014
+ static fromAngle(a, mag = 1) {
1015
+ return vec2(mag).setAngle(a);
1016
+ }
1017
+ rotate(angle) {
1018
+ const { x, y } = this;
1019
+ const cos = Math.cos(angle);
1020
+ const sin = Math.sin(angle);
1021
+ this.x = cos * x - sin * y;
1022
+ this.y = sin * x + cos * y;
1023
+ return this;
1024
+ }
1025
+ static rotate(v, angle) {
1026
+ return v.copy().rotate(angle);
1027
+ }
1028
+ rotateAbout(angle, center) {
1029
+ return this.sub(center).rotate(angle).add(center);
1030
+ }
1031
+ reflect(normal) {
1032
+ return this.sub(_Vec2.mul(normal, 2 * this.dot(normal)));
1033
+ }
1034
+ refract(normal, eta) {
1035
+ const dot2 = this.dot(normal);
1036
+ const k = 1 - eta * eta * (1 - dot2 * dot2);
1037
+ if (k < 0) {
1038
+ this.x = this.y = 0;
1039
+ return this;
1040
+ }
1041
+ return this.mul(eta).sub(_Vec2.mul(normal, eta * dot2 + Math.sqrt(k)));
1042
+ }
1043
+ };
1044
+ function vec2(x, y) {
1045
+ return new Vec2(x, y);
1046
+ }
1047
+
1048
+ // src/math/vector/vec3.ts
1049
+ var Vec3 = class _Vec3 extends Float32Array {
1050
+ static BYTE_LENGTH = 3 * Float32Array.BYTES_PER_ELEMENT;
1051
+ constructor(x = 0, y, z) {
1052
+ super([0, 0, 0]);
1053
+ if (typeof x === "number") {
1054
+ this.x = x;
1055
+ this.y = y ?? x;
1056
+ this.z = z ?? (y === void 0 ? x : 0);
1057
+ } else {
1058
+ [this[0] = 0, this[1] = 0, this[2] = 0] = x;
1059
+ }
1060
+ }
1061
+ /* prettier-ignore */
1062
+ get x() {
1063
+ return this[0] || 0;
1064
+ }
1065
+ /* prettier-ignore */
1066
+ set x(value) {
1067
+ this[0] = value;
1068
+ }
1069
+ /* prettier-ignore */
1070
+ get y() {
1071
+ return this[1] || 0;
1072
+ }
1073
+ /* prettier-ignore */
1074
+ set y(value) {
1075
+ this[1] = value;
1076
+ }
1077
+ /* prettier-ignore */
1078
+ get z() {
1079
+ return this[2] || 0;
1080
+ }
1081
+ /* prettier-ignore */
1082
+ set z(value) {
1083
+ this[2] = value;
1084
+ }
1085
+ /* prettier-ignore */
1086
+ get r() {
1087
+ return this[0] || 0;
1088
+ }
1089
+ /* prettier-ignore */
1090
+ set r(value) {
1091
+ this[0] = value;
1092
+ }
1093
+ /* prettier-ignore */
1094
+ get g() {
1095
+ return this[1] || 0;
1096
+ }
1097
+ /* prettier-ignore */
1098
+ set g(value) {
1099
+ this[1] = value;
1100
+ }
1101
+ /* prettier-ignore */
1102
+ get b() {
1103
+ return this[2] || 0;
1104
+ }
1105
+ /* prettier-ignore */
1106
+ set b(value) {
1107
+ this[2] = value;
1108
+ }
1109
+ toString() {
1110
+ const [x, y, z] = this;
1111
+ return `vec3 <${x}, ${y}, ${z}>`;
1112
+ }
1113
+ copy() {
1114
+ return vec3(...this);
1115
+ }
1116
+ static random(mag = 1) {
1117
+ return vec3(0, 0, 1).rotateX(random(Math.PI * 2)).rotateY(random(Math.PI * 2)).setMag(mag);
1118
+ }
1119
+ eq(x, y, z) {
1120
+ if (typeof x === "number") {
1121
+ return this.x === x && this.y === (y ?? x) && this.z === (z ?? (y === void 0 ? x : 0));
1122
+ }
1123
+ return this.x === x[0] && this.y === x[1] && this.z === x[2];
1124
+ }
1125
+ neg() {
1126
+ return vec3(-this.x, -this.y, -this.z);
1127
+ }
1128
+ add(x, y, z) {
1129
+ if (typeof x === "number") {
1130
+ this.x += x;
1131
+ this.y += y ?? x;
1132
+ this.z += z ?? (y === void 0 ? x : 0);
1133
+ } else {
1134
+ this.x += x[0];
1135
+ this.y += x[1];
1136
+ this.z += x[2];
1137
+ }
1138
+ return this;
1139
+ }
1140
+ static add(v1, x, y, z) {
1141
+ return v1.copy().add(x, y, z);
1142
+ }
1143
+ sub(x, y, z) {
1144
+ if (typeof x === "number") {
1145
+ this.x -= x;
1146
+ this.y -= y ?? x;
1147
+ this.z -= z ?? (y === void 0 ? x : 0);
1148
+ } else {
1149
+ this.x -= x[0];
1150
+ this.y -= x[1];
1151
+ this.z -= x[2];
1152
+ }
1153
+ return this;
1154
+ }
1155
+ static sub(v1, x, y, z) {
1156
+ return v1.copy().sub(x, y, z);
1157
+ }
1158
+ mul(x, y, z) {
1159
+ if (typeof x === "number") {
1160
+ this.x *= x;
1161
+ this.y *= y ?? x;
1162
+ this.z *= z ?? (y === void 0 ? x : 1);
1163
+ } else {
1164
+ this.x *= x[0];
1165
+ this.y *= x[1];
1166
+ this.z *= x[2];
1167
+ }
1168
+ return this;
1169
+ }
1170
+ static mul(v1, x, y, z) {
1171
+ return v1.copy().mul(x, y, z);
1172
+ }
1173
+ div(x, y, z) {
1174
+ if (typeof x === "number") {
1175
+ this.x /= x;
1176
+ this.y /= y ?? x;
1177
+ this.z /= z ?? (y === void 0 ? x : 1);
1178
+ } else {
1179
+ this.x /= x[0];
1180
+ this.y /= x[1];
1181
+ this.z /= x[2];
1182
+ }
1183
+ return this;
1184
+ }
1185
+ static div(v1, x, y, z) {
1186
+ return v1.copy().div(x, y, z);
1187
+ }
1188
+ static fma(a, b, c) {
1189
+ return vec3(a[0] * b[0] + c[0], a[1] * b[1] + c[1], a[2] * b[2] + c[2]);
1190
+ }
1191
+ lt(x) {
1192
+ return vec3(
1193
+ this.x < x[0] ? 1 : 0,
1194
+ this.y < x[1] ? 1 : 0,
1195
+ this.z < x[2] ? 1 : 0
1196
+ );
1197
+ }
1198
+ lte(x) {
1199
+ return vec3(
1200
+ this.x <= x[0] ? 1 : 0,
1201
+ this.y <= x[1] ? 1 : 0,
1202
+ this.z <= x[2] ? 1 : 0
1203
+ );
1204
+ }
1205
+ gt(x) {
1206
+ return vec3(
1207
+ this.x > x[0] ? 1 : 0,
1208
+ this.y > x[1] ? 1 : 0,
1209
+ this.z > x[2] ? 1 : 0
1210
+ );
1211
+ }
1212
+ gte(x) {
1213
+ return vec3(
1214
+ this.x >= x[0] ? 1 : 0,
1215
+ this.y >= x[1] ? 1 : 0,
1216
+ this.z >= x[2] ? 1 : 0
1217
+ );
1218
+ }
1219
+ limit(max2) {
1220
+ const maxSq = max2 * max2;
1221
+ const magSq = this.magSq();
1222
+ if (magSq > maxSq) {
1223
+ this.setMag(max2);
1224
+ }
1225
+ return this;
1226
+ }
1227
+ normalize() {
1228
+ const mag = this.mag();
1229
+ if (mag !== 0) {
1230
+ this.div(mag);
1231
+ }
1232
+ return this;
1233
+ }
1234
+ static normalize(v) {
1235
+ return v.copy().normalize();
1236
+ }
1237
+ mag() {
1238
+ return Math.sqrt(this.magSq());
1239
+ }
1240
+ setMag(n) {
1241
+ return this.normalize().mul(n);
1242
+ }
1243
+ magSq() {
1244
+ const { x, y, z } = this;
1245
+ return x * x + y * y + z * z;
1246
+ }
1247
+ dist(v) {
1248
+ return Math.sqrt(this.distSq(v));
1249
+ }
1250
+ distSq(v) {
1251
+ return _Vec3.sub(v, this).magSq();
1252
+ }
1253
+ dot(v) {
1254
+ const { x, y, z } = this;
1255
+ return x * v[0] + y * v[1] + z * v[2];
1256
+ }
1257
+ cross(v) {
1258
+ const { x, y, z } = this;
1259
+ return vec3(y * v[2] - z * v[1], z * v[0] - x * v[2], x * v[1] - y * v[0]);
1260
+ }
1261
+ lerp(v, norm2) {
1262
+ const { x, y, z } = this;
1263
+ this.x = lerp(x, v[0], norm2);
1264
+ this.y = lerp(y, v[1], norm2);
1265
+ this.z = lerp(z, v[2], norm2);
1266
+ return this;
1267
+ }
1268
+ static lerp(v1, v2, norm2) {
1269
+ return v1.copy().lerp(v2, norm2);
1270
+ }
1271
+ clamp(min2, max2) {
1272
+ const { x, y, z } = this;
1273
+ this.x = clamp(x, min2[0], max2[0]);
1274
+ this.y = clamp(y, min2[1], max2[1]);
1275
+ this.z = clamp(z, min2[2], max2[2]);
1276
+ return this;
1277
+ }
1278
+ static clamp(v, min2, max2) {
1279
+ return v.copy().clamp(min2, max2);
1280
+ }
1281
+ rotateX(angle) {
1282
+ const { y, z } = this;
1283
+ const cos = Math.cos(angle);
1284
+ const sin = Math.sin(angle);
1285
+ this.y = cos * y - sin * z;
1286
+ this.z = sin * y + cos * z;
1287
+ return this;
1288
+ }
1289
+ rotateY(angle) {
1290
+ const { x, z } = this;
1291
+ const cos = Math.cos(angle);
1292
+ const sin = Math.sin(angle);
1293
+ this.x = cos * x + sin * z;
1294
+ this.z = -sin * x + cos * z;
1295
+ return this;
1296
+ }
1297
+ rotateZ(angle) {
1298
+ const { x, y } = this;
1299
+ const cos = Math.cos(angle);
1300
+ const sin = Math.sin(angle);
1301
+ this.x = cos * x - sin * y;
1302
+ this.y = sin * x + cos * y;
1303
+ return this;
1304
+ }
1305
+ reflect(normal) {
1306
+ return this.sub(_Vec3.mul(normal, 2 * this.dot(normal)));
1307
+ }
1308
+ static reflect(v, normal) {
1309
+ return v.copy().reflect(normal);
1310
+ }
1311
+ refract(normal, eta) {
1312
+ const nDot = this.dot(normal);
1313
+ const k = 1 - eta * eta * (1 - nDot * nDot);
1314
+ if (k < 0) {
1315
+ this.x = this.y = this.z = 0;
1316
+ return this;
1317
+ }
1318
+ return this.sub(_Vec3.mul(normal, eta * nDot + Math.sqrt(k)));
1319
+ }
1320
+ };
1321
+ function vec3(x, y, z) {
1322
+ return new Vec3(x, y, z);
1323
+ }
1324
+
1325
+ // src/math/vector/vec4.ts
1326
+ var Vec4 = class _Vec4 extends Float32Array {
1327
+ static BYTE_LENGTH = 4 * Float32Array.BYTES_PER_ELEMENT;
1328
+ constructor(x = 0, y, z, w) {
1329
+ super([0, 0, 0, 0]);
1330
+ if (typeof x === "number") {
1331
+ this.x = x;
1332
+ this.y = y ?? x;
1333
+ this.z = z ?? (y === void 0 ? x : 0);
1334
+ this.w = w ?? (z === void 0 ? x : 0);
1335
+ } else {
1336
+ [this[0] = 0, this[1] = 0, this[2] = 0, this[3] = 0] = x;
1337
+ }
1338
+ }
1339
+ /* prettier-ignore */
1340
+ get x() {
1341
+ return this[0] || 0;
1342
+ }
1343
+ /* prettier-ignore */
1344
+ set x(value) {
1345
+ this[0] = value;
1346
+ }
1347
+ /* prettier-ignore */
1348
+ get y() {
1349
+ return this[1] || 0;
1350
+ }
1351
+ /* prettier-ignore */
1352
+ set y(value) {
1353
+ this[1] = value;
1354
+ }
1355
+ /* prettier-ignore */
1356
+ get z() {
1357
+ return this[2] || 0;
1358
+ }
1359
+ /* prettier-ignore */
1360
+ set z(value) {
1361
+ this[2] = value;
1362
+ }
1363
+ /* prettier-ignore */
1364
+ get w() {
1365
+ return this[2] || 0;
1366
+ }
1367
+ /* prettier-ignore */
1368
+ set w(value) {
1369
+ this[2] = value;
1370
+ }
1371
+ /* prettier-ignore */
1372
+ get r() {
1373
+ return this[0] || 0;
1374
+ }
1375
+ /* prettier-ignore */
1376
+ set r(value) {
1377
+ this[0] = value;
1378
+ }
1379
+ /* prettier-ignore */
1380
+ get g() {
1381
+ return this[1] || 0;
1382
+ }
1383
+ /* prettier-ignore */
1384
+ set g(value) {
1385
+ this[1] = value;
1386
+ }
1387
+ /* prettier-ignore */
1388
+ get b() {
1389
+ return this[2] || 0;
1390
+ }
1391
+ /* prettier-ignore */
1392
+ set b(value) {
1393
+ this[2] = value;
1394
+ }
1395
+ /* prettier-ignore */
1396
+ get a() {
1397
+ return this[2] || 0;
1398
+ }
1399
+ /* prettier-ignore */
1400
+ set a(value) {
1401
+ this[2] = value;
1402
+ }
1403
+ toString() {
1404
+ const [x, y, z, w] = this;
1405
+ return `vec4 <${x}, ${y}, ${z}, ${w}>`;
1406
+ }
1407
+ copy() {
1408
+ return vec4(...this);
1409
+ }
1410
+ eq(x, y, z, w) {
1411
+ if (typeof x === "number") {
1412
+ return this.x === x && this.y === (y ?? x) && this.z === (z ?? (y === void 0 ? x : 0)) && this.w === (w ?? (z === void 0 ? x : 0));
1413
+ }
1414
+ return this.x === x[0] && this.y === x[1] && this.z === x[2] && this.w === x[3];
1415
+ }
1416
+ add(x, y, z, w) {
1417
+ if (typeof x === "number") {
1418
+ this.x += x;
1419
+ this.y += y ?? x;
1420
+ this.z += z ?? (y === void 0 ? x : 0);
1421
+ this.w += w ?? (z === void 0 ? x : 0);
1422
+ } else {
1423
+ this.x += x[0];
1424
+ this.y += x[1];
1425
+ this.z += x[2];
1426
+ this.w += x[3];
1427
+ }
1428
+ return this;
1429
+ }
1430
+ static add(v1, x, y, z, w) {
1431
+ return v1.copy().add(x, y, z, w);
1432
+ }
1433
+ sub(x, y, z, w) {
1434
+ if (typeof x === "number") {
1435
+ this.x -= x;
1436
+ this.y -= y ?? x;
1437
+ this.z -= z ?? (y === void 0 ? x : 0);
1438
+ this.w -= w ?? (z === void 0 ? x : 0);
1439
+ } else {
1440
+ this.x -= x[0];
1441
+ this.y -= x[1];
1442
+ this.z -= x[2];
1443
+ this.w -= x[3];
1444
+ }
1445
+ return this;
1446
+ }
1447
+ static sub(v1, x, y, z, w) {
1448
+ return v1.copy().sub(x, y, z, w);
1449
+ }
1450
+ mul(x, y, z, w) {
1451
+ if (typeof x === "number") {
1452
+ this.x *= x;
1453
+ this.y *= y ?? x;
1454
+ this.z *= z ?? (y === void 0 ? x : 1);
1455
+ this.w *= w ?? (z === void 0 ? x : 1);
1456
+ } else {
1457
+ this.x *= x[0];
1458
+ this.y *= x[1];
1459
+ this.z *= x[2];
1460
+ this.w *= x[3];
1461
+ }
1462
+ return this;
1463
+ }
1464
+ static mul(v1, x, y, z, w) {
1465
+ return v1.copy().mul(x, y, z, w);
1466
+ }
1467
+ div(x, y, z, w) {
1468
+ if (typeof x === "number") {
1469
+ this.x /= x;
1470
+ this.y /= y ?? x;
1471
+ this.z /= z ?? (y === void 0 ? x : 1);
1472
+ this.w /= w ?? (z === void 0 ? x : 1);
1473
+ } else {
1474
+ this.x /= x[0];
1475
+ this.y /= x[1];
1476
+ this.z /= x[2];
1477
+ this.w /= x[3];
1478
+ }
1479
+ return this;
1480
+ }
1481
+ static div(v1, x, y, z, w) {
1482
+ return v1.copy().div(x, y, z, w);
1483
+ }
1484
+ static fma(a, b, c) {
1485
+ return vec4(
1486
+ a[0] * b[0] + c[0],
1487
+ a[1] * b[1] + c[1],
1488
+ a[2] * b[2] + c[2],
1489
+ a[3] * b[3] + c[3]
1490
+ );
1491
+ }
1492
+ lt(x) {
1493
+ return vec4(
1494
+ this.x < x[0] ? 1 : 0,
1495
+ this.y < x[1] ? 1 : 0,
1496
+ this.z < x[2] ? 1 : 0,
1497
+ this.w < x[3] ? 1 : 0
1498
+ );
1499
+ }
1500
+ lte(x) {
1501
+ return vec4(
1502
+ this.x <= x[0] ? 1 : 0,
1503
+ this.y <= x[1] ? 1 : 0,
1504
+ this.z <= x[2] ? 1 : 0,
1505
+ this.w <= x[3] ? 1 : 0
1506
+ );
1507
+ }
1508
+ gt(x) {
1509
+ return vec4(
1510
+ this.x > x[0] ? 1 : 0,
1511
+ this.y > x[1] ? 1 : 0,
1512
+ this.z > x[2] ? 1 : 0,
1513
+ this.w > x[3] ? 1 : 0
1514
+ );
1515
+ }
1516
+ gte(x) {
1517
+ return vec4(
1518
+ this.x >= x[0] ? 1 : 0,
1519
+ this.y >= x[1] ? 1 : 0,
1520
+ this.z >= x[2] ? 1 : 0,
1521
+ this.w >= x[3] ? 1 : 0
1522
+ );
1523
+ }
1524
+ limit(max2) {
1525
+ const maxSq = max2 * max2;
1526
+ const magSq = this.magSq();
1527
+ if (magSq > maxSq) {
1528
+ this.setMag(max2);
1529
+ }
1530
+ return this;
1531
+ }
1532
+ normalize() {
1533
+ const mag = this.mag();
1534
+ if (mag !== 0) {
1535
+ this.div(mag);
1536
+ }
1537
+ return this;
1538
+ }
1539
+ static normalize(v) {
1540
+ return v.copy().normalize();
1541
+ }
1542
+ mag() {
1543
+ return Math.sqrt(this.magSq());
1544
+ }
1545
+ setMag(n) {
1546
+ return this.normalize().mul(n);
1547
+ }
1548
+ magSq() {
1549
+ const { x, y, z, w } = this;
1550
+ return x * x + y * y + z * z + w * w;
1551
+ }
1552
+ dist(v) {
1553
+ return Math.sqrt(this.distSq(v));
1554
+ }
1555
+ distSq(v) {
1556
+ return _Vec4.sub(v, this).magSq();
1557
+ }
1558
+ dot(v) {
1559
+ const { x, y, z, w } = this;
1560
+ return x * v[0] + y * v[1] + z * v[2] + w * v[3];
1561
+ }
1562
+ lerp(v, norm2) {
1563
+ const { x, y, z, w } = this;
1564
+ this.x = lerp(x, v[0], norm2);
1565
+ this.y = lerp(y, v[1], norm2);
1566
+ this.z = lerp(z, v[2], norm2);
1567
+ this.w = lerp(w, v[3], norm2);
1568
+ return this;
1569
+ }
1570
+ static lerp(v1, v2, norm2) {
1571
+ return v1.copy().lerp(v2, norm2);
1572
+ }
1573
+ clamp(min2, max2) {
1574
+ const { x, y, z, w } = this;
1575
+ this.x = clamp(x, min2[0], max2[0]);
1576
+ this.y = clamp(y, min2[1], max2[1]);
1577
+ this.z = clamp(z, min2[2], max2[2]);
1578
+ this.w = clamp(w, min2[3], max2[3]);
1579
+ return this;
1580
+ }
1581
+ static clamp(v, min2, max2) {
1582
+ return v.copy().clamp(min2, max2);
1583
+ }
1584
+ reflect(normal) {
1585
+ return this.sub(_Vec4.mul(normal, 2 * this.dot(normal)));
1586
+ }
1587
+ static reflect(v, normal) {
1588
+ return v.copy().reflect(normal);
1589
+ }
1590
+ refract(normal, eta) {
1591
+ const nDot = this.dot(normal);
1592
+ const k = 1 - eta * eta * (1 - nDot * nDot);
1593
+ if (k < 0) {
1594
+ this.x = this.y = this.z = this.w = 0;
1595
+ return this;
1596
+ }
1597
+ return this.sub(_Vec4.mul(normal, eta * nDot + Math.sqrt(k)));
1598
+ }
1599
+ };
1600
+ function vec4(x, y, z, w) {
1601
+ return new Vec4(x, y, z, w);
1602
+ }
1603
+
1604
+ export {
1605
+ min,
1606
+ max,
1607
+ minmax,
1608
+ sum,
1609
+ product,
1610
+ avg,
1611
+ median,
1612
+ mode,
1613
+ variance,
1614
+ stddev,
1615
+ meanAbsDev,
1616
+ isNumber,
1617
+ isReal,
1618
+ isInteger,
1619
+ roundToMultiple,
1620
+ roundToEven,
1621
+ norm,
1622
+ lerp,
1623
+ map2 as map,
1624
+ step,
1625
+ smoothstep,
1626
+ smootherstep,
1627
+ clamp,
1628
+ overlap,
1629
+ closer,
1630
+ round,
1631
+ floor,
1632
+ ceil,
1633
+ trunc,
1634
+ fract,
1635
+ closeTo,
1636
+ factorial,
1637
+ log,
1638
+ ln,
1639
+ gcd,
1640
+ fibonacci,
1641
+ celsius,
1642
+ fahrenheit,
1643
+ lineOfBestFit,
1644
+ permutations,
1645
+ combinations,
1646
+ dot,
1647
+ Mat,
1648
+ mat,
1649
+ Mat2,
1650
+ mat2,
1651
+ Mat3,
1652
+ mat3,
1653
+ Mat4,
1654
+ mat4,
1655
+ DEG2RAD,
1656
+ degrees,
1657
+ radians,
1658
+ Vec2,
1659
+ vec2,
1660
+ Vec3,
1661
+ vec3,
1662
+ Vec4,
1663
+ vec4
1664
+ };