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 // A template for a simple rectangle class. The containment semantics | 5 // A template for a simple 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 InsetsClass InsetsFrom(const Class& inner) const { | 68 InsetsClass InsetsFrom(const Class& inner) const { |
69 return InsetsClass(inner.y() - y(), | 69 return InsetsClass(inner.y() - y(), |
70 inner.x() - x(), | 70 inner.x() - x(), |
71 bottom() - inner.bottom(), | 71 bottom() - inner.bottom(), |
72 right() - inner.right()); | 72 right() - inner.right()); |
73 } | 73 } |
74 | 74 |
75 // Returns true if the area of the rectangle is zero. | 75 // Returns true if the area of the rectangle is zero. |
76 bool IsEmpty() const { return size_.IsEmpty(); } | 76 bool IsEmpty() const { return size_.IsEmpty(); } |
77 | 77 |
78 bool operator==(const Class& other) const; | |
79 | |
80 bool operator!=(const Class& other) const { | |
81 return !(*this == other); | |
82 } | |
83 | |
84 // A rect is less than another rect if its origin is less than | 78 // A rect is less than another rect if its origin is less than |
85 // the other rect's origin. If the origins are equal, then the | 79 // the other rect's origin. If the origins are equal, then the |
86 // shortest rect is less than the other. If the origin and the | 80 // shortest rect is less than the other. If the origin and the |
87 // height are equal, then the narrowest rect is less than. | 81 // height are equal, then the narrowest rect is less than. |
88 // This comparison is required to use Rects in sets, or sorted | 82 // This comparison is required to use Rects in sets, or sorted |
89 // vectors. | 83 // vectors. |
90 bool operator<(const Class& other) const; | 84 bool operator<(const Class& other) const; |
91 | 85 |
92 // Returns true if the point identified by point_x and point_y falls inside | 86 // Returns true if the point identified by point_x and point_y falls inside |
93 // this rectangle. The point (x, y) is inside the rectangle, but the | 87 // this rectangle. The point (x, y) is inside the rectangle, but the |
(...skipping 17 matching lines...) Expand all Loading... |
111 // Computes the union of this rectangle with the given rectangle. The union | 105 // Computes the union of this rectangle with the given rectangle. The union |
112 // is the smallest rectangle containing both rectangles. | 106 // is the smallest rectangle containing both rectangles. |
113 Class Union(const Class& rect) const WARN_UNUSED_RESULT; | 107 Class Union(const Class& rect) const WARN_UNUSED_RESULT; |
114 | 108 |
115 // Computes the rectangle resulting from subtracting |rect| from |this|. If | 109 // Computes the rectangle resulting from subtracting |rect| from |this|. If |
116 // |rect| does not intersect completely in either the x- or y-direction, then | 110 // |rect| does not intersect completely in either the x- or y-direction, then |
117 // |*this| is returned. If |rect| contains |this|, then an empty Rect is | 111 // |*this| is returned. If |rect| contains |this|, then an empty Rect is |
118 // returned. | 112 // returned. |
119 Class Subtract(const Class& rect) const WARN_UNUSED_RESULT; | 113 Class Subtract(const Class& rect) const WARN_UNUSED_RESULT; |
120 | 114 |
121 // Returns true if this rectangle equals that of the supplied rectangle. | |
122 bool Equals(const Class& rect) const { | |
123 return *this == rect; | |
124 } | |
125 | |
126 // Fits as much of the receiving rectangle into the supplied rectangle as | 115 // Fits as much of the receiving rectangle into the supplied rectangle as |
127 // possible, returning the result. For example, if the receiver had | 116 // possible, returning the result. For example, if the receiver had |
128 // a x-location of 2 and a width of 4, and the supplied rectangle had | 117 // a x-location of 2 and a width of 4, and the supplied rectangle had |
129 // an x-location of 0 with a width of 5, the returned rectangle would have | 118 // an x-location of 0 with a width of 5, the returned rectangle would have |
130 // an x-location of 1 with a width of 4. | 119 // an x-location of 1 with a width of 4. |
131 Class AdjustToFit(const Class& rect) const WARN_UNUSED_RESULT; | 120 Class AdjustToFit(const Class& rect) const WARN_UNUSED_RESULT; |
132 | 121 |
133 // Returns the center of this rectangle. | 122 // Returns the center of this rectangle. |
134 PointClass CenterPoint() const; | 123 PointClass CenterPoint() const; |
135 | 124 |
(...skipping 17 matching lines...) Expand all Loading... |
153 ~RectBase(); | 142 ~RectBase(); |
154 | 143 |
155 private: | 144 private: |
156 PointClass origin_; | 145 PointClass origin_; |
157 SizeClass size_; | 146 SizeClass size_; |
158 }; | 147 }; |
159 | 148 |
160 } // namespace gfx | 149 } // namespace gfx |
161 | 150 |
162 #endif // UI_GFX_RECT_BASE_H_ | 151 #endif // UI_GFX_RECT_BASE_H_ |
OLD | NEW |