mirror of
https://github.com/godotengine/godot.git
synced 2024-11-25 05:33:11 +00:00
Replace Rect2(i) has_no_area with has_area
This commit is contained in:
parent
817ae95667
commit
995b9f94e8
@ -2671,7 +2671,7 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2i &p_src_rect, const P
|
||||
Rect2i src_rect;
|
||||
Rect2i dest_rect;
|
||||
_get_clipped_src_and_dest_rects(p_src, p_src_rect, p_dest, src_rect, dest_rect);
|
||||
if (src_rect.has_no_area() || dest_rect.has_no_area()) {
|
||||
if (!src_rect.has_area() || !dest_rect.has_area()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2717,7 +2717,7 @@ void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, co
|
||||
Rect2i src_rect;
|
||||
Rect2i dest_rect;
|
||||
_get_clipped_src_and_dest_rects(p_src, p_src_rect, p_dest, src_rect, dest_rect);
|
||||
if (src_rect.has_no_area() || dest_rect.has_no_area()) {
|
||||
if (!src_rect.has_area() || !dest_rect.has_area()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2762,7 +2762,7 @@ void Image::blend_rect(const Ref<Image> &p_src, const Rect2i &p_src_rect, const
|
||||
Rect2i src_rect;
|
||||
Rect2i dest_rect;
|
||||
_get_clipped_src_and_dest_rects(p_src, p_src_rect, p_dest, src_rect, dest_rect);
|
||||
if (src_rect.has_no_area() || dest_rect.has_no_area()) {
|
||||
if (!src_rect.has_area() || !dest_rect.has_area()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2802,7 +2802,7 @@ void Image::blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, c
|
||||
Rect2i src_rect;
|
||||
Rect2i dest_rect;
|
||||
_get_clipped_src_and_dest_rects(p_src, p_src_rect, p_dest, src_rect, dest_rect);
|
||||
if (src_rect.has_no_area() || dest_rect.has_no_area()) {
|
||||
if (!src_rect.has_area() || !dest_rect.has_area()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2862,7 +2862,7 @@ void Image::fill_rect(const Rect2i &p_rect, const Color &p_color) {
|
||||
ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot fill rect in compressed or custom image formats.");
|
||||
|
||||
Rect2i r = Rect2i(0, 0, width, height).intersection(p_rect.abs());
|
||||
if (r.has_no_area()) {
|
||||
if (!r.has_area()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -140,8 +140,8 @@ struct _NO_DISCARD_ Rect2 {
|
||||
((p_rect.position.y + p_rect.size.y) <= (position.y + size.y));
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool has_no_area() const {
|
||||
return (size.x <= 0 || size.y <= 0);
|
||||
_FORCE_INLINE_ bool has_area() const {
|
||||
return size.x > 0.0f && size.y > 0.0f;
|
||||
}
|
||||
|
||||
// Returns the instersection between two Rect2s or an empty Rect2 if there is no intersection
|
||||
|
@ -83,8 +83,8 @@ struct _NO_DISCARD_ Rect2i {
|
||||
((p_rect.position.y + p_rect.size.y) <= (position.y + size.y));
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool has_no_area() const {
|
||||
return (size.x <= 0 || size.y <= 0);
|
||||
_FORCE_INLINE_ bool has_area() const {
|
||||
return size.x > 0 && size.y > 0;
|
||||
}
|
||||
|
||||
// Returns the instersection between two Rect2is or an empty Rect2i if there is no intersection
|
||||
|
@ -1650,7 +1650,7 @@ static void _register_variant_builtin_methods() {
|
||||
|
||||
bind_method(Rect2, get_center, sarray(), varray());
|
||||
bind_method(Rect2, get_area, sarray(), varray());
|
||||
bind_method(Rect2, has_no_area, sarray(), varray());
|
||||
bind_method(Rect2, has_area, sarray(), varray());
|
||||
bind_method(Rect2, has_point, sarray("point"), varray());
|
||||
bind_method(Rect2, is_equal_approx, sarray("rect"), varray());
|
||||
bind_method(Rect2, intersects, sarray("b", "include_borders"), varray(false));
|
||||
@ -1667,7 +1667,7 @@ static void _register_variant_builtin_methods() {
|
||||
|
||||
bind_method(Rect2i, get_center, sarray(), varray());
|
||||
bind_method(Rect2i, get_area, sarray(), varray());
|
||||
bind_method(Rect2i, has_no_area, sarray(), varray());
|
||||
bind_method(Rect2i, has_area, sarray(), varray());
|
||||
bind_method(Rect2i, has_point, sarray("point"), varray());
|
||||
bind_method(Rect2i, intersects, sarray("b"), varray());
|
||||
bind_method(Rect2i, encloses, sarray("b"), varray());
|
||||
|
@ -93,7 +93,7 @@
|
||||
<method name="get_area" qualifiers="const">
|
||||
<return type="float" />
|
||||
<description>
|
||||
Returns the area of the [Rect2]. See also [method has_no_area].
|
||||
Returns the area of the [Rect2]. See also [method has_area].
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_center" qualifiers="const">
|
||||
@ -127,11 +127,10 @@
|
||||
Returns a copy of the [Rect2] grown by the specified [param amount] on the specified [enum Side].
|
||||
</description>
|
||||
</method>
|
||||
<method name="has_no_area" qualifiers="const">
|
||||
<method name="has_area" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<description>
|
||||
Returns [code]true[/code] if the [Rect2] is flat or empty, [code]false[/code] otherwise. See also [method get_area].
|
||||
[b]Note:[/b] If the [Rect2] has a negative size and is not flat or empty, [method has_no_area] will return [code]true[/code].
|
||||
Returns [code]true[/code] if the [Rect2] has area, and [code]false[/code] if the [Rect2] is linear, empty, or has a negative [member size]. See also [method get_area].
|
||||
</description>
|
||||
</method>
|
||||
<method name="has_point" qualifiers="const">
|
||||
|
@ -90,7 +90,7 @@
|
||||
<method name="get_area" qualifiers="const">
|
||||
<return type="int" />
|
||||
<description>
|
||||
Returns the area of the [Rect2i]. See also [method has_no_area].
|
||||
Returns the area of the [Rect2i]. See also [method has_area].
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_center" qualifiers="const">
|
||||
@ -125,11 +125,10 @@
|
||||
Returns a copy of the [Rect2i] grown by the specified [param amount] on the specified [enum Side].
|
||||
</description>
|
||||
</method>
|
||||
<method name="has_no_area" qualifiers="const">
|
||||
<method name="has_area" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<description>
|
||||
Returns [code]true[/code] if the [Rect2i] is flat or empty, [code]false[/code] otherwise. See also [method get_area].
|
||||
[b]Note:[/b] If the [Rect2i] has a negative size and is not flat or empty, [method has_no_area] will return [code]true[/code].
|
||||
Returns [code]true[/code] if the [Rect2i] has area, and [code]false[/code] if the [Rect2i] is linear, empty, or has a negative [member size]. See also [method get_area].
|
||||
</description>
|
||||
</method>
|
||||
<method name="has_point" qualifiers="const">
|
||||
|
@ -1172,7 +1172,7 @@ HashMap<Vector2i, TileMapCell> TileMapEditorTilesPlugin::_draw_bucket_fill(Vecto
|
||||
TypedArray<Vector2i> to_check;
|
||||
if (source_cell.source_id == TileSet::INVALID_SOURCE) {
|
||||
Rect2i rect = tile_map->get_used_rect();
|
||||
if (rect.has_no_area()) {
|
||||
if (!rect.has_area()) {
|
||||
rect = Rect2i(p_coords, Vector2i(1, 1));
|
||||
}
|
||||
for (int x = boundaries.position.x; x < boundaries.get_end().x; x++) {
|
||||
@ -2558,7 +2558,7 @@ RBSet<Vector2i> TileMapEditorTerrainsPlugin::_get_cells_for_bucket_fill(Vector2i
|
||||
TypedArray<Vector2i> to_check;
|
||||
if (source_cell.source_id == TileSet::INVALID_SOURCE) {
|
||||
Rect2i rect = tile_map->get_used_rect();
|
||||
if (rect.has_no_area()) {
|
||||
if (!rect.has_area()) {
|
||||
rect = Rect2i(p_coords, Vector2i(1, 1));
|
||||
}
|
||||
for (int x = boundaries.position.x; x < boundaries.get_end().x; x++) {
|
||||
|
@ -1015,7 +1015,7 @@ Rect2i DisplayServerX11::screen_get_usable_rect(int p_screen) const {
|
||||
Rect2i left_rect(pos.x, pos.y + left_start_y, left, left_end_y - left_start_y);
|
||||
if (left_rect.size.x > 0) {
|
||||
Rect2i intersection = rect.intersection(left_rect);
|
||||
if (!intersection.has_no_area() && intersection.size.x < rect.size.x) {
|
||||
if (intersection.has_area() && intersection.size.x < rect.size.x) {
|
||||
rect.position.x = left_rect.size.x;
|
||||
rect.size.x = rect.size.x - intersection.size.x;
|
||||
}
|
||||
@ -1024,7 +1024,7 @@ Rect2i DisplayServerX11::screen_get_usable_rect(int p_screen) const {
|
||||
Rect2i right_rect(pos.x + size.x - right, pos.y + right_start_y, right, right_end_y - right_start_y);
|
||||
if (right_rect.size.x > 0) {
|
||||
Rect2i intersection = rect.intersection(right_rect);
|
||||
if (!intersection.has_no_area() && right_rect.size.x < rect.size.x) {
|
||||
if (intersection.has_area() && right_rect.size.x < rect.size.x) {
|
||||
rect.size.x = intersection.position.x - rect.position.x;
|
||||
}
|
||||
}
|
||||
@ -1032,7 +1032,7 @@ Rect2i DisplayServerX11::screen_get_usable_rect(int p_screen) const {
|
||||
Rect2i top_rect(pos.x + top_start_x, pos.y, top_end_x - top_start_x, top);
|
||||
if (top_rect.size.y > 0) {
|
||||
Rect2i intersection = rect.intersection(top_rect);
|
||||
if (!intersection.has_no_area() && intersection.size.y < rect.size.y) {
|
||||
if (intersection.has_area() && intersection.size.y < rect.size.y) {
|
||||
rect.position.y = top_rect.size.y;
|
||||
rect.size.y = rect.size.y - intersection.size.y;
|
||||
}
|
||||
@ -1041,7 +1041,7 @@ Rect2i DisplayServerX11::screen_get_usable_rect(int p_screen) const {
|
||||
Rect2i bottom_rect(pos.x + bottom_start_x, pos.y + size.y - bottom, bottom_end_x - bottom_start_x, bottom);
|
||||
if (bottom_rect.size.y > 0) {
|
||||
Rect2i intersection = rect.intersection(bottom_rect);
|
||||
if (!intersection.has_no_area() && right_rect.size.y < rect.size.y) {
|
||||
if (intersection.has_area() && right_rect.size.y < rect.size.y) {
|
||||
rect.size.y = intersection.position.y - rect.position.y;
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ bool TextureButton::has_point(const Point2 &p_point) const {
|
||||
Rect2 rect = Rect2();
|
||||
Size2 mask_size = click_mask->get_size();
|
||||
|
||||
if (_position_rect.has_no_area()) {
|
||||
if (!_position_rect.has_area()) {
|
||||
rect.size = mask_size;
|
||||
} else if (_tile) {
|
||||
// if the stretch mode is tile we offset the point to keep it inside the mask size
|
||||
|
@ -94,7 +94,7 @@ void TextureRect::_notification(int p_what) {
|
||||
|
||||
Ref<AtlasTexture> p_atlas = texture;
|
||||
|
||||
if (p_atlas.is_valid() && region.has_no_area()) {
|
||||
if (p_atlas.is_valid() && !region.has_area()) {
|
||||
Size2 scale_size(size.width / texture->get_width(), size.height / texture->get_height());
|
||||
|
||||
offset.width += hflip ? p_atlas->get_margin().get_position().width * scale_size.width * 2 : 0;
|
||||
@ -104,10 +104,10 @@ void TextureRect::_notification(int p_what) {
|
||||
size.width *= hflip ? -1.0f : 1.0f;
|
||||
size.height *= vflip ? -1.0f : 1.0f;
|
||||
|
||||
if (region.has_no_area()) {
|
||||
draw_texture_rect(texture, Rect2(offset, size), tile);
|
||||
} else {
|
||||
if (region.has_area()) {
|
||||
draw_texture_rect_region(texture, Rect2(offset, size), region);
|
||||
} else {
|
||||
draw_texture_rect(texture, Rect2(offset, size), tile);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
@ -118,17 +118,17 @@ TEST_CASE("[Rect2] Area getters") {
|
||||
"get_area() should return the expected value.");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
!Rect2(0, 100, 1280, 720).has_no_area(),
|
||||
"has_no_area() should return the expected value on Rect2 with an area.");
|
||||
Rect2(0, 100, 1280, 720).has_area(),
|
||||
"has_area() should return the expected value on Rect2 with an area.");
|
||||
CHECK_MESSAGE(
|
||||
Rect2(0, 100, 0, 500).has_no_area(),
|
||||
"has_no_area() should return the expected value on Rect2 with no area.");
|
||||
!Rect2(0, 100, 0, 500).has_area(),
|
||||
"has_area() should return the expected value on Rect2 with no area.");
|
||||
CHECK_MESSAGE(
|
||||
Rect2(0, 100, 500, 0).has_no_area(),
|
||||
"has_no_area() should return the expected value on Rect2 with no area.");
|
||||
!Rect2(0, 100, 500, 0).has_area(),
|
||||
"has_area() should return the expected value on Rect2 with no area.");
|
||||
CHECK_MESSAGE(
|
||||
Rect2(0, 100, 0, 0).has_no_area(),
|
||||
"has_no_area() should return the expected value on Rect2 with no area.");
|
||||
!Rect2(0, 100, 0, 0).has_area(),
|
||||
"has_area() should return the expected value on Rect2 with no area.");
|
||||
}
|
||||
|
||||
TEST_CASE("[Rect2] Absolute coordinates") {
|
||||
|
@ -118,17 +118,17 @@ TEST_CASE("[Rect2i] Area getters") {
|
||||
"get_area() should return the expected value.");
|
||||
|
||||
CHECK_MESSAGE(
|
||||
!Rect2i(0, 100, 1280, 720).has_no_area(),
|
||||
"has_no_area() should return the expected value on Rect2i with an area.");
|
||||
Rect2i(0, 100, 1280, 720).has_area(),
|
||||
"has_area() should return the expected value on Rect2i with an area.");
|
||||
CHECK_MESSAGE(
|
||||
Rect2i(0, 100, 0, 500).has_no_area(),
|
||||
"has_no_area() should return the expected value on Rect2i with no area.");
|
||||
!Rect2i(0, 100, 0, 500).has_area(),
|
||||
"has_area() should return the expected value on Rect2i with no area.");
|
||||
CHECK_MESSAGE(
|
||||
Rect2i(0, 100, 500, 0).has_no_area(),
|
||||
"has_no_area() should return the expected value on Rect2i with no area.");
|
||||
!Rect2i(0, 100, 500, 0).has_area(),
|
||||
"has_area() should return the expected value on Rect2i with no area.");
|
||||
CHECK_MESSAGE(
|
||||
Rect2i(0, 100, 0, 0).has_no_area(),
|
||||
"has_no_area() should return the expected value on Rect2i with no area.");
|
||||
!Rect2i(0, 100, 0, 0).has_area(),
|
||||
"has_area() should return the expected value on Rect2i with no area.");
|
||||
}
|
||||
|
||||
TEST_CASE("[Rect2i] Absolute coordinates") {
|
||||
|
Loading…
Reference in New Issue
Block a user