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

Unified Diff: cc/base/math_util.h

Issue 1321503002: cc: Do not create separate tilings for almost equal scale factors. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moved roundto function to ideal scales. Created 5 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 | « no previous file | cc/base/math_util.cc » ('j') | cc/layers/picture_layer_impl.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/base/math_util.h
diff --git a/cc/base/math_util.h b/cc/base/math_util.h
index a83ab4fdce34be03b56fd23ffe978262abbe69fb..3a688d1ea95bae232ae3c9e1dfc383fb149c3a88 100644
--- a/cc/base/math_util.h
+++ b/cc/base/math_util.h
@@ -97,6 +97,20 @@ class CC_EXPORT MathUtil {
return (d > 0.0) ? std::floor(d + 0.5) : std::ceil(d - 0.5);
}
+ // Rounds the given |value| to fixed precision. This makes almost equal
+ // floats (which differ by some threshold magnitude of floating point epsilon)
+ // to be considered as same.
+ // The |precision| should be >= 0, otherwise crashes in debug builds.
+ // The max number of digits that can be represented without change by float
+ // is 6. The maximum possible digits in the fraction part is computed by
+ // considering digits in integral part and digits required for |precision|.
+ // e.g. If intergral part has 4 digits and precision in fractional part
+ // requested is 5, then max allowed precision for fraction part is 2.
+ // Examples:
+ // RoundToFixedPrecision(7.33907556533813, 4) returns 7.339000225067138671875.
+ // RoundToFixedPrecision(7.33907508850098, 4) returns 7.339000225067138671875.
+ static float RoundToFixedPrecision(float value, int precision);
+
// Returns true if rounded up value does not overflow, false otherwise.
template <typename T>
static bool VerifyRoundup(T n, T mul) {
« no previous file with comments | « no previous file | cc/base/math_util.cc » ('j') | cc/layers/picture_layer_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698