Fix for mishandling disjoined Rectangles in Rectangle::intersect 42/152542/3
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Tue, 26 Sep 2017 09:43:49 +0000 (11:43 +0200)
committerLukasz Oleksak <l.oleksak@samsung.com>
Fri, 29 Sep 2017 11:27:26 +0000 (11:27 +0000)
Disjoined rectangles wont produce negate width and height values -
instead width and height are bound to minimum value 0.

Change-Id: I93402a1f9705fa1b98fce151f141496d56ae37cf

src/Geometry.cpp
src/Geometry.hpp

index a0143f8..768a469 100644 (file)
@@ -17,12 +17,24 @@ Rectangle Rectangle::intersect(const Rectangle first, const Rectangle second)
        rect.position.x = std::max(first.position.x, second.position.x);
        rect.position.y = std::max(first.position.y, second.position.y);
 
-       rect.size.width = std::min(first.position.x + first.size.width, second.position.x + second.size.width) - rect.position.x;
-       rect.size.height = std::min(first.position.y + first.size.height, second.position.y + second.size.height) - rect.position.y;
+       rect.size.width = std::max(rect.position.x, std::min(first.position.x + first.size.width, second.position.x + second.size.width)) - rect.position.x;
+       rect.size.height = std::max(rect.position.y, std::min(first.position.y + first.size.height, second.position.y + second.size.height)) - rect.position.y;
 
        return rect;
 }
 
+Rectangle Rectangle::sum(const Rectangle first, const Rectangle second)
+{
+       Rectangle rect;
+
+       rect.position.x = std::min(first.position.x, second.position.x);
+       rect.position.y = std::min(first.position.y, second.position.y);
+
+       rect.size.width = std::max(first.position.x + first.size.width, second.position.x + second.size.width) - rect.position.x;
+       rect.size.height = std::max(first.position.y + first.size.height, second.position.y + second.size.height) - rect.position.y;
+
+       return rect;
+}
 
 namespace
 {
index 904e392..3f1c8eb 100644 (file)
@@ -21,6 +21,7 @@ struct Rectangle {
        Size size;
 
        static Rectangle intersect(const Rectangle first, const Rectangle second);
+       static Rectangle sum(const Rectangle first, const Rectangle second);
 };
 
 namespace evas