2
0
Эх сурвалжийг харах

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

(cherry picked from commit 8c8c48a7adb27f1563e8ec7d3c756ce08ffbdf5c)
Michael Alexsander 5 жил өмнө
parent
commit
bd2a2a7e40

+ 20 - 22
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;
 	}

+ 2 - 2
core/variant_call.cpp

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

+ 4 - 1
doc/classes/Rect2.xml

@@ -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">

+ 1 - 1
servers/visual/visual_server_canvas.cpp

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