diff --git a/core/math/rect2.h b/core/math/rect2.h index e4ea615c22c..3b9660e2f07 100644 --- a/core/math/rect2.h +++ b/core/math/rect2.h @@ -47,28 +47,26 @@ struct Rect2 { real_t get_area() const { return size.width * size.height; } - inline bool intersects(const Rect2 &p_rect) const { - if (position.x >= (p_rect.position.x + p_rect.size.width)) - return false; - if ((position.x + size.width) <= p_rect.position.x) - return false; - if (position.y >= (p_rect.position.y + p_rect.size.height)) - return false; - if ((position.y + size.height) <= p_rect.position.y) - return false; - - return true; - } - - inline bool intersects_touch(const Rect2 &p_rect) const { - if (position.x > (p_rect.position.x + p_rect.size.width)) - return false; - if ((position.x + size.width) < p_rect.position.x) - return false; - if (position.y > (p_rect.position.y + p_rect.size.height)) - return false; - if ((position.y + size.height) < p_rect.position.y) - return false; + inline bool intersects(const Rect2 &p_rect, const bool p_include_borders = false) const { + if (p_include_borders) { + if (position.x > (p_rect.position.x + p_rect.size.width)) + return false; + if ((position.x + size.width) < p_rect.position.x) + return false; + if (position.y > (p_rect.position.y + p_rect.size.height)) + return false; + if ((position.y + size.height) < p_rect.position.y) + return false; + } else { + if (position.x >= (p_rect.position.x + p_rect.size.width)) + return false; + if ((position.x + size.width) <= p_rect.position.x) + return false; + if (position.y >= (p_rect.position.y + p_rect.size.height)) + return false; + if ((position.y + size.height) <= p_rect.position.y) + return false; + } return true; } diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 9cc08b54e68..99cfc7ed3c3 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -391,7 +391,7 @@ struct _VariantCall { VCALL_LOCALMEM0R(Rect2, has_no_area); VCALL_LOCALMEM1R(Rect2, has_point); VCALL_LOCALMEM1R(Rect2, is_equal_approx); - VCALL_LOCALMEM1R(Rect2, intersects); + VCALL_LOCALMEM2R(Rect2, intersects); VCALL_LOCALMEM1R(Rect2, encloses); VCALL_LOCALMEM1R(Rect2, clip); VCALL_LOCALMEM1R(Rect2, merge); @@ -1834,7 +1834,7 @@ void register_variant_methods() { ADDFUNC0R(RECT2, BOOL, Rect2, has_no_area, varray()); ADDFUNC1R(RECT2, BOOL, Rect2, has_point, VECTOR2, "point", varray()); ADDFUNC1R(RECT2, BOOL, Rect2, is_equal_approx, RECT2, "rect", varray()); - ADDFUNC1R(RECT2, BOOL, Rect2, intersects, RECT2, "b", varray()); + ADDFUNC2R(RECT2, BOOL, Rect2, intersects, RECT2, "b", BOOL, "include_borders", varray(false)); ADDFUNC1R(RECT2, BOOL, Rect2, encloses, RECT2, "b", varray()); ADDFUNC1R(RECT2, RECT2, Rect2, clip, RECT2, "b", varray()); ADDFUNC1R(RECT2, RECT2, Rect2, merge, RECT2, "b", varray()); diff --git a/doc/classes/Rect2.xml b/doc/classes/Rect2.xml index 26abfb538bd..dbf461cdf15 100644 --- a/doc/classes/Rect2.xml +++ b/doc/classes/Rect2.xml @@ -143,8 +143,11 @@ + + - Returns [code]true[/code] if the [Rect2] overlaps with another. + Returns [code]true[/code] if the [Rect2] overlaps with [code]b[/code] (i.e. they have at least one point in common). + If [code]include_borders[/code] is [code]true[/code], they will also be considered overlapping if their borders touch, even without intersection. diff --git a/servers/visual/visual_server_canvas.cpp b/servers/visual/visual_server_canvas.cpp index c1833fea44c..c192b779884 100644 --- a/servers/visual/visual_server_canvas.cpp +++ b/servers/visual/visual_server_canvas.cpp @@ -183,7 +183,7 @@ void VisualServerCanvas::_cull_canvas_item(Item *p_canvas_item, const Transform2 VisualServerRaster::redraw_request(); } - if ((ci->commands != NULL && p_clip_rect.intersects_touch(global_rect)) || ci->vp_render || ci->copy_back_buffer) { + if ((ci->commands != NULL && p_clip_rect.intersects(global_rect, true)) || ci->vp_render || ci->copy_back_buffer) { //something to draw? ci->final_transform = xform; ci->final_modulate = Color(modulate.r * ci->self_modulate.r, modulate.g * ci->self_modulate.g, modulate.b * ci->self_modulate.b, modulate.a * ci->self_modulate.a);