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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | ui/gfx/geometry/rect_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "ui/gfx/geometry/rect_conversions.h" 5 #include "ui/gfx/geometry/rect_conversions.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "ui/gfx/geometry/safe_integer_conversions.h" 11 #include "ui/gfx/geometry/safe_integer_conversions.h"
12 12
13 namespace gfx { 13 namespace gfx {
14 14
15 Rect ToEnclosingRect(const RectF& rect) { 15 Rect ToEnclosingRect(const RectF& rect) {
16 int min_x = ToFlooredInt(rect.x()); 16 int min_x = ToFlooredInt(rect.x());
17 int min_y = ToFlooredInt(rect.y()); 17 int min_y = ToFlooredInt(rect.y());
18 float max_x = rect.right(); 18 float max_x = rect.right();
19 float max_y = rect.bottom(); 19 float max_y = rect.bottom();
20 int width = rect.width() == 0 ? 0 : std::max(ToCeiledInt(max_x) - min_x, 0); 20 int width =
21 int height = rect.height() == 0 ? 0 : std::max(ToCeiledInt(max_y) - min_y, 0); 21 rect.width() == 0
22 ? 0
23 : std::max(
24 ToCeiledInt(static_cast<float>(ToCeiledInt(max_x)) - min_x), 0);
25 int height =
26 rect.height() == 0
27 ? 0
28 : std::max(
29 ToCeiledInt(static_cast<float>(ToCeiledInt(max_y)) - min_y), 0);
22 return Rect(min_x, min_y, width, height); 30 return Rect(min_x, min_y, width, height);
23 } 31 }
24 32
25 Rect ToEnclosedRect(const RectF& rect) { 33 Rect ToEnclosedRect(const RectF& rect) {
26 int min_x = ToCeiledInt(rect.x()); 34 int min_x = ToCeiledInt(rect.x());
27 int min_y = ToCeiledInt(rect.y()); 35 int min_y = ToCeiledInt(rect.y());
28 float max_x = rect.right(); 36 float max_x = rect.right();
29 float max_y = rect.bottom(); 37 float max_y = rect.bottom();
30 int width = std::max(ToFlooredInt(max_x) - min_x, 0); 38 int width = std::max(
31 int height = std::max(ToFlooredInt(max_y) - min_y, 0); 39 ToFlooredInt(static_cast<float>(ToFlooredInt(max_x)) - min_x), 0);
40 int height = std::max(
41 ToFlooredInt(static_cast<float>(ToFlooredInt(max_y)) - min_y), 0);
32 return Rect(min_x, min_y, width, height); 42 return Rect(min_x, min_y, width, height);
33 } 43 }
34 44
35 Rect ToNearestRect(const RectF& rect) { 45 Rect ToNearestRect(const RectF& rect) {
36 float float_min_x = rect.x(); 46 float float_min_x = rect.x();
37 float float_min_y = rect.y(); 47 float float_min_y = rect.y();
38 float float_max_x = rect.right(); 48 float float_max_x = rect.right();
39 float float_max_y = rect.bottom(); 49 float float_max_y = rect.bottom();
40 50
41 int min_x = ToRoundedInt(float_min_x); 51 int min_x = ToRoundedInt(float_min_x);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 83
74 Rect ToFlooredRectDeprecated(const RectF& rect) { 84 Rect ToFlooredRectDeprecated(const RectF& rect) {
75 return Rect(ToFlooredInt(rect.x()), 85 return Rect(ToFlooredInt(rect.x()),
76 ToFlooredInt(rect.y()), 86 ToFlooredInt(rect.y()),
77 ToFlooredInt(rect.width()), 87 ToFlooredInt(rect.width()),
78 ToFlooredInt(rect.height())); 88 ToFlooredInt(rect.height()));
79 } 89 }
80 90
81 } // namespace gfx 91 } // namespace gfx
82 92
OLDNEW
« 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