@minecraft/math 1.5.2 → 2.0.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.
@@ -1,516 +1,430 @@
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
- var require_clamp = __commonJS({
8
- "lib/general/clamp.js"(exports) {
9
- "use strict";
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 require_coreHelpers = __commonJS({
21
- "lib/vector3/coreHelpers.js"(exports) {
22
- "use strict";
23
- Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.VECTOR3_SOUTH = exports.VECTOR3_NORTH = exports.VECTOR3_EAST = exports.VECTOR3_WEST = exports.VECTOR3_ZERO = exports.VECTOR3_ONE = exports.VECTOR3_BACK = exports.VECTOR3_FORWARD = exports.VECTOR3_RIGHT = exports.VECTOR3_LEFT = exports.VECTOR3_DOWN = exports.VECTOR3_UP = exports.Vector2Utils = exports.Vector3Utils = void 0;
25
- var clamp_1 = require_clamp();
26
- var Vector3Utils = class _Vector3Utils {
27
- /**
28
- * equals
29
- *
30
- * Check the equality of two vectors
31
- */
32
- static equals(v1, v2) {
33
- return v1.x === v2.x && v1.y === v2.y && v1.z === v2.z;
34
- }
35
- /**
36
- * add
37
- *
38
- * Add two vectors to produce a new vector
39
- */
40
- static add(v1, v2) {
41
- return { x: v1.x + v2.x, y: v1.y + v2.y, z: v1.z + v2.z };
42
- }
43
- /**
44
- * subtract
45
- *
46
- * Subtract two vectors to produce a new vector (v1-v2)
47
- */
48
- static subtract(v1, v2) {
49
- return { x: v1.x - v2.x, y: v1.y - v2.y, z: v1.z - v2.z };
50
- }
51
- /** scale
52
- *
53
- * Multiple all entries in a vector by a single scalar value producing a new vector
54
- */
55
- static scale(v1, scale) {
56
- return { x: v1.x * scale, y: v1.y * scale, z: v1.z * scale };
57
- }
58
- /**
59
- * dot
60
- *
61
- * Calculate the dot product of two vectors
62
- */
63
- static dot(a, b) {
64
- return a.x * b.x + a.y * b.y + a.z * b.z;
65
- }
66
- /**
67
- * cross
68
- *
69
- * Calculate the cross product of two vectors. Returns a new vector.
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
- * multiply
159
- *
160
- * Element-wise multiplication of two vectors together.
161
- * Not to be confused with {@link Vector3Utils.dot} product or {@link Vector3Utils.cross} product
162
- */
163
- static multiply(a, b) {
164
- return {
165
- x: a.x * b.x,
166
- y: a.y * b.y,
167
- z: a.z * b.z
168
- };
169
- }
170
- /**
171
- * rotateX
172
- *
173
- * Rotates the vector around the x axis counterclockwise (left hand rule)
174
- * @param a - Angle in radians
175
- */
176
- static rotateX(v, a) {
177
- let cos = Math.cos(a);
178
- let sin = Math.sin(a);
179
- return {
180
- x: v.x,
181
- y: v.y * cos - v.z * sin,
182
- z: v.z * cos + v.y * sin
183
- };
184
- }
185
- /**
186
- * rotateY
187
- *
188
- * Rotates the vector around the y axis counterclockwise (left hand rule)
189
- * @param a - Angle in radians
190
- */
191
- static rotateY(v, a) {
192
- let cos = Math.cos(a);
193
- let sin = Math.sin(a);
194
- return {
195
- x: v.x * cos + v.z * sin,
196
- y: v.y,
197
- z: v.z * cos - v.x * sin
198
- };
199
- }
200
- /**
201
- * rotateZ
202
- *
203
- * Rotates the vector around the z axis counterclockwise (left hand rule)
204
- * @param a - Angle in radians
205
- */
206
- static rotateZ(v, a) {
207
- let cos = Math.cos(a);
208
- let sin = Math.sin(a);
209
- return {
210
- x: v.x * cos - v.y * sin,
211
- y: v.y * cos + v.x * sin,
212
- z: v.z
213
- };
214
- }
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
215
57
  };
216
- exports.Vector3Utils = Vector3Utils;
217
- var Vector2Utils = class {
218
- /**
219
- * toString
220
- *
221
- * Create a string representation of a vector2
222
- */
223
- static toString(v, options) {
224
- const decimals = options?.decimals ?? 2;
225
- const str = [v.x.toFixed(decimals), v.y.toFixed(decimals)];
226
- return str.join(options?.delimiter ?? ", ");
227
- }
58
+ }
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)
228
112
  };
229
- exports.Vector2Utils = Vector2Utils;
230
- exports.VECTOR3_UP = { x: 0, y: 1, z: 0 };
231
- exports.VECTOR3_DOWN = { x: 0, y: -1, z: 0 };
232
- exports.VECTOR3_LEFT = { x: -1, y: 0, z: 0 };
233
- exports.VECTOR3_RIGHT = { x: 1, y: 0, z: 0 };
234
- exports.VECTOR3_FORWARD = { x: 0, y: 0, z: 1 };
235
- exports.VECTOR3_BACK = { x: 0, y: 0, z: -1 };
236
- exports.VECTOR3_ONE = { x: 1, y: 1, z: 1 };
237
- exports.VECTOR3_ZERO = { x: 0, y: 0, z: 0 };
238
- exports.VECTOR3_WEST = { x: -1, y: 0, z: 0 };
239
- exports.VECTOR3_EAST = { x: 1, y: 0, z: 0 };
240
- exports.VECTOR3_NORTH = { x: 0, y: 0, z: 1 };
241
- exports.VECTOR3_SOUTH = { x: 0, y: 0, z: -1 };
242
- }
243
- });
244
-
245
- // lib/vector3/vectorWrapper.js
246
- var require_vectorWrapper = __commonJS({
247
- "lib/vector3/vectorWrapper.js"(exports) {
248
- "use strict";
249
- Object.defineProperty(exports, "__esModule", { value: true });
250
- exports.Vector2Builder = exports.Vector3Builder = void 0;
251
- var coreHelpers_1 = require_coreHelpers();
252
- var Vector3Builder = class {
253
- constructor(first, y, z) {
254
- if (typeof first === "object") {
255
- this.x = first.x;
256
- this.y = first.y;
257
- this.z = first.z;
258
- } else {
259
- this.x = first;
260
- this.y = y ?? 0;
261
- this.z = z ?? 0;
262
- }
263
- }
264
- /**
265
- * Assigns the values of the passed in vector to this vector. Returns itself.
266
- */
267
- assign(vec) {
268
- this.x = vec.x;
269
- this.y = vec.y;
270
- this.z = vec.z;
271
- return this;
272
- }
273
- /**
274
- * equals
275
- *
276
- * Check the equality of two vectors
277
- */
278
- equals(v) {
279
- return coreHelpers_1.Vector3Utils.equals(this, v);
280
- }
281
- /**
282
- * add
283
- *
284
- * Adds the vector v to this, returning itself.
285
- */
286
- add(v) {
287
- return this.assign(coreHelpers_1.Vector3Utils.add(this, v));
288
- }
289
- /**
290
- * subtract
291
- *
292
- * Subtracts the vector v from this, returning itself.
293
- */
294
- subtract(v) {
295
- return this.assign(coreHelpers_1.Vector3Utils.subtract(this, v));
296
- }
297
- /** scale
298
- *
299
- * Scales this by the passed in value, returning itself.
300
- */
301
- scale(val) {
302
- return this.assign(coreHelpers_1.Vector3Utils.scale(this, val));
303
- }
304
- /**
305
- * dot
306
- *
307
- * Computes the dot product of this and the passed in vector.
308
- */
309
- dot(vec) {
310
- return coreHelpers_1.Vector3Utils.dot(this, vec);
311
- }
312
- /**
313
- * cross
314
- *
315
- * Computes the cross product of this and the passed in vector, returning itself.
316
- */
317
- cross(vec) {
318
- return this.assign(coreHelpers_1.Vector3Utils.cross(this, vec));
319
- }
320
- /**
321
- * magnitude
322
- *
323
- * The magnitude of the vector
324
- */
325
- magnitude() {
326
- return coreHelpers_1.Vector3Utils.magnitude(this);
327
- }
328
- /**
329
- * distance
330
- *
331
- * Calculate the distance between two vectors
332
- */
333
- distance(vec) {
334
- return coreHelpers_1.Vector3Utils.distance(this, vec);
335
- }
336
- /**
337
- * normalize
338
- *
339
- * Normalizes this vector, returning itself.
340
- */
341
- normalize() {
342
- return this.assign(coreHelpers_1.Vector3Utils.normalize(this));
343
- }
344
- /**
345
- * floor
346
- *
347
- * Floor the components of a vector to produce a new vector
348
- */
349
- floor() {
350
- return this.assign(coreHelpers_1.Vector3Utils.floor(this));
351
- }
352
- /**
353
- * toString
354
- *
355
- * Create a string representation of a vector
356
- */
357
- toString(options) {
358
- return coreHelpers_1.Vector3Utils.toString(this, options);
359
- }
360
- /**
361
- * clamp
362
- *
363
- * Clamps the components of a vector to limits to produce a new vector
364
- */
365
- clamp(limits) {
366
- return this.assign(coreHelpers_1.Vector3Utils.clamp(this, limits));
367
- }
368
- /**
369
- * lerp
370
- *
371
- * Constructs a new vector using linear interpolation on each component from two vectors.
372
- */
373
- lerp(vec, t) {
374
- return this.assign(coreHelpers_1.Vector3Utils.lerp(this, vec, t));
375
- }
376
- /**
377
- * slerp
378
- *
379
- * Constructs a new vector using spherical linear interpolation on each component from two vectors.
380
- */
381
- slerp(vec, t) {
382
- return this.assign(coreHelpers_1.Vector3Utils.slerp(this, vec, t));
383
- }
384
- /**
385
- * multiply
386
- *
387
- * Element-wise multiplication of two vectors together.
388
- * Not to be confused with {@link Vector3Builder.dot} product or {@link Vector3Builder.cross} product
389
- */
390
- multiply(vec) {
391
- return this.assign(coreHelpers_1.Vector3Utils.multiply(this, vec));
392
- }
393
- /**
394
- * rotateX
395
- *
396
- * Rotates the vector around the x axis counterclockwise (left hand rule)
397
- * @param a - Angle in radians
398
- */
399
- rotateX(a) {
400
- return this.assign(coreHelpers_1.Vector3Utils.rotateX(this, a));
401
- }
402
- /**
403
- * rotateY
404
- *
405
- * Rotates the vector around the y axis counterclockwise (left hand rule)
406
- * @param a - Angle in radians
407
- */
408
- rotateY(a) {
409
- return this.assign(coreHelpers_1.Vector3Utils.rotateY(this, a));
410
- }
411
- /**
412
- * rotateZ
413
- *
414
- * Rotates the vector around the z axis counterclockwise (left hand rule)
415
- * @param a - Angle in radians
416
- */
417
- rotateZ(a) {
418
- return this.assign(coreHelpers_1.Vector3Utils.rotateZ(this, a));
419
- }
113
+ }
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
420
124
  };
421
- exports.Vector3Builder = Vector3Builder;
422
- var Vector2Builder = class {
423
- constructor(first, y) {
424
- if (typeof first === "object") {
425
- this.x = first.x;
426
- this.y = first.y;
427
- } else {
428
- this.x = first;
429
- this.y = y ?? 0;
430
- }
431
- }
432
- toString(options) {
433
- return coreHelpers_1.Vector2Utils.toString(this, options);
434
- }
125
+ }
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
+ * multiply
140
+ *
141
+ * Element-wise multiplication of two vectors together.
142
+ * Not to be confused with {@link Vector3Utils.dot} product or {@link Vector3Utils.cross} product
143
+ */
144
+ static multiply(a, b) {
145
+ return {
146
+ x: a.x * b.x,
147
+ y: a.y * b.y,
148
+ z: a.z * b.z
435
149
  };
436
- exports.Vector2Builder = Vector2Builder;
437
150
  }
438
- });
439
-
440
- // lib/vector3/index.js
441
- var require_vector3 = __commonJS({
442
- "lib/vector3/index.js"(exports) {
443
- "use strict";
444
- var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
445
- if (k2 === void 0) k2 = k;
446
- var desc = Object.getOwnPropertyDescriptor(m, k);
447
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
448
- desc = { enumerable: true, get: function() {
449
- return m[k];
450
- } };
451
- }
452
- Object.defineProperty(o, k2, desc);
453
- } : function(o, m, k, k2) {
454
- if (k2 === void 0) k2 = k;
455
- o[k2] = m[k];
456
- });
457
- var __exportStar = exports && exports.__exportStar || function(m, exports2) {
458
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
151
+ /**
152
+ * rotateX
153
+ *
154
+ * Rotates the vector around the x axis counterclockwise (left hand rule)
155
+ * @param a - Angle in radians
156
+ */
157
+ static rotateX(v, a) {
158
+ let cos = Math.cos(a);
159
+ let sin = Math.sin(a);
160
+ return {
161
+ x: v.x,
162
+ y: v.y * cos - v.z * sin,
163
+ z: v.z * cos + v.y * sin
459
164
  };
460
- Object.defineProperty(exports, "__esModule", { value: true });
461
- __exportStar(require_coreHelpers(), exports);
462
- __exportStar(require_vectorWrapper(), exports);
463
165
  }
464
- });
465
-
466
- // lib/general/index.js
467
- var require_general = __commonJS({
468
- "lib/general/index.js"(exports) {
469
- "use strict";
470
- var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
471
- if (k2 === void 0) k2 = k;
472
- var desc = Object.getOwnPropertyDescriptor(m, k);
473
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
474
- desc = { enumerable: true, get: function() {
475
- return m[k];
476
- } };
477
- }
478
- Object.defineProperty(o, k2, desc);
479
- } : function(o, m, k, k2) {
480
- if (k2 === void 0) k2 = k;
481
- o[k2] = m[k];
482
- });
483
- var __exportStar = exports && exports.__exportStar || function(m, exports2) {
484
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
166
+ /**
167
+ * rotateY
168
+ *
169
+ * Rotates the vector around the y axis counterclockwise (left hand rule)
170
+ * @param a - Angle in radians
171
+ */
172
+ static rotateY(v, a) {
173
+ let cos = Math.cos(a);
174
+ let sin = Math.sin(a);
175
+ return {
176
+ x: v.x * cos + v.z * sin,
177
+ y: v.y,
178
+ z: v.z * cos - v.x * sin
485
179
  };
486
- Object.defineProperty(exports, "__esModule", { value: true });
487
- __exportStar(require_clamp(), exports);
488
180
  }
489
- });
490
-
491
- // lib/index.js
492
- var require_lib = __commonJS({
493
- "lib/index.js"(exports) {
494
- var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
495
- if (k2 === void 0) k2 = k;
496
- var desc = Object.getOwnPropertyDescriptor(m, k);
497
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
498
- desc = { enumerable: true, get: function() {
499
- return m[k];
500
- } };
501
- }
502
- Object.defineProperty(o, k2, desc);
503
- } : function(o, m, k, k2) {
504
- if (k2 === void 0) k2 = k;
505
- o[k2] = m[k];
506
- });
507
- var __exportStar = exports && exports.__exportStar || function(m, exports2) {
508
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
181
+ /**
182
+ * rotateZ
183
+ *
184
+ * Rotates the vector around the z axis counterclockwise (left hand rule)
185
+ * @param a - Angle in radians
186
+ */
187
+ static rotateZ(v, a) {
188
+ let cos = Math.cos(a);
189
+ let sin = Math.sin(a);
190
+ return {
191
+ x: v.x * cos - v.y * sin,
192
+ y: v.y * cos + v.x * sin,
193
+ z: v.z
509
194
  };
510
- Object.defineProperty(exports, "__esModule", { value: true });
511
- __exportStar(require_vector3(), exports);
512
- __exportStar(require_general(), exports);
513
195
  }
514
- });
515
- export default require_lib();
196
+ };
197
+ var Vector2Utils = class {
198
+ /**
199
+ * toString
200
+ *
201
+ * Create a string representation of a vector2
202
+ */
203
+ static toString(v, options) {
204
+ const decimals = options?.decimals ?? 2;
205
+ const str = [v.x.toFixed(decimals), v.y.toFixed(decimals)];
206
+ return str.join(options?.delimiter ?? ", ");
207
+ }
208
+ };
209
+ var VECTOR3_UP = { x: 0, y: 1, z: 0 };
210
+ var VECTOR3_DOWN = { x: 0, y: -1, z: 0 };
211
+ var VECTOR3_LEFT = { x: -1, y: 0, z: 0 };
212
+ var VECTOR3_RIGHT = { x: 1, y: 0, z: 0 };
213
+ var VECTOR3_FORWARD = { x: 0, y: 0, z: 1 };
214
+ var VECTOR3_BACK = { x: 0, y: 0, z: -1 };
215
+ var VECTOR3_ONE = { x: 1, y: 1, z: 1 };
216
+ var VECTOR3_ZERO = { x: 0, y: 0, z: 0 };
217
+ var VECTOR3_WEST = { x: -1, y: 0, z: 0 };
218
+ var VECTOR3_EAST = { x: 1, y: 0, z: 0 };
219
+ var VECTOR3_NORTH = { x: 0, y: 0, z: 1 };
220
+ var VECTOR3_SOUTH = { x: 0, y: 0, z: -1 };
221
+
222
+ // lib/vector3/vectorWrapper.js
223
+ var Vector3Builder = class {
224
+ x;
225
+ y;
226
+ z;
227
+ constructor(first, y, z) {
228
+ if (typeof first === "object") {
229
+ this.x = first.x;
230
+ this.y = first.y;
231
+ this.z = first.z;
232
+ } else {
233
+ this.x = first;
234
+ this.y = y ?? 0;
235
+ this.z = z ?? 0;
236
+ }
237
+ }
238
+ /**
239
+ * Assigns the values of the passed in vector to this vector. Returns itself.
240
+ */
241
+ assign(vec) {
242
+ this.x = vec.x;
243
+ this.y = vec.y;
244
+ this.z = vec.z;
245
+ return this;
246
+ }
247
+ /**
248
+ * equals
249
+ *
250
+ * Check the equality of two vectors
251
+ */
252
+ equals(v) {
253
+ return Vector3Utils.equals(this, v);
254
+ }
255
+ /**
256
+ * add
257
+ *
258
+ * Adds the vector v to this, returning itself.
259
+ */
260
+ add(v) {
261
+ return this.assign(Vector3Utils.add(this, v));
262
+ }
263
+ /**
264
+ * subtract
265
+ *
266
+ * Subtracts the vector v from this, returning itself.
267
+ */
268
+ subtract(v) {
269
+ return this.assign(Vector3Utils.subtract(this, v));
270
+ }
271
+ /** scale
272
+ *
273
+ * Scales this by the passed in value, returning itself.
274
+ */
275
+ scale(val) {
276
+ return this.assign(Vector3Utils.scale(this, val));
277
+ }
278
+ /**
279
+ * dot
280
+ *
281
+ * Computes the dot product of this and the passed in vector.
282
+ */
283
+ dot(vec) {
284
+ return Vector3Utils.dot(this, vec);
285
+ }
286
+ /**
287
+ * cross
288
+ *
289
+ * Computes the cross product of this and the passed in vector, returning itself.
290
+ */
291
+ cross(vec) {
292
+ return this.assign(Vector3Utils.cross(this, vec));
293
+ }
294
+ /**
295
+ * magnitude
296
+ *
297
+ * The magnitude of the vector
298
+ */
299
+ magnitude() {
300
+ return Vector3Utils.magnitude(this);
301
+ }
302
+ /**
303
+ * distance
304
+ *
305
+ * Calculate the distance between two vectors
306
+ */
307
+ distance(vec) {
308
+ return Vector3Utils.distance(this, vec);
309
+ }
310
+ /**
311
+ * normalize
312
+ *
313
+ * Normalizes this vector, returning itself.
314
+ */
315
+ normalize() {
316
+ return this.assign(Vector3Utils.normalize(this));
317
+ }
318
+ /**
319
+ * floor
320
+ *
321
+ * Floor the components of a vector to produce a new vector
322
+ */
323
+ floor() {
324
+ return this.assign(Vector3Utils.floor(this));
325
+ }
326
+ /**
327
+ * toString
328
+ *
329
+ * Create a string representation of a vector
330
+ */
331
+ toString(options) {
332
+ return Vector3Utils.toString(this, options);
333
+ }
334
+ /**
335
+ * clamp
336
+ *
337
+ * Clamps the components of a vector to limits to produce a new vector
338
+ */
339
+ clamp(limits) {
340
+ return this.assign(Vector3Utils.clamp(this, limits));
341
+ }
342
+ /**
343
+ * lerp
344
+ *
345
+ * Constructs a new vector using linear interpolation on each component from two vectors.
346
+ */
347
+ lerp(vec, t) {
348
+ return this.assign(Vector3Utils.lerp(this, vec, t));
349
+ }
350
+ /**
351
+ * slerp
352
+ *
353
+ * Constructs a new vector using spherical linear interpolation on each component from two vectors.
354
+ */
355
+ slerp(vec, t) {
356
+ return this.assign(Vector3Utils.slerp(this, vec, t));
357
+ }
358
+ /**
359
+ * multiply
360
+ *
361
+ * Element-wise multiplication of two vectors together.
362
+ * Not to be confused with {@link Vector3Builder.dot} product or {@link Vector3Builder.cross} product
363
+ */
364
+ multiply(vec) {
365
+ return this.assign(Vector3Utils.multiply(this, vec));
366
+ }
367
+ /**
368
+ * rotateX
369
+ *
370
+ * Rotates the vector around the x axis counterclockwise (left hand rule)
371
+ * @param a - Angle in radians
372
+ */
373
+ rotateX(a) {
374
+ return this.assign(Vector3Utils.rotateX(this, a));
375
+ }
376
+ /**
377
+ * rotateY
378
+ *
379
+ * Rotates the vector around the y axis counterclockwise (left hand rule)
380
+ * @param a - Angle in radians
381
+ */
382
+ rotateY(a) {
383
+ return this.assign(Vector3Utils.rotateY(this, a));
384
+ }
385
+ /**
386
+ * rotateZ
387
+ *
388
+ * Rotates the vector around the z axis counterclockwise (left hand rule)
389
+ * @param a - Angle in radians
390
+ */
391
+ rotateZ(a) {
392
+ return this.assign(Vector3Utils.rotateZ(this, a));
393
+ }
394
+ };
395
+ var Vector2Builder = class {
396
+ x;
397
+ y;
398
+ constructor(first, y) {
399
+ if (typeof first === "object") {
400
+ this.x = first.x;
401
+ this.y = first.y;
402
+ } else {
403
+ this.x = first;
404
+ this.y = y ?? 0;
405
+ }
406
+ }
407
+ toString(options) {
408
+ return Vector2Utils.toString(this, options);
409
+ }
410
+ };
411
+ export {
412
+ VECTOR3_BACK,
413
+ VECTOR3_DOWN,
414
+ VECTOR3_EAST,
415
+ VECTOR3_FORWARD,
416
+ VECTOR3_LEFT,
417
+ VECTOR3_NORTH,
418
+ VECTOR3_ONE,
419
+ VECTOR3_RIGHT,
420
+ VECTOR3_SOUTH,
421
+ VECTOR3_UP,
422
+ VECTOR3_WEST,
423
+ VECTOR3_ZERO,
424
+ Vector2Builder,
425
+ Vector2Utils,
426
+ Vector3Builder,
427
+ Vector3Utils,
428
+ clampNumber
429
+ };
516
430
  //# sourceMappingURL=minecraft-math.js.map