12 VRect(int x, int y, int w, int h):x1(x),y1(y),x2(x+w),y2(y+h){}
13 VRect(const VRectF &r);
14 V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;}
15 V_CONSTEXPR int left() const {return x1;}
16 V_CONSTEXPR int top() const {return y1;}
17 V_CONSTEXPR int right() const {return x2;}
18 V_CONSTEXPR int bottom() const {return y2;}
19 V_CONSTEXPR int width() const {return x2-x1;}
20 V_CONSTEXPR int height() const {return y2-y1;}
21 V_CONSTEXPR int x() const {return x1;}
22 V_CONSTEXPR int y() const {return y1;}
23 void setLeft(int l) { x1 = l; }
24 void setTop(int t) { y1 = t; }
25 void setRight(int r) { x2 = r; }
26 void setBottom(int b) { y2 = b; }
27 void setWidth(int w) { x2 = x1 + w; }
28 void setHeight(int h) { y2 = y1 + h; }
29 VRect translated(int dx, int dy) const;
30 void translate(int dx, int dy);
31 bool contains(const VRect &r, bool proper = false) const;
32 bool intersects(const VRect &r);
33 friend V_CONSTEXPR inline bool operator==(const VRect &,
34 const VRect &) noexcept;
35 friend V_CONSTEXPR inline bool operator!=(const VRect &,
36 const VRect &) noexcept;
37 friend VDebug & operator<<(VDebug &os, const VRect &o);
46 inline bool VRect::intersects(const VRect &r)
48 return (right() > r.left() && left() < r.right() && bottom() > r.top() &&
52 inline VDebug &operator<<(VDebug &os, const VRect &o)
54 os << "{R " << o.x() << "," << o.y() << "," << o.width() << ","
58 V_CONSTEXPR inline bool operator==(const VRect &r1, const VRect &r2) noexcept
60 return r1.x1 == r2.x1 && r1.x2 == r2.x2 && r1.y1 == r2.y1 && r1.y2 == r2.y2;
63 V_CONSTEXPR inline bool operator!=(const VRect &r1, const VRect &r2) noexcept
65 return r1.x1 != r2.x1 || r1.x2 != r2.x2 || r1.y1 != r2.y1 || r1.y2 != r2.y2;
68 inline VRect VRect::translated(int dx, int dy) const
70 return {x1 + dx, y1 + dy, x2 - x1, y2 - y1};
73 inline void VRect::translate(int dx, int dy)
81 inline bool VRect::contains(const VRect &r, bool proper) const
84 if ((x1 <= r.x1) && (x2 >= r.x2) && (y1 <= r.y1) && (y2 >= r.y2))
88 if ((x1 < r.x1) && (x2 > r.x2) && (y1 < r.y1) && (y2 > r.y2))
97 VRectF(float x, float y, float w, float h):x1(x),y1(y),x2(x+w),y2(y+h){}
98 VRectF(const VRect &r):x1(r.left()),y1(r.top()),
99 x2(r.right()),y2(r.bottom()){}
101 V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;}
102 V_CONSTEXPR float left() const {return x1;}
103 V_CONSTEXPR float top() const {return y1;}
104 V_CONSTEXPR float right() const {return x2;}
105 V_CONSTEXPR float bottom() const {return y2;}
106 V_CONSTEXPR float width() const {return x2-x1;}
107 V_CONSTEXPR float height() const {return y2-y1;}
108 V_CONSTEXPR float x() const {return x1;}
109 V_CONSTEXPR float y() const {return y1;}
110 V_CONSTEXPR inline VPointF center() const
112 return {x1 + (x2 - x1) / 2.f, y1 + (y2 - y1) / 2.f};
114 void setLeft(float l) { x1 = l; }
115 void setTop(float t) { y1 = t; }
116 void setRight(float r) { x2 = r; }
117 void setBottom(float b) { y2 = b; }
118 void setWidth(float w) { x2 = x1 + w; }
119 void setHeight(float h) { y2 = y1 + h; }
120 void translate(float dx, float dy)
135 inline VRect::VRect(const VRectF &r):x1(r.left()),y1(r.top()),
136 x2(r.right()),y2(r.bottom()){}