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

Unified Diff: ui/gfx/geometry/safe_integer_conversions.h

Issue 1164063005: Replace gfx::ClampToInt with base::saturated_cast. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clamp: . 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/geometry/rect_unittest.cc ('k') | ui/gfx/geometry/safe_integer_conversions_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/geometry/safe_integer_conversions.h
diff --git a/ui/gfx/geometry/safe_integer_conversions.h b/ui/gfx/geometry/safe_integer_conversions.h
index 873378018b497f6c1b0ce5465e6931e7e0d412b8..5efe134f0793ba51f1ba0908e04b9c987e638073 100644
--- a/ui/gfx/geometry/safe_integer_conversions.h
+++ b/ui/gfx/geometry/safe_integer_conversions.h
@@ -8,34 +8,25 @@
#include <cmath>
#include <limits>
+#include "base/numerics/safe_conversions.h"
#include "ui/gfx/gfx_export.h"
namespace gfx {
-inline int ClampToInt(float value) {
- if (value != value)
- return 0; // no int NaN.
- if (value >= std::numeric_limits<int>::max())
- return std::numeric_limits<int>::max();
- if (value <= std::numeric_limits<int>::min())
- return std::numeric_limits<int>::min();
- return static_cast<int>(value);
-}
-
inline int ToFlooredInt(float value) {
- return ClampToInt(std::floor(value));
+ return base::saturated_cast<int>(std::floor(value));
}
inline int ToCeiledInt(float value) {
- return ClampToInt(std::ceil(value));
+ return base::saturated_cast<int>(std::ceil(value));
}
inline int ToFlooredInt(double value) {
- return ClampToInt(std::floor(value));
+ return base::saturated_cast<int>(std::floor(value));
}
inline int ToCeiledInt(double value) {
- return ClampToInt(std::ceil(value));
+ return base::saturated_cast<int>(std::ceil(value));
}
inline int ToRoundedInt(float value) {
@@ -44,7 +35,7 @@ inline int ToRoundedInt(float value) {
rounded = std::floor(value + 0.5f);
else
rounded = std::ceil(value - 0.5f);
- return ClampToInt(rounded);
+ return base::saturated_cast<int>(rounded);
}
inline int ToRoundedInt(double value) {
@@ -53,7 +44,7 @@ inline int ToRoundedInt(double value) {
rounded = std::floor(value + 0.5);
else
rounded = std::ceil(value - 0.5);
- return ClampToInt(rounded);
+ return base::saturated_cast<int>(rounded);
}
inline bool IsExpressibleAsInt(float value) {
« no previous file with comments | « ui/gfx/geometry/rect_unittest.cc ('k') | ui/gfx/geometry/safe_integer_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698