@vpmedia/phaser 1.75.0 → 1.76.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 (91) hide show
  1. package/README.md +1 -1
  2. package/coverage/clover.xml +1089 -3
  3. package/coverage/coverage-final.json +19 -1
  4. package/coverage/lcov-report/core/const.js.html +901 -0
  5. package/coverage/lcov-report/core/index.html +116 -0
  6. package/coverage/lcov-report/geom/circle.js.html +1003 -0
  7. package/coverage/lcov-report/geom/ellipse.js.html +388 -0
  8. package/coverage/lcov-report/geom/index.html +221 -0
  9. package/coverage/lcov-report/geom/line.js.html +1102 -0
  10. package/coverage/lcov-report/geom/matrix.js.html +751 -0
  11. package/coverage/lcov-report/geom/point.js.html +1027 -0
  12. package/coverage/lcov-report/geom/polygon.js.html +604 -0
  13. package/coverage/lcov-report/geom/rectangle.js.html +1774 -0
  14. package/coverage/lcov-report/geom/rounded_rectangle.js.html +226 -0
  15. package/coverage/lcov-report/geom/util/circle.js.html +436 -0
  16. package/coverage/lcov-report/geom/util/ellipse.js.html +139 -0
  17. package/coverage/lcov-report/geom/util/index.html +221 -0
  18. package/coverage/lcov-report/geom/util/line.js.html +475 -0
  19. package/coverage/lcov-report/geom/util/matrix.js.html +223 -0
  20. package/coverage/lcov-report/geom/util/point.js.html +961 -0
  21. package/coverage/lcov-report/geom/util/polygon.js.html +124 -0
  22. package/coverage/lcov-report/geom/util/rectangle.js.html +784 -0
  23. package/coverage/lcov-report/geom/util/rounded_rectangle.js.html +136 -0
  24. package/coverage/lcov-report/index.html +70 -10
  25. package/coverage/lcov-report/util/index.html +116 -0
  26. package/coverage/lcov-report/util/math.js.html +958 -0
  27. package/coverage/lcov.info +2179 -0
  28. package/package.json +1 -1
  29. package/src/phaser/core/device_util.js +1 -0
  30. package/src/phaser/core/dom.js +1 -0
  31. package/src/phaser/core/game.js +4 -1
  32. package/src/phaser/core/input_handler.js +2 -2
  33. package/src/phaser/core/scene.js +3 -1
  34. package/src/phaser/core/signal.js +1 -1
  35. package/src/phaser/core/timer.js +1 -1
  36. package/src/phaser/display/canvas/util.js +1 -0
  37. package/src/phaser/display/display_object.js +2 -0
  38. package/src/phaser/display/webgl/render_texture.js +5 -4
  39. package/src/phaser/display/webgl/shader/complex.js +1 -0
  40. package/src/phaser/display/webgl/shader/fast.js +1 -0
  41. package/src/phaser/display/webgl/shader/normal.js +3 -0
  42. package/src/phaser/display/webgl/shader/primitive.js +1 -0
  43. package/src/phaser/display/webgl/shader/strip.js +1 -0
  44. package/src/phaser/display/webgl/shader_manager.js +1 -1
  45. package/src/phaser/display/webgl/texture.js +1 -1
  46. package/src/phaser/geom/circle.test.js +198 -0
  47. package/src/phaser/geom/ellipse.test.js +83 -0
  48. package/src/phaser/geom/line.test.js +112 -0
  49. package/src/phaser/geom/matrix.test.js +242 -0
  50. package/src/phaser/geom/point.test.js +209 -0
  51. package/src/phaser/geom/rectangle.test.js +460 -0
  52. package/src/phaser/geom/rounded_rectangle.test.js +63 -0
  53. package/src/phaser/geom/util/circle.test.js +29 -0
  54. package/src/phaser/geom/util/ellipse.js +1 -1
  55. package/src/phaser/geom/util/ellipse.test.js +8 -0
  56. package/src/phaser/geom/util/line.js +1 -1
  57. package/src/phaser/geom/util/line.test.js +11 -0
  58. package/src/phaser/geom/util/matrix.test.js +23 -0
  59. package/src/phaser/geom/util/point.js +1 -1
  60. package/src/phaser/geom/util/point.test.js +9 -0
  61. package/src/phaser/geom/util/polygon.test.js +13 -0
  62. package/src/phaser/geom/util/rectangle.test.js +11 -0
  63. package/src/phaser/geom/util/rounded_rectangle.test.js +12 -0
  64. package/src/phaser/util/math.test.js +187 -0
  65. package/types/phaser/core/device_util.d.ts.map +1 -1
  66. package/types/phaser/core/dom.d.ts.map +1 -1
  67. package/types/phaser/core/game.d.ts.map +1 -1
  68. package/types/phaser/core/scene.d.ts +3 -1
  69. package/types/phaser/core/scene.d.ts.map +1 -1
  70. package/types/phaser/core/signal.d.ts +1 -1
  71. package/types/phaser/core/signal.d.ts.map +1 -1
  72. package/types/phaser/core/timer.d.ts +1 -1
  73. package/types/phaser/core/timer.d.ts.map +1 -1
  74. package/types/phaser/display/canvas/util.d.ts.map +1 -1
  75. package/types/phaser/display/display_object.d.ts +2 -0
  76. package/types/phaser/display/display_object.d.ts.map +1 -1
  77. package/types/phaser/display/webgl/render_texture.d.ts.map +1 -1
  78. package/types/phaser/display/webgl/shader/complex.d.ts +1 -0
  79. package/types/phaser/display/webgl/shader/complex.d.ts.map +1 -1
  80. package/types/phaser/display/webgl/shader/fast.d.ts +1 -0
  81. package/types/phaser/display/webgl/shader/fast.d.ts.map +1 -1
  82. package/types/phaser/display/webgl/shader/normal.d.ts +3 -0
  83. package/types/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  84. package/types/phaser/display/webgl/shader/primitive.d.ts +1 -0
  85. package/types/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
  86. package/types/phaser/display/webgl/shader/strip.d.ts +1 -0
  87. package/types/phaser/display/webgl/shader/strip.d.ts.map +1 -1
  88. package/types/phaser/display/webgl/shader_manager.d.ts +7 -3
  89. package/types/phaser/display/webgl/shader_manager.d.ts.map +1 -1
  90. package/types/phaser/geom/util/ellipse.d.ts +1 -1
  91. package/types/phaser/geom/util/ellipse.d.ts.map +1 -1
