2010-07-08 22:26:58 +00:00
|
|
|
/*
|
|
|
|
* iGeometry.h
|
|
|
|
* 2Term
|
|
|
|
*
|
|
|
|
* Created by Kelvin Sherlock on 7/7/2010.
|
|
|
|
* Copyright 2010 __MyCompanyName__. All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __IGEOMETRY_H__
|
|
|
|
#define __IGEOMETRY_H__
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct iSize {
|
|
|
|
|
2016-07-11 02:25:39 +00:00
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
2010-07-08 22:26:58 +00:00
|
|
|
|
2016-07-08 00:54:52 +00:00
|
|
|
iSize() = default;
|
|
|
|
iSize(const iSize &) = default;
|
2010-07-08 22:26:58 +00:00
|
|
|
iSize(int w, int h) : width(w), height(h) {}
|
2010-07-12 02:18:37 +00:00
|
|
|
|
2016-07-08 00:54:52 +00:00
|
|
|
iSize &operator=(const iSize &) = default;
|
2010-07-12 02:18:37 +00:00
|
|
|
|
2017-02-16 00:26:01 +00:00
|
|
|
bool operator==(const iSize &aSize) const
|
2010-07-12 02:18:37 +00:00
|
|
|
{ return width == aSize.width && height == aSize.height; }
|
|
|
|
|
2017-02-16 00:26:01 +00:00
|
|
|
bool operator!=(const iSize& aSize) const
|
2010-07-12 02:18:37 +00:00
|
|
|
{ return !(*this == aSize); }
|
2010-07-08 22:26:58 +00:00
|
|
|
|
|
|
|
} iSize;
|
|
|
|
|
|
|
|
|
2010-07-12 02:18:37 +00:00
|
|
|
typedef struct iPoint {
|
|
|
|
|
2016-07-11 02:25:39 +00:00
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
2010-07-12 02:18:37 +00:00
|
|
|
|
2016-07-08 00:54:52 +00:00
|
|
|
iPoint() = default;
|
|
|
|
iPoint(const iPoint &aPoint) = default;
|
2010-07-12 02:18:37 +00:00
|
|
|
iPoint(int xx, int yy) : x(xx), y(yy) {}
|
|
|
|
|
2016-07-08 00:54:52 +00:00
|
|
|
iPoint &operator=(const iPoint &) = default;
|
|
|
|
|
2017-02-16 00:26:01 +00:00
|
|
|
bool operator==(const iPoint &aPoint) const
|
2010-07-12 02:18:37 +00:00
|
|
|
{ return x == aPoint.x && y == aPoint.y; }
|
|
|
|
|
2017-02-16 00:26:01 +00:00
|
|
|
bool operator!=(const iPoint &aPoint) const
|
2010-07-12 02:18:37 +00:00
|
|
|
{ return !(*this == aPoint); }
|
|
|
|
|
|
|
|
iPoint offset(int dx, int dy) const
|
|
|
|
{ return iPoint(x + dx, y + dy); }
|
|
|
|
|
|
|
|
iPoint offset(iSize aSize) const
|
|
|
|
{ return iPoint(x + aSize.width, y + aSize.height); }
|
2016-07-11 02:25:39 +00:00
|
|
|
|
2010-07-12 02:18:37 +00:00
|
|
|
} iPoint;
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-08 22:26:58 +00:00
|
|
|
typedef struct iRect {
|
|
|
|
iPoint origin;
|
|
|
|
iSize size;
|
|
|
|
|
2016-07-08 00:54:52 +00:00
|
|
|
iRect() = default;
|
|
|
|
iRect(const iRect &aRect) = default;
|
2016-07-11 02:25:39 +00:00
|
|
|
|
2010-07-08 22:26:58 +00:00
|
|
|
iRect(const iPoint &aPoint, const iSize &aSize) : origin(aPoint), size(aSize) {}
|
2016-07-11 02:25:39 +00:00
|
|
|
iRect(int x, int y, int width, int height) : origin(x, y), size(width, height) {}
|
|
|
|
|
|
|
|
iRect(const iPoint &topLeft, const iPoint &bottomRight) :
|
|
|
|
origin(topLeft), size(bottomRight.x - topLeft.x, bottomRight.y - topLeft.y)
|
|
|
|
{}
|
2010-07-11 15:26:53 +00:00
|
|
|
|
2016-07-08 00:54:52 +00:00
|
|
|
iRect &operator=(const iRect &) = default;
|
|
|
|
|
2010-07-12 02:18:37 +00:00
|
|
|
bool contains(const iPoint aPoint) const;
|
|
|
|
bool contains(const iRect aRect) const;
|
2010-07-11 15:26:53 +00:00
|
|
|
|
2010-07-12 02:18:37 +00:00
|
|
|
bool intersects(const iRect aRect) const;
|
2010-07-17 18:21:26 +00:00
|
|
|
|
2017-02-16 00:26:01 +00:00
|
|
|
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);
|
2010-07-17 18:21:26 +00:00
|
|
|
|
|
|
|
int height() const
|
|
|
|
{ return size.height; }
|
|
|
|
|
|
|
|
int width() const
|
|
|
|
{ return size.width; }
|
|
|
|
|
|
|
|
int minX() const
|
|
|
|
{ return origin.x; }
|
|
|
|
|
|
|
|
int minY() const
|
|
|
|
{ return origin.y; }
|
|
|
|
|
|
|
|
int maxX() const
|
|
|
|
{ return minX() + width(); }
|
|
|
|
|
|
|
|
int maxY() const
|
|
|
|
{ return minY() + height(); }
|
|
|
|
|
|
|
|
|
2010-07-08 22:26:58 +00:00
|
|
|
} iRect;
|
|
|
|
|
2010-07-09 01:18:30 +00:00
|
|
|
#endif
|