@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
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// source/algebra/function.ts
|
|
2
|
+
var MathFunction = class {
|
|
3
|
+
};
|
|
3
4
|
|
|
5
|
+
// source/common/sign.ts
|
|
4
6
|
function sign_char(num) {
|
|
5
7
|
if (num == 0)
|
|
6
|
-
return
|
|
8
|
+
return void 0;
|
|
7
9
|
if (num < 0)
|
|
8
10
|
return "-";
|
|
9
11
|
if (num > 0)
|
|
10
12
|
return "+";
|
|
11
|
-
return
|
|
13
|
+
return void 0;
|
|
12
14
|
}
|
|
13
15
|
|
|
16
|
+
// source/common/types.ts
|
|
14
17
|
function check_number(obj) {
|
|
15
18
|
return obj != null && typeof obj == "number" && !isNaN(obj) && isFinite(obj);
|
|
16
19
|
}
|
|
@@ -74,15 +77,17 @@ function has_property(obj, name, type) {
|
|
|
74
77
|
return obj != null && typeof obj == "object" && name in obj && typeof obj[name] == type;
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
|
|
80
|
+
// source/common/error.ts
|
|
81
|
+
var ResolveError = class extends Error {
|
|
78
82
|
constructor(target, value) {
|
|
79
83
|
super(`can't resolve ${value} to ${target}`);
|
|
80
84
|
this.target = target;
|
|
81
85
|
this.value = value;
|
|
82
86
|
}
|
|
83
|
-
}
|
|
87
|
+
};
|
|
84
88
|
|
|
85
|
-
|
|
89
|
+
// source/geometry/size.ts
|
|
90
|
+
var Size = class _Size {
|
|
86
91
|
width;
|
|
87
92
|
height;
|
|
88
93
|
get aspectRatio() {
|
|
@@ -102,7 +107,7 @@ class Size {
|
|
|
102
107
|
}
|
|
103
108
|
static cast(a) {
|
|
104
109
|
if (a == null || typeof a == "undefined")
|
|
105
|
-
return
|
|
110
|
+
return void 0;
|
|
106
111
|
if (check_number_array(a, 2))
|
|
107
112
|
return new this(a[0], a[1]);
|
|
108
113
|
if (has_property(a, "width", "number") && has_property(a, "height", "number"))
|
|
@@ -114,7 +119,7 @@ class Size {
|
|
|
114
119
|
}
|
|
115
120
|
if (check_number(a))
|
|
116
121
|
return new this(a, a);
|
|
117
|
-
return
|
|
122
|
+
return void 0;
|
|
118
123
|
}
|
|
119
124
|
static is(a) {
|
|
120
125
|
return typeof this.cast(a) != "undefined";
|
|
@@ -140,17 +145,18 @@ class Size {
|
|
|
140
145
|
};
|
|
141
146
|
}
|
|
142
147
|
clone() {
|
|
143
|
-
return new
|
|
148
|
+
return new _Size(this.width, this.height);
|
|
144
149
|
}
|
|
145
150
|
equals(square) {
|
|
146
|
-
const s =
|
|
151
|
+
const s = _Size.resolve(square);
|
|
147
152
|
return this.width == s.width && this.height == s.height;
|
|
148
153
|
}
|
|
149
154
|
toVec2() {
|
|
150
155
|
return [this.width, this.height];
|
|
151
156
|
}
|
|
152
|
-
}
|
|
157
|
+
};
|
|
153
158
|
|
|
159
|
+
// source/utils.ts
|
|
154
160
|
function clamp(value, min, max) {
|
|
155
161
|
if (value <= min)
|
|
156
162
|
return min;
|
|
@@ -170,9 +176,10 @@ function log_hypot(a, b) {
|
|
|
170
176
|
const _a = a / 2, _b = b / 2;
|
|
171
177
|
return 0.5 * Math.log(_a * _a + _b * _b) + Math.LN2;
|
|
172
178
|
}
|
|
173
|
-
|
|
179
|
+
var EPSILON = 1e-16;
|
|
174
180
|
|
|
175
|
-
|
|
181
|
+
// source/vectors/vec3.ts
|
|
182
|
+
var Vec3 = class _Vec3 {
|
|
176
183
|
x;
|
|
177
184
|
y;
|
|
178
185
|
z;
|
|
@@ -185,22 +192,22 @@ class Vec3 {
|
|
|
185
192
|
}
|
|
186
193
|
static cast(a) {
|
|
187
194
|
if (a == null || typeof a == "undefined")
|
|
188
|
-
return
|
|
195
|
+
return void 0;
|
|
189
196
|
if (check_number_array(a, 3) || check_number_array(a, 4))
|
|
190
|
-
return new this(a[0], a[1], a[2], check_number(a[3]) ? a[3] :
|
|
197
|
+
return new this(a[0], a[1], a[2], check_number(a[3]) ? a[3] : void 0);
|
|
191
198
|
if (has_property(a, "x", "number") && has_property(a, "y", "number") && has_property(a, "z", "number"))
|
|
192
|
-
return new this(a.x, a.y, a.z, has_property(a, "w", "number") ? a.w :
|
|
199
|
+
return new this(a.x, a.y, a.z, has_property(a, "w", "number") ? a.w : void 0);
|
|
193
200
|
if (check_string(a)) {
|
|
194
201
|
const [sxyz, sw] = a.split(";");
|
|
195
202
|
if (check_string(sxyz)) {
|
|
196
203
|
const parts = sxyz.split(",");
|
|
197
204
|
if (check_string_array(parts, 3))
|
|
198
|
-
return new this(parseFloat(parts[0]), parseFloat(parts[1]), parseFloat(parts[2]), check_string(sw) ? parseFloat(sw) :
|
|
205
|
+
return new this(parseFloat(parts[0]), parseFloat(parts[1]), parseFloat(parts[2]), check_string(sw) ? parseFloat(sw) : void 0);
|
|
199
206
|
}
|
|
200
207
|
}
|
|
201
208
|
if (check_number(a))
|
|
202
209
|
return new this(a, a, a);
|
|
203
|
-
return
|
|
210
|
+
return void 0;
|
|
204
211
|
}
|
|
205
212
|
static resolveArgs(args) {
|
|
206
213
|
if (check_number_array(args, 3))
|
|
@@ -231,7 +238,7 @@ class Vec3 {
|
|
|
231
238
|
t = (-plane_d - ad) / (bd - ad);
|
|
232
239
|
const lineStartToEnd = this.resolve(lineEnd).subtract(lineStart);
|
|
233
240
|
const linetoIntersect = lineStartToEnd.multiply(t);
|
|
234
|
-
return
|
|
241
|
+
return _Vec3.resolve(lineStart).add(linetoIntersect);
|
|
235
242
|
}
|
|
236
243
|
constructor(x = 0, y = 0, z = 0, w = 1) {
|
|
237
244
|
if (!check_number(x))
|
|
@@ -265,10 +272,10 @@ class Vec3 {
|
|
|
265
272
|
return [this.x, this.y, this.w];
|
|
266
273
|
}
|
|
267
274
|
clone() {
|
|
268
|
-
return new
|
|
275
|
+
return new _Vec3(this.x, this.y, this.z, this.w);
|
|
269
276
|
}
|
|
270
277
|
equals(vec) {
|
|
271
|
-
const a =
|
|
278
|
+
const a = _Vec3.resolve(vec);
|
|
272
279
|
return this.x == a.x && this.y == a.y && this.z == a.z;
|
|
273
280
|
}
|
|
274
281
|
setX(x) {
|
|
@@ -284,42 +291,42 @@ class Vec3 {
|
|
|
284
291
|
return this;
|
|
285
292
|
}
|
|
286
293
|
set(...args) {
|
|
287
|
-
const vec =
|
|
294
|
+
const vec = _Vec3.resolveArgs(args);
|
|
288
295
|
return this.setX(vec.x).setY(vec.y).setZ(vec.z);
|
|
289
296
|
}
|
|
290
297
|
add(...args) {
|
|
291
|
-
const vec =
|
|
292
|
-
return new
|
|
298
|
+
const vec = _Vec3.resolveArgs(args);
|
|
299
|
+
return new _Vec3(
|
|
293
300
|
this.x + vec.x,
|
|
294
301
|
this.y + vec.y,
|
|
295
302
|
this.z + vec.z
|
|
296
303
|
);
|
|
297
304
|
}
|
|
298
305
|
offset(...args) {
|
|
299
|
-
const vec =
|
|
306
|
+
const vec = _Vec3.resolveArgs(args);
|
|
300
307
|
this.x += vec.x;
|
|
301
308
|
this.y += vec.y;
|
|
302
309
|
this.z += vec.z;
|
|
303
310
|
return this;
|
|
304
311
|
}
|
|
305
312
|
subtract(...args) {
|
|
306
|
-
const vec =
|
|
307
|
-
return new
|
|
313
|
+
const vec = _Vec3.resolveArgs(args);
|
|
314
|
+
return new _Vec3(
|
|
308
315
|
this.x - vec.x,
|
|
309
316
|
this.y - vec.y,
|
|
310
317
|
this.z - vec.z
|
|
311
318
|
);
|
|
312
319
|
}
|
|
313
320
|
multiply(scalar) {
|
|
314
|
-
return new
|
|
321
|
+
return new _Vec3(
|
|
315
322
|
this.x * scalar,
|
|
316
323
|
this.y * scalar,
|
|
317
324
|
this.z * scalar
|
|
318
325
|
);
|
|
319
326
|
}
|
|
320
327
|
naiveMultiply(...args) {
|
|
321
|
-
const vec =
|
|
322
|
-
return new
|
|
328
|
+
const vec = _Vec3.resolveArgs(args);
|
|
329
|
+
return new _Vec3(
|
|
323
330
|
this.x * vec.x,
|
|
324
331
|
this.y * vec.y,
|
|
325
332
|
this.z * vec.z
|
|
@@ -327,36 +334,36 @@ class Vec3 {
|
|
|
327
334
|
}
|
|
328
335
|
divide(...args) {
|
|
329
336
|
if (check_number_array(args, 1))
|
|
330
|
-
return new
|
|
337
|
+
return new _Vec3(
|
|
331
338
|
this.x / args[0],
|
|
332
339
|
this.y / args[0],
|
|
333
340
|
this.z / args[0]
|
|
334
341
|
);
|
|
335
|
-
const vec =
|
|
336
|
-
return new
|
|
342
|
+
const vec = _Vec3.resolveArgs(args);
|
|
343
|
+
return new _Vec3(
|
|
337
344
|
this.x / vec.x,
|
|
338
345
|
this.y / vec.y,
|
|
339
346
|
this.z / vec.z
|
|
340
347
|
);
|
|
341
348
|
}
|
|
342
349
|
dot(...args) {
|
|
343
|
-
const vec =
|
|
350
|
+
const vec = _Vec3.resolveArgs(args);
|
|
344
351
|
return this.x * vec.x + this.y * vec.y + this.z * vec.z;
|
|
345
352
|
}
|
|
346
353
|
cross(...args) {
|
|
347
|
-
const vec =
|
|
348
|
-
return new
|
|
354
|
+
const vec = _Vec3.resolveArgs(args);
|
|
355
|
+
return new _Vec3(
|
|
349
356
|
this.y * vec.z - this.z * vec.y,
|
|
350
357
|
this.z * vec.x - this.x * vec.z,
|
|
351
358
|
this.x * vec.y - this.y * vec.x
|
|
352
359
|
);
|
|
353
360
|
}
|
|
354
361
|
distance(...args) {
|
|
355
|
-
const vec =
|
|
362
|
+
const vec = _Vec3.resolveArgs(args);
|
|
356
363
|
return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2);
|
|
357
364
|
}
|
|
358
365
|
distanceSquare(...args) {
|
|
359
|
-
const vec =
|
|
366
|
+
const vec = _Vec3.resolveArgs(args);
|
|
360
367
|
return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2));
|
|
361
368
|
}
|
|
362
369
|
length() {
|
|
@@ -364,8 +371,8 @@ class Vec3 {
|
|
|
364
371
|
}
|
|
365
372
|
normalize() {
|
|
366
373
|
const length = this.length();
|
|
367
|
-
if (length == 0) return new
|
|
368
|
-
return new
|
|
374
|
+
if (length == 0) return new _Vec3();
|
|
375
|
+
return new _Vec3(
|
|
369
376
|
this.x / length,
|
|
370
377
|
this.y / length,
|
|
371
378
|
this.z / length
|
|
@@ -375,11 +382,12 @@ class Vec3 {
|
|
|
375
382
|
return this.multiply(-1);
|
|
376
383
|
}
|
|
377
384
|
round() {
|
|
378
|
-
return new
|
|
385
|
+
return new _Vec3(Math.round(this.x), Math.round(this.y), Math.round(this.z), Math.round(this.w));
|
|
379
386
|
}
|
|
380
|
-
}
|
|
387
|
+
};
|
|
381
388
|
|
|
382
|
-
|
|
389
|
+
// source/vectors/vec2.ts
|
|
390
|
+
var Vec2 = class _Vec2 {
|
|
383
391
|
x;
|
|
384
392
|
y;
|
|
385
393
|
w;
|
|
@@ -391,22 +399,22 @@ class Vec2 {
|
|
|
391
399
|
}
|
|
392
400
|
static cast(a) {
|
|
393
401
|
if (a == null || typeof a == "undefined")
|
|
394
|
-
return
|
|
402
|
+
return void 0;
|
|
395
403
|
if (check_number_array(a, 2) || check_number_array(a, 3))
|
|
396
|
-
return new this(a[0], a[1], check_number(a[2]) ? a[2] :
|
|
404
|
+
return new this(a[0], a[1], check_number(a[2]) ? a[2] : void 0);
|
|
397
405
|
if (has_property(a, "x", "number") && has_property(a, "y", "number"))
|
|
398
|
-
return new this(a.x, a.y, has_property(a, "w", "number") ? a.w :
|
|
406
|
+
return new this(a.x, a.y, has_property(a, "w", "number") ? a.w : void 0);
|
|
399
407
|
if (check_string(a)) {
|
|
400
408
|
const [sxy, sw] = a.split(";");
|
|
401
409
|
if (check_string(sxy)) {
|
|
402
410
|
const parts = sxy.split(",");
|
|
403
411
|
if (check_string_array(parts, 2))
|
|
404
|
-
return new this(parseFloat(parts[0]), parseFloat(parts[1]), check_string(sw) ? parseFloat(sw) :
|
|
412
|
+
return new this(parseFloat(parts[0]), parseFloat(parts[1]), check_string(sw) ? parseFloat(sw) : void 0);
|
|
405
413
|
}
|
|
406
414
|
}
|
|
407
415
|
if (check_number(a))
|
|
408
416
|
return new this(a, a);
|
|
409
|
-
return
|
|
417
|
+
return void 0;
|
|
410
418
|
}
|
|
411
419
|
static resolveArgs(args) {
|
|
412
420
|
if (check_number_array(args, 2))
|
|
@@ -459,10 +467,10 @@ class Vec2 {
|
|
|
459
467
|
return new Vec3(this.x, this.y, z, this.w);
|
|
460
468
|
}
|
|
461
469
|
clone() {
|
|
462
|
-
return new
|
|
470
|
+
return new _Vec2(this.x, this.y, this.w);
|
|
463
471
|
}
|
|
464
472
|
equals(vec) {
|
|
465
|
-
const a =
|
|
473
|
+
const a = _Vec2.resolve(vec);
|
|
466
474
|
return this.x == a.x && this.y == a.y;
|
|
467
475
|
}
|
|
468
476
|
setX(x) {
|
|
@@ -478,85 +486,85 @@ class Vec2 {
|
|
|
478
486
|
return this;
|
|
479
487
|
}
|
|
480
488
|
set(...args) {
|
|
481
|
-
const vec =
|
|
489
|
+
const vec = _Vec2.resolveArgs(args);
|
|
482
490
|
return this.setX(vec.x).setY(vec.y);
|
|
483
491
|
}
|
|
484
492
|
add(...args) {
|
|
485
|
-
const vec =
|
|
486
|
-
return new
|
|
493
|
+
const vec = _Vec2.resolveArgs(args);
|
|
494
|
+
return new _Vec2(
|
|
487
495
|
this.x + vec.x,
|
|
488
496
|
this.y + vec.y
|
|
489
497
|
);
|
|
490
498
|
}
|
|
491
499
|
offset(...args) {
|
|
492
|
-
const vec =
|
|
500
|
+
const vec = _Vec2.resolveArgs(args);
|
|
493
501
|
this.x += vec.x;
|
|
494
502
|
this.y += vec.y;
|
|
495
503
|
return this;
|
|
496
504
|
}
|
|
497
505
|
subtract(...args) {
|
|
498
|
-
const vec =
|
|
499
|
-
return new
|
|
506
|
+
const vec = _Vec2.resolveArgs(args);
|
|
507
|
+
return new _Vec2(
|
|
500
508
|
this.x - vec.x,
|
|
501
509
|
this.y - vec.y
|
|
502
510
|
);
|
|
503
511
|
}
|
|
504
512
|
multiply(scalar) {
|
|
505
|
-
return new
|
|
513
|
+
return new _Vec2(
|
|
506
514
|
this.x * scalar,
|
|
507
515
|
this.y * scalar
|
|
508
516
|
);
|
|
509
517
|
}
|
|
510
518
|
naiveMultiply(...args) {
|
|
511
|
-
const vec =
|
|
512
|
-
return new
|
|
519
|
+
const vec = _Vec2.resolveArgs(args);
|
|
520
|
+
return new _Vec2(
|
|
513
521
|
this.x * vec.x,
|
|
514
522
|
this.y * vec.y
|
|
515
523
|
);
|
|
516
524
|
}
|
|
517
525
|
divide(...args) {
|
|
518
526
|
if (check_number_array(args, 1))
|
|
519
|
-
return new
|
|
527
|
+
return new _Vec2(
|
|
520
528
|
this.x / args[0],
|
|
521
529
|
this.y / args[0]
|
|
522
530
|
);
|
|
523
|
-
const vec =
|
|
524
|
-
return new
|
|
531
|
+
const vec = _Vec2.resolveArgs(args);
|
|
532
|
+
return new _Vec2(
|
|
525
533
|
this.x / vec.x,
|
|
526
534
|
this.y / vec.y
|
|
527
535
|
);
|
|
528
536
|
}
|
|
529
537
|
dot(...args) {
|
|
530
|
-
const vec =
|
|
538
|
+
const vec = _Vec2.resolveArgs(args);
|
|
531
539
|
return this.x * vec.x + this.y * vec.y;
|
|
532
540
|
}
|
|
533
541
|
distance(...args) {
|
|
534
|
-
const vec =
|
|
542
|
+
const vec = _Vec2.resolveArgs(args);
|
|
535
543
|
return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2);
|
|
536
544
|
}
|
|
537
545
|
distanceSquare(...args) {
|
|
538
|
-
const vec =
|
|
546
|
+
const vec = _Vec2.resolveArgs(args);
|
|
539
547
|
return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2));
|
|
540
548
|
}
|
|
541
549
|
length() {
|
|
542
550
|
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
543
551
|
}
|
|
544
552
|
cartesianify() {
|
|
545
|
-
return new
|
|
553
|
+
return new _Vec2(
|
|
546
554
|
this.x * Math.cos(this.y),
|
|
547
555
|
this.x * Math.sin(this.y)
|
|
548
556
|
);
|
|
549
557
|
}
|
|
550
558
|
polarify() {
|
|
551
|
-
return new
|
|
559
|
+
return new _Vec2(
|
|
552
560
|
Math.sqrt(this.x * this.x + this.y * this.y),
|
|
553
561
|
Math.atan(this.y / this.x)
|
|
554
562
|
);
|
|
555
563
|
}
|
|
556
564
|
normalize() {
|
|
557
565
|
const length = this.length();
|
|
558
|
-
if (length == 0) return new
|
|
559
|
-
return new
|
|
566
|
+
if (length == 0) return new _Vec2();
|
|
567
|
+
return new _Vec2(
|
|
560
568
|
this.x / length,
|
|
561
569
|
this.y / length
|
|
562
570
|
);
|
|
@@ -565,11 +573,12 @@ class Vec2 {
|
|
|
565
573
|
return this.multiply(-1);
|
|
566
574
|
}
|
|
567
575
|
round() {
|
|
568
|
-
return new
|
|
576
|
+
return new _Vec2(Math.round(this.x), Math.round(this.y), Math.round(this.w));
|
|
569
577
|
}
|
|
570
|
-
}
|
|
578
|
+
};
|
|
571
579
|
|
|
572
|
-
|
|
580
|
+
// source/algebra/linear.ts
|
|
581
|
+
var LinearFunction = class extends MathFunction {
|
|
573
582
|
/**
|
|
574
583
|
* The factor of the linear function
|
|
575
584
|
*/
|
|
@@ -622,9 +631,10 @@ class LinearFunction extends MathFunction {
|
|
|
622
631
|
return `f(x) = ${this.m} * x ${bsign} ${Math.abs(this.b)}`;
|
|
623
632
|
return `f(x) = ${this.m} * x`;
|
|
624
633
|
}
|
|
625
|
-
}
|
|
634
|
+
};
|
|
626
635
|
|
|
627
|
-
|
|
636
|
+
// source/algebra/quad.ts
|
|
637
|
+
var QuadFunction = class extends MathFunction {
|
|
628
638
|
a;
|
|
629
639
|
b;
|
|
630
640
|
c;
|
|
@@ -675,13 +685,15 @@ class QuadFunction extends MathFunction {
|
|
|
675
685
|
}
|
|
676
686
|
}
|
|
677
687
|
}
|
|
678
|
-
}
|
|
688
|
+
};
|
|
679
689
|
|
|
690
|
+
// source/common/string.ts
|
|
680
691
|
function stringify(value) {
|
|
681
692
|
return value != null && typeof value == "object" && "toString" in value && typeof value.toString == "function" ? value.toString() : String(value);
|
|
682
693
|
}
|
|
683
694
|
|
|
684
|
-
|
|
695
|
+
// source/crypto/hash.ts
|
|
696
|
+
var DJB2_OFFSET = 5381n;
|
|
685
697
|
function djb2(value) {
|
|
686
698
|
const string = stringify(value);
|
|
687
699
|
let hash = DJB2_OFFSET;
|
|
@@ -690,8 +702,8 @@ function djb2(value) {
|
|
|
690
702
|
}
|
|
691
703
|
return hash;
|
|
692
704
|
}
|
|
693
|
-
|
|
694
|
-
|
|
705
|
+
var FNV1_OFFSET = 14695981039346656037n;
|
|
706
|
+
var FNV1_PRIME = 1099511628211n;
|
|
695
707
|
function fnv1(value) {
|
|
696
708
|
const string = stringify(value);
|
|
697
709
|
let hash = FNV1_OFFSET;
|
|
@@ -710,13 +722,326 @@ function sdbm(value) {
|
|
|
710
722
|
return hash;
|
|
711
723
|
}
|
|
712
724
|
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
725
|
+
// source/crypto/md2.ts
|
|
726
|
+
var STABLE = [
|
|
727
|
+
41,
|
|
728
|
+
46,
|
|
729
|
+
67,
|
|
730
|
+
201,
|
|
731
|
+
162,
|
|
732
|
+
216,
|
|
733
|
+
124,
|
|
734
|
+
1,
|
|
735
|
+
61,
|
|
736
|
+
54,
|
|
737
|
+
84,
|
|
738
|
+
161,
|
|
739
|
+
236,
|
|
740
|
+
240,
|
|
741
|
+
6,
|
|
742
|
+
19,
|
|
743
|
+
98,
|
|
744
|
+
167,
|
|
745
|
+
5,
|
|
746
|
+
243,
|
|
747
|
+
192,
|
|
748
|
+
199,
|
|
749
|
+
115,
|
|
750
|
+
140,
|
|
751
|
+
152,
|
|
752
|
+
147,
|
|
753
|
+
43,
|
|
754
|
+
217,
|
|
755
|
+
188,
|
|
756
|
+
76,
|
|
757
|
+
130,
|
|
758
|
+
202,
|
|
759
|
+
30,
|
|
760
|
+
155,
|
|
761
|
+
87,
|
|
762
|
+
60,
|
|
763
|
+
253,
|
|
764
|
+
212,
|
|
765
|
+
224,
|
|
766
|
+
22,
|
|
767
|
+
103,
|
|
768
|
+
66,
|
|
769
|
+
111,
|
|
770
|
+
24,
|
|
771
|
+
138,
|
|
772
|
+
23,
|
|
773
|
+
229,
|
|
774
|
+
18,
|
|
775
|
+
190,
|
|
776
|
+
78,
|
|
777
|
+
196,
|
|
778
|
+
214,
|
|
779
|
+
218,
|
|
780
|
+
158,
|
|
781
|
+
222,
|
|
782
|
+
73,
|
|
783
|
+
160,
|
|
784
|
+
251,
|
|
785
|
+
245,
|
|
786
|
+
142,
|
|
787
|
+
187,
|
|
788
|
+
47,
|
|
789
|
+
238,
|
|
790
|
+
122,
|
|
791
|
+
169,
|
|
792
|
+
104,
|
|
793
|
+
121,
|
|
794
|
+
145,
|
|
795
|
+
21,
|
|
796
|
+
178,
|
|
797
|
+
7,
|
|
798
|
+
63,
|
|
799
|
+
148,
|
|
800
|
+
194,
|
|
801
|
+
16,
|
|
802
|
+
137,
|
|
803
|
+
11,
|
|
804
|
+
34,
|
|
805
|
+
95,
|
|
806
|
+
33,
|
|
807
|
+
128,
|
|
808
|
+
127,
|
|
809
|
+
93,
|
|
810
|
+
154,
|
|
811
|
+
90,
|
|
812
|
+
144,
|
|
813
|
+
50,
|
|
814
|
+
39,
|
|
815
|
+
53,
|
|
816
|
+
62,
|
|
817
|
+
204,
|
|
818
|
+
231,
|
|
819
|
+
191,
|
|
820
|
+
247,
|
|
821
|
+
151,
|
|
822
|
+
3,
|
|
823
|
+
255,
|
|
824
|
+
25,
|
|
825
|
+
48,
|
|
826
|
+
179,
|
|
827
|
+
72,
|
|
828
|
+
165,
|
|
829
|
+
181,
|
|
830
|
+
209,
|
|
831
|
+
215,
|
|
832
|
+
94,
|
|
833
|
+
146,
|
|
834
|
+
42,
|
|
835
|
+
172,
|
|
836
|
+
86,
|
|
837
|
+
170,
|
|
838
|
+
198,
|
|
839
|
+
79,
|
|
840
|
+
184,
|
|
841
|
+
56,
|
|
842
|
+
210,
|
|
843
|
+
150,
|
|
844
|
+
164,
|
|
845
|
+
125,
|
|
846
|
+
182,
|
|
847
|
+
118,
|
|
848
|
+
252,
|
|
849
|
+
107,
|
|
850
|
+
226,
|
|
851
|
+
156,
|
|
852
|
+
116,
|
|
853
|
+
4,
|
|
854
|
+
241,
|
|
855
|
+
69,
|
|
856
|
+
157,
|
|
857
|
+
112,
|
|
858
|
+
89,
|
|
859
|
+
100,
|
|
860
|
+
113,
|
|
861
|
+
135,
|
|
862
|
+
32,
|
|
863
|
+
134,
|
|
864
|
+
91,
|
|
865
|
+
207,
|
|
866
|
+
101,
|
|
867
|
+
230,
|
|
868
|
+
45,
|
|
869
|
+
168,
|
|
870
|
+
2,
|
|
871
|
+
27,
|
|
872
|
+
96,
|
|
873
|
+
37,
|
|
874
|
+
173,
|
|
875
|
+
174,
|
|
876
|
+
176,
|
|
877
|
+
185,
|
|
878
|
+
246,
|
|
879
|
+
28,
|
|
880
|
+
70,
|
|
881
|
+
97,
|
|
882
|
+
105,
|
|
883
|
+
52,
|
|
884
|
+
64,
|
|
885
|
+
126,
|
|
886
|
+
15,
|
|
887
|
+
85,
|
|
888
|
+
71,
|
|
889
|
+
163,
|
|
890
|
+
35,
|
|
891
|
+
221,
|
|
892
|
+
81,
|
|
893
|
+
175,
|
|
894
|
+
58,
|
|
895
|
+
195,
|
|
896
|
+
92,
|
|
897
|
+
249,
|
|
898
|
+
206,
|
|
899
|
+
186,
|
|
900
|
+
197,
|
|
901
|
+
234,
|
|
902
|
+
38,
|
|
903
|
+
44,
|
|
904
|
+
83,
|
|
905
|
+
13,
|
|
906
|
+
110,
|
|
907
|
+
133,
|
|
908
|
+
40,
|
|
909
|
+
132,
|
|
910
|
+
9,
|
|
911
|
+
211,
|
|
912
|
+
223,
|
|
913
|
+
205,
|
|
914
|
+
244,
|
|
915
|
+
65,
|
|
916
|
+
129,
|
|
917
|
+
77,
|
|
918
|
+
82,
|
|
919
|
+
106,
|
|
920
|
+
220,
|
|
921
|
+
55,
|
|
922
|
+
200,
|
|
923
|
+
108,
|
|
924
|
+
193,
|
|
925
|
+
171,
|
|
926
|
+
250,
|
|
927
|
+
36,
|
|
928
|
+
225,
|
|
929
|
+
123,
|
|
930
|
+
8,
|
|
931
|
+
12,
|
|
932
|
+
189,
|
|
933
|
+
177,
|
|
934
|
+
74,
|
|
935
|
+
120,
|
|
936
|
+
136,
|
|
937
|
+
149,
|
|
938
|
+
139,
|
|
939
|
+
227,
|
|
940
|
+
99,
|
|
941
|
+
232,
|
|
942
|
+
109,
|
|
943
|
+
233,
|
|
944
|
+
203,
|
|
945
|
+
213,
|
|
946
|
+
254,
|
|
947
|
+
59,
|
|
948
|
+
0,
|
|
949
|
+
29,
|
|
950
|
+
57,
|
|
951
|
+
242,
|
|
952
|
+
239,
|
|
953
|
+
183,
|
|
954
|
+
14,
|
|
955
|
+
102,
|
|
956
|
+
88,
|
|
957
|
+
208,
|
|
958
|
+
228,
|
|
959
|
+
166,
|
|
960
|
+
119,
|
|
961
|
+
114,
|
|
962
|
+
248,
|
|
963
|
+
235,
|
|
964
|
+
117,
|
|
965
|
+
75,
|
|
966
|
+
10,
|
|
967
|
+
49,
|
|
968
|
+
68,
|
|
969
|
+
80,
|
|
970
|
+
180,
|
|
971
|
+
143,
|
|
972
|
+
237,
|
|
973
|
+
31,
|
|
974
|
+
26,
|
|
975
|
+
219,
|
|
976
|
+
153,
|
|
977
|
+
141,
|
|
978
|
+
51,
|
|
979
|
+
159,
|
|
980
|
+
17,
|
|
981
|
+
131,
|
|
982
|
+
20
|
|
983
|
+
];
|
|
984
|
+
var MD2 = class _MD2 {
|
|
985
|
+
static BLOCK_SIZE = 16;
|
|
986
|
+
_data = new Uint8Array(16);
|
|
987
|
+
_state = new Uint8Array(48);
|
|
988
|
+
_checksum = new Uint8Array(16);
|
|
989
|
+
_length = 0;
|
|
990
|
+
constructor() {
|
|
991
|
+
for (let i = 0; i < this._state.length; i++)
|
|
992
|
+
this._state[i] = 0;
|
|
993
|
+
for (let i = 0; i < this._checksum.length; i++)
|
|
994
|
+
this._checksum[i] = 0;
|
|
995
|
+
}
|
|
996
|
+
update(input) {
|
|
997
|
+
for (let i = 0; i < input.length; i++) {
|
|
998
|
+
this._data[this._length] = input[i];
|
|
999
|
+
this._length++;
|
|
1000
|
+
if (this._length == _MD2.BLOCK_SIZE) {
|
|
1001
|
+
this._transform(input);
|
|
1002
|
+
this._length = 0;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
return this;
|
|
1006
|
+
}
|
|
1007
|
+
_transform(data) {
|
|
1008
|
+
for (let i = 0; i < 16; ++i) {
|
|
1009
|
+
this._state[i + 16] = this._data[i];
|
|
1010
|
+
this._state[i + 32] = this._state[i + 16] ^ this._state[i];
|
|
1011
|
+
}
|
|
1012
|
+
let t = 0;
|
|
1013
|
+
for (let i = 0; i < 18; ++i) {
|
|
1014
|
+
for (let j = 0; j < 48; ++j) {
|
|
1015
|
+
this._state[j] ^= STABLE[t];
|
|
1016
|
+
t = this._state[j];
|
|
1017
|
+
}
|
|
1018
|
+
t = t + i & 255;
|
|
1019
|
+
}
|
|
1020
|
+
t = this._checksum[15];
|
|
1021
|
+
for (let i = 0; i < 16; ++i) {
|
|
1022
|
+
this._checksum[i] ^= STABLE[this._data[i] ^ t];
|
|
1023
|
+
t = this._checksum[i];
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
digest() {
|
|
1027
|
+
const toPad = _MD2.BLOCK_SIZE - this._length;
|
|
1028
|
+
while (this._length < _MD2.BLOCK_SIZE)
|
|
1029
|
+
this._data[this._length++] = toPad;
|
|
1030
|
+
this._transform(this._data);
|
|
1031
|
+
this._transform(this._checksum);
|
|
1032
|
+
return this._state.slice();
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
|
|
1036
|
+
// source/geometry/angle.ts
|
|
1037
|
+
var MAX_ANGLE_DEGREE = 360;
|
|
1038
|
+
var cap_angle_degree = (angle) => angle % MAX_ANGLE_DEGREE;
|
|
1039
|
+
var cap_angle_radian = (angle) => cap_angle_degree(degree_to_radian(angle));
|
|
1040
|
+
var radian_to_degree = (angle) => angle * (180 / Math.PI);
|
|
1041
|
+
var degree_to_radian = (angle) => angle * (Math.PI / 180);
|
|
718
1042
|
|
|
719
|
-
|
|
1043
|
+
// source/geometry/circle.ts
|
|
1044
|
+
var Circle = class _Circle {
|
|
720
1045
|
radius;
|
|
721
1046
|
get perimeter() {
|
|
722
1047
|
return this.radius * Math.PI * 2;
|
|
@@ -751,7 +1076,7 @@ class Circle {
|
|
|
751
1076
|
}
|
|
752
1077
|
static cast(a) {
|
|
753
1078
|
if (a == null || typeof a == "undefined")
|
|
754
|
-
return
|
|
1079
|
+
return void 0;
|
|
755
1080
|
if (check_number_array(a, 3))
|
|
756
1081
|
return new this([a[0], a[1]], a[2]);
|
|
757
1082
|
if (check_number_array(a, 4)) {
|
|
@@ -765,12 +1090,12 @@ class Circle {
|
|
|
765
1090
|
const [spos, sradius] = a.split("|");
|
|
766
1091
|
const pos = Vec2.cast(spos);
|
|
767
1092
|
if (typeof pos == "undefined")
|
|
768
|
-
return
|
|
1093
|
+
return void 0;
|
|
769
1094
|
const radius = parseFloat(sradius);
|
|
770
1095
|
if (!isNaN(radius))
|
|
771
1096
|
return new this(pos, radius);
|
|
772
1097
|
}
|
|
773
|
-
return
|
|
1098
|
+
return void 0;
|
|
774
1099
|
}
|
|
775
1100
|
static is(a) {
|
|
776
1101
|
return typeof this.cast(a) != "undefined";
|
|
@@ -794,14 +1119,14 @@ class Circle {
|
|
|
794
1119
|
return `${this.position.toString()}|${this.radius}`;
|
|
795
1120
|
}
|
|
796
1121
|
clone() {
|
|
797
|
-
return new
|
|
1122
|
+
return new _Circle(this.position.clone(), this.radius);
|
|
798
1123
|
}
|
|
799
1124
|
equals(circle) {
|
|
800
|
-
const c =
|
|
1125
|
+
const c = _Circle.resolve(circle);
|
|
801
1126
|
return c.position.equals(c.position) && this.radius == c.radius;
|
|
802
1127
|
}
|
|
803
1128
|
inside(a) {
|
|
804
|
-
const circle =
|
|
1129
|
+
const circle = _Circle.resolve(a);
|
|
805
1130
|
const distX = circle.x - this.x;
|
|
806
1131
|
const distY = circle.y - this.y;
|
|
807
1132
|
const dist = Math.sqrt(distX * distX + (distY + distY));
|
|
@@ -810,9 +1135,10 @@ class Circle {
|
|
|
810
1135
|
insidePoint(a) {
|
|
811
1136
|
return this.position.distance(a) <= this.radius;
|
|
812
1137
|
}
|
|
813
|
-
}
|
|
1138
|
+
};
|
|
814
1139
|
|
|
815
|
-
|
|
1140
|
+
// source/geometry/rectangle.ts
|
|
1141
|
+
var Rectangle = class _Rectangle {
|
|
816
1142
|
position;
|
|
817
1143
|
size;
|
|
818
1144
|
get area() {
|
|
@@ -859,11 +1185,11 @@ class Rectangle {
|
|
|
859
1185
|
}
|
|
860
1186
|
static cast(a) {
|
|
861
1187
|
if (a == null || typeof a == "undefined")
|
|
862
|
-
return
|
|
1188
|
+
return void 0;
|
|
863
1189
|
if (check_number_array(a, 4))
|
|
864
|
-
return new this(a[0], a[1], a[2], a[3]);
|
|
1190
|
+
return new this([a[0], a[1]], [a[2], a[3]]);
|
|
865
1191
|
if (check_number_array(a, 5)) {
|
|
866
|
-
const rect = new this(a[0], a[1], a[3], a[4]);
|
|
1192
|
+
const rect = new this([a[0], a[1]], [a[3], a[4]]);
|
|
867
1193
|
rect.w = a[2];
|
|
868
1194
|
return rect;
|
|
869
1195
|
}
|
|
@@ -872,39 +1198,25 @@ class Rectangle {
|
|
|
872
1198
|
const pos = Vec2.cast(spos);
|
|
873
1199
|
const size = Size.cast(ssize);
|
|
874
1200
|
if (typeof pos == "undefined" || typeof size == "undefined")
|
|
875
|
-
return
|
|
876
|
-
const rect = new this(pos.x, pos.y, size.width, size.height);
|
|
1201
|
+
return void 0;
|
|
1202
|
+
const rect = new this([pos.x, pos.y], [size.width, size.height]);
|
|
877
1203
|
rect.w = pos.w;
|
|
878
1204
|
return rect;
|
|
879
1205
|
}
|
|
880
1206
|
if (has_property(a, "x", "number") && has_property(a, "y", "number") && has_property(a, "width", "number") && has_property(a, "height", "number")) {
|
|
881
|
-
const rect = new this(a.x, a.y, a.width, a.height);
|
|
1207
|
+
const rect = new this([a.x, a.y], [a.width, a.height]);
|
|
882
1208
|
if (has_property(a, "w", "number"))
|
|
883
1209
|
rect.w = a.w;
|
|
884
1210
|
return rect;
|
|
885
1211
|
}
|
|
886
|
-
return
|
|
1212
|
+
return void 0;
|
|
887
1213
|
}
|
|
888
1214
|
static is(a) {
|
|
889
1215
|
return typeof this.cast(a) != "undefined";
|
|
890
1216
|
}
|
|
891
|
-
constructor(
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
const x = typeof a == "number" ? a : vec?.x;
|
|
895
|
-
if (!check_number(x))
|
|
896
|
-
throw new TypeError("expected number for x position");
|
|
897
|
-
const y = typeof b == "number" ? b : vec?.y;
|
|
898
|
-
if (!check_number(y))
|
|
899
|
-
throw new TypeError("expected number for y position");
|
|
900
|
-
const width = typeof c == "number" ? c : size?.width;
|
|
901
|
-
if (!check_number(width))
|
|
902
|
-
throw new TypeError("expected number for width");
|
|
903
|
-
const height = typeof d == "number" ? d : size?.height;
|
|
904
|
-
if (!check_number(height))
|
|
905
|
-
throw new TypeError("expected number for height");
|
|
906
|
-
this.position = new Vec2(x, y);
|
|
907
|
-
this.size = new Size(width, height);
|
|
1217
|
+
constructor(pos, size) {
|
|
1218
|
+
this.position = Vec2.resolve(pos);
|
|
1219
|
+
this.size = Size.resolve(size);
|
|
908
1220
|
}
|
|
909
1221
|
toArray(w = false) {
|
|
910
1222
|
return [...this.position.toArray(w), ...this.size.toArray()];
|
|
@@ -919,15 +1231,16 @@ class Rectangle {
|
|
|
919
1231
|
return [this.x, this.x + this.width, this.y, this.y + this.height];
|
|
920
1232
|
}
|
|
921
1233
|
clone() {
|
|
922
|
-
return new
|
|
1234
|
+
return new _Rectangle(this.position.clone(), this.size.clone());
|
|
923
1235
|
}
|
|
924
1236
|
equals(rectangle) {
|
|
925
|
-
const rect =
|
|
1237
|
+
const rect = _Rectangle.resolve(rectangle);
|
|
926
1238
|
return this.position.equals(rect.position) && this.size.equals(rect.size);
|
|
927
1239
|
}
|
|
928
|
-
}
|
|
1240
|
+
};
|
|
929
1241
|
|
|
930
|
-
|
|
1242
|
+
// source/geometry/bbox.ts
|
|
1243
|
+
var BoundingBox = class _BoundingBox {
|
|
931
1244
|
left;
|
|
932
1245
|
right;
|
|
933
1246
|
top;
|
|
@@ -952,7 +1265,7 @@ class BoundingBox {
|
|
|
952
1265
|
}
|
|
953
1266
|
static cast(a) {
|
|
954
1267
|
if (a == null || typeof a == "undefined")
|
|
955
|
-
return
|
|
1268
|
+
return void 0;
|
|
956
1269
|
if (check_number_array(a, 4))
|
|
957
1270
|
return new this(a[0], a[1], a[2], a[3]);
|
|
958
1271
|
if (has_property(a, "left", "number") && has_property(a, "right", "number") && has_property(a, "top", "number") && has_property(a, "bottom", "number"))
|
|
@@ -962,7 +1275,7 @@ class BoundingBox {
|
|
|
962
1275
|
if (check_string_array(parts, 4))
|
|
963
1276
|
return this.cast(parts.map((v) => parseFloat(v)));
|
|
964
1277
|
}
|
|
965
|
-
return
|
|
1278
|
+
return void 0;
|
|
966
1279
|
}
|
|
967
1280
|
static is(a) {
|
|
968
1281
|
return typeof this.cast(a) != "undefined";
|
|
@@ -996,25 +1309,25 @@ class BoundingBox {
|
|
|
996
1309
|
};
|
|
997
1310
|
}
|
|
998
1311
|
clone() {
|
|
999
|
-
return new
|
|
1312
|
+
return new _BoundingBox(this.left, this.right, this.top, this.bottom);
|
|
1000
1313
|
}
|
|
1001
1314
|
equals(bbox) {
|
|
1002
|
-
const b =
|
|
1315
|
+
const b = _BoundingBox.resolve(bbox);
|
|
1003
1316
|
return this.left == b.left && this.right == b.right && this.top == b.top && this.bottom == b.bottom;
|
|
1004
1317
|
}
|
|
1005
1318
|
toSquare() {
|
|
1006
1319
|
return new Size(this.width, this.height);
|
|
1007
1320
|
}
|
|
1008
1321
|
toRectangle() {
|
|
1009
|
-
return new Rectangle(this.left, this.top, this.width, this.height);
|
|
1322
|
+
return new Rectangle([this.left, this.top], [this.width, this.height]);
|
|
1010
1323
|
}
|
|
1011
1324
|
inside(a) {
|
|
1012
|
-
const bbox =
|
|
1325
|
+
const bbox = _BoundingBox.resolve(a);
|
|
1013
1326
|
return this.right >= bbox.left && bbox.right >= this.left && this.bottom >= bbox.top && bbox.bottom >= this.top;
|
|
1014
1327
|
}
|
|
1015
1328
|
insidePoint(a) {
|
|
1016
1329
|
const point = Vec2.resolve(a);
|
|
1017
|
-
return this.left <= point.x && this.right >= point.x && this.top
|
|
1330
|
+
return this.left <= point.x && this.right >= point.x && this.top <= point.y && this.bottom >= point.y;
|
|
1018
1331
|
}
|
|
1019
1332
|
insideCircle(a) {
|
|
1020
1333
|
const circle = Circle.resolve(a);
|
|
@@ -1027,9 +1340,10 @@ class BoundingBox {
|
|
|
1027
1340
|
diff = closest.subtract(center);
|
|
1028
1341
|
return diff.length() < circle.radius;
|
|
1029
1342
|
}
|
|
1030
|
-
}
|
|
1343
|
+
};
|
|
1031
1344
|
|
|
1032
|
-
|
|
1345
|
+
// source/geometry/triangle.ts
|
|
1346
|
+
var ATriangle = class {
|
|
1033
1347
|
constructor(A, B, C) {
|
|
1034
1348
|
this.A = A;
|
|
1035
1349
|
this.B = B;
|
|
@@ -1059,8 +1373,8 @@ class ATriangle {
|
|
|
1059
1373
|
get height() {
|
|
1060
1374
|
return 2 * (this.area / this.base);
|
|
1061
1375
|
}
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1376
|
+
};
|
|
1377
|
+
var Triangle2D = class extends ATriangle {
|
|
1064
1378
|
get a() {
|
|
1065
1379
|
return Vec2.fromPoints(this.B, this.C).length();
|
|
1066
1380
|
}
|
|
@@ -1070,8 +1384,8 @@ class Triangle2D extends ATriangle {
|
|
|
1070
1384
|
get c() {
|
|
1071
1385
|
return Vec2.fromPoints(this.A, this.B).length();
|
|
1072
1386
|
}
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1387
|
+
};
|
|
1388
|
+
var Triangle3D = class extends ATriangle {
|
|
1075
1389
|
get a() {
|
|
1076
1390
|
return Vec3.fromPoints(this.B, this.C).length();
|
|
1077
1391
|
}
|
|
@@ -1081,9 +1395,10 @@ class Triangle3D extends ATriangle {
|
|
|
1081
1395
|
get c() {
|
|
1082
1396
|
return Vec3.fromPoints(this.A, this.B).length();
|
|
1083
1397
|
}
|
|
1084
|
-
}
|
|
1398
|
+
};
|
|
1085
1399
|
|
|
1086
|
-
|
|
1400
|
+
// source/matrices/mat3.ts
|
|
1401
|
+
var Mat3 = class _Mat3 {
|
|
1087
1402
|
_raw;
|
|
1088
1403
|
get m00() {
|
|
1089
1404
|
return this._raw[0];
|
|
@@ -1147,11 +1462,11 @@ class Mat3 {
|
|
|
1147
1462
|
}
|
|
1148
1463
|
static cast(a) {
|
|
1149
1464
|
if (a == null || typeof a == "undefined")
|
|
1150
|
-
return
|
|
1465
|
+
return void 0;
|
|
1151
1466
|
if (check_number_array(a, 9)) {
|
|
1152
1467
|
return new this(a);
|
|
1153
1468
|
}
|
|
1154
|
-
if (check_array(a,
|
|
1469
|
+
if (check_array(a, void 0, 3)) {
|
|
1155
1470
|
const row0 = a[0], row1 = a[1], row2 = a[2];
|
|
1156
1471
|
if (check_number_array(row0, 3) && check_number_array(row1, 3) && check_number_array(row2, 3))
|
|
1157
1472
|
return new this([
|
|
@@ -1186,7 +1501,7 @@ class Mat3 {
|
|
|
1186
1501
|
if (check_number(a)) {
|
|
1187
1502
|
return new this([a, a, a, a, a, a, a, a, a]);
|
|
1188
1503
|
}
|
|
1189
|
-
return
|
|
1504
|
+
return void 0;
|
|
1190
1505
|
}
|
|
1191
1506
|
static is(a) {
|
|
1192
1507
|
return typeof this.cast(a) != "undefined";
|
|
@@ -1246,7 +1561,7 @@ class Mat3 {
|
|
|
1246
1561
|
return `${this.m00},${this.m01},${this.m02},${this.m10},${this.m11},${this.m12},${this.m20},${this.m21},${this.m22}`;
|
|
1247
1562
|
}
|
|
1248
1563
|
clone() {
|
|
1249
|
-
return new
|
|
1564
|
+
return new _Mat3([
|
|
1250
1565
|
this.m00,
|
|
1251
1566
|
this.m01,
|
|
1252
1567
|
this.m02,
|
|
@@ -1259,29 +1574,29 @@ class Mat3 {
|
|
|
1259
1574
|
]);
|
|
1260
1575
|
}
|
|
1261
1576
|
equals(mat) {
|
|
1262
|
-
const m =
|
|
1577
|
+
const m = _Mat3.resolve(mat);
|
|
1263
1578
|
for (let index = 0; index < this._raw.length; index++)
|
|
1264
1579
|
if (this._raw[index] != m._raw[index])
|
|
1265
1580
|
return false;
|
|
1266
1581
|
return true;
|
|
1267
1582
|
}
|
|
1268
1583
|
add(mat) {
|
|
1269
|
-
const b =
|
|
1270
|
-
const m = new
|
|
1584
|
+
const b = _Mat3.resolve(mat);
|
|
1585
|
+
const m = new _Mat3();
|
|
1271
1586
|
for (let index = 0; index < this._raw.length; index++)
|
|
1272
1587
|
m._raw[index] = this._raw[index] + b._raw[index];
|
|
1273
|
-
return
|
|
1588
|
+
return m;
|
|
1274
1589
|
}
|
|
1275
1590
|
subtract(mat) {
|
|
1276
|
-
const b =
|
|
1277
|
-
const m = new
|
|
1591
|
+
const b = _Mat3.resolve(mat);
|
|
1592
|
+
const m = new _Mat3();
|
|
1278
1593
|
for (let index = 0; index < this._raw.length; index++)
|
|
1279
1594
|
m._raw[index] = this._raw[index] - b._raw[index];
|
|
1280
|
-
return
|
|
1595
|
+
return m;
|
|
1281
1596
|
}
|
|
1282
1597
|
multiply(a) {
|
|
1283
1598
|
if (check_number(a))
|
|
1284
|
-
return new
|
|
1599
|
+
return new _Mat3([
|
|
1285
1600
|
this.m00 * a,
|
|
1286
1601
|
this.m01 * a,
|
|
1287
1602
|
this.m02 * a,
|
|
@@ -1292,8 +1607,8 @@ class Mat3 {
|
|
|
1292
1607
|
this.m21 * a,
|
|
1293
1608
|
this.m22 * a
|
|
1294
1609
|
]);
|
|
1295
|
-
const b =
|
|
1296
|
-
return new
|
|
1610
|
+
const b = _Mat3.resolve(a);
|
|
1611
|
+
return new _Mat3([
|
|
1297
1612
|
b.m00 * this.m00 + b.m01 * this.m10 + b.m02 * this.m20,
|
|
1298
1613
|
b.m00 * this.m01 + b.m01 * this.m11 + b.m02 * this.m21,
|
|
1299
1614
|
b.m00 * this.m02 + b.m01 * this.m12 + b.m02 * this.m22,
|
|
@@ -1353,7 +1668,7 @@ class Mat3 {
|
|
|
1353
1668
|
}
|
|
1354
1669
|
inverse() {
|
|
1355
1670
|
const det = this.determinant();
|
|
1356
|
-
return new
|
|
1671
|
+
return new _Mat3([
|
|
1357
1672
|
(this.m11 * this.m22 - this.m21 * this.m12) * det,
|
|
1358
1673
|
(this.m02 * this.m21 - this.m01 * this.m22) * det,
|
|
1359
1674
|
(this.m01 * this.m12 - this.m02 * this.m11) * det,
|
|
@@ -1385,9 +1700,10 @@ class Mat3 {
|
|
|
1385
1700
|
1
|
|
1386
1701
|
];
|
|
1387
1702
|
}
|
|
1388
|
-
}
|
|
1703
|
+
};
|
|
1389
1704
|
|
|
1390
|
-
|
|
1705
|
+
// source/matrices/mat4.ts
|
|
1706
|
+
var Mat4 = class _Mat4 {
|
|
1391
1707
|
_raw;
|
|
1392
1708
|
get m00() {
|
|
1393
1709
|
return this._raw[0];
|
|
@@ -1493,11 +1809,11 @@ class Mat4 {
|
|
|
1493
1809
|
}
|
|
1494
1810
|
static cast(a) {
|
|
1495
1811
|
if (a == null || typeof a == "undefined")
|
|
1496
|
-
return
|
|
1812
|
+
return void 0;
|
|
1497
1813
|
if (check_number_array(a, 16)) {
|
|
1498
1814
|
return new this(a);
|
|
1499
1815
|
}
|
|
1500
|
-
if (check_array(a,
|
|
1816
|
+
if (check_array(a, void 0, 4)) {
|
|
1501
1817
|
const row0 = a[0], row1 = a[1], row2 = a[2], row3 = a[3];
|
|
1502
1818
|
if (check_number_array(row0, 4) && check_number_array(row1, 4) && check_number_array(row2, 4) && check_number_array(row3, 4))
|
|
1503
1819
|
return new this([
|
|
@@ -1546,7 +1862,7 @@ class Mat4 {
|
|
|
1546
1862
|
if (check_number(a)) {
|
|
1547
1863
|
return new this([a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a]);
|
|
1548
1864
|
}
|
|
1549
|
-
return
|
|
1865
|
+
return void 0;
|
|
1550
1866
|
}
|
|
1551
1867
|
static is(a) {
|
|
1552
1868
|
return typeof this.cast(a) != "undefined";
|
|
@@ -1675,7 +1991,7 @@ class Mat4 {
|
|
|
1675
1991
|
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}`;
|
|
1676
1992
|
}
|
|
1677
1993
|
clone() {
|
|
1678
|
-
return new
|
|
1994
|
+
return new _Mat4([
|
|
1679
1995
|
this.m00,
|
|
1680
1996
|
this.m01,
|
|
1681
1997
|
this.m02,
|
|
@@ -1695,29 +2011,29 @@ class Mat4 {
|
|
|
1695
2011
|
]);
|
|
1696
2012
|
}
|
|
1697
2013
|
equals(mat) {
|
|
1698
|
-
const m =
|
|
2014
|
+
const m = _Mat4.resolve(mat);
|
|
1699
2015
|
for (let index = 0; index < this._raw.length; index++)
|
|
1700
2016
|
if (this._raw[index] != m._raw[index])
|
|
1701
2017
|
return false;
|
|
1702
2018
|
return true;
|
|
1703
2019
|
}
|
|
1704
2020
|
add(mat) {
|
|
1705
|
-
const b =
|
|
1706
|
-
const m = new
|
|
2021
|
+
const b = _Mat4.resolve(mat);
|
|
2022
|
+
const m = new _Mat4();
|
|
1707
2023
|
for (let index = 0; index < this._raw.length; index++)
|
|
1708
2024
|
m._raw[index] = this._raw[index] + b._raw[index];
|
|
1709
2025
|
return m;
|
|
1710
2026
|
}
|
|
1711
2027
|
subtract(mat) {
|
|
1712
|
-
const b =
|
|
1713
|
-
const m = new
|
|
2028
|
+
const b = _Mat4.resolve(mat);
|
|
2029
|
+
const m = new _Mat4();
|
|
1714
2030
|
for (let index = 0; index < this._raw.length; index++)
|
|
1715
2031
|
m._raw[index] = this._raw[index] - b._raw[index];
|
|
1716
2032
|
return m;
|
|
1717
2033
|
}
|
|
1718
2034
|
multiply(a) {
|
|
1719
2035
|
if (check_number(a)) {
|
|
1720
|
-
return new
|
|
2036
|
+
return new _Mat4([
|
|
1721
2037
|
this.m00 * a,
|
|
1722
2038
|
this.m01 * a,
|
|
1723
2039
|
this.m02 * a,
|
|
@@ -1736,9 +2052,9 @@ class Mat4 {
|
|
|
1736
2052
|
this.m33 * a
|
|
1737
2053
|
]);
|
|
1738
2054
|
}
|
|
1739
|
-
if (
|
|
1740
|
-
const b =
|
|
1741
|
-
return new
|
|
2055
|
+
if (_Mat4.is(a)) {
|
|
2056
|
+
const b = _Mat4.resolve(a);
|
|
2057
|
+
return new _Mat4([
|
|
1742
2058
|
b.m00 * this.m00 + b.m01 * this.m10 + b.m02 * this.m20 + b.m03 * this.m30,
|
|
1743
2059
|
b.m00 * this.m01 + b.m01 * this.m11 + b.m02 * this.m21 + b.m03 * this.m31,
|
|
1744
2060
|
b.m00 * this.m02 + b.m01 * this.m12 + b.m02 * this.m22 + b.m03 * this.m32,
|
|
@@ -1884,7 +2200,7 @@ class Mat4 {
|
|
|
1884
2200
|
]);
|
|
1885
2201
|
}
|
|
1886
2202
|
inverse() {
|
|
1887
|
-
return new
|
|
2203
|
+
return new _Mat4([
|
|
1888
2204
|
this.m00,
|
|
1889
2205
|
this.m10,
|
|
1890
2206
|
this.m20,
|
|
@@ -1916,11 +2232,12 @@ class Mat4 {
|
|
|
1916
2232
|
this.m33
|
|
1917
2233
|
];
|
|
1918
2234
|
}
|
|
1919
|
-
}
|
|
2235
|
+
};
|
|
1920
2236
|
|
|
2237
|
+
// source/color.ts
|
|
1921
2238
|
function _hex_to_array(hex) {
|
|
1922
2239
|
if (!check_hex(hex))
|
|
1923
|
-
return
|
|
2240
|
+
return void 0;
|
|
1924
2241
|
const part = get_hex_part(hex);
|
|
1925
2242
|
const a = parseInt(part.substring(0, 2), 16) / 255;
|
|
1926
2243
|
const b = parseInt(part.substring(2, 4), 16) / 255;
|
|
@@ -1944,7 +2261,7 @@ function _number_to_rgba(number) {
|
|
|
1944
2261
|
function _fix_integer(number) {
|
|
1945
2262
|
return number * 255 | 0;
|
|
1946
2263
|
}
|
|
1947
|
-
|
|
2264
|
+
var RGBAColor = class _RGBAColor {
|
|
1948
2265
|
_red;
|
|
1949
2266
|
get red() {
|
|
1950
2267
|
return this._red;
|
|
@@ -1981,11 +2298,11 @@ class RGBAColor {
|
|
|
1981
2298
|
}
|
|
1982
2299
|
static cast(a) {
|
|
1983
2300
|
if (a == null || typeof a == "undefined")
|
|
1984
|
-
return
|
|
2301
|
+
return void 0;
|
|
1985
2302
|
if (check_number_array(a, 3) || check_number_array(a, 4))
|
|
1986
2303
|
return new this(a[0], a[1], a[2], a[3]);
|
|
1987
2304
|
if (has_property(a, "red", "number") && has_property(a, "green", "number") && has_property(a, "blue", "number"))
|
|
1988
|
-
return new this(a.red, a.green, a.blue, has_property(a, "alpha", "number") ? a.alpha :
|
|
2305
|
+
return new this(a.red, a.green, a.blue, has_property(a, "alpha", "number") ? a.alpha : void 0);
|
|
1989
2306
|
if (check_number(a)) {
|
|
1990
2307
|
const hex = a.toString(16);
|
|
1991
2308
|
const convert = hex.length <= 6 ? _number_to_rgb : _number_to_rgba;
|
|
@@ -2001,7 +2318,7 @@ class RGBAColor {
|
|
|
2001
2318
|
}
|
|
2002
2319
|
return this.cast(_hex_to_array(a));
|
|
2003
2320
|
}
|
|
2004
|
-
return
|
|
2321
|
+
return void 0;
|
|
2005
2322
|
}
|
|
2006
2323
|
static is(a) {
|
|
2007
2324
|
return typeof this.cast(a) != "undefined";
|
|
@@ -2024,14 +2341,14 @@ class RGBAColor {
|
|
|
2024
2341
|
} : this.alpha == 1 ? { red: this.red, green: this.green, blue: this.blue } : this.toJSON(true);
|
|
2025
2342
|
}
|
|
2026
2343
|
toString(withAlpha = false) {
|
|
2027
|
-
return withAlpha ? `rgba(${_fix_integer(this.red)},${_fix_integer(this.green)},${_fix_integer(this.blue)},${
|
|
2344
|
+
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);
|
|
2028
2345
|
}
|
|
2029
2346
|
toHSL(withAlpha = true) {
|
|
2030
2347
|
const red = this.red, green = this.green, blue = this.blue;
|
|
2031
2348
|
const min = Math.min(red, green, blue), max = Math.max(red, green, blue);
|
|
2032
2349
|
const luminace = (min + max) / 2;
|
|
2033
2350
|
if (min == max)
|
|
2034
|
-
return new HSLColor(0, 0, luminace, withAlpha ? this.alpha :
|
|
2351
|
+
return new HSLColor(0, 0, luminace, withAlpha ? this.alpha : void 0);
|
|
2035
2352
|
const d = max - min;
|
|
2036
2353
|
const saturation = luminace > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
2037
2354
|
if (max == red)
|
|
@@ -2040,18 +2357,18 @@ class RGBAColor {
|
|
|
2040
2357
|
return new HSLColor(((blue - red) / d + 2) / 6, saturation, luminace);
|
|
2041
2358
|
if (max == blue)
|
|
2042
2359
|
return new HSLColor(((red - green) / d + 4) / 6, saturation, luminace);
|
|
2043
|
-
return new HSLColor(0, saturation, luminace, withAlpha ? this.alpha :
|
|
2360
|
+
return new HSLColor(0, saturation, luminace, withAlpha ? this.alpha : void 0);
|
|
2044
2361
|
}
|
|
2045
2362
|
invert(withAlpha = false) {
|
|
2046
|
-
return new
|
|
2363
|
+
return new _RGBAColor(
|
|
2047
2364
|
1 - this.red,
|
|
2048
2365
|
1 - this.green,
|
|
2049
2366
|
1 - this.blue,
|
|
2050
2367
|
withAlpha ? 1 - this.alpha : this.alpha
|
|
2051
2368
|
);
|
|
2052
2369
|
}
|
|
2053
|
-
}
|
|
2054
|
-
|
|
2370
|
+
};
|
|
2371
|
+
var HSLColor = class _HSLColor {
|
|
2055
2372
|
_hue;
|
|
2056
2373
|
get hue() {
|
|
2057
2374
|
return this._hue;
|
|
@@ -2088,11 +2405,11 @@ class HSLColor {
|
|
|
2088
2405
|
}
|
|
2089
2406
|
static cast(a) {
|
|
2090
2407
|
if (a == null || typeof a == "undefined")
|
|
2091
|
-
return
|
|
2408
|
+
return void 0;
|
|
2092
2409
|
if (check_number_array(a, 3) || check_number_array(a, 4))
|
|
2093
2410
|
return new this(a[0], a[1], a[2], a[3]);
|
|
2094
2411
|
if (has_property(a, "hue", "number") && has_property(a, "saturation", "number") && has_property(a, "luminace", "number"))
|
|
2095
|
-
return new this(a.hue, a.saturation, a.luminace, has_property(a, "alpha", "number") ? a.alpha :
|
|
2412
|
+
return new this(a.hue, a.saturation, a.luminace, has_property(a, "alpha", "number") ? a.alpha : void 0);
|
|
2096
2413
|
if (check_number(a)) {
|
|
2097
2414
|
const hex = a.toString(16);
|
|
2098
2415
|
const convert = hex.length <= 6 ? _number_to_rgb : _number_to_rgba;
|
|
@@ -2108,7 +2425,7 @@ class HSLColor {
|
|
|
2108
2425
|
}
|
|
2109
2426
|
return this.cast(_hex_to_array(a));
|
|
2110
2427
|
}
|
|
2111
|
-
return
|
|
2428
|
+
return void 0;
|
|
2112
2429
|
}
|
|
2113
2430
|
static is(a) {
|
|
2114
2431
|
return typeof this.cast(a) != "undefined";
|
|
@@ -2139,11 +2456,11 @@ class HSLColor {
|
|
|
2139
2456
|
} : this.alpha == 1 ? { hue: this.hue, saturation: this.saturation, luminace: this.luminace } : this.toJSON(true);
|
|
2140
2457
|
}
|
|
2141
2458
|
toString(withAlpha = false) {
|
|
2142
|
-
return withAlpha ? `hsla(${_fix_integer(this.hue)},${_fix_integer(this.saturation)},${_fix_integer(this.luminace)},${
|
|
2459
|
+
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);
|
|
2143
2460
|
}
|
|
2144
2461
|
toRGB(withAlpha = true) {
|
|
2145
2462
|
if (this.saturation == 0)
|
|
2146
|
-
return new RGBAColor(this.luminace * 255, this.luminace * 255, this.luminace * 255, withAlpha ? this.alpha :
|
|
2463
|
+
return new RGBAColor(this.luminace * 255, this.luminace * 255, this.luminace * 255, withAlpha ? this.alpha : void 0);
|
|
2147
2464
|
const q = this.luminace < 0.5 ? this.luminace * (1 + this.saturation) : this.luminace + this.saturation - this.luminace * this.saturation;
|
|
2148
2465
|
const p = 2 * this.luminace - q;
|
|
2149
2466
|
function _hue_2_rgb(t) {
|
|
@@ -2160,17 +2477,17 @@ class HSLColor {
|
|
|
2160
2477
|
return p + (q - p) * (2 / 3 - _t) * 6;
|
|
2161
2478
|
return p;
|
|
2162
2479
|
}
|
|
2163
|
-
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 :
|
|
2480
|
+
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);
|
|
2164
2481
|
}
|
|
2165
2482
|
invert(withAlpha = false) {
|
|
2166
|
-
return new
|
|
2483
|
+
return new _HSLColor(
|
|
2167
2484
|
1 - this.hue,
|
|
2168
2485
|
1 - this.saturation,
|
|
2169
2486
|
1 - this.luminace,
|
|
2170
2487
|
withAlpha ? 1 - this.alpha : this.alpha
|
|
2171
2488
|
);
|
|
2172
2489
|
}
|
|
2173
|
-
}
|
|
2490
|
+
};
|
|
2174
2491
|
function resolveColor(a, preferHSL = false) {
|
|
2175
2492
|
const value = castColor(a, preferHSL);
|
|
2176
2493
|
if (typeof value != "undefined")
|
|
@@ -2196,10 +2513,11 @@ function castColor(a, preferHSL = false) {
|
|
|
2196
2513
|
const secondItem = results[offset + 1];
|
|
2197
2514
|
if (secondItem)
|
|
2198
2515
|
return secondItem;
|
|
2199
|
-
return
|
|
2516
|
+
return void 0;
|
|
2200
2517
|
}
|
|
2201
2518
|
|
|
2202
|
-
|
|
2519
|
+
// source/quaternion.ts
|
|
2520
|
+
var Quaternion = class _Quaternion {
|
|
2203
2521
|
w;
|
|
2204
2522
|
x;
|
|
2205
2523
|
y;
|
|
@@ -2215,7 +2533,7 @@ class Quaternion {
|
|
|
2215
2533
|
}
|
|
2216
2534
|
static cast(a) {
|
|
2217
2535
|
if (a == null || typeof a == "undefined")
|
|
2218
|
-
return
|
|
2536
|
+
return void 0;
|
|
2219
2537
|
if (check_number_array(a, 4))
|
|
2220
2538
|
return new this(a[0], a[1], a[2], a[3]);
|
|
2221
2539
|
if (has_property(a, "w", "number") && has_property(a, "x", "number") && has_property(a, "y", "number") && has_property(a, "z", "number"))
|
|
@@ -2233,7 +2551,7 @@ class Quaternion {
|
|
|
2233
2551
|
]);
|
|
2234
2552
|
}
|
|
2235
2553
|
}
|
|
2236
|
-
return
|
|
2554
|
+
return void 0;
|
|
2237
2555
|
}
|
|
2238
2556
|
static fromAxisAngle(axis, angle) {
|
|
2239
2557
|
const vec = Vec3.resolve(axis);
|
|
@@ -2248,7 +2566,7 @@ class Quaternion {
|
|
|
2248
2566
|
const x2 = vec.x * 0.5, y2 = vec.y * 0.5, z2 = vec.z * 0.5;
|
|
2249
2567
|
const cx = Math.cos(x2), cy = Math.cos(y2), cz = Math.cos(z2);
|
|
2250
2568
|
const sx = Math.sin(x2), sy = Math.sin(y2), sz = Math.sin(z2);
|
|
2251
|
-
return new
|
|
2569
|
+
return new _Quaternion(
|
|
2252
2570
|
cx * cy * cz - sx * sy * sz,
|
|
2253
2571
|
sx * cy * cz - sy * sz * cx,
|
|
2254
2572
|
sy * cx * cz - sx * sz * cy,
|
|
@@ -2284,11 +2602,11 @@ class Quaternion {
|
|
|
2284
2602
|
};
|
|
2285
2603
|
}
|
|
2286
2604
|
clone() {
|
|
2287
|
-
return new
|
|
2605
|
+
return new _Quaternion(this.w, this.x, this.y, this.z);
|
|
2288
2606
|
}
|
|
2289
2607
|
add(a) {
|
|
2290
|
-
const quat =
|
|
2291
|
-
return new
|
|
2608
|
+
const quat = _Quaternion.resolve(a);
|
|
2609
|
+
return new _Quaternion(
|
|
2292
2610
|
this.w + quat.w,
|
|
2293
2611
|
this.x + quat.x,
|
|
2294
2612
|
this.y + quat.y,
|
|
@@ -2296,7 +2614,7 @@ class Quaternion {
|
|
|
2296
2614
|
);
|
|
2297
2615
|
}
|
|
2298
2616
|
offset(a) {
|
|
2299
|
-
const quat =
|
|
2617
|
+
const quat = _Quaternion.resolve(a);
|
|
2300
2618
|
this.w += quat.w;
|
|
2301
2619
|
this.x += quat.x;
|
|
2302
2620
|
this.y += quat.y;
|
|
@@ -2304,8 +2622,8 @@ class Quaternion {
|
|
|
2304
2622
|
return this;
|
|
2305
2623
|
}
|
|
2306
2624
|
subtract(a) {
|
|
2307
|
-
const quat =
|
|
2308
|
-
return new
|
|
2625
|
+
const quat = _Quaternion.resolve(a);
|
|
2626
|
+
return new _Quaternion(
|
|
2309
2627
|
this.w - quat.w,
|
|
2310
2628
|
this.x - quat.x,
|
|
2311
2629
|
this.y - quat.y,
|
|
@@ -2313,7 +2631,7 @@ class Quaternion {
|
|
|
2313
2631
|
);
|
|
2314
2632
|
}
|
|
2315
2633
|
negative() {
|
|
2316
|
-
return new
|
|
2634
|
+
return new _Quaternion(-this.w, -this.x, -this.y, -this.z);
|
|
2317
2635
|
}
|
|
2318
2636
|
length(sqrt = true) {
|
|
2319
2637
|
const value = this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z;
|
|
@@ -2322,13 +2640,13 @@ class Quaternion {
|
|
|
2322
2640
|
normalize() {
|
|
2323
2641
|
let length = this.length();
|
|
2324
2642
|
if (length < EPSILON)
|
|
2325
|
-
return new
|
|
2643
|
+
return new _Quaternion();
|
|
2326
2644
|
length = 1 / length;
|
|
2327
|
-
return new
|
|
2645
|
+
return new _Quaternion(this.w * length, this.x * length, this.y * length, this.z * length);
|
|
2328
2646
|
}
|
|
2329
2647
|
multiply(a) {
|
|
2330
|
-
const quat =
|
|
2331
|
-
return new
|
|
2648
|
+
const quat = _Quaternion.resolve(a);
|
|
2649
|
+
return new _Quaternion(
|
|
2332
2650
|
this.w * quat.w - this.x * quat.x - this.y * quat.y - this.z * quat.z,
|
|
2333
2651
|
this.w * quat.x + this.x * quat.w + this.y * quat.z - this.z * quat.y,
|
|
2334
2652
|
this.w * quat.y + this.y * quat.w + this.z * quat.x - this.x * quat.z,
|
|
@@ -2348,25 +2666,25 @@ class Quaternion {
|
|
|
2348
2666
|
);
|
|
2349
2667
|
}
|
|
2350
2668
|
scale(scalar) {
|
|
2351
|
-
return new
|
|
2669
|
+
return new _Quaternion(this.w * scalar, this.x * scalar, this.y * scalar, this.z * scalar);
|
|
2352
2670
|
}
|
|
2353
2671
|
dot(a) {
|
|
2354
|
-
const quat =
|
|
2672
|
+
const quat = _Quaternion.resolve(a);
|
|
2355
2673
|
return this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z;
|
|
2356
2674
|
}
|
|
2357
2675
|
inverse() {
|
|
2358
2676
|
let length = this.length(false);
|
|
2359
2677
|
if (length == 0)
|
|
2360
|
-
return new
|
|
2678
|
+
return new _Quaternion();
|
|
2361
2679
|
length = 1 / length;
|
|
2362
|
-
return new
|
|
2680
|
+
return new _Quaternion(this.w * length, -this.x * length, -this.y * length, -this.z * length);
|
|
2363
2681
|
}
|
|
2364
2682
|
divide(a) {
|
|
2365
|
-
const quat =
|
|
2683
|
+
const quat = _Quaternion.resolve(a);
|
|
2366
2684
|
let length = quat.length(false);
|
|
2367
|
-
if (length == 0) return new
|
|
2685
|
+
if (length == 0) return new _Quaternion();
|
|
2368
2686
|
length = 1 / length;
|
|
2369
|
-
return new
|
|
2687
|
+
return new _Quaternion(
|
|
2370
2688
|
(this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z) * length,
|
|
2371
2689
|
(this.x * quat.w - this.w * quat.x - this.y * quat.z + this.z * quat.y) * length,
|
|
2372
2690
|
(this.y * quat.w - this.w * quat.y - this.z * quat.x + this.x * quat.z) * length,
|
|
@@ -2374,15 +2692,15 @@ class Quaternion {
|
|
|
2374
2692
|
);
|
|
2375
2693
|
}
|
|
2376
2694
|
conjugate() {
|
|
2377
|
-
return new
|
|
2695
|
+
return new _Quaternion(this.w, -this.x, -this.y, -this.z);
|
|
2378
2696
|
}
|
|
2379
2697
|
exp() {
|
|
2380
2698
|
const length = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
|
2381
2699
|
const exp = Math.exp(this.w);
|
|
2382
2700
|
const scale = exp * Math.sin(length) / length;
|
|
2383
2701
|
if (length == 0)
|
|
2384
|
-
return new
|
|
2385
|
-
return new
|
|
2702
|
+
return new _Quaternion(exp);
|
|
2703
|
+
return new _Quaternion(
|
|
2386
2704
|
exp * Math.cos(length),
|
|
2387
2705
|
this.x * scale,
|
|
2388
2706
|
this.y * scale,
|
|
@@ -2391,11 +2709,11 @@ class Quaternion {
|
|
|
2391
2709
|
}
|
|
2392
2710
|
log() {
|
|
2393
2711
|
if (this.x == 0 && this.z == 0)
|
|
2394
|
-
return new
|
|
2712
|
+
return new _Quaternion(log_hypot(this.w, this.x), Math.atan2(this.x, this.w));
|
|
2395
2713
|
const length = this.length(false);
|
|
2396
2714
|
const length2 = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
|
2397
2715
|
const scale = Math.atan2(length2, this.w) / length;
|
|
2398
|
-
return new
|
|
2716
|
+
return new _Quaternion(Math.log(length) * 0.5, this.x * scale, this.y * scale, this.z * scale);
|
|
2399
2717
|
}
|
|
2400
2718
|
toVector() {
|
|
2401
2719
|
return new Vec3(this.x, this.y, this.z, this.w);
|
|
@@ -2451,9 +2769,10 @@ class Quaternion {
|
|
|
2451
2769
|
1
|
|
2452
2770
|
]);
|
|
2453
2771
|
}
|
|
2454
|
-
}
|
|
2772
|
+
};
|
|
2455
2773
|
|
|
2456
|
-
|
|
2774
|
+
// source/transform.ts
|
|
2775
|
+
var Transform = class {
|
|
2457
2776
|
/**
|
|
2458
2777
|
* The position of the object
|
|
2459
2778
|
*/
|
|
@@ -2484,6 +2803,53 @@ class Transform {
|
|
|
2484
2803
|
toMat4() {
|
|
2485
2804
|
return new Mat4().translate(this.position).multiply(this.rotation.toMat4()).scale(this.scale);
|
|
2486
2805
|
}
|
|
2487
|
-
}
|
|
2488
|
-
|
|
2489
|
-
|
|
2806
|
+
};
|
|
2807
|
+
export {
|
|
2808
|
+
ATriangle,
|
|
2809
|
+
BoundingBox,
|
|
2810
|
+
Circle,
|
|
2811
|
+
DJB2_OFFSET,
|
|
2812
|
+
EPSILON,
|
|
2813
|
+
FNV1_OFFSET,
|
|
2814
|
+
FNV1_PRIME,
|
|
2815
|
+
HSLColor,
|
|
2816
|
+
LinearFunction,
|
|
2817
|
+
MAX_ANGLE_DEGREE,
|
|
2818
|
+
MD2,
|
|
2819
|
+
Mat3,
|
|
2820
|
+
Mat4,
|
|
2821
|
+
MathFunction,
|
|
2822
|
+
QuadFunction,
|
|
2823
|
+
Quaternion,
|
|
2824
|
+
RGBAColor,
|
|
2825
|
+
Rectangle,
|
|
2826
|
+
ResolveError,
|
|
2827
|
+
Size,
|
|
2828
|
+
Transform,
|
|
2829
|
+
Triangle2D,
|
|
2830
|
+
Triangle3D,
|
|
2831
|
+
Vec2,
|
|
2832
|
+
Vec3,
|
|
2833
|
+
cap_angle_degree,
|
|
2834
|
+
cap_angle_radian,
|
|
2835
|
+
castColor,
|
|
2836
|
+
check_array,
|
|
2837
|
+
check_hex,
|
|
2838
|
+
check_hex_digit,
|
|
2839
|
+
check_number,
|
|
2840
|
+
check_number_array,
|
|
2841
|
+
check_string,
|
|
2842
|
+
check_string_array,
|
|
2843
|
+
clamp,
|
|
2844
|
+
degree_to_radian,
|
|
2845
|
+
djb2,
|
|
2846
|
+
fnv1,
|
|
2847
|
+
get_hex_part,
|
|
2848
|
+
has_property,
|
|
2849
|
+
log_hypot,
|
|
2850
|
+
radian_to_degree,
|
|
2851
|
+
resolveColor,
|
|
2852
|
+
sdbm,
|
|
2853
|
+
sign_char,
|
|
2854
|
+
stringify
|
|
2855
|
+
};
|