melonjs 15.3.0 → 15.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
- package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
- package/dist/melonjs.mjs/_virtual/howler.js +1 -1
- package/dist/melonjs.mjs/_virtual/index.js +1 -1
- package/dist/melonjs.mjs/application/application.js +53 -5
- package/dist/melonjs.mjs/application/header.js +2 -2
- package/dist/melonjs.mjs/application/resize.js +4 -8
- package/dist/melonjs.mjs/application/settings.js +5 -5
- package/dist/melonjs.mjs/audio/audio.js +4 -6
- package/dist/melonjs.mjs/camera/camera2d.js +12 -14
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +3 -4
- package/dist/melonjs.mjs/geometries/ellipse.js +26 -59
- package/dist/melonjs.mjs/geometries/line.js +18 -25
- package/dist/melonjs.mjs/geometries/path2d.js +16 -13
- package/dist/melonjs.mjs/geometries/point.js +8 -16
- package/dist/melonjs.mjs/geometries/poly.js +40 -97
- package/dist/melonjs.mjs/geometries/rectangle.js +37 -91
- package/dist/melonjs.mjs/geometries/roundrect.js +26 -35
- package/dist/melonjs.mjs/index.js +6 -6
- package/dist/melonjs.mjs/input/gamepad.js +1 -1
- package/dist/melonjs.mjs/input/input.js +1 -1
- package/dist/melonjs.mjs/input/keyboard.js +3 -3
- package/dist/melonjs.mjs/input/pointer.js +4 -4
- package/dist/melonjs.mjs/input/pointerevent.js +6 -7
- package/dist/melonjs.mjs/lang/console.js +1 -1
- package/dist/melonjs.mjs/lang/deprecated.js +2 -2
- package/dist/melonjs.mjs/level/level.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +16 -33
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +3 -4
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +4 -4
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +4 -7
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +2 -2
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +26 -29
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +3 -3
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +1 -1
- package/dist/melonjs.mjs/loader/loader.js +1 -1
- package/dist/melonjs.mjs/loader/loadingscreen.js +1 -1
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +4 -5
- package/dist/melonjs.mjs/loader/settings.js +1 -1
- package/dist/melonjs.mjs/math/color.js +2 -2
- package/dist/melonjs.mjs/math/math.js +1 -1
- package/dist/melonjs.mjs/math/matrix2.js +5 -59
- package/dist/melonjs.mjs/math/matrix3.js +82 -141
- package/dist/melonjs.mjs/math/observable_vector2.js +7 -7
- package/dist/melonjs.mjs/math/observable_vector3.js +5 -5
- package/dist/melonjs.mjs/math/vector2.js +7 -91
- package/dist/melonjs.mjs/math/vector3.js +6 -90
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
- package/dist/melonjs.mjs/particles/emitter.js +2 -2
- package/dist/melonjs.mjs/particles/particle.js +2 -2
- package/dist/melonjs.mjs/particles/settings.js +1 -1
- package/dist/melonjs.mjs/physics/body.js +22 -20
- package/dist/melonjs.mjs/physics/bounds.js +27 -33
- package/dist/melonjs.mjs/physics/collision.js +5 -5
- package/dist/melonjs.mjs/physics/detector.js +10 -10
- package/dist/melonjs.mjs/physics/quadtree.js +5 -5
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +3 -4
- package/dist/melonjs.mjs/physics/world.js +6 -9
- package/dist/melonjs.mjs/plugin/plugin.js +3 -3
- package/dist/melonjs.mjs/renderable/collectable.js +2 -2
- package/dist/melonjs.mjs/renderable/colorlayer.js +4 -4
- package/dist/melonjs.mjs/renderable/container.js +25 -25
- package/dist/melonjs.mjs/renderable/draggable.js +1 -1
- package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
- package/dist/melonjs.mjs/renderable/imagelayer.js +4 -4
- package/dist/melonjs.mjs/renderable/light2d.js +3 -3
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +2 -2
- package/dist/melonjs.mjs/renderable/renderable.js +26 -26
- package/dist/melonjs.mjs/renderable/sprite.js +3 -3
- package/dist/melonjs.mjs/renderable/text/bitmaptext.js +421 -0
- package/dist/melonjs.mjs/renderable/text/bitmaptextdata.js +195 -0
- package/dist/melonjs.mjs/renderable/text/glyph.js +65 -0
- package/dist/melonjs.mjs/renderable/text/text.js +422 -0
- package/dist/melonjs.mjs/renderable/text/textmetrics.js +175 -0
- package/dist/melonjs.mjs/renderable/text/textstyle.js +21 -0
- package/dist/melonjs.mjs/renderable/trigger.js +10 -10
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +7 -7
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +7 -7
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +3 -3
- package/dist/melonjs.mjs/state/stage.js +2 -2
- package/dist/melonjs.mjs/state/state.js +1 -38
- package/dist/melonjs.mjs/system/device.js +49 -10
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +24 -2
- package/dist/melonjs.mjs/system/platform.js +18 -18
- package/dist/melonjs.mjs/system/pooling.js +10 -10
- package/dist/melonjs.mjs/system/save.js +1 -1
- package/dist/melonjs.mjs/system/timer.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptext.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptextdata.js +3 -6
- package/dist/melonjs.mjs/text/glyph.js +1 -1
- package/dist/melonjs.mjs/text/text.js +1 -1
- package/dist/melonjs.mjs/text/textmetrics.js +1 -1
- package/dist/melonjs.mjs/text/textstyle.js +1 -1
- package/dist/melonjs.mjs/tweens/easing.js +1 -1
- package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
- package/dist/melonjs.mjs/tweens/tween.js +2 -2
- package/dist/melonjs.mjs/utils/agent.js +1 -1
- package/dist/melonjs.mjs/utils/array.js +1 -1
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +2 -3
- package/dist/melonjs.mjs/utils/string.js +1 -1
- package/dist/melonjs.mjs/utils/utils.js +1 -1
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +3 -7
- package/dist/melonjs.mjs/video/renderer.js +16 -16
- package/dist/melonjs.mjs/video/texture/atlas.js +13 -13
- package/dist/melonjs.mjs/video/texture/cache.js +1 -1
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +15 -15
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +4 -4
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +3 -3
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +13 -14
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +2 -3
- package/dist/melonjs.mjs/video/webgl/glshader.js +2 -2
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +4 -4
- package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +50 -52
- package/dist/melonjs.module.js +1137 -1576
- package/dist/types/application/application.d.ts +28 -4
- package/dist/types/application/header.d.ts +2 -2
- package/dist/types/application/settings.d.ts +23 -23
- package/dist/types/audio/audio.d.ts +3 -5
- package/dist/types/camera/camera2d.d.ts +13 -16
- package/dist/types/entity/entity.d.ts +0 -1
- package/dist/types/geometries/ellipse.d.ts +18 -50
- package/dist/types/geometries/path2d.d.ts +1 -1
- package/dist/types/geometries/point.d.ts +5 -13
- package/dist/types/geometries/poly.d.ts +26 -75
- package/dist/types/geometries/rectangle.d.ts +12 -58
- package/dist/types/geometries/roundrect.d.ts +2 -11
- package/dist/types/index.d.ts +3 -3
- package/dist/types/input/gamepad.d.ts +31 -31
- package/dist/types/input/keyboard.d.ts +105 -105
- package/dist/types/input/pointer.d.ts +21 -21
- package/dist/types/input/pointerevent.d.ts +6 -6
- package/dist/types/level/tiled/TMXLayer.d.ts +1 -1
- package/dist/types/math/matrix2.d.ts +9 -63
- package/dist/types/math/matrix3.d.ts +9 -68
- package/dist/types/math/observable_vector2.d.ts +2 -2
- package/dist/types/math/observable_vector3.d.ts +2 -2
- package/dist/types/math/vector2.d.ts +8 -92
- package/dist/types/math/vector3.d.ts +8 -92
- package/dist/types/particles/settings.d.ts +29 -29
- package/dist/types/physics/body.d.ts +10 -8
- package/dist/types/physics/bounds.d.ts +24 -30
- package/dist/types/physics/collision.d.ts +12 -12
- package/dist/types/physics/detector.d.ts +1 -1
- package/dist/types/physics/world.d.ts +4 -7
- package/dist/types/renderable/container.d.ts +19 -19
- package/dist/types/renderable/imagelayer.d.ts +6 -6
- package/dist/types/renderable/light2d.d.ts +7 -7
- package/dist/types/renderable/renderable.d.ts +9 -16
- package/dist/types/renderable/text/bitmaptext.d.ts +151 -0
- package/dist/types/renderable/text/bitmaptextdata.d.ts +35 -0
- package/dist/types/renderable/text/glyph.d.ts +28 -0
- package/dist/types/renderable/text/text.d.ts +159 -0
- package/dist/types/renderable/text/textmetrics.d.ts +47 -0
- package/dist/types/renderable/text/textstyle.d.ts +5 -0
- package/dist/types/renderable/ui/uibaseelement.d.ts +0 -1
- package/dist/types/renderable/ui/uispriteelement.d.ts +0 -1
- package/dist/types/renderable/ui/uitextbutton.d.ts +2 -7
- package/dist/types/state/state.d.ts +11 -11
- package/dist/types/system/device.d.ts +15 -9
- package/dist/types/system/event.d.ts +20 -0
- package/dist/types/system/platform.d.ts +17 -17
- package/dist/types/utils/function.d.ts +1 -2
- package/dist/types/video/renderer.d.ts +13 -13
- package/dist/types/video/texture/canvas_texture.d.ts +14 -14
- package/dist/types/video/video.d.ts +2 -2
- package/dist/types/video/webgl/buffer/vertex.d.ts +2 -2
- package/dist/types/video/webgl/compositors/compositor.d.ts +24 -13
- package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +0 -1
- package/dist/types/video/webgl/compositors/quad_compositor.d.ts +0 -1
- package/dist/types/video/webgl/utils/precision.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +47 -50
- package/package.json +15 -15
- package/src/application/application.js +51 -3
- package/src/application/header.js +1 -1
- package/src/application/resize.js +3 -7
- package/src/application/settings.js +4 -4
- package/src/audio/audio.js +3 -5
- package/src/camera/camera2d.js +11 -13
- package/src/entity/entity.js +2 -3
- package/src/geometries/ellipse.js +25 -58
- package/src/geometries/line.js +17 -24
- package/src/geometries/path2d.js +15 -12
- package/src/geometries/point.js +7 -15
- package/src/geometries/poly.js +39 -96
- package/src/geometries/rectangle.js +36 -90
- package/src/geometries/roundrect.js +25 -34
- package/src/index.js +4 -4
- package/src/input/keyboard.js +2 -2
- package/src/input/pointer.js +3 -3
- package/src/input/pointerevent.js +5 -6
- package/src/lang/deprecated.js +1 -1
- package/src/level/tiled/TMXLayer.js +15 -32
- package/src/level/tiled/TMXObject.js +2 -3
- package/src/level/tiled/TMXTile.js +3 -3
- package/src/level/tiled/TMXTileMap.js +2 -2
- package/src/level/tiled/TMXTileset.js +3 -6
- package/src/level/tiled/TMXTilesetGroup.js +1 -1
- package/src/level/tiled/TMXUtils.js +25 -28
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/src/loader/parser.js +3 -4
- package/src/math/color.js +1 -1
- package/src/math/matrix2.js +4 -58
- package/src/math/matrix3.js +81 -140
- package/src/math/observable_vector2.js +6 -6
- package/src/math/observable_vector3.js +4 -4
- package/src/math/vector2.js +6 -90
- package/src/math/vector3.js +5 -89
- package/src/particles/emitter.js +1 -1
- package/src/particles/particle.js +1 -1
- package/src/physics/body.js +21 -19
- package/src/physics/bounds.js +26 -32
- package/src/physics/collision.js +4 -4
- package/src/physics/detector.js +9 -9
- package/src/physics/quadtree.js +4 -4
- package/src/physics/sat.js +2 -3
- package/src/physics/world.js +5 -8
- package/src/polyfill/roundrect.js +163 -163
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/colorlayer.js +3 -3
- package/src/renderable/container.js +24 -24
- package/src/renderable/imagelayer.js +3 -3
- package/src/renderable/light2d.js +2 -2
- package/src/renderable/nineslicesprite.js +1 -1
- package/src/renderable/renderable.js +25 -25
- package/src/renderable/sprite.js +2 -2
- package/src/{text → renderable/text}/bitmaptext.js +8 -8
- package/src/{text → renderable/text}/bitmaptextdata.js +4 -7
- package/src/{text → renderable/text}/glyph.js +1 -1
- package/src/{text → renderable/text}/text.js +16 -17
- package/src/{text → renderable/text}/textmetrics.js +2 -2
- package/src/renderable/trigger.js +9 -9
- package/src/renderable/ui/uibaseelement.js +6 -6
- package/src/renderable/ui/uispriteelement.js +6 -6
- package/src/renderable/ui/uitextbutton.js +2 -2
- package/src/state/stage.js +1 -1
- package/src/state/state.js +0 -49
- package/src/system/device.js +48 -9
- package/src/system/event.js +22 -0
- package/src/system/platform.js +18 -18
- package/src/system/pooling.js +9 -9
- package/src/tweens/tween.js +1 -1
- package/src/utils/function.js +1 -2
- package/src/video/canvas/canvas_renderer.js +2 -6
- package/src/video/renderer.js +15 -15
- package/src/video/texture/atlas.js +12 -12
- package/src/video/texture/canvas_texture.js +14 -14
- package/src/video/video.js +3 -3
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/compositors/compositor.js +12 -13
- package/src/video/webgl/compositors/primitive_compositor.js +4 -4
- package/src/video/webgl/compositors/quad_compositor.js +1 -2
- package/src/video/webgl/glshader.js +1 -1
- package/src/video/webgl/utils/precision.js +3 -3
- package/src/video/webgl/webgl_renderer.js +49 -51
- /package/src/{text → renderable/text}/textstyle.js +0 -0
package/src/geometries/poly.js
CHANGED
|
@@ -12,7 +12,7 @@ import pool from "./../system/pooling.js";
|
|
|
12
12
|
*
|
|
13
13
|
* A polygon's `winding` is clockwise if its vertices (points) are declared turning to the right. The image above shows COUNTERCLOCKWISE winding.
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
export default class Polygon {
|
|
16
16
|
/**
|
|
17
17
|
* @param {number} x - origin point of the Polygon
|
|
18
18
|
* @param {number} y - origin point of the Polygon
|
|
@@ -21,10 +21,7 @@ import pool from "./../system/pooling.js";
|
|
|
21
21
|
constructor(x, y, points) {
|
|
22
22
|
/**
|
|
23
23
|
* origin point of the Polygon
|
|
24
|
-
* @public
|
|
25
24
|
* @type {Vector2d}
|
|
26
|
-
* @name pos
|
|
27
|
-
* @memberof Polygon
|
|
28
25
|
*/
|
|
29
26
|
this.pos = pool.pull("Vector2d");
|
|
30
27
|
|
|
@@ -32,18 +29,13 @@ import pool from "./../system/pooling.js";
|
|
|
32
29
|
* The bounding rectangle for this shape
|
|
33
30
|
* @ignore
|
|
34
31
|
* @member {Bounds}
|
|
35
|
-
* @name _bounds
|
|
36
|
-
* @memberof Polygon
|
|
37
32
|
*/
|
|
38
33
|
this._bounds;
|
|
39
34
|
|
|
40
35
|
/**
|
|
41
36
|
* Array of points defining the Polygon <br>
|
|
42
37
|
* Note: If you manually change `points`, you **must** call `recalc`afterwards so that the changes get applied correctly.
|
|
43
|
-
* @public
|
|
44
38
|
* @type {Vector2d[]}
|
|
45
|
-
* @name points
|
|
46
|
-
* @memberof Polygon
|
|
47
39
|
*/
|
|
48
40
|
this.points = [];
|
|
49
41
|
|
|
@@ -81,8 +73,6 @@ import pool from "./../system/pooling.js";
|
|
|
81
73
|
|
|
82
74
|
/**
|
|
83
75
|
* set new value to the Polygon
|
|
84
|
-
* @name setShape
|
|
85
|
-
* @memberof Polygon
|
|
86
76
|
* @param {number} x - position of the Polygon
|
|
87
77
|
* @param {number} y - position of the Polygon
|
|
88
78
|
* @param {Vector2d[]|number[]} points - array of vector or vertice defining the Polygon
|
|
@@ -96,8 +86,6 @@ import pool from "./../system/pooling.js";
|
|
|
96
86
|
|
|
97
87
|
/**
|
|
98
88
|
* set the vertices defining this Polygon
|
|
99
|
-
* @name setVertices
|
|
100
|
-
* @memberof Polygon
|
|
101
89
|
* @param {Vector2d[]} vertices - array of vector or vertice defining the Polygon
|
|
102
90
|
* @returns {Polygon} this instance for objecf chaining
|
|
103
91
|
*/
|
|
@@ -114,7 +102,7 @@ import pool from "./../system/pooling.js";
|
|
|
114
102
|
if (typeof vertices[0] === "object") {
|
|
115
103
|
// array of {x,y} object
|
|
116
104
|
vertices.forEach((vertice) => {
|
|
117
|
-
|
|
105
|
+
this.points.push(pool.pull("Vector2d", vertice.x, vertice.y));
|
|
118
106
|
});
|
|
119
107
|
|
|
120
108
|
} else {
|
|
@@ -135,8 +123,6 @@ import pool from "./../system/pooling.js";
|
|
|
135
123
|
|
|
136
124
|
/**
|
|
137
125
|
* apply the given transformation matrix to this Polygon
|
|
138
|
-
* @name transform
|
|
139
|
-
* @memberof Polygon
|
|
140
126
|
* @param {Matrix2d} m - the transformation matrix
|
|
141
127
|
* @returns {Polygon} Reference to this object for method chaining
|
|
142
128
|
*/
|
|
@@ -153,8 +139,6 @@ import pool from "./../system/pooling.js";
|
|
|
153
139
|
|
|
154
140
|
/**
|
|
155
141
|
* apply an isometric projection to this shape
|
|
156
|
-
* @name toIso
|
|
157
|
-
* @memberof Polygon
|
|
158
142
|
* @returns {Polygon} Reference to this object for method chaining
|
|
159
143
|
*/
|
|
160
144
|
toIso() {
|
|
@@ -162,9 +146,7 @@ import pool from "./../system/pooling.js";
|
|
|
162
146
|
}
|
|
163
147
|
|
|
164
148
|
/**
|
|
165
|
-
* apply a 2d projection to this
|
|
166
|
-
* @name to2d
|
|
167
|
-
* @memberof Polygon
|
|
149
|
+
* apply a 2d projection to this shapen
|
|
168
150
|
* @returns {Polygon} Reference to this object for method chaining
|
|
169
151
|
*/
|
|
170
152
|
to2d() {
|
|
@@ -173,8 +155,6 @@ import pool from "./../system/pooling.js";
|
|
|
173
155
|
|
|
174
156
|
/**
|
|
175
157
|
* Rotate this Polygon (counter-clockwise) by the specified angle (in radians).
|
|
176
|
-
* @name rotate
|
|
177
|
-
* @memberof Polygon
|
|
178
158
|
* @param {number} angle - The angle to rotate (in radians)
|
|
179
159
|
* @param {Vector2d|ObservableVector2d} [v] - an optional point to rotate around
|
|
180
160
|
* @returns {Polygon} Reference to this object for method chaining
|
|
@@ -194,8 +174,6 @@ import pool from "./../system/pooling.js";
|
|
|
194
174
|
|
|
195
175
|
/**
|
|
196
176
|
* Scale this Polygon by the given scalar.
|
|
197
|
-
* @name scale
|
|
198
|
-
* @memberof Polygon
|
|
199
177
|
* @param {number} x
|
|
200
178
|
* @param {number} [y=x]
|
|
201
179
|
* @returns {Polygon} Reference to this object for method chaining
|
|
@@ -213,8 +191,6 @@ import pool from "./../system/pooling.js";
|
|
|
213
191
|
|
|
214
192
|
/**
|
|
215
193
|
* Scale this Polygon by the given vector
|
|
216
|
-
* @name scaleV
|
|
217
|
-
* @memberof Polygon
|
|
218
194
|
* @param {Vector2d} v
|
|
219
195
|
* @returns {Polygon} Reference to this object for method chaining
|
|
220
196
|
*/
|
|
@@ -225,12 +201,9 @@ import pool from "./../system/pooling.js";
|
|
|
225
201
|
/**
|
|
226
202
|
* Computes the calculated collision polygon.
|
|
227
203
|
* This **must** be called if the `points` array, `angle`, or `offset` is modified manually.
|
|
228
|
-
* @name recalc
|
|
229
|
-
* @memberof Polygon
|
|
230
204
|
* @returns {Polygon} Reference to this object for method chaining
|
|
231
205
|
*/
|
|
232
206
|
recalc() {
|
|
233
|
-
let i;
|
|
234
207
|
let edges = this.edges;
|
|
235
208
|
let normals = this.normals;
|
|
236
209
|
let indices = this.indices;
|
|
@@ -244,7 +217,7 @@ import pool from "./../system/pooling.js";
|
|
|
244
217
|
}
|
|
245
218
|
|
|
246
219
|
// Calculate the edges/normals
|
|
247
|
-
for (i = 0; i < len; i++) {
|
|
220
|
+
for (let i = 0; i < len; i++) {
|
|
248
221
|
if (edges[i] === undefined) {
|
|
249
222
|
edges[i] = pool.pull("Vector2d");
|
|
250
223
|
}
|
|
@@ -268,8 +241,6 @@ import pool from "./../system/pooling.js";
|
|
|
268
241
|
|
|
269
242
|
/**
|
|
270
243
|
* returns a list of indices for all triangles defined in this polygon
|
|
271
|
-
* @name getIndices
|
|
272
|
-
* @memberof Polygon
|
|
273
244
|
* @returns {Array} an array of vertex indices for all triangles forming this polygon.
|
|
274
245
|
*/
|
|
275
246
|
getIndices() {
|
|
@@ -281,8 +252,6 @@ import pool from "./../system/pooling.js";
|
|
|
281
252
|
|
|
282
253
|
/**
|
|
283
254
|
* Returns true if the vertices composing this polygon form a convex shape (vertices must be in clockwise order).
|
|
284
|
-
* @name isConvex
|
|
285
|
-
* @memberof Polygon
|
|
286
255
|
* @returns {boolean} true if the vertices are convex, false if not, null if not computable
|
|
287
256
|
*/
|
|
288
257
|
isConvex() {
|
|
@@ -291,20 +260,16 @@ import pool from "./../system/pooling.js";
|
|
|
291
260
|
|
|
292
261
|
let flag = 0,
|
|
293
262
|
vertices = this.points,
|
|
294
|
-
n = vertices.length
|
|
295
|
-
i,
|
|
296
|
-
j,
|
|
297
|
-
k,
|
|
298
|
-
z;
|
|
263
|
+
n = vertices.length;
|
|
299
264
|
|
|
300
265
|
if (n < 3) {
|
|
301
266
|
return null;
|
|
302
267
|
}
|
|
303
268
|
|
|
304
|
-
for (i = 0; i < n; i++) {
|
|
305
|
-
j = (i + 1) % n;
|
|
306
|
-
k = (i + 2) % n;
|
|
307
|
-
z = (vertices[j].x - vertices[i].x) * (vertices[k].y - vertices[j].y);
|
|
269
|
+
for (let i = 0; i < n; i++) {
|
|
270
|
+
let j = (i + 1) % n;
|
|
271
|
+
let k = (i + 2) % n;
|
|
272
|
+
let z = (vertices[j].x - vertices[i].x) * (vertices[k].y - vertices[j].y);
|
|
308
273
|
z -= (vertices[j].y - vertices[i].y) * (vertices[k].x - vertices[j].x);
|
|
309
274
|
|
|
310
275
|
if (z < 0) {
|
|
@@ -327,19 +292,13 @@ import pool from "./../system/pooling.js";
|
|
|
327
292
|
|
|
328
293
|
/**
|
|
329
294
|
* translate the Polygon by the specified offset
|
|
330
|
-
* @
|
|
331
|
-
* @
|
|
332
|
-
* @method
|
|
333
|
-
* @param {number} x - x offset
|
|
334
|
-
* @param {number} y - y offset
|
|
335
|
-
* @returns {Polygon} this Polygon
|
|
336
|
-
*/
|
|
337
|
-
/**
|
|
338
|
-
* translate the Polygon by the specified vector
|
|
339
|
-
* @name translate
|
|
340
|
-
* @memberof Polygon
|
|
341
|
-
* @param {Vector2d} v - vector offset
|
|
295
|
+
* @param {number|Vector2d} x - x offset or a vector point to translate by
|
|
296
|
+
* @param {number} [y] - y offset
|
|
342
297
|
* @returns {Polygon} Reference to this object for method chaining
|
|
298
|
+
* @example
|
|
299
|
+
* polygon.translate(10, 10);
|
|
300
|
+
* // or
|
|
301
|
+
* polygon.translate(myVector2d);
|
|
343
302
|
*/
|
|
344
303
|
translate() {
|
|
345
304
|
let _x, _y;
|
|
@@ -363,17 +322,12 @@ import pool from "./../system/pooling.js";
|
|
|
363
322
|
|
|
364
323
|
/**
|
|
365
324
|
* Shifts the Polygon to the given position vector.
|
|
366
|
-
* @
|
|
367
|
-
* @
|
|
368
|
-
* @
|
|
369
|
-
*
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
* Shifts the Polygon to the given x, y position.
|
|
373
|
-
* @name shift
|
|
374
|
-
* @memberof Polygon
|
|
375
|
-
* @param {number} x
|
|
376
|
-
* @param {number} y
|
|
325
|
+
* @param {number|Vector2d} x - x coordinate or a vector point to shift to
|
|
326
|
+
* @param {number} [y]
|
|
327
|
+
* @example
|
|
328
|
+
* polygon.shift(10, 10);
|
|
329
|
+
* // or
|
|
330
|
+
* polygon.shift(myVector2d);
|
|
377
331
|
*/
|
|
378
332
|
shift() {
|
|
379
333
|
let _x, _y;
|
|
@@ -391,38 +345,33 @@ import pool from "./../system/pooling.js";
|
|
|
391
345
|
this.updateBounds();
|
|
392
346
|
}
|
|
393
347
|
|
|
394
|
-
/**
|
|
395
|
-
* Returns true if the polygon contains the given point.
|
|
396
|
-
* (Note: it is highly recommended to first do a hit test on the corresponding <br>
|
|
397
|
-
* bounding rect, as the function can be highly consuming with complex shapes)
|
|
398
|
-
* @name contains
|
|
399
|
-
* @memberof Polygon
|
|
400
|
-
* @method
|
|
401
|
-
* @param {Vector2d} point
|
|
402
|
-
* @returns {boolean} true if contains
|
|
403
|
-
*/
|
|
404
|
-
|
|
405
348
|
/**
|
|
406
349
|
* Returns true if the polygon contains the given point. <br>
|
|
407
350
|
* (Note: it is highly recommended to first do a hit test on the corresponding <br>
|
|
408
351
|
* bounding rect, as the function can be highly consuming with complex shapes)
|
|
409
|
-
* @
|
|
410
|
-
* @
|
|
411
|
-
* @
|
|
412
|
-
* @
|
|
413
|
-
*
|
|
352
|
+
* @param {number|Vector2d} x - x coordinate or a vector point to check
|
|
353
|
+
* @param {number} [y] - y coordinate
|
|
354
|
+
* @returns {boolean} True if the polygon contain the point, otherwise false
|
|
355
|
+
* @example
|
|
356
|
+
* if (polygon.contains(10, 10)) {
|
|
357
|
+
* // do something
|
|
358
|
+
* }
|
|
359
|
+
* // or
|
|
360
|
+
* if (polygon.contains(myVector2d)) {
|
|
361
|
+
* // do something
|
|
362
|
+
* }
|
|
414
363
|
*/
|
|
415
364
|
contains() {
|
|
416
365
|
let _x, _y;
|
|
417
366
|
|
|
418
367
|
if (arguments.length === 2) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
368
|
+
// x, y
|
|
369
|
+
_x = arguments[0];
|
|
370
|
+
_y = arguments[1];
|
|
422
371
|
} else {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
372
|
+
// vector
|
|
373
|
+
_x = arguments[0].x;
|
|
374
|
+
_y = arguments[0].y;
|
|
426
375
|
}
|
|
427
376
|
|
|
428
377
|
let intersects = false;
|
|
@@ -433,7 +382,7 @@ import pool from "./../system/pooling.js";
|
|
|
433
382
|
//http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
|
434
383
|
for (let i = 0, j = len - 1; i < len; j = i++) {
|
|
435
384
|
const iy = points[i].y + posy, ix = points[i].x + posx,
|
|
436
|
-
|
|
385
|
+
jy = points[j].y + posy, jx = points[j].x + posx;
|
|
437
386
|
if (((iy > _y) !== (jy > _y)) && (_x < (jx - ix) * (_y - iy) / (jy - iy) + ix)) {
|
|
438
387
|
intersects = !intersects;
|
|
439
388
|
}
|
|
@@ -443,8 +392,6 @@ import pool from "./../system/pooling.js";
|
|
|
443
392
|
|
|
444
393
|
/**
|
|
445
394
|
* returns the bounding box for this shape, the smallest Rectangle object completely containing this shape.
|
|
446
|
-
* @name getBounds
|
|
447
|
-
* @memberof Polygon
|
|
448
395
|
* @returns {Bounds} this shape bounding box Rectangle object
|
|
449
396
|
*/
|
|
450
397
|
getBounds() {
|
|
@@ -456,8 +403,6 @@ import pool from "./../system/pooling.js";
|
|
|
456
403
|
|
|
457
404
|
/**
|
|
458
405
|
* update the bounding box for this shape.
|
|
459
|
-
* @name updateBounds
|
|
460
|
-
* @memberof Polygon
|
|
461
406
|
* @returns {Bounds} this shape bounding box Rectangle object
|
|
462
407
|
*/
|
|
463
408
|
updateBounds() {
|
|
@@ -471,8 +416,6 @@ import pool from "./../system/pooling.js";
|
|
|
471
416
|
|
|
472
417
|
/**
|
|
473
418
|
* clone this Polygon
|
|
474
|
-
* @name clone
|
|
475
|
-
* @memberof Polygon
|
|
476
419
|
* @returns {Polygon} new Polygon
|
|
477
420
|
*/
|
|
478
421
|
clone() {
|
|
@@ -6,7 +6,7 @@ import Polygon from "./poly.js";
|
|
|
6
6
|
* a rectangle Object
|
|
7
7
|
* @augments Polygon
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
export default class Rect extends Polygon {
|
|
10
10
|
/**
|
|
11
11
|
* @param {number} x - position of the Rectangle
|
|
12
12
|
* @param {number} y - position of the Rectangle
|
|
@@ -31,8 +31,6 @@ import Polygon from "./poly.js";
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* set new value to the rectangle shape
|
|
34
|
-
* @name setShape
|
|
35
|
-
* @memberof Rect
|
|
36
34
|
* @param {number} x - position of the Rectangle
|
|
37
35
|
* @param {number} y - position of the Rectangle
|
|
38
36
|
* @param {number|Vector2d[]} w - width of the rectangle, or an array of vector defining the rectangle
|
|
@@ -59,10 +57,7 @@ import Polygon from "./poly.js";
|
|
|
59
57
|
|
|
60
58
|
/**
|
|
61
59
|
* left coordinate of the Rectangle
|
|
62
|
-
* @public
|
|
63
60
|
* @type {number}
|
|
64
|
-
* @name left
|
|
65
|
-
* @memberof Rect
|
|
66
61
|
*/
|
|
67
62
|
get left() {
|
|
68
63
|
return this.pos.x;
|
|
@@ -70,10 +65,7 @@ import Polygon from "./poly.js";
|
|
|
70
65
|
|
|
71
66
|
/**
|
|
72
67
|
* right coordinate of the Rectangle
|
|
73
|
-
* @public
|
|
74
68
|
* @type {number}
|
|
75
|
-
* @name right
|
|
76
|
-
* @memberof Rect
|
|
77
69
|
*/
|
|
78
70
|
get right() {
|
|
79
71
|
let w = this.width;
|
|
@@ -82,10 +74,7 @@ import Polygon from "./poly.js";
|
|
|
82
74
|
|
|
83
75
|
/**
|
|
84
76
|
* top coordinate of the Rectangle
|
|
85
|
-
* @public
|
|
86
77
|
* @type {number}
|
|
87
|
-
* @name top
|
|
88
|
-
* @memberof Rect
|
|
89
78
|
*/
|
|
90
79
|
get top() {
|
|
91
80
|
return this.pos.y;
|
|
@@ -93,10 +82,7 @@ import Polygon from "./poly.js";
|
|
|
93
82
|
|
|
94
83
|
/**
|
|
95
84
|
* bottom coordinate of the Rectangle
|
|
96
|
-
* @public
|
|
97
85
|
* @type {number}
|
|
98
|
-
* @name bottom
|
|
99
|
-
* @memberof Rect
|
|
100
86
|
*/
|
|
101
87
|
get bottom() {
|
|
102
88
|
let h = this.height;
|
|
@@ -105,10 +91,7 @@ import Polygon from "./poly.js";
|
|
|
105
91
|
|
|
106
92
|
/**
|
|
107
93
|
* width of the Rectangle
|
|
108
|
-
* @public
|
|
109
94
|
* @type {number}
|
|
110
|
-
* @name width
|
|
111
|
-
* @memberof Rect
|
|
112
95
|
*/
|
|
113
96
|
get width() {
|
|
114
97
|
return this.points[2].x;
|
|
@@ -121,10 +104,7 @@ import Polygon from "./poly.js";
|
|
|
121
104
|
|
|
122
105
|
/**
|
|
123
106
|
* height of the Rectangle
|
|
124
|
-
* @public
|
|
125
107
|
* @type {number}
|
|
126
|
-
* @name height
|
|
127
|
-
* @memberof Rect
|
|
128
108
|
*/
|
|
129
109
|
get height() {
|
|
130
110
|
return this.points[2].y;
|
|
@@ -137,10 +117,7 @@ import Polygon from "./poly.js";
|
|
|
137
117
|
|
|
138
118
|
/**
|
|
139
119
|
* absolute center of this rectangle on the horizontal axis
|
|
140
|
-
* @public
|
|
141
120
|
* @type {number}
|
|
142
|
-
* @name centerX
|
|
143
|
-
* @memberof Rect
|
|
144
121
|
*/
|
|
145
122
|
get centerX() {
|
|
146
123
|
if (isFinite(this.width)) {
|
|
@@ -157,10 +134,7 @@ import Polygon from "./poly.js";
|
|
|
157
134
|
|
|
158
135
|
/**
|
|
159
136
|
* absolute center of this rectangle on the vertical axis
|
|
160
|
-
* @public
|
|
161
137
|
* @type {number}
|
|
162
|
-
* @name centerY
|
|
163
|
-
* @memberof Rect
|
|
164
138
|
*/
|
|
165
139
|
get centerY() {
|
|
166
140
|
if (isFinite(this.height)) {
|
|
@@ -177,8 +151,6 @@ import Polygon from "./poly.js";
|
|
|
177
151
|
|
|
178
152
|
/**
|
|
179
153
|
* center the rectangle position around the given coordinates
|
|
180
|
-
* @name centerOn
|
|
181
|
-
* @memberof Rect
|
|
182
154
|
* @param {number} x - the x coordinate around which to center this rectangle
|
|
183
155
|
* @param {number} y - the y coordinate around which to center this rectangle
|
|
184
156
|
* @returns {Rect} this rectangle
|
|
@@ -191,8 +163,6 @@ import Polygon from "./poly.js";
|
|
|
191
163
|
|
|
192
164
|
/**
|
|
193
165
|
* resize the rectangle
|
|
194
|
-
* @name resize
|
|
195
|
-
* @memberof Rect
|
|
196
166
|
* @param {number} w - new width of the rectangle
|
|
197
167
|
* @param {number} h - new height of the rectangle
|
|
198
168
|
* @returns {Rect} this rectangle
|
|
@@ -205,8 +175,6 @@ import Polygon from "./poly.js";
|
|
|
205
175
|
|
|
206
176
|
/**
|
|
207
177
|
* scale the rectangle
|
|
208
|
-
* @name scale
|
|
209
|
-
* @memberof Rect
|
|
210
178
|
* @param {number} x - a number representing the abscissa of the scaling vector.
|
|
211
179
|
* @param {number} [y=x] - a number representing the ordinate of the scaling vector.
|
|
212
180
|
* @returns {Rect} this rectangle
|
|
@@ -219,8 +187,6 @@ import Polygon from "./poly.js";
|
|
|
219
187
|
|
|
220
188
|
/**
|
|
221
189
|
* clone this rectangle
|
|
222
|
-
* @name clone
|
|
223
|
-
* @memberof Rect
|
|
224
190
|
* @returns {Rect} new rectangle
|
|
225
191
|
*/
|
|
226
192
|
clone() {
|
|
@@ -229,8 +195,6 @@ import Polygon from "./poly.js";
|
|
|
229
195
|
|
|
230
196
|
/**
|
|
231
197
|
* copy the position and size of the given rectangle into this one
|
|
232
|
-
* @name copy
|
|
233
|
-
* @memberof Rect
|
|
234
198
|
* @param {Rect} rect - Source rectangle
|
|
235
199
|
* @returns {Rect} new rectangle
|
|
236
200
|
*/
|
|
@@ -240,8 +204,6 @@ import Polygon from "./poly.js";
|
|
|
240
204
|
|
|
241
205
|
/**
|
|
242
206
|
* merge this rectangle with another one
|
|
243
|
-
* @name union
|
|
244
|
-
* @memberof Rect
|
|
245
207
|
* @param {Rect} rect - other rectangle to union with
|
|
246
208
|
* @returns {Rect} the union(ed) rectangle
|
|
247
209
|
*/
|
|
@@ -261,8 +223,6 @@ import Polygon from "./poly.js";
|
|
|
261
223
|
|
|
262
224
|
/**
|
|
263
225
|
* check if this rectangle is intersecting with the specified one
|
|
264
|
-
* @name overlaps
|
|
265
|
-
* @memberof Rect
|
|
266
226
|
* @param {Rect} rect
|
|
267
227
|
* @returns {boolean} true if overlaps
|
|
268
228
|
*/
|
|
@@ -276,63 +236,53 @@ import Polygon from "./poly.js";
|
|
|
276
236
|
}
|
|
277
237
|
|
|
278
238
|
/**
|
|
279
|
-
* Returns true if the rectangle contains the given rectangle
|
|
280
|
-
* @
|
|
281
|
-
* @
|
|
282
|
-
* @
|
|
283
|
-
* @
|
|
284
|
-
*
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
* @returns {boolean} true if contains
|
|
295
|
-
*/
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Returns true if the rectangle contains the given point
|
|
299
|
-
* @name contains
|
|
300
|
-
* @memberof Rect
|
|
301
|
-
* @param {Vector2d} point
|
|
302
|
-
* @returns {boolean} true if contains
|
|
239
|
+
* Returns true if the rectangle contains the given point or rectangle
|
|
240
|
+
* @param {number|Vector2d|Rect} x - x coordinate or a vector point, or a rectangle to test
|
|
241
|
+
* @param {number} [y] - y coordinate
|
|
242
|
+
* @returns {boolean} True if the rectangle contain the given point or rectangle, otherwise false
|
|
243
|
+
* @example
|
|
244
|
+
* if (rect.contains(10, 10)) {
|
|
245
|
+
* // do something
|
|
246
|
+
* }
|
|
247
|
+
* // or
|
|
248
|
+
* if (rect.contains(myVector2d)) {
|
|
249
|
+
* // do something
|
|
250
|
+
* }
|
|
251
|
+
* if (rect.contains(myRect)) {
|
|
252
|
+
* // do something
|
|
253
|
+
* }
|
|
303
254
|
*/
|
|
304
255
|
contains() {
|
|
305
256
|
let arg0 = arguments[0];
|
|
306
257
|
let _x1, _x2, _y1, _y2;
|
|
307
258
|
if (arguments.length === 2) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
259
|
+
// x, y
|
|
260
|
+
_x1 = _x2 = arg0;
|
|
261
|
+
_y1 = _y2 = arguments[1];
|
|
262
|
+
} else {
|
|
263
|
+
// only Rect based objects define a top and bottom properties
|
|
264
|
+
if (typeof arg0.bottom === "number") {
|
|
265
|
+
// me.Rect
|
|
266
|
+
_x1 = arg0.left;
|
|
267
|
+
_x2 = arg0.right;
|
|
268
|
+
_y1 = arg0.top;
|
|
269
|
+
_y2 = arg0.bottom;
|
|
270
|
+
} else {
|
|
271
|
+
// vector
|
|
272
|
+
_x1 = _x2 = arg0.x;
|
|
273
|
+
_y1 = _y2 = arg0.y;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return (
|
|
277
|
+
_x1 >= this.left &&
|
|
326
278
|
_x2 <= this.right &&
|
|
327
279
|
_y1 >= this.top &&
|
|
328
280
|
_y2 <= this.bottom
|
|
329
|
-
|
|
281
|
+
);
|
|
330
282
|
}
|
|
331
283
|
|
|
332
284
|
/**
|
|
333
285
|
* check if this rectangle is identical to the specified one
|
|
334
|
-
* @name equals
|
|
335
|
-
* @memberof Rect
|
|
336
286
|
* @param {Rect} rect
|
|
337
287
|
* @returns {boolean} true if equals
|
|
338
288
|
*/
|
|
@@ -347,8 +297,6 @@ import Polygon from "./poly.js";
|
|
|
347
297
|
|
|
348
298
|
/**
|
|
349
299
|
* determines whether all coordinates of this rectangle are finite numbers.
|
|
350
|
-
* @name isFinite
|
|
351
|
-
* @memberof Rect
|
|
352
300
|
* @returns {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
|
|
353
301
|
*/
|
|
354
302
|
isFinite() {
|
|
@@ -357,8 +305,6 @@ import Polygon from "./poly.js";
|
|
|
357
305
|
|
|
358
306
|
/**
|
|
359
307
|
* Returns a polygon whose edges are the same as this box.
|
|
360
|
-
* @name toPolygon
|
|
361
|
-
* @memberof Rect
|
|
362
308
|
* @returns {Polygon} a new Polygon that represents this rectangle.
|
|
363
309
|
*/
|
|
364
310
|
toPolygon() {
|