@ntf/math 1.2.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.
Files changed (125) hide show
  1. package/dist/index.d.mts +754 -0
  2. package/dist/index.d.ts +754 -0
  3. package/dist/index.js +2892 -0
  4. package/dist/index.mjs +2869 -0
  5. package/package.json +23 -13
  6. package/dist/cjs/algebra/function.js +0 -7
  7. package/dist/cjs/algebra/function.js.map +0 -1
  8. package/dist/cjs/algebra/linear.js +0 -49
  9. package/dist/cjs/algebra/linear.js.map +0 -1
  10. package/dist/cjs/algebra/quad.js +0 -62
  11. package/dist/cjs/algebra/quad.js.map +0 -1
  12. package/dist/cjs/color.js +0 -243
  13. package/dist/cjs/color.js.map +0 -1
  14. package/dist/cjs/common/error.js +0 -14
  15. package/dist/cjs/common/error.js.map +0 -1
  16. package/dist/cjs/common/sign.js +0 -14
  17. package/dist/cjs/common/sign.js.map +0 -1
  18. package/dist/cjs/common/types.js +0 -77
  19. package/dist/cjs/common/types.js.map +0 -1
  20. package/dist/cjs/geometry/angle.js +0 -11
  21. package/dist/cjs/geometry/angle.js.map +0 -1
  22. package/dist/cjs/geometry/bbox.js +0 -102
  23. package/dist/cjs/geometry/bbox.js.map +0 -1
  24. package/dist/cjs/geometry/circle.js +0 -87
  25. package/dist/cjs/geometry/circle.js.map +0 -1
  26. package/dist/cjs/geometry/object.js +0 -3
  27. package/dist/cjs/geometry/object.js.map +0 -1
  28. package/dist/cjs/geometry/rectangle.js +0 -98
  29. package/dist/cjs/geometry/rectangle.js.map +0 -1
  30. package/dist/cjs/geometry/square.js +0 -70
  31. package/dist/cjs/geometry/square.js.map +0 -1
  32. package/dist/cjs/geometry/triangle.js +0 -65
  33. package/dist/cjs/geometry/triangle.js.map +0 -1
  34. package/dist/cjs/index.js +0 -59
  35. package/dist/cjs/index.js.map +0 -1
  36. package/dist/cjs/matrices/mat3.js +0 -202
  37. package/dist/cjs/matrices/mat3.js.map +0 -1
  38. package/dist/cjs/matrices/mat4.js +0 -292
  39. package/dist/cjs/matrices/mat4.js.map +0 -1
  40. package/dist/cjs/quaternion.js +0 -204
  41. package/dist/cjs/quaternion.js.map +0 -1
  42. package/dist/cjs/vectors/vec2.js +0 -168
  43. package/dist/cjs/vectors/vec2.js.map +0 -1
  44. package/dist/cjs/vectors/vec3.js +0 -177
  45. package/dist/cjs/vectors/vec3.js.map +0 -1
  46. package/dist/esm/algebra/function.js +0 -3
  47. package/dist/esm/algebra/function.js.map +0 -1
  48. package/dist/esm/algebra/linear.js +0 -45
  49. package/dist/esm/algebra/linear.js.map +0 -1
  50. package/dist/esm/algebra/quad.js +0 -58
  51. package/dist/esm/algebra/quad.js.map +0 -1
  52. package/dist/esm/color.js +0 -236
  53. package/dist/esm/color.js.map +0 -1
  54. package/dist/esm/common/error.js +0 -10
  55. package/dist/esm/common/error.js.map +0 -1
  56. package/dist/esm/common/sign.js +0 -10
  57. package/dist/esm/common/sign.js.map +0 -1
  58. package/dist/esm/common/types.js +0 -65
  59. package/dist/esm/common/types.js.map +0 -1
  60. package/dist/esm/geometry/angle.js +0 -5
  61. package/dist/esm/geometry/angle.js.map +0 -1
  62. package/dist/esm/geometry/bbox.js +0 -98
  63. package/dist/esm/geometry/bbox.js.map +0 -1
  64. package/dist/esm/geometry/circle.js +0 -83
  65. package/dist/esm/geometry/circle.js.map +0 -1
  66. package/dist/esm/geometry/object.js +0 -2
  67. package/dist/esm/geometry/object.js.map +0 -1
  68. package/dist/esm/geometry/rectangle.js +0 -94
  69. package/dist/esm/geometry/rectangle.js.map +0 -1
  70. package/dist/esm/geometry/square.js +0 -66
  71. package/dist/esm/geometry/square.js.map +0 -1
  72. package/dist/esm/geometry/triangle.js +0 -59
  73. package/dist/esm/geometry/triangle.js.map +0 -1
  74. package/dist/esm/index.js +0 -40
  75. package/dist/esm/index.js.map +0 -1
  76. package/dist/esm/matrices/mat3.js +0 -198
  77. package/dist/esm/matrices/mat3.js.map +0 -1
  78. package/dist/esm/matrices/mat4.js +0 -288
  79. package/dist/esm/matrices/mat4.js.map +0 -1
  80. package/dist/esm/quaternion.js +0 -200
  81. package/dist/esm/quaternion.js.map +0 -1
  82. package/dist/esm/vectors/vec2.js +0 -164
  83. package/dist/esm/vectors/vec2.js.map +0 -1
  84. package/dist/esm/vectors/vec3.js +0 -173
  85. package/dist/esm/vectors/vec3.js.map +0 -1
  86. package/dist/types/algebra/function.d.ts +0 -6
  87. package/dist/types/algebra/function.d.ts.map +0 -1
  88. package/dist/types/algebra/linear.d.ts +0 -14
  89. package/dist/types/algebra/linear.d.ts.map +0 -1
  90. package/dist/types/algebra/quad.d.ts +0 -18
  91. package/dist/types/algebra/quad.d.ts.map +0 -1
  92. package/dist/types/color.d.ts +0 -90
  93. package/dist/types/color.d.ts.map +0 -1
  94. package/dist/types/common/error.d.ts +0 -6
  95. package/dist/types/common/error.d.ts.map +0 -1
  96. package/dist/types/common/sign.d.ts +0 -2
  97. package/dist/types/common/sign.d.ts.map +0 -1
  98. package/dist/types/common/types.d.ts +0 -26
  99. package/dist/types/common/types.d.ts.map +0 -1
  100. package/dist/types/geometry/angle.d.ts +0 -5
  101. package/dist/types/geometry/angle.d.ts.map +0 -1
  102. package/dist/types/geometry/bbox.d.ts +0 -38
  103. package/dist/types/geometry/bbox.d.ts.map +0 -1
  104. package/dist/types/geometry/circle.d.ts +0 -32
  105. package/dist/types/geometry/circle.d.ts.map +0 -1
  106. package/dist/types/geometry/object.d.ts +0 -5
  107. package/dist/types/geometry/object.d.ts.map +0 -1
  108. package/dist/types/geometry/rectangle.d.ts +0 -34
  109. package/dist/types/geometry/rectangle.d.ts.map +0 -1
  110. package/dist/types/geometry/square.d.ts +0 -28
  111. package/dist/types/geometry/square.d.ts.map +0 -1
  112. package/dist/types/geometry/triangle.d.ts +0 -42
  113. package/dist/types/geometry/triangle.d.ts.map +0 -1
  114. package/dist/types/index.d.ts +0 -23
  115. package/dist/types/index.d.ts.map +0 -1
  116. package/dist/types/matrices/mat3.d.ts +0 -62
  117. package/dist/types/matrices/mat3.d.ts.map +0 -1
  118. package/dist/types/matrices/mat4.d.ts +0 -89
  119. package/dist/types/matrices/mat4.d.ts.map +0 -1
  120. package/dist/types/quaternion.d.ts +0 -50
  121. package/dist/types/quaternion.d.ts.map +0 -1
  122. package/dist/types/vectors/vec2.d.ts +0 -60
  123. package/dist/types/vectors/vec2.d.ts.map +0 -1
  124. package/dist/types/vectors/vec3.d.ts +0 -58
  125. package/dist/types/vectors/vec3.d.ts.map +0 -1
