| OLD | NEW |
| 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 "ui/gfx/transform.h" | 14 #include "ui/gfx/transform.h" |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 TEST(MathUtilTest, verifyBackfaceVisibilityBasicCases) | 19 TEST(MathUtilTest, verifyBackfaceVisibilityBasicCases) |
| 20 { | 20 { |
| 21 gfx::Transform transform; | 21 gfx::Transform transform; |
| 22 | 22 |
| 23 transform.MakeIdentity(); | 23 transform.MakeIdentity(); |
| 24 EXPECT_FALSE(MathUtil::isBackFaceVisible(transform)); | 24 EXPECT_FALSE(transform.IsBackFaceVisible()); |
| 25 | 25 |
| 26 transform.MakeIdentity(); | 26 transform.MakeIdentity(); |
| 27 MathUtil::rotateEulerAngles(&transform, 0, 80, 0); | 27 MathUtil::rotateEulerAngles(&transform, 0, 80, 0); |
| 28 EXPECT_FALSE(MathUtil::isBackFaceVisible(transform)); | 28 EXPECT_FALSE(transform.IsBackFaceVisible()); |
| 29 | 29 |
| 30 transform.MakeIdentity(); | 30 transform.MakeIdentity(); |
| 31 MathUtil::rotateEulerAngles(&transform, 0, 100, 0); | 31 MathUtil::rotateEulerAngles(&transform, 0, 100, 0); |
| 32 EXPECT_TRUE(MathUtil::isBackFaceVisible(transform)); | 32 EXPECT_TRUE(transform.IsBackFaceVisible()); |
| 33 | 33 |
| 34 // Edge case, 90 degree rotation should return false. | 34 // Edge case, 90 degree rotation should return false. |
| 35 transform.MakeIdentity(); | 35 transform.MakeIdentity(); |
| 36 MathUtil::rotateEulerAngles(&transform, 0, 90, 0); | 36 MathUtil::rotateEulerAngles(&transform, 0, 90, 0); |
| 37 EXPECT_FALSE(MathUtil::isBackFaceVisible(transform)); | 37 EXPECT_FALSE(transform.IsBackFaceVisible()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 TEST(MathUtilTest, verifyBackfaceVisibilityForPerspective) | 40 TEST(MathUtilTest, verifyBackfaceVisibilityForPerspective) |
| 41 { | 41 { |
| 42 gfx::Transform layerSpaceToProjectionPlane; | 42 gfx::Transform layerSpaceToProjectionPlane; |
| 43 | 43 |
| 44 // This tests if isBackFaceVisible works properly under perspective transfor
ms. | 44 // This tests if IsBackFaceVisible works properly under perspective transfor
ms. |
| 45 // 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 |
| 46 // 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. |
| 47 | 47 |
| 48 // 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 |
| 49 // 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 |
| 50 // the camera. | 50 // the camera. |
| 51 layerSpaceToProjectionPlane.MakeIdentity(); | 51 layerSpaceToProjectionPlane.MakeIdentity(); |
| 52 layerSpaceToProjectionPlane.ApplyPerspectiveDepth(1); | 52 layerSpaceToProjectionPlane.ApplyPerspectiveDepth(1); |
| 53 layerSpaceToProjectionPlane.Translate3d(0, 0, 0); | 53 layerSpaceToProjectionPlane.Translate3d(0, 0, 0); |
| 54 MathUtil::rotateEulerAngles(&layerSpaceToProjectionPlane, 0, 100, 0); | 54 MathUtil::rotateEulerAngles(&layerSpaceToProjectionPlane, 0, 100, 0); |
| 55 EXPECT_TRUE(MathUtil::isBackFaceVisible(layerSpaceToProjectionPlane)); | 55 EXPECT_TRUE(layerSpaceToProjectionPlane.IsBackFaceVisible()); |
| 56 | 56 |
| 57 // 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 |
| 58 // 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 |
| 59 // side is still visible. | 59 // side is still visible. |
| 60 // | 60 // |
| 61 // |<-- front side of layer is visible to perspective
camera | 61 // |<-- front side of layer is visible to perspective
camera |
| 62 // \ | / | 62 // \ | / |
| 63 // \ | / | 63 // \ | / |
| 64 // \| / | 64 // \| / |
| 65 // | / | 65 // | / |
| 66 // |\ /<-- camera field of view | 66 // |\ /<-- camera field of view |
| 67 // | \ / | 67 // | \ / |
| 68 // back side of layer -->| \ / | 68 // back side of layer -->| \ / |
| 69 // \./ <-- camera origin | 69 // \./ <-- camera origin |
| 70 // | 70 // |
| 71 layerSpaceToProjectionPlane.MakeIdentity(); | 71 layerSpaceToProjectionPlane.MakeIdentity(); |
| 72 layerSpaceToProjectionPlane.ApplyPerspectiveDepth(1); | 72 layerSpaceToProjectionPlane.ApplyPerspectiveDepth(1); |
| 73 layerSpaceToProjectionPlane.Translate3d(-10, 0, 0); | 73 layerSpaceToProjectionPlane.Translate3d(-10, 0, 0); |
| 74 MathUtil::rotateEulerAngles(&layerSpaceToProjectionPlane, 0, 100, 0); | 74 MathUtil::rotateEulerAngles(&layerSpaceToProjectionPlane, 0, 100, 0); |
| 75 EXPECT_FALSE(MathUtil::isBackFaceVisible(layerSpaceToProjectionPlane)); | 75 EXPECT_FALSE(layerSpaceToProjectionPlane.IsBackFaceVisible()); |
| 76 | 76 |
| 77 // 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 |
| 78 // opposite result of case 2. | 78 // opposite result of case 2. |
| 79 MathUtil::rotateEulerAngles(&layerSpaceToProjectionPlane, 0, 180, 0); | 79 MathUtil::rotateEulerAngles(&layerSpaceToProjectionPlane, 0, 180, 0); |
| 80 EXPECT_TRUE(MathUtil::isBackFaceVisible(layerSpaceToProjectionPlane)); | 80 EXPECT_TRUE(layerSpaceToProjectionPlane.IsBackFaceVisible()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 TEST(MathUtilTest, verifyProjectionOfPerpendicularPlane) | 83 TEST(MathUtilTest, verifyProjectionOfPerpendicularPlane) |
| 84 { | 84 { |
| 85 // 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 |
| 86 // divide-by-zero when projecting points/quads. | 86 // divide-by-zero when projecting points/quads. |
| 87 | 87 |
| 88 gfx::Transform transform; | 88 gfx::Transform transform; |
| 89 transform.MakeIdentity(); | 89 transform.MakeIdentity(); |
| 90 transform.matrix().setDouble(2, 2, 0); | 90 transform.matrix().setDouble(2, 2, 0); |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 0.8825641192593856043657752, | 720 0.8825641192593856043657752, |
| 721 0.0180283112362972230968694, | 721 0.0180283112362972230968694, |
| 722 0, A, ERROR_THRESHOLD); | 722 0, A, ERROR_THRESHOLD); |
| 723 EXPECT_ROW3_NEAR(-0.3420201433256686573969318, | 723 EXPECT_ROW3_NEAR(-0.3420201433256686573969318, |
| 724 0.1631759111665348205288950, | 724 0.1631759111665348205288950, |
| 725 0.9254165783983233639631294, | 725 0.9254165783983233639631294, |
| 726 0, A, ERROR_THRESHOLD); | 726 0, A, ERROR_THRESHOLD); |
| 727 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 727 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
| 728 } | 728 } |
| 729 | 729 |
| 730 TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForAlignedAxes) | 730 TEST(MathUtilGfxTransformTest, verifyRotateAboutXAxis) |
| 731 { |
| 732 gfx::Transform A; |
| 733 double sin45 = 0.5 * sqrt(2.0); |
| 734 double cos45 = sin45; |
| 735 |
| 736 A.MakeIdentity(); |
| 737 A.RotateAboutXAxis(90); |
| 738 EXPECT_ROW1_EQ(1, 0, 0, 0, A); |
| 739 EXPECT_ROW2_NEAR(0, 0, -1, 0, A, ERROR_THRESHOLD); |
| 740 EXPECT_ROW3_NEAR(0, 1, 0, 0, A, ERROR_THRESHOLD); |
| 741 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
| 742 |
| 743 A.MakeIdentity(); |
| 744 A.RotateAboutXAxis(45); |
| 745 EXPECT_ROW1_EQ(1, 0, 0, 0, A); |
| 746 EXPECT_ROW2_NEAR(0, cos45, -sin45, 0, A, ERROR_THRESHOLD); |
| 747 EXPECT_ROW3_NEAR(0, sin45, cos45, 0, A, ERROR_THRESHOLD); |
| 748 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
| 749 |
| 750 // Verify that rotateAboutXAxis(angle) post-multiplies the existing matrix. |
| 751 A.MakeIdentity(); |
| 752 A.Scale3d(6, 7, 8); |
| 753 A.RotateAboutXAxis(90); |
| 754 EXPECT_ROW1_NEAR(6, 0, 0, 0, A, ERROR_THRESHOLD); |
| 755 EXPECT_ROW2_NEAR(0, 0, -7, 0, A, ERROR_THRESHOLD); |
| 756 EXPECT_ROW3_NEAR(0, 8, 0, 0, A, ERROR_THRESHOLD); |
| 757 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
| 758 } |
| 759 |
| 760 TEST(MathUtilGfxTransformTest, verifyRotateAboutYAxis) |
| 761 { |
| 762 gfx::Transform A; |
| 763 double sin45 = 0.5 * sqrt(2.0); |
| 764 double cos45 = sin45; |
| 765 |
| 766 // Note carefully, the expected pattern is inverted compared to rotating abo
ut x axis or z axis. |
| 767 A.MakeIdentity(); |
| 768 A.RotateAboutYAxis(90); |
| 769 EXPECT_ROW1_NEAR(0, 0, 1, 0, A, ERROR_THRESHOLD); |
| 770 EXPECT_ROW2_EQ(0, 1, 0, 0, A); |
| 771 EXPECT_ROW3_NEAR(-1, 0, 0, 0, A, ERROR_THRESHOLD); |
| 772 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
| 773 |
| 774 A.MakeIdentity(); |
| 775 A.RotateAboutYAxis(45); |
| 776 EXPECT_ROW1_NEAR(cos45, 0, sin45, 0, A, ERROR_THRESHOLD); |
| 777 EXPECT_ROW2_EQ(0, 1, 0, 0, A); |
| 778 EXPECT_ROW3_NEAR(-sin45, 0, cos45, 0, A, ERROR_THRESHOLD); |
| 779 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
| 780 |
| 781 // Verify that rotateAboutYAxis(angle) post-multiplies the existing matrix. |
| 782 A.MakeIdentity(); |
| 783 A.Scale3d(6, 7, 8); |
| 784 A.RotateAboutYAxis(90); |
| 785 EXPECT_ROW1_NEAR(0, 0, 6, 0, A, ERROR_THRESHOLD); |
| 786 EXPECT_ROW2_NEAR(0, 7, 0, 0, A, ERROR_THRESHOLD); |
| 787 EXPECT_ROW3_NEAR(-8, 0, 0, 0, A, ERROR_THRESHOLD); |
| 788 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
| 789 } |
| 790 |
| 791 TEST(MathUtilGfxTransformTest, verifyRotateAboutZAxis) |
| 792 { |
| 793 gfx::Transform A; |
| 794 double sin45 = 0.5 * sqrt(2.0); |
| 795 double cos45 = sin45; |
| 796 |
| 797 A.MakeIdentity(); |
| 798 A.RotateAboutZAxis(90); |
| 799 EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD); |
| 800 EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD); |
| 801 EXPECT_ROW3_EQ(0, 0, 1, 0, A); |
| 802 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
| 803 |
| 804 A.MakeIdentity(); |
| 805 A.RotateAboutZAxis(45); |
| 806 EXPECT_ROW1_NEAR(cos45, -sin45, 0, 0, A, ERROR_THRESHOLD); |
| 807 EXPECT_ROW2_NEAR(sin45, cos45, 0, 0, A, ERROR_THRESHOLD); |
| 808 EXPECT_ROW3_EQ(0, 0, 1, 0, A); |
| 809 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
| 810 |
| 811 // Verify that rotateAboutZAxis(angle) post-multiplies the existing matrix. |
| 812 A.MakeIdentity(); |
| 813 A.Scale3d(6, 7, 8); |
| 814 A.RotateAboutZAxis(90); |
| 815 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD); |
| 816 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD); |
| 817 EXPECT_ROW3_EQ(0, 0, 8, 0, A); |
| 818 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
| 819 } |
| 820 |
| 821 TEST(MathUtilGfxTransformTest, verifyRotateAboutForAlignedAxes) |
| 731 { | 822 { |
| 732 gfx::Transform A; | 823 gfx::Transform A; |
| 733 | 824 |
| 734 // Check rotation about z-axis | 825 // Check rotation about z-axis |
| 735 A.MakeIdentity(); | 826 A.MakeIdentity(); |
| 736 MathUtil::rotateAxisAngle(&A, 0, 0, 1, 90); | 827 A.RotateAbout(gfx::Vector3dF(0, 0, 1), 90); |
| 737 EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD); | 828 EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD); |
| 738 EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD); | 829 EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD); |
| 739 EXPECT_ROW3_EQ(0, 0, 1, 0, A); | 830 EXPECT_ROW3_EQ(0, 0, 1, 0, A); |
| 740 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 831 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
| 741 | 832 |
| 742 // Check rotation about x-axis | 833 // Check rotation about x-axis |
| 743 A.MakeIdentity(); | 834 A.MakeIdentity(); |
| 744 MathUtil::rotateAxisAngle(&A, 1, 0, 0, 90); | 835 A.RotateAbout(gfx::Vector3dF(1, 0, 0), 90); |
| 745 EXPECT_ROW1_EQ(1, 0, 0, 0, A); | 836 EXPECT_ROW1_EQ(1, 0, 0, 0, A); |
| 746 EXPECT_ROW2_NEAR(0, 0, -1, 0, A, ERROR_THRESHOLD); | 837 EXPECT_ROW2_NEAR(0, 0, -1, 0, A, ERROR_THRESHOLD); |
| 747 EXPECT_ROW3_NEAR(0, 1, 0, 0, A, ERROR_THRESHOLD); | 838 EXPECT_ROW3_NEAR(0, 1, 0, 0, A, ERROR_THRESHOLD); |
| 748 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 839 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
| 749 | 840 |
| 750 // Check rotation about y-axis. | 841 // Check rotation about y-axis. |
| 751 // Note carefully, the expected pattern is inverted compared to rotating abo
ut x axis or z axis. | 842 // Note carefully, the expected pattern is inverted compared to rotating abo
ut x axis or z axis. |
| 752 A.MakeIdentity(); | 843 A.MakeIdentity(); |
| 753 MathUtil::rotateAxisAngle(&A, 0, 1, 0, 90); | 844 A.RotateAbout(gfx::Vector3dF(0, 1, 0), 90); |
| 754 EXPECT_ROW1_NEAR(0, 0, 1, 0, A, ERROR_THRESHOLD); | 845 EXPECT_ROW1_NEAR(0, 0, 1, 0, A, ERROR_THRESHOLD); |
| 755 EXPECT_ROW2_EQ(0, 1, 0, 0, A); | 846 EXPECT_ROW2_EQ(0, 1, 0, 0, A); |
| 756 EXPECT_ROW3_NEAR(-1, 0, 0, 0, A, ERROR_THRESHOLD); | 847 EXPECT_ROW3_NEAR(-1, 0, 0, 0, A, ERROR_THRESHOLD); |
| 757 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 848 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
| 758 | 849 |
| 759 // Verify that rotate3d(axis, angle) post-multiplies the existing matrix. | 850 // Verify that rotate3d(axis, angle) post-multiplies the existing matrix. |
| 760 A.MakeIdentity(); | 851 A.MakeIdentity(); |
| 761 A.Scale3d(6, 7, 8); | 852 A.Scale3d(6, 7, 8); |
| 762 MathUtil::rotateAxisAngle(&A, 0, 0, 1, 90); | 853 A.RotateAboutZAxis(90); |
| 763 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD); | 854 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD); |
| 764 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD); | 855 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD); |
| 765 EXPECT_ROW3_EQ(0, 0, 8, 0, A); | 856 EXPECT_ROW3_EQ(0, 0, 8, 0, A); |
| 766 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 857 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
| 767 } | 858 } |
| 768 | 859 |
| 769 TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForArbitraryAxis) | 860 TEST(MathUtilGfxTransformTest, verifyRotateAboutForArbitraryAxis) |
| 770 { | 861 { |
| 771 // Check rotation about an arbitrary non-axis-aligned vector. | 862 // Check rotation about an arbitrary non-axis-aligned vector. |
| 772 gfx::Transform A; | 863 gfx::Transform A; |
| 773 MathUtil::rotateAxisAngle(&A, 1, 1, 1, 90); | 864 A.RotateAbout(gfx::Vector3dF(1, 1, 1), 90); |
| 774 EXPECT_ROW1_NEAR(0.3333333333333334258519187, | 865 EXPECT_ROW1_NEAR(0.3333333333333334258519187, |
| 775 -0.2440169358562924717404030, | 866 -0.2440169358562924717404030, |
| 776 0.9106836025229592124219380, | 867 0.9106836025229592124219380, |
| 777 0, A, ERROR_THRESHOLD); | 868 0, A, ERROR_THRESHOLD); |
| 778 EXPECT_ROW2_NEAR(0.9106836025229592124219380, | 869 EXPECT_ROW2_NEAR(0.9106836025229592124219380, |
| 779 0.3333333333333334258519187, | 870 0.3333333333333334258519187, |
| 780 -0.2440169358562924717404030, | 871 -0.2440169358562924717404030, |
| 781 0, A, ERROR_THRESHOLD); | 872 0, A, ERROR_THRESHOLD); |
| 782 EXPECT_ROW3_NEAR(-0.2440169358562924717404030, | 873 EXPECT_ROW3_NEAR(-0.2440169358562924717404030, |
| 783 0.9106836025229592124219380, | 874 0.9106836025229592124219380, |
| 784 0.3333333333333334258519187, | 875 0.3333333333333334258519187, |
| 785 0, A, ERROR_THRESHOLD); | 876 0, A, ERROR_THRESHOLD); |
| 786 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 877 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
| 787 } | 878 } |
| 788 | 879 |
| 789 TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForDegenerateAxis) | 880 TEST(MathUtilGfxTransformTest, verifyRotateAboutForDegenerateAxis) |
| 790 { | 881 { |
| 791 // Check rotation about a degenerate zero vector. | 882 // Check rotation about a degenerate zero vector. |
| 792 // It is expected to skip applying the rotation. | 883 // It is expected to skip applying the rotation. |
| 793 gfx::Transform A; | 884 gfx::Transform A; |
| 794 | 885 |
| 795 MathUtil::rotateAxisAngle(&A, 0, 0, 0, 45); | 886 A.RotateAbout(gfx::Vector3dF(0, 0, 0), 45); |
| 796 // Verify that A remains unchanged. | 887 // Verify that A remains unchanged. |
| 797 EXPECT_TRUE(A.IsIdentity()); | 888 EXPECT_TRUE(A.IsIdentity()); |
| 798 | 889 |
| 799 initializeTestMatrix(&A); | 890 initializeTestMatrix(&A); |
| 800 MathUtil::rotateAxisAngle(&A, 0, 0, 0, 35); | 891 A.RotateAbout(gfx::Vector3dF(0, 0, 0), 35); |
| 801 | 892 |
| 802 // Verify that A remains unchanged. | 893 // Verify that A remains unchanged. |
| 803 EXPECT_ROW1_EQ(10, 14, 18, 22, A); | 894 EXPECT_ROW1_EQ(10, 14, 18, 22, A); |
| 804 EXPECT_ROW2_EQ(11, 15, 19, 23, A); | 895 EXPECT_ROW2_EQ(11, 15, 19, 23, A); |
| 805 EXPECT_ROW3_EQ(12, 16, 20, 24, A); | 896 EXPECT_ROW3_EQ(12, 16, 20, 24, A); |
| 806 EXPECT_ROW4_EQ(13, 17, 21, 25, A); | 897 EXPECT_ROW4_EQ(13, 17, 21, 25, A); |
| 807 } | 898 } |
| 808 | 899 |
| 809 TEST(MathUtilGfxTransformTest, verifySkewX) | 900 TEST(MathUtilGfxTransformTest, verifySkewX) |
| 810 { | 901 { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 EXPECT_ROW1_EQ(1, 0, -2, 2, A); | 953 EXPECT_ROW1_EQ(1, 0, -2, 2, A); |
| 863 EXPECT_ROW2_EQ(0, 1, -3, 3, A); | 954 EXPECT_ROW2_EQ(0, 1, -3, 3, A); |
| 864 EXPECT_ROW3_EQ(0, 0, -3, 4, A); | 955 EXPECT_ROW3_EQ(0, 0, -3, 4, A); |
| 865 EXPECT_ROW4_EQ(0, 0, -1, 1, A); | 956 EXPECT_ROW4_EQ(0, 0, -1, 1, A); |
| 866 } | 957 } |
| 867 | 958 |
| 868 TEST(MathUtilGfxTransformTest, verifyHasPerspective) | 959 TEST(MathUtilGfxTransformTest, verifyHasPerspective) |
| 869 { | 960 { |
| 870 gfx::Transform A; | 961 gfx::Transform A; |
| 871 A.ApplyPerspectiveDepth(1); | 962 A.ApplyPerspectiveDepth(1); |
| 872 EXPECT_TRUE(MathUtil::hasPerspective(A)); | 963 EXPECT_TRUE(A.HasPerspective()); |
| 873 | 964 |
| 874 A.MakeIdentity(); | 965 A.MakeIdentity(); |
| 875 A.ApplyPerspectiveDepth(0); | 966 A.ApplyPerspectiveDepth(0); |
| 876 EXPECT_FALSE(MathUtil::hasPerspective(A)); | 967 EXPECT_FALSE(A.HasPerspective()); |
| 877 | 968 |
| 878 A.MakeIdentity(); | 969 A.MakeIdentity(); |
| 879 A.matrix().setDouble(3, 0, -1); | 970 A.matrix().setDouble(3, 0, -1); |
| 880 EXPECT_TRUE(MathUtil::hasPerspective(A)); | 971 EXPECT_TRUE(A.HasPerspective()); |
| 881 | 972 |
| 882 A.MakeIdentity(); | 973 A.MakeIdentity(); |
| 883 A.matrix().setDouble(3, 1, -1); | 974 A.matrix().setDouble(3, 1, -1); |
| 884 EXPECT_TRUE(MathUtil::hasPerspective(A)); | 975 EXPECT_TRUE(A.HasPerspective()); |
| 885 | 976 |
| 886 A.MakeIdentity(); | 977 A.MakeIdentity(); |
| 887 A.matrix().setDouble(3, 2, -0.3); | 978 A.matrix().setDouble(3, 2, -0.3); |
| 888 EXPECT_TRUE(MathUtil::hasPerspective(A)); | 979 EXPECT_TRUE(A.HasPerspective()); |
| 889 | 980 |
| 890 A.MakeIdentity(); | 981 A.MakeIdentity(); |
| 891 A.matrix().setDouble(3, 3, 0.5); | 982 A.matrix().setDouble(3, 3, 0.5); |
| 892 EXPECT_TRUE(MathUtil::hasPerspective(A)); | 983 EXPECT_TRUE(A.HasPerspective()); |
| 893 | 984 |
| 894 A.MakeIdentity(); | 985 A.MakeIdentity(); |
| 895 A.matrix().setDouble(3, 3, 0); | 986 A.matrix().setDouble(3, 3, 0); |
| 896 EXPECT_TRUE(MathUtil::hasPerspective(A)); | 987 EXPECT_TRUE(A.HasPerspective()); |
| 897 } | 988 } |
| 898 | 989 |
| 899 TEST(MathUtilGfxTransformTest, verifyIsInvertible) | 990 TEST(MathUtilGfxTransformTest, verifyIsInvertible) |
| 900 { | 991 { |
| 901 gfx::Transform A; | 992 gfx::Transform A; |
| 902 | 993 |
| 903 // Translations, rotations, scales, skews and arbitrary combinations of them
are invertible. | 994 // Translations, rotations, scales, skews and arbitrary combinations of them
are invertible. |
| 904 A.MakeIdentity(); | 995 A.MakeIdentity(); |
| 905 EXPECT_TRUE(A.IsInvertible()); | 996 EXPECT_TRUE(A.IsInvertible()); |
| 906 | 997 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 A.MakeIdentity(); | 1117 A.MakeIdentity(); |
| 1027 A.matrix().setDouble(3, 3, 2); | 1118 A.matrix().setDouble(3, 3, 2); |
| 1028 EXPECT_FALSE(A.IsIdentity()); | 1119 EXPECT_FALSE(A.IsIdentity()); |
| 1029 } | 1120 } |
| 1030 | 1121 |
| 1031 TEST(MathUtilGfxTransformTest, verifyIsIdentityOrTranslation) | 1122 TEST(MathUtilGfxTransformTest, verifyIsIdentityOrTranslation) |
| 1032 { | 1123 { |
| 1033 gfx::Transform A; | 1124 gfx::Transform A; |
| 1034 | 1125 |
| 1035 initializeTestMatrix(&A); | 1126 initializeTestMatrix(&A); |
| 1036 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1127 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
| 1037 | 1128 |
| 1038 A.MakeIdentity(); | 1129 A.MakeIdentity(); |
| 1039 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); | 1130 EXPECT_TRUE(A.IsIdentityOrTranslation()); |
| 1040 | 1131 |
| 1041 // Modifying any non-translation components should cause isIdentityOrTransla
tion() to | 1132 // Modifying any non-translation components should cause IsIdentityOrTransla
tion() to |
| 1042 // return false. NOTE: (0, 3), (1, 3), and (2, 3) are the translation compon
ents, so | 1133 // return false. NOTE: (0, 3), (1, 3), and (2, 3) are the translation compon
ents, so |
| 1043 // modifying them should still return true for isIdentityOrTranslation(). | 1134 // modifying them should still return true. |
| 1044 A.MakeIdentity(); | 1135 A.MakeIdentity(); |
| 1045 A.matrix().setDouble(0, 0, 2); | 1136 A.matrix().setDouble(0, 0, 2); |
| 1046 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1137 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
| 1047 | 1138 |
| 1048 A.MakeIdentity(); | 1139 A.MakeIdentity(); |
| 1049 A.matrix().setDouble(1, 0, 2); | 1140 A.matrix().setDouble(1, 0, 2); |
| 1050 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1141 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
| 1051 | 1142 |
| 1052 A.MakeIdentity(); | 1143 A.MakeIdentity(); |
| 1053 A.matrix().setDouble(2, 0, 2); | 1144 A.matrix().setDouble(2, 0, 2); |
| 1054 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1145 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
| 1055 | 1146 |
| 1056 A.MakeIdentity(); | 1147 A.MakeIdentity(); |
| 1057 A.matrix().setDouble(3, 0, 2); | 1148 A.matrix().setDouble(3, 0, 2); |
| 1058 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1149 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
| 1059 | 1150 |
| 1060 A.MakeIdentity(); | 1151 A.MakeIdentity(); |
| 1061 A.matrix().setDouble(0, 0, 2); | 1152 A.matrix().setDouble(0, 1, 2); |
| 1062 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1153 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
| 1063 | 1154 |
| 1064 A.MakeIdentity(); | 1155 A.MakeIdentity(); |
| 1065 A.matrix().setDouble(1, 1, 2); | 1156 A.matrix().setDouble(1, 1, 2); |
| 1066 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1157 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
| 1067 | 1158 |
| 1068 A.MakeIdentity(); | 1159 A.MakeIdentity(); |
| 1069 A.matrix().setDouble(2, 1, 2); | 1160 A.matrix().setDouble(2, 1, 2); |
| 1070 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1161 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
| 1071 | 1162 |
| 1072 A.MakeIdentity(); | 1163 A.MakeIdentity(); |
| 1073 A.matrix().setDouble(3, 1, 2); | 1164 A.matrix().setDouble(3, 1, 2); |
| 1074 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1165 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
| 1075 | 1166 |
| 1076 A.MakeIdentity(); | 1167 A.MakeIdentity(); |
| 1077 A.matrix().setDouble(0, 2, 2); | 1168 A.matrix().setDouble(0, 2, 2); |
| 1078 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1169 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
| 1079 | 1170 |
| 1080 A.MakeIdentity(); | 1171 A.MakeIdentity(); |
| 1081 A.matrix().setDouble(1, 2, 2); | 1172 A.matrix().setDouble(1, 2, 2); |
| 1082 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1173 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
| 1083 | 1174 |
| 1084 A.MakeIdentity(); | 1175 A.MakeIdentity(); |
| 1085 A.matrix().setDouble(2, 2, 2); | 1176 A.matrix().setDouble(2, 2, 2); |
| 1086 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1177 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
| 1087 | 1178 |
| 1088 A.MakeIdentity(); | 1179 A.MakeIdentity(); |
| 1089 A.matrix().setDouble(3, 2, 2); | 1180 A.matrix().setDouble(3, 2, 2); |
| 1090 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1181 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
| 1091 | 1182 |
| 1092 // Note carefully - expecting true here. | 1183 // Note carefully - expecting true here. |
| 1093 A.MakeIdentity(); | 1184 A.MakeIdentity(); |
| 1094 A.matrix().setDouble(0, 3, 2); | 1185 A.matrix().setDouble(0, 3, 2); |
| 1095 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); | 1186 EXPECT_TRUE(A.IsIdentityOrTranslation()); |
| 1096 | 1187 |
| 1097 // Note carefully - expecting true here. | 1188 // Note carefully - expecting true here. |
| 1098 A.MakeIdentity(); | 1189 A.MakeIdentity(); |
| 1099 A.matrix().setDouble(1, 3, 2); | 1190 A.matrix().setDouble(1, 3, 2); |
| 1100 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); | 1191 EXPECT_TRUE(A.IsIdentityOrTranslation()); |
| 1101 | 1192 |
| 1102 // Note carefully - expecting true here. | 1193 // Note carefully - expecting true here. |
| 1103 A.MakeIdentity(); | 1194 A.MakeIdentity(); |
| 1104 A.matrix().setDouble(2, 3, 2); | 1195 A.matrix().setDouble(2, 3, 2); |
| 1105 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); | 1196 EXPECT_TRUE(A.IsIdentityOrTranslation()); |
| 1106 | 1197 |
| 1107 A.MakeIdentity(); | 1198 A.MakeIdentity(); |
| 1108 A.matrix().setDouble(3, 3, 2); | 1199 A.matrix().setDouble(3, 3, 2); |
| 1109 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1200 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
| 1201 } |
| 1202 |
| 1203 TEST(MathUtilGfxTransformTest, verifyIsScaleOrTranslation) |
| 1204 { |
| 1205 gfx::Transform A; |
| 1206 |
| 1207 initializeTestMatrix(&A); |
| 1208 EXPECT_FALSE(A.IsScaleOrTranslation()); |
| 1209 |
| 1210 A.MakeIdentity(); |
| 1211 EXPECT_TRUE(A.IsScaleOrTranslation()); |
| 1212 |
| 1213 // Modifying any non-scale or non-translation components should cause |
| 1214 // IsScaleOrTranslation() to return false. (0, 0), (1, 1), (2, 2), (0, 3), |
| 1215 // (1, 3), and (2, 3) are the scale and translation components, so |
| 1216 // modifying them should still return true. |
| 1217 |
| 1218 // Note carefully - expecting true here. |
| 1219 A.MakeIdentity(); |
| 1220 A.matrix().setDouble(0, 0, 2); |
| 1221 EXPECT_TRUE(A.IsScaleOrTranslation()); |
| 1222 |
| 1223 A.MakeIdentity(); |
| 1224 A.matrix().setDouble(1, 0, 2); |
| 1225 EXPECT_FALSE(A.IsScaleOrTranslation()); |
| 1226 |
| 1227 A.MakeIdentity(); |
| 1228 A.matrix().setDouble(2, 0, 2); |
| 1229 EXPECT_FALSE(A.IsScaleOrTranslation()); |
| 1230 |
| 1231 A.MakeIdentity(); |
| 1232 A.matrix().setDouble(3, 0, 2); |
| 1233 EXPECT_FALSE(A.IsScaleOrTranslation()); |
| 1234 |
| 1235 A.MakeIdentity(); |
| 1236 A.matrix().setDouble(0, 1, 2); |
| 1237 EXPECT_FALSE(A.IsScaleOrTranslation()); |
| 1238 |
| 1239 // Note carefully - expecting true here. |
| 1240 A.MakeIdentity(); |
| 1241 A.matrix().setDouble(1, 1, 2); |
| 1242 EXPECT_TRUE(A.IsScaleOrTranslation()); |
| 1243 |
| 1244 A.MakeIdentity(); |
| 1245 A.matrix().setDouble(2, 1, 2); |
| 1246 EXPECT_FALSE(A.IsScaleOrTranslation()); |
| 1247 |
| 1248 A.MakeIdentity(); |
| 1249 A.matrix().setDouble(3, 1, 2); |
| 1250 EXPECT_FALSE(A.IsScaleOrTranslation()); |
| 1251 |
| 1252 A.MakeIdentity(); |
| 1253 A.matrix().setDouble(0, 2, 2); |
| 1254 EXPECT_FALSE(A.IsScaleOrTranslation()); |
| 1255 |
| 1256 A.MakeIdentity(); |
| 1257 A.matrix().setDouble(1, 2, 2); |
| 1258 EXPECT_FALSE(A.IsScaleOrTranslation()); |
| 1259 |
| 1260 // Note carefully - expecting true here. |
| 1261 A.MakeIdentity(); |
| 1262 A.matrix().setDouble(2, 2, 2); |
| 1263 EXPECT_TRUE(A.IsScaleOrTranslation()); |
| 1264 |
| 1265 A.MakeIdentity(); |
| 1266 A.matrix().setDouble(3, 2, 2); |
| 1267 EXPECT_FALSE(A.IsScaleOrTranslation()); |
| 1268 |
| 1269 // Note carefully - expecting true here. |
| 1270 A.MakeIdentity(); |
| 1271 A.matrix().setDouble(0, 3, 2); |
| 1272 EXPECT_TRUE(A.IsScaleOrTranslation()); |
| 1273 |
| 1274 // Note carefully - expecting true here. |
| 1275 A.MakeIdentity(); |
| 1276 A.matrix().setDouble(1, 3, 2); |
| 1277 EXPECT_TRUE(A.IsScaleOrTranslation()); |
| 1278 |
| 1279 // Note carefully - expecting true here. |
| 1280 A.MakeIdentity(); |
| 1281 A.matrix().setDouble(2, 3, 2); |
| 1282 EXPECT_TRUE(A.IsScaleOrTranslation()); |
| 1283 |
| 1284 A.MakeIdentity(); |
| 1285 A.matrix().setDouble(3, 3, 2); |
| 1286 EXPECT_FALSE(A.IsScaleOrTranslation()); |
| 1110 } | 1287 } |
| 1111 | 1288 |
| 1112 } // namespace | 1289 } // namespace |
| 1113 } // namespace cc | 1290 } // namespace cc |
| OLD | NEW |