@ntf/math 1.3.0 → 1.3.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.d.mts +19 -4
- package/dist/{index.d.cts → index.d.ts} +19 -4
- package/dist/{index.cjs → index.js} +608 -266
- package/dist/index.mjs +586 -220
- package/package.json +13 -10
|
@@ -1,18 +1,91 @@
|
|
|
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);
|
|
2
19
|
|
|
3
|
-
|
|
4
|
-
}
|
|
20
|
+
// source/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ATriangle: () => ATriangle,
|
|
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
|
+
HSLColor: () => HSLColor,
|
|
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
|
+
RGBAColor: () => RGBAColor,
|
|
40
|
+
Rectangle: () => Rectangle,
|
|
41
|
+
ResolveError: () => ResolveError,
|
|
42
|
+
Size: () => Size,
|
|
43
|
+
Transform: () => Transform,
|
|
44
|
+
Triangle2D: () => Triangle2D,
|
|
45
|
+
Triangle3D: () => Triangle3D,
|
|
46
|
+
Vec2: () => Vec2,
|
|
47
|
+
Vec3: () => Vec3,
|
|
48
|
+
cap_angle_degree: () => cap_angle_degree,
|
|
49
|
+
cap_angle_radian: () => cap_angle_radian,
|
|
50
|
+
castColor: () => castColor,
|
|
51
|
+
check_array: () => check_array,
|
|
52
|
+
check_hex: () => check_hex,
|
|
53
|
+
check_hex_digit: () => check_hex_digit,
|
|
54
|
+
check_number: () => check_number,
|
|
55
|
+
check_number_array: () => check_number_array,
|
|
56
|
+
check_string: () => check_string,
|
|
57
|
+
check_string_array: () => check_string_array,
|
|
58
|
+
clamp: () => clamp,
|
|
59
|
+
degree_to_radian: () => degree_to_radian,
|
|
60
|
+
djb2: () => djb2,
|
|
61
|
+
fnv1: () => fnv1,
|
|
62
|
+
get_hex_part: () => get_hex_part,
|
|
63
|
+
has_property: () => has_property,
|
|
64
|
+
log_hypot: () => log_hypot,
|
|
65
|
+
radian_to_degree: () => radian_to_degree,
|
|
66
|
+
resolveColor: () => resolveColor,
|
|
67
|
+
sdbm: () => sdbm,
|
|
68
|
+
sign_char: () => sign_char,
|
|
69
|
+
stringify: () => stringify
|
|
70
|
+
});
|
|
71
|
+
module.exports = __toCommonJS(index_exports);
|
|
72
|
+
|
|
73
|
+
// source/algebra/function.ts
|
|
74
|
+
var MathFunction = class {
|
|
75
|
+
};
|
|
5
76
|
|
|
77
|
+
// source/common/sign.ts
|
|
6
78
|
function sign_char(num) {
|
|
7
79
|
if (num == 0)
|
|
8
|
-
return
|
|
80
|
+
return void 0;
|
|
9
81
|
if (num < 0)
|
|
10
82
|
return "-";
|
|
11
83
|
if (num > 0)
|
|
12
84
|
return "+";
|
|
13
|
-
return
|
|
85
|
+
return void 0;
|
|
14
86
|
}
|
|
15
87
|
|
|
88
|
+
// source/common/types.ts
|
|
16
89
|
function check_number(obj) {
|
|
17
90
|
return obj != null && typeof obj == "number" && !isNaN(obj) && isFinite(obj);
|
|
18
91
|
}
|
|
@@ -76,15 +149,17 @@ function has_property(obj, name, type) {
|
|
|
76
149
|
return obj != null && typeof obj == "object" && name in obj && typeof obj[name] == type;
|
|
77
150
|
}
|
|
78
151
|
|
|
79
|
-
|
|
152
|
+
// source/common/error.ts
|
|
153
|
+
var ResolveError = class extends Error {
|
|
80
154
|
constructor(target, value) {
|
|
81
155
|
super(`can't resolve ${value} to ${target}`);
|
|
82
156
|
this.target = target;
|
|
83
157
|
this.value = value;
|
|
84
158
|
}
|
|
85
|
-
}
|
|
159
|
+
};
|
|
86
160
|
|
|
87
|
-
|
|
161
|
+
// source/geometry/size.ts
|
|
162
|
+
var Size = class _Size {
|
|
88
163
|
width;
|
|
89
164
|
height;
|
|
90
165
|
get aspectRatio() {
|
|
@@ -104,7 +179,7 @@ class Size {
|
|
|
104
179
|
}
|
|
105
180
|
static cast(a) {
|
|
106
181
|
if (a == null || typeof a == "undefined")
|
|
107
|
-
return
|
|
182
|
+
return void 0;
|
|
108
183
|
if (check_number_array(a, 2))
|
|
109
184
|
return new this(a[0], a[1]);
|
|
110
185
|
if (has_property(a, "width", "number") && has_property(a, "height", "number"))
|
|
@@ -116,7 +191,7 @@ class Size {
|
|
|
116
191
|
}
|
|
117
192
|
if (check_number(a))
|
|
118
193
|
return new this(a, a);
|
|
119
|
-
return
|
|
194
|
+
return void 0;
|
|
120
195
|
}
|
|
121
196
|
static is(a) {
|
|
122
197
|
return typeof this.cast(a) != "undefined";
|
|
@@ -142,17 +217,18 @@ class Size {
|
|
|
142
217
|
};
|
|
143
218
|
}
|
|
144
219
|
clone() {
|
|
145
|
-
return new
|
|
220
|
+
return new _Size(this.width, this.height);
|
|
146
221
|
}
|
|
147
222
|
equals(square) {
|
|
148
|
-
const s =
|
|
223
|
+
const s = _Size.resolve(square);
|
|
149
224
|
return this.width == s.width && this.height == s.height;
|
|
150
225
|
}
|
|
151
226
|
toVec2() {
|
|
152
227
|
return [this.width, this.height];
|
|
153
228
|
}
|
|
154
|
-
}
|
|
229
|
+
};
|
|
155
230
|
|
|
231
|
+
// source/utils.ts
|
|
156
232
|
function clamp(value, min, max) {
|
|
157
233
|
if (value <= min)
|
|
158
234
|
return min;
|
|
@@ -172,9 +248,10 @@ function log_hypot(a, b) {
|
|
|
172
248
|
const _a = a / 2, _b = b / 2;
|
|
173
249
|
return 0.5 * Math.log(_a * _a + _b * _b) + Math.LN2;
|
|
174
250
|
}
|
|
175
|
-
|
|
251
|
+
var EPSILON = 1e-16;
|
|
176
252
|
|
|
177
|
-
|
|
253
|
+
// source/vectors/vec3.ts
|
|
254
|
+
var Vec3 = class _Vec3 {
|
|
178
255
|
x;
|
|
179
256
|
y;
|
|
180
257
|
z;
|
|
@@ -187,22 +264,22 @@ class Vec3 {
|
|
|
187
264
|
}
|
|
188
265
|
static cast(a) {
|
|
189
266
|
if (a == null || typeof a == "undefined")
|
|
190
|
-
return
|
|
267
|
+
return void 0;
|
|
191
268
|
if (check_number_array(a, 3) || check_number_array(a, 4))
|
|
192
|
-
return new this(a[0], a[1], a[2], check_number(a[3]) ? a[3] :
|
|
269
|
+
return new this(a[0], a[1], a[2], check_number(a[3]) ? a[3] : void 0);
|
|
193
270
|
if (has_property(a, "x", "number") && has_property(a, "y", "number") && has_property(a, "z", "number"))
|
|
194
|
-
return new this(a.x, a.y, a.z, has_property(a, "w", "number") ? a.w :
|
|
271
|
+
return new this(a.x, a.y, a.z, has_property(a, "w", "number") ? a.w : void 0);
|
|
195
272
|
if (check_string(a)) {
|
|
196
273
|
const [sxyz, sw] = a.split(";");
|
|
197
274
|
if (check_string(sxyz)) {
|
|
198
275
|
const parts = sxyz.split(",");
|
|
199
276
|
if (check_string_array(parts, 3))
|
|
200
|
-
return new this(parseFloat(parts[0]), parseFloat(parts[1]), parseFloat(parts[2]), check_string(sw) ? parseFloat(sw) :
|
|
277
|
+
return new this(parseFloat(parts[0]), parseFloat(parts[1]), parseFloat(parts[2]), check_string(sw) ? parseFloat(sw) : void 0);
|
|
201
278
|
}
|
|
202
279
|
}
|
|
203
280
|
if (check_number(a))
|
|
204
281
|
return new this(a, a, a);
|
|
205
|
-
return
|
|
282
|
+
return void 0;
|
|
206
283
|
}
|
|
207
284
|
static resolveArgs(args) {
|
|
208
285
|
if (check_number_array(args, 3))
|
|
@@ -233,7 +310,7 @@ class Vec3 {
|
|
|
233
310
|
t = (-plane_d - ad) / (bd - ad);
|
|
234
311
|
const lineStartToEnd = this.resolve(lineEnd).subtract(lineStart);
|
|
235
312
|
const linetoIntersect = lineStartToEnd.multiply(t);
|
|
236
|
-
return
|
|
313
|
+
return _Vec3.resolve(lineStart).add(linetoIntersect);
|
|
237
314
|
}
|
|
238
315
|
constructor(x = 0, y = 0, z = 0, w = 1) {
|
|
239
316
|
if (!check_number(x))
|
|
@@ -267,10 +344,10 @@ class Vec3 {
|
|
|
267
344
|
return [this.x, this.y, this.w];
|
|
268
345
|
}
|
|
269
346
|
clone() {
|
|
270
|
-
return new
|
|
347
|
+
return new _Vec3(this.x, this.y, this.z, this.w);
|
|
271
348
|
}
|
|
272
349
|
equals(vec) {
|
|
273
|
-
const a =
|
|
350
|
+
const a = _Vec3.resolve(vec);
|
|
274
351
|
return this.x == a.x && this.y == a.y && this.z == a.z;
|
|
275
352
|
}
|
|
276
353
|
setX(x) {
|
|
@@ -286,42 +363,42 @@ class Vec3 {
|
|
|
286
363
|
return this;
|
|
287
364
|
}
|
|
288
365
|
set(...args) {
|
|
289
|
-
const vec =
|
|
366
|
+
const vec = _Vec3.resolveArgs(args);
|
|
290
367
|
return this.setX(vec.x).setY(vec.y).setZ(vec.z);
|
|
291
368
|
}
|
|
292
369
|
add(...args) {
|
|
293
|
-
const vec =
|
|
294
|
-
return new
|
|
370
|
+
const vec = _Vec3.resolveArgs(args);
|
|
371
|
+
return new _Vec3(
|
|
295
372
|
this.x + vec.x,
|
|
296
373
|
this.y + vec.y,
|
|
297
374
|
this.z + vec.z
|
|
298
375
|
);
|
|
299
376
|
}
|
|
300
377
|
offset(...args) {
|
|
301
|
-
const vec =
|
|
378
|
+
const vec = _Vec3.resolveArgs(args);
|
|
302
379
|
this.x += vec.x;
|
|
303
380
|
this.y += vec.y;
|
|
304
381
|
this.z += vec.z;
|
|
305
382
|
return this;
|
|
306
383
|
}
|
|
307
384
|
subtract(...args) {
|
|
308
|
-
const vec =
|
|
309
|
-
return new
|
|
385
|
+
const vec = _Vec3.resolveArgs(args);
|
|
386
|
+
return new _Vec3(
|
|
310
387
|
this.x - vec.x,
|
|
311
388
|
this.y - vec.y,
|
|
312
389
|
this.z - vec.z
|
|
313
390
|
);
|
|
314
391
|
}
|
|
315
392
|
multiply(scalar) {
|
|
316
|
-
return new
|
|
393
|
+
return new _Vec3(
|
|
317
394
|
this.x * scalar,
|
|
318
395
|
this.y * scalar,
|
|
319
396
|
this.z * scalar
|
|
320
397
|
);
|
|
321
398
|
}
|
|
322
399
|
naiveMultiply(...args) {
|
|
323
|
-
const vec =
|
|
324
|
-
return new
|
|
400
|
+
const vec = _Vec3.resolveArgs(args);
|
|
401
|
+
return new _Vec3(
|
|
325
402
|
this.x * vec.x,
|
|
326
403
|
this.y * vec.y,
|
|
327
404
|
this.z * vec.z
|
|
@@ -329,36 +406,36 @@ class Vec3 {
|
|
|
329
406
|
}
|
|
330
407
|
divide(...args) {
|
|
331
408
|
if (check_number_array(args, 1))
|
|
332
|
-
return new
|
|
409
|
+
return new _Vec3(
|
|
333
410
|
this.x / args[0],
|
|
334
411
|
this.y / args[0],
|
|
335
412
|
this.z / args[0]
|
|
336
413
|
);
|
|
337
|
-
const vec =
|
|
338
|
-
return new
|
|
414
|
+
const vec = _Vec3.resolveArgs(args);
|
|
415
|
+
return new _Vec3(
|
|
339
416
|
this.x / vec.x,
|
|
340
417
|
this.y / vec.y,
|
|
341
418
|
this.z / vec.z
|
|
342
419
|
);
|
|
343
420
|
}
|
|
344
421
|
dot(...args) {
|
|
345
|
-
const vec =
|
|
422
|
+
const vec = _Vec3.resolveArgs(args);
|
|
346
423
|
return this.x * vec.x + this.y * vec.y + this.z * vec.z;
|
|
347
424
|
}
|
|
348
425
|
cross(...args) {
|
|
349
|
-
const vec =
|
|
350
|
-
return new
|
|
426
|
+
const vec = _Vec3.resolveArgs(args);
|
|
427
|
+
return new _Vec3(
|
|
351
428
|
this.y * vec.z - this.z * vec.y,
|
|
352
429
|
this.z * vec.x - this.x * vec.z,
|
|
353
430
|
this.x * vec.y - this.y * vec.x
|
|
354
431
|
);
|
|
355
432
|
}
|
|
356
433
|
distance(...args) {
|
|
357
|
-
const vec =
|
|
434
|
+
const vec = _Vec3.resolveArgs(args);
|
|
358
435
|
return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2);
|
|
359
436
|
}
|
|
360
437
|
distanceSquare(...args) {
|
|
361
|
-
const vec =
|
|
438
|
+
const vec = _Vec3.resolveArgs(args);
|
|
362
439
|
return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2));
|
|
363
440
|
}
|
|
364
441
|
length() {
|
|
@@ -366,8 +443,8 @@ class Vec3 {
|
|
|
366
443
|
}
|
|
367
444
|
normalize() {
|
|
368
445
|
const length = this.length();
|
|
369
|
-
if (length == 0) return new
|
|
370
|
-
return new
|
|
446
|
+
if (length == 0) return new _Vec3();
|
|
447
|
+
return new _Vec3(
|
|
371
448
|
this.x / length,
|
|
372
449
|
this.y / length,
|
|
373
450
|
this.z / length
|
|
@@ -377,11 +454,12 @@ class Vec3 {
|
|
|
377
454
|
return this.multiply(-1);
|
|
378
455
|
}
|
|
379
456
|
round() {
|
|
380
|
-
return new
|
|
457
|
+
return new _Vec3(Math.round(this.x), Math.round(this.y), Math.round(this.z), Math.round(this.w));
|
|
381
458
|
}
|
|
382
|
-
}
|
|
459
|
+
};
|
|
383
460
|
|
|
384
|
-
|
|
461
|
+
// source/vectors/vec2.ts
|
|
462
|
+
var Vec2 = class _Vec2 {
|
|
385
463
|
x;
|
|
386
464
|
y;
|
|
387
465
|
w;
|
|
@@ -393,22 +471,22 @@ class Vec2 {
|
|
|
393
471
|
}
|
|
394
472
|
static cast(a) {
|
|
395
473
|
if (a == null || typeof a == "undefined")
|
|
396
|
-
return
|
|
474
|
+
return void 0;
|
|
397
475
|
if (check_number_array(a, 2) || check_number_array(a, 3))
|
|
398
|
-
return new this(a[0], a[1], check_number(a[2]) ? a[2] :
|
|
476
|
+
return new this(a[0], a[1], check_number(a[2]) ? a[2] : void 0);
|
|
399
477
|
if (has_property(a, "x", "number") && has_property(a, "y", "number"))
|
|
400
|
-
return new this(a.x, a.y, has_property(a, "w", "number") ? a.w :
|
|
478
|
+
return new this(a.x, a.y, has_property(a, "w", "number") ? a.w : void 0);
|
|
401
479
|
if (check_string(a)) {
|
|
402
480
|
const [sxy, sw] = a.split(";");
|
|
403
481
|
if (check_string(sxy)) {
|
|
404
482
|
const parts = sxy.split(",");
|
|
405
483
|
if (check_string_array(parts, 2))
|
|
406
|
-
return new this(parseFloat(parts[0]), parseFloat(parts[1]), check_string(sw) ? parseFloat(sw) :
|
|
484
|
+
return new this(parseFloat(parts[0]), parseFloat(parts[1]), check_string(sw) ? parseFloat(sw) : void 0);
|
|
407
485
|
}
|
|
408
486
|
}
|
|
409
487
|
if (check_number(a))
|
|
410
488
|
return new this(a, a);
|
|
411
|
-
return
|
|
489
|
+
return void 0;
|
|
412
490
|
}
|
|
413
491
|
static resolveArgs(args) {
|
|
414
492
|
if (check_number_array(args, 2))
|
|
@@ -461,10 +539,10 @@ class Vec2 {
|
|
|
461
539
|
return new Vec3(this.x, this.y, z, this.w);
|
|
462
540
|
}
|
|
463
541
|
clone() {
|
|
464
|
-
return new
|
|
542
|
+
return new _Vec2(this.x, this.y, this.w);
|
|
465
543
|
}
|
|
466
544
|
equals(vec) {
|
|
467
|
-
const a =
|
|
545
|
+
const a = _Vec2.resolve(vec);
|
|
468
546
|
return this.x == a.x && this.y == a.y;
|
|
469
547
|
}
|
|
470
548
|
setX(x) {
|
|
@@ -480,85 +558,85 @@ class Vec2 {
|
|
|
480
558
|
return this;
|
|
481
559
|
}
|
|
482
560
|
set(...args) {
|
|
483
|
-
const vec =
|
|
561
|
+
const vec = _Vec2.resolveArgs(args);
|
|
484
562
|
return this.setX(vec.x).setY(vec.y);
|
|
485
563
|
}
|
|
486
564
|
add(...args) {
|
|
487
|
-
const vec =
|
|
488
|
-
return new
|
|
565
|
+
const vec = _Vec2.resolveArgs(args);
|
|
566
|
+
return new _Vec2(
|
|
489
567
|
this.x + vec.x,
|
|
490
568
|
this.y + vec.y
|
|
491
569
|
);
|
|
492
570
|
}
|
|
493
571
|
offset(...args) {
|
|
494
|
-
const vec =
|
|
572
|
+
const vec = _Vec2.resolveArgs(args);
|
|
495
573
|
this.x += vec.x;
|
|
496
574
|
this.y += vec.y;
|
|
497
575
|
return this;
|
|
498
576
|
}
|
|
499
577
|
subtract(...args) {
|
|
500
|
-
const vec =
|
|
501
|
-
return new
|
|
578
|
+
const vec = _Vec2.resolveArgs(args);
|
|
579
|
+
return new _Vec2(
|
|
502
580
|
this.x - vec.x,
|
|
503
581
|
this.y - vec.y
|
|
504
582
|
);
|
|
505
583
|
}
|
|
506
584
|
multiply(scalar) {
|
|
507
|
-
return new
|
|
585
|
+
return new _Vec2(
|
|
508
586
|
this.x * scalar,
|
|
509
587
|
this.y * scalar
|
|
510
588
|
);
|
|
511
589
|
}
|
|
512
590
|
naiveMultiply(...args) {
|
|
513
|
-
const vec =
|
|
514
|
-
return new
|
|
591
|
+
const vec = _Vec2.resolveArgs(args);
|
|
592
|
+
return new _Vec2(
|
|
515
593
|
this.x * vec.x,
|
|
516
594
|
this.y * vec.y
|
|
517
595
|
);
|
|
518
596
|
}
|
|
519
597
|
divide(...args) {
|
|
520
598
|
if (check_number_array(args, 1))
|
|
521
|
-
return new
|
|
599
|
+
return new _Vec2(
|
|
522
600
|
this.x / args[0],
|
|
523
601
|
this.y / args[0]
|
|
524
602
|
);
|
|
525
|
-
const vec =
|
|
526
|
-
return new
|
|
603
|
+
const vec = _Vec2.resolveArgs(args);
|
|
604
|
+
return new _Vec2(
|
|
527
605
|
this.x / vec.x,
|
|
528
606
|
this.y / vec.y
|
|
529
607
|
);
|
|
530
608
|
}
|
|
531
609
|
dot(...args) {
|
|
532
|
-
const vec =
|
|
610
|
+
const vec = _Vec2.resolveArgs(args);
|
|
533
611
|
return this.x * vec.x + this.y * vec.y;
|
|
534
612
|
}
|
|
535
613
|
distance(...args) {
|
|
536
|
-
const vec =
|
|
614
|
+
const vec = _Vec2.resolveArgs(args);
|
|
537
615
|
return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2);
|
|
538
616
|
}
|
|
539
617
|
distanceSquare(...args) {
|
|
540
|
-
const vec =
|
|
618
|
+
const vec = _Vec2.resolveArgs(args);
|
|
541
619
|
return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2));
|
|
542
620
|
}
|
|
543
621
|
length() {
|
|
544
622
|
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
545
623
|
}
|
|
546
624
|
cartesianify() {
|
|
547
|
-
return new
|
|
625
|
+
return new _Vec2(
|
|
548
626
|
this.x * Math.cos(this.y),
|
|
549
627
|
this.x * Math.sin(this.y)
|
|
550
628
|
);
|
|
551
629
|
}
|
|
552
630
|
polarify() {
|
|
553
|
-
return new
|
|
631
|
+
return new _Vec2(
|
|
554
632
|
Math.sqrt(this.x * this.x + this.y * this.y),
|
|
555
633
|
Math.atan(this.y / this.x)
|
|
556
634
|
);
|
|
557
635
|
}
|
|
558
636
|
normalize() {
|
|
559
637
|
const length = this.length();
|
|
560
|
-
if (length == 0) return new
|
|
561
|
-
return new
|
|
638
|
+
if (length == 0) return new _Vec2();
|
|
639
|
+
return new _Vec2(
|
|
562
640
|
this.x / length,
|
|
563
641
|
this.y / length
|
|
564
642
|
);
|
|
@@ -567,11 +645,12 @@ class Vec2 {
|
|
|
567
645
|
return this.multiply(-1);
|
|
568
646
|
}
|
|
569
647
|
round() {
|
|
570
|
-
return new
|
|
648
|
+
return new _Vec2(Math.round(this.x), Math.round(this.y), Math.round(this.w));
|
|
571
649
|
}
|
|
572
|
-
}
|
|
650
|
+
};
|
|
573
651
|
|
|
574
|
-
|
|
652
|
+
// source/algebra/linear.ts
|
|
653
|
+
var LinearFunction = class extends MathFunction {
|
|
575
654
|
/**
|
|
576
655
|
* The factor of the linear function
|
|
577
656
|
*/
|
|
@@ -624,9 +703,10 @@ class LinearFunction extends MathFunction {
|
|
|
624
703
|
return `f(x) = ${this.m} * x ${bsign} ${Math.abs(this.b)}`;
|
|
625
704
|
return `f(x) = ${this.m} * x`;
|
|
626
705
|
}
|
|
627
|
-
}
|
|
706
|
+
};
|
|
628
707
|
|
|
629
|
-
|
|
708
|
+
// source/algebra/quad.ts
|
|
709
|
+
var QuadFunction = class extends MathFunction {
|
|
630
710
|
a;
|
|
631
711
|
b;
|
|
632
712
|
c;
|
|
@@ -677,13 +757,15 @@ class QuadFunction extends MathFunction {
|
|
|
677
757
|
}
|
|
678
758
|
}
|
|
679
759
|
}
|
|
680
|
-
}
|
|
760
|
+
};
|
|
681
761
|
|
|
762
|
+
// source/common/string.ts
|
|
682
763
|
function stringify(value) {
|
|
683
764
|
return value != null && typeof value == "object" && "toString" in value && typeof value.toString == "function" ? value.toString() : String(value);
|
|
684
765
|
}
|
|
685
766
|
|
|
686
|
-
|
|
767
|
+
// source/crypto/hash.ts
|
|
768
|
+
var DJB2_OFFSET = 5381n;
|
|
687
769
|
function djb2(value) {
|
|
688
770
|
const string = stringify(value);
|
|
689
771
|
let hash = DJB2_OFFSET;
|
|
@@ -692,8 +774,8 @@ function djb2(value) {
|
|
|
692
774
|
}
|
|
693
775
|
return hash;
|
|
694
776
|
}
|
|
695
|
-
|
|
696
|
-
|
|
777
|
+
var FNV1_OFFSET = 14695981039346656037n;
|
|
778
|
+
var FNV1_PRIME = 1099511628211n;
|
|
697
779
|
function fnv1(value) {
|
|
698
780
|
const string = stringify(value);
|
|
699
781
|
let hash = FNV1_OFFSET;
|
|
@@ -712,13 +794,326 @@ function sdbm(value) {
|
|
|
712
794
|
return hash;
|
|
713
795
|
}
|
|
714
796
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
797
|
+
// source/crypto/md2.ts
|
|
798
|
+
var STABLE = [
|
|
799
|
+
41,
|
|
800
|
+
46,
|
|
801
|
+
67,
|
|
802
|
+
201,
|
|
803
|
+
162,
|
|
804
|
+
216,
|
|
805
|
+
124,
|
|
806
|
+
1,
|
|
807
|
+
61,
|
|
808
|
+
54,
|
|
809
|
+
84,
|
|
810
|
+
161,
|
|
811
|
+
236,
|
|
812
|
+
240,
|
|
813
|
+
6,
|
|
814
|
+
19,
|
|
815
|
+
98,
|
|
816
|
+
167,
|
|
817
|
+
5,
|
|
818
|
+
243,
|
|
819
|
+
192,
|
|
820
|
+
199,
|
|
821
|
+
115,
|
|
822
|
+
140,
|
|
823
|
+
152,
|
|
824
|
+
147,
|
|
825
|
+
43,
|
|
826
|
+
217,
|
|
827
|
+
188,
|
|
828
|
+
76,
|
|
829
|
+
130,
|
|
830
|
+
202,
|
|
831
|
+
30,
|
|
832
|
+
155,
|
|
833
|
+
87,
|
|
834
|
+
60,
|
|
835
|
+
253,
|
|
836
|
+
212,
|
|
837
|
+
224,
|
|
838
|
+
22,
|
|
839
|
+
103,
|
|
840
|
+
66,
|
|
841
|
+
111,
|
|
842
|
+
24,
|
|
843
|
+
138,
|
|
844
|
+
23,
|
|
845
|
+
229,
|
|
846
|
+
18,
|
|
847
|
+
190,
|
|
848
|
+
78,
|
|
849
|
+
196,
|
|
850
|
+
214,
|
|
851
|
+
218,
|
|
852
|
+
158,
|
|
853
|
+
222,
|
|
854
|
+
73,
|
|
855
|
+
160,
|
|
856
|
+
251,
|
|
857
|
+
245,
|
|
858
|
+
142,
|
|
859
|
+
187,
|
|
860
|
+
47,
|
|
861
|
+
238,
|
|
862
|
+
122,
|
|
863
|
+
169,
|
|
864
|
+
104,
|
|
865
|
+
121,
|
|
866
|
+
145,
|
|
867
|
+
21,
|
|
868
|
+
178,
|
|
869
|
+
7,
|
|
870
|
+
63,
|
|
871
|
+
148,
|
|
872
|
+
194,
|
|
873
|
+
16,
|
|
874
|
+
137,
|
|
875
|
+
11,
|
|
876
|
+
34,
|
|
877
|
+
95,
|
|
878
|
+
33,
|
|
879
|
+
128,
|
|
880
|
+
127,
|
|
881
|
+
93,
|
|
882
|
+
154,
|
|
883
|
+
90,
|
|
884
|
+
144,
|
|
885
|
+
50,
|
|
886
|
+
39,
|
|
887
|
+
53,
|
|
888
|
+
62,
|
|
889
|
+
204,
|
|
890
|
+
231,
|
|
891
|
+
191,
|
|
892
|
+
247,
|
|
893
|
+
151,
|
|
894
|
+
3,
|
|
895
|
+
255,
|
|
896
|
+
25,
|
|
897
|
+
48,
|
|
898
|
+
179,
|
|
899
|
+
72,
|
|
900
|
+
165,
|
|
901
|
+
181,
|
|
902
|
+
209,
|
|
903
|
+
215,
|
|
904
|
+
94,
|
|
905
|
+
146,
|
|
906
|
+
42,
|
|
907
|
+
172,
|
|
908
|
+
86,
|
|
909
|
+
170,
|
|
910
|
+
198,
|
|
911
|
+
79,
|
|
912
|
+
184,
|
|
913
|
+
56,
|
|
914
|
+
210,
|
|
915
|
+
150,
|
|
916
|
+
164,
|
|
917
|
+
125,
|
|
918
|
+
182,
|
|
919
|
+
118,
|
|
920
|
+
252,
|
|
921
|
+
107,
|
|
922
|
+
226,
|
|
923
|
+
156,
|
|
924
|
+
116,
|
|
925
|
+
4,
|
|
926
|
+
241,
|
|
927
|
+
69,
|
|
928
|
+
157,
|
|
929
|
+
112,
|
|
930
|
+
89,
|
|
931
|
+
100,
|
|
932
|
+
113,
|
|
933
|
+
135,
|
|
934
|
+
32,
|
|
935
|
+
134,
|
|
936
|
+
91,
|
|
937
|
+
207,
|
|
938
|
+
101,
|
|
939
|
+
230,
|
|
940
|
+
45,
|
|
941
|
+
168,
|
|
942
|
+
2,
|
|
943
|
+
27,
|
|
944
|
+
96,
|
|
945
|
+
37,
|
|
946
|
+
173,
|
|
947
|
+
174,
|
|
948
|
+
176,
|
|
949
|
+
185,
|
|
950
|
+
246,
|
|
951
|
+
28,
|
|
952
|
+
70,
|
|
953
|
+
97,
|
|
954
|
+
105,
|
|
955
|
+
52,
|
|
956
|
+
64,
|
|
957
|
+
126,
|
|
958
|
+
15,
|
|
959
|
+
85,
|
|
960
|
+
71,
|
|
961
|
+
163,
|
|
962
|
+
35,
|
|
963
|
+
221,
|
|
964
|
+
81,
|
|
965
|
+
175,
|
|
966
|
+
58,
|
|
967
|
+
195,
|
|
968
|
+
92,
|
|
969
|
+
249,
|
|
970
|
+
206,
|
|
971
|
+
186,
|
|
972
|
+
197,
|
|
973
|
+
234,
|
|
974
|
+
38,
|
|
975
|
+
44,
|
|
976
|
+
83,
|
|
977
|
+
13,
|
|
978
|
+
110,
|
|
979
|
+
133,
|
|
980
|
+
40,
|
|
981
|
+
132,
|
|
982
|
+
9,
|
|
983
|
+
211,
|
|
984
|
+
223,
|
|
985
|
+
205,
|
|
986
|
+
244,
|
|
987
|
+
65,
|
|
988
|
+
129,
|
|
989
|
+
77,
|
|
990
|
+
82,
|
|
991
|
+
106,
|
|
992
|
+
220,
|
|
993
|
+
55,
|
|
994
|
+
200,
|
|
995
|
+
108,
|
|
996
|
+
193,
|
|
997
|
+
171,
|
|
998
|
+
250,
|
|
999
|
+
36,
|
|
1000
|
+
225,
|
|
1001
|
+
123,
|
|
1002
|
+
8,
|
|
1003
|
+
12,
|
|
1004
|
+
189,
|
|
1005
|
+
177,
|
|
1006
|
+
74,
|
|
1007
|
+
120,
|
|
1008
|
+
136,
|
|
1009
|
+
149,
|
|
1010
|
+
139,
|
|
1011
|
+
227,
|
|
1012
|
+
99,
|
|
1013
|
+
232,
|
|
1014
|
+
109,
|
|
1015
|
+
233,
|
|
1016
|
+
203,
|
|
1017
|
+
213,
|
|
1018
|
+
254,
|
|
1019
|
+
59,
|
|
1020
|
+
0,
|
|
1021
|
+
29,
|
|
1022
|
+
57,
|
|
1023
|
+
242,
|
|
1024
|
+
239,
|
|
1025
|
+
183,
|
|
1026
|
+
14,
|
|
1027
|
+
102,
|
|
1028
|
+
88,
|
|
1029
|
+
208,
|
|
1030
|
+
228,
|
|
1031
|
+
166,
|
|
1032
|
+
119,
|
|
1033
|
+
114,
|
|
1034
|
+
248,
|
|
1035
|
+
235,
|
|
1036
|
+
117,
|
|
1037
|
+
75,
|
|
1038
|
+
10,
|
|
1039
|
+
49,
|
|
1040
|
+
68,
|
|
1041
|
+
80,
|
|
1042
|
+
180,
|
|
1043
|
+
143,
|
|
1044
|
+
237,
|
|
1045
|
+
31,
|
|
1046
|
+
26,
|
|
1047
|
+
219,
|
|
1048
|
+
153,
|
|
1049
|
+
141,
|
|
1050
|
+
51,
|
|
1051
|
+
159,
|
|
1052
|
+
17,
|
|
1053
|
+
131,
|
|
1054
|
+
20
|
|
1055
|
+
];
|
|
1056
|
+
var MD2 = class _MD2 {
|
|
1057
|
+
static BLOCK_SIZE = 16;
|
|
1058
|
+
_data = new Uint8Array(16);
|
|
1059
|
+
_state = new Uint8Array(48);
|
|
1060
|
+
_checksum = new Uint8Array(16);
|
|
1061
|
+
_length = 0;
|
|
1062
|
+
constructor() {
|
|
1063
|
+
for (let i = 0; i < this._state.length; i++)
|
|
1064
|
+
this._state[i] = 0;
|
|
1065
|
+
for (let i = 0; i < this._checksum.length; i++)
|
|
1066
|
+
this._checksum[i] = 0;
|
|
1067
|
+
}
|
|
1068
|
+
update(input) {
|
|
1069
|
+
for (let i = 0; i < input.length; i++) {
|
|
1070
|
+
this._data[this._length] = input[i];
|
|
1071
|
+
this._length++;
|
|
1072
|
+
if (this._length == _MD2.BLOCK_SIZE) {
|
|
1073
|
+
this._transform(input);
|
|
1074
|
+
this._length = 0;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
return this;
|
|
1078
|
+
}
|
|
1079
|
+
_transform(data) {
|
|
1080
|
+
for (let i = 0; i < 16; ++i) {
|
|
1081
|
+
this._state[i + 16] = this._data[i];
|
|
1082
|
+
this._state[i + 32] = this._state[i + 16] ^ this._state[i];
|
|
1083
|
+
}
|
|
1084
|
+
let t = 0;
|
|
1085
|
+
for (let i = 0; i < 18; ++i) {
|
|
1086
|
+
for (let j = 0; j < 48; ++j) {
|
|
1087
|
+
this._state[j] ^= STABLE[t];
|
|
1088
|
+
t = this._state[j];
|
|
1089
|
+
}
|
|
1090
|
+
t = t + i & 255;
|
|
1091
|
+
}
|
|
1092
|
+
t = this._checksum[15];
|
|
1093
|
+
for (let i = 0; i < 16; ++i) {
|
|
1094
|
+
this._checksum[i] ^= STABLE[this._data[i] ^ t];
|
|
1095
|
+
t = this._checksum[i];
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
digest() {
|
|
1099
|
+
const toPad = _MD2.BLOCK_SIZE - this._length;
|
|
1100
|
+
while (this._length < _MD2.BLOCK_SIZE)
|
|
1101
|
+
this._data[this._length++] = toPad;
|
|
1102
|
+
this._transform(this._data);
|
|
1103
|
+
this._transform(this._checksum);
|
|
1104
|
+
return this._state.slice();
|
|
1105
|
+
}
|
|
1106
|
+
};
|
|
1107
|
+
|
|
1108
|
+
// source/geometry/angle.ts
|
|
1109
|
+
var MAX_ANGLE_DEGREE = 360;
|
|
1110
|
+
var cap_angle_degree = (angle) => angle % MAX_ANGLE_DEGREE;
|
|
1111
|
+
var cap_angle_radian = (angle) => cap_angle_degree(degree_to_radian(angle));
|
|
1112
|
+
var radian_to_degree = (angle) => angle * (180 / Math.PI);
|
|
1113
|
+
var degree_to_radian = (angle) => angle * (Math.PI / 180);
|
|
720
1114
|
|
|
721
|
-
|
|
1115
|
+
// source/geometry/circle.ts
|
|
1116
|
+
var Circle = class _Circle {
|
|
722
1117
|
radius;
|
|
723
1118
|
get perimeter() {
|
|
724
1119
|
return this.radius * Math.PI * 2;
|
|
@@ -753,7 +1148,7 @@ class Circle {
|
|
|
753
1148
|
}
|
|
754
1149
|
static cast(a) {
|
|
755
1150
|
if (a == null || typeof a == "undefined")
|
|
756
|
-
return
|
|
1151
|
+
return void 0;
|
|
757
1152
|
if (check_number_array(a, 3))
|
|
758
1153
|
return new this([a[0], a[1]], a[2]);
|
|
759
1154
|
if (check_number_array(a, 4)) {
|
|
@@ -767,12 +1162,12 @@ class Circle {
|
|
|
767
1162
|
const [spos, sradius] = a.split("|");
|
|
768
1163
|
const pos = Vec2.cast(spos);
|
|
769
1164
|
if (typeof pos == "undefined")
|
|
770
|
-
return
|
|
1165
|
+
return void 0;
|
|
771
1166
|
const radius = parseFloat(sradius);
|
|
772
1167
|
if (!isNaN(radius))
|
|
773
1168
|
return new this(pos, radius);
|
|
774
1169
|
}
|
|
775
|
-
return
|
|
1170
|
+
return void 0;
|
|
776
1171
|
}
|
|
777
1172
|
static is(a) {
|
|
778
1173
|
return typeof this.cast(a) != "undefined";
|
|
@@ -796,14 +1191,14 @@ class Circle {
|
|
|
796
1191
|
return `${this.position.toString()}|${this.radius}`;
|
|
797
1192
|
}
|
|
798
1193
|
clone() {
|
|
799
|
-
return new
|
|
1194
|
+
return new _Circle(this.position.clone(), this.radius);
|
|
800
1195
|
}
|
|
801
1196
|
equals(circle) {
|
|
802
|
-
const c =
|
|
1197
|
+
const c = _Circle.resolve(circle);
|
|
803
1198
|
return c.position.equals(c.position) && this.radius == c.radius;
|
|
804
1199
|
}
|
|
805
1200
|
inside(a) {
|
|
806
|
-
const circle =
|
|
1201
|
+
const circle = _Circle.resolve(a);
|
|
807
1202
|
const distX = circle.x - this.x;
|
|
808
1203
|
const distY = circle.y - this.y;
|
|
809
1204
|
const dist = Math.sqrt(distX * distX + (distY + distY));
|
|
@@ -812,9 +1207,10 @@ class Circle {
|
|
|
812
1207
|
insidePoint(a) {
|
|
813
1208
|
return this.position.distance(a) <= this.radius;
|
|
814
1209
|
}
|
|
815
|
-
}
|
|
1210
|
+
};
|
|
816
1211
|
|
|
817
|
-
|
|
1212
|
+
// source/geometry/rectangle.ts
|
|
1213
|
+
var Rectangle = class _Rectangle {
|
|
818
1214
|
position;
|
|
819
1215
|
size;
|
|
820
1216
|
get area() {
|
|
@@ -861,11 +1257,11 @@ class Rectangle {
|
|
|
861
1257
|
}
|
|
862
1258
|
static cast(a) {
|
|
863
1259
|
if (a == null || typeof a == "undefined")
|
|
864
|
-
return
|
|
1260
|
+
return void 0;
|
|
865
1261
|
if (check_number_array(a, 4))
|
|
866
|
-
return new this(a[0], a[1], a[2], a[3]);
|
|
1262
|
+
return new this([a[0], a[1]], [a[2], a[3]]);
|
|
867
1263
|
if (check_number_array(a, 5)) {
|
|
868
|
-
const rect = new this(a[0], a[1], a[3], a[4]);
|
|
1264
|
+
const rect = new this([a[0], a[1]], [a[3], a[4]]);
|
|
869
1265
|
rect.w = a[2];
|
|
870
1266
|
return rect;
|
|
871
1267
|
}
|
|
@@ -874,39 +1270,25 @@ class Rectangle {
|
|
|
874
1270
|
const pos = Vec2.cast(spos);
|
|
875
1271
|
const size = Size.cast(ssize);
|
|
876
1272
|
if (typeof pos == "undefined" || typeof size == "undefined")
|
|
877
|
-
return
|
|
878
|
-
const rect = new this(pos.x, pos.y, size.width, size.height);
|
|
1273
|
+
return void 0;
|
|
1274
|
+
const rect = new this([pos.x, pos.y], [size.width, size.height]);
|
|
879
1275
|
rect.w = pos.w;
|
|
880
1276
|
return rect;
|
|
881
1277
|
}
|
|
882
1278
|
if (has_property(a, "x", "number") && has_property(a, "y", "number") && has_property(a, "width", "number") && has_property(a, "height", "number")) {
|
|
883
|
-
const rect = new this(a.x, a.y, a.width, a.height);
|
|
1279
|
+
const rect = new this([a.x, a.y], [a.width, a.height]);
|
|
884
1280
|
if (has_property(a, "w", "number"))
|
|
885
1281
|
rect.w = a.w;
|
|
886
1282
|
return rect;
|
|
887
1283
|
}
|
|
888
|
-
return
|
|
1284
|
+
return void 0;
|
|
889
1285
|
}
|
|
890
1286
|
static is(a) {
|
|
891
1287
|
return typeof this.cast(a) != "undefined";
|
|
892
1288
|
}
|
|
893
|
-
constructor(
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
const x = typeof a == "number" ? a : vec?.x;
|
|
897
|
-
if (!check_number(x))
|
|
898
|
-
throw new TypeError("expected number for x position");
|
|
899
|
-
const y = typeof b == "number" ? b : vec?.y;
|
|
900
|
-
if (!check_number(y))
|
|
901
|
-
throw new TypeError("expected number for y position");
|
|
902
|
-
const width = typeof c == "number" ? c : size?.width;
|
|
903
|
-
if (!check_number(width))
|
|
904
|
-
throw new TypeError("expected number for width");
|
|
905
|
-
const height = typeof d == "number" ? d : size?.height;
|
|
906
|
-
if (!check_number(height))
|
|
907
|
-
throw new TypeError("expected number for height");
|
|
908
|
-
this.position = new Vec2(x, y);
|
|
909
|
-
this.size = new Size(width, height);
|
|
1289
|
+
constructor(pos, size) {
|
|
1290
|
+
this.position = Vec2.resolve(pos);
|
|
1291
|
+
this.size = Size.resolve(size);
|
|
910
1292
|
}
|
|
911
1293
|
toArray(w = false) {
|
|
912
1294
|
return [...this.position.toArray(w), ...this.size.toArray()];
|
|
@@ -921,15 +1303,16 @@ class Rectangle {
|
|
|
921
1303
|
return [this.x, this.x + this.width, this.y, this.y + this.height];
|
|
922
1304
|
}
|
|
923
1305
|
clone() {
|
|
924
|
-
return new
|
|
1306
|
+
return new _Rectangle(this.position.clone(), this.size.clone());
|
|
925
1307
|
}
|
|
926
1308
|
equals(rectangle) {
|
|
927
|
-
const rect =
|
|
1309
|
+
const rect = _Rectangle.resolve(rectangle);
|
|
928
1310
|
return this.position.equals(rect.position) && this.size.equals(rect.size);
|
|
929
1311
|
}
|
|
930
|
-
}
|
|
1312
|
+
};
|
|
931
1313
|
|
|
932
|
-
|
|
1314
|
+
// source/geometry/bbox.ts
|
|
1315
|
+
var BoundingBox = class _BoundingBox {
|
|
933
1316
|
left;
|
|
934
1317
|
right;
|
|
935
1318
|
top;
|
|
@@ -954,7 +1337,7 @@ class BoundingBox {
|
|
|
954
1337
|
}
|
|
955
1338
|
static cast(a) {
|
|
956
1339
|
if (a == null || typeof a == "undefined")
|
|
957
|
-
return
|
|
1340
|
+
return void 0;
|
|
958
1341
|
if (check_number_array(a, 4))
|
|
959
1342
|
return new this(a[0], a[1], a[2], a[3]);
|
|
960
1343
|
if (has_property(a, "left", "number") && has_property(a, "right", "number") && has_property(a, "top", "number") && has_property(a, "bottom", "number"))
|
|
@@ -964,7 +1347,7 @@ class BoundingBox {
|
|
|
964
1347
|
if (check_string_array(parts, 4))
|
|
965
1348
|
return this.cast(parts.map((v) => parseFloat(v)));
|
|
966
1349
|
}
|
|
967
|
-
return
|
|
1350
|
+
return void 0;
|
|
968
1351
|
}
|
|
969
1352
|
static is(a) {
|
|
970
1353
|
return typeof this.cast(a) != "undefined";
|
|
@@ -998,25 +1381,25 @@ class BoundingBox {
|
|
|
998
1381
|
};
|
|
999
1382
|
}
|
|
1000
1383
|
clone() {
|
|
1001
|
-
return new
|
|
1384
|
+
return new _BoundingBox(this.left, this.right, this.top, this.bottom);
|
|
1002
1385
|
}
|
|
1003
1386
|
equals(bbox) {
|
|
1004
|
-
const b =
|
|
1387
|
+
const b = _BoundingBox.resolve(bbox);
|
|
1005
1388
|
return this.left == b.left && this.right == b.right && this.top == b.top && this.bottom == b.bottom;
|
|
1006
1389
|
}
|
|
1007
1390
|
toSquare() {
|
|
1008
1391
|
return new Size(this.width, this.height);
|
|
1009
1392
|
}
|
|
1010
1393
|
toRectangle() {
|
|
1011
|
-
return new Rectangle(this.left, this.top, this.width, this.height);
|
|
1394
|
+
return new Rectangle([this.left, this.top], [this.width, this.height]);
|
|
1012
1395
|
}
|
|
1013
1396
|
inside(a) {
|
|
1014
|
-
const bbox =
|
|
1397
|
+
const bbox = _BoundingBox.resolve(a);
|
|
1015
1398
|
return this.right >= bbox.left && bbox.right >= this.left && this.bottom >= bbox.top && bbox.bottom >= this.top;
|
|
1016
1399
|
}
|
|
1017
1400
|
insidePoint(a) {
|
|
1018
1401
|
const point = Vec2.resolve(a);
|
|
1019
|
-
return this.left <= point.x && this.right >= point.x && this.top
|
|
1402
|
+
return this.left <= point.x && this.right >= point.x && this.top <= point.y && this.bottom >= point.y;
|
|
1020
1403
|
}
|
|
1021
1404
|
insideCircle(a) {
|
|
1022
1405
|
const circle = Circle.resolve(a);
|
|
@@ -1029,9 +1412,10 @@ class BoundingBox {
|
|
|
1029
1412
|
diff = closest.subtract(center);
|
|
1030
1413
|
return diff.length() < circle.radius;
|
|
1031
1414
|
}
|
|
1032
|
-
}
|
|
1415
|
+
};
|
|
1033
1416
|
|
|
1034
|
-
|
|
1417
|
+
// source/geometry/triangle.ts
|
|
1418
|
+
var ATriangle = class {
|
|
1035
1419
|
constructor(A, B, C) {
|
|
1036
1420
|
this.A = A;
|
|
1037
1421
|
this.B = B;
|
|
@@ -1061,8 +1445,8 @@ class ATriangle {
|
|
|
1061
1445
|
get height() {
|
|
1062
1446
|
return 2 * (this.area / this.base);
|
|
1063
1447
|
}
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1448
|
+
};
|
|
1449
|
+
var Triangle2D = class extends ATriangle {
|
|
1066
1450
|
get a() {
|
|
1067
1451
|
return Vec2.fromPoints(this.B, this.C).length();
|
|
1068
1452
|
}
|
|
@@ -1072,8 +1456,8 @@ class Triangle2D extends ATriangle {
|
|
|
1072
1456
|
get c() {
|
|
1073
1457
|
return Vec2.fromPoints(this.A, this.B).length();
|
|
1074
1458
|
}
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1459
|
+
};
|
|
1460
|
+
var Triangle3D = class extends ATriangle {
|
|
1077
1461
|
get a() {
|
|
1078
1462
|
return Vec3.fromPoints(this.B, this.C).length();
|
|
1079
1463
|
}
|
|
@@ -1083,9 +1467,10 @@ class Triangle3D extends ATriangle {
|
|
|
1083
1467
|
get c() {
|
|
1084
1468
|
return Vec3.fromPoints(this.A, this.B).length();
|
|
1085
1469
|
}
|
|
1086
|
-
}
|
|
1470
|
+
};
|
|
1087
1471
|
|
|
1088
|
-
|
|
1472
|
+
// source/matrices/mat3.ts
|
|
1473
|
+
var Mat3 = class _Mat3 {
|
|
1089
1474
|
_raw;
|
|
1090
1475
|
get m00() {
|
|
1091
1476
|
return this._raw[0];
|
|
@@ -1149,11 +1534,11 @@ class Mat3 {
|
|
|
1149
1534
|
}
|
|
1150
1535
|
static cast(a) {
|
|
1151
1536
|
if (a == null || typeof a == "undefined")
|
|
1152
|
-
return
|
|
1537
|
+
return void 0;
|
|
1153
1538
|
if (check_number_array(a, 9)) {
|
|
1154
1539
|
return new this(a);
|
|
1155
1540
|
}
|
|
1156
|
-
if (check_array(a,
|
|
1541
|
+
if (check_array(a, void 0, 3)) {
|
|
1157
1542
|
const row0 = a[0], row1 = a[1], row2 = a[2];
|
|
1158
1543
|
if (check_number_array(row0, 3) && check_number_array(row1, 3) && check_number_array(row2, 3))
|
|
1159
1544
|
return new this([
|
|
@@ -1188,7 +1573,7 @@ class Mat3 {
|
|
|
1188
1573
|
if (check_number(a)) {
|
|
1189
1574
|
return new this([a, a, a, a, a, a, a, a, a]);
|
|
1190
1575
|
}
|
|
1191
|
-
return
|
|
1576
|
+
return void 0;
|
|
1192
1577
|
}
|
|
1193
1578
|
static is(a) {
|
|
1194
1579
|
return typeof this.cast(a) != "undefined";
|
|
@@ -1248,7 +1633,7 @@ class Mat3 {
|
|
|
1248
1633
|
return `${this.m00},${this.m01},${this.m02},${this.m10},${this.m11},${this.m12},${this.m20},${this.m21},${this.m22}`;
|
|
1249
1634
|
}
|
|
1250
1635
|
clone() {
|
|
1251
|
-
return new
|
|
1636
|
+
return new _Mat3([
|
|
1252
1637
|
this.m00,
|
|
1253
1638
|
this.m01,
|
|
1254
1639
|
this.m02,
|
|
@@ -1261,29 +1646,29 @@ class Mat3 {
|
|
|
1261
1646
|
]);
|
|
1262
1647
|
}
|
|
1263
1648
|
equals(mat) {
|
|
1264
|
-
const m =
|
|
1649
|
+
const m = _Mat3.resolve(mat);
|
|
1265
1650
|
for (let index = 0; index < this._raw.length; index++)
|
|
1266
1651
|
if (this._raw[index] != m._raw[index])
|
|
1267
1652
|
return false;
|
|
1268
1653
|
return true;
|
|
1269
1654
|
}
|
|
1270
1655
|
add(mat) {
|
|
1271
|
-
const b =
|
|
1272
|
-
const m = new
|
|
1656
|
+
const b = _Mat3.resolve(mat);
|
|
1657
|
+
const m = new _Mat3();
|
|
1273
1658
|
for (let index = 0; index < this._raw.length; index++)
|
|
1274
1659
|
m._raw[index] = this._raw[index] + b._raw[index];
|
|
1275
|
-
return
|
|
1660
|
+
return m;
|
|
1276
1661
|
}
|
|
1277
1662
|
subtract(mat) {
|
|
1278
|
-
const b =
|
|
1279
|
-
const m = new
|
|
1663
|
+
const b = _Mat3.resolve(mat);
|
|
1664
|
+
const m = new _Mat3();
|
|
1280
1665
|
for (let index = 0; index < this._raw.length; index++)
|
|
1281
1666
|
m._raw[index] = this._raw[index] - b._raw[index];
|
|
1282
|
-
return
|
|
1667
|
+
return m;
|
|
1283
1668
|
}
|
|
1284
1669
|
multiply(a) {
|
|
1285
1670
|
if (check_number(a))
|
|
1286
|
-
return new
|
|
1671
|
+
return new _Mat3([
|
|
1287
1672
|
this.m00 * a,
|
|
1288
1673
|
this.m01 * a,
|
|
1289
1674
|
this.m02 * a,
|
|
@@ -1294,8 +1679,8 @@ class Mat3 {
|
|
|
1294
1679
|
this.m21 * a,
|
|
1295
1680
|
this.m22 * a
|
|
1296
1681
|
]);
|
|
1297
|
-
const b =
|
|
1298
|
-
return new
|
|
1682
|
+
const b = _Mat3.resolve(a);
|
|
1683
|
+
return new _Mat3([
|
|
1299
1684
|
b.m00 * this.m00 + b.m01 * this.m10 + b.m02 * this.m20,
|
|
1300
1685
|
b.m00 * this.m01 + b.m01 * this.m11 + b.m02 * this.m21,
|
|
1301
1686
|
b.m00 * this.m02 + b.m01 * this.m12 + b.m02 * this.m22,
|
|
@@ -1355,7 +1740,7 @@ class Mat3 {
|
|
|
1355
1740
|
}
|
|
1356
1741
|
inverse() {
|
|
1357
1742
|
const det = this.determinant();
|
|
1358
|
-
return new
|
|
1743
|
+
return new _Mat3([
|
|
1359
1744
|
(this.m11 * this.m22 - this.m21 * this.m12) * det,
|
|
1360
1745
|
(this.m02 * this.m21 - this.m01 * this.m22) * det,
|
|
1361
1746
|
(this.m01 * this.m12 - this.m02 * this.m11) * det,
|
|
@@ -1387,9 +1772,10 @@ class Mat3 {
|
|
|
1387
1772
|
1
|
|
1388
1773
|
];
|
|
1389
1774
|
}
|
|
1390
|
-
}
|
|
1775
|
+
};
|
|
1391
1776
|
|
|
1392
|
-
|
|
1777
|
+
// source/matrices/mat4.ts
|
|
1778
|
+
var Mat4 = class _Mat4 {
|
|
1393
1779
|
_raw;
|
|
1394
1780
|
get m00() {
|
|
1395
1781
|
return this._raw[0];
|
|
@@ -1495,11 +1881,11 @@ class Mat4 {
|
|
|
1495
1881
|
}
|
|
1496
1882
|
static cast(a) {
|
|
1497
1883
|
if (a == null || typeof a == "undefined")
|
|
1498
|
-
return
|
|
1884
|
+
return void 0;
|
|
1499
1885
|
if (check_number_array(a, 16)) {
|
|
1500
1886
|
return new this(a);
|
|
1501
1887
|
}
|
|
1502
|
-
if (check_array(a,
|
|
1888
|
+
if (check_array(a, void 0, 4)) {
|
|
1503
1889
|
const row0 = a[0], row1 = a[1], row2 = a[2], row3 = a[3];
|
|
1504
1890
|
if (check_number_array(row0, 4) && check_number_array(row1, 4) && check_number_array(row2, 4) && check_number_array(row3, 4))
|
|
1505
1891
|
return new this([
|
|
@@ -1548,7 +1934,7 @@ class Mat4 {
|
|
|
1548
1934
|
if (check_number(a)) {
|
|
1549
1935
|
return new this([a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a]);
|
|
1550
1936
|
}
|
|
1551
|
-
return
|
|
1937
|
+
return void 0;
|
|
1552
1938
|
}
|
|
1553
1939
|
static is(a) {
|
|
1554
1940
|
return typeof this.cast(a) != "undefined";
|
|
@@ -1677,7 +2063,7 @@ class Mat4 {
|
|
|
1677
2063
|
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}`;
|
|
1678
2064
|
}
|
|
1679
2065
|
clone() {
|
|
1680
|
-
return new
|
|
2066
|
+
return new _Mat4([
|
|
1681
2067
|
this.m00,
|
|
1682
2068
|
this.m01,
|
|
1683
2069
|
this.m02,
|
|
@@ -1697,29 +2083,29 @@ class Mat4 {
|
|
|
1697
2083
|
]);
|
|
1698
2084
|
}
|
|
1699
2085
|
equals(mat) {
|
|
1700
|
-
const m =
|
|
2086
|
+
const m = _Mat4.resolve(mat);
|
|
1701
2087
|
for (let index = 0; index < this._raw.length; index++)
|
|
1702
2088
|
if (this._raw[index] != m._raw[index])
|
|
1703
2089
|
return false;
|
|
1704
2090
|
return true;
|
|
1705
2091
|
}
|
|
1706
2092
|
add(mat) {
|
|
1707
|
-
const b =
|
|
1708
|
-
const m = new
|
|
2093
|
+
const b = _Mat4.resolve(mat);
|
|
2094
|
+
const m = new _Mat4();
|
|
1709
2095
|
for (let index = 0; index < this._raw.length; index++)
|
|
1710
2096
|
m._raw[index] = this._raw[index] + b._raw[index];
|
|
1711
2097
|
return m;
|
|
1712
2098
|
}
|
|
1713
2099
|
subtract(mat) {
|
|
1714
|
-
const b =
|
|
1715
|
-
const m = new
|
|
2100
|
+
const b = _Mat4.resolve(mat);
|
|
2101
|
+
const m = new _Mat4();
|
|
1716
2102
|
for (let index = 0; index < this._raw.length; index++)
|
|
1717
2103
|
m._raw[index] = this._raw[index] - b._raw[index];
|
|
1718
2104
|
return m;
|
|
1719
2105
|
}
|
|
1720
2106
|
multiply(a) {
|
|
1721
2107
|
if (check_number(a)) {
|
|
1722
|
-
return new
|
|
2108
|
+
return new _Mat4([
|
|
1723
2109
|
this.m00 * a,
|
|
1724
2110
|
this.m01 * a,
|
|
1725
2111
|
this.m02 * a,
|
|
@@ -1738,9 +2124,9 @@ class Mat4 {
|
|
|
1738
2124
|
this.m33 * a
|
|
1739
2125
|
]);
|
|
1740
2126
|
}
|
|
1741
|
-
if (
|
|
1742
|
-
const b =
|
|
1743
|
-
return new
|
|
2127
|
+
if (_Mat4.is(a)) {
|
|
2128
|
+
const b = _Mat4.resolve(a);
|
|
2129
|
+
return new _Mat4([
|
|
1744
2130
|
b.m00 * this.m00 + b.m01 * this.m10 + b.m02 * this.m20 + b.m03 * this.m30,
|
|
1745
2131
|
b.m00 * this.m01 + b.m01 * this.m11 + b.m02 * this.m21 + b.m03 * this.m31,
|
|
1746
2132
|
b.m00 * this.m02 + b.m01 * this.m12 + b.m02 * this.m22 + b.m03 * this.m32,
|
|
@@ -1886,7 +2272,7 @@ class Mat4 {
|
|
|
1886
2272
|
]);
|
|
1887
2273
|
}
|
|
1888
2274
|
inverse() {
|
|
1889
|
-
return new
|
|
2275
|
+
return new _Mat4([
|
|
1890
2276
|
this.m00,
|
|
1891
2277
|
this.m10,
|
|
1892
2278
|
this.m20,
|
|
@@ -1918,11 +2304,12 @@ class Mat4 {
|
|
|
1918
2304
|
this.m33
|
|
1919
2305
|
];
|
|
1920
2306
|
}
|
|
1921
|
-
}
|
|
2307
|
+
};
|
|
1922
2308
|
|
|
2309
|
+
// source/color.ts
|
|
1923
2310
|
function _hex_to_array(hex) {
|
|
1924
2311
|
if (!check_hex(hex))
|
|
1925
|
-
return
|
|
2312
|
+
return void 0;
|
|
1926
2313
|
const part = get_hex_part(hex);
|
|
1927
2314
|
const a = parseInt(part.substring(0, 2), 16) / 255;
|
|
1928
2315
|
const b = parseInt(part.substring(2, 4), 16) / 255;
|
|
@@ -1946,7 +2333,7 @@ function _number_to_rgba(number) {
|
|
|
1946
2333
|
function _fix_integer(number) {
|
|
1947
2334
|
return number * 255 | 0;
|
|
1948
2335
|
}
|
|
1949
|
-
|
|
2336
|
+
var RGBAColor = class _RGBAColor {
|
|
1950
2337
|
_red;
|
|
1951
2338
|
get red() {
|
|
1952
2339
|
return this._red;
|
|
@@ -1983,11 +2370,11 @@ class RGBAColor {
|
|
|
1983
2370
|
}
|
|
1984
2371
|
static cast(a) {
|
|
1985
2372
|
if (a == null || typeof a == "undefined")
|
|
1986
|
-
return
|
|
2373
|
+
return void 0;
|
|
1987
2374
|
if (check_number_array(a, 3) || check_number_array(a, 4))
|
|
1988
2375
|
return new this(a[0], a[1], a[2], a[3]);
|
|
1989
2376
|
if (has_property(a, "red", "number") && has_property(a, "green", "number") && has_property(a, "blue", "number"))
|
|
1990
|
-
return new this(a.red, a.green, a.blue, has_property(a, "alpha", "number") ? a.alpha :
|
|
2377
|
+
return new this(a.red, a.green, a.blue, has_property(a, "alpha", "number") ? a.alpha : void 0);
|
|
1991
2378
|
if (check_number(a)) {
|
|
1992
2379
|
const hex = a.toString(16);
|
|
1993
2380
|
const convert = hex.length <= 6 ? _number_to_rgb : _number_to_rgba;
|
|
@@ -2003,7 +2390,7 @@ class RGBAColor {
|
|
|
2003
2390
|
}
|
|
2004
2391
|
return this.cast(_hex_to_array(a));
|
|
2005
2392
|
}
|
|
2006
|
-
return
|
|
2393
|
+
return void 0;
|
|
2007
2394
|
}
|
|
2008
2395
|
static is(a) {
|
|
2009
2396
|
return typeof this.cast(a) != "undefined";
|
|
@@ -2026,14 +2413,14 @@ class RGBAColor {
|
|
|
2026
2413
|
} : this.alpha == 1 ? { red: this.red, green: this.green, blue: this.blue } : this.toJSON(true);
|
|
2027
2414
|
}
|
|
2028
2415
|
toString(withAlpha = false) {
|
|
2029
|
-
return withAlpha ? `rgba(${_fix_integer(this.red)},${_fix_integer(this.green)},${_fix_integer(this.blue)},${
|
|
2416
|
+
return withAlpha ? `rgba(${_fix_integer(this.red)},${_fix_integer(this.green)},${_fix_integer(this.blue)},${this.alpha})` : this.alpha == 1 ? `rgb(${_fix_integer(this.red)},${_fix_integer(this.green)},${_fix_integer(this.blue)})` : this.toString(true);
|
|
2030
2417
|
}
|
|
2031
2418
|
toHSL(withAlpha = true) {
|
|
2032
2419
|
const red = this.red, green = this.green, blue = this.blue;
|
|
2033
2420
|
const min = Math.min(red, green, blue), max = Math.max(red, green, blue);
|
|
2034
2421
|
const luminace = (min + max) / 2;
|
|
2035
2422
|
if (min == max)
|
|
2036
|
-
return new HSLColor(0, 0, luminace, withAlpha ? this.alpha :
|
|
2423
|
+
return new HSLColor(0, 0, luminace, withAlpha ? this.alpha : void 0);
|
|
2037
2424
|
const d = max - min;
|
|
2038
2425
|
const saturation = luminace > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
2039
2426
|
if (max == red)
|
|
@@ -2042,18 +2429,18 @@ class RGBAColor {
|
|
|
2042
2429
|
return new HSLColor(((blue - red) / d + 2) / 6, saturation, luminace);
|
|
2043
2430
|
if (max == blue)
|
|
2044
2431
|
return new HSLColor(((red - green) / d + 4) / 6, saturation, luminace);
|
|
2045
|
-
return new HSLColor(0, saturation, luminace, withAlpha ? this.alpha :
|
|
2432
|
+
return new HSLColor(0, saturation, luminace, withAlpha ? this.alpha : void 0);
|
|
2046
2433
|
}
|
|
2047
2434
|
invert(withAlpha = false) {
|
|
2048
|
-
return new
|
|
2435
|
+
return new _RGBAColor(
|
|
2049
2436
|
1 - this.red,
|
|
2050
2437
|
1 - this.green,
|
|
2051
2438
|
1 - this.blue,
|
|
2052
2439
|
withAlpha ? 1 - this.alpha : this.alpha
|
|
2053
2440
|
);
|
|
2054
2441
|
}
|
|
2055
|
-
}
|
|
2056
|
-
|
|
2442
|
+
};
|
|
2443
|
+
var HSLColor = class _HSLColor {
|
|
2057
2444
|
_hue;
|
|
2058
2445
|
get hue() {
|
|
2059
2446
|
return this._hue;
|
|
@@ -2090,11 +2477,11 @@ class HSLColor {
|
|
|
2090
2477
|
}
|
|
2091
2478
|
static cast(a) {
|
|
2092
2479
|
if (a == null || typeof a == "undefined")
|
|
2093
|
-
return
|
|
2480
|
+
return void 0;
|
|
2094
2481
|
if (check_number_array(a, 3) || check_number_array(a, 4))
|
|
2095
2482
|
return new this(a[0], a[1], a[2], a[3]);
|
|
2096
2483
|
if (has_property(a, "hue", "number") && has_property(a, "saturation", "number") && has_property(a, "luminace", "number"))
|
|
2097
|
-
return new this(a.hue, a.saturation, a.luminace, has_property(a, "alpha", "number") ? a.alpha :
|
|
2484
|
+
return new this(a.hue, a.saturation, a.luminace, has_property(a, "alpha", "number") ? a.alpha : void 0);
|
|
2098
2485
|
if (check_number(a)) {
|
|
2099
2486
|
const hex = a.toString(16);
|
|
2100
2487
|
const convert = hex.length <= 6 ? _number_to_rgb : _number_to_rgba;
|
|
@@ -2110,7 +2497,7 @@ class HSLColor {
|
|
|
2110
2497
|
}
|
|
2111
2498
|
return this.cast(_hex_to_array(a));
|
|
2112
2499
|
}
|
|
2113
|
-
return
|
|
2500
|
+
return void 0;
|
|
2114
2501
|
}
|
|
2115
2502
|
static is(a) {
|
|
2116
2503
|
return typeof this.cast(a) != "undefined";
|
|
@@ -2141,11 +2528,11 @@ class HSLColor {
|
|
|
2141
2528
|
} : this.alpha == 1 ? { hue: this.hue, saturation: this.saturation, luminace: this.luminace } : this.toJSON(true);
|
|
2142
2529
|
}
|
|
2143
2530
|
toString(withAlpha = false) {
|
|
2144
|
-
return withAlpha ? `hsla(${_fix_integer(this.hue)},${_fix_integer(this.saturation)},${_fix_integer(this.luminace)},${
|
|
2531
|
+
return withAlpha ? `hsla(${_fix_integer(this.hue)},${_fix_integer(this.saturation)},${_fix_integer(this.luminace)},${this.alpha})` : this.alpha == 1 ? `hsl(${_fix_integer(this.hue)},${_fix_integer(this.saturation)},${_fix_integer(this.luminace)})` : this.toString(true);
|
|
2145
2532
|
}
|
|
2146
2533
|
toRGB(withAlpha = true) {
|
|
2147
2534
|
if (this.saturation == 0)
|
|
2148
|
-
return new RGBAColor(this.luminace * 255, this.luminace * 255, this.luminace * 255, withAlpha ? this.alpha :
|
|
2535
|
+
return new RGBAColor(this.luminace * 255, this.luminace * 255, this.luminace * 255, withAlpha ? this.alpha : void 0);
|
|
2149
2536
|
const q = this.luminace < 0.5 ? this.luminace * (1 + this.saturation) : this.luminace + this.saturation - this.luminace * this.saturation;
|
|
2150
2537
|
const p = 2 * this.luminace - q;
|
|
2151
2538
|
function _hue_2_rgb(t) {
|
|
@@ -2162,17 +2549,17 @@ class HSLColor {
|
|
|
2162
2549
|
return p + (q - p) * (2 / 3 - _t) * 6;
|
|
2163
2550
|
return p;
|
|
2164
2551
|
}
|
|
2165
|
-
return new RGBAColor(_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 :
|
|
2552
|
+
return new RGBAColor(_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);
|
|
2166
2553
|
}
|
|
2167
2554
|
invert(withAlpha = false) {
|
|
2168
|
-
return new
|
|
2555
|
+
return new _HSLColor(
|
|
2169
2556
|
1 - this.hue,
|
|
2170
2557
|
1 - this.saturation,
|
|
2171
2558
|
1 - this.luminace,
|
|
2172
2559
|
withAlpha ? 1 - this.alpha : this.alpha
|
|
2173
2560
|
);
|
|
2174
2561
|
}
|
|
2175
|
-
}
|
|
2562
|
+
};
|
|
2176
2563
|
function resolveColor(a, preferHSL = false) {
|
|
2177
2564
|
const value = castColor(a, preferHSL);
|
|
2178
2565
|
if (typeof value != "undefined")
|
|
@@ -2198,10 +2585,11 @@ function castColor(a, preferHSL = false) {
|
|
|
2198
2585
|
const secondItem = results[offset + 1];
|
|
2199
2586
|
if (secondItem)
|
|
2200
2587
|
return secondItem;
|
|
2201
|
-
return
|
|
2588
|
+
return void 0;
|
|
2202
2589
|
}
|
|
2203
2590
|
|
|
2204
|
-
|
|
2591
|
+
// source/quaternion.ts
|
|
2592
|
+
var Quaternion = class _Quaternion {
|
|
2205
2593
|
w;
|
|
2206
2594
|
x;
|
|
2207
2595
|
y;
|
|
@@ -2217,7 +2605,7 @@ class Quaternion {
|
|
|
2217
2605
|
}
|
|
2218
2606
|
static cast(a) {
|
|
2219
2607
|
if (a == null || typeof a == "undefined")
|
|
2220
|
-
return
|
|
2608
|
+
return void 0;
|
|
2221
2609
|
if (check_number_array(a, 4))
|
|
2222
2610
|
return new this(a[0], a[1], a[2], a[3]);
|
|
2223
2611
|
if (has_property(a, "w", "number") && has_property(a, "x", "number") && has_property(a, "y", "number") && has_property(a, "z", "number"))
|
|
@@ -2235,7 +2623,7 @@ class Quaternion {
|
|
|
2235
2623
|
]);
|
|
2236
2624
|
}
|
|
2237
2625
|
}
|
|
2238
|
-
return
|
|
2626
|
+
return void 0;
|
|
2239
2627
|
}
|
|
2240
2628
|
static fromAxisAngle(axis, angle) {
|
|
2241
2629
|
const vec = Vec3.resolve(axis);
|
|
@@ -2250,7 +2638,7 @@ class Quaternion {
|
|
|
2250
2638
|
const x2 = vec.x * 0.5, y2 = vec.y * 0.5, z2 = vec.z * 0.5;
|
|
2251
2639
|
const cx = Math.cos(x2), cy = Math.cos(y2), cz = Math.cos(z2);
|
|
2252
2640
|
const sx = Math.sin(x2), sy = Math.sin(y2), sz = Math.sin(z2);
|
|
2253
|
-
return new
|
|
2641
|
+
return new _Quaternion(
|
|
2254
2642
|
cx * cy * cz - sx * sy * sz,
|
|
2255
2643
|
sx * cy * cz - sy * sz * cx,
|
|
2256
2644
|
sy * cx * cz - sx * sz * cy,
|
|
@@ -2286,11 +2674,11 @@ class Quaternion {
|
|
|
2286
2674
|
};
|
|
2287
2675
|
}
|
|
2288
2676
|
clone() {
|
|
2289
|
-
return new
|
|
2677
|
+
return new _Quaternion(this.w, this.x, this.y, this.z);
|
|
2290
2678
|
}
|
|
2291
2679
|
add(a) {
|
|
2292
|
-
const quat =
|
|
2293
|
-
return new
|
|
2680
|
+
const quat = _Quaternion.resolve(a);
|
|
2681
|
+
return new _Quaternion(
|
|
2294
2682
|
this.w + quat.w,
|
|
2295
2683
|
this.x + quat.x,
|
|
2296
2684
|
this.y + quat.y,
|
|
@@ -2298,7 +2686,7 @@ class Quaternion {
|
|
|
2298
2686
|
);
|
|
2299
2687
|
}
|
|
2300
2688
|
offset(a) {
|
|
2301
|
-
const quat =
|
|
2689
|
+
const quat = _Quaternion.resolve(a);
|
|
2302
2690
|
this.w += quat.w;
|
|
2303
2691
|
this.x += quat.x;
|
|
2304
2692
|
this.y += quat.y;
|
|
@@ -2306,8 +2694,8 @@ class Quaternion {
|
|
|
2306
2694
|
return this;
|
|
2307
2695
|
}
|
|
2308
2696
|
subtract(a) {
|
|
2309
|
-
const quat =
|
|
2310
|
-
return new
|
|
2697
|
+
const quat = _Quaternion.resolve(a);
|
|
2698
|
+
return new _Quaternion(
|
|
2311
2699
|
this.w - quat.w,
|
|
2312
2700
|
this.x - quat.x,
|
|
2313
2701
|
this.y - quat.y,
|
|
@@ -2315,7 +2703,7 @@ class Quaternion {
|
|
|
2315
2703
|
);
|
|
2316
2704
|
}
|
|
2317
2705
|
negative() {
|
|
2318
|
-
return new
|
|
2706
|
+
return new _Quaternion(-this.w, -this.x, -this.y, -this.z);
|
|
2319
2707
|
}
|
|
2320
2708
|
length(sqrt = true) {
|
|
2321
2709
|
const value = this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z;
|
|
@@ -2324,13 +2712,13 @@ class Quaternion {
|
|
|
2324
2712
|
normalize() {
|
|
2325
2713
|
let length = this.length();
|
|
2326
2714
|
if (length < EPSILON)
|
|
2327
|
-
return new
|
|
2715
|
+
return new _Quaternion();
|
|
2328
2716
|
length = 1 / length;
|
|
2329
|
-
return new
|
|
2717
|
+
return new _Quaternion(this.w * length, this.x * length, this.y * length, this.z * length);
|
|
2330
2718
|
}
|
|
2331
2719
|
multiply(a) {
|
|
2332
|
-
const quat =
|
|
2333
|
-
return new
|
|
2720
|
+
const quat = _Quaternion.resolve(a);
|
|
2721
|
+
return new _Quaternion(
|
|
2334
2722
|
this.w * quat.w - this.x * quat.x - this.y * quat.y - this.z * quat.z,
|
|
2335
2723
|
this.w * quat.x + this.x * quat.w + this.y * quat.z - this.z * quat.y,
|
|
2336
2724
|
this.w * quat.y + this.y * quat.w + this.z * quat.x - this.x * quat.z,
|
|
@@ -2350,25 +2738,25 @@ class Quaternion {
|
|
|
2350
2738
|
);
|
|
2351
2739
|
}
|
|
2352
2740
|
scale(scalar) {
|
|
2353
|
-
return new
|
|
2741
|
+
return new _Quaternion(this.w * scalar, this.x * scalar, this.y * scalar, this.z * scalar);
|
|
2354
2742
|
}
|
|
2355
2743
|
dot(a) {
|
|
2356
|
-
const quat =
|
|
2744
|
+
const quat = _Quaternion.resolve(a);
|
|
2357
2745
|
return this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z;
|
|
2358
2746
|
}
|
|
2359
2747
|
inverse() {
|
|
2360
2748
|
let length = this.length(false);
|
|
2361
2749
|
if (length == 0)
|
|
2362
|
-
return new
|
|
2750
|
+
return new _Quaternion();
|
|
2363
2751
|
length = 1 / length;
|
|
2364
|
-
return new
|
|
2752
|
+
return new _Quaternion(this.w * length, -this.x * length, -this.y * length, -this.z * length);
|
|
2365
2753
|
}
|
|
2366
2754
|
divide(a) {
|
|
2367
|
-
const quat =
|
|
2755
|
+
const quat = _Quaternion.resolve(a);
|
|
2368
2756
|
let length = quat.length(false);
|
|
2369
|
-
if (length == 0) return new
|
|
2757
|
+
if (length == 0) return new _Quaternion();
|
|
2370
2758
|
length = 1 / length;
|
|
2371
|
-
return new
|
|
2759
|
+
return new _Quaternion(
|
|
2372
2760
|
(this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z) * length,
|
|
2373
2761
|
(this.x * quat.w - this.w * quat.x - this.y * quat.z + this.z * quat.y) * length,
|
|
2374
2762
|
(this.y * quat.w - this.w * quat.y - this.z * quat.x + this.x * quat.z) * length,
|
|
@@ -2376,15 +2764,15 @@ class Quaternion {
|
|
|
2376
2764
|
);
|
|
2377
2765
|
}
|
|
2378
2766
|
conjugate() {
|
|
2379
|
-
return new
|
|
2767
|
+
return new _Quaternion(this.w, -this.x, -this.y, -this.z);
|
|
2380
2768
|
}
|
|
2381
2769
|
exp() {
|
|
2382
2770
|
const length = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
|
2383
2771
|
const exp = Math.exp(this.w);
|
|
2384
2772
|
const scale = exp * Math.sin(length) / length;
|
|
2385
2773
|
if (length == 0)
|
|
2386
|
-
return new
|
|
2387
|
-
return new
|
|
2774
|
+
return new _Quaternion(exp);
|
|
2775
|
+
return new _Quaternion(
|
|
2388
2776
|
exp * Math.cos(length),
|
|
2389
2777
|
this.x * scale,
|
|
2390
2778
|
this.y * scale,
|
|
@@ -2393,11 +2781,11 @@ class Quaternion {
|
|
|
2393
2781
|
}
|
|
2394
2782
|
log() {
|
|
2395
2783
|
if (this.x == 0 && this.z == 0)
|
|
2396
|
-
return new
|
|
2784
|
+
return new _Quaternion(log_hypot(this.w, this.x), Math.atan2(this.x, this.w));
|
|
2397
2785
|
const length = this.length(false);
|
|
2398
2786
|
const length2 = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
|
2399
2787
|
const scale = Math.atan2(length2, this.w) / length;
|
|
2400
|
-
return new
|
|
2788
|
+
return new _Quaternion(Math.log(length) * 0.5, this.x * scale, this.y * scale, this.z * scale);
|
|
2401
2789
|
}
|
|
2402
2790
|
toVector() {
|
|
2403
2791
|
return new Vec3(this.x, this.y, this.z, this.w);
|
|
@@ -2453,9 +2841,10 @@ class Quaternion {
|
|
|
2453
2841
|
1
|
|
2454
2842
|
]);
|
|
2455
2843
|
}
|
|
2456
|
-
}
|
|
2844
|
+
};
|
|
2457
2845
|
|
|
2458
|
-
|
|
2846
|
+
// source/transform.ts
|
|
2847
|
+
var Transform = class {
|
|
2459
2848
|
/**
|
|
2460
2849
|
* The position of the object
|
|
2461
2850
|
*/
|
|
@@ -2486,51 +2875,4 @@ class Transform {
|
|
|
2486
2875
|
toMat4() {
|
|
2487
2876
|
return new Mat4().translate(this.position).multiply(this.rotation.toMat4()).scale(this.scale);
|
|
2488
2877
|
}
|
|
2489
|
-
}
|
|
2490
|
-
|
|
2491
|
-
exports.ATriangle = ATriangle;
|
|
2492
|
-
exports.BoundingBox = BoundingBox;
|
|
2493
|
-
exports.Circle = Circle;
|
|
2494
|
-
exports.DJB2_OFFSET = DJB2_OFFSET;
|
|
2495
|
-
exports.EPSILON = EPSILON;
|
|
2496
|
-
exports.FNV1_OFFSET = FNV1_OFFSET;
|
|
2497
|
-
exports.FNV1_PRIME = FNV1_PRIME;
|
|
2498
|
-
exports.HSLColor = HSLColor;
|
|
2499
|
-
exports.LinearFunction = LinearFunction;
|
|
2500
|
-
exports.MAX_ANGLE_DEGREE = MAX_ANGLE_DEGREE;
|
|
2501
|
-
exports.Mat3 = Mat3;
|
|
2502
|
-
exports.Mat4 = Mat4;
|
|
2503
|
-
exports.MathFunction = MathFunction;
|
|
2504
|
-
exports.QuadFunction = QuadFunction;
|
|
2505
|
-
exports.Quaternion = Quaternion;
|
|
2506
|
-
exports.RGBAColor = RGBAColor;
|
|
2507
|
-
exports.Rectangle = Rectangle;
|
|
2508
|
-
exports.ResolveError = ResolveError;
|
|
2509
|
-
exports.Size = Size;
|
|
2510
|
-
exports.Transform = Transform;
|
|
2511
|
-
exports.Triangle2D = Triangle2D;
|
|
2512
|
-
exports.Triangle3D = Triangle3D;
|
|
2513
|
-
exports.Vec2 = Vec2;
|
|
2514
|
-
exports.Vec3 = Vec3;
|
|
2515
|
-
exports.cap_angle_degree = cap_angle_degree;
|
|
2516
|
-
exports.cap_angle_radian = cap_angle_radian;
|
|
2517
|
-
exports.castColor = castColor;
|
|
2518
|
-
exports.check_array = check_array;
|
|
2519
|
-
exports.check_hex = check_hex;
|
|
2520
|
-
exports.check_hex_digit = check_hex_digit;
|
|
2521
|
-
exports.check_number = check_number;
|
|
2522
|
-
exports.check_number_array = check_number_array;
|
|
2523
|
-
exports.check_string = check_string;
|
|
2524
|
-
exports.check_string_array = check_string_array;
|
|
2525
|
-
exports.clamp = clamp;
|
|
2526
|
-
exports.degree_to_radian = degree_to_radian;
|
|
2527
|
-
exports.djb2 = djb2;
|
|
2528
|
-
exports.fnv1 = fnv1;
|
|
2529
|
-
exports.get_hex_part = get_hex_part;
|
|
2530
|
-
exports.has_property = has_property;
|
|
2531
|
-
exports.log_hypot = log_hypot;
|
|
2532
|
-
exports.radian_to_degree = radian_to_degree;
|
|
2533
|
-
exports.resolveColor = resolveColor;
|
|
2534
|
-
exports.sdbm = sdbm;
|
|
2535
|
-
exports.sign_char = sign_char;
|
|
2536
|
-
exports.stringify = stringify;
|
|
2878
|
+
};
|