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

Unified Diff: ui/gfx/safe_integer_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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/safe_integer_conversions.h ('k') | ui/gfx/size_conversions.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/safe_integer_conversions.cc
diff --git a/ui/gfx/safe_floor_ceil.cc b/ui/gfx/safe_integer_conversions.cc
similarity index 78%
rename from ui/gfx/safe_floor_ceil.cc
rename to ui/gfx/safe_integer_conversions.cc
index c8ac9e1c9e524e8508fcdb0ac3f0bc4a50e5cd14..cdb69e91adad0cf988abe4dffbfcd583e1695d4a 100644
--- a/ui/gfx/safe_floor_ceil.cc
+++ b/ui/gfx/safe_integer_conversions.cc
@@ -25,5 +25,14 @@ int ToCeiledInt(float value) {
return ClampToInt(std::ceil(value));
}
+int ToRoundedInt(float value) {
tfarina 2012/10/10 00:26:02 Looks like this is what SymmetricRound() is trying
danakj 2012/10/10 00:28:04 cool :)
+ float rounded;
+ if (value >= 0.0f)
+ rounded = std::floor(value + 0.5f);
+ else
+ rounded = std::ceil(value - 0.5f);
+ return ClampToInt(rounded);
+}
+
} // namespace gfx
tfarina 2012/10/10 00:26:02 rm extra blank line.
danakj 2012/10/10 00:28:04 Done.
« no previous file with comments | « ui/gfx/safe_integer_conversions.h ('k') | ui/gfx/size_conversions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698