iRect operators.

git-svn-id: svn://qnap.local/TwoTerm/branches/fix-gno-scrolling-region@3161 5590a31f-7b70-45f8-8c82-aa3a8e5f4507
This commit is contained in:
Kelvin Sherlock
2017-02-16 00:26:01 +00:00
parent df2570a146
commit 29776f8366
2 changed files with 38 additions and 6 deletions

View File

@@ -9,7 +9,7 @@
#include "iGeometry.h"
#include <algorithm>
bool iRect::contains(const iPoint aPoint) const
{
@@ -30,4 +30,19 @@ bool iRect::contains(const iRect aRect) const
bool iRect::intersects(const iRect aRect) const
{
return aRect.contains(origin) || aRect.contains(origin.offset(size));
}
}
iRect iRect::intersection(const iRect &rhs) const {
iPoint topLeft;
iPoint bottomRight;
topLeft.x = std::max(origin.x, rhs.origin.x);
topLeft.y = std::max(origin.y, rhs.origin.y);
bottomRight.x = std::min(maxX(), rhs.maxX());
bottomRight.y = std::min(maxY(), rhs.maxY());
if (bottomRight.x <= topLeft.x) return iRect();
if (bottomRight.y <= topLeft.y) return iRect();
return iRect(topLeft, bottomRight);
}