@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.js CHANGED
@@ -20,53 +20,53 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // source/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- ATriangle: () => ATriangle,
23
+ AnyColor: () => AnyColor,
24
24
  BoundingBox: () => BoundingBox,
25
25
  Circle: () => Circle,
26
26
  DJB2_OFFSET: () => DJB2_OFFSET,
27
27
  EPSILON: () => EPSILON,
28
28
  FNV1_OFFSET: () => FNV1_OFFSET,
29
29
  FNV1_PRIME: () => FNV1_PRIME,
30
- HSLColor: () => HSLColor,
30
+ HSLA: () => HSLA,
31
31
  LinearFunction: () => LinearFunction,
32
32
  MAX_ANGLE_DEGREE: () => MAX_ANGLE_DEGREE,
33
33
  MD2: () => MD2,
34
34
  Mat3: () => Mat3,
35
35
  Mat4: () => Mat4,
36
36
  MathFunction: () => MathFunction,
37
+ NodeJSCustomInspect: () => NodeJSCustomInspect,
37
38
  QuadFunction: () => QuadFunction,
38
39
  Quaternion: () => Quaternion,
39
- RGBAColor: () => RGBAColor,
40
+ RGBA: () => RGBA,
40
41
  Rectangle: () => Rectangle,
41
42
  ResolveError: () => ResolveError,
42
43
  Size: () => Size,
43
- Transform: () => Transform,
44
+ Transform2D: () => Transform2D,
45
+ Transform3D: () => Transform3D,
46
+ Triangle: () => Triangle,
44
47
  Triangle2D: () => Triangle2D,
45
48
  Triangle3D: () => Triangle3D,
46
49
  Vec2: () => Vec2,
47
50
  Vec3: () => Vec3,
48
- cap_angle_degree: () => cap_angle_degree,
49
- cap_angle_radian: () => cap_angle_radian,
50
- castColor: () => castColor,
51
- check_array: () => check_array,
52
- check_hex: () => check_hex,
53
- check_hex_digit: () => check_hex_digit,
54
- check_number: () => check_number,
55
- check_number_array: () => check_number_array,
56
- check_string: () => check_string,
57
- check_string_array: () => check_string_array,
51
+ checkArray: () => checkArray,
52
+ checkHex: () => checkHex,
53
+ checkNumber: () => checkNumber,
54
+ checkNumberArray: () => checkNumberArray,
55
+ checkString: () => checkString,
56
+ checkStringArray: () => checkStringArray,
58
57
  clamp: () => clamp,
59
- degree_to_radian: () => degree_to_radian,
58
+ clampAngleDegree: () => clampAngleDegree,
59
+ clampAngleRadian: () => clampAngleRadian,
60
+ degreeToRadian: () => degreeToRadian,
60
61
  djb2: () => djb2,
61
62
  fnv1: () => fnv1,
62
- get_hex_part: () => get_hex_part,
63
- has_property: () => has_property,
64
- log_hypot: () => log_hypot,
65
- radian_to_degree: () => radian_to_degree,
66
- resolveColor: () => resolveColor,
63
+ getHexValue: () => getHexValue,
64
+ hasProperty: () => hasProperty,
65
+ lerp: () => lerp,
66
+ logHypot: () => logHypot,
67
+ radianToDegree: () => radianToDegree,
67
68
  sdbm: () => sdbm,
68
- sign_char: () => sign_char,
69
- stringify: () => stringify
69
+ signCharacter: () => signCharacter
70
70
  });
71
71
  module.exports = __toCommonJS(index_exports);
72
72
 
@@ -75,7 +75,7 @@ var MathFunction = class {
75
75
  };
76
76
 
77
77
  // source/common/sign.ts
