remove has_empty + fix is_empty implementaion to work with geometry.hpp

This commit is contained in:
artemp 2017-03-29 11:39:04 +01:00
parent 064b99168b
commit 3e803b52bb
3 changed files with 2 additions and 253 deletions

View file

@ -107,26 +107,6 @@ private:
template <typename Geom> template <typename Geom>
result_type centroid_multi(Geom const & multi_geom) const 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<T> multi_pt;
multi_pt.reserve(multi_geom.size());
for (auto const& geom : multi_geom)
{
try
{
point<T> 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); return centroid_simple(multi_geom);
} }
}; };

View file

@ -48,7 +48,7 @@ struct geometry_is_empty
bool operator() (mapnik::geometry::polygon<double> const& geom) const bool operator() (mapnik::geometry::polygon<double> const& geom) const
{ {
return geom.empty(); return geom.empty() || geom.front().empty();
} }
bool operator() (mapnik::geometry::multi_point<double> const& geom) const bool operator() (mapnik::geometry::multi_point<double> const& geom) const
@ -78,96 +78,15 @@ struct geometry_is_empty
} }
}; };
struct geometry_has_empty
{
bool operator() (mapnik::geometry::geometry<double> 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<double> const&) const
{
return false;
}
bool operator() (mapnik::geometry::line_string<double> const&) const
{
return false;
}
bool operator() (mapnik::geometry::polygon<double> const&) const
{
return false;
}
bool operator() (mapnik::geometry::multi_point<double> const&) const
{
return false;
}
bool operator() (mapnik::geometry::multi_line_string<double> const& geom) const
{
return test_multigeometry(geom);
}
bool operator() (mapnik::geometry::multi_polygon<double> const& geom) const
{
return test_multigeometry(geom);
}
bool operator() (mapnik::geometry::geometry_collection<double> const& geom) const
{
for (auto const & item : geom)
{
if (geometry_is_empty()(item) || (*this)(item))
{
return true;
}
}
return false;
}
template <typename T>
bool operator() (T const&) const
{
return true;
}
private:
template <typename T>
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 <typename GeomType> template <typename GeomType>
inline bool is_empty(GeomType const& geom) inline bool is_empty(GeomType const& geom)
{ {
return detail::geometry_is_empty()(geom); return detail::geometry_is_empty()(geom);
} }
template <typename GeomType>
inline bool has_empty(GeomType const& geom)
{
return detail::geometry_has_empty()(geom);
}
}} }}
#endif // MAPNIK_GEOMETRY_IS_EMPTY_HPP #endif // MAPNIK_GEOMETRY_IS_EMPTY_HPP

View file

@ -1,150 +0,0 @@
#include "catch.hpp"
#include <mapnik/geometry/is_empty.hpp>
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<double> geom;
REQUIRE(!mapnik::geometry::has_empty(geom));
}
{
mapnik::geometry::geometry_collection<double> geom;
mapnik::geometry::geometry_empty geom1;
geom.emplace_back(std::move(geom1));
REQUIRE(mapnik::geometry::has_empty(geom));
}
{
mapnik::geometry::geometry_collection<double> geom;
mapnik::geometry::multi_line_string<double> mls;
mapnik::geometry::line_string<double> line;
mls.emplace_back(std::move(line));
geom.emplace_back(std::move(mls));
REQUIRE(mapnik::geometry::has_empty(geom));
}
{
mapnik::geometry::geometry_collection<double> geom;
mapnik::geometry::multi_line_string<double> mls;
mapnik::geometry::line_string<double> 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<double> pt(10, 10);
REQUIRE(!mapnik::geometry::has_empty(pt));
}
SECTION("linestring") {
{
mapnik::geometry::line_string<double> line;
REQUIRE(!mapnik::geometry::has_empty(line));
}
{
mapnik::geometry::line_string<double> 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<double> poly;
REQUIRE(!mapnik::geometry::has_empty(poly));
}
{
mapnik::geometry::polygon<double> poly;
mapnik::geometry::linear_ring<double> ring;
poly.push_back(std::move(ring));
REQUIRE(!mapnik::geometry::has_empty(poly));
}
{
mapnik::geometry::polygon<double> poly;
mapnik::geometry::linear_ring<double> 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<double> geom;
REQUIRE(!mapnik::geometry::has_empty(geom));
}
{
mapnik::geometry::multi_point<double> 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<double> geom;
REQUIRE(!mapnik::geometry::has_empty(geom));
}
{
mapnik::geometry::multi_line_string<double> geom;
mapnik::geometry::line_string<double> line;
geom.emplace_back(std::move(line));
REQUIRE(mapnik::geometry::has_empty(geom));
}
{
mapnik::geometry::multi_line_string<double> geom;
mapnik::geometry::line_string<double> 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<double> geom;
REQUIRE(!mapnik::geometry::has_empty(geom));
}
{
mapnik::geometry::multi_polygon<double> geom;
mapnik::geometry::polygon<double> poly;
mapnik::geometry::linear_ring<double> ring;
poly.push_back(std::move(ring));
geom.emplace_back(std::move(poly));
REQUIRE(mapnik::geometry::has_empty(geom));
}
{
mapnik::geometry::multi_polygon<double> geom;
mapnik::geometry::polygon<double> poly;
mapnik::geometry::linear_ring<double> ring;
ring.emplace_back(0, 0);
poly.push_back(std::move(ring));
geom.emplace_back(std::move(poly));
REQUIRE(!mapnik::geometry::has_empty(geom));
}
}
}