Chromium Code Reviews| Index: ui/gfx/transform_unittest.cc |
| diff --git a/ui/gfx/transform_unittest.cc b/ui/gfx/transform_unittest.cc |
| index 31892c3d29a98170d21e045abed59ddcce1ce57d..08428b10ae87052710db2cdae707389bc20241a4 100644 |
| --- a/ui/gfx/transform_unittest.cc |
| +++ b/ui/gfx/transform_unittest.cc |
| @@ -1182,6 +1182,62 @@ TEST(XFormTest, IntegerTranslation) { |
| EXPECT_FALSE(transform.IsIdentityOrIntegerTranslation()); |
| } |
| +TEST(XFormTest, verifyMatrixInversion) |
| +{ |
| + // Invert a translation |
| + { |
| + gfx::Transform translation; |
| + translation.Translate3d(2, 3, 4); |
| + EXPECT_TRUE(translation.IsInvertible()); |
| + |
| + gfx::Transform inverse_translation; |
|
danakj
2012/12/19 05:23:06
kSkipInitialization?
|
| + bool is_invertible = translation.GetInverse(&inverse_translation); |
| + EXPECT_TRUE(is_invertible); |
| + EXPECT_ROW1_EQ(1, 0, 0, -2, inverse_translation); |
| + EXPECT_ROW2_EQ(0, 1, 0, -3, inverse_translation); |
| + EXPECT_ROW3_EQ(0, 0, 1, -4, inverse_translation); |
| + EXPECT_ROW4_EQ(0, 0, 0, 1, inverse_translation); |
| + } |
| + |
| + { |
| + // Invert a non-uniform scale |
| + gfx::Transform scale; |
| + scale.Scale3d(4, 10, 100); |
| + EXPECT_TRUE(scale.IsInvertible()); |
| + |
| + gfx::Transform inverse_scale; |
|
danakj
2012/12/19 05:23:06
kSkipInit?
|
| + bool is_invertible = scale.GetInverse(&inverse_scale); |
| + EXPECT_TRUE(is_invertible); |
| + EXPECT_ROW1_EQ(0.25, 0, 0, 0, inverse_scale); |
| + EXPECT_ROW2_EQ(0, .1f, 0, 0, inverse_scale); |
| + EXPECT_ROW3_EQ(0, 0, .01f, 0, inverse_scale); |
| + EXPECT_ROW4_EQ(0, 0, 0, 1, inverse_scale); |
| + } |
| + |
| + { |
| + // Try to invert a matrix that is not invertible. |
|
danakj
2012/12/19 05:23:06
Is this really desirable? Why don't we set it to t
|
| + // The inverse() function should not modify the given matrix. |
| + gfx::Transform uninvertible; |
|
danakj
2012/12/19 05:23:06
kSkipInitialization?
|
| + uninvertible.matrix().setDouble(0, 0, 0); |
| + uninvertible.matrix().setDouble(1, 1, 0); |
| + uninvertible.matrix().setDouble(2, 2, 0); |
| + uninvertible.matrix().setDouble(3, 3, 0); |
| + EXPECT_FALSE(uninvertible.IsInvertible()); |
| + |
| + gfx::Transform inverse_of_uninvertible; |
| + |
| + // Add a scale just to more easily ensure that inverse_of_uninvertible is |
| + // not modified. |
| + inverse_of_uninvertible.Scale3d(4, 10, 100); |
| + |
| + bool is_invertible = uninvertible.GetInverse(&inverse_of_uninvertible); |
| + EXPECT_FALSE(is_invertible); |
| + EXPECT_ROW1_EQ(4, 0, 0, 0, inverse_of_uninvertible); |
| + EXPECT_ROW2_EQ(0, 10, 0, 0, inverse_of_uninvertible); |
| + EXPECT_ROW3_EQ(0, 0, 100, 0, inverse_of_uninvertible); |
| + EXPECT_ROW4_EQ(0, 0, 0, 1, inverse_of_uninvertible); |
| + } |
| +} |
| } // namespace |