2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 VRect(int x, int y, int w, int h):x1(x),y1(y),x2(x+w),y2(y+h){}
31 VRect(const VRectF &r);
32 V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;}
33 V_CONSTEXPR int left() const {return x1;}
34 V_CONSTEXPR int top() const {return y1;}
35 V_CONSTEXPR int right() const {return x2;}
36 V_CONSTEXPR int bottom() const {return y2;}
37 V_CONSTEXPR int width() const {return x2-x1;}
38 V_CONSTEXPR int height() const {return y2-y1;}
39 V_CONSTEXPR int x() const {return x1;}
40 V_CONSTEXPR int y() const {return y1;}
41 void setLeft(int l) { x1 = l; }
42 void setTop(int t) { y1 = t; }
43 void setRight(int r) { x2 = r; }
44 void setBottom(int b) { y2 = b; }
45 void setWidth(int w) { x2 = x1 + w; }
46 void setHeight(int h) { y2 = y1 + h; }
47 VRect translated(int dx, int dy) const;
48 void translate(int dx, int dy);
49 bool contains(const VRect &r, bool proper = false) const;
50 bool intersects(const VRect &r);
51 friend V_CONSTEXPR inline bool operator==(const VRect &,
52 const VRect &) noexcept;
53 friend V_CONSTEXPR inline bool operator!=(const VRect &,
54 const VRect &) noexcept;
55 friend VDebug & operator<<(VDebug &os, const VRect &o);
64 inline bool VRect::intersects(const VRect &r)
66 return (right() > r.left() && left() < r.right() && bottom() > r.top() &&
70 inline VDebug &operator<<(VDebug &os, const VRect &o)
72 os << "{R " << o.x() << "," << o.y() << "," << o.width() << ","
76 V_CONSTEXPR inline bool operator==(const VRect &r1, const VRect &r2) noexcept
78 return r1.x1 == r2.x1 && r1.x2 == r2.x2 && r1.y1 == r2.y1 && r1.y2 == r2.y2;
81 V_CONSTEXPR inline bool operator!=(const VRect &r1, const VRect &r2) noexcept
83 return r1.x1 != r2.x1 || r1.x2 != r2.x2 || r1.y1 != r2.y1 || r1.y2 != r2.y2;
86 inline VRect VRect::translated(int dx, int dy) const
88 return {x1 + dx, y1 + dy, x2 - x1, y2 - y1};
91 inline void VRect::translate(int dx, int dy)
99 inline bool VRect::contains(const VRect &r, bool proper) const
102 if ((x1 <= r.x1) && (x2 >= r.x2) && (y1 <= r.y1) && (y2 >= r.y2))
106 if ((x1 < r.x1) && (x2 > r.x2) && (y1 < r.y1) && (y2 > r.y2))
115 VRectF(float x, float y, float w, float h):x1(x),y1(y),x2(x+w),y2(y+h){}
116 VRectF(const VRect &r):x1(r.left()),y1(r.top()),
117 x2(r.right()),y2(r.bottom()){}
119 V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;}
120 V_CONSTEXPR float left() const {return x1;}
121 V_CONSTEXPR float top() const {return y1;}
122 V_CONSTEXPR float right() const {return x2;}
123 V_CONSTEXPR float bottom() const {return y2;}
124 V_CONSTEXPR float width() const {return x2-x1;}
125 V_CONSTEXPR float height() const {return y2-y1;}
126 V_CONSTEXPR float x() const {return x1;}
127 V_CONSTEXPR float y() const {return y1;}
128 V_CONSTEXPR inline VPointF center() const
130 return {x1 + (x2 - x1) / 2.f, y1 + (y2 - y1) / 2.f};
132 void setLeft(float l) { x1 = l; }
133 void setTop(float t) { y1 = t; }
134 void setRight(float r) { x2 = r; }
135 void setBottom(float b) { y2 = b; }
136 void setWidth(float w) { x2 = x1 + w; }
137 void setHeight(float h) { y2 = y1 + h; }
138 void translate(float dx, float dy)
153 inline VRect::VRect(const VRectF &r):x1(r.left()),y1(r.top()),
154 x2(r.right()),y2(r.bottom()){}