diff --git a/include/mapnik/geometry/centroid.hpp b/include/mapnik/geometry/centroid.hpp index 3608d95ce..ab8b05ba4 100644 --- a/include/mapnik/geometry/centroid.hpp +++ b/include/mapnik/geometry/centroid.hpp @@ -107,26 +107,6 @@ private: template result_type centroid_multi(Geom const & multi_geom) const { -// https://github.com/mapnik/mapnik/issues/3169 -#if BOOST_VERSION <= 105900 - if (mapnik::geometry::has_empty(multi_geom)) - { - mapnik::geometry::multi_point multi_pt; - multi_pt.reserve(multi_geom.size()); - for (auto const& geom : multi_geom) - { - try - { - point c; - boost::geometry::centroid(geom, c); - multi_pt.push_back(std::move(c)); - - } - catch (boost::geometry::centroid_exception const & e) {} - } - return centroid_simple(multi_pt); - } -#endif return centroid_simple(multi_geom); } }; diff --git a/include/mapnik/geometry/is_empty.hpp b/include/mapnik/geometry/is_empty.hpp index 206fb185c..1ad0389aa 100644 --- a/include/mapnik/geometry/is_empty.hpp +++ b/include/mapnik/geometry/is_empty.hpp @@ -48,7 +48,7 @@ struct geometry_is_empty bool operator() (mapnik::geometry::polygon const& geom) const { - return geom.empty(); + return geom.empty() || geom.front().empty(); } bool operator() (mapnik::geometry::multi_point const& geom) const @@ -78,96 +78,15 @@ struct geometry_is_empty } }; - -struct geometry_has_empty -{ - bool operator() (mapnik::geometry::geometry const& geom) const - { - return mapnik::util::apply_visitor(*this, geom); - } - - bool operator() (mapnik::geometry::geometry_empty const&) const - { - return false; - } - - bool operator() (mapnik::geometry::point const&) const - { - return false; - } - - bool operator() (mapnik::geometry::line_string const&) const - { - return false; - } - - bool operator() (mapnik::geometry::polygon const&) const - { - return false; - } - - bool operator() (mapnik::geometry::multi_point const&) const - { - return false; - } - - bool operator() (mapnik::geometry::multi_line_string const& geom) const - { - return test_multigeometry(geom); - } - - bool operator() (mapnik::geometry::multi_polygon const& geom) const - { - return test_multigeometry(geom); - } - - bool operator() (mapnik::geometry::geometry_collection const& geom) const - { - for (auto const & item : geom) - { - if (geometry_is_empty()(item) || (*this)(item)) - { - return true; - } - } - return false; - } - - template - bool operator() (T const&) const - { - return true; - } - -private: - template - bool test_multigeometry(T const & geom) const - { - for (auto const & item : geom) - { - if (item.empty()) - { - return true; - } - } - return false; - } -}; - } +// returns true if the geometry is the empty set template inline bool is_empty(GeomType const& geom) { return detail::geometry_is_empty()(geom); } -template -inline bool has_empty(GeomType const& geom) -{ - return detail::geometry_has_empty()(geom); -} - }} #endif // MAPNIK_GEOMETRY_IS_EMPTY_HPP diff --git a/test/unit/geometry/has_empty.cpp b/test/unit/geometry/has_empty.cpp deleted file mode 100644 index 79159d173..000000000 --- a/test/unit/geometry/has_empty.cpp +++ /dev/null @@ -1,150 +0,0 @@ -#include "catch.hpp" - -#include - -TEST_CASE("geometry has_empty") { - -SECTION("empty geometry") { - - mapnik::geometry::geometry_empty geom; - REQUIRE(!mapnik::geometry::has_empty(geom)); -} - -SECTION("geometry collection") { - - { - mapnik::geometry::geometry_collection geom; - REQUIRE(!mapnik::geometry::has_empty(geom)); - } - { - mapnik::geometry::geometry_collection geom; - mapnik::geometry::geometry_empty geom1; - geom.emplace_back(std::move(geom1)); - REQUIRE(mapnik::geometry::has_empty(geom)); - } - { - mapnik::geometry::geometry_collection geom; - mapnik::geometry::multi_line_string mls; - mapnik::geometry::line_string line; - mls.emplace_back(std::move(line)); - geom.emplace_back(std::move(mls)); - REQUIRE(mapnik::geometry::has_empty(geom)); - } - { - mapnik::geometry::geometry_collection geom; - mapnik::geometry::multi_line_string mls; - mapnik::geometry::line_string line; - line.emplace_back(0, 0); - mls.emplace_back(std::move(line)); - geom.emplace_back(std::move(mls)); - REQUIRE(!mapnik::geometry::has_empty(geom)); - } -} - -SECTION("point") { - - mapnik::geometry::point pt(10, 10); - REQUIRE(!mapnik::geometry::has_empty(pt)); -} - -SECTION("linestring") { - - { - mapnik::geometry::line_string line; - REQUIRE(!mapnik::geometry::has_empty(line)); - } - { - mapnik::geometry::line_string line; - line.emplace_back(0, 0); - line.emplace_back(25, 25); - line.emplace_back(50, 50); - REQUIRE(!mapnik::geometry::has_empty(line)); - } -} - -SECTION("polygon") { - - { - mapnik::geometry::polygon poly; - REQUIRE(!mapnik::geometry::has_empty(poly)); - } - { - mapnik::geometry::polygon poly; - mapnik::geometry::linear_ring ring; - poly.push_back(std::move(ring)); - REQUIRE(!mapnik::geometry::has_empty(poly)); - } - { - mapnik::geometry::polygon poly; - mapnik::geometry::linear_ring ring; - ring.emplace_back(0, 0); - ring.emplace_back(1, 0); - ring.emplace_back(1, 1); - ring.emplace_back(0, 1); - ring.emplace_back(0, 0); - poly.push_back(std::move(ring)); - REQUIRE(!mapnik::geometry::has_empty(poly)); - } -} - -SECTION("multi-point") { - - { - mapnik::geometry::multi_point geom; - REQUIRE(!mapnik::geometry::has_empty(geom)); - } - { - mapnik::geometry::multi_point geom; - geom.emplace_back(0, 0); - geom.emplace_back(25, 25); - geom.emplace_back(50, 50); - REQUIRE(!mapnik::geometry::has_empty(geom)); - } -} - -SECTION("multi-linestring") { - - { - mapnik::geometry::multi_line_string geom; - REQUIRE(!mapnik::geometry::has_empty(geom)); - } - { - mapnik::geometry::multi_line_string geom; - mapnik::geometry::line_string line; - geom.emplace_back(std::move(line)); - REQUIRE(mapnik::geometry::has_empty(geom)); - } - { - mapnik::geometry::multi_line_string geom; - mapnik::geometry::line_string line; - line.emplace_back(0, 0); - geom.emplace_back(std::move(line)); - REQUIRE(!mapnik::geometry::has_empty(geom)); - } -} - -SECTION("multi-polygon") { - - { - mapnik::geometry::multi_polygon geom; - REQUIRE(!mapnik::geometry::has_empty(geom)); - } - { - mapnik::geometry::multi_polygon geom; - mapnik::geometry::polygon poly; - mapnik::geometry::linear_ring ring; - poly.push_back(std::move(ring)); - geom.emplace_back(std::move(poly)); - REQUIRE(mapnik::geometry::has_empty(geom)); - } - { - mapnik::geometry::multi_polygon geom; - mapnik::geometry::polygon poly; - mapnik::geometry::linear_ring ring; - ring.emplace_back(0, 0); - poly.push_back(std::move(ring)); - geom.emplace_back(std::move(poly)); - REQUIRE(!mapnik::geometry::has_empty(geom)); - } -} -}