Index: ui/gfx/transform.cc |
diff --git a/ui/gfx/transform.cc b/ui/gfx/transform.cc |
index 057c93c60b8cd2746ed7b75ab1c3d18200856c31..e129af520640f35bef1fc47718f01f4351e67e40 100644 |
--- a/ui/gfx/transform.cc |
+++ b/ui/gfx/transform.cc |
@@ -32,6 +32,14 @@ SkMScalar TanDegrees(double degrees) { |
return SkDoubleToMScalar(std::tan(radians)); |
} |
+inline bool ApproximatelyZero(SkMScalar x, SkMScalar tolerance) { |
+ return std::abs(x) <= tolerance; |
+} |
+ |
+inline bool ApproximatelyOne(SkMScalar x, SkMScalar tolerance) { |
+ return std::abs(x - SkDoubleToMScalar(1.0)) <= tolerance; |
+} |
+ |
} // namespace |
Transform::Transform(SkMScalar col1row1, |
@@ -210,6 +218,25 @@ void Transform::ConcatTransform(const Transform& transform) { |
matrix_.postConcat(transform.matrix_); |
} |
+bool Transform::IsApproximatelyIdentityOrTranslation( |
+ SkMScalar tolerance) const { |
+ DCHECK_GE(tolerance, 0); |
+ 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; |
+} |
+ |
bool Transform::IsIdentityOrIntegerTranslation() const { |
if (!IsIdentityOrTranslation()) |
return false; |