@vpmedia/phaser 1.112.0 → 1.113.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.
- package/dist/index.js +1261 -1314
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/animation.d.ts +14 -10
- package/dist/phaser/core/animation.d.ts.map +1 -1
- package/dist/phaser/core/animation_manager.d.ts +10 -8
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- package/dist/phaser/core/animation_parser.d.ts +5 -4
- package/dist/phaser/core/animation_parser.d.ts.map +1 -1
- package/dist/phaser/core/array_set.d.ts.map +1 -1
- package/dist/phaser/core/cache.d.ts +4 -3
- package/dist/phaser/core/cache.d.ts.map +1 -1
- package/dist/phaser/core/const.d.ts.map +1 -1
- package/dist/phaser/core/device.d.ts.map +1 -1
- package/dist/phaser/core/device_util.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts +3 -2
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/event_manager.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts +1 -1
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/frame.d.ts.map +1 -1
- package/dist/phaser/core/frame_data.d.ts.map +1 -1
- package/dist/phaser/core/game.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +8 -6
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts +40 -30
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts +3 -2
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_mspointer.d.ts +3 -2
- package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +6 -4
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts +3 -2
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts +4 -3
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/loader_parser.d.ts +9 -8
- package/dist/phaser/core/loader_parser.d.ts.map +1 -1
- package/dist/phaser/core/raf.d.ts +3 -2
- package/dist/phaser/core/raf.d.ts.map +1 -1
- package/dist/phaser/core/registry.d.ts +7 -0
- package/dist/phaser/core/registry.d.ts.map +1 -0
- package/dist/phaser/core/scale_manager.d.ts +1 -1
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene.d.ts +0 -1
- package/dist/phaser/core/scene.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts +1 -1
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts +0 -1
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/signal_binding.d.ts +4 -3
- package/dist/phaser/core/signal_binding.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts +6 -4
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +3 -2
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/sound_sprite.d.ts +5 -4
- package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
- package/dist/phaser/core/stage.d.ts +3 -2
- package/dist/phaser/core/stage.d.ts.map +1 -1
- package/dist/phaser/core/time.d.ts +1 -1
- package/dist/phaser/core/time.d.ts.map +1 -1
- package/dist/phaser/core/timer.d.ts +1 -1
- package/dist/phaser/core/timer.d.ts.map +1 -1
- package/dist/phaser/core/timer_event.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts +10 -7
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +3 -2
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_easing.d.ts.map +1 -1
- package/dist/phaser/core/tween_manager.d.ts +3 -2
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/core/world.d.ts +3 -2
- package/dist/phaser/core/world.d.ts.map +1 -1
- package/dist/phaser/display/bitmap_text.d.ts +3 -2
- package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
- package/dist/phaser/display/button.d.ts +3 -2
- package/dist/phaser/display/button.d.ts.map +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/graphics.d.ts +7 -6
- package/dist/phaser/display/canvas/graphics.d.ts.map +1 -1
- package/dist/phaser/display/canvas/pool.d.ts +2 -2
- package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
- package/dist/phaser/display/canvas/renderer.d.ts +10 -8
- package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/tinter.d.ts +3 -2
- package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
- package/dist/phaser/display/canvas/util.d.ts +2 -2
- package/dist/phaser/display/canvas/util.d.ts.map +1 -1
- package/dist/phaser/display/display_object.d.ts +14 -12
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- package/dist/phaser/display/graphics.d.ts +8 -5
- package/dist/phaser/display/graphics.d.ts.map +1 -1
- package/dist/phaser/display/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/graphics_data_util.d.ts.map +1 -1
- package/dist/phaser/display/group.d.ts +4 -3
- package/dist/phaser/display/group.d.ts.map +1 -1
- package/dist/phaser/display/image.d.ts +13 -10
- package/dist/phaser/display/image.d.ts.map +1 -1
- package/dist/phaser/display/sprite_batch.d.ts +3 -2
- package/dist/phaser/display/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/sprite_util.d.ts +18 -15
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- package/dist/phaser/display/text.d.ts +11 -9
- package/dist/phaser/display/text.d.ts.map +1 -1
- package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
- package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts +0 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut_node.d.ts.map +1 -1
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +4 -3
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts +2 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts +2 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +7 -6
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts +2 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts +4 -2
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts +16 -11
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/complex.d.ts +16 -6
- package/dist/phaser/display/webgl/shader/complex.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/fast.d.ts +19 -7
- package/dist/phaser/display/webgl/shader/fast.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts +33 -12
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/primitive.d.ts +15 -6
- package/dist/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/strip.d.ts +15 -6
- package/dist/phaser/display/webgl/shader/strip.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader_manager.d.ts +16 -11
- package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts +29 -20
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts +12 -10
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts +3 -2
- package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/dist/phaser/display/webgl/util.d.ts.map +1 -1
- package/dist/phaser/geom/circle.d.ts +4 -1
- package/dist/phaser/geom/circle.d.ts.map +1 -1
- package/dist/phaser/geom/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/line.d.ts +1 -1
- package/dist/phaser/geom/line.d.ts.map +1 -1
- package/dist/phaser/geom/matrix.d.ts.map +1 -1
- package/dist/phaser/geom/point.d.ts.map +1 -1
- package/dist/phaser/geom/polygon.d.ts.map +1 -1
- package/dist/phaser/geom/rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/rounded_rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/util/circle.d.ts.map +1 -1
- package/dist/phaser/geom/util/ellipse.d.ts +3 -2
- package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/util/line.d.ts.map +1 -1
- package/dist/phaser/geom/util/matrix.d.ts +2 -2
- package/dist/phaser/geom/util/matrix.d.ts.map +1 -1
- package/dist/phaser/geom/util/point.d.ts.map +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
- package/dist/phaser/util/math.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/phaser/core/animation.ts +64 -60
- package/src/phaser/core/animation_manager.ts +50 -53
- package/src/phaser/core/animation_parser.ts +9 -9
- package/src/phaser/core/array_set.ts +16 -17
- package/src/phaser/core/cache.ts +92 -93
- package/src/phaser/core/const.ts +1 -1
- package/src/phaser/core/device.ts +24 -29
- package/src/phaser/core/device_util.ts +22 -26
- package/src/phaser/core/dom.ts +54 -65
- package/src/phaser/core/event_manager.ts +64 -94
- package/src/phaser/core/factory.ts +14 -14
- package/src/phaser/core/frame.ts +28 -28
- package/src/phaser/core/frame_data.test.ts +100 -0
- package/src/phaser/core/frame_data.ts +24 -24
- package/src/phaser/core/frame_util.ts +2 -2
- package/src/phaser/core/game.ts +47 -48
- package/src/phaser/core/input.ts +104 -110
- package/src/phaser/core/input_handler.test.ts +113 -0
- package/src/phaser/core/input_handler.ts +199 -218
- package/src/phaser/core/input_mouse.ts +71 -54
- package/src/phaser/core/input_mspointer.ts +52 -39
- package/src/phaser/core/input_pointer.ts +81 -80
- package/src/phaser/core/input_touch.ts +49 -36
- package/src/phaser/core/loader.ts +173 -152
- package/src/phaser/core/loader_parser.ts +39 -57
- package/src/phaser/core/raf.ts +8 -7
- package/src/phaser/core/registry.test.ts +31 -0
- package/src/phaser/core/registry.ts +9 -0
- package/src/phaser/core/scale_manager.ts +156 -152
- package/src/phaser/core/scene.ts +9 -13
- package/src/phaser/core/scene_manager.ts +47 -47
- package/src/phaser/core/signal.test.ts +4 -4
- package/src/phaser/core/signal.ts +41 -52
- package/src/phaser/core/signal_binding.ts +26 -25
- package/src/phaser/core/signal_dispatch.test.ts +180 -0
- package/src/phaser/core/sound.ts +75 -83
- package/src/phaser/core/sound_manager.ts +52 -51
- package/src/phaser/core/sound_sprite.ts +17 -16
- package/src/phaser/core/stage.ts +25 -24
- package/src/phaser/core/time.ts +52 -52
- package/src/phaser/core/timer.test.ts +187 -0
- package/src/phaser/core/timer.ts +82 -69
- package/src/phaser/core/timer_event.ts +10 -10
- package/src/phaser/core/tween.ts +90 -93
- package/src/phaser/core/tween_data.ts +45 -51
- package/src/phaser/core/tween_easing.test.ts +106 -0
- package/src/phaser/core/tween_easing.ts +151 -123
- package/src/phaser/core/tween_manager.ts +19 -18
- package/src/phaser/core/world.ts +4 -3
- package/src/phaser/display/bitmap_text.ts +56 -64
- package/src/phaser/display/button.ts +33 -32
- package/src/phaser/display/canvas/buffer.ts +8 -8
- package/src/phaser/display/canvas/graphics.ts +36 -37
- package/src/phaser/display/canvas/masker.ts +2 -2
- package/src/phaser/display/canvas/pool.test.ts +106 -0
- package/src/phaser/display/canvas/pool.ts +25 -27
- package/src/phaser/display/canvas/renderer.ts +32 -31
- package/src/phaser/display/canvas/tinter.ts +25 -25
- package/src/phaser/display/canvas/util.ts +7 -10
- package/src/phaser/display/display_object.ts +114 -118
- package/src/phaser/display/graphics.ts +121 -119
- package/src/phaser/display/graphics_data.ts +12 -12
- package/src/phaser/display/graphics_data_util.ts +2 -3
- package/src/phaser/display/group.ts +50 -57
- package/src/phaser/display/image.ts +55 -52
- package/src/phaser/display/sprite_batch.ts +3 -2
- package/src/phaser/display/sprite_util.ts +48 -54
- package/src/phaser/display/text.ts +199 -204
- package/src/phaser/display/webgl/abstract_filter.ts +9 -9
- package/src/phaser/display/webgl/base_texture.ts +21 -24
- package/src/phaser/display/webgl/blend_manager.ts +6 -10
- package/src/phaser/display/webgl/earcut.ts +73 -37
- package/src/phaser/display/webgl/earcut_node.ts +10 -10
- package/src/phaser/display/webgl/fast_sprite_batch.ts +34 -34
- package/src/phaser/display/webgl/filter_manager.ts +13 -12
- package/src/phaser/display/webgl/filter_texture.ts +14 -13
- package/src/phaser/display/webgl/graphics.ts +51 -57
- package/src/phaser/display/webgl/graphics_data.ts +15 -14
- package/src/phaser/display/webgl/mask_manager.ts +2 -2
- package/src/phaser/display/webgl/render_texture.ts +26 -25
- package/src/phaser/display/webgl/renderer.ts +57 -62
- package/src/phaser/display/webgl/shader/complex.ts +28 -12
- package/src/phaser/display/webgl/shader/fast.ts +30 -12
- package/src/phaser/display/webgl/shader/normal.ts +70 -57
- package/src/phaser/display/webgl/shader/primitive.ts +26 -11
- package/src/phaser/display/webgl/shader/shader.test.ts +148 -0
- package/src/phaser/display/webgl/shader/strip.ts +27 -12
- package/src/phaser/display/webgl/shader_manager.test.ts +124 -0
- package/src/phaser/display/webgl/shader_manager.ts +26 -34
- package/src/phaser/display/webgl/sprite_batch.ts +67 -61
- package/src/phaser/display/webgl/stencil_manager.ts +23 -34
- package/src/phaser/display/webgl/texture.ts +43 -50
- package/src/phaser/display/webgl/texture_util.ts +2 -3
- package/src/phaser/display/webgl/util.ts +26 -25
- package/src/phaser/geom/circle.test.ts +2 -3
- package/src/phaser/geom/circle.ts +36 -36
- package/src/phaser/geom/ellipse.test.ts +73 -71
- package/src/phaser/geom/ellipse.ts +14 -14
- package/src/phaser/geom/line.test.ts +5 -5
- package/src/phaser/geom/line.ts +35 -35
- package/src/phaser/geom/matrix.test.ts +1 -1
- package/src/phaser/geom/matrix.ts +27 -27
- package/src/phaser/geom/point.test.ts +1 -2
- package/src/phaser/geom/point.ts +35 -35
- package/src/phaser/geom/polygon.test.ts +82 -0
- package/src/phaser/geom/polygon.ts +16 -16
- package/src/phaser/geom/rectangle.test.ts +14 -14
- package/src/phaser/geom/rectangle.ts +83 -75
- package/src/phaser/geom/rounded_rectangle.test.ts +1 -7
- package/src/phaser/geom/rounded_rectangle.ts +9 -9
- package/src/phaser/geom/util/circle.test.ts +25 -23
- package/src/phaser/geom/util/circle.ts +9 -18
- package/src/phaser/geom/util/ellipse.test.ts +7 -5
- package/src/phaser/geom/util/ellipse.ts +3 -2
- package/src/phaser/geom/util/line.test.ts +10 -8
- package/src/phaser/geom/util/line.ts +6 -16
- package/src/phaser/geom/util/matrix.test.ts +20 -18
- package/src/phaser/geom/util/matrix.ts +8 -15
- package/src/phaser/geom/util/point.test.ts +8 -6
- package/src/phaser/geom/util/point.ts +24 -28
- package/src/phaser/geom/util/polygon.test.ts +12 -10
- package/src/phaser/geom/util/polygon.ts +2 -2
- package/src/phaser/geom/util/rectangle.test.ts +10 -8
- package/src/phaser/geom/util/rectangle.ts +18 -37
- package/src/phaser/geom/util/rounded_rectangle.test.ts +11 -9
- package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
- package/src/phaser/util/math.test.ts +11 -11
- package/src/phaser/util/math.ts +29 -46
|
@@ -25,11 +25,11 @@ import {
|
|
|
25
25
|
} from '../core/const.js';
|
|
26
26
|
|
|
27
27
|
export class Rectangle {
|
|
28
|
-
x: number;
|
|
29
|
-
y: number;
|
|
30
|
-
width: number;
|
|
31
|
-
height: number;
|
|
32
|
-
type: number;
|
|
28
|
+
public x: number;
|
|
29
|
+
public y: number;
|
|
30
|
+
public width: number;
|
|
31
|
+
public height: number;
|
|
32
|
+
public type: number;
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Creates a new Rectangle instance.
|
|
@@ -38,7 +38,7 @@ export class Rectangle {
|
|
|
38
38
|
* @param {number} width - The width of the rectangle (default: 0).
|
|
39
39
|
* @param {number} height - The height of the rectangle (default: 0).
|
|
40
40
|
*/
|
|
41
|
-
constructor(x
|
|
41
|
+
public constructor(x = 0, y = 0, width = 0, height = 0) {
|
|
42
42
|
/** @type {number} */
|
|
43
43
|
this.x = x;
|
|
44
44
|
/** @type {number} */
|
|
@@ -57,7 +57,7 @@ export class Rectangle {
|
|
|
57
57
|
* @param {number} dy - The amount to offset the y coordinate by.
|
|
58
58
|
* @returns {Rectangle} This rectangle instance for chaining.
|
|
59
59
|
*/
|
|
60
|
-
offset(dx: number, dy: number) {
|
|
60
|
+
public offset(dx: number, dy: number) {
|
|
61
61
|
this.x += dx;
|
|
62
62
|
this.y += dy;
|
|
63
63
|
return this;
|
|
@@ -68,7 +68,7 @@ export class Rectangle {
|
|
|
68
68
|
* @param {Point} point - The point to offset the rectangle by.
|
|
69
69
|
* @returns {Rectangle} This rectangle instance for chaining.
|
|
70
70
|
*/
|
|
71
|
-
offsetPoint(point: Point) {
|
|
71
|
+
public offsetPoint(point: Point) {
|
|
72
72
|
return this.offset(point.x, point.y);
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -80,7 +80,7 @@ export class Rectangle {
|
|
|
80
80
|
* @param {number} height - The new height of the rectangle.
|
|
81
81
|
* @returns {Rectangle} This rectangle instance for chaining.
|
|
82
82
|
*/
|
|
83
|
-
setTo(x: number, y: number, width: number, height: number) {
|
|
83
|
+
public setTo(x: number, y: number, width: number, height: number) {
|
|
84
84
|
this.x = x;
|
|
85
85
|
this.y = y;
|
|
86
86
|
this.width = width;
|
|
@@ -94,10 +94,8 @@ export class Rectangle {
|
|
|
94
94
|
* @param {number} y - The amount to scale the height by (default: x).
|
|
95
95
|
* @returns {Rectangle} This rectangle instance for chaining.
|
|
96
96
|
*/
|
|
97
|
-
scale(x: number, y?: number) {
|
|
98
|
-
|
|
99
|
-
y = x;
|
|
100
|
-
}
|
|
97
|
+
public scale(x: number, y?: number) {
|
|
98
|
+
y ??= x;
|
|
101
99
|
this.width *= x;
|
|
102
100
|
this.height *= y;
|
|
103
101
|
return this;
|
|
@@ -109,7 +107,7 @@ export class Rectangle {
|
|
|
109
107
|
* @param {number} y - The y coordinate to center the rectangle on.
|
|
110
108
|
* @returns {Rectangle} This rectangle instance for chaining.
|
|
111
109
|
*/
|
|
112
|
-
centerOn(x: number, y: number) {
|
|
110
|
+
public centerOn(x: number, y: number) {
|
|
113
111
|
this.centerX = x;
|
|
114
112
|
this.centerY = y;
|
|
115
113
|
return this;
|
|
@@ -118,7 +116,7 @@ export class Rectangle {
|
|
|
118
116
|
/**
|
|
119
117
|
* Floors the x and y coordinates of the rectangle (rounds down to nearest integer).
|
|
120
118
|
*/
|
|
121
|
-
floor() {
|
|
119
|
+
public floor() {
|
|
122
120
|
this.x = Math.floor(this.x);
|
|
123
121
|
this.y = Math.floor(this.y);
|
|
124
122
|
}
|
|
@@ -126,7 +124,7 @@ export class Rectangle {
|
|
|
126
124
|
/**
|
|
127
125
|
* Floors all coordinates of the rectangle (rounds down to nearest integer).
|
|
128
126
|
*/
|
|
129
|
-
floorAll() {
|
|
127
|
+
public floorAll() {
|
|
130
128
|
this.x = Math.floor(this.x);
|
|
131
129
|
this.y = Math.floor(this.y);
|
|
132
130
|
this.width = Math.floor(this.width);
|
|
@@ -136,7 +134,7 @@ export class Rectangle {
|
|
|
136
134
|
/**
|
|
137
135
|
* Ceils the x and y coordinates of the rectangle (rounds up to nearest integer).
|
|
138
136
|
*/
|
|
139
|
-
ceil() {
|
|
137
|
+
public ceil() {
|
|
140
138
|
this.x = Math.ceil(this.x);
|
|
141
139
|
this.y = Math.ceil(this.y);
|
|
142
140
|
}
|
|
@@ -144,7 +142,7 @@ export class Rectangle {
|
|
|
144
142
|
/**
|
|
145
143
|
* Ceils all coordinates of the rectangle (rounds up to nearest integer).
|
|
146
144
|
*/
|
|
147
|
-
ceilAll() {
|
|
145
|
+
public ceilAll() {
|
|
148
146
|
this.x = Math.ceil(this.x);
|
|
149
147
|
this.y = Math.ceil(this.y);
|
|
150
148
|
this.width = Math.ceil(this.width);
|
|
@@ -156,7 +154,7 @@ export class Rectangle {
|
|
|
156
154
|
* @param {Rectangle} source - The rectangle to copy values from.
|
|
157
155
|
* @returns {Rectangle} This rectangle instance for chaining.
|
|
158
156
|
*/
|
|
159
|
-
copyFrom(source: Rectangle) {
|
|
157
|
+
public copyFrom(source: Rectangle) {
|
|
160
158
|
return this.setTo(source.x, source.y, source.width, source.height);
|
|
161
159
|
}
|
|
162
160
|
|
|
@@ -165,7 +163,7 @@ export class Rectangle {
|
|
|
165
163
|
* @param {Rectangle} dest - The rectangle to copy values to.
|
|
166
164
|
* @returns {Rectangle} The destination rectangle.
|
|
167
165
|
*/
|
|
168
|
-
copyTo(dest: Rectangle) {
|
|
166
|
+
public copyTo(dest: Rectangle) {
|
|
169
167
|
dest.x = this.x;
|
|
170
168
|
dest.y = this.y;
|
|
171
169
|
dest.width = this.width;
|
|
@@ -179,7 +177,7 @@ export class Rectangle {
|
|
|
179
177
|
* @param {number} dy - The amount to increase the height by.
|
|
180
178
|
* @returns {Rectangle} This rectangle instance for chaining.
|
|
181
179
|
*/
|
|
182
|
-
inflate(dx: number, dy: number) {
|
|
180
|
+
public inflate(dx: number, dy: number) {
|
|
183
181
|
return inflate(this, dx, dy);
|
|
184
182
|
}
|
|
185
183
|
|
|
@@ -188,7 +186,7 @@ export class Rectangle {
|
|
|
188
186
|
* @param {Point} output - The point to store the size in (optional).
|
|
189
187
|
* @returns {Point} The size of the rectangle as a point.
|
|
190
188
|
*/
|
|
191
|
-
size(output: Point) {
|
|
189
|
+
public size(output: Point) {
|
|
192
190
|
return size(this, output);
|
|
193
191
|
}
|
|
194
192
|
|
|
@@ -198,7 +196,7 @@ export class Rectangle {
|
|
|
198
196
|
* @param {number} height - The new height of the rectangle.
|
|
199
197
|
* @returns {Rectangle} This rectangle instance for chaining.
|
|
200
198
|
*/
|
|
201
|
-
resize(width: number, height: number) {
|
|
199
|
+
public resize(width: number, height: number) {
|
|
202
200
|
this.width = width;
|
|
203
201
|
this.height = height;
|
|
204
202
|
return this;
|
|
@@ -209,7 +207,7 @@ export class Rectangle {
|
|
|
209
207
|
* @param {Rectangle} output - The rectangle to store the clone in (optional).
|
|
210
208
|
* @returns {Rectangle} A new rectangle with the same values as this one.
|
|
211
209
|
*/
|
|
212
|
-
clone(output?: Rectangle) {
|
|
210
|
+
public clone(output?: Rectangle) {
|
|
213
211
|
return clone(this, output);
|
|
214
212
|
}
|
|
215
213
|
|
|
@@ -219,7 +217,7 @@ export class Rectangle {
|
|
|
219
217
|
* @param {number} y - The y coordinate of the point to check.
|
|
220
218
|
* @returns {boolean} True if the point is contained within this rectangle, false otherwise.
|
|
221
219
|
*/
|
|
222
|
-
contains(x: number, y: number) {
|
|
220
|
+
public contains(x: number, y: number) {
|
|
223
221
|
return contains(this, x, y);
|
|
224
222
|
}
|
|
225
223
|
|
|
@@ -228,7 +226,7 @@ export class Rectangle {
|
|
|
228
226
|
* @param {Rectangle} b - The rectangle to check if it's contained.
|
|
229
227
|
* @returns {boolean} True if the rectangle is contained within this rectangle, false otherwise.
|
|
230
228
|
*/
|
|
231
|
-
containsRect(b: Rectangle) {
|
|
229
|
+
public containsRect(b: Rectangle) {
|
|
232
230
|
return containsRect(b, this);
|
|
233
231
|
}
|
|
234
232
|
|
|
@@ -237,7 +235,7 @@ export class Rectangle {
|
|
|
237
235
|
* @param {Rectangle} b - The rectangle to compare with.
|
|
238
236
|
* @returns {boolean} True if the rectangles have the same values, false otherwise.
|
|
239
237
|
*/
|
|
240
|
-
equals(b: Rectangle) {
|
|
238
|
+
public equals(b: Rectangle) {
|
|
241
239
|
return equals(this, b);
|
|
242
240
|
}
|
|
243
241
|
|
|
@@ -247,7 +245,7 @@ export class Rectangle {
|
|
|
247
245
|
* @param {Rectangle} out - The rectangle to store the result in (optional).
|
|
248
246
|
* @returns {Rectangle} The intersection of the two rectangles.
|
|
249
247
|
*/
|
|
250
|
-
intersection(b: Rectangle, out?: Rectangle) {
|
|
248
|
+
public intersection(b: Rectangle, out?: Rectangle) {
|
|
251
249
|
return intersection(this, b, out);
|
|
252
250
|
}
|
|
253
251
|
|
|
@@ -256,7 +254,7 @@ export class Rectangle {
|
|
|
256
254
|
* @param {Rectangle} b - The rectangle to check for intersection with.
|
|
257
255
|
* @returns {boolean} True if the rectangles intersect, false otherwise.
|
|
258
256
|
*/
|
|
259
|
-
intersects(b: Rectangle) {
|
|
257
|
+
public intersects(b: Rectangle) {
|
|
260
258
|
return intersects(this, b);
|
|
261
259
|
}
|
|
262
260
|
|
|
@@ -269,7 +267,7 @@ export class Rectangle {
|
|
|
269
267
|
* @param {number} tolerance - A tolerance value to use when checking (default: 0).
|
|
270
268
|
* @returns {boolean} True if the rectangle intersects with the bounds, false otherwise.
|
|
271
269
|
*/
|
|
272
|
-
intersectsRaw(left: number, right: number, top: number, bottom: number, tolerance: number) {
|
|
270
|
+
public intersectsRaw(left: number, right: number, top: number, bottom: number, tolerance: number) {
|
|
273
271
|
return intersectsRaw(this, left, right, top, bottom, tolerance);
|
|
274
272
|
}
|
|
275
273
|
|
|
@@ -279,7 +277,7 @@ export class Rectangle {
|
|
|
279
277
|
* @param {Rectangle} out - The rectangle to store the result in (optional).
|
|
280
278
|
* @returns {Rectangle} The union of the two rectangles.
|
|
281
279
|
*/
|
|
282
|
-
union(b: Rectangle, out?: Rectangle) {
|
|
280
|
+
public union(b: Rectangle, out?: Rectangle) {
|
|
283
281
|
return union(this, b, out);
|
|
284
282
|
}
|
|
285
283
|
|
|
@@ -288,8 +286,8 @@ export class Rectangle {
|
|
|
288
286
|
* @param {Point} output - The point to store the result in (optional).
|
|
289
287
|
* @returns {Point} A random point within this rectangle.
|
|
290
288
|
*/
|
|
291
|
-
random(output: Point | null = null) {
|
|
292
|
-
const result = output
|
|
289
|
+
public random(output: Point | null = null) {
|
|
290
|
+
const result = output ?? new Point();
|
|
293
291
|
result.x = this.randomX;
|
|
294
292
|
result.y = this.randomY;
|
|
295
293
|
return result;
|
|
@@ -301,29 +299,39 @@ export class Rectangle {
|
|
|
301
299
|
* @param {Point} output - The point to store the result in (optional).
|
|
302
300
|
* @returns {Point} A point at the specified position on the rectangle.
|
|
303
301
|
*/
|
|
304
|
-
getPoint(position: number, output: Point | null = null) {
|
|
305
|
-
const result = output
|
|
302
|
+
public getPoint(position: number, output: Point | null = null) {
|
|
303
|
+
const result = output ?? new Point();
|
|
306
304
|
switch (position) {
|
|
307
|
-
case TOP_LEFT:
|
|
305
|
+
case TOP_LEFT: {
|
|
308
306
|
return result.setTo(this.x, this.y);
|
|
309
|
-
|
|
307
|
+
}
|
|
308
|
+
case TOP_CENTER: {
|
|
310
309
|
return result.setTo(this.centerX, this.y);
|
|
311
|
-
|
|
310
|
+
}
|
|
311
|
+
case TOP_RIGHT: {
|
|
312
312
|
return result.setTo(this.right, this.y);
|
|
313
|
-
|
|
313
|
+
}
|
|
314
|
+
case LEFT_CENTER: {
|
|
314
315
|
return result.setTo(this.x, this.centerY);
|
|
315
|
-
|
|
316
|
+
}
|
|
317
|
+
case CENTER: {
|
|
316
318
|
return result.setTo(this.centerX, this.centerY);
|
|
317
|
-
|
|
319
|
+
}
|
|
320
|
+
case RIGHT_CENTER: {
|
|
318
321
|
return result.setTo(this.right, this.centerY);
|
|
319
|
-
|
|
322
|
+
}
|
|
323
|
+
case BOTTOM_LEFT: {
|
|
320
324
|
return result.setTo(this.x, this.bottom);
|
|
321
|
-
|
|
325
|
+
}
|
|
326
|
+
case BOTTOM_CENTER: {
|
|
322
327
|
return result.setTo(this.centerX, this.bottom);
|
|
323
|
-
|
|
328
|
+
}
|
|
329
|
+
case BOTTOM_RIGHT: {
|
|
324
330
|
return result.setTo(this.right, this.bottom);
|
|
325
|
-
|
|
331
|
+
}
|
|
332
|
+
default: {
|
|
326
333
|
return result.setTo(this.x, this.y);
|
|
334
|
+
}
|
|
327
335
|
}
|
|
328
336
|
}
|
|
329
337
|
|
|
@@ -331,7 +339,7 @@ export class Rectangle {
|
|
|
331
339
|
* Returns a string representation of this rectangle.
|
|
332
340
|
* @returns {string} A string representation of the rectangle.
|
|
333
341
|
*/
|
|
334
|
-
toString() {
|
|
342
|
+
public toString() {
|
|
335
343
|
return `[{Rectangle (x=${this.x} y=${this.y} width=${this.width} height=${this.height} empty=${this.empty})}]`;
|
|
336
344
|
}
|
|
337
345
|
|
|
@@ -339,7 +347,7 @@ export class Rectangle {
|
|
|
339
347
|
* Gets half the width of this rectangle.
|
|
340
348
|
* @returns {number} Half the width of this rectangle.
|
|
341
349
|
*/
|
|
342
|
-
get halfWidth() {
|
|
350
|
+
public get halfWidth() {
|
|
343
351
|
return Math.round(this.width / 2);
|
|
344
352
|
}
|
|
345
353
|
|
|
@@ -347,7 +355,7 @@ export class Rectangle {
|
|
|
347
355
|
* Gets half the height of this rectangle.
|
|
348
356
|
* @returns {number} Half the height of this rectangle.
|
|
349
357
|
*/
|
|
350
|
-
get halfHeight() {
|
|
358
|
+
public get halfHeight() {
|
|
351
359
|
return Math.round(this.height / 2);
|
|
352
360
|
}
|
|
353
361
|
|
|
@@ -355,14 +363,14 @@ export class Rectangle {
|
|
|
355
363
|
* Gets the top coordinate of this rectangle.
|
|
356
364
|
* @returns {number} The top coordinate of this rectangle.
|
|
357
365
|
*/
|
|
358
|
-
get top() {
|
|
366
|
+
public get top() {
|
|
359
367
|
return this.y;
|
|
360
368
|
}
|
|
361
369
|
|
|
362
370
|
/**
|
|
363
371
|
* Sets the top coordinate of this rectangle.
|
|
364
372
|
*/
|
|
365
|
-
set top(value) {
|
|
373
|
+
public set top(value) {
|
|
366
374
|
if (value >= this.bottom) {
|
|
367
375
|
this.height = 0;
|
|
368
376
|
this.y = value;
|
|
@@ -375,14 +383,14 @@ export class Rectangle {
|
|
|
375
383
|
* Gets the top-left point of this rectangle.
|
|
376
384
|
* @returns {Point} The top-left point of this rectangle.
|
|
377
385
|
*/
|
|
378
|
-
get topLeft() {
|
|
386
|
+
public get topLeft() {
|
|
379
387
|
return new Point(this.x, this.y);
|
|
380
388
|
}
|
|
381
389
|
|
|
382
390
|
/**
|
|
383
391
|
* Sets the top-left point of this rectangle.
|
|
384
392
|
*/
|
|
385
|
-
set topLeft(value) {
|
|
393
|
+
public set topLeft(value) {
|
|
386
394
|
this.x = value.x;
|
|
387
395
|
this.y = value.y;
|
|
388
396
|
}
|
|
@@ -391,14 +399,14 @@ export class Rectangle {
|
|
|
391
399
|
* Gets the top-right point of this rectangle.
|
|
392
400
|
* @returns {Point} The top-right point of this rectangle.
|
|
393
401
|
*/
|
|
394
|
-
get topRight() {
|
|
402
|
+
public get topRight() {
|
|
395
403
|
return new Point(this.x + this.width, this.y);
|
|
396
404
|
}
|
|
397
405
|
|
|
398
406
|
/**
|
|
399
407
|
* Sets the top-right point of this rectangle.
|
|
400
408
|
*/
|
|
401
|
-
set topRight(value) {
|
|
409
|
+
public set topRight(value) {
|
|
402
410
|
this.right = value.x;
|
|
403
411
|
this.y = value.y;
|
|
404
412
|
}
|
|
@@ -407,14 +415,14 @@ export class Rectangle {
|
|
|
407
415
|
* Gets the bottom coordinate of this rectangle.
|
|
408
416
|
* @returns {number} The bottom coordinate of this rectangle.
|
|
409
417
|
*/
|
|
410
|
-
get bottom() {
|
|
418
|
+
public get bottom() {
|
|
411
419
|
return this.y + this.height;
|
|
412
420
|
}
|
|
413
421
|
|
|
414
422
|
/**
|
|
415
423
|
* Sets the bottom coordinate of this rectangle.
|
|
416
424
|
*/
|
|
417
|
-
set bottom(value) {
|
|
425
|
+
public set bottom(value) {
|
|
418
426
|
if (value <= this.y) {
|
|
419
427
|
this.height = 0;
|
|
420
428
|
} else {
|
|
@@ -426,14 +434,14 @@ export class Rectangle {
|
|
|
426
434
|
* Gets the bottom-left point of this rectangle.
|
|
427
435
|
* @returns {Point} The bottom-left point of this rectangle.
|
|
428
436
|
*/
|
|
429
|
-
get bottomLeft() {
|
|
437
|
+
public get bottomLeft() {
|
|
430
438
|
return new Point(this.x, this.bottom);
|
|
431
439
|
}
|
|
432
440
|
|
|
433
441
|
/**
|
|
434
442
|
* Sets the bottom-left point of this rectangle.
|
|
435
443
|
*/
|
|
436
|
-
set bottomLeft(value) {
|
|
444
|
+
public set bottomLeft(value) {
|
|
437
445
|
this.x = value.x;
|
|
438
446
|
this.bottom = value.y;
|
|
439
447
|
}
|
|
@@ -442,14 +450,14 @@ export class Rectangle {
|
|
|
442
450
|
* Gets the bottom-right point of this rectangle.
|
|
443
451
|
* @returns {Point} The bottom-right point of this rectangle.
|
|
444
452
|
*/
|
|
445
|
-
get bottomRight() {
|
|
453
|
+
public get bottomRight() {
|
|
446
454
|
return new Point(this.right, this.bottom);
|
|
447
455
|
}
|
|
448
456
|
|
|
449
457
|
/**
|
|
450
458
|
* Sets the bottom-right point of this rectangle.
|
|
451
459
|
*/
|
|
452
|
-
set bottomRight(value) {
|
|
460
|
+
public set bottomRight(value) {
|
|
453
461
|
this.right = value.x;
|
|
454
462
|
this.bottom = value.y;
|
|
455
463
|
}
|
|
@@ -458,14 +466,14 @@ export class Rectangle {
|
|
|
458
466
|
* Gets the left coordinate of this rectangle.
|
|
459
467
|
* @returns {number} The left coordinate of this rectangle.
|
|
460
468
|
*/
|
|
461
|
-
get left() {
|
|
469
|
+
public get left() {
|
|
462
470
|
return this.x;
|
|
463
471
|
}
|
|
464
472
|
|
|
465
473
|
/**
|
|
466
474
|
* Sets the left coordinate of this rectangle.
|
|
467
475
|
*/
|
|
468
|
-
set left(value) {
|
|
476
|
+
public set left(value) {
|
|
469
477
|
if (value >= this.right) {
|
|
470
478
|
this.width = 0;
|
|
471
479
|
} else {
|
|
@@ -478,14 +486,14 @@ export class Rectangle {
|
|
|
478
486
|
* Gets the right coordinate of this rectangle.
|
|
479
487
|
* @returns {number} The right coordinate of this rectangle.
|
|
480
488
|
*/
|
|
481
|
-
get right() {
|
|
489
|
+
public get right() {
|
|
482
490
|
return this.x + this.width;
|
|
483
491
|
}
|
|
484
492
|
|
|
485
493
|
/**
|
|
486
494
|
* Sets the right coordinate of this rectangle.
|
|
487
495
|
*/
|
|
488
|
-
set right(value) {
|
|
496
|
+
public set right(value) {
|
|
489
497
|
if (value <= this.x) {
|
|
490
498
|
this.width = 0;
|
|
491
499
|
} else {
|
|
@@ -497,7 +505,7 @@ export class Rectangle {
|
|
|
497
505
|
* Gets the volume (area) of this rectangle.
|
|
498
506
|
* @returns {number} The volume (area) of this rectangle.
|
|
499
507
|
*/
|
|
500
|
-
get volume() {
|
|
508
|
+
public get volume() {
|
|
501
509
|
return this.width * this.height;
|
|
502
510
|
}
|
|
503
511
|
|
|
@@ -505,7 +513,7 @@ export class Rectangle {
|
|
|
505
513
|
* Gets the perimeter of this rectangle.
|
|
506
514
|
* @returns {number} The perimeter of this rectangle.
|
|
507
515
|
*/
|
|
508
|
-
get perimeter() {
|
|
516
|
+
public get perimeter() {
|
|
509
517
|
return this.width * 2 + this.height * 2;
|
|
510
518
|
}
|
|
511
519
|
|
|
@@ -513,14 +521,14 @@ export class Rectangle {
|
|
|
513
521
|
* Gets the x coordinate of the center of this rectangle.
|
|
514
522
|
* @returns {number} The x coordinate of the center of this rectangle.
|
|
515
523
|
*/
|
|
516
|
-
get centerX() {
|
|
524
|
+
public get centerX() {
|
|
517
525
|
return this.x + this.halfWidth;
|
|
518
526
|
}
|
|
519
527
|
|
|
520
528
|
/**
|
|
521
529
|
* Sets the x coordinate of the center of this rectangle.
|
|
522
530
|
*/
|
|
523
|
-
set centerX(value) {
|
|
531
|
+
public set centerX(value) {
|
|
524
532
|
this.x = value - this.halfWidth;
|
|
525
533
|
}
|
|
526
534
|
|
|
@@ -528,14 +536,14 @@ export class Rectangle {
|
|
|
528
536
|
* Gets the y coordinate of the center of this rectangle.
|
|
529
537
|
* @returns {number} The y coordinate of the center of this rectangle.
|
|
530
538
|
*/
|
|
531
|
-
get centerY() {
|
|
539
|
+
public get centerY() {
|
|
532
540
|
return this.y + this.halfHeight;
|
|
533
541
|
}
|
|
534
542
|
|
|
535
543
|
/**
|
|
536
544
|
* Sets the y coordinate of the center of this rectangle.
|
|
537
545
|
*/
|
|
538
|
-
set centerY(value) {
|
|
546
|
+
public set centerY(value) {
|
|
539
547
|
this.y = value - this.halfHeight;
|
|
540
548
|
}
|
|
541
549
|
|
|
@@ -543,7 +551,7 @@ export class Rectangle {
|
|
|
543
551
|
* Gets a random x coordinate within this rectangle.
|
|
544
552
|
* @returns {number} A random x coordinate within this rectangle.
|
|
545
553
|
*/
|
|
546
|
-
get randomX() {
|
|
554
|
+
public get randomX() {
|
|
547
555
|
return this.x + Math.random() * this.width;
|
|
548
556
|
}
|
|
549
557
|
|
|
@@ -551,7 +559,7 @@ export class Rectangle {
|
|
|
551
559
|
* Gets a random y coordinate within this rectangle.
|
|
552
560
|
* @returns {number} A random y coordinate within this rectangle.
|
|
553
561
|
*/
|
|
554
|
-
get randomY() {
|
|
562
|
+
public get randomY() {
|
|
555
563
|
return this.y + Math.random() * this.height;
|
|
556
564
|
}
|
|
557
565
|
|
|
@@ -559,15 +567,15 @@ export class Rectangle {
|
|
|
559
567
|
* Checks if this rectangle is empty (has zero width or height).
|
|
560
568
|
* @returns {boolean} True if the rectangle is empty, false otherwise.
|
|
561
569
|
*/
|
|
562
|
-
get empty() {
|
|
570
|
+
public get empty() {
|
|
563
571
|
return !this.width || !this.height;
|
|
564
572
|
}
|
|
565
573
|
|
|
566
574
|
/**
|
|
567
575
|
* Sets whether this rectangle is empty (zero width or height).
|
|
568
576
|
*/
|
|
569
|
-
set empty(value) {
|
|
570
|
-
if (value
|
|
577
|
+
public set empty(value) {
|
|
578
|
+
if (value) {
|
|
571
579
|
this.setTo(0, 0, 0, 0);
|
|
572
580
|
}
|
|
573
581
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { expect } from 'vitest';
|
|
1
|
+
import { expect, describe, it } from 'vitest';
|
|
2
2
|
import { RoundedRectangle } from './rounded_rectangle.js';
|
|
3
3
|
|
|
4
4
|
describe('RoundedRectangle Constructor', () => {
|
|
@@ -20,16 +20,12 @@ describe('RoundedRectangle contains Method', () => {
|
|
|
20
20
|
const rectangle2 = new RoundedRectangle(10, 20, 30, 0, 5);
|
|
21
21
|
expect(rectangle2.contains(15, 25)).toBe(false);
|
|
22
22
|
});
|
|
23
|
-
});
|
|
24
23
|
|
|
25
|
-
describe('RoundedRectangle contains Method', () => {
|
|
26
24
|
it('should return true for a point inside the rectangle', () => {
|
|
27
25
|
const rectangle = new RoundedRectangle(10, 20, 30, 40, 5);
|
|
28
26
|
expect(rectangle.contains(15, 25)).toBe(true);
|
|
29
27
|
});
|
|
30
|
-
});
|
|
31
28
|
|
|
32
|
-
describe('RoundedRectangle contains Method', () => {
|
|
33
29
|
it("should return true for a point on the rectangle's edge", () => {
|
|
34
30
|
const rectangle = new RoundedRectangle(10, 20, 30, 40, 5);
|
|
35
31
|
expect(rectangle.contains(0, 25)).toBe(false);
|
|
@@ -37,9 +33,7 @@ describe('RoundedRectangle contains Method', () => {
|
|
|
37
33
|
expect(rectangle.contains(15, 0)).toBe(false);
|
|
38
34
|
expect(rectangle.contains(15, 40)).toBe(true);
|
|
39
35
|
});
|
|
40
|
-
});
|
|
41
36
|
|
|
42
|
-
describe('RoundedRectangle contains Method', () => {
|
|
43
37
|
it('should return false for a point outside the rectangle', () => {
|
|
44
38
|
const rectangle = new RoundedRectangle(10, 20, 30, 40, 5);
|
|
45
39
|
expect(rectangle.contains(-1, -1)).toBe(false);
|
|
@@ -2,12 +2,12 @@ import { clone } from './util/rounded_rectangle.js';
|
|
|
2
2
|
import { GEOM_ROUNDED_RECTANGLE } from '../core/const.js';
|
|
3
3
|
|
|
4
4
|
export class RoundedRectangle {
|
|
5
|
-
x: number;
|
|
6
|
-
y: number;
|
|
7
|
-
width: number;
|
|
8
|
-
height: number;
|
|
9
|
-
radius: number;
|
|
10
|
-
type: number;
|
|
5
|
+
public x: number;
|
|
6
|
+
public y: number;
|
|
7
|
+
public width: number;
|
|
8
|
+
public height: number;
|
|
9
|
+
public radius: number;
|
|
10
|
+
public type: number;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Creates a new RoundedRectangle instance.
|
|
@@ -17,7 +17,7 @@ export class RoundedRectangle {
|
|
|
17
17
|
* @param {number} height - The height of the rectangle (default: 0).
|
|
18
18
|
* @param {number} radius - The corner radius (default: 20).
|
|
19
19
|
*/
|
|
20
|
-
constructor(x
|
|
20
|
+
public constructor(x = 0, y = 0, width = 0, height = 0, radius = 20) {
|
|
21
21
|
this.x = x;
|
|
22
22
|
this.y = y;
|
|
23
23
|
this.width = width;
|
|
@@ -32,7 +32,7 @@ export class RoundedRectangle {
|
|
|
32
32
|
* @param {number} y - The y coordinate of the point to check.
|
|
33
33
|
* @returns {boolean} True if the point is contained within this rounded rectangle, false otherwise.
|
|
34
34
|
*/
|
|
35
|
-
contains(x: number, y: number) {
|
|
35
|
+
public contains(x: number, y: number) {
|
|
36
36
|
if (this.width <= 0 || this.height <= 0) {
|
|
37
37
|
return false;
|
|
38
38
|
}
|
|
@@ -48,7 +48,7 @@ export class RoundedRectangle {
|
|
|
48
48
|
* Creates a clone of this rounded rectangle.
|
|
49
49
|
* @returns {RoundedRectangle} A new rounded rectangle with the same values as this one.
|
|
50
50
|
*/
|
|
51
|
-
clone() {
|
|
51
|
+
public clone() {
|
|
52
52
|
return clone(this);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -1,30 +1,32 @@
|
|
|
1
|
-
import { expect } from 'vitest';
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { Circle } from '../circle.js';
|
|
3
3
|
import { clone, contains, equals, intersects } from './circle.js';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
describe('circle utils', () => {
|
|
6
|
+
it('should clone a circle', () => {
|
|
7
|
+
const circle1 = new Circle(0, 0, 10);
|
|
8
|
+
const circle2 = clone(circle1);
|
|
9
|
+
expect(circle1.x).toBe(circle2.x);
|
|
10
|
+
expect(circle1.y).toBe(circle2.y);
|
|
11
|
+
expect(circle1.radius).toBe(circle2.radius);
|
|
12
|
+
});
|
|
12
13
|
|
|
13
|
-
it('should contain a point in a circle', () => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
});
|
|
14
|
+
it('should contain a point in a circle', () => {
|
|
15
|
+
const circle = new Circle(5, 5, 10);
|
|
16
|
+
expect(contains(circle, 5, 5)).toBe(true);
|
|
17
|
+
});
|
|
17
18
|
|
|
18
|
-
it('should match two circles', () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
19
|
+
it('should match two circles', () => {
|
|
20
|
+
const circle1 = new Circle(5, 5, 10);
|
|
21
|
+
const circle2 = new Circle(5, 5, 10);
|
|
22
|
+
expect(equals(circle1, circle2)).toBe(true);
|
|
23
|
+
circle2.x = 0;
|
|
24
|
+
expect(equals(circle1, circle2)).toBe(false);
|
|
25
|
+
});
|
|
25
26
|
|
|
26
|
-
it('should intersects two circles', () => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
it('should intersects two circles', () => {
|
|
28
|
+
const circle1 = new Circle(5, 5, 10);
|
|
29
|
+
const circle2 = new Circle(5, 5, 5);
|
|
30
|
+
expect(intersects(circle1, circle2)).toBe(true);
|
|
31
|
+
});
|
|
30
32
|
});
|