@ntf/math 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -2,6 +2,9 @@
2
2
  var MathFunction = class {
3
3
  };
4
4
 
5
+ // source/algebra/linear.ts
6
+ import { checkValidNumber as checkValidNumber2, NodeJSCustomInspect as NodeJSCustomInspect2 } from "@ntf/types";
7
+
5
8
  // source/common/sign.ts
6
9
  function signCharacter(num) {
7
10
  if (num == 0)
@@ -13,46 +16,6 @@ function signCharacter(num) {
13
16
  return void 0;
14
17
  }
15
18
 
16
- // source/common/types.ts
17
- function checkNumber(value) {
18
- return value !== null && typeof value == "number" && !isNaN(value) && isFinite(value);
19
- }
20
- function getHexValue(string) {
21
- let offset = 0;
22
- if (string.startsWith("#") || string.startsWith("$"))
23
- offset = 1;
24
- if (string.startsWith("0x"))
25
- offset = 2;
26
- return string.substring(offset);
27
- }
28
- function checkHex(value) {
29
- if (!checkString(value))
30
- return false;
31
- const hexValue = getHexValue(value).split("").map((char) => parseInt(char.toUpperCase(), 16));
32
- return checkNumberArray(hexValue);
33
- }
34
- function checkString(value) {
35
- return value !== null && typeof value == "string" && value.length > 0;
36
- }
37
- function checkArray(value, predicate, requiredLength) {
38
- if (!Array.isArray(value)) return false;
39
- if (typeof requiredLength == "number" && requiredLength !== value.length) return false;
40
- for (const item of value)
41
- if (typeof predicate == "function" && !predicate(item))
42
- return false;
43
- return true;
44
- }
45
- function checkNumberArray(value, requiredLength) {
46
- return checkArray(value, checkNumber, requiredLength);
47
- }
48
- function checkStringArray(value, requiredLength) {
49
- return checkArray(value, checkString, requiredLength);
50
- }
51
- function hasProperty(value, propertyName, type) {
52
- return value !== null && typeof value == "object" && propertyName in value && typeof value[propertyName] == type;
53
- }
54
- var NodeJSCustomInspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
55
-
56
19
  // source/common/error.ts
57
20
  var ResolveError = class extends Error {
58
21
  /**
@@ -67,6 +30,9 @@ var ResolveError = class extends Error {
67
30
  }
68
31
  };
69
32
 
33
+ // source/vectors/vec2.ts
34
+ import { isValidNumber, isValidString, hasObjectProperty, NodeJSCustomInspect, isFixedTypeArray, checkValidNumber } from "@ntf/types";
35
+
70
36
  // source/utils.ts
71
37
  function clamp(value, min, max) {
72
38
  if (value <= min)
@@ -104,26 +70,26 @@ var Vec2 = class _Vec2 {
104
70
  static cast(a) {
105
71
  if (a == null || typeof a == "undefined")
106
72
  return void 0;
107
- if (checkNumberArray(a, 2) || checkNumberArray(a, 3))
108
- return new this(a[0], a[1], checkNumber(a[2]) ? a[2] : void 0);
109
- if (hasProperty(a, "toVec2", "function"))
73
+ if (isFixedTypeArray(a, isValidNumber, 2) || isFixedTypeArray(a, isValidNumber, 3))
74
+ return new this(a[0], a[1], a[2]);
75
+ if (hasObjectProperty(a, "toVec2", "function"))
110
76
  return this.cast(a.toVec2());
111
- if (hasProperty(a, "x", "number") && hasProperty(a, "y", "number"))
112
- return new this(a.x, a.y, hasProperty(a, "w", "number") ? a.w : void 0);
113
- if (checkString(a)) {
77
+ if (hasObjectProperty(a, "x", "number") && hasObjectProperty(a, "y", "number"))
78
+ return new this(a.x, a.y, hasObjectProperty(a, "w", "number") ? a.w : void 0);
79
+ if (isValidString(a)) {
114
80
  const [sxy, sw] = a.split(";");
115
- if (checkString(sxy)) {
81
+ if (isValidString(sxy)) {
116
82
  const parts = sxy.split(",");
117
- if (checkStringArray(parts, 2))
118
- return new this(parseFloat(parts[0]), parseFloat(parts[1]), checkString(sw) ? parseFloat(sw) : void 0);
83
+ if (isFixedTypeArray(parts, isValidString, 2))
84
+ return new this(parseFloat(parts[0]), parseFloat(parts[1]), isValidString(sw) ? parseFloat(sw) : void 0);
119
85
  }
120
86
  }
121
- if (checkNumber(a))
87
+ if (isValidNumber(a))
122
88
  return new this(a, a);
123
89
  return void 0;
124
90
  }
125
91
  static resolveArgs(args) {
126
- if (checkNumberArray(args, 2))
92
+ if (isFixedTypeArray(args, isValidNumber, 2))
127
93
  return new this(args[0], args[1]);
128
94
  return this.resolve(args[0]);
129
95
  }
@@ -149,12 +115,9 @@ var Vec2 = class _Vec2 {
149
115
  return new this(1, 1);
150
116
  }
151
117
  constructor(x, y, w = 1) {
152
- if (!checkNumber(x))
153
- throw new TypeError("expected number for x");
154
- if (!checkNumber(y))
155
- throw new TypeError("expected number for y");
156
- if (!checkNumber(w))
157
- throw new TypeError("expected number for w");
118
+ checkValidNumber(x);
119
+ checkValidNumber(y);
120
+ checkValidNumber(w);
158
121
  this.x = x;
159
122
  this.y = y;
160
123
  this.w = w;
@@ -257,7 +220,7 @@ var Vec2 = class _Vec2 {
257
220
  );
258
221
  }
259
222
  divide(...args) {
260
- if (checkNumberArray(args, 1))
223
+ if (isFixedTypeArray(args, isValidNumber, 1))
261
224
  return new _Vec2(
262
225
  this.x / args[0],
263
226
  this.y / args[0]
@@ -342,17 +305,14 @@ var LinearFunction = class extends MathFunction {
342
305
  */
343
306
  constructor(m, b) {
344
307
  super();
345
- if (!checkNumber(m))
346
- throw new TypeError("expected number for m");
347
- if (!checkNumber(b))
348
- throw new TypeError("expected number for b");
308
+ checkValidNumber2(m);
309
+ checkValidNumber2(b);
349
310
  this.m = m;
350
311
  this.b = b;
351
312
  }
352
313
  get(x) {
353
- if (!checkNumber(x))
354
- throw new TypeError("expected number for x");
355
- return this.m;
314
+ checkValidNumber2(x);
315
+ return this.m * x + this.b;
356
316
  }
357
317
  roots() {
358
318
  const x = -this.b / this.m;
@@ -369,12 +329,13 @@ var LinearFunction = class extends MathFunction {
369
329
  get [Symbol.toStringTag]() {
370
330
  return "LinearFunction";
371
331
  }
372
- [NodeJSCustomInspect]() {
332
+ [NodeJSCustomInspect2]() {
373
333
  return `LinearFunction <${this.toString()}>`;
374
334
  }
375
335
  };
376
336
 
377
337
  // source/algebra/quad.ts
338
+ import { checkValidNumber as checkValidNumber3, ExpectedTypeError, NodeJSCustomInspect as NodeJSCustomInspect3 } from "@ntf/types";
378
339
  var QuadFunction = class extends MathFunction {
379
340
  a;
380
341
  b;
@@ -384,21 +345,17 @@ var QuadFunction = class extends MathFunction {
384
345
  }
385
346
  constructor(a, b, c) {
386
347
  super();
387
- if (!checkNumber(a))
388
- throw new TypeError("expected number for a");
389
- if (a == 0)
390
- throw new TypeError("a cannot be 0");
391
- if (!checkNumber(b))
392
- throw new TypeError("expected number for b");
393
- if (!checkNumber(c))
394
- throw new TypeError("expected number for c");
348
+ checkValidNumber3(a);
349
+ if (a === 0)
350
+ throw new ExpectedTypeError("non-zero valid number", a);
351
+ checkValidNumber3(b);
352
+ checkValidNumber3(c);
395
353
  this.a = a;
396
354
  this.b = b;
397
355
  this.c = c;
398
356
  }
399
357
  get(x) {
400
- if (!checkNumber(x))
401
- throw new TypeError("expected number for x");
358
+ checkValidNumber3(x);
402
359
  return this.a * x * x + this.b * x + this.c;
403
360
  }
404
361
  roots() {
@@ -429,1448 +386,1704 @@ var QuadFunction = class extends MathFunction {
429
386
  get [Symbol.toStringTag]() {
430
387
  return "QuadFunction";
431
388
  }
432
- [NodeJSCustomInspect]() {
389
+ [NodeJSCustomInspect3]() {
433
390
  return `QuadFunction <${this.toString()}>`;
434
391
  }
435
392
  };
436
393
 
437
- // source/crypto/hash.ts
438
- var DJB2_OFFSET = 5381n;
439
- function djb2(value) {
440
- const string = String(value);
441
- let hash = DJB2_OFFSET;
442
- for (let i = 0; i < string.length; i++) {
443
- hash = (hash << 5n) + hash + BigInt(string.charCodeAt(i));
394
+ // source/algebra/quaternion.ts
395
+ import { isValidNumber as isValidNumber3, isValidString as isValidString3, hasObjectProperty as hasObjectProperty3, NodeJSCustomInspect as NodeJSCustomInspect5, isFixedTypeArray as isFixedTypeArray3, checkValidNumber as checkValidNumber5 } from "@ntf/types";
396
+
397
+ // source/vectors/vec3.ts
398
+ import { isValidNumber as isValidNumber2, isValidString as isValidString2, hasObjectProperty as hasObjectProperty2, NodeJSCustomInspect as NodeJSCustomInspect4, isFixedTypeArray as isFixedTypeArray2, checkValidNumber as checkValidNumber4 } from "@ntf/types";
399
+ var Vec3 = class _Vec3 {
400
+ x;
401
+ y;
402
+ z;
403
+ w;
404
+ static resolve(a) {
405
+ const value = this.cast(a);
406
+ if (typeof value != "undefined")
407
+ return value;
408
+ throw new ResolveError("Vec3", a);
444
409
  }
445
- return hash;
446
- }
447
- var FNV1_OFFSET = 14695981039346656037n;
448
- var FNV1_PRIME = 1099511628211n;
449
- function fnv1(value) {
450
- const string = String(value);
451
- let hash = FNV1_OFFSET;
452
- for (let i = 0; i < string.length; i++) {
453
- hash *= FNV1_PRIME;
454
- hash ^= BigInt(string.charCodeAt(i));
410
+ static cast(a) {
411
+ if (a == null || typeof a == "undefined")
412
+ return void 0;
413
+ if (isFixedTypeArray2(a, isValidNumber2, 3) || isFixedTypeArray2(a, isValidNumber2, 4))
414
+ return new this(a[0], a[1], a[2], a[3]);
415
+ if (hasObjectProperty2(a, "x", "number") && hasObjectProperty2(a, "y", "number") && hasObjectProperty2(a, "z", "number"))
416
+ return new this(a.x, a.y, a.z, hasObjectProperty2(a, "w", "number") ? a.w : void 0);
417
+ if (isValidString2(a)) {
418
+ const [sxyz, sw] = a.split(";");
419
+ if (isValidString2(sxyz)) {
420
+ const parts = sxyz.split(",");
421
+ if (isFixedTypeArray2(parts, isValidString2, 3))
422
+ return new this(parseFloat(parts[0]), parseFloat(parts[1]), parseFloat(parts[2]), isValidString2(sw) ? parseFloat(sw) : void 0);
423
+ }
424
+ }
425
+ if (isValidNumber2(a))
426
+ return new this(a, a, a);
427
+ return void 0;
455
428
  }
456
- return hash;
457
- }
458
- function sdbm(value) {
459
- const string = String(value);
460
- let hash = 0n;
461
- for (let i = 0; i < string.length; i++) {
462
- hash = BigInt(string.charCodeAt(i)) + (hash << 6n) + (hash << 16n) - hash;
429
+ static resolveArgs(args) {
430
+ if (isFixedTypeArray2(args, isValidNumber2, 3))
431
+ return new this(args[0], args[1], args[2]);
432
+ return this.resolve(args[0]);
463
433
  }
464
- return hash;
465
- }
466
-
467
- // source/crypto/md2.ts
468
- var STABLE = [
469
- 41,
470
- 46,
471
- 67,
472
- 201,
473
- 162,
474
- 216,
475
- 124,
476
- 1,
477
- 61,
478
- 54,
479
- 84,
480
- 161,
481
- 236,
482
- 240,
483
- 6,
484
- 19,
485
- 98,
486
- 167,
487
- 5,
488
- 243,
489
- 192,
490
- 199,
491
- 115,
492
- 140,
493
- 152,
494
- 147,
495
- 43,
496
- 217,
497
- 188,
498
- 76,
499
- 130,
500
- 202,
501
- 30,
502
- 155,
503
- 87,
504
- 60,
505
- 253,
506
- 212,
507
- 224,
508
- 22,
509
- 103,
510
- 66,
511
- 111,
512
- 24,
513
- 138,
514
- 23,
515
- 229,
516
- 18,
517
- 190,
518
- 78,
519
- 196,
520
- 214,
521
- 218,
522
- 158,
523
- 222,
524
- 73,
525
- 160,
526
- 251,
527
- 245,
528
- 142,
529
- 187,
530
- 47,
531
- 238,
532
- 122,
533
- 169,
534
- 104,
535
- 121,
536
- 145,
537
- 21,
538
- 178,
539
- 7,
540
- 63,
541
- 148,
542
- 194,
543
- 16,
544
- 137,
545
- 11,
546
- 34,
547
- 95,
548
- 33,
549
- 128,
550
- 127,
551
- 93,
552
- 154,
553
- 90,
554
- 144,
555
- 50,
556
- 39,
557
- 53,
558
- 62,
559
- 204,
560
- 231,
561
- 191,
562
- 247,
563
- 151,
564
- 3,
565
- 255,
566
- 25,
567
- 48,
568
- 179,
569
- 72,
570
- 165,
571
- 181,
572
- 209,
573
- 215,
574
- 94,
575
- 146,
576
- 42,
577
- 172,
578
- 86,
579
- 170,
580
- 198,
581
- 79,
582
- 184,
583
- 56,
584
- 210,
585
- 150,
586
- 164,
587
- 125,
588
- 182,
589
- 118,
590
- 252,
591
- 107,
592
- 226,
593
- 156,
594
- 116,
595
- 4,
596
- 241,
597
- 69,
598
- 157,
599
- 112,
600
- 89,
601
- 100,
602
- 113,
603
- 135,
604
- 32,
605
- 134,
606
- 91,
607
- 207,
608
- 101,
609
- 230,
610
- 45,
611
- 168,
612
- 2,
613
- 27,
614
- 96,
615
- 37,
616
- 173,
617
- 174,
618
- 176,
619
- 185,
620
- 246,
621
- 28,
622
- 70,
623
- 97,
624
- 105,
625
- 52,
626
- 64,
627
- 126,
628
- 15,
629
- 85,
630
- 71,
631
- 163,
632
- 35,
633
- 221,
634
- 81,
635
- 175,
636
- 58,
637
- 195,
638
- 92,
639
- 249,
640
- 206,
641
- 186,
642
- 197,
643
- 234,
644
- 38,
645
- 44,
646
- 83,
647
- 13,
648
- 110,
649
- 133,
650
- 40,
651
- 132,
652
- 9,
653
- 211,
654
- 223,
655
- 205,
656
- 244,
657
- 65,
658
- 129,
659
- 77,
660
- 82,
661
- 106,
662
- 220,
663
- 55,
664
- 200,
665
- 108,
666
- 193,
667
- 171,
668
- 250,
669
- 36,
670
- 225,
671
- 123,
672
- 8,
673
- 12,
674
- 189,
675
- 177,
676
- 74,
677
- 120,
678
- 136,
679
- 149,
680
- 139,
681
- 227,
682
- 99,
683
- 232,
684
- 109,
685
- 233,
686
- 203,
687
- 213,
688
- 254,
689
- 59,
690
- 0,
691
- 29,
692
- 57,
693
- 242,
694
- 239,
695
- 183,
696
- 14,
697
- 102,
698
- 88,
699
- 208,
700
- 228,
701
- 166,
702
- 119,
703
- 114,
704
- 248,
705
- 235,
706
- 117,
707
- 75,
708
- 10,
709
- 49,
710
- 68,
711
- 80,
712
- 180,
713
- 143,
714
- 237,
715
- 31,
716
- 26,
717
- 219,
718
- 153,
719
- 141,
720
- 51,
721
- 159,
722
- 17,
723
- 131,
724
- 20
725
- ];
726
- var MD2 = class _MD2 {
727
- static BLOCK_SIZE = 16;
728
- _data = new Uint8Array(16);
729
- _state = new Uint8Array(48);
730
- _checksum = new Uint8Array(16);
731
- _length = 0;
732
- constructor() {
733
- for (let i = 0; i < this._state.length; i++)
734
- this._state[i] = 0;
735
- for (let i = 0; i < this._checksum.length; i++)
736
- this._checksum[i] = 0;
434
+ static is(a) {
435
+ return typeof this.cast(a) != "undefined";
737
436
  }
738
- update(input) {
739
- for (let i = 0; i < input.length; i++) {
740
- this._data[this._length] = input[i];
741
- this._length++;
742
- if (this._length == _MD2.BLOCK_SIZE) {
743
- this._transform(input);
744
- this._length = 0;
745
- }
746
- }
747
- return this;
437
+ static fromPoints(a, b) {
438
+ const veca = this.resolve(a);
439
+ const vecb = this.resolve(b);
440
+ return new this(vecb.x - veca.x, vecb.y - veca.y, vecb.z - veca.z);
748
441
  }
749
- _transform(data) {
750
- for (let i = 0; i < 16; ++i) {
751
- this._state[i + 16] = this._data[i];
752
- this._state[i + 32] = this._state[i + 16] ^ this._state[i];
753
- }
754
- let t = 0;
755
- for (let i = 0; i < 18; ++i) {
756
- for (let j = 0; j < 48; ++j) {
757
- this._state[j] ^= STABLE[t];
758
- t = this._state[j];
759
- }
760
- t = t + i & 255;
761
- }
762
- t = this._checksum[15];
763
- for (let i = 0; i < 16; ++i) {
764
- this._checksum[i] ^= STABLE[this._data[i] ^ t];
765
- t = this._checksum[i];
766
- }
442
+ static clamp(value, min, max) {
443
+ const a = this.resolve(value), b = this.resolve(min), c = this.resolve(max);
444
+ return new this(
445
+ clamp(a.x, b.x, c.x),
446
+ clamp(a.y, b.y, c.y),
447
+ clamp(a.z, b.z, c.z)
448
+ );
767
449
  }
768
- digest() {
769
- const toPad = _MD2.BLOCK_SIZE - this._length;
770
- while (this._length < _MD2.BLOCK_SIZE)
771
- this._data[this._length++] = toPad;
772
- this._transform(this._data);
773
- this._transform(this._checksum);
774
- return this._state.slice();
450
+ static intersectPlane(planeP, planeN, lineStart, lineEnd, t) {
451
+ planeN = this.resolve(planeN).normalize();
452
+ const plane_d = -this.resolve(planeN).dot(planeP);
453
+ const ad = this.resolve(lineStart).dot(planeN);
454
+ const bd = this.resolve(lineEnd).dot(planeN);
455
+ t = (-plane_d - ad) / (bd - ad);
456
+ const lineStartToEnd = this.resolve(lineEnd).subtract(lineStart);
457
+ const linetoIntersect = lineStartToEnd.multiply(t);
458
+ return _Vec3.resolve(lineStart).add(linetoIntersect);
775
459
  }
776
- toString() {
777
- return "";
460
+ static get zero() {
461
+ return new this(0, 0, 0);
778
462
  }
779
- get [Symbol.toStringTag]() {
780
- return "MD2";
463
+ static get one() {
464
+ return new this(1, 1, 1);
781
465
  }
782
- [NodeJSCustomInspect]() {
783
- return `MD2 <${this.toString()}>`;
466
+ constructor(x, y, z, w = 1) {
467
+ checkValidNumber4(x);
468
+ checkValidNumber4(y);
469
+ checkValidNumber4(z);
470
+ checkValidNumber4(w);
471
+ this.x = x;
472
+ this.y = y;
473
+ this.z = z;
474
+ this.w = w;
784
475
  }
785
- };
786
-
787
- // source/geometry/angle.ts
788
- var MAX_ANGLE_DEGREE = 360;
789
- var clampAngleDegree = (angle) => angle % MAX_ANGLE_DEGREE;
790
- var clampAngleRadian = (angle) => clampAngleDegree(degreeToRadian(angle));
791
- var radianToDegree = (angle) => angle * (180 / Math.PI);
792
- var degreeToRadian = (angle) => angle * (Math.PI / 180);
793
-
794
- // source/geometry/circle.ts
795
- var Circle = class _Circle {
796
- radius;
797
- get perimeter() {
798
- return this.radius * Math.PI * 2;
476
+ toArray(w = this.w !== 1) {
477
+ return w ? [this.x, this.y, this.z, this.w] : [this.x, this.y, this.z];
799
478
  }
800
- get area() {
801
- return Math.PI * Math.pow(this.radius, 2);
479
+ toJSON() {
480
+ return {
481
+ x: this.x,
482
+ y: this.y,
483
+ z: this.z,
484
+ w: this.w
485
+ };
802
486
  }
803
- position;
804
- get x() {
805
- return this.position.x;
487
+ toString(w = this.w !== 1) {
488
+ return w ? `${this.x},${this.y},${this.z};${this.w}` : `${this.x},${this.y},${this.z}`;
806
489
  }
807
- set x(val) {
808
- this.position.x = val;
490
+ get [Symbol.toStringTag]() {
491
+ return "Vec3";
809
492
  }
810
- get y() {
811
- return this.position.y;
493
+ [NodeJSCustomInspect4]() {
494
+ return `Vec3 <${this.toString()}>`;
812
495
  }
813
- set y(val) {
814
- this.position.y = val;
496
+ toVec2() {
497
+ return [this.x, this.y, this.w];
815
498
  }
816
- get w() {
817
- return this.position.w;
499
+ toRGB() {
500
+ const vec = this.normalize();
501
+ return [vec.x, vec.y, vec.z];
818
502
  }
819
- set w(val) {
820
- this.position.w = val;
503
+ toRGBA() {
504
+ const vec = this.normalize();
505
+ return [vec.x, vec.y, vec.z, vec.w];
821
506
  }
822
- static resolve(a) {
823
- const value = this.cast(a);
824
- if (typeof value != "undefined")
825
- return value;
826
- throw new ResolveError("Circle", a);
507
+ toHSL() {
508
+ const vec = this.normalize();
509
+ return [vec.x, vec.y, vec.z];
827
510
  }
828
- static resolveArgs(args) {
829
- if (checkNumberArray(args, 3))
830
- return new this([args[0], args[1]], args[2]);
831
- if (args.length === 2)
832
- return new this(args[0], args[1]);
833
- return this.resolve(args[0]);
511
+ toHSLA() {
512
+ const vec = this.normalize();
513
+ return [vec.x, vec.y, vec.z, vec.w];
834
514
  }
835
- static cast(a) {
836
- if (a == null || typeof a == "undefined")
837
- return void 0;
838
- if (checkNumberArray(a, 3))
839
- return new this([a[0], a[1]], a[2]);
840
- if (checkNumberArray(a, 4)) {
841
- const c = new this([a[0], a[1]], a[3]);
842
- c.w = a[2];
843
- return c;
844
- }
845
- if (hasProperty(a, "toCircle", "function"))
846
- return this.cast(a.toCircle());
847
- if (hasProperty(a, "x", "number") && hasProperty(a, "y", "number") && hasProperty(a, "radius", "number"))
848
- return new this(hasProperty(a, "w", "number") ? [a.x, a.y, a.w] : [a.x, a.y], a.radius);
849
- if (checkString(a)) {
850
- const [spos, sradius] = a.split("|");
851
- const pos = Vec2.cast(spos);
852
- if (typeof pos == "undefined")
853
- return void 0;
854
- const radius = parseFloat(sradius);
855
- if (!isNaN(radius))
856
- return new this(pos, radius);
857
- }
858
- return void 0;
515
+ toQuaternion() {
516
+ return [this.w, this.x, this.y, this.z];
859
517
  }
860
- static is(a) {
861
- return typeof this.cast(a) != "undefined";
518
+ clone() {
519
+ return new _Vec3(this.x, this.y, this.z, this.w);
862
520
  }
863
- constructor(position, radius) {
864
- this.position = Vec2.resolve(position);
865
- if (!checkNumber(radius))
866
- throw new TypeError("expected number for radius");
867
- this.radius = radius;
521
+ equals(...args) {
522
+ const a = _Vec3.resolveArgs(args);
523
+ return this.x == a.x && this.y == a.y && this.z == a.z;
868
524
  }
869
- toArray() {
870
- return [...this.position.toArray(), this.radius];
525
+ setX(x) {
526
+ this.x = x;
527
+ return this;
871
528
  }
872
- toJSON() {
873
- return {
874
- ...this.position.toJSON(),
875
- radius: this.radius
876
- };
529
+ setY(y) {
530
+ this.y = y;
531
+ return this;
877
532
  }
878
- toString() {
879
- return `${this.position.toString()}|${this.radius}`;
533
+ setZ(z) {
534
+ this.z = z;
535
+ return this;
880
536
  }
881
- get [Symbol.toStringTag]() {
882
- return "Circle";
537
+ set(...args) {
538
+ const vec = _Vec3.resolveArgs(args);
539
+ return this.setX(vec.x).setY(vec.y).setZ(vec.z);
883
540
  }
884
- [NodeJSCustomInspect]() {
885
- return `Circle <${this.toString()}>`;
541
+ add(...args) {
542
+ const vec = _Vec3.resolveArgs(args);
543
+ return new _Vec3(
544
+ this.x + vec.x,
545
+ this.y + vec.y,
546
+ this.z + vec.z
547
+ );
886
548
  }
887
- clone() {
888
- return new _Circle(this.position.clone(), this.radius);
549
+ offset(...args) {
550
+ const vec = _Vec3.resolveArgs(args);
551
+ this.x += vec.x;
552
+ this.y += vec.y;
553
+ this.z += vec.z;
554
+ return this;
889
555
  }
890
- toVec2() {
891
- return [this.x, this.y, this.w];
556
+ subtract(...args) {
557
+ const vec = _Vec3.resolveArgs(args);
558
+ return new _Vec3(
559
+ this.x - vec.x,
560
+ this.y - vec.y,
561
+ this.z - vec.z
562
+ );
892
563
  }
893
- equals(...args) {
894
- const c = _Circle.resolveArgs(args);
895
- return c.position.equals(c.position) && this.radius == c.radius;
564
+ multiply(scalar) {
565
+ return new _Vec3(
566
+ this.x * scalar,
567
+ this.y * scalar,
568
+ this.z * scalar
569
+ );
896
570
  }
897
- inside(...args) {
898
- const circle = _Circle.resolveArgs(args);
899
- const distX = circle.x - this.x;
900
- const distY = circle.y - this.y;
901
- const dist = Math.sqrt(distX * distX + (distY + distY));
902
- return dist <= this.radius + circle.radius;
571
+ naiveMultiply(...args) {
572
+ const vec = _Vec3.resolveArgs(args);
573
+ return new _Vec3(
574
+ this.x * vec.x,
575
+ this.y * vec.y,
576
+ this.z * vec.z
577
+ );
903
578
  }
904
- insidePoint(...args) {
905
- return this.position.distance(Vec2.resolveArgs(args)) <= this.radius;
579
+ divide(...args) {
580
+ if (isFixedTypeArray2(args, isValidNumber2, 1))
581
+ return new _Vec3(
582
+ this.x / args[0],
583
+ this.y / args[0],
584
+ this.z / args[0]
585
+ );
586
+ const vec = _Vec3.resolveArgs(args);
587
+ return new _Vec3(
588
+ this.x / vec.x,
589
+ this.y / vec.y,
590
+ this.z / vec.z
591
+ );
906
592
  }
907
- };
908
-
909
- // source/geometry/bbox.ts
910
- var BoundingBox = class _BoundingBox {
911
- left;
912
- right;
913
- top;
914
- bottom;
915
- get width() {
916
- return this.right - this.left;
593
+ dot(...args) {
594
+ const vec = _Vec3.resolveArgs(args);
595
+ return this.x * vec.x + this.y * vec.y + this.z * vec.z;
917
596
  }
918
- set width(val) {
919
- this.right = this.left + val;
597
+ cross(...args) {
598
+ const vec = _Vec3.resolveArgs(args);
599
+ return new _Vec3(
600
+ this.y * vec.z - this.z * vec.y,
601
+ this.z * vec.x - this.x * vec.z,
602
+ this.x * vec.y - this.y * vec.x
603
+ );
920
604
  }
921
- get height() {
922
- return this.bottom - this.top;
605
+ distance(...args) {
606
+ const vec = _Vec3.resolveArgs(args);
607
+ return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2);
923
608
  }
924
- set height(val) {
925
- this.bottom = this.top + val;
609
+ distanceSquare(...args) {
610
+ const vec = _Vec3.resolveArgs(args);
611
+ return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2));
926
612
  }
927
- get x() {
928
- return this.left;
613
+ length() {
614
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
929
615
  }
930
- set x(x) {
931
- this.left = x;
616
+ normalize() {
617
+ const length = this.length();
618
+ if (length == 0) return _Vec3.zero;
619
+ return new _Vec3(
620
+ this.x / length,
621
+ this.y / length,
622
+ this.z / length,
623
+ this.w / length
624
+ );
932
625
  }
933
- get y() {
934
- return this.top;
626
+ invert() {
627
+ return this.multiply(-1);
935
628
  }
936
- set y(y) {
937
- this.top = y;
629
+ round() {
630
+ return new _Vec3(Math.round(this.x), Math.round(this.y), Math.round(this.z), Math.round(this.w));
631
+ }
632
+ };
633
+
634
+ // source/algebra/quaternion.ts
635
+ var Quaternion = class _Quaternion {
636
+ w;
637
+ x;
638
+ y;
639
+ z;
640
+ static is(a) {
641
+ return typeof this.cast(a) != "undefined";
938
642
  }
939
- w = 1;
940
643
  static resolve(a) {
941
644
  const value = this.cast(a);
942
645
  if (typeof value != "undefined")
943
646
  return value;
944
- throw new ResolveError("BoundingBox", a);
647
+ throw new ResolveError("Quaternion", a);
945
648
  }
946
649
  static resolveArgs(args) {
947
- if (checkNumberArray(args, 4))
650
+ if (isFixedTypeArray3(args, isValidNumber3, 4))
948
651
  return new this(args[0], args[1], args[2], args[3]);
949
652
  return this.resolve(args[0]);
950
653
  }
951
654
  static cast(a) {
952
655
  if (a == null || typeof a == "undefined")
953
656
  return void 0;
954
- if (checkNumberArray(a, 4))
657
+ if (isFixedTypeArray3(a, isValidNumber3, 4))
955
658
  return new this(a[0], a[1], a[2], a[3]);
956
- if (hasProperty(a, "toBoundingBox", "function"))
957
- return this.cast(a.toBoundingBox());
958
- if (hasProperty(a, "left", "number") && hasProperty(a, "right", "number") && hasProperty(a, "top", "number") && hasProperty(a, "bottom", "number"))
959
- return new this(a.left, a.right, a.top, a.bottom);
960
- if (checkString(a)) {
961
- const parts = a.split(",");
962
- if (checkStringArray(parts, 4))
963
- return this.cast(parts.map((v) => parseFloat(v)));
659
+ if (hasObjectProperty3(a, "toQuaternion", "function"))
660
+ return this.cast(a.toQuaternion());
661
+ if (hasObjectProperty3(a, "w", "number") && hasObjectProperty3(a, "x", "number") && hasObjectProperty3(a, "y", "number") && hasObjectProperty3(a, "z", "number"))
662
+ return new this(a.w, a.x, a.y, a.z);
663
+ if (isValidString3(a)) {
664
+ const parts = a.replaceAll(" ", "").split("+");
665
+ if (isFixedTypeArray3(parts, isValidString3, 4)) {
666
+ const [sw, sxi, syj, szk] = parts;
667
+ if (sxi.endsWith("i") && syj.endsWith("j") && szk.endsWith("k"))
668
+ return this.cast([
669
+ parseFloat(sw),
670
+ parseFloat(sxi.substring(0, sxi.length - 1)),
671
+ parseFloat(syj.substring(0, syj.length - 1)),
672
+ parseFloat(szk.substring(0, szk.length - 1))
673
+ ]);
674
+ }
964
675
  }
965
676
  return void 0;
966
677
  }
967
- static is(a) {
968
- return typeof this.cast(a) != "undefined";
678
+ static fromAxisAngle(...args) {
679
+ const axis = isFixedTypeArray3(args, isValidNumber3, 4) ? new Vec3(args[0], args[1], args[2]) : Vec3.resolve(args[0]);
680
+ const angle = isFixedTypeArray3(args, isValidNumber3, 4) ? args[3] : args[1];
681
+ const vec = Vec3.resolve(axis);
682
+ const hangle = angle * 0.5;
683
+ const sin2 = Math.sin(hangle);
684
+ const cos2 = Math.cos(hangle);
685
+ const length = sin2 / Math.sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z);
686
+ return new this(cos2, vec.x * length, vec.y * length, vec.z * length);
969
687
  }
970
- constructor(left, right, top, bottom) {
971
- if (!checkNumber(left))
972
- throw new TypeError("expected number for left");
973
- if (!checkNumber(right))
974
- throw new TypeError("expected number for right");
975
- if (!checkNumber(top))
976
- throw new TypeError("expected number for top");
977
- if (!checkNumber(bottom))
978
- throw new TypeError("expected number for bottom");
979
- this.left = left;
980
- this.right = right;
981
- this.top = top;
982
- this.bottom = bottom;
688
+ static fromEuler(...args) {
689
+ const vec = Vec3.resolveArgs(args);
690
+ const x2 = vec.x * 0.5, y2 = vec.y * 0.5, z2 = vec.z * 0.5;
691
+ const cx = Math.cos(x2), cy = Math.cos(y2), cz = Math.cos(z2);
692
+ const sx = Math.sin(x2), sy = Math.sin(y2), sz = Math.sin(z2);
693
+ return new _Quaternion(
694
+ cx * cy * cz - sx * sy * sz,
695
+ sx * cy * cz - sy * sz * cx,
696
+ sy * cx * cz - sx * sz * cy,
697
+ sx * sy * cz + sz * cx * cy
698
+ );
699
+ }
700
+ static get zero() {
701
+ return new _Quaternion(0, 0, 0, 0);
702
+ }
703
+ constructor(w, x, y, z) {
704
+ checkValidNumber5(w);
705
+ checkValidNumber5(x);
706
+ checkValidNumber5(y);
707
+ checkValidNumber5(z);
708
+ this.w = w;
709
+ this.x = x;
710
+ this.y = y;
711
+ this.z = z;
983
712
  }
984
713
  toArray() {
985
- return [this.left, this.right, this.top, this.bottom];
714
+ return [this.w, this.x, this.y, this.z];
986
715
  }
987
716
  toString() {
988
- return `${this.left},${this.right},${this.top},${this.bottom}`;
717
+ return `${this.w} + ${this.x}i + ${this.y}j + ${this.z}k`;
989
718
  }
990
719
  get [Symbol.toStringTag]() {
991
- return "BoundingBox";
720
+ return "Quaternion";
992
721
  }
993
- [NodeJSCustomInspect]() {
994
- return `BoundingBox <${this.toString()}>`;
722
+ [NodeJSCustomInspect5]() {
723
+ return `Quaternion <${this.toString()}>`;
995
724
  }
996
725
  toJSON() {
997
726
  return {
998
- left: this.left,
999
- top: this.top,
1000
- right: this.right,
1001
- bottom: this.bottom
727
+ w: this.w,
728
+ x: this.x,
729
+ y: this.y,
730
+ z: this.z
1002
731
  };
1003
732
  }
1004
733
  clone() {
1005
- return new _BoundingBox(this.left, this.right, this.top, this.bottom);
734
+ return new _Quaternion(this.w, this.x, this.y, this.z);
1006
735
  }
1007
- equals(...args) {
1008
- const b = _BoundingBox.resolveArgs(args);
1009
- return this.left === b.left && this.right === b.right && this.top === b.top && this.bottom === b.bottom;
736
+ add(...args) {
737
+ const quat = _Quaternion.resolveArgs(args);
738
+ return new _Quaternion(
739
+ this.w + quat.w,
740
+ this.x + quat.x,
741
+ this.y + quat.y,
742
+ this.z + quat.z
743
+ );
1010
744
  }
1011
- toSize() {
1012
- return [this.width, this.height];
745
+ offset(...args) {
746
+ const quat = _Quaternion.resolveArgs(args);
747
+ this.w += quat.w;
748
+ this.x += quat.x;
749
+ this.y += quat.y;
750
+ this.z += quat.z;
751
+ return this;
1013
752
  }
1014
- toVec2() {
1015
- return [this.left, this.top];
753
+ subtract(...args) {
754
+ const quat = _Quaternion.resolveArgs(args);
755
+ return new _Quaternion(
756
+ this.w - quat.w,
757
+ this.x - quat.x,
758
+ this.y - quat.y,
759
+ this.z - quat.z
760
+ );
1016
761
  }
1017
- toRectangle() {
1018
- return [this.left, this.top, this.width, this.height];
762
+ negative() {
763
+ return new _Quaternion(-this.w, -this.x, -this.y, -this.z);
1019
764
  }
1020
- inside(...args) {
1021
- const bbox = _BoundingBox.resolve(args);
1022
- return this.right >= bbox.left && bbox.right >= this.left && this.bottom >= bbox.top && bbox.bottom >= this.top;
765
+ length(sqrt = true) {
766
+ const value = this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z;
767
+ return sqrt ? Math.sqrt(value) : value;
1023
768
  }
1024
- insidePoint(...args) {
1025
- const point = Vec2.resolveArgs(args);
1026
- return this.left <= point.x && this.right >= point.x && this.top <= point.y && this.bottom >= point.y;
769
+ normalize() {
770
+ let length = this.length();
771
+ if (length < EPSILON)
772
+ return _Quaternion.zero;
773
+ length = 1 / length;
774
+ return new _Quaternion(this.w * length, this.x * length, this.y * length, this.z * length);
1027
775
  }
1028
- insideCircle(...args) {
1029
- const circle = Circle.resolveArgs(args);
1030
- const center = Vec2.resolve(circle).add(circle.radius);
1031
- const bboxhe = new Vec2(this.width / 2, this.height / 2);
1032
- const bboxcenter = new Vec2(this.left + bboxhe.x, this.top + bboxhe.y);
1033
- let diff = center.subtract(bboxcenter);
1034
- const clamped = Vec2.clamp(diff, bboxhe.invert(), bboxhe);
1035
- const closest = bboxcenter.add(clamped);
1036
- diff = closest.subtract(center);
1037
- return diff.length() < circle.radius;
776
+ multiply(...args) {
777
+ const quat = _Quaternion.resolveArgs(args);
778
+ return new _Quaternion(
779
+ this.w * quat.w - this.x * quat.x - this.y * quat.y - this.z * quat.z,
780
+ this.w * quat.x + this.x * quat.w + this.y * quat.z - this.z * quat.y,
781
+ this.w * quat.y + this.y * quat.w + this.z * quat.x - this.x * quat.z,
782
+ this.w * quat.z + this.z * quat.w + this.x * quat.y - this.y * quat.x
783
+ );
784
+ }
785
+ multiplyVector(...args) {
786
+ const vec = Vec3.resolveArgs(args);
787
+ const ix = this.w * vec.x + this.y * vec.y - this.z * vec.y;
788
+ const iy = this.w * vec.y + this.z * vec.x - this.x * vec.z;
789
+ const iz = this.w * vec.z + this.x * vec.y - this.y * vec.x;
790
+ const iw = -this.w * vec.x - this.y * vec.y - this.z * vec.z;
791
+ return new Vec3(
792
+ ix * this.w + iw * -this.x + iy * -this.z - iz * -this.y,
793
+ iy * this.w + iw * -this.y + iz * -this.x - ix * -this.z,
794
+ iz * this.w + iw * -this.z + ix * -this.y - iy * -this.x
795
+ );
796
+ }
797
+ scale(scalar) {
798
+ return new _Quaternion(this.w * scalar, this.x * scalar, this.y * scalar, this.z * scalar);
799
+ }
800
+ dot(...args) {
801
+ const quat = _Quaternion.resolveArgs(args);
802
+ return this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z;
803
+ }
804
+ inverse() {
805
+ let length = this.length(false);
806
+ if (length == 0)
807
+ return _Quaternion.zero;
808
+ length = 1 / length;
809
+ return new _Quaternion(this.w * length, -this.x * length, -this.y * length, -this.z * length);
810
+ }
811
+ divide(...args) {
812
+ const quat = _Quaternion.resolveArgs(args);
813
+ let length = quat.length(false);
814
+ if (length == 0) return _Quaternion.zero;
815
+ length = 1 / length;
816
+ return new _Quaternion(
817
+ (this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z) * length,
818
+ (this.x * quat.w - this.w * quat.x - this.y * quat.z + this.z * quat.y) * length,
819
+ (this.y * quat.w - this.w * quat.y - this.z * quat.x + this.x * quat.z) * length,
820
+ (this.z * quat.w - this.w * quat.z - this.x * quat.y + this.y * quat.x) * length
821
+ );
822
+ }
823
+ conjugate() {
824
+ return new _Quaternion(this.w, -this.x, -this.y, -this.z);
825
+ }
826
+ exp() {
827
+ const length = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
828
+ const exp = Math.exp(this.w);
829
+ const scale = exp * Math.sin(length) / length;
830
+ if (length == 0)
831
+ return new _Quaternion(exp, 0, 0, 0);
832
+ return new _Quaternion(
833
+ exp * Math.cos(length),
834
+ this.x * scale,
835
+ this.y * scale,
836
+ this.z * scale
837
+ );
838
+ }
839
+ log() {
840
+ if (this.x == 0 && this.z == 0)
841
+ return new _Quaternion(logHypot(this.w, this.x), Math.atan2(this.x, this.w), 0, 0);
842
+ const length = this.length(false);
843
+ const length2 = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
844
+ const scale = Math.atan2(length2, this.w) / length;
845
+ return new _Quaternion(Math.log(length) * 0.5, this.x * scale, this.y * scale, this.z * scale);
846
+ }
847
+ toVec3() {
848
+ return [this.x, this.y, this.z, this.w];
849
+ }
850
+ toAxisAngle() {
851
+ const sin2 = 1 - this.w * this.w;
852
+ if (sin2 > EPSILON)
853
+ return new Vec3(this.x, this.y, this.z, 0);
854
+ const isin = 1 / Math.sqrt(sin2);
855
+ const angle = 2 * Math.acos(this.w);
856
+ return new Vec3(this.x * isin, this.y * isin, this.z * isin, angle);
857
+ }
858
+ toEuler() {
859
+ function __asin__(t) {
860
+ return t >= 1 ? Math.PI / 2 : t <= -1 ? -Math.PI / 2 : Math.asin(t);
861
+ }
862
+ return new Vec3(
863
+ -Math.atan2(2 * (this.y * this.z - this.w * this.x), 1 - 2 * (this.x * this.x + this.y * this.y)),
864
+ __asin__(2 * (this.x * this.z + this.w * this.y)),
865
+ -Math.atan2(2 * (this.x * this.y - this.w * this.z), 1 - 2 * (this.y * this.y + this.z * this.z))
866
+ );
867
+ }
868
+ toMat3() {
869
+ return [
870
+ 1 - 2 * (this.y * this.y + this.z * this.z),
871
+ 2 * (this.x * this.y - this.w * this.z),
872
+ 2 * (this.x * this.z + this.w * this.y),
873
+ 2 * (this.x * this.y + this.w * this.z),
874
+ 1 - 2 * (this.x * this.x + this.z * this.z),
875
+ 2 * (this.y * this.z - this.w * this.x),
876
+ 2 * (this.x * this.z - this.w * this.y),
877
+ 2 * (this.y * this.z + this.w * this.x),
878
+ 1 - 2 * (this.x * this.x + this.y * this.y)
879
+ ];
880
+ }
881
+ toMat4() {
882
+ return [
883
+ 1 - 2 * (this.y * this.y + this.z * this.z),
884
+ 2 * (this.x * this.y - this.w * this.z),
885
+ 2 * (this.x * this.z + this.w * this.y),
886
+ 0,
887
+ 2 * (this.x * this.y + this.w * this.z),
888
+ 1 - 2 * (this.x * this.x + this.z * this.z),
889
+ 2 * (this.y * this.z - this.w * this.x),
890
+ 0,
891
+ 2 * (this.x * this.z - this.w * this.y),
892
+ 2 * (this.y * this.z + this.w * this.x),
893
+ 1 - 2 * (this.x * this.x + this.y * this.y),
894
+ 0,
895
+ 0,
896
+ 0,
897
+ 0,
898
+ 1
899
+ ];
1038
900
  }
1039
901
  };
1040
902
 
1041
- // source/geometry/size.ts
1042
- var Size = class _Size {
1043
- width;
1044
- height;
1045
- get aspectRatio() {
1046
- return this.height / this.width;
903
+ // source/color/hsl.ts
904
+ import { isFixedTypeArray as isFixedTypeArray5, isValidNumber as isValidNumber5, hasObjectProperty as hasObjectProperty5, isValidString as isValidString5, checkValidNumber as checkValidNumber7, NodeJSCustomInspect as NodeJSCustomInspect7 } from "@ntf/types";
905
+
906
+ // source/color/rgb.ts
907
+ import { isFixedTypeArray as isFixedTypeArray4, isValidNumber as isValidNumber4, hasObjectProperty as hasObjectProperty4, isValidString as isValidString4, checkValidNumber as checkValidNumber6, NodeJSCustomInspect as NodeJSCustomInspect6 } from "@ntf/types";
908
+
909
+ // source/color/utils.ts
910
+ function numberToRGB(number) {
911
+ const blue = number & 255;
912
+ const green = (number & 65280) >>> 8;
913
+ const red = (number & 16711680) >>> 16;
914
+ return [red / 255, green / 255, blue / 255];
915
+ }
916
+ function numberToRGBA(number) {
917
+ const alpha = number & 255;
918
+ const blue = (number & 65280) >>> 8;
919
+ const green = (number & 16711680) >>> 16;
920
+ const red = (number & 4278190080) >>> 24;
921
+ return [red / 255, green / 255, blue / 255, alpha / 255];
922
+ }
923
+
924
+ // source/color/rgb.ts
925
+ var RGBA = class _RGBA {
926
+ _red;
927
+ get red() {
928
+ return this._red;
1047
929
  }
1048
- get area() {
1049
- return this.width * this.height;
930
+ set red(val) {
931
+ this._red = clamp(val, 0, 1);
1050
932
  }
1051
- get perimeter() {
1052
- return this.width + this.width + this.height + this.height;
933
+ _green;
934
+ get green() {
935
+ return this._green;
936
+ }
937
+ set green(val) {
938
+ this._green = clamp(val, 0, 1);
939
+ }
940
+ _blue;
941
+ get blue() {
942
+ return this._blue;
943
+ }
944
+ set blue(val) {
945
+ this._blue = clamp(val, 0, 1);
946
+ }
947
+ _alpha;
948
+ get alpha() {
949
+ return this._alpha;
950
+ }
951
+ set alpha(val) {
952
+ this._alpha = clamp(val, 0, 1);
1053
953
  }
1054
954
  static resolve(a) {
1055
955
  const value = this.cast(a);
1056
956
  if (typeof value != "undefined")
1057
957
  return value;
1058
- throw new ResolveError("Square", a);
958
+ throw new ResolveError("RGBAColor", a);
1059
959
  }
1060
960
  static resolveArgs(args) {
1061
- if (checkNumberArray(args, 2))
1062
- return new this(args[0], args[1]);
961
+ if (isFixedTypeArray4(args, isValidNumber4, 3) || isFixedTypeArray4(args, isValidNumber4, 4))
962
+ return new this(args[0], args[1], args[2], args[3]);
1063
963
  return this.resolve(args[0]);
1064
964
  }
1065
965
  static cast(a) {
1066
966
  if (a == null || typeof a == "undefined")
1067
967
  return void 0;
1068
- if (checkNumberArray(a, 2))
1069
- return new this(a[0], a[1]);
1070
- if (hasProperty(a, "toSize", "function"))
1071
- return this.cast(a.toSize());
1072
- if (hasProperty(a, "width", "number") && hasProperty(a, "height", "number"))
1073
- return new this(a.width, a.height);
1074
- if (checkString(a)) {
1075
- const parts = a.split("x").map((v) => parseFloat(v));
1076
- if (checkNumberArray(parts, 2))
1077
- return this.cast(parts);
968
+ if (isFixedTypeArray4(a, isValidNumber4, 3) || isFixedTypeArray4(a, isValidNumber4, 4))
969
+ return new this(a[0], a[1], a[2], a[3]);
970
+ if (hasObjectProperty4(a, "toRGB", "function"))
971
+ return this.cast(a.toRGB());
972
+ if (hasObjectProperty4(a, "toRGBA", "function"))
973
+ return this.cast(a.toRGBA());
974
+ if (hasObjectProperty4(a, "red", "number") && hasObjectProperty4(a, "green", "number") && hasObjectProperty4(a, "blue", "number"))
975
+ return new this(a.red, a.green, a.blue, hasObjectProperty4(a, "alpha", "number") ? a.alpha : void 0);
976
+ if (isValidNumber4(a)) {
977
+ const hex = a.toString(16);
978
+ const convert = hex.length <= 6 ? numberToRGB : numberToRGBA;
979
+ return this.cast(convert(a));
980
+ }
981
+ if (isValidString4(a)) {
982
+ if (a.startsWith("rgb")) {
983
+ const hasAlpha = a.startsWith("rgba");
984
+ const offset = hasAlpha ? 5 : 4;
985
+ const parts = a.substring(offset, a.indexOf(")", offset)).split(",");
986
+ if (isFixedTypeArray4(parts, isValidString4, hasAlpha ? 4 : 3))
987
+ return this.cast(parts.map((v) => parseInt(v) / 255));
988
+ }
1078
989
  }
1079
- if (checkNumber(a))
1080
- return new this(a, a);
1081
990
  return void 0;
1082
991
  }
1083
992
  static is(a) {
1084
993
  return typeof this.cast(a) != "undefined";
1085
994
  }
1086
- constructor(width, height) {
1087
- if (!checkNumber(width))
1088
- throw new TypeError("expected number for width");
1089
- if (!checkNumber(height))
1090
- throw new TypeError("expected number for height");
1091
- this.width = width;
1092
- this.height = height;
995
+ constructor(red, green, blue, alpha = 1) {
996
+ checkValidNumber6(red);
997
+ checkValidNumber6(green);
998
+ checkValidNumber6(blue);
999
+ checkValidNumber6(alpha);
1000
+ this._red = clamp(red, 0, 1);
1001
+ this._green = clamp(green, 0, 1);
1002
+ this._blue = clamp(blue, 0, 1);
1003
+ this._alpha = clamp(alpha, 0, 1);
1093
1004
  }
1094
- toArray() {
1095
- return [this.width, this.height];
1005
+ toArray(withAlpha = this._alpha !== 1) {
1006
+ return withAlpha ? [this.red, this.green, this.blue, this.alpha] : [this.red, this.green, this.blue];
1096
1007
  }
1097
- toString() {
1098
- return `${this.width}x${this.height}`;
1008
+ toJSON(withAlpha = this._alpha !== 1) {
1009
+ return withAlpha ? {
1010
+ red: this.red,
1011
+ green: this.green,
1012
+ blue: this.blue,
1013
+ alpha: this.alpha
1014
+ } : {
1015
+ red: this.red,
1016
+ green: this.green,
1017
+ blue: this.blue
1018
+ };
1019
+ }
1020
+ toString(withAlpha = this._alpha !== 1) {
1021
+ return withAlpha ? `rgba(${clamp(this.red * 255 | 0, 0, 255)},${clamp(this.green * 255 | 0, 0, 255)},${clamp(this.blue * 255 | 0, 0, 255)},${this.alpha})` : `rgb(${clamp(this.red * 255 | 0, 0, 255)},${clamp(this.green * 255 | 0, 0, 255)},${clamp(this.blue * 255 | 0, 0, 255)})`;
1099
1022
  }
1100
1023
  get [Symbol.toStringTag]() {
1101
- return "Size";
1024
+ return "RGBA";
1102
1025
  }
1103
- [NodeJSCustomInspect]() {
1104
- return `Size <${this.toString()}>`;
1026
+ [NodeJSCustomInspect6]() {
1027
+ return `RGBA <${this.toString()}>`;
1105
1028
  }
1106
- toJSON() {
1107
- return {
1108
- width: this.width,
1109
- height: this.height
1110
- };
1029
+ toVec2() {
1030
+ return [this.red, this.green, this.blue];
1111
1031
  }
1112
- clone() {
1113
- return new _Size(this.width, this.height);
1032
+ toVec3() {
1033
+ return [this.red, this.green, this.blue, this.alpha];
1114
1034
  }
1115
- equals(...args) {
1116
- const s = _Size.resolveArgs(args);
1117
- return this.width == s.width && this.height == s.height;
1035
+ toHSL(withAlpha = this._alpha !== 1) {
1036
+ const red = this.red, green = this.green, blue = this.blue;
1037
+ const min = Math.min(red, green, blue), max = Math.max(red, green, blue);
1038
+ const luminace = (min + max) / 2;
1039
+ if (min == max)
1040
+ return new HSLA(0, 0, luminace, withAlpha ? this.alpha : void 0);
1041
+ const d = max - min;
1042
+ const saturation = luminace > 0.5 ? d / (2 - max - min) : d / (max + min);
1043
+ if (max == red)
1044
+ return new HSLA(((green - blue) / d + (green < blue ? 6 : 0)) / 6, saturation, luminace, withAlpha ? this.alpha : void 0);
1045
+ if (max == green)
1046
+ return new HSLA(((blue - red) / d + 2) / 6, saturation, luminace, withAlpha ? this.alpha : void 0);
1047
+ if (max == blue)
1048
+ return new HSLA(((red - green) / d + 4) / 6, saturation, luminace, withAlpha ? this.alpha : void 0);
1049
+ return new HSLA(0, saturation, luminace, withAlpha ? this.alpha : void 0);
1118
1050
  }
1119
- toVec2() {
1120
- return [this.width, this.height];
1051
+ toHSLA() {
1052
+ return this.toHSL(true);
1053
+ }
1054
+ invert(withAlpha = this._alpha !== 1) {
1055
+ return new _RGBA(
1056
+ 1 - this.red,
1057
+ 1 - this.green,
1058
+ 1 - this.blue,
1059
+ withAlpha ? 1 - this.alpha : this.alpha
1060
+ );
1121
1061
  }
1122
1062
  };
1123
1063
 
1124
- // source/geometry/rectangle.ts
1125
- var Rectangle = class _Rectangle {
1126
- position;
1127
- size;
1128
- get area() {
1129
- return this.width * this.height;
1130
- }
1131
- get perimeter() {
1132
- return this.width + this.width + this.height + this.height;
1133
- }
1134
- get x() {
1135
- return this.position.x;
1136
- }
1137
- set x(val) {
1138
- this.position.x = val;
1139
- }
1140
- get y() {
1141
- return this.position.y;
1064
+ // source/color/hsl.ts
1065
+ var HSLA = class _HSLA {
1066
+ _hue;
1067
+ get hue() {
1068
+ return this._hue;
1142
1069
  }
1143
- set y(val) {
1144
- this.position.y = val;
1070
+ set hue(val) {
1071
+ this._hue = clamp(val, 0, 1);
1145
1072
  }
1146
- get w() {
1147
- return this.position.w;
1073
+ _saturation;
1074
+ get saturation() {
1075
+ return this._saturation;
1148
1076
  }
1149
- set w(val) {
1150
- this.position.w = val;
1077
+ set saturation(val) {
1078
+ this._saturation = clamp(val, 0, 1);
1151
1079
  }
1152
- get width() {
1153
- return this.size.width;
1080
+ _luminace;
1081
+ get luminace() {
1082
+ return this._luminace;
1154
1083
  }
1155
- set width(val) {
1156
- this.size.width = val;
1084
+ set luminace(val) {
1085
+ this._luminace = clamp(val, 0, 1);
1157
1086
  }
1158
- get height() {
1159
- return this.size.height;
1087
+ _alpha;
1088
+ get alpha() {
1089
+ return this._alpha;
1160
1090
  }
1161
- set height(val) {
1162
- this.size.height = val;
1091
+ set alpha(val) {
1092
+ this._alpha = clamp(val, 0, 1);
1163
1093
  }
1164
1094
  static resolve(a) {
1165
1095
  const value = this.cast(a);
1166
1096
  if (typeof value != "undefined")
1167
1097
  return value;
1168
- throw new ResolveError("Rectangle", a);
1098
+ throw new ResolveError("HSLColor", a);
1169
1099
  }
1170
1100
  static resolveArgs(args) {
1171
- if (checkNumberArray(args, 4))
1172
- return new this([args[0], args[1]], [args[2], args[3]]);
1101
+ if (isFixedTypeArray5(args, isValidNumber5, 3) || isFixedTypeArray5(args, isValidNumber5, 4))
1102
+ return new this(args[0], args[1], args[2], args[3]);
1173
1103
  return this.resolve(args[0]);
1174
1104
  }
1175
1105
  static cast(a) {
1176
1106
  if (a == null || typeof a == "undefined")
1177
1107
  return void 0;
1178
- if (checkNumberArray(a, 4))
1179
- return new this([a[0], a[1]], [a[2], a[3]]);
1180
- if (checkNumberArray(a, 5)) {
1181
- const rect = new this([a[0], a[1]], [a[3], a[4]]);
1182
- rect.w = a[2];
1183
- return rect;
1184
- }
1185
- if (checkString(a)) {
1186
- const [spos, ssize] = a.split("|");
1187
- const pos = Vec2.cast(spos);
1188
- const size = Size.cast(ssize);
1189
- if (typeof pos == "undefined" || typeof size == "undefined")
1190
- return void 0;
1191
- const rect = new this([pos.x, pos.y], [size.width, size.height]);
1192
- rect.w = pos.w;
1193
- return rect;
1108
+ if (isFixedTypeArray5(a, isValidNumber5, 3) || isFixedTypeArray5(a, isValidNumber5, 4))
1109
+ return new this(a[0], a[1], a[2], a[3]);
1110
+ if (hasObjectProperty5(a, "toHSL", "function"))
1111
+ return this.cast(a.toHSL());
1112
+ if (hasObjectProperty5(a, "toHSLA", "function"))
1113
+ return this.cast(a.toHSLA());
1114
+ if (hasObjectProperty5(a, "hue", "number") && hasObjectProperty5(a, "saturation", "number") && hasObjectProperty5(a, "luminace", "number"))
1115
+ return new this(a.hue, a.saturation, a.luminace, hasObjectProperty5(a, "alpha", "number") ? a.alpha : void 0);
1116
+ if (isValidNumber5(a)) {
1117
+ const hex = a.toString(16);
1118
+ const convert = hex.length <= 6 ? numberToRGB : numberToRGBA;
1119
+ return this.cast(convert(a));
1194
1120
  }
1195
- if (hasProperty(a, "toRectangle", "function"))
1196
- return this.cast(a.toRectangle());
1197
- if (hasProperty(a, "x", "number") && hasProperty(a, "y", "number") && hasProperty(a, "width", "number") && hasProperty(a, "height", "number")) {
1198
- const rect = new this([a.x, a.y], [a.width, a.height]);
1199
- if (hasProperty(a, "w", "number"))
1200
- rect.w = a.w;
1201
- return rect;
1121
+ if (isValidString5(a)) {
1122
+ if (a.startsWith("hsl")) {
1123
+ const hasAlpha = a.startsWith("hsla");
1124
+ const offset = hasAlpha ? 5 : 4;
1125
+ const parts = a.substring(offset, a.indexOf(")", offset)).split(",");
1126
+ if (isFixedTypeArray5(parts, isValidString5, hasAlpha ? 4 : 3))
1127
+ return this.cast(parts.map((v) => parseInt(v) / 255));
1128
+ }
1202
1129
  }
1203
1130
  return void 0;
1204
1131
  }
1205
1132
  static is(a) {
1206
1133
  return typeof this.cast(a) != "undefined";
1207
1134
  }
1208
- constructor(pos, size) {
1209
- this.position = Vec2.resolve(pos);
1210
- this.size = Size.resolve(size);
1135
+ constructor(hue, saturation, luminace, alpha = 1) {
1136
+ checkValidNumber7(hue);
1137
+ checkValidNumber7(saturation);
1138
+ checkValidNumber7(luminace);
1139
+ checkValidNumber7(alpha);
1140
+ this._hue = clamp(hue, 0, 1);
1141
+ this._saturation = clamp(saturation, 0, 1);
1142
+ this._luminace = clamp(luminace, 0, 1);
1143
+ this._alpha = clamp(alpha, 0, 1);
1211
1144
  }
1212
- toArray(w = this.w !== 1) {
1213
- return [...this.position.toArray(w), ...this.size.toArray()];
1145
+ toArray(withAlpha = this._alpha !== 1) {
1146
+ return withAlpha ? [this.hue, this.saturation, this.luminace, this.alpha] : [this.hue, this.saturation, this.luminace];
1214
1147
  }
1215
- toString(w = this.w !== 1) {
1216
- return `${this.position.toString(w)}|${this.size.toString()}`;
1148
+ toJSON(withAlpha = this._alpha !== 1) {
1149
+ return withAlpha ? {
1150
+ hue: this.hue,
1151
+ saturation: this.saturation,
1152
+ luminace: this.luminace,
1153
+ alpha: this.alpha
1154
+ } : {
1155
+ hue: this.hue,
1156
+ saturation: this.saturation,
1157
+ luminace: this.luminace
1158
+ };
1159
+ }
1160
+ toString(withAlpha = this._alpha !== 1) {
1161
+ return withAlpha ? `hsla(${clamp(this.hue * 255 | 0, 0, 255)},${clamp(this.saturation * 255 | 0, 0, 255)},${clamp(this.luminace * 255 | 0, 0, 255)},${this.alpha})` : `hsl(${clamp(this.hue * 255 | 0, 0, 255)},${clamp(this.saturation * 255 | 0, 0, 255)},${clamp(this.luminace * 255 | 0, 0, 255)})`;
1217
1162
  }
1218
1163
  get [Symbol.toStringTag]() {
1219
- return "Rectangle";
1164
+ return "HSLA";
1220
1165
  }
1221
- [NodeJSCustomInspect]() {
1222
- return `Rectangle <${this.toString()}>`;
1166
+ [NodeJSCustomInspect7]() {
1167
+ return `HSLA <${this.toString()}>`;
1223
1168
  }
1224
- toJSON() {
1225
- return { ...this.position.toJSON(), ...this.size.toJSON() };
1169
+ toRGB(withAlpha = this._alpha !== 1) {
1170
+ if (this.saturation == 0)
1171
+ return new RGBA(this.luminace * 255, this.luminace * 255, this.luminace * 255, withAlpha ? this.alpha : void 0);
1172
+ const q = this.luminace < 0.5 ? this.luminace * (1 + this.saturation) : this.luminace + this.saturation - this.luminace * this.saturation;
1173
+ const p = 2 * this.luminace - q;
1174
+ function __hue_2_rgb__(t) {
1175
+ let _t = t;
1176
+ if (_t < 0)
1177
+ _t++;
1178
+ if (_t > 1)
1179
+ _t--;
1180
+ if (_t < 1 / 6)
1181
+ return p + (q - p) * 6 * _t;
1182
+ if (_t < 1 / 2)
1183
+ return q;
1184
+ if (_t < 2 / 3)
1185
+ return p + (q - p) * (2 / 3 - _t) * 6;
1186
+ return p;
1187
+ }
1188
+ return new RGBA(__hue_2_rgb__(this.hue + 1 / 3) * 255, __hue_2_rgb__(this.hue) * 255, __hue_2_rgb__(this.hue - 1 / 3) * 255, withAlpha ? this.alpha : void 0);
1226
1189
  }
1227
- toBoundingBox() {
1228
- return [this.x, this.x + this.width, this.y, this.y + this.height];
1190
+ toRGBA() {
1191
+ return this.toRGB(true);
1229
1192
  }
1230
1193
  toVec2() {
1231
- return [this.x, this.y, this.w];
1232
- }
1233
- toSize() {
1234
- return [this.width, this.height];
1194
+ return [this.hue, this.saturation, this.luminace];
1235
1195
  }
1236
- clone() {
1237
- return new _Rectangle(this.position.clone(), this.size.clone());
1196
+ toVec3() {
1197
+ return [this.hue, this.saturation, this.luminace, this.alpha];
1238
1198
  }
1239
- equals(...args) {
1240
- const rect = _Rectangle.resolveArgs(args);
1241
- return this.position.equals(rect.position) && this.size.equals(rect.size);
1199
+ invert(withAlpha = this._alpha !== 1) {
1200
+ return new _HSLA(
1201
+ 1 - this.hue,
1202
+ 1 - this.saturation,
1203
+ 1 - this.luminace,
1204
+ withAlpha ? 1 - this.alpha : this.alpha
1205
+ );
1242
1206
  }
1243
1207
  };
1244
1208
 
1245
- // source/common/string.ts
1246
- function stringify(value) {
1247
- return value != null && typeof value == "object" && "toString" in value && typeof value.toString == "function" ? value.toString() : String(value);
1248
- }
1249
-
1250
- // source/vectors/vec3.ts
1251
- var Vec3 = class _Vec3 {
1252
- x;
1253
- y;
1254
- z;
1255
- w;
1256
- static resolve(a) {
1257
- const value = this.cast(a);
1258
- if (typeof value != "undefined")
1259
- return value;
1260
- throw new ResolveError("Vec3", a);
1261
- }
1262
- static cast(a) {
1263
- if (a == null || typeof a == "undefined")
1264
- return void 0;
1265
- if (checkNumberArray(a, 3) || checkNumberArray(a, 4))
1266
- return new this(a[0], a[1], a[2], checkNumber(a[3]) ? a[3] : void 0);
1267
- if (hasProperty(a, "x", "number") && hasProperty(a, "y", "number") && hasProperty(a, "z", "number"))
1268
- return new this(a.x, a.y, a.z, hasProperty(a, "w", "number") ? a.w : void 0);
1269
- if (checkString(a)) {
1270
- const [sxyz, sw] = a.split(";");
1271
- if (checkString(sxyz)) {
1272
- const parts = sxyz.split(",");
1273
- if (checkStringArray(parts, 3))
1274
- return new this(parseFloat(parts[0]), parseFloat(parts[1]), parseFloat(parts[2]), checkString(sw) ? parseFloat(sw) : void 0);
1275
- }
1276
- }
1277
- if (checkNumber(a))
1278
- return new this(a, a, a);
1279
- return void 0;
1280
- }
1281
- static resolveArgs(args) {
1282
- if (checkNumberArray(args, 3))
1283
- return new this(args[0], args[1], args[2]);
1284
- return this.resolve(args[0]);
1209
+ // source/crypto/hash.ts
1210
+ var DJB2_OFFSET = 5381n;
1211
+ function djb2(value) {
1212
+ const string = String(value);
1213
+ let hash = DJB2_OFFSET;
1214
+ for (let i = 0; i < string.length; i++) {
1215
+ hash = (hash << 5n) + hash + BigInt(string.charCodeAt(i));
1285
1216
  }
1286
- static is(a) {
1287
- return typeof this.cast(a) != "undefined";
1217
+ return hash;
1218
+ }
1219
+ var FNV1_OFFSET = 14695981039346656037n;
1220
+ var FNV1_PRIME = 1099511628211n;
1221
+ function fnv1(value) {
1222
+ const string = String(value);
1223
+ let hash = FNV1_OFFSET;
1224
+ for (let i = 0; i < string.length; i++) {
1225
+ hash *= FNV1_PRIME;
1226
+ hash ^= BigInt(string.charCodeAt(i));
1288
1227
  }
1289
- static fromPoints(a, b) {
1290
- const veca = this.resolve(a);
1291
- const vecb = this.resolve(b);
1292
- return new this(vecb.x - veca.x, vecb.y - veca.y, vecb.z - veca.z);
1228
+ return hash;
1229
+ }
1230
+ function sdbm(value) {
1231
+ const string = String(value);
1232
+ let hash = 0n;
1233
+ for (let i = 0; i < string.length; i++) {
1234
+ hash = BigInt(string.charCodeAt(i)) + (hash << 6n) + (hash << 16n) - hash;
1293
1235
  }
1294
- static clamp(value, min, max) {
1295
- const a = this.resolve(value), b = this.resolve(min), c = this.resolve(max);
1296
- return new this(
1297
- clamp(a.x, b.x, c.x),
1298
- clamp(a.y, b.y, c.y),
1299
- clamp(a.z, b.z, c.z)
1300
- );
1236
+ return hash;
1237
+ }
1238
+
1239
+ // source/crypto/md2.ts
1240
+ import { NodeJSCustomInspect as NodeJSCustomInspect8 } from "@ntf/types";
1241
+ var STABLE = [
1242
+ 41,
1243
+ 46,
1244
+ 67,
1245
+ 201,
1246
+ 162,
1247
+ 216,
1248
+ 124,
1249
+ 1,
1250
+ 61,
1251
+ 54,
1252
+ 84,
1253
+ 161,
1254
+ 236,
1255
+ 240,
1256
+ 6,
1257
+ 19,
1258
+ 98,
1259
+ 167,
1260
+ 5,
1261
+ 243,
1262
+ 192,
1263
+ 199,
1264
+ 115,
1265
+ 140,
1266
+ 152,
1267
+ 147,
1268
+ 43,
1269
+ 217,
1270
+ 188,
1271
+ 76,
1272
+ 130,
1273
+ 202,
1274
+ 30,
1275
+ 155,
1276
+ 87,
1277
+ 60,
1278
+ 253,
1279
+ 212,
1280
+ 224,
1281
+ 22,
1282
+ 103,
1283
+ 66,
1284
+ 111,
1285
+ 24,
1286
+ 138,
1287
+ 23,
1288
+ 229,
1289
+ 18,
1290
+ 190,
1291
+ 78,
1292
+ 196,
1293
+ 214,
1294
+ 218,
1295
+ 158,
1296
+ 222,
1297
+ 73,
1298
+ 160,
1299
+ 251,
1300
+ 245,
1301
+ 142,
1302
+ 187,
1303
+ 47,
1304
+ 238,
1305
+ 122,
1306
+ 169,
1307
+ 104,
1308
+ 121,
1309
+ 145,
1310
+ 21,
1311
+ 178,
1312
+ 7,
1313
+ 63,
1314
+ 148,
1315
+ 194,
1316
+ 16,
1317
+ 137,
1318
+ 11,
1319
+ 34,
1320
+ 95,
1321
+ 33,
1322
+ 128,
1323
+ 127,
1324
+ 93,
1325
+ 154,
1326
+ 90,
1327
+ 144,
1328
+ 50,
1329
+ 39,
1330
+ 53,
1331
+ 62,
1332
+ 204,
1333
+ 231,
1334
+ 191,
1335
+ 247,
1336
+ 151,
1337
+ 3,
1338
+ 255,
1339
+ 25,
1340
+ 48,
1341
+ 179,
1342
+ 72,
1343
+ 165,
1344
+ 181,
1345
+ 209,
1346
+ 215,
1347
+ 94,
1348
+ 146,
1349
+ 42,
1350
+ 172,
1351
+ 86,
1352
+ 170,
1353
+ 198,
1354
+ 79,
1355
+ 184,
1356
+ 56,
1357
+ 210,
1358
+ 150,
1359
+ 164,
1360
+ 125,
1361
+ 182,
1362
+ 118,
1363
+ 252,
1364
+ 107,
1365
+ 226,
1366
+ 156,
1367
+ 116,
1368
+ 4,
1369
+ 241,
1370
+ 69,
1371
+ 157,
1372
+ 112,
1373
+ 89,
1374
+ 100,
1375
+ 113,
1376
+ 135,
1377
+ 32,
1378
+ 134,
1379
+ 91,
1380
+ 207,
1381
+ 101,
1382
+ 230,
1383
+ 45,
1384
+ 168,
1385
+ 2,
1386
+ 27,
1387
+ 96,
1388
+ 37,
1389
+ 173,
1390
+ 174,
1391
+ 176,
1392
+ 185,
1393
+ 246,
1394
+ 28,
1395
+ 70,
1396
+ 97,
1397
+ 105,
1398
+ 52,
1399
+ 64,
1400
+ 126,
1401
+ 15,
1402
+ 85,
1403
+ 71,
1404
+ 163,
1405
+ 35,
1406
+ 221,
1407
+ 81,
1408
+ 175,
1409
+ 58,
1410
+ 195,
1411
+ 92,
1412
+ 249,
1413
+ 206,
1414
+ 186,
1415
+ 197,
1416
+ 234,
1417
+ 38,
1418
+ 44,
1419
+ 83,
1420
+ 13,
1421
+ 110,
1422
+ 133,
1423
+ 40,
1424
+ 132,
1425
+ 9,
1426
+ 211,
1427
+ 223,
1428
+ 205,
1429
+ 244,
1430
+ 65,
1431
+ 129,
1432
+ 77,
1433
+ 82,
1434
+ 106,
1435
+ 220,
1436
+ 55,
1437
+ 200,
1438
+ 108,
1439
+ 193,
1440
+ 171,
1441
+ 250,
1442
+ 36,
1443
+ 225,
1444
+ 123,
1445
+ 8,
1446
+ 12,
1447
+ 189,
1448
+ 177,
1449
+ 74,
1450
+ 120,
1451
+ 136,
1452
+ 149,
1453
+ 139,
1454
+ 227,
1455
+ 99,
1456
+ 232,
1457
+ 109,
1458
+ 233,
1459
+ 203,
1460
+ 213,
1461
+ 254,
1462
+ 59,
1463
+ 0,
1464
+ 29,
1465
+ 57,
1466
+ 242,
1467
+ 239,
1468
+ 183,
1469
+ 14,
1470
+ 102,
1471
+ 88,
1472
+ 208,
1473
+ 228,
1474
+ 166,
1475
+ 119,
1476
+ 114,
1477
+ 248,
1478
+ 235,
1479
+ 117,
1480
+ 75,
1481
+ 10,
1482
+ 49,
1483
+ 68,
1484
+ 80,
1485
+ 180,
1486
+ 143,
1487
+ 237,
1488
+ 31,
1489
+ 26,
1490
+ 219,
1491
+ 153,
1492
+ 141,
1493
+ 51,
1494
+ 159,
1495
+ 17,
1496
+ 131,
1497
+ 20
1498
+ ];
1499
+ var MD2 = class _MD2 {
1500
+ static BLOCK_SIZE = 16;
1501
+ _data = new Uint8Array(16);
1502
+ _state = new Uint8Array(48);
1503
+ _checksum = new Uint8Array(16);
1504
+ _length = 0;
1505
+ constructor() {
1506
+ for (let i = 0; i < this._state.length; i++)
1507
+ this._state[i] = 0;
1508
+ for (let i = 0; i < this._checksum.length; i++)
1509
+ this._checksum[i] = 0;
1301
1510
  }
1302
- static intersectPlane(planeP, planeN, lineStart, lineEnd, t) {
1303
- planeN = this.resolve(planeN).normalize();
1304
- const plane_d = -this.resolve(planeN).dot(planeP);
1305
- const ad = this.resolve(lineStart).dot(planeN);
1306
- const bd = this.resolve(lineEnd).dot(planeN);
1307
- t = (-plane_d - ad) / (bd - ad);
1308
- const lineStartToEnd = this.resolve(lineEnd).subtract(lineStart);
1309
- const linetoIntersect = lineStartToEnd.multiply(t);
1310
- return _Vec3.resolve(lineStart).add(linetoIntersect);
1511
+ update(input) {
1512
+ for (let i = 0; i < input.length; i++) {
1513
+ this._data[this._length] = input[i];
1514
+ this._length++;
1515
+ if (this._length == _MD2.BLOCK_SIZE) {
1516
+ this._transform(input);
1517
+ this._length = 0;
1518
+ }
1519
+ }
1520
+ return this;
1311
1521
  }
1312
- static get zero() {
1313
- return new this(0, 0, 0);
1522
+ _transform(data) {
1523
+ for (let i = 0; i < 16; ++i) {
1524
+ this._state[i + 16] = this._data[i];
1525
+ this._state[i + 32] = this._state[i + 16] ^ this._state[i];
1526
+ }
1527
+ let t = 0;
1528
+ for (let i = 0; i < 18; ++i) {
1529
+ for (let j = 0; j < 48; ++j) {
1530
+ this._state[j] ^= STABLE[t];
1531
+ t = this._state[j];
1532
+ }
1533
+ t = t + i & 255;
1534
+ }
1535
+ t = this._checksum[15];
1536
+ for (let i = 0; i < 16; ++i) {
1537
+ this._checksum[i] ^= STABLE[this._data[i] ^ t];
1538
+ t = this._checksum[i];
1539
+ }
1314
1540
  }
1315
- static get one() {
1316
- return new this(1, 1, 1);
1541
+ digest() {
1542
+ const toPad = _MD2.BLOCK_SIZE - this._length;
1543
+ while (this._length < _MD2.BLOCK_SIZE)
1544
+ this._data[this._length++] = toPad;
1545
+ this._transform(this._data);
1546
+ this._transform(this._checksum);
1547
+ return this._state.slice();
1317
1548
  }
1318
- constructor(x, y, z, w = 1) {
1319
- if (!checkNumber(x))
1320
- throw new TypeError("expected number for x");
1321
- if (!checkNumber(y))
1322
- throw new TypeError("expected number for y");
1323
- if (!checkNumber(z))
1324
- throw new TypeError("expected number for z");
1325
- if (!checkNumber(w))
1326
- throw new TypeError("expected number for w");
1327
- this.x = x;
1328
- this.y = y;
1329
- this.z = z;
1330
- this.w = w;
1549
+ toString() {
1550
+ return "";
1331
1551
  }
1332
- toArray(w = this.w !== 1) {
1333
- return w ? [this.x, this.y, this.z, this.w] : [this.x, this.y, this.z];
1552
+ get [Symbol.toStringTag]() {
1553
+ return "MD2";
1334
1554
  }
1335
- toJSON() {
1336
- return {
1337
- x: this.x,
1338
- y: this.y,
1339
- z: this.z,
1340
- w: this.w
1341
- };
1555
+ [NodeJSCustomInspect8]() {
1556
+ return `MD2 <${this.toString()}>`;
1342
1557
  }
1343
- toString(w = this.w !== 1) {
1344
- return w ? `${this.x},${this.y},${this.z};${this.w}` : `${this.x},${this.y},${this.z}`;
1558
+ };
1559
+
1560
+ // source/geometry/angle.ts
1561
+ var MAX_ANGLE_DEGREE = 360;
1562
+ var clampAngleDegree = (angle) => angle % MAX_ANGLE_DEGREE;
1563
+ var clampAngleRadian = (angle) => clampAngleDegree(degreeToRadian(angle));
1564
+ var radianToDegree = (angle) => angle * (180 / Math.PI);
1565
+ var degreeToRadian = (angle) => angle * (Math.PI / 180);
1566
+
1567
+ // source/geometry/bbox.ts
1568
+ import { checkValidNumber as checkValidNumber9, hasObjectProperty as hasObjectProperty7, isFixedTypeArray as isFixedTypeArray7, isValidNumber as isValidNumber7, isValidString as isValidString7, NodeJSCustomInspect as NodeJSCustomInspect10 } from "@ntf/types";
1569
+
1570
+ // source/geometry/circle.ts
1571
+ import { isValidNumber as isValidNumber6, isValidString as isValidString6, hasObjectProperty as hasObjectProperty6, NodeJSCustomInspect as NodeJSCustomInspect9, isFixedTypeArray as isFixedTypeArray6, checkValidNumber as checkValidNumber8 } from "@ntf/types";
1572
+ var Circle = class _Circle {
1573
+ radius;
1574
+ get perimeter() {
1575
+ return this.radius * Math.PI * 2;
1345
1576
  }
1346
- get [Symbol.toStringTag]() {
1347
- return "Vec3";
1577
+ get area() {
1578
+ return Math.PI * Math.pow(this.radius, 2);
1348
1579
  }
1349
- [NodeJSCustomInspect]() {
1350
- return `Vec3 <${this.toString()}>`;
1580
+ position;
1581
+ get x() {
1582
+ return this.position.x;
1351
1583
  }
1352
- toVec2() {
1353
- return [this.x, this.y, this.w];
1584
+ set x(val) {
1585
+ this.position.x = val;
1354
1586
  }
1355
- toRGB() {
1356
- const vec = this.normalize();
1357
- return [vec.x, vec.y, vec.z];
1587
+ get y() {
1588
+ return this.position.y;
1358
1589
  }
1359
- toRGBA() {
1360
- const vec = this.normalize();
1361
- return [vec.x, vec.y, vec.z, vec.w];
1590
+ set y(val) {
1591
+ this.position.y = val;
1362
1592
  }
1363
- toHSL() {
1364
- const vec = this.normalize();
1365
- return [vec.x, vec.y, vec.z];
1593
+ get w() {
1594
+ return this.position.w;
1366
1595
  }
1367
- toHSLA() {
1368
- const vec = this.normalize();
1369
- return [vec.x, vec.y, vec.z, vec.w];
1596
+ set w(val) {
1597
+ this.position.w = val;
1370
1598
  }
1371
- toQuaternion() {
1372
- return [this.w, this.x, this.y, this.z];
1599
+ static resolve(a) {
1600
+ const value = this.cast(a);
1601
+ if (typeof value != "undefined")
1602
+ return value;
1603
+ throw new ResolveError("Circle", a);
1604
+ }
1605
+ static resolveArgs(args) {
1606
+ if (isFixedTypeArray6(args, isValidNumber6, 3))
1607
+ return new this([args[0], args[1]], args[2]);
1608
+ if (args.length === 2)
1609
+ return new this(args[0], args[1]);
1610
+ return this.resolve(args[0]);
1611
+ }
1612
+ static cast(a) {
1613
+ if (a == null || typeof a == "undefined")
1614
+ return void 0;
1615
+ if (isFixedTypeArray6(a, isValidNumber6, 3))
1616
+ return new this([a[0], a[1]], a[2]);
1617
+ if (isFixedTypeArray6(a, isValidNumber6, 4)) {
1618
+ const c = new this([a[0], a[1]], a[3]);
1619
+ c.w = a[2];
1620
+ return c;
1621
+ }
1622
+ if (hasObjectProperty6(a, "toCircle", "function"))
1623
+ return this.cast(a.toCircle());
1624
+ if (hasObjectProperty6(a, "x", "number") && hasObjectProperty6(a, "y", "number") && hasObjectProperty6(a, "radius", "number"))
1625
+ return new this(hasObjectProperty6(a, "w", "number") ? [a.x, a.y, a.w] : [a.x, a.y], a.radius);
1626
+ if (isValidString6(a)) {
1627
+ const [spos, sradius] = a.split("|");
1628
+ const pos = Vec2.cast(spos);
1629
+ if (typeof pos == "undefined")
1630
+ return void 0;
1631
+ const radius = parseFloat(sradius);
1632
+ if (!isNaN(radius))
1633
+ return new this(pos, radius);
1634
+ }
1635
+ return void 0;
1636
+ }
1637
+ static is(a) {
1638
+ return typeof this.cast(a) != "undefined";
1639
+ }
1640
+ constructor(position, radius) {
1641
+ checkValidNumber8(radius);
1642
+ this.position = Vec2.resolve(position);
1643
+ this.radius = radius;
1644
+ }
1645
+ toArray() {
1646
+ return [...this.position.toArray(), this.radius];
1647
+ }
1648
+ toJSON() {
1649
+ return {
1650
+ ...this.position.toJSON(),
1651
+ radius: this.radius
1652
+ };
1653
+ }
1654
+ toString() {
1655
+ return `${this.position.toString()}|${this.radius}`;
1656
+ }
1657
+ get [Symbol.toStringTag]() {
1658
+ return "Circle";
1659
+ }
1660
+ [NodeJSCustomInspect9]() {
1661
+ return `Circle <${this.toString()}>`;
1373
1662
  }
1374
1663
  clone() {
1375
- return new _Vec3(this.x, this.y, this.z, this.w);
1664
+ return new _Circle(this.position.clone(), this.radius);
1665
+ }
1666
+ toVec2() {
1667
+ return [this.x, this.y, this.w];
1376
1668
  }
1377
1669
  equals(...args) {
1378
- const a = _Vec3.resolveArgs(args);
1379
- return this.x == a.x && this.y == a.y && this.z == a.z;
1670
+ const c = _Circle.resolveArgs(args);
1671
+ return c.position.equals(c.position) && this.radius == c.radius;
1672
+ }
1673
+ inside(...args) {
1674
+ const circle = _Circle.resolveArgs(args);
1675
+ const distX = circle.x - this.x;
1676
+ const distY = circle.y - this.y;
1677
+ const dist = Math.sqrt(distX * distX + (distY + distY));
1678
+ return dist <= this.radius + circle.radius;
1679
+ }
1680
+ insidePoint(...args) {
1681
+ return this.position.distance(Vec2.resolveArgs(args)) <= this.radius;
1380
1682
  }
1381
- setX(x) {
1382
- this.x = x;
1383
- return this;
1683
+ };
1684
+
1685
+ // source/geometry/bbox.ts
1686
+ var BoundingBox = class _BoundingBox {
1687
+ left;
1688
+ right;
1689
+ top;
1690
+ bottom;
1691
+ get width() {
1692
+ return this.right - this.left;
1384
1693
  }
1385
- setY(y) {
1386
- this.y = y;
1387
- return this;
1694
+ set width(val) {
1695
+ this.right = this.left + val;
1388
1696
  }
1389
- setZ(z) {
1390
- this.z = z;
1391
- return this;
1697
+ get height() {
1698
+ return this.bottom - this.top;
1392
1699
  }
1393
- set(...args) {
1394
- const vec = _Vec3.resolveArgs(args);
1395
- return this.setX(vec.x).setY(vec.y).setZ(vec.z);
1700
+ set height(val) {
1701
+ this.bottom = this.top + val;
1396
1702
  }
1397
- add(...args) {
1398
- const vec = _Vec3.resolveArgs(args);
1399
- return new _Vec3(
1400
- this.x + vec.x,
1401
- this.y + vec.y,
1402
- this.z + vec.z
1403
- );
1703
+ get x() {
1704
+ return this.left;
1404
1705
  }
1405
- offset(...args) {
1406
- const vec = _Vec3.resolveArgs(args);
1407
- this.x += vec.x;
1408
- this.y += vec.y;
1409
- this.z += vec.z;
1410
- return this;
1706
+ set x(x) {
1707
+ this.left = x;
1411
1708
  }
1412
- subtract(...args) {
1413
- const vec = _Vec3.resolveArgs(args);
1414
- return new _Vec3(
1415
- this.x - vec.x,
1416
- this.y - vec.y,
1417
- this.z - vec.z
1418
- );
1709
+ get y() {
1710
+ return this.top;
1419
1711
  }
1420
- multiply(scalar) {
1421
- return new _Vec3(
1422
- this.x * scalar,
1423
- this.y * scalar,
1424
- this.z * scalar
1425
- );
1712
+ set y(y) {
1713
+ this.top = y;
1426
1714
  }
1427
- naiveMultiply(...args) {
1428
- const vec = _Vec3.resolveArgs(args);
1429
- return new _Vec3(
1430
- this.x * vec.x,
1431
- this.y * vec.y,
1432
- this.z * vec.z
1433
- );
1715
+ w = 1;
1716
+ static resolve(a) {
1717
+ const value = this.cast(a);
1718
+ if (typeof value != "undefined")
1719
+ return value;
1720
+ throw new ResolveError("BoundingBox", a);
1434
1721
  }
1435
- divide(...args) {
1436
- if (checkNumberArray(args, 1))
1437
- return new _Vec3(
1438
- this.x / args[0],
1439
- this.y / args[0],
1440
- this.z / args[0]
1441
- );
1442
- const vec = _Vec3.resolveArgs(args);
1443
- return new _Vec3(
1444
- this.x / vec.x,
1445
- this.y / vec.y,
1446
- this.z / vec.z
1447
- );
1722
+ static resolveArgs(args) {
1723
+ if (isFixedTypeArray7(args, isValidNumber7, 4))
1724
+ return new this(args[0], args[1], args[2], args[3]);
1725
+ return this.resolve(args[0]);
1448
1726
  }
1449
- dot(...args) {
1450
- const vec = _Vec3.resolveArgs(args);
1451
- return this.x * vec.x + this.y * vec.y + this.z * vec.z;
1727
+ static cast(a) {
1728
+ if (a == null || typeof a == "undefined")
1729
+ return void 0;
1730
+ if (isFixedTypeArray7(a, isValidNumber7, 4))
1731
+ return new this(a[0], a[1], a[2], a[3]);
1732
+ if (hasObjectProperty7(a, "toBoundingBox", "function"))
1733
+ return this.cast(a.toBoundingBox());
1734
+ if (hasObjectProperty7(a, "left", "number") && hasObjectProperty7(a, "right", "number") && hasObjectProperty7(a, "top", "number") && hasObjectProperty7(a, "bottom", "number"))
1735
+ return new this(a.left, a.right, a.top, a.bottom);
1736
+ if (isValidString7(a)) {
1737
+ const parts = a.split(",");
1738
+ if (isFixedTypeArray7(parts, isValidString7, 4))
1739
+ return this.cast(parts.map((v) => parseFloat(v)));
1740
+ }
1741
+ return void 0;
1452
1742
  }
1453
- cross(...args) {
1454
- const vec = _Vec3.resolveArgs(args);
1455
- return new _Vec3(
1456
- this.y * vec.z - this.z * vec.y,
1457
- this.z * vec.x - this.x * vec.z,
1458
- this.x * vec.y - this.y * vec.x
1459
- );
1743
+ static is(a) {
1744
+ return typeof this.cast(a) != "undefined";
1460
1745
  }
1461
- distance(...args) {
1462
- const vec = _Vec3.resolveArgs(args);
1463
- return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2);
1746
+ constructor(left, right, top, bottom) {
1747
+ checkValidNumber9(left);
1748
+ checkValidNumber9(right);
1749
+ checkValidNumber9(top);
1750
+ checkValidNumber9(bottom);
1751
+ this.left = left;
1752
+ this.right = right;
1753
+ this.top = top;
1754
+ this.bottom = bottom;
1464
1755
  }
1465
- distanceSquare(...args) {
1466
- const vec = _Vec3.resolveArgs(args);
1467
- return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2));
1756
+ toArray() {
1757
+ return [this.left, this.right, this.top, this.bottom];
1468
1758
  }
1469
- length() {
1470
- return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
1759
+ toString() {
1760
+ return `${this.left},${this.right},${this.top},${this.bottom}`;
1471
1761
  }
1472
- normalize() {
1473
- const length = this.length();
1474
- if (length == 0) return _Vec3.zero;
1475
- return new _Vec3(
1476
- this.x / length,
1477
- this.y / length,
1478
- this.z / length,
1479
- this.w / length
1480
- );
1762
+ get [Symbol.toStringTag]() {
1763
+ return "BoundingBox";
1481
1764
  }
1482
- invert() {
1483
- return this.multiply(-1);
1765
+ [NodeJSCustomInspect10]() {
1766
+ return `BoundingBox <${this.toString()}>`;
1484
1767
  }
1485
- round() {
1486
- return new _Vec3(Math.round(this.x), Math.round(this.y), Math.round(this.z), Math.round(this.w));
1768
+ toJSON() {
1769
+ return {
1770
+ left: this.left,
1771
+ top: this.top,
1772
+ right: this.right,
1773
+ bottom: this.bottom
1774
+ };
1487
1775
  }
1488
- };
1489
-
1490
- // source/geometry/triangle.ts
1491
- var Triangle = class {
1492
- constructor(A, B, C) {
1493
- this.A = A;
1494
- this.B = B;
1495
- this.C = C;
1776
+ clone() {
1777
+ return new _BoundingBox(this.left, this.right, this.top, this.bottom);
1496
1778
  }
1497
- get alpha() {
1498
- return Math.acos((this.b * this.b + this.c * this.c - this.a * this.a) / (2 * this.b * this.c));
1779
+ equals(...args) {
1780
+ const b = _BoundingBox.resolveArgs(args);
1781
+ return this.left === b.left && this.right === b.right && this.top === b.top && this.bottom === b.bottom;
1499
1782
  }
1500
- get beta() {
1501
- return Math.acos((this.c * this.c + this.a * this.a - this.b * this.b) / (2 * this.c * this.a));
1783
+ toSize() {
1784
+ return [this.width, this.height];
1502
1785
  }
1503
- get gamma() {
1504
- return Math.acos((this.a * this.a + this.b * this.b - this.c * this.c) / (2 * this.a * this.b));
1786
+ toVec2() {
1787
+ return [this.left, this.top];
1505
1788
  }
1506
- get perimeter() {
1507
- return this.a + this.b + this.c;
1789
+ toRectangle() {
1790
+ return [this.left, this.top, this.width, this.height];
1508
1791
  }
1509
- get semiperimeter() {
1510
- return this.perimeter / 2;
1792
+ inside(...args) {
1793
+ const bbox = _BoundingBox.resolve(args);
1794
+ return this.right >= bbox.left && bbox.right >= this.left && this.bottom >= bbox.top && bbox.bottom >= this.top;
1511
1795
  }
1512
- get area() {
1513
- return Math.sqrt(this.semiperimeter * (this.semiperimeter - this.a) * (this.semiperimeter - this.b) * (this.semiperimeter - this.c));
1796
+ insidePoint(...args) {
1797
+ const point = Vec2.resolveArgs(args);
1798
+ return this.left <= point.x && this.right >= point.x && this.top <= point.y && this.bottom >= point.y;
1514
1799
  }
1515
- get base() {
1516
- return 2 * (this.area / (this.a * Math.sin(this.gamma)));
1800
+ insideCircle(...args) {
1801
+ const circle = Circle.resolveArgs(args);
1802
+ const center = Vec2.resolve(circle).add(circle.radius);
1803
+ const bboxhe = new Vec2(this.width / 2, this.height / 2);
1804
+ const bboxcenter = new Vec2(this.left + bboxhe.x, this.top + bboxhe.y);
1805
+ let diff = center.subtract(bboxcenter);
1806
+ const clamped = Vec2.clamp(diff, bboxhe.invert(), bboxhe);
1807
+ const closest = bboxcenter.add(clamped);
1808
+ diff = closest.subtract(center);
1809
+ return diff.length() < circle.radius;
1517
1810
  }
1518
- get height() {
1519
- return 2 * (this.area / this.base);
1811
+ };
1812
+
1813
+ // source/geometry/rectangle.ts
1814
+ import { isValidString as isValidString9, hasObjectProperty as hasObjectProperty9, NodeJSCustomInspect as NodeJSCustomInspect12, isFixedTypeArray as isFixedTypeArray9, isValidNumber as isValidNumber9 } from "@ntf/types";
1815
+
1816
+ // source/geometry/size.ts
1817
+ import { isValidNumber as isValidNumber8, isValidString as isValidString8, hasObjectProperty as hasObjectProperty8, NodeJSCustomInspect as NodeJSCustomInspect11, isFixedTypeArray as isFixedTypeArray8, checkValidNumber as checkValidNumber10 } from "@ntf/types";
1818
+ var Size = class _Size {
1819
+ width;
1820
+ height;
1821
+ get aspectRatio() {
1822
+ return this.height / this.width;
1520
1823
  }
1521
- toString() {
1522
- return `${stringify(this.A)}|${stringify(this.B)}|${stringify(this.C)}`;
1824
+ get area() {
1825
+ return this.width * this.height;
1523
1826
  }
1524
- get [Symbol.toStringTag]() {
1525
- return "Triangle";
1827
+ get perimeter() {
1828
+ return this.width + this.width + this.height + this.height;
1526
1829
  }
1527
- [NodeJSCustomInspect]() {
1528
- return `Triangle <${this.toString()}>`;
1830
+ static resolve(a) {
1831
+ const value = this.cast(a);
1832
+ if (typeof value != "undefined")
1833
+ return value;
1834
+ throw new ResolveError("Square", a);
1529
1835
  }
1530
- };
1531
- var Triangle2D = class extends Triangle {
1532
- get a() {
1533
- return Vec2.fromPoints(this.B, this.C).length();
1836
+ static resolveArgs(args) {
1837
+ if (isFixedTypeArray8(args, isValidNumber8, 2))
1838
+ return new this(args[0], args[1]);
1839
+ return this.resolve(args[0]);
1534
1840
  }
1535
- get b() {
1536
- return Vec2.fromPoints(this.A, this.C).length();
1841
+ static cast(a) {
1842
+ if (a == null || typeof a == "undefined")
1843
+ return void 0;
1844
+ if (isFixedTypeArray8(a, isValidNumber8, 2))
1845
+ return new this(a[0], a[1]);
1846
+ if (hasObjectProperty8(a, "toSize", "function"))
1847
+ return this.cast(a.toSize());
1848
+ if (hasObjectProperty8(a, "width", "number") && hasObjectProperty8(a, "height", "number"))
1849
+ return new this(a.width, a.height);
1850
+ if (isValidString8(a)) {
1851
+ const parts = a.split("x").map((v) => parseFloat(v));
1852
+ if (isFixedTypeArray8(parts, isValidNumber8, 2))
1853
+ return this.cast(parts);
1854
+ }
1855
+ if (isValidNumber8(a))
1856
+ return new this(a, a);
1857
+ return void 0;
1537
1858
  }
1538
- get c() {
1539
- return Vec2.fromPoints(this.A, this.B).length();
1859
+ static is(a) {
1860
+ return typeof this.cast(a) != "undefined";
1540
1861
  }
1541
- };
1542
- var Triangle3D = class extends Triangle {
1543
- get a() {
1544
- return Vec3.fromPoints(this.B, this.C).length();
1862
+ constructor(width, height) {
1863
+ checkValidNumber10(width);
1864
+ checkValidNumber10(height);
1865
+ this.width = width;
1866
+ this.height = height;
1545
1867
  }
1546
- get b() {
1547
- return Vec3.fromPoints(this.A, this.C).length();
1868
+ toArray() {
1869
+ return [this.width, this.height];
1548
1870
  }
1549
- get c() {
1550
- return Vec3.fromPoints(this.A, this.B).length();
1871
+ toString() {
1872
+ return `${this.width}x${this.height}`;
1551
1873
  }
1552
- };
1553
-
1554
- // source/matrices/mat3.ts
1555
- var Mat3 = class _Mat3 {
1556
- _raw;
1557
- get m00() {
1558
- return this._raw[0];
1874
+ get [Symbol.toStringTag]() {
1875
+ return "Size";
1559
1876
  }
1560
- set m00(val) {
1561
- this._raw[0] = val;
1877
+ [NodeJSCustomInspect11]() {
1878
+ return `Size <${this.toString()}>`;
1562
1879
  }
1563
- get m01() {
1564
- return this._raw[1];
1880
+ toJSON() {
1881
+ return {
1882
+ width: this.width,
1883
+ height: this.height
1884
+ };
1565
1885
  }
1566
- set m01(val) {
1567
- this._raw[1] = val;
1886
+ clone() {
1887
+ return new _Size(this.width, this.height);
1568
1888
  }
1569
- get m02() {
1570
- return this._raw[2];
1889
+ equals(...args) {
1890
+ const s = _Size.resolveArgs(args);
1891
+ return this.width == s.width && this.height == s.height;
1571
1892
  }
1572
- set m02(val) {
1573
- this._raw[2] = val;
1893
+ toVec2() {
1894
+ return [this.width, this.height];
1574
1895
  }
1575
- get m10() {
1576
- return this._raw[3];
1896
+ };
1897
+
1898
+ // source/geometry/rectangle.ts
1899
+ var Rectangle = class _Rectangle {
1900
+ position;
1901
+ size;
1902
+ get area() {
1903
+ return this.width * this.height;
1577
1904
  }
1578
- set m10(val) {
1579
- this._raw[3] = val;
1905
+ get perimeter() {
1906
+ return this.width + this.width + this.height + this.height;
1580
1907
  }
1581
- get m11() {
1582
- return this._raw[4];
1908
+ get x() {
1909
+ return this.position.x;
1583
1910
  }
1584
- set m11(val) {
1585
- this._raw[4] = val;
1911
+ set x(val) {
1912
+ this.position.x = val;
1586
1913
  }
1587
- get m12() {
1588
- return this._raw[5];
1914
+ get y() {
1915
+ return this.position.y;
1589
1916
  }
1590
- set m12(val) {
1591
- this._raw[5] = val;
1917
+ set y(val) {
1918
+ this.position.y = val;
1592
1919
  }
1593
- get m20() {
1594
- return this._raw[6];
1920
+ get w() {
1921
+ return this.position.w;
1595
1922
  }
1596
- set m20(val) {
1597
- this._raw[6] = val;
1923
+ set w(val) {
1924
+ this.position.w = val;
1598
1925
  }
1599
- get m21() {
1600
- return this._raw[7];
1926
+ get width() {
1927
+ return this.size.width;
1601
1928
  }
1602
- set m21(val) {
1603
- this._raw[7] = val;
1929
+ set width(val) {
1930
+ this.size.width = val;
1604
1931
  }
1605
- get m22() {
1606
- return this._raw[8];
1932
+ get height() {
1933
+ return this.size.height;
1607
1934
  }
1608
- set m22(val) {
1609
- this._raw[8] = val;
1935
+ set height(val) {
1936
+ this.size.height = val;
1610
1937
  }
1611
1938
  static resolve(a) {
1612
1939
  const value = this.cast(a);
1613
1940
  if (typeof value != "undefined")
1614
1941
  return value;
1615
- throw new ResolveError("Mat3", a);
1942
+ throw new ResolveError("Rectangle", a);
1616
1943
  }
1617
1944
  static resolveArgs(args) {
1618
- if (checkNumberArray(args, 9))
1619
- return new this(args);
1945
+ if (isFixedTypeArray9(args, isValidNumber9, 4))
1946
+ return new this([args[0], args[1]], [args[2], args[3]]);
1620
1947
  return this.resolve(args[0]);
1621
1948
  }
1622
1949
  static cast(a) {
1623
1950
  if (a == null || typeof a == "undefined")
1624
1951
  return void 0;
1625
- if (checkNumberArray(a, 9)) {
1626
- return new this(a);
1627
- }
1628
- if (checkArray(a, void 0, 3)) {
1629
- const row0 = a[0], row1 = a[1], row2 = a[2];
1630
- if (checkNumberArray(row0, 3) && checkNumberArray(row1, 3) && checkNumberArray(row2, 3))
1631
- return new this([
1632
- row0[0],
1633
- row0[1],
1634
- row0[2],
1635
- row1[0],
1636
- row1[1],
1637
- row1[2],
1638
- row2[0],
1639
- row2[1],
1640
- row2[2]
1641
- ]);
1952
+ if (isFixedTypeArray9(a, isValidNumber9, 4))
1953
+ return new this([a[0], a[1]], [a[2], a[3]]);
1954
+ if (isFixedTypeArray9(a, isValidNumber9, 5)) {
1955
+ const rect = new this([a[0], a[1]], [a[3], a[4]]);
1956
+ rect.w = a[2];
1957
+ return rect;
1642
1958
  }
1643
- if (checkString(a)) {
1644
- const parts = a.split(",");
1645
- if (checkStringArray(parts, 9))
1646
- return this.cast(parts.map((i) => parseFloat(i)));
1959
+ if (isValidString9(a)) {
1960
+ const [spos, ssize] = a.split("|");
1961
+ const pos = Vec2.cast(spos);
1962
+ const size = Size.cast(ssize);
1963
+ if (typeof pos == "undefined" || typeof size == "undefined")
1964
+ return void 0;
1965
+ const rect = new this([pos.x, pos.y], [size.width, size.height]);
1966
+ rect.w = pos.w;
1967
+ return rect;
1647
1968
  }
1648
- if (hasProperty(a, "toMat3", "function"))
1649
- return this.cast(a.toMat3());
1650
- if (hasProperty(a, "m00", "number") && hasProperty(a, "m01", "number") && hasProperty(a, "m02", "number") && hasProperty(a, "m10", "number") && hasProperty(a, "m11", "number") && hasProperty(a, "m12", "number") && hasProperty(a, "m20", "number") && hasProperty(a, "m21", "number") && hasProperty(a, "m22", "number"))
1651
- return new this([
1652
- a.m00,
1653
- a.m01,
1654
- a.m02,
1655
- a.m10,
1656
- a.m11,
1657
- a.m12,
1658
- a.m20,
1659
- a.m21,
1660
- a.m22
1661
- ]);
1662
- if (checkNumber(a)) {
1663
- return new this([a, a, a, a, a, a, a, a, a]);
1969
+ if (hasObjectProperty9(a, "toRectangle", "function"))
1970
+ return this.cast(a.toRectangle());
1971
+ if (hasObjectProperty9(a, "x", "number") && hasObjectProperty9(a, "y", "number") && hasObjectProperty9(a, "width", "number") && hasObjectProperty9(a, "height", "number")) {
1972
+ const rect = new this([a.x, a.y], [a.width, a.height]);
1973
+ if (hasObjectProperty9(a, "w", "number"))
1974
+ rect.w = a.w;
1975
+ return rect;
1664
1976
  }
1665
1977
  return void 0;
1666
1978
  }
1667
1979
  static is(a) {
1668
1980
  return typeof this.cast(a) != "undefined";
1669
1981
  }
1670
- static projection(width, height) {
1671
- return new this([
1672
- 2 / width,
1673
- 0,
1674
- 0,
1675
- 0,
1676
- -2 / height,
1677
- 0,
1678
- -1,
1679
- 1,
1680
- 1
1681
- ]);
1982
+ constructor(pos, size) {
1983
+ this.position = Vec2.resolve(pos);
1984
+ this.size = Size.resolve(size);
1682
1985
  }
1683
- constructor(init = [1, 0, 0, 0, 1, 0, 0, 0, 1]) {
1684
- if (!checkNumberArray(init, 9))
1685
- throw new TypeError("expected a number array with 9 elements");
1686
- this._raw = init;
1986
+ toArray(w = this.w !== 1) {
1987
+ return [...this.position.toArray(w), ...this.size.toArray()];
1687
1988
  }
1688
- toArray() {
1689
- return [
1690
- this.m00,
1691
- this.m01,
1692
- this.m02,
1693
- this.m10,
1694
- this.m11,
1695
- this.m12,
1696
- this.m20,
1697
- this.m21,
1698
- this.m22
1699
- ];
1989
+ toString(w = this.w !== 1) {
1990
+ return `${this.position.toString(w)}|${this.size.toString()}`;
1700
1991
  }
1701
- toNestetArray() {
1702
- return [
1703
- [this.m00, this.m01, this.m02],
1704
- [this.m10, this.m11, this.m12],
1705
- [this.m20, this.m21, this.m22]
1706
- ];
1992
+ get [Symbol.toStringTag]() {
1993
+ return "Rectangle";
1994
+ }
1995
+ [NodeJSCustomInspect12]() {
1996
+ return `Rectangle <${this.toString()}>`;
1707
1997
  }
1708
1998
  toJSON() {
1709
- return {
1710
- m00: this.m00,
1711
- m01: this.m01,
1712
- m02: this.m02,
1713
- m10: this.m10,
1714
- m11: this.m11,
1715
- m12: this.m12,
1716
- m20: this.m20,
1717
- m21: this.m21,
1718
- m22: this.m22
1719
- };
1999
+ return { ...this.position.toJSON(), ...this.size.toJSON() };
1720
2000
  }
1721
- toString() {
1722
- return `${this.m00},${this.m01},${this.m02},${this.m10},${this.m11},${this.m12},${this.m20},${this.m21},${this.m22}`;
2001
+ toBoundingBox() {
2002
+ return [this.x, this.x + this.width, this.y, this.y + this.height];
1723
2003
  }
1724
- get [Symbol.toStringTag]() {
1725
- return "Mat3";
2004
+ toVec2() {
2005
+ return [this.x, this.y, this.w];
1726
2006
  }
1727
- [NodeJSCustomInspect]() {
1728
- return `Mat3 <${this.toString()}>`;
2007
+ toSize() {
2008
+ return [this.width, this.height];
1729
2009
  }
1730
2010
  clone() {
1731
- return new _Mat3([
1732
- this.m00,
1733
- this.m01,
1734
- this.m02,
1735
- this.m10,
1736
- this.m11,
1737
- this.m12,
1738
- this.m20,
1739
- this.m21,
1740
- this.m22
1741
- ]);
2011
+ return new _Rectangle(this.position.clone(), this.size.clone());
2012
+ }
2013
+ equals(...args) {
2014
+ const rect = _Rectangle.resolveArgs(args);
2015
+ return this.position.equals(rect.position) && this.size.equals(rect.size);
2016
+ }
2017
+ };
2018
+
2019
+ // source/geometry/triangle.ts
2020
+ import { NodeJSCustomInspect as NodeJSCustomInspect13 } from "@ntf/types";
2021
+ var Triangle = class {
2022
+ constructor(A, B, C) {
2023
+ this.A = A;
2024
+ this.B = B;
2025
+ this.C = C;
2026
+ }
2027
+ get alpha() {
2028
+ return Math.acos((this.b * this.b + this.c * this.c - this.a * this.a) / (2 * this.b * this.c));
2029
+ }
2030
+ get beta() {
2031
+ return Math.acos((this.c * this.c + this.a * this.a - this.b * this.b) / (2 * this.c * this.a));
2032
+ }
2033
+ get gamma() {
2034
+ return Math.acos((this.a * this.a + this.b * this.b - this.c * this.c) / (2 * this.a * this.b));
2035
+ }
2036
+ get perimeter() {
2037
+ return this.a + this.b + this.c;
2038
+ }
2039
+ get semiperimeter() {
2040
+ return this.perimeter / 2;
2041
+ }
2042
+ get area() {
2043
+ return Math.sqrt(this.semiperimeter * (this.semiperimeter - this.a) * (this.semiperimeter - this.b) * (this.semiperimeter - this.c));
2044
+ }
2045
+ get base() {
2046
+ return 2 * (this.area / (this.a * Math.sin(this.gamma)));
1742
2047
  }
1743
- equals(...args) {
1744
- const m = _Mat3.resolveArgs(args);
1745
- for (let index = 0; index < this._raw.length; index++)
1746
- if (this._raw[index] != m._raw[index])
1747
- return false;
1748
- return true;
2048
+ get height() {
2049
+ return 2 * (this.area / this.base);
1749
2050
  }
1750
- add(...args) {
1751
- const b = _Mat3.resolveArgs(args);
1752
- const m = new _Mat3();
1753
- for (let index = 0; index < this._raw.length; index++)
1754
- m._raw[index] = this._raw[index] + b._raw[index];
1755
- return m;
2051
+ toString() {
2052
+ return `${this.A}|${this.B}|${this.C}`;
1756
2053
  }
1757
- subtract(...args) {
1758
- const b = _Mat3.resolveArgs(args);
1759
- const m = new _Mat3();
1760
- for (let index = 0; index < this._raw.length; index++)
1761
- m._raw[index] = this._raw[index] - b._raw[index];
1762
- return m;
2054
+ get [Symbol.toStringTag]() {
2055
+ return "Triangle";
1763
2056
  }
1764
- multiply(...args) {
1765
- if (checkNumberArray(args, 1))
1766
- return new _Mat3([
1767
- this.m00 * args[0],
1768
- this.m01 * args[0],
1769
- this.m02 * args[0],
1770
- this.m10 * args[0],
1771
- this.m11 * args[0],
1772
- this.m12 * args[0],
1773
- this.m20 * args[0],
1774
- this.m21 * args[0],
1775
- this.m22 * args[0]
1776
- ]);
1777
- const b = _Mat3.resolveArgs(args);
1778
- return new _Mat3([
1779
- b.m00 * this.m00 + b.m01 * this.m10 + b.m02 * this.m20,
1780
- b.m00 * this.m01 + b.m01 * this.m11 + b.m02 * this.m21,
1781
- b.m00 * this.m02 + b.m01 * this.m12 + b.m02 * this.m22,
1782
- b.m10 * this.m00 + b.m11 * this.m10 + b.m12 * this.m20,
1783
- b.m10 * this.m01 + b.m11 * this.m11 + b.m12 * this.m21,
1784
- b.m10 * this.m02 + b.m11 * this.m12 + b.m12 * this.m22,
1785
- b.m20 * this.m00 + b.m21 * this.m10 + b.m22 * this.m20,
1786
- b.m20 * this.m01 + b.m21 * this.m11 + b.m22 * this.m21,
1787
- b.m20 * this.m02 + b.m21 * this.m12 + b.m22 * this.m22
1788
- ]);
2057
+ [NodeJSCustomInspect13]() {
2058
+ return `Triangle <${this.toString()}>`;
1789
2059
  }
1790
- translate(...args) {
1791
- const vec = Vec2.resolveArgs(args);
1792
- return this.multiply([
1793
- 1,
1794
- 0,
1795
- 0,
1796
- 0,
1797
- 1,
1798
- 0,
1799
- vec.x,
1800
- vec.y,
1801
- 1
1802
- ]);
2060
+ };
2061
+ var Triangle2D = class extends Triangle {
2062
+ get a() {
2063
+ return Vec2.fromPoints(this.B, this.C).length();
1803
2064
  }
1804
- rotate(angle) {
1805
- const c = Math.cos(angle);
1806
- const s = Math.sin(angle);
1807
- return this.multiply([
1808
- c,
1809
- -s,
1810
- 0,
1811
- s,
1812
- c,
1813
- 0,
1814
- 0,
1815
- 0,
1816
- 1
1817
- ]);
2065
+ get b() {
2066
+ return Vec2.fromPoints(this.A, this.C).length();
1818
2067
  }
1819
- scale(...args) {
1820
- const vec = Vec2.resolve(args);
1821
- return this.multiply([
1822
- vec.x,
1823
- 0,
1824
- 0,
1825
- 0,
1826
- vec.y,
1827
- 0,
1828
- 0,
1829
- 0,
1830
- 1
1831
- ]);
2068
+ get c() {
2069
+ return Vec2.fromPoints(this.A, this.B).length();
1832
2070
  }
1833
- determinant() {
1834
- return this.m00 * this.m11 * this.m22 - this.m21 * this.m12 - this.m01 * this.m10 * this.m22 - this.m12 * this.m20 + this.m02 * this.m10 * this.m21 - this.m11 * this.m20;
2071
+ };
2072
+ var Triangle3D = class extends Triangle {
2073
+ get a() {
2074
+ return Vec3.fromPoints(this.B, this.C).length();
1835
2075
  }
1836
- inverse() {
1837
- const det = this.determinant();
1838
- return new _Mat3([
1839
- (this.m11 * this.m22 - this.m21 * this.m12) * det,
1840
- (this.m02 * this.m21 - this.m01 * this.m22) * det,
1841
- (this.m01 * this.m12 - this.m02 * this.m11) * det,
1842
- (this.m12 * this.m20 - this.m10 * this.m22) * det,
1843
- (this.m00 * this.m22 - this.m02 * this.m20) * det,
1844
- (this.m10 * this.m02 - this.m00 * this.m12) * det,
1845
- (this.m10 * this.m21 - this.m20 * this.m11) * det,
1846
- (this.m20 * this.m01 - this.m00 * this.m21) * det,
1847
- (this.m00 * this.m11 - this.m10 * this.m01) * det
1848
- ]);
2076
+ get b() {
2077
+ return Vec3.fromPoints(this.A, this.C).length();
1849
2078
  }
1850
- toMat4() {
1851
- return [
1852
- this.m00,
1853
- this.m01,
1854
- this.m02,
1855
- 0,
1856
- this.m10,
1857
- this.m11,
1858
- this.m12,
1859
- 0,
1860
- this.m20,
1861
- this.m20,
1862
- this.m22,
1863
- 0,
1864
- 0,
1865
- 0,
1866
- 0,
1867
- 1
1868
- ];
2079
+ get c() {
2080
+ return Vec3.fromPoints(this.A, this.B).length();
1869
2081
  }
1870
2082
  };
1871
2083
 
1872
- // source/matrices/mat4.ts
1873
- var Mat4 = class _Mat4 {
2084
+ // source/matrices/mat3.ts
2085
+ import { isValidNumber as isValidNumber10, isValidString as isValidString10, hasObjectProperty as hasObjectProperty10, NodeJSCustomInspect as NodeJSCustomInspect14, isFixedTypeArray as isFixedTypeArray10, isFixedArray, checkFixedTypeArray } from "@ntf/types";
2086
+ var Mat3 = class _Mat3 {
1874
2087
  _raw;
1875
2088
  get m00() {
1876
2089
  return this._raw[0];
@@ -1890,230 +2103,116 @@ var Mat4 = class _Mat4 {
1890
2103
  set m02(val) {
1891
2104
  this._raw[2] = val;
1892
2105
  }
1893
- get m03() {
1894
- return this._raw[3];
1895
- }
1896
- set m03(val) {
1897
- this._raw[3] = val;
1898
- }
1899
2106
  get m10() {
1900
- return this._raw[4];
2107
+ return this._raw[3];
1901
2108
  }
1902
2109
  set m10(val) {
1903
- this._raw[4] = val;
2110
+ this._raw[3] = val;
1904
2111
  }
1905
2112
  get m11() {
1906
- return this._raw[5];
2113
+ return this._raw[4];
1907
2114
  }
1908
2115
  set m11(val) {
1909
- this._raw[5] = val;
2116
+ this._raw[4] = val;
1910
2117
  }
1911
2118
  get m12() {
1912
- return this._raw[6];
2119
+ return this._raw[5];
1913
2120
  }
1914
2121
  set m12(val) {
1915
- this._raw[6] = val;
1916
- }
1917
- get m13() {
1918
- return this._raw[7];
1919
- }
1920
- set m13(val) {
1921
- this._raw[7] = val;
2122
+ this._raw[5] = val;
1922
2123
  }
1923
2124
  get m20() {
1924
- return this._raw[8];
2125
+ return this._raw[6];
1925
2126
  }
1926
2127
  set m20(val) {
1927
- this._raw[8] = val;
2128
+ this._raw[6] = val;
1928
2129
  }
1929
2130
  get m21() {
1930
- return this._raw[9];
2131
+ return this._raw[7];
1931
2132
  }
1932
2133
  set m21(val) {
1933
- this._raw[9] = val;
2134
+ this._raw[7] = val;
1934
2135
  }
1935
2136
  get m22() {
1936
- return this._raw[10];
2137
+ return this._raw[8];
1937
2138
  }
1938
2139
  set m22(val) {
1939
- this._raw[10] = val;
1940
- }
1941
- get m23() {
1942
- return this._raw[11];
1943
- }
1944
- set m23(val) {
1945
- this._raw[11] = val;
1946
- }
1947
- get m30() {
1948
- return this._raw[12];
1949
- }
1950
- set m30(val) {
1951
- this._raw[12] = val;
1952
- }
1953
- get m31() {
1954
- return this._raw[13];
1955
- }
1956
- set m31(val) {
1957
- this._raw[13] = val;
1958
- }
1959
- get m32() {
1960
- return this._raw[14];
1961
- }
1962
- set m32(val) {
1963
- this._raw[14] = val;
1964
- }
1965
- get m33() {
1966
- return this._raw[15];
1967
- }
1968
- set m33(val) {
1969
- this._raw[15] = val;
2140
+ this._raw[8] = val;
1970
2141
  }
1971
2142
  static resolve(a) {
1972
2143
  const value = this.cast(a);
1973
2144
  if (typeof value != "undefined")
1974
2145
  return value;
1975
- throw new ResolveError("Mat4", a);
2146
+ throw new ResolveError("Mat3", a);
1976
2147
  }
1977
2148
  static resolveArgs(args) {
1978
- if (checkNumberArray(args, 16))
2149
+ if (isFixedTypeArray10(args, isValidNumber10, 9))
1979
2150
  return new this(args);
1980
2151
  return this.resolve(args[0]);
1981
2152
  }
1982
2153
  static cast(a) {
1983
2154
  if (a == null || typeof a == "undefined")
1984
2155
  return void 0;
1985
- if (checkNumberArray(a, 16)) {
2156
+ if (isFixedTypeArray10(a, isValidNumber10, 9)) {
1986
2157
  return new this(a);
1987
2158
  }
1988
- if (checkArray(a, void 0, 4)) {
1989
- const row0 = a[0], row1 = a[1], row2 = a[2], row3 = a[3];
1990
- if (checkNumberArray(row0, 4) && checkNumberArray(row1, 4) && checkNumberArray(row2, 4) && checkNumberArray(row3, 4))
2159
+ if (isFixedArray(a, 3)) {
2160
+ const row0 = a[0], row1 = a[1], row2 = a[2];
2161
+ if (isFixedTypeArray10(row0, isValidNumber10, 3) && isFixedTypeArray10(row1, isValidNumber10, 3) && isFixedTypeArray10(row2, isValidNumber10, 3))
1991
2162
  return new this([
1992
2163
  row0[0],
1993
2164
  row0[1],
1994
2165
  row0[2],
1995
- row0[3],
1996
2166
  row1[0],
1997
2167
  row1[1],
1998
2168
  row1[2],
1999
- row1[3],
2000
2169
  row2[0],
2001
2170
  row2[1],
2002
- row2[2],
2003
- row2[3],
2004
- row3[0],
2005
- row3[1],
2006
- row3[2],
2007
- row3[3]
2171
+ row2[2]
2008
2172
  ]);
2009
2173
  }
2010
- if (checkString(a)) {
2174
+ if (isValidString10(a)) {
2011
2175
  const parts = a.split(",");
2012
- if (checkStringArray(parts, 16))
2176
+ if (isFixedTypeArray10(parts, isValidString10, 9))
2013
2177
  return this.cast(parts.map((i) => parseFloat(i)));
2014
2178
  }
2015
- if (hasProperty(a, "toMat4", "function"))
2016
- return this.cast(a.toMat4());
2017
- if (hasProperty(a, "m00", "number") && hasProperty(a, "m01", "number") && hasProperty(a, "m02", "number") && hasProperty(a, "m03", "number") && hasProperty(a, "m10", "number") && hasProperty(a, "m11", "number") && hasProperty(a, "m12", "number") && hasProperty(a, "m13", "number") && hasProperty(a, "m20", "number") && hasProperty(a, "m21", "number") && hasProperty(a, "m22", "number") && hasProperty(a, "m23", "number") && hasProperty(a, "m30", "number") && hasProperty(a, "m31", "number") && hasProperty(a, "m32", "number") && hasProperty(a, "m33", "number"))
2179
+ if (hasObjectProperty10(a, "toMat3", "function"))
2180
+ return this.cast(a.toMat3());
2181
+ if (hasObjectProperty10(a, "m00", "number") && hasObjectProperty10(a, "m01", "number") && hasObjectProperty10(a, "m02", "number") && hasObjectProperty10(a, "m10", "number") && hasObjectProperty10(a, "m11", "number") && hasObjectProperty10(a, "m12", "number") && hasObjectProperty10(a, "m20", "number") && hasObjectProperty10(a, "m21", "number") && hasObjectProperty10(a, "m22", "number"))
2018
2182
  return new this([
2019
2183
  a.m00,
2020
2184
  a.m01,
2021
2185
  a.m02,
2022
- a.m03,
2023
2186
  a.m10,
2024
2187
  a.m11,
2025
2188
  a.m12,
2026
- a.m13,
2027
2189
  a.m20,
2028
2190
  a.m21,
2029
- a.m22,
2030
- a.m23,
2031
- a.m30,
2032
- a.m31,
2033
- a.m32,
2034
- a.m33
2191
+ a.m22
2035
2192
  ]);
2036
- if (checkNumber(a)) {
2037
- return new this([a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a]);
2193
+ if (isValidNumber10(a)) {
2194
+ return new this([a, a, a, a, a, a, a, a, a]);
2038
2195
  }
2039
2196
  return void 0;
2040
2197
  }
2041
2198
  static is(a) {
2042
2199
  return typeof this.cast(a) != "undefined";
2043
2200
  }
2044
- static orthographic(...args) {
2045
- const bbox = checkNumberArray(args, 6) ? new BoundingBox(args[0], args[1], args[2], args[3]) : BoundingBox.resolve(args[0]);
2046
- const near = checkNumberArray(args, 6) ? args[4] : args[1];
2047
- const far = checkNumberArray(args, 6) ? args[5] : args[2];
2048
- return new this([
2049
- 2 / (bbox.right - bbox.left),
2050
- 0,
2051
- 0,
2052
- 0,
2053
- 0,
2054
- 2 / (bbox.top - bbox.bottom),
2055
- 0,
2056
- 0,
2057
- 0,
2058
- 0,
2059
- 2 / (near - far),
2060
- 0,
2061
- (bbox.left + bbox.right) / (bbox.left - bbox.right),
2062
- (bbox.bottom + bbox.top) / (bbox.bottom - bbox.top),
2063
- (near + far) / (near - far),
2064
- 1
2065
- ]);
2066
- }
2067
- static perspective(fov, aspect, near, far) {
2068
- const f = Math.tan(Math.PI * 0.5 - 0.5 * fov);
2069
- const rangeInv = 1 / (near - far);
2201
+ static projection(width, height) {
2070
2202
  return new this([
2071
- f / aspect,
2072
- 0,
2073
- 0,
2074
- 0,
2075
- 0,
2076
- f,
2203
+ 2 / width,
2077
2204
  0,
2078
2205
  0,
2079
2206
  0,
2207
+ -2 / height,
2080
2208
  0,
2081
- (near + far) * rangeInv,
2082
2209
  -1,
2083
- 0,
2084
- 0,
2085
- near * far * rangeInv * 2,
2086
- 0
2087
- ]);
2088
- }
2089
- static pointAt(position, target, up) {
2090
- const newForward = Vec3.resolve(target).subtract(position).normalize();
2091
- const a = newForward.multiply(Vec3.resolve(up).dot(newForward));
2092
- const newUp = Vec3.resolve(up).subtract(a).normalize();
2093
- const newRight = newUp.cross(newForward);
2094
- const pos = Vec3.resolve(position);
2095
- return new this([
2096
- newRight.x,
2097
- newRight.y,
2098
- newRight.z,
2099
- 0,
2100
- newUp.x,
2101
- newUp.y,
2102
- newUp.z,
2103
- 0,
2104
- newForward.x,
2105
- newForward.y,
2106
- newForward.z,
2107
- 0,
2108
- pos.x,
2109
- pos.y,
2110
- pos.z,
2210
+ 1,
2111
2211
  1
2112
2212
  ]);
2113
2213
  }
2114
- constructor(init = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]) {
2115
- if (!checkNumberArray(init, 16))
2116
- throw new TypeError("expected a number array with 16 elements");
2214
+ constructor(init = [1, 0, 0, 0, 1, 0, 0, 0, 1]) {
2215
+ checkFixedTypeArray(init, isValidNumber10, 9);
2117
2216
  this._raw = init;
2118
2217
  }
2119
2218
  toArray() {
@@ -2121,27 +2220,19 @@ var Mat4 = class _Mat4 {
2121
2220
  this.m00,
2122
2221
  this.m01,
2123
2222
  this.m02,
2124
- this.m03,
2125
2223
  this.m10,
2126
2224
  this.m11,
2127
2225
  this.m12,
2128
- this.m13,
2129
2226
  this.m20,
2130
2227
  this.m21,
2131
- this.m22,
2132
- this.m23,
2133
- this.m30,
2134
- this.m31,
2135
- this.m32,
2136
- this.m33
2228
+ this.m22
2137
2229
  ];
2138
2230
  }
2139
2231
  toNestetArray() {
2140
2232
  return [
2141
- [this.m00, this.m01, this.m02, this.m03],
2142
- [this.m10, this.m11, this.m12, this.m13],
2143
- [this.m20, this.m21, this.m22, this.m23],
2144
- [this.m30, this.m31, this.m32, this.m33]
2233
+ [this.m00, this.m01, this.m02],
2234
+ [this.m10, this.m11, this.m12],
2235
+ [this.m20, this.m21, this.m22]
2145
2236
  ];
2146
2237
  }
2147
2238
  toJSON() {
@@ -2149,896 +2240,758 @@ var Mat4 = class _Mat4 {
2149
2240
  m00: this.m00,
2150
2241
  m01: this.m01,
2151
2242
  m02: this.m02,
2152
- m03: this.m03,
2153
2243
  m10: this.m10,
2154
2244
  m11: this.m11,
2155
2245
  m12: this.m12,
2156
- m13: this.m13,
2157
2246
  m20: this.m20,
2158
2247
  m21: this.m21,
2159
- m22: this.m22,
2160
- m23: this.m23,
2161
- m30: this.m20,
2162
- m31: this.m21,
2163
- m32: this.m22,
2164
- m33: this.m23
2248
+ m22: this.m22
2165
2249
  };
2166
2250
  }
2167
2251
  toString() {
2168
- return `${this.m00},${this.m01},${this.m02},${this.m03},${this.m10},${this.m11},${this.m12},${this.m13},${this.m20},${this.m21},${this.m22},${this.m23},${this.m30},${this.m31},${this.m32},${this.m33}`;
2252
+ return `${this.m00},${this.m01},${this.m02},${this.m10},${this.m11},${this.m12},${this.m20},${this.m21},${this.m22}`;
2169
2253
  }
2170
2254
  get [Symbol.toStringTag]() {
2171
- return "Mat4";
2255
+ return "Mat3";
2172
2256
  }
2173
- [NodeJSCustomInspect]() {
2174
- return `Mat4 <${this.toString()}>`;
2257
+ [NodeJSCustomInspect14]() {
2258
+ return `Mat3 <${this.toString()}>`;
2175
2259
  }
2176
2260
  clone() {
2177
- return new _Mat4([
2261
+ return new _Mat3([
2178
2262
  this.m00,
2179
2263
  this.m01,
2180
2264
  this.m02,
2181
- this.m03,
2182
2265
  this.m10,
2183
2266
  this.m11,
2184
2267
  this.m12,
2185
- this.m13,
2186
2268
  this.m20,
2187
2269
  this.m21,
2188
- this.m22,
2189
- this.m23,
2190
- this.m30,
2191
- this.m31,
2192
- this.m32,
2193
- this.m33
2270
+ this.m22
2194
2271
  ]);
2195
2272
  }
2196
2273
  equals(...args) {
2197
- const m = _Mat4.resolveArgs(args);
2274
+ const m = _Mat3.resolveArgs(args);
2198
2275
  for (let index = 0; index < this._raw.length; index++)
2199
2276
  if (this._raw[index] != m._raw[index])
2200
2277
  return false;
2201
2278
  return true;
2202
2279
  }
2203
2280
  add(...args) {
2204
- const b = _Mat4.resolveArgs(args);
2205
- const m = new _Mat4();
2281
+ const b = _Mat3.resolveArgs(args);
2282
+ const m = new _Mat3();
2206
2283
  for (let index = 0; index < this._raw.length; index++)
2207
2284
  m._raw[index] = this._raw[index] + b._raw[index];
2208
2285
  return m;
2209
2286
  }
2210
2287
  subtract(...args) {
2211
- const b = _Mat4.resolveArgs(args);
2212
- const m = new _Mat4();
2288
+ const b = _Mat3.resolveArgs(args);
2289
+ const m = new _Mat3();
2213
2290
  for (let index = 0; index < this._raw.length; index++)
2214
2291
  m._raw[index] = this._raw[index] - b._raw[index];
2215
2292
  return m;
2216
2293
  }
2217
2294
  multiply(...args) {
2218
- if (checkNumberArray(args, 1)) {
2219
- const scalar = args[0];
2220
- return new _Mat4([
2221
- this.m00 * scalar,
2222
- this.m01 * scalar,
2223
- this.m02 * scalar,
2224
- this.m03 * scalar,
2225
- this.m10 * scalar,
2226
- this.m11 * scalar,
2227
- this.m12 * scalar,
2228
- this.m13 * scalar,
2229
- this.m20 * scalar,
2230
- this.m21 * scalar,
2231
- this.m22 * scalar,
2232
- this.m23 * scalar,
2233
- this.m30 * scalar,
2234
- this.m31 * scalar,
2235
- this.m32 * scalar,
2236
- this.m33 * scalar
2295
+ if (isFixedTypeArray10(args, isValidNumber10, 1))
2296
+ return new _Mat3([
2297
+ this.m00 * args[0],
2298
+ this.m01 * args[0],
2299
+ this.m02 * args[0],
2300
+ this.m10 * args[0],
2301
+ this.m11 * args[0],
2302
+ this.m12 * args[0],
2303
+ this.m20 * args[0],
2304
+ this.m21 * args[0],
2305
+ this.m22 * args[0]
2237
2306
  ]);
2238
- }
2239
- const vec = Vec3.cast(args[0]);
2240
- if (vec !== void 0) {
2241
- const result = new Vec3(
2242
- vec.x * this.m00 + vec.y * this.m10 + vec.z * this.m20 + this.m30,
2243
- vec.x * this.m01 + vec.y * this.m11 + vec.z * this.m21 + this.m31,
2244
- vec.x * this.m02 + vec.y * this.m12 + vec.z * this.m22 + this.m32,
2245
- vec.x * this.m03 + vec.y * this.m13 + vec.z * this.m23 + this.m33
2246
- );
2247
- if (result.w != 0)
2248
- return result.divide(result.w);
2249
- return result;
2250
- }
2251
- const mat = _Mat4.resolveArgs(args);
2252
- return new _Mat4([
2253
- mat.m00 * this.m00 + mat.m01 * this.m10 + mat.m02 * this.m20 + mat.m03 * this.m30,
2254
- mat.m00 * this.m01 + mat.m01 * this.m11 + mat.m02 * this.m21 + mat.m03 * this.m31,
2255
- mat.m00 * this.m02 + mat.m01 * this.m12 + mat.m02 * this.m22 + mat.m03 * this.m32,
2256
- mat.m00 * this.m03 + mat.m01 * this.m13 + mat.m02 * this.m23 + mat.m03 * this.m33,
2257
- mat.m10 * this.m00 + mat.m11 * this.m10 + mat.m12 * this.m20 + mat.m13 * this.m30,
2258
- mat.m10 * this.m01 + mat.m11 * this.m11 + mat.m12 * this.m21 + mat.m13 * this.m31,
2259
- mat.m10 * this.m02 + mat.m11 * this.m12 + mat.m12 * this.m22 + mat.m13 * this.m32,
2260
- mat.m10 * this.m03 + mat.m11 * this.m13 + mat.m12 * this.m23 + mat.m13 * this.m33,
2261
- mat.m20 * this.m00 + mat.m21 * this.m10 + mat.m22 * this.m20 + mat.m23 * this.m30,
2262
- mat.m20 * this.m01 + mat.m21 * this.m11 + mat.m22 * this.m21 + mat.m23 * this.m31,
2263
- mat.m20 * this.m02 + mat.m21 * this.m12 + mat.m22 * this.m22 + mat.m23 * this.m32,
2264
- mat.m20 * this.m03 + mat.m21 * this.m13 + mat.m22 * this.m23 + mat.m23 * this.m33,
2265
- mat.m30 * this.m00 + mat.m31 * this.m10 + mat.m32 * this.m20 + mat.m33 * this.m30,
2266
- mat.m30 * this.m01 + mat.m31 * this.m11 + mat.m32 * this.m21 + mat.m33 * this.m31,
2267
- mat.m30 * this.m02 + mat.m31 * this.m12 + mat.m32 * this.m22 + mat.m33 * this.m32,
2268
- mat.m30 * this.m03 + mat.m31 * this.m13 + mat.m32 * this.m23 + mat.m33 * this.m33
2307
+ const b = _Mat3.resolveArgs(args);
2308
+ return new _Mat3([
2309
+ b.m00 * this.m00 + b.m01 * this.m10 + b.m02 * this.m20,
2310
+ b.m00 * this.m01 + b.m01 * this.m11 + b.m02 * this.m21,
2311
+ b.m00 * this.m02 + b.m01 * this.m12 + b.m02 * this.m22,
2312
+ b.m10 * this.m00 + b.m11 * this.m10 + b.m12 * this.m20,
2313
+ b.m10 * this.m01 + b.m11 * this.m11 + b.m12 * this.m21,
2314
+ b.m10 * this.m02 + b.m11 * this.m12 + b.m12 * this.m22,
2315
+ b.m20 * this.m00 + b.m21 * this.m10 + b.m22 * this.m20,
2316
+ b.m20 * this.m01 + b.m21 * this.m11 + b.m22 * this.m21,
2317
+ b.m20 * this.m02 + b.m21 * this.m12 + b.m22 * this.m22
2269
2318
  ]);
2270
2319
  }
2271
2320
  translate(...args) {
2272
- const vec = Vec3.resolveArgs(args);
2321
+ const vec = Vec2.resolveArgs(args);
2273
2322
  return this.multiply([
2274
2323
  1,
2275
2324
  0,
2276
2325
  0,
2277
2326
  0,
2278
- 0,
2279
- 1,
2280
- 0,
2281
- 0,
2282
- 0,
2283
- 0,
2284
2327
  1,
2285
2328
  0,
2286
2329
  vec.x,
2287
2330
  vec.y,
2288
- vec.z,
2289
- 1
2290
- ]);
2291
- }
2292
- rotateX(angle) {
2293
- const c = Math.cos(angle);
2294
- const s = Math.sin(angle);
2295
- return this.multiply([
2296
- 1,
2297
- 0,
2298
- 0,
2299
- 0,
2300
- 0,
2301
- c,
2302
- s,
2303
- 0,
2304
- 0,
2305
- -s,
2306
- c,
2307
- 0,
2308
- 0,
2309
- 0,
2310
- 0,
2311
2331
  1
2312
2332
  ]);
2313
2333
  }
2314
- rotateY(angle) {
2334
+ rotate(angle) {
2315
2335
  const c = Math.cos(angle);
2316
2336
  const s = Math.sin(angle);
2317
2337
  return this.multiply([
2318
2338
  c,
2319
- 0,
2320
2339
  -s,
2321
2340
  0,
2322
- 0,
2323
- 1,
2324
- 0,
2325
- 0,
2326
- s,
2327
- 0,
2328
- c,
2329
- 0,
2330
- 0,
2331
- 0,
2332
- 0,
2333
- 1
2334
- ]);
2335
- }
2336
- rotateZ(angle) {
2337
- const c = Math.cos(angle);
2338
- const s = Math.sin(angle);
2339
- return this.multiply([
2340
- c,
2341
2341
  s,
2342
- 0,
2343
- 0,
2344
- -s,
2345
2342
  c,
2346
2343
  0,
2347
2344
  0,
2348
2345
  0,
2349
- 0,
2350
- 1,
2351
- 0,
2352
- 0,
2353
- 0,
2354
- 0,
2355
2346
  1
2356
2347
  ]);
2357
2348
  }
2358
- rotate(...args) {
2359
- const vec = Vec3.resolveArgs(args);
2360
- return this.rotateX(vec.x).rotateY(vec.y).rotateZ(vec.z);
2361
- }
2362
2349
  scale(...args) {
2363
- const vec = Vec3.resolveArgs(args);
2350
+ const vec = Vec2.resolve(args);
2364
2351
  return this.multiply([
2365
2352
  vec.x,
2366
2353
  0,
2367
2354
  0,
2368
2355
  0,
2356
+ vec.y,
2357
+ 0,
2358
+ 0,
2369
2359
  0,
2370
- vec.y,
2371
- 0,
2372
- 0,
2373
- 0,
2374
- 0,
2375
- vec.z,
2376
- 0,
2377
- 0,
2378
- 0,
2379
- 0,
2380
- 1
2381
- ]);
2382
- }
2383
- inverse() {
2384
- return new _Mat4([
2385
- this.m00,
2386
- this.m10,
2387
- this.m20,
2388
- 0,
2389
- this.m01,
2390
- this.m11,
2391
- this.m21,
2392
- 0,
2393
- this.m02,
2394
- this.m12,
2395
- this.m22,
2396
- 0,
2397
- -(this.m30 * this.m00 + this.m31 * this.m10 + this.m32 * this.m20),
2398
- -(this.m30 * this.m01 + this.m31 * this.m11 + this.m32 * this.m21),
2399
- -(this.m30 * this.m02 + this.m31 * this.m12 + this.m32 * this.m22),
2400
2360
  1
2401
2361
  ]);
2402
2362
  }
2403
- toMat3() {
2363
+ determinant() {
2364
+ return this.m00 * this.m11 * this.m22 - this.m21 * this.m12 - this.m01 * this.m10 * this.m22 - this.m12 * this.m20 + this.m02 * this.m10 * this.m21 - this.m11 * this.m20;
2365
+ }
2366
+ inverse() {
2367
+ const det = this.determinant();
2368
+ return new _Mat3([
2369
+ (this.m11 * this.m22 - this.m21 * this.m12) * det,
2370
+ (this.m02 * this.m21 - this.m01 * this.m22) * det,
2371
+ (this.m01 * this.m12 - this.m02 * this.m11) * det,
2372
+ (this.m12 * this.m20 - this.m10 * this.m22) * det,
2373
+ (this.m00 * this.m22 - this.m02 * this.m20) * det,
2374
+ (this.m10 * this.m02 - this.m00 * this.m12) * det,
2375
+ (this.m10 * this.m21 - this.m20 * this.m11) * det,
2376
+ (this.m20 * this.m01 - this.m00 * this.m21) * det,
2377
+ (this.m00 * this.m11 - this.m10 * this.m01) * det
2378
+ ]);
2379
+ }
2380
+ toMat4() {
2404
2381
  return [
2405
2382
  this.m00,
2406
2383
  this.m01,
2407
- this.m03,
2384
+ this.m02,
2385
+ 0,
2408
2386
  this.m10,
2409
2387
  this.m11,
2410
- this.m13,
2411
- this.m30,
2412
- this.m31,
2413
- this.m33
2388
+ this.m12,
2389
+ 0,
2390
+ this.m20,
2391
+ this.m20,
2392
+ this.m22,
2393
+ 0,
2394
+ 0,
2395
+ 0,
2396
+ 0,
2397
+ 1
2414
2398
  ];
2415
2399
  }
2416
2400
  };
2417
2401
 
2418
- // source/color.ts
2419
- function __hex_to_array__(hex) {
2420
- if (!checkHex(hex))
2421
- return void 0;
2422
- const part = getHexValue(hex);
2423
- const red = parseInt(part.substring(0, 2), 16) / 255;
2424
- const green = parseInt(part.substring(2, 4), 16) / 255;
2425
- const blue = parseInt(part.substring(4, 6), 16) / 255;
2426
- const alpha = part.length == 8 ? parseInt(hex.substring(6, 8), 16) / 255 : 1;
2427
- return [red, green, blue, alpha];
2428
- }
2429
- function __number_to_rgb__(number) {
2430
- const blue = number & 255;
2431
- const green = (number & 65280) >>> 8;
2432
- const red = (number & 16711680) >>> 16;
2433
- return [red / 255, green / 255, blue / 255];
2434
- }
2435
- function __number_to_rgba__(number) {
2436
- const alpha = number & 255;
2437
- const blue = (number & 65280) >>> 8;
2438
- const green = (number & 16711680) >>> 16;
2439
- const red = (number & 4278190080) >>> 24;
2440
- return [red / 255, green / 255, blue / 255, alpha / 255];
2441
- }
2442
- var __to_byte__ = (scale) => clamp(scale * 255 | 0, 0, 255);
2443
- var RGBA = class _RGBA {
2444
- _red;
2445
- get red() {
2446
- return this._red;
2447
- }
2448
- set red(val) {
2449
- this._red = clamp(val, 0, 1);
2450
- }
2451
- _green;
2452
- get green() {
2453
- return this._green;
2454
- }
2455
- set green(val) {
2456
- this._green = clamp(val, 0, 1);
2457
- }
2458
- _blue;
2459
- get blue() {
2460
- return this._blue;
2461
- }
2462
- set blue(val) {
2463
- this._blue = clamp(val, 0, 1);
2464
- }
2465
- _alpha;
2466
- get alpha() {
2467
- return this._alpha;
2468
- }
2469
- set alpha(val) {
2470
- this._alpha = clamp(val, 0, 1);
2471
- }
2472
- static resolve(a) {
2473
- const value = this.cast(a);
2474
- if (typeof value != "undefined")
2475
- return value;
2476
- throw new ResolveError("RGBAColor", a);
2477
- }
2478
- static resolveArgs(args) {
2479
- if (checkNumberArray(args, 3) || checkNumberArray(args, 4))
2480
- return new this(args[0], args[1], args[2], args[3]);
2481
- return this.resolve(args[0]);
2482
- }
2483
- static cast(a) {
2484
- if (a == null || typeof a == "undefined")
2485
- return void 0;
2486
- if (checkNumberArray(a, 3) || checkNumberArray(a, 4))
2487
- return new this(a[0], a[1], a[2], a[3]);
2488
- if (hasProperty(a, "toRGB", "function"))
2489
- return this.cast(a.toRGB());
2490
- if (hasProperty(a, "toRGBA", "function"))
2491
- return this.cast(a.toRGBA());
2492
- if (hasProperty(a, "red", "number") && hasProperty(a, "green", "number") && hasProperty(a, "blue", "number"))
2493
- return new this(a.red, a.green, a.blue, hasProperty(a, "alpha", "number") ? a.alpha : void 0);
2494
- if (checkNumber(a)) {
2495
- const hex = a.toString(16);
2496
- const convert = hex.length <= 6 ? __number_to_rgb__ : __number_to_rgba__;
2497
- return this.cast(convert(a));
2498
- }
2499
- if (checkString(a)) {
2500
- if (a.startsWith("rgb")) {
2501
- const hasAlpha = a.startsWith("rgba");
2502
- const offset = hasAlpha ? 5 : 4;
2503
- const parts = a.substring(offset, a.indexOf(")", offset)).split(",");
2504
- if (checkStringArray(parts, hasAlpha ? 4 : 3))
2505
- return this.cast(parts.map((v) => parseInt(v) / 255));
2506
- }
2507
- return this.cast(__hex_to_array__(a));
2508
- }
2509
- return void 0;
2510
- }
2511
- static is(a) {
2512
- return typeof this.cast(a) != "undefined";
2513
- }
2514
- constructor(red, green, blue, alpha = 1) {
2515
- this._red = clamp(red, 0, 1);
2516
- this._green = clamp(green, 0, 1);
2517
- this._blue = clamp(blue, 0, 1);
2518
- this._alpha = clamp(alpha, 0, 1);
2519
- }
2520
- toArray(withAlpha = this._alpha !== 1) {
2521
- return withAlpha ? [this.red, this.green, this.blue, this.alpha] : [this.red, this.green, this.blue];
2522
- }
2523
- toJSON(withAlpha = this._alpha !== 1) {
2524
- return withAlpha ? {
2525
- red: this.red,
2526
- green: this.green,
2527
- blue: this.blue,
2528
- alpha: this.alpha
2529
- } : {
2530
- red: this.red,
2531
- green: this.green,
2532
- blue: this.blue
2533
- };
2534
- }
2535
- toString(withAlpha = this._alpha !== 1) {
2536
- return withAlpha ? `rgba(${__to_byte__(this.red)},${__to_byte__(this.green)},${__to_byte__(this.blue)},${this.alpha})` : `rgb(${__to_byte__(this.red)},${__to_byte__(this.green)},${__to_byte__(this.blue)})`;
2537
- }
2538
- get [Symbol.toStringTag]() {
2539
- return "RGBA";
2540
- }
2541
- [NodeJSCustomInspect]() {
2542
- return `RGBA <${this.toString()}>`;
2543
- }
2544
- toVec2() {
2545
- return [this.red, this.green, this.blue];
2546
- }
2547
- toVec3() {
2548
- return [this.red, this.green, this.blue, this.alpha];
2549
- }
2550
- toHSL(withAlpha = this._alpha !== 1) {
2551
- const red = this.red, green = this.green, blue = this.blue;
2552
- const min = Math.min(red, green, blue), max = Math.max(red, green, blue);
2553
- const luminace = (min + max) / 2;
2554
- if (min == max)
2555
- return new HSLA(0, 0, luminace, withAlpha ? this.alpha : void 0);
2556
- const d = max - min;
2557
- const saturation = luminace > 0.5 ? d / (2 - max - min) : d / (max + min);
2558
- if (max == red)
2559
- return new HSLA(((green - blue) / d + (green < blue ? 6 : 0)) / 6, saturation, luminace, withAlpha ? this.alpha : void 0);
2560
- if (max == green)
2561
- return new HSLA(((blue - red) / d + 2) / 6, saturation, luminace, withAlpha ? this.alpha : void 0);
2562
- if (max == blue)
2563
- return new HSLA(((red - green) / d + 4) / 6, saturation, luminace, withAlpha ? this.alpha : void 0);
2564
- return new HSLA(0, saturation, luminace, withAlpha ? this.alpha : void 0);
2565
- }
2566
- toHSLA() {
2567
- return this.toHSL(true);
2568
- }
2569
- invert(withAlpha = this._alpha !== 1) {
2570
- return new _RGBA(
2571
- 1 - this.red,
2572
- 1 - this.green,
2573
- 1 - this.blue,
2574
- withAlpha ? 1 - this.alpha : this.alpha
2575
- );
2576
- }
2577
- };
2578
- var HSLA = class _HSLA {
2579
- _hue;
2580
- get hue() {
2581
- return this._hue;
2402
+ // source/matrices/mat4.ts
2403
+ import { isValidNumber as isValidNumber11, isValidString as isValidString11, hasObjectProperty as hasObjectProperty11, NodeJSCustomInspect as NodeJSCustomInspect15, isFixedTypeArray as isFixedTypeArray11, isFixedArray as isFixedArray2, checkFixedTypeArray as checkFixedTypeArray2 } from "@ntf/types";
2404
+ var Mat4 = class _Mat4 {
2405
+ _raw;
2406
+ get m00() {
2407
+ return this._raw[0];
2582
2408
  }
2583
- set hue(val) {
2584
- this._hue = clamp(val, 0, 1);
2409
+ set m00(val) {
2410
+ this._raw[0] = val;
2585
2411
  }
2586
- _saturation;
2587
- get saturation() {
2588
- return this._saturation;
2412
+ get m01() {
2413
+ return this._raw[1];
2589
2414
  }
2590
- set saturation(val) {
2591
- this._saturation = clamp(val, 0, 1);
2415
+ set m01(val) {
2416
+ this._raw[1] = val;
2592
2417
  }
2593
- _luminace;
2594
- get luminace() {
2595
- return this._luminace;
2418
+ get m02() {
2419
+ return this._raw[2];
2596
2420
  }
2597
- set luminace(val) {
2598
- this._luminace = clamp(val, 0, 1);
2421
+ set m02(val) {
2422
+ this._raw[2] = val;
2599
2423
  }
2600
- _alpha;
2601
- get alpha() {
2602
- return this._alpha;
2424
+ get m03() {
2425
+ return this._raw[3];
2603
2426
  }
2604
- set alpha(val) {
2605
- this._alpha = clamp(val, 0, 1);
2427
+ set m03(val) {
2428
+ this._raw[3] = val;
2606
2429
  }
2607
- static resolve(a) {
2608
- const value = this.cast(a);
2609
- if (typeof value != "undefined")
2610
- return value;
2611
- throw new ResolveError("HSLColor", a);
2430
+ get m10() {
2431
+ return this._raw[4];
2612
2432
  }
2613
- static resolveArgs(args) {
2614
- if (checkNumberArray(args, 3) || checkNumberArray(args, 4))
2615
- return new this(args[0], args[1], args[2], args[3]);
2616
- return this.resolve(args[0]);
2433
+ set m10(val) {
2434
+ this._raw[4] = val;
2617
2435
  }
2618
- static cast(a) {
2619
- if (a == null || typeof a == "undefined")
2620
- return void 0;
2621
- if (checkNumberArray(a, 3) || checkNumberArray(a, 4))
2622
- return new this(a[0], a[1], a[2], a[3]);
2623
- if (hasProperty(a, "toHSL", "function"))
2624
- return this.cast(a.toHSL());
2625
- if (hasProperty(a, "toHSLA", "function"))
2626
- return this.cast(a.toHSLA());
2627
- if (hasProperty(a, "hue", "number") && hasProperty(a, "saturation", "number") && hasProperty(a, "luminace", "number"))
2628
- return new this(a.hue, a.saturation, a.luminace, hasProperty(a, "alpha", "number") ? a.alpha : void 0);
2629
- if (checkNumber(a)) {
2630
- const hex = a.toString(16);
2631
- const convert = hex.length <= 6 ? __number_to_rgb__ : __number_to_rgba__;
2632
- return this.cast(convert(a));
2633
- }
2634
- if (checkString(a)) {
2635
- if (a.startsWith("hsl")) {
2636
- const hasAlpha = a.startsWith("hsla");
2637
- const offset = hasAlpha ? 5 : 4;
2638
- const parts = a.substring(offset, a.indexOf(")", offset)).split(",");
2639
- if (checkStringArray(parts, hasAlpha ? 4 : 3))
2640
- return this.cast(parts.map((v) => parseInt(v) / 255));
2641
- }
2642
- return this.cast(__hex_to_array__(a));
2643
- }
2644
- return void 0;
2436
+ get m11() {
2437
+ return this._raw[5];
2645
2438
  }
2646
- static is(a) {
2647
- return typeof this.cast(a) != "undefined";
2439
+ set m11(val) {
2440
+ this._raw[5] = val;
2648
2441
  }
2649
- constructor(hue, saturation, luminace, alpha = 1) {
2650
- if (!checkNumber(hue))
2651
- throw new TypeError("expected number for hue");
2652
- if (!checkNumber(saturation))
2653
- throw new TypeError("expected number for saturation");
2654
- if (!checkNumber(luminace))
2655
- throw new TypeError("expected number for luminace");
2656
- if (!checkNumber(alpha))
2657
- throw new TypeError("expected number for alpha");
2658
- this._hue = clamp(hue, 0, 1);
2659
- this._saturation = clamp(saturation, 0, 1);
2660
- this._luminace = clamp(luminace, 0, 1);
2661
- this._alpha = clamp(alpha, 0, 1);
2442
+ get m12() {
2443
+ return this._raw[6];
2662
2444
  }
2663
- toArray(withAlpha = this._alpha !== 1) {
2664
- return withAlpha ? [this.hue, this.saturation, this.luminace, this.alpha] : [this.hue, this.saturation, this.luminace];
2445
+ set m12(val) {
2446
+ this._raw[6] = val;
2665
2447
  }
2666
- toJSON(withAlpha = this._alpha !== 1) {
2667
- return withAlpha ? {
2668
- hue: this.hue,
2669
- saturation: this.saturation,
2670
- luminace: this.luminace,
2671
- alpha: this.alpha
2672
- } : {
2673
- hue: this.hue,
2674
- saturation: this.saturation,
2675
- luminace: this.luminace
2676
- };
2448
+ get m13() {
2449
+ return this._raw[7];
2677
2450
  }
2678
- toString(withAlpha = this._alpha !== 1) {
2679
- return withAlpha ? `hsla(${__to_byte__(this.hue)},${__to_byte__(this.saturation)},${__to_byte__(this.luminace)},${this.alpha})` : `hsl(${__to_byte__(this.hue)},${__to_byte__(this.saturation)},${__to_byte__(this.luminace)})`;
2451
+ set m13(val) {
2452
+ this._raw[7] = val;
2680
2453
  }
2681
- get [Symbol.toStringTag]() {
2682
- return "HSLA";
2454
+ get m20() {
2455
+ return this._raw[8];
2683
2456
  }
2684
- [NodeJSCustomInspect]() {
2685
- return `HSLA <${this.toString()}>`;
2457
+ set m20(val) {
2458
+ this._raw[8] = val;
2686
2459
  }
2687
- toRGB(withAlpha = this._alpha !== 1) {
2688
- if (this.saturation == 0)
2689
- return new RGBA(this.luminace * 255, this.luminace * 255, this.luminace * 255, withAlpha ? this.alpha : void 0);
2690
- const q = this.luminace < 0.5 ? this.luminace * (1 + this.saturation) : this.luminace + this.saturation - this.luminace * this.saturation;
2691
- const p = 2 * this.luminace - q;
2692
- function __hue_2_rgb__(t) {
2693
- let _t = t;
2694
- if (_t < 0)
2695
- _t++;
2696
- if (_t > 1)
2697
- _t--;
2698
- if (_t < 1 / 6)
2699
- return p + (q - p) * 6 * _t;
2700
- if (_t < 1 / 2)
2701
- return q;
2702
- if (_t < 2 / 3)
2703
- return p + (q - p) * (2 / 3 - _t) * 6;
2704
- return p;
2705
- }
2706
- return new RGBA(__hue_2_rgb__(this.hue + 1 / 3) * 255, __hue_2_rgb__(this.hue) * 255, __hue_2_rgb__(this.hue - 1 / 3) * 255, withAlpha ? this.alpha : void 0);
2460
+ get m21() {
2461
+ return this._raw[9];
2707
2462
  }
2708
- toRGBA() {
2709
- return this.toRGB(true);
2463
+ set m21(val) {
2464
+ this._raw[9] = val;
2710
2465
  }
2711
- toVec2() {
2712
- return [this.hue, this.saturation, this.luminace];
2466
+ get m22() {
2467
+ return this._raw[10];
2713
2468
  }
2714
- toVec3() {
2715
- return [this.hue, this.saturation, this.luminace, this.alpha];
2469
+ set m22(val) {
2470
+ this._raw[10] = val;
2716
2471
  }
2717
- invert(withAlpha = this._alpha !== 1) {
2718
- return new _HSLA(
2719
- 1 - this.hue,
2720
- 1 - this.saturation,
2721
- 1 - this.luminace,
2722
- withAlpha ? 1 - this.alpha : this.alpha
2723
- );
2472
+ get m23() {
2473
+ return this._raw[11];
2724
2474
  }
2725
- };
2726
- var AnyColor;
2727
- ((AnyColor2) => {
2728
- function cast(a, preferHSL = false) {
2729
- const results = [];
2730
- try {
2731
- const rgba = RGBA.resolve(a);
2732
- results.push(rgba);
2733
- } catch (e) {
2734
- }
2735
- try {
2736
- const hsla = HSLA.resolve(a);
2737
- results.push(hsla);
2738
- } catch (e) {
2739
- }
2740
- let offset = preferHSL ? 1 : 0;
2741
- const firstItem = results[offset];
2742
- if (firstItem)
2743
- return firstItem;
2744
- const secondItem = results[offset + 1];
2745
- if (secondItem)
2746
- return secondItem;
2747
- return void 0;
2475
+ set m23(val) {
2476
+ this._raw[11] = val;
2748
2477
  }
2749
- AnyColor2.cast = cast;
2750
- function resolve(a, preferHSL = false) {
2751
- const value = cast(a, preferHSL);
2752
- if (typeof value != "undefined")
2753
- return value;
2754
- throw new ResolveError("Color", a);
2478
+ get m30() {
2479
+ return this._raw[12];
2755
2480
  }
2756
- AnyColor2.resolve = resolve;
2757
- function resolveArgs(args, preferHSL = false) {
2758
- if (checkNumberArray(args, 3) || checkNumberArray(args, 4))
2759
- return resolve(args, preferHSL);
2760
- return resolve(args[0], preferHSL);
2481
+ set m30(val) {
2482
+ this._raw[12] = val;
2761
2483
  }
2762
- AnyColor2.resolveArgs = resolveArgs;
2763
- })(AnyColor || (AnyColor = {}));
2764
-
2765
- // source/quaternion.ts
2766
- var Quaternion = class _Quaternion {
2767
- w;
2768
- x;
2769
- y;
2770
- z;
2771
- static is(a) {
2772
- return typeof this.cast(a) != "undefined";
2484
+ get m31() {
2485
+ return this._raw[13];
2486
+ }
2487
+ set m31(val) {
2488
+ this._raw[13] = val;
2489
+ }
2490
+ get m32() {
2491
+ return this._raw[14];
2492
+ }
2493
+ set m32(val) {
2494
+ this._raw[14] = val;
2495
+ }
2496
+ get m33() {
2497
+ return this._raw[15];
2498
+ }
2499
+ set m33(val) {
2500
+ this._raw[15] = val;
2773
2501
  }
2774
2502
  static resolve(a) {
2775
2503
  const value = this.cast(a);
2776
2504
  if (typeof value != "undefined")
2777
2505
  return value;
2778
- throw new ResolveError("Quaternion", a);
2506
+ throw new ResolveError("Mat4", a);
2779
2507
  }
2780
2508
  static resolveArgs(args) {
2781
- if (checkNumberArray(args, 4))
2782
- return new this(args[0], args[1], args[2], args[3]);
2509
+ if (isFixedTypeArray11(args, isValidNumber11, 16))
2510
+ return new this(args);
2783
2511
  return this.resolve(args[0]);
2784
2512
  }
2785
2513
  static cast(a) {
2786
2514
  if (a == null || typeof a == "undefined")
2787
2515
  return void 0;
2788
- if (checkNumberArray(a, 4))
2789
- return new this(a[0], a[1], a[2], a[3]);
2790
- if (hasProperty(a, "toQuaternion", "function"))
2791
- return this.cast(a.toQuaternion());
2792
- if (hasProperty(a, "w", "number") && hasProperty(a, "x", "number") && hasProperty(a, "y", "number") && hasProperty(a, "z", "number"))
2793
- return new this(a.w, a.x, a.y, a.z);
2794
- if (checkString(a)) {
2795
- const parts = a.replaceAll(" ", "").split("+");
2796
- if (checkStringArray(parts, 4)) {
2797
- const [sw, sxi, syj, szk] = parts;
2798
- if (sxi.endsWith("i") && syj.endsWith("j") && szk.endsWith("k"))
2799
- return this.cast([
2800
- parseFloat(sw),
2801
- parseFloat(sxi.substring(0, sxi.length - 1)),
2802
- parseFloat(syj.substring(0, syj.length - 1)),
2803
- parseFloat(szk.substring(0, szk.length - 1))
2804
- ]);
2805
- }
2516
+ if (isFixedTypeArray11(a, isValidNumber11, 16)) {
2517
+ return new this(a);
2518
+ }
2519
+ if (isFixedArray2(a, 4)) {
2520
+ const row0 = a[0], row1 = a[1], row2 = a[2], row3 = a[3];
2521
+ if (isFixedTypeArray11(row0, isValidNumber11, 4) && isFixedTypeArray11(row1, isValidNumber11, 4) && isFixedTypeArray11(row2, isValidNumber11, 4) && isFixedTypeArray11(row3, isValidNumber11, 4))
2522
+ return new this([
2523
+ row0[0],
2524
+ row0[1],
2525
+ row0[2],
2526
+ row0[3],
2527
+ row1[0],
2528
+ row1[1],
2529
+ row1[2],
2530
+ row1[3],
2531
+ row2[0],
2532
+ row2[1],
2533
+ row2[2],
2534
+ row2[3],
2535
+ row3[0],
2536
+ row3[1],
2537
+ row3[2],
2538
+ row3[3]
2539
+ ]);
2540
+ }
2541
+ if (isValidString11(a)) {
2542
+ const parts = a.split(",");
2543
+ if (isFixedTypeArray11(parts, isValidString11, 16))
2544
+ return this.cast(parts.map((i) => parseFloat(i)));
2545
+ }
2546
+ if (hasObjectProperty11(a, "toMat4", "function"))
2547
+ return this.cast(a.toMat4());
2548
+ if (hasObjectProperty11(a, "m00", "number") && hasObjectProperty11(a, "m01", "number") && hasObjectProperty11(a, "m02", "number") && hasObjectProperty11(a, "m03", "number") && hasObjectProperty11(a, "m10", "number") && hasObjectProperty11(a, "m11", "number") && hasObjectProperty11(a, "m12", "number") && hasObjectProperty11(a, "m13", "number") && hasObjectProperty11(a, "m20", "number") && hasObjectProperty11(a, "m21", "number") && hasObjectProperty11(a, "m22", "number") && hasObjectProperty11(a, "m23", "number") && hasObjectProperty11(a, "m30", "number") && hasObjectProperty11(a, "m31", "number") && hasObjectProperty11(a, "m32", "number") && hasObjectProperty11(a, "m33", "number"))
2549
+ return new this([
2550
+ a.m00,
2551
+ a.m01,
2552
+ a.m02,
2553
+ a.m03,
2554
+ a.m10,
2555
+ a.m11,
2556
+ a.m12,
2557
+ a.m13,
2558
+ a.m20,
2559
+ a.m21,
2560
+ a.m22,
2561
+ a.m23,
2562
+ a.m30,
2563
+ a.m31,
2564
+ a.m32,
2565
+ a.m33
2566
+ ]);
2567
+ if (isValidNumber11(a)) {
2568
+ return new this([a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a]);
2806
2569
  }
2807
2570
  return void 0;
2808
2571
  }
2809
- static fromAxisAngle(...args) {
2810
- const axis = checkNumberArray(args, 4) ? new Vec3(args[0], args[1], args[2]) : Vec3.resolve(args[0]);
2811
- const angle = checkNumberArray(args, 4) ? args[3] : args[1];
2812
- const vec = Vec3.resolve(axis);
2813
- const hangle = angle * 0.5;
2814
- const sin2 = Math.sin(hangle);
2815
- const cos2 = Math.cos(hangle);
2816
- const length = sin2 / Math.sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z);
2817
- return new this(cos2, vec.x * length, vec.y * length, vec.z * length);
2572
+ static is(a) {
2573
+ return typeof this.cast(a) != "undefined";
2818
2574
  }
2819
- static fromEuler(...args) {
2820
- const vec = Vec3.resolveArgs(args);
2821
- const x2 = vec.x * 0.5, y2 = vec.y * 0.5, z2 = vec.z * 0.5;
2822
- const cx = Math.cos(x2), cy = Math.cos(y2), cz = Math.cos(z2);
2823
- const sx = Math.sin(x2), sy = Math.sin(y2), sz = Math.sin(z2);
2824
- return new _Quaternion(
2825
- cx * cy * cz - sx * sy * sz,
2826
- sx * cy * cz - sy * sz * cx,
2827
- sy * cx * cz - sx * sz * cy,
2828
- sx * sy * cz + sz * cx * cy
2829
- );
2575
+ static orthographic(...args) {
2576
+ const bbox = isFixedTypeArray11(args, isValidNumber11, 6) ? new BoundingBox(args[0], args[1], args[2], args[3]) : BoundingBox.resolve(args[0]);
2577
+ const near = isFixedTypeArray11(args, isValidNumber11, 6) ? args[4] : args[1];
2578
+ const far = isFixedTypeArray11(args, isValidNumber11, 6) ? args[5] : args[2];
2579
+ return new this([
2580
+ 2 / (bbox.right - bbox.left),
2581
+ 0,
2582
+ 0,
2583
+ 0,
2584
+ 0,
2585
+ 2 / (bbox.top - bbox.bottom),
2586
+ 0,
2587
+ 0,
2588
+ 0,
2589
+ 0,
2590
+ 2 / (near - far),
2591
+ 0,
2592
+ (bbox.left + bbox.right) / (bbox.left - bbox.right),
2593
+ (bbox.bottom + bbox.top) / (bbox.bottom - bbox.top),
2594
+ (near + far) / (near - far),
2595
+ 1
2596
+ ]);
2597
+ }
2598
+ static perspective(fov, aspect, near, far) {
2599
+ const f = Math.tan(Math.PI * 0.5 - 0.5 * fov);
2600
+ const rangeInv = 1 / (near - far);
2601
+ return new this([
2602
+ f / aspect,
2603
+ 0,
2604
+ 0,
2605
+ 0,
2606
+ 0,
2607
+ f,
2608
+ 0,
2609
+ 0,
2610
+ 0,
2611
+ 0,
2612
+ (near + far) * rangeInv,
2613
+ -1,
2614
+ 0,
2615
+ 0,
2616
+ near * far * rangeInv * 2,
2617
+ 0
2618
+ ]);
2830
2619
  }
2831
- static get zero() {
2832
- return new _Quaternion(0, 0, 0, 0);
2620
+ static pointAt(position, target, up) {
2621
+ const newForward = Vec3.resolve(target).subtract(position).normalize();
2622
+ const a = newForward.multiply(Vec3.resolve(up).dot(newForward));
2623
+ const newUp = Vec3.resolve(up).subtract(a).normalize();
2624
+ const newRight = newUp.cross(newForward);
2625
+ const pos = Vec3.resolve(position);
2626
+ return new this([
2627
+ newRight.x,
2628
+ newRight.y,
2629
+ newRight.z,
2630
+ 0,
2631
+ newUp.x,
2632
+ newUp.y,
2633
+ newUp.z,
2634
+ 0,
2635
+ newForward.x,
2636
+ newForward.y,
2637
+ newForward.z,
2638
+ 0,
2639
+ pos.x,
2640
+ pos.y,
2641
+ pos.z,
2642
+ 1
2643
+ ]);
2833
2644
  }
2834
- constructor(w, x, y, z) {
2835
- if (!checkNumber(w))
2836
- throw new TypeError("expected number for w");
2837
- if (!checkNumber(x))
2838
- throw new TypeError("expected number for x");
2839
- if (!checkNumber(y))
2840
- throw new TypeError("expected number for x");
2841
- if (!checkNumber(z))
2842
- throw new TypeError("expected number for w");
2843
- this.w = w;
2844
- this.x = x;
2845
- this.y = y;
2846
- this.z = z;
2645
+ constructor(init = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]) {
2646
+ checkFixedTypeArray2(init, isValidNumber11, 16);
2647
+ this._raw = init;
2847
2648
  }
2848
2649
  toArray() {
2849
- return [this.w, this.x, this.y, this.z];
2850
- }
2851
- toString() {
2852
- return `${this.w} + ${this.x}i + ${this.y}j + ${this.z}k`;
2853
- }
2854
- get [Symbol.toStringTag]() {
2855
- return "Quaternion";
2650
+ return [
2651
+ this.m00,
2652
+ this.m01,
2653
+ this.m02,
2654
+ this.m03,
2655
+ this.m10,
2656
+ this.m11,
2657
+ this.m12,
2658
+ this.m13,
2659
+ this.m20,
2660
+ this.m21,
2661
+ this.m22,
2662
+ this.m23,
2663
+ this.m30,
2664
+ this.m31,
2665
+ this.m32,
2666
+ this.m33
2667
+ ];
2856
2668
  }
2857
- [NodeJSCustomInspect]() {
2858
- return `Quaternion <${this.toString()}>`;
2669
+ toNestetArray() {
2670
+ return [
2671
+ [this.m00, this.m01, this.m02, this.m03],
2672
+ [this.m10, this.m11, this.m12, this.m13],
2673
+ [this.m20, this.m21, this.m22, this.m23],
2674
+ [this.m30, this.m31, this.m32, this.m33]
2675
+ ];
2859
2676
  }
2860
2677
  toJSON() {
2861
2678
  return {
2862
- w: this.w,
2863
- x: this.x,
2864
- y: this.y,
2865
- z: this.z
2679
+ m00: this.m00,
2680
+ m01: this.m01,
2681
+ m02: this.m02,
2682
+ m03: this.m03,
2683
+ m10: this.m10,
2684
+ m11: this.m11,
2685
+ m12: this.m12,
2686
+ m13: this.m13,
2687
+ m20: this.m20,
2688
+ m21: this.m21,
2689
+ m22: this.m22,
2690
+ m23: this.m23,
2691
+ m30: this.m20,
2692
+ m31: this.m21,
2693
+ m32: this.m22,
2694
+ m33: this.m23
2866
2695
  };
2867
2696
  }
2868
- clone() {
2869
- return new _Quaternion(this.w, this.x, this.y, this.z);
2697
+ toString() {
2698
+ return `${this.m00},${this.m01},${this.m02},${this.m03},${this.m10},${this.m11},${this.m12},${this.m13},${this.m20},${this.m21},${this.m22},${this.m23},${this.m30},${this.m31},${this.m32},${this.m33}`;
2870
2699
  }
2871
- add(...args) {
2872
- const quat = _Quaternion.resolveArgs(args);
2873
- return new _Quaternion(
2874
- this.w + quat.w,
2875
- this.x + quat.x,
2876
- this.y + quat.y,
2877
- this.z + quat.z
2878
- );
2700
+ get [Symbol.toStringTag]() {
2701
+ return "Mat4";
2879
2702
  }
2880
- offset(...args) {
2881
- const quat = _Quaternion.resolveArgs(args);
2882
- this.w += quat.w;
2883
- this.x += quat.x;
2884
- this.y += quat.y;
2885
- this.z += quat.z;
2886
- return this;
2703
+ [NodeJSCustomInspect15]() {
2704
+ return `Mat4 <${this.toString()}>`;
2887
2705
  }
2888
- subtract(...args) {
2889
- const quat = _Quaternion.resolveArgs(args);
2890
- return new _Quaternion(
2891
- this.w - quat.w,
2892
- this.x - quat.x,
2893
- this.y - quat.y,
2894
- this.z - quat.z
2895
- );
2706
+ clone() {
2707
+ return new _Mat4([
2708
+ this.m00,
2709
+ this.m01,
2710
+ this.m02,
2711
+ this.m03,
2712
+ this.m10,
2713
+ this.m11,
2714
+ this.m12,
2715
+ this.m13,
2716
+ this.m20,
2717
+ this.m21,
2718
+ this.m22,
2719
+ this.m23,
2720
+ this.m30,
2721
+ this.m31,
2722
+ this.m32,
2723
+ this.m33
2724
+ ]);
2896
2725
  }
2897
- negative() {
2898
- return new _Quaternion(-this.w, -this.x, -this.y, -this.z);
2726
+ equals(...args) {
2727
+ const m = _Mat4.resolveArgs(args);
2728
+ for (let index = 0; index < this._raw.length; index++)
2729
+ if (this._raw[index] != m._raw[index])
2730
+ return false;
2731
+ return true;
2899
2732
  }
2900
- length(sqrt = true) {
2901
- const value = this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z;
2902
- return sqrt ? Math.sqrt(value) : value;
2733
+ add(...args) {
2734
+ const b = _Mat4.resolveArgs(args);
2735
+ const m = new _Mat4();
2736
+ for (let index = 0; index < this._raw.length; index++)
2737
+ m._raw[index] = this._raw[index] + b._raw[index];
2738
+ return m;
2903
2739
  }
2904
- normalize() {
2905
- let length = this.length();
2906
- if (length < EPSILON)
2907
- return _Quaternion.zero;
2908
- length = 1 / length;
2909
- return new _Quaternion(this.w * length, this.x * length, this.y * length, this.z * length);
2740
+ subtract(...args) {
2741
+ const b = _Mat4.resolveArgs(args);
2742
+ const m = new _Mat4();
2743
+ for (let index = 0; index < this._raw.length; index++)
2744
+ m._raw[index] = this._raw[index] - b._raw[index];
2745
+ return m;
2910
2746
  }
2911
2747
  multiply(...args) {
2912
- const quat = _Quaternion.resolveArgs(args);
2913
- return new _Quaternion(
2914
- this.w * quat.w - this.x * quat.x - this.y * quat.y - this.z * quat.z,
2915
- this.w * quat.x + this.x * quat.w + this.y * quat.z - this.z * quat.y,
2916
- this.w * quat.y + this.y * quat.w + this.z * quat.x - this.x * quat.z,
2917
- this.w * quat.z + this.z * quat.w + this.x * quat.y - this.y * quat.x
2918
- );
2919
- }
2920
- multiplyVector(...args) {
2921
- const vec = Vec3.resolveArgs(args);
2922
- const ix = this.w * vec.x + this.y * vec.y - this.z * vec.y;
2923
- const iy = this.w * vec.y + this.z * vec.x - this.x * vec.z;
2924
- const iz = this.w * vec.z + this.x * vec.y - this.y * vec.x;
2925
- const iw = -this.w * vec.x - this.y * vec.y - this.z * vec.z;
2926
- return new Vec3(
2927
- ix * this.w + iw * -this.x + iy * -this.z - iz * -this.y,
2928
- iy * this.w + iw * -this.y + iz * -this.x - ix * -this.z,
2929
- iz * this.w + iw * -this.z + ix * -this.y - iy * -this.x
2930
- );
2931
- }
2932
- scale(scalar) {
2933
- return new _Quaternion(this.w * scalar, this.x * scalar, this.y * scalar, this.z * scalar);
2934
- }
2935
- dot(...args) {
2936
- const quat = _Quaternion.resolveArgs(args);
2937
- return this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z;
2938
- }
2939
- inverse() {
2940
- let length = this.length(false);
2941
- if (length == 0)
2942
- return _Quaternion.zero;
2943
- length = 1 / length;
2944
- return new _Quaternion(this.w * length, -this.x * length, -this.y * length, -this.z * length);
2945
- }
2946
- divide(...args) {
2947
- const quat = _Quaternion.resolveArgs(args);
2948
- let length = quat.length(false);
2949
- if (length == 0) return _Quaternion.zero;
2950
- length = 1 / length;
2951
- return new _Quaternion(
2952
- (this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z) * length,
2953
- (this.x * quat.w - this.w * quat.x - this.y * quat.z + this.z * quat.y) * length,
2954
- (this.y * quat.w - this.w * quat.y - this.z * quat.x + this.x * quat.z) * length,
2955
- (this.z * quat.w - this.w * quat.z - this.x * quat.y + this.y * quat.x) * length
2956
- );
2957
- }
2958
- conjugate() {
2959
- return new _Quaternion(this.w, -this.x, -this.y, -this.z);
2960
- }
2961
- exp() {
2962
- const length = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
2963
- const exp = Math.exp(this.w);
2964
- const scale = exp * Math.sin(length) / length;
2965
- if (length == 0)
2966
- return new _Quaternion(exp, 0, 0, 0);
2967
- return new _Quaternion(
2968
- exp * Math.cos(length),
2969
- this.x * scale,
2970
- this.y * scale,
2971
- this.z * scale
2972
- );
2748
+ if (isFixedTypeArray11(args, isValidNumber11, 1)) {
2749
+ const scalar = args[0];
2750
+ return new _Mat4([
2751
+ this.m00 * scalar,
2752
+ this.m01 * scalar,
2753
+ this.m02 * scalar,
2754
+ this.m03 * scalar,
2755
+ this.m10 * scalar,
2756
+ this.m11 * scalar,
2757
+ this.m12 * scalar,
2758
+ this.m13 * scalar,
2759
+ this.m20 * scalar,
2760
+ this.m21 * scalar,
2761
+ this.m22 * scalar,
2762
+ this.m23 * scalar,
2763
+ this.m30 * scalar,
2764
+ this.m31 * scalar,
2765
+ this.m32 * scalar,
2766
+ this.m33 * scalar
2767
+ ]);
2768
+ }
2769
+ const vec = Vec3.cast(args[0]);
2770
+ if (vec !== void 0) {
2771
+ const result = new Vec3(
2772
+ vec.x * this.m00 + vec.y * this.m10 + vec.z * this.m20 + this.m30,
2773
+ vec.x * this.m01 + vec.y * this.m11 + vec.z * this.m21 + this.m31,
2774
+ vec.x * this.m02 + vec.y * this.m12 + vec.z * this.m22 + this.m32,
2775
+ vec.x * this.m03 + vec.y * this.m13 + vec.z * this.m23 + this.m33
2776
+ );
2777
+ if (result.w != 0)
2778
+ return result.divide(result.w);
2779
+ return result;
2780
+ }
2781
+ const mat = _Mat4.resolveArgs(args);
2782
+ return new _Mat4([
2783
+ mat.m00 * this.m00 + mat.m01 * this.m10 + mat.m02 * this.m20 + mat.m03 * this.m30,
2784
+ mat.m00 * this.m01 + mat.m01 * this.m11 + mat.m02 * this.m21 + mat.m03 * this.m31,
2785
+ mat.m00 * this.m02 + mat.m01 * this.m12 + mat.m02 * this.m22 + mat.m03 * this.m32,
2786
+ mat.m00 * this.m03 + mat.m01 * this.m13 + mat.m02 * this.m23 + mat.m03 * this.m33,
2787
+ mat.m10 * this.m00 + mat.m11 * this.m10 + mat.m12 * this.m20 + mat.m13 * this.m30,
2788
+ mat.m10 * this.m01 + mat.m11 * this.m11 + mat.m12 * this.m21 + mat.m13 * this.m31,
2789
+ mat.m10 * this.m02 + mat.m11 * this.m12 + mat.m12 * this.m22 + mat.m13 * this.m32,
2790
+ mat.m10 * this.m03 + mat.m11 * this.m13 + mat.m12 * this.m23 + mat.m13 * this.m33,
2791
+ mat.m20 * this.m00 + mat.m21 * this.m10 + mat.m22 * this.m20 + mat.m23 * this.m30,
2792
+ mat.m20 * this.m01 + mat.m21 * this.m11 + mat.m22 * this.m21 + mat.m23 * this.m31,
2793
+ mat.m20 * this.m02 + mat.m21 * this.m12 + mat.m22 * this.m22 + mat.m23 * this.m32,
2794
+ mat.m20 * this.m03 + mat.m21 * this.m13 + mat.m22 * this.m23 + mat.m23 * this.m33,
2795
+ mat.m30 * this.m00 + mat.m31 * this.m10 + mat.m32 * this.m20 + mat.m33 * this.m30,
2796
+ mat.m30 * this.m01 + mat.m31 * this.m11 + mat.m32 * this.m21 + mat.m33 * this.m31,
2797
+ mat.m30 * this.m02 + mat.m31 * this.m12 + mat.m32 * this.m22 + mat.m33 * this.m32,
2798
+ mat.m30 * this.m03 + mat.m31 * this.m13 + mat.m32 * this.m23 + mat.m33 * this.m33
2799
+ ]);
2973
2800
  }
2974
- log() {
2975
- if (this.x == 0 && this.z == 0)
2976
- return new _Quaternion(logHypot(this.w, this.x), Math.atan2(this.x, this.w), 0, 0);
2977
- const length = this.length(false);
2978
- const length2 = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
2979
- const scale = Math.atan2(length2, this.w) / length;
2980
- return new _Quaternion(Math.log(length) * 0.5, this.x * scale, this.y * scale, this.z * scale);
2801
+ translate(...args) {
2802
+ const vec = Vec3.resolveArgs(args);
2803
+ return this.multiply([
2804
+ 1,
2805
+ 0,
2806
+ 0,
2807
+ 0,
2808
+ 0,
2809
+ 1,
2810
+ 0,
2811
+ 0,
2812
+ 0,
2813
+ 0,
2814
+ 1,
2815
+ 0,
2816
+ vec.x,
2817
+ vec.y,
2818
+ vec.z,
2819
+ 1
2820
+ ]);
2981
2821
  }
2982
- toVec3() {
2983
- return [this.x, this.y, this.z, this.w];
2822
+ rotateX(angle) {
2823
+ const c = Math.cos(angle);
2824
+ const s = Math.sin(angle);
2825
+ return this.multiply([
2826
+ 1,
2827
+ 0,
2828
+ 0,
2829
+ 0,
2830
+ 0,
2831
+ c,
2832
+ s,
2833
+ 0,
2834
+ 0,
2835
+ -s,
2836
+ c,
2837
+ 0,
2838
+ 0,
2839
+ 0,
2840
+ 0,
2841
+ 1
2842
+ ]);
2984
2843
  }
2985
- toAxisAngle() {
2986
- const sin2 = 1 - this.w * this.w;
2987
- if (sin2 > EPSILON)
2988
- return new Vec3(this.x, this.y, this.z, 0);
2989
- const isin = 1 / Math.sqrt(sin2);
2990
- const angle = 2 * Math.acos(this.w);
2991
- return new Vec3(this.x * isin, this.y * isin, this.z * isin, angle);
2844
+ rotateY(angle) {
2845
+ const c = Math.cos(angle);
2846
+ const s = Math.sin(angle);
2847
+ return this.multiply([
2848
+ c,
2849
+ 0,
2850
+ -s,
2851
+ 0,
2852
+ 0,
2853
+ 1,
2854
+ 0,
2855
+ 0,
2856
+ s,
2857
+ 0,
2858
+ c,
2859
+ 0,
2860
+ 0,
2861
+ 0,
2862
+ 0,
2863
+ 1
2864
+ ]);
2992
2865
  }
2993
- toEuler() {
2994
- function __asin__(t) {
2995
- return t >= 1 ? Math.PI / 2 : t <= -1 ? -Math.PI / 2 : Math.asin(t);
2996
- }
2997
- return new Vec3(
2998
- -Math.atan2(2 * (this.y * this.z - this.w * this.x), 1 - 2 * (this.x * this.x + this.y * this.y)),
2999
- __asin__(2 * (this.x * this.z + this.w * this.y)),
3000
- -Math.atan2(2 * (this.x * this.y - this.w * this.z), 1 - 2 * (this.y * this.y + this.z * this.z))
3001
- );
2866
+ rotateZ(angle) {
2867
+ const c = Math.cos(angle);
2868
+ const s = Math.sin(angle);
2869
+ return this.multiply([
2870
+ c,
2871
+ s,
2872
+ 0,
2873
+ 0,
2874
+ -s,
2875
+ c,
2876
+ 0,
2877
+ 0,
2878
+ 0,
2879
+ 0,
2880
+ 1,
2881
+ 0,
2882
+ 0,
2883
+ 0,
2884
+ 0,
2885
+ 1
2886
+ ]);
3002
2887
  }
3003
- toMat3() {
3004
- return [
3005
- 1 - 2 * (this.y * this.y + this.z * this.z),
3006
- 2 * (this.x * this.y - this.w * this.z),
3007
- 2 * (this.x * this.z + this.w * this.y),
3008
- 2 * (this.x * this.y + this.w * this.z),
3009
- 1 - 2 * (this.x * this.x + this.z * this.z),
3010
- 2 * (this.y * this.z - this.w * this.x),
3011
- 2 * (this.x * this.z - this.w * this.y),
3012
- 2 * (this.y * this.z + this.w * this.x),
3013
- 1 - 2 * (this.x * this.x + this.y * this.y)
3014
- ];
2888
+ rotate(...args) {
2889
+ const vec = Vec3.resolveArgs(args);
2890
+ return this.rotateX(vec.x).rotateY(vec.y).rotateZ(vec.z);
3015
2891
  }
3016
- toMat4() {
3017
- return [
3018
- 1 - 2 * (this.y * this.y + this.z * this.z),
3019
- 2 * (this.x * this.y - this.w * this.z),
3020
- 2 * (this.x * this.z + this.w * this.y),
2892
+ scale(...args) {
2893
+ const vec = Vec3.resolveArgs(args);
2894
+ return this.multiply([
2895
+ vec.x,
2896
+ 0,
2897
+ 0,
2898
+ 0,
2899
+ 0,
2900
+ vec.y,
2901
+ 0,
2902
+ 0,
2903
+ 0,
2904
+ 0,
2905
+ vec.z,
3021
2906
  0,
3022
- 2 * (this.x * this.y + this.w * this.z),
3023
- 1 - 2 * (this.x * this.x + this.z * this.z),
3024
- 2 * (this.y * this.z - this.w * this.x),
3025
2907
  0,
3026
- 2 * (this.x * this.z - this.w * this.y),
3027
- 2 * (this.y * this.z + this.w * this.x),
3028
- 1 - 2 * (this.x * this.x + this.y * this.y),
3029
2908
  0,
3030
2909
  0,
2910
+ 1
2911
+ ]);
2912
+ }
2913
+ inverse() {
2914
+ return new _Mat4([
2915
+ this.m00,
2916
+ this.m10,
2917
+ this.m20,
2918
+ 0,
2919
+ this.m01,
2920
+ this.m11,
2921
+ this.m21,
3031
2922
  0,
2923
+ this.m02,
2924
+ this.m12,
2925
+ this.m22,
3032
2926
  0,
2927
+ -(this.m30 * this.m00 + this.m31 * this.m10 + this.m32 * this.m20),
2928
+ -(this.m30 * this.m01 + this.m31 * this.m11 + this.m32 * this.m21),
2929
+ -(this.m30 * this.m02 + this.m31 * this.m12 + this.m32 * this.m22),
3033
2930
  1
2931
+ ]);
2932
+ }
2933
+ toMat3() {
2934
+ return [
2935
+ this.m00,
2936
+ this.m01,
2937
+ this.m03,
2938
+ this.m10,
2939
+ this.m11,
2940
+ this.m13,
2941
+ this.m30,
2942
+ this.m31,
2943
+ this.m33
3034
2944
  ];
3035
2945
  }
3036
2946
  };
3037
2947
 
2948
+ // source/color.ts
2949
+ import { isValidNumber as isValidNumber12, isFixedTypeArray as isFixedTypeArray12 } from "@ntf/types";
2950
+ var AnyColor;
2951
+ ((AnyColor2) => {
2952
+ function cast(a, preferHSL = false) {
2953
+ const results = [];
2954
+ try {
2955
+ const rgba = RGBA.resolve(a);
2956
+ results.push(rgba);
2957
+ } catch (e) {
2958
+ }
2959
+ try {
2960
+ const hsla = HSLA.resolve(a);
2961
+ results.push(hsla);
2962
+ } catch (e) {
2963
+ }
2964
+ let offset = preferHSL ? 1 : 0;
2965
+ const firstItem = results[offset];
2966
+ if (firstItem)
2967
+ return firstItem;
2968
+ const secondItem = results[offset + 1];
2969
+ if (secondItem)
2970
+ return secondItem;
2971
+ return void 0;
2972
+ }
2973
+ AnyColor2.cast = cast;
2974
+ function resolve(a, preferHSL = false) {
2975
+ const value = cast(a, preferHSL);
2976
+ if (typeof value != "undefined")
2977
+ return value;
2978
+ throw new ResolveError("Color", a);
2979
+ }
2980
+ AnyColor2.resolve = resolve;
2981
+ function resolveArgs(args, preferHSL = false) {
2982
+ if (isFixedTypeArray12(args, isValidNumber12, 3) || isFixedTypeArray12(args, isValidNumber12, 4))
2983
+ return resolve(args, preferHSL);
2984
+ return resolve(args[0], preferHSL);
2985
+ }
2986
+ AnyColor2.resolveArgs = resolveArgs;
2987
+ })(AnyColor || (AnyColor = {}));
2988
+
3038
2989
  // source/transform.ts
2990
+ import { checkValidNumber as checkValidNumber11, NodeJSCustomInspect as NodeJSCustomInspect16 } from "@ntf/types";
3039
2991
  var Transform2D = class {
3040
2992
  constructor(position, rotation, scale, parent) {
3041
2993
  this.parent = parent;
2994
+ checkValidNumber11(rotation);
3042
2995
  this.localPosition = Vec2.resolve(position);
3043
2996
  this.localRotation = rotation;
3044
2997
  this.localScale = Vec2.resolve(scale);
@@ -3089,7 +3042,7 @@ var Transform2D = class {
3089
3042
  get [Symbol.toStringTag]() {
3090
3043
  return "Transform2D";
3091
3044
  }
3092
- [NodeJSCustomInspect]() {
3045
+ [NodeJSCustomInspect16]() {
3093
3046
  return `Transform2D <${this.toString()}>`;
3094
3047
  }
3095
3048
  toMat3() {
@@ -3164,7 +3117,7 @@ var Transform3D = class {
3164
3117
  get [Symbol.toStringTag]() {
3165
3118
  return "Transform2D";
3166
3119
  }
3167
- [NodeJSCustomInspect]() {
3120
+ [NodeJSCustomInspect16]() {
3168
3121
  return `Transform2D <${this.toString()}>`;
3169
3122
  }
3170
3123
  /**
@@ -3199,7 +3152,6 @@ export {
3199
3152
  Mat3,
3200
3153
  Mat4,
3201
3154
  MathFunction,
3202
- NodeJSCustomInspect,
3203
3155
  QuadFunction,
3204
3156
  Quaternion,
3205
3157
  RGBA,
@@ -3213,22 +3165,16 @@ export {
3213
3165
  Triangle3D,
3214
3166
  Vec2,
3215
3167
  Vec3,
3216
- checkArray,
3217
- checkHex,
3218
- checkNumber,
3219
- checkNumberArray,
3220
- checkString,
3221
- checkStringArray,
3222
3168
  clamp,
3223
3169
  clampAngleDegree,
3224
3170
  clampAngleRadian,
3225
3171
  degreeToRadian,
3226
3172
  djb2,
3227
3173
  fnv1,
3228
- getHexValue,
3229
- hasProperty,
3230
3174
  lerp,
3231
3175
  logHypot,
3176
+ numberToRGB,
3177
+ numberToRGBA,
3232
3178
  radianToDegree,
3233
3179
  sdbm,
3234
3180
  signCharacter