From 95a4bff1271311319b3268dda3b4db9a2bf5c8c4 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 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) 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 From 75381d217f7ede14084f335afa1337d915ae2811 Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Tue, 6 Feb 2018 11:52:53 +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 1a9784770..758c44874 160000 --- a/test/data-visual +++ b/test/data-visual @@ -1 +1 @@ -Subproject commit 1a9784770b378d5bdc05020b5f27d79189c7af4a +Subproject commit 758c44874adcc54702b3f4d9ff5cdff64e967b2b