@@ -0,0 +1,460 @@
1
+ import { TOP_LEFT } from '../core/const.js';
2
+ import { Point } from './point.js';
3
+ import { Rectangle } from './rectangle.js';
4
+
5
+ describe('Rectangle', () => {
6
+ describe('offset()', () => {
7
+ it('should update x and y properties when dx and dy are provided', () => {
8
+ const rect = new Rectangle(0, 0, 10, 10);
9
+ rect.offset(10, 20);
10
+ expect(rect.x).toBe(10);
11
+ expect(rect.y).toBe(20);
12
+ });
13
+ });
14
+
15
+ describe('offsetPoint()', () => {
16
+ it('should call offset() with point.x and point.y as arguments when a Point object is provided', () => {
17
+ const rect = new Rectangle(0, 0, 10, 10);
18
+ const point = new Point(15, 25);
19
+ rect.offsetPoint(point);
20
+ expect(rect.x).toBe(15);
21
+ expect(rect.y).toBe(25);
22
+ });
23
+ });
24
+
25
+ describe('setTo()', () => {
26
+ it('should update x, y, width and height properties when all arguments are provided', () => {
27
+ const rect = new Rectangle(0, 0, 10, 10);
28
+ rect.setTo(100, 200, 300, 400);
29
+ expect(rect.x).toBe(100);
30
+ expect(rect.y).toBe(200);
31
+ expect(rect.width).toBe(300);
32
+ expect(rect.height).toBe(400);
33
+ });
34
+ });
35
+
36
+ describe('scale()', () => {
37
+ it('should update width and height properties when x is provided', () => {
38
+ const rect = new Rectangle(0, 0, 10, 10);
39
+ rect.scale(2);
40
+ expect(rect.width).toBe(20);
41
+ expect(rect.height).toBe(20);
42
+ });
43
+
44
+ it('should update width and height properties when both x and y are provided', () => {
45
+ const rect = new Rectangle(0, 0, 10, 10);
46
+ const point = new Point(3, 4);
47
+ rect.scale(point.x, point.y);
48
+ expect(rect.width).toBe(30);
49
+ expect(rect.height).toBe(40);
50
+ });
51
+ });
52
+
53
+ describe('centerOn()', () => {
54
+ it('should update centerX and centerY properties when both x and y are provided', () => {
55
+ const rect = new Rectangle(0, 0, 10, 10);
56
+ const point = new Point(150, 250);
57
+ rect.centerOn(point.x, point.y);
58
+ expect(rect.centerX).toBe(point.x);
59
+ expect(rect.centerY).toBe(point.y);
60
+ });
61
+ });
62
+
63
+ describe('floor()', () => {
64
+ it('should update x and y properties by rounding down', () => {
65
+ const rect = new Rectangle(0, 0, 10, 10);
66
+ rect.floor();
67
+ expect(rect.x).toBe(Math.floor(rect.x));
68
+ expect(rect.y).toBe(Math.floor(rect.y));
69
+ });
70
+ });
71
+
72
+ describe('floorAll()', () => {
73
+ it('should update x, y, width and height properties by rounding down', () => {
74
+ const rect = new Rectangle(0, 0, 10, 10);
75
+ rect.floorAll();
76
+ expect(rect.x).toBe(Math.floor(rect.x));
77
+ expect(rect.y).toBe(Math.floor(rect.y));
78
+ expect(rect.width).toBe(Math.floor(rect.width));
79
+ expect(rect.height).toBe(Math.floor(rect.height));
80
+ });
81
+ });
82
+
83
+ describe('ceil()', () => {
84
+ it('should update x and y properties by rounding up', () => {
85
+ const rect = new Rectangle(0, 0, 10, 10);
86
+ rect.ceil();
87
+ expect(rect.x).toBe(Math.ceil(rect.x));
88
+ expect(rect.y).toBe(Math.ceil(rect.y));
89
+ });
90
+ });
91
+
92
+ describe('ceilAll()', () => {
93
+ it('should update x, y, width and height properties by rounding up', () => {
94
+ const rect = new Rectangle(0, 0, 10, 10);
95
+ rect.ceilAll();
96
+ expect(rect.x).toBe(Math.ceil(rect.x));
97
+ expect(rect.y).toBe(Math.ceil(rect.y));
98
+ expect(rect.width).toBe(Math.ceil(rect.width));
99
+ expect(rect.height).toBe(Math.ceil(rect.height));
100
+ });
101
+ });
102
+
103
+ describe('copyFrom()', () => {
104
+ it('should return a new Rectangle object with the same properties as the provided rectangle', () => {
105
+ const rect = new Rectangle(0, 0, 10, 10);
106
+ const source = new Rectangle();
107
+ source.setTo(500, 600, 700, 800);
108
+ const copy = rect.copyFrom(source);
109
+ expect(copy.x).toBe(source.x);
110
+ expect(copy.y).toBe(source.y);
111
+ expect(copy.width).toBe(source.width);
112
+ expect(copy.height).toBe(source.height);
113
+ });
114
+ });
115
+
116
+ describe('copyTo()', () => {
117
+ it('should update the provided rectangle with the same properties as this rectangle', () => {
118
+ const rect = new Rectangle(0, 0, 10, 10);
119
+ const dest = new Rectangle();
120
+ rect.setTo(50, 60, 70, 80);
121
+ rect.copyTo(dest);
122
+ expect(dest.x).toBe(rect.x);
123
+ expect(dest.y).toBe(rect.y);
124
+ expect(dest.width).toBe(rect.width);
125
+ expect(dest.height).toBe(rect.height);
126
+ });
127
+ });
128
+
129
+ describe('inflate()', () => {
130
+ it('should call the inflate() function from another module with this rectangle and dx and dy as arguments', () => {
131
+ const rect = new Rectangle(0, 0, 10, 10);
132
+ const inflated = rect.inflate(10, 20);
133
+ expect(inflated.x).toBe(-10);
134
+ expect(inflated.y).toBe(-20);
135
+ });
136
+ });
137
+
138
+ describe('size()', () => {
139
+ it('should call the size() function from another module with this rectangle and an output point as arguments', () => {
140
+ const rect = new Rectangle(0, 0, 10, 10);
141
+ const point = new Point();
142
+ const sized = rect.size(point);
143
+ expect(sized.x).toBe(rect.width);
144
+ expect(sized.y).toBe(rect.height);
145
+ });
146
+ });
147
+
148
+ describe('resize()', () => {
149
+ it('should update width and height properties when both x and y are provided', () => {
150
+ const rect = new Rectangle(0, 0, 10, 10);
151
+ rect.resize(120, 140);
152
+ expect(rect.width).toBe(120);
153
+ expect(rect.height).toBe(140);
154
+ });
155
+ });
156
+
157
+ describe('clone()', () => {
158
+ it('should return a new Rectangle object with the same properties as this rectangle', () => {
159
+ const rect = new Rectangle(0, 0, 10, 10);
160
+ const clone = rect.clone();
161
+ expect(clone.x).toBe(rect.x);
162
+ expect(clone.y).toBe(rect.y);
163
+ expect(clone.width).toBe(rect.width);
164
+ expect(clone.height).toBe(rect.height);
165
+ });
166
+ });
167
+
168
+ describe('contains()', () => {
169
+ it('should return true if the point x, y is within this rectangle', () => {
170
+ const rect = new Rectangle(0, 0, 10, 10);
171
+ rect.setTo(100, 200, 300, 400);
172
+ const contains = rect.contains(150, 250);
173
+ expect(contains).toBe(true);
174
+ });
175
+
176
+ it('should return false if the point x, y is outside this rectangle', () => {
177
+ const rect = new Rectangle(0, 0, 10, 10);
178
+ rect.setTo(100, 200, 300, 400);
179
+ const contains = rect.contains(500, 600);
180
+ expect(contains).toBe(false);
181
+ });
182
+ });
183
+
184
+ describe('containsRect()', () => {
185
+ it('should return true if the rectangle b is within this rectangle', () => {
186
+ const rect = new Rectangle(0, 0, 10, 10);
187
+ const source = new Rectangle();
188
+ source.setTo(100, 200, 300, 400);
189
+ const contains = rect.containsRect(source);
190
+ expect(contains).toBe(false);
191
+ });
192
+
193
+ it('should return false if the rectangle b is outside this rectangle', () => {
194
+ const rect = new Rectangle(0, 0, 10, 10);
195
+ const source = new Rectangle();
196
+ source.setTo(-500, -600, 700, 800);
197
+ const contains = rect.containsRect(source);
198
+ expect(contains).toBe(false);
199
+ });
200
+ });
201
+
202
+ describe('equals()', () => {
203
+ it('should return true if the rectangle b has the same properties as this rectangle', () => {
204
+ const rect = new Rectangle(0, 0, 10, 10);
205
+ const source = new Rectangle();
206
+ source.setTo(100, 200, 300, 400);
207
+ const equals = rect.equals(source);
208
+ expect(equals).toBe(false);
209
+ });
210
+
211
+ it('should return false if the rectangle b does not have the same properties as this rectangle', () => {
212
+ const rect = new Rectangle(0, 0, 10, 10);
213
+ const source = new Rectangle();
214
+ source.setTo(-500, -600, 700, 800);
215
+ const equals = rect.equals(source);
216
+ expect(equals).toBe(false);
217
+ });
218
+ });
219
+
220
+ describe('intersection()', () => {
221
+ it('should return a new Rectangle object that represents the intersection of this rectangle and b', () => {
222
+ const rect = new Rectangle(0, 0, 10, 10);
223
+ const source = new Rectangle();
224
+ source.setTo(100, 200, 300, 400);
225
+ const intersection = rect.intersection(source);
226
+ expect(intersection.x).toBe(0);
227
+ expect(intersection.y).toBe(0);
228
+ expect(intersection.width).toBe(0);
229
+ expect(intersection.height).toBe(0);
230
+ });
231
+ });
232
+
233
+ describe('intersects()', () => {
234
+ it('should return true if the rectangle b intersects with this rectangle', () => {
235
+ const rect = new Rectangle(0, 0, 10, 10);
236
+ const source = new Rectangle();
237
+ source.setTo(100, 200, 300, 400);
238
+ const intersects = rect.intersects(source);
239
+ expect(intersects).toBe(false);
240
+ });
241
+
242
+ it('should return false if the rectangle b does not intersect with this rectangle', () => {
243
+ const rect = new Rectangle(0, 0, 10, 10);
244
+ const source = new Rectangle();
245
+ source.setTo(-500, -600, 700, 800);
246
+ const intersects = rect.intersects(source);
247
+ expect(intersects).toBe(true);
248
+ });
249
+ });
250
+
251
+ describe('intersectsRaw()', () => {
252
+ it('should return true if the rectangle b intersects with this rectangle at left, right, top and bottom', () => {
253
+ const rect = new Rectangle(0, 0, 10, 10);
254
+ const source = new Rectangle();
255
+ source.setTo(100, 200, 300, 400);
256
+ const intersects = rect.intersectsRaw(-500, -600, -700, -800, 0.1);
257
+ expect(intersects).toBe(false);
258
+ });
259
+
260
+ it('should return false if the rectangle b does not intersect with this rectangle at left, right, top and bottom', () => {
261
+ const rect = new Rectangle(0, 0, 10, 10);
262
+ const source = new Rectangle();
263
+ source.setTo(-500, -600, 700, 800);
264
+ const intersects = rect.intersectsRaw(0, 10, -1000, 1500, 0.1);
265
+ expect(intersects).toBe(true);
266
+ });
267
+ });
268
+
269
+ describe('union()', () => {
270
+ it('should return a new Rectangle object that represents the union of this rectangle and b', () => {
271
+ const rect = new Rectangle(0, 0, 10, 10);
272
+ const source = new Rectangle();
273
+ source.setTo(100, 200, 300, 400);
274
+ const union = rect.union(source);
275
+ expect(union.x).toBe(Math.min(rect.left, source.left));
276
+ expect(union.y).toBe(Math.min(rect.top, source.top));
277
+ expect(union.width).toBe(Math.max(rect.right, source.right) - Math.min(rect.left, source.left));
278
+ expect(union.height).toBe(Math.max(rect.bottom, source.bottom) - Math.min(rect.top, source.top));
279
+ });
280
+ });
281
+
282
+ describe('random()', () => {
283
+ it('should return a new Point object with x and y coordinates within this rectangle', () => {
284
+ const rect = new Rectangle(0, 0, 10, 10);
285
+ const random = rect.random();
286
+ expect(random.x >= rect.left && random.x <= rect.right).toBe(true);
287
+ expect(random.y >= rect.top && random.y <= rect.bottom).toBe(true);
288
+ });
289
+ });
290
+
291
+ describe('getPoint()', () => {
292
+ it('should return a new Point object at the specified position within this rectangle', () => {
293
+ const rect = new Rectangle(0, 0, 10, 10);
294
+ const point = rect.getPoint(TOP_LEFT);
295
+ expect(point.x).toBe(rect.left);
296
+ expect(point.y).toBe(rect.top);
297
+ });
298
+ });
299
+
300
+ describe('toString()', () => {
301
+ it('should return a string representation of this rectangle', () => {
302
+ const rect = new Rectangle(0, 0, 10, 10);
303
+ const string = rect.toString();
304
+ expect(string).toContain(`x=${rect.x}`);
305
+ expect(string).toContain(`y=${rect.y}`);
306
+ expect(string).toContain(`width=${rect.width}`);
307
+ expect(string).toContain(`height=${rect.height}`);
308
+ });
309
+ });
310
+
311
+ describe('halfWidth', () => {
312
+ it('should return half the width of this rectangle', () => {
313
+ const rect = new Rectangle(0, 0, 10, 10);
314
+ const half = rect.halfWidth;
315
+ expect(half).toBe(Math.round(rect.width / 2));
316
+ });
317
+ });
318
+
319
+ describe('halfHeight', () => {
320
+ it('should return half the height of this rectangle', () => {
321
+ const rect = new Rectangle(0, 0, 10, 10);
322
+ const half = rect.halfHeight;
323
+ expect(half).toBe(Math.round(rect.height / 2));
324
+ });
325
+ });
326
+
327
+ describe('top', () => {
328
+ it('should get and set the top coordinate of this rectangle', () => {
329
+ const rect = new Rectangle(0, 0, 10, 10);
330
+ const top = rect.top;
331
+ expect(top).toBe(rect.y);
332
+ rect.top = 1000;
333
+ expect(rect.top).toBe(1000);
334
+ });
335
+ });
336
+
337
+ describe('left', () => {
338
+ it('should get and set the left coordinate of this rectangle', () => {
339
+ const rect = new Rectangle(0, 0, 10, 10);
340
+ const left = rect.left;
341
+ expect(left).toBe(rect.x);
342
+ rect.left = 1500;
343
+ expect(rect.left).toBe(1500);
344
+ });
345
+ });
346
+
347
+ describe('right', () => {
348
+ it('should get and set the right coordinate of this rectangle', () => {
349
+ const rect = new Rectangle(0, 0, 10, 10);
350
+ const right = rect.right;
351
+ expect(right).toBe(rect.x + rect.width);
352
+ rect.right = 1600;
353
+ expect(rect.right).toBe(1600);
354
+ });
355
+ });
356
+
357
+ describe('bottom', () => {
358
+ it('should get and set the bottom coordinate of this rectangle', () => {
359
+ const rect = new Rectangle(0, 0, 10, 10);
360
+ const bottom = rect.bottom;
361
+ expect(bottom).toBe(rect.y + rect.height);
362
+ rect.bottom = 1700;
363
+ expect(rect.bottom).toBe(1700);
364
+ });
365
+ });
366
+
367
+ describe('topLeft', () => {
368
+ it('should get and set the top-left coordinates of this rectangle', () => {
369
+ const rect = new Rectangle(0, 0, 10, 10);
370
+ const topLeft = rect.topLeft;
371
+ expect(topLeft.x).toBe(rect.left);
372
+ expect(topLeft.y).toBe(rect.top);
373
+ rect.topLeft = new Point(1800, 1900);
374
+ expect(rect.left).toBe(1800);
375
+ expect(rect.top).toBe(1900);
376
+ });
377
+ });
378
+
379
+ describe('topRight', () => {
380
+ it('should get and set the top-right coordinates of this rectangle', () => {
381
+ const rect = new Rectangle(0, 0, 10, 10);
382
+ const topRight = rect.topRight;
383
+ expect(topRight.x).toBe(rect.right);
384
+ expect(topRight.y).toBe(rect.top);
385
+ rect.topRight = new Point(2000, 2100);
386
+ expect(rect.right).toBe(2000);
387
+ expect(rect.top).toBe(2100);
388
+ });
389
+ });
390
+
391
+ describe('bottomLeft', () => {
392
+ it('should get and set the bottom-left coordinates of this rectangle', () => {
393
+ const rect = new Rectangle(0, 0, 10, 10);
394
+ const bottomLeft = rect.bottomLeft;
395
+ expect(bottomLeft.x).toBe(rect.left);
396
+ expect(bottomLeft.y).toBe(rect.bottom);
397
+ rect.bottomLeft = new Point(2200, 2300);
398
+ expect(rect.left).toBe(2200);
399
+ expect(rect.bottom).toBe(2300);
400
+ });
401
+ });
402
+
403
+ describe('bottomRight', () => {
404
+ it('should get and set the bottom-right coordinates of this rectangle', () => {
405
+ const rect = new Rectangle(0, 0, 10, 10);
406
+ const bottomRight = rect.bottomRight;
407
+ expect(bottomRight.x).toBe(rect.right);
408
+ expect(bottomRight.y).toBe(rect.bottom);
409
+ rect.bottomRight = new Point(2400, 2500);
410
+ expect(rect.right).toBe(2400);
411
+ expect(rect.bottom).toBe(2500);
412
+ });
413
+ });
414
+
415
+ describe('centerX', () => {
416
+ it('should get and set the center x coordinate of this rectangle', () => {
417
+ const rect = new Rectangle(0, 0, 10, 10);
418
+ const centerX = rect.centerX;
419
+ expect(centerX).toBe(rect.x + rect.halfWidth);
420
+ rect.centerX = 2600;
421
+ expect(rect.centerX).toBe(2600);
422
+ });
423
+ });
424
+
425
+ describe('centerY', () => {
426
+ it('should get and set the center y coordinate of this rectangle', () => {
427
+ const rect = new Rectangle(0, 0, 10, 10);
428
+ const centerY = rect.centerY;
429
+ expect(centerY).toBe(rect.y + rect.halfHeight);
430
+ rect.centerY = 2700;
431
+ expect(rect.centerY).toBe(2700);
432
+ });
433
+ });
434
+
435
+ describe('randomX', () => {
436
+ it('should return a random x coordinate within this rectangle', () => {
437
+ const rect = new Rectangle(0, 0, 10, 10);
438
+ const randomX = rect.randomX;
439
+ expect(randomX >= rect.left && randomX <= rect.right).toBe(true);
440
+ });
441
+ });
442
+
443
+ describe('randomY', () => {
444
+ it('should return a random y coordinate within this rectangle', () => {
445
+ const rect = new Rectangle(0, 0, 10, 10);
446
+ const randomY = rect.randomY;
447
+ expect(randomY >= rect.top && randomY <= rect.bottom).toBe(true);
448
+ });
449
+ });
450
+
451
+ describe('empty', () => {
452
+ it('should get and set whether this rectangle is empty or not', () => {
453
+ const rect = new Rectangle(0, 0, 10, 10);
454
+ const empty = rect.empty;
455
+ expect(empty).toBe(!rect.width || !rect.height);
456
+ rect.empty = true;
457
+ expect(rect.empty).toBe(true);
458
+ });
459
+ });
460
+ });
@@ -0,0 +1,63 @@
1
+ import { RoundedRectangle } from './rounded_rectangle.js';
2
+
3
+ describe('RoundedRectangle Constructor', () => {
4
+ it('should create a new instance with correct properties', () => {
5
+ const rectangle = new RoundedRectangle(10, 20, 30, 40, 5);
6
+ expect(rectangle.x).toBe(10);
7
+ expect(rectangle.y).toBe(20);
8
+ expect(rectangle.width).toBe(30);
9
+ expect(rectangle.height).toBe(40);
10
+ expect(rectangle.radius).toBe(5);
11
+ });
12
+ });
13
+
14
+ describe('RoundedRectangle contains Method', () => {
15
+ it('should return false for zero width or height', () => {
16
+ const rectangle = new RoundedRectangle(10, 20, 0, 40, 5);
17
+ expect(rectangle.contains(15, 25)).toBe(false);
18
+
19
+ const rectangle2 = new RoundedRectangle(10, 20, 30, 0, 5);
20
+ expect(rectangle2.contains(15, 25)).toBe(false);
21
+ });
22
+ });
23
+
24
+ describe('RoundedRectangle contains Method', () => {
25
+ it('should return true for a point inside the rectangle', () => {
26
+ const rectangle = new RoundedRectangle(10, 20, 30, 40, 5);
27
+ expect(rectangle.contains(15, 25)).toBe(true);
28
+ });
29
+ });
30
+
31
+ describe('RoundedRectangle contains Method', () => {
32
+ it("should return true for a point on the rectangle's edge", () => {
33
+ const rectangle = new RoundedRectangle(10, 20, 30, 40, 5);
34
+ expect(rectangle.contains(0, 25)).toBe(false);
35
+ expect(rectangle.contains(30, 25)).toBe(true);
36
+ expect(rectangle.contains(15, 0)).toBe(false);
37
+ expect(rectangle.contains(15, 40)).toBe(true);
38
+ });
39
+ });
40
+
41
+ describe('RoundedRectangle contains Method', () => {
42
+ it('should return false for a point outside the rectangle', () => {
43
+ const rectangle = new RoundedRectangle(10, 20, 30, 40, 5);
44
+ expect(rectangle.contains(-1, -1)).toBe(false);
45
+ expect(rectangle.contains(50, 60)).toBe(false);
46
+ });
47
+ });
48
+
49
+ describe('RoundedRectangle clone Method', () => {
50
+ it('should create a deep copy of the original rectangle', () => {
51
+ const original = new RoundedRectangle(10, 20, 30, 40, 5);
52
+ const clone = original.clone();
53
+ expect(clone.x).toBe(original.x);
54
+ expect(clone.y).toBe(original.y);
55
+ expect(clone.width).toBe(original.width);
56
+ expect(clone.height).toBe(original.height);
57
+ expect(clone.radius).toBe(original.radius);
58
+
59
+ // Change one property to verify the clone is independent
60
+ original.x += 1;
61
+ expect(original.x).not.toBe(clone.x);
62
+ });
63
+ });
@@ -0,0 +1,29 @@
1
+ import { Circle } from '../circle.js';
2
+ import { clone, contains, equals, intersects } from './circle.js';
3
+
4
+ it('should clone a circle', () => {
5
+ const circle1 = new Circle(0, 0, 10);
6
+ const circle2 = clone(circle1);
7
+ expect(circle1.x).toBe(circle2.x);
8
+ expect(circle1.y).toBe(circle2.y);
9
+ expect(circle1.radius).toBe(circle2.radius);
10
+ });
11
+
12
+ it('should contain a point in a circle', () => {
13
+ const circle = new Circle(5, 5, 10);
14
+ expect(contains(circle, 5, 5)).toBe(true);
15
+ });
16
+
17
+ it('should match two circles', () => {
18
+ const circle1 = new Circle(5, 5, 10);
19
+ const circle2 = new Circle(5, 5, 10);
20
+ expect(equals(circle1, circle2)).toBe(true);
21
+ circle2.x = 0;
22
+ expect(equals(circle1, circle2)).toBe(false);
23
+ });
24
+
25
+ it('should intersects two circles', () => {
26
+ const circle1 = new Circle(5, 5, 10);
27
+ const circle2 = new Circle(5, 5, 5);
28
+ expect(intersects(circle1, circle2)).toBe(true);
29
+ });
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * TBD.
3
- * @param {object} a - TBD.
3
+ * @param {import('../ellipse.js').Ellipse} a - TBD.
4
4
  * @param {number} x - TBD.
