melonjs 10.9.0 → 10.12.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/LICENSE.md +1 -1
- package/README.md +32 -25
- package/dist/melonjs.js +1635 -2383
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +929 -1504
- package/dist/melonjs.module.js +1581 -2344
- package/package.json +18 -18
- package/src/audio/audio.js +0 -1
- package/src/camera/camera2d.js +1 -16
- package/src/entity/entity.js +6 -11
- package/src/game.js +2 -2
- package/src/geometries/ellipse.js +19 -28
- package/src/geometries/line.js +5 -8
- package/src/geometries/path2d.js +14 -24
- package/src/geometries/poly.js +29 -47
- package/src/geometries/rectangle.js +25 -37
- package/src/geometries/roundrect.js +8 -12
- package/src/index.js +7 -2
- package/src/input/gamepad.js +3 -14
- package/src/input/keyboard.js +1 -9
- package/src/input/pointer.js +0 -1
- package/src/input/pointerevent.js +14 -23
- package/src/lang/deprecated.js +9 -6
- package/src/level/level.js +0 -9
- package/src/level/tiled/TMXGroup.js +0 -4
- package/src/level/tiled/TMXLayer.js +0 -8
- package/src/level/tiled/TMXObject.js +0 -3
- package/src/level/tiled/TMXTile.js +4 -5
- package/src/level/tiled/TMXTileMap.js +1 -7
- package/src/level/tiled/TMXTileset.js +0 -5
- package/src/level/tiled/TMXTilesetGroup.js +1 -4
- package/src/level/tiled/TMXUtils.js +1 -4
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -3
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +0 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -7
- package/src/loader/loader.js +0 -11
- package/src/loader/loadingscreen.js +16 -5
- package/src/math/color.js +10 -30
- package/src/math/math.js +0 -10
- package/src/math/matrix2.js +12 -27
- package/src/math/matrix3.js +1 -22
- package/src/math/observable_vector2.js +0 -29
- package/src/math/observable_vector3.js +0 -29
- package/src/math/vector2.js +3 -40
- package/src/math/vector3.js +4 -41
- package/src/particles/emitter.js +11 -12
- package/src/physics/body.js +4 -5
- package/src/physics/bounds.js +5 -19
- package/src/physics/collision.js +1 -13
- package/src/physics/detector.js +6 -56
- package/src/physics/quadtree.js +0 -7
- package/src/physics/response.js +48 -0
- package/src/physics/sat.js +4 -4
- package/src/physics/world.js +0 -4
- package/src/plugin/plugin.js +0 -2
- package/src/polyfill/roundrect.js +4 -2
- package/src/renderable/GUI.js +11 -14
- package/src/renderable/collectable.js +1 -0
- package/src/renderable/colorlayer.js +9 -7
- package/src/renderable/container.js +38 -64
- package/src/renderable/dragndrop.js +1 -10
- package/src/renderable/imagelayer.js +8 -12
- package/src/renderable/light2d.js +118 -0
- package/src/renderable/renderable.js +27 -48
- package/src/renderable/sprite.js +17 -29
- package/src/renderable/trigger.js +10 -3
- package/src/state/stage.js +72 -6
- package/src/state/state.js +22 -23
- package/src/system/device.js +14 -53
- package/src/system/event.js +11 -0
- package/src/system/pooling.js +20 -9
- package/src/system/save.js +9 -11
- package/src/system/timer.js +239 -218
- package/src/text/bitmaptextdata.js +1 -4
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +25 -24
- package/src/text/textmetrics.js +0 -2
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +2 -2
- package/src/tweens/tween.js +1 -13
- package/src/utils/agent.js +1 -3
- package/src/utils/array.js +0 -3
- package/src/utils/file.js +0 -2
- package/src/utils/function.js +0 -2
- package/src/utils/string.js +0 -6
- package/src/utils/utils.js +0 -3
- package/src/video/canvas/canvas_renderer.js +73 -90
- package/src/video/renderer.js +34 -49
- package/src/video/{texture.js → texture/atlas.js} +10 -8
- package/src/video/{texture_cache.js → texture/cache.js} +4 -5
- package/src/video/texture/canvas_texture.js +99 -0
- package/src/video/video.js +3 -3
- package/src/video/webgl/glshader.js +0 -5
- package/src/video/webgl/utils/uniforms.js +3 -6
- package/src/video/webgl/webgl_compositor.js +0 -14
- package/src/video/webgl/webgl_renderer.js +73 -97
package/src/loader/loader.js
CHANGED
|
@@ -310,7 +310,6 @@ var loader = {
|
|
|
310
310
|
/**
|
|
311
311
|
* onload callback
|
|
312
312
|
* @public
|
|
313
|
-
* @function
|
|
314
313
|
* @name onload
|
|
315
314
|
* @memberof loader
|
|
316
315
|
* @example
|
|
@@ -324,7 +323,6 @@ var loader = {
|
|
|
324
323
|
* each time a resource is loaded, the loader will fire the specified function,
|
|
325
324
|
* giving the actual progress [0 ... 1], as argument, and an object describing the resource loaded
|
|
326
325
|
* @public
|
|
327
|
-
* @function
|
|
328
326
|
* @name onProgress
|
|
329
327
|
* @memberof loader
|
|
330
328
|
* @example
|
|
@@ -412,7 +410,6 @@ var loader = {
|
|
|
412
410
|
* @name setBaseURL
|
|
413
411
|
* @memberof loader
|
|
414
412
|
* @public
|
|
415
|
-
* @function
|
|
416
413
|
* @param {string} type "*", "audio", binary", "image", "json", "js", "tmx", "tsx"
|
|
417
414
|
* @param {string} [url="./"] default base URL
|
|
418
415
|
* @example
|
|
@@ -443,7 +440,6 @@ var loader = {
|
|
|
443
440
|
* @name preload
|
|
444
441
|
* @memberof loader
|
|
445
442
|
* @public
|
|
446
|
-
* @function
|
|
447
443
|
* @param {object[]} res
|
|
448
444
|
* @param {string} res.name internal name of the resource
|
|
449
445
|
* @param {string} res.type "audio", binary", "image", "json","js", "tmx", "tsx", "fontface"
|
|
@@ -508,7 +504,6 @@ var loader = {
|
|
|
508
504
|
* @name load
|
|
509
505
|
* @memberof loader
|
|
510
506
|
* @public
|
|
511
|
-
* @function
|
|
512
507
|
* @param {object} res
|
|
513
508
|
* @param {string} res.name internal name of the resource
|
|
514
509
|
* @param {string} res.type "audio", binary", "image", "json", "tmx", "tsx"
|
|
@@ -578,7 +573,6 @@ var loader = {
|
|
|
578
573
|
* @name unload
|
|
579
574
|
* @memberof loader
|
|
580
575
|
* @public
|
|
581
|
-
* @function
|
|
582
576
|
* @param {object} res
|
|
583
577
|
* @param {string} res.name internal name of the resource
|
|
584
578
|
* @param {string} res.type "audio", binary", "image", "json", "tmx", "tsx"
|
|
@@ -640,7 +634,6 @@ var loader = {
|
|
|
640
634
|
* @name unloadAll
|
|
641
635
|
* @memberof loader
|
|
642
636
|
* @public
|
|
643
|
-
* @function
|
|
644
637
|
* @example me.loader.unloadAll();
|
|
645
638
|
*/
|
|
646
639
|
unloadAll() {
|
|
@@ -695,7 +688,6 @@ var loader = {
|
|
|
695
688
|
* @name getTMX
|
|
696
689
|
* @memberof loader
|
|
697
690
|
* @public
|
|
698
|
-
* @function
|
|
699
691
|
* @param {string} elt name of the tmx/tsx element ("map1");
|
|
700
692
|
* @returns {object} requested element or null if not found
|
|
701
693
|
*/
|
|
@@ -713,7 +705,6 @@ var loader = {
|
|
|
713
705
|
* @name getBinary
|
|
714
706
|
* @memberof loader
|
|
715
707
|
* @public
|
|
716
|
-
* @function
|
|
717
708
|
* @param {string} elt name of the binary object ("ymTrack");
|
|
718
709
|
* @returns {object} requested element or null if not found
|
|
719
710
|
*/
|
|
@@ -731,7 +722,6 @@ var loader = {
|
|
|
731
722
|
* @name getImage
|
|
732
723
|
* @memberof loader
|
|
733
724
|
* @public
|
|
734
|
-
* @function
|
|
735
725
|
* @param {string} image name of the Image element ("tileset-platformer");
|
|
736
726
|
* @returns {HTMLImageElement} requested element or null if not found
|
|
737
727
|
*/
|
|
@@ -750,7 +740,6 @@ var loader = {
|
|
|
750
740
|
* @name getJSON
|
|
751
741
|
* @memberof loader
|
|
752
742
|
* @public
|
|
753
|
-
* @function
|
|
754
743
|
* @param {string} elt name of the json file to load
|
|
755
744
|
* @returns {object}
|
|
756
745
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { world, viewport } from "./../game.js";
|
|
2
|
-
import {
|
|
2
|
+
import { renderer } from "./../video/video.js";
|
|
3
3
|
import * as event from "./../system/event.js";
|
|
4
4
|
import {nextPowerOfTwo} from "./../math/math.js";
|
|
5
5
|
import pool from "./../system/pooling.js";
|
|
@@ -69,13 +69,13 @@ class IconLogo extends Renderable {
|
|
|
69
69
|
constructor(x, y) {
|
|
70
70
|
super(x, y, 100, 85);
|
|
71
71
|
|
|
72
|
-
this.
|
|
72
|
+
this.iconTexture = pool.pull("CanvasTexture",
|
|
73
73
|
renderer.WebGLVersion > 1 ? this.width : nextPowerOfTwo(this.width),
|
|
74
74
|
renderer.WebGLVersion > 1 ? this.height : nextPowerOfTwo(this.height),
|
|
75
|
-
|
|
75
|
+
{ offscreenCanvas: true }
|
|
76
76
|
);
|
|
77
77
|
|
|
78
|
-
var context =
|
|
78
|
+
var context = this.iconTexture.context;
|
|
79
79
|
|
|
80
80
|
context.beginPath();
|
|
81
81
|
context.moveTo(0.7, 48.9);
|
|
@@ -110,7 +110,18 @@ class IconLogo extends Renderable {
|
|
|
110
110
|
* @ignore
|
|
111
111
|
*/
|
|
112
112
|
draw(renderer) {
|
|
113
|
-
renderer.drawImage(this.
|
|
113
|
+
renderer.drawImage(this.iconTexture.canvas, renderer.getWidth() / 2, this.pos.y);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Destroy function
|
|
118
|
+
* @ignore
|
|
119
|
+
*/
|
|
120
|
+
destroy() {
|
|
121
|
+
// call the parent destroy method
|
|
122
|
+
super.destroy(arguments);
|
|
123
|
+
pool.push(this.iconTexture);
|
|
124
|
+
this.iconTexture = undefined;
|
|
114
125
|
}
|
|
115
126
|
};
|
|
116
127
|
|
package/src/math/color.js
CHANGED
|
@@ -6,11 +6,11 @@ var toHex = function (component) {
|
|
|
6
6
|
return "0123456789ABCDEF".charAt((component - (component % 16)) >> 4) + "0123456789ABCDEF".charAt(component % 16);
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const rgbaRx = /^rgba?\((\d+), ?(\d+), ?(\d+)(, ?([\d\.]+))?\)$/;
|
|
10
|
+
const hex3Rx = /^#([\da-fA-F])([\da-fA-F])([\da-fA-F])$/;
|
|
11
|
+
const hex4Rx = /^#([\da-fA-F])([\da-fA-F])([\da-fA-F])([\da-fA-F])$/;
|
|
12
|
+
const hex6Rx = /^#([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})$/;
|
|
13
|
+
const hex8Rx = /^#([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})$/;
|
|
14
14
|
|
|
15
15
|
var cssToRGB = new Map();
|
|
16
16
|
|
|
@@ -188,9 +188,6 @@ class Color {
|
|
|
188
188
|
* @ignore
|
|
189
189
|
*/
|
|
190
190
|
onResetEvent(r = 0, g = 0, b = 0, alpha = 1.0) {
|
|
191
|
-
/**
|
|
192
|
-
* @ignore
|
|
193
|
-
*/
|
|
194
191
|
if (typeof (this.glArray) === "undefined") {
|
|
195
192
|
// Color components in a Float32Array suitable for WebGL
|
|
196
193
|
this.glArray = new Float32Array([ 0.0, 0.0, 0.0, 1.0 ]);
|
|
@@ -257,7 +254,6 @@ class Color {
|
|
|
257
254
|
* Set this color to the specified value.
|
|
258
255
|
* @name setColor
|
|
259
256
|
* @memberof Color
|
|
260
|
-
* @function
|
|
261
257
|
* @param {number} r red component [0 .. 255]
|
|
262
258
|
* @param {number} g green component [0 .. 255]
|
|
263
259
|
* @param {number} b blue component [0 .. 255]
|
|
@@ -276,7 +272,6 @@ class Color {
|
|
|
276
272
|
* Create a new copy of this color object.
|
|
277
273
|
* @name clone
|
|
278
274
|
* @memberof Color
|
|
279
|
-
* @function
|
|
280
275
|
* @returns {Color} Reference to the newly cloned object
|
|
281
276
|
*/
|
|
282
277
|
clone() {
|
|
@@ -287,7 +282,6 @@ class Color {
|
|
|
287
282
|
* Copy a color object or CSS color into this one.
|
|
288
283
|
* @name copy
|
|
289
284
|
* @memberof Color
|
|
290
|
-
* @function
|
|
291
285
|
* @param {Color|string} color
|
|
292
286
|
* @returns {Color} Reference to this object for method chaining
|
|
293
287
|
*/
|
|
@@ -304,7 +298,6 @@ class Color {
|
|
|
304
298
|
* Blend this color with the given one using addition.
|
|
305
299
|
* @name add
|
|
306
300
|
* @memberof Color
|
|
307
|
-
* @function
|
|
308
301
|
* @param {Color} color
|
|
309
302
|
* @returns {Color} Reference to this object for method chaining
|
|
310
303
|
*/
|
|
@@ -321,7 +314,6 @@ class Color {
|
|
|
321
314
|
* Darken this color value by 0..1
|
|
322
315
|
* @name darken
|
|
323
316
|
* @memberof Color
|
|
324
|
-
* @function
|
|
325
317
|
* @param {number} scale
|
|
326
318
|
* @returns {Color} Reference to this object for method chaining
|
|
327
319
|
*/
|
|
@@ -338,7 +330,6 @@ class Color {
|
|
|
338
330
|
* Linearly interpolate between this color and the given one.
|
|
339
331
|
* @name lerp
|
|
340
332
|
* @memberof Color
|
|
341
|
-
* @function
|
|
342
333
|
* @param {Color} color
|
|
343
334
|
* @param {number} alpha with alpha = 0 being this color, and alpha = 1 being the given one.
|
|
344
335
|
* @returns {Color} Reference to this object for method chaining
|
|
@@ -356,7 +347,6 @@ class Color {
|
|
|
356
347
|
* Lighten this color value by 0..1
|
|
357
348
|
* @name lighten
|
|
358
349
|
* @memberof Color
|
|
359
|
-
* @function
|
|
360
350
|
* @param {number} scale
|
|
361
351
|
* @returns {Color} Reference to this object for method chaining
|
|
362
352
|
*/
|
|
@@ -373,7 +363,6 @@ class Color {
|
|
|
373
363
|
* Generate random r,g,b values for this color object
|
|
374
364
|
* @name random
|
|
375
365
|
* @memberof Color
|
|
376
|
-
* @function
|
|
377
366
|
* @param {number} [min=0] minimum value for the random range
|
|
378
367
|
* @param {number} [max=255] maxmium value for the random range
|
|
379
368
|
* @returns {Color} Reference to this object for method chaining
|
|
@@ -399,7 +388,6 @@ class Color {
|
|
|
399
388
|
* given one.
|
|
400
389
|
* @name equals
|
|
401
390
|
* @memberof Color
|
|
402
|
-
* @function
|
|
403
391
|
* @param {Color} color
|
|
404
392
|
* @returns {boolean}
|
|
405
393
|
*/
|
|
@@ -417,7 +405,6 @@ class Color {
|
|
|
417
405
|
* r,g,b values
|
|
418
406
|
* @name parseCSS
|
|
419
407
|
* @memberof Color
|
|
420
|
-
* @function
|
|
421
408
|
* @param {string} cssColor
|
|
422
409
|
* @returns {Color} Reference to this object for method chaining
|
|
423
410
|
*/
|
|
@@ -435,7 +422,6 @@ class Color {
|
|
|
435
422
|
* Parse an RGB or RGBA CSS color string
|
|
436
423
|
* @name parseRGB
|
|
437
424
|
* @memberof Color
|
|
438
|
-
* @function
|
|
439
425
|
* @param {string} rgbColor
|
|
440
426
|
* @returns {Color} Reference to this object for method chaining
|
|
441
427
|
*/
|
|
@@ -455,7 +441,6 @@ class Color {
|
|
|
455
441
|
* the corresponding r,g,b,a values
|
|
456
442
|
* @name parseHex
|
|
457
443
|
* @memberof Color
|
|
458
|
-
* @function
|
|
459
444
|
* @param {string} hexColor
|
|
460
445
|
* @param {boolean} [argb = false] true if format is #ARGB, or #AARRGGBB (as opposed to #RGBA or #RGGBBAA)
|
|
461
446
|
* @returns {Color} Reference to this object for method chaining
|
|
@@ -515,7 +500,6 @@ class Color {
|
|
|
515
500
|
* Pack this color into a Uint32 ARGB representation
|
|
516
501
|
* @name toUint32
|
|
517
502
|
* @memberof Color
|
|
518
|
-
* @function
|
|
519
503
|
* @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
|
|
520
504
|
* @returns {number}
|
|
521
505
|
*/
|
|
@@ -532,7 +516,6 @@ class Color {
|
|
|
532
516
|
* return an array representation of this object
|
|
533
517
|
* @name toArray
|
|
534
518
|
* @memberof Color
|
|
535
|
-
* @function
|
|
536
519
|
* @returns {Float32Array}
|
|
537
520
|
*/
|
|
538
521
|
toArray() {
|
|
@@ -544,7 +527,6 @@ class Color {
|
|
|
544
527
|
* Get the color in "#RRGGBB" format
|
|
545
528
|
* @name toHex
|
|
546
529
|
* @memberof Color
|
|
547
|
-
* @function
|
|
548
530
|
* @returns {string}
|
|
549
531
|
*/
|
|
550
532
|
toHex() {
|
|
@@ -558,21 +540,19 @@ class Color {
|
|
|
558
540
|
* Get the color in "#RRGGBBAA" format
|
|
559
541
|
* @name toHex8
|
|
560
542
|
* @memberof Color
|
|
561
|
-
* @function
|
|
562
543
|
* @returns {string}
|
|
563
544
|
*/
|
|
564
|
-
toHex8() {
|
|
545
|
+
toHex8(alpha = this.alpha) {
|
|
565
546
|
// TODO : Memoize this function by caching its result until any of
|
|
566
547
|
// the r,g,b,a values are changed
|
|
567
548
|
|
|
568
|
-
return "#" + toHex(this.r) + toHex(this.g) + toHex(this.b) + toHex(
|
|
549
|
+
return "#" + toHex(this.r) + toHex(this.g) + toHex(this.b) + toHex(alpha * 255);
|
|
569
550
|
}
|
|
570
551
|
|
|
571
552
|
/**
|
|
572
553
|
* Get the color in "rgb(R,G,B)" format
|
|
573
554
|
* @name toRGB
|
|
574
555
|
* @memberof Color
|
|
575
|
-
* @function
|
|
576
556
|
* @returns {string}
|
|
577
557
|
*/
|
|
578
558
|
toRGB() {
|
|
@@ -590,10 +570,10 @@ class Color {
|
|
|
590
570
|
* Get the color in "rgba(R,G,B,A)" format
|
|
591
571
|
* @name toRGBA
|
|
592
572
|
* @memberof Color
|
|
593
|
-
* @
|
|
573
|
+
* @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
|
|
594
574
|
* @returns {string}
|
|
595
575
|
*/
|
|
596
|
-
toRGBA() {
|
|
576
|
+
toRGBA(alpha = this.alpha) {
|
|
597
577
|
// TODO : Memoize this function by caching its result until any of
|
|
598
578
|
// the r,g,b,a values are changed
|
|
599
579
|
|
|
@@ -601,7 +581,7 @@ class Color {
|
|
|
601
581
|
this.r + "," +
|
|
602
582
|
this.g + "," +
|
|
603
583
|
this.b + "," +
|
|
604
|
-
|
|
584
|
+
alpha +
|
|
605
585
|
")";
|
|
606
586
|
}
|
|
607
587
|
};
|
package/src/math/math.js
CHANGED
|
@@ -51,7 +51,6 @@ export const EPSILON = 0.000001;
|
|
|
51
51
|
/**
|
|
52
52
|
* returns true if the given value is a power of two
|
|
53
53
|
* @public
|
|
54
|
-
* @function
|
|
55
54
|
* @memberof Math
|
|
56
55
|
* @name isPowerOfTwo
|
|
57
56
|
* @param {number} val
|
|
@@ -64,7 +63,6 @@ export function isPowerOfTwo(val) {
|
|
|
64
63
|
/**
|
|
65
64
|
* returns the next power of two for the given value
|
|
66
65
|
* @public
|
|
67
|
-
* @function
|
|
68
66
|
* @memberof Math
|
|
69
67
|
* @name nextPowerOfTwo
|
|
70
68
|
* @param {number} val
|
|
@@ -84,7 +82,6 @@ export function nextPowerOfTwo(val) {
|
|
|
84
82
|
/**
|
|
85
83
|
* Converts an angle in degrees to an angle in radians
|
|
86
84
|
* @public
|
|
87
|
-
* @function
|
|
88
85
|
* @memberof Math
|
|
89
86
|
* @name degToRad
|
|
90
87
|
* @param {number} angle angle in degrees
|
|
@@ -100,7 +97,6 @@ export function degToRad(angle) {
|
|
|
100
97
|
/**
|
|
101
98
|
* Converts an angle in radians to an angle in degrees.
|
|
102
99
|
* @public
|
|
103
|
-
* @function
|
|
104
100
|
* @memberof Math
|
|
105
101
|
* @name radToDeg
|
|
106
102
|
* @param {number} radians angle in radians
|
|
@@ -116,7 +112,6 @@ export function radToDeg(radians) {
|
|
|
116
112
|
/**
|
|
117
113
|
* clamp the given value
|
|
118
114
|
* @public
|
|
119
|
-
* @function
|
|
120
115
|
* @memberof Math
|
|
121
116
|
* @name clamp
|
|
122
117
|
* @param {number} val the value to clamp
|
|
@@ -131,7 +126,6 @@ export function clamp(val, low, high) {
|
|
|
131
126
|
/**
|
|
132
127
|
* return a random integer between min (included) and max (excluded)
|
|
133
128
|
* @public
|
|
134
|
-
* @function
|
|
135
129
|
* @memberof Math
|
|
136
130
|
* @name random
|
|
137
131
|
* @param {number} min minimum value.
|
|
@@ -148,7 +142,6 @@ export function random(min, max) {
|
|
|
148
142
|
/**
|
|
149
143
|
* return a random float between min, max (exclusive)
|
|
150
144
|
* @public
|
|
151
|
-
* @function
|
|
152
145
|
* @memberof Math
|
|
153
146
|
* @name randomFloat
|
|
154
147
|
* @param {number} min minimum value.
|
|
@@ -165,7 +158,6 @@ export function randomFloat(min, max) {
|
|
|
165
158
|
/**
|
|
166
159
|
* return a weighted random between min, max (exclusive)
|
|
167
160
|
* @public
|
|
168
|
-
* @function
|
|
169
161
|
* @memberof Math
|
|
170
162
|
* @name weightedRandom
|
|
171
163
|
* @param {number} min minimum value.
|
|
@@ -182,7 +174,6 @@ export function weightedRandom(min, max) {
|
|
|
182
174
|
/**
|
|
183
175
|
* round a value to the specified number of digit
|
|
184
176
|
* @public
|
|
185
|
-
* @function
|
|
186
177
|
* @memberof Math
|
|
187
178
|
* @name round
|
|
188
179
|
* @param {number} num value to be rounded.
|
|
@@ -201,7 +192,6 @@ export function round(num, dec = 0) {
|
|
|
201
192
|
/**
|
|
202
193
|
* check if the given value is close to the expected one
|
|
203
194
|
* @public
|
|
204
|
-
* @function
|
|
205
195
|
* @memberof Math
|
|
206
196
|
* @name toBeCloseTo
|
|
207
197
|
* @param {number} expected value to be compared with.
|
package/src/math/matrix2.js
CHANGED
|
@@ -68,7 +68,6 @@ class Matrix2d {
|
|
|
68
68
|
* <img src="images/identity-matrix_2x.png"/>
|
|
69
69
|
* @name identity
|
|
70
70
|
* @memberof Matrix2d
|
|
71
|
-
* @function
|
|
72
71
|
* @returns {Matrix2d} Reference to this object for method chaining
|
|
73
72
|
*/
|
|
74
73
|
identity() {
|
|
@@ -84,7 +83,6 @@ class Matrix2d {
|
|
|
84
83
|
* set the matrix to the specified value
|
|
85
84
|
* @name setTransform
|
|
86
85
|
* @memberof Matrix2d
|
|
87
|
-
* @function
|
|
88
86
|
* @param {number} a
|
|
89
87
|
* @param {number} b
|
|
90
88
|
* @param {number} c
|
|
@@ -128,7 +126,6 @@ class Matrix2d {
|
|
|
128
126
|
* Copies over the values from another me.Matrix2d.
|
|
129
127
|
* @name copy
|
|
130
128
|
* @memberof Matrix2d
|
|
131
|
-
* @function
|
|
132
129
|
* @param {Matrix2d} m the matrix object to copy from
|
|
133
130
|
* @returns {Matrix2d} Reference to this object for method chaining
|
|
134
131
|
*/
|
|
@@ -141,7 +138,6 @@ class Matrix2d {
|
|
|
141
138
|
* Copies over the upper-left 3x3 values from the given me.Matrix3d
|
|
142
139
|
* @name fromMat3d
|
|
143
140
|
* @memberof Matrix2d
|
|
144
|
-
* @function
|
|
145
141
|
* @param {Matrix3d} m the matrix object to copy from
|
|
146
142
|
* @returns {Matrix2d} Reference to this object for method chaining
|
|
147
143
|
*/
|
|
@@ -166,7 +162,6 @@ class Matrix2d {
|
|
|
166
162
|
* multiply both matrix
|
|
167
163
|
* @name multiply
|
|
168
164
|
* @memberof Matrix2d
|
|
169
|
-
* @function
|
|
170
165
|
* @param {Matrix2d} m the other matrix
|
|
171
166
|
* @returns {Matrix2d} Reference to this object for method chaining
|
|
172
167
|
*/
|
|
@@ -198,7 +193,6 @@ class Matrix2d {
|
|
|
198
193
|
* Transpose the value of this matrix.
|
|
199
194
|
* @name transpose
|
|
200
195
|
* @memberof Matrix2d
|
|
201
|
-
* @function
|
|
202
196
|
* @returns {Matrix2d} Reference to this object for method chaining
|
|
203
197
|
*/
|
|
204
198
|
transpose() {
|
|
@@ -221,7 +215,6 @@ class Matrix2d {
|
|
|
221
215
|
* invert this matrix, causing it to apply the opposite transformation.
|
|
222
216
|
* @name invert
|
|
223
217
|
* @memberof Matrix2d
|
|
224
|
-
* @function
|
|
225
218
|
* @returns {Matrix2d} Reference to this object for method chaining
|
|
226
219
|
*/
|
|
227
220
|
invert() {
|
|
@@ -253,20 +246,24 @@ class Matrix2d {
|
|
|
253
246
|
}
|
|
254
247
|
|
|
255
248
|
/**
|
|
256
|
-
* apply the current transform to the given 2d vector
|
|
249
|
+
* apply the current transform to the given 2d or 3d vector
|
|
257
250
|
* @name apply
|
|
258
251
|
* @memberof Matrix2d
|
|
259
|
-
* @
|
|
260
|
-
* @
|
|
261
|
-
* @returns {Vector2d} result vector object.
|
|
252
|
+
* @param {Vector2d|Vector3d} v the vector object to be transformed
|
|
253
|
+
* @returns {Vector2d|Vector3d} result vector object.
|
|
262
254
|
*/
|
|
263
255
|
apply(v) {
|
|
264
256
|
var a = this.val,
|
|
265
257
|
x = v.x,
|
|
266
|
-
y = v.y
|
|
258
|
+
y = v.y,
|
|
259
|
+
z = (typeof v.z !== "undefined") ? v.z : 1;
|
|
260
|
+
|
|
261
|
+
v.x = x * a[0] + y * a[3] + z * a[6];
|
|
262
|
+
v.y = x * a[1] + y * a[4] + z * a[7];
|
|
267
263
|
|
|
268
|
-
v.
|
|
269
|
-
|
|
264
|
+
if (typeof v.z !== "undefined") {
|
|
265
|
+
v.z = x * a[2] + y * a[5] + z * a[8];
|
|
266
|
+
}
|
|
270
267
|
|
|
271
268
|
return v;
|
|
272
269
|
}
|
|
@@ -275,7 +272,6 @@ class Matrix2d {
|
|
|
275
272
|
* apply the inverted current transform to the given 2d vector
|
|
276
273
|
* @name applyInverse
|
|
277
274
|
* @memberof Matrix2d
|
|
278
|
-
* @function
|
|
279
275
|
* @param {Vector2d} v the vector object to be transformed
|
|
280
276
|
* @returns {Vector2d} result vector object.
|
|
281
277
|
*/
|
|
@@ -296,7 +292,6 @@ class Matrix2d {
|
|
|
296
292
|
* scale the matrix
|
|
297
293
|
* @name scale
|
|
298
294
|
* @memberof Matrix2d
|
|
299
|
-
* @function
|
|
300
295
|
* @param {number} x a number representing the abscissa of the scaling vector.
|
|
301
296
|
* @param {number} [y=x] a number representing the ordinate of the scaling vector.
|
|
302
297
|
* @returns {Matrix2d} Reference to this object for method chaining
|
|
@@ -318,7 +313,6 @@ class Matrix2d {
|
|
|
318
313
|
* adds a 2D scaling transformation.
|
|
319
314
|
* @name scaleV
|
|
320
315
|
* @memberof Matrix2d
|
|
321
|
-
* @function
|
|
322
316
|
* @param {Vector2d} v scaling vector
|
|
323
317
|
* @returns {Matrix2d} Reference to this object for method chaining
|
|
324
318
|
*/
|
|
@@ -330,7 +324,6 @@ class Matrix2d {
|
|
|
330
324
|
* specifies a 2D scale operation using the [sx, 1] scaling vector
|
|
331
325
|
* @name scaleX
|
|
332
326
|
* @memberof Matrix2d
|
|
333
|
-
* @function
|
|
334
327
|
* @param {number} x x scaling vector
|
|
335
328
|
* @returns {Matrix2d} Reference to this object for method chaining
|
|
336
329
|
*/
|
|
@@ -342,7 +335,6 @@ class Matrix2d {
|
|
|
342
335
|
* specifies a 2D scale operation using the [1,sy] scaling vector
|
|
343
336
|
* @name scaleY
|
|
344
337
|
* @memberof Matrix2d
|
|
345
|
-
* @function
|
|
346
338
|
* @param {number} y y scaling vector
|
|
347
339
|
* @returns {Matrix2d} Reference to this object for method chaining
|
|
348
340
|
*/
|
|
@@ -354,7 +346,6 @@ class Matrix2d {
|
|
|
354
346
|
* rotate the matrix (counter-clockwise) by the specified angle (in radians).
|
|
355
347
|
* @name rotate
|
|
356
348
|
* @memberof Matrix2d
|
|
357
|
-
* @function
|
|
358
349
|
* @param {number} angle Rotation angle in radians.
|
|
359
350
|
* @returns {Matrix2d} Reference to this object for method chaining
|
|
360
351
|
*/
|
|
@@ -385,7 +376,7 @@ class Matrix2d {
|
|
|
385
376
|
* translate the matrix position on the horizontal and vertical axis
|
|
386
377
|
* @name translate
|
|
387
378
|
* @memberof Matrix2d
|
|
388
|
-
* @
|
|
379
|
+
* @method
|
|
389
380
|
* @param {number} x the x coordindates to translate the matrix by
|
|
390
381
|
* @param {number} y the y coordindates to translate the matrix by
|
|
391
382
|
* @returns {Matrix2d} Reference to this object for method chaining
|
|
@@ -394,7 +385,6 @@ class Matrix2d {
|
|
|
394
385
|
* translate the matrix by a vector on the horizontal and vertical axis
|
|
395
386
|
* @name translateV
|
|
396
387
|
* @memberof Matrix2d
|
|
397
|
-
* @function
|
|
398
388
|
* @param {Vector2d} v the vector to translate the matrix by
|
|
399
389
|
* @returns {Matrix2d} Reference to this object for method chaining
|
|
400
390
|
*/
|
|
@@ -422,7 +412,6 @@ class Matrix2d {
|
|
|
422
412
|
* returns true if the matrix is an identity matrix.
|
|
423
413
|
* @name isIdentity
|
|
424
414
|
* @memberof Matrix2d
|
|
425
|
-
* @function
|
|
426
415
|
* @returns {boolean}
|
|
427
416
|
*/
|
|
428
417
|
isIdentity() {
|
|
@@ -445,7 +434,6 @@ class Matrix2d {
|
|
|
445
434
|
* return true if the two matrices are identical
|
|
446
435
|
* @name equals
|
|
447
436
|
* @memberof Matrix2d
|
|
448
|
-
* @function
|
|
449
437
|
* @param {Matrix2d} m the other matrix
|
|
450
438
|
* @returns {boolean} true if both are equals
|
|
451
439
|
*/
|
|
@@ -470,7 +458,6 @@ class Matrix2d {
|
|
|
470
458
|
* Clone the Matrix
|
|
471
459
|
* @name clone
|
|
472
460
|
* @memberof Matrix2d
|
|
473
|
-
* @function
|
|
474
461
|
* @returns {Matrix2d}
|
|
475
462
|
*/
|
|
476
463
|
clone() {
|
|
@@ -481,7 +468,6 @@ class Matrix2d {
|
|
|
481
468
|
* return an array representation of this Matrix
|
|
482
469
|
* @name toArray
|
|
483
470
|
* @memberof Matrix2d
|
|
484
|
-
* @function
|
|
485
471
|
* @returns {Float32Array}
|
|
486
472
|
*/
|
|
487
473
|
toArray() {
|
|
@@ -492,7 +478,6 @@ class Matrix2d {
|
|
|
492
478
|
* convert the object to a string representation
|
|
493
479
|
* @name toString
|
|
494
480
|
* @memberof Matrix2d
|
|
495
|
-
* @function
|
|
496
481
|
* @returns {string}
|
|
497
482
|
*/
|
|
498
483
|
toString() {
|