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

Unified Diff: cc/base/math_util.cc

Issue 27223008: Provide approximate type functions for SkMatrix44. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-upload. Created 7 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
Index: cc/base/math_util.cc
diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc
index eeb1523db46a080aff9850caaf126c1c3f8b0509..98dbb94233c20281d20a4b8d2ae5245534c08543 100644
--- a/cc/base/math_util.cc
+++ b/cc/base/math_util.cc
@@ -17,6 +17,19 @@
#include "ui/gfx/vector2d_f.h"
namespace cc {
+namespace {
+
+inline bool ApproximatelyZero(SkMScalar x, SkMScalar tolerance) {
+ DCHECK_GE(tolerance, 0);
+ return std::abs(x) <= tolerance;
+}
+
+inline bool ApproximatelyOne(SkMScalar x, SkMScalar tolerance) {
+ DCHECK_GE(tolerance, 0);
+ return std::abs(x-SkDoubleToMScalar(1.0)) <= tolerance;
danakj 2013/10/16 19:04:14 spaces around -
+}
+
+} // namespace
const double MathUtil::kPiDouble = 3.14159265358979323846;
const float MathUtil::kPiFloat = 3.14159265358979323846f;
@@ -593,4 +606,27 @@ scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) {
std::min(value, std::numeric_limits<float>::max())));
}
+bool MathUtil::IsApproximatelyPureTranslation(
+ const gfx::Transform& transform, SkMScalar tolerance) {
+ return IsMatrixApproximatelyPureTranslation(transform.matrix(), tolerance);
+}
+
+bool MathUtil::IsMatrixApproximatelyPureTranslation(const SkMatrix44& matrix,
+ SkMScalar tolerance) {
+ return
+ ApproximatelyOne(matrix.get(0, 0), tolerance) &&
+ ApproximatelyZero(matrix.get(1, 0), tolerance) &&
+ ApproximatelyZero(matrix.get(2, 0), tolerance) &&
+ matrix.get(3, 0) == 0 &&
+ ApproximatelyZero(matrix.get(0, 1), tolerance) &&
+ ApproximatelyOne(matrix.get(1, 1), tolerance) &&
+ ApproximatelyZero(matrix.get(2, 1), tolerance) &&
+ matrix.get(3, 1) == 0 &&
+ ApproximatelyZero(matrix.get(0, 2), tolerance) &&
+ ApproximatelyZero(matrix.get(1, 2), tolerance) &&
+ ApproximatelyOne(matrix.get(2, 2), tolerance) &&
+ matrix.get(3, 2) == 0 &&
+ matrix.get(3, 3) == 1;
+}
+
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698