From 69c3ee550d02877581086cb9e5d20e78c796acec Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Sat, 3 Feb 2018 12:53:07 +0000 Subject: [PATCH 1/2] interior, polylabel: Scale precision by polygon size --- src/geometry/interior.cpp | 28 ++++++++++++---------------- src/geometry/polylabel.cpp | 5 +++-- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/geometry/interior.cpp b/src/geometry/interior.cpp index 9f8f5b427..c59b0846a 100644 --- a/src/geometry/interior.cpp +++ b/src/geometry/interior.cpp @@ -145,15 +145,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.empty() || polygon.front().empty()) - { - return boost::none; - } - - // find the bounding box of the outer ring - const box2d bbox = envelope(polygon.at(0)); const point size { bbox.width(), bbox.height() }; const T cell_size = std::min(size.x, size.y); @@ -169,14 +162,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); @@ -224,15 +217,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.empty() || polygon.front().empty()) { - pt = *opt; - return true; + return false; } - return false; + const box2d bbox = envelope(polygon.at(0)); + + // 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/src/geometry/polylabel.cpp b/src/geometry/polylabel.cpp index 740eccbfe..07012fcdb 100644 --- a/src/geometry/polylabel.cpp +++ b/src/geometry/polylabel.cpp @@ -29,8 +29,9 @@ namespace mapnik { namespace geometry { template T polylabel_precision(polygon const& polygon, double scale_factor) { - // This precision has been chosen to work well in the map (viewport) coordinates. - return 10.0 * scale_factor; + const box2d bbox = mapnik::geometry::envelope(polygon); + // Let the precision be 1% of the polygon size to be independent to map scale. + return (std::max(bbox.width(), bbox.height()) / 100.0) * scale_factor; } template From c975c1b6b80241fd3f47140fb906dedd91a31bad Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Sat, 3 Feb 2018 13:50:37 +0000 Subject: [PATCH 2/2] Update visual tests --- test/data-visual | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data-visual b/test/data-visual index 62747ea33..edfc559b9 160000 --- a/test/data-visual +++ b/test/data-visual @@ -1 +1 @@ -Subproject commit 62747ea33b88a62fbfc90f109cbf1899435e75da +Subproject commit edfc559b9775344eb589474861fff6ca340b0c65