@vpmedia/phaser 1.123.0 → 1.125.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 (221) hide show
  1. package/dist/index.js +635 -623
  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/frame_data.d.ts.map +1 -1
  17. package/dist/phaser/core/input.d.ts +3 -2
  18. package/dist/phaser/core/input.d.ts.map +1 -1
  19. package/dist/phaser/core/input_handler.d.ts.map +1 -1
  20. package/dist/phaser/core/input_mouse.d.ts +5 -1
  21. package/dist/phaser/core/input_mouse.d.ts.map +1 -1
  22. package/dist/phaser/core/input_pointer.d.ts +3 -3
  23. package/dist/phaser/core/input_pointer.d.ts.map +1 -1
  24. package/dist/phaser/core/input_touch.d.ts +8 -8
  25. package/dist/phaser/core/input_touch.d.ts.map +1 -1
  26. package/dist/phaser/core/loader.d.ts +11 -2
  27. package/dist/phaser/core/loader.d.ts.map +1 -1
  28. package/dist/phaser/core/loader_parser.d.ts +14 -1
  29. package/dist/phaser/core/loader_parser.d.ts.map +1 -1
  30. package/dist/phaser/core/raf.d.ts +1 -1
  31. package/dist/phaser/core/raf.d.ts.map +1 -1
  32. package/dist/phaser/core/scale_manager.d.ts.map +1 -1
  33. package/dist/phaser/core/scene_manager.d.ts.map +1 -1
  34. package/dist/phaser/core/signal.d.ts.map +1 -1
  35. package/dist/phaser/core/sound.d.ts.map +1 -1
  36. package/dist/phaser/core/sound_manager.d.ts +1 -1
  37. package/dist/phaser/core/sound_manager.d.ts.map +1 -1
  38. package/dist/phaser/core/stage.d.ts +16 -6
  39. package/dist/phaser/core/stage.d.ts.map +1 -1
  40. package/dist/phaser/core/time.d.ts.map +1 -1
  41. package/dist/phaser/core/timer.d.ts +1 -1
  42. package/dist/phaser/core/timer.d.ts.map +1 -1
  43. package/dist/phaser/core/tween.d.ts +13 -5
  44. package/dist/phaser/core/tween.d.ts.map +1 -1
  45. package/dist/phaser/core/tween_data.d.ts +9 -7
  46. package/dist/phaser/core/tween_data.d.ts.map +1 -1
  47. package/dist/phaser/core/tween_manager.d.ts.map +1 -1
  48. package/dist/phaser/display/button.d.ts +6 -5
  49. package/dist/phaser/display/button.d.ts.map +1 -1
  50. package/dist/phaser/display/canvas/buffer.d.ts +1 -1
  51. package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
  52. package/dist/phaser/display/canvas/masker.d.ts +1 -1
  53. package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
  54. package/dist/phaser/display/canvas/pool.d.ts +2 -2
  55. package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
  56. package/dist/phaser/display/canvas/renderer.d.ts +9 -8
  57. package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
  58. package/dist/phaser/display/display_object.d.ts +5 -3
  59. package/dist/phaser/display/display_object.d.ts.map +1 -1
  60. package/dist/phaser/display/graphics.d.ts +1 -1
  61. package/dist/phaser/display/graphics.d.ts.map +1 -1
  62. package/dist/phaser/display/group.d.ts +1 -1
  63. package/dist/phaser/display/group.d.ts.map +1 -1
  64. package/dist/phaser/display/image.d.ts +6 -5
  65. package/dist/phaser/display/image.d.ts.map +1 -1
  66. package/dist/phaser/display/sprite_util.d.ts +3 -2
  67. package/dist/phaser/display/sprite_util.d.ts.map +1 -1
  68. package/dist/phaser/display/text.d.ts +2 -16
  69. package/dist/phaser/display/text.d.ts.map +1 -1
  70. package/dist/phaser/display/webgl/abstract_filter.d.ts +14 -8
  71. package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
  72. package/dist/phaser/display/webgl/blend_manager.d.ts +2 -3
  73. package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
  74. package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
  75. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +11 -5
  76. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
  77. package/dist/phaser/display/webgl/filter_manager.d.ts +6 -4
  78. package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
  79. package/dist/phaser/display/webgl/filter_texture.d.ts +4 -4
  80. package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
  81. package/dist/phaser/display/webgl/graphics.d.ts +2 -2
  82. package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
  83. package/dist/phaser/display/webgl/mask_manager.d.ts +3 -2
  84. package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
  85. package/dist/phaser/display/webgl/render_texture.d.ts +11 -8
  86. package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
  87. package/dist/phaser/display/webgl/renderer.d.ts +8 -4
  88. package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
  89. package/dist/phaser/display/webgl/shader/normal.d.ts +28 -3
  90. package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  91. package/dist/phaser/display/webgl/sprite_batch.d.ts +6 -5
  92. package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
  93. package/dist/phaser/display/webgl/stencil_manager.d.ts +3 -3
  94. package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
  95. package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
  96. package/dist/phaser/display/webgl/texture_util.d.ts +2 -2
  97. package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
  98. package/dist/phaser/display/webgl/util.d.ts +1 -1
  99. package/dist/phaser/display/webgl/util.d.ts.map +1 -1
  100. package/dist/phaser/geom/circle.d.ts.map +1 -1
  101. package/dist/phaser/geom/line.d.ts +10 -1
  102. package/dist/phaser/geom/line.d.ts.map +1 -1
  103. package/dist/phaser/geom/rectangle.d.ts.map +1 -1
  104. package/dist/phaser/geom/util/circle.d.ts +2 -1
  105. package/dist/phaser/geom/util/circle.d.ts.map +1 -1
  106. package/dist/phaser/geom/util/point.d.ts +1 -1
  107. package/dist/phaser/geom/util/point.d.ts.map +1 -1
  108. package/dist/phaser/geom/util/rectangle.d.ts +1 -1
  109. package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
  110. package/dist/phaser/util/math.d.ts.map +1 -1
  111. package/package.json +1 -1
  112. package/src/phaser/core/animation.ts +11 -11
  113. package/src/phaser/core/animation_manager.ts +12 -12
  114. package/src/phaser/core/animation_parser.ts +39 -37
  115. package/src/phaser/core/array_set.ts +28 -28
  116. package/src/phaser/core/cache.test.ts +33 -33
  117. package/src/phaser/core/cache.ts +7 -7
  118. package/src/phaser/core/callback.ts +1 -0
  119. package/src/phaser/core/callback_context.test.ts +8 -8
  120. package/src/phaser/core/device_util.ts +4 -4
  121. package/src/phaser/core/dom.ts +38 -24
  122. package/src/phaser/core/factory.ts +9 -2
  123. package/src/phaser/core/frame_data.test.ts +23 -23
  124. package/src/phaser/core/frame_data.ts +2 -5
  125. package/src/phaser/core/game.ts +12 -12
  126. package/src/phaser/core/input.ts +11 -10
  127. package/src/phaser/core/input_handler.test.ts +18 -18
  128. package/src/phaser/core/input_handler.ts +14 -14
  129. package/src/phaser/core/input_mouse.ts +13 -12
  130. package/src/phaser/core/input_pointer.test.ts +26 -26
  131. package/src/phaser/core/input_pointer.ts +4 -4
  132. package/src/phaser/core/input_touch.ts +8 -8
  133. package/src/phaser/core/loader.test.ts +26 -26
  134. package/src/phaser/core/loader.ts +63 -75
  135. package/src/phaser/core/loader_parser.test.ts +16 -16
  136. package/src/phaser/core/loader_parser.ts +16 -6
  137. package/src/phaser/core/raf.ts +1 -1
  138. package/src/phaser/core/registry.test.ts +6 -6
  139. package/src/phaser/core/scale_manager.ts +12 -11
  140. package/src/phaser/core/scene_manager.test.ts +30 -30
  141. package/src/phaser/core/scene_manager.ts +3 -3
  142. package/src/phaser/core/signal.test.ts +8 -8
  143. package/src/phaser/core/signal.ts +3 -3
  144. package/src/phaser/core/signal_dispatch.test.ts +30 -30
  145. package/src/phaser/core/sound.ts +45 -40
  146. package/src/phaser/core/sound_manager.ts +18 -22
  147. package/src/phaser/core/sound_sprite.ts +1 -1
  148. package/src/phaser/core/stage.ts +22 -12
  149. package/src/phaser/core/time.ts +1 -1
  150. package/src/phaser/core/timer.test.ts +47 -47
  151. package/src/phaser/core/timer.ts +2 -2
  152. package/src/phaser/core/tween.ts +34 -36
  153. package/src/phaser/core/tween_data.test.ts +119 -0
  154. package/src/phaser/core/tween_data.ts +54 -39
  155. package/src/phaser/core/tween_easing.test.ts +5 -5
  156. package/src/phaser/core/tween_manager.ts +2 -2
  157. package/src/phaser/display/bitmap_text.test.ts +30 -30
  158. package/src/phaser/display/bitmap_text.ts +3 -3
  159. package/src/phaser/display/button.ts +20 -18
  160. package/src/phaser/display/canvas/buffer.ts +2 -2
  161. package/src/phaser/display/canvas/graphics.ts +2 -2
  162. package/src/phaser/display/canvas/masker.ts +1 -1
  163. package/src/phaser/display/canvas/pool.test.ts +20 -20
  164. package/src/phaser/display/canvas/pool.ts +6 -6
  165. package/src/phaser/display/canvas/renderer.ts +18 -16
  166. package/src/phaser/display/canvas/tinter.ts +1 -1
  167. package/src/phaser/display/canvas/util.test.ts +25 -25
  168. package/src/phaser/display/canvas/util.ts +2 -2
  169. package/src/phaser/display/display_object.ts +16 -15
  170. package/src/phaser/display/graphics.test.ts +70 -20
  171. package/src/phaser/display/graphics.ts +46 -42
  172. package/src/phaser/display/group.ts +13 -12
  173. package/src/phaser/display/image.ts +35 -31
  174. package/src/phaser/display/sprite_util.ts +4 -3
  175. package/src/phaser/display/text.test.ts +28 -25
  176. package/src/phaser/display/text.ts +56 -62
  177. package/src/phaser/display/webgl/abstract_filter.ts +21 -11
  178. package/src/phaser/display/webgl/blend_manager.ts +4 -5
  179. package/src/phaser/display/webgl/earcut.test.ts +20 -20
  180. package/src/phaser/display/webgl/earcut.ts +46 -42
  181. package/src/phaser/display/webgl/fast_sprite_batch.ts +21 -16
  182. package/src/phaser/display/webgl/filter_manager.ts +7 -4
  183. package/src/phaser/display/webgl/filter_texture.ts +5 -5
  184. package/src/phaser/display/webgl/graphics.ts +3 -3
  185. package/src/phaser/display/webgl/mask_manager.ts +9 -14
  186. package/src/phaser/display/webgl/render_texture.ts +15 -14
  187. package/src/phaser/display/webgl/renderer.ts +10 -9
  188. package/src/phaser/display/webgl/shader/normal.ts +45 -35
  189. package/src/phaser/display/webgl/shader/shader.test.ts +24 -24
  190. package/src/phaser/display/webgl/shader_manager.test.ts +18 -18
  191. package/src/phaser/display/webgl/shader_manager.ts +1 -1
  192. package/src/phaser/display/webgl/sprite_batch.ts +10 -10
  193. package/src/phaser/display/webgl/stencil_manager.ts +4 -4
  194. package/src/phaser/display/webgl/texture.ts +2 -1
  195. package/src/phaser/display/webgl/texture_util.ts +2 -2
  196. package/src/phaser/display/webgl/util.ts +4 -4
  197. package/src/phaser/geom/circle.test.ts +38 -38
  198. package/src/phaser/geom/circle.ts +7 -7
  199. package/src/phaser/geom/ellipse.test.ts +12 -12
  200. package/src/phaser/geom/line.test.ts +15 -15
  201. package/src/phaser/geom/line.ts +5 -2
  202. package/src/phaser/geom/matrix.test.ts +31 -31
  203. package/src/phaser/geom/point.test.ts +31 -31
  204. package/src/phaser/geom/polygon.test.ts +27 -27
  205. package/src/phaser/geom/polygon.ts +2 -2
  206. package/src/phaser/geom/rectangle.test.ts +87 -87
  207. package/src/phaser/geom/rectangle.ts +12 -13
  208. package/src/phaser/geom/rounded_rectangle.test.ts +9 -9
  209. package/src/phaser/geom/util/circle.test.ts +5 -5
  210. package/src/phaser/geom/util/circle.ts +8 -11
  211. package/src/phaser/geom/util/ellipse.test.ts +2 -2
  212. package/src/phaser/geom/util/line.test.ts +2 -2
  213. package/src/phaser/geom/util/matrix.test.ts +4 -4
  214. package/src/phaser/geom/util/point.test.ts +2 -2
  215. package/src/phaser/geom/util/point.ts +6 -8
  216. package/src/phaser/geom/util/polygon.test.ts +2 -2
  217. package/src/phaser/geom/util/rectangle.test.ts +2 -2
  218. package/src/phaser/geom/util/rectangle.ts +1 -1
  219. package/src/phaser/geom/util/rounded_rectangle.test.ts +2 -2
  220. package/src/phaser/util/math.test.ts +41 -41
  221. package/src/phaser/util/math.ts +7 -5
