#include "vpoint.h"
V_BEGIN_NAMESPACE
+class VRectF;
class VRect {
public:
VRect() = default;
- V_CONSTEXPR VRect(int left, int top, int width, int height);
- V_CONSTEXPR inline bool isEmpty() const;
- V_CONSTEXPR inline bool isNull() const;
-
- V_CONSTEXPR inline int left() const;
- V_CONSTEXPR inline int top() const;
- V_CONSTEXPR inline int right() const;
- V_CONSTEXPR inline int bottom() const;
- V_CONSTEXPR inline int width() const;
- V_CONSTEXPR inline int height() const;
- V_CONSTEXPR inline int x() const;
- V_CONSTEXPR inline int y() const;
- inline void setLeft(int l) { x1 = l; }
- inline void setTop(int t) { y1 = t; }
- inline void setRight(int r) { x2 = r; }
- inline void setBottom(int b) { y2 = b; }
- inline void setWidth(int w) { x2 = x1 + w; }
- inline void setHeight(int h) { y2 = y1 + h; }
- inline VRect translated(int dx, int dy) const;
- inline void translate(int dx, int dy);
- inline bool contains(const VRect &r, bool proper = false) const;
- inline bool intersects(const VRect &r);
+ VRect(int x, int y, int w, int h):x1(x),y1(y),x2(x+w),y2(y+h){}
+ VRect(const VRectF &r);
+ V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;}
+ V_CONSTEXPR int left() const {return x1;}
+ V_CONSTEXPR int top() const {return y1;}
+ V_CONSTEXPR int right() const {return x2;}
+ V_CONSTEXPR int bottom() const {return y2;}
+ V_CONSTEXPR int width() const {return x2-x1;}
+ V_CONSTEXPR int height() const {return y2-y1;}
+ V_CONSTEXPR int x() const {return x1;}
+ V_CONSTEXPR int y() const {return y1;}
+ void setLeft(int l) { x1 = l; }
+ void setTop(int t) { y1 = t; }
+ void setRight(int r) { x2 = r; }
+ void setBottom(int b) { y2 = b; }
+ void setWidth(int w) { x2 = x1 + w; }
+ void setHeight(int h) { y2 = y1 + h; }
+ VRect translated(int dx, int dy) const;
+ void translate(int dx, int dy);
+ bool contains(const VRect &r, bool proper = false) const;
+ bool intersects(const VRect &r);
friend V_CONSTEXPR inline bool operator==(const VRect &,
const VRect &) noexcept;
friend V_CONSTEXPR inline bool operator!=(const VRect &,
private:
int x1{0};
int y1{0};
- int x2{-1};
- int y2{-1};
+ int x2{0};
+ int y2{0};
};
inline bool VRect::intersects(const VRect &r)
return r1.x1 != r2.x1 || r1.x2 != r2.x2 || r1.y1 != r2.y1 || r1.y2 != r2.y2;
}
-V_CONSTEXPR inline bool VRect::isEmpty() const
-{
- return x1 > x2 || y1 > y2;
-}
-
-V_CONSTEXPR inline bool VRect::isNull() const
-{
- return (((x2 - x1) == 0) || ((y2 - y1) == 0));
-}
-
-V_CONSTEXPR inline int VRect::x() const
-{
- return x1;
-}
-
-V_CONSTEXPR inline int VRect::y() const
-{
- return y1;
-}
-
-V_CONSTEXPR inline int VRect::left() const
-{
- return x1;
-}
-
-V_CONSTEXPR inline int VRect::top() const
-{
- return y1;
-}
-
-V_CONSTEXPR inline int VRect::right() const
-{
- return x2;
-}
-
-V_CONSTEXPR inline int VRect::bottom() const
-{
- return y2;
-}
-V_CONSTEXPR inline int VRect::width() const
-{
- return x2 - x1;
-}
-V_CONSTEXPR inline int VRect::height() const
-{
- return y2 - y1;
-}
-
inline VRect VRect::translated(int dx, int dy) const
{
return {x1 + dx, y1 + dy, x2 - x1, y2 - y1};
x2 += dx;
y2 += dy;
}
+
inline bool VRect::contains(const VRect &r, bool proper) const
{
if (!proper) {
return false;
}
}
-V_CONSTEXPR inline VRect::VRect(int left, int top, int width, int height)
- : x1(left), y1(top), x2(width + left), y2(height + top)
-{
-}
class VRectF {
public:
VRectF() = default;
- VRectF(float left, float top, float width, float height)
- {
- x1 = left;
- y1 = top;
- x2 = x1 + width;
- y2 = y1 + height;
- }
-
- V_CONSTEXPR inline bool isEmpty() const;
- V_CONSTEXPR inline bool isNull() const;
- V_CONSTEXPR inline float left() const;
- V_CONSTEXPR inline float top() const;
- V_CONSTEXPR inline float right() const;
- V_CONSTEXPR inline float bottom() const;
- V_CONSTEXPR inline float width() const;
- V_CONSTEXPR inline float height() const;
- V_CONSTEXPR inline float x() const;
- V_CONSTEXPR inline float y() const;
+ VRectF(float x, float y, float w, float h):x1(x),y1(y),x2(x+w),y2(y+h){}
+ VRectF(const VRect &r):x1(r.left()),y1(r.top()),
+ x2(r.right()),y2(r.bottom()){}
+
+ V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;}
+ V_CONSTEXPR float left() const {return x1;}
+ V_CONSTEXPR float top() const {return y1;}
+ V_CONSTEXPR float right() const {return x2;}
+ V_CONSTEXPR float bottom() const {return y2;}
+ V_CONSTEXPR float width() const {return x2-x1;}
+ V_CONSTEXPR float height() const {return y2-y1;}
+ V_CONSTEXPR float x() const {return x1;}
+ V_CONSTEXPR float y() const {return y1;}
V_CONSTEXPR inline VPointF center() const
{
return {x1 + (x2 - x1) / 2.f, y1 + (y2 - y1) / 2.f};
}
- inline void setLeft(float l) { x1 = l; }
- inline void setTop(float t) { y1 = t; }
- inline void setRight(float r) { x2 = r; }
- inline void setBottom(float b) { y2 = b; }
- inline void setWidth(float w) { x2 = x1 + w; }
- inline void setHeight(float h) { y2 = y1 + h; }
- inline void translate(float dx, float dy)
+ void setLeft(float l) { x1 = l; }
+ void setTop(float t) { y1 = t; }
+ void setRight(float r) { x2 = r; }
+ void setBottom(float b) { y2 = b; }
+ void setWidth(float w) { x2 = x1 + w; }
+ void setHeight(float h) { y2 = y1 + h; }
+ void translate(float dx, float dy)
{
x1 += dx;
y1 += dy;
private:
float x1{0};
float y1{0};
- float x2{-1};
- float y2{-1};
+ float x2{0};
+ float y2{0};
};
-V_CONSTEXPR inline bool VRectF::isEmpty() const
-{
- return x1 > x2 || y1 > y2;
-}
-
-V_CONSTEXPR inline bool VRectF::isNull() const
-{
- return (((x2 - x1) == 0) || ((y2 - y1) == 0));
-}
-
-V_CONSTEXPR inline float VRectF::x() const
-{
- return x1;
-}
-
-V_CONSTEXPR inline float VRectF::y() const
-{
- return y1;
-}
-
-V_CONSTEXPR inline float VRectF::left() const
-{
- return x1;
-}
-
-V_CONSTEXPR inline float VRectF::top() const
-{
- return y1;
-}
-
-V_CONSTEXPR inline float VRectF::right() const
-{
- return x2;
-}
-
-V_CONSTEXPR inline float VRectF::bottom() const
-{
- return y2;
-}
-V_CONSTEXPR inline float VRectF::width() const
-{
- return x2 - x1;
-}
-V_CONSTEXPR inline float VRectF::height() const
-{
- return y2 - y1;
-}
-
+inline VRect::VRect(const VRectF &r):x1(r.left()),y1(r.top()),
+ x2(r.right()),y2(r.bottom()){}
V_END_NAMESPACE
#endif // VRECT_H