package/dist/index.mjs ADDED
@@ -0,0 +1,2869 @@
1
+ // source/algebra/function.ts
2
+ var MathFunction = class {
3
+ };
4
+
5
+ // source/common/sign.ts
6
+ function sign_char(num) {
7
+ if (num == 0)
8
+ return void 0;
9
+ if (num < 0)
10
+ return "-";
11
+ if (num > 0)
12
+ return "+";
13
+ return void 0;
14
+ }
15
+
16
+ // source/common/types.ts
17
+ function check_number(obj) {
18
+ return obj != null && typeof obj == "number" && !isNaN(obj) && isFinite(obj);
19
+ }
20
+ function check_hex_digit(obj) {
21
+ if (!check_string(obj) || obj.length != 1)
22
+ return false;
23
+ switch (obj.toUpperCase()) {
24
+ default:
25
+ return false;
26
+ case "0":
27
+ case "1":
28
+ case "2":
29
+ case "3":
30
+ case "4":
31
+ case "5":
32
+ case "6":
33
+ case "7":
34
+ case "8":
35
+ case "9":
36
+ case "A":
37
+ case "B":
38
+ case "C":
39
+ case "D":
40
+ case "E":
41
+ case "F":
42
+ return true;
43
+ }
44
+ }
45
+ function get_hex_part(string) {
46
+ let offset = 0;
47
+ if (string.startsWith("#") || string.startsWith("$"))
48
+ offset = 1;
49
+ if (string.startsWith("0x"))
50
+ offset = 2;
51
+ return string.substring(offset);
52
+ }
53
+ function check_hex(obj) {
54
+ if (!check_string(obj))
55
+ return false;
56
+ const value = get_hex_part(obj).split("").map((char) => parseInt(char.toUpperCase(), 16));
57
+ return check_number_array(value);
58
+ }
59
+ function check_string(obj) {
60
+ return obj != null && typeof obj == "string" && obj.length > 0;
61
+ }
62
+ function check_array(obj, predicate, requiredLength) {
63
+ if (!Array.isArray(obj)) return false;
64
+ if (requiredLength && requiredLength != obj.length) return false;
65
+ for (const item of obj)
66
+ if (predicate && !predicate(item))
67
+ return false;
68
+ return true;
69
+ }
70
+ function check_number_array(obj, requiredLength) {
71
+ return check_array(obj, check_number, requiredLength);
72
+ }
73
+ function check_string_array(obj, requiredLength) {
74
+ return check_array(obj, check_string, requiredLength);
75
+ }
76
+ function has_property(obj, name, type) {
77
+ return obj != null && typeof obj == "object" && name in obj && typeof obj[name] == type;
78
+ }
79
+
80
+ // source/common/error.ts
81
+ var ResolveError = class extends Error {
82
+ constructor(target, value) {
83
+ super(`can't resolve ${value} to ${target}`);
84
+ this.target = target;
85
+ this.value = value;
86
+ }
87
+ };
88
+
89
+ // source/geometry/size.ts
90
+ var Size = class _Size {
91
+ width;
92
+ height;
93
+ get aspectRatio() {
94
+ return this.height / this.width;
95
+ }
96
+ get area() {
97
+ return this.width * this.height;
98
+ }
99
+ get perimeter() {
100
+ return this.width + this.width + this.height + this.height;
101
+ }
102
+ static resolve(a) {
103
+ const value = this.cast(a);
104
+ if (typeof value != "undefined")
105
+ return value;
106
+ throw new ResolveError("Square", a);
107
+ }
108
+ static cast(a) {
109
+ if (a == null || typeof a == "undefined")
110
+ return void 0;
111
+ if (check_number_array(a, 2))
112
+ return new this(a[0], a[1]);
113
+ if (has_property(a, "width", "number") && has_property(a, "height", "number"))
114
+ return new this(a.width, a.height);
115
+ if (check_string(a)) {
116
+ const parts = a.split("x").map((v) => parseFloat(v));
117
+ if (check_number_array(parts, 2))
118
+ return this.cast(parts);
119
+ }
120
+ if (check_number(a))
121
+ return new this(a, a);
122
+ return void 0;
123
+ }
124
+ static is(a) {
125
+ return typeof this.cast(a) != "undefined";
126
+ }
127
+ constructor(width, height) {
128
+ if (!check_number(width))
129
+ throw new TypeError("expected number for width");
130
+ if (!check_number(height))
131
+ throw new TypeError("expected number for height");
132
+ this.width = width;
133
+ this.height = height;
134
+ }
135
+ toArray() {
136
+ return [this.width, this.height];
137
+ }
138
+ toString() {
139
+ return `${this.width}x${this.height}`;
140
+ }
141
+ toJSON() {
142
+ return {
143
+ width: this.width,
144
+ height: this.height
145
+ };
146
+ }
147
+ clone() {
148
+ return new _Size(this.width, this.height);
149
+ }
150
+ equals(square) {
151
+ const s = _Size.resolve(square);
152
+ return this.width == s.width && this.height == s.height;
153
+ }
154
+ toVec2() {
155
+ return [this.width, this.height];
156
+ }
157
+ };
158
+
159
+ // source/utils.ts
160
+ function clamp(value, min, max) {
161
+ if (value <= min)
162
+ return min;
163
+ if (value >= max)
164
+ return max;
165
+ return value;
166
+ }
167
+ function log_hypot(a, b) {
168
+ const a_abs = Math.abs(a);
169
+ const b_abs = Math.abs(b);
170
+ if (a == 0)
171
+ return Math.log(b_abs);
172
+ if (b == 0)
173
+ return Math.log(a_abs);
174
+ if (a_abs < 3e3 && b_abs < 3e3)
175
+ return 0.5 * Math.log(a * a + b * b);
176
+ const _a = a / 2, _b = b / 2;
177
+ return 0.5 * Math.log(_a * _a + _b * _b) + Math.LN2;
178
+ }
179
+ var EPSILON = 1e-16;
180
+
181
+ // source/vectors/vec3.ts
182
+ var Vec3 = class _Vec3 {
183
+ x;
184
+ y;
185
+ z;
186
+ w;
187
+ static resolve(a) {
188
+ const value = this.cast(a);
189
+ if (typeof value != "undefined")
190
+ return value;
191
+ throw new ResolveError("Vec3", a);
192
+ }
193
+ static cast(a) {
194
+ if (a == null || typeof a == "undefined")
195
+ return void 0;
196
+ if (check_number_array(a, 3) || check_number_array(a, 4))
197
+ return new this(a[0], a[1], a[2], check_number(a[3]) ? a[3] : void 0);
198
+ if (has_property(a, "x", "number") && has_property(a, "y", "number") && has_property(a, "z", "number"))
199
+ return new this(a.x, a.y, a.z, has_property(a, "w", "number") ? a.w : void 0);
200
+ if (check_string(a)) {
201
+ const [sxyz, sw] = a.split(";");
202
+ if (check_string(sxyz)) {
203
+ const parts = sxyz.split(",");
204
+ if (check_string_array(parts, 3))
205
+ return new this(parseFloat(parts[0]), parseFloat(parts[1]), parseFloat(parts[2]), check_string(sw) ? parseFloat(sw) : void 0);
206
+ }
207
+ }
208
+ if (check_number(a))
209
+ return new this(a, a, a);
210
+ return void 0;
211
+ }
212
+ static resolveArgs(args) {
213
+ if (check_number_array(args, 3))
214
+ return new this(args[0], args[1], args[2]);
215
+ return this.resolve(args[0]);
216
+ }
217
+ static is(a) {
218
+ return typeof this.cast(a) != "undefined";
219
+ }
220
+ static fromPoints(a, b) {
221
+ const veca = this.resolve(a);
222
+ const vecb = this.resolve(b);
223
+ return new this(vecb.x - veca.x, vecb.y - veca.y, vecb.z - veca.z);
224
+ }
225
+ static clamp(value, min, max) {
226
+ const a = this.resolve(value), b = this.resolve(min), c = this.resolve(max);
227
+ return new this(
228
+ clamp(a.x, b.x, c.x),
229
+ clamp(a.y, b.y, c.y),
230
+ clamp(a.z, b.z, c.z)
231
+ );
232
+ }
233
+ static intersectPlane(planeP, planeN, lineStart, lineEnd, t) {
234
+ planeN = this.resolve(planeN).normalize();
235
+ const plane_d = -this.resolve(planeN).dot(planeP);
236
+ const ad = this.resolve(lineStart).dot(planeN);
237
+ const bd = this.resolve(lineEnd).dot(planeN);
238
+ t = (-plane_d - ad) / (bd - ad);
239
+ const lineStartToEnd = this.resolve(lineEnd).subtract(lineStart);
240
+ const linetoIntersect = lineStartToEnd.multiply(t);
241
+ return _Vec3.resolve(lineStart).add(linetoIntersect);
242
+ }
243
+ constructor(x = 0, y = 0, z = 0, w = 1) {
244
+ if (!check_number(x))
245
+ throw new TypeError("expected number for x");
246
+ if (!check_number(y))
247
+ throw new TypeError("expected number for y");
248
+ if (!check_number(z))
249
+ throw new TypeError("expected number for z");
250
+ if (!check_number(w))
251
+ throw new TypeError("expected number for w");
252
+ this.x = x;
253
+ this.y = y;
254
+ this.z = z;
255
+ this.w = w;
256
+ }
257
+ toArray(w = false) {
258
+ return w ? [this.x, this.y, this.z] : [this.x, this.y, this.z, this.w];
259
+ }
260
+ toJSON() {
261
+ return {
262
+ x: this.x,
263
+ y: this.y,
264
+ z: this.z,
265
+ w: this.w
266
+ };
267
+ }
268
+ toString(w = false) {
269
+ return w ? `${this.x},${this.y},${this.z}` : `${this.x},${this.y},${this.z};${this.w}`;
270
+ }
271
+ toVec2() {
272
+ return [this.x, this.y, this.w];
273
+ }
274
+ clone() {
275
+ return new _Vec3(this.x, this.y, this.z, this.w);
276
+ }
277
+ equals(vec) {
278
+ const a = _Vec3.resolve(vec);
279
+ return this.x == a.x && this.y == a.y && this.z == a.z;
280
+ }
281
+ setX(x) {
282
+ this.x = x;
283
+ return this;
284
+ }
285
+ setY(y) {
286
+ this.y = y;
287
+ return this;
288
+ }
289
+ setZ(z) {
290
+ this.z = z;
291
+ return this;
292
+ }
293
+ set(...args) {
294
+ const vec = _Vec3.resolveArgs(args);
295
+ return this.setX(vec.x).setY(vec.y).setZ(vec.z);
296
+ }
297
+ add(...args) {
298
+ const vec = _Vec3.resolveArgs(args);
299
+ return new _Vec3(
300
+ this.x + vec.x,
301
+ this.y + vec.y,
302
+ this.z + vec.z
303
+ );
304
+ }
305
+ offset(...args) {
306
+ const vec = _Vec3.resolveArgs(args);
307
+ this.x += vec.x;
308
+ this.y += vec.y;
309
+ this.z += vec.z;
310
+ return this;
311
+ }
312
+ subtract(...args) {
313
+ const vec = _Vec3.resolveArgs(args);
314
+ return new _Vec3(
315
+ this.x - vec.x,
316
+ this.y - vec.y,
317
+ this.z - vec.z
318
+ );
319
+ }
320
+ multiply(scalar) {
321
+ return new _Vec3(
322
+ this.x * scalar,
323
+ this.y * scalar,
324
+ this.z * scalar
325
+ );
326
+ }
327
+ naiveMultiply(...args) {
328
+ const vec = _Vec3.resolveArgs(args);
329
+ return new _Vec3(
330
+ this.x * vec.x,
331
+ this.y * vec.y,
332
+ this.z * vec.z
333
+ );
334
+ }
335
+ divide(...args) {
336
+ if (check_number_array(args, 1))
337
+ return new _Vec3(
338
+ this.x / args[0],
339
+ this.y / args[0],
340
+ this.z / args[0]
341
+ );
342
+ const vec = _Vec3.resolveArgs(args);
343
+ return new _Vec3(
344
+ this.x / vec.x,
345
+ this.y / vec.y,
346
+ this.z / vec.z
347
+ );
348
+ }
349
+ dot(...args) {
350
+ const vec = _Vec3.resolveArgs(args);
351
+ return this.x * vec.x + this.y * vec.y + this.z * vec.z;
352
+ }
353
+ cross(...args) {
354
+ const vec = _Vec3.resolveArgs(args);
355
+ return new _Vec3(
356
+ this.y * vec.z - this.z * vec.y,
357
+ this.z * vec.x - this.x * vec.z,
358
+ this.x * vec.y - this.y * vec.x
359
+ );
360
+ }
361
+ distance(...args) {
362
+ const vec = _Vec3.resolveArgs(args);
363
+ return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2);
364
+ }
365
+ distanceSquare(...args) {
366
+ const vec = _Vec3.resolveArgs(args);
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));
368
+ }
369
+ length() {
370
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
371
+ }
372
+ normalize() {
373
+ const length = this.length();
374
+ if (length == 0) return new _Vec3();
375
+ return new _Vec3(
376
+ this.x / length,
377
+ this.y / length,
378
+ this.z / length
379
+ );
380
+ }
381
+ invert() {
382
+ return this.multiply(-1);
383
+ }
384
+ round() {
385
+ return new _Vec3(Math.round(this.x), Math.round(this.y), Math.round(this.z), Math.round(this.w));
386
+ }
387
+ };
388
+
389
+ // source/vectors/vec2.ts
390
+ var Vec2 = class _Vec2 {
391
+ x;
392
+ y;
393
+ w;
394
+ static resolve(a) {
395
+ const value = this.cast(a);
396
+ if (typeof value != "undefined")
397
+ return value;
398
+ throw new ResolveError("Vec2", a);
399
+ }
400
+ static cast(a) {
401
+ if (a == null || typeof a == "undefined")
402
+ return void 0;
403
+ if (check_number_array(a, 2) || check_number_array(a, 3))
404
+ return new this(a[0], a[1], check_number(a[2]) ? a[2] : void 0);
405
+ if (has_property(a, "x", "number") && has_property(a, "y", "number"))
406
+ return new this(a.x, a.y, has_property(a, "w", "number") ? a.w : void 0);
407
+ if (check_string(a)) {
408
+ const [sxy, sw] = a.split(";");
409
+ if (check_string(sxy)) {
410
+ const parts = sxy.split(",");
411
+ if (check_string_array(parts, 2))
412
+ return new this(parseFloat(parts[0]), parseFloat(parts[1]), check_string(sw) ? parseFloat(sw) : void 0);
413
+ }
414
+ }
415
+ if (check_number(a))
416
+ return new this(a, a);
417
+ return void 0;
418
+ }
419
+ static resolveArgs(args) {
420
+ if (check_number_array(args, 2))
421
+ return new this(args[0], args[1]);
422
+ return this.resolve(args[0]);
423
+ }
424
+ static is(a) {
425
+ return typeof this.cast(a) != "undefined";
426
+ }
427
+ static fromPoints(a, b) {
428
+ const veca = this.resolve(a);
429
+ const vecb = this.resolve(b);
430
+ return new this(vecb.x - veca.x, vecb.y - veca.y);
431
+ }
432
+ static clamp(value, min, max) {
433
+ const a = this.resolve(value), b = this.resolve(min), c = this.resolve(max);
434
+ return new this(
435
+ clamp(a.x, b.x, c.x),
436
+ clamp(a.y, b.y, c.y)
437
+ );
438
+ }
439
+ constructor(x = 0, y = 0, w = 1) {
440
+ if (!check_number(x))
441
+ throw new TypeError("expected number for x");
442
+ if (!check_number(y))
443
+ throw new TypeError("expected number for y");
444
+ if (!check_number(w))
445
+ throw new TypeError("expected number for w");
446
+ this.x = x;
447
+ this.y = y;
448
+ this.w = w;
449
+ }
450
+ toArray(w = false) {
451
+ return w ? [this.x, this.y] : [this.x, this.y, this.w];
452
+ }
453
+ toJSON() {
454
+ return {
455
+ x: this.x,
456
+ y: this.y,
457
+ w: this.w
458
+ };
459
+ }
460
+ toString(w = false) {
461
+ return w ? `${this.x},${this.y}` : `${this.x},${this.y};${this.w}`;
462
+ }
463
+ toSquare() {
464
+ return new Size(this.x, this.y);
465
+ }
466
+ toVec3(z) {
467
+ return new Vec3(this.x, this.y, z, this.w);
468
+ }
469
+ clone() {
470
+ return new _Vec2(this.x, this.y, this.w);
471
+ }
472
+ equals(vec) {
473
+ const a = _Vec2.resolve(vec);
474
+ return this.x == a.x && this.y == a.y;
475
+ }
476
+ setX(x) {
477
+ this.x = x;
478
+ return this;
479
+ }
480
+ setY(y) {
481
+ this.y = y;
482
+ return this;
483
+ }
484
+ setW(w) {
485
+ this.w = w;
486
+ return this;
487
+ }
488
+ set(...args) {
489
+ const vec = _Vec2.resolveArgs(args);
490
+ return this.setX(vec.x).setY(vec.y);
491
+ }
492
+ add(...args) {
493
+ const vec = _Vec2.resolveArgs(args);
494
+ return new _Vec2(
495
+ this.x + vec.x,
496
+ this.y + vec.y
497
+ );
498
+ }
499
+ offset(...args) {
500
+ const vec = _Vec2.resolveArgs(args);
501
+ this.x += vec.x;
502
+ this.y += vec.y;
503
+ return this;
504
+ }
505
+ subtract(...args) {
506
+ const vec = _Vec2.resolveArgs(args);
507
+ return new _Vec2(
508
+ this.x - vec.x,
509
+ this.y - vec.y
510
+ );
511
+ }
512
+ multiply(scalar) {
513
+ return new _Vec2(
514
+ this.x * scalar,
515
+ this.y * scalar
516
+ );
517
+ }
518
+ naiveMultiply(...args) {
519
+ const vec = _Vec2.resolveArgs(args);
520
+ return new _Vec2(
521
+ this.x * vec.x,
522
+ this.y * vec.y
523
+ );
524
+ }
525
+ divide(...args) {
526
+ if (check_number_array(args, 1))
527
+ return new _Vec2(
528
+ this.x / args[0],
529
+ this.y / args[0]
530
+ );
531
+ const vec = _Vec2.resolveArgs(args);
532
+ return new _Vec2(
533
+ this.x / vec.x,
534
+ this.y / vec.y
535
+ );
536
+ }
537
+ dot(...args) {
538
+ const vec = _Vec2.resolveArgs(args);
539
+ return this.x * vec.x + this.y * vec.y;
540
+ }
541
+ distance(...args) {
542
+ const vec = _Vec2.resolveArgs(args);
543
+ return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2);
544
+ }
545
+ distanceSquare(...args) {
546
+ const vec = _Vec2.resolveArgs(args);
547
+ return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2));
548
+ }
549
+ length() {
550
+ return Math.sqrt(this.x * this.x + this.y * this.y);
551
+ }
552
+ cartesianify() {
553
+ return new _Vec2(
554
+ this.x * Math.cos(this.y),
555
+ this.x * Math.sin(this.y)
556
+ );
557
+ }
558
+ polarify() {
559
+ return new _Vec2(
560
+ Math.sqrt(this.x * this.x + this.y * this.y),
561
+ Math.atan(this.y / this.x)
562
+ );
563
+ }
564
+ normalize() {
565
+ const length = this.length();
566
+ if (length == 0) return new _Vec2();
567
+ return new _Vec2(
568
+ this.x / length,
569
+ this.y / length
570
+ );
571
+ }
572
+ invert() {
573
+ return this.multiply(-1);
574
+ }
575
+ round() {
576
+ return new _Vec2(Math.round(this.x), Math.round(this.y), Math.round(this.w));
577
+ }
578
+ };
579
+
580
+ // source/algebra/linear.ts
581
+ var LinearFunction = class extends MathFunction {
582
+ /**
583
+ * The factor of the linear function
584
+ */
585
+ m;
586
+ /**
587
+ * The height of the linear function
588
+ */
589
+ b;
590
+ /**
591
+ * Create a linear function from two points
592
+ * @param a A point
593
+ * @param b A point
594
+ * @returns A linear function from two points
595
+ */
596
+ static fromPoints(a, b) {
597
+ const veca = Vec2.resolve(a);
598
+ const vecb = Vec2.resolve(b);
599
+ const m = (vecb.y - veca.y) / (vecb.x - veca.x);
600
+ const h = -m * veca.x + veca.y;
601
+ return new this(m, h);
602
+ }
603
+ /**
604
+ * Create a linear function with a factor and height
605
+ * @param m The factor
606
+ * @param b The height
607
+ */
608
+ constructor(m, b) {
609
+ super();
610
+ if (!check_number(m))
611
+ throw new TypeError("expected number for m");
612
+ if (!check_number(b))
613
+ throw new TypeError("expected number for b");
614
+ this.m = m;
615
+ this.b = b;
616
+ }
617
+ get(x) {
618
+ if (!check_number(x))
619
+ throw new TypeError("expected number for x");
620
+ return this.m;
621
+ }
622
+ roots() {
623
+ const x = -this.b / this.m;
624
+ if (!isNaN(x))
625
+ return [new Vec2(x)];
626
+ return [];
627
+ }
628
+ toString() {
629
+ const bsign = sign_char(this.b);
630
+ if (bsign)
631
+ return `f(x) = ${this.m} * x ${bsign} ${Math.abs(this.b)}`;
632
+ return `f(x) = ${this.m} * x`;
633
+ }
634
+ };
635
+
636
+ // source/algebra/quad.ts
637
+ var QuadFunction = class extends MathFunction {
638
+ a;
639
+ b;
640
+ c;
641
+ static get(a, b, c, x) {
642
+ return new this(a, b, c).get(x);
643
+ }
644
+ constructor(a, b, c) {
645
+ super();
646
+ if (!check_number(a))
647
+ throw new TypeError("expected number for a");
648
+ if (a == 0)
649
+ throw new TypeError("a cannot be 0");
650
+ if (!check_number(b))
651
+ throw new TypeError("expected number for b");
652
+ if (!check_number(c))
653
+ throw new TypeError("expected number for c");
654
+ this.a = a;
655
+ this.b = b;
656
+ this.c = c;
657
+ }
658
+ get(x) {
659
+ if (!check_number(x))
660
+ throw new TypeError("expected number for x");
661
+ return this.a * x * x + this.b * x + this.c;
662
+ }
663
+ roots() {
664
+ const roots = new Array();
665
+ const discriminant = this.b * this.b - 4 * this.a * this.c;
666
+ const n0 = (-this.b + Math.sqrt(discriminant)) / (2 * this.a);
667
+ const n1 = (-this.b + Math.sqrt(discriminant)) / (2 * this.a);
668
+ if (!isNaN(n0))
669
+ roots.push(new Vec2(n0));
670
+ if (!isNaN(n1) && n0 != n1)
671
+ roots.push(new Vec2(n1));
672
+ return roots;
673
+ }
674
+ toString(type = "standard") {
675
+ switch (type) {
676
+ default:
677
+ case "standard": {
678
+ const bsign = sign_char(this.b);
679
+ const csign = sign_char(this.c);
680
+ if (bsign && csign)
681
+ return `f(x) = ${this.a}x^2 ${bsign} ${Math.abs(this.b)}x ${csign} ${Math.abs(this.c)}`;
682
+ if (bsign)
683
+ return `f(x) = ${this.a}x^2 ${bsign} ${Math.abs(this.b)}x`;
684
+ return `f(x) = ${this.a}x^2`;
685
+ }
686
+ }
687
+ }
688
+ };
689
+
690
+ // source/common/string.ts
691
+ function stringify(value) {
692
+ return value != null && typeof value == "object" && "toString" in value && typeof value.toString == "function" ? value.toString() : String(value);
693
+ }
694
+
695
+ // source/crypto/hash.ts
696
+ var DJB2_OFFSET = 5381n;
697
+ function djb2(value) {
698
+ const string = stringify(value);
699
+ let hash = DJB2_OFFSET;
700
+ for (let i = 0; i < string.length; i++) {
701
+ hash = (hash << 5n) + hash + BigInt(string.charCodeAt(i));
702
+ }
703
+ return hash;
704
+ }
705
+ var FNV1_OFFSET = 14695981039346656037n;
706
+ var FNV1_PRIME = 1099511628211n;
707
+ function fnv1(value) {
708
+ const string = stringify(value);
709
+ let hash = FNV1_OFFSET;
710
+ for (let i = 0; i < string.length; i++) {
711
+ hash *= FNV1_PRIME;
712
+ hash ^= BigInt(string.charCodeAt(i));
713
+ }
714
+ return hash;
715
+ }
716
+ function sdbm(value) {
717
+ const string = stringify(value);
718
+ let hash = 0n;
719
+ for (let i = 0; i < string.length; i++) {
720
+ hash = BigInt(string.charCodeAt(i)) + (hash << 6n) + (hash << 16n) - hash;
721
+ }
722
+ return hash;
723
+ }
724
+
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);
1042
+
1043
+ // source/geometry/circle.ts
1044
+ var Circle = class _Circle {
1045
+ radius;
1046
+ get perimeter() {
1047
+ return this.radius * Math.PI * 2;
1048
+ }
1049
+ get area() {
1050
+ return Math.PI * Math.pow(this.radius, 2);
1051
+ }
1052
+ position;
1053
+ get x() {
1054
+ return this.position.x;
1055
+ }
1056
+ set x(val) {
1057
+ this.position.x = val;
1058
+ }
1059
+ get y() {
1060
+ return this.position.y;
1061
+ }
1062
+ set y(val) {
1063
+ this.position.y = val;
1064
+ }
1065
+ get w() {
1066
+ return this.position.w;
1067
+ }
1068
+ set w(val) {
1069
+ this.position.w = val;
1070
+ }
1071
+ static resolve(a) {
1072
+ const value = this.cast(a);
1073
+ if (typeof value != "undefined")
1074
+ return value;
1075
+ throw new ResolveError("Circle", a);
1076
+ }
1077
+ static cast(a) {
1078
+ if (a == null || typeof a == "undefined")
1079
+ return void 0;
1080
+ if (check_number_array(a, 3))
1081
+ return new this([a[0], a[1]], a[2]);
1082
+ if (check_number_array(a, 4)) {
1083
+ const c = new this([a[0], a[1]], a[3]);
1084
+ c.w = a[2];
1085
+ return c;
1086
+ }
1087
+ if (has_property(a, "x", "number") && has_property(a, "y", "number") && has_property(a, "radius", "number"))
1088
+ return new this(has_property(a, "w", "number") ? [a.x, a.y, a.w] : [a.x, a.y], a.radius);
1089
+ if (check_string(a)) {
1090
+ const [spos, sradius] = a.split("|");
1091
+ const pos = Vec2.cast(spos);
1092
+ if (typeof pos == "undefined")
1093
+ return void 0;
1094
+ const radius = parseFloat(sradius);
1095
+ if (!isNaN(radius))
1096
+ return new this(pos, radius);
1097
+ }
1098
+ return void 0;
1099
+ }
1100
+ static is(a) {
1101
+ return typeof this.cast(a) != "undefined";
1102
+ }
1103
+ constructor(position, radius) {
1104
+ this.position = Vec2.resolve(position);
1105
+ if (!check_number(radius))
1106
+ throw new TypeError("expected number for radius");
1107
+ this.radius = radius;
1108
+ }
1109
+ toArray() {
1110
+ return [...this.position.toArray(), this.radius];
1111
+ }
1112
+ toJSON() {
1113
+ return {
1114
+ ...this.position.toJSON(),
1115
+ radius: this.radius
1116
+ };
1117
+ }
1118
+ toString() {
1119
+ return `${this.position.toString()}|${this.radius}`;
1120
+ }
1121
+ clone() {
1122
+ return new _Circle(this.position.clone(), this.radius);
1123
+ }
1124
+ equals(circle) {
1125
+ const c = _Circle.resolve(circle);
1126
+ return c.position.equals(c.position) && this.radius == c.radius;
1127
+ }
1128
+ inside(a) {
1129
+ const circle = _Circle.resolve(a);
1130
+ const distX = circle.x - this.x;
1131
+ const distY = circle.y - this.y;
1132
+ const dist = Math.sqrt(distX * distX + (distY + distY));
1133
+ return dist <= this.radius + circle.radius;
1134
+ }
1135
+ insidePoint(a) {
1136
+ return this.position.distance(a) <= this.radius;
1137
+ }
1138
+ };
1139
+
1140
+ // source/geometry/rectangle.ts
1141
+ var Rectangle = class _Rectangle {
1142
+ position;
1143
+ size;
1144
+ get area() {
1145
+ return this.width * this.height;
1146
+ }
1147
+ get perimeter() {
1148
+ return this.width + this.width + this.height + this.height;
1149
+ }
1150
+ get x() {
1151
+ return this.position.x;
1152
+ }
1153
+ set x(val) {
1154
+ this.position.x = val;
1155
+ }
1156
+ get y() {
1157
+ return this.position.y;
1158
+ }
1159
+ set y(val) {
1160
+ this.position.y = val;
1161
+ }
1162
+ get w() {
1163
+ return this.position.w;
1164
+ }
1165
+ set w(val) {
1166
+ this.position.w = val;
1167
+ }
1168
+ get width() {
1169
+ return this.size.width;
1170
+ }
1171
+ set width(val) {
1172
+ this.size.width = val;
1173
+ }
1174
+ get height() {
1175
+ return this.size.height;
1176
+ }
1177
+ set height(val) {
1178
+ this.size.height = val;
1179
+ }
1180
+ static resolve(a) {
1181
+ const value = this.cast(a);
1182
+ if (typeof value != "undefined")
1183
+ return value;
1184
+ throw new ResolveError("Rectangle", a);
1185
+ }
1186
+ static cast(a) {
1187
+ if (a == null || typeof a == "undefined")
1188
+ return void 0;
1189
+ if (check_number_array(a, 4))
1190
+ return new this(a[0], a[1], a[2], a[3]);
1191
+ if (check_number_array(a, 5)) {
1192
+ const rect = new this(a[0], a[1], a[3], a[4]);
1193
+ rect.w = a[2];
1194
+ return rect;
1195
+ }
1196
+ if (check_string(a)) {
1197
+ const [spos, ssize] = a.split("|");
1198
+ const pos = Vec2.cast(spos);
1199
+ const size = Size.cast(ssize);
1200
+ if (typeof pos == "undefined" || typeof size == "undefined")
1201
+ return void 0;
1202
+ const rect = new this(pos.x, pos.y, size.width, size.height);
1203
+ rect.w = pos.w;
1204
+ return rect;
1205
+ }
1206
+ if (has_property(a, "x", "number") && has_property(a, "y", "number") && has_property(a, "width", "number") && has_property(a, "height", "number")) {
1207
+ const rect = new this(a.x, a.y, a.width, a.height);
1208
+ if (has_property(a, "w", "number"))
1209
+ rect.w = a.w;
1210
+ return rect;
1211
+ }
1212
+ return void 0;
1213
+ }
1214
+ static is(a) {
1215
+ return typeof this.cast(a) != "undefined";
1216
+ }
1217
+ constructor(a, b, c, d) {
1218
+ const vec = Vec2.is(a) ? Vec2.resolve(a) : void 0;
1219
+ const size = Size.is(b) ? Size.resolve(b) : void 0;
1220
+ const x = typeof a == "number" ? a : vec?.x;
1221
+ if (!check_number(x))
1222
+ throw new TypeError("expected number for x position");
1223
+ const y = typeof b == "number" ? b : vec?.y;
1224
+ if (!check_number(y))
1225
+ throw new TypeError("expected number for y position");
1226
+ const width = typeof c == "number" ? c : size?.width;
1227
+ if (!check_number(width))
1228
+ throw new TypeError("expected number for width");
1229
+ const height = typeof d == "number" ? d : size?.height;
1230
+ if (!check_number(height))
1231
+ throw new TypeError("expected number for height");
1232
+ this.position = new Vec2(x, y);
1233
+ this.size = new Size(width, height);
1234
+ }
1235
+ toArray(w = false) {
1236
+ return [...this.position.toArray(w), ...this.size.toArray()];
1237
+ }
1238
+ toString(w = false) {
1239
+ return `${this.position.toString(w)}|${this.size.toString()}`;
1240
+ }
1241
+ toJSON() {
1242
+ return { ...this.position.toJSON(), ...this.size.toJSON() };
1243
+ }
1244
+ toBoundingBox() {
1245
+ return [this.x, this.x + this.width, this.y, this.y + this.height];
1246
+ }
1247
+ clone() {
1248
+ return new _Rectangle(this.position.clone(), this.size.clone());
1249
+ }
1250
+ equals(rectangle) {
1251
+ const rect = _Rectangle.resolve(rectangle);
1252
+ return this.position.equals(rect.position) && this.size.equals(rect.size);
1253
+ }
1254
+ };
1255
+
1256
+ // source/geometry/bbox.ts
1257
+ var BoundingBox = class _BoundingBox {
1258
+ left;
1259
+ right;
1260
+ top;
1261
+ bottom;
1262
+ get width() {
1263
+ return this.right - this.left;
1264
+ }
1265
+ set width(val) {
1266
+ this.right = this.left + val;
1267
+ }
1268
+ get height() {
1269
+ return this.bottom - this.top;
1270
+ }
1271
+ set height(val) {
1272
+ this.bottom = this.top + val;
1273
+ }
1274
+ static resolve(a) {
1275
+ const value = this.cast(a);
1276
+ if (typeof value != "undefined")
1277
+ return value;
1278
+ throw new ResolveError("BoundingBox", a);
1279
+ }
1280
+ static cast(a) {
1281
+ if (a == null || typeof a == "undefined")
1282
+ return void 0;
1283
+ if (check_number_array(a, 4))
1284
+ return new this(a[0], a[1], a[2], a[3]);
1285
+ if (has_property(a, "left", "number") && has_property(a, "right", "number") && has_property(a, "top", "number") && has_property(a, "bottom", "number"))
1286
+ return new this(a.left, a.right, a.top, a.bottom);
1287
+ if (check_string(a)) {
1288
+ const parts = a.split(",");
1289
+ if (check_string_array(parts, 4))
1290
+ return this.cast(parts.map((v) => parseFloat(v)));
1291
+ }
1292
+ return void 0;
1293
+ }
1294
+ static is(a) {
1295
+ return typeof this.cast(a) != "undefined";
1296
+ }
1297
+ constructor(left, right, top, bottom) {
1298
+ if (!check_number(left))
1299
+ throw new TypeError("expected number for left");
1300
+ if (!check_number(right))
1301
+ throw new TypeError("expected number for right");
1302
+ if (!check_number(top))
1303
+ throw new TypeError("expected number for top");
1304
+ if (!check_number(bottom))
1305
+ throw new TypeError("expected number for bottom");
1306
+ this.left = left;
1307
+ this.right = right;
1308
+ this.top = top;
1309
+ this.bottom = bottom;
1310
+ }
1311
+ toArray() {
1312
+ return [this.left, this.right, this.top, this.bottom];
1313
+ }
1314
+ toString() {
1315
+ return `${this.left},${this.right},${this.top},${this.bottom}`;
1316
+ }
1317
+ toJSON() {
1318
+ return {
1319
+ left: this.left,
1320
+ top: this.top,
1321
+ right: this.right,
1322
+ bottom: this.bottom
1323
+ };
1324
+ }
1325
+ clone() {
1326
+ return new _BoundingBox(this.left, this.right, this.top, this.bottom);
1327
+ }
1328
+ equals(bbox) {
1329
+ const b = _BoundingBox.resolve(bbox);
1330
+ return this.left == b.left && this.right == b.right && this.top == b.top && this.bottom == b.bottom;
1331
+ }
1332
+ toSquare() {
1333
+ return new Size(this.width, this.height);
1334
+ }
1335
+ toRectangle() {
1336
+ return new Rectangle(this.left, this.top, this.width, this.height);
1337
+ }
1338
+ inside(a) {
1339
+ const bbox = _BoundingBox.resolve(a);
1340
+ return this.right >= bbox.left && bbox.right >= this.left && this.bottom >= bbox.top && bbox.bottom >= this.top;
1341
+ }
1342
+ insidePoint(a) {
1343
+ const point = Vec2.resolve(a);
1344
+ return this.left <= point.x && this.right >= point.x && this.top <= point.y && this.bottom >= point.y;
1345
+ }
1346
+ insideCircle(a) {
1347
+ const circle = Circle.resolve(a);
1348
+ const center = Vec2.resolve(circle).add(circle.radius);
1349
+ const bboxhe = new Vec2(this.width / 2, this.height / 2);
1350
+ const bboxcenter = new Vec2(this.left + bboxhe.x, this.top + bboxhe.y);
1351
+ let diff = center.subtract(bboxcenter);
1352
+ const clamped = Vec2.clamp(diff, bboxhe.invert(), bboxhe);
1353
+ const closest = bboxcenter.add(clamped);
1354
+ diff = closest.subtract(center);
1355
+ return diff.length() < circle.radius;
1356
+ }
1357
+ };
1358
+
1359
+ // source/geometry/triangle.ts
1360
+ var ATriangle = class {
1361
+ constructor(A, B, C) {
1362
+ this.A = A;
1363
+ this.B = B;
1364
+ this.C = C;
1365
+ }
1366
+ get alpha() {
1367
+ return Math.acos((this.b * this.b + this.c * this.c - this.a * this.a) / (2 * this.b * this.c));
1368
+ }
1369
+ get beta() {
1370
+ return Math.acos((this.c * this.c + this.a * this.a - this.b * this.b) / (2 * this.c * this.a));
1371
+ }
1372
+ get gamma() {
1373
+ return Math.acos((this.a * this.a + this.b * this.b - this.c * this.c) / (2 * this.a * this.b));
1374
+ }
1375
+ get perimeter() {
1376
+ return this.a + this.b + this.c;
1377
+ }
1378
+ get semiperimeter() {
1379
+ return this.perimeter / 2;
1380
+ }
1381
+ get area() {
1382
+ return Math.sqrt(this.semiperimeter * (this.semiperimeter - this.a) * (this.semiperimeter - this.b) * (this.semiperimeter - this.c));
1383
+ }
1384
+ get base() {
1385
+ return 2 * (this.area / (this.a * Math.sin(this.gamma)));
1386
+ }
1387
+ get height() {
1388
+ return 2 * (this.area / this.base);
1389
+ }
1390
+ };
1391
+ var Triangle2D = class extends ATriangle {
1392
+ get a() {
1393
+ return Vec2.fromPoints(this.B, this.C).length();
1394
+ }
1395
+ get b() {
1396
+ return Vec2.fromPoints(this.A, this.C).length();
1397
+ }
1398
+ get c() {
1399
+ return Vec2.fromPoints(this.A, this.B).length();
1400
+ }
1401
+ };
1402
+ var Triangle3D = class extends ATriangle {
1403
+ get a() {
1404
+ return Vec3.fromPoints(this.B, this.C).length();
1405
+ }
1406
+ get b() {
1407
+ return Vec3.fromPoints(this.A, this.C).length();
1408
+ }
1409
+ get c() {
1410
+ return Vec3.fromPoints(this.A, this.B).length();
1411
+ }
1412
+ };
1413
+
1414
+ // source/matrices/mat3.ts
1415
+ var Mat3 = class _Mat3 {
1416
+ _raw;
1417
+ get m00() {
1418
+ return this._raw[0];
1419
+ }
1420
+ set m00(val) {
1421
+ this._raw[0] = val;
1422
+ }
1423
+ get m01() {
1424
+ return this._raw[1];
1425
+ }
1426
+ set m01(val) {
1427
+ this._raw[1] = val;
1428
+ }
1429
+ get m02() {
1430
+ return this._raw[2];
1431
+ }
1432
+ set m02(val) {
1433
+ this._raw[2] = val;
1434
+ }
1435
+ get m10() {
1436
+ return this._raw[3];
1437
+ }
1438
+ set m10(val) {
1439
+ this._raw[3] = val;
1440
+ }
1441
+ get m11() {
1442
+ return this._raw[4];
1443
+ }
1444
+ set m11(val) {
1445
+ this._raw[4] = val;
1446
+ }
1447
+ get m12() {
1448
+ return this._raw[5];
1449
+ }
1450
+ set m12(val) {
1451
+ this._raw[5] = val;
1452
+ }
1453
+ get m20() {
1454
+ return this._raw[6];
1455
+ }
1456
+ set m20(val) {
1457
+ this._raw[6] = val;
1458
+ }
1459
+ get m21() {
1460
+ return this._raw[7];
1461
+ }
1462
+ set m21(val) {
1463
+ this._raw[7] = val;
1464
+ }
1465
+ get m22() {
1466
+ return this._raw[8];
1467
+ }
1468
+ set m22(val) {
1469
+ this._raw[8] = val;
1470
+ }
1471
+ static resolve(a) {
1472
+ const value = this.cast(a);
1473
+ if (typeof value != "undefined")
1474
+ return value;
1475
+ throw new ResolveError("Mat3", a);
1476
+ }
1477
+ static cast(a) {
1478
+ if (a == null || typeof a == "undefined")
1479
+ return void 0;
1480
+ if (check_number_array(a, 9)) {
1481
+ return new this(a);
1482
+ }
1483
+ if (check_array(a, void 0, 3)) {
1484
+ const row0 = a[0], row1 = a[1], row2 = a[2];
1485
+ if (check_number_array(row0, 3) && check_number_array(row1, 3) && check_number_array(row2, 3))
1486
+ return new this([
1487
+ row0[0],
1488
+ row0[1],
1489
+ row0[2],
1490
+ row1[0],
1491
+ row1[1],
1492
+ row1[2],
1493
+ row2[0],
1494
+ row2[1],
1495
+ row2[2]
1496
+ ]);
1497
+ }
1498
+ if (check_string(a)) {
1499
+ const parts = a.split(",");
1500
+ if (check_string_array(parts, 9))
1501
+ return this.cast(parts.map((i) => parseFloat(i)));
1502
+ }
1503
+ if (has_property(a, "m00", "number") && has_property(a, "m01", "number") && has_property(a, "m02", "number") && has_property(a, "m10", "number") && has_property(a, "m11", "number") && has_property(a, "m12", "number") && has_property(a, "m20", "number") && has_property(a, "m21", "number") && has_property(a, "m22", "number"))
1504
+ return new this([
1505
+ a.m00,
1506
+ a.m01,
1507
+ a.m02,
1508
+ a.m10,
1509
+ a.m11,
1510
+ a.m12,
1511
+ a.m20,
1512
+ a.m21,
1513
+ a.m22
1514
+ ]);
1515
+ if (check_number(a)) {
1516
+ return new this([a, a, a, a, a, a, a, a, a]);
1517
+ }
1518
+ return void 0;
1519
+ }
1520
+ static is(a) {
1521
+ return typeof this.cast(a) != "undefined";
1522
+ }
1523
+ static projection(width, height) {
1524
+ return new this([
1525
+ 2 / width,
1526
+ 0,
1527
+ 0,
1528
+ 0,
1529
+ -2 / height,
1530
+ 0,
1531
+ -1,
1532
+ 1,
1533
+ 1
1534
+ ]);
1535
+ }
1536
+ constructor(init = [1, 0, 0, 0, 1, 0, 0, 0, 1]) {
1537
+ if (!check_number_array(init, 9))
1538
+ throw new TypeError("expected a number array with 9 elements");
1539
+ this._raw = init;
1540
+ }
1541
+ toArray() {
1542
+ return [
1543
+ this.m00,
1544
+ this.m01,
1545
+ this.m02,
1546
+ this.m10,
1547
+ this.m11,
1548
+ this.m12,
1549
+ this.m20,
1550
+ this.m21,
1551
+ this.m22
1552
+ ];
1553
+ }
1554
+ toNestetArray() {
1555
+ return [
1556
+ [this.m00, this.m01, this.m02],
1557
+ [this.m10, this.m11, this.m12],
1558
+ [this.m20, this.m21, this.m22]
1559
+ ];
1560
+ }
1561
+ toJSON() {
1562
+ return {
1563
+ m00: this.m00,
1564
+ m01: this.m01,
1565
+ m02: this.m02,
1566
+ m10: this.m10,
1567
+ m11: this.m11,
1568
+ m12: this.m12,
1569
+ m20: this.m20,
1570
+ m21: this.m21,
1571
+ m22: this.m22
1572
+ };
1573
+ }
1574
+ toString() {
1575
+ return `${this.m00},${this.m01},${this.m02},${this.m10},${this.m11},${this.m12},${this.m20},${this.m21},${this.m22}`;
1576
+ }
1577
+ clone() {
1578
+ return new _Mat3([
1579
+ this.m00,
1580
+ this.m01,
1581
+ this.m02,
1582
+ this.m10,
1583
+ this.m11,
1584
+ this.m12,
1585
+ this.m20,
1586
+ this.m21,
1587
+ this.m22
1588
+ ]);
1589
+ }
1590
+ equals(mat) {
1591
+ const m = _Mat3.resolve(mat);
1592
+ for (let index = 0; index < this._raw.length; index++)
1593
+ if (this._raw[index] != m._raw[index])
1594
+ return false;
1595
+ return true;
1596
+ }
1597
+ add(mat) {
1598
+ const b = _Mat3.resolve(mat);
1599
+ const m = new _Mat3();
1600
+ for (let index = 0; index < this._raw.length; index++)
1601
+ m._raw[index] = this._raw[index] + b._raw[index];
1602
+ return m;
1603
+ }
1604
+ subtract(mat) {
1605
+ const b = _Mat3.resolve(mat);
1606
+ const m = new _Mat3();
1607
+ for (let index = 0; index < this._raw.length; index++)
1608
+ m._raw[index] = this._raw[index] - b._raw[index];
1609
+ return m;
1610
+ }
1611
+ multiply(a) {
1612
+ if (check_number(a))
1613
+ return new _Mat3([
1614
+ this.m00 * a,
1615
+ this.m01 * a,
1616
+ this.m02 * a,
1617
+ this.m10 * a,
1618
+ this.m11 * a,
1619
+ this.m12 * a,
1620
+ this.m20 * a,
1621
+ this.m21 * a,
1622
+ this.m22 * a
1623
+ ]);
1624
+ const b = _Mat3.resolve(a);
1625
+ return new _Mat3([
1626
+ b.m00 * this.m00 + b.m01 * this.m10 + b.m02 * this.m20,
1627
+ b.m00 * this.m01 + b.m01 * this.m11 + b.m02 * this.m21,
1628
+ b.m00 * this.m02 + b.m01 * this.m12 + b.m02 * this.m22,
1629
+ b.m10 * this.m00 + b.m11 * this.m10 + b.m12 * this.m20,
1630
+ b.m10 * this.m01 + b.m11 * this.m11 + b.m12 * this.m21,
1631
+ b.m10 * this.m02 + b.m11 * this.m12 + b.m12 * this.m22,
1632
+ b.m20 * this.m00 + b.m21 * this.m10 + b.m22 * this.m20,
1633
+ b.m20 * this.m01 + b.m21 * this.m11 + b.m22 * this.m21,
1634
+ b.m20 * this.m02 + b.m21 * this.m12 + b.m22 * this.m22
1635
+ ]);
1636
+ }
1637
+ translate(...args) {
1638
+ const vec = Vec2.resolveArgs(args);
1639
+ return this.multiply([
1640
+ 1,
1641
+ 0,
1642
+ 0,
1643
+ 0,
1644
+ 1,
1645
+ 0,
1646
+ vec.x,
1647
+ vec.y,
1648
+ 1
1649
+ ]);
1650
+ }
1651
+ rotate(angle) {
1652
+ const c = Math.cos(angle);
1653
+ const s = Math.sin(angle);
1654
+ return this.multiply([
1655
+ c,
1656
+ -s,
1657
+ 0,
1658
+ s,
1659
+ c,
1660
+ 0,
1661
+ 0,
1662
+ 0,
1663
+ 1
1664
+ ]);
1665
+ }
1666
+ scale(...args) {
1667
+ const vec = Vec2.resolve(args);
1668
+ return this.multiply([
1669
+ vec.x,
1670
+ 0,
1671
+ 0,
1672
+ 0,
1673
+ vec.y,
1674
+ 0,
1675
+ 0,
1676
+ 0,
1677
+ 1
1678
+ ]);
1679
+ }
1680
+ determinant() {
1681
+ return this.m00 * this.m11 * this.m22 - this.m21 * this.m12 - this.m01 * this.m10 * this.m22 - this.m12 * this.m20 + this.m02 * this.m10 * this.m21 - this.m11 * this.m20;
1682
+ }
1683
+ inverse() {
1684
+ const det = this.determinant();
1685
+ return new _Mat3([
1686
+ (this.m11 * this.m22 - this.m21 * this.m12) * det,
1687
+ (this.m02 * this.m21 - this.m01 * this.m22) * det,
1688
+ (this.m01 * this.m12 - this.m02 * this.m11) * det,
1689
+ (this.m12 * this.m20 - this.m10 * this.m22) * det,
1690
+ (this.m00 * this.m22 - this.m02 * this.m20) * det,
1691
+ (this.m10 * this.m02 - this.m00 * this.m12) * det,
1692
+ (this.m10 * this.m21 - this.m20 * this.m11) * det,
1693
+ (this.m20 * this.m01 - this.m00 * this.m21) * det,
1694
+ (this.m00 * this.m11 - this.m10 * this.m01) * det
1695
+ ]);
1696
+ }
1697
+ toMat4() {
1698
+ return [
1699
+ this.m00,
1700
+ this.m01,
1701
+ this.m02,
1702
+ 0,
1703
+ this.m10,
1704
+ this.m11,
1705
+ this.m12,
1706
+ 0,
1707
+ this.m20,
1708
+ this.m20,
1709
+ this.m22,
1710
+ 0,
1711
+ 0,
1712
+ 0,
1713
+ 0,
1714
+ 1
1715
+ ];
1716
+ }
1717
+ };
1718
+
1719
+ // source/matrices/mat4.ts
1720
+ var Mat4 = class _Mat4 {
1721
+ _raw;
1722
+ get m00() {
1723
+ return this._raw[0];
1724
+ }
1725
+ set m00(val) {
1726
+ this._raw[0] = val;
1727
+ }
1728
+ get m01() {
1729
+ return this._raw[1];
1730
+ }
1731
+ set m01(val) {
1732
+ this._raw[1] = val;
1733
+ }
1734
+ get m02() {
1735
+ return this._raw[2];
1736
+ }
1737
+ set m02(val) {
1738
+ this._raw[2] = val;
1739
+ }
1740
+ get m03() {
1741
+ return this._raw[3];
1742
+ }
1743
+ set m03(val) {
1744
+ this._raw[3] = val;
1745
+ }
1746
+ get m10() {
1747
+ return this._raw[4];
1748
+ }
1749
+ set m10(val) {
1750
+ this._raw[4] = val;
1751
+ }
1752
+ get m11() {
1753
+ return this._raw[5];
1754
+ }
1755
+ set m11(val) {
1756
+ this._raw[5] = val;
1757
+ }
1758
+ get m12() {
1759
+ return this._raw[6];
1760
+ }
1761
+ set m12(val) {
1762
+ this._raw[6] = val;
1763
+ }
1764
+ get m13() {
1765
+ return this._raw[7];
1766
+ }
1767
+ set m13(val) {
1768
+ this._raw[7] = val;
1769
+ }
1770
+ get m20() {
1771
+ return this._raw[8];
1772
+ }
1773
+ set m20(val) {
1774
+ this._raw[8] = val;
1775
+ }
1776
+ get m21() {
1777
+ return this._raw[9];
1778
+ }
1779
+ set m21(val) {
1780
+ this._raw[9] = val;
1781
+ }
1782
+ get m22() {
1783
+ return this._raw[10];
1784
+ }
1785
+ set m22(val) {
1786
+ this._raw[10] = val;
1787
+ }
1788
+ get m23() {
1789
+ return this._raw[11];
1790
+ }
1791
+ set m23(val) {
1792
+ this._raw[11] = val;
1793
+ }
1794
+ get m30() {
1795
+ return this._raw[12];
1796
+ }
1797
+ set m30(val) {
1798
+ this._raw[12] = val;
1799
+ }
1800
+ get m31() {
1801
+ return this._raw[13];
1802
+ }
1803
+ set m31(val) {
1804
+ this._raw[13] = val;
1805
+ }
1806
+ get m32() {
1807
+ return this._raw[14];
1808
+ }
1809
+ set m32(val) {
1810
+ this._raw[14] = val;
1811
+ }
1812
+ get m33() {
1813
+ return this._raw[15];
1814
+ }
1815
+ set m33(val) {
1816
+ this._raw[15] = val;
1817
+ }
1818
+ static resolve(a) {
1819
+ const value = this.cast(a);
1820
+ if (typeof value != "undefined")
1821
+ return value;
1822
+ throw new ResolveError("Mat4", a);
1823
+ }
1824
+ static cast(a) {
1825
+ if (a == null || typeof a == "undefined")
1826
+ return void 0;
1827
+ if (check_number_array(a, 16)) {
1828
+ return new this(a);
1829
+ }
1830
+ if (check_array(a, void 0, 4)) {
1831
+ const row0 = a[0], row1 = a[1], row2 = a[2], row3 = a[3];
1832
+ if (check_number_array(row0, 4) && check_number_array(row1, 4) && check_number_array(row2, 4) && check_number_array(row3, 4))
1833
+ return new this([
1834
+ row0[0],
1835
+ row0[1],
1836
+ row0[2],
1837
+ row0[3],
1838
+ row1[0],
1839
+ row1[1],
1840
+ row1[2],
1841
+ row1[3],
1842
+ row2[0],
1843
+ row2[1],
1844
+ row2[2],
1845
+ row2[3],
1846
+ row3[0],
1847
+ row3[1],
1848
+ row3[2],
1849
+ row3[3]
1850
+ ]);
1851
+ }
1852
+ if (check_string(a)) {
1853
+ const parts = a.split(",");
1854
+ if (check_string_array(parts, 16))
1855
+ return this.cast(parts.map((i) => parseFloat(i)));
1856
+ }
1857
+ if (has_property(a, "m00", "number") && has_property(a, "m01", "number") && has_property(a, "m02", "number") && has_property(a, "m03", "number") && has_property(a, "m10", "number") && has_property(a, "m11", "number") && has_property(a, "m12", "number") && has_property(a, "m13", "number") && has_property(a, "m20", "number") && has_property(a, "m21", "number") && has_property(a, "m22", "number") && has_property(a, "m23", "number") && has_property(a, "m30", "number") && has_property(a, "m31", "number") && has_property(a, "m32", "number") && has_property(a, "m33", "number"))
1858
+ return new this([
1859
+ a.m00,
1860
+ a.m01,
1861
+ a.m02,
1862
+ a.m03,
1863
+ a.m10,
1864
+ a.m11,
1865
+ a.m12,
1866
+ a.m13,
1867
+ a.m20,
1868
+ a.m21,
1869
+ a.m22,
1870
+ a.m23,
1871
+ a.m30,
1872
+ a.m31,
1873
+ a.m32,
1874
+ a.m33
1875
+ ]);
1876
+ if (check_number(a)) {
1877
+ return new this([a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a]);
1878
+ }
1879
+ return void 0;
1880
+ }
1881
+ static is(a) {
1882
+ return typeof this.cast(a) != "undefined";
1883
+ }
1884
+ static orthographic(left, right, bottom, top, near, far) {
1885
+ return new this([
1886
+ 2 / (right - left),
1887
+ 0,
1888
+ 0,
1889
+ 0,
1890
+ 0,
1891
+ 2 / (top - bottom),
1892
+ 0,
1893
+ 0,
1894
+ 0,
1895
+ 0,
1896
+ 2 / (near - far),
1897
+ 0,
1898
+ (left + right) / (left - right),
1899
+ (bottom + top) / (bottom - top),
1900
+ (near + far) / (near - far),
1901
+ 1
1902
+ ]);
1903
+ }
1904
+ static perspective(fov, aspect, near, far) {
1905
+ const f = Math.tan(Math.PI * 0.5 - 0.5 * fov);
1906
+ const rangeInv = 1 / (near - far);
1907
+ return new this([
1908
+ f / aspect,
1909
+ 0,
1910
+ 0,
1911
+ 0,
1912
+ 0,
1913
+ f,
1914
+ 0,
1915
+ 0,
1916
+ 0,
1917
+ 0,
1918
+ (near + far) * rangeInv,
1919
+ -1,
1920
+ 0,
1921
+ 0,
1922
+ near * far * rangeInv * 2,
1923
+ 0
1924
+ ]);
1925
+ }
1926
+ static pointAt(position, target, up) {
1927
+ const newForward = Vec3.resolve(target).subtract(position).normalize();
1928
+ const a = newForward.multiply(Vec3.resolve(up).dot(newForward));
1929
+ const newUp = Vec3.resolve(up).subtract(a).normalize();
1930
+ const newRight = newUp.cross(newForward);
1931
+ const pos = Vec3.resolve(position);
1932
+ return new this([
1933
+ newRight.x,
1934
+ newRight.y,
1935
+ newRight.z,
1936
+ 0,
1937
+ newUp.x,
1938
+ newUp.y,
1939
+ newUp.z,
1940
+ 0,
1941
+ newForward.x,
1942
+ newForward.y,
1943
+ newForward.z,
1944
+ 0,
1945
+ pos.x,
1946
+ pos.y,
1947
+ pos.z,
1948
+ 1
1949
+ ]);
1950
+ }
1951
+ constructor(init = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]) {
1952
+ if (!check_number_array(init, 16))
1953
+ throw new TypeError("expected a number array with 16 elements");
1954
+ this._raw = init;
1955
+ }
1956
+ toArray() {
1957
+ return [
1958
+ this.m00,
1959
+ this.m01,
1960
+ this.m02,
1961
+ this.m03,
1962
+ this.m10,
1963
+ this.m11,
1964
+ this.m12,
1965
+ this.m13,
1966
+ this.m20,
1967
+ this.m21,
1968
+ this.m22,
1969
+ this.m23,
1970
+ this.m30,
1971
+ this.m31,
1972
+ this.m32,
1973
+ this.m33
1974
+ ];
1975
+ }
1976
+ toNestetArray() {
1977
+ return [
1978
+ [this.m00, this.m01, this.m02, this.m03],
1979
+ [this.m10, this.m11, this.m12, this.m13],
1980
+ [this.m20, this.m21, this.m22, this.m23],
1981
+ [this.m30, this.m31, this.m32, this.m33]
1982
+ ];
1983
+ }
1984
+ toJSON() {
1985
+ return {
1986
+ m00: this.m00,
1987
+ m01: this.m01,
1988
+ m02: this.m02,
1989
+ m03: this.m03,
1990
+ m10: this.m10,
1991
+ m11: this.m11,
1992
+ m12: this.m12,
1993
+ m13: this.m13,
1994
+ m20: this.m20,
1995
+ m21: this.m21,
1996
+ m22: this.m22,
1997
+ m23: this.m23,
1998
+ m30: this.m20,
1999
+ m31: this.m21,
2000
+ m32: this.m22,
2001
+ m33: this.m23
2002
+ };
2003
+ }
2004
+ toString() {
2005
+ 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}`;
2006
+ }
2007
+ clone() {
2008
+ return new _Mat4([
2009
+ this.m00,
2010
+ this.m01,
2011
+ this.m02,
2012
+ this.m03,
2013
+ this.m10,
2014
+ this.m11,
2015
+ this.m12,
2016
+ this.m13,
2017
+ this.m20,
2018
+ this.m21,
2019
+ this.m22,
2020
+ this.m23,
2021
+ this.m30,
2022
+ this.m31,
2023
+ this.m32,
2024
+ this.m33
2025
+ ]);
2026
+ }
2027
+ equals(mat) {
2028
+ const m = _Mat4.resolve(mat);
2029
+ for (let index = 0; index < this._raw.length; index++)
2030
+ if (this._raw[index] != m._raw[index])
2031
+ return false;
2032
+ return true;
2033
+ }
2034
+ add(mat) {
2035
+ const b = _Mat4.resolve(mat);
2036
+ const m = new _Mat4();
2037
+ for (let index = 0; index < this._raw.length; index++)
2038
+ m._raw[index] = this._raw[index] + b._raw[index];
2039
+ return m;
2040
+ }
2041
+ subtract(mat) {
2042
+ const b = _Mat4.resolve(mat);
2043
+ const m = new _Mat4();
2044
+ for (let index = 0; index < this._raw.length; index++)
2045
+ m._raw[index] = this._raw[index] - b._raw[index];
2046
+ return m;
2047
+ }
2048
+ multiply(a) {
2049
+ if (check_number(a)) {
2050
+ return new _Mat4([
2051
+ this.m00 * a,
2052
+ this.m01 * a,
2053
+ this.m02 * a,
2054
+ this.m03 * a,
2055
+ this.m10 * a,
2056
+ this.m11 * a,
2057
+ this.m12 * a,
2058
+ this.m13 * a,
2059
+ this.m20 * a,
2060
+ this.m21 * a,
2061
+ this.m22 * a,
2062
+ this.m23 * a,
2063
+ this.m30 * a,
2064
+ this.m31 * a,
2065
+ this.m32 * a,
2066
+ this.m33 * a
2067
+ ]);
2068
+ }
2069
+ if (_Mat4.is(a)) {
2070
+ const b = _Mat4.resolve(a);
2071
+ return new _Mat4([
2072
+ b.m00 * this.m00 + b.m01 * this.m10 + b.m02 * this.m20 + b.m03 * this.m30,
2073
+ b.m00 * this.m01 + b.m01 * this.m11 + b.m02 * this.m21 + b.m03 * this.m31,
2074
+ b.m00 * this.m02 + b.m01 * this.m12 + b.m02 * this.m22 + b.m03 * this.m32,
2075
+ b.m00 * this.m03 + b.m01 * this.m13 + b.m02 * this.m23 + b.m03 * this.m33,
2076
+ b.m10 * this.m00 + b.m11 * this.m10 + b.m12 * this.m20 + b.m13 * this.m30,
2077
+ b.m10 * this.m01 + b.m11 * this.m11 + b.m12 * this.m21 + b.m13 * this.m31,
2078
+ b.m10 * this.m02 + b.m11 * this.m12 + b.m12 * this.m22 + b.m13 * this.m32,
2079
+ b.m10 * this.m03 + b.m11 * this.m13 + b.m12 * this.m23 + b.m13 * this.m33,
2080
+ b.m20 * this.m00 + b.m21 * this.m10 + b.m22 * this.m20 + b.m23 * this.m30,
2081
+ b.m20 * this.m01 + b.m21 * this.m11 + b.m22 * this.m21 + b.m23 * this.m31,
2082
+ b.m20 * this.m02 + b.m21 * this.m12 + b.m22 * this.m22 + b.m23 * this.m32,
2083
+ b.m20 * this.m03 + b.m21 * this.m13 + b.m22 * this.m23 + b.m23 * this.m33,
2084
+ b.m30 * this.m00 + b.m31 * this.m10 + b.m32 * this.m20 + b.m33 * this.m30,
2085
+ b.m30 * this.m01 + b.m31 * this.m11 + b.m32 * this.m21 + b.m33 * this.m31,
2086
+ b.m30 * this.m02 + b.m31 * this.m12 + b.m32 * this.m22 + b.m33 * this.m32,
2087
+ b.m30 * this.m03 + b.m31 * this.m13 + b.m32 * this.m23 + b.m33 * this.m33
2088
+ ]);
2089
+ }
2090
+ if (Vec3.is(a)) {
2091
+ const b = Vec3.resolve(a);
2092
+ const vec = new Vec3(
2093
+ b.x * this.m00 + b.y * this.m10 + b.z * this.m20 + this.m30,
2094
+ b.x * this.m01 + b.y * this.m11 + b.z * this.m21 + this.m31,
2095
+ b.x * this.m02 + b.y * this.m12 + b.z * this.m22 + this.m32,
2096
+ b.x * this.m03 + b.y * this.m13 + b.z * this.m23 + this.m33
2097
+ );
2098
+ if (vec.w != 0)
2099
+ return vec.divide(vec.w);
2100
+ return vec;
2101
+ }
2102
+ throw new ResolveError("Mat4 or Vec3 or number", a);
2103
+ }
2104
+ translate(...args) {
2105
+ const vec = Vec3.resolveArgs(args);
2106
+ return this.multiply([
2107
+ 1,
2108
+ 0,
2109
+ 0,
2110
+ 0,
2111
+ 0,
2112
+ 1,
2113
+ 0,
2114
+ 0,
2115
+ 0,
2116
+ 0,
2117
+ 1,
2118
+ 0,
2119
+ vec.x,
2120
+ vec.y,
2121
+ vec.z,
2122
+ 1
2123
+ ]);
2124
+ }
2125
+ rotateX(angle) {
2126
+ const c = Math.cos(angle);
2127
+ const s = Math.sin(angle);
2128
+ return this.multiply([
2129
+ 1,
2130
+ 0,
2131
+ 0,
2132
+ 0,
2133
+ 0,
2134
+ c,
2135
+ s,
2136
+ 0,
2137
+ 0,
2138
+ -s,
2139
+ c,
2140
+ 0,
2141
+ 0,
2142
+ 0,
2143
+ 0,
2144
+ 1
2145
+ ]);
2146
+ }
2147
+ rotateY(angle) {
2148
+ const c = Math.cos(angle);
2149
+ const s = Math.sin(angle);
2150
+ return this.multiply([
2151
+ c,
2152
+ 0,
2153
+ -s,
2154
+ 0,
2155
+ 0,
2156
+ 1,
2157
+ 0,
2158
+ 0,
2159
+ s,
2160
+ 0,
2161
+ c,
2162
+ 0,
2163
+ 0,
2164
+ 0,
2165
+ 0,
2166
+ 1
2167
+ ]);
2168
+ }
2169
+ rotateZ(angle) {
2170
+ const c = Math.cos(angle);
2171
+ const s = Math.sin(angle);
2172
+ return this.multiply([
2173
+ c,
2174
+ s,
2175
+ 0,
2176
+ 0,
2177
+ -s,
2178
+ c,
2179
+ 0,
2180
+ 0,
2181
+ 0,
2182
+ 0,
2183
+ 1,
2184
+ 0,
2185
+ 0,
2186
+ 0,
2187
+ 0,
2188
+ 1
2189
+ ]);
2190
+ }
2191
+ rotate(...args) {
2192
+ const vec = Vec3.resolveArgs(args);
2193
+ return this.rotateX(vec.x).rotateY(vec.y).rotateZ(vec.z);
2194
+ }
2195
+ scale(...args) {
2196
+ const vec = Vec3.resolveArgs(args);
2197
+ return this.multiply([
2198
+ vec.x,
2199
+ 0,
2200
+ 0,
2201
+ 0,
2202
+ 0,
2203
+ vec.y,
2204
+ 0,
2205
+ 0,
2206
+ 0,
2207
+ 0,
2208
+ vec.z,
2209
+ 0,
2210
+ 0,
2211
+ 0,
2212
+ 0,
2213
+ 1
2214
+ ]);
2215
+ }
2216
+ inverse() {
2217
+ return new _Mat4([
2218
+ this.m00,
2219
+ this.m10,
2220
+ this.m20,
2221
+ 0,
2222
+ this.m01,
2223
+ this.m11,
2224
+ this.m21,
2225
+ 0,
2226
+ this.m02,
2227
+ this.m12,
2228
+ this.m22,
2229
+ 0,
2230
+ -(this.m30 * this.m00 + this.m31 * this.m10 + this.m32 * this.m20),
2231
+ -(this.m30 * this.m01 + this.m31 * this.m11 + this.m32 * this.m21),
2232
+ -(this.m30 * this.m02 + this.m31 * this.m12 + this.m32 * this.m22),
2233
+ 1
2234
+ ]);
2235
+ }
2236
+ toMat3() {
2237
+ return [
2238
+ this.m00,
2239
+ this.m01,
2240
+ this.m03,
2241
+ this.m10,
2242
+ this.m11,
2243
+ this.m13,
2244
+ this.m30,
2245
+ this.m31,
2246
+ this.m33
2247
+ ];
2248
+ }
2249
+ };
2250
+
2251
+ // source/color.ts
2252
+ function _hex_to_array(hex) {
2253
+ if (!check_hex(hex))
2254
+ return void 0;
2255
+ const part = get_hex_part(hex);
2256
+ const a = parseInt(part.substring(0, 2), 16) / 255;
2257
+ const b = parseInt(part.substring(2, 4), 16) / 255;
2258
+ const c = parseInt(part.substring(4, 6), 16) / 255;
2259
+ const d = part.length == 8 ? parseInt(hex.substring(6, 8), 16) / 255 : 1;
2260
+ return [a, b, c, d];
2261
+ }
2262
+ function _number_to_rgb(number) {
2263
+ const blue = number & 255;
2264
+ const green = (number & 65280) >>> 8;
2265
+ const red = (number & 16711680) >>> 16;
2266
+ return [red / 255, green / 255, blue / 255];
2267
+ }
2268
+ function _number_to_rgba(number) {
2269
+ const alpha = number & 255;
2270
+ const blue = (number & 65280) >>> 8;
2271
+ const green = (number & 16711680) >>> 16;
2272
+ const red = (number & 4278190080) >>> 24;
2273
+ return [red / 255, green / 255, blue / 255, alpha / 255];
2274
+ }
2275
+ function _fix_integer(number) {
2276
+ return number * 255 | 0;
2277
+ }
2278
+ var RGBAColor = class _RGBAColor {
2279
+ _red;
2280
+ get red() {
2281
+ return this._red;
2282
+ }
2283
+ set red(val) {
2284
+ this._red = clamp(val, 0, 1);
2285
+ }
2286
+ _green;
2287
+ get green() {
2288
+ return this._green;
2289
+ }
2290
+ set green(val) {
2291
+ this._green = clamp(val, 0, 1);
2292
+ }
2293
+ _blue;
2294
+ get blue() {
2295
+ return this._blue;
2296
+ }
2297
+ set blue(val) {
2298
+ this._blue = clamp(val, 0, 1);
2299
+ }
2300
+ _alpha;
2301
+ get alpha() {
2302
+ return this._alpha;
2303
+ }
2304
+ set alpha(val) {
2305
+ this._alpha = clamp(val, 0, 1);
2306
+ }
2307
+ static resolve(a) {
2308
+ const value = this.cast(a);
2309
+ if (typeof value != "undefined")
2310
+ return value;
2311
+ throw new ResolveError("RGBAColor", a);
2312
+ }
2313
+ static cast(a) {
2314
+ if (a == null || typeof a == "undefined")
2315
+ return void 0;
2316
+ if (check_number_array(a, 3) || check_number_array(a, 4))
2317
+ return new this(a[0], a[1], a[2], a[3]);
2318
+ if (has_property(a, "red", "number") && has_property(a, "green", "number") && has_property(a, "blue", "number"))
2319
+ return new this(a.red, a.green, a.blue, has_property(a, "alpha", "number") ? a.alpha : void 0);
2320
+ if (check_number(a)) {
2321
+ const hex = a.toString(16);
2322
+ const convert = hex.length <= 6 ? _number_to_rgb : _number_to_rgba;
2323
+ return this.cast(convert(a));
2324
+ }
2325
+ if (check_string(a)) {
2326
+ if (a.startsWith("rgb")) {
2327
+ const hasAlpha = a.startsWith("rgba");
2328
+ const offset = hasAlpha ? 5 : 4;
2329
+ const parts = a.substring(offset, a.indexOf(")", offset)).split(",");
2330
+ if (check_string_array(parts, hasAlpha ? 4 : 3))
2331
+ return this.cast(parts.map((v) => parseInt(v) / 255));
2332
+ }
2333
+ return this.cast(_hex_to_array(a));
2334
+ }
2335
+ return void 0;
2336
+ }
2337
+ static is(a) {
2338
+ return typeof this.cast(a) != "undefined";
2339
+ }
2340
+ constructor(red, green, blue, alpha = 1) {
2341
+ this._red = clamp(red, 0, 1);
2342
+ this._green = clamp(green, 0, 1);
2343
+ this._blue = clamp(blue, 0, 1);
2344
+ this._alpha = clamp(alpha, 0, 1);
2345
+ }
2346
+ toArray(withAlpha = false) {
2347
+ return withAlpha ? [this.red, this.green, this.blue, this.alpha] : this.alpha == 1 ? [this.red, this.green, this.blue] : this.toArray(true);
2348
+ }
2349
+ toJSON(withAlpha = false) {
2350
+ return withAlpha ? {
2351
+ red: this.red,
2352
+ green: this.green,
2353
+ blue: this.blue,
2354
+ alpha: this.alpha
2355
+ } : this.alpha == 1 ? { red: this.red, green: this.green, blue: this.blue } : this.toJSON(true);
2356
+ }
2357
+ toString(withAlpha = false) {
2358
+ return withAlpha ? `rgba(${_fix_integer(this.red)},${_fix_integer(this.green)},${_fix_integer(this.blue)},${_fix_integer(this.alpha)})` : this.alpha == 1 ? `rgb(${_fix_integer(this.red)},${_fix_integer(this.green)},${_fix_integer(this.blue)})` : this.toString(true);
2359
+ }
2360
+ toHSL(withAlpha = true) {
2361
+ const red = this.red, green = this.green, blue = this.blue;
2362
+ const min = Math.min(red, green, blue), max = Math.max(red, green, blue);
2363
+ const luminace = (min + max) / 2;
2364
+ if (min == max)
2365
+ return new HSLColor(0, 0, luminace, withAlpha ? this.alpha : void 0);
2366
+ const d = max - min;
2367
+ const saturation = luminace > 0.5 ? d / (2 - max - min) : d / (max + min);
2368
+ if (max == red)
2369
+ return new HSLColor(((green - blue) / d + (green < blue ? 6 : 0)) / 6, saturation, luminace);
2370
+ if (max == green)
2371
+ return new HSLColor(((blue - red) / d + 2) / 6, saturation, luminace);
2372
+ if (max == blue)
2373
+ return new HSLColor(((red - green) / d + 4) / 6, saturation, luminace);
2374
+ return new HSLColor(0, saturation, luminace, withAlpha ? this.alpha : void 0);
2375
+ }
2376
+ invert(withAlpha = false) {
2377
+ return new _RGBAColor(
2378
+ 1 - this.red,
2379
+ 1 - this.green,
2380
+ 1 - this.blue,
2381
+ withAlpha ? 1 - this.alpha : this.alpha
2382
+ );
2383
+ }
2384
+ };
2385
+ var HSLColor = class _HSLColor {
2386
+ _hue;
2387
+ get hue() {
2388
+ return this._hue;
2389
+ }
2390
+ set hue(val) {
2391
+ this._hue = clamp(val, 0, 1);
2392
+ }
2393
+ _saturation;
2394
+ get saturation() {
2395
+ return this._saturation;
2396
+ }
2397
+ set saturation(val) {
2398
+ this._saturation = clamp(val, 0, 1);
2399
+ }
2400
+ _luminace;
2401
+ get luminace() {
2402
+ return this._luminace;
2403
+ }
2404
+ set luminace(val) {
2405
+ this._luminace = clamp(val, 0, 1);
2406
+ }
2407
+ _alpha;
2408
+ get alpha() {
2409
+ return this._alpha;
2410
+ }
2411
+ set alpha(val) {
2412
+ this._alpha = clamp(val, 0, 1);
2413
+ }
2414
+ static resolve(a) {
2415
+ const value = this.cast(a);
2416
+ if (typeof value != "undefined")
2417
+ return value;
2418
+ throw new ResolveError("HSLColor", a);
2419
+ }
2420
+ static cast(a) {
2421
+ if (a == null || typeof a == "undefined")
2422
+ return void 0;
2423
+ if (check_number_array(a, 3) || check_number_array(a, 4))
2424
+ return new this(a[0], a[1], a[2], a[3]);
2425
+ if (has_property(a, "hue", "number") && has_property(a, "saturation", "number") && has_property(a, "luminace", "number"))
2426
+ return new this(a.hue, a.saturation, a.luminace, has_property(a, "alpha", "number") ? a.alpha : void 0);
2427
+ if (check_number(a)) {
2428
+ const hex = a.toString(16);
2429
+ const convert = hex.length <= 6 ? _number_to_rgb : _number_to_rgba;
2430
+ return this.cast(convert(a));
2431
+ }
2432
+ if (check_string(a)) {
2433
+ if (a.startsWith("hsl")) {
2434
+ const hasAlpha = a.startsWith("hsla");
2435
+ const offset = hasAlpha ? 5 : 4;
2436
+ const parts = a.substring(offset, a.indexOf(")", offset)).split(",");
2437
+ if (check_string_array(parts, hasAlpha ? 4 : 3))
2438
+ return this.cast(parts.map((v) => parseInt(v) / 255));
2439
+ }
2440
+ return this.cast(_hex_to_array(a));
2441
+ }
2442
+ return void 0;
2443
+ }
2444
+ static is(a) {
2445
+ return typeof this.cast(a) != "undefined";
2446
+ }
2447
+ constructor(hue, saturation, luminace, alpha = 1) {
2448
+ if (!check_number(hue))
2449
+ throw new TypeError("expected number for hue");
2450
+ if (!check_number(saturation))
2451
+ throw new TypeError("expected number for saturation");
2452
+ if (!check_number(luminace))
2453
+ throw new TypeError("expected number for luminace");
2454
+ if (!check_number(alpha))
2455
+ throw new TypeError("expected number for alpha");
2456
+ this._hue = clamp(hue, 0, 1);
2457
+ this._saturation = clamp(saturation, 0, 1);
2458
+ this._luminace = clamp(luminace, 0, 1);
2459
+ this._alpha = clamp(alpha, 0, 1);
2460
+ }
2461
+ toArray(withAlpha = false) {
2462
+ return withAlpha ? [this.hue, this.saturation, this.luminace, this.alpha] : this.alpha == 1 ? [this.hue, this.saturation, this.luminace] : this.toArray(true);
2463
+ }
2464
+ toJSON(withAlpha = false) {
2465
+ return withAlpha ? {
2466
+ hue: this.hue,
2467
+ saturation: this.saturation,
2468
+ luminace: this.luminace,
2469
+ alpha: this.alpha
2470
+ } : this.alpha == 1 ? { hue: this.hue, saturation: this.saturation, luminace: this.luminace } : this.toJSON(true);
2471
+ }
2472
+ toString(withAlpha = false) {
2473
+ return withAlpha ? `hsla(${_fix_integer(this.hue)},${_fix_integer(this.saturation)},${_fix_integer(this.luminace)},${_fix_integer(this.alpha)})` : this.alpha == 1 ? `hsl(${_fix_integer(this.hue)},${_fix_integer(this.saturation)},${_fix_integer(this.luminace)})` : this.toString(true);
2474
+ }
2475
+ toRGB(withAlpha = true) {
2476
+ if (this.saturation == 0)
2477
+ return new RGBAColor(this.luminace * 255, this.luminace * 255, this.luminace * 255, withAlpha ? this.alpha : void 0);
2478
+ const q = this.luminace < 0.5 ? this.luminace * (1 + this.saturation) : this.luminace + this.saturation - this.luminace * this.saturation;
2479
+ const p = 2 * this.luminace - q;
2480
+ function _hue_2_rgb(t) {
2481
+ let _t = t;
2482
+ if (_t < 0)
2483
+ _t++;
2484
+ if (_t > 1)
2485
+ _t--;
2486
+ if (_t < 1 / 6)
2487
+ return p + (q - p) * 6 * _t;
2488
+ if (_t < 1 / 2)
2489
+ return q;
2490
+ if (_t < 2 / 3)
2491
+ return p + (q - p) * (2 / 3 - _t) * 6;
2492
+ return p;
2493
+ }
2494
+ 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);
2495
+ }
2496
+ invert(withAlpha = false) {
2497
+ return new _HSLColor(
2498
+ 1 - this.hue,
2499
+ 1 - this.saturation,
2500
+ 1 - this.luminace,
2501
+ withAlpha ? 1 - this.alpha : this.alpha
2502
+ );
2503
+ }
2504
+ };
2505
+ function resolveColor(a, preferHSL = false) {
2506
+ const value = castColor(a, preferHSL);
2507
+ if (typeof value != "undefined")
2508
+ return value;
2509
+ throw new ResolveError("Color", a);
2510
+ }
2511
+ function castColor(a, preferHSL = false) {
2512
+ const results = [];
2513
+ try {
2514
+ const rgba = RGBAColor.resolve(a);
2515
+ results.push(rgba);
2516
+ } catch (e) {
2517
+ }
2518
+ try {
2519
+ const hsla = HSLColor.resolve(a);
2520
+ results.push(hsla);
2521
+ } catch (e) {
2522
+ }
2523
+ let offset = preferHSL ? 1 : 0;
2524
+ const firstItem = results[offset];
2525
+ if (firstItem)
2526
+ return firstItem;
2527
+ const secondItem = results[offset + 1];
2528
+ if (secondItem)
2529
+ return secondItem;
2530
+ return void 0;
2531
+ }
2532
+
2533
+ // source/quaternion.ts
2534
+ var Quaternion = class _Quaternion {
2535
+ w;
2536
+ x;
2537
+ y;
2538
+ z;
2539
+ static is(a) {
2540
+ return typeof this.cast(a) != "undefined";
2541
+ }
2542
+ static resolve(a) {
2543
+ const value = this.cast(a);
2544
+ if (typeof value != "undefined")
2545
+ return value;
2546
+ throw new ResolveError("Quaternion", a);
2547
+ }
2548
+ static cast(a) {
2549
+ if (a == null || typeof a == "undefined")
2550
+ return void 0;
2551
+ if (check_number_array(a, 4))
2552
+ return new this(a[0], a[1], a[2], a[3]);
2553
+ if (has_property(a, "w", "number") && has_property(a, "x", "number") && has_property(a, "y", "number") && has_property(a, "z", "number"))
2554
+ return new this(a.w, a.x, a.y, a.z);
2555
+ if (check_string(a)) {
2556
+ const parts = a.replaceAll(" ", "").split("+");
2557
+ if (check_string_array(parts, 4)) {
2558
+ const [sw, sxi, syj, szk] = parts;
2559
+ if (sxi.endsWith("i") && syj.endsWith("j") && szk.endsWith("k"))
2560
+ return this.cast([
2561
+ parseFloat(sw),
2562
+ parseFloat(sxi.substring(0, sxi.length - 1)),
2563
+ parseFloat(syj.substring(0, syj.length - 1)),
2564
+ parseFloat(szk.substring(0, szk.length - 1))
2565
+ ]);
2566
+ }
2567
+ }
2568
+ return void 0;
2569
+ }
2570
+ static fromAxisAngle(axis, angle) {
2571
+ const vec = Vec3.resolve(axis);
2572
+ const hangle = angle * 0.5;
2573
+ const sin2 = Math.sin(hangle);
2574
+ const cos2 = Math.cos(hangle);
2575
+ const length = sin2 / Math.sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z);
2576
+ return new this(cos2, vec.x * length, vec.y * length, vec.z * length);
2577
+ }
2578
+ static fromEuler(...args) {
2579
+ const vec = Vec3.resolveArgs(args);
2580
+ const x2 = vec.x * 0.5, y2 = vec.y * 0.5, z2 = vec.z * 0.5;
2581
+ const cx = Math.cos(x2), cy = Math.cos(y2), cz = Math.cos(z2);
2582
+ const sx = Math.sin(x2), sy = Math.sin(y2), sz = Math.sin(z2);
2583
+ return new _Quaternion(
2584
+ cx * cy * cz - sx * sy * sz,
2585
+ sx * cy * cz - sy * sz * cx,
2586
+ sy * cx * cz - sx * sz * cy,
2587
+ sx * sy * cz + sz * cx * cy
2588
+ );
2589
+ }
2590
+ constructor(w = 0, x = 0, y = 0, z = 0) {
2591
+ if (!check_number(w))
2592
+ throw new TypeError("expected number for w");
2593
+ if (!check_number(x))
2594
+ throw new TypeError("expected number for x");
2595
+ if (!check_number(y))
2596
+ throw new TypeError("expected number for x");
2597
+ if (!check_number(z))
2598
+ throw new TypeError("expected number for w");
2599
+ this.w = w;
2600
+ this.x = x;
2601
+ this.y = y;
2602
+ this.z = z;
2603
+ }
2604
+ toArray() {
2605
+ return [this.w, this.x, this.y, this.z];
2606
+ }
2607
+ toString() {
2608
+ return `${this.w} + ${this.x}i + ${this.y}j + ${this.z}k`;
2609
+ }
2610
+ toJSON() {
2611
+ return {
2612
+ w: this.w,
2613
+ x: this.x,
2614
+ y: this.y,
2615
+ z: this.z
2616
+ };
2617
+ }
2618
+ clone() {
2619
+ return new _Quaternion(this.w, this.x, this.y, this.z);
2620
+ }
2621
+ add(a) {
2622
+ const quat = _Quaternion.resolve(a);
2623
+ return new _Quaternion(
2624
+ this.w + quat.w,
2625
+ this.x + quat.x,
2626
+ this.y + quat.y,
2627
+ this.z + quat.z
2628
+ );
2629
+ }
2630
+ offset(a) {
2631
+ const quat = _Quaternion.resolve(a);
2632
+ this.w += quat.w;
2633
+ this.x += quat.x;
2634
+ this.y += quat.y;
2635
+ this.z += quat.z;
2636
+ return this;
2637
+ }
2638
+ subtract(a) {
2639
+ const quat = _Quaternion.resolve(a);
2640
+ return new _Quaternion(
2641
+ this.w - quat.w,
2642
+ this.x - quat.x,
2643
+ this.y - quat.y,
2644
+ this.z - quat.z
2645
+ );
2646
+ }
2647
+ negative() {
2648
+ return new _Quaternion(-this.w, -this.x, -this.y, -this.z);
2649
+ }
2650
+ length(sqrt = true) {
2651
+ const value = this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z;
2652
+ return sqrt ? Math.sqrt(value) : value;
2653
+ }
2654
+ normalize() {
2655
+ let length = this.length();
2656
+ if (length < EPSILON)
2657
+ return new _Quaternion();
2658
+ length = 1 / length;
2659
+ return new _Quaternion(this.w * length, this.x * length, this.y * length, this.z * length);
2660
+ }
2661
+ multiply(a) {
2662
+ const quat = _Quaternion.resolve(a);
2663
+ return new _Quaternion(
2664
+ this.w * quat.w - this.x * quat.x - this.y * quat.y - this.z * quat.z,
2665
+ this.w * quat.x + this.x * quat.w + this.y * quat.z - this.z * quat.y,
2666
+ this.w * quat.y + this.y * quat.w + this.z * quat.x - this.x * quat.z,
2667
+ this.w * quat.z + this.z * quat.w + this.x * quat.y - this.y * quat.x
2668
+ );
2669
+ }
2670
+ multiplyVector(...args) {
2671
+ const vec = Vec3.resolveArgs(args);
2672
+ const ix = this.w * vec.x + this.y * vec.y - this.z * vec.y;
2673
+ const iy = this.w * vec.y + this.z * vec.x - this.x * vec.z;
2674
+ const iz = this.w * vec.z + this.x * vec.y - this.y * vec.x;
2675
+ const iw = -this.w * vec.x - this.y * vec.y - this.z * vec.z;
2676
+ return new Vec3(
2677
+ ix * this.w + iw * -this.x + iy * -this.z - iz * -this.y,
2678
+ iy * this.w + iw * -this.y + iz * -this.x - ix * -this.z,
2679
+ iz * this.w + iw * -this.z + ix * -this.y - iy * -this.x
2680
+ );
2681
+ }
2682
+ scale(scalar) {
2683
+ return new _Quaternion(this.w * scalar, this.x * scalar, this.y * scalar, this.z * scalar);
2684
+ }
2685
+ dot(a) {
2686
+ const quat = _Quaternion.resolve(a);
2687
+ return this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z;
2688
+ }
2689
+ inverse() {
2690
+ let length = this.length(false);
2691
+ if (length == 0)
2692
+ return new _Quaternion();
2693
+ length = 1 / length;
2694
+ return new _Quaternion(this.w * length, -this.x * length, -this.y * length, -this.z * length);
2695
+ }
2696
+ divide(a) {
2697
+ const quat = _Quaternion.resolve(a);
2698
+ let length = quat.length(false);
2699
+ if (length == 0) return new _Quaternion();
2700
+ length = 1 / length;
2701
+ return new _Quaternion(
2702
+ (this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z) * length,
2703
+ (this.x * quat.w - this.w * quat.x - this.y * quat.z + this.z * quat.y) * length,
2704
+ (this.y * quat.w - this.w * quat.y - this.z * quat.x + this.x * quat.z) * length,
2705
+ (this.z * quat.w - this.w * quat.z - this.x * quat.y + this.y * quat.x) * length
2706
+ );
2707
+ }
2708
+ conjugate() {
2709
+ return new _Quaternion(this.w, -this.x, -this.y, -this.z);
2710
+ }
2711
+ exp() {
2712
+ const length = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
2713
+ const exp = Math.exp(this.w);
2714
+ const scale = exp * Math.sin(length) / length;
2715
+ if (length == 0)
2716
+ return new _Quaternion(exp);
2717
+ return new _Quaternion(
2718
+ exp * Math.cos(length),
2719
+ this.x * scale,
2720
+ this.y * scale,
2721
+ this.z * scale
2722
+ );
2723
+ }
2724
+ log() {
2725
+ if (this.x == 0 && this.z == 0)
2726
+ return new _Quaternion(log_hypot(this.w, this.x), Math.atan2(this.x, this.w));
2727
+ const length = this.length(false);
2728
+ const length2 = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
2729
+ const scale = Math.atan2(length2, this.w) / length;
2730
+ return new _Quaternion(Math.log(length) * 0.5, this.x * scale, this.y * scale, this.z * scale);
2731
+ }
2732
+ toVector() {
2733
+ return new Vec3(this.x, this.y, this.z, this.w);
2734
+ }
2735
+ toAxisAngle() {
2736
+ const sin2 = 1 - this.w * this.w;
2737
+ if (sin2 > EPSILON)
2738
+ return new Vec3(this.x, this.y, this.z, 0);
2739
+ const isin = 1 / Math.sqrt(sin2);
2740
+ const angle = 2 * Math.acos(this.w);
2741
+ return new Vec3(this.x * isin, this.y * isin, this.z * isin, angle);
2742
+ }
2743
+ toEuler() {
2744
+ function asin(t) {
2745
+ return t >= 1 ? Math.PI / 2 : t <= -1 ? -Math.PI / 2 : Math.asin(t);
2746
+ }
2747
+ return new Vec3(
2748
+ -Math.atan2(2 * (this.y * this.z - this.w * this.x), 1 - 2 * (this.x * this.x + this.y * this.y)),
2749
+ asin(2 * (this.x * this.z + this.w * this.y)),
2750
+ -Math.atan2(2 * (this.x * this.y - this.w * this.z), 1 - 2 * (this.y * this.y + this.z * this.z))
2751
+ );
2752
+ }
2753
+ toMat3() {
2754
+ return new Mat3([
2755
+ 1 - 2 * (this.y * this.y + this.z * this.z),
2756
+ 2 * (this.x * this.y - this.w * this.z),
2757
+ 2 * (this.x * this.z + this.w * this.y),
2758
+ 2 * (this.x * this.y + this.w * this.z),
2759
+ 1 - 2 * (this.x * this.x + this.z * this.z),
2760
+ 2 * (this.y * this.z - this.w * this.x),
2761
+ 2 * (this.x * this.z - this.w * this.y),
2762
+ 2 * (this.y * this.z + this.w * this.x),
2763
+ 1 - 2 * (this.x * this.x + this.y * this.y)
2764
+ ]);
2765
+ }
2766
+ toMat4() {
2767
+ return new Mat4([
2768
+ 1 - 2 * (this.y * this.y + this.z * this.z),
2769
+ 2 * (this.x * this.y - this.w * this.z),
2770
+ 2 * (this.x * this.z + this.w * this.y),
2771
+ 0,
2772
+ 2 * (this.x * this.y + this.w * this.z),
2773
+ 1 - 2 * (this.x * this.x + this.z * this.z),
2774
+ 2 * (this.y * this.z - this.w * this.x),
2775
+ 0,
2776
+ 2 * (this.x * this.z - this.w * this.y),
2777
+ 2 * (this.y * this.z + this.w * this.x),
2778
+ 1 - 2 * (this.x * this.x + this.y * this.y),
2779
+ 0,
2780
+ 0,
2781
+ 0,
2782
+ 0,
2783
+ 1
2784
+ ]);
2785
+ }
2786
+ };
2787
+
2788
+ // source/transform.ts
2789
+ var Transform = class {
2790
+ /**
2791
+ * The position of the object
2792
+ */
2793
+ position;
2794
+ /**
2795
+ * The rotation of the object
2796
+ */
2797
+ rotation;
2798
+ /**
2799
+ * The scale of the object
2800
+ */
2801
+ scale;
2802
+ /**
2803
+ * Create a new transform with `position`, `rotation` and `scale`
2804
+ * @param position The position as a Vec3
2805
+ * @param rotation The rotation as a Quaternion
2806
+ * @param scale The scale as a Vec3
2807
+ */
2808
+ constructor(position, rotation, scale) {
2809
+ this.position = Vec3.resolve(position);
2810
+ this.rotation = Quaternion.resolve(rotation);
2811
+ this.scale = Vec3.resolve(scale);
2812
+ }
2813
+ /**
2814
+ * Convert the transform into a 4x3 matrix
2815
+ * @returns A 4x4 matrix from the transform
2816
+ */
2817
+ toMat4() {
2818
+ return new Mat4().translate(this.position).multiply(this.rotation.toMat4()).scale(this.scale);
2819
+ }
2820
+ };
2821
+ export {
2822
+ ATriangle,
2823
+ BoundingBox,
2824
+ Circle,
2825
+ DJB2_OFFSET,
2826
+ EPSILON,
2827
+ FNV1_OFFSET,
2828
+ FNV1_PRIME,
2829
+ HSLColor,
2830
+ LinearFunction,
2831
+ MAX_ANGLE_DEGREE,
2832
+ MD2,
2833
+ Mat3,
2834
+ Mat4,
2835
+ MathFunction,
2836
+ QuadFunction,
2837
+ Quaternion,
2838
+ RGBAColor,
2839
+ Rectangle,
2840
+ ResolveError,
2841
+ Size,
2842
+ Transform,
2843
+ Triangle2D,
2844
+ Triangle3D,
2845
+ Vec2,
2846
+ Vec3,
2847
+ cap_angle_degree,
2848
+ cap_angle_radian,
2849
+ castColor,
2850
+ check_array,
2851
+ check_hex,
2852
+ check_hex_digit,
2853
+ check_number,
2854
+ check_number_array,
2855
+ check_string,
2856
+ check_string_array,
2857
+ clamp,
2858
+ degree_to_radian,
2859
+ djb2,
2860
+ fnv1,
2861
+ get_hex_part,
2862
+ has_property,
2863
+ log_hypot,
2864
+ radian_to_degree,
2865
+ resolveColor,
2866
+ sdbm,
2867
+ sign_char,
2868
+ stringify
2869
+ };