Ticket #12305: boost.cpp

File boost.cpp, 2.0 KB (added by anonymous, 6 years ago)
Line 
1#include <boost/geometry.hpp>
2#include <boost/range/iterator_range_core.hpp>
3
4#include <vector>
5
6struct point {
7 double x;
8 double y;
9};
10
11using ring = std::vector<point>;
12using polygon = std::vector<ring>;
13
14namespace boost {
15namespace geometry {
16namespace traits {
17
18template <>
19struct tag<point>
20{
21 using type = point_tag;
22};
23
24template <>
25struct coordinate_type<point>
26{
27 using type = double;
28};
29
30template <>
31struct coordinate_system<point>
32{
33 using type = boost::geometry::cs::cartesian;
34};
35
36template <>
37struct dimension<point>
38 : boost::mpl::int_<2>
39{
40};
41
42template <>
43struct access<point, 0>
44{
45 static double get(point const& p)
46 {
47 return p.x;
48 }
49
50 static void set(point& p, double x)
51 {
52 p.x = x;
53 }
54};
55
56template <>
57struct access<point, 1>
58{
59 static double get(point const& p)
60 {
61 return p.y;
62 }
63
64 static void set(point& p, double y)
65 {
66 p.y = y;
67 }
68};
69
70template <>
71struct tag<ring>
72{
73 using type = ring_tag;
74};
75
76template <>
77struct tag<polygon>
78{
79 using type = polygon_tag;
80};
81
82template <>
83struct ring_mutable_type<polygon>
84{
85 using type = ring&;
86};
87
88template <>
89struct ring_const_type<polygon>
90{
91 using type = ring const&;
92};
93
94template <>
95struct interior_mutable_type<polygon>
96{
97 using type = boost::iterator_range<typename polygon::iterator>;
98};
99
100template <>
101struct interior_const_type<polygon>
102{
103 using type = boost::iterator_range<typename polygon::const_iterator>;
104};
105
106template <>
107struct exterior_ring<polygon>
108{
109 static auto& get(polygon& p)
110 {
111 return p.at(0);
112 }
113
114 static auto const& get(polygon const& p)
115 {
116 return p.at(0);
117 }
118};
119
120template <>
121struct interior_rings<polygon >
122{
123 static auto get(polygon& p)
124 {
125 return boost::make_iterator_range(p.begin() + 1, p.end());
126 }
127
128 static auto get(polygon const& p)
129 {
130 return boost::make_iterator_range(p.begin() + 1, p.end());
131 }
132};
133
134}
135}
136}
137
138void testBoost() {
139 polygon a;
140 polygon b;
141 std::vector<polygon> result;
142 boost::geometry::intersection(a, b, result);
143}