Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(591)

Unified Diff: ui/gfx/transform_unittest.cc

Issue 11644008: Migrate from MathUtil::inverse() to gfx::Transform::GetInverse() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch for landing Created 7 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/transform.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/transform_unittest.cc
diff --git a/ui/gfx/transform_unittest.cc b/ui/gfx/transform_unittest.cc
index 31892c3d29a98170d21e045abed59ddcce1ce57d..1984feab23c8375acfb834524005febac2e3d70f 100644
--- a/ui/gfx/transform_unittest.cc
+++ b/ui/gfx/transform_unittest.cc
@@ -1182,6 +1182,63 @@ 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;
+ 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;
+ 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.
+ // The inverse() function should reset the output matrix to identity.
+ gfx::Transform uninvertible;
+ 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
+ // reset to identity.
+ inverse_of_uninvertible.Scale3d(4, 10, 100);
+
+ bool is_invertible = uninvertible.GetInverse(&inverse_of_uninvertible);
+ EXPECT_FALSE(is_invertible);
+ EXPECT_TRUE(inverse_of_uninvertible.IsIdentity());
+ EXPECT_ROW1_EQ(1, 0, 0, 0, inverse_of_uninvertible);
+ EXPECT_ROW2_EQ(0, 1, 0, 0, inverse_of_uninvertible);
+ EXPECT_ROW3_EQ(0, 0, 1, 0, inverse_of_uninvertible);
+ EXPECT_ROW4_EQ(0, 0, 0, 1, inverse_of_uninvertible);
+ }
+}
} // namespace
« no previous file with comments | « ui/gfx/transform.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698