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

View File

@ -23,10 +23,10 @@ typedef struct iSize {
iSize &operator=(const iSize &) = default;
bool operator==(const iSize &aSize)
bool operator==(const iSize &aSize) const
{ return width == aSize.width && height == aSize.height; }
bool operator!=(const iSize& aSize)
bool operator!=(const iSize& aSize) const
{ return !(*this == aSize); }
} iSize;
@ -43,10 +43,10 @@ typedef struct iPoint {
iPoint &operator=(const iPoint &) = default;
bool operator==(const iPoint &aPoint)
bool operator==(const iPoint &aPoint) const
{ return x == aPoint.x && y == aPoint.y; }
bool operator!=(const iPoint &aPoint)
bool operator!=(const iPoint &aPoint) const
{ return !(*this == aPoint); }
iPoint offset(int dx, int dy) const
@ -80,6 +80,23 @@ typedef struct iRect {
bool intersects(const iRect aRect) const;
iRect intersection(const iRect &rhs) const;
bool operator==(const iRect &rhs) const {
return origin == rhs.origin && size == rhs.size;
}
bool operator!=(const iRect &rhs) const {
return !(*this == rhs);
}
explicit operator bool() const { return size.height >= 0 && size.width >= 0; }
bool operator!() const { return size.height < 0 || size.width < 0; }
bool valid() const { return size.height >= 0 && size.width >= 0; }
iPoint topLeft() const { return origin; }
iPoint bottomRight() const { return iPoint(maxX(), maxY()); }
void setBottomLeft(iPoint &p);
int height() const
{ return size.height; }