78
- function sign_char(num) {
78
+ function signCharacter(num) {
79
79
  if (num == 0)
80
80
  return void 0;
81
81
  if (num < 0)
@@ -86,35 +86,10 @@ function sign_char(num) {
86
86
  }
87
87
 
88
88
  // source/common/types.ts
89
- function check_number(obj) {
90
- return obj != null && typeof obj == "number" && !isNaN(obj) && isFinite(obj);
89
+ function checkNumber(value) {
90
+ return value !== null && typeof value == "number" && !isNaN(value) && isFinite(value);
91
91
  }
92
- function check_hex_digit(obj) {
93
- if (!check_string(obj) || obj.length != 1)
94
- return false;
95
- switch (obj.toUpperCase()) {
96
- default:
97
- return false;
98
- case "0":
99
- case "1":
100
- case "2":
101
- case "3":
102
- case "4":
103
- case "5":
104
- case "6":
105
- case "7":
106
- case "8":
107
- case "9":
108
- case "A":
109
- case "B":
110
- case "C":
111
- case "D":
112
- case "E":
113
- case "F":
114
- return true;
115
- }
116
- }
117
- function get_hex_part(string) {
92
+ function getHexValue(string) {
118
93
  let offset = 0;
119
94
  if (string.startsWith("#") || string.startsWith("$"))
120
95
  offset = 1;
@@ -122,112 +97,48 @@ function get_hex_part(string) {
122
97
  offset = 2;
123
98
  return string.substring(offset);
124
99
  }
125
- function check_hex(obj) {
126
- if (!check_string(obj))
100
+ function checkHex(value) {
101
+ if (!checkString(value))
127
102
  return false;
128
- const value = get_hex_part(obj).split("").map((char) => parseInt(char.toUpperCase(), 16));
129
- return check_number_array(value);
103
+ const hexValue = getHexValue(value).split("").map((char) => parseInt(char.toUpperCase(), 16));
104
+ return checkNumberArray(hexValue);
130
105
  }
131
- function check_string(obj) {
132
- return obj != null && typeof obj == "string" && obj.length > 0;
106
+ function checkString(value) {
107
+ return value !== null && typeof value == "string" && value.length > 0;
133
108
  }
134
- function check_array(obj, predicate, requiredLength) {
135
- if (!Array.isArray(obj)) return false;
136
- if (requiredLength && requiredLength != obj.length) return false;
137
- for (const item of obj)
138
- if (predicate && !predicate(item))
109
+ function checkArray(value, predicate, requiredLength) {
110
+ if (!Array.isArray(value)) return false;
111
+ if (typeof requiredLength == "number" && requiredLength !== value.length) return false;
112
+ for (const item of value)
113
+ if (typeof predicate == "function" && !predicate(item))
139
114
  return false;
140
115
  return true;
141
116
  }
142
- function check_number_array(obj, requiredLength) {
143
- return check_array(obj, check_number, requiredLength);
117
+ function checkNumberArray(value, requiredLength) {
118
+ return checkArray(value, checkNumber, requiredLength);
144
119
  }
145
- function check_string_array(obj, requiredLength) {
146
- return check_array(obj, check_string, requiredLength);
120
+ function checkStringArray(value, requiredLength) {
121
+ return checkArray(value, checkString, requiredLength);
147
122
  }
148
- function has_property(obj, name, type) {
149
- return obj != null && typeof obj == "object" && name in obj && typeof obj[name] == type;
123
+ function hasProperty(value, propertyName, type) {
124
+ return value !== null && typeof value == "object" && propertyName in value && typeof value[propertyName] == type;
150
125
  }
126
+ var NodeJSCustomInspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
151
127
 
152
128
  // source/common/error.ts
153
129
  var ResolveError = class extends Error {
130
+ /**
131
+ * Create a resolve exception
132
+ * @param target The target type name
133
+ * @param value A value
134
+ */
154
135
  constructor(target, value) {
155
- super(`can't resolve ${value} to ${target}`);
136
+ super(`Can't resolve ${value} to ${target}`);
156
137
  this.target = target;
157
138
  this.value = value;
158
139
  }
159
140
  };
160
141
 
161
- // source/geometry/size.ts
162
- var Size = class _Size {
163
- width;
164
- height;
165
- get aspectRatio() {
166
- return this.height / this.width;
167
- }
168
- get area() {
169
- return this.width * this.height;
170
- }
171
- get perimeter() {
172
- return this.width + this.width + this.height + this.height;
173
- }
174
- static resolve(a) {
175
- const value = this.cast(a);
176
- if (typeof value != "undefined")
177
- return value;
178
- throw new ResolveError("Square", a);
179
- }
180
- static cast(a) {
181
- if (a == null || typeof a == "undefined")
182
- return void 0;
183
- if (check_number_array(a, 2))
184
- return new this(a[0], a[1]);
185
- if (has_property(a, "width", "number") && has_property(a, "height", "number"))
186
- return new this(a.width, a.height);
187
- if (check_string(a)) {
188
- const parts = a.split("x").map((v) => parseFloat(v));
189
- if (check_number_array(parts, 2))
190
- return this.cast(parts);
191
- }
192
- if (check_number(a))
193
- return new this(a, a);
194
- return void 0;
195
- }
196
- static is(a) {
197
- return typeof this.cast(a) != "undefined";
198
- }
199
- constructor(width, height) {
200
- if (!check_number(width))
201
- throw new TypeError("expected number for width");
202
- if (!check_number(height))
203
- throw new TypeError("expected number for height");
204
- this.width = width;
205
- this.height = height;
206
- }
207
- toArray() {
208
- return [this.width, this.height];
209
- }
210
- toString() {
211
- return `${this.width}x${this.height}`;
212
- }
213
- toJSON() {
214
- return {
215
- width: this.width,
216
- height: this.height
217
- };
218
- }
219
- clone() {
220
- return new _Size(this.width, this.height);
221
- }
222
- equals(square) {
223
- const s = _Size.resolve(square);
224
- return this.width == s.width && this.height == s.height;
225
- }
226
- toVec2() {
227
- return [this.width, this.height];
228
- }
229
- };
230
-
231
142
  // source/utils.ts
232
143
  function clamp(value, min, max) {
233
144
  if (value <= min)
@@ -236,7 +147,7 @@ function clamp(value, min, max) {
236
147
  return max;
237
148
  return value;
238
149
  }
239
- function log_hypot(a, b) {
150
+ function logHypot(a, b) {
240
151
  const a_abs = Math.abs(a);
241
152
  const b_abs = Math.abs(b);
242
153
  if (a == 0)
@@ -249,41 +160,43 @@ function log_hypot(a, b) {
249
160
  return 0.5 * Math.log(_a * _a + _b * _b) + Math.LN2;
250
161
  }
251
162
  var EPSILON = 1e-16;
163
+ var lerp = (a, b, t) => ((typeof a == "number" ? 1 : 1n) - t) * a + t * b;
252
164
 
253
- // source/vectors/vec3.ts
254
- var Vec3 = class _Vec3 {
165
+ // source/vectors/vec2.ts
166
+ var Vec2 = class _Vec2 {
255
167
  x;
256
168
  y;
257
- z;
258
169
  w;
259
170
  static resolve(a) {
260
171
  const value = this.cast(a);
261
172
  if (typeof value != "undefined")
262
173
  return value;
263
- throw new ResolveError("Vec3", a);
174
+ throw new ResolveError("Vec2", a);
264
175
  }
265
176
  static cast(a) {
266
177
  if (a == null || typeof a == "undefined")
267
178
  return void 0;
268
- if (check_number_array(a, 3) || check_number_array(a, 4))
269
- return new this(a[0], a[1], a[2], check_number(a[3]) ? a[3] : void 0);
270
- if (has_property(a, "x", "number") && has_property(a, "y", "number") && has_property(a, "z", "number"))
271
- return new this(a.x, a.y, a.z, has_property(a, "w", "number") ? a.w : void 0);
272
- if (check_string(a)) {
273
- const [sxyz, sw] = a.split(";");
274
- if (check_string(sxyz)) {
275
- const parts = sxyz.split(",");
276
- if (check_string_array(parts, 3))
277
- return new this(parseFloat(parts[0]), parseFloat(parts[1]), parseFloat(parts[2]), check_string(sw) ? parseFloat(sw) : void 0);
179
+ if (checkNumberArray(a, 2) || checkNumberArray(a, 3))
180
+ return new this(a[0], a[1], checkNumber(a[2]) ? a[2] : void 0);
181
+ if (hasProperty(a, "toVec2", "function"))
182
+ return this.cast(a.toVec2());
183
+ if (hasProperty(a, "x", "number") && hasProperty(a, "y", "number"))
184
+ return new this(a.x, a.y, hasProperty(a, "w", "number") ? a.w : void 0);
185
+ if (checkString(a)) {
186
+ const [sxy, sw] = a.split(";");
187
+ if (checkString(sxy)) {
188
+ const parts = sxy.split(",");
189
+ if (checkStringArray(parts, 2))
190
+ return new this(parseFloat(parts[0]), parseFloat(parts[1]), checkString(sw) ? parseFloat(sw) : void 0);
278
191
  }
279
192
  }
280
- if (check_number(a))
281
- return new this(a, a, a);
193
+ if (checkNumber(a))
194
+ return new this(a, a);
282
195
  return void 0;
283
196
  }
284
197
  static resolveArgs(args) {
285
- if (check_number_array(args, 3))
286
- return new this(args[0], args[1], args[2]);
198
+ if (checkNumberArray(args, 2))
199
+ return new this(args[0], args[1]);
287
200
  return this.resolve(args[0]);
288
201
  }
289
202
  static is(a) {
@@ -292,63 +205,79 @@ var Vec3 = class _Vec3 {
292
205
  static fromPoints(a, b) {
293
206
  const veca = this.resolve(a);
294
207
  const vecb = this.resolve(b);
295
- return new this(vecb.x - veca.x, vecb.y - veca.y, vecb.z - veca.z);
208
+ return new this(vecb.x - veca.x, vecb.y - veca.y);
296
209
  }
297
210
  static clamp(value, min, max) {
298
211
  const a = this.resolve(value), b = this.resolve(min), c = this.resolve(max);
299
212
  return new this(
300
213
  clamp(a.x, b.x, c.x),
301
- clamp(a.y, b.y, c.y),
302
- clamp(a.z, b.z, c.z)
214
+ clamp(a.y, b.y, c.y)
303
215
  );
304
216
  }
305
- static intersectPlane(planeP, planeN, lineStart, lineEnd, t) {
306
- planeN = this.resolve(planeN).normalize();
307
- const plane_d = -this.resolve(planeN).dot(planeP);
308
- const ad = this.resolve(lineStart).dot(planeN);
309
- const bd = this.resolve(lineEnd).dot(planeN);
310
- t = (-plane_d - ad) / (bd - ad);
311
- const lineStartToEnd = this.resolve(lineEnd).subtract(lineStart);
312
- const linetoIntersect = lineStartToEnd.multiply(t);
313
- return _Vec3.resolve(lineStart).add(linetoIntersect);
217
+ static get zero() {
218
+ return new this(0, 0);
314
219
  }
315
- constructor(x = 0, y = 0, z = 0, w = 1) {
316
- if (!check_number(x))
220
+ static get one() {
221
+ return new this(1, 1);
222
+ }
223
+ constructor(x, y, w = 1) {
224
+ if (!checkNumber(x))
317
225
  throw new TypeError("expected number for x");
318
- if (!check_number(y))
226
+ if (!checkNumber(y))
319
227
  throw new TypeError("expected number for y");
320
- if (!check_number(z))
321
- throw new TypeError("expected number for z");
322
- if (!check_number(w))
228
+ if (!checkNumber(w))
323
229
  throw new TypeError("expected number for w");
324
230
  this.x = x;
325
231
  this.y = y;
326
- this.z = z;
327
232
  this.w = w;
328
233
  }
329
- toArray(w = false) {
330
- return w ? [this.x, this.y, this.z] : [this.x, this.y, this.z, this.w];
234
+ toArray(w = this.w !== 1) {
235
+ return w ? [this.x, this.y, this.w] : [this.x, this.y];
331
236
  }
332
237
  toJSON() {
333
238
  return {
334
239
  x: this.x,
335
240
  y: this.y,
336
- z: this.z,
337
241
  w: this.w
338
242
  };
339
243
  }
340
- toString(w = false) {
341
- return w ? `${this.x},${this.y},${this.z}` : `${this.x},${this.y},${this.z};${this.w}`;
244
+ toString(w = this.w !== 1) {
245
+ return w ? `${this.x},${this.y};${this.w}` : `${this.x},${this.y}`;
342
246
  }
343
- toVec2() {
344
- return [this.x, this.y, this.w];
247
+ get [Symbol.toStringTag]() {
248
+ return "Vec2";
249
+ }
250
+ [NodeJSCustomInspect]() {
251
+ return `Vec2 <${this.toString()}>`;
252
+ }
253
+ toSize() {
254
+ return [this.x, this.y];
255
+ }
256
+ toVec3(z = 0) {
257
+ return [this.x, this.y, z, this.w];
258
+ }
259
+ toRGB() {
260
+ const vec = this.normalize();
261
+ return [vec.x, vec.y, vec.w];
262
+ }
263
+ toRGBA() {
264
+ const vec = this.normalize();
265
+ return [vec.x, vec.y, vec.w, 1];
266
+ }
267
+ toHSL() {
268
+ const vec = this.normalize();
269
+ return [vec.x, vec.y, vec.w];
270
+ }
271
+ toHSLA() {
272
+ const vec = this.normalize();
273
+ return [vec.x, vec.y, vec.w, 1];
345
274
  }
346
275
  clone() {
347
- return new _Vec3(this.x, this.y, this.z, this.w);
276
+ return new _Vec2(this.x, this.y, this.w);
348
277
  }
349
- equals(vec) {
350
- const a = _Vec3.resolve(vec);
351
- return this.x == a.x && this.y == a.y && this.z == a.z;
278
+ equals(...args) {
279
+ const a = _Vec2.resolveArgs(args);
280
+ return this.x == a.x && this.y == a.y;
352
281
  }
353
282
  setX(x) {
354
283
  this.x = x;
@@ -358,319 +287,125 @@ var Vec3 = class _Vec3 {
358
287
  this.y = y;
359
288
  return this;
360
289
  }
361
- setZ(z) {
362
- this.z = z;
290
+ setW(w) {
291
+ this.w = w;
363
292
  return this;
364
293
  }
365
294
  set(...args) {
366
- const vec = _Vec3.resolveArgs(args);
367
- return this.setX(vec.x).setY(vec.y).setZ(vec.z);
295
+ const vec = _Vec2.resolveArgs(args);
296
+ return this.setX(vec.x).setY(vec.y);
368
297
  }
369
298
  add(...args) {
370
- const vec = _Vec3.resolveArgs(args);
371
- return new _Vec3(
299
+ const vec = _Vec2.resolveArgs(args);
300
+ return new _Vec2(
372
301
  this.x + vec.x,
373
- this.y + vec.y,
374
- this.z + vec.z
302
+ this.y + vec.y
375
303
  );
376
304
  }
377
305
  offset(...args) {
378
- const vec = _Vec3.resolveArgs(args);
306
+ const vec = _Vec2.resolveArgs(args);
379
307
  this.x += vec.x;
380
308
  this.y += vec.y;
381
- this.z += vec.z;
382
309
  return this;
383
310
  }
384
311
  subtract(...args) {
385
- const vec = _Vec3.resolveArgs(args);
386
- return new _Vec3(
312
+ const vec = _Vec2.resolveArgs(args);
313
+ return new _Vec2(
387
314
  this.x - vec.x,
388
- this.y - vec.y,
389
- this.z - vec.z
315
+ this.y - vec.y
390
316
  );
391
317
  }
392
318
  multiply(scalar) {
393
- return new _Vec3(
319
+ return new _Vec2(
394
320
  this.x * scalar,
395
- this.y * scalar,
396
- this.z * scalar
321
+ this.y * scalar
397
322
  );
398
323
  }
399
324
  naiveMultiply(...args) {
400
- const vec = _Vec3.resolveArgs(args);
401
- return new _Vec3(
325
+ const vec = _Vec2.resolveArgs(args);
326
+ return new _Vec2(
402
327
  this.x * vec.x,
403
- this.y * vec.y,
404
- this.z * vec.z
328
+ this.y * vec.y
405
329
  );
406
330
  }
407
331
  divide(...args) {
408
- if (check_number_array(args, 1))
409
- return new _Vec3(
332
+ if (checkNumberArray(args, 1))
333
+ return new _Vec2(
410
334
  this.x / args[0],
411
- this.y / args[0],
412
- this.z / args[0]
335
+ this.y / args[0]
413
336
  );
414
- const vec = _Vec3.resolveArgs(args);
415
- return new _Vec3(
337
+ const vec = _Vec2.resolveArgs(args);
338
+ return new _Vec2(
416
339
  this.x / vec.x,
417
- this.y / vec.y,
418
- this.z / vec.z
340
+ this.y / vec.y
419
341
  );
420
342
  }
421
343
  dot(...args) {
422
- const vec = _Vec3.resolveArgs(args);
423
- return this.x * vec.x + this.y * vec.y + this.z * vec.z;
424
- }
425
- cross(...args) {
426
- const vec = _Vec3.resolveArgs(args);
427
- return new _Vec3(
428
- this.y * vec.z - this.z * vec.y,
429
- this.z * vec.x - this.x * vec.z,
430
- this.x * vec.y - this.y * vec.x
431
- );
344
+ const vec = _Vec2.resolveArgs(args);
345
+ return this.x * vec.x + this.y * vec.y;
432
346
  }
433
347
  distance(...args) {
434
- const vec = _Vec3.resolveArgs(args);
435
- return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2);
348
+ const vec = _Vec2.resolveArgs(args);
349
+ return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2);
436
350
  }
437
351
  distanceSquare(...args) {
438
- const vec = _Vec3.resolveArgs(args);
439
- return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2));
352
+ const vec = _Vec2.resolveArgs(args);
353
+ return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2));
440
354
  }
441
355
  length() {
442
- return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
356
+ return Math.sqrt(this.x * this.x + this.y * this.y);
357
+ }
358
+ cartesianify() {
359
+ return new _Vec2(
360
+ this.x * Math.cos(this.y),
361
+ this.x * Math.sin(this.y)
362
+ );
363
+ }
364
+ polarify() {
365
+ return new _Vec2(
366
+ Math.sqrt(this.x * this.x + this.y * this.y),
367
+ Math.atan(this.y / this.x)
368
+ );
443
369
  }
444
370
  normalize() {
445
371
  const length = this.length();
446
- if (length == 0) return new _Vec3();
447
- return new _Vec3(
372
+ if (length == 0) return _Vec2.zero;
373
+ return new _Vec2(
448
374
  this.x / length,
449
375
  this.y / length,
450
- this.z / length
376
+ this.w / length
451
377
  );
452
378
  }
453
379
  invert() {
454
380
  return this.multiply(-1);
455
381
  }
456
382
  round() {
457
- return new _Vec3(Math.round(this.x), Math.round(this.y), Math.round(this.z), Math.round(this.w));
383
+ return new _Vec2(Math.round(this.x), Math.round(this.y), Math.round(this.w));
458
384
  }
459
385
  };
460
386
 
461
- // source/vectors/vec2.ts
462
- var Vec2 = class _Vec2 {
463
- x;
464
- y;
465
- w;
466
- static resolve(a) {
467
- const value = this.cast(a);
468
- if (typeof value != "undefined")
469
- return value;
470
- throw new ResolveError("Vec2", a);
471
- }
472
- static cast(a) {
473
- if (a == null || typeof a == "undefined")
474
- return void 0;
475
- if (check_number_array(a, 2) || check_number_array(a, 3))
476
- return new this(a[0], a[1], check_number(a[2]) ? a[2] : void 0);
477
- if (has_property(a, "x", "number") && has_property(a, "y", "number"))
478
- return new this(a.x, a.y, has_property(a, "w", "number") ? a.w : void 0);
479
- if (check_string(a)) {
480
- const [sxy, sw] = a.split(";");
481
- if (check_string(sxy)) {
482
- const parts = sxy.split(",");
483
- if (check_string_array(parts, 2))
484
- return new this(parseFloat(parts[0]), parseFloat(parts[1]), check_string(sw) ? parseFloat(sw) : void 0);
485
- }
486
- }
487
- if (check_number(a))
488
- return new this(a, a);
489
- return void 0;
490
- }
491
- static resolveArgs(args) {
492
- if (check_number_array(args, 2))
493
- return new this(args[0], args[1]);
494
- return this.resolve(args[0]);
495
- }
496
- static is(a) {
497
- return typeof this.cast(a) != "undefined";
498
- }
387
+ // source/algebra/linear.ts
388
+ var LinearFunction = class extends MathFunction {
389
+ /**
390
+ * The factor of the linear function
391
+ */
392
+ m;
393
+ /**
394
+ * The height of the linear function
395
+ */
396
+ b;
397
+ /**
398
+ * Create a linear function from two points
399
+ * @param a A point
400
+ * @param b A point
401
+ * @returns A linear function from two points
402
+ */
499
403
  static fromPoints(a, b) {
500
- const veca = this.resolve(a);
501
- const vecb = this.resolve(b);
502
- return new this(vecb.x - veca.x, vecb.y - veca.y);
503
- }
504
- static clamp(value, min, max) {
505
- const a = this.resolve(value), b = this.resolve(min), c = this.resolve(max);
506
- return new this(
507
- clamp(a.x, b.x, c.x),
508
- clamp(a.y, b.y, c.y)
509
- );
510
- }
511
- constructor(x = 0, y = 0, w = 1) {
512
- if (!check_number(x))
513
- throw new TypeError("expected number for x");
514
- if (!check_number(y))
515
- throw new TypeError("expected number for y");
516
- if (!check_number(w))
517
- throw new TypeError("expected number for w");
518
- this.x = x;
519
- this.y = y;
520
- this.w = w;
521
- }
522
- toArray(w = false) {
523
- return w ? [this.x, this.y] : [this.x, this.y, this.w];
524
- }
525
- toJSON() {
526
- return {
527
- x: this.x,
528
- y: this.y,
529
- w: this.w
530
- };
531
- }
532
- toString(w = false) {
533
- return w ? `${this.x},${this.y}` : `${this.x},${this.y};${this.w}`;
534
- }
535
- toSquare() {
536
- return new Size(this.x, this.y);
537
- }
538
- toVec3(z) {
539
- return new Vec3(this.x, this.y, z, this.w);
540
- }
541
- clone() {
542
- return new _Vec2(this.x, this.y, this.w);
543
- }
544
- equals(vec) {
545
- const a = _Vec2.resolve(vec);
546
- return this.x == a.x && this.y == a.y;
547
- }
548
- setX(x) {
549
- this.x = x;
550
- return this;
551
- }
552
- setY(y) {
553
- this.y = y;
554
- return this;
555
- }
556
- setW(w) {
557
- this.w = w;
558
- return this;
559
- }
560
- set(...args) {
561
- const vec = _Vec2.resolveArgs(args);
562
- return this.setX(vec.x).setY(vec.y);
563
- }
564
- add(...args) {
565
- const vec = _Vec2.resolveArgs(args);
566
- return new _Vec2(
567
- this.x + vec.x,
568
- this.y + vec.y
569
- );
570
- }
571
- offset(...args) {
572
- const vec = _Vec2.resolveArgs(args);
573
- this.x += vec.x;
574
- this.y += vec.y;
575
- return this;
576
- }
577
- subtract(...args) {
578
- const vec = _Vec2.resolveArgs(args);
579
- return new _Vec2(
580
- this.x - vec.x,
581
- this.y - vec.y
582
- );
583
- }
584
- multiply(scalar) {
585
- return new _Vec2(
586
- this.x * scalar,
587
- this.y * scalar
588
- );
589
- }
590
- naiveMultiply(...args) {
591
- const vec = _Vec2.resolveArgs(args);
592
- return new _Vec2(
593
- this.x * vec.x,
594
- this.y * vec.y
595
- );
596
- }
597
- divide(...args) {
598
- if (check_number_array(args, 1))
599
- return new _Vec2(
600
- this.x / args[0],
601
- this.y / args[0]
602
- );
603
- const vec = _Vec2.resolveArgs(args);
604
- return new _Vec2(
605
- this.x / vec.x,
606
- this.y / vec.y
607
- );
608
- }
609
- dot(...args) {
610
- const vec = _Vec2.resolveArgs(args);
611
- return this.x * vec.x + this.y * vec.y;
612
- }
613
- distance(...args) {
614
- const vec = _Vec2.resolveArgs(args);
615
- return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2);
616
- }
617
- distanceSquare(...args) {
618
- const vec = _Vec2.resolveArgs(args);
619
- return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2));
620
- }
621
- length() {
622
- return Math.sqrt(this.x * this.x + this.y * this.y);
623
- }
624
- cartesianify() {
625
- return new _Vec2(
626
- this.x * Math.cos(this.y),
627
- this.x * Math.sin(this.y)
628
- );
629
- }
630
- polarify() {
631
- return new _Vec2(
632
- Math.sqrt(this.x * this.x + this.y * this.y),
633
- Math.atan(this.y / this.x)
634
- );
635
- }
636
- normalize() {
637
- const length = this.length();
638
- if (length == 0) return new _Vec2();
639
- return new _Vec2(
640
- this.x / length,
641
- this.y / length
642
- );
643
- }
644
- invert() {
645
- return this.multiply(-1);
646
- }
647
- round() {
648
- return new _Vec2(Math.round(this.x), Math.round(this.y), Math.round(this.w));
649
- }
650
- };
651
-
652
- // source/algebra/linear.ts
653
- var LinearFunction = class extends MathFunction {
654
- /**
655
- * The factor of the linear function
656
- */
657
- m;
658
- /**
659
- * The height of the linear function
660
- */
661
- b;
662
- /**
663
- * Create a linear function from two points
664
- * @param a A point
665
- * @param b A point
666
- * @returns A linear function from two points
667
- */
668
- static fromPoints(a, b) {
669
- const veca = Vec2.resolve(a);
670
- const vecb = Vec2.resolve(b);
671
- const m = (vecb.y - veca.y) / (vecb.x - veca.x);
672
- const h = -m * veca.x + veca.y;
673
- return new this(m, h);
404
+ const veca = Vec2.resolve(a);
405
+ const vecb = Vec2.resolve(b);
406
+ const m = (vecb.y - veca.y) / (vecb.x - veca.x);
407
+ const h = -m * veca.x + veca.y;
408
+ return new this(m, h);
674
409
  }
675
410
  /**
676
411
  * Create a linear function with a factor and height
@@ -679,30 +414,36 @@ var LinearFunction = class extends MathFunction {
679
414
  */
680
415
  constructor(m, b) {
681
416
  super();
682
- if (!check_number(m))
417
+ if (!checkNumber(m))
683
418
  throw new TypeError("expected number for m");
684
- if (!check_number(b))
419
+ if (!checkNumber(b))
685
420
  throw new TypeError("expected number for b");
686
421
  this.m = m;
687
422
  this.b = b;
688
423
  }
689
424
  get(x) {
690
- if (!check_number(x))
425
+ if (!checkNumber(x))
691
426
  throw new TypeError("expected number for x");
692
427
  return this.m;
693
428
  }
694
429
  roots() {
695
430
  const x = -this.b / this.m;
696
431
  if (!isNaN(x))
697
- return [new Vec2(x)];
432
+ return [new Vec2(x, 0)];
698
433
  return [];
699
434
  }
700
435
  toString() {
701
- const bsign = sign_char(this.b);
436
+ const bsign = signCharacter(this.b);
702
437
  if (bsign)
703
438
  return `f(x) = ${this.m} * x ${bsign} ${Math.abs(this.b)}`;
704
439
  return `f(x) = ${this.m} * x`;
705
440
  }
441
+ get [Symbol.toStringTag]() {
442
+ return "LinearFunction";
443
+ }
444
+ [NodeJSCustomInspect]() {
445
+ return `LinearFunction <${this.toString()}>`;
446
+ }
706
447
  };
707
448
 
708
449
  // source/algebra/quad.ts
@@ -715,20 +456,20 @@ var QuadFunction = class extends MathFunction {
715
456
  }
716
457
  constructor(a, b, c) {
717
458
  super();
718
- if (!check_number(a))
459
+ if (!checkNumber(a))
719
460
  throw new TypeError("expected number for a");
720
461
  if (a == 0)
721
462
  throw new TypeError("a cannot be 0");
722
- if (!check_number(b))
463
+ if (!checkNumber(b))
723
464
  throw new TypeError("expected number for b");
724
- if (!check_number(c))
465
+ if (!checkNumber(c))
725
466
  throw new TypeError("expected number for c");
726
467
  this.a = a;
727
468
  this.b = b;
728
469
  this.c = c;
729
470
  }
730
471
  get(x) {
731
- if (!check_number(x))
472
+ if (!checkNumber(x))
732
473
  throw new TypeError("expected number for x");
733
474
  return this.a * x * x + this.b * x + this.c;
734
475
  }
@@ -738,17 +479,17 @@ var QuadFunction = class extends MathFunction {
738
479
  const n0 = (-this.b + Math.sqrt(discriminant)) / (2 * this.a);
739
480
  const n1 = (-this.b + Math.sqrt(discriminant)) / (2 * this.a);
740
481
  if (!isNaN(n0))
741
- roots.push(new Vec2(n0));
482
+ roots.push(new Vec2(n0, 0));
742
483
  if (!isNaN(n1) && n0 != n1)
743
- roots.push(new Vec2(n1));
484
+ roots.push(new Vec2(n1, 0));
744
485
  return roots;
745
486
  }
746
487
  toString(type = "standard") {
747
488
  switch (type) {
748
489
  default:
749
490
  case "standard": {
750
- const bsign = sign_char(this.b);
751
- const csign = sign_char(this.c);
491
+ const bsign = signCharacter(this.b);
492
+ const csign = signCharacter(this.c);
752
493
  if (bsign && csign)
753
494
  return `f(x) = ${this.a}x^2 ${bsign} ${Math.abs(this.b)}x ${csign} ${Math.abs(this.c)}`;
754
495
  if (bsign)
@@ -757,17 +498,18 @@ var QuadFunction = class extends MathFunction {
757
498
  }
758
499
  }
759
500
  }
501
+ get [Symbol.toStringTag]() {
502
+ return "QuadFunction";
503
+ }
504
+ [NodeJSCustomInspect]() {
505
+ return `QuadFunction <${this.toString()}>`;
506
+ }
760
507
  };
761
508
 
762
- // source/common/string.ts
763
- function stringify(value) {
764
- return value != null && typeof value == "object" && "toString" in value && typeof value.toString == "function" ? value.toString() : String(value);
765
- }
766
-
767
509
  // source/crypto/hash.ts
768
510
  var DJB2_OFFSET = 5381n;
769
511
  function djb2(value) {
770
- const string = stringify(value);
512
+ const string = String(value);
771
513
  let hash = DJB2_OFFSET;
772
514
  for (let i = 0; i < string.length; i++) {
773
515
  hash = (hash << 5n) + hash + BigInt(string.charCodeAt(i));
@@ -777,7 +519,7 @@ function djb2(value) {
777
519
  var FNV1_OFFSET = 14695981039346656037n;
778
520
  var FNV1_PRIME = 1099511628211n;
779
521
  function fnv1(value) {
780
- const string = stringify(value);
522
+ const string = String(value);
781
523
  let hash = FNV1_OFFSET;
782
524
  for (let i = 0; i < string.length; i++) {
783
525
  hash *= FNV1_PRIME;
@@ -786,7 +528,7 @@ function fnv1(value) {
786
528
  return hash;
787
529
  }
788
530
  function sdbm(value) {
789
- const string = stringify(value);
531
+ const string = String(value);
790
532
  let hash = 0n;
791
533
  for (let i = 0; i < string.length; i++) {
792
534
  hash = BigInt(string.charCodeAt(i)) + (hash << 6n) + (hash << 16n) - hash;
@@ -1103,14 +845,23 @@ var MD2 = class _MD2 {
1103
845
  this._transform(this._checksum);
1104
846
  return this._state.slice();
1105
847
  }
848
+ toString() {
849
+ return "";
850
+ }
851
+ get [Symbol.toStringTag]() {
852
+ return "MD2";
853
+ }
854
+ [NodeJSCustomInspect]() {
855
+ return `MD2 <${this.toString()}>`;
856
+ }
1106
857
  };
1107
858
 
1108
859
  // source/geometry/angle.ts
1109
860
  var MAX_ANGLE_DEGREE = 360;
1110
- var cap_angle_degree = (angle) => angle % MAX_ANGLE_DEGREE;
1111
- var cap_angle_radian = (angle) => cap_angle_degree(degree_to_radian(angle));
1112
- var radian_to_degree = (angle) => angle * (180 / Math.PI);
1113
- var degree_to_radian = (angle) => angle * (Math.PI / 180);
861
+ var clampAngleDegree = (angle) => angle % MAX_ANGLE_DEGREE;
862
+ var clampAngleRadian = (angle) => clampAngleDegree(degreeToRadian(angle));
863
+ var radianToDegree = (angle) => angle * (180 / Math.PI);
864
+ var degreeToRadian = (angle) => angle * (Math.PI / 180);
1114
865
 
1115
866
  // source/geometry/circle.ts
1116
867
  var Circle = class _Circle {
@@ -1146,19 +897,28 @@ var Circle = class _Circle {
1146
897
  return value;
1147
898
  throw new ResolveError("Circle", a);
1148
899
  }
900
+ static resolveArgs(args) {
901
+ if (checkNumberArray(args, 3))
902
+ return new this([args[0], args[1]], args[2]);
903
+ if (args.length === 2)
904
+ return new this(args[0], args[1]);
905
+ return this.resolve(args[0]);
906
+ }
1149
907
  static cast(a) {
1150
908
  if (a == null || typeof a == "undefined")
1151
909
  return void 0;
1152
- if (check_number_array(a, 3))
910
+ if (checkNumberArray(a, 3))
1153
911
  return new this([a[0], a[1]], a[2]);
1154
- if (check_number_array(a, 4)) {
912
+ if (checkNumberArray(a, 4)) {
1155
913
  const c = new this([a[0], a[1]], a[3]);
1156
914
  c.w = a[2];
1157
915
  return c;
1158
916
  }
1159
- if (has_property(a, "x", "number") && has_property(a, "y", "number") && has_property(a, "radius", "number"))
1160
- return new this(has_property(a, "w", "number") ? [a.x, a.y, a.w] : [a.x, a.y], a.radius);
1161
- if (check_string(a)) {
917
+ if (hasProperty(a, "toCircle", "function"))
918
+ return this.cast(a.toCircle());
919
+ if (hasProperty(a, "x", "number") && hasProperty(a, "y", "number") && hasProperty(a, "radius", "number"))
920
+ return new this(hasProperty(a, "w", "number") ? [a.x, a.y, a.w] : [a.x, a.y], a.radius);
921
+ if (checkString(a)) {
1162
922
  const [spos, sradius] = a.split("|");
1163
923
  const pos = Vec2.cast(spos);
1164
924
  if (typeof pos == "undefined")
@@ -1174,7 +934,7 @@ var Circle = class _Circle {
1174
934
  }
1175
935
  constructor(position, radius) {
1176
936
  this.position = Vec2.resolve(position);
1177
- if (!check_number(radius))
937
+ if (!checkNumber(radius))
1178
938
  throw new TypeError("expected number for radius");
1179
939
  this.radius = radius;
1180
940
  }
@@ -1190,22 +950,246 @@ var Circle = class _Circle {
1190
950
  toString() {
1191
951
  return `${this.position.toString()}|${this.radius}`;
1192
952
  }
953
+ get [Symbol.toStringTag]() {
954
+ return "Circle";
955
+ }
956
+ [NodeJSCustomInspect]() {
957
+ return `Circle <${this.toString()}>`;
958
+ }
1193
959
  clone() {
1194
960
  return new _Circle(this.position.clone(), this.radius);
1195
961
  }
1196
- equals(circle) {
1197
- const c = _Circle.resolve(circle);
962
+ toVec2() {
963
+ return [this.x, this.y, this.w];
964
+ }
965
+ equals(...args) {
966
+ const c = _Circle.resolveArgs(args);
1198
967
  return c.position.equals(c.position) && this.radius == c.radius;
1199
968
  }
1200
- inside(a) {
1201
- const circle = _Circle.resolve(a);
969
+ inside(...args) {
970
+ const circle = _Circle.resolveArgs(args);
1202
971
  const distX = circle.x - this.x;
1203
972
  const distY = circle.y - this.y;
1204
973
  const dist = Math.sqrt(distX * distX + (distY + distY));
1205
974
  return dist <= this.radius + circle.radius;
1206
975
  }
1207
- insidePoint(a) {
1208
- return this.position.distance(a) <= this.radius;
976
+ insidePoint(...args) {
977
+ return this.position.distance(Vec2.resolveArgs(args)) <= this.radius;
978
+ }
979
+ };
980
+
981
+ // source/geometry/bbox.ts
982
+ var BoundingBox = class _BoundingBox {
983
+ left;
984
+ right;
985
+ top;
986
+ bottom;
987
+ get width() {
988
+ return this.right - this.left;
989
+ }
990
+ set width(val) {
991
+ this.right = this.left + val;
992
+ }
993
+ get height() {
994
+ return this.bottom - this.top;
995
+ }
996
+ set height(val) {
997
+ this.bottom = this.top + val;
998
+ }
999
+ get x() {
1000
+ return this.left;
1001
+ }
1002
+ set x(x) {
1003
+ this.left = x;
1004
+ }
1005
+ get y() {
1006
+ return this.top;
1007
+ }
1008
+ set y(y) {
1009
+ this.top = y;
1010
+ }
1011
+ w = 1;
1012
+ static resolve(a) {
1013
+ const value = this.cast(a);
1014
+ if (typeof value != "undefined")
1015
+ return value;
1016
+ throw new ResolveError("BoundingBox", a);
1017
+ }
1018
+ static resolveArgs(args) {
1019
+ if (checkNumberArray(args, 4))
1020
+ return new this(args[0], args[1], args[2], args[3]);
1021
+ return this.resolve(args[0]);
1022
+ }
1023
+ static cast(a) {
1024
+ if (a == null || typeof a == "undefined")
1025
+ return void 0;
1026
+ if (checkNumberArray(a, 4))
1027
+ return new this(a[0], a[1], a[2], a[3]);
1028
+ if (hasProperty(a, "toBoundingBox", "function"))
1029
+ return this.cast(a.toBoundingBox());
1030
+ if (hasProperty(a, "left", "number") && hasProperty(a, "right", "number") && hasProperty(a, "top", "number") && hasProperty(a, "bottom", "number"))
1031
+ return new this(a.left, a.right, a.top, a.bottom);
1032
+ if (checkString(a)) {
1033
+ const parts = a.split(",");
1034
+ if (checkStringArray(parts, 4))
1035
+ return this.cast(parts.map((v) => parseFloat(v)));
1036
+ }
1037
+ return void 0;
1038
+ }
1039
+ static is(a) {
1040
+ return typeof this.cast(a) != "undefined";
1041
+ }
1042
+ constructor(left, right, top, bottom) {
1043
+ if (!checkNumber(left))
1044
+ throw new TypeError("expected number for left");
1045
+ if (!checkNumber(right))
1046
+ throw new TypeError("expected number for right");
1047
+ if (!checkNumber(top))
1048
+ throw new TypeError("expected number for top");
1049
+ if (!checkNumber(bottom))
1050
+ throw new TypeError("expected number for bottom");
1051
+ this.left = left;
1052
+ this.right = right;
1053
+ this.top = top;
1054
+ this.bottom = bottom;
1055
+ }
1056
+ toArray() {
1057
+ return [this.left, this.right, this.top, this.bottom];
1058
+ }
1059
+ toString() {
1060
+ return `${this.left},${this.right},${this.top},${this.bottom}`;
1061
+ }
1062
+ get [Symbol.toStringTag]() {
1063
+ return "BoundingBox";
1064
+ }
1065
+ [NodeJSCustomInspect]() {
1066
+ return `BoundingBox <${this.toString()}>`;
1067
+ }
1068
+ toJSON() {
1069
+ return {
1070
+ left: this.left,
1071
+ top: this.top,
1072
+ right: this.right,
1073
+ bottom: this.bottom
1074
+ };
1075
+ }
1076
+ clone() {
1077
+ return new _BoundingBox(this.left, this.right, this.top, this.bottom);
1078
+ }
1079
+ equals(...args) {
1080
+ const b = _BoundingBox.resolveArgs(args);
1081
+ return this.left === b.left && this.right === b.right && this.top === b.top && this.bottom === b.bottom;
1082
+ }
1083
+ toSize() {
1084
+ return [this.width, this.height];
1085
+ }
1086
+ toVec2() {
1087
+ return [this.left, this.top];
1088
+ }
1089
+ toRectangle() {
1090
+ return [this.left, this.top, this.width, this.height];
1091
+ }
1092
+ inside(...args) {
1093
+ const bbox = _BoundingBox.resolve(args);
1094
+ return this.right >= bbox.left && bbox.right >= this.left && this.bottom >= bbox.top && bbox.bottom >= this.top;
1095
+ }
1096
+ insidePoint(...args) {
1097
+ const point = Vec2.resolveArgs(args);
1098
+ return this.left <= point.x && this.right >= point.x && this.top <= point.y && this.bottom >= point.y;
1099
+ }
1100
+ insideCircle(...args) {
1101
+ const circle = Circle.resolveArgs(args);
1102
+ const center = Vec2.resolve(circle).add(circle.radius);
1103
+ const bboxhe = new Vec2(this.width / 2, this.height / 2);
1104
+ const bboxcenter = new Vec2(this.left + bboxhe.x, this.top + bboxhe.y);
1105
+ let diff = center.subtract(bboxcenter);
1106
+ const clamped = Vec2.clamp(diff, bboxhe.invert(), bboxhe);
1107
+ const closest = bboxcenter.add(clamped);
1108
+ diff = closest.subtract(center);
1109
+ return diff.length() < circle.radius;
1110
+ }
1111
+ };
1112
+
1113
+ // source/geometry/size.ts
1114
+ var Size = class _Size {
1115
+ width;
1116
+ height;
1117
+ get aspectRatio() {
1118
+ return this.height / this.width;
1119
+ }
1120
+ get area() {
1121
+ return this.width * this.height;
1122
+ }
1123
+ get perimeter() {
1124
+ return this.width + this.width + this.height + this.height;
1125
+ }
1126
+ static resolve(a) {
1127
+ const value = this.cast(a);
1128
+ if (typeof value != "undefined")
1129
+ return value;
1130
+ throw new ResolveError("Square", a);
1131
+ }
1132
+ static resolveArgs(args) {
1133
+ if (checkNumberArray(args, 2))
1134
+ return new this(args[0], args[1]);
1135
+ return this.resolve(args[0]);
1136
+ }
1137
+ static cast(a) {
1138
+ if (a == null || typeof a == "undefined")
1139
+ return void 0;
1140
+ if (checkNumberArray(a, 2))
1141
+ return new this(a[0], a[1]);
1142
+ if (hasProperty(a, "toSize", "function"))
1143
+ return this.cast(a.toSize());
1144
+ if (hasProperty(a, "width", "number") && hasProperty(a, "height", "number"))
1145
+ return new this(a.width, a.height);
1146
+ if (checkString(a)) {
1147
+ const parts = a.split("x").map((v) => parseFloat(v));
1148
+ if (checkNumberArray(parts, 2))
1149
+ return this.cast(parts);
1150
+ }
1151
+ if (checkNumber(a))
1152
+ return new this(a, a);
1153
+ return void 0;
1154
+ }
1155
+ static is(a) {
1156
+ return typeof this.cast(a) != "undefined";
1157
+ }
1158
+ constructor(width, height) {
1159
+ if (!checkNumber(width))
1160
+ throw new TypeError("expected number for width");
1161
+ if (!checkNumber(height))
1162
+ throw new TypeError("expected number for height");
1163
+ this.width = width;
1164
+ this.height = height;
1165
+ }
1166
+ toArray() {
1167
+ return [this.width, this.height];
1168
+ }
1169
+ toString() {
1170
+ return `${this.width}x${this.height}`;
1171
+ }
1172
+ get [Symbol.toStringTag]() {
1173
+ return "Size";
1174
+ }
1175
+ [NodeJSCustomInspect]() {
1176
+ return `Size <${this.toString()}>`;
1177
+ }
1178
+ toJSON() {
1179
+ return {
1180
+ width: this.width,
1181
+ height: this.height
1182
+ };
1183
+ }
1184
+ clone() {
1185
+ return new _Size(this.width, this.height);
1186
+ }
1187
+ equals(...args) {
1188
+ const s = _Size.resolveArgs(args);
1189
+ return this.width == s.width && this.height == s.height;
1190
+ }
1191
+ toVec2() {
1192
+ return [this.width, this.height];
1209
1193
  }
1210
1194
  };
1211
1195
 
@@ -1255,29 +1239,36 @@ var Rectangle = class _Rectangle {
1255
1239
  return value;
1256
1240
  throw new ResolveError("Rectangle", a);
1257
1241
  }
1242
+ static resolveArgs(args) {
1243
+ if (checkNumberArray(args, 4))
1244
+ return new this([args[0], args[1]], [args[2], args[3]]);
1245
+ return this.resolve(args[0]);
1246
+ }
1258
1247
  static cast(a) {
1259
1248
  if (a == null || typeof a == "undefined")
1260
1249
  return void 0;
1261
- if (check_number_array(a, 4))
1262
- return new this(a[0], a[1], a[2], a[3]);
1263
- if (check_number_array(a, 5)) {
1264
- const rect = new this(a[0], a[1], a[3], a[4]);
1250
+ if (checkNumberArray(a, 4))
1251
+ return new this([a[0], a[1]], [a[2], a[3]]);
1252
+ if (checkNumberArray(a, 5)) {
1253
+ const rect = new this([a[0], a[1]], [a[3], a[4]]);
1265
1254
  rect.w = a[2];
1266
1255
  return rect;
1267
1256
  }
1268
- if (check_string(a)) {
1257
+ if (checkString(a)) {
1269
1258
  const [spos, ssize] = a.split("|");
1270
1259
  const pos = Vec2.cast(spos);
1271
1260
  const size = Size.cast(ssize);
1272
1261
  if (typeof pos == "undefined" || typeof size == "undefined")
1273
1262
  return void 0;
1274
- const rect = new this(pos.x, pos.y, size.width, size.height);
1263
+ const rect = new this([pos.x, pos.y], [size.width, size.height]);
1275
1264
  rect.w = pos.w;
1276
1265
  return rect;
1277
1266
  }
1278
- if (has_property(a, "x", "number") && has_property(a, "y", "number") && has_property(a, "width", "number") && has_property(a, "height", "number")) {
1279
- const rect = new this(a.x, a.y, a.width, a.height);
1280
- if (has_property(a, "w", "number"))
1267
+ if (hasProperty(a, "toRectangle", "function"))
1268
+ return this.cast(a.toRectangle());
1269
+ if (hasProperty(a, "x", "number") && hasProperty(a, "y", "number") && hasProperty(a, "width", "number") && hasProperty(a, "height", "number")) {
1270
+ const rect = new this([a.x, a.y], [a.width, a.height]);
1271
+ if (hasProperty(a, "w", "number"))
1281
1272
  rect.w = a.w;
1282
1273
  return rect;
1283
1274
  }
@@ -1286,150 +1277,290 @@ var Rectangle = class _Rectangle {
1286
1277
  static is(a) {
1287
1278
  return typeof this.cast(a) != "undefined";
1288
1279
  }
1289
- constructor(a, b, c, d) {
1290
- const vec = Vec2.is(a) ? Vec2.resolve(a) : void 0;
1291
- const size = Size.is(b) ? Size.resolve(b) : void 0;
1292
- const x = typeof a == "number" ? a : vec?.x;
1293
- if (!check_number(x))
1294
- throw new TypeError("expected number for x position");
1295
- const y = typeof b == "number" ? b : vec?.y;
1296
- if (!check_number(y))
1297
- throw new TypeError("expected number for y position");
1298
- const width = typeof c == "number" ? c : size?.width;
1299
- if (!check_number(width))
1300
- throw new TypeError("expected number for width");
1301
- const height = typeof d == "number" ? d : size?.height;
1302
- if (!check_number(height))
1303
- throw new TypeError("expected number for height");
1304
- this.position = new Vec2(x, y);
1305
- this.size = new Size(width, height);
1280
+ constructor(pos, size) {
1281
+ this.position = Vec2.resolve(pos);
1282
+ this.size = Size.resolve(size);
1306
1283
  }
1307
- toArray(w = false) {
1284
+ toArray(w = this.w !== 1) {
1308
1285
  return [...this.position.toArray(w), ...this.size.toArray()];
1309
1286
  }
1310
- toString(w = false) {
1287
+ toString(w = this.w !== 1) {
1311
1288
  return `${this.position.toString(w)}|${this.size.toString()}`;
1312
1289
  }
1290
+ get [Symbol.toStringTag]() {
1291
+ return "Rectangle";
1292
+ }
1293
+ [NodeJSCustomInspect]() {
1294
+ return `Rectangle <${this.toString()}>`;
1295
+ }
1313
1296
  toJSON() {
1314
1297
  return { ...this.position.toJSON(), ...this.size.toJSON() };
1315
1298
  }
1316
1299
  toBoundingBox() {
1317
1300
  return [this.x, this.x + this.width, this.y, this.y + this.height];
1318
1301
  }
1302
+ toVec2() {
1303
+ return [this.x, this.y, this.w];
1304
+ }
1305
+ toSize() {
1306
+ return [this.width, this.height];
1307
+ }
1319
1308
  clone() {
1320
1309
  return new _Rectangle(this.position.clone(), this.size.clone());
1321
1310
  }
1322
- equals(rectangle) {
1323
- const rect = _Rectangle.resolve(rectangle);
1311
+ equals(...args) {
1312
+ const rect = _Rectangle.resolveArgs(args);
1324
1313
  return this.position.equals(rect.position) && this.size.equals(rect.size);
1325
1314
  }
1326
1315
  };
1327
1316
 
1328
- // source/geometry/bbox.ts
1329
- var BoundingBox = class _BoundingBox {
1330
- left;
1331
- right;
1332
- top;
1333
- bottom;
1334
- get width() {
1335
- return this.right - this.left;
1317
+ // source/common/string.ts
1318
+ function stringify(value) {
1319
+ return value != null && typeof value == "object" && "toString" in value && typeof value.toString == "function" ? value.toString() : String(value);
1320
+ }
1321
+
1322
+ // source/vectors/vec3.ts
1323
+ var Vec3 = class _Vec3 {
1324
+ x;
1325
+ y;
1326
+ z;
1327
+ w;
1328
+ static resolve(a) {
1329
+ const value = this.cast(a);
1330
+ if (typeof value != "undefined")
1331
+ return value;
1332
+ throw new ResolveError("Vec3", a);
1333
+ }
1334
+ static cast(a) {
1335
+ if (a == null || typeof a == "undefined")
1336
+ return void 0;
1337
+ if (checkNumberArray(a, 3) || checkNumberArray(a, 4))
1338
+ return new this(a[0], a[1], a[2], checkNumber(a[3]) ? a[3] : void 0);
1339
+ if (hasProperty(a, "x", "number") && hasProperty(a, "y", "number") && hasProperty(a, "z", "number"))
1340
+ return new this(a.x, a.y, a.z, hasProperty(a, "w", "number") ? a.w : void 0);
1341
+ if (checkString(a)) {
1342
+ const [sxyz, sw] = a.split(";");
1343
+ if (checkString(sxyz)) {
1344
+ const parts = sxyz.split(",");
1345
+ if (checkStringArray(parts, 3))
1346
+ return new this(parseFloat(parts[0]), parseFloat(parts[1]), parseFloat(parts[2]), checkString(sw) ? parseFloat(sw) : void 0);
1347
+ }
1348
+ }
1349
+ if (checkNumber(a))
1350
+ return new this(a, a, a);
1351
+ return void 0;
1352
+ }
1353
+ static resolveArgs(args) {
1354
+ if (checkNumberArray(args, 3))
1355
+ return new this(args[0], args[1], args[2]);
1356
+ return this.resolve(args[0]);
1357
+ }
1358
+ static is(a) {
1359
+ return typeof this.cast(a) != "undefined";
1360
+ }
1361
+ static fromPoints(a, b) {
1362
+ const veca = this.resolve(a);
1363
+ const vecb = this.resolve(b);
1364
+ return new this(vecb.x - veca.x, vecb.y - veca.y, vecb.z - veca.z);
1365
+ }
1366
+ static clamp(value, min, max) {
1367
+ const a = this.resolve(value), b = this.resolve(min), c = this.resolve(max);
1368
+ return new this(
1369
+ clamp(a.x, b.x, c.x),
1370
+ clamp(a.y, b.y, c.y),
1371
+ clamp(a.z, b.z, c.z)
1372
+ );
1373
+ }
1374
+ static intersectPlane(planeP, planeN, lineStart, lineEnd, t) {
1375
+ planeN = this.resolve(planeN).normalize();
1376
+ const plane_d = -this.resolve(planeN).dot(planeP);
1377
+ const ad = this.resolve(lineStart).dot(planeN);
1378
+ const bd = this.resolve(lineEnd).dot(planeN);
1379
+ t = (-plane_d - ad) / (bd - ad);
1380
+ const lineStartToEnd = this.resolve(lineEnd).subtract(lineStart);
1381
+ const linetoIntersect = lineStartToEnd.multiply(t);
1382
+ return _Vec3.resolve(lineStart).add(linetoIntersect);
1383
+ }
1384
+ static get zero() {
1385
+ return new this(0, 0, 0);
1386
+ }
1387
+ static get one() {
1388
+ return new this(1, 1, 1);
1389
+ }
1390
+ constructor(x, y, z, w = 1) {
1391
+ if (!checkNumber(x))
1392
+ throw new TypeError("expected number for x");
1393
+ if (!checkNumber(y))
1394
+ throw new TypeError("expected number for y");
1395
+ if (!checkNumber(z))
1396
+ throw new TypeError("expected number for z");
1397
+ if (!checkNumber(w))
1398
+ throw new TypeError("expected number for w");
1399
+ this.x = x;
1400
+ this.y = y;
1401
+ this.z = z;
1402
+ this.w = w;
1403
+ }
1404
+ toArray(w = this.w !== 1) {
1405
+ return w ? [this.x, this.y, this.z, this.w] : [this.x, this.y, this.z];
1406
+ }
1407
+ toJSON() {
1408
+ return {
1409
+ x: this.x,
1410
+ y: this.y,
1411
+ z: this.z,
1412
+ w: this.w
1413
+ };
1414
+ }
1415
+ toString(w = this.w !== 1) {
1416
+ return w ? `${this.x},${this.y},${this.z};${this.w}` : `${this.x},${this.y},${this.z}`;
1417
+ }
1418
+ get [Symbol.toStringTag]() {
1419
+ return "Vec3";
1420
+ }
1421
+ [NodeJSCustomInspect]() {
1422
+ return `Vec3 <${this.toString()}>`;
1423
+ }
1424
+ toVec2() {
1425
+ return [this.x, this.y, this.w];
1426
+ }
1427
+ toRGB() {
1428
+ const vec = this.normalize();
1429
+ return [vec.x, vec.y, vec.z];
1430
+ }
1431
+ toRGBA() {
1432
+ const vec = this.normalize();
1433
+ return [vec.x, vec.y, vec.z, vec.w];
1434
+ }
1435
+ toHSL() {
1436
+ const vec = this.normalize();
1437
+ return [vec.x, vec.y, vec.z];
1438
+ }
1439
+ toHSLA() {
1440
+ const vec = this.normalize();
1441
+ return [vec.x, vec.y, vec.z, vec.w];
1336
1442
  }
1337
- set width(val) {
1338
- this.right = this.left + val;
1443
+ toQuaternion() {
1444
+ return [this.w, this.x, this.y, this.z];
1339
1445
  }
1340
- get height() {
1341
- return this.bottom - this.top;
1446
+ clone() {
1447
+ return new _Vec3(this.x, this.y, this.z, this.w);
1342
1448
  }
1343
- set height(val) {
1344
- this.bottom = this.top + val;
1449
+ equals(...args) {
1450
+ const a = _Vec3.resolveArgs(args);
1451
+ return this.x == a.x && this.y == a.y && this.z == a.z;
1345
1452
  }
1346
- static resolve(a) {
1347
- const value = this.cast(a);
1348
- if (typeof value != "undefined")
1349
- return value;
1350
- throw new ResolveError("BoundingBox", a);
1453
+ setX(x) {
1454
+ this.x = x;
1455
+ return this;
1351
1456
  }
1352
- static cast(a) {
1353
- if (a == null || typeof a == "undefined")
1354
- return void 0;
1355
- if (check_number_array(a, 4))
1356
- return new this(a[0], a[1], a[2], a[3]);
1357
- if (has_property(a, "left", "number") && has_property(a, "right", "number") && has_property(a, "top", "number") && has_property(a, "bottom", "number"))
1358
- return new this(a.left, a.right, a.top, a.bottom);
1359
- if (check_string(a)) {
1360
- const parts = a.split(",");
1361
- if (check_string_array(parts, 4))
1362
- return this.cast(parts.map((v) => parseFloat(v)));
1363
- }
1364
- return void 0;
1457
+ setY(y) {
1458
+ this.y = y;
1459
+ return this;
1365
1460
  }
1366
- static is(a) {
1367
- return typeof this.cast(a) != "undefined";
1461
+ setZ(z) {
1462
+ this.z = z;
1463
+ return this;
1368
1464
  }
1369
- constructor(left, right, top, bottom) {
1370
- if (!check_number(left))
1371
- throw new TypeError("expected number for left");
1372
- if (!check_number(right))
1373
- throw new TypeError("expected number for right");
1374
- if (!check_number(top))
1375
- throw new TypeError("expected number for top");
1376
- if (!check_number(bottom))
1377
- throw new TypeError("expected number for bottom");
1378
- this.left = left;
1379
- this.right = right;
1380
- this.top = top;
1381
- this.bottom = bottom;
1465
+ set(...args) {
1466
+ const vec = _Vec3.resolveArgs(args);
1467
+ return this.setX(vec.x).setY(vec.y).setZ(vec.z);
1382
1468
  }
1383
- toArray() {
1384
- return [this.left, this.right, this.top, this.bottom];
1469
+ add(...args) {
1470
+ const vec = _Vec3.resolveArgs(args);
1471
+ return new _Vec3(
1472
+ this.x + vec.x,
1473
+ this.y + vec.y,
1474
+ this.z + vec.z
1475
+ );
1385
1476
  }
1386
- toString() {
1387
- return `${this.left},${this.right},${this.top},${this.bottom}`;
1477
+ offset(...args) {
1478
+ const vec = _Vec3.resolveArgs(args);
1479
+ this.x += vec.x;
1480
+ this.y += vec.y;
1481
+ this.z += vec.z;
1482
+ return this;
1388
1483
  }
1389
- toJSON() {
1390
- return {
1391
- left: this.left,
1392
- top: this.top,
1393
- right: this.right,
1394
- bottom: this.bottom
1395
- };
1484
+ subtract(...args) {
1485
+ const vec = _Vec3.resolveArgs(args);
1486
+ return new _Vec3(
1487
+ this.x - vec.x,
1488
+ this.y - vec.y,
1489
+ this.z - vec.z
1490
+ );
1396
1491
  }
1397
- clone() {
1398
- return new _BoundingBox(this.left, this.right, this.top, this.bottom);
1492
+ multiply(scalar) {
1493
+ return new _Vec3(
1494
+ this.x * scalar,
1495
+ this.y * scalar,
1496
+ this.z * scalar
1497
+ );
1399
1498
  }
1400
- equals(bbox) {
1401
- const b = _BoundingBox.resolve(bbox);
1402
- return this.left == b.left && this.right == b.right && this.top == b.top && this.bottom == b.bottom;
1499
+ naiveMultiply(...args) {
1500
+ const vec = _Vec3.resolveArgs(args);
1501
+ return new _Vec3(
1502
+ this.x * vec.x,
1503
+ this.y * vec.y,
1504
+ this.z * vec.z
1505
+ );
1403
1506
  }
1404
- toSquare() {
1405
- return new Size(this.width, this.height);
1507
+ divide(...args) {
1508
+ if (checkNumberArray(args, 1))
1509
+ return new _Vec3(
1510
+ this.x / args[0],
1511
+ this.y / args[0],
1512
+ this.z / args[0]
1513
+ );
1514
+ const vec = _Vec3.resolveArgs(args);
1515
+ return new _Vec3(
1516
+ this.x / vec.x,
1517
+ this.y / vec.y,
1518
+ this.z / vec.z
1519
+ );
1406
1520
  }
1407
- toRectangle() {
1408
- return new Rectangle(this.left, this.top, this.width, this.height);
1521
+ dot(...args) {
1522
+ const vec = _Vec3.resolveArgs(args);
1523
+ return this.x * vec.x + this.y * vec.y + this.z * vec.z;
1409
1524
  }
1410
- inside(a) {
1411
- const bbox = _BoundingBox.resolve(a);
1412
- return this.right >= bbox.left && bbox.right >= this.left && this.bottom >= bbox.top && bbox.bottom >= this.top;
1525
+ cross(...args) {
1526
+ const vec = _Vec3.resolveArgs(args);
1527
+ return new _Vec3(
1528
+ this.y * vec.z - this.z * vec.y,
1529
+ this.z * vec.x - this.x * vec.z,
1530
+ this.x * vec.y - this.y * vec.x
1531
+ );
1413
1532
  }
1414
- insidePoint(a) {
1415
- const point = Vec2.resolve(a);
1416
- return this.left <= point.x && this.right >= point.x && this.top <= point.y && this.bottom >= point.y;
1533
+ distance(...args) {
1534
+ const vec = _Vec3.resolveArgs(args);
1535
+ return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2);
1417
1536
  }
1418
- insideCircle(a) {
1419
- const circle = Circle.resolve(a);
1420
- const center = Vec2.resolve(circle).add(circle.radius);
1421
- const bboxhe = new Vec2(this.width / 2, this.height / 2);
1422
- const bboxcenter = new Vec2(this.left + bboxhe.x, this.top + bboxhe.y);
1423
- let diff = center.subtract(bboxcenter);
1424
- const clamped = Vec2.clamp(diff, bboxhe.invert(), bboxhe);
1425
- const closest = bboxcenter.add(clamped);
1426
- diff = closest.subtract(center);
1427
- return diff.length() < circle.radius;
1537
+ distanceSquare(...args) {
1538
+ const vec = _Vec3.resolveArgs(args);
1539
+ return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2));
1540
+ }
1541
+ length() {
1542
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
1543
+ }
1544
+ normalize() {
1545
+ const length = this.length();
1546
+ if (length == 0) return _Vec3.zero;
1547
+ return new _Vec3(
1548
+ this.x / length,
1549
+ this.y / length,
1550
+ this.z / length,
1551
+ this.w / length
1552
+ );
1553
+ }
1554
+ invert() {
1555
+ return this.multiply(-1);
1556
+ }
1557
+ round() {
1558
+ return new _Vec3(Math.round(this.x), Math.round(this.y), Math.round(this.z), Math.round(this.w));
1428
1559
  }
1429
1560
  };
1430
1561
 
1431
1562
  // source/geometry/triangle.ts
1432
- var ATriangle = class {
1563
+ var Triangle = class {
1433
1564
  constructor(A, B, C) {
1434
1565
  this.A = A;
1435
1566
  this.B = B;
@@ -1459,8 +1590,17 @@ var ATriangle = class {
1459
1590
  get height() {
1460
1591
  return 2 * (this.area / this.base);
1461
1592
  }
1593
+ toString() {
1594
+ return `${stringify(this.A)}|${stringify(this.B)}|${stringify(this.C)}`;
1595
+ }
1596
+ get [Symbol.toStringTag]() {
1597
+ return "Triangle";
1598
+ }
1599
+ [NodeJSCustomInspect]() {
1600
+ return `Triangle <${this.toString()}>`;
1601
+ }
1462
1602
  };
1463
- var Triangle2D = class extends ATriangle {
1603
+ var Triangle2D = class extends Triangle {
1464
1604
  get a() {
1465
1605
  return Vec2.fromPoints(this.B, this.C).length();
1466
1606
  }
@@ -1471,7 +1611,7 @@ var Triangle2D = class extends ATriangle {
1471
1611
  return Vec2.fromPoints(this.A, this.B).length();
1472
1612
  }
1473
1613
  };
1474
- var Triangle3D = class extends ATriangle {
1614
+ var Triangle3D = class extends Triangle {
1475
1615
  get a() {
1476
1616
  return Vec3.fromPoints(this.B, this.C).length();
1477
1617
  }
@@ -1546,15 +1686,20 @@ var Mat3 = class _Mat3 {
1546
1686
  return value;
1547
1687
  throw new ResolveError("Mat3", a);
1548
1688
  }
1689
+ static resolveArgs(args) {
1690
+ if (checkNumberArray(args, 9))
1691
+ return new this(args);
1692
+ return this.resolve(args[0]);
1693
+ }
1549
1694
  static cast(a) {
1550
1695
  if (a == null || typeof a == "undefined")
1551
1696
  return void 0;
1552
- if (check_number_array(a, 9)) {
1697
+ if (checkNumberArray(a, 9)) {
1553
1698
  return new this(a);
1554
1699
  }
1555
- if (check_array(a, void 0, 3)) {
1700
+ if (checkArray(a, void 0, 3)) {
1556
1701
  const row0 = a[0], row1 = a[1], row2 = a[2];
1557
- if (check_number_array(row0, 3) && check_number_array(row1, 3) && check_number_array(row2, 3))
1702
+ if (checkNumberArray(row0, 3) && checkNumberArray(row1, 3) && checkNumberArray(row2, 3))
1558
1703
  return new this([
1559
1704
  row0[0],
1560
1705
  row0[1],
@@ -1567,12 +1712,14 @@ var Mat3 = class _Mat3 {
1567
1712
  row2[2]
1568
1713
  ]);
1569
1714
  }
1570
- if (check_string(a)) {
1715
+ if (checkString(a)) {
1571
1716
  const parts = a.split(",");
1572
- if (check_string_array(parts, 9))
1717
+ if (checkStringArray(parts, 9))
1573
1718
  return this.cast(parts.map((i) => parseFloat(i)));
1574
1719
  }
1575
- 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"))
1720
+ if (hasProperty(a, "toMat3", "function"))
1721
+ return this.cast(a.toMat3());
1722
+ 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"))
1576
1723
  return new this([
1577
1724
  a.m00,
1578
1725
  a.m01,
@@ -1584,7 +1731,7 @@ var Mat3 = class _Mat3 {
1584
1731
  a.m21,
1585
1732
  a.m22
1586
1733
  ]);
1587
- if (check_number(a)) {
1734
+ if (checkNumber(a)) {
1588
1735
  return new this([a, a, a, a, a, a, a, a, a]);
1589
1736
  }
1590
1737
  return void 0;
@@ -1606,7 +1753,7 @@ var Mat3 = class _Mat3 {
1606
1753
  ]);
1607
1754
  }
1608
1755
  constructor(init = [1, 0, 0, 0, 1, 0, 0, 0, 1]) {
1609
- if (!check_number_array(init, 9))
1756
+ if (!checkNumberArray(init, 9))
1610
1757
  throw new TypeError("expected a number array with 9 elements");
1611
1758
  this._raw = init;
1612
1759
  }
@@ -1646,6 +1793,12 @@ var Mat3 = class _Mat3 {
1646
1793
  toString() {
1647
1794
  return `${this.m00},${this.m01},${this.m02},${this.m10},${this.m11},${this.m12},${this.m20},${this.m21},${this.m22}`;
1648
1795
  }
1796
+ get [Symbol.toStringTag]() {
1797
+ return "Mat3";
1798
+ }
1799
+ [NodeJSCustomInspect]() {
1800
+ return `Mat3 <${this.toString()}>`;
1801
+ }
1649
1802
  clone() {
1650
1803
  return new _Mat3([
1651
1804
  this.m00,
@@ -1659,41 +1812,41 @@ var Mat3 = class _Mat3 {
1659
1812
  this.m22
1660
1813
  ]);
1661
1814
  }
1662
- equals(mat) {
1663
- const m = _Mat3.resolve(mat);
1815
+ equals(...args) {
1816
+ const m = _Mat3.resolveArgs(args);
1664
1817
  for (let index = 0; index < this._raw.length; index++)
1665
1818
  if (this._raw[index] != m._raw[index])
1666
1819
  return false;
1667
1820
  return true;
1668
1821
  }
1669
- add(mat) {
1670
- const b = _Mat3.resolve(mat);
1822
+ add(...args) {
1823
+ const b = _Mat3.resolveArgs(args);
1671
1824
  const m = new _Mat3();
1672
1825
  for (let index = 0; index < this._raw.length; index++)
1673
1826
  m._raw[index] = this._raw[index] + b._raw[index];
1674
1827
  return m;
1675
1828
  }
1676
- subtract(mat) {
1677
- const b = _Mat3.resolve(mat);
1829
+ subtract(...args) {
1830
+ const b = _Mat3.resolveArgs(args);
1678
1831
  const m = new _Mat3();
1679
1832
  for (let index = 0; index < this._raw.length; index++)
1680
1833
  m._raw[index] = this._raw[index] - b._raw[index];
1681
1834
  return m;
1682
1835
  }
1683
- multiply(a) {
1684
- if (check_number(a))
1836
+ multiply(...args) {
1837
+ if (checkNumberArray(args, 1))
1685
1838
  return new _Mat3([
1686
- this.m00 * a,
1687
- this.m01 * a,
1688
- this.m02 * a,
1689
- this.m10 * a,
1690
- this.m11 * a,
1691
- this.m12 * a,
1692
- this.m20 * a,
1693
- this.m21 * a,
1694
- this.m22 * a
1839
+ this.m00 * args[0],
1840
+ this.m01 * args[0],
1841
+ this.m02 * args[0],
1842
+ this.m10 * args[0],
1843
+ this.m11 * args[0],
1844
+ this.m12 * args[0],
1845
+ this.m20 * args[0],
1846
+ this.m21 * args[0],
1847
+ this.m22 * args[0]
1695
1848
  ]);
1696
- const b = _Mat3.resolve(a);
1849
+ const b = _Mat3.resolveArgs(args);
1697
1850
  return new _Mat3([
1698
1851
  b.m00 * this.m00 + b.m01 * this.m10 + b.m02 * this.m20,
1699
1852
  b.m00 * this.m01 + b.m01 * this.m11 + b.m02 * this.m21,
@@ -1893,15 +2046,20 @@ var Mat4 = class _Mat4 {
1893
2046
  return value;
1894
2047
  throw new ResolveError("Mat4", a);
1895
2048
  }
2049
+ static resolveArgs(args) {
2050
+ if (checkNumberArray(args, 16))
2051
+ return new this(args);
2052
+ return this.resolve(args[0]);
2053
+ }
1896
2054
  static cast(a) {
1897
2055
  if (a == null || typeof a == "undefined")
1898
2056
  return void 0;
1899
- if (check_number_array(a, 16)) {
2057
+ if (checkNumberArray(a, 16)) {
1900
2058
  return new this(a);
1901
2059
  }
1902
- if (check_array(a, void 0, 4)) {
2060
+ if (checkArray(a, void 0, 4)) {
1903
2061
  const row0 = a[0], row1 = a[1], row2 = a[2], row3 = a[3];
1904
- if (check_number_array(row0, 4) && check_number_array(row1, 4) && check_number_array(row2, 4) && check_number_array(row3, 4))
2062
+ if (checkNumberArray(row0, 4) && checkNumberArray(row1, 4) && checkNumberArray(row2, 4) && checkNumberArray(row3, 4))
1905
2063
  return new this([
1906
2064
  row0[0],
1907
2065
  row0[1],
@@ -1921,12 +2079,14 @@ var Mat4 = class _Mat4 {
1921
2079
  row3[3]
1922
2080
  ]);
1923
2081
  }
1924
- if (check_string(a)) {
2082
+ if (checkString(a)) {
1925
2083
  const parts = a.split(",");
1926
- if (check_string_array(parts, 16))
2084
+ if (checkStringArray(parts, 16))
1927
2085
  return this.cast(parts.map((i) => parseFloat(i)));
1928
2086
  }
1929
- 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"))
2087
+ if (hasProperty(a, "toMat4", "function"))
2088
+ return this.cast(a.toMat4());
2089
+ 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"))
1930
2090
  return new this([
1931
2091
  a.m00,
1932
2092
  a.m01,
@@ -1945,7 +2105,7 @@ var Mat4 = class _Mat4 {
1945
2105
  a.m32,
1946
2106
  a.m33
1947
2107
  ]);
1948
- if (check_number(a)) {
2108
+ if (checkNumber(a)) {
1949
2109
  return new this([a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a]);
1950
2110
  }
1951
2111
  return void 0;
@@ -1953,22 +2113,25 @@ var Mat4 = class _Mat4 {
1953
2113
  static is(a) {
1954
2114
  return typeof this.cast(a) != "undefined";
1955
2115
  }
1956
- static orthographic(left, right, bottom, top, near, far) {
2116
+ static orthographic(...args) {
2117
+ const bbox = checkNumberArray(args, 6) ? new BoundingBox(args[0], args[1], args[2], args[3]) : BoundingBox.resolve(args[0]);
2118
+ const near = checkNumberArray(args, 6) ? args[4] : args[1];
2119
+ const far = checkNumberArray(args, 6) ? args[5] : args[2];
1957
2120
  return new this([
1958
- 2 / (right - left),
2121
+ 2 / (bbox.right - bbox.left),
1959
2122
  0,
1960
2123
  0,
1961
2124
  0,
1962
2125
  0,
1963
- 2 / (top - bottom),
2126
+ 2 / (bbox.top - bbox.bottom),
1964
2127
  0,
1965
2128
  0,
1966
2129
  0,
1967
2130
  0,
1968
2131
  2 / (near - far),
1969
2132
  0,
1970
- (left + right) / (left - right),
1971
- (bottom + top) / (bottom - top),
2133
+ (bbox.left + bbox.right) / (bbox.left - bbox.right),
2134
+ (bbox.bottom + bbox.top) / (bbox.bottom - bbox.top),
1972
2135
  (near + far) / (near - far),
1973
2136
  1
1974
2137
  ]);
@@ -2021,7 +2184,7 @@ var Mat4 = class _Mat4 {
2021
2184
  ]);
2022
2185
  }
2023
2186
  constructor(init = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]) {
2024
- if (!check_number_array(init, 16))
2187
+ if (!checkNumberArray(init, 16))
2025
2188
  throw new TypeError("expected a number array with 16 elements");
2026
2189
  this._raw = init;
2027
2190
  }
@@ -2076,6 +2239,12 @@ var Mat4 = class _Mat4 {
2076
2239
  toString() {
2077
2240
  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}`;
2078
2241
  }
2242
+ get [Symbol.toStringTag]() {
2243
+ return "Mat4";
2244
+ }
2245
+ [NodeJSCustomInspect]() {
2246
+ return `Mat4 <${this.toString()}>`;
2247
+ }
2079
2248
  clone() {
2080
2249
  return new _Mat4([
2081
2250
  this.m00,
@@ -2096,82 +2265,80 @@ var Mat4 = class _Mat4 {
2096
2265
  this.m33
2097
2266
  ]);
2098
2267
  }
2099
- equals(mat) {
2100
- const m = _Mat4.resolve(mat);
2268
+ equals(...args) {
2269
+ const m = _Mat4.resolveArgs(args);
2101
2270
  for (let index = 0; index < this._raw.length; index++)
2102
2271
  if (this._raw[index] != m._raw[index])
2103
2272
  return false;
2104
2273
  return true;
2105
2274
  }
2106
- add(mat) {
2107
- const b = _Mat4.resolve(mat);
2275
+ add(...args) {
2276
+ const b = _Mat4.resolveArgs(args);
2108
2277
  const m = new _Mat4();
2109
2278
  for (let index = 0; index < this._raw.length; index++)
2110
2279
  m._raw[index] = this._raw[index] + b._raw[index];
2111
2280
  return m;
2112
2281
  }
2113
- subtract(mat) {
2114
- const b = _Mat4.resolve(mat);
2282
+ subtract(...args) {
2283
+ const b = _Mat4.resolveArgs(args);
2115
2284
  const m = new _Mat4();
2116
2285
  for (let index = 0; index < this._raw.length; index++)
2117
2286
  m._raw[index] = this._raw[index] - b._raw[index];
2118
2287
  return m;
2119
2288
  }
2120
- multiply(a) {
2121
- if (check_number(a)) {
2122
- return new _Mat4([
2123
- this.m00 * a,
2124
- this.m01 * a,
2125
- this.m02 * a,
2126
- this.m03 * a,
2127
- this.m10 * a,
2128
- this.m11 * a,
2129
- this.m12 * a,
2130
- this.m13 * a,
2131
- this.m20 * a,
2132
- this.m21 * a,
2133
- this.m22 * a,
2134
- this.m23 * a,
2135
- this.m30 * a,
2136
- this.m31 * a,
2137
- this.m32 * a,
2138
- this.m33 * a
2139
- ]);
2140
- }
2141
- if (_Mat4.is(a)) {
2142
- const b = _Mat4.resolve(a);
2289
+ multiply(...args) {
2290
+ if (checkNumberArray(args, 1)) {
2291
+ const scalar = args[0];
2143
2292
  return new _Mat4([
2144
- b.m00 * this.m00 + b.m01 * this.m10 + b.m02 * this.m20 + b.m03 * this.m30,
2145
- b.m00 * this.m01 + b.m01 * this.m11 + b.m02 * this.m21 + b.m03 * this.m31,
2146
- b.m00 * this.m02 + b.m01 * this.m12 + b.m02 * this.m22 + b.m03 * this.m32,
2147
- b.m00 * this.m03 + b.m01 * this.m13 + b.m02 * this.m23 + b.m03 * this.m33,
2148
- b.m10 * this.m00 + b.m11 * this.m10 + b.m12 * this.m20 + b.m13 * this.m30,
2149
- b.m10 * this.m01 + b.m11 * this.m11 + b.m12 * this.m21 + b.m13 * this.m31,
2150
- b.m10 * this.m02 + b.m11 * this.m12 + b.m12 * this.m22 + b.m13 * this.m32,
2151
- b.m10 * this.m03 + b.m11 * this.m13 + b.m12 * this.m23 + b.m13 * this.m33,
2152
- b.m20 * this.m00 + b.m21 * this.m10 + b.m22 * this.m20 + b.m23 * this.m30,
2153
- b.m20 * this.m01 + b.m21 * this.m11 + b.m22 * this.m21 + b.m23 * this.m31,
2154
- b.m20 * this.m02 + b.m21 * this.m12 + b.m22 * this.m22 + b.m23 * this.m32,
2155
- b.m20 * this.m03 + b.m21 * this.m13 + b.m22 * this.m23 + b.m23 * this.m33,
2156
- b.m30 * this.m00 + b.m31 * this.m10 + b.m32 * this.m20 + b.m33 * this.m30,
2157
- b.m30 * this.m01 + b.m31 * this.m11 + b.m32 * this.m21 + b.m33 * this.m31,
2158
- b.m30 * this.m02 + b.m31 * this.m12 + b.m32 * this.m22 + b.m33 * this.m32,
2159
- b.m30 * this.m03 + b.m31 * this.m13 + b.m32 * this.m23 + b.m33 * this.m33
2293
+ this.m00 * scalar,
2294
+ this.m01 * scalar,
2295
+ this.m02 * scalar,
2296
+ this.m03 * scalar,
2297
+ this.m10 * scalar,
2298
+ this.m11 * scalar,
2299
+ this.m12 * scalar,
2300
+ this.m13 * scalar,
2301
+ this.m20 * scalar,
2302
+ this.m21 * scalar,
2303
+ this.m22 * scalar,
2304
+ this.m23 * scalar,
2305
+ this.m30 * scalar,
2306
+ this.m31 * scalar,
2307
+ this.m32 * scalar,
2308
+ this.m33 * scalar
2160
2309
  ]);
2161
2310
  }
2162
- if (Vec3.is(a)) {
2163
- const b = Vec3.resolve(a);
2164
- const vec = new Vec3(
2165
- b.x * this.m00 + b.y * this.m10 + b.z * this.m20 + this.m30,
2166
- b.x * this.m01 + b.y * this.m11 + b.z * this.m21 + this.m31,
2167
- b.x * this.m02 + b.y * this.m12 + b.z * this.m22 + this.m32,
2168
- b.x * this.m03 + b.y * this.m13 + b.z * this.m23 + this.m33
2311
+ const vec = Vec3.cast(args[0]);
2312
+ if (vec !== void 0) {
2313
+ const result = new Vec3(
2314
+ vec.x * this.m00 + vec.y * this.m10 + vec.z * this.m20 + this.m30,
2315
+ vec.x * this.m01 + vec.y * this.m11 + vec.z * this.m21 + this.m31,
2316
+ vec.x * this.m02 + vec.y * this.m12 + vec.z * this.m22 + this.m32,
2317
+ vec.x * this.m03 + vec.y * this.m13 + vec.z * this.m23 + this.m33
2169
2318
  );
2170
- if (vec.w != 0)
2171
- return vec.divide(vec.w);
2172
- return vec;
2319
+ if (result.w != 0)
2320
+ return result.divide(result.w);
2321
+ return result;
2173
2322
  }
2174
- throw new ResolveError("Mat4 or Vec3 or number", a);
2323
+ const mat = _Mat4.resolveArgs(args);
2324
+ return new _Mat4([
2325
+ mat.m00 * this.m00 + mat.m01 * this.m10 + mat.m02 * this.m20 + mat.m03 * this.m30,
2326
+ mat.m00 * this.m01 + mat.m01 * this.m11 + mat.m02 * this.m21 + mat.m03 * this.m31,
2327
+ mat.m00 * this.m02 + mat.m01 * this.m12 + mat.m02 * this.m22 + mat.m03 * this.m32,
2328
+ mat.m00 * this.m03 + mat.m01 * this.m13 + mat.m02 * this.m23 + mat.m03 * this.m33,
2329
+ mat.m10 * this.m00 + mat.m11 * this.m10 + mat.m12 * this.m20 + mat.m13 * this.m30,
2330
+ mat.m10 * this.m01 + mat.m11 * this.m11 + mat.m12 * this.m21 + mat.m13 * this.m31,
2331
+ mat.m10 * this.m02 + mat.m11 * this.m12 + mat.m12 * this.m22 + mat.m13 * this.m32,
2332
+ mat.m10 * this.m03 + mat.m11 * this.m13 + mat.m12 * this.m23 + mat.m13 * this.m33,
2333
+ mat.m20 * this.m00 + mat.m21 * this.m10 + mat.m22 * this.m20 + mat.m23 * this.m30,
2334
+ mat.m20 * this.m01 + mat.m21 * this.m11 + mat.m22 * this.m21 + mat.m23 * this.m31,
2335
+ mat.m20 * this.m02 + mat.m21 * this.m12 + mat.m22 * this.m22 + mat.m23 * this.m32,
2336
+ mat.m20 * this.m03 + mat.m21 * this.m13 + mat.m22 * this.m23 + mat.m23 * this.m33,
2337
+ mat.m30 * this.m00 + mat.m31 * this.m10 + mat.m32 * this.m20 + mat.m33 * this.m30,
2338
+ mat.m30 * this.m01 + mat.m31 * this.m11 + mat.m32 * this.m21 + mat.m33 * this.m31,
2339
+ mat.m30 * this.m02 + mat.m31 * this.m12 + mat.m32 * this.m22 + mat.m33 * this.m32,
2340
+ mat.m30 * this.m03 + mat.m31 * this.m13 + mat.m32 * this.m23 + mat.m33 * this.m33
2341
+ ]);
2175
2342
  }
2176
2343
  translate(...args) {
2177
2344
  const vec = Vec3.resolveArgs(args);
@@ -2321,33 +2488,31 @@ var Mat4 = class _Mat4 {
2321
2488
  };
2322
2489
 
2323
2490
  // source/color.ts
2324
- function _hex_to_array(hex) {
2325
- if (!check_hex(hex))
2491
+ function __hex_to_array__(hex) {
2492
+ if (!checkHex(hex))
2326
2493
  return void 0;
2327
- const part = get_hex_part(hex);
2328
- const a = parseInt(part.substring(0, 2), 16) / 255;
2329
- const b = parseInt(part.substring(2, 4), 16) / 255;
2330
- const c = parseInt(part.substring(4, 6), 16) / 255;
2331
- const d = part.length == 8 ? parseInt(hex.substring(6, 8), 16) / 255 : 1;
2332
- return [a, b, c, d];
2494
+ const part = getHexValue(hex);
2495
+ const red = parseInt(part.substring(0, 2), 16) / 255;
2496
+ const green = parseInt(part.substring(2, 4), 16) / 255;
2497
+ const blue = parseInt(part.substring(4, 6), 16) / 255;
2498
+ const alpha = part.length == 8 ? parseInt(hex.substring(6, 8), 16) / 255 : 1;
2499
+ return [red, green, blue, alpha];
2333
2500
  }
2334
- function _number_to_rgb(number) {
2501
+ function __number_to_rgb__(number) {
2335
2502
  const blue = number & 255;
2336
2503
  const green = (number & 65280) >>> 8;
2337
2504
  const red = (number & 16711680) >>> 16;
2338
2505
  return [red / 255, green / 255, blue / 255];
2339
2506
  }
2340
- function _number_to_rgba(number) {
2507
+ function __number_to_rgba__(number) {
2341
2508
  const alpha = number & 255;
2342
2509
  const blue = (number & 65280) >>> 8;
2343
2510
  const green = (number & 16711680) >>> 16;
2344
2511
  const red = (number & 4278190080) >>> 24;
2345
2512
  return [red / 255, green / 255, blue / 255, alpha / 255];
2346
2513
  }
2347
- function _fix_integer(number) {
2348
- return number * 255 | 0;
2349
- }
2350
- var RGBAColor = class _RGBAColor {
2514
+ var __to_byte__ = (scale) => clamp(scale * 255 | 0, 0, 255);
2515
+ var RGBA = class _RGBA {
2351
2516
  _red;
2352
2517
  get red() {
2353
2518
  return this._red;
@@ -2382,27 +2547,36 @@ var RGBAColor = class _RGBAColor {
2382
2547
  return value;
2383
2548
  throw new ResolveError("RGBAColor", a);
2384
2549
  }
2550
+ static resolveArgs(args) {
2551
+ if (checkNumberArray(args, 3) || checkNumberArray(args, 4))
2552
+ return new this(args[0], args[1], args[2], args[3]);
2553
+ return this.resolve(args[0]);
2554
+ }
2385
2555
  static cast(a) {
2386
2556
  if (a == null || typeof a == "undefined")
2387
2557
  return void 0;
2388
- if (check_number_array(a, 3) || check_number_array(a, 4))
2558
+ if (checkNumberArray(a, 3) || checkNumberArray(a, 4))
2389
2559
  return new this(a[0], a[1], a[2], a[3]);
2390
- if (has_property(a, "red", "number") && has_property(a, "green", "number") && has_property(a, "blue", "number"))
2391
- return new this(a.red, a.green, a.blue, has_property(a, "alpha", "number") ? a.alpha : void 0);
2392
- if (check_number(a)) {
2560
+ if (hasProperty(a, "toRGB", "function"))
2561
+ return this.cast(a.toRGB());
2562
+ if (hasProperty(a, "toRGBA", "function"))
2563
+ return this.cast(a.toRGBA());
2564
+ if (hasProperty(a, "red", "number") && hasProperty(a, "green", "number") && hasProperty(a, "blue", "number"))
2565
+ return new this(a.red, a.green, a.blue, hasProperty(a, "alpha", "number") ? a.alpha : void 0);
2566
+ if (checkNumber(a)) {
2393
2567
  const hex = a.toString(16);
2394
- const convert = hex.length <= 6 ? _number_to_rgb : _number_to_rgba;
2568
+ const convert = hex.length <= 6 ? __number_to_rgb__ : __number_to_rgba__;
2395
2569
  return this.cast(convert(a));
2396
2570
  }
2397
- if (check_string(a)) {
2571
+ if (checkString(a)) {
2398
2572
  if (a.startsWith("rgb")) {
2399
2573
  const hasAlpha = a.startsWith("rgba");
2400
2574
  const offset = hasAlpha ? 5 : 4;
2401
2575
  const parts = a.substring(offset, a.indexOf(")", offset)).split(",");
2402
- if (check_string_array(parts, hasAlpha ? 4 : 3))
2576
+ if (checkStringArray(parts, hasAlpha ? 4 : 3))
2403
2577
  return this.cast(parts.map((v) => parseInt(v) / 255));
2404
2578
  }
2405
- return this.cast(_hex_to_array(a));
2579
+ return this.cast(__hex_to_array__(a));
2406
2580
  }
2407
2581
  return void 0;
2408
2582
  }
@@ -2415,38 +2589,57 @@ var RGBAColor = class _RGBAColor {
2415
2589
  this._blue = clamp(blue, 0, 1);
2416
2590
  this._alpha = clamp(alpha, 0, 1);
2417
2591
  }
2418
- toArray(withAlpha = false) {
2419
- return withAlpha ? [this.red, this.green, this.blue, this.alpha] : this.alpha == 1 ? [this.red, this.green, this.blue] : this.toArray(true);
2592
+ toArray(withAlpha = this._alpha !== 1) {
2593
+ return withAlpha ? [this.red, this.green, this.blue, this.alpha] : [this.red, this.green, this.blue];
2420
2594
  }
2421
- toJSON(withAlpha = false) {
2595
+ toJSON(withAlpha = this._alpha !== 1) {
2422
2596
  return withAlpha ? {
2423
2597
  red: this.red,
2424
2598
  green: this.green,
2425
2599
  blue: this.blue,
2426
2600
  alpha: this.alpha
2427
- } : this.alpha == 1 ? { red: this.red, green: this.green, blue: this.blue } : this.toJSON(true);
2601
+ } : {
2602
+ red: this.red,
2603
+ green: this.green,
2604
+ blue: this.blue
2605
+ };
2606
+ }
2607
+ toString(withAlpha = this._alpha !== 1) {
2608
+ 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)})`;
2609
+ }
2610
+ get [Symbol.toStringTag]() {
2611
+ return "RGBA";
2428
2612
  }
2429
- toString(withAlpha = false) {
2430
- 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);
2613
+ [NodeJSCustomInspect]() {
2614
+ return `RGBA <${this.toString()}>`;
2431
2615
  }
2432
- toHSL(withAlpha = true) {
2616
+ toVec2() {
2617
+ return [this.red, this.green, this.blue];
2618
+ }
2619
+ toVec3() {
2620
+ return [this.red, this.green, this.blue, this.alpha];
2621
+ }
2622
+ toHSL(withAlpha = this._alpha !== 1) {
2433
2623
  const red = this.red, green = this.green, blue = this.blue;
2434
2624
  const min = Math.min(red, green, blue), max = Math.max(red, green, blue);
2435
2625
  const luminace = (min + max) / 2;
2436
2626
  if (min == max)
2437
- return new HSLColor(0, 0, luminace, withAlpha ? this.alpha : void 0);
2627
+ return new HSLA(0, 0, luminace, withAlpha ? this.alpha : void 0);
2438
2628
  const d = max - min;
2439
2629
  const saturation = luminace > 0.5 ? d / (2 - max - min) : d / (max + min);
2440
2630
  if (max == red)
2441
- return new HSLColor(((green - blue) / d + (green < blue ? 6 : 0)) / 6, saturation, luminace);
2631
+ return new HSLA(((green - blue) / d + (green < blue ? 6 : 0)) / 6, saturation, luminace, withAlpha ? this.alpha : void 0);
2442
2632
  if (max == green)
2443
- return new HSLColor(((blue - red) / d + 2) / 6, saturation, luminace);
2633
+ return new HSLA(((blue - red) / d + 2) / 6, saturation, luminace, withAlpha ? this.alpha : void 0);
2444
2634
  if (max == blue)
2445
- return new HSLColor(((red - green) / d + 4) / 6, saturation, luminace);
2446
- return new HSLColor(0, saturation, luminace, withAlpha ? this.alpha : void 0);
2635
+ return new HSLA(((red - green) / d + 4) / 6, saturation, luminace, withAlpha ? this.alpha : void 0);
2636
+ return new HSLA(0, saturation, luminace, withAlpha ? this.alpha : void 0);
2637
+ }
2638
+ toHSLA() {
2639
+ return this.toHSL(true);
2447
2640
  }
2448
- invert(withAlpha = false) {
2449
- return new _RGBAColor(
2641
+ invert(withAlpha = this._alpha !== 1) {
2642
+ return new _RGBA(
2450
2643
  1 - this.red,
2451
2644
  1 - this.green,
2452
2645
  1 - this.blue,
@@ -2454,7 +2647,7 @@ var RGBAColor = class _RGBAColor {
2454
2647
  );
2455
2648
  }
2456
2649
  };
2457
- var HSLColor = class _HSLColor {
2650
+ var HSLA = class _HSLA {
2458
2651
  _hue;
2459
2652
  get hue() {
2460
2653
  return this._hue;
@@ -2489,27 +2682,36 @@ var HSLColor = class _HSLColor {
2489
2682
  return value;
2490
2683
  throw new ResolveError("HSLColor", a);
2491
2684
  }
2685
+ static resolveArgs(args) {
2686
+ if (checkNumberArray(args, 3) || checkNumberArray(args, 4))
2687
+ return new this(args[0], args[1], args[2], args[3]);
2688
+ return this.resolve(args[0]);
2689
+ }
2492
2690
  static cast(a) {
2493
2691
  if (a == null || typeof a == "undefined")
2494
2692
  return void 0;
2495
- if (check_number_array(a, 3) || check_number_array(a, 4))
2693
+ if (checkNumberArray(a, 3) || checkNumberArray(a, 4))
2496
2694
  return new this(a[0], a[1], a[2], a[3]);
2497
- if (has_property(a, "hue", "number") && has_property(a, "saturation", "number") && has_property(a, "luminace", "number"))
2498
- return new this(a.hue, a.saturation, a.luminace, has_property(a, "alpha", "number") ? a.alpha : void 0);
2499
- if (check_number(a)) {
2695
+ if (hasProperty(a, "toHSL", "function"))
2696
+ return this.cast(a.toHSL());
2697
+ if (hasProperty(a, "toHSLA", "function"))
2698
+ return this.cast(a.toHSLA());
2699
+ if (hasProperty(a, "hue", "number") && hasProperty(a, "saturation", "number") && hasProperty(a, "luminace", "number"))
2700
+ return new this(a.hue, a.saturation, a.luminace, hasProperty(a, "alpha", "number") ? a.alpha : void 0);
2701
+ if (checkNumber(a)) {
2500
2702
  const hex = a.toString(16);
2501
- const convert = hex.length <= 6 ? _number_to_rgb : _number_to_rgba;
2703
+ const convert = hex.length <= 6 ? __number_to_rgb__ : __number_to_rgba__;
2502
2704
  return this.cast(convert(a));
2503
2705
  }
2504
- if (check_string(a)) {
2706
+ if (checkString(a)) {
2505
2707
  if (a.startsWith("hsl")) {
2506
2708
  const hasAlpha = a.startsWith("hsla");
2507
2709
  const offset = hasAlpha ? 5 : 4;
2508
2710
  const parts = a.substring(offset, a.indexOf(")", offset)).split(",");
2509
- if (check_string_array(parts, hasAlpha ? 4 : 3))
2711
+ if (checkStringArray(parts, hasAlpha ? 4 : 3))
2510
2712
  return this.cast(parts.map((v) => parseInt(v) / 255));
2511
2713
  }
2512
- return this.cast(_hex_to_array(a));
2714
+ return this.cast(__hex_to_array__(a));
2513
2715
  }
2514
2716
  return void 0;
2515
2717
  }
@@ -2517,39 +2719,49 @@ var HSLColor = class _HSLColor {
2517
2719
  return typeof this.cast(a) != "undefined";
2518
2720
  }
2519
2721
  constructor(hue, saturation, luminace, alpha = 1) {
2520
- if (!check_number(hue))
2722
+ if (!checkNumber(hue))
2521
2723
  throw new TypeError("expected number for hue");
2522
- if (!check_number(saturation))
2724
+ if (!checkNumber(saturation))
2523
2725
  throw new TypeError("expected number for saturation");
2524
- if (!check_number(luminace))
2726
+ if (!checkNumber(luminace))
2525
2727
  throw new TypeError("expected number for luminace");
2526
- if (!check_number(alpha))
2728
+ if (!checkNumber(alpha))
2527
2729
  throw new TypeError("expected number for alpha");
2528
2730
  this._hue = clamp(hue, 0, 1);
2529
2731
  this._saturation = clamp(saturation, 0, 1);
2530
2732
  this._luminace = clamp(luminace, 0, 1);
2531
2733
  this._alpha = clamp(alpha, 0, 1);
2532
2734
  }
2533
- toArray(withAlpha = false) {
2534
- return withAlpha ? [this.hue, this.saturation, this.luminace, this.alpha] : this.alpha == 1 ? [this.hue, this.saturation, this.luminace] : this.toArray(true);
2735
+ toArray(withAlpha = this._alpha !== 1) {
2736
+ return withAlpha ? [this.hue, this.saturation, this.luminace, this.alpha] : [this.hue, this.saturation, this.luminace];
2535
2737
  }
2536
- toJSON(withAlpha = false) {
2738
+ toJSON(withAlpha = this._alpha !== 1) {
2537
2739
  return withAlpha ? {
2538
2740
  hue: this.hue,
2539
2741
  saturation: this.saturation,
2540
2742
  luminace: this.luminace,
2541
2743
  alpha: this.alpha
2542
- } : this.alpha == 1 ? { hue: this.hue, saturation: this.saturation, luminace: this.luminace } : this.toJSON(true);
2744
+ } : {
2745
+ hue: this.hue,
2746
+ saturation: this.saturation,
2747
+ luminace: this.luminace
2748
+ };
2749
+ }
2750
+ toString(withAlpha = this._alpha !== 1) {
2751
+ 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)})`;
2752
+ }
2753
+ get [Symbol.toStringTag]() {
2754
+ return "HSLA";
2543
2755
  }
2544
- toString(withAlpha = false) {
2545
- 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);
2756
+ [NodeJSCustomInspect]() {
2757
+ return `HSLA <${this.toString()}>`;
2546
2758
  }
2547
- toRGB(withAlpha = true) {
2759
+ toRGB(withAlpha = this._alpha !== 1) {
2548
2760
  if (this.saturation == 0)
2549
- return new RGBAColor(this.luminace * 255, this.luminace * 255, this.luminace * 255, withAlpha ? this.alpha : void 0);
2761
+ return new RGBA(this.luminace * 255, this.luminace * 255, this.luminace * 255, withAlpha ? this.alpha : void 0);
2550
2762
  const q = this.luminace < 0.5 ? this.luminace * (1 + this.saturation) : this.luminace + this.saturation - this.luminace * this.saturation;
2551
2763
  const p = 2 * this.luminace - q;
2552
- function _hue_2_rgb(t) {
2764
+ function __hue_2_rgb__(t) {
2553
2765
  let _t = t;
2554
2766
  if (_t < 0)
2555
2767
  _t++;
@@ -2563,10 +2775,19 @@ var HSLColor = class _HSLColor {
2563
2775
  return p + (q - p) * (2 / 3 - _t) * 6;
2564
2776
  return p;
2565
2777
  }
2566
- return new RGBAColor(_hue_2_rgb(this.hue + 1 / 3) * 255, _hue_2_rgb(this.hue) * 255, _hue_2_rgb(this.hue - 1 / 3) * 255, withAlpha ? this.alpha : void 0);
2778
+ 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);
2567
2779
  }
2568
- invert(withAlpha = false) {
2569
- return new _HSLColor(
2780
+ toRGBA() {
2781
+ return this.toRGB(true);
2782
+ }
2783
+ toVec2() {
2784
+ return [this.hue, this.saturation, this.luminace];
2785
+ }
2786
+ toVec3() {
2787
+ return [this.hue, this.saturation, this.luminace, this.alpha];
2788
+ }
2789
+ invert(withAlpha = this._alpha !== 1) {
2790
+ return new _HSLA(
2570
2791
  1 - this.hue,
2571
2792
  1 - this.saturation,
2572
2793
  1 - this.luminace,
@@ -2574,33 +2795,44 @@ var HSLColor = class _HSLColor {
2574
2795
  );
2575
2796
  }
2576
2797
  };
2577
- function resolveColor(a, preferHSL = false) {
2578
- const value = castColor(a, preferHSL);
2579
- if (typeof value != "undefined")
2580
- return value;
2581
- throw new ResolveError("Color", a);
2582
- }
2583
- function castColor(a, preferHSL = false) {
2584
- const results = [];
2585
- try {
2586
- const rgba = RGBAColor.resolve(a);
2587
- results.push(rgba);
2588
- } catch (e) {
2589
- }
2590
- try {
2591
- const hsla = HSLColor.resolve(a);
2592
- results.push(hsla);
2593
- } catch (e) {
2594
- }
2595
- let offset = preferHSL ? 1 : 0;
2596
- const firstItem = results[offset];
2597
- if (firstItem)
2598
- return firstItem;
2599
- const secondItem = results[offset + 1];
2600
- if (secondItem)
2601
- return secondItem;
2602
- return void 0;
2603
- }
2798
+ var AnyColor;
2799
+ ((AnyColor2) => {
2800
+ function cast(a, preferHSL = false) {
2801
+ const results = [];
2802
+ try {
2803
+ const rgba = RGBA.resolve(a);
2804
+ results.push(rgba);
2805
+ } catch (e) {
2806
+ }
2807
+ try {
2808
+ const hsla = HSLA.resolve(a);
2809
+ results.push(hsla);
2810
+ } catch (e) {
2811
+ }
2812
+ let offset = preferHSL ? 1 : 0;
2813
+ const firstItem = results[offset];
2814
+ if (firstItem)
2815
+ return firstItem;
2816
+ const secondItem = results[offset + 1];
2817
+ if (secondItem)
2818
+ return secondItem;
2819
+ return void 0;
2820
+ }
2821
+ AnyColor2.cast = cast;
2822
+ function resolve(a, preferHSL = false) {
2823
+ const value = cast(a, preferHSL);
2824
+ if (typeof value != "undefined")
2825
+ return value;
2826
+ throw new ResolveError("Color", a);
2827
+ }
2828
+ AnyColor2.resolve = resolve;
2829
+ function resolveArgs(args, preferHSL = false) {
2830
+ if (checkNumberArray(args, 3) || checkNumberArray(args, 4))
2831
+ return resolve(args, preferHSL);
2832
+ return resolve(args[0], preferHSL);
2833
+ }
2834
+ AnyColor2.resolveArgs = resolveArgs;
2835
+ })(AnyColor || (AnyColor = {}));
2604
2836
 
2605
2837
  // source/quaternion.ts
2606
2838
  var Quaternion = class _Quaternion {
@@ -2617,16 +2849,23 @@ var Quaternion = class _Quaternion {
2617
2849
  return value;
2618
2850
  throw new ResolveError("Quaternion", a);
2619
2851
  }
2852
+ static resolveArgs(args) {
2853
+ if (checkNumberArray(args, 4))
2854
+ return new this(args[0], args[1], args[2], args[3]);
2855
+ return this.resolve(args[0]);
2856
+ }
2620
2857
  static cast(a) {
2621
2858
  if (a == null || typeof a == "undefined")
2622
2859
  return void 0;
2623
- if (check_number_array(a, 4))
2860
+ if (checkNumberArray(a, 4))
2624
2861
  return new this(a[0], a[1], a[2], a[3]);
2625
- if (has_property(a, "w", "number") && has_property(a, "x", "number") && has_property(a, "y", "number") && has_property(a, "z", "number"))
2862
+ if (hasProperty(a, "toQuaternion", "function"))
2863
+ return this.cast(a.toQuaternion());
2864
+ if (hasProperty(a, "w", "number") && hasProperty(a, "x", "number") && hasProperty(a, "y", "number") && hasProperty(a, "z", "number"))
2626
2865
  return new this(a.w, a.x, a.y, a.z);
2627
- if (check_string(a)) {
2866
+ if (checkString(a)) {
2628
2867
  const parts = a.replaceAll(" ", "").split("+");
2629
- if (check_string_array(parts, 4)) {
2868
+ if (checkStringArray(parts, 4)) {
2630
2869
  const [sw, sxi, syj, szk] = parts;
2631
2870
  if (sxi.endsWith("i") && syj.endsWith("j") && szk.endsWith("k"))
2632
2871
  return this.cast([
@@ -2639,7 +2878,9 @@ var Quaternion = class _Quaternion {
2639
2878
  }
2640
2879
  return void 0;
2641
2880
  }
2642
- static fromAxisAngle(axis, angle) {
2881
+ static fromAxisAngle(...args) {
2882
+ const axis = checkNumberArray(args, 4) ? new Vec3(args[0], args[1], args[2]) : Vec3.resolve(args[0]);
2883
+ const angle = checkNumberArray(args, 4) ? args[3] : args[1];
2643
2884
  const vec = Vec3.resolve(axis);
2644
2885
  const hangle = angle * 0.5;
2645
2886
  const sin2 = Math.sin(hangle);
@@ -2659,14 +2900,17 @@ var Quaternion = class _Quaternion {
2659
2900
  sx * sy * cz + sz * cx * cy
2660
2901
  );
2661
2902
  }
2662
- constructor(w = 0, x = 0, y = 0, z = 0) {
2663
- if (!check_number(w))
2903
+ static get zero() {
2904
+ return new _Quaternion(0, 0, 0, 0);
2905
+ }
2906
+ constructor(w, x, y, z) {
2907
+ if (!checkNumber(w))
2664
2908
  throw new TypeError("expected number for w");
2665
- if (!check_number(x))
2909
+ if (!checkNumber(x))
2666
2910
  throw new TypeError("expected number for x");
2667
- if (!check_number(y))
2911
+ if (!checkNumber(y))
2668
2912
  throw new TypeError("expected number for x");
2669
- if (!check_number(z))
2913
+ if (!checkNumber(z))
2670
2914
  throw new TypeError("expected number for w");
2671
2915
  this.w = w;
2672
2916
  this.x = x;
@@ -2679,6 +2923,12 @@ var Quaternion = class _Quaternion {
2679
2923
  toString() {
2680
2924
  return `${this.w} + ${this.x}i + ${this.y}j + ${this.z}k`;
2681
2925
  }
2926
+ get [Symbol.toStringTag]() {
2927
+ return "Quaternion";
2928
+ }
2929
+ [NodeJSCustomInspect]() {
2930
+ return `Quaternion <${this.toString()}>`;
2931
+ }
2682
2932
  toJSON() {
2683
2933
  return {
2684
2934
  w: this.w,
@@ -2690,8 +2940,8 @@ var Quaternion = class _Quaternion {
2690
2940
  clone() {
2691
2941
  return new _Quaternion(this.w, this.x, this.y, this.z);
2692
2942
  }
2693
- add(a) {
2694
- const quat = _Quaternion.resolve(a);
2943
+ add(...args) {
2944
+ const quat = _Quaternion.resolveArgs(args);
2695
2945
  return new _Quaternion(
2696
2946
  this.w + quat.w,
2697
2947
  this.x + quat.x,
@@ -2699,16 +2949,16 @@ var Quaternion = class _Quaternion {
2699
2949
  this.z + quat.z
2700
2950
  );
2701
2951
  }
2702
- offset(a) {
2703
- const quat = _Quaternion.resolve(a);
2952
+ offset(...args) {
2953
+ const quat = _Quaternion.resolveArgs(args);
2704
2954
  this.w += quat.w;
2705
2955
  this.x += quat.x;
2706
2956
  this.y += quat.y;
2707
2957
  this.z += quat.z;
2708
2958
  return this;
2709
2959
  }
2710
- subtract(a) {
2711
- const quat = _Quaternion.resolve(a);
2960
+ subtract(...args) {
2961
+ const quat = _Quaternion.resolveArgs(args);
2712
2962
  return new _Quaternion(
2713
2963
  this.w - quat.w,
2714
2964
  this.x - quat.x,
@@ -2726,12 +2976,12 @@ var Quaternion = class _Quaternion {
2726
2976
  normalize() {
2727
2977
  let length = this.length();
2728
2978
  if (length < EPSILON)
2729
- return new _Quaternion();
2979
+ return _Quaternion.zero;
2730
2980
  length = 1 / length;
2731
2981
  return new _Quaternion(this.w * length, this.x * length, this.y * length, this.z * length);
2732
2982
  }
2733
- multiply(a) {
2734
- const quat = _Quaternion.resolve(a);
2983
+ multiply(...args) {
2984
+ const quat = _Quaternion.resolveArgs(args);
2735
2985
  return new _Quaternion(
2736
2986
  this.w * quat.w - this.x * quat.x - this.y * quat.y - this.z * quat.z,
2737
2987
  this.w * quat.x + this.x * quat.w + this.y * quat.z - this.z * quat.y,
@@ -2754,21 +3004,21 @@ var Quaternion = class _Quaternion {
2754
3004
  scale(scalar) {
2755
3005
  return new _Quaternion(this.w * scalar, this.x * scalar, this.y * scalar, this.z * scalar);
2756
3006
  }
2757
- dot(a) {
2758
- const quat = _Quaternion.resolve(a);
3007
+ dot(...args) {
3008
+ const quat = _Quaternion.resolveArgs(args);
2759
3009
  return this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z;
2760
3010
  }
2761
3011
  inverse() {
2762
3012
  let length = this.length(false);
2763
3013
  if (length == 0)
2764
- return new _Quaternion();
3014
+ return _Quaternion.zero;
2765
3015
  length = 1 / length;
2766
3016
  return new _Quaternion(this.w * length, -this.x * length, -this.y * length, -this.z * length);
2767
3017
  }
2768
- divide(a) {
2769
- const quat = _Quaternion.resolve(a);
3018
+ divide(...args) {
3019
+ const quat = _Quaternion.resolveArgs(args);
2770
3020
  let length = quat.length(false);
2771
- if (length == 0) return new _Quaternion();
3021
+ if (length == 0) return _Quaternion.zero;
2772
3022
  length = 1 / length;
2773
3023
  return new _Quaternion(
2774
3024
  (this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z) * length,
@@ -2785,7 +3035,7 @@ var Quaternion = class _Quaternion {
2785
3035
  const exp = Math.exp(this.w);
2786
3036
  const scale = exp * Math.sin(length) / length;
2787
3037
  if (length == 0)
2788
- return new _Quaternion(exp);
3038
+ return new _Quaternion(exp, 0, 0, 0);
2789
3039
  return new _Quaternion(
2790
3040
  exp * Math.cos(length),
2791
3041
  this.x * scale,
@@ -2795,14 +3045,14 @@ var Quaternion = class _Quaternion {
2795
3045
  }
2796
3046
  log() {
2797
3047
  if (this.x == 0 && this.z == 0)
2798
- return new _Quaternion(log_hypot(this.w, this.x), Math.atan2(this.x, this.w));
3048
+ return new _Quaternion(logHypot(this.w, this.x), Math.atan2(this.x, this.w), 0, 0);
2799
3049
  const length = this.length(false);
2800
3050
  const length2 = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
2801
3051
  const scale = Math.atan2(length2, this.w) / length;
2802
3052
  return new _Quaternion(Math.log(length) * 0.5, this.x * scale, this.y * scale, this.z * scale);
2803
3053
  }
2804
- toVector() {
2805
- return new Vec3(this.x, this.y, this.z, this.w);
3054
+ toVec3() {
3055
+ return [this.x, this.y, this.z, this.w];
2806
3056
  }
2807
3057
  toAxisAngle() {
2808
3058
  const sin2 = 1 - this.w * this.w;
@@ -2813,17 +3063,17 @@ var Quaternion = class _Quaternion {
2813
3063
  return new Vec3(this.x * isin, this.y * isin, this.z * isin, angle);
2814
3064
  }
2815
3065
  toEuler() {
2816
- function asin(t) {
3066
+ function __asin__(t) {
2817
3067
  return t >= 1 ? Math.PI / 2 : t <= -1 ? -Math.PI / 2 : Math.asin(t);
2818
3068
  }
2819
3069
  return new Vec3(
2820
3070
  -Math.atan2(2 * (this.y * this.z - this.w * this.x), 1 - 2 * (this.x * this.x + this.y * this.y)),
2821
- asin(2 * (this.x * this.z + this.w * this.y)),
3071
+ __asin__(2 * (this.x * this.z + this.w * this.y)),
2822
3072
  -Math.atan2(2 * (this.x * this.y - this.w * this.z), 1 - 2 * (this.y * this.y + this.z * this.z))
2823
3073
  );
2824
3074
  }
2825
3075
  toMat3() {
2826
- return new Mat3([
3076
+ return [
2827
3077
  1 - 2 * (this.y * this.y + this.z * this.z),
2828
3078
  2 * (this.x * this.y - this.w * this.z),
2829
3079
  2 * (this.x * this.z + this.w * this.y),
@@ -2833,10 +3083,10 @@ var Quaternion = class _Quaternion {
2833
3083
  2 * (this.x * this.z - this.w * this.y),
2834
3084
  2 * (this.y * this.z + this.w * this.x),
2835
3085
  1 - 2 * (this.x * this.x + this.y * this.y)
2836
- ]);
3086
+ ];
2837
3087
  }
2838
3088
  toMat4() {
2839
- return new Mat4([
3089
+ return [
2840
3090
  1 - 2 * (this.y * this.y + this.z * this.z),
2841
3091
  2 * (this.x * this.y - this.w * this.z),
2842
3092
  2 * (this.x * this.z + this.w * this.y),
@@ -2853,40 +3103,156 @@ var Quaternion = class _Quaternion {
2853
3103
  0,
2854
3104
  0,
2855
3105
  1
2856
- ]);
3106
+ ];
2857
3107
  }
2858
3108
  };
2859
3109
 
2860
3110
  // source/transform.ts
2861
- var Transform = class {
3111
+ var Transform2D = class {
3112
+ constructor(position, rotation, scale, parent) {
3113
+ this.parent = parent;
3114
+ this.localPosition = Vec2.resolve(position);
3115
+ this.localRotation = rotation;
3116
+ this.localScale = Vec2.resolve(scale);
3117
+ }
3118
+ origin = Vec2.zero;
3119
+ localPosition;
3120
+ localRotation;
3121
+ get localRotationDegree() {
3122
+ return radianToDegree(this.localRotation);
3123
+ }
3124
+ set localRotationDegree(v) {
3125
+ this.localRotation = degreeToRadian(v);
3126
+ }
3127
+ localScale;
3128
+ get globalPosition() {
3129
+ let position = Vec2.zero;
3130
+ let transform = this;
3131
+ while (transform !== void 0) {
3132
+ position = position.add(transform.localPosition).add(transform.origin);
3133
+ transform = transform.parent;
3134
+ }
3135
+ return position;
3136
+ }
3137
+ get globalRotation() {
3138
+ let rotation = 0;
3139
+ let transform = this;
3140
+ while (transform !== void 0) {
3141
+ rotation += transform.localRotation;
3142
+ transform = transform.parent;
3143
+ }
3144
+ return rotation;
3145
+ }
3146
+ get globalRotationDegree() {
3147
+ return radianToDegree(this.globalRotation);
3148
+ }
3149
+ get globalScale() {
3150
+ let scale = Vec2.one;
3151
+ let transform = this;
3152
+ while (transform !== void 0) {
3153
+ scale = scale.naiveMultiply(transform.localScale);
3154
+ transform = transform.parent;
3155
+ }
3156
+ return scale;
3157
+ }
3158
+ toString() {
3159
+ return `${this.localPosition.toString()}|${this.localRotation}|${this.localScale.toString()}`;
3160
+ }
3161
+ get [Symbol.toStringTag]() {
3162
+ return "Transform2D";
3163
+ }
3164
+ [NodeJSCustomInspect]() {
3165
+ return `Transform2D <${this.toString()}>`;
3166
+ }
3167
+ toMat3() {
3168
+ return new Mat3().scale(this.localScale).rotate(this.localRotation).translate(this.localPosition);
3169
+ }
3170
+ toGlobalMat3() {
3171
+ let result = new Mat3();
3172
+ let transform = this;
3173
+ while (transform !== void 0) {
3174
+ result = result.multiply(transform.toMat3());
3175
+ transform = transform.parent;
3176
+ }
3177
+ return result;
3178
+ }
3179
+ };
3180
+ var Transform3D = class {
2862
3181
  /**
2863
- * The position of the object
3182
+ * Create a new transform with `position`, `rotation` and `scale`
3183
+ * @param position The position as a Vec3
3184
+ * @param rotation The rotation as a Quaternion
3185
+ * @param scale The scale as a Vec3
2864
3186
  */
2865
- position;
3187
+ constructor(position, rotation, scale, parent) {
3188
+ this.parent = parent;
3189
+ this.localPosition = Vec3.resolve(position);
3190
+ this.localRotation = Quaternion.resolve(rotation);
3191
+ this.localScale = Vec3.resolve(scale);
3192
+ }
3193
+ origin = Vec3.zero;
2866
3194
  /**
2867
- * The rotation of the object
3195
+ * The local position
2868
3196
  */
2869
- rotation;
3197
+ localPosition;
2870
3198
  /**
2871
- * The scale of the object
3199
+ * The local rotation
2872
3200
  */
2873
- scale;
3201
+ localRotation;
2874
3202
  /**
2875
- * Create a new transform with `position`, `rotation` and `scale`
2876
- * @param position The position as a Vec3
2877
- * @param rotation The rotation as a Quaternion
2878
- * @param scale The scale as a Vec3
3203
+ * The local scale
2879
3204
  */
2880
- constructor(position, rotation, scale) {
2881
- this.position = Vec3.resolve(position);
2882
- this.rotation = Quaternion.resolve(rotation);
2883
- this.scale = Vec3.resolve(scale);
3205
+ localScale;
3206
+ get globalPosition() {
3207
+ let position = Vec3.zero;
3208
+ let transform = this;
3209
+ while (transform !== void 0) {
3210
+ position = position.add(transform.localPosition).add(transform.origin);
3211
+ transform = transform.parent;
3212
+ }
3213
+ return position;
3214
+ }
3215
+ get globalRotation() {
3216
+ let rotation = Quaternion.zero;
3217
+ let transform = this;
3218
+ while (transform !== void 0) {
3219
+ rotation = rotation.add(transform.localRotation);
3220
+ transform = transform.parent;
3221
+ }
3222
+ return rotation;
3223
+ }
3224
+ get globalScale() {
3225
+ let scale = Vec3.one;
3226
+ let transform = this;
3227
+ while (transform !== void 0) {
3228
+ scale = scale.naiveMultiply(transform.localScale);
3229
+ transform = transform.parent;
3230
+ }
3231
+ return scale;
3232
+ }
3233
+ toString() {
3234
+ return `${this.localPosition.toString()}|${this.localRotation.toString()}|${this.localScale.toString()}`;
3235
+ }
3236
+ get [Symbol.toStringTag]() {
3237
+ return "Transform2D";
3238
+ }
3239
+ [NodeJSCustomInspect]() {
3240
+ return `Transform2D <${this.toString()}>`;
2884
3241
  }
2885
3242
  /**
2886
3243
  * Convert the transform into a 4x3 matrix
2887
3244
  * @returns A 4x4 matrix from the transform
2888
3245
  */
2889
3246
  toMat4() {
2890
- return new Mat4().translate(this.position).multiply(this.rotation.toMat4()).scale(this.scale);
3247
+ return new Mat4().scale(this.localScale).multiply(this.localRotation).translate(this.localPosition);
3248
+ }
3249
+ toGlobalMat4() {
3250
+ let result = new Mat4();
3251
+ let transform = this;
3252
+ while (transform !== void 0) {
3253
+ result = result.multiply(transform.toMat4());
3254
+ transform = transform.parent;
3255
+ }
3256
+ return result;
2891
3257
  }
2892
3258
  };