| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 #if defined(OS_WIN) | 53 #if defined(OS_WIN) |
| 54 // Construct an equivalent Win32 RECT object. | 54 // Construct an equivalent Win32 RECT object. |
| 55 RECT ToRECT() const; | 55 RECT ToRECT() const; |
| 56 #elif defined(OS_MACOSX) | 56 #elif defined(OS_MACOSX) |
| 57 // Construct an equivalent CoreGraphics object. | 57 // Construct an equivalent CoreGraphics object. |
| 58 CGRect ToCGRect() const; | 58 CGRect ToCGRect() const; |
| 59 #endif | 59 #endif |
| 60 | 60 |
| 61 operator RectF() const { | 61 operator RectF() const { |
| 62 return RectF(origin().x(), origin().y(), size().width(), size().height()); | 62 return RectF(static_cast<float>(x()), static_cast<float>(y()), |
| 63 static_cast<float>(width()), static_cast<float>(height())); |
| 63 } | 64 } |
| 64 | 65 |
| 65 int x() const { return origin_.x(); } | 66 int x() const { return origin_.x(); } |
| 66 void set_x(int x) { origin_.set_x(x); } | 67 void set_x(int x) { origin_.set_x(x); } |
| 67 | 68 |
| 68 int y() const { return origin_.y(); } | 69 int y() const { return origin_.y(); } |
| 69 void set_y(int y) { origin_.set_y(y); } | 70 void set_y(int y) { origin_.set_y(y); } |
| 70 | 71 |
| 71 int width() const { return size_.width(); } | 72 int width() const { return size_.width(); } |
| 72 void set_width(int width) { size_.set_width(width); } | 73 void set_width(int width) { size_.set_width(width); } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 // | 214 // |
| 214 // This could also be thought of as "the smallest rect that contains both | 215 // This could also be thought of as "the smallest rect that contains both |
| 215 // points", except that we consider points on the right/bottom edges of the | 216 // points", except that we consider points on the right/bottom edges of the |
| 216 // rect to be outside the rect. So technically one or both points will not be | 217 // rect to be outside the rect. So technically one or both points will not be |
| 217 // contained within the rect, because they will appear on one of these edges. | 218 // contained within the rect, because they will appear on one of these edges. |
| 218 GFX_EXPORT Rect BoundingRect(const Point& p1, const Point& p2); | 219 GFX_EXPORT Rect BoundingRect(const Point& p1, const Point& p2); |
| 219 | 220 |
| 220 inline Rect ScaleToEnclosingRect(const Rect& rect, | 221 inline Rect ScaleToEnclosingRect(const Rect& rect, |
| 221 float x_scale, | 222 float x_scale, |
| 222 float y_scale) { | 223 float y_scale) { |
| 223 int x = std::floor(rect.x() * x_scale); | 224 int x = static_cast<int>(std::floor(rect.x() * x_scale)); |
| 224 int y = std::floor(rect.y() * y_scale); | 225 int y = static_cast<int>(std::floor(rect.y() * y_scale)); |
| 225 int r = rect.width() == 0 ? x : std::ceil(rect.right() * x_scale); | 226 int r = rect.width() == 0 ? |
| 226 int b = rect.height() == 0 ? y : std::ceil(rect.bottom() * y_scale); | 227 x : static_cast<int>(std::ceil(rect.right() * x_scale)); |
| 228 int b = rect.height() == 0 ? |
| 229 y : static_cast<int>(std::ceil(rect.bottom() * y_scale)); |
| 227 return Rect(x, y, r - x, b - y); | 230 return Rect(x, y, r - x, b - y); |
| 228 } | 231 } |
| 229 | 232 |
| 230 inline Rect ScaleToEnclosingRect(const Rect& rect, float scale) { | 233 inline Rect ScaleToEnclosingRect(const Rect& rect, float scale) { |
| 231 return ScaleToEnclosingRect(rect, scale, scale); | 234 return ScaleToEnclosingRect(rect, scale, scale); |
| 232 } | 235 } |
| 233 | 236 |
| 234 inline Rect ScaleToEnclosedRect(const Rect& rect, | 237 inline Rect ScaleToEnclosedRect(const Rect& rect, |
| 235 float x_scale, | 238 float x_scale, |
| 236 float y_scale) { | 239 float y_scale) { |
| 237 int x = std::ceil(rect.x() * x_scale); | 240 int x = static_cast<int>(std::ceil(rect.x() * x_scale)); |
| 238 int y = std::ceil(rect.y() * y_scale); | 241 int y = static_cast<int>(std::ceil(rect.y() * y_scale)); |
| 239 int r = rect.width() == 0 ? x : std::floor(rect.right() * x_scale); | 242 int r = rect.width() == 0 ? |
| 240 int b = rect.height() == 0 ? y : std::floor(rect.bottom() * y_scale); | 243 x : static_cast<int>(std::floor(rect.right() * x_scale)); |
| 244 int b = rect.height() == 0 ? |
| 245 y : static_cast<int>(std::floor(rect.bottom() * y_scale)); |
| 241 return Rect(x, y, r - x, b - y); | 246 return Rect(x, y, r - x, b - y); |
| 242 } | 247 } |
| 243 | 248 |
| 244 inline Rect ScaleToEnclosedRect(const Rect& rect, float scale) { | 249 inline Rect ScaleToEnclosedRect(const Rect& rect, float scale) { |
| 245 return ScaleToEnclosedRect(rect, scale, scale); | 250 return ScaleToEnclosedRect(rect, scale, scale); |
| 246 } | 251 } |
| 247 | 252 |
| 248 // This is declared here for use in gtest-based unit tests but is defined in | 253 // This is declared here for use in gtest-based unit tests but is defined in |
| 249 // the gfx_test_support target. Depend on that to use this in your unit test. | 254 // the gfx_test_support target. Depend on that to use this in your unit test. |
| 250 // This should not be used in production code - call ToString() instead. | 255 // This should not be used in production code - call ToString() instead. |
| 251 void PrintTo(const Rect& rect, ::std::ostream* os); | 256 void PrintTo(const Rect& rect, ::std::ostream* os); |
| 252 | 257 |
| 253 } // namespace gfx | 258 } // namespace gfx |
| 254 | 259 |
| 255 #endif // UI_GFX_GEOMETRY_RECT_H_ | 260 #endif // UI_GFX_GEOMETRY_RECT_H_ |
| OLD | NEW |