Chromium Code Reviews| 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 |