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

Side by Side 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, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/transform.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // MSVC++ requires this to be set before any other includes to get M_PI. 5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 7
8 #include "ui/gfx/transform.h" 8 #include "ui/gfx/transform.h"
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 1175
1176 transform.MakeIdentity(); 1176 transform.MakeIdentity();
1177 transform.Translate3d(0, -6.7, 0); 1177 transform.Translate3d(0, -6.7, 0);
1178 EXPECT_FALSE(transform.IsIdentityOrIntegerTranslation()); 1178 EXPECT_FALSE(transform.IsIdentityOrIntegerTranslation());
1179 1179
1180 transform.MakeIdentity(); 1180 transform.MakeIdentity();
1181 transform.Translate3d(0, 0, 8.9); 1181 transform.Translate3d(0, 0, 8.9);
1182 EXPECT_FALSE(transform.IsIdentityOrIntegerTranslation()); 1182 EXPECT_FALSE(transform.IsIdentityOrIntegerTranslation());
1183 } 1183 }
1184 1184
1185 TEST(XFormTest, verifyMatrixInversion)
1186 {
1187 {
1188 // Invert a translation
1189 gfx::Transform translation;
1190 translation.Translate3d(2, 3, 4);
1191 EXPECT_TRUE(translation.IsInvertible());
1192
1193 gfx::Transform inverse_translation;
1194 bool is_invertible = translation.GetInverse(&inverse_translation);
1195 EXPECT_TRUE(is_invertible);
1196 EXPECT_ROW1_EQ(1, 0, 0, -2, inverse_translation);
1197 EXPECT_ROW2_EQ(0, 1, 0, -3, inverse_translation);
1198 EXPECT_ROW3_EQ(0, 0, 1, -4, inverse_translation);
1199 EXPECT_ROW4_EQ(0, 0, 0, 1, inverse_translation);
1200 }
1201
1202 {
1203 // Invert a non-uniform scale
1204 gfx::Transform scale;
1205 scale.Scale3d(4, 10, 100);
1206 EXPECT_TRUE(scale.IsInvertible());
1207
1208 gfx::Transform inverse_scale;
1209 bool is_invertible = scale.GetInverse(&inverse_scale);
1210 EXPECT_TRUE(is_invertible);
1211 EXPECT_ROW1_EQ(0.25, 0, 0, 0, inverse_scale);
1212 EXPECT_ROW2_EQ(0, .1f, 0, 0, inverse_scale);
1213 EXPECT_ROW3_EQ(0, 0, .01f, 0, inverse_scale);
1214 EXPECT_ROW4_EQ(0, 0, 0, 1, inverse_scale);
1215 }
1216
1217 {
1218 // Try to invert a matrix that is not invertible.
1219 // The inverse() function should reset the output matrix to identity.
1220 gfx::Transform uninvertible;
1221 uninvertible.matrix().setDouble(0, 0, 0);
1222 uninvertible.matrix().setDouble(1, 1, 0);
1223 uninvertible.matrix().setDouble(2, 2, 0);
1224 uninvertible.matrix().setDouble(3, 3, 0);
1225 EXPECT_FALSE(uninvertible.IsInvertible());
1226
1227 gfx::Transform inverse_of_uninvertible;
1228
1229 // Add a scale just to more easily ensure that inverse_of_uninvertible is
1230 // reset to identity.
1231 inverse_of_uninvertible.Scale3d(4, 10, 100);
1232
1233 bool is_invertible = uninvertible.GetInverse(&inverse_of_uninvertible);
1234 EXPECT_FALSE(is_invertible);
1235 EXPECT_TRUE(inverse_of_uninvertible.IsIdentity());
1236 EXPECT_ROW1_EQ(1, 0, 0, 0, inverse_of_uninvertible);
1237 EXPECT_ROW2_EQ(0, 1, 0, 0, inverse_of_uninvertible);
1238 EXPECT_ROW3_EQ(0, 0, 1, 0, inverse_of_uninvertible);
1239 EXPECT_ROW4_EQ(0, 0, 0, 1, inverse_of_uninvertible);
1240 }
1241 }
1185 1242
1186 } // namespace 1243 } // namespace
1187 1244
1188 } // namespace gfx 1245 } // namespace gfx
OLDNEW
« 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