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

Side by Side 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, 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
« no previous file with comments | « no previous file | cc/base/math_util.cc » ('j') | cc/layers/picture_layer_impl.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 CC_BASE_MATH_UTIL_H_ 5 #ifndef CC_BASE_MATH_UTIL_H_
6 #define CC_BASE_MATH_UTIL_H_ 6 #define CC_BASE_MATH_UTIL_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <cmath> 9 #include <cmath>
10 #include <vector> 10 #include <vector>
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 static float Deg2Rad(float deg) { return deg * kPiFloat / 180.0f; } 90 static float Deg2Rad(float deg) { return deg * kPiFloat / 180.0f; }
91 static float Rad2Deg(float rad) { return rad * 180.0f / kPiFloat; } 91 static float Rad2Deg(float rad) { return rad * 180.0f / kPiFloat; }
92 92
93 static float Round(float f) { 93 static float Round(float f) {
94 return (f > 0.f) ? std::floor(f + 0.5f) : std::ceil(f - 0.5f); 94 return (f > 0.f) ? std::floor(f + 0.5f) : std::ceil(f - 0.5f);
95 } 95 }
96 static double Round(double d) { 96 static double Round(double d) {
97 return (d > 0.0) ? std::floor(d + 0.5) : std::ceil(d - 0.5); 97 return (d > 0.0) ? std::floor(d + 0.5) : std::ceil(d - 0.5);
98 } 98 }
99 99
100 // Rounds the given |value| to fixed precision. This makes almost equal
101 // floats (which differ by some threshold magnitude of floating point epsilon)
102 // to be considered as same.
103 // The |precision| should be >= 0, otherwise crashes in debug builds.
104 // The max number of digits that can be represented without change by float
105 // is 6. The maximum possible digits in the fraction part is computed by
106 // considering digits in integral part and digits required for |precision|.
107 // e.g. If intergral part has 4 digits and precision in fractional part
108 // requested is 5, then max allowed precision for fraction part is 2.
109 // Examples:
110 // RoundToFixedPrecision(7.33907556533813, 4) returns 7.339000225067138671875.
111 // RoundToFixedPrecision(7.33907508850098, 4) returns 7.339000225067138671875.
112 static float RoundToFixedPrecision(float value, int precision);
113
100 // Returns true if rounded up value does not overflow, false otherwise. 114 // Returns true if rounded up value does not overflow, false otherwise.
101 template <typename T> 115 template <typename T>
102 static bool VerifyRoundup(T n, T mul) { 116 static bool VerifyRoundup(T n, T mul) {
103 return mul && (n <= (std::numeric_limits<T>::max() - 117 return mul && (n <= (std::numeric_limits<T>::max() -
104 (std::numeric_limits<T>::max() % mul))); 118 (std::numeric_limits<T>::max() % mul)));
105 } 119 }
106 120
107 // Rounds up a given |n| to be a multiple of |mul|, but may overflow. 121 // Rounds up a given |n| to be a multiple of |mul|, but may overflow.
108 // Examples: 122 // Examples:
109 // - RoundUp(123, 50) returns 150. 123 // - RoundUp(123, 50) returns 150.
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 template <typename T> 330 template <typename T>
317 static T RoundDownInternal(T n, T mul) { 331 static T RoundDownInternal(T n, T mul) {
318 return (n > 0) ? (n / mul) * mul : (n == 0) ? 0 332 return (n > 0) ? (n / mul) * mul : (n == 0) ? 0
319 : ((n - mul + 1) / mul) * mul; 333 : ((n - mul + 1) / mul) * mul;
320 } 334 }
321 }; 335 };
322 336
323 } // namespace cc 337 } // namespace cc
324 338
325 #endif // CC_BASE_MATH_UTIL_H_ 339 #endif // CC_BASE_MATH_UTIL_H_
OLDNEW
« 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