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

Side by Side Diff: ui/gfx/transform_unittest.cc

Issue 11774005: Migrate more functions from MathUtil to gfx::Transform (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
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>
11 #include <ostream> 11 #include <ostream>
12 #include <limits> 12 #include <limits>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/gfx/point.h" 16 #include "ui/gfx/point.h"
17 #include "ui/gfx/point3_f.h" 17 #include "ui/gfx/point3_f.h"
18 #include "ui/gfx/test/transform_test_common.h"
18 #include "ui/gfx/transform_util.h" 19 #include "ui/gfx/transform_util.h"
19 #include "ui/gfx/vector3d_f.h" 20 #include "ui/gfx/vector3d_f.h"
20 21
21 namespace gfx { 22 namespace gfx {
22 23
23 namespace { 24 namespace {
24 25
25 bool PointsAreNearlyEqual(const Point3F& lhs, 26 bool PointsAreNearlyEqual(const Point3F& lhs,
26 const Point3F& rhs) { 27 const Point3F& rhs) {
27 float epsilon = 0.0001f; 28 float epsilon = 0.0001f;
28 return lhs.SquaredDistanceTo(rhs) < epsilon; 29 return lhs.SquaredDistanceTo(rhs) < epsilon;
29 } 30 }
30 31
31 bool MatricesAreNearlyEqual(const Transform& lhs, 32 bool MatricesAreNearlyEqual(const Transform& lhs,
32 const Transform& rhs) { 33 const Transform& rhs) {
33 float epsilon = 0.0001f; 34 float epsilon = 0.0001f;
34 for (int row = 0; row < 4; ++row) { 35 for (int row = 0; row < 4; ++row) {
35 for (int col = 0; col < 4; ++col) { 36 for (int col = 0; col < 4; ++col) {
36 if (std::abs(lhs.matrix().get(row, col) - 37 if (std::abs(lhs.matrix().get(row, col) -
37 rhs.matrix().get(row, col)) > epsilon) 38 rhs.matrix().get(row, col)) > epsilon)
38 return false; 39 return false;
39 } 40 }
40 } 41 }
41 return true; 42 return true;
42 } 43 }
43 44
44 #define EXPECT_ROW1_EQ(a, b, c, d, transform) \
45 EXPECT_FLOAT_EQ((a), (transform).matrix().get(0, 0)); \
46 EXPECT_FLOAT_EQ((b), (transform).matrix().get(0, 1)); \
47 EXPECT_FLOAT_EQ((c), (transform).matrix().get(0, 2)); \
48 EXPECT_FLOAT_EQ((d), (transform).matrix().get(0, 3));
49
50 #define EXPECT_ROW2_EQ(a, b, c, d, transform) \
51 EXPECT_FLOAT_EQ((a), (transform).matrix().get(1, 0)); \
52 EXPECT_FLOAT_EQ((b), (transform).matrix().get(1, 1)); \
53 EXPECT_FLOAT_EQ((c), (transform).matrix().get(1, 2)); \
54 EXPECT_FLOAT_EQ((d), (transform).matrix().get(1, 3));
55
56 #define EXPECT_ROW3_EQ(a, b, c, d, transform) \
57 EXPECT_FLOAT_EQ((a), (transform).matrix().get(2, 0)); \
58 EXPECT_FLOAT_EQ((b), (transform).matrix().get(2, 1)); \
59 EXPECT_FLOAT_EQ((c), (transform).matrix().get(2, 2)); \
60 EXPECT_FLOAT_EQ((d), (transform).matrix().get(2, 3));
61
62 #define EXPECT_ROW4_EQ(a, b, c, d, transform) \
63 EXPECT_FLOAT_EQ((a), (transform).matrix().get(3, 0)); \
64 EXPECT_FLOAT_EQ((b), (transform).matrix().get(3, 1)); \
65 EXPECT_FLOAT_EQ((c), (transform).matrix().get(3, 2)); \
66 EXPECT_FLOAT_EQ((d), (transform).matrix().get(3, 3)); \
67
68 // Checking float values for equality close to zero is not robust using
69 // EXPECT_FLOAT_EQ (see gtest documentation). So, to verify rotation matrices,
70 // we must use a looser absolute error threshold in some places.
71 #define EXPECT_ROW1_NEAR(a, b, c, d, transform, errorThreshold) \
72 EXPECT_NEAR((a), (transform).matrix().get(0, 0), (errorThreshold)); \
73 EXPECT_NEAR((b), (transform).matrix().get(0, 1), (errorThreshold)); \
74 EXPECT_NEAR((c), (transform).matrix().get(0, 2), (errorThreshold)); \
75 EXPECT_NEAR((d), (transform).matrix().get(0, 3), (errorThreshold));
76
77 #define EXPECT_ROW2_NEAR(a, b, c, d, transform, errorThreshold) \
78 EXPECT_NEAR((a), (transform).matrix().get(1, 0), (errorThreshold)); \
79 EXPECT_NEAR((b), (transform).matrix().get(1, 1), (errorThreshold)); \
80 EXPECT_NEAR((c), (transform).matrix().get(1, 2), (errorThreshold)); \
81 EXPECT_NEAR((d), (transform).matrix().get(1, 3), (errorThreshold));
82
83 #define EXPECT_ROW3_NEAR(a, b, c, d, transform, errorThreshold) \
84 EXPECT_NEAR((a), (transform).matrix().get(2, 0), (errorThreshold)); \
85 EXPECT_NEAR((b), (transform).matrix().get(2, 1), (errorThreshold)); \
86 EXPECT_NEAR((c), (transform).matrix().get(2, 2), (errorThreshold)); \
87 EXPECT_NEAR((d), (transform).matrix().get(2, 3), (errorThreshold));
88
89 #ifdef SK_MSCALAR_IS_DOUBLE 45 #ifdef SK_MSCALAR_IS_DOUBLE
90 #define ERROR_THRESHOLD 1e-14 46 #define ERROR_THRESHOLD 1e-14
91 #else 47 #else
92 #define ERROR_THRESHOLD 1e-7 48 #define ERROR_THRESHOLD 1e-7
93 #endif 49 #endif
94 #define LOOSE_ERROR_THRESHOLD 1e-7 50 #define LOOSE_ERROR_THRESHOLD 1e-7
95 51
96 TEST(XFormTest, Equality) { 52 TEST(XFormTest, Equality) {
97 Transform lhs, rhs, interpolated; 53 Transform lhs, rhs, interpolated;
98 rhs.matrix().set3x3(1, 2, 3, 54 rhs.matrix().set3x3(1, 2, 3,
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 bool is_invertible = uninvertible.GetInverse(&inverse_of_uninvertible); 1189 bool is_invertible = uninvertible.GetInverse(&inverse_of_uninvertible);
1234 EXPECT_FALSE(is_invertible); 1190 EXPECT_FALSE(is_invertible);
1235 EXPECT_TRUE(inverse_of_uninvertible.IsIdentity()); 1191 EXPECT_TRUE(inverse_of_uninvertible.IsIdentity());
1236 EXPECT_ROW1_EQ(1, 0, 0, 0, inverse_of_uninvertible); 1192 EXPECT_ROW1_EQ(1, 0, 0, 0, inverse_of_uninvertible);
1237 EXPECT_ROW2_EQ(0, 1, 0, 0, inverse_of_uninvertible); 1193 EXPECT_ROW2_EQ(0, 1, 0, 0, inverse_of_uninvertible);
1238 EXPECT_ROW3_EQ(0, 0, 1, 0, inverse_of_uninvertible); 1194 EXPECT_ROW3_EQ(0, 0, 1, 0, inverse_of_uninvertible);
1239 EXPECT_ROW4_EQ(0, 0, 0, 1, inverse_of_uninvertible); 1195 EXPECT_ROW4_EQ(0, 0, 0, 1, inverse_of_uninvertible);
1240 } 1196 }
1241 } 1197 }
1242 1198
1199 TEST(XFormTest, verifyBackfaceVisibilityBasicCases)
1200 {
1201 Transform transform;
1202
1203 transform.MakeIdentity();
1204 EXPECT_FALSE(transform.IsBackFaceVisible());
1205
1206 transform.MakeIdentity();
1207 transform.RotateAboutYAxis(80);
1208 EXPECT_FALSE(transform.IsBackFaceVisible());
1209
1210 transform.MakeIdentity();
1211 transform.RotateAboutYAxis(100);
1212 EXPECT_TRUE(transform.IsBackFaceVisible());
1213
1214 // Edge case, 90 degree rotation should return false.
1215 transform.MakeIdentity();
1216 transform.RotateAboutYAxis(90);
1217 EXPECT_FALSE(transform.IsBackFaceVisible());
1218 }
1219
1220 TEST(XFormTest, verifyBackfaceVisibilityForPerspective)
1221 {
1222 Transform layer_space_to_projection_plane;
1223
1224 // This tests if IsBackFaceVisible works properly under perspective
1225 // transforms. Specifically, layers that may have their back face visible in
1226 // orthographic projection, may not actually have back face visible under
1227 // perspective projection.
1228
1229 // Case 1: Layer is rotated by slightly more than 90 degrees, at the center
1230 // of the prespective projection. In this case, the layer's back-side
1231 // is visible to the camera.
1232 layer_space_to_projection_plane.MakeIdentity();
1233 layer_space_to_projection_plane.ApplyPerspectiveDepth(1);
1234 layer_space_to_projection_plane.Translate3d(0, 0, 0);
1235 layer_space_to_projection_plane.RotateAboutYAxis(100);
1236 EXPECT_TRUE(layer_space_to_projection_plane.IsBackFaceVisible());
1237
1238 // Case 2: Layer is rotated by slightly more than 90 degrees, but shifted off
1239 // to the side of the camera. Because of the wide field-of-view, the
1240 // layer's front side is still visible.
1241 //
1242 // |<-- front side of layer is visible to camera
1243 // \ | /
1244 // \ | /
1245 // \| /
1246 // | /
1247 // |\ /<-- camera field of view
1248 // | \ /
1249 // back side of layer -->| \ /
1250 // \./ <-- camera origin
1251 //
1252 layer_space_to_projection_plane.MakeIdentity();
1253 layer_space_to_projection_plane.ApplyPerspectiveDepth(1);
1254 layer_space_to_projection_plane.Translate3d(-10, 0, 0);
1255 layer_space_to_projection_plane.RotateAboutYAxis(100);
1256 EXPECT_FALSE(layer_space_to_projection_plane.IsBackFaceVisible());
1257
1258 // Case 3: Additionally rotating the layer by 180 degrees should of course
1259 // show the opposite result of case 2.
1260 layer_space_to_projection_plane.RotateAboutYAxis(180);
1261 EXPECT_TRUE(layer_space_to_projection_plane.IsBackFaceVisible());
1262 }
1263
1264 TEST(XFormTest, verifyDefaultConstructorCreatesIdentityMatrix)
1265 {
1266 Transform A;
1267 EXPECT_ROW1_EQ(1, 0, 0, 0, A);
1268 EXPECT_ROW2_EQ(0, 1, 0, 0, A);
1269 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
1270 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1271 EXPECT_TRUE(A.IsIdentity());
1272 }
1273
1274 TEST(XFormTest, verifyCopyConstructor)
1275 {
1276 Transform A;
1277 InitializeTestMatrix(&A);
1278
1279 // Copy constructor should produce exact same elements as matrix A.
1280 Transform B(A);
1281 EXPECT_ROW1_EQ(10, 14, 18, 22, B);
1282 EXPECT_ROW2_EQ(11, 15, 19, 23, B);
1283 EXPECT_ROW3_EQ(12, 16, 20, 24, B);
1284 EXPECT_ROW4_EQ(13, 17, 21, 25, B);
1285 }
1286
1287 TEST(XFormTest, verifyAssignmentOperator)
1288 {
1289 Transform A;
1290 InitializeTestMatrix(&A);
1291 Transform B;
1292 InitializeTestMatrix2(&B);
1293 Transform C;
1294 InitializeTestMatrix2(&C);
1295 C = B = A;
1296
1297 // Both B and C should now have been re-assigned to the value of A.
1298 EXPECT_ROW1_EQ(10, 14, 18, 22, B);
1299 EXPECT_ROW2_EQ(11, 15, 19, 23, B);
1300 EXPECT_ROW3_EQ(12, 16, 20, 24, B);
1301 EXPECT_ROW4_EQ(13, 17, 21, 25, B);
1302
1303 EXPECT_ROW1_EQ(10, 14, 18, 22, C);
1304 EXPECT_ROW2_EQ(11, 15, 19, 23, C);
1305 EXPECT_ROW3_EQ(12, 16, 20, 24, C);
1306 EXPECT_ROW4_EQ(13, 17, 21, 25, C);
1307 }
1308
1309 TEST(XFormTest, verifyEqualsBooleanOperator)
1310 {
1311 Transform A;
1312 InitializeTestMatrix(&A);
1313
1314 Transform B;
1315 InitializeTestMatrix(&B);
1316 EXPECT_TRUE(A == B);
1317
1318 // Modifying multiple elements should cause equals operator to return false.
1319 Transform C;
1320 InitializeTestMatrix2(&C);
1321 EXPECT_FALSE(A == C);
1322
1323 // Modifying any one individual element should cause equals operator to
1324 // return false.
1325 Transform D;
1326 D = A;
1327 D.matrix().setDouble(0, 0, 0);
1328 EXPECT_FALSE(A == D);
1329
1330 D = A;
1331 D.matrix().setDouble(1, 0, 0);
1332 EXPECT_FALSE(A == D);
1333
1334 D = A;
1335 D.matrix().setDouble(2, 0, 0);
1336 EXPECT_FALSE(A == D);
1337
1338 D = A;
1339 D.matrix().setDouble(3, 0, 0);
1340 EXPECT_FALSE(A == D);
1341
1342 D = A;
1343 D.matrix().setDouble(0, 1, 0);
1344 EXPECT_FALSE(A == D);
1345
1346 D = A;
1347 D.matrix().setDouble(1, 1, 0);
1348 EXPECT_FALSE(A == D);
1349
1350 D = A;
1351 D.matrix().setDouble(2, 1, 0);
1352 EXPECT_FALSE(A == D);
1353
1354 D = A;
1355 D.matrix().setDouble(3, 1, 0);
1356 EXPECT_FALSE(A == D);
1357
1358 D = A;
1359 D.matrix().setDouble(0, 2, 0);
1360 EXPECT_FALSE(A == D);
1361
1362 D = A;
1363 D.matrix().setDouble(1, 2, 0);
1364 EXPECT_FALSE(A == D);
1365
1366 D = A;
1367 D.matrix().setDouble(2, 2, 0);
1368 EXPECT_FALSE(A == D);
1369
1370 D = A;
1371 D.matrix().setDouble(3, 2, 0);
1372 EXPECT_FALSE(A == D);
1373
1374 D = A;
1375 D.matrix().setDouble(0, 3, 0);
1376 EXPECT_FALSE(A == D);
1377
1378 D = A;
1379 D.matrix().setDouble(1, 3, 0);
1380 EXPECT_FALSE(A == D);
1381
1382 D = A;
1383 D.matrix().setDouble(2, 3, 0);
1384 EXPECT_FALSE(A == D);
1385
1386 D = A;
1387 D.matrix().setDouble(3, 3, 0);
1388 EXPECT_FALSE(A == D);
1389 }
1390
1391 TEST(XFormTest, verifyMultiplyOperator)
1392 {
danakj 2013/01/07 23:22:35 chromium style here. { on previous line for all th
1393 Transform A;
1394 InitializeTestMatrix(&A);
1395
1396 Transform B;
1397 InitializeTestMatrix2(&B);
1398
1399 Transform C = A * B;
1400 EXPECT_ROW1_EQ(2036, 2292, 2548, 2804, C);
danakj 2013/01/07 23:22:35 float literals should have .f or .0f suffix all th
1401 EXPECT_ROW2_EQ(2162, 2434, 2706, 2978, C);
1402 EXPECT_ROW3_EQ(2288, 2576, 2864, 3152, C);
1403 EXPECT_ROW4_EQ(2414, 2718, 3022, 3326, C);
1404
1405 // Just an additional sanity check; matrix multiplication is not commutative.
1406 EXPECT_FALSE(A * B == B * A);
1407 }
1408
1409 TEST(XFormTest, verifyMultiplyAndAssignOperator)
1410 {
1411 Transform A;
1412 InitializeTestMatrix(&A);
1413
1414 Transform B;
1415 InitializeTestMatrix2(&B);
1416
1417 A *= B;
1418 EXPECT_ROW1_EQ(2036, 2292, 2548, 2804, A);
1419 EXPECT_ROW2_EQ(2162, 2434, 2706, 2978, A);
1420 EXPECT_ROW3_EQ(2288, 2576, 2864, 3152, A);
1421 EXPECT_ROW4_EQ(2414, 2718, 3022, 3326, A);
1422
1423 // Just an additional sanity check; matrix multiplication is not commutative.
1424 Transform C = A;
1425 C *= B;
1426 Transform D = B;
1427 D *= A;
1428 EXPECT_FALSE(C == D);
1429 }
1430
1431 TEST(XFormTest, verifyMatrixMultiplication)
1432 {
1433 Transform A;
1434 InitializeTestMatrix(&A);
1435
1436 Transform B;
1437 InitializeTestMatrix2(&B);
1438
1439 A.PreconcatTransform(B);
1440 EXPECT_ROW1_EQ(2036, 2292, 2548, 2804, A);
1441 EXPECT_ROW2_EQ(2162, 2434, 2706, 2978, A);
1442 EXPECT_ROW3_EQ(2288, 2576, 2864, 3152, A);
1443 EXPECT_ROW4_EQ(2414, 2718, 3022, 3326, A);
1444 }
1445
1446 TEST(XFormTest, verifyMakeIdentiy)
1447 {
1448 Transform A;
1449 InitializeTestMatrix(&A);
1450 A.MakeIdentity();
1451 EXPECT_ROW1_EQ(1, 0, 0, 0, A);
1452 EXPECT_ROW2_EQ(0, 1, 0, 0, A);
1453 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
1454 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1455 EXPECT_TRUE(A.IsIdentity());
1456 }
1457
1458 TEST(XFormTest, verifyTranslate)
1459 {
1460 Transform A;
1461 A.Translate(2, 3);
1462 EXPECT_ROW1_EQ(1, 0, 0, 2, A);
1463 EXPECT_ROW2_EQ(0, 1, 0, 3, A);
1464 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
1465 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1466
1467 // Verify that Translate() post-multiplies the existing matrix.
1468 A.MakeIdentity();
1469 A.Scale(5, 5);
1470 A.Translate(2, 3);
1471 EXPECT_ROW1_EQ(5, 0, 0, 10, A);
1472 EXPECT_ROW2_EQ(0, 5, 0, 15, A);
1473 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
1474 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1475 }
1476
1477 TEST(XFormTest, verifyTranslate3d)
1478 {
1479 Transform A;
1480 A.Translate3d(2, 3, 4);
1481 EXPECT_ROW1_EQ(1, 0, 0, 2, A);
1482 EXPECT_ROW2_EQ(0, 1, 0, 3, A);
1483 EXPECT_ROW3_EQ(0, 0, 1, 4, A);
1484 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1485
1486 // Verify that Translate3d() post-multiplies the existing matrix.
1487 A.MakeIdentity();
1488 A.Scale3d(6, 7, 8);
1489 A.Translate3d(2, 3, 4);
1490 EXPECT_ROW1_EQ(6, 0, 0, 12, A);
1491 EXPECT_ROW2_EQ(0, 7, 0, 21, A);
1492 EXPECT_ROW3_EQ(0, 0, 8, 32, A);
1493 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1494 }
1495
1496 TEST(XFormTest, verifyScale)
1497 {
1498 Transform A;
1499 A.Scale(6, 7);
1500 EXPECT_ROW1_EQ(6, 0, 0, 0, A);
1501 EXPECT_ROW2_EQ(0, 7, 0, 0, A);
1502 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
1503 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1504
1505 // Verify that Scale() post-multiplies the existing matrix.
1506 A.MakeIdentity();
1507 A.Translate3d(2, 3, 4);
1508 A.Scale(6, 7);
1509 EXPECT_ROW1_EQ(6, 0, 0, 2, A);
1510 EXPECT_ROW2_EQ(0, 7, 0, 3, A);
1511 EXPECT_ROW3_EQ(0, 0, 1, 4, A);
1512 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1513 }
1514
1515 TEST(XFormTest, verifyScale3d)
1516 {
1517 Transform A;
1518 A.Scale3d(6, 7, 8);
1519 EXPECT_ROW1_EQ(6, 0, 0, 0, A);
1520 EXPECT_ROW2_EQ(0, 7, 0, 0, A);
1521 EXPECT_ROW3_EQ(0, 0, 8, 0, A);
1522 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1523
1524 // Verify that scale3d() post-multiplies the existing matrix.
1525 A.MakeIdentity();
1526 A.Translate3d(2, 3, 4);
1527 A.Scale3d(6, 7, 8);
1528 EXPECT_ROW1_EQ(6, 0, 0, 2, A);
1529 EXPECT_ROW2_EQ(0, 7, 0, 3, A);
1530 EXPECT_ROW3_EQ(0, 0, 8, 4, A);
1531 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1532 }
1533
1534 TEST(XFormTest, verifyRotate)
1535 {
1536 Transform A;
1537 A.Rotate(90);
1538 EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD);
1539 EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD);
1540 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
1541 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1542
1543 // Verify that Rotate() post-multiplies the existing matrix.
1544 A.MakeIdentity();
1545 A.Scale3d(6, 7, 8);
1546 A.Rotate(90);
1547 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD);
1548 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD);
1549 EXPECT_ROW3_EQ(0, 0, 8, 0, A);
1550 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1551 }
1552
1553 TEST(XFormTest, verifyRotateAboutXAxis)
1554 {
1555 Transform A;
1556 double sin45 = 0.5 * sqrt(2.0);
1557 double cos45 = sin45;
1558
1559 A.MakeIdentity();
1560 A.RotateAboutXAxis(90);
1561 EXPECT_ROW1_EQ(1, 0, 0, 0, A);
1562 EXPECT_ROW2_NEAR(0, 0, -1, 0, A, ERROR_THRESHOLD);
1563 EXPECT_ROW3_NEAR(0, 1, 0, 0, A, ERROR_THRESHOLD);
1564 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1565
1566 A.MakeIdentity();
1567 A.RotateAboutXAxis(45);
1568 EXPECT_ROW1_EQ(1, 0, 0, 0, A);
1569 EXPECT_ROW2_NEAR(0, cos45, -sin45, 0, A, ERROR_THRESHOLD);
1570 EXPECT_ROW3_NEAR(0, sin45, cos45, 0, A, ERROR_THRESHOLD);
1571 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1572
1573 // Verify that RotateAboutXAxis(angle) post-multiplies the existing matrix.
1574 A.MakeIdentity();
1575 A.Scale3d(6, 7, 8);
1576 A.RotateAboutXAxis(90);
1577 EXPECT_ROW1_NEAR(6, 0, 0, 0, A, ERROR_THRESHOLD);
1578 EXPECT_ROW2_NEAR(0, 0, -7, 0, A, ERROR_THRESHOLD);
1579 EXPECT_ROW3_NEAR(0, 8, 0, 0, A, ERROR_THRESHOLD);
1580 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1581 }
1582
1583 TEST(XFormTest, verifyRotateAboutYAxis)
1584 {
1585 Transform A;
1586 double sin45 = 0.5 * sqrt(2.0);
1587 double cos45 = sin45;
1588
1589 // Note carefully, the expected pattern is inverted compared to rotating
1590 // about x axis or z axis.
1591 A.MakeIdentity();
1592 A.RotateAboutYAxis(90);
1593 EXPECT_ROW1_NEAR(0, 0, 1, 0, A, ERROR_THRESHOLD);
1594 EXPECT_ROW2_EQ(0, 1, 0, 0, A);
1595 EXPECT_ROW3_NEAR(-1, 0, 0, 0, A, ERROR_THRESHOLD);
1596 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1597
1598 A.MakeIdentity();
1599 A.RotateAboutYAxis(45);
1600 EXPECT_ROW1_NEAR(cos45, 0, sin45, 0, A, ERROR_THRESHOLD);
1601 EXPECT_ROW2_EQ(0, 1, 0, 0, A);
1602 EXPECT_ROW3_NEAR(-sin45, 0, cos45, 0, A, ERROR_THRESHOLD);
1603 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1604
1605 // Verify that RotateAboutYAxis(angle) post-multiplies the existing matrix.
1606 A.MakeIdentity();
1607 A.Scale3d(6, 7, 8);
1608 A.RotateAboutYAxis(90);
1609 EXPECT_ROW1_NEAR(0, 0, 6, 0, A, ERROR_THRESHOLD);
danakj 2013/01/07 23:22:35 constants are named kErrorThreshold
shawnsingh 2013/01/07 23:59:53 This is a macro, not a constant. Do you want to c
danakj 2013/01/08 00:45:08 Oh, I see. I guess it's fine.
1610 EXPECT_ROW2_NEAR(0, 7, 0, 0, A, ERROR_THRESHOLD);
1611 EXPECT_ROW3_NEAR(-8, 0, 0, 0, A, ERROR_THRESHOLD);
1612 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1613 }
1614
1615 TEST(XFormTest, verifyRotateAboutZAxis)
1616 {
1617 Transform A;
1618 double sin45 = 0.5 * sqrt(2.0);
1619 double cos45 = sin45;
1620
1621 A.MakeIdentity();
1622 A.RotateAboutZAxis(90);
1623 EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD);
1624 EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD);
1625 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
1626 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1627
1628 A.MakeIdentity();
1629 A.RotateAboutZAxis(45);
1630 EXPECT_ROW1_NEAR(cos45, -sin45, 0, 0, A, ERROR_THRESHOLD);
1631 EXPECT_ROW2_NEAR(sin45, cos45, 0, 0, A, ERROR_THRESHOLD);
1632 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
1633 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1634
1635 // Verify that RotateAboutZAxis(angle) post-multiplies the existing matrix.
1636 A.MakeIdentity();
1637 A.Scale3d(6, 7, 8);
1638 A.RotateAboutZAxis(90);
1639 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD);
1640 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD);
1641 EXPECT_ROW3_EQ(0, 0, 8, 0, A);
1642 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1643 }
1644
1645 TEST(XFormTest, verifyRotateAboutForAlignedAxes)
1646 {
1647 Transform A;
1648
1649 // Check rotation about z-axis
1650 A.MakeIdentity();
1651 A.RotateAbout(Vector3dF(0, 0, 1), 90);
1652 EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD);
1653 EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD);
1654 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
1655 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1656
1657 // Check rotation about x-axis
1658 A.MakeIdentity();
1659 A.RotateAbout(Vector3dF(1, 0, 0), 90);
1660 EXPECT_ROW1_EQ(1, 0, 0, 0, A);
1661 EXPECT_ROW2_NEAR(0, 0, -1, 0, A, ERROR_THRESHOLD);
1662 EXPECT_ROW3_NEAR(0, 1, 0, 0, A, ERROR_THRESHOLD);
1663 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1664
1665 // Check rotation about y-axis. Note carefully, the expected pattern is
1666 // inverted compared to rotating about x axis or z axis.
1667 A.MakeIdentity();
1668 A.RotateAbout(Vector3dF(0, 1, 0), 90);
1669 EXPECT_ROW1_NEAR(0, 0, 1, 0, A, ERROR_THRESHOLD);
1670 EXPECT_ROW2_EQ(0, 1, 0, 0, A);
1671 EXPECT_ROW3_NEAR(-1, 0, 0, 0, A, ERROR_THRESHOLD);
1672 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1673
1674 // Verify that rotate3d(axis, angle) post-multiplies the existing matrix.
1675 A.MakeIdentity();
1676 A.Scale3d(6, 7, 8);
1677 A.RotateAboutZAxis(90);
1678 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD);
1679 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD);
1680 EXPECT_ROW3_EQ(0, 0, 8, 0, A);
1681 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1682 }
1683
1684 TEST(XFormTest, verifyRotateAboutForArbitraryAxis)
1685 {
1686 // Check rotation about an arbitrary non-axis-aligned vector.
1687 Transform A;
1688 A.RotateAbout(Vector3dF(1, 1, 1), 90);
1689 EXPECT_ROW1_NEAR(0.3333333333333334258519187,
1690 -0.2440169358562924717404030,
1691 0.9106836025229592124219380,
1692 0, A, ERROR_THRESHOLD);
1693 EXPECT_ROW2_NEAR(0.9106836025229592124219380,
1694 0.3333333333333334258519187,
1695 -0.2440169358562924717404030,
1696 0, A, ERROR_THRESHOLD);
1697 EXPECT_ROW3_NEAR(-0.2440169358562924717404030,
1698 0.9106836025229592124219380,
1699 0.3333333333333334258519187,
1700 0, A, ERROR_THRESHOLD);
1701 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1702 }
1703
1704 TEST(XFormTest, verifyRotateAboutForDegenerateAxis)
1705 {
1706 // Check rotation about a degenerate zero vector.
1707 // It is expected to skip applying the rotation.
1708 Transform A;
1709
1710 A.RotateAbout(Vector3dF(0, 0, 0), 45);
1711 // Verify that A remains unchanged.
1712 EXPECT_TRUE(A.IsIdentity());
1713
1714 InitializeTestMatrix(&A);
1715 A.RotateAbout(Vector3dF(0, 0, 0), 35);
1716
1717 // Verify that A remains unchanged.
1718 EXPECT_ROW1_EQ(10, 14, 18, 22, A);
1719 EXPECT_ROW2_EQ(11, 15, 19, 23, A);
1720 EXPECT_ROW3_EQ(12, 16, 20, 24, A);
1721 EXPECT_ROW4_EQ(13, 17, 21, 25, A);
1722 }
1723
1724 TEST(XFormTest, verifySkewX)
1725 {
1726 Transform A;
1727 A.SkewX(45);
1728 EXPECT_ROW1_EQ(1, 1, 0, 0, A);
1729 EXPECT_ROW2_EQ(0, 1, 0, 0, A);
1730 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
1731 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1732
1733 // Verify that skewX() post-multiplies the existing matrix. Row 1, column 2,
1734 // would incorrectly have value "7" if the matrix is pre-multiplied instead
1735 // of post-multiplied.
1736 A.MakeIdentity();
1737 A.Scale3d(6, 7, 8);
1738 A.SkewX(45);
1739 EXPECT_ROW1_EQ(6, 6, 0, 0, A);
1740 EXPECT_ROW2_EQ(0, 7, 0, 0, A);
1741 EXPECT_ROW3_EQ(0, 0, 8, 0, A);
1742 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1743 }
1744
1745 TEST(XFormTest, verifySkewY)
1746 {
1747 Transform A;
1748 A.SkewY(45);
1749 EXPECT_ROW1_EQ(1, 0, 0, 0, A);
1750 EXPECT_ROW2_EQ(1, 1, 0, 0, A);
1751 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
1752 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1753
1754 // Verify that skewY() post-multiplies the existing matrix. Row 2, column 1,
1755 // would incorrectly have value "6" if the matrix is pre-multiplied instead
1756 // of post-multiplied.
1757 A.MakeIdentity();
1758 A.Scale3d(6, 7, 8);
1759 A.SkewY(45);
1760 EXPECT_ROW1_EQ(6, 0, 0, 0, A);
1761 EXPECT_ROW2_EQ(7, 7, 0, 0, A);
1762 EXPECT_ROW3_EQ(0, 0, 8, 0, A);
1763 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
1764 }
1765
1766 TEST(XFormTest, verifyPerspectiveDepth)
1767 {
1768 Transform A;
1769 A.ApplyPerspectiveDepth(1);
1770 EXPECT_ROW1_EQ(1, 0, 0, 0, A);
1771 EXPECT_ROW2_EQ(0, 1, 0, 0, A);
1772 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
1773 EXPECT_ROW4_EQ(0, 0, -1, 1, A);
1774
1775 // Verify that PerspectiveDepth() post-multiplies the existing matrix.
1776 A.MakeIdentity();
1777 A.Translate3d(2, 3, 4);
1778 A.ApplyPerspectiveDepth(1);
1779 EXPECT_ROW1_EQ(1, 0, -2, 2, A);
1780 EXPECT_ROW2_EQ(0, 1, -3, 3, A);
1781 EXPECT_ROW3_EQ(0, 0, -3, 4, A);
1782 EXPECT_ROW4_EQ(0, 0, -1, 1, A);
1783 }
1784
1785 TEST(XFormTest, verifyHasPerspective)
1786 {
1787 Transform A;
1788 A.ApplyPerspectiveDepth(1);
1789 EXPECT_TRUE(A.HasPerspective());
1790
1791 A.MakeIdentity();
1792 A.ApplyPerspectiveDepth(0);
1793 EXPECT_FALSE(A.HasPerspective());
1794
1795 A.MakeIdentity();
1796 A.matrix().setDouble(3, 0, -1);
1797 EXPECT_TRUE(A.HasPerspective());
1798
1799 A.MakeIdentity();
1800 A.matrix().setDouble(3, 1, -1);
1801 EXPECT_TRUE(A.HasPerspective());
1802
1803 A.MakeIdentity();
1804 A.matrix().setDouble(3, 2, -0.3);
1805 EXPECT_TRUE(A.HasPerspective());
1806
1807 A.MakeIdentity();
1808 A.matrix().setDouble(3, 3, 0.5);
1809 EXPECT_TRUE(A.HasPerspective());
1810
1811 A.MakeIdentity();
1812 A.matrix().setDouble(3, 3, 0);
1813 EXPECT_TRUE(A.HasPerspective());
1814 }
1815
1816 TEST(XFormTest, verifyIsInvertible)
1817 {
1818 Transform A;
1819
1820 // Translations, rotations, scales, skews and arbitrary combinations of them
1821 // are invertible.
1822 A.MakeIdentity();
1823 EXPECT_TRUE(A.IsInvertible());
1824
1825 A.MakeIdentity();
1826 A.Translate3d(2, 3, 4);
1827 EXPECT_TRUE(A.IsInvertible());
1828
1829 A.MakeIdentity();
1830 A.Scale3d(6, 7, 8);
1831 EXPECT_TRUE(A.IsInvertible());
1832
1833 A.MakeIdentity();
1834 A.RotateAboutXAxis(10);
1835 A.RotateAboutYAxis(20);
1836 A.RotateAboutZAxis(30);
1837 EXPECT_TRUE(A.IsInvertible());
1838
1839 A.MakeIdentity();
1840 A.SkewX(45);
1841 EXPECT_TRUE(A.IsInvertible());
1842
1843 // A perspective matrix (projection plane at z=0) is invertible. The
1844 // intuitive explanation is that perspective is eqivalent to a skew of the
1845 // w-axis; skews are invertible.
1846 A.MakeIdentity();
1847 A.ApplyPerspectiveDepth(1);
1848 EXPECT_TRUE(A.IsInvertible());
1849
1850 // A "pure" perspective matrix derived by similar triangles, with m44() set
1851 // to zero (i.e. camera positioned at the origin), is not invertible.
1852 A.MakeIdentity();
1853 A.ApplyPerspectiveDepth(1);
1854 A.matrix().setDouble(3, 3, 0);
1855 EXPECT_FALSE(A.IsInvertible());
1856
1857 // Adding more to a non-invertible matrix will not make it invertible in the
1858 // general case.
1859 A.MakeIdentity();
1860 A.ApplyPerspectiveDepth(1);
1861 A.matrix().setDouble(3, 3, 0);
1862 A.Scale3d(6, 7, 8);
1863 A.RotateAboutXAxis(10);
1864 A.RotateAboutYAxis(20);
1865 A.RotateAboutZAxis(30);
1866 A.Translate3d(6, 7, 8);
1867 EXPECT_FALSE(A.IsInvertible());
1868
1869 // A degenerate matrix of all zeros is not invertible.
1870 A.MakeIdentity();
1871 A.matrix().setDouble(0, 0, 0);
1872 A.matrix().setDouble(1, 1, 0);
1873 A.matrix().setDouble(2, 2, 0);
1874 A.matrix().setDouble(3, 3, 0);
1875 EXPECT_FALSE(A.IsInvertible());
1876 }
1877
1878 TEST(XFormTest, verifyIsIdentity)
1879 {
1880 Transform A;
1881
1882 InitializeTestMatrix(&A);
1883 EXPECT_FALSE(A.IsIdentity());
1884
1885 A.MakeIdentity();
1886 EXPECT_TRUE(A.IsIdentity());
1887
1888 // Modifying any one individual element should cause the matrix to no longer
1889 // be identity.
1890 A.MakeIdentity();
1891 A.matrix().setDouble(0, 0, 2);
1892 EXPECT_FALSE(A.IsIdentity());
1893
1894 A.MakeIdentity();
1895 A.matrix().setDouble(1, 0, 2);
1896 EXPECT_FALSE(A.IsIdentity());
1897
1898 A.MakeIdentity();
1899 A.matrix().setDouble(2, 0, 2);
1900 EXPECT_FALSE(A.IsIdentity());
1901
1902 A.MakeIdentity();
1903 A.matrix().setDouble(3, 0, 2);
1904 EXPECT_FALSE(A.IsIdentity());
1905
1906 A.MakeIdentity();
1907 A.matrix().setDouble(0, 1, 2);
1908 EXPECT_FALSE(A.IsIdentity());
1909
1910 A.MakeIdentity();
1911 A.matrix().setDouble(1, 1, 2);
1912 EXPECT_FALSE(A.IsIdentity());
1913
1914 A.MakeIdentity();
1915 A.matrix().setDouble(2, 1, 2);
1916 EXPECT_FALSE(A.IsIdentity());
1917
1918 A.MakeIdentity();
1919 A.matrix().setDouble(3, 1, 2);
1920 EXPECT_FALSE(A.IsIdentity());
1921
1922 A.MakeIdentity();
1923 A.matrix().setDouble(0, 2, 2);
1924 EXPECT_FALSE(A.IsIdentity());
1925
1926 A.MakeIdentity();
1927 A.matrix().setDouble(1, 2, 2);
1928 EXPECT_FALSE(A.IsIdentity());
1929
1930 A.MakeIdentity();
1931 A.matrix().setDouble(2, 2, 2);
1932 EXPECT_FALSE(A.IsIdentity());
1933
1934 A.MakeIdentity();
1935 A.matrix().setDouble(3, 2, 2);
1936 EXPECT_FALSE(A.IsIdentity());
1937
1938 A.MakeIdentity();
1939 A.matrix().setDouble(0, 3, 2);
1940 EXPECT_FALSE(A.IsIdentity());
1941
1942 A.MakeIdentity();
1943 A.matrix().setDouble(1, 3, 2);
1944 EXPECT_FALSE(A.IsIdentity());
1945
1946 A.MakeIdentity();
1947 A.matrix().setDouble(2, 3, 2);
1948 EXPECT_FALSE(A.IsIdentity());
1949
1950 A.MakeIdentity();
1951 A.matrix().setDouble(3, 3, 2);
1952 EXPECT_FALSE(A.IsIdentity());
1953 }
1954
1955 TEST(XFormTest, verifyIsIdentityOrTranslation)
1956 {
1957 Transform A;
1958
1959 InitializeTestMatrix(&A);
1960 EXPECT_FALSE(A.IsIdentityOrTranslation());
1961
1962 A.MakeIdentity();
1963 EXPECT_TRUE(A.IsIdentityOrTranslation());
1964
1965 // Modifying any non-translation components should cause
1966 // IsIdentityOrTranslation() to return false. NOTE: (0, 3), (1, 3), and
1967 // (2, 3) are the translation components, so modifying them should still
1968 // return true.
1969 A.MakeIdentity();
1970 A.matrix().setDouble(0, 0, 2);
1971 EXPECT_FALSE(A.IsIdentityOrTranslation());
1972
1973 A.MakeIdentity();
1974 A.matrix().setDouble(1, 0, 2);
1975 EXPECT_FALSE(A.IsIdentityOrTranslation());
1976
1977 A.MakeIdentity();
1978 A.matrix().setDouble(2, 0, 2);
1979 EXPECT_FALSE(A.IsIdentityOrTranslation());
1980
1981 A.MakeIdentity();
1982 A.matrix().setDouble(3, 0, 2);
1983 EXPECT_FALSE(A.IsIdentityOrTranslation());
1984
1985 A.MakeIdentity();
1986 A.matrix().setDouble(0, 1, 2);
1987 EXPECT_FALSE(A.IsIdentityOrTranslation());
1988
1989 A.MakeIdentity();
1990 A.matrix().setDouble(1, 1, 2);
1991 EXPECT_FALSE(A.IsIdentityOrTranslation());
1992
1993 A.MakeIdentity();
1994 A.matrix().setDouble(2, 1, 2);
1995 EXPECT_FALSE(A.IsIdentityOrTranslation());
1996
1997 A.MakeIdentity();
1998 A.matrix().setDouble(3, 1, 2);
1999 EXPECT_FALSE(A.IsIdentityOrTranslation());
2000
2001 A.MakeIdentity();
2002 A.matrix().setDouble(0, 2, 2);
2003 EXPECT_FALSE(A.IsIdentityOrTranslation());
2004
2005 A.MakeIdentity();
2006 A.matrix().setDouble(1, 2, 2);
2007 EXPECT_FALSE(A.IsIdentityOrTranslation());
2008
2009 A.MakeIdentity();
2010 A.matrix().setDouble(2, 2, 2);
2011 EXPECT_FALSE(A.IsIdentityOrTranslation());
2012
2013 A.MakeIdentity();
2014 A.matrix().setDouble(3, 2, 2);
2015 EXPECT_FALSE(A.IsIdentityOrTranslation());
2016
2017 // Note carefully - expecting true here.
2018 A.MakeIdentity();
2019 A.matrix().setDouble(0, 3, 2);
2020 EXPECT_TRUE(A.IsIdentityOrTranslation());
2021
2022 // Note carefully - expecting true here.
2023 A.MakeIdentity();
2024 A.matrix().setDouble(1, 3, 2);
2025 EXPECT_TRUE(A.IsIdentityOrTranslation());
2026
2027 // Note carefully - expecting true here.
2028 A.MakeIdentity();
2029 A.matrix().setDouble(2, 3, 2);
2030 EXPECT_TRUE(A.IsIdentityOrTranslation());
2031
2032 A.MakeIdentity();
2033 A.matrix().setDouble(3, 3, 2);
2034 EXPECT_FALSE(A.IsIdentityOrTranslation());
2035 }
2036
2037 TEST(XFormTest, verifyIsScaleOrTranslation)
2038 {
2039 Transform A;
2040
2041 InitializeTestMatrix(&A);
2042 EXPECT_FALSE(A.IsScaleOrTranslation());
2043
2044 A.MakeIdentity();
2045 EXPECT_TRUE(A.IsScaleOrTranslation());
2046
2047 // Modifying any non-scale or non-translation components should cause
2048 // IsScaleOrTranslation() to return false. (0, 0), (1, 1), (2, 2), (0, 3),
2049 // (1, 3), and (2, 3) are the scale and translation components, so
2050 // modifying them should still return true.
2051
2052 // Note carefully - expecting true here.
2053 A.MakeIdentity();
2054 A.matrix().setDouble(0, 0, 2);
2055 EXPECT_TRUE(A.IsScaleOrTranslation());
2056
2057 A.MakeIdentity();
2058 A.matrix().setDouble(1, 0, 2);
2059 EXPECT_FALSE(A.IsScaleOrTranslation());
2060
2061 A.MakeIdentity();
2062 A.matrix().setDouble(2, 0, 2);
2063 EXPECT_FALSE(A.IsScaleOrTranslation());
2064
2065 A.MakeIdentity();
2066 A.matrix().setDouble(3, 0, 2);
2067 EXPECT_FALSE(A.IsScaleOrTranslation());
2068
2069 A.MakeIdentity();
2070 A.matrix().setDouble(0, 1, 2);
2071 EXPECT_FALSE(A.IsScaleOrTranslation());
2072
2073 // Note carefully - expecting true here.
2074 A.MakeIdentity();
2075 A.matrix().setDouble(1, 1, 2);
2076 EXPECT_TRUE(A.IsScaleOrTranslation());
2077
2078 A.MakeIdentity();
2079 A.matrix().setDouble(2, 1, 2);
2080 EXPECT_FALSE(A.IsScaleOrTranslation());
2081
2082 A.MakeIdentity();
2083 A.matrix().setDouble(3, 1, 2);
2084 EXPECT_FALSE(A.IsScaleOrTranslation());
2085
2086 A.MakeIdentity();
2087 A.matrix().setDouble(0, 2, 2);
2088 EXPECT_FALSE(A.IsScaleOrTranslation());
2089
2090 A.MakeIdentity();
2091 A.matrix().setDouble(1, 2, 2);
2092 EXPECT_FALSE(A.IsScaleOrTranslation());
2093
2094 // Note carefully - expecting true here.
2095 A.MakeIdentity();
2096 A.matrix().setDouble(2, 2, 2);
2097 EXPECT_TRUE(A.IsScaleOrTranslation());
2098
2099 A.MakeIdentity();
2100 A.matrix().setDouble(3, 2, 2);
2101 EXPECT_FALSE(A.IsScaleOrTranslation());
2102
2103 // Note carefully - expecting true here.
2104 A.MakeIdentity();
2105 A.matrix().setDouble(0, 3, 2);
2106 EXPECT_TRUE(A.IsScaleOrTranslation());
2107
2108 // Note carefully - expecting true here.
2109 A.MakeIdentity();
2110 A.matrix().setDouble(1, 3, 2);
2111 EXPECT_TRUE(A.IsScaleOrTranslation());
2112
2113 // Note carefully - expecting true here.
2114 A.MakeIdentity();
2115 A.matrix().setDouble(2, 3, 2);
2116 EXPECT_TRUE(A.IsScaleOrTranslation());
2117
2118 A.MakeIdentity();
2119 A.matrix().setDouble(3, 3, 2);
2120 EXPECT_FALSE(A.IsScaleOrTranslation());
2121 }
2122
1243 } // namespace 2123 } // namespace
1244 2124
1245 } // namespace gfx 2125 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698