@@ -1,6 +1,7 @@
1
1
  import { degToRad, distance } from '../../util/math.js';
2
2
  import { Circle } from '../circle.js';
3
3
  import { Point } from '../point.js';
4
+ import type { Rectangle } from '../rectangle.js';
4
5
 
5
6
  /**
6
7
  * Clones a circle.
@@ -58,11 +59,9 @@ export const intersects = (a: Circle, b: Circle): boolean => distance(a.x, a.y,
58
59
  */
59
60
  export const circumferencePoint = (a: Circle, angle: number, asDegrees = false, output: Point | null = null): Point => {
60
61
  const result = output ?? new Point();
61
- if (asDegrees) {
62
- angle = degToRad(angle);
63
- }
64
- result.x = a.x + a.radius * Math.cos(angle);
65
- result.y = a.y + a.radius * Math.sin(angle);
62
+ const radians = asDegrees ? degToRad(angle) : angle;
63
+ result.x = a.x + a.radius * Math.cos(radians);
64
+ result.y = a.y + a.radius * Math.sin(radians);
66
65
  return result;
67
66
  };
68
67
 
@@ -76,11 +75,9 @@ export const circumferencePoint = (a: Circle, angle: number, asDegrees = false,
76
75
  */
77
76
  export const intersectsPoint = (a: Circle, angle: number, asDegrees = false, output: Point | null = null): Point => {
78
77
  const result = output ?? new Point();
79
- if (asDegrees) {
80
- angle = degToRad(angle);
81
- }
82
- result.x = a.x + a.radius * Math.cos(angle);
83
- result.y = a.y + a.radius * Math.sin(angle);
78
+ const radians = asDegrees ? degToRad(angle) : angle;
79
+ result.x = a.x + a.radius * Math.cos(radians);
80
+ result.y = a.y + a.radius * Math.sin(radians);
84
81
  return result;
85
82
  };
86
83
 
@@ -90,7 +87,7 @@ export const intersectsPoint = (a: Circle, angle: number, asDegrees = false, out
90
87
  * @param {object} r - The rectangle to check.
91
88
  * @returns {boolean} True if the circle intersects with the rectangle, false otherwise.
92
89
  */
93
- export const intersectsRectangle = (c: Circle, r: any): boolean => {
90
+ export const intersectsRectangle = (c: Circle, r: Rectangle): boolean => {
94
91
  const cx = Math.abs(c.x - r.x - r.halfWidth);
95
92
  const xDist = r.halfWidth + c.radius;
96
93
  if (cx > xDist) {
@@ -2,8 +2,8 @@ import { describe, expect, it } from 'vitest';
2
2
  import { Ellipse } from '../ellipse.js';
3
3
  import { contains } from './ellipse.js';
4
4
 
5
- describe('ellipse utils', () => {
6
- it('should contain an ellipse the given coordinates', () => {
5
+ describe('ellipse utils', (): void => {
6
+ it('should contain an ellipse the given coordinates', (): void => {
7
7
  const ellipse = new Ellipse(0, 0, 10, 10);
8
8
  expect(contains(ellipse, 5, 5)).toBe(true);
9
9
  expect(contains(ellipse, 15, 15)).toBe(false);
@@ -2,8 +2,8 @@ import { describe, expect, it } from 'vitest';
2
2
  import { Line } from '../line.js';
3
3
  import { clone } from './line.js';
4
4
 
5
- describe('line utils', () => {
6
- it('should clone a line', () => {
5
+ describe('line utils', (): void => {
6
+ it('should clone a line', (): void => {
7
7
  const line1 = new Line(0, 0, 10, 0);
8
8
  const line2 = clone(line1);
9
9
  expect(line1.start.x).toBe(line2.start.x);
@@ -2,8 +2,8 @@ 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
- describe('matrix utils', () => {
6
- it('should clone a matrix', () => {
5
+ describe('matrix utils', (): void => {
6
+ it('should clone a matrix', (): void => {
7
7
  const matrix1 = new Matrix(2, 0, 0, 2, 0, 0);
8
8
  const matrix2 = clone(matrix1);
9
9
  expect(matrix1.a).toBe(matrix2.a);
@@ -14,12 +14,12 @@ describe('matrix utils', () => {
14
14
  expect(matrix1.ty).toBe(matrix2.ty);
15
15
  });
16
16
 
17
- it('should create an identity matrix', () => {
17
+ it('should create an identity matrix', (): void => {
18
18
  const matrix = getIdentityMatrix();
19
19
  expect(matrix.a).toBe(1);
20
20
  });
21
21
 
22
- it('should create a temporary matrix', () => {
22
+ it('should create a temporary matrix', (): void => {
23
23
  const matrix = getTempMatrix();
24
24
  expect(matrix.a).toBe(1);
25
25
  });
@@ -2,8 +2,8 @@ import { describe, expect, it } from 'vitest';
2
2
  import { Point } from '../point.js';
3
3
  import { clone } from './point.js';
4
4
 
5
- describe('point utils', () => {
6
- it('should clone a point', () => {
5
+ describe('point utils', (): void => {
6
+ it('should clone a point', (): void => {
7
7
  const point1 = new Point(1, 2);
8
8
  const point2 = clone(point1);
9
9
  expect(point1.x).toBe(point2.x);
@@ -221,13 +221,11 @@ export const rotate = (
221
221
  asDegrees: boolean,
222
222
  dist: number | null | undefined
223
223
  ): Point => {
224
- if (asDegrees) {
225
- ang *= Math.PI / 180;
226
- }
224
+ const radians = asDegrees ? ang * (Math.PI / 180) : ang;
227
225
  if (dist === undefined || dist === null) {
228
226
  a.subtract(x, y);
229
- const s = Math.sin(ang);
230
- const c = Math.cos(ang);
227
+ const s = Math.sin(radians);
228
+ const c = Math.cos(radians);
231
229
  const tx = c * a.x - s * a.y;
232
230
  const ty = s * a.x + c * a.y;
233
231
  a.x = tx + x;
@@ -271,12 +269,12 @@ export const centroid = (points: Point[], output: Point | null = null): Point =>
271
269
  * @param {string} yProp - The name of the property containing the y value (default: 'y').
272
270
  * @returns {Point} A new point with parsed x and y values.
273
271
  */
274
- export const parse = (obj: any, xProp = 'x', yProp = 'y'): Point => {
272
+ export const parse = (obj: Record<string, unknown>, xProp = 'x', yProp = 'y'): Point => {
275
273
  const point = new Point();
276
- if (obj[xProp]) {
274
+ if (obj[xProp] !== undefined) {
277
275
  point.x = Math.trunc(Number(obj[xProp]));
278
276
  }
279
- if (obj[yProp]) {
277
+ if (obj[yProp] !== undefined) {
280
278
  point.y = Math.trunc(Number(obj[yProp]));
281
279
  }
282
280
  return point;
@@ -2,8 +2,8 @@ import { describe, expect, it } from 'vitest';
2
2
  import { Polygon } from '../polygon.js';
3
3
  import { clone } from './polygon.js';
4
4
 
5
- describe('polygon utils', () => {
6
- it('should clone a polygon', () => {
5
+ describe('polygon utils', (): void => {
6
+ it('should clone a polygon', (): void => {
7
7
  const polygon = new Polygon([0, 0, 1, 0, 1, 1]);
8
8
  const points = clone(polygon).toNumberArray();
9
9
  expect(points[0]).toBe(0);
@@ -2,8 +2,8 @@ import { describe, expect, it } from 'vitest';
2
2
  import { Rectangle } from '../rectangle.js';
3
3
  import { clone } from './rectangle.js';
4
4
 
5
- describe('rectangle utils', () => {
6
- it('should clone a rectangle', () => {
5
+ describe('rectangle utils', (): void => {
6
+ it('should clone a rectangle', (): void => {
7
7
  const rectangle1 = new Rectangle(0, 0, 10, 10);
8
8
  const rectangle2 = clone(rectangle1);
9
9
  expect(rectangle1.x).toBe(rectangle2.x);
@@ -23,7 +23,7 @@ export const inflate = (a: Rectangle, dx: number, dy: number): Rectangle => {
23
23
  * @param {object} point - The point containing x and y values to inflate the rectangle by.
24
24
  * @returns {Rectangle} The inflated rectangle.
25
25
  */
26
- export const inflatePoint = (a: Rectangle, point: any): Rectangle => inflate(a, point.x, point.y);
26
+ export const inflatePoint = (a: Rectangle, point: Point): Rectangle => inflate(a, point.x, point.y);
27
27
 
28
28
  /**
29
29
  * Gets the size of the rectangle as a point.
@@ -2,8 +2,8 @@ import { describe, expect, it } from 'vitest';
2
2
  import { RoundedRectangle } from '../rounded_rectangle.js';
3
3
  import { clone } from './rounded_rectangle.js';
4
4
 
5
- describe('rounded rectangle utils', () => {
6
- it('should clone a rounded rectangle', () => {
5
+ describe('rounded rectangle utils', (): void => {
6
+ it('should clone a rounded rectangle', (): void => {
7
7
  const rectangle1 = new RoundedRectangle(0, 0, 10, 10, 2);
8
8
  const rectangle2 = clone(rectangle1);
9
9
  expect(rectangle1.x).toBe(rectangle2.x);
@@ -17,66 +17,66 @@ import {
17
17
  wrap,
18
18
  } from './math.js';
19
19
 
20
- describe('DEG_TO_RAD', () => {
21
- it('returns the correct value', () => {
20
+ describe('DEG_TO_RAD', (): void => {
21
+ it('returns the correct value', (): void => {
22
22
  expect(DEG_TO_RAD).toBeCloseTo(Math.PI / 180);
23
23
  });
24
24
  });
25
25
 
26
- describe('RAD_TO_DEG', () => {
27
- it('returns the correct value', () => {
26
+ describe('RAD_TO_DEG', (): void => {
27
+ it('returns the correct value', (): void => {
28
28
  expect(RAD_TO_DEG).toBeCloseTo(180 / Math.PI);
29
29
  });
30
30
  });
31
31
 
32
- describe('PI_2', () => {
33
- it('returns the correct value', () => {
32
+ describe('PI_2', (): void => {
33
+ it('returns the correct value', (): void => {
34
34
  expect(PI_2).toBeCloseTo(Math.PI * 2);
35
35
  });
36
36
  });
37
37
 
38
- describe('getNextPowerOfTwo', () => {
39
- it('returns the correct power of two value for a valid input', () => {
38
+ describe('getNextPowerOfTwo', (): void => {
39
+ it('returns the correct power of two value for a valid input', (): void => {
40
40
  expect(getNextPowerOfTwo(10)).toBe(16);
41
41
  });
42
42
 
43
- it('returns the correct power of two value for an invalid input', () => {
43
+ it('returns the correct power of two value for an invalid input', (): void => {
44
44
  expect(getNextPowerOfTwo(-5)).toBe(1);
45
45
  });
46
46
  });
47
47
 
48
- describe('isPowerOfTwo', () => {
49
- it('returns true for a valid power of two value', () => {
48
+ describe('isPowerOfTwo', (): void => {
49
+ it('returns true for a valid power of two value', (): void => {
50
50
  expect(isPowerOfTwo(8, 16)).toBe(true);
51
51
  });
52
52
 
53
- it('returns false for an invalid power of two value', () => {
53
+ it('returns false for an invalid power of two value', (): void => {
54
54
  expect(isPowerOfTwo(7, 15)).toBe(false);
55
55
  });
56
56
  });
57
57
 
58
- describe('degToRad', () => {
59
- it('returns the correct radian value for a valid degree input', () => {
58
+ describe('degToRad', (): void => {
59
+ it('returns the correct radian value for a valid degree input', (): void => {
60
60
  expect(degToRad(90)).toBeCloseTo(Math.PI / 2);
61
61
  });
62
62
 
63
- it('returns the correct radian value for an invalid degree input', () => {
63
+ it('returns the correct radian value for an invalid degree input', (): void => {
64
64
  expect(degToRad(-45)).toBeCloseTo(-0.7853);
65
65
  });
66
66
  });
67
67
 
68
- describe('radToDeg', () => {
69
- it('returns the correct degree value for a valid radian input', () => {
68
+ describe('radToDeg', (): void => {
69
+ it('returns the correct degree value for a valid radian input', (): void => {
70
70
  expect(radToDeg(Math.PI / 2)).toBe(90);
71
71
  });
72
72
 
73
- it('returns the correct degree value for an invalid radian input', () => {
73
+ it('returns the correct degree value for an invalid radian input', (): void => {
74
74
  expect(radToDeg(-Math.PI / 10)).toBe(-18);
75
75
  });
76
76
  });
77
77
 
78
- describe('between', () => {
79
- it('returns a random value within the specified range', () => {
78
+ describe('between', (): void => {
79
+ it('returns a random value within the specified range', (): void => {
80
80
  const min = 1;
81
81
  const max = 100;
82
82
  const result = between(min, max);
@@ -85,18 +85,18 @@ describe('between', () => {
85
85
  });
86
86
  });
87
87
 
88
- describe('snapToCeil', () => {
89
- it('returns the correct snapped value for a valid input with a gap of 1', () => {
88
+ describe('snapToCeil', (): void => {
89
+ it('returns the correct snapped value for a valid input with a gap of 1', (): void => {
90
90
  expect(snapToCeil(3.7, 1)).toBe(4);
91
91
  });
92
92
 
93
- it('returns the correct snapped value for a valid input with a gap of 2', () => {
93
+ it('returns the correct snapped value for a valid input with a gap of 2', (): void => {
94
94
  expect(snapToCeil(5.3, 2)).toBe(6);
95
95
  });
96
96
  });
97
97
 
98
- describe('wrap', () => {
99
- it('returns the correct wrapped value for a valid input', () => {
98
+ describe('wrap', (): void => {
99
+ it('returns the correct wrapped value for a valid input', (): void => {
100
100
  const min = 0;
101
101
  const max = 100;
102
102
  const result = wrap(150, min, max);
@@ -104,7 +104,7 @@ describe('wrap', () => {
104
104
  expect(result).toBeLessThanOrEqual(max);
105
105
  });
106
106
 
107
- it('returns the correct wrapped value for an invalid input', () => {
107
+ it('returns the correct wrapped value for an invalid input', (): void => {
108
108
  const min = -1;
109
109
  const max = 10;
110
110
  const result = wrap(-20, min, max);
@@ -113,15 +113,15 @@ describe('wrap', () => {
113
113
  });
114
114
  });
115
115
 
116
- describe('linear', () => {
117
- it('returns the correct interpolated value for a valid input', () => {
116
+ describe('linear', (): void => {
117
+ it('returns the correct interpolated value for a valid input', (): void => {
118
118
  const p0 = 1;
119
119
  const p1 = 2;
120
120
  const t = 0.5;
121
121
  expect(linear(p0, p1, t)).toStrictEqual(1.5);
122
122
  });
123
123
 
124
- it('returns the correct interpolated value for an invalid input', () => {
124
+ it('returns the correct interpolated value for an invalid input', (): void => {
125
125
  const p0 = 1;
126
126
  const p1 = 2;
127
127
  const t = 2;
@@ -129,32 +129,32 @@ describe('linear', () => {
129
129
  });
130
130
  });
131
131
 
132
- describe('difference', () => {
133
- it('returns the correct difference value for a valid input', () => {
132
+ describe('difference', (): void => {
133
+ it('returns the correct difference value for a valid input', (): void => {
134
134
  expect(difference(10, 5)).toBe(5);
135
135
  });
136
136
 
137
- it('returns the correct difference value for an invalid input', () => {
137
+ it('returns the correct difference value for an invalid input', (): void => {
138
138
  expect(difference(-10, -15)).toBe(5);
139
139
  });
140
140
  });
141
141
 
142
- describe('linearInterpolation', () => {
143
- it('returns the correct interpolated value for a valid input', () => {
142
+ describe('linearInterpolation', (): void => {
143
+ it('returns the correct interpolated value for a valid input', (): void => {
144
144
  const v = [1, 2, 3];
145
145
  const k = 0.5;
146
146
  expect(linearInterpolation(v, k)).toBe(2);
147
147
  });
148
148
 
149
- it('returns the correct interpolated value for an invalid input', () => {
149
+ it('returns the correct interpolated value for an invalid input', (): void => {
150
150
  const v = [-10, -20, -30];
151
151
  const k = -1;
152
152
  expect(linearInterpolation(v, k)).toBe(10);
153
153
  });
154
154
  });
155
155
 
156
- describe('distance', () => {
157
- it('returns the correct distance value for a valid input', () => {
156
+ describe('distance', (): void => {
157
+ it('returns the correct distance value for a valid input', (): void => {
158
158
  const x1 = 0;
159
159
  const y1 = 0;
160
160
  const x2 = 3;
@@ -162,7 +162,7 @@ describe('distance', () => {
162
162
  expect(distance(x1, y1, x2, y2)).toBeCloseTo(5);
163
163
  });
164
164
 
165
- it('returns the correct distance value for an invalid input', () => {
165
+ it('returns the correct distance value for an invalid input', (): void => {
166
166
  const x1 = -10;
167
167
  const y1 = -20;
168
168
  const x2 = 100;
@@ -171,15 +171,15 @@ describe('distance', () => {
171
171
  });
172
172
  });
173
173
 
174
- describe('within', () => {
175
- it('returns true for a valid input within the specified tolerance', () => {
174
+ describe('within', (): void => {
175
+ it('returns true for a valid input within the specified tolerance', (): void => {
176
176
  const a = 6;
177
177
  const b = 5;
178
178
  const tolerance = 1;
179
179
  expect(within(a, b, tolerance)).toBe(true);
180
180
  });
181
181
 
182
- it('returns false for an invalid input outside the specified tolerance', () => {
182
+ it('returns false for an invalid input outside the specified tolerance', (): void => {
183
183
  const a = -10;
184
184
  const b = -15;
185
185
  const tolerance = 0.001;
@@ -63,9 +63,8 @@ export const snapToCeil = (input: number, gap = 0, start = 0): number => {
63
63
  if (gap === 0) {
64
64
  return input;
65
65
  }
66
- input -= start;
67
- input = gap * Math.ceil(input / gap);
68
- return start + input;
66
+ const offset = gap * Math.ceil((input - start) / gap);
67
+ return start + offset;
69
68
  };
70
69
 
71
70
  /** Wraps a value within a range. */
@@ -115,8 +114,11 @@ export const getColor = (r: number, g: number, b: number): number => (r << 16) |
115
114
 
116
115
  /** Converts a hex color string to RGB components. */
117
116
  export const hexToColor = (value: string, out: ColorTarget): void => {
118
- value = value.replace(/^(?:#|0x)?([a-f\d])([a-f\d])([a-f\d])$/i, (_m, r, g, b) => r + r + g + g + b + b);
119
- const result = /^(?:#|0x)?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(value);
117
+ const expanded = value.replace(
118
+ /^(?:#|0x)?([a-f\d])([a-f\d])([a-f\d])$/i,
119
+ (_match: string, r: string, g: string, b: string): string => r + r + g + g + b + b
120
+ );
121
+ const result = /^(?:#|0x)?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(expanded);
120
122
  if (result) {
121
123
  out.r = Number.parseInt(result[1]!, 16);
122
124
  out.g = Number.parseInt(result[2]!, 16);