@vpmedia/phaser 1.111.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 (296) hide show
  1. package/dist/index.js +1300 -1334
  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 +1 -1
  23. package/dist/phaser/core/game.d.ts.map +1 -1
  24. package/dist/phaser/core/input.d.ts +8 -6
  25. package/dist/phaser/core/input.d.ts.map +1 -1
  26. package/dist/phaser/core/input_handler.d.ts +40 -30
  27. package/dist/phaser/core/input_handler.d.ts.map +1 -1
  28. package/dist/phaser/core/input_mouse.d.ts +3 -2
  29. package/dist/phaser/core/input_mouse.d.ts.map +1 -1
  30. package/dist/phaser/core/input_mspointer.d.ts +3 -2
  31. package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
  32. package/dist/phaser/core/input_pointer.d.ts +6 -4
  33. package/dist/phaser/core/input_pointer.d.ts.map +1 -1
  34. package/dist/phaser/core/input_touch.d.ts +3 -2
  35. package/dist/phaser/core/input_touch.d.ts.map +1 -1
  36. package/dist/phaser/core/loader.d.ts +4 -3
  37. package/dist/phaser/core/loader.d.ts.map +1 -1
  38. package/dist/phaser/core/loader_parser.d.ts +9 -8
  39. package/dist/phaser/core/loader_parser.d.ts.map +1 -1
  40. package/dist/phaser/core/raf.d.ts +3 -2
  41. package/dist/phaser/core/raf.d.ts.map +1 -1
  42. package/dist/phaser/core/registry.d.ts +7 -0
  43. package/dist/phaser/core/registry.d.ts.map +1 -0
  44. package/dist/phaser/core/scale_manager.d.ts +1 -1
  45. package/dist/phaser/core/scale_manager.d.ts.map +1 -1
  46. package/dist/phaser/core/scene.d.ts +0 -1
  47. package/dist/phaser/core/scene.d.ts.map +1 -1
  48. package/dist/phaser/core/scene_manager.d.ts +1 -1
  49. package/dist/phaser/core/scene_manager.d.ts.map +1 -1
  50. package/dist/phaser/core/signal.d.ts +0 -1
  51. package/dist/phaser/core/signal.d.ts.map +1 -1
  52. package/dist/phaser/core/signal_binding.d.ts +4 -3
  53. package/dist/phaser/core/signal_binding.d.ts.map +1 -1
  54. package/dist/phaser/core/sound.d.ts +6 -4
  55. package/dist/phaser/core/sound.d.ts.map +1 -1
  56. package/dist/phaser/core/sound_manager.d.ts +3 -2
  57. package/dist/phaser/core/sound_manager.d.ts.map +1 -1
  58. package/dist/phaser/core/sound_sprite.d.ts +5 -4
  59. package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
  60. package/dist/phaser/core/stage.d.ts +3 -2
  61. package/dist/phaser/core/stage.d.ts.map +1 -1
  62. package/dist/phaser/core/time.d.ts +1 -1
  63. package/dist/phaser/core/time.d.ts.map +1 -1
  64. package/dist/phaser/core/timer.d.ts +1 -1
  65. package/dist/phaser/core/timer.d.ts.map +1 -1
  66. package/dist/phaser/core/timer_event.d.ts.map +1 -1
  67. package/dist/phaser/core/tween.d.ts +10 -7
  68. package/dist/phaser/core/tween.d.ts.map +1 -1
  69. package/dist/phaser/core/tween_data.d.ts +3 -2
  70. package/dist/phaser/core/tween_data.d.ts.map +1 -1
  71. package/dist/phaser/core/tween_easing.d.ts.map +1 -1
  72. package/dist/phaser/core/tween_manager.d.ts +3 -2
  73. package/dist/phaser/core/tween_manager.d.ts.map +1 -1
  74. package/dist/phaser/core/world.d.ts +3 -2
  75. package/dist/phaser/core/world.d.ts.map +1 -1
  76. package/dist/phaser/display/bitmap_text.d.ts +3 -2
  77. package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
  78. package/dist/phaser/display/button.d.ts +3 -2
  79. package/dist/phaser/display/button.d.ts.map +1 -1
  80. package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
  81. package/dist/phaser/display/canvas/graphics.d.ts +7 -6
  82. package/dist/phaser/display/canvas/graphics.d.ts.map +1 -1
  83. package/dist/phaser/display/canvas/pool.d.ts +2 -2
  84. package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
  85. package/dist/phaser/display/canvas/renderer.d.ts +10 -8
  86. package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
  87. package/dist/phaser/display/canvas/tinter.d.ts +3 -2
  88. package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
  89. package/dist/phaser/display/canvas/util.d.ts +2 -2
  90. package/dist/phaser/display/canvas/util.d.ts.map +1 -1
  91. package/dist/phaser/display/display_object.d.ts +14 -12
  92. package/dist/phaser/display/display_object.d.ts.map +1 -1
  93. package/dist/phaser/display/graphics.d.ts +8 -5
  94. package/dist/phaser/display/graphics.d.ts.map +1 -1
  95. package/dist/phaser/display/graphics_data.d.ts.map +1 -1
  96. package/dist/phaser/display/graphics_data_util.d.ts.map +1 -1
  97. package/dist/phaser/display/group.d.ts +4 -3
  98. package/dist/phaser/display/group.d.ts.map +1 -1
  99. package/dist/phaser/display/image.d.ts +13 -10
  100. package/dist/phaser/display/image.d.ts.map +1 -1
  101. package/dist/phaser/display/sprite_batch.d.ts +3 -2
  102. package/dist/phaser/display/sprite_batch.d.ts.map +1 -1
  103. package/dist/phaser/display/sprite_util.d.ts +18 -15
  104. package/dist/phaser/display/sprite_util.d.ts.map +1 -1
  105. package/dist/phaser/display/text.d.ts +11 -9
  106. package/dist/phaser/display/text.d.ts.map +1 -1
  107. package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
  108. package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
  109. package/dist/phaser/display/webgl/blend_manager.d.ts +0 -1
  110. package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
  111. package/dist/phaser/display/webgl/earcut.d.ts +1 -1
  112. package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
  113. package/dist/phaser/display/webgl/earcut_node.d.ts.map +1 -1
  114. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +4 -3
  115. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
  116. package/dist/phaser/display/webgl/filter_manager.d.ts +2 -1
  117. package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
  118. package/dist/phaser/display/webgl/filter_texture.d.ts +2 -1
  119. package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
  120. package/dist/phaser/display/webgl/graphics.d.ts +7 -6
  121. package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
  122. package/dist/phaser/display/webgl/graphics_data.d.ts +2 -1
  123. package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
  124. package/dist/phaser/display/webgl/render_texture.d.ts +4 -2
  125. package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
  126. package/dist/phaser/display/webgl/renderer.d.ts +16 -11
  127. package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
  128. package/dist/phaser/display/webgl/shader/complex.d.ts +16 -6
  129. package/dist/phaser/display/webgl/shader/complex.d.ts.map +1 -1
  130. package/dist/phaser/display/webgl/shader/fast.d.ts +19 -7
  131. package/dist/phaser/display/webgl/shader/fast.d.ts.map +1 -1
  132. package/dist/phaser/display/webgl/shader/normal.d.ts +33 -12
  133. package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  134. package/dist/phaser/display/webgl/shader/primitive.d.ts +15 -6
  135. package/dist/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
  136. package/dist/phaser/display/webgl/shader/strip.d.ts +15 -6
  137. package/dist/phaser/display/webgl/shader/strip.d.ts.map +1 -1
  138. package/dist/phaser/display/webgl/shader_manager.d.ts +16 -11
  139. package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
  140. package/dist/phaser/display/webgl/sprite_batch.d.ts +29 -20
  141. package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
  142. package/dist/phaser/display/webgl/stencil_manager.d.ts +12 -10
  143. package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
  144. package/dist/phaser/display/webgl/texture.d.ts +3 -2
  145. package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
  146. package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
  147. package/dist/phaser/display/webgl/util.d.ts.map +1 -1
  148. package/dist/phaser/geom/circle.d.ts +4 -1
  149. package/dist/phaser/geom/circle.d.ts.map +1 -1
  150. package/dist/phaser/geom/ellipse.d.ts.map +1 -1
  151. package/dist/phaser/geom/line.d.ts +1 -1
  152. package/dist/phaser/geom/line.d.ts.map +1 -1
  153. package/dist/phaser/geom/matrix.d.ts.map +1 -1
  154. package/dist/phaser/geom/point.d.ts.map +1 -1
  155. package/dist/phaser/geom/polygon.d.ts.map +1 -1
  156. package/dist/phaser/geom/rectangle.d.ts.map +1 -1
  157. package/dist/phaser/geom/rounded_rectangle.d.ts.map +1 -1
  158. package/dist/phaser/geom/util/circle.d.ts.map +1 -1
  159. package/dist/phaser/geom/util/ellipse.d.ts +3 -2
  160. package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
  161. package/dist/phaser/geom/util/line.d.ts.map +1 -1
  162. package/dist/phaser/geom/util/matrix.d.ts +2 -2
  163. package/dist/phaser/geom/util/matrix.d.ts.map +1 -1
  164. package/dist/phaser/geom/util/point.d.ts.map +1 -1
  165. package/dist/phaser/geom/util/rectangle.d.ts +1 -1
  166. package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
  167. package/dist/phaser/util/math.d.ts.map +1 -1
  168. package/package.json +5 -4
  169. package/src/phaser/core/animation.ts +64 -60
  170. package/src/phaser/core/animation_manager.ts +54 -55
  171. package/src/phaser/core/animation_parser.ts +9 -9
  172. package/src/phaser/core/array_set.ts +16 -17
  173. package/src/phaser/core/cache.ts +92 -93
  174. package/src/phaser/core/const.ts +1 -1
  175. package/src/phaser/core/device.ts +24 -29
  176. package/src/phaser/core/device_util.ts +28 -32
  177. package/src/phaser/core/dom.ts +54 -65
  178. package/src/phaser/core/event_manager.ts +64 -94
  179. package/src/phaser/core/factory.ts +14 -14
  180. package/src/phaser/core/frame.ts +28 -28
  181. package/src/phaser/core/frame_data.test.ts +100 -0
  182. package/src/phaser/core/frame_data.ts +24 -24
  183. package/src/phaser/core/frame_util.ts +2 -2
  184. package/src/phaser/core/game.ts +50 -51
  185. package/src/phaser/core/input.ts +104 -110
  186. package/src/phaser/core/input_handler.test.ts +113 -0
  187. package/src/phaser/core/input_handler.ts +199 -218
  188. package/src/phaser/core/input_mouse.ts +71 -54
  189. package/src/phaser/core/input_mspointer.ts +52 -39
  190. package/src/phaser/core/input_pointer.ts +81 -80
  191. package/src/phaser/core/input_touch.ts +49 -36
  192. package/src/phaser/core/loader.ts +175 -154
  193. package/src/phaser/core/loader_parser.ts +39 -57
  194. package/src/phaser/core/raf.ts +8 -7
  195. package/src/phaser/core/registry.test.ts +31 -0
  196. package/src/phaser/core/registry.ts +9 -0
  197. package/src/phaser/core/scale_manager.ts +156 -152
  198. package/src/phaser/core/scene.ts +9 -13
  199. package/src/phaser/core/scene_manager.ts +47 -47
  200. package/src/phaser/core/signal.test.ts +4 -4
  201. package/src/phaser/core/signal.ts +41 -52
  202. package/src/phaser/core/signal_binding.ts +26 -25
  203. package/src/phaser/core/signal_dispatch.test.ts +180 -0
  204. package/src/phaser/core/sound.ts +75 -83
  205. package/src/phaser/core/sound_manager.ts +58 -56
  206. package/src/phaser/core/sound_sprite.ts +17 -16
  207. package/src/phaser/core/stage.ts +25 -24
  208. package/src/phaser/core/time.ts +52 -52
  209. package/src/phaser/core/timer.test.ts +187 -0
  210. package/src/phaser/core/timer.ts +82 -69
  211. package/src/phaser/core/timer_event.ts +10 -10
  212. package/src/phaser/core/tween.ts +90 -93
  213. package/src/phaser/core/tween_data.ts +45 -51
  214. package/src/phaser/core/tween_easing.test.ts +106 -0
  215. package/src/phaser/core/tween_easing.ts +151 -123
  216. package/src/phaser/core/tween_manager.ts +19 -18
  217. package/src/phaser/core/world.ts +4 -3
  218. package/src/phaser/display/bitmap_text.ts +56 -64
  219. package/src/phaser/display/button.ts +33 -32
  220. package/src/phaser/display/canvas/buffer.ts +8 -8
  221. package/src/phaser/display/canvas/graphics.ts +36 -37
  222. package/src/phaser/display/canvas/masker.ts +2 -2
  223. package/src/phaser/display/canvas/pool.test.ts +106 -0
  224. package/src/phaser/display/canvas/pool.ts +25 -27
  225. package/src/phaser/display/canvas/renderer.ts +32 -31
  226. package/src/phaser/display/canvas/tinter.ts +27 -27
  227. package/src/phaser/display/canvas/util.ts +7 -10
  228. package/src/phaser/display/display_object.ts +114 -118
  229. package/src/phaser/display/graphics.ts +121 -119
  230. package/src/phaser/display/graphics_data.ts +12 -12
  231. package/src/phaser/display/graphics_data_util.ts +2 -3
  232. package/src/phaser/display/group.ts +50 -57
  233. package/src/phaser/display/image.ts +55 -52
  234. package/src/phaser/display/sprite_batch.ts +3 -2
  235. package/src/phaser/display/sprite_util.ts +48 -54
  236. package/src/phaser/display/text.ts +199 -204
  237. package/src/phaser/display/webgl/abstract_filter.ts +9 -9
  238. package/src/phaser/display/webgl/base_texture.ts +21 -24
  239. package/src/phaser/display/webgl/blend_manager.ts +6 -10
  240. package/src/phaser/display/webgl/earcut.ts +73 -37
  241. package/src/phaser/display/webgl/earcut_node.ts +10 -10
  242. package/src/phaser/display/webgl/fast_sprite_batch.ts +34 -34
  243. package/src/phaser/display/webgl/filter_manager.ts +13 -12
  244. package/src/phaser/display/webgl/filter_texture.ts +14 -13
  245. package/src/phaser/display/webgl/graphics.ts +51 -57
  246. package/src/phaser/display/webgl/graphics_data.ts +15 -14
  247. package/src/phaser/display/webgl/mask_manager.ts +2 -2
  248. package/src/phaser/display/webgl/render_texture.ts +26 -25
  249. package/src/phaser/display/webgl/renderer.ts +57 -62
  250. package/src/phaser/display/webgl/shader/complex.ts +28 -12
  251. package/src/phaser/display/webgl/shader/fast.ts +30 -12
  252. package/src/phaser/display/webgl/shader/normal.ts +70 -57
  253. package/src/phaser/display/webgl/shader/primitive.ts +26 -11
  254. package/src/phaser/display/webgl/shader/shader.test.ts +148 -0
  255. package/src/phaser/display/webgl/shader/strip.ts +27 -12
  256. package/src/phaser/display/webgl/shader_manager.test.ts +124 -0
  257. package/src/phaser/display/webgl/shader_manager.ts +26 -34
  258. package/src/phaser/display/webgl/sprite_batch.ts +67 -61
  259. package/src/phaser/display/webgl/stencil_manager.ts +23 -34
  260. package/src/phaser/display/webgl/texture.ts +43 -50
  261. package/src/phaser/display/webgl/texture_util.ts +2 -3
  262. package/src/phaser/display/webgl/util.ts +26 -25
  263. package/src/phaser/geom/circle.test.ts +2 -3
  264. package/src/phaser/geom/circle.ts +36 -36
  265. package/src/phaser/geom/ellipse.test.ts +73 -71
  266. package/src/phaser/geom/ellipse.ts +14 -14
  267. package/src/phaser/geom/line.test.ts +5 -5
  268. package/src/phaser/geom/line.ts +35 -35
  269. package/src/phaser/geom/matrix.test.ts +1 -1
  270. package/src/phaser/geom/matrix.ts +27 -27
  271. package/src/phaser/geom/point.test.ts +1 -2
  272. package/src/phaser/geom/point.ts +35 -35
  273. package/src/phaser/geom/polygon.test.ts +82 -0
  274. package/src/phaser/geom/polygon.ts +16 -16
  275. package/src/phaser/geom/rectangle.test.ts +14 -14
  276. package/src/phaser/geom/rectangle.ts +83 -75
  277. package/src/phaser/geom/rounded_rectangle.test.ts +1 -7
  278. package/src/phaser/geom/rounded_rectangle.ts +9 -9
  279. package/src/phaser/geom/util/circle.test.ts +25 -23
  280. package/src/phaser/geom/util/circle.ts +9 -18
  281. package/src/phaser/geom/util/ellipse.test.ts +7 -5
  282. package/src/phaser/geom/util/ellipse.ts +3 -2
  283. package/src/phaser/geom/util/line.test.ts +10 -8
  284. package/src/phaser/geom/util/line.ts +6 -16
  285. package/src/phaser/geom/util/matrix.test.ts +20 -18
  286. package/src/phaser/geom/util/matrix.ts +8 -15
  287. package/src/phaser/geom/util/point.test.ts +8 -6
  288. package/src/phaser/geom/util/point.ts +24 -28
  289. package/src/phaser/geom/util/polygon.test.ts +12 -10
  290. package/src/phaser/geom/util/polygon.ts +2 -2
  291. package/src/phaser/geom/util/rectangle.test.ts +10 -8
  292. package/src/phaser/geom/util/rectangle.ts +18 -37
  293. package/src/phaser/geom/util/rounded_rectangle.test.ts +11 -9
  294. package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
  295. package/src/phaser/util/math.test.ts +11 -11
  296. package/src/phaser/util/math.ts +29 -46
