melonjs 10.2.0 → 10.3.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 +1 -1
- package/dist/melonjs.js +4435 -4283
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +3348 -3833
- package/dist/melonjs.module.js +4025 -3920
- package/package.json +13 -14
- package/src/audio/audio.js +45 -45
- package/src/camera/camera2d.js +78 -101
- package/src/entity/draggable.js +21 -29
- package/src/entity/droptarget.js +24 -31
- package/src/entity/entity.js +34 -38
- package/src/game.js +8 -8
- package/src/{shapes → geometries}/ellipse.js +46 -46
- package/src/{shapes → geometries}/line.js +14 -14
- package/src/{shapes → geometries}/poly.js +103 -54
- package/src/{shapes → geometries}/rectangle.js +73 -120
- package/src/index.js +18 -19
- package/src/input/gamepad.js +20 -20
- package/src/input/input.js +3 -3
- package/src/input/keyboard.js +122 -124
- package/src/input/pointer.js +102 -62
- package/src/input/pointerevent.js +97 -42
- package/src/lang/deprecated.js +29 -18
- package/src/level/level.js +34 -26
- package/src/level/tiled/TMXGroup.js +12 -13
- package/src/level/tiled/TMXLayer.js +41 -42
- package/src/level/tiled/TMXObject.js +76 -70
- package/src/level/tiled/TMXTile.js +13 -15
- package/src/level/tiled/TMXTileMap.js +26 -25
- package/src/level/tiled/TMXTileset.js +14 -15
- package/src/level/tiled/TMXTilesetGroup.js +5 -6
- package/src/level/tiled/TMXUtils.js +13 -11
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +3 -4
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +3 -4
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -3
- package/src/level/tiled/renderer/TMXRenderer.js +18 -19
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +2 -3
- package/src/loader/loader.js +46 -40
- package/src/loader/loadingscreen.js +7 -7
- package/src/math/color.js +68 -88
- package/src/math/math.js +33 -33
- package/src/math/matrix2.js +70 -71
- package/src/math/matrix3.js +90 -91
- package/src/math/observable_vector2.js +91 -92
- package/src/math/observable_vector3.js +110 -106
- package/src/math/vector2.js +116 -104
- package/src/math/vector3.js +129 -110
- package/src/particles/emitter.js +116 -126
- package/src/particles/particle.js +4 -5
- package/src/particles/particlecontainer.js +2 -3
- package/src/physics/body.js +82 -83
- package/src/physics/bounds.js +64 -66
- package/src/physics/collision.js +21 -22
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +26 -25
- package/src/physics/sat.js +21 -21
- package/src/physics/world.js +23 -22
- package/src/plugin/plugin.js +12 -13
- package/src/renderable/GUI.js +20 -26
- package/src/renderable/collectable.js +6 -7
- package/src/renderable/colorlayer.js +11 -12
- package/src/renderable/container.js +98 -81
- package/src/renderable/imagelayer.js +33 -35
- package/src/renderable/nineslicesprite.js +15 -16
- package/src/renderable/renderable.js +112 -111
- package/src/renderable/sprite.js +71 -58
- package/src/renderable/trigger.js +17 -19
- package/src/state/stage.js +14 -15
- package/src/state/state.js +78 -78
- package/src/system/device.js +137 -180
- package/src/system/event.js +116 -104
- package/src/system/pooling.js +15 -15
- package/src/system/save.js +9 -6
- package/src/system/timer.js +33 -33
- package/src/text/bitmaptext.js +39 -46
- package/src/text/bitmaptextdata.js +14 -15
- package/src/text/text.js +55 -58
- package/src/tweens/easing.js +5 -5
- package/src/tweens/interpolation.js +5 -5
- package/src/tweens/tween.js +49 -40
- package/src/utils/agent.js +12 -11
- package/src/utils/array.js +8 -8
- package/src/utils/file.js +7 -7
- package/src/utils/function.js +8 -8
- package/src/utils/string.js +19 -19
- package/src/utils/utils.js +23 -23
- package/src/video/canvas/canvas_renderer.js +127 -128
- package/src/video/renderer.js +69 -69
- package/src/video/texture.js +80 -82
- package/src/video/texture_cache.js +2 -4
- package/src/video/video.js +38 -38
- package/src/video/webgl/buffer/vertex.js +11 -3
- package/src/video/webgl/glshader.js +31 -32
- package/src/video/webgl/webgl_compositor.js +145 -127
- package/src/video/webgl/webgl_renderer.js +196 -175
package/src/math/color.js
CHANGED
|
@@ -173,12 +173,11 @@ var cssToRGB = new Map();
|
|
|
173
173
|
* @classdesc
|
|
174
174
|
* A color manipulation object.
|
|
175
175
|
* @class Color
|
|
176
|
-
* @
|
|
177
|
-
* @
|
|
178
|
-
* @param {
|
|
179
|
-
* @param {
|
|
180
|
-
* @param {
|
|
181
|
-
* @param {Number} [alpha=1.0] alpha value
|
|
176
|
+
* @memberof me
|
|
177
|
+
* @param {number|Float32Array} [r=0] red component or array of color components
|
|
178
|
+
* @param {number} [g=0] green component
|
|
179
|
+
* @param {number} [b=0] blue component
|
|
180
|
+
* @param {number} [alpha=1.0] alpha value
|
|
182
181
|
*/
|
|
183
182
|
class Color {
|
|
184
183
|
|
|
@@ -203,21 +202,16 @@ class Color {
|
|
|
203
202
|
|
|
204
203
|
/**
|
|
205
204
|
* Color Red Component [0 .. 255]
|
|
206
|
-
* @type
|
|
205
|
+
* @type {number}
|
|
207
206
|
* @name r
|
|
208
207
|
* @readonly
|
|
209
|
-
* @
|
|
208
|
+
* @memberof me.Color
|
|
210
209
|
*/
|
|
211
210
|
|
|
212
|
-
/**
|
|
213
|
-
* @ignore
|
|
214
|
-
*/
|
|
215
211
|
get r() {
|
|
216
212
|
return ~~(this.glArray[0] * 255);
|
|
217
213
|
}
|
|
218
|
-
|
|
219
|
-
* @ignore
|
|
220
|
-
*/
|
|
214
|
+
|
|
221
215
|
set r(value) {
|
|
222
216
|
this.glArray[0] = clamp(~~value || 0, 0, 255) / 255.0;
|
|
223
217
|
}
|
|
@@ -225,21 +219,16 @@ class Color {
|
|
|
225
219
|
|
|
226
220
|
/**
|
|
227
221
|
* Color Green Component [0 .. 255]
|
|
228
|
-
* @type
|
|
222
|
+
* @type {number}
|
|
229
223
|
* @name g
|
|
230
224
|
* @readonly
|
|
231
|
-
* @
|
|
225
|
+
* @memberof me.Color
|
|
232
226
|
*/
|
|
233
227
|
|
|
234
|
-
/**
|
|
235
|
-
* @ignore
|
|
236
|
-
*/
|
|
237
228
|
get g() {
|
|
238
229
|
return ~~(this.glArray[1] * 255);
|
|
239
230
|
}
|
|
240
|
-
|
|
241
|
-
* @ignore
|
|
242
|
-
*/
|
|
231
|
+
|
|
243
232
|
set g(value) {
|
|
244
233
|
this.glArray[1] = clamp(~~value || 0, 0, 255) / 255.0;
|
|
245
234
|
}
|
|
@@ -247,41 +236,32 @@ class Color {
|
|
|
247
236
|
|
|
248
237
|
/**
|
|
249
238
|
* Color Blue Component [0 .. 255]
|
|
250
|
-
* @type
|
|
239
|
+
* @type {number}
|
|
251
240
|
* @name b
|
|
252
241
|
* @readonly
|
|
253
|
-
* @
|
|
254
|
-
*/
|
|
255
|
-
/**
|
|
256
|
-
* @ignore
|
|
242
|
+
* @memberof me.Color
|
|
257
243
|
*/
|
|
244
|
+
|
|
258
245
|
get b() {
|
|
259
246
|
return ~~(this.glArray[2] * 255);
|
|
260
247
|
}
|
|
261
|
-
|
|
262
|
-
* @ignore
|
|
263
|
-
*/
|
|
248
|
+
|
|
264
249
|
set b(value) {
|
|
265
250
|
this.glArray[2] = clamp(~~value || 0, 0, 255) / 255.0;
|
|
266
251
|
}
|
|
267
252
|
|
|
268
253
|
/**
|
|
269
254
|
* Color Alpha Component [0.0 .. 1.0]
|
|
270
|
-
* @type
|
|
255
|
+
* @type {number}
|
|
271
256
|
* @name alpha
|
|
272
257
|
* @readonly
|
|
273
|
-
* @
|
|
258
|
+
* @memberof me.Color
|
|
274
259
|
*/
|
|
275
260
|
|
|
276
|
-
/**
|
|
277
|
-
* @ignore
|
|
278
|
-
*/
|
|
279
261
|
get alpha() {
|
|
280
262
|
return this.glArray[3];
|
|
281
263
|
}
|
|
282
|
-
|
|
283
|
-
* @ignore
|
|
284
|
-
*/
|
|
264
|
+
|
|
285
265
|
set alpha(value) {
|
|
286
266
|
this.glArray[3] = typeof(value) === "undefined" ? 1.0 : clamp(+value, 0, 1.0);
|
|
287
267
|
}
|
|
@@ -290,13 +270,13 @@ class Color {
|
|
|
290
270
|
/**
|
|
291
271
|
* Set this color to the specified value.
|
|
292
272
|
* @name setColor
|
|
293
|
-
* @
|
|
273
|
+
* @memberof me.Color
|
|
294
274
|
* @function
|
|
295
|
-
* @param {
|
|
296
|
-
* @param {
|
|
297
|
-
* @param {
|
|
298
|
-
* @param {
|
|
299
|
-
* @
|
|
275
|
+
* @param {number} r red component [0 .. 255]
|
|
276
|
+
* @param {number} g green component [0 .. 255]
|
|
277
|
+
* @param {number} b blue component [0 .. 255]
|
|
278
|
+
* @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
|
|
279
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
300
280
|
*/
|
|
301
281
|
setColor(r, g, b, alpha = 1.0) {
|
|
302
282
|
// Private initialization: copy Color value directly
|
|
@@ -314,9 +294,9 @@ class Color {
|
|
|
314
294
|
/**
|
|
315
295
|
* Create a new copy of this color object.
|
|
316
296
|
* @name clone
|
|
317
|
-
* @
|
|
297
|
+
* @memberof me.Color
|
|
318
298
|
* @function
|
|
319
|
-
* @
|
|
299
|
+
* @returns {me.Color} Reference to the newly cloned object
|
|
320
300
|
*/
|
|
321
301
|
clone() {
|
|
322
302
|
return pool.pull("Color", this);
|
|
@@ -325,10 +305,10 @@ class Color {
|
|
|
325
305
|
/**
|
|
326
306
|
* Copy a color object or CSS color into this one.
|
|
327
307
|
* @name copy
|
|
328
|
-
* @
|
|
308
|
+
* @memberof me.Color
|
|
329
309
|
* @function
|
|
330
|
-
* @param {me.Color|
|
|
331
|
-
* @
|
|
310
|
+
* @param {me.Color|string} color
|
|
311
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
332
312
|
*/
|
|
333
313
|
copy(color) {
|
|
334
314
|
if (color instanceof Color) {
|
|
@@ -342,10 +322,10 @@ class Color {
|
|
|
342
322
|
/**
|
|
343
323
|
* Blend this color with the given one using addition.
|
|
344
324
|
* @name add
|
|
345
|
-
* @
|
|
325
|
+
* @memberof me.Color
|
|
346
326
|
* @function
|
|
347
327
|
* @param {me.Color} color
|
|
348
|
-
* @
|
|
328
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
349
329
|
*/
|
|
350
330
|
add(color) {
|
|
351
331
|
this.glArray[0] = clamp(this.glArray[0] + color.glArray[0], 0, 1);
|
|
@@ -359,10 +339,10 @@ class Color {
|
|
|
359
339
|
/**
|
|
360
340
|
* Darken this color value by 0..1
|
|
361
341
|
* @name darken
|
|
362
|
-
* @
|
|
342
|
+
* @memberof me.Color
|
|
363
343
|
* @function
|
|
364
|
-
* @param {
|
|
365
|
-
* @
|
|
344
|
+
* @param {number} scale
|
|
345
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
366
346
|
*/
|
|
367
347
|
darken(scale) {
|
|
368
348
|
scale = clamp(scale, 0, 1);
|
|
@@ -376,11 +356,11 @@ class Color {
|
|
|
376
356
|
/**
|
|
377
357
|
* Linearly interpolate between this color and the given one.
|
|
378
358
|
* @name lerp
|
|
379
|
-
* @
|
|
359
|
+
* @memberof me.Color
|
|
380
360
|
* @function
|
|
381
361
|
* @param {me.Color} color
|
|
382
|
-
* @param {
|
|
383
|
-
* @
|
|
362
|
+
* @param {number} alpha with alpha = 0 being this color, and alpha = 1 being the given one.
|
|
363
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
384
364
|
*/
|
|
385
365
|
lerp(color, alpha) {
|
|
386
366
|
alpha = clamp(alpha, 0, 1);
|
|
@@ -394,10 +374,10 @@ class Color {
|
|
|
394
374
|
/**
|
|
395
375
|
* Lighten this color value by 0..1
|
|
396
376
|
* @name lighten
|
|
397
|
-
* @
|
|
377
|
+
* @memberof me.Color
|
|
398
378
|
* @function
|
|
399
|
-
* @param {
|
|
400
|
-
* @
|
|
379
|
+
* @param {number} scale
|
|
380
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
401
381
|
*/
|
|
402
382
|
lighten(scale) {
|
|
403
383
|
scale = clamp(scale, 0, 1);
|
|
@@ -411,11 +391,11 @@ class Color {
|
|
|
411
391
|
/**
|
|
412
392
|
* Generate random r,g,b values for this color object
|
|
413
393
|
* @name random
|
|
414
|
-
* @
|
|
394
|
+
* @memberof me.Color
|
|
415
395
|
* @function
|
|
416
|
-
* @param {
|
|
417
|
-
* @param {
|
|
418
|
-
* @
|
|
396
|
+
* @param {number} [min=0] minimum value for the random range
|
|
397
|
+
* @param {number} [max=255] maxmium value for the random range
|
|
398
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
419
399
|
*/
|
|
420
400
|
random(min = 0, max = 255) {
|
|
421
401
|
if (min < 0) {
|
|
@@ -437,10 +417,10 @@ class Color {
|
|
|
437
417
|
* Return true if the r,g,b,a values of this color are equal with the
|
|
438
418
|
* given one.
|
|
439
419
|
* @name equals
|
|
440
|
-
* @
|
|
420
|
+
* @memberof me.Color
|
|
441
421
|
* @function
|
|
442
422
|
* @param {me.Color} color
|
|
443
|
-
* @
|
|
423
|
+
* @returns {boolean}
|
|
444
424
|
*/
|
|
445
425
|
equals(color) {
|
|
446
426
|
return (
|
|
@@ -455,10 +435,10 @@ class Color {
|
|
|
455
435
|
* Parse a CSS color string and set this color to the corresponding
|
|
456
436
|
* r,g,b values
|
|
457
437
|
* @name parseCSS
|
|
458
|
-
* @
|
|
438
|
+
* @memberof me.Color
|
|
459
439
|
* @function
|
|
460
|
-
* @param {
|
|
461
|
-
* @
|
|
440
|
+
* @param {string} cssColor
|
|
441
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
462
442
|
*/
|
|
463
443
|
parseCSS(cssColor) {
|
|
464
444
|
// TODO : Memoize this function by caching its input
|
|
@@ -473,10 +453,10 @@ class Color {
|
|
|
473
453
|
/**
|
|
474
454
|
* Parse an RGB or RGBA CSS color string
|
|
475
455
|
* @name parseRGB
|
|
476
|
-
* @
|
|
456
|
+
* @memberof me.Color
|
|
477
457
|
* @function
|
|
478
|
-
* @param {
|
|
479
|
-
* @
|
|
458
|
+
* @param {string} rgbColor
|
|
459
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
480
460
|
*/
|
|
481
461
|
parseRGB(rgbColor) {
|
|
482
462
|
// TODO : Memoize this function by caching its input
|
|
@@ -493,11 +473,11 @@ class Color {
|
|
|
493
473
|
* Parse a Hex color ("#RGB", "#RGBA" or "#RRGGBB", "#RRGGBBAA" format) and set this color to
|
|
494
474
|
* the corresponding r,g,b,a values
|
|
495
475
|
* @name parseHex
|
|
496
|
-
* @
|
|
476
|
+
* @memberof me.Color
|
|
497
477
|
* @function
|
|
498
|
-
* @param {
|
|
478
|
+
* @param {string} hexColor
|
|
499
479
|
* @param {boolean} [argb = false] true if format is #ARGB, or #AARRGGBB (as opposed to #RGBA or #RGGBBAA)
|
|
500
|
-
* @
|
|
480
|
+
* @returns {me.Color} Reference to this object for method chaining
|
|
501
481
|
*/
|
|
502
482
|
parseHex(hexColor, argb = false) {
|
|
503
483
|
// TODO : Memoize this function by caching its input
|
|
@@ -553,10 +533,10 @@ class Color {
|
|
|
553
533
|
/**
|
|
554
534
|
* Pack this color into a Uint32 ARGB representation
|
|
555
535
|
* @name toUint32
|
|
556
|
-
* @
|
|
536
|
+
* @memberof me.Color
|
|
557
537
|
* @function
|
|
558
|
-
* @param {
|
|
559
|
-
* @
|
|
538
|
+
* @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
|
|
539
|
+
* @returns {Uint32}
|
|
560
540
|
*/
|
|
561
541
|
toUint32(alpha = this.alpha) {
|
|
562
542
|
var ur = this.r & 0xff;
|
|
@@ -570,9 +550,9 @@ class Color {
|
|
|
570
550
|
/**
|
|
571
551
|
* return an array representation of this object
|
|
572
552
|
* @name toArray
|
|
573
|
-
* @
|
|
553
|
+
* @memberof me.Color
|
|
574
554
|
* @function
|
|
575
|
-
* @
|
|
555
|
+
* @returns {Float32Array}
|
|
576
556
|
*/
|
|
577
557
|
toArray() {
|
|
578
558
|
return this.glArray;
|
|
@@ -582,9 +562,9 @@ class Color {
|
|
|
582
562
|
/**
|
|
583
563
|
* Get the color in "#RRGGBB" format
|
|
584
564
|
* @name toHex
|
|
585
|
-
* @
|
|
565
|
+
* @memberof me.Color
|
|
586
566
|
* @function
|
|
587
|
-
* @
|
|
567
|
+
* @returns {string}
|
|
588
568
|
*/
|
|
589
569
|
toHex() {
|
|
590
570
|
// TODO : Memoize this function by caching its result until any of
|
|
@@ -596,9 +576,9 @@ class Color {
|
|
|
596
576
|
/**
|
|
597
577
|
* Get the color in "#RRGGBBAA" format
|
|
598
578
|
* @name toHex8
|
|
599
|
-
* @
|
|
579
|
+
* @memberof me.Color
|
|
600
580
|
* @function
|
|
601
|
-
* @
|
|
581
|
+
* @returns {string}
|
|
602
582
|
*/
|
|
603
583
|
toHex8() {
|
|
604
584
|
// TODO : Memoize this function by caching its result until any of
|
|
@@ -610,9 +590,9 @@ class Color {
|
|
|
610
590
|
/**
|
|
611
591
|
* Get the color in "rgb(R,G,B)" format
|
|
612
592
|
* @name toRGB
|
|
613
|
-
* @
|
|
593
|
+
* @memberof me.Color
|
|
614
594
|
* @function
|
|
615
|
-
* @
|
|
595
|
+
* @returns {string}
|
|
616
596
|
*/
|
|
617
597
|
toRGB() {
|
|
618
598
|
// TODO : Memoize this function by caching its result until any of
|
|
@@ -628,9 +608,9 @@ class Color {
|
|
|
628
608
|
/**
|
|
629
609
|
* Get the color in "rgba(R,G,B,A)" format
|
|
630
610
|
* @name toRGBA
|
|
631
|
-
* @
|
|
611
|
+
* @memberof me.Color
|
|
632
612
|
* @function
|
|
633
|
-
* @
|
|
613
|
+
* @returns {string}
|
|
634
614
|
*/
|
|
635
615
|
toRGBA() {
|
|
636
616
|
// TODO : Memoize this function by caching its result until any of
|
package/src/math/math.js
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* a collection of math utility functions
|
|
3
3
|
* @namespace Math
|
|
4
|
-
* @
|
|
4
|
+
* @memberof me
|
|
5
5
|
*/
|
|
6
6
|
|
|
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
|
*/
|
|
14
14
|
export const DEG_TO_RAD = Math.PI / 180.0;
|
|
15
15
|
|
|
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
|
*/
|
|
23
23
|
export const RAD_TO_DEG = 180.0 / Math.PI;
|
|
24
24
|
|
|
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
|
*/
|
|
32
32
|
export const TAU = Math.PI * 2;
|
|
33
33
|
|
|
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
|
*/
|
|
41
41
|
export const ETA = Math.PI * 0.5;
|
|
42
42
|
|
|
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
|
*/
|
|
50
50
|
export const EPSILON = 0.000001;
|
|
51
51
|
|
|
@@ -53,10 +53,10 @@ export const EPSILON = 0.000001;
|
|
|
53
53
|
* returns true if the given value is a power of two
|
|
54
54
|
* @public
|
|
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;
|
|
@@ -66,10 +66,10 @@ export function isPowerOfTwo(val) {
|
|
|
66
66
|
* returns the next power of two for the given value
|
|
67
67
|
* @public
|
|
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 --;
|
|
@@ -86,10 +86,10 @@ export function nextPowerOfTwo(val) {
|
|
|
86
86
|
* Converts an angle in degrees to an angle in radians
|
|
87
87
|
* @public
|
|
88
88
|
* @function
|
|
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...
|
|
@@ -102,10 +102,10 @@ export function degToRad(angle) {
|
|
|
102
102
|
* Converts an angle in radians to an angle in degrees.
|
|
103
103
|
* @public
|
|
104
104
|
* @function
|
|
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
|
|
@@ -118,12 +118,12 @@ export function radToDeg(radians) {
|
|
|
118
118
|
* clamp the given value
|
|
119
119
|
* @public
|
|
120
120
|
* @function
|
|
121
|
-
* @
|
|
121
|
+
* @memberof me.Math
|
|
122
122
|
* @name clamp
|
|
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;
|
|
@@ -133,11 +133,11 @@ export function clamp(val, low, high) {
|
|
|
133
133
|
* return a random integer between min (included) and max (excluded)
|
|
134
134
|
* @public
|
|
135
135
|
* @function
|
|
136
|
-
* @
|
|
136
|
+
* @memberof me.Math
|
|
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) );
|
|
@@ -150,11 +150,11 @@ export function random(min, max) {
|
|
|
150
150
|
* return a random float between min, max (exclusive)
|
|
151
151
|
* @public
|
|
152
152
|
* @function
|
|
153
|
-
* @
|
|
153
|
+
* @memberof me.Math
|
|
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) );
|
|
@@ -167,11 +167,11 @@ export function randomFloat(min, max) {
|
|
|
167
167
|
* return a weighted random between min, max (exclusive)
|
|
168
168
|
* @public
|
|
169
169
|
* @function
|
|
170
|
-
* @
|
|
170
|
+
* @memberof me.Math
|
|
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) );
|
|
@@ -184,11 +184,11 @@ export function weightedRandom(min, max) {
|
|
|
184
184
|
* round a value to the specified number of digit
|
|
185
185
|
* @public
|
|
186
186
|
* @function
|
|
187
|
-
* @
|
|
187
|
+
* @memberof me.Math
|
|
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
|
|
@@ -203,12 +203,12 @@ export function round(num, dec = 0) {
|
|
|
203
203
|
* check if the given value is close to the expected one
|
|
204
204
|
* @public
|
|
205
205
|
* @function
|
|
206
|
-
* @
|
|
206
|
+
* @memberof me.Math
|
|
207
207
|
* @name toBeCloseTo
|
|
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)) {
|