Index: ui/gfx/geometry/rect_conversions.cc |
diff --git a/ui/gfx/geometry/rect_conversions.cc b/ui/gfx/geometry/rect_conversions.cc |
index b4ef3d44ec9c4e434b93ae64531cde2f6197014e..1e69045a9521b821208cd3666cdc3988ab88f99e 100644 |
--- a/ui/gfx/geometry/rect_conversions.cc |
+++ b/ui/gfx/geometry/rect_conversions.cc |
@@ -12,36 +12,25 @@ |
namespace gfx { |
-Rect ToEnclosingRect(const RectF& rect) { |
- int min_x = ToFlooredInt(rect.x()); |
- int min_y = ToFlooredInt(rect.y()); |
- float max_x = rect.right(); |
- float max_y = rect.bottom(); |
- int width = |
- rect.width() == 0 |
- ? 0 |
- : std::max( |
- ToCeiledInt(static_cast<double>(ToCeiledInt(max_x)) - min_x), |
- 0); |
- int height = |
- rect.height() == 0 |
- ? 0 |
- : std::max( |
- ToCeiledInt(static_cast<double>(ToCeiledInt(max_y)) - min_y), |
- 0); |
- return Rect(min_x, min_y, width, height); |
+// This is the minimum size of a float rect dimension for use to include it |
+// in the enclosing int rect. |
+static const float kEmptyDimension = 0.1f; |
+Rect ToEnclosingRect(const RectF& r) { |
+ int left = ToFlooredInt(r.x()); |
+ int right = r.width() < kEmptyDimension ? left : ToCeiledInt(r.right()); |
+ int top = ToFlooredInt(r.y()); |
+ int bottom = r.height() < kEmptyDimension ? top : ToCeiledInt(r.bottom()); |
+ |
+ Rect result; |
+ result.SetByBounds(left, right, top, bottom); |
+ return result; |
} |
Rect ToEnclosedRect(const RectF& rect) { |
- int min_x = ToCeiledInt(rect.x()); |
- int min_y = ToCeiledInt(rect.y()); |
- float max_x = rect.right(); |
- float max_y = rect.bottom(); |
- int width = std::max( |
- ToFlooredInt(static_cast<float>(ToFlooredInt(max_x)) - min_x), 0); |
- int height = std::max( |
- ToFlooredInt(static_cast<float>(ToFlooredInt(max_y)) - min_y), 0); |
- return Rect(min_x, min_y, width, height); |
+ Rect result; |
+ result.SetByBounds(ToCeiledInt(rect.x()), ToFlooredInt(rect.right()), |
+ ToCeiledInt(rect.y()), ToFlooredInt(rect.bottom())); |
+ return result; |
} |
Rect ToNearestRect(const RectF& rect) { |
@@ -62,7 +51,10 @@ Rect ToNearestRect(const RectF& rect) { |
DCHECK(std::abs(max_x - float_max_x) < 0.01f); |
DCHECK(std::abs(max_y - float_max_y) < 0.01f); |
- return Rect(min_x, min_y, max_x - min_x, max_y - min_y); |
+ Rect result; |
+ result.SetByBounds(min_x, max_x, min_y, max_y); |
+ |
+ return result; |
} |
bool IsNearestRectWithinDistance(const gfx::RectF& rect, float distance) { |