@vpmedia/phaser 1.112.0 → 1.113.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 (295) hide show
  1. package/dist/index.js +1261 -1314
  2. package/dist/index.js.map +1 -1
  3. package/dist/phaser/core/animation.d.ts +14 -10
  4. package/dist/phaser/core/animation.d.ts.map +1 -1
  5. package/dist/phaser/core/animation_manager.d.ts +10 -8
  6. package/dist/phaser/core/animation_manager.d.ts.map +1 -1
  7. package/dist/phaser/core/animation_parser.d.ts +5 -4
  8. package/dist/phaser/core/animation_parser.d.ts.map +1 -1
  9. package/dist/phaser/core/array_set.d.ts.map +1 -1
  10. package/dist/phaser/core/cache.d.ts +4 -3
  11. package/dist/phaser/core/cache.d.ts.map +1 -1
  12. package/dist/phaser/core/const.d.ts.map +1 -1
  13. package/dist/phaser/core/device.d.ts.map +1 -1
  14. package/dist/phaser/core/device_util.d.ts.map +1 -1
  15. package/dist/phaser/core/dom.d.ts +3 -2
  16. package/dist/phaser/core/dom.d.ts.map +1 -1
  17. package/dist/phaser/core/event_manager.d.ts.map +1 -1
  18. package/dist/phaser/core/factory.d.ts +1 -1
  19. package/dist/phaser/core/factory.d.ts.map +1 -1
  20. package/dist/phaser/core/frame.d.ts.map +1 -1
  21. package/dist/phaser/core/frame_data.d.ts.map +1 -1
  22. package/dist/phaser/core/game.d.ts.map +1 -1
  23. package/dist/phaser/core/input.d.ts +8 -6
  24. package/dist/phaser/core/input.d.ts.map +1 -1
  25. package/dist/phaser/core/input_handler.d.ts +40 -30
  26. package/dist/phaser/core/input_handler.d.ts.map +1 -1
  27. package/dist/phaser/core/input_mouse.d.ts +3 -2
  28. package/dist/phaser/core/input_mouse.d.ts.map +1 -1
  29. package/dist/phaser/core/input_mspointer.d.ts +3 -2
  30. package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
  31. package/dist/phaser/core/input_pointer.d.ts +6 -4
  32. package/dist/phaser/core/input_pointer.d.ts.map +1 -1
  33. package/dist/phaser/core/input_touch.d.ts +3 -2
  34. package/dist/phaser/core/input_touch.d.ts.map +1 -1
  35. package/dist/phaser/core/loader.d.ts +4 -3
  36. package/dist/phaser/core/loader.d.ts.map +1 -1
  37. package/dist/phaser/core/loader_parser.d.ts +9 -8
  38. package/dist/phaser/core/loader_parser.d.ts.map +1 -1
  39. package/dist/phaser/core/raf.d.ts +3 -2
  40. package/dist/phaser/core/raf.d.ts.map +1 -1
  41. package/dist/phaser/core/registry.d.ts +7 -0
  42. package/dist/phaser/core/registry.d.ts.map +1 -0
  43. package/dist/phaser/core/scale_manager.d.ts +1 -1
  44. package/dist/phaser/core/scale_manager.d.ts.map +1 -1
  45. package/dist/phaser/core/scene.d.ts +0 -1
  46. package/dist/phaser/core/scene.d.ts.map +1 -1
  47. package/dist/phaser/core/scene_manager.d.ts +1 -1
  48. package/dist/phaser/core/scene_manager.d.ts.map +1 -1
  49. package/dist/phaser/core/signal.d.ts +0 -1
  50. package/dist/phaser/core/signal.d.ts.map +1 -1
  51. package/dist/phaser/core/signal_binding.d.ts +4 -3
  52. package/dist/phaser/core/signal_binding.d.ts.map +1 -1
  53. package/dist/phaser/core/sound.d.ts +6 -4
  54. package/dist/phaser/core/sound.d.ts.map +1 -1
  55. package/dist/phaser/core/sound_manager.d.ts +3 -2
  56. package/dist/phaser/core/sound_manager.d.ts.map +1 -1
  57. package/dist/phaser/core/sound_sprite.d.ts +5 -4
  58. package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
  59. package/dist/phaser/core/stage.d.ts +3 -2
  60. package/dist/phaser/core/stage.d.ts.map +1 -1
  61. package/dist/phaser/core/time.d.ts +1 -1
  62. package/dist/phaser/core/time.d.ts.map +1 -1
  63. package/dist/phaser/core/timer.d.ts +1 -1
  64. package/dist/phaser/core/timer.d.ts.map +1 -1
  65. package/dist/phaser/core/timer_event.d.ts.map +1 -1
  66. package/dist/phaser/core/tween.d.ts +10 -7
  67. package/dist/phaser/core/tween.d.ts.map +1 -1
  68. package/dist/phaser/core/tween_data.d.ts +3 -2
  69. package/dist/phaser/core/tween_data.d.ts.map +1 -1
  70. package/dist/phaser/core/tween_easing.d.ts.map +1 -1
  71. package/dist/phaser/core/tween_manager.d.ts +3 -2
  72. package/dist/phaser/core/tween_manager.d.ts.map +1 -1
  73. package/dist/phaser/core/world.d.ts +3 -2
  74. package/dist/phaser/core/world.d.ts.map +1 -1
  75. package/dist/phaser/display/bitmap_text.d.ts +3 -2
  76. package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
  77. package/dist/phaser/display/button.d.ts +3 -2
  78. package/dist/phaser/display/button.d.ts.map +1 -1
  79. package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
  80. package/dist/phaser/display/canvas/graphics.d.ts +7 -6
  81. package/dist/phaser/display/canvas/graphics.d.ts.map +1 -1
  82. package/dist/phaser/display/canvas/pool.d.ts +2 -2
  83. package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
  84. package/dist/phaser/display/canvas/renderer.d.ts +10 -8
  85. package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
  86. package/dist/phaser/display/canvas/tinter.d.ts +3 -2
  87. package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
  88. package/dist/phaser/display/canvas/util.d.ts +2 -2
  89. package/dist/phaser/display/canvas/util.d.ts.map +1 -1
  90. package/dist/phaser/display/display_object.d.ts +14 -12
  91. package/dist/phaser/display/display_object.d.ts.map +1 -1
  92. package/dist/phaser/display/graphics.d.ts +8 -5
  93. package/dist/phaser/display/graphics.d.ts.map +1 -1
  94. package/dist/phaser/display/graphics_data.d.ts.map +1 -1
  95. package/dist/phaser/display/graphics_data_util.d.ts.map +1 -1
  96. package/dist/phaser/display/group.d.ts +4 -3
  97. package/dist/phaser/display/group.d.ts.map +1 -1
  98. package/dist/phaser/display/image.d.ts +13 -10
  99. package/dist/phaser/display/image.d.ts.map +1 -1
  100. package/dist/phaser/display/sprite_batch.d.ts +3 -2
  101. package/dist/phaser/display/sprite_batch.d.ts.map +1 -1
  102. package/dist/phaser/display/sprite_util.d.ts +18 -15
  103. package/dist/phaser/display/sprite_util.d.ts.map +1 -1
  104. package/dist/phaser/display/text.d.ts +11 -9
  105. package/dist/phaser/display/text.d.ts.map +1 -1
  106. package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
  107. package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
  108. package/dist/phaser/display/webgl/blend_manager.d.ts +0 -1
  109. package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
  110. package/dist/phaser/display/webgl/earcut.d.ts +1 -1
  111. package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
  112. package/dist/phaser/display/webgl/earcut_node.d.ts.map +1 -1
  113. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +4 -3
  114. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
  115. package/dist/phaser/display/webgl/filter_manager.d.ts +2 -1
  116. package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
  117. package/dist/phaser/display/webgl/filter_texture.d.ts +2 -1
  118. package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
  119. package/dist/phaser/display/webgl/graphics.d.ts +7 -6
  120. package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
  121. package/dist/phaser/display/webgl/graphics_data.d.ts +2 -1
  122. package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
  123. package/dist/phaser/display/webgl/render_texture.d.ts +4 -2
  124. package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
  125. package/dist/phaser/display/webgl/renderer.d.ts +16 -11
  126. package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
  127. package/dist/phaser/display/webgl/shader/complex.d.ts +16 -6
  128. package/dist/phaser/display/webgl/shader/complex.d.ts.map +1 -1
  129. package/dist/phaser/display/webgl/shader/fast.d.ts +19 -7
  130. package/dist/phaser/display/webgl/shader/fast.d.ts.map +1 -1
  131. package/dist/phaser/display/webgl/shader/normal.d.ts +33 -12
  132. package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  133. package/dist/phaser/display/webgl/shader/primitive.d.ts +15 -6
  134. package/dist/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
  135. package/dist/phaser/display/webgl/shader/strip.d.ts +15 -6
  136. package/dist/phaser/display/webgl/shader/strip.d.ts.map +1 -1
  137. package/dist/phaser/display/webgl/shader_manager.d.ts +16 -11
  138. package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
  139. package/dist/phaser/display/webgl/sprite_batch.d.ts +29 -20
  140. package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
  141. package/dist/phaser/display/webgl/stencil_manager.d.ts +12 -10
  142. package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
  143. package/dist/phaser/display/webgl/texture.d.ts +3 -2
  144. package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
  145. package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
  146. package/dist/phaser/display/webgl/util.d.ts.map +1 -1
  147. package/dist/phaser/geom/circle.d.ts +4 -1
  148. package/dist/phaser/geom/circle.d.ts.map +1 -1
  149. package/dist/phaser/geom/ellipse.d.ts.map +1 -1
  150. package/dist/phaser/geom/line.d.ts +1 -1
  151. package/dist/phaser/geom/line.d.ts.map +1 -1
  152. package/dist/phaser/geom/matrix.d.ts.map +1 -1
  153. package/dist/phaser/geom/point.d.ts.map +1 -1
  154. package/dist/phaser/geom/polygon.d.ts.map +1 -1
  155. package/dist/phaser/geom/rectangle.d.ts.map +1 -1
  156. package/dist/phaser/geom/rounded_rectangle.d.ts.map +1 -1
  157. package/dist/phaser/geom/util/circle.d.ts.map +1 -1
  158. package/dist/phaser/geom/util/ellipse.d.ts +3 -2
  159. package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
  160. package/dist/phaser/geom/util/line.d.ts.map +1 -1
  161. package/dist/phaser/geom/util/matrix.d.ts +2 -2
  162. package/dist/phaser/geom/util/matrix.d.ts.map +1 -1
  163. package/dist/phaser/geom/util/point.d.ts.map +1 -1
  164. package/dist/phaser/geom/util/rectangle.d.ts +1 -1
  165. package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
  166. package/dist/phaser/util/math.d.ts.map +1 -1
  167. package/package.json +5 -5
  168. package/src/phaser/core/animation.ts +64 -60
  169. package/src/phaser/core/animation_manager.ts +50 -53
  170. package/src/phaser/core/animation_parser.ts +9 -9
  171. package/src/phaser/core/array_set.ts +16 -17
  172. package/src/phaser/core/cache.ts +92 -93
  173. package/src/phaser/core/const.ts +1 -1
  174. package/src/phaser/core/device.ts +24 -29
  175. package/src/phaser/core/device_util.ts +22 -26
  176. package/src/phaser/core/dom.ts +54 -65
  177. package/src/phaser/core/event_manager.ts +64 -94
  178. package/src/phaser/core/factory.ts +14 -14
  179. package/src/phaser/core/frame.ts +28 -28
  180. package/src/phaser/core/frame_data.test.ts +100 -0
  181. package/src/phaser/core/frame_data.ts +24 -24
  182. package/src/phaser/core/frame_util.ts +2 -2
  183. package/src/phaser/core/game.ts +47 -48
  184. package/src/phaser/core/input.ts +104 -110
  185. package/src/phaser/core/input_handler.test.ts +113 -0
  186. package/src/phaser/core/input_handler.ts +199 -218
  187. package/src/phaser/core/input_mouse.ts +71 -54
  188. package/src/phaser/core/input_mspointer.ts +52 -39
  189. package/src/phaser/core/input_pointer.ts +81 -80
  190. package/src/phaser/core/input_touch.ts +49 -36
  191. package/src/phaser/core/loader.ts +173 -152
  192. package/src/phaser/core/loader_parser.ts +39 -57
  193. package/src/phaser/core/raf.ts +8 -7
  194. package/src/phaser/core/registry.test.ts +31 -0
  195. package/src/phaser/core/registry.ts +9 -0
  196. package/src/phaser/core/scale_manager.ts +156 -152
  197. package/src/phaser/core/scene.ts +9 -13
  198. package/src/phaser/core/scene_manager.ts +47 -47
  199. package/src/phaser/core/signal.test.ts +4 -4
  200. package/src/phaser/core/signal.ts +41 -52
  201. package/src/phaser/core/signal_binding.ts +26 -25
  202. package/src/phaser/core/signal_dispatch.test.ts +180 -0
  203. package/src/phaser/core/sound.ts +75 -83
  204. package/src/phaser/core/sound_manager.ts +52 -51
  205. package/src/phaser/core/sound_sprite.ts +17 -16
  206. package/src/phaser/core/stage.ts +25 -24
  207. package/src/phaser/core/time.ts +52 -52
  208. package/src/phaser/core/timer.test.ts +187 -0
  209. package/src/phaser/core/timer.ts +82 -69
  210. package/src/phaser/core/timer_event.ts +10 -10
  211. package/src/phaser/core/tween.ts +90 -93
  212. package/src/phaser/core/tween_data.ts +45 -51
  213. package/src/phaser/core/tween_easing.test.ts +106 -0
  214. package/src/phaser/core/tween_easing.ts +151 -123
  215. package/src/phaser/core/tween_manager.ts +19 -18
  216. package/src/phaser/core/world.ts +4 -3
  217. package/src/phaser/display/bitmap_text.ts +56 -64
  218. package/src/phaser/display/button.ts +33 -32
  219. package/src/phaser/display/canvas/buffer.ts +8 -8
  220. package/src/phaser/display/canvas/graphics.ts +36 -37
  221. package/src/phaser/display/canvas/masker.ts +2 -2
  222. package/src/phaser/display/canvas/pool.test.ts +106 -0
  223. package/src/phaser/display/canvas/pool.ts +25 -27
  224. package/src/phaser/display/canvas/renderer.ts +32 -31
  225. package/src/phaser/display/canvas/tinter.ts +25 -25
  226. package/src/phaser/display/canvas/util.ts +7 -10
  227. package/src/phaser/display/display_object.ts +114 -118
  228. package/src/phaser/display/graphics.ts +121 -119
  229. package/src/phaser/display/graphics_data.ts +12 -12
  230. package/src/phaser/display/graphics_data_util.ts +2 -3
  231. package/src/phaser/display/group.ts +50 -57
  232. package/src/phaser/display/image.ts +55 -52
  233. package/src/phaser/display/sprite_batch.ts +3 -2
  234. package/src/phaser/display/sprite_util.ts +48 -54
  235. package/src/phaser/display/text.ts +199 -204
  236. package/src/phaser/display/webgl/abstract_filter.ts +9 -9
  237. package/src/phaser/display/webgl/base_texture.ts +21 -24
  238. package/src/phaser/display/webgl/blend_manager.ts +6 -10
  239. package/src/phaser/display/webgl/earcut.ts +73 -37
  240. package/src/phaser/display/webgl/earcut_node.ts +10 -10
  241. package/src/phaser/display/webgl/fast_sprite_batch.ts +34 -34
  242. package/src/phaser/display/webgl/filter_manager.ts +13 -12
  243. package/src/phaser/display/webgl/filter_texture.ts +14 -13
  244. package/src/phaser/display/webgl/graphics.ts +51 -57
  245. package/src/phaser/display/webgl/graphics_data.ts +15 -14
  246. package/src/phaser/display/webgl/mask_manager.ts +2 -2
  247. package/src/phaser/display/webgl/render_texture.ts +26 -25
  248. package/src/phaser/display/webgl/renderer.ts +57 -62
  249. package/src/phaser/display/webgl/shader/complex.ts +28 -12
  250. package/src/phaser/display/webgl/shader/fast.ts +30 -12
  251. package/src/phaser/display/webgl/shader/normal.ts +70 -57
  252. package/src/phaser/display/webgl/shader/primitive.ts +26 -11
  253. package/src/phaser/display/webgl/shader/shader.test.ts +148 -0
  254. package/src/phaser/display/webgl/shader/strip.ts +27 -12
  255. package/src/phaser/display/webgl/shader_manager.test.ts +124 -0
  256. package/src/phaser/display/webgl/shader_manager.ts +26 -34
  257. package/src/phaser/display/webgl/sprite_batch.ts +67 -61
  258. package/src/phaser/display/webgl/stencil_manager.ts +23 -34
  259. package/src/phaser/display/webgl/texture.ts +43 -50
  260. package/src/phaser/display/webgl/texture_util.ts +2 -3
  261. package/src/phaser/display/webgl/util.ts +26 -25
  262. package/src/phaser/geom/circle.test.ts +2 -3
  263. package/src/phaser/geom/circle.ts +36 -36
  264. package/src/phaser/geom/ellipse.test.ts +73 -71
  265. package/src/phaser/geom/ellipse.ts +14 -14
  266. package/src/phaser/geom/line.test.ts +5 -5
  267. package/src/phaser/geom/line.ts +35 -35
  268. package/src/phaser/geom/matrix.test.ts +1 -1
  269. package/src/phaser/geom/matrix.ts +27 -27
  270. package/src/phaser/geom/point.test.ts +1 -2
  271. package/src/phaser/geom/point.ts +35 -35
  272. package/src/phaser/geom/polygon.test.ts +82 -0
  273. package/src/phaser/geom/polygon.ts +16 -16
  274. package/src/phaser/geom/rectangle.test.ts +14 -14
  275. package/src/phaser/geom/rectangle.ts +83 -75
  276. package/src/phaser/geom/rounded_rectangle.test.ts +1 -7
  277. package/src/phaser/geom/rounded_rectangle.ts +9 -9
  278. package/src/phaser/geom/util/circle.test.ts +25 -23
  279. package/src/phaser/geom/util/circle.ts +9 -18
  280. package/src/phaser/geom/util/ellipse.test.ts +7 -5
  281. package/src/phaser/geom/util/ellipse.ts +3 -2
  282. package/src/phaser/geom/util/line.test.ts +10 -8
  283. package/src/phaser/geom/util/line.ts +6 -16
  284. package/src/phaser/geom/util/matrix.test.ts +20 -18
  285. package/src/phaser/geom/util/matrix.ts +8 -15
  286. package/src/phaser/geom/util/point.test.ts +8 -6
  287. package/src/phaser/geom/util/point.ts +24 -28
  288. package/src/phaser/geom/util/polygon.test.ts +12 -10
  289. package/src/phaser/geom/util/polygon.ts +2 -2
  290. package/src/phaser/geom/util/rectangle.test.ts +10 -8
  291. package/src/phaser/geom/util/rectangle.ts +18 -37
  292. package/src/phaser/geom/util/rounded_rectangle.test.ts +11 -9
  293. package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
  294. package/src/phaser/util/math.test.ts +11 -11
  295. package/src/phaser/util/math.ts +29 -46
