@vpmedia/phaser 1.122.0 → 1.124.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 (207) hide show
  1. package/dist/index.js +341 -325
  2. package/dist/index.js.map +1 -1
  3. package/dist/phaser/core/animation.d.ts +3 -3
  4. package/dist/phaser/core/animation.d.ts.map +1 -1
  5. package/dist/phaser/core/animation_manager.d.ts.map +1 -1
  6. package/dist/phaser/core/animation_parser.d.ts +27 -2
  7. package/dist/phaser/core/animation_parser.d.ts.map +1 -1
  8. package/dist/phaser/core/array_set.d.ts +11 -11
  9. package/dist/phaser/core/array_set.d.ts.map +1 -1
  10. package/dist/phaser/core/cache.d.ts.map +1 -1
  11. package/dist/phaser/core/callback.d.ts.map +1 -1
  12. package/dist/phaser/core/dom.d.ts +125 -19
  13. package/dist/phaser/core/dom.d.ts.map +1 -1
  14. package/dist/phaser/core/factory.d.ts +3 -2
  15. package/dist/phaser/core/factory.d.ts.map +1 -1
  16. package/dist/phaser/core/input.d.ts +3 -2
  17. package/dist/phaser/core/input.d.ts.map +1 -1
  18. package/dist/phaser/core/input_handler.d.ts.map +1 -1
  19. package/dist/phaser/core/input_mouse.d.ts +5 -1
  20. package/dist/phaser/core/input_mouse.d.ts.map +1 -1
  21. package/dist/phaser/core/input_pointer.d.ts +3 -3
  22. package/dist/phaser/core/input_pointer.d.ts.map +1 -1
  23. package/dist/phaser/core/input_touch.d.ts +8 -8
  24. package/dist/phaser/core/input_touch.d.ts.map +1 -1
  25. package/dist/phaser/core/loader.d.ts +11 -2
  26. package/dist/phaser/core/loader.d.ts.map +1 -1
  27. package/dist/phaser/core/loader_parser.d.ts +14 -1
  28. package/dist/phaser/core/loader_parser.d.ts.map +1 -1
  29. package/dist/phaser/core/raf.d.ts +1 -1
  30. package/dist/phaser/core/raf.d.ts.map +1 -1
  31. package/dist/phaser/core/scale_manager.d.ts.map +1 -1
  32. package/dist/phaser/core/scene_manager.d.ts.map +1 -1
  33. package/dist/phaser/core/signal.d.ts.map +1 -1
  34. package/dist/phaser/core/sound.d.ts.map +1 -1
  35. package/dist/phaser/core/sound_manager.d.ts +1 -1
  36. package/dist/phaser/core/sound_manager.d.ts.map +1 -1
  37. package/dist/phaser/core/stage.d.ts +16 -6
  38. package/dist/phaser/core/stage.d.ts.map +1 -1
  39. package/dist/phaser/core/time.d.ts.map +1 -1
  40. package/dist/phaser/core/timer.d.ts +1 -1
  41. package/dist/phaser/core/timer.d.ts.map +1 -1
  42. package/dist/phaser/core/tween.d.ts +13 -5
  43. package/dist/phaser/core/tween.d.ts.map +1 -1
  44. package/dist/phaser/core/tween_data.d.ts +9 -7
  45. package/dist/phaser/core/tween_data.d.ts.map +1 -1
  46. package/dist/phaser/core/tween_manager.d.ts.map +1 -1
  47. package/dist/phaser/display/button.d.ts +6 -5
  48. package/dist/phaser/display/button.d.ts.map +1 -1
  49. package/dist/phaser/display/canvas/buffer.d.ts +1 -1
  50. package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
  51. package/dist/phaser/display/canvas/masker.d.ts +1 -1
  52. package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
  53. package/dist/phaser/display/canvas/pool.d.ts +2 -2
  54. package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
  55. package/dist/phaser/display/canvas/renderer.d.ts +9 -8
  56. package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
  57. package/dist/phaser/display/display_object.d.ts +3 -1
  58. package/dist/phaser/display/display_object.d.ts.map +1 -1
  59. package/dist/phaser/display/graphics.d.ts +1 -1
  60. package/dist/phaser/display/graphics.d.ts.map +1 -1
  61. package/dist/phaser/display/group.d.ts +1 -1
  62. package/dist/phaser/display/group.d.ts.map +1 -1
  63. package/dist/phaser/display/image.d.ts +6 -5
  64. package/dist/phaser/display/image.d.ts.map +1 -1
  65. package/dist/phaser/display/sprite_util.d.ts +3 -2
  66. package/dist/phaser/display/sprite_util.d.ts.map +1 -1
  67. package/dist/phaser/display/text.d.ts +2 -16
  68. package/dist/phaser/display/text.d.ts.map +1 -1
  69. package/dist/phaser/display/webgl/abstract_filter.d.ts +14 -8
  70. package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
  71. package/dist/phaser/display/webgl/blend_manager.d.ts +2 -3
  72. package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
  73. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +11 -5
  74. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
  75. package/dist/phaser/display/webgl/filter_manager.d.ts +6 -4
  76. package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
  77. package/dist/phaser/display/webgl/filter_texture.d.ts +4 -4
  78. package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
  79. package/dist/phaser/display/webgl/graphics.d.ts +2 -2
  80. package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
  81. package/dist/phaser/display/webgl/mask_manager.d.ts +3 -2
  82. package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
  83. package/dist/phaser/display/webgl/render_texture.d.ts +11 -8
  84. package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
  85. package/dist/phaser/display/webgl/renderer.d.ts +8 -4
  86. package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
  87. package/dist/phaser/display/webgl/shader/normal.d.ts +28 -3
  88. package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  89. package/dist/phaser/display/webgl/sprite_batch.d.ts +6 -5
  90. package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
  91. package/dist/phaser/display/webgl/stencil_manager.d.ts +3 -3
  92. package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
  93. package/dist/phaser/display/webgl/texture_util.d.ts +2 -2
  94. package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
  95. package/dist/phaser/display/webgl/util.d.ts +1 -1
  96. package/dist/phaser/display/webgl/util.d.ts.map +1 -1
  97. package/dist/phaser/geom/circle.d.ts.map +1 -1
  98. package/dist/phaser/geom/line.d.ts +10 -1
  99. package/dist/phaser/geom/line.d.ts.map +1 -1
  100. package/dist/phaser/geom/rectangle.d.ts.map +1 -1
  101. package/dist/phaser/geom/util/circle.d.ts +2 -1
  102. package/dist/phaser/geom/util/circle.d.ts.map +1 -1
  103. package/dist/phaser/geom/util/point.d.ts +1 -1
  104. package/dist/phaser/geom/util/point.d.ts.map +1 -1
  105. package/dist/phaser/geom/util/rectangle.d.ts +1 -1
  106. package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
  107. package/dist/phaser/util/math.d.ts.map +1 -1
  108. package/package.json +1 -1
  109. package/src/phaser/core/animation.ts +4 -4
  110. package/src/phaser/core/animation_manager.ts +10 -10
  111. package/src/phaser/core/animation_parser.ts +30 -24
  112. package/src/phaser/core/array_set.ts +27 -27
  113. package/src/phaser/core/cache.test.ts +33 -33
  114. package/src/phaser/core/cache.ts +3 -3
  115. package/src/phaser/core/callback.ts +1 -0
  116. package/src/phaser/core/callback_context.test.ts +8 -8
  117. package/src/phaser/core/dom.ts +15 -5
  118. package/src/phaser/core/factory.ts +9 -2
  119. package/src/phaser/core/frame_data.test.ts +23 -23
  120. package/src/phaser/core/input.ts +9 -8
  121. package/src/phaser/core/input_handler.test.ts +18 -18
  122. package/src/phaser/core/input_handler.ts +1 -1
  123. package/src/phaser/core/input_mouse.ts +9 -8
  124. package/src/phaser/core/input_pointer.test.ts +26 -26
  125. package/src/phaser/core/input_pointer.ts +3 -3
  126. package/src/phaser/core/input_touch.ts +8 -8
  127. package/src/phaser/core/loader.test.ts +26 -26
  128. package/src/phaser/core/loader.ts +25 -25
  129. package/src/phaser/core/loader_parser.test.ts +16 -16
  130. package/src/phaser/core/loader_parser.ts +16 -6
  131. package/src/phaser/core/raf.ts +1 -1
  132. package/src/phaser/core/registry.test.ts +6 -6
  133. package/src/phaser/core/scale_manager.ts +2 -2
  134. package/src/phaser/core/scene_manager.test.ts +30 -30
  135. package/src/phaser/core/scene_manager.ts +1 -1
  136. package/src/phaser/core/signal.test.ts +8 -8
  137. package/src/phaser/core/signal.ts +1 -1
  138. package/src/phaser/core/signal_dispatch.test.ts +30 -30
  139. package/src/phaser/core/sound.ts +20 -8
  140. package/src/phaser/core/sound_manager.ts +6 -6
  141. package/src/phaser/core/stage.ts +19 -9
  142. package/src/phaser/core/time.ts +1 -1
  143. package/src/phaser/core/timer.test.ts +47 -47
  144. package/src/phaser/core/timer.ts +1 -1
  145. package/src/phaser/core/tween.ts +28 -25
  146. package/src/phaser/core/tween_data.test.ts +119 -0
  147. package/src/phaser/core/tween_data.ts +54 -39
  148. package/src/phaser/core/tween_easing.test.ts +5 -5
  149. package/src/phaser/core/tween_manager.ts +2 -2
  150. package/src/phaser/display/bitmap_text.test.ts +30 -30
  151. package/src/phaser/display/button.ts +8 -6
  152. package/src/phaser/display/canvas/buffer.ts +2 -2
  153. package/src/phaser/display/canvas/masker.ts +1 -1
  154. package/src/phaser/display/canvas/pool.test.ts +20 -20
  155. package/src/phaser/display/canvas/pool.ts +3 -3
  156. package/src/phaser/display/canvas/renderer.ts +12 -11
  157. package/src/phaser/display/canvas/util.test.ts +31 -24
  158. package/src/phaser/display/canvas/util.ts +2 -2
  159. package/src/phaser/display/display_object.ts +3 -1
  160. package/src/phaser/display/graphics.test.ts +70 -20
  161. package/src/phaser/display/graphics.ts +38 -32
  162. package/src/phaser/display/group.ts +4 -4
  163. package/src/phaser/display/image.ts +28 -25
  164. package/src/phaser/display/sprite_util.ts +3 -2
  165. package/src/phaser/display/text.test.ts +28 -25
  166. package/src/phaser/display/text.ts +21 -18
  167. package/src/phaser/display/webgl/abstract_filter.ts +20 -10
  168. package/src/phaser/display/webgl/blend_manager.ts +4 -5
  169. package/src/phaser/display/webgl/earcut.test.ts +20 -20
  170. package/src/phaser/display/webgl/fast_sprite_batch.ts +21 -16
  171. package/src/phaser/display/webgl/filter_manager.ts +7 -4
  172. package/src/phaser/display/webgl/filter_texture.ts +5 -5
  173. package/src/phaser/display/webgl/graphics.ts +2 -2
  174. package/src/phaser/display/webgl/mask_manager.ts +9 -14
  175. package/src/phaser/display/webgl/render_texture.ts +15 -14
  176. package/src/phaser/display/webgl/renderer.ts +7 -6
  177. package/src/phaser/display/webgl/shader/normal.ts +41 -31
  178. package/src/phaser/display/webgl/shader/shader.test.ts +24 -24
  179. package/src/phaser/display/webgl/shader_manager.test.ts +18 -18
  180. package/src/phaser/display/webgl/sprite_batch.ts +8 -8
  181. package/src/phaser/display/webgl/stencil_manager.ts +4 -4
  182. package/src/phaser/display/webgl/texture_util.ts +2 -2
  183. package/src/phaser/display/webgl/util.ts +1 -1
  184. package/src/phaser/geom/circle.test.ts +38 -38
  185. package/src/phaser/geom/circle.ts +7 -7
  186. package/src/phaser/geom/ellipse.test.ts +12 -12
  187. package/src/phaser/geom/line.test.ts +15 -15
  188. package/src/phaser/geom/line.ts +5 -2
  189. package/src/phaser/geom/matrix.test.ts +31 -31
  190. package/src/phaser/geom/point.test.ts +31 -31
  191. package/src/phaser/geom/polygon.test.ts +27 -27
  192. package/src/phaser/geom/rectangle.test.ts +87 -87
  193. package/src/phaser/geom/rectangle.ts +11 -11
  194. package/src/phaser/geom/rounded_rectangle.test.ts +9 -9
  195. package/src/phaser/geom/util/circle.test.ts +5 -5
  196. package/src/phaser/geom/util/circle.ts +2 -1
  197. package/src/phaser/geom/util/ellipse.test.ts +2 -2
  198. package/src/phaser/geom/util/line.test.ts +2 -2
  199. package/src/phaser/geom/util/matrix.test.ts +4 -4
  200. package/src/phaser/geom/util/point.test.ts +2 -2
  201. package/src/phaser/geom/util/point.ts +1 -1
  202. package/src/phaser/geom/util/polygon.test.ts +2 -2
  203. package/src/phaser/geom/util/rectangle.test.ts +2 -2
  204. package/src/phaser/geom/util/rectangle.ts +1 -1
  205. package/src/phaser/geom/util/rounded_rectangle.test.ts +2 -2
  206. package/src/phaser/util/math.test.ts +41 -41
  207. package/src/phaser/util/math.ts +5 -2
