@@ -114,19 +114,43 @@ void expire_tiles_t::from_polygon_boundary(geom::polygon_t const &geom,
114114 }
115115}
116116
117+ namespace {
118+
119+ template <typename TGEOM>
120+ expire_mode decide_expire_mode (TGEOM const &geom,
121+ expire_config_t const &expire_config,
122+ geom::box_t *box)
123+ {
124+ if (expire_config.mode != expire_mode::hybrid) {
125+ return expire_config.mode ;
126+ }
127+
128+ *box = geom::envelope (geom);
129+ if (box->width () > expire_config.full_area_limit ||
130+ box->height () > expire_config.full_area_limit ) {
131+ return expire_mode::boundary_only;
132+ }
133+
134+ return expire_mode::full_area;
135+ }
136+
137+ } // anonymous namespace
138+
117139void expire_tiles_t::from_geometry (geom::polygon_t const &geom,
118140 expire_config_t const &expire_config)
119141{
120- if (expire_config.mode == expire_mode::boundary_only) {
142+ geom::box_t box;
143+ auto const mode = decide_expire_mode (geom, expire_config, &box);
144+
145+ if (mode == expire_mode::boundary_only) {
121146 from_polygon_boundary (geom, expire_config);
122147 return ;
123148 }
124149
125- geom::box_t const box = geom::envelope (geom);
126- if (from_bbox (box, expire_config)) {
127- /* Bounding box too big - just expire tiles on the boundary */
128- from_polygon_boundary (geom, expire_config);
150+ if (!box.valid ()) {
151+ box = geom::envelope (geom);
129152 }
153+ from_bbox (box, expire_config);
130154}
131155
132156void expire_tiles_t::from_polygon_boundary (geom::multipolygon_t const &geom,
@@ -140,16 +164,18 @@ void expire_tiles_t::from_polygon_boundary(geom::multipolygon_t const &geom,
140164void expire_tiles_t::from_geometry (geom::multipolygon_t const &geom,
141165 expire_config_t const &expire_config)
142166{
143- if (expire_config.mode == expire_mode::boundary_only) {
167+ geom::box_t box;
168+ auto const mode = decide_expire_mode (geom, expire_config, &box);
169+
170+ if (mode == expire_mode::boundary_only) {
144171 from_polygon_boundary (geom, expire_config);
145172 return ;
146173 }
147174
148- geom::box_t const box = geom::envelope (geom);
149- if (from_bbox (box, expire_config)) {
150- /* Bounding box too big - just expire tiles on the boundary */
151- from_polygon_boundary (geom, expire_config);
175+ if (!box.valid ()) {
176+ box = geom::envelope (geom);
152177 }
178+ from_bbox (box, expire_config);
153179}
154180
155181// False positive: Apparently clang-tidy can not see through the visit()
@@ -238,15 +264,6 @@ void expire_tiles_t::from_line_segment(geom::point_t const &a,
238264int expire_tiles_t::from_bbox (geom::box_t const &box,
239265 expire_config_t const &expire_config)
240266{
241- double const width = box.width ();
242- double const height = box.height ();
243-
244- if (expire_config.mode == expire_mode::hybrid &&
245- (width > expire_config.full_area_limit ||
246- height > expire_config.full_area_limit )) {
247- return -1 ;
248- }
249-
250267 /* Convert the box's Mercator coordinates into tile coordinates */
251268 auto const tmp_min = coords_to_tile ({box.min_x (), box.max_y ()});
252269 int const min_tile_x =
0 commit comments