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