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

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

Issue 11093031: Add gfx::ToRoundedInt safe conversion method from float to int. (Closed) Base URL: http://git.chromium.org/chromium/src.git@gfx-scale
Patch Set: Created 8 years, 2 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 | « ui/gfx/point_conversions.cc ('k') | ui/gfx/safe_floor_ceil.h » ('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/rect_conversions.h" 5 #include "ui/gfx/rect_conversions.h"
6 6
7 #include "ui/gfx/safe_floor_ceil.h" 7 #include "ui/gfx/safe_integer_conversions.h"
8 8
9 namespace gfx { 9 namespace gfx {
10 10
11 Rect ToEnclosingRect(const RectF& rect) { 11 Rect ToEnclosingRect(const RectF& rect) {
12 int min_x = ToFlooredInt(rect.origin().x()); 12 int min_x = ToFlooredInt(rect.origin().x());
13 int min_y = ToFlooredInt(rect.origin().y()); 13 int min_y = ToFlooredInt(rect.origin().y());
14 float max_x = rect.origin().x() + rect.size().width(); 14 float max_x = rect.origin().x() + rect.size().width();
15 float max_y = rect.origin().y() + rect.size().height(); 15 float max_y = rect.origin().y() + rect.size().height();
16 int width = std::max(ToCeiledInt(max_x) - min_x, 0); 16 int width = std::max(ToCeiledInt(max_x) - min_x, 0);
17 int height = std::max(ToCeiledInt(max_y) - min_y, 0); 17 int height = std::max(ToCeiledInt(max_y) - min_y, 0);
18 return Rect(min_x, min_y, width, height); 18 return Rect(min_x, min_y, width, height);
19 } 19 }
20 20
21 Rect ToEnclosedRect(const RectF& rect) { 21 Rect ToEnclosedRect(const RectF& rect) {
22 int min_x = ToCeiledInt(rect.origin().x()); 22 int min_x = ToCeiledInt(rect.origin().x());
23 int min_y = ToCeiledInt(rect.origin().y()); 23 int min_y = ToCeiledInt(rect.origin().y());
24 float max_x = rect.origin().x() + rect.size().width(); 24 float max_x = rect.origin().x() + rect.size().width();
25 float max_y = rect.origin().y() + rect.size().height(); 25 float max_y = rect.origin().y() + rect.size().height();
26 int width = std::max(ToFlooredInt(max_x) - min_x, 0); 26 int width = std::max(ToFlooredInt(max_x) - min_x, 0);
27 int height = std::max(ToFlooredInt(max_y) - min_y, 0); 27 int height = std::max(ToFlooredInt(max_y) - min_y, 0);
28 return Rect(min_x, min_y, width, height); 28 return Rect(min_x, min_y, width, height);
29 } 29 }
30 30
31 } // namespace gfx 31 } // namespace gfx
32 32
OLDNEW
« no previous file with comments | « ui/gfx/point_conversions.cc ('k') | ui/gfx/safe_floor_ceil.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698