@@ -9,7 +9,7 @@ import { Point } from '../point.js';
9
9
  * @returns {Circle} The cloned circle.
10
10
  */
11
11
  export const clone = (input: Circle, output: Circle | null = null) => {
12
- const result = output || new Circle();
12
+ const result = output ?? new Circle();
13
13
  result.x = input.x;
14
14
  result.y = input.y;
15
15
  result.diameter = input.diameter;
@@ -38,9 +38,7 @@ export const contains = (a: Circle, x: number, y: number) => {
38
38
  * @param {Circle} b - The second circle to compare.
39
39
  * @returns {boolean} True if the circles are equal, false otherwise.
40
40
  */
41
- export const equals = (a: Circle, b: Circle) => {
42
- return a.x === b.x && a.y === b.y && a.diameter === b.diameter;
43
- };
41
+ export const equals = (a: Circle, b: Circle) => a.x === b.x && a.y === b.y && a.diameter === b.diameter;
44
42
 
45
43
  /**
46
44
  * Checks if two circles intersect.
@@ -48,9 +46,7 @@ export const equals = (a: Circle, b: Circle) => {
48
46
  * @param {Circle} b - The second circle to check.
49
47
  * @returns {boolean} True if the circles intersect, false otherwise.
50
48
  */
51
- export const intersects = (a: Circle, b: Circle) => {
52
- return distance(a.x, a.y, b.x, b.y) <= a.radius + b.radius;
53
- };
49
+ export const intersects = (a: Circle, b: Circle) => distance(a.x, a.y, b.x, b.y) <= a.radius + b.radius;
54
50
 
55
51
  /**
56
52
  * Gets a point on the circumference of the circle at the specified angle.
@@ -60,14 +56,9 @@ export const intersects = (a: Circle, b: Circle) => {
60
56
  * @param {Point} output - Optional point to store the result in.
61
57
  * @returns {Point} The point on the circumference of the circle.
62
58
  */
63
- export const circumferencePoint = (
64
- a: Circle,
65
- angle: number,
66
- asDegrees: boolean = false,
67
- output: Point | null = null
68
- ) => {
69
- const result = output || new Point();
70
- if (asDegrees === true) {
59
+ export const circumferencePoint = (a: Circle, angle: number, asDegrees = false, output: Point | null = null) => {
60
+ const result = output ?? new Point();
61
+ if (asDegrees) {
71
62
  angle = degToRad(angle);
72
63
  }
73
64
  result.x = a.x + a.radius * Math.cos(angle);
@@ -83,9 +74,9 @@ export const circumferencePoint = (
83
74
  * @param {Point} output - Optional point to store the result in.
84
75
  * @returns {Point} The point on the circumference of the circle.
85
76
  */
86
- export const intersectsPoint = (a: Circle, angle: number, asDegrees: boolean = false, output: Point | null = null) => {
87
- const result = output || new Point();
88
- if (asDegrees === true) {
77
+ export const intersectsPoint = (a: Circle, angle: number, asDegrees = false, output: Point | null = null) => {
78
+ const result = output ?? new Point();
79
+ if (asDegrees) {
89
80
  angle = degToRad(angle);
90
81
  }
91
82
  result.x = a.x + a.radius * Math.cos(angle);
@@ -1,9 +1,11 @@
1
- import { expect } from 'vitest';
1
+ import { describe, expect, it } from 'vitest';
2
2
  import { Ellipse } from '../ellipse.js';
3
3
  import { contains } from './ellipse.js';
4
4
 
5
- it('should contain an ellipse the given coordinates', () => {
6
- const ellipse = new Ellipse(0, 0, 10, 10);
7
- expect(contains(ellipse, 5, 5)).toBe(true);
8
- expect(contains(ellipse, 15, 15)).toBe(false);
5
+ describe('ellipse utils', () => {
6
+ it('should contain an ellipse the given coordinates', () => {
7
+ const ellipse = new Ellipse(0, 0, 10, 10);
8
+ expect(contains(ellipse, 5, 5)).toBe(true);
9
+ expect(contains(ellipse, 15, 15)).toBe(false);
10
+ });
9
11
  });
@@ -1,11 +1,12 @@
1
+ import type { Ellipse } from '../ellipse.js';
1
2
  /**
2
3
  * Checks if a point is contained within the ellipse.
3
- * @param {import('../ellipse.js').Ellipse} a - The ellipse to check.
4
+ * @param {Ellipse} a - The ellipse to check.
4
5
  * @param {number} x - The x coordinate of the point.
5
6
  * @param {number} y - The y coordinate of the point.
6
7
  * @returns {boolean} True if the point is contained within the ellipse, false otherwise.
7
8
  */
8
- export const contains = (a: import('../ellipse.js').Ellipse, x: number, y: number) => {
9
+ export const contains = (a: Ellipse, x: number, y: number) => {
9
10
  if (a.width <= 0 || a.height <= 0) {
10
11
  return false;
11
12
  }
@@ -1,12 +1,14 @@
1
- import { expect } from 'vitest';
1
+ import { describe, expect, it } from 'vitest';
2
2
  import { Line } from '../line.js';
3
3
  import { clone } from './line.js';
4
4
 
5
- it('should clone a line', () => {
6
- const line1 = new Line(0, 0, 10, 0);
7
- const line2 = clone(line1);
8
- expect(line1.start.x).toBe(line2.start.x);
9
- expect(line1.start.y).toBe(line2.start.y);
10
- expect(line1.end.x).toBe(line2.end.x);
11
- expect(line1.end.y).toBe(line2.end.y);
5
+ describe('line utils', () => {
6
+ it('should clone a line', () => {
7
+ const line1 = new Line(0, 0, 10, 0);
8
+ const line2 = clone(line1);
9
+ expect(line1.start.x).toBe(line2.start.x);
10
+ expect(line1.start.y).toBe(line2.start.y);
11
+ expect(line1.end.x).toBe(line2.end.x);
12
+ expect(line1.end.y).toBe(line2.end.y);
13
+ });
12
14
  });
@@ -9,7 +9,7 @@ import { intersects as intersectsRect } from './rectangle.js';
9
9
  * @returns {Line} The cloned line.
10
10
  */
11
11
  export const clone = (input: Line, output: Line | null = null) => {
12
- const result = output || new Line();
12
+ const result = output ?? new Line();
13
13
  result.start.x = input.start.x;
14
14
  result.start.y = input.start.y;
15
15
  result.end.x = input.end.x;
@@ -27,15 +27,8 @@ export const clone = (input: Line, output: Line | null = null) => {
27
27
  * @param {Point} output - Optional point to store the result in.
28
28
  * @returns {Point} The intersection point, or null if there is no intersection.
29
29
  */
30
- export const intersectsPoints = (
31
- a: any,
32
- b: any,
33
- e: any,
34
- f: any,
35
- asSegment: boolean = true,
36
- output: Point | null = null
37
- ) => {
38
- const result = output || new Point();
30
+ export const intersectsPoints = (a: any, b: any, e: any, f: any, asSegment = true, output: Point | null = null) => {
31
+ const result = output ?? new Point();
39
32
  const a1 = b.y - a.y;
40
33
  const a2 = f.y - e.y;
41
34
  const b1 = a.x - b.x;
@@ -68,9 +61,8 @@ export const intersectsPoints = (
68
61
  * @param {Point} result - Optional point to store the result in.
69
62
  * @returns {Point} The intersection point, or null if there is no intersection.
70
63
  */
71
- export const intersects = (a: any, b: any, asSegment: boolean, result: Point) => {
72
- return intersectsPoints(a.start, a.end, b.start, b.end, asSegment, result);
73
- };
64
+ export const intersects = (a: any, b: any, asSegment: boolean, result: Point) =>
65
+ intersectsPoints(a.start, a.end, b.start, b.end, asSegment, result);
74
66
 
75
67
  /**
76
68
  * Checks if a line intersects with a rectangle.
@@ -132,6 +124,4 @@ export const intersectsRectangle = (line: any, rect: any) => {
132
124
  * @param {object} b - The second point (with x, y properties).
133
125
  * @returns {number} The distance between the points.
134
126
  */
135
- export const reflect = (a: any, b: any) => {
136
- return 2 * b.normalAngle - 3.141592653589793 - a.angle;
137
- };
127
+ export const reflect = (a: any, b: any) => 2 * b.normalAngle - Math.PI - a.angle;
@@ -1,24 +1,26 @@
1
- import { expect } from 'vitest';
1
+ import { describe, expect, it } from 'vitest';
2
2
  import { Matrix } from '../matrix.js';
3
3
  import { clone, getIdentityMatrix, getTempMatrix } from './matrix.js';
4
4
 
5
- it('should clone a matrix', () => {
6
- const matrix1 = new Matrix(2, 0, 0, 2, 0, 0);
7
- const matrix2 = clone(matrix1);
8
- expect(matrix1.a).toBe(matrix2.a);
9
- expect(matrix1.b).toBe(matrix2.b);
10
- expect(matrix1.c).toBe(matrix2.c);
11
- expect(matrix1.d).toBe(matrix2.d);
12
- expect(matrix1.tx).toBe(matrix2.tx);
13
- expect(matrix1.ty).toBe(matrix2.ty);
14
- });
5
+ describe('matrix utils', () => {
6
+ it('should clone a matrix', () => {
7
+ const matrix1 = new Matrix(2, 0, 0, 2, 0, 0);
8
+ const matrix2 = clone(matrix1);
9
+ expect(matrix1.a).toBe(matrix2.a);
10
+ expect(matrix1.b).toBe(matrix2.b);
11
+ expect(matrix1.c).toBe(matrix2.c);
12
+ expect(matrix1.d).toBe(matrix2.d);
13
+ expect(matrix1.tx).toBe(matrix2.tx);
14
+ expect(matrix1.ty).toBe(matrix2.ty);
15
+ });
15
16
 
16
- it('should create an identity matrix', () => {
17
- const matrix = getIdentityMatrix();
18
- expect(matrix.a).toBe(1);
19
- });
17
+ it('should create an identity matrix', () => {
18
+ const matrix = getIdentityMatrix();
19
+ expect(matrix.a).toBe(1);
20
+ });
20
21
 
21
- it('should create a temporary matrix', () => {
22
- const matrix = getTempMatrix();
23
- expect(matrix.a).toBe(1);
22
+ it('should create a temporary matrix', () => {
23
+ const matrix = getTempMatrix();
24
+ expect(matrix.a).toBe(1);
25
+ });
24
26
  });
@@ -1,4 +1,5 @@
1
1
  import { Matrix } from '../matrix.js';
2
+ import { getRegistry } from '../../core/registry.js';
2
3
 
3
4
  /**
4
5
  * Clones a matrix.
@@ -7,7 +8,7 @@ import { Matrix } from '../matrix.js';
7
8
  * @returns {Matrix} The cloned matrix.
8
9
  */
9
10
  export const clone = (input: Matrix, output: Matrix | null = null) => {
10
- const result = output || new Matrix();
11
+ const result = output ?? new Matrix();
11
12
  result.a = input.a;
12
13
  result.b = input.b;
13
14
  result.c = input.c;
@@ -22,13 +23,9 @@ export const clone = (input: Matrix, output: Matrix | null = null) => {
22
23
  * @returns {Matrix} A new identity matrix.
23
24
  */
24
25
  export const getIdentityMatrix = () => {
25
- if (!window.PhaserRegistry) {
26
- window.PhaserRegistry = {};
27
- }
28
- if (!window.PhaserRegistry.IDENTITY_MATRIX) {
29
- window.PhaserRegistry.IDENTITY_MATRIX = new Matrix();
30
- }
31
- return window.PhaserRegistry.IDENTITY_MATRIX;
26
+ getRegistry();
27
+ globalThis.PhaserRegistry.IDENTITY_MATRIX ??= new Matrix();
28
+ return globalThis.PhaserRegistry.IDENTITY_MATRIX;
32
29
  };
33
30
 
34
31
  /**
@@ -36,11 +33,7 @@ export const getIdentityMatrix = () => {
36
33
  * @returns {Matrix} A new matrix.
37
34
  */
38
35
  export const getTempMatrix = () => {
39
- if (!window.PhaserRegistry) {
40
- window.PhaserRegistry = {};
41
- }
42
- if (!window.PhaserRegistry.TEMP_MATRIX) {
43
- window.PhaserRegistry.TEMP_MATRIX = new Matrix();
44
- }
45
- return window.PhaserRegistry.TEMP_MATRIX;
36
+ getRegistry();
37
+ globalThis.PhaserRegistry.TEMP_MATRIX ??= new Matrix();
38
+ return globalThis.PhaserRegistry.TEMP_MATRIX;
46
39
  };
@@ -1,10 +1,12 @@
1
- import { expect } from 'vitest';
1
+ import { describe, expect, it } from 'vitest';
2
2
  import { Point } from '../point.js';
3
3
  import { clone } from './point.js';
4
4
 
5
- it('should clone a point', () => {
6
- const point1 = new Point(1, 2);
7
- const point2 = clone(point1);
8
- expect(point1.x).toBe(point2.x);
9
- expect(point1.y).toBe(point2.y);
5
+ describe('point utils', () => {
6
+ it('should clone a point', () => {
7
+ const point1 = new Point(1, 2);
8
+ const point2 = clone(point1);
9
+ expect(point1.x).toBe(point2.x);
10
+ expect(point1.y).toBe(point2.y);
11
+ });
10
12
  });
@@ -8,7 +8,7 @@ import { Point } from '../point.js';
8
8
  * @returns {Point} A new point containing the sum of the two points.
9
9
  */
10
10
  export const add = (a: Point, b: Point, output: Point | null = null) => {
11
- const result = output || new Point();
11
+ const result = output ?? new Point();
12
12
  result.x = a.x + b.x;
13
13
  result.y = a.y + b.y;
14
14
  return result;
@@ -22,7 +22,7 @@ export const add = (a: Point, b: Point, output: Point | null = null) => {
22
22
  * @returns {Point} A new point containing the difference of the two points.
23
23
  */
24
24
  export const subtract = (a: Point, b: Point, output: Point | null = null) => {
25
- const result = output || new Point();
25
+ const result = output ?? new Point();
26
26
  result.x = a.x - b.x;
27
27
  result.y = a.y - b.y;
28
28
  return result;
@@ -36,7 +36,7 @@ export const subtract = (a: Point, b: Point, output: Point | null = null) => {
36
36
  * @returns {Point} A new point containing the product of the two points.
37
37
  */
38
38
  export const multiply = (a: Point, b: Point, output: Point | null = null) => {
39
- const result = output || new Point();
39
+ const result = output ?? new Point();
40
40
  result.x = a.x * b.x;
41
41
  result.y = a.y * b.y;
42
42
  return result;
@@ -50,7 +50,7 @@ export const multiply = (a: Point, b: Point, output: Point | null = null) => {
50
50
  * @returns {Point} A new point containing the quotient of the two points.
51
51
  */
52
52
  export const divide = (a: Point, b: Point, output: Point | null = null) => {
53
- const result = output || new Point();
53
+ const result = output ?? new Point();
54
54
  result.x = a.x / b.x;
55
55
  result.y = a.y / b.y;
56
56
  return result;
@@ -62,9 +62,7 @@ export const divide = (a: Point, b: Point, output: Point | null = null) => {
62
62
  * @param {Point} b - The second point to compare.
63
63
  * @returns {boolean} True if the points are equal, false otherwise.
64
64
  */
65
- export const equals = (a: Point, b: Point) => {
66
- return a.x === b.x && a.y === b.y;
67
- };
65
+ export const equals = (a: Point, b: Point) => a.x === b.x && a.y === b.y;
68
66
 
69
67
  /**
70
68
  * Calculates the angle between two points.
@@ -72,9 +70,7 @@ export const equals = (a: Point, b: Point) => {
72
70
  * @param {Point} b - The second point to calculate the angle to.
73
71
  * @returns {number} The angle between the two points in radians.
74
72
  */
75
- export const angle = (a: Point, b: Point) => {
76
- return Math.atan2(a.y - b.y, a.x - b.x);
77
- };
73
+ export const angle = (a: Point, b: Point) => Math.atan2(a.y - b.y, a.x - b.x);
78
74
 
79
75
  /**
80
76
  * Creates a new point with the same coordinates as the input point but with inverted signs.
@@ -83,7 +79,7 @@ export const angle = (a: Point, b: Point) => {
83
79
  * @returns {Point} A new point with negated coordinates.
84
80
  */
85
81
  export const negative = (a: Point, output: Point | null = null) => {
86
- const result = output || new Point();
82
+ const result = output ?? new Point();
87
83
  return result.setTo(-a.x, -a.y);
88
84
  };
89
85
 
@@ -96,7 +92,7 @@ export const negative = (a: Point, output: Point | null = null) => {
96
92
  * @returns {Point} A new point with the result of the operation.
97
93
  */
98
94
  export const multiplyAdd = (a: Point, b: Point, s: number, output: Point | null = null) => {
99
- const result = output || new Point();
95
+ const result = output ?? new Point();
100
96
  return result.setTo(a.x + b.x * s, a.y + b.y * s);
101
97
  };
102
98
 
@@ -109,7 +105,7 @@ export const multiplyAdd = (a: Point, b: Point, s: number, output: Point | null
109
105
  * @returns {Point} A new point interpolated between the two points.
110
106
  */
111
107
  export const interpolate = (a: Point, b: Point, f: number, output: Point | null = null) => {
112
- const result = output || new Point();
108
+ const result = output ?? new Point();
113
109
  return result.setTo(a.x + (b.x - a.x) * f, a.y + (b.y - a.y) * f);
114
110
  };
115
111
 
@@ -120,7 +116,7 @@ export const interpolate = (a: Point, b: Point, f: number, output: Point | null
120
116
  * @returns {Point} A new point that is perpendicular to the input point.
121
117
  */
122
118
  export const perp = (a: Point, output: Point | null = null) => {
123
- const result = output || new Point();
119
+ const result = output ?? new Point();
124
120
  return result.setTo(-a.y, a.x);
125
121
  };
126
122
 
@@ -131,7 +127,7 @@ export const perp = (a: Point, output: Point | null = null) => {
131
127
  * @returns {Point} A new point that is perpendicular to the input point (rotated clockwise).
132
128
  */
133
129
  export const rperp = (a: Point, output: Point | null = null) => {
134
- const result = output || new Point();
130
+ const result = output ?? new Point();
135
131
  return result.setTo(a.y, -a.x);
136
132
  };
137
133
 
@@ -142,7 +138,7 @@ export const rperp = (a: Point, output: Point | null = null) => {
142
138
  * @param {boolean} round - Whether to round the result (default: false).
143
139
  * @returns {number} The distance between the two points.
144
140
  */
145
- export const distance = (a: Point, b: Point, round: boolean = false) => {
141
+ export const distance = (a: Point, b: Point, round = false) => {
146
142
  const dx = a.x - b.x;
147
143
  const dy = a.y - b.y;
148
144
  const abDistance = Math.sqrt(dx * dx + dy * dy);
@@ -157,7 +153,7 @@ export const distance = (a: Point, b: Point, round: boolean = false) => {
157
153
  * @returns {Point} A new point with the projected result.
158
154
  */
159
155
  export const project = (a: Point, b: Point, output: Point | null = null) => {
160
- const result = output || new Point();
156
+ const result = output ?? new Point();
161
157
  const amt = a.dot(b) / b.getMagnitudeSq();
162
158
  if (amt !== 0) {
163
159
  result.setTo(amt * b.x, amt * b.y);
@@ -173,7 +169,7 @@ export const project = (a: Point, b: Point, output: Point | null = null) => {
173
169
  * @returns {Point} A new point with the projected result.
174
170
  */
175
171
  export const projectUnit = (a: Point, b: Point, output: Point | null = null) => {
176
- const result = output || new Point();
172
+ const result = output ?? new Point();
177
173
  const amt = a.dot(b);
178
174
  if (amt !== 0) {
179
175
  result.setTo(amt * b.x, amt * b.y);
@@ -188,7 +184,7 @@ export const projectUnit = (a: Point, b: Point, output: Point | null = null) =>
188
184
  * @returns {Point} A new point with the same x coordinate but negated y coordinate.
189
185
  */
190
186
  export const normalRightHand = (a: Point, output: Point | null = null) => {
191
- const result = output || new Point();
187
+ const result = output ?? new Point();
192
188
  return result.setTo(a.y * -1, a.x);
193
189
  };
194
190
 
@@ -199,7 +195,7 @@ export const normalRightHand = (a: Point, output: Point | null = null) => {
199
195
  * @returns {Point} A new normalized point.
200
196
  */
201
197
  export const normalize = (a: Point, output: Point | null = null) => {
202
- const result = output || new Point();
198
+ const result = output ?? new Point();
203
199
  const m = a.getMagnitude();
204
200
  if (m !== 0) {
205
201
  result.setTo(a.x / m, a.y / m);
@@ -252,17 +248,17 @@ export const rotate = (
252
248
  * @throws {Error} If the points array is empty.
253
249
  */
254
250
  export const centroid = (points: Point[], output: Point | null = null) => {
255
- const result = output || new Point();
251
+ const result = output ?? new Point();
256
252
  const pointsLen = points.length;
257
253
  if (pointsLen < 1) {
258
254
  throw new Error('Point(points) array must not be empty');
259
255
  }
260
256
  if (pointsLen === 1) {
261
- result.copyFrom(points[0]);
257
+ result.copyFrom(points[0]!);
262
258
  return result;
263
259
  }
264
- for (let i = 0; i < pointsLen; i += 1) {
265
- add(result, points[i], result);
260
+ for (const point of points) {
261
+ add(result, point, result);
266
262
  }
267
263
  result.divide(pointsLen, pointsLen);
268
264
  return result;
@@ -275,13 +271,13 @@ export const centroid = (points: Point[], output: Point | null = null) => {
275
271
  * @param {string} yProp - The name of the property containing the y value (default: 'y').
276
272
  * @returns {Point} A new point with parsed x and y values.
277
273
  */
278
- export const parse = (obj: any, xProp: string = 'x', yProp: string = 'y') => {
274
+ export const parse = (obj: any, xProp = 'x', yProp = 'y') => {
279
275
  const point = new Point();
280
276
  if (obj[xProp]) {
281
- point.x = Number.parseInt(obj[xProp], 10);
277
+ point.x = Math.trunc(Number(obj[xProp]));
282
278
  }
283
279
  if (obj[yProp]) {
284
- point.y = Number.parseInt(obj[yProp], 10);
280
+ point.y = Math.trunc(Number(obj[yProp]));
285
281
  }
286
282
  return point;
287
283
  };
@@ -293,7 +289,7 @@ export const parse = (obj: any, xProp: string = 'x', yProp: string = 'y') => {
293
289
  * @returns {Point} A new point with the same coordinates as the input.
294
290
  */
295
291
  export const clone = (input: Point, output: Point | null = null) => {
296
- const result = output || new Point();
292
+ const result = output ?? new Point();
297
293
  result.setTo(input.x, input.y);
298
294
  return result;
299
295
  };
@@ -1,14 +1,16 @@
1
- import { expect } from 'vitest';
1
+ import { describe, expect, it } from 'vitest';
2
2
  import { Polygon } from '../polygon.js';
3
3
  import { clone } from './polygon.js';
4
4
 
5
- it('should clone a polygon', () => {
6
- const polygon = new Polygon([0, 0, 1, 0, 1, 1]);
7
- const points = clone(polygon).toNumberArray();
8
- expect(points[0]).toBe(0);
9
- expect(points[1]).toBe(0);
10
- expect(points[2]).toBe(1);
11
- expect(points[3]).toBe(0);
12
- expect(points[4]).toBe(1);
13
- expect(points[5]).toBe(1);
5
+ describe('polygon utils', () => {
6
+ it('should clone a polygon', () => {
7
+ const polygon = new Polygon([0, 0, 1, 0, 1, 1]);
8
+ const points = clone(polygon).toNumberArray();
9
+ expect(points[0]).toBe(0);
10
+ expect(points[1]).toBe(0);
11
+ expect(points[2]).toBe(1);
12
+ expect(points[3]).toBe(0);
13
+ expect(points[4]).toBe(1);
14
+ expect(points[5]).toBe(1);
15
+ });
14
16
  });
@@ -7,7 +7,7 @@ import { Polygon } from '../polygon.js';
7
7
  * @returns {Polygon} The cloned polygon.
8
8
  */
9
9
  export const clone = (input: Polygon, output: Polygon | null = null) => {
10
- const result = output || new Polygon();
11
- result.setTo(input._points.slice());
10
+ const result = output ?? new Polygon();
11
+ result.setTo([...input._points]);
12
12
  return result;
13
13
  };
@@ -1,12 +1,14 @@
1
- import { expect } from 'vitest';
1
+ import { describe, expect, it } from 'vitest';
2
2
  import { Rectangle } from '../rectangle.js';
3
3
  import { clone } from './rectangle.js';
4
4
 
5
- it('should clone a rectangle', () => {
6
- const rectangle1 = new Rectangle(0, 0, 10, 10);
7
- const rectangle2 = clone(rectangle1);
8
- expect(rectangle1.x).toBe(rectangle2.x);
9
- expect(rectangle1.y).toBe(rectangle2.y);
10
- expect(rectangle1.width).toBe(rectangle2.width);
11
- expect(rectangle1.height).toBe(rectangle2.height);
5
+ describe('rectangle utils', () => {
6
+ it('should clone a rectangle', () => {
7
+ const rectangle1 = new Rectangle(0, 0, 10, 10);
8
+ const rectangle2 = clone(rectangle1);
9
+ expect(rectangle1.x).toBe(rectangle2.x);
10
+ expect(rectangle1.y).toBe(rectangle2.y);
11
+ expect(rectangle1.width).toBe(rectangle2.width);
12
+ expect(rectangle1.height).toBe(rectangle2.height);
13
+ });
12
14
  });