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

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

Issue 11364054: ui: Add IsExpressibleAsRect() method to RectF (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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
« ui/gfx/rect_f.h ('K') | « ui/gfx/safe_integer_conversions.h ('k') | 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/safe_integer_conversions.h" 5 #include "ui/gfx/safe_integer_conversions.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 9
10 namespace gfx { 10 namespace gfx {
11 11
12 int ClampToInt(float value) { 12 int ClampToInt(float value) {
13 if (value != value) 13 if (value != value)
14 return 0; // no int NaN. 14 return 0; // no int NaN.
sky 2012/11/02 17:54:30 nit: spacing is off.
danakj 2012/11/02 18:01:30 this is supposed to be fixing the spacing, but it
15 if (value >= std::numeric_limits<int>::max()) 15 if (value >= std::numeric_limits<int>::max())
16 return std::numeric_limits<int>::max(); 16 return std::numeric_limits<int>::max();
17 if (value <= std::numeric_limits<int>::min()) 17 if (value <= std::numeric_limits<int>::min())
18 return std::numeric_limits<int>::min(); 18 return std::numeric_limits<int>::min();
19 return static_cast<int>(value); 19 return static_cast<int>(value);
20 } 20 }
21 21
22 int ToFlooredInt(float value) { 22 int ToFlooredInt(float value) {
23 return ClampToInt(std::floor(value)); 23 return ClampToInt(std::floor(value));
24 } 24 }
25 25
26 int ToCeiledInt(float value) { 26 int ToCeiledInt(float value) {
27 return ClampToInt(std::ceil(value)); 27 return ClampToInt(std::ceil(value));
28 } 28 }
29 29
30 int ToRoundedInt(float value) { 30 int ToRoundedInt(float value) {
31 float rounded; 31 float rounded;
32 if (value >= 0.0f) 32 if (value >= 0.0f)
33 rounded = std::floor(value + 0.5f); 33 rounded = std::floor(value + 0.5f);
34 else 34 else
35 rounded = std::ceil(value - 0.5f); 35 rounded = std::ceil(value - 0.5f);
36 return ClampToInt(rounded); 36 return ClampToInt(rounded);
37 } 37 }
38 38
39 bool IsExpressibleAsInt(float value) {
40 if (value != value)
41 return false; // no int NaN.
42 if (value > std::numeric_limits<int>::max())
43 return false;
44 if (value < std::numeric_limits<int>::min())
45 return false;
46 return true;
47 }
48
39 } // namespace gfx 49 } // namespace gfx
OLDNEW
« ui/gfx/rect_f.h ('K') | « ui/gfx/safe_integer_conversions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698