@minecraft/math 1.3.5 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/minecraft-math.js +319 -422
- package/dist/minecraft-math.js.map +3 -3
- package/lib/general/clamp.js +1 -5
- package/lib/general/clamp.js.map +1 -1
- package/lib/general/index.js +1 -17
- package/lib/general/index.js.map +1 -1
- package/lib/index.js +2 -18
- package/lib/index.js.map +1 -1
- package/lib/index.test.js +4 -6
- package/lib/index.test.js.map +1 -1
- package/lib/vector3/coreHelpers.js +18 -23
- package/lib/vector3/coreHelpers.js.map +1 -1
- package/lib/vector3/coreHelpers.test.js +111 -113
- package/lib/vector3/coreHelpers.test.js.map +1 -1
- package/lib/vector3/index.js +2 -18
- package/lib/vector3/index.js.map +1 -1
- package/lib/vector3/vectorWrapper.js +18 -23
- package/lib/vector3/vectorWrapper.js.map +1 -1
- package/lib/vector3/vectorWrapper.test.js +108 -110
- package/lib/vector3/vectorWrapper.test.js.map +1 -1
- package/package.json +3 -2
package/dist/minecraft-math.js
CHANGED
|
@@ -1,434 +1,331 @@
|
|
|
1
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
1
|
// lib/general/clamp.js
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.clampNumber = void 0;
|
|
12
|
-
function clampNumber(val, min, max) {
|
|
13
|
-
return Math.min(Math.max(val, min), max);
|
|
14
|
-
}
|
|
15
|
-
exports.clampNumber = clampNumber;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
2
|
+
function clampNumber(val, min, max) {
|
|
3
|
+
return Math.min(Math.max(val, min), max);
|
|
4
|
+
}
|
|
18
5
|
|
|
19
6
|
// lib/vector3/coreHelpers.js
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
*/
|
|
71
|
-
static cross(a, b) {
|
|
72
|
-
return {
|
|
73
|
-
x: a.y * b.z - a.z * b.y,
|
|
74
|
-
y: a.z * b.x - a.x * b.z,
|
|
75
|
-
z: a.x * b.y - a.y * b.x
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* magnitude
|
|
80
|
-
*
|
|
81
|
-
* The magnitude of a vector
|
|
82
|
-
*/
|
|
83
|
-
static magnitude(v) {
|
|
84
|
-
return Math.sqrt(v.x ** 2 + v.y ** 2 + v.z ** 2);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* distance
|
|
88
|
-
*
|
|
89
|
-
* Calculate the distance between two vectors
|
|
90
|
-
*/
|
|
91
|
-
static distance(a, b) {
|
|
92
|
-
return _Vector3Utils.magnitude(_Vector3Utils.subtract(a, b));
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* normalize
|
|
96
|
-
*
|
|
97
|
-
* Takes a vector 3 and normalizes it to a unit vector
|
|
98
|
-
*/
|
|
99
|
-
static normalize(v) {
|
|
100
|
-
const mag = _Vector3Utils.magnitude(v);
|
|
101
|
-
return { x: v.x / mag, y: v.y / mag, z: v.z / mag };
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* floor
|
|
105
|
-
*
|
|
106
|
-
* Floor the components of a vector to produce a new vector
|
|
107
|
-
*/
|
|
108
|
-
static floor(v) {
|
|
109
|
-
return { x: Math.floor(v.x), y: Math.floor(v.y), z: Math.floor(v.z) };
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* toString
|
|
113
|
-
*
|
|
114
|
-
* Create a string representation of a vector3
|
|
115
|
-
*/
|
|
116
|
-
static toString(v, options) {
|
|
117
|
-
const decimals = options?.decimals ?? 2;
|
|
118
|
-
const str = [v.x.toFixed(decimals), v.y.toFixed(decimals), v.z.toFixed(decimals)];
|
|
119
|
-
return str.join(options?.delimiter ?? ", ");
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* clamp
|
|
123
|
-
*
|
|
124
|
-
* Clamps the components of a vector to limits to produce a new vector
|
|
125
|
-
*/
|
|
126
|
-
static clamp(v, limits) {
|
|
127
|
-
return {
|
|
128
|
-
x: (0, clamp_1.clampNumber)(v.x, limits?.min?.x ?? Number.MIN_SAFE_INTEGER, limits?.max?.x ?? Number.MAX_SAFE_INTEGER),
|
|
129
|
-
y: (0, clamp_1.clampNumber)(v.y, limits?.min?.y ?? Number.MIN_SAFE_INTEGER, limits?.max?.y ?? Number.MAX_SAFE_INTEGER),
|
|
130
|
-
z: (0, clamp_1.clampNumber)(v.z, limits?.min?.z ?? Number.MIN_SAFE_INTEGER, limits?.max?.z ?? Number.MAX_SAFE_INTEGER)
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* lerp
|
|
135
|
-
*
|
|
136
|
-
* Constructs a new vector using linear interpolation on each component from two vectors.
|
|
137
|
-
*/
|
|
138
|
-
static lerp(a, b, t) {
|
|
139
|
-
return {
|
|
140
|
-
x: a.x + (b.x - a.x) * t,
|
|
141
|
-
y: a.y + (b.y - a.y) * t,
|
|
142
|
-
z: a.z + (b.z - a.z) * t
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* slerp
|
|
147
|
-
*
|
|
148
|
-
* Constructs a new vector using spherical linear interpolation on each component from two vectors.
|
|
149
|
-
*/
|
|
150
|
-
static slerp(a, b, t) {
|
|
151
|
-
const theta = Math.acos(_Vector3Utils.dot(a, b));
|
|
152
|
-
const sinTheta = Math.sin(theta);
|
|
153
|
-
const ta = Math.sin((1 - t) * theta) / sinTheta;
|
|
154
|
-
const tb = Math.sin(t * theta) / sinTheta;
|
|
155
|
-
return _Vector3Utils.add(_Vector3Utils.scale(a, ta), _Vector3Utils.scale(b, tb));
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
exports.Vector3Utils = Vector3Utils;
|
|
159
|
-
var Vector2Utils = class {
|
|
160
|
-
/**
|
|
161
|
-
* toString
|
|
162
|
-
*
|
|
163
|
-
* Create a string representation of a vector2
|
|
164
|
-
*/
|
|
165
|
-
static toString(v, options) {
|
|
166
|
-
const decimals = options?.decimals ?? 2;
|
|
167
|
-
const str = [v.x.toFixed(decimals), v.y.toFixed(decimals)];
|
|
168
|
-
return str.join(options?.delimiter ?? ", ");
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
exports.Vector2Utils = Vector2Utils;
|
|
172
|
-
exports.VECTOR3_UP = { x: 0, y: 1, z: 0 };
|
|
173
|
-
exports.VECTOR3_DOWN = { x: 0, y: -1, z: 0 };
|
|
174
|
-
exports.VECTOR3_LEFT = { x: -1, y: 0, z: 0 };
|
|
175
|
-
exports.VECTOR3_RIGHT = { x: 1, y: 0, z: 0 };
|
|
176
|
-
exports.VECTOR3_FORWARD = { x: 0, y: 0, z: 1 };
|
|
177
|
-
exports.VECTOR3_BACK = { x: 0, y: 0, z: -1 };
|
|
178
|
-
exports.VECTOR3_ONE = { x: 1, y: 1, z: 1 };
|
|
179
|
-
exports.VECTOR3_ZERO = { x: 0, y: 0, z: 0 };
|
|
180
|
-
exports.VECTOR3_WEST = { x: -1, y: 0, z: 0 };
|
|
181
|
-
exports.VECTOR3_EAST = { x: 1, y: 0, z: 0 };
|
|
182
|
-
exports.VECTOR3_NORTH = { x: 0, y: 0, z: 1 };
|
|
183
|
-
exports.VECTOR3_SOUTH = { x: 0, y: 0, z: -1 };
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
// lib/vector3/vectorWrapper.js
|
|
188
|
-
var require_vectorWrapper = __commonJS({
|
|
189
|
-
"lib/vector3/vectorWrapper.js"(exports) {
|
|
190
|
-
"use strict";
|
|
191
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
192
|
-
exports.Vector2Builder = exports.Vector3Builder = void 0;
|
|
193
|
-
var coreHelpers_1 = require_coreHelpers();
|
|
194
|
-
var Vector3Builder = class {
|
|
195
|
-
constructor(first, y, z) {
|
|
196
|
-
if (typeof first === "object") {
|
|
197
|
-
this.x = first.x;
|
|
198
|
-
this.y = first.y;
|
|
199
|
-
this.z = first.z;
|
|
200
|
-
} else {
|
|
201
|
-
this.x = first;
|
|
202
|
-
this.y = y ?? 0;
|
|
203
|
-
this.z = z ?? 0;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Assigns the values of the passed in vector to this vector. Returns itself.
|
|
208
|
-
*/
|
|
209
|
-
assign(vec) {
|
|
210
|
-
this.x = vec.x;
|
|
211
|
-
this.y = vec.y;
|
|
212
|
-
this.z = vec.z;
|
|
213
|
-
return this;
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* equals
|
|
217
|
-
*
|
|
218
|
-
* Check the equality of two vectors
|
|
219
|
-
*/
|
|
220
|
-
equals(v) {
|
|
221
|
-
return coreHelpers_1.Vector3Utils.equals(this, v);
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* add
|
|
225
|
-
*
|
|
226
|
-
* Adds the vector v to this, returning itself.
|
|
227
|
-
*/
|
|
228
|
-
add(v) {
|
|
229
|
-
return this.assign(coreHelpers_1.Vector3Utils.add(this, v));
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* subtract
|
|
233
|
-
*
|
|
234
|
-
* Subtracts the vector v from this, returning itself.
|
|
235
|
-
*/
|
|
236
|
-
subtract(v) {
|
|
237
|
-
return this.assign(coreHelpers_1.Vector3Utils.subtract(this, v));
|
|
238
|
-
}
|
|
239
|
-
/** scale
|
|
240
|
-
*
|
|
241
|
-
* Scales this by the passed in value, returning itself.
|
|
242
|
-
*/
|
|
243
|
-
scale(val) {
|
|
244
|
-
return this.assign(coreHelpers_1.Vector3Utils.scale(this, val));
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* dot
|
|
248
|
-
*
|
|
249
|
-
* Computes the dot product of this and the passed in vector.
|
|
250
|
-
*/
|
|
251
|
-
dot(vec) {
|
|
252
|
-
return coreHelpers_1.Vector3Utils.dot(this, vec);
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* cross
|
|
256
|
-
*
|
|
257
|
-
* Computes the cross product of this and the passed in vector, returning itself.
|
|
258
|
-
*/
|
|
259
|
-
cross(vec) {
|
|
260
|
-
return this.assign(coreHelpers_1.Vector3Utils.cross(this, vec));
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* magnitude
|
|
264
|
-
*
|
|
265
|
-
* The magnitude of the vector
|
|
266
|
-
*/
|
|
267
|
-
magnitude() {
|
|
268
|
-
return coreHelpers_1.Vector3Utils.magnitude(this);
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* distance
|
|
272
|
-
*
|
|
273
|
-
* Calculate the distance between two vectors
|
|
274
|
-
*/
|
|
275
|
-
distance(vec) {
|
|
276
|
-
return coreHelpers_1.Vector3Utils.distance(this, vec);
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* normalize
|
|
280
|
-
*
|
|
281
|
-
* Normalizes this vector, returning itself.
|
|
282
|
-
*/
|
|
283
|
-
normalize() {
|
|
284
|
-
return this.assign(coreHelpers_1.Vector3Utils.normalize(this));
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* floor
|
|
288
|
-
*
|
|
289
|
-
* Floor the components of a vector to produce a new vector
|
|
290
|
-
*/
|
|
291
|
-
floor() {
|
|
292
|
-
return this.assign(coreHelpers_1.Vector3Utils.floor(this));
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* toString
|
|
296
|
-
*
|
|
297
|
-
* Create a string representation of a vector
|
|
298
|
-
*/
|
|
299
|
-
toString(options) {
|
|
300
|
-
return coreHelpers_1.Vector3Utils.toString(this, options);
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* clamp
|
|
304
|
-
*
|
|
305
|
-
* Clamps the components of a vector to limits to produce a new vector
|
|
306
|
-
*/
|
|
307
|
-
clamp(limits) {
|
|
308
|
-
return this.assign(coreHelpers_1.Vector3Utils.clamp(this, limits));
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* lerp
|
|
312
|
-
*
|
|
313
|
-
* Constructs a new vector using linear interpolation on each component from two vectors.
|
|
314
|
-
*/
|
|
315
|
-
lerp(vec, t) {
|
|
316
|
-
return this.assign(coreHelpers_1.Vector3Utils.lerp(this, vec, t));
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* slerp
|
|
320
|
-
*
|
|
321
|
-
* Constructs a new vector using spherical linear interpolation on each component from two vectors.
|
|
322
|
-
*/
|
|
323
|
-
slerp(vec, t) {
|
|
324
|
-
return this.assign(coreHelpers_1.Vector3Utils.slerp(this, vec, t));
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
exports.Vector3Builder = Vector3Builder;
|
|
328
|
-
var Vector2Builder = class {
|
|
329
|
-
constructor(first, y) {
|
|
330
|
-
if (typeof first === "object") {
|
|
331
|
-
this.x = first.x;
|
|
332
|
-
this.y = first.y;
|
|
333
|
-
} else {
|
|
334
|
-
this.x = first;
|
|
335
|
-
this.y = y ?? 0;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
toString(options) {
|
|
339
|
-
return coreHelpers_1.Vector2Utils.toString(this, options);
|
|
340
|
-
}
|
|
7
|
+
var Vector3Utils = class _Vector3Utils {
|
|
8
|
+
/**
|
|
9
|
+
* equals
|
|
10
|
+
*
|
|
11
|
+
* Check the equality of two vectors
|
|
12
|
+
*/
|
|
13
|
+
static equals(v1, v2) {
|
|
14
|
+
return v1.x === v2.x && v1.y === v2.y && v1.z === v2.z;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* add
|
|
18
|
+
*
|
|
19
|
+
* Add two vectors to produce a new vector
|
|
20
|
+
*/
|
|
21
|
+
static add(v1, v2) {
|
|
22
|
+
return { x: v1.x + v2.x, y: v1.y + v2.y, z: v1.z + v2.z };
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* subtract
|
|
26
|
+
*
|
|
27
|
+
* Subtract two vectors to produce a new vector (v1-v2)
|
|
28
|
+
*/
|
|
29
|
+
static subtract(v1, v2) {
|
|
30
|
+
return { x: v1.x - v2.x, y: v1.y - v2.y, z: v1.z - v2.z };
|
|
31
|
+
}
|
|
32
|
+
/** scale
|
|
33
|
+
*
|
|
34
|
+
* Multiple all entries in a vector by a single scalar value producing a new vector
|
|
35
|
+
*/
|
|
36
|
+
static scale(v1, scale) {
|
|
37
|
+
return { x: v1.x * scale, y: v1.y * scale, z: v1.z * scale };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* dot
|
|
41
|
+
*
|
|
42
|
+
* Calculate the dot product of two vectors
|
|
43
|
+
*/
|
|
44
|
+
static dot(a, b) {
|
|
45
|
+
return a.x * b.x + a.y * b.y + a.z * b.z;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* cross
|
|
49
|
+
*
|
|
50
|
+
* Calculate the cross product of two vectors. Returns a new vector.
|
|
51
|
+
*/
|
|
52
|
+
static cross(a, b) {
|
|
53
|
+
return {
|
|
54
|
+
x: a.y * b.z - a.z * b.y,
|
|
55
|
+
y: a.z * b.x - a.x * b.z,
|
|
56
|
+
z: a.x * b.y - a.y * b.x
|
|
341
57
|
};
|
|
342
|
-
exports.Vector2Builder = Vector2Builder;
|
|
343
58
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
59
|
+
/**
|
|
60
|
+
* magnitude
|
|
61
|
+
*
|
|
62
|
+
* The magnitude of a vector
|
|
63
|
+
*/
|
|
64
|
+
static magnitude(v) {
|
|
65
|
+
return Math.sqrt(v.x ** 2 + v.y ** 2 + v.z ** 2);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* distance
|
|
69
|
+
*
|
|
70
|
+
* Calculate the distance between two vectors
|
|
71
|
+
*/
|
|
72
|
+
static distance(a, b) {
|
|
73
|
+
return _Vector3Utils.magnitude(_Vector3Utils.subtract(a, b));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* normalize
|
|
77
|
+
*
|
|
78
|
+
* Takes a vector 3 and normalizes it to a unit vector
|
|
79
|
+
*/
|
|
80
|
+
static normalize(v) {
|
|
81
|
+
const mag = _Vector3Utils.magnitude(v);
|
|
82
|
+
return { x: v.x / mag, y: v.y / mag, z: v.z / mag };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* floor
|
|
86
|
+
*
|
|
87
|
+
* Floor the components of a vector to produce a new vector
|
|
88
|
+
*/
|
|
89
|
+
static floor(v) {
|
|
90
|
+
return { x: Math.floor(v.x), y: Math.floor(v.y), z: Math.floor(v.z) };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* toString
|
|
94
|
+
*
|
|
95
|
+
* Create a string representation of a vector3
|
|
96
|
+
*/
|
|
97
|
+
static toString(v, options) {
|
|
98
|
+
const decimals = options?.decimals ?? 2;
|
|
99
|
+
const str = [v.x.toFixed(decimals), v.y.toFixed(decimals), v.z.toFixed(decimals)];
|
|
100
|
+
return str.join(options?.delimiter ?? ", ");
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* clamp
|
|
104
|
+
*
|
|
105
|
+
* Clamps the components of a vector to limits to produce a new vector
|
|
106
|
+
*/
|
|
107
|
+
static clamp(v, limits) {
|
|
108
|
+
return {
|
|
109
|
+
x: clampNumber(v.x, limits?.min?.x ?? Number.MIN_SAFE_INTEGER, limits?.max?.x ?? Number.MAX_SAFE_INTEGER),
|
|
110
|
+
y: clampNumber(v.y, limits?.min?.y ?? Number.MIN_SAFE_INTEGER, limits?.max?.y ?? Number.MAX_SAFE_INTEGER),
|
|
111
|
+
z: clampNumber(v.z, limits?.min?.z ?? Number.MIN_SAFE_INTEGER, limits?.max?.z ?? Number.MAX_SAFE_INTEGER)
|
|
369
112
|
};
|
|
370
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
371
|
-
__exportStar(require_coreHelpers(), exports);
|
|
372
|
-
__exportStar(require_vectorWrapper(), exports);
|
|
373
113
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
385
|
-
desc = { enumerable: true, get: function() {
|
|
386
|
-
return m[k];
|
|
387
|
-
} };
|
|
388
|
-
}
|
|
389
|
-
Object.defineProperty(o, k2, desc);
|
|
390
|
-
} : function(o, m, k, k2) {
|
|
391
|
-
if (k2 === void 0)
|
|
392
|
-
k2 = k;
|
|
393
|
-
o[k2] = m[k];
|
|
394
|
-
});
|
|
395
|
-
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
396
|
-
for (var p in m)
|
|
397
|
-
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
398
|
-
__createBinding(exports2, m, p);
|
|
114
|
+
/**
|
|
115
|
+
* lerp
|
|
116
|
+
*
|
|
117
|
+
* Constructs a new vector using linear interpolation on each component from two vectors.
|
|
118
|
+
*/
|
|
119
|
+
static lerp(a, b, t) {
|
|
120
|
+
return {
|
|
121
|
+
x: a.x + (b.x - a.x) * t,
|
|
122
|
+
y: a.y + (b.y - a.y) * t,
|
|
123
|
+
z: a.z + (b.z - a.z) * t
|
|
399
124
|
};
|
|
400
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
401
|
-
__exportStar(require_clamp(), exports);
|
|
402
125
|
}
|
|
403
|
-
|
|
126
|
+
/**
|
|
127
|
+
* slerp
|
|
128
|
+
*
|
|
129
|
+
* Constructs a new vector using spherical linear interpolation on each component from two vectors.
|
|
130
|
+
*/
|
|
131
|
+
static slerp(a, b, t) {
|
|
132
|
+
const theta = Math.acos(_Vector3Utils.dot(a, b));
|
|
133
|
+
const sinTheta = Math.sin(theta);
|
|
134
|
+
const ta = Math.sin((1 - t) * theta) / sinTheta;
|
|
135
|
+
const tb = Math.sin(t * theta) / sinTheta;
|
|
136
|
+
return _Vector3Utils.add(_Vector3Utils.scale(a, ta), _Vector3Utils.scale(b, tb));
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var Vector2Utils = class {
|
|
140
|
+
/**
|
|
141
|
+
* toString
|
|
142
|
+
*
|
|
143
|
+
* Create a string representation of a vector2
|
|
144
|
+
*/
|
|
145
|
+
static toString(v, options) {
|
|
146
|
+
const decimals = options?.decimals ?? 2;
|
|
147
|
+
const str = [v.x.toFixed(decimals), v.y.toFixed(decimals)];
|
|
148
|
+
return str.join(options?.delimiter ?? ", ");
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
var VECTOR3_UP = { x: 0, y: 1, z: 0 };
|
|
152
|
+
var VECTOR3_DOWN = { x: 0, y: -1, z: 0 };
|
|
153
|
+
var VECTOR3_LEFT = { x: -1, y: 0, z: 0 };
|
|
154
|
+
var VECTOR3_RIGHT = { x: 1, y: 0, z: 0 };
|
|
155
|
+
var VECTOR3_FORWARD = { x: 0, y: 0, z: 1 };
|
|
156
|
+
var VECTOR3_BACK = { x: 0, y: 0, z: -1 };
|
|
157
|
+
var VECTOR3_ONE = { x: 1, y: 1, z: 1 };
|
|
158
|
+
var VECTOR3_ZERO = { x: 0, y: 0, z: 0 };
|
|
159
|
+
var VECTOR3_WEST = { x: -1, y: 0, z: 0 };
|
|
160
|
+
var VECTOR3_EAST = { x: 1, y: 0, z: 0 };
|
|
161
|
+
var VECTOR3_NORTH = { x: 0, y: 0, z: 1 };
|
|
162
|
+
var VECTOR3_SOUTH = { x: 0, y: 0, z: -1 };
|
|
404
163
|
|
|
405
|
-
// lib/
|
|
406
|
-
var
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
164
|
+
// lib/vector3/vectorWrapper.js
|
|
165
|
+
var Vector3Builder = class {
|
|
166
|
+
constructor(first, y, z) {
|
|
167
|
+
if (typeof first === "object") {
|
|
168
|
+
this.x = first.x;
|
|
169
|
+
this.y = first.y;
|
|
170
|
+
this.z = first.z;
|
|
171
|
+
} else {
|
|
172
|
+
this.x = first;
|
|
173
|
+
this.y = y ?? 0;
|
|
174
|
+
this.z = z ?? 0;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Assigns the values of the passed in vector to this vector. Returns itself.
|
|
179
|
+
*/
|
|
180
|
+
assign(vec) {
|
|
181
|
+
this.x = vec.x;
|
|
182
|
+
this.y = vec.y;
|
|
183
|
+
this.z = vec.z;
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* equals
|
|
188
|
+
*
|
|
189
|
+
* Check the equality of two vectors
|
|
190
|
+
*/
|
|
191
|
+
equals(v) {
|
|
192
|
+
return Vector3Utils.equals(this, v);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* add
|
|
196
|
+
*
|
|
197
|
+
* Adds the vector v to this, returning itself.
|
|
198
|
+
*/
|
|
199
|
+
add(v) {
|
|
200
|
+
return this.assign(Vector3Utils.add(this, v));
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* subtract
|
|
204
|
+
*
|
|
205
|
+
* Subtracts the vector v from this, returning itself.
|
|
206
|
+
*/
|
|
207
|
+
subtract(v) {
|
|
208
|
+
return this.assign(Vector3Utils.subtract(this, v));
|
|
209
|
+
}
|
|
210
|
+
/** scale
|
|
211
|
+
*
|
|
212
|
+
* Scales this by the passed in value, returning itself.
|
|
213
|
+
*/
|
|
214
|
+
scale(val) {
|
|
215
|
+
return this.assign(Vector3Utils.scale(this, val));
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* dot
|
|
219
|
+
*
|
|
220
|
+
* Computes the dot product of this and the passed in vector.
|
|
221
|
+
*/
|
|
222
|
+
dot(vec) {
|
|
223
|
+
return Vector3Utils.dot(this, vec);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* cross
|
|
227
|
+
*
|
|
228
|
+
* Computes the cross product of this and the passed in vector, returning itself.
|
|
229
|
+
*/
|
|
230
|
+
cross(vec) {
|
|
231
|
+
return this.assign(Vector3Utils.cross(this, vec));
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* magnitude
|
|
235
|
+
*
|
|
236
|
+
* The magnitude of the vector
|
|
237
|
+
*/
|
|
238
|
+
magnitude() {
|
|
239
|
+
return Vector3Utils.magnitude(this);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* distance
|
|
243
|
+
*
|
|
244
|
+
* Calculate the distance between two vectors
|
|
245
|
+
*/
|
|
246
|
+
distance(vec) {
|
|
247
|
+
return Vector3Utils.distance(this, vec);
|
|
431
248
|
}
|
|
432
|
-
|
|
433
|
-
|
|
249
|
+
/**
|
|
250
|
+
* normalize
|
|
251
|
+
*
|
|
252
|
+
* Normalizes this vector, returning itself.
|
|
253
|
+
*/
|
|
254
|
+
normalize() {
|
|
255
|
+
return this.assign(Vector3Utils.normalize(this));
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* floor
|
|
259
|
+
*
|
|
260
|
+
* Floor the components of a vector to produce a new vector
|
|
261
|
+
*/
|
|
262
|
+
floor() {
|
|
263
|
+
return this.assign(Vector3Utils.floor(this));
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* toString
|
|
267
|
+
*
|
|
268
|
+
* Create a string representation of a vector
|
|
269
|
+
*/
|
|
270
|
+
toString(options) {
|
|
271
|
+
return Vector3Utils.toString(this, options);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* clamp
|
|
275
|
+
*
|
|
276
|
+
* Clamps the components of a vector to limits to produce a new vector
|
|
277
|
+
*/
|
|
278
|
+
clamp(limits) {
|
|
279
|
+
return this.assign(Vector3Utils.clamp(this, limits));
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* lerp
|
|
283
|
+
*
|
|
284
|
+
* Constructs a new vector using linear interpolation on each component from two vectors.
|
|
285
|
+
*/
|
|
286
|
+
lerp(vec, t) {
|
|
287
|
+
return this.assign(Vector3Utils.lerp(this, vec, t));
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* slerp
|
|
291
|
+
*
|
|
292
|
+
* Constructs a new vector using spherical linear interpolation on each component from two vectors.
|
|
293
|
+
*/
|
|
294
|
+
slerp(vec, t) {
|
|
295
|
+
return this.assign(Vector3Utils.slerp(this, vec, t));
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
var Vector2Builder = class {
|
|
299
|
+
constructor(first, y) {
|
|
300
|
+
if (typeof first === "object") {
|
|
301
|
+
this.x = first.x;
|
|
302
|
+
this.y = first.y;
|
|
303
|
+
} else {
|
|
304
|
+
this.x = first;
|
|
305
|
+
this.y = y ?? 0;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
toString(options) {
|
|
309
|
+
return Vector2Utils.toString(this, options);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
export {
|
|
313
|
+
VECTOR3_BACK,
|
|
314
|
+
VECTOR3_DOWN,
|
|
315
|
+
VECTOR3_EAST,
|
|
316
|
+
VECTOR3_FORWARD,
|
|
317
|
+
VECTOR3_LEFT,
|
|
318
|
+
VECTOR3_NORTH,
|
|
319
|
+
VECTOR3_ONE,
|
|
320
|
+
VECTOR3_RIGHT,
|
|
321
|
+
VECTOR3_SOUTH,
|
|
322
|
+
VECTOR3_UP,
|
|
323
|
+
VECTOR3_WEST,
|
|
324
|
+
VECTOR3_ZERO,
|
|
325
|
+
Vector2Builder,
|
|
326
|
+
Vector2Utils,
|
|
327
|
+
Vector3Builder,
|
|
328
|
+
Vector3Utils,
|
|
329
|
+
clampNumber
|
|
330
|
+
};
|
|
434
331
|
//# sourceMappingURL=minecraft-math.js.map
|