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

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: Removed unrelated changes. 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 unified diff | Download patch
« no previous file with comments | « no previous file | cc/base/math_util.cc » ('j') | cc/base/math_util.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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
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 // Round the given float value to fixed precision. This makes amlost euqal
100 // floats (differ by some threshold magnitude of floating point epsilon) to
101 // be considered as same.
102 static float RoundToFixedPrecision(float value);
99 103
100 // Returns true if rounded up value does not overflow, false otherwise. 104 // Returns true if rounded up value does not overflow, false otherwise.
101 template <typename T> 105 template <typename T>
102 static bool VerifyRoundup(T n, T mul) { 106 static bool VerifyRoundup(T n, T mul) {
103 return mul && (n <= (std::numeric_limits<T>::max() - 107 return mul && (n <= (std::numeric_limits<T>::max() -
104 (std::numeric_limits<T>::max() % mul))); 108 (std::numeric_limits<T>::max() % mul)));
105 } 109 }
106 110
107 // Rounds up a given |n| to be a multiple of |mul|, but may overflow. 111 // Rounds up a given |n| to be a multiple of |mul|, but may overflow.
108 // Examples: 112 // Examples:
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 template <typename T> 320 template <typename T>
317 static T RoundDownInternal(T n, T mul) { 321 static T RoundDownInternal(T n, T mul) {
318 return (n > 0) ? (n / mul) * mul : (n == 0) ? 0 322 return (n > 0) ? (n / mul) * mul : (n == 0) ? 0
319 : ((n - mul + 1) / mul) * mul; 323 : ((n - mul + 1) / mul) * mul;
320 } 324 }
321 }; 325 };
322 326
323 } // namespace cc 327 } // namespace cc
324 328
325 #endif // CC_BASE_MATH_UTIL_H_ 329 #endif // CC_BASE_MATH_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | cc/base/math_util.cc » ('j') | cc/base/math_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698