melonjs 14.0.2 → 14.1.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.
Files changed (214) hide show
  1. package/README.md +2 -0
  2. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +10 -0
  3. package/dist/melonjs.mjs/_virtual/arraymultimap.js +10 -0
  4. package/dist/melonjs.mjs/_virtual/earcut.js +10 -0
  5. package/dist/melonjs.mjs/_virtual/howler.js +10 -0
  6. package/dist/melonjs.mjs/_virtual/index.js +10 -0
  7. package/dist/melonjs.mjs/_virtual/index2.js +10 -0
  8. package/dist/melonjs.mjs/_virtual/multimap.js +10 -0
  9. package/dist/melonjs.mjs/_virtual/setmultimap.js +10 -0
  10. package/dist/melonjs.mjs/application/application.js +240 -0
  11. package/dist/melonjs.mjs/audio/audio.js +536 -0
  12. package/dist/melonjs.mjs/camera/camera2d.js +732 -0
  13. package/dist/melonjs.mjs/entity/entity.js +248 -0
  14. package/dist/melonjs.mjs/game.js +29 -0
  15. package/dist/melonjs.mjs/geometries/ellipse.js +275 -0
  16. package/dist/melonjs.mjs/geometries/line.js +116 -0
  17. package/dist/melonjs.mjs/geometries/path2d.js +319 -0
  18. package/dist/melonjs.mjs/geometries/point.js +89 -0
  19. package/dist/melonjs.mjs/geometries/poly.js +500 -0
  20. package/dist/melonjs.mjs/geometries/rectangle.js +375 -0
  21. package/dist/melonjs.mjs/geometries/roundrect.js +168 -0
  22. package/dist/melonjs.mjs/index.js +248 -0
  23. package/dist/melonjs.mjs/input/gamepad.js +501 -0
  24. package/dist/melonjs.mjs/input/input.js +26 -0
  25. package/dist/melonjs.mjs/input/keyboard.js +470 -0
  26. package/dist/melonjs.mjs/input/pointer.js +393 -0
  27. package/dist/melonjs.mjs/input/pointerevent.js +818 -0
  28. package/dist/melonjs.mjs/lang/deprecated.js +157 -0
  29. package/dist/melonjs.mjs/level/level.js +297 -0
  30. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +141 -0
  31. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +448 -0
  32. package/dist/melonjs.mjs/level/tiled/TMXObject.js +355 -0
  33. package/dist/melonjs.mjs/level/tiled/TMXTile.js +194 -0
  34. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +639 -0
  35. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +311 -0
  36. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +83 -0
  37. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +367 -0
  38. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +506 -0
  39. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +220 -0
  40. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +157 -0
  41. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +125 -0
  42. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +109 -0
  43. package/dist/melonjs.mjs/loader/loader.js +801 -0
  44. package/dist/melonjs.mjs/loader/loadingscreen.js +120 -0
  45. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +11 -0
  46. package/dist/melonjs.mjs/math/color.js +618 -0
  47. package/dist/melonjs.mjs/math/math.js +218 -0
  48. package/dist/melonjs.mjs/math/matrix2.js +503 -0
  49. package/dist/melonjs.mjs/math/matrix3.js +681 -0
  50. package/dist/melonjs.mjs/math/observable_vector2.js +471 -0
  51. package/dist/melonjs.mjs/math/observable_vector3.js +561 -0
  52. package/dist/melonjs.mjs/math/vector2.js +528 -0
  53. package/dist/melonjs.mjs/math/vector3.js +569 -0
  54. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +73 -0
  55. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +21 -0
  56. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +324 -0
  57. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +69 -0
  58. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +691 -0
  59. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +350 -0
  60. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +3241 -0
  61. package/dist/melonjs.mjs/particles/emitter.js +267 -0
  62. package/dist/melonjs.mjs/particles/particle.js +188 -0
  63. package/dist/melonjs.mjs/particles/settings.js +319 -0
  64. package/dist/melonjs.mjs/physics/body.js +704 -0
  65. package/dist/melonjs.mjs/physics/bounds.js +460 -0
  66. package/dist/melonjs.mjs/physics/collision.js +132 -0
  67. package/dist/melonjs.mjs/physics/detector.js +194 -0
  68. package/dist/melonjs.mjs/physics/quadtree.js +391 -0
  69. package/dist/melonjs.mjs/physics/response.js +57 -0
  70. package/dist/melonjs.mjs/physics/sat.js +483 -0
  71. package/dist/melonjs.mjs/physics/world.js +221 -0
  72. package/dist/melonjs.mjs/plugin/plugin.js +141 -0
  73. package/dist/melonjs.mjs/renderable/collectable.js +62 -0
  74. package/dist/melonjs.mjs/renderable/colorlayer.js +80 -0
  75. package/dist/melonjs.mjs/renderable/container.js +1018 -0
  76. package/dist/melonjs.mjs/renderable/dragndrop.js +224 -0
  77. package/dist/melonjs.mjs/renderable/imagelayer.js +306 -0
  78. package/dist/melonjs.mjs/renderable/light2d.js +156 -0
  79. package/dist/melonjs.mjs/renderable/nineslicesprite.js +247 -0
  80. package/dist/melonjs.mjs/renderable/renderable.js +783 -0
  81. package/dist/melonjs.mjs/renderable/sprite.js +654 -0
  82. package/dist/melonjs.mjs/renderable/trigger.js +157 -0
  83. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +213 -0
  84. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +226 -0
  85. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +128 -0
  86. package/dist/melonjs.mjs/state/stage.js +237 -0
  87. package/dist/melonjs.mjs/state/state.js +596 -0
  88. package/dist/melonjs.mjs/system/device.js +909 -0
  89. package/dist/melonjs.mjs/system/dom.js +78 -0
  90. package/dist/melonjs.mjs/system/event.js +537 -0
  91. package/dist/melonjs.mjs/system/platform.js +41 -0
  92. package/dist/melonjs.mjs/system/pooling.js +209 -0
  93. package/dist/melonjs.mjs/system/save.js +157 -0
  94. package/dist/melonjs.mjs/system/timer.js +286 -0
  95. package/dist/melonjs.mjs/text/bitmaptext.js +364 -0
  96. package/dist/melonjs.mjs/text/bitmaptextdata.js +199 -0
  97. package/dist/melonjs.mjs/text/glyph.js +66 -0
  98. package/dist/melonjs.mjs/text/text.js +453 -0
  99. package/dist/melonjs.mjs/text/textmetrics.js +176 -0
  100. package/dist/melonjs.mjs/text/textstyle.js +23 -0
  101. package/dist/melonjs.mjs/tweens/easing.js +336 -0
  102. package/dist/melonjs.mjs/tweens/interpolation.js +112 -0
  103. package/dist/melonjs.mjs/tweens/tween.js +480 -0
  104. package/dist/melonjs.mjs/utils/agent.js +76 -0
  105. package/dist/melonjs.mjs/utils/array.js +63 -0
  106. package/dist/melonjs.mjs/utils/file.js +42 -0
  107. package/dist/melonjs.mjs/utils/function.js +70 -0
  108. package/dist/melonjs.mjs/utils/string.js +82 -0
  109. package/dist/melonjs.mjs/utils/utils.js +173 -0
  110. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +807 -0
  111. package/dist/melonjs.mjs/video/renderer.js +411 -0
  112. package/dist/melonjs.mjs/video/texture/atlas.js +519 -0
  113. package/dist/melonjs.mjs/video/texture/cache.js +143 -0
  114. package/dist/melonjs.mjs/video/texture/canvas_texture.js +144 -0
  115. package/dist/melonjs.mjs/video/video.js +462 -0
  116. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +143 -0
  117. package/dist/melonjs.mjs/video/webgl/glshader.js +168 -0
  118. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +10 -0
  119. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +10 -0
  120. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +10 -0
  121. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +10 -0
  122. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +25 -0
  123. package/dist/melonjs.mjs/video/webgl/utils/precision.js +20 -0
  124. package/dist/melonjs.mjs/video/webgl/utils/program.js +67 -0
  125. package/dist/melonjs.mjs/video/webgl/utils/string.js +25 -0
  126. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +92 -0
  127. package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +495 -0
  128. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +1036 -0
  129. package/dist/melonjs.module.d.ts +1163 -1163
  130. package/dist/melonjs.module.js +1903 -3274
  131. package/package.json +22 -17
  132. package/src/application/application.js +3 -3
  133. package/src/audio/audio.js +32 -32
  134. package/src/camera/camera2d.js +31 -31
  135. package/src/entity/entity.js +17 -17
  136. package/src/geometries/ellipse.js +16 -16
  137. package/src/geometries/line.js +5 -5
  138. package/src/geometries/path2d.js +32 -32
  139. package/src/geometries/poly.js +15 -15
  140. package/src/geometries/rectangle.js +18 -18
  141. package/src/geometries/roundrect.js +8 -8
  142. package/src/input/gamepad.js +15 -15
  143. package/src/input/keyboard.js +12 -12
  144. package/src/input/pointer.js +6 -6
  145. package/src/input/pointerevent.js +12 -12
  146. package/src/lang/deprecated.js +12 -12
  147. package/src/level/level.js +25 -25
  148. package/src/level/tiled/TMXLayer.js +22 -22
  149. package/src/level/tiled/TMXTile.js +5 -5
  150. package/src/level/tiled/TMXTileMap.js +6 -6
  151. package/src/level/tiled/TMXTileset.js +2 -2
  152. package/src/level/tiled/TMXUtils.js +5 -5
  153. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
  154. package/src/level/tiled/renderer/TMXIsometricRenderer.js +2 -2
  155. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  156. package/src/level/tiled/renderer/TMXRenderer.js +19 -19
  157. package/src/loader/loader.js +20 -20
  158. package/src/math/color.js +20 -20
  159. package/src/math/math.js +16 -16
  160. package/src/math/matrix2.js +16 -16
  161. package/src/math/matrix3.js +25 -25
  162. package/src/math/observable_vector2.js +14 -14
  163. package/src/math/observable_vector3.js +16 -16
  164. package/src/math/vector2.js +9 -9
  165. package/src/math/vector3.js +10 -10
  166. package/src/particles/emitter.js +6 -6
  167. package/src/particles/particle.js +2 -2
  168. package/src/physics/body.js +28 -28
  169. package/src/physics/bounds.js +8 -8
  170. package/src/physics/collision.js +2 -2
  171. package/src/physics/detector.js +6 -6
  172. package/src/physics/quadtree.js +11 -11
  173. package/src/physics/sat.js +31 -31
  174. package/src/physics/world.js +5 -5
  175. package/src/plugin/plugin.js +5 -5
  176. package/src/renderable/collectable.js +3 -3
  177. package/src/renderable/colorlayer.js +5 -5
  178. package/src/renderable/container.js +21 -21
  179. package/src/renderable/dragndrop.js +14 -14
  180. package/src/renderable/imagelayer.js +13 -13
  181. package/src/renderable/light2d.js +3 -3
  182. package/src/renderable/nineslicesprite.js +16 -16
  183. package/src/renderable/renderable.js +23 -23
  184. package/src/renderable/sprite.js +28 -28
  185. package/src/renderable/trigger.js +15 -15
  186. package/src/renderable/ui/uibaseelement.js +7 -7
  187. package/src/renderable/ui/uispriteelement.js +6 -6
  188. package/src/renderable/ui/uitextbutton.js +13 -13
  189. package/src/state/stage.js +7 -7
  190. package/src/state/state.js +17 -17
  191. package/src/system/device.js +11 -11
  192. package/src/system/event.js +10 -10
  193. package/src/system/pooling.js +9 -9
  194. package/src/system/save.js +2 -2
  195. package/src/system/timer.js +10 -10
  196. package/src/text/bitmaptext.js +18 -18
  197. package/src/text/bitmaptextdata.js +2 -2
  198. package/src/text/text.js +23 -23
  199. package/src/text/textmetrics.js +8 -8
  200. package/src/tweens/tween.js +19 -19
  201. package/src/utils/agent.js +5 -5
  202. package/src/utils/array.js +4 -4
  203. package/src/utils/file.js +2 -2
  204. package/src/utils/function.js +6 -6
  205. package/src/utils/string.js +5 -5
  206. package/src/utils/utils.js +4 -4
  207. package/src/video/canvas/canvas_renderer.js +70 -70
  208. package/src/video/renderer.js +26 -26
  209. package/src/video/texture/atlas.js +22 -22
  210. package/src/video/texture/canvas_texture.js +9 -9
  211. package/src/video/video.js +17 -17
  212. package/src/video/webgl/glshader.js +10 -10
  213. package/src/video/webgl/webgl_compositor.js +41 -41
  214. package/src/video/webgl/webgl_renderer.js +75 -75
