@ntf/math 1.3.2 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -20,14 +20,14 @@ 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,
@@ -36,37 +36,30 @@ __export(index_exports, {
36
36
  MathFunction: () => MathFunction,
37
37
  QuadFunction: () => QuadFunction,
38
38
  Quaternion: () => Quaternion,
39
- RGBAColor: () => RGBAColor,
39
+ RGBA: () => RGBA,
40
40
  Rectangle: () => Rectangle,
41
41
  ResolveError: () => ResolveError,
42
42
  Size: () => Size,
43
- Transform: () => Transform,
43
+ Transform2D: () => Transform2D,
44
+ Transform3D: () => Transform3D,
45
+ Triangle: () => Triangle,
44
46
  Triangle2D: () => Triangle2D,
45
47
  Triangle3D: () => Triangle3D,
46
48
  Vec2: () => Vec2,
47
49
  Vec3: () => Vec3,
48
- cap_angle_degree: () => cap_angle_degree,
49
- cap_angle_radian: () => cap_angle_radian,
50
- castColor: () => castColor,
51
- check_array: () => check_array,
52
- check_hex: () => check_hex,
53
- check_hex_digit: () => check_hex_digit,
54
- check_number: () => check_number,
55
- check_number_array: () => check_number_array,
56
- check_string: () => check_string,
57
- check_string_array: () => check_string_array,
58
50
  clamp: () => clamp,
59
- degree_to_radian: () => degree_to_radian,
51
+ clampAngleDegree: () => clampAngleDegree,
52
+ clampAngleRadian: () => clampAngleRadian,
53
+ degreeToRadian: () => degreeToRadian,
60
54
  djb2: () => djb2,
61
55
  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,
56
+ lerp: () => lerp,
57
+ logHypot: () => logHypot,
58
+ numberToRGB: () => numberToRGB,
59
+ numberToRGBA: () => numberToRGBA,
60
+ radianToDegree: () => radianToDegree,
67
61
  sdbm: () => sdbm,
68
- sign_char: () => sign_char,
69
- stringify: () => stringify
62
+ signCharacter: () => signCharacter
70
63
  });
71
64
  module.exports = __toCommonJS(index_exports);
72
65
 
@@ -74,8 +67,11 @@ module.exports = __toCommonJS(index_exports);
74
67
  var MathFunction = class {
75
68
  };
76
69
 
70
+ // source/algebra/linear.ts
71
+ var import_types2 = require("@ntf/types");
72
+
77
73
  // source/common/sign.ts
78
- function sign_char(num) {
74
+ function signCharacter(num) {
79
75
  if (num == 0)
80
76
  return void 0;
81
77
  if (num < 0)
@@ -85,148 +81,22 @@ function sign_char(num) {
85
81
  return void 0;
86
82
  }
87
83
 
88
- // source/common/types.ts
89
- function check_number(obj) {
90
- return obj != null && typeof obj == "number" && !isNaN(obj) && isFinite(obj);
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) {
118
- let offset = 0;
119
- if (string.startsWith("#") || string.startsWith("$"))
120
- offset = 1;
121
- if (string.startsWith("0x"))
122
- offset = 2;
123
- return string.substring(offset);
124
- }
125
- function check_hex(obj) {
126
- if (!check_string(obj))
127
- return false;
128
- const value = get_hex_part(obj).split("").map((char) => parseInt(char.toUpperCase(), 16));
129
- return check_number_array(value);
130
- }
131
- function check_string(obj) {
132
- return obj != null && typeof obj == "string" && obj.length > 0;
133
- }
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))
139
- return false;
140
- return true;
141
- }
142
- function check_number_array(obj, requiredLength) {
143
- return check_array(obj, check_number, requiredLength);
144
- }
145
- function check_string_array(obj, requiredLength) {
146
- return check_array(obj, check_string, requiredLength);
147
- }
148
- function has_property(obj, name, type) {
149
- return obj != null && typeof obj == "object" && name in obj && typeof obj[name] == type;
150
- }
151
-
152
84
  // source/common/error.ts
153
85
  var ResolveError = class extends Error {
86
+ /**
87
+ * Create a resolve exception
88
+ * @param target The target type name
89
+ * @param value A value
90
+ */
154
91
  constructor(target, value) {
155
- super(`can't resolve ${value} to ${target}`);
92
+ super(`Can't resolve ${value} to ${target}`);
156
93
  this.target = target;
157
94
  this.value = value;
158
95
  }
159
96
  };
160
97
 
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
- };
98
+ // source/vectors/vec2.ts
99
+ var import_types = require("@ntf/types");
230
100
 
231
101
  // source/utils.ts