@@ -2,16 +2,16 @@ import { GEOM_POINT } from '../core/const.js';
2
2
  import { clone, distance, rotate } from './util/point.js';
3
3
 
4
4
  export class Point {
5
- x: number;
6
- y: number;
7
- type: number;
5
+ public x: number;
6
+ public y: number;
7
+ public type: number;
8
8
 
9
9
  /**
10
10
  * Creates a new Point instance.
11
11
  * @param {number} x - The x coordinate of the point (default: 0).
12
12
  * @param {number} y - The y coordinate of the point (default: 0).
13
13
  */
14
- constructor(x: number = 0, y: number = 0) {
14
+ public constructor(x = 0, y = 0) {
15
15
  /** @type {number} */
16
16
  this.x = x;
17
17
  /** @type {number} */
@@ -25,7 +25,7 @@ export class Point {
25
25
  * @param {Point} source - The point to copy coordinates from.
26
26
  * @returns {Point} This point instance for chaining.
27
27
  */
28
- copyFrom(source: Point) {
28
+ public copyFrom(source: Point) {
29
29
  return this.setTo(source.x, source.y);
30
30
  }
31
31
 
@@ -33,7 +33,7 @@ export class Point {
33
33
  * Returns a new point with the x and y coordinates swapped.
34
34
  * @returns {Point} A new point instance with swapped coordinates.
35
35
  */
36
- invert() {
36
+ public invert() {
37
37
  return this.setTo(this.y, this.x);
38
38
  }
39
39
 
@@ -43,9 +43,9 @@ export class Point {
43
43
  * @param {number} y - The new y coordinate for the point.
44
44
  * @returns {Point} This point instance for chaining.
45
45
  */
46
- setTo(x: number, y?: number) {
46
+ public setTo(x: number, y?: number) {
47
47
  this.x = x || 0;
48
- this.y = y || (y !== 0 ? this.x : 0);
48
+ this.y = y ?? (y !== 0 ? this.x : 0);
49
49
  return this;
50
50
  }
51
51
 
@@ -56,7 +56,7 @@ export class Point {
56
56
  * @returns {Point} This point instance for chaining.
57
57
  * @deprecated Use setTo instead.
58
58
  */
59
- set(x: number, y: number) {
59
+ public set(x: number, y: number) {
60
60
  this.x = x || 0;
61
61
  this.y = y || (y !== 0 ? this.x : 0);
62
62
  return this;
@@ -68,7 +68,7 @@ export class Point {
68
68
  * @param {number} y - The amount to add to the y coordinate.
69
69
  * @returns {Point} This point instance for chaining.
70
70
  */
71
- add(x: number, y: number) {
71
+ public add(x: number, y: number) {
72
72
  this.x += x;
73
73
  this.y += y;
74
74
  return this;
@@ -80,7 +80,7 @@ export class Point {
80
80
  * @param {number} y - The amount to subtract from the y coordinate.
81
81
  * @returns {Point} This point instance for chaining.
82
82
  */
83
- subtract(x: number, y: number) {
83
+ public subtract(x: number, y: number) {
84
84
  this.x -= x;
85
85
  this.y -= y;
86
86
  return this;
@@ -92,7 +92,7 @@ export class Point {
92
92
  * @param {number} y - The amount to multiply the y coordinate by.
93
93
  * @returns {Point} This point instance for chaining.
94
94
  */
95
- multiply(x: number, y: number) {
95
+ public multiply(x: number, y: number) {
96
96
  this.x *= x;
97
97
  this.y *= y;
98
98
  return this;
@@ -104,7 +104,7 @@ export class Point {
104
104
  * @param {number} y - The amount to divide the y coordinate by.
105
105
  * @returns {Point} This point instance for chaining.
106
106
  */
107
- divide(x: number, y: number) {
107
+ public divide(x: number, y: number) {
108
108
  this.x /= x;
109
109
  this.y /= y;
110
110
  return this;
@@ -116,7 +116,7 @@ export class Point {
116
116
  * @param {number} max - The maximum value for the x coordinate.
117
117
  * @returns {Point} This point instance for chaining.
118
118
  */
119
- clampX(min: number, max: number) {
119
+ public clampX(min: number, max: number) {
120
120
  this.x = Math.max(min, Math.min(max, this.x));
121
121
  return this;
122
122
  }
@@ -127,7 +127,7 @@ export class Point {
127
127
  * @param {number} max - The maximum value for the y coordinate.
128
128
  * @returns {Point} This point instance for chaining.
129
129
  */
130
- clampY(min: number, max: number) {
130
+ public clampY(min: number, max: number) {
131
131
  this.y = Math.max(min, Math.min(max, this.y));
132
132
  return this;
133
133
  }
@@ -138,7 +138,7 @@ export class Point {
138
138
  * @param {number} max - The maximum value for both coordinates.
139
139
  * @returns {Point} This point instance for chaining.
140
140
  */
141
- clamp(min: number, max: number) {
141
+ public clamp(min: number, max: number) {
142
142
  this.x = Math.max(min, Math.min(max, this.x));
143
143
  this.y = Math.max(min, Math.min(max, this.y));
144
144
  return this;
@@ -148,7 +148,7 @@ export class Point {
148
148
  * Creates a clone of this point.
149
149
  * @returns {Point} A new point with the same coordinates as this one.
150
150
  */
151
- clone() {
151
+ public clone() {
152
152
  return clone(this);
153
153
  }
154
154
 
@@ -157,7 +157,7 @@ export class Point {
157
157
  * @param {Point} dest - The point to copy coordinates to.
158
158
  * @returns {Point} The destination point.
159
159
  */
160
- copyTo(dest: Point) {
160
+ public copyTo(dest: Point) {
161
161
  dest.x = this.x;
162
162
  dest.y = this.y;
163
163
  return dest;
@@ -168,7 +168,7 @@ export class Point {
168
168
  * @param {Point} b - The other point to calculate the distance to.
169
169
  * @returns {number} The distance between the two points.
170
170
  */
171
- distance(b: Point) {
171
+ public distance(b: Point) {
172
172
  return distance(this, b);
173
173
  }
174
174
 
@@ -177,7 +177,7 @@ export class Point {
177
177
  * @param {Point} a - The other point to compare with.
178
178
  * @returns {boolean} True if the points have the same coordinates, false otherwise.
179
179
  */
180
- equals(a: Point) {
180
+ public equals(a: Point) {
181
181
  return a.x === this.x && a.y === this.y;
182
182
  }
183
183
 
@@ -187,7 +187,7 @@ export class Point {
187
187
  * @param {boolean} asDegrees - Whether to return the result in degrees (default: false).
188
188
  * @returns {number} The angle between the two points in radians or degrees.
189
189
  */
190
- angle(a: Point, asDegrees: boolean = false) {
190
+ public angle(a: Point, asDegrees = false) {
191
191
  if (asDegrees) {
192
192
  return (180 / Math.PI) * Math.atan2(a.y - this.y, a.x - this.x);
193
193
  }
@@ -203,7 +203,7 @@ export class Point {
203
203
  * @param {number | null | undefined} dist - The distance to rotate from (default: null).
204
204
  * @returns {Point} This point instance for chaining.
205
205
  */
206
- rotate(x: number, y: number, angle: number, asDegrees: boolean, dist: number | null | undefined = null) {
206
+ public rotate(x: number, y: number, angle: number, asDegrees: boolean, dist: number | null | undefined = null) {
207
207
  return rotate(this, x, y, angle, asDegrees, dist);
208
208
  }
209
209
 
@@ -211,7 +211,7 @@ export class Point {
211
211
  * Calculates the magnitude (length) of this point from the origin.
212
212
  * @returns {number} The magnitude of the point.
213
213
  */
214
- getMagnitude() {
214
+ public getMagnitude() {
215
215
  return Math.sqrt(this.x * this.x + this.y * this.y);
216
216
  }
217
217
 
@@ -219,7 +219,7 @@ export class Point {
219
219
  * Calculates the square of the magnitude (length) of this point from the origin.
220
220
  * @returns {number} The square of the magnitude of the point.
221
221
  */
222
- getMagnitudeSq() {
222
+ public getMagnitudeSq() {
223
223
  return this.x * this.x + this.y * this.y;
224
224
  }
225
225
 
@@ -228,7 +228,7 @@ export class Point {
228
228
  * @param {number} magnitude - The new magnitude for the point.
229
229
  * @returns {Point} This point instance for chaining.
230
230
  */
231
- setMagnitude(magnitude: number) {
231
+ public setMagnitude(magnitude: number) {
232
232
  return this.normalize().multiply(magnitude, magnitude);
233
233
  }
234
234
 
@@ -236,7 +236,7 @@ export class Point {
236
236
  * Normalizes this point to have a magnitude of 1 while preserving its direction.
237
237
  * @returns {Point} This point instance for chaining.
238
238
  */
239
- normalize() {
239
+ public normalize() {
240
240
  if (!this.isZero()) {
241
241
  const m = this.getMagnitude();
242
242
  this.x /= m;
@@ -249,7 +249,7 @@ export class Point {
249
249
  * Checks if this point has zero magnitude (is at the origin).
250
250
  * @returns {boolean} True if both x and y coordinates are zero, false otherwise.
251
251
  */
252
- isZero() {
252
+ public isZero() {
253
253
  return this.x === 0 && this.y === 0;
254
254
  }
255
255
 
@@ -258,7 +258,7 @@ export class Point {
258
258
  * @param {Point} a - The other point to calculate the dot product with.
259
259
  * @returns {number} The dot product of the two points.
260
260
  */
261
- dot(a: Point) {
261
+ public dot(a: Point) {
262
262
  return this.x * a.x + this.y * a.y;
263
263
  }
264
264
 
@@ -267,7 +267,7 @@ export class Point {
267
267
  * @param {Point} a - The other point to calculate the cross product with.
268
268
  * @returns {number} The cross product of the two points.
269
269
  */
270
- cross(a: Point) {
270
+ public cross(a: Point) {
271
271
  return this.x * a.y - this.y * a.x;
272
272
  }
273
273
 
@@ -275,7 +275,7 @@ export class Point {
275
275
  * Returns a perpendicular point (rotated 90 degrees counter-clockwise).
276
276
  * @returns {Point} A new point that is perpendicular to this one.
277
277
  */
278
- perp() {
278
+ public perp() {
279
279
  return this.setTo(-this.y, this.x);
280
280
  }
281
281
 
@@ -283,7 +283,7 @@ export class Point {
283
283
  * Returns a perpendicular point (rotated 90 degrees clockwise).
284
284
  * @returns {Point} A new point that is perpendicular to this one (rotated clockwise).
285
285
  */
286
- rperp() {
286
+ public rperp() {
287
287
  return this.setTo(this.y, -this.x);
288
288
  }
289
289
 
@@ -291,7 +291,7 @@ export class Point {
291
291
  * Returns a point with the same direction as this one but with y coordinate negated.
292
292
  * @returns {Point} A new point with the same x coordinate but negated y coordinate.
293
293
  */
294
- normalRightHand() {
294
+ public normalRightHand() {
295
295
  return this.setTo(this.y * -1, this.x);
296
296
  }
297
297
 
@@ -299,7 +299,7 @@ export class Point {
299
299
  * Returns a new point with the x and y coordinates rounded down to the nearest integer.
300
300
  * @returns {Point} A new point with floored coordinates.
301
301
  */
302
- floor() {
302
+ public floor() {
303
303
  return this.setTo(Math.floor(this.x), Math.floor(this.y));
304
304
  }
305
305
 
@@ -307,7 +307,7 @@ export class Point {
307
307
  * Returns a new point with the x and y coordinates rounded up to the nearest integer.
308
308
  * @returns {Point} A new point with ceiled coordinates.
309
309
  */
310
- ceil() {
310
+ public ceil() {
311
311
  return this.setTo(Math.ceil(this.x), Math.ceil(this.y));
312
312
  }
313
313
 
@@ -315,7 +315,7 @@ export class Point {
315
315
  * Returns a string representation of this point.
316
316
  * @returns {string} A string representation of the point in the format "[Point (x=value y=value)]".
317
317
  */
318
- toString() {
318
+ public toString() {
319
319
  return `[{Point (x=${this.x} y=${this.y})}]`;
320
320
  }
321
321
  }
@@ -0,0 +1,82 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { Point } from './point.js';
3
+ import { Polygon } from './polygon.js';
4
+
5
+ const square = (): Polygon => new Polygon([new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10)]);
6
+
7
+ const triangle = (): Polygon => new Polygon([new Point(0, 0), new Point(10, 0), new Point(0, 10)]);
8
+
9
+ describe('Polygon', () => {
10
+ describe('contains', () => {
11
+ it('accepts a point well inside a square', () => {
12
+ expect(square().contains(5, 5)).toBe(true);
13
+ });
14
+
15
+ it('rejects points outside a square on every side', () => {
16
+ const polygon = square();
17
+ expect(polygon.contains(-1, 5)).toBe(false);
18
+ expect(polygon.contains(11, 5)).toBe(false);
19
+ expect(polygon.contains(5, -1)).toBe(false);
20
+ expect(polygon.contains(5, 11)).toBe(false);
21
+ });
22
+
23
+ it('accepts a point inside a triangle and rejects one in the cut corner', () => {
24
+ const polygon = triangle();
25
+ expect(polygon.contains(2, 2)).toBe(true);
26
+ expect(polygon.contains(8, 8)).toBe(false);
27
+ });
28
+
29
+ it('agrees with itself once flattened', () => {
30
+ const probes: [number, number][] = [
31
+ [5, 5],
32
+ [-1, 5],
33
+ [11, 5],
34
+ [2, 2],
35
+ [9, 9],
36
+ [0.5, 9.5],
37
+ ];
38
+ const asPoints = square();
39
+ const asNumbers = square().flatten();
40
+ for (const [x, y] of probes) {
41
+ expect(asNumbers.contains(x, y)).toBe(asPoints.contains(x, y));
42
+ }
43
+ });
44
+
45
+ it('agrees with itself once flattened for a triangle', () => {
46
+ const probes: [number, number][] = [
47
+ [2, 2],
48
+ [8, 8],
49
+ [1, 8],
50
+ [9, 0.5],
51
+ [-5, -5],
52
+ ];
53
+ const asPoints = triangle();
54
+ const asNumbers = triangle().flatten();
55
+ for (const [x, y] of probes) {
56
+ expect(asNumbers.contains(x, y)).toBe(asPoints.contains(x, y));
57
+ }
58
+ });
59
+
60
+ it('reports false for a polygon with no points', () => {
61
+ expect(new Polygon().contains(0, 0)).toBe(false);
62
+ });
63
+ });
64
+
65
+ describe('toNumberArray', () => {
66
+ it('flattens points to x/y pairs', () => {
67
+ expect(square().toNumberArray()).toStrictEqual([0, 0, 10, 0, 10, 10, 0, 10]);
68
+ });
69
+
70
+ it('passes an already flattened polygon through unchanged', () => {
71
+ expect(square().flatten().toNumberArray()).toStrictEqual([0, 0, 10, 0, 10, 10, 0, 10]);
72
+ });
73
+ });
74
+
75
+ describe('flatten', () => {
76
+ it('marks the polygon flattened and swaps the point representation', () => {
77
+ const polygon = square().flatten();
78
+ expect(polygon.flattened).toBe(true);
79
+ expect(polygon._points.every((value) => typeof value === 'number')).toBe(true);
80
+ });
81
+ });
82
+ });
@@ -3,19 +3,19 @@ import { clone } from './util/polygon.js';
3
3
  import { GEOM_POLYGON } from '../core/const.js';
4
4
 
5
5
  export class Polygon {
6
- area: number;
7
- _points: any[];
8
- closed: boolean;
9
- flattened: boolean;
10
- type: number;
6
+ public area = 0;
7
+ public _points: any[];
8
+ public closed: boolean;
9
+ public flattened: boolean;
10
+ public type: number;
11
11
 
12
12
  /**
13
13
  * Creates a new Polygon instance.
14
14
  * @param {object[]} points - The array of points to define the polygon (optional).
15
15
  */
16
- constructor(points: any[] | null = null) {
16
+ public constructor(points: any[] | null = null) {
17
17
  /** @type {number} */
18
- this.area = 0;
18
+
19
19
  /** @type {Point[]} */
20
20
  this._points = [];
21
21
  /** @type {boolean} */
@@ -34,7 +34,7 @@ export class Polygon {
34
34
  * @param {number[]} output - The array to store the result in (optional).
35
35
  * @returns {number[]} An array of numbers representing the polygon's points.
36
36
  */
37
- toNumberArray(output: number[] = []) {
37
+ public toNumberArray(output: number[] = []) {
38
38
  for (let i = 0; i < this._points.length; i += 1) {
39
39
  if (typeof this._points[i] === 'number') {
40
40
  output.push(this._points[i]);
@@ -52,7 +52,7 @@ export class Polygon {
52
52
  * Flattens the polygon's point array to a simple numeric array.
53
53
  * @returns {Polygon} This polygon instance for chaining.
54
54
  */
55
- flatten() {
55
+ public flatten() {
56
56
  this._points = this.toNumberArray();
57
57
  this.flattened = true;
58
58
  return this;
@@ -62,7 +62,7 @@ export class Polygon {
62
62
  * Creates a clone of this polygon.
63
63
  * @returns {Polygon} A new polygon with the same values as this one.
64
64
  */
65
- clone() {
65
+ public clone() {
66
66
  return clone(this);
67
67
  }
68
68
 
@@ -72,7 +72,7 @@ export class Polygon {
72
72
  * @param {number} y - The y coordinate of the point to check.
73
73
  * @returns {boolean} True if the point is contained within this polygon, false otherwise.
74
74
  */
75
- contains(x: number, y: number) {
75
+ public contains(x: number, y: number) {
76
76
  // Adapted from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html by Jonas Raoni Soares Silva
77
77
  let inside = false;
78
78
  if (this.flattened) {
@@ -86,7 +86,7 @@ export class Polygon {
86
86
  }
87
87
  }
88
88
  } else {
89
- for (let i = -1, j = this._points.length - 1; ++i < this._points.length; j = i) {
89
+ for (let i = 0, j = this._points.length - 1; i < this._points.length; j = i, i += 1) {
90
90
  const ix = this._points[i].x;
91
91
  const iy = this._points[i].y;
92
92
  const jx = this._points[j].x;
@@ -104,7 +104,7 @@ export class Polygon {
104
104
  * @param {object[]} points - The array of points to define the polygon.
105
105
  * @returns {Polygon} This polygon instance for chaining.
106
106
  */
107
- setTo(points: any[]) {
107
+ public setTo(points: any[]) {
108
108
  this.area = 0;
109
109
  this._points = [];
110
110
  if (points) {
@@ -143,7 +143,7 @@ export class Polygon {
143
143
  * @param {number} y0 - The y coordinate of the lowest boundary (internal use).
144
144
  * @returns {number} The area of this polygon.
145
145
  */
146
- calculateArea(y0: number) {
146
+ public calculateArea(y0: number) {
147
147
  let p1;
148
148
  let p2;
149
149
  let avgHeight;
@@ -166,14 +166,14 @@ export class Polygon {
166
166
  * Gets the points of this polygon.
167
167
  * @returns {object[]} The array of points that define this polygon.
168
168
  */
169
- get points() {
169
+ public get points() {
170
170
  return this._points;
171
171
  }
172
172
 
173
173
  /**
174
174
  * Sets the points of this polygon.
175
175
  */
176
- set points(value) {
176
+ public set points(value) {
177
177
  if (value !== null) {
178
178
  this.setTo(value);
179
179
  } else {
@@ -1,4 +1,4 @@
1
- import { expect } from 'vitest';
1
+ import { expect, describe, it } from 'vitest';
2
2
  import { TOP_LEFT } from '../core/const.js';
3
3
  import { Point } from './point.js';
4
4
  import { Rectangle } from './rectangle.js';
@@ -328,7 +328,7 @@ describe('Rectangle', () => {
328
328
  describe('top', () => {
329
329
  it('should get and set the top coordinate of this rectangle', () => {
330
330
  const rect = new Rectangle(0, 0, 10, 10);
331
- const top = rect.top;
331
+ const { top } = rect;
332
332
  expect(top).toBe(rect.y);
333
333
  rect.top = 1000;
334
334
  expect(rect.top).toBe(1000);
@@ -338,7 +338,7 @@ describe('Rectangle', () => {
338
338
  describe('left', () => {
339
339
  it('should get and set the left coordinate of this rectangle', () => {
340
340
  const rect = new Rectangle(0, 0, 10, 10);
341
- const left = rect.left;
341
+ const { left } = rect;
342
342
  expect(left).toBe(rect.x);
343
343
  rect.left = 1500;
344
344
  expect(rect.left).toBe(1500);
@@ -348,7 +348,7 @@ describe('Rectangle', () => {
348
348
  describe('right', () => {
349
349
  it('should get and set the right coordinate of this rectangle', () => {
350
350
  const rect = new Rectangle(0, 0, 10, 10);
351
- const right = rect.right;
351
+ const { right } = rect;
352
352
  expect(right).toBe(rect.x + rect.width);
353
353
  rect.right = 1600;
354
354
  expect(rect.right).toBe(1600);
@@ -358,7 +358,7 @@ describe('Rectangle', () => {
358
358
  describe('bottom', () => {
359
359
  it('should get and set the bottom coordinate of this rectangle', () => {
360
360
  const rect = new Rectangle(0, 0, 10, 10);
361
- const bottom = rect.bottom;
361
+ const { bottom } = rect;
362
362
  expect(bottom).toBe(rect.y + rect.height);
363
363
  rect.bottom = 1700;
364
364
  expect(rect.bottom).toBe(1700);
@@ -368,7 +368,7 @@ describe('Rectangle', () => {
368
368
  describe('topLeft', () => {
369
369
  it('should get and set the top-left coordinates of this rectangle', () => {
370
370
  const rect = new Rectangle(0, 0, 10, 10);
371
- const topLeft = rect.topLeft;
371
+ const { topLeft } = rect;
372
372
  expect(topLeft.x).toBe(rect.left);
373
373
  expect(topLeft.y).toBe(rect.top);
374
374
  rect.topLeft = new Point(1800, 1900);
@@ -380,7 +380,7 @@ describe('Rectangle', () => {
380
380
  describe('topRight', () => {
381
381
  it('should get and set the top-right coordinates of this rectangle', () => {
382
382
  const rect = new Rectangle(0, 0, 10, 10);
383
- const topRight = rect.topRight;
383
+ const { topRight } = rect;
384
384
  expect(topRight.x).toBe(rect.right);
385
385
  expect(topRight.y).toBe(rect.top);
386
386
  rect.topRight = new Point(2000, 2100);
@@ -392,7 +392,7 @@ describe('Rectangle', () => {
392
392
  describe('bottomLeft', () => {
393
393
  it('should get and set the bottom-left coordinates of this rectangle', () => {
394
394
  const rect = new Rectangle(0, 0, 10, 10);
395
- const bottomLeft = rect.bottomLeft;
395
+ const { bottomLeft } = rect;
396
396
  expect(bottomLeft.x).toBe(rect.left);
397
397
  expect(bottomLeft.y).toBe(rect.bottom);
398
398
  rect.bottomLeft = new Point(2200, 2300);
@@ -404,7 +404,7 @@ describe('Rectangle', () => {
404
404
  describe('bottomRight', () => {
405
405
  it('should get and set the bottom-right coordinates of this rectangle', () => {
406
406
  const rect = new Rectangle(0, 0, 10, 10);
407
- const bottomRight = rect.bottomRight;
407
+ const { bottomRight } = rect;
408
408
  expect(bottomRight.x).toBe(rect.right);
409
409
  expect(bottomRight.y).toBe(rect.bottom);
410
410
  rect.bottomRight = new Point(2400, 2500);
@@ -416,7 +416,7 @@ describe('Rectangle', () => {
416
416
  describe('centerX', () => {
417
417
  it('should get and set the center x coordinate of this rectangle', () => {
418
418
  const rect = new Rectangle(0, 0, 10, 10);
419
- const centerX = rect.centerX;
419
+ const { centerX } = rect;
420
420
  expect(centerX).toBe(rect.x + rect.halfWidth);
421
421
  rect.centerX = 2600;
422
422
  expect(rect.centerX).toBe(2600);
@@ -426,7 +426,7 @@ describe('Rectangle', () => {
426
426
  describe('centerY', () => {
427
427
  it('should get and set the center y coordinate of this rectangle', () => {
428
428
  const rect = new Rectangle(0, 0, 10, 10);
429
- const centerY = rect.centerY;
429
+ const { centerY } = rect;
430
430
  expect(centerY).toBe(rect.y + rect.halfHeight);
431
431
  rect.centerY = 2700;
432
432
  expect(rect.centerY).toBe(2700);
@@ -436,7 +436,7 @@ describe('Rectangle', () => {
436
436
  describe('randomX', () => {
437
437
  it('should return a random x coordinate within this rectangle', () => {
438
438
  const rect = new Rectangle(0, 0, 10, 10);
439
- const randomX = rect.randomX;
439
+ const { randomX } = rect;
440
440
  expect(randomX >= rect.left && randomX <= rect.right).toBe(true);
441
441
  });
442
442
  });
@@ -444,7 +444,7 @@ describe('Rectangle', () => {
444
444
  describe('randomY', () => {
445
445
  it('should return a random y coordinate within this rectangle', () => {
446
446
  const rect = new Rectangle(0, 0, 10, 10);
447
- const randomY = rect.randomY;
447
+ const { randomY } = rect;
448
448
  expect(randomY >= rect.top && randomY <= rect.bottom).toBe(true);
449
449
  });
450
450
  });
@@ -452,7 +452,7 @@ describe('Rectangle', () => {
452
452
  describe('empty', () => {
453
453
  it('should get and set whether this rectangle is empty or not', () => {
454
454
  const rect = new Rectangle(0, 0, 10, 10);
455
- const empty = rect.empty;
455
+ const { empty } = rect;
456
456
  expect(empty).toBe(!rect.width || !rect.height);
457
457
  rect.empty = true;
458
458
  expect(rect.empty).toBe(true);