From 348ce1fbd41e205ced29acb9772222562215d001 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 22 Aug 2016 21:49:57 -0700 Subject: [PATCH] upgrade to latest geometry.hpp --- .gitmodules | 3 + SConstruct | 1 + benchmark/test_polygon_clipping.cpp | 37 +- deps/mapnik/build.py | 4 +- include/build.py | 1 + include/mapnik/feature.hpp | 2 +- include/mapnik/geometry.hpp | 126 ++----- include/mapnik/geometry_adapters.hpp | 35 +- include/mapnik/geometry_centroid.hpp | 28 +- include/mapnik/geometry_correct.hpp | 4 +- include/mapnik/geometry_envelope.hpp | 2 +- include/mapnik/geometry_envelope_impl.hpp | 79 ++-- include/mapnik/geometry_fusion_adapted.hpp | 18 +- include/mapnik/geometry_is_empty.hpp | 107 +++--- include/mapnik/geometry_is_simple.hpp | 23 +- include/mapnik/geometry_is_valid.hpp | 57 +-- include/mapnik/geometry_remove_empty.hpp | 8 +- include/mapnik/geometry_reprojection_impl.hpp | 69 ++-- include/mapnik/geometry_to_path.hpp | 44 +-- include/mapnik/geometry_transform.hpp | 5 +- include/mapnik/geometry_type.hpp | 16 +- include/mapnik/hit_test_filter.hpp | 57 +-- .../json/geometry_generator_grammar.hpp | 3 +- .../json/geometry_generator_grammar_impl.hpp | 8 +- include/mapnik/json/geometry_util.hpp | 16 +- include/mapnik/json/topojson_utils.hpp | 36 +- include/mapnik/path.hpp | 10 +- include/mapnik/proj_strategy.hpp | 5 - include/mapnik/proj_transform.hpp | 11 +- include/mapnik/svg/geometry_svg_generator.hpp | 4 +- .../mapnik/svg/output/svg_path_iterator.hpp | 6 +- include/mapnik/text/symbolizer_helpers.hpp | 5 + include/mapnik/util/geometry_to_ds_type.hpp | 2 +- include/mapnik/util/geometry_to_wkb.hpp | 25 +- .../util/spirit_transform_attribute.hpp | 40 +- include/mapnik/vertex.hpp | 14 +- include/mapnik/vertex_adapters.hpp | 19 +- include/mapnik/vertex_processor.hpp | 3 +- include/mapnik/vertex_vector.hpp | 24 +- include/mapnik/well_known_srs.hpp | 9 +- include/mapnik/wkt/wkt_generator_grammar.hpp | 36 +- .../mapnik/wkt/wkt_generator_grammar_impl.hpp | 8 +- include/mapnik/wkt/wkt_grammar.hpp | 16 +- include/mapnik/wkt/wkt_grammar_impl.hpp | 8 +- plugins/input/csv/csv_featureset.cpp | 2 +- plugins/input/csv/csv_index_featureset.cpp | 2 +- plugins/input/csv/csv_inline_featureset.cpp | 2 +- plugins/input/csv/csv_utils.cpp | 2 +- plugins/input/ogr/ogr_converter.cpp | 6 +- plugins/input/shape/shape_io.cpp | 20 +- src/agg/process_debug_symbolizer.cpp | 28 +- src/box2d.cpp | 1 + src/geometry_reprojection.cpp | 8 +- src/proj_transform.cpp | 4 +- src/text/symbolizer_helpers.cpp | 2 +- src/twkb.cpp | 11 +- src/vertex_adapters.cpp | 23 +- src/wkb.cpp | 11 +- test/unit/datasource/ds_test_util.hpp | 43 ++- test/unit/datasource/geojson.cpp | 11 +- test/unit/geometry/centroid.cpp | 104 +++--- test/unit/geometry/geometry_envelope_test.cpp | 68 ++-- test/unit/geometry/geometry_equal.hpp | 25 +- test/unit/geometry/geometry_hit_test.cpp | 61 ++-- test/unit/geometry/geometry_is_simple.cpp | 250 ++++++------- test/unit/geometry/geometry_is_valid.cpp | 232 ++++++------ test/unit/geometry/geometry_reprojection.cpp | 344 ++++++++++-------- test/unit/geometry/geometry_strategy_test.cpp | 3 - test/unit/geometry/has_empty.cpp | 41 +-- test/unit/geometry/is_empty.cpp | 33 +- test/unit/geometry/remove_empty.cpp | 23 +- test/unit/serialization/wkb_formats_test.cpp | 4 +- test/unit/serialization/wkb_test.cpp | 2 +- test/unit/vertex_adapter/vertex_adapter.cpp | 47 +-- 74 files changed, 1165 insertions(+), 1282 deletions(-) diff --git a/.gitmodules b/.gitmodules index dfcbea536..7846a4f6c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -9,3 +9,6 @@ [submodule "deps/mapbox/variant"] path = deps/mapbox/variant url = https://github.com/mapbox/variant.git +[submodule "deps/mapbox/geometry"] + path = deps/mapbox/geometry + url = https://github.com/mapbox/geometry.hpp.git diff --git a/SConstruct b/SConstruct index 0523e184d..85713c694 100644 --- a/SConstruct +++ b/SConstruct @@ -1598,6 +1598,7 @@ if not preconfigured: env.Prepend(CPPPATH = '#deps/agg/include') env.Prepend(LIBPATH = '#deps/agg') env.Prepend(CPPPATH = '#deps/mapbox/variant/include') + env.Prepend(CPPPATH = '#deps/mapbox/geometry/include') # prepend deps dir for auxillary headers env.Prepend(CPPPATH = '#deps') diff --git a/benchmark/test_polygon_clipping.cpp b/benchmark/test_polygon_clipping.cpp index b189a0443..d10911a42 100644 --- a/benchmark/test_polygon_clipping.cpp +++ b/benchmark/test_polygon_clipping.cpp @@ -123,12 +123,12 @@ public: if (cmd == mapnik::SEG_CLOSE) { - ring.add_coord(x0, y0); + ring.emplace_back(x0, y0); break; } - ring.add_coord(x,y); + ring.emplace_back(x,y); } - poly2.set_exterior_ring(std::move(ring)); + poly2.push_back(std::move(ring)); // interior rings ring.clear(); while ((cmd = clipped.vertex(&x, &y)) != mapnik::SEG_END) @@ -139,12 +139,12 @@ public: } else if (cmd == mapnik::SEG_CLOSE) { - ring.add_coord(x0,y0); - poly2.add_hole(std::move(ring)); + ring.emplace_back(x0,y0); + poly2.push_back(std::move(ring)); ring.clear(); continue; } - ring.add_coord(x,y); + ring.emplace_back(x,y); } std::string expect = expected_+".png"; @@ -243,11 +243,11 @@ public: mapnik::geometry::correct(poly); mapnik::geometry::linear_ring bbox; - bbox.add_coord(extent_.minx(), extent_.miny()); - bbox.add_coord(extent_.minx(), extent_.maxy()); - bbox.add_coord(extent_.maxx(), extent_.maxy()); - bbox.add_coord(extent_.maxx(), extent_.miny()); - bbox.add_coord(extent_.minx(), extent_.miny()); + bbox.emplace_back(extent_.minx(), extent_.miny()); + bbox.emplace_back(extent_.minx(), extent_.maxy()); + bbox.emplace_back(extent_.maxx(), extent_.maxy()); + bbox.emplace_back(extent_.maxx(), extent_.miny()); + bbox.emplace_back(extent_.minx(), extent_.miny()); std::deque > result; boost::geometry::intersection(bbox, poly, result); @@ -291,11 +291,11 @@ public: mapnik::geometry::correct(poly); mapnik::geometry::linear_ring bbox; - bbox.add_coord(extent_.minx(), extent_.miny()); - bbox.add_coord(extent_.minx(), extent_.maxy()); - bbox.add_coord(extent_.maxx(), extent_.maxy()); - bbox.add_coord(extent_.maxx(), extent_.miny()); - bbox.add_coord(extent_.minx(), extent_.miny()); + bbox.emplace_back(extent_.minx(), extent_.miny()); + bbox.emplace_back(extent_.minx(), extent_.maxy()); + bbox.emplace_back(extent_.maxx(), extent_.maxy()); + bbox.emplace_back(extent_.maxx(), extent_.miny()); + bbox.emplace_back(extent_.minx(), extent_.miny()); bool valid = true; for (unsigned i=0;i clipping_box(181,106,631,470); std::string filename_("./benchmark/data/polygon.wkt"); std::ifstream in(filename_.c_str(),std::ios_base::in | std::ios_base::binary); @@ -543,5 +543,6 @@ int main(int argc, char** argv) return_value = return_value | run(test_runner,"clipping polygon with clipper_tree"); } */ - return return_value; +#endif + return 0;// return_value; } diff --git a/deps/mapnik/build.py b/deps/mapnik/build.py index 76529fbda..dff5f70e7 100644 --- a/deps/mapnik/build.py +++ b/deps/mapnik/build.py @@ -7,7 +7,9 @@ subdirs = { './sparsehash':{'dir':'sparsehash','glob':'*'}, './sparsehash/internal':{'dir':'sparsehash/internal','glob':'*'}, '../agg/include':{'dir':'agg','glob':'agg*'}, - '../mapbox/variant/include':{'dir':'mapbox','glob':'*/*.hpp'} + '../mapbox/variant/include':{'dir':'mapbox','glob':'*/*.hpp'}, + '../mapbox/geometry/include':{'dir':'mapbox','glob':'*/*.hpp'}, + '../mapbox/geometry/include/mapbox':{'dir':'mapbox/geometry','glob':'*/*.hpp'} } if 'install' in COMMAND_LINE_TARGETS: diff --git a/include/build.py b/include/build.py index 9c225a767..ec705419a 100644 --- a/include/build.py +++ b/include/build.py @@ -27,6 +27,7 @@ Import('env') base = './mapnik/' subdirs = [ '', + 'geometry', 'csv', 'svg', 'wkt', diff --git a/include/mapnik/feature.hpp b/include/mapnik/feature.hpp index 1300d3220..2812d0b3d 100644 --- a/include/mapnik/feature.hpp +++ b/include/mapnik/feature.hpp @@ -105,7 +105,7 @@ public: : id_(_id), ctx_(ctx), data_(ctx_->mapping_.size()), - geom_(geometry::geometry_empty()), + geom_(geometry::geometry_empty()), raster_() {} inline mapnik::value_integer id() const { return id_;} diff --git a/include/mapnik/geometry.hpp b/include/mapnik/geometry.hpp index aae2bf3e8..3f5d2aabd 100644 --- a/include/mapnik/geometry.hpp +++ b/include/mapnik/geometry.hpp @@ -23,117 +23,34 @@ #ifndef MAPNIK_GEOMETRY_HPP #define MAPNIK_GEOMETRY_HPP +// mapnik +#include +#include +#include +#include +#include +#include +// #include +// stl #include +#include #include #include namespace mapnik { namespace geometry { -template -struct point -{ - using coord_type = T; - point() {} - point(T x_, T y_) - : x(x_), y(y_) - {} - - coord_type x; - coord_type y; -}; - -template -bool operator==(point const& lhs, point const& rhs) -{ - return lhs.x == rhs.x && lhs.y == rhs.y; -} - -template -bool operator!=(point const& lhs, point const& rhs) -{ - return !(lhs == rhs); -} - -template -struct line_string : std::vector > -{ - using coord_type = T; - line_string() = default; - explicit line_string(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 linear_ring : line_string -{ - using coord_type = T; - linear_ring() = default; - explicit linear_ring(std::size_t size) - : line_string(size) {} - linear_ring(line_string && other) - : line_string(std::move(other)) {} - linear_ring(line_string const& other) - : line_string(other) {} -}; - -template -using rings_container = std::vector>; - -template class InteriorRings = rings_container> -struct polygon -{ - using coord_type = T; - using rings_container = InteriorRings; - linear_ring exterior_ring; - rings_container interior_rings; - - inline void set_exterior_ring(linear_ring && ring) - { - exterior_ring = std::move(ring); - } - - inline void add_hole(linear_ring && ring) - { - interior_rings.emplace_back(std::move(ring)); - } - - inline bool empty() const { return exterior_ring.empty(); } - - inline std::size_t num_rings() const - { - return 1 + interior_rings.size(); - } -}; - -template -struct multi_point : line_string -{ - using coord_type = T; -}; - -template -struct multi_line_string : std::vector> -{ - using coord_type = T; -}; - -template -struct multi_polygon : std::vector> -{ - using coord_type = T; -}; - -template +template class Cont = std::vector> struct geometry_collection; -struct geometry_empty {}; - +template +struct geometry_empty +{ + using coordinate_type = T; +}; template -using geometry_base = mapnik::util::variant, point, line_string, polygon, @@ -144,7 +61,7 @@ using geometry_base = mapnik::util::variant struct geometry : geometry_base { - using coord_type = T; + using coordinate_type = T; #if __cpp_inheriting_constructors >= 200802 @@ -161,10 +78,11 @@ struct geometry : geometry_base #endif }; -template -struct geometry_collection : std::vector> + +template class Cont> +struct geometry_collection : Cont> { - using coord_type = T; + using coordinate_type = T; }; }} diff --git a/include/mapnik/geometry_adapters.hpp b/include/mapnik/geometry_adapters.hpp index 7a708463a..770cb630c 100644 --- a/include/mapnik/geometry_adapters.hpp +++ b/include/mapnik/geometry_adapters.hpp @@ -37,11 +37,10 @@ // and once we do that the compile time is == to just including boost/geometry.hpp #include #pragma GCC diagnostic pop - +#include #include #include #include - #include // register point @@ -82,7 +81,9 @@ template inline typename mapnik::geometry::line_string::const_iterator range_end(mapnik::geometry::line_string const& line) {return line.end();} -namespace geometry { namespace traits { +namespace geometry { + +namespace traits { // register mapnik::box2d template<> struct tag > { using type = box_tag; }; @@ -175,42 +176,48 @@ struct ring_mutable_type > template struct interior_const_type > { - using type = typename mapnik::geometry::polygon::rings_container const&; + using type = typename mapnik::geometry::polygon::interior_rings const&; }; template struct interior_mutable_type > { - using type = typename mapnik::geometry::polygon::rings_container&; + using type = typename mapnik::geometry::polygon::interior_rings& ; }; // exterior template struct exterior_ring > { - static mapnik::geometry::linear_ring & get(mapnik::geometry::polygon & p) + using ring_const_type = typename ring_const_type >::type; + using ring_mutable_type = typename ring_mutable_type >::type; + static ring_mutable_type get(mapnik::geometry::polygon & p) { - return p.exterior_ring; + if (p.empty()) throw std::runtime_error("ring must be initialized 1"); + return p[0]; } - static mapnik::geometry::linear_ring const& get(mapnik::geometry::polygon const& p) + static ring_const_type get(mapnik::geometry::polygon const& p) { - return p.exterior_ring; + if (p.empty()) throw std::runtime_error("ring must be initialized 2"); + return p[0]; } }; template struct interior_rings > { - using holes_type = typename mapnik::geometry::polygon::rings_container; - static holes_type& get(mapnik::geometry::polygon & p) + using interior_const_type = typename interior_const_type >::type; + using interior_mutable_type = typename interior_mutable_type >::type; + + static interior_const_type get(mapnik::geometry::polygon const& p) { - return p.interior_rings; + return p.interior(); } - static holes_type const& get(mapnik::geometry::polygon const& p) + static interior_mutable_type get(mapnik::geometry::polygon& p) { - return p.interior_rings; + return p.interior(); } }; diff --git a/include/mapnik/geometry_centroid.hpp b/include/mapnik/geometry_centroid.hpp index 590ba4898..c88588fba 100644 --- a/include/mapnik/geometry_centroid.hpp +++ b/include/mapnik/geometry_centroid.hpp @@ -41,13 +41,13 @@ struct geometry_centroid geometry_centroid(point & pt) : pt_(pt) {} - template - result_type operator() (T1 const& geom) const + template + result_type operator() (U const& geom) const { return util::apply_visitor(*this, geom); } - result_type operator() (geometry_empty const&) const + result_type operator() (geometry_empty const&) const { return false; } @@ -105,17 +105,29 @@ private: } template - result_type centroid_multi(Geom const & 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(geom)) + if (mapnik::geometry::has_empty(multi_geom)) { - Geom stripped = mapnik::geometry::remove_empty(geom); - return centroid_simple(stripped); + 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(geom); + return centroid_simple(multi_geom); } }; diff --git a/include/mapnik/geometry_correct.hpp b/include/mapnik/geometry_correct.hpp index dc83ad3a2..673250c0c 100644 --- a/include/mapnik/geometry_correct.hpp +++ b/include/mapnik/geometry_correct.hpp @@ -60,13 +60,13 @@ struct geometry_correct template result_type operator() (polygon & poly) const { - boost::geometry::correct(poly); + if (!poly.empty()) boost::geometry::correct(poly); } template result_type operator() (multi_polygon & multi_poly) const { - boost::geometry::correct(multi_poly); + if (!multi_poly.empty()) boost::geometry::correct(multi_poly); } template diff --git a/include/mapnik/geometry_envelope.hpp b/include/mapnik/geometry_envelope.hpp index 981b97849..1621fd22f 100644 --- a/include/mapnik/geometry_envelope.hpp +++ b/include/mapnik/geometry_envelope.hpp @@ -30,7 +30,7 @@ namespace mapnik { namespace geometry { template -MAPNIK_DECL auto envelope(T const& geom) -> box2d; +MAPNIK_DECL auto envelope(T const& geom) -> box2d; } // end ns geometry } // end ns mapnik diff --git a/include/mapnik/geometry_envelope_impl.hpp b/include/mapnik/geometry_envelope_impl.hpp index 2ebddb9d9..692481131 100644 --- a/include/mapnik/geometry_envelope_impl.hpp +++ b/include/mapnik/geometry_envelope_impl.hpp @@ -31,11 +31,11 @@ namespace detail { template struct geometry_envelope { - using coord_type = T; - using bbox_type = box2d; + using coordinate_type = T; + using bbox_type = box2d; bbox_type & bbox; - geometry_envelope(bbox_type & bbox_) + explicit geometry_envelope(bbox_type & bbox_) : bbox(bbox_) {} template @@ -44,7 +44,7 @@ struct geometry_envelope return mapnik::util::apply_visitor(*this, geom); } - void operator() (mapnik::geometry::geometry_empty const&) const {} + void operator() (mapnik::geometry::geometry_empty const&) const {} void operator() (mapnik::geometry::point const& pt) const { @@ -57,58 +57,22 @@ struct geometry_envelope void operator() (mapnik::geometry::line_string const& line) const { - bool first = true; - for (auto const& pt : line) - { - if (first && !bbox.valid()) - { - bbox.init(pt.x, pt.y, pt.x, pt.y); - first = false; - } - else - { - bbox.expand_to_include(pt.x, pt.y); - } - } + _envelope_impl(line, bbox); } void operator() (mapnik::geometry::linear_ring const& ring) const { - (*this)(static_cast const&>(ring)); + _envelope_impl(ring, bbox); } void operator() (mapnik::geometry::polygon const& poly) const { - bool first = true; - for (auto const& pt : poly.exterior_ring) - { - if (first && !bbox.valid()) - { - bbox.init(pt.x, pt.y, pt.x, pt.y); - first = false; - } - else - { - bbox.expand_to_include(pt.x, pt.y); - } - } + if (!poly.empty()) _envelope_impl(poly[0], bbox); } void operator() (mapnik::geometry::multi_point const& multi_point) const { - bool first = true; - for (auto const& pt : multi_point) - { - if (first && !bbox.valid()) - { - bbox.init(pt.x, pt.y, pt.x, pt.y); - first = false; - } - else - { - bbox.expand_to_include(pt.x, pt.y); - } - } + _envelope_impl(multi_point, bbox); } void operator() (mapnik::geometry::multi_line_string const& multi_line) const @@ -134,16 +98,35 @@ struct geometry_envelope (*this)(geom); } } + +private: + template + void _envelope_impl(Points const& points, bbox_type & b) const + { + bool first = true; + for (auto const& pt : points) + { + if (first && !b.valid()) + { + b.init(pt.x, pt.y, pt.x, pt.y); + first = false; + } + else + { + b.expand_to_include(pt.x, pt.y); + } + } + } }; } // end ns detail template -auto envelope(T const& geom) -> box2d +auto envelope(T const& geom) -> box2d { - using coord_type = typename T::coord_type; - box2d bbox; - detail::geometry_envelope op(bbox); + using coordinate_type = typename T::coordinate_type; + box2d bbox; + detail::geometry_envelope op(bbox); op(geom); return bbox; } diff --git a/include/mapnik/geometry_fusion_adapted.hpp b/include/mapnik/geometry_fusion_adapted.hpp index e3bdd7ef8..8430d4f48 100644 --- a/include/mapnik/geometry_fusion_adapted.hpp +++ b/include/mapnik/geometry_fusion_adapted.hpp @@ -24,7 +24,7 @@ #ifndef MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP #define MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP -#include +#include #include BOOST_FUSION_ADAPT_STRUCT( @@ -39,14 +39,14 @@ BOOST_FUSION_ADAPT_STRUCT( (std::int64_t, y) ) -BOOST_FUSION_ADAPT_STRUCT( - mapnik::geometry::polygon, - (mapnik::geometry::linear_ring const&, exterior_ring) - (mapnik::geometry::polygon::rings_container const& , interior_rings)) +//BOOST_FUSION_ADAPT_STRUCT( +// mapnik::geometry::polygon, +// (mapnik::geometry::linear_ring const&, exterior_ring) +// (mapnik::geometry::polygon::rings_container const& , interior_rings)) -BOOST_FUSION_ADAPT_STRUCT( - mapnik::geometry::polygon, - (mapnik::geometry::linear_ring const&, exterior_ring) - (mapnik::geometry::polygon::rings_container const& , interior_rings)) +//BOOST_FUSION_ADAPT_STRUCT( +// mapnik::geometry::polygon, +// (mapnik::geometry::linear_ring const&, exterior_ring) +// (mapnik::geometry::polygon::rings_container const& , interior_rings)) #endif // MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP diff --git a/include/mapnik/geometry_is_empty.hpp b/include/mapnik/geometry_is_empty.hpp index 953bddc22..ccc85a41e 100644 --- a/include/mapnik/geometry_is_empty.hpp +++ b/include/mapnik/geometry_is_empty.hpp @@ -29,103 +29,114 @@ namespace mapnik { namespace geometry { namespace detail { +template struct geometry_is_empty { - bool operator() (mapnik::geometry::geometry const& geom) const + bool operator() (mapnik::geometry::geometry const& geom) const { return mapnik::util::apply_visitor(*this, geom); } - bool operator() (mapnik::geometry::point const&) const + bool operator() (mapnik::geometry::point const&) const { return false; } - bool operator() (mapnik::geometry::line_string const& geom) const + bool operator() (mapnik::geometry::line_string const& geom) const { return geom.empty(); } - bool operator() (mapnik::geometry::polygon const& geom) const + bool operator() (mapnik::geometry::linear_ring const& geom) const { return geom.empty(); } - bool operator() (mapnik::geometry::multi_point const& geom) const + bool operator() (mapnik::geometry::polygon const& geom) const + { + return geom.empty() || geom.front().empty(); + } + + bool operator() (mapnik::geometry::multi_point const& geom) const { return geom.empty(); } - bool operator() (mapnik::geometry::multi_line_string const& geom) const + bool operator() (mapnik::geometry::multi_line_string const& geom) const { return geom.empty(); } - bool operator() (mapnik::geometry::multi_polygon const& geom) const + bool operator() (mapnik::geometry::multi_polygon const& geom) const { return geom.empty(); } - bool operator() (mapnik::geometry::geometry_collection const& geom) const + bool operator() (mapnik::geometry::geometry_collection const& geom) const { return geom.empty(); } - template - bool operator() (T const&) const + template + bool operator() (U const&) const { return true; } }; +template struct geometry_has_empty { - bool operator() (mapnik::geometry::geometry const& geom) const + bool operator() (mapnik::geometry::geometry const& geom) const { return mapnik::util::apply_visitor(*this, geom); } - bool operator() (mapnik::geometry::geometry_empty const&) const + bool operator() (mapnik::geometry::geometry_empty const&) const { return false; } - bool operator() (mapnik::geometry::point const&) const + bool operator() (mapnik::geometry::point const&) const { return false; } - bool operator() (mapnik::geometry::line_string const&) const + bool operator() (mapnik::geometry::line_string const&) const { return false; } - bool operator() (mapnik::geometry::polygon const&) const + bool operator() (mapnik::geometry::linear_ring const&) const { return false; } - bool operator() (mapnik::geometry::multi_point const&) const + bool operator() (mapnik::geometry::polygon const&) const { return false; } - bool operator() (mapnik::geometry::multi_line_string const& geom) const + bool operator() (mapnik::geometry::multi_point const&) const { - return test_multigeometry(geom); + return false; } - bool operator() (mapnik::geometry::multi_polygon const& geom) const + bool operator() (mapnik::geometry::multi_line_string const& multi_line) const { - return test_multigeometry(geom); - } - - bool operator() (mapnik::geometry::geometry_collection const& geom) const - { - for (auto const & item : geom) + for (auto const& line : multi_line) { - if (geometry_is_empty()(item) || (*this)(item)) + if (line.empty()) return true; + } + return false; + } + + bool operator() (mapnik::geometry::multi_polygon const& multi_poly) const + { + for (auto const& poly : multi_poly) + { + if (poly.empty() || poly.front().empty()) // no-rings OR exterioir is empty { return true; } @@ -133,39 +144,39 @@ struct geometry_has_empty return false; } - template - bool operator() (T const&) const + 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() (U 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; - } }; } -template -inline bool is_empty(GeomType const& geom) +template +inline bool is_empty(G const& geom) { - return detail::geometry_is_empty()(geom); + using coordinate_type = typename G::coordinate_type; + return detail::geometry_is_empty()(geom); } -template -inline bool has_empty(GeomType const& geom) +template +inline bool has_empty(G const& geom) { - return detail::geometry_has_empty()(geom); + using coordinate_type = typename G::coordinate_type; + return detail::geometry_has_empty()(geom); } }} diff --git a/include/mapnik/geometry_is_simple.hpp b/include/mapnik/geometry_is_simple.hpp index 868b41afd..68953ca1f 100644 --- a/include/mapnik/geometry_is_simple.hpp +++ b/include/mapnik/geometry_is_simple.hpp @@ -36,24 +36,23 @@ namespace mapnik { namespace geometry { namespace detail { +template struct geometry_is_simple { using result_type = bool; - template result_type operator() (geometry const& geom) const { return mapnik::util::apply_visitor(*this, geom); } - result_type operator() (geometry_empty const& ) const + result_type operator() (geometry_empty const& ) const { // An empty geometry has no anomalous geometric points, such as self intersection or self tangency. // Therefore, we will return true return true; } - template result_type operator() (geometry_collection const& collection) const { for (auto const& geom : collection) @@ -63,12 +62,11 @@ struct geometry_is_simple return true; } - template result_type operator() (point const& pt) const { return boost::geometry::is_simple(pt); } - template + result_type operator() (line_string const& line) const { if (line.empty()) @@ -80,12 +78,12 @@ struct geometry_is_simple } return boost::geometry::is_simple(line); } - template + result_type operator() (polygon const& poly) const { - return boost::geometry::is_simple(poly); + return poly.empty() ? true : boost::geometry::is_simple(poly); } - template + result_type operator() (multi_point const& multi_pt) const { if (multi_pt.empty()) @@ -96,7 +94,7 @@ struct geometry_is_simple } return boost::geometry::is_simple(multi_pt); } - template + result_type operator() (multi_line_string const& multi_line) const { if (multi_line.empty()) @@ -111,7 +109,7 @@ struct geometry_is_simple } return true; } - template + result_type operator() (multi_polygon const& multi_poly) const { if (multi_poly.empty()) @@ -134,13 +132,14 @@ struct geometry_is_simple template inline bool is_simple(T const& geom) { - return detail::geometry_is_simple() (geom); + using coordinate_type = typename T::coordinate_type; + return detail::geometry_is_simple() (geom); } template inline bool is_simple(mapnik::geometry::geometry const& geom) { - return util::apply_visitor(detail::geometry_is_simple(), geom); + return util::apply_visitor(detail::geometry_is_simple(), geom); } }} diff --git a/include/mapnik/geometry_is_valid.hpp b/include/mapnik/geometry_is_valid.hpp index 95319cce9..fbaef63c4 100644 --- a/include/mapnik/geometry_is_valid.hpp +++ b/include/mapnik/geometry_is_valid.hpp @@ -37,22 +37,21 @@ namespace mapnik { namespace geometry { namespace detail { +template struct geometry_is_valid { using result_type = bool; - template result_type operator() (geometry const& geom) const { return mapnik::util::apply_visitor(*this, geom); } - result_type operator() (geometry_empty const& ) const + result_type operator() (geometry_empty const& ) const { return true; } - template result_type operator() (geometry_collection const& collection) const { for (auto const& geom : collection) @@ -62,65 +61,58 @@ struct geometry_is_valid return true; } - template result_type operator() (point const& pt) const { return boost::geometry::is_valid(pt); } - template result_type operator() (line_string const& line) const { return boost::geometry::is_valid(line); } - template result_type operator() (polygon const& poly) const { return boost::geometry::is_valid(poly); } - template result_type operator() (multi_point const& multi_pt) const { return boost::geometry::is_valid(multi_pt); } - template result_type operator() (multi_line_string const& multi_line) const { return boost::geometry::is_valid(multi_line); } - template result_type operator() (multi_polygon const& multi_poly) const { return boost::geometry::is_valid(multi_poly); } }; +template struct geometry_is_valid_reason { using result_type = bool; - + boost::geometry::validity_failure_type & failure_; geometry_is_valid_reason(boost::geometry::validity_failure_type & failure): failure_(failure) {} - template result_type operator() (geometry const& geom) const { return mapnik::util::apply_visitor(*this, geom); } - result_type operator() (geometry_empty const& ) const + result_type operator() (geometry_empty const& ) const { failure_ = boost::geometry::no_failure; return true; } - template result_type operator() (geometry_collection const& collection) const { for (auto const& geom : collection) @@ -130,65 +122,58 @@ struct geometry_is_valid_reason return true; } - template result_type operator() (point const& pt) const { return boost::geometry::is_valid(pt, failure_); } - template result_type operator() (line_string const& line) const { return boost::geometry::is_valid(line, failure_); } - template result_type operator() (polygon const& poly) const { return boost::geometry::is_valid(poly, failure_); } - template result_type operator() (multi_point const& multi_pt) const { return boost::geometry::is_valid(multi_pt, failure_); } - template result_type operator() (multi_line_string const& multi_line) const { return boost::geometry::is_valid(multi_line, failure_); } - template result_type operator() (multi_polygon const& multi_poly) const { return boost::geometry::is_valid(multi_poly, failure_); } }; +template struct geometry_is_valid_string { using result_type = bool; - + std::string & message_; geometry_is_valid_string(std::string & message): message_(message) {} - template result_type operator() (geometry const& geom) const { return mapnik::util::apply_visitor(*this, geom); } - result_type operator() (geometry_empty const& ) const + result_type operator() (geometry_empty const& ) const { message_ = "Geometry is valid"; return true; } - template result_type operator() (geometry_collection const& collection) const { for (auto const& geom : collection) @@ -198,82 +183,78 @@ struct geometry_is_valid_string return true; } - template result_type operator() (point const& pt) const { return boost::geometry::is_valid(pt, message_); } - template result_type operator() (line_string const& line) const { return boost::geometry::is_valid(line, message_); } - template result_type operator() (polygon const& poly) const { return boost::geometry::is_valid(poly, message_); } - template result_type operator() (multi_point const& multi_pt) const { return boost::geometry::is_valid(multi_pt, message_); } - template result_type operator() (multi_line_string const& multi_line) const { return boost::geometry::is_valid(multi_line, message_); } - template result_type operator() (multi_polygon const& multi_poly) const { return boost::geometry::is_valid(multi_poly, message_); } }; - } template inline bool is_valid(T const& geom) { - return detail::geometry_is_valid() (geom); + using coordinate_type = typename T::coordinate_type; + return detail::geometry_is_valid() (geom); } template inline bool is_valid(mapnik::geometry::geometry const& geom) { - return util::apply_visitor(detail::geometry_is_valid(), geom); + return util::apply_visitor(detail::geometry_is_valid(), geom); } template inline bool is_valid(T const& geom, boost::geometry::validity_failure_type & failure) { - return detail::geometry_is_valid_reason(failure) (geom); + using coordinate_type = typename T::coordinate_type; + return detail::geometry_is_valid_reason(failure) (geom); } template -inline bool is_valid(mapnik::geometry::geometry const& geom, +inline bool is_valid(mapnik::geometry::geometry const& geom, boost::geometry::validity_failure_type & failure) { - return util::apply_visitor(detail::geometry_is_valid_reason(failure), geom); + return util::apply_visitor(detail::geometry_is_valid_reason(failure), geom); } template inline bool is_valid(T const& geom, std::string & message) { - return detail::geometry_is_valid_string(message) (geom); + using coordinate_type = typename T::coordinate_type; + return detail::geometry_is_valid_string(message) (geom); } template -inline bool is_valid(mapnik::geometry::geometry const& geom, +inline bool is_valid(mapnik::geometry::geometry const& geom, std::string & message) { - return util::apply_visitor(detail::geometry_is_valid_string(message), geom); + return util::apply_visitor(detail::geometry_is_valid_string(message), geom); } }} diff --git a/include/mapnik/geometry_remove_empty.hpp b/include/mapnik/geometry_remove_empty.hpp index 9838b5a61..de60d9869 100644 --- a/include/mapnik/geometry_remove_empty.hpp +++ b/include/mapnik/geometry_remove_empty.hpp @@ -32,25 +32,25 @@ namespace detail { struct geometry_remove_empty { - mapnik::geometry::multi_line_string operator() (mapnik::geometry::multi_line_string const & geom) const + mapnik::geometry::multi_line_string operator() (mapnik::geometry::multi_line_string const& geom) const { return remove_empty(geom); } - mapnik::geometry::multi_polygon operator() (mapnik::geometry::multi_polygon const & geom) const + mapnik::geometry::multi_polygon operator() (mapnik::geometry::multi_polygon const& geom) const { return remove_empty(geom); } template - T operator() (T const & geom) const + T operator() (T const& geom) const { return geom; } private: template - T remove_empty(T const & geom) const + T remove_empty(T const& geom) const { T new_geom; for (auto const & g : geom) diff --git a/include/mapnik/geometry_reprojection_impl.hpp b/include/mapnik/geometry_reprojection_impl.hpp index ff01bd451..d76e84081 100644 --- a/include/mapnik/geometry_reprojection_impl.hpp +++ b/include/mapnik/geometry_reprojection_impl.hpp @@ -20,8 +20,7 @@ * *****************************************************************************/ -// mapnik -#include +// mapnik #include namespace mapnik { @@ -30,9 +29,10 @@ namespace geometry { namespace detail { -geometry_empty reproject_internal(geometry_empty const&, proj_transform const&, unsigned int &) +template +geometry_empty reproject_internal(geometry_empty const&, proj_transform const&, unsigned int &) { - return geometry_empty(); + return geometry_empty(); } template @@ -62,31 +62,22 @@ template polygon reproject_internal(polygon const& poly, proj_transform const& proj_trans, unsigned int & n_err) { polygon new_poly; - linear_ring new_ext(poly.exterior_ring); - unsigned int err = proj_trans.forward(new_ext); - // If the exterior ring doesn't transform don't bother with the holes. - if (err > 0 || new_ext.empty()) + new_poly.reserve(poly.size()); + bool exterior = true; + for (auto const& lr : poly) { - n_err += err; - } - else - { - new_poly.set_exterior_ring(std::move(new_ext)); - new_poly.interior_rings.reserve(poly.interior_rings.size()); - - for (auto const& lr : poly.interior_rings) + linear_ring new_lr(lr); + unsigned int err = proj_trans.forward(new_lr); + if (err > 0 || new_lr.empty()) { - linear_ring new_lr(lr); - err = proj_trans.forward(new_lr); - if (err > 0 || new_lr.empty()) - { - n_err += err; - // If there is an error in interior ring drop - // it from polygon. - continue; - } - new_poly.add_hole(std::move(new_lr)); + n_err += err; + // If there is an error in interior ring drop + // it from polygon. + if (!exterior) continue; } + if (exterior) exterior = false; + new_poly.push_back(std::move(new_lr)); + } return new_poly; } @@ -145,7 +136,7 @@ multi_polygon reproject_internal(multi_polygon const & mpoly, proj_transfo for (auto const& poly : mpoly) { polygon new_poly = reproject_internal(poly, proj_trans, n_err); - if (!new_poly.exterior_ring.empty()) + if (new_poly.size() > 0 && !new_poly[0].empty()) { new_mpoly.emplace_back(std::move(new_poly)); } @@ -162,7 +153,7 @@ geometry_collection reproject_internal(geometry_collection const & c, proj { geometry new_g = reproject_copy(g, proj_trans, n_err); - if (!new_g.template is()) + if (!new_g.template is>()) { new_c.emplace_back(std::move(new_g)); } @@ -178,9 +169,9 @@ struct geom_reproj_copy_visitor : proj_trans_(proj_trans), n_err_(n_err) {} - geometry operator() (geometry_empty const&) const + geometry operator() (geometry_empty) const { - return geometry_empty(); + return geometry_empty(); } geometry operator() (point const& p) const @@ -207,7 +198,7 @@ struct geom_reproj_copy_visitor { geometry geom; // default empty polygon new_poly = reproject_internal(poly, proj_trans_, n_err_); - if (new_poly.exterior_ring.empty()) return geom; + if (new_poly.size() == 0 || new_poly[0].size() == 0) return geom; geom = std::move(new_poly); return geom; } @@ -289,7 +280,8 @@ struct geom_reproj_visitor { return mapnik::util::apply_visitor((*this), geom); } - bool operator() (geometry_empty &) const { return true; } + template + bool operator() (geometry_empty &) const { return true; } template bool operator() (point & p) const @@ -314,12 +306,7 @@ struct geom_reproj_visitor { template bool operator() (polygon & poly) const { - if (proj_trans_.forward(poly.exterior_ring) > 0) - { - return false; - } - - for (auto & lr : poly.interior_rings) + for (auto & lr : poly) { if (proj_trans_.forward(lr) > 0) { @@ -332,7 +319,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/geometry_to_path.hpp b/include/mapnik/geometry_to_path.hpp index d443158a6..2aadbc200 100644 --- a/include/mapnik/geometry_to_path.hpp +++ b/include/mapnik/geometry_to_path.hpp @@ -28,24 +28,22 @@ namespace mapnik { namespace geometry { namespace detail { -//template +template struct geometry_to_path { geometry_to_path(path_type & p) : p_(p) {} - template void operator() (geometry const& geom) const { mapnik::util::apply_visitor(*this, geom); } - void operator() (geometry_empty const&) const + void operator() (geometry_empty const&) const { // no-op } // point - template void operator() (point const& pt) const { //point pt_new; @@ -54,7 +52,6 @@ struct geometry_to_path } // line_string - template void operator() (line_string const& line) const { bool first = true; @@ -68,34 +65,16 @@ struct geometry_to_path } // polygon - template void operator() (polygon const& poly) const { - // exterior - bool first = true; - for (auto const& pt : poly.exterior_ring) + // rings: exterior *interior + for (auto const& ring : poly) { - if (first) - { - p_.move_to(pt.x, pt.y); - first=false; - } - else - { - p_.line_to(pt.x, pt.y); - } - } - if (!first) - { - p_.close_path(); - } - // interior - for (auto const& ring : poly.interior_rings) - { - first = true; + bool first = true; for (auto const& pt : ring) { - if (first) { + if (first) + { p_.move_to(pt.x, pt.y); first=false; } @@ -112,7 +91,6 @@ struct geometry_to_path } // multi point - template void operator() (multi_point const& multi_pt) const { for (auto const& pt : multi_pt) @@ -121,7 +99,6 @@ struct geometry_to_path } } // multi_line_string - template void operator() (multi_line_string const& multi_line) const { for (auto const& line : multi_line) @@ -131,7 +108,6 @@ struct geometry_to_path } // multi_polygon - template void operator() (multi_polygon const& multi_poly) const { for (auto const& poly : multi_poly) @@ -139,8 +115,7 @@ struct geometry_to_path (*this)(poly); } } - - template + // geometry_collection void operator() (geometry_collection const& collection) const { for (auto const& geom : collection) @@ -157,7 +132,8 @@ struct geometry_to_path template void to_path(T const& geom, path_type & p) { - detail::geometry_to_path func(p); + using coordinate_type = typename T::coordinate_type; + detail::geometry_to_path func(p); func(geom); } diff --git a/include/mapnik/geometry_transform.hpp b/include/mapnik/geometry_transform.hpp index a7bb2f13d..4004d6083 100644 --- a/include/mapnik/geometry_transform.hpp +++ b/include/mapnik/geometry_transform.hpp @@ -103,9 +103,10 @@ struct geometry_transform using result_type = geometry; - geometry operator() (geometry_empty const& empty) const + template + geometry operator() (geometry_empty const& empty) const { - return empty; + return geometry_empty(); } template diff --git a/include/mapnik/geometry_type.hpp b/include/mapnik/geometry_type.hpp index b052446cd..c0055c5b4 100644 --- a/include/mapnik/geometry_type.hpp +++ b/include/mapnik/geometry_type.hpp @@ -29,56 +29,49 @@ namespace mapnik { namespace geometry { namespace detail { +template struct geometry_type { - template - mapnik::geometry::geometry_types operator () (T const& geom) const + mapnik::geometry::geometry_types operator () (mapnik::geometry::geometry const& geom) const { return mapnik::util::apply_visitor(*this, geom); } - mapnik::geometry::geometry_types operator() (geometry_empty const& ) const + mapnik::geometry::geometry_types operator() (geometry_empty const& ) const { return mapnik::geometry::geometry_types::Unknown; } - template mapnik::geometry::geometry_types operator () (mapnik::geometry::point const&) const { return mapnik::geometry::geometry_types::Point; } - template mapnik::geometry::geometry_types operator () (mapnik::geometry::line_string const&) const { return mapnik::geometry::geometry_types::LineString; } - template mapnik::geometry::geometry_types operator () (mapnik::geometry::polygon const&) const { return mapnik::geometry::geometry_types::Polygon; } - template mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_point const&) const { return mapnik::geometry::geometry_types::MultiPoint; } - template mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_line_string const&) const { return mapnik::geometry::geometry_types::MultiLineString; } - template mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_polygon const&) const { return mapnik::geometry::geometry_types::MultiPolygon; } - template mapnik::geometry::geometry_types operator () (mapnik::geometry::geometry_collection const&) const { return mapnik::geometry::geometry_types::GeometryCollection; @@ -89,7 +82,8 @@ struct geometry_type template static inline mapnik::geometry::geometry_types geometry_type(T const& geom) { - return detail::geometry_type()(geom); + using coordinate_type = typename T::coordinate_type; + return detail::geometry_type()(geom); } }} diff --git a/include/mapnik/hit_test_filter.hpp b/include/mapnik/hit_test_filter.hpp index d4b850496..fd9fb443c 100644 --- a/include/mapnik/hit_test_filter.hpp +++ b/include/mapnik/hit_test_filter.hpp @@ -49,7 +49,7 @@ struct hit_test_visitor y_(y), tol_(tol) {} - bool operator() (geometry::geometry_empty const& ) const + bool operator() (geometry::geometry_empty const& ) const { return false; } @@ -68,7 +68,7 @@ struct hit_test_visitor } bool operator() (geometry::line_string const& geom) const { - std::size_t num_points = geom.num_points(); + std::size_t num_points = geom.size(); if (num_points > 1) { for (std::size_t i = 1; i < num_points; ++i) @@ -89,41 +89,48 @@ struct hit_test_visitor } return false; } - bool operator() (geometry::polygon const& geom) const + bool operator() (geometry::polygon const& poly) const { - auto const& exterior = geom.exterior_ring; - std::size_t num_points = exterior.num_points(); - if (num_points < 4) return false; - bool inside = false; - for (std::size_t i = 1; i < num_points; ++i) - { - auto const& pt0 = exterior[i-1]; - auto const& pt1 = exterior[i]; + //auto const& exterior = geom.exterior_ring; + //std::size_t num_points = exterior.size(); + //if (num_points < 4) return false; + + //for (std::size_t i = 1; i < num_points; ++i) + //{ + // auto const& pt0 = exterior[i-1]; + // auto const& pt1 = exterior[i]; // todo - account for tolerance - if (pip(pt0.x,pt0.y,pt1.x,pt1.y,x_,y_)) - { - inside = !inside; - } - } - if (!inside) return false; - for (auto const& ring : geom.interior_rings) + // if (pip(pt0.x,pt0.y,pt1.x,pt1.y,x_,y_)) + // { + // inside = !inside; + // } + //} + //if (!inside) return false; + + //// FIXME !!! + bool inside = false; + bool exterior = true; + for (auto const& ring : poly) { - std::size_t num_interior_points = ring.size(); - if (num_interior_points < 4) + std::size_t num_points = ring.size(); + if (num_points < 4) { - continue; + if (exterior) return false; + else continue; } - for (std::size_t j = 1; j < num_interior_points; ++j) + + for (std::size_t j = 1; j < num_points; ++j) { - auto const& pt0 = ring[j-1]; + auto const& pt0 = ring[j - 1]; auto const& pt1 = ring[j]; - if (pip(pt0.x,pt0.y,pt1.x,pt1.y,x_,y_)) + if (pip(pt0.x, pt0.y, pt1.x, pt1.y, x_, y_)) { // TODO - account for tolerance - inside=!inside; + inside = !inside; } } } + //////////////////////////// return inside; } bool operator() (geometry::multi_polygon const& geom) const diff --git a/include/mapnik/json/geometry_generator_grammar.hpp b/include/mapnik/json/geometry_generator_grammar.hpp index 0e314650b..931c41629 100644 --- a/include/mapnik/json/geometry_generator_grammar.hpp +++ b/include/mapnik/json/geometry_generator_grammar.hpp @@ -99,8 +99,7 @@ struct geometry_generator_grammar : karma::rule const&()> linestring_coord; karma::rule const&()> polygon; karma::rule const&()> polygon_coord; - karma::rule const&()> exterior_ring_coord; - karma::rule::rings_container const&()> interior_ring_coord; + karma::rule const&()> linearring_coord; karma::rule const& ()> multi_point; karma::rule const& ()> multi_point_coord; karma::rule const& ()> multi_linestring; diff --git a/include/mapnik/json/geometry_generator_grammar_impl.hpp b/include/mapnik/json/geometry_generator_grammar_impl.hpp index 87a60db70..952bb739f 100644 --- a/include/mapnik/json/geometry_generator_grammar_impl.hpp +++ b/include/mapnik/json/geometry_generator_grammar_impl.hpp @@ -98,11 +98,9 @@ geometry_generator_grammar::geometry_generator_grammar ; linestring_coord = point_coord % lit(',') ; - polygon_coord = lit('[') << exterior_ring_coord << lit(']') << interior_ring_coord + linearring_coord = point_coord % lit(',') ; - exterior_ring_coord = linestring_coord.alias() - ; - interior_ring_coord = *(lit(",[") << exterior_ring_coord << lit(']')) + polygon_coord = (lit('[') << linearring_coord << lit(']')) % lit(',') ; multi_point_coord = linestring_coord.alias() ; @@ -110,7 +108,7 @@ geometry_generator_grammar::geometry_generator_grammar ; multi_polygon_coord = (lit('[') << polygon_coord << lit(']')) % lit(',') ; - geometries = geometry % lit(',') + geometries = geometry % lit(',') ; } diff --git a/include/mapnik/json/geometry_util.hpp b/include/mapnik/json/geometry_util.hpp index cf538ae73..82c4158b0 100644 --- a/include/mapnik/json/geometry_util.hpp +++ b/include/mapnik/json/geometry_util.hpp @@ -84,10 +84,7 @@ struct create_polygon { mapnik::geometry::polygon poly; std::size_t num_rings = rings.size(); - if (num_rings > 1) - { - poly.interior_rings.reserve(num_rings - 1); - } + poly.reserve(num_rings); for ( std::size_t i = 0; i < num_rings; ++i) { @@ -98,8 +95,7 @@ struct create_polygon { ring.emplace_back(std::move(pt)); } - if (i == 0) poly.set_exterior_ring(std::move(ring)); - else poly.add_hole(std::move(ring)); + poly.push_back(std::move(ring)); } geom_ = std::move(poly); mapnik::geometry::correct(geom_); @@ -179,9 +175,7 @@ struct create_multipolygon { mapnik::geometry::polygon poly; std::size_t num_rings = rings.size(); - if ( num_rings > 1) - poly.interior_rings.reserve(num_rings - 1); - + poly.reserve(num_rings); for ( std::size_t i = 0; i < num_rings; ++i) { std::size_t size = rings[i].size(); @@ -191,8 +185,8 @@ struct create_multipolygon { ring.emplace_back(std::move(pt)); } - if (i == 0) poly.set_exterior_ring(std::move(ring)); - else poly.add_hole(std::move(ring)); + + poly.push_back(std::move(ring)); } multi_poly.emplace_back(std::move(poly)); } diff --git a/include/mapnik/json/topojson_utils.hpp b/include/mapnik/json/topojson_utils.hpp index 40a2c91ff..dc4166475 100644 --- a/include/mapnik/json/topojson_utils.hpp +++ b/include/mapnik/json/topojson_utils.hpp @@ -313,7 +313,7 @@ struct feature_generator x = x * (*topo_.tr).scale_x + (*topo_.tr).translate_x; y = y * (*topo_.tr).scale_y + (*topo_.tr).translate_y; } - multi_point.add_coord(x, y); + multi_point.emplace_back(x, y); } feature->set_geometry(std::move(multi_point)); assign_properties(*feature, multi_pt, tr_); @@ -344,7 +344,7 @@ struct feature_generator x = (px += x) * (*topo_.tr).scale_x + (*topo_.tr).translate_x; y = (py += y) * (*topo_.tr).scale_y + (*topo_.tr).translate_y; } - line_string.add_coord(x,y); + line_string.emplace_back(x,y); } } } @@ -383,7 +383,7 @@ struct feature_generator x = (px += x) * (*topo_.tr).scale_x + (*topo_.tr).translate_x; y = (py += y) * (*topo_.tr).scale_y + (*topo_.tr).translate_y; } - line_string.add_coord(x, y); + line_string.emplace_back(x, y); } } @@ -406,8 +406,7 @@ struct feature_generator { std::vector processed_coords; mapnik::geometry::polygon polygon; - if (poly.rings.size() > 1) polygon.interior_rings.reserve(poly.rings.size() - 1); - bool first = true; + polygon.reserve(poly.rings.size()); bool hit = false; for (auto const& ring : poly.rings) { @@ -454,15 +453,7 @@ struct feature_generator } } } - if (first) - { - first = false; - polygon.set_exterior_ring(std::move(linear_ring)); - } - else - { - polygon.add_hole(std::move(linear_ring)); - } + polygon.push_back(std::move(linear_ring)); } if (hit) { @@ -485,9 +476,8 @@ struct feature_generator bool hit = false; for (auto const& poly : multi_poly.polygons) { - bool first = true; mapnik::geometry::polygon polygon; - if (poly.size() > 1) polygon.interior_rings.reserve(poly.size() - 1); + polygon.reserve(poly.size()); for (auto const& ring : poly) { @@ -524,27 +514,19 @@ struct feature_generator { for (auto const& c : (processed_coords | reversed)) { - linear_ring.add_coord(c.x, c.y); + linear_ring.emplace_back(c.x, c.y); } } else { for (auto const& c : processed_coords) { - linear_ring.add_coord(c.x, c.y); + linear_ring.emplace_back(c.x, c.y); } } } } - if (first) - { - first = false; - polygon.set_exterior_ring(std::move(linear_ring)); - } - else - { - polygon.add_hole(std::move(linear_ring)); - } + polygon.push_back(std::move(linear_ring)); } multi_polygon.push_back(std::move(polygon)); } diff --git a/include/mapnik/path.hpp b/include/mapnik/path.hpp index 6d253466d..fc1cdab1a 100644 --- a/include/mapnik/path.hpp +++ b/include/mapnik/path.hpp @@ -44,8 +44,8 @@ public: PolygonExterior = Polygon, PolygonInterior = Polygon | ( 1 << geometry_bits) }; - using coord_type = T; - using container_type = Container; + using coordinate_type = T; + using container_type = Container; using value_type = typename container_type::value_type; using size_type = typename container_type::size_type; container_type cont_; @@ -84,17 +84,17 @@ public: { return cont_.size(); } - void push_vertex(coord_type x, coord_type y, CommandType c) + void push_vertex(coordinate_type x, coordinate_type y, CommandType c) { cont_.push_back(x,y,c); } - void line_to(coord_type x,coord_type y) + void line_to(coordinate_type x,coordinate_type y) { push_vertex(x,y,SEG_LINETO); } - void move_to(coord_type x,coord_type y) + void move_to(coordinate_type x,coordinate_type y) { push_vertex(x,y,SEG_MOVETO); } diff --git a/include/mapnik/proj_strategy.hpp b/include/mapnik/proj_strategy.hpp index 064f3669b..a8366fc5a 100644 --- a/include/mapnik/proj_strategy.hpp +++ b/include/mapnik/proj_strategy.hpp @@ -35,13 +35,8 @@ #include #pragma GCC diagnostic pop - namespace mapnik { -namespace geometry { -template struct point; -template struct line_string; -} class projection; template class box2d; diff --git a/include/mapnik/proj_transform.hpp b/include/mapnik/proj_transform.hpp index 3247a15e3..71d678ef4 100644 --- a/include/mapnik/proj_transform.hpp +++ b/include/mapnik/proj_transform.hpp @@ -26,13 +26,12 @@ // mapnik #include #include +#include +// stl +#include namespace mapnik { -namespace geometry { -template struct point; -template struct line_string; -} class projection; template class box2d; @@ -50,8 +49,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/svg/geometry_svg_generator.hpp b/include/mapnik/svg/geometry_svg_generator.hpp index 7594c26dd..24135e5a6 100644 --- a/include/mapnik/svg/geometry_svg_generator.hpp +++ b/include/mapnik/svg/geometry_svg_generator.hpp @@ -145,7 +145,7 @@ struct svg_path_generator : { using path_type = Path; - using coord_type = typename boost::remove_pointer::type; + using coordinate_type = typename boost::remove_pointer::type; svg_path_generator(); // rules @@ -153,7 +153,7 @@ struct svg_path_generator : karma::rule point; karma::rule linestring; karma::rule polygon; - karma::rule svg_point; + karma::rule svg_point; karma::rule svg_path; // phoenix functions diff --git a/include/mapnik/svg/output/svg_path_iterator.hpp b/include/mapnik/svg/output/svg_path_iterator.hpp index b773888cd..639788ae4 100644 --- a/include/mapnik/svg/output/svg_path_iterator.hpp +++ b/include/mapnik/svg/output/svg_path_iterator.hpp @@ -117,8 +117,8 @@ private: void increment() { // variables used to extract vertex components. - geometry_type::coord_type x; - geometry_type::coord_type y; + geometry_type::coordinate_type x; + geometry_type::coordinate_type y; // extract next vertex components. unsigned cmd = path_.vertex(&x, &y); @@ -170,7 +170,7 @@ private: // Specialization of geometry_iterator, as needed by mapnik::svg::svg_path_data_grammar. // The Value type is a std::tuple that holds 5 elements, the command and the x and y coordinate. // Each coordinate is stored twice to match the needs of the grammar. -//using path_iterator_type = path_iterator, +//using path_iterator_type = path_iterator, // transform_path_adapter >; }} diff --git a/include/mapnik/text/symbolizer_helpers.hpp b/include/mapnik/text/symbolizer_helpers.hpp index 8fd3c155a..83a3c1939 100644 --- a/include/mapnik/text/symbolizer_helpers.hpp +++ b/include/mapnik/text/symbolizer_helpers.hpp @@ -69,6 +69,7 @@ public: using line_string_cref = std::reference_wrapper const>; using polygon_cref = std::reference_wrapper const>; using geometry_cref = util::variant; + // Using list instead of vector, because we delete random elements and need iterators to stay valid. using geometry_container_type = std::list; base_symbolizer_helper(symbolizer_base const& sym, @@ -110,6 +111,10 @@ protected: evaluated_text_properties_ptr text_props_; }; +namespace geometry { +MAPNIK_DECL mapnik::box2d envelope(mapnik::base_symbolizer_helper::geometry_cref const& geom); +} + // Helper object that does all the TextSymbolizer placement finding // work except actually rendering the object. diff --git a/include/mapnik/util/geometry_to_ds_type.hpp b/include/mapnik/util/geometry_to_ds_type.hpp index e09808f3e..7791285ac 100644 --- a/include/mapnik/util/geometry_to_ds_type.hpp +++ b/include/mapnik/util/geometry_to_ds_type.hpp @@ -42,7 +42,7 @@ namespace detail { struct datasource_geometry_type { - mapnik::datasource_geometry_t operator () (mapnik::geometry::geometry_empty const&) const + mapnik::datasource_geometry_t operator () (mapnik::geometry::geometry_empty const&) const { return mapnik::datasource_geometry_t::Unknown; } diff --git a/include/mapnik/util/geometry_to_wkb.hpp b/include/mapnik/util/geometry_to_wkb.hpp index bb9d05b34..f16ad240a 100644 --- a/include/mapnik/util/geometry_to_wkb.hpp +++ b/include/mapnik/util/geometry_to_wkb.hpp @@ -133,7 +133,7 @@ using wkb_buffer_ptr = std::unique_ptr; wkb_buffer_ptr point_wkb( geometry::point const& pt, wkbByteOrder byte_order) { - std::size_t size = 1 + 4 + 8 * 2 ; // byteOrder + wkbType + Point + std::size_t const size = 1 + 4 + 8 * 2 ; // byteOrder + wkbType + Point wkb_buffer_ptr wkb = std::make_unique(size); wkb_stream ss(wkb->buffer(), wkb->size()); ss.write(reinterpret_cast(&byte_order),1); @@ -148,7 +148,7 @@ wkb_buffer_ptr line_string_wkb(geometry::line_string const& line, wkbByt { std::size_t num_points = line.size(); assert(num_points > 1); - std::size_t size = 1 + 4 + 4 + 8 * 2 * num_points ; // byteOrder + wkbType + numPoints + Point*numPoints + std::size_t const size = 1 + 4 + 4 + 8 * 2 * num_points ; // byteOrder + wkbType + numPoints + Point*numPoints wkb_buffer_ptr wkb = std::make_unique(size); wkb_stream ss(wkb->buffer(), wkb->size()); ss.write(reinterpret_cast(&byte_order),1); @@ -167,10 +167,8 @@ wkb_buffer_ptr line_string_wkb(geometry::line_string const& line, wkbByt wkb_buffer_ptr polygon_wkb( geometry::polygon const& poly, wkbByteOrder byte_order) { std::size_t size = 1 + 4 + 4 ; // byteOrder + wkbType + numRings - size += 4 + 2 * 8 * poly.exterior_ring.size(); - for ( auto const& ring : poly.interior_rings) + for ( auto const& ring : poly) { - size += 4 + 2 * 8 * ring.size(); } @@ -178,17 +176,10 @@ wkb_buffer_ptr polygon_wkb( geometry::polygon const& poly, wkbByteOrder wkb_stream ss(wkb->buffer(), wkb->size()); ss.write(reinterpret_cast(&byte_order),1); write(ss, static_cast(mapnik::geometry::geometry_types::Polygon), 4, byte_order); - write(ss, poly.num_rings(), 4, byte_order); + write(ss, poly.size(), 4, byte_order); - // exterior - write(ss, poly.exterior_ring.size(), 4, byte_order); - for (auto const& pt : poly.exterior_ring) - { - write(ss, pt.x, 8, byte_order); - write(ss, pt.y, 8, byte_order); - } - // interiors - for (auto const& ring : poly.interior_rings) + // exterior *interior + for (auto const& ring : poly) { write(ss, ring.size(), 4, byte_order); for ( auto const& pt : ring) @@ -238,7 +229,7 @@ struct geometry_to_wkb return util::apply_visitor(*this, geom); } - result_type operator() (geometry::geometry_empty const&) const + result_type operator() (geometry::geometry_empty const&) const { return result_type(); } @@ -288,7 +279,7 @@ wkb_buffer_ptr multi_geom_wkb(MultiGeometry const& multi_geom, wkbByteOrder byte wkb_buffer_ptr multi_wkb = std::make_unique(multi_size); wkb_stream ss(multi_wkb->buffer(), multi_wkb->size()); ss.write(reinterpret_cast(&byte_order),1); - write(ss, static_cast(geometry::detail::geometry_type()(multi_geom)) , 4, byte_order); + write(ss, static_cast(geometry::detail::geometry_type()(multi_geom)) , 4, byte_order); write(ss, multi_geom.size(), 4 ,byte_order); for ( wkb_buffer_ptr const& wkb : wkb_cont) diff --git a/include/mapnik/util/spirit_transform_attribute.hpp b/include/mapnik/util/spirit_transform_attribute.hpp index c4176f1fa..e53d335a1 100644 --- a/include/mapnik/util/spirit_transform_attribute.hpp +++ b/include/mapnik/util/spirit_transform_attribute.hpp @@ -68,16 +68,16 @@ namespace boost { namespace spirit { namespace traits { } }; - template <> - struct transform_attribute const, - mapnik::geometry::polygon::rings_container const&, karma::domain> - { - using type = mapnik::geometry::polygon::rings_container const&; - static type pre(mapnik::geometry::polygon const& poly) - { - return poly.interior_rings; - } - }; +//template <> +// struct transform_attribute const, +// mapnik::geometry::polygon::rings_container const&, karma::domain> +// { +// using type = mapnik::geometry::polygon::rings_container const&; +// static type pre(mapnik::geometry::polygon const& poly) +// { +// return poly.interior_rings; +// } +// }; template <> struct transform_attribute const, @@ -156,16 +156,16 @@ namespace boost { namespace spirit { namespace traits { } }; - template <> - struct transform_attribute const, - mapnik::geometry::polygon::rings_container const&, karma::domain> - { - using type = mapnik::geometry::polygon::rings_container const&; - static type pre(mapnik::geometry::polygon const& poly) - { - return poly.interior_rings; - } - }; +//template <> +// struct transform_attribute const, +// mapnik::geometry::polygon::rings_container const&, karma::domain> +// { +// using type = mapnik::geometry::polygon::rings_container const&; +// static type pre(mapnik::geometry::polygon const& poly) +// { +// return poly.interior_rings; +// } +// }; template <> struct transform_attribute const, diff --git a/include/mapnik/vertex.hpp b/include/mapnik/vertex.hpp index 2e1d37844..92b6a0b4f 100644 --- a/include/mapnik/vertex.hpp +++ b/include/mapnik/vertex.hpp @@ -39,7 +39,7 @@ enum CommandType : std::uint8_t { template struct vertex { - using coord_type = T; + using coordinate_type = T; }; template @@ -47,9 +47,9 @@ struct vertex { enum no_init_t : std::uint8_t { no_init }; - using coord_type = T; - coord_type x; - coord_type y; + using coordinate_type = T; + coordinate_type x; + coordinate_type y; unsigned cmd; vertex() @@ -58,13 +58,13 @@ struct vertex explicit vertex(no_init_t) {} - vertex(coord_type x_,coord_type y_,unsigned cmd_) + vertex(coordinate_type x_,coordinate_type y_,unsigned cmd_) : x(x_),y(y_),cmd(cmd_) {} template vertex(vertex const& rhs) - : x(coord_type(rhs.x)), - y(coord_type(rhs.y)), + : x(coordinate_type(rhs.x)), + y(coordinate_type(rhs.y)), cmd(rhs.cmd) {} template diff --git a/include/mapnik/vertex_adapters.hpp b/include/mapnik/vertex_adapters.hpp index 0c77d7550..4dbdcd2e5 100644 --- a/include/mapnik/vertex_adapters.hpp +++ b/include/mapnik/vertex_adapters.hpp @@ -32,10 +32,9 @@ namespace mapnik { namespace geometry { template struct point_vertex_adapter { - using coord_type = typename point::coord_type; - + using coordinate_type = T; point_vertex_adapter(point const& pt); - unsigned vertex(coord_type * x, coord_type * y) const; + unsigned vertex(coordinate_type * x, coordinate_type * y) const; void rewind(unsigned) const; geometry_types type () const; point const& pt_; @@ -45,23 +44,23 @@ struct point_vertex_adapter template struct line_string_vertex_adapter { - using coord_type = typename point::coord_type; + using coordinate_type = T; line_string_vertex_adapter(line_string const& line); - unsigned vertex(coord_type * x, coord_type * y) const; + unsigned vertex(coordinate_type * x, coordinate_type * y) const; void rewind(unsigned) const; geometry_types type () const; line_string const& line_; mutable std::size_t current_index_; - const std::size_t end_index_; + const std::size_t end_index_; }; template struct polygon_vertex_adapter { - using coord_type = typename point::coord_type; + using coordinate_type = T; polygon_vertex_adapter(polygon const& poly); void rewind(unsigned) const; - unsigned vertex(coord_type * x, coord_type * y) const; + unsigned vertex(coordinate_type * x, coordinate_type * y) const; geometry_types type () const; private: polygon const& poly_; @@ -75,10 +74,10 @@ private: template struct ring_vertex_adapter { - using coord_type = typename point::coord_type; + using coordinate_type = T; ring_vertex_adapter(linear_ring const& ring); void rewind(unsigned) const; - unsigned vertex(coord_type * x, coord_type * y) const; + unsigned vertex(coordinate_type * x, coordinate_type * y) const; geometry_types type () const; private: linear_ring const& ring_; diff --git a/include/mapnik/vertex_processor.hpp b/include/mapnik/vertex_processor.hpp index 7cd2c40a4..57f6b4112 100644 --- a/include/mapnik/vertex_processor.hpp +++ b/include/mapnik/vertex_processor.hpp @@ -39,7 +39,8 @@ struct vertex_processor { util::apply_visitor(*this, geom); } - void operator() (geometry_empty const&) const + template + void operator() (geometry_empty const&) const { // no-op } diff --git a/include/mapnik/vertex_vector.hpp b/include/mapnik/vertex_vector.hpp index 67e30fc54..a55f5ec20 100644 --- a/include/mapnik/vertex_vector.hpp +++ b/include/mapnik/vertex_vector.hpp @@ -42,7 +42,7 @@ namespace mapnik template class vertex_vector : private util::noncopyable { - using coord_type = T; + using coordinate_type = T; enum block_e { block_shift = 8, block_size = 1<; + using value_type = std::tuple; using size_type = std::size_t; using command_size = std::uint8_t; private: unsigned num_blocks_; unsigned max_blocks_; - coord_type** vertices_; + coordinate_type** vertices_; command_size** commands_; size_type pos_; @@ -74,7 +74,7 @@ public: { if ( num_blocks_ ) { - coord_type** vertices=vertices_ + num_blocks_ - 1; + coordinate_type** vertices=vertices_ + num_blocks_ - 1; while ( num_blocks_-- ) { ::operator delete(*vertices); @@ -88,14 +88,14 @@ public: return pos_; } - void push_back (coord_type x,coord_type y,command_size command) + void push_back (coordinate_type x,coordinate_type y,command_size command) { size_type block = pos_ >> block_shift; if (block >= num_blocks_) { allocate_block(block); } - coord_type* vertex = vertices_[block] + ((pos_ & block_mask) << 1); + coordinate_type* vertex = vertices_[block] + ((pos_ & block_mask) << 1); command_size* cmd= commands_[block] + (pos_ & block_mask); *cmd = static_cast(command); @@ -103,11 +103,11 @@ public: *vertex = y; ++pos_; } - unsigned get_vertex(unsigned pos,coord_type* x,coord_type* y) const + unsigned get_vertex(unsigned pos,coordinate_type* x,coordinate_type* y) const { if (pos >= pos_) return SEG_END; size_type block = pos >> block_shift; - const coord_type* vertex = vertices_[block] + (( pos & block_mask) << 1); + const coordinate_type* vertex = vertices_[block] + (( pos & block_mask) << 1); *x = (*vertex++); *y = (*vertex); return commands_[block] [pos & block_mask]; @@ -126,8 +126,8 @@ private: { if (block >= max_blocks_) { - coord_type** new_vertices = - static_cast(::operator new (sizeof(coord_type*)*((max_blocks_ + grow_by) * 2))); + coordinate_type** new_vertices = + static_cast(::operator new (sizeof(coordinate_type*)*((max_blocks_ + grow_by) * 2))); command_size** new_commands = (command_size**)(new_vertices + max_blocks_ + grow_by); if (vertices_) { @@ -139,8 +139,8 @@ private: commands_ = new_commands; max_blocks_ += grow_by; } - vertices_[block] = static_cast - (::operator new(sizeof(coord_type)*(block_size * 2 + block_size / (sizeof(coord_type))))); + vertices_[block] = static_cast + (::operator new(sizeof(coordinate_type)*(block_size * 2 + block_size / (sizeof(coordinate_type))))); commands_[block] = (command_size*)(vertices_[block] + block_size*2); ++num_blocks_; 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/include/mapnik/wkt/wkt_generator_grammar.hpp b/include/mapnik/wkt/wkt_generator_grammar.hpp index f31fcc08e..2df1bd7cc 100644 --- a/include/mapnik/wkt/wkt_generator_grammar.hpp +++ b/include/mapnik/wkt/wkt_generator_grammar.hpp @@ -104,31 +104,31 @@ template struct wkt_generator_grammar : karma::grammar { - using coord_type = typename Geometry::coord_type; + using coordinate_type = typename Geometry::coordinate_type; wkt_generator_grammar(); // rules karma::rule geometry; karma::rule, Geometry const&() > geometry_dispatch; - karma::rule const&()> point; - karma::rule const&()> point_coord; - karma::rule const&()> linestring; - karma::rule const&()> linestring_coord; - karma::rule const&()> polygon; - karma::rule const&()> polygon_coord; - karma::rule const&()> exterior_ring_coord; - karma::rule > const&()> interior_ring_coord; - karma::rule const& ()> multi_point; - karma::rule const& ()> multi_point_coord; - karma::rule const& ()> multi_linestring; - karma::rule const& ()> multi_linestring_coord; - karma::rule const& ()> multi_polygon; - karma::rule const& ()> multi_polygon_coord; - karma::rule const& ()> geometry_collection; - karma::rule const& ()> geometries; + karma::rule const&()> point; + karma::rule const&()> point_coord; + karma::rule const&()> linestring; + karma::rule const&()> linestring_coord; + karma::rule const&()> polygon; + karma::rule const&()> polygon_coord; + karma::rule const&()> ring; + //karma::rule > const&()> interior_ring_coord; + karma::rule const& ()> multi_point; + karma::rule const& ()> multi_point_coord; + karma::rule const& ()> multi_linestring; + karma::rule const& ()> multi_linestring_coord; + karma::rule const& ()> multi_polygon; + karma::rule const& ()> multi_polygon_coord; + karma::rule const& ()> geometry_collection; + karma::rule const& ()> geometries; boost::phoenix::function > geometry_type; karma::symbols empty; // - typename detail::coordinate_generator::generator coordinate; + typename detail::coordinate_generator::generator coordinate; }; }} diff --git a/include/mapnik/wkt/wkt_generator_grammar_impl.hpp b/include/mapnik/wkt/wkt_generator_grammar_impl.hpp index 8d950edd0..ea000ca92 100644 --- a/include/mapnik/wkt/wkt_generator_grammar_impl.hpp +++ b/include/mapnik/wkt/wkt_generator_grammar_impl.hpp @@ -79,7 +79,7 @@ wkt_generator_grammar::wkt_generator_grammar() << (geometry_collection | empty[_1 = _a])) | (&uint_(geometry::geometry_types::Unknown)[_1 = _a] - << lit("POINT EMPTY")) // special case for geometry_empty as mapnik::geometry::point can't be empty + << lit("POINT EMPTY")) // special case for geometry_empty as mapnik::geometry::point can't be empty ; point = lit("POINT(") << point_coord << lit(")") @@ -100,11 +100,9 @@ wkt_generator_grammar::wkt_generator_grammar() ; linestring_coord = point_coord % lit(',') ; - polygon_coord = lit('(') << exterior_ring_coord << lit(')') << interior_ring_coord + polygon_coord = ring % lit(',')//<< interior_ring_coord ; - exterior_ring_coord = linestring_coord.alias() - ; - interior_ring_coord = *(lit(",(") << exterior_ring_coord << lit(')')) + ring = lit('(') << linestring_coord << lit(')') ; multi_point_coord = linestring_coord.alias() ; diff --git a/include/mapnik/wkt/wkt_grammar.hpp b/include/mapnik/wkt/wkt_grammar.hpp index 9d23f81ca..55750b838 100644 --- a/include/mapnik/wkt/wkt_grammar.hpp +++ b/include/mapnik/wkt/wkt_grammar.hpp @@ -60,23 +60,14 @@ struct move_part } }; -struct set_exterior -{ - using result_type = void; - template - void operator() (Polygon & poly, Ring && ring) const - { - poly.set_exterior_ring(std::move(ring)); - } -}; -struct add_hole +struct set_ring { using result_type = void; template void operator() (Polygon & poly, Ring && ring) const { - poly.add_hole(std::move(ring)); + poly.push_back(std::move(ring)); } }; @@ -109,8 +100,7 @@ struct wkt_grammar : qi::grammar empty_set; boost::phoenix::function assign; boost::phoenix::function move_part; - boost::phoenix::function set_exterior; - boost::phoenix::function add_hole; + boost::phoenix::function set_ring; }; }} diff --git a/include/mapnik/wkt/wkt_grammar_impl.hpp b/include/mapnik/wkt/wkt_grammar_impl.hpp index d2444130a..33caab6bc 100644 --- a/include/mapnik/wkt/wkt_grammar_impl.hpp +++ b/include/mapnik/wkt/wkt_grammar_impl.hpp @@ -62,7 +62,7 @@ wkt_grammar::wkt_grammar() // ::= point point_tagged_text = no_case[lit("POINT")] - >> (point_text[assign(_r1,_1)] | empty_set[assign(_r1,construct())]) + >> (point_text[assign(_r1,_1)] | empty_set[assign(_r1,construct>())]) ; // ::= | point_text = (lit("(") >> point >> lit(')')) @@ -86,12 +86,14 @@ wkt_grammar::wkt_grammar() // ::= | { }* polygon_text = - (lit('(') >> linearring_text[set_exterior(_val,_1)] >> *(lit(',') >> linearring_text[add_hole(_val,_1)]) >> lit(')')) + lit('(') >> linearring_text[set_ring(_val,_1)] % lit(',') >> lit(')') | empty_set ; - linearring_text = ring_points | empty_set + linearring_text = ring_points + | + empty_set ; // ::= multipoint multipoint_tagged_text = no_case[lit("MULTIPOINT")] diff --git a/plugins/input/csv/csv_featureset.cpp b/plugins/input/csv/csv_featureset.cpp index 151811201..f73b52a54 100644 --- a/plugins/input/csv/csv_featureset.cpp +++ b/plugins/input/csv/csv_featureset.cpp @@ -73,7 +73,7 @@ mapnik::feature_ptr csv_featureset::parse_feature(char const* beg, char const* e { auto values = csv_utils::parse_line(beg, end, separator_, quote_, headers_.size()); auto geom = csv_utils::extract_geometry(values, locator_); - if (!geom.is()) + if (!geom.is>()) { mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_, ++feature_id_)); feature->set_geometry(std::move(geom)); diff --git a/plugins/input/csv/csv_index_featureset.cpp b/plugins/input/csv/csv_index_featureset.cpp index e94f41bc5..493d65daf 100644 --- a/plugins/input/csv/csv_index_featureset.cpp +++ b/plugins/input/csv/csv_index_featureset.cpp @@ -90,7 +90,7 @@ mapnik::feature_ptr csv_index_featureset::parse_feature(char const* beg, char co { auto values = csv_utils::parse_line(beg, end, separator_, quote_, headers_.size()); auto geom = csv_utils::extract_geometry(values, locator_); - if (!geom.is()) + if (!geom.is>()) { mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_, ++feature_id_)); feature->set_geometry(std::move(geom)); diff --git a/plugins/input/csv/csv_inline_featureset.cpp b/plugins/input/csv/csv_inline_featureset.cpp index 2d91efcf4..54c8f14f9 100644 --- a/plugins/input/csv/csv_inline_featureset.cpp +++ b/plugins/input/csv/csv_inline_featureset.cpp @@ -58,7 +58,7 @@ mapnik::feature_ptr csv_inline_featureset::parse_feature(std::string const& str) auto const* end = start + str.size(); auto values = csv_utils::parse_line(start, end, separator_, quote_, headers_.size()); auto geom = csv_utils::extract_geometry(values, locator_); - if (!geom.is()) + if (!geom.is>()) { mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_, ++feature_id_)); feature->set_geometry(std::move(geom)); diff --git a/plugins/input/csv/csv_utils.cpp b/plugins/input/csv/csv_utils.cpp index 217276f6a..b35942d4c 100644 --- a/plugins/input/csv/csv_utils.cpp +++ b/plugins/input/csv/csv_utils.cpp @@ -406,7 +406,7 @@ void csv_file_parser::parse_csv_and_boxes(std::istream & csv_file, T & boxes) } auto geom = extract_geometry(values, locator_); - if (!geom.is()) + if (!geom.is>()) { auto box = mapnik::geometry::envelope(geom); if (!extent_initialized_) diff --git a/plugins/input/ogr/ogr_converter.cpp b/plugins/input/ogr/ogr_converter.cpp index 207c0e1e4..e409e81a0 100644 --- a/plugins/input/ogr/ogr_converter.cpp +++ b/plugins/input/ogr/ogr_converter.cpp @@ -98,7 +98,7 @@ mapnik::geometry::line_string ogr_converter::convert_linestring(OGRLineS geom.reserve(num_points); for (int i = 0; i < num_points; ++i) { - geom.add_coord(ogr_geom->getX(i), ogr_geom->getY(i)); + geom.emplace_back(ogr_geom->getX(i), ogr_geom->getY(i)); } return geom; } @@ -127,7 +127,7 @@ mapnik::geometry::polygon ogr_converter::convert_polygon(OGRPolygon* ogr { exterior.emplace_back(ogr_exterior->getX(i), ogr_exterior->getY(i)); } - geom.set_exterior_ring(std::move(exterior)); + geom.push_back(std::move(exterior)); int num_interior = ogr_geom->getNumInteriorRings(); for (int r = 0; r < num_interior; ++r) @@ -140,7 +140,7 @@ mapnik::geometry::polygon ogr_converter::convert_polygon(OGRPolygon* ogr { interior.emplace_back(ogr_interior->getX(i), ogr_interior->getY(i)); } - geom.add_hole(std::move(interior)); + geom.push_back(std::move(interior)); } return geom; } diff --git a/plugins/input/shape/shape_io.cpp b/plugins/input/shape/shape_io.cpp index 5dd591996..b5d3776e4 100644 --- a/plugins/input/shape/shape_io.cpp +++ b/plugins/input/shape/shape_io.cpp @@ -114,7 +114,7 @@ mapnik::geometry::geometry shape_io::read_polyline(shape_file::record_ty { double x = record.read_double(); double y = record.read_double(); - line.add_coord(x, y); + line.emplace_back(x, y); } geom = std::move(line); } @@ -144,7 +144,7 @@ mapnik::geometry::geometry shape_io::read_polyline(shape_file::record_ty { double x = record.read_double(); double y = record.read_double(); - line.add_coord(x, y); + line.emplace_back(x, y); } multi_line.push_back(std::move(line)); } @@ -210,17 +210,17 @@ mapnik::geometry::geometry shape_io::read_polygon(shape_file::record_typ } if (k == 0) { - poly.set_exterior_ring(std::move(ring)); + poly.push_back(std::move(ring)); } else if (mapnik::util::is_clockwise(ring)) { multi_poly.emplace_back(std::move(poly)); - poly.interior_rings.clear(); - poly.set_exterior_ring(std::move(ring)); + poly.clear(); + poly.push_back(std::move(ring)); } else { - poly.add_hole(std::move(ring)); + poly.push_back(std::move(ring)); } } @@ -260,17 +260,17 @@ mapnik::geometry::geometry shape_io::read_polygon_parts(shape_file::reco } if (k == 0) { - poly.set_exterior_ring(std::move(ring)); + poly.push_back(std::move(ring)); } else if (mapnik::util::is_clockwise(ring)) { multi_poly.emplace_back(std::move(poly)); - poly.interior_rings.clear(); - poly.set_exterior_ring(std::move(ring)); + poly.clear(); + poly.push_back(std::move(ring)); } else { - poly.add_hole(std::move(ring)); + poly.push_back(std::move(ring)); } } diff --git a/src/agg/process_debug_symbolizer.cpp b/src/agg/process_debug_symbolizer.cpp index 3c3f898f8..137c2457d 100644 --- a/src/agg/process_debug_symbolizer.cpp +++ b/src/agg/process_debug_symbolizer.cpp @@ -180,22 +180,30 @@ struct render_ring_visitor } } - void operator()(mapnik::geometry::polygon const& geom) const + void operator()(mapnik::geometry::polygon const& poly) const { agg::rgba8 red(255,0,0,255); agg::rgba8 green(0,255,255,255); agg::rgba8 black(0,0,0,255); - renderer_.draw_ring(geom.exterior_ring,red); - if (mapnik::util::is_clockwise(geom.exterior_ring)) + bool exterior = true; + for (auto const& ring : poly) { - renderer_.draw_outline(geom.exterior_ring,black); - } - for (auto const& ring : geom.interior_rings) - { - renderer_.draw_ring(ring,green); - if (!mapnik::util::is_clockwise(ring)) + if (exterior) { - renderer_.draw_outline(ring,black); + exterior = false; + renderer_.draw_ring(ring, red); + if (mapnik::util::is_clockwise(ring)) + { + renderer_.draw_outline(ring,black); + } + } + else + { + renderer_.draw_ring(ring,green); + if (!mapnik::util::is_clockwise(ring)) + { + renderer_.draw_outline(ring,black); + } } } } diff --git a/src/box2d.cpp b/src/box2d.cpp index 407c054ba..2a87553ce 100644 --- a/src/box2d.cpp +++ b/src/box2d.cpp @@ -26,6 +26,7 @@ namespace mapnik { template class box2d; +template class box2d; template class box2d; template class box2d; diff --git a/src/geometry_reprojection.cpp b/src/geometry_reprojection.cpp index 7cd3ff08d..fad2c5b6f 100644 --- a/src/geometry_reprojection.cpp +++ b/src/geometry_reprojection.cpp @@ -29,7 +29,7 @@ namespace mapnik { namespace geometry { template MAPNIK_DECL geometry reproject_copy(geometry const& geom, proj_transform const& proj_trans, unsigned int & n_err); -template MAPNIK_DECL geometry_empty reproject_copy(geometry_empty const& geom, proj_transform const& proj_trans, unsigned int & n_err); +template MAPNIK_DECL geometry_empty reproject_copy(geometry_empty const& geom, proj_transform const& proj_trans, unsigned int & n_err); template MAPNIK_DECL point reproject_copy(point const& geom, proj_transform const& proj_trans, unsigned int & n_err); template MAPNIK_DECL line_string reproject_copy(line_string const& geom, proj_transform const& proj_trans, unsigned int & n_err); template MAPNIK_DECL polygon reproject_copy(polygon const& geom, proj_transform const& proj_trans, unsigned int & n_err); @@ -39,7 +39,7 @@ template MAPNIK_DECL multi_polygon reproject_copy(multi_polygon template MAPNIK_DECL geometry_collection reproject_copy(geometry_collection const& geom, proj_transform const& proj_trans, unsigned int & n_err); template MAPNIK_DECL geometry reproject_copy(geometry const& geom, projection const& source, projection const& dest, unsigned int & n_err); -template MAPNIK_DECL geometry_empty reproject_copy(geometry_empty const& geom, projection const& source, projection const& dest, unsigned int & n_err); +template MAPNIK_DECL geometry_empty reproject_copy(geometry_empty const& geom, projection const& source, projection const& dest, unsigned int & n_err); template MAPNIK_DECL point reproject_copy(point const& geom, projection const& source, projection const& dest, unsigned int & n_err); template MAPNIK_DECL line_string reproject_copy(line_string const& geom, projection const& source, projection const& dest, unsigned int & n_err); template MAPNIK_DECL polygon reproject_copy(polygon const& geom, projection const& source, projection const& dest, unsigned int & n_err); @@ -49,7 +49,7 @@ template MAPNIK_DECL multi_polygon reproject_copy(multi_polygon template MAPNIK_DECL geometry_collection reproject_copy(geometry_collection const& geom, projection const& source, projection const& dest, unsigned int & n_err); template MAPNIK_DECL bool reproject(geometry & geom, proj_transform const& proj_trans); -template MAPNIK_DECL bool reproject(geometry_empty & geom, proj_transform const& proj_trans); +template MAPNIK_DECL bool reproject(geometry_empty & geom, proj_transform const& proj_trans); template MAPNIK_DECL bool reproject(point & geom, proj_transform const& proj_trans); template MAPNIK_DECL bool reproject(line_string & geom, proj_transform const& proj_trans); template MAPNIK_DECL bool reproject(polygon & geom, proj_transform const& proj_trans); @@ -59,7 +59,7 @@ template MAPNIK_DECL bool reproject(multi_polygon & geom, proj_transform template MAPNIK_DECL bool reproject(geometry_collection & geom, proj_transform const& proj_trans); template MAPNIK_DECL bool reproject(geometry & geom, projection const& source, projection const& dest); -template MAPNIK_DECL bool reproject(geometry_empty & geom, projection const& source, projection const& dest); +template MAPNIK_DECL bool reproject(geometry_empty & geom, projection const& source, projection const& dest); template MAPNIK_DECL bool reproject(point & geom, projection const& source, projection const& dest); template MAPNIK_DECL bool reproject(line_string & geom, projection const& source, projection const& dest); template MAPNIK_DECL bool reproject(polygon & geom, projection const& source, projection const& dest); diff --git a/src/proj_transform.cpp b/src/proj_transform.cpp index 9c23d805a..4761724de 100644 --- a/src/proj_transform.cpp +++ b/src/proj_transform.cpp @@ -103,7 +103,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; @@ -244,7 +244,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/src/text/symbolizer_helpers.cpp b/src/text/symbolizer_helpers.cpp index fe5568ad2..9eae83cfa 100644 --- a/src/text/symbolizer_helpers.cpp +++ b/src/text/symbolizer_helpers.cpp @@ -110,7 +110,7 @@ struct split_multi_geometries split_multi_geometries(container_type & cont) : cont_(cont) { } - void operator() (geometry::geometry_empty const&) const {} + void operator() (geometry::geometry_empty const&) const {} void operator() (geometry::multi_point const& multi_pt) const { for ( auto const& pt : multi_pt ) diff --git a/src/twkb.cpp b/src/twkb.cpp index f1928e5a6..64ef6aa34 100644 --- a/src/twkb.cpp +++ b/src/twkb.cpp @@ -82,7 +82,7 @@ public: mapnik::geometry::geometry read() { - mapnik::geometry::geometry geom = mapnik::geometry::geometry_empty(); + mapnik::geometry::geometry geom = mapnik::geometry::geometry_empty(); // Read the metadata bytes, populating all the // information about optional fields, extended (z/m) dimensions // expansion factors and so on @@ -328,11 +328,7 @@ private: { unsigned int num_rings = read_unsigned_integer(); mapnik::geometry::polygon poly; - if (num_rings > 1) - { - poly.interior_rings.reserve(num_rings - 1); - } - + poly.reserve(num_rings); for (unsigned int i = 0; i < num_rings; ++i) { mapnik::geometry::linear_ring ring; @@ -342,8 +338,7 @@ private: ring.reserve(num_points); read_coords>(ring, num_points); } - if ( i == 0) poly.set_exterior_ring(std::move(ring)); - else poly.add_hole(std::move(ring)); + poly.push_back(std::move(ring)); } return poly; } diff --git a/src/vertex_adapters.cpp b/src/vertex_adapters.cpp index e96a9e25e..dd7b0202f 100644 --- a/src/vertex_adapters.cpp +++ b/src/vertex_adapters.cpp @@ -34,7 +34,7 @@ point_vertex_adapter::point_vertex_adapter(point const& pt) first_(true) {} template -unsigned point_vertex_adapter::vertex(coord_type * x, coord_type * y) const +unsigned point_vertex_adapter::vertex(coordinate_type * x, coordinate_type * y) const { if (first_) { @@ -67,7 +67,7 @@ line_string_vertex_adapter::line_string_vertex_adapter(line_string const& {} template -unsigned line_string_vertex_adapter::vertex(coord_type * x, coord_type * y) const +unsigned line_string_vertex_adapter::vertex(coordinate_type * x, coordinate_type * y) const { if (current_index_ != end_index_) { @@ -102,22 +102,22 @@ template polygon_vertex_adapter::polygon_vertex_adapter(polygon const& poly) : poly_(poly), rings_itr_(0), - rings_end_(poly_.interior_rings.size() + 1), + rings_end_(poly_.size()), current_index_(0), - end_index_((rings_itr_ < rings_end_) ? poly_.exterior_ring.size() : 0), + end_index_(poly_.empty() ? 0 : poly_[0].size()), start_loop_(true) {} template void polygon_vertex_adapter::rewind(unsigned) const { rings_itr_ = 0; - rings_end_ = poly_.interior_rings.size() + 1; + rings_end_ = poly_.size(); current_index_ = 0; - end_index_ = (rings_itr_ < rings_end_) ? poly_.exterior_ring.size() : 0; + end_index_ = poly_.empty() ? 0 : poly_[0].size(); start_loop_ = true; } template -unsigned polygon_vertex_adapter::vertex(coord_type * x, coord_type * y) const +unsigned polygon_vertex_adapter::vertex(coordinate_type * x, coordinate_type * y) const { if (rings_itr_ == rings_end_) { @@ -125,8 +125,7 @@ unsigned polygon_vertex_adapter::vertex(coord_type * x, coord_type * y) const } if (current_index_ < end_index_) { - point const& coord = (rings_itr_ == 0) ? - poly_.exterior_ring[current_index_++] : poly_.interior_rings[rings_itr_- 1][current_index_++]; + point const& coord = poly_[rings_itr_][current_index_++]; *x = coord.x; *y = coord.y; if (start_loop_) @@ -145,8 +144,8 @@ unsigned polygon_vertex_adapter::vertex(coord_type * x, coord_type * y) const else if (++rings_itr_ != rings_end_) { current_index_ = 0; - end_index_ = poly_.interior_rings[rings_itr_ - 1].size(); - point const& coord = poly_.interior_rings[rings_itr_ - 1][current_index_++]; + end_index_ = poly_[rings_itr_].size(); + point const& coord = poly_[rings_itr_][current_index_++]; *x = coord.x; *y = coord.y; return mapnik::SEG_MOVETO; @@ -177,7 +176,7 @@ void ring_vertex_adapter::rewind(unsigned) const } template -unsigned ring_vertex_adapter::vertex(coord_type * x, coord_type * y) const +unsigned ring_vertex_adapter::vertex(coordinate_type * x, coordinate_type * y) const { if (current_index_ < end_index_) { diff --git a/src/wkb.cpp b/src/wkb.cpp index 94c1fccde..21a07fd97 100644 --- a/src/wkb.cpp +++ b/src/wkb.cpp @@ -119,7 +119,7 @@ public: mapnik::geometry::geometry read() { - mapnik::geometry::geometry geom = mapnik::geometry::geometry_empty(); + mapnik::geometry::geometry geom = mapnik::geometry::geometry_empty(); int type = read_integer(); switch (type) { @@ -329,11 +329,7 @@ private: { int num_rings = read_integer(); mapnik::geometry::polygon poly; - if (num_rings > 1) - { - poly.interior_rings.reserve(num_rings - 1); - } - + poly.reserve(num_rings); for (int i = 0; i < num_rings; ++i) { mapnik::geometry::linear_ring ring; @@ -343,8 +339,7 @@ private: ring.reserve(num_points); read_coords, M, Z>(ring, num_points); } - if ( i == 0) poly.set_exterior_ring(std::move(ring)); - else poly.add_hole(std::move(ring)); + poly.push_back(std::move(ring)); } return poly; } diff --git a/test/unit/datasource/ds_test_util.hpp b/test/unit/datasource/ds_test_util.hpp index 46868d4e5..dd2e4a242 100644 --- a/test/unit/datasource/ds_test_util.hpp +++ b/test/unit/datasource/ds_test_util.hpp @@ -121,48 +121,53 @@ inline void require_attributes(mapnik::feature_ptr feature, } namespace detail { -struct feature_count { - template - std::size_t operator()(T const &geom) const { + +template +struct feature_count +{ + template + std::size_t operator()(U const &geom) const + { return mapnik::util::apply_visitor(*this, geom); } - std::size_t operator()(mapnik::geometry::geometry_empty const &) const { + std::size_t operator()(mapnik::geometry::geometry_empty const &) const + { return 0; } - template - std::size_t operator()(mapnik::geometry::point const &) const { + std::size_t operator()(mapnik::geometry::point const &) const + { return 1; } - template - std::size_t operator()(mapnik::geometry::line_string const &) const { + std::size_t operator()(mapnik::geometry::line_string const &) const + { return 1; } - template - std::size_t operator()(mapnik::geometry::polygon const &) const { + std::size_t operator()(mapnik::geometry::polygon const &) const + { return 1; } - template - std::size_t operator()(mapnik::geometry::multi_point const &mp) const { + std::size_t operator()(mapnik::geometry::multi_point const &mp) const + { return mp.size(); } - template - std::size_t operator()(mapnik::geometry::multi_line_string const &mls) const { + std::size_t operator()(mapnik::geometry::multi_line_string const &mls) const + { return mls.size(); } - template - std::size_t operator()(mapnik::geometry::multi_polygon const &mp) const { + std::size_t operator()(mapnik::geometry::multi_polygon const &mp) const + { return mp.size(); } - template - std::size_t operator()(mapnik::geometry::geometry_collection const &col) const { + std::size_t operator()(mapnik::geometry::geometry_collection const &col) const + { std::size_t sum = 0; for (auto const &geom : col) { sum += operator()(geom); @@ -174,7 +179,7 @@ struct feature_count { template inline std::size_t feature_count(mapnik::geometry::geometry const &g) { - return detail::feature_count()(g); + return detail::feature_count()(g); } inline void require_geometry(mapnik::feature_ptr feature, diff --git a/test/unit/datasource/geojson.cpp b/test/unit/datasource/geojson.cpp index bcc9fa2e6..6dcc154c1 100644 --- a/test/unit/datasource/geojson.cpp +++ b/test/unit/datasource/geojson.cpp @@ -191,10 +191,9 @@ TEST_CASE("geojson") { auto const& geometry = feature->get_geometry(); REQUIRE(mapnik::geometry::geometry_type(geometry) == mapnik::geometry::Polygon); auto const& poly = mapnik::util::get >(geometry); - REQUIRE(poly.num_rings() == 2); - REQUIRE(poly.exterior_ring.size() == 5); - REQUIRE(poly.interior_rings.size() == 1); - REQUIRE(poly.interior_rings[0].size() == 5); + REQUIRE(poly.size() == 2); + REQUIRE(poly[0].size() == 5); + REQUIRE(poly[1].size() == 5); REQUIRE(mapnik::geometry::envelope(poly) == mapnik::box2d(100,0,101,1)); } @@ -248,8 +247,8 @@ TEST_CASE("geojson") { REQUIRE(mapnik::geometry::geometry_type(geometry) == mapnik::geometry::MultiPolygon); auto const& multi_poly = mapnik::util::get >(geometry); REQUIRE(multi_poly.size() == 2); - REQUIRE(multi_poly[0].num_rings() == 1); - REQUIRE(multi_poly[1].num_rings() == 2); + REQUIRE(multi_poly[0].size() == 1); + REQUIRE(multi_poly[1].size() == 2); REQUIRE(mapnik::geometry::envelope(multi_poly) == mapnik::box2d(100,0,103,3)); } diff --git a/test/unit/geometry/centroid.cpp b/test/unit/geometry/centroid.cpp index cdfbd6e4b..4549bec9b 100644 --- a/test/unit/geometry/centroid.cpp +++ b/test/unit/geometry/centroid.cpp @@ -1,4 +1,3 @@ - #include "catch.hpp" #include @@ -7,7 +6,7 @@ TEST_CASE("geometry centroid") { SECTION("empty geometry") { - mapnik::geometry::geometry_empty geom; + mapnik::geometry::geometry_empty geom; mapnik::geometry::point centroid; REQUIRE(!mapnik::geometry::centroid(geom, centroid)); } @@ -31,9 +30,9 @@ SECTION("point") { SECTION("linestring") { mapnik::geometry::line_string line; - line.add_coord(0, 0); - line.add_coord(25, 25); - line.add_coord(50, 50); + line.emplace_back(0, 0); + line.emplace_back(25, 25); + line.emplace_back(50, 50); mapnik::geometry::point centroid; REQUIRE(mapnik::geometry::centroid(line, centroid)); REQUIRE(centroid.x == 25); @@ -51,12 +50,12 @@ SECTION("polygon") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0, 0); - ring.add_coord(1, 0); - ring.add_coord(1, 1); - ring.add_coord(0, 1); - ring.add_coord(0, 0); - poly.set_exterior_ring(std::move(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)); mapnik::geometry::point centroid; REQUIRE(mapnik::geometry::centroid(poly, centroid)); @@ -68,7 +67,7 @@ SECTION("polygon with empty exterior ring") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - poly.set_exterior_ring(std::move(ring)); + poly.push_back(std::move(ring)); mapnik::geometry::point centroid; REQUIRE(!mapnik::geometry::centroid(poly, centroid)); @@ -77,6 +76,7 @@ SECTION("polygon with empty exterior ring") { SECTION("empty polygon") { mapnik::geometry::polygon poly; + poly.emplace_back(); mapnik::geometry::point centroid; REQUIRE(!mapnik::geometry::centroid(poly, centroid)); } @@ -84,9 +84,9 @@ SECTION("empty polygon") { SECTION("multi-point") { mapnik::geometry::multi_point geom; - geom.add_coord(0, 0); - geom.add_coord(25, 25); - geom.add_coord(50, 50); + geom.emplace_back(0, 0); + geom.emplace_back(25, 25); + geom.emplace_back(50, 50); mapnik::geometry::point centroid; REQUIRE(mapnik::geometry::centroid(geom, centroid)); REQUIRE(centroid.x == 25); @@ -105,16 +105,16 @@ SECTION("multi-linestring") { mapnik::geometry::multi_line_string geom; { mapnik::geometry::line_string line; - line.add_coord(0, 0); - line.add_coord(0, 25); - line.add_coord(0, 50); + line.emplace_back(0, 0); + line.emplace_back(0, 25); + line.emplace_back(0, 50); geom.emplace_back(std::move(line)); } { mapnik::geometry::line_string line; - line.add_coord(0, 0); - line.add_coord(25, 0); - line.add_coord(50, 0); + line.emplace_back(0, 0); + line.emplace_back(25, 0); + line.emplace_back(50, 0); geom.emplace_back(std::move(line)); } mapnik::geometry::point centroid; @@ -127,9 +127,9 @@ SECTION("multi-linestring: one component empty") { mapnik::geometry::multi_line_string geom; mapnik::geometry::line_string line; - line.add_coord(0, 0); - line.add_coord(0, 25); - line.add_coord(0, 50); + line.emplace_back(0, 0); + line.emplace_back(0, 25); + line.emplace_back(0, 50); geom.emplace_back(std::move(line)); geom.emplace_back(); mapnik::geometry::point centroid; @@ -151,23 +151,23 @@ SECTION("multi-polygon") { { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0, 0); - ring.add_coord(1, 0); - ring.add_coord(1, 1); - ring.add_coord(0, 1); - ring.add_coord(0, 0); - poly.set_exterior_ring(std::move(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)); geom.emplace_back(std::move(poly)); } { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(1, 1); - ring.add_coord(2, 1); - ring.add_coord(2, 2); - ring.add_coord(1, 2); - ring.add_coord(1, 1); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(1, 1); + ring.emplace_back(2, 1); + ring.emplace_back(2, 2); + ring.emplace_back(1, 2); + ring.emplace_back(1, 1); + poly.push_back(std::move(ring)); geom.emplace_back(std::move(poly)); } @@ -179,22 +179,22 @@ SECTION("multi-polygon") { SECTION("multi-polygon: one component empty") { - mapnik::geometry::multi_polygon geom; - mapnik::geometry::polygon poly; - mapnik::geometry::linear_ring ring; - ring.add_coord(0, 0); - ring.add_coord(1, 0); - ring.add_coord(1, 1); - ring.add_coord(0, 1); - ring.add_coord(0, 0); - poly.set_exterior_ring(std::move(ring)); - geom.emplace_back(std::move(poly)); - geom.emplace_back(); - - mapnik::geometry::point centroid; - REQUIRE(mapnik::geometry::centroid(geom, centroid)); - REQUIRE(centroid.x == 0.5); - REQUIRE(centroid.y == 0.5); + mapnik::geometry::multi_polygon geom; + 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)); + geom.emplace_back(std::move(poly)); + geom.emplace_back(); + geom.back().emplace_back(); + mapnik::geometry::point centroid; + REQUIRE(mapnik::geometry::centroid(geom, centroid)); + REQUIRE(centroid.x == 0.5); + REQUIRE(centroid.y == 0.5); } SECTION("empty multi-polygon") { diff --git a/test/unit/geometry/geometry_envelope_test.cpp b/test/unit/geometry/geometry_envelope_test.cpp index 75049820a..10551d363 100644 --- a/test/unit/geometry/geometry_envelope_test.cpp +++ b/test/unit/geometry/geometry_envelope_test.cpp @@ -21,15 +21,15 @@ void envelope_test() } { // Test empty geom - geometry geom = mapnik::geometry::geometry_empty(); + geometry geom = mapnik::geometry::geometry_empty(); mapnik::box2d bbox = mapnik::geometry::envelope(geom); REQUIRE_FALSE( bbox.valid() ); } { line_string line; - line.add_coord(0,0); - line.add_coord(1,1); - line.add_coord(2,2); + line.emplace_back(0,0); + line.emplace_back(1,1); + line.emplace_back(2,2); geometry geom(line); mapnik::box2d bbox = mapnik::geometry::envelope(geom); REQUIRE( bbox.minx() == 0 ); @@ -39,13 +39,13 @@ void envelope_test() } { line_string line; - line.add_coord(0,0); - line.add_coord(1,1); - line.add_coord(2,2); + line.emplace_back(0,0); + line.emplace_back(1,1); + line.emplace_back(2,2); line_string line2; - line2.add_coord(0,0); - line2.add_coord(-1,-1); - line2.add_coord(-2,-2); + line2.emplace_back(0,0); + line2.emplace_back(-1,-1); + line2.emplace_back(-2,-2); multi_line_string multi_line; multi_line.emplace_back(std::move(line)); multi_line.emplace_back(std::move(line2)); @@ -59,12 +59,12 @@ void envelope_test() { polygon poly; linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(-10,0); - ring.add_coord(-10,10); - ring.add_coord(0,10); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(-10,0); + ring.emplace_back(-10,10); + ring.emplace_back(0,10); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); geometry geom(poly); mapnik::box2d bbox = mapnik::geometry::envelope(geom); REQUIRE( bbox.minx() == -10 ); @@ -102,19 +102,19 @@ void envelope_test() // polygon with hole polygon poly; linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(-10,0); - ring.add_coord(-10,10); - ring.add_coord(0,10); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(-10,0); + ring.emplace_back(-10,10); + ring.emplace_back(0,10); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); linear_ring hole; - hole.add_coord(-7,7); - hole.add_coord(-7,3); - hole.add_coord(-3,3); - hole.add_coord(-3,7); - hole.add_coord(-7,7); - poly.add_hole(std::move(hole)); + hole.emplace_back(-7,7); + hole.emplace_back(-7,3); + hole.emplace_back(-3,3); + hole.emplace_back(-3,7); + hole.emplace_back(-7,7); + poly.push_back(std::move(hole)); geometry geom(poly); mapnik::box2d bbox = mapnik::geometry::envelope(poly); REQUIRE( bbox.minx() == -10 ); @@ -124,12 +124,12 @@ void envelope_test() // add another hole inside the first hole // which should be considered a hit linear_ring fill; - fill.add_coord(-6,4); - fill.add_coord(-6,6); - fill.add_coord(-4,6); - fill.add_coord(-4,4); - fill.add_coord(-6,4); - poly.add_hole(std::move(fill)); + fill.emplace_back(-6,4); + fill.emplace_back(-6,6); + fill.emplace_back(-4,6); + fill.emplace_back(-4,4); + fill.emplace_back(-6,4); + poly.push_back(std::move(fill)); bbox = mapnik::geometry::envelope(poly); REQUIRE( bbox.minx() == -10 ); REQUIRE( bbox.miny() == 0 ); diff --git a/test/unit/geometry/geometry_equal.hpp b/test/unit/geometry/geometry_equal.hpp index 4ff80abab..97e0bf26a 100644 --- a/test/unit/geometry/geometry_equal.hpp +++ b/test/unit/geometry/geometry_equal.hpp @@ -106,7 +106,8 @@ struct geometry_equal_visitor REQUIRE(false); } - void operator() (geometry_empty const&, geometry_empty const&) const + template + void operator() (geometry_empty const&, geometry_empty const&) const { REQUIRE(true); } @@ -119,7 +120,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()) { @@ -136,25 +137,33 @@ struct geometry_equal_visitor template void operator() (polygon const& p1, polygon const& p2) const { - (*this)(static_cast const&>(p1.exterior_ring), static_cast const&>(p2.exterior_ring)); - - if (p1.interior_rings.size() != p2.interior_rings.size()) + if (p1.size() != p2.size()) { REQUIRE(false); } - for (auto const& p : zip_crange(p1.interior_rings, p2.interior_rings)) + for (auto const& p : zip_crange(p1, p2)) { - (*this)(static_cast const&>(p.template get<0>()),static_cast const&>(p.template get<1>())); + (*this)(static_cast> const&>(p.template get<0>()), + static_cast> const&>(p.template get<1>())); } } + 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 { diff --git a/test/unit/geometry/geometry_hit_test.cpp b/test/unit/geometry/geometry_hit_test.cpp index 3b21407f6..afc7dfa9c 100644 --- a/test/unit/geometry/geometry_hit_test.cpp +++ b/test/unit/geometry/geometry_hit_test.cpp @@ -1,4 +1,3 @@ - #include "catch.hpp" #include @@ -27,17 +26,17 @@ SECTION("hit_test_filter - double") { } { line_string line; - line.add_coord(0,0); - line.add_coord(1,1); - line.add_coord(2,2); + line.emplace_back(0,0); + line.emplace_back(1,1); + line.emplace_back(2,2); geometry geom(line); REQUIRE( mapnik::hit_test(geom,0,0,1.5) ); } { line_string line; - line.add_coord(0,0); - line.add_coord(1,1); - line.add_coord(2,2); + line.emplace_back(0,0); + line.emplace_back(1,1); + line.emplace_back(2,2); multi_line_string multi_line; multi_line.emplace_back(std::move(line)); geometry geom(multi_line); @@ -46,12 +45,12 @@ SECTION("hit_test_filter - double") { { polygon poly; linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(-10,0); - ring.add_coord(-10,10); - ring.add_coord(0,10); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(-10,0); + ring.emplace_back(-10,10); + ring.emplace_back(0,10); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); geometry geom(poly); REQUIRE( mapnik::hit_test(geom,-5,5,0) ); @@ -78,30 +77,30 @@ SECTION("hit_test_filter - double") { // polygon with hole polygon poly; linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(-10,0); - ring.add_coord(-10,10); - ring.add_coord(0,10); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(-10,0); + ring.emplace_back(-10,10); + ring.emplace_back(0,10); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); linear_ring hole; - hole.add_coord(-7,7); - hole.add_coord(-7,3); - hole.add_coord(-3,3); - hole.add_coord(-3,7); - hole.add_coord(-7,7); - poly.add_hole(std::move(hole)); + hole.emplace_back(-7,7); + hole.emplace_back(-7,3); + hole.emplace_back(-3,3); + hole.emplace_back(-3,7); + hole.emplace_back(-7,7); + poly.push_back(std::move(hole)); geometry geom(poly); REQUIRE( !mapnik::hit_test(geom,-5,5,0) ); // add another hole inside the first hole // which should be considered a hit linear_ring fill; - fill.add_coord(-6,4); - fill.add_coord(-6,6); - fill.add_coord(-4,6); - fill.add_coord(-4,4); - fill.add_coord(-6,4); - poly.add_hole(std::move(fill)); + fill.emplace_back(-6,4); + fill.emplace_back(-6,6); + fill.emplace_back(-4,6); + fill.emplace_back(-4,4); + fill.emplace_back(-6,4); + poly.push_back(std::move(fill)); REQUIRE( mapnik::hit_test(geometry(poly),-5,5,0) ); } } diff --git a/test/unit/geometry/geometry_is_simple.cpp b/test/unit/geometry/geometry_is_simple.cpp index 55480585c..936c3caae 100644 --- a/test/unit/geometry/geometry_is_simple.cpp +++ b/test/unit/geometry/geometry_is_simple.cpp @@ -1,4 +1,3 @@ - #include "catch.hpp" #include @@ -11,7 +10,7 @@ TEST_CASE("geometry is_simple") { #if BOOST_VERSION >= 105800 SECTION("point") { - mapnik::geometry::geometry_empty empty; + mapnik::geometry::geometry_empty empty; CHECK( mapnik::geometry::is_simple(empty) ); } @@ -53,8 +52,8 @@ SECTION("point Infinity") { SECTION("multi point") { mapnik::geometry::multi_point mpt; - mpt.add_coord(0,0); - mpt.add_coord(1,1); + mpt.emplace_back(0,0); + mpt.emplace_back(1,1); CHECK( mapnik::geometry::is_simple(mpt) ); } @@ -65,18 +64,18 @@ SECTION("multi point empty") { SECTION("line_string") { mapnik::geometry::line_string line; - line.add_coord(0,0); - line.add_coord(1,1); + line.emplace_back(0,0); + line.emplace_back(1,1); CHECK( mapnik::geometry::is_simple(line) ); } // This fails while is_valid will not fail! SECTION("line_string repeated points") { mapnik::geometry::line_string line; - line.add_coord(0,0); - line.add_coord(1,1); - line.add_coord(1,1); - line.add_coord(2,2); + line.emplace_back(0,0); + line.emplace_back(1,1); + line.emplace_back(1,1); + line.emplace_back(2,2); CHECK( !mapnik::geometry::is_simple(line) ); } @@ -87,11 +86,11 @@ SECTION("line_string empty") { SECTION("multi_line_string") { mapnik::geometry::line_string line1; - line1.add_coord(0,0); - line1.add_coord(1,1); + line1.emplace_back(0,0); + line1.emplace_back(1,1); mapnik::geometry::line_string line2; - line2.add_coord(0,1); - line2.add_coord(1,2); + line2.emplace_back(0,1); + line2.emplace_back(1,2); mapnik::geometry::multi_line_string lines; lines.emplace_back(line1); lines.emplace_back(line2); @@ -113,24 +112,24 @@ SECTION("multi_line_string empty") { SECTION("polygon") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(1,0); - ring.add_coord(1,1); - ring.add_coord(0,1); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(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)); CHECK( mapnik::geometry::is_simple(poly) ); } SECTION("polygon invalid winding order") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(0,1); - ring.add_coord(1,1); - ring.add_coord(1,0); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(0,1); + ring.emplace_back(1,1); + ring.emplace_back(1,0); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); CHECK( mapnik::geometry::is_simple(poly) ); } @@ -139,13 +138,13 @@ SECTION("polygon invalid winding order") { SECTION("polygon 2 repeated points") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(1,0); - ring.add_coord(1,1); - ring.add_coord(1,1); - ring.add_coord(0,1); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(1,0); + ring.emplace_back(1,1); + ring.emplace_back(1,1); + ring.emplace_back(0,1); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); CHECK( !mapnik::geometry::is_simple(poly) ); } // repeated points are not considered invalid in a polygon @@ -153,14 +152,14 @@ SECTION("polygon 2 repeated points") { SECTION("polygon 3 repeated points") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(1,0); - ring.add_coord(1,1); - ring.add_coord(1,1); - ring.add_coord(1,1); - ring.add_coord(0,1); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(1,0); + ring.emplace_back(1,1); + ring.emplace_back(1,1); + ring.emplace_back(1,1); + ring.emplace_back(0,1); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); CHECK( !mapnik::geometry::is_simple(poly) ); } @@ -168,27 +167,28 @@ SECTION("polygon 3 repeated points") { SECTION("polygon that is empty") { mapnik::geometry::polygon poly; + poly.emplace_back(); CHECK( !mapnik::geometry::is_simple(poly) ); } SECTION("polygon that has empty exterior ring") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - poly.set_exterior_ring(std::move(ring)); + poly.push_back(std::move(ring)); CHECK( !mapnik::geometry::is_simple(poly) ); } SECTION("polygon that has empty interior ring") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(1,0); - ring.add_coord(1,1); - ring.add_coord(0,1); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(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)); mapnik::geometry::linear_ring ring2; - poly.add_hole(std::move(ring2)); + poly.push_back(std::move(ring2)); CHECK( !mapnik::geometry::is_simple(poly) ); } @@ -202,21 +202,21 @@ SECTION("polygon that is empty") { SECTION("polygon that has empty exterior ring") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - poly.set_exterior_ring(std::move(ring)); + poly.push_back(std::move(ring)); CHECK( mapnik::geometry::is_simple(poly) ); } SECTION("polygon that has empty interior ring") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(1,0); - ring.add_coord(1,1); - ring.add_coord(0,1); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(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)); mapnik::geometry::linear_ring ring2; - poly.add_hole(std::move(ring2)); + poly.push_back(std::move(ring2)); CHECK( mapnik::geometry::is_simple(poly) ); } @@ -226,33 +226,33 @@ SECTION("polygon that has empty interior ring") { SECTION("polygon with spike") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(1,0); - ring.add_coord(1,1); - ring.add_coord(2,2); - ring.add_coord(1,1); - ring.add_coord(0,1); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(1,0); + ring.emplace_back(1,1); + ring.emplace_back(2,2); + ring.emplace_back(1,1); + ring.emplace_back(0,1); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); CHECK( mapnik::geometry::is_simple(poly) ); } SECTION("polygon with hole") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(3,0); - ring.add_coord(3,3); - ring.add_coord(0,3); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(3,0); + ring.emplace_back(3,3); + ring.emplace_back(0,3); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); mapnik::geometry::linear_ring hole; - hole.add_coord(1,1); - hole.add_coord(1,2); - hole.add_coord(2,2); - hole.add_coord(2,1); - hole.add_coord(1,1); - poly.add_hole(std::move(hole)); + hole.emplace_back(1,1); + hole.emplace_back(1,2); + hole.emplace_back(2,2); + hole.emplace_back(2,1); + hole.emplace_back(1,1); + poly.push_back(std::move(hole)); CHECK( mapnik::geometry::is_simple(poly) ); } @@ -260,19 +260,19 @@ SECTION("polygon with hole") { SECTION("polygon with hole with invalid winding order") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(3,0); - ring.add_coord(3,3); - ring.add_coord(0,3); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(3,0); + ring.emplace_back(3,3); + ring.emplace_back(0,3); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); mapnik::geometry::linear_ring hole; - hole.add_coord(1,1); - hole.add_coord(2,1); - hole.add_coord(2,2); - hole.add_coord(1,2); - hole.add_coord(1,1); - poly.add_hole(std::move(hole)); + hole.emplace_back(1,1); + hole.emplace_back(2,1); + hole.emplace_back(2,2); + hole.emplace_back(1,2); + hole.emplace_back(1,1); + poly.push_back(std::move(hole)); CHECK( mapnik::geometry::is_simple(poly) ); } @@ -280,20 +280,20 @@ SECTION("multi polygon") { mapnik::geometry::multi_polygon mp; mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(1,0); - ring.add_coord(1,1); - ring.add_coord(0,1); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(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)); mapnik::geometry::polygon poly2; mapnik::geometry::linear_ring ring2; - ring2.add_coord(0,0); - ring2.add_coord(-1,0); - ring2.add_coord(-1,-1); - ring2.add_coord(0,-1); - ring2.add_coord(0,0); - poly2.set_exterior_ring(std::move(ring2)); + ring2.emplace_back(0,0); + ring2.emplace_back(-1,0); + ring2.emplace_back(-1,-1); + ring2.emplace_back(0,-1); + ring2.emplace_back(0,0); + poly2.push_back(std::move(ring2)); mp.emplace_back(poly); mp.emplace_back(poly2); CHECK( mapnik::geometry::is_simple(mp) ); @@ -303,34 +303,34 @@ SECTION("multi polygon with hole") { mapnik::geometry::multi_polygon mp; mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(3,0); - ring.add_coord(3,3); - ring.add_coord(0,3); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(3,0); + ring.emplace_back(3,3); + ring.emplace_back(0,3); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); mapnik::geometry::linear_ring hole; - hole.add_coord(1,1); - hole.add_coord(1,2); - hole.add_coord(2,2); - hole.add_coord(2,1); - hole.add_coord(1,1); - poly.add_hole(std::move(hole)); + hole.emplace_back(1,1); + hole.emplace_back(1,2); + hole.emplace_back(2,2); + hole.emplace_back(2,1); + hole.emplace_back(1,1); + poly.push_back(std::move(hole)); mapnik::geometry::polygon poly2; mapnik::geometry::linear_ring ring2; - ring2.add_coord(0,0); - ring2.add_coord(-3,0); - ring2.add_coord(-3,-3); - ring2.add_coord(0,-3); - ring2.add_coord(0,0); - poly2.set_exterior_ring(std::move(ring2)); + ring2.emplace_back(0,0); + ring2.emplace_back(-3,0); + ring2.emplace_back(-3,-3); + ring2.emplace_back(0,-3); + ring2.emplace_back(0,0); + poly2.push_back(std::move(ring2)); mapnik::geometry::linear_ring hole2; - hole2.add_coord(-1,-1); - hole2.add_coord(-1,-2); - hole2.add_coord(-2,-2); - hole2.add_coord(-2,-1); - hole2.add_coord(-1,-1); - poly2.add_hole(std::move(hole2)); + hole2.emplace_back(-1,-1); + hole2.emplace_back(-1,-2); + hole2.emplace_back(-2,-2); + hole2.emplace_back(-2,-1); + hole2.emplace_back(-1,-1); + poly2.push_back(std::move(hole2)); mp.emplace_back(poly); mp.emplace_back(poly2); CHECK( mapnik::geometry::is_simple(mp) ); diff --git a/test/unit/geometry/geometry_is_valid.cpp b/test/unit/geometry/geometry_is_valid.cpp index de1ee4c04..f8227b050 100644 --- a/test/unit/geometry/geometry_is_valid.cpp +++ b/test/unit/geometry/geometry_is_valid.cpp @@ -1,4 +1,3 @@ - #include "catch.hpp" #include @@ -11,7 +10,7 @@ TEST_CASE("geometry is_valid") { SECTION("empty geometry") { - mapnik::geometry::geometry_empty empty; + mapnik::geometry::geometry_empty empty; CHECK( mapnik::geometry::is_valid(empty) ); std::string message; CHECK( mapnik::geometry::is_valid(empty, message) ); @@ -124,8 +123,8 @@ SECTION("point Infinity") { SECTION("multi point") { mapnik::geometry::multi_point mpt; - mpt.add_coord(0,0); - mpt.add_coord(1,1); + mpt.emplace_back(0,0); + mpt.emplace_back(1,1); CHECK( mapnik::geometry::is_valid(mpt) ); std::string message; CHECK( mapnik::geometry::is_valid(mpt, message) ); @@ -149,8 +148,8 @@ SECTION("multi point empty") { SECTION("line_string") { mapnik::geometry::line_string line; - line.add_coord(0,0); - line.add_coord(1,1); + line.emplace_back(0,0); + line.emplace_back(1,1); CHECK( mapnik::geometry::is_valid(line) ); std::string message; CHECK( mapnik::geometry::is_valid(line, message) ); @@ -163,10 +162,10 @@ SECTION("line_string") { // This shouldn't fail -- test added in case logic ever changes SECTION("line_string repeated points") { mapnik::geometry::line_string line; - line.add_coord(0,0); - line.add_coord(1,1); - line.add_coord(1,1); - line.add_coord(2,2); + line.emplace_back(0,0); + line.emplace_back(1,1); + line.emplace_back(1,1); + line.emplace_back(2,2); CHECK( mapnik::geometry::is_valid(line) ); std::string message; CHECK( mapnik::geometry::is_valid(line, message) ); @@ -189,11 +188,11 @@ SECTION("line_string empty") { SECTION("multi_line_string") { mapnik::geometry::line_string line1; - line1.add_coord(0,0); - line1.add_coord(1,1); + line1.emplace_back(0,0); + line1.emplace_back(1,1); mapnik::geometry::line_string line2; - line2.add_coord(0,1); - line2.add_coord(1,2); + line2.emplace_back(0,1); + line2.emplace_back(1,2); mapnik::geometry::multi_line_string lines; lines.emplace_back(line1); lines.emplace_back(line2); @@ -220,12 +219,12 @@ SECTION("multi_line_string empty") { SECTION("polygon") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(1,0); - ring.add_coord(1,1); - ring.add_coord(0,1); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(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)); CHECK( mapnik::geometry::is_valid(poly) ); std::string message; CHECK( mapnik::geometry::is_valid(poly, message) ); @@ -238,12 +237,12 @@ SECTION("polygon") { SECTION("polygon invalid winding order") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(0,1); - ring.add_coord(1,1); - ring.add_coord(1,0); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(0,1); + ring.emplace_back(1,1); + ring.emplace_back(1,0); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); CHECK( !mapnik::geometry::is_valid(poly) ); std::string message; CHECK( !mapnik::geometry::is_valid(poly, message) ); @@ -257,13 +256,13 @@ SECTION("polygon invalid winding order") { SECTION("polygon 2 repeated points") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(1,0); - ring.add_coord(1,1); - ring.add_coord(1,1); - ring.add_coord(0,1); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(1,0); + ring.emplace_back(1,1); + ring.emplace_back(1,1); + ring.emplace_back(0,1); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); CHECK( mapnik::geometry::is_valid(poly) ); std::string message; CHECK( mapnik::geometry::is_valid(poly, message) ); @@ -276,14 +275,14 @@ SECTION("polygon 2 repeated points") { SECTION("polygon 3 repeated points") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(1,0); - ring.add_coord(1,1); - ring.add_coord(1,1); - ring.add_coord(1,1); - ring.add_coord(0,1); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(1,0); + ring.emplace_back(1,1); + ring.emplace_back(1,1); + ring.emplace_back(1,1); + ring.emplace_back(0,1); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); CHECK( mapnik::geometry::is_valid(poly) ); std::string message; CHECK( mapnik::geometry::is_valid(poly, message) ); @@ -295,6 +294,7 @@ SECTION("polygon 3 repeated points") { SECTION("polygon that is empty") { mapnik::geometry::polygon poly; + poly.emplace_back(); CHECK( !mapnik::geometry::is_valid(poly) ); std::string message; CHECK( !mapnik::geometry::is_valid(poly, message) ); @@ -307,14 +307,14 @@ SECTION("polygon that is empty") { SECTION("polygon with spike") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(1,0); - ring.add_coord(1,1); - ring.add_coord(2,2); - ring.add_coord(1,1); - ring.add_coord(0,1); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(1,0); + ring.emplace_back(1,1); + ring.emplace_back(2,2); + ring.emplace_back(1,1); + ring.emplace_back(0,1); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); CHECK( !mapnik::geometry::is_valid(poly) ); std::string message; CHECK( !mapnik::geometry::is_valid(poly, message) ); @@ -327,19 +327,19 @@ SECTION("polygon with spike") { SECTION("polygon with hole") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(3,0); - ring.add_coord(3,3); - ring.add_coord(0,3); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(3,0); + ring.emplace_back(3,3); + ring.emplace_back(0,3); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); mapnik::geometry::linear_ring hole; - hole.add_coord(1,1); - hole.add_coord(1,2); - hole.add_coord(2,2); - hole.add_coord(2,1); - hole.add_coord(1,1); - poly.add_hole(std::move(hole)); + hole.emplace_back(1,1); + hole.emplace_back(1,2); + hole.emplace_back(2,2); + hole.emplace_back(2,1); + hole.emplace_back(1,1); + poly.push_back(std::move(hole)); CHECK( mapnik::geometry::is_valid(poly) ); std::string message; CHECK( mapnik::geometry::is_valid(poly, message) ); @@ -352,14 +352,14 @@ SECTION("polygon with hole") { SECTION("polygon with empty hole") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(3,0); - ring.add_coord(3,3); - ring.add_coord(0,3); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(3,0); + ring.emplace_back(3,3); + ring.emplace_back(0,3); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); mapnik::geometry::linear_ring hole; - poly.add_hole(std::move(hole)); + poly.push_back(std::move(hole)); CHECK( !mapnik::geometry::is_valid(poly) ); std::string message; CHECK( !mapnik::geometry::is_valid(poly, message) ); @@ -373,19 +373,19 @@ SECTION("polygon with empty hole") { SECTION("polygon with hole with invalid winding order") { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(3,0); - ring.add_coord(3,3); - ring.add_coord(0,3); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(3,0); + ring.emplace_back(3,3); + ring.emplace_back(0,3); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); mapnik::geometry::linear_ring hole; - hole.add_coord(1,1); - hole.add_coord(2,1); - hole.add_coord(2,2); - hole.add_coord(1,2); - hole.add_coord(1,1); - poly.add_hole(std::move(hole)); + hole.emplace_back(1,1); + hole.emplace_back(2,1); + hole.emplace_back(2,2); + hole.emplace_back(1,2); + hole.emplace_back(1,1); + poly.push_back(std::move(hole)); CHECK( !mapnik::geometry::is_valid(poly) ); std::string message; CHECK( !mapnik::geometry::is_valid(poly, message) ); @@ -399,20 +399,20 @@ SECTION("multi polygon") { mapnik::geometry::multi_polygon mp; mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(1,0); - ring.add_coord(1,1); - ring.add_coord(0,1); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(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)); mapnik::geometry::polygon poly2; mapnik::geometry::linear_ring ring2; - ring2.add_coord(0,0); - ring2.add_coord(-1,0); - ring2.add_coord(-1,-1); - ring2.add_coord(0,-1); - ring2.add_coord(0,0); - poly2.set_exterior_ring(std::move(ring2)); + ring2.emplace_back(0,0); + ring2.emplace_back(-1,0); + ring2.emplace_back(-1,-1); + ring2.emplace_back(0,-1); + ring2.emplace_back(0,0); + poly2.push_back(std::move(ring2)); mp.emplace_back(poly); mp.emplace_back(poly2); CHECK( mapnik::geometry::is_valid(mp) ); @@ -428,34 +428,34 @@ SECTION("multi polygon with hole") { mapnik::geometry::multi_polygon mp; mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0,0); - ring.add_coord(3,0); - ring.add_coord(3,3); - ring.add_coord(0,3); - ring.add_coord(0,0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0,0); + ring.emplace_back(3,0); + ring.emplace_back(3,3); + ring.emplace_back(0,3); + ring.emplace_back(0,0); + poly.push_back(std::move(ring)); mapnik::geometry::linear_ring hole; - hole.add_coord(1,1); - hole.add_coord(1,2); - hole.add_coord(2,2); - hole.add_coord(2,1); - hole.add_coord(1,1); - poly.add_hole(std::move(hole)); + hole.emplace_back(1,1); + hole.emplace_back(1,2); + hole.emplace_back(2,2); + hole.emplace_back(2,1); + hole.emplace_back(1,1); + poly.push_back(std::move(hole)); mapnik::geometry::polygon poly2; mapnik::geometry::linear_ring ring2; - ring2.add_coord(0,0); - ring2.add_coord(-3,0); - ring2.add_coord(-3,-3); - ring2.add_coord(0,-3); - ring2.add_coord(0,0); - poly2.set_exterior_ring(std::move(ring2)); + ring2.emplace_back(0,0); + ring2.emplace_back(-3,0); + ring2.emplace_back(-3,-3); + ring2.emplace_back(0,-3); + ring2.emplace_back(0,0); + poly2.push_back(std::move(ring2)); mapnik::geometry::linear_ring hole2; - hole2.add_coord(-1,-1); - hole2.add_coord(-1,-2); - hole2.add_coord(-2,-2); - hole2.add_coord(-2,-1); - hole2.add_coord(-1,-1); - poly2.add_hole(std::move(hole2)); + hole2.emplace_back(-1,-1); + hole2.emplace_back(-1,-2); + hole2.emplace_back(-2,-2); + hole2.emplace_back(-2,-1); + hole2.emplace_back(-1,-1); + poly2.push_back(std::move(hole2)); mp.emplace_back(poly); mp.emplace_back(poly2); CHECK( mapnik::geometry::is_valid(mp) ); diff --git a/test/unit/geometry/geometry_reprojection.cpp b/test/unit/geometry/geometry_reprojection.cpp index c8ec36243..95bfdb099 100644 --- a/test/unit/geometry/geometry_reprojection.cpp +++ b/test/unit/geometry/geometry_reprojection.cpp @@ -1,4 +1,3 @@ - #include "catch.hpp" #include "geometry_equal.hpp" @@ -16,10 +15,10 @@ SECTION("test_projection_4326_3857 - Empty Geometry Object") { mapnik::projection dest("+init=epsg:3857"); mapnik::proj_transform proj_trans(source, dest); { - geometry_empty geom; + geometry_empty geom; unsigned int err = 0; // Test Standard Transform - geometry_empty new_geom = reproject_copy(geom, proj_trans, err); + geometry_empty new_geom = reproject_copy(geom, proj_trans, err); REQUIRE(err == 0); // Transform providing projections not transfrom new_geom = reproject_copy(geom, source, dest, err); @@ -42,20 +41,20 @@ SECTION("test_projection_4326_3857 - Empty Geometry in Geometry Variant") { mapnik::projection dest("+init=epsg:3857"); mapnik::proj_transform proj_trans(source, dest); { - geometry geom = geometry_empty(); + geometry geom = geometry_empty(); unsigned int err = 0; // Test Standard Transform geometry new_geom = reproject_copy(geom, proj_trans, err); REQUIRE(err == 0); - REQUIRE(new_geom.is()); + REQUIRE(new_geom.is>()); // Transform providing projections not transfrom new_geom = reproject_copy(geom, source, dest, err); REQUIRE(err == 0); - REQUIRE(new_geom.is()); + REQUIRE(new_geom.is>()); // Transform providing projections in reverse new_geom = reproject_copy(geom, dest, source, err); REQUIRE(err == 0); - REQUIRE(new_geom.is()); + REQUIRE(new_geom.is>()); // Transform in place REQUIRE(reproject(new_geom, proj_trans)); // Transform in place providing projections @@ -269,7 +268,7 @@ SECTION("test_projection_4326_3857 - Line_String Geometry Variant Object") { // Reprojecting empty line string will return a geometry_empty geometry new_geom = reproject_copy(geom0, proj_trans1, err); REQUIRE(err == 0); - REQUIRE(new_geom.is()); + REQUIRE(new_geom.is>()); } { // Test Standard Transform @@ -322,43 +321,49 @@ SECTION("test_projection_4326_3857 - Polygon Geometry Object") { mapnik::proj_transform proj_trans1(source, dest); mapnik::proj_transform proj_trans2(dest, source); polygon geom1; - geom1.exterior_ring.emplace_back(point(-97.62588500976562, 35.62939577711732)); - geom1.exterior_ring.emplace_back(point(-97.79067993164062, 35.43941441533686)); - geom1.exterior_ring.emplace_back(point(-97.60391235351562, 35.34425514918409)); - geom1.exterior_ring.emplace_back(point(-97.42813110351562, 35.48191987272801)); - geom1.exterior_ring.emplace_back(point(-97.62588500976562, 35.62939577711732)); - geom1.interior_rings.emplace_back(); - geom1.interior_rings.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); - geom1.interior_rings.back().emplace_back(point(-97.61489868164062, 35.54116627999813)); - geom1.interior_rings.back().emplace_back(point(-97.53799438476562, 35.459551379037606)); - geom1.interior_rings.back().emplace_back(point(-97.62451171875, 35.42598697382711)); - geom1.interior_rings.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); + // exterior + geom1.emplace_back(); + geom1.back().emplace_back(point(-97.62588500976562, 35.62939577711732)); + geom1.back().emplace_back(point(-97.79067993164062, 35.43941441533686)); + geom1.back().emplace_back(point(-97.60391235351562, 35.34425514918409)); + geom1.back().emplace_back(point(-97.42813110351562, 35.48191987272801)); + geom1.back().emplace_back(point(-97.62588500976562, 35.62939577711732)); + // interior + geom1.emplace_back(); + geom1.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); + geom1.back().emplace_back(point(-97.61489868164062, 35.54116627999813)); + geom1.back().emplace_back(point(-97.53799438476562, 35.459551379037606)); + geom1.back().emplace_back(point(-97.62451171875, 35.42598697382711)); + geom1.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); polygon geom2; - geom2.exterior_ring.emplace_back(point(-10867663.807530, 4249745.898599)); - geom2.exterior_ring.emplace_back(point(-10886008.694318, 4223757.308982)); - geom2.exterior_ring.emplace_back(point(-10865217.822625, 4210763.014174)); - geom2.exterior_ring.emplace_back(point(-10845649.943384, 4229566.523132)); - geom2.exterior_ring.emplace_back(point(-10867663.807530, 4249745.898599)); - geom2.interior_rings.emplace_back(); - geom2.interior_rings.back().emplace_back(point(-10872097.155170, 4227732.034453)); - geom2.interior_rings.back().emplace_back(point(-10866440.815077, 4237668.848130)); - geom2.interior_rings.back().emplace_back(point(-10857879.867909, 4226509.042001)); - geom2.interior_rings.back().emplace_back(point(-10867510.933473, 4221922.820303)); - geom2.interior_rings.back().emplace_back(point(-10872097.155170, 4227732.034453)); + // interior + geom2.emplace_back(); + geom2.back().emplace_back(point(-10867663.807530, 4249745.898599)); + geom2.back().emplace_back(point(-10886008.694318, 4223757.308982)); + geom2.back().emplace_back(point(-10865217.822625, 4210763.014174)); + geom2.back().emplace_back(point(-10845649.943384, 4229566.523132)); + geom2.back().emplace_back(point(-10867663.807530, 4249745.898599)); + // exterior + geom2.emplace_back(); + geom2.back().emplace_back(point(-10872097.155170, 4227732.034453)); + geom2.back().emplace_back(point(-10866440.815077, 4237668.848130)); + geom2.back().emplace_back(point(-10857879.867909, 4226509.042001)); + geom2.back().emplace_back(point(-10867510.933473, 4221922.820303)); + geom2.back().emplace_back(point(-10872097.155170, 4227732.034453)); unsigned int err = 0; { // Test Standard Transform // Add extra vector to outer ring. - geom1.interior_rings.emplace_back(); - REQUIRE(geom1.interior_rings.size() == 2); + geom1.emplace_back(); + REQUIRE(geom1.size() == 3); polygon new_geom = reproject_copy(geom1, proj_trans1, err); REQUIRE(err == 0); // Should remove the empty ring added to back of geom1 - REQUIRE(new_geom.interior_rings.size() == 1); + REQUIRE(new_geom.size() == 2); assert_g_equal(new_geom, geom2); // Remove extra ring for future validity tests. - geom1.interior_rings.pop_back(); - REQUIRE(geom1.interior_rings.size() == 1); + geom1.pop_back(); + REQUIRE(geom1.size() == 2); } { // Transform in reverse @@ -381,13 +386,13 @@ SECTION("test_projection_4326_3857 - Polygon Geometry Object") { { // Transform in place polygon geom3(geom1); - geom3.interior_rings.emplace_back(); + geom3.emplace_back(); REQUIRE(reproject(geom3, proj_trans1)); // Should NOT remove the empty ring added to back of geom1 - REQUIRE(geom3.interior_rings.size() == 2); + REQUIRE(geom3.size() == 3); // Remove so asserts that geometries are the same - geom3.interior_rings.pop_back(); - REQUIRE(geom3.interior_rings.size() == 1); + geom3.pop_back(); + REQUIRE(geom3.size() == 2); assert_g_equal(geom3, geom2); // Transform in place reverse REQUIRE(reproject(geom3, proj_trans2)); @@ -411,29 +416,36 @@ SECTION("test_projection_4326_3857 - Polygon Geometry Variant Object") { mapnik::proj_transform proj_trans1(source, dest); mapnik::proj_transform proj_trans2(dest, source); polygon geom1_; - geom1_.exterior_ring.emplace_back(point(-97.62588500976562, 35.62939577711732)); - geom1_.exterior_ring.emplace_back(point(-97.79067993164062, 35.43941441533686)); - geom1_.exterior_ring.emplace_back(point(-97.60391235351562, 35.34425514918409)); - geom1_.exterior_ring.emplace_back(point(-97.42813110351562, 35.48191987272801)); - geom1_.exterior_ring.emplace_back(point(-97.62588500976562, 35.62939577711732)); - geom1_.interior_rings.emplace_back(); - geom1_.interior_rings.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); - geom1_.interior_rings.back().emplace_back(point(-97.61489868164062, 35.54116627999813)); - geom1_.interior_rings.back().emplace_back(point(-97.53799438476562, 35.459551379037606)); - geom1_.interior_rings.back().emplace_back(point(-97.62451171875, 35.42598697382711)); - geom1_.interior_rings.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); + // exterior + geom1_.emplace_back(); + geom1_.back().emplace_back(point(-97.62588500976562, 35.62939577711732)); + geom1_.back().emplace_back(point(-97.79067993164062, 35.43941441533686)); + geom1_.back().emplace_back(point(-97.60391235351562, 35.34425514918409)); + geom1_.back().emplace_back(point(-97.42813110351562, 35.48191987272801)); + geom1_.back().emplace_back(point(-97.62588500976562, 35.62939577711732)); + // interior + geom1_.emplace_back(); + geom1_.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); + geom1_.back().emplace_back(point(-97.61489868164062, 35.54116627999813)); + geom1_.back().emplace_back(point(-97.53799438476562, 35.459551379037606)); + geom1_.back().emplace_back(point(-97.62451171875, 35.42598697382711)); + geom1_.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); + polygon geom2_; - geom2_.exterior_ring.emplace_back(point(-10867663.807530, 4249745.898599)); - geom2_.exterior_ring.emplace_back(point(-10886008.694318, 4223757.308982)); - geom2_.exterior_ring.emplace_back(point(-10865217.822625, 4210763.014174)); - geom2_.exterior_ring.emplace_back(point(-10845649.943384, 4229566.523132)); - geom2_.exterior_ring.emplace_back(point(-10867663.807530, 4249745.898599)); - geom2_.interior_rings.emplace_back(); - geom2_.interior_rings.back().emplace_back(point(-10872097.155170, 4227732.034453)); - geom2_.interior_rings.back().emplace_back(point(-10866440.815077, 4237668.848130)); - geom2_.interior_rings.back().emplace_back(point(-10857879.867909, 4226509.042001)); - geom2_.interior_rings.back().emplace_back(point(-10867510.933473, 4221922.820303)); - geom2_.interior_rings.back().emplace_back(point(-10872097.155170, 4227732.034453)); + // exterior + geom2_.emplace_back(); + geom2_.back().emplace_back(point(-10867663.807530, 4249745.898599)); + geom2_.back().emplace_back(point(-10886008.694318, 4223757.308982)); + geom2_.back().emplace_back(point(-10865217.822625, 4210763.014174)); + geom2_.back().emplace_back(point(-10845649.943384, 4229566.523132)); + geom2_.back().emplace_back(point(-10867663.807530, 4249745.898599)); + // interior + geom2_.emplace_back(); + geom2_.back().emplace_back(point(-10872097.155170, 4227732.034453)); + geom2_.back().emplace_back(point(-10866440.815077, 4237668.848130)); + geom2_.back().emplace_back(point(-10857879.867909, 4226509.042001)); + geom2_.back().emplace_back(point(-10867510.933473, 4221922.820303)); + geom2_.back().emplace_back(point(-10872097.155170, 4227732.034453)); polygon geom0_; geometry geom0(geom0_); geometry geom1(geom1_); @@ -443,7 +455,7 @@ SECTION("test_projection_4326_3857 - Polygon Geometry Variant Object") { // Reprojecting empty poly will return a geometry_empty geometry new_geom = reproject_copy(geom0, proj_trans1, err); REQUIRE(err == 0); - REQUIRE(new_geom.is()); + REQUIRE(new_geom.is>()); } { // Test Standard Transform @@ -583,7 +595,7 @@ SECTION("test_projection_4326_3857 - Multi_Point Geometry Variant Object") { // Reprojecting empty multi point will return a geometry_empty geometry new_geom = reproject_copy(geom0, proj_trans1, err); REQUIRE(err == 0); - REQUIRE(new_geom.is()); + REQUIRE(new_geom.is>()); } { // Test Standard Transform @@ -739,7 +751,7 @@ SECTION("test_projection_4326_3857 - Multi_Line_String Geometry Variant Object") // Reprojecting empty line string will return a geometry_empty geometry new_geom = reproject_copy(geom0, proj_trans1, err); REQUIRE(err == 0); - REQUIRE(new_geom.is()); + REQUIRE(new_geom.is>()); } { // Test Standard Transform @@ -792,31 +804,37 @@ SECTION("test_projection_4326_3857 - Multi_Polygon Geometry Object") { mapnik::proj_transform proj_trans1(source, dest); mapnik::proj_transform proj_trans2(dest, source); polygon geom1a; - geom1a.exterior_ring.emplace_back(point(-97.62588500976562, 35.62939577711732)); - geom1a.exterior_ring.emplace_back(point(-97.79067993164062, 35.43941441533686)); - geom1a.exterior_ring.emplace_back(point(-97.60391235351562, 35.34425514918409)); - geom1a.exterior_ring.emplace_back(point(-97.42813110351562, 35.48191987272801)); - geom1a.exterior_ring.emplace_back(point(-97.62588500976562, 35.62939577711732)); - geom1a.interior_rings.emplace_back(); - geom1a.interior_rings.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); - geom1a.interior_rings.back().emplace_back(point(-97.61489868164062, 35.54116627999813)); - geom1a.interior_rings.back().emplace_back(point(-97.53799438476562, 35.459551379037606)); - geom1a.interior_rings.back().emplace_back(point(-97.62451171875, 35.42598697382711)); - geom1a.interior_rings.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); + // exterior + geom1a.emplace_back(); + geom1a.back().emplace_back(point(-97.62588500976562, 35.62939577711732)); + geom1a.back().emplace_back(point(-97.79067993164062, 35.43941441533686)); + geom1a.back().emplace_back(point(-97.60391235351562, 35.34425514918409)); + geom1a.back().emplace_back(point(-97.42813110351562, 35.48191987272801)); + geom1a.back().emplace_back(point(-97.62588500976562, 35.62939577711732)); + // interior + geom1a.emplace_back(); + geom1a.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); + geom1a.back().emplace_back(point(-97.61489868164062, 35.54116627999813)); + geom1a.back().emplace_back(point(-97.53799438476562, 35.459551379037606)); + geom1a.back().emplace_back(point(-97.62451171875, 35.42598697382711)); + geom1a.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); multi_polygon geom1; geom1.emplace_back(geom1a); polygon geom2a; - geom2a.exterior_ring.emplace_back(point(-10867663.807530, 4249745.898599)); - geom2a.exterior_ring.emplace_back(point(-10886008.694318, 4223757.308982)); - geom2a.exterior_ring.emplace_back(point(-10865217.822625, 4210763.014174)); - geom2a.exterior_ring.emplace_back(point(-10845649.943384, 4229566.523132)); - geom2a.exterior_ring.emplace_back(point(-10867663.807530, 4249745.898599)); - geom2a.interior_rings.emplace_back(); - geom2a.interior_rings.back().emplace_back(point(-10872097.155170, 4227732.034453)); - geom2a.interior_rings.back().emplace_back(point(-10866440.815077, 4237668.848130)); - geom2a.interior_rings.back().emplace_back(point(-10857879.867909, 4226509.042001)); - geom2a.interior_rings.back().emplace_back(point(-10867510.933473, 4221922.820303)); - geom2a.interior_rings.back().emplace_back(point(-10872097.155170, 4227732.034453)); + // exterior + geom2a.emplace_back(); + geom2a.back().emplace_back(point(-10867663.807530, 4249745.898599)); + geom2a.back().emplace_back(point(-10886008.694318, 4223757.308982)); + geom2a.back().emplace_back(point(-10865217.822625, 4210763.014174)); + geom2a.back().emplace_back(point(-10845649.943384, 4229566.523132)); + geom2a.back().emplace_back(point(-10867663.807530, 4249745.898599)); + // interior + geom2a.emplace_back(); + geom2a.back().emplace_back(point(-10872097.155170, 4227732.034453)); + geom2a.back().emplace_back(point(-10866440.815077, 4237668.848130)); + geom2a.back().emplace_back(point(-10857879.867909, 4226509.042001)); + geom2a.back().emplace_back(point(-10867510.933473, 4221922.820303)); + geom2a.back().emplace_back(point(-10872097.155170, 4227732.034453)); multi_polygon geom2; geom2.emplace_back(geom2a); unsigned int err = 0; @@ -885,31 +903,37 @@ SECTION("test_projection_4326_3857 - Multi_Polygon Geometry Variant Object") { mapnik::proj_transform proj_trans1(source, dest); mapnik::proj_transform proj_trans2(dest, source); polygon geom1a_; - geom1a_.exterior_ring.emplace_back(point(-97.62588500976562, 35.62939577711732)); - geom1a_.exterior_ring.emplace_back(point(-97.79067993164062, 35.43941441533686)); - geom1a_.exterior_ring.emplace_back(point(-97.60391235351562, 35.34425514918409)); - geom1a_.exterior_ring.emplace_back(point(-97.42813110351562, 35.48191987272801)); - geom1a_.exterior_ring.emplace_back(point(-97.62588500976562, 35.62939577711732)); - geom1a_.interior_rings.emplace_back(); - geom1a_.interior_rings.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); - geom1a_.interior_rings.back().emplace_back(point(-97.61489868164062, 35.54116627999813)); - geom1a_.interior_rings.back().emplace_back(point(-97.53799438476562, 35.459551379037606)); - geom1a_.interior_rings.back().emplace_back(point(-97.62451171875, 35.42598697382711)); - geom1a_.interior_rings.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); + // exterior + geom1a_.emplace_back(); + geom1a_.back().emplace_back(point(-97.62588500976562, 35.62939577711732)); + geom1a_.back().emplace_back(point(-97.79067993164062, 35.43941441533686)); + geom1a_.back().emplace_back(point(-97.60391235351562, 35.34425514918409)); + geom1a_.back().emplace_back(point(-97.42813110351562, 35.48191987272801)); + geom1a_.back().emplace_back(point(-97.62588500976562, 35.62939577711732)); + // interior + geom1a_.emplace_back(); + geom1a_.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); + geom1a_.back().emplace_back(point(-97.61489868164062, 35.54116627999813)); + geom1a_.back().emplace_back(point(-97.53799438476562, 35.459551379037606)); + geom1a_.back().emplace_back(point(-97.62451171875, 35.42598697382711)); + geom1a_.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); multi_polygon geom1_; geom1_.emplace_back(geom1a_); polygon geom2a_; - geom2a_.exterior_ring.emplace_back(point(-10867663.807530, 4249745.898599)); - geom2a_.exterior_ring.emplace_back(point(-10886008.694318, 4223757.308982)); - geom2a_.exterior_ring.emplace_back(point(-10865217.822625, 4210763.014174)); - geom2a_.exterior_ring.emplace_back(point(-10845649.943384, 4229566.523132)); - geom2a_.exterior_ring.emplace_back(point(-10867663.807530, 4249745.898599)); - geom2a_.interior_rings.emplace_back(); - geom2a_.interior_rings.back().emplace_back(point(-10872097.155170, 4227732.034453)); - geom2a_.interior_rings.back().emplace_back(point(-10866440.815077, 4237668.848130)); - geom2a_.interior_rings.back().emplace_back(point(-10857879.867909, 4226509.042001)); - geom2a_.interior_rings.back().emplace_back(point(-10867510.933473, 4221922.820303)); - geom2a_.interior_rings.back().emplace_back(point(-10872097.155170, 4227732.034453)); + // exterior + geom2a_.emplace_back(); + geom2a_.back().emplace_back(point(-10867663.807530, 4249745.898599)); + geom2a_.back().emplace_back(point(-10886008.694318, 4223757.308982)); + geom2a_.back().emplace_back(point(-10865217.822625, 4210763.014174)); + geom2a_.back().emplace_back(point(-10845649.943384, 4229566.523132)); + geom2a_.back().emplace_back(point(-10867663.807530, 4249745.898599)); + // interior + geom2a_.emplace_back(); + geom2a_.back().emplace_back(point(-10872097.155170, 4227732.034453)); + geom2a_.back().emplace_back(point(-10866440.815077, 4237668.848130)); + geom2a_.back().emplace_back(point(-10857879.867909, 4226509.042001)); + geom2a_.back().emplace_back(point(-10867510.933473, 4221922.820303)); + geom2a_.back().emplace_back(point(-10872097.155170, 4227732.034453)); multi_polygon geom2_; geom2_.emplace_back(geom2a_); multi_polygon geom0_; @@ -921,7 +945,7 @@ SECTION("test_projection_4326_3857 - Multi_Polygon Geometry Variant Object") { // Reprojecting empty poly will return a geometry_empty geometry new_geom = reproject_copy(geom0, proj_trans1, err); REQUIRE(err == 0); - REQUIRE(new_geom.is()); + REQUIRE(new_geom.is>()); } { // Test Standard Transform @@ -974,31 +998,37 @@ SECTION("test_projection_4326_3857 - Geometry Collection Object") { mapnik::proj_transform proj_trans1(source, dest); mapnik::proj_transform proj_trans2(dest, source); polygon geom1a; - geom1a.exterior_ring.emplace_back(point(-97.62588500976562, 35.62939577711732)); - geom1a.exterior_ring.emplace_back(point(-97.79067993164062, 35.43941441533686)); - geom1a.exterior_ring.emplace_back(point(-97.60391235351562, 35.34425514918409)); - geom1a.exterior_ring.emplace_back(point(-97.42813110351562, 35.48191987272801)); - geom1a.exterior_ring.emplace_back(point(-97.62588500976562, 35.62939577711732)); - geom1a.interior_rings.emplace_back(); - geom1a.interior_rings.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); - geom1a.interior_rings.back().emplace_back(point(-97.61489868164062, 35.54116627999813)); - geom1a.interior_rings.back().emplace_back(point(-97.53799438476562, 35.459551379037606)); - geom1a.interior_rings.back().emplace_back(point(-97.62451171875, 35.42598697382711)); - geom1a.interior_rings.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); + // exterior + geom1a.emplace_back(); + geom1a.back().emplace_back(point(-97.62588500976562, 35.62939577711732)); + geom1a.back().emplace_back(point(-97.79067993164062, 35.43941441533686)); + geom1a.back().emplace_back(point(-97.60391235351562, 35.34425514918409)); + geom1a.back().emplace_back(point(-97.42813110351562, 35.48191987272801)); + geom1a.back().emplace_back(point(-97.62588500976562, 35.62939577711732)); + // interior + geom1a.emplace_back(); + geom1a.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); + geom1a.back().emplace_back(point(-97.61489868164062, 35.54116627999813)); + geom1a.back().emplace_back(point(-97.53799438476562, 35.459551379037606)); + geom1a.back().emplace_back(point(-97.62451171875, 35.42598697382711)); + geom1a.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); geometry_collection geom1; geom1.emplace_back(geometry(geom1a)); polygon geom2a; - geom2a.exterior_ring.emplace_back(point(-10867663.807530, 4249745.898599)); - geom2a.exterior_ring.emplace_back(point(-10886008.694318, 4223757.308982)); - geom2a.exterior_ring.emplace_back(point(-10865217.822625, 4210763.014174)); - geom2a.exterior_ring.emplace_back(point(-10845649.943384, 4229566.523132)); - geom2a.exterior_ring.emplace_back(point(-10867663.807530, 4249745.898599)); - geom2a.interior_rings.emplace_back(); - geom2a.interior_rings.back().emplace_back(point(-10872097.155170, 4227732.034453)); - geom2a.interior_rings.back().emplace_back(point(-10866440.815077, 4237668.848130)); - geom2a.interior_rings.back().emplace_back(point(-10857879.867909, 4226509.042001)); - geom2a.interior_rings.back().emplace_back(point(-10867510.933473, 4221922.820303)); - geom2a.interior_rings.back().emplace_back(point(-10872097.155170, 4227732.034453)); + // exerior + geom2a.emplace_back(); + geom2a.back().emplace_back(point(-10867663.807530, 4249745.898599)); + geom2a.back().emplace_back(point(-10886008.694318, 4223757.308982)); + geom2a.back().emplace_back(point(-10865217.822625, 4210763.014174)); + geom2a.back().emplace_back(point(-10845649.943384, 4229566.523132)); + geom2a.back().emplace_back(point(-10867663.807530, 4249745.898599)); + // interior + geom2a.emplace_back(); + geom2a.back().emplace_back(point(-10872097.155170, 4227732.034453)); + geom2a.back().emplace_back(point(-10866440.815077, 4237668.848130)); + geom2a.back().emplace_back(point(-10857879.867909, 4226509.042001)); + geom2a.back().emplace_back(point(-10867510.933473, 4221922.820303)); + geom2a.back().emplace_back(point(-10872097.155170, 4227732.034453)); geometry_collection geom2; geom2.emplace_back(geometry(geom2a)); unsigned int err = 0; @@ -1067,31 +1097,37 @@ SECTION("test_projection_4326_3857 - Geometry Collection Variant Object") { mapnik::proj_transform proj_trans1(source, dest); mapnik::proj_transform proj_trans2(dest, source); polygon geom1a_; - geom1a_.exterior_ring.emplace_back(point(-97.62588500976562, 35.62939577711732)); - geom1a_.exterior_ring.emplace_back(point(-97.79067993164062, 35.43941441533686)); - geom1a_.exterior_ring.emplace_back(point(-97.60391235351562, 35.34425514918409)); - geom1a_.exterior_ring.emplace_back(point(-97.42813110351562, 35.48191987272801)); - geom1a_.exterior_ring.emplace_back(point(-97.62588500976562, 35.62939577711732)); - geom1a_.interior_rings.emplace_back(); - geom1a_.interior_rings.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); - geom1a_.interior_rings.back().emplace_back(point(-97.61489868164062, 35.54116627999813)); - geom1a_.interior_rings.back().emplace_back(point(-97.53799438476562, 35.459551379037606)); - geom1a_.interior_rings.back().emplace_back(point(-97.62451171875, 35.42598697382711)); - geom1a_.interior_rings.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); + // exterior + geom1a_.emplace_back(); + geom1a_.back().emplace_back(point(-97.62588500976562, 35.62939577711732)); + geom1a_.back().emplace_back(point(-97.79067993164062, 35.43941441533686)); + geom1a_.back().emplace_back(point(-97.60391235351562, 35.34425514918409)); + geom1a_.back().emplace_back(point(-97.42813110351562, 35.48191987272801)); + geom1a_.back().emplace_back(point(-97.62588500976562, 35.62939577711732)); + // interior + geom1a_.emplace_back(); + geom1a_.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); + geom1a_.back().emplace_back(point(-97.61489868164062, 35.54116627999813)); + geom1a_.back().emplace_back(point(-97.53799438476562, 35.459551379037606)); + geom1a_.back().emplace_back(point(-97.62451171875, 35.42598697382711)); + geom1a_.back().emplace_back(point(-97.66571044921875, 35.46849952318069)); geometry_collection geom1_; geom1_.emplace_back(geometry(geom1a_)); polygon geom2a_; - geom2a_.exterior_ring.emplace_back(point(-10867663.807530, 4249745.898599)); - geom2a_.exterior_ring.emplace_back(point(-10886008.694318, 4223757.308982)); - geom2a_.exterior_ring.emplace_back(point(-10865217.822625, 4210763.014174)); - geom2a_.exterior_ring.emplace_back(point(-10845649.943384, 4229566.523132)); - geom2a_.exterior_ring.emplace_back(point(-10867663.807530, 4249745.898599)); - geom2a_.interior_rings.emplace_back(); - geom2a_.interior_rings.back().emplace_back(point(-10872097.155170, 4227732.034453)); - geom2a_.interior_rings.back().emplace_back(point(-10866440.815077, 4237668.848130)); - geom2a_.interior_rings.back().emplace_back(point(-10857879.867909, 4226509.042001)); - geom2a_.interior_rings.back().emplace_back(point(-10867510.933473, 4221922.820303)); - geom2a_.interior_rings.back().emplace_back(point(-10872097.155170, 4227732.034453)); + // exterior + geom2a_.emplace_back(); + geom2a_.back().emplace_back(point(-10867663.807530, 4249745.898599)); + geom2a_.back().emplace_back(point(-10886008.694318, 4223757.308982)); + geom2a_.back().emplace_back(point(-10865217.822625, 4210763.014174)); + geom2a_.back().emplace_back(point(-10845649.943384, 4229566.523132)); + geom2a_.back().emplace_back(point(-10867663.807530, 4249745.898599)); + // interior + geom2a_.emplace_back(); + geom2a_.back().emplace_back(point(-10872097.155170, 4227732.034453)); + geom2a_.back().emplace_back(point(-10866440.815077, 4237668.848130)); + geom2a_.back().emplace_back(point(-10857879.867909, 4226509.042001)); + geom2a_.back().emplace_back(point(-10867510.933473, 4221922.820303)); + geom2a_.back().emplace_back(point(-10872097.155170, 4227732.034453)); geometry_collection geom2_; geom2_.emplace_back(geometry(geom2a_)); multi_polygon geom0_; @@ -1103,7 +1139,7 @@ SECTION("test_projection_4326_3857 - Geometry Collection Variant Object") { // Reprojecting empty poly will return a geometry_empty geometry new_geom = reproject_copy(geom0, proj_trans1, err); REQUIRE(err == 0); - REQUIRE(new_geom.is()); + REQUIRE(new_geom.is>()); } { // Test Standard Transform diff --git a/test/unit/geometry/geometry_strategy_test.cpp b/test/unit/geometry/geometry_strategy_test.cpp index c08e828cb..cb20cb74a 100644 --- a/test/unit/geometry/geometry_strategy_test.cpp +++ b/test/unit/geometry/geometry_strategy_test.cpp @@ -1,4 +1,3 @@ - #include "catch.hpp" #include "geometry_equal.hpp" @@ -12,7 +11,6 @@ #include TEST_CASE("geometry strategy tests") { - SECTION("proj and view strategy") { using namespace mapnik::geometry; mapnik::box2d e(-20037508.342789,-20037508.342789,20037508.342789,20037508.342789); @@ -184,5 +182,4 @@ SECTION("scaling strategies - double to int64") { assert_g_equal(r, o); } } // END SECTION - } // END TEST CASE diff --git a/test/unit/geometry/has_empty.cpp b/test/unit/geometry/has_empty.cpp index b7fcab14e..ff2e40f23 100644 --- a/test/unit/geometry/has_empty.cpp +++ b/test/unit/geometry/has_empty.cpp @@ -1,4 +1,3 @@ - #include "catch.hpp" #include @@ -7,7 +6,7 @@ TEST_CASE("geometry has_empty") { SECTION("empty geometry") { - mapnik::geometry::geometry_empty geom; + mapnik::geometry::geometry_empty geom; REQUIRE(!mapnik::geometry::has_empty(geom)); } @@ -19,7 +18,7 @@ SECTION("geometry collection") { } { mapnik::geometry::geometry_collection geom; - mapnik::geometry::geometry_empty geom1; + mapnik::geometry::geometry_empty geom1; geom.emplace_back(std::move(geom1)); REQUIRE(mapnik::geometry::has_empty(geom)); } @@ -35,7 +34,7 @@ SECTION("geometry collection") { mapnik::geometry::geometry_collection geom; mapnik::geometry::multi_line_string mls; mapnik::geometry::line_string line; - line.add_coord(0, 0); + line.emplace_back(0, 0); mls.emplace_back(std::move(line)); geom.emplace_back(std::move(mls)); REQUIRE(!mapnik::geometry::has_empty(geom)); @@ -56,9 +55,9 @@ SECTION("linestring") { } { mapnik::geometry::line_string line; - line.add_coord(0, 0); - line.add_coord(25, 25); - line.add_coord(50, 50); + line.emplace_back(0, 0); + line.emplace_back(25, 25); + line.emplace_back(50, 50); REQUIRE(!mapnik::geometry::has_empty(line)); } } @@ -72,18 +71,18 @@ SECTION("polygon") { { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - poly.set_exterior_ring(std::move(ring)); + poly.push_back(std::move(ring)); REQUIRE(!mapnik::geometry::has_empty(poly)); } { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0, 0); - ring.add_coord(1, 0); - ring.add_coord(1, 1); - ring.add_coord(0, 1); - ring.add_coord(0, 0); - poly.set_exterior_ring(std::move(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)); } } @@ -96,9 +95,9 @@ SECTION("multi-point") { } { mapnik::geometry::multi_point geom; - geom.add_coord(0, 0); - geom.add_coord(25, 25); - geom.add_coord(50, 50); + geom.emplace_back(0, 0); + geom.emplace_back(25, 25); + geom.emplace_back(50, 50); REQUIRE(!mapnik::geometry::has_empty(geom)); } } @@ -118,7 +117,7 @@ SECTION("multi-linestring") { { mapnik::geometry::multi_line_string geom; mapnik::geometry::line_string line; - line.add_coord(0, 0); + line.emplace_back(0, 0); geom.emplace_back(std::move(line)); REQUIRE(!mapnik::geometry::has_empty(geom)); } @@ -134,7 +133,7 @@ SECTION("multi-polygon") { mapnik::geometry::multi_polygon geom; mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - poly.set_exterior_ring(std::move(ring)); + poly.push_back(std::move(ring)); geom.emplace_back(std::move(poly)); REQUIRE(mapnik::geometry::has_empty(geom)); } @@ -142,8 +141,8 @@ SECTION("multi-polygon") { mapnik::geometry::multi_polygon geom; mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0, 0); - poly.set_exterior_ring(std::move(ring)); + ring.emplace_back(0, 0); + poly.push_back(std::move(ring)); geom.emplace_back(std::move(poly)); REQUIRE(!mapnik::geometry::has_empty(geom)); } diff --git a/test/unit/geometry/is_empty.cpp b/test/unit/geometry/is_empty.cpp index 949b2b285..25ed8a487 100644 --- a/test/unit/geometry/is_empty.cpp +++ b/test/unit/geometry/is_empty.cpp @@ -1,4 +1,3 @@ - #include "catch.hpp" #include @@ -7,7 +6,7 @@ TEST_CASE("geometry is_empty") { SECTION("empty geometry") { - mapnik::geometry::geometry_empty geom; + mapnik::geometry::geometry_empty geom; REQUIRE(mapnik::geometry::is_empty(geom)); } @@ -19,7 +18,7 @@ SECTION("geometry collection") { } { mapnik::geometry::geometry_collection geom; - mapnik::geometry::geometry_empty geom1; + mapnik::geometry::geometry_empty geom1; geom.emplace_back(std::move(geom1)); REQUIRE(!mapnik::geometry::is_empty(geom)); } @@ -39,9 +38,9 @@ SECTION("linestring") { } { mapnik::geometry::line_string line; - line.add_coord(0, 0); - line.add_coord(25, 25); - line.add_coord(50, 50); + line.emplace_back(0, 0); + line.emplace_back(25, 25); + line.emplace_back(50, 50); REQUIRE(!mapnik::geometry::is_empty(line)); } } @@ -55,18 +54,18 @@ SECTION("polygon") { { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - poly.set_exterior_ring(std::move(ring)); + poly.push_back(std::move(ring)); REQUIRE(mapnik::geometry::is_empty(poly)); } { mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0, 0); - ring.add_coord(1, 0); - ring.add_coord(1, 1); - ring.add_coord(0, 1); - ring.add_coord(0, 0); - poly.set_exterior_ring(std::move(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::is_empty(poly)); } } @@ -79,9 +78,9 @@ SECTION("multi-point") { } { mapnik::geometry::multi_point geom; - geom.add_coord(0, 0); - geom.add_coord(25, 25); - geom.add_coord(50, 50); + geom.emplace_back(0, 0); + geom.emplace_back(25, 25); + geom.emplace_back(50, 50); REQUIRE(!mapnik::geometry::is_empty(geom)); } } @@ -110,7 +109,7 @@ SECTION("multi-polygon") { mapnik::geometry::multi_polygon geom; mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - poly.set_exterior_ring(std::move(ring)); + poly.push_back(std::move(ring)); geom.emplace_back(std::move(poly)); REQUIRE(!mapnik::geometry::is_empty(geom)); } diff --git a/test/unit/geometry/remove_empty.cpp b/test/unit/geometry/remove_empty.cpp index 93881c854..36a6955c5 100644 --- a/test/unit/geometry/remove_empty.cpp +++ b/test/unit/geometry/remove_empty.cpp @@ -1,4 +1,3 @@ - #include "catch.hpp" #include @@ -19,9 +18,9 @@ SECTION("multi-linestring") { using geom_type = mapnik::geometry::multi_line_string; geom_type geom; mapnik::geometry::line_string line; - line.add_coord(0, 0); - line.add_coord(0, 25); - line.add_coord(0, 50); + line.emplace_back(0, 0); + line.emplace_back(0, 25); + line.emplace_back(0, 50); geom.emplace_back(std::move(line)); geom.emplace_back(); @@ -37,18 +36,18 @@ SECTION("multi-polygon") { geom_type geom; mapnik::geometry::polygon poly; mapnik::geometry::linear_ring ring; - ring.add_coord(0, 0); - ring.add_coord(1, 0); - ring.add_coord(1, 1); - ring.add_coord(0, 1); - ring.add_coord(0, 0); - poly.set_exterior_ring(std::move(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)); geom.emplace_back(std::move(poly)); geom.emplace_back(); - + //geom.back().emplace_back(); //add an empty exterior ring REQUIRE(geom.size() == 2); geom_type geom2 = mapnik::geometry::remove_empty(geom); REQUIRE(geom2.size() == 1); - REQUIRE(geom2[0].exterior_ring.size() == 5); + REQUIRE(geom2.front().front().size() == 5); } } diff --git a/test/unit/serialization/wkb_formats_test.cpp b/test/unit/serialization/wkb_formats_test.cpp index bc0c17198..6d1a0ea2c 100644 --- a/test/unit/serialization/wkb_formats_test.cpp +++ b/test/unit/serialization/wkb_formats_test.cpp @@ -79,7 +79,7 @@ SECTION("wkb") { geom = mapnik::geometry_utils::from_wkb((const char*)sp_invalid_blob, sizeof(sp_invalid_blob) / sizeof(sp_invalid_blob[0]), mapnik::wkbAuto); - REQUIRE(geom.is()); // returns geometry_empty + REQUIRE(geom.is>()); // returns geometry_empty // sqlite generic wkb blob @@ -103,7 +103,7 @@ SECTION("wkb") { geom = mapnik::geometry_utils::from_wkb((const char*)sq_invalid_blob, sizeof(sq_invalid_blob) / sizeof(sq_invalid_blob[0]), mapnik::wkbGeneric); - REQUIRE(geom.is()); // returns geometry_empty + REQUIRE(geom.is>()); // returns geometry_empty } catch (std::exception const& ex) diff --git a/test/unit/serialization/wkb_test.cpp b/test/unit/serialization/wkb_test.cpp index 8a617df26..2dbb49cca 100644 --- a/test/unit/serialization/wkb_test.cpp +++ b/test/unit/serialization/wkb_test.cpp @@ -23,7 +23,7 @@ struct spatially_equal_visitor { using result_type = bool; - result_type operator() (mapnik::geometry::geometry_empty, mapnik::geometry::geometry_empty) const + result_type operator() (mapnik::geometry::geometry_empty, mapnik::geometry::geometry_empty) const { return true; } diff --git a/test/unit/vertex_adapter/vertex_adapter.cpp b/test/unit/vertex_adapter/vertex_adapter.cpp index da3e815fa..d6c1ed592 100644 --- a/test/unit/vertex_adapter/vertex_adapter.cpp +++ b/test/unit/vertex_adapter/vertex_adapter.cpp @@ -1,4 +1,3 @@ - #include "catch.hpp" #include @@ -8,10 +7,11 @@ TEST_CASE("vertex_adapters") { SECTION("polygon") { mapnik::geometry::polygon g; - g.exterior_ring.add_coord(1,1); - g.exterior_ring.add_coord(2,2); - g.exterior_ring.add_coord(100,100); - g.exterior_ring.add_coord(1,1); + g.emplace_back(); + g.back().emplace_back(1,1); + g.back().emplace_back(2,2); + g.back().emplace_back(100,100); + g.back().emplace_back(1,1); mapnik::geometry::polygon_vertex_adapter va(g); double x,y; @@ -47,27 +47,28 @@ SECTION("polygon") { SECTION("polygon with hole") { mapnik::geometry::polygon g; - g.exterior_ring.add_coord(0,0); - g.exterior_ring.add_coord(-10,0); - g.exterior_ring.add_coord(-10,10); - g.exterior_ring.add_coord(0,10); - g.exterior_ring.add_coord(0,0); + g.emplace_back(); + g.back().emplace_back(0,0); + g.back().emplace_back(-10,0); + g.back().emplace_back(-10,10); + g.back().emplace_back(0,10); + g.back().emplace_back(0,0); std::vector > interior_rings; mapnik::geometry::linear_ring hole; - hole.add_coord(-7,7); - hole.add_coord(-7,3); - hole.add_coord(-3,3); - hole.add_coord(-3,7); - hole.add_coord(-7,7); - g.add_hole(std::move(hole)); + hole.emplace_back(-7,7); + hole.emplace_back(-7,3); + hole.emplace_back(-3,3); + hole.emplace_back(-3,7); + hole.emplace_back(-7,7); + g.push_back(std::move(hole)); mapnik::geometry::linear_ring hole_in_hole; - hole_in_hole.add_coord(-6,4); - hole_in_hole.add_coord(-6,6); - hole_in_hole.add_coord(-4,6); - hole_in_hole.add_coord(-4,4); - hole_in_hole.add_coord(-6,4); - g.add_hole(std::move(hole_in_hole)); + hole_in_hole.emplace_back(-6,4); + hole_in_hole.emplace_back(-6,6); + hole_in_hole.emplace_back(-4,6); + hole_in_hole.emplace_back(-4,4); + hole_in_hole.emplace_back(-6,4); + g.push_back(std::move(hole_in_hole)); mapnik::geometry::polygon_vertex_adapter va(g); double x,y; @@ -100,7 +101,7 @@ SECTION("polygon with hole") { REQUIRE( y == 0 ); // exterior ring via ring_vertex_adapter - mapnik::geometry::ring_vertex_adapter va2(g.exterior_ring); + mapnik::geometry::ring_vertex_adapter va2(g.front()); cmd = va2.vertex(&x,&y); REQUIRE( cmd == mapnik::SEG_MOVETO ); REQUIRE( x == 0 );