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

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

Issue 1186133003: gfx: Fix ToEnclosing/ToEnclosed math to deal with big numbers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 | « no previous file | 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 cceeb83a0ae7b897070f0e0bab5b75c1a0448104..412041a4163952c0e9cb60f7839a08c5b19120f9 100644
--- a/ui/gfx/geometry/rect_conversions.cc
+++ b/ui/gfx/geometry/rect_conversions.cc
@@ -17,8 +17,16 @@ Rect ToEnclosingRect(const RectF& rect) {
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(max_x) - min_x, 0);
- int height = rect.height() == 0 ? 0 : std::max(ToCeiledInt(max_y) - min_y, 0);
+ int width =
+ rect.width() == 0
+ ? 0
+ : std::max(
+ ToCeiledInt(static_cast<float>(ToCeiledInt(max_x)) - min_x), 0);
+ int height =
+ rect.height() == 0
+ ? 0
+ : std::max(
+ ToCeiledInt(static_cast<float>(ToCeiledInt(max_y)) - min_y), 0);
return Rect(min_x, min_y, width, height);
}
@@ -27,8 +35,10 @@ Rect ToEnclosedRect(const RectF& rect) {
int min_y = ToCeiledInt(rect.y());
float max_x = rect.right();
float max_y = rect.bottom();
- int width = std::max(ToFlooredInt(max_x) - min_x, 0);
- int height = std::max(ToFlooredInt(max_y) - min_y, 0);
+ 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);
}
« no previous file with comments | « no previous file | ui/gfx/geometry/rect_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698