@ntf/math 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +19 -3
- package/dist/{index.d.cts → index.d.ts} +19 -3
- package/dist/{index.cjs → index.js} +600 -244
- package/dist/index.mjs +578 -198
- 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,7 +1257,7 @@ 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
1262
|
return new this(a[0], a[1], a[2], a[3]);
|
|
867
1263
|
if (check_number_array(a, 5)) {
|
|
@@ -874,7 +1270,7 @@ 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
|
|
1273
|
+
return void 0;
|
|
878
1274
|
const rect = new this(pos.x, pos.y, size.width, size.height);
|
|
879
1275
|
rect.w = pos.w;
|
|
880
1276
|
return rect;
|
|
@@ -885,14 +1281,14 @@ class Rectangle {
|
|
|
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
1289
|
constructor(a, b, c, d) {
|
|
894
|
-
const vec = Vec2.is(a) ? Vec2.resolve(a) :
|
|
895
|
-
const size = Size.is(b) ? Size.resolve(b) :
|
|
1290
|
+
const vec = Vec2.is(a) ? Vec2.resolve(a) : void 0;
|
|
1291
|
+
const size = Size.is(b) ? Size.resolve(b) : void 0;
|
|
896
1292
|
const x = typeof a == "number" ? a : vec?.x;
|
|
897
1293
|
if (!check_number(x))
|
|
898
1294
|
throw new TypeError("expected number for x position");
|
|
@@ -921,15 +1317,16 @@ class Rectangle {
|
|
|
921
1317
|
return [this.x, this.x + this.width, this.y, this.y + this.height];
|
|
922
1318
|
}
|
|
923
1319
|
clone() {
|
|
924
|
-
return new
|
|
1320
|
+
return new _Rectangle(this.position.clone(), this.size.clone());
|
|
925
1321
|
}
|
|
926
1322
|
equals(rectangle) {
|
|
927
|
-
const rect =
|
|
1323
|
+
const rect = _Rectangle.resolve(rectangle);
|
|
928
1324
|
return this.position.equals(rect.position) && this.size.equals(rect.size);
|
|
929
1325
|
}
|
|
930
|
-
}
|
|
1326
|
+
};
|
|
931
1327
|
|
|
932
|
-
|
|
1328
|
+
// source/geometry/bbox.ts
|
|
1329
|
+
var BoundingBox = class _BoundingBox {
|
|
933
1330
|
left;
|
|
934
1331
|
right;
|
|
935
1332
|
top;
|
|
@@ -954,7 +1351,7 @@ class BoundingBox {
|
|
|
954
1351
|
}
|
|
955
1352
|
static cast(a) {
|
|
956
1353
|
if (a == null || typeof a == "undefined")
|
|
957
|
-
return
|
|
1354
|
+
return void 0;
|
|
958
1355
|
if (check_number_array(a, 4))
|
|
959
1356
|
return new this(a[0], a[1], a[2], a[3]);
|
|
960
1357
|
if (has_property(a, "left", "number") && has_property(a, "right", "number") && has_property(a, "top", "number") && has_property(a, "bottom", "number"))
|
|
@@ -964,7 +1361,7 @@ class BoundingBox {
|
|
|
964
1361
|
if (check_string_array(parts, 4))
|
|
965
1362
|
return this.cast(parts.map((v) => parseFloat(v)));
|
|
966
1363
|
}
|
|
967
|
-
return
|
|
1364
|
+
return void 0;
|
|
968
1365
|
}
|
|
969
1366
|
static is(a) {
|
|
970
1367
|
return typeof this.cast(a) != "undefined";
|
|
@@ -998,10 +1395,10 @@ class BoundingBox {
|
|
|
998
1395
|
};
|
|
999
1396
|
}
|
|
1000
1397
|
clone() {
|
|
1001
|
-
return new
|
|
1398
|
+
return new _BoundingBox(this.left, this.right, this.top, this.bottom);
|
|
1002
1399
|
}
|
|
1003
1400
|
equals(bbox) {
|
|
1004
|
-
const b =
|
|
1401
|
+
const b = _BoundingBox.resolve(bbox);
|
|
1005
1402
|
return this.left == b.left && this.right == b.right && this.top == b.top && this.bottom == b.bottom;
|
|
1006
1403
|
}
|
|
1007
1404
|
toSquare() {
|
|
@@ -1011,12 +1408,12 @@ class BoundingBox {
|
|
|
1011
1408
|
return new Rectangle(this.left, this.top, this.width, this.height);
|
|
1012
1409
|
}
|
|
1013
1410
|
inside(a) {
|
|
1014
|
-
const bbox =
|
|
1411
|
+
const bbox = _BoundingBox.resolve(a);
|
|
1015
1412
|
return this.right >= bbox.left && bbox.right >= this.left && this.bottom >= bbox.top && bbox.bottom >= this.top;
|
|
1016
1413
|
}
|
|
1017
1414
|
insidePoint(a) {
|
|
1018
1415
|
const point = Vec2.resolve(a);
|
|
1019
|
-
return this.left <= point.x && this.right >= point.x && this.top
|
|
1416
|
+
return this.left <= point.x && this.right >= point.x && this.top <= point.y && this.bottom >= point.y;
|
|
1020
1417
|
}
|
|
1021
1418
|
insideCircle(a) {
|
|
1022
1419
|
const circle = Circle.resolve(a);
|
|
@@ -1029,9 +1426,10 @@ class BoundingBox {
|
|
|
1029
1426
|
diff = closest.subtract(center);
|
|
1030
1427
|
return diff.length() < circle.radius;
|
|
1031
1428
|
}
|
|
1032
|
-
}
|
|
1429
|
+
};
|
|
1033
1430
|
|
|
1034
|
-
|
|
1431
|
+
// source/geometry/triangle.ts
|
|
1432
|
+
var ATriangle = class {
|
|
1035
1433
|
constructor(A, B, C) {
|
|
1036
1434
|
this.A = A;
|
|
1037
1435
|
this.B = B;
|
|
@@ -1061,8 +1459,8 @@ class ATriangle {
|
|
|
1061
1459
|
get height() {
|
|
1062
1460
|
return 2 * (this.area / this.base);
|
|
1063
1461
|
}
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1462
|
+
};
|
|
1463
|
+
var Triangle2D = class extends ATriangle {
|
|
1066
1464
|
get a() {
|
|
1067
1465
|
return Vec2.fromPoints(this.B, this.C).length();
|
|
1068
1466
|
}
|
|
@@ -1072,8 +1470,8 @@ class Triangle2D extends ATriangle {
|
|
|
1072
1470
|
get c() {
|
|
1073
1471
|
return Vec2.fromPoints(this.A, this.B).length();
|
|
1074
1472
|
}
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1473
|
+
};
|
|
1474
|
+
var Triangle3D = class extends ATriangle {
|
|
1077
1475
|
get a() {
|
|
1078
1476
|
return Vec3.fromPoints(this.B, this.C).length();
|
|
1079
1477
|
}
|
|
@@ -1083,9 +1481,10 @@ class Triangle3D extends ATriangle {
|
|
|
1083
1481
|
get c() {
|
|
1084
1482
|
return Vec3.fromPoints(this.A, this.B).length();
|
|
1085
1483
|
}
|
|
1086
|
-
}
|
|
1484
|
+
};
|
|
1087
1485
|
|
|
1088
|
-
|
|
1486
|
+
// source/matrices/mat3.ts
|
|
1487
|
+
var Mat3 = class _Mat3 {
|
|
1089
1488
|
_raw;
|
|
1090
1489
|
get m00() {
|
|
1091
1490
|
return this._raw[0];
|
|
@@ -1149,11 +1548,11 @@ class Mat3 {
|
|
|
1149
1548
|
}
|
|
1150
1549
|
static cast(a) {
|
|
1151
1550
|
if (a == null || typeof a == "undefined")
|
|
1152
|
-
return
|
|
1551
|
+
return void 0;
|
|
1153
1552
|
if (check_number_array(a, 9)) {
|
|
1154
1553
|
return new this(a);
|
|
1155
1554
|
}
|
|
1156
|
-
if (check_array(a,
|
|
1555
|
+
if (check_array(a, void 0, 3)) {
|
|
1157
1556
|
const row0 = a[0], row1 = a[1], row2 = a[2];
|
|
1158
1557
|
if (check_number_array(row0, 3) && check_number_array(row1, 3) && check_number_array(row2, 3))
|
|
1159
1558
|
return new this([
|
|
@@ -1188,7 +1587,7 @@ class Mat3 {
|
|
|
1188
1587
|
if (check_number(a)) {
|
|
1189
1588
|
return new this([a, a, a, a, a, a, a, a, a]);
|
|
1190
1589
|
}
|
|
1191
|
-
return
|
|
1590
|
+
return void 0;
|
|
1192
1591
|
}
|
|
1193
1592
|
static is(a) {
|
|
1194
1593
|
return typeof this.cast(a) != "undefined";
|
|
@@ -1248,7 +1647,7 @@ class Mat3 {
|
|
|
1248
1647
|
return `${this.m00},${this.m01},${this.m02},${this.m10},${this.m11},${this.m12},${this.m20},${this.m21},${this.m22}`;
|
|
1249
1648
|
}
|
|
1250
1649
|
clone() {
|
|
1251
|
-
return new
|
|
1650
|
+
return new _Mat3([
|
|
1252
1651
|
this.m00,
|
|
1253
1652
|
this.m01,
|
|
1254
1653
|
this.m02,
|
|
@@ -1261,29 +1660,29 @@ class Mat3 {
|
|
|
1261
1660
|
]);
|
|
1262
1661
|
}
|
|
1263
1662
|
equals(mat) {
|
|
1264
|
-
const m =
|
|
1663
|
+
const m = _Mat3.resolve(mat);
|
|
1265
1664
|
for (let index = 0; index < this._raw.length; index++)
|
|
1266
1665
|
if (this._raw[index] != m._raw[index])
|
|
1267
1666
|
return false;
|
|
1268
1667
|
return true;
|
|
1269
1668
|
}
|
|
1270
1669
|
add(mat) {
|
|
1271
|
-
const b =
|
|
1272
|
-
const m = new
|
|
1670
|
+
const b = _Mat3.resolve(mat);
|
|
1671
|
+
const m = new _Mat3();
|
|
1273
1672
|
for (let index = 0; index < this._raw.length; index++)
|
|
1274
1673
|
m._raw[index] = this._raw[index] + b._raw[index];
|
|
1275
|
-
return
|
|
1674
|
+
return m;
|
|
1276
1675
|
}
|
|
1277
1676
|
subtract(mat) {
|
|
1278
|
-
const b =
|
|
1279
|
-
const m = new
|
|
1677
|
+
const b = _Mat3.resolve(mat);
|
|
1678
|
+
const m = new _Mat3();
|
|
1280
1679
|
for (let index = 0; index < this._raw.length; index++)
|
|
1281
1680
|
m._raw[index] = this._raw[index] - b._raw[index];
|
|
1282
|
-
return
|
|
1681
|
+
return m;
|
|
1283
1682
|
}
|
|
1284
1683
|
multiply(a) {
|
|
1285
1684
|
if (check_number(a))
|
|
1286
|
-
return new
|
|
1685
|
+
return new _Mat3([
|
|
1287
1686
|
this.m00 * a,
|
|
1288
1687
|
this.m01 * a,
|
|
1289
1688
|
this.m02 * a,
|
|
@@ -1294,8 +1693,8 @@ class Mat3 {
|
|
|
1294
1693
|
this.m21 * a,
|
|
1295
1694
|
this.m22 * a
|
|
1296
1695
|
]);
|
|
1297
|
-
const b =
|
|
1298
|
-
return new
|
|
1696
|
+
const b = _Mat3.resolve(a);
|
|
1697
|
+
return new _Mat3([
|
|
1299
1698
|
b.m00 * this.m00 + b.m01 * this.m10 + b.m02 * this.m20,
|
|
1300
1699
|
b.m00 * this.m01 + b.m01 * this.m11 + b.m02 * this.m21,
|
|
1301
1700
|
b.m00 * this.m02 + b.m01 * this.m12 + b.m02 * this.m22,
|
|
@@ -1355,7 +1754,7 @@ class Mat3 {
|
|
|
1355
1754
|
}
|
|
1356
1755
|
inverse() {
|
|
1357
1756
|
const det = this.determinant();
|
|
1358
|
-
return new
|
|
1757
|
+
return new _Mat3([
|
|
1359
1758
|
(this.m11 * this.m22 - this.m21 * this.m12) * det,
|
|
1360
1759
|
(this.m02 * this.m21 - this.m01 * this.m22) * det,
|
|
1361
1760
|
(this.m01 * this.m12 - this.m02 * this.m11) * det,
|
|
@@ -1387,9 +1786,10 @@ class Mat3 {
|
|
|
1387
1786
|
1
|
|
1388
1787
|
];
|
|
1389
1788
|
}
|
|
1390
|
-
}
|
|
1789
|
+
};
|
|
1391
1790
|
|
|
1392
|
-
|
|
1791
|
+
// source/matrices/mat4.ts
|
|
1792
|
+
var Mat4 = class _Mat4 {
|
|
1393
1793
|
_raw;
|
|
1394
1794
|
get m00() {
|
|
1395
1795
|
return this._raw[0];
|
|
@@ -1495,11 +1895,11 @@ class Mat4 {
|
|
|
1495
1895
|
}
|
|
1496
1896
|
static cast(a) {
|
|
1497
1897
|
if (a == null || typeof a == "undefined")
|
|
1498
|
-
return
|
|
1898
|
+
return void 0;
|
|
1499
1899
|
if (check_number_array(a, 16)) {
|
|
1500
1900
|
return new this(a);
|
|
1501
1901
|
}
|
|
1502
|
-
if (check_array(a,
|
|
1902
|
+
if (check_array(a, void 0, 4)) {
|
|
1503
1903
|
const row0 = a[0], row1 = a[1], row2 = a[2], row3 = a[3];
|
|
1504
1904
|
if (check_number_array(row0, 4) && check_number_array(row1, 4) && check_number_array(row2, 4) && check_number_array(row3, 4))
|
|
1505
1905
|
return new this([
|
|
@@ -1548,7 +1948,7 @@ class Mat4 {
|
|
|
1548
1948
|
if (check_number(a)) {
|
|
1549
1949
|
return new this([a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a]);
|
|
1550
1950
|
}
|
|
1551
|
-
return
|
|
1951
|
+
return void 0;
|
|
1552
1952
|
}
|
|
1553
1953
|
static is(a) {
|
|
1554
1954
|
return typeof this.cast(a) != "undefined";
|
|
@@ -1677,7 +2077,7 @@ class Mat4 {
|
|
|
1677
2077
|
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
2078
|
}
|
|
1679
2079
|
clone() {
|
|
1680
|
-
return new
|
|
2080
|
+
return new _Mat4([
|
|
1681
2081
|
this.m00,
|
|
1682
2082
|
this.m01,
|
|
1683
2083
|
this.m02,
|
|
@@ -1697,29 +2097,29 @@ class Mat4 {
|
|
|
1697
2097
|
]);
|
|
1698
2098
|
}
|
|
1699
2099
|
equals(mat) {
|
|
1700
|
-
const m =
|
|
2100
|
+
const m = _Mat4.resolve(mat);
|
|
1701
2101
|
for (let index = 0; index < this._raw.length; index++)
|
|
1702
2102
|
if (this._raw[index] != m._raw[index])
|
|
1703
2103
|
return false;
|
|
1704
2104
|
return true;
|
|
1705
2105
|
}
|
|
1706
2106
|
add(mat) {
|
|
1707
|
-
const b =
|
|
1708
|
-
const m = new
|
|
2107
|
+
const b = _Mat4.resolve(mat);
|
|
2108
|
+
const m = new _Mat4();
|
|
1709
2109
|
for (let index = 0; index < this._raw.length; index++)
|
|
1710
2110
|
m._raw[index] = this._raw[index] + b._raw[index];
|
|
1711
2111
|
return m;
|
|
1712
2112
|
}
|
|
1713
2113
|
subtract(mat) {
|
|
1714
|
-
const b =
|
|
1715
|
-
const m = new
|
|
2114
|
+
const b = _Mat4.resolve(mat);
|
|
2115
|
+
const m = new _Mat4();
|
|
1716
2116
|
for (let index = 0; index < this._raw.length; index++)
|
|
1717
2117
|
m._raw[index] = this._raw[index] - b._raw[index];
|
|
1718
2118
|
return m;
|
|
1719
2119
|
}
|
|
1720
2120
|
multiply(a) {
|
|
1721
2121
|
if (check_number(a)) {
|
|
1722
|
-
return new
|
|
2122
|
+
return new _Mat4([
|
|
1723
2123
|
this.m00 * a,
|
|
1724
2124
|
this.m01 * a,
|
|
1725
2125
|
this.m02 * a,
|
|
@@ -1738,9 +2138,9 @@ class Mat4 {
|
|
|
1738
2138
|
this.m33 * a
|
|
1739
2139
|
]);
|
|
1740
2140
|
}
|
|
1741
|
-
if (
|
|
1742
|
-
const b =
|
|
1743
|
-
return new
|
|
2141
|
+
if (_Mat4.is(a)) {
|
|
2142
|
+
const b = _Mat4.resolve(a);
|
|
2143
|
+
return new _Mat4([
|
|
1744
2144
|
b.m00 * this.m00 + b.m01 * this.m10 + b.m02 * this.m20 + b.m03 * this.m30,
|
|
1745
2145
|
b.m00 * this.m01 + b.m01 * this.m11 + b.m02 * this.m21 + b.m03 * this.m31,
|
|
1746
2146
|
b.m00 * this.m02 + b.m01 * this.m12 + b.m02 * this.m22 + b.m03 * this.m32,
|
|
@@ -1886,7 +2286,7 @@ class Mat4 {
|
|
|
1886
2286
|
]);
|
|
1887
2287
|
}
|
|
1888
2288
|
inverse() {
|
|
1889
|
-
return new
|
|
2289
|
+
return new _Mat4([
|
|
1890
2290
|
this.m00,
|
|
1891
2291
|
this.m10,
|
|
1892
2292
|
this.m20,
|
|
@@ -1918,11 +2318,12 @@ class Mat4 {
|
|
|
1918
2318
|
this.m33
|
|
1919
2319
|
];
|
|
1920
2320
|
}
|
|
1921
|
-
}
|
|
2321
|
+
};
|
|
1922
2322
|
|
|
2323
|
+
// source/color.ts
|
|
1923
2324
|
function _hex_to_array(hex) {
|
|
1924
2325
|
if (!check_hex(hex))
|
|
1925
|
-
return
|
|
2326
|
+
return void 0;
|
|
1926
2327
|
const part = get_hex_part(hex);
|
|
1927
2328
|
const a = parseInt(part.substring(0, 2), 16) / 255;
|
|
1928
2329
|
const b = parseInt(part.substring(2, 4), 16) / 255;
|
|
@@ -1946,7 +2347,7 @@ function _number_to_rgba(number) {
|
|
|
1946
2347
|
function _fix_integer(number) {
|
|
1947
2348
|
return number * 255 | 0;
|
|
1948
2349
|
}
|
|
1949
|
-
|
|
2350
|
+
var RGBAColor = class _RGBAColor {
|
|
1950
2351
|
_red;
|
|
1951
2352
|
get red() {
|
|
1952
2353
|
return this._red;
|
|
@@ -1983,11 +2384,11 @@ class RGBAColor {
|
|
|
1983
2384
|
}
|
|
1984
2385
|
static cast(a) {
|
|
1985
2386
|
if (a == null || typeof a == "undefined")
|
|
1986
|
-
return
|
|
2387
|
+
return void 0;
|
|
1987
2388
|
if (check_number_array(a, 3) || check_number_array(a, 4))
|
|
1988
2389
|
return new this(a[0], a[1], a[2], a[3]);
|
|
1989
2390
|
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 :
|
|
2391
|
+
return new this(a.red, a.green, a.blue, has_property(a, "alpha", "number") ? a.alpha : void 0);
|
|
1991
2392
|
if (check_number(a)) {
|
|
1992
2393
|
const hex = a.toString(16);
|
|
1993
2394
|
const convert = hex.length <= 6 ? _number_to_rgb : _number_to_rgba;
|
|
@@ -2003,7 +2404,7 @@ class RGBAColor {
|
|
|
2003
2404
|
}
|
|
2004
2405
|
return this.cast(_hex_to_array(a));
|
|
2005
2406
|
}
|
|
2006
|
-
return
|
|
2407
|
+
return void 0;
|
|
2007
2408
|
}
|
|
2008
2409
|
static is(a) {
|
|
2009
2410
|
return typeof this.cast(a) != "undefined";
|
|
@@ -2033,7 +2434,7 @@ class RGBAColor {
|
|
|
2033
2434
|
const min = Math.min(red, green, blue), max = Math.max(red, green, blue);
|
|
2034
2435
|
const luminace = (min + max) / 2;
|
|
2035
2436
|
if (min == max)
|
|
2036
|
-
return new HSLColor(0, 0, luminace, withAlpha ? this.alpha :
|
|
2437
|
+
return new HSLColor(0, 0, luminace, withAlpha ? this.alpha : void 0);
|
|
2037
2438
|
const d = max - min;
|
|
2038
2439
|
const saturation = luminace > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
2039
2440
|
if (max == red)
|
|
@@ -2042,18 +2443,18 @@ class RGBAColor {
|
|
|
2042
2443
|
return new HSLColor(((blue - red) / d + 2) / 6, saturation, luminace);
|
|
2043
2444
|
if (max == blue)
|
|
2044
2445
|
return new HSLColor(((red - green) / d + 4) / 6, saturation, luminace);
|
|
2045
|
-
return new HSLColor(0, saturation, luminace, withAlpha ? this.alpha :
|
|
2446
|
+
return new HSLColor(0, saturation, luminace, withAlpha ? this.alpha : void 0);
|
|
2046
2447
|
}
|
|
2047
2448
|
invert(withAlpha = false) {
|
|
2048
|
-
return new
|
|
2449
|
+
return new _RGBAColor(
|
|
2049
2450
|
1 - this.red,
|
|
2050
2451
|
1 - this.green,
|
|
2051
2452
|
1 - this.blue,
|
|
2052
2453
|
withAlpha ? 1 - this.alpha : this.alpha
|
|
2053
2454
|
);
|
|
2054
2455
|
}
|
|
2055
|
-
}
|
|
2056
|
-
|
|
2456
|
+
};
|
|
2457
|
+
var HSLColor = class _HSLColor {
|
|
2057
2458
|
_hue;
|
|
2058
2459
|
get hue() {
|
|
2059
2460
|
return this._hue;
|
|
@@ -2090,11 +2491,11 @@ class HSLColor {
|
|
|
2090
2491
|
}
|
|
2091
2492
|
static cast(a) {
|
|
2092
2493
|
if (a == null || typeof a == "undefined")
|
|
2093
|
-
return
|
|
2494
|
+
return void 0;
|
|
2094
2495
|
if (check_number_array(a, 3) || check_number_array(a, 4))
|
|
2095
2496
|
return new this(a[0], a[1], a[2], a[3]);
|
|
2096
2497
|
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 :
|
|
2498
|
+
return new this(a.hue, a.saturation, a.luminace, has_property(a, "alpha", "number") ? a.alpha : void 0);
|
|
2098
2499
|
if (check_number(a)) {
|
|
2099
2500
|
const hex = a.toString(16);
|
|
2100
2501
|
const convert = hex.length <= 6 ? _number_to_rgb : _number_to_rgba;
|
|
@@ -2110,7 +2511,7 @@ class HSLColor {
|
|
|
2110
2511
|
}
|
|
2111
2512
|
return this.cast(_hex_to_array(a));
|
|
2112
2513
|
}
|
|
2113
|
-
return
|
|
2514
|
+
return void 0;
|
|
2114
2515
|
}
|
|
2115
2516
|
static is(a) {
|
|
2116
2517
|
return typeof this.cast(a) != "undefined";
|
|
@@ -2145,7 +2546,7 @@ class HSLColor {
|
|
|
2145
2546
|
}
|
|
2146
2547
|
toRGB(withAlpha = true) {
|
|
2147
2548
|
if (this.saturation == 0)
|
|
2148
|
-
return new RGBAColor(this.luminace * 255, this.luminace * 255, this.luminace * 255, withAlpha ? this.alpha :
|
|
2549
|
+
return new RGBAColor(this.luminace * 255, this.luminace * 255, this.luminace * 255, withAlpha ? this.alpha : void 0);
|
|
2149
2550
|
const q = this.luminace < 0.5 ? this.luminace * (1 + this.saturation) : this.luminace + this.saturation - this.luminace * this.saturation;
|
|
2150
2551
|
const p = 2 * this.luminace - q;
|
|
2151
2552
|
function _hue_2_rgb(t) {
|
|
@@ -2162,17 +2563,17 @@ class HSLColor {
|
|
|
2162
2563
|
return p + (q - p) * (2 / 3 - _t) * 6;
|
|
2163
2564
|
return p;
|
|
2164
2565
|
}
|
|
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 :
|
|
2566
|
+
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
2567
|
}
|
|
2167
2568
|
invert(withAlpha = false) {
|
|
2168
|
-
return new
|
|
2569
|
+
return new _HSLColor(
|
|
2169
2570
|
1 - this.hue,
|
|
2170
2571
|
1 - this.saturation,
|
|
2171
2572
|
1 - this.luminace,
|
|
2172
2573
|
withAlpha ? 1 - this.alpha : this.alpha
|
|
2173
2574
|
);
|
|
2174
2575
|
}
|
|
2175
|
-
}
|
|
2576
|
+
};
|
|
2176
2577
|
function resolveColor(a, preferHSL = false) {
|
|
2177
2578
|
const value = castColor(a, preferHSL);
|
|
2178
2579
|
if (typeof value != "undefined")
|
|
@@ -2198,10 +2599,11 @@ function castColor(a, preferHSL = false) {
|
|
|
2198
2599
|
const secondItem = results[offset + 1];
|
|
2199
2600
|
if (secondItem)
|
|
2200
2601
|
return secondItem;
|
|
2201
|
-
return
|
|
2602
|
+
return void 0;
|
|
2202
2603
|
}
|
|
2203
2604
|
|
|
2204
|
-
|
|
2605
|
+
// source/quaternion.ts
|
|
2606
|
+
var Quaternion = class _Quaternion {
|
|
2205
2607
|
w;
|
|
2206
2608
|
x;
|
|
2207
2609
|
y;
|
|
@@ -2217,7 +2619,7 @@ class Quaternion {
|
|
|
2217
2619
|
}
|
|
2218
2620
|
static cast(a) {
|
|
2219
2621
|
if (a == null || typeof a == "undefined")
|
|
2220
|
-
return
|
|
2622
|
+
return void 0;
|
|
2221
2623
|
if (check_number_array(a, 4))
|
|
2222
2624
|
return new this(a[0], a[1], a[2], a[3]);
|
|
2223
2625
|
if (has_property(a, "w", "number") && has_property(a, "x", "number") && has_property(a, "y", "number") && has_property(a, "z", "number"))
|
|
@@ -2235,7 +2637,7 @@ class Quaternion {
|
|
|
2235
2637
|
]);
|
|
2236
2638
|
}
|
|
2237
2639
|
}
|
|
2238
|
-
return
|
|
2640
|
+
return void 0;
|
|
2239
2641
|
}
|
|
2240
2642
|
static fromAxisAngle(axis, angle) {
|
|
2241
2643
|
const vec = Vec3.resolve(axis);
|
|
@@ -2250,7 +2652,7 @@ class Quaternion {
|
|
|
2250
2652
|
const x2 = vec.x * 0.5, y2 = vec.y * 0.5, z2 = vec.z * 0.5;
|
|
2251
2653
|
const cx = Math.cos(x2), cy = Math.cos(y2), cz = Math.cos(z2);
|
|
2252
2654
|
const sx = Math.sin(x2), sy = Math.sin(y2), sz = Math.sin(z2);
|
|
2253
|
-
return new
|
|
2655
|
+
return new _Quaternion(
|
|
2254
2656
|
cx * cy * cz - sx * sy * sz,
|
|
2255
2657
|
sx * cy * cz - sy * sz * cx,
|
|
2256
2658
|
sy * cx * cz - sx * sz * cy,
|
|
@@ -2286,11 +2688,11 @@ class Quaternion {
|
|
|
2286
2688
|
};
|
|
2287
2689
|
}
|
|
2288
2690
|
clone() {
|
|
2289
|
-
return new
|
|
2691
|
+
return new _Quaternion(this.w, this.x, this.y, this.z);
|
|
2290
2692
|
}
|
|
2291
2693
|
add(a) {
|
|
2292
|
-
const quat =
|
|
2293
|
-
return new
|
|
2694
|
+
const quat = _Quaternion.resolve(a);
|
|
2695
|
+
return new _Quaternion(
|
|
2294
2696
|
this.w + quat.w,
|
|
2295
2697
|
this.x + quat.x,
|
|
2296
2698
|
this.y + quat.y,
|
|
@@ -2298,7 +2700,7 @@ class Quaternion {
|
|
|
2298
2700
|
);
|
|
2299
2701
|
}
|
|
2300
2702
|
offset(a) {
|
|
2301
|
-
const quat =
|
|
2703
|
+
const quat = _Quaternion.resolve(a);
|
|
2302
2704
|
this.w += quat.w;
|
|
2303
2705
|
this.x += quat.x;
|
|
2304
2706
|
this.y += quat.y;
|
|
@@ -2306,8 +2708,8 @@ class Quaternion {
|
|
|
2306
2708
|
return this;
|
|
2307
2709
|
}
|
|
2308
2710
|
subtract(a) {
|
|
2309
|
-
const quat =
|
|
2310
|
-
return new
|
|
2711
|
+
const quat = _Quaternion.resolve(a);
|
|
2712
|
+
return new _Quaternion(
|
|
2311
2713
|
this.w - quat.w,
|
|
2312
2714
|
this.x - quat.x,
|
|
2313
2715
|
this.y - quat.y,
|
|
@@ -2315,7 +2717,7 @@ class Quaternion {
|
|
|
2315
2717
|
);
|
|
2316
2718
|
}
|
|
2317
2719
|
negative() {
|
|
2318
|
-
return new
|
|
2720
|
+
return new _Quaternion(-this.w, -this.x, -this.y, -this.z);
|
|
2319
2721
|
}
|
|
2320
2722
|
length(sqrt = true) {
|
|
2321
2723
|
const value = this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z;
|
|
@@ -2324,13 +2726,13 @@ class Quaternion {
|
|
|
2324
2726
|
normalize() {
|
|
2325
2727
|
let length = this.length();
|
|
2326
2728
|
if (length < EPSILON)
|
|
2327
|
-
return new
|
|
2729
|
+
return new _Quaternion();
|
|
2328
2730
|
length = 1 / length;
|
|
2329
|
-
return new
|
|
2731
|
+
return new _Quaternion(this.w * length, this.x * length, this.y * length, this.z * length);
|
|
2330
2732
|
}
|
|
2331
2733
|
multiply(a) {
|
|
2332
|
-
const quat =
|
|
2333
|
-
return new
|
|
2734
|
+
const quat = _Quaternion.resolve(a);
|
|
2735
|
+
return new _Quaternion(
|
|
2334
2736
|
this.w * quat.w - this.x * quat.x - this.y * quat.y - this.z * quat.z,
|
|
2335
2737
|
this.w * quat.x + this.x * quat.w + this.y * quat.z - this.z * quat.y,
|
|
2336
2738
|
this.w * quat.y + this.y * quat.w + this.z * quat.x - this.x * quat.z,
|
|
@@ -2350,25 +2752,25 @@ class Quaternion {
|
|
|
2350
2752
|
);
|
|
2351
2753
|
}
|
|
2352
2754
|
scale(scalar) {
|
|
2353
|
-
return new
|
|
2755
|
+
return new _Quaternion(this.w * scalar, this.x * scalar, this.y * scalar, this.z * scalar);
|
|
2354
2756
|
}
|
|
2355
2757
|
dot(a) {
|
|
2356
|
-
const quat =
|
|
2758
|
+
const quat = _Quaternion.resolve(a);
|
|
2357
2759
|
return this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z;
|
|
2358
2760
|
}
|
|
2359
2761
|
inverse() {
|
|
2360
2762
|
let length = this.length(false);
|
|
2361
2763
|
if (length == 0)
|
|
2362
|
-
return new
|
|
2764
|
+
return new _Quaternion();
|
|
2363
2765
|
length = 1 / length;
|
|
2364
|
-
return new
|
|
2766
|
+
return new _Quaternion(this.w * length, -this.x * length, -this.y * length, -this.z * length);
|
|
2365
2767
|
}
|
|
2366
2768
|
divide(a) {
|
|
2367
|
-
const quat =
|
|
2769
|
+
const quat = _Quaternion.resolve(a);
|
|
2368
2770
|
let length = quat.length(false);
|
|
2369
|
-
if (length == 0) return new
|
|
2771
|
+
if (length == 0) return new _Quaternion();
|
|
2370
2772
|
length = 1 / length;
|
|
2371
|
-
return new
|
|
2773
|
+
return new _Quaternion(
|
|
2372
2774
|
(this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z) * length,
|
|
2373
2775
|
(this.x * quat.w - this.w * quat.x - this.y * quat.z + this.z * quat.y) * length,
|
|
2374
2776
|
(this.y * quat.w - this.w * quat.y - this.z * quat.x + this.x * quat.z) * length,
|
|
@@ -2376,15 +2778,15 @@ class Quaternion {
|
|
|
2376
2778
|
);
|
|
2377
2779
|
}
|
|
2378
2780
|
conjugate() {
|
|
2379
|
-
return new
|
|
2781
|
+
return new _Quaternion(this.w, -this.x, -this.y, -this.z);
|
|
2380
2782
|
}
|
|
2381
2783
|
exp() {
|
|
2382
2784
|
const length = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
|
2383
2785
|
const exp = Math.exp(this.w);
|
|
2384
2786
|
const scale = exp * Math.sin(length) / length;
|
|
2385
2787
|
if (length == 0)
|
|
2386
|
-
return new
|
|
2387
|
-
return new
|
|
2788
|
+
return new _Quaternion(exp);
|
|
2789
|
+
return new _Quaternion(
|
|
2388
2790
|
exp * Math.cos(length),
|
|
2389
2791
|
this.x * scale,
|
|
2390
2792
|
this.y * scale,
|
|
@@ -2393,11 +2795,11 @@ class Quaternion {
|
|
|
2393
2795
|
}
|
|
2394
2796
|
log() {
|
|
2395
2797
|
if (this.x == 0 && this.z == 0)
|
|
2396
|
-
return new
|
|
2798
|
+
return new _Quaternion(log_hypot(this.w, this.x), Math.atan2(this.x, this.w));
|
|
2397
2799
|
const length = this.length(false);
|
|
2398
2800
|
const length2 = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
|
2399
2801
|
const scale = Math.atan2(length2, this.w) / length;
|
|
2400
|
-
return new
|
|
2802
|
+
return new _Quaternion(Math.log(length) * 0.5, this.x * scale, this.y * scale, this.z * scale);
|
|
2401
2803
|
}
|
|
2402
2804
|
toVector() {
|
|
2403
2805
|
return new Vec3(this.x, this.y, this.z, this.w);
|
|
@@ -2453,9 +2855,10 @@ class Quaternion {
|
|
|
2453
2855
|
1
|
|
2454
2856
|
]);
|
|
2455
2857
|
}
|
|
2456
|
-
}
|
|
2858
|
+
};
|
|
2457
2859
|
|
|
2458
|
-
|
|
2860
|
+
// source/transform.ts
|
|
2861
|
+
var Transform = class {
|
|
2459
2862
|
/**
|
|
2460
2863
|
* The position of the object
|
|
2461
2864
|
*/
|
|
@@ -2486,51 +2889,4 @@ class Transform {
|
|
|
2486
2889
|
toMat4() {
|
|
2487
2890
|
return new Mat4().translate(this.position).multiply(this.rotation.toMat4()).scale(this.scale);
|
|
2488
2891
|
}
|
|
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;
|
|
2892
|
+
};
|