1 | #pragma once |
---|---|
2 | |
3 | #include <mapbox/geometry/geometry.hpp> |
4 | #include <mapbox/geometry/point_arithmetic.hpp> |
5 | #include <mapbox/geometry/for_each_point.hpp> |
6 | |
7 | namespace mbgl { |
8 | |
9 | enum class FeatureType : uint8_t { |
10 | Unknown = 0, |
11 | Point = 1, |
12 | LineString = 2, |
13 | Polygon = 3 |
14 | }; |
15 | |
16 | template <class T> |
17 | using Point = mapbox::geometry::point<T>; |
18 | |
19 | template <class T> |
20 | using LineString = mapbox::geometry::line_string<T>; |
21 | |
22 | template <class T> |
23 | using Polygon = mapbox::geometry::polygon<T>; |
24 | |
25 | template <class T> |
26 | using MultiPoint = mapbox::geometry::multi_point<T>; |
27 | |
28 | template <class T> |
29 | using MultiLineString = mapbox::geometry::multi_line_string<T>; |
30 | |
31 | template <class T> |
32 | using MultiPolygon = mapbox::geometry::multi_polygon<T>; |
33 | |
34 | template <class T> |
35 | using LinearRing = mapbox::geometry::linear_ring<T>; |
36 | |
37 | template <class T> |
38 | using Geometry = mapbox::geometry::geometry<T>; |
39 | |
40 | template <class S, class T> |
41 | Point<S> convertPoint(const Point<T>& p) { |
42 | return Point<S>(p.x, p.y); |
43 | } |
44 | |
45 | struct ToFeatureType { |
46 | template <class T> |
47 | FeatureType operator()(const Point<T> &) const { return FeatureType::Point; } |
48 | template <class T> |
49 | FeatureType operator()(const MultiPoint<T> &) const { return FeatureType::Point; } |
50 | template <class T> |
51 | FeatureType operator()(const LineString<T> &) const { return FeatureType::LineString; } |
52 | template <class T> |
53 | FeatureType operator()(const MultiLineString<T> &) const { return FeatureType::LineString; } |
54 | template <class T> |
55 | FeatureType operator()(const Polygon<T> &) const { return FeatureType::Polygon; } |
56 | template <class T> |
57 | FeatureType operator()(const MultiPolygon<T> &) const { return FeatureType::Polygon; } |
58 | template <class T> |
59 | FeatureType operator()(const mapbox::geometry::geometry_collection<T> &) const { return FeatureType::Unknown; } |
60 | }; |
61 | |
62 | template <class T, typename F> |
63 | auto forEachPoint(const Geometry<T>& g, F f) { |
64 | mapbox::geometry::for_each_point(g, f); |
65 | } |
66 | |
67 | } // namespace mbgl |
68 |