@@ -0,0 +1,375 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import pool from '../system/pooling.js';
9
+ import Polygon from './poly.js';
10
+
11
+ /**
12
+ * @classdesc
13
+ * a rectangle Object
14
+ * @augments Polygon
15
+ */
16
+ class Rect extends Polygon {
17
+ /**
18
+ * @param {number} x - position of the Rectangle
19
+ * @param {number} y - position of the Rectangle
20
+ * @param {number} w - width of the rectangle
21
+ * @param {number} h - height of the rectangle
22
+ */
23
+ constructor(x, y, w, h) {
24
+ // parent constructor
25
+ super(x, y, [
26
+ pool.pull("Vector2d", 0, 0), // 0, 0
27
+ pool.pull("Vector2d", w, 0), // 1, 0
28
+ pool.pull("Vector2d", w, h), // 1, 1
29
+ pool.pull("Vector2d", 0, h) // 0, 1
30
+ ]);
31
+ this.shapeType = "Rectangle";
32
+ }
33
+
34
+ /** @ignore */
35
+ onResetEvent(x, y, w, h) {
36
+ this.setShape(x, y, w, h);
37
+ }
38
+
39
+ /**
40
+ * set new value to the rectangle shape
41
+ * @name setShape
42
+ * @memberof Rect
43
+ * @param {number} x - position of the Rectangle
44
+ * @param {number} y - position of the Rectangle
45
+ * @param {number|Vector2d[]} w - width of the rectangle, or an array of vector defining the rectangle
46
+ * @param {number} [h] - height of the rectangle, if a numeral width parameter is specified
47
+ * @returns {Rect} this rectangle
48
+ */
49
+ setShape(x, y, w, h) {
50
+ var points = w; // assume w is an array by default
51
+
52
+ this.pos.set(x, y);
53
+
54
+ if (arguments.length === 4) {
55
+ points = this.points;
56
+ points[0].set(0, 0); // 0, 0
57
+ points[1].set(w, 0); // 1, 0
58
+ points[2].set(w, h); // 1, 1
59
+ points[3].set(0, h); // 0, 1
60
+ }
61
+
62
+ this.setVertices(points);
63
+ return this;
64
+ }
65
+
66
+
67
+ /**
68
+ * left coordinate of the Rectangle
69
+ * @public
70
+ * @type {number}
71
+ * @name left
72
+ * @memberof Rect
73
+ */
74
+ get left() {
75
+ return this.pos.x;
76
+ }
77
+
78
+ /**
79
+ * right coordinate of the Rectangle
80
+ * @public
81
+ * @type {number}
82
+ * @name right
83
+ * @memberof Rect
84
+ */
85
+ get right() {
86
+ var w = this.width;
87
+ return (this.pos.x + w) || w;
88
+ }
89
+
90
+ /**
91
+ * top coordinate of the Rectangle
92
+ * @public
93
+ * @type {number}
94
+ * @name top
95
+ * @memberof Rect
96
+ */
97
+ get top() {
98
+ return this.pos.y;
99
+ }
100
+
101
+ /**
102
+ * bottom coordinate of the Rectangle
103
+ * @public
104
+ * @type {number}
105
+ * @name bottom
106
+ * @memberof Rect
107
+ */
108
+ get bottom() {
109
+ var h = this.height;
110
+ return (this.pos.y + h) || h;
111
+ }
112
+
113
+ /**
114
+ * width of the Rectangle
115
+ * @public
116
+ * @type {number}
117
+ * @name width
118
+ * @memberof Rect
119
+ */
120
+ get width() {
121
+ return this.points[2].x;
122
+ }
123
+ set width(value) {
124
+ this.points[1].x = this.points[2].x = value;
125
+ this.recalc();
126
+ this.updateBounds();
127
+ }
128
+
129
+ /**
130
+ * height of the Rectangle
131
+ * @public
132
+ * @type {number}
133
+ * @name height
134
+ * @memberof Rect
135
+ */
136
+ get height() {
137
+ return this.points[2].y;
138
+ }
139
+ set height(value) {
140
+ this.points[2].y = this.points[3].y = value;
141
+ this.recalc();
142
+ this.updateBounds();
143
+ }
144
+
145
+ /**
146
+ * absolute center of this rectangle on the horizontal axis
147
+ * @public
148
+ * @type {number}
149
+ * @name centerX
150
+ * @memberof Rect
151
+ */
152
+ get centerX() {
153
+ if (isFinite(this.width)) {
154
+ return this.pos.x + (this.width / 2);
155
+ } else {
156
+ return this.width;
157
+ }
158
+ }
159
+ set centerX (value) {
160
+ this.pos.x = value - (this.width / 2);
161
+ }
162
+
163
+ /**
164
+ * absolute center of this rectangle on the vertical axis
165
+ * @public
166
+ * @type {number}
167
+ * @name centerY
168
+ * @memberof Rect
169
+ */
170
+ get centerY() {
171
+ if (isFinite(this.height)) {
172
+ return this.pos.y + (this.height / 2);
173
+ } else {
174
+ return this.height;
175
+ }
176
+ }
177
+ set centerY(value) {
178
+ this.pos.y = value - (this.height / 2);
179
+ }
180
+
181
+ /**
182
+ * center the rectangle position around the given coordinates
183
+ * @name centerOn
184
+ * @memberof Rect
185
+ * @param {number} x - the x coordinate around which to center this rectangle
186
+ * @param {number} y - the y coordinate around which to center this rectangle
187
+ * @returns {Rect} this rectangle
188
+ */
189
+ centerOn(x, y) {
190
+ this.centerX = x;
191
+ this.centerY = y;
192
+ return this;
193
+ }
194
+
195
+ /**
196
+ * resize the rectangle
197
+ * @name resize
198
+ * @memberof Rect
199
+ * @param {number} w - new width of the rectangle
200
+ * @param {number} h - new height of the rectangle
201
+ * @returns {Rect} this rectangle
202
+ */
203
+ resize(w, h) {
204
+ this.width = w;
205
+ this.height = h;
206
+ return this;
207
+ }
208
+
209
+ /**
210
+ * scale the rectangle
211
+ * @name scale
212
+ * @memberof Rect
213
+ * @param {number} x - a number representing the abscissa of the scaling vector.
214
+ * @param {number} [y=x] - a number representing the ordinate of the scaling vector.
215
+ * @returns {Rect} this rectangle
216
+ */
217
+ scale(x, y = x) {
218
+ this.width *= x;
219
+ this.height *= y;
220
+ return this;
221
+ }
222
+
223
+ /**
224
+ * clone this rectangle
225
+ * @name clone
226
+ * @memberof Rect
227
+ * @returns {Rect} new rectangle
228
+ */
229
+ clone() {
230
+ return new Rect(this.pos.x, this.pos.y, this.width, this.height);
231
+ }
232
+
233
+ /**
234
+ * copy the position and size of the given rectangle into this one
235
+ * @name copy
236
+ * @memberof Rect
237
+ * @param {Rect} rect - Source rectangle
238
+ * @returns {Rect} new rectangle
239
+ */
240
+ copy(rect) {
241
+ return this.setShape(rect.pos.x, rect.pos.y, rect.width, rect.height);
242
+ }
243
+
244
+ /**
245
+ * merge this rectangle with another one
246
+ * @name union
247
+ * @memberof Rect
248
+ * @param {Rect} rect - other rectangle to union with
249
+ * @returns {Rect} the union(ed) rectangle
250
+ */
251
+ union(rect) {
252
+ var x1 = Math.min(this.left, rect.left);
253
+ var y1 = Math.min(this.top, rect.top);
254
+
255
+ this.resize(
256
+ Math.max(this.right, rect.right) - x1,
257
+ Math.max(this.bottom, rect.bottom) - y1
258
+ );
259
+
260
+ this.pos.set(x1, y1);
261
+
262
+ return this;
263
+ }
264
+
265
+ /**
266
+ * check if this rectangle is intersecting with the specified one
267
+ * @name overlaps
268
+ * @memberof Rect
269
+ * @param {Rect} rect
270
+ * @returns {boolean} true if overlaps
271
+ */
272
+ overlaps(rect) {
273
+ return (
274
+ this.left < rect.right &&
275
+ rect.left < this.right &&
276
+ this.top < rect.bottom &&
277
+ rect.top < this.bottom
278
+ );
279
+ }
280
+
281
+ /**
282
+ * Returns true if the rectangle contains the given rectangle
283
+ * @name contains
284
+ * @memberof Rect
285
+ * @method
286
+ * @param {Rect} rect
287
+ * @returns {boolean} true if contains
288
+ */
289
+
290
+ /**
291
+ * Returns true if the rectangle contains the given point
292
+ * @name contains
293
+ * @memberof Rect
294
+ * @method
295
+ * @param {number} x - x coordinate
296
+ * @param {number} y - y coordinate
297
+ * @returns {boolean} true if contains
298
+ */
299
+
300
+ /**
301
+ * Returns true if the rectangle contains the given point
302
+ * @name contains
303
+ * @memberof Rect
304
+ * @param {Vector2d} point
305
+ * @returns {boolean} true if contains
306
+ */
307
+ contains() {
308
+ var arg0 = arguments[0];
309
+ var _x1, _x2, _y1, _y2;
310
+ if (arguments.length === 2) {
311
+ // x, y
312
+ _x1 = _x2 = arg0;
313
+ _y1 = _y2 = arguments[1];
314
+ } else {
315
+ if (arg0 instanceof Rect) {
316
+ // me.Rect
317
+ _x1 = arg0.left;
318
+ _x2 = arg0.right;
319
+ _y1 = arg0.top;
320
+ _y2 = arg0.bottom;
321
+ } else {
322
+ // vector
323
+ _x1 = _x2 = arg0.x;
324
+ _y1 = _y2 = arg0.y;
325
+ }
326
+ }
327
+ return (
328
+ _x1 >= this.left &&
329
+ _x2 <= this.right &&
330
+ _y1 >= this.top &&
331
+ _y2 <= this.bottom
332
+ );
333
+ }
334
+
335
+ /**
336
+ * check if this rectangle is identical to the specified one
337
+ * @name equals
338
+ * @memberof Rect
339
+ * @param {Rect} rect
340
+ * @returns {boolean} true if equals
341
+ */
342
+ equals(rect) {
343
+ return (
344
+ rect.left === this.left &&
345
+ rect.right === this.right &&
346
+ rect.top === this.top &&
347
+ rect.bottom === this.bottom
348
+ );
349
+ }
350
+
351
+ /**
352
+ * determines whether all coordinates of this rectangle are finite numbers.
353
+ * @name isFinite
354
+ * @memberof Rect
355
+ * @returns {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
356
+ */
357
+ isFinite() {
358
+ return (isFinite(this.pos.x) && isFinite(this.pos.y) && isFinite(this.width) && isFinite(this.height));
359
+ }
360
+
361
+ /**
362
+ * Returns a polygon whose edges are the same as this box.
363
+ * @name toPolygon
364
+ * @memberof Rect
365
+ * @returns {Polygon} a new Polygon that represents this rectangle.
366
+ */
367
+ toPolygon() {
368
+ return pool.pull("Polygon",
369
+ this.pos.x, this.pos.y, this.points
370
+ );
371
+ }
372
+ }
373
+ var Rect$1 = Rect;
374
+
375
+ export { Rect$1 as default };
@@ -0,0 +1,168 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import Rect from './rectangle.js';
9
+
10
+ // https://developer.chrome.com/blog/canvas2d/#round-rect
11
+
12
+ /**
13
+ * @classdesc
14
+ * a rectangle object with rounded corners
15
+ * @augments Rect
16
+ */
17
+ class RoundRect extends Rect {
18
+ /**
19
+ * @param {number} x - position of the rounded rectangle
20
+ * @param {number} y - position of the rounded rectangle
21
+ * @param {number} width - the rectangle width
22
+ * @param {number} height - the rectangle height
23
+ * @param {number} [radius=20] - the radius of the rounded corner
24
+ */
25
+ constructor(x, y, width, height, radius = 20) {
26
+ // parent constructor
27
+ super(x, y, width, height);
28
+
29
+ // set the corner radius
30
+ this.radius = radius;
31
+ }
32
+
33
+ /** @ignore */
34
+ onResetEvent(x, y, w, h, radius) {
35
+ super.setShape(x, y, w, h);
36
+ this.radius = radius;
37
+ }
38
+
39
+
40
+ /**
41
+ * the radius of the rounded corner
42
+ * @public
43
+ * @type {number}
44
+ * @default 20
45
+ * @name radius
46
+ * @memberof RoundRect
47
+ */
48
+ get radius() {
49
+ return this._radius;
50
+ }
51
+ set radius(value) {
52
+ // verify the rectangle is at least as wide and tall as the rounded corners.
53
+ if (this.width < 2 * value) {
54
+ value = this.width / 2;
55
+ }
56
+ if (this.height < 2 * value) {
57
+ value = this.height / 2;
58
+ }
59
+ this._radius = value;
60
+ }
61
+
62
+ /**
63
+ * copy the position, size and radius of the given rounded rectangle into this one
64
+ * @name copy
65
+ * @memberof RoundRect
66
+ * @param {RoundRect} rrect - source rounded rectangle
67
+ * @returns {RoundRect} new rectangle
68
+ */
69
+ copy(rrect) {
70
+ super.setShape(rrect.pos.x, rrect.pos.y, rrect.width, rrect.height);
71
+ this.radius = rrect.radius;
72
+ return this;
73
+ }
74
+
75
+ /**
76
+ * Returns true if the rounded rectangle contains the given point
77
+ * @name contains
78
+ * @memberof RoundRect
79
+ * @method
80
+ * @param {number} x - x coordinate
81
+ * @param {number} y - y coordinate
82
+ * @returns {boolean} true if contains
83
+ */
84
+
85
+ /**
86
+ * Returns true if the rounded rectangle contains the given point
87
+ * @name contains
88
+ * @memberof RoundRect
89
+ * @param {Vector2d} point
90
+ * @returns {boolean} true if contains
91
+ */
92
+ contains() {
93
+ var arg0 = arguments[0];
94
+ var _x, _y;
95
+ if (arguments.length === 2) {
96
+ // x, y
97
+ _x = arg0;
98
+ _y = arguments[1];
99
+ } else {
100
+ if (arg0 instanceof Rect) {
101
+ // good enough
102
+ return super.contains(arg0);
103
+ } else {
104
+ // vector
105
+ _x = arg0.x;
106
+ _y = arg0.y;
107
+ }
108
+ }
109
+
110
+ // check whether point is outside the bounding box
111
+ if (_x < this.left || _x >= this.right || _y < this.top || _y >= this.bottom) {
112
+ return false; // outside bounding box
113
+ }
114
+
115
+ // check whether point is within the bounding box minus radius
116
+ if ((_x >= this.left + this.radius && _x <= this.right - this.radius) || (_y >= this.top + this.radius && _y <= this.bottom - this.radius)) {
117
+ return true;
118
+ }
119
+
120
+ // check whether point is in one of the rounded corner areas
121
+ var tx, ty;
122
+ var radiusX = Math.max(0, Math.min(this.radius, this.width / 2));
123
+ var radiusY = Math.max(0, Math.min(this.radius, this.height / 2));
124
+
125
+ if (_x < this.left + radiusX && _y < this.top + radiusY) {
126
+ tx = _x - this.left - radiusX;
127
+ ty = _y - this.top - radiusY;
128
+ } else if (_x > this.right - radiusX && _y < this.top + radiusY) {
129
+ tx = _x - this.right + radiusX;
130
+ ty = _y - this.top - radiusY;
131
+ } else if (_x > this.right - radiusX && _y > this.bottom - radiusY) {
132
+ tx = _x - this.right + radiusX;
133
+ ty = _y - this.bottom + radiusY;
134
+ } else if (_x < this.left + radiusX && _y > this.bottom - radiusY) {
135
+ tx = _x - this.left - radiusX;
136
+ ty = _y - this.bottom + radiusY;
137
+ } else {
138
+ return false; // inside and not within the rounded corner area
139
+ }
140
+
141
+ // Pythagorean theorem.
142
+ return ((tx * tx) + (ty * ty) <= (radiusX * radiusY));
143
+ }
144
+
145
+ /**
146
+ * check if this RoundRect is identical to the specified one
147
+ * @name equals
148
+ * @memberof RoundRect
149
+ * @param {RoundRect} rrect
150
+ * @returns {boolean} true if equals
151
+ */
152
+ equals(rrect) {
153
+ return super.equals(rrect) && this.radius === rrect.radius;
154
+ }
155
+
156
+ /**
157
+ * clone this RoundRect
158
+ * @name clone
159
+ * @memberof RoundRect
160
+ * @returns {RoundRect} new RoundRect
161
+ */
162
+ clone() {
163
+ return new RoundRect(this.pos.x, this.pos.y, this.width, this.height, this.radius);
164
+ }
165
+ }
166
+ var RoundRect$1 = RoundRect;
167
+
168
+ export { RoundRect$1 as default };