@minecraft/math 1.4.2 → 1.5.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/api-report/math.api.md +8 -0
- package/dist/minecraft-math.js +504 -319
- package/dist/minecraft-math.js.map +3 -3
- package/lib/general/clamp.js +5 -1
- package/lib/general/clamp.js.map +1 -1
- package/lib/general/index.js +17 -1
- package/lib/general/index.js.map +1 -1
- package/lib/index.js +18 -2
- package/lib/index.js.map +1 -1
- package/lib/index.test.js +6 -4
- package/lib/index.test.js.map +1 -1
- package/lib/types/math-beta.d.ts +56 -0
- package/lib/types/math-public.d.ts +56 -0
- package/lib/types/math.d.ts +56 -0
- package/lib/vector3/coreHelpers.js +81 -18
- package/lib/vector3/coreHelpers.js.map +1 -1
- package/lib/vector3/coreHelpers.test.js +137 -111
- package/lib/vector3/coreHelpers.test.js.map +1 -1
- package/lib/vector3/index.js +18 -2
- package/lib/vector3/index.js.map +1 -1
- package/lib/vector3/vectorWrapper.js +59 -18
- package/lib/vector3/vectorWrapper.js.map +1 -1
- package/lib/vector3/vectorWrapper.test.js +138 -108
- package/lib/vector3/vectorWrapper.test.js.map +1 -1
- package/package.json +3 -3
package/dist/minecraft-math.js
CHANGED
|
@@ -1,331 +1,516 @@
|
|
|
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
|
+
|
|
1
6
|
// lib/general/clamp.js
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
});
|
|
5
18
|
|
|
6
19
|
// lib/vector3/coreHelpers.js
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
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
|
+
}
|
|
57
215
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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)
|
|
112
|
-
};
|
|
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
|
|
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
|
+
}
|
|
124
228
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
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 };
|
|
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
|
+
});
|
|
163
244
|
|
|
164
245
|
// lib/vector3/vectorWrapper.js
|
|
165
|
-
var
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
+
}
|
|
420
|
+
};
|
|
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
|
+
}
|
|
435
|
+
};
|
|
436
|
+
exports.Vector2Builder = Vector2Builder;
|
|
288
437
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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);
|
|
459
|
+
};
|
|
460
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
461
|
+
__exportStar(require_coreHelpers(), exports);
|
|
462
|
+
__exportStar(require_vectorWrapper(), exports);
|
|
296
463
|
}
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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);
|
|
485
|
+
};
|
|
486
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
487
|
+
__exportStar(require_clamp(), exports);
|
|
307
488
|
}
|
|
308
|
-
|
|
309
|
-
|
|
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);
|
|
509
|
+
};
|
|
510
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
511
|
+
__exportStar(require_vector3(), exports);
|
|
512
|
+
__exportStar(require_general(), exports);
|
|
310
513
|
}
|
|
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
|
-
};
|
|
514
|
+
});
|
|
515
|
+
export default require_lib();
|
|
331
516
|
//# sourceMappingURL=minecraft-math.js.map
|