OLD | NEW |
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 #ifndef UI_GFX_GEOMETRY_SAFE_INTEGER_CONVERSIONS_H_ | 5 #ifndef UI_GFX_GEOMETRY_SAFE_INTEGER_CONVERSIONS_H_ |
6 #define UI_GFX_GEOMETRY_SAFE_INTEGER_CONVERSIONS_H_ | 6 #define UI_GFX_GEOMETRY_SAFE_INTEGER_CONVERSIONS_H_ |
7 | 7 |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 } | 23 } |
24 | 24 |
25 inline int ToFlooredInt(float value) { | 25 inline int ToFlooredInt(float value) { |
26 return ClampToInt(std::floor(value)); | 26 return ClampToInt(std::floor(value)); |
27 } | 27 } |
28 | 28 |
29 inline int ToCeiledInt(float value) { | 29 inline int ToCeiledInt(float value) { |
30 return ClampToInt(std::ceil(value)); | 30 return ClampToInt(std::ceil(value)); |
31 } | 31 } |
32 | 32 |
| 33 inline int ToFlooredInt(double value) { |
| 34 return ClampToInt(std::floor(value)); |
| 35 } |
| 36 |
| 37 inline int ToCeiledInt(double value) { |
| 38 return ClampToInt(std::ceil(value)); |
| 39 } |
| 40 |
33 inline int ToRoundedInt(float value) { | 41 inline int ToRoundedInt(float value) { |
34 float rounded; | 42 float rounded; |
35 if (value >= 0.0f) | 43 if (value >= 0.0f) |
36 rounded = std::floor(value + 0.5f); | 44 rounded = std::floor(value + 0.5f); |
37 else | 45 else |
38 rounded = std::ceil(value - 0.5f); | 46 rounded = std::ceil(value - 0.5f); |
39 return ClampToInt(rounded); | 47 return ClampToInt(rounded); |
40 } | 48 } |
41 | 49 |
42 inline bool IsExpressibleAsInt(float value) { | 50 inline bool IsExpressibleAsInt(float value) { |
43 if (value != value) | 51 if (value != value) |
44 return false; // no int NaN. | 52 return false; // no int NaN. |
45 if (value > std::numeric_limits<int>::max()) | 53 if (value > std::numeric_limits<int>::max()) |
46 return false; | 54 return false; |
47 if (value < std::numeric_limits<int>::min()) | 55 if (value < std::numeric_limits<int>::min()) |
48 return false; | 56 return false; |
49 return true; | 57 return true; |
50 } | 58 } |
51 | 59 |
52 } // namespace gfx | 60 } // namespace gfx |
53 | 61 |
54 #endif // UI_GFX_GEOMETRY_SAFE_INTEGER_CONVERSIONS_H_ | 62 #endif // UI_GFX_GEOMETRY_SAFE_INTEGER_CONVERSIONS_H_ |
OLD | NEW |