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

Side by Side Diff: cc/math_util_unittest.cc

Issue 11308153: Migrate most of cc/ from WebKit::WebTransformationMatrix to gfx::Transform (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to tip of tree and addressed feedback Created 8 years, 1 month 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 #include "cc/math_util.h" 5 #include "cc/math_util.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "cc/test/geometry_test_utils.h" 9 #include "cc/test/geometry_test_utils.h"
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/gfx/rect.h" 12 #include "ui/gfx/rect.h"
13 #include "ui/gfx/rect_f.h" 13 #include "ui/gfx/rect_f.h"
14 #include <public/WebTransformationMatrix.h> 14 #include "ui/gfx/transform.h"
15 15
16 using WebKit::WebTransformationMatrix; 16 using gfx::Transform;
17 17
18 namespace cc { 18 namespace cc {
19 namespace { 19 namespace {
20 20
21 TEST(MathUtilTest, verifyBackfaceVisibilityBasicCases) 21 TEST(MathUtilTest, verifyBackfaceVisibilityBasicCases)
22 { 22 {
23 WebTransformationMatrix transform; 23 Transform transform;
24 24
25 transform.makeIdentity(); 25 transform.matrix().setIdentity();
26 EXPECT_FALSE(transform.isBackFaceVisible()); 26 EXPECT_FALSE(MathUtil::isBackFaceVisible(transform));
27 27
28 transform.makeIdentity(); 28 transform.matrix().setIdentity();
29 transform.rotate3d(0, 80, 0); 29 MathUtil::rotateEulerAngles(&transform, 0, 80, 0);
30 EXPECT_FALSE(transform.isBackFaceVisible()); 30 EXPECT_FALSE(MathUtil::isBackFaceVisible(transform));
31 31
32 transform.makeIdentity(); 32 transform.matrix().setIdentity();
33 transform.rotate3d(0, 100, 0); 33 MathUtil::rotateEulerAngles(&transform, 0, 100, 0);
34 EXPECT_TRUE(transform.isBackFaceVisible()); 34 EXPECT_TRUE(MathUtil::isBackFaceVisible(transform));
35 35
36 // Edge case, 90 degree rotation should return false. 36 // Edge case, 90 degree rotation should return false.
37 transform.makeIdentity(); 37 transform.matrix().setIdentity();
38 transform.rotate3d(0, 90, 0); 38 MathUtil::rotateEulerAngles(&transform, 0, 90, 0);
39 EXPECT_FALSE(transform.isBackFaceVisible()); 39 EXPECT_FALSE(MathUtil::isBackFaceVisible(transform));
40 } 40 }
41 41
42 TEST(MathUtilTest, verifyBackfaceVisibilityForPerspective) 42 TEST(MathUtilTest, verifyBackfaceVisibilityForPerspective)
43 { 43 {
44 WebTransformationMatrix layerSpaceToProjectionPlane; 44 Transform layerSpaceToProjectionPlane;
45 45
46 // This tests if isBackFaceVisible works properly under perspective transfor ms. 46 // This tests if isBackFaceVisible works properly under perspective transfor ms.
47 // Specifically, layers that may have their back face visible in orthographi c 47 // Specifically, layers that may have their back face visible in orthographi c
48 // projection, may not actually have back face visible under perspective pro jection. 48 // projection, may not actually have back face visible under perspective pro jection.
49 49
50 // Case 1: Layer is rotated by slightly more than 90 degrees, at the center of the 50 // Case 1: Layer is rotated by slightly more than 90 degrees, at the center of the
51 // prespective projection. In this case, the layer's back-side is vi sible to 51 // prespective projection. In this case, the layer's back-side is vi sible to
52 // the camera. 52 // the camera.
53 layerSpaceToProjectionPlane.makeIdentity(); 53 layerSpaceToProjectionPlane.matrix().setIdentity();
54 layerSpaceToProjectionPlane.applyPerspective(1); 54 layerSpaceToProjectionPlane.PreconcatPerspectiveDepth(1);
55 layerSpaceToProjectionPlane.translate3d(0, 0, 0); 55 layerSpaceToProjectionPlane.PreconcatTranslate3d(0, 0, 0);
56 layerSpaceToProjectionPlane.rotate3d(0, 100, 0); 56 MathUtil::rotateEulerAngles(&layerSpaceToProjectionPlane, 0, 100, 0);
57 EXPECT_TRUE(layerSpaceToProjectionPlane.isBackFaceVisible()); 57 EXPECT_TRUE(MathUtil::isBackFaceVisible(layerSpaceToProjectionPlane));
58 58
59 // Case 2: Layer is rotated by slightly more than 90 degrees, but shifted of f to the 59 // Case 2: Layer is rotated by slightly more than 90 degrees, but shifted of f to the
60 // side of the camera. Because of the wide field-of-view, the layer' s front 60 // side of the camera. Because of the wide field-of-view, the layer' s front
61 // side is still visible. 61 // side is still visible.
62 // 62 //
63 // |<-- front side of layer is visible to perspective camera 63 // |<-- front side of layer is visible to perspective camera
64 // \ | / 64 // \ | /
65 // \ | / 65 // \ | /
66 // \| / 66 // \| /
67 // | / 67 // | /
68 // |\ /<-- camera field of view 68 // |\ /<-- camera field of view
69 // | \ / 69 // | \ /
70 // back side of layer -->| \ / 70 // back side of layer -->| \ /
71 // \./ <-- camera origin 71 // \./ <-- camera origin
72 // 72 //
73 layerSpaceToProjectionPlane.makeIdentity(); 73 layerSpaceToProjectionPlane.matrix().setIdentity();
74 layerSpaceToProjectionPlane.applyPerspective(1); 74 layerSpaceToProjectionPlane.PreconcatPerspectiveDepth(1);
75 layerSpaceToProjectionPlane.translate3d(-10, 0, 0); 75 layerSpaceToProjectionPlane.PreconcatTranslate3d(-10, 0, 0);
76 layerSpaceToProjectionPlane.rotate3d(0, 100, 0); 76 MathUtil::rotateEulerAngles(&layerSpaceToProjectionPlane, 0, 100, 0);
77 EXPECT_FALSE(layerSpaceToProjectionPlane.isBackFaceVisible()); 77 EXPECT_FALSE(MathUtil::isBackFaceVisible(layerSpaceToProjectionPlane));
78 78
79 // Case 3: Additionally rotating the layer by 180 degrees should of course s how the 79 // Case 3: Additionally rotating the layer by 180 degrees should of course s how the
80 // opposite result of case 2. 80 // opposite result of case 2.
81 layerSpaceToProjectionPlane.rotate3d(0, 180, 0); 81 MathUtil::rotateEulerAngles(&layerSpaceToProjectionPlane, 0, 180, 0);
82 EXPECT_TRUE(layerSpaceToProjectionPlane.isBackFaceVisible()); 82 EXPECT_TRUE(MathUtil::isBackFaceVisible(layerSpaceToProjectionPlane));
83 } 83 }
84 84
85 TEST(MathUtilTest, verifyProjectionOfPerpendicularPlane) 85 TEST(MathUtilTest, verifyProjectionOfPerpendicularPlane)
86 { 86 {
87 // In this case, the m33() element of the transform becomes zero, which coul d cause a 87 // In this case, the m33() element of the transform becomes zero, which coul d cause a
88 // divide-by-zero when projecting points/quads. 88 // divide-by-zero when projecting points/quads.
89 89
90 WebTransformationMatrix transform; 90 Transform transform;
91 transform.makeIdentity(); 91 transform.matrix().setIdentity();
92 transform.setM33(0); 92 transform.matrix().setDouble(2, 2, 0);
93 93
94 gfx::RectF rect = gfx::RectF(0, 0, 1, 1); 94 gfx::RectF rect = gfx::RectF(0, 0, 1, 1);
95 gfx::RectF projectedRect = MathUtil::projectClippedRect(transform, rect); 95 gfx::RectF projectedRect = MathUtil::projectClippedRect(transform, rect);
96 96
97 EXPECT_EQ(0, projectedRect.x()); 97 EXPECT_EQ(0, projectedRect.x());
98 EXPECT_EQ(0, projectedRect.y()); 98 EXPECT_EQ(0, projectedRect.y());
99 EXPECT_TRUE(projectedRect.IsEmpty()); 99 EXPECT_TRUE(projectedRect.IsEmpty());
100 } 100 }
101 101
102 TEST(MathUtilTest, verifyEnclosingClippedRectUsesCorrectInitialBounds) 102 TEST(MathUtilTest, verifyEnclosingClippedRectUsesCorrectInitialBounds)
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 EXPECT_ROW4_EQ(33, 37, 41, 45, (*transform)); 286 EXPECT_ROW4_EQ(33, 37, 41, 45, (*transform));
287 } 287 }
288 288
289 TEST(MathUtilGfxTransformTest, verifyDefaultConstructorCreatesIdentityMatrix) 289 TEST(MathUtilGfxTransformTest, verifyDefaultConstructorCreatesIdentityMatrix)
290 { 290 {
291 gfx::Transform A; 291 gfx::Transform A;
292 EXPECT_ROW1_EQ(1, 0, 0, 0, A); 292 EXPECT_ROW1_EQ(1, 0, 0, 0, A);
293 EXPECT_ROW2_EQ(0, 1, 0, 0, A); 293 EXPECT_ROW2_EQ(0, 1, 0, 0, A);
294 EXPECT_ROW3_EQ(0, 0, 1, 0, A); 294 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
295 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 295 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
296 EXPECT_TRUE(MathUtil::isIdentity(A)); 296 EXPECT_TRUE(A.IsIdentity());
297 } 297 }
298 298
299 TEST(MathUtilGfxTransformTest, verifyCreateGfxTransformFor2dElements) 299 TEST(MathUtilGfxTransformTest, verifyCreateGfxTransformFor2dElements)
300 { 300 {
301 gfx::Transform A = MathUtil::createGfxTransform(1, 2, 3, 4, 5, 6); 301 gfx::Transform A = MathUtil::createGfxTransform(1, 2, 3, 4, 5, 6);
302 EXPECT_ROW1_EQ(1, 3, 0, 5, A); 302 EXPECT_ROW1_EQ(1, 3, 0, 5, A);
303 EXPECT_ROW2_EQ(2, 4, 0, 6, A); 303 EXPECT_ROW2_EQ(2, 4, 0, 6, A);
304 EXPECT_ROW3_EQ(0, 0, 1, 0, A); 304 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
305 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 305 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
306 } 306 }
(...skipping 18 matching lines...) Expand all
325 EXPECT_ROW2_EQ(11, 15, 19, 23, B); 325 EXPECT_ROW2_EQ(11, 15, 19, 23, B);
326 EXPECT_ROW3_EQ(12, 16, 20, 24, B); 326 EXPECT_ROW3_EQ(12, 16, 20, 24, B);
327 EXPECT_ROW4_EQ(13, 17, 21, 25, B); 327 EXPECT_ROW4_EQ(13, 17, 21, 25, B);
328 } 328 }
329 329
330 TEST(MathUtilGfxTransformTest, verifyMatrixInversion) 330 TEST(MathUtilGfxTransformTest, verifyMatrixInversion)
331 { 331 {
332 // Invert a translation 332 // Invert a translation
333 gfx::Transform translation; 333 gfx::Transform translation;
334 translation.PreconcatTranslate3d(2, 3, 4); 334 translation.PreconcatTranslate3d(2, 3, 4);
335 EXPECT_TRUE(MathUtil::isInvertible(translation)); 335 EXPECT_TRUE(translation.IsInvertible());
336 336
337 gfx::Transform inverseTranslation = MathUtil::inverse(translation); 337 gfx::Transform inverseTranslation = MathUtil::inverse(translation);
338 EXPECT_ROW1_EQ(1, 0, 0, -2, inverseTranslation); 338 EXPECT_ROW1_EQ(1, 0, 0, -2, inverseTranslation);
339 EXPECT_ROW2_EQ(0, 1, 0, -3, inverseTranslation); 339 EXPECT_ROW2_EQ(0, 1, 0, -3, inverseTranslation);
340 EXPECT_ROW3_EQ(0, 0, 1, -4, inverseTranslation); 340 EXPECT_ROW3_EQ(0, 0, 1, -4, inverseTranslation);
341 EXPECT_ROW4_EQ(0, 0, 0, 1, inverseTranslation); 341 EXPECT_ROW4_EQ(0, 0, 0, 1, inverseTranslation);
342 342
343 // Note that inversion should not have changed the original matrix. 343 // Note that inversion should not have changed the original matrix.
344 EXPECT_ROW1_EQ(1, 0, 0, 2, translation); 344 EXPECT_ROW1_EQ(1, 0, 0, 2, translation);
345 EXPECT_ROW2_EQ(0, 1, 0, 3, translation); 345 EXPECT_ROW2_EQ(0, 1, 0, 3, translation);
346 EXPECT_ROW3_EQ(0, 0, 1, 4, translation); 346 EXPECT_ROW3_EQ(0, 0, 1, 4, translation);
347 EXPECT_ROW4_EQ(0, 0, 0, 1, translation); 347 EXPECT_ROW4_EQ(0, 0, 0, 1, translation);
348 348
349 // Invert a non-uniform scale 349 // Invert a non-uniform scale
350 gfx::Transform scale; 350 gfx::Transform scale;
351 scale.PreconcatScale3d(4, 10, 100); 351 scale.PreconcatScale3d(4, 10, 100);
352 EXPECT_TRUE(MathUtil::isInvertible(scale)); 352 EXPECT_TRUE(scale.IsInvertible());
353 353
354 gfx::Transform inverseScale = MathUtil::inverse(scale); 354 gfx::Transform inverseScale = MathUtil::inverse(scale);
355 EXPECT_ROW1_EQ(0.25, 0, 0, 0, inverseScale); 355 EXPECT_ROW1_EQ(0.25, 0, 0, 0, inverseScale);
356 EXPECT_ROW2_EQ(0, .1f, 0, 0, inverseScale); 356 EXPECT_ROW2_EQ(0, .1f, 0, 0, inverseScale);
357 EXPECT_ROW3_EQ(0, 0, .01f, 0, inverseScale); 357 EXPECT_ROW3_EQ(0, 0, .01f, 0, inverseScale);
358 EXPECT_ROW4_EQ(0, 0, 0, 1, inverseScale); 358 EXPECT_ROW4_EQ(0, 0, 0, 1, inverseScale);
359 359
360 // Try to invert a matrix that is not invertible. 360 // Try to invert a matrix that is not invertible.
361 // The inverse() function should simply return an identity matrix. 361 // The inverse() function should simply return an identity matrix.
362 gfx::Transform notInvertible; 362 gfx::Transform notInvertible;
363 notInvertible.matrix().setDouble(0, 0, 0); 363 notInvertible.matrix().setDouble(0, 0, 0);
364 notInvertible.matrix().setDouble(1, 1, 0); 364 notInvertible.matrix().setDouble(1, 1, 0);
365 notInvertible.matrix().setDouble(2, 2, 0); 365 notInvertible.matrix().setDouble(2, 2, 0);
366 notInvertible.matrix().setDouble(3, 3, 0); 366 notInvertible.matrix().setDouble(3, 3, 0);
367 EXPECT_FALSE(MathUtil::isInvertible(notInvertible)); 367 EXPECT_FALSE(notInvertible.IsInvertible());
368 368
369 gfx::Transform inverseOfNotInvertible; 369 gfx::Transform inverseOfNotInvertible;
370 initializeTestMatrix(&inverseOfNotInvertible); // initialize this to somethi ng non-identity, to make sure that assignment below actually took place. 370 initializeTestMatrix(&inverseOfNotInvertible); // initialize this to somethi ng non-identity, to make sure that assignment below actually took place.
371 inverseOfNotInvertible = MathUtil::inverse(notInvertible); 371 inverseOfNotInvertible = MathUtil::inverse(notInvertible);
372 EXPECT_TRUE(MathUtil::isIdentity(inverseOfNotInvertible)); 372 EXPECT_TRUE(inverseOfNotInvertible.IsIdentity());
373 } 373 }
374 374
375 TEST(MathUtilGfxTransformTest, verifyTo2DTransform) 375 TEST(MathUtilGfxTransformTest, verifyTo2DTransform)
376 { 376 {
377 gfx::Transform A; 377 gfx::Transform A;
378 initializeTestMatrix(&A); 378 initializeTestMatrix(&A);
379 379
380 gfx::Transform B = MathUtil::to2dTransform(A); 380 gfx::Transform B = MathUtil::to2dTransform(A);
381 381
382 EXPECT_ROW1_EQ(10, 14, 0, 22, B); 382 EXPECT_ROW1_EQ(10, 14, 0, 22, B);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 EXPECT_ROW1_EQ(2036, 2292, 2548, 2804, A); 524 EXPECT_ROW1_EQ(2036, 2292, 2548, 2804, A);
525 EXPECT_ROW2_EQ(2162, 2434, 2706, 2978, A); 525 EXPECT_ROW2_EQ(2162, 2434, 2706, 2978, A);
526 EXPECT_ROW3_EQ(2288, 2576, 2864, 3152, A); 526 EXPECT_ROW3_EQ(2288, 2576, 2864, 3152, A);
527 EXPECT_ROW4_EQ(2414, 2718, 3022, 3326, A); 527 EXPECT_ROW4_EQ(2414, 2718, 3022, 3326, A);
528 } 528 }
529 529
530 TEST(MathUtilGfxTransformTest, verifyMakeIdentiy) 530 TEST(MathUtilGfxTransformTest, verifyMakeIdentiy)
531 { 531 {
532 gfx::Transform A; 532 gfx::Transform A;
533 initializeTestMatrix(&A); 533 initializeTestMatrix(&A);
534 MathUtil::makeIdentity(&A); 534 A.matrix().setIdentity();
535 EXPECT_ROW1_EQ(1, 0, 0, 0, A); 535 EXPECT_ROW1_EQ(1, 0, 0, 0, A);
536 EXPECT_ROW2_EQ(0, 1, 0, 0, A); 536 EXPECT_ROW2_EQ(0, 1, 0, 0, A);
537 EXPECT_ROW3_EQ(0, 0, 1, 0, A); 537 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
538 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 538 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
539 EXPECT_TRUE(MathUtil::isIdentity(A)); 539 EXPECT_TRUE(A.IsIdentity());
540 } 540 }
541 541
542 TEST(MathUtilGfxTransformTest, verifyTranslate) 542 TEST(MathUtilGfxTransformTest, verifyTranslate)
543 { 543 {
544 gfx::Transform A; 544 gfx::Transform A;
545 A.PreconcatTranslate(2, 3); 545 A.PreconcatTranslate(2, 3);
546 EXPECT_ROW1_EQ(1, 0, 0, 2, A); 546 EXPECT_ROW1_EQ(1, 0, 0, 2, A);
547 EXPECT_ROW2_EQ(0, 1, 0, 3, A); 547 EXPECT_ROW2_EQ(0, 1, 0, 3, A);
548 EXPECT_ROW3_EQ(0, 0, 1, 0, A); 548 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
549 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 549 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
550 550
551 // Verify that PreconcatTranslate() post-multiplies the existing matrix. 551 // Verify that PreconcatTranslate() post-multiplies the existing matrix.
552 MathUtil::makeIdentity(&A); 552 A.matrix().setIdentity();
553 A.PreconcatScale(5, 5); 553 A.PreconcatScale(5, 5);
554 A.PreconcatTranslate(2, 3); 554 A.PreconcatTranslate(2, 3);
555 EXPECT_ROW1_EQ(5, 0, 0, 10, A); 555 EXPECT_ROW1_EQ(5, 0, 0, 10, A);
556 EXPECT_ROW2_EQ(0, 5, 0, 15, A); 556 EXPECT_ROW2_EQ(0, 5, 0, 15, A);
557 EXPECT_ROW3_EQ(0, 0, 1, 0, A); 557 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
558 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 558 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
559 } 559 }
560 560
561 TEST(MathUtilGfxTransformTest, verifyTranslate3d) 561 TEST(MathUtilGfxTransformTest, verifyTranslate3d)
562 { 562 {
563 gfx::Transform A; 563 gfx::Transform A;
564 A.PreconcatTranslate3d(2, 3, 4); 564 A.PreconcatTranslate3d(2, 3, 4);
565 EXPECT_ROW1_EQ(1, 0, 0, 2, A); 565 EXPECT_ROW1_EQ(1, 0, 0, 2, A);
566 EXPECT_ROW2_EQ(0, 1, 0, 3, A); 566 EXPECT_ROW2_EQ(0, 1, 0, 3, A);
567 EXPECT_ROW3_EQ(0, 0, 1, 4, A); 567 EXPECT_ROW3_EQ(0, 0, 1, 4, A);
568 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 568 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
569 569
570 // Verify that PreconcatTranslate3d() post-multiplies the existing matrix. 570 // Verify that PreconcatTranslate3d() post-multiplies the existing matrix.
571 MathUtil::makeIdentity(&A); 571 A.matrix().setIdentity();
572 A.PreconcatScale3d(6, 7, 8); 572 A.PreconcatScale3d(6, 7, 8);
573 A.PreconcatTranslate3d(2, 3, 4); 573 A.PreconcatTranslate3d(2, 3, 4);
574 EXPECT_ROW1_EQ(6, 0, 0, 12, A); 574 EXPECT_ROW1_EQ(6, 0, 0, 12, A);
575 EXPECT_ROW2_EQ(0, 7, 0, 21, A); 575 EXPECT_ROW2_EQ(0, 7, 0, 21, A);
576 EXPECT_ROW3_EQ(0, 0, 8, 32, A); 576 EXPECT_ROW3_EQ(0, 0, 8, 32, A);
577 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 577 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
578 } 578 }
579 579
580 TEST(MathUtilGfxTransformTest, verifyScale) 580 TEST(MathUtilGfxTransformTest, verifyScale)
581 { 581 {
582 gfx::Transform A; 582 gfx::Transform A;
583 A.PreconcatScale(6, 7); 583 A.PreconcatScale(6, 7);
584 EXPECT_ROW1_EQ(6, 0, 0, 0, A); 584 EXPECT_ROW1_EQ(6, 0, 0, 0, A);
585 EXPECT_ROW2_EQ(0, 7, 0, 0, A); 585 EXPECT_ROW2_EQ(0, 7, 0, 0, A);
586 EXPECT_ROW3_EQ(0, 0, 1, 0, A); 586 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
587 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 587 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
588 588
589 // Verify that PreconcatScale() post-multiplies the existing matrix. 589 // Verify that PreconcatScale() post-multiplies the existing matrix.
590 MathUtil::makeIdentity(&A); 590 A.matrix().setIdentity();
591 A.PreconcatTranslate3d(2, 3, 4); 591 A.PreconcatTranslate3d(2, 3, 4);
592 A.PreconcatScale(6, 7); 592 A.PreconcatScale(6, 7);
593 EXPECT_ROW1_EQ(6, 0, 0, 2, A); 593 EXPECT_ROW1_EQ(6, 0, 0, 2, A);
594 EXPECT_ROW2_EQ(0, 7, 0, 3, A); 594 EXPECT_ROW2_EQ(0, 7, 0, 3, A);
595 EXPECT_ROW3_EQ(0, 0, 1, 4, A); 595 EXPECT_ROW3_EQ(0, 0, 1, 4, A);
596 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 596 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
597 } 597 }
598 598
599 TEST(MathUtilGfxTransformTest, verifyScale3d) 599 TEST(MathUtilGfxTransformTest, verifyScale3d)
600 { 600 {
601 gfx::Transform A; 601 gfx::Transform A;
602 A.PreconcatScale3d(6, 7, 8); 602 A.PreconcatScale3d(6, 7, 8);
603 EXPECT_ROW1_EQ(6, 0, 0, 0, A); 603 EXPECT_ROW1_EQ(6, 0, 0, 0, A);
604 EXPECT_ROW2_EQ(0, 7, 0, 0, A); 604 EXPECT_ROW2_EQ(0, 7, 0, 0, A);
605 EXPECT_ROW3_EQ(0, 0, 8, 0, A); 605 EXPECT_ROW3_EQ(0, 0, 8, 0, A);
606 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 606 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
607 607
608 // Verify that scale3d() post-multiplies the existing matrix. 608 // Verify that scale3d() post-multiplies the existing matrix.
609 MathUtil::makeIdentity(&A); 609 A.matrix().setIdentity();
610 A.PreconcatTranslate3d(2, 3, 4); 610 A.PreconcatTranslate3d(2, 3, 4);
611 A.PreconcatScale3d(6, 7, 8); 611 A.PreconcatScale3d(6, 7, 8);
612 EXPECT_ROW1_EQ(6, 0, 0, 2, A); 612 EXPECT_ROW1_EQ(6, 0, 0, 2, A);
613 EXPECT_ROW2_EQ(0, 7, 0, 3, A); 613 EXPECT_ROW2_EQ(0, 7, 0, 3, A);
614 EXPECT_ROW3_EQ(0, 0, 8, 4, A); 614 EXPECT_ROW3_EQ(0, 0, 8, 4, A);
615 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 615 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
616 } 616 }
617 617
618 TEST(MathUtilGfxTransformTest, verifyRotate) 618 TEST(MathUtilGfxTransformTest, verifyRotate)
619 { 619 {
620 gfx::Transform A; 620 gfx::Transform A;
621 A.PreconcatRotate(90); 621 A.PreconcatRotate(90);
622 EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD); 622 EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD);
623 EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD); 623 EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD);
624 EXPECT_ROW3_EQ(0, 0, 1, 0, A); 624 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
625 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 625 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
626 626
627 // Verify that PreconcatRotate() post-multiplies the existing matrix. 627 // Verify that PreconcatRotate() post-multiplies the existing matrix.
628 MathUtil::makeIdentity(&A); 628 A.matrix().setIdentity();
629 A.PreconcatScale3d(6, 7, 8); 629 A.PreconcatScale3d(6, 7, 8);
630 A.PreconcatRotate(90); 630 A.PreconcatRotate(90);
631 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD); 631 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD);
632 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD); 632 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD);
633 EXPECT_ROW3_EQ(0, 0, 8, 0, A); 633 EXPECT_ROW3_EQ(0, 0, 8, 0, A);
634 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 634 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
635 } 635 }
636 636
637 TEST(MathUtilGfxTransformTest, verifyRotateEulerAngles) 637 TEST(MathUtilGfxTransformTest, verifyRotateEulerAngles)
638 { 638 {
639 gfx::Transform A; 639 gfx::Transform A;
640 640
641 // Check rotation about z-axis 641 // Check rotation about z-axis
642 MathUtil::makeIdentity(&A); 642 A.matrix().setIdentity();
643 MathUtil::rotateEulerAngles(&A, 0, 0, 90); 643 MathUtil::rotateEulerAngles(&A, 0, 0, 90);
644 EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD); 644 EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD);
645 EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD); 645 EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD);
646 EXPECT_ROW3_EQ(0, 0, 1, 0, A); 646 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
647 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 647 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
648 648
649 // Check rotation about x-axis 649 // Check rotation about x-axis
650 MathUtil::makeIdentity(&A); 650 A.matrix().setIdentity();
651 MathUtil::rotateEulerAngles(&A, 90, 0, 0); 651 MathUtil::rotateEulerAngles(&A, 90, 0, 0);
652 EXPECT_ROW1_EQ(1, 0, 0, 0, A); 652 EXPECT_ROW1_EQ(1, 0, 0, 0, A);
653 EXPECT_ROW2_NEAR(0, 0, -1, 0, A, ERROR_THRESHOLD); 653 EXPECT_ROW2_NEAR(0, 0, -1, 0, A, ERROR_THRESHOLD);
654 EXPECT_ROW3_NEAR(0, 1, 0, 0, A, ERROR_THRESHOLD); 654 EXPECT_ROW3_NEAR(0, 1, 0, 0, A, ERROR_THRESHOLD);
655 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 655 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
656 656
657 // Check rotation about y-axis. 657 // Check rotation about y-axis.
658 // Note carefully, the expected pattern is inverted compared to rotating abo ut x axis or z axis. 658 // Note carefully, the expected pattern is inverted compared to rotating abo ut x axis or z axis.
659 MathUtil::makeIdentity(&A); 659 A.matrix().setIdentity();
660 MathUtil::rotateEulerAngles(&A, 0, 90, 0); 660 MathUtil::rotateEulerAngles(&A, 0, 90, 0);
661 EXPECT_ROW1_NEAR(0, 0, 1, 0, A, ERROR_THRESHOLD); 661 EXPECT_ROW1_NEAR(0, 0, 1, 0, A, ERROR_THRESHOLD);
662 EXPECT_ROW2_EQ(0, 1, 0, 0, A); 662 EXPECT_ROW2_EQ(0, 1, 0, 0, A);
663 EXPECT_ROW3_NEAR(-1, 0, 0, 0, A, ERROR_THRESHOLD); 663 EXPECT_ROW3_NEAR(-1, 0, 0, 0, A, ERROR_THRESHOLD);
664 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 664 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
665 665
666 // Verify that rotate3d(rx, ry, rz) post-multiplies the existing matrix. 666 // Verify that rotate3d(rx, ry, rz) post-multiplies the existing matrix.
667 MathUtil::makeIdentity(&A); 667 A.matrix().setIdentity();
668 A.PreconcatScale3d(6, 7, 8); 668 A.PreconcatScale3d(6, 7, 8);
669 MathUtil::rotateEulerAngles(&A, 0, 0, 90); 669 MathUtil::rotateEulerAngles(&A, 0, 0, 90);
670 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD); 670 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD);
671 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD); 671 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD);
672 EXPECT_ROW3_EQ(0, 0, 8, 0, A); 672 EXPECT_ROW3_EQ(0, 0, 8, 0, A);
673 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 673 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
674 } 674 }
675 675
676 TEST(MathUtilGfxTransformTest, verifyRotateEulerAnglesOrderOfCompositeRotations) 676 TEST(MathUtilGfxTransformTest, verifyRotateEulerAnglesOrderOfCompositeRotations)
677 { 677 {
678 // Rotate3d(degreesX, degreesY, degreesZ) is actually composite transform co nsiting of 678 // Rotate3d(degreesX, degreesY, degreesZ) is actually composite transform co nsiting of
679 // three primitive rotations. This test verifies that the ordering of those three 679 // three primitive rotations. This test verifies that the ordering of those three
680 // transforms is the intended ordering. 680 // transforms is the intended ordering.
681 // 681 //
682 // The correct ordering for this test case should be: 682 // The correct ordering for this test case should be:
683 // 1. rotate by 30 degrees about z-axis 683 // 1. rotate by 30 degrees about z-axis
684 // 2. rotate by 20 degrees about y-axis 684 // 2. rotate by 20 degrees about y-axis
685 // 3. rotate by 10 degrees about x-axis 685 // 3. rotate by 10 degrees about x-axis
686 // 686 //
687 // Note: there are 6 possible orderings of 3 transforms. For the specific tr ansforms 687 // Note: there are 6 possible orderings of 3 transforms. For the specific tr ansforms
688 // used in this test, all 6 combinations produce a unique matrix that is dif ferent 688 // used in this test, all 6 combinations produce a unique matrix that is dif ferent
689 // from the other orderings. That way, this test verifies the exact ordering . 689 // from the other orderings. That way, this test verifies the exact ordering .
690 690
691 gfx::Transform A; 691 gfx::Transform A;
692 MathUtil::makeIdentity(&A); 692 A.matrix().setIdentity();
693 MathUtil::rotateEulerAngles(&A, 10, 20, 30); 693 MathUtil::rotateEulerAngles(&A, 10, 20, 30);
694 694
695 EXPECT_ROW1_NEAR(0.8137976813493738026394908, 695 EXPECT_ROW1_NEAR(0.8137976813493738026394908,
696 -0.4409696105298823720630708, 696 -0.4409696105298823720630708,
697 0.3785223063697923939763257, 697 0.3785223063697923939763257,
698 0, A, ERROR_THRESHOLD); 698 0, A, ERROR_THRESHOLD);
699 EXPECT_ROW2_NEAR(0.4698463103929541584413698, 699 EXPECT_ROW2_NEAR(0.4698463103929541584413698,
700 0.8825641192593856043657752, 700 0.8825641192593856043657752,
701 0.0180283112362972230968694, 701 0.0180283112362972230968694,
702 0, A, ERROR_THRESHOLD); 702 0, A, ERROR_THRESHOLD);
703 EXPECT_ROW3_NEAR(-0.3420201433256686573969318, 703 EXPECT_ROW3_NEAR(-0.3420201433256686573969318,
704 0.1631759111665348205288950, 704 0.1631759111665348205288950,
705 0.9254165783983233639631294, 705 0.9254165783983233639631294,
706 0, A, ERROR_THRESHOLD); 706 0, A, ERROR_THRESHOLD);
707 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 707 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
708 } 708 }
709 709
710 TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForAlignedAxes) 710 TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForAlignedAxes)
711 { 711 {
712 gfx::Transform A; 712 gfx::Transform A;
713 713
714 // Check rotation about z-axis 714 // Check rotation about z-axis
715 MathUtil::makeIdentity(&A); 715 A.matrix().setIdentity();
716 MathUtil::rotateAxisAngle(&A, 0, 0, 1, 90); 716 MathUtil::rotateAxisAngle(&A, 0, 0, 1, 90);
717 EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD); 717 EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD);
718 EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD); 718 EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD);
719 EXPECT_ROW3_EQ(0, 0, 1, 0, A); 719 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
720 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 720 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
721 721
722 // Check rotation about x-axis 722 // Check rotation about x-axis
723 MathUtil::makeIdentity(&A); 723 A.matrix().setIdentity();
724 MathUtil::rotateAxisAngle(&A, 1, 0, 0, 90); 724 MathUtil::rotateAxisAngle(&A, 1, 0, 0, 90);
725 EXPECT_ROW1_EQ(1, 0, 0, 0, A); 725 EXPECT_ROW1_EQ(1, 0, 0, 0, A);
726 EXPECT_ROW2_NEAR(0, 0, -1, 0, A, ERROR_THRESHOLD); 726 EXPECT_ROW2_NEAR(0, 0, -1, 0, A, ERROR_THRESHOLD);
727 EXPECT_ROW3_NEAR(0, 1, 0, 0, A, ERROR_THRESHOLD); 727 EXPECT_ROW3_NEAR(0, 1, 0, 0, A, ERROR_THRESHOLD);
728 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 728 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
729 729
730 // Check rotation about y-axis. 730 // Check rotation about y-axis.
731 // Note carefully, the expected pattern is inverted compared to rotating abo ut x axis or z axis. 731 // Note carefully, the expected pattern is inverted compared to rotating abo ut x axis or z axis.
732 MathUtil::makeIdentity(&A); 732 A.matrix().setIdentity();
733 MathUtil::rotateAxisAngle(&A, 0, 1, 0, 90); 733 MathUtil::rotateAxisAngle(&A, 0, 1, 0, 90);
734 EXPECT_ROW1_NEAR(0, 0, 1, 0, A, ERROR_THRESHOLD); 734 EXPECT_ROW1_NEAR(0, 0, 1, 0, A, ERROR_THRESHOLD);
735 EXPECT_ROW2_EQ(0, 1, 0, 0, A); 735 EXPECT_ROW2_EQ(0, 1, 0, 0, A);
736 EXPECT_ROW3_NEAR(-1, 0, 0, 0, A, ERROR_THRESHOLD); 736 EXPECT_ROW3_NEAR(-1, 0, 0, 0, A, ERROR_THRESHOLD);
737 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 737 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
738 738
739 // Verify that rotate3d(axis, angle) post-multiplies the existing matrix. 739 // Verify that rotate3d(axis, angle) post-multiplies the existing matrix.
740 MathUtil::makeIdentity(&A); 740 A.matrix().setIdentity();
741 A.PreconcatScale3d(6, 7, 8); 741 A.PreconcatScale3d(6, 7, 8);
742 MathUtil::rotateAxisAngle(&A, 0, 0, 1, 90); 742 MathUtil::rotateAxisAngle(&A, 0, 0, 1, 90);
743 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD); 743 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD);
744 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD); 744 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD);
745 EXPECT_ROW3_EQ(0, 0, 8, 0, A); 745 EXPECT_ROW3_EQ(0, 0, 8, 0, A);
746 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 746 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
747 } 747 }
748 748
749 TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForArbitraryAxis) 749 TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForArbitraryAxis)
750 { 750 {
(...skipping 16 matching lines...) Expand all
767 } 767 }
768 768
769 TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForDegenerateAxis) 769 TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForDegenerateAxis)
770 { 770 {
771 // Check rotation about a degenerate zero vector. 771 // Check rotation about a degenerate zero vector.
772 // It is expected to skip applying the rotation. 772 // It is expected to skip applying the rotation.
773 gfx::Transform A; 773 gfx::Transform A;
774 774
775 MathUtil::rotateAxisAngle(&A, 0, 0, 0, 45); 775 MathUtil::rotateAxisAngle(&A, 0, 0, 0, 45);
776 // Verify that A remains unchanged. 776 // Verify that A remains unchanged.
777 EXPECT_TRUE(MathUtil::isIdentity(A)); 777 EXPECT_TRUE(A.IsIdentity());
778 778
779 initializeTestMatrix(&A); 779 initializeTestMatrix(&A);
780 MathUtil::rotateAxisAngle(&A, 0, 0, 0, 35); 780 MathUtil::rotateAxisAngle(&A, 0, 0, 0, 35);
781 781
782 // Verify that A remains unchanged. 782 // Verify that A remains unchanged.
783 EXPECT_ROW1_EQ(10, 14, 18, 22, A); 783 EXPECT_ROW1_EQ(10, 14, 18, 22, A);
784 EXPECT_ROW2_EQ(11, 15, 19, 23, A); 784 EXPECT_ROW2_EQ(11, 15, 19, 23, A);
785 EXPECT_ROW3_EQ(12, 16, 20, 24, A); 785 EXPECT_ROW3_EQ(12, 16, 20, 24, A);
786 EXPECT_ROW4_EQ(13, 17, 21, 25, A); 786 EXPECT_ROW4_EQ(13, 17, 21, 25, A);
787 } 787 }
788 788
789 TEST(MathUtilGfxTransformTest, verifySkewX) 789 TEST(MathUtilGfxTransformTest, verifySkewX)
790 { 790 {
791 gfx::Transform A; 791 gfx::Transform A;
792 A.PreconcatSkewX(45); 792 A.PreconcatSkewX(45);
793 EXPECT_ROW1_EQ(1, 1, 0, 0, A); 793 EXPECT_ROW1_EQ(1, 1, 0, 0, A);
794 EXPECT_ROW2_EQ(0, 1, 0, 0, A); 794 EXPECT_ROW2_EQ(0, 1, 0, 0, A);
795 EXPECT_ROW3_EQ(0, 0, 1, 0, A); 795 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
796 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 796 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
797 797
798 // Verify that skewX() post-multiplies the existing matrix. 798 // Verify that skewX() post-multiplies the existing matrix.
799 // Row 1, column 2, would incorrectly have value "7" if the matrix is pre-mu ltiplied instead of post-multiplied. 799 // Row 1, column 2, would incorrectly have value "7" if the matrix is pre-mu ltiplied instead of post-multiplied.
800 MathUtil::makeIdentity(&A); 800 A.matrix().setIdentity();
801 A.PreconcatScale3d(6, 7, 8); 801 A.PreconcatScale3d(6, 7, 8);
802 A.PreconcatSkewX(45); 802 A.PreconcatSkewX(45);
803 EXPECT_ROW1_EQ(6, 6, 0, 0, A); 803 EXPECT_ROW1_EQ(6, 6, 0, 0, A);
804 EXPECT_ROW2_EQ(0, 7, 0, 0, A); 804 EXPECT_ROW2_EQ(0, 7, 0, 0, A);
805 EXPECT_ROW3_EQ(0, 0, 8, 0, A); 805 EXPECT_ROW3_EQ(0, 0, 8, 0, A);
806 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 806 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
807 } 807 }
808 808
809 TEST(MathUtilGfxTransformTest, verifySkewY) 809 TEST(MathUtilGfxTransformTest, verifySkewY)
810 { 810 {
811 gfx::Transform A; 811 gfx::Transform A;
812 A.PreconcatSkewY(45); 812 A.PreconcatSkewY(45);
813 EXPECT_ROW1_EQ(1, 0, 0, 0, A); 813 EXPECT_ROW1_EQ(1, 0, 0, 0, A);
814 EXPECT_ROW2_EQ(1, 1, 0, 0, A); 814 EXPECT_ROW2_EQ(1, 1, 0, 0, A);
815 EXPECT_ROW3_EQ(0, 0, 1, 0, A); 815 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
816 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 816 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
817 817
818 // Verify that skewY() post-multiplies the existing matrix. 818 // Verify that skewY() post-multiplies the existing matrix.
819 // Row 2, column 1, would incorrectly have value "6" if the matrix is pre-mu ltiplied instead of post-multiplied. 819 // Row 2, column 1, would incorrectly have value "6" if the matrix is pre-mu ltiplied instead of post-multiplied.
820 MathUtil::makeIdentity(&A); 820 A.matrix().setIdentity();
821 A.PreconcatScale3d(6, 7, 8); 821 A.PreconcatScale3d(6, 7, 8);
822 A.PreconcatSkewY(45); 822 A.PreconcatSkewY(45);
823 EXPECT_ROW1_EQ(6, 0, 0, 0, A); 823 EXPECT_ROW1_EQ(6, 0, 0, 0, A);
824 EXPECT_ROW2_EQ(7, 7, 0, 0, A); 824 EXPECT_ROW2_EQ(7, 7, 0, 0, A);
825 EXPECT_ROW3_EQ(0, 0, 8, 0, A); 825 EXPECT_ROW3_EQ(0, 0, 8, 0, A);
826 EXPECT_ROW4_EQ(0, 0, 0, 1, A); 826 EXPECT_ROW4_EQ(0, 0, 0, 1, A);
827 } 827 }
828 828
829 TEST(MathUtilGfxTransformTest, verifyPerspectiveDepth) 829 TEST(MathUtilGfxTransformTest, verifyPerspectiveDepth)
830 { 830 {
831 gfx::Transform A; 831 gfx::Transform A;
832 A.PreconcatPerspectiveDepth(1); 832 A.PreconcatPerspectiveDepth(1);
833 EXPECT_ROW1_EQ(1, 0, 0, 0, A); 833 EXPECT_ROW1_EQ(1, 0, 0, 0, A);
834 EXPECT_ROW2_EQ(0, 1, 0, 0, A); 834 EXPECT_ROW2_EQ(0, 1, 0, 0, A);
835 EXPECT_ROW3_EQ(0, 0, 1, 0, A); 835 EXPECT_ROW3_EQ(0, 0, 1, 0, A);
836 EXPECT_ROW4_EQ(0, 0, -1, 1, A); 836 EXPECT_ROW4_EQ(0, 0, -1, 1, A);
837 837
838 // Verify that PreconcatPerspectiveDepth() post-multiplies the existing matr ix. 838 // Verify that PreconcatPerspectiveDepth() post-multiplies the existing matr ix.
839 MathUtil::makeIdentity(&A); 839 A.matrix().setIdentity();
840 A.PreconcatTranslate3d(2, 3, 4); 840 A.PreconcatTranslate3d(2, 3, 4);
841 A.PreconcatPerspectiveDepth(1); 841 A.PreconcatPerspectiveDepth(1);
842 EXPECT_ROW1_EQ(1, 0, -2, 2, A); 842 EXPECT_ROW1_EQ(1, 0, -2, 2, A);
843 EXPECT_ROW2_EQ(0, 1, -3, 3, A); 843 EXPECT_ROW2_EQ(0, 1, -3, 3, A);
844 EXPECT_ROW3_EQ(0, 0, -3, 4, A); 844 EXPECT_ROW3_EQ(0, 0, -3, 4, A);
845 EXPECT_ROW4_EQ(0, 0, -1, 1, A); 845 EXPECT_ROW4_EQ(0, 0, -1, 1, A);
846 } 846 }
847 847
848 TEST(MathUtilGfxTransformTest, verifyHasPerspective) 848 TEST(MathUtilGfxTransformTest, verifyHasPerspective)
849 { 849 {
850 gfx::Transform A; 850 gfx::Transform A;
851 A.PreconcatPerspectiveDepth(1); 851 A.PreconcatPerspectiveDepth(1);
852 EXPECT_TRUE(MathUtil::hasPerspective(A)); 852 EXPECT_TRUE(MathUtil::hasPerspective(A));
853 853
854 MathUtil::makeIdentity(&A); 854 A.matrix().setIdentity();
855 A.PreconcatPerspectiveDepth(0); 855 A.PreconcatPerspectiveDepth(0);
856 EXPECT_FALSE(MathUtil::hasPerspective(A)); 856 EXPECT_FALSE(MathUtil::hasPerspective(A));
857 857
858 MathUtil::makeIdentity(&A); 858 A.matrix().setIdentity();
859 A.matrix().setDouble(3, 0, -1); 859 A.matrix().setDouble(3, 0, -1);
860 EXPECT_TRUE(MathUtil::hasPerspective(A)); 860 EXPECT_TRUE(MathUtil::hasPerspective(A));
861 861
862 MathUtil::makeIdentity(&A); 862 A.matrix().setIdentity();
863 A.matrix().setDouble(3, 1, -1); 863 A.matrix().setDouble(3, 1, -1);
864 EXPECT_TRUE(MathUtil::hasPerspective(A)); 864 EXPECT_TRUE(MathUtil::hasPerspective(A));
865 865
866 MathUtil::makeIdentity(&A); 866 A.matrix().setIdentity();
867 A.matrix().setDouble(3, 2, -0.3); 867 A.matrix().setDouble(3, 2, -0.3);
868 EXPECT_TRUE(MathUtil::hasPerspective(A)); 868 EXPECT_TRUE(MathUtil::hasPerspective(A));
869 869
870 MathUtil::makeIdentity(&A); 870 A.matrix().setIdentity();
871 A.matrix().setDouble(3, 3, 0.5); 871 A.matrix().setDouble(3, 3, 0.5);
872 EXPECT_TRUE(MathUtil::hasPerspective(A)); 872 EXPECT_TRUE(MathUtil::hasPerspective(A));
873 873
874 MathUtil::makeIdentity(&A); 874 A.matrix().setIdentity();
875 A.matrix().setDouble(3, 3, 0); 875 A.matrix().setDouble(3, 3, 0);
876 EXPECT_TRUE(MathUtil::hasPerspective(A)); 876 EXPECT_TRUE(MathUtil::hasPerspective(A));
877 } 877 }
878 878
879 TEST(MathUtilGfxTransformTest, verifyIsInvertible) 879 TEST(MathUtilGfxTransformTest, verifyIsInvertible)
880 { 880 {
881 gfx::Transform A; 881 gfx::Transform A;
882 882
883 // Translations, rotations, scales, skews and arbitrary combinations of them are invertible. 883 // Translations, rotations, scales, skews and arbitrary combinations of them are invertible.
884 MathUtil::makeIdentity(&A); 884 A.matrix().setIdentity();
885 EXPECT_TRUE(MathUtil::isInvertible(A)); 885 EXPECT_TRUE(A.IsInvertible());
886 886
887 MathUtil::makeIdentity(&A); 887 A.matrix().setIdentity();
888 A.PreconcatTranslate3d(2, 3, 4); 888 A.PreconcatTranslate3d(2, 3, 4);
889 EXPECT_TRUE(MathUtil::isInvertible(A)); 889 EXPECT_TRUE(A.IsInvertible());
890 890
891 MathUtil::makeIdentity(&A); 891 A.matrix().setIdentity();
892 A.PreconcatScale3d(6, 7, 8); 892 A.PreconcatScale3d(6, 7, 8);
893 EXPECT_TRUE(MathUtil::isInvertible(A)); 893 EXPECT_TRUE(A.IsInvertible());
894 894
895 MathUtil::makeIdentity(&A); 895 A.matrix().setIdentity();
896 MathUtil::rotateEulerAngles(&A, 10, 20, 30); 896 MathUtil::rotateEulerAngles(&A, 10, 20, 30);
897 EXPECT_TRUE(MathUtil::isInvertible(A)); 897 EXPECT_TRUE(A.IsInvertible());
898 898
899 MathUtil::makeIdentity(&A); 899 A.matrix().setIdentity();
900 A.PreconcatSkewX(45); 900 A.PreconcatSkewX(45);
901 EXPECT_TRUE(MathUtil::isInvertible(A)); 901 EXPECT_TRUE(A.IsInvertible());
902 902
903 // A perspective matrix (projection plane at z=0) is invertible. The intuiti ve 903 // A perspective matrix (projection plane at z=0) is invertible. The intuiti ve
904 // explanation is that perspective is eqivalent to a skew of the w-axis; ske ws are 904 // explanation is that perspective is eqivalent to a skew of the w-axis; ske ws are
905 // invertible. 905 // invertible.
906 MathUtil::makeIdentity(&A); 906 A.matrix().setIdentity();
907 A.PreconcatPerspectiveDepth(1); 907 A.PreconcatPerspectiveDepth(1);
908 EXPECT_TRUE(MathUtil::isInvertible(A)); 908 EXPECT_TRUE(A.IsInvertible());
909 909
910 // A "pure" perspective matrix derived by similar triangles, with m44() set to zero 910 // A "pure" perspective matrix derived by similar triangles, with m44() set to zero
911 // (i.e. camera positioned at the origin), is not invertible. 911 // (i.e. camera positioned at the origin), is not invertible.
912 MathUtil::makeIdentity(&A); 912 A.matrix().setIdentity();
913 A.PreconcatPerspectiveDepth(1); 913 A.PreconcatPerspectiveDepth(1);
914 A.matrix().setDouble(3, 3, 0); 914 A.matrix().setDouble(3, 3, 0);
915 EXPECT_FALSE(MathUtil::isInvertible(A)); 915 EXPECT_FALSE(A.IsInvertible());
916 916
917 // Adding more to a non-invertible matrix will not make it invertible in the general case. 917 // Adding more to a non-invertible matrix will not make it invertible in the general case.
918 MathUtil::makeIdentity(&A); 918 A.matrix().setIdentity();
919 A.PreconcatPerspectiveDepth(1); 919 A.PreconcatPerspectiveDepth(1);
920 A.matrix().setDouble(3, 3, 0); 920 A.matrix().setDouble(3, 3, 0);
921 A.PreconcatScale3d(6, 7, 8); 921 A.PreconcatScale3d(6, 7, 8);
922 MathUtil::rotateEulerAngles(&A, 10, 20, 30); 922 MathUtil::rotateEulerAngles(&A, 10, 20, 30);
923 A.PreconcatTranslate3d(6, 7, 8); 923 A.PreconcatTranslate3d(6, 7, 8);
924 EXPECT_FALSE(MathUtil::isInvertible(A)); 924 EXPECT_FALSE(A.IsInvertible());
925 925
926 // A degenerate matrix of all zeros is not invertible. 926 // A degenerate matrix of all zeros is not invertible.
927 MathUtil::makeIdentity(&A); 927 A.matrix().setIdentity();
928 A.matrix().setDouble(0, 0, 0); 928 A.matrix().setDouble(0, 0, 0);
929 A.matrix().setDouble(1, 1, 0); 929 A.matrix().setDouble(1, 1, 0);
930 A.matrix().setDouble(2, 2, 0); 930 A.matrix().setDouble(2, 2, 0);
931 A.matrix().setDouble(3, 3, 0); 931 A.matrix().setDouble(3, 3, 0);
932 EXPECT_FALSE(MathUtil::isInvertible(A)); 932 EXPECT_FALSE(A.IsInvertible());
933 } 933 }
934 934
935 TEST(MathUtilGfxTransformTest, verifyIsIdentity) 935 TEST(MathUtilGfxTransformTest, verifyIsIdentity)
936 { 936 {
937 gfx::Transform A; 937 gfx::Transform A;
938 938
939 initializeTestMatrix(&A); 939 initializeTestMatrix(&A);
940 EXPECT_FALSE(MathUtil::isIdentity(A)); 940 EXPECT_FALSE(A.IsIdentity());
941 941
942 MathUtil::makeIdentity(&A); 942 A.matrix().setIdentity();
943 EXPECT_TRUE(MathUtil::isIdentity(A)); 943 EXPECT_TRUE(A.IsIdentity());
944 944
945 // Modifying any one individual element should cause the matrix to no longer be identity. 945 // Modifying any one individual element should cause the matrix to no longer be identity.
946 MathUtil::makeIdentity(&A); 946 A.matrix().setIdentity();
947 A.matrix().setDouble(0, 0, 2); 947 A.matrix().setDouble(0, 0, 2);
948 EXPECT_FALSE(MathUtil::isIdentity(A)); 948 EXPECT_FALSE(A.IsIdentity());
949 949
950 MathUtil::makeIdentity(&A); 950 A.matrix().setIdentity();
951 A.matrix().setDouble(1, 0, 2); 951 A.matrix().setDouble(1, 0, 2);
952 EXPECT_FALSE(MathUtil::isIdentity(A)); 952 EXPECT_FALSE(A.IsIdentity());
953 953
954 MathUtil::makeIdentity(&A); 954 A.matrix().setIdentity();
955 A.matrix().setDouble(2, 0, 2); 955 A.matrix().setDouble(2, 0, 2);
956 EXPECT_FALSE(MathUtil::isIdentity(A)); 956 EXPECT_FALSE(A.IsIdentity());
957 957
958 MathUtil::makeIdentity(&A); 958 A.matrix().setIdentity();
959 A.matrix().setDouble(3, 0, 2); 959 A.matrix().setDouble(3, 0, 2);
960 EXPECT_FALSE(MathUtil::isIdentity(A)); 960 EXPECT_FALSE(A.IsIdentity());
961 961
962 MathUtil::makeIdentity(&A); 962 A.matrix().setIdentity();
963 A.matrix().setDouble(0, 1, 2); 963 A.matrix().setDouble(0, 1, 2);
964 EXPECT_FALSE(MathUtil::isIdentity(A)); 964 EXPECT_FALSE(A.IsIdentity());
965 965
966 MathUtil::makeIdentity(&A); 966 A.matrix().setIdentity();
967 A.matrix().setDouble(1, 1, 2); 967 A.matrix().setDouble(1, 1, 2);
968 EXPECT_FALSE(MathUtil::isIdentity(A)); 968 EXPECT_FALSE(A.IsIdentity());
969 969
970 MathUtil::makeIdentity(&A); 970 A.matrix().setIdentity();
971 A.matrix().setDouble(2, 1, 2); 971 A.matrix().setDouble(2, 1, 2);
972 EXPECT_FALSE(MathUtil::isIdentity(A)); 972 EXPECT_FALSE(A.IsIdentity());
973 973
974 MathUtil::makeIdentity(&A); 974 A.matrix().setIdentity();
975 A.matrix().setDouble(3, 1, 2); 975 A.matrix().setDouble(3, 1, 2);
976 EXPECT_FALSE(MathUtil::isIdentity(A)); 976 EXPECT_FALSE(A.IsIdentity());
977 977
978 MathUtil::makeIdentity(&A); 978 A.matrix().setIdentity();
979 A.matrix().setDouble(0, 2, 2); 979 A.matrix().setDouble(0, 2, 2);
980 EXPECT_FALSE(MathUtil::isIdentity(A)); 980 EXPECT_FALSE(A.IsIdentity());
981 981
982 MathUtil::makeIdentity(&A); 982 A.matrix().setIdentity();
983 A.matrix().setDouble(1, 2, 2); 983 A.matrix().setDouble(1, 2, 2);
984 EXPECT_FALSE(MathUtil::isIdentity(A)); 984 EXPECT_FALSE(A.IsIdentity());
985 985
986 MathUtil::makeIdentity(&A); 986 A.matrix().setIdentity();
987 A.matrix().setDouble(2, 2, 2); 987 A.matrix().setDouble(2, 2, 2);
988 EXPECT_FALSE(MathUtil::isIdentity(A)); 988 EXPECT_FALSE(A.IsIdentity());
989 989
990 MathUtil::makeIdentity(&A); 990 A.matrix().setIdentity();
991 A.matrix().setDouble(3, 2, 2); 991 A.matrix().setDouble(3, 2, 2);
992 EXPECT_FALSE(MathUtil::isIdentity(A)); 992 EXPECT_FALSE(A.IsIdentity());
993 993
994 MathUtil::makeIdentity(&A); 994 A.matrix().setIdentity();
995 A.matrix().setDouble(0, 3, 2); 995 A.matrix().setDouble(0, 3, 2);
996 EXPECT_FALSE(MathUtil::isIdentity(A)); 996 EXPECT_FALSE(A.IsIdentity());
997 997
998 MathUtil::makeIdentity(&A); 998 A.matrix().setIdentity();
999 A.matrix().setDouble(1, 3, 2); 999 A.matrix().setDouble(1, 3, 2);
1000 EXPECT_FALSE(MathUtil::isIdentity(A)); 1000 EXPECT_FALSE(A.IsIdentity());
1001 1001
1002 MathUtil::makeIdentity(&A); 1002 A.matrix().setIdentity();
1003 A.matrix().setDouble(2, 3, 2); 1003 A.matrix().setDouble(2, 3, 2);
1004 EXPECT_FALSE(MathUtil::isIdentity(A)); 1004 EXPECT_FALSE(A.IsIdentity());
1005 1005
1006 MathUtil::makeIdentity(&A); 1006 A.matrix().setIdentity();
1007 A.matrix().setDouble(3, 3, 2); 1007 A.matrix().setDouble(3, 3, 2);
1008 EXPECT_FALSE(MathUtil::isIdentity(A)); 1008 EXPECT_FALSE(A.IsIdentity());
1009 } 1009 }
1010 1010
1011 TEST(MathUtilGfxTransformTest, verifyIsIdentityOrTranslation) 1011 TEST(MathUtilGfxTransformTest, verifyIsIdentityOrTranslation)
1012 { 1012 {
1013 gfx::Transform A; 1013 gfx::Transform A;
1014 1014
1015 initializeTestMatrix(&A); 1015 initializeTestMatrix(&A);
1016 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); 1016 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A));
1017 1017
1018 MathUtil::makeIdentity(&A); 1018 A.matrix().setIdentity();
1019 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); 1019 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A));
1020 1020
1021 // Modifying any non-translation components should cause isIdentityOrTransla tion() to 1021 // Modifying any non-translation components should cause isIdentityOrTransla tion() to
1022 // return false. NOTE: (0, 3), (1, 3), and (2, 3) are the translation compon ents, so 1022 // return false. NOTE: (0, 3), (1, 3), and (2, 3) are the translation compon ents, so
1023 // modifying them should still return true for isIdentityOrTranslation(). 1023 // modifying them should still return true for isIdentityOrTranslation().
1024 MathUtil::makeIdentity(&A); 1024 A.matrix().setIdentity();
1025 A.matrix().setDouble(0, 0, 2); 1025 A.matrix().setDouble(0, 0, 2);
1026 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); 1026 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A));
1027 1027
1028 MathUtil::makeIdentity(&A); 1028 A.matrix().setIdentity();
1029 A.matrix().setDouble(1, 0, 2); 1029 A.matrix().setDouble(1, 0, 2);
1030 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); 1030 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A));
1031 1031
1032 MathUtil::makeIdentity(&A); 1032 A.matrix().setIdentity();
1033 A.matrix().setDouble(2, 0, 2); 1033 A.matrix().setDouble(2, 0, 2);
1034 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); 1034 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A));
1035 1035
1036 MathUtil::makeIdentity(&A); 1036 A.matrix().setIdentity();
1037 A.matrix().setDouble(3, 0, 2); 1037 A.matrix().setDouble(3, 0, 2);
1038 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); 1038 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A));
1039 1039
1040 MathUtil::makeIdentity(&A); 1040 A.matrix().setIdentity();
1041 A.matrix().setDouble(0, 0, 2); 1041 A.matrix().setDouble(0, 0, 2);
1042 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); 1042 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A));
1043 1043
1044 MathUtil::makeIdentity(&A); 1044 A.matrix().setIdentity();
1045 A.matrix().setDouble(1, 1, 2); 1045 A.matrix().setDouble(1, 1, 2);
1046 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); 1046 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A));
1047 1047
1048 MathUtil::makeIdentity(&A); 1048 A.matrix().setIdentity();
1049 A.matrix().setDouble(2, 1, 2); 1049 A.matrix().setDouble(2, 1, 2);
1050 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); 1050 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A));
1051 1051
1052 MathUtil::makeIdentity(&A); 1052 A.matrix().setIdentity();
1053 A.matrix().setDouble(3, 1, 2); 1053 A.matrix().setDouble(3, 1, 2);
1054 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); 1054 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A));
1055 1055
1056 MathUtil::makeIdentity(&A); 1056 A.matrix().setIdentity();
1057 A.matrix().setDouble(0, 2, 2); 1057 A.matrix().setDouble(0, 2, 2);
1058 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); 1058 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A));
1059 1059
1060 MathUtil::makeIdentity(&A); 1060 A.matrix().setIdentity();
1061 A.matrix().setDouble(1, 2, 2); 1061 A.matrix().setDouble(1, 2, 2);
1062 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); 1062 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A));
1063 1063
1064 MathUtil::makeIdentity(&A); 1064 A.matrix().setIdentity();
1065 A.matrix().setDouble(2, 2, 2); 1065 A.matrix().setDouble(2, 2, 2);
1066 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); 1066 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A));
1067 1067
1068 MathUtil::makeIdentity(&A); 1068 A.matrix().setIdentity();
1069 A.matrix().setDouble(3, 2, 2); 1069 A.matrix().setDouble(3, 2, 2);
1070 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); 1070 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A));
1071 1071
1072 // Note carefully - expecting true here. 1072 // Note carefully - expecting true here.
1073 MathUtil::makeIdentity(&A); 1073 A.matrix().setIdentity();
1074 A.matrix().setDouble(0, 3, 2); 1074 A.matrix().setDouble(0, 3, 2);
1075 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); 1075 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A));
1076 1076
1077 // Note carefully - expecting true here. 1077 // Note carefully - expecting true here.
1078 MathUtil::makeIdentity(&A); 1078 A.matrix().setIdentity();
1079 A.matrix().setDouble(1, 3, 2); 1079 A.matrix().setDouble(1, 3, 2);
1080 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); 1080 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A));
1081 1081
1082 // Note carefully - expecting true here. 1082 // Note carefully - expecting true here.
1083 MathUtil::makeIdentity(&A); 1083 A.matrix().setIdentity();
1084 A.matrix().setDouble(2, 3, 2); 1084 A.matrix().setDouble(2, 3, 2);
1085 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); 1085 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A));
1086 1086
1087 MathUtil::makeIdentity(&A); 1087 A.matrix().setIdentity();
1088 A.matrix().setDouble(3, 3, 2); 1088 A.matrix().setDouble(3, 3, 2);
1089 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); 1089 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A));
1090 } 1090 }
1091 1091
1092 } // namespace 1092 } // namespace
1093 } // namespace cc 1093 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698