diff --git a/src/geometry/interior.cpp b/src/geometry/interior.cpp index 164d4c46e..683f3ad86 100644 --- a/src/geometry/interior.cpp +++ b/src/geometry/interior.cpp @@ -153,15 +153,8 @@ struct cell }; template -boost::optional> polylabel(polygon const& polygon, T precision = 1) +point polylabel(polygon const& polygon, box2d const& bbox , T precision = 1) { - if (polygon.exterior_ring.empty()) - { - return boost::none; - } - - // find the bounding box of the outer ring - const box2d bbox = envelope(polygon.exterior_ring); const point size { bbox.width(), bbox.height() }; const T cell_size = std::min(size.x, size.y); @@ -177,14 +170,14 @@ boost::optional> polylabel(polygon const& polygon, T precision = 1) if (cell_size == 0) { - return point{ bbox.minx(), bbox.miny() }; + return { bbox.minx(), bbox.miny() }; } point centroid; if (!mapnik::geometry::centroid(polygon, centroid)) { auto center = bbox.center(); - return point{ center.x, center.y }; + return { center.x, center.y }; } fitness_functor fitness_func(centroid, size); @@ -232,15 +225,18 @@ boost::optional> polylabel(polygon const& polygon, T precision = 1) template bool interior(polygon const& polygon, double scale_factor, point & pt) { - // This precision has been chosen to work well in the map (viewport) coordinates. - double precision = 10.0 * scale_factor; - if (boost::optional> opt = detail::polylabel(polygon, precision)) + if (polygon.exterior_ring.empty()) { - pt = *opt; - return true; + return false; } - return false; + const box2d bbox = envelope(polygon.exterior_ring); + + // Let the precision be 1% of the polygon size to be independent to map scale. + double precision = (std::max(bbox.width(), bbox.height()) / 100.0) * scale_factor; + + pt = detail::polylabel(polygon, bbox, precision); + return true; } template diff --git a/test/data-visual b/test/data-visual index 1a9784770..758c44874 160000 --- a/test/data-visual +++ b/test/data-visual @@ -1 +1 @@ -Subproject commit 1a9784770b378d5bdc05020b5f27d79189c7af4a +Subproject commit 758c44874adcc54702b3f4d9ff5cdff64e967b2b