5
5
  * @param {number} y - TBD.
6
6
  * @returns {boolean} TBD.
@@ -0,0 +1,8 @@
1
+ import { Ellipse } from '../ellipse.js';
2
+ import { contains } from './ellipse.js';
3
+
4
+ it('should contain an ellipse the given coordinates', () => {
5
+ const ellipse = new Ellipse(0, 0, 10, 10);
6
+ expect(contains(ellipse, 5, 5)).toBe(true);
7
+ expect(contains(ellipse, 15, 15)).toBe(false);
8
+ });
@@ -73,7 +73,7 @@ export const intersects = (a, b, asSegment, result) => {
73
73
  */
74
74
  export const intersectsRectangle = (line, rect) => {
75
75
  // Quick bail out of the Line and Rect bounds don't intersect
76
- if (intersectsRect(line, rect)) {
76
+ if (!intersectsRect(line, rect)) {
77
77
  return false;
78
78
  }
79
79
  const x1 = line.start.x;
@@ -0,0 +1,11 @@
1
+ import { Line } from '../line.js';
2
+ import { clone } from './line.js';
3
+
4
+ it('should clone a line', () => {
5
+ const line1 = new Line(0, 0, 10, 0);
6
+ const line2 = clone(line1);
7
+ expect(line1.start.x).toBe(line2.start.x);
8
+ expect(line1.start.y).toBe(line2.start.y);
9
+ expect(line1.end.x).toBe(line2.end.x);
10
+ expect(line1.end.y).toBe(line2.end.y);
11
+ });
@@ -0,0 +1,23 @@
1
+ import { Matrix } from '../matrix.js';
2
+ import { clone, getIdentityMatrix, getTempMatrix } from './matrix.js';
3
+
4
+ it('should clone a matrix', () => {
5
+ const matrix1 = new Matrix(2, 0, 0, 2, 0, 0);
6
+ const matrix2 = clone(matrix1);
7
+ expect(matrix1.a).toBe(matrix2.a);
8
+ expect(matrix1.b).toBe(matrix2.b);
9
+ expect(matrix1.c).toBe(matrix2.c);
10
+ expect(matrix1.d).toBe(matrix2.d);
11
+ expect(matrix1.tx).toBe(matrix2.tx);
12
+ expect(matrix1.ty).toBe(matrix2.ty);
13
+ });
14
+
15
+ it('should create an identity matrix', () => {
16
+ const matrix = getIdentityMatrix();
17
+ expect(matrix.a).toBe(1);
18
+ });
19
+
20
+ it('should create a temporary matrix', () => {
21
+ const matrix = getTempMatrix();
22
+ expect(matrix.a).toBe(1);
23
+ });
@@ -221,7 +221,7 @@ export const rotate = (a, x, y, ang, asDegrees, dist) => {
221
221
  if (asDegrees) {
222
222
  ang *= Math.PI / 180;
223
223
  }
224
- if (dist === undefined) {
224
+ if (dist === undefined || dist === null) {
225
225
  a.subtract(x, y);
226
226
  const s = Math.sin(ang);
227
227
  const c = Math.cos(ang);
@@ -0,0 +1,9 @@
1
+ import { Point } from '../point.js';
2
+ import { clone } from './point.js';
3
+
4
+ it('should clone a point', () => {
5
+ const point1 = new Point(1, 2);
6
+ const point2 = clone(point1);
7
+ expect(point1.x).toBe(point2.x);
8
+ expect(point1.y).toBe(point2.y);
9
+ });
@@ -0,0 +1,13 @@
1
+ import { Polygon } from '../polygon.js';
2
+ import { clone } from './polygon.js';
3
+
4
+ it('should clone a polygon', () => {
5
+ const polygon = new Polygon([0, 0, 1, 0, 1, 1]);
6
+ const points = clone(polygon).toNumberArray();
7
+ expect(points[0]).toBe(0);
8
+ expect(points[1]).toBe(0);
9
+ expect(points[2]).toBe(1);
10
+ expect(points[3]).toBe(0);
11
+ expect(points[4]).toBe(1);
12
+ expect(points[5]).toBe(1);
13
+ });
@@ -0,0 +1,11 @@
1
+ import { Rectangle } from '../rectangle.js';
2
+ import { clone } from './rectangle.js';
3
+
4
+ it('should clone a rectangle', () => {
5
+ const rectangle1 = new Rectangle(0, 0, 10, 10);
6
+ const rectangle2 = clone(rectangle1);
7
+ expect(rectangle1.x).toBe(rectangle2.x);
8
+ expect(rectangle1.y).toBe(rectangle2.y);
9
+ expect(rectangle1.width).toBe(rectangle2.width);
10
+ expect(rectangle1.height).toBe(rectangle2.height);
11
+ });
@@ -0,0 +1,12 @@
1
+ import { RoundedRectangle } from '../rounded_rectangle.js';
2
+ import { clone } from './rounded_rectangle.js';
3
+
4
+ it('should clone a rounded rectangle', () => {
5
+ const rectangle1 = new RoundedRectangle(0, 0, 10, 10, 2);
6
+ const rectangle2 = clone(rectangle1);
7
+ expect(rectangle1.x).toBe(rectangle2.x);
8
+ expect(rectangle1.y).toBe(rectangle2.y);
9
+ expect(rectangle1.width).toBe(rectangle2.width);
10
+ expect(rectangle1.height).toBe(rectangle2.height);
11
+ expect(rectangle1.radius).toBe(rectangle2.radius);
12
+ });