Chromium Code Reviews| Index: ui/gfx/geometry/rect.h |
| diff --git a/ui/gfx/geometry/rect.h b/ui/gfx/geometry/rect.h |
| index fed202d2bd30b769f91ee041c70224f618495010..53d43ef55186a157e8096f914a8fe7b85946d6ea 100644 |
| --- a/ui/gfx/geometry/rect.h |
| +++ b/ui/gfx/geometry/rect.h |
| @@ -18,6 +18,7 @@ |
| #include "ui/gfx/geometry/point.h" |
| #include "ui/gfx/geometry/rect_f.h" |
| +#include "ui/gfx/geometry/safe_integer_conversions.h" |
| #include "ui/gfx/geometry/size.h" |
| #include "ui/gfx/geometry/vector2d.h" |
| @@ -59,7 +60,8 @@ class GFX_EXPORT Rect { |
| #endif |
| operator RectF() const { |
| - return RectF(origin().x(), origin().y(), size().width(), size().height()); |
| + return RectF(static_cast<float>(x()), static_cast<float>(y()), |
| + static_cast<float>(width()), static_cast<float>(height())); |
| } |
| int x() const { return origin_.x(); } |
| @@ -220,10 +222,10 @@ GFX_EXPORT Rect BoundingRect(const Point& p1, const Point& p2); |
| inline Rect ScaleToEnclosingRect(const Rect& rect, |
| float x_scale, |
| float y_scale) { |
| - int x = std::floor(rect.x() * x_scale); |
| - int y = std::floor(rect.y() * y_scale); |
| - int r = rect.width() == 0 ? x : std::ceil(rect.right() * x_scale); |
| - int b = rect.height() == 0 ? y : std::ceil(rect.bottom() * y_scale); |
| + int x = ToFlooredInt(rect.x() * x_scale); |
|
danakj
2014/10/23 15:35:44
i had written these purposefully as static_casts i
Peter Kasting
2014/10/23 17:29:45
Is that a performance concern? I originally added
danakj
2014/10/23 17:43:23
I think we should cast unless we can show there is
|
| + int y = ToFlooredInt(rect.y() * y_scale); |
| + int r = rect.width() == 0 ? x : ToCeiledInt(rect.right() * x_scale); |
| + int b = rect.height() == 0 ? y : ToCeiledInt(rect.bottom() * y_scale); |
| return Rect(x, y, r - x, b - y); |
| } |
| @@ -234,10 +236,10 @@ inline Rect ScaleToEnclosingRect(const Rect& rect, float scale) { |
| inline Rect ScaleToEnclosedRect(const Rect& rect, |
| float x_scale, |
| float y_scale) { |
| - int x = std::ceil(rect.x() * x_scale); |
| - int y = std::ceil(rect.y() * y_scale); |
| - int r = rect.width() == 0 ? x : std::floor(rect.right() * x_scale); |
| - int b = rect.height() == 0 ? y : std::floor(rect.bottom() * y_scale); |
| + int x = ToCeiledInt(rect.x() * x_scale); |
| + int y = ToCeiledInt(rect.y() * y_scale); |
| + int r = rect.width() == 0 ? x : ToFlooredInt(rect.right() * x_scale); |
| + int b = rect.height() == 0 ? y : ToFlooredInt(rect.bottom() * y_scale); |
| return Rect(x, y, r - x, b - y); |
| } |