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

This commit is contained in:
Michael Alexsander 2020-02-08 14:43:08 -03:00
parent f83f1d7c9b
commit 8c8c48a7ad
4 changed files with 27 additions and 26 deletions

View file

@ -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;
}

View file

@ -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());

View file

@ -143,8 +143,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

@ -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);