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"
10 #include "cc/test/geometry_test_utils.h"
11 #include "testing/gtest/include/gtest/gtest.h"
16 int NumTiles(const gfx::Size
& max_texture_size
,
17 const gfx::Size
& tiling_size
,
18 bool has_border_texels
) {
19 TilingData
tiling(max_texture_size
, tiling_size
, 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);
25 EXPECT_EQ(num_tiles
/ tiling
.num_tiles_x(), tiling
.num_tiles_y());
30 int XIndex(const gfx::Size
& max_texture_size
,
31 const gfx::Size
& tiling_size
,
32 bool has_border_texels
,
34 TilingData
tiling(max_texture_size
, tiling_size
, has_border_texels
);
35 return tiling
.TileXIndexFromSrcCoord(x_coord
);
38 int YIndex(const gfx::Size
& max_texture_size
,
39 const gfx::Size
& tiling_size
,
40 bool has_border_texels
,
42 TilingData
tiling(max_texture_size
, tiling_size
, has_border_texels
);
43 return tiling
.TileYIndexFromSrcCoord(y_coord
);
46 int MinBorderXIndex(const gfx::Size
& max_texture_size
,
47 const gfx::Size
& tiling_size
,
48 bool has_border_texels
,
50 TilingData
tiling(max_texture_size
, tiling_size
, has_border_texels
);
51 return tiling
.FirstBorderTileXIndexFromSrcCoord(x_coord
);
54 int MinBorderYIndex(const gfx::Size
& max_texture_size
,
55 const gfx::Size
& tiling_size
,
56 bool has_border_texels
,
58 TilingData
tiling(max_texture_size
, tiling_size
, has_border_texels
);
59 return tiling
.FirstBorderTileYIndexFromSrcCoord(y_coord
);
62 int MaxBorderXIndex(const gfx::Size
& max_texture_size
,
63 const gfx::Size
& tiling_size
,
64 bool has_border_texels
,
66 TilingData
tiling(max_texture_size
, tiling_size
, has_border_texels
);
67 return tiling
.LastBorderTileXIndexFromSrcCoord(x_coord
);
70 int MaxBorderYIndex(const gfx::Size
& max_texture_size
,
71 const gfx::Size
& tiling_size
,
72 bool has_border_texels
,
74 TilingData
tiling(max_texture_size
, tiling_size
, has_border_texels
);
75 return tiling
.LastBorderTileYIndexFromSrcCoord(y_coord
);
78 int PosX(const gfx::Size
& max_texture_size
,
79 const gfx::Size
& tiling_size
,
80 bool has_border_texels
,
82 TilingData
tiling(max_texture_size
, tiling_size
, has_border_texels
);
83 return tiling
.TilePositionX(x_index
);
86 int PosY(const gfx::Size
& max_texture_size
,
87 const gfx::Size
& tiling_size
,
88 bool has_border_texels
,
90 TilingData
tiling(max_texture_size
, tiling_size
, has_border_texels
);
91 return tiling
.TilePositionY(y_index
);
94 int SizeX(const gfx::Size
& max_texture_size
,
95 const gfx::Size
& tiling_size
,
96 bool has_border_texels
,
98 TilingData
tiling(max_texture_size
, tiling_size
, has_border_texels
);
99 return tiling
.TileSizeX(x_index
);
102 int SizeY(const gfx::Size
& max_texture_size
,
103 const gfx::Size
& tiling_size
,
104 bool has_border_texels
,
106 TilingData
tiling(max_texture_size
, tiling_size
, has_border_texels
);
107 return tiling
.TileSizeY(y_index
);
110 class TilingDataTest
: public ::testing::TestWithParam
<gfx::Point
> {};
112 TEST(TilingDataTest
, NumTiles_NoTiling
) {
113 EXPECT_EQ(1, NumTiles(gfx::Size(16, 16), gfx::Size(16, 16), false));
114 EXPECT_EQ(1, NumTiles(gfx::Size(16, 16), gfx::Size(15, 15), true));
115 EXPECT_EQ(1, NumTiles(gfx::Size(16, 16), gfx::Size(16, 16), true));
116 EXPECT_EQ(1, NumTiles(gfx::Size(16, 16), gfx::Size(1, 16), false));
117 EXPECT_EQ(1, NumTiles(gfx::Size(15, 15), gfx::Size(15, 15), true));
118 EXPECT_EQ(1, NumTiles(gfx::Size(32, 16), gfx::Size(32, 16), false));
119 EXPECT_EQ(1, NumTiles(gfx::Size(32, 16), gfx::Size(32, 16), true));
122 TEST(TilingDataTest
, NumTiles_TilingNoBorders
) {
123 EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(0, 0), false));
124 EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(4, 0), false));
125 EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(0, 4), false));
126 EXPECT_EQ(0, NumTiles(gfx::Size(4, 4), gfx::Size(4, 0), false));
127 EXPECT_EQ(0, NumTiles(gfx::Size(4, 4), gfx::Size(0, 4), false));
128 EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(1, 1), false));
130 EXPECT_EQ(1, NumTiles(gfx::Size(1, 1), gfx::Size(1, 1), false));
131 EXPECT_EQ(2, NumTiles(gfx::Size(1, 1), gfx::Size(1, 2), false));
132 EXPECT_EQ(2, NumTiles(gfx::Size(1, 1), gfx::Size(2, 1), false));
133 EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(1, 1), false));
134 EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(1, 2), false));
135 EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(2, 1), false));
136 EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(2, 2), false));
137 EXPECT_EQ(1, NumTiles(gfx::Size(3, 3), gfx::Size(3, 3), false));
139 EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(1, 4), false));
140 EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(2, 4), false));
141 EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(3, 4), false));
142 EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(4, 4), false));
143 EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(5, 4), false));
144 EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(6, 4), false));
145 EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(7, 4), false));
146 EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(8, 4), false));
147 EXPECT_EQ(3, NumTiles(gfx::Size(4, 4), gfx::Size(9, 4), false));
148 EXPECT_EQ(3, NumTiles(gfx::Size(4, 4), gfx::Size(10, 4), false));
149 EXPECT_EQ(3, NumTiles(gfx::Size(4, 4), gfx::Size(11, 4), false));
151 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(1, 5), false));
152 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(2, 5), false));
153 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(3, 5), false));
154 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(4, 5), false));
155 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(5, 5), false));
156 EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(6, 5), false));
157 EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(7, 5), false));
158 EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(8, 5), false));
159 EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(9, 5), false));
160 EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(10, 5), false));
161 EXPECT_EQ(3, NumTiles(gfx::Size(5, 5), gfx::Size(11, 5), false));
163 EXPECT_EQ(1, NumTiles(gfx::Size(16, 16), gfx::Size(16, 16), false));
164 EXPECT_EQ(1, NumTiles(gfx::Size(17, 17), gfx::Size(16, 16), false));
165 EXPECT_EQ(4, NumTiles(gfx::Size(15, 15), gfx::Size(16, 16), false));
166 EXPECT_EQ(4, NumTiles(gfx::Size(8, 8), gfx::Size(16, 16), false));
167 EXPECT_EQ(6, NumTiles(gfx::Size(8, 8), gfx::Size(17, 16), false));
169 EXPECT_EQ(8, NumTiles(gfx::Size(5, 8), gfx::Size(17, 16), false));
172 TEST(TilingDataTest
, NumTiles_TilingWithBorders
) {
173 EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(0, 0), true));
174 EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(4, 0), true));
175 EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(0, 4), true));
176 EXPECT_EQ(0, NumTiles(gfx::Size(4, 4), gfx::Size(4, 0), true));
177 EXPECT_EQ(0, NumTiles(gfx::Size(4, 4), gfx::Size(0, 4), true));
178 EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(1, 1), true));
180 EXPECT_EQ(1, NumTiles(gfx::Size(1, 1), gfx::Size(1, 1), true));
181 EXPECT_EQ(0, NumTiles(gfx::Size(1, 1), gfx::Size(1, 2), true));
182 EXPECT_EQ(0, NumTiles(gfx::Size(1, 1), gfx::Size(2, 1), true));
183 EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(1, 1), true));
184 EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(1, 2), true));
185 EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(2, 1), true));
186 EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(2, 2), true));
188 EXPECT_EQ(1, NumTiles(gfx::Size(3, 3), gfx::Size(1, 3), true));
189 EXPECT_EQ(1, NumTiles(gfx::Size(3, 3), gfx::Size(2, 3), true));
190 EXPECT_EQ(1, NumTiles(gfx::Size(3, 3), gfx::Size(3, 3), true));
191 EXPECT_EQ(2, NumTiles(gfx::Size(3, 3), gfx::Size(4, 3), true));
192 EXPECT_EQ(3, NumTiles(gfx::Size(3, 3), gfx::Size(5, 3), true));
193 EXPECT_EQ(4, NumTiles(gfx::Size(3, 3), gfx::Size(6, 3), true));
194 EXPECT_EQ(5, NumTiles(gfx::Size(3, 3), gfx::Size(7, 3), true));
196 EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(1, 4), true));
197 EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(2, 4), true));
198 EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(3, 4), true));
199 EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(4, 4), true));
200 EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(5, 4), true));
201 EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(6, 4), true));
202 EXPECT_EQ(3, NumTiles(gfx::Size(4, 4), gfx::Size(7, 4), true));
203 EXPECT_EQ(3, NumTiles(gfx::Size(4, 4), gfx::Size(8, 4), true));
204 EXPECT_EQ(4, NumTiles(gfx::Size(4, 4), gfx::Size(9, 4), true));
205 EXPECT_EQ(4, NumTiles(gfx::Size(4, 4), gfx::Size(10, 4), true));
206 EXPECT_EQ(5, NumTiles(gfx::Size(4, 4), gfx::Size(11, 4), true));
208 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(1, 5), true));
209 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(2, 5), true));
210 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(3, 5), true));
211 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(4, 5), true));
212 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(5, 5), true));
213 EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(6, 5), true));
214 EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(7, 5), true));
215 EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(8, 5), true));
216 EXPECT_EQ(3, NumTiles(gfx::Size(5, 5), gfx::Size(9, 5), true));
217 EXPECT_EQ(3, NumTiles(gfx::Size(5, 5), gfx::Size(10, 5), true));
218 EXPECT_EQ(3, NumTiles(gfx::Size(5, 5), gfx::Size(11, 5), true));
220 EXPECT_EQ(30, NumTiles(gfx::Size(8, 5), gfx::Size(16, 32), true));
223 TEST(TilingDataTest
, TileXIndexFromSrcCoord
) {
224 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
225 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
226 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
227 EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
228 EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
229 EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
230 EXPECT_EQ(2, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
231 EXPECT_EQ(2, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
232 EXPECT_EQ(2, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
233 EXPECT_EQ(3, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
234 EXPECT_EQ(3, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
235 EXPECT_EQ(3, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
237 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
238 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
239 EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
240 EXPECT_EQ(2, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
241 EXPECT_EQ(3, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
242 EXPECT_EQ(4, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
243 EXPECT_EQ(5, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
244 EXPECT_EQ(6, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
245 EXPECT_EQ(7, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
246 EXPECT_EQ(7, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
247 EXPECT_EQ(7, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
248 EXPECT_EQ(7, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
250 EXPECT_EQ(0, XIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
251 EXPECT_EQ(0, XIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
252 EXPECT_EQ(0, XIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
253 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
254 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
255 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
257 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 0));
258 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 1));
259 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 2));
260 EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 3));
262 EXPECT_EQ(0, XIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
263 EXPECT_EQ(0, XIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
264 EXPECT_EQ(0, XIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
265 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
266 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
267 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
269 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 0));
270 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 1));
271 EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 2));
272 EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 3));
275 TEST(TilingDataTest
, FirstBorderTileXIndexFromSrcCoord
) {
276 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
277 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
278 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
279 EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
280 EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
281 EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
282 EXPECT_EQ(2, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
283 EXPECT_EQ(2, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
284 EXPECT_EQ(2, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
285 EXPECT_EQ(3, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
286 EXPECT_EQ(3, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
287 EXPECT_EQ(3, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
289 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
290 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
291 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
292 EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
293 EXPECT_EQ(2, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
294 EXPECT_EQ(3, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
295 EXPECT_EQ(4, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
296 EXPECT_EQ(5, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
297 EXPECT_EQ(6, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
298 EXPECT_EQ(7, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
299 EXPECT_EQ(7, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
300 EXPECT_EQ(7, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
302 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
303 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
304 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
305 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
306 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
307 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
309 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 0));
310 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 1));
311 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 2));
312 EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 3));
314 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
315 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
316 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
317 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
318 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
319 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
321 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 0));
322 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 1));
323 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 2));
324 EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 3));
327 TEST(TilingDataTest
, LastBorderTileXIndexFromSrcCoord
) {
328 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
329 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
330 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
331 EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
332 EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
333 EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
334 EXPECT_EQ(2, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
335 EXPECT_EQ(2, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
336 EXPECT_EQ(2, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
337 EXPECT_EQ(3, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
338 EXPECT_EQ(3, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
339 EXPECT_EQ(3, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
341 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
342 EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
343 EXPECT_EQ(2, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
344 EXPECT_EQ(3, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
345 EXPECT_EQ(4, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
346 EXPECT_EQ(5, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
347 EXPECT_EQ(6, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
348 EXPECT_EQ(7, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
349 EXPECT_EQ(7, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
350 EXPECT_EQ(7, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
351 EXPECT_EQ(7, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
352 EXPECT_EQ(7, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
354 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
355 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
356 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
357 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
358 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
359 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
361 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 0));
362 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 1));
363 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 2));
364 EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 3));
366 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
367 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
368 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
369 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
370 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
371 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
373 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 0));
374 EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 1));
375 EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 2));
376 EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 3));
379 TEST(TilingDataTest
, TileYIndexFromSrcCoord
) {
380 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
381 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
382 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
383 EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
384 EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
385 EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
386 EXPECT_EQ(2, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
387 EXPECT_EQ(2, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
388 EXPECT_EQ(2, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
389 EXPECT_EQ(3, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
390 EXPECT_EQ(3, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
391 EXPECT_EQ(3, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
393 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
394 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
395 EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
396 EXPECT_EQ(2, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
397 EXPECT_EQ(3, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
398 EXPECT_EQ(4, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
399 EXPECT_EQ(5, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
400 EXPECT_EQ(6, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
401 EXPECT_EQ(7, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
402 EXPECT_EQ(7, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
403 EXPECT_EQ(7, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
404 EXPECT_EQ(7, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
406 EXPECT_EQ(0, YIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
407 EXPECT_EQ(0, YIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
408 EXPECT_EQ(0, YIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
409 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
410 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
411 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
413 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 0));
414 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 1));
415 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 2));
416 EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 3));
418 EXPECT_EQ(0, YIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
419 EXPECT_EQ(0, YIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
420 EXPECT_EQ(0, YIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
421 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
422 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
423 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
425 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 0));
426 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 1));
427 EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 2));
428 EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 3));
431 TEST(TilingDataTest
, FirstBorderTileYIndexFromSrcCoord
) {
432 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
433 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
434 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
435 EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
436 EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
437 EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
438 EXPECT_EQ(2, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
439 EXPECT_EQ(2, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
440 EXPECT_EQ(2, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
441 EXPECT_EQ(3, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
442 EXPECT_EQ(3, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
443 EXPECT_EQ(3, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
445 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
446 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
447 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
448 EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
449 EXPECT_EQ(2, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
450 EXPECT_EQ(3, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
451 EXPECT_EQ(4, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
452 EXPECT_EQ(5, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
453 EXPECT_EQ(6, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
454 EXPECT_EQ(7, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
455 EXPECT_EQ(7, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
456 EXPECT_EQ(7, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
458 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
459 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
460 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
461 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
462 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
463 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
465 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 0));
466 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 1));
467 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 2));
468 EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 3));
470 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
471 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
472 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
473 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
474 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
475 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
477 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 0));
478 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 1));
479 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 2));
480 EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 3));
483 TEST(TilingDataTest
, LastBorderTileYIndexFromSrcCoord
) {
484 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
485 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
486 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
487 EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
488 EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
489 EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
490 EXPECT_EQ(2, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
491 EXPECT_EQ(2, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
492 EXPECT_EQ(2, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
493 EXPECT_EQ(3, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
494 EXPECT_EQ(3, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
495 EXPECT_EQ(3, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
497 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
498 EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
499 EXPECT_EQ(2, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
500 EXPECT_EQ(3, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
501 EXPECT_EQ(4, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
502 EXPECT_EQ(5, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
503 EXPECT_EQ(6, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
504 EXPECT_EQ(7, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
505 EXPECT_EQ(7, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
506 EXPECT_EQ(7, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
507 EXPECT_EQ(7, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
508 EXPECT_EQ(7, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
510 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
511 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
512 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
513 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
514 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
515 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
517 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 0));
518 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 1));
519 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 2));
520 EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 3));
522 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
523 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
524 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
525 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
526 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
527 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
529 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 0));
530 EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 1));
531 EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 2));
532 EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 3));
535 TEST(TilingDataTest
, TileSizeX
) {
536 EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(5, 5), false, 0));
537 EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(5, 5), true, 0));
539 EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(6, 6), false, 0));
540 EXPECT_EQ(1, SizeX(gfx::Size(5, 5), gfx::Size(6, 6), false, 1));
541 EXPECT_EQ(4, SizeX(gfx::Size(5, 5), gfx::Size(6, 6), true, 0));
542 EXPECT_EQ(2, SizeX(gfx::Size(5, 5), gfx::Size(6, 6), true, 1));
544 EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(8, 8), false, 0));
545 EXPECT_EQ(3, SizeX(gfx::Size(5, 5), gfx::Size(8, 8), false, 1));
546 EXPECT_EQ(4, SizeX(gfx::Size(5, 5), gfx::Size(8, 8), true, 0));
547 EXPECT_EQ(4, SizeX(gfx::Size(5, 5), gfx::Size(8, 8), true, 1));
549 EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(10, 10), false, 0));
550 EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(10, 10), false, 1));
551 EXPECT_EQ(4, SizeX(gfx::Size(5, 5), gfx::Size(10, 10), true, 0));
552 EXPECT_EQ(3, SizeX(gfx::Size(5, 5), gfx::Size(10, 10), true, 1));
553 EXPECT_EQ(3, SizeX(gfx::Size(5, 5), gfx::Size(10, 10), true, 2));
555 EXPECT_EQ(4, SizeX(gfx::Size(5, 5), gfx::Size(11, 11), true, 2));
556 EXPECT_EQ(3, SizeX(gfx::Size(5, 5), gfx::Size(12, 12), true, 2));
558 EXPECT_EQ(3, SizeX(gfx::Size(5, 9), gfx::Size(12, 17), true, 2));
561 TEST(TilingDataTest
, TileSizeY
) {
562 EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(5, 5), false, 0));
563 EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(5, 5), true, 0));
565 EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(6, 6), false, 0));
566 EXPECT_EQ(1, SizeY(gfx::Size(5, 5), gfx::Size(6, 6), false, 1));
567 EXPECT_EQ(4, SizeY(gfx::Size(5, 5), gfx::Size(6, 6), true, 0));
568 EXPECT_EQ(2, SizeY(gfx::Size(5, 5), gfx::Size(6, 6), true, 1));
570 EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(8, 8), false, 0));
571 EXPECT_EQ(3, SizeY(gfx::Size(5, 5), gfx::Size(8, 8), false, 1));
572 EXPECT_EQ(4, SizeY(gfx::Size(5, 5), gfx::Size(8, 8), true, 0));
573 EXPECT_EQ(4, SizeY(gfx::Size(5, 5), gfx::Size(8, 8), true, 1));
575 EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(10, 10), false, 0));
576 EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(10, 10), false, 1));
577 EXPECT_EQ(4, SizeY(gfx::Size(5, 5), gfx::Size(10, 10), true, 0));
578 EXPECT_EQ(3, SizeY(gfx::Size(5, 5), gfx::Size(10, 10), true, 1));
579 EXPECT_EQ(3, SizeY(gfx::Size(5, 5), gfx::Size(10, 10), true, 2));
581 EXPECT_EQ(4, SizeY(gfx::Size(5, 5), gfx::Size(11, 11), true, 2));
582 EXPECT_EQ(3, SizeY(gfx::Size(5, 5), gfx::Size(12, 12), true, 2));
584 EXPECT_EQ(3, SizeY(gfx::Size(9, 5), gfx::Size(17, 12), true, 2));
587 TEST(TilingDataTest
, TileSizeX_and_TilePositionX
) {
588 // Single tile cases:
589 EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(1, 1), false, 0));
590 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(1, 1), false, 0));
591 EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(1, 100), false, 0));
592 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(1, 100), false, 0));
593 EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(3, 1), false, 0));
594 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(3, 1), false, 0));
595 EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(3, 100), false, 0));
596 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(3, 100), false, 0));
597 EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(1, 1), true, 0));
598 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(1, 1), true, 0));
599 EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(1, 100), true, 0));
600 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(1, 100), true, 0));
601 EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(3, 1), true, 0));
602 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(3, 1), true, 0));
603 EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(3, 100), true, 0));
604 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(3, 100), true, 0));
609 EXPECT_EQ(2, NumTiles(gfx::Size(3, 3), gfx::Size(6, 1), false));
610 EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), false, 0));
611 EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), false, 1));
612 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(6, 1), false, 0));
613 EXPECT_EQ(3, PosX(gfx::Size(3, 3), gfx::Size(6, 1), false, 1));
614 EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(6, 100), false, 0));
615 EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(6, 100), false, 1));
616 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(6, 100), false, 0));
617 EXPECT_EQ(3, PosX(gfx::Size(3, 3), gfx::Size(6, 100), false, 1));
621 // positions 0, 2, 3, 4
622 EXPECT_EQ(4, NumTiles(gfx::Size(3, 3), gfx::Size(6, 1), true));
623 EXPECT_EQ(2, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), true, 0));
624 EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), true, 1));
625 EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), true, 2));
626 EXPECT_EQ(2, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), true, 3));
627 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(6, 1), true, 0));
628 EXPECT_EQ(2, PosX(gfx::Size(3, 3), gfx::Size(6, 1), true, 1));
629 EXPECT_EQ(3, PosX(gfx::Size(3, 3), gfx::Size(6, 1), true, 2));
630 EXPECT_EQ(4, PosX(gfx::Size(3, 3), gfx::Size(6, 1), true, 3));
631 EXPECT_EQ(2, SizeX(gfx::Size(3, 7), gfx::Size(6, 100), true, 0));
632 EXPECT_EQ(1, SizeX(gfx::Size(3, 7), gfx::Size(6, 100), true, 1));
633 EXPECT_EQ(1, SizeX(gfx::Size(3, 7), gfx::Size(6, 100), true, 2));
634 EXPECT_EQ(2, SizeX(gfx::Size(3, 7), gfx::Size(6, 100), true, 3));
635 EXPECT_EQ(0, PosX(gfx::Size(3, 7), gfx::Size(6, 100), true, 0));
636 EXPECT_EQ(2, PosX(gfx::Size(3, 7), gfx::Size(6, 100), true, 1));
637 EXPECT_EQ(3, PosX(gfx::Size(3, 7), gfx::Size(6, 100), true, 2));
638 EXPECT_EQ(4, PosX(gfx::Size(3, 7), gfx::Size(6, 100), true, 3));
641 TEST(TilingDataTest
, TileSizeY_and_TilePositionY
) {
642 // Single tile cases:
643 EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(1, 1), false, 0));
644 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 1), false, 0));
645 EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(100, 1), false, 0));
646 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(100, 1), false, 0));
647 EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(1, 3), false, 0));
648 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 3), false, 0));
649 EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(100, 3), false, 0));
650 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(100, 3), false, 0));
651 EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(1, 1), true, 0));
652 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 1), true, 0));
653 EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(100, 1), true, 0));
654 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(100, 1), true, 0));
655 EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(1, 3), true, 0));
656 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 3), true, 0));
657 EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(100, 3), true, 0));
658 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(100, 3), true, 0));
663 EXPECT_EQ(2, NumTiles(gfx::Size(3, 3), gfx::Size(1, 6), false));
664 EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), false, 0));
665 EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), false, 1));
666 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 6), false, 0));
667 EXPECT_EQ(3, PosY(gfx::Size(3, 3), gfx::Size(1, 6), false, 1));
668 EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(100, 6), false, 0));
669 EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(100, 6), false, 1));
670 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(100, 6), false, 0));
671 EXPECT_EQ(3, PosY(gfx::Size(3, 3), gfx::Size(100, 6), false, 1));
675 // positions 0, 2, 3, 4
676 EXPECT_EQ(4, NumTiles(gfx::Size(3, 3), gfx::Size(1, 6), true));
677 EXPECT_EQ(2, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), true, 0));
678 EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), true, 1));
679 EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), true, 2));
680 EXPECT_EQ(2, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), true, 3));
681 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 6), true, 0));
682 EXPECT_EQ(2, PosY(gfx::Size(3, 3), gfx::Size(1, 6), true, 1));
683 EXPECT_EQ(3, PosY(gfx::Size(3, 3), gfx::Size(1, 6), true, 2));
684 EXPECT_EQ(4, PosY(gfx::Size(3, 3), gfx::Size(1, 6), true, 3));
685 EXPECT_EQ(2, SizeY(gfx::Size(7, 3), gfx::Size(100, 6), true, 0));
686 EXPECT_EQ(1, SizeY(gfx::Size(7, 3), gfx::Size(100, 6), true, 1));
687 EXPECT_EQ(1, SizeY(gfx::Size(7, 3), gfx::Size(100, 6), true, 2));
688 EXPECT_EQ(2, SizeY(gfx::Size(7, 3), gfx::Size(100, 6), true, 3));
689 EXPECT_EQ(0, PosY(gfx::Size(7, 3), gfx::Size(100, 6), true, 0));
690 EXPECT_EQ(2, PosY(gfx::Size(7, 3), gfx::Size(100, 6), true, 1));
691 EXPECT_EQ(3, PosY(gfx::Size(7, 3), gfx::Size(100, 6), true, 2));
692 EXPECT_EQ(4, PosY(gfx::Size(7, 3), gfx::Size(100, 6), true, 3));
695 TEST(TilingDataTest
, SetTotalSize
) {
696 TilingData
data(gfx::Size(5, 5), gfx::Size(5, 5), false);
697 EXPECT_EQ(5, data
.tiling_size().width());
698 EXPECT_EQ(5, data
.tiling_size().height());
699 EXPECT_EQ(1, data
.num_tiles_x());
700 EXPECT_EQ(5, data
.TileSizeX(0));
701 EXPECT_EQ(1, data
.num_tiles_y());
702 EXPECT_EQ(5, data
.TileSizeY(0));
704 data
.SetTilingSize(gfx::Size(6, 5));
705 EXPECT_EQ(6, data
.tiling_size().width());
706 EXPECT_EQ(5, data
.tiling_size().height());
707 EXPECT_EQ(2, data
.num_tiles_x());
708 EXPECT_EQ(5, data
.TileSizeX(0));
709 EXPECT_EQ(1, data
.TileSizeX(1));
710 EXPECT_EQ(1, data
.num_tiles_y());
711 EXPECT_EQ(5, data
.TileSizeY(0));
713 data
.SetTilingSize(gfx::Size(5, 12));
714 EXPECT_EQ(5, data
.tiling_size().width());
715 EXPECT_EQ(12, data
.tiling_size().height());
716 EXPECT_EQ(1, data
.num_tiles_x());
717 EXPECT_EQ(5, data
.TileSizeX(0));
718 EXPECT_EQ(3, data
.num_tiles_y());
719 EXPECT_EQ(5, data
.TileSizeY(0));
720 EXPECT_EQ(5, data
.TileSizeY(1));
721 EXPECT_EQ(2, data
.TileSizeY(2));
724 TEST(TilingDataTest
, SetMaxTextureSizeNoBorders
) {
725 TilingData
data(gfx::Size(8, 8), gfx::Size(16, 32), false);
726 EXPECT_EQ(2, data
.num_tiles_x());
727 EXPECT_EQ(4, data
.num_tiles_y());
729 data
.SetMaxTextureSize(gfx::Size(32, 32));
730 EXPECT_EQ(gfx::Size(32, 32), data
.max_texture_size());
731 EXPECT_EQ(1, data
.num_tiles_x());
732 EXPECT_EQ(1, data
.num_tiles_y());
734 data
.SetMaxTextureSize(gfx::Size(2, 2));
735 EXPECT_EQ(gfx::Size(2, 2), data
.max_texture_size());
736 EXPECT_EQ(8, data
.num_tiles_x());
737 EXPECT_EQ(16, data
.num_tiles_y());
739 data
.SetMaxTextureSize(gfx::Size(5, 5));
740 EXPECT_EQ(gfx::Size(5, 5), data
.max_texture_size());
741 EXPECT_EQ(4, data
.num_tiles_x());
742 EXPECT_EQ(7, data
.num_tiles_y());
744 data
.SetMaxTextureSize(gfx::Size(8, 5));
745 EXPECT_EQ(gfx::Size(8, 5), data
.max_texture_size());
746 EXPECT_EQ(2, data
.num_tiles_x());
747 EXPECT_EQ(7, data
.num_tiles_y());
750 TEST(TilingDataTest
, SetMaxTextureSizeBorders
) {
751 TilingData
data(gfx::Size(8, 8), gfx::Size(16, 32), true);
752 EXPECT_EQ(3, data
.num_tiles_x());
753 EXPECT_EQ(5, data
.num_tiles_y());
755 data
.SetMaxTextureSize(gfx::Size(32, 32));
756 EXPECT_EQ(gfx::Size(32, 32), data
.max_texture_size());
757 EXPECT_EQ(1, data
.num_tiles_x());
758 EXPECT_EQ(1, data
.num_tiles_y());
760 data
.SetMaxTextureSize(gfx::Size(2, 2));
761 EXPECT_EQ(gfx::Size(2, 2), data
.max_texture_size());
762 EXPECT_EQ(0, data
.num_tiles_x());
763 EXPECT_EQ(0, data
.num_tiles_y());
765 data
.SetMaxTextureSize(gfx::Size(5, 5));
766 EXPECT_EQ(gfx::Size(5, 5), data
.max_texture_size());
767 EXPECT_EQ(5, data
.num_tiles_x());
768 EXPECT_EQ(10, data
.num_tiles_y());
770 data
.SetMaxTextureSize(gfx::Size(8, 5));
771 EXPECT_EQ(gfx::Size(8, 5), data
.max_texture_size());
772 EXPECT_EQ(3, data
.num_tiles_x());
773 EXPECT_EQ(10, data
.num_tiles_y());
776 TEST(TilingDataTest
, ExpandRectIgnoringBordersToTileBoundsEmpty
) {
777 TilingData
empty_total_size(gfx::Size(0, 0), gfx::Size(8, 8), true);
778 EXPECT_EQ(gfx::Rect(), empty_total_size
.ExpandRectIgnoringBordersToTileBounds(
780 EXPECT_EQ(gfx::Rect(), empty_total_size
.ExpandRectIgnoringBordersToTileBounds(
781 gfx::Rect(100, 100, 100, 100)));
782 EXPECT_EQ(gfx::Rect(), empty_total_size
.ExpandRectIgnoringBordersToTileBounds(
783 gfx::Rect(100, 100)));
785 TilingData
empty_max_texture_size(gfx::Size(8, 8), gfx::Size(0, 0), true);
786 EXPECT_EQ(gfx::Rect(),
787 empty_max_texture_size
.ExpandRectIgnoringBordersToTileBounds(
789 EXPECT_EQ(gfx::Rect(),
790 empty_max_texture_size
.ExpandRectIgnoringBordersToTileBounds(
791 gfx::Rect(100, 100, 100, 100)));
792 EXPECT_EQ(gfx::Rect(),
793 empty_max_texture_size
.ExpandRectIgnoringBordersToTileBounds(
794 gfx::Rect(100, 100)));
797 TEST(TilingDataTest
, ExpandRectIgnoringBordersToTileBounds
) {
798 TilingData
data(gfx::Size(4, 4), gfx::Size(16, 32), true);
800 // Small rect at origin rounds up to tile 0, 0.
801 gfx::Rect
at_origin_src(1, 1);
802 gfx::Rect
at_origin_result(data
.TileBounds(0, 0));
803 EXPECT_NE(at_origin_src
, at_origin_result
);
804 EXPECT_EQ(at_origin_result
,
805 data
.ExpandRectIgnoringBordersToTileBounds(at_origin_src
));
807 // Arbitrary internal rect.
808 gfx::Rect
rect_src(6, 6, 1, 3);
809 // Tile 2, 2 => gfx::Rect(4, 4, 4, 4)
810 // Tile 2, 3 => gfx::Rect(4, 6, 4, 4)
811 gfx::Rect
rect_result(
812 gfx::UnionRects(data
.TileBounds(2, 2), data
.TileBounds(2, 3)));
813 EXPECT_NE(rect_src
, rect_result
);
814 EXPECT_EQ(rect_result
, data
.ExpandRectIgnoringBordersToTileBounds(rect_src
));
816 // On tile bounds does not round up to next tile (ignores the border).
817 gfx::Rect
border_rect_src(
818 gfx::UnionRects(data
.TileBounds(1, 2), data
.TileBounds(3, 4)));
819 gfx::Rect
border_rect_result(
820 gfx::UnionRects(data
.TileBounds(1, 2), data
.TileBounds(3, 4)));
821 EXPECT_EQ(border_rect_result
,
822 data
.ExpandRectIgnoringBordersToTileBounds(border_rect_src
));
824 // Equal to tiling rect.
825 EXPECT_EQ(gfx::Rect(data
.tiling_size()),
826 data
.ExpandRectIgnoringBordersToTileBounds(
827 gfx::Rect(data
.tiling_size())));
829 // Containing, but larger than tiling rect.
830 EXPECT_EQ(gfx::Rect(data
.tiling_size()),
831 data
.ExpandRectIgnoringBordersToTileBounds(gfx::Rect(100, 100)));
833 // Non-intersecting with tiling rect.
834 gfx::Rect
non_intersect(200, 200, 100, 100);
835 EXPECT_FALSE(non_intersect
.Intersects(gfx::Rect(data
.tiling_size())));
836 EXPECT_EQ(gfx::Rect(),
837 data
.ExpandRectIgnoringBordersToTileBounds(non_intersect
));
839 TilingData
data2(gfx::Size(8, 8), gfx::Size(32, 64), true);
841 // Inside other tile border texels doesn't include other tiles.
842 gfx::Rect
inner_rect_src(data2
.TileBounds(1, 1));
843 inner_rect_src
.Inset(data2
.border_texels(), data
.border_texels());
844 gfx::Rect
inner_rect_result(data2
.TileBounds(1, 1));
846 data2
.ExpandRectIgnoringBordersToTileBounds(inner_rect_src
);
847 EXPECT_EQ(inner_rect_result
.ToString(), expanded
.ToString());
850 TEST(TilingDataTest
, ExpandRectToTileBounds
) {
851 TilingData
data(gfx::Size(4, 4), gfx::Size(16, 32), true);
853 // Small rect at origin rounds up to tile 0, 0.
854 gfx::Rect
at_origin_src(1, 1);
855 gfx::Rect
at_origin_result(data
.TileBounds(0, 0));
856 EXPECT_NE(at_origin_src
, at_origin_result
);
857 EXPECT_EQ(at_origin_result
, data
.ExpandRectToTileBounds(at_origin_src
));
859 // Arbitrary internal rect.
860 gfx::Rect
rect_src(6, 6, 1, 3);
861 // Tile 2, 2 => gfx::Rect(4, 4, 4, 4)
862 // Tile 3, 4 => gfx::Rect(6, 8, 4, 4)
863 gfx::Rect
rect_result(
864 gfx::UnionRects(data
.TileBounds(2, 2), data
.TileBounds(3, 4)));
865 EXPECT_NE(rect_src
, rect_result
);
866 EXPECT_EQ(rect_result
, data
.ExpandRectToTileBounds(rect_src
));
868 // On tile bounds rounds up to next tile (since border overlaps).
869 gfx::Rect
border_rect_src(
870 gfx::UnionRects(data
.TileBounds(1, 2), data
.TileBounds(3, 4)));
871 gfx::Rect
border_rect_result(
872 gfx::UnionRects(data
.TileBounds(0, 1), data
.TileBounds(4, 5)));
873 EXPECT_EQ(border_rect_result
, data
.ExpandRectToTileBounds(border_rect_src
));
875 // Equal to tiling rect.
876 EXPECT_EQ(gfx::Rect(data
.tiling_size()),
877 data
.ExpandRectToTileBounds(gfx::Rect(data
.tiling_size())));
879 // Containing, but larger than tiling rect.
880 EXPECT_EQ(gfx::Rect(data
.tiling_size()),
881 data
.ExpandRectToTileBounds(gfx::Rect(100, 100)));
883 // Non-intersecting with tiling rect.
884 gfx::Rect
non_intersect(200, 200, 100, 100);
885 EXPECT_FALSE(non_intersect
.Intersects(gfx::Rect(data
.tiling_size())));
886 EXPECT_EQ(gfx::Rect(), data
.ExpandRectToTileBounds(non_intersect
));
888 TilingData
data2(gfx::Size(8, 8), gfx::Size(32, 64), true);
890 // Inside other tile border texels doesn't include other tiles.
891 gfx::Rect
inner_rect_src(data2
.TileBounds(1, 1));
892 inner_rect_src
.Inset(data2
.border_texels(), data
.border_texels());
893 gfx::Rect
inner_rect_result(data2
.TileBounds(1, 1));
894 gfx::Rect expanded
= data2
.ExpandRectToTileBounds(inner_rect_src
);
895 EXPECT_EQ(inner_rect_result
.ToString(), expanded
.ToString());
898 TEST(TilingDataTest
, Assignment
) {
900 TilingData
source(gfx::Size(8, 8), gfx::Size(16, 32), true);
901 TilingData dest
= source
;
902 EXPECT_EQ(source
.border_texels(), dest
.border_texels());
903 EXPECT_EQ(source
.max_texture_size(), dest
.max_texture_size());
904 EXPECT_EQ(source
.num_tiles_x(), dest
.num_tiles_x());
905 EXPECT_EQ(source
.num_tiles_y(), dest
.num_tiles_y());
906 EXPECT_EQ(source
.tiling_size(), dest
.tiling_size());
909 TilingData
source(gfx::Size(7, 3), gfx::Size(6, 100), false);
910 TilingData
dest(source
);
911 EXPECT_EQ(source
.border_texels(), dest
.border_texels());
912 EXPECT_EQ(source
.max_texture_size(), dest
.max_texture_size());
913 EXPECT_EQ(source
.num_tiles_x(), dest
.num_tiles_x());
914 EXPECT_EQ(source
.num_tiles_y(), dest
.num_tiles_y());
915 EXPECT_EQ(source
.tiling_size(), dest
.tiling_size());
919 TEST(TilingDataTest
, SetBorderTexels
) {
920 TilingData
data(gfx::Size(8, 8), gfx::Size(16, 32), false);
921 EXPECT_EQ(2, data
.num_tiles_x());
922 EXPECT_EQ(4, data
.num_tiles_y());
924 data
.SetHasBorderTexels(true);
925 EXPECT_EQ(3, data
.num_tiles_x());
926 EXPECT_EQ(5, data
.num_tiles_y());
928 data
.SetHasBorderTexels(false);
929 EXPECT_EQ(2, data
.num_tiles_x());
930 EXPECT_EQ(4, data
.num_tiles_y());
933 TEST(TilingDataTest
, LargeBorders
) {
934 TilingData
data(gfx::Size(100, 80), gfx::Size(200, 145), 30);
935 EXPECT_EQ(30, data
.border_texels());
937 EXPECT_EQ(70, data
.TileSizeX(0));
938 EXPECT_EQ(40, data
.TileSizeX(1));
939 EXPECT_EQ(40, data
.TileSizeX(2));
940 EXPECT_EQ(50, data
.TileSizeX(3));
941 EXPECT_EQ(4, data
.num_tiles_x());
943 EXPECT_EQ(50, data
.TileSizeY(0));
944 EXPECT_EQ(20, data
.TileSizeY(1));
945 EXPECT_EQ(20, data
.TileSizeY(2));
946 EXPECT_EQ(20, data
.TileSizeY(3));
947 EXPECT_EQ(35, data
.TileSizeY(4));
948 EXPECT_EQ(5, data
.num_tiles_y());
950 EXPECT_EQ(gfx::Rect(70, 50), data
.TileBounds(0, 0));
951 EXPECT_EQ(gfx::Rect(70, 50, 40, 20), data
.TileBounds(1, 1));
952 EXPECT_EQ(gfx::Rect(110, 110, 40, 35), data
.TileBounds(2, 4));
953 EXPECT_EQ(gfx::Rect(150, 70, 50, 20), data
.TileBounds(3, 2));
954 EXPECT_EQ(gfx::Rect(150, 110, 50, 35), data
.TileBounds(3, 4));
956 EXPECT_EQ(gfx::Rect(100, 80), data
.TileBoundsWithBorder(0, 0));
957 EXPECT_EQ(gfx::Rect(40, 20, 100, 80), data
.TileBoundsWithBorder(1, 1));
958 EXPECT_EQ(gfx::Rect(80, 80, 100, 65), data
.TileBoundsWithBorder(2, 4));
959 EXPECT_EQ(gfx::Rect(120, 40, 80, 80), data
.TileBoundsWithBorder(3, 2));
960 EXPECT_EQ(gfx::Rect(120, 80, 80, 65), data
.TileBoundsWithBorder(3, 4));
962 EXPECT_EQ(0, data
.TileXIndexFromSrcCoord(0));
963 EXPECT_EQ(0, data
.TileXIndexFromSrcCoord(69));
964 EXPECT_EQ(1, data
.TileXIndexFromSrcCoord(70));
965 EXPECT_EQ(1, data
.TileXIndexFromSrcCoord(109));
966 EXPECT_EQ(2, data
.TileXIndexFromSrcCoord(110));
967 EXPECT_EQ(2, data
.TileXIndexFromSrcCoord(149));
968 EXPECT_EQ(3, data
.TileXIndexFromSrcCoord(150));
969 EXPECT_EQ(3, data
.TileXIndexFromSrcCoord(199));
971 EXPECT_EQ(0, data
.TileYIndexFromSrcCoord(0));
972 EXPECT_EQ(0, data
.TileYIndexFromSrcCoord(49));
973 EXPECT_EQ(1, data
.TileYIndexFromSrcCoord(50));
974 EXPECT_EQ(1, data
.TileYIndexFromSrcCoord(69));
975 EXPECT_EQ(2, data
.TileYIndexFromSrcCoord(70));
976 EXPECT_EQ(2, data
.TileYIndexFromSrcCoord(89));
977 EXPECT_EQ(3, data
.TileYIndexFromSrcCoord(90));
978 EXPECT_EQ(3, data
.TileYIndexFromSrcCoord(109));
979 EXPECT_EQ(4, data
.TileYIndexFromSrcCoord(110));
980 EXPECT_EQ(4, data
.TileYIndexFromSrcCoord(144));
982 EXPECT_EQ(0, data
.FirstBorderTileXIndexFromSrcCoord(0));
983 EXPECT_EQ(0, data
.FirstBorderTileXIndexFromSrcCoord(99));
984 EXPECT_EQ(1, data
.FirstBorderTileXIndexFromSrcCoord(100));
985 EXPECT_EQ(1, data
.FirstBorderTileXIndexFromSrcCoord(139));
986 EXPECT_EQ(2, data
.FirstBorderTileXIndexFromSrcCoord(140));
987 EXPECT_EQ(2, data
.FirstBorderTileXIndexFromSrcCoord(179));
988 EXPECT_EQ(3, data
.FirstBorderTileXIndexFromSrcCoord(180));
989 EXPECT_EQ(3, data
.FirstBorderTileXIndexFromSrcCoord(199));
991 EXPECT_EQ(0, data
.FirstBorderTileYIndexFromSrcCoord(0));
992 EXPECT_EQ(0, data
.FirstBorderTileYIndexFromSrcCoord(79));
993 EXPECT_EQ(1, data
.FirstBorderTileYIndexFromSrcCoord(80));
994 EXPECT_EQ(1, data
.FirstBorderTileYIndexFromSrcCoord(99));
995 EXPECT_EQ(2, data
.FirstBorderTileYIndexFromSrcCoord(100));
996 EXPECT_EQ(2, data
.FirstBorderTileYIndexFromSrcCoord(119));
997 EXPECT_EQ(3, data
.FirstBorderTileYIndexFromSrcCoord(120));
998 EXPECT_EQ(3, data
.FirstBorderTileYIndexFromSrcCoord(139));
999 EXPECT_EQ(4, data
.FirstBorderTileYIndexFromSrcCoord(140));
1000 EXPECT_EQ(4, data
.FirstBorderTileYIndexFromSrcCoord(144));
1002 EXPECT_EQ(0, data
.LastBorderTileXIndexFromSrcCoord(0));
1003 EXPECT_EQ(0, data
.LastBorderTileXIndexFromSrcCoord(39));
1004 EXPECT_EQ(1, data
.LastBorderTileXIndexFromSrcCoord(40));
1005 EXPECT_EQ(1, data
.LastBorderTileXIndexFromSrcCoord(79));
1006 EXPECT_EQ(2, data
.LastBorderTileXIndexFromSrcCoord(80));
1007 EXPECT_EQ(2, data
.LastBorderTileXIndexFromSrcCoord(119));
1008 EXPECT_EQ(3, data
.LastBorderTileXIndexFromSrcCoord(120));
1009 EXPECT_EQ(3, data
.LastBorderTileXIndexFromSrcCoord(199));
1011 EXPECT_EQ(0, data
.LastBorderTileYIndexFromSrcCoord(0));
1012 EXPECT_EQ(0, data
.LastBorderTileYIndexFromSrcCoord(19));
1013 EXPECT_EQ(1, data
.LastBorderTileYIndexFromSrcCoord(20));
1014 EXPECT_EQ(1, data
.LastBorderTileYIndexFromSrcCoord(39));
1015 EXPECT_EQ(2, data
.LastBorderTileYIndexFromSrcCoord(40));
1016 EXPECT_EQ(2, data
.LastBorderTileYIndexFromSrcCoord(59));
1017 EXPECT_EQ(3, data
.LastBorderTileYIndexFromSrcCoord(60));
1018 EXPECT_EQ(3, data
.LastBorderTileYIndexFromSrcCoord(79));
1019 EXPECT_EQ(4, data
.LastBorderTileYIndexFromSrcCoord(80));
1020 EXPECT_EQ(4, data
.LastBorderTileYIndexFromSrcCoord(144));
1023 void TestIterate(const TilingData
& data
,
1029 bool include_borders
) {
1030 EXPECT_GE(expect_left
, 0);
1031 EXPECT_GE(expect_top
, 0);
1032 EXPECT_LT(expect_right
, data
.num_tiles_x());
1033 EXPECT_LT(expect_bottom
, data
.num_tiles_y());
1035 std::vector
<std::pair
<int, int>> original_expected
;
1036 for (int x
= 0; x
< data
.num_tiles_x(); ++x
) {
1037 for (int y
= 0; y
< data
.num_tiles_y(); ++y
) {
1039 if (include_borders
)
1040 bounds
= data
.TileBoundsWithBorder(x
, y
);
1042 bounds
= data
.TileBounds(x
, y
);
1043 if (x
>= expect_left
&& x
<= expect_right
&&
1044 y
>= expect_top
&& y
<= expect_bottom
) {
1045 EXPECT_TRUE(bounds
.Intersects(rect
));
1046 original_expected
.push_back(std::make_pair(x
, y
));
1048 EXPECT_FALSE(bounds
.Intersects(rect
));
1053 // Verify with vanilla iterator.
1055 std::vector
<std::pair
<int, int>> expected
= original_expected
;
1056 for (TilingData::Iterator
iter(&data
, rect
, include_borders
); iter
;
1059 for (size_t i
= 0; i
< expected
.size(); ++i
) {
1060 if (expected
[i
] == iter
.index()) {
1061 expected
[i
] = expected
.back();
1062 expected
.pop_back();
1069 EXPECT_EQ(0u, expected
.size());
1072 // Make sure this also works with a difference iterator and an empty ignore.
1073 // The difference iterator never includes borders, so ignore it otherwise.
1074 if (!include_borders
) {
1075 std::vector
<std::pair
<int, int>> expected
= original_expected
;
1076 for (TilingData::DifferenceIterator
iter(&data
, rect
, gfx::Rect()); iter
;
1079 for (size_t i
= 0; i
< expected
.size(); ++i
) {
1080 if (expected
[i
] == iter
.index()) {
1081 expected
[i
] = expected
.back();
1082 expected
.pop_back();
1089 EXPECT_EQ(0u, expected
.size());
1093 void TestIterateBorders(const TilingData
& data
,
1098 int expect_bottom
) {
1099 bool include_borders
= true;
1109 void TestIterateNoBorders(const TilingData
& data
,
1114 int expect_bottom
) {
1115 bool include_borders
= false;
1125 void TestIterateAll(const TilingData
& data
,
1130 int expect_bottom
) {
1132 data
, rect
, expect_left
, expect_top
, expect_right
, expect_bottom
);
1133 TestIterateNoBorders(
1134 data
, rect
, expect_left
, expect_top
, expect_right
, expect_bottom
);
1137 TEST(TilingDataTest
, IteratorNoBorderTexels
) {
1138 TilingData
data(gfx::Size(10, 10), gfx::Size(40, 25), false);
1139 // X border index by src coord: [0-10), [10-20), [20, 30), [30, 40)
1140 // Y border index by src coord: [0-10), [10-20), [20, 25)
1141 TestIterateAll(data
, gfx::Rect(40, 25), 0, 0, 3, 2);
1142 TestIterateAll(data
, gfx::Rect(15, 15, 8, 8), 1, 1, 2, 2);
1145 TestIterateAll(data
, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 3, 2);
1146 TestIterateAll(data
, gfx::Rect(-100, 20, 1000, 1), 0, 2, 3, 2);
1147 TestIterateAll(data
, gfx::Rect(29, -100, 31, 1000), 2, 0, 3, 2);
1149 TestIterateAll(data
, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1);
1152 TEST(TilingDataTest
, BordersIteratorOneBorderTexel
) {
1153 TilingData
data(gfx::Size(10, 20), gfx::Size(25, 45), true);
1154 // X border index by src coord: [0-10), [8-18), [16-25)
1155 // Y border index by src coord: [0-20), [18-38), [36-45)
1156 TestIterateBorders(data
, gfx::Rect(25, 45), 0, 0, 2, 2);
1157 TestIterateBorders(data
, gfx::Rect(18, 19, 3, 17), 2, 0, 2, 1);
1158 TestIterateBorders(data
, gfx::Rect(10, 20, 6, 16), 1, 1, 1, 1);
1159 TestIterateBorders(data
, gfx::Rect(9, 19, 8, 18), 0, 0, 2, 2);
1161 TestIterateBorders(data
, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 2);
1162 TestIterateBorders(data
, gfx::Rect(-100, 20, 1000, 1), 0, 1, 2, 1);
1163 TestIterateBorders(data
, gfx::Rect(18, -100, 6, 1000), 2, 0, 2, 2);
1165 TestIterateBorders(data
, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1);
1168 TEST(TilingDataTest
, NoBordersIteratorOneBorderTexel
) {
1169 TilingData
data(gfx::Size(10, 20), gfx::Size(25, 45), true);
1170 // X index by src coord: [0-9), [9-17), [17-25)
1171 // Y index by src coord: [0-19), [19-37), [37-45)
1172 TestIterateNoBorders(data
, gfx::Rect(25, 45), 0, 0, 2, 2);
1173 TestIterateNoBorders(data
, gfx::Rect(17, 19, 3, 18), 2, 1, 2, 1);
1174 TestIterateNoBorders(data
, gfx::Rect(17, 19, 3, 19), 2, 1, 2, 2);
1175 TestIterateNoBorders(data
, gfx::Rect(8, 18, 9, 19), 0, 0, 1, 1);
1176 TestIterateNoBorders(data
, gfx::Rect(9, 19, 9, 19), 1, 1, 2, 2);
1178 TestIterateNoBorders(data
, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 2);
1179 TestIterateNoBorders(data
, gfx::Rect(-100, 20, 1000, 1), 0, 1, 2, 1);
1180 TestIterateNoBorders(data
, gfx::Rect(18, -100, 6, 1000), 2, 0, 2, 2);
1182 TestIterateNoBorders(data
, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1);
1185 TEST(TilingDataTest
, BordersIteratorManyBorderTexels
) {
1186 TilingData
data(gfx::Size(50, 60), gfx::Size(65, 110), 20);
1187 // X border index by src coord: [0-50), [10-60), [20-65)
1188 // Y border index by src coord: [0-60), [20-80), [40-100), [60-110)
1189 TestIterateBorders(data
, gfx::Rect(65, 110), 0, 0, 2, 3);
1190 TestIterateBorders(data
, gfx::Rect(50, 60, 15, 65), 1, 1, 2, 3);
1191 TestIterateBorders(data
, gfx::Rect(60, 30, 2, 10), 2, 0, 2, 1);
1193 TestIterateBorders(data
, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 3);
1194 TestIterateBorders(data
, gfx::Rect(-100, 10, 1000, 10), 0, 0, 2, 0);
1195 TestIterateBorders(data
, gfx::Rect(10, -100, 10, 1000), 0, 0, 1, 3);
1197 TestIterateBorders(data
, gfx::Rect(65, 110, 100, 100), 0, 0, -1, -1);
1200 TEST(TilingDataTest
, NoBordersIteratorManyBorderTexels
) {
1201 TilingData
data(gfx::Size(50, 60), gfx::Size(65, 110), 20);
1202 // X index by src coord: [0-30), [30-40), [40, 65)
1203 // Y index by src coord: [0-40), [40-60), [60, 80), [80-110)
1204 TestIterateNoBorders(data
, gfx::Rect(65, 110), 0, 0, 2, 3);
1205 TestIterateNoBorders(data
, gfx::Rect(30, 40, 15, 65), 1, 1, 2, 3);
1206 TestIterateNoBorders(data
, gfx::Rect(60, 20, 2, 21), 2, 0, 2, 1);
1208 TestIterateNoBorders(data
, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 3);
1209 TestIterateNoBorders(data
, gfx::Rect(-100, 10, 1000, 10), 0, 0, 2, 0);
1210 TestIterateNoBorders(data
, gfx::Rect(10, -100, 10, 1000), 0, 0, 0, 3);
1212 TestIterateNoBorders(data
, gfx::Rect(65, 110, 100, 100), 0, 0, -1, -1);
1215 TEST(TilingDataTest
, IteratorOneTile
) {
1216 TilingData
no_border(gfx::Size(1000, 1000), gfx::Size(30, 40), false);
1217 TestIterateAll(no_border
, gfx::Rect(30, 40), 0, 0, 0, 0);
1218 TestIterateAll(no_border
, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0);
1219 TestIterateAll(no_border
, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1);
1221 TilingData
one_border(gfx::Size(1000, 1000), gfx::Size(30, 40), true);
1222 TestIterateAll(one_border
, gfx::Rect(30, 40), 0, 0, 0, 0);
1223 TestIterateAll(one_border
, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0);
1224 TestIterateAll(one_border
, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1);
1226 TilingData
big_border(gfx::Size(1000, 1000), gfx::Size(30, 40), 50);
1227 TestIterateAll(big_border
, gfx::Rect(30, 40), 0, 0, 0, 0);
1228 TestIterateAll(big_border
, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0);
1229 TestIterateAll(big_border
, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1);
1232 TEST(TilingDataTest
, IteratorNoTiles
) {
1233 TilingData
data(gfx::Size(100, 100), gfx::Size(), false);
1234 TestIterateAll(data
, gfx::Rect(100, 100), 0, 0, -1, -1);
1237 void TestDiff(const TilingData
& data
,
1241 std::vector
<std::pair
<int, int>> expected
;
1242 for (int y
= 0; y
< data
.num_tiles_y(); ++y
) {
1243 for (int x
= 0; x
< data
.num_tiles_x(); ++x
) {
1244 gfx::Rect bounds
= data
.TileBounds(x
, y
);
1245 if (bounds
.Intersects(consider
) && !bounds
.Intersects(ignore
))
1246 expected
.push_back(std::make_pair(x
, y
));
1250 // Sanity check the test.
1251 EXPECT_EQ(num_tiles
, expected
.size());
1253 for (TilingData::DifferenceIterator
iter(&data
, consider
, ignore
); iter
;
1256 for (size_t i
= 0; i
< expected
.size(); ++i
) {
1257 if (expected
[i
] == iter
.index()) {
1258 expected
[i
] = expected
.back();
1259 expected
.pop_back();
1266 EXPECT_EQ(0u, expected
.size());
1269 TEST(TilingDataTest
, DifferenceIteratorIgnoreGeometry
) {
1270 // This test is checking that the iterator can handle different geometries of
1271 // ignore rects relative to the consider rect. The consider rect indices
1272 // themselves are mostly tested by the non-difference iterator tests, so the
1273 // full rect is mostly used here for simplicity.
1275 // X border index by src coord: [0-10), [10-20), [20, 30), [30, 40)
1276 // Y border index by src coord: [0-10), [10-20), [20, 25)
1277 TilingData
data(gfx::Size(10, 10), gfx::Size(40, 25), false);
1280 TestDiff(data
, gfx::Rect(40, 25), gfx::Rect(40, 25), 0);
1281 TestDiff(data
, gfx::Rect(40, 25), gfx::Rect(-100, -100, 200, 200), 0);
1282 TestDiff(data
, gfx::Rect(40, 25), gfx::Rect(9, 9, 30, 15), 0);
1283 TestDiff(data
, gfx::Rect(15, 15, 8, 8), gfx::Rect(15, 15, 8, 8), 0);
1286 TestDiff(data
, gfx::Rect(40, 25), gfx::Rect(-30, -20, 8, 8), 12);
1287 TestDiff(data
, gfx::Rect(40, 25), gfx::Rect(), 12);
1289 // Top left, remove 2x2 tiles
1290 TestDiff(data
, gfx::Rect(40, 25), gfx::Rect(20, 19), 8);
1291 // Bottom right, remove 2x2 tiles
1292 TestDiff(data
, gfx::Rect(40, 25), gfx::Rect(20, 15, 20, 6), 8);
1293 // Bottom left, remove 2x2 tiles
1294 TestDiff(data
, gfx::Rect(40, 25), gfx::Rect(0, 15, 20, 6), 8);
1295 // Top right, remove 2x2 tiles
1296 TestDiff(data
, gfx::Rect(40, 25), gfx::Rect(20, 0, 20, 19), 8);
1297 // Center, remove only one tile
1298 TestDiff(data
, gfx::Rect(40, 25), gfx::Rect(10, 10, 5, 5), 11);
1300 // Left column, flush left, removing two columns
1301 TestDiff(data
, gfx::Rect(40, 25), gfx::Rect(11, 25), 6);
1302 // Middle column, removing two columns
1303 TestDiff(data
, gfx::Rect(40, 25), gfx::Rect(11, 0, 11, 25), 6);
1304 // Right column, flush right, removing one column
1305 TestDiff(data
, gfx::Rect(40, 25), gfx::Rect(30, 0, 2, 25), 9);
1307 // Top row, flush top, removing one row
1308 TestDiff(data
, gfx::Rect(40, 25), gfx::Rect(0, 5, 40, 5), 8);
1309 // Middle row, removing one row
1310 TestDiff(data
, gfx::Rect(40, 25), gfx::Rect(0, 13, 40, 5), 8);
1311 // Bottom row, flush bottom, removing two rows
1312 TestDiff(data
, gfx::Rect(40, 25), gfx::Rect(0, 13, 40, 12), 4);
1314 // Non-intersecting, but still touching two of the same tiles.
1315 TestDiff(data
, gfx::Rect(8, 0, 32, 25), gfx::Rect(0, 12, 5, 12), 10);
1317 // Intersecting, but neither contains the other. 2x3 with one overlap.
1318 TestDiff(data
, gfx::Rect(5, 2, 20, 10), gfx::Rect(25, 15, 5, 10), 5);
1321 TEST(TilingDataTest
, DifferenceIteratorManyBorderTexels
) {
1322 // X border index by src coord: [0-50), [10-60), [20-65)
1323 // Y border index by src coord: [0-60), [20-80), [40-100), [60-110)
1324 // X tile bounds by src coord: [0-30), [30-40), [40-65)
1325 // Y tile bounds by src coord: [0-40), [40-60), [60-80), [80-110)
1326 TilingData
data(gfx::Size(50, 60), gfx::Size(65, 110), 20);
1328 // Knock out two rows, but not the left column.
1329 TestDiff(data
, gfx::Rect(10, 30, 55, 80), gfx::Rect(30, 59, 20, 2), 8);
1331 // Knock out one row.
1332 TestDiff(data
, gfx::Rect(10, 30, 55, 80), gfx::Rect(29, 59, 20, 1), 9);
1334 // Overlap all tiles with ignore rect.
1335 TestDiff(data
, gfx::Rect(65, 110), gfx::Rect(29, 39, 12, 42), 0);
1337 gfx::Rect tile
= data
.TileBounds(1, 1);
1340 TestDiff(data
, gfx::Rect(20, 30, 45, 80), tile
, 11);
1342 // Include one tile.
1343 TestDiff(data
, tile
, gfx::Rect(), 1);
1346 TEST(TilingDataTest
, DifferenceIteratorOneTile
) {
1347 TilingData
no_border(gfx::Size(1000, 1000), gfx::Size(30, 40), false);
1348 TestDiff(no_border
, gfx::Rect(30, 40), gfx::Rect(), 1);
1349 TestDiff(no_border
, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0);
1351 TilingData
one_border(gfx::Size(1000, 1000), gfx::Size(30, 40), true);
1352 TestDiff(one_border
, gfx::Rect(30, 40), gfx::Rect(), 1);
1353 TestDiff(one_border
, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0);
1355 TilingData
big_border(gfx::Size(1000, 1000), gfx::Size(30, 40), 50);
1356 TestDiff(big_border
, gfx::Rect(30, 40), gfx::Rect(), 1);
1357 TestDiff(big_border
, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0);
1360 TEST(TilingDataTest
, DifferenceIteratorNoTiles
) {
1361 TilingData
data(gfx::Size(100, 100), gfx::Size(), false);
1362 TestDiff(data
, gfx::Rect(100, 100), gfx::Rect(5, 5), 0);
1365 void TestSpiralIterate(int source_line_number
,
1366 const TilingData
& tiling_data
,
1367 const gfx::Rect
& consider
,
1368 const gfx::Rect
& ignore
,
1369 const gfx::Rect
& center
,
1370 const std::vector
<std::pair
<int, int>>& expected
) {
1371 std::vector
<std::pair
<int, int>> actual_forward
;
1372 for (TilingData::SpiralDifferenceIterator
it(
1373 &tiling_data
, consider
, ignore
, center
);
1376 actual_forward
.push_back(it
.index());
1379 EXPECT_EQ(expected
.size(), actual_forward
.size()) << "error from line "
1380 << source_line_number
;
1381 for (size_t i
= 0; i
< std::min(expected
.size(), actual_forward
.size());
1383 EXPECT_EQ(expected
[i
].first
, actual_forward
[i
].first
)
1384 << "i: " << i
<< " error from line: " << source_line_number
;
1385 EXPECT_EQ(expected
[i
].second
, actual_forward
[i
].second
)
1386 << "i: " << i
<< " error from line: " << source_line_number
;
1389 std::vector
<std::pair
<int, int>> actual_reverse
;
1390 for (TilingData::ReverseSpiralDifferenceIterator
it(
1391 &tiling_data
, consider
, ignore
, center
);
1394 actual_reverse
.push_back(it
.index());
1397 std::vector
<std::pair
<int, int>> reversed_expected
= expected
;
1398 std::reverse(reversed_expected
.begin(), reversed_expected
.end());
1399 EXPECT_EQ(reversed_expected
.size(), actual_reverse
.size())
1400 << "error from line " << source_line_number
;
1402 i
< std::min(reversed_expected
.size(), actual_reverse
.size());
1404 EXPECT_EQ(reversed_expected
[i
].first
, actual_reverse
[i
].first
)
1405 << "i: " << i
<< " error from line: " << source_line_number
;
1406 EXPECT_EQ(reversed_expected
[i
].second
, actual_reverse
[i
].second
)
1407 << "i: " << i
<< " error from line: " << source_line_number
;
1411 TEST(TilingDataTest
, SpiralDifferenceIteratorNoIgnoreFullConsider
) {
1412 TilingData
tiling_data(gfx::Size(10, 10), gfx::Size(30, 30), false);
1413 gfx::Rect
consider(30, 30);
1415 std::vector
<std::pair
<int, int>> expected
;
1417 // Center is in the center of the tiling.
1418 gfx::Rect
center(15, 15, 1, 1);
1420 // Layout of the tiling data, and expected return order:
1426 expected
.push_back(std::make_pair(2, 1));
1427 expected
.push_back(std::make_pair(2, 0));
1428 expected
.push_back(std::make_pair(1, 0));
1429 expected
.push_back(std::make_pair(0, 0));
1430 expected
.push_back(std::make_pair(0, 1));
1431 expected
.push_back(std::make_pair(0, 2));
1432 expected
.push_back(std::make_pair(1, 2));
1433 expected
.push_back(std::make_pair(2, 2));
1435 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1437 // Center is off to the right side of the tiling (and far away).
1438 center
= gfx::Rect(100, 15, 1, 1);
1440 // Layout of the tiling data, and expected return order:
1447 expected
.push_back(std::make_pair(2, 0));
1448 expected
.push_back(std::make_pair(2, 1));
1449 expected
.push_back(std::make_pair(2, 2));
1450 expected
.push_back(std::make_pair(1, 0));
1451 expected
.push_back(std::make_pair(1, 1));
1452 expected
.push_back(std::make_pair(1, 2));
1453 expected
.push_back(std::make_pair(0, 0));
1454 expected
.push_back(std::make_pair(0, 1));
1455 expected
.push_back(std::make_pair(0, 2));
1457 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1459 // Center is the bottom right corner of the tiling.
1460 center
= gfx::Rect(25, 25, 1, 1);
1462 // Layout of the tiling data, and expected return order:
1469 expected
.push_back(std::make_pair(2, 1));
1470 expected
.push_back(std::make_pair(1, 1));
1471 expected
.push_back(std::make_pair(1, 2));
1472 expected
.push_back(std::make_pair(2, 0));
1473 expected
.push_back(std::make_pair(1, 0));
1474 expected
.push_back(std::make_pair(0, 0));
1475 expected
.push_back(std::make_pair(0, 1));
1476 expected
.push_back(std::make_pair(0, 2));
1478 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1480 // Center is off the top left side of the tiling.
1481 center
= gfx::Rect(-60, -50, 1, 1);
1483 // Layout of the tiling data, and expected return order:
1490 expected
.push_back(std::make_pair(0, 0));
1491 expected
.push_back(std::make_pair(1, 0));
1492 expected
.push_back(std::make_pair(0, 1));
1493 expected
.push_back(std::make_pair(1, 1));
1494 expected
.push_back(std::make_pair(2, 1));
1495 expected
.push_back(std::make_pair(2, 0));
1496 expected
.push_back(std::make_pair(0, 2));
1497 expected
.push_back(std::make_pair(1, 2));
1498 expected
.push_back(std::make_pair(2, 2));
1500 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1503 center
= gfx::Rect(15, 15, 1, 10);
1505 // Layout of the tiling data, and expected return order:
1512 expected
.push_back(std::make_pair(2, 2));
1513 expected
.push_back(std::make_pair(2, 1));
1514 expected
.push_back(std::make_pair(2, 0));
1515 expected
.push_back(std::make_pair(1, 0));
1516 expected
.push_back(std::make_pair(0, 0));
1517 expected
.push_back(std::make_pair(0, 1));
1518 expected
.push_back(std::make_pair(0, 2));
1520 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1523 TEST(TilingDataTest
, SpiralDifferenceIteratorSmallConsider
) {
1524 TilingData
tiling_data(gfx::Size(10, 10), gfx::Size(50, 50), false);
1526 std::vector
<std::pair
<int, int>> expected
;
1527 gfx::Rect
center(15, 15, 1, 1);
1529 // Consider is one cell.
1530 gfx::Rect
consider(1, 1);
1532 // Layout of the tiling data, and expected return order:
1540 expected
.push_back(std::make_pair(0, 0));
1542 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1544 // Consider is bottom right corner.
1545 consider
= gfx::Rect(25, 25, 10, 10);
1547 // Layout of the tiling data, and expected return order:
1556 expected
.push_back(std::make_pair(2, 2));
1557 expected
.push_back(std::make_pair(3, 2));
1558 expected
.push_back(std::make_pair(2, 3));
1559 expected
.push_back(std::make_pair(3, 3));
1561 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1563 // Consider is one column.
1564 consider
= gfx::Rect(11, 0, 1, 100);
1566 // Layout of the tiling data, and expected return order:
1575 expected
.push_back(std::make_pair(1, 0));
1576 expected
.push_back(std::make_pair(1, 2));
1577 expected
.push_back(std::make_pair(1, 3));
1578 expected
.push_back(std::make_pair(1, 4));
1580 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1583 TEST(TilingDataTest
, SpiralDifferenceIteratorHasIgnore
) {
1584 TilingData
tiling_data(gfx::Size(10, 10), gfx::Size(50, 50), false);
1585 gfx::Rect
consider(50, 50);
1586 std::vector
<std::pair
<int, int>> expected
;
1587 gfx::Rect
center(15, 15, 1, 1);
1590 gfx::Rect
ignore(50, 50);
1592 // Layout of the tiling data, and expected return order:
1602 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1605 ignore
= gfx::Rect(15, 0, 20, 100);
1607 // Layout of the tiling data, and expected return order:
1617 expected
.push_back(std::make_pair(0, 0));
1618 expected
.push_back(std::make_pair(0, 1));
1619 expected
.push_back(std::make_pair(0, 2));
1620 expected
.push_back(std::make_pair(0, 3));
1621 expected
.push_back(std::make_pair(4, 3));
1622 expected
.push_back(std::make_pair(4, 2));
1623 expected
.push_back(std::make_pair(4, 1));
1624 expected
.push_back(std::make_pair(4, 0));
1625 expected
.push_back(std::make_pair(0, 4));
1626 expected
.push_back(std::make_pair(4, 4));
1628 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1630 // Ignore covers the top half.
1631 ignore
= gfx::Rect(50, 25);
1633 // Layout of the tiling data, and expected return order:
1643 expected
.push_back(std::make_pair(0, 3));
1644 expected
.push_back(std::make_pair(1, 3));
1645 expected
.push_back(std::make_pair(2, 3));
1646 expected
.push_back(std::make_pair(3, 3));
1647 expected
.push_back(std::make_pair(4, 3));
1648 expected
.push_back(std::make_pair(0, 4));
1649 expected
.push_back(std::make_pair(1, 4));
1650 expected
.push_back(std::make_pair(2, 4));
1651 expected
.push_back(std::make_pair(3, 4));
1652 expected
.push_back(std::make_pair(4, 4));
1654 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1657 TEST(TilingDataTest
, SpiralDifferenceIteratorRectangleCenter
) {
1658 TilingData
tiling_data(gfx::Size(10, 10), gfx::Size(50, 50), false);
1659 gfx::Rect
consider(50, 50);
1660 std::vector
<std::pair
<int, int>> expected
;
1664 gfx::Rect
center(25, 25, 1, 10);
1666 // Layout of the tiling data, and expected return order:
1676 expected
.push_back(std::make_pair(3, 3));
1677 expected
.push_back(std::make_pair(3, 2));
1678 expected
.push_back(std::make_pair(3, 1));
1679 expected
.push_back(std::make_pair(2, 1));
1680 expected
.push_back(std::make_pair(1, 1));
1681 expected
.push_back(std::make_pair(1, 2));
1682 expected
.push_back(std::make_pair(1, 3));
1683 expected
.push_back(std::make_pair(1, 4));
1684 expected
.push_back(std::make_pair(2, 4));
1685 expected
.push_back(std::make_pair(3, 4));
1686 expected
.push_back(std::make_pair(4, 4));
1687 expected
.push_back(std::make_pair(4, 3));
1688 expected
.push_back(std::make_pair(4, 2));
1689 expected
.push_back(std::make_pair(4, 1));
1690 expected
.push_back(std::make_pair(4, 0));
1691 expected
.push_back(std::make_pair(3, 0));
1692 expected
.push_back(std::make_pair(2, 0));
1693 expected
.push_back(std::make_pair(1, 0));
1694 expected
.push_back(std::make_pair(0, 0));
1695 expected
.push_back(std::make_pair(0, 1));
1696 expected
.push_back(std::make_pair(0, 2));
1697 expected
.push_back(std::make_pair(0, 3));
1698 expected
.push_back(std::make_pair(0, 4));
1700 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1702 // Three by two center.
1703 center
= gfx::Rect(15, 25, 20, 10);
1705 // Layout of the tiling data, and expected return order:
1715 expected
.push_back(std::make_pair(4, 3));
1716 expected
.push_back(std::make_pair(4, 2));
1717 expected
.push_back(std::make_pair(4, 1));
1718 expected
.push_back(std::make_pair(3, 1));
1719 expected
.push_back(std::make_pair(2, 1));
1720 expected
.push_back(std::make_pair(1, 1));
1721 expected
.push_back(std::make_pair(0, 1));
1722 expected
.push_back(std::make_pair(0, 2));
1723 expected
.push_back(std::make_pair(0, 3));
1724 expected
.push_back(std::make_pair(0, 4));
1725 expected
.push_back(std::make_pair(1, 4));
1726 expected
.push_back(std::make_pair(2, 4));
1727 expected
.push_back(std::make_pair(3, 4));
1728 expected
.push_back(std::make_pair(4, 4));
1729 expected
.push_back(std::make_pair(4, 0));
1730 expected
.push_back(std::make_pair(3, 0));
1731 expected
.push_back(std::make_pair(2, 0));
1732 expected
.push_back(std::make_pair(1, 0));
1733 expected
.push_back(std::make_pair(0, 0));
1735 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1737 // Column center off the left side.
1738 center
= gfx::Rect(-50, 0, 30, 50);
1740 // Layout of the tiling data, and expected return order:
1750 expected
.push_back(std::make_pair(0, 4));
1751 expected
.push_back(std::make_pair(0, 3));
1752 expected
.push_back(std::make_pair(0, 2));
1753 expected
.push_back(std::make_pair(0, 1));
1754 expected
.push_back(std::make_pair(0, 0));
1755 expected
.push_back(std::make_pair(1, 4));
1756 expected
.push_back(std::make_pair(1, 3));
1757 expected
.push_back(std::make_pair(1, 2));
1758 expected
.push_back(std::make_pair(1, 1));
1759 expected
.push_back(std::make_pair(1, 0));
1760 expected
.push_back(std::make_pair(2, 4));
1761 expected
.push_back(std::make_pair(2, 3));
1762 expected
.push_back(std::make_pair(2, 2));
1763 expected
.push_back(std::make_pair(2, 1));
1764 expected
.push_back(std::make_pair(2, 0));
1765 expected
.push_back(std::make_pair(3, 4));
1766 expected
.push_back(std::make_pair(3, 3));
1767 expected
.push_back(std::make_pair(3, 2));
1768 expected
.push_back(std::make_pair(3, 1));
1769 expected
.push_back(std::make_pair(3, 0));
1770 expected
.push_back(std::make_pair(4, 4));
1771 expected
.push_back(std::make_pair(4, 3));
1772 expected
.push_back(std::make_pair(4, 2));
1773 expected
.push_back(std::make_pair(4, 1));
1774 expected
.push_back(std::make_pair(4, 0));
1776 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1779 TEST(TilingDataTest
, SpiralDifferenceIteratorEdgeCases
) {
1780 TilingData
tiling_data(gfx::Size(10, 10), gfx::Size(30, 30), false);
1781 std::vector
<std::pair
<int, int>> expected
;
1786 // Ignore contains, but is not equal to, consider and center.
1787 ignore
= gfx::Rect(15, 0, 20, 30);
1788 consider
= gfx::Rect(20, 10, 10, 20);
1789 center
= gfx::Rect(25, 0, 5, 5);
1791 // Layout of the tiling data, and expected return order:
1799 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1801 // Center intersects with consider.
1802 ignore
= gfx::Rect();
1803 center
= gfx::Rect(0, 15, 30, 15);
1804 consider
= gfx::Rect(15, 30);
1806 // Layout of the tiling data, and expected return order:
1814 expected
.push_back(std::make_pair(1, 0));
1815 expected
.push_back(std::make_pair(0, 0));
1817 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1819 // Consider and ignore are non-intersecting.
1820 ignore
= gfx::Rect(5, 30);
1821 consider
= gfx::Rect(25, 0, 5, 30);
1822 center
= gfx::Rect(15, 0, 1, 1);
1824 // Layout of the tiling data, and expected return order:
1832 expected
.push_back(std::make_pair(2, 0));
1833 expected
.push_back(std::make_pair(2, 1));
1834 expected
.push_back(std::make_pair(2, 2));
1836 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1838 // Center intersects with ignore.
1839 consider
= gfx::Rect(30, 30);
1840 center
= gfx::Rect(15, 0, 1, 30);
1841 ignore
= gfx::Rect(0, 15, 30, 1);
1843 // Layout of the tiling data, and expected return order:
1851 expected
.push_back(std::make_pair(2, 2));
1852 expected
.push_back(std::make_pair(2, 0));
1853 expected
.push_back(std::make_pair(0, 0));
1854 expected
.push_back(std::make_pair(0, 2));
1856 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1858 // Center and ignore are the same.
1859 consider
= gfx::Rect(30, 30);
1860 center
= gfx::Rect(15, 0, 1, 30);
1863 // Layout of the tiling data, and expected return order:
1871 expected
.push_back(std::make_pair(2, 2));
1872 expected
.push_back(std::make_pair(2, 1));
1873 expected
.push_back(std::make_pair(2, 0));
1874 expected
.push_back(std::make_pair(0, 0));
1875 expected
.push_back(std::make_pair(0, 1));
1876 expected
.push_back(std::make_pair(0, 2));
1878 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1880 // Empty tiling data.
1881 TilingData
empty_data(gfx::Size(0, 0), gfx::Size(0, 0), false);
1884 TestSpiralIterate(__LINE__
, empty_data
, consider
, ignore
, center
, expected
);
1887 ignore
= gfx::Rect();
1888 center
= gfx::Rect(1, 1, 1, 1);
1889 consider
= gfx::Rect();
1892 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1894 // Empty center. Note: This arbitrarily puts the center to be off the top-left
1896 consider
= gfx::Rect(30, 30);
1897 ignore
= gfx::Rect();
1898 center
= gfx::Rect();
1900 // Layout of the tiling data, and expected return order:
1908 expected
.push_back(std::make_pair(0, 0));
1909 expected
.push_back(std::make_pair(1, 0));
1910 expected
.push_back(std::make_pair(0, 1));
1911 expected
.push_back(std::make_pair(1, 1));
1912 expected
.push_back(std::make_pair(2, 1));
1913 expected
.push_back(std::make_pair(2, 0));
1914 expected
.push_back(std::make_pair(0, 2));
1915 expected
.push_back(std::make_pair(1, 2));
1916 expected
.push_back(std::make_pair(2, 2));
1918 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1920 // Every rect is empty.
1921 ignore
= gfx::Rect();
1922 center
= gfx::Rect();
1923 consider
= gfx::Rect();
1926 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);
1928 // Center is just to the left of cover, and off of the tiling's left side.
1929 consider
= gfx::Rect(30, 30);
1930 ignore
= gfx::Rect();
1931 center
= gfx::Rect(-20, 0, 19, 30);
1933 // Layout of the tiling data, and expected return order:
1941 expected
.push_back(std::make_pair(0, 2));
1942 expected
.push_back(std::make_pair(0, 1));
1943 expected
.push_back(std::make_pair(0, 0));
1944 expected
.push_back(std::make_pair(1, 2));
1945 expected
.push_back(std::make_pair(1, 1));
1946 expected
.push_back(std::make_pair(1, 0));
1947 expected
.push_back(std::make_pair(2, 2));
1948 expected
.push_back(std::make_pair(2, 1));
1949 expected
.push_back(std::make_pair(2, 0));
1951 TestSpiralIterate(__LINE__
, tiling_data
, consider
, ignore
, center
, expected
);