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

Side by Side Diff: cc/quads/draw_polygon_unittest.cc

Issue 1860823003: Enhance unit tests for normals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 8 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // We would like to use M_PI on windows too. 5 // We would like to use M_PI on windows too.
6 #ifdef _WIN32 6 #ifdef _WIN32
7 #define _USE_MATH_DEFINES 7 #define _USE_MATH_DEFINES
8 #endif 8 #endif
9 9
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 std::vector<gfx::Point3F> vertices; 67 std::vector<gfx::Point3F> vertices;
68 vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); 68 vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
69 vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); 69 vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
70 vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); 70 vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
71 vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f)); 71 vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
72 72
73 CREATE_TEST_DRAW_POLYGON(polygon, vertices, 1); 73 CREATE_TEST_DRAW_POLYGON(polygon, vertices, 1);
74 EXPECT_NORMAL(polygon, 0.0f, 0.0f, 1.0f); 74 EXPECT_NORMAL(polygon, 0.0f, 0.0f, 1.0f);
75 } 75 }
76 76
77 TEST(DrawPolygonConstructionTest, InverseNormal) {
78 std::vector<gfx::Point3F> vertices;
79 vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
80 vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
81 vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
82 vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
83
84 CREATE_TEST_DRAW_POLYGON(polygon, vertices, 1);
85 EXPECT_NORMAL(polygon, 0.0f, 0.0f, -1.0f);
86 }
87
88 TEST(DrawPolygonConstructionTest, ClippedNormal) { 77 TEST(DrawPolygonConstructionTest, ClippedNormal) {
89 std::vector<gfx::Point3F> vertices; 78 std::vector<gfx::Point3F> vertices;
90 vertices.push_back(gfx::Point3F(0.1f, 10.0f, 0.0f)); 79 vertices.push_back(gfx::Point3F(0.1f, 10.0f, 0.0f));
91 vertices.push_back(gfx::Point3F(0.0f, 9.9f, 0.0f)); 80 vertices.push_back(gfx::Point3F(0.0f, 9.9f, 0.0f));
92 vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); 81 vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
93 vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); 82 vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
94 vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); 83 vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
95 vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f)); 84 vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
96 85
97 CREATE_TEST_DRAW_POLYGON(polygon, vertices, 1); 86 CREATE_TEST_DRAW_POLYGON(polygon, vertices, 1);
(...skipping 20 matching lines...) Expand all
118 sin(i * M_PI / 50) + 99.0f, 100.0f)); 107 sin(i * M_PI / 50) + 99.0f, 100.0f));
119 } 108 }
120 CREATE_TEST_DRAW_POLYGON(polygon_c, vertices_c, 3); 109 CREATE_TEST_DRAW_POLYGON(polygon_c, vertices_c, 3);
121 EXPECT_NORMAL(polygon_c, 0.0f, 0.0f, 1.0f); 110 EXPECT_NORMAL(polygon_c, 0.0f, 0.0f, 1.0f);
122 111
123 CREATE_TEST_DRAW_POLYGON(polygon_d, vertices_d, 4); 112 CREATE_TEST_DRAW_POLYGON(polygon_d, vertices_d, 4);
124 EXPECT_NORMAL(polygon_c, 0.0f, 0.0f, 1.0f); 113 EXPECT_NORMAL(polygon_c, 0.0f, 0.0f, 1.0f);
125 } 114 }
126 115
127 // A simple rect being transformed. 116 // A simple rect being transformed.
128 TEST(DrawPolygonConstructionTest, DizzyNormal) { 117 TEST(DrawPolygonConstructionTest, SimpleNormal) {
129 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f); 118 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
130 119
131 gfx::Transform transform_i(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 120 gfx::Transform transform_i(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
132 DrawPolygon polygon_i(NULL, src, transform_i, 1); 121 DrawPolygon polygon_i(NULL, src, transform_i, 1);
133 122
134 EXPECT_NORMAL(polygon_i, 0.0f, 0.0f, 1.0f); 123 EXPECT_NORMAL(polygon_i, 0.0f, 0.0f, 1.0f);
124 }
135 125
136 gfx::Transform tranform_a(0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 126 TEST(DrawPolygonConstructionTest, DISABLED_NormalInvertXY) {
137 DrawPolygon polygon_a(NULL, src, tranform_a, 2); 127 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
138 EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, -1.0f);
139 128
140 gfx::Transform tranform_b(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1); 129 gfx::Transform transform(0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
141 DrawPolygon polygon_b(NULL, src, tranform_b, 3); 130 DrawPolygon polygon_a(NULL, src, transform, 2);
142 EXPECT_NORMAL(polygon_b, -1.0f, 0.0f, 0.0f);
143 131
144 gfx::Transform tranform_c(1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1); 132 EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, 1.0f);
145 DrawPolygon polygon_c(NULL, src, tranform_c, 4); 133 }
146 EXPECT_NORMAL(polygon_c, 0.0f, -1.0f, 0.0f);
147 134
148 gfx::Transform tranform_d(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 135 TEST(DrawPolygonConstructionTest, DISABLED_NormalInvertXZ) {
149 DrawPolygon polygon_d(NULL, src, tranform_d, 5); 136 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
137
138 gfx::Transform transform(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1);
139 DrawPolygon polygon_b(NULL, src, transform, 3);
140
141 EXPECT_NORMAL(polygon_b, 1.0f, 0.0f, 0.0f);
142 }
143
144 TEST(DrawPolygonConstructionTest, DISABLED_NormalInvertYZ) {
145 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
146
147 gfx::Transform transform(1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1);
148 DrawPolygon polygon_c(NULL, src, transform, 4);
149
150 EXPECT_NORMAL(polygon_c, 0.0f, 1.0f, 0.0f);
151 }
152
153 TEST(DrawPolygonConstructionTest, NormalRotate90) {
154 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
155
156 gfx::Transform transform(0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1);
157 DrawPolygon polygon_b(NULL, src, transform, 3);
158
159 EXPECT_NORMAL(polygon_b, 0.0f, 0.0f, 1.0f);
160 }
161
162 TEST(DrawPolygonConstructionTest, DISABLED_InvertXNormal) {
163 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
164
165 gfx::Transform transform(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
166 DrawPolygon polygon_d(NULL, src, transform, 5);
167
168 EXPECT_NORMAL(polygon_d, 0.0f, 0.0f, 1.0f);
169 }
170
171 TEST(DrawPolygonConstructionTest, DISABLED_InvertYNormal) {
172 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
173
174 gfx::Transform transform(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
175 DrawPolygon polygon_d(NULL, src, transform, 5);
176
177 EXPECT_NORMAL(polygon_d, 0.0f, 0.0f, 1.0f);
178 }
179
180 TEST(DrawPolygonConstructionTest, DISABLED_InvertZNormal) {
181 gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
182
183 gfx::Transform transform(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1);
184 DrawPolygon polygon_d(NULL, src, transform, 5);
185
150 EXPECT_NORMAL(polygon_d, 0.0f, 0.0f, -1.0f); 186 EXPECT_NORMAL(polygon_d, 0.0f, 0.0f, -1.0f);
151 } 187 }
152 188
153 // Two quads are nearly touching but definitely ordered. Second one should 189 // Two quads are nearly touching but definitely ordered. Second one should
154 // compare in front. 190 // compare in front.
155 TEST(DrawPolygonSplitTest, NearlyTouchingOrder) { 191 TEST(DrawPolygonSplitTest, NearlyTouchingOrder) {
156 std::vector<gfx::Point3F> vertices_a; 192 std::vector<gfx::Point3F> vertices_a;
157 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); 193 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
158 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); 194 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
159 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); 195 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // Two quads are definitely not touching and so no split should occur. 236 // Two quads are definitely not touching and so no split should occur.
201 TEST(DrawPolygonSplitTest, NotTouchingNoSplit) { 237 TEST(DrawPolygonSplitTest, NotTouchingNoSplit) {
202 std::vector<gfx::Point3F> vertices_a; 238 std::vector<gfx::Point3F> vertices_a;
203 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); 239 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
204 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); 240 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
205 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); 241 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
206 vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f)); 242 vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
207 std::vector<gfx::Point3F> vertices_b; 243 std::vector<gfx::Point3F> vertices_b;
208 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 5.0f)); 244 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 5.0f));
209 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 15.0f)); 245 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 15.0f));
210 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 15.0f)); 246 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 15.0f));
Peter Mayo 2016/04/06 21:01:09 This is a degenerate polygon (line) as written.
211 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 5.0f)); 247 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 5.0f));
212 248
213 CREATE_NEW_DRAW_POLYGON( 249 CREATE_NEW_DRAW_POLYGON(
214 polygon_a, vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0); 250 polygon_a, vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0);
215 CREATE_NEW_DRAW_POLYGON( 251 CREATE_NEW_DRAW_POLYGON(
216 polygon_b, vertices_b, gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1); 252 polygon_b, vertices_b, gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1);
217 253
218 EXPECT_EQ(BSP_FRONT, DrawPolygon::SideCompare(polygon_b, polygon_a)); 254 EXPECT_EQ(BSP_FRONT, DrawPolygon::SideCompare(polygon_b, polygon_a));
219 } 255 }
220 256
221 // One quad is resting against another, but doesn't cross its plane so no split 257 // One quad is resting against another, but doesn't cross its plane so no split
222 // should occur. 258 // should occur.
223 TEST(DrawPolygonSplitTest, BarelyTouchingNoSplit) { 259 TEST(DrawPolygonSplitTest, BarelyTouchingNoSplit) {
224 std::vector<gfx::Point3F> vertices_a; 260 std::vector<gfx::Point3F> vertices_a;
225 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); 261 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
226 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); 262 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
227 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); 263 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
228 vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f)); 264 vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
229 std::vector<gfx::Point3F> vertices_b; 265 std::vector<gfx::Point3F> vertices_b;
230 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 0.0f)); 266 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 0.0f));
231 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, -10.0f)); 267 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, -10.0f));
232 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, -10.0f)); 268 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, -10.0f));
Peter Mayo 2016/04/06 21:01:09 This is a degenerate polygon (line) as written.
233 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 0.0f)); 269 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 0.0f));
234 270
235 CREATE_NEW_DRAW_POLYGON( 271 CREATE_NEW_DRAW_POLYGON(
236 polygon_a, vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0); 272 polygon_a, vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0);
237 CREATE_NEW_DRAW_POLYGON( 273 CREATE_NEW_DRAW_POLYGON(
238 polygon_b, vertices_b, gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1); 274 polygon_b, vertices_b, gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1);
239 275
240 EXPECT_EQ(BSP_BACK, DrawPolygon::SideCompare(polygon_b, polygon_a)); 276 EXPECT_EQ(BSP_BACK, DrawPolygon::SideCompare(polygon_b, polygon_a));
241 } 277 }
242 278
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 387
352 // Note: We use EXPECT_FLOAT_WITHIN_EPSILON instead of EXPECT_FLOAT_EQUAL here 388 // Note: We use EXPECT_FLOAT_WITHIN_EPSILON instead of EXPECT_FLOAT_EQUAL here
353 // because some architectures (e.g., Arm64) employ a fused multiply-add 389 // because some architectures (e.g., Arm64) employ a fused multiply-add
354 // instruction which causes rounding asymmetry and reduces precision. 390 // instruction which causes rounding asymmetry and reduces precision.
355 // http://crbug.com/401117. 391 // http://crbug.com/401117.
356 EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, -1.0f); 392 EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, -1.0f);
357 } 393 }
358 394
359 } // namespace 395 } // namespace
360 } // namespace cc 396 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698