Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / base / tiling_data_unittest.cc
blob84d9e79dc722a000152863a5dbbf24771778bcef
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
3 // found in the LICENSE file.
5 #include "cc/base/tiling_data.h"
7 #include <algorithm>
8 #include <vector>
10 #include "cc/test/geometry_test_utils.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace cc {
14 namespace {
16 int NumTiles(const gfx::Size& max_texture_size,
17 const gfx::Rect& tiling_rect,
18 bool has_border_texels) {
19 TilingData tiling(max_texture_size, tiling_rect, has_border_texels);
20 int num_tiles = tiling.num_tiles_x() * tiling.num_tiles_y();
22 // Assert no overflow.
23 EXPECT_GE(num_tiles, 0);
24 if (num_tiles > 0)
25 EXPECT_EQ(num_tiles / tiling.num_tiles_x(), tiling.num_tiles_y());
27 return num_tiles;
30 int XIndex(const gfx::Size& max_texture_size,
31 const gfx::Rect& tiling_rect,
32 bool has_border_texels,
33 int x_coord) {
34 TilingData tiling(max_texture_size, tiling_rect, has_border_texels);
35 return tiling.TileXIndexFromSrcCoord(x_coord);
38 int YIndex(const gfx::Size& max_texture_size,
39 const gfx::Rect& tiling_rect,
40 bool has_border_texels,
41 int y_coord) {
42 TilingData tiling(max_texture_size, tiling_rect, has_border_texels);
43 return tiling.TileYIndexFromSrcCoord(y_coord);
46 int MinBorderXIndex(const gfx::Size& max_texture_size,
47 const gfx::Rect& tiling_rect,
48 bool has_border_texels,
49 int x_coord) {
50 TilingData tiling(max_texture_size, tiling_rect, has_border_texels);
51 return tiling.FirstBorderTileXIndexFromSrcCoord(x_coord);
54 int MinBorderYIndex(const gfx::Size& max_texture_size,
55 const gfx::Rect& tiling_rect,
56 bool has_border_texels,
57 int y_coord) {
58 TilingData tiling(max_texture_size, tiling_rect, has_border_texels);
59 return tiling.FirstBorderTileYIndexFromSrcCoord(y_coord);
62 int MaxBorderXIndex(const gfx::Size& max_texture_size,
63 const gfx::Rect& tiling_rect,
64 bool has_border_texels,
65 int x_coord) {
66 TilingData tiling(max_texture_size, tiling_rect, has_border_texels);
67 return tiling.LastBorderTileXIndexFromSrcCoord(x_coord);
70 int MaxBorderYIndex(const gfx::Size& max_texture_size,
71 const gfx::Rect& tiling_rect,
72 bool has_border_texels,
73 int y_coord) {
74 TilingData tiling(max_texture_size, tiling_rect, has_border_texels);
75 return tiling.LastBorderTileYIndexFromSrcCoord(y_coord);
78 int PosX(const gfx::Size& max_texture_size,
79 const gfx::Rect& tiling_rect,
80 bool has_border_texels,
81 int x_index) {
82 TilingData tiling(max_texture_size, tiling_rect, has_border_texels);
83 return tiling.TilePositionX(x_index);
86 int PosY(const gfx::Size& max_texture_size,
87 const gfx::Rect& tiling_rect,
88 bool has_border_texels,
89 int y_index) {
90 TilingData tiling(max_texture_size, tiling_rect, has_border_texels);
91 return tiling.TilePositionY(y_index);
94 int SizeX(const gfx::Size& max_texture_size,
95 const gfx::Rect& tiling_rect,
96 bool has_border_texels,
97 int x_index) {
98 TilingData tiling(max_texture_size, tiling_rect, has_border_texels);
99 return tiling.TileSizeX(x_index);
102 int SizeY(const gfx::Size& max_texture_size,
103 const gfx::Rect& tiling_rect,
104 bool has_border_texels,
105 int y_index) {
106 TilingData tiling(max_texture_size, tiling_rect, has_border_texels);
107 return tiling.TileSizeY(y_index);
110 class TilingDataTest : public ::testing::TestWithParam<gfx::Point> {};
112 TEST_P(TilingDataTest, NumTiles_NoTiling) {
113 gfx::Point origin = GetParam();
115 EXPECT_EQ(
117 NumTiles(gfx::Size(16, 16), gfx::Rect(origin, gfx::Size(16, 16)), false));
118 EXPECT_EQ(
120 NumTiles(gfx::Size(16, 16), gfx::Rect(origin, gfx::Size(15, 15)), true));
121 EXPECT_EQ(
123 NumTiles(gfx::Size(16, 16), gfx::Rect(origin, gfx::Size(16, 16)), true));
124 EXPECT_EQ(
126 NumTiles(gfx::Size(16, 16), gfx::Rect(origin, gfx::Size(1, 16)), false));
127 EXPECT_EQ(
129 NumTiles(gfx::Size(15, 15), gfx::Rect(origin, gfx::Size(15, 15)), true));
130 EXPECT_EQ(
132 NumTiles(gfx::Size(32, 16), gfx::Rect(origin, gfx::Size(32, 16)), false));
133 EXPECT_EQ(
135 NumTiles(gfx::Size(32, 16), gfx::Rect(origin, gfx::Size(32, 16)), true));
138 TEST_P(TilingDataTest, NumTiles_TilingNoBorders) {
139 gfx::Point origin = GetParam();
141 EXPECT_EQ(
142 0, NumTiles(gfx::Size(0, 0), gfx::Rect(origin, gfx::Size(0, 0)), false));
143 EXPECT_EQ(
144 0, NumTiles(gfx::Size(0, 0), gfx::Rect(origin, gfx::Size(4, 0)), false));
145 EXPECT_EQ(
146 0, NumTiles(gfx::Size(0, 0), gfx::Rect(origin, gfx::Size(0, 4)), false));
147 EXPECT_EQ(
148 0, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(4, 0)), false));
149 EXPECT_EQ(
150 0, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(0, 4)), false));
151 EXPECT_EQ(
152 0, NumTiles(gfx::Size(0, 0), gfx::Rect(origin, gfx::Size(1, 1)), false));
154 EXPECT_EQ(
155 1, NumTiles(gfx::Size(1, 1), gfx::Rect(origin, gfx::Size(1, 1)), false));
156 EXPECT_EQ(
157 2, NumTiles(gfx::Size(1, 1), gfx::Rect(origin, gfx::Size(1, 2)), false));
158 EXPECT_EQ(
159 2, NumTiles(gfx::Size(1, 1), gfx::Rect(origin, gfx::Size(2, 1)), false));
160 EXPECT_EQ(
161 1, NumTiles(gfx::Size(2, 2), gfx::Rect(origin, gfx::Size(1, 1)), false));
162 EXPECT_EQ(
163 1, NumTiles(gfx::Size(2, 2), gfx::Rect(origin, gfx::Size(1, 2)), false));
164 EXPECT_EQ(
165 1, NumTiles(gfx::Size(2, 2), gfx::Rect(origin, gfx::Size(2, 1)), false));
166 EXPECT_EQ(
167 1, NumTiles(gfx::Size(2, 2), gfx::Rect(origin, gfx::Size(2, 2)), false));
168 EXPECT_EQ(
169 1, NumTiles(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(3, 3)), false));
171 EXPECT_EQ(
172 1, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(1, 4)), false));
173 EXPECT_EQ(
174 1, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(2, 4)), false));
175 EXPECT_EQ(
176 1, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(3, 4)), false));
177 EXPECT_EQ(
178 1, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(4, 4)), false));
179 EXPECT_EQ(
180 2, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(5, 4)), false));
181 EXPECT_EQ(
182 2, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(6, 4)), false));
183 EXPECT_EQ(
184 2, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(7, 4)), false));
185 EXPECT_EQ(
186 2, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(8, 4)), false));
187 EXPECT_EQ(
188 3, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(9, 4)), false));
189 EXPECT_EQ(
190 3, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(10, 4)), false));
191 EXPECT_EQ(
192 3, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(11, 4)), false));
194 EXPECT_EQ(
195 1, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(1, 5)), false));
196 EXPECT_EQ(
197 1, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(2, 5)), false));
198 EXPECT_EQ(
199 1, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(3, 5)), false));
200 EXPECT_EQ(
201 1, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(4, 5)), false));
202 EXPECT_EQ(
203 1, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(5, 5)), false));
204 EXPECT_EQ(
205 2, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(6, 5)), false));
206 EXPECT_EQ(
207 2, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(7, 5)), false));
208 EXPECT_EQ(
209 2, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(8, 5)), false));
210 EXPECT_EQ(
211 2, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(9, 5)), false));
212 EXPECT_EQ(
213 2, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(10, 5)), false));
214 EXPECT_EQ(
215 3, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(11, 5)), false));
217 EXPECT_EQ(
219 NumTiles(gfx::Size(16, 16), gfx::Rect(origin, gfx::Size(16, 16)), false));
220 EXPECT_EQ(
222 NumTiles(gfx::Size(17, 17), gfx::Rect(origin, gfx::Size(16, 16)), false));
223 EXPECT_EQ(
225 NumTiles(gfx::Size(15, 15), gfx::Rect(origin, gfx::Size(16, 16)), false));
226 EXPECT_EQ(
228 NumTiles(gfx::Size(8, 8), gfx::Rect(origin, gfx::Size(16, 16)), false));
229 EXPECT_EQ(
231 NumTiles(gfx::Size(8, 8), gfx::Rect(origin, gfx::Size(17, 16)), false));
233 EXPECT_EQ(
235 NumTiles(gfx::Size(5, 8), gfx::Rect(origin, gfx::Size(17, 16)), false));
238 TEST_P(TilingDataTest, NumTiles_TilingWithBorders) {
239 gfx::Point origin = GetParam();
241 EXPECT_EQ(
242 0, NumTiles(gfx::Size(0, 0), gfx::Rect(origin, gfx::Size(0, 0)), true));
243 EXPECT_EQ(
244 0, NumTiles(gfx::Size(0, 0), gfx::Rect(origin, gfx::Size(4, 0)), true));
245 EXPECT_EQ(
246 0, NumTiles(gfx::Size(0, 0), gfx::Rect(origin, gfx::Size(0, 4)), true));
247 EXPECT_EQ(
248 0, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(4, 0)), true));
249 EXPECT_EQ(
250 0, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(0, 4)), true));
251 EXPECT_EQ(
252 0, NumTiles(gfx::Size(0, 0), gfx::Rect(origin, gfx::Size(1, 1)), true));
254 EXPECT_EQ(
255 1, NumTiles(gfx::Size(1, 1), gfx::Rect(origin, gfx::Size(1, 1)), true));
256 EXPECT_EQ(
257 0, NumTiles(gfx::Size(1, 1), gfx::Rect(origin, gfx::Size(1, 2)), true));
258 EXPECT_EQ(
259 0, NumTiles(gfx::Size(1, 1), gfx::Rect(origin, gfx::Size(2, 1)), true));
260 EXPECT_EQ(
261 1, NumTiles(gfx::Size(2, 2), gfx::Rect(origin, gfx::Size(1, 1)), true));
262 EXPECT_EQ(
263 1, NumTiles(gfx::Size(2, 2), gfx::Rect(origin, gfx::Size(1, 2)), true));
264 EXPECT_EQ(
265 1, NumTiles(gfx::Size(2, 2), gfx::Rect(origin, gfx::Size(2, 1)), true));
266 EXPECT_EQ(
267 1, NumTiles(gfx::Size(2, 2), gfx::Rect(origin, gfx::Size(2, 2)), true));
269 EXPECT_EQ(
270 1, NumTiles(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 3)), true));
271 EXPECT_EQ(
272 1, NumTiles(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(2, 3)), true));
273 EXPECT_EQ(
274 1, NumTiles(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(3, 3)), true));
275 EXPECT_EQ(
276 2, NumTiles(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(4, 3)), true));
277 EXPECT_EQ(
278 3, NumTiles(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(5, 3)), true));
279 EXPECT_EQ(
280 4, NumTiles(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 3)), true));
281 EXPECT_EQ(
282 5, NumTiles(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(7, 3)), true));
284 EXPECT_EQ(
285 1, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(1, 4)), true));
286 EXPECT_EQ(
287 1, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(2, 4)), true));
288 EXPECT_EQ(
289 1, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(3, 4)), true));
290 EXPECT_EQ(
291 1, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(4, 4)), true));
292 EXPECT_EQ(
293 2, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(5, 4)), true));
294 EXPECT_EQ(
295 2, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(6, 4)), true));
296 EXPECT_EQ(
297 3, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(7, 4)), true));
298 EXPECT_EQ(
299 3, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(8, 4)), true));
300 EXPECT_EQ(
301 4, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(9, 4)), true));
302 EXPECT_EQ(
303 4, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(10, 4)), true));
304 EXPECT_EQ(
305 5, NumTiles(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(11, 4)), true));
307 EXPECT_EQ(
308 1, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(1, 5)), true));
309 EXPECT_EQ(
310 1, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(2, 5)), true));
311 EXPECT_EQ(
312 1, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(3, 5)), true));
313 EXPECT_EQ(
314 1, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(4, 5)), true));
315 EXPECT_EQ(
316 1, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(5, 5)), true));
317 EXPECT_EQ(
318 2, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(6, 5)), true));
319 EXPECT_EQ(
320 2, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(7, 5)), true));
321 EXPECT_EQ(
322 2, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(8, 5)), true));
323 EXPECT_EQ(
324 3, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(9, 5)), true));
325 EXPECT_EQ(
326 3, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(10, 5)), true));
327 EXPECT_EQ(
328 3, NumTiles(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(11, 5)), true));
330 EXPECT_EQ(
332 NumTiles(gfx::Size(8, 5), gfx::Rect(origin, gfx::Size(16, 32)), true));
335 TEST_P(TilingDataTest, TileXIndexFromSrcCoord) {
336 gfx::Point origin = GetParam();
338 EXPECT_EQ(0,
339 XIndex(gfx::Size(3, 3),
340 gfx::Rect(origin, gfx::Size(10, 10)),
341 false,
342 origin.x() + 0));
343 EXPECT_EQ(0,
344 XIndex(gfx::Size(3, 3),
345 gfx::Rect(origin, gfx::Size(10, 10)),
346 false,
347 origin.x() + 1));
348 EXPECT_EQ(0,
349 XIndex(gfx::Size(3, 3),
350 gfx::Rect(origin, gfx::Size(10, 10)),
351 false,
352 origin.x() + 2));
353 EXPECT_EQ(1,
354 XIndex(gfx::Size(3, 3),
355 gfx::Rect(origin, gfx::Size(10, 10)),
356 false,
357 origin.x() + 3));
358 EXPECT_EQ(1,
359 XIndex(gfx::Size(3, 3),
360 gfx::Rect(origin, gfx::Size(10, 10)),
361 false,
362 origin.x() + 4));
363 EXPECT_EQ(1,
364 XIndex(gfx::Size(3, 3),
365 gfx::Rect(origin, gfx::Size(10, 10)),
366 false,
367 origin.x() + 5));
368 EXPECT_EQ(2,
369 XIndex(gfx::Size(3, 3),
370 gfx::Rect(origin, gfx::Size(10, 10)),
371 false,
372 origin.x() + 6));
373 EXPECT_EQ(2,
374 XIndex(gfx::Size(3, 3),
375 gfx::Rect(origin, gfx::Size(10, 10)),
376 false,
377 origin.x() + 7));
378 EXPECT_EQ(2,
379 XIndex(gfx::Size(3, 3),
380 gfx::Rect(origin, gfx::Size(10, 10)),
381 false,
382 origin.x() + 8));
383 EXPECT_EQ(3,
384 XIndex(gfx::Size(3, 3),
385 gfx::Rect(origin, gfx::Size(10, 10)),
386 false,
387 origin.x() + 9));
388 EXPECT_EQ(3,
389 XIndex(gfx::Size(3, 3),
390 gfx::Rect(origin, gfx::Size(10, 10)),
391 false,
392 origin.x() + 10));
393 EXPECT_EQ(3,
394 XIndex(gfx::Size(3, 3),
395 gfx::Rect(origin, gfx::Size(10, 10)),
396 false,
397 origin.x() + 11));
399 EXPECT_EQ(0,
400 XIndex(gfx::Size(3, 3),
401 gfx::Rect(origin, gfx::Size(10, 10)),
402 true,
403 origin.x()));
404 EXPECT_EQ(0,
405 XIndex(gfx::Size(3, 3),
406 gfx::Rect(origin, gfx::Size(10, 10)),
407 true,
408 origin.x() + 1));
409 EXPECT_EQ(1,
410 XIndex(gfx::Size(3, 3),
411 gfx::Rect(origin, gfx::Size(10, 10)),
412 true,
413 origin.x() + 2));
414 EXPECT_EQ(2,
415 XIndex(gfx::Size(3, 3),
416 gfx::Rect(origin, gfx::Size(10, 10)),
417 true,
418 origin.x() + 3));
419 EXPECT_EQ(3,
420 XIndex(gfx::Size(3, 3),
421 gfx::Rect(origin, gfx::Size(10, 10)),
422 true,
423 origin.x() + 4));
424 EXPECT_EQ(4,
425 XIndex(gfx::Size(3, 3),
426 gfx::Rect(origin, gfx::Size(10, 10)),
427 true,
428 origin.x() + 5));
429 EXPECT_EQ(5,
430 XIndex(gfx::Size(3, 3),
431 gfx::Rect(origin, gfx::Size(10, 10)),
432 true,
433 origin.x() + 6));
434 EXPECT_EQ(6,
435 XIndex(gfx::Size(3, 3),
436 gfx::Rect(origin, gfx::Size(10, 10)),
437 true,
438 origin.x() + 7));
439 EXPECT_EQ(7,
440 XIndex(gfx::Size(3, 3),
441 gfx::Rect(origin, gfx::Size(10, 10)),
442 true,
443 origin.x() + 8));
444 EXPECT_EQ(7,
445 XIndex(gfx::Size(3, 3),
446 gfx::Rect(origin, gfx::Size(10, 10)),
447 true,
448 origin.x() + 9));
449 EXPECT_EQ(7,
450 XIndex(gfx::Size(3, 3),
451 gfx::Rect(origin, gfx::Size(10, 10)),
452 true,
453 origin.x() + 10));
454 EXPECT_EQ(7,
455 XIndex(gfx::Size(3, 3),
456 gfx::Rect(origin, gfx::Size(10, 10)),
457 true,
458 origin.x() + 11));
460 EXPECT_EQ(0,
461 XIndex(gfx::Size(1, 1),
462 gfx::Rect(origin, gfx::Size(1, 1)),
463 false,
464 origin.x() + 0));
465 EXPECT_EQ(0,
466 XIndex(gfx::Size(2, 2),
467 gfx::Rect(origin, gfx::Size(2, 2)),
468 false,
469 origin.x() + 0));
470 EXPECT_EQ(0,
471 XIndex(gfx::Size(2, 2),
472 gfx::Rect(origin, gfx::Size(2, 2)),
473 false,
474 origin.x() + 1));
475 EXPECT_EQ(0,
476 XIndex(gfx::Size(3, 3),
477 gfx::Rect(origin, gfx::Size(3, 3)),
478 false,
479 origin.x() + 0));
480 EXPECT_EQ(0,
481 XIndex(gfx::Size(3, 3),
482 gfx::Rect(origin, gfx::Size(3, 3)),
483 false,
484 origin.x() + 1));
485 EXPECT_EQ(0,
486 XIndex(gfx::Size(3, 3),
487 gfx::Rect(origin, gfx::Size(3, 3)),
488 false,
489 origin.x() + 2));
491 EXPECT_EQ(0,
492 XIndex(gfx::Size(3, 3),
493 gfx::Rect(origin, gfx::Size(4, 3)),
494 false,
495 origin.x() + 0));
496 EXPECT_EQ(0,
497 XIndex(gfx::Size(3, 3),
498 gfx::Rect(origin, gfx::Size(4, 3)),
499 false,
500 origin.x() + 1));
501 EXPECT_EQ(0,
502 XIndex(gfx::Size(3, 3),
503 gfx::Rect(origin, gfx::Size(4, 3)),
504 false,
505 origin.x() + 2));
506 EXPECT_EQ(1,
507 XIndex(gfx::Size(3, 3),
508 gfx::Rect(origin, gfx::Size(4, 3)),
509 false,
510 origin.x() + 3));
512 EXPECT_EQ(0,
513 XIndex(gfx::Size(1, 1),
514 gfx::Rect(origin, gfx::Size(1, 1)),
515 true,
516 origin.x() + 0));
517 EXPECT_EQ(0,
518 XIndex(gfx::Size(2, 2),
519 gfx::Rect(origin, gfx::Size(2, 2)),
520 true,
521 origin.x() + 0));
522 EXPECT_EQ(0,
523 XIndex(gfx::Size(2, 2),
524 gfx::Rect(origin, gfx::Size(2, 2)),
525 true,
526 origin.x() + 1));
527 EXPECT_EQ(0,
528 XIndex(gfx::Size(3, 3),
529 gfx::Rect(origin, gfx::Size(3, 3)),
530 true,
531 origin.x() + 0));
532 EXPECT_EQ(0,
533 XIndex(gfx::Size(3, 3),
534 gfx::Rect(origin, gfx::Size(3, 3)),
535 true,
536 origin.x() + 1));
537 EXPECT_EQ(0,
538 XIndex(gfx::Size(3, 3),
539 gfx::Rect(origin, gfx::Size(3, 3)),
540 true,
541 origin.x() + 2));
543 EXPECT_EQ(0,
544 XIndex(gfx::Size(3, 3),
545 gfx::Rect(origin, gfx::Size(4, 3)),
546 true,
547 origin.x() + 0));
548 EXPECT_EQ(0,
549 XIndex(gfx::Size(3, 3),
550 gfx::Rect(origin, gfx::Size(4, 3)),
551 true,
552 origin.x() + 1));
553 EXPECT_EQ(1,
554 XIndex(gfx::Size(3, 3),
555 gfx::Rect(origin, gfx::Size(4, 3)),
556 true,
557 origin.x() + 2));
558 EXPECT_EQ(1,
559 XIndex(gfx::Size(3, 3),
560 gfx::Rect(origin, gfx::Size(4, 3)),
561 true,
562 origin.x() + 3));
565 TEST_P(TilingDataTest, FirstBorderTileXIndexFromSrcCoord) {
566 gfx::Point origin = GetParam();
568 EXPECT_EQ(0,
569 MinBorderXIndex(gfx::Size(3, 3),
570 gfx::Rect(origin, gfx::Size(10, 10)),
571 false,
572 origin.x() + 0));
573 EXPECT_EQ(0,
574 MinBorderXIndex(gfx::Size(3, 3),
575 gfx::Rect(origin, gfx::Size(10, 10)),
576 false,
577 origin.x() + 1));
578 EXPECT_EQ(0,
579 MinBorderXIndex(gfx::Size(3, 3),
580 gfx::Rect(origin, gfx::Size(10, 10)),
581 false,
582 origin.x() + 2));
583 EXPECT_EQ(1,
584 MinBorderXIndex(gfx::Size(3, 3),
585 gfx::Rect(origin, gfx::Size(10, 10)),
586 false,
587 origin.x() + 3));
588 EXPECT_EQ(1,
589 MinBorderXIndex(gfx::Size(3, 3),
590 gfx::Rect(origin, gfx::Size(10, 10)),
591 false,
592 origin.x() + 4));
593 EXPECT_EQ(1,
594 MinBorderXIndex(gfx::Size(3, 3),
595 gfx::Rect(origin, gfx::Size(10, 10)),
596 false,
597 origin.x() + 5));
598 EXPECT_EQ(2,
599 MinBorderXIndex(gfx::Size(3, 3),
600 gfx::Rect(origin, gfx::Size(10, 10)),
601 false,
602 origin.x() + 6));
603 EXPECT_EQ(2,
604 MinBorderXIndex(gfx::Size(3, 3),
605 gfx::Rect(origin, gfx::Size(10, 10)),
606 false,
607 origin.x() + 7));
608 EXPECT_EQ(2,
609 MinBorderXIndex(gfx::Size(3, 3),
610 gfx::Rect(origin, gfx::Size(10, 10)),
611 false,
612 origin.x() + 8));
613 EXPECT_EQ(3,
614 MinBorderXIndex(gfx::Size(3, 3),
615 gfx::Rect(origin, gfx::Size(10, 10)),
616 false,
617 origin.x() + 9));
618 EXPECT_EQ(3,
619 MinBorderXIndex(gfx::Size(3, 3),
620 gfx::Rect(origin, gfx::Size(10, 10)),
621 false,
622 origin.x() + 10));
623 EXPECT_EQ(3,
624 MinBorderXIndex(gfx::Size(3, 3),
625 gfx::Rect(origin, gfx::Size(10, 10)),
626 false,
627 origin.x() + 11));
629 EXPECT_EQ(0,
630 MinBorderXIndex(gfx::Size(3, 3),
631 gfx::Rect(origin, gfx::Size(10, 10)),
632 true,
633 origin.x() + 0));
634 EXPECT_EQ(0,
635 MinBorderXIndex(gfx::Size(3, 3),
636 gfx::Rect(origin, gfx::Size(10, 10)),
637 true,
638 origin.x() + 1));
639 EXPECT_EQ(0,
640 MinBorderXIndex(gfx::Size(3, 3),
641 gfx::Rect(origin, gfx::Size(10, 10)),
642 true,
643 origin.x() + 2));
644 EXPECT_EQ(1,
645 MinBorderXIndex(gfx::Size(3, 3),
646 gfx::Rect(origin, gfx::Size(10, 10)),
647 true,
648 origin.x() + 3));
649 EXPECT_EQ(2,
650 MinBorderXIndex(gfx::Size(3, 3),
651 gfx::Rect(origin, gfx::Size(10, 10)),
652 true,
653 origin.x() + 4));
654 EXPECT_EQ(3,
655 MinBorderXIndex(gfx::Size(3, 3),
656 gfx::Rect(origin, gfx::Size(10, 10)),
657 true,
658 origin.x() + 5));
659 EXPECT_EQ(4,
660 MinBorderXIndex(gfx::Size(3, 3),
661 gfx::Rect(origin, gfx::Size(10, 10)),
662 true,
663 origin.x() + 6));
664 EXPECT_EQ(5,
665 MinBorderXIndex(gfx::Size(3, 3),
666 gfx::Rect(origin, gfx::Size(10, 10)),
667 true,
668 origin.x() + 7));
669 EXPECT_EQ(6,
670 MinBorderXIndex(gfx::Size(3, 3),
671 gfx::Rect(origin, gfx::Size(10, 10)),
672 true,
673 origin.x() + 8));
674 EXPECT_EQ(7,
675 MinBorderXIndex(gfx::Size(3, 3),
676 gfx::Rect(origin, gfx::Size(10, 10)),
677 true,
678 origin.x() + 9));
679 EXPECT_EQ(7,
680 MinBorderXIndex(gfx::Size(3, 3),
681 gfx::Rect(origin, gfx::Size(10, 10)),
682 true,
683 origin.x() + 10));
684 EXPECT_EQ(7,
685 MinBorderXIndex(gfx::Size(3, 3),
686 gfx::Rect(origin, gfx::Size(10, 10)),
687 true,
688 origin.x() + 11));
690 EXPECT_EQ(0,
691 MinBorderXIndex(gfx::Size(1, 1),
692 gfx::Rect(origin, gfx::Size(1, 1)),
693 false,
694 origin.x() + 0));
695 EXPECT_EQ(0,
696 MinBorderXIndex(gfx::Size(2, 2),
697 gfx::Rect(origin, gfx::Size(2, 2)),
698 false,
699 origin.x() + 0));
700 EXPECT_EQ(0,
701 MinBorderXIndex(gfx::Size(2, 2),
702 gfx::Rect(origin, gfx::Size(2, 2)),
703 false,
704 origin.x() + 1));
705 EXPECT_EQ(0,
706 MinBorderXIndex(gfx::Size(3, 3),
707 gfx::Rect(origin, gfx::Size(3, 3)),
708 false,
709 origin.x() + 0));
710 EXPECT_EQ(0,
711 MinBorderXIndex(gfx::Size(3, 3),
712 gfx::Rect(origin, gfx::Size(3, 3)),
713 false,
714 origin.x() + 1));
715 EXPECT_EQ(0,
716 MinBorderXIndex(gfx::Size(3, 3),
717 gfx::Rect(origin, gfx::Size(3, 3)),
718 false,
719 origin.x() + 2));
721 EXPECT_EQ(0,
722 MinBorderXIndex(gfx::Size(3, 3),
723 gfx::Rect(origin, gfx::Size(4, 3)),
724 false,
725 origin.x() + 0));
726 EXPECT_EQ(0,
727 MinBorderXIndex(gfx::Size(3, 3),
728 gfx::Rect(origin, gfx::Size(4, 3)),
729 false,
730 origin.x() + 1));
731 EXPECT_EQ(0,
732 MinBorderXIndex(gfx::Size(3, 3),
733 gfx::Rect(origin, gfx::Size(4, 3)),
734 false,
735 origin.x() + 2));
736 EXPECT_EQ(1,
737 MinBorderXIndex(gfx::Size(3, 3),
738 gfx::Rect(origin, gfx::Size(4, 3)),
739 false,
740 origin.x() + 3));
742 EXPECT_EQ(0,
743 MinBorderXIndex(gfx::Size(1, 1),
744 gfx::Rect(origin, gfx::Size(1, 1)),
745 true,
746 origin.x() + 0));
747 EXPECT_EQ(0,
748 MinBorderXIndex(gfx::Size(2, 2),
749 gfx::Rect(origin, gfx::Size(2, 2)),
750 true,
751 origin.x() + 0));
752 EXPECT_EQ(0,
753 MinBorderXIndex(gfx::Size(2, 2),
754 gfx::Rect(origin, gfx::Size(2, 2)),
755 true,
756 origin.x() + 1));
757 EXPECT_EQ(0,
758 MinBorderXIndex(gfx::Size(3, 3),
759 gfx::Rect(origin, gfx::Size(3, 3)),
760 true,
761 origin.x() + 0));
762 EXPECT_EQ(0,
763 MinBorderXIndex(gfx::Size(3, 3),
764 gfx::Rect(origin, gfx::Size(3, 3)),
765 true,
766 origin.x() + 1));
767 EXPECT_EQ(0,
768 MinBorderXIndex(gfx::Size(3, 3),
769 gfx::Rect(origin, gfx::Size(3, 3)),
770 true,
771 origin.x() + 2));
773 EXPECT_EQ(0,
774 MinBorderXIndex(gfx::Size(3, 3),
775 gfx::Rect(origin, gfx::Size(4, 3)),
776 true,
777 origin.x() + 0));
778 EXPECT_EQ(0,
779 MinBorderXIndex(gfx::Size(3, 3),
780 gfx::Rect(origin, gfx::Size(4, 3)),
781 true,
782 origin.x() + 1));
783 EXPECT_EQ(0,
784 MinBorderXIndex(gfx::Size(3, 3),
785 gfx::Rect(origin, gfx::Size(4, 3)),
786 true,
787 origin.x() + 2));
788 EXPECT_EQ(1,
789 MinBorderXIndex(gfx::Size(3, 3),
790 gfx::Rect(origin, gfx::Size(4, 3)),
791 true,
792 origin.x() + 3));
795 TEST_P(TilingDataTest, LastBorderTileXIndexFromSrcCoord) {
796 gfx::Point origin = GetParam();
798 EXPECT_EQ(0,
799 MaxBorderXIndex(gfx::Size(3, 3),
800 gfx::Rect(origin, gfx::Size(10, 10)),
801 false,
802 origin.x() + 0));
803 EXPECT_EQ(0,
804 MaxBorderXIndex(gfx::Size(3, 3),
805 gfx::Rect(origin, gfx::Size(10, 10)),
806 false,
807 origin.x() + 1));
808 EXPECT_EQ(0,
809 MaxBorderXIndex(gfx::Size(3, 3),
810 gfx::Rect(origin, gfx::Size(10, 10)),
811 false,
812 origin.x() + 2));
813 EXPECT_EQ(1,
814 MaxBorderXIndex(gfx::Size(3, 3),
815 gfx::Rect(origin, gfx::Size(10, 10)),
816 false,
817 origin.x() + 3));
818 EXPECT_EQ(1,
819 MaxBorderXIndex(gfx::Size(3, 3),
820 gfx::Rect(origin, gfx::Size(10, 10)),
821 false,
822 origin.x() + 4));
823 EXPECT_EQ(1,
824 MaxBorderXIndex(gfx::Size(3, 3),
825 gfx::Rect(origin, gfx::Size(10, 10)),
826 false,
827 origin.x() + 5));
828 EXPECT_EQ(2,
829 MaxBorderXIndex(gfx::Size(3, 3),
830 gfx::Rect(origin, gfx::Size(10, 10)),
831 false,
832 origin.x() + 6));
833 EXPECT_EQ(2,
834 MaxBorderXIndex(gfx::Size(3, 3),
835 gfx::Rect(origin, gfx::Size(10, 10)),
836 false,
837 origin.x() + 7));
838 EXPECT_EQ(2,
839 MaxBorderXIndex(gfx::Size(3, 3),
840 gfx::Rect(origin, gfx::Size(10, 10)),
841 false,
842 origin.x() + 8));
843 EXPECT_EQ(3,
844 MaxBorderXIndex(gfx::Size(3, 3),
845 gfx::Rect(origin, gfx::Size(10, 10)),
846 false,
847 origin.x() + 9));
848 EXPECT_EQ(3,
849 MaxBorderXIndex(gfx::Size(3, 3),
850 gfx::Rect(origin, gfx::Size(10, 10)),
851 false,
852 origin.x() + 10));
853 EXPECT_EQ(3,
854 MaxBorderXIndex(gfx::Size(3, 3),
855 gfx::Rect(origin, gfx::Size(10, 10)),
856 false,
857 origin.x() + 11));
859 EXPECT_EQ(0,
860 MaxBorderXIndex(gfx::Size(3, 3),
861 gfx::Rect(origin, gfx::Size(10, 10)),
862 true,
863 origin.x() + 0));
864 EXPECT_EQ(1,
865 MaxBorderXIndex(gfx::Size(3, 3),
866 gfx::Rect(origin, gfx::Size(10, 10)),
867 true,
868 origin.x() + 1));
869 EXPECT_EQ(2,
870 MaxBorderXIndex(gfx::Size(3, 3),
871 gfx::Rect(origin, gfx::Size(10, 10)),
872 true,
873 origin.x() + 2));
874 EXPECT_EQ(3,
875 MaxBorderXIndex(gfx::Size(3, 3),
876 gfx::Rect(origin, gfx::Size(10, 10)),
877 true,
878 origin.x() + 3));
879 EXPECT_EQ(4,
880 MaxBorderXIndex(gfx::Size(3, 3),
881 gfx::Rect(origin, gfx::Size(10, 10)),
882 true,
883 origin.x() + 4));
884 EXPECT_EQ(5,
885 MaxBorderXIndex(gfx::Size(3, 3),
886 gfx::Rect(origin, gfx::Size(10, 10)),
887 true,
888 origin.x() + 5));
889 EXPECT_EQ(6,
890 MaxBorderXIndex(gfx::Size(3, 3),
891 gfx::Rect(origin, gfx::Size(10, 10)),
892 true,
893 origin.x() + 6));
894 EXPECT_EQ(7,
895 MaxBorderXIndex(gfx::Size(3, 3),
896 gfx::Rect(origin, gfx::Size(10, 10)),
897 true,
898 origin.x() + 7));
899 EXPECT_EQ(7,
900 MaxBorderXIndex(gfx::Size(3, 3),
901 gfx::Rect(origin, gfx::Size(10, 10)),
902 true,
903 origin.x() + 8));
904 EXPECT_EQ(7,
905 MaxBorderXIndex(gfx::Size(3, 3),
906 gfx::Rect(origin, gfx::Size(10, 10)),
907 true,
908 origin.x() + 9));
909 EXPECT_EQ(7,
910 MaxBorderXIndex(gfx::Size(3, 3),
911 gfx::Rect(origin, gfx::Size(10, 10)),
912 true,
913 origin.x() + 10));
914 EXPECT_EQ(7,
915 MaxBorderXIndex(gfx::Size(3, 3),
916 gfx::Rect(origin, gfx::Size(10, 10)),
917 true,
918 origin.x() + 11));
920 EXPECT_EQ(0,
921 MaxBorderXIndex(gfx::Size(1, 1),
922 gfx::Rect(origin, gfx::Size(1, 1)),
923 false,
924 origin.x() + 0));
925 EXPECT_EQ(0,
926 MaxBorderXIndex(gfx::Size(2, 2),
927 gfx::Rect(origin, gfx::Size(2, 2)),
928 false,
929 origin.x() + 0));
930 EXPECT_EQ(0,
931 MaxBorderXIndex(gfx::Size(2, 2),
932 gfx::Rect(origin, gfx::Size(2, 2)),
933 false,
934 origin.x() + 1));
935 EXPECT_EQ(0,
936 MaxBorderXIndex(gfx::Size(3, 3),
937 gfx::Rect(origin, gfx::Size(3, 3)),
938 false,
939 origin.x() + 0));
940 EXPECT_EQ(0,
941 MaxBorderXIndex(gfx::Size(3, 3),
942 gfx::Rect(origin, gfx::Size(3, 3)),
943 false,
944 origin.x() + 1));
945 EXPECT_EQ(0,
946 MaxBorderXIndex(gfx::Size(3, 3),
947 gfx::Rect(origin, gfx::Size(3, 3)),
948 false,
949 origin.x() + 2));
951 EXPECT_EQ(0,
952 MaxBorderXIndex(gfx::Size(3, 3),
953 gfx::Rect(origin, gfx::Size(4, 3)),
954 false,
955 origin.x() + 0));
956 EXPECT_EQ(0,
957 MaxBorderXIndex(gfx::Size(3, 3),
958 gfx::Rect(origin, gfx::Size(4, 3)),
959 false,
960 origin.x() + 1));
961 EXPECT_EQ(0,
962 MaxBorderXIndex(gfx::Size(3, 3),
963 gfx::Rect(origin, gfx::Size(4, 3)),
964 false,
965 origin.x() + 2));
966 EXPECT_EQ(1,
967 MaxBorderXIndex(gfx::Size(3, 3),
968 gfx::Rect(origin, gfx::Size(4, 3)),
969 false,
970 origin.x() + 3));
972 EXPECT_EQ(0,
973 MaxBorderXIndex(gfx::Size(1, 1),
974 gfx::Rect(origin, gfx::Size(1, 1)),
975 true,
976 origin.x() + 0));
977 EXPECT_EQ(0,
978 MaxBorderXIndex(gfx::Size(2, 2),
979 gfx::Rect(origin, gfx::Size(2, 2)),
980 true,
981 origin.x() + 0));
982 EXPECT_EQ(0,
983 MaxBorderXIndex(gfx::Size(2, 2),
984 gfx::Rect(origin, gfx::Size(2, 2)),
985 true,
986 origin.x() + 1));
987 EXPECT_EQ(0,
988 MaxBorderXIndex(gfx::Size(3, 3),
989 gfx::Rect(origin, gfx::Size(3, 3)),
990 true,
991 origin.x() + 0));
992 EXPECT_EQ(0,
993 MaxBorderXIndex(gfx::Size(3, 3),
994 gfx::Rect(origin, gfx::Size(3, 3)),
995 true,
996 origin.x() + 1));
997 EXPECT_EQ(0,
998 MaxBorderXIndex(gfx::Size(3, 3),
999 gfx::Rect(origin, gfx::Size(3, 3)),
1000 true,
1001 origin.x() + 2));
1003 EXPECT_EQ(0,
1004 MaxBorderXIndex(gfx::Size(3, 3),
1005 gfx::Rect(origin, gfx::Size(4, 3)),
1006 true,
1007 origin.x() + 0));
1008 EXPECT_EQ(1,
1009 MaxBorderXIndex(gfx::Size(3, 3),
1010 gfx::Rect(origin, gfx::Size(4, 3)),
1011 true,
1012 origin.x() + 1));
1013 EXPECT_EQ(1,
1014 MaxBorderXIndex(gfx::Size(3, 3),
1015 gfx::Rect(origin, gfx::Size(4, 3)),
1016 true,
1017 origin.x() + 2));
1018 EXPECT_EQ(1,
1019 MaxBorderXIndex(gfx::Size(3, 3),
1020 gfx::Rect(origin, gfx::Size(4, 3)),
1021 true,
1022 origin.x() + 3));
1025 TEST_P(TilingDataTest, TileYIndexFromSrcCoord) {
1026 gfx::Point origin = GetParam();
1028 EXPECT_EQ(0,
1029 YIndex(gfx::Size(3, 3),
1030 gfx::Rect(origin, gfx::Size(10, 10)),
1031 false,
1032 origin.y() + 0));
1033 EXPECT_EQ(0,
1034 YIndex(gfx::Size(3, 3),
1035 gfx::Rect(origin, gfx::Size(10, 10)),
1036 false,
1037 origin.y() + 1));
1038 EXPECT_EQ(0,
1039 YIndex(gfx::Size(3, 3),
1040 gfx::Rect(origin, gfx::Size(10, 10)),
1041 false,
1042 origin.y() + 2));
1043 EXPECT_EQ(1,
1044 YIndex(gfx::Size(3, 3),
1045 gfx::Rect(origin, gfx::Size(10, 10)),
1046 false,
1047 origin.y() + 3));
1048 EXPECT_EQ(1,
1049 YIndex(gfx::Size(3, 3),
1050 gfx::Rect(origin, gfx::Size(10, 10)),
1051 false,
1052 origin.y() + 4));
1053 EXPECT_EQ(1,
1054 YIndex(gfx::Size(3, 3),
1055 gfx::Rect(origin, gfx::Size(10, 10)),
1056 false,
1057 origin.y() + 5));
1058 EXPECT_EQ(2,
1059 YIndex(gfx::Size(3, 3),
1060 gfx::Rect(origin, gfx::Size(10, 10)),
1061 false,
1062 origin.y() + 6));
1063 EXPECT_EQ(2,
1064 YIndex(gfx::Size(3, 3),
1065 gfx::Rect(origin, gfx::Size(10, 10)),
1066 false,
1067 origin.y() + 7));
1068 EXPECT_EQ(2,
1069 YIndex(gfx::Size(3, 3),
1070 gfx::Rect(origin, gfx::Size(10, 10)),
1071 false,
1072 origin.y() + 8));
1073 EXPECT_EQ(3,
1074 YIndex(gfx::Size(3, 3),
1075 gfx::Rect(origin, gfx::Size(10, 10)),
1076 false,
1077 origin.y() + 9));
1078 EXPECT_EQ(3,
1079 YIndex(gfx::Size(3, 3),
1080 gfx::Rect(origin, gfx::Size(10, 10)),
1081 false,
1082 origin.y() + 10));
1083 EXPECT_EQ(3,
1084 YIndex(gfx::Size(3, 3),
1085 gfx::Rect(origin, gfx::Size(10, 10)),
1086 false,
1087 origin.y() + 11));
1089 EXPECT_EQ(0,
1090 YIndex(gfx::Size(3, 3),
1091 gfx::Rect(origin, gfx::Size(10, 10)),
1092 true,
1093 origin.y() + 0));
1094 EXPECT_EQ(0,
1095 YIndex(gfx::Size(3, 3),
1096 gfx::Rect(origin, gfx::Size(10, 10)),
1097 true,
1098 origin.y() + 1));
1099 EXPECT_EQ(1,
1100 YIndex(gfx::Size(3, 3),
1101 gfx::Rect(origin, gfx::Size(10, 10)),
1102 true,
1103 origin.y() + 2));
1104 EXPECT_EQ(2,
1105 YIndex(gfx::Size(3, 3),
1106 gfx::Rect(origin, gfx::Size(10, 10)),
1107 true,
1108 origin.y() + 3));
1109 EXPECT_EQ(3,
1110 YIndex(gfx::Size(3, 3),
1111 gfx::Rect(origin, gfx::Size(10, 10)),
1112 true,
1113 origin.y() + 4));
1114 EXPECT_EQ(4,
1115 YIndex(gfx::Size(3, 3),
1116 gfx::Rect(origin, gfx::Size(10, 10)),
1117 true,
1118 origin.y() + 5));
1119 EXPECT_EQ(5,
1120 YIndex(gfx::Size(3, 3),
1121 gfx::Rect(origin, gfx::Size(10, 10)),
1122 true,
1123 origin.y() + 6));
1124 EXPECT_EQ(6,
1125 YIndex(gfx::Size(3, 3),
1126 gfx::Rect(origin, gfx::Size(10, 10)),
1127 true,
1128 origin.y() + 7));
1129 EXPECT_EQ(7,
1130 YIndex(gfx::Size(3, 3),
1131 gfx::Rect(origin, gfx::Size(10, 10)),
1132 true,
1133 origin.y() + 8));
1134 EXPECT_EQ(7,
1135 YIndex(gfx::Size(3, 3),
1136 gfx::Rect(origin, gfx::Size(10, 10)),
1137 true,
1138 origin.y() + 9));
1139 EXPECT_EQ(7,
1140 YIndex(gfx::Size(3, 3),
1141 gfx::Rect(origin, gfx::Size(10, 10)),
1142 true,
1143 origin.y() + 10));
1144 EXPECT_EQ(7,
1145 YIndex(gfx::Size(3, 3),
1146 gfx::Rect(origin, gfx::Size(10, 10)),
1147 true,
1148 origin.y() + 11));
1150 EXPECT_EQ(0,
1151 YIndex(gfx::Size(1, 1),
1152 gfx::Rect(origin, gfx::Size(1, 1)),
1153 false,
1154 origin.y() + 0));
1155 EXPECT_EQ(0,
1156 YIndex(gfx::Size(2, 2),
1157 gfx::Rect(origin, gfx::Size(2, 2)),
1158 false,
1159 origin.y() + 0));
1160 EXPECT_EQ(0,
1161 YIndex(gfx::Size(2, 2),
1162 gfx::Rect(origin, gfx::Size(2, 2)),
1163 false,
1164 origin.y() + 1));
1165 EXPECT_EQ(0,
1166 YIndex(gfx::Size(3, 3),
1167 gfx::Rect(origin, gfx::Size(3, 3)),
1168 false,
1169 origin.y() + 0));
1170 EXPECT_EQ(0,
1171 YIndex(gfx::Size(3, 3),
1172 gfx::Rect(origin, gfx::Size(3, 3)),
1173 false,
1174 origin.y() + 1));
1175 EXPECT_EQ(0,
1176 YIndex(gfx::Size(3, 3),
1177 gfx::Rect(origin, gfx::Size(3, 3)),
1178 false,
1179 origin.y() + 2));
1181 EXPECT_EQ(0,
1182 YIndex(gfx::Size(3, 3),
1183 gfx::Rect(origin, gfx::Size(3, 4)),
1184 false,
1185 origin.y() + 0));
1186 EXPECT_EQ(0,
1187 YIndex(gfx::Size(3, 3),
1188 gfx::Rect(origin, gfx::Size(3, 4)),
1189 false,
1190 origin.y() + 1));
1191 EXPECT_EQ(0,
1192 YIndex(gfx::Size(3, 3),
1193 gfx::Rect(origin, gfx::Size(3, 4)),
1194 false,
1195 origin.y() + 2));
1196 EXPECT_EQ(1,
1197 YIndex(gfx::Size(3, 3),
1198 gfx::Rect(origin, gfx::Size(3, 4)),
1199 false,
1200 origin.y() + 3));
1202 EXPECT_EQ(0,
1203 YIndex(gfx::Size(1, 1),
1204 gfx::Rect(origin, gfx::Size(1, 1)),
1205 true,
1206 origin.y() + 0));
1207 EXPECT_EQ(0,
1208 YIndex(gfx::Size(2, 2),
1209 gfx::Rect(origin, gfx::Size(2, 2)),
1210 true,
1211 origin.y() + 0));
1212 EXPECT_EQ(0,
1213 YIndex(gfx::Size(2, 2),
1214 gfx::Rect(origin, gfx::Size(2, 2)),
1215 true,
1216 origin.y() + 1));
1217 EXPECT_EQ(0,
1218 YIndex(gfx::Size(3, 3),
1219 gfx::Rect(origin, gfx::Size(3, 3)),
1220 true,
1221 origin.y() + 0));
1222 EXPECT_EQ(0,
1223 YIndex(gfx::Size(3, 3),
1224 gfx::Rect(origin, gfx::Size(3, 3)),
1225 true,
1226 origin.y() + 1));
1227 EXPECT_EQ(0,
1228 YIndex(gfx::Size(3, 3),
1229 gfx::Rect(origin, gfx::Size(3, 3)),
1230 true,
1231 origin.y() + 2));
1233 EXPECT_EQ(0,
1234 YIndex(gfx::Size(3, 3),
1235 gfx::Rect(origin, gfx::Size(3, 4)),
1236 true,
1237 origin.y() + 0));
1238 EXPECT_EQ(0,
1239 YIndex(gfx::Size(3, 3),
1240 gfx::Rect(origin, gfx::Size(3, 4)),
1241 true,
1242 origin.y() + 1));
1243 EXPECT_EQ(1,
1244 YIndex(gfx::Size(3, 3),
1245 gfx::Rect(origin, gfx::Size(3, 4)),
1246 true,
1247 origin.y() + 2));
1248 EXPECT_EQ(1,
1249 YIndex(gfx::Size(3, 3),
1250 gfx::Rect(origin, gfx::Size(3, 4)),
1251 true,
1252 origin.y() + 3));
1255 TEST_P(TilingDataTest, FirstBorderTileYIndexFromSrcCoord) {
1256 gfx::Point origin = GetParam();
1258 EXPECT_EQ(0,
1259 MinBorderYIndex(gfx::Size(3, 3),
1260 gfx::Rect(origin, gfx::Size(10, 10)),
1261 false,
1262 origin.y() + 0));
1263 EXPECT_EQ(0,
1264 MinBorderYIndex(gfx::Size(3, 3),
1265 gfx::Rect(origin, gfx::Size(10, 10)),
1266 false,
1267 origin.y() + 1));
1268 EXPECT_EQ(0,
1269 MinBorderYIndex(gfx::Size(3, 3),
1270 gfx::Rect(origin, gfx::Size(10, 10)),
1271 false,
1272 origin.y() + 2));
1273 EXPECT_EQ(1,
1274 MinBorderYIndex(gfx::Size(3, 3),
1275 gfx::Rect(origin, gfx::Size(10, 10)),
1276 false,
1277 origin.y() + 3));
1278 EXPECT_EQ(1,
1279 MinBorderYIndex(gfx::Size(3, 3),
1280 gfx::Rect(origin, gfx::Size(10, 10)),
1281 false,
1282 origin.y() + 4));
1283 EXPECT_EQ(1,
1284 MinBorderYIndex(gfx::Size(3, 3),
1285 gfx::Rect(origin, gfx::Size(10, 10)),
1286 false,
1287 origin.y() + 5));
1288 EXPECT_EQ(2,
1289 MinBorderYIndex(gfx::Size(3, 3),
1290 gfx::Rect(origin, gfx::Size(10, 10)),
1291 false,
1292 origin.y() + 6));
1293 EXPECT_EQ(2,
1294 MinBorderYIndex(gfx::Size(3, 3),
1295 gfx::Rect(origin, gfx::Size(10, 10)),
1296 false,
1297 origin.y() + 7));
1298 EXPECT_EQ(2,
1299 MinBorderYIndex(gfx::Size(3, 3),
1300 gfx::Rect(origin, gfx::Size(10, 10)),
1301 false,
1302 origin.y() + 8));
1303 EXPECT_EQ(3,
1304 MinBorderYIndex(gfx::Size(3, 3),
1305 gfx::Rect(origin, gfx::Size(10, 10)),
1306 false,
1307 origin.y() + 9));
1308 EXPECT_EQ(3,
1309 MinBorderYIndex(gfx::Size(3, 3),
1310 gfx::Rect(origin, gfx::Size(10, 10)),
1311 false,
1312 origin.y() + 10));
1313 EXPECT_EQ(3,
1314 MinBorderYIndex(gfx::Size(3, 3),
1315 gfx::Rect(origin, gfx::Size(10, 10)),
1316 false,
1317 origin.y() + 11));
1319 EXPECT_EQ(0,
1320 MinBorderYIndex(gfx::Size(3, 3),
1321 gfx::Rect(origin, gfx::Size(10, 10)),
1322 true,
1323 origin.y() + 0));
1324 EXPECT_EQ(0,
1325 MinBorderYIndex(gfx::Size(3, 3),
1326 gfx::Rect(origin, gfx::Size(10, 10)),
1327 true,
1328 origin.y() + 1));
1329 EXPECT_EQ(0,
1330 MinBorderYIndex(gfx::Size(3, 3),
1331 gfx::Rect(origin, gfx::Size(10, 10)),
1332 true,
1333 origin.y() + 2));
1334 EXPECT_EQ(1,
1335 MinBorderYIndex(gfx::Size(3, 3),
1336 gfx::Rect(origin, gfx::Size(10, 10)),
1337 true,
1338 origin.y() + 3));
1339 EXPECT_EQ(2,
1340 MinBorderYIndex(gfx::Size(3, 3),
1341 gfx::Rect(origin, gfx::Size(10, 10)),
1342 true,
1343 origin.y() + 4));
1344 EXPECT_EQ(3,
1345 MinBorderYIndex(gfx::Size(3, 3),
1346 gfx::Rect(origin, gfx::Size(10, 10)),
1347 true,
1348 origin.y() + 5));
1349 EXPECT_EQ(4,
1350 MinBorderYIndex(gfx::Size(3, 3),
1351 gfx::Rect(origin, gfx::Size(10, 10)),
1352 true,
1353 origin.y() + 6));
1354 EXPECT_EQ(5,
1355 MinBorderYIndex(gfx::Size(3, 3),
1356 gfx::Rect(origin, gfx::Size(10, 10)),
1357 true,
1358 origin.y() + 7));
1359 EXPECT_EQ(6,
1360 MinBorderYIndex(gfx::Size(3, 3),
1361 gfx::Rect(origin, gfx::Size(10, 10)),
1362 true,
1363 origin.y() + 8));
1364 EXPECT_EQ(7,
1365 MinBorderYIndex(gfx::Size(3, 3),
1366 gfx::Rect(origin, gfx::Size(10, 10)),
1367 true,
1368 origin.y() + 9));
1369 EXPECT_EQ(7,
1370 MinBorderYIndex(gfx::Size(3, 3),
1371 gfx::Rect(origin, gfx::Size(10, 10)),
1372 true,
1373 origin.y() + 10));
1374 EXPECT_EQ(7,
1375 MinBorderYIndex(gfx::Size(3, 3),
1376 gfx::Rect(origin, gfx::Size(10, 10)),
1377 true,
1378 origin.y() + 11));
1380 EXPECT_EQ(0,
1381 MinBorderYIndex(gfx::Size(1, 1),
1382 gfx::Rect(origin, gfx::Size(1, 1)),
1383 false,
1384 origin.y() + 0));
1385 EXPECT_EQ(0,
1386 MinBorderYIndex(gfx::Size(2, 2),
1387 gfx::Rect(origin, gfx::Size(2, 2)),
1388 false,
1389 origin.y() + 0));
1390 EXPECT_EQ(0,
1391 MinBorderYIndex(gfx::Size(2, 2),
1392 gfx::Rect(origin, gfx::Size(2, 2)),
1393 false,
1394 origin.y() + 1));
1395 EXPECT_EQ(0,
1396 MinBorderYIndex(gfx::Size(3, 3),
1397 gfx::Rect(origin, gfx::Size(3, 3)),
1398 false,
1399 origin.y() + 0));
1400 EXPECT_EQ(0,
1401 MinBorderYIndex(gfx::Size(3, 3),
1402 gfx::Rect(origin, gfx::Size(3, 3)),
1403 false,
1404 origin.y() + 1));
1405 EXPECT_EQ(0,
1406 MinBorderYIndex(gfx::Size(3, 3),
1407 gfx::Rect(origin, gfx::Size(3, 3)),
1408 false,
1409 origin.y() + 2));
1411 EXPECT_EQ(0,
1412 MinBorderYIndex(gfx::Size(3, 3),
1413 gfx::Rect(origin, gfx::Size(3, 4)),
1414 false,
1415 origin.y() + 0));
1416 EXPECT_EQ(0,
1417 MinBorderYIndex(gfx::Size(3, 3),
1418 gfx::Rect(origin, gfx::Size(3, 4)),
1419 false,
1420 origin.y() + 1));
1421 EXPECT_EQ(0,
1422 MinBorderYIndex(gfx::Size(3, 3),
1423 gfx::Rect(origin, gfx::Size(3, 4)),
1424 false,
1425 origin.y() + 2));
1426 EXPECT_EQ(1,
1427 MinBorderYIndex(gfx::Size(3, 3),
1428 gfx::Rect(origin, gfx::Size(3, 4)),
1429 false,
1430 origin.y() + 3));
1432 EXPECT_EQ(0,
1433 MinBorderYIndex(gfx::Size(1, 1),
1434 gfx::Rect(origin, gfx::Size(1, 1)),
1435 true,
1436 origin.y() + 0));
1437 EXPECT_EQ(0,
1438 MinBorderYIndex(gfx::Size(2, 2),
1439 gfx::Rect(origin, gfx::Size(2, 2)),
1440 true,
1441 origin.y() + 0));
1442 EXPECT_EQ(0,
1443 MinBorderYIndex(gfx::Size(2, 2),
1444 gfx::Rect(origin, gfx::Size(2, 2)),
1445 true,
1446 origin.y() + 1));
1447 EXPECT_EQ(0,
1448 MinBorderYIndex(gfx::Size(3, 3),
1449 gfx::Rect(origin, gfx::Size(3, 3)),
1450 true,
1451 origin.y() + 0));
1452 EXPECT_EQ(0,
1453 MinBorderYIndex(gfx::Size(3, 3),
1454 gfx::Rect(origin, gfx::Size(3, 3)),
1455 true,
1456 origin.y() + 1));
1457 EXPECT_EQ(0,
1458 MinBorderYIndex(gfx::Size(3, 3),
1459 gfx::Rect(origin, gfx::Size(3, 3)),
1460 true,
1461 origin.y() + 2));
1463 EXPECT_EQ(0,
1464 MinBorderYIndex(gfx::Size(3, 3),
1465 gfx::Rect(origin, gfx::Size(3, 4)),
1466 true,
1467 origin.y() + 0));
1468 EXPECT_EQ(0,
1469 MinBorderYIndex(gfx::Size(3, 3),
1470 gfx::Rect(origin, gfx::Size(3, 4)),
1471 true,
1472 origin.y() + 1));
1473 EXPECT_EQ(0,
1474 MinBorderYIndex(gfx::Size(3, 3),
1475 gfx::Rect(origin, gfx::Size(3, 4)),
1476 true,
1477 origin.y() + 2));
1478 EXPECT_EQ(1,
1479 MinBorderYIndex(gfx::Size(3, 3),
1480 gfx::Rect(origin, gfx::Size(3, 4)),
1481 true,
1482 origin.y() + 3));
1485 TEST_P(TilingDataTest, LastBorderTileYIndexFromSrcCoord) {
1486 gfx::Point origin = GetParam();
1488 EXPECT_EQ(0,
1489 MaxBorderYIndex(gfx::Size(3, 3),
1490 gfx::Rect(origin, gfx::Size(10, 10)),
1491 false,
1492 origin.y() + 0));
1493 EXPECT_EQ(0,
1494 MaxBorderYIndex(gfx::Size(3, 3),
1495 gfx::Rect(origin, gfx::Size(10, 10)),
1496 false,
1497 origin.y() + 1));
1498 EXPECT_EQ(0,
1499 MaxBorderYIndex(gfx::Size(3, 3),
1500 gfx::Rect(origin, gfx::Size(10, 10)),
1501 false,
1502 origin.y() + 2));
1503 EXPECT_EQ(1,
1504 MaxBorderYIndex(gfx::Size(3, 3),
1505 gfx::Rect(origin, gfx::Size(10, 10)),
1506 false,
1507 origin.y() + 3));
1508 EXPECT_EQ(1,
1509 MaxBorderYIndex(gfx::Size(3, 3),
1510 gfx::Rect(origin, gfx::Size(10, 10)),
1511 false,
1512 origin.y() + 4));
1513 EXPECT_EQ(1,
1514 MaxBorderYIndex(gfx::Size(3, 3),
1515 gfx::Rect(origin, gfx::Size(10, 10)),
1516 false,
1517 origin.y() + 5));
1518 EXPECT_EQ(2,
1519 MaxBorderYIndex(gfx::Size(3, 3),
1520 gfx::Rect(origin, gfx::Size(10, 10)),
1521 false,
1522 origin.y() + 6));
1523 EXPECT_EQ(2,
1524 MaxBorderYIndex(gfx::Size(3, 3),
1525 gfx::Rect(origin, gfx::Size(10, 10)),
1526 false,
1527 origin.y() + 7));
1528 EXPECT_EQ(2,
1529 MaxBorderYIndex(gfx::Size(3, 3),
1530 gfx::Rect(origin, gfx::Size(10, 10)),
1531 false,
1532 origin.y() + 8));
1533 EXPECT_EQ(3,
1534 MaxBorderYIndex(gfx::Size(3, 3),
1535 gfx::Rect(origin, gfx::Size(10, 10)),
1536 false,
1537 origin.y() + 9));
1538 EXPECT_EQ(3,
1539 MaxBorderYIndex(gfx::Size(3, 3),
1540 gfx::Rect(origin, gfx::Size(10, 10)),
1541 false,
1542 origin.y() + 10));
1543 EXPECT_EQ(3,
1544 MaxBorderYIndex(gfx::Size(3, 3),
1545 gfx::Rect(origin, gfx::Size(10, 10)),
1546 false,
1547 origin.y() + 11));
1549 EXPECT_EQ(0,
1550 MaxBorderYIndex(gfx::Size(3, 3),
1551 gfx::Rect(origin, gfx::Size(10, 10)),
1552 true,
1553 origin.y() + 0));
1554 EXPECT_EQ(1,
1555 MaxBorderYIndex(gfx::Size(3, 3),
1556 gfx::Rect(origin, gfx::Size(10, 10)),
1557 true,
1558 origin.y() + 1));
1559 EXPECT_EQ(2,
1560 MaxBorderYIndex(gfx::Size(3, 3),
1561 gfx::Rect(origin, gfx::Size(10, 10)),
1562 true,
1563 origin.y() + 2));
1564 EXPECT_EQ(3,
1565 MaxBorderYIndex(gfx::Size(3, 3),
1566 gfx::Rect(origin, gfx::Size(10, 10)),
1567 true,
1568 origin.y() + 3));
1569 EXPECT_EQ(4,
1570 MaxBorderYIndex(gfx::Size(3, 3),
1571 gfx::Rect(origin, gfx::Size(10, 10)),
1572 true,
1573 origin.y() + 4));
1574 EXPECT_EQ(5,
1575 MaxBorderYIndex(gfx::Size(3, 3),
1576 gfx::Rect(origin, gfx::Size(10, 10)),
1577 true,
1578 origin.y() + 5));
1579 EXPECT_EQ(6,
1580 MaxBorderYIndex(gfx::Size(3, 3),
1581 gfx::Rect(origin, gfx::Size(10, 10)),
1582 true,
1583 origin.y() + 6));
1584 EXPECT_EQ(7,
1585 MaxBorderYIndex(gfx::Size(3, 3),
1586 gfx::Rect(origin, gfx::Size(10, 10)),
1587 true,
1588 origin.y() + 7));
1589 EXPECT_EQ(7,
1590 MaxBorderYIndex(gfx::Size(3, 3),
1591 gfx::Rect(origin, gfx::Size(10, 10)),
1592 true,
1593 origin.y() + 8));
1594 EXPECT_EQ(7,
1595 MaxBorderYIndex(gfx::Size(3, 3),
1596 gfx::Rect(origin, gfx::Size(10, 10)),
1597 true,
1598 origin.y() + 9));
1599 EXPECT_EQ(7,
1600 MaxBorderYIndex(gfx::Size(3, 3),
1601 gfx::Rect(origin, gfx::Size(10, 10)),
1602 true,
1603 origin.y() + 10));
1604 EXPECT_EQ(7,
1605 MaxBorderYIndex(gfx::Size(3, 3),
1606 gfx::Rect(origin, gfx::Size(10, 10)),
1607 true,
1608 origin.y() + 11));
1610 EXPECT_EQ(0,
1611 MaxBorderYIndex(gfx::Size(1, 1),
1612 gfx::Rect(origin, gfx::Size(1, 1)),
1613 false,
1614 origin.y() + 0));
1615 EXPECT_EQ(0,
1616 MaxBorderYIndex(gfx::Size(2, 2),
1617 gfx::Rect(origin, gfx::Size(2, 2)),
1618 false,
1619 origin.y() + 0));
1620 EXPECT_EQ(0,
1621 MaxBorderYIndex(gfx::Size(2, 2),
1622 gfx::Rect(origin, gfx::Size(2, 2)),
1623 false,
1624 origin.y() + 1));
1625 EXPECT_EQ(0,
1626 MaxBorderYIndex(gfx::Size(3, 3),
1627 gfx::Rect(origin, gfx::Size(3, 3)),
1628 false,
1629 origin.y() + 0));
1630 EXPECT_EQ(0,
1631 MaxBorderYIndex(gfx::Size(3, 3),
1632 gfx::Rect(origin, gfx::Size(3, 3)),
1633 false,
1634 origin.y() + 1));
1635 EXPECT_EQ(0,
1636 MaxBorderYIndex(gfx::Size(3, 3),
1637 gfx::Rect(origin, gfx::Size(3, 3)),
1638 false,
1639 origin.y() + 2));
1641 EXPECT_EQ(0,
1642 MaxBorderYIndex(gfx::Size(3, 3),
1643 gfx::Rect(origin, gfx::Size(3, 4)),
1644 false,
1645 origin.y() + 0));
1646 EXPECT_EQ(0,
1647 MaxBorderYIndex(gfx::Size(3, 3),
1648 gfx::Rect(origin, gfx::Size(3, 4)),
1649 false,
1650 origin.y() + 1));
1651 EXPECT_EQ(0,
1652 MaxBorderYIndex(gfx::Size(3, 3),
1653 gfx::Rect(origin, gfx::Size(3, 4)),
1654 false,
1655 origin.y() + 2));
1656 EXPECT_EQ(1,
1657 MaxBorderYIndex(gfx::Size(3, 3),
1658 gfx::Rect(origin, gfx::Size(3, 4)),
1659 false,
1660 origin.y() + 3));
1662 EXPECT_EQ(0,
1663 MaxBorderYIndex(gfx::Size(1, 1),
1664 gfx::Rect(origin, gfx::Size(1, 1)),
1665 true,
1666 origin.y() + 0));
1667 EXPECT_EQ(0,
1668 MaxBorderYIndex(gfx::Size(2, 2),
1669 gfx::Rect(origin, gfx::Size(2, 2)),
1670 true,
1671 origin.y() + 0));
1672 EXPECT_EQ(0,
1673 MaxBorderYIndex(gfx::Size(2, 2),
1674 gfx::Rect(origin, gfx::Size(2, 2)),
1675 true,
1676 origin.y() + 1));
1677 EXPECT_EQ(0,
1678 MaxBorderYIndex(gfx::Size(3, 3),
1679 gfx::Rect(origin, gfx::Size(3, 3)),
1680 true,
1681 origin.y() + 0));
1682 EXPECT_EQ(0,
1683 MaxBorderYIndex(gfx::Size(3, 3),
1684 gfx::Rect(origin, gfx::Size(3, 3)),
1685 true,
1686 origin.y() + 1));
1687 EXPECT_EQ(0,
1688 MaxBorderYIndex(gfx::Size(3, 3),
1689 gfx::Rect(origin, gfx::Size(3, 3)),
1690 true,
1691 origin.y() + 2));
1693 EXPECT_EQ(0,
1694 MaxBorderYIndex(gfx::Size(3, 3),
1695 gfx::Rect(origin, gfx::Size(3, 4)),
1696 true,
1697 origin.y() + 0));
1698 EXPECT_EQ(1,
1699 MaxBorderYIndex(gfx::Size(3, 3),
1700 gfx::Rect(origin, gfx::Size(3, 4)),
1701 true,
1702 origin.y() + 1));
1703 EXPECT_EQ(1,
1704 MaxBorderYIndex(gfx::Size(3, 3),
1705 gfx::Rect(origin, gfx::Size(3, 4)),
1706 true,
1707 origin.y() + 2));
1708 EXPECT_EQ(1,
1709 MaxBorderYIndex(gfx::Size(3, 3),
1710 gfx::Rect(origin, gfx::Size(3, 4)),
1711 true,
1712 origin.y() + 3));
1715 TEST_P(TilingDataTest, TileSizeX) {
1716 gfx::Point origin = GetParam();
1718 EXPECT_EQ(
1719 5, SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(5, 5)), false, 0));
1720 EXPECT_EQ(
1721 5, SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(5, 5)), true, 0));
1723 EXPECT_EQ(
1724 5, SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(6, 6)), false, 0));
1725 EXPECT_EQ(
1726 1, SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(6, 6)), false, 1));
1727 EXPECT_EQ(
1728 4, SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(6, 6)), true, 0));
1729 EXPECT_EQ(
1730 2, SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(6, 6)), true, 1));
1732 EXPECT_EQ(
1733 5, SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(8, 8)), false, 0));
1734 EXPECT_EQ(
1735 3, SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(8, 8)), false, 1));
1736 EXPECT_EQ(
1737 4, SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(8, 8)), true, 0));
1738 EXPECT_EQ(
1739 4, SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(8, 8)), true, 1));
1741 EXPECT_EQ(
1743 SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(10, 10)), false, 0));
1744 EXPECT_EQ(
1746 SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(10, 10)), false, 1));
1747 EXPECT_EQ(
1748 4, SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(10, 10)), true, 0));
1749 EXPECT_EQ(
1750 3, SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(10, 10)), true, 1));
1751 EXPECT_EQ(
1752 3, SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(10, 10)), true, 2));
1754 EXPECT_EQ(
1755 4, SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(11, 11)), true, 2));
1756 EXPECT_EQ(
1757 3, SizeX(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(12, 12)), true, 2));
1759 EXPECT_EQ(
1760 3, SizeX(gfx::Size(5, 9), gfx::Rect(origin, gfx::Size(12, 17)), true, 2));
1763 TEST_P(TilingDataTest, TileSizeY) {
1764 gfx::Point origin = GetParam();
1766 EXPECT_EQ(
1767 5, SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(5, 5)), false, 0));
1768 EXPECT_EQ(
1769 5, SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(5, 5)), true, 0));
1771 EXPECT_EQ(
1772 5, SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(6, 6)), false, 0));
1773 EXPECT_EQ(
1774 1, SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(6, 6)), false, 1));
1775 EXPECT_EQ(
1776 4, SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(6, 6)), true, 0));
1777 EXPECT_EQ(
1778 2, SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(6, 6)), true, 1));
1780 EXPECT_EQ(
1781 5, SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(8, 8)), false, 0));
1782 EXPECT_EQ(
1783 3, SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(8, 8)), false, 1));
1784 EXPECT_EQ(
1785 4, SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(8, 8)), true, 0));
1786 EXPECT_EQ(
1787 4, SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(8, 8)), true, 1));
1789 EXPECT_EQ(
1791 SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(10, 10)), false, 0));
1792 EXPECT_EQ(
1794 SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(10, 10)), false, 1));
1795 EXPECT_EQ(
1796 4, SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(10, 10)), true, 0));
1797 EXPECT_EQ(
1798 3, SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(10, 10)), true, 1));
1799 EXPECT_EQ(
1800 3, SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(10, 10)), true, 2));
1802 EXPECT_EQ(
1803 4, SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(11, 11)), true, 2));
1804 EXPECT_EQ(
1805 3, SizeY(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(12, 12)), true, 2));
1807 EXPECT_EQ(
1808 3, SizeY(gfx::Size(9, 5), gfx::Rect(origin, gfx::Size(17, 12)), true, 2));
1811 TEST_P(TilingDataTest, TileSizeX_and_TilePositionX) {
1812 gfx::Point origin = GetParam();
1814 // Single tile cases:
1815 EXPECT_EQ(
1816 1, SizeX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 1)), false, 0));
1817 EXPECT_EQ(
1818 origin.x(),
1819 PosX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 1)), false, 0));
1820 EXPECT_EQ(
1822 SizeX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 100)), false, 0));
1823 EXPECT_EQ(
1824 origin.x(),
1825 PosX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 100)), false, 0));
1826 EXPECT_EQ(
1827 3, SizeX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(3, 1)), false, 0));
1828 EXPECT_EQ(
1829 origin.x(),
1830 PosX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(3, 1)), false, 0));
1831 EXPECT_EQ(
1833 SizeX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(3, 100)), false, 0));
1834 EXPECT_EQ(
1835 origin.x(),
1836 PosX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(3, 100)), false, 0));
1837 EXPECT_EQ(
1838 1, SizeX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 1)), true, 0));
1839 EXPECT_EQ(origin.x(),
1840 PosX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 1)), true, 0));
1841 EXPECT_EQ(
1842 1, SizeX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 100)), true, 0));
1843 EXPECT_EQ(
1844 origin.x(),
1845 PosX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 100)), true, 0));
1846 EXPECT_EQ(
1847 3, SizeX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(3, 1)), true, 0));
1848 EXPECT_EQ(origin.x(),
1849 PosX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(3, 1)), true, 0));
1850 EXPECT_EQ(
1851 3, SizeX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(3, 100)), true, 0));
1852 EXPECT_EQ(
1853 origin.x(),
1854 PosX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(3, 100)), true, 0));
1856 // Multiple tiles:
1857 // no border
1858 // positions 0, 3
1859 EXPECT_EQ(
1860 2, NumTiles(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 1)), false));
1861 EXPECT_EQ(
1862 3, SizeX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 1)), false, 0));
1863 EXPECT_EQ(
1864 3, SizeX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 1)), false, 1));
1865 EXPECT_EQ(
1866 origin.x() + 0,
1867 PosX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 1)), false, 0));
1868 EXPECT_EQ(
1869 origin.x() + 3,
1870 PosX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 1)), false, 1));
1871 EXPECT_EQ(
1873 SizeX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 100)), false, 0));
1874 EXPECT_EQ(
1876 SizeX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 100)), false, 1));
1877 EXPECT_EQ(
1878 origin.x() + 0,
1879 PosX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 100)), false, 0));
1880 EXPECT_EQ(
1881 origin.x() + 3,
1882 PosX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 100)), false, 1));
1884 // Multiple tiles:
1885 // with border
1886 // positions 0, 2, 3, 4
1887 EXPECT_EQ(
1888 4, NumTiles(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 1)), true));
1889 EXPECT_EQ(
1890 2, SizeX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 1)), true, 0));
1891 EXPECT_EQ(
1892 1, SizeX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 1)), true, 1));
1893 EXPECT_EQ(
1894 1, SizeX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 1)), true, 2));
1895 EXPECT_EQ(
1896 2, SizeX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 1)), true, 3));
1897 EXPECT_EQ(origin.x() + 0,
1898 PosX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 1)), true, 0));
1899 EXPECT_EQ(origin.x() + 2,
1900 PosX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 1)), true, 1));
1901 EXPECT_EQ(origin.x() + 3,
1902 PosX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 1)), true, 2));
1903 EXPECT_EQ(origin.x() + 4,
1904 PosX(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(6, 1)), true, 3));
1905 EXPECT_EQ(
1906 2, SizeX(gfx::Size(3, 7), gfx::Rect(origin, gfx::Size(6, 100)), true, 0));
1907 EXPECT_EQ(
1908 1, SizeX(gfx::Size(3, 7), gfx::Rect(origin, gfx::Size(6, 100)), true, 1));
1909 EXPECT_EQ(
1910 1, SizeX(gfx::Size(3, 7), gfx::Rect(origin, gfx::Size(6, 100)), true, 2));
1911 EXPECT_EQ(
1912 2, SizeX(gfx::Size(3, 7), gfx::Rect(origin, gfx::Size(6, 100)), true, 3));
1913 EXPECT_EQ(
1914 origin.x() + 0,
1915 PosX(gfx::Size(3, 7), gfx::Rect(origin, gfx::Size(6, 100)), true, 0));
1916 EXPECT_EQ(
1917 origin.x() + 2,
1918 PosX(gfx::Size(3, 7), gfx::Rect(origin, gfx::Size(6, 100)), true, 1));
1919 EXPECT_EQ(
1920 origin.x() + 3,
1921 PosX(gfx::Size(3, 7), gfx::Rect(origin, gfx::Size(6, 100)), true, 2));
1922 EXPECT_EQ(
1923 origin.x() + 4,
1924 PosX(gfx::Size(3, 7), gfx::Rect(origin, gfx::Size(6, 100)), true, 3));
1927 TEST_P(TilingDataTest, TileSizeY_and_TilePositionY) {
1928 gfx::Point origin = GetParam();
1930 // Single tile cases:
1931 EXPECT_EQ(
1932 1, SizeY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 1)), false, 0));
1933 EXPECT_EQ(
1934 origin.y(),
1935 PosY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 1)), false, 0));
1936 EXPECT_EQ(
1938 SizeY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(100, 1)), false, 0));
1939 EXPECT_EQ(
1940 origin.y(),
1941 PosY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(100, 1)), false, 0));
1942 EXPECT_EQ(
1943 3, SizeY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 3)), false, 0));
1944 EXPECT_EQ(
1945 origin.y(),
1946 PosY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 3)), false, 0));
1947 EXPECT_EQ(
1949 SizeY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(100, 3)), false, 0));
1950 EXPECT_EQ(
1951 origin.y(),
1952 PosY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(100, 3)), false, 0));
1953 EXPECT_EQ(
1954 1, SizeY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 1)), true, 0));
1955 EXPECT_EQ(origin.y(),
1956 PosY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 1)), true, 0));
1957 EXPECT_EQ(
1958 1, SizeY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(100, 1)), true, 0));
1959 EXPECT_EQ(
1960 origin.y(),
1961 PosY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(100, 1)), true, 0));
1962 EXPECT_EQ(
1963 3, SizeY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 3)), true, 0));
1964 EXPECT_EQ(origin.y(),
1965 PosY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 3)), true, 0));
1966 EXPECT_EQ(
1967 3, SizeY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(100, 3)), true, 0));
1968 EXPECT_EQ(
1969 origin.y(),
1970 PosY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(100, 3)), true, 0));
1972 // Multiple tiles:
1973 // no border
1974 // positions 0, 3
1975 EXPECT_EQ(
1976 2, NumTiles(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 6)), false));
1977 EXPECT_EQ(
1978 3, SizeY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 6)), false, 0));
1979 EXPECT_EQ(
1980 3, SizeY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 6)), false, 1));
1981 EXPECT_EQ(
1982 origin.y() + 0,
1983 PosY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 6)), false, 0));
1984 EXPECT_EQ(
1985 origin.y() + 3,
1986 PosY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 6)), false, 1));
1987 EXPECT_EQ(
1989 SizeY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(100, 6)), false, 0));
1990 EXPECT_EQ(
1992 SizeY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(100, 6)), false, 1));
1993 EXPECT_EQ(
1994 origin.y() + 0,
1995 PosY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(100, 6)), false, 0));
1996 EXPECT_EQ(
1997 origin.y() + 3,
1998 PosY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(100, 6)), false, 1));
2000 // Multiple tiles:
2001 // with border
2002 // positions 0, 2, 3, 4
2003 EXPECT_EQ(
2004 4, NumTiles(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 6)), true));
2005 EXPECT_EQ(
2006 2, SizeY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 6)), true, 0));
2007 EXPECT_EQ(
2008 1, SizeY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 6)), true, 1));
2009 EXPECT_EQ(
2010 1, SizeY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 6)), true, 2));
2011 EXPECT_EQ(
2012 2, SizeY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 6)), true, 3));
2013 EXPECT_EQ(origin.y() + 0,
2014 PosY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 6)), true, 0));
2015 EXPECT_EQ(origin.y() + 2,
2016 PosY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 6)), true, 1));
2017 EXPECT_EQ(origin.y() + 3,
2018 PosY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 6)), true, 2));
2019 EXPECT_EQ(origin.y() + 4,
2020 PosY(gfx::Size(3, 3), gfx::Rect(origin, gfx::Size(1, 6)), true, 3));
2021 EXPECT_EQ(
2022 2, SizeY(gfx::Size(7, 3), gfx::Rect(origin, gfx::Size(100, 6)), true, 0));
2023 EXPECT_EQ(
2024 1, SizeY(gfx::Size(7, 3), gfx::Rect(origin, gfx::Size(100, 6)), true, 1));
2025 EXPECT_EQ(
2026 1, SizeY(gfx::Size(7, 3), gfx::Rect(origin, gfx::Size(100, 6)), true, 2));
2027 EXPECT_EQ(
2028 2, SizeY(gfx::Size(7, 3), gfx::Rect(origin, gfx::Size(100, 6)), true, 3));
2029 EXPECT_EQ(
2030 origin.y() + 0,
2031 PosY(gfx::Size(7, 3), gfx::Rect(origin, gfx::Size(100, 6)), true, 0));
2032 EXPECT_EQ(
2033 origin.y() + 2,
2034 PosY(gfx::Size(7, 3), gfx::Rect(origin, gfx::Size(100, 6)), true, 1));
2035 EXPECT_EQ(
2036 origin.y() + 3,
2037 PosY(gfx::Size(7, 3), gfx::Rect(origin, gfx::Size(100, 6)), true, 2));
2038 EXPECT_EQ(
2039 origin.y() + 4,
2040 PosY(gfx::Size(7, 3), gfx::Rect(origin, gfx::Size(100, 6)), true, 3));
2043 TEST_P(TilingDataTest, SetTotalSize) {
2044 gfx::Point origin = GetParam();
2046 TilingData data(gfx::Size(5, 5), gfx::Rect(origin, gfx::Size(5, 5)), false);
2047 EXPECT_EQ(origin.x(), data.tiling_rect().x());
2048 EXPECT_EQ(origin.y(), data.tiling_rect().y());
2049 EXPECT_EQ(5, data.tiling_rect().width());
2050 EXPECT_EQ(5, data.tiling_rect().height());
2051 EXPECT_EQ(1, data.num_tiles_x());
2052 EXPECT_EQ(5, data.TileSizeX(0));
2053 EXPECT_EQ(1, data.num_tiles_y());
2054 EXPECT_EQ(5, data.TileSizeY(0));
2056 data.SetTilingRect(gfx::Rect(36, 82, 6, 5));
2057 EXPECT_EQ(36, data.tiling_rect().x());
2058 EXPECT_EQ(82, data.tiling_rect().y());
2059 EXPECT_EQ(6, data.tiling_rect().width());
2060 EXPECT_EQ(5, data.tiling_rect().height());
2061 EXPECT_EQ(2, data.num_tiles_x());
2062 EXPECT_EQ(5, data.TileSizeX(0));
2063 EXPECT_EQ(1, data.TileSizeX(1));
2064 EXPECT_EQ(1, data.num_tiles_y());
2065 EXPECT_EQ(5, data.TileSizeY(0));
2067 data.SetTilingRect(gfx::Rect(4, 22, 5, 12));
2068 EXPECT_EQ(4, data.tiling_rect().x());
2069 EXPECT_EQ(22, data.tiling_rect().y());
2070 EXPECT_EQ(5, data.tiling_rect().width());
2071 EXPECT_EQ(12, data.tiling_rect().height());
2072 EXPECT_EQ(1, data.num_tiles_x());
2073 EXPECT_EQ(5, data.TileSizeX(0));
2074 EXPECT_EQ(3, data.num_tiles_y());
2075 EXPECT_EQ(5, data.TileSizeY(0));
2076 EXPECT_EQ(5, data.TileSizeY(1));
2077 EXPECT_EQ(2, data.TileSizeY(2));
2080 TEST_P(TilingDataTest, SetMaxTextureSizeNoBorders) {
2081 gfx::Point origin = GetParam();
2083 TilingData data(gfx::Size(8, 8), gfx::Rect(origin, gfx::Size(16, 32)), false);
2084 EXPECT_EQ(2, data.num_tiles_x());
2085 EXPECT_EQ(4, data.num_tiles_y());
2087 data.SetMaxTextureSize(gfx::Size(32, 32));
2088 EXPECT_EQ(gfx::Size(32, 32), data.max_texture_size());
2089 EXPECT_EQ(1, data.num_tiles_x());
2090 EXPECT_EQ(1, data.num_tiles_y());
2092 data.SetMaxTextureSize(gfx::Size(2, 2));
2093 EXPECT_EQ(gfx::Size(2, 2), data.max_texture_size());
2094 EXPECT_EQ(8, data.num_tiles_x());
2095 EXPECT_EQ(16, data.num_tiles_y());
2097 data.SetMaxTextureSize(gfx::Size(5, 5));
2098 EXPECT_EQ(gfx::Size(5, 5), data.max_texture_size());
2099 EXPECT_EQ(4, data.num_tiles_x());
2100 EXPECT_EQ(7, data.num_tiles_y());
2102 data.SetMaxTextureSize(gfx::Size(8, 5));
2103 EXPECT_EQ(gfx::Size(8, 5), data.max_texture_size());
2104 EXPECT_EQ(2, data.num_tiles_x());
2105 EXPECT_EQ(7, data.num_tiles_y());
2108 TEST_P(TilingDataTest, SetMaxTextureSizeBorders) {
2109 gfx::Point origin = GetParam();
2111 TilingData data(gfx::Size(8, 8), gfx::Rect(origin, gfx::Size(16, 32)), true);
2112 EXPECT_EQ(3, data.num_tiles_x());
2113 EXPECT_EQ(5, data.num_tiles_y());
2115 data.SetMaxTextureSize(gfx::Size(32, 32));
2116 EXPECT_EQ(gfx::Size(32, 32), data.max_texture_size());
2117 EXPECT_EQ(1, data.num_tiles_x());
2118 EXPECT_EQ(1, data.num_tiles_y());
2120 data.SetMaxTextureSize(gfx::Size(2, 2));
2121 EXPECT_EQ(gfx::Size(2, 2), data.max_texture_size());
2122 EXPECT_EQ(0, data.num_tiles_x());
2123 EXPECT_EQ(0, data.num_tiles_y());
2125 data.SetMaxTextureSize(gfx::Size(5, 5));
2126 EXPECT_EQ(gfx::Size(5, 5), data.max_texture_size());
2127 EXPECT_EQ(5, data.num_tiles_x());
2128 EXPECT_EQ(10, data.num_tiles_y());
2130 data.SetMaxTextureSize(gfx::Size(8, 5));
2131 EXPECT_EQ(gfx::Size(8, 5), data.max_texture_size());
2132 EXPECT_EQ(3, data.num_tiles_x());
2133 EXPECT_EQ(10, data.num_tiles_y());
2136 TEST_P(TilingDataTest, ExpandRectToTileBoundsWithBordersEmpty) {
2137 gfx::Point origin = GetParam();
2138 TilingData empty_total_size(
2139 gfx::Size(0, 0), gfx::Rect(origin, gfx::Size(8, 8)), true);
2140 EXPECT_RECT_EQ(
2141 gfx::Rect(),
2142 empty_total_size.ExpandRectToTileBoundsWithBorders(gfx::Rect()));
2143 EXPECT_RECT_EQ(gfx::Rect(),
2144 empty_total_size.ExpandRectToTileBoundsWithBorders(
2145 gfx::Rect(100, 100, 100, 100)));
2146 EXPECT_RECT_EQ(gfx::Rect(),
2147 empty_total_size.ExpandRectToTileBoundsWithBorders(
2148 gfx::Rect(0, 0, 100, 100)));
2150 TilingData empty_max_texture_size(
2151 gfx::Size(8, 8), gfx::Rect(origin, gfx::Size(0, 0)), true);
2152 EXPECT_RECT_EQ(
2153 gfx::Rect(),
2154 empty_max_texture_size.ExpandRectToTileBoundsWithBorders(gfx::Rect()));
2155 EXPECT_RECT_EQ(gfx::Rect(),
2156 empty_max_texture_size.ExpandRectToTileBoundsWithBorders(
2157 gfx::Rect(100, 100, 100, 100)));
2158 EXPECT_RECT_EQ(gfx::Rect(),
2159 empty_max_texture_size.ExpandRectToTileBoundsWithBorders(
2160 gfx::Rect(0, 0, 100, 100)));
2163 TEST_P(TilingDataTest, ExpandRectToTileBoundsWithBorders) {
2164 gfx::Point origin = GetParam();
2165 TilingData data(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(16, 32)), true);
2167 // Small rect at origin rounds up to tile 0, 0.
2168 gfx::Rect at_origin_src(origin, gfx::Size(1, 1));
2169 gfx::Rect at_origin_result(data.TileBoundsWithBorder(0, 0));
2170 EXPECT_NE(at_origin_src, at_origin_result);
2171 EXPECT_RECT_EQ(at_origin_result,
2172 data.ExpandRectToTileBoundsWithBorders(at_origin_src));
2174 // Arbitrary internal rect.
2175 gfx::Rect rect_src(origin.x() + 6, origin.y() + 6, 1, 3);
2176 // Tile 2, 2 => gfx::Rect(4, 4, 4, 4)
2177 // Tile 3, 4 => gfx::Rect(6, 8, 4, 4)
2178 gfx::Rect rect_result(gfx::UnionRects(data.TileBoundsWithBorder(2, 2),
2179 data.TileBoundsWithBorder(3, 4)));
2180 EXPECT_NE(rect_src, rect_result);
2181 EXPECT_RECT_EQ(rect_result, data.ExpandRectToTileBoundsWithBorders(rect_src));
2183 // On tile bounds rounds up to next tile (since border overlaps).
2184 gfx::Rect border_rect_src(
2185 gfx::UnionRects(data.TileBounds(1, 2), data.TileBounds(3, 4)));
2186 gfx::Rect border_rect_result(gfx::UnionRects(
2187 data.TileBoundsWithBorder(0, 1), data.TileBoundsWithBorder(4, 5)));
2188 EXPECT_RECT_EQ(border_rect_result,
2189 data.ExpandRectToTileBoundsWithBorders(border_rect_src));
2191 // Equal to tiling rect.
2192 EXPECT_RECT_EQ(data.tiling_rect(),
2193 data.ExpandRectToTileBoundsWithBorders(data.tiling_rect()));
2195 // Containing, but larger than tiling rect.
2196 EXPECT_RECT_EQ(data.tiling_rect(),
2197 data.ExpandRectToTileBoundsWithBorders(
2198 gfx::Rect(origin, gfx::Size(100, 100))));
2200 // Non-intersecting with tiling rect.
2201 gfx::Rect non_intersect(origin.x() + 200, origin.y() + 200, 100, 100);
2202 EXPECT_FALSE(non_intersect.Intersects(data.tiling_rect()));
2203 EXPECT_RECT_EQ(gfx::Rect(),
2204 data.ExpandRectToTileBoundsWithBorders(non_intersect));
2206 TilingData data2(gfx::Size(8, 8), gfx::Rect(origin, gfx::Size(32, 64)), true);
2208 // Inside other tile border texels doesn't include other tiles.
2209 gfx::Rect inner_rect_src(data2.TileBounds(1, 1));
2210 inner_rect_src.Inset(data2.border_texels(), data.border_texels());
2211 gfx::Rect inner_rect_result(data2.TileBoundsWithBorder(1, 1));
2212 gfx::Rect expanded = data2.ExpandRectToTileBoundsWithBorders(inner_rect_src);
2213 EXPECT_EQ(inner_rect_result.ToString(), expanded.ToString());
2216 TEST_P(TilingDataTest, ExpandRectToTileBounds) {
2217 gfx::Point origin = GetParam();
2218 TilingData data(gfx::Size(4, 4), gfx::Rect(origin, gfx::Size(16, 32)), true);
2220 // Small rect at origin rounds up to tile 0, 0.
2221 gfx::Rect at_origin_src(origin, gfx::Size(1, 1));
2222 gfx::Rect at_origin_result(data.TileBounds(0, 0));
2223 EXPECT_NE(at_origin_src, at_origin_result);
2224 EXPECT_RECT_EQ(at_origin_result, data.ExpandRectToTileBounds(at_origin_src));
2226 // Arbitrary internal rect.
2227 gfx::Rect rect_src(origin.x() + 6, origin.y() + 6, 1, 3);
2228 // Tile 2, 2 => gfx::Rect(4, 4, 4, 4)
2229 // Tile 3, 4 => gfx::Rect(6, 8, 4, 4)
2230 gfx::Rect rect_result(
2231 gfx::UnionRects(data.TileBounds(2, 2), data.TileBounds(3, 4)));
2232 EXPECT_NE(rect_src, rect_result);
2233 EXPECT_RECT_EQ(rect_result, data.ExpandRectToTileBounds(rect_src));
2235 // On tile bounds rounds up to next tile (since border overlaps).
2236 gfx::Rect border_rect_src(
2237 gfx::UnionRects(data.TileBounds(1, 2), data.TileBounds(3, 4)));
2238 gfx::Rect border_rect_result(
2239 gfx::UnionRects(data.TileBounds(0, 1), data.TileBounds(4, 5)));
2240 EXPECT_RECT_EQ(border_rect_result,
2241 data.ExpandRectToTileBounds(border_rect_src));
2243 // Equal to tiling rect.
2244 EXPECT_RECT_EQ(data.tiling_rect(),
2245 data.ExpandRectToTileBounds(data.tiling_rect()));
2247 // Containing, but larger than tiling rect.
2248 EXPECT_RECT_EQ(
2249 data.tiling_rect(),
2250 data.ExpandRectToTileBounds(gfx::Rect(origin, gfx::Size(100, 100))));
2252 // Non-intersecting with tiling rect.
2253 gfx::Rect non_intersect(origin.x() + 200, origin.y() + 200, 100, 100);
2254 EXPECT_FALSE(non_intersect.Intersects(data.tiling_rect()));
2255 EXPECT_RECT_EQ(gfx::Rect(), data.ExpandRectToTileBounds(non_intersect));
2257 TilingData data2(gfx::Size(8, 8), gfx::Rect(origin, gfx::Size(32, 64)), true);
2259 // Inside other tile border texels doesn't include other tiles.
2260 gfx::Rect inner_rect_src(data2.TileBounds(1, 1));
2261 inner_rect_src.Inset(data2.border_texels(), data.border_texels());
2262 gfx::Rect inner_rect_result(data2.TileBounds(1, 1));
2263 gfx::Rect expanded = data2.ExpandRectToTileBounds(inner_rect_src);
2264 EXPECT_EQ(inner_rect_result.ToString(), expanded.ToString());
2267 TEST_P(TilingDataTest, Assignment) {
2268 gfx::Point origin = GetParam();
2271 TilingData source(
2272 gfx::Size(8, 8), gfx::Rect(origin, gfx::Size(16, 32)), true);
2273 TilingData dest = source;
2274 EXPECT_EQ(source.border_texels(), dest.border_texels());
2275 EXPECT_EQ(source.max_texture_size(), dest.max_texture_size());
2276 EXPECT_EQ(source.num_tiles_x(), dest.num_tiles_x());
2277 EXPECT_EQ(source.num_tiles_y(), dest.num_tiles_y());
2278 EXPECT_EQ(source.tiling_rect().x(), dest.tiling_rect().x());
2279 EXPECT_EQ(source.tiling_rect().y(), dest.tiling_rect().y());
2280 EXPECT_EQ(source.tiling_rect().width(), dest.tiling_rect().width());
2281 EXPECT_EQ(source.tiling_rect().height(), dest.tiling_rect().height());
2284 TilingData source(
2285 gfx::Size(7, 3), gfx::Rect(origin, gfx::Size(6, 100)), false);
2286 TilingData dest(source);
2287 EXPECT_EQ(source.border_texels(), dest.border_texels());
2288 EXPECT_EQ(source.max_texture_size(), dest.max_texture_size());
2289 EXPECT_EQ(source.num_tiles_x(), dest.num_tiles_x());
2290 EXPECT_EQ(source.num_tiles_y(), dest.num_tiles_y());
2291 EXPECT_EQ(source.tiling_rect().x(), dest.tiling_rect().x());
2292 EXPECT_EQ(source.tiling_rect().y(), dest.tiling_rect().y());
2293 EXPECT_EQ(source.tiling_rect().width(), dest.tiling_rect().width());
2294 EXPECT_EQ(source.tiling_rect().height(), dest.tiling_rect().height());
2298 TEST_P(TilingDataTest, SetBorderTexels) {
2299 gfx::Point origin = GetParam();
2301 TilingData data(gfx::Size(8, 8), gfx::Rect(origin, gfx::Size(16, 32)), false);
2302 EXPECT_EQ(2, data.num_tiles_x());
2303 EXPECT_EQ(4, data.num_tiles_y());
2305 data.SetHasBorderTexels(true);
2306 EXPECT_EQ(3, data.num_tiles_x());
2307 EXPECT_EQ(5, data.num_tiles_y());
2309 data.SetHasBorderTexels(false);
2310 EXPECT_EQ(2, data.num_tiles_x());
2311 EXPECT_EQ(4, data.num_tiles_y());
2314 TEST_P(TilingDataTest, LargeBorders) {
2315 gfx::Point origin = GetParam();
2317 TilingData data(
2318 gfx::Size(100, 80), gfx::Rect(origin, gfx::Size(200, 145)), 30);
2319 EXPECT_EQ(30, data.border_texels());
2321 EXPECT_EQ(70, data.TileSizeX(0));
2322 EXPECT_EQ(40, data.TileSizeX(1));
2323 EXPECT_EQ(40, data.TileSizeX(2));
2324 EXPECT_EQ(50, data.TileSizeX(3));
2325 EXPECT_EQ(4, data.num_tiles_x());
2327 EXPECT_EQ(50, data.TileSizeY(0));
2328 EXPECT_EQ(20, data.TileSizeY(1));
2329 EXPECT_EQ(20, data.TileSizeY(2));
2330 EXPECT_EQ(20, data.TileSizeY(3));
2331 EXPECT_EQ(35, data.TileSizeY(4));
2332 EXPECT_EQ(5, data.num_tiles_y());
2334 EXPECT_RECT_EQ(gfx::Rect(origin.x() + 0, origin.y() + 0, 70, 50),
2335 data.TileBounds(0, 0));
2336 EXPECT_RECT_EQ(gfx::Rect(origin.x() + 70, origin.y() + 50, 40, 20),
2337 data.TileBounds(1, 1));
2338 EXPECT_RECT_EQ(gfx::Rect(origin.x() + 110, origin.y() + 110, 40, 35),
2339 data.TileBounds(2, 4));
2340 EXPECT_RECT_EQ(gfx::Rect(origin.x() + 150, origin.y() + 70, 50, 20),
2341 data.TileBounds(3, 2));
2342 EXPECT_RECT_EQ(gfx::Rect(origin.x() + 150, origin.y() + 110, 50, 35),
2343 data.TileBounds(3, 4));
2345 EXPECT_RECT_EQ(gfx::Rect(origin.x() + 0, origin.y() + 0, 100, 80),
2346 data.TileBoundsWithBorder(0, 0));
2347 EXPECT_RECT_EQ(gfx::Rect(origin.x() + 40, origin.y() + 20, 100, 80),
2348 data.TileBoundsWithBorder(1, 1));
2349 EXPECT_RECT_EQ(gfx::Rect(origin.x() + 80, origin.y() + 80, 100, 65),
2350 data.TileBoundsWithBorder(2, 4));
2351 EXPECT_RECT_EQ(gfx::Rect(origin.x() + 120, origin.y() + 40, 80, 80),
2352 data.TileBoundsWithBorder(3, 2));
2353 EXPECT_RECT_EQ(gfx::Rect(origin.x() + 120, origin.y() + 80, 80, 65),
2354 data.TileBoundsWithBorder(3, 4));
2356 EXPECT_EQ(0, data.TileXIndexFromSrcCoord(origin.x() + 0));
2357 EXPECT_EQ(0, data.TileXIndexFromSrcCoord(origin.x() + 69));
2358 EXPECT_EQ(1, data.TileXIndexFromSrcCoord(origin.x() + 70));
2359 EXPECT_EQ(1, data.TileXIndexFromSrcCoord(origin.x() + 109));
2360 EXPECT_EQ(2, data.TileXIndexFromSrcCoord(origin.x() + 110));
2361 EXPECT_EQ(2, data.TileXIndexFromSrcCoord(origin.x() + 149));
2362 EXPECT_EQ(3, data.TileXIndexFromSrcCoord(origin.x() + 150));
2363 EXPECT_EQ(3, data.TileXIndexFromSrcCoord(origin.x() + 199));
2365 EXPECT_EQ(0, data.TileYIndexFromSrcCoord(origin.y() + 0));
2366 EXPECT_EQ(0, data.TileYIndexFromSrcCoord(origin.y() + 49));
2367 EXPECT_EQ(1, data.TileYIndexFromSrcCoord(origin.y() + 50));
2368 EXPECT_EQ(1, data.TileYIndexFromSrcCoord(origin.y() + 69));
2369 EXPECT_EQ(2, data.TileYIndexFromSrcCoord(origin.y() + 70));
2370 EXPECT_EQ(2, data.TileYIndexFromSrcCoord(origin.y() + 89));
2371 EXPECT_EQ(3, data.TileYIndexFromSrcCoord(origin.y() + 90));
2372 EXPECT_EQ(3, data.TileYIndexFromSrcCoord(origin.y() + 109));
2373 EXPECT_EQ(4, data.TileYIndexFromSrcCoord(origin.y() + 110));
2374 EXPECT_EQ(4, data.TileYIndexFromSrcCoord(origin.y() + 144));
2376 EXPECT_EQ(0, data.FirstBorderTileXIndexFromSrcCoord(origin.x() + 0));
2377 EXPECT_EQ(0, data.FirstBorderTileXIndexFromSrcCoord(origin.x() + 99));
2378 EXPECT_EQ(1, data.FirstBorderTileXIndexFromSrcCoord(origin.x() + 100));
2379 EXPECT_EQ(1, data.FirstBorderTileXIndexFromSrcCoord(origin.x() + 139));
2380 EXPECT_EQ(2, data.FirstBorderTileXIndexFromSrcCoord(origin.x() + 140));
2381 EXPECT_EQ(2, data.FirstBorderTileXIndexFromSrcCoord(origin.x() + 179));
2382 EXPECT_EQ(3, data.FirstBorderTileXIndexFromSrcCoord(origin.x() + 180));
2383 EXPECT_EQ(3, data.FirstBorderTileXIndexFromSrcCoord(origin.x() + 199));
2385 EXPECT_EQ(0, data.FirstBorderTileYIndexFromSrcCoord(origin.y() + 0));
2386 EXPECT_EQ(0, data.FirstBorderTileYIndexFromSrcCoord(origin.y() + 79));
2387 EXPECT_EQ(1, data.FirstBorderTileYIndexFromSrcCoord(origin.y() + 80));
2388 EXPECT_EQ(1, data.FirstBorderTileYIndexFromSrcCoord(origin.y() + 99));
2389 EXPECT_EQ(2, data.FirstBorderTileYIndexFromSrcCoord(origin.y() + 100));
2390 EXPECT_EQ(2, data.FirstBorderTileYIndexFromSrcCoord(origin.y() + 119));
2391 EXPECT_EQ(3, data.FirstBorderTileYIndexFromSrcCoord(origin.y() + 120));
2392 EXPECT_EQ(3, data.FirstBorderTileYIndexFromSrcCoord(origin.y() + 139));
2393 EXPECT_EQ(4, data.FirstBorderTileYIndexFromSrcCoord(origin.y() + 140));
2394 EXPECT_EQ(4, data.FirstBorderTileYIndexFromSrcCoord(origin.y() + 144));
2396 EXPECT_EQ(0, data.LastBorderTileXIndexFromSrcCoord(origin.x() + 0));
2397 EXPECT_EQ(0, data.LastBorderTileXIndexFromSrcCoord(origin.x() + 39));
2398 EXPECT_EQ(1, data.LastBorderTileXIndexFromSrcCoord(origin.x() + 40));
2399 EXPECT_EQ(1, data.LastBorderTileXIndexFromSrcCoord(origin.x() + 79));
2400 EXPECT_EQ(2, data.LastBorderTileXIndexFromSrcCoord(origin.x() + 80));
2401 EXPECT_EQ(2, data.LastBorderTileXIndexFromSrcCoord(origin.x() + 119));
2402 EXPECT_EQ(3, data.LastBorderTileXIndexFromSrcCoord(origin.x() + 120));
2403 EXPECT_EQ(3, data.LastBorderTileXIndexFromSrcCoord(origin.x() + 199));
2405 EXPECT_EQ(0, data.LastBorderTileYIndexFromSrcCoord(origin.y() + 0));
2406 EXPECT_EQ(0, data.LastBorderTileYIndexFromSrcCoord(origin.y() + 19));
2407 EXPECT_EQ(1, data.LastBorderTileYIndexFromSrcCoord(origin.y() + 20));
2408 EXPECT_EQ(1, data.LastBorderTileYIndexFromSrcCoord(origin.y() + 39));
2409 EXPECT_EQ(2, data.LastBorderTileYIndexFromSrcCoord(origin.y() + 40));
2410 EXPECT_EQ(2, data.LastBorderTileYIndexFromSrcCoord(origin.y() + 59));
2411 EXPECT_EQ(3, data.LastBorderTileYIndexFromSrcCoord(origin.y() + 60));
2412 EXPECT_EQ(3, data.LastBorderTileYIndexFromSrcCoord(origin.y() + 79));
2413 EXPECT_EQ(4, data.LastBorderTileYIndexFromSrcCoord(origin.y() + 80));
2414 EXPECT_EQ(4, data.LastBorderTileYIndexFromSrcCoord(origin.y() + 144));
2417 void TestIterate(const TilingData& data,
2418 gfx::Rect rect,
2419 int expect_left,
2420 int expect_top,
2421 int expect_right,
2422 int expect_bottom,
2423 bool include_borders) {
2424 EXPECT_GE(expect_left, 0);
2425 EXPECT_GE(expect_top, 0);
2426 EXPECT_LT(expect_right, data.num_tiles_x());
2427 EXPECT_LT(expect_bottom, data.num_tiles_y());
2429 std::vector<std::pair<int, int> > original_expected;
2430 for (int x = 0; x < data.num_tiles_x(); ++x) {
2431 for (int y = 0; y < data.num_tiles_y(); ++y) {
2432 gfx::Rect bounds;
2433 if (include_borders)
2434 bounds = data.TileBoundsWithBorder(x, y);
2435 else
2436 bounds = data.TileBounds(x, y);
2437 if (x >= expect_left && x <= expect_right &&
2438 y >= expect_top && y <= expect_bottom) {
2439 EXPECT_TRUE(bounds.Intersects(rect));
2440 original_expected.push_back(std::make_pair(x, y));
2441 } else {
2442 EXPECT_FALSE(bounds.Intersects(rect));
2447 // Verify with vanilla iterator.
2449 std::vector<std::pair<int, int> > expected = original_expected;
2450 for (TilingData::Iterator iter(&data, rect, include_borders); iter;
2451 ++iter) {
2452 bool found = false;
2453 for (size_t i = 0; i < expected.size(); ++i) {
2454 if (expected[i] == iter.index()) {
2455 expected[i] = expected.back();
2456 expected.pop_back();
2457 found = true;
2458 break;
2461 EXPECT_TRUE(found);
2463 EXPECT_EQ(0u, expected.size());
2466 // Make sure this also works with a difference iterator and an empty ignore.
2467 // The difference iterator always includes borders, so ignore it otherwise.
2468 if (include_borders) {
2469 std::vector<std::pair<int, int> > expected = original_expected;
2470 for (TilingData::DifferenceIterator iter(&data, rect, gfx::Rect());
2471 iter; ++iter) {
2472 bool found = false;
2473 for (size_t i = 0; i < expected.size(); ++i) {
2474 if (expected[i] == iter.index()) {
2475 expected[i] = expected.back();
2476 expected.pop_back();
2477 found = true;
2478 break;
2481 EXPECT_TRUE(found);
2483 EXPECT_EQ(0u, expected.size());
2487 void TestIterateBorders(const TilingData& data,
2488 gfx::Rect rect,
2489 int expect_left,
2490 int expect_top,
2491 int expect_right,
2492 int expect_bottom) {
2493 bool include_borders = true;
2494 TestIterate(data,
2495 rect,
2496 expect_left,
2497 expect_top,
2498 expect_right,
2499 expect_bottom,
2500 include_borders);
2503 void TestIterateNoBorders(const TilingData& data,
2504 gfx::Rect rect,
2505 int expect_left,
2506 int expect_top,
2507 int expect_right,
2508 int expect_bottom) {
2509 bool include_borders = false;
2510 TestIterate(data,
2511 rect,
2512 expect_left,
2513 expect_top,
2514 expect_right,
2515 expect_bottom,
2516 include_borders);
2519 void TestIterateAll(const TilingData& data,
2520 gfx::Rect rect,
2521 int expect_left,
2522 int expect_top,
2523 int expect_right,
2524 int expect_bottom) {
2525 TestIterateBorders(
2526 data, rect, expect_left, expect_top, expect_right, expect_bottom);
2527 TestIterateNoBorders(
2528 data, rect, expect_left, expect_top, expect_right, expect_bottom);
2531 TEST_P(TilingDataTest, IteratorNoBorderTexels) {
2532 gfx::Point origin = GetParam();
2534 TilingData data(
2535 gfx::Size(10, 10), gfx::Rect(origin, gfx::Size(40, 25)), false);
2536 // The following Coordinates are relative to the origin.
2537 // X border index by src coord: [0-10), [10-20), [20, 30), [30, 40)
2538 // Y border index by src coord: [0-10), [10-20), [20, 25)
2539 TestIterateAll(data, gfx::Rect(origin.x(), origin.y(), 40, 25), 0, 0, 3, 2);
2540 TestIterateAll(
2541 data, gfx::Rect(origin.x() + 15, origin.y() + 15, 8, 8), 1, 1, 2, 2);
2543 // Oversized.
2544 TestIterateAll(data,
2545 gfx::Rect(origin.x() - 100, origin.y() - 100, 1000, 1000),
2550 TestIterateAll(
2551 data, gfx::Rect(origin.x() - 100, origin.y() + 20, 1000, 1), 0, 2, 3, 2);
2552 TestIterateAll(
2553 data, gfx::Rect(origin.x() + 29, origin.y() - 100, 31, 1000), 2, 0, 3, 2);
2554 // Nonintersecting.
2555 TestIterateAll(data,
2556 gfx::Rect(origin.x() + 60, origin.y() + 80, 100, 100),
2560 -1);
2563 TEST_P(TilingDataTest, BordersIteratorOneBorderTexel) {
2564 gfx::Point origin = GetParam();
2566 TilingData data(
2567 gfx::Size(10, 20), gfx::Rect(origin, gfx::Size(25, 45)), true);
2568 // The following Coordinates are relative to the origin.
2569 // X border index by src coord: [0-10), [8-18), [16-25)
2570 // Y border index by src coord: [0-20), [18-38), [36-45)
2571 TestIterateBorders(
2572 data, gfx::Rect(origin.x(), origin.y(), 25, 45), 0, 0, 2, 2);
2573 TestIterateBorders(
2574 data, gfx::Rect(origin.x() + 18, origin.y() + 19, 3, 17), 2, 0, 2, 1);
2575 TestIterateBorders(
2576 data, gfx::Rect(origin.x() + 10, origin.y() + 20, 6, 16), 1, 1, 1, 1);
2577 TestIterateBorders(
2578 data, gfx::Rect(origin.x() + 9, origin.y() + 19, 8, 18), 0, 0, 2, 2);
2579 // Oversized.
2580 TestIterateBorders(data,
2581 gfx::Rect(origin.x() - 100, origin.y() - 100, 1000, 1000),
2586 TestIterateBorders(
2587 data, gfx::Rect(origin.x() - 100, origin.y() + 20, 1000, 1), 0, 1, 2, 1);
2588 TestIterateBorders(
2589 data, gfx::Rect(origin.x() + 18, origin.y() - 100, 6, 1000), 2, 0, 2, 2);
2590 // Nonintersecting.
2591 TestIterateBorders(data,
2592 gfx::Rect(origin.x() + 60, origin.y() + 80, 100, 100),
2596 -1);
2599 TEST_P(TilingDataTest, NoBordersIteratorOneBorderTexel) {
2600 gfx::Point origin = GetParam();
2602 TilingData data(
2603 gfx::Size(10, 20), gfx::Rect(origin, gfx::Size(25, 45)), true);
2604 // The following Coordinates are relative to the origin.
2605 // X index by src coord: [0-9), [9-17), [17-25)
2606 // Y index by src coord: [0-19), [19-37), [37-45)
2607 TestIterateNoBorders(
2608 data, gfx::Rect(origin.x(), origin.y(), 25, 45), 0, 0, 2, 2);
2609 TestIterateNoBorders(
2610 data, gfx::Rect(origin.x() + 17, origin.y() + 19, 3, 18), 2, 1, 2, 1);
2611 TestIterateNoBorders(
2612 data, gfx::Rect(origin.x() + 17, origin.y() + 19, 3, 19), 2, 1, 2, 2);
2613 TestIterateNoBorders(
2614 data, gfx::Rect(origin.x() + 8, origin.y() + 18, 9, 19), 0, 0, 1, 1);
2615 TestIterateNoBorders(
2616 data, gfx::Rect(origin.x() + 9, origin.y() + 19, 9, 19), 1, 1, 2, 2);
2617 // Oversized.
2618 TestIterateNoBorders(
2619 data,
2620 gfx::Rect(origin.x() - 100, origin.y() - 100, 1000, 1000),
2625 TestIterateNoBorders(
2626 data, gfx::Rect(origin.x() - 100, origin.y() + 20, 1000, 1), 0, 1, 2, 1);
2627 TestIterateNoBorders(
2628 data, gfx::Rect(origin.x() + 18, origin.y() - 100, 6, 1000), 2, 0, 2, 2);
2629 // Nonintersecting.
2630 TestIterateNoBorders(data,
2631 gfx::Rect(origin.x() + 60, origin.y() + 80, 100, 100),
2635 -1);
2638 TEST_P(TilingDataTest, BordersIteratorManyBorderTexels) {
2639 gfx::Point origin = GetParam();
2641 TilingData data(gfx::Size(50, 60), gfx::Rect(origin, gfx::Size(65, 110)), 20);
2642 // The following Coordinates are relative to the origin.
2643 // X border index by src coord: [0-50), [10-60), [20-65)
2644 // Y border index by src coord: [0-60), [20-80), [40-100), [60-110)
2645 TestIterateBorders(
2646 data, gfx::Rect(origin.x(), origin.y(), 65, 110), 0, 0, 2, 3);
2647 TestIterateBorders(
2648 data, gfx::Rect(origin.x() + 50, origin.y() + 60, 15, 65), 1, 1, 2, 3);
2649 TestIterateBorders(
2650 data, gfx::Rect(origin.x() + 60, origin.y() + 30, 2, 10), 2, 0, 2, 1);
2651 // Oversized.
2652 TestIterateBorders(data,
2653 gfx::Rect(origin.x() - 100, origin.y() - 100, 1000, 1000),
2658 TestIterateBorders(
2659 data, gfx::Rect(origin.x() - 100, origin.y() + 10, 1000, 10), 0, 0, 2, 0);
2660 TestIterateBorders(
2661 data, gfx::Rect(origin.x() + 10, origin.y() - 100, 10, 1000), 0, 0, 1, 3);
2662 // Nonintersecting.
2663 TestIterateBorders(data,
2664 gfx::Rect(origin.x() + 65, origin.y() + 110, 100, 100),
2668 -1);
2671 TEST_P(TilingDataTest, NoBordersIteratorManyBorderTexels) {
2672 gfx::Point origin = GetParam();
2674 TilingData data(gfx::Size(50, 60), gfx::Rect(origin, gfx::Size(65, 110)), 20);
2675 // The following Coordinates are relative to the origin.
2676 // X index by src coord: [0-30), [30-40), [40, 65)
2677 // Y index by src coord: [0-40), [40-60), [60, 80), [80-110)
2678 TestIterateNoBorders(
2679 data, gfx::Rect(origin.x(), origin.y(), 65, 110), 0, 0, 2, 3);
2680 TestIterateNoBorders(
2681 data, gfx::Rect(origin.x() + 30, origin.y() + 40, 15, 65), 1, 1, 2, 3);
2682 TestIterateNoBorders(
2683 data, gfx::Rect(origin.x() + 60, origin.y() + 20, 2, 21), 2, 0, 2, 1);
2684 // Oversized.
2685 TestIterateNoBorders(
2686 data,
2687 gfx::Rect(origin.x() - 100, origin.y() - 100, 1000, 1000),
2692 TestIterateNoBorders(
2693 data, gfx::Rect(origin.x() - 100, origin.y() + 10, 1000, 10), 0, 0, 2, 0);
2694 TestIterateNoBorders(
2695 data, gfx::Rect(origin.x() + 10, origin.y() - 100, 10, 1000), 0, 0, 0, 3);
2696 // Nonintersecting.
2697 TestIterateNoBorders(data,
2698 gfx::Rect(origin.x() + 65, origin.y() + 110, 100, 100),
2702 -1);
2705 TEST_P(TilingDataTest, IteratorOneTile) {
2706 gfx::Point origin = GetParam();
2708 TilingData no_border(
2709 gfx::Size(1000, 1000), gfx::Rect(origin, gfx::Size(30, 40)), false);
2710 TestIterateAll(
2711 no_border, gfx::Rect(origin.x(), origin.y(), 30, 40), 0, 0, 0, 0);
2712 TestIterateAll(no_border,
2713 gfx::Rect(origin.x() + 10, origin.y() + 10, 20, 20),
2718 TestIterateAll(no_border,
2719 gfx::Rect(origin.x() + 30, origin.y() + 40, 100, 100),
2723 -1);
2725 TilingData one_border(
2726 gfx::Size(1000, 1000), gfx::Rect(origin, gfx::Size(30, 40)), true);
2727 TestIterateAll(
2728 one_border, gfx::Rect(origin.x(), origin.y(), 30, 40), 0, 0, 0, 0);
2729 TestIterateAll(one_border,
2730 gfx::Rect(origin.x() + 10, origin.y() + 10, 20, 20),
2735 TestIterateAll(one_border,
2736 gfx::Rect(origin.x() + 30, origin.y() + 40, 100, 100),
2740 -1);
2742 TilingData big_border(
2743 gfx::Size(1000, 1000), gfx::Rect(origin, gfx::Size(30, 40)), 50);
2744 TestIterateAll(
2745 big_border, gfx::Rect(origin.x(), origin.y(), 30, 40), 0, 0, 0, 0);
2746 TestIterateAll(big_border,
2747 gfx::Rect(origin.x() + 10, origin.y() + 10, 20, 20),
2752 TestIterateAll(big_border,
2753 gfx::Rect(origin.x() + 30, origin.y() + 40, 100, 100),
2757 -1);
2760 TEST(TilingDataTest, IteratorNoTiles) {
2761 TilingData data(gfx::Size(100, 100), gfx::Rect(), false);
2762 TestIterateAll(data, gfx::Rect(0, 0, 100, 100), 0, 0, -1, -1);
2765 void TestDiff(
2766 const TilingData& data,
2767 gfx::Rect consider,
2768 gfx::Rect ignore,
2769 size_t num_tiles) {
2771 std::vector<std::pair<int, int> > expected;
2772 for (int y = 0; y < data.num_tiles_y(); ++y) {
2773 for (int x = 0; x < data.num_tiles_x(); ++x) {
2774 gfx::Rect bounds = data.TileBoundsWithBorder(x, y);
2775 if (bounds.Intersects(consider) && !bounds.Intersects(ignore))
2776 expected.push_back(std::make_pair(x, y));
2780 // Sanity check the test.
2781 EXPECT_EQ(num_tiles, expected.size());
2783 for (TilingData::DifferenceIterator iter(&data, consider, ignore);
2784 iter; ++iter) {
2785 bool found = false;
2786 for (size_t i = 0; i < expected.size(); ++i) {
2787 if (expected[i] == iter.index()) {
2788 expected[i] = expected.back();
2789 expected.pop_back();
2790 found = true;
2791 break;
2794 EXPECT_TRUE(found);
2796 EXPECT_EQ(0u, expected.size());
2799 TEST_P(TilingDataTest, DifferenceIteratorIgnoreGeometry) {
2800 // This test is checking that the iterator can handle different geometries of
2801 // ignore rects relative to the consider rect. The consider rect indices
2802 // themselves are mostly tested by the non-difference iterator tests, so the
2803 // full rect is mostly used here for simplicity.
2805 gfx::Point origin = GetParam();
2807 // The following Coordinates are relative to the origin.
2808 // X border index by src coord: [0-10), [10-20), [20, 30), [30, 40)
2809 // Y border index by src coord: [0-10), [10-20), [20, 25)
2810 TilingData data(
2811 gfx::Size(10, 10), gfx::Rect(origin, gfx::Size(40, 25)), false);
2813 // Fully ignored
2814 TestDiff(data,
2815 gfx::Rect(origin.x(), origin.y(), 40, 25),
2816 gfx::Rect(origin.x(), origin.y(), 40, 25),
2818 TestDiff(data,
2819 gfx::Rect(origin.x(), origin.y(), 40, 25),
2820 gfx::Rect(origin.x() - 100, origin.y() - 100, 200, 200),
2822 TestDiff(data,
2823 gfx::Rect(origin.x(), origin.y(), 40, 25),
2824 gfx::Rect(origin.x() + 9, origin.y() + 9, 30, 15),
2826 TestDiff(data,
2827 gfx::Rect(origin.x() + 15, origin.y() + 15, 8, 8),
2828 gfx::Rect(origin.x() + 15, origin.y() + 15, 8, 8),
2831 // Fully un-ignored
2832 TestDiff(data,
2833 gfx::Rect(origin.x(), origin.y(), 40, 25),
2834 gfx::Rect(origin.x() - 30, origin.y() - 20, 8, 8),
2835 12);
2836 TestDiff(data, gfx::Rect(origin.x(), origin.y(), 40, 25), gfx::Rect(), 12);
2838 // Top left, remove 2x2 tiles
2839 TestDiff(data,
2840 gfx::Rect(origin.x(), origin.y(), 40, 25),
2841 gfx::Rect(origin.x(), origin.y(), 20, 19),
2843 // Bottom right, remove 2x2 tiles
2844 TestDiff(data,
2845 gfx::Rect(origin.x(), origin.y(), 40, 25),
2846 gfx::Rect(origin.x() + 20, origin.y() + 15, 20, 6),
2848 // Bottom left, remove 2x2 tiles
2849 TestDiff(data,
2850 gfx::Rect(origin.x(), origin.y(), 40, 25),
2851 gfx::Rect(origin.x(), origin.y() + 15, 20, 6),
2853 // Top right, remove 2x2 tiles
2854 TestDiff(data,
2855 gfx::Rect(origin.x(), origin.y(), 40, 25),
2856 gfx::Rect(origin.x() + 20, origin.y(), 20, 19),
2858 // Center, remove only one tile
2859 TestDiff(data,
2860 gfx::Rect(origin.x(), origin.y(), 40, 25),
2861 gfx::Rect(origin.x() + 10, origin.y() + 10, 5, 5),
2862 11);
2864 // Left column, flush left, removing two columns
2865 TestDiff(data,
2866 gfx::Rect(origin.x(), origin.y(), 40, 25),
2867 gfx::Rect(origin.x(), origin.y(), 11, 25),
2869 // Middle column, removing two columns
2870 TestDiff(data,
2871 gfx::Rect(origin.x(), origin.y(), 40, 25),
2872 gfx::Rect(origin.x() + 11, origin.y(), 11, 25),
2874 // Right column, flush right, removing one column
2875 TestDiff(data,
2876 gfx::Rect(origin.x(), origin.y(), 40, 25),
2877 gfx::Rect(origin.x() + 30, origin.y(), 2, 25),
2880 // Top row, flush top, removing one row
2881 TestDiff(data,
2882 gfx::Rect(origin.x(), origin.y(), 40, 25),
2883 gfx::Rect(origin.x(), origin.y() + 5, 40, 5),
2885 // Middle row, removing one row
2886 TestDiff(data,
2887 gfx::Rect(origin.x(), origin.y(), 40, 25),
2888 gfx::Rect(origin.x(), origin.y() + 13, 40, 5),
2890 // Bottom row, flush bottom, removing two rows
2891 TestDiff(data,
2892 gfx::Rect(origin.x(), origin.y(), 40, 25),
2893 gfx::Rect(origin.x(), origin.y() + 13, 40, 12),
2896 // Non-intersecting, but still touching two of the same tiles.
2897 TestDiff(data,
2898 gfx::Rect(origin.x() + 8, origin.y(), 32, 25),
2899 gfx::Rect(origin.x(), origin.y() + 12, 5, 12),
2900 10);
2902 // Intersecting, but neither contains the other. 2x3 with one overlap.
2903 TestDiff(data,
2904 gfx::Rect(origin.x() + 5, origin.y() + 2, 20, 10),
2905 gfx::Rect(origin.x() + 25, origin.y() + 15, 5, 10),
2909 TEST_P(TilingDataTest, DifferenceIteratorManyBorderTexels) {
2910 gfx::Point origin = GetParam();
2912 // The following Coordinates are relative to the origin.
2913 // X border index by src coord: [0-50), [10-60), [20-65)
2914 // Y border index by src coord: [0-60), [20-80), [40-100), [60-110)
2915 TilingData data(gfx::Size(50, 60), gfx::Rect(origin, gfx::Size(65, 110)), 20);
2917 // Ignore one column, three rows
2918 TestDiff(data,
2919 gfx::Rect(origin.x(), origin.y() + 30, 55, 80),
2920 gfx::Rect(origin.x() + 5, origin.y() + 30, 5, 15),
2923 // Knock out three columns, leaving only one.
2924 TestDiff(data,
2925 gfx::Rect(origin.x() + 10, origin.y() + 30, 55, 80),
2926 gfx::Rect(origin.x() + 30, origin.y() + 59, 20, 1),
2929 // Overlap all tiles with ignore rect.
2930 TestDiff(data,
2931 gfx::Rect(origin.x(), origin.y(), 65, 110),
2932 gfx::Rect(origin.x() + 30, origin.y() + 59, 1, 2),
2936 TEST_P(TilingDataTest, DifferenceIteratorOneTile) {
2937 gfx::Point origin = GetParam();
2939 TilingData no_border(
2940 gfx::Size(1000, 1000), gfx::Rect(origin, gfx::Size(30, 40)), false);
2941 TestDiff(
2942 no_border, gfx::Rect(origin.x(), origin.y(), 30, 40), gfx::Rect(), 1);
2943 TestDiff(no_border,
2944 gfx::Rect(origin.x() + 5, origin.y() + 5, 100, 100),
2945 gfx::Rect(origin.x() + 5, origin.y() + 5, 1, 1),
2948 TilingData one_border(
2949 gfx::Size(1000, 1000), gfx::Rect(origin, gfx::Size(30, 40)), true);
2950 TestDiff(
2951 one_border, gfx::Rect(origin.x(), origin.y(), 30, 40), gfx::Rect(), 1);
2952 TestDiff(one_border,
2953 gfx::Rect(origin.x() + 5, origin.y() + 5, 100, 100),
2954 gfx::Rect(origin.x() + 5, origin.y() + 5, 1, 1),
2957 TilingData big_border(
2958 gfx::Size(1000, 1000), gfx::Rect(origin, gfx::Size(30, 40)), 50);
2959 TestDiff(
2960 big_border, gfx::Rect(origin.x(), origin.y(), 30, 40), gfx::Rect(), 1);
2961 TestDiff(big_border,
2962 gfx::Rect(origin.x() + 5, origin.y() + 5, 100, 100),
2963 gfx::Rect(origin.x() + 5, origin.y() + 5, 1, 1),
2967 TEST(TilingDataTest, DifferenceIteratorNoTiles) {
2968 TilingData data(gfx::Size(100, 100), gfx::Rect(), false);
2969 TestDiff(data, gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 5, 5), 0);
2972 void TestSpiralIterate(int source_line_number,
2973 const TilingData& tiling_data,
2974 const gfx::Rect& consider,
2975 const gfx::Rect& ignore,
2976 const gfx::Rect& center,
2977 const std::vector<std::pair<int, int> >& expected) {
2978 std::vector<std::pair<int, int> > actual;
2979 for (TilingData::SpiralDifferenceIterator it(
2980 &tiling_data, consider, ignore, center);
2982 ++it) {
2983 actual.push_back(it.index());
2986 EXPECT_EQ(expected.size(), actual.size()) << "error from line "
2987 << source_line_number;
2988 for (size_t i = 0; i < std::min(expected.size(), actual.size()); ++i) {
2989 EXPECT_EQ(expected[i].first, actual[i].first)
2990 << "i: " << i << " error from line: " << source_line_number;
2991 EXPECT_EQ(expected[i].second, actual[i].second)
2992 << "i: " << i << " error from line: " << source_line_number;
2996 TEST_P(TilingDataTest, SpiralDifferenceIteratorNoIgnoreFullConsider) {
2997 gfx::Point origin = GetParam();
2998 TilingData tiling_data(
2999 gfx::Size(10, 10), gfx::Rect(origin, gfx::Size(30, 30)), false);
3000 gfx::Rect consider(origin.x(), origin.y(), 30, 30);
3001 gfx::Rect ignore;
3002 std::vector<std::pair<int, int> > expected;
3004 // Center is in the center of the tiling.
3005 gfx::Rect center(origin.x() + 15, origin.y() + 15, 1, 1);
3007 // Layout of the tiling data, and expected return order:
3008 // x 0 1 2
3009 // y.------
3010 // 0| 4 3 2
3011 // 1| 5 * 1
3012 // 2| 6 7 8
3013 expected.push_back(std::make_pair(2, 1));
3014 expected.push_back(std::make_pair(2, 0));
3015 expected.push_back(std::make_pair(1, 0));
3016 expected.push_back(std::make_pair(0, 0));
3017 expected.push_back(std::make_pair(0, 1));
3018 expected.push_back(std::make_pair(0, 2));
3019 expected.push_back(std::make_pair(1, 2));
3020 expected.push_back(std::make_pair(2, 2));
3022 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3024 // Center is off to the right side of the tiling (and far away).
3025 center = gfx::Rect(origin.x() + 100, origin.y() + 15, 1, 1);
3027 // Layout of the tiling data, and expected return order:
3028 // x 0 1 2
3029 // y.------
3030 // 0| 7 4 1
3031 // 1| 8 5 2 *
3032 // 2| 9 6 3
3033 expected.clear();
3034 expected.push_back(std::make_pair(2, 0));
3035 expected.push_back(std::make_pair(2, 1));
3036 expected.push_back(std::make_pair(2, 2));
3037 expected.push_back(std::make_pair(1, 0));
3038 expected.push_back(std::make_pair(1, 1));
3039 expected.push_back(std::make_pair(1, 2));
3040 expected.push_back(std::make_pair(0, 0));
3041 expected.push_back(std::make_pair(0, 1));
3042 expected.push_back(std::make_pair(0, 2));
3044 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3046 // Center is the bottom right corner of the tiling.
3047 center = gfx::Rect(origin.x() + 25, origin.y() + 25, 1, 1);
3049 // Layout of the tiling data, and expected return order:
3050 // x 0 1 2
3051 // y.------
3052 // 0| 6 5 4
3053 // 1| 7 2 1
3054 // 2| 8 3 *
3055 expected.clear();
3056 expected.push_back(std::make_pair(2, 1));
3057 expected.push_back(std::make_pair(1, 1));
3058 expected.push_back(std::make_pair(1, 2));
3059 expected.push_back(std::make_pair(2, 0));
3060 expected.push_back(std::make_pair(1, 0));
3061 expected.push_back(std::make_pair(0, 0));
3062 expected.push_back(std::make_pair(0, 1));
3063 expected.push_back(std::make_pair(0, 2));
3065 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3067 // Center is off the top left side of the tiling.
3068 center = gfx::Rect(origin.x() - 60, origin.y() - 50, 1, 1);
3070 // Layout of the tiling data, and expected return order:
3071 // * x 0 1 2
3072 // y.------
3073 // 0| 1 2 6
3074 // 1| 3 4 5
3075 // 2| 7 8 9
3076 expected.clear();
3077 expected.push_back(std::make_pair(0, 0));
3078 expected.push_back(std::make_pair(1, 0));
3079 expected.push_back(std::make_pair(0, 1));
3080 expected.push_back(std::make_pair(1, 1));
3081 expected.push_back(std::make_pair(2, 1));
3082 expected.push_back(std::make_pair(2, 0));
3083 expected.push_back(std::make_pair(0, 2));
3084 expected.push_back(std::make_pair(1, 2));
3085 expected.push_back(std::make_pair(2, 2));
3087 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3089 // Two tile center.
3090 center = gfx::Rect(origin.x() + 15, origin.y() + 15, 1, 10);
3092 // Layout of the tiling data, and expected return order:
3093 // x 0 1 2
3094 // y.------
3095 // 0| 5 4 3
3096 // 1| 6 * 2
3097 // 2| 7 * 1
3098 expected.clear();
3099 expected.push_back(std::make_pair(2, 2));
3100 expected.push_back(std::make_pair(2, 1));
3101 expected.push_back(std::make_pair(2, 0));
3102 expected.push_back(std::make_pair(1, 0));
3103 expected.push_back(std::make_pair(0, 0));
3104 expected.push_back(std::make_pair(0, 1));
3105 expected.push_back(std::make_pair(0, 2));
3107 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3110 TEST_P(TilingDataTest, SpiralDifferenceIteratorSmallConsider) {
3111 gfx::Point origin = GetParam();
3112 TilingData tiling_data(
3113 gfx::Size(10, 10), gfx::Rect(origin, gfx::Size(50, 50)), false);
3114 gfx::Rect ignore;
3115 std::vector<std::pair<int, int> > expected;
3116 gfx::Rect center(origin.x() + 15, origin.y() + 15, 1, 1);
3118 // Consider is one cell.
3119 gfx::Rect consider(origin.x(), origin.y(), 1, 1);
3121 // Layout of the tiling data, and expected return order:
3122 // x 0 1 2 3 4
3123 // y.----------
3124 // 0| 1
3125 // 1| *
3126 // 2|
3127 // 3|
3128 // 4|
3129 expected.push_back(std::make_pair(0, 0));
3131 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3133 // Consider is bottom right corner.
3134 consider = gfx::Rect(origin.x() + 25, origin.y() + 25, 10, 10);
3136 // Layout of the tiling data, and expected return order:
3137 // x 0 1 2 3 4
3138 // y.----------
3139 // 0|
3140 // 1| *
3141 // 2| 1 2
3142 // 3| 3 4
3143 // 4|
3144 expected.clear();
3145 expected.push_back(std::make_pair(2, 2));
3146 expected.push_back(std::make_pair(3, 2));
3147 expected.push_back(std::make_pair(2, 3));
3148 expected.push_back(std::make_pair(3, 3));
3150 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3152 // Consider is one column.
3153 consider = gfx::Rect(origin.x() + 11, origin.y(), 1, 100);
3155 // Layout of the tiling data, and expected return order:
3156 // x 0 1 2 3 4
3157 // y.----------
3158 // 0| 2
3159 // 1| *
3160 // 2| 3
3161 // 3| 4
3162 // 4| 5
3163 expected.clear();
3164 expected.push_back(std::make_pair(1, 0));
3165 expected.push_back(std::make_pair(1, 2));
3166 expected.push_back(std::make_pair(1, 3));
3167 expected.push_back(std::make_pair(1, 4));
3169 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3172 TEST_P(TilingDataTest, SpiralDifferenceIteratorHasIgnore) {
3173 gfx::Point origin = GetParam();
3174 TilingData tiling_data(
3175 gfx::Size(10, 10), gfx::Rect(origin, gfx::Size(50, 50)), false);
3176 gfx::Rect consider(origin.x(), origin.y(), 50, 50);
3177 std::vector<std::pair<int, int> > expected;
3178 gfx::Rect center(origin.x() + 15, origin.y() + 15, 1, 1);
3180 // Full ignore.
3181 gfx::Rect ignore(origin.x(), origin.y(), 50, 50);
3183 // Layout of the tiling data, and expected return order:
3184 // x 0 1 2 3 4
3185 // y.----------
3186 // 0| . . . . .
3187 // 1| . * . . .
3188 // 2| . . . . .
3189 // 3| . . . . .
3190 // 4| . . . . .
3191 expected.clear();
3193 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3195 // 3 column ignore.
3196 ignore = gfx::Rect(origin.x() + 15, origin.y(), 20, 100);
3198 // Layout of the tiling data, and expected return order:
3199 // x 0 1 2 3 4
3200 // y.----------
3201 // 0| 1 . . . 8
3202 // 1| 2 * . . 7
3203 // 2| 3 . . . 6
3204 // 3| 4 . . . 5
3205 // 4| 9 . . . 10
3206 expected.clear();
3208 expected.push_back(std::make_pair(0, 0));
3209 expected.push_back(std::make_pair(0, 1));
3210 expected.push_back(std::make_pair(0, 2));
3211 expected.push_back(std::make_pair(0, 3));
3212 expected.push_back(std::make_pair(4, 3));
3213 expected.push_back(std::make_pair(4, 2));
3214 expected.push_back(std::make_pair(4, 1));
3215 expected.push_back(std::make_pair(4, 0));
3216 expected.push_back(std::make_pair(0, 4));
3217 expected.push_back(std::make_pair(4, 4));
3219 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3221 // Ignore covers the top half.
3222 ignore = gfx::Rect(origin.x(), origin.y(), 50, 25);
3224 // Layout of the tiling data, and expected return order:
3225 // x 0 1 2 3 4
3226 // y.----------
3227 // 0| . . . . .
3228 // 1| . * . . .
3229 // 2| . . . . .
3230 // 3| 1 2 3 4 5
3231 // 4| 6 7 8 9 10
3232 expected.clear();
3234 expected.push_back(std::make_pair(0, 3));
3235 expected.push_back(std::make_pair(1, 3));
3236 expected.push_back(std::make_pair(2, 3));
3237 expected.push_back(std::make_pair(3, 3));
3238 expected.push_back(std::make_pair(4, 3));
3239 expected.push_back(std::make_pair(0, 4));
3240 expected.push_back(std::make_pair(1, 4));
3241 expected.push_back(std::make_pair(2, 4));
3242 expected.push_back(std::make_pair(3, 4));
3243 expected.push_back(std::make_pair(4, 4));
3245 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3248 TEST_P(TilingDataTest, SpiralDifferenceIteratorRectangleCenter) {
3249 gfx::Point origin = GetParam();
3250 TilingData tiling_data(
3251 gfx::Size(10, 10), gfx::Rect(origin, gfx::Size(50, 50)), false);
3252 gfx::Rect consider(origin.x(), origin.y(), 50, 50);
3253 std::vector<std::pair<int, int> > expected;
3254 gfx::Rect ignore;
3256 // Two cell center
3257 gfx::Rect center(origin.x() + 25, origin.y() + 25, 1, 10);
3259 // Layout of the tiling data, and expected return order:
3260 // x 0 1 2 3 4
3261 // y.----------
3262 // 0| J I H G F
3263 // 1| K 5 4 3 E
3264 // 2| L 6 * 2 D
3265 // 3| M 7 * 1 C
3266 // 4| N 8 9 A B
3267 expected.clear();
3269 expected.push_back(std::make_pair(3, 3));
3270 expected.push_back(std::make_pair(3, 2));
3271 expected.push_back(std::make_pair(3, 1));
3272 expected.push_back(std::make_pair(2, 1));
3273 expected.push_back(std::make_pair(1, 1));
3274 expected.push_back(std::make_pair(1, 2));
3275 expected.push_back(std::make_pair(1, 3));
3276 expected.push_back(std::make_pair(1, 4));
3277 expected.push_back(std::make_pair(2, 4));
3278 expected.push_back(std::make_pair(3, 4));
3279 expected.push_back(std::make_pair(4, 4));
3280 expected.push_back(std::make_pair(4, 3));
3281 expected.push_back(std::make_pair(4, 2));
3282 expected.push_back(std::make_pair(4, 1));
3283 expected.push_back(std::make_pair(4, 0));
3284 expected.push_back(std::make_pair(3, 0));
3285 expected.push_back(std::make_pair(2, 0));
3286 expected.push_back(std::make_pair(1, 0));
3287 expected.push_back(std::make_pair(0, 0));
3288 expected.push_back(std::make_pair(0, 1));
3289 expected.push_back(std::make_pair(0, 2));
3290 expected.push_back(std::make_pair(0, 3));
3291 expected.push_back(std::make_pair(0, 4));
3293 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3295 // Three by two center.
3296 center = gfx::Rect(origin.x() + 15, origin.y() + 25, 20, 10);
3298 // Layout of the tiling data, and expected return order:
3299 // x 0 1 2 3 4
3300 // y.----------
3301 // 0| J I H G F
3302 // 1| 7 6 5 4 3
3303 // 2| 8 * * * 2
3304 // 3| 9 * * * 1
3305 // 4| A B C D E
3306 expected.clear();
3308 expected.push_back(std::make_pair(4, 3));
3309 expected.push_back(std::make_pair(4, 2));
3310 expected.push_back(std::make_pair(4, 1));
3311 expected.push_back(std::make_pair(3, 1));
3312 expected.push_back(std::make_pair(2, 1));
3313 expected.push_back(std::make_pair(1, 1));
3314 expected.push_back(std::make_pair(0, 1));
3315 expected.push_back(std::make_pair(0, 2));
3316 expected.push_back(std::make_pair(0, 3));
3317 expected.push_back(std::make_pair(0, 4));
3318 expected.push_back(std::make_pair(1, 4));
3319 expected.push_back(std::make_pair(2, 4));
3320 expected.push_back(std::make_pair(3, 4));
3321 expected.push_back(std::make_pair(4, 4));
3322 expected.push_back(std::make_pair(4, 0));
3323 expected.push_back(std::make_pair(3, 0));
3324 expected.push_back(std::make_pair(2, 0));
3325 expected.push_back(std::make_pair(1, 0));
3326 expected.push_back(std::make_pair(0, 0));
3328 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3330 // Column center off the left side.
3331 center = gfx::Rect(origin.x() - 50, origin.y(), 30, 50);
3333 // Layout of the tiling data, and expected return order:
3334 // x 0 1 2 3 4
3335 // y.----------
3336 // * 0| 5 A F K P
3337 // * 1| 4 9 E J O
3338 // * 2| 3 8 D I N
3339 // * 3| 2 7 C H M
3340 // * 4| 1 6 B G L
3341 expected.clear();
3343 expected.push_back(std::make_pair(0, 4));
3344 expected.push_back(std::make_pair(0, 3));
3345 expected.push_back(std::make_pair(0, 2));
3346 expected.push_back(std::make_pair(0, 1));
3347 expected.push_back(std::make_pair(0, 0));
3348 expected.push_back(std::make_pair(1, 4));
3349 expected.push_back(std::make_pair(1, 3));
3350 expected.push_back(std::make_pair(1, 2));
3351 expected.push_back(std::make_pair(1, 1));
3352 expected.push_back(std::make_pair(1, 0));
3353 expected.push_back(std::make_pair(2, 4));
3354 expected.push_back(std::make_pair(2, 3));
3355 expected.push_back(std::make_pair(2, 2));
3356 expected.push_back(std::make_pair(2, 1));
3357 expected.push_back(std::make_pair(2, 0));
3358 expected.push_back(std::make_pair(3, 4));
3359 expected.push_back(std::make_pair(3, 3));
3360 expected.push_back(std::make_pair(3, 2));
3361 expected.push_back(std::make_pair(3, 1));
3362 expected.push_back(std::make_pair(3, 0));
3363 expected.push_back(std::make_pair(4, 4));
3364 expected.push_back(std::make_pair(4, 3));
3365 expected.push_back(std::make_pair(4, 2));
3366 expected.push_back(std::make_pair(4, 1));
3367 expected.push_back(std::make_pair(4, 0));
3369 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3372 TEST_P(TilingDataTest, SpiralDifferenceIteratorEdgeCases) {
3373 gfx::Point origin = GetParam();
3374 TilingData tiling_data(
3375 gfx::Size(10, 10), gfx::Rect(origin, gfx::Size(30, 30)), false);
3376 std::vector<std::pair<int, int> > expected;
3377 gfx::Rect center;
3378 gfx::Rect consider;
3379 gfx::Rect ignore;
3381 // Ignore contains, but is not equal to, consider and center.
3382 ignore = gfx::Rect(origin.x() + 15, origin.y(), 20, 30);
3383 consider = gfx::Rect(origin.x() + 20, origin.y() + 10, 10, 20);
3384 center = gfx::Rect(origin.x() + 25, origin.y(), 5, 5);
3386 // Layout of the tiling data, and expected return order:
3387 // x 0 1 2
3388 // y.------
3389 // 0| . *
3390 // 1| . .
3391 // 2| . .
3392 expected.clear();
3394 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3396 // Center intersects with consider.
3397 ignore = gfx::Rect();
3398 center = gfx::Rect(origin.x(), origin.y() + 15, 30, 15);
3399 consider = gfx::Rect(origin.x(), origin.y(), 15, 30);
3401 // Layout of the tiling data, and expected return order:
3402 // x 0 1 2
3403 // y.------
3404 // 0| 2 1
3405 // 1| * * *
3406 // 2| * * *
3407 expected.clear();
3409 expected.push_back(std::make_pair(1, 0));
3410 expected.push_back(std::make_pair(0, 0));
3412 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3414 // Consider and ignore are non-intersecting.
3415 ignore = gfx::Rect(origin.x(), origin.y(), 5, 30);
3416 consider = gfx::Rect(origin.x() + 25, origin.y(), 5, 30);
3417 center = gfx::Rect(origin.x() + 15, origin.y(), 1, 1);
3419 // Layout of the tiling data, and expected return order:
3420 // x 0 1 2
3421 // y.------
3422 // 0| . * 1
3423 // 1| . 2
3424 // 2| . 3
3425 expected.clear();
3427 expected.push_back(std::make_pair(2, 0));
3428 expected.push_back(std::make_pair(2, 1));
3429 expected.push_back(std::make_pair(2, 2));
3431 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3433 // Center intersects with ignore.
3434 consider = gfx::Rect(origin.x(), origin.y(), 30, 30);
3435 center = gfx::Rect(origin.x() + 15, origin.y(), 1, 30);
3436 ignore = gfx::Rect(origin.x(), origin.y() + 15, 30, 1);
3438 // Layout of the tiling data, and expected return order:
3439 // x 0 1 2
3440 // y.------
3441 // 0| 3 * 2
3442 // 1| . * .
3443 // 2| 4 * 1
3444 expected.clear();
3446 expected.push_back(std::make_pair(2, 2));
3447 expected.push_back(std::make_pair(2, 0));
3448 expected.push_back(std::make_pair(0, 0));
3449 expected.push_back(std::make_pair(0, 2));
3451 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3453 // Center and ignore are the same.
3454 consider = gfx::Rect(origin.x(), origin.y(), 30, 30);
3455 center = gfx::Rect(origin.x() + 15, origin.y(), 1, 30);
3456 ignore = center;
3458 // Layout of the tiling data, and expected return order:
3459 // x 0 1 2
3460 // y.------
3461 // 0| 4 * 3
3462 // 1| 5 * 2
3463 // 2| 6 * 1
3464 expected.clear();
3466 expected.push_back(std::make_pair(2, 2));
3467 expected.push_back(std::make_pair(2, 1));
3468 expected.push_back(std::make_pair(2, 0));
3469 expected.push_back(std::make_pair(0, 0));
3470 expected.push_back(std::make_pair(0, 1));
3471 expected.push_back(std::make_pair(0, 2));
3473 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3475 // Empty tiling data.
3476 TilingData empty_data(gfx::Size(0, 0), gfx::Rect(0, 0, 0, 0), false);
3478 expected.clear();
3479 TestSpiralIterate(__LINE__, empty_data, consider, ignore, center, expected);
3481 // Empty consider.
3482 ignore = gfx::Rect();
3483 center = gfx::Rect(1, 1, 1, 1);
3484 consider = gfx::Rect();
3486 expected.clear();
3487 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3489 // Empty center. Note: This arbitrarily puts the center to be off the top-left
3490 // corner.
3491 consider = gfx::Rect(origin.x(), origin.y(), 30, 30);
3492 ignore = gfx::Rect();
3493 center = gfx::Rect();
3495 // Layout of the tiling data, and expected return order:
3496 // * x 0 1 2
3497 // y.------
3498 // 0| 1 2 6
3499 // 1| 3 4 5
3500 // 2| 7 8 9
3501 expected.clear();
3503 expected.push_back(std::make_pair(0, 0));
3504 expected.push_back(std::make_pair(1, 0));
3505 expected.push_back(std::make_pair(0, 1));
3506 expected.push_back(std::make_pair(1, 1));
3507 expected.push_back(std::make_pair(2, 1));
3508 expected.push_back(std::make_pair(2, 0));
3509 expected.push_back(std::make_pair(0, 2));
3510 expected.push_back(std::make_pair(1, 2));
3511 expected.push_back(std::make_pair(2, 2));
3513 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3515 // Every rect is empty.
3516 ignore = gfx::Rect();
3517 center = gfx::Rect();
3518 consider = gfx::Rect();
3520 expected.clear();
3521 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3523 // Center is just to the left of cover, and off of the tiling's left side.
3524 consider = gfx::Rect(origin.x(), origin.y(), 30, 30);
3525 ignore = gfx::Rect();
3526 center = gfx::Rect(origin.x() - 20, origin.y(), 19, 30);
3528 // Layout of the tiling data, and expected return order:
3529 // x 0 1 2
3530 // y.------
3531 // *0| 3 6 9
3532 // *1| 2 5 8
3533 // *2| 1 4 7
3534 expected.clear();
3536 expected.push_back(std::make_pair(0, 2));
3537 expected.push_back(std::make_pair(0, 1));
3538 expected.push_back(std::make_pair(0, 0));
3539 expected.push_back(std::make_pair(1, 2));
3540 expected.push_back(std::make_pair(1, 1));
3541 expected.push_back(std::make_pair(1, 0));
3542 expected.push_back(std::make_pair(2, 2));
3543 expected.push_back(std::make_pair(2, 1));
3544 expected.push_back(std::make_pair(2, 0));
3546 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
3549 INSTANTIATE_TEST_CASE_P(TilingData,
3550 TilingDataTest,
3551 ::testing::Values(gfx::Point(42, 17),
3552 gfx::Point(0, 0),
3553 gfx::Point(-8, 15),
3554 gfx::Point(-12, 4),
3555 gfx::Point(-16, -35),
3556 gfx::Point(-10000, -15000)));
3557 } // namespace
3559 } // namespace cc