@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,9 +3,9 @@ import { clone, distance, rotate } from './util/point.js';
3
3
 
4
4
  export class Point {
5
5
  /**
6
- * TBD.
7
- * @param {number} x - TBD.
8
- * @param {number} y - TBD.
6
+ * Creates a new Point instance.
7
+ * @param {number} x - The x coordinate of the point (default: 0).
8
+ * @param {number} y - The y coordinate of the point (default: 0).
9
9
  */
10
10
  constructor(x = 0, y = 0) {
11
11
  /** @type {number} */
@@ -17,27 +17,27 @@ export class Point {
17
17
  }
18
18
 
19
19
  /**
20
- * TBD.
21
- * @param {Point} source - TBD.
22
- * @returns {Point} TBD.
20
+ * Copies the coordinates from another point to this point.
21
+ * @param {Point} source - The point to copy coordinates from.
22
+ * @returns {Point} This point instance for chaining.
23
23
  */
24
24
  copyFrom(source) {
25
25
  return this.setTo(source.x, source.y);
26
26
  }
27
27
 
28
28
  /**
29
- * TBD.
30
- * @returns {Point} TBD.
29
+ * Returns a new point with the x and y coordinates swapped.
30
+ * @returns {Point} A new point instance with swapped coordinates.
31
31
  */
32
32
  invert() {
33
33
  return this.setTo(this.y, this.x);
34
34
  }
35
35
 
36
36
  /**
37
- * TBD.
38
- * @param {number} x - TBD.
39
- * @param {number} y - TBD.
40
- * @returns {Point} TBD.
37
+ * Sets the coordinates of this point to new values.
38
+ * @param {number} x - The new x coordinate for the point.
39
+ * @param {number} y - The new y coordinate for the point.
40
+ * @returns {Point} This point instance for chaining.
41
41
  */
42
42
  setTo(x, y) {
43
43
  this.x = x || 0;
@@ -46,11 +46,11 @@ export class Point {
46
46
  }
47
47
 
48
48
  /**
49
- * TBD.
50
- * @param {number} x - TBD.
51
- * @param {number} y - TBD.
52
- * @returns {Point} TBD.
53
- * @deprecated
49
+ * Sets the coordinates of this point to new values.
50
+ * @param {number} x - The new x coordinate for the point.
51
+ * @param {number} y - The new y coordinate for the point.
52
+ * @returns {Point} This point instance for chaining.
53
+ * @deprecated Use setTo instead.
54
54
  */
55
55
  set(x, y) {
56
56
  this.x = x || 0;
@@ -59,10 +59,10 @@ export class Point {
59
59
  }
60
60
 
61
61
  /**
62
- * TBD.
63
- * @param {number} x - TBD.
64
- * @param {number} y - TBD.
65
- * @returns {Point} TBD.
62
+ * Adds the given x and y values to the point's coordinates.
63
+ * @param {number} x - The amount to add to the x coordinate.
64
+ * @param {number} y - The amount to add to the y coordinate.
65
+ * @returns {Point} This point instance for chaining.
66
66
  */
67
67
  add(x, y) {
68
68
  this.x += x;
@@ -71,10 +71,10 @@ export class Point {
71
71
  }
72
72
 
73
73
  /**
74
- * TBD.
75
- * @param {number} x - TBD.
76
- * @param {number} y - TBD.
77
- * @returns {Point} TBD.
74
+ * Subtracts the given x and y values from the point's coordinates.
75
+ * @param {number} x - The amount to subtract from the x coordinate.
76
+ * @param {number} y - The amount to subtract from the y coordinate.
77
+ * @returns {Point} This point instance for chaining.
78
78
  */
79
79
  subtract(x, y) {
80
80
  this.x -= x;
@@ -83,10 +83,10 @@ export class Point {
83
83
  }
84
84
 
85
85
  /**
86
- * TBD.
87
- * @param {number} x - TBD.
88
- * @param {number} y - TBD.
89
- * @returns {Point} TBD.
86
+ * Multiplies the point's coordinates by the given x and y values.
87
+ * @param {number} x - The amount to multiply the x coordinate by.
88
+ * @param {number} y - The amount to multiply the y coordinate by.
89
+ * @returns {Point} This point instance for chaining.
90
90
  */
91
91
  multiply(x, y) {
92
92
  this.x *= x;
@@ -95,10 +95,10 @@ export class Point {
95
95
  }
96
96
 
97
97
  /**
98
- * TBD.
99
- * @param {number} x - TBD.
100
- * @param {number} y - TBD.
101
- * @returns {Point} TBD.
98
+ * Divides the point's coordinates by the given x and y values.
99
+ * @param {number} x - The amount to divide the x coordinate by.
100
+ * @param {number} y - The amount to divide the y coordinate by.
101
+ * @returns {Point} This point instance for chaining.
102
102
  */
103
103
  divide(x, y) {
104
104
  this.x /= x;
@@ -107,10 +107,10 @@ export class Point {
107
107
  }
108
108
 
109
109
  /**
110
- * TBD.
111
- * @param {number} min - TBD.
112
- * @param {number} max - TBD.
113
- * @returns {Point} TBD.
110
+ * Constrains the x coordinate of this point to the given range.
111
+ * @param {number} min - The minimum value for the x coordinate.
112
+ * @param {number} max - The maximum value for the x coordinate.
113
+ * @returns {Point} This point instance for chaining.
114
114
  */
115
115
  clampX(min, max) {
116
116
  this.x = Math.max(min, Math.min(max, this.x));
@@ -118,10 +118,10 @@ export class Point {
118
118
  }
119
119
 
120
120
  /**
121
- * TBD.
122
- * @param {number} min - TBD.
123
- * @param {number} max - TBD.
124
- * @returns {Point} TBD.
121
+ * Constrains the y coordinate of this point to the given range.
122
+ * @param {number} min - The minimum value for the y coordinate.
123
+ * @param {number} max - The maximum value for the y coordinate.
124
+ * @returns {Point} This point instance for chaining.
125
125
  */
126
126
  clampY(min, max) {
127
127
  this.y = Math.max(min, Math.min(max, this.y));
@@ -129,10 +129,10 @@ export class Point {
129
129
  }
130
130
 
131
131
  /**
132
- * TBD.
133
- * @param {number} min - TBD.
134
- * @param {number} max - TBD.
135
- * @returns {Point} TBD.
132
+ * Constrains both coordinates of this point to the given range.
133
+ * @param {number} min - The minimum value for both coordinates.
134
+ * @param {number} max - The maximum value for both coordinates.
135
+ * @returns {Point} This point instance for chaining.
136
136
  */
137
137
  clamp(min, max) {
138
138
  this.x = Math.max(min, Math.min(max, this.x));
@@ -141,17 +141,17 @@ export class Point {
141
141
  }
142
142
 
143
143
  /**
144
- * TBD.
145
- * @returns {Point} TBD.
144
+ * Creates a clone of this point.
145
+ * @returns {Point} A new point with the same coordinates as this one.
146
146
  */
147
147
  clone() {
148
148
  return clone(this);
149
149
  }
150
150
 
151
151
  /**
152
- * TBD.
153
- * @param {Point} dest - TBD.
154
- * @returns {Point} TBD.
152
+ * Copies the coordinates of this point to another point.
153
+ * @param {Point} dest - The point to copy coordinates to.
154
+ * @returns {Point} The destination point.
155
155
  */
156
156
  copyTo(dest) {
157
157
  dest.x = this.x;
@@ -160,28 +160,28 @@ export class Point {
160
160
  }
161
161
 
162
162
  /**
163
- * TBD.
164
- * @param {Point} b - TBD.
165
- * @returns {number} TBD.
163
+ * Calculates the distance between this point and another point.
164
+ * @param {Point} b - The other point to calculate the distance to.
165
+ * @returns {number} The distance between the two points.
166
166
  */
167
167
  distance(b) {
168
168
  return distance(this, b);
169
169
  }
170
170
 
171
171
  /**
172
- * TBD.
173
- * @param {Point} a - TBD.
174
- * @returns {boolean} TBD.
172
+ * Checks if this point is equal to another point.
173
+ * @param {Point} a - The other point to compare with.
174
+ * @returns {boolean} True if the points have the same coordinates, false otherwise.
175
175
  */
176
176
  equals(a) {
177
177
  return a.x === this.x && a.y === this.y;
178
178
  }
179
179
 
180
180
  /**
181
- * TBD.
182
- * @param {Point} a - TBD.
183
- * @param {boolean} asDegrees - TBD.
184
- * @returns {number} TBD.
181
+ * Calculates the angle between this point and another point.
182
+ * @param {Point} a - The other point to calculate the angle to.
183
+ * @param {boolean} asDegrees - Whether to return the result in degrees (default: false).
184
+ * @returns {number} The angle between the two points in radians or degrees.
185
185
  */
186
186
  angle(a, asDegrees = false) {
187
187
  if (asDegrees) {
@@ -191,46 +191,46 @@ export class Point {
191
191
  }
192
192
 
193
193
  /**
194
- * TBD.
195
- * @param {number} x - TBD.
196
- * @param {number} y - TBD.
197
- * @param {number} angle - TBD.
198
- * @param {boolean} asDegrees - TBD.
199
- * @param {number | null | undefined} dist - TBD.
200
- * @returns {Point} TBD.
194
+ * Rotates this point around another point by a given angle.
195
+ * @param {number} x - The x coordinate of the center point to rotate around.
196
+ * @param {number} y - The y coordinate of the center point to rotate around.
197
+ * @param {number} angle - The angle in radians to rotate by.
198
+ * @param {boolean} asDegrees - Whether the angle is provided in degrees (default: false).
199
+ * @param {number | null | undefined} dist - The distance to rotate from (default: null).
200
+ * @returns {Point} This point instance for chaining.
201
201
  */
202
202
  rotate(x, y, angle, asDegrees, dist = null) {
203
203
  return rotate(this, x, y, angle, asDegrees, dist);
204
204
  }
205
205
 
206
206
  /**
207
- * TBD.
208
- * @returns {number} TBD.
207
+ * Calculates the magnitude (length) of this point from the origin.
208
+ * @returns {number} The magnitude of the point.
209
209
  */
210
210
  getMagnitude() {
211
211
  return Math.sqrt(this.x * this.x + this.y * this.y);
212
212
  }
213
213
 
214
214
  /**
215
- * TBD.
216
- * @returns {number} TBD.
215
+ * Calculates the square of the magnitude (length) of this point from the origin.
216
+ * @returns {number} The square of the magnitude of the point.
217
217
  */
218
218
  getMagnitudeSq() {
219
219
  return this.x * this.x + this.y * this.y;
220
220
  }
221
221
 
222
222
  /**
223
- * TBD.
224
- * @param {number} magnitude - TBD.
225
- * @returns {Point} TBD.
223
+ * Sets the magnitude (length) of this point while preserving its direction.
224
+ * @param {number} magnitude - The new magnitude for the point.
225
+ * @returns {Point} This point instance for chaining.
226
226
  */
227
227
  setMagnitude(magnitude) {
228
228
  return this.normalize().multiply(magnitude, magnitude);
229
229
  }
230
230
 
231
231
  /**
232
- * TBD.
233
- * @returns {Point} TBD.
232
+ * Normalizes this point to have a magnitude of 1 while preserving its direction.
233
+ * @returns {Point} This point instance for chaining.
234
234
  */
235
235
  normalize() {
236
236
  if (!this.isZero()) {
@@ -242,74 +242,74 @@ export class Point {
242
242
  }
243
243
 
244
244
  /**
245
- * TBD.
246
- * @returns {boolean} TBD.
245
+ * Checks if this point has zero magnitude (is at the origin).
246
+ * @returns {boolean} True if both x and y coordinates are zero, false otherwise.
247
247
  */
248
248
  isZero() {
249
249
  return this.x === 0 && this.y === 0;
250
250
  }
251
251
 
252
252
  /**
253
- * TBD.
254
- * @param {Point} a - TBD.
255
- * @returns {number} TBD.
253
+ * Calculates the dot product of this point and another point.
254
+ * @param {Point} a - The other point to calculate the dot product with.
255
+ * @returns {number} The dot product of the two points.
256
256
  */
257
257
  dot(a) {
258
258
  return this.x * a.x + this.y * a.y;
259
259
  }
260
260
 
261
261
  /**
262
- * TBD.
263
- * @param {Point} a - TBD.
264
- * @returns {number} TBD.
262
+ * Calculates the cross product of this point and another point.
263
+ * @param {Point} a - The other point to calculate the cross product with.
264
+ * @returns {number} The cross product of the two points.
265
265
  */
266
266
  cross(a) {
267
267
  return this.x * a.y - this.y * a.x;
268
268
  }
269
269
 
270
270
  /**
271
- * TBD.
272
- * @returns {Point} TBD.
271
+ * Returns a perpendicular point (rotated 90 degrees counter-clockwise).
272
+ * @returns {Point} A new point that is perpendicular to this one.
273
273
  */
274
274
  perp() {
275
275
  return this.setTo(-this.y, this.x);
276
276
  }
277
277
 
278
278
  /**
279
- * TBD.
280
- * @returns {Point} TBD.
279
+ * Returns a perpendicular point (rotated 90 degrees clockwise).
280
+ * @returns {Point} A new point that is perpendicular to this one (rotated clockwise).
281
281
  */
282
282
  rperp() {
283
283
  return this.setTo(this.y, -this.x);
284
284
  }
285
285
 
286
286
  /**
287
- * TBD.
288
- * @returns {Point} TBD.
287
+ * Returns a point with the same direction as this one but with y coordinate negated.
288
+ * @returns {Point} A new point with the same x coordinate but negated y coordinate.
289
289
  */
290
290
  normalRightHand() {
291
291
  return this.setTo(this.y * -1, this.x);
292
292
  }
293
293
 
294
294
  /**
295
- * TBD.
296
- * @returns {Point} TBD.
295
+ * Returns a new point with the x and y coordinates rounded down to the nearest integer.
296
+ * @returns {Point} A new point with floored coordinates.
297
297
  */
298
298
  floor() {
299
299
  return this.setTo(Math.floor(this.x), Math.floor(this.y));
300
300
  }
301
301
 
302
302
  /**
303
- * TBD.
304
- * @returns {Point} TBD.
303
+ * Returns a new point with the x and y coordinates rounded up to the nearest integer.
304
+ * @returns {Point} A new point with ceiled coordinates.
305
305
  */
306
306
  ceil() {
307
307
  return this.setTo(Math.ceil(this.x), Math.ceil(this.y));
308
308
  }
309
309
 
310
310
  /**
311
- * TBD.
312
- * @returns {string} TBD.
311
+ * Returns a string representation of this point.
312
+ * @returns {string} A string representation of the point in the format "[Point (x=value y=value)]".
313
313
  */
314
314
  toString() {
315
315
  return `[{Point (x=${this.x} y=${this.y})}]`;
@@ -1,3 +1,4 @@
1
+ import { expect } from 'vitest';
1
2
  import { Point } from './point.js';
2
3
 
3
4
  describe('Point', () => {
@@ -4,8 +4,8 @@ import { GEOM_POLYGON } from '../core/const.js';
4
4
 
5
5
  export class Polygon {
6
6
  /**
7
- * TBD.
8
- * @param {object[]} points - TBD.
7
+ * Creates a new Polygon instance.
8
+ * @param {object[]} points - The array of points to define the polygon (optional).
9
9
  */
10
10
  constructor(points = null) {
11
11
  /** @type {number} */
@@ -24,9 +24,9 @@ export class Polygon {
24
24
  }
25
25
 
26
26
  /**
27
- * TBD.
28
- * @param {number[]} output - TBD.
29
- * @returns {number[]} TBD.
27
+ * Converts the polygon's points to a number array.
28
+ * @param {number[]} output - The array to store the result in (optional).
29
+ * @returns {number[]} An array of numbers representing the polygon's points.
30
30
  */
31
31
  toNumberArray(output = []) {
32
32
  for (let i = 0; i < this._points.length; i += 1) {
@@ -43,8 +43,8 @@ export class Polygon {
43
43
  }
44
44
 
45
45
  /**
46
- * TBD.
47
- * @returns {Polygon} TBD.
46
+ * Flattens the polygon's point array to a simple numeric array.
47
+ * @returns {Polygon} This polygon instance for chaining.
48
48
  */
49
49
  flatten() {
50
50
  this._points = this.toNumberArray();
@@ -53,18 +53,18 @@ export class Polygon {
53
53
  }
54
54
 
55
55
  /**
56
- * TBD.
57
- * @returns {Polygon} TBD.
56
+ * Creates a clone of this polygon.
57
+ * @returns {Polygon} A new polygon with the same values as this one.
58
58
  */
59
59
  clone() {
60
60
  return clone(this);
61
61
  }
62
62
 
63
63
  /**
64
- * TBD.
65
- * @param {number} x - TBD.
66
- * @param {number} y - TBD.
67
- * @returns {boolean} TBD.
64
+ * Checks if the specified point is contained within this polygon.
65
+ * @param {number} x - The x coordinate of the point to check.
66
+ * @param {number} y - The y coordinate of the point to check.
67
+ * @returns {boolean} True if the point is contained within this polygon, false otherwise.
68
68
  */
69
69
  contains(x, y) {
70
70
  // Adapted from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html by Jonas Raoni Soares Silva
@@ -94,9 +94,9 @@ export class Polygon {
94
94
  }
95
95
 
96
96
  /**
97
- * TBD.
98
- * @param {object[]} points - TBD.
99
- * @returns {Polygon} TBD.
97
+ * Sets the polygon's points to new values.
98
+ * @param {object[]} points - The array of points to define the polygon.
99
+ * @returns {Polygon} This polygon instance for chaining.
100
100
  */
101
101
  setTo(points) {
102
102
  this.area = 0;
@@ -133,9 +133,9 @@ export class Polygon {
133
133
  }
134
134
 
135
135
  /**
136
- * TBD.
137
- * @param {number} y0 - TBD.
138
- * @returns {number} TBD.
136
+ * Calculates the area of this polygon.
137
+ * @param {number} y0 - The y coordinate of the lowest boundary (internal use).
138
+ * @returns {number} The area of this polygon.
139
139
  */
140
140
  calculateArea(y0) {
141
141
  let p1;
@@ -157,15 +157,15 @@ export class Polygon {
157
157
  }
158
158
 
159
159
  /**
160
- * TBD.
161
- * @returns {object[]} TBD.
160
+ * Gets the points of this polygon.
161
+ * @returns {object[]} The array of points that define this polygon.
162
162
  */
163
163
  get points() {
164
164
  return this._points;
165
165
  }
166
166
 
167
167
  /**
168
- * TBD.
168
+ * Sets the points of this polygon.
169
169
  */
170
170
  set points(value) {
171
171
  if (value !== null) {