Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <limits> | 5 #include <limits> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "cc/animation/transform_operations.h" | 9 #include "cc/animation/transform_operations.h" |
| 10 #include "cc/test/geometry_test_utils.h" | 10 #include "cc/test/geometry_test_utils.h" |
| (...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 920 operations_to.AppendRotate(1.f, 1.f, 1.f, 390.f); | 920 operations_to.AppendRotate(1.f, 1.f, 1.f, 390.f); |
| 921 | 921 |
| 922 gfx::BoxF box(1.f, 1.f, 1.f, 0.f, 0.f, 0.f); | 922 gfx::BoxF box(1.f, 1.f, 1.f, 0.f, 0.f, 0.f); |
| 923 gfx::BoxF bounds; | 923 gfx::BoxF bounds; |
| 924 | 924 |
| 925 EXPECT_TRUE(operations_to.BlendedBoundsForBox( | 925 EXPECT_TRUE(operations_to.BlendedBoundsForBox( |
| 926 box, operations_from, 0.f, 1.f, &bounds)); | 926 box, operations_from, 0.f, 1.f, &bounds)); |
| 927 EXPECT_EQ(box.ToString(), bounds.ToString()); | 927 EXPECT_EQ(box.ToString(), bounds.ToString()); |
| 928 } | 928 } |
| 929 | 929 |
| 930 // This would have been best as anonymous structs, but |arraysize| does not get | |
| 931 // along with anonymous structs (and using ARRAYSIZE_UNSAFE seemed like a worse | |
| 932 // option). | |
| 933 struct ProblematicAxisTest { | |
| 934 float x; | |
| 935 float y; | |
| 936 float z; | |
| 937 gfx::BoxF expected; | |
| 938 }; | |
| 939 | |
| 940 TEST(TransformOperationTest, BlendedBoundsForRotationProblematicAxes) { | 930 TEST(TransformOperationTest, BlendedBoundsForRotationProblematicAxes) { |
| 941 // Zeros in the components of the axis of rotation turned out to be tricky to | 931 // Zeros in the components of the axis of rotation turned out to be tricky to |
| 942 // deal with in practice. This function tests some potentially problematic | 932 // deal with in practice. This function tests some potentially problematic |
| 943 // axes to ensure sane behavior. | 933 // axes to ensure sane behavior. |
| 944 | 934 |
| 945 // Some common values used in the expected boxes. | 935 // Some common values used in the expected boxes. |
| 946 float dim1 = 0.292893f; | 936 float dim1 = 0.292893f; |
| 947 float dim2 = sqrt(2.f); | 937 float dim2 = sqrt(2.f); |
| 948 float dim3 = 2.f * dim2; | 938 float dim3 = 2.f * dim2; |
| 949 | 939 |
| 950 ProblematicAxisTest tests[] = { | 940 struct { |
| 951 { 0.f, 0.f, 0.f, gfx::BoxF(1.f, 1.f, 1.f, 0.f, 0.f, 0.f) }, | 941 float x; |
| 952 { 1.f, 0.f, 0.f, gfx::BoxF(1.f, -dim2, -dim2, 0.f, dim3, dim3) }, | 942 float y; |
| 953 { 0.f, 1.f, 0.f, gfx::BoxF(-dim2, 1.f, -dim2, dim3, 0.f, dim3) }, | 943 float z; |
| 954 { 0.f, 0.f, 1.f, gfx::BoxF(-dim2, -dim2, 1.f, dim3, dim3, 0.f) }, | 944 gfx::BoxF expected; |
| 955 { 1.f, 1.f, 0.f, gfx::BoxF(dim1, dim1, -1.f, dim2, dim2, 2.f) }, | 945 } tests[] = {{0.f, 0.f, 0.f, gfx::BoxF(1.f, 1.f, 1.f, 0.f, 0.f, 0.f)}, |
| 956 { 0.f, 1.f, 1.f, gfx::BoxF(-1.f, dim1, dim1, 2.f, dim2, dim2) }, | 946 {1.f, 0.f, 0.f, gfx::BoxF(1.f, -dim2, -dim2, 0.f, dim3, dim3)}, |
| 957 { 1.f, 0.f, 1.f, gfx::BoxF(dim1, -1.f, dim1, dim2, 2.f, dim2) } | 947 {0.f, 1.f, 0.f, gfx::BoxF(-dim2, 1.f, -dim2, dim3, 0.f, dim3)}, |
| 958 }; | 948 {0.f, 0.f, 1.f, gfx::BoxF(-dim2, -dim2, 1.f, dim3, dim3, 0.f)}, |
| 949 {1.f, 1.f, 0.f, gfx::BoxF(dim1, dim1, -1.f, dim2, dim2, 2.f)}, | |
| 950 {0.f, 1.f, 1.f, gfx::BoxF(-1.f, dim1, dim1, 2.f, dim2, dim2)}, | |
| 951 {1.f, 0.f, 1.f, gfx::BoxF(dim1, -1.f, dim1, dim2, 2.f, dim2)}}; | |
| 959 | 952 |
| 960 for (size_t i = 0; i < arraysize(tests); ++i) { | 953 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 961 float x = tests[i].x; | 954 float x = tests[i].x; |
| 962 float y = tests[i].y; | 955 float y = tests[i].y; |
| 963 float z = tests[i].z; | 956 float z = tests[i].z; |
| 964 TransformOperations operations_from; | 957 TransformOperations operations_from; |
| 965 operations_from.AppendRotate(x, y, z, 0.f); | 958 operations_from.AppendRotate(x, y, z, 0.f); |
| 966 TransformOperations operations_to; | 959 TransformOperations operations_to; |
| 967 operations_to.AppendRotate(x, y, z, 360.f); | 960 operations_to.AppendRotate(x, y, z, 360.f); |
| 968 gfx::BoxF box(1.f, 1.f, 1.f, 0.f, 0.f, 0.f); | 961 gfx::BoxF box(1.f, 1.f, 1.f, 0.f, 0.f, 0.f); |
| 969 gfx::BoxF bounds; | 962 gfx::BoxF bounds; |
| 970 | 963 |
| 971 EXPECT_TRUE(operations_to.BlendedBoundsForBox( | 964 EXPECT_TRUE(operations_to.BlendedBoundsForBox( |
| 972 box, operations_from, 0.f, 1.f, &bounds)); | 965 box, operations_from, 0.f, 1.f, &bounds)); |
| 973 EXPECT_EQ(tests[i].expected.ToString(), bounds.ToString()); | 966 EXPECT_EQ(tests[i].expected.ToString(), bounds.ToString()); |
| 974 } | 967 } |
| 975 } | 968 } |
| 976 | 969 |
| 977 // These would have been best as anonymous structs, but |arraysize| does not get | |
| 978 // along with anonymous structs (and using ARRAYSIZE_UNSAFE seemed like a worse | |
| 979 // option). | |
| 980 struct TestAxis { | |
| 981 float x; | |
| 982 float y; | |
| 983 float z; | |
| 984 }; | |
| 985 | |
| 986 struct TestAngles { | |
| 987 float theta_from; | |
| 988 float theta_to; | |
| 989 }; | |
| 990 | |
| 991 struct TestProgress { | |
| 992 float min_progress; | |
| 993 float max_progress; | |
| 994 }; | |
| 995 | |
| 996 static void ExpectBoxesApproximatelyEqual(const gfx::BoxF& lhs, | 970 static void ExpectBoxesApproximatelyEqual(const gfx::BoxF& lhs, |
| 997 const gfx::BoxF& rhs, | 971 const gfx::BoxF& rhs, |
| 998 float tolerance) { | 972 float tolerance) { |
| 999 EXPECT_NEAR(lhs.x(), rhs.x(), tolerance); | 973 EXPECT_NEAR(lhs.x(), rhs.x(), tolerance); |
| 1000 EXPECT_NEAR(lhs.y(), rhs.y(), tolerance); | 974 EXPECT_NEAR(lhs.y(), rhs.y(), tolerance); |
| 1001 EXPECT_NEAR(lhs.z(), rhs.z(), tolerance); | 975 EXPECT_NEAR(lhs.z(), rhs.z(), tolerance); |
| 1002 EXPECT_NEAR(lhs.width(), rhs.width(), tolerance); | 976 EXPECT_NEAR(lhs.width(), rhs.width(), tolerance); |
| 1003 EXPECT_NEAR(lhs.height(), rhs.height(), tolerance); | 977 EXPECT_NEAR(lhs.height(), rhs.height(), tolerance); |
| 1004 EXPECT_NEAR(lhs.depth(), rhs.depth(), tolerance); | 978 EXPECT_NEAR(lhs.depth(), rhs.depth(), tolerance); |
| 1005 } | 979 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1064 SkMScalar min_progress, | 1038 SkMScalar min_progress, |
| 1065 SkMScalar max_progress) { | 1039 SkMScalar max_progress) { |
| 1066 EmpiricallyTestBounds(from, to, min_progress, max_progress, true); | 1040 EmpiricallyTestBounds(from, to, min_progress, max_progress, true); |
| 1067 } | 1041 } |
| 1068 | 1042 |
| 1069 TEST(TransformOperationTest, BlendedBoundsForRotationEmpiricalTests) { | 1043 TEST(TransformOperationTest, BlendedBoundsForRotationEmpiricalTests) { |
| 1070 // Sets up various axis angle combinations, computes the bounding box and | 1044 // Sets up various axis angle combinations, computes the bounding box and |
| 1071 // empirically tests that the transformed bounds are indeed contained by the | 1045 // empirically tests that the transformed bounds are indeed contained by the |
| 1072 // computed bounding box. | 1046 // computed bounding box. |
| 1073 | 1047 |
| 1074 TestAxis axes[] = { | 1048 struct { |
| 1075 { 1.f, 1.f, 1.f }, | 1049 float x; |
| 1076 { -1.f, -1.f, -1.f }, | 1050 float y; |
| 1077 { -1.f, 2.f, 3.f }, | 1051 float z; |
| 1078 { 1.f, -2.f, 3.f }, | 1052 } axes[] = {{1.f, 1.f, 1.f}, |
| 1079 { 1.f, 2.f, -3.f }, | 1053 {-1.f, -1.f, -1.f}, |
| 1080 { 0.f, 0.f, 0.f }, | 1054 {-1.f, 2.f, 3.f}, |
| 1081 { 1.f, 0.f, 0.f }, | 1055 {1.f, -2.f, 3.f}, |
| 1082 { 0.f, 1.f, 0.f }, | 1056 {1.f, 2.f, -3.f}, |
| 1083 { 0.f, 0.f, 1.f }, | 1057 {0.f, 0.f, 0.f}, |
| 1084 { 1.f, 1.f, 0.f }, | 1058 {1.f, 0.f, 0.f}, |
| 1085 { 0.f, 1.f, 1.f }, | 1059 {0.f, 1.f, 0.f}, |
| 1086 { 1.f, 0.f, 1.f }, | 1060 {0.f, 0.f, 1.f}, |
| 1087 { -1.f, 0.f, 0.f }, | 1061 {1.f, 1.f, 0.f}, |
| 1088 { 0.f, -1.f, 0.f }, | 1062 {0.f, 1.f, 1.f}, |
| 1089 { 0.f, 0.f, -1.f }, | 1063 {1.f, 0.f, 1.f}, |
| 1090 { -1.f, -1.f, 0.f }, | 1064 {-1.f, 0.f, 0.f}, |
| 1091 { 0.f, -1.f, -1.f }, | 1065 {0.f, -1.f, 0.f}, |
| 1092 { -1.f, 0.f, -1.f } | 1066 {0.f, 0.f, -1.f}, |
| 1093 }; | 1067 {-1.f, -1.f, 0.f}, |
| 1068 {0.f, -1.f, -1.f}, | |
| 1069 {-1.f, 0.f, -1.f}}; | |
| 1094 | 1070 |
| 1095 TestAngles angles[] = { | 1071 struct { |
| 1096 { 5.f, 10.f }, | 1072 float theta_from; |
| 1097 { 10.f, 5.f }, | 1073 float theta_to; |
| 1098 { 0.f, 360.f }, | 1074 } angles[] = {{5.f, 10.f}, |
| 1099 { 20.f, 180.f }, | 1075 {10.f, 5.f}, |
| 1100 { -20.f, -180.f }, | 1076 {0.f, 360.f}, |
| 1101 { 180.f, -220.f }, | 1077 {20.f, 180.f}, |
| 1102 { 220.f, 320.f } | 1078 {-20.f, -180.f}, |
| 1103 }; | 1079 {180.f, -220.f}, |
| 1080 {220.f, 320.f}}; | |
| 1104 | 1081 |
| 1105 // We can go beyond the range [0, 1] (the bezier might slide out of this range | 1082 // We can go beyond the range [0, 1] (the bezier might slide out of this range |
| 1106 // at either end), but since the first and last knots are at (0, 0) and (1, 1) | 1083 // at either end), but since the first and last knots are at (0, 0) and (1, 1) |
| 1107 // we will never go within it, so these tests are sufficient. | 1084 // we will never go within it, so these tests are sufficient. |
| 1108 TestProgress progress[] = { | 1085 struct { |
| 1109 { 0.f, 1.f }, | 1086 float min_progress; |
| 1110 { -.25f, 1.25f }, | 1087 float max_progress; |
| 1111 }; | 1088 } progress[] = { |
| 1089 {0.f, 1.f}, {-.25f, 1.25f}, | |
| 1090 }; | |
| 1112 | 1091 |
| 1113 for (size_t i = 0; i < arraysize(axes); ++i) { | 1092 for (size_t i = 0; i < arraysize(axes); ++i) { |
| 1114 for (size_t j = 0; j < arraysize(angles); ++j) { | 1093 for (size_t j = 0; j < arraysize(angles); ++j) { |
| 1115 for (size_t k = 0; k < arraysize(progress); ++k) { | 1094 for (size_t k = 0; k < arraysize(progress); ++k) { |
| 1116 float x = axes[i].x; | 1095 float x = axes[i].x; |
| 1117 float y = axes[i].y; | 1096 float y = axes[i].y; |
| 1118 float z = axes[i].z; | 1097 float z = axes[i].z; |
| 1119 TransformOperations operations_from; | 1098 TransformOperations operations_from; |
| 1120 operations_from.AppendRotate(x, y, z, angles[j].theta_from); | 1099 operations_from.AppendRotate(x, y, z, angles[j].theta_from); |
| 1121 TransformOperations operations_to; | 1100 TransformOperations operations_to; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1149 gfx::Transform blended_matrix = to_transform; | 1128 gfx::Transform blended_matrix = to_transform; |
| 1150 EXPECT_TRUE(blended_matrix.Blend(from_transform, progress)); | 1129 EXPECT_TRUE(blended_matrix.Blend(from_transform, progress)); |
| 1151 | 1130 |
| 1152 gfx::Transform blended_transform = | 1131 gfx::Transform blended_transform = |
| 1153 to_operations.Blend(from_operations, progress); | 1132 to_operations.Blend(from_operations, progress); |
| 1154 | 1133 |
| 1155 EXPECT_TRANSFORMATION_MATRIX_EQ(blended_matrix, blended_transform); | 1134 EXPECT_TRANSFORMATION_MATRIX_EQ(blended_matrix, blended_transform); |
| 1156 } | 1135 } |
| 1157 } | 1136 } |
| 1158 | 1137 |
| 1159 struct TestPerspectiveDepths { | 1138 TEST(TransformOperationTest, BlendedBoundsForPerspective) { |
| 1160 float from_depth; | 1139 struct { |
| 1161 float to_depth; | 1140 float from_depth; |
| 1162 }; | 1141 float to_depth; |
| 1142 } perspective_depths[] = { | |
| 1143 {600.f, 400.f}, | |
| 1144 {800.f, 1000.f}, | |
| 1145 {800.f, std::numeric_limits<float>::infinity()}, | |
| 1146 }; | |
| 1163 | 1147 |
| 1164 TEST(TransformOperationTest, BlendedBoundsForPerspective) { | 1148 struct { |
| 1165 TestPerspectiveDepths perspective_depths[] = { | 1149 float min_progress; |
| 1166 { 600.f, 400.f }, | 1150 float max_progress; |
| 1167 { 800.f, 1000.f }, | 1151 } progress[] = { |
| 1168 { 800.f, std::numeric_limits<float>::infinity() }, | 1152 {0.f, 1.f}, {-0.1f, 1.1f}, |
| 1169 }; | 1153 }; |
| 1170 | |
| 1171 TestProgress progress[] = { | |
| 1172 { 0.f, 1.f }, | |
| 1173 { -0.1f, 1.1f }, | |
| 1174 }; | |
| 1175 | 1154 |
| 1176 for (size_t i = 0; i < arraysize(perspective_depths); ++i) { | 1155 for (size_t i = 0; i < arraysize(perspective_depths); ++i) { |
| 1177 for (size_t j = 0; j < arraysize(progress); ++j) { | 1156 for (size_t j = 0; j < arraysize(progress); ++j) { |
| 1178 TransformOperations operations_from; | 1157 TransformOperations operations_from; |
| 1179 operations_from.AppendPerspective(perspective_depths[i].from_depth); | 1158 operations_from.AppendPerspective(perspective_depths[i].from_depth); |
| 1180 TransformOperations operations_to; | 1159 TransformOperations operations_to; |
| 1181 operations_to.AppendPerspective(perspective_depths[i].to_depth); | 1160 operations_to.AppendPerspective(perspective_depths[i].to_depth); |
| 1182 EmpiricallyTestBoundsEquality(operations_from, | 1161 EmpiricallyTestBoundsEquality(operations_from, |
| 1183 operations_to, | 1162 operations_to, |
| 1184 progress[j].min_progress, | 1163 progress[j].min_progress, |
| 1185 progress[j].max_progress); | 1164 progress[j].max_progress); |
| 1186 } | 1165 } |
| 1187 } | 1166 } |
| 1188 } | 1167 } |
| 1189 | 1168 |
| 1190 struct TestSkews { | 1169 TEST(TransformOperationTest, BlendedBoundsForSkew) { |
| 1191 float from_x; | 1170 struct { |
| 1192 float from_y; | 1171 float from_x; |
| 1193 float to_x; | 1172 float from_y; |
| 1194 float to_y; | 1173 float to_x; |
| 1195 }; | 1174 float to_y; |
| 1175 } skews[] = { | |
| 1176 {1.f, 0.5f, 0.5f, 1.f}, {2.f, 1.f, 0.5f, 0.5f}, | |
| 1177 }; | |
|
danakj
2014/10/16 20:08:02
this is super weird, mind filing a clang-format bu
jamesr
2014/10/16 20:43:09
I don't see the issue. The declaration here start
danakj
2014/10/16 20:50:27
i expect the } to be at the level of indent of the
| |
| 1196 | 1178 |
| 1197 TEST(TransformOperationTest, BlendedBoundsForSkew) { | 1179 struct { |
| 1198 TestSkews skews[] = { | 1180 float min_progress; |
| 1199 { 1.f, 0.5f, 0.5f, 1.f }, | 1181 float max_progress; |
| 1200 { 2.f, 1.f, 0.5f, 0.5f }, | 1182 } progress[] = { |
| 1201 }; | 1183 {0.f, 1.f}, {-0.1f, 1.1f}, |
| 1202 | 1184 }; |
| 1203 TestProgress progress[] = { | |
| 1204 { 0.f, 1.f }, | |
| 1205 { -0.1f, 1.1f }, | |
| 1206 }; | |
| 1207 | 1185 |
| 1208 for (size_t i = 0; i < arraysize(skews); ++i) { | 1186 for (size_t i = 0; i < arraysize(skews); ++i) { |
| 1209 for (size_t j = 0; j < arraysize(progress); ++j) { | 1187 for (size_t j = 0; j < arraysize(progress); ++j) { |
| 1210 TransformOperations operations_from; | 1188 TransformOperations operations_from; |
| 1211 operations_from.AppendSkew(skews[i].from_x, skews[i].from_y); | 1189 operations_from.AppendSkew(skews[i].from_x, skews[i].from_y); |
| 1212 TransformOperations operations_to; | 1190 TransformOperations operations_to; |
| 1213 operations_to.AppendSkew(skews[i].to_x, skews[i].to_y); | 1191 operations_to.AppendSkew(skews[i].to_x, skews[i].to_y); |
| 1214 EmpiricallyTestBoundsEquality(operations_from, | 1192 EmpiricallyTestBoundsEquality(operations_from, |
| 1215 operations_to, | 1193 operations_to, |
| 1216 progress[j].min_progress, | 1194 progress[j].min_progress, |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1476 | 1454 |
| 1477 // Scale + Perspective can't. | 1455 // Scale + Perspective can't. |
| 1478 TransformOperations operations11; | 1456 TransformOperations operations11; |
| 1479 operations11.AppendScale(2.f, 2.f, 2.f); | 1457 operations11.AppendScale(2.f, 2.f, 2.f); |
| 1480 operations11.AppendPerspective(1.f); | 1458 operations11.AppendPerspective(1.f); |
| 1481 EXPECT_FALSE(operations11.ScaleComponent(&scale)); | 1459 EXPECT_FALSE(operations11.ScaleComponent(&scale)); |
| 1482 } | 1460 } |
| 1483 | 1461 |
| 1484 } // namespace | 1462 } // namespace |
| 1485 } // namespace cc | 1463 } // namespace cc |
| OLD | NEW |