aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
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;
+ }
};
};