232
102
  function clamp(value, min, max) {
@@ -236,7 +106,7 @@ function clamp(value, min, max) {
236
106
  return max;
237
107
  return value;
238
108
  }
239
- function log_hypot(a, b) {
109
+ function logHypot(a, b) {
240
110
  const a_abs = Math.abs(a);
241
111
  const b_abs = Math.abs(b);
242
112
  if (a == 0)
@@ -249,41 +119,43 @@ function log_hypot(a, b) {
249
119
  return 0.5 * Math.log(_a * _a + _b * _b) + Math.LN2;
250
120
  }
251
121
  var EPSILON = 1e-16;
122
+ var lerp = (a, b, t) => ((typeof a == "number" ? 1 : 1n) - t) * a + t * b;
252
123
 
253
- // source/vectors/vec3.ts
254
- var Vec3 = class _Vec3 {
124
+ // source/vectors/vec2.ts
125
+ var Vec2 = class _Vec2 {
255
126
  x;
256
127
  y;
257
- z;
258
128
  w;
259
129
  static resolve(a) {
260
130
  const value = this.cast(a);
261
131
  if (typeof value != "undefined")
262
132
  return value;
263
- throw new ResolveError("Vec3", a);
133
+ throw new ResolveError("Vec2", a);
264
134
  }
265
135
  static cast(a) {
266
136
  if (a == null || typeof a == "undefined")
267
137
  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);
138
+ if ((0, import_types.isFixedTypeArray)(a, import_types.isValidNumber, 2) || (0, import_types.isFixedTypeArray)(a, import_types.isValidNumber, 3))
139
+ return new this(a[0], a[1], a[2]);
140
+ if ((0, import_types.hasObjectProperty)(a, "toVec2", "function"))
141
+ return this.cast(a.toVec2());
142
+ if ((0, import_types.hasObjectProperty)(a, "x", "number") && (0, import_types.hasObjectProperty)(a, "y", "number"))
143
+ return new this(a.x, a.y, (0, import_types.hasObjectProperty)(a, "w", "number") ? a.w : void 0);
144
+ if ((0, import_types.isValidString)(a)) {
145
+ const [sxy, sw] = a.split(";");
146
+ if ((0, import_types.isValidString)(sxy)) {
147
+ const parts = sxy.split(",");
148
+ if ((0, import_types.isFixedTypeArray)(parts, import_types.isValidString, 2))
149
+ return new this(parseFloat(parts[0]), parseFloat(parts[1]), (0, import_types.isValidString)(sw) ? parseFloat(sw) : void 0);
278
150
  }
279
151
  }
280
- if (check_number(a))
281
- return new this(a, a, a);
152
+ if ((0, import_types.isValidNumber)(a))
153
+ return new this(a, a);
282
154
  return void 0;
283
155
  }
284
156
  static resolveArgs(args) {
285
- if (check_number_array(args, 3))
286
- return new this(args[0], args[1], args[2]);
157
+ if ((0, import_types.isFixedTypeArray)(args, import_types.isValidNumber, 2))
158
+ return new this(args[0], args[1]);
287
159
  return this.resolve(args[0]);
288
160
  }
289
161
  static is(a) {
@@ -292,63 +164,76 @@ var Vec3 = class _Vec3 {
292
164
  static fromPoints(a, b) {
293
165
  const veca = this.resolve(a);
294
166
  const vecb = this.resolve(b);
295
- return new this(vecb.x - veca.x, vecb.y - veca.y, vecb.z - veca.z);
167
+ return new this(vecb.x - veca.x, vecb.y - veca.y);
296
168
  }
297
169
  static clamp(value, min, max) {
298
170
  const a = this.resolve(value), b = this.resolve(min), c = this.resolve(max);
299
171
  return new this(
300
172
  clamp(a.x, b.x, c.x),
301
- clamp(a.y, b.y, c.y),
302
- clamp(a.z, b.z, c.z)
173
+ clamp(a.y, b.y, c.y)
303
174
  );
304
175
  }
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);
176
+ static get zero() {
177
+ return new this(0, 0);
178
+ }
179
+ static get one() {
180
+ return new this(1, 1);
314
181
  }
315
- constructor(x = 0, y = 0, z = 0, w = 1) {
316
- if (!check_number(x))
317
- throw new TypeError("expected number for x");
318
- if (!check_number(y))
319
- 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))
323
- throw new TypeError("expected number for w");
182
+ constructor(x, y, w = 1) {
183
+ (0, import_types.checkValidNumber)(x);
184
+ (0, import_types.checkValidNumber)(y);
185
+ (0, import_types.checkValidNumber)(w);
324
186
  this.x = x;
325
187
  this.y = y;
326
- this.z = z;
327
188
  this.w = w;
328
189
  }
329
- toArray(w = false) {
330
- return w ? [this.x, this.y, this.z] : [this.x, this.y, this.z, this.w];
190
+ toArray(w = this.w !== 1) {
191
+ return w ? [this.x, this.y, this.w] : [this.x, this.y];
331
192
  }
332
193
  toJSON() {
333
194
  return {
334
195
  x: this.x,
335
196
  y: this.y,
336
- z: this.z,
337
197
  w: this.w
338
198
  };
339
199
  }
340
- toString(w = false) {
341
- return w ? `${this.x},${this.y},${this.z}` : `${this.x},${this.y},${this.z};${this.w}`;
200
+ toString(w = this.w !== 1) {
201
+ return w ? `${this.x},${this.y};${this.w}` : `${this.x},${this.y}`;
342
202
  }
343
- toVec2() {
344
- return [this.x, this.y, this.w];
203
+ get [Symbol.toStringTag]() {
204
+ return "Vec2";
205
+ }
206
+ [import_types.NodeJSCustomInspect]() {
207
+ return `Vec2 <${this.toString()}>`;
208
+ }
209
+ toSize() {
210
+ return [this.x, this.y];
211
+ }
212
+ toVec3(z = 0) {
213
+ return [this.x, this.y, z, this.w];
214
+ }
215
+ toRGB() {
216
+ const vec = this.normalize();
217
+ return [vec.x, vec.y, vec.w];
218
+ }
219
+ toRGBA() {
220
+ const vec = this.normalize();
221
+ return [vec.x, vec.y, vec.w, 1];
222
+ }
223
+ toHSL() {
224
+ const vec = this.normalize();
225
+ return [vec.x, vec.y, vec.w];
226
+ }
227
+ toHSLA() {
228
+ const vec = this.normalize();
229
+ return [vec.x, vec.y, vec.w, 1];
345
230
  }
346
231
  clone() {
347
- return new _Vec3(this.x, this.y, this.z, this.w);
232
+ return new _Vec2(this.x, this.y, this.w);
348
233
  }
349
- equals(vec) {
350
- const a = _Vec3.resolve(vec);
351
- return this.x == a.x && this.y == a.y && this.z == a.z;
234
+ equals(...args) {
235
+ const a = _Vec2.resolveArgs(args);
236
+ return this.x == a.x && this.y == a.y;
352
237
  }
353
238
  setX(x) {
354
239
  this.x = x;
@@ -358,139 +243,257 @@ var Vec3 = class _Vec3 {
358
243
  this.y = y;
359
244
  return this;
360
245
  }
361
- setZ(z) {
362
- this.z = z;
246
+ setW(w) {
247
+ this.w = w;
363
248
  return this;
364
249
  }
365
250
  set(...args) {
366
- const vec = _Vec3.resolveArgs(args);
367
- return this.setX(vec.x).setY(vec.y).setZ(vec.z);
251
+ const vec = _Vec2.resolveArgs(args);
252
+ return this.setX(vec.x).setY(vec.y);
368
253
  }
369
254
  add(...args) {
370
- const vec = _Vec3.resolveArgs(args);
371
- return new _Vec3(
255
+ const vec = _Vec2.resolveArgs(args);
256
+ return new _Vec2(
372
257
  this.x + vec.x,
373
- this.y + vec.y,
374
- this.z + vec.z
258
+ this.y + vec.y
375
259
  );
376
260
  }
377
261
  offset(...args) {
378
- const vec = _Vec3.resolveArgs(args);
262
+ const vec = _Vec2.resolveArgs(args);
379
263
  this.x += vec.x;
380
264
  this.y += vec.y;
381
- this.z += vec.z;
382
265
  return this;
383
266
  }
384
267
  subtract(...args) {
385
- const vec = _Vec3.resolveArgs(args);
386
- return new _Vec3(
268
+ const vec = _Vec2.resolveArgs(args);
269
+ return new _Vec2(
387
270
  this.x - vec.x,
388
- this.y - vec.y,
389
- this.z - vec.z
271
+ this.y - vec.y
390
272
  );
391
273
  }
392
274
  multiply(scalar) {
393
- return new _Vec3(
275
+ return new _Vec2(
394
276
  this.x * scalar,
395
- this.y * scalar,
396
- this.z * scalar
277
+ this.y * scalar
397
278
  );
398
279
  }
399
280
  naiveMultiply(...args) {
400
- const vec = _Vec3.resolveArgs(args);
401
- return new _Vec3(
281
+ const vec = _Vec2.resolveArgs(args);
282
+ return new _Vec2(
402
283
  this.x * vec.x,
403
- this.y * vec.y,
404
- this.z * vec.z
284
+ this.y * vec.y
405
285
  );
406
286
  }
407
287
  divide(...args) {
408
- if (check_number_array(args, 1))
409
- return new _Vec3(
288
+ if ((0, import_types.isFixedTypeArray)(args, import_types.isValidNumber, 1))
289
+ return new _Vec2(
410
290
  this.x / args[0],
411
- this.y / args[0],
412
- this.z / args[0]
291
+ this.y / args[0]
413
292
  );
414
- const vec = _Vec3.resolveArgs(args);
415
- return new _Vec3(
293
+ const vec = _Vec2.resolveArgs(args);
294
+ return new _Vec2(
416
295
  this.x / vec.x,
417
- this.y / vec.y,
418
- this.z / vec.z
296
+ this.y / vec.y
419
297
  );
420
298
  }
421
299
  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
- );
300
+ const vec = _Vec2.resolveArgs(args);
301
+ return this.x * vec.x + this.y * vec.y;
432
302
  }
433
303
  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);
304
+ const vec = _Vec2.resolveArgs(args);
305
+ return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2);
436
306
  }
437
307
  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));
308
+ const vec = _Vec2.resolveArgs(args);
309
+ return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2));
440
310
  }
441
311
  length() {
442
- return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
312
+ return Math.sqrt(this.x * this.x + this.y * this.y);
313
+ }
314
+ cartesianify() {
315
+ return new _Vec2(
316
+ this.x * Math.cos(this.y),
317
+ this.x * Math.sin(this.y)
318
+ );
319
+ }
320
+ polarify() {
321
+ return new _Vec2(
322
+ Math.sqrt(this.x * this.x + this.y * this.y),
323
+ Math.atan(this.y / this.x)
324
+ );
443
325
  }
444
326
  normalize() {
445
327
  const length = this.length();
446
- if (length == 0) return new _Vec3();
447
- return new _Vec3(
328
+ if (length == 0) return _Vec2.zero;
329
+ return new _Vec2(
448
330
  this.x / length,
449
331
  this.y / length,
450
- this.z / length
332
+ this.w / length
451
333
  );
452
334
  }
453
335
  invert() {
454
336
  return this.multiply(-1);
455
337
  }
456
338
  round() {
457
- return new _Vec3(Math.round(this.x), Math.round(this.y), Math.round(this.z), Math.round(this.w));
339
+ return new _Vec2(Math.round(this.x), Math.round(this.y), Math.round(this.w));
458
340
  }
459
341
  };
460
342
 
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);
343
+ // source/algebra/linear.ts
344
+ var LinearFunction = class extends MathFunction {
345
+ /**
346
+ * The factor of the linear function
347
+ */
348
+ m;
349
+ /**
350
+ * The height of the linear function
351
+ */
352
+ b;
353
+ /**
354
+ * Create a linear function from two points
355
+ * @param a A point
356
+ * @param b A point
357
+ * @returns A linear function from two points
358
+ */
359
+ static fromPoints(a, b) {
360
+ const veca = Vec2.resolve(a);
361
+ const vecb = Vec2.resolve(b);
362
+ const m = (vecb.y - veca.y) / (vecb.x - veca.x);
363
+ const h = -m * veca.x + veca.y;
364
+ return new this(m, h);
471
365
  }
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;
366
+ /**
367
+ * Create a linear function with a factor and height
368
+ * @param m The factor
369
+ * @param b The height
370
+ */
371
+ constructor(m, b) {
372
+ super();
373
+ (0, import_types2.checkValidNumber)(m);
374
+ (0, import_types2.checkValidNumber)(b);
375
+ this.m = m;
376
+ this.b = b;
377
+ }
378
+ get(x) {
379
+ (0, import_types2.checkValidNumber)(x);
380
+ return this.m * x + this.b;
381
+ }
382
+ roots() {
383
+ const x = -this.b / this.m;
384
+ if (!isNaN(x))
385
+ return [new Vec2(x, 0)];
386
+ return [];
387
+ }
388
+ toString() {
389
+ const bsign = signCharacter(this.b);
390
+ if (bsign)
391
+ return `f(x) = ${this.m} * x ${bsign} ${Math.abs(this.b)}`;
392
+ return `f(x) = ${this.m} * x`;
393
+ }
394
+ get [Symbol.toStringTag]() {
395
+ return "LinearFunction";
396
+ }
397
+ [import_types2.NodeJSCustomInspect]() {
398
+ return `LinearFunction <${this.toString()}>`;
399
+ }
400
+ };
401
+
402
+ // source/algebra/quad.ts
403
+ var import_types3 = require("@ntf/types");
404
+ var QuadFunction = class extends MathFunction {
405
+ a;
406
+ b;
407
+ c;
408
+ static get(a, b, c, x) {
409
+ return new this(a, b, c).get(x);
410
+ }
411
+ constructor(a, b, c) {
412
+ super();
413
+ (0, import_types3.checkValidNumber)(a);
414
+ if (a === 0)
415
+ throw new import_types3.ExpectedTypeError("non-zero valid number", a);
416
+ (0, import_types3.checkValidNumber)(b);
417
+ (0, import_types3.checkValidNumber)(c);
418
+ this.a = a;
419
+ this.b = b;
420
+ this.c = c;
421
+ }
422
+ get(x) {
423
+ (0, import_types3.checkValidNumber)(x);
424
+ return this.a * x * x + this.b * x + this.c;
425
+ }
426
+ roots() {
427
+ const roots = new Array();
428
+ const discriminant = this.b * this.b - 4 * this.a * this.c;
429
+ const n0 = (-this.b + Math.sqrt(discriminant)) / (2 * this.a);
430
+ const n1 = (-this.b + Math.sqrt(discriminant)) / (2 * this.a);
431
+ if (!isNaN(n0))
432
+ roots.push(new Vec2(n0, 0));
433
+ if (!isNaN(n1) && n0 != n1)
434
+ roots.push(new Vec2(n1, 0));
435
+ return roots;
436
+ }
437
+ toString(type = "standard") {
438
+ switch (type) {
439
+ default:
440
+ case "standard": {
441
+ const bsign = signCharacter(this.b);
442
+ const csign = signCharacter(this.c);
443
+ if (bsign && csign)
444
+ return `f(x) = ${this.a}x^2 ${bsign} ${Math.abs(this.b)}x ${csign} ${Math.abs(this.c)}`;
445
+ if (bsign)
446
+ return `f(x) = ${this.a}x^2 ${bsign} ${Math.abs(this.b)}x`;
447
+ return `f(x) = ${this.a}x^2`;
448
+ }
449
+ }
450
+ }
451
+ get [Symbol.toStringTag]() {
452
+ return "QuadFunction";
453
+ }
454
+ [import_types3.NodeJSCustomInspect]() {
455
+ return `QuadFunction <${this.toString()}>`;
456
+ }
457
+ };
458
+
459
+ // source/algebra/quaternion.ts
460
+ var import_types5 = require("@ntf/types");
461
+
462
+ // source/vectors/vec3.ts
463
+ var import_types4 = require("@ntf/types");
464
+ var Vec3 = class _Vec3 {
465
+ x;
466
+ y;
467
+ z;
468
+ w;
469
+ static resolve(a) {
470
+ const value = this.cast(a);
471
+ if (typeof value != "undefined")
472
+ return value;
473
+ throw new ResolveError("Vec3", a);
474
+ }
475
+ static cast(a) {
476
+ if (a == null || typeof a == "undefined")
477
+ return void 0;
478
+ if ((0, import_types4.isFixedTypeArray)(a, import_types4.isValidNumber, 3) || (0, import_types4.isFixedTypeArray)(a, import_types4.isValidNumber, 4))
479
+ return new this(a[0], a[1], a[2], a[3]);
480
+ if ((0, import_types4.hasObjectProperty)(a, "x", "number") && (0, import_types4.hasObjectProperty)(a, "y", "number") && (0, import_types4.hasObjectProperty)(a, "z", "number"))
481
+ return new this(a.x, a.y, a.z, (0, import_types4.hasObjectProperty)(a, "w", "number") ? a.w : void 0);
482
+ if ((0, import_types4.isValidString)(a)) {
483
+ const [sxyz, sw] = a.split(";");
484
+ if ((0, import_types4.isValidString)(sxyz)) {
485
+ const parts = sxyz.split(",");
486
+ if ((0, import_types4.isFixedTypeArray)(parts, import_types4.isValidString, 3))
487
+ return new this(parseFloat(parts[0]), parseFloat(parts[1]), parseFloat(parts[2]), (0, import_types4.isValidString)(sw) ? parseFloat(sw) : void 0);
488
+ }
489
+ }
490
+ if ((0, import_types4.isValidNumber)(a))
491
+ return new this(a, a, a);
492
+ return void 0;
490
493
  }
491
494
  static resolveArgs(args) {
492
- if (check_number_array(args, 2))
493
- return new this(args[0], args[1]);
495
+ if ((0, import_types4.isFixedTypeArray)(args, import_types4.isValidNumber, 3))
496
+ return new this(args[0], args[1], args[2]);
494
497
  return this.resolve(args[0]);
495
498
  }
496
499
  static is(a) {
@@ -499,51 +502,90 @@ var Vec2 = class _Vec2 {
499
502
  static fromPoints(a, b) {
500
503
  const veca = this.resolve(a);
501
504
  const vecb = this.resolve(b);
502
- return new this(vecb.x - veca.x, vecb.y - veca.y);
505
+ return new this(vecb.x - veca.x, vecb.y - veca.y, vecb.z - veca.z);
503
506
  }
504
507
  static clamp(value, min, max) {
505
508
  const a = this.resolve(value), b = this.resolve(min), c = this.resolve(max);
506
509
  return new this(
507
510
  clamp(a.x, b.x, c.x),
508
- clamp(a.y, b.y, c.y)
511
+ clamp(a.y, b.y, c.y),
512
+ clamp(a.z, b.z, c.z)
509
513
  );
510
514
  }
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");
515
+ static intersectPlane(planeP, planeN, lineStart, lineEnd, t) {
516
+ planeN = this.resolve(planeN).normalize();
517
+ const plane_d = -this.resolve(planeN).dot(planeP);
518
+ const ad = this.resolve(lineStart).dot(planeN);
519
+ const bd = this.resolve(lineEnd).dot(planeN);
520
+ t = (-plane_d - ad) / (bd - ad);
521
+ const lineStartToEnd = this.resolve(lineEnd).subtract(lineStart);
522
+ const linetoIntersect = lineStartToEnd.multiply(t);
523
+ return _Vec3.resolve(lineStart).add(linetoIntersect);
524
+ }
525
+ static get zero() {
526
+ return new this(0, 0, 0);
527
+ }
528
+ static get one() {
529
+ return new this(1, 1, 1);
530
+ }
531
+ constructor(x, y, z, w = 1) {
532
+ (0, import_types4.checkValidNumber)(x);
533
+ (0, import_types4.checkValidNumber)(y);
534
+ (0, import_types4.checkValidNumber)(z);
535
+ (0, import_types4.checkValidNumber)(w);
518
536
  this.x = x;
519
537
  this.y = y;
538
+ this.z = z;
520
539
  this.w = w;
521
540
  }
522
- toArray(w = false) {
523
- return w ? [this.x, this.y] : [this.x, this.y, this.w];
541
+ toArray(w = this.w !== 1) {
542
+ return w ? [this.x, this.y, this.z, this.w] : [this.x, this.y, this.z];
524
543
  }
525
544
  toJSON() {
526
545
  return {
527
546
  x: this.x,
528
547
  y: this.y,
548
+ z: this.z,
529
549
  w: this.w
530
550
  };
531
551
  }
532
- toString(w = false) {
533
- return w ? `${this.x},${this.y}` : `${this.x},${this.y};${this.w}`;
552
+ toString(w = this.w !== 1) {
553
+ return w ? `${this.x},${this.y},${this.z};${this.w}` : `${this.x},${this.y},${this.z}`;
554
+ }
555
+ get [Symbol.toStringTag]() {
556
+ return "Vec3";
534
557
  }
535
- toSquare() {
536
- return new Size(this.x, this.y);
558
+ [import_types4.NodeJSCustomInspect]() {
559
+ return `Vec3 <${this.toString()}>`;
537
560
  }
538
- toVec3(z) {
539
- return new Vec3(this.x, this.y, z, this.w);
561
+ toVec2() {
562
+ return [this.x, this.y, this.w];
563
+ }
564
+ toRGB() {
565
+ const vec = this.normalize();
566
+ return [vec.x, vec.y, vec.z];
567
+ }
568
+ toRGBA() {
569
+ const vec = this.normalize();
570
+ return [vec.x, vec.y, vec.z, vec.w];
571
+ }
572
+ toHSL() {
573
+ const vec = this.normalize();
574
+ return [vec.x, vec.y, vec.z];
575
+ }
576
+ toHSLA() {
577
+ const vec = this.normalize();
578
+ return [vec.x, vec.y, vec.z, vec.w];
579
+ }
580
+ toQuaternion() {
581
+ return [this.w, this.x, this.y, this.z];
540
582
  }
541
583
  clone() {
542
- return new _Vec2(this.x, this.y, this.w);
584
+ return new _Vec3(this.x, this.y, this.z, this.w);
543
585
  }
544
- equals(vec) {
545
- const a = _Vec2.resolve(vec);
546
- return this.x == a.x && this.y == a.y;
586
+ equals(...args) {
587
+ const a = _Vec3.resolveArgs(args);
588
+ return this.x == a.x && this.y == a.y && this.z == a.z;
547
589
  }
548
590
  setX(x) {
549
591
  this.x = x;
@@ -553,221 +595,686 @@ var Vec2 = class _Vec2 {
553
595
  this.y = y;
554
596
  return this;
555
597
  }
556
- setW(w) {
557
- this.w = w;
598
+ setZ(z) {
599
+ this.z = z;
558
600
  return this;
559
601
  }
560
602
  set(...args) {
561
- const vec = _Vec2.resolveArgs(args);
562
- return this.setX(vec.x).setY(vec.y);
603
+ const vec = _Vec3.resolveArgs(args);
604
+ return this.setX(vec.x).setY(vec.y).setZ(vec.z);
563
605
  }
564
606
  add(...args) {
565
- const vec = _Vec2.resolveArgs(args);
566
- return new _Vec2(
607
+ const vec = _Vec3.resolveArgs(args);
608
+ return new _Vec3(
567
609
  this.x + vec.x,
568
- this.y + vec.y
610
+ this.y + vec.y,
611
+ this.z + vec.z
569
612
  );
570
613
  }
571
614
  offset(...args) {
572
- const vec = _Vec2.resolveArgs(args);
615
+ const vec = _Vec3.resolveArgs(args);
573
616
  this.x += vec.x;
574
617
  this.y += vec.y;
618
+ this.z += vec.z;
575
619
  return this;
576
620
  }
577
621
  subtract(...args) {
578
- const vec = _Vec2.resolveArgs(args);
579
- return new _Vec2(
622
+ const vec = _Vec3.resolveArgs(args);
623
+ return new _Vec3(
580
624
  this.x - vec.x,
581
- this.y - vec.y
625
+ this.y - vec.y,
626
+ this.z - vec.z
582
627
  );
583
628
  }
584
629
  multiply(scalar) {
585
- return new _Vec2(
630
+ return new _Vec3(
586
631
  this.x * scalar,
587
- this.y * scalar
632
+ this.y * scalar,
633
+ this.z * scalar
588
634
  );
589
635
  }
590
636
  naiveMultiply(...args) {
591
- const vec = _Vec2.resolveArgs(args);
592
- return new _Vec2(
637
+ const vec = _Vec3.resolveArgs(args);
638
+ return new _Vec3(
593
639
  this.x * vec.x,
594
- this.y * vec.y
640
+ this.y * vec.y,
641
+ this.z * vec.z
595
642
  );
596
643
  }
597
644
  divide(...args) {
598
- if (check_number_array(args, 1))
599
- return new _Vec2(
645
+ if ((0, import_types4.isFixedTypeArray)(args, import_types4.isValidNumber, 1))
646
+ return new _Vec3(
600
647
  this.x / args[0],
601
- this.y / args[0]
648
+ this.y / args[0],
649
+ this.z / args[0]
602
650
  );
603
- const vec = _Vec2.resolveArgs(args);
604
- return new _Vec2(
651
+ const vec = _Vec3.resolveArgs(args);
652
+ return new _Vec3(
605
653
  this.x / vec.x,
606
- this.y / vec.y
654
+ this.y / vec.y,
655
+ this.z / vec.z
607
656
  );
608
657
  }
609
658
  dot(...args) {
610
- const vec = _Vec2.resolveArgs(args);
611
- return this.x * vec.x + this.y * vec.y;
659
+ const vec = _Vec3.resolveArgs(args);
660
+ return this.x * vec.x + this.y * vec.y + this.z * vec.z;
661
+ }
662
+ cross(...args) {
663
+ const vec = _Vec3.resolveArgs(args);
664
+ return new _Vec3(
665
+ this.y * vec.z - this.z * vec.y,
666
+ this.z * vec.x - this.x * vec.z,
667
+ this.x * vec.y - this.y * vec.x
668
+ );
612
669
  }
613
670
  distance(...args) {
614
- const vec = _Vec2.resolveArgs(args);
615
- return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2);
671
+ const vec = _Vec3.resolveArgs(args);
672
+ return Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2);
616
673
  }
617
674
  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));
675
+ const vec = _Vec3.resolveArgs(args);
676
+ return Math.sqrt(Math.pow(vec.x - this.x, 2) + Math.pow(vec.y - this.y, 2) + Math.pow(vec.z - this.z, 2));
620
677
  }
621
678
  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
- );
679
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
635
680
  }
636
681
  normalize() {
637
682
  const length = this.length();
638
- if (length == 0) return new _Vec2();
639
- return new _Vec2(
683
+ if (length == 0) return _Vec3.zero;
684
+ return new _Vec3(
640
685
  this.x / length,
641
- this.y / length
686
+ this.y / length,
687
+ this.z / length,
688
+ this.w / length
642
689
  );
643
690
  }
644
691
  invert() {
645
692
  return this.multiply(-1);
646
693
  }
647
694
  round() {
648
- return new _Vec2(Math.round(this.x), Math.round(this.y), Math.round(this.w));
695
+ return new _Vec3(Math.round(this.x), Math.round(this.y), Math.round(this.z), Math.round(this.w));
649
696
  }
650
697
  };
651
698
 
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);
674
- }
675
- /**
676
- * Create a linear function with a factor and height
677
- * @param m The factor
678
- * @param b The height
679
- */
680
- constructor(m, b) {
681
- super();
682
- if (!check_number(m))
683
- throw new TypeError("expected number for m");
684
- if (!check_number(b))
685
- throw new TypeError("expected number for b");
686
- this.m = m;
687
- this.b = b;
699
+ // source/algebra/quaternion.ts
700
+ var Quaternion = class _Quaternion {
701
+ w;
702
+ x;
703
+ y;
704
+ z;
705
+ static is(a) {
706
+ return typeof this.cast(a) != "undefined";
688
707
  }
689
- get(x) {
690
- if (!check_number(x))
691
- throw new TypeError("expected number for x");
692
- return this.m;
708
+ static resolve(a) {
709
+ const value = this.cast(a);
710
+ if (typeof value != "undefined")
711
+ return value;
712
+ throw new ResolveError("Quaternion", a);
693
713
  }
694
- roots() {
695
- const x = -this.b / this.m;
696
- if (!isNaN(x))
697
- return [new Vec2(x)];
698
- return [];
714
+ static resolveArgs(args) {
715
+ if ((0, import_types5.isFixedTypeArray)(args, import_types5.isValidNumber, 4))
716
+ return new this(args[0], args[1], args[2], args[3]);
717
+ return this.resolve(args[0]);
699
718
  }
700
- toString() {
701
- const bsign = sign_char(this.b);
702
- if (bsign)
703
- return `f(x) = ${this.m} * x ${bsign} ${Math.abs(this.b)}`;
704
- return `f(x) = ${this.m} * x`;
719
+ static cast(a) {
720
+ if (a == null || typeof a == "undefined")
721
+ return void 0;
722
+ if ((0, import_types5.isFixedTypeArray)(a, import_types5.isValidNumber, 4))
723
+ return new this(a[0], a[1], a[2], a[3]);
724
+ if ((0, import_types5.hasObjectProperty)(a, "toQuaternion", "function"))
725
+ return this.cast(a.toQuaternion());
726
+ if ((0, import_types5.hasObjectProperty)(a, "w", "number") && (0, import_types5.hasObjectProperty)(a, "x", "number") && (0, import_types5.hasObjectProperty)(a, "y", "number") && (0, import_types5.hasObjectProperty)(a, "z", "number"))
727
+ return new this(a.w, a.x, a.y, a.z);
728
+ if ((0, import_types5.isValidString)(a)) {
729
+ const parts = a.replaceAll(" ", "").split("+");
730
+ if ((0, import_types5.isFixedTypeArray)(parts, import_types5.isValidString, 4)) {
731
+ const [sw, sxi, syj, szk] = parts;
732
+ if (sxi.endsWith("i") && syj.endsWith("j") && szk.endsWith("k"))
733
+ return this.cast([
734
+ parseFloat(sw),
735
+ parseFloat(sxi.substring(0, sxi.length - 1)),
736
+ parseFloat(syj.substring(0, syj.length - 1)),
737
+ parseFloat(szk.substring(0, szk.length - 1))
738
+ ]);
739
+ }
740
+ }
741
+ return void 0;
742
+ }
743
+ static fromAxisAngle(...args) {
744
+ const axis = (0, import_types5.isFixedTypeArray)(args, import_types5.isValidNumber, 4) ? new Vec3(args[0], args[1], args[2]) : Vec3.resolve(args[0]);
745
+ const angle = (0, import_types5.isFixedTypeArray)(args, import_types5.isValidNumber, 4) ? args[3] : args[1];
746
+ const vec = Vec3.resolve(axis);
747
+ const hangle = angle * 0.5;
748
+ const sin2 = Math.sin(hangle);
749
+ const cos2 = Math.cos(hangle);
750
+ const length = sin2 / Math.sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z);
751
+ return new this(cos2, vec.x * length, vec.y * length, vec.z * length);
752
+ }
753
+ static fromEuler(...args) {
754
+ const vec = Vec3.resolveArgs(args);
755
+ const x2 = vec.x * 0.5, y2 = vec.y * 0.5, z2 = vec.z * 0.5;
756
+ const cx = Math.cos(x2), cy = Math.cos(y2), cz = Math.cos(z2);
757
+ const sx = Math.sin(x2), sy = Math.sin(y2), sz = Math.sin(z2);
758
+ return new _Quaternion(
759
+ cx * cy * cz - sx * sy * sz,
760
+ sx * cy * cz - sy * sz * cx,
761
+ sy * cx * cz - sx * sz * cy,
762
+ sx * sy * cz + sz * cx * cy
763
+ );
764
+ }
765
+ static get zero() {
766
+ return new _Quaternion(0, 0, 0, 0);
767
+ }
768
+ constructor(w, x, y, z) {
769
+ (0, import_types5.checkValidNumber)(w);
770
+ (0, import_types5.checkValidNumber)(x);
771
+ (0, import_types5.checkValidNumber)(y);
772
+ (0, import_types5.checkValidNumber)(z);
773
+ this.w = w;
774
+ this.x = x;
775
+ this.y = y;
776
+ this.z = z;
777
+ }
778
+ toArray() {
779
+ return [this.w, this.x, this.y, this.z];
780
+ }
781
+ toString() {
782
+ return `${this.w} + ${this.x}i + ${this.y}j + ${this.z}k`;
783
+ }
784
+ get [Symbol.toStringTag]() {
785
+ return "Quaternion";
786
+ }
787
+ [import_types5.NodeJSCustomInspect]() {
788
+ return `Quaternion <${this.toString()}>`;
789
+ }
790
+ toJSON() {
791
+ return {
792
+ w: this.w,
793
+ x: this.x,
794
+ y: this.y,
795
+ z: this.z
796
+ };
797
+ }
798
+ clone() {
799
+ return new _Quaternion(this.w, this.x, this.y, this.z);
800
+ }
801
+ add(...args) {
802
+ const quat = _Quaternion.resolveArgs(args);
803
+ return new _Quaternion(
804
+ this.w + quat.w,
805
+ this.x + quat.x,
806
+ this.y + quat.y,
807
+ this.z + quat.z
808
+ );
809
+ }
810
+ offset(...args) {
811
+ const quat = _Quaternion.resolveArgs(args);
812
+ this.w += quat.w;
813
+ this.x += quat.x;
814
+ this.y += quat.y;
815
+ this.z += quat.z;
816
+ return this;
817
+ }
818
+ subtract(...args) {
819
+ const quat = _Quaternion.resolveArgs(args);
820
+ return new _Quaternion(
821
+ this.w - quat.w,
822
+ this.x - quat.x,
823
+ this.y - quat.y,
824
+ this.z - quat.z
825
+ );
826
+ }
827
+ negative() {
828
+ return new _Quaternion(-this.w, -this.x, -this.y, -this.z);
829
+ }
830
+ length(sqrt = true) {
831
+ const value = this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z;
832
+ return sqrt ? Math.sqrt(value) : value;
833
+ }
834
+ normalize() {
835
+ let length = this.length();
836
+ if (length < EPSILON)
837
+ return _Quaternion.zero;
838
+ length = 1 / length;
839
+ return new _Quaternion(this.w * length, this.x * length, this.y * length, this.z * length);
840
+ }
841
+ multiply(...args) {
842
+ const quat = _Quaternion.resolveArgs(args);
843
+ return new _Quaternion(
844
+ this.w * quat.w - this.x * quat.x - this.y * quat.y - this.z * quat.z,
845
+ this.w * quat.x + this.x * quat.w + this.y * quat.z - this.z * quat.y,
846
+ this.w * quat.y + this.y * quat.w + this.z * quat.x - this.x * quat.z,
847
+ this.w * quat.z + this.z * quat.w + this.x * quat.y - this.y * quat.x
848
+ );
849
+ }
850
+ multiplyVector(...args) {
851
+ const vec = Vec3.resolveArgs(args);
852
+ const ix = this.w * vec.x + this.y * vec.y - this.z * vec.y;
853
+ const iy = this.w * vec.y + this.z * vec.x - this.x * vec.z;
854
+ const iz = this.w * vec.z + this.x * vec.y - this.y * vec.x;
855
+ const iw = -this.w * vec.x - this.y * vec.y - this.z * vec.z;
856
+ return new Vec3(
857
+ ix * this.w + iw * -this.x + iy * -this.z - iz * -this.y,
858
+ iy * this.w + iw * -this.y + iz * -this.x - ix * -this.z,
859
+ iz * this.w + iw * -this.z + ix * -this.y - iy * -this.x
860
+ );
861
+ }
862
+ scale(scalar) {
863
+ return new _Quaternion(this.w * scalar, this.x * scalar, this.y * scalar, this.z * scalar);
864
+ }
865
+ dot(...args) {
866
+ const quat = _Quaternion.resolveArgs(args);
867
+ return this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z;
868
+ }
869
+ inverse() {
870
+ let length = this.length(false);
871
+ if (length == 0)
872
+ return _Quaternion.zero;
873
+ length = 1 / length;
874
+ return new _Quaternion(this.w * length, -this.x * length, -this.y * length, -this.z * length);
875
+ }
876
+ divide(...args) {
877
+ const quat = _Quaternion.resolveArgs(args);
878
+ let length = quat.length(false);
879
+ if (length == 0) return _Quaternion.zero;
880
+ length = 1 / length;
881
+ return new _Quaternion(
882
+ (this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z) * length,
883
+ (this.x * quat.w - this.w * quat.x - this.y * quat.z + this.z * quat.y) * length,
884
+ (this.y * quat.w - this.w * quat.y - this.z * quat.x + this.x * quat.z) * length,
885
+ (this.z * quat.w - this.w * quat.z - this.x * quat.y + this.y * quat.x) * length
886
+ );
887
+ }
888
+ conjugate() {
889
+ return new _Quaternion(this.w, -this.x, -this.y, -this.z);
890
+ }
891
+ exp() {
892
+ const length = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
893
+ const exp = Math.exp(this.w);
894
+ const scale = exp * Math.sin(length) / length;
895
+ if (length == 0)
896
+ return new _Quaternion(exp, 0, 0, 0);
897
+ return new _Quaternion(
898
+ exp * Math.cos(length),
899
+ this.x * scale,
900
+ this.y * scale,
901
+ this.z * scale
902
+ );
903
+ }
904
+ log() {
905
+ if (this.x == 0 && this.z == 0)
906
+ return new _Quaternion(logHypot(this.w, this.x), Math.atan2(this.x, this.w), 0, 0);
907
+ const length = this.length(false);
908
+ const length2 = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
909
+ const scale = Math.atan2(length2, this.w) / length;
910
+ return new _Quaternion(Math.log(length) * 0.5, this.x * scale, this.y * scale, this.z * scale);
911
+ }
912
+ toVec3() {
913
+ return [this.x, this.y, this.z, this.w];
914
+ }
915
+ toAxisAngle() {
916
+ const sin2 = 1 - this.w * this.w;
917
+ if (sin2 > EPSILON)
918
+ return new Vec3(this.x, this.y, this.z, 0);
919
+ const isin = 1 / Math.sqrt(sin2);
920
+ const angle = 2 * Math.acos(this.w);
921
+ return new Vec3(this.x * isin, this.y * isin, this.z * isin, angle);
922
+ }
923
+ toEuler() {
924
+ function __asin__(t) {
925
+ return t >= 1 ? Math.PI / 2 : t <= -1 ? -Math.PI / 2 : Math.asin(t);
926
+ }
927
+ return new Vec3(
928
+ -Math.atan2(2 * (this.y * this.z - this.w * this.x), 1 - 2 * (this.x * this.x + this.y * this.y)),
929
+ __asin__(2 * (this.x * this.z + this.w * this.y)),
930
+ -Math.atan2(2 * (this.x * this.y - this.w * this.z), 1 - 2 * (this.y * this.y + this.z * this.z))
931
+ );
932
+ }
933
+ toMat3() {
934
+ return [
935
+ 1 - 2 * (this.y * this.y + this.z * this.z),
936
+ 2 * (this.x * this.y - this.w * this.z),
937
+ 2 * (this.x * this.z + this.w * this.y),
938
+ 2 * (this.x * this.y + this.w * this.z),
939
+ 1 - 2 * (this.x * this.x + this.z * this.z),
940
+ 2 * (this.y * this.z - this.w * this.x),
941
+ 2 * (this.x * this.z - this.w * this.y),
942
+ 2 * (this.y * this.z + this.w * this.x),
943
+ 1 - 2 * (this.x * this.x + this.y * this.y)
944
+ ];
945
+ }
946
+ toMat4() {
947
+ return [
948
+ 1 - 2 * (this.y * this.y + this.z * this.z),
949
+ 2 * (this.x * this.y - this.w * this.z),
950
+ 2 * (this.x * this.z + this.w * this.y),
951
+ 0,
952
+ 2 * (this.x * this.y + this.w * this.z),
953
+ 1 - 2 * (this.x * this.x + this.z * this.z),
954
+ 2 * (this.y * this.z - this.w * this.x),
955
+ 0,
956
+ 2 * (this.x * this.z - this.w * this.y),
957
+ 2 * (this.y * this.z + this.w * this.x),
958
+ 1 - 2 * (this.x * this.x + this.y * this.y),
959
+ 0,
960
+ 0,
961
+ 0,
962
+ 0,
963
+ 1
964
+ ];
705
965
  }
706
966
  };
707
967
 
708
- // source/algebra/quad.ts
709
- var QuadFunction = class extends MathFunction {
710
- a;
711
- b;
712
- c;
713
- static get(a, b, c, x) {
714
- return new this(a, b, c).get(x);
968
+ // source/color/hsl.ts
969
+ var import_types7 = require("@ntf/types");
970
+
971
+ // source/color/rgb.ts
972
+ var import_types6 = require("@ntf/types");
973
+
974
+ // source/color/utils.ts
975
+ function numberToRGB(number) {
976
+ const blue = number & 255;
977
+ const green = (number & 65280) >>> 8;
978
+ const red = (number & 16711680) >>> 16;
979
+ return [red / 255, green / 255, blue / 255];
980
+ }
981
+ function numberToRGBA(number) {
982
+ const alpha = number & 255;
983
+ const blue = (number & 65280) >>> 8;
984
+ const green = (number & 16711680) >>> 16;
985
+ const red = (number & 4278190080) >>> 24;
986
+ return [red / 255, green / 255, blue / 255, alpha / 255];
987
+ }
988
+
989
+ // source/color/rgb.ts
990
+ var RGBA = class _RGBA {
991
+ _red;
992
+ get red() {
993
+ return this._red;
715
994
  }
716
- constructor(a, b, c) {
717
- super();
718
- if (!check_number(a))
719
- throw new TypeError("expected number for a");
720
- if (a == 0)
721
- throw new TypeError("a cannot be 0");
722
- if (!check_number(b))
723
- throw new TypeError("expected number for b");
724
- if (!check_number(c))
725
- throw new TypeError("expected number for c");
726
- this.a = a;
727
- this.b = b;
728
- this.c = c;
995
+ set red(val) {
996
+ this._red = clamp(val, 0, 1);
729
997
  }
730
- get(x) {
731
- if (!check_number(x))
732
- throw new TypeError("expected number for x");
733
- return this.a * x * x + this.b * x + this.c;
998
+ _green;
999
+ get green() {
1000
+ return this._green;
734
1001
  }
735
- roots() {
736
- const roots = new Array();
737
- const discriminant = this.b * this.b - 4 * this.a * this.c;
738
- const n0 = (-this.b + Math.sqrt(discriminant)) / (2 * this.a);
739
- const n1 = (-this.b + Math.sqrt(discriminant)) / (2 * this.a);
740
- if (!isNaN(n0))
741
- roots.push(new Vec2(n0));
742
- if (!isNaN(n1) && n0 != n1)
743
- roots.push(new Vec2(n1));
744
- return roots;
1002
+ set green(val) {
1003
+ this._green = clamp(val, 0, 1);
745
1004
  }
746
- toString(type = "standard") {
747
- switch (type) {
748
- default:
749
- case "standard": {
750
- const bsign = sign_char(this.b);
751
- const csign = sign_char(this.c);
752
- if (bsign && csign)
753
- return `f(x) = ${this.a}x^2 ${bsign} ${Math.abs(this.b)}x ${csign} ${Math.abs(this.c)}`;
754
- if (bsign)
755
- return `f(x) = ${this.a}x^2 ${bsign} ${Math.abs(this.b)}x`;
756
- return `f(x) = ${this.a}x^2`;
1005
+ _blue;
1006
+ get blue() {
1007
+ return this._blue;
1008
+ }
1009
+ set blue(val) {
1010
+ this._blue = clamp(val, 0, 1);
1011
+ }
1012
+ _alpha;
1013
+ get alpha() {
1014
+ return this._alpha;
1015
+ }
1016
+ set alpha(val) {
1017
+ this._alpha = clamp(val, 0, 1);
1018
+ }
1019
+ static resolve(a) {
1020
+ const value = this.cast(a);
1021
+ if (typeof value != "undefined")
1022
+ return value;
1023
+ throw new ResolveError("RGBAColor", a);
1024
+ }
1025
+ static resolveArgs(args) {
1026
+ if ((0, import_types6.isFixedTypeArray)(args, import_types6.isValidNumber, 3) || (0, import_types6.isFixedTypeArray)(args, import_types6.isValidNumber, 4))
1027
+ return new this(args[0], args[1], args[2], args[3]);
1028
+ return this.resolve(args[0]);
1029
+ }
1030
+ static cast(a) {
1031
+ if (a == null || typeof a == "undefined")
1032
+ return void 0;
1033
+ if ((0, import_types6.isFixedTypeArray)(a, import_types6.isValidNumber, 3) || (0, import_types6.isFixedTypeArray)(a, import_types6.isValidNumber, 4))
1034
+ return new this(a[0], a[1], a[2], a[3]);
1035
+ if ((0, import_types6.hasObjectProperty)(a, "toRGB", "function"))
1036
+ return this.cast(a.toRGB());
1037
+ if ((0, import_types6.hasObjectProperty)(a, "toRGBA", "function"))
1038
+ return this.cast(a.toRGBA());
1039
+ if ((0, import_types6.hasObjectProperty)(a, "red", "number") && (0, import_types6.hasObjectProperty)(a, "green", "number") && (0, import_types6.hasObjectProperty)(a, "blue", "number"))
1040
+ return new this(a.red, a.green, a.blue, (0, import_types6.hasObjectProperty)(a, "alpha", "number") ? a.alpha : void 0);
1041
+ if ((0, import_types6.isValidNumber)(a)) {
1042
+ const hex = a.toString(16);
1043
+ const convert = hex.length <= 6 ? numberToRGB : numberToRGBA;
1044
+ return this.cast(convert(a));
1045
+ }
1046
+ if ((0, import_types6.isValidString)(a)) {
1047
+ if (a.startsWith("rgb")) {
1048
+ const hasAlpha = a.startsWith("rgba");
1049
+ const offset = hasAlpha ? 5 : 4;
1050
+ const parts = a.substring(offset, a.indexOf(")", offset)).split(",");
1051
+ if ((0, import_types6.isFixedTypeArray)(parts, import_types6.isValidString, hasAlpha ? 4 : 3))
1052
+ return this.cast(parts.map((v) => parseInt(v) / 255));
1053
+ }
1054
+ }
1055
+ return void 0;
1056
+ }
1057
+ static is(a) {
1058
+ return typeof this.cast(a) != "undefined";
1059
+ }
1060
+ constructor(red, green, blue, alpha = 1) {
1061
+ (0, import_types6.checkValidNumber)(red);
1062
+ (0, import_types6.checkValidNumber)(green);
1063
+ (0, import_types6.checkValidNumber)(blue);
1064
+ (0, import_types6.checkValidNumber)(alpha);
1065
+ this._red = clamp(red, 0, 1);
1066
+ this._green = clamp(green, 0, 1);
1067
+ this._blue = clamp(blue, 0, 1);
1068
+ this._alpha = clamp(alpha, 0, 1);
1069
+ }
1070
+ toArray(withAlpha = this._alpha !== 1) {
1071
+ return withAlpha ? [this.red, this.green, this.blue, this.alpha] : [this.red, this.green, this.blue];
1072
+ }
1073
+ toJSON(withAlpha = this._alpha !== 1) {
1074
+ return withAlpha ? {
1075
+ red: this.red,
1076
+ green: this.green,
1077
+ blue: this.blue,
1078
+ alpha: this.alpha
1079
+ } : {
1080
+ red: this.red,
1081
+ green: this.green,
1082
+ blue: this.blue
1083
+ };
1084
+ }
1085
+ toString(withAlpha = this._alpha !== 1) {
1086
+ return withAlpha ? `rgba(${clamp(this.red * 255 | 0, 0, 255)},${clamp(this.green * 255 | 0, 0, 255)},${clamp(this.blue * 255 | 0, 0, 255)},${this.alpha})` : `rgb(${clamp(this.red * 255 | 0, 0, 255)},${clamp(this.green * 255 | 0, 0, 255)},${clamp(this.blue * 255 | 0, 0, 255)})`;
1087
+ }
1088
+ get [Symbol.toStringTag]() {
1089
+ return "RGBA";
1090
+ }
1091
+ [import_types6.NodeJSCustomInspect]() {
1092
+ return `RGBA <${this.toString()}>`;
1093
+ }
1094
+ toVec2() {
1095
+ return [this.red, this.green, this.blue];
1096
+ }
1097
+ toVec3() {
1098
+ return [this.red, this.green, this.blue, this.alpha];
1099
+ }
1100
+ toHSL(withAlpha = this._alpha !== 1) {
1101
+ const red = this.red, green = this.green, blue = this.blue;
1102
+ const min = Math.min(red, green, blue), max = Math.max(red, green, blue);
1103
+ const luminace = (min + max) / 2;
1104
+ if (min == max)
1105
+ return new HSLA(0, 0, luminace, withAlpha ? this.alpha : void 0);
1106
+ const d = max - min;
1107
+ const saturation = luminace > 0.5 ? d / (2 - max - min) : d / (max + min);
1108
+ if (max == red)
1109
+ return new HSLA(((green - blue) / d + (green < blue ? 6 : 0)) / 6, saturation, luminace, withAlpha ? this.alpha : void 0);
1110
+ if (max == green)
1111
+ return new HSLA(((blue - red) / d + 2) / 6, saturation, luminace, withAlpha ? this.alpha : void 0);
1112
+ if (max == blue)
1113
+ return new HSLA(((red - green) / d + 4) / 6, saturation, luminace, withAlpha ? this.alpha : void 0);
1114
+ return new HSLA(0, saturation, luminace, withAlpha ? this.alpha : void 0);
1115
+ }
1116
+ toHSLA() {
1117
+ return this.toHSL(true);
1118
+ }
1119
+ invert(withAlpha = this._alpha !== 1) {
1120
+ return new _RGBA(
1121
+ 1 - this.red,
1122
+ 1 - this.green,
1123
+ 1 - this.blue,
1124
+ withAlpha ? 1 - this.alpha : this.alpha
1125
+ );
1126
+ }
1127
+ };
1128
+
1129
+ // source/color/hsl.ts
1130
+ var HSLA = class _HSLA {
1131
+ _hue;
1132
+ get hue() {
1133
+ return this._hue;
1134
+ }
1135
+ set hue(val) {
1136
+ this._hue = clamp(val, 0, 1);
1137
+ }
1138
+ _saturation;
1139
+ get saturation() {
1140
+ return this._saturation;
1141
+ }
1142
+ set saturation(val) {
1143
+ this._saturation = clamp(val, 0, 1);
1144
+ }
1145
+ _luminace;
1146
+ get luminace() {
1147
+ return this._luminace;
1148
+ }
1149
+ set luminace(val) {
1150
+ this._luminace = clamp(val, 0, 1);
1151
+ }
1152
+ _alpha;
1153
+ get alpha() {
1154
+ return this._alpha;
1155
+ }
1156
+ set alpha(val) {
1157
+ this._alpha = clamp(val, 0, 1);
1158
+ }
1159
+ static resolve(a) {
1160
+ const value = this.cast(a);
1161
+ if (typeof value != "undefined")
1162
+ return value;
1163
+ throw new ResolveError("HSLColor", a);
1164
+ }
1165
+ static resolveArgs(args) {
1166
+ if ((0, import_types7.isFixedTypeArray)(args, import_types7.isValidNumber, 3) || (0, import_types7.isFixedTypeArray)(args, import_types7.isValidNumber, 4))
1167
+ return new this(args[0], args[1], args[2], args[3]);
1168
+ return this.resolve(args[0]);
1169
+ }
1170
+ static cast(a) {
1171
+ if (a == null || typeof a == "undefined")
1172
+ return void 0;
1173
+ if ((0, import_types7.isFixedTypeArray)(a, import_types7.isValidNumber, 3) || (0, import_types7.isFixedTypeArray)(a, import_types7.isValidNumber, 4))
1174
+ return new this(a[0], a[1], a[2], a[3]);
1175
+ if ((0, import_types7.hasObjectProperty)(a, "toHSL", "function"))
1176
+ return this.cast(a.toHSL());
1177
+ if ((0, import_types7.hasObjectProperty)(a, "toHSLA", "function"))
1178
+ return this.cast(a.toHSLA());
1179
+ if ((0, import_types7.hasObjectProperty)(a, "hue", "number") && (0, import_types7.hasObjectProperty)(a, "saturation", "number") && (0, import_types7.hasObjectProperty)(a, "luminace", "number"))
1180
+ return new this(a.hue, a.saturation, a.luminace, (0, import_types7.hasObjectProperty)(a, "alpha", "number") ? a.alpha : void 0);
1181
+ if ((0, import_types7.isValidNumber)(a)) {
1182
+ const hex = a.toString(16);
1183
+ const convert = hex.length <= 6 ? numberToRGB : numberToRGBA;
1184
+ return this.cast(convert(a));
1185
+ }
1186
+ if ((0, import_types7.isValidString)(a)) {
1187
+ if (a.startsWith("hsl")) {
1188
+ const hasAlpha = a.startsWith("hsla");
1189
+ const offset = hasAlpha ? 5 : 4;
1190
+ const parts = a.substring(offset, a.indexOf(")", offset)).split(",");
1191
+ if ((0, import_types7.isFixedTypeArray)(parts, import_types7.isValidString, hasAlpha ? 4 : 3))
1192
+ return this.cast(parts.map((v) => parseInt(v) / 255));
757
1193
  }
758
1194
  }
1195
+ return void 0;
1196
+ }
1197
+ static is(a) {
1198
+ return typeof this.cast(a) != "undefined";
1199
+ }
1200
+ constructor(hue, saturation, luminace, alpha = 1) {
1201
+ (0, import_types7.checkValidNumber)(hue);
1202
+ (0, import_types7.checkValidNumber)(saturation);
1203
+ (0, import_types7.checkValidNumber)(luminace);
1204
+ (0, import_types7.checkValidNumber)(alpha);
1205
+ this._hue = clamp(hue, 0, 1);
1206
+ this._saturation = clamp(saturation, 0, 1);
1207
+ this._luminace = clamp(luminace, 0, 1);
1208
+ this._alpha = clamp(alpha, 0, 1);
1209
+ }
1210
+ toArray(withAlpha = this._alpha !== 1) {
1211
+ return withAlpha ? [this.hue, this.saturation, this.luminace, this.alpha] : [this.hue, this.saturation, this.luminace];
1212
+ }
1213
+ toJSON(withAlpha = this._alpha !== 1) {
1214
+ return withAlpha ? {
1215
+ hue: this.hue,
1216
+ saturation: this.saturation,
1217
+ luminace: this.luminace,
1218
+ alpha: this.alpha
1219
+ } : {
1220
+ hue: this.hue,
1221
+ saturation: this.saturation,
1222
+ luminace: this.luminace
1223
+ };
1224
+ }
1225
+ toString(withAlpha = this._alpha !== 1) {
1226
+ return withAlpha ? `hsla(${clamp(this.hue * 255 | 0, 0, 255)},${clamp(this.saturation * 255 | 0, 0, 255)},${clamp(this.luminace * 255 | 0, 0, 255)},${this.alpha})` : `hsl(${clamp(this.hue * 255 | 0, 0, 255)},${clamp(this.saturation * 255 | 0, 0, 255)},${clamp(this.luminace * 255 | 0, 0, 255)})`;
1227
+ }
1228
+ get [Symbol.toStringTag]() {
1229
+ return "HSLA";
1230
+ }
1231
+ [import_types7.NodeJSCustomInspect]() {
1232
+ return `HSLA <${this.toString()}>`;
1233
+ }
1234
+ toRGB(withAlpha = this._alpha !== 1) {
1235
+ if (this.saturation == 0)
1236
+ return new RGBA(this.luminace * 255, this.luminace * 255, this.luminace * 255, withAlpha ? this.alpha : void 0);
1237
+ const q = this.luminace < 0.5 ? this.luminace * (1 + this.saturation) : this.luminace + this.saturation - this.luminace * this.saturation;
1238
+ const p = 2 * this.luminace - q;
1239
+ function __hue_2_rgb__(t) {
1240
+ let _t = t;
1241
+ if (_t < 0)
1242
+ _t++;
1243
+ if (_t > 1)
1244
+ _t--;
1245
+ if (_t < 1 / 6)
1246
+ return p + (q - p) * 6 * _t;
1247
+ if (_t < 1 / 2)
1248
+ return q;
1249
+ if (_t < 2 / 3)
1250
+ return p + (q - p) * (2 / 3 - _t) * 6;
1251
+ return p;
1252
+ }
1253
+ 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);
1254
+ }
1255
+ toRGBA() {
1256
+ return this.toRGB(true);
1257
+ }
1258
+ toVec2() {
1259
+ return [this.hue, this.saturation, this.luminace];
1260
+ }
1261
+ toVec3() {
1262
+ return [this.hue, this.saturation, this.luminace, this.alpha];
1263
+ }
1264
+ invert(withAlpha = this._alpha !== 1) {
1265
+ return new _HSLA(
1266
+ 1 - this.hue,
1267
+ 1 - this.saturation,
1268
+ 1 - this.luminace,
1269
+ withAlpha ? 1 - this.alpha : this.alpha
1270
+ );
759
1271
  }
760
1272
  };
761
1273
 
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
1274
  // source/crypto/hash.ts
768
1275
  var DJB2_OFFSET = 5381n;
769
1276
  function djb2(value) {
770
- const string = stringify(value);
1277
+ const string = String(value);
771
1278
  let hash = DJB2_OFFSET;
772
1279
  for (let i = 0; i < string.length; i++) {
773
1280
  hash = (hash << 5n) + hash + BigInt(string.charCodeAt(i));
@@ -777,7 +1284,7 @@ function djb2(value) {
777
1284
  var FNV1_OFFSET = 14695981039346656037n;
778
1285
  var FNV1_PRIME = 1099511628211n;
779
1286
  function fnv1(value) {
780
- const string = stringify(value);
1287
+ const string = String(value);
781
1288
  let hash = FNV1_OFFSET;
782
1289
  for (let i = 0; i < string.length; i++) {
783
1290
  hash *= FNV1_PRIME;
@@ -786,7 +1293,7 @@ function fnv1(value) {
786
1293
  return hash;
787
1294
  }
788
1295
  function sdbm(value) {
789
- const string = stringify(value);
1296
+ const string = String(value);
790
1297
  let hash = 0n;
791
1298
  for (let i = 0; i < string.length; i++) {
792
1299
  hash = BigInt(string.charCodeAt(i)) + (hash << 6n) + (hash << 16n) - hash;
@@ -795,6 +1302,7 @@ function sdbm(value) {
795
1302
  }
796
1303
 
797
1304
  // source/crypto/md2.ts
1305
+ var import_types8 = require("@ntf/types");
798
1306
  var STABLE = [
799
1307
  41,
800
1308
  46,
@@ -1103,16 +1611,29 @@ var MD2 = class _MD2 {
1103
1611
  this._transform(this._checksum);
1104
1612
  return this._state.slice();
1105
1613
  }
1614
+ toString() {
1615
+ return "";
1616
+ }
1617
+ get [Symbol.toStringTag]() {
1618
+ return "MD2";
1619
+ }
1620
+ [import_types8.NodeJSCustomInspect]() {
1621
+ return `MD2 <${this.toString()}>`;
1622
+ }
1106
1623
  };
1107
1624
 
1108
1625
  // source/geometry/angle.ts
1109
1626
  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);
1627
+ var clampAngleDegree = (angle) => angle % MAX_ANGLE_DEGREE;
1628
+ var clampAngleRadian = (angle) => clampAngleDegree(degreeToRadian(angle));
1629
+ var radianToDegree = (angle) => angle * (180 / Math.PI);
1630
+ var degreeToRadian = (angle) => angle * (Math.PI / 180);
1631
+
1632
+ // source/geometry/bbox.ts
1633
+ var import_types10 = require("@ntf/types");
1114
1634
 
1115
1635
  // source/geometry/circle.ts
1636
+ var import_types9 = require("@ntf/types");
1116
1637
  var Circle = class _Circle {
1117
1638
  radius;
1118
1639
  get perimeter() {
@@ -1146,19 +1667,28 @@ var Circle = class _Circle {
1146
1667
  return value;
1147
1668
  throw new ResolveError("Circle", a);
1148
1669
  }
1670
+ static resolveArgs(args) {
1671
+ if ((0, import_types9.isFixedTypeArray)(args, import_types9.isValidNumber, 3))
1672
+ return new this([args[0], args[1]], args[2]);
1673
+ if (args.length === 2)
1674
+ return new this(args[0], args[1]);
1675
+ return this.resolve(args[0]);
1676
+ }
1149
1677
  static cast(a) {
1150
1678
  if (a == null || typeof a == "undefined")
1151
1679
  return void 0;
1152
- if (check_number_array(a, 3))
1680
+ if ((0, import_types9.isFixedTypeArray)(a, import_types9.isValidNumber, 3))
1153
1681
  return new this([a[0], a[1]], a[2]);
1154
- if (check_number_array(a, 4)) {
1682
+ if ((0, import_types9.isFixedTypeArray)(a, import_types9.isValidNumber, 4)) {
1155
1683
  const c = new this([a[0], a[1]], a[3]);
1156
1684
  c.w = a[2];
1157
1685
  return c;
1158
1686
  }
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)) {
1687
+ if ((0, import_types9.hasObjectProperty)(a, "toCircle", "function"))
1688
+ return this.cast(a.toCircle());
1689
+ if ((0, import_types9.hasObjectProperty)(a, "x", "number") && (0, import_types9.hasObjectProperty)(a, "y", "number") && (0, import_types9.hasObjectProperty)(a, "radius", "number"))
1690
+ return new this((0, import_types9.hasObjectProperty)(a, "w", "number") ? [a.x, a.y, a.w] : [a.x, a.y], a.radius);
1691
+ if ((0, import_types9.isValidString)(a)) {
1162
1692
  const [spos, sradius] = a.split("|");
1163
1693
  const pos = Vec2.cast(spos);
1164
1694
  if (typeof pos == "undefined")
@@ -1173,9 +1703,8 @@ var Circle = class _Circle {
1173
1703
  return typeof this.cast(a) != "undefined";
1174
1704
  }
1175
1705
  constructor(position, radius) {
1706
+ (0, import_types9.checkValidNumber)(radius);
1176
1707
  this.position = Vec2.resolve(position);
1177
- if (!check_number(radius))
1178
- throw new TypeError("expected number for radius");
1179
1708
  this.radius = radius;
1180
1709
  }
1181
1710
  toArray() {
@@ -1190,232 +1719,371 @@ var Circle = class _Circle {
1190
1719
  toString() {
1191
1720
  return `${this.position.toString()}|${this.radius}`;
1192
1721
  }
1722
+ get [Symbol.toStringTag]() {
1723
+ return "Circle";
1724
+ }
1725
+ [import_types9.NodeJSCustomInspect]() {
1726
+ return `Circle <${this.toString()}>`;
1727
+ }
1193
1728
  clone() {
1194
1729
  return new _Circle(this.position.clone(), this.radius);
1195
1730
  }
1196
- equals(circle) {
1197
- const c = _Circle.resolve(circle);
1731
+ toVec2() {
1732
+ return [this.x, this.y, this.w];
1733
+ }
1734
+ equals(...args) {
1735
+ const c = _Circle.resolveArgs(args);
1198
1736
  return c.position.equals(c.position) && this.radius == c.radius;
1199
1737
  }
1200
- inside(a) {
1201
- const circle = _Circle.resolve(a);
1738
+ inside(...args) {
1739
+ const circle = _Circle.resolveArgs(args);
1202
1740
  const distX = circle.x - this.x;
1203
1741
  const distY = circle.y - this.y;
1204
1742
  const dist = Math.sqrt(distX * distX + (distY + distY));
1205
1743
  return dist <= this.radius + circle.radius;
1206
1744
  }
1207
- insidePoint(a) {
1208
- return this.position.distance(a) <= this.radius;
1745
+ insidePoint(...args) {
1746
+ return this.position.distance(Vec2.resolveArgs(args)) <= this.radius;
1209
1747
  }
1210
1748
  };
1211
1749
 
1212
- // source/geometry/rectangle.ts
1213
- var Rectangle = class _Rectangle {
1214
- position;
1215
- size;
1216
- get area() {
1217
- return this.width * this.height;
1750
+ // source/geometry/bbox.ts
1751
+ var BoundingBox = class _BoundingBox {
1752
+ left;
1753
+ right;
1754
+ top;
1755
+ bottom;
1756
+ get width() {
1757
+ return this.right - this.left;
1218
1758
  }
1219
- get perimeter() {
1220
- return this.width + this.width + this.height + this.height;
1759
+ set width(val) {
1760
+ this.right = this.left + val;
1761
+ }
1762
+ get height() {
1763
+ return this.bottom - this.top;
1764
+ }
1765
+ set height(val) {
1766
+ this.bottom = this.top + val;
1221
1767
  }
1222
1768
  get x() {
1223
- return this.position.x;
1769
+ return this.left;
1224
1770
  }
1225
- set x(val) {
1226
- this.position.x = val;
1771
+ set x(x) {
1772
+ this.left = x;
1227
1773
  }
1228
1774
  get y() {
1229
- return this.position.y;
1775
+ return this.top;
1230
1776
  }
1231
- set y(val) {
1232
- this.position.y = val;
1777
+ set y(y) {
1778
+ this.top = y;
1233
1779
  }
1234
- get w() {
1235
- return this.position.w;
1780
+ w = 1;
1781
+ static resolve(a) {
1782
+ const value = this.cast(a);
1783
+ if (typeof value != "undefined")
1784
+ return value;
1785
+ throw new ResolveError("BoundingBox", a);
1236
1786
  }
1237
- set w(val) {
1238
- this.position.w = val;
1787
+ static resolveArgs(args) {
1788
+ if ((0, import_types10.isFixedTypeArray)(args, import_types10.isValidNumber, 4))
1789
+ return new this(args[0], args[1], args[2], args[3]);
1790
+ return this.resolve(args[0]);
1239
1791
  }
1240
- get width() {
1241
- return this.size.width;
1792
+ static cast(a) {
1793
+ if (a == null || typeof a == "undefined")
1794
+ return void 0;
1795
+ if ((0, import_types10.isFixedTypeArray)(a, import_types10.isValidNumber, 4))
1796
+ return new this(a[0], a[1], a[2], a[3]);
1797
+ if ((0, import_types10.hasObjectProperty)(a, "toBoundingBox", "function"))
1798
+ return this.cast(a.toBoundingBox());
1799
+ if ((0, import_types10.hasObjectProperty)(a, "left", "number") && (0, import_types10.hasObjectProperty)(a, "right", "number") && (0, import_types10.hasObjectProperty)(a, "top", "number") && (0, import_types10.hasObjectProperty)(a, "bottom", "number"))
1800
+ return new this(a.left, a.right, a.top, a.bottom);
1801
+ if ((0, import_types10.isValidString)(a)) {
1802
+ const parts = a.split(",");
1803
+ if ((0, import_types10.isFixedTypeArray)(parts, import_types10.isValidString, 4))
1804
+ return this.cast(parts.map((v) => parseFloat(v)));
1805
+ }
1806
+ return void 0;
1242
1807
  }
1243
- set width(val) {
1244
- this.size.width = val;
1808
+ static is(a) {
1809
+ return typeof this.cast(a) != "undefined";
1245
1810
  }
1246
- get height() {
1247
- return this.size.height;
1811
+ constructor(left, right, top, bottom) {
1812
+ (0, import_types10.checkValidNumber)(left);
1813
+ (0, import_types10.checkValidNumber)(right);
1814
+ (0, import_types10.checkValidNumber)(top);
1815
+ (0, import_types10.checkValidNumber)(bottom);
1816
+ this.left = left;
1817
+ this.right = right;
1818
+ this.top = top;
1819
+ this.bottom = bottom;
1248
1820
  }
1249
- set height(val) {
1250
- this.size.height = val;
1821
+ toArray() {
1822
+ return [this.left, this.right, this.top, this.bottom];
1823
+ }
1824
+ toString() {
1825
+ return `${this.left},${this.right},${this.top},${this.bottom}`;
1826
+ }
1827
+ get [Symbol.toStringTag]() {
1828
+ return "BoundingBox";
1829
+ }
1830
+ [import_types10.NodeJSCustomInspect]() {
1831
+ return `BoundingBox <${this.toString()}>`;
1832
+ }
1833
+ toJSON() {
1834
+ return {
1835
+ left: this.left,
1836
+ top: this.top,
1837
+ right: this.right,
1838
+ bottom: this.bottom
1839
+ };
1840
+ }
1841
+ clone() {
1842
+ return new _BoundingBox(this.left, this.right, this.top, this.bottom);
1843
+ }
1844
+ equals(...args) {
1845
+ const b = _BoundingBox.resolveArgs(args);
1846
+ return this.left === b.left && this.right === b.right && this.top === b.top && this.bottom === b.bottom;
1847
+ }
1848
+ toSize() {
1849
+ return [this.width, this.height];
1850
+ }
1851
+ toVec2() {
1852
+ return [this.left, this.top];
1853
+ }
1854
+ toRectangle() {
1855
+ return [this.left, this.top, this.width, this.height];
1856
+ }
1857
+ inside(...args) {
1858
+ const bbox = _BoundingBox.resolve(args);
1859
+ return this.right >= bbox.left && bbox.right >= this.left && this.bottom >= bbox.top && bbox.bottom >= this.top;
1860
+ }
1861
+ insidePoint(...args) {
1862
+ const point = Vec2.resolveArgs(args);
1863
+ return this.left <= point.x && this.right >= point.x && this.top <= point.y && this.bottom >= point.y;
1864
+ }
1865
+ insideCircle(...args) {
1866
+ const circle = Circle.resolveArgs(args);
1867
+ const center = Vec2.resolve(circle).add(circle.radius);
1868
+ const bboxhe = new Vec2(this.width / 2, this.height / 2);
1869
+ const bboxcenter = new Vec2(this.left + bboxhe.x, this.top + bboxhe.y);
1870
+ let diff = center.subtract(bboxcenter);
1871
+ const clamped = Vec2.clamp(diff, bboxhe.invert(), bboxhe);
1872
+ const closest = bboxcenter.add(clamped);
1873
+ diff = closest.subtract(center);
1874
+ return diff.length() < circle.radius;
1875
+ }
1876
+ };
1877
+
1878
+ // source/geometry/rectangle.ts
1879
+ var import_types12 = require("@ntf/types");
1880
+
1881
+ // source/geometry/size.ts
1882
+ var import_types11 = require("@ntf/types");
1883
+ var Size = class _Size {
1884
+ width;
1885
+ height;
1886
+ get aspectRatio() {
1887
+ return this.height / this.width;
1888
+ }
1889
+ get area() {
1890
+ return this.width * this.height;
1891
+ }
1892
+ get perimeter() {
1893
+ return this.width + this.width + this.height + this.height;
1251
1894
  }
1252
1895
  static resolve(a) {
1253
1896
  const value = this.cast(a);
1254
1897
  if (typeof value != "undefined")
1255
1898
  return value;
1256
- throw new ResolveError("Rectangle", a);
1899
+ throw new ResolveError("Square", a);
1900
+ }
1901
+ static resolveArgs(args) {
1902
+ if ((0, import_types11.isFixedTypeArray)(args, import_types11.isValidNumber, 2))
1903
+ return new this(args[0], args[1]);
1904
+ return this.resolve(args[0]);
1257
1905
  }
1258
1906
  static cast(a) {
1259
1907
  if (a == null || typeof a == "undefined")
1260
1908
  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]]);
1265
- rect.w = a[2];
1266
- return rect;
1267
- }
1268
- if (check_string(a)) {
1269
- const [spos, ssize] = a.split("|");
1270
- const pos = Vec2.cast(spos);
1271
- const size = Size.cast(ssize);
1272
- if (typeof pos == "undefined" || typeof size == "undefined")
1273
- return void 0;
1274
- const rect = new this([pos.x, pos.y], [size.width, size.height]);
1275
- rect.w = pos.w;
1276
- return rect;
1277
- }
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"))
1281
- rect.w = a.w;
1282
- return rect;
1909
+ if ((0, import_types11.isFixedTypeArray)(a, import_types11.isValidNumber, 2))
1910
+ return new this(a[0], a[1]);
1911
+ if ((0, import_types11.hasObjectProperty)(a, "toSize", "function"))
1912
+ return this.cast(a.toSize());
1913
+ if ((0, import_types11.hasObjectProperty)(a, "width", "number") && (0, import_types11.hasObjectProperty)(a, "height", "number"))
1914
+ return new this(a.width, a.height);
1915
+ if ((0, import_types11.isValidString)(a)) {
1916
+ const parts = a.split("x").map((v) => parseFloat(v));
1917
+ if ((0, import_types11.isFixedTypeArray)(parts, import_types11.isValidNumber, 2))
1918
+ return this.cast(parts);
1283
1919
  }
1920
+ if ((0, import_types11.isValidNumber)(a))
1921
+ return new this(a, a);
1284
1922
  return void 0;
1285
1923
  }
1286
1924
  static is(a) {
1287
1925
  return typeof this.cast(a) != "undefined";
1288
1926
  }
1289
- constructor(pos, size) {
1290
- this.position = Vec2.resolve(pos);
1291
- this.size = Size.resolve(size);
1927
+ constructor(width, height) {
1928
+ (0, import_types11.checkValidNumber)(width);
1929
+ (0, import_types11.checkValidNumber)(height);
1930
+ this.width = width;
1931
+ this.height = height;
1292
1932
  }
1293
- toArray(w = false) {
1294
- return [...this.position.toArray(w), ...this.size.toArray()];
1933
+ toArray() {
1934
+ return [this.width, this.height];
1295
1935
  }
1296
- toString(w = false) {
1297
- return `${this.position.toString(w)}|${this.size.toString()}`;
1936
+ toString() {
1937
+ return `${this.width}x${this.height}`;
1298
1938
  }
1299
- toJSON() {
1300
- return { ...this.position.toJSON(), ...this.size.toJSON() };
1939
+ get [Symbol.toStringTag]() {
1940
+ return "Size";
1301
1941
  }
1302
- toBoundingBox() {
1303
- return [this.x, this.x + this.width, this.y, this.y + this.height];
1942
+ [import_types11.NodeJSCustomInspect]() {
1943
+ return `Size <${this.toString()}>`;
1944
+ }
1945
+ toJSON() {
1946
+ return {
1947
+ width: this.width,
1948
+ height: this.height
1949
+ };
1304
1950
  }
1305
1951
  clone() {
1306
- return new _Rectangle(this.position.clone(), this.size.clone());
1952
+ return new _Size(this.width, this.height);
1307
1953
  }
1308
- equals(rectangle) {
1309
- const rect = _Rectangle.resolve(rectangle);
1310
- return this.position.equals(rect.position) && this.size.equals(rect.size);
1954
+ equals(...args) {
1955
+ const s = _Size.resolveArgs(args);
1956
+ return this.width == s.width && this.height == s.height;
1957
+ }
1958
+ toVec2() {
1959
+ return [this.width, this.height];
1311
1960
  }
1312
1961
  };
1313
1962
 
1314
- // source/geometry/bbox.ts
1315
- var BoundingBox = class _BoundingBox {
1316
- left;
1317
- right;
1318
- top;
1319
- bottom;
1963
+ // source/geometry/rectangle.ts
1964
+ var Rectangle = class _Rectangle {
1965
+ position;
1966
+ size;
1967
+ get area() {
1968
+ return this.width * this.height;
1969
+ }
1970
+ get perimeter() {
1971
+ return this.width + this.width + this.height + this.height;
1972
+ }
1973
+ get x() {
1974
+ return this.position.x;
1975
+ }
1976
+ set x(val) {
1977
+ this.position.x = val;
1978
+ }
1979
+ get y() {
1980
+ return this.position.y;
1981
+ }
1982
+ set y(val) {
1983
+ this.position.y = val;
1984
+ }
1985
+ get w() {
1986
+ return this.position.w;
1987
+ }
1988
+ set w(val) {
1989
+ this.position.w = val;
1990
+ }
1320
1991
  get width() {
1321
- return this.right - this.left;
1992
+ return this.size.width;
1322
1993
  }
1323
1994
  set width(val) {
1324
- this.right = this.left + val;
1995
+ this.size.width = val;
1325
1996
  }
1326
1997
  get height() {
1327
- return this.bottom - this.top;
1998
+ return this.size.height;
1328
1999
  }
1329
2000
  set height(val) {
1330
- this.bottom = this.top + val;
2001
+ this.size.height = val;
1331
2002
  }
1332
2003
  static resolve(a) {
1333
2004
  const value = this.cast(a);
1334
2005
  if (typeof value != "undefined")
1335
2006
  return value;
1336
- throw new ResolveError("BoundingBox", a);
2007
+ throw new ResolveError("Rectangle", a);
2008
+ }
2009
+ static resolveArgs(args) {
2010
+ if ((0, import_types12.isFixedTypeArray)(args, import_types12.isValidNumber, 4))
2011
+ return new this([args[0], args[1]], [args[2], args[3]]);
2012
+ return this.resolve(args[0]);
1337
2013
  }
1338
2014
  static cast(a) {
1339
2015
  if (a == null || typeof a == "undefined")
1340
2016
  return void 0;
1341
- if (check_number_array(a, 4))
1342
- return new this(a[0], a[1], a[2], a[3]);
1343
- if (has_property(a, "left", "number") && has_property(a, "right", "number") && has_property(a, "top", "number") && has_property(a, "bottom", "number"))
1344
- return new this(a.left, a.right, a.top, a.bottom);
1345
- if (check_string(a)) {
1346
- const parts = a.split(",");
1347
- if (check_string_array(parts, 4))
1348
- return this.cast(parts.map((v) => parseFloat(v)));
2017
+ if ((0, import_types12.isFixedTypeArray)(a, import_types12.isValidNumber, 4))
2018
+ return new this([a[0], a[1]], [a[2], a[3]]);
2019
+ if ((0, import_types12.isFixedTypeArray)(a, import_types12.isValidNumber, 5)) {
2020
+ const rect = new this([a[0], a[1]], [a[3], a[4]]);
2021
+ rect.w = a[2];
2022
+ return rect;
2023
+ }
2024
+ if ((0, import_types12.isValidString)(a)) {
2025
+ const [spos, ssize] = a.split("|");
2026
+ const pos = Vec2.cast(spos);
2027
+ const size = Size.cast(ssize);
2028
+ if (typeof pos == "undefined" || typeof size == "undefined")
2029
+ return void 0;
2030
+ const rect = new this([pos.x, pos.y], [size.width, size.height]);
2031
+ rect.w = pos.w;
2032
+ return rect;
2033
+ }
2034
+ if ((0, import_types12.hasObjectProperty)(a, "toRectangle", "function"))
2035
+ return this.cast(a.toRectangle());
2036
+ if ((0, import_types12.hasObjectProperty)(a, "x", "number") && (0, import_types12.hasObjectProperty)(a, "y", "number") && (0, import_types12.hasObjectProperty)(a, "width", "number") && (0, import_types12.hasObjectProperty)(a, "height", "number")) {
2037
+ const rect = new this([a.x, a.y], [a.width, a.height]);
2038
+ if ((0, import_types12.hasObjectProperty)(a, "w", "number"))
2039
+ rect.w = a.w;
2040
+ return rect;
1349
2041
  }
1350
2042
  return void 0;
1351
2043
  }
1352
2044
  static is(a) {
1353
2045
  return typeof this.cast(a) != "undefined";
1354
2046
  }
1355
- constructor(left, right, top, bottom) {
1356
- if (!check_number(left))
1357
- throw new TypeError("expected number for left");
1358
- if (!check_number(right))
1359
- throw new TypeError("expected number for right");
1360
- if (!check_number(top))
1361
- throw new TypeError("expected number for top");
1362
- if (!check_number(bottom))
1363
- throw new TypeError("expected number for bottom");
1364
- this.left = left;
1365
- this.right = right;
1366
- this.top = top;
1367
- this.bottom = bottom;
2047
+ constructor(pos, size) {
2048
+ this.position = Vec2.resolve(pos);
2049
+ this.size = Size.resolve(size);
1368
2050
  }
1369
- toArray() {
1370
- return [this.left, this.right, this.top, this.bottom];
2051
+ toArray(w = this.w !== 1) {
2052
+ return [...this.position.toArray(w), ...this.size.toArray()];
1371
2053
  }
1372
- toString() {
1373
- return `${this.left},${this.right},${this.top},${this.bottom}`;
2054
+ toString(w = this.w !== 1) {
2055
+ return `${this.position.toString(w)}|${this.size.toString()}`;
1374
2056
  }
1375
- toJSON() {
1376
- return {
1377
- left: this.left,
1378
- top: this.top,
1379
- right: this.right,
1380
- bottom: this.bottom
1381
- };
2057
+ get [Symbol.toStringTag]() {
2058
+ return "Rectangle";
1382
2059
  }
1383
- clone() {
1384
- return new _BoundingBox(this.left, this.right, this.top, this.bottom);
2060
+ [import_types12.NodeJSCustomInspect]() {
2061
+ return `Rectangle <${this.toString()}>`;
1385
2062
  }
1386
- equals(bbox) {
1387
- const b = _BoundingBox.resolve(bbox);
1388
- return this.left == b.left && this.right == b.right && this.top == b.top && this.bottom == b.bottom;
2063
+ toJSON() {
2064
+ return { ...this.position.toJSON(), ...this.size.toJSON() };
1389
2065
  }
1390
- toSquare() {
1391
- return new Size(this.width, this.height);
2066
+ toBoundingBox() {
2067
+ return [this.x, this.x + this.width, this.y, this.y + this.height];
1392
2068
  }
1393
- toRectangle() {
1394
- return new Rectangle([this.left, this.top], [this.width, this.height]);
2069
+ toVec2() {
2070
+ return [this.x, this.y, this.w];
1395
2071
  }
1396
- inside(a) {
1397
- const bbox = _BoundingBox.resolve(a);
1398
- return this.right >= bbox.left && bbox.right >= this.left && this.bottom >= bbox.top && bbox.bottom >= this.top;
2072
+ toSize() {
2073
+ return [this.width, this.height];
1399
2074
  }
1400
- insidePoint(a) {
1401
- const point = Vec2.resolve(a);
1402
- return this.left <= point.x && this.right >= point.x && this.top <= point.y && this.bottom >= point.y;
2075
+ clone() {
2076
+ return new _Rectangle(this.position.clone(), this.size.clone());
1403
2077
  }
1404
- insideCircle(a) {
1405
- const circle = Circle.resolve(a);
1406
- const center = Vec2.resolve(circle).add(circle.radius);
1407
- const bboxhe = new Vec2(this.width / 2, this.height / 2);
1408
- const bboxcenter = new Vec2(this.left + bboxhe.x, this.top + bboxhe.y);
1409
- let diff = center.subtract(bboxcenter);
1410
- const clamped = Vec2.clamp(diff, bboxhe.invert(), bboxhe);
1411
- const closest = bboxcenter.add(clamped);
1412
- diff = closest.subtract(center);
1413
- return diff.length() < circle.radius;
2078
+ equals(...args) {
2079
+ const rect = _Rectangle.resolveArgs(args);
2080
+ return this.position.equals(rect.position) && this.size.equals(rect.size);
1414
2081
  }
1415
2082
  };
1416
2083
 
1417
2084
  // source/geometry/triangle.ts
1418
- var ATriangle = class {
2085
+ var import_types13 = require("@ntf/types");
2086
+ var Triangle = class {
1419
2087
  constructor(A, B, C) {
1420
2088
  this.A = A;
1421
2089
  this.B = B;
@@ -1433,349 +2101,54 @@ var ATriangle = class {
1433
2101
  get perimeter() {
1434
2102
  return this.a + this.b + this.c;
1435
2103
  }
1436
- get semiperimeter() {
1437
- return this.perimeter / 2;
1438
- }
1439
- get area() {
1440
- return Math.sqrt(this.semiperimeter * (this.semiperimeter - this.a) * (this.semiperimeter - this.b) * (this.semiperimeter - this.c));
1441
- }
1442
- get base() {
1443
- return 2 * (this.area / (this.a * Math.sin(this.gamma)));
1444
- }
1445
- get height() {
1446
- return 2 * (this.area / this.base);
1447
- }
1448
- };
1449
- var Triangle2D = class extends ATriangle {
1450
- get a() {
1451
- return Vec2.fromPoints(this.B, this.C).length();
1452
- }
1453
- get b() {
1454
- return Vec2.fromPoints(this.A, this.C).length();
1455
- }
1456
- get c() {
1457
- return Vec2.fromPoints(this.A, this.B).length();
1458
- }
1459
- };
1460
- var Triangle3D = class extends ATriangle {
1461
- get a() {
1462
- return Vec3.fromPoints(this.B, this.C).length();
1463
- }
1464
- get b() {
1465
- return Vec3.fromPoints(this.A, this.C).length();
1466
- }
1467
- get c() {
1468
- return Vec3.fromPoints(this.A, this.B).length();
1469
- }
1470
- };
1471
-
1472
- // source/matrices/mat3.ts
1473
- var Mat3 = class _Mat3 {
1474
- _raw;
1475
- get m00() {
1476
- return this._raw[0];
1477
- }
1478
- set m00(val) {
1479
- this._raw[0] = val;
1480
- }
1481
- get m01() {
1482
- return this._raw[1];
1483
- }
1484
- set m01(val) {
1485
- this._raw[1] = val;
1486
- }
1487
- get m02() {
1488
- return this._raw[2];
1489
- }
1490
- set m02(val) {
1491
- this._raw[2] = val;
1492
- }
1493
- get m10() {
1494
- return this._raw[3];
1495
- }
1496
- set m10(val) {
1497
- this._raw[3] = val;
1498
- }
1499
- get m11() {
1500
- return this._raw[4];
1501
- }
1502
- set m11(val) {
1503
- this._raw[4] = val;
1504
- }
1505
- get m12() {
1506
- return this._raw[5];
1507
- }
1508
- set m12(val) {
1509
- this._raw[5] = val;
1510
- }
1511
- get m20() {
1512
- return this._raw[6];
1513
- }
1514
- set m20(val) {
1515
- this._raw[6] = val;
1516
- }
1517
- get m21() {
1518
- return this._raw[7];
1519
- }
1520
- set m21(val) {
1521
- this._raw[7] = val;
1522
- }
1523
- get m22() {
1524
- return this._raw[8];
1525
- }
1526
- set m22(val) {
1527
- this._raw[8] = val;
1528
- }
1529
- static resolve(a) {
1530
- const value = this.cast(a);
1531
- if (typeof value != "undefined")
1532
- return value;
1533
- throw new ResolveError("Mat3", a);
1534
- }
1535
- static cast(a) {
1536
- if (a == null || typeof a == "undefined")
1537
- return void 0;
1538
- if (check_number_array(a, 9)) {
1539
- return new this(a);
1540
- }
1541
- if (check_array(a, void 0, 3)) {
1542
- const row0 = a[0], row1 = a[1], row2 = a[2];
1543
- if (check_number_array(row0, 3) && check_number_array(row1, 3) && check_number_array(row2, 3))
1544
- return new this([
1545
- row0[0],
1546
- row0[1],
1547
- row0[2],
1548
- row1[0],
1549
- row1[1],
1550
- row1[2],
1551
- row2[0],
1552
- row2[1],
1553
- row2[2]
1554
- ]);
1555
- }
1556
- if (check_string(a)) {
1557
- const parts = a.split(",");
1558
- if (check_string_array(parts, 9))
1559
- return this.cast(parts.map((i) => parseFloat(i)));
1560
- }
1561
- 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"))
1562
- return new this([
1563
- a.m00,
1564
- a.m01,
1565
- a.m02,
1566
- a.m10,
1567
- a.m11,
1568
- a.m12,
1569
- a.m20,
1570
- a.m21,
1571
- a.m22
1572
- ]);
1573
- if (check_number(a)) {
1574
- return new this([a, a, a, a, a, a, a, a, a]);
1575
- }
1576
- return void 0;
1577
- }
1578
- static is(a) {
1579
- return typeof this.cast(a) != "undefined";
1580
- }
1581
- static projection(width, height) {
1582
- return new this([
1583
- 2 / width,
1584
- 0,
1585
- 0,
1586
- 0,
1587
- -2 / height,
1588
- 0,
1589
- -1,
1590
- 1,
1591
- 1
1592
- ]);
1593
- }
1594
- constructor(init = [1, 0, 0, 0, 1, 0, 0, 0, 1]) {
1595
- if (!check_number_array(init, 9))
1596
- throw new TypeError("expected a number array with 9 elements");
1597
- this._raw = init;
1598
- }
1599
- toArray() {
1600
- return [
1601
- this.m00,
1602
- this.m01,
1603
- this.m02,
1604
- this.m10,
1605
- this.m11,
1606
- this.m12,
1607
- this.m20,
1608
- this.m21,
1609
- this.m22
1610
- ];
1611
- }
1612
- toNestetArray() {
1613
- return [
1614
- [this.m00, this.m01, this.m02],
1615
- [this.m10, this.m11, this.m12],
1616
- [this.m20, this.m21, this.m22]
1617
- ];
1618
- }
1619
- toJSON() {
1620
- return {
1621
- m00: this.m00,
1622
- m01: this.m01,
1623
- m02: this.m02,
1624
- m10: this.m10,
1625
- m11: this.m11,
1626
- m12: this.m12,
1627
- m20: this.m20,
1628
- m21: this.m21,
1629
- m22: this.m22
1630
- };
2104
+ get semiperimeter() {
2105
+ return this.perimeter / 2;
1631
2106
  }
1632
- toString() {
1633
- return `${this.m00},${this.m01},${this.m02},${this.m10},${this.m11},${this.m12},${this.m20},${this.m21},${this.m22}`;
2107
+ get area() {
2108
+ return Math.sqrt(this.semiperimeter * (this.semiperimeter - this.a) * (this.semiperimeter - this.b) * (this.semiperimeter - this.c));
1634
2109
  }
1635
- clone() {
1636
- return new _Mat3([
1637
- this.m00,
1638
- this.m01,
1639
- this.m02,
1640
- this.m10,
1641
- this.m11,
1642
- this.m12,
1643
- this.m20,
1644
- this.m21,
1645
- this.m22
1646
- ]);
2110
+ get base() {
2111
+ return 2 * (this.area / (this.a * Math.sin(this.gamma)));
1647
2112
  }
1648
- equals(mat) {
1649
- const m = _Mat3.resolve(mat);
1650
- for (let index = 0; index < this._raw.length; index++)
1651
- if (this._raw[index] != m._raw[index])
1652
- return false;
1653
- return true;
2113
+ get height() {
2114
+ return 2 * (this.area / this.base);
1654
2115
  }
1655
- add(mat) {
1656
- const b = _Mat3.resolve(mat);
1657
- const m = new _Mat3();
1658
- for (let index = 0; index < this._raw.length; index++)
1659
- m._raw[index] = this._raw[index] + b._raw[index];
1660
- return m;
2116
+ toString() {
2117
+ return `${this.A}|${this.B}|${this.C}`;
1661
2118
  }
1662
- subtract(mat) {
1663
- const b = _Mat3.resolve(mat);
1664
- const m = new _Mat3();
1665
- for (let index = 0; index < this._raw.length; index++)
1666
- m._raw[index] = this._raw[index] - b._raw[index];
1667
- return m;
2119
+ get [Symbol.toStringTag]() {
2120
+ return "Triangle";
1668
2121
  }
1669
- multiply(a) {
1670
- if (check_number(a))
1671
- return new _Mat3([
1672
- this.m00 * a,
1673
- this.m01 * a,
1674
- this.m02 * a,
1675
- this.m10 * a,
1676
- this.m11 * a,
1677
- this.m12 * a,
1678
- this.m20 * a,
1679
- this.m21 * a,
1680
- this.m22 * a
1681
- ]);
1682
- const b = _Mat3.resolve(a);
1683
- return new _Mat3([
1684
- b.m00 * this.m00 + b.m01 * this.m10 + b.m02 * this.m20,
1685
- b.m00 * this.m01 + b.m01 * this.m11 + b.m02 * this.m21,
1686
- b.m00 * this.m02 + b.m01 * this.m12 + b.m02 * this.m22,
1687
- b.m10 * this.m00 + b.m11 * this.m10 + b.m12 * this.m20,
1688
- b.m10 * this.m01 + b.m11 * this.m11 + b.m12 * this.m21,
1689
- b.m10 * this.m02 + b.m11 * this.m12 + b.m12 * this.m22,
1690
- b.m20 * this.m00 + b.m21 * this.m10 + b.m22 * this.m20,
1691
- b.m20 * this.m01 + b.m21 * this.m11 + b.m22 * this.m21,
1692
- b.m20 * this.m02 + b.m21 * this.m12 + b.m22 * this.m22
1693
- ]);
2122
+ [import_types13.NodeJSCustomInspect]() {
2123
+ return `Triangle <${this.toString()}>`;
1694
2124
  }
1695
- translate(...args) {
1696
- const vec = Vec2.resolveArgs(args);
1697
- return this.multiply([
1698
- 1,
1699
- 0,
1700
- 0,
1701
- 0,
1702
- 1,
1703
- 0,
1704
- vec.x,
1705
- vec.y,
1706
- 1
1707
- ]);
2125
+ };
2126
+ var Triangle2D = class extends Triangle {
2127
+ get a() {
2128
+ return Vec2.fromPoints(this.B, this.C).length();
1708
2129
  }
1709
- rotate(angle) {
1710
- const c = Math.cos(angle);
1711
- const s = Math.sin(angle);
1712
- return this.multiply([
1713
- c,
1714
- -s,
1715
- 0,
1716
- s,
1717
- c,
1718
- 0,
1719
- 0,
1720
- 0,
1721
- 1
1722
- ]);
2130
+ get b() {
2131
+ return Vec2.fromPoints(this.A, this.C).length();
1723
2132
  }
1724
- scale(...args) {
1725
- const vec = Vec2.resolve(args);
1726
- return this.multiply([
1727
- vec.x,
1728
- 0,
1729
- 0,
1730
- 0,
1731
- vec.y,
1732
- 0,
1733
- 0,
1734
- 0,
1735
- 1
1736
- ]);
2133
+ get c() {
2134
+ return Vec2.fromPoints(this.A, this.B).length();
1737
2135
  }
1738
- determinant() {
1739
- return this.m00 * this.m11 * this.m22 - this.m21 * this.m12 - this.m01 * this.m10 * this.m22 - this.m12 * this.m20 + this.m02 * this.m10 * this.m21 - this.m11 * this.m20;
2136
+ };
2137
+ var Triangle3D = class extends Triangle {
2138
+ get a() {
2139
+ return Vec3.fromPoints(this.B, this.C).length();
1740
2140
  }
1741
- inverse() {
1742
- const det = this.determinant();
1743
- return new _Mat3([
1744
- (this.m11 * this.m22 - this.m21 * this.m12) * det,
1745
- (this.m02 * this.m21 - this.m01 * this.m22) * det,
1746
- (this.m01 * this.m12 - this.m02 * this.m11) * det,
1747
- (this.m12 * this.m20 - this.m10 * this.m22) * det,
1748
- (this.m00 * this.m22 - this.m02 * this.m20) * det,
1749
- (this.m10 * this.m02 - this.m00 * this.m12) * det,
1750
- (this.m10 * this.m21 - this.m20 * this.m11) * det,
1751
- (this.m20 * this.m01 - this.m00 * this.m21) * det,
1752
- (this.m00 * this.m11 - this.m10 * this.m01) * det
1753
- ]);
2141
+ get b() {
2142
+ return Vec3.fromPoints(this.A, this.C).length();
1754
2143
  }
1755
- toMat4() {
1756
- return [
1757
- this.m00,
1758
- this.m01,
1759
- this.m02,
1760
- 0,
1761
- this.m10,
1762
- this.m11,
1763
- this.m12,
1764
- 0,
1765
- this.m20,
1766
- this.m20,
1767
- this.m22,
1768
- 0,
1769
- 0,
1770
- 0,
1771
- 0,
1772
- 1
1773
- ];
2144
+ get c() {
2145
+ return Vec3.fromPoints(this.A, this.B).length();
1774
2146
  }
1775
2147
  };
1776
2148
 
1777
- // source/matrices/mat4.ts
1778
- var Mat4 = class _Mat4 {
2149
+ // source/matrices/mat3.ts
2150
+ var import_types14 = require("@ntf/types");
2151
+ var Mat3 = class _Mat3 {
1779
2152
  _raw;
1780
2153
  get m00() {
1781
2154
  return this._raw[0];
@@ -1795,220 +2168,116 @@ var Mat4 = class _Mat4 {
1795
2168
  set m02(val) {
1796
2169
  this._raw[2] = val;
1797
2170
  }
1798
- get m03() {
1799
- return this._raw[3];
1800
- }
1801
- set m03(val) {
1802
- this._raw[3] = val;
1803
- }
1804
2171
  get m10() {
1805
- return this._raw[4];
2172
+ return this._raw[3];
1806
2173
  }
1807
2174
  set m10(val) {
1808
- this._raw[4] = val;
2175
+ this._raw[3] = val;
1809
2176
  }
1810
2177
  get m11() {
1811
- return this._raw[5];
2178
+ return this._raw[4];
1812
2179
  }
1813
2180
  set m11(val) {
1814
- this._raw[5] = val;
2181
+ this._raw[4] = val;
1815
2182
  }
1816
2183
  get m12() {
1817
- return this._raw[6];
2184
+ return this._raw[5];
1818
2185
  }
1819
2186
  set m12(val) {
1820
- this._raw[6] = val;
1821
- }
1822
- get m13() {
1823
- return this._raw[7];
1824
- }
1825
- set m13(val) {
1826
- this._raw[7] = val;
2187
+ this._raw[5] = val;
1827
2188
  }
1828
2189
  get m20() {
1829
- return this._raw[8];
2190
+ return this._raw[6];
1830
2191
  }
1831
2192
  set m20(val) {
1832
- this._raw[8] = val;
2193
+ this._raw[6] = val;
1833
2194
  }
1834
2195
  get m21() {
1835
- return this._raw[9];
2196
+ return this._raw[7];
1836
2197
  }
1837
2198
  set m21(val) {
1838
- this._raw[9] = val;
2199
+ this._raw[7] = val;
1839
2200
  }
1840
2201
  get m22() {
1841
- return this._raw[10];
2202
+ return this._raw[8];
1842
2203
  }
1843
2204
  set m22(val) {
1844
- this._raw[10] = val;
1845
- }
1846
- get m23() {
1847
- return this._raw[11];
1848
- }
1849
- set m23(val) {
1850
- this._raw[11] = val;
1851
- }
1852
- get m30() {
1853
- return this._raw[12];
1854
- }
1855
- set m30(val) {
1856
- this._raw[12] = val;
1857
- }
1858
- get m31() {
1859
- return this._raw[13];
1860
- }
1861
- set m31(val) {
1862
- this._raw[13] = val;
1863
- }
1864
- get m32() {
1865
- return this._raw[14];
1866
- }
1867
- set m32(val) {
1868
- this._raw[14] = val;
1869
- }
1870
- get m33() {
1871
- return this._raw[15];
1872
- }
1873
- set m33(val) {
1874
- this._raw[15] = val;
2205
+ this._raw[8] = val;
1875
2206
  }
1876
2207
  static resolve(a) {
1877
2208
  const value = this.cast(a);
1878
2209
  if (typeof value != "undefined")
1879
2210
  return value;
1880
- throw new ResolveError("Mat4", a);
2211
+ throw new ResolveError("Mat3", a);
2212
+ }
2213
+ static resolveArgs(args) {
2214
+ if ((0, import_types14.isFixedTypeArray)(args, import_types14.isValidNumber, 9))
2215
+ return new this(args);
2216
+ return this.resolve(args[0]);
1881
2217
  }
1882
2218
  static cast(a) {
1883
2219
  if (a == null || typeof a == "undefined")
1884
2220
  return void 0;
1885
- if (check_number_array(a, 16)) {
2221
+ if ((0, import_types14.isFixedTypeArray)(a, import_types14.isValidNumber, 9)) {
1886
2222
  return new this(a);
1887
2223
  }
1888
- if (check_array(a, void 0, 4)) {
1889
- const row0 = a[0], row1 = a[1], row2 = a[2], row3 = a[3];
1890
- if (check_number_array(row0, 4) && check_number_array(row1, 4) && check_number_array(row2, 4) && check_number_array(row3, 4))
2224
+ if ((0, import_types14.isFixedArray)(a, 3)) {
2225
+ const row0 = a[0], row1 = a[1], row2 = a[2];
2226
+ if ((0, import_types14.isFixedTypeArray)(row0, import_types14.isValidNumber, 3) && (0, import_types14.isFixedTypeArray)(row1, import_types14.isValidNumber, 3) && (0, import_types14.isFixedTypeArray)(row2, import_types14.isValidNumber, 3))
1891
2227
  return new this([
1892
2228
  row0[0],
1893
2229
  row0[1],
1894
2230
  row0[2],
1895
- row0[3],
1896
2231
  row1[0],
1897
2232
  row1[1],
1898
2233
  row1[2],
1899
- row1[3],
1900
2234
  row2[0],
1901
2235
  row2[1],
1902
- row2[2],
1903
- row2[3],
1904
- row3[0],
1905
- row3[1],
1906
- row3[2],
1907
- row3[3]
2236
+ row2[2]
1908
2237
  ]);
1909
2238
  }
1910
- if (check_string(a)) {
2239
+ if ((0, import_types14.isValidString)(a)) {
1911
2240
  const parts = a.split(",");
1912
- if (check_string_array(parts, 16))
2241
+ if ((0, import_types14.isFixedTypeArray)(parts, import_types14.isValidString, 9))
1913
2242
  return this.cast(parts.map((i) => parseFloat(i)));
1914
2243
  }
1915
- 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"))
2244
+ if ((0, import_types14.hasObjectProperty)(a, "toMat3", "function"))
2245
+ return this.cast(a.toMat3());
2246
+ if ((0, import_types14.hasObjectProperty)(a, "m00", "number") && (0, import_types14.hasObjectProperty)(a, "m01", "number") && (0, import_types14.hasObjectProperty)(a, "m02", "number") && (0, import_types14.hasObjectProperty)(a, "m10", "number") && (0, import_types14.hasObjectProperty)(a, "m11", "number") && (0, import_types14.hasObjectProperty)(a, "m12", "number") && (0, import_types14.hasObjectProperty)(a, "m20", "number") && (0, import_types14.hasObjectProperty)(a, "m21", "number") && (0, import_types14.hasObjectProperty)(a, "m22", "number"))
1916
2247
  return new this([
1917
2248
  a.m00,
1918
2249
  a.m01,
1919
2250
  a.m02,
1920
- a.m03,
1921
2251
  a.m10,
1922
- a.m11,
1923
- a.m12,
1924
- a.m13,
1925
- a.m20,
1926
- a.m21,
1927
- a.m22,
1928
- a.m23,
1929
- a.m30,
1930
- a.m31,
1931
- a.m32,
1932
- a.m33
1933
- ]);
1934
- if (check_number(a)) {
1935
- return new this([a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a]);
1936
- }
1937
- return void 0;
1938
- }
1939
- static is(a) {
1940
- return typeof this.cast(a) != "undefined";
1941
- }
1942
- static orthographic(left, right, bottom, top, near, far) {
1943
- return new this([
1944
- 2 / (right - left),
1945
- 0,
1946
- 0,
1947
- 0,
1948
- 0,
1949
- 2 / (top - bottom),
1950
- 0,
1951
- 0,
1952
- 0,
1953
- 0,
1954
- 2 / (near - far),
1955
- 0,
1956
- (left + right) / (left - right),
1957
- (bottom + top) / (bottom - top),
1958
- (near + far) / (near - far),
1959
- 1
1960
- ]);
2252
+ a.m11,
2253
+ a.m12,
2254
+ a.m20,
2255
+ a.m21,
2256
+ a.m22
2257
+ ]);
2258
+ if ((0, import_types14.isValidNumber)(a)) {
2259
+ return new this([a, a, a, a, a, a, a, a, a]);
2260
+ }
2261
+ return void 0;
1961
2262
  }
1962
- static perspective(fov, aspect, near, far) {
1963
- const f = Math.tan(Math.PI * 0.5 - 0.5 * fov);
1964
- const rangeInv = 1 / (near - far);
2263
+ static is(a) {
2264
+ return typeof this.cast(a) != "undefined";
2265
+ }
2266
+ static projection(width, height) {
1965
2267
  return new this([
1966
- f / aspect,
1967
- 0,
1968
- 0,
1969
- 0,
1970
- 0,
1971
- f,
2268
+ 2 / width,
1972
2269
  0,
1973
2270
  0,
1974
2271
  0,
2272
+ -2 / height,
1975
2273
  0,
1976
- (near + far) * rangeInv,
1977
2274
  -1,
1978
- 0,
1979
- 0,
1980
- near * far * rangeInv * 2,
1981
- 0
1982
- ]);
1983
- }
1984
- static pointAt(position, target, up) {
1985
- const newForward = Vec3.resolve(target).subtract(position).normalize();
1986
- const a = newForward.multiply(Vec3.resolve(up).dot(newForward));
1987
- const newUp = Vec3.resolve(up).subtract(a).normalize();
1988
- const newRight = newUp.cross(newForward);
1989
- const pos = Vec3.resolve(position);
1990
- return new this([
1991
- newRight.x,
1992
- newRight.y,
1993
- newRight.z,
1994
- 0,
1995
- newUp.x,
1996
- newUp.y,
1997
- newUp.z,
1998
- 0,
1999
- newForward.x,
2000
- newForward.y,
2001
- newForward.z,
2002
- 0,
2003
- pos.x,
2004
- pos.y,
2005
- pos.z,
2275
+ 1,
2006
2276
  1
2007
2277
  ]);
2008
2278
  }
2009
- constructor(init = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]) {
2010
- if (!check_number_array(init, 16))
2011
- throw new TypeError("expected a number array with 16 elements");
2279
+ constructor(init = [1, 0, 0, 0, 1, 0, 0, 0, 1]) {
2280
+ (0, import_types14.checkFixedTypeArray)(init, import_types14.isValidNumber, 9);
2012
2281
  this._raw = init;
2013
2282
  }
2014
2283
  toArray() {
@@ -2016,27 +2285,19 @@ var Mat4 = class _Mat4 {
2016
2285
  this.m00,
2017
2286
  this.m01,
2018
2287
  this.m02,
2019
- this.m03,
2020
2288
  this.m10,
2021
2289
  this.m11,
2022
2290
  this.m12,
2023
- this.m13,
2024
2291
  this.m20,
2025
2292
  this.m21,
2026
- this.m22,
2027
- this.m23,
2028
- this.m30,
2029
- this.m31,
2030
- this.m32,
2031
- this.m33
2293
+ this.m22
2032
2294
  ];
2033
2295
  }
2034
2296
  toNestetArray() {
2035
2297
  return [
2036
- [this.m00, this.m01, this.m02, this.m03],
2037
- [this.m10, this.m11, this.m12, this.m13],
2038
- [this.m20, this.m21, this.m22, this.m23],
2039
- [this.m30, this.m31, this.m32, this.m33]
2298
+ [this.m00, this.m01, this.m02],
2299
+ [this.m10, this.m11, this.m12],
2300
+ [this.m20, this.m21, this.m22]
2040
2301
  ];
2041
2302
  }
2042
2303
  toJSON() {
@@ -2044,835 +2305,900 @@ var Mat4 = class _Mat4 {
2044
2305
  m00: this.m00,
2045
2306
  m01: this.m01,
2046
2307
  m02: this.m02,
2047
- m03: this.m03,
2048
2308
  m10: this.m10,
2049
2309
  m11: this.m11,
2050
2310
  m12: this.m12,
2051
- m13: this.m13,
2052
2311
  m20: this.m20,
2053
2312
  m21: this.m21,
2054
- m22: this.m22,
2055
- m23: this.m23,
2056
- m30: this.m20,
2057
- m31: this.m21,
2058
- m32: this.m22,
2059
- m33: this.m23
2313
+ m22: this.m22
2060
2314
  };
2061
2315
  }
2062
2316
  toString() {
2063
- 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}`;
2317
+ return `${this.m00},${this.m01},${this.m02},${this.m10},${this.m11},${this.m12},${this.m20},${this.m21},${this.m22}`;
2318
+ }
2319
+ get [Symbol.toStringTag]() {
2320
+ return "Mat3";
2321
+ }
2322
+ [import_types14.NodeJSCustomInspect]() {
2323
+ return `Mat3 <${this.toString()}>`;
2064
2324
  }
2065
2325
  clone() {
2066
- return new _Mat4([
2326
+ return new _Mat3([
2067
2327
  this.m00,
2068
2328
  this.m01,
2069
2329
  this.m02,
2070
- this.m03,
2071
2330
  this.m10,
2072
2331
  this.m11,
2073
2332
  this.m12,
2074
- this.m13,
2075
2333
  this.m20,
2076
2334
  this.m21,
2077
- this.m22,
2078
- this.m23,
2079
- this.m30,
2080
- this.m31,
2081
- this.m32,
2082
- this.m33
2335
+ this.m22
2083
2336
  ]);
2084
2337
  }
2085
- equals(mat) {
2086
- const m = _Mat4.resolve(mat);
2338
+ equals(...args) {
2339
+ const m = _Mat3.resolveArgs(args);
2087
2340
  for (let index = 0; index < this._raw.length; index++)
2088
2341
  if (this._raw[index] != m._raw[index])
2089
2342
  return false;
2090
2343
  return true;
2091
2344
  }
2092
- add(mat) {
2093
- const b = _Mat4.resolve(mat);
2094
- const m = new _Mat4();
2345
+ add(...args) {
2346
+ const b = _Mat3.resolveArgs(args);
2347
+ const m = new _Mat3();
2095
2348
  for (let index = 0; index < this._raw.length; index++)
2096
2349
  m._raw[index] = this._raw[index] + b._raw[index];
2097
2350
  return m;
2098
2351
  }
2099
- subtract(mat) {
2100
- const b = _Mat4.resolve(mat);
2101
- const m = new _Mat4();
2352
+ subtract(...args) {
2353
+ const b = _Mat3.resolveArgs(args);
2354
+ const m = new _Mat3();
2102
2355
  for (let index = 0; index < this._raw.length; index++)
2103
2356
  m._raw[index] = this._raw[index] - b._raw[index];
2104
2357
  return m;
2105
2358
  }
2106
- multiply(a) {
2107
- if (check_number(a)) {
2108
- return new _Mat4([
2109
- this.m00 * a,
2110
- this.m01 * a,
2111
- this.m02 * a,
2112
- this.m03 * a,
2113
- this.m10 * a,
2114
- this.m11 * a,
2115
- this.m12 * a,
2116
- this.m13 * a,
2117
- this.m20 * a,
2118
- this.m21 * a,
2119
- this.m22 * a,
2120
- this.m23 * a,
2121
- this.m30 * a,
2122
- this.m31 * a,
2123
- this.m32 * a,
2124
- this.m33 * a
2125
- ]);
2126
- }
2127
- if (_Mat4.is(a)) {
2128
- const b = _Mat4.resolve(a);
2129
- return new _Mat4([
2130
- b.m00 * this.m00 + b.m01 * this.m10 + b.m02 * this.m20 + b.m03 * this.m30,
2131
- b.m00 * this.m01 + b.m01 * this.m11 + b.m02 * this.m21 + b.m03 * this.m31,
2132
- b.m00 * this.m02 + b.m01 * this.m12 + b.m02 * this.m22 + b.m03 * this.m32,
2133
- b.m00 * this.m03 + b.m01 * this.m13 + b.m02 * this.m23 + b.m03 * this.m33,
2134
- b.m10 * this.m00 + b.m11 * this.m10 + b.m12 * this.m20 + b.m13 * this.m30,
2135
- b.m10 * this.m01 + b.m11 * this.m11 + b.m12 * this.m21 + b.m13 * this.m31,
2136
- b.m10 * this.m02 + b.m11 * this.m12 + b.m12 * this.m22 + b.m13 * this.m32,
2137
- b.m10 * this.m03 + b.m11 * this.m13 + b.m12 * this.m23 + b.m13 * this.m33,
2138
- b.m20 * this.m00 + b.m21 * this.m10 + b.m22 * this.m20 + b.m23 * this.m30,
2139
- b.m20 * this.m01 + b.m21 * this.m11 + b.m22 * this.m21 + b.m23 * this.m31,
2140
- b.m20 * this.m02 + b.m21 * this.m12 + b.m22 * this.m22 + b.m23 * this.m32,
2141
- b.m20 * this.m03 + b.m21 * this.m13 + b.m22 * this.m23 + b.m23 * this.m33,
2142
- b.m30 * this.m00 + b.m31 * this.m10 + b.m32 * this.m20 + b.m33 * this.m30,
2143
- b.m30 * this.m01 + b.m31 * this.m11 + b.m32 * this.m21 + b.m33 * this.m31,
2144
- b.m30 * this.m02 + b.m31 * this.m12 + b.m32 * this.m22 + b.m33 * this.m32,
2145
- b.m30 * this.m03 + b.m31 * this.m13 + b.m32 * this.m23 + b.m33 * this.m33
2359
+ multiply(...args) {
2360
+ if ((0, import_types14.isFixedTypeArray)(args, import_types14.isValidNumber, 1))
2361
+ return new _Mat3([
2362
+ this.m00 * args[0],
2363
+ this.m01 * args[0],
2364
+ this.m02 * args[0],
2365
+ this.m10 * args[0],
2366
+ this.m11 * args[0],
2367
+ this.m12 * args[0],
2368
+ this.m20 * args[0],
2369
+ this.m21 * args[0],
2370
+ this.m22 * args[0]
2146
2371
  ]);
2147
- }
2148
- if (Vec3.is(a)) {
2149
- const b = Vec3.resolve(a);
2150
- const vec = new Vec3(
2151
- b.x * this.m00 + b.y * this.m10 + b.z * this.m20 + this.m30,
2152
- b.x * this.m01 + b.y * this.m11 + b.z * this.m21 + this.m31,
2153
- b.x * this.m02 + b.y * this.m12 + b.z * this.m22 + this.m32,
2154
- b.x * this.m03 + b.y * this.m13 + b.z * this.m23 + this.m33
2155
- );
2156
- if (vec.w != 0)
2157
- return vec.divide(vec.w);
2158
- return vec;
2159
- }
2160
- throw new ResolveError("Mat4 or Vec3 or number", a);
2372
+ const b = _Mat3.resolveArgs(args);
2373
+ return new _Mat3([
2374
+ b.m00 * this.m00 + b.m01 * this.m10 + b.m02 * this.m20,
2375
+ b.m00 * this.m01 + b.m01 * this.m11 + b.m02 * this.m21,
2376
+ b.m00 * this.m02 + b.m01 * this.m12 + b.m02 * this.m22,
2377
+ b.m10 * this.m00 + b.m11 * this.m10 + b.m12 * this.m20,
2378
+ b.m10 * this.m01 + b.m11 * this.m11 + b.m12 * this.m21,
2379
+ b.m10 * this.m02 + b.m11 * this.m12 + b.m12 * this.m22,
2380
+ b.m20 * this.m00 + b.m21 * this.m10 + b.m22 * this.m20,
2381
+ b.m20 * this.m01 + b.m21 * this.m11 + b.m22 * this.m21,
2382
+ b.m20 * this.m02 + b.m21 * this.m12 + b.m22 * this.m22
2383
+ ]);
2161
2384
  }
2162
2385
  translate(...args) {
2163
- const vec = Vec3.resolveArgs(args);
2386
+ const vec = Vec2.resolveArgs(args);
2164
2387
  return this.multiply([
2165
2388
  1,
2166
2389
  0,
2167
2390
  0,
2168
2391
  0,
2169
- 0,
2170
- 1,
2171
- 0,
2172
- 0,
2173
- 0,
2174
- 0,
2175
2392
  1,
2176
2393
  0,
2177
2394
  vec.x,
2178
2395
  vec.y,
2179
- vec.z,
2180
- 1
2181
- ]);
2182
- }
2183
- rotateX(angle) {
2184
- const c = Math.cos(angle);
2185
- const s = Math.sin(angle);
2186
- return this.multiply([
2187
- 1,
2188
- 0,
2189
- 0,
2190
- 0,
2191
- 0,
2192
- c,
2193
- s,
2194
- 0,
2195
- 0,
2196
- -s,
2197
- c,
2198
- 0,
2199
- 0,
2200
- 0,
2201
- 0,
2202
2396
  1
2203
2397
  ]);
2204
2398
  }
2205
- rotateY(angle) {
2399
+ rotate(angle) {
2206
2400
  const c = Math.cos(angle);
2207
2401
  const s = Math.sin(angle);
2208
2402
  return this.multiply([
2209
2403
  c,
2210
- 0,
2211
2404
  -s,
2212
2405
  0,
2213
- 0,
2214
- 1,
2215
- 0,
2216
- 0,
2217
- s,
2218
- 0,
2219
- c,
2220
- 0,
2221
- 0,
2222
- 0,
2223
- 0,
2224
- 1
2225
- ]);
2226
- }
2227
- rotateZ(angle) {
2228
- const c = Math.cos(angle);
2229
- const s = Math.sin(angle);
2230
- return this.multiply([
2231
- c,
2232
2406
  s,
2233
- 0,
2234
- 0,
2235
- -s,
2236
2407
  c,
2237
2408
  0,
2238
2409
  0,
2239
2410
  0,
2240
- 0,
2241
- 1,
2242
- 0,
2243
- 0,
2244
- 0,
2245
- 0,
2246
2411
  1
2247
2412
  ]);
2248
2413
  }
2249
- rotate(...args) {
2250
- const vec = Vec3.resolveArgs(args);
2251
- return this.rotateX(vec.x).rotateY(vec.y).rotateZ(vec.z);
2252
- }
2253
2414
  scale(...args) {
2254
- const vec = Vec3.resolveArgs(args);
2415
+ const vec = Vec2.resolve(args);
2255
2416
  return this.multiply([
2256
2417
  vec.x,
2257
2418
  0,
2258
2419
  0,
2259
2420
  0,
2260
- 0,
2261
2421
  vec.y,
2262
2422
  0,
2263
2423
  0,
2264
2424
  0,
2265
- 0,
2266
- vec.z,
2267
- 0,
2268
- 0,
2269
- 0,
2270
- 0,
2271
2425
  1
2272
2426
  ]);
2273
2427
  }
2428
+ determinant() {
2429
+ return this.m00 * this.m11 * this.m22 - this.m21 * this.m12 - this.m01 * this.m10 * this.m22 - this.m12 * this.m20 + this.m02 * this.m10 * this.m21 - this.m11 * this.m20;
2430
+ }
2274
2431
  inverse() {
2275
- return new _Mat4([
2432
+ const det = this.determinant();
2433
+ return new _Mat3([
2434
+ (this.m11 * this.m22 - this.m21 * this.m12) * det,
2435
+ (this.m02 * this.m21 - this.m01 * this.m22) * det,
2436
+ (this.m01 * this.m12 - this.m02 * this.m11) * det,
2437
+ (this.m12 * this.m20 - this.m10 * this.m22) * det,
2438
+ (this.m00 * this.m22 - this.m02 * this.m20) * det,
2439
+ (this.m10 * this.m02 - this.m00 * this.m12) * det,
2440
+ (this.m10 * this.m21 - this.m20 * this.m11) * det,
2441
+ (this.m20 * this.m01 - this.m00 * this.m21) * det,
2442
+ (this.m00 * this.m11 - this.m10 * this.m01) * det
2443
+ ]);
2444
+ }
2445
+ toMat4() {
2446
+ return [
2276
2447
  this.m00,
2277
- this.m10,
2278
- this.m20,
2279
- 0,
2280
2448
  this.m01,
2281
- this.m11,
2282
- this.m21,
2283
- 0,
2284
2449
  this.m02,
2450
+ 0,
2451
+ this.m10,
2452
+ this.m11,
2285
2453
  this.m12,
2454
+ 0,
2455
+ this.m20,
2456
+ this.m20,
2286
2457
  this.m22,
2287
2458
  0,
2288
- -(this.m30 * this.m00 + this.m31 * this.m10 + this.m32 * this.m20),
2289
- -(this.m30 * this.m01 + this.m31 * this.m11 + this.m32 * this.m21),
2290
- -(this.m30 * this.m02 + this.m31 * this.m12 + this.m32 * this.m22),
2459
+ 0,
2460
+ 0,
2461
+ 0,
2291
2462
  1
2292
- ]);
2463
+ ];
2464
+ }
2465
+ };
2466
+
2467
+ // source/matrices/mat4.ts
2468
+ var import_types15 = require("@ntf/types");
2469
+ var Mat4 = class _Mat4 {
2470
+ _raw;
2471
+ get m00() {
2472
+ return this._raw[0];
2473
+ }
2474
+ set m00(val) {
2475
+ this._raw[0] = val;
2476
+ }
2477
+ get m01() {
2478
+ return this._raw[1];
2479
+ }
2480
+ set m01(val) {
2481
+ this._raw[1] = val;
2482
+ }
2483
+ get m02() {
2484
+ return this._raw[2];
2485
+ }
2486
+ set m02(val) {
2487
+ this._raw[2] = val;
2293
2488
  }
2294
- toMat3() {
2295
- return [
2296
- this.m00,
2297
- this.m01,
2298
- this.m03,
2299
- this.m10,
2300
- this.m11,
2301
- this.m13,
2302
- this.m30,
2303
- this.m31,
2304
- this.m33
2305
- ];
2489
+ get m03() {
2490
+ return this._raw[3];
2306
2491
  }
2307
- };
2308
-
2309
- // source/color.ts
2310
- function _hex_to_array(hex) {
2311
- if (!check_hex(hex))
2312
- return void 0;
2313
- const part = get_hex_part(hex);
2314
- const a = parseInt(part.substring(0, 2), 16) / 255;
2315
- const b = parseInt(part.substring(2, 4), 16) / 255;
2316
- const c = parseInt(part.substring(4, 6), 16) / 255;
2317
- const d = part.length == 8 ? parseInt(hex.substring(6, 8), 16) / 255 : 1;
2318
- return [a, b, c, d];
2319
- }
2320
- function _number_to_rgb(number) {
2321
- const blue = number & 255;
2322
- const green = (number & 65280) >>> 8;
2323
- const red = (number & 16711680) >>> 16;
2324
- return [red / 255, green / 255, blue / 255];
2325
- }
2326
- function _number_to_rgba(number) {
2327
- const alpha = number & 255;
2328
- const blue = (number & 65280) >>> 8;
2329
- const green = (number & 16711680) >>> 16;
2330
- const red = (number & 4278190080) >>> 24;
2331
- return [red / 255, green / 255, blue / 255, alpha / 255];
2332
- }
2333
- function _fix_integer(number) {
2334
- return number * 255 | 0;
2335
- }
2336
- var RGBAColor = class _RGBAColor {
2337
- _red;
2338
- get red() {
2339
- return this._red;
2492
+ set m03(val) {
2493
+ this._raw[3] = val;
2340
2494
  }
2341
- set red(val) {
2342
- this._red = clamp(val, 0, 1);
2495
+ get m10() {
2496
+ return this._raw[4];
2343
2497
  }
2344
- _green;
2345
- get green() {
2346
- return this._green;
2498
+ set m10(val) {
2499
+ this._raw[4] = val;
2347
2500
  }
2348
- set green(val) {
2349
- this._green = clamp(val, 0, 1);
2501
+ get m11() {
2502
+ return this._raw[5];
2350
2503
  }
2351
- _blue;
2352
- get blue() {
2353
- return this._blue;
2504
+ set m11(val) {
2505
+ this._raw[5] = val;
2354
2506
  }
2355
- set blue(val) {
2356
- this._blue = clamp(val, 0, 1);
2507
+ get m12() {
2508
+ return this._raw[6];
2357
2509
  }
2358
- _alpha;
2359
- get alpha() {
2360
- return this._alpha;
2510
+ set m12(val) {
2511
+ this._raw[6] = val;
2361
2512
  }
2362
- set alpha(val) {
2363
- this._alpha = clamp(val, 0, 1);
2513
+ get m13() {
2514
+ return this._raw[7];
2364
2515
  }
2365
- static resolve(a) {
2366
- const value = this.cast(a);
2367
- if (typeof value != "undefined")
2368
- return value;
2369
- throw new ResolveError("RGBAColor", a);
2516
+ set m13(val) {
2517
+ this._raw[7] = val;
2370
2518
  }
2371
- static cast(a) {
2372
- if (a == null || typeof a == "undefined")
2373
- return void 0;
2374
- if (check_number_array(a, 3) || check_number_array(a, 4))
2375
- return new this(a[0], a[1], a[2], a[3]);
2376
- if (has_property(a, "red", "number") && has_property(a, "green", "number") && has_property(a, "blue", "number"))
2377
- return new this(a.red, a.green, a.blue, has_property(a, "alpha", "number") ? a.alpha : void 0);
2378
- if (check_number(a)) {
2379
- const hex = a.toString(16);
2380
- const convert = hex.length <= 6 ? _number_to_rgb : _number_to_rgba;
2381
- return this.cast(convert(a));
2382
- }
2383
- if (check_string(a)) {
2384
- if (a.startsWith("rgb")) {
2385
- const hasAlpha = a.startsWith("rgba");
2386
- const offset = hasAlpha ? 5 : 4;
2387
- const parts = a.substring(offset, a.indexOf(")", offset)).split(",");
2388
- if (check_string_array(parts, hasAlpha ? 4 : 3))
2389
- return this.cast(parts.map((v) => parseInt(v) / 255));
2390
- }
2391
- return this.cast(_hex_to_array(a));
2392
- }
2393
- return void 0;
2519
+ get m20() {
2520
+ return this._raw[8];
2394
2521
  }
2395
- static is(a) {
2396
- return typeof this.cast(a) != "undefined";
2522
+ set m20(val) {
2523
+ this._raw[8] = val;
2397
2524
  }
2398
- constructor(red, green, blue, alpha = 1) {
2399
- this._red = clamp(red, 0, 1);
2400
- this._green = clamp(green, 0, 1);
2401
- this._blue = clamp(blue, 0, 1);
2402
- this._alpha = clamp(alpha, 0, 1);
2525
+ get m21() {
2526
+ return this._raw[9];
2403
2527
  }
2404
- toArray(withAlpha = false) {
2405
- return withAlpha ? [this.red, this.green, this.blue, this.alpha] : this.alpha == 1 ? [this.red, this.green, this.blue] : this.toArray(true);
2528
+ set m21(val) {
2529
+ this._raw[9] = val;
2406
2530
  }
2407
- toJSON(withAlpha = false) {
2408
- return withAlpha ? {
2409
- red: this.red,
2410
- green: this.green,
2411
- blue: this.blue,
2412
- alpha: this.alpha
2413
- } : this.alpha == 1 ? { red: this.red, green: this.green, blue: this.blue } : this.toJSON(true);
2531
+ get m22() {
2532
+ return this._raw[10];
2414
2533
  }
2415
- toString(withAlpha = false) {
2416
- return withAlpha ? `rgba(${_fix_integer(this.red)},${_fix_integer(this.green)},${_fix_integer(this.blue)},${this.alpha})` : this.alpha == 1 ? `rgb(${_fix_integer(this.red)},${_fix_integer(this.green)},${_fix_integer(this.blue)})` : this.toString(true);
2534
+ set m22(val) {
2535
+ this._raw[10] = val;
2417
2536
  }
2418
- toHSL(withAlpha = true) {
2419
- const red = this.red, green = this.green, blue = this.blue;
2420
- const min = Math.min(red, green, blue), max = Math.max(red, green, blue);
2421
- const luminace = (min + max) / 2;
2422
- if (min == max)
2423
- return new HSLColor(0, 0, luminace, withAlpha ? this.alpha : void 0);
2424
- const d = max - min;
2425
- const saturation = luminace > 0.5 ? d / (2 - max - min) : d / (max + min);
2426
- if (max == red)
2427
- return new HSLColor(((green - blue) / d + (green < blue ? 6 : 0)) / 6, saturation, luminace);
2428
- if (max == green)
2429
- return new HSLColor(((blue - red) / d + 2) / 6, saturation, luminace);
2430
- if (max == blue)
2431
- return new HSLColor(((red - green) / d + 4) / 6, saturation, luminace);
2432
- return new HSLColor(0, saturation, luminace, withAlpha ? this.alpha : void 0);
2537
+ get m23() {
2538
+ return this._raw[11];
2433
2539
  }
2434
- invert(withAlpha = false) {
2435
- return new _RGBAColor(
2436
- 1 - this.red,
2437
- 1 - this.green,
2438
- 1 - this.blue,
2439
- withAlpha ? 1 - this.alpha : this.alpha
2440
- );
2540
+ set m23(val) {
2541
+ this._raw[11] = val;
2441
2542
  }
2442
- };
2443
- var HSLColor = class _HSLColor {
2444
- _hue;
2445
- get hue() {
2446
- return this._hue;
2543
+ get m30() {
2544
+ return this._raw[12];
2447
2545
  }
2448
- set hue(val) {
2449
- this._hue = clamp(val, 0, 1);
2546
+ set m30(val) {
2547
+ this._raw[12] = val;
2450
2548
  }
2451
- _saturation;
2452
- get saturation() {
2453
- return this._saturation;
2549
+ get m31() {
2550
+ return this._raw[13];
2454
2551
  }
2455
- set saturation(val) {
2456
- this._saturation = clamp(val, 0, 1);
2552
+ set m31(val) {
2553
+ this._raw[13] = val;
2457
2554
  }
2458
- _luminace;
2459
- get luminace() {
2460
- return this._luminace;
2555
+ get m32() {
2556
+ return this._raw[14];
2461
2557
  }
2462
- set luminace(val) {
2463
- this._luminace = clamp(val, 0, 1);
2558
+ set m32(val) {
2559
+ this._raw[14] = val;
2464
2560
  }
2465
- _alpha;
2466
- get alpha() {
2467
- return this._alpha;
2561
+ get m33() {
2562
+ return this._raw[15];
2468
2563
  }
2469
- set alpha(val) {
2470
- this._alpha = clamp(val, 0, 1);
2564
+ set m33(val) {
2565
+ this._raw[15] = val;
2471
2566
  }
2472
2567
  static resolve(a) {
2473
2568
  const value = this.cast(a);
2474
2569
  if (typeof value != "undefined")
2475
2570
  return value;
2476
- throw new ResolveError("HSLColor", a);
2571
+ throw new ResolveError("Mat4", a);
2572
+ }
2573
+ static resolveArgs(args) {
2574
+ if ((0, import_types15.isFixedTypeArray)(args, import_types15.isValidNumber, 16))
2575
+ return new this(args);
2576
+ return this.resolve(args[0]);
2477
2577
  }
2478
2578
  static cast(a) {
2479
2579
  if (a == null || typeof a == "undefined")
2480
2580
  return void 0;
2481
- if (check_number_array(a, 3) || check_number_array(a, 4))
2482
- return new this(a[0], a[1], a[2], a[3]);
2483
- if (has_property(a, "hue", "number") && has_property(a, "saturation", "number") && has_property(a, "luminace", "number"))
2484
- return new this(a.hue, a.saturation, a.luminace, has_property(a, "alpha", "number") ? a.alpha : void 0);
2485
- if (check_number(a)) {
2486
- const hex = a.toString(16);
2487
- const convert = hex.length <= 6 ? _number_to_rgb : _number_to_rgba;
2488
- return this.cast(convert(a));
2581
+ if ((0, import_types15.isFixedTypeArray)(a, import_types15.isValidNumber, 16)) {
2582
+ return new this(a);
2489
2583
  }
2490
- if (check_string(a)) {
2491
- if (a.startsWith("hsl")) {
2492
- const hasAlpha = a.startsWith("hsla");
2493
- const offset = hasAlpha ? 5 : 4;
2494
- const parts = a.substring(offset, a.indexOf(")", offset)).split(",");
2495
- if (check_string_array(parts, hasAlpha ? 4 : 3))
2496
- return this.cast(parts.map((v) => parseInt(v) / 255));
2497
- }
2498
- return this.cast(_hex_to_array(a));
2584
+ if ((0, import_types15.isFixedArray)(a, 4)) {
2585
+ const row0 = a[0], row1 = a[1], row2 = a[2], row3 = a[3];
2586
+ if ((0, import_types15.isFixedTypeArray)(row0, import_types15.isValidNumber, 4) && (0, import_types15.isFixedTypeArray)(row1, import_types15.isValidNumber, 4) && (0, import_types15.isFixedTypeArray)(row2, import_types15.isValidNumber, 4) && (0, import_types15.isFixedTypeArray)(row3, import_types15.isValidNumber, 4))
2587
+ return new this([
2588
+ row0[0],
2589
+ row0[1],
2590
+ row0[2],
2591
+ row0[3],
2592
+ row1[0],
2593
+ row1[1],
2594
+ row1[2],
2595
+ row1[3],
2596
+ row2[0],
2597
+ row2[1],
2598
+ row2[2],
2599
+ row2[3],
2600
+ row3[0],
2601
+ row3[1],
2602
+ row3[2],
2603
+ row3[3]
2604
+ ]);
2499
2605
  }
2500
- return void 0;
2501
- }
2502
- static is(a) {
2503
- return typeof this.cast(a) != "undefined";
2504
- }
2505
- constructor(hue, saturation, luminace, alpha = 1) {
2506
- if (!check_number(hue))
2507
- throw new TypeError("expected number for hue");
2508
- if (!check_number(saturation))
2509
- throw new TypeError("expected number for saturation");
2510
- if (!check_number(luminace))
2511
- throw new TypeError("expected number for luminace");
2512
- if (!check_number(alpha))
2513
- throw new TypeError("expected number for alpha");
2514
- this._hue = clamp(hue, 0, 1);
2515
- this._saturation = clamp(saturation, 0, 1);
2516
- this._luminace = clamp(luminace, 0, 1);
2517
- this._alpha = clamp(alpha, 0, 1);
2518
- }
2519
- toArray(withAlpha = false) {
2520
- return withAlpha ? [this.hue, this.saturation, this.luminace, this.alpha] : this.alpha == 1 ? [this.hue, this.saturation, this.luminace] : this.toArray(true);
2521
- }
2522
- toJSON(withAlpha = false) {
2523
- return withAlpha ? {
2524
- hue: this.hue,
2525
- saturation: this.saturation,
2526
- luminace: this.luminace,
2527
- alpha: this.alpha
2528
- } : this.alpha == 1 ? { hue: this.hue, saturation: this.saturation, luminace: this.luminace } : this.toJSON(true);
2529
- }
2530
- toString(withAlpha = false) {
2531
- return withAlpha ? `hsla(${_fix_integer(this.hue)},${_fix_integer(this.saturation)},${_fix_integer(this.luminace)},${this.alpha})` : this.alpha == 1 ? `hsl(${_fix_integer(this.hue)},${_fix_integer(this.saturation)},${_fix_integer(this.luminace)})` : this.toString(true);
2532
- }
2533
- toRGB(withAlpha = true) {
2534
- if (this.saturation == 0)
2535
- return new RGBAColor(this.luminace * 255, this.luminace * 255, this.luminace * 255, withAlpha ? this.alpha : void 0);
2536
- const q = this.luminace < 0.5 ? this.luminace * (1 + this.saturation) : this.luminace + this.saturation - this.luminace * this.saturation;
2537
- const p = 2 * this.luminace - q;
2538
- function _hue_2_rgb(t) {
2539
- let _t = t;
2540
- if (_t < 0)
2541
- _t++;
2542
- if (_t > 1)
2543
- _t--;
2544
- if (_t < 1 / 6)
2545
- return p + (q - p) * 6 * _t;
2546
- if (_t < 1 / 2)
2547
- return q;
2548
- if (_t < 2 / 3)
2549
- return p + (q - p) * (2 / 3 - _t) * 6;
2550
- return p;
2606
+ if ((0, import_types15.isValidString)(a)) {
2607
+ const parts = a.split(",");
2608
+ if ((0, import_types15.isFixedTypeArray)(parts, import_types15.isValidString, 16))
2609
+ return this.cast(parts.map((i) => parseFloat(i)));
2610
+ }
2611
+ if ((0, import_types15.hasObjectProperty)(a, "toMat4", "function"))
2612
+ return this.cast(a.toMat4());
2613
+ if ((0, import_types15.hasObjectProperty)(a, "m00", "number") && (0, import_types15.hasObjectProperty)(a, "m01", "number") && (0, import_types15.hasObjectProperty)(a, "m02", "number") && (0, import_types15.hasObjectProperty)(a, "m03", "number") && (0, import_types15.hasObjectProperty)(a, "m10", "number") && (0, import_types15.hasObjectProperty)(a, "m11", "number") && (0, import_types15.hasObjectProperty)(a, "m12", "number") && (0, import_types15.hasObjectProperty)(a, "m13", "number") && (0, import_types15.hasObjectProperty)(a, "m20", "number") && (0, import_types15.hasObjectProperty)(a, "m21", "number") && (0, import_types15.hasObjectProperty)(a, "m22", "number") && (0, import_types15.hasObjectProperty)(a, "m23", "number") && (0, import_types15.hasObjectProperty)(a, "m30", "number") && (0, import_types15.hasObjectProperty)(a, "m31", "number") && (0, import_types15.hasObjectProperty)(a, "m32", "number") && (0, import_types15.hasObjectProperty)(a, "m33", "number"))
2614
+ return new this([
2615
+ a.m00,
2616
+ a.m01,
2617
+ a.m02,
2618
+ a.m03,
2619
+ a.m10,
2620
+ a.m11,
2621
+ a.m12,
2622
+ a.m13,
2623
+ a.m20,
2624
+ a.m21,
2625
+ a.m22,
2626
+ a.m23,
2627
+ a.m30,
2628
+ a.m31,
2629
+ a.m32,
2630
+ a.m33
2631
+ ]);
2632
+ if ((0, import_types15.isValidNumber)(a)) {
2633
+ return new this([a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a]);
2551
2634
  }
2552
- 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);
2553
- }
2554
- invert(withAlpha = false) {
2555
- return new _HSLColor(
2556
- 1 - this.hue,
2557
- 1 - this.saturation,
2558
- 1 - this.luminace,
2559
- withAlpha ? 1 - this.alpha : this.alpha
2560
- );
2635
+ return void 0;
2561
2636
  }
2562
- };
2563
- function resolveColor(a, preferHSL = false) {
2564
- const value = castColor(a, preferHSL);
2565
- if (typeof value != "undefined")
2566
- return value;
2567
- throw new ResolveError("Color", a);
2568
- }
2569
- function castColor(a, preferHSL = false) {
2570
- const results = [];
2571
- try {
2572
- const rgba = RGBAColor.resolve(a);
2573
- results.push(rgba);
2574
- } catch (e) {
2575
- }
2576
- try {
2577
- const hsla = HSLColor.resolve(a);
2578
- results.push(hsla);
2579
- } catch (e) {
2580
- }
2581
- let offset = preferHSL ? 1 : 0;
2582
- const firstItem = results[offset];
2583
- if (firstItem)
2584
- return firstItem;
2585
- const secondItem = results[offset + 1];
2586
- if (secondItem)
2587
- return secondItem;
2588
- return void 0;
2589
- }
2590
-
2591
- // source/quaternion.ts
2592
- var Quaternion = class _Quaternion {
2593
- w;
2594
- x;
2595
- y;
2596
- z;
2597
2637
  static is(a) {
2598
2638
  return typeof this.cast(a) != "undefined";
2599
2639
  }
2600
- static resolve(a) {
2601
- const value = this.cast(a);
2602
- if (typeof value != "undefined")
2603
- return value;
2604
- throw new ResolveError("Quaternion", a);
2605
- }
2606
- static cast(a) {
2607
- if (a == null || typeof a == "undefined")
2608
- return void 0;
2609
- if (check_number_array(a, 4))
2610
- return new this(a[0], a[1], a[2], a[3]);
2611
- if (has_property(a, "w", "number") && has_property(a, "x", "number") && has_property(a, "y", "number") && has_property(a, "z", "number"))
2612
- return new this(a.w, a.x, a.y, a.z);
2613
- if (check_string(a)) {
2614
- const parts = a.replaceAll(" ", "").split("+");
2615
- if (check_string_array(parts, 4)) {
2616
- const [sw, sxi, syj, szk] = parts;
2617
- if (sxi.endsWith("i") && syj.endsWith("j") && szk.endsWith("k"))
2618
- return this.cast([
2619
- parseFloat(sw),
2620
- parseFloat(sxi.substring(0, sxi.length - 1)),
2621
- parseFloat(syj.substring(0, syj.length - 1)),
2622
- parseFloat(szk.substring(0, szk.length - 1))
2623
- ]);
2624
- }
2625
- }
2626
- return void 0;
2640
+ static orthographic(...args) {
2641
+ const bbox = (0, import_types15.isFixedTypeArray)(args, import_types15.isValidNumber, 6) ? new BoundingBox(args[0], args[1], args[2], args[3]) : BoundingBox.resolve(args[0]);
2642
+ const near = (0, import_types15.isFixedTypeArray)(args, import_types15.isValidNumber, 6) ? args[4] : args[1];
2643
+ const far = (0, import_types15.isFixedTypeArray)(args, import_types15.isValidNumber, 6) ? args[5] : args[2];
2644
+ return new this([
2645
+ 2 / (bbox.right - bbox.left),
2646
+ 0,
2647
+ 0,
2648
+ 0,
2649
+ 0,
2650
+ 2 / (bbox.top - bbox.bottom),
2651
+ 0,
2652
+ 0,
2653
+ 0,
2654
+ 0,
2655
+ 2 / (near - far),
2656
+ 0,
2657
+ (bbox.left + bbox.right) / (bbox.left - bbox.right),
2658
+ (bbox.bottom + bbox.top) / (bbox.bottom - bbox.top),
2659
+ (near + far) / (near - far),
2660
+ 1
2661
+ ]);
2627
2662
  }
2628
- static fromAxisAngle(axis, angle) {
2629
- const vec = Vec3.resolve(axis);
2630
- const hangle = angle * 0.5;
2631
- const sin2 = Math.sin(hangle);
2632
- const cos2 = Math.cos(hangle);
2633
- const length = sin2 / Math.sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z);
2634
- return new this(cos2, vec.x * length, vec.y * length, vec.z * length);
2663
+ static perspective(fov, aspect, near, far) {
2664
+ const f = Math.tan(Math.PI * 0.5 - 0.5 * fov);
2665
+ const rangeInv = 1 / (near - far);
2666
+ return new this([
2667
+ f / aspect,
2668
+ 0,
2669
+ 0,
2670
+ 0,
2671
+ 0,
2672
+ f,
2673
+ 0,
2674
+ 0,
2675
+ 0,
2676
+ 0,
2677
+ (near + far) * rangeInv,
2678
+ -1,
2679
+ 0,
2680
+ 0,
2681
+ near * far * rangeInv * 2,
2682
+ 0
2683
+ ]);
2635
2684
  }
2636
- static fromEuler(...args) {
2637
- const vec = Vec3.resolveArgs(args);
2638
- const x2 = vec.x * 0.5, y2 = vec.y * 0.5, z2 = vec.z * 0.5;
2639
- const cx = Math.cos(x2), cy = Math.cos(y2), cz = Math.cos(z2);
2640
- const sx = Math.sin(x2), sy = Math.sin(y2), sz = Math.sin(z2);
2641
- return new _Quaternion(
2642
- cx * cy * cz - sx * sy * sz,
2643
- sx * cy * cz - sy * sz * cx,
2644
- sy * cx * cz - sx * sz * cy,
2645
- sx * sy * cz + sz * cx * cy
2646
- );
2685
+ static pointAt(position, target, up) {
2686
+ const newForward = Vec3.resolve(target).subtract(position).normalize();
2687
+ const a = newForward.multiply(Vec3.resolve(up).dot(newForward));
2688
+ const newUp = Vec3.resolve(up).subtract(a).normalize();
2689
+ const newRight = newUp.cross(newForward);
2690
+ const pos = Vec3.resolve(position);
2691
+ return new this([
2692
+ newRight.x,
2693
+ newRight.y,
2694
+ newRight.z,
2695
+ 0,
2696
+ newUp.x,
2697
+ newUp.y,
2698
+ newUp.z,
2699
+ 0,
2700
+ newForward.x,
2701
+ newForward.y,
2702
+ newForward.z,
2703
+ 0,
2704
+ pos.x,
2705
+ pos.y,
2706
+ pos.z,
2707
+ 1
2708
+ ]);
2647
2709
  }
2648
- constructor(w = 0, x = 0, y = 0, z = 0) {
2649
- if (!check_number(w))
2650
- throw new TypeError("expected number for w");
2651
- if (!check_number(x))
2652
- throw new TypeError("expected number for x");
2653
- if (!check_number(y))
2654
- throw new TypeError("expected number for x");
2655
- if (!check_number(z))
2656
- throw new TypeError("expected number for w");
2657
- this.w = w;
2658
- this.x = x;
2659
- this.y = y;
2660
- this.z = z;
2710
+ constructor(init = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]) {
2711
+ (0, import_types15.checkFixedTypeArray)(init, import_types15.isValidNumber, 16);
2712
+ this._raw = init;
2661
2713
  }
2662
2714
  toArray() {
2663
- return [this.w, this.x, this.y, this.z];
2715
+ return [
2716
+ this.m00,
2717
+ this.m01,
2718
+ this.m02,
2719
+ this.m03,
2720
+ this.m10,
2721
+ this.m11,
2722
+ this.m12,
2723
+ this.m13,
2724
+ this.m20,
2725
+ this.m21,
2726
+ this.m22,
2727
+ this.m23,
2728
+ this.m30,
2729
+ this.m31,
2730
+ this.m32,
2731
+ this.m33
2732
+ ];
2664
2733
  }
2665
- toString() {
2666
- return `${this.w} + ${this.x}i + ${this.y}j + ${this.z}k`;
2734
+ toNestetArray() {
2735
+ return [
2736
+ [this.m00, this.m01, this.m02, this.m03],
2737
+ [this.m10, this.m11, this.m12, this.m13],
2738
+ [this.m20, this.m21, this.m22, this.m23],
2739
+ [this.m30, this.m31, this.m32, this.m33]
2740
+ ];
2667
2741
  }
2668
2742
  toJSON() {
2669
2743
  return {
2670
- w: this.w,
2671
- x: this.x,
2672
- y: this.y,
2673
- z: this.z
2744
+ m00: this.m00,
2745
+ m01: this.m01,
2746
+ m02: this.m02,
2747
+ m03: this.m03,
2748
+ m10: this.m10,
2749
+ m11: this.m11,
2750
+ m12: this.m12,
2751
+ m13: this.m13,
2752
+ m20: this.m20,
2753
+ m21: this.m21,
2754
+ m22: this.m22,
2755
+ m23: this.m23,
2756
+ m30: this.m20,
2757
+ m31: this.m21,
2758
+ m32: this.m22,
2759
+ m33: this.m23
2674
2760
  };
2675
2761
  }
2676
- clone() {
2677
- return new _Quaternion(this.w, this.x, this.y, this.z);
2678
- }
2679
- add(a) {
2680
- const quat = _Quaternion.resolve(a);
2681
- return new _Quaternion(
2682
- this.w + quat.w,
2683
- this.x + quat.x,
2684
- this.y + quat.y,
2685
- this.z + quat.z
2686
- );
2687
- }
2688
- offset(a) {
2689
- const quat = _Quaternion.resolve(a);
2690
- this.w += quat.w;
2691
- this.x += quat.x;
2692
- this.y += quat.y;
2693
- this.z += quat.z;
2694
- return this;
2695
- }
2696
- subtract(a) {
2697
- const quat = _Quaternion.resolve(a);
2698
- return new _Quaternion(
2699
- this.w - quat.w,
2700
- this.x - quat.x,
2701
- this.y - quat.y,
2702
- this.z - quat.z
2703
- );
2704
- }
2705
- negative() {
2706
- return new _Quaternion(-this.w, -this.x, -this.y, -this.z);
2707
- }
2708
- length(sqrt = true) {
2709
- const value = this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z;
2710
- return sqrt ? Math.sqrt(value) : value;
2711
- }
2712
- normalize() {
2713
- let length = this.length();
2714
- if (length < EPSILON)
2715
- return new _Quaternion();
2716
- length = 1 / length;
2717
- return new _Quaternion(this.w * length, this.x * length, this.y * length, this.z * length);
2718
- }
2719
- multiply(a) {
2720
- const quat = _Quaternion.resolve(a);
2721
- return new _Quaternion(
2722
- this.w * quat.w - this.x * quat.x - this.y * quat.y - this.z * quat.z,
2723
- this.w * quat.x + this.x * quat.w + this.y * quat.z - this.z * quat.y,
2724
- this.w * quat.y + this.y * quat.w + this.z * quat.x - this.x * quat.z,
2725
- this.w * quat.z + this.z * quat.w + this.x * quat.y - this.y * quat.x
2726
- );
2727
- }
2728
- multiplyVector(...args) {
2729
- const vec = Vec3.resolveArgs(args);
2730
- const ix = this.w * vec.x + this.y * vec.y - this.z * vec.y;
2731
- const iy = this.w * vec.y + this.z * vec.x - this.x * vec.z;
2732
- const iz = this.w * vec.z + this.x * vec.y - this.y * vec.x;
2733
- const iw = -this.w * vec.x - this.y * vec.y - this.z * vec.z;
2734
- return new Vec3(
2735
- ix * this.w + iw * -this.x + iy * -this.z - iz * -this.y,
2736
- iy * this.w + iw * -this.y + iz * -this.x - ix * -this.z,
2737
- iz * this.w + iw * -this.z + ix * -this.y - iy * -this.x
2738
- );
2762
+ toString() {
2763
+ 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}`;
2739
2764
  }
2740
- scale(scalar) {
2741
- return new _Quaternion(this.w * scalar, this.x * scalar, this.y * scalar, this.z * scalar);
2765
+ get [Symbol.toStringTag]() {
2766
+ return "Mat4";
2742
2767
  }
2743
- dot(a) {
2744
- const quat = _Quaternion.resolve(a);
2745
- return this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z;
2768
+ [import_types15.NodeJSCustomInspect]() {
2769
+ return `Mat4 <${this.toString()}>`;
2746
2770
  }
2747
- inverse() {
2748
- let length = this.length(false);
2749
- if (length == 0)
2750
- return new _Quaternion();
2751
- length = 1 / length;
2752
- return new _Quaternion(this.w * length, -this.x * length, -this.y * length, -this.z * length);
2771
+ clone() {
2772
+ return new _Mat4([
2773
+ this.m00,
2774
+ this.m01,
2775
+ this.m02,
2776
+ this.m03,
2777
+ this.m10,
2778
+ this.m11,
2779
+ this.m12,
2780
+ this.m13,
2781
+ this.m20,
2782
+ this.m21,
2783
+ this.m22,
2784
+ this.m23,
2785
+ this.m30,
2786
+ this.m31,
2787
+ this.m32,
2788
+ this.m33
2789
+ ]);
2753
2790
  }
2754
- divide(a) {
2755
- const quat = _Quaternion.resolve(a);
2756
- let length = quat.length(false);
2757
- if (length == 0) return new _Quaternion();
2758
- length = 1 / length;
2759
- return new _Quaternion(
2760
- (this.w * quat.w + this.x * quat.x + this.y * quat.y + this.z * quat.z) * length,
2761
- (this.x * quat.w - this.w * quat.x - this.y * quat.z + this.z * quat.y) * length,
2762
- (this.y * quat.w - this.w * quat.y - this.z * quat.x + this.x * quat.z) * length,
2763
- (this.z * quat.w - this.w * quat.z - this.x * quat.y + this.y * quat.x) * length
2764
- );
2791
+ equals(...args) {
2792
+ const m = _Mat4.resolveArgs(args);
2793
+ for (let index = 0; index < this._raw.length; index++)
2794
+ if (this._raw[index] != m._raw[index])
2795
+ return false;
2796
+ return true;
2765
2797
  }
2766
- conjugate() {
2767
- return new _Quaternion(this.w, -this.x, -this.y, -this.z);
2798
+ add(...args) {
2799
+ const b = _Mat4.resolveArgs(args);
2800
+ const m = new _Mat4();
2801
+ for (let index = 0; index < this._raw.length; index++)
2802
+ m._raw[index] = this._raw[index] + b._raw[index];
2803
+ return m;
2768
2804
  }
2769
- exp() {
2770
- const length = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
2771
- const exp = Math.exp(this.w);
2772
- const scale = exp * Math.sin(length) / length;
2773
- if (length == 0)
2774
- return new _Quaternion(exp);
2775
- return new _Quaternion(
2776
- exp * Math.cos(length),
2777
- this.x * scale,
2778
- this.y * scale,
2779
- this.z * scale
2780
- );
2805
+ subtract(...args) {
2806
+ const b = _Mat4.resolveArgs(args);
2807
+ const m = new _Mat4();
2808
+ for (let index = 0; index < this._raw.length; index++)
2809
+ m._raw[index] = this._raw[index] - b._raw[index];
2810
+ return m;
2781
2811
  }
2782
- log() {
2783
- if (this.x == 0 && this.z == 0)
2784
- return new _Quaternion(log_hypot(this.w, this.x), Math.atan2(this.x, this.w));
2785
- const length = this.length(false);
2786
- const length2 = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
2787
- const scale = Math.atan2(length2, this.w) / length;
2788
- return new _Quaternion(Math.log(length) * 0.5, this.x * scale, this.y * scale, this.z * scale);
2812
+ multiply(...args) {
2813
+ if ((0, import_types15.isFixedTypeArray)(args, import_types15.isValidNumber, 1)) {
2814
+ const scalar = args[0];
2815
+ return new _Mat4([
2816
+ this.m00 * scalar,
2817
+ this.m01 * scalar,
2818
+ this.m02 * scalar,
2819
+ this.m03 * scalar,
2820
+ this.m10 * scalar,
2821
+ this.m11 * scalar,
2822
+ this.m12 * scalar,
2823
+ this.m13 * scalar,
2824
+ this.m20 * scalar,
2825
+ this.m21 * scalar,
2826
+ this.m22 * scalar,
2827
+ this.m23 * scalar,
2828
+ this.m30 * scalar,
2829
+ this.m31 * scalar,
2830
+ this.m32 * scalar,
2831
+ this.m33 * scalar
2832
+ ]);
2833
+ }
2834
+ const vec = Vec3.cast(args[0]);
2835
+ if (vec !== void 0) {
2836
+ const result = new Vec3(
2837
+ vec.x * this.m00 + vec.y * this.m10 + vec.z * this.m20 + this.m30,
2838
+ vec.x * this.m01 + vec.y * this.m11 + vec.z * this.m21 + this.m31,
2839
+ vec.x * this.m02 + vec.y * this.m12 + vec.z * this.m22 + this.m32,
2840
+ vec.x * this.m03 + vec.y * this.m13 + vec.z * this.m23 + this.m33
2841
+ );
2842
+ if (result.w != 0)
2843
+ return result.divide(result.w);
2844
+ return result;
2845
+ }
2846
+ const mat = _Mat4.resolveArgs(args);
2847
+ return new _Mat4([
2848
+ mat.m00 * this.m00 + mat.m01 * this.m10 + mat.m02 * this.m20 + mat.m03 * this.m30,
2849
+ mat.m00 * this.m01 + mat.m01 * this.m11 + mat.m02 * this.m21 + mat.m03 * this.m31,
2850
+ mat.m00 * this.m02 + mat.m01 * this.m12 + mat.m02 * this.m22 + mat.m03 * this.m32,
2851
+ mat.m00 * this.m03 + mat.m01 * this.m13 + mat.m02 * this.m23 + mat.m03 * this.m33,
2852
+ mat.m10 * this.m00 + mat.m11 * this.m10 + mat.m12 * this.m20 + mat.m13 * this.m30,
2853
+ mat.m10 * this.m01 + mat.m11 * this.m11 + mat.m12 * this.m21 + mat.m13 * this.m31,
2854
+ mat.m10 * this.m02 + mat.m11 * this.m12 + mat.m12 * this.m22 + mat.m13 * this.m32,
2855
+ mat.m10 * this.m03 + mat.m11 * this.m13 + mat.m12 * this.m23 + mat.m13 * this.m33,
2856
+ mat.m20 * this.m00 + mat.m21 * this.m10 + mat.m22 * this.m20 + mat.m23 * this.m30,
2857
+ mat.m20 * this.m01 + mat.m21 * this.m11 + mat.m22 * this.m21 + mat.m23 * this.m31,
2858
+ mat.m20 * this.m02 + mat.m21 * this.m12 + mat.m22 * this.m22 + mat.m23 * this.m32,
2859
+ mat.m20 * this.m03 + mat.m21 * this.m13 + mat.m22 * this.m23 + mat.m23 * this.m33,
2860
+ mat.m30 * this.m00 + mat.m31 * this.m10 + mat.m32 * this.m20 + mat.m33 * this.m30,
2861
+ mat.m30 * this.m01 + mat.m31 * this.m11 + mat.m32 * this.m21 + mat.m33 * this.m31,
2862
+ mat.m30 * this.m02 + mat.m31 * this.m12 + mat.m32 * this.m22 + mat.m33 * this.m32,
2863
+ mat.m30 * this.m03 + mat.m31 * this.m13 + mat.m32 * this.m23 + mat.m33 * this.m33
2864
+ ]);
2789
2865
  }
2790
- toVector() {
2791
- return new Vec3(this.x, this.y, this.z, this.w);
2866
+ translate(...args) {
2867
+ const vec = Vec3.resolveArgs(args);
2868
+ return this.multiply([
2869
+ 1,
2870
+ 0,
2871
+ 0,
2872
+ 0,
2873
+ 0,
2874
+ 1,
2875
+ 0,
2876
+ 0,
2877
+ 0,
2878
+ 0,
2879
+ 1,
2880
+ 0,
2881
+ vec.x,
2882
+ vec.y,
2883
+ vec.z,
2884
+ 1
2885
+ ]);
2792
2886
  }
2793
- toAxisAngle() {
2794
- const sin2 = 1 - this.w * this.w;
2795
- if (sin2 > EPSILON)
2796
- return new Vec3(this.x, this.y, this.z, 0);
2797
- const isin = 1 / Math.sqrt(sin2);
2798
- const angle = 2 * Math.acos(this.w);
2799
- return new Vec3(this.x * isin, this.y * isin, this.z * isin, angle);
2887
+ rotateX(angle) {
2888
+ const c = Math.cos(angle);
2889
+ const s = Math.sin(angle);
2890
+ return this.multiply([
2891
+ 1,
2892
+ 0,
2893
+ 0,
2894
+ 0,
2895
+ 0,
2896
+ c,
2897
+ s,
2898
+ 0,
2899
+ 0,
2900
+ -s,
2901
+ c,
2902
+ 0,
2903
+ 0,
2904
+ 0,
2905
+ 0,
2906
+ 1
2907
+ ]);
2800
2908
  }
2801
- toEuler() {
2802
- function asin(t) {
2803
- return t >= 1 ? Math.PI / 2 : t <= -1 ? -Math.PI / 2 : Math.asin(t);
2804
- }
2805
- return new Vec3(
2806
- -Math.atan2(2 * (this.y * this.z - this.w * this.x), 1 - 2 * (this.x * this.x + this.y * this.y)),
2807
- asin(2 * (this.x * this.z + this.w * this.y)),
2808
- -Math.atan2(2 * (this.x * this.y - this.w * this.z), 1 - 2 * (this.y * this.y + this.z * this.z))
2809
- );
2909
+ rotateY(angle) {
2910
+ const c = Math.cos(angle);
2911
+ const s = Math.sin(angle);
2912
+ return this.multiply([
2913
+ c,
2914
+ 0,
2915
+ -s,
2916
+ 0,
2917
+ 0,
2918
+ 1,
2919
+ 0,
2920
+ 0,
2921
+ s,
2922
+ 0,
2923
+ c,
2924
+ 0,
2925
+ 0,
2926
+ 0,
2927
+ 0,
2928
+ 1
2929
+ ]);
2810
2930
  }
2811
- toMat3() {
2812
- return new Mat3([
2813
- 1 - 2 * (this.y * this.y + this.z * this.z),
2814
- 2 * (this.x * this.y - this.w * this.z),
2815
- 2 * (this.x * this.z + this.w * this.y),
2816
- 2 * (this.x * this.y + this.w * this.z),
2817
- 1 - 2 * (this.x * this.x + this.z * this.z),
2818
- 2 * (this.y * this.z - this.w * this.x),
2819
- 2 * (this.x * this.z - this.w * this.y),
2820
- 2 * (this.y * this.z + this.w * this.x),
2821
- 1 - 2 * (this.x * this.x + this.y * this.y)
2931
+ rotateZ(angle) {
2932
+ const c = Math.cos(angle);
2933
+ const s = Math.sin(angle);
2934
+ return this.multiply([
2935
+ c,
2936
+ s,
2937
+ 0,
2938
+ 0,
2939
+ -s,
2940
+ c,
2941
+ 0,
2942
+ 0,
2943
+ 0,
2944
+ 0,
2945
+ 1,
2946
+ 0,
2947
+ 0,
2948
+ 0,
2949
+ 0,
2950
+ 1
2822
2951
  ]);
2823
2952
  }
2824
- toMat4() {
2825
- return new Mat4([
2826
- 1 - 2 * (this.y * this.y + this.z * this.z),
2827
- 2 * (this.x * this.y - this.w * this.z),
2828
- 2 * (this.x * this.z + this.w * this.y),
2953
+ rotate(...args) {
2954
+ const vec = Vec3.resolveArgs(args);
2955
+ return this.rotateX(vec.x).rotateY(vec.y).rotateZ(vec.z);
2956
+ }
2957
+ scale(...args) {
2958
+ const vec = Vec3.resolveArgs(args);
2959
+ return this.multiply([
2960
+ vec.x,
2829
2961
  0,
2830
- 2 * (this.x * this.y + this.w * this.z),
2831
- 1 - 2 * (this.x * this.x + this.z * this.z),
2832
- 2 * (this.y * this.z - this.w * this.x),
2833
2962
  0,
2834
- 2 * (this.x * this.z - this.w * this.y),
2835
- 2 * (this.y * this.z + this.w * this.x),
2836
- 1 - 2 * (this.x * this.x + this.y * this.y),
2837
2963
  0,
2838
2964
  0,
2965
+ vec.y,
2966
+ 0,
2967
+ 0,
2968
+ 0,
2969
+ 0,
2970
+ vec.z,
2971
+ 0,
2972
+ 0,
2973
+ 0,
2974
+ 0,
2975
+ 1
2976
+ ]);
2977
+ }
2978
+ inverse() {
2979
+ return new _Mat4([
2980
+ this.m00,
2981
+ this.m10,
2982
+ this.m20,
2983
+ 0,
2984
+ this.m01,
2985
+ this.m11,
2986
+ this.m21,
2839
2987
  0,
2988
+ this.m02,
2989
+ this.m12,
2990
+ this.m22,
2840
2991
  0,
2992
+ -(this.m30 * this.m00 + this.m31 * this.m10 + this.m32 * this.m20),
2993
+ -(this.m30 * this.m01 + this.m31 * this.m11 + this.m32 * this.m21),
2994
+ -(this.m30 * this.m02 + this.m31 * this.m12 + this.m32 * this.m22),
2841
2995
  1
2842
2996
  ]);
2843
2997
  }
2998
+ toMat3() {
2999
+ return [
3000
+ this.m00,
3001
+ this.m01,
3002
+ this.m03,
3003
+ this.m10,
3004
+ this.m11,
3005
+ this.m13,
3006
+ this.m30,
3007
+ this.m31,
3008
+ this.m33
3009
+ ];
3010
+ }
2844
3011
  };
2845
3012
 
3013
+ // source/color.ts
3014
+ var import_types16 = require("@ntf/types");
3015
+ var AnyColor;
3016
+ ((AnyColor2) => {
3017
+ function cast(a, preferHSL = false) {
3018
+ const results = [];
3019
+ try {
3020
+ const rgba = RGBA.resolve(a);
3021
+ results.push(rgba);
3022
+ } catch (e) {
3023
+ }
3024
+ try {
3025
+ const hsla = HSLA.resolve(a);
3026
+ results.push(hsla);
3027
+ } catch (e) {
3028
+ }
3029
+ let offset = preferHSL ? 1 : 0;
3030
+ const firstItem = results[offset];
3031
+ if (firstItem)
3032
+ return firstItem;
3033
+ const secondItem = results[offset + 1];
3034
+ if (secondItem)
3035
+ return secondItem;
3036
+ return void 0;
3037
+ }
3038
+ AnyColor2.cast = cast;
3039
+ function resolve(a, preferHSL = false) {
3040
+ const value = cast(a, preferHSL);
3041
+ if (typeof value != "undefined")
3042
+ return value;
3043
+ throw new ResolveError("Color", a);
3044
+ }
3045
+ AnyColor2.resolve = resolve;
3046
+ function resolveArgs(args, preferHSL = false) {
3047
+ if ((0, import_types16.isFixedTypeArray)(args, import_types16.isValidNumber, 3) || (0, import_types16.isFixedTypeArray)(args, import_types16.isValidNumber, 4))
3048
+ return resolve(args, preferHSL);
3049
+ return resolve(args[0], preferHSL);
3050
+ }
3051
+ AnyColor2.resolveArgs = resolveArgs;
3052
+ })(AnyColor || (AnyColor = {}));
3053
+
2846
3054
  // source/transform.ts
2847
- var Transform = class {
3055
+ var import_types17 = require("@ntf/types");
3056
+ var Transform2D = class {
3057
+ constructor(position, rotation, scale, parent) {
3058
+ this.parent = parent;
3059
+ (0, import_types17.checkValidNumber)(rotation);
3060
+ this.localPosition = Vec2.resolve(position);
3061
+ this.localRotation = rotation;
3062
+ this.localScale = Vec2.resolve(scale);
3063
+ }
3064
+ origin = Vec2.zero;
3065
+ localPosition;
3066
+ localRotation;
3067
+ get localRotationDegree() {
3068
+ return radianToDegree(this.localRotation);
3069
+ }
3070
+ set localRotationDegree(v) {
3071
+ this.localRotation = degreeToRadian(v);
3072
+ }
3073
+ localScale;
3074
+ get globalPosition() {
3075
+ let position = Vec2.zero;
3076
+ let transform = this;
3077
+ while (transform !== void 0) {
3078
+ position = position.add(transform.localPosition).add(transform.origin);
3079
+ transform = transform.parent;
3080
+ }
3081
+ return position;
3082
+ }
3083
+ get globalRotation() {
3084
+ let rotation = 0;
3085
+ let transform = this;
3086
+ while (transform !== void 0) {
3087
+ rotation += transform.localRotation;
3088
+ transform = transform.parent;
3089
+ }
3090
+ return rotation;
3091
+ }
3092
+ get globalRotationDegree() {
3093
+ return radianToDegree(this.globalRotation);
3094
+ }
3095
+ get globalScale() {
3096
+ let scale = Vec2.one;
3097
+ let transform = this;
3098
+ while (transform !== void 0) {
3099
+ scale = scale.naiveMultiply(transform.localScale);
3100
+ transform = transform.parent;
3101
+ }
3102
+ return scale;
3103
+ }
3104
+ toString() {
3105
+ return `${this.localPosition.toString()}|${this.localRotation}|${this.localScale.toString()}`;
3106
+ }
3107
+ get [Symbol.toStringTag]() {
3108
+ return "Transform2D";
3109
+ }
3110
+ [import_types17.NodeJSCustomInspect]() {
3111
+ return `Transform2D <${this.toString()}>`;
3112
+ }
3113
+ toMat3() {
3114
+ return new Mat3().scale(this.localScale).rotate(this.localRotation).translate(this.localPosition);
3115
+ }
3116
+ toGlobalMat3() {
3117
+ let result = new Mat3();
3118
+ let transform = this;
3119
+ while (transform !== void 0) {
3120
+ result = result.multiply(transform.toMat3());
3121
+ transform = transform.parent;
3122
+ }
3123
+ return result;
3124
+ }
3125
+ };
3126
+ var Transform3D = class {
2848
3127
  /**
2849
- * The position of the object
3128
+ * Create a new transform with `position`, `rotation` and `scale`
3129
+ * @param position The position as a Vec3
3130
+ * @param rotation The rotation as a Quaternion
3131
+ * @param scale The scale as a Vec3
2850
3132
  */
2851
- position;
3133
+ constructor(position, rotation, scale, parent) {
3134
+ this.parent = parent;
3135
+ this.localPosition = Vec3.resolve(position);
3136
+ this.localRotation = Quaternion.resolve(rotation);
3137
+ this.localScale = Vec3.resolve(scale);
3138
+ }
3139
+ origin = Vec3.zero;
2852
3140
  /**
2853
- * The rotation of the object
3141
+ * The local position
2854
3142
  */
2855
- rotation;
3143
+ localPosition;
2856
3144
  /**
2857
- * The scale of the object
3145
+ * The local rotation
2858
3146
  */
2859
- scale;
3147
+ localRotation;
2860
3148
  /**
2861
- * Create a new transform with `position`, `rotation` and `scale`
2862
- * @param position The position as a Vec3
2863
- * @param rotation The rotation as a Quaternion
2864
- * @param scale The scale as a Vec3
3149
+ * The local scale
2865
3150
  */
2866
- constructor(position, rotation, scale) {
2867
- this.position = Vec3.resolve(position);
2868
- this.rotation = Quaternion.resolve(rotation);
2869
- this.scale = Vec3.resolve(scale);
3151
+ localScale;
3152
+ get globalPosition() {
3153
+ let position = Vec3.zero;
3154
+ let transform = this;
3155
+ while (transform !== void 0) {
3156
+ position = position.add(transform.localPosition).add(transform.origin);
3157
+ transform = transform.parent;
3158
+ }
3159
+ return position;
3160
+ }
3161
+ get globalRotation() {
3162
+ let rotation = Quaternion.zero;
3163
+ let transform = this;
3164
+ while (transform !== void 0) {
3165
+ rotation = rotation.add(transform.localRotation);
3166
+ transform = transform.parent;
3167
+ }
3168
+ return rotation;
3169
+ }
3170
+ get globalScale() {
3171
+ let scale = Vec3.one;
3172
+ let transform = this;
3173
+ while (transform !== void 0) {
3174
+ scale = scale.naiveMultiply(transform.localScale);
3175
+ transform = transform.parent;
3176
+ }
3177
+ return scale;
3178
+ }
3179
+ toString() {
3180
+ return `${this.localPosition.toString()}|${this.localRotation.toString()}|${this.localScale.toString()}`;
3181
+ }
3182
+ get [Symbol.toStringTag]() {
3183
+ return "Transform2D";
3184
+ }
3185
+ [import_types17.NodeJSCustomInspect]() {
3186
+ return `Transform2D <${this.toString()}>`;
2870
3187
  }
2871
3188
  /**
2872
3189
  * Convert the transform into a 4x3 matrix
2873
3190
  * @returns A 4x4 matrix from the transform
2874
3191
  */
2875
3192
  toMat4() {
2876
- return new Mat4().translate(this.position).multiply(this.rotation.toMat4()).scale(this.scale);
3193
+ return new Mat4().scale(this.localScale).multiply(this.localRotation).translate(this.localPosition);
3194
+ }
3195
+ toGlobalMat4() {
3196
+ let result = new Mat4();
3197
+ let transform = this;
3198
+ while (transform !== void 0) {
3199
+ result = result.multiply(transform.toMat4());
3200
+ transform = transform.parent;
3201
+ }
3202
+ return result;
2877
3203
  }
2878
3204
  };