@ntf/math 1.3.1 → 1.4.0

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.mjs CHANGED
@@ -3,7 +3,7 @@ var MathFunction = class {
3
3
  };
4
4
 
5
5
  // source/common/sign.ts
6
- function sign_char(num) {
6
+ function signCharacter(num) {
7
7
  if (num == 0)
8
8
  return void 0;
9
9
  if (num < 0)
@@ -14,35 +14,10 @@ function sign_char(num) {
14
14
  }
15
15
 
16
16
  // source/common/types.ts
17
- function check_number(obj) {
18
- return obj != null && typeof obj == "number" && !isNaN(obj) && isFinite(obj);
17
+ function checkNumber(value) {
18
+ return value !== null && typeof value == "number" && !isNaN(value) && isFinite(value);
19
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) {
20
+ function getHexValue(string) {
46
21
  let offset = 0;
47
22
  if (string.startsWith("#") || string.startsWith("$"))
48
23
  offset = 1;
@@ -50,112 +25,48 @@ function get_hex_part(string) {
50
25
  offset = 2;
51
26
  return string.substring(offset);
52
27
  }
53
- function check_hex(obj) {
54
- if (!check_string(obj))
28
+ function checkHex(value) {
29
+ if (!checkString(value))
55
30
  return false;
56
- const value = get_hex_part(obj).split("").map((char) => parseInt(char.toUpperCase(), 16));
57
- return check_number_array(value);
31
+ const hexValue = getHexValue(value).split("").map((char) => parseInt(char.toUpperCase(), 16));
32
+ return checkNumberArray(hexValue);
58
33
  }
59
- function check_string(obj) {
60
- return obj != null && typeof obj == "string" && obj.length > 0;
34
+ function checkString(value) {
35
+ return value !== null && typeof value == "string" && value.length > 0;
61
36
  }
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))
37
+ function checkArray(value, predicate, requiredLength) {
38
+ if (!Array.isArray(value)) return false;
39
+ if (typeof requiredLength == "number" && requiredLength !== value.length) return false;
40
+ for (const item of value)
41
+ if (typeof predicate == "function" && !predicate(item))
67
42
  return false;
68
43
  return true;
69
44
  }
70
- function check_number_array(obj, requiredLength) {
71
- return check_array(obj, check_number, requiredLength);
45
+ function checkNumberArray(value, requiredLength) {
46
+ return checkArray(value, checkNumber, requiredLength);
72
47
  }
73
- function check_string_array(obj, requiredLength) {
74
- return check_array(obj, check_string, requiredLength);
48
+ function checkStringArray(value, requiredLength) {
49
+ return checkArray(value, checkString, requiredLength);
75
50
  }
76
- function has_property(obj, name, type) {
77
- return obj != null && typeof obj == "object" && name in obj && typeof obj[name] == type;
51
+ function hasProperty(value, propertyName, type) {
52
+ return value !== null && typeof value == "object" && propertyName in value && typeof value[propertyName] == type;
78
53
  }
54
+ var NodeJSCustomInspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
79
55
 
80
56
  // source/common/error.ts
81
57
  var ResolveError = class extends Error {
58
+ /**
59
+ * Create a resolve exception
60
+ * @param target The target type name
61
+ * @param value A value
62
+ */
82
63
  constructor(target, value) {
83
- super(`can't resolve ${value} to ${target}`);
64
+ super(`Can't resolve ${value} to ${target}`);
84
65
  this.target = target;
85
66
  this.value = value;
86
67
  }
87
68
  };
88
69
 
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
70
  // source/utils.ts
160
71
  function clamp(value, min, max) {
161
72
  if (value <= min)
@@ -164,7 +75,7 @@ function clamp(value, min, max) {
164
75
  return max;
165
76
  return value;
166
77
  }
167
- function log_hypot(a, b) {
78
+ function logHypot(a, b) {
168
79
  const a_abs = Math.abs(a);
169
80
  const b_abs = Math.abs(b);
170
81
  if (a == 0)
@@ -177,41 +88,43 @@ function log_hypot(a, b) {
177
88
  return 0.5 * Math.log(_a * _a + _b * _b) + Math.LN2;
178
89
  }
179
90
  var EPSILON = 1e-16;
91
+ var lerp = (a, b, t) => ((typeof a == "number" ? 1 : 1n) - t) * a + t * b;
180
92
 
181
- // source/vectors/vec3.ts
182
- var Vec3 = class _Vec3 {
93
+ // source/vectors/vec2.ts
94
+ var Vec2 = class _Vec2 {
183
95
  x;
184
96
  y;
185
- z;
186
97
  w;
187
98
  static resolve(a) {
188
99
  const value = this.cast(a);
189
100
  if (typeof value != "undefined")
190
101
  return value;
191
- throw new ResolveError("Vec3", a);
102
+ throw new ResolveError("Vec2", a);
192
103
  }
193
104
  static cast(a) {
194
105
  if (a == null || typeof a == "undefined")
195
106
  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);
107
+ if (checkNumberArray(a, 2) || checkNumberArray(a, 3))
108
+ return new this(a[0], a[1], checkNumber(a[2]) ? a[2] : void 0);
109
+ if (hasProperty(a, "toVec2", "function"))
110
+ return this.cast(a.toVec2());
111
+ if (hasProperty(a, "x", "number") && hasProperty(a, "y", "number"))
112
+ return new this(a.x, a.y, hasProperty(a, "w", "number") ? a.w : void 0);
113
+ if (checkString(a)) {
114
+ const [sxy, sw] = a.split(";");
115
+ if (checkString(sxy)) {
116
+ const parts = sxy.split(",");
117
+ if (checkStringArray(parts, 2))
118
+ return new this(parseFloat(parts[0]), parseFloat(parts[1]), checkString(sw) ? parseFloat(sw) : void 0);
206
119
  }
207
120
  }
208
- if (check_number(a))
209
- return new this(a, a, a);
121
+ if (checkNumber(a))
122
+ return new this(a, a);
210
123
  return void 0;
211
124
  }
212
125
  static resolveArgs(args) {
213
- if (check_number_array(args, 3))
214
- return new this(args[0], args[1], args[2]);
126
+ if (checkNumberArray(args, 2))
127
+ return new this(args[0], args[1]);
215
128
  return this.resolve(args[0]);
216
129
  }
217
130
  static is(a) {
@@ -220,63 +133,79 @@ var Vec3 = class _Vec3 {
220
133
  static fromPoints(a, b) {
221
134
  const veca = this.resolve(a);
222
135
  const vecb = this.resolve(b);
223
- return new this(vecb.x - veca.x, vecb.y - veca.y, vecb.z - veca.z);
136
+ return new this(vecb.x - veca.x, vecb.y - veca.y);
224
137
  }
225
138
  static clamp(value, min, max) {
226
139
  const a = this.resolve(value), b = this.resolve(min), c = this.resolve(max);
227
140
  return new this(
228
141
  clamp(a.x, b.x, c.x),
229
- clamp(a.y, b.y, c.y),
230
- clamp(a.z, b.z, c.z)
142
+ clamp(a.y, b.y, c.y)
231
143
  );
232
144
  }
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);
145
+ static get zero() {
146
+ return new this(0, 0);
242
147
  }
243
- constructor(x = 0, y = 0, z = 0, w = 1) {
244
- if (!check_number(x))
148
+ static get one() {
149
+ return new this(1, 1);
150
+ }
151
+ constructor(x, y, w = 1) {
152
+ if (!checkNumber(x))
245
153
  throw new TypeError("expected number for x");
246
- if (!check_number(y))
154
+ if (!checkNumber(y))
247
155
  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))
156
+ if (!checkNumber(w))
251
157
  throw new TypeError("expected number for w");
252
158
  this.x = x;
253
159
  this.y = y;
254
- this.z = z;
255
160
  this.w = w;
256
161
  }
257
- toArray(w = false) {
258
- return w ? [this.x, this.y, this.z] : [this.x, this.y, this.z, this.w];
162
+ toArray(w = this.w !== 1) {
163
+ return w ? [this.x, this.y, this.w] : [this.x, this.y];
259
164
  }
260
165
  toJSON() {
261
166
  return {
262
167
  x: this.x,
263
168
  y: this.y,
264
- z: this.z,
265
169
  w: this.w
266
170
  };
267
171
  }
268
- toString(w = false) {
269
- return w ? `${this.x},${this.y},${this.z}` : `${this.x},${this.y},${this.z};${this.w}`;
172
+ toString(w = this.w !== 1) {
173
+ return w ? `${this.x},${this.y};${this.w}` : `${this.x},${this.y}`;
270
174
  }
271
- toVec2() {
272
- return [this.x, this.y, this.w];
175
+ get [Symbol.toStringTag]() {
176
+ return "Vec2";
177
+ }
178
+ [NodeJSCustomInspect]() {
179
+ return `Vec2 <${this.toString()}>`;
180
+ }
181
+ toSize() {
182
+ return [this.x, this.y];
183
+ }
184
+ toVec3(z = 0) {
185
+ return [this.x, this.y, z, this.w];
186
+ }
187
+ toRGB() {
188
+ const vec = this.normalize();
189
+ return [vec.x, vec.y, vec.w];
190
+ }
191
+ toRGBA() {
192
+ const vec = this.normalize();
193
+ return [vec.x, vec.y, vec.w, 1];
194
+ }
195
+ toHSL() {
196
+ const vec = this.normalize();
197
+ return [vec.x, vec.y, vec.w];
198
+ }
199
+ toHSLA() {
200
+ const vec = this.normalize();
201
+ return [vec.x, vec.y, vec.w, 1];
273
202
  }
274
203
  clone() {
275
- return new _Vec3(this.x, this.y, this.z, this.w);
204
+ return new _Vec2(this.x, this.y, this.w);
276
205
  }
277
- equals(vec) {
278
- const a = _Vec3.resolve(vec);
279
- return this.x == a.x && this.y == a.y && this.z == a.z;
206
+ equals(...args) {
207
+ const a = _Vec2.resolveArgs(args);
208
+ return this.x == a.x && this.y == a.y;
280
209
  }
281
210
  setX(x) {
282
211
  this.x = x;
@@ -286,319 +215,125 @@ var Vec3 = class _Vec3 {
286
215
  this.y = y;
287
216
  return this;
288
217
  }
289
- setZ(z) {
290
- this.z = z;
218
+ setW(w) {
219
+ this.w = w;
291
220
  return this;
292
221
  }
293
222
  set(...args) {
294
- const vec = _Vec3.resolveArgs(args);
295
- return this.setX(vec.x).setY(vec.y).setZ(vec.z);
223
+ const vec = _Vec2.resolveArgs(args);
224
+ return this.setX(vec.x).setY(vec.y);
296
225
  }
297
226
  add(...args) {
298
- const vec = _Vec3.resolveArgs(args);
299
- return new _Vec3(
227
+ const vec = _Vec2.resolveArgs(args);
228
+ return new _Vec2(
300
229
  this.x + vec.x,
301
- this.y + vec.y,
302
- this.z + vec.z
230
+ this.y + vec.y
303
231
  );
304
232
  }
305
233
  offset(...args) {
306
- const vec = _Vec3.resolveArgs(args);
234
+ const vec = _Vec2.resolveArgs(args);
307
235
  this.x += vec.x;
308
236
  this.y += vec.y;
309
- this.z += vec.z;
310
237
  return this;
311
238
  }
312
239
  subtract(...args) {
313
- const vec = _Vec3.resolveArgs(args);
314
- return new _Vec3(
240
+ const vec = _Vec2.resolveArgs(args);
241
+ return new _Vec2(
315
242
  this.x - vec.x,
316
- this.y - vec.y,
317
- this.z - vec.z
243
+ this.y - vec.y
318
244
  );
319
245
  }
320
246
  multiply(scalar) {
321
- return new _Vec3(
247
+ return new _Vec2(
322
248
  this.x * scalar,
323
- this.y * scalar,
324
- this.z * scalar
249
+ this.y * scalar
325
250
  );
326
251
  }
327
252
  naiveMultiply(...args) {
328
- const vec = _Vec3.resolveArgs(args);
329
- return new _Vec3(
253
+ const vec = _Vec2.resolveArgs(args);
254
+ return new _Vec2(
330
255
  this.x * vec.x,
331
- this.y * vec.y,
332
- this.z * vec.z
256
+ this.y * vec.y
333
257
  );
334
258
  }
335
259
  divide(...args) {
336
- if (check_number_array(args, 1))
337
- return new _Vec3(
260
+ if (checkNumberArray(args, 1))
261
+ return new _Vec2(
338
262
  this.x / args[0],
339
- this.y / args[0],
340
- this.z / args[0]
263
+ this.y / args[0]
341
264
  );
342
- const vec = _Vec3.resolveArgs(args);
343
- return new _Vec3(
265
+ const vec = _Vec2.resolveArgs(args);
266
+ return new _Vec2(
344
267
  this.x / vec.x,
345
- this.y / vec.y,
346
- this.z / vec.z
268
+ this.y / vec.y
347
269
  );
348
270
  }
349
271
  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
- );
272
+ const vec = _Vec2.resolveArgs(args);
273
+ return this.x * vec.x + this.y * vec.y;
360
274
  }
361
275
  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);
276
+ const vec = _Vec2.resolveArgs(args);
277
+ return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2);
364
278
  }
365
279
  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));
280
+ const vec = _Vec2.resolveArgs(args);
281
+ return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2));
368
282
  }
369
283
  length() {
370
- return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
284
+ return Math.sqrt(this.x * this.x + this.y * this.y);
285
+ }
286
+ cartesianify() {
287
+ return new _Vec2(
288
+ this.x * Math.cos(this.y),
289
+ this.x * Math.sin(this.y)
290
+ );
291
+ }
292
+ polarify() {
293
+ return new _Vec2(
294
+ Math.sqrt(this.x * this.x + this.y * this.y),
295
+ Math.atan(this.y / this.x)
296
+ );
371
297
  }
372
298
  normalize() {
373
299
  const length = this.length();
374
- if (length == 0) return new _Vec3();
375
- return new _Vec3(
300
+ if (length == 0) return _Vec2.zero;
301
+ return new _Vec2(
376
302
  this.x / length,
377
303
  this.y / length,
378
- this.z / length
304
+ this.w / length
379
305
  );
380
306
  }
381
307
  invert() {
382
308
  return this.multiply(-1);
383
309
  }
384
310
  round() {
385
- return new _Vec3(Math.round(this.x), Math.round(this.y), Math.round(this.z), Math.round(this.w));
311
+ return new _Vec2(Math.round(this.x), Math.round(this.y), Math.round(this.w));
386
312
  }
387
313
  };
388
314
 
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
- }
315
+ // source/algebra/linear.ts
316
+ var LinearFunction = class extends MathFunction {
317
+ /**
318
+ * The factor of the linear function
319
+ */
320
+ m;
321
+ /**
322
+ * The height of the linear function
323
+ */
324
+ b;
325
+ /**
326
+ * Create a linear function from two points
327
+ * @param a A point
328
+ * @param b A point
329
+ * @returns A linear function from two points
330
+ */
427
331
  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);
332
+ const veca = Vec2.resolve(a);
333
+ const vecb = Vec2.resolve(b);
334
+ const m = (vecb.y - veca.y) / (vecb.x - veca.x);
335
+ const h = -m * veca.x + veca.y;
336
+ return new this(m, h);
602
337
  }
603
338
  /**
604
339
  * Create a linear function with a factor and height
@@ -607,30 +342,36 @@ var LinearFunction = class extends MathFunction {
607
342
  */
608
343
  constructor(m, b) {
609
344
  super();
610
- if (!check_number(m))
345
+ if (!checkNumber(m))
611
346
  throw new TypeError("expected number for m");
612
- if (!check_number(b))
347
+ if (!checkNumber(b))
613
348
  throw new TypeError("expected number for b");
614
349
  this.m = m;
615
350
  this.b = b;
616
351
  }
617
352
  get(x) {
618
- if (!check_number(x))
353
+ if (!checkNumber(x))
619
354
  throw new TypeError("expected number for x");
620
355
  return this.m;
621
356
  }
622
357
  roots() {
623
358
  const x = -this.b / this.m;
624
359
  if (!isNaN(x))
625
- return [new Vec2(x)];
360
+ return [new Vec2(x, 0)];
626
361
  return [];
627
362
  }
628
363
  toString() {
629
- const bsign = sign_char(this.b);
364
+ const bsign = signCharacter(this.b);
630
365
  if (bsign)
631
366
  return `f(x) = ${this.m} * x ${bsign} ${Math.abs(this.b)}`;
632
367
  return `f(x) = ${this.m} * x`;
633
368
  }
369
+ get [Symbol.toStringTag]() {
370
+ return "LinearFunction";
371
+ }
372
+ [NodeJSCustomInspect]() {
373
+ return `LinearFunction <${this.toString()}>`;
374
+ }
634
375
  };
635
376
 
636
377
  // source/algebra/quad.ts
@@ -643,20 +384,20 @@ var QuadFunction = class extends MathFunction {
643
384
  }
644
385
  constructor(a, b, c) {
645
386
  super();
646
- if (!check_number(a))
387
+ if (!checkNumber(a))
647
388
  throw new TypeError("expected number for a");
648
389
  if (a == 0)
649
390
  throw new TypeError("a cannot be 0");
650
- if (!check_number(b))
391
+ if (!checkNumber(b))
651
392
  throw new TypeError("expected number for b");
652
- if (!check_number(c))
393
+ if (!checkNumber(c))
653
394
  throw new TypeError("expected number for c");
654
395
  this.a = a;
655
396
  this.b = b;
656
397
  this.c = c;
657
398
  }
658
399
  get(x) {
659
- if (!check_number(x))
400
+ if (!checkNumber(x))
660
401
  throw new TypeError("expected number for x");
661
402
  return this.a * x * x + this.b * x + this.c;
662
403
  }
@@ -666,17 +407,17 @@ var QuadFunction = class extends MathFunction {
666
407
  const n0 = (-this.b + Math.sqrt(discriminant)) / (2 * this.a);
667
408
  const n1 = (-this.b + Math.sqrt(discriminant)) / (2 * this.a);
668
409
  if (!isNaN(n0))
669
- roots.push(new Vec2(n0));
410
+ roots.push(new Vec2(n0, 0));
670
411
  if (!isNaN(n1) && n0 != n1)
671
- roots.push(new Vec2(n1));
412
+ roots.push(new Vec2(n1, 0));
672
413
  return roots;
673
414
  }
674
415
  toString(type = "standard") {
675
416
  switch (type) {
676
417
  default:
677
418
  case "standard": {
678
- const bsign = sign_char(this.b);
679
- const csign = sign_char(this.c);
419
+ const bsign = signCharacter(this.b);
420
+ const csign = signCharacter(this.c);
680
421
  if (bsign && csign)
681
422
  return `f(x) = ${this.a}x^2 ${bsign} ${Math.abs(this.b)}x ${csign} ${Math.abs(this.c)}`;
682
423
  if (bsign)
@@ -685,17 +426,18 @@ var QuadFunction = class extends MathFunction {
685
426
  }
686
427
  }
687
428
  }
429
+ get [Symbol.toStringTag]() {
430
+ return "QuadFunction";
431
+ }
432
+ [NodeJSCustomInspect]() {
433
+ return `QuadFunction <${this.toString()}>`;
434
+ }
688
435
  };
689
436
 
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
437
  // source/crypto/hash.ts
696
438
  var DJB2_OFFSET = 5381n;
697
439
  function djb2(value) {
698
- const string = stringify(value);
440
+ const string = String(value);
699
441
  let hash = DJB2_OFFSET;
700
442
  for (let i = 0; i < string.length; i++) {
701
443
  hash = (hash << 5n) + hash + BigInt(string.charCodeAt(i));
@@ -705,7 +447,7 @@ function djb2(value) {
705
447
  var FNV1_OFFSET = 14695981039346656037n;
706
448
  var FNV1_PRIME = 1099511628211n;
707
449
  function fnv1(value) {
708
- const string = stringify(value);
450
+ const string = String(value);
709
451
  let hash = FNV1_OFFSET;
710
452
  for (let i = 0; i < string.length; i++) {
711
453
  hash *= FNV1_PRIME;
@@ -714,7 +456,7 @@ function fnv1(value) {
714
456
  return hash;
715
457
  }
716
458
  function sdbm(value) {
717
- const string = stringify(value);
459
+ const string = String(value);
718
460
  let hash = 0n;
719
461
  for (let i = 0; i < string.length; i++) {
720
462
  hash = BigInt(string.charCodeAt(i)) + (hash << 6n) + (hash << 16n) - hash;
@@ -1031,14 +773,23 @@ var MD2 = class _MD2 {
1031
773
  this._transform(this._checksum);
1032
774
  return this._state.slice();
1033
775
  }
776
+ toString() {
777
+ return "";
778
+ }
779
+ get [Symbol.toStringTag]() {
780
+ return "MD2";
781
+ }
782
+ [NodeJSCustomInspect]() {
783
+ return `MD2 <${this.toString()}>`;
784
+ }
1034
785
  };
1035
786
 
1036
787
  // source/geometry/angle.ts
1037
788
  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);
789
+ var clampAngleDegree = (angle) => angle % MAX_ANGLE_DEGREE;
790
+ var clampAngleRadian = (angle) => clampAngleDegree(degreeToRadian(angle));
791
+ var radianToDegree = (angle) => angle * (180 / Math.PI);
792
+ var degreeToRadian = (angle) => angle * (Math.PI / 180);
1042
793
 
1043
794
  // source/geometry/circle.ts
1044
795
  var Circle = class _Circle {
@@ -1074,19 +825,28 @@ var Circle = class _Circle {
1074
825
  return value;
1075
826
  throw new ResolveError("Circle", a);
1076
827
  }
828
+ static resolveArgs(args) {
829
+ if (checkNumberArray(args, 3))
830
+ return new this([args[0], args[1]], args[2]);
831
+ if (args.length === 2)
832
+ return new this(args[0], args[1]);
833
+ return this.resolve(args[0]);
834
+ }
1077
835
  static cast(a) {
1078
836
  if (a == null || typeof a == "undefined")
1079
837
  return void 0;
1080
- if (check_number_array(a, 3))
838
+ if (checkNumberArray(a, 3))
1081
839
  return new this([a[0], a[1]], a[2]);
1082
- if (check_number_array(a, 4)) {
840
+ if (checkNumberArray(a, 4)) {
1083
841
  const c = new this([a[0], a[1]], a[3]);
1084
842
  c.w = a[2];
1085
843
  return c;
1086
844
  }
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)) {
845
+ if (hasProperty(a, "toCircle", "function"))
846
+ return this.cast(a.toCircle());
847
+ if (hasProperty(a, "x", "number") && hasProperty(a, "y", "number") && hasProperty(a, "radius", "number"))
848
+ return new this(hasProperty(a, "w", "number") ? [a.x, a.y, a.w] : [a.x, a.y], a.radius);
849
+ if (checkString(a)) {
1090
850
  const [spos, sradius] = a.split("|");
1091
851
  const pos = Vec2.cast(spos);
1092
852
  if (typeof pos == "undefined")
@@ -1102,7 +862,7 @@ var Circle = class _Circle {
1102
862
  }
1103
863
  constructor(position, radius) {
1104
864
  this.position = Vec2.resolve(position);
1105
- if (!check_number(radius))
865
+ if (!checkNumber(radius))
1106
866
  throw new TypeError("expected number for radius");
1107
867
  this.radius = radius;
1108
868
  }
@@ -1118,22 +878,246 @@ var Circle = class _Circle {
1118
878
  toString() {
1119
879
  return `${this.position.toString()}|${this.radius}`;
1120
880
  }
881
+ get [Symbol.toStringTag]() {
882
+ return "Circle";
883
+ }
884
+ [NodeJSCustomInspect]() {
885
+ return `Circle <${this.toString()}>`;
886
+ }
1121
887
  clone() {
1122
888
  return new _Circle(this.position.clone(), this.radius);
1123
889
  }
1124
- equals(circle) {
1125
- const c = _Circle.resolve(circle);
890
+ toVec2() {
891
+ return [this.x, this.y, this.w];
892
+ }
893
+ equals(...args) {
894
+ const c = _Circle.resolveArgs(args);
1126
895
  return c.position.equals(c.position) && this.radius == c.radius;
1127
896
  }
1128
- inside(a) {
1129
- const circle = _Circle.resolve(a);
897
+ inside(...args) {
898
+ const circle = _Circle.resolveArgs(args);
1130
899
  const distX = circle.x - this.x;
1131
900
  const distY = circle.y - this.y;
1132
901
  const dist = Math.sqrt(distX * distX + (distY + distY));
1133
902
  return dist <= this.radius + circle.radius;
1134
903
  }
1135
- insidePoint(a) {
1136
- return this.position.distance(a) <= this.radius;
904
+ insidePoint(...args) {
905
+ return this.position.distance(Vec2.resolveArgs(args)) <= this.radius;
906
+ }
907
+ };
908
+
909
+ // source/geometry/bbox.ts
910
+ var BoundingBox = class _BoundingBox {
911
+ left;
912
+ right;
913
+ top;
914
+ bottom;
915
+ get width() {
916
+ return this.right - this.left;
917
+ }
918
+ set width(val) {
919
+ this.right = this.left + val;
920
+ }
921
+ get height() {
922
+ return this.bottom - this.top;
923
+ }
924
+ set height(val) {
925
+ this.bottom = this.top + val;
926
+ }
927
+ get x() {
928
+ return this.left;
929
+ }
930
+ set x(x) {
931
+ this.left = x;
932
+ }
933
+ get y() {
934
+ return this.top;
935
+ }
936
+ set y(y) {
937
+ this.top = y;
938
+ }
939
+ w = 1;
940
+ static resolve(a) {
941
+ const value = this.cast(a);
942
+ if (typeof value != "undefined")
943
+ return value;
944
+ throw new ResolveError("BoundingBox", a);
945
+ }
946
+ static resolveArgs(args) {
947
+ if (checkNumberArray(args, 4))
948
+ return new this(args[0], args[1], args[2], args[3]);
949
+ return this.resolve(args[0]);
950
+ }
951
+ static cast(a) {
952
+ if (a == null || typeof a == "undefined")
953
+ return void 0;
954
+ if (checkNumberArray(a, 4))
955
+ return new this(a[0], a[1], a[2], a[3]);
956
+ if (hasProperty(a, "toBoundingBox", "function"))
957
+ return this.cast(a.toBoundingBox());
958
+ if (hasProperty(a, "left", "number") && hasProperty(a, "right", "number") && hasProperty(a, "top", "number") && hasProperty(a, "bottom", "number"))
959
+ return new this(a.left, a.right, a.top, a.bottom);
960
+ if (checkString(a)) {
961
+ const parts = a.split(",");
962
+ if (checkStringArray(parts, 4))
963
+ return this.cast(parts.map((v) => parseFloat(v)));
964
+ }
965
+ return void 0;
966
+ }
967
+ static is(a) {
968
+ return typeof this.cast(a) != "undefined";
969
+ }
970
+ constructor(left, right, top, bottom) {
971
+ if (!checkNumber(left))
972
+ throw new TypeError("expected number for left");
973
+ if (!checkNumber(right))
974
+ throw new TypeError("expected number for right");
975
+ if (!checkNumber(top))
976
+ throw new TypeError("expected number for top");
977
+ if (!checkNumber(bottom))
978
+ throw new TypeError("expected number for bottom");
979
+ this.left = left;
980
+ this.right = right;
981
+ this.top = top;
982
+ this.bottom = bottom;
983
+ }
984
+ toArray() {
985
+ return [this.left, this.right, this.top, this.bottom];
986
+ }
987
+ toString() {
988
+ return `${this.left},${this.right},${this.top},${this.bottom}`;
989
+ }
990
+ get [Symbol.toStringTag]() {
991
+ return "BoundingBox";
992
+ }
993
+ [NodeJSCustomInspect]() {
994
+ return `BoundingBox <${this.toString()}>`;
995
+ }
996
+ toJSON() {
997
+ return {
998
+ left: this.left,
999
+ top: this.top,
1000
+ right: this.right,
1001
+ bottom: this.bottom
1002
+ };
1003
+ }
1004
+ clone() {
1005
+ return new _BoundingBox(this.left, this.right, this.top, this.bottom);
1006
+ }
1007
+ equals(...args) {
1008
+ const b = _BoundingBox.resolveArgs(args);
1009
+ return this.left === b.left && this.right === b.right && this.top === b.top && this.bottom === b.bottom;
1010
+ }
1011
+ toSize() {
1012
+ return [this.width, this.height];
1013
+ }
1014
+ toVec2() {
1015
+ return [this.left, this.top];
1016
+ }
1017
+ toRectangle() {
1018
+ return [this.left, this.top, this.width, this.height];
1019
+ }
1020
+ inside(...args) {
1021
+ const bbox = _BoundingBox.resolve(args);
1022
+ return this.right >= bbox.left && bbox.right >= this.left && this.bottom >= bbox.top && bbox.bottom >= this.top;
1023
+ }
1024
+ insidePoint(...args) {
1025
+ const point = Vec2.resolveArgs(args);
1026
+ return this.left <= point.x && this.right >= point.x && this.top <= point.y && this.bottom >= point.y;
1027
+ }
1028
+ insideCircle(...args) {
1029
+ const circle = Circle.resolveArgs(args);
1030
+ const center = Vec2.resolve(circle).add(circle.radius);
1031
+ const bboxhe = new Vec2(this.width / 2, this.height / 2);
1032
+ const bboxcenter = new Vec2(this.left + bboxhe.x, this.top + bboxhe.y);
1033
+ let diff = center.subtract(bboxcenter);
1034
+ const clamped = Vec2.clamp(diff, bboxhe.invert(), bboxhe);
1035
+ const closest = bboxcenter.add(clamped);
1036
+ diff = closest.subtract(center);
1037
+ return diff.length() < circle.radius;
1038
+ }
1039
+ };
1040
+
1041
+ // source/geometry/size.ts
1042
+ var Size = class _Size {
1043
+ width;
1044
+ height;
1045
+ get aspectRatio() {
1046
+ return this.height / this.width;
1047
+ }
1048
+ get area() {
1049
+ return this.width * this.height;
1050
+ }
1051
+ get perimeter() {
1052
+ return this.width + this.width + this.height + this.height;
1053
+ }
1054
+ static resolve(a) {
1055
+ const value = this.cast(a);
1056
+ if (typeof value != "undefined")
1057
+ return value;
1058
+ throw new ResolveError("Square", a);
1059
+ }
1060
+ static resolveArgs(args) {
1061
+ if (checkNumberArray(args, 2))
1062
+ return new this(args[0], args[1]);
1063
+ return this.resolve(args[0]);
1064
+ }
1065
+ static cast(a) {
1066
+ if (a == null || typeof a == "undefined")
1067
+ return void 0;
1068
+ if (checkNumberArray(a, 2))
1069
+ return new this(a[0], a[1]);
1070
+ if (hasProperty(a, "toSize", "function"))
1071
+ return this.cast(a.toSize());
1072
+ if (hasProperty(a, "width", "number") && hasProperty(a, "height", "number"))
1073
+ return new this(a.width, a.height);
1074
+ if (checkString(a)) {
1075
+ const parts = a.split("x").map((v) => parseFloat(v));
1076
+ if (checkNumberArray(parts, 2))
1077
+ return this.cast(parts);
1078
+ }
1079
+ if (checkNumber(a))
1080
+ return new this(a, a);
1081
+ return void 0;
1082
+ }
1083
+ static is(a) {
1084
+ return typeof this.cast(a) != "undefined";
1085
+ }
1086
+ constructor(width, height) {
1087
+ if (!checkNumber(width))
1088
+ throw new TypeError("expected number for width");
1089
+ if (!checkNumber(height))
1090
+ throw new TypeError("expected number for height");
1091
+ this.width = width;
1092
+ this.height = height;
1093
+ }
1094
+ toArray() {
1095
+ return [this.width, this.height];
1096
+ }
1097
+ toString() {
1098
+ return `${this.width}x${this.height}`;
1099
+ }
1100
+ get [Symbol.toStringTag]() {
1101
+ return "Size";
1102
+ }
1103
+ [NodeJSCustomInspect]() {
1104
+ return `Size <${this.toString()}>`;
1105
+ }
1106
+ toJSON() {
1107
+ return {
1108
+ width: this.width,
1109
+ height: this.height
1110
+ };
1111
+ }
1112
+ clone() {
1113
+ return new _Size(this.width, this.height);
1114
+ }
1115
+ equals(...args) {
1116
+ const s = _Size.resolveArgs(args);
1117
+ return this.width == s.width && this.height == s.height;
1118
+ }
1119
+ toVec2() {
1120
+ return [this.width, this.height];
1137
1121
  }
1138
1122
  };
1139
1123
 
@@ -1183,29 +1167,36 @@ var Rectangle = class _Rectangle {
1183
1167
  return value;
1184
1168
  throw new ResolveError("Rectangle", a);
1185
1169
  }
1170
+ static resolveArgs(args) {
1171
+ if (checkNumberArray(args, 4))
1172
+ return new this([args[0], args[1]], [args[2], args[3]]);
1173
+ return this.resolve(args[0]);
1174
+ }
1186
1175
  static cast(a) {
1187
1176
  if (a == null || typeof a == "undefined")
1188
1177
  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]);
1178
+ if (checkNumberArray(a, 4))
1179
+ return new this([a[0], a[1]], [a[2], a[3]]);
1180
+ if (checkNumberArray(a, 5)) {
1181
+ const rect = new this([a[0], a[1]], [a[3], a[4]]);
1193
1182
  rect.w = a[2];
1194
1183
  return rect;
1195
1184
  }
1196
- if (check_string(a)) {
1185
+ if (checkString(a)) {
1197
1186
  const [spos, ssize] = a.split("|");
1198
1187
  const pos = Vec2.cast(spos);
1199
1188
  const size = Size.cast(ssize);
1200
1189
  if (typeof pos == "undefined" || typeof size == "undefined")
1201
1190
  return void 0;
1202
- const rect = new this(pos.x, pos.y, size.width, size.height);
1191
+ const rect = new this([pos.x, pos.y], [size.width, size.height]);
1203
1192
  rect.w = pos.w;
1204
1193
  return rect;
1205
1194
  }
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"))
1195
+ if (hasProperty(a, "toRectangle", "function"))
1196
+ return this.cast(a.toRectangle());
1197
+ if (hasProperty(a, "x", "number") && hasProperty(a, "y", "number") && hasProperty(a, "width", "number") && hasProperty(a, "height", "number")) {
1198
+ const rect = new this([a.x, a.y], [a.width, a.height]);
1199
+ if (hasProperty(a, "w", "number"))
1209
1200
  rect.w = a.w;
1210
1201
  return rect;
1211
1202
  }
@@ -1214,150 +1205,290 @@ var Rectangle = class _Rectangle {
1214
1205
  static is(a) {
1215
1206
  return typeof this.cast(a) != "undefined";
1216
1207
  }
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);
1208
+ constructor(pos, size) {
1209
+ this.position = Vec2.resolve(pos);
1210
+ this.size = Size.resolve(size);
1234
1211
  }
1235
- toArray(w = false) {
1212
+ toArray(w = this.w !== 1) {
1236
1213
  return [...this.position.toArray(w), ...this.size.toArray()];
1237
1214
  }
1238
- toString(w = false) {
1215
+ toString(w = this.w !== 1) {
1239
1216
  return `${this.position.toString(w)}|${this.size.toString()}`;
1240
1217
  }
1218
+ get [Symbol.toStringTag]() {
1219
+ return "Rectangle";
1220
+ }
1221
+ [NodeJSCustomInspect]() {
1222
+ return `Rectangle <${this.toString()}>`;
1223
+ }
1241
1224
  toJSON() {
1242
1225
  return { ...this.position.toJSON(), ...this.size.toJSON() };
1243
1226
  }
1244
1227
  toBoundingBox() {
1245
1228
  return [this.x, this.x + this.width, this.y, this.y + this.height];
1246
1229
  }
1230
+ toVec2() {
1231
+ return [this.x, this.y, this.w];
1232
+ }
1233
+ toSize() {
1234
+ return [this.width, this.height];
1235
+ }
1247
1236
  clone() {
1248
1237
  return new _Rectangle(this.position.clone(), this.size.clone());
1249
1238
  }
1250
- equals(rectangle) {
1251
- const rect = _Rectangle.resolve(rectangle);
1239
+ equals(...args) {
1240
+ const rect = _Rectangle.resolveArgs(args);
1252
1241
  return this.position.equals(rect.position) && this.size.equals(rect.size);
1253
1242
  }
1254
1243
  };
1255
1244
 
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;
1245
+ // source/common/string.ts
1246
+ function stringify(value) {
1247
+ return value != null && typeof value == "object" && "toString" in value && typeof value.toString == "function" ? value.toString() : String(value);
1248
+ }
1249
+
1250
+ // source/vectors/vec3.ts
1251
+ var Vec3 = class _Vec3 {
1252
+ x;
1253
+ y;
1254
+ z;
1255
+ w;
1256
+ static resolve(a) {
1257
+ const value = this.cast(a);
1258
+ if (typeof value != "undefined")
1259
+ return value;
1260
+ throw new ResolveError("Vec3", a);
1261
+ }
1262
+ static cast(a) {
1263
+ if (a == null || typeof a == "undefined")
1264
+ return void 0;
1265
+ if (checkNumberArray(a, 3) || checkNumberArray(a, 4))
1266
+ return new this(a[0], a[1], a[2], checkNumber(a[3]) ? a[3] : void 0);
1267
+ if (hasProperty(a, "x", "number") && hasProperty(a, "y", "number") && hasProperty(a, "z", "number"))
1268
+ return new this(a.x, a.y, a.z, hasProperty(a, "w", "number") ? a.w : void 0);
1269
+ if (checkString(a)) {
1270
+ const [sxyz, sw] = a.split(";");
1271
+ if (checkString(sxyz)) {
1272
+ const parts = sxyz.split(",");
1273
+ if (checkStringArray(parts, 3))
1274
+ return new this(parseFloat(parts[0]), parseFloat(parts[1]), parseFloat(parts[2]), checkString(sw) ? parseFloat(sw) : void 0);
1275
+ }
1276
+ }
1277
+ if (checkNumber(a))
1278
+ return new this(a, a, a);
1279
+ return void 0;
1280
+ }
1281
+ static resolveArgs(args) {
1282
+ if (checkNumberArray(args, 3))
1283
+ return new this(args[0], args[1], args[2]);
1284
+ return this.resolve(args[0]);
1285
+ }
1286
+ static is(a) {
1287
+ return typeof this.cast(a) != "undefined";
1288
+ }
1289
+ static fromPoints(a, b) {
1290
+ const veca = this.resolve(a);
1291
+ const vecb = this.resolve(b);
1292
+ return new this(vecb.x - veca.x, vecb.y - veca.y, vecb.z - veca.z);
1293
+ }
1294
+ static clamp(value, min, max) {
1295
+ const a = this.resolve(value), b = this.resolve(min), c = this.resolve(max);
1296
+ return new this(
1297
+ clamp(a.x, b.x, c.x),
1298
+ clamp(a.y, b.y, c.y),
1299
+ clamp(a.z, b.z, c.z)
1300
+ );
1301
+ }
1302
+ static intersectPlane(planeP, planeN, lineStart, lineEnd, t) {
1303
+ planeN = this.resolve(planeN).normalize();
1304
+ const plane_d = -this.resolve(planeN).dot(planeP);
1305
+ const ad = this.resolve(lineStart).dot(planeN);
1306
+ const bd = this.resolve(lineEnd).dot(planeN);
1307
+ t = (-plane_d - ad) / (bd - ad);
1308
+ const lineStartToEnd = this.resolve(lineEnd).subtract(lineStart);
1309
+ const linetoIntersect = lineStartToEnd.multiply(t);
1310
+ return _Vec3.resolve(lineStart).add(linetoIntersect);
1311
+ }
1312
+ static get zero() {
1313
+ return new this(0, 0, 0);
1314
+ }
1315
+ static get one() {
1316
+ return new this(1, 1, 1);
1317
+ }
1318
+ constructor(x, y, z, w = 1) {
1319
+ if (!checkNumber(x))
1320
+ throw new TypeError("expected number for x");
1321
+ if (!checkNumber(y))
1322
+ throw new TypeError("expected number for y");
1323
+ if (!checkNumber(z))
1324
+ throw new TypeError("expected number for z");
1325
+ if (!checkNumber(w))
1326
+ throw new TypeError("expected number for w");
1327
+ this.x = x;
1328
+ this.y = y;
1329
+ this.z = z;
1330
+ this.w = w;
1331
+ }
1332
+ toArray(w = this.w !== 1) {
1333
+ return w ? [this.x, this.y, this.z, this.w] : [this.x, this.y, this.z];
1334
+ }
1335
+ toJSON() {
1336
+ return {
1337
+ x: this.x,
1338
+ y: this.y,
1339
+ z: this.z,
1340
+ w: this.w
1341
+ };
1342
+ }
1343
+ toString(w = this.w !== 1) {
1344
+ return w ? `${this.x},${this.y},${this.z};${this.w}` : `${this.x},${this.y},${this.z}`;
1345
+ }
1346
+ get [Symbol.toStringTag]() {
1347
+ return "Vec3";
1348
+ }
1349
+ [NodeJSCustomInspect]() {
1350
+ return `Vec3 <${this.toString()}>`;
1351
+ }
1352
+ toVec2() {
1353
+ return [this.x, this.y, this.w];
1354
+ }
1355
+ toRGB() {
1356
+ const vec = this.normalize();
1357
+ return [vec.x, vec.y, vec.z];
1358
+ }
1359
+ toRGBA() {
1360
+ const vec = this.normalize();
1361
+ return [vec.x, vec.y, vec.z, vec.w];
1362
+ }
1363
+ toHSL() {
1364
+ const vec = this.normalize();
1365
+ return [vec.x, vec.y, vec.z];
1366
+ }
1367
+ toHSLA() {
1368
+ const vec = this.normalize();
1369
+ return [vec.x, vec.y, vec.z, vec.w];
1264
1370
  }
1265
- set width(val) {
1266
- this.right = this.left + val;
1371
+ toQuaternion() {
1372
+ return [this.w, this.x, this.y, this.z];
1267
1373
  }
1268
- get height() {
1269
- return this.bottom - this.top;
1374
+ clone() {
1375
+ return new _Vec3(this.x, this.y, this.z, this.w);
1270
1376
  }
1271
- set height(val) {
1272
- this.bottom = this.top + val;
1377
+ equals(...args) {
1378
+ const a = _Vec3.resolveArgs(args);
1379
+ return this.x == a.x && this.y == a.y && this.z == a.z;
1273
1380
  }
1274
- static resolve(a) {
1275
- const value = this.cast(a);
1276
- if (typeof value != "undefined")
1277
- return value;
1278
- throw new ResolveError("BoundingBox", a);
1381
+ setX(x) {
1382
+ this.x = x;
1383
+ return this;
1279
1384
  }
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;
1385
+ setY(y) {
1386
+ this.y = y;
1387
+ return this;
1293
1388
  }
1294
- static is(a) {
1295
- return typeof this.cast(a) != "undefined";
1389
+ setZ(z) {
1390
+ this.z = z;
1391
+ return this;
1296
1392
  }
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;
1393
+ set(...args) {
1394
+ const vec = _Vec3.resolveArgs(args);
1395
+ return this.setX(vec.x).setY(vec.y).setZ(vec.z);
1310
1396
  }
1311
- toArray() {
1312
- return [this.left, this.right, this.top, this.bottom];
1397
+ add(...args) {
1398
+ const vec = _Vec3.resolveArgs(args);
1399
+ return new _Vec3(
1400
+ this.x + vec.x,
1401
+ this.y + vec.y,
1402
+ this.z + vec.z
1403
+ );
1313
1404
  }
1314
- toString() {
1315
- return `${this.left},${this.right},${this.top},${this.bottom}`;
1405
+ offset(...args) {
1406
+ const vec = _Vec3.resolveArgs(args);
1407
+ this.x += vec.x;
1408
+ this.y += vec.y;
1409
+ this.z += vec.z;
1410
+ return this;
1316
1411
  }
1317
- toJSON() {
1318
- return {
1319
- left: this.left,
1320
- top: this.top,
1321
- right: this.right,
1322
- bottom: this.bottom
1323
- };
1412
+ subtract(...args) {
1413
+ const vec = _Vec3.resolveArgs(args);
1414
+ return new _Vec3(
1415
+ this.x - vec.x,
1416
+ this.y - vec.y,
1417
+ this.z - vec.z
1418
+ );
1324
1419
  }
1325
- clone() {
1326
- return new _BoundingBox(this.left, this.right, this.top, this.bottom);
1420
+ multiply(scalar) {
1421
+ return new _Vec3(
1422
+ this.x * scalar,
1423
+ this.y * scalar,
1424
+ this.z * scalar
1425
+ );
1327
1426
  }
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;
1427
+ naiveMultiply(...args) {
1428
+ const vec = _Vec3.resolveArgs(args);
1429
+ return new _Vec3(
1430
+ this.x * vec.x,
1431
+ this.y * vec.y,
1432
+ this.z * vec.z
1433
+ );
1331
1434
  }
1332
- toSquare() {
1333
- return new Size(this.width, this.height);
1435
+ divide(...args) {
1436
+ if (checkNumberArray(args, 1))
1437
+ return new _Vec3(
1438
+ this.x / args[0],
1439
+ this.y / args[0],
1440
+ this.z / args[0]
1441
+ );
1442
+ const vec = _Vec3.resolveArgs(args);
1443
+ return new _Vec3(
1444
+ this.x / vec.x,
1445
+ this.y / vec.y,
1446
+ this.z / vec.z
1447
+ );
1334
1448
  }
1335
- toRectangle() {
1336
- return new Rectangle(this.left, this.top, this.width, this.height);
1449
+ dot(...args) {
1450
+ const vec = _Vec3.resolveArgs(args);
1451
+ return this.x * vec.x + this.y * vec.y + this.z * vec.z;
1337
1452
  }
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;
1453
+ cross(...args) {
1454
+ const vec = _Vec3.resolveArgs(args);
1455
+ return new _Vec3(
1456
+ this.y * vec.z - this.z * vec.y,
1457
+ this.z * vec.x - this.x * vec.z,
1458
+ this.x * vec.y - this.y * vec.x
1459
+ );
1341
1460
  }
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;
1461
+ distance(...args) {
1462
+ const vec = _Vec3.resolveArgs(args);
1463
+ return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2);
1345
1464
  }
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;
1465
+ distanceSquare(...args) {
1466
+ const vec = _Vec3.resolveArgs(args);
1467
+ return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2));
1468
+ }
1469
+ length() {
1470
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
1471
+ }
1472
+ normalize() {
1473
+ const length = this.length();
1474
+ if (length == 0) return _Vec3.zero;
1475
+ return new _Vec3(
1476
+ this.x / length,
1477
+ this.y / length,
1478
+ this.z / length,
1479
+ this.w / length
1480
+ );
1481
+ }
1482
+ invert() {
1483
+ return this.multiply(-1);
1484
+ }
1485
+ round() {
1486
+ return new _Vec3(Math.round(this.x), Math.round(this.y), Math.round(this.z), Math.round(this.w));
1356
1487
  }
1357
1488
  };
1358
1489
 
1359
1490
  // source/geometry/triangle.ts
1360
- var ATriangle = class {
1491
+ var Triangle = class {
1361
1492
  constructor(A, B, C) {
1362
1493
  this.A = A;
1363
1494
  this.B = B;
@@ -1387,8 +1518,17 @@ var ATriangle = class {
1387
1518
  get height() {
1388
1519
  return 2 * (this.area / this.base);
1389
1520
  }
1521
+ toString() {
1522
+ return `${stringify(this.A)}|${stringify(this.B)}|${stringify(this.C)}`;
1523
+ }
1524
+ get [Symbol.toStringTag]() {
1525
+ return "Triangle";
1526
+ }
1527
+ [NodeJSCustomInspect]() {
1528
+ return `Triangle <${this.toString()}>`;
1529
+ }
1390
1530
  };
1391
- var Triangle2D = class extends ATriangle {
1531
+ var Triangle2D = class extends Triangle {
1392
1532
  get a() {
1393
1533
  return Vec2.fromPoints(this.B, this.C).length();
1394
1534
  }
@@ -1399,7 +1539,7 @@ var Triangle2D = class extends ATriangle {
1399
1539
  return Vec2.fromPoints(this.A, this.B).length();
1400
1540
  }
1401
1541
  };
1402
- var Triangle3D = class extends ATriangle {
1542
+ var Triangle3D = class extends Triangle {
1403
1543
  get a() {
1404
1544
  return Vec3.fromPoints(this.B, this.C).length();
1405
1545
  }
@@ -1474,15 +1614,20 @@ var Mat3 = class _Mat3 {
1474
1614
  return value;
1475
1615
  throw new ResolveError("Mat3", a);
1476
1616
  }
1617
+ static resolveArgs(args) {
1618
+ if (checkNumberArray(args, 9))
1619
+ return new this(args);
1620
+ return this.resolve(args[0]);
1621
+ }
1477
1622
  static cast(a) {
1478
1623
  if (a == null || typeof a == "undefined")
1479
1624
  return void 0;
1480
- if (check_number_array(a, 9)) {
1625
+ if (checkNumberArray(a, 9)) {
1481
1626
  return new this(a);
1482
1627
  }
1483
- if (check_array(a, void 0, 3)) {
1628
+ if (checkArray(a, void 0, 3)) {
1484
1629
  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))
1630
+ if (checkNumberArray(row0, 3) && checkNumberArray(row1, 3) && checkNumberArray(row2, 3))
1486
1631
  return new this([
1487
1632
  row0[0],
1488
1633
  row0[1],
@@ -1495,12 +1640,14 @@ var Mat3 = class _Mat3 {
1495
1640
  row2[2]
1496
1641
  ]);
1497
1642
  }
1498
- if (check_string(a)) {
1643
+ if (checkString(a)) {
1499
1644
  const parts = a.split(",");
1500
- if (check_string_array(parts, 9))
1645
+ if (checkStringArray(parts, 9))
1501
1646
  return this.cast(parts.map((i) => parseFloat(i)));
1502
1647
  }
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"))
1648
+ if (hasProperty(a, "toMat3", "function"))
1649
+ return this.cast(a.toMat3());
1650
+ if (hasProperty(a, "m00", "number") && hasProperty(a, "m01", "number") && hasProperty(a, "m02", "number") && hasProperty(a, "m10", "number") && hasProperty(a, "m11", "number") && hasProperty(a, "m12", "number") && hasProperty(a, "m20", "number") && hasProperty(a, "m21", "number") && hasProperty(a, "m22", "number"))
1504
1651
  return new this([
1505
1652
  a.m00,
1506
1653
  a.m01,
@@ -1512,7 +1659,7 @@ var Mat3 = class _Mat3 {
1512
1659
  a.m21,
1513
1660
  a.m22
1514
1661
  ]);
1515
- if (check_number(a)) {
1662
+ if (checkNumber(a)) {
1516
1663
  return new this([a, a, a, a, a, a, a, a, a]);
1517
1664
  }
1518
1665
  return void 0;
@@ -1534,7 +1681,7 @@ var Mat3 = class _Mat3 {
1534
1681
  ]);
1535
1682
  }
1536
1683
  constructor(init = [1, 0, 0, 0, 1, 0, 0, 0, 1]) {
1537
- if (!check_number_array(init, 9))
1684
+ if (!checkNumberArray(init, 9))
1538
1685
  throw new TypeError("expected a number array with 9 elements");
1539
1686
  this._raw = init;
1540
1687
  }
@@ -1574,6 +1721,12 @@ var Mat3 = class _Mat3 {
1574
1721
  toString() {
1575
1722
  return `${this.m00},${this.m01},${this.m02},${this.m10},${this.m11},${this.m12},${this.m20},${this.m21},${this.m22}`;
1576
1723
  }
1724
+ get [Symbol.toStringTag]() {
1725
+ return "Mat3";
1726
+ }
1727
+ [NodeJSCustomInspect]() {
1728
+ return `Mat3 <${this.toString()}>`;
1729
+ }
1577
1730
  clone() {
1578
1731
  return new _Mat3([
1579
1732
  this.m00,
@@ -1587,41 +1740,41 @@ var Mat3 = class _Mat3 {
1587
1740
  this.m22
1588
1741
  ]);
1589
1742
  }
1590
- equals(mat) {
1591
- const m = _Mat3.resolve(mat);
1743
+ equals(...args) {
1744
+ const m = _Mat3.resolveArgs(args);
1592
1745
  for (let index = 0; index < this._raw.length; index++)
1593
1746
  if (this._raw[index] != m._raw[index])
1594
1747
  return false;
1595
1748
  return true;
1596
1749
  }
1597
- add(mat) {
1598
- const b = _Mat3.resolve(mat);
1750
+ add(...args) {
1751
+ const b = _Mat3.resolveArgs(args);
1599
1752
  const m = new _Mat3();
1600
1753
  for (let index = 0; index < this._raw.length; index++)
1601
1754
  m._raw[index] = this._raw[index] + b._raw[index];
1602
1755
  return m;
1603
1756
  }
1604
- subtract(mat) {
1605
- const b = _Mat3.resolve(mat);
1757
+ subtract(...args) {
1758
+ const b = _Mat3.resolveArgs(args);
1606
1759
  const m = new _Mat3();
1607
1760
  for (let index = 0; index < this._raw.length; index++)
1608
1761
  m._raw[index] = this._raw[index] - b._raw[index];
1609
1762
  return m;
1610
1763
  }
1611
- multiply(a) {
1612
- if (check_number(a))
1764
+ multiply(...args) {
1765
+ if (checkNumberArray(args, 1))
1613
1766
  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
1767
+ this.m00 * args[0],
1768
+ this.m01 * args[0],
1769
+ this.m02 * args[0],
1770
+ this.m10 * args[0],
1771
+ this.m11 * args[0],
1772
+ this.m12 * args[0],
1773
+ this.m20 * args[0],
1774
+ this.m21 * args[0],
1775
+ this.m22 * args[0]
1623
1776
  ]);
1624
- const b = _Mat3.resolve(a);
1777
+ const b = _Mat3.resolveArgs(args);
1625
1778
  return new _Mat3([
1626
1779
  b.m00 * this.m00 + b.m01 * this.m10 + b.m02 * this.m20,
1627
1780
  b.m00 * this.m01 + b.m01 * this.m11 + b.m02 * this.m21,
@@ -1821,15 +1974,20 @@ var Mat4 = class _Mat4 {
1821
1974
  return value;
1822
1975
  throw new ResolveError("Mat4", a);
1823
1976
  }
1977
+ static resolveArgs(args) {
1978
+ if (checkNumberArray(args, 16))
1979
+ return new this(args);
1980
+ return this.resolve(args[0]);
1981
+ }
1824
1982
  static cast(a) {
1825
1983
  if (a == null || typeof a == "undefined")
1826
1984
  return void 0;
1827
- if (check_number_array(a, 16)) {
1985
+ if (checkNumberArray(a, 16)) {
1828
1986
  return new this(a);
1829
1987
  }
1830
- if (check_array(a, void 0, 4)) {
1988
+ if (checkArray(a, void 0, 4)) {
1831
1989
  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))
1990
+ if (checkNumberArray(row0, 4) && checkNumberArray(row1, 4) && checkNumberArray(row2, 4) && checkNumberArray(row3, 4))
1833
1991
  return new this([
1834
1992
  row0[0],
1835
1993
  row0[1],
@@ -1849,12 +2007,14 @@ var Mat4 = class _Mat4 {
1849
2007
  row3[3]
1850
2008
  ]);
1851
2009
  }
1852
- if (check_string(a)) {
2010
+ if (checkString(a)) {
1853
2011
  const parts = a.split(",");
1854
- if (check_string_array(parts, 16))
2012
+ if (checkStringArray(parts, 16))
1855
2013
  return this.cast(parts.map((i) => parseFloat(i)));
1856
2014
  }
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"))
2015
+ if (hasProperty(a, "toMat4", "function"))
2016
+ return this.cast(a.toMat4());
2017
+ if (hasProperty(a, "m00", "number") && hasProperty(a, "m01", "number") && hasProperty(a, "m02", "number") && hasProperty(a, "m03", "number") && hasProperty(a, "m10", "number") && hasProperty(a, "m11", "number") && hasProperty(a, "m12", "number") && hasProperty(a, "m13", "number") && hasProperty(a, "m20", "number") && hasProperty(a, "m21", "number") && hasProperty(a, "m22", "number") && hasProperty(a, "m23", "number") && hasProperty(a, "m30", "number") && hasProperty(a, "m31", "number") && hasProperty(a, "m32", "number") && hasProperty(a, "m33", "number"))
1858
2018
  return new this([
1859
2019
  a.m00,
1860
2020
  a.m01,
@@ -1873,7 +2033,7 @@ var Mat4 = class _Mat4 {
1873
2033
  a.m32,
1874
2034
  a.m33
1875
2035
  ]);
1876
- if (check_number(a)) {
2036
+ if (checkNumber(a)) {
1877
2037
  return new this([a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a]);
1878
2038
  }
1879
2039
  return void 0;
@@ -1881,22 +2041,25 @@ var Mat4 = class _Mat4 {
1881
2041
  static is(a) {
1882
2042
  return typeof this.cast(a) != "undefined";
1883
2043
  }
1884
- static orthographic(left, right, bottom, top, near, far) {
2044
+ static orthographic(...args) {
2045
+ const bbox = checkNumberArray(args, 6) ? new BoundingBox(args[0], args[1], args[2], args[3]) : BoundingBox.resolve(args[0]);
2046
+ const near = checkNumberArray(args, 6) ? args[4] : args[1];
2047
+ const far = checkNumberArray(args, 6) ? args[5] : args[2];
1885
2048
  return new this([
1886
- 2 / (right - left),
2049
+ 2 / (bbox.right - bbox.left),
1887
2050
  0,
1888
2051
  0,
1889
2052
  0,
1890
2053
  0,
1891
- 2 / (top - bottom),
2054
+ 2 / (bbox.top - bbox.bottom),
1892
2055
  0,
1893
2056
  0,
1894
2057
  0,
1895
2058
  0,
1896
2059
  2 / (near - far),
1897
2060
  0,
1898
- (left + right) / (left - right),
1899
- (bottom + top) / (bottom - top),
2061
+ (bbox.left + bbox.right) / (bbox.left - bbox.right),
2062
+ (bbox.bottom + bbox.top) / (bbox.bottom - bbox.top),
1900
2063
  (near + far) / (near - far),
1901
2064
  1
1902
2065
  ]);
@@ -1949,7 +2112,7 @@ var Mat4 = class _Mat4 {
1949
2112
  ]);
1950
2113
  }
1951
2114
  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))
2115
+ if (!checkNumberArray(init, 16))
1953
2116
  throw new TypeError("expected a number array with 16 elements");
1954
2117
  this._raw = init;
1955
2118
  }
@@ -2004,6 +2167,12 @@ var Mat4 = class _Mat4 {
2004
2167
  toString() {
2005
2168
  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
2169
  }
2170
+ get [Symbol.toStringTag]() {
2171
+ return "Mat4";
2172
+ }
2173
+ [NodeJSCustomInspect]() {
2174
+ return `Mat4 <${this.toString()}>`;
2175
+ }
2007
2176
  clone() {
2008
2177
  return new _Mat4([
2009
2178
  this.m00,
@@ -2024,82 +2193,80 @@ var Mat4 = class _Mat4 {
2024
2193
  this.m33
2025
2194
  ]);
2026
2195
  }
2027
- equals(mat) {
2028
- const m = _Mat4.resolve(mat);
2196
+ equals(...args) {
2197
+ const m = _Mat4.resolveArgs(args);
2029
2198
  for (let index = 0; index < this._raw.length; index++)
2030
2199
  if (this._raw[index] != m._raw[index])
2031
2200
  return false;
2032
2201
  return true;
2033
2202
  }
2034
- add(mat) {
2035
- const b = _Mat4.resolve(mat);
2203
+ add(...args) {
2204
+ const b = _Mat4.resolveArgs(args);
2036
2205
  const m = new _Mat4();
2037
2206
  for (let index = 0; index < this._raw.length; index++)
2038
2207
  m._raw[index] = this._raw[index] + b._raw[index];
2039
2208
  return m;
2040
2209
  }
2041
- subtract(mat) {
2042
- const b = _Mat4.resolve(mat);
2210
+ subtract(...args) {
2211
+ const b = _Mat4.resolveArgs(args);
2043
2212
  const m = new _Mat4();
2044
2213
  for (let index = 0; index < this._raw.length; index++)
2045
2214
  m._raw[index] = this._raw[index] - b._raw[index];
2046
2215
  return m;
2047
2216
  }
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);
2217
+ multiply(...args) {
2218
+ if (checkNumberArray(args, 1)) {
2219
+ const scalar = args[0];
2071
2220
  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
2221
+ this.m00 * scalar,
2222
+ this.m01 * scalar,
2223
+ this.m02 * scalar,
2224
+ this.m03 * scalar,
2225
+ this.m10 * scalar,
2226
+ this.m11 * scalar,
2227
+ this.m12 * scalar,
2228
+ this.m13 * scalar,
2229
+ this.m20 * scalar,
2230
+ this.m21 * scalar,
2231
+ this.m22 * scalar,
2232
+ this.m23 * scalar,
2233
+ this.m30 * scalar,
2234
+ this.m31 * scalar,
2235
+ this.m32 * scalar,
2236
+ this.m33 * scalar
2088
2237
  ]);
2089
2238
  }
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
2239
+ const vec = Vec3.cast(args[0]);
2240
+ if (vec !== void 0) {
2241
+ const result = new Vec3(
2242
+ vec.x * this.m00 + vec.y * this.m10 + vec.z * this.m20 + this.m30,
2243
+ vec.x * this.m01 + vec.y * this.m11 + vec.z * this.m21 + this.m31,
2244
+ vec.x * this.m02 + vec.y * this.m12 + vec.z * this.m22 + this.m32,
2245
+ vec.x * this.m03 + vec.y * this.m13 + vec.z * this.m23 + this.m33
2097
2246
  );
2098
- if (vec.w != 0)
2099
- return vec.divide(vec.w);
2100
- return vec;
2247
+ if (result.w != 0)
2248
+ return result.divide(result.w);
2249
+ return result;
2101
2250
  }
2102
- throw new ResolveError("Mat4 or Vec3 or number", a);
2251
+ const mat = _Mat4.resolveArgs(args);
2252
+ return new _Mat4([
2253
+ mat.m00 * this.m00 + mat.m01 * this.m10 + mat.m02 * this.m20 + mat.m03 * this.m30,
2254
+ mat.m00 * this.m01 + mat.m01 * this.m11 + mat.m02 * this.m21 + mat.m03 * this.m31,
2255
+ mat.m00 * this.m02 + mat.m01 * this.m12 + mat.m02 * this.m22 + mat.m03 * this.m32,
2256
+ mat.m00 * this.m03 + mat.m01 * this.m13 + mat.m02 * this.m23 + mat.m03 * this.m33,
2257
+ mat.m10 * this.m00 + mat.m11 * this.m10 + mat.m12 * this.m20 + mat.m13 * this.m30,
2258
+ mat.m10 * this.m01 + mat.m11 * this.m11 + mat.m12 * this.m21 + mat.m13 * this.m31,
2259
+ mat.m10 * this.m02 + mat.m11 * this.m12 + mat.m12 * this.m22 + mat.m13 * this.m32,
2260
+ mat.m10 * this.m03 + mat.m11 * this.m13 + mat.m12 * this.m23 + mat.m13 * this.m33,
2261
+ mat.m20 * this.m00 + mat.m21 * this.m10 + mat.m22 * this.m20 + mat.m23 * this.m30,
2262
+ mat.m20 * this.m01 + mat.m21 * this.m11 + mat.m22 * this.m21 + mat.m23 * this.m31,
2263
+ mat.m20 * this.m02 + mat.m21 * this.m12 + mat.m22 * this.m22 + mat.m23 * this.m32,
2264
+ mat.m20 * this.m03 + mat.m21 * this.m13 + mat.m22 * this.m23 + mat.m23 * this.m33,
2265
+ mat.m30 * this.m00 + mat.m31 * this.m10 + mat.m32 * this.m20 + mat.m33 * this.m30,
2266
+ mat.m30 * this.m01 + mat.m31 * this.m11 + mat.m32 * this.m21 + mat.m33 * this.m31,
2267
+ mat.m30 * this.m02 + mat.m31 * this.m12 + mat.m32 * this.m22 + mat.m33 * this.m32,
2268
+ mat.m30 * this.m03 + mat.m31 * this.m13 + mat.m32 * this.m23 + mat.m33 * this.m33
2269
+ ]);
2103
2270
  }
2104
2271
  translate(...args) {
2105
2272
  const vec = Vec3.resolveArgs(args);
@@ -2249,33 +2416,31 @@ var Mat4 = class _Mat4 {
2249
2416
  };
2250
2417
 
2251
2418
  // source/color.ts
2252
- function _hex_to_array(hex) {
2253
- if (!check_hex(hex))
2419
+ function __hex_to_array__(hex) {
2420
+ if (!checkHex(hex))
2254
2421
  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];
2422
+ const part = getHexValue(hex);
2423
+ const red = parseInt(part.substring(0, 2), 16) / 255;
2424
+ const green = parseInt(part.substring(2, 4), 16) / 255;
2425
+ const blue = parseInt(part.substring(4, 6), 16) / 255;
2426
+ const alpha = part.length == 8 ? parseInt(hex.substring(6, 8), 16) / 255 : 1;
2427
+ return [red, green, blue, alpha];
2261
2428
  }
2262
- function _number_to_rgb(number) {
2429
+ function __number_to_rgb__(number) {
2263
2430
  const blue = number & 255;
2264
2431
  const green = (number & 65280) >>> 8;
2265
2432
  const red = (number & 16711680) >>> 16;
2266
2433
  return [red / 255, green / 255, blue / 255];
2267
2434
  }
2268
- function _number_to_rgba(number) {
2435
+ function __number_to_rgba__(number) {
2269
2436
  const alpha = number & 255;
2270
2437
  const blue = (number & 65280) >>> 8;
2271
2438
  const green = (number & 16711680) >>> 16;
2272
2439
  const red = (number & 4278190080) >>> 24;
2273
2440
  return [red / 255, green / 255, blue / 255, alpha / 255];
2274
2441
  }
2275
- function _fix_integer(number) {
2276
- return number * 255 | 0;
2277
- }
2278
- var RGBAColor = class _RGBAColor {
2442
+ var __to_byte__ = (scale) => clamp(scale * 255 | 0, 0, 255);
2443
+ var RGBA = class _RGBA {
2279
2444
  _red;
2280
2445
  get red() {
2281
2446
  return this._red;
@@ -2310,27 +2475,36 @@ var RGBAColor = class _RGBAColor {
2310
2475
  return value;
2311
2476
  throw new ResolveError("RGBAColor", a);
2312
2477
  }
2478
+ static resolveArgs(args) {
2479
+ if (checkNumberArray(args, 3) || checkNumberArray(args, 4))
2480
+ return new this(args[0], args[1], args[2], args[3]);
2481
+ return this.resolve(args[0]);
2482
+ }
2313
2483
  static cast(a) {
2314
2484
  if (a == null || typeof a == "undefined")
2315
2485
  return void 0;
2316
- if (check_number_array(a, 3) || check_number_array(a, 4))
2486
+ if (checkNumberArray(a, 3) || checkNumberArray(a, 4))
2317
2487
  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)) {
2488
+ if (hasProperty(a, "toRGB", "function"))
2489
+ return this.cast(a.toRGB());
2490
+ if (hasProperty(a, "toRGBA", "function"))
2491
+ return this.cast(a.toRGBA());
2492
+ if (hasProperty(a, "red", "number") && hasProperty(a, "green", "number") && hasProperty(a, "blue", "number"))
2493
+ return new this(a.red, a.green, a.blue, hasProperty(a, "alpha", "number") ? a.alpha : void 0);
2494
+ if (checkNumber(a)) {
2321
2495
  const hex = a.toString(16);
2322
- const convert = hex.length <= 6 ? _number_to_rgb : _number_to_rgba;
2496
+ const convert = hex.length <= 6 ? __number_to_rgb__ : __number_to_rgba__;
2323
2497
  return this.cast(convert(a));
2324
2498
  }
2325
- if (check_string(a)) {
2499
+ if (checkString(a)) {
2326
2500
  if (a.startsWith("rgb")) {
2327
2501
  const hasAlpha = a.startsWith("rgba");
2328
2502
  const offset = hasAlpha ? 5 : 4;
2329
2503
  const parts = a.substring(offset, a.indexOf(")", offset)).split(",");
2330
- if (check_string_array(parts, hasAlpha ? 4 : 3))
2504
+ if (checkStringArray(parts, hasAlpha ? 4 : 3))
2331
2505
  return this.cast(parts.map((v) => parseInt(v) / 255));
2332
2506
  }
2333
- return this.cast(_hex_to_array(a));
2507
+ return this.cast(__hex_to_array__(a));
2334
2508
  }
2335
2509
  return void 0;
2336
2510
  }
@@ -2343,38 +2517,57 @@ var RGBAColor = class _RGBAColor {
2343
2517
  this._blue = clamp(blue, 0, 1);
2344
2518
  this._alpha = clamp(alpha, 0, 1);
2345
2519
  }
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);
2520
+ toArray(withAlpha = this._alpha !== 1) {
2521
+ return withAlpha ? [this.red, this.green, this.blue, this.alpha] : [this.red, this.green, this.blue];
2348
2522
  }
2349
- toJSON(withAlpha = false) {
2523
+ toJSON(withAlpha = this._alpha !== 1) {
2350
2524
  return withAlpha ? {
2351
2525
  red: this.red,
2352
2526
  green: this.green,
2353
2527
  blue: this.blue,
2354
2528
  alpha: this.alpha
2355
- } : this.alpha == 1 ? { red: this.red, green: this.green, blue: this.blue } : this.toJSON(true);
2529
+ } : {
2530
+ red: this.red,
2531
+ green: this.green,
2532
+ blue: this.blue
2533
+ };
2534
+ }
2535
+ toString(withAlpha = this._alpha !== 1) {
2536
+ return withAlpha ? `rgba(${__to_byte__(this.red)},${__to_byte__(this.green)},${__to_byte__(this.blue)},${this.alpha})` : `rgb(${__to_byte__(this.red)},${__to_byte__(this.green)},${__to_byte__(this.blue)})`;
2537
+ }
2538
+ get [Symbol.toStringTag]() {
2539
+ return "RGBA";
2356
2540
  }
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);
2541
+ [NodeJSCustomInspect]() {
2542
+ return `RGBA <${this.toString()}>`;
2359
2543
  }
2360
- toHSL(withAlpha = true) {
2544
+ toVec2() {
2545
+ return [this.red, this.green, this.blue];
2546
+ }
2547
+ toVec3() {
2548
+ return [this.red, this.green, this.blue, this.alpha];
2549
+ }
2550
+ toHSL(withAlpha = this._alpha !== 1) {
2361
2551
  const red = this.red, green = this.green, blue = this.blue;
2362
2552
  const min = Math.min(red, green, blue), max = Math.max(red, green, blue);
2363
2553
  const luminace = (min + max) / 2;
2364
2554
  if (min == max)
2365
- return new HSLColor(0, 0, luminace, withAlpha ? this.alpha : void 0);
2555
+ return new HSLA(0, 0, luminace, withAlpha ? this.alpha : void 0);
2366
2556
  const d = max - min;
2367
2557
  const saturation = luminace > 0.5 ? d / (2 - max - min) : d / (max + min);
2368
2558
  if (max == red)
2369
- return new HSLColor(((green - blue) / d + (green < blue ? 6 : 0)) / 6, saturation, luminace);
2559
+ return new HSLA(((green - blue) / d + (green < blue ? 6 : 0)) / 6, saturation, luminace, withAlpha ? this.alpha : void 0);
2370
2560
  if (max == green)
2371
- return new HSLColor(((blue - red) / d + 2) / 6, saturation, luminace);
2561
+ return new HSLA(((blue - red) / d + 2) / 6, saturation, luminace, withAlpha ? this.alpha : void 0);
2372
2562
  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);
2563
+ return new HSLA(((red - green) / d + 4) / 6, saturation, luminace, withAlpha ? this.alpha : void 0);
2564
+ return new HSLA(0, saturation, luminace, withAlpha ? this.alpha : void 0);
2565
+ }
2566
+ toHSLA() {
2567
+ return this.toHSL(true);
2375
2568
  }
2376
- invert(withAlpha = false) {
2377
- return new _RGBAColor(
2569
+ invert(withAlpha = this._alpha !== 1) {
2570
+ return new _RGBA(
2378
2571
  1 - this.red,
2379
2572
  1 - this.green,
2380
2573
  1 - this.blue,
@@ -2382,7 +2575,7 @@ var RGBAColor = class _RGBAColor {
2382
2575
  );
2383
2576
  }
2384
2577
  };
2385
- var HSLColor = class _HSLColor {
2578
+ var HSLA = class _HSLA {
2386
2579
  _hue;
2387
2580
  get hue() {
2388
2581
  return this._hue;
@@ -2417,27 +2610,36 @@ var HSLColor = class _HSLColor {
2417
2610
  return value;
2418
2611
  throw new ResolveError("HSLColor", a);
2419
2612
  }
2613
+ static resolveArgs(args) {
2614
+ if (checkNumberArray(args, 3) || checkNumberArray(args, 4))
2615
+ return new this(args[0], args[1], args[2], args[3]);
2616
+ return this.resolve(args[0]);
2617
+ }
2420
2618
  static cast(a) {
2421
2619
  if (a == null || typeof a == "undefined")
2422
2620
  return void 0;
2423
- if (check_number_array(a, 3) || check_number_array(a, 4))
2621
+ if (checkNumberArray(a, 3) || checkNumberArray(a, 4))
2424
2622
  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)) {
2623
+ if (hasProperty(a, "toHSL", "function"))
2624
+ return this.cast(a.toHSL());
2625
+ if (hasProperty(a, "toHSLA", "function"))
2626
+ return this.cast(a.toHSLA());
2627
+ if (hasProperty(a, "hue", "number") && hasProperty(a, "saturation", "number") && hasProperty(a, "luminace", "number"))
2628
+ return new this(a.hue, a.saturation, a.luminace, hasProperty(a, "alpha", "number") ? a.alpha : void 0);
2629
+ if (checkNumber(a)) {
2428
2630
  const hex = a.toString(16);
2429
- const convert = hex.length <= 6 ? _number_to_rgb : _number_to_rgba;
2631
+ const convert = hex.length <= 6 ? __number_to_rgb__ : __number_to_rgba__;
2430
2632
  return this.cast(convert(a));
2431
2633
  }
2432
- if (check_string(a)) {
2634
+ if (checkString(a)) {
2433
2635
  if (a.startsWith("hsl")) {
2434
2636
  const hasAlpha = a.startsWith("hsla");
2435
2637
  const offset = hasAlpha ? 5 : 4;
2436
2638
  const parts = a.substring(offset, a.indexOf(")", offset)).split(",");
2437
- if (check_string_array(parts, hasAlpha ? 4 : 3))
2639
+ if (checkStringArray(parts, hasAlpha ? 4 : 3))
2438
2640
  return this.cast(parts.map((v) => parseInt(v) / 255));
2439
2641
  }
2440
- return this.cast(_hex_to_array(a));
2642
+ return this.cast(__hex_to_array__(a));
2441
2643
  }
2442
2644
  return void 0;
2443
2645
  }
@@ -2445,39 +2647,49 @@ var HSLColor = class _HSLColor {
2445
2647
  return typeof this.cast(a) != "undefined";
2446
2648
  }
2447
2649
  constructor(hue, saturation, luminace, alpha = 1) {
2448
- if (!check_number(hue))
2650
+ if (!checkNumber(hue))
2449
2651
  throw new TypeError("expected number for hue");
2450
- if (!check_number(saturation))
2652
+ if (!checkNumber(saturation))
2451
2653
  throw new TypeError("expected number for saturation");
2452
- if (!check_number(luminace))
2654
+ if (!checkNumber(luminace))
2453
2655
  throw new TypeError("expected number for luminace");
2454
- if (!check_number(alpha))
2656
+ if (!checkNumber(alpha))
2455
2657
  throw new TypeError("expected number for alpha");
2456
2658
  this._hue = clamp(hue, 0, 1);
2457
2659
  this._saturation = clamp(saturation, 0, 1);
2458
2660
  this._luminace = clamp(luminace, 0, 1);
2459
2661
  this._alpha = clamp(alpha, 0, 1);
2460
2662
  }
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);
2663
+ toArray(withAlpha = this._alpha !== 1) {
2664
+ return withAlpha ? [this.hue, this.saturation, this.luminace, this.alpha] : [this.hue, this.saturation, this.luminace];
2463
2665
  }
2464
- toJSON(withAlpha = false) {
2666
+ toJSON(withAlpha = this._alpha !== 1) {
2465
2667
  return withAlpha ? {
2466
2668
  hue: this.hue,
2467
2669
  saturation: this.saturation,
2468
2670
  luminace: this.luminace,
2469
2671
  alpha: this.alpha
2470
- } : this.alpha == 1 ? { hue: this.hue, saturation: this.saturation, luminace: this.luminace } : this.toJSON(true);
2672
+ } : {
2673
+ hue: this.hue,
2674
+ saturation: this.saturation,
2675
+ luminace: this.luminace
2676
+ };
2677
+ }
2678
+ toString(withAlpha = this._alpha !== 1) {
2679
+ return withAlpha ? `hsla(${__to_byte__(this.hue)},${__to_byte__(this.saturation)},${__to_byte__(this.luminace)},${this.alpha})` : `hsl(${__to_byte__(this.hue)},${__to_byte__(this.saturation)},${__to_byte__(this.luminace)})`;
2680
+ }
2681
+ get [Symbol.toStringTag]() {
2682
+ return "HSLA";
2471
2683
  }
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);
2684
+ [NodeJSCustomInspect]() {
2685
+ return `HSLA <${this.toString()}>`;
2474
2686
  }
2475
- toRGB(withAlpha = true) {
2687
+ toRGB(withAlpha = this._alpha !== 1) {
2476
2688
  if (this.saturation == 0)
2477
- return new RGBAColor(this.luminace * 255, this.luminace * 255, this.luminace * 255, withAlpha ? this.alpha : void 0);
2689
+ return new RGBA(this.luminace * 255, this.luminace * 255, this.luminace * 255, withAlpha ? this.alpha : void 0);
2478
2690
  const q = this.luminace < 0.5 ? this.luminace * (1 + this.saturation) : this.luminace + this.saturation - this.luminace * this.saturation;
2479
2691
  const p = 2 * this.luminace - q;
2480
- function _hue_2_rgb(t) {
2692
+ function __hue_2_rgb__(t) {
2481
2693
  let _t = t;
2482
2694
  if (_t < 0)
2483
2695
  _t++;
@@ -2491,10 +2703,19 @@ var HSLColor = class _HSLColor {
2491
2703
  return p + (q - p) * (2 / 3 - _t) * 6;
2492
2704
  return p;
2493
2705
  }
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);
2706
+ return new RGBA(__hue_2_rgb__(this.hue + 1 / 3) * 255, __hue_2_rgb__(this.hue) * 255, __hue_2_rgb__(this.hue - 1 / 3) * 255, withAlpha ? this.alpha : void 0);
2495
2707
  }
2496
- invert(withAlpha = false) {
2497
- return new _HSLColor(
2708
+ toRGBA() {
2709
+ return this.toRGB(true);
2710
+ }
2711
+ toVec2() {
2712
+ return [this.hue, this.saturation, this.luminace];
2713
+ }
2714
+ toVec3() {
2715
+ return [this.hue, this.saturation, this.luminace, this.alpha];
2716
+ }
2717
+ invert(withAlpha = this._alpha !== 1) {
2718
+ return new _HSLA(
2498
2719
  1 - this.hue,
2499
2720
  1 - this.saturation,
2500
2721
  1 - this.luminace,
@@ -2502,33 +2723,44 @@ var HSLColor = class _HSLColor {
2502
2723
  );
2503
2724
  }
2504
2725
  };
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
- }
2726
+ var AnyColor;
2727
+ ((AnyColor2) => {
2728
+ function cast(a, preferHSL = false) {
2729
+ const results = [];
2730
+ try {
2731
+ const rgba = RGBA.resolve(a);
2732
+ results.push(rgba);
2733
+ } catch (e) {
2734
+ }
2735
+ try {
2736
+ const hsla = HSLA.resolve(a);
2737
+ results.push(hsla);
2738
+ } catch (e) {
2739
+ }
2740
+ let offset = preferHSL ? 1 : 0;
2741
+ const firstItem = results[offset];
2742
+ if (firstItem)
2743
+ return firstItem;
2744
+ const secondItem = results[offset + 1];
2745
+ if (secondItem)
2746
+ return secondItem;
2747
+ return void 0;
2748
+ }
2749
+ AnyColor2.cast = cast;
2750
+ function resolve(a, preferHSL = false) {
2751
+ const value = cast(a, preferHSL);
2752
+ if (typeof value != "undefined")
2753
+ return value;
2754
+ throw new ResolveError("Color", a);
2755
+ }
2756
+ AnyColor2.resolve = resolve;
2757
+ function resolveArgs(args, preferHSL = false) {
2758
+ if (checkNumberArray(args, 3) || checkNumberArray(args, 4))
2759
+ return resolve(args, preferHSL);
2760
+ return resolve(args[0], preferHSL);
2761
+ }
2762
+ AnyColor2.resolveArgs = resolveArgs;
2763
+ })(AnyColor || (AnyColor = {}));
2532
2764
 
2533
2765
  // source/quaternion.ts
2534
2766
  var Quaternion = class _Quaternion {
@@ -2545,16 +2777,23 @@ var Quaternion = class _Quaternion {
2545
2777
  return value;
2546
2778
  throw new ResolveError("Quaternion", a);
2547
2779
  }
2780
+ static resolveArgs(args) {
2781
+ if (checkNumberArray(args, 4))
2782
+ return new this(args[0], args[1], args[2], args[3]);
2783
+ return this.resolve(args[0]);
2784
+ }
2548
2785
  static cast(a) {
2549
2786
  if (a == null || typeof a == "undefined")
2550
2787
  return void 0;
2551
- if (check_number_array(a, 4))
2788
+ if (checkNumberArray(a, 4))
2552
2789
  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"))
2790
+ if (hasProperty(a, "toQuaternion", "function"))
2791
+ return this.cast(a.toQuaternion());
2792
+ if (hasProperty(a, "w", "number") && hasProperty(a, "x", "number") && hasProperty(a, "y", "number") && hasProperty(a, "z", "number"))
2554
2793
  return new this(a.w, a.x, a.y, a.z);
2555
- if (check_string(a)) {
2794
+ if (checkString(a)) {
2556
2795
  const parts = a.replaceAll(" ", "").split("+");
2557
- if (check_string_array(parts, 4)) {
2796
+ if (checkStringArray(parts, 4)) {
2558
2797
  const [sw, sxi, syj, szk] = parts;
2559
2798
  if (sxi.endsWith("i") && syj.endsWith("j") && szk.endsWith("k"))
2560
2799
  return this.cast([
@@ -2567,7 +2806,9 @@ var Quaternion = class _Quaternion {
2567
2806
  }
2568
2807
  return void 0;
2569
2808
  }
2570
- static fromAxisAngle(axis, angle) {
2809
+ static fromAxisAngle(...args) {
2810
+ const axis = checkNumberArray(args, 4) ? new Vec3(args[0], args[1], args[2]) : Vec3.resolve(args[0]);
2811
+ const angle = checkNumberArray(args, 4) ? args[3] : args[1];
2571
2812
  const vec = Vec3.resolve(axis);
2572
2813
  const hangle = angle * 0.5;
2573
2814
  const sin2 = Math.sin(hangle);
@@ -2587,14 +2828,17 @@ var Quaternion = class _Quaternion {
2587
2828
  sx * sy * cz + sz * cx * cy
2588
2829
  );
2589
2830
  }
2590
- constructor(w = 0, x = 0, y = 0, z = 0) {
2591
- if (!check_number(w))
2831
+ static get zero() {
2832
+ return new _Quaternion(0, 0, 0, 0);
2833
+ }
2834
+ constructor(w, x, y, z) {
2835
+ if (!checkNumber(w))
2592
2836
  throw new TypeError("expected number for w");
2593
- if (!check_number(x))
2837
+ if (!checkNumber(x))
2594
2838
  throw new TypeError("expected number for x");
2595
- if (!check_number(y))
2839
+ if (!checkNumber(y))
2596
2840
  throw new TypeError("expected number for x");
2597
- if (!check_number(z))
2841
+ if (!checkNumber(z))
2598
2842
  throw new TypeError("expected number for w");
2599
2843
  this.w = w;
2600
2844
  this.x = x;
@@ -2607,6 +2851,12 @@ var Quaternion = class _Quaternion {
2607
2851
  toString() {
2608
2852
  return `${this.w} + ${this.x}i + ${this.y}j + ${this.z}k`;
2609
2853
  }
2854
+ get [Symbol.toStringTag]() {
2855
+ return "Quaternion";
2856
+ }
2857
+ [NodeJSCustomInspect]() {
2858
+ return `Quaternion <${this.toString()}>`;
2859
+ }
2610
2860
  toJSON() {
2611
2861
  return {
2612
2862
  w: this.w,
@@ -2618,8 +2868,8 @@ var Quaternion = class _Quaternion {
2618
2868
  clone() {
2619
2869
  return new _Quaternion(this.w, this.x, this.y, this.z);
2620
2870
  }
2621
- add(a) {
2622
- const quat = _Quaternion.resolve(a);
2871
+ add(...args) {
2872
+ const quat = _Quaternion.resolveArgs(args);
2623
2873
  return new _Quaternion(
2624
2874
  this.w + quat.w,
2625
2875
  this.x + quat.x,
@@ -2627,16 +2877,16 @@ var Quaternion = class _Quaternion {
2627
2877
  this.z + quat.z
2628
2878
  );
2629
2879
  }
2630
- offset(a) {
2631
- const quat = _Quaternion.resolve(a);
2880
+ offset(...args) {
2881
+ const quat = _Quaternion.resolveArgs(args);
2632
2882
  this.w += quat.w;
2633
2883
  this.x += quat.x;
2634
2884
  this.y += quat.y;
2635
2885
  this.z += quat.z;
2636
2886
  return this;
2637
2887
  }
2638
- subtract(a) {
2639
- const quat = _Quaternion.resolve(a);
2888
+ subtract(...args) {
2889
+ const quat = _Quaternion.resolveArgs(args);
2640
2890
  return new _Quaternion(
2641
2891
  this.w - quat.w,
2642
2892
  this.x - quat.x,
@@ -2654,12 +2904,12 @@ var Quaternion = class _Quaternion {
2654
2904
  normalize() {
2655
2905
  let length = this.length();
2656
2906
  if (length < EPSILON)
2657
- return new _Quaternion();
2907
+ return _Quaternion.zero;
2658
2908
  length = 1 / length;
2659
2909
  return new _Quaternion(this.w * length, this.x * length, this.y * length, this.z * length);
2660
2910
  }
2661
- multiply(a) {
2662
- const quat = _Quaternion.resolve(a);
2911
+ multiply(...args) {
2912
+ const quat = _Quaternion.resolveArgs(args);
2663
2913
  return new _Quaternion(
2664
2914
  this.w * quat.w - this.x * quat.x - this.y * quat.y - this.z * quat.z,
2665
2915
  this.w * quat.x + this.x * quat.w + this.y * quat.z - this.z * quat.y,
@@ -2682,21 +2932,21 @@ var Quaternion = class _Quaternion {
2682
2932
  scale(scalar) {
2683
2933
  return new _Quaternion(this.w * scalar, this.x * scalar, this.y * scalar, this.z * scalar);
2684
2934
  }
2685
- dot(a) {
2686
- const quat = _Quaternion.resolve(a);
2935
+ dot(...args) {
2936
+ const quat = _Quaternion.resolveArgs(args);
2687
2937
  return this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z;
2688
2938
  }
2689
2939
  inverse() {
2690
2940
  let length = this.length(false);
2691
2941
  if (length == 0)
2692
- return new _Quaternion();
2942
+ return _Quaternion.zero;
2693
2943
  length = 1 / length;
2694
2944
  return new _Quaternion(this.w * length, -this.x * length, -this.y * length, -this.z * length);
2695
2945
  }
2696
- divide(a) {
2697
- const quat = _Quaternion.resolve(a);
2946
+ divide(...args) {
2947
+ const quat = _Quaternion.resolveArgs(args);
2698
2948
  let length = quat.length(false);
2699
- if (length == 0) return new _Quaternion();
2949
+ if (length == 0) return _Quaternion.zero;
2700
2950
  length = 1 / length;
2701
2951
  return new _Quaternion(
2702
2952
  (this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z) * length,
@@ -2713,7 +2963,7 @@ var Quaternion = class _Quaternion {
2713
2963
  const exp = Math.exp(this.w);
2714
2964
  const scale = exp * Math.sin(length) / length;
2715
2965
  if (length == 0)
2716
- return new _Quaternion(exp);
2966
+ return new _Quaternion(exp, 0, 0, 0);
2717
2967
  return new _Quaternion(
2718
2968
  exp * Math.cos(length),
2719
2969
  this.x * scale,
@@ -2723,14 +2973,14 @@ var Quaternion = class _Quaternion {
2723
2973
  }
2724
2974
  log() {
2725
2975
  if (this.x == 0 && this.z == 0)
2726
- return new _Quaternion(log_hypot(this.w, this.x), Math.atan2(this.x, this.w));
2976
+ return new _Quaternion(logHypot(this.w, this.x), Math.atan2(this.x, this.w), 0, 0);
2727
2977
  const length = this.length(false);
2728
2978
  const length2 = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
2729
2979
  const scale = Math.atan2(length2, this.w) / length;
2730
2980
  return new _Quaternion(Math.log(length) * 0.5, this.x * scale, this.y * scale, this.z * scale);
2731
2981
  }
2732
- toVector() {
2733
- return new Vec3(this.x, this.y, this.z, this.w);
2982
+ toVec3() {
2983
+ return [this.x, this.y, this.z, this.w];
2734
2984
  }
2735
2985
  toAxisAngle() {
2736
2986
  const sin2 = 1 - this.w * this.w;
@@ -2741,17 +2991,17 @@ var Quaternion = class _Quaternion {
2741
2991
  return new Vec3(this.x * isin, this.y * isin, this.z * isin, angle);
2742
2992
  }
2743
2993
  toEuler() {
2744
- function asin(t) {
2994
+ function __asin__(t) {
2745
2995
  return t >= 1 ? Math.PI / 2 : t <= -1 ? -Math.PI / 2 : Math.asin(t);
2746
2996
  }
2747
2997
  return new Vec3(
2748
2998
  -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)),
2999
+ __asin__(2 * (this.x * this.z + this.w * this.y)),
2750
3000
  -Math.atan2(2 * (this.x * this.y - this.w * this.z), 1 - 2 * (this.y * this.y + this.z * this.z))
2751
3001
  );
2752
3002
  }
2753
3003
  toMat3() {
2754
- return new Mat3([
3004
+ return [
2755
3005
  1 - 2 * (this.y * this.y + this.z * this.z),
2756
3006
  2 * (this.x * this.y - this.w * this.z),
2757
3007
  2 * (this.x * this.z + this.w * this.y),
@@ -2761,10 +3011,10 @@ var Quaternion = class _Quaternion {
2761
3011
  2 * (this.x * this.z - this.w * this.y),
2762
3012
  2 * (this.y * this.z + this.w * this.x),
2763
3013
  1 - 2 * (this.x * this.x + this.y * this.y)
2764
- ]);
3014
+ ];
2765
3015
  }
2766
3016
  toMat4() {
2767
- return new Mat4([
3017
+ return [
2768
3018
  1 - 2 * (this.y * this.y + this.z * this.z),
2769
3019
  2 * (this.x * this.y - this.w * this.z),
2770
3020
  2 * (this.x * this.z + this.w * this.y),
@@ -2781,89 +3031,205 @@ var Quaternion = class _Quaternion {
2781
3031
  0,
2782
3032
  0,
2783
3033
  1
2784
- ]);
3034
+ ];
2785
3035
  }
2786
3036
  };
2787
3037
 
2788
3038
  // source/transform.ts
2789
- var Transform = class {
3039
+ var Transform2D = class {
3040
+ constructor(position, rotation, scale, parent) {
3041
+ this.parent = parent;
3042
+ this.localPosition = Vec2.resolve(position);
3043
+ this.localRotation = rotation;
3044
+ this.localScale = Vec2.resolve(scale);
3045
+ }
3046
+ origin = Vec2.zero;
3047
+ localPosition;
3048
+ localRotation;
3049
+ get localRotationDegree() {
3050
+ return radianToDegree(this.localRotation);
3051
+ }
3052
+ set localRotationDegree(v) {
3053
+ this.localRotation = degreeToRadian(v);
3054
+ }
3055
+ localScale;
3056
+ get globalPosition() {
3057
+ let position = Vec2.zero;
3058
+ let transform = this;
3059
+ while (transform !== void 0) {
3060
+ position = position.add(transform.localPosition).add(transform.origin);
3061
+ transform = transform.parent;
3062
+ }
3063
+ return position;
3064
+ }
3065
+ get globalRotation() {
3066
+ let rotation = 0;
3067
+ let transform = this;
3068
+ while (transform !== void 0) {
3069
+ rotation += transform.localRotation;
3070
+ transform = transform.parent;
3071
+ }
3072
+ return rotation;
3073
+ }
3074
+ get globalRotationDegree() {
3075
+ return radianToDegree(this.globalRotation);
3076
+ }
3077
+ get globalScale() {
3078
+ let scale = Vec2.one;
3079
+ let transform = this;
3080
+ while (transform !== void 0) {
3081
+ scale = scale.naiveMultiply(transform.localScale);
3082
+ transform = transform.parent;
3083
+ }
3084
+ return scale;
3085
+ }
3086
+ toString() {
3087
+ return `${this.localPosition.toString()}|${this.localRotation}|${this.localScale.toString()}`;
3088
+ }
3089
+ get [Symbol.toStringTag]() {
3090
+ return "Transform2D";
3091
+ }
3092
+ [NodeJSCustomInspect]() {
3093
+ return `Transform2D <${this.toString()}>`;
3094
+ }
3095
+ toMat3() {
3096
+ return new Mat3().scale(this.localScale).rotate(this.localRotation).translate(this.localPosition);
3097
+ }
3098
+ toGlobalMat3() {
3099
+ let result = new Mat3();
3100
+ let transform = this;
3101
+ while (transform !== void 0) {
3102
+ result = result.multiply(transform.toMat3());
3103
+ transform = transform.parent;
3104
+ }
3105
+ return result;
3106
+ }
3107
+ };
3108
+ var Transform3D = class {
2790
3109
  /**
2791
- * The position of the object
3110
+ * Create a new transform with `position`, `rotation` and `scale`
3111
+ * @param position The position as a Vec3
3112
+ * @param rotation The rotation as a Quaternion
3113
+ * @param scale The scale as a Vec3
2792
3114
  */
2793
- position;
3115
+ constructor(position, rotation, scale, parent) {
3116
+ this.parent = parent;
3117
+ this.localPosition = Vec3.resolve(position);
3118
+ this.localRotation = Quaternion.resolve(rotation);
3119
+ this.localScale = Vec3.resolve(scale);
3120
+ }
3121
+ origin = Vec3.zero;
2794
3122
  /**
2795
- * The rotation of the object
3123
+ * The local position
2796
3124
  */
2797
- rotation;
3125
+ localPosition;
2798
3126
  /**
2799
- * The scale of the object
3127
+ * The local rotation
2800
3128
  */
2801
- scale;
3129
+ localRotation;
2802
3130
  /**
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
3131
+ * The local scale
2807
3132
  */
2808
- constructor(position, rotation, scale) {
2809
- this.position = Vec3.resolve(position);
2810
- this.rotation = Quaternion.resolve(rotation);
2811
- this.scale = Vec3.resolve(scale);
3133
+ localScale;
3134
+ get globalPosition() {
3135
+ let position = Vec3.zero;
3136
+ let transform = this;
3137
+ while (transform !== void 0) {
3138
+ position = position.add(transform.localPosition).add(transform.origin);
3139
+ transform = transform.parent;
3140
+ }
3141
+ return position;
3142
+ }
3143
+ get globalRotation() {
3144
+ let rotation = Quaternion.zero;
3145
+ let transform = this;
3146
+ while (transform !== void 0) {
3147
+ rotation = rotation.add(transform.localRotation);
3148
+ transform = transform.parent;
3149
+ }
3150
+ return rotation;
3151
+ }
3152
+ get globalScale() {
3153
+ let scale = Vec3.one;
3154
+ let transform = this;
3155
+ while (transform !== void 0) {
3156
+ scale = scale.naiveMultiply(transform.localScale);
3157
+ transform = transform.parent;
3158
+ }
3159
+ return scale;
3160
+ }
3161
+ toString() {
3162
+ return `${this.localPosition.toString()}|${this.localRotation.toString()}|${this.localScale.toString()}`;
3163
+ }
3164
+ get [Symbol.toStringTag]() {
3165
+ return "Transform2D";
3166
+ }
3167
+ [NodeJSCustomInspect]() {
3168
+ return `Transform2D <${this.toString()}>`;
2812
3169
  }
2813
3170
  /**
2814
3171
  * Convert the transform into a 4x3 matrix
2815
3172
  * @returns A 4x4 matrix from the transform
2816
3173
  */
2817
3174
  toMat4() {
2818
- return new Mat4().translate(this.position).multiply(this.rotation.toMat4()).scale(this.scale);
3175
+ return new Mat4().scale(this.localScale).multiply(this.localRotation).translate(this.localPosition);
3176
+ }
3177
+ toGlobalMat4() {
3178
+ let result = new Mat4();
3179
+ let transform = this;
3180
+ while (transform !== void 0) {
3181
+ result = result.multiply(transform.toMat4());
3182
+ transform = transform.parent;
3183
+ }
3184
+ return result;
2819
3185
  }
2820
3186
  };
2821
3187
  export {
2822
- ATriangle,
3188
+ AnyColor,
2823
3189
  BoundingBox,
2824
3190
  Circle,
2825
3191
  DJB2_OFFSET,
2826
3192
  EPSILON,
2827
3193
  FNV1_OFFSET,
2828
3194
  FNV1_PRIME,
2829
- HSLColor,
3195
+ HSLA,
2830
3196
  LinearFunction,
2831
3197
  MAX_ANGLE_DEGREE,
2832
3198
  MD2,
2833
3199
  Mat3,
2834
3200
  Mat4,
2835
3201
  MathFunction,
3202
+ NodeJSCustomInspect,
2836
3203
  QuadFunction,
2837
3204
  Quaternion,
2838
- RGBAColor,
3205
+ RGBA,
2839
3206
  Rectangle,
2840
3207
  ResolveError,
2841
3208
  Size,
2842
- Transform,
3209
+ Transform2D,
3210
+ Transform3D,
3211
+ Triangle,
2843
3212
  Triangle2D,
2844
3213
  Triangle3D,
2845
3214
  Vec2,
2846
3215
  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,
3216
+ checkArray,
3217
+ checkHex,
3218
+ checkNumber,
3219
+ checkNumberArray,
3220
+ checkString,
3221
+ checkStringArray,
2857
3222
  clamp,
2858
- degree_to_radian,
3223
+ clampAngleDegree,
3224
+ clampAngleRadian,
3225
+ degreeToRadian,
2859
3226
  djb2,
2860
3227
  fnv1,
2861
- get_hex_part,
2862
- has_property,
2863
- log_hypot,
2864
- radian_to_degree,
2865
- resolveColor,
3228
+ getHexValue,
3229
+ hasProperty,
3230
+ lerp,
3231
+ logHypot,
3232
+ radianToDegree,
2866
3233
  sdbm,
2867
- sign_char,
2868
- stringify
3234
+ signCharacter
2869
3235
  };