Files
Upsilon/kandinsky/include/kandinsky/rect.h
Romain Goyet 0e26e1b2b7 [kandinsky] Add an equality operator on KDRect
Change-Id: Id9d1ce04ecc8869d221c5f6db5faac47bdb391bd
2016-10-04 17:06:19 +02:00

52 lines
1.6 KiB
C++

#ifndef KANDINSKY_RECT_H
#define KANDINSKY_RECT_H
#include <kandinsky/coordinate.h>
#include <kandinsky/point.h>
#include <kandinsky/size.h>
class KDRect {
public:
constexpr KDRect(KDCoordinate x, KDCoordinate y,
KDCoordinate width, KDCoordinate height) :
m_x(x), m_y(y), m_width(width), m_height(height) {}
KDRect(KDPoint p, KDSize s);
KDRect(KDCoordinate x, KDCoordinate y, KDSize s);
KDRect(KDPoint p, KDCoordinate width, KDCoordinate height);
KDCoordinate x() const { return m_x; }
KDCoordinate y() const { return m_y; }
KDPoint origin() const { return KDPoint(m_x, m_y); }
KDCoordinate width() const { return m_width; }
KDCoordinate height() const { return m_height; }
KDSize size() const { return KDSize(m_width, m_height); }
KDCoordinate top() const { return m_y; }
KDCoordinate right() const { return m_x+m_width; }
KDCoordinate bottom() const { return m_y+m_height; }
KDCoordinate left() const { return m_x; }
bool operator ==(const KDRect &other) const {
return (m_x == other.m_x && m_y == other.m_y
&& m_width == other.m_width && m_height == other.m_height);
}
void setOrigin(KDPoint origin);
void setSize(KDSize size);
KDRect translatedBy(KDPoint p) const;
KDRect movedTo(KDPoint p) const;
bool intersects(const KDRect & other) const;
KDRect intersectedWith(const KDRect & other) const;
KDRect unionedWith(const KDRect & other) const; // Returns the smallest rectangle containing r1 and r2
bool contains(KDPoint p) const;
bool isEmpty() const;
private:
KDCoordinate m_x, m_y, m_width, m_height;
};
constexpr KDRect KDRectZero = KDRect(0,0,0,0);
#endif