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

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

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

Powered by Google App Engine
This is Rietveld 408576698