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