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

Unified Diff: ui/gfx/geometry/rect_conversions.cc

Issue 2744423002: Handle large rects better. (Closed)
Patch Set: Add comment and change constant reference. Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/geometry/rect.cc ('k') | ui/gfx/geometry/rect_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/geometry/rect_conversions.cc
diff --git a/ui/gfx/geometry/rect_conversions.cc b/ui/gfx/geometry/rect_conversions.cc
index cc92c57f948b145bfa54165ce16e9e490f488411..3a5b2dceaded9fc458ece1a5a8a9c32a07e61c65 100644
--- a/ui/gfx/geometry/rect_conversions.cc
+++ b/ui/gfx/geometry/rect_conversions.cc
@@ -12,31 +12,22 @@
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()
- ? ToCeiledInt(static_cast<double>(ToCeiledInt(max_x)) - min_x)
- : 0;
- int height =
- rect.height()
- ? ToCeiledInt(static_cast<double>(ToCeiledInt(max_y)) - min_y)
- : 0;
- return Rect(min_x, min_y, width, height);
+Rect ToEnclosingRect(const RectF& r) {
+ int left = ToFlooredInt(r.x());
+ int right = r.width() ? ToCeiledInt(r.right()) : left;
+ int top = ToFlooredInt(r.y());
+ int bottom = r.height() ? ToCeiledInt(r.bottom()) : top;
+
+ Rect result;
+ result.SetByBounds(left, top, right, 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()), ToCeiledInt(rect.y()),
+ ToFlooredInt(rect.right()), ToFlooredInt(rect.bottom()));
+ return result;
}
Rect ToNearestRect(const RectF& rect) {
@@ -57,7 +48,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, min_y, max_x, max_y);
+
+ return result;
}
bool IsNearestRectWithinDistance(const gfx::RectF& rect, float distance) {
« no previous file with comments | « ui/gfx/geometry/rect.cc ('k') | ui/gfx/geometry/rect_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698