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

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

Powered by Google App Engine
This is Rietveld 408576698