Chromium Code Reviews| Index: ui/gfx/transform.cc |
| diff --git a/ui/gfx/transform.cc b/ui/gfx/transform.cc |
| index 5e8799841fc4508782958a3aa716e3c5fe30630e..469abc49c409b2e40538b17db15d07b836e78b55 100644 |
| --- a/ui/gfx/transform.cc |
| +++ b/ui/gfx/transform.cc |
| @@ -30,6 +30,15 @@ double TanDegrees(double degrees) { |
| return std::tan(radians); |
| } |
| +bool AlmostEqual(double d, double i) { |
| + const double kErrorThreshold = 1e-6; |
|
alokp
2013/03/08 19:40:06
The error threshold should really depend on the tr
Xianzhu
2013/03/08 23:36:56
My another thought is not to add these methods but
|
| + return std::abs(d - i) < kErrorThreshold; |
| +} |
| + |
| +double Round(double d) { |
| + return (d > 0.0) ? std::floor(d + 0.5) : std::ceil(d - 0.5); |
| +} |
| + |
| } // namespace |
| Transform::Transform( |
| @@ -215,6 +224,28 @@ bool Transform::IsIdentityOrIntegerTranslation() const { |
| return no_fractional_translation; |
| } |
| + |
| +bool Transform::IsAlmostIdentity() const { |
| + return IsAlmostIdentityOrTranslation() && |
| + AlmostEqual(matrix_.getDouble(0, 3), 0) && |
| + AlmostEqual(matrix_.getDouble(1, 3), 0) && |
| + AlmostEqual(matrix_.getDouble(2, 3), 0); |
| +} |
| + |
| +bool Transform::IsAlmostIdentityOrTranslation() const { |
| + return IsScaleOrTranslation() && |
| + AlmostEqual(matrix_.getDouble(0, 0), 1) && |
| + AlmostEqual(matrix_.getDouble(1, 1), 1) && |
| + AlmostEqual(matrix_.getDouble(2, 2), 1); |
| +} |
| + |
| +bool Transform::IsAlmostIdentityOrIntegerTranslation() const { |
| + return IsAlmostIdentityOrTranslation() && |
| + AlmostEqual(matrix_.getDouble(0, 3), Round(matrix_.getDouble(0, 3))) && |
| + AlmostEqual(matrix_.getDouble(1, 3), Round(matrix_.getDouble(1, 3))) && |
| + AlmostEqual(matrix_.getDouble(2, 3), Round(matrix_.getDouble(2, 3))); |
| +} |
| + |
| bool Transform::IsBackFaceVisible() const { |
| // Compute whether a layer with a forward-facing normal of (0, 0, 1, 0) |
| // would have its back face visible after applying the transform. |