Chromium Code Reviews| Index: ui/gfx/transform.cc |
| diff --git a/ui/gfx/transform.cc b/ui/gfx/transform.cc |
| index 59e6a607a8de11558cbec9ac06fd6f1b47c067ab..22818f4e61df2b8acd4fb4c6a1febc165b082f4b 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) && |
|
danakj
2013/10/17 17:43:18
no extra white space to line things up vertically.
|
| + 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; |