@ntf/math 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,3204 +1 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // source/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- AnyColor: () => AnyColor,
24
- BoundingBox: () => BoundingBox,
25
- Circle: () => Circle,
26
- DJB2_OFFSET: () => DJB2_OFFSET,
27
- EPSILON: () => EPSILON,
28
- FNV1_OFFSET: () => FNV1_OFFSET,
29
- FNV1_PRIME: () => FNV1_PRIME,
30
- HSLA: () => HSLA,
31
- LinearFunction: () => LinearFunction,
32
- MAX_ANGLE_DEGREE: () => MAX_ANGLE_DEGREE,
33
- MD2: () => MD2,
34
- Mat3: () => Mat3,
35
- Mat4: () => Mat4,
36
- MathFunction: () => MathFunction,
37
- QuadFunction: () => QuadFunction,
38
- Quaternion: () => Quaternion,
39
- RGBA: () => RGBA,
40
- Rectangle: () => Rectangle,
41
- ResolveError: () => ResolveError,
42
- Size: () => Size,
43
- Transform2D: () => Transform2D,
44
- Transform3D: () => Transform3D,
45
- Triangle: () => Triangle,
46
- Triangle2D: () => Triangle2D,
47
- Triangle3D: () => Triangle3D,
48
- Vec2: () => Vec2,
49
- Vec3: () => Vec3,
50
- clamp: () => clamp,
51
- clampAngleDegree: () => clampAngleDegree,
52
- clampAngleRadian: () => clampAngleRadian,
53
- degreeToRadian: () => degreeToRadian,
54
- djb2: () => djb2,
55
- fnv1: () => fnv1,
56
- lerp: () => lerp,
57
- logHypot: () => logHypot,
58
- numberToRGB: () => numberToRGB,
59
- numberToRGBA: () => numberToRGBA,
60
- radianToDegree: () => radianToDegree,
61
- sdbm: () => sdbm,
62
- signCharacter: () => signCharacter
63
- });
64
- module.exports = __toCommonJS(index_exports);
65
-
66
- // source/algebra/function.ts
67
- var MathFunction = class {
68
- };
69
-
70
- // source/algebra/linear.ts
71
- var import_types2 = require("@ntf/types");
72
-
73
- // source/common/sign.ts
74
- function signCharacter(num) {
75
- if (num == 0)
76
- return void 0;
77
- if (num < 0)
78
- return "-";
79
- if (num > 0)
80
- return "+";
81
- return void 0;
82
- }
83
-
84
- // source/common/error.ts
85
- var ResolveError = class extends Error {
86
- /**
87
- * Create a resolve exception
88
- * @param target The target type name
89
- * @param value A value
90
- */
91
- constructor(target, value) {
92
- super(`Can't resolve ${value} to ${target}`);
93
- this.target = target;
94
- this.value = value;
95
- }
96
- };
97
-
98
- // source/vectors/vec2.ts
99
- var import_types = require("@ntf/types");
100
-
101
- // source/utils.ts
102
- function clamp(value, min, max) {
103
- if (value <= min)
104
- return min;
105
- if (value >= max)
106
- return max;
107
- return value;
108
- }
109
- function logHypot(a, b) {
110
- const a_abs = Math.abs(a);
111
- const b_abs = Math.abs(b);
112
- if (a == 0)
113
- return Math.log(b_abs);
114
- if (b == 0)
115
- return Math.log(a_abs);
116
- if (a_abs < 3e3 && b_abs < 3e3)
117
- return 0.5 * Math.log(a * a + b * b);
118
- const _a = a / 2, _b = b / 2;
119
- return 0.5 * Math.log(_a * _a + _b * _b) + Math.LN2;
120
- }
121
- var EPSILON = 1e-16;
122
- var lerp = (a, b, t) => ((typeof a == "number" ? 1 : 1n) - t) * a + t * b;
123
-
124
- // source/vectors/vec2.ts
125
- var Vec2 = class _Vec2 {
126
- x;
127
- y;
128
- w;
129
- static resolve(a) {
130
- const value = this.cast(a);
131
- if (typeof value != "undefined")
132
- return value;
133
- throw new ResolveError("Vec2", a);
134
- }
135
- static cast(a) {
136
- if (a == null || typeof a == "undefined")
137
- return void 0;
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"))
141
- return this.cast(a.toVec2());
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)) {
145
- const [sxy, sw] = a.split(";");
146
- if ((0, import_types.isValidString)(sxy)) {
147
- const parts = sxy.split(",");
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);
150
- }
151
- }
152
- if ((0, import_types.isValidNumber)(a))
153
- return new this(a, a);
154
- return void 0;
155
- }
156
- static resolveArgs(args) {
157
- if ((0, import_types.isFixedTypeArray)(args, import_types.isValidNumber, 2))
158
- return new this(args[0], args[1]);
159
- return this.resolve(args[0]);
160
- }
161
- static is(a) {
162
- return typeof this.cast(a) != "undefined";
163
- }
164
- static fromPoints(a, b) {
165
- const veca = this.resolve(a);
166
- const vecb = this.resolve(b);
167
- return new this(vecb.x - veca.x, vecb.y - veca.y);
168
- }
169
- static clamp(value, min, max) {
170
- const a = this.resolve(value), b = this.resolve(min), c = this.resolve(max);
171
- return new this(
172
- clamp(a.x, b.x, c.x),
173
- clamp(a.y, b.y, c.y)
174
- );
175
- }
176
- static get zero() {
177
- return new this(0, 0);
178
- }
179
- static get one() {
180
- return new this(1, 1);
181
- }
182
- constructor(x, y, w = 1) {
183
- (0, import_types.checkValidNumber)(x);
184
- (0, import_types.checkValidNumber)(y);
185
- (0, import_types.checkValidNumber)(w);
186
- this.x = x;
187
- this.y = y;
188
- this.w = w;
189
- }
190
- toArray(w = this.w !== 1) {
191
- return w ? [this.x, this.y, this.w] : [this.x, this.y];
192
- }
193
- toJSON() {
194
- return {
195
- x: this.x,
196
- y: this.y,
197
- w: this.w
198
- };
199
- }
200
- toString(w = this.w !== 1) {
201
- return w ? `${this.x},${this.y};${this.w}` : `${this.x},${this.y}`;
202
- }
203
- get [Symbol.toStringTag]() {
204
- return "Vec2";
205
- }
206
- [import_types.NodeJSCustomInspect]() {
207
- return `Vec2 <${this.toString()}>`;
208
- }
209
- toSize() {
210
- return [this.x, this.y];
211
- }
212
- toVec3(z = 0) {
213
- return [this.x, this.y, z, this.w];
214
- }
215
- toRGB() {
216
- const vec = this.normalize();
217
- return [vec.x, vec.y, vec.w];
218
- }
219
- toRGBA() {
220
- const vec = this.normalize();
221
- return [vec.x, vec.y, vec.w, 1];
222
- }
223
- toHSL() {
224
- const vec = this.normalize();
225
- return [vec.x, vec.y, vec.w];
226
- }
227
- toHSLA() {
228
- const vec = this.normalize();
229
- return [vec.x, vec.y, vec.w, 1];
230
- }
231
- clone() {
232
- return new _Vec2(this.x, this.y, this.w);
233
- }
234
- equals(...args) {
235
- const a = _Vec2.resolveArgs(args);
236
- return this.x == a.x && this.y == a.y;
237
- }
238
- setX(x) {
239
- this.x = x;
240
- return this;
241
- }
242
- setY(y) {
243
- this.y = y;
244
- return this;
245
- }
246
- setW(w) {
247
- this.w = w;
248
- return this;
249
- }
250
- set(...args) {
251
- const vec = _Vec2.resolveArgs(args);
252
- return this.setX(vec.x).setY(vec.y);
253
- }
254
- add(...args) {
255
- const vec = _Vec2.resolveArgs(args);
256
- return new _Vec2(
257
- this.x + vec.x,
258
- this.y + vec.y
259
- );
260
- }
261
- offset(...args) {
262
- const vec = _Vec2.resolveArgs(args);
263
- this.x += vec.x;
264
- this.y += vec.y;
265
- return this;
266
- }
267
- subtract(...args) {
268
- const vec = _Vec2.resolveArgs(args);
269
- return new _Vec2(
270
- this.x - vec.x,
271
- this.y - vec.y
272
- );
273
- }
274
- multiply(scalar) {
275
- return new _Vec2(
276
- this.x * scalar,
277
- this.y * scalar
278
- );
279
- }
280
- naiveMultiply(...args) {
281
- const vec = _Vec2.resolveArgs(args);
282
- return new _Vec2(
283
- this.x * vec.x,
284
- this.y * vec.y
285
- );
286
- }
287
- divide(...args) {
288
- if ((0, import_types.isFixedTypeArray)(args, import_types.isValidNumber, 1))
289
- return new _Vec2(
290
- this.x / args[0],
291
- this.y / args[0]
292
- );
293
- const vec = _Vec2.resolveArgs(args);
294
- return new _Vec2(
295
- this.x / vec.x,
296
- this.y / vec.y
297
- );
298
- }
299
- dot(...args) {
300
- const vec = _Vec2.resolveArgs(args);
301
- return this.x * vec.x + this.y * vec.y;
302
- }
303
- distance(...args) {
304
- const vec = _Vec2.resolveArgs(args);
305
- return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2);
306
- }
307
- distanceSquare(...args) {
308
- const vec = _Vec2.resolveArgs(args);
309
- return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2));
310
- }
311
- length() {
312
- return Math.sqrt(this.x * this.x + this.y * this.y);
313
- }
314
- cartesianify() {
315
- return new _Vec2(
316
- this.x * Math.cos(this.y),
317
- this.x * Math.sin(this.y)
318
- );
319
- }
320
- polarify() {
321
- return new _Vec2(
322
- Math.sqrt(this.x * this.x + this.y * this.y),
323
- Math.atan(this.y / this.x)
324
- );
325
- }
326
- normalize() {
327
- const length = this.length();
328
- if (length == 0) return _Vec2.zero;
329
- return new _Vec2(
330
- this.x / length,
331
- this.y / length,
332
- this.w / length
333
- );
334
- }
335
- invert() {
336
- return this.multiply(-1);
337
- }
338
- round() {
339
- return new _Vec2(Math.round(this.x), Math.round(this.y), Math.round(this.w));
340
- }
341
- };
342
-
343
- // source/algebra/linear.ts
344
- var LinearFunction = class extends MathFunction {
345
- /**
346
- * The factor of the linear function
347
- */
348
- m;
349
- /**
350
- * The height of the linear function
351
- */
352
- b;
353
- /**
354
- * Create a linear function from two points
355
- * @param a A point
356
- * @param b A point
357
- * @returns A linear function from two points
358
- */
359
- static fromPoints(a, b) {
360
- const veca = Vec2.resolve(a);
361
- const vecb = Vec2.resolve(b);
362
- const m = (vecb.y - veca.y) / (vecb.x - veca.x);
363
- const h = -m * veca.x + veca.y;
364
- return new this(m, h);
365
- }
366
- /**
367
- * Create a linear function with a factor and height
368
- * @param m The factor
369
- * @param b The height
370
- */
371
- constructor(m, b) {
372
- super();
373
- (0, import_types2.checkValidNumber)(m);
374
- (0, import_types2.checkValidNumber)(b);
375
- this.m = m;
376
- this.b = b;
377
- }
378
- get(x) {
379
- (0, import_types2.checkValidNumber)(x);
380
- return this.m * x + this.b;
381
- }
382
- roots() {
383
- const x = -this.b / this.m;
384
- if (!isNaN(x))
385
- return [new Vec2(x, 0)];
386
- return [];
387
- }
388
- toString() {
389
- const bsign = signCharacter(this.b);
390
- if (bsign)
391
- return `f(x) = ${this.m} * x ${bsign} ${Math.abs(this.b)}`;
392
- return `f(x) = ${this.m} * x`;
393
- }
394
- get [Symbol.toStringTag]() {
395
- return "LinearFunction";
396
- }
397
- [import_types2.NodeJSCustomInspect]() {
398
- return `LinearFunction <${this.toString()}>`;
399
- }
400
- };
401
-
402
- // source/algebra/quad.ts
403
- var import_types3 = require("@ntf/types");
404
- var QuadFunction = class extends MathFunction {
405
- a;
406
- b;
407
- c;
408
- static get(a, b, c, x) {
409
- return new this(a, b, c).get(x);
410
- }
411
- constructor(a, b, c) {
412
- super();
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);
418
- this.a = a;
419
- this.b = b;
420
- this.c = c;
421
- }
422
- get(x) {
423
- (0, import_types3.checkValidNumber)(x);
424
- return this.a * x * x + this.b * x + this.c;
425
- }
426
- roots() {
427
- const roots = new Array();
428
- const discriminant = this.b * this.b - 4 * this.a * this.c;
429
- const n0 = (-this.b + Math.sqrt(discriminant)) / (2 * this.a);
430
- const n1 = (-this.b + Math.sqrt(discriminant)) / (2 * this.a);
431
- if (!isNaN(n0))
432
- roots.push(new Vec2(n0, 0));
433
- if (!isNaN(n1) && n0 != n1)
434
- roots.push(new Vec2(n1, 0));
435
- return roots;
436
- }
437
- toString(type = "standard") {
438
- switch (type) {
439
- default:
440
- case "standard": {
441
- const bsign = signCharacter(this.b);
442
- const csign = signCharacter(this.c);
443
- if (bsign && csign)
444
- return `f(x) = ${this.a}x^2 ${bsign} ${Math.abs(this.b)}x ${csign} ${Math.abs(this.c)}`;
445
- if (bsign)
446
- return `f(x) = ${this.a}x^2 ${bsign} ${Math.abs(this.b)}x`;
447
- return `f(x) = ${this.a}x^2`;
448
- }
449
- }
450
- }
451
- get [Symbol.toStringTag]() {
452
- return "QuadFunction";
453
- }
454
- [import_types3.NodeJSCustomInspect]() {
455
- return `QuadFunction <${this.toString()}>`;
456
- }
457
- };
458
-
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);
474
- }
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;
493
- }
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]);
498
- }
499
- static is(a) {
500
- return typeof this.cast(a) != "undefined";
501
- }
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);
506
- }
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
- );
514
- }
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);
524
- }
525
- static get zero() {
526
- return new this(0, 0, 0);
527
- }
528
- static get one() {
529
- return new this(1, 1, 1);
530
- }
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;
540
- }
541
- toArray(w = this.w !== 1) {
542
- return w ? [this.x, this.y, this.z, this.w] : [this.x, this.y, this.z];
543
- }
544
- toJSON() {
545
- return {
546
- x: this.x,
547
- y: this.y,
548
- z: this.z,
549
- w: this.w
550
- };
551
- }
552
- toString(w = this.w !== 1) {
553
- return w ? `${this.x},${this.y},${this.z};${this.w}` : `${this.x},${this.y},${this.z}`;
554
- }
555
- get [Symbol.toStringTag]() {
556
- return "Vec3";
557
- }
558
- [import_types4.NodeJSCustomInspect]() {
559
- return `Vec3 <${this.toString()}>`;
560
- }
561
- toVec2() {
562
- return [this.x, this.y, this.w];
563
- }
564
- toRGB() {
565
- const vec = this.normalize();
566
- return [vec.x, vec.y, vec.z];
567
- }
568
- toRGBA() {
569
- const vec = this.normalize();
570
- return [vec.x, vec.y, vec.z, vec.w];
571
- }
572
- toHSL() {
573
- const vec = this.normalize();
574
- return [vec.x, vec.y, vec.z];
575
- }
576
- toHSLA() {
577
- const vec = this.normalize();
578
- return [vec.x, vec.y, vec.z, vec.w];
579
- }
580
- toQuaternion() {
581
- return [this.w, this.x, this.y, this.z];
582
- }
583
- clone() {
584
- return new _Vec3(this.x, this.y, this.z, this.w);
585
- }
586
- equals(...args) {
587
- const a = _Vec3.resolveArgs(args);
588
- return this.x == a.x && this.y == a.y && this.z == a.z;
589
- }
590
- setX(x) {
591
- this.x = x;
592
- return this;
593
- }
594
- setY(y) {
595
- this.y = y;
596
- return this;
597
- }
598
- setZ(z) {
599
- this.z = z;
600
- return this;
601
- }
602
- set(...args) {
603
- const vec = _Vec3.resolveArgs(args);
604
- return this.setX(vec.x).setY(vec.y).setZ(vec.z);
605
- }
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
- );
613
- }
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;
620
- }
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
- );
628
- }
629
- multiply(scalar) {
630
- return new _Vec3(
631
- this.x * scalar,
632
- this.y * scalar,
633
- this.z * scalar
634
- );
635
- }
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
- );
643
- }
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
- );
657
- }
658
- dot(...args) {
659
- const vec = _Vec3.resolveArgs(args);
660
- return this.x * vec.x + this.y * vec.y + this.z * vec.z;
661
- }
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
- );
669
- }
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);
673
- }
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));
677
- }
678
- length() {
679
- return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
680
- }
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
- );
690
- }
691
- invert() {
692
- return this.multiply(-1);
693
- }
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";
707
- }
708
- static resolve(a) {
709
- const value = this.cast(a);
710
- if (typeof value != "undefined")
711
- return value;
712
- throw new ResolveError("Quaternion", a);
713
- }
714
- static resolveArgs(args) {
715
- if ((0, import_types5.isFixedTypeArray)(args, import_types5.isValidNumber, 4))
716
- return new this(args[0], args[1], args[2], args[3]);
717
- return this.resolve(args[0]);
718
- }
719
- static cast(a) {
720
- if (a == null || typeof a == "undefined")
721
- return void 0;
722
- if ((0, import_types5.isFixedTypeArray)(a, import_types5.isValidNumber, 4))
723
- return new this(a[0], a[1], a[2], a[3]);
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
- }
740
- }
741
- return void 0;
742
- }
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);
752
- }
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;
777
- }
778
- toArray() {
779
- return [this.w, this.x, this.y, this.z];
780
- }
781
- toString() {
782
- return `${this.w} + ${this.x}i + ${this.y}j + ${this.z}k`;
783
- }
784
- get [Symbol.toStringTag]() {
785
- return "Quaternion";
786
- }
787
- [import_types5.NodeJSCustomInspect]() {
788
- return `Quaternion <${this.toString()}>`;
789
- }
790
- toJSON() {
791
- return {
792
- w: this.w,
793
- x: this.x,
794
- y: this.y,
795
- z: this.z
796
- };
797
- }
798
- clone() {
799
- return new _Quaternion(this.w, this.x, this.y, this.z);
800
- }
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
- );
809
- }
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;
817
- }
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
- );
826
- }
827
- negative() {
828
- return new _Quaternion(-this.w, -this.x, -this.y, -this.z);
829
- }
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;
833
- }
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);
840
- }
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
- );
849
- }
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
- );
861
- }
862
- scale(scalar) {
863
- return new _Quaternion(this.w * scalar, this.x * scalar, this.y * scalar, this.z * scalar);
864
- }
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;
868
- }
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);
875
- }
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
- );
887
- }
888
- conjugate() {
889
- return new _Quaternion(this.w, -this.x, -this.y, -this.z);
890
- }
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
- );
903
- }
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);
911
- }
912
- toVec3() {
913
- return [this.x, this.y, this.z, this.w];
914
- }
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);
922
- }
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
- );
932
- }
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
- ];
945
- }
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
- ];
965
- }
966
- };
967
-
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;
994
- }
995
- set red(val) {
996
- this._red = clamp(val, 0, 1);
997
- }
998
- _green;
999
- get green() {
1000
- return this._green;
1001
- }
1002
- set green(val) {
1003
- this._green = clamp(val, 0, 1);
1004
- }
1005
- _blue;
1006
- get blue() {
1007
- return this._blue;
1008
- }
1009
- set blue(val) {
1010
- this._blue = clamp(val, 0, 1);
1011
- }
1012
- _alpha;
1013
- get alpha() {
1014
- return this._alpha;
1015
- }
1016
- set alpha(val) {
1017
- this._alpha = clamp(val, 0, 1);
1018
- }
1019
- static resolve(a) {
1020
- const value = this.cast(a);
1021
- if (typeof value != "undefined")
1022
- return value;
1023
- throw new ResolveError("RGBAColor", a);
1024
- }
1025
- static resolveArgs(args) {
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]);
1028
- return this.resolve(args[0]);
1029
- }
1030
- static cast(a) {
1031
- if (a == null || typeof a == "undefined")
1032
- return void 0;
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));
1045
- }
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
- }
1054
- }
1055
- return void 0;
1056
- }
1057
- static is(a) {
1058
- return typeof this.cast(a) != "undefined";
1059
- }
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);
1069
- }
1070
- toArray(withAlpha = this._alpha !== 1) {
1071
- return withAlpha ? [this.red, this.green, this.blue, this.alpha] : [this.red, this.green, this.blue];
1072
- }
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
- };
1084
- }
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)})`;
1087
- }
1088
- get [Symbol.toStringTag]() {
1089
- return "RGBA";
1090
- }
1091
- [import_types6.NodeJSCustomInspect]() {
1092
- return `RGBA <${this.toString()}>`;
1093
- }
1094
- toVec2() {
1095
- return [this.red, this.green, this.blue];
1096
- }
1097
- toVec3() {
1098
- return [this.red, this.green, this.blue, this.alpha];
1099
- }
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);
1115
- }
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
- );
1126
- }
1127
- };
1128
-
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
- }
1159
- static resolve(a) {
1160
- const value = this.cast(a);
1161
- if (typeof value != "undefined")
1162
- return value;
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]);
1169
- }
1170
- static cast(a) {
1171
- if (a == null || typeof a == "undefined")
1172
- return void 0;
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));
1193
- }
1194
- }
1195
- return void 0;
1196
- }
1197
- static is(a) {
1198
- return typeof this.cast(a) != "undefined";
1199
- }
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);
1209
- }
1210
- toArray(withAlpha = this._alpha !== 1) {
1211
- return withAlpha ? [this.hue, this.saturation, this.luminace, this.alpha] : [this.hue, this.saturation, this.luminace];
1212
- }
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
1223
- };
1224
- }
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)})`;
1227
- }
1228
- get [Symbol.toStringTag]() {
1229
- return "HSLA";
1230
- }
1231
- [import_types7.NodeJSCustomInspect]() {
1232
- return `HSLA <${this.toString()}>`;
1233
- }
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);
1254
- }
1255
- toRGBA() {
1256
- return this.toRGB(true);
1257
- }
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;
1709
- }
1710
- toArray() {
1711
- return [...this.position.toArray(), this.radius];
1712
- }
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()}>`;
1727
- }
1728
- clone() {
1729
- return new _Circle(this.position.clone(), this.radius);
1730
- }
1731
- toVec2() {
1732
- return [this.x, this.y, this.w];
1733
- }
1734
- equals(...args) {
1735
- const c = _Circle.resolveArgs(args);
1736
- return c.position.equals(c.position) && this.radius == c.radius;
1737
- }
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;
1744
- }
1745
- insidePoint(...args) {
1746
- return this.position.distance(Vec2.resolveArgs(args)) <= this.radius;
1747
- }
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;
1758
- }
1759
- set width(val) {
1760
- this.right = this.left + val;
1761
- }
1762
- get height() {
1763
- return this.bottom - this.top;
1764
- }
1765
- set height(val) {
1766
- this.bottom = this.top + val;
1767
- }
1768
- get x() {
1769
- return this.left;
1770
- }
1771
- set x(x) {
1772
- this.left = x;
1773
- }
1774
- get y() {
1775
- return this.top;
1776
- }
1777
- set y(y) {
1778
- this.top = y;
1779
- }
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);
1786
- }
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]);
1791
- }
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;
1807
- }
1808
- static is(a) {
1809
- return typeof this.cast(a) != "undefined";
1810
- }
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;
1820
- }
1821
- toArray() {
1822
- return [this.left, this.right, this.top, this.bottom];
1823
- }
1824
- toString() {
1825
- return `${this.left},${this.right},${this.top},${this.bottom}`;
1826
- }
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;
1875
- }
1876
- };
1877
-
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;
1888
- }
1889
- get area() {
1890
- return this.width * this.height;
1891
- }
1892
- get perimeter() {
1893
- return this.width + this.width + this.height + this.height;
1894
- }
1895
- static resolve(a) {
1896
- const value = this.cast(a);
1897
- if (typeof value != "undefined")
1898
- return value;
1899
- throw new ResolveError("Square", a);
1900
- }
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]);
1905
- }
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;
1923
- }
1924
- static is(a) {
1925
- return typeof this.cast(a) != "undefined";
1926
- }
1927
- constructor(width, height) {
1928
- (0, import_types11.checkValidNumber)(width);
1929
- (0, import_types11.checkValidNumber)(height);
1930
- this.width = width;
1931
- this.height = height;
1932
- }
1933
- toArray() {
1934
- return [this.width, this.height];
1935
- }
1936
- toString() {
1937
- return `${this.width}x${this.height}`;
1938
- }
1939
- get [Symbol.toStringTag]() {
1940
- return "Size";
1941
- }
1942
- [import_types11.NodeJSCustomInspect]() {
1943
- return `Size <${this.toString()}>`;
1944
- }
1945
- toJSON() {
1946
- return {
1947
- width: this.width,
1948
- height: this.height
1949
- };
1950
- }
1951
- clone() {
1952
- return new _Size(this.width, this.height);
1953
- }
1954
- equals(...args) {
1955
- const s = _Size.resolveArgs(args);
1956
- return this.width == s.width && this.height == s.height;
1957
- }
1958
- toVec2() {
1959
- return [this.width, this.height];
1960
- }
1961
- };
1962
-
1963
- // source/geometry/rectangle.ts
1964
- var Rectangle = class _Rectangle {
1965
- position;
1966
- size;
1967
- get area() {
1968
- return this.width * this.height;
1969
- }
1970
- get perimeter() {
1971
- return this.width + this.width + this.height + this.height;
1972
- }
1973
- get x() {
1974
- return this.position.x;
1975
- }
1976
- set x(val) {
1977
- this.position.x = val;
1978
- }
1979
- get y() {
1980
- return this.position.y;
1981
- }
1982
- set y(val) {
1983
- this.position.y = val;
1984
- }
1985
- get w() {
1986
- return this.position.w;
1987
- }
1988
- set w(val) {
1989
- this.position.w = val;
1990
- }
1991
- get width() {
1992
- return this.size.width;
1993
- }
1994
- set width(val) {
1995
- this.size.width = val;
1996
- }
1997
- get height() {
1998
- return this.size.height;
1999
- }
2000
- set height(val) {
2001
- this.size.height = val;
2002
- }
2003
- static resolve(a) {
2004
- const value = this.cast(a);
2005
- if (typeof value != "undefined")
2006
- return value;
2007
- throw new ResolveError("Rectangle", a);
2008
- }
2009
- static resolveArgs(args) {
2010
- if ((0, import_types12.isFixedTypeArray)(args, import_types12.isValidNumber, 4))
2011
- return new this([args[0], args[1]], [args[2], args[3]]);
2012
- return this.resolve(args[0]);
2013
- }
2014
- static cast(a) {
2015
- if (a == null || typeof a == "undefined")
2016
- return void 0;
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;
2023
- }
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;
2033
- }
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;
2041
- }
2042
- return void 0;
2043
- }
2044
- static is(a) {
2045
- return typeof this.cast(a) != "undefined";
2046
- }
2047
- constructor(pos, size) {
2048
- this.position = Vec2.resolve(pos);
2049
- this.size = Size.resolve(size);
2050
- }
2051
- toArray(w = this.w !== 1) {
2052
- return [...this.position.toArray(w), ...this.size.toArray()];
2053
- }
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;
2091
- }
2092
- get alpha() {
2093
- return Math.acos((this.b * this.b + this.c * this.c - this.a * this.a) / (2 * this.b * this.c));
2094
- }
2095
- get beta() {
2096
- return Math.acos((this.c * this.c + this.a * this.a - this.b * this.b) / (2 * this.c * this.a));
2097
- }
2098
- get gamma() {
2099
- return Math.acos((this.a * this.a + this.b * this.b - this.c * this.c) / (2 * this.a * this.b));
2100
- }
2101
- get perimeter() {
2102
- return this.a + this.b + this.c;
2103
- }
2104
- get semiperimeter() {
2105
- return this.perimeter / 2;
2106
- }
2107
- get area() {
2108
- return Math.sqrt(this.semiperimeter * (this.semiperimeter - this.a) * (this.semiperimeter - this.b) * (this.semiperimeter - this.c));
2109
- }
2110
- get base() {
2111
- return 2 * (this.area / (this.a * Math.sin(this.gamma)));
2112
- }
2113
- get height() {
2114
- return 2 * (this.area / this.base);
2115
- }
2116
- toString() {
2117
- return `${this.A}|${this.B}|${this.C}`;
2118
- }
2119
- get [Symbol.toStringTag]() {
2120
- return "Triangle";
2121
- }
2122
- [import_types13.NodeJSCustomInspect]() {
2123
- return `Triangle <${this.toString()}>`;
2124
- }
2125
- };
2126
- var Triangle2D = class extends Triangle {
2127
- get a() {
2128
- return Vec2.fromPoints(this.B, this.C).length();
2129
- }
2130
- get b() {
2131
- return Vec2.fromPoints(this.A, this.C).length();
2132
- }
2133
- get c() {
2134
- return Vec2.fromPoints(this.A, this.B).length();
2135
- }
2136
- };
2137
- var Triangle3D = class extends Triangle {
2138
- get a() {
2139
- return Vec3.fromPoints(this.B, this.C).length();
2140
- }
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();
2146
- }
2147
- };
2148
-
2149
- // source/matrices/mat3.ts
2150
- var import_types14 = require("@ntf/types");
2151
- var Mat3 = class _Mat3 {
2152
- _raw;
2153
- get m00() {
2154
- return this._raw[0];
2155
- }
2156
- set m00(val) {
2157
- this._raw[0] = val;
2158
- }
2159
- get m01() {
2160
- return this._raw[1];
2161
- }
2162
- set m01(val) {
2163
- this._raw[1] = val;
2164
- }
2165
- get m02() {
2166
- return this._raw[2];
2167
- }
2168
- set m02(val) {
2169
- this._raw[2] = val;
2170
- }
2171
- get m10() {
2172
- return this._raw[3];
2173
- }
2174
- set m10(val) {
2175
- this._raw[3] = val;
2176
- }
2177
- get m11() {
2178
- return this._raw[4];
2179
- }
2180
- set m11(val) {
2181
- this._raw[4] = val;
2182
- }
2183
- get m12() {
2184
- return this._raw[5];
2185
- }
2186
- set m12(val) {
2187
- this._raw[5] = val;
2188
- }
2189
- get m20() {
2190
- return this._raw[6];
2191
- }
2192
- set m20(val) {
2193
- this._raw[6] = val;
2194
- }
2195
- get m21() {
2196
- return this._raw[7];
2197
- }
2198
- set m21(val) {
2199
- this._raw[7] = val;
2200
- }
2201
- get m22() {
2202
- return this._raw[8];
2203
- }
2204
- set m22(val) {
2205
- this._raw[8] = val;
2206
- }
2207
- static resolve(a) {
2208
- const value = this.cast(a);
2209
- if (typeof value != "undefined")
2210
- return value;
2211
- throw new ResolveError("Mat3", a);
2212
- }
2213
- static resolveArgs(args) {
2214
- if ((0, import_types14.isFixedTypeArray)(args, import_types14.isValidNumber, 9))
2215
- return new this(args);
2216
- return this.resolve(args[0]);
2217
- }
2218
- static cast(a) {
2219
- if (a == null || typeof a == "undefined")
2220
- return void 0;
2221
- if ((0, import_types14.isFixedTypeArray)(a, import_types14.isValidNumber, 9)) {
2222
- return new this(a);
2223
- }
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))
2227
- return new this([
2228
- row0[0],
2229
- row0[1],
2230
- row0[2],
2231
- row1[0],
2232
- row1[1],
2233
- row1[2],
2234
- row2[0],
2235
- row2[1],
2236
- row2[2]
2237
- ]);
2238
- }
2239
- if ((0, import_types14.isValidString)(a)) {
2240
- const parts = a.split(",");
2241
- if ((0, import_types14.isFixedTypeArray)(parts, import_types14.isValidString, 9))
2242
- return this.cast(parts.map((i) => parseFloat(i)));
2243
- }
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"))
2247
- return new this([
2248
- a.m00,
2249
- a.m01,
2250
- a.m02,
2251
- a.m10,
2252
- a.m11,
2253
- a.m12,
2254
- a.m20,
2255
- a.m21,
2256
- a.m22
2257
- ]);
2258
- if ((0, import_types14.isValidNumber)(a)) {
2259
- return new this([a, a, a, a, a, a, a, a, a]);
2260
- }
2261
- return void 0;
2262
- }
2263
- static is(a) {
2264
- return typeof this.cast(a) != "undefined";
2265
- }
2266
- static projection(width, height) {
2267
- return new this([
2268
- 2 / width,
2269
- 0,
2270
- 0,
2271
- 0,
2272
- -2 / height,
2273
- 0,
2274
- -1,
2275
- 1,
2276
- 1
2277
- ]);
2278
- }
2279
- constructor(init = [1, 0, 0, 0, 1, 0, 0, 0, 1]) {
2280
- (0, import_types14.checkFixedTypeArray)(init, import_types14.isValidNumber, 9);
2281
- this._raw = init;
2282
- }
2283
- toArray() {
2284
- return [
2285
- this.m00,
2286
- this.m01,
2287
- this.m02,
2288
- this.m10,
2289
- this.m11,
2290
- this.m12,
2291
- this.m20,
2292
- this.m21,
2293
- this.m22
2294
- ];
2295
- }
2296
- toNestetArray() {
2297
- return [
2298
- [this.m00, this.m01, this.m02],
2299
- [this.m10, this.m11, this.m12],
2300
- [this.m20, this.m21, this.m22]
2301
- ];
2302
- }
2303
- toJSON() {
2304
- return {
2305
- m00: this.m00,
2306
- m01: this.m01,
2307
- m02: this.m02,
2308
- m10: this.m10,
2309
- m11: this.m11,
2310
- m12: this.m12,
2311
- m20: this.m20,
2312
- m21: this.m21,
2313
- m22: this.m22
2314
- };
2315
- }
2316
- toString() {
2317
- return `${this.m00},${this.m01},${this.m02},${this.m10},${this.m11},${this.m12},${this.m20},${this.m21},${this.m22}`;
2318
- }
2319
- get [Symbol.toStringTag]() {
2320
- return "Mat3";
2321
- }
2322
- [import_types14.NodeJSCustomInspect]() {
2323
- return `Mat3 <${this.toString()}>`;
2324
- }
2325
- clone() {
2326
- return new _Mat3([
2327
- this.m00,
2328
- this.m01,
2329
- this.m02,
2330
- this.m10,
2331
- this.m11,
2332
- this.m12,
2333
- this.m20,
2334
- this.m21,
2335
- this.m22
2336
- ]);
2337
- }
2338
- equals(...args) {
2339
- const m = _Mat3.resolveArgs(args);
2340
- for (let index = 0; index < this._raw.length; index++)
2341
- if (this._raw[index] != m._raw[index])
2342
- return false;
2343
- return true;
2344
- }
2345
- add(...args) {
2346
- const b = _Mat3.resolveArgs(args);
2347
- const m = new _Mat3();
2348
- for (let index = 0; index < this._raw.length; index++)
2349
- m._raw[index] = this._raw[index] + b._raw[index];
2350
- return m;
2351
- }
2352
- subtract(...args) {
2353
- const b = _Mat3.resolveArgs(args);
2354
- const m = new _Mat3();
2355
- for (let index = 0; index < this._raw.length; index++)
2356
- m._raw[index] = this._raw[index] - b._raw[index];
2357
- return m;
2358
- }
2359
- multiply(...args) {
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]
2371
- ]);
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
2383
- ]);
2384
- }
2385
- translate(...args) {
2386
- const vec = Vec2.resolveArgs(args);
2387
- return this.multiply([
2388
- 1,
2389
- 0,
2390
- 0,
2391
- 0,
2392
- 1,
2393
- 0,
2394
- vec.x,
2395
- vec.y,
2396
- 1
2397
- ]);
2398
- }
2399
- rotate(angle) {
2400
- const c = Math.cos(angle);
2401
- const s = Math.sin(angle);
2402
- return this.multiply([
2403
- c,
2404
- -s,
2405
- 0,
2406
- s,
2407
- c,
2408
- 0,
2409
- 0,
2410
- 0,
2411
- 1
2412
- ]);
2413
- }
2414
- scale(...args) {
2415
- const vec = Vec2.resolve(args);
2416
- return this.multiply([
2417
- vec.x,
2418
- 0,
2419
- 0,
2420
- 0,
2421
- vec.y,
2422
- 0,
2423
- 0,
2424
- 0,
2425
- 1
2426
- ]);
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
- }
2431
- inverse() {
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
2443
- ]);
2444
- }
2445
- toMat4() {
2446
- return [
2447
- this.m00,
2448
- this.m01,
2449
- this.m02,
2450
- 0,
2451
- this.m10,
2452
- this.m11,
2453
- this.m12,
2454
- 0,
2455
- this.m20,
2456
- this.m20,
2457
- this.m22,
2458
- 0,
2459
- 0,
2460
- 0,
2461
- 0,
2462
- 1
2463
- ];
2464
- }
2465
- };
2466
-
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];
2473
- }
2474
- set m00(val) {
2475
- this._raw[0] = val;
2476
- }
2477
- get m01() {
2478
- return this._raw[1];
2479
- }
2480
- set m01(val) {
2481
- this._raw[1] = val;
2482
- }
2483
- get m02() {
2484
- return this._raw[2];
2485
- }
2486
- set m02(val) {
2487
- this._raw[2] = val;
2488
- }
2489
- get m03() {
2490
- return this._raw[3];
2491
- }
2492
- set m03(val) {
2493
- this._raw[3] = val;
2494
- }
2495
- get m10() {
2496
- return this._raw[4];
2497
- }
2498
- set m10(val) {
2499
- this._raw[4] = val;
2500
- }
2501
- get m11() {
2502
- return this._raw[5];
2503
- }
2504
- set m11(val) {
2505
- this._raw[5] = val;
2506
- }
2507
- get m12() {
2508
- return this._raw[6];
2509
- }
2510
- set m12(val) {
2511
- this._raw[6] = val;
2512
- }
2513
- get m13() {
2514
- return this._raw[7];
2515
- }
2516
- set m13(val) {
2517
- this._raw[7] = val;
2518
- }
2519
- get m20() {
2520
- return this._raw[8];
2521
- }
2522
- set m20(val) {
2523
- this._raw[8] = val;
2524
- }
2525
- get m21() {
2526
- return this._raw[9];
2527
- }
2528
- set m21(val) {
2529
- this._raw[9] = val;
2530
- }
2531
- get m22() {
2532
- return this._raw[10];
2533
- }
2534
- set m22(val) {
2535
- this._raw[10] = val;
2536
- }
2537
- get m23() {
2538
- return this._raw[11];
2539
- }
2540
- set m23(val) {
2541
- this._raw[11] = val;
2542
- }
2543
- get m30() {
2544
- return this._raw[12];
2545
- }
2546
- set m30(val) {
2547
- this._raw[12] = val;
2548
- }
2549
- get m31() {
2550
- return this._raw[13];
2551
- }
2552
- set m31(val) {
2553
- this._raw[13] = val;
2554
- }
2555
- get m32() {
2556
- return this._raw[14];
2557
- }
2558
- set m32(val) {
2559
- this._raw[14] = val;
2560
- }
2561
- get m33() {
2562
- return this._raw[15];
2563
- }
2564
- set m33(val) {
2565
- this._raw[15] = val;
2566
- }
2567
- static resolve(a) {
2568
- const value = this.cast(a);
2569
- if (typeof value != "undefined")
2570
- return value;
2571
- throw new ResolveError("Mat4", a);
2572
- }
2573
- static resolveArgs(args) {
2574
- if ((0, import_types15.isFixedTypeArray)(args, import_types15.isValidNumber, 16))
2575
- return new this(args);
2576
- return this.resolve(args[0]);
2577
- }
2578
- static cast(a) {
2579
- if (a == null || typeof a == "undefined")
2580
- return void 0;
2581
- if ((0, import_types15.isFixedTypeArray)(a, import_types15.isValidNumber, 16)) {
2582
- return new this(a);
2583
- }
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]);
2634
- }
2635
- return void 0;
2636
- }
2637
- static is(a) {
2638
- return typeof this.cast(a) != "undefined";
2639
- }
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;
2797
- }
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;
2804
- }
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;
2811
- }
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
- ]);
2865
- }
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
- ]);
2886
- }
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
- ]);
2908
- }
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
- ]);
2930
- }
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
- ]);
2952
- }
2953
- rotate(...args) {
2954
- const vec = Vec3.resolveArgs(args);
2955
- return this.rotateX(vec.x).rotateY(vec.y).rotateZ(vec.z);
2956
- }
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
- ]);
2977
- }
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
- ];
3010
- }
3011
- };
3012
-
3013
- // source/color.ts
3014
- var import_types16 = require("@ntf/types");
3015
- var AnyColor;
3016
- ((AnyColor2) => {
3017
- function cast(a, preferHSL = false) {
3018
- const results = [];
3019
- try {
3020
- const rgba = RGBA.resolve(a);
3021
- results.push(rgba);
3022
- } catch (e) {
3023
- }
3024
- try {
3025
- const hsla = HSLA.resolve(a);
3026
- results.push(hsla);
3027
- } catch (e) {
3028
- }
3029
- let offset = preferHSL ? 1 : 0;
3030
- const firstItem = results[offset];
3031
- if (firstItem)
3032
- return firstItem;
3033
- const secondItem = results[offset + 1];
3034
- if (secondItem)
3035
- return secondItem;
3036
- return void 0;
3037
- }
3038
- AnyColor2.cast = cast;
3039
- function resolve(a, preferHSL = false) {
3040
- const value = cast(a, preferHSL);
3041
- if (typeof value != "undefined")
3042
- return value;
3043
- throw new ResolveError("Color", a);
3044
- }
3045
- AnyColor2.resolve = resolve;
3046
- function resolveArgs(args, preferHSL = false) {
3047
- if ((0, import_types16.isFixedTypeArray)(args, import_types16.isValidNumber, 3) || (0, import_types16.isFixedTypeArray)(args, import_types16.isValidNumber, 4))
3048
- return resolve(args, preferHSL);
3049
- return resolve(args[0], preferHSL);
3050
- }
3051
- AnyColor2.resolveArgs = resolveArgs;
3052
- })(AnyColor || (AnyColor = {}));
3053
-
3054
- // source/transform.ts
3055
- var import_types17 = require("@ntf/types");
3056
- var Transform2D = class {
3057
- constructor(position, rotation, scale, parent) {
3058
- this.parent = parent;
3059
- (0, import_types17.checkValidNumber)(rotation);
3060
- this.localPosition = Vec2.resolve(position);
3061
- this.localRotation = rotation;
3062
- this.localScale = Vec2.resolve(scale);
3063
- }
3064
- origin = Vec2.zero;
3065
- localPosition;
3066
- localRotation;
3067
- get localRotationDegree() {
3068
- return radianToDegree(this.localRotation);
3069
- }
3070
- set localRotationDegree(v) {
3071
- this.localRotation = degreeToRadian(v);
3072
- }
3073
- localScale;
3074
- get globalPosition() {
3075
- let position = Vec2.zero;
3076
- let transform = this;
3077
- while (transform !== void 0) {
3078
- position = position.add(transform.localPosition).add(transform.origin);
3079
- transform = transform.parent;
3080
- }
3081
- return position;
3082
- }
3083
- get globalRotation() {
3084
- let rotation = 0;
3085
- let transform = this;
3086
- while (transform !== void 0) {
3087
- rotation += transform.localRotation;
3088
- transform = transform.parent;
3089
- }
3090
- return rotation;
3091
- }
3092
- get globalRotationDegree() {
3093
- return radianToDegree(this.globalRotation);
3094
- }
3095
- get globalScale() {
3096
- let scale = Vec2.one;
3097
- let transform = this;
3098
- while (transform !== void 0) {
3099
- scale = scale.naiveMultiply(transform.localScale);
3100
- transform = transform.parent;
3101
- }
3102
- return scale;
3103
- }
3104
- toString() {
3105
- return `${this.localPosition.toString()}|${this.localRotation}|${this.localScale.toString()}`;
3106
- }
3107
- get [Symbol.toStringTag]() {
3108
- return "Transform2D";
3109
- }
3110
- [import_types17.NodeJSCustomInspect]() {
3111
- return `Transform2D <${this.toString()}>`;
3112
- }
3113
- toMat3() {
3114
- return new Mat3().scale(this.localScale).rotate(this.localRotation).translate(this.localPosition);
3115
- }
3116
- toGlobalMat3() {
3117
- let result = new Mat3();
3118
- let transform = this;
3119
- while (transform !== void 0) {
3120
- result = result.multiply(transform.toMat3());
3121
- transform = transform.parent;
3122
- }
3123
- return result;
3124
- }
3125
- };
3126
- var Transform3D = class {
3127
- /**
3128
- * Create a new transform with `position`, `rotation` and `scale`
3129
- * @param position The position as a Vec3
3130
- * @param rotation The rotation as a Quaternion
3131
- * @param scale The scale as a Vec3
3132
- */
3133
- constructor(position, rotation, scale, parent) {
3134
- this.parent = parent;
3135
- this.localPosition = Vec3.resolve(position);
3136
- this.localRotation = Quaternion.resolve(rotation);
3137
- this.localScale = Vec3.resolve(scale);
3138
- }
3139
- origin = Vec3.zero;
3140
- /**
3141
- * The local position
3142
- */
3143
- localPosition;
3144
- /**
3145
- * The local rotation
3146
- */
3147
- localRotation;
3148
- /**
3149
- * The local scale
3150
- */
3151
- localScale;
3152
- get globalPosition() {
3153
- let position = Vec3.zero;
3154
- let transform = this;
3155
- while (transform !== void 0) {
3156
- position = position.add(transform.localPosition).add(transform.origin);
3157
- transform = transform.parent;
3158
- }
3159
- return position;
3160
- }
3161
- get globalRotation() {
3162
- let rotation = Quaternion.zero;
3163
- let transform = this;
3164
- while (transform !== void 0) {
3165
- rotation = rotation.add(transform.localRotation);
3166
- transform = transform.parent;
3167
- }
3168
- return rotation;
3169
- }
3170
- get globalScale() {
3171
- let scale = Vec3.one;
3172
- let transform = this;
3173
- while (transform !== void 0) {
3174
- scale = scale.naiveMultiply(transform.localScale);
3175
- transform = transform.parent;
3176
- }
3177
- return scale;
3178
- }
3179
- toString() {
3180
- return `${this.localPosition.toString()}|${this.localRotation.toString()}|${this.localScale.toString()}`;
3181
- }
3182
- get [Symbol.toStringTag]() {
3183
- return "Transform2D";
3184
- }
3185
- [import_types17.NodeJSCustomInspect]() {
3186
- return `Transform2D <${this.toString()}>`;
3187
- }
3188
- /**
3189
- * Convert the transform into a 4x3 matrix
3190
- * @returns A 4x4 matrix from the transform
3191
- */
3192
- toMat4() {
3193
- return new Mat4().scale(this.localScale).multiply(this.localRotation).translate(this.localPosition);
3194
- }
3195
- toGlobalMat4() {
3196
- let result = new Mat4();
3197
- let transform = this;
3198
- while (transform !== void 0) {
3199
- result = result.multiply(transform.toMat4());
3200
- transform = transform.parent;
3201
- }
3202
- return result;
3203
- }
3204
- };
1
+ let e=require(`@ntf/types`);var t=class{};function n(e){if(e!=0){if(e<0)return`-`;if(e>0)return`+`}}var r=class extends Error{constructor(e,t){super(`Can't resolve ${t} to ${e}`),this.target=e,this.value=t}};function i(e,t,n){return e<=t?t:e>=n?n:e}function a(e,t){let n=Math.abs(e),r=Math.abs(t);if(e==0)return Math.log(r);if(t==0)return Math.log(n);if(n<3e3&&r<3e3)return .5*Math.log(e*e+t*t);let i=e/2,a=t/2;return .5*Math.log(i*i+a*a)+Math.LN2}const o=1e-16,s=(e,t,n)=>((typeof e==`number`?1:1n)-n)*e+n*t;var c=class t{x;y;w;static resolve(e){let t=this.cast(e);if(t!==void 0)return t;throw new r(`Vec2`,e)}static cast(t){if(!(t==null||t===void 0)){if((0,e.isFixedTypeArray)(t,e.isValidNumber,2)||(0,e.isFixedTypeArray)(t,e.isValidNumber,3))return new this(t[0],t[1],t[2]);if((0,e.hasTypedProperty)(t,`toVec2`,`function`))return this.cast(t.toVec2());if((0,e.hasTypedProperty)(t,`x`,`number`)&&(0,e.hasTypedProperty)(t,`y`,`number`))return new this(t.x,t.y,(0,e.hasTypedProperty)(t,`w`,`number`)?t.w:void 0);if((0,e.isValidString)(t)){let[n,r]=t.split(`;`);if((0,e.isValidString)(n)){let t=n.split(`,`);if((0,e.isFixedTypeArray)(t,e.isValidString,2))return new this(parseFloat(t[0]),parseFloat(t[1]),(0,e.isValidString)(r)?parseFloat(r):void 0)}}if((0,e.isValidNumber)(t))return new this(t,t)}}static resolveArgs(t){return(0,e.isFixedTypeArray)(t,e.isValidNumber,2)?new this(t[0],t[1]):this.resolve(t[0])}static is(e){return this.cast(e)!==void 0}static fromPoints(e,t){let n=this.resolve(e),r=this.resolve(t);return new this(r.x-n.x,r.y-n.y)}static clamp(e,t,n){let r=this.resolve(e),a=this.resolve(t),o=this.resolve(n);return new this(i(r.x,a.x,o.x),i(r.y,a.y,o.y))}static get zero(){return new this(0,0)}static get one(){return new this(1,1)}constructor(t,n,r=1){(0,e.checkValidNumber)(t),(0,e.checkValidNumber)(n),(0,e.checkValidNumber)(r),this.x=t,this.y=n,this.w=r}toArray(e=this.w!==1){return e?[this.x,this.y,this.w]:[this.x,this.y]}toJSON(){return{x:this.x,y:this.y,w:this.w}}toString(e=this.w!==1){return e?`${this.x},${this.y};${this.w}`:`${this.x},${this.y}`}get[Symbol.toStringTag](){return`Vec2`}[e.NodeJSCustomInspect](){return`Vec2 <${this.toString()}>`}toSize(){return[this.x,this.y]}toVec3(e=0){return[this.x,this.y,e,this.w]}toRGB(){let e=this.normalize();return[e.x,e.y,e.w]}toRGBA(){let e=this.normalize();return[e.x,e.y,e.w,1]}toHSL(){let e=this.normalize();return[e.x,e.y,e.w]}toHSLA(){let e=this.normalize();return[e.x,e.y,e.w,1]}clone(){return new t(this.x,this.y,this.w)}equals(...e){let n=t.resolveArgs(e);return this.x==n.x&&this.y==n.y}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setW(e){return this.w=e,this}set(...e){let n=t.resolveArgs(e);return this.setX(n.x).setY(n.y)}add(...e){let n=t.resolveArgs(e);return new t(this.x+n.x,this.y+n.y)}offset(...e){let n=t.resolveArgs(e);return this.x+=n.x,this.y+=n.y,this}subtract(...e){let n=t.resolveArgs(e);return new t(this.x-n.x,this.y-n.y)}multiply(e){return new t(this.x*e,this.y*e)}naiveMultiply(...e){let n=t.resolveArgs(e);return new t(this.x*n.x,this.y*n.y)}divide(...n){if((0,e.isFixedTypeArray)(n,e.isValidNumber,1))return new t(this.x/n[0],this.y/n[0]);let r=t.resolveArgs(n);return new t(this.x/r.x,this.y/r.y)}dot(...e){let n=t.resolveArgs(e);return this.x*n.x+this.y*n.y}distance(...e){let n=t.resolveArgs(e);return(n.x-this.x)**2+(n.y-this.y)**2}distanceSquare(...e){let n=t.resolveArgs(e);return Math.sqrt((n.x-this.x)**2+(n.y-this.y)**2)}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}cartesianify(){return new t(this.x*Math.cos(this.y),this.x*Math.sin(this.y))}polarify(){return new t(Math.sqrt(this.x*this.x+this.y*this.y),Math.atan(this.y/this.x))}normalize(){let e=this.length();return e==0?t.zero:new t(this.x/e,this.y/e,this.w/e)}invert(){return this.multiply(-1)}round(){return new t(Math.round(this.x),Math.round(this.y),Math.round(this.w))}},l=class extends t{m;b;static fromPoints(e,t){let n=c.resolve(e),r=c.resolve(t),i=(r.y-n.y)/(r.x-n.x),a=-i*n.x+n.y;return new this(i,a)}constructor(t,n){super(),(0,e.checkValidNumber)(t),(0,e.checkValidNumber)(n),this.m=t,this.b=n}get(t){return(0,e.checkValidNumber)(t),this.m*t+this.b}roots(){let e=-this.b/this.m;return isNaN(e)?[]:[new c(e,0)]}toString(){let e=n(this.b);return e?`f(x) = ${this.m} * x ${e} ${Math.abs(this.b)}`:`f(x) = ${this.m} * x`}get[Symbol.toStringTag](){return`LinearFunction`}[e.NodeJSCustomInspect](){return`LinearFunction <${this.toString()}>`}},u=class extends t{a;b;c;static get(e,t,n,r){return new this(e,t,n).get(r)}constructor(t,n,r){if(super(),(0,e.checkValidNumber)(t),t===0)throw new e.ExpectedTypeError(`non-zero valid number`,t);(0,e.checkValidNumber)(n),(0,e.checkValidNumber)(r),this.a=t,this.b=n,this.c=r}get(t){return(0,e.checkValidNumber)(t),this.a*t*t+this.b*t+this.c}roots(){let e=[],t=this.b*this.b-4*this.a*this.c,n=(-this.b+Math.sqrt(t))/(2*this.a),r=(-this.b+Math.sqrt(t))/(2*this.a);return isNaN(n)||e.push(new c(n,0)),!isNaN(r)&&n!=r&&e.push(new c(r,0)),e}toString(e=`standard`){switch(e){default:case`standard`:{let e=n(this.b),t=n(this.c);return e&&t?`f(x) = ${this.a}x^2 ${e} ${Math.abs(this.b)}x ${t} ${Math.abs(this.c)}`:e?`f(x) = ${this.a}x^2 ${e} ${Math.abs(this.b)}x`:`f(x) = ${this.a}x^2`}}}get[Symbol.toStringTag](){return`QuadFunction`}[e.NodeJSCustomInspect](){return`QuadFunction <${this.toString()}>`}},d=class t{x;y;z;w;static resolve(e){let t=this.cast(e);if(t!==void 0)return t;throw new r(`Vec3`,e)}static cast(t){if(!(t==null||t===void 0)){if((0,e.isFixedTypeArray)(t,e.isValidNumber,3)||(0,e.isFixedTypeArray)(t,e.isValidNumber,4))return new this(t[0],t[1],t[2],t[3]);if((0,e.hasTypedProperty)(t,`x`,`number`)&&(0,e.hasTypedProperty)(t,`y`,`number`)&&(0,e.hasTypedProperty)(t,`z`,`number`))return new this(t.x,t.y,t.z,(0,e.hasTypedProperty)(t,`w`,`number`)?t.w:void 0);if((0,e.isValidString)(t)){let[n,r]=t.split(`;`);if((0,e.isValidString)(n)){let t=n.split(`,`);if((0,e.isFixedTypeArray)(t,e.isValidString,3))return new this(parseFloat(t[0]),parseFloat(t[1]),parseFloat(t[2]),(0,e.isValidString)(r)?parseFloat(r):void 0)}}if((0,e.isValidNumber)(t))return new this(t,t,t)}}static resolveArgs(t){return(0,e.isFixedTypeArray)(t,e.isValidNumber,3)?new this(t[0],t[1],t[2]):this.resolve(t[0])}static is(e){return this.cast(e)!==void 0}static fromPoints(e,t){let n=this.resolve(e),r=this.resolve(t);return new this(r.x-n.x,r.y-n.y,r.z-n.z)}static clamp(e,t,n){let r=this.resolve(e),a=this.resolve(t),o=this.resolve(n);return new this(i(r.x,a.x,o.x),i(r.y,a.y,o.y),i(r.z,a.z,o.z))}static intersectPlane(e,n,r,i,a){n=this.resolve(n).normalize();let o=-this.resolve(n).dot(e),s=this.resolve(r).dot(n),c=this.resolve(i).dot(n);a=(-o-s)/(c-s);let l=this.resolve(i).subtract(r).multiply(a);return t.resolve(r).add(l)}static get zero(){return new this(0,0,0)}static get one(){return new this(1,1,1)}constructor(t,n,r,i=1){(0,e.checkValidNumber)(t),(0,e.checkValidNumber)(n),(0,e.checkValidNumber)(r),(0,e.checkValidNumber)(i),this.x=t,this.y=n,this.z=r,this.w=i}toArray(e=this.w!==1){return e?[this.x,this.y,this.z,this.w]:[this.x,this.y,this.z]}toJSON(){return{x:this.x,y:this.y,z:this.z,w:this.w}}toString(e=this.w!==1){return e?`${this.x},${this.y},${this.z};${this.w}`:`${this.x},${this.y},${this.z}`}get[Symbol.toStringTag](){return`Vec3`}[e.NodeJSCustomInspect](){return`Vec3 <${this.toString()}>`}toVec2(){return[this.x,this.y,this.w]}toRGB(){let e=this.normalize();return[e.x,e.y,e.z]}toRGBA(){let e=this.normalize();return[e.x,e.y,e.z,e.w]}toHSL(){let e=this.normalize();return[e.x,e.y,e.z]}toHSLA(){let e=this.normalize();return[e.x,e.y,e.z,e.w]}toQuaternion(){return[this.w,this.x,this.y,this.z]}clone(){return new t(this.x,this.y,this.z,this.w)}equals(...e){let n=t.resolveArgs(e);return this.x==n.x&&this.y==n.y&&this.z==n.z}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}set(...e){let n=t.resolveArgs(e);return this.setX(n.x).setY(n.y).setZ(n.z)}add(...e){let n=t.resolveArgs(e);return new t(this.x+n.x,this.y+n.y,this.z+n.z)}offset(...e){let n=t.resolveArgs(e);return this.x+=n.x,this.y+=n.y,this.z+=n.z,this}subtract(...e){let n=t.resolveArgs(e);return new t(this.x-n.x,this.y-n.y,this.z-n.z)}multiply(e){return new t(this.x*e,this.y*e,this.z*e)}naiveMultiply(...e){let n=t.resolveArgs(e);return new t(this.x*n.x,this.y*n.y,this.z*n.z)}divide(...n){if((0,e.isFixedTypeArray)(n,e.isValidNumber,1))return new t(this.x/n[0],this.y/n[0],this.z/n[0]);let r=t.resolveArgs(n);return new t(this.x/r.x,this.y/r.y,this.z/r.z)}dot(...e){let n=t.resolveArgs(e);return this.x*n.x+this.y*n.y+this.z*n.z}cross(...e){let n=t.resolveArgs(e);return new t(this.y*n.z-this.z*n.y,this.z*n.x-this.x*n.z,this.x*n.y-this.y*n.x)}distance(...e){let n=t.resolveArgs(e);return(n.x-this.x)**2+(n.y-this.y)**2+(n.z-this.z)**2}distanceSquare(...e){let n=t.resolveArgs(e);return Math.sqrt((n.x-this.x)**2+(n.y-this.y)**2+(n.z-this.z)**2)}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}normalize(){let e=this.length();return e==0?t.zero:new t(this.x/e,this.y/e,this.z/e,this.w/e)}invert(){return this.multiply(-1)}round(){return new t(Math.round(this.x),Math.round(this.y),Math.round(this.z),Math.round(this.w))}},f=class t{w;x;y;z;static is(e){return this.cast(e)!==void 0}static resolve(e){let t=this.cast(e);if(t!==void 0)return t;throw new r(`Quaternion`,e)}static resolveArgs(t){return(0,e.isFixedTypeArray)(t,e.isValidNumber,4)?new this(t[0],t[1],t[2],t[3]):this.resolve(t[0])}static cast(t){if(!(t==null||t===void 0)){if((0,e.isFixedTypeArray)(t,e.isValidNumber,4))return new this(t[0],t[1],t[2],t[3]);if((0,e.hasTypedProperty)(t,`toQuaternion`,`function`))return this.cast(t.toQuaternion());if((0,e.hasTypedProperty)(t,`w`,`number`)&&(0,e.hasTypedProperty)(t,`x`,`number`)&&(0,e.hasTypedProperty)(t,`y`,`number`)&&(0,e.hasTypedProperty)(t,`z`,`number`))return new this(t.w,t.x,t.y,t.z);if((0,e.isValidString)(t)){let n=t.replaceAll(` `,``).split(`+`);if((0,e.isFixedTypeArray)(n,e.isValidString,4)){let[e,t,r,i]=n;if(e&&t?.endsWith(`i`)&&r?.endsWith(`j`)&&i?.endsWith(`k`))return this.cast([parseFloat(e),parseFloat(t.substring(0,t.length-1)),parseFloat(r.substring(0,r.length-1)),parseFloat(i.substring(0,i.length-1))])}}}}static fromAxisAngle(...t){let n=(0,e.isFixedTypeArray)(t,e.isValidNumber,4)?new d(t[0],t[1],t[2]):d.resolve(t[0]),r=(0,e.isFixedTypeArray)(t,e.isValidNumber,4)?t[3]:t[1],i=d.resolve(n),a=r*.5,o=Math.sin(a),s=Math.cos(a),c=o/Math.sqrt(i.x*i.x+i.y*i.y+i.z*i.z);return new this(s,i.x*c,i.y*c,i.z*c)}static fromEuler(...e){let n=d.resolveArgs(e),r=n.x*.5,i=n.y*.5,a=n.z*.5,o=Math.cos(r),s=Math.cos(i),c=Math.cos(a),l=Math.sin(r),u=Math.sin(i),f=Math.sin(a);return new t(o*s*c-l*u*f,l*s*c-u*f*o,u*o*c-l*f*s,l*u*c+f*o*s)}static get zero(){return new t(0,0,0,0)}constructor(t,n,r,i){(0,e.checkValidNumber)(t),(0,e.checkValidNumber)(n),(0,e.checkValidNumber)(r),(0,e.checkValidNumber)(i),this.w=t,this.x=n,this.y=r,this.z=i}toArray(){return[this.w,this.x,this.y,this.z]}toString(){return`${this.w} + ${this.x}i + ${this.y}j + ${this.z}k`}get[Symbol.toStringTag](){return`Quaternion`}[e.NodeJSCustomInspect](){return`Quaternion <${this.toString()}>`}toJSON(){return{w:this.w,x:this.x,y:this.y,z:this.z}}clone(){return new t(this.w,this.x,this.y,this.z)}add(...e){let n=t.resolveArgs(e);return new t(this.w+n.w,this.x+n.x,this.y+n.y,this.z+n.z)}offset(...e){let n=t.resolveArgs(e);return this.w+=n.w,this.x+=n.x,this.y+=n.y,this.z+=n.z,this}subtract(...e){let n=t.resolveArgs(e);return new t(this.w-n.w,this.x-n.x,this.y-n.y,this.z-n.z)}negative(){return new t(-this.w,-this.x,-this.y,-this.z)}length(e=!0){let t=this.w*this.w+this.x*this.x+this.y*this.y+this.z*this.z;return e?Math.sqrt(t):t}normalize(){let e=this.length();return e<o?t.zero:(e=1/e,new t(this.w*e,this.x*e,this.y*e,this.z*e))}multiply(...e){let n=t.resolveArgs(e);return new t(this.w*n.w-this.x*n.x-this.y*n.y-this.z*n.z,this.w*n.x+this.x*n.w+this.y*n.z-this.z*n.y,this.w*n.y+this.y*n.w+this.z*n.x-this.x*n.z,this.w*n.z+this.z*n.w+this.x*n.y-this.y*n.x)}multiplyVector(...e){let t=d.resolveArgs(e),n=this.w*t.x+this.y*t.y-this.z*t.y,r=this.w*t.y+this.z*t.x-this.x*t.z,i=this.w*t.z+this.x*t.y-this.y*t.x,a=-this.w*t.x-this.y*t.y-this.z*t.z;return new d(n*this.w+a*-this.x+r*-this.z-i*-this.y,r*this.w+a*-this.y+i*-this.x-n*-this.z,i*this.w+a*-this.z+n*-this.y-r*-this.x)}scale(e){return new t(this.w*e,this.x*e,this.y*e,this.z*e)}dot(...e){let n=t.resolveArgs(e);return this.w*n.w+this.x*n.x+this.y*n.y+this.z*n.z}inverse(){let e=this.length(!1);return e==0?t.zero:(e=1/e,new t(this.w*e,-this.x*e,-this.y*e,-this.z*e))}divide(...e){let n=t.resolveArgs(e),r=n.length(!1);return r==0?t.zero:(r=1/r,new t((this.w*n.w+this.x*n.x+this.y*n.y+this.z*n.z)*r,(this.x*n.w-this.w*n.x-this.y*n.z+this.z*n.y)*r,(this.y*n.w-this.w*n.y-this.z*n.x+this.x*n.z)*r,(this.z*n.w-this.w*n.z-this.x*n.y+this.y*n.x)*r))}conjugate(){return new t(this.w,-this.x,-this.y,-this.z)}exp(){let e=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z),n=Math.exp(this.w),r=n*Math.sin(e)/e;return e==0?new t(n,0,0,0):new t(n*Math.cos(e),this.x*r,this.y*r,this.z*r)}log(){if(this.x==0&&this.z==0)return new t(a(this.w,this.x),Math.atan2(this.x,this.w),0,0);let e=this.length(!1),n=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z),r=Math.atan2(n,this.w)/e;return new t(Math.log(e)*.5,this.x*r,this.y*r,this.z*r)}toVec3(){return[this.x,this.y,this.z,this.w]}toAxisAngle(){let e=1-this.w*this.w;if(e>o)return new d(this.x,this.y,this.z,0);let t=1/Math.sqrt(e),n=2*Math.acos(this.w);return new d(this.x*t,this.y*t,this.z*t,n)}toEuler(){function e(e){return e>=1?Math.PI/2:e<=-1?-Math.PI/2:Math.asin(e)}return new d(-Math.atan2(2*(this.y*this.z-this.w*this.x),1-2*(this.x*this.x+this.y*this.y)),e(2*(this.x*this.z+this.w*this.y)),-Math.atan2(2*(this.x*this.y-this.w*this.z),1-2*(this.y*this.y+this.z*this.z)))}toMat3(){return[1-2*(this.y*this.y+this.z*this.z),2*(this.x*this.y-this.w*this.z),2*(this.x*this.z+this.w*this.y),2*(this.x*this.y+this.w*this.z),1-2*(this.x*this.x+this.z*this.z),2*(this.y*this.z-this.w*this.x),2*(this.x*this.z-this.w*this.y),2*(this.y*this.z+this.w*this.x),1-2*(this.x*this.x+this.y*this.y)]}toMat4(){return[1-2*(this.y*this.y+this.z*this.z),2*(this.x*this.y-this.w*this.z),2*(this.x*this.z+this.w*this.y),0,2*(this.x*this.y+this.w*this.z),1-2*(this.x*this.x+this.z*this.z),2*(this.y*this.z-this.w*this.x),0,2*(this.x*this.z-this.w*this.y),2*(this.y*this.z+this.w*this.x),1-2*(this.x*this.x+this.y*this.y),0,0,0,0,1]}};function p(e){let t=e<4096,n=t?e&15:e&255,r=t?(e&240)>>>4:(e&65280)>>>8;return[(t?(e&3840)>>>8:(e&16711680)>>>16)/255,r/255,n/255]}function m(e){let t=e<65536,n=t?e&15:e&255,r=t?(e&240)>>>4:(e&65280)>>>8,i=t?(e&3840)>>>8:(e&16711680)>>>16;return[(t?(e&61440)>>>12:(e&4278190080)>>>24)/255,i/255,r/255,n/255]}function h(e){return e=e.trim(),[`$`,`#`].includes(e[0]??``)||e.startsWith(`0x`)}function g(e){return e=e.trim(),[`$`,`#`].includes(e[0]??``)?e.substring(1):e.startsWith(`0x`)?e.substring(2):e}function _(e){let t=g(e);return[4,8].includes(t.length)}function v(e){let t=g(e),n=t.length===3,r=parseInt(n?t[0]:t.substring(0,2),16),i=parseInt(n?t[1]:t.substring(2,4),16),a=parseInt(n?t[2]:t.substring(4,6),16);return[r/255,i/255,a/255]}function y(e){let t=g(e),n=t.length===4,r=parseInt(n?t[0]:t.substring(0,2),16),i=parseInt(n?t[1]:t.substring(2,4),16),a=parseInt(n?t[2]:t.substring(4,6),16),o=parseInt(n?t[3]:t.substring(6,8),16);return[r/255,i/255,a/255,o/255]}var b=class t{_red;get red(){return this._red}set red(e){this._red=i(e,0,1)}_green;get green(){return this._green}set green(e){this._green=i(e,0,1)}_blue;get blue(){return this._blue}set blue(e){this._blue=i(e,0,1)}_alpha;get alpha(){return this._alpha}set alpha(e){this._alpha=i(e,0,1)}static resolve(e){let t=this.cast(e);if(t!==void 0)return t;throw new r(`RGBAColor`,e)}static resolveArgs(t){return(0,e.isFixedTypeArray)(t,e.isValidNumber,3)||(0,e.isFixedTypeArray)(t,e.isValidNumber,4)?new this(t[0],t[1],t[2],t[3]):this.resolve(t[0])}static cast(t){if(!(t==null||t===void 0)){if((0,e.isFixedTypeArray)(t,e.isValidNumber,3)||(0,e.isFixedTypeArray)(t,e.isValidNumber,4))return new this(t[0],t[1],t[2],t[3]);if((0,e.hasTypedProperty)(t,`toRGB`,`function`))return this.cast(t.toRGB());if((0,e.hasTypedProperty)(t,`toRGBA`,`function`))return this.cast(t.toRGBA());if((0,e.hasTypedProperty)(t,`red`,`number`)&&(0,e.hasTypedProperty)(t,`green`,`number`)&&(0,e.hasTypedProperty)(t,`blue`,`number`))return new this(t.red,t.green,t.blue,(0,e.hasTypedProperty)(t,`alpha`,`number`)?t.alpha:void 0);if((0,e.isValidNumber)(t)){let e=t.toString(16).length<=6?p:m;return this.cast(e(t))}if((0,e.isValidString)(t)){if(t.startsWith(`rgb`)){let n=t.startsWith(`rgba`),r=n?5:4,i=t.substring(r,t.indexOf(`)`,r)).split(`,`);if((0,e.isFixedTypeArray)(i,e.isValidString,n?4:3))return this.cast(i.map(e=>parseInt(e)/255))}if(h(t)){let e=_(t)?y:v;return this.cast(e(t))}}}}static is(e){return this.cast(e)!==void 0}constructor(t,n,r,a=1){(0,e.checkValidNumber)(t),(0,e.checkValidNumber)(n),(0,e.checkValidNumber)(r),(0,e.checkValidNumber)(a),this._red=i(t,0,1),this._green=i(n,0,1),this._blue=i(r,0,1),this._alpha=i(a,0,1)}toArray(e=this._alpha!==1){return e?[this.red,this.green,this.blue,this.alpha]:[this.red,this.green,this.blue]}toJSON(e=this._alpha!==1){return e?{red:this.red,green:this.green,blue:this.blue,alpha:this.alpha}:{red:this.red,green:this.green,blue:this.blue}}toString(e=this._alpha!==1){return e?`rgba(${i(this.red*255|0,0,255)},${i(this.green*255|0,0,255)},${i(this.blue*255|0,0,255)},${this.alpha})`:`rgb(${i(this.red*255|0,0,255)},${i(this.green*255|0,0,255)},${i(this.blue*255|0,0,255)})`}get[Symbol.toStringTag](){return`RGBA`}[e.NodeJSCustomInspect](){return`RGBA <${this.toString()}>`}toVec2(){return[this.red,this.green,this.blue]}toVec3(){return[this.red,this.green,this.blue,this.alpha]}toHSL(e=this._alpha!==1){let t=this.red,n=this.green,r=this.blue,i=Math.min(t,n,r),a=Math.max(t,n,r),o=(i+a)/2;if(i==a)return new x(0,0,o,e?this.alpha:void 0);let s=a-i,c=o>.5?s/(2-a-i):s/(a+i);return a==t?new x(((n-r)/s+(n<r?6:0))/6,c,o,e?this.alpha:void 0):a==n?new x(((r-t)/s+2)/6,c,o,e?this.alpha:void 0):a==r?new x(((t-n)/s+4)/6,c,o,e?this.alpha:void 0):new x(0,c,o,e?this.alpha:void 0)}toHSLA(){return this.toHSL(!0)}invert(e=this._alpha!==1){return new t(1-this.red,1-this.green,1-this.blue,e?1-this.alpha:this.alpha)}},x=class t{_hue;get hue(){return this._hue}set hue(e){this._hue=i(e,0,1)}_saturation;get saturation(){return this._saturation}set saturation(e){this._saturation=i(e,0,1)}_luminace;get luminace(){return this._luminace}set luminace(e){this._luminace=i(e,0,1)}_alpha;get alpha(){return this._alpha}set alpha(e){this._alpha=i(e,0,1)}static resolve(e){let t=this.cast(e);if(t!==void 0)return t;throw new r(`HSLColor`,e)}static resolveArgs(t){return(0,e.isFixedTypeArray)(t,e.isValidNumber,3)||(0,e.isFixedTypeArray)(t,e.isValidNumber,4)?new this(t[0],t[1],t[2],t[3]):this.resolve(t[0])}static cast(t){if(!(t==null||t===void 0)){if((0,e.isFixedTypeArray)(t,e.isValidNumber,3)||(0,e.isFixedTypeArray)(t,e.isValidNumber,4))return new this(t[0],t[1],t[2],t[3]);if((0,e.hasTypedProperty)(t,`toHSL`,`function`))return this.cast(t.toHSL());if((0,e.hasTypedProperty)(t,`toHSLA`,`function`))return this.cast(t.toHSLA());if((0,e.hasTypedProperty)(t,`hue`,`number`)&&(0,e.hasTypedProperty)(t,`saturation`,`number`)&&(0,e.hasTypedProperty)(t,`luminace`,`number`))return new this(t.hue,t.saturation,t.luminace,(0,e.hasTypedProperty)(t,`alpha`,`number`)?t.alpha:void 0);if((0,e.isValidNumber)(t)){let e=t.toString(16).length<=6?p:m;return this.cast(e(t))}if((0,e.isValidString)(t)){if(t.startsWith(`hsl`)){let n=t.startsWith(`hsla`),r=n?5:4,i=t.substring(r,t.indexOf(`)`,r)).split(`,`);if((0,e.isFixedTypeArray)(i,e.isValidString,n?4:3))return this.cast(i.map(e=>parseInt(e)/255))}if(h(t)){let e=_(t)?y:v;return this.cast(e(t))}}}}static is(e){return this.cast(e)!==void 0}constructor(t,n,r,a=1){(0,e.checkValidNumber)(t),(0,e.checkValidNumber)(n),(0,e.checkValidNumber)(r),(0,e.checkValidNumber)(a),this._hue=i(t,0,1),this._saturation=i(n,0,1),this._luminace=i(r,0,1),this._alpha=i(a,0,1)}toArray(e=this._alpha!==1){return e?[this.hue,this.saturation,this.luminace,this.alpha]:[this.hue,this.saturation,this.luminace]}toJSON(e=this._alpha!==1){return e?{hue:this.hue,saturation:this.saturation,luminace:this.luminace,alpha:this.alpha}:{hue:this.hue,saturation:this.saturation,luminace:this.luminace}}toString(e=this._alpha!==1){return e?`hsla(${i(this.hue*255|0,0,255)},${i(this.saturation*255|0,0,255)},${i(this.luminace*255|0,0,255)},${this.alpha})`:`hsl(${i(this.hue*255|0,0,255)},${i(this.saturation*255|0,0,255)},${i(this.luminace*255|0,0,255)})`}get[Symbol.toStringTag](){return`HSLA`}[e.NodeJSCustomInspect](){return`HSLA <${this.toString()}>`}toRGB(e=this._alpha!==1){if(this.saturation==0)return new b(this.luminace*255,this.luminace*255,this.luminace*255,e?this.alpha:void 0);let t=this.luminace<.5?this.luminace*(1+this.saturation):this.luminace+this.saturation-this.luminace*this.saturation,n=2*this.luminace-t;function r(e){let r=e;return r<0&&r++,r>1&&r--,r<1/6?n+(t-n)*6*r:r<1/2?t:r<2/3?n+(t-n)*(2/3-r)*6:n}return new b(r(this.hue+1/3)*255,r(this.hue)*255,r(this.hue-1/3)*255,e?this.alpha:void 0)}toRGBA(){return this.toRGB(!0)}toVec2(){return[this.hue,this.saturation,this.luminace]}toVec3(){return[this.hue,this.saturation,this.luminace,this.alpha]}invert(e=this._alpha!==1){return new t(1-this.hue,1-this.saturation,1-this.luminace,e?1-this.alpha:this.alpha)}};const S=5381n;function C(e){let t=String(e),n=S;for(let e=0;e<t.length;e++)n=(n<<5n)+n+BigInt(t.charCodeAt(e));return n}const w=14695981039346656037n,T=1099511628211n;function E(e){let t=String(e),n=w;for(let e=0;e<t.length;e++)n*=T,n^=BigInt(t.charCodeAt(e));return n}function D(e){let t=String(e),n=0n;for(let e=0;e<t.length;e++)n=BigInt(t.charCodeAt(e))+(n<<6n)+(n<<16n)-n;return n}const O=e=>e%360,k=e=>O(j(e)),A=e=>e*(180/Math.PI),j=e=>e*(Math.PI/180);var M=class t{radius;get perimeter(){return this.radius*Math.PI*2}get area(){return Math.PI*this.radius**2}position;get x(){return this.position.x}set x(e){this.position.x=e}get y(){return this.position.y}set y(e){this.position.y=e}get w(){return this.position.w}set w(e){this.position.w=e}static resolve(e){let t=this.cast(e);if(t!==void 0)return t;throw new r(`Circle`,e)}static resolveArgs(t){return(0,e.isFixedTypeArray)(t,e.isValidNumber,3)?new this([t[0],t[1]],t[2]):t.length===2?new this(t[0],t[1]):this.resolve(t[0])}static cast(t){if(!(t==null||t===void 0)){if((0,e.isFixedTypeArray)(t,e.isValidNumber,3))return new this([t[0],t[1]],t[2]);if((0,e.isFixedTypeArray)(t,e.isValidNumber,4)){let e=new this([t[0],t[1]],t[3]);return e.w=t[2],e}if((0,e.hasTypedProperty)(t,`toCircle`,`function`))return this.cast(t.toCircle());if((0,e.hasTypedProperty)(t,`x`,`number`)&&(0,e.hasTypedProperty)(t,`y`,`number`)&&(0,e.hasTypedProperty)(t,`radius`,`number`))return new this((0,e.hasTypedProperty)(t,`w`,`number`)?[t.x,t.y,t.w]:[t.x,t.y],t.radius);if((0,e.isValidString)(t)){let[e,n]=t.split(`|`),r=c.cast(e);if(r===void 0||n===void 0)return;let i=parseFloat(n);if(!isNaN(i))return new this(r,i)}}}static is(e){return this.cast(e)!==void 0}constructor(t,n){(0,e.checkValidNumber)(n),this.position=c.resolve(t),this.radius=n}toArray(){return[...this.position.toArray(),this.radius]}toJSON(){return{...this.position.toJSON(),radius:this.radius}}toString(){return`${this.position.toString()}|${this.radius}`}get[Symbol.toStringTag](){return`Circle`}[e.NodeJSCustomInspect](){return`Circle <${this.toString()}>`}clone(){return new t(this.position.clone(),this.radius)}toVec2(){return[this.x,this.y,this.w]}equals(...e){let n=t.resolveArgs(e);return n.position.equals(n.position)&&this.radius==n.radius}inside(...e){let n=t.resolveArgs(e),r=n.x-this.x,i=n.y-this.y;return Math.sqrt(r*r+(i+i))<=this.radius+n.radius}insidePoint(...e){return this.position.distance(c.resolveArgs(e))<=this.radius}},N=class t{left;right;top;bottom;get width(){return this.right-this.left}set width(e){this.right=this.left+e}get height(){return this.bottom-this.top}set height(e){this.bottom=this.top+e}get x(){return this.left}set x(e){this.left=e}get y(){return this.top}set y(e){this.top=e}w=1;static resolve(e){let t=this.cast(e);if(t!==void 0)return t;throw new r(`BoundingBox`,e)}static resolveArgs(t){return(0,e.isFixedTypeArray)(t,e.isValidNumber,4)?new this(t[0],t[1],t[2],t[3]):this.resolve(t[0])}static cast(t){if(!(t==null||t===void 0)){if((0,e.isFixedTypeArray)(t,e.isValidNumber,4))return new this(t[0],t[1],t[2],t[3]);if((0,e.hasTypedProperty)(t,`toBoundingBox`,`function`))return this.cast(t.toBoundingBox());if((0,e.hasTypedProperty)(t,`left`,`number`)&&(0,e.hasTypedProperty)(t,`right`,`number`)&&(0,e.hasTypedProperty)(t,`top`,`number`)&&(0,e.hasTypedProperty)(t,`bottom`,`number`))return new this(t.left,t.right,t.top,t.bottom);if((0,e.isValidString)(t)){let n=t.split(`,`);if((0,e.isFixedTypeArray)(n,e.isValidString,4))return this.cast(n.map(e=>parseFloat(e)))}}}static is(e){return this.cast(e)!==void 0}constructor(t,n,r,i){(0,e.checkValidNumber)(t),(0,e.checkValidNumber)(n),(0,e.checkValidNumber)(r),(0,e.checkValidNumber)(i),this.left=t,this.right=n,this.top=r,this.bottom=i}toArray(){return[this.left,this.right,this.top,this.bottom]}toString(){return`${this.left},${this.right},${this.top},${this.bottom}`}get[Symbol.toStringTag](){return`BoundingBox`}[e.NodeJSCustomInspect](){return`BoundingBox <${this.toString()}>`}toJSON(){return{left:this.left,top:this.top,right:this.right,bottom:this.bottom}}clone(){return new t(this.left,this.right,this.top,this.bottom)}equals(...e){let n=t.resolveArgs(e);return this.left===n.left&&this.right===n.right&&this.top===n.top&&this.bottom===n.bottom}toSize(){return[this.width,this.height]}toVec2(){return[this.left,this.top]}toRectangle(){return[this.left,this.top,this.width,this.height]}inside(...e){let n=t.resolve(e);return this.right>=n.left&&n.right>=this.left&&this.bottom>=n.top&&n.bottom>=this.top}insidePoint(...e){let t=c.resolveArgs(e);return this.left<=t.x&&this.right>=t.x&&this.top<=t.y&&this.bottom>=t.y}insideCircle(...e){let t=M.resolveArgs(e),n=c.resolve(t).add(t.radius),r=new c(this.width/2,this.height/2),i=new c(this.left+r.x,this.top+r.y),a=n.subtract(i),o=c.clamp(a,r.invert(),r);return a=i.add(o).subtract(n),a.length()<t.radius}},P=class t{width;height;get aspectRatio(){return this.height/this.width}get area(){return this.width*this.height}get perimeter(){return this.width+this.width+this.height+this.height}static resolve(e){let t=this.cast(e);if(t!==void 0)return t;throw new r(`Square`,e)}static resolveArgs(t){return(0,e.isFixedTypeArray)(t,e.isValidNumber,2)?new this(t[0],t[1]):this.resolve(t[0])}static cast(t){if(!(t==null||t===void 0)){if((0,e.isFixedTypeArray)(t,e.isValidNumber,2))return new this(t[0],t[1]);if((0,e.hasTypedProperty)(t,`toSize`,`function`))return this.cast(t.toSize());if((0,e.hasTypedProperty)(t,`width`,`number`)&&(0,e.hasTypedProperty)(t,`height`,`number`))return new this(t.width,t.height);if((0,e.isValidString)(t)){let n=t.split(`x`).map(e=>parseFloat(e));if((0,e.isFixedTypeArray)(n,e.isValidNumber,2))return this.cast(n)}if((0,e.isValidNumber)(t))return new this(t,t)}}static is(e){return this.cast(e)!==void 0}constructor(t,n){(0,e.checkValidNumber)(t),(0,e.checkValidNumber)(n),this.width=t,this.height=n}toArray(){return[this.width,this.height]}toString(){return`${this.width}x${this.height}`}get[Symbol.toStringTag](){return`Size`}[e.NodeJSCustomInspect](){return`Size <${this.toString()}>`}toJSON(){return{width:this.width,height:this.height}}clone(){return new t(this.width,this.height)}equals(...e){let n=t.resolveArgs(e);return this.width==n.width&&this.height==n.height}toVec2(){return[this.width,this.height]}},F=class t{position;size;get area(){return this.width*this.height}get perimeter(){return this.width+this.width+this.height+this.height}get x(){return this.position.x}set x(e){this.position.x=e}get y(){return this.position.y}set y(e){this.position.y=e}get w(){return this.position.w}set w(e){this.position.w=e}get width(){return this.size.width}set width(e){this.size.width=e}get height(){return this.size.height}set height(e){this.size.height=e}static resolve(e){let t=this.cast(e);if(t!==void 0)return t;throw new r(`Rectangle`,e)}static resolveArgs(t){return(0,e.isFixedTypeArray)(t,e.isValidNumber,4)?new this([t[0],t[1]],[t[2],t[3]]):this.resolve(t[0])}static cast(t){if(!(t==null||t===void 0)){if((0,e.isFixedTypeArray)(t,e.isValidNumber,4))return new this([t[0],t[1]],[t[2],t[3]]);if((0,e.isFixedTypeArray)(t,e.isValidNumber,5)){let e=new this([t[0],t[1]],[t[3],t[4]]);return e.w=t[2],e}if((0,e.isValidString)(t)){let[e,n]=t.split(`|`),r=c.cast(e),i=P.cast(n);if(r===void 0||i===void 0)return;let a=new this([r.x,r.y],[i.width,i.height]);return a.w=r.w,a}if((0,e.hasTypedProperty)(t,`toRectangle`,`function`))return this.cast(t.toRectangle());if((0,e.hasTypedProperty)(t,`x`,`number`)&&(0,e.hasTypedProperty)(t,`y`,`number`)&&(0,e.hasTypedProperty)(t,`width`,`number`)&&(0,e.hasTypedProperty)(t,`height`,`number`)){let n=new this([t.x,t.y],[t.width,t.height]);return(0,e.hasTypedProperty)(t,`w`,`number`)&&(n.w=t.w),n}}}static is(e){return this.cast(e)!==void 0}constructor(e,t){this.position=c.resolve(e),this.size=P.resolve(t)}toArray(e=this.w!==1){return[...this.position.toArray(e),...this.size.toArray()]}toString(e=this.w!==1){return`${this.position.toString(e)}|${this.size.toString()}`}get[Symbol.toStringTag](){return`Rectangle`}[e.NodeJSCustomInspect](){return`Rectangle <${this.toString()}>`}toJSON(){return{...this.position.toJSON(),...this.size.toJSON()}}toBoundingBox(){return[this.x,this.x+this.width,this.y,this.y+this.height]}toVec2(){return[this.x,this.y,this.w]}toSize(){return[this.width,this.height]}clone(){return new t(this.position.clone(),this.size.clone())}equals(...e){let n=t.resolveArgs(e);return this.position.equals(n.position)&&this.size.equals(n.size)}},I=class{constructor(e,t,n){this.A=e,this.B=t,this.C=n}get alpha(){return Math.acos((this.b*this.b+this.c*this.c-this.a*this.a)/(2*this.b*this.c))}get beta(){return Math.acos((this.c*this.c+this.a*this.a-this.b*this.b)/(2*this.c*this.a))}get gamma(){return Math.acos((this.a*this.a+this.b*this.b-this.c*this.c)/(2*this.a*this.b))}get perimeter(){return this.a+this.b+this.c}get semiperimeter(){return this.perimeter/2}get area(){return Math.sqrt(this.semiperimeter*(this.semiperimeter-this.a)*(this.semiperimeter-this.b)*(this.semiperimeter-this.c))}get base(){return 2*(this.area/(this.a*Math.sin(this.gamma)))}get height(){return 2*(this.area/this.base)}toString(){return`${this.A}|${this.B}|${this.C}`}get[Symbol.toStringTag](){return`Triangle`}[e.NodeJSCustomInspect](){return`Triangle <${this.toString()}>`}},L=class extends I{get a(){return c.fromPoints(this.B,this.C).length()}get b(){return c.fromPoints(this.A,this.C).length()}get c(){return c.fromPoints(this.A,this.B).length()}},R=class extends I{get a(){return d.fromPoints(this.B,this.C).length()}get b(){return d.fromPoints(this.A,this.C).length()}get c(){return d.fromPoints(this.A,this.B).length()}},z=class t{_raw;get m00(){return this._raw[0]}set m00(e){this._raw[0]=e}get m01(){return this._raw[1]}set m01(e){this._raw[1]=e}get m02(){return this._raw[2]}set m02(e){this._raw[2]=e}get m10(){return this._raw[3]}set m10(e){this._raw[3]=e}get m11(){return this._raw[4]}set m11(e){this._raw[4]=e}get m12(){return this._raw[5]}set m12(e){this._raw[5]=e}get m20(){return this._raw[6]}set m20(e){this._raw[6]=e}get m21(){return this._raw[7]}set m21(e){this._raw[7]=e}get m22(){return this._raw[8]}set m22(e){this._raw[8]=e}static resolve(e){let t=this.cast(e);if(t!==void 0)return t;throw new r(`Mat3`,e)}static resolveArgs(t){return(0,e.isFixedTypeArray)(t,e.isValidNumber,9)?new this(t):this.resolve(t[0])}static cast(t){if(!(t==null||t===void 0)){if((0,e.isFixedTypeArray)(t,e.isValidNumber,9))return new this(t);if((0,e.isFixedArray)(t,3)){let n=t[0],r=t[1],i=t[2];if((0,e.isFixedTypeArray)(n,e.isValidNumber,3)&&(0,e.isFixedTypeArray)(r,e.isValidNumber,3)&&(0,e.isFixedTypeArray)(i,e.isValidNumber,3))return new this([n[0],n[1],n[2],r[0],r[1],r[2],i[0],i[1],i[2]])}if((0,e.isValidString)(t)){let n=t.split(`,`);if((0,e.isFixedTypeArray)(n,e.isValidString,9))return this.cast(n.map(e=>parseFloat(e)))}if((0,e.hasTypedProperty)(t,`toMat3`,`function`))return this.cast(t.toMat3());if((0,e.hasTypedProperty)(t,`m00`,`number`)&&(0,e.hasTypedProperty)(t,`m01`,`number`)&&(0,e.hasTypedProperty)(t,`m02`,`number`)&&(0,e.hasTypedProperty)(t,`m10`,`number`)&&(0,e.hasTypedProperty)(t,`m11`,`number`)&&(0,e.hasTypedProperty)(t,`m12`,`number`)&&(0,e.hasTypedProperty)(t,`m20`,`number`)&&(0,e.hasTypedProperty)(t,`m21`,`number`)&&(0,e.hasTypedProperty)(t,`m22`,`number`))return new this([t.m00,t.m01,t.m02,t.m10,t.m11,t.m12,t.m20,t.m21,t.m22]);if((0,e.isValidNumber)(t))return new this([t,t,t,t,t,t,t,t,t])}}static is(e){return this.cast(e)!==void 0}static projection(e,t){return new this([2/e,0,0,0,-2/t,0,-1,1,1])}constructor(t=[1,0,0,0,1,0,0,0,1]){(0,e.checkFixedTypeArray)(t,e.isValidNumber,9),this._raw=t}toArray(){return[this.m00,this.m01,this.m02,this.m10,this.m11,this.m12,this.m20,this.m21,this.m22]}toNestetArray(){return[[this.m00,this.m01,this.m02],[this.m10,this.m11,this.m12],[this.m20,this.m21,this.m22]]}toJSON(){return{m00:this.m00,m01:this.m01,m02:this.m02,m10:this.m10,m11:this.m11,m12:this.m12,m20:this.m20,m21:this.m21,m22:this.m22}}toString(){return`${this.m00},${this.m01},${this.m02},${this.m10},${this.m11},${this.m12},${this.m20},${this.m21},${this.m22}`}get[Symbol.toStringTag](){return`Mat3`}[e.NodeJSCustomInspect](){return`Mat3 <${this.toString()}>`}clone(){return new t([this.m00,this.m01,this.m02,this.m10,this.m11,this.m12,this.m20,this.m21,this.m22])}equals(...e){let n=t.resolveArgs(e);for(let e=0;e<this._raw.length;e++)if(this._raw[e]!=n._raw[e])return!1;return!0}add(...e){let n=t.resolveArgs(e),r=new t;for(let e=0;e<this._raw.length;e++)r._raw[e]=this._raw[e]+n._raw[e];return r}subtract(...e){let n=t.resolveArgs(e),r=new t;for(let e=0;e<this._raw.length;e++)r._raw[e]=this._raw[e]-n._raw[e];return r}multiply(...n){if((0,e.isFixedTypeArray)(n,e.isValidNumber,1))return new t([this.m00*n[0],this.m01*n[0],this.m02*n[0],this.m10*n[0],this.m11*n[0],this.m12*n[0],this.m20*n[0],this.m21*n[0],this.m22*n[0]]);let r=t.resolveArgs(n);return new t([r.m00*this.m00+r.m01*this.m10+r.m02*this.m20,r.m00*this.m01+r.m01*this.m11+r.m02*this.m21,r.m00*this.m02+r.m01*this.m12+r.m02*this.m22,r.m10*this.m00+r.m11*this.m10+r.m12*this.m20,r.m10*this.m01+r.m11*this.m11+r.m12*this.m21,r.m10*this.m02+r.m11*this.m12+r.m12*this.m22,r.m20*this.m00+r.m21*this.m10+r.m22*this.m20,r.m20*this.m01+r.m21*this.m11+r.m22*this.m21,r.m20*this.m02+r.m21*this.m12+r.m22*this.m22])}translate(...e){let t=c.resolveArgs(e);return this.multiply([1,0,0,0,1,0,t.x,t.y,1])}rotate(e){let t=Math.cos(e),n=Math.sin(e);return this.multiply([t,-n,0,n,t,0,0,0,1])}scale(...e){let t=c.resolve(e);return this.multiply([t.x,0,0,0,t.y,0,0,0,1])}determinant(){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}inverse(){let e=this.determinant();return new t([(this.m11*this.m22-this.m21*this.m12)*e,(this.m02*this.m21-this.m01*this.m22)*e,(this.m01*this.m12-this.m02*this.m11)*e,(this.m12*this.m20-this.m10*this.m22)*e,(this.m00*this.m22-this.m02*this.m20)*e,(this.m10*this.m02-this.m00*this.m12)*e,(this.m10*this.m21-this.m20*this.m11)*e,(this.m20*this.m01-this.m00*this.m21)*e,(this.m00*this.m11-this.m10*this.m01)*e])}toMat4(){return[this.m00,this.m01,this.m02,0,this.m10,this.m11,this.m12,0,this.m20,this.m20,this.m22,0,0,0,0,1]}},B=class t{_raw;get m00(){return this._raw[0]}set m00(e){this._raw[0]=e}get m01(){return this._raw[1]}set m01(e){this._raw[1]=e}get m02(){return this._raw[2]}set m02(e){this._raw[2]=e}get m03(){return this._raw[3]}set m03(e){this._raw[3]=e}get m10(){return this._raw[4]}set m10(e){this._raw[4]=e}get m11(){return this._raw[5]}set m11(e){this._raw[5]=e}get m12(){return this._raw[6]}set m12(e){this._raw[6]=e}get m13(){return this._raw[7]}set m13(e){this._raw[7]=e}get m20(){return this._raw[8]}set m20(e){this._raw[8]=e}get m21(){return this._raw[9]}set m21(e){this._raw[9]=e}get m22(){return this._raw[10]}set m22(e){this._raw[10]=e}get m23(){return this._raw[11]}set m23(e){this._raw[11]=e}get m30(){return this._raw[12]}set m30(e){this._raw[12]=e}get m31(){return this._raw[13]}set m31(e){this._raw[13]=e}get m32(){return this._raw[14]}set m32(e){this._raw[14]=e}get m33(){return this._raw[15]}set m33(e){this._raw[15]=e}static resolve(e){let t=this.cast(e);if(t!==void 0)return t;throw new r(`Mat4`,e)}static resolveArgs(t){return(0,e.isFixedTypeArray)(t,e.isValidNumber,16)?new this(t):this.resolve(t[0])}static cast(t){if(!(t==null||t===void 0)){if((0,e.isFixedTypeArray)(t,e.isValidNumber,16))return new this(t);if((0,e.isFixedArray)(t,4)){let n=t[0],r=t[1],i=t[2],a=t[3];if((0,e.isFixedTypeArray)(n,e.isValidNumber,4)&&(0,e.isFixedTypeArray)(r,e.isValidNumber,4)&&(0,e.isFixedTypeArray)(i,e.isValidNumber,4)&&(0,e.isFixedTypeArray)(a,e.isValidNumber,4))return new this([n[0],n[1],n[2],n[3],r[0],r[1],r[2],r[3],i[0],i[1],i[2],i[3],a[0],a[1],a[2],a[3]])}if((0,e.isValidString)(t)){let n=t.split(`,`);if((0,e.isFixedTypeArray)(n,e.isValidString,16))return this.cast(n.map(e=>parseFloat(e)))}if((0,e.hasTypedProperty)(t,`toMat4`,`function`))return this.cast(t.toMat4());if((0,e.hasTypedProperty)(t,`m00`,`number`)&&(0,e.hasTypedProperty)(t,`m01`,`number`)&&(0,e.hasTypedProperty)(t,`m02`,`number`)&&(0,e.hasTypedProperty)(t,`m03`,`number`)&&(0,e.hasTypedProperty)(t,`m10`,`number`)&&(0,e.hasTypedProperty)(t,`m11`,`number`)&&(0,e.hasTypedProperty)(t,`m12`,`number`)&&(0,e.hasTypedProperty)(t,`m13`,`number`)&&(0,e.hasTypedProperty)(t,`m20`,`number`)&&(0,e.hasTypedProperty)(t,`m21`,`number`)&&(0,e.hasTypedProperty)(t,`m22`,`number`)&&(0,e.hasTypedProperty)(t,`m23`,`number`)&&(0,e.hasTypedProperty)(t,`m30`,`number`)&&(0,e.hasTypedProperty)(t,`m31`,`number`)&&(0,e.hasTypedProperty)(t,`m32`,`number`)&&(0,e.hasTypedProperty)(t,`m33`,`number`))return new this([t.m00,t.m01,t.m02,t.m03,t.m10,t.m11,t.m12,t.m13,t.m20,t.m21,t.m22,t.m23,t.m30,t.m31,t.m32,t.m33]);if((0,e.isValidNumber)(t))return new this([t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t])}}static is(e){return this.cast(e)!==void 0}static orthographic(...t){let n=(0,e.isFixedTypeArray)(t,e.isValidNumber,6)?new N(t[0],t[1],t[2],t[3]):N.resolve(t[0]),r=(0,e.isFixedTypeArray)(t,e.isValidNumber,6)?t[4]:t[1],i=(0,e.isFixedTypeArray)(t,e.isValidNumber,6)?t[5]:t[2];return new this([2/(n.right-n.left),0,0,0,0,2/(n.top-n.bottom),0,0,0,0,2/(r-i),0,(n.left+n.right)/(n.left-n.right),(n.bottom+n.top)/(n.bottom-n.top),(r+i)/(r-i),1])}static perspective(e,t,n,r){let i=Math.tan(Math.PI*.5-.5*e),a=1/(n-r);return new this([i/t,0,0,0,0,i,0,0,0,0,(n+r)*a,-1,0,0,n*r*a*2,0])}static pointAt(e,t,n){let r=d.resolve(t).subtract(e).normalize(),i=r.multiply(d.resolve(n).dot(r)),a=d.resolve(n).subtract(i).normalize(),o=a.cross(r),s=d.resolve(e);return new this([o.x,o.y,o.z,0,a.x,a.y,a.z,0,r.x,r.y,r.z,0,s.x,s.y,s.z,1])}constructor(t=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]){(0,e.checkFixedTypeArray)(t,e.isValidNumber,16),this._raw=t}toArray(){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]}toNestetArray(){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]]}toJSON(){return{m00:this.m00,m01:this.m01,m02:this.m02,m03:this.m03,m10:this.m10,m11:this.m11,m12:this.m12,m13:this.m13,m20:this.m20,m21:this.m21,m22:this.m22,m23:this.m23,m30:this.m20,m31:this.m21,m32:this.m22,m33:this.m23}}toString(){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}`}get[Symbol.toStringTag](){return`Mat4`}[e.NodeJSCustomInspect](){return`Mat4 <${this.toString()}>`}clone(){return new t([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])}equals(...e){let n=t.resolveArgs(e);for(let e=0;e<this._raw.length;e++)if(this._raw[e]!=n._raw[e])return!1;return!0}add(...e){let n=t.resolveArgs(e),r=new t;for(let e=0;e<this._raw.length;e++)r._raw[e]=this._raw[e]+n._raw[e];return r}subtract(...e){let n=t.resolveArgs(e),r=new t;for(let e=0;e<this._raw.length;e++)r._raw[e]=this._raw[e]-n._raw[e];return r}multiply(...n){if((0,e.isFixedTypeArray)(n,e.isValidNumber,1)){let e=n[0];return new t([this.m00*e,this.m01*e,this.m02*e,this.m03*e,this.m10*e,this.m11*e,this.m12*e,this.m13*e,this.m20*e,this.m21*e,this.m22*e,this.m23*e,this.m30*e,this.m31*e,this.m32*e,this.m33*e])}let r=d.cast(n[0]);if(r!==void 0){let e=new d(r.x*this.m00+r.y*this.m10+r.z*this.m20+this.m30,r.x*this.m01+r.y*this.m11+r.z*this.m21+this.m31,r.x*this.m02+r.y*this.m12+r.z*this.m22+this.m32,r.x*this.m03+r.y*this.m13+r.z*this.m23+this.m33);return e.w==0?e:e.divide(e.w)}let i=t.resolveArgs(n);return new t([i.m00*this.m00+i.m01*this.m10+i.m02*this.m20+i.m03*this.m30,i.m00*this.m01+i.m01*this.m11+i.m02*this.m21+i.m03*this.m31,i.m00*this.m02+i.m01*this.m12+i.m02*this.m22+i.m03*this.m32,i.m00*this.m03+i.m01*this.m13+i.m02*this.m23+i.m03*this.m33,i.m10*this.m00+i.m11*this.m10+i.m12*this.m20+i.m13*this.m30,i.m10*this.m01+i.m11*this.m11+i.m12*this.m21+i.m13*this.m31,i.m10*this.m02+i.m11*this.m12+i.m12*this.m22+i.m13*this.m32,i.m10*this.m03+i.m11*this.m13+i.m12*this.m23+i.m13*this.m33,i.m20*this.m00+i.m21*this.m10+i.m22*this.m20+i.m23*this.m30,i.m20*this.m01+i.m21*this.m11+i.m22*this.m21+i.m23*this.m31,i.m20*this.m02+i.m21*this.m12+i.m22*this.m22+i.m23*this.m32,i.m20*this.m03+i.m21*this.m13+i.m22*this.m23+i.m23*this.m33,i.m30*this.m00+i.m31*this.m10+i.m32*this.m20+i.m33*this.m30,i.m30*this.m01+i.m31*this.m11+i.m32*this.m21+i.m33*this.m31,i.m30*this.m02+i.m31*this.m12+i.m32*this.m22+i.m33*this.m32,i.m30*this.m03+i.m31*this.m13+i.m32*this.m23+i.m33*this.m33])}translate(...e){let t=d.resolveArgs(e);return this.multiply([1,0,0,0,0,1,0,0,0,0,1,0,t.x,t.y,t.z,1])}rotateX(e){let t=Math.cos(e),n=Math.sin(e);return this.multiply([1,0,0,0,0,t,n,0,0,-n,t,0,0,0,0,1])}rotateY(e){let t=Math.cos(e),n=Math.sin(e);return this.multiply([t,0,-n,0,0,1,0,0,n,0,t,0,0,0,0,1])}rotateZ(e){let t=Math.cos(e),n=Math.sin(e);return this.multiply([t,n,0,0,-n,t,0,0,0,0,1,0,0,0,0,1])}rotate(...e){let t=d.resolveArgs(e);return this.rotateX(t.x).rotateY(t.y).rotateZ(t.z)}scale(...e){let t=d.resolveArgs(e);return this.multiply([t.x,0,0,0,0,t.y,0,0,0,0,t.z,0,0,0,0,1])}inverse(){return new t([this.m00,this.m10,this.m20,0,this.m01,this.m11,this.m21,0,this.m02,this.m12,this.m22,0,-(this.m30*this.m00+this.m31*this.m10+this.m32*this.m20),-(this.m30*this.m01+this.m31*this.m11+this.m32*this.m21),-(this.m30*this.m02+this.m31*this.m12+this.m32*this.m22),1])}toMat3(){return[this.m00,this.m01,this.m03,this.m10,this.m11,this.m13,this.m30,this.m31,this.m33]}};let V;(function(t){function n(e,t=!1){let n=[];try{let t=b.resolve(e);n.push(t)}catch{}try{let t=x.resolve(e);n.push(t)}catch{}let r=t?1:0,i=n[r];if(i)return i;let a=n[r+1];if(a)return a}t.cast=n;function i(e,t=!1){let i=n(e,t);if(i!==void 0)return i;throw new r(`Color`,e)}t.resolve=i;function a(t,n=!1){return(0,e.isFixedTypeArray)(t,e.isValidNumber,3)||(0,e.isFixedTypeArray)(t,e.isValidNumber,4)?i(t,n):i(t[0],n)}t.resolveArgs=a})(V||={});var H=class{origin=c.zero;localPosition;localRotation;get localRotationDegree(){return A(this.localRotation)}set localRotationDegree(e){this.localRotation=j(e)}localScale;get globalPosition(){let e=c.zero,t=this;for(;t!==void 0;)e=e.add(t.localPosition).add(t.origin),t=t.parent;return e}get globalRotation(){let e=0,t=this;for(;t!==void 0;)e+=t.localRotation,t=t.parent;return e}get globalRotationDegree(){return A(this.globalRotation)}get globalScale(){let e=c.one,t=this;for(;t!==void 0;)e=e.naiveMultiply(t.localScale),t=t.parent;return e}constructor(t,n,r,i){this.parent=i,(0,e.checkValidNumber)(n),this.localPosition=c.resolve(t),this.localRotation=n,this.localScale=c.resolve(r)}toString(){return`${this.localPosition.toString()}|${this.localRotation}|${this.localScale.toString()}`}get[Symbol.toStringTag](){return`Transform2D`}[e.NodeJSCustomInspect](){return`Transform2D <${this.toString()}>`}toMat3(){return new z().scale(this.localScale).rotate(this.localRotation).translate(this.localPosition)}toGlobalMat3(){let e=new z,t=this;for(;t!==void 0;)e=e.multiply(t.toMat3()),t=t.parent;return e}},U=class{origin=d.zero;localPosition;localRotation;localScale;get globalPosition(){let e=d.zero,t=this;for(;t!==void 0;)e=e.add(t.localPosition).add(t.origin),t=t.parent;return e}get globalRotation(){let e=f.zero,t=this;for(;t!==void 0;)e=e.add(t.localRotation),t=t.parent;return e}get globalScale(){let e=d.one,t=this;for(;t!==void 0;)e=e.naiveMultiply(t.localScale),t=t.parent;return e}constructor(e,t,n,r){this.parent=r,this.localPosition=d.resolve(e),this.localRotation=f.resolve(t),this.localScale=d.resolve(n)}toString(){return`${this.localPosition.toString()}|${this.localRotation.toString()}|${this.localScale.toString()}`}get[Symbol.toStringTag](){return`Transform2D`}[e.NodeJSCustomInspect](){return`Transform2D <${this.toString()}>`}toMat4(){return new B().scale(this.localScale).multiply(this.localRotation).translate(this.localPosition)}toGlobalMat4(){let e=new B,t=this;for(;t!==void 0;)e=e.multiply(t.toMat4()),t=t.parent;return e}};Object.defineProperty(exports,`AnyColor`,{enumerable:!0,get:function(){return V}}),exports.BoundingBox=N,exports.Circle=M,exports.DJB2_OFFSET=S,exports.EPSILON=o,exports.FNV1_OFFSET=w,exports.FNV1_PRIME=T,exports.HSLA=x,exports.LinearFunction=l,exports.MAX_ANGLE_DEGREE=360,exports.Mat3=z,exports.Mat4=B,exports.MathFunction=t,exports.QuadFunction=u,exports.Quaternion=f,exports.RGBA=b,exports.Rectangle=F,exports.ResolveError=r,exports.Size=P,exports.Transform2D=H,exports.Transform3D=U,exports.Triangle=I,exports.Triangle2D=L,exports.Triangle3D=R,exports.Vec2=c,exports.Vec3=d,exports.clamp=i,exports.clampAngleDegree=O,exports.clampAngleRadian=k,exports.degreeToRadian=j,exports.djb2=C,exports.fnv1=E,exports.hasHexNumberAlpha=_,exports.hexNumberToRGB=v,exports.hexNumberToRGBA=y,exports.isHexNumber=h,exports.lerp=s,exports.logHypot=a,exports.numberToRGB=p,exports.numberToRGBA=m,exports.radianToDegree=A,exports.sdbm=D,exports.signCharacter=n;