From 2e0d83aa91f201e99c5f61316b71adecfa3aa39d Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 12 Apr 2016 10:12:16 +0200 Subject: [PATCH] geometry::multi_point - derive from std::vector> instead of line_string --- include/mapnik/geometry.hpp | 9 ++++++++- include/mapnik/geometry_reprojection_impl.hpp | 6 +++++- include/mapnik/proj_transform.hpp | 7 ++++--- include/mapnik/well_known_srs.hpp | 9 +++++---- src/proj_transform.cpp | 4 ++-- test/unit/geometry/geometry_equal.hpp | 11 +++++++++-- 6 files changed, 33 insertions(+), 13 deletions(-) diff --git a/include/mapnik/geometry.hpp b/include/mapnik/geometry.hpp index d2e3d2a42..e94f760a2 100644 --- a/include/mapnik/geometry.hpp +++ b/include/mapnik/geometry.hpp @@ -36,7 +36,14 @@ namespace mapnik { namespace geometry { template -struct multi_point : line_string {}; +struct multi_point : std::vector> +{ + multi_point() = default; + explicit multi_point(std::size_t size) + : std::vector >(size) {} + inline std::size_t num_points() const { return std::vector>::size(); } + inline void add_coord(T x, T y) { std::vector>::template emplace_back(x,y);} +}; template struct multi_line_string : std::vector> {}; diff --git a/include/mapnik/geometry_reprojection_impl.hpp b/include/mapnik/geometry_reprojection_impl.hpp index ff01bd451..02b7846fd 100644 --- a/include/mapnik/geometry_reprojection_impl.hpp +++ b/include/mapnik/geometry_reprojection_impl.hpp @@ -332,7 +332,11 @@ struct geom_reproj_visitor { template bool operator() (multi_point & mp) const { - return (*this) (static_cast &>(mp)); + if (proj_trans_.forward(mp) > 0) + { + return false; + } + return true; } template diff --git a/include/mapnik/proj_transform.hpp b/include/mapnik/proj_transform.hpp index 3247a15e3..82b732f4b 100644 --- a/include/mapnik/proj_transform.hpp +++ b/include/mapnik/proj_transform.hpp @@ -26,12 +26,13 @@ // mapnik #include #include +// stl +#include namespace mapnik { namespace geometry { template struct point; -template struct line_string; } class projection; template class box2d; @@ -50,8 +51,8 @@ public: bool backward (double *x, double *y , double *z, int point_count, int offset = 1) const; bool forward (geometry::point & p) const; bool backward (geometry::point & p) const; - unsigned int forward (geometry::line_string & ls) const; - unsigned int backward (geometry::line_string & ls) const; + unsigned int forward (std::vector> & ls) const; + unsigned int backward (std::vector> & ls) const; bool forward (box2d & box) const; bool backward (box2d & box) const; bool forward (box2d & box, int points) const; diff --git a/include/mapnik/well_known_srs.hpp b/include/mapnik/well_known_srs.hpp index e8349e709..d175ef528 100644 --- a/include/mapnik/well_known_srs.hpp +++ b/include/mapnik/well_known_srs.hpp @@ -26,7 +26,7 @@ // mapnik #include // for M_PI on windows #include -#include +#include #pragma GCC diagnostic push #include @@ -35,6 +35,7 @@ // stl #include +#include namespace mapnik { @@ -93,9 +94,9 @@ static inline bool merc2lonlat(double * x, double * y , int point_count) return true; } -static inline bool lonlat2merc(geometry::line_string & ls) +static inline bool lonlat2merc(std::vector> & ls) { - for(auto & p : ls) + for (auto& p : ls) { if (p.x > 180) p.x = 180; else if (p.x < -180) p.x = -180; @@ -108,7 +109,7 @@ static inline bool lonlat2merc(geometry::line_string & ls) return true; } -static inline bool merc2lonlat(geometry::line_string & ls) +static inline bool merc2lonlat(std::vector> & ls) { for (auto & p : ls) { diff --git a/src/proj_transform.cpp b/src/proj_transform.cpp index 108e3f97c..a418d5d21 100644 --- a/src/proj_transform.cpp +++ b/src/proj_transform.cpp @@ -102,7 +102,7 @@ bool proj_transform::forward (geometry::point & p) const return forward(&(p.x), &(p.y), &z, 1); } -unsigned int proj_transform::forward (geometry::line_string & ls) const +unsigned int proj_transform::forward (std::vector> & ls) const { std::size_t size = ls.size(); if (size == 0) return 0; @@ -242,7 +242,7 @@ bool proj_transform::backward (geometry::point & p) const return backward(&(p.x), &(p.y), &z, 1); } -unsigned int proj_transform::backward (geometry::line_string & ls) const +unsigned int proj_transform::backward (std::vector> & ls) const { std::size_t size = ls.size(); if (size == 0) return 0; diff --git a/test/unit/geometry/geometry_equal.hpp b/test/unit/geometry/geometry_equal.hpp index 4ff80abab..6a510ced0 100644 --- a/test/unit/geometry/geometry_equal.hpp +++ b/test/unit/geometry/geometry_equal.hpp @@ -119,7 +119,7 @@ struct geometry_equal_visitor } template - void operator() (line_string const& ls1, line_string const& ls2) const + void operator() (std::vector> const& ls1, std::vector> const& ls2) const { if (ls1.size() != ls2.size()) { @@ -149,12 +149,19 @@ struct geometry_equal_visitor } } + template + void operator() (line_string const& ls1, line_string const& ls2) const + { + (*this)(static_cast> const&>(ls1), static_cast> const&>(ls2)); + } + template void operator() (multi_point const& mp1, multi_point const& mp2) const { - (*this)(static_cast const&>(mp1), static_cast const&>(mp2)); + (*this)(static_cast> const&>(mp1), static_cast> const&>(mp2)); } + template void operator() (multi_line_string const& mls1, multi_line_string const& mls2) const {