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 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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, verifyRotateAxisAngleForAlignedAxes) |
731 { | 731 { |
732 gfx::Transform A; | 732 gfx::Transform A; |
733 | 733 |
734 // Check rotation about z-axis | 734 // Check rotation about z-axis |
735 A.MakeIdentity(); | 735 A.MakeIdentity(); |
736 MathUtil::rotateAxisAngle(&A, 0, 0, 1, 90); | 736 A.RotateAboutZAxis(90); |
danakj
2012/11/28 20:52:17
I think you should duplicate this test with Rotate
| |
737 EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD); | 737 EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD); |
738 EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD); | 738 EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD); |
739 EXPECT_ROW3_EQ(0, 0, 1, 0, A); | 739 EXPECT_ROW3_EQ(0, 0, 1, 0, A); |
740 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 740 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
741 | 741 |
742 // Check rotation about x-axis | 742 // Check rotation about x-axis |
743 A.MakeIdentity(); | 743 A.MakeIdentity(); |
744 MathUtil::rotateAxisAngle(&A, 1, 0, 0, 90); | 744 A.RotateAboutXAxis(90); |
745 EXPECT_ROW1_EQ(1, 0, 0, 0, A); | 745 EXPECT_ROW1_EQ(1, 0, 0, 0, A); |
746 EXPECT_ROW2_NEAR(0, 0, -1, 0, A, ERROR_THRESHOLD); | 746 EXPECT_ROW2_NEAR(0, 0, -1, 0, A, ERROR_THRESHOLD); |
747 EXPECT_ROW3_NEAR(0, 1, 0, 0, A, ERROR_THRESHOLD); | 747 EXPECT_ROW3_NEAR(0, 1, 0, 0, A, ERROR_THRESHOLD); |
748 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 748 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
749 | 749 |
750 // Check rotation about y-axis. | 750 // Check rotation about y-axis. |
751 // 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. |
752 A.MakeIdentity(); | 752 A.MakeIdentity(); |
753 MathUtil::rotateAxisAngle(&A, 0, 1, 0, 90); | 753 A.RotateAboutYAxis(90); |
754 EXPECT_ROW1_NEAR(0, 0, 1, 0, A, ERROR_THRESHOLD); | 754 EXPECT_ROW1_NEAR(0, 0, 1, 0, A, ERROR_THRESHOLD); |
755 EXPECT_ROW2_EQ(0, 1, 0, 0, A); | 755 EXPECT_ROW2_EQ(0, 1, 0, 0, A); |
756 EXPECT_ROW3_NEAR(-1, 0, 0, 0, A, ERROR_THRESHOLD); | 756 EXPECT_ROW3_NEAR(-1, 0, 0, 0, A, ERROR_THRESHOLD); |
757 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 757 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
758 | 758 |
759 // Verify that rotate3d(axis, angle) post-multiplies the existing matrix. | 759 // Verify that rotate3d(axis, angle) post-multiplies the existing matrix. |
760 A.MakeIdentity(); | 760 A.MakeIdentity(); |
761 A.Scale3d(6, 7, 8); | 761 A.Scale3d(6, 7, 8); |
762 MathUtil::rotateAxisAngle(&A, 0, 0, 1, 90); | 762 A.RotateAboutZAxis(90); |
763 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD); | 763 EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD); |
764 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD); | 764 EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD); |
765 EXPECT_ROW3_EQ(0, 0, 8, 0, A); | 765 EXPECT_ROW3_EQ(0, 0, 8, 0, A); |
766 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 766 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
767 } | 767 } |
768 | 768 |
769 TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForArbitraryAxis) | 769 TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForArbitraryAxis) |
770 { | 770 { |
771 // Check rotation about an arbitrary non-axis-aligned vector. | 771 // Check rotation about an arbitrary non-axis-aligned vector. |
772 gfx::Transform A; | 772 gfx::Transform A; |
773 MathUtil::rotateAxisAngle(&A, 1, 1, 1, 90); | 773 A.RotateAbout(gfx::Vector3dF(1, 1, 1), 90); |
774 EXPECT_ROW1_NEAR(0.3333333333333334258519187, | 774 EXPECT_ROW1_NEAR(0.3333333333333334258519187, |
775 -0.2440169358562924717404030, | 775 -0.2440169358562924717404030, |
776 0.9106836025229592124219380, | 776 0.9106836025229592124219380, |
777 0, A, ERROR_THRESHOLD); | 777 0, A, ERROR_THRESHOLD); |
778 EXPECT_ROW2_NEAR(0.9106836025229592124219380, | 778 EXPECT_ROW2_NEAR(0.9106836025229592124219380, |
779 0.3333333333333334258519187, | 779 0.3333333333333334258519187, |
780 -0.2440169358562924717404030, | 780 -0.2440169358562924717404030, |
781 0, A, ERROR_THRESHOLD); | 781 0, A, ERROR_THRESHOLD); |
782 EXPECT_ROW3_NEAR(-0.2440169358562924717404030, | 782 EXPECT_ROW3_NEAR(-0.2440169358562924717404030, |
783 0.9106836025229592124219380, | 783 0.9106836025229592124219380, |
784 0.3333333333333334258519187, | 784 0.3333333333333334258519187, |
785 0, A, ERROR_THRESHOLD); | 785 0, A, ERROR_THRESHOLD); |
786 EXPECT_ROW4_EQ(0, 0, 0, 1, A); | 786 EXPECT_ROW4_EQ(0, 0, 0, 1, A); |
787 } | 787 } |
788 | 788 |
789 TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForDegenerateAxis) | 789 TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForDegenerateAxis) |
790 { | 790 { |
791 // Check rotation about a degenerate zero vector. | 791 // Check rotation about a degenerate zero vector. |
792 // It is expected to skip applying the rotation. | 792 // It is expected to skip applying the rotation. |
793 gfx::Transform A; | 793 gfx::Transform A; |
794 | 794 |
795 MathUtil::rotateAxisAngle(&A, 0, 0, 0, 45); | 795 A.RotateAbout(gfx::Vector3dF(0, 0, 0), 45); |
danakj
2012/11/28 20:42:59
I guess in my previous comment, I was also wonderi
danakj
2012/11/28 20:52:17
To answer my own question, I see this being used i
| |
796 // Verify that A remains unchanged. | 796 // Verify that A remains unchanged. |
797 EXPECT_TRUE(A.IsIdentity()); | 797 EXPECT_TRUE(A.IsIdentity()); |
798 | 798 |
799 initializeTestMatrix(&A); | 799 initializeTestMatrix(&A); |
800 MathUtil::rotateAxisAngle(&A, 0, 0, 0, 35); | 800 A.RotateAbout(gfx::Vector3dF(0, 0, 0), 35); |
801 | 801 |
802 // Verify that A remains unchanged. | 802 // Verify that A remains unchanged. |
803 EXPECT_ROW1_EQ(10, 14, 18, 22, A); | 803 EXPECT_ROW1_EQ(10, 14, 18, 22, A); |
804 EXPECT_ROW2_EQ(11, 15, 19, 23, A); | 804 EXPECT_ROW2_EQ(11, 15, 19, 23, A); |
805 EXPECT_ROW3_EQ(12, 16, 20, 24, A); | 805 EXPECT_ROW3_EQ(12, 16, 20, 24, A); |
806 EXPECT_ROW4_EQ(13, 17, 21, 25, A); | 806 EXPECT_ROW4_EQ(13, 17, 21, 25, A); |
807 } | 807 } |
808 | 808 |
809 TEST(MathUtilGfxTransformTest, verifySkewX) | 809 TEST(MathUtilGfxTransformTest, verifySkewX) |
810 { | 810 { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
862 EXPECT_ROW1_EQ(1, 0, -2, 2, A); | 862 EXPECT_ROW1_EQ(1, 0, -2, 2, A); |
863 EXPECT_ROW2_EQ(0, 1, -3, 3, A); | 863 EXPECT_ROW2_EQ(0, 1, -3, 3, A); |
864 EXPECT_ROW3_EQ(0, 0, -3, 4, A); | 864 EXPECT_ROW3_EQ(0, 0, -3, 4, A); |
865 EXPECT_ROW4_EQ(0, 0, -1, 1, A); | 865 EXPECT_ROW4_EQ(0, 0, -1, 1, A); |
866 } | 866 } |
867 | 867 |
868 TEST(MathUtilGfxTransformTest, verifyHasPerspective) | 868 TEST(MathUtilGfxTransformTest, verifyHasPerspective) |
869 { | 869 { |
870 gfx::Transform A; | 870 gfx::Transform A; |
871 A.ApplyPerspectiveDepth(1); | 871 A.ApplyPerspectiveDepth(1); |
872 EXPECT_TRUE(MathUtil::hasPerspective(A)); | 872 EXPECT_TRUE(A.HasPerspective()); |
873 | 873 |
874 A.MakeIdentity(); | 874 A.MakeIdentity(); |
875 A.ApplyPerspectiveDepth(0); | 875 A.ApplyPerspectiveDepth(0); |
876 EXPECT_FALSE(MathUtil::hasPerspective(A)); | 876 EXPECT_FALSE(A.HasPerspective()); |
877 | 877 |
878 A.MakeIdentity(); | 878 A.MakeIdentity(); |
879 A.matrix().setDouble(3, 0, -1); | 879 A.matrix().setDouble(3, 0, -1); |
880 EXPECT_TRUE(MathUtil::hasPerspective(A)); | 880 EXPECT_TRUE(A.HasPerspective()); |
881 | 881 |
882 A.MakeIdentity(); | 882 A.MakeIdentity(); |
883 A.matrix().setDouble(3, 1, -1); | 883 A.matrix().setDouble(3, 1, -1); |
884 EXPECT_TRUE(MathUtil::hasPerspective(A)); | 884 EXPECT_TRUE(A.HasPerspective()); |
885 | 885 |
886 A.MakeIdentity(); | 886 A.MakeIdentity(); |
887 A.matrix().setDouble(3, 2, -0.3); | 887 A.matrix().setDouble(3, 2, -0.3); |
888 EXPECT_TRUE(MathUtil::hasPerspective(A)); | 888 EXPECT_TRUE(A.HasPerspective()); |
889 | 889 |
890 A.MakeIdentity(); | 890 A.MakeIdentity(); |
891 A.matrix().setDouble(3, 3, 0.5); | 891 A.matrix().setDouble(3, 3, 0.5); |
892 EXPECT_TRUE(MathUtil::hasPerspective(A)); | 892 EXPECT_TRUE(A.HasPerspective()); |
893 | 893 |
894 A.MakeIdentity(); | 894 A.MakeIdentity(); |
895 A.matrix().setDouble(3, 3, 0); | 895 A.matrix().setDouble(3, 3, 0); |
896 EXPECT_TRUE(MathUtil::hasPerspective(A)); | 896 EXPECT_TRUE(A.HasPerspective()); |
897 } | 897 } |
898 | 898 |
899 TEST(MathUtilGfxTransformTest, verifyIsInvertible) | 899 TEST(MathUtilGfxTransformTest, verifyIsInvertible) |
900 { | 900 { |
901 gfx::Transform A; | 901 gfx::Transform A; |
902 | 902 |
903 // Translations, rotations, scales, skews and arbitrary combinations of them are invertible. | 903 // Translations, rotations, scales, skews and arbitrary combinations of them are invertible. |
904 A.MakeIdentity(); | 904 A.MakeIdentity(); |
905 EXPECT_TRUE(A.IsInvertible()); | 905 EXPECT_TRUE(A.IsInvertible()); |
906 | 906 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1026 A.MakeIdentity(); | 1026 A.MakeIdentity(); |
1027 A.matrix().setDouble(3, 3, 2); | 1027 A.matrix().setDouble(3, 3, 2); |
1028 EXPECT_FALSE(A.IsIdentity()); | 1028 EXPECT_FALSE(A.IsIdentity()); |
1029 } | 1029 } |
1030 | 1030 |
1031 TEST(MathUtilGfxTransformTest, verifyIsIdentityOrTranslation) | 1031 TEST(MathUtilGfxTransformTest, verifyIsIdentityOrTranslation) |
1032 { | 1032 { |
1033 gfx::Transform A; | 1033 gfx::Transform A; |
1034 | 1034 |
1035 initializeTestMatrix(&A); | 1035 initializeTestMatrix(&A); |
1036 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1036 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
1037 | 1037 |
1038 A.MakeIdentity(); | 1038 A.MakeIdentity(); |
1039 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); | 1039 EXPECT_TRUE(A.IsIdentityOrTranslation()); |
1040 | 1040 |
1041 // Modifying any non-translation components should cause isIdentityOrTransla tion() to | 1041 // 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 | 1042 // 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(). | 1043 // modifying them should still return true. |
1044 A.MakeIdentity(); | 1044 A.MakeIdentity(); |
1045 A.matrix().setDouble(0, 0, 2); | 1045 A.matrix().setDouble(0, 0, 2); |
1046 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1046 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
1047 | 1047 |
1048 A.MakeIdentity(); | 1048 A.MakeIdentity(); |
1049 A.matrix().setDouble(1, 0, 2); | 1049 A.matrix().setDouble(1, 0, 2); |
1050 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1050 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
1051 | 1051 |
1052 A.MakeIdentity(); | 1052 A.MakeIdentity(); |
1053 A.matrix().setDouble(2, 0, 2); | 1053 A.matrix().setDouble(2, 0, 2); |
1054 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1054 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
1055 | 1055 |
1056 A.MakeIdentity(); | 1056 A.MakeIdentity(); |
1057 A.matrix().setDouble(3, 0, 2); | 1057 A.matrix().setDouble(3, 0, 2); |
1058 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1058 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
1059 | 1059 |
1060 A.MakeIdentity(); | 1060 A.MakeIdentity(); |
1061 A.matrix().setDouble(0, 0, 2); | 1061 A.matrix().setDouble(0, 1, 2); |
1062 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1062 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
1063 | 1063 |
1064 A.MakeIdentity(); | 1064 A.MakeIdentity(); |
1065 A.matrix().setDouble(1, 1, 2); | 1065 A.matrix().setDouble(1, 1, 2); |
1066 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1066 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
1067 | 1067 |
1068 A.MakeIdentity(); | 1068 A.MakeIdentity(); |
1069 A.matrix().setDouble(2, 1, 2); | 1069 A.matrix().setDouble(2, 1, 2); |
1070 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1070 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
1071 | 1071 |
1072 A.MakeIdentity(); | 1072 A.MakeIdentity(); |
1073 A.matrix().setDouble(3, 1, 2); | 1073 A.matrix().setDouble(3, 1, 2); |
1074 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1074 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
1075 | 1075 |
1076 A.MakeIdentity(); | 1076 A.MakeIdentity(); |
1077 A.matrix().setDouble(0, 2, 2); | 1077 A.matrix().setDouble(0, 2, 2); |
1078 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1078 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
1079 | 1079 |
1080 A.MakeIdentity(); | 1080 A.MakeIdentity(); |
1081 A.matrix().setDouble(1, 2, 2); | 1081 A.matrix().setDouble(1, 2, 2); |
1082 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1082 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
1083 | 1083 |
1084 A.MakeIdentity(); | 1084 A.MakeIdentity(); |
1085 A.matrix().setDouble(2, 2, 2); | 1085 A.matrix().setDouble(2, 2, 2); |
1086 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1086 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
1087 | 1087 |
1088 A.MakeIdentity(); | 1088 A.MakeIdentity(); |
1089 A.matrix().setDouble(3, 2, 2); | 1089 A.matrix().setDouble(3, 2, 2); |
1090 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1090 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
1091 | 1091 |
1092 // Note carefully - expecting true here. | 1092 // Note carefully - expecting true here. |
1093 A.MakeIdentity(); | 1093 A.MakeIdentity(); |
1094 A.matrix().setDouble(0, 3, 2); | 1094 A.matrix().setDouble(0, 3, 2); |
1095 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); | 1095 EXPECT_TRUE(A.IsIdentityOrTranslation()); |
1096 | 1096 |
1097 // Note carefully - expecting true here. | 1097 // Note carefully - expecting true here. |
1098 A.MakeIdentity(); | 1098 A.MakeIdentity(); |
1099 A.matrix().setDouble(1, 3, 2); | 1099 A.matrix().setDouble(1, 3, 2); |
1100 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); | 1100 EXPECT_TRUE(A.IsIdentityOrTranslation()); |
1101 | 1101 |
1102 // Note carefully - expecting true here. | 1102 // Note carefully - expecting true here. |
1103 A.MakeIdentity(); | 1103 A.MakeIdentity(); |
1104 A.matrix().setDouble(2, 3, 2); | 1104 A.matrix().setDouble(2, 3, 2); |
1105 EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); | 1105 EXPECT_TRUE(A.IsIdentityOrTranslation()); |
1106 | 1106 |
1107 A.MakeIdentity(); | 1107 A.MakeIdentity(); |
1108 A.matrix().setDouble(3, 3, 2); | 1108 A.matrix().setDouble(3, 3, 2); |
1109 EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); | 1109 EXPECT_FALSE(A.IsIdentityOrTranslation()); |
1110 } | |
1111 | |
1112 TEST(MathUtilGfxTransformTest, verifyIsScaleOrTranslation) | |
1113 { | |
1114 gfx::Transform A; | |
1115 | |
1116 initializeTestMatrix(&A); | |
1117 EXPECT_FALSE(A.IsScaleOrTranslation()); | |
1118 | |
1119 A.MakeIdentity(); | |
1120 EXPECT_TRUE(A.IsScaleOrTranslation()); | |
1121 | |
1122 // Modifying any non-scale or non-translation components should cause | |
1123 // IsScaleOrTranslation() to return false. (0, 0), (1, 1), (2, 2), (0, 3), | |
1124 // (1, 3), and (2, 3) are the scale and translation components, so | |
1125 // modifying them should still return true. | |
1126 | |
1127 // Note carefully - expecting true here. | |
1128 A.MakeIdentity(); | |
1129 A.matrix().setDouble(0, 0, 2); | |
1130 EXPECT_TRUE(A.IsScaleOrTranslation()); | |
1131 | |
1132 A.MakeIdentity(); | |
1133 A.matrix().setDouble(1, 0, 2); | |
1134 EXPECT_FALSE(A.IsScaleOrTranslation()); | |
1135 | |
1136 A.MakeIdentity(); | |
1137 A.matrix().setDouble(2, 0, 2); | |
1138 EXPECT_FALSE(A.IsScaleOrTranslation()); | |
1139 | |
1140 A.MakeIdentity(); | |
1141 A.matrix().setDouble(3, 0, 2); | |
1142 EXPECT_FALSE(A.IsScaleOrTranslation()); | |
1143 | |
1144 A.MakeIdentity(); | |
1145 A.matrix().setDouble(0, 1, 2); | |
1146 EXPECT_FALSE(A.IsScaleOrTranslation()); | |
1147 | |
1148 // Note carefully - expecting true here. | |
1149 A.MakeIdentity(); | |
1150 A.matrix().setDouble(1, 1, 2); | |
1151 EXPECT_TRUE(A.IsScaleOrTranslation()); | |
1152 | |
1153 A.MakeIdentity(); | |
1154 A.matrix().setDouble(2, 1, 2); | |
1155 EXPECT_FALSE(A.IsScaleOrTranslation()); | |
1156 | |
1157 A.MakeIdentity(); | |
1158 A.matrix().setDouble(3, 1, 2); | |
1159 EXPECT_FALSE(A.IsScaleOrTranslation()); | |
1160 | |
1161 A.MakeIdentity(); | |
1162 A.matrix().setDouble(0, 2, 2); | |
1163 EXPECT_FALSE(A.IsScaleOrTranslation()); | |
1164 | |
1165 A.MakeIdentity(); | |
1166 A.matrix().setDouble(1, 2, 2); | |
1167 EXPECT_FALSE(A.IsScaleOrTranslation()); | |
1168 | |
1169 // Note carefully - expecting true here. | |
1170 A.MakeIdentity(); | |
1171 A.matrix().setDouble(2, 2, 2); | |
1172 EXPECT_TRUE(A.IsScaleOrTranslation()); | |
1173 | |
1174 A.MakeIdentity(); | |
1175 A.matrix().setDouble(3, 2, 2); | |
1176 EXPECT_FALSE(A.IsScaleOrTranslation()); | |
1177 | |
1178 // Note carefully - expecting true here. | |
1179 A.MakeIdentity(); | |
1180 A.matrix().setDouble(0, 3, 2); | |
1181 EXPECT_TRUE(A.IsScaleOrTranslation()); | |
1182 | |
1183 // Note carefully - expecting true here. | |
1184 A.MakeIdentity(); | |
1185 A.matrix().setDouble(1, 3, 2); | |
1186 EXPECT_TRUE(A.IsScaleOrTranslation()); | |
1187 | |
1188 // Note carefully - expecting true here. | |
1189 A.MakeIdentity(); | |
1190 A.matrix().setDouble(2, 3, 2); | |
1191 EXPECT_TRUE(A.IsScaleOrTranslation()); | |
1192 | |
1193 A.MakeIdentity(); | |
1194 A.matrix().setDouble(3, 3, 2); | |
1195 EXPECT_FALSE(A.IsScaleOrTranslation()); | |
1110 } | 1196 } |
1111 | 1197 |
1112 } // namespace | 1198 } // namespace |
1113 } // namespace cc | 1199 } // namespace cc |
OLD | NEW |