1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
#include <iostream>
#include "../util.hpp"
#include <algorithm>
#include <mbgl/util/clip_ids.hpp>
#include <mbgl/util/std.hpp>
using namespace mbgl;
template <typename T> void generate(const T &sources) {
ClipIDGenerator generator;
for (size_t j = 0; j < sources.size(); j++) {
std::forward_list<Tile *> tile_ptrs;
std::transform(sources[j].begin(), sources[j].end(), std::front_inserter(tile_ptrs), [](const std::shared_ptr<Tile> &tile) { return tile.get(); });
generator.update(tile_ptrs);
}
}
template <typename T> void print(const T &sources) {
for (size_t j = 0; j < sources.size(); j++) {
for (size_t i = 0; i < sources[j].size(); i++) {
std::cout << " ASSERT_EQ(ClipID(\"" << sources[j][i]->clip.mask << "\", \"" << sources[j][i]->clip.reference << "\"), sources[" << j << "][" << i << "]->clip);\n";
}
}
}
TEST(ClipIDs, ParentAndFourChildren) {
const std::vector<std::vector<std::shared_ptr<Tile>>> sources = {
{
std::make_shared<Tile>(Tile::ID { 1, 0, 0 }),
std::make_shared<Tile>(Tile::ID { 1, 0, 1 }),
std::make_shared<Tile>(Tile::ID { 1, 1, 0 }),
std::make_shared<Tile>(Tile::ID { 1, 1, 1 }),
std::make_shared<Tile>(Tile::ID { 0, 0, 0 }),
},
};
generate(sources);
// print(sources);
ASSERT_EQ(ClipID("00000111", "00000010"), sources[0][0]->clip);
ASSERT_EQ(ClipID("00000111", "00000011"), sources[0][1]->clip);
ASSERT_EQ(ClipID("00000111", "00000100"), sources[0][2]->clip);
ASSERT_EQ(ClipID("00000111", "00000101"), sources[0][3]->clip);
ASSERT_EQ(ClipID("00000111", "00000001"), sources[0][4]->clip);
}
TEST(ClipIDs, ParentAndFourChildrenNegative) {
const std::vector<std::vector<std::shared_ptr<Tile>>> sources = {
{
std::make_shared<Tile>(Tile::ID { 1, -2, 0 }),
std::make_shared<Tile>(Tile::ID { 1, -2, 1 }),
std::make_shared<Tile>(Tile::ID { 1, -1, 0 }),
std::make_shared<Tile>(Tile::ID { 1, -1, 1 }),
std::make_shared<Tile>(Tile::ID { 0, -1, 0 }),
},
};
generate(sources);
// print(sources);
ASSERT_EQ(ClipID("00000111", "00000010"), sources[0][0]->clip);
ASSERT_EQ(ClipID("00000111", "00000011"), sources[0][1]->clip);
ASSERT_EQ(ClipID("00000111", "00000100"), sources[0][2]->clip);
ASSERT_EQ(ClipID("00000111", "00000101"), sources[0][3]->clip);
ASSERT_EQ(ClipID("00000111", "00000001"), sources[0][4]->clip);
}
TEST(ClipIDs, NegativeParentAndMissingLevel) {
const std::vector<std::vector<std::shared_ptr<Tile>>> sources = {
{
std::make_shared<Tile>(Tile::ID { 1, -1, 0 }),
std::make_shared<Tile>(Tile::ID { 2, -1, 0 }),
std::make_shared<Tile>(Tile::ID { 2, -2, 1 }),
std::make_shared<Tile>(Tile::ID { 2, -1, 1 }),
std::make_shared<Tile>(Tile::ID { 2, -2, 0 }),
},
};
generate(sources);
// print(sources);
ASSERT_EQ(ClipID("00000111", "00000001"), sources[0][0]->clip);
ASSERT_EQ(ClipID("00000111", "00000100"), sources[0][1]->clip);
ASSERT_EQ(ClipID("00000111", "00000011"), sources[0][2]->clip);
ASSERT_EQ(ClipID("00000111", "00000101"), sources[0][3]->clip);
ASSERT_EQ(ClipID("00000111", "00000010"), sources[0][4]->clip);
}
TEST(ClipIDs, SevenOnSameLevel) {
const std::vector<std::vector<std::shared_ptr<Tile>>> sources = {
{
std::make_shared<Tile>(Tile::ID { 2, 0, 0 }),
std::make_shared<Tile>(Tile::ID { 2, 0, 1 }),
std::make_shared<Tile>(Tile::ID { 2, 0, 2 }),
std::make_shared<Tile>(Tile::ID { 2, 1, 0 }),
std::make_shared<Tile>(Tile::ID { 2, 1, 1 }),
std::make_shared<Tile>(Tile::ID { 2, 1, 2 }),
std::make_shared<Tile>(Tile::ID { 2, 2, 0 }),
},
};
generate(sources);
// print(sources);
ASSERT_EQ(ClipID("00000111", "00000001"), sources[0][0]->clip);
ASSERT_EQ(ClipID("00000111", "00000010"), sources[0][1]->clip);
ASSERT_EQ(ClipID("00000111", "00000011"), sources[0][2]->clip);
ASSERT_EQ(ClipID("00000111", "00000100"), sources[0][3]->clip);
ASSERT_EQ(ClipID("00000111", "00000101"), sources[0][4]->clip);
ASSERT_EQ(ClipID("00000111", "00000110"), sources[0][5]->clip);
ASSERT_EQ(ClipID("00000111", "00000111"), sources[0][6]->clip);
}
TEST(ClipIDs, MultipleLevels) {
const std::vector<std::vector<std::shared_ptr<Tile>>> sources = {
{
std::make_shared<Tile>(Tile::ID { 2, 0, 0 }),
std::make_shared<Tile>(Tile::ID { 3, 0, 0 }),
std::make_shared<Tile>(Tile::ID { 3, 0, 1 }),
std::make_shared<Tile>(Tile::ID { 4, 0, 2 }),
std::make_shared<Tile>(Tile::ID { 4, 1, 2 }),
std::make_shared<Tile>(Tile::ID { 4, 0, 3 }),
std::make_shared<Tile>(Tile::ID { 4, 1, 3 }),
std::make_shared<Tile>(Tile::ID { 3, 1, 0 }),
std::make_shared<Tile>(Tile::ID { 3, 1, 1 }),
std::make_shared<Tile>(Tile::ID { 2, 1, 0 }),
std::make_shared<Tile>(Tile::ID { 3, 2, 0 }),
std::make_shared<Tile>(Tile::ID { 3, 2, 1 }),
},
};
generate(sources);
// print(sources);
ASSERT_EQ(ClipID("00001111", "00000001"), sources[0][0]->clip);
ASSERT_EQ(ClipID("00001111", "00000011"), sources[0][1]->clip);
ASSERT_EQ(ClipID("00001111", "00000100"), sources[0][2]->clip);
ASSERT_EQ(ClipID("00001111", "00001001"), sources[0][3]->clip);
ASSERT_EQ(ClipID("00001111", "00001011"), sources[0][4]->clip);
ASSERT_EQ(ClipID("00001111", "00001010"), sources[0][5]->clip);
ASSERT_EQ(ClipID("00001111", "00001100"), sources[0][6]->clip);
ASSERT_EQ(ClipID("00001111", "00000101"), sources[0][7]->clip);
ASSERT_EQ(ClipID("00001111", "00000110"), sources[0][8]->clip);
ASSERT_EQ(ClipID("00001111", "00000010"), sources[0][9]->clip);
ASSERT_EQ(ClipID("00001111", "00000111"), sources[0][10]->clip);
ASSERT_EQ(ClipID("00001111", "00001000"), sources[0][11]->clip);
}
TEST(ClipIDs, Bug206) {
const std::vector<std::vector<std::shared_ptr<Tile>>> sources = {
{
std::make_shared<Tile>(Tile::ID { 10, 162, 395 }),
std::make_shared<Tile>(Tile::ID { 10, 162, 396 }),
std::make_shared<Tile>(Tile::ID { 10, 163, 395 }),
std::make_shared<Tile>(Tile::ID { 11, 326, 791 }),
std::make_shared<Tile>(Tile::ID { 12, 654, 1582 }),
std::make_shared<Tile>(Tile::ID { 12, 654, 1583 }),
std::make_shared<Tile>(Tile::ID { 12, 655, 1582 }),
std::make_shared<Tile>(Tile::ID { 12, 655, 1583 }),
std::make_shared<Tile>(Tile::ID { 10, 163, 396 }),
std::make_shared<Tile>(Tile::ID { 10, 164, 395 }),
std::make_shared<Tile>(Tile::ID { 10, 164, 396 }),
},
};
generate(sources);
// print(sources);
ASSERT_EQ(ClipID("00001111", "00000001"), sources[0][0]->clip);
ASSERT_EQ(ClipID("00001111", "00000010"), sources[0][1]->clip);
ASSERT_EQ(ClipID("00001111", "00000011"), sources[0][2]->clip);
ASSERT_EQ(ClipID("00001111", "00000111"), sources[0][3]->clip);
ASSERT_EQ(ClipID("00001111", "00001000"), sources[0][4]->clip);
ASSERT_EQ(ClipID("00001111", "00001001"), sources[0][5]->clip);
ASSERT_EQ(ClipID("00001111", "00001010"), sources[0][6]->clip);
ASSERT_EQ(ClipID("00001111", "00001011"), sources[0][7]->clip);
ASSERT_EQ(ClipID("00001111", "00000100"), sources[0][8]->clip);
ASSERT_EQ(ClipID("00001111", "00000101"), sources[0][9]->clip);
ASSERT_EQ(ClipID("00001111", "00000110"), sources[0][10]->clip);
}
TEST(ClipIDs, MultipleSources) {
const std::vector<std::vector<std::shared_ptr<Tile>>> sources = {
{
std::make_shared<Tile>(Tile::ID { 0, 0, 0 }),
std::make_shared<Tile>(Tile::ID { 1, 1, 1 }),
std::make_shared<Tile>(Tile::ID { 2, 2, 1 }),
std::make_shared<Tile>(Tile::ID { 2, 2, 2 }),
},
{
std::make_shared<Tile>(Tile::ID { 0, 0, 0 }),
std::make_shared<Tile>(Tile::ID { 1, 1, 1 }),
std::make_shared<Tile>(Tile::ID { 2, 1, 1 }),
std::make_shared<Tile>(Tile::ID { 2, 2, 2 }),
},
{
std::make_shared<Tile>(Tile::ID { 1, 0, 0 }),
std::make_shared<Tile>(Tile::ID { 1, 0, 1 }),
std::make_shared<Tile>(Tile::ID { 1, 1, 0 }),
std::make_shared<Tile>(Tile::ID { 1, 1, 1 }),
std::make_shared<Tile>(Tile::ID { 2, 1, 1 }),
},
};
generate(sources);
// print(sources);
ASSERT_EQ(ClipID("00000111", "00000001"), sources[0][0]->clip);
ASSERT_EQ(ClipID("00000111", "00000010"), sources[0][1]->clip);
ASSERT_EQ(ClipID("00000111", "00000011"), sources[0][2]->clip);
ASSERT_EQ(ClipID("00000111", "00000100"), sources[0][3]->clip);
ASSERT_EQ(ClipID("00011000", "00001000"), sources[1][0]->clip);
ASSERT_EQ(ClipID("00000111", "00000010"), sources[1][1]->clip);
ASSERT_EQ(ClipID("00011000", "00010000"), sources[1][2]->clip);
ASSERT_EQ(ClipID("00000111", "00000100"), sources[1][3]->clip);
ASSERT_EQ(ClipID("11100000", "00100000"), sources[2][0]->clip);
ASSERT_EQ(ClipID("11100000", "01000000"), sources[2][1]->clip);
ASSERT_EQ(ClipID("11100000", "01100000"), sources[2][2]->clip);
ASSERT_EQ(ClipID("11100000", "10000000"), sources[2][3]->clip);
ASSERT_EQ(ClipID("00011000", "00010000"), sources[2][4]->clip);
}
TEST(ClipIDs, DuplicateIDs) {
const std::vector<std::vector<std::shared_ptr<Tile>>> sources = {
{
std::make_shared<Tile>(Tile::ID { 2, 0, 0 }),
std::make_shared<Tile>(Tile::ID { 2, 0, 1 }),
},
{
std::make_shared<Tile>(Tile::ID { 2, 0, 0 }),
std::make_shared<Tile>(Tile::ID { 2, 0, 1 }),
std::make_shared<Tile>(Tile::ID { 2, 0, 1 }),
}
};
generate(sources);
// print(sources);
ASSERT_EQ(ClipID("00000011", "00000001"), sources[0][0]->clip);
ASSERT_EQ(ClipID("00000011", "00000010"), sources[0][1]->clip);
ASSERT_EQ(ClipID("00000011", "00000001"), sources[1][0]->clip);
ASSERT_EQ(ClipID("00000011", "00000010"), sources[1][1]->clip);
ASSERT_EQ(ClipID("00000011", "00000010"), sources[1][2]->clip);
}
|