2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
28 VRect(int x, int y, int w, int h):x1(x),y1(y),x2(x+w),y2(y+h){}
29 VRect(const VRectF &r);
30 V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;}
31 V_CONSTEXPR int left() const {return x1;}
32 V_CONSTEXPR int top() const {return y1;}
33 V_CONSTEXPR int right() const {return x2;}
34 V_CONSTEXPR int bottom() const {return y2;}
35 V_CONSTEXPR int width() const {return x2-x1;}
36 V_CONSTEXPR int height() const {return y2-y1;}
37 V_CONSTEXPR int x() const {return x1;}
38 V_CONSTEXPR int y() const {return y1;}
39 void setLeft(int l) { x1 = l; }
40 void setTop(int t) { y1 = t; }
41 void setRight(int r) { x2 = r; }
42 void setBottom(int b) { y2 = b; }
43 void setWidth(int w) { x2 = x1 + w; }
44 void setHeight(int h) { y2 = y1 + h; }
45 VRect translated(int dx, int dy) const;
46 void translate(int dx, int dy);
47 bool contains(const VRect &r, bool proper = false) const;
48 bool intersects(const VRect &r);
49 friend V_CONSTEXPR inline bool operator==(const VRect &,
50 const VRect &) noexcept;
51 friend V_CONSTEXPR inline bool operator!=(const VRect &,
52 const VRect &) noexcept;
53 friend VDebug & operator<<(VDebug &os, const VRect &o);
62 inline bool VRect::intersects(const VRect &r)
64 return (right() > r.left() && left() < r.right() && bottom() > r.top() &&
68 inline VDebug &operator<<(VDebug &os, const VRect &o)
70 os << "{R " << o.x() << "," << o.y() << "," << o.width() << ","
74 V_CONSTEXPR inline bool operator==(const VRect &r1, const VRect &r2) noexcept
76 return r1.x1 == r2.x1 && r1.x2 == r2.x2 && r1.y1 == r2.y1 && r1.y2 == r2.y2;
79 V_CONSTEXPR inline bool operator!=(const VRect &r1, const VRect &r2) noexcept
81 return r1.x1 != r2.x1 || r1.x2 != r2.x2 || r1.y1 != r2.y1 || r1.y2 != r2.y2;
84 inline VRect VRect::translated(int dx, int dy) const
86 return {x1 + dx, y1 + dy, x2 - x1, y2 - y1};
89 inline void VRect::translate(int dx, int dy)
97 inline bool VRect::contains(const VRect &r, bool proper) const
100 if ((x1 <= r.x1) && (x2 >= r.x2) && (y1 <= r.y1) && (y2 >= r.y2))
104 if ((x1 < r.x1) && (x2 > r.x2) && (y1 < r.y1) && (y2 > r.y2))
113 VRectF(float x, float y, float w, float h):x1(x),y1(y),x2(x+w),y2(y+h){}
114 VRectF(const VRect &r):x1(r.left()),y1(r.top()),
115 x2(r.right()),y2(r.bottom()){}
117 V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;}
118 V_CONSTEXPR float left() const {return x1;}
119 V_CONSTEXPR float top() const {return y1;}
120 V_CONSTEXPR float right() const {return x2;}
121 V_CONSTEXPR float bottom() const {return y2;}
122 V_CONSTEXPR float width() const {return x2-x1;}
123 V_CONSTEXPR float height() const {return y2-y1;}
124 V_CONSTEXPR float x() const {return x1;}
125 V_CONSTEXPR float y() const {return y1;}
126 V_CONSTEXPR inline VPointF center() const
128 return {x1 + (x2 - x1) / 2.f, y1 + (y2 - y1) / 2.f};
130 void setLeft(float l) { x1 = l; }
131 void setTop(float t) { y1 = t; }
132 void setRight(float r) { x2 = r; }
133 void setBottom(float b) { y2 = b; }
134 void setWidth(float w) { x2 = x1 + w; }
135 void setHeight(float h) { y2 = y1 + h; }
136 void translate(float dx, float dy)
151 inline VRect::VRect(const VRectF &r):x1(r.left()),y1(r.top()),
152 x2(r.right()),y2(r.bottom()){}