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