diff --git a/.mason b/.mason index e47f5f5..9e7f1d8 160000 --- a/.mason +++ b/.mason @@ -1 +1 @@ -Subproject commit e47f5f5a0c75e9ffab17f08e4982abf9f389caa7 +Subproject commit 9e7f1d8d54ac6c60d09b9c4744d20dbfbc7bc860 diff --git a/Makefile b/Makefile index 23b2e4c..be11105 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ DEBUG_FLAGS ?= -g -O0 -DDEBUG MASON ?= .mason/mason VARIANT = variant 1.1.5 -GEOMETRY = geometry 0.9.3 -GEOJSON = geojson 0.4.2 +GEOMETRY = geometry 1.0.0 +GEOJSON = geojson 0.4.3 GLFW = glfw 3.1.2 GTEST = gtest 1.8.0 RAPIDJSON = rapidjson 1.1.0 diff --git a/debug/debug.cpp b/debug/debug.cpp index ff713f0..20f1f23 100644 --- a/debug/debug.cpp +++ b/debug/debug.cpp @@ -18,8 +18,9 @@ void drawLine(const T points) { } struct DrawFeature { - void operator()(const mapbox::geometry::point&) { - } + void operator()(const mapbox::geometry::empty&) {} + + void operator()(const mapbox::geometry::point&) {} void operator()(const mapbox::geometry::line_string& points) { drawLine(points); diff --git a/include/mapbox/geojsonvt.hpp b/include/mapbox/geojsonvt.hpp index c317817..80ac432 100644 --- a/include/mapbox/geojsonvt.hpp +++ b/include/mapbox/geojsonvt.hpp @@ -5,6 +5,8 @@ #include #include +#include + #include #include #include @@ -14,8 +16,8 @@ namespace mapbox { namespace geojsonvt { using geometry = mapbox::geometry::geometry; -using feature = mapbox::geometry::feature; -using feature_collection = mapbox::geometry::feature_collection; +using feature = mapbox::feature::feature; +using feature_collection = mapbox::feature::feature_collection; using geometry_collection = mapbox::geometry::geometry_collection; using geojson = mapbox::util::variant; @@ -93,7 +95,7 @@ class GeoJSONVT { public: const Options options; - GeoJSONVT(const mapbox::geometry::feature_collection& features_, + GeoJSONVT(const mapbox::feature::feature_collection& features_, const Options& options_ = Options()) : options(options_) { diff --git a/include/mapbox/geojsonvt/clip.hpp b/include/mapbox/geojsonvt/clip.hpp index 07884e9..2ffec9a 100644 --- a/include/mapbox/geojsonvt/clip.hpp +++ b/include/mapbox/geojsonvt/clip.hpp @@ -16,6 +16,10 @@ class clipper { const double k2; const bool lineMetrics; + vt_geometry operator()(const vt_empty& empty) const { + return empty; + } + vt_geometry operator()(const vt_point& point) const { return point; } diff --git a/include/mapbox/geojsonvt/convert.hpp b/include/mapbox/geojsonvt/convert.hpp index 65b3bd4..3090082 100644 --- a/include/mapbox/geojsonvt/convert.hpp +++ b/include/mapbox/geojsonvt/convert.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -15,6 +16,10 @@ struct project { const double tolerance; using result_type = vt_geometry; + vt_empty operator()(const geometry::empty& empty) { + return empty; + } + vt_point operator()(const geometry::point& p) { const double sine = std::sin(p.y * M_PI / 180); const double x = p.x / 360 + 0.5; @@ -93,13 +98,13 @@ struct project { } }; -inline vt_features convert(const geometry::feature_collection& features, +inline vt_features convert(const feature::feature_collection& features, const double tolerance, bool generateId) { vt_features projected; projected.reserve(features.size()); uint64_t genId = 0; for (const auto& feature : features) { - optional featureId = feature.id; + identifier featureId = feature.id; if (generateId) { featureId = { uint64_t {genId++} }; } diff --git a/include/mapbox/geojsonvt/tile.hpp b/include/mapbox/geojsonvt/tile.hpp index 53f6c15..2c75c54 100644 --- a/include/mapbox/geojsonvt/tile.hpp +++ b/include/mapbox/geojsonvt/tile.hpp @@ -8,7 +8,7 @@ namespace mapbox { namespace geojsonvt { struct Tile { - mapbox::geometry::feature_collection features; + mapbox::feature::feature_collection features; uint32_t num_points = 0; uint32_t num_simplified = 0; }; @@ -68,14 +68,18 @@ class InternalTile { } private: + void addFeature(const vt_empty& empty, const property_map& props, const identifier& id) { + tile.features.push_back({ transform(empty), props, id }); + } + void - addFeature(const vt_point& point, const property_map& props, const optional& id) { + addFeature(const vt_point& point, const property_map& props, const identifier& id) { tile.features.push_back({ transform(point), props, id }); } void addFeature(const vt_line_string& line, const property_map& props, - const optional& id) { + const identifier& id) { const auto new_line = transform(line); if (!new_line.empty()) { if (lineMetrics) { @@ -90,7 +94,7 @@ class InternalTile { void addFeature(const vt_polygon& polygon, const property_map& props, - const optional& id) { + const identifier& id) { const auto new_polygon = transform(polygon); if (!new_polygon.empty()) tile.features.push_back({ std::move(new_polygon), props, id }); @@ -98,7 +102,7 @@ class InternalTile { void addFeature(const vt_geometry_collection& collection, const property_map& props, - const optional& id) { + const identifier& id) { for (const auto& geom : collection) { vt_geometry::visit(geom, [&](const auto& g) { // `this->` is a workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61636 @@ -108,7 +112,7 @@ class InternalTile { } template - void addFeature(const T& multi, const property_map& props, const optional& id) { + void addFeature(const T& multi, const property_map& props, const identifier& id) { const auto new_multi = transform(multi); switch (new_multi.size()) { @@ -123,6 +127,10 @@ class InternalTile { } } + mapbox::geometry::empty transform(const vt_empty& empty) { + return empty; + } + mapbox::geometry::point transform(const vt_point& p) { ++tile.num_simplified; return { static_cast(::round((p.x * z2 - x) * extent)), diff --git a/include/mapbox/geojsonvt/types.hpp b/include/mapbox/geojsonvt/types.hpp index 3bf7ae3..e13c99e 100644 --- a/include/mapbox/geojsonvt/types.hpp +++ b/include/mapbox/geojsonvt/types.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -12,6 +13,8 @@ namespace mapbox { namespace geojsonvt { namespace detail { +using vt_empty = mapbox::geometry::empty; + struct vt_point : mapbox::geometry::point { double z = 0.0; // simplification tolerance @@ -97,7 +100,8 @@ using vt_multi_polygon = std::vector; struct vt_geometry_collection; -using vt_geometry = mapbox::util::variant {}; -using property_map = mapbox::geometry::property_map; -using identifier = mapbox::geometry::identifier; - -template -using optional = std::experimental::optional; +using null_value = mapbox::feature::null_value_t; +using property_map = mapbox::feature::property_map; +using identifier = mapbox::feature::identifier; template struct vt_geometry_type; +template <> +struct vt_geometry_type { + using type = vt_empty; +}; template <> struct vt_geometry_type> { using type = vt_point; @@ -152,12 +158,12 @@ struct vt_geometry_type> { struct vt_feature { vt_geometry geometry; property_map properties; - optional id; + identifier id; mapbox::geometry::box bbox = { { 2, 1 }, { -1, 0 } }; uint32_t num_points = 0; - vt_feature(const vt_geometry& geom, const property_map& props, const optional& id_) + vt_feature(const vt_geometry& geom, const property_map& props, const identifier& id_) : geometry(geom), properties(props), id(id_) { mapbox::geometry::for_each_point(geom, [&](const vt_point& p) { diff --git a/test/test.cpp b/test/test.cpp index 1b1b4e0..e884309 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -337,7 +337,7 @@ TEST(GetTile, Projection) { } } -std::map> +std::map> genTiles(const std::string& data, uint8_t maxZoom = 0, uint32_t maxPoints = 10000, bool lineMetrics = false) { Options options; options.maxZoom = 14; @@ -348,7 +348,7 @@ genTiles(const std::string& data, uint8_t maxZoom = 0, uint32_t maxPoints = 1000 const auto geojson = mapbox::geojson::parse(data); GeoJSONVT index{ geojson, options }; - std::map> output; + std::map> output; for (const auto& pair : index.getInternalTiles()) { auto& tile = pair.second; diff --git a/test/util.cpp b/test/util.cpp index 599be61..c4066f4 100644 --- a/test/util.cpp +++ b/test/util.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -50,12 +51,12 @@ inline void compareValues(const T& a, const T& b) { EXPECT_TRUE(a == b); } -void compareValues(const mapbox::geometry::value& a, - const mapbox::geometry::value& b) { +void compareValues(const mapbox::feature::value& a, + const mapbox::feature::value& b) { if (a == b) return; - double a_as_double = mapbox::geometry::value::visit(a, ToDouble{}); - double b_as_double = mapbox::geometry::value::visit(b, ToDouble{}); + double a_as_double = mapbox::feature::value::visit(a, ToDouble{}); + double b_as_double = mapbox::feature::value::visit(b, ToDouble{}); EXPECT_DOUBLE_EQ(a_as_double, b_as_double); } @@ -74,8 +75,8 @@ void compareMaps(const MapType& a, const MapType& b) { } // namespace -bool operator==(const mapbox::geometry::feature& a, - const mapbox::geometry::feature& b) { +bool operator==(const mapbox::feature::feature& a, + const mapbox::feature::feature& b) { // EXPECT_EQ(a.geometry, b.geometry); EXPECT_EQ(typeid(a.geometry), typeid(b.geometry)); compareMaps(a.properties, b.properties); @@ -84,8 +85,8 @@ bool operator==(const mapbox::geometry::feature& a, return true; } -bool operator==(const mapbox::geometry::feature_collection& a, - const mapbox::geometry::feature_collection& b) { +bool operator==(const mapbox::feature::feature_collection& a, + const mapbox::feature::feature_collection& b) { EXPECT_EQ(a.size(), b.size()); if (a.size() == b.size()) { unsigned i = 0; @@ -96,10 +97,10 @@ bool operator==(const mapbox::geometry::feature_collection& a, return true; } -bool operator==(const std::map>& a, - const std::map>& b) { +bool operator==(const std::map>& a, + const std::map>& b) { EXPECT_EQ(a.size(), b.size()); - typedef std::map>::const_iterator + typedef std::map>::const_iterator it_type; for (it_type it = a.begin(); it != a.end(); it++) { if (b.find(it->first) != b.end()) { @@ -125,14 +126,14 @@ bool operator==(const mapbox::geojsonvt::Tile& a, const mapbox::geojsonvt::Tile& return true; } -mapbox::geometry::feature_collection +mapbox::feature::feature_collection parseJSONTile(const rapidjson::GenericValue, rapidjson::CrtAllocator>& tile) { - mapbox::geometry::feature_collection features; + mapbox::feature::feature_collection features; EXPECT_TRUE(tile.IsArray()); for (rapidjson::SizeType k = 0; k < tile.Size(); ++k) { const auto& feature = tile[k]; - mapbox::geometry::feature feat{ mapbox::geometry::point() }; + mapbox::feature::feature feat{ mapbox::geometry::point() }; if (feature.HasMember("tags") && feature["tags"].IsObject()) { const auto& tags = feature["tags"]; @@ -140,7 +141,7 @@ parseJSONTile(const rapidjson::GenericValue, rapidjson::CrtAll const std::string tagKey{ jt->name.GetString(), jt->name.GetStringLength() }; switch (jt->value.GetType()) { case rapidjson::kNullType: - feat.properties.emplace(tagKey, mapbox::geometry::null_value); + feat.properties.emplace(tagKey, mapbox::feature::null_value); break; case rapidjson::kFalseType: feat.properties.emplace(tagKey, false); @@ -247,7 +248,7 @@ parseJSONTile(const rapidjson::GenericValue, rapidjson::CrtAll return features; } -mapbox::geometry::feature_collection parseJSONTile(const std::string& data) { +mapbox::feature::feature_collection parseJSONTile(const std::string& data) { rapidjson::GenericDocument, rapidjson::CrtAllocator> d; d.Parse<0>(data.c_str()); @@ -260,9 +261,9 @@ mapbox::geometry::feature_collection parseJSONTile(const std::string& d return parseJSONTile(d); } -std::map> +std::map> parseJSONTiles(const std::string& data) { - std::map> result; + std::map> result; rapidjson::GenericDocument, rapidjson::CrtAllocator> d; d.Parse<0>(data.c_str()); diff --git a/test/util.hpp b/test/util.hpp index cfc6308..d4f9dba 100644 --- a/test/util.hpp +++ b/test/util.hpp @@ -10,15 +10,15 @@ namespace mapbox { namespace geojsonvt { std::string loadFile(const std::string& filename); -mapbox::geometry::feature_collection parseJSONTile(const std::string& data); -std::map> +mapbox::feature::feature_collection parseJSONTile(const std::string& data); +std::map> parseJSONTiles(const std::string& data); -bool operator==(const mapbox::geometry::feature& a, - const mapbox::geometry::feature& b); -bool operator==(const mapbox::geometry::feature_collection& a, - const mapbox::geometry::feature_collection& b); -bool operator==(const std::map>& a, - const std::map>& b); +bool operator==(const mapbox::feature::feature& a, + const mapbox::feature::feature& b); +bool operator==(const mapbox::feature::feature_collection& a, + const mapbox::feature::feature_collection& b); +bool operator==(const std::map>& a, + const std::map>& b); bool operator==(const mapbox::geojsonvt::Tile& a, const mapbox::geojsonvt::Tile& b); namespace detail {