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

Side by Side Diff: cc/base/spiral_iterator_unittest.cc

Issue 2352393002: cc: Detach spiral iterator implementation to separate file. (Closed)
Patch Set: review comments Created 4 years, 3 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 | « cc/base/spiral_iterator.cc ('k') | cc/base/tiling_data.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stddef.h>
6
7 #include <algorithm>
8 #include <vector>
9
10 #include "cc/base/tiling_data.h"
11 #include "cc/test/geometry_test_utils.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace cc {
15 namespace {
16
17 void TestSpiralIterate(int source_line_number,
18 const TilingData& tiling_data,
19 const gfx::Rect& consider,
20 const gfx::Rect& ignore,
21 const gfx::Rect& center,
22 const std::vector<std::pair<int, int>>& expected) {
23 std::vector<std::pair<int, int>> actual_forward;
24 for (TilingData::SpiralDifferenceIterator it(&tiling_data, consider, ignore,
25 center);
26 it; ++it) {
27 actual_forward.push_back(it.index());
28 }
29
30 EXPECT_EQ(expected.size(), actual_forward.size()) << "error from line "
31 << source_line_number;
32 for (size_t i = 0; i < std::min(expected.size(), actual_forward.size());
33 ++i) {
34 EXPECT_EQ(expected[i].first, actual_forward[i].first)
35 << "i: " << i << " error from line: " << source_line_number;
36 EXPECT_EQ(expected[i].second, actual_forward[i].second)
37 << "i: " << i << " error from line: " << source_line_number;
38 }
39
40 std::vector<std::pair<int, int>> actual_reverse;
41 for (TilingData::ReverseSpiralDifferenceIterator it(&tiling_data, consider,
42 ignore, center);
43 it; ++it) {
44 actual_reverse.push_back(it.index());
45 }
46
47 std::vector<std::pair<int, int>> reversed_expected = expected;
48 std::reverse(reversed_expected.begin(), reversed_expected.end());
49 EXPECT_EQ(reversed_expected.size(), actual_reverse.size())
50 << "error from line " << source_line_number;
51 for (size_t i = 0;
52 i < std::min(reversed_expected.size(), actual_reverse.size()); ++i) {
53 EXPECT_EQ(reversed_expected[i].first, actual_reverse[i].first)
54 << "i: " << i << " error from line: " << source_line_number;
55 EXPECT_EQ(reversed_expected[i].second, actual_reverse[i].second)
56 << "i: " << i << " error from line: " << source_line_number;
57 }
58 }
59
60 TEST(SpiralIteratorTest, NoIgnoreFullConsider) {
prashant.n 2016/09/23 12:11:24 How about moving this test code under function Exe
prashant.n 2016/09/23 13:52:17 I thought over this again. I guess we may not need
vmpstr 2016/09/23 21:05:34 Yeah I think we can just write a separate perftest
61 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(30, 30), false);
62 gfx::Rect consider(30, 30);
63 gfx::Rect ignore;
64 std::vector<std::pair<int, int>> expected;
65
66 // Center is in the center of the tiling.
67 gfx::Rect center(15, 15, 1, 1);
68
69 // Layout of the tiling data, and expected return order:
70 // x 0 1 2
71 // y ┌───┬───┬───┐
72 // 0 │ 4│ 3│ 2│
73 // ├───┼───┼───┤
74 // 1 │ 5│ *│ 1│
75 // ├───┼───┼───┤
76 // 2 │ 6│ 7│ 8│
77 // └───┴───┴───┘
78 expected.push_back(std::make_pair(2, 1));
79 expected.push_back(std::make_pair(2, 0));
80 expected.push_back(std::make_pair(1, 0));
81 expected.push_back(std::make_pair(0, 0));
82 expected.push_back(std::make_pair(0, 1));
83 expected.push_back(std::make_pair(0, 2));
84 expected.push_back(std::make_pair(1, 2));
85 expected.push_back(std::make_pair(2, 2));
86
87 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
88
89 // Center is off to the right side of the tiling (and far away).
90 center = gfx::Rect(100, 15, 1, 1);
91
92 // Layout of the tiling data, and expected return order:
93 // x 0 1 2
94 // y ┌───┬───┬───┐
95 // 0 │ 7│ 4│ 1│
96 // ├───┼───┼───┤
97 // 1 │ 8│ 5│ 2│ *
98 // ├───┼───┼───┤
99 // 2 │ 9│ 6│ 3│
100 // └───┴───┴───┘
101 expected.clear();
102 expected.push_back(std::make_pair(2, 0));
103 expected.push_back(std::make_pair(2, 1));
104 expected.push_back(std::make_pair(2, 2));
105 expected.push_back(std::make_pair(1, 0));
106 expected.push_back(std::make_pair(1, 1));
107 expected.push_back(std::make_pair(1, 2));
108 expected.push_back(std::make_pair(0, 0));
109 expected.push_back(std::make_pair(0, 1));
110 expected.push_back(std::make_pair(0, 2));
111
112 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
113
114 // Center is the bottom right corner of the tiling.
115 center = gfx::Rect(25, 25, 1, 1);
116
117 // Layout of the tiling data, and expected return order:
118 // x 0 1 2
119 // y ┌───┬───┬───┐
120 // 0 │ 6│ 5│ 4│
121 // ├───┼───┼───┤
122 // 1 │ 7│ 2│ 1│
123 // ├───┼───┼───┤
124 // 2 │ 8│ 3│ *│
125 // └───┴───┴───┘
126 expected.clear();
127 expected.push_back(std::make_pair(2, 1));
128 expected.push_back(std::make_pair(1, 1));
129 expected.push_back(std::make_pair(1, 2));
130 expected.push_back(std::make_pair(2, 0));
131 expected.push_back(std::make_pair(1, 0));
132 expected.push_back(std::make_pair(0, 0));
133 expected.push_back(std::make_pair(0, 1));
134 expected.push_back(std::make_pair(0, 2));
135
136 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
137
138 // Center is off the top left side of the tiling.
139 center = gfx::Rect(-60, -50, 1, 1);
140
141 // Layout of the tiling data, and expected return order:
142 // * x 0 1 2
143 // y ┌───┬───┬───┐
144 // 0 │ 1│ 2│ 6│
145 // ├───┼───┼───┤
146 // 1 │ 3│ 4│ 5│
147 // ├───┼───┼───┤
148 // 2 │ 7│ 8│ 9│
149 // └───┴───┴───┘
150 expected.clear();
151 expected.push_back(std::make_pair(0, 0));
152 expected.push_back(std::make_pair(1, 0));
153 expected.push_back(std::make_pair(0, 1));
154 expected.push_back(std::make_pair(1, 1));
155 expected.push_back(std::make_pair(2, 1));
156 expected.push_back(std::make_pair(2, 0));
157 expected.push_back(std::make_pair(0, 2));
158 expected.push_back(std::make_pair(1, 2));
159 expected.push_back(std::make_pair(2, 2));
160
161 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
162
163 // Two tile center.
164 center = gfx::Rect(15, 15, 1, 10);
165
166 // Layout of the tiling data, and expected return order:
167 // x 0 1 2
168 // y ┌───┬───┬───┐
169 // 0 │ 5│ 4│ 3│
170 // ├───┼───┼───┤
171 // 1 │ 6│ *│ 2│
172 // ├───┼───┼───┤
173 // 2 │ 7│ *│ 1│
174 // └───┴───┴───┘
175 expected.clear();
176 expected.push_back(std::make_pair(2, 2));
177 expected.push_back(std::make_pair(2, 1));
178 expected.push_back(std::make_pair(2, 0));
179 expected.push_back(std::make_pair(1, 0));
180 expected.push_back(std::make_pair(0, 0));
181 expected.push_back(std::make_pair(0, 1));
182 expected.push_back(std::make_pair(0, 2));
183
184 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
185 }
186
187 TEST(SpiralIteratorTest, SmallConsider) {
188 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(50, 50), false);
189 gfx::Rect ignore;
190 std::vector<std::pair<int, int>> expected;
191 gfx::Rect center(15, 15, 1, 1);
192
193 // Consider is one cell.
194 gfx::Rect consider(1, 1);
195
196 // Layout of the tiling data, and expected return order:
197 // x 0 1 2 3 4
198 // y ┌───┬───┬───┬───┬───┐
199 // 0 │ 1│ │ │ │ │
200 // ├───┼───┼───┼───┼───┤
201 // 1 │ │ *│ │ │ │
202 // ├───┼───┼───┼───┼───┤
203 // 2 │ │ │ │ │ │
204 // ├───┼───┼───┼───┼───┤
205 // 3 │ │ │ │ │ │
206 // ├───┼───┼───┼───┼───┤
207 // 4 │ │ │ │ │ │
208 // └───┴───┴───┴───┴───┘
209 expected.push_back(std::make_pair(0, 0));
210
211 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
212
213 // Consider is bottom right corner.
214 consider = gfx::Rect(25, 25, 10, 10);
215
216 // Layout of the tiling data, and expected return order:
217 // x 0 1 2 3 4
218 // y ┌───┬───┬───┬───┬───┐
219 // 0 │ │ │ │ │ │
220 // ├───┼───┼───┼───┼───┤
221 // 1 │ │ *│ │ │ │
222 // ├───┼───┼───┼───┼───┤
223 // 2 │ │ │ 1│ 2│ │
224 // ├───┼───┼───┼───┼───┤
225 // 3 │ │ │ 3│ 4│ │
226 // ├───┼───┼───┼───┼───┤
227 // 4 │ │ │ │ │ │
228 // └───┴───┴───┴───┴───┘
229 expected.clear();
230 expected.push_back(std::make_pair(2, 2));
231 expected.push_back(std::make_pair(3, 2));
232 expected.push_back(std::make_pair(2, 3));
233 expected.push_back(std::make_pair(3, 3));
234
235 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
236
237 // Consider is one column.
238 consider = gfx::Rect(11, 0, 1, 100);
239
240 // Layout of the tiling data, and expected return order:
241 // x 0 1 2 3 4
242 // y ┌───┬───┬───┬───┬───┐
243 // 0 │ │ 2│ │ │ │
244 // ├───┼───┼───┼───┼───┤
245 // 1 │ │ *│ │ │ │
246 // ├───┼───┼───┼───┼───┤
247 // 2 │ │ 3│ │ │ │
248 // ├───┼───┼───┼───┼───┤
249 // 3 │ │ 4│ │ │ │
250 // ├───┼───┼───┼───┼───┤
251 // 4 │ │ 5│ │ │ │
252 // └───┴───┴───┴───┴───┘
253 expected.clear();
254 expected.push_back(std::make_pair(1, 0));
255 expected.push_back(std::make_pair(1, 2));
256 expected.push_back(std::make_pair(1, 3));
257 expected.push_back(std::make_pair(1, 4));
258
259 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
260 }
261
262 TEST(SpiralIteratorTest, HasIgnore) {
263 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(50, 50), false);
264 gfx::Rect consider(50, 50);
265 std::vector<std::pair<int, int>> expected;
266 gfx::Rect center(15, 15, 1, 1);
267
268 // Full ignore.
269 gfx::Rect ignore(50, 50);
270
271 // Layout of the tiling data, and expected return order:
272 // x 0 1 2 3 4
273 // y ┌───┬───┬───┬───┬───┐
274 // 0 │ I│ I│ I│ I│ I│
275 // ├───┼───┼───┼───┼───┤
276 // 1 │ I│ *│ I│ I│ I│
277 // ├───┼───┼───┼───┼───┤
278 // 2 │ I│ I│ I│ I│ I│
279 // ├───┼───┼───┼───┼───┤
280 // 3 │ I│ I│ I│ I│ I│
281 // ├───┼───┼───┼───┼───┤
282 // 4 │ I│ I│ I│ I│ I│
283 // └───┴───┴───┴───┴───┘
284 expected.clear();
285
286 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
287
288 // 3 column ignore.
289 ignore = gfx::Rect(15, 0, 20, 100);
290
291 // Layout of the tiling data, and expected return order:
292 // x 0 1 2 3 4
293 // y ┌───┬───┬───┬───┬───┐
294 // 0 │ 1│ I│ I│ I│ 8│
295 // ├───┼───┼───┼───┼───┤
296 // 1 │ 2│ *│ I│ I│ 7│
297 // ├───┼───┼───┼───┼───┤
298 // 2 │ 3│ I│ I│ I│ 6│
299 // ├───┼───┼───┼───┼───┤
300 // 3 │ 4│ I│ I│ I│ 5│
301 // ├───┼───┼───┼───┼───┤
302 // 4 │ 9│ I│ I│ I│ 10│
303 // └───┴───┴───┴───┴───┘
304 expected.clear();
305 expected.push_back(std::make_pair(0, 0));
306 expected.push_back(std::make_pair(0, 1));
307 expected.push_back(std::make_pair(0, 2));
308 expected.push_back(std::make_pair(0, 3));
309 expected.push_back(std::make_pair(4, 3));
310 expected.push_back(std::make_pair(4, 2));
311 expected.push_back(std::make_pair(4, 1));
312 expected.push_back(std::make_pair(4, 0));
313 expected.push_back(std::make_pair(0, 4));
314 expected.push_back(std::make_pair(4, 4));
315
316 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
317
318 // Ignore covers the top half.
319 ignore = gfx::Rect(50, 25);
320
321 // Layout of the tiling data, and expected return order:
322 // x 0 1 2 3 4
323 // y ┌───┬───┬───┬───┬───┐
324 // 0 │ I│ I│ I│ I│ I│
325 // ├───┼───┼───┼───┼───┤
326 // 1 │ I│ *│ I│ I│ I│
327 // ├───┼───┼───┼───┼───┤
328 // 2 │ I│ I│ I│ I│ I│
329 // ├───┼───┼───┼───┼───┤
330 // 3 │ 1│ 2│ 3│ 4│ 5│
331 // ├───┼───┼───┼───┼───┤
332 // 4 │ 6│ 7│ 8│ 9│ 10│
333 // └───┴───┴───┴───┴───┘
334 expected.clear();
335 expected.push_back(std::make_pair(0, 3));
336 expected.push_back(std::make_pair(1, 3));
337 expected.push_back(std::make_pair(2, 3));
338 expected.push_back(std::make_pair(3, 3));
339 expected.push_back(std::make_pair(4, 3));
340 expected.push_back(std::make_pair(0, 4));
341 expected.push_back(std::make_pair(1, 4));
342 expected.push_back(std::make_pair(2, 4));
343 expected.push_back(std::make_pair(3, 4));
344 expected.push_back(std::make_pair(4, 4));
345
346 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
347 }
348
349 TEST(SpiralIteratorTest, RectangleCenter) {
350 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(50, 50), false);
351 gfx::Rect consider(50, 50);
352 std::vector<std::pair<int, int>> expected;
353 gfx::Rect ignore;
354
355 // Two cell center
356 gfx::Rect center(25, 25, 1, 10);
357
358 // Layout of the tiling data, and expected return order:
359 // x 0 1 2 3 4
360 // y ┌───┬───┬───┬───┬───┐
361 // 0 │ 19│ 18│ 17│ 16│ 15│
362 // ├───┼───┼───┼───┼───┤
363 // 1 │ 20│ 5│ 4│ 3│ 14│
364 // ├───┼───┼───┼───┼───┤
365 // 2 │ 21│ 6│ *│ 2│ 13│
366 // ├───┼───┼───┼───┼───┤
367 // 3 │ 22│ 7│ *│ 1│ 12│
368 // ├───┼───┼───┼───┼───┤
369 // 4 │ 23│ 8│ 9│ 10│ 11│
370 // └───┴───┴───┴───┴───┘
371 expected.clear();
372 expected.push_back(std::make_pair(3, 3));
373 expected.push_back(std::make_pair(3, 2));
374 expected.push_back(std::make_pair(3, 1));
375 expected.push_back(std::make_pair(2, 1));
376 expected.push_back(std::make_pair(1, 1));
377 expected.push_back(std::make_pair(1, 2));
378 expected.push_back(std::make_pair(1, 3));
379 expected.push_back(std::make_pair(1, 4));
380 expected.push_back(std::make_pair(2, 4));
381 expected.push_back(std::make_pair(3, 4));
382 expected.push_back(std::make_pair(4, 4));
383 expected.push_back(std::make_pair(4, 3));
384 expected.push_back(std::make_pair(4, 2));
385 expected.push_back(std::make_pair(4, 1));
386 expected.push_back(std::make_pair(4, 0));
387 expected.push_back(std::make_pair(3, 0));
388 expected.push_back(std::make_pair(2, 0));
389 expected.push_back(std::make_pair(1, 0));
390 expected.push_back(std::make_pair(0, 0));
391 expected.push_back(std::make_pair(0, 1));
392 expected.push_back(std::make_pair(0, 2));
393 expected.push_back(std::make_pair(0, 3));
394 expected.push_back(std::make_pair(0, 4));
395
396 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
397
398 // Three by two center.
399 center = gfx::Rect(15, 25, 20, 10);
400
401 // Layout of the tiling data, and expected return order:
402 // x 0 1 2 3 4
403 // y ┌───┬───┬───┬───┬───┐
404 // 0 │ 19│ 18│ 17│ 16│ 15│
405 // ├───┼───┼───┼───┼───┤
406 // 1 │ 7│ 6│ 5│ 4│ 3│
407 // ├───┼───┼───┼───┼───┤
408 // 2 │ 8│ *│ *│ *│ 2│
409 // ├───┼───┼───┼───┼───┤
410 // 3 │ 9│ *│ *│ *│ 1│
411 // ├───┼───┼───┼───┼───┤
412 // 4 │ 10│ 11│ 12│ 13│ 14│
413 // └───┴───┴───┴───┴───┘
414 expected.clear();
415 expected.push_back(std::make_pair(4, 3));
416 expected.push_back(std::make_pair(4, 2));
417 expected.push_back(std::make_pair(4, 1));
418 expected.push_back(std::make_pair(3, 1));
419 expected.push_back(std::make_pair(2, 1));
420 expected.push_back(std::make_pair(1, 1));
421 expected.push_back(std::make_pair(0, 1));
422 expected.push_back(std::make_pair(0, 2));
423 expected.push_back(std::make_pair(0, 3));
424 expected.push_back(std::make_pair(0, 4));
425 expected.push_back(std::make_pair(1, 4));
426 expected.push_back(std::make_pair(2, 4));
427 expected.push_back(std::make_pair(3, 4));
428 expected.push_back(std::make_pair(4, 4));
429 expected.push_back(std::make_pair(4, 0));
430 expected.push_back(std::make_pair(3, 0));
431 expected.push_back(std::make_pair(2, 0));
432 expected.push_back(std::make_pair(1, 0));
433 expected.push_back(std::make_pair(0, 0));
434
435 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
436
437 // Column center off the left side.
438 center = gfx::Rect(-50, 0, 30, 50);
439
440 // Layout of the tiling data, and expected return order:
441 // x 0 1 2 3 4
442 // y ┌───┬───┬───┬───┬───┐
443 // * 0 │ 5│ 10│ 15│ 20│ 25│
444 // ├───┼───┼───┼───┼───┤
445 // * 1 │ 4│ 9│ 14│ 19│ 24│
446 // ├───┼───┼───┼───┼───┤
447 // * 2 │ 3│ 8│ 13│ 18│ 23│
448 // ├───┼───┼───┼───┼───┤
449 // * 3 │ 2│ 7│ 12│ 17│ 22│
450 // ├───┼───┼───┼───┼───┤
451 // * 4 │ 1│ 6│ 11│ 16│ 21│
452 // └───┴───┴───┴───┴───┘
453 expected.clear();
454 expected.push_back(std::make_pair(0, 4));
455 expected.push_back(std::make_pair(0, 3));
456 expected.push_back(std::make_pair(0, 2));
457 expected.push_back(std::make_pair(0, 1));
458 expected.push_back(std::make_pair(0, 0));
459 expected.push_back(std::make_pair(1, 4));
460 expected.push_back(std::make_pair(1, 3));
461 expected.push_back(std::make_pair(1, 2));
462 expected.push_back(std::make_pair(1, 1));
463 expected.push_back(std::make_pair(1, 0));
464 expected.push_back(std::make_pair(2, 4));
465 expected.push_back(std::make_pair(2, 3));
466 expected.push_back(std::make_pair(2, 2));
467 expected.push_back(std::make_pair(2, 1));
468 expected.push_back(std::make_pair(2, 0));
469 expected.push_back(std::make_pair(3, 4));
470 expected.push_back(std::make_pair(3, 3));
471 expected.push_back(std::make_pair(3, 2));
472 expected.push_back(std::make_pair(3, 1));
473 expected.push_back(std::make_pair(3, 0));
474 expected.push_back(std::make_pair(4, 4));
475 expected.push_back(std::make_pair(4, 3));
476 expected.push_back(std::make_pair(4, 2));
477 expected.push_back(std::make_pair(4, 1));
478 expected.push_back(std::make_pair(4, 0));
479
480 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
481 }
482
483 TEST(SpiralIteratorTest, EdgeCases) {
484 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(30, 30), false);
485 std::vector<std::pair<int, int>> expected;
486 gfx::Rect center;
487 gfx::Rect consider;
488 gfx::Rect ignore;
489
490 // Ignore contains, but is not equal to, consider and center.
491 ignore = gfx::Rect(15, 0, 20, 30);
492 consider = gfx::Rect(20, 10, 10, 20);
493 center = gfx::Rect(25, 0, 5, 5);
494
495 // Layout of the tiling data, and expected return order:
496 // x 0 1 2
497 // y ┌───┬───┬───┐
498 // 0 │ │ I│ *│
499 // ├───┼───┼───┤
500 // 1 │ │ I│ I│
501 // ├───┼───┼───┤
502 // 2 │ │ I│ I│
503 // └───┴───┴───┘
504 expected.clear();
505
506 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
507
508 // Center intersects with consider.
509 ignore = gfx::Rect();
510 center = gfx::Rect(0, 15, 30, 15);
511 consider = gfx::Rect(15, 30);
512
513 // Layout of the tiling data, and expected return order:
514 // x 0 1 2
515 // y ┌───┬───┬───┐
516 // 0 │ 2│ 1│ │
517 // ├───┼───┼───┤
518 // 1 │ *│ *│ *│
519 // ├───┼───┼───┤
520 // 2 │ *│ *│ *│
521 // └───┴───┴───┘
522 expected.clear();
523 expected.push_back(std::make_pair(1, 0));
524 expected.push_back(std::make_pair(0, 0));
525
526 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
527
528 // Consider and ignore are non-intersecting.
529 ignore = gfx::Rect(5, 30);
530 consider = gfx::Rect(25, 0, 5, 30);
531 center = gfx::Rect(15, 0, 1, 1);
532
533 // Layout of the tiling data, and expected return order:
534 // x 0 1 2
535 // y ┌───┬───┬───┐
536 // 0 │ I│ *│ 1│
537 // ├───┼───┼───┤
538 // 1 │ I│ │ 2│
539 // ├───┼───┼───┤
540 // 2 │ I│ │ 3│
541 // └───┴───┴───┘
542 expected.clear();
543 expected.push_back(std::make_pair(2, 0));
544 expected.push_back(std::make_pair(2, 1));
545 expected.push_back(std::make_pair(2, 2));
546
547 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
548
549 // Center intersects with ignore.
550 consider = gfx::Rect(30, 30);
551 center = gfx::Rect(15, 0, 1, 30);
552 ignore = gfx::Rect(0, 15, 30, 1);
553
554 // Layout of the tiling data, and expected return order:
555 // x 0 1 2
556 // y ┌───┬───┬───┐
557 // 0 │ 3│ *│ 2│
558 // ├───┼───┼───┤
559 // 1 │ I│ *│ I│
560 // ├───┼───┼───┤
561 // 2 │ 4│ *│ 1│
562 // └───┴───┴───┘
563 expected.clear();
564 expected.push_back(std::make_pair(2, 2));
565 expected.push_back(std::make_pair(2, 0));
566 expected.push_back(std::make_pair(0, 0));
567 expected.push_back(std::make_pair(0, 2));
568
569 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
570
571 // Center and ignore are the same.
572 consider = gfx::Rect(30, 30);
573 center = gfx::Rect(15, 0, 1, 30);
574 ignore = center;
575
576 // Layout of the tiling data, and expected return order:
577 // x 0 1 2
578 // y ┌───┬───┬───┐
579 // 0 │ 4│ *│ 3│
580 // ├───┼───┼───┤
581 // 1 │ 5│ *│ 2│
582 // ├───┼───┼───┤
583 // 2 │ 6│ *│ 1│
584 // └───┴───┴───┘
585 expected.clear();
586 expected.push_back(std::make_pair(2, 2));
587 expected.push_back(std::make_pair(2, 1));
588 expected.push_back(std::make_pair(2, 0));
589 expected.push_back(std::make_pair(0, 0));
590 expected.push_back(std::make_pair(0, 1));
591 expected.push_back(std::make_pair(0, 2));
592
593 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
594
595 // Empty tiling data.
596 TilingData empty_data(gfx::Size(0, 0), gfx::Size(0, 0), false);
597
598 expected.clear();
599
600 TestSpiralIterate(__LINE__, empty_data, consider, ignore, center, expected);
601
602 // Empty consider.
603 ignore = gfx::Rect();
604 center = gfx::Rect(1, 1, 1, 1);
605 consider = gfx::Rect();
606
607 expected.clear();
608
609 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
610
611 // Empty center. Note: This arbitrarily puts the center to be off the top-left
612 // corner.
613 consider = gfx::Rect(30, 30);
614 ignore = gfx::Rect();
615 center = gfx::Rect();
616
617 // Layout of the tiling data, and expected return order:
618 // x 0 1 2
619 // y ┌───┬───┬───┐
620 // 0 │ 1│ 2│ 6│
621 // ├───┼───┼───┤
622 // 1 │ 3│ 4│ 5│
623 // ├───┼───┼───┤
624 // 2 │ 7│ 8│ 9│
625 // └───┴───┴───┘
626 expected.clear();
627 expected.push_back(std::make_pair(0, 0));
628 expected.push_back(std::make_pair(1, 0));
629 expected.push_back(std::make_pair(0, 1));
630 expected.push_back(std::make_pair(1, 1));
631 expected.push_back(std::make_pair(2, 1));
632 expected.push_back(std::make_pair(2, 0));
633 expected.push_back(std::make_pair(0, 2));
634 expected.push_back(std::make_pair(1, 2));
635 expected.push_back(std::make_pair(2, 2));
636
637 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
638
639 // Every rect is empty.
640 ignore = gfx::Rect();
641 center = gfx::Rect();
642 consider = gfx::Rect();
643
644 expected.clear();
645
646 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
647
648 // Center is just to the left of cover, and off of the tiling's left side.
649 consider = gfx::Rect(30, 30);
650 ignore = gfx::Rect();
651 center = gfx::Rect(-20, 0, 19, 30);
652
653 // Layout of the tiling data, and expected return order:
654 // x 0 1 2
655 // y ┌───┬───┬───┐
656 // * 0 │ 3│ 6│ 9│
657 // ├───┼───┼───┤
658 // * 1 │ 2│ 5│ 8│
659 // ├───┼───┼───┤
660 // * 2 │ 1│ 4│ 7│
661 // └───┴───┴───┘
662 expected.clear();
663 expected.push_back(std::make_pair(0, 2));
664 expected.push_back(std::make_pair(0, 1));
665 expected.push_back(std::make_pair(0, 0));
666 expected.push_back(std::make_pair(1, 2));
667 expected.push_back(std::make_pair(1, 1));
668 expected.push_back(std::make_pair(1, 0));
669 expected.push_back(std::make_pair(2, 2));
670 expected.push_back(std::make_pair(2, 1));
671 expected.push_back(std::make_pair(2, 0));
672
673 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
674 }
675
676 } // namespace
677
678 } // namespace cc
OLDNEW
« no previous file with comments | « cc/base/spiral_iterator.cc ('k') | cc/base/tiling_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698