aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2012-03-21 21:36:59 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-05 17:17:51 +0100
commitb489968dcc1416a530b9f5289b47962e39ec4158 (patch)
treeeb299b599bd0f7ae98661d61eb33d971250d7b67 /src
parente762b9d1a0080bfbba36d1b53ada858d05e13db1 (diff)
downloadusdx-b489968dcc1416a530b9f5289b47962e39ec4158.tar.gz
usdx-b489968dcc1416a530b9f5289b47962e39ec4158.tar.xz
usdx-b489968dcc1416a530b9f5289b47962e39ec4158.zip
utils/rectangle: added function to intersect two rectangles
Diffstat (limited to 'src')
-rw-r--r--src/utils/rectangle.hpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/utils/rectangle.hpp b/src/utils/rectangle.hpp
index fc5d8ac3..e2fddc78 100644
--- a/src/utils/rectangle.hpp
+++ b/src/utils/rectangle.hpp
@@ -104,6 +104,29 @@ namespace usdx
{
return point2.get_y() - point1.get_y();
}
+
+ const Rectangle<T> intersect(const Rectangle<T>& inner) const
+ {
+ Rectangle<T> result(*this);
+
+ if (inner.point1.get_x() > result.point1.get_x()) {
+ result.point1.set_x(inner.point1.get_x());
+ }
+
+ if (inner.point1.get_y() > result.point1.get_y()) {
+ result.point1.set_y(inner.point1.get_y());
+ }
+
+ if (inner.point2.get_x() < result.point2.get_x()) {
+ result.point2.set_x(inner.point2.get_x());
+ }
+
+ if (inner.point2.get_y() < result.point2.get_y()) {
+ result.point2.set_y(inner.point2.get_y());
+ }
+
+ return result;
+ }
};
};