@@ -70,17 +70,17 @@ void expire_tiles::output_and_destroy(char const *filename, uint32_t minzoom)
7070
7171expire_tiles::expire_tiles (uint32_t max, double bbox,
7272 const std::shared_ptr<reprojection> &proj)
73- : max_bbox (bbox), maxzoom (max), projection (proj)
73+ : m_max_bbox (bbox), m_maxzoom (max), m_projection (proj)
7474{
75- map_width = 1U << maxzoom ;
76- tile_width = EARTH_CIRCUMFERENCE / map_width ;
75+ m_map_width = 1U << m_maxzoom ;
76+ m_tile_width = EARTH_CIRCUMFERENCE / m_map_width ;
7777}
7878
7979void expire_tiles::expire_tile (uint32_t x, uint32_t y)
8080{
8181 // Only try to insert to tile into the set if the last inserted tile
8282 // is different from this tile.
83- tile_t const new_tile{maxzoom , x, y};
83+ tile_t const new_tile{m_maxzoom , x, y};
8484 if (!m_prev_tile.valid () || m_prev_tile != new_tile) {
8585 m_dirty_tiles.insert (new_tile.quadkey ());
8686 m_prev_tile = new_tile;
@@ -89,26 +89,26 @@ void expire_tiles::expire_tile(uint32_t x, uint32_t y)
8989
9090uint32_t expire_tiles::normalise_tile_x_coord (int x) const
9191{
92- x %= map_width ;
92+ x %= m_map_width ;
9393 if (x < 0 ) {
94- x = (map_width - x) + 1 ;
94+ x = (m_map_width - x) + 1 ;
9595 }
9696 return static_cast <uint32_t >(x);
9797}
9898
99- void expire_tiles::coords_to_tile (double lon, double lat , double *tilex,
99+ void expire_tiles::coords_to_tile (geom:: point_t const &point , double *tilex,
100100 double *tiley)
101101{
102- auto const c = projection ->target_to_tile (geom:: point_t {lon, lat} );
102+ auto const c = m_projection ->target_to_tile (point );
103103
104- *tilex = map_width * (0.5 + c.x () / EARTH_CIRCUMFERENCE);
105- *tiley = map_width * (0.5 - c.y () / EARTH_CIRCUMFERENCE);
104+ *tilex = m_map_width * (0.5 + c.x () / EARTH_CIRCUMFERENCE);
105+ *tiley = m_map_width * (0.5 - c.y () / EARTH_CIRCUMFERENCE);
106106}
107107
108108void expire_tiles::from_point_list (geom::point_list_t const &list)
109109{
110- for_each_segment (list, [&](geom::point_t a, geom::point_t b) {
111- from_line (a. x (), a. y (), b. x (), b. y () );
110+ for_each_segment (list, [&](geom::point_t const & a, geom::point_t const & b) {
111+ from_line (a, b );
112112 });
113113}
114114
@@ -154,16 +154,15 @@ void expire_tiles::from_geometry(geom::geometry_t const &geom, osmid_t osm_id)
154154/*
155155 * Expire tiles that a line crosses
156156 */
157- void expire_tiles::from_line (double lon_a, double lat_a, double lon_b,
158- double lat_b)
157+ void expire_tiles::from_line (geom::point_t const &a, geom::point_t const &b)
159158{
160159 double tile_x_a = NAN;
161160 double tile_y_a = NAN;
162161 double tile_x_b = NAN;
163162 double tile_y_b = NAN;
164163
165- coords_to_tile (lon_a, lat_a , &tile_x_a, &tile_y_a);
166- coords_to_tile (lon_b, lat_b , &tile_x_b, &tile_y_b);
164+ coords_to_tile (a , &tile_x_a, &tile_y_a);
165+ coords_to_tile (b , &tile_x_b, &tile_y_b);
167166
168167 if (tile_x_a > tile_x_b) {
169168 /* We always want the line to go from left to right - swap the ends if it doesn't */
@@ -176,11 +175,11 @@ void expire_tiles::from_line(double lon_a, double lat_a, double lon_b,
176175 }
177176
178177 double const x_len = tile_x_b - tile_x_a;
179- if (x_len > map_width / 2 ) {
178+ if (x_len > m_map_width / 2 ) {
180179 /* If the line is wider than half the map, assume it
181180 crosses the international date line.
182181 These coordinates get normalised again later */
183- tile_x_a += map_width ;
182+ tile_x_a += m_map_width ;
184183 double temp = tile_x_b;
185184 tile_x_b = tile_x_a;
186185 tile_x_a = temp;
@@ -232,43 +231,32 @@ void expire_tiles::from_line(double lon_a, double lat_a, double lon_b,
232231 */
233232int expire_tiles::from_bbox (geom::box_t const &box)
234233{
235- double const min_lon = box.min_x ();
236- double const min_lat = box.min_y ();
237- double const max_lon = box.max_x ();
238- double const max_lat = box.max_y ();
239-
240- return from_bbox (min_lon, min_lat, max_lon, max_lat);
241- }
242-
243- int expire_tiles::from_bbox (double min_lon, double min_lat, double max_lon,
244- double max_lat)
245- {
246- if (maxzoom == 0 ) {
234+ if (!enabled ()) {
247235 return 0 ;
248236 }
249237
250- double const width = max_lon - min_lon ;
251- double const height = max_lat - min_lat ;
238+ double const width = box. width () ;
239+ double const height = box. height () ;
252240 if (width > HALF_EARTH_CIRCUMFERENCE + 1 ) {
253241 /* Over half the planet's width within the bounding box - assume the
254242 box crosses the international date line and split it into two boxes */
255243 int ret =
256- from_bbox (-HALF_EARTH_CIRCUMFERENCE, min_lat, min_lon, max_lat );
257- ret += from_bbox (max_lon, min_lat , HALF_EARTH_CIRCUMFERENCE, max_lat );
244+ from_bbox ({ -HALF_EARTH_CIRCUMFERENCE, box. min_y (), box. min_x (), box. max_y ()} );
245+ ret += from_bbox ({box. max_x (), box. min_y () , HALF_EARTH_CIRCUMFERENCE, box. max_y ()} );
258246 return ret;
259247 }
260248
261- if (width > max_bbox || height > max_bbox ) {
249+ if (width > m_max_bbox || height > m_max_bbox ) {
262250 return -1 ;
263251 }
264252
265253 /* Convert the box's Mercator coordinates into tile coordinates */
266254 double tmp_x = NAN;
267255 double tmp_y = NAN;
268- coords_to_tile (min_lon, max_lat , &tmp_x, &tmp_y);
256+ coords_to_tile ({box. min_x (), box. max_y ()} , &tmp_x, &tmp_y);
269257 int min_tile_x = tmp_x - TILE_EXPIRY_LEEWAY;
270258 int min_tile_y = tmp_y - TILE_EXPIRY_LEEWAY;
271- coords_to_tile (max_lon, min_lat , &tmp_x, &tmp_y);
259+ coords_to_tile ({box. max_x (), box. min_y ()} , &tmp_x, &tmp_y);
272260 int max_tile_x = tmp_x + TILE_EXPIRY_LEEWAY;
273261 int max_tile_y = tmp_y + TILE_EXPIRY_LEEWAY;
274262 if (min_tile_x < 0 ) {
@@ -277,11 +265,11 @@ int expire_tiles::from_bbox(double min_lon, double min_lat, double max_lon,
277265 if (min_tile_y < 0 ) {
278266 min_tile_y = 0 ;
279267 }
280- if (max_tile_x > map_width ) {
281- max_tile_x = map_width ;
268+ if (max_tile_x > m_map_width ) {
269+ max_tile_x = m_map_width ;
282270 }
283- if (max_tile_y > map_width ) {
284- max_tile_y = map_width ;
271+ if (max_tile_y > m_map_width ) {
272+ max_tile_y = m_map_width ;
285273 }
286274 for (int iterator_x = min_tile_x; iterator_x <= max_tile_x; ++iterator_x) {
287275 uint32_t const norm_x = normalise_tile_x_coord (iterator_x);
@@ -295,34 +283,31 @@ int expire_tiles::from_bbox(double min_lon, double min_lat, double max_lon,
295283
296284int expire_tiles::from_result (pg_result_t const &result, osmid_t osm_id)
297285{
298- // bail if we dont care about expiry
299- if (maxzoom == 0 ) {
286+ if (!enabled ()) {
300287 return -1 ;
301288 }
302289
303- // dirty the stuff
304290 auto const num_tuples = result.num_tuples ();
305291 for (int i = 0 ; i < num_tuples; ++i) {
306292 char const *const wkb = result.get_value (i, 0 );
307293 from_geometry (ewkb_to_geom (decode_hex (wkb)), osm_id);
308294 }
309295
310- // return how many rows were affected
311296 return num_tuples;
312297}
313298
314299void expire_tiles::merge_and_destroy (expire_tiles &other)
315300{
316- if (map_width != other.map_width ) {
301+ if (m_map_width != other.m_map_width ) {
317302 throw std::runtime_error{" Unable to merge tile expiry sets when "
318303 " map_width does not match: {} != {}." _format (
319- map_width , other.map_width )};
304+ m_map_width , other.m_map_width )};
320305 }
321306
322- if (tile_width != other.tile_width ) {
307+ if (m_tile_width != other.m_tile_width ) {
323308 throw std::runtime_error{" Unable to merge tile expiry sets when "
324309 " tile_width does not match: {} != {}." _format (
325- tile_width , other.tile_width )};
310+ m_tile_width , other.m_tile_width )};
326311 }
327312
328313 if (m_dirty_tiles.empty ()) {
0 commit comments