Skip to content

Commit

Permalink
Add feature type
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Apr 30, 2016
1 parent ae3874f commit 465bfe8
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
10 changes: 10 additions & 0 deletions include/mapbox/geometry.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <mapbox/geometry/point.hpp>
#include <mapbox/geometry/line_string.hpp>
#include <mapbox/geometry/polygon.hpp>
#include <mapbox/geometry/multi_point.hpp>
#include <mapbox/geometry/multi_line_string.hpp>
#include <mapbox/geometry/multi_polygon.hpp>
#include <mapbox/geometry/geometry.hpp>
#include <mapbox/geometry/feature.hpp>

This comment has been minimized.

Copy link
@artemp

artemp May 3, 2016

Contributor

@jfirebaugh - why mixing feature concept into geometry ? I'd imagine including geometry.hpp shouldn't pull feature.hpp.

43 changes: 43 additions & 0 deletions include/mapbox/geometry/feature.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include <mapbox/geometry/geometry.hpp>

#include <mapbox/variant.hpp>

#include <cstdint>
#include <string>
#include <vector>
#include <unordered_map>

namespace mapbox { namespace geometry {

struct value;

using value_base = mapbox::util::variant<bool, int64_t, uint64_t, double, std::string,
mapbox::util::recursive_wrapper<std::vector<value>>,
mapbox::util::recursive_wrapper<std::unordered_map<std::string, value>>>;

struct value : value_base
{
using value_base::value_base;
};

template <class T>
struct feature
{
using geometry_type = mapbox::geometry::geometry<T>; // Fully qualified to avoid GCC -fpermissive error.
using property_map = std::unordered_map<std::string, value>;

geometry_type geometry;
property_map properties {};
};

template <class T, template <typename...> class Cont = std::vector>
struct feature_collection : Cont<feature<T>>
{
using feature_type = feature<T>;
using container_type = Cont<feature_type>;
using container_type::container_type;
};

}}
15 changes: 14 additions & 1 deletion tests/test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <mapbox/geometry/geometry.hpp>
#include <mapbox/geometry.hpp>

#include <cassert>

Expand Down Expand Up @@ -76,6 +76,17 @@ static void testGeometryCollection() {
assert(gc1.size() == 0);
}

static void testFeature() {
feature<double> pf { point<double>() };
assert(pf.geometry.is<point<double>>());
assert(pf.properties.size() == 0);
}

static void testFeatureCollection() {
feature_collection<double> fc1;
assert(fc1.size() == 0);
}

int main() {
testPoint();
testMultiPoint();
Expand All @@ -85,5 +96,7 @@ int main() {
testMultiPolygon();
testGeometry();
testGeometryCollection();
testFeature();
testFeatureCollection();
return 0;
}

0 comments on commit 465bfe8

Please sign in to comment.