@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.d.mts +136 -227
- package/dist/index.d.ts +136 -227
- package/dist/index.js +2072 -2126
- package/dist/index.mjs +2078 -2132
- package/package.json +4 -1
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 (
|
|
108
|
-
return new this(a[0], a[1],
|
|
109
|
-
if (
|
|
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 (
|
|
112
|
-
return new this(a.x, a.y,
|
|
113
|
-
if (
|
|
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 (
|
|
81
|
+
if (isValidString(sxy)) {
|
|
116
82
|
const parts = sxy.split(",");
|
|
117
|
-
if (
|
|
118
|
-
return new this(parseFloat(parts[0]), parseFloat(parts[1]),
|
|
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 (
|
|
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 (
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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 (
|
|
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
|
-
|
|
346
|
-
|
|
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
|
-
|
|
354
|
-
|
|
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
|
-
[
|
|
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
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
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
|
-
|
|
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
|
-
[
|
|
389
|
+
[NodeJSCustomInspect3]() {
|
|
433
390
|
return `QuadFunction <${this.toString()}>`;
|
|
434
391
|
}
|
|
435
392
|
};
|
|
436
393
|
|
|
437
|
-
// source/
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
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
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
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
|
-
|
|
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
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
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
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
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
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
this.
|
|
773
|
-
|
|
774
|
-
|
|
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
|
-
|
|
777
|
-
return
|
|
460
|
+
static get zero() {
|
|
461
|
+
return new this(0, 0, 0);
|
|
778
462
|
}
|
|
779
|
-
get
|
|
780
|
-
return
|
|
463
|
+
static get one() {
|
|
464
|
+
return new this(1, 1, 1);
|
|
781
465
|
}
|
|
782
|
-
|
|
783
|
-
|
|
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
|
-
|
|
801
|
-
return
|
|
479
|
+
toJSON() {
|
|
480
|
+
return {
|
|
481
|
+
x: this.x,
|
|
482
|
+
y: this.y,
|
|
483
|
+
z: this.z,
|
|
484
|
+
w: this.w
|
|
485
|
+
};
|
|
802
486
|
}
|
|
803
|
-
|
|
804
|
-
|
|
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
|
-
|
|
808
|
-
|
|
490
|
+
get [Symbol.toStringTag]() {
|
|
491
|
+
return "Vec3";
|
|
809
492
|
}
|
|
810
|
-
|
|
811
|
-
return this.
|
|
493
|
+
[NodeJSCustomInspect4]() {
|
|
494
|
+
return `Vec3 <${this.toString()}>`;
|
|
812
495
|
}
|
|
813
|
-
|
|
814
|
-
this.
|
|
496
|
+
toVec2() {
|
|
497
|
+
return [this.x, this.y, this.w];
|
|
815
498
|
}
|
|
816
|
-
|
|
817
|
-
|
|
499
|
+
toRGB() {
|
|
500
|
+
const vec = this.normalize();
|
|
501
|
+
return [vec.x, vec.y, vec.z];
|
|
818
502
|
}
|
|
819
|
-
|
|
820
|
-
|
|
503
|
+
toRGBA() {
|
|
504
|
+
const vec = this.normalize();
|
|
505
|
+
return [vec.x, vec.y, vec.z, vec.w];
|
|
821
506
|
}
|
|
822
|
-
|
|
823
|
-
const
|
|
824
|
-
|
|
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
|
-
|
|
829
|
-
|
|
830
|
-
|
|
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
|
-
|
|
836
|
-
|
|
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
|
-
|
|
861
|
-
return
|
|
518
|
+
clone() {
|
|
519
|
+
return new _Vec3(this.x, this.y, this.z, this.w);
|
|
862
520
|
}
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
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
|
-
|
|
870
|
-
|
|
525
|
+
setX(x) {
|
|
526
|
+
this.x = x;
|
|
527
|
+
return this;
|
|
871
528
|
}
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
radius: this.radius
|
|
876
|
-
};
|
|
529
|
+
setY(y) {
|
|
530
|
+
this.y = y;
|
|
531
|
+
return this;
|
|
877
532
|
}
|
|
878
|
-
|
|
879
|
-
|
|
533
|
+
setZ(z) {
|
|
534
|
+
this.z = z;
|
|
535
|
+
return this;
|
|
880
536
|
}
|
|
881
|
-
|
|
882
|
-
|
|
537
|
+
set(...args) {
|
|
538
|
+
const vec = _Vec3.resolveArgs(args);
|
|
539
|
+
return this.setX(vec.x).setY(vec.y).setZ(vec.z);
|
|
883
540
|
}
|
|
884
|
-
|
|
885
|
-
|
|
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
|
-
|
|
888
|
-
|
|
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
|
-
|
|
891
|
-
|
|
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
|
-
|
|
894
|
-
|
|
895
|
-
|
|
564
|
+
multiply(scalar) {
|
|
565
|
+
return new _Vec3(
|
|
566
|
+
this.x * scalar,
|
|
567
|
+
this.y * scalar,
|
|
568
|
+
this.z * scalar
|
|
569
|
+
);
|
|
896
570
|
}
|
|
897
|
-
|
|
898
|
-
const
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
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
|
-
|
|
905
|
-
|
|
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
|
-
|
|
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
|
-
|
|
919
|
-
|
|
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
|
-
|
|
922
|
-
|
|
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
|
-
|
|
925
|
-
|
|
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
|
-
|
|
928
|
-
return this.
|
|
613
|
+
length() {
|
|
614
|
+
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
|
929
615
|
}
|
|
930
|
-
|
|
931
|
-
|
|
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
|
-
|
|
934
|
-
return this.
|
|
626
|
+
invert() {
|
|
627
|
+
return this.multiply(-1);
|
|
935
628
|
}
|
|
936
|
-
|
|
937
|
-
this.
|
|
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("
|
|
647
|
+
throw new ResolveError("Quaternion", a);
|
|
945
648
|
}
|
|
946
649
|
static resolveArgs(args) {
|
|
947
|
-
if (
|
|
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 (
|
|
657
|
+
if (isFixedTypeArray3(a, isValidNumber3, 4))
|
|
955
658
|
return new this(a[0], a[1], a[2], a[3]);
|
|
956
|
-
if (
|
|
957
|
-
return this.cast(a.
|
|
958
|
-
if (
|
|
959
|
-
return new this(a.
|
|
960
|
-
if (
|
|
961
|
-
const parts = a.
|
|
962
|
-
if (
|
|
963
|
-
|
|
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
|
|
968
|
-
|
|
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
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
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.
|
|
714
|
+
return [this.w, this.x, this.y, this.z];
|
|
986
715
|
}
|
|
987
716
|
toString() {
|
|
988
|
-
return `${this.
|
|
717
|
+
return `${this.w} + ${this.x}i + ${this.y}j + ${this.z}k`;
|
|
989
718
|
}
|
|
990
719
|
get [Symbol.toStringTag]() {
|
|
991
|
-
return "
|
|
720
|
+
return "Quaternion";
|
|
992
721
|
}
|
|
993
|
-
[
|
|
994
|
-
return `
|
|
722
|
+
[NodeJSCustomInspect5]() {
|
|
723
|
+
return `Quaternion <${this.toString()}>`;
|
|
995
724
|
}
|
|
996
725
|
toJSON() {
|
|
997
726
|
return {
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
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
|
|
734
|
+
return new _Quaternion(this.w, this.x, this.y, this.z);
|
|
1006
735
|
}
|
|
1007
|
-
|
|
1008
|
-
const
|
|
1009
|
-
return
|
|
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
|
-
|
|
1012
|
-
|
|
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
|
-
|
|
1015
|
-
|
|
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
|
-
|
|
1018
|
-
return
|
|
762
|
+
negative() {
|
|
763
|
+
return new _Quaternion(-this.w, -this.x, -this.y, -this.z);
|
|
1019
764
|
}
|
|
1020
|
-
|
|
1021
|
-
const
|
|
1022
|
-
return
|
|
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
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
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
|
-
|
|
1029
|
-
const
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
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/
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
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
|
-
|
|
1049
|
-
|
|
930
|
+
set red(val) {
|
|
931
|
+
this._red = clamp(val, 0, 1);
|
|
1050
932
|
}
|
|
1051
|
-
|
|
1052
|
-
|
|
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("
|
|
958
|
+
throw new ResolveError("RGBAColor", a);
|
|
1059
959
|
}
|
|
1060
960
|
static resolveArgs(args) {
|
|
1061
|
-
if (
|
|
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 (
|
|
1069
|
-
return new this(a[0], a[1]);
|
|
1070
|
-
if (
|
|
1071
|
-
return this.cast(a.
|
|
1072
|
-
if (
|
|
1073
|
-
return
|
|
1074
|
-
if (
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
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(
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
this.
|
|
1092
|
-
this.
|
|
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.
|
|
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
|
-
|
|
1098
|
-
return
|
|
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 "
|
|
1024
|
+
return "RGBA";
|
|
1102
1025
|
}
|
|
1103
|
-
[
|
|
1104
|
-
return `
|
|
1026
|
+
[NodeJSCustomInspect6]() {
|
|
1027
|
+
return `RGBA <${this.toString()}>`;
|
|
1105
1028
|
}
|
|
1106
|
-
|
|
1107
|
-
return
|
|
1108
|
-
width: this.width,
|
|
1109
|
-
height: this.height
|
|
1110
|
-
};
|
|
1029
|
+
toVec2() {
|
|
1030
|
+
return [this.red, this.green, this.blue];
|
|
1111
1031
|
}
|
|
1112
|
-
|
|
1113
|
-
return
|
|
1032
|
+
toVec3() {
|
|
1033
|
+
return [this.red, this.green, this.blue, this.alpha];
|
|
1114
1034
|
}
|
|
1115
|
-
|
|
1116
|
-
const
|
|
1117
|
-
|
|
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
|
-
|
|
1120
|
-
return
|
|
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/
|
|
1125
|
-
var
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
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
|
|
1144
|
-
this.
|
|
1070
|
+
set hue(val) {
|
|
1071
|
+
this._hue = clamp(val, 0, 1);
|
|
1145
1072
|
}
|
|
1146
|
-
|
|
1147
|
-
|
|
1073
|
+
_saturation;
|
|
1074
|
+
get saturation() {
|
|
1075
|
+
return this._saturation;
|
|
1148
1076
|
}
|
|
1149
|
-
set
|
|
1150
|
-
this.
|
|
1077
|
+
set saturation(val) {
|
|
1078
|
+
this._saturation = clamp(val, 0, 1);
|
|
1151
1079
|
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1080
|
+
_luminace;
|
|
1081
|
+
get luminace() {
|
|
1082
|
+
return this._luminace;
|
|
1154
1083
|
}
|
|
1155
|
-
set
|
|
1156
|
-
this.
|
|
1084
|
+
set luminace(val) {
|
|
1085
|
+
this._luminace = clamp(val, 0, 1);
|
|
1157
1086
|
}
|
|
1158
|
-
|
|
1159
|
-
|
|
1087
|
+
_alpha;
|
|
1088
|
+
get alpha() {
|
|
1089
|
+
return this._alpha;
|
|
1160
1090
|
}
|
|
1161
|
-
set
|
|
1162
|
-
this.
|
|
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("
|
|
1098
|
+
throw new ResolveError("HSLColor", a);
|
|
1169
1099
|
}
|
|
1170
1100
|
static resolveArgs(args) {
|
|
1171
|
-
if (
|
|
1172
|
-
return new this(
|
|
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 (
|
|
1179
|
-
return new this(
|
|
1180
|
-
if (
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
return
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
const
|
|
1188
|
-
const
|
|
1189
|
-
|
|
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 (
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
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(
|
|
1209
|
-
|
|
1210
|
-
|
|
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(
|
|
1213
|
-
return [
|
|
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
|
-
|
|
1216
|
-
return
|
|
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 "
|
|
1164
|
+
return "HSLA";
|
|
1220
1165
|
}
|
|
1221
|
-
[
|
|
1222
|
-
return `
|
|
1166
|
+
[NodeJSCustomInspect7]() {
|
|
1167
|
+
return `HSLA <${this.toString()}>`;
|
|
1223
1168
|
}
|
|
1224
|
-
|
|
1225
|
-
|
|
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
|
-
|
|
1228
|
-
return
|
|
1190
|
+
toRGBA() {
|
|
1191
|
+
return this.toRGB(true);
|
|
1229
1192
|
}
|
|
1230
1193
|
toVec2() {
|
|
1231
|
-
return [this.
|
|
1232
|
-
}
|
|
1233
|
-
toSize() {
|
|
1234
|
-
return [this.width, this.height];
|
|
1194
|
+
return [this.hue, this.saturation, this.luminace];
|
|
1235
1195
|
}
|
|
1236
|
-
|
|
1237
|
-
return
|
|
1196
|
+
toVec3() {
|
|
1197
|
+
return [this.hue, this.saturation, this.luminace, this.alpha];
|
|
1238
1198
|
}
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
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/
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
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
|
-
|
|
1287
|
-
|
|
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
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
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
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
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
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
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
|
-
|
|
1313
|
-
|
|
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
|
-
|
|
1316
|
-
|
|
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
|
-
|
|
1319
|
-
|
|
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
|
-
|
|
1333
|
-
return
|
|
1552
|
+
get [Symbol.toStringTag]() {
|
|
1553
|
+
return "MD2";
|
|
1334
1554
|
}
|
|
1335
|
-
|
|
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
|
-
|
|
1344
|
-
|
|
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
|
|
1347
|
-
return
|
|
1577
|
+
get area() {
|
|
1578
|
+
return Math.PI * Math.pow(this.radius, 2);
|
|
1348
1579
|
}
|
|
1349
|
-
|
|
1350
|
-
|
|
1580
|
+
position;
|
|
1581
|
+
get x() {
|
|
1582
|
+
return this.position.x;
|
|
1351
1583
|
}
|
|
1352
|
-
|
|
1353
|
-
|
|
1584
|
+
set x(val) {
|
|
1585
|
+
this.position.x = val;
|
|
1354
1586
|
}
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
return [vec.x, vec.y, vec.z];
|
|
1587
|
+
get y() {
|
|
1588
|
+
return this.position.y;
|
|
1358
1589
|
}
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
return [vec.x, vec.y, vec.z, vec.w];
|
|
1590
|
+
set y(val) {
|
|
1591
|
+
this.position.y = val;
|
|
1362
1592
|
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
return [vec.x, vec.y, vec.z];
|
|
1593
|
+
get w() {
|
|
1594
|
+
return this.position.w;
|
|
1366
1595
|
}
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
return [vec.x, vec.y, vec.z, vec.w];
|
|
1596
|
+
set w(val) {
|
|
1597
|
+
this.position.w = val;
|
|
1370
1598
|
}
|
|
1371
|
-
|
|
1372
|
-
|
|
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
|
|
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
|
|
1379
|
-
return
|
|
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
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
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
|
-
|
|
1386
|
-
this.
|
|
1387
|
-
return this;
|
|
1694
|
+
set width(val) {
|
|
1695
|
+
this.right = this.left + val;
|
|
1388
1696
|
}
|
|
1389
|
-
|
|
1390
|
-
this.
|
|
1391
|
-
return this;
|
|
1697
|
+
get height() {
|
|
1698
|
+
return this.bottom - this.top;
|
|
1392
1699
|
}
|
|
1393
|
-
set(
|
|
1394
|
-
|
|
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
|
-
|
|
1398
|
-
|
|
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
|
-
|
|
1406
|
-
|
|
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
|
-
|
|
1413
|
-
|
|
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
|
-
|
|
1421
|
-
|
|
1422
|
-
this.x * scalar,
|
|
1423
|
-
this.y * scalar,
|
|
1424
|
-
this.z * scalar
|
|
1425
|
-
);
|
|
1712
|
+
set y(y) {
|
|
1713
|
+
this.top = y;
|
|
1426
1714
|
}
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
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
|
-
|
|
1436
|
-
if (
|
|
1437
|
-
return new
|
|
1438
|
-
|
|
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
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
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
|
-
|
|
1454
|
-
|
|
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
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
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
|
-
|
|
1466
|
-
|
|
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
|
-
|
|
1470
|
-
return
|
|
1759
|
+
toString() {
|
|
1760
|
+
return `${this.left},${this.right},${this.top},${this.bottom}`;
|
|
1471
1761
|
}
|
|
1472
|
-
|
|
1473
|
-
|
|
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
|
-
|
|
1483
|
-
return this.
|
|
1765
|
+
[NodeJSCustomInspect10]() {
|
|
1766
|
+
return `BoundingBox <${this.toString()}>`;
|
|
1484
1767
|
}
|
|
1485
|
-
|
|
1486
|
-
return
|
|
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
|
-
|
|
1498
|
-
|
|
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
|
-
|
|
1501
|
-
return
|
|
1783
|
+
toSize() {
|
|
1784
|
+
return [this.width, this.height];
|
|
1502
1785
|
}
|
|
1503
|
-
|
|
1504
|
-
return
|
|
1786
|
+
toVec2() {
|
|
1787
|
+
return [this.left, this.top];
|
|
1505
1788
|
}
|
|
1506
|
-
|
|
1507
|
-
return this.
|
|
1789
|
+
toRectangle() {
|
|
1790
|
+
return [this.left, this.top, this.width, this.height];
|
|
1508
1791
|
}
|
|
1509
|
-
|
|
1510
|
-
|
|
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
|
-
|
|
1513
|
-
|
|
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
|
-
|
|
1516
|
-
|
|
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
|
-
|
|
1519
|
-
|
|
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
|
-
|
|
1522
|
-
return
|
|
1824
|
+
get area() {
|
|
1825
|
+
return this.width * this.height;
|
|
1523
1826
|
}
|
|
1524
|
-
get
|
|
1525
|
-
return
|
|
1827
|
+
get perimeter() {
|
|
1828
|
+
return this.width + this.width + this.height + this.height;
|
|
1526
1829
|
}
|
|
1527
|
-
|
|
1528
|
-
|
|
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
|
-
|
|
1532
|
-
|
|
1533
|
-
return
|
|
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
|
-
|
|
1536
|
-
|
|
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
|
-
|
|
1539
|
-
return
|
|
1859
|
+
static is(a) {
|
|
1860
|
+
return typeof this.cast(a) != "undefined";
|
|
1540
1861
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1862
|
+
constructor(width, height) {
|
|
1863
|
+
checkValidNumber10(width);
|
|
1864
|
+
checkValidNumber10(height);
|
|
1865
|
+
this.width = width;
|
|
1866
|
+
this.height = height;
|
|
1545
1867
|
}
|
|
1546
|
-
|
|
1547
|
-
return
|
|
1868
|
+
toArray() {
|
|
1869
|
+
return [this.width, this.height];
|
|
1548
1870
|
}
|
|
1549
|
-
|
|
1550
|
-
return
|
|
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
|
-
|
|
1561
|
-
this.
|
|
1877
|
+
[NodeJSCustomInspect11]() {
|
|
1878
|
+
return `Size <${this.toString()}>`;
|
|
1562
1879
|
}
|
|
1563
|
-
|
|
1564
|
-
return
|
|
1880
|
+
toJSON() {
|
|
1881
|
+
return {
|
|
1882
|
+
width: this.width,
|
|
1883
|
+
height: this.height
|
|
1884
|
+
};
|
|
1565
1885
|
}
|
|
1566
|
-
|
|
1567
|
-
this.
|
|
1886
|
+
clone() {
|
|
1887
|
+
return new _Size(this.width, this.height);
|
|
1568
1888
|
}
|
|
1569
|
-
|
|
1570
|
-
|
|
1889
|
+
equals(...args) {
|
|
1890
|
+
const s = _Size.resolveArgs(args);
|
|
1891
|
+
return this.width == s.width && this.height == s.height;
|
|
1571
1892
|
}
|
|
1572
|
-
|
|
1573
|
-
this.
|
|
1893
|
+
toVec2() {
|
|
1894
|
+
return [this.width, this.height];
|
|
1574
1895
|
}
|
|
1575
|
-
|
|
1576
|
-
|
|
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
|
-
|
|
1579
|
-
this.
|
|
1905
|
+
get perimeter() {
|
|
1906
|
+
return this.width + this.width + this.height + this.height;
|
|
1580
1907
|
}
|
|
1581
|
-
get
|
|
1582
|
-
return this.
|
|
1908
|
+
get x() {
|
|
1909
|
+
return this.position.x;
|
|
1583
1910
|
}
|
|
1584
|
-
set
|
|
1585
|
-
this.
|
|
1911
|
+
set x(val) {
|
|
1912
|
+
this.position.x = val;
|
|
1586
1913
|
}
|
|
1587
|
-
get
|
|
1588
|
-
return this.
|
|
1914
|
+
get y() {
|
|
1915
|
+
return this.position.y;
|
|
1589
1916
|
}
|
|
1590
|
-
set
|
|
1591
|
-
this.
|
|
1917
|
+
set y(val) {
|
|
1918
|
+
this.position.y = val;
|
|
1592
1919
|
}
|
|
1593
|
-
get
|
|
1594
|
-
return this.
|
|
1920
|
+
get w() {
|
|
1921
|
+
return this.position.w;
|
|
1595
1922
|
}
|
|
1596
|
-
set
|
|
1597
|
-
this.
|
|
1923
|
+
set w(val) {
|
|
1924
|
+
this.position.w = val;
|
|
1598
1925
|
}
|
|
1599
|
-
get
|
|
1600
|
-
return this.
|
|
1926
|
+
get width() {
|
|
1927
|
+
return this.size.width;
|
|
1601
1928
|
}
|
|
1602
|
-
set
|
|
1603
|
-
this.
|
|
1929
|
+
set width(val) {
|
|
1930
|
+
this.size.width = val;
|
|
1604
1931
|
}
|
|
1605
|
-
get
|
|
1606
|
-
return this.
|
|
1932
|
+
get height() {
|
|
1933
|
+
return this.size.height;
|
|
1607
1934
|
}
|
|
1608
|
-
set
|
|
1609
|
-
this.
|
|
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("
|
|
1942
|
+
throw new ResolveError("Rectangle", a);
|
|
1616
1943
|
}
|
|
1617
1944
|
static resolveArgs(args) {
|
|
1618
|
-
if (
|
|
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 (
|
|
1626
|
-
return new this(a);
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
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 (
|
|
1644
|
-
const
|
|
1645
|
-
|
|
1646
|
-
|
|
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 (
|
|
1649
|
-
return this.cast(a.
|
|
1650
|
-
if (
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
a.
|
|
1654
|
-
|
|
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
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
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
|
-
|
|
1684
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1702
|
-
return
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
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
|
-
|
|
1722
|
-
return
|
|
2001
|
+
toBoundingBox() {
|
|
2002
|
+
return [this.x, this.x + this.width, this.y, this.y + this.height];
|
|
1723
2003
|
}
|
|
1724
|
-
|
|
1725
|
-
return
|
|
2004
|
+
toVec2() {
|
|
2005
|
+
return [this.x, this.y, this.w];
|
|
1726
2006
|
}
|
|
1727
|
-
|
|
1728
|
-
return
|
|
2007
|
+
toSize() {
|
|
2008
|
+
return [this.width, this.height];
|
|
1729
2009
|
}
|
|
1730
2010
|
clone() {
|
|
1731
|
-
return new
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
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
|
-
|
|
1744
|
-
|
|
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
|
-
|
|
1751
|
-
|
|
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
|
-
|
|
1758
|
-
|
|
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
|
-
|
|
1765
|
-
|
|
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
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
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
|
-
|
|
1805
|
-
|
|
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
|
-
|
|
1820
|
-
|
|
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
|
-
|
|
1834
|
-
|
|
2071
|
+
};
|
|
2072
|
+
var Triangle3D = class extends Triangle {
|
|
2073
|
+
get a() {
|
|
2074
|
+
return Vec3.fromPoints(this.B, this.C).length();
|
|
1835
2075
|
}
|
|
1836
|
-
|
|
1837
|
-
|
|
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
|
-
|
|
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/
|
|
1873
|
-
|
|
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[
|
|
2107
|
+
return this._raw[3];
|
|
1901
2108
|
}
|
|
1902
2109
|
set m10(val) {
|
|
1903
|
-
this._raw[
|
|
2110
|
+
this._raw[3] = val;
|
|
1904
2111
|
}
|
|
1905
2112
|
get m11() {
|
|
1906
|
-
return this._raw[
|
|
2113
|
+
return this._raw[4];
|
|
1907
2114
|
}
|
|
1908
2115
|
set m11(val) {
|
|
1909
|
-
this._raw[
|
|
2116
|
+
this._raw[4] = val;
|
|
1910
2117
|
}
|
|
1911
2118
|
get m12() {
|
|
1912
|
-
return this._raw[
|
|
2119
|
+
return this._raw[5];
|
|
1913
2120
|
}
|
|
1914
2121
|
set m12(val) {
|
|
1915
|
-
this._raw[
|
|
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[
|
|
2125
|
+
return this._raw[6];
|
|
1925
2126
|
}
|
|
1926
2127
|
set m20(val) {
|
|
1927
|
-
this._raw[
|
|
2128
|
+
this._raw[6] = val;
|
|
1928
2129
|
}
|
|
1929
2130
|
get m21() {
|
|
1930
|
-
return this._raw[
|
|
2131
|
+
return this._raw[7];
|
|
1931
2132
|
}
|
|
1932
2133
|
set m21(val) {
|
|
1933
|
-
this._raw[
|
|
2134
|
+
this._raw[7] = val;
|
|
1934
2135
|
}
|
|
1935
2136
|
get m22() {
|
|
1936
|
-
return this._raw[
|
|
2137
|
+
return this._raw[8];
|
|
1937
2138
|
}
|
|
1938
2139
|
set m22(val) {
|
|
1939
|
-
this._raw[
|
|
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("
|
|
2146
|
+
throw new ResolveError("Mat3", a);
|
|
1976
2147
|
}
|
|
1977
2148
|
static resolveArgs(args) {
|
|
1978
|
-
if (
|
|
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 (
|
|
2156
|
+
if (isFixedTypeArray10(a, isValidNumber10, 9)) {
|
|
1986
2157
|
return new this(a);
|
|
1987
2158
|
}
|
|
1988
|
-
if (
|
|
1989
|
-
const row0 = a[0], row1 = a[1], row2 = a[2]
|
|
1990
|
-
if (
|
|
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 (
|
|
2174
|
+
if (isValidString10(a)) {
|
|
2011
2175
|
const parts = a.split(",");
|
|
2012
|
-
if (
|
|
2176
|
+
if (isFixedTypeArray10(parts, isValidString10, 9))
|
|
2013
2177
|
return this.cast(parts.map((i) => parseFloat(i)));
|
|
2014
2178
|
}
|
|
2015
|
-
if (
|
|
2016
|
-
return this.cast(a.
|
|
2017
|
-
if (
|
|
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 (
|
|
2037
|
-
return new this([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
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
2115
|
-
|
|
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
|
|
2142
|
-
[this.m10, this.m11, this.m12
|
|
2143
|
-
[this.m20, this.m21, this.m22
|
|
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.
|
|
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 "
|
|
2255
|
+
return "Mat3";
|
|
2172
2256
|
}
|
|
2173
|
-
[
|
|
2174
|
-
return `
|
|
2257
|
+
[NodeJSCustomInspect14]() {
|
|
2258
|
+
return `Mat3 <${this.toString()}>`;
|
|
2175
2259
|
}
|
|
2176
2260
|
clone() {
|
|
2177
|
-
return new
|
|
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 =
|
|
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 =
|
|
2205
|
-
const m = new
|
|
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 =
|
|
2212
|
-
const m = new
|
|
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 (
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
this.
|
|
2222
|
-
this.
|
|
2223
|
-
this.
|
|
2224
|
-
this.
|
|
2225
|
-
this.
|
|
2226
|
-
this.
|
|
2227
|
-
this.
|
|
2228
|
-
this.
|
|
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
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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.
|
|
2384
|
+
this.m02,
|
|
2385
|
+
0,
|
|
2408
2386
|
this.m10,
|
|
2409
2387
|
this.m11,
|
|
2410
|
-
this.
|
|
2411
|
-
|
|
2412
|
-
this.
|
|
2413
|
-
this.
|
|
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/
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
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
|
|
2584
|
-
this.
|
|
2409
|
+
set m00(val) {
|
|
2410
|
+
this._raw[0] = val;
|
|
2585
2411
|
}
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
return this._saturation;
|
|
2412
|
+
get m01() {
|
|
2413
|
+
return this._raw[1];
|
|
2589
2414
|
}
|
|
2590
|
-
set
|
|
2591
|
-
this.
|
|
2415
|
+
set m01(val) {
|
|
2416
|
+
this._raw[1] = val;
|
|
2592
2417
|
}
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
return this._luminace;
|
|
2418
|
+
get m02() {
|
|
2419
|
+
return this._raw[2];
|
|
2596
2420
|
}
|
|
2597
|
-
set
|
|
2598
|
-
this.
|
|
2421
|
+
set m02(val) {
|
|
2422
|
+
this._raw[2] = val;
|
|
2599
2423
|
}
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
return this._alpha;
|
|
2424
|
+
get m03() {
|
|
2425
|
+
return this._raw[3];
|
|
2603
2426
|
}
|
|
2604
|
-
set
|
|
2605
|
-
this.
|
|
2427
|
+
set m03(val) {
|
|
2428
|
+
this._raw[3] = val;
|
|
2606
2429
|
}
|
|
2607
|
-
|
|
2608
|
-
|
|
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
|
-
|
|
2614
|
-
|
|
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
|
-
|
|
2619
|
-
|
|
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
|
-
|
|
2647
|
-
|
|
2439
|
+
set m11(val) {
|
|
2440
|
+
this._raw[5] = val;
|
|
2648
2441
|
}
|
|
2649
|
-
|
|
2650
|
-
|
|
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
|
-
|
|
2664
|
-
|
|
2445
|
+
set m12(val) {
|
|
2446
|
+
this._raw[6] = val;
|
|
2665
2447
|
}
|
|
2666
|
-
|
|
2667
|
-
return
|
|
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
|
-
|
|
2679
|
-
|
|
2451
|
+
set m13(val) {
|
|
2452
|
+
this._raw[7] = val;
|
|
2680
2453
|
}
|
|
2681
|
-
get
|
|
2682
|
-
return
|
|
2454
|
+
get m20() {
|
|
2455
|
+
return this._raw[8];
|
|
2683
2456
|
}
|
|
2684
|
-
|
|
2685
|
-
|
|
2457
|
+
set m20(val) {
|
|
2458
|
+
this._raw[8] = val;
|
|
2686
2459
|
}
|
|
2687
|
-
|
|
2688
|
-
|
|
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
|
-
|
|
2709
|
-
|
|
2463
|
+
set m21(val) {
|
|
2464
|
+
this._raw[9] = val;
|
|
2710
2465
|
}
|
|
2711
|
-
|
|
2712
|
-
return
|
|
2466
|
+
get m22() {
|
|
2467
|
+
return this._raw[10];
|
|
2713
2468
|
}
|
|
2714
|
-
|
|
2715
|
-
|
|
2469
|
+
set m22(val) {
|
|
2470
|
+
this._raw[10] = val;
|
|
2716
2471
|
}
|
|
2717
|
-
|
|
2718
|
-
return
|
|
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
|
-
|
|
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
|
-
|
|
2750
|
-
|
|
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
|
-
|
|
2757
|
-
|
|
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
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
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("
|
|
2506
|
+
throw new ResolveError("Mat4", a);
|
|
2779
2507
|
}
|
|
2780
2508
|
static resolveArgs(args) {
|
|
2781
|
-
if (
|
|
2782
|
-
return new this(args
|
|
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 (
|
|
2789
|
-
return new this(a
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
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
|
|
2810
|
-
|
|
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
|
|
2820
|
-
const
|
|
2821
|
-
const
|
|
2822
|
-
const
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
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
|
|
2832
|
-
|
|
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(
|
|
2835
|
-
|
|
2836
|
-
|
|
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 [
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
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
|
-
|
|
2858
|
-
return
|
|
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
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
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
|
-
|
|
2869
|
-
return
|
|
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
|
-
|
|
2872
|
-
|
|
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
|
-
|
|
2881
|
-
|
|
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
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
this.
|
|
2892
|
-
this.
|
|
2893
|
-
this.
|
|
2894
|
-
this.
|
|
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
|
-
|
|
2898
|
-
|
|
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
|
-
|
|
2901
|
-
const
|
|
2902
|
-
|
|
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
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
return
|
|
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
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
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
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
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
|
-
|
|
2983
|
-
|
|
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
|
-
|
|
2986
|
-
const
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
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
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
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
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
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
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
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
|
-
[
|
|
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
|
-
[
|
|
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
|