Turn Rect2's 'intersects_touch()' into an extra argument of 'intersects()'

(cherry picked from commit 8c8c48a7ad)
This commit is contained in:
Michael Alexsander 2020-02-08 14:43:08 -03:00 committed by Rémi Verschelde
parent 2e152b945f
commit bd2a2a7e40
4 changed files with 27 additions and 26 deletions

View file

@ -47,20 +47,8 @@ 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 {
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)
@ -69,6 +57,16 @@ struct Rect2 {
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;
}

View file

@ -389,7 +389,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);
@ -1660,7 +1660,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());

View file

@ -133,8 +133,11 @@
</return>
<argument index="0" name="b" type="Rect2">
</argument>
<argument index="1" name="include_borders" type="bool" default="false">
</argument>
<description>
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.
</description>
</method>
<method name="is_equal_approx">

View file

@ -168,7 +168,7 @@ void VisualServerCanvas::_render_canvas_item(Item *p_canvas_item, const Transfor
VisualServerRaster::redraw_request();
}
if ((!ci->commands.empty() && p_clip_rect.intersects_touch(global_rect)) || ci->vp_render || ci->copy_back_buffer) {
if ((!ci->commands.empty() && 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);