diff --git a/bench/vtile-encode.cpp b/bench/vtile-encode.cpp index bc15088b..d3704857 100644 --- a/bench/vtile-encode.cpp +++ b/bench/vtile-encode.cpp @@ -13,7 +13,7 @@ #include // mapnik -#include +#include #include #include #include @@ -121,7 +121,7 @@ int main(int argc, char** argv) else { mapnik::feature_ptr feature = json_fs->next(); - + while (feature) { ds->push(feature); @@ -129,7 +129,7 @@ int main(int argc, char** argv) } } - // Create tile + // Create tile unsigned tile_size = layer_extent; int buffer_size = 0; diff --git a/gyp/common.gypi b/gyp/common.gypi index 49940efd..4e0b1416 100644 --- a/gyp/common.gypi +++ b/gyp/common.gypi @@ -108,10 +108,10 @@ "default_configuration": "Release", "xcode_settings": { "CLANG_CXX_LIBRARY": "libc++", - "CLANG_CXX_LANGUAGE_STANDARD":"c++11", + "CLANG_CXX_LANGUAGE_STANDARD":"c++14", "GCC_VERSION": "com.apple.compilers.llvm.clang.1_0", }, - "cflags_cc": ["-std=c++11"], + "cflags_cc": ["-std=c++14"], "configurations": { "Debug": { "defines": [ diff --git a/src/boost_geometry_adapters.hpp b/src/boost_geometry_adapters.hpp deleted file mode 100644 index 5aaf52e9..00000000 --- a/src/boost_geometry_adapters.hpp +++ /dev/null @@ -1,263 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-function" -#pragma GCC diagnostic ignored "-Wunused-parameter" -#pragma GCC diagnostic ignored "-Wunused-variable" -#pragma GCC diagnostic ignored "-Wshadow" -#ifdef __clang__ -#pragma GCC diagnostic ignored "-Wunknown-pragmas" -#endif -#pragma GCC diagnostic ignored "-Wfloat-equal" -#pragma GCC diagnostic ignored "-Wpragmas" -#pragma GCC diagnostic ignored "-Wdeprecated-register" -#pragma GCC diagnostic ignored "-Wshorten-64-to-32" -#pragma GCC diagnostic ignored "-Wunused-local-typedefs" -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" -#include -#include -#include -#include -#pragma GCC diagnostic pop - -#include - -#include - -BOOST_GEOMETRY_REGISTER_POINT_2D (mapbox::geometry::point, double, boost::geometry::cs::cartesian, x, y) -BOOST_GEOMETRY_REGISTER_POINT_2D (mapbox::geometry::point, std::int64_t, boost::geometry::cs::cartesian, x, y) - -namespace boost { - -template -struct range_iterator > -{ - using type = typename mapbox::geometry::multi_point::iterator; -}; - -template -struct range_const_iterator > -{ - using type = typename mapbox::geometry::multi_point::const_iterator; -}; - -template -inline typename mapbox::geometry::multi_point::iterator -range_begin(mapbox::geometry::multi_point & mp) {return mp.begin();} - -template -inline typename mapbox::geometry::multi_point::iterator -range_end(mapbox::geometry::multi_point & mp) {return mp.end();} - -template -inline typename mapbox::geometry::multi_point::const_iterator -range_begin(mapbox::geometry::multi_point const& mp) {return mp.begin();} - -template -inline typename mapbox::geometry::multi_point::const_iterator -range_end(mapbox::geometry::multi_point const& mp) {return mp.end();} - -template -struct range_iterator > -{ - using type = typename mapbox::geometry::line_string::iterator; -}; - -template -struct range_const_iterator > -{ - using type = typename mapbox::geometry::line_string::const_iterator; -}; - -template -inline typename mapbox::geometry::line_string::iterator -range_begin(mapbox::geometry::line_string & line) {return line.begin();} - -template -inline typename mapbox::geometry::line_string::iterator -range_end(mapbox::geometry::line_string & line) {return line.end();} - -template -inline typename mapbox::geometry::line_string::const_iterator -range_begin(mapbox::geometry::line_string const& line) {return line.begin();} - -template -inline typename mapbox::geometry::line_string::const_iterator -range_end(mapbox::geometry::line_string const& line) {return line.end();} - -namespace geometry { -namespace traits { - -template -struct tag> { - using type = box_tag; -}; - -template -struct indexed_access, min_corner, 0> -{ - static inline CoordinateType get(mapbox::geometry::box const& b) { return b.min.x;} - static inline void set(mapbox::geometry::box &b, CoordinateType const& value) { b.min.x = value; } -}; - -template -struct indexed_access, min_corner, 1> -{ - static inline CoordinateType get(mapbox::geometry::box const& b) { return b.min.y;} - static inline void set(mapbox::geometry::box &b, CoordinateType const& value) { b.min.y = value; } -}; - -template -struct indexed_access, max_corner, 0> -{ - static inline CoordinateType get(mapbox::geometry::box const& b) { return b.max.x;} - static inline void set(mapbox::geometry::box &b, CoordinateType const& value) { b.max.x = value; } -}; - -template -struct indexed_access, max_corner, 1> -{ - static inline CoordinateType get(mapbox::geometry::box const& b) { return b.max.y;} - static inline void set(mapbox::geometry::box &b, CoordinateType const& value) { b.max.y = value; } -}; - -template -struct coordinate_type> { - using type = CoordinateType; -}; - -template -struct coordinate_system> { - using type = boost::geometry::cs::cartesian; -}; - -template -struct dimension> : boost::mpl::int_<2> {}; - -template -struct access, 0> { - static CoordinateType get(mapbox::geometry::point const& p) { - return p.x; - } - - static void set(mapbox::geometry::point& p, CoordinateType x) { - p.x = x; - } -}; - -template -struct access, 1> { - static CoordinateType get(mapbox::geometry::point const& p) { - return p.y; - } - - static void set(mapbox::geometry::point& p, CoordinateType y) { - p.y = y; - } -}; - -template -struct tag> { - using type = multi_point_tag; -}; - -template -struct tag> { - using type = linestring_tag; -}; - -template -struct tag> { - using type = multi_linestring_tag; -}; - -template -struct tag> { - using type = ring_tag; -}; - -template -struct point_order > -{ - static const order_selector value = counterclockwise; -}; - -template -struct tag> { - using type = polygon_tag; -}; - -template -struct ring_mutable_type> { - using type = mapbox::geometry::point&; -}; - -template -struct ring_const_type> { - using type = mapbox::geometry::point const&; -}; - -template -struct ring_mutable_type> { - using type = mapbox::geometry::linear_ring&; -}; - -template -struct ring_const_type> { - using type = mapbox::geometry::linear_ring const&; -}; - -template -struct interior_mutable_type> { - using type = - boost::iterator_range::iterator>; -}; - -template -struct interior_const_type> { - using type = - boost::iterator_range::const_iterator>; -}; - -template -struct exterior_ring> { - static mapbox::geometry::linear_ring& - get(mapbox::geometry::polygon& p) { - return p.at(0); - } - - static mapbox::geometry::linear_ring const& - get(mapbox::geometry::polygon const& p) { - return p.at(0); - } -}; - -template -struct interior_rings> { - static boost::iterator_range::iterator> - get(mapbox::geometry::polygon& p) { - return boost::make_iterator_range(p.begin() + 1, p.end()); - } - - static boost::iterator_range::const_iterator> - get(mapbox::geometry::polygon const& p) { - return boost::make_iterator_range(p.begin() + 1, p.end()); - } -}; - -template -struct tag> { - using type = multi_polygon_tag; -}; -} -} -} - diff --git a/src/convert_geometry_types.hpp b/src/convert_geometry_types.hpp deleted file mode 100644 index 85ead516..00000000 --- a/src/convert_geometry_types.hpp +++ /dev/null @@ -1,94 +0,0 @@ -#pragma once - -// Mapnik -#include - -// Mapbox -#include - -namespace mapnik -{ - -namespace vector_tile_impl -{ - -template -mapbox::geometry::linear_ring mapnik_to_mapbox(mapnik::geometry::linear_ring const& input) -{ - mapbox::geometry::linear_ring r; - r.reserve(input.size()); - for (auto const& pt : input) { - r.emplace_back(pt.x, pt.y); - } - return r; -} - -template -mapbox::geometry::polygon mapnik_to_mapbox(mapnik::geometry::polygon const& input) -{ - mapbox::geometry::polygon out; - if (input.exterior_ring.empty()) - { - return out; - } - - out.push_back(mapnik_to_mapbox(input.exterior_ring)); - - for (auto const& in_r : input.interior_rings) { - out.push_back(mapnik_to_mapbox(in_r)); - } - - return out; -} - -template -mapbox::geometry::multi_polygon mapnik_to_mapbox(mapnik::geometry::multi_polygon const& input) -{ - mapbox::geometry::multi_polygon out; - for (auto const& poly : input) { - out.push_back(mapnik_to_mapbox(poly)); - } - return out; -} - -template -mapnik::geometry::linear_ring mapbox_to_mapnik(mapbox::geometry::linear_ring const& input) -{ - mapnik::geometry::linear_ring r; - r.reserve(input.size()); - for (auto const& pt : input) { - r.emplace_back(pt.x, pt.y); - } - return r; -} - -template -mapnik::geometry::polygon mapbox_to_mapnik(mapbox::geometry::polygon const& input) -{ - mapnik::geometry::polygon out; - - bool first = true; - for (auto const& in_r : input) { - if (first) { - out.exterior_ring = mapbox_to_mapnik(in_r); - first = false; - } else { - out.interior_rings.push_back(mapbox_to_mapnik(in_r)); - } - } - return out; -} - -template -mapnik::geometry::multi_polygon mapbox_to_mapnik(mapbox::geometry::multi_polygon const& input) -{ - mapnik::geometry::multi_polygon out; - for (auto const& poly : input) { - out.push_back(mapbox_to_mapnik(poly)); - } - return out; -} - -} // end ns vector_tile_impl - -} // end ns mapnik diff --git a/src/vector_tile_datasource_pbf.hpp b/src/vector_tile_datasource_pbf.hpp index 3de2ca6c..51d07491 100644 --- a/src/vector_tile_datasource_pbf.hpp +++ b/src/vector_tile_datasource_pbf.hpp @@ -1,7 +1,7 @@ #pragma once // mapnik -#include +//#include #include #include @@ -10,7 +10,7 @@ namespace mapnik { - + namespace vector_tile_impl { diff --git a/src/vector_tile_datasource_pbf.ipp b/src/vector_tile_datasource_pbf.ipp index b9800e86..e4cb7544 100644 --- a/src/vector_tile_datasource_pbf.ipp +++ b/src/vector_tile_datasource_pbf.ipp @@ -4,7 +4,7 @@ #include "vector_tile_config.hpp" // mapnik -#include +#include #include #include #include diff --git a/src/vector_tile_featureset_pbf.hpp b/src/vector_tile_featureset_pbf.hpp index ee0a345a..d8acc4c5 100644 --- a/src/vector_tile_featureset_pbf.hpp +++ b/src/vector_tile_featureset_pbf.hpp @@ -4,7 +4,7 @@ #include // mapnik -#include +//#include #include #include #include @@ -14,10 +14,10 @@ // std #include -namespace mapnik -{ +namespace mapnik +{ -namespace vector_tile_impl +namespace vector_tile_impl { using pbf_attr_value_type = mapnik::util::variant; @@ -38,7 +38,7 @@ class tile_featureset_pbf : public Featureset std::vector const& layer_keys, layer_pbf_attr_type const& layer_values, unsigned version); - + virtual ~tile_featureset_pbf() {} feature_ptr next(); diff --git a/src/vector_tile_featureset_pbf.ipp b/src/vector_tile_featureset_pbf.ipp index 51211347..13a65fd1 100644 --- a/src/vector_tile_featureset_pbf.ipp +++ b/src/vector_tile_featureset_pbf.ipp @@ -2,7 +2,7 @@ #include "vector_tile_geometry_decoder.hpp" // mapnik -#include +#include #include #include #include @@ -17,10 +17,10 @@ // protozero #include -namespace mapnik -{ +namespace mapnik +{ -namespace vector_tile_impl +namespace vector_tile_impl { template @@ -78,7 +78,7 @@ struct value_visitor : tr_(tr), feature_(feature), name_(name) {} - + void operator() (std::string const& val) { feature_->put(name_, tr_.transcode(val.data(), val.length())); diff --git a/src/vector_tile_geometry_clipper.hpp b/src/vector_tile_geometry_clipper.hpp index 104227ba..5313f75a 100644 --- a/src/vector_tile_geometry_clipper.hpp +++ b/src/vector_tile_geometry_clipper.hpp @@ -4,7 +4,7 @@ #include "vector_tile_config.hpp" // mapnik -#include +#include // mapbox #include @@ -50,12 +50,12 @@ double area(mapbox::geometry::linear_ring const& poly) { inline mapbox::geometry::wagyu::fill_type get_wagyu_fill_type(polygon_fill_type type) { - switch (type) + switch (type) { case polygon_fill_type_max: case even_odd_fill: return mapbox::geometry::wagyu::fill_type_even_odd; - case non_zero_fill: + case non_zero_fill: return mapbox::geometry::wagyu::fill_type_non_zero; case positive_fill: return mapbox::geometry::wagyu::fill_type_positive; @@ -69,7 +69,7 @@ inline mapbox::geometry::wagyu::fill_type get_wagyu_fill_type(polygon_fill_type } // end ns detail template -class geometry_clipper +class geometry_clipper { private: NextProcessor & next_; @@ -178,7 +178,7 @@ class geometry_clipper { return; } - + mapbox::geometry::wagyu::wagyu clipper; mapbox::geometry::point min_pt(tile_clipping_extent_.minx(), tile_clipping_extent_.miny()); mapbox::geometry::point max_pt(tile_clipping_extent_.maxx(), tile_clipping_extent_.maxy()); @@ -186,7 +186,7 @@ class geometry_clipper bool first = true; for (auto & ring : geom) { - if (ring.size() < 3) + if (ring.size() < 3) { if (first) { if (process_all_rings_) { @@ -203,7 +203,7 @@ class geometry_clipper if ((std::abs(area) < area_threshold_) && !process_all_rings_) { return; } - if (area < 0) { + if (area < 0) { std::reverse(ring.begin(), ring.end()); } auto new_ring = mapbox::geometry::wagyu::quick_clip::quick_lr_clip(ring, b); @@ -231,10 +231,10 @@ class geometry_clipper } mapbox::geometry::multi_polygon mp; - - clipper.execute(mapbox::geometry::wagyu::clip_type_union, - mp, - detail::get_wagyu_fill_type(fill_type_), + + clipper.execute(mapbox::geometry::wagyu::clip_type_union, + mp, + detail::get_wagyu_fill_type(fill_type_), mapbox::geometry::wagyu::fill_type_even_odd); if (mp.empty()) @@ -250,12 +250,12 @@ class geometry_clipper { return; } - + mapbox::geometry::point min_pt(tile_clipping_extent_.minx(), tile_clipping_extent_.miny()); mapbox::geometry::point max_pt(tile_clipping_extent_.maxx(), tile_clipping_extent_.maxy()); mapbox::geometry::box b(min_pt, max_pt); mapbox::geometry::multi_polygon mp; - + if (multi_polygon_union_) { mapbox::geometry::wagyu::wagyu clipper; @@ -263,7 +263,7 @@ class geometry_clipper { bool first = true; for (auto & ring : poly) { - if (ring.size() < 3) + if (ring.size() < 3) { if (first) { first = false; @@ -279,7 +279,7 @@ class geometry_clipper if ((std::abs(area) < area_threshold_) && !process_all_rings_) { break; } - if (area < 0) { + if (area < 0) { std::reverse(ring.begin(), ring.end()); } auto new_ring = mapbox::geometry::wagyu::quick_clip::quick_lr_clip(ring, b); @@ -306,9 +306,9 @@ class geometry_clipper } } } - clipper.execute(mapbox::geometry::wagyu::clip_type_union, - mp, - detail::get_wagyu_fill_type(fill_type_), + clipper.execute(mapbox::geometry::wagyu::clip_type_union, + mp, + detail::get_wagyu_fill_type(fill_type_), mapbox::geometry::wagyu::fill_type_even_odd); } else @@ -319,7 +319,7 @@ class geometry_clipper mapbox::geometry::multi_polygon tmp_mp; bool first = true; for (auto & ring : poly) { - if (ring.size() < 3) + if (ring.size() < 3) { if (first) { first = false; @@ -335,7 +335,7 @@ class geometry_clipper if ((std::abs(area) < area_threshold_) && !process_all_rings_) { break; } - if (area < 0) { + if (area < 0) { std::reverse(ring.begin(), ring.end()); } auto new_ring = mapbox::geometry::wagyu::quick_clip::quick_lr_clip(ring, b); @@ -361,9 +361,9 @@ class geometry_clipper clipper.add_ring(new_ring); } } - clipper.execute(mapbox::geometry::wagyu::clip_type_union, - tmp_mp, - detail::get_wagyu_fill_type(fill_type_), + clipper.execute(mapbox::geometry::wagyu::clip_type_union, + tmp_mp, + detail::get_wagyu_fill_type(fill_type_), mapbox::geometry::wagyu::fill_type_even_odd); mp.insert(mp.end(), tmp_mp.begin(), tmp_mp.end()); } diff --git a/src/vector_tile_geometry_decoder.hpp b/src/vector_tile_geometry_decoder.hpp index 91624c23..ece5b8ba 100644 --- a/src/vector_tile_geometry_decoder.hpp +++ b/src/vector_tile_geometry_decoder.hpp @@ -7,7 +7,7 @@ #include //mapnik -#include +#include #include #if defined(DEBUG) #include @@ -18,21 +18,21 @@ #include #include -namespace mapnik -{ - -namespace vector_tile_impl +namespace mapnik +{ + +namespace vector_tile_impl { // NOTE: this object is for one-time use. Once you've progressed to the end // by calling next(), to re-iterate, you must construct a new object -class GeometryPBF +class GeometryPBF { public: using value_type = std::int64_t; using iterator_type = protozero::pbf_reader::const_uint32_iterator; using pbf_itr = protozero::iterator_range; - + explicit GeometryPBF(pbf_itr const& geo_iterator); enum command : uint8_t @@ -66,8 +66,8 @@ class GeometryPBF }; template -MAPNIK_VECTOR_INLINE mapnik::geometry::geometry decode_geometry(GeometryPBF & paths, - std::int32_t geom_type, +MAPNIK_VECTOR_INLINE mapnik::geometry::geometry decode_geometry(GeometryPBF & paths, + std::int32_t geom_type, unsigned version, value_type tile_x, value_type tile_y, @@ -76,8 +76,8 @@ MAPNIK_VECTOR_INLINE mapnik::geometry::geometry decode_geometry(Geom mapnik::box2d const& bbox); template -MAPNIK_VECTOR_INLINE mapnik::geometry::geometry decode_geometry(GeometryPBF & paths, - std::int32_t geom_type, +MAPNIK_VECTOR_INLINE mapnik::geometry::geometry decode_geometry(GeometryPBF & paths, + std::int32_t geom_type, unsigned version, value_type tile_x, value_type tile_y, diff --git a/src/vector_tile_geometry_decoder.ipp b/src/vector_tile_geometry_decoder.ipp index d4bc43ec..b3bf81d5 100644 --- a/src/vector_tile_geometry_decoder.ipp +++ b/src/vector_tile_geometry_decoder.ipp @@ -2,7 +2,7 @@ #include //mapnik -#include +#include #include #if defined(DEBUG) #include @@ -13,10 +13,10 @@ #include #include -namespace mapnik -{ - -namespace vector_tile_impl +namespace mapnik +{ + +namespace vector_tile_impl { namespace detail @@ -48,7 +48,7 @@ inline void move_cursor(value_type & x, value_type & y, std::int32_t dx, std::in template -inline value_type get_point_value(value_type const val, +inline value_type get_point_value(value_type const val, double const scale_val, double const tile_loc) { @@ -56,7 +56,7 @@ inline value_type get_point_value(value_type const val, } template <> -inline double get_point_value(double const val, +inline double get_point_value(double const val, double const scale_val, double const tile_loc) { @@ -64,8 +64,8 @@ inline double get_point_value(double const val, } template -void decode_point(mapnik::geometry::geometry & geom, - GeometryPBF & paths, +void decode_point(mapnik::geometry::geometry & geom, + GeometryPBF & paths, geom_value_type const tile_x, geom_value_type const tile_y, double const scale_x, @@ -89,7 +89,7 @@ void decode_point(mapnik::geometry::geometry & geom, { geom = mapnik::geometry::geometry_empty(); return; - } + } else if (bbox.intersects(x1_, y1_)) { #if defined(DEBUG) @@ -145,7 +145,7 @@ void decode_point(mapnik::geometry::geometry & geom, } template -void decode_linestring(mapnik::geometry::geometry & geom, +void decode_linestring(mapnik::geometry::geometry & geom, GeometryPBF & paths, geom_value_type const tile_x, geom_value_type const tile_y, @@ -198,11 +198,11 @@ void decode_linestring(mapnik::geometry::geometry & geom, } } else //cmd == GeometryPBF::end - { + { if (version == 1) { // Version 1 of the spec wasn't clearly defined and therefore - // we shouldn't be strict on the reading of a tile that has only a moveto + // we shouldn't be strict on the reading of a tile that has only a moveto // command. So lets just ignore this moveto command. break; } @@ -220,12 +220,12 @@ void decode_linestring(mapnik::geometry::geometry & geom, // add moveto command position x0_ = get_point_value(x0, scale_x, tile_x); y0_ = get_point_value(y0, scale_y, tile_y); - line.add_coord(x0_, y0_); + line.emplace_back(x0_, y0_); part_env.init(x0_, y0_, x0_, y0_); // add first lineto x1_ = get_point_value(x1, scale_x, tile_x); y1_ = get_point_value(y1, scale_y, tile_y); - line.add_coord(x1_, y1_); + line.emplace_back(x1_, y1_); part_env.expand_to_include(x1_, y1_); #if defined(DEBUG) previous_len = paths.get_length(); @@ -234,7 +234,7 @@ void decode_linestring(mapnik::geometry::geometry & geom, { x1_ = get_point_value(x1, scale_x, tile_x); y1_ = get_point_value(y1, scale_y, tile_y); - line.add_coord(x1_, y1_); + line.emplace_back(x1_, y1_); part_env.expand_to_include(x1_, y1_); #if defined(DEBUG) if (previous_len <= paths.get_length() && !paths.already_had_error) @@ -253,12 +253,12 @@ void decode_linestring(mapnik::geometry::geometry & geom, if (cmd == GeometryPBF::end) { break; - } + } // else we are guaranteed it is a moveto x0 = x1; y0 = y1; } - + std::size_t num_lines = multi_line.size(); if (num_lines == 0) { @@ -284,7 +284,7 @@ void decode_linestring(mapnik::geometry::geometry & geom, template void decode_polygon(mapnik::geometry::geometry & geom, - GeometryPBF & paths, + GeometryPBF & paths, geom_value_type const tile_x, geom_value_type const tile_y, double scale_x, @@ -394,18 +394,18 @@ void decode_polygon(mapnik::geometry::geometry & geom, // add moveto command position x0_ = get_point_value(x0, scale_x, tile_x); y0_ = get_point_value(y0, scale_y, tile_y); - ring.add_coord(x0_, y0_); + ring.emplace_back(x0_, y0_); part_env.init(x0_, y0_, x0_, y0_); // add first lineto x1_ = get_point_value(x1, scale_x, tile_x); y1_ = get_point_value(y1, scale_y, tile_y); - ring.add_coord(x1_, y1_); + ring.emplace_back(x1_, y1_); part_env.expand_to_include(x1_, y1_); ring_area += calculate_segment_area(x0, y0, x1, y1); // add second lineto x2_ = get_point_value(x2, scale_x, tile_x); y2_ = get_point_value(y2, scale_y, tile_y); - ring.add_coord(x2_, y2_); + ring.emplace_back(x2_, y2_); part_env.expand_to_include(x2_, y2_); ring_area += calculate_segment_area(x1, y1, x2, y2); x1 = x2; @@ -422,7 +422,7 @@ void decode_polygon(mapnik::geometry::geometry & geom, { x2_ = get_point_value(x2, scale_x, tile_x); y2_ = get_point_value(y2, scale_y, tile_y); - ring.add_coord(x2_, y2_); + ring.emplace_back(x2_, y2_); part_env.expand_to_include(x2_, y2_); ring_area += calculate_segment_area(x1, y1, x2, y2); x1 = x2; @@ -445,7 +445,7 @@ void decode_polygon(mapnik::geometry::geometry & geom, { // If the previous lineto didn't already close the polygon (WHICH IT SHOULD NOT) // close out the polygon ring. - ring.add_coord(x0_, y0_); + ring.emplace_back(x0_, y0_); ring_area += calculate_segment_area(x1, y1, x0, y0); } if (ring.size() > 3) @@ -482,7 +482,7 @@ void decode_polygon(mapnik::geometry::geometry & geom, { rings.pop_back(); } - ring_area = 0.0; + ring_area = 0.0; cmd = paths.ring_next(x0, y0, false); if (cmd == GeometryPBF::end) @@ -503,42 +503,25 @@ void decode_polygon(mapnik::geometry::geometry & geom, } if (rings.size() == 0) - { + { geom = mapnik::geometry::geometry_empty(); return; } - std::size_t i = 0; + bool reverse_rings = (scaling_reversed_orientation(scale_x, scale_y) != first_ring_is_clockwise); auto rings_itr = std::make_move_iterator(rings.begin()); auto rings_end = std::make_move_iterator(rings.end()); mapnik::geometry::multi_polygon multi_poly; - while (rings_itr != rings_end) + for (std::size_t i = 0; rings_itr != rings_end; ++rings_itr,++i) { - multi_poly.emplace_back(); + if (rings_exterior[i]) multi_poly.emplace_back(); auto & poly = multi_poly.back(); if (reverse_rings) { std::reverse(rings_itr->begin(), rings_itr->end()); } - poly.set_exterior_ring(std::move(*rings_itr)); - ++rings_itr; - ++i; - while (rings_itr != rings_end) - { - if (rings_exterior[i]) - { - break; - } - if (reverse_rings) - { - std::reverse(rings_itr->begin(), rings_itr->end()); - } - poly.add_hole(std::move(*rings_itr)); - ++rings_itr; - ++i; - } + poly.push_back(std::move(*rings_itr)); } - auto num_poly = multi_poly.size(); if (num_poly == 1) { @@ -558,7 +541,7 @@ GeometryPBF::GeometryPBF(pbf_itr const& geo_iterator) geo_end_itr_(geo_iterator.end()), x(0), y(0), - ox(0), + ox(0), oy(0), length(0), cmd(move_to) @@ -570,7 +553,7 @@ GeometryPBF::GeometryPBF(pbf_itr const& geo_iterator) typename GeometryPBF::command GeometryPBF::point_next(value_type & rx, value_type & ry) { - if (length == 0) + if (length == 0) { if (geo_itr_ != geo_end_itr_) { @@ -600,7 +583,7 @@ typename GeometryPBF::command GeometryPBF::point_next(value_type & rx, value_typ } } } - else + else { return end; } @@ -620,8 +603,8 @@ typename GeometryPBF::command GeometryPBF::point_next(value_type & rx, value_typ return move_to; } -typename GeometryPBF::command GeometryPBF::line_next(value_type & rx, - value_type & ry, +typename GeometryPBF::command GeometryPBF::line_next(value_type & rx, + value_type & ry, bool skip_lineto_zero) { if (length == 0) @@ -694,8 +677,8 @@ typename GeometryPBF::command GeometryPBF::line_next(value_type & rx, return line_to; } -typename GeometryPBF::command GeometryPBF::ring_next(value_type & rx, - value_type & ry, +typename GeometryPBF::command GeometryPBF::ring_next(value_type & rx, + value_type & ry, bool skip_lineto_zero) { if (length == 0) @@ -774,8 +757,8 @@ typename GeometryPBF::command GeometryPBF::ring_next(value_type & rx, } template -MAPNIK_VECTOR_INLINE mapnik::geometry::geometry decode_geometry(GeometryPBF & paths, - int32_t geom_type, +MAPNIK_VECTOR_INLINE mapnik::geometry::geometry decode_geometry(GeometryPBF & paths, + int32_t geom_type, unsigned version, value_type tile_x, value_type tile_y, @@ -814,8 +797,8 @@ MAPNIK_VECTOR_INLINE mapnik::geometry::geometry decode_geometry(Geom } template -MAPNIK_VECTOR_INLINE mapnik::geometry::geometry decode_geometry(GeometryPBF & paths, - int32_t geom_type, +MAPNIK_VECTOR_INLINE mapnik::geometry::geometry decode_geometry(GeometryPBF & paths, + int32_t geom_type, unsigned version, value_type tile_x, value_type tile_y, diff --git a/src/vector_tile_layer.hpp b/src/vector_tile_layer.hpp index 532b0f6b..8873e39b 100644 --- a/src/vector_tile_layer.hpp +++ b/src/vector_tile_layer.hpp @@ -5,7 +5,7 @@ #include "vector_tile_config.hpp" // mapnik -#include +#include #include #include #include @@ -199,7 +199,7 @@ class tile_layer } ext.width(buffered_width); ext.height(buffered_height); - + boost::optional > const& maximum_extent = map.maximum_extent(); if (maximum_extent) { @@ -207,7 +207,7 @@ class tile_layer } return ext; } - + mapnik::box2d calc_source_buffered_extent() { mapnik::box2d new_extent(target_buffered_extent_); @@ -271,7 +271,7 @@ class tile_layer else { // if no intersection then nothing to do for layer - valid_ = false; + valid_ = false; } double qw = unbuffered_query_extent.width() > 0 ? unbuffered_query_extent.width() : 1; double qh = unbuffered_query_extent.height() > 0 ? unbuffered_query_extent.height() : 1; @@ -348,7 +348,7 @@ class tile_layer { return name_; } - + void name(std::string const& val) { name_ = val; @@ -358,12 +358,12 @@ class tile_layer { return empty_; } - + bool is_painted() const { return painted_; } - + void make_painted() { painted_ = true; diff --git a/src/vector_tile_processor.ipp b/src/vector_tile_processor.ipp index ad9a21ab..6190f951 100644 --- a/src/vector_tile_processor.ipp +++ b/src/vector_tile_processor.ipp @@ -8,7 +8,7 @@ #include "vector_tile_layer.hpp" // mapnik -#include +#include #include #include #include @@ -29,10 +29,10 @@ // std #include -namespace mapnik +namespace mapnik { -namespace vector_tile_impl +namespace vector_tile_impl { namespace detail @@ -62,7 +62,7 @@ inline void create_geom_layer(tile_layer & layer, { return; } - + using encoding_process = mapnik::vector_tile_impl::geometry_to_feature_pbf_visitor; using clipping_process = mapnik::vector_tile_impl::geometry_clipper; @@ -89,10 +89,10 @@ inline void create_geom_layer(tile_layer & layer, { mapnik::geometry::geometry const& geom = feature->get_geometry(); encoding_process encoder(*feature, builder); - clipping_process clipper(tile_clipping_extent, - area_threshold, - strictly_simple, - multi_polygon_union, + clipping_process clipper(tile_clipping_extent, + area_threshold, + strictly_simple, + multi_polygon_union, fill_type, process_all_rings, encoder); @@ -112,10 +112,10 @@ inline void create_geom_layer(tile_layer & layer, { mapnik::geometry::geometry const& geom = feature->get_geometry(); encoding_process encoder(*feature, builder); - clipping_process clipper(tile_clipping_extent, - area_threshold, - strictly_simple, - multi_polygon_union, + clipping_process clipper(tile_clipping_extent, + area_threshold, + strictly_simple, + multi_polygon_union, fill_type, process_all_rings, encoder); @@ -136,10 +136,10 @@ inline void create_geom_layer(tile_layer & layer, { mapnik::geometry::geometry const& geom = feature->get_geometry(); encoding_process encoder(*feature, builder); - clipping_process clipper(tile_clipping_extent, - area_threshold, - strictly_simple, - multi_polygon_union, + clipping_process clipper(tile_clipping_extent, + area_threshold, + strictly_simple, + multi_polygon_union, fill_type, process_all_rings, encoder); @@ -158,10 +158,10 @@ inline void create_geom_layer(tile_layer & layer, { mapnik::geometry::geometry const& geom = feature->get_geometry(); encoding_process encoder(*feature, builder); - clipping_process clipper(tile_clipping_extent, - area_threshold, - strictly_simple, - multi_polygon_union, + clipping_process clipper(tile_clipping_extent, + area_threshold, + strictly_simple, + multi_polygon_union, fill_type, process_all_rings, encoder); @@ -195,7 +195,7 @@ inline void create_raster_layer(tile_layer & layer, { return; } - + mapnik::raster_ptr const& source = feature->get_raster(); if (!source) { @@ -203,7 +203,7 @@ inline void create_raster_layer(tile_layer & layer, } mapnik::box2d target_ext = box2d(source->ext_); - + layer.get_proj_transform().backward(target_ext, PROJ_ENVELOPE_POINTS); mapnik::box2d ext = layer.get_view_transform().forward(target_ext); @@ -244,7 +244,7 @@ MAPNIK_VECTOR_INLINE void processor::update_tile(tile & t, { // Futures std::vector tile_layers; - + for (mapnik::layer const& lay : m_.layers()) { if (t.has_layer(lay.name())) @@ -268,7 +268,7 @@ MAPNIK_VECTOR_INLINE void processor::update_tile(tile & t, continue; } } - + if (threading_mode_ == std::launch::deferred) { for (auto & layer_ref : tile_layers) @@ -338,7 +338,7 @@ MAPNIK_VECTOR_INLINE void processor::update_tile(tile & t, for (auto & layer_ref : tile_layers) { - t.add_layer(layer_ref); + t.add_layer(layer_ref); } } diff --git a/src/vector_tile_projection.hpp b/src/vector_tile_projection.hpp index 88d86fb7..81d01255 100644 --- a/src/vector_tile_projection.hpp +++ b/src/vector_tile_projection.hpp @@ -5,12 +5,12 @@ #include "vector_tile_config.hpp" // mapnik -#include +#include -namespace mapnik -{ +namespace mapnik +{ -namespace vector_tile_impl +namespace vector_tile_impl { class spherical_mercator @@ -32,9 +32,9 @@ class spherical_mercator double & maxy); }; -MAPNIK_VECTOR_INLINE mapnik::box2d merc_extent(std::uint32_t tile_size, - std::uint64_t x, - std::uint64_t y, +MAPNIK_VECTOR_INLINE mapnik::box2d merc_extent(std::uint32_t tile_size, + std::uint64_t x, + std::uint64_t y, std::uint64_t z); } // end vector_tile_impl ns diff --git a/src/vector_tile_projection.ipp b/src/vector_tile_projection.ipp index d3576822..4ef78e4b 100644 --- a/src/vector_tile_projection.ipp +++ b/src/vector_tile_projection.ipp @@ -2,7 +2,6 @@ #include "vector_tile_config.hpp" // mapnik -#include #include // std @@ -13,10 +12,10 @@ #define M_PI 3.141592653589793238462643 #endif -namespace mapnik -{ +namespace mapnik +{ -namespace vector_tile_impl +namespace vector_tile_impl { MAPNIK_VECTOR_INLINE void spherical_mercator::from_pixels(double shift, double & x, double & y) @@ -46,9 +45,9 @@ MAPNIK_VECTOR_INLINE void spherical_mercator::xyz(std::uint64_t x, lonlat2merc(&maxx,&maxy,1); } -MAPNIK_VECTOR_INLINE mapnik::box2d merc_extent(std::uint32_t tile_size, - std::uint64_t x, - std::uint64_t y, +MAPNIK_VECTOR_INLINE mapnik::box2d merc_extent(std::uint32_t tile_size, + std::uint64_t x, + std::uint64_t y, std::uint64_t z) { spherical_mercator merc(tile_size); diff --git a/src/vector_tile_raster_clipper.hpp b/src/vector_tile_raster_clipper.hpp index 0a9ec9a5..03d7f81b 100644 --- a/src/vector_tile_raster_clipper.hpp +++ b/src/vector_tile_raster_clipper.hpp @@ -5,7 +5,7 @@ #include "vector_tile_config.hpp" // mapnik -#include +#include #include #include #include @@ -58,12 +58,12 @@ struct raster_clipper raster_width_(raster_width), raster_height_(raster_height), start_x_(start_x), - start_y_(start_y) + start_y_(start_y) { } - + MAPNIK_VECTOR_INLINE std::string operator() (mapnik::image_rgba8 & source_data); - + MAPNIK_VECTOR_INLINE std::string operator() (mapnik::image_gray8 & source_data); MAPNIK_VECTOR_INLINE std::string operator() (mapnik::image_gray8s & source_data); @@ -77,9 +77,9 @@ struct raster_clipper MAPNIK_VECTOR_INLINE std::string operator() (mapnik::image_gray32s & source_data); MAPNIK_VECTOR_INLINE std::string operator() (mapnik::image_gray32f & source_data); - + MAPNIK_VECTOR_INLINE std::string operator() (mapnik::image_gray64 & source_data); - + MAPNIK_VECTOR_INLINE std::string operator() (mapnik::image_gray64s & source_data); MAPNIK_VECTOR_INLINE std::string operator() (mapnik::image_gray64f & source_data); diff --git a/src/vector_tile_raster_clipper.ipp b/src/vector_tile_raster_clipper.ipp index 173cca61..deee8ab1 100644 --- a/src/vector_tile_raster_clipper.ipp +++ b/src/vector_tile_raster_clipper.ipp @@ -1,5 +1,5 @@ // mapnik -#include +#include #include #include #include @@ -37,7 +37,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_rgba8 else if ((raster_width_ == source_data.width()) && (raster_height_ == source_data.height())) { mapnik::demultiply_alpha(source_data); - return mapnik::save_to_string(source_data, image_format_); + return mapnik::save_to_string(source_data, image_format_); } else { @@ -65,7 +65,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_rgba8 renderer_type ren(dst_pixf); ren.copy_from(src_pixf,0,start_x_, start_y_); mapnik::demultiply_alpha(im_tile); - return mapnik::save_to_string(im_tile, image_format_); + return mapnik::save_to_string(im_tile, image_format_); } MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray8 & source_data) @@ -84,7 +84,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray8 else if ((raster_width_ == source_data.width()) && (raster_height_ == source_data.height())) { mapnik::image_any any(source_data); - return mapnik::save_to_string(any, image_format_); + return mapnik::save_to_string(any, image_format_); } else { @@ -110,7 +110,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray8 pixfmt_type dst_pixf(dst_buffer); renderer_type ren(dst_pixf); ren.copy_from(src_pixf,0,start_x_, start_y_); - return mapnik::save_to_string(im_tile, image_format_); + return mapnik::save_to_string(im_tile, image_format_); } MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray8s & source_data) @@ -129,7 +129,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray8 else if ((raster_width_ == source_data.width()) && (raster_height_ == source_data.height())) { mapnik::image_any any(source_data); - return mapnik::save_to_string(any, image_format_); + return mapnik::save_to_string(any, image_format_); } else { @@ -155,7 +155,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray8 pixfmt_type dst_pixf(dst_buffer); renderer_type ren(dst_pixf); ren.copy_from(src_pixf,0,start_x_, start_y_); - return mapnik::save_to_string(im_tile, image_format_); + return mapnik::save_to_string(im_tile, image_format_); } MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray16 & source_data) @@ -174,7 +174,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray1 else if ((raster_width_ == source_data.width()) && (raster_height_ == source_data.height())) { mapnik::image_any any(source_data); - return mapnik::save_to_string(any, image_format_); + return mapnik::save_to_string(any, image_format_); } else { @@ -200,7 +200,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray1 pixfmt_type dst_pixf(dst_buffer); renderer_type ren(dst_pixf); ren.copy_from(src_pixf,0,start_x_, start_y_); - return mapnik::save_to_string(im_tile, image_format_); + return mapnik::save_to_string(im_tile, image_format_); } MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray16s & source_data) @@ -219,7 +219,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray1 else if ((raster_width_ == source_data.width()) && (raster_height_ == source_data.height())) { mapnik::image_any any(source_data); - return mapnik::save_to_string(any, image_format_); + return mapnik::save_to_string(any, image_format_); } else { @@ -245,7 +245,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray1 pixfmt_type dst_pixf(dst_buffer); renderer_type ren(dst_pixf); ren.copy_from(src_pixf,0,start_x_, start_y_); - return mapnik::save_to_string(im_tile, image_format_); + return mapnik::save_to_string(im_tile, image_format_); } MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray32 & source_data) @@ -264,7 +264,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray3 else if ((raster_width_ == source_data.width()) && (raster_height_ == source_data.height())) { mapnik::image_any any(source_data); - return mapnik::save_to_string(any, image_format_); + return mapnik::save_to_string(any, image_format_); } else { @@ -290,7 +290,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray3 pixfmt_type dst_pixf(dst_buffer); renderer_type ren(dst_pixf); ren.copy_from(src_pixf,0,start_x_, start_y_); - return mapnik::save_to_string(im_tile, image_format_); + return mapnik::save_to_string(im_tile, image_format_); } MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray32s & source_data) @@ -309,7 +309,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray3 else if ((raster_width_ == source_data.width()) && (raster_height_ == source_data.height())) { mapnik::image_any any(source_data); - return mapnik::save_to_string(any, image_format_); + return mapnik::save_to_string(any, image_format_); } else { @@ -335,7 +335,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray3 pixfmt_type dst_pixf(dst_buffer); renderer_type ren(dst_pixf); ren.copy_from(src_pixf,0,start_x_, start_y_); - return mapnik::save_to_string(im_tile, image_format_); + return mapnik::save_to_string(im_tile, image_format_); } MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray32f & source_data) @@ -354,7 +354,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray3 else if ((raster_width_ == source_data.width()) && (raster_height_ == source_data.height())) { mapnik::image_any any(source_data); - return mapnik::save_to_string(any, image_format_); + return mapnik::save_to_string(any, image_format_); } else { @@ -380,7 +380,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray3 pixfmt_type dst_pixf(dst_buffer); renderer_type ren(dst_pixf); ren.copy_from(src_pixf,0,start_x_, start_y_); - return mapnik::save_to_string(im_tile, image_format_); + return mapnik::save_to_string(im_tile, image_format_); } MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray64 & source_data) @@ -399,7 +399,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray6 else if ((raster_width_ == source_data.width()) && (raster_height_ == source_data.height())) { mapnik::image_any any(source_data); - return mapnik::save_to_string(any, image_format_); + return mapnik::save_to_string(any, image_format_); } else { @@ -425,7 +425,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray6 pixfmt_type dst_pixf(dst_buffer); renderer_type ren(dst_pixf); ren.copy_from(src_pixf,0,start_x_, start_y_); - return mapnik::save_to_string(im_tile, image_format_); + return mapnik::save_to_string(im_tile, image_format_); } MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray64s & source_data) @@ -444,7 +444,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray6 else if ((raster_width_ == source_data.width()) && (raster_height_ == source_data.height())) { mapnik::image_any any(source_data); - return mapnik::save_to_string(any, image_format_); + return mapnik::save_to_string(any, image_format_); } else { @@ -470,7 +470,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray6 pixfmt_type dst_pixf(dst_buffer); renderer_type ren(dst_pixf); ren.copy_from(src_pixf,0,start_x_, start_y_); - return mapnik::save_to_string(im_tile, image_format_); + return mapnik::save_to_string(im_tile, image_format_); } MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray64f & source_data) @@ -489,7 +489,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray6 else if ((raster_width_ == source_data.width()) && (raster_height_ == source_data.height())) { mapnik::image_any any(source_data); - return mapnik::save_to_string(any, image_format_); + return mapnik::save_to_string(any, image_format_); } else { @@ -515,7 +515,7 @@ MAPNIK_VECTOR_INLINE std::string raster_clipper::operator() (mapnik::image_gray6 pixfmt_type dst_pixf(dst_buffer); renderer_type ren(dst_pixf); ren.copy_from(src_pixf,0,start_x_, start_y_); - return mapnik::save_to_string(im_tile, image_format_); + return mapnik::save_to_string(im_tile, image_format_); } } // end ns vector_tile_impl diff --git a/src/vector_tile_strategy.hpp b/src/vector_tile_strategy.hpp index 60b94336..c50f2425 100644 --- a/src/vector_tile_strategy.hpp +++ b/src/vector_tile_strategy.hpp @@ -20,7 +20,6 @@ #pragma GCC diagnostic push #include -#include "boost_geometry_adapters.hpp" #include #include #pragma GCC diagnostic pop @@ -91,7 +90,7 @@ struct vector_tile_strategy_proj boost::geometry::set<1>(p2, static_cast(y)); return true; } - + template inline P2 execute(P1 const& p1, bool & status) const { @@ -124,7 +123,7 @@ struct transform_visitor NextProcessor & next_; box2d const& target_clipping_extent_; - transform_visitor(TransformType const& tr, + transform_visitor(TransformType const& tr, box2d const& target_clipping_extent, NextProcessor & next) : tr_(tr), @@ -167,7 +166,7 @@ struct transform_visitor inline void operator() (mapnik::geometry::line_string const& geom) { mapnik::box2d geom_bbox = mapnik::geometry::envelope(geom); - if (!target_clipping_extent_.intersects(geom_bbox)) + if (!target_clipping_extent_.intersects(geom_bbox)) { return; } @@ -213,30 +212,17 @@ struct transform_visitor inline void operator() (mapnik::geometry::polygon const& geom) { - mapnik::box2d ext_bbox = mapnik::geometry::envelope(geom); - if (!target_clipping_extent_.intersects(ext_bbox)) - { - return; - } + bool exterior = true; mapbox::geometry::polygon new_geom; - mapbox::geometry::linear_ring exterior_ring; - exterior_ring.reserve(geom.exterior_ring.size()); - for (auto const& pt : geom.exterior_ring) + for (auto const& ring : geom) { - mapbox::geometry::point pt2; - if (tr_.apply(pt,pt2)) + mapnik::box2d ring_bbox = mapnik::geometry::envelope(ring); + if (!target_clipping_extent_.intersects(ring_bbox)) { - exterior_ring.push_back(std::move(pt2)); - } - } - new_geom.push_back(std::move(exterior_ring)); - for (auto const& ring : geom.interior_rings) - { - mapnik::box2d ring_bbox = mapnik::geometry::envelope(static_cast const&>(ring)); - if (!target_clipping_extent_.intersects(ring_bbox)) - { - continue; + if (exterior) return; + else continue; } + exterior = false; mapbox::geometry::linear_ring new_ring; new_ring.reserve(ring.size()); for (auto const& pt : ring) @@ -259,25 +245,14 @@ struct transform_visitor for (auto const& poly : geom) { mapnik::box2d ext_bbox = mapnik::geometry::envelope(poly); - if (!target_clipping_extent_.intersects(ext_bbox)) + if (!target_clipping_extent_.intersects(ext_bbox)) { continue; } mapbox::geometry::polygon new_poly; - mapbox::geometry::linear_ring exterior_ring; - exterior_ring.reserve(poly.exterior_ring.size()); - for (auto const& pt : poly.exterior_ring) - { - mapbox::geometry::point pt2; - if (tr_.apply(pt,pt2)) - { - exterior_ring.push_back(std::move(pt2)); - } - } - new_poly.push_back(std::move(exterior_ring)); - for (auto const& ring : poly.interior_rings) + for (auto const& ring : poly) { - mapnik::box2d ring_bbox = mapnik::geometry::envelope(static_cast const&>(ring)); + mapnik::box2d ring_bbox = mapnik::geometry::envelope(ring); if (!target_clipping_extent_.intersects(ring_bbox)) { continue; diff --git a/src/vector_tile_tile.hpp b/src/vector_tile_tile.hpp index 0bbf2e5c..09b50be7 100644 --- a/src/vector_tile_tile.hpp +++ b/src/vector_tile_tile.hpp @@ -8,7 +8,7 @@ #include // mapnik -#include +#include // std #include @@ -64,7 +64,7 @@ class tile { return buffer_.data(); } - + std::size_t size() const { return buffer_.size(); @@ -102,7 +102,7 @@ class tile ext.height(extra_height); return ext; } - + void append_to_string(std::string & str) const { str.append(buffer_); @@ -159,7 +159,7 @@ class tile { return empty_layers_; } - + std::vector const& get_layers() const { return layers_; @@ -183,7 +183,7 @@ class tile layers_set_.clear(); painted_layers_.clear(); } - + bool has_layer(std::string const& name) { auto itr = layers_set_.find(name); diff --git a/test/system/encode_and_datasource_decode.cpp b/test/system/encode_and_datasource_decode.cpp index 70134760..f96236d5 100644 --- a/test/system/encode_and_datasource_decode.cpp +++ b/test/system/encode_and_datasource_decode.cpp @@ -14,7 +14,6 @@ // mapnik-vector-tile #include "vector_tile_geometry_encoder_pbf.hpp" #include "vector_tile_datasource_pbf.hpp" -#include "convert_geometry_types.hpp" // vector tile #pragma GCC diagnostic push @@ -94,20 +93,18 @@ TEST_CASE("encoding and decoding with datasource simple polygon") mapnik::geometry::polygon geom; { mapnik::geometry::linear_ring ring; - ring.add_coord(168.267850,-24.576888); - ring.add_coord(167.982618,-24.697145); - ring.add_coord(168.114561,-24.783548); - ring.add_coord(168.267850,-24.576888); - ring.add_coord(168.267850,-24.576888); - geom.set_exterior_ring(std::move(ring)); + ring.emplace_back(168.267850,-24.576888); + ring.emplace_back(167.982618,-24.697145); + ring.emplace_back(168.114561,-24.783548); + ring.emplace_back(168.267850,-24.576888); + ring.emplace_back(168.267850,-24.576888); + geom.push_back(std::move(ring)); } unsigned path_multiplier = 16; mapnik::geometry::scale_rounding_strategy scale_strat(path_multiplier); mapnik::geometry::polygon geom2 = mapnik::geometry::transform(geom, scale_strat); - auto geom3 = mapnik::vector_tile_impl::mapnik_to_mapbox(geom2); - // encode geometry vector_tile::Tile tile; vector_tile::Tile_Layer * t_layer = tile.add_layers(); @@ -116,7 +113,7 @@ TEST_CASE("encoding and decoding with datasource simple polygon") std::int32_t y = 0; std::string feature_str; protozero::pbf_writer feature_writer(feature_str); - CHECK(mapnik::vector_tile_impl::encode_geometry_pbf(geom3, feature_writer, x, y)); + CHECK(mapnik::vector_tile_impl::encode_geometry_pbf(geom2, feature_writer, x, y)); t_feature->ParseFromString(feature_str); // test results diff --git a/test/system/processor_and_datasource.cpp b/test/system/processor_and_datasource.cpp index ac60ed91..2a7ce776 100644 --- a/test/system/processor_and_datasource.cpp +++ b/test/system/processor_and_datasource.cpp @@ -127,8 +127,8 @@ TEST_CASE("vector tile output -- layers outside extent") mapnik::context_ptr ctx = std::make_shared(); mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx,1)); mapnik::geometry::line_string g; - g.add_coord(-10,-10); - g.add_coord(-11,-11); + g.emplace_back(-10,-10); + g.emplace_back(-11,-11); feature->set_geometry(std::move(g)); mapnik::parameters params; params["type"] = "memory"; diff --git a/test/system/round_trip.cpp b/test/system/round_trip.cpp index 69e1c7c1..7c6757d1 100644 --- a/test/system/round_trip.cpp +++ b/test/system/round_trip.cpp @@ -79,8 +79,8 @@ TEST_CASE("vector tile multi_point encoding of actual multi_point") TEST_CASE("vector tile line_string encoding") { mapnik::geometry::line_string geom; - geom.add_coord(0,0); - geom.add_coord(100,100); + geom.emplace_back(0,0); + geom.emplace_back(100,100); mapnik::geometry::geometry new_geom = test_utils::round_trip(geom); std::string wkt; CHECK( test_utils::to_wkt(wkt, new_geom) ); @@ -93,8 +93,8 @@ TEST_CASE("vector tile multi_line_string encoding of single line_string") { mapnik::geometry::multi_line_string geom; mapnik::geometry::line_string line; - line.add_coord(0,0); - line.add_coord(100,100); + line.emplace_back(0,0); + line.emplace_back(100,100); geom.emplace_back(std::move(line)); mapnik::geometry::geometry new_geom = test_utils::round_trip(geom); std::string wkt; @@ -108,12 +108,12 @@ TEST_CASE("vector tile multi_line_string encoding of actual multi_line_string") { mapnik::geometry::multi_line_string geom; mapnik::geometry::line_string line; - line.add_coord(0,0); - line.add_coord(100,100); + line.emplace_back(0,0); + line.emplace_back(100,100); geom.emplace_back(std::move(line)); mapnik::geometry::line_string line2; - line2.add_coord(-10,-0); - line2.add_coord(-100,-100); + line2.emplace_back(-10,-0); + line2.emplace_back(-100,-100); geom.emplace_back(std::move(line2)); mapnik::geometry::geometry new_geom = test_utils::round_trip(geom); std::string wkt; @@ -126,11 +126,12 @@ TEST_CASE("vector tile multi_line_string encoding of actual multi_line_string") TEST_CASE("vector tile polygon encoding") { mapnik::geometry::polygon geom; - geom.exterior_ring.add_coord(0,0); - geom.exterior_ring.add_coord(0,10); - geom.exterior_ring.add_coord(-10,10); - geom.exterior_ring.add_coord(-10,0); - geom.exterior_ring.add_coord(0,0); + geom.emplace_back(); + geom.front().emplace_back(0,0); + geom.front().emplace_back(0,10); + geom.front().emplace_back(-10,10); + geom.front().emplace_back(-10,0); + geom.front().emplace_back(0,0); mapnik::geometry::geometry new_geom = test_utils::round_trip(geom); CHECK( !mapnik::geometry::is_empty(new_geom) ); CHECK( new_geom.is >() ); @@ -142,11 +143,12 @@ TEST_CASE("vector tile polygon encoding") TEST_CASE("vector tile multi_polygon encoding of single polygon") { mapnik::geometry::polygon poly; - poly.exterior_ring.add_coord(0,0); - poly.exterior_ring.add_coord(0,10); - poly.exterior_ring.add_coord(-10,10); - poly.exterior_ring.add_coord(-10,0); - poly.exterior_ring.add_coord(0,0); + poly.emplace_back(); + poly.front().emplace_back(0,0); + poly.front().emplace_back(0,10); + poly.front().emplace_back(-10,10); + poly.front().emplace_back(-10,0); + poly.front().emplace_back(0,0); mapnik::geometry::multi_polygon geom; geom.emplace_back(std::move(poly)); mapnik::geometry::geometry new_geom = test_utils::round_trip(geom); @@ -160,17 +162,19 @@ TEST_CASE("vector tile multi_polygon encoding of single polygon") TEST_CASE("vector tile multi_polygon with multipolygon union") { mapnik::geometry::polygon poly; - poly.exterior_ring.add_coord(0,0); - poly.exterior_ring.add_coord(0,10); - poly.exterior_ring.add_coord(-10,10); - poly.exterior_ring.add_coord(-10,0); - poly.exterior_ring.add_coord(0,0); + poly.emplace_back(); + poly.front().emplace_back(0,0); + poly.front().emplace_back(0,10); + poly.front().emplace_back(-10,10); + poly.front().emplace_back(-10,0); + poly.front().emplace_back(0,0); mapnik::geometry::polygon poly2; - poly2.exterior_ring.add_coord(0,0); - poly2.exterior_ring.add_coord(0,10); - poly2.exterior_ring.add_coord(-10,10); - poly2.exterior_ring.add_coord(-10,0); - poly2.exterior_ring.add_coord(0,0); + poly2.emplace_back(); + poly2.front().emplace_back(0,0); + poly2.front().emplace_back(0,10); + poly2.front().emplace_back(-10,10); + poly2.front().emplace_back(-10,0); + poly2.front().emplace_back(0,0); mapnik::geometry::multi_polygon geom; geom.emplace_back(std::move(poly)); geom.emplace_back(std::move(poly2)); @@ -185,17 +189,19 @@ TEST_CASE("vector tile multi_polygon with multipolygon union") TEST_CASE("vector tile multi_polygon with out multipolygon union") { mapnik::geometry::polygon poly; - poly.exterior_ring.add_coord(0,0); - poly.exterior_ring.add_coord(0,10); - poly.exterior_ring.add_coord(-10,10); - poly.exterior_ring.add_coord(-10,0); - poly.exterior_ring.add_coord(0,0); + poly.emplace_back(); + poly.front().emplace_back(0,0); + poly.front().emplace_back(0,10); + poly.front().emplace_back(-10,10); + poly.front().emplace_back(-10,0); + poly.front().emplace_back(0,0); mapnik::geometry::polygon poly2; - poly2.exterior_ring.add_coord(0,0); - poly2.exterior_ring.add_coord(0,10); - poly2.exterior_ring.add_coord(-10,10); - poly2.exterior_ring.add_coord(-10,0); - poly2.exterior_ring.add_coord(0,0); + poly2.emplace_back(); + poly2.front().emplace_back(0,0); + poly2.front().emplace_back(0,10); + poly2.front().emplace_back(-10,10); + poly2.front().emplace_back(-10,0); + poly2.front().emplace_back(0,0); mapnik::geometry::multi_polygon geom; geom.emplace_back(std::move(poly)); geom.emplace_back(std::move(poly2)); @@ -211,18 +217,20 @@ TEST_CASE("vector tile multi_polygon encoding of actual multi_polygon") { mapnik::geometry::multi_polygon geom; mapnik::geometry::polygon poly; - poly.exterior_ring.add_coord(0,0); - poly.exterior_ring.add_coord(0,10); - poly.exterior_ring.add_coord(-10,10); - poly.exterior_ring.add_coord(-10,0); - poly.exterior_ring.add_coord(0,0); + poly.emplace_back(); + poly.front().emplace_back(0,0); + poly.front().emplace_back(0,10); + poly.front().emplace_back(-10,10); + poly.front().emplace_back(-10,0); + poly.front().emplace_back(0,0); geom.emplace_back(std::move(poly)); mapnik::geometry::polygon poly2; - poly2.exterior_ring.add_coord(11,11); - poly2.exterior_ring.add_coord(11,21); - poly2.exterior_ring.add_coord(1,21); - poly2.exterior_ring.add_coord(1,11); - poly2.exterior_ring.add_coord(11,11); + poly2.emplace_back(); + poly2.front().emplace_back(11,11); + poly2.front().emplace_back(11,21); + poly2.front().emplace_back(1,21); + poly2.front().emplace_back(1,11); + poly2.front().emplace_back(11,11); geom.emplace_back(std::move(poly2)); mapnik::geometry::geometry new_geom = test_utils::round_trip(geom); CHECK( !mapnik::geometry::is_empty(new_geom) ); @@ -233,18 +241,20 @@ TEST_CASE("vector tile multi_polygon encoding overlapping multipolygons") { mapnik::geometry::multi_polygon geom; mapnik::geometry::polygon poly; - poly.exterior_ring.add_coord(0,0); - poly.exterior_ring.add_coord(0,10); - poly.exterior_ring.add_coord(-10,10); - poly.exterior_ring.add_coord(-10,0); - poly.exterior_ring.add_coord(0,0); + poly.emplace_back(); + poly.front().emplace_back(0,0); + poly.front().emplace_back(0,10); + poly.front().emplace_back(-10,10); + poly.front().emplace_back(-10,0); + poly.front().emplace_back(0,0); geom.emplace_back(std::move(poly)); mapnik::geometry::polygon poly2; - poly2.exterior_ring.add_coord(-5,5); - poly2.exterior_ring.add_coord(-5,15); - poly2.exterior_ring.add_coord(-15,15); - poly2.exterior_ring.add_coord(-15,5); - poly2.exterior_ring.add_coord(-5,5); + poly2.emplace_back(); + poly2.front().emplace_back(-5,5); + poly2.front().emplace_back(-5,15); + poly2.front().emplace_back(-15,15); + poly2.front().emplace_back(-15,5); + poly2.front().emplace_back(-5,5); geom.emplace_back(std::move(poly2)); mapnik::geometry::geometry new_geom = test_utils::round_trip(geom); CHECK( !mapnik::geometry::is_empty(new_geom) ); diff --git a/test/system/round_trip_fill_type.cpp b/test/system/round_trip_fill_type.cpp index 236fa228..995895ea 100644 --- a/test/system/round_trip_fill_type.cpp +++ b/test/system/round_trip_fill_type.cpp @@ -18,19 +18,19 @@ TEST_CASE("vector tile polygon even odd fill") 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.emplace_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.emplace_back(std::move(hole)); } mapnik::geometry::geometry new_geom = test_utils::round_trip(poly,0,mapnik::vector_tile_impl::even_odd_fill); std::string wkt; @@ -46,19 +46,19 @@ TEST_CASE("vector tile polygon non zero fill") 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.emplace_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.emplace_back(std::move(hole)); } mapnik::geometry::geometry new_geom = test_utils::round_trip(poly,0,mapnik::vector_tile_impl::non_zero_fill); std::string wkt; diff --git a/test/system/round_trip_simplification.cpp b/test/system/round_trip_simplification.cpp index 6466eab2..c9f72dcc 100644 --- a/test/system/round_trip_simplification.cpp +++ b/test/system/round_trip_simplification.cpp @@ -39,10 +39,10 @@ TEST_CASE("vector tile mulit_point correctly passed through simplification code TEST_CASE("vector tile line_string is simplified") { mapnik::geometry::line_string line; - line.add_coord(0,0); - line.add_coord(1,1); - line.add_coord(2,2); - line.add_coord(100,100); + line.emplace_back(0,0); + line.emplace_back(1,1); + line.emplace_back(2,2); + line.emplace_back(100,100); mapnik::geometry::geometry new_geom = test_utils::round_trip(line,500); std::string wkt; CHECK( test_utils::to_wkt(wkt, new_geom) ); @@ -57,10 +57,10 @@ TEST_CASE("vector tile multi_line_string is simplified") { mapnik::geometry::multi_line_string geom; mapnik::geometry::line_string line; - line.add_coord(0,0); - line.add_coord(1,1); - line.add_coord(2,2); - line.add_coord(100,100); + line.emplace_back(0,0); + line.emplace_back(1,1); + line.emplace_back(2,2); + line.emplace_back(100,100); geom.emplace_back(std::move(line)); mapnik::geometry::geometry new_geom = test_utils::round_trip(geom,500); std::string wkt; @@ -78,19 +78,19 @@ TEST_CASE("vector tile polygon is simplified") 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.emplace_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.emplace_back(std::move(hole)); } mapnik::geometry::geometry new_geom = test_utils::round_trip(poly,500); std::string wkt; @@ -106,19 +106,19 @@ TEST_CASE("vector tile mulit_polygon is simplified") 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.emplace_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.emplace_back(std::move(hole)); } multi_polygon mp; mp.push_back(poly); @@ -133,9 +133,9 @@ TEST_CASE("vector tile mulit_polygon is simplified") TEST_CASE("vector tile line_string is simplified when outside bounds", "should create vector tile with data" ) { mapnik::geometry::multi_line_string geom; mapnik::geometry::line_string line; - line.add_coord(-10000,0); - line.add_coord(-10000.1,0); - line.add_coord(100000,0); + line.emplace_back(-10000,0); + line.emplace_back(-10000.1,0); + line.emplace_back(100000,0); geom.emplace_back(std::move(line)); mapnik::geometry::geometry new_geom = test_utils::round_trip(geom,100); std::string wkt; diff --git a/test/utils/geometry_equal.hpp b/test/utils/geometry_equal.hpp index 65b0ee7e..226da66c 100644 --- a/test/utils/geometry_equal.hpp +++ b/test/utils/geometry_equal.hpp @@ -127,38 +127,51 @@ struct geometry_equal_visitor template void operator() (mapnik::geometry::line_string const& ls1, mapnik::geometry::line_string const& ls2) { - if (ls1.size() != ls2.size()) + using ct = typename mapnik::geometry::line_string::container_type; + (*this)(static_cast(ls1), static_cast(ls2)); + } + + template + void operator() (mapnik::geometry::polygon const& p1, mapnik::geometry::polygon const& p2) + { + if (p1.size() != p2.size()) { REQUIRE(false); } - for(auto const& p : zip_crange(ls1, ls2)) + for (auto const& p : zip_crange(p1, p2)) { - REQUIRE(p.template get<0>().x == Approx(p.template get<1>().x)); - REQUIRE(p.template get<0>().y == Approx(p.template get<1>().y)); + (*this)(p.template get<0>(), p.template get<1>()); } } template - void operator() (mapnik::geometry::polygon const& p1, mapnik::geometry::polygon const& p2) + void operator() (std::vector> const& ls1, std::vector> const& ls2) { - (*this)(static_cast const&>(p1.exterior_ring), static_cast const&>(p2.exterior_ring)); - - if (p1.interior_rings.size() != p2.interior_rings.size()) + if (ls1.size() != ls2.size()) { REQUIRE(false); } - for (auto const& p : zip_crange(p1.interior_rings, p2.interior_rings)) + for(auto const& p : zip_crange(ls1, ls2)) { - (*this)(static_cast const&>(p.template get<0>()),static_cast const&>(p.template get<1>())); + REQUIRE(p.template get<0>().x == Approx(p.template get<1>().x)); + REQUIRE(p.template get<0>().y == Approx(p.template get<1>().y)); } } + template + void operator() (mapnik::geometry::linear_ring const& mp1, mapnik::geometry::linear_ring const& mp2) + { + using ct = typename mapnik::geometry::linear_ring::container_type; + (*this)(static_cast(mp1), static_cast(mp2)); + } + template void operator() (mapnik::geometry::multi_point const& mp1, mapnik::geometry::multi_point const& mp2) { - (*this)(static_cast const&>(mp1), static_cast const&>(mp2)); + using ct = typename mapnik::geometry::multi_point::container_type; + (*this)(static_cast(mp1), static_cast(mp2)); } template diff --git a/test/vector_tile_projection.cpp b/test/vector_tile_projection.cpp index 3fcbcf49..98ef5816 100644 --- a/test/vector_tile_projection.cpp +++ b/test/vector_tile_projection.cpp @@ -1,7 +1,7 @@ #include "catch.hpp" #include -#include +#include #include #include #include "vector_tile_projection.hpp"