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

Side by Side Diff: ui/gfx/rect_conversions.cc

Issue 14195014: ui: Use RectF::x/y/right/bottom for rect conversions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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/rect_conversions.h" 5 #include "ui/gfx/rect_conversions.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/gfx/safe_integer_conversions.h" 10 #include "ui/gfx/safe_integer_conversions.h"
11 11
12 namespace gfx { 12 namespace gfx {
13 13
14 Rect ToEnclosingRect(const RectF& rect) { 14 Rect ToEnclosingRect(const RectF& rect) {
15 int min_x = ToFlooredInt(rect.origin().x()); 15 int min_x = ToFlooredInt(rect.x());
16 int min_y = ToFlooredInt(rect.origin().y()); 16 int min_y = ToFlooredInt(rect.y());
17 float max_x = rect.origin().x() + rect.size().width(); 17 float max_x = rect.right();
18 float max_y = rect.origin().y() + rect.size().height(); 18 float max_y = rect.bottom();
19 int width = std::max(ToCeiledInt(max_x) - min_x, 0); 19 int width = std::max(ToCeiledInt(max_x) - min_x, 0);
20 int height = std::max(ToCeiledInt(max_y) - min_y, 0); 20 int height = std::max(ToCeiledInt(max_y) - min_y, 0);
21 return Rect(min_x, min_y, width, height); 21 return Rect(min_x, min_y, width, height);
22 } 22 }
23 23
24 Rect ToEnclosedRect(const RectF& rect) { 24 Rect ToEnclosedRect(const RectF& rect) {
25 int min_x = ToCeiledInt(rect.origin().x()); 25 int min_x = ToCeiledInt(rect.x());
26 int min_y = ToCeiledInt(rect.origin().y()); 26 int min_y = ToCeiledInt(rect.y());
27 float max_x = rect.origin().x() + rect.size().width(); 27 float max_x = rect.right();
28 float max_y = rect.origin().y() + rect.size().height(); 28 float max_y = rect.bottom();
29 int width = std::max(ToFlooredInt(max_x) - min_x, 0); 29 int width = std::max(ToFlooredInt(max_x) - min_x, 0);
30 int height = std::max(ToFlooredInt(max_y) - min_y, 0); 30 int height = std::max(ToFlooredInt(max_y) - min_y, 0);
31 return Rect(min_x, min_y, width, height); 31 return Rect(min_x, min_y, width, height);
32 } 32 }
33 33
34 Rect ToNearestRect(const RectF& rect) { 34 Rect ToNearestRect(const RectF& rect) {
35 float float_min_x = rect.origin().x(); 35 float float_min_x = rect.x();
36 float float_min_y = rect.origin().y(); 36 float float_min_y = rect.y();
37 float float_max_x = float_min_x + rect.size().width(); 37 float float_max_x = rect.right();
38 float float_max_y = float_min_y + rect.size().height(); 38 float float_max_y = rect.bottom();
39 39
40 int min_x = ToRoundedInt(float_min_x); 40 int min_x = ToRoundedInt(float_min_x);
41 int min_y = ToRoundedInt(float_min_y); 41 int min_y = ToRoundedInt(float_min_y);
42 int max_x = ToRoundedInt(float_max_x); 42 int max_x = ToRoundedInt(float_max_x);
43 int max_y = ToRoundedInt(float_max_y); 43 int max_y = ToRoundedInt(float_max_y);
44 44
45 // If these DCHECKs fail, you're using the wrong method, consider using 45 // If these DCHECKs fail, you're using the wrong method, consider using
46 // ToEnclosingRect or ToEnclosedRect instead. 46 // ToEnclosingRect or ToEnclosedRect instead.
47 DCHECK(std::abs(min_x - float_min_x) < 0.01f); 47 DCHECK(std::abs(min_x - float_min_x) < 0.01f);
48 DCHECK(std::abs(min_y - float_min_y) < 0.01f); 48 DCHECK(std::abs(min_y - float_min_y) < 0.01f);
49 DCHECK(std::abs(max_x - float_max_x) < 0.01f); 49 DCHECK(std::abs(max_x - float_max_x) < 0.01f);
50 DCHECK(std::abs(max_y - float_max_y) < 0.01f); 50 DCHECK(std::abs(max_y - float_max_y) < 0.01f);
51 51
52 return Rect(min_x, min_y, max_x - min_x, max_y - min_y); 52 return Rect(min_x, min_y, max_x - min_x, max_y - min_y);
53 } 53 }
54 54
55 Rect ToFlooredRectDeprecated(const RectF& rect) { 55 Rect ToFlooredRectDeprecated(const RectF& rect) {
56 return Rect(ToFlooredInt(rect.origin().x()), 56 return Rect(ToFlooredInt(rect.x()),
57 ToFlooredInt(rect.origin().y()), 57 ToFlooredInt(rect.y()),
58 ToFlooredInt(rect.size().width()), 58 ToFlooredInt(rect.width()),
59 ToFlooredInt(rect.size().height())); 59 ToFlooredInt(rect.height()));
60 } 60 }
61 61
62 } // namespace gfx 62 } // namespace gfx
63 63
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698