Skip to content

Commit 32020bd

Browse files
committed
Update to geometry v1.0.0 & geojson v0.4.3
1 parent 37ebe04 commit 32020bd

File tree

11 files changed

+79
-52
lines changed

11 files changed

+79
-52
lines changed

.mason

Submodule .mason updated 138 files

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ DEBUG_FLAGS ?= -g -O0 -DDEBUG
55
MASON ?= .mason/mason
66

77
VARIANT = variant 1.1.5
8-
GEOMETRY = geometry 0.9.3
9-
GEOJSON = geojson 0.4.2
8+
GEOMETRY = geometry 1.0.0
9+
GEOJSON = geojson 0.4.3
1010
GLFW = glfw 3.1.2
1111
GTEST = gtest 1.8.0
1212
RAPIDJSON = rapidjson 1.1.0

debug/debug.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ void drawLine(const T points) {
1818
}
1919

2020
struct DrawFeature {
21-
void operator()(const mapbox::geometry::point<int16_t>&) {
22-
}
21+
void operator()(const mapbox::geometry::empty&) {}
22+
23+
void operator()(const mapbox::geometry::point<int16_t>&) {}
2324

2425
void operator()(const mapbox::geometry::line_string<int16_t>& points) {
2526
drawLine(points);

include/mapbox/geojsonvt.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <mapbox/geojsonvt/types.hpp>
66
#include <mapbox/geojsonvt/wrap.hpp>
77

8+
#include <mapbox/feature.hpp>
9+
810
#include <chrono>
911
#include <cmath>
1012
#include <map>
@@ -14,8 +16,8 @@ namespace mapbox {
1416
namespace geojsonvt {
1517

1618
using geometry = mapbox::geometry::geometry<double>;
17-
using feature = mapbox::geometry::feature<double>;
18-
using feature_collection = mapbox::geometry::feature_collection<double>;
19+
using feature = mapbox::feature::feature<double>;
20+
using feature_collection = mapbox::feature::feature_collection<double>;
1921
using geometry_collection = mapbox::geometry::geometry_collection<double>;
2022
using geojson = mapbox::util::variant<geometry, feature, feature_collection>;
2123

@@ -93,7 +95,7 @@ class GeoJSONVT {
9395
public:
9496
const Options options;
9597

96-
GeoJSONVT(const mapbox::geometry::feature_collection<double>& features_,
98+
GeoJSONVT(const mapbox::feature::feature_collection<double>& features_,
9799
const Options& options_ = Options())
98100
: options(options_) {
99101

include/mapbox/geojsonvt/clip.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class clipper {
1616
const double k2;
1717
const bool lineMetrics;
1818

19+
vt_geometry operator()(const vt_empty& empty) const {
20+
return empty;
21+
}
22+
1923
vt_geometry operator()(const vt_point& point) const {
2024
return point;
2125
}

include/mapbox/geojsonvt/convert.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <mapbox/geojsonvt/simplify.hpp>
44
#include <mapbox/geojsonvt/types.hpp>
55
#include <mapbox/geometry.hpp>
6+
#include <mapbox/feature.hpp>
67

78
#include <algorithm>
89
#include <cmath>
@@ -15,6 +16,10 @@ struct project {
1516
const double tolerance;
1617
using result_type = vt_geometry;
1718

19+
vt_empty operator()(const geometry::empty& empty) {
20+
return empty;
21+
}
22+
1823
vt_point operator()(const geometry::point<double>& p) {
1924
const double sine = std::sin(p.y * M_PI / 180);
2025
const double x = p.x / 360 + 0.5;
@@ -93,13 +98,13 @@ struct project {
9398
}
9499
};
95100

96-
inline vt_features convert(const geometry::feature_collection<double>& features,
101+
inline vt_features convert(const feature::feature_collection<double>& features,
97102
const double tolerance, bool generateId) {
98103
vt_features projected;
99104
projected.reserve(features.size());
100105
uint64_t genId = 0;
101106
for (const auto& feature : features) {
102-
optional<identifier> featureId = feature.id;
107+
identifier featureId = feature.id;
103108
if (generateId) {
104109
featureId = { uint64_t {genId++} };
105110
}

include/mapbox/geojsonvt/tile.hpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace mapbox {
88
namespace geojsonvt {
99

1010
struct Tile {
11-
mapbox::geometry::feature_collection<int16_t> features;
11+
mapbox::feature::feature_collection<int16_t> features;
1212
uint32_t num_points = 0;
1313
uint32_t num_simplified = 0;
1414
};
@@ -68,14 +68,18 @@ class InternalTile {
6868
}
6969

7070
private:
71+
void addFeature(const vt_empty& empty, const property_map& props, const identifier& id) {
72+
tile.features.push_back({ transform(empty), props, id });
73+
}
74+
7175
void
72-
addFeature(const vt_point& point, const property_map& props, const optional<identifier>& id) {
76+
addFeature(const vt_point& point, const property_map& props, const identifier& id) {
7377
tile.features.push_back({ transform(point), props, id });
7478
}
7579

7680
void addFeature(const vt_line_string& line,
7781
const property_map& props,
78-
const optional<identifier>& id) {
82+
const identifier& id) {
7983
const auto new_line = transform(line);
8084
if (!new_line.empty()) {
8185
if (lineMetrics) {
@@ -90,15 +94,15 @@ class InternalTile {
9094

9195
void addFeature(const vt_polygon& polygon,
9296
const property_map& props,
93-
const optional<identifier>& id) {
97+
const identifier& id) {
9498
const auto new_polygon = transform(polygon);
9599
if (!new_polygon.empty())
96100
tile.features.push_back({ std::move(new_polygon), props, id });
97101
}
98102

99103
void addFeature(const vt_geometry_collection& collection,
100104
const property_map& props,
101-
const optional<identifier>& id) {
105+
const identifier& id) {
102106
for (const auto& geom : collection) {
103107
vt_geometry::visit(geom, [&](const auto& g) {
104108
// `this->` is a workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61636
@@ -108,7 +112,7 @@ class InternalTile {
108112
}
109113

110114
template <class T>
111-
void addFeature(const T& multi, const property_map& props, const optional<identifier>& id) {
115+
void addFeature(const T& multi, const property_map& props, const identifier& id) {
112116
const auto new_multi = transform(multi);
113117

114118
switch (new_multi.size()) {
@@ -123,6 +127,10 @@ class InternalTile {
123127
}
124128
}
125129

130+
mapbox::geometry::empty transform(const vt_empty& empty) {
131+
return empty;
132+
}
133+
126134
mapbox::geometry::point<int16_t> transform(const vt_point& p) {
127135
++tile.num_simplified;
128136
return { static_cast<int16_t>(::round((p.x * z2 - x) * extent)),

include/mapbox/geojsonvt/types.hpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <mapbox/geometry.hpp>
4+
#include <mapbox/feature.hpp>
45
#include <mapbox/variant.hpp>
56

67
#include <algorithm>
@@ -12,6 +13,8 @@ namespace mapbox {
1213
namespace geojsonvt {
1314
namespace detail {
1415

16+
using vt_empty = mapbox::geometry::empty;
17+
1518
struct vt_point : mapbox::geometry::point<double> {
1619
double z = 0.0; // simplification tolerance
1720

@@ -97,7 +100,8 @@ using vt_multi_polygon = std::vector<vt_polygon>;
97100

98101
struct vt_geometry_collection;
99102

100-
using vt_geometry = mapbox::util::variant<vt_point,
103+
using vt_geometry = mapbox::util::variant<vt_empty,
104+
vt_point,
101105
vt_line_string,
102106
vt_polygon,
103107
vt_multi_point,
@@ -107,15 +111,17 @@ using vt_geometry = mapbox::util::variant<vt_point,
107111

108112
struct vt_geometry_collection : std::vector<vt_geometry> {};
109113

110-
using property_map = mapbox::geometry::property_map;
111-
using identifier = mapbox::geometry::identifier;
112-
113-
template <class T>
114-
using optional = std::experimental::optional<T>;
114+
using null_value = mapbox::feature::null_value_t;
115+
using property_map = mapbox::feature::property_map;
116+
using identifier = mapbox::feature::identifier;
115117

116118
template <class T>
117119
struct vt_geometry_type;
118120

121+
template <>
122+
struct vt_geometry_type<geometry::empty> {
123+
using type = vt_empty;
124+
};
119125
template <>
120126
struct vt_geometry_type<geometry::point<double>> {
121127
using type = vt_point;
@@ -152,12 +158,12 @@ struct vt_geometry_type<geometry::geometry_collection<double>> {
152158
struct vt_feature {
153159
vt_geometry geometry;
154160
property_map properties;
155-
optional<identifier> id;
161+
identifier id;
156162

157163
mapbox::geometry::box<double> bbox = { { 2, 1 }, { -1, 0 } };
158164
uint32_t num_points = 0;
159165

160-
vt_feature(const vt_geometry& geom, const property_map& props, const optional<identifier>& id_)
166+
vt_feature(const vt_geometry& geom, const property_map& props, const identifier& id_)
161167
: geometry(geom), properties(props), id(id_) {
162168

163169
mapbox::geometry::for_each_point(geom, [&](const vt_point& p) {

test/test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ TEST(GetTile, Projection) {
337337
}
338338
}
339339

340-
std::map<std::string, mapbox::geometry::feature_collection<int16_t>>
340+
std::map<std::string, mapbox::feature::feature_collection<int16_t>>
341341
genTiles(const std::string& data, uint8_t maxZoom = 0, uint32_t maxPoints = 10000, bool lineMetrics = false) {
342342
Options options;
343343
options.maxZoom = 14;
@@ -348,7 +348,7 @@ genTiles(const std::string& data, uint8_t maxZoom = 0, uint32_t maxPoints = 1000
348348
const auto geojson = mapbox::geojson::parse(data);
349349
GeoJSONVT index{ geojson, options };
350350

351-
std::map<std::string, mapbox::geometry::feature_collection<int16_t>> output;
351+
std::map<std::string, mapbox::feature::feature_collection<int16_t>> output;
352352

353353
for (const auto& pair : index.getInternalTiles()) {
354354
auto& tile = pair.second;

test/util.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <mapbox/geojsonvt/tile.hpp>
1111
#include <mapbox/geojsonvt/types.hpp>
1212
#include <mapbox/geometry.hpp>
13+
#include <mapbox/geometry_io.hpp>
1314
#include <mapbox/variant_io.hpp>
1415
#include <rapidjson/document.h>
1516
#include <rapidjson/error/en.h>
@@ -50,12 +51,12 @@ inline void compareValues(const T& a, const T& b) {
5051
EXPECT_TRUE(a == b);
5152
}
5253

53-
void compareValues(const mapbox::geometry::value& a,
54-
const mapbox::geometry::value& b) {
54+
void compareValues(const mapbox::feature::value& a,
55+
const mapbox::feature::value& b) {
5556
if (a == b) return;
5657

57-
double a_as_double = mapbox::geometry::value::visit(a, ToDouble{});
58-
double b_as_double = mapbox::geometry::value::visit(b, ToDouble{});
58+
double a_as_double = mapbox::feature::value::visit(a, ToDouble{});
59+
double b_as_double = mapbox::feature::value::visit(b, ToDouble{});
5960
EXPECT_DOUBLE_EQ(a_as_double, b_as_double);
6061
}
6162

@@ -74,8 +75,8 @@ void compareMaps(const MapType& a, const MapType& b) {
7475

7576
} // namespace
7677

77-
bool operator==(const mapbox::geometry::feature<short>& a,
78-
const mapbox::geometry::feature<short>& b) {
78+
bool operator==(const mapbox::feature::feature<short>& a,
79+
const mapbox::feature::feature<short>& b) {
7980
// EXPECT_EQ(a.geometry, b.geometry);
8081
EXPECT_EQ(typeid(a.geometry), typeid(b.geometry));
8182
compareMaps(a.properties, b.properties);
@@ -84,8 +85,8 @@ bool operator==(const mapbox::geometry::feature<short>& a,
8485
return true;
8586
}
8687

87-
bool operator==(const mapbox::geometry::feature_collection<short>& a,
88-
const mapbox::geometry::feature_collection<short>& b) {
88+
bool operator==(const mapbox::feature::feature_collection<short>& a,
89+
const mapbox::feature::feature_collection<short>& b) {
8990
EXPECT_EQ(a.size(), b.size());
9091
if (a.size() == b.size()) {
9192
unsigned i = 0;
@@ -96,10 +97,10 @@ bool operator==(const mapbox::geometry::feature_collection<short>& a,
9697
return true;
9798
}
9899

99-
bool operator==(const std::map<std::string, mapbox::geometry::feature_collection<short>>& a,
100-
const std::map<std::string, mapbox::geometry::feature_collection<short>>& b) {
100+
bool operator==(const std::map<std::string, mapbox::feature::feature_collection<short>>& a,
101+
const std::map<std::string, mapbox::feature::feature_collection<short>>& b) {
101102
EXPECT_EQ(a.size(), b.size());
102-
typedef std::map<std::string, mapbox::geometry::feature_collection<short>>::const_iterator
103+
typedef std::map<std::string, mapbox::feature::feature_collection<short>>::const_iterator
103104
it_type;
104105
for (it_type it = a.begin(); it != a.end(); it++) {
105106
if (b.find(it->first) != b.end()) {
@@ -125,22 +126,22 @@ bool operator==(const mapbox::geojsonvt::Tile& a, const mapbox::geojsonvt::Tile&
125126
return true;
126127
}
127128

128-
mapbox::geometry::feature_collection<int16_t>
129+
mapbox::feature::feature_collection<int16_t>
129130
parseJSONTile(const rapidjson::GenericValue<rapidjson::UTF8<>, rapidjson::CrtAllocator>& tile) {
130-
mapbox::geometry::feature_collection<int16_t> features;
131+
mapbox::feature::feature_collection<int16_t> features;
131132
EXPECT_TRUE(tile.IsArray());
132133
for (rapidjson::SizeType k = 0; k < tile.Size(); ++k) {
133134
const auto& feature = tile[k];
134135

135-
mapbox::geometry::feature<short> feat{ mapbox::geometry::point<short>() };
136+
mapbox::feature::feature<short> feat{ mapbox::geometry::point<short>() };
136137

137138
if (feature.HasMember("tags") && feature["tags"].IsObject()) {
138139
const auto& tags = feature["tags"];
139140
for (auto jt = tags.MemberBegin(); jt != tags.MemberEnd(); jt++) {
140141
const std::string tagKey{ jt->name.GetString(), jt->name.GetStringLength() };
141142
switch (jt->value.GetType()) {
142143
case rapidjson::kNullType:
143-
feat.properties.emplace(tagKey, mapbox::geometry::null_value);
144+
feat.properties.emplace(tagKey, mapbox::feature::null_value);
144145
break;
145146
case rapidjson::kFalseType:
146147
feat.properties.emplace(tagKey, false);
@@ -247,7 +248,7 @@ parseJSONTile(const rapidjson::GenericValue<rapidjson::UTF8<>, rapidjson::CrtAll
247248
return features;
248249
}
249250

250-
mapbox::geometry::feature_collection<int16_t> parseJSONTile(const std::string& data) {
251+
mapbox::feature::feature_collection<int16_t> parseJSONTile(const std::string& data) {
251252
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> d;
252253
d.Parse<0>(data.c_str());
253254

@@ -260,9 +261,9 @@ mapbox::geometry::feature_collection<int16_t> parseJSONTile(const std::string& d
260261
return parseJSONTile(d);
261262
}
262263

263-
std::map<std::string, mapbox::geometry::feature_collection<int16_t>>
264+
std::map<std::string, mapbox::feature::feature_collection<int16_t>>
264265
parseJSONTiles(const std::string& data) {
265-
std::map<std::string, mapbox::geometry::feature_collection<int16_t>> result;
266+
std::map<std::string, mapbox::feature::feature_collection<int16_t>> result;
266267
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> d;
267268
d.Parse<0>(data.c_str());
268269

test/util.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ namespace mapbox {
1010
namespace geojsonvt {
1111

1212
std::string loadFile(const std::string& filename);
13-
mapbox::geometry::feature_collection<int16_t> parseJSONTile(const std::string& data);
14-
std::map<std::string, mapbox::geometry::feature_collection<int16_t>>
13+
mapbox::feature::feature_collection<int16_t> parseJSONTile(const std::string& data);
14+
std::map<std::string, mapbox::feature::feature_collection<int16_t>>
1515
parseJSONTiles(const std::string& data);
16-
bool operator==(const mapbox::geometry::feature<short>& a,
17-
const mapbox::geometry::feature<short>& b);
18-
bool operator==(const mapbox::geometry::feature_collection<short>& a,
19-
const mapbox::geometry::feature_collection<short>& b);
20-
bool operator==(const std::map<std::string, mapbox::geometry::feature_collection<short>>& a,
21-
const std::map<std::string, mapbox::geometry::feature_collection<short>>& b);
16+
bool operator==(const mapbox::feature::feature<short>& a,
17+
const mapbox::feature::feature<short>& b);
18+
bool operator==(const mapbox::feature::feature_collection<short>& a,
19+
const mapbox::feature::feature_collection<short>& b);
20+
bool operator==(const std::map<std::string, mapbox::feature::feature_collection<short>>& a,
21+
const std::map<std::string, mapbox::feature::feature_collection<short>>& b);
2222
bool operator==(const mapbox::geojsonvt::Tile& a, const mapbox::geojsonvt::Tile& b);
2323

2424
namespace detail {

0 commit comments

Comments
 (0)