@vpmedia/phaser 1.95.0 → 1.97.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 (184) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/package.json +10 -10
  3. package/src/phaser/core/animation.js +61 -56
  4. package/src/phaser/core/animation_manager.js +55 -55
  5. package/src/phaser/core/cache.js +154 -154
  6. package/src/phaser/core/device.js +2 -1
  7. package/src/phaser/core/device_util.js +27 -27
  8. package/src/phaser/core/dom.js +43 -43
  9. package/src/phaser/core/event_manager.js +63 -63
  10. package/src/phaser/core/factory.js +47 -47
  11. package/src/phaser/core/frame.js +30 -30
  12. package/src/phaser/core/frame_data.js +30 -28
  13. package/src/phaser/core/frame_util.js +8 -8
  14. package/src/phaser/core/game.js +34 -18
  15. package/src/phaser/core/loader.js +170 -170
  16. package/src/phaser/core/loader_parser.js +22 -22
  17. package/src/phaser/core/raf.js +1 -1
  18. package/src/phaser/core/scene.js +16 -10
  19. package/src/phaser/core/scene_manager.js +51 -43
  20. package/src/phaser/core/signal.js +68 -52
  21. package/src/phaser/core/signal.test.js +37 -0
  22. package/src/phaser/core/sound.js +54 -54
  23. package/src/phaser/core/sound_manager.js +49 -49
  24. package/src/phaser/core/stage.js +16 -16
  25. package/src/phaser/core/time.js +30 -30
  26. package/src/phaser/core/timer.js +79 -64
  27. package/src/phaser/core/timer_event.js +9 -9
  28. package/src/phaser/core/tween.js +90 -90
  29. package/src/phaser/core/tween_data.js +30 -30
  30. package/src/phaser/core/tween_manager.js +29 -24
  31. package/src/phaser/core/world.js +4 -3
  32. package/src/phaser/display/bitmap_text.js +61 -54
  33. package/src/phaser/display/button.js +48 -47
  34. package/src/phaser/display/canvas/buffer.js +8 -8
  35. package/src/phaser/display/canvas/graphics.js +8 -8
  36. package/src/phaser/display/canvas/masker.js +5 -5
  37. package/src/phaser/display/canvas/pool.js +18 -18
  38. package/src/phaser/display/canvas/renderer.js +16 -16
  39. package/src/phaser/display/canvas/tinter.js +22 -22
  40. package/src/phaser/display/canvas/util.js +42 -42
  41. package/src/phaser/display/display_object.js +119 -108
  42. package/src/phaser/display/graphics.js +112 -112
  43. package/src/phaser/display/graphics_data.js +10 -10
  44. package/src/phaser/display/graphics_data_util.js +3 -3
  45. package/src/phaser/display/group.js +50 -50
  46. package/src/phaser/display/image.js +54 -50
  47. package/src/phaser/display/sprite_batch.js +2 -2
  48. package/src/phaser/display/sprite_util.js +19 -19
  49. package/src/phaser/display/text.js +212 -187
  50. package/src/phaser/display/webgl/abstract_filter.js +4 -4
  51. package/src/phaser/display/webgl/base_texture.js +9 -9
  52. package/src/phaser/display/webgl/blend_manager.js +7 -7
  53. package/src/phaser/display/webgl/earcut.js +95 -95
  54. package/src/phaser/display/webgl/earcut_node.js +4 -4
  55. package/src/phaser/display/webgl/fast_sprite_batch.js +15 -15
  56. package/src/phaser/display/webgl/filter_manager.js +9 -9
  57. package/src/phaser/display/webgl/filter_texture.js +10 -10
  58. package/src/phaser/display/webgl/graphics.js +37 -37
  59. package/src/phaser/display/webgl/graphics_data.js +4 -4
  60. package/src/phaser/display/webgl/mask_manager.js +6 -6
  61. package/src/phaser/display/webgl/render_texture.js +16 -16
  62. package/src/phaser/display/webgl/renderer.js +20 -20
  63. package/src/phaser/display/webgl/shader/complex.js +4 -4
  64. package/src/phaser/display/webgl/shader/fast.js +4 -4
  65. package/src/phaser/display/webgl/shader/normal.js +8 -8
  66. package/src/phaser/display/webgl/shader/primitive.js +4 -4
  67. package/src/phaser/display/webgl/shader/strip.js +4 -4
  68. package/src/phaser/display/webgl/shader_manager.js +9 -9
  69. package/src/phaser/display/webgl/sprite_batch.js +18 -18
  70. package/src/phaser/display/webgl/stencil_manager.js +16 -16
  71. package/src/phaser/display/webgl/texture.js +13 -13
  72. package/src/phaser/display/webgl/texture_util.js +8 -8
  73. package/src/phaser/display/webgl/util.js +25 -25
  74. package/src/phaser/geom/circle.js +69 -69
  75. package/src/phaser/geom/circle.test.js +1 -0
  76. package/src/phaser/geom/ellipse.js +28 -28
  77. package/src/phaser/geom/ellipse.test.js +1 -0
  78. package/src/phaser/geom/line.js +93 -93
  79. package/src/phaser/geom/line.test.js +1 -0
  80. package/src/phaser/geom/matrix.js +54 -54
  81. package/src/phaser/geom/matrix.test.js +1 -0
  82. package/src/phaser/geom/point.js +96 -96
  83. package/src/phaser/geom/point.test.js +1 -0
  84. package/src/phaser/geom/polygon.js +22 -22
  85. package/src/phaser/geom/rectangle.js +132 -132
  86. package/src/phaser/geom/rectangle.test.js +1 -0
  87. package/src/phaser/geom/rounded_rectangle.js +12 -12
  88. package/src/phaser/geom/rounded_rectangle.test.js +1 -0
  89. package/src/phaser/geom/util/circle.js +33 -33
  90. package/src/phaser/geom/util/circle.test.js +1 -0
  91. package/src/phaser/geom/util/ellipse.js +5 -5
  92. package/src/phaser/geom/util/ellipse.test.js +1 -0
  93. package/src/phaser/geom/util/line.js +26 -26
  94. package/src/phaser/geom/util/line.test.js +1 -0
  95. package/src/phaser/geom/util/matrix.js +8 -8
  96. package/src/phaser/geom/util/matrix.test.js +1 -0
  97. package/src/phaser/geom/util/point.js +97 -97
  98. package/src/phaser/geom/util/point.test.js +1 -0
  99. package/src/phaser/geom/util/polygon.js +4 -4
  100. package/src/phaser/geom/util/polygon.test.js +1 -0
  101. package/src/phaser/geom/util/rectangle.js +74 -74
  102. package/src/phaser/geom/util/rectangle.test.js +1 -0
  103. package/src/phaser/geom/util/rounded_rectangle.js +4 -4
  104. package/src/phaser/geom/util/rounded_rectangle.test.js +1 -0
  105. package/src/phaser/util/math.js +81 -81
  106. package/src/phaser/util/math.test.js +1 -0
  107. package/types/phaser/core/animation.d.ts +61 -56
  108. package/types/phaser/core/animation.d.ts.map +1 -1
  109. package/types/phaser/core/animation_manager.d.ts +55 -55
  110. package/types/phaser/core/cache.d.ts +154 -154
  111. package/types/phaser/core/device.d.ts.map +1 -1
  112. package/types/phaser/core/dom.d.ts +43 -43
  113. package/types/phaser/core/event_manager.d.ts +63 -63
  114. package/types/phaser/core/factory.d.ts +47 -47
  115. package/types/phaser/core/frame.d.ts +30 -30
  116. package/types/phaser/core/frame_data.d.ts +28 -27
  117. package/types/phaser/core/frame_data.d.ts.map +1 -1
  118. package/types/phaser/core/game.d.ts +52 -19
  119. package/types/phaser/core/game.d.ts.map +1 -1
  120. package/types/phaser/core/loader.d.ts +170 -170
  121. package/types/phaser/core/loader_parser.d.ts.map +1 -1
  122. package/types/phaser/core/raf.d.ts +1 -1
  123. package/types/phaser/core/scene.d.ts +15 -9
  124. package/types/phaser/core/scene.d.ts.map +1 -1
  125. package/types/phaser/core/scene_manager.d.ts +51 -43
  126. package/types/phaser/core/scene_manager.d.ts.map +1 -1
  127. package/types/phaser/core/signal.d.ts +54 -51
  128. package/types/phaser/core/signal.d.ts.map +1 -1
  129. package/types/phaser/core/sound.d.ts +54 -54
  130. package/types/phaser/core/sound_manager.d.ts +49 -49
  131. package/types/phaser/core/stage.d.ts +10 -10
  132. package/types/phaser/core/time.d.ts +30 -30
  133. package/types/phaser/core/timer.d.ts +64 -64
  134. package/types/phaser/core/timer_event.d.ts +9 -9
  135. package/types/phaser/core/tween.d.ts +90 -90
  136. package/types/phaser/core/tween_data.d.ts +30 -30
  137. package/types/phaser/core/tween_manager.d.ts +29 -24
  138. package/types/phaser/core/tween_manager.d.ts.map +1 -1
  139. package/types/phaser/core/world.d.ts +4 -3
  140. package/types/phaser/core/world.d.ts.map +1 -1
  141. package/types/phaser/display/bitmap_text.d.ts +59 -52
  142. package/types/phaser/display/bitmap_text.d.ts.map +1 -1
  143. package/types/phaser/display/button.d.ts +47 -46
  144. package/types/phaser/display/button.d.ts.map +1 -1
  145. package/types/phaser/display/canvas/buffer.d.ts +8 -8
  146. package/types/phaser/display/canvas/renderer.d.ts +16 -16
  147. package/types/phaser/display/display_object.d.ts +119 -108
  148. package/types/phaser/display/display_object.d.ts.map +1 -1
  149. package/types/phaser/display/graphics.d.ts +101 -101
  150. package/types/phaser/display/graphics_data.d.ts +10 -10
  151. package/types/phaser/display/group.d.ts +47 -47
  152. package/types/phaser/display/image.d.ts +42 -40
  153. package/types/phaser/display/image.d.ts.map +1 -1
  154. package/types/phaser/display/text.d.ts +207 -184
  155. package/types/phaser/display/text.d.ts.map +1 -1
  156. package/types/phaser/display/webgl/abstract_filter.d.ts +4 -4
  157. package/types/phaser/display/webgl/base_texture.d.ts +9 -9
  158. package/types/phaser/display/webgl/blend_manager.d.ts +6 -6
  159. package/types/phaser/display/webgl/earcut.d.ts +95 -95
  160. package/types/phaser/display/webgl/earcut_node.d.ts +4 -4
  161. package/types/phaser/display/webgl/fast_sprite_batch.d.ts +15 -15
  162. package/types/phaser/display/webgl/filter_manager.d.ts +8 -8
  163. package/types/phaser/display/webgl/filter_texture.d.ts +10 -10
  164. package/types/phaser/display/webgl/graphics_data.d.ts +4 -4
  165. package/types/phaser/display/webgl/render_texture.d.ts +16 -16
  166. package/types/phaser/display/webgl/renderer.d.ts +20 -20
  167. package/types/phaser/display/webgl/shader/complex.d.ts +4 -4
  168. package/types/phaser/display/webgl/shader/fast.d.ts +4 -4
  169. package/types/phaser/display/webgl/shader/normal.d.ts +8 -8
  170. package/types/phaser/display/webgl/shader/primitive.d.ts +4 -4
  171. package/types/phaser/display/webgl/shader/strip.d.ts +4 -4
  172. package/types/phaser/display/webgl/shader_manager.d.ts +8 -8
  173. package/types/phaser/display/webgl/sprite_batch.d.ts +17 -17
  174. package/types/phaser/display/webgl/stencil_manager.d.ts +15 -15
  175. package/types/phaser/display/webgl/texture.d.ts +12 -12
  176. package/types/phaser/geom/circle.d.ts +69 -69
  177. package/types/phaser/geom/ellipse.d.ts +28 -28
  178. package/types/phaser/geom/line.d.ts +93 -93
  179. package/types/phaser/geom/matrix.d.ts +54 -54
  180. package/types/phaser/geom/point.d.ts +96 -96
  181. package/types/phaser/geom/polygon.d.ts +22 -22
  182. package/types/phaser/geom/rectangle.d.ts +132 -132
  183. package/types/phaser/geom/rounded_rectangle.d.ts +12 -12
  184. package/pnpm-workspace.yaml +0 -4
