Skip to content

Commit efb0072

Browse files
authored
Merge pull request #1883 from joto/expire-code-fiddling
Expire code fiddling
2 parents 41ec9ca + c9245c1 commit efb0072

File tree

2 files changed

+102
-4
lines changed

2 files changed

+102
-4
lines changed

src/expire-tiles.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ void expire_tiles::from_line(geom::point_t const &a, geom::point_t const &b)
173173
but for simplicity, treat the coordinates as a bounding box
174174
and expire everything within that box. */
175175
if (y1 > y2) {
176-
double const temp = y2;
177-
y2 = y1;
178-
y1 = temp;
176+
std::swap(y1, y2);
179177
}
180178
for (int x = x1 - tile_expiry_leeway; x <= x2 + tile_expiry_leeway;
181179
++x) {
@@ -257,7 +255,8 @@ void expire_tiles::merge_and_destroy(expire_tiles *other)
257255
}
258256

259257
if (m_dirty_tiles.empty()) {
260-
m_dirty_tiles = std::move(other->m_dirty_tiles);
258+
using std::swap;
259+
swap(m_dirty_tiles, other->m_dirty_tiles);
261260
} else {
262261
m_dirty_tiles.insert(other->m_dirty_tiles.begin(),
263262
other->m_dirty_tiles.end());

tests/test-expire-tiles.cpp

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,105 @@ TEST_CASE("simple expire z18", "[NoDB]")
144144
CHECK(*(itr++) == tile_t(18, 131072, 131072));
145145
}
146146

147+
TEST_CASE("expire a simple line", "[NoDB]")
148+
{
149+
uint32_t const zoom = 18;
150+
expire_tiles et{zoom, 20000, defproj};
151+
152+
et.from_geometry(
153+
geom::linestring_t{{1398725.0, 7493354.0}, {1399030.0, 7493354.0}});
154+
155+
auto const tiles = get_tiles_ordered(&et, zoom, zoom);
156+
CHECK(tiles.size() == 3);
157+
158+
auto itr = tiles.begin();
159+
CHECK(*(itr++) == tile_t(18, 140221, 82055));
160+
CHECK(*(itr++) == tile_t(18, 140222, 82055));
161+
CHECK(*(itr++) == tile_t(18, 140223, 82055));
162+
}
163+
164+
TEST_CASE("expire a line near the tile border", "[NoDB]")
165+
{
166+
uint32_t const zoom = 18;
167+
expire_tiles et{zoom, 20000, defproj};
168+
169+
et.from_geometry(
170+
geom::linestring_t{{1398945.0, 7493267.0}, {1398960.0, 7493282.0}});
171+
172+
auto const tiles = get_tiles_ordered(&et, zoom, zoom);
173+
REQUIRE(tiles.size() == 4);
174+
175+
auto itr = tiles.begin();
176+
CHECK(*(itr++) == tile_t(18, 140222, 82055));
177+
CHECK(*(itr++) == tile_t(18, 140223, 82055));
178+
CHECK(*(itr++) == tile_t(18, 140222, 82056));
179+
CHECK(*(itr++) == tile_t(18, 140223, 82056));
180+
}
181+
182+
TEST_CASE("expire a u-shaped linestring", "[NoDB]")
183+
{
184+
uint32_t const zoom = 18;
185+
expire_tiles et{zoom, 20000, defproj};
186+
187+
et.from_geometry(geom::linestring_t{{1398586.0, 7493485.0},
188+
{1398575.0, 7493347.0},
189+
{1399020.0, 7493344.0},
190+
{1399012.0, 7493470.0}});
191+
192+
auto const tiles = get_tiles_unordered(&et, zoom);
193+
REQUIRE(tiles.size() == 6);
194+
195+
CHECK(tiles.count(tile_t(18, 140220, 82054)) == 1);
196+
CHECK(tiles.count(tile_t(18, 140220, 82055)) == 1);
197+
CHECK(tiles.count(tile_t(18, 140221, 82055)) == 1);
198+
CHECK(tiles.count(tile_t(18, 140222, 82055)) == 1);
199+
CHECK(tiles.count(tile_t(18, 140223, 82055)) == 1);
200+
CHECK(tiles.count(tile_t(18, 140223, 82054)) == 1);
201+
}
202+
203+
TEST_CASE("expire longer horizontal line", "[NoDB]")
204+
{
205+
uint32_t const zoom = 18;
206+
expire_tiles et{zoom, 20000, defproj};
207+
208+
et.from_geometry(
209+
geom::linestring_t{{1397815.0, 7493800.0}, {1399316.0, 7493780.0}});
210+
211+
auto const tiles = get_tiles_unordered(&et, zoom);
212+
REQUIRE(tiles.size() == 11);
213+
214+
for (uint32_t x = 140215; x <= 140225; ++x) {
215+
CHECK(tiles.count(tile_t(18, x, 82052)) == 1);
216+
}
217+
}
218+
219+
TEST_CASE("expire longer diagonal line", "[NoDB]")
220+
{
221+
uint32_t const zoom = 18;
222+
expire_tiles et{zoom, 20000, defproj};
223+
224+
et.from_geometry(
225+
geom::linestring_t{{1398427.0, 7494118.0}, {1398869.0, 7493189.0}});
226+
227+
auto const tiles = get_tiles_unordered(&et, zoom);
228+
REQUIRE(tiles.size() == 14);
229+
230+
CHECK(tiles.count(tile_t(18, 140219, 82050)) == 1);
231+
CHECK(tiles.count(tile_t(18, 140220, 82050)) == 1);
232+
CHECK(tiles.count(tile_t(18, 140219, 82051)) == 1);
233+
CHECK(tiles.count(tile_t(18, 140220, 82051)) == 1);
234+
CHECK(tiles.count(tile_t(18, 140219, 82052)) == 1);
235+
CHECK(tiles.count(tile_t(18, 140220, 82052)) == 1);
236+
CHECK(tiles.count(tile_t(18, 140221, 82052)) == 1);
237+
CHECK(tiles.count(tile_t(18, 140220, 82053)) == 1);
238+
CHECK(tiles.count(tile_t(18, 140221, 82053)) == 1);
239+
CHECK(tiles.count(tile_t(18, 140221, 82054)) == 1);
240+
CHECK(tiles.count(tile_t(18, 140221, 82055)) == 1);
241+
CHECK(tiles.count(tile_t(18, 140222, 82055)) == 1);
242+
CHECK(tiles.count(tile_t(18, 140221, 82056)) == 1);
243+
CHECK(tiles.count(tile_t(18, 140222, 82056)) == 1);
244+
}
245+
147246
/**
148247
* Test tile expiry on two zoom levels.
149248
*/

0 commit comments

Comments
 (0)