@@ -1,8 +1,8 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
  import { Ellipse } from './ellipse.js';
3
3
 
4
- describe('Ellipse', () => {
5
- it('should create an ellipse with default values', () => {
4
+ describe('Ellipse', (): void => {
5
+ it('should create an ellipse with default values', (): void => {
6
6
  const ellipse = new Ellipse();
7
7
  expect(ellipse.x).toBe(0);
8
8
  expect(ellipse.y).toBe(0);
@@ -10,7 +10,7 @@ describe('Ellipse', () => {
10
10
  expect(ellipse.height).toBe(0);
11
11
  });
12
12
 
13
- it('should create an ellipse with custom x, y, width, height', () => {
13
+ it('should create an ellipse with custom x, y, width, height', (): void => {
14
14
  const ellipse = new Ellipse(10, 20, 30, 40);
15
15
  expect(ellipse.x).toBe(10);
16
16
  expect(ellipse.y).toBe(20);
@@ -18,7 +18,7 @@ describe('Ellipse', () => {
18
18
  expect(ellipse.height).toBe(40);
19
19
  });
20
20
 
21
- it('should set the ellipse values to new x, y, width, height', () => {
21
+ it('should set the ellipse values to new x, y, width, height', (): void => {
22
22
  const ellipse = new Ellipse();
23
23
  ellipse.setTo(10, 20, 30, 40);
24
24
  expect(ellipse.x).toBe(10);
@@ -27,13 +27,13 @@ describe('Ellipse', () => {
27
27
  expect(ellipse.height).toBe(40);
28
28
  });
29
29
 
30
- it('should return the ellipse instance', () => {
30
+ it('should return the ellipse instance', (): void => {
31
31
  const ellipse = new Ellipse();
32
32
  const result = ellipse.setTo(10, 20, 30, 40);
33
33
  expect(result).toBe(ellipse);
34
34
  });
35
35
 
36
- it('should create a rectangle with correct bounds', () => {
36
+ it('should create a rectangle with correct bounds', (): void => {
37
37
  const ellipse = new Ellipse(10, 20, 30, 40);
38
38
  const bounds = ellipse.getBounds();
39
39
  expect(bounds.x).toBe(10 - 30);
@@ -42,7 +42,7 @@ describe('Ellipse', () => {
42
42
  expect(bounds.height).toBe(40);
43
43
  });
44
44
 
45
- it('should copy the values from another ellipse', () => {
45
+ it('should copy the values from another ellipse', (): void => {
46
46
  const source = new Ellipse(10, 20, 30, 40);
47
47
  const target = new Ellipse();
48
48
  target.copyFrom(source);
@@ -52,7 +52,7 @@ describe('Ellipse', () => {
52
52
  expect(target.height).toBe(source.height);
53
53
  });
54
54
 
55
- it('should copy the values to another ellipse', () => {
55
+ it('should copy the values to another ellipse', (): void => {
56
56
  const source = new Ellipse(10, 20, 30, 40);
57
57
  const target = new Ellipse();
58
58
  source.copyTo(target);
@@ -62,24 +62,24 @@ describe('Ellipse', () => {
62
62
  expect(target.height).toBe(source.height);
63
63
  });
64
64
 
65
- it('should return true if point is inside the ellipse', () => {
65
+ it('should return true if point is inside the ellipse', (): void => {
66
66
  const ellipse = new Ellipse(10, 20, 30, 40);
67
67
  expect(ellipse.contains(20, 30)).toBe(true);
68
68
  });
69
69
 
70
- it('should return false if point is outside the ellipse', () => {
70
+ it('should return false if point is outside the ellipse', (): void => {
71
71
  const ellipse = new Ellipse(10, 20, 30, 40);
72
72
  expect(ellipse.contains(-5, -10)).toBe(false);
73
73
  });
74
74
 
75
- it('should generate a random point within the ellipse', () => {
75
+ it('should generate a random point within the ellipse', (): void => {
76
76
  const ellipse = new Ellipse(10, 20, 30, 40);
77
77
  const point = ellipse.random();
78
78
  expect(point.x).toBeTypeOf('number');
79
79
  expect(point.y).toBeTypeOf('number');
80
80
  });
81
81
 
82
- it('should return a string representation of the ellipse', () => {
82
+ it('should return a string representation of the ellipse', (): void => {
83
83
  const ellipse = new Ellipse(10, 20, 30, 40);
84
84
  expect(ellipse.toString()).toBe('[{Ellipse (x=10 y=20 width=30 height=40)}]');
85
85
  });
@@ -2,8 +2,8 @@ import { expect, describe, it } from 'vitest';
2
2
  import { degToRad } from '../util/math.js';
3
3
  import { Line } from './line.js';
4
4
 
5
- describe('Line', () => {
6
- it('should create a new line instance with correct coordinates', () => {
5
+ describe('Line', (): void => {
6
+ it('should create a new line instance with correct coordinates', (): void => {
7
7
  const line = new Line(0, 0, 10, 10);
8
8
  expect(line.start.x).toBe(0);
9
9
  expect(line.start.y).toBe(0);
@@ -11,7 +11,7 @@ describe('Line', () => {
11
11
  expect(line.end.y).toBe(10);
12
12
  });
13
13
 
14
- it('should set the start and end points of the line correctly', () => {
14
+ it('should set the start and end points of the line correctly', (): void => {
15
15
  const line = new Line(0, 0, 10, 10);
16
16
  line.setTo(5, 5, 15, 15);
17
17
  expect(line.start.x).toBe(5);
@@ -20,7 +20,7 @@ describe('Line', () => {
20
20
  expect(line.end.y).toBe(15);
21
21
  });
22
22
 
23
- it('should create a new line instance from two sprites correctly', () => {
23
+ it('should create a new line instance from two sprites correctly', (): void => {
24
24
  const line = new Line(0, 0, 10, 10);
25
25
  const sprite1 = { x: 0, y: 0 };
26
26
  const sprite2 = { x: 10, y: 10 };
@@ -31,7 +31,7 @@ describe('Line', () => {
31
31
  expect(result.end.y).toBe(10);
32
32
  });
33
33
 
34
- it('should create a new line instance from an angle and length correctly', () => {
34
+ it('should create a new line instance from an angle and length correctly', (): void => {
35
35
  const line = new Line(0, 10, 10, 10);
36
36
  const result = line.fromAngle(0, 0, degToRad(45), 10);
37
37
  expect(result.start.x).toBe(0);
@@ -40,7 +40,7 @@ describe('Line', () => {
40
40
  expect(result.end.y).toBeCloseTo(7.07);
41
41
  });
42
42
 
43
- it('should rotate the line correctly', () => {
43
+ it('should rotate the line correctly', (): void => {
44
44
  const line = new Line(0, 0, 10, 0);
45
45
  const result = line.rotate(90, true);
46
46
  expect(result.start.x).toBe(5);
@@ -49,7 +49,7 @@ describe('Line', () => {
49
49
  expect(result.end.y).toBe(5);
50
50
  });
51
51
 
52
- it('should rotate the line around a point correctly', () => {
52
+ it('should rotate the line around a point correctly', (): void => {
53
53
  const line = new Line(0, 0, 10, 10);
54
54
  const result = line.rotateAround(5, 5, 90, true);
55
55
  expect(result.start.x).toBe(10);
@@ -58,54 +58,54 @@ describe('Line', () => {
58
58
  expect(result.end.y).toBe(10);
59
59
  });
60
60
 
61
- it('should intersect the line with another line correctly', () => {
61
+ it('should intersect the line with another line correctly', (): void => {
62
62
  const line = new Line(0, 0, 10, 10);
63
63
  const line2 = new Line(5, 5, 15, 15);
64
64
  const result = line.intersects(line2, true, null);
65
65
  expect(result).toBeNull();
66
66
  });
67
67
 
68
- it('should reflect the line across another line correctly', () => {
68
+ it('should reflect the line across another line correctly', (): void => {
69
69
  const line = new Line(0, 0, 10, 10);
70
70
  const line2 = new Line(5, 5, 15, 15);
71
71
  const result = line.reflect(line2);
72
72
  expect(result).toBeCloseTo(-5.497);
73
73
  });
74
74
 
75
- it('should get the midpoint of the line correctly', () => {
75
+ it('should get the midpoint of the line correctly', (): void => {
76
76
  const line = new Line(0, 0, 10, 10);
77
77
  const result = line.midPoint(null);
78
78
  expect(result.x).toBe(5);
79
79
  expect(result.y).toBe(5);
80
80
  });
81
81
 
82
- it('should center the line on a point correctly', () => {
82
+ it('should center the line on a point correctly', (): void => {
83
83
  const line = new Line(0, 0, 10, 10);
84
84
  line.centerOn(10, 10);
85
85
  expect(line.start.x).toBe(10 - (line.end.x - line.start.x) / 2);
86
86
  expect(line.start.y).toBe(10 - (line.end.y - line.start.y) / 2);
87
87
  });
88
88
 
89
- it('should check if a point is on the line correctly', () => {
89
+ it('should check if a point is on the line correctly', (): void => {
90
90
  const line = new Line(0, 0, 10, 10);
91
91
  expect(line.pointOnLine(5, 0)).toBe(false);
92
92
  expect(line.pointOnLine(-5, 0)).toBe(false);
93
93
  });
94
94
 
95
- it('should check if a point is on the segment of the line correctly', () => {
95
+ it('should check if a point is on the segment of the line correctly', (): void => {
96
96
  const line = new Line(0, 0, 10, 10);
97
97
  expect(line.pointOnSegment(5, -10)).toBe(false);
98
98
  expect(line.pointOnSegment(15, 15)).toBe(false);
99
99
  });
100
100
 
101
- it('should get the random point on the line correctly', () => {
101
+ it('should get the random point on the line correctly', (): void => {
102
102
  const line = new Line(0, 0, 10, 10);
103
103
  const result = line.random(null);
104
104
  expect(result.x).toBeGreaterThan(0);
105
105
  expect(result.y).toBeGreaterThan(0);
106
106
  });
107
107
 
108
- it('should get the coordinates on the line correctly', () => {
108
+ it('should get the coordinates on the line correctly', (): void => {
109
109
  const line = new Line(0, 0, 10, 10);
110
110
  const result = line.coordinatesOnLine(1, []);
111
111
  expect(result.length).toBeGreaterThan(0);
@@ -3,6 +3,9 @@ import { clone, intersectsPoints, reflect } from './util/line.js';
3
3
  import { wrap } from '../util/math.js';
4
4
  import { GEOM_LINE } from '../core/const.js';
5
5
 
6
+ /** Anything a line can read a position from: a display object, a point, or a plain x/y pair. */
7
+ export type LineAnchor = { x: number; y: number; center?: { x: number; y: number } };
8
+
6
9
  export class Line {
7
10
  public start: Point;
8
11
  public end: Point;
@@ -45,9 +48,9 @@ export class Line {
45
48
  * @param {boolean} useCenter - Whether to use the center of the sprites (default: false).
46
49
  * @returns {Line} This line instance for chaining.
47
50
  */
48
- public fromSprite(startSprite: any, endSprite: any, useCenter = false): this {
51
+ public fromSprite(startSprite: LineAnchor, endSprite: LineAnchor, useCenter = false): this {
49
52
  if (useCenter) {
50
- return this.setTo(startSprite.center.x, startSprite.center.y, endSprite.center.x, endSprite.center.y);
53
+ return this.setTo(startSprite.center!.x, startSprite.center!.y, endSprite.center!.x, endSprite.center!.y);
51
54
  }
52
55
  return this.setTo(startSprite.x, startSprite.y, endSprite.x, endSprite.y);
53
56
  }
@@ -2,8 +2,8 @@ import { expect, describe, it } from 'vitest';
2
2
  import { Matrix } from './matrix.js';
3
3
  import { Point } from './point.js';
4
4
 
5
- describe('Constructor', () => {
6
- it('should set default values when no arguments are passed', () => {
5
+ describe('Constructor', (): void => {
6
+ it('should set default values when no arguments are passed', (): void => {
7
7
  const matrix = new Matrix();
8
8
  expect(matrix.a).toBe(1);
9
9
  expect(matrix.b).toBe(0);
@@ -13,7 +13,7 @@ describe('Constructor', () => {
13
13
  expect(matrix.ty).toBe(0);
14
14
  });
15
15
 
16
- it('should set values when arguments are passed', () => {
16
+ it('should set values when arguments are passed', (): void => {
17
17
  const matrix = new Matrix(2, 3, 4, 5, 6, 7);
18
18
  expect(matrix.a).toBe(2);
19
19
  expect(matrix.b).toBe(3);
@@ -24,8 +24,8 @@ describe('Constructor', () => {
24
24
  });
25
25
  });
26
26
 
27
- describe('fromArray', () => {
28
- it('should set values from an array', () => {
27
+ describe('fromArray', (): void => {
28
+ it('should set values from an array', (): void => {
29
29
  const matrix = new Matrix();
30
30
  const array = [2, 3, 4, 5, 6, 7];
31
31
  matrix.fromArray(array);
@@ -38,8 +38,8 @@ describe('fromArray', () => {
38
38
  });
39
39
  });
40
40
 
41
- describe('setTo', () => {
42
- it('should set values when arguments are passed', () => {
41
+ describe('setTo', (): void => {
42
+ it('should set values when arguments are passed', (): void => {
43
43
  const matrix = new Matrix();
44
44
  const a = 2;
45
45
  const b = 3;
@@ -56,7 +56,7 @@ describe('setTo', () => {
56
56
  expect(matrix.ty).toBe(ty);
57
57
  });
58
58
 
59
- it('should return the matrix instance', () => {
59
+ it('should return the matrix instance', (): void => {
60
60
  const matrix = new Matrix();
61
61
  const a = 2;
62
62
  const b = 3;
@@ -68,8 +68,8 @@ describe('setTo', () => {
68
68
  });
69
69
  });
70
70
 
71
- describe('clone', () => {
72
- it('should return a copy of the matrix instance', () => {
71
+ describe('clone', (): void => {
72
+ it('should return a copy of the matrix instance', (): void => {
73
73
  const matrix1 = new Matrix(2, 3, 4, 5, 6, 7);
74
74
  const matrix2 = matrix1.clone();
75
75
  expect(matrix2.a).toBe(matrix1.a);
@@ -81,8 +81,8 @@ describe('clone', () => {
81
81
  });
82
82
  });
83
83
 
84
- describe('copyTo', () => {
85
- it('should copy values to another matrix instance', () => {
84
+ describe('copyTo', (): void => {
85
+ it('should copy values to another matrix instance', (): void => {
86
86
  const matrix1 = new Matrix(2, 3, 4, 5, 6, 7);
87
87
  const matrix2 = new Matrix();
88
88
  matrix1.copyTo(matrix2);
@@ -95,8 +95,8 @@ describe('copyTo', () => {
95
95
  });
96
96
  });
97
97
 
98
- describe('copyFrom', () => {
99
- it('should copy values from another matrix instance', () => {
98
+ describe('copyFrom', (): void => {
99
+ it('should copy values from another matrix instance', (): void => {
100
100
  const matrix1 = new Matrix(2, 3, 4, 5, 6, 7);
101
101
  const matrix2 = new Matrix();
102
102
  matrix2.copyFrom(matrix1);
@@ -109,8 +109,8 @@ describe('copyFrom', () => {
109
109
  });
110
110
  });
111
111
 
112
- describe('apply', () => {
113
- it('should apply the matrix to a point', () => {
112
+ describe('apply', (): void => {
113
+ it('should apply the matrix to a point', (): void => {
114
114
  const matrix = new Matrix(2, 3, 4, 5, 6, 7);
115
115
  const point = new Point(1, 2);
116
116
  const result = new Point();
@@ -125,8 +125,8 @@ describe('apply', () => {
125
125
  });
126
126
  });
127
127
 
128
- describe('applyInverse', () => {
129
- it('should apply the inverse of the matrix to a point', () => {
128
+ describe('applyInverse', (): void => {
129
+ it('should apply the inverse of the matrix to a point', (): void => {
130
130
  const matrix = new Matrix(2, 3, 4, 5, 6, 7);
131
131
  const point = new Point(1, 2);
132
132
  const result = new Point();
@@ -136,8 +136,8 @@ describe('applyInverse', () => {
136
136
  });
137
137
  });
138
138
 
139
- describe('translate', () => {
140
- it('should add the translation values to the matrix', () => {
139
+ describe('translate', (): void => {
140
+ it('should add the translation values to the matrix', (): void => {
141
141
  const matrix = new Matrix(2, 3, 4, 5, 6, 7);
142
142
  const x = 1;
143
143
  const y = 2;
@@ -147,8 +147,8 @@ describe('translate', () => {
147
147
  });
148
148
  });
149
149
 
150
- describe('scale', () => {
151
- it('should multiply the scaling values with the matrix', () => {
150
+ describe('scale', (): void => {
151
+ it('should multiply the scaling values with the matrix', (): void => {
152
152
  const matrix = new Matrix(2, 3, 4, 5, 6, 7);
153
153
  const x = 1;
154
154
  const y = 2;
@@ -162,8 +162,8 @@ describe('scale', () => {
162
162
  });
163
163
  });
164
164
 
165
- describe('rotate', () => {
166
- it('should multiply the rotation values with the matrix', () => {
165
+ describe('rotate', (): void => {
166
+ it('should multiply the rotation values with the matrix', (): void => {
167
167
  const matrix = new Matrix(2, 3, 4, 5, 6, 7);
168
168
  const angle = Math.PI / 2;
169
169
  matrix.rotate(angle);
@@ -173,8 +173,8 @@ describe('rotate', () => {
173
173
  });
174
174
  });
175
175
 
176
- describe('append', () => {
177
- it('should add the second matrix to the first one', () => {
176
+ describe('append', (): void => {
177
+ it('should add the second matrix to the first one', (): void => {
178
178
  const matrix1 = new Matrix(2, 3, 4, 5, 6, 7);
179
179
  const matrix2 = new Matrix(8, 9, 10, 11, 12, 13);
180
180
  matrix1.append(matrix2);
@@ -184,8 +184,8 @@ describe('append', () => {
184
184
  });
185
185
  });
186
186
 
187
- describe('identity', () => {
188
- it('should set the values to the identity matrix', () => {
187
+ describe('identity', (): void => {
188
+ it('should set the values to the identity matrix', (): void => {
189
189
  const matrix = new Matrix();
190
190
  matrix.identity();
191
191
  expect(matrix.a).toBe(1);
@@ -200,8 +200,8 @@ describe('identity', () => {
200
200
  });
201
201
  });
202
202
 
203
- describe('toArray', () => {
204
- it('should return the values as an array', () => {
203
+ describe('toArray', (): void => {
204
+ it('should return the values as an array', (): void => {
205
205
  const matrix = new Matrix(2, 3, 4, 5, 6, 7);
206
206
  const result = matrix.toArray();
207
207
  expect(result[0]).toBe(matrix.a);
@@ -221,7 +221,7 @@ describe('toArray', () => {
221
221
  expect(result2[5]).toBe(matrix.ty);
222
222
  });
223
223
 
224
- it('should return the values as an array with transposed coordinates', () => {
224
+ it('should return the values as an array with transposed coordinates', (): void => {
225
225
  const matrix = new Matrix(2, 3, 4, 5, 6, 7);
226
226
  const result = matrix.toArray(true);
227
227
  expect(result[0]).toBe(matrix.a);
@@ -1,20 +1,20 @@
1
1
  import { expect, describe, it } from 'vitest';
2
2
  import { Point } from './point.js';
3
3
 
4
- describe('Point', () => {
5
- it('should create a point with default values', () => {
4
+ describe('Point', (): void => {
5
+ it('should create a point with default values', (): void => {
6
6
  const point = new Point();
7
7
  expect(point.x).toBe(0);
8
8
  expect(point.y).toBe(0);
9
9
  });
10
10
 
11
- it('should create a point with custom x and y values', () => {
11
+ it('should create a point with custom x and y values', (): void => {
12
12
  const point = new Point(10, 20);
13
13
  expect(point.x).toBe(10);
14
14
  expect(point.y).toBe(20);
15
15
  });
16
16
 
17
- it('should copy from another point', () => {
17
+ it('should copy from another point', (): void => {
18
18
  const point1 = new Point(10, 20);
19
19
  const point2 = new Point();
20
20
  point2.copyFrom(point1);
@@ -22,28 +22,28 @@ describe('Point', () => {
22
22
  expect(point2.y).toBe(20);
23
23
  });
24
24
 
25
- it('should invert a point', () => {
25
+ it('should invert a point', (): void => {
26
26
  const point = new Point(10, 20);
27
27
  const invertedPoint = point.invert();
28
28
  expect(invertedPoint.x).toBe(20);
29
29
  expect(invertedPoint.y).toBe(10);
30
30
  });
31
31
 
32
- it('should set to x and y values', () => {
32
+ it('should set to x and y values', (): void => {
33
33
  const point = new Point();
34
34
  point.setTo(10, 20);
35
35
  expect(point.x).toBe(10);
36
36
  expect(point.y).toBe(20);
37
37
  });
38
38
 
39
- it('should set to y value as x value', () => {
39
+ it('should set to y value as x value', (): void => {
40
40
  const point = new Point();
41
41
  point.setTo(10);
42
42
  expect(point.x).toBe(10);
43
43
  expect(point.y).toBe(10);
44
44
  });
45
45
 
46
- it('should add points', () => {
46
+ it('should add points', (): void => {
47
47
  const point1 = new Point(10, 20);
48
48
  const point2 = new Point(30, 40);
49
49
  const sum = point1.add(point2.x, point2.y);
@@ -51,7 +51,7 @@ describe('Point', () => {
51
51
  expect(sum.y).toBe(60);
52
52
  });
53
53
 
54
- it('should subtract points', () => {
54
+ it('should subtract points', (): void => {
55
55
  const point1 = new Point(10, 20);
56
56
  const point2 = new Point(30, 40);
57
57
  const difference = point1.subtract(point2.x, point2.y);
@@ -59,49 +59,49 @@ describe('Point', () => {
59
59
  expect(difference.y).toBe(-20);
60
60
  });
61
61
 
62
- it('should multiply points', () => {
62
+ it('should multiply points', (): void => {
63
63
  const point = new Point(10, 20);
64
64
  const multipliedPoint = point.multiply(2, 3);
65
65
  expect(multipliedPoint.x).toBe(20);
66
66
  expect(multipliedPoint.y).toBe(60);
67
67
  });
68
68
 
69
- it('should divide points', () => {
69
+ it('should divide points', (): void => {
70
70
  const point1 = new Point(10, 20);
71
71
  const quotient = point1.divide(2, 3);
72
72
  expect(quotient.x).toBe(5);
73
73
  expect(quotient.y).toBeCloseTo(6.67);
74
74
  });
75
75
 
76
- it('should clamp x value', () => {
76
+ it('should clamp x value', (): void => {
77
77
  const point = new Point(-10, 20);
78
78
  const clampedPoint = point.clampX(-5, 10);
79
79
  expect(clampedPoint.x).toBe(-5);
80
80
  expect(clampedPoint.y).toBe(20);
81
81
  });
82
82
 
83
- it('should clamp y value', () => {
83
+ it('should clamp y value', (): void => {
84
84
  const point = new Point(10, -20);
85
85
  const clampedPoint = point.clampY(-5, 10);
86
86
  expect(clampedPoint.x).toBe(10);
87
87
  expect(clampedPoint.y).toBe(-5);
88
88
  });
89
89
 
90
- it('should clamp x and y values', () => {
90
+ it('should clamp x and y values', (): void => {
91
91
  const point = new Point(-10, -20);
92
92
  const clampedPoint = point.clamp(-5, 10);
93
93
  expect(clampedPoint.x).toBe(-5);
94
94
  expect(clampedPoint.y).toBe(-5);
95
95
  });
96
96
 
97
- it('should clone a point', () => {
97
+ it('should clone a point', (): void => {
98
98
  const point1 = new Point(10, 20);
99
99
  const clonedPoint = point1.clone();
100
100
  expect(clonedPoint.x).toBe(10);
101
101
  expect(clonedPoint.y).toBe(20);
102
102
  });
103
103
 
104
- it('should copy to another point', () => {
104
+ it('should copy to another point', (): void => {
105
105
  const point1 = new Point(10, 20);
106
106
  const point2 = new Point();
107
107
  point1.copyTo(point2);
@@ -109,98 +109,98 @@ describe('Point', () => {
109
109
  expect(point2.y).toBe(20);
110
110
  });
111
111
 
112
- it('should calculate distance between two points', () => {
112
+ it('should calculate distance between two points', (): void => {
113
113
  const point1 = new Point(0, 0);
114
114
  const point2 = new Point(3, 4);
115
115
  const distance = point1.distance(point2);
116
116
  expect(distance).toBeCloseTo(5);
117
117
  });
118
118
 
119
- it('should check if two points are equal', () => {
119
+ it('should check if two points are equal', (): void => {
120
120
  const point1 = new Point(10, 20);
121
121
  const point2 = new Point(10, 20);
122
122
  expect(point1.equals(point2)).toBe(true);
123
123
  });
124
124
 
125
- it('should calculate angle between two points', () => {
125
+ it('should calculate angle between two points', (): void => {
126
126
  const point1 = new Point(0, 0);
127
127
  const point2 = new Point(3, 4);
128
128
  const angle = point1.angle(point2, true);
129
129
  expect(angle).toBeCloseTo(53.13);
130
130
  });
131
131
 
132
- it('should rotate a point around another point', () => {
132
+ it('should rotate a point around another point', (): void => {
133
133
  const point1 = new Point(10, 20);
134
134
  const rotatedPoint = point1.rotate(0, 0, Math.PI / 2, true);
135
135
  expect(rotatedPoint.x).toBeCloseTo(9.447);
136
136
  expect(rotatedPoint.y).toBeCloseTo(20.266);
137
137
  });
138
138
 
139
- it('should get magnitude of a point', () => {
139
+ it('should get magnitude of a point', (): void => {
140
140
  const point = new Point(3, 4);
141
141
  expect(point.getMagnitude()).toBeCloseTo(5);
142
142
  });
143
143
 
144
- it('should get magnitude squared of a point', () => {
144
+ it('should get magnitude squared of a point', (): void => {
145
145
  const point = new Point(3, 4);
146
146
  expect(point.getMagnitudeSq()).toBeCloseTo(25);
147
147
  });
148
148
 
149
- it('should set magnitude of a point', () => {
149
+ it('should set magnitude of a point', (): void => {
150
150
  const point = new Point(3, 4);
151
151
  const newPoint = point.setMagnitude(10);
152
152
  expect(newPoint.x).toBe(6);
153
153
  expect(newPoint.y).toBe(8);
154
154
  });
155
155
 
156
- it('should normalize a point', () => {
156
+ it('should normalize a point', (): void => {
157
157
  const point = new Point(3, 4);
158
158
  const normalizedPoint = point.normalize();
159
159
  expect(normalizedPoint.x).toBeCloseTo(0.6);
160
160
  expect(normalizedPoint.y).toBeCloseTo(0.8);
161
161
  });
162
162
 
163
- it('should check if a point is zero', () => {
163
+ it('should check if a point is zero', (): void => {
164
164
  const point1 = new Point(0, 0);
165
165
  const point2 = new Point(10, 20);
166
166
  expect(point1.isZero()).toBe(true);
167
167
  expect(point2.isZero()).toBe(false);
168
168
  });
169
169
 
170
- it('should calculate dot product of two points', () => {
170
+ it('should calculate dot product of two points', (): void => {
171
171
  const point1 = new Point(1, 1);
172
172
  const point2 = new Point(2, 2);
173
173
  expect(point1.dot(point2)).toBe(4);
174
174
  });
175
175
 
176
- it('should calculate cross product of two points', () => {
176
+ it('should calculate cross product of two points', (): void => {
177
177
  const point1 = new Point(1, 1);
178
178
  const point2 = new Point(1, 2);
179
179
  expect(point1.cross(point2)).toBe(1);
180
180
  });
181
181
 
182
- it('should get perpendicular point', () => {
182
+ it('should get perpendicular point', (): void => {
183
183
  const point = new Point(10, 20);
184
184
  const perpPoint = point.perp();
185
185
  expect(perpPoint.x).toBe(-20);
186
186
  expect(perpPoint.y).toBe(10);
187
187
  });
188
188
 
189
- it('should get right-hand normal point', () => {
189
+ it('should get right-hand normal point', (): void => {
190
190
  const point = new Point(10, 20);
191
191
  const normalPoint = point.normalRightHand();
192
192
  expect(normalPoint.x).toBe(-20);
193
193
  expect(normalPoint.y).toBe(10);
194
194
  });
195
195
 
196
- it('should floor a point', () => {
196
+ it('should floor a point', (): void => {
197
197
  const point = new Point(3.14, 4.23);
198
198
  const flooredPoint = point.floor();
199
199
  expect(flooredPoint.x).toBe(3);
200
200
  expect(flooredPoint.y).toBe(4);
201
201
  });
202
202
 
203
- it('should ceil a point', () => {
203
+ it('should ceil a point', (): void => {
204
204
  const point = new Point(3.14, 4.23);
205
205
  const ceiledPoint = point.ceil();
206
206
  expect(ceiledPoint.x).toBe(4);