melonjs 10.1.1 → 10.2.3
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 -10
- package/dist/melonjs.js +3114 -2866
- package/dist/melonjs.min.js +3 -3
- package/dist/melonjs.module.d.ts +2588 -2498
- package/dist/melonjs.module.js +2694 -2479
- package/package.json +10 -11
- package/src/audio/audio.js +43 -43
- package/src/camera/camera2d.js +52 -74
- package/src/entity/draggable.js +18 -17
- package/src/entity/droptarget.js +19 -18
- package/src/entity/entity.js +22 -26
- package/src/game.js +3 -3
- package/src/index.js +15 -11
- package/src/input/gamepad.js +13 -13
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -16
- package/src/input/pointer.js +42 -35
- package/src/input/pointerevent.js +25 -33
- package/src/lang/deprecated.js +3 -3
- package/src/level/level.js +24 -16
- package/src/level/tiled/TMXGroup.js +6 -6
- package/src/level/tiled/TMXLayer.js +31 -31
- package/src/level/tiled/TMXObject.js +19 -19
- package/src/level/tiled/TMXTile.js +11 -12
- package/src/level/tiled/TMXTileMap.js +23 -21
- package/src/level/tiled/TMXTileset.js +13 -13
- package/src/level/tiled/TMXTilesetGroup.js +4 -4
- package/src/level/tiled/TMXUtils.js +13 -11
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +17 -17
- package/src/loader/loader.js +31 -27
- package/src/loader/loadingscreen.js +44 -75
- package/src/math/color.js +45 -64
- package/src/math/math.js +17 -17
- package/src/math/matrix2.js +46 -46
- package/src/math/matrix3.js +64 -64
- package/src/math/observable_vector2.js +45 -57
- package/src/math/observable_vector3.js +56 -70
- package/src/math/vector2.js +60 -59
- package/src/math/vector3.js +65 -64
- package/src/particles/emitter.js +53 -55
- package/src/particles/particle.js +1 -1
- package/src/physics/body.js +45 -51
- package/src/physics/bounds.js +36 -36
- package/src/physics/collision.js +15 -16
- package/src/physics/detector.js +10 -11
- package/src/physics/quadtree.js +18 -16
- package/src/physics/sat.js +17 -17
- package/src/physics/world.js +12 -10
- package/src/plugin/plugin.js +6 -6
- package/src/renderable/GUI.js +13 -18
- package/src/renderable/collectable.js +3 -3
- package/src/renderable/colorlayer.js +4 -4
- package/src/renderable/container.js +64 -46
- package/src/renderable/imagelayer.js +30 -31
- package/src/renderable/nineslicesprite.js +158 -69
- package/src/renderable/renderable.js +68 -67
- package/src/renderable/sprite.js +57 -43
- package/src/renderable/trigger.js +14 -15
- package/src/shapes/ellipse.js +27 -26
- package/src/shapes/line.js +8 -7
- package/src/shapes/poly.js +33 -31
- package/src/shapes/rectangle.js +50 -96
- package/src/state/stage.js +8 -8
- package/src/state/state.js +56 -56
- package/src/system/device.js +97 -84
- package/src/system/event.js +72 -72
- package/src/system/pooling.js +14 -14
- package/src/system/save.js +6 -3
- package/src/system/timer.js +20 -20
- package/src/text/bitmaptext.js +27 -33
- package/src/text/bitmaptextdata.js +9 -9
- package/src/text/text.js +118 -59
- package/src/tweens/easing.js +4 -4
- package/src/tweens/interpolation.js +4 -4
- package/src/tweens/tween.js +37 -27
- package/src/utils/agent.js +9 -8
- package/src/utils/array.js +4 -4
- package/src/utils/file.js +4 -4
- package/src/utils/function.js +5 -5
- package/src/utils/string.js +12 -12
- package/src/utils/utils.js +19 -19
- package/src/video/canvas/canvas_renderer.js +90 -90
- package/src/video/renderer.js +40 -39
- package/src/video/texture.js +85 -76
- package/src/video/texture_cache.js +11 -0
- package/src/video/video.js +31 -31
- package/src/video/webgl/buffer/vertex.js +9 -1
- package/src/video/webgl/glshader.js +20 -20
- package/src/video/webgl/webgl_compositor.js +47 -46
- package/src/video/webgl/webgl_renderer.js +104 -104
package/src/math/color.js
CHANGED
|
@@ -175,10 +175,10 @@ var cssToRGB = new Map();
|
|
|
175
175
|
* @class Color
|
|
176
176
|
* @memberOf me
|
|
177
177
|
* @constructor
|
|
178
|
-
* @param {
|
|
179
|
-
* @param {
|
|
180
|
-
* @param {
|
|
181
|
-
* @param {
|
|
178
|
+
* @param {number|Float32Array} [r=0] red component or array of color components
|
|
179
|
+
* @param {number} [g=0] green component
|
|
180
|
+
* @param {number} [b=0] blue component
|
|
181
|
+
* @param {number} [alpha=1.0] alpha value
|
|
182
182
|
*/
|
|
183
183
|
class Color {
|
|
184
184
|
|
|
@@ -203,21 +203,16 @@ class Color {
|
|
|
203
203
|
|
|
204
204
|
/**
|
|
205
205
|
* Color Red Component [0 .. 255]
|
|
206
|
-
* @type
|
|
206
|
+
* @type {number}
|
|
207
207
|
* @name r
|
|
208
208
|
* @readonly
|
|
209
209
|
* @memberOf me.Color
|
|
210
210
|
*/
|
|
211
211
|
|
|
212
|
-
/**
|
|
213
|
-
* @ignore
|
|
214
|
-
*/
|
|
215
212
|
get r() {
|
|
216
213
|
return ~~(this.glArray[0] * 255);
|
|
217
214
|
}
|
|
218
|
-
|
|
219
|
-
* @ignore
|
|
220
|
-
*/
|
|
215
|
+
|
|
221
216
|
set r(value) {
|
|
222
217
|
this.glArray[0] = clamp(~~value || 0, 0, 255) / 255.0;
|
|
223
218
|
}
|
|
@@ -225,21 +220,16 @@ class Color {
|
|
|
225
220
|
|
|
226
221
|
/**
|
|
227
222
|
* Color Green Component [0 .. 255]
|
|
228
|
-
* @type
|
|
223
|
+
* @type {number}
|
|
229
224
|
* @name g
|
|
230
225
|
* @readonly
|
|
231
226
|
* @memberOf me.Color
|
|
232
227
|
*/
|
|
233
228
|
|
|
234
|
-
/**
|
|
235
|
-
* @ignore
|
|
236
|
-
*/
|
|
237
229
|
get g() {
|
|
238
230
|
return ~~(this.glArray[1] * 255);
|
|
239
231
|
}
|
|
240
|
-
|
|
241
|
-
* @ignore
|
|
242
|
-
*/
|
|
232
|
+
|
|
243
233
|
set g(value) {
|
|
244
234
|
this.glArray[1] = clamp(~~value || 0, 0, 255) / 255.0;
|
|
245
235
|
}
|
|
@@ -247,41 +237,32 @@ class Color {
|
|
|
247
237
|
|
|
248
238
|
/**
|
|
249
239
|
* Color Blue Component [0 .. 255]
|
|
250
|
-
* @type
|
|
240
|
+
* @type {number}
|
|
251
241
|
* @name b
|
|
252
242
|
* @readonly
|
|
253
243
|
* @memberOf me.Color
|
|
254
244
|
*/
|
|
255
|
-
|
|
256
|
-
* @ignore
|
|
257
|
-
*/
|
|
245
|
+
|
|
258
246
|
get b() {
|
|
259
247
|
return ~~(this.glArray[2] * 255);
|
|
260
248
|
}
|
|
261
|
-
|
|
262
|
-
* @ignore
|
|
263
|
-
*/
|
|
249
|
+
|
|
264
250
|
set b(value) {
|
|
265
251
|
this.glArray[2] = clamp(~~value || 0, 0, 255) / 255.0;
|
|
266
252
|
}
|
|
267
253
|
|
|
268
254
|
/**
|
|
269
255
|
* Color Alpha Component [0.0 .. 1.0]
|
|
270
|
-
* @type
|
|
256
|
+
* @type {number}
|
|
271
257
|
* @name alpha
|
|
272
258
|
* @readonly
|
|
273
259
|
* @memberOf me.Color
|
|
274
260
|
*/
|
|
275
261
|
|
|
276
|
-
/**
|
|
277
|
-
* @ignore
|
|
278
|
-
*/
|
|
279
262
|
get alpha() {
|
|
280
263
|
return this.glArray[3];
|
|
281
264
|
}
|
|
282
|
-
|
|
283
|
-
* @ignore
|
|
284
|
-
*/
|
|
265
|
+
|
|
285
266
|
set alpha(value) {
|
|
286
267
|
this.glArray[3] = typeof(value) === "undefined" ? 1.0 : clamp(+value, 0, 1.0);
|
|
287
268
|
}
|
|
@@ -292,11 +273,11 @@ class Color {
|
|
|
292
273
|
* @name setColor
|
|
293
274
|
* @memberOf me.Color
|
|
294
275
|
* @function
|
|
295
|
-
* @param {
|
|
296
|
-
* @param {
|
|
297
|
-
* @param {
|
|
298
|
-
* @param {
|
|
299
|
-
* @
|
|
276
|
+
* @param {number} r red component [0 .. 255]
|
|
277
|
+
* @param {number} g green component [0 .. 255]
|
|
278
|
+
* @param {number} b blue component [0 .. 255]
|
|
279
|
+
* @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
|
|
280
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
300
281
|
*/
|
|
301
282
|
setColor(r, g, b, alpha = 1.0) {
|
|
302
283
|
// Private initialization: copy Color value directly
|
|
@@ -316,7 +297,7 @@ class Color {
|
|
|
316
297
|
* @name clone
|
|
317
298
|
* @memberOf me.Color
|
|
318
299
|
* @function
|
|
319
|
-
* @
|
|
300
|
+
* @returns {me.Color} Reference to the newly cloned object
|
|
320
301
|
*/
|
|
321
302
|
clone() {
|
|
322
303
|
return pool.pull("Color", this);
|
|
@@ -327,8 +308,8 @@ class Color {
|
|
|
327
308
|
* @name copy
|
|
328
309
|
* @memberOf me.Color
|
|
329
310
|
* @function
|
|
330
|
-
* @param {me.Color|
|
|
331
|
-
* @
|
|
311
|
+
* @param {me.Color|string} color
|
|
312
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
332
313
|
*/
|
|
333
314
|
copy(color) {
|
|
334
315
|
if (color instanceof Color) {
|
|
@@ -345,7 +326,7 @@ class Color {
|
|
|
345
326
|
* @memberOf me.Color
|
|
346
327
|
* @function
|
|
347
328
|
* @param {me.Color} color
|
|
348
|
-
* @
|
|
329
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
349
330
|
*/
|
|
350
331
|
add(color) {
|
|
351
332
|
this.glArray[0] = clamp(this.glArray[0] + color.glArray[0], 0, 1);
|
|
@@ -361,8 +342,8 @@ class Color {
|
|
|
361
342
|
* @name darken
|
|
362
343
|
* @memberOf me.Color
|
|
363
344
|
* @function
|
|
364
|
-
* @param {
|
|
365
|
-
* @
|
|
345
|
+
* @param {number} scale
|
|
346
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
366
347
|
*/
|
|
367
348
|
darken(scale) {
|
|
368
349
|
scale = clamp(scale, 0, 1);
|
|
@@ -379,8 +360,8 @@ class Color {
|
|
|
379
360
|
* @memberOf me.Color
|
|
380
361
|
* @function
|
|
381
362
|
* @param {me.Color} color
|
|
382
|
-
* @param {
|
|
383
|
-
* @
|
|
363
|
+
* @param {number} alpha with alpha = 0 being this color, and alpha = 1 being the given one.
|
|
364
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
384
365
|
*/
|
|
385
366
|
lerp(color, alpha) {
|
|
386
367
|
alpha = clamp(alpha, 0, 1);
|
|
@@ -396,8 +377,8 @@ class Color {
|
|
|
396
377
|
* @name lighten
|
|
397
378
|
* @memberOf me.Color
|
|
398
379
|
* @function
|
|
399
|
-
* @param {
|
|
400
|
-
* @
|
|
380
|
+
* @param {number} scale
|
|
381
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
401
382
|
*/
|
|
402
383
|
lighten(scale) {
|
|
403
384
|
scale = clamp(scale, 0, 1);
|
|
@@ -413,9 +394,9 @@ class Color {
|
|
|
413
394
|
* @name random
|
|
414
395
|
* @memberOf me.Color
|
|
415
396
|
* @function
|
|
416
|
-
* @param {
|
|
417
|
-
* @param {
|
|
418
|
-
* @
|
|
397
|
+
* @param {number} [min=0] minimum value for the random range
|
|
398
|
+
* @param {number} [max=255] maxmium value for the random range
|
|
399
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
419
400
|
*/
|
|
420
401
|
random(min = 0, max = 255) {
|
|
421
402
|
if (min < 0) {
|
|
@@ -440,7 +421,7 @@ class Color {
|
|
|
440
421
|
* @memberOf me.Color
|
|
441
422
|
* @function
|
|
442
423
|
* @param {me.Color} color
|
|
443
|
-
* @
|
|
424
|
+
* @returns {boolean}
|
|
444
425
|
*/
|
|
445
426
|
equals(color) {
|
|
446
427
|
return (
|
|
@@ -457,8 +438,8 @@ class Color {
|
|
|
457
438
|
* @name parseCSS
|
|
458
439
|
* @memberOf me.Color
|
|
459
440
|
* @function
|
|
460
|
-
* @param {
|
|
461
|
-
* @
|
|
441
|
+
* @param {string} cssColor
|
|
442
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
462
443
|
*/
|
|
463
444
|
parseCSS(cssColor) {
|
|
464
445
|
// TODO : Memoize this function by caching its input
|
|
@@ -475,8 +456,8 @@ class Color {
|
|
|
475
456
|
* @name parseRGB
|
|
476
457
|
* @memberOf me.Color
|
|
477
458
|
* @function
|
|
478
|
-
* @param {
|
|
479
|
-
* @
|
|
459
|
+
* @param {string} rgbColor
|
|
460
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
480
461
|
*/
|
|
481
462
|
parseRGB(rgbColor) {
|
|
482
463
|
// TODO : Memoize this function by caching its input
|
|
@@ -495,9 +476,9 @@ class Color {
|
|
|
495
476
|
* @name parseHex
|
|
496
477
|
* @memberOf me.Color
|
|
497
478
|
* @function
|
|
498
|
-
* @param {
|
|
479
|
+
* @param {string} hexColor
|
|
499
480
|
* @param {boolean} [argb = false] true if format is #ARGB, or #AARRGGBB (as opposed to #RGBA or #RGGBBAA)
|
|
500
|
-
* @
|
|
481
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
501
482
|
*/
|
|
502
483
|
parseHex(hexColor, argb = false) {
|
|
503
484
|
// TODO : Memoize this function by caching its input
|
|
@@ -555,8 +536,8 @@ class Color {
|
|
|
555
536
|
* @name toUint32
|
|
556
537
|
* @memberOf me.Color
|
|
557
538
|
* @function
|
|
558
|
-
* @param {
|
|
559
|
-
* @
|
|
539
|
+
* @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
|
|
540
|
+
* @returns {Uint32}
|
|
560
541
|
*/
|
|
561
542
|
toUint32(alpha = this.alpha) {
|
|
562
543
|
var ur = this.r & 0xff;
|
|
@@ -572,7 +553,7 @@ class Color {
|
|
|
572
553
|
* @name toArray
|
|
573
554
|
* @memberOf me.Color
|
|
574
555
|
* @function
|
|
575
|
-
* @
|
|
556
|
+
* @returns {Float32Array}
|
|
576
557
|
*/
|
|
577
558
|
toArray() {
|
|
578
559
|
return this.glArray;
|
|
@@ -584,7 +565,7 @@ class Color {
|
|
|
584
565
|
* @name toHex
|
|
585
566
|
* @memberOf me.Color
|
|
586
567
|
* @function
|
|
587
|
-
* @
|
|
568
|
+
* @returns {string}
|
|
588
569
|
*/
|
|
589
570
|
toHex() {
|
|
590
571
|
// TODO : Memoize this function by caching its result until any of
|
|
@@ -598,7 +579,7 @@ class Color {
|
|
|
598
579
|
* @name toHex8
|
|
599
580
|
* @memberOf me.Color
|
|
600
581
|
* @function
|
|
601
|
-
* @
|
|
582
|
+
* @returns {string}
|
|
602
583
|
*/
|
|
603
584
|
toHex8() {
|
|
604
585
|
// TODO : Memoize this function by caching its result until any of
|
|
@@ -612,7 +593,7 @@ class Color {
|
|
|
612
593
|
* @name toRGB
|
|
613
594
|
* @memberOf me.Color
|
|
614
595
|
* @function
|
|
615
|
-
* @
|
|
596
|
+
* @returns {string}
|
|
616
597
|
*/
|
|
617
598
|
toRGB() {
|
|
618
599
|
// TODO : Memoize this function by caching its result until any of
|
|
@@ -630,7 +611,7 @@ class Color {
|
|
|
630
611
|
* @name toRGBA
|
|
631
612
|
* @memberOf me.Color
|
|
632
613
|
* @function
|
|
633
|
-
* @
|
|
614
|
+
* @returns {string}
|
|
634
615
|
*/
|
|
635
616
|
toRGBA() {
|
|
636
617
|
// TODO : Memoize this function by caching its result until any of
|
package/src/math/math.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* constant to convert from degrees to radians
|
|
9
9
|
* @public
|
|
10
|
-
* @type {
|
|
10
|
+
* @type {number}
|
|
11
11
|
* @name DEG_TO_RAD
|
|
12
12
|
* @memberOf me.Math
|
|
13
13
|
*/
|
|
@@ -16,7 +16,7 @@ export const DEG_TO_RAD = Math.PI / 180.0;
|
|
|
16
16
|
/**
|
|
17
17
|
* constant to convert from radians to degrees
|
|
18
18
|
* @public
|
|
19
|
-
* @type {
|
|
19
|
+
* @type {number}
|
|
20
20
|
* @name RAD_TO_DEG
|
|
21
21
|
* @memberOf me.Math
|
|
22
22
|
*/
|
|
@@ -25,7 +25,7 @@ export const RAD_TO_DEG = 180.0 / Math.PI;
|
|
|
25
25
|
/**
|
|
26
26
|
* constant equals to 2 times pi
|
|
27
27
|
* @public
|
|
28
|
-
* @type {
|
|
28
|
+
* @type {number}
|
|
29
29
|
* @name TAU
|
|
30
30
|
* @memberOf me.Math
|
|
31
31
|
*/
|
|
@@ -34,7 +34,7 @@ export const TAU = Math.PI * 2;
|
|
|
34
34
|
/**
|
|
35
35
|
* constant equals to half pi
|
|
36
36
|
* @public
|
|
37
|
-
* @type {
|
|
37
|
+
* @type {number}
|
|
38
38
|
* @name ETA
|
|
39
39
|
* @memberOf me.Math
|
|
40
40
|
*/
|
|
@@ -43,7 +43,7 @@ export const ETA = Math.PI * 0.5;
|
|
|
43
43
|
/**
|
|
44
44
|
* the difference between 1 and the smallest floating point number greater than 1
|
|
45
45
|
* @public
|
|
46
|
-
* @type {
|
|
46
|
+
* @type {number}
|
|
47
47
|
* @name EPSILON
|
|
48
48
|
* @memberOf me.Math
|
|
49
49
|
*/
|
|
@@ -55,8 +55,8 @@ export const EPSILON = 0.000001;
|
|
|
55
55
|
* @function
|
|
56
56
|
* @memberOf me.Math
|
|
57
57
|
* @name isPowerOfTwo
|
|
58
|
-
* @param {
|
|
59
|
-
* @
|
|
58
|
+
* @param {number} val
|
|
59
|
+
* @returns {boolean}
|
|
60
60
|
*/
|
|
61
61
|
export function isPowerOfTwo(val) {
|
|
62
62
|
return (val & (val - 1)) === 0;
|
|
@@ -68,8 +68,8 @@ export function isPowerOfTwo(val) {
|
|
|
68
68
|
* @function
|
|
69
69
|
* @memberOf me.Math
|
|
70
70
|
* @name nextPowerOfTwo
|
|
71
|
-
* @param {
|
|
72
|
-
* @
|
|
71
|
+
* @param {number} val
|
|
72
|
+
* @returns {boolean}
|
|
73
73
|
*/
|
|
74
74
|
export function nextPowerOfTwo(val) {
|
|
75
75
|
val --;
|
|
@@ -89,7 +89,7 @@ export function nextPowerOfTwo(val) {
|
|
|
89
89
|
* @memberOf me.Math
|
|
90
90
|
* @name degToRad
|
|
91
91
|
* @param {number} angle angle in degrees
|
|
92
|
-
* @
|
|
92
|
+
* @returns {number} corresponding angle in radians
|
|
93
93
|
* @example
|
|
94
94
|
* // convert a specific angle
|
|
95
95
|
* me.Math.degToRad(60); // return 1.0471...
|
|
@@ -105,7 +105,7 @@ export function degToRad(angle) {
|
|
|
105
105
|
* @memberOf me.Math
|
|
106
106
|
* @name radToDeg
|
|
107
107
|
* @param {number} radians angle in radians
|
|
108
|
-
* @
|
|
108
|
+
* @returns {number} corresponding angle in degrees
|
|
109
109
|
* @example
|
|
110
110
|
* // convert a specific angle
|
|
111
111
|
* me.Math.radToDeg(1.0471975511965976); // return 60
|
|
@@ -123,7 +123,7 @@ export function radToDeg(radians) {
|
|
|
123
123
|
* @param {number} val the value to clamp
|
|
124
124
|
* @param {number} low lower limit
|
|
125
125
|
* @param {number} high higher limit
|
|
126
|
-
* @
|
|
126
|
+
* @returns {number} clamped value
|
|
127
127
|
*/
|
|
128
128
|
export function clamp(val, low, high) {
|
|
129
129
|
return val < low ? low : val > high ? high : +val;
|
|
@@ -137,7 +137,7 @@ export function clamp(val, low, high) {
|
|
|
137
137
|
* @name random
|
|
138
138
|
* @param {number} min minimum value.
|
|
139
139
|
* @param {number} max maximum value.
|
|
140
|
-
* @
|
|
140
|
+
* @returns {number} random value
|
|
141
141
|
* @example
|
|
142
142
|
* // Print a random number; one of 5, 6, 7, 8, 9
|
|
143
143
|
* console.log(me.Math.random(5, 10) );
|
|
@@ -154,7 +154,7 @@ export function random(min, max) {
|
|
|
154
154
|
* @name randomFloat
|
|
155
155
|
* @param {number} min minimum value.
|
|
156
156
|
* @param {number} max maximum value.
|
|
157
|
-
* @
|
|
157
|
+
* @returns {number} random value
|
|
158
158
|
* @example
|
|
159
159
|
* // Print a random number; one of 5, 6, 7, 8, 9
|
|
160
160
|
* console.log(me.Math.randomFloat(5, 10) );
|
|
@@ -171,7 +171,7 @@ export function randomFloat(min, max) {
|
|
|
171
171
|
* @name weightedRandom
|
|
172
172
|
* @param {number} min minimum value.
|
|
173
173
|
* @param {number} max maximum value.
|
|
174
|
-
* @
|
|
174
|
+
* @returns {number} random value
|
|
175
175
|
* @example
|
|
176
176
|
* // Print a random number; one of 5, 6, 7, 8, 9
|
|
177
177
|
* console.log(me.Math.weightedRandom(5, 10) );
|
|
@@ -188,7 +188,7 @@ export function weightedRandom(min, max) {
|
|
|
188
188
|
* @name round
|
|
189
189
|
* @param {number} num value to be rounded.
|
|
190
190
|
* @param {number} [dec=0] number of decimal digit to be rounded to.
|
|
191
|
-
* @
|
|
191
|
+
* @returns {number} rounded value
|
|
192
192
|
* @example
|
|
193
193
|
* // round a specific value to 2 digits
|
|
194
194
|
* me.Math.round(10.33333, 2); // return 10.33
|
|
@@ -208,7 +208,7 @@ export function round(num, dec = 0) {
|
|
|
208
208
|
* @param {number} expected value to be compared with.
|
|
209
209
|
* @param {number} actual actual value to compare
|
|
210
210
|
* @param {number} [precision=2] float precision for the comparison
|
|
211
|
-
* @
|
|
211
|
+
* @returns {boolean} if close to
|
|
212
212
|
* @example
|
|
213
213
|
* // test if the given value is close to 10
|
|
214
214
|
* if (me.Math.toBeCloseTo(10, value)) {
|
package/src/math/matrix2.js
CHANGED
|
@@ -10,7 +10,7 @@ import Matrix3d from "./matrix3.js";
|
|
|
10
10
|
* @memberOf me
|
|
11
11
|
* @constructor
|
|
12
12
|
* @param {me.Matrix2d} [mat2d] An instance of me.Matrix2d to copy from
|
|
13
|
-
* @param {
|
|
13
|
+
* @param {number[]} [arguments...] Matrix elements. See {@link me.Matrix2d.setTransform}
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
class Matrix2d {
|
|
@@ -45,7 +45,7 @@ class Matrix2d {
|
|
|
45
45
|
/**
|
|
46
46
|
* tx component of the matrix
|
|
47
47
|
* @public
|
|
48
|
-
* @type {
|
|
48
|
+
* @type {number}
|
|
49
49
|
* @readonly
|
|
50
50
|
* @see me.Matrix2d.translate
|
|
51
51
|
* @name tx
|
|
@@ -58,7 +58,7 @@ class Matrix2d {
|
|
|
58
58
|
/**
|
|
59
59
|
* ty component of the matrix
|
|
60
60
|
* @public
|
|
61
|
-
* @type {
|
|
61
|
+
* @type {number}
|
|
62
62
|
* @readonly
|
|
63
63
|
* @see me.Matrix2d.translate
|
|
64
64
|
* @name ty
|
|
@@ -75,7 +75,7 @@ class Matrix2d {
|
|
|
75
75
|
* @name identity
|
|
76
76
|
* @memberOf me.Matrix2d
|
|
77
77
|
* @function
|
|
78
|
-
* @
|
|
78
|
+
* @returns {me.Matrix2d} Reference to this object for method chaining
|
|
79
79
|
*/
|
|
80
80
|
identity() {
|
|
81
81
|
this.setTransform(
|
|
@@ -91,16 +91,16 @@ class Matrix2d {
|
|
|
91
91
|
* @name setTransform
|
|
92
92
|
* @memberOf me.Matrix2d
|
|
93
93
|
* @function
|
|
94
|
-
* @param {
|
|
95
|
-
* @param {
|
|
96
|
-
* @param {
|
|
97
|
-
* @param {
|
|
98
|
-
* @param {
|
|
99
|
-
* @param {
|
|
100
|
-
* @param {
|
|
101
|
-
* @param {
|
|
102
|
-
* @param {
|
|
103
|
-
* @
|
|
94
|
+
* @param {number} a
|
|
95
|
+
* @param {number} b
|
|
96
|
+
* @param {number} c
|
|
97
|
+
* @param {number} d
|
|
98
|
+
* @param {number} e
|
|
99
|
+
* @param {number} f
|
|
100
|
+
* @param {number} [g=0]
|
|
101
|
+
* @param {number} [h=0]
|
|
102
|
+
* @param {number} [i=1]
|
|
103
|
+
* @returns {me.Matrix2d} Reference to this object for method chaining
|
|
104
104
|
*/
|
|
105
105
|
setTransform() {
|
|
106
106
|
var a = this.val;
|
|
@@ -136,10 +136,10 @@ class Matrix2d {
|
|
|
136
136
|
* @memberOf me.Matrix2d
|
|
137
137
|
* @function
|
|
138
138
|
* @param {me.Matrix2d} m the matrix object to copy from
|
|
139
|
-
* @
|
|
139
|
+
* @returns {me.Matrix2d} Reference to this object for method chaining
|
|
140
140
|
*/
|
|
141
|
-
copy(
|
|
142
|
-
this.val.set(
|
|
141
|
+
copy(m) {
|
|
142
|
+
this.val.set(m.val);
|
|
143
143
|
return this;
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -149,7 +149,7 @@ class Matrix2d {
|
|
|
149
149
|
* @memberOf me.Matrix2d
|
|
150
150
|
* @function
|
|
151
151
|
* @param {me.Matrix3d} m the matrix object to copy from
|
|
152
|
-
* @
|
|
152
|
+
* @returns {me.Matrix2d} Reference to this object for method chaining
|
|
153
153
|
*/
|
|
154
154
|
fromMat3d(m) {
|
|
155
155
|
var b = m.val;
|
|
@@ -174,7 +174,7 @@ class Matrix2d {
|
|
|
174
174
|
* @memberOf me.Matrix2d
|
|
175
175
|
* @function
|
|
176
176
|
* @param {me.Matrix2d} m the other matrix
|
|
177
|
-
* @
|
|
177
|
+
* @returns {me.Matrix2d} Reference to this object for method chaining
|
|
178
178
|
*/
|
|
179
179
|
multiply(m) {
|
|
180
180
|
var b = m.val;
|
|
@@ -205,7 +205,7 @@ class Matrix2d {
|
|
|
205
205
|
* @name transpose
|
|
206
206
|
* @memberOf me.Matrix2d
|
|
207
207
|
* @function
|
|
208
|
-
* @
|
|
208
|
+
* @returns {me.Matrix2d} Reference to this object for method chaining
|
|
209
209
|
*/
|
|
210
210
|
transpose() {
|
|
211
211
|
var a = this.val,
|
|
@@ -228,7 +228,7 @@ class Matrix2d {
|
|
|
228
228
|
* @name invert
|
|
229
229
|
* @memberOf me.Matrix2d
|
|
230
230
|
* @function
|
|
231
|
-
* @
|
|
231
|
+
* @returns {me.Matrix2d} Reference to this object for method chaining
|
|
232
232
|
*/
|
|
233
233
|
invert() {
|
|
234
234
|
var val = this.val;
|
|
@@ -263,8 +263,8 @@ class Matrix2d {
|
|
|
263
263
|
* @name apply
|
|
264
264
|
* @memberOf me.Matrix2d
|
|
265
265
|
* @function
|
|
266
|
-
* @param {me.Vector2d}
|
|
267
|
-
* @
|
|
266
|
+
* @param {me.Vector2d} v the vector object to be transformed
|
|
267
|
+
* @returns {me.Vector2d} result vector object.
|
|
268
268
|
*/
|
|
269
269
|
apply(v) {
|
|
270
270
|
var a = this.val,
|
|
@@ -282,8 +282,8 @@ class Matrix2d {
|
|
|
282
282
|
* @name applyInverse
|
|
283
283
|
* @memberOf me.Matrix2d
|
|
284
284
|
* @function
|
|
285
|
-
* @param {me.Vector2d}
|
|
286
|
-
* @
|
|
285
|
+
* @param {me.Vector2d} v the vector object to be transformed
|
|
286
|
+
* @returns {me.Vector2d} result vector object.
|
|
287
287
|
*/
|
|
288
288
|
applyInverse(v) {
|
|
289
289
|
var a = this.val,
|
|
@@ -303,9 +303,9 @@ class Matrix2d {
|
|
|
303
303
|
* @name scale
|
|
304
304
|
* @memberOf me.Matrix2d
|
|
305
305
|
* @function
|
|
306
|
-
* @param {
|
|
307
|
-
* @param {
|
|
308
|
-
* @
|
|
306
|
+
* @param {number} x a number representing the abscissa of the scaling vector.
|
|
307
|
+
* @param {number} [y=x] a number representing the ordinate of the scaling vector.
|
|
308
|
+
* @returns {me.Matrix2d} Reference to this object for method chaining
|
|
309
309
|
*/
|
|
310
310
|
scale(x, y) {
|
|
311
311
|
var a = this.val,
|
|
@@ -325,8 +325,8 @@ class Matrix2d {
|
|
|
325
325
|
* @name scaleV
|
|
326
326
|
* @memberOf me.Matrix2d
|
|
327
327
|
* @function
|
|
328
|
-
* @param {me.Vector2d}
|
|
329
|
-
* @
|
|
328
|
+
* @param {me.Vector2d} v scaling vector
|
|
329
|
+
* @returns {me.Matrix2d} Reference to this object for method chaining
|
|
330
330
|
*/
|
|
331
331
|
scaleV(v) {
|
|
332
332
|
return this.scale(v.x, v.y);
|
|
@@ -337,8 +337,8 @@ class Matrix2d {
|
|
|
337
337
|
* @name scaleX
|
|
338
338
|
* @memberOf me.Matrix2d
|
|
339
339
|
* @function
|
|
340
|
-
* @param {
|
|
341
|
-
* @
|
|
340
|
+
* @param {number} x x scaling vector
|
|
341
|
+
* @returns {me.Matrix2d} Reference to this object for method chaining
|
|
342
342
|
*/
|
|
343
343
|
scaleX(x) {
|
|
344
344
|
return this.scale(x, 1);
|
|
@@ -349,8 +349,8 @@ class Matrix2d {
|
|
|
349
349
|
* @name scaleY
|
|
350
350
|
* @memberOf me.Matrix2d
|
|
351
351
|
* @function
|
|
352
|
-
* @param {
|
|
353
|
-
* @
|
|
352
|
+
* @param {number} y y scaling vector
|
|
353
|
+
* @returns {me.Matrix2d} Reference to this object for method chaining
|
|
354
354
|
*/
|
|
355
355
|
scaleY(y) {
|
|
356
356
|
return this.scale(1, y);
|
|
@@ -361,8 +361,8 @@ class Matrix2d {
|
|
|
361
361
|
* @name rotate
|
|
362
362
|
* @memberOf me.Matrix2d
|
|
363
363
|
* @function
|
|
364
|
-
* @param {
|
|
365
|
-
* @
|
|
364
|
+
* @param {number} angle Rotation angle in radians.
|
|
365
|
+
* @returns {me.Matrix2d} Reference to this object for method chaining
|
|
366
366
|
*/
|
|
367
367
|
rotate(angle) {
|
|
368
368
|
if (angle !== 0) {
|
|
@@ -392,9 +392,9 @@ class Matrix2d {
|
|
|
392
392
|
* @name translate
|
|
393
393
|
* @memberOf me.Matrix2d
|
|
394
394
|
* @function
|
|
395
|
-
* @param {
|
|
396
|
-
* @param {
|
|
397
|
-
* @
|
|
395
|
+
* @param {number} x the x coordindates to translate the matrix by
|
|
396
|
+
* @param {number} y the y coordindates to translate the matrix by
|
|
397
|
+
* @returns {me.Matrix2d} Reference to this object for method chaining
|
|
398
398
|
*/
|
|
399
399
|
/**
|
|
400
400
|
* translate the matrix by a vector on the horizontal and vertical axis
|
|
@@ -402,7 +402,7 @@ class Matrix2d {
|
|
|
402
402
|
* @memberOf me.Matrix2d
|
|
403
403
|
* @function
|
|
404
404
|
* @param {me.Vector2d} v the vector to translate the matrix by
|
|
405
|
-
* @
|
|
405
|
+
* @returns {me.Matrix2d} Reference to this object for method chaining
|
|
406
406
|
*/
|
|
407
407
|
translate() {
|
|
408
408
|
var a = this.val;
|
|
@@ -429,8 +429,8 @@ class Matrix2d {
|
|
|
429
429
|
* @name isIdentity
|
|
430
430
|
* @memberOf me.Matrix2d
|
|
431
431
|
* @function
|
|
432
|
-
* @
|
|
433
|
-
|
|
432
|
+
* @returns {boolean}
|
|
433
|
+
*/
|
|
434
434
|
isIdentity() {
|
|
435
435
|
var a = this.val;
|
|
436
436
|
|
|
@@ -453,7 +453,7 @@ class Matrix2d {
|
|
|
453
453
|
* @memberOf me.Matrix2d
|
|
454
454
|
* @function
|
|
455
455
|
* @param {me.Matrix2d} m the other matrix
|
|
456
|
-
* @
|
|
456
|
+
* @returns {boolean} true if both are equals
|
|
457
457
|
*/
|
|
458
458
|
equals(m) {
|
|
459
459
|
var b = m.val;
|
|
@@ -477,7 +477,7 @@ class Matrix2d {
|
|
|
477
477
|
* @name clone
|
|
478
478
|
* @memberOf me.Matrix2d
|
|
479
479
|
* @function
|
|
480
|
-
* @
|
|
480
|
+
* @returns {me.Matrix2d}
|
|
481
481
|
*/
|
|
482
482
|
clone() {
|
|
483
483
|
return pool.pull("Matrix2d", this);
|
|
@@ -488,7 +488,7 @@ class Matrix2d {
|
|
|
488
488
|
* @name toArray
|
|
489
489
|
* @memberOf me.Matrix2d
|
|
490
490
|
* @function
|
|
491
|
-
* @
|
|
491
|
+
* @returns {Float32Array}
|
|
492
492
|
*/
|
|
493
493
|
toArray() {
|
|
494
494
|
return this.val;
|
|
@@ -499,7 +499,7 @@ class Matrix2d {
|
|
|
499
499
|
* @name toString
|
|
500
500
|
* @memberOf me.Matrix2d
|
|
501
501
|
* @function
|
|
502
|
-
* @
|
|
502
|
+
* @returns {string}
|
|
503
503
|
*/
|
|
504
504
|
toString() {
|
|
505
505
|
var a = this.val;
|