@@ -3,10 +3,10 @@ import { Circle } from '../circle.js';
3
3
  import { Point } from '../point.js';
4
4
 
5
5
  /**
6
- * TBD.
7
- * @param {Circle} input - TBD.
8
- * @param {Circle} output - TBD.
9
- * @returns {Circle} TBD.
6
+ * Clones a circle.
7
+ * @param {Circle} input - The circle to clone.
8
+ * @param {Circle} output - Optional circle to store the result in.
9
+ * @returns {Circle} The cloned circle.
10
10
  */
11
11
  export const clone = (input, output = null) => {
12
12
  const result = output || new Circle();
@@ -17,11 +17,11 @@ export const clone = (input, output = null) => {
17
17
  };
18
18
 
19
19
  /**
20
- * TBD.
21
- * @param {Circle} a - TBD.
22
- * @param {number} x - TBD.
23
- * @param {number} y - TBD.
24
- * @returns {boolean} TBD.
20
+ * Checks if a point is contained within the circle.
21
+ * @param {Circle} a - The circle to check.
22
+ * @param {number} x - The x coordinate of the point.
23
+ * @param {number} y - The y coordinate of the point.
24
+ * @returns {boolean} True if the point is contained within the circle, false otherwise.
25
25
  */
26
26
  export const contains = (a, x, y) => {
27
27
  if (a.radius > 0 && x >= a.left && x <= a.right && y >= a.top && y <= a.bottom) {
@@ -33,32 +33,32 @@ export const contains = (a, x, y) => {
33
33
  };
34
34
 
35
35
  /**
36
- * TBD.
37
- * @param {Circle} a - TBD.
38
- * @param {Circle} b - TBD.
39
- * @returns {boolean} TBD.
36
+ * Checks if two circles are equal.
37
+ * @param {Circle} a - The first circle to compare.
38
+ * @param {Circle} b - The second circle to compare.
39
+ * @returns {boolean} True if the circles are equal, false otherwise.
40
40
  */
41
41
  export const equals = (a, b) => {
42
42
  return a.x === b.x && a.y === b.y && a.diameter === b.diameter;
43
43
  };
44
44
 
45
45
  /**
46
- * TBD.
47
- * @param {Circle} a - TBD.
48
- * @param {Circle} b - TBD.
49
- * @returns {boolean} TBD.
46
+ * Checks if two circles intersect.
47
+ * @param {Circle} a - The first circle to check.
48
+ * @param {Circle} b - The second circle to check.
49
+ * @returns {boolean} True if the circles intersect, false otherwise.
50
50
  */
51
51
  export const intersects = (a, b) => {
52
52
  return distance(a.x, a.y, b.x, b.y) <= a.radius + b.radius;
53
53
  };
54
54
 
55
55
  /**
56
- * TBD.
57
- * @param {Circle} a - TBD.
58
- * @param {number} angle - TBD.
59
- * @param {boolean} asDegrees - TBD.
60
- * @param {Point} output - TBD.
61
- * @returns {Point} TBD.
56
+ * Gets a point on the circumference of the circle at the specified angle.
57
+ * @param {Circle} a - The circle to get the point from.
58
+ * @param {number} angle - The angle in radians or degrees (depending on asDegrees).
59
+ * @param {boolean} asDegrees - True if the angle is in degrees, false if in radians.
60
+ * @param {Point} output - Optional point to store the result in.
61
+ * @returns {Point} The point on the circumference of the circle.
62
62
  */
63
63
  export const circumferencePoint = (a, angle, asDegrees = false, output = null) => {
64
64
  const result = output || new Point();
@@ -71,12 +71,12 @@ export const circumferencePoint = (a, angle, asDegrees = false, output = null) =
71
71
  };
72
72
 
73
73
  /**
74
- * TBD.
75
- * @param {Circle} a - TBD.
76
- * @param {number} angle - TBD.
77
- * @param {boolean} asDegrees - TBD.
78
- * @param {Point} output - TBD.
79
- * @returns {Point} TBD.
74
+ * Gets a point on the circumference of the circle at the specified angle.
75
+ * @param {Circle} a - The circle to get the point from.
76
+ * @param {number} angle - The angle in radians or degrees (depending on asDegrees).
77
+ * @param {boolean} asDegrees - True if the angle is in degrees, false if in radians.
78
+ * @param {Point} output - Optional point to store the result in.
79
+ * @returns {Point} The point on the circumference of the circle.
80
80
  */
81
81
  export const intersectsPoint = (a, angle, asDegrees = false, output = null) => {
82
82
  const result = output || new Point();
@@ -89,10 +89,10 @@ export const intersectsPoint = (a, angle, asDegrees = false, output = null) => {
89
89
  };
90
90
 
91
91
  /**
92
- * TBD.
93
- * @param {Circle} c - TBD.
94
- * @param {object} r - TBD.
95
- * @returns {boolean} TBD.
92
+ * Checks if a circle intersects with a rectangle.
93
+ * @param {Circle} c - The circle to check.
94
+ * @param {object} r - The rectangle to check.
95
+ * @returns {boolean} True if the circle intersects with the rectangle, false otherwise.
96
96
  */
97
97
  export const intersectsRectangle = (c, r) => {
98
98
  const cx = Math.abs(c.x - r.x - r.halfWidth);
@@ -1,3 +1,4 @@
1
+ import { expect } from 'vitest';
1
2
  import { Circle } from '../circle.js';
2
3
  import { clone, contains, equals, intersects } from './circle.js';
3
4
 
@@ -1,9 +1,9 @@
1
1
  /**
2
- * TBD.
3
- * @param {import('../ellipse.js').Ellipse} a - TBD.
4
- * @param {number} x - TBD.
5
- * @param {number} y - TBD.
6
- * @returns {boolean} TBD.
2
+ * Checks if a point is contained within the ellipse.
3
+ * @param {import('../ellipse.js').Ellipse} a - The ellipse to check.
4
+ * @param {number} x - The x coordinate of the point.
5
+ * @param {number} y - The y coordinate of the point.
6
+ * @returns {boolean} True if the point is contained within the ellipse, false otherwise.
7
7
  */
8
8
  export const contains = (a, x, y) => {
9
9
  if (a.width <= 0 || a.height <= 0) {
@@ -1,3 +1,4 @@
1
+ import { expect } from 'vitest';
1
2
  import { Ellipse } from '../ellipse.js';
2
3
  import { contains } from './ellipse.js';
3
4
 
@@ -3,10 +3,10 @@ import { Point } from '../point.js';
3
3
  import { intersects as intersectsRect } from './rectangle.js';
4
4
 
5
5
  /**
6
- * TBD.
7
- * @param {Line} input - TBD.
8
- * @param {Line} output - TBD.
9
- * @returns {Line} TBD.
6
+ * Clones a line.
7
+ * @param {Line} input - The line to clone.
8
+ * @param {Line} output - Optional line to store the result in.
9
+ * @returns {Line} The cloned line.
10
10
  */
11
11
  export const clone = (input, output = null) => {
12
12
  const result = output || new Line();
@@ -18,14 +18,14 @@ export const clone = (input, output = null) => {
18
18
  };
19
19
 
20
20
  /**
21
- * TBD.
22
- * @param {object} a - TBD.
23
- * @param {object} b - TBD.
24
- * @param {object} e - TBD.
25
- * @param {object} f - TBD.
26
- * @param {boolean} asSegment - TBD.
27
- * @param {Point} output - TBD.
28
- * @returns {Point} TBD.
21
+ * Gets the intersection point of two lines.
22
+ * @param {object} a - The first line (with x1, y1, x2, y2 properties).
23
+ * @param {object} b - The second line (with x1, y1, x2, y2 properties).
24
+ * @param {object} e - The first endpoint of the first line (with x, y properties).
25
+ * @param {object} f - The second endpoint of the second line (with x, y properties).
26
+ * @param {boolean} asSegment - True if the lines are treated as segments, false if infinite lines.
27
+ * @param {Point} output - Optional point to store the result in.
28
+ * @returns {Point} The intersection point, or null if there is no intersection.
29
29
  */
30
30
  export const intersectsPoints = (a, b, e, f, asSegment = true, output = null) => {
31
31
  const result = output || new Point();
@@ -54,22 +54,22 @@ export const intersectsPoints = (a, b, e, f, asSegment = true, output = null) =>
54
54
  };
55
55
 
56
56
  /**
57
- * TBD.
58
- * @param {object} a - TBD.
59
- * @param {object} b - TBD.
60
- * @param {boolean} asSegment - TBD.
61
- * @param {Point} result - TBD.
62
- * @returns {Point} TBD.
57
+ * Gets the intersection point of two lines (alternative implementation).
58
+ * @param {object} a - The first line (with x1, y1, x2, y2 properties).
59
+ * @param {object} b - The second line (with x1, y1, x2, y2 properties).
60
+ * @param {boolean} asSegment - True if the lines are treated as segments, false if infinite lines.
61
+ * @param {Point} result - Optional point to store the result in.
62
+ * @returns {Point} The intersection point, or null if there is no intersection.
63
63
  */
64
64
  export const intersects = (a, b, asSegment, result) => {
65
65
  return intersectsPoints(a.start, a.end, b.start, b.end, asSegment, result);
66
66
  };
67
67
 
68
68
  /**
69
- * TBD.
70
- * @param {object} line - TBD.
71
- * @param {object} rect - TBD.
72
- * @returns {boolean} TBD.
69
+ * Checks if a line intersects with a rectangle.
70
+ * @param {object} line - The line to check (with x1, y1, x2, y2 properties).
71
+ * @param {object} rect - The rectangle to check (with x, y, width, height properties).
72
+ * @returns {boolean} True if the line intersects with the rectangle, false otherwise.
73
73
  */
74
74
  export const intersectsRectangle = (line, rect) => {
75
75
  // Quick bail out of the Line and Rect bounds don't intersect
@@ -120,10 +120,10 @@ export const intersectsRectangle = (line, rect) => {
120
120
  };
121
121
 
122
122
  /**
123
- * TBD.
124
- * @param {object} a - TBD.
125
- * @param {object} b - TBD.
126
- * @returns {number} TBD.
123
+ * Calculates the distance between two points (line length).
124
+ * @param {object} a - The first point (with x, y properties).
125
+ * @param {object} b - The second point (with x, y properties).
126
+ * @returns {number} The distance between the points.
127
127
  */
128
128
  export const reflect = (a, b) => {
129
129
  return 2 * b.normalAngle - 3.141592653589793 - a.angle;
@@ -1,3 +1,4 @@
1
+ import { expect } from 'vitest';
1
2
  import { Line } from '../line.js';
2
3
  import { clone } from './line.js';
3
4
 
@@ -1,10 +1,10 @@
1
1
  import { Matrix } from '../matrix.js';
2
2
 
3
3
  /**
4
- * TBD.
5
- * @param {Matrix} input - TBD.
6
- * @param {Matrix} output - TBD.
7
- * @returns {Matrix} TBD.
4
+ * Clones a matrix.
5
+ * @param {Matrix} input - The matrix to clone.
6
+ * @param {Matrix} output - Optional matrix to store the result in.
7
+ * @returns {Matrix} The cloned matrix.
8
8
  */
9
9
  export const clone = (input, output = null) => {
10
10
  const result = output || new Matrix();
@@ -18,8 +18,8 @@ export const clone = (input, output = null) => {
18
18
  };
19
19
 
20
20
  /**
21
- * TBD.
22
- * @returns {Matrix} TBD.
21
+ * Creates a new identity matrix.
22
+ * @returns {Matrix} A new identity matrix.
23
23
  */
24
24
  export const getIdentityMatrix = () => {
25
25
  if (!window.PhaserRegistry) {
@@ -32,8 +32,8 @@ export const getIdentityMatrix = () => {
32
32
  };
33
33
 
34
34
  /**
35
- * TBD.
36
- * @returns {Matrix} TBD.
35
+ * Creates a new matrix with the specified values.
36
+ * @returns {Matrix} A new matrix.
37
37
  */
38
38
  export const getTempMatrix = () => {
39
39
  if (!window.PhaserRegistry) {
@@ -1,3 +1,4 @@
1
+ import { expect } from 'vitest';
1
2
  import { Matrix } from '../matrix.js';
2
3
  import { clone, getIdentityMatrix, getTempMatrix } from './matrix.js';
3
4
 
@@ -1,11 +1,11 @@
1
1
  import { Point } from '../point.js';
2
2
 
3
3
  /**
4
- * TBD.
5
- * @param {Point} a - TBD.
6
- * @param {Point} b - TBD.
7
- * @param {Point} output - TBD.
8
- * @returns {Point} TBD.
4
+ * Adds two points together.
5
+ * @param {Point} a - The first point to add.
6
+ * @param {Point} b - The second point to add.
7
+ * @param {Point} output - The point to store the result in (optional).
8
+ * @returns {Point} A new point containing the sum of the two points.
9
9
  */
10
10
  export const add = (a, b, output = null) => {
11
11
  const result = output || new Point();
@@ -15,11 +15,11 @@ export const add = (a, b, output = null) => {
15
15
  };
16
16
 
17
17
  /**
18
- * TBD.
19
- * @param {Point} a - TBD.
20
- * @param {Point} b - TBD.
21
- * @param {Point} output - TBD.
22
- * @returns {Point} TBD.
18
+ * Subtracts the second point from the first point.
19
+ * @param {Point} a - The first point to subtract from.
20
+ * @param {Point} b - The second point to subtract.
21
+ * @param {Point} output - The point to store the result in (optional).
22
+ * @returns {Point} A new point containing the difference of the two points.
23
23
  */
24
24
  export const subtract = (a, b, output = null) => {
25
25
  const result = output || new Point();
@@ -29,11 +29,11 @@ export const subtract = (a, b, output = null) => {
29
29
  };
30
30
 
31
31
  /**
32
- * TBD.
33
- * @param {Point} a - TBD.
34
- * @param {Point} b - TBD.
35
- * @param {Point} output - TBD.
36
- * @returns {Point} TBD.
32
+ * Multiplies two points together.
33
+ * @param {Point} a - The first point to multiply.
34
+ * @param {Point} b - The second point to multiply.
35
+ * @param {Point} output - The point to store the result in (optional).
36
+ * @returns {Point} A new point containing the product of the two points.
37
37
  */
38
38
  export const multiply = (a, b, output = null) => {
39
39
  const result = output || new Point();
@@ -43,11 +43,11 @@ export const multiply = (a, b, output = null) => {
43
43
  };
44
44
 
45
45
  /**
46
- * TBD.
47
- * @param {Point} a - TBD.
48
- * @param {Point} b - TBD.
49
- * @param {Point} output - TBD.
50
- * @returns {Point} TBD.
46
+ * Divides the first point by the second point.
47
+ * @param {Point} a - The first point to divide.
48
+ * @param {Point} b - The second point to divide by.
49
+ * @param {Point} output - The point to store the result in (optional).
50
+ * @returns {Point} A new point containing the quotient of the two points.
51
51
  */
52
52
  export const divide = (a, b, output = null) => {
53
53
  const result = output || new Point();
@@ -57,30 +57,30 @@ export const divide = (a, b, output = null) => {
57
57
  };
58
58
 
59
59
  /**
60
- * TBD.
61
- * @param {Point} a - TBD.
62
- * @param {Point} b - TBD.
63
- * @returns {boolean} TBD.
60
+ * Checks if two points are equal.
61
+ * @param {Point} a - The first point to compare.
62
+ * @param {Point} b - The second point to compare.
63
+ * @returns {boolean} True if the points are equal, false otherwise.
64
64
  */
65
65
  export const equals = (a, b) => {
66
66
  return a.x === b.x && a.y === b.y;
67
67
  };
68
68
 
69
69
  /**
70
- * TBD.
71
- * @param {Point} a - TBD.
72
- * @param {Point} b - TBD.
73
- * @returns {number} TBD.
70
+ * Calculates the angle between two points.
71
+ * @param {Point} a - The first point to calculate the angle from.
72
+ * @param {Point} b - The second point to calculate the angle to.
73
+ * @returns {number} The angle between the two points in radians.
74
74
  */
75
75
  export const angle = (a, b) => {
76
76
  return Math.atan2(a.y - b.y, a.x - b.x);
77
77
  };
78
78
 
79
79
  /**
80
- * TBD.
81
- * @param {Point} a - TBD.
82
- * @param {Point} output - TBD.
83
- * @returns {Point} TBD.
80
+ * Creates a new point with the same coordinates as the input point but with inverted signs.
81
+ * @param {Point} a - The point to negate.
82
+ * @param {Point} output - The point to store the result in (optional).
83
+ * @returns {Point} A new point with negated coordinates.
84
84
  */
85
85
  export const negative = (a, output = null) => {
86
86
  const result = output || new Point();
@@ -88,12 +88,12 @@ export const negative = (a, output = null) => {
88
88
  };
89
89
 
90
90
  /**
91
- * TBD.
92
- * @param {Point} a - TBD.
93
- * @param {Point} b - TBD.
94
- * @param {number} s - TBD.
95
- * @param {Point} output - TBD.
96
- * @returns {Point} TBD.
91
+ * Multiplies the second point by a scalar and adds it to the first point.
92
+ * @param {Point} a - The first point to add to.
93
+ * @param {Point} b - The second point to multiply by the scalar and add.
94
+ * @param {number} s - The scalar value to multiply the second point by.
95
+ * @param {Point} output - The point to store the result in (optional).
96
+ * @returns {Point} A new point with the result of the operation.
97
97
  */
98
98
  export const multiplyAdd = (a, b, s, output = null) => {
99
99
  const result = output || new Point();
@@ -101,12 +101,12 @@ export const multiplyAdd = (a, b, s, output = null) => {
101
101
  };
102
102
 
103
103
  /**
104
- * TBD.
105
- * @param {Point} a - TBD.
106
- * @param {Point} b - TBD.
107
- * @param {number} f - TBD.
108
- * @param {Point} output - TBD.
109
- * @returns {Point} TBD.
104
+ * Interpolates between two points at a given factor.
105
+ * @param {Point} a - The first point to interpolate from.
106
+ * @param {Point} b - The second point to interpolate to.
107
+ * @param {number} f - The interpolation factor (0-1).
108
+ * @param {Point} output - The point to store the result in (optional).
109
+ * @returns {Point} A new point interpolated between the two points.
110
110
  */
111
111
  export const interpolate = (a, b, f, output = null) => {
112
112
  const result = output || new Point();
@@ -114,10 +114,10 @@ export const interpolate = (a, b, f, output = null) => {
114
114
  };
115
115
 
116
116
  /**
117
- * TBD.
118
- * @param {Point} a - TBD.
119
- * @param {Point} output - TBD.
120
- * @returns {Point} TBD.
117
+ * Returns a perpendicular point (rotated 90 degrees counter-clockwise).
118
+ * @param {Point} a - The point to calculate the perpendicular for.
119
+ * @param {Point} output - The point to store the result in (optional).
120
+ * @returns {Point} A new point that is perpendicular to the input point.
121
121
  */
122
122
  export const perp = (a, output = null) => {
123
123
  const result = output || new Point();
@@ -125,10 +125,10 @@ export const perp = (a, output = null) => {
125
125
  };
126
126
 
127
127
  /**
128
- * TBD.
129
- * @param {Point} a - TBD.
130
- * @param {Point} output - TBD.
131
- * @returns {Point} TBD.
128
+ * Returns a perpendicular point (rotated 90 degrees clockwise).
129
+ * @param {Point} a - The point to calculate the perpendicular for.
130
+ * @param {Point} output - The point to store the result in (optional).
131
+ * @returns {Point} A new point that is perpendicular to the input point (rotated clockwise).
132
132
  */
133
133
  export const rperp = (a, output = null) => {
134
134
  const result = output || new Point();
@@ -136,11 +136,11 @@ export const rperp = (a, output = null) => {
136
136
  };
137
137
 
138
138
  /**
139
- * TBD.
140
- * @param {Point} a - TBD.
141
- * @param {Point} b - TBD.
142
- * @param {boolean} round - TBD.
143
- * @returns {number} TBD.
139
+ * Calculates the distance between two points.
140
+ * @param {Point} a - The first point to calculate the distance from.
141
+ * @param {Point} b - The second point to calculate the distance to.
142
+ * @param {boolean} round - Whether to round the result (default: false).
143
+ * @returns {number} The distance between the two points.
144
144
  */
145
145
  export const distance = (a, b, round = false) => {
146
146
  const dx = a.x - b.x;
@@ -150,11 +150,11 @@ export const distance = (a, b, round = false) => {
150
150
  };
151
151
 
152
152
  /**
153
- * TBD.
154
- * @param {Point} a - TBD.
155
- * @param {Point} b - TBD.
156
- * @param {Point} output - TBD.
157
- * @returns {Point} TBD.
153
+ * Projects the first point onto the second point.
154
+ * @param {Point} a - The point to project.
155
+ * @param {Point} b - The point to project onto.
156
+ * @param {Point} output - The point to store the result in (optional).
157
+ * @returns {Point} A new point with the projected result.
158
158
  */
159
159
  export const project = (a, b, output = null) => {
160
160
  const result = output || new Point();
@@ -166,11 +166,11 @@ export const project = (a, b, output = null) => {
166
166
  };
167
167
 
168
168
  /**
169
- * TBD.
170
- * @param {Point} a - TBD.
171
- * @param {Point} b - TBD.
172
- * @param {Point} output - TBD.
173
- * @returns {Point} TBD.
169
+ * Projects the first point onto the unit vector of the second point.
170
+ * @param {Point} a - The point to project.
171
+ * @param {Point} b - The point to project onto (unit vector).
172
+ * @param {Point} output - The point to store the result in (optional).
173
+ * @returns {Point} A new point with the projected result.
174
174
  */
175
175
  export const projectUnit = (a, b, output = null) => {
176
176
  const result = output || new Point();
@@ -182,10 +182,10 @@ export const projectUnit = (a, b, output = null) => {
182
182
  };
183
183
 
184
184
  /**
185
- * TBD.
186
- * @param {Point} a - TBD.
187
- * @param {Point} output - TBD.
188
- * @returns {Point} TBD.
185
+ * Returns a point with the same direction as the input point but with y coordinate negated.
186
+ * @param {Point} a - The point to calculate the normal for.
187
+ * @param {Point} output - The point to store the result in (optional).
188
+ * @returns {Point} A new point with the same x coordinate but negated y coordinate.
189
189
  */
190
190
  export const normalRightHand = (a, output = null) => {
191
191
  const result = output || new Point();
@@ -193,10 +193,10 @@ export const normalRightHand = (a, output = null) => {
193
193
  };
194
194
 
195
195
  /**
196
- * TBD.
197
- * @param {Point} a - TBD.
198
- * @param {Point} output - TBD.
199
- * @returns {Point} TBD.
196
+ * Normalizes the input point to have a magnitude of 1 while preserving its direction.
197
+ * @param {Point} a - The point to normalize.
198
+ * @param {Point} output - The point to store the result in (optional).
199
+ * @returns {Point} A new normalized point.
200
200
  */
201
201
  export const normalize = (a, output = null) => {
202
202
  const result = output || new Point();
@@ -208,14 +208,14 @@ export const normalize = (a, output = null) => {
208
208
  };
209
209
 
210
210
  /**
211
- * TBD.
212
- * @param {Point} a - TBD.
213
- * @param {number} x - TBD.
214
- * @param {number} y - TBD.
215
- * @param {number} ang - TBD.
216
- * @param {boolean} asDegrees - TBD.
217
- * @param {number | null | undefined} dist - TBD.
218
- * @returns {Point} TBD.
211
+ * Rotates a point around another point by a given angle.
212
+ * @param {Point} a - The point to rotate.
213
+ * @param {number} x - The x coordinate of the center point to rotate around.
214
+ * @param {number} y - The y coordinate of the center point to rotate around.
215
+ * @param {number} ang - The angle in radians to rotate by.
216
+ * @param {boolean} asDegrees - Whether the angle is provided in degrees (default: false).
217
+ * @param {number | null | undefined} dist - The distance to rotate from (default: null).
218
+ * @returns {Point} The rotated point instance for chaining.
219
219
  */
220
220
  export const rotate = (a, x, y, ang, asDegrees, dist) => {
221
221
  if (asDegrees) {
@@ -238,11 +238,11 @@ export const rotate = (a, x, y, ang, asDegrees, dist) => {
238
238
  };
239
239
 
240
240
  /**
241
- * TBD.
242
- * @param {Point[]} points - TBD.
243
- * @param {Point} output - TBD.
244
- * @returns {Point} TBD.
245
- * @throws {Error}
241
+ * Calculates the centroid (average position) of a set of points.
242
+ * @param {Point[]} points - The array of points to calculate the centroid for.
243
+ * @param {Point} output - The point to store the result in (optional).
244
+ * @returns {Point} A new point representing the centroid of the input points.
245
+ * @throws {Error} If the points array is empty.
246
246
  */
247
247
  export const centroid = (points, output = null) => {
248
248
  const result = output || new Point();
@@ -262,11 +262,11 @@ export const centroid = (points, output = null) => {
262
262
  };
263
263
 
264
264
  /**
265
- * TBD.
266
- * @param {object} obj - TBD.
267
- * @param {string} xProp - TBD.
268
- * @param {string} yProp - TBD.
269
- * @returns {Point} TBD.
265
+ * Parses an object with x and y properties into a Point.
266
+ * @param {object} obj - The object to parse (must have x and y properties).
267
+ * @param {string} xProp - The name of the property containing the x value (default: 'x').
268
+ * @param {string} yProp - The name of the property containing the y value (default: 'y').
269
+ * @returns {Point} A new point with parsed x and y values.
270
270
  */
271
271
  export const parse = (obj, xProp = 'x', yProp = 'y') => {
272
272
  const point = new Point();
@@ -280,10 +280,10 @@ export const parse = (obj, xProp = 'x', yProp = 'y') => {
280
280
  };
281
281
 
282
282
  /**
283
- * TBD.
284
- * @param {Point} input - TBD.
285
- * @param {Point} output - TBD.
286
- * @returns {Point} TBD.
283
+ * Creates a clone of the input point.
284
+ * @param {Point} input - The point to clone.
285
+ * @param {Point} output - The point to store the result in (optional).
286
+ * @returns {Point} A new point with the same coordinates as the input.
287
287
  */
288
288
  export const clone = (input, output = null) => {
289
289
  const result = output || new Point();
@@ -1,3 +1,4 @@
1
+ import { expect } from 'vitest';
1
2
  import { Point } from '../point.js';
2
3
  import { clone } from './point.js';
3
4
 
@@ -1,10 +1,10 @@
1
1
  import { Polygon } from '../polygon.js';
2
2
 
3
3
  /**
4
- * TBD.
5
- * @param {Polygon} input - TBD.
6
- * @param {Polygon} output - TBD.
7
- * @returns {Polygon} TBD.
4
+ * Clones a polygon.
5
+ * @param {Polygon} input - The polygon to clone.
6
+ * @param {Polygon} output - Optional polygon to store the result in.
7
+ * @returns {Polygon} The cloned polygon.
8
8
  */
9
9
  export const clone = (input, output = null) => {
10
10
  const result = output || new Polygon();
@@ -1,3 +1,4 @@
1
+ import { expect } from 'vitest';
1
2
  import { Polygon } from '../polygon.js';
2
3
  import { clone } from './polygon.js';
3
4