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