melonjs 10.2.2 → 10.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/README.md +6 -6
- package/dist/melonjs.js +2907 -3383
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +3620 -4528
- package/dist/melonjs.module.js +3210 -3331
- package/package.json +19 -19
- package/src/audio/audio.js +30 -31
- package/src/camera/camera2d.js +47 -58
- package/src/entity/draggable.js +11 -21
- package/src/entity/droptarget.js +12 -22
- package/src/entity/entity.js +32 -38
- package/src/game.js +21 -22
- package/src/{shapes → geometries}/ellipse.js +40 -47
- package/src/{shapes → geometries}/line.js +9 -12
- package/src/{shapes → geometries}/poly.js +100 -53
- package/src/{shapes → geometries}/rectangle.js +42 -45
- package/src/index.js +9 -20
- package/src/input/gamepad.js +11 -10
- package/src/input/input.js +2 -3
- package/src/input/keyboard.js +113 -113
- package/src/input/pointer.js +61 -29
- package/src/input/pointerevent.js +92 -29
- package/src/lang/deprecated.js +44 -14
- package/src/level/level.js +23 -24
- package/src/level/tiled/TMXGroup.js +7 -9
- package/src/level/tiled/TMXLayer.js +30 -33
- package/src/level/tiled/TMXObject.js +59 -53
- package/src/level/tiled/TMXTile.js +18 -19
- package/src/level/tiled/TMXTileMap.js +38 -46
- package/src/level/tiled/TMXTileset.js +12 -16
- package/src/level/tiled/TMXTilesetGroup.js +9 -10
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -6
- package/src/level/tiled/renderer/TMXRenderer.js +24 -26
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -5
- package/src/loader/loader.js +17 -16
- package/src/loader/loadingscreen.js +8 -10
- package/src/math/color.js +47 -67
- package/src/math/math.js +15 -16
- package/src/math/matrix2.js +53 -59
- package/src/math/matrix3.js +56 -63
- package/src/math/observable_vector2.js +87 -77
- package/src/math/observable_vector3.js +97 -80
- package/src/math/vector2.js +107 -97
- package/src/math/vector3.js +116 -100
- package/src/particles/emitter.js +66 -76
- package/src/particles/particle.js +4 -6
- package/src/particles/particlecontainer.js +2 -4
- package/src/physics/body.js +47 -146
- package/src/physics/bounds.js +48 -50
- package/src/physics/collision.js +13 -14
- package/src/physics/detector.js +14 -14
- package/src/physics/quadtree.js +18 -21
- package/src/physics/sat.js +30 -30
- package/src/physics/world.js +24 -29
- package/src/plugin/plugin.js +11 -15
- package/src/renderable/GUI.js +41 -47
- package/src/renderable/collectable.js +5 -10
- package/src/renderable/colorlayer.js +10 -15
- package/src/renderable/container.js +87 -73
- package/src/renderable/imagelayer.js +25 -32
- package/src/renderable/nineslicesprite.js +41 -42
- package/src/renderable/renderable.js +113 -124
- package/src/renderable/sprite.js +62 -69
- package/src/renderable/trigger.js +26 -32
- package/src/state/stage.js +13 -18
- package/src/state/state.js +26 -27
- package/src/system/device.js +76 -133
- package/src/system/event.js +81 -70
- package/src/system/pooling.js +11 -12
- package/src/system/save.js +3 -4
- package/src/system/timer.js +19 -20
- package/src/text/bitmaptext.js +57 -55
- package/src/text/bitmaptextdata.js +10 -11
- package/src/text/glyph.js +3 -0
- package/src/text/text.js +49 -55
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +1 -1
- package/src/tweens/tween.js +44 -46
- package/src/utils/agent.js +3 -4
- package/src/utils/array.js +4 -5
- package/src/utils/file.js +3 -4
- package/src/utils/function.js +4 -5
- package/src/utils/string.js +7 -9
- package/src/utils/utils.js +4 -5
- package/src/video/canvas/canvas_renderer.js +60 -62
- package/src/video/renderer.js +53 -58
- package/src/video/texture.js +98 -112
- package/src/video/texture_cache.js +4 -6
- package/src/video/video.js +16 -17
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/glshader.js +37 -39
- package/src/video/webgl/webgl_compositor.js +128 -110
- package/src/video/webgl/webgl_renderer.js +126 -106
package/src/math/vector2.js
CHANGED
|
@@ -4,16 +4,14 @@ import pool from "./../system/pooling.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* @classdesc
|
|
6
6
|
* a generic 2D Vector Object
|
|
7
|
-
* @class Vector2d
|
|
8
|
-
* @memberOf me
|
|
9
|
-
* @constructor
|
|
10
|
-
* @param {number} [x=0] x value of the vector
|
|
11
|
-
* @param {number} [y=0] y value of the vector
|
|
12
7
|
*/
|
|
13
8
|
class Vector2d {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @param {number} [x=0] x value of the vector
|
|
11
|
+
* @param {number} [y=0] y value of the vector
|
|
12
|
+
*/
|
|
13
|
+
constructor(x = 0, y = 0) {
|
|
14
|
+
this.onResetEvent(x, y);
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
/**
|
|
@@ -38,11 +36,11 @@ class Vector2d {
|
|
|
38
36
|
/**
|
|
39
37
|
* set the Vector x and y properties to the given values<br>
|
|
40
38
|
* @name set
|
|
41
|
-
* @
|
|
39
|
+
* @memberof Vector2d
|
|
42
40
|
* @function
|
|
43
41
|
* @param {number} x
|
|
44
42
|
* @param {number} y
|
|
45
|
-
* @returns {
|
|
43
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
46
44
|
*/
|
|
47
45
|
set(x, y) {
|
|
48
46
|
if (x !== +x || y !== +y) {
|
|
@@ -56,7 +54,7 @@ class Vector2d {
|
|
|
56
54
|
* @public
|
|
57
55
|
* @type {number}
|
|
58
56
|
* @name x
|
|
59
|
-
* @
|
|
57
|
+
* @memberof Vector2d
|
|
60
58
|
*/
|
|
61
59
|
//this.x = x;
|
|
62
60
|
|
|
@@ -65,7 +63,7 @@ class Vector2d {
|
|
|
65
63
|
* @public
|
|
66
64
|
* @type {number}
|
|
67
65
|
* @name y
|
|
68
|
-
* @
|
|
66
|
+
* @memberof Vector2d
|
|
69
67
|
*/
|
|
70
68
|
//this.y = y;
|
|
71
69
|
|
|
@@ -75,9 +73,9 @@ class Vector2d {
|
|
|
75
73
|
/**
|
|
76
74
|
* set the Vector x and y properties to 0
|
|
77
75
|
* @name setZero
|
|
78
|
-
* @
|
|
76
|
+
* @memberof Vector2d
|
|
79
77
|
* @function
|
|
80
|
-
* @returns {
|
|
78
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
81
79
|
*/
|
|
82
80
|
setZero() {
|
|
83
81
|
return this.set(0, 0);
|
|
@@ -86,10 +84,10 @@ class Vector2d {
|
|
|
86
84
|
/**
|
|
87
85
|
* set the Vector x and y properties using the passed vector
|
|
88
86
|
* @name setV
|
|
89
|
-
* @
|
|
87
|
+
* @memberof Vector2d
|
|
90
88
|
* @function
|
|
91
|
-
* @param {
|
|
92
|
-
* @returns {
|
|
89
|
+
* @param {Vector2d} v
|
|
90
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
93
91
|
*/
|
|
94
92
|
setV(v) {
|
|
95
93
|
return this._set(v.x, v.y);
|
|
@@ -98,10 +96,10 @@ class Vector2d {
|
|
|
98
96
|
/**
|
|
99
97
|
* Add the passed vector to this vector
|
|
100
98
|
* @name add
|
|
101
|
-
* @
|
|
99
|
+
* @memberof Vector2d
|
|
102
100
|
* @function
|
|
103
|
-
* @param {
|
|
104
|
-
* @returns {
|
|
101
|
+
* @param {Vector2d} v
|
|
102
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
105
103
|
*/
|
|
106
104
|
add(v) {
|
|
107
105
|
return this._set(this.x + v.x, this.y + v.y);
|
|
@@ -110,10 +108,10 @@ class Vector2d {
|
|
|
110
108
|
/**
|
|
111
109
|
* Substract the passed vector to this vector
|
|
112
110
|
* @name sub
|
|
113
|
-
* @
|
|
111
|
+
* @memberof Vector2d
|
|
114
112
|
* @function
|
|
115
|
-
* @param {
|
|
116
|
-
* @returns {
|
|
113
|
+
* @param {Vector2d} v
|
|
114
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
117
115
|
*/
|
|
118
116
|
sub(v) {
|
|
119
117
|
return this._set(this.x - v.x, this.y - v.y);
|
|
@@ -122,11 +120,11 @@ class Vector2d {
|
|
|
122
120
|
/**
|
|
123
121
|
* Multiply this vector values by the given scalar
|
|
124
122
|
* @name scale
|
|
125
|
-
* @
|
|
123
|
+
* @memberof Vector2d
|
|
126
124
|
* @function
|
|
127
125
|
* @param {number} x
|
|
128
126
|
* @param {number} [y=x]
|
|
129
|
-
* @returns {
|
|
127
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
130
128
|
*/
|
|
131
129
|
scale(x, y) {
|
|
132
130
|
return this._set(this.x * x, this.y * (typeof (y) !== "undefined" ? y : x));
|
|
@@ -135,9 +133,9 @@ class Vector2d {
|
|
|
135
133
|
/**
|
|
136
134
|
* Convert this vector into isometric coordinate space
|
|
137
135
|
* @name toIso
|
|
138
|
-
* @
|
|
136
|
+
* @memberof Vector2d
|
|
139
137
|
* @function
|
|
140
|
-
* @returns {
|
|
138
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
141
139
|
*/
|
|
142
140
|
toIso() {
|
|
143
141
|
return this._set(this.x - this.y, (this.x + this.y) * 0.5);
|
|
@@ -146,9 +144,9 @@ class Vector2d {
|
|
|
146
144
|
/**
|
|
147
145
|
* Convert this vector into 2d coordinate space
|
|
148
146
|
* @name to2d
|
|
149
|
-
* @
|
|
147
|
+
* @memberof Vector2d
|
|
150
148
|
* @function
|
|
151
|
-
* @returns {
|
|
149
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
152
150
|
*/
|
|
153
151
|
to2d() {
|
|
154
152
|
return this._set(this.y + this.x / 2, this.y - this.x / 2);
|
|
@@ -157,10 +155,10 @@ class Vector2d {
|
|
|
157
155
|
/**
|
|
158
156
|
* Multiply this vector values by the passed vector
|
|
159
157
|
* @name scaleV
|
|
160
|
-
* @
|
|
158
|
+
* @memberof Vector2d
|
|
161
159
|
* @function
|
|
162
|
-
* @param {
|
|
163
|
-
* @returns {
|
|
160
|
+
* @param {Vector2d} v
|
|
161
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
164
162
|
*/
|
|
165
163
|
scaleV(v) {
|
|
166
164
|
return this._set(this.x * v.x, this.y * v.y);
|
|
@@ -169,10 +167,10 @@ class Vector2d {
|
|
|
169
167
|
/**
|
|
170
168
|
* Divide this vector values by the passed value
|
|
171
169
|
* @name div
|
|
172
|
-
* @
|
|
170
|
+
* @memberof Vector2d
|
|
173
171
|
* @function
|
|
174
172
|
* @param {number} n the value to divide the vector by
|
|
175
|
-
* @returns {
|
|
173
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
176
174
|
*/
|
|
177
175
|
div(n) {
|
|
178
176
|
return this._set(this.x / n, this.y / n);
|
|
@@ -181,9 +179,9 @@ class Vector2d {
|
|
|
181
179
|
/**
|
|
182
180
|
* Update this vector values to absolute values
|
|
183
181
|
* @name abs
|
|
184
|
-
* @
|
|
182
|
+
* @memberof Vector2d
|
|
185
183
|
* @function
|
|
186
|
-
* @returns {
|
|
184
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
187
185
|
*/
|
|
188
186
|
abs() {
|
|
189
187
|
return this._set((this.x < 0) ? -this.x : this.x, (this.y < 0) ? -this.y : this.y);
|
|
@@ -192,11 +190,11 @@ class Vector2d {
|
|
|
192
190
|
/**
|
|
193
191
|
* Clamp the vector value within the specified value range
|
|
194
192
|
* @name clamp
|
|
195
|
-
* @
|
|
193
|
+
* @memberof Vector2d
|
|
196
194
|
* @function
|
|
197
195
|
* @param {number} low
|
|
198
196
|
* @param {number} high
|
|
199
|
-
* @returns {
|
|
197
|
+
* @returns {Vector2d} new me.Vector2d
|
|
200
198
|
*/
|
|
201
199
|
clamp(low, high) {
|
|
202
200
|
return new Vector2d(clamp(this.x, low, high), clamp(this.y, low, high));
|
|
@@ -205,11 +203,11 @@ class Vector2d {
|
|
|
205
203
|
/**
|
|
206
204
|
* Clamp this vector value within the specified value range
|
|
207
205
|
* @name clampSelf
|
|
208
|
-
* @
|
|
206
|
+
* @memberof Vector2d
|
|
209
207
|
* @function
|
|
210
208
|
* @param {number} low
|
|
211
209
|
* @param {number} high
|
|
212
|
-
* @returns {
|
|
210
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
213
211
|
*/
|
|
214
212
|
clampSelf(low, high) {
|
|
215
213
|
return this._set(clamp(this.x, low, high), clamp(this.y, low, high));
|
|
@@ -218,10 +216,10 @@ class Vector2d {
|
|
|
218
216
|
/**
|
|
219
217
|
* Update this vector with the minimum value between this and the passed vector
|
|
220
218
|
* @name minV
|
|
221
|
-
* @
|
|
219
|
+
* @memberof Vector2d
|
|
222
220
|
* @function
|
|
223
|
-
* @param {
|
|
224
|
-
* @returns {
|
|
221
|
+
* @param {Vector2d} v
|
|
222
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
225
223
|
*/
|
|
226
224
|
minV(v) {
|
|
227
225
|
return this._set((this.x < v.x) ? this.x : v.x, (this.y < v.y) ? this.y : v.y);
|
|
@@ -230,10 +228,10 @@ class Vector2d {
|
|
|
230
228
|
/**
|
|
231
229
|
* Update this vector with the maximum value between this and the passed vector
|
|
232
230
|
* @name maxV
|
|
233
|
-
* @
|
|
231
|
+
* @memberof Vector2d
|
|
234
232
|
* @function
|
|
235
|
-
* @param {
|
|
236
|
-
* @returns {
|
|
233
|
+
* @param {Vector2d} v
|
|
234
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
237
235
|
*/
|
|
238
236
|
maxV(v) {
|
|
239
237
|
return this._set((this.x > v.x) ? this.x : v.x, (this.y > v.y) ? this.y : v.y);
|
|
@@ -242,9 +240,9 @@ class Vector2d {
|
|
|
242
240
|
/**
|
|
243
241
|
* Floor the vector values
|
|
244
242
|
* @name floor
|
|
245
|
-
* @
|
|
243
|
+
* @memberof Vector2d
|
|
246
244
|
* @function
|
|
247
|
-
* @returns {
|
|
245
|
+
* @returns {Vector2d} new me.Vector2d
|
|
248
246
|
*/
|
|
249
247
|
floor() {
|
|
250
248
|
return new Vector2d(Math.floor(this.x), Math.floor(this.y));
|
|
@@ -253,9 +251,9 @@ class Vector2d {
|
|
|
253
251
|
/**
|
|
254
252
|
* Floor this vector values
|
|
255
253
|
* @name floorSelf
|
|
256
|
-
* @
|
|
254
|
+
* @memberof Vector2d
|
|
257
255
|
* @function
|
|
258
|
-
* @returns {
|
|
256
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
259
257
|
*/
|
|
260
258
|
floorSelf() {
|
|
261
259
|
return this._set(Math.floor(this.x), Math.floor(this.y));
|
|
@@ -264,9 +262,9 @@ class Vector2d {
|
|
|
264
262
|
/**
|
|
265
263
|
* Ceil the vector values
|
|
266
264
|
* @name ceil
|
|
267
|
-
* @
|
|
265
|
+
* @memberof Vector2d
|
|
268
266
|
* @function
|
|
269
|
-
* @returns {
|
|
267
|
+
* @returns {Vector2d} new me.Vector2d
|
|
270
268
|
*/
|
|
271
269
|
ceil() {
|
|
272
270
|
return new Vector2d(Math.ceil(this.x), Math.ceil(this.y));
|
|
@@ -275,9 +273,9 @@ class Vector2d {
|
|
|
275
273
|
/**
|
|
276
274
|
* Ceil this vector values
|
|
277
275
|
* @name ceilSelf
|
|
278
|
-
* @
|
|
276
|
+
* @memberof Vector2d
|
|
279
277
|
* @function
|
|
280
|
-
* @returns {
|
|
278
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
281
279
|
*/
|
|
282
280
|
ceilSelf() {
|
|
283
281
|
return this._set(Math.ceil(this.x), Math.ceil(this.y));
|
|
@@ -286,9 +284,9 @@ class Vector2d {
|
|
|
286
284
|
/**
|
|
287
285
|
* Negate the vector values
|
|
288
286
|
* @name negate
|
|
289
|
-
* @
|
|
287
|
+
* @memberof Vector2d
|
|
290
288
|
* @function
|
|
291
|
-
* @returns {
|
|
289
|
+
* @returns {Vector2d} new me.Vector2d
|
|
292
290
|
*/
|
|
293
291
|
negate() {
|
|
294
292
|
return new Vector2d(-this.x, -this.y);
|
|
@@ -297,9 +295,9 @@ class Vector2d {
|
|
|
297
295
|
/**
|
|
298
296
|
* Negate this vector values
|
|
299
297
|
* @name negateSelf
|
|
300
|
-
* @
|
|
298
|
+
* @memberof Vector2d
|
|
301
299
|
* @function
|
|
302
|
-
* @returns {
|
|
300
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
303
301
|
*/
|
|
304
302
|
negateSelf() {
|
|
305
303
|
return this._set(-this.x, -this.y);
|
|
@@ -308,10 +306,10 @@ class Vector2d {
|
|
|
308
306
|
/**
|
|
309
307
|
* Copy the x,y values of the passed vector to this one
|
|
310
308
|
* @name copy
|
|
311
|
-
* @
|
|
309
|
+
* @memberof Vector2d
|
|
312
310
|
* @function
|
|
313
|
-
* @param {
|
|
314
|
-
* @returns {
|
|
311
|
+
* @param {Vector2d} v
|
|
312
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
315
313
|
*/
|
|
316
314
|
copy(v) {
|
|
317
315
|
return this._set(v.x, v.y);
|
|
@@ -320,15 +318,15 @@ class Vector2d {
|
|
|
320
318
|
/**
|
|
321
319
|
* return true if the two vectors are the same
|
|
322
320
|
* @name equals
|
|
323
|
-
* @
|
|
321
|
+
* @memberof Vector2d
|
|
324
322
|
* @function
|
|
325
|
-
* @param {
|
|
323
|
+
* @param {Vector2d} v
|
|
326
324
|
* @returns {boolean}
|
|
327
325
|
*/
|
|
328
326
|
/**
|
|
329
327
|
* return true if this vector is equal to the given values
|
|
330
328
|
* @name equals
|
|
331
|
-
* @
|
|
329
|
+
* @memberof Vector2d
|
|
332
330
|
* @function
|
|
333
331
|
* @param {number} x
|
|
334
332
|
* @param {number} y
|
|
@@ -351,9 +349,9 @@ class Vector2d {
|
|
|
351
349
|
/**
|
|
352
350
|
* normalize this vector (scale the vector so that its magnitude is 1)
|
|
353
351
|
* @name normalize
|
|
354
|
-
* @
|
|
352
|
+
* @memberof Vector2d
|
|
355
353
|
* @function
|
|
356
|
-
* @returns {
|
|
354
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
357
355
|
*/
|
|
358
356
|
normalize() {
|
|
359
357
|
return this.div(this.length() || 1);
|
|
@@ -363,9 +361,9 @@ class Vector2d {
|
|
|
363
361
|
* change this vector to be perpendicular to what it was before.<br>
|
|
364
362
|
* (Effectively rotates it 90 degrees in a clockwise direction)
|
|
365
363
|
* @name perp
|
|
366
|
-
* @
|
|
364
|
+
* @memberof Vector2d
|
|
367
365
|
* @function
|
|
368
|
-
* @returns {
|
|
366
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
369
367
|
*/
|
|
370
368
|
perp() {
|
|
371
369
|
return this._set(this.y, -this.x);
|
|
@@ -374,11 +372,11 @@ class Vector2d {
|
|
|
374
372
|
/**
|
|
375
373
|
* Rotate this vector (counter-clockwise) by the specified angle (in radians).
|
|
376
374
|
* @name rotate
|
|
377
|
-
* @
|
|
375
|
+
* @memberof Vector2d
|
|
378
376
|
* @function
|
|
379
377
|
* @param {number} angle The angle to rotate (in radians)
|
|
380
|
-
* @param {
|
|
381
|
-
* @returns {
|
|
378
|
+
* @param {Vector2d|ObservableVector2d} [v] an optional point to rotate around
|
|
379
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
382
380
|
*/
|
|
383
381
|
rotate(angle, v) {
|
|
384
382
|
var cx = 0;
|
|
@@ -400,31 +398,43 @@ class Vector2d {
|
|
|
400
398
|
|
|
401
399
|
/**
|
|
402
400
|
* return the dot product of this vector and the passed one
|
|
403
|
-
* @name
|
|
404
|
-
* @
|
|
401
|
+
* @name dot
|
|
402
|
+
* @memberof Vector2d
|
|
405
403
|
* @function
|
|
406
|
-
* @param {
|
|
404
|
+
* @param {Vector2d} v
|
|
407
405
|
* @returns {number} The dot product.
|
|
408
406
|
*/
|
|
409
|
-
|
|
407
|
+
dot(v) {
|
|
410
408
|
return this.x * v.x + this.y * v.y;
|
|
411
409
|
}
|
|
412
410
|
|
|
411
|
+
/**
|
|
412
|
+
* return the cross product of this vector and the passed one
|
|
413
|
+
* @name cross
|
|
414
|
+
* @memberof Vector2d
|
|
415
|
+
* @function
|
|
416
|
+
* @param {Vector2d} v
|
|
417
|
+
* @returns {number} The cross product.
|
|
418
|
+
*/
|
|
419
|
+
cross(v) {
|
|
420
|
+
return this.x * v.y - this.y * v.x;
|
|
421
|
+
}
|
|
422
|
+
|
|
413
423
|
/**
|
|
414
424
|
* return the square length of this vector
|
|
415
425
|
* @name length2
|
|
416
|
-
* @
|
|
426
|
+
* @memberof Vector2d
|
|
417
427
|
* @function
|
|
418
428
|
* @returns {number} The length^2 of this vector.
|
|
419
429
|
*/
|
|
420
430
|
length2() {
|
|
421
|
-
return this.
|
|
431
|
+
return this.dot(this);
|
|
422
432
|
}
|
|
423
433
|
|
|
424
434
|
/**
|
|
425
435
|
* return the length (magnitude) of this vector
|
|
426
436
|
* @name length
|
|
427
|
-
* @
|
|
437
|
+
* @memberof Vector2d
|
|
428
438
|
* @function
|
|
429
439
|
* @returns {number} the length of this vector
|
|
430
440
|
*/
|
|
@@ -435,11 +445,11 @@ class Vector2d {
|
|
|
435
445
|
/**
|
|
436
446
|
* Linearly interpolate between this vector and the given one.
|
|
437
447
|
* @name lerp
|
|
438
|
-
* @
|
|
448
|
+
* @memberof Vector2d
|
|
439
449
|
* @function
|
|
440
|
-
* @param {
|
|
450
|
+
* @param {Vector2d} v
|
|
441
451
|
* @param {number} alpha distance along the line (alpha = 0 will be this vector, and alpha = 1 will be the given one).
|
|
442
|
-
* @returns {
|
|
452
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
443
453
|
*/
|
|
444
454
|
lerp(v, alpha) {
|
|
445
455
|
this.x += ( v.x - this.x ) * alpha;
|
|
@@ -450,9 +460,9 @@ class Vector2d {
|
|
|
450
460
|
/**
|
|
451
461
|
* return the distance between this vector and the passed one
|
|
452
462
|
* @name distance
|
|
453
|
-
* @
|
|
463
|
+
* @memberof Vector2d
|
|
454
464
|
* @function
|
|
455
|
-
* @param {
|
|
465
|
+
* @param {Vector2d} v
|
|
456
466
|
* @returns {number}
|
|
457
467
|
*/
|
|
458
468
|
distance(v) {
|
|
@@ -463,46 +473,46 @@ class Vector2d {
|
|
|
463
473
|
/**
|
|
464
474
|
* return the angle between this vector and the passed one
|
|
465
475
|
* @name angle
|
|
466
|
-
* @
|
|
476
|
+
* @memberof Vector2d
|
|
467
477
|
* @function
|
|
468
|
-
* @param {
|
|
478
|
+
* @param {Vector2d} v
|
|
469
479
|
* @returns {number} angle in radians
|
|
470
480
|
*/
|
|
471
481
|
angle(v) {
|
|
472
|
-
return Math.acos(clamp(this.
|
|
482
|
+
return Math.acos(clamp(this.dot(v) / (this.length() * v.length()), -1, 1));
|
|
473
483
|
}
|
|
474
484
|
|
|
475
485
|
/**
|
|
476
486
|
* project this vector on to another vector.
|
|
477
487
|
* @name project
|
|
478
|
-
* @
|
|
488
|
+
* @memberof Vector2d
|
|
479
489
|
* @function
|
|
480
|
-
* @param {
|
|
481
|
-
* @returns {
|
|
490
|
+
* @param {Vector2d} v The vector to project onto.
|
|
491
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
482
492
|
*/
|
|
483
493
|
project(v) {
|
|
484
|
-
return this.scale(this.
|
|
494
|
+
return this.scale(this.dot(v) / v.length2());
|
|
485
495
|
}
|
|
486
496
|
|
|
487
497
|
/**
|
|
488
498
|
* Project this vector onto a vector of unit length.<br>
|
|
489
499
|
* This is slightly more efficient than `project` when dealing with unit vectors.
|
|
490
500
|
* @name projectN
|
|
491
|
-
* @
|
|
501
|
+
* @memberof Vector2d
|
|
492
502
|
* @function
|
|
493
|
-
* @param {
|
|
494
|
-
* @returns {
|
|
503
|
+
* @param {Vector2d} v The unit vector to project onto.
|
|
504
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
495
505
|
*/
|
|
496
506
|
projectN(v) {
|
|
497
|
-
return this.scale(this.
|
|
507
|
+
return this.scale(this.dot(v));
|
|
498
508
|
}
|
|
499
509
|
|
|
500
510
|
/**
|
|
501
511
|
* return a clone copy of this vector
|
|
502
512
|
* @name clone
|
|
503
|
-
* @
|
|
513
|
+
* @memberof Vector2d
|
|
504
514
|
* @function
|
|
505
|
-
* @returns {
|
|
515
|
+
* @returns {Vector2d} new me.Vector2d
|
|
506
516
|
*/
|
|
507
517
|
clone() {
|
|
508
518
|
return pool.pull("Vector2d", this.x, this.y);
|
|
@@ -511,7 +521,7 @@ class Vector2d {
|
|
|
511
521
|
/**
|
|
512
522
|
* convert the object to a string representation
|
|
513
523
|
* @name toString
|
|
514
|
-
* @
|
|
524
|
+
* @memberof Vector2d
|
|
515
525
|
* @function
|
|
516
526
|
* @returns {string}
|
|
517
527
|
*/
|