OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Defines a simple integer rectangle class. The containment semantics | 5 // Defines a simple integer rectangle class. The containment semantics |
6 // are array-like; that is, the coordinate (x, y) is considered to be | 6 // are array-like; that is, the coordinate (x, y) is considered to be |
7 // contained by the rectangle, but the coordinate (x + width, y) is not. | 7 // contained by the rectangle, but the coordinate (x + width, y) is not. |
8 // The class will happily let you create malformed rectangles (that is, | 8 // The class will happily let you create malformed rectangles (that is, |
9 // rectangles with negative width and/or height), but there will be assertions | 9 // rectangles with negative width and/or height), but there will be assertions |
10 // in the operations (such as Contains()) to complain in this case. | 10 // in the operations (such as Contains()) to complain in this case. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 }; | 70 }; |
71 | 71 |
72 inline bool operator==(const Rect& lhs, const Rect& rhs) { | 72 inline bool operator==(const Rect& lhs, const Rect& rhs) { |
73 return lhs.origin() == rhs.origin() && lhs.size() == rhs.size(); | 73 return lhs.origin() == rhs.origin() && lhs.size() == rhs.size(); |
74 } | 74 } |
75 | 75 |
76 inline bool operator!=(const Rect& lhs, const Rect& rhs) { | 76 inline bool operator!=(const Rect& lhs, const Rect& rhs) { |
77 return !(lhs == rhs); | 77 return !(lhs == rhs); |
78 } | 78 } |
79 | 79 |
| 80 UI_EXPORT Rect operator+(const Rect& lhs, const Vector2d& rhs); |
| 81 UI_EXPORT Rect operator-(const Rect& lhs, const Vector2d& rhs); |
| 82 |
| 83 inline Rect operator+(const Vector2d& lhs, const Rect& rhs) { |
| 84 return rhs + lhs; |
| 85 } |
| 86 |
80 UI_EXPORT Rect IntersectRects(const Rect& a, const Rect& b); | 87 UI_EXPORT Rect IntersectRects(const Rect& a, const Rect& b); |
81 UI_EXPORT Rect UnionRects(const Rect& a, const Rect& b); | 88 UI_EXPORT Rect UnionRects(const Rect& a, const Rect& b); |
82 UI_EXPORT Rect SubtractRects(const Rect& a, const Rect& b); | 89 UI_EXPORT Rect SubtractRects(const Rect& a, const Rect& b); |
83 | 90 |
84 // Constructs a rectangle with |p1| and |p2| as opposite corners. | 91 // Constructs a rectangle with |p1| and |p2| as opposite corners. |
85 // | 92 // |
86 // This could also be thought of as "the smallest rect that contains both | 93 // This could also be thought of as "the smallest rect that contains both |
87 // points", except that we consider points on the right/bottom edges of the | 94 // points", except that we consider points on the right/bottom edges of the |
88 // rect to be outside the rect. So technically one or both points will not be | 95 // rect to be outside the rect. So technically one or both points will not be |
89 // contained within the rect, because they will appear on one of these edges. | 96 // contained within the rect, because they will appear on one of these edges. |
90 UI_EXPORT Rect BoundingRect(const Point& p1, const Point& p2); | 97 UI_EXPORT Rect BoundingRect(const Point& p1, const Point& p2); |
91 | 98 |
92 #if !defined(COMPILER_MSVC) | 99 #if !defined(COMPILER_MSVC) |
93 extern template class RectBase<Rect, Point, Size, Insets, Vector2d, int>; | 100 extern template class RectBase<Rect, Point, Size, Insets, Vector2d, int>; |
94 #endif | 101 #endif |
95 | 102 |
96 } // namespace gfx | 103 } // namespace gfx |
97 | 104 |
98 #endif // UI_GFX_RECT_H_ | 105 #endif // UI_GFX_RECT_H_ |
OLD | NEW |