Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Side by Side Diff: ui/gfx/rect_base.h

Issue 11110004: Make gfx::Rect class operations consistently mutate the class they are called on. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: cc/ fixes Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/rect.h ('k') | ui/gfx/rect_base_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 return Contains(point.x(), point.y()); 93 return Contains(point.x(), point.y());
94 } 94 }
95 95
96 // Returns true if this rectangle contains the specified rectangle. 96 // Returns true if this rectangle contains the specified rectangle.
97 bool Contains(const Class& rect) const; 97 bool Contains(const Class& rect) const;
98 98
99 // Returns true if this rectangle intersects the specified rectangle. 99 // Returns true if this rectangle intersects the specified rectangle.
100 bool Intersects(const Class& rect) const; 100 bool Intersects(const Class& rect) const;
101 101
102 // Computes the intersection of this rectangle with the given rectangle. 102 // Computes the intersection of this rectangle with the given rectangle.
103 Class Intersect(const Class& rect) const WARN_UNUSED_RESULT; 103 void Intersect(const Class& rect);
104 104
105 // 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
106 // is the smallest rectangle containing both rectangles. 106 // is the smallest rectangle containing both rectangles.
107 Class Union(const Class& rect) const WARN_UNUSED_RESULT; 107 void Union(const Class& rect);
108 108
109 // Computes the rectangle resulting from subtracting |rect| from |this|. If 109 // Computes the rectangle resulting from subtracting |rect| from |this|. If
110 // |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
111 // |*this| is returned. If |rect| contains |this|, then an empty Rect is 111 // |*this| does not change. If |rect| contains |this|, then an empty Rect is
112 // returned. 112 // the result.
113 Class Subtract(const Class& rect) const WARN_UNUSED_RESULT; 113 void Subtract(const Class& rect);
114 114
115 // 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
116 // possible, returning the result. For example, if the receiver had 116 // possible, becoming the result. For example, if the receiver had
117 // 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
118 // 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
119 // an x-location of 1 with a width of 4. 119 // an x-location of 1 with a width of 4.
120 Class AdjustToFit(const Class& rect) const WARN_UNUSED_RESULT; 120 void AdjustToFit(const Class& rect);
121 121
122 // Returns the center of this rectangle. 122 // Returns the center of this rectangle.
123 PointClass CenterPoint() const; 123 PointClass CenterPoint() const;
124 124
125 // Return a rectangle that has the same center point but with a size capped 125 // Becomes a rectangle that has the same center point but with a size capped
126 // at given |size|. 126 // at given |size|.
127 Class Center(const SizeClass& size) const WARN_UNUSED_RESULT; 127 void ClampToCenteredSize(const SizeClass& size);
128 128
129 // Splits |this| in two halves, |left_half| and |right_half|. 129 // Splits |this| in two halves, |left_half| and |right_half|.
130 void SplitVertically(Class* left_half, Class* right_half) const; 130 void SplitVertically(Class* left_half, Class* right_half) const;
131 131
132 // Returns true if this rectangle shares an entire edge (i.e., same width or 132 // Returns true if this rectangle shares an entire edge (i.e., same width or
133 // same height) with the given rectangle, and the rectangles do not overlap. 133 // same height) with the given rectangle, and the rectangles do not overlap.
134 bool SharesEdgeWith(const Class& rect) const; 134 bool SharesEdgeWith(const Class& rect) const;
135 135
136 protected: 136 protected:
137 RectBase(const PointClass& origin, const SizeClass& size); 137 RectBase(const PointClass& origin, const SizeClass& size);
138 explicit RectBase(const SizeClass& size); 138 explicit RectBase(const SizeClass& size);
139 explicit RectBase(const PointClass& origin); 139 explicit RectBase(const PointClass& origin);
140 // Destructor is intentionally made non virtual and protected. 140 // Destructor is intentionally made non virtual and protected.
141 // Do not make this public. 141 // Do not make this public.
142 ~RectBase(); 142 ~RectBase();
143 143
144 private: 144 private:
145 PointClass origin_; 145 PointClass origin_;
146 SizeClass size_; 146 SizeClass size_;
147 }; 147 };
148 148
149 } // namespace gfx 149 } // namespace gfx
150 150
151 #endif // UI_GFX_RECT_BASE_H_ 151 #endif // UI_GFX_RECT_BASE_H_
OLDNEW
« no previous file with comments | « ui/gfx/rect.h ('k') | ui/gfx/rect_base_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698