| 1 | #include <boost/geometry.hpp>
|
|---|
| 2 | #include <boost/range/iterator_range_core.hpp>
|
|---|
| 3 |
|
|---|
| 4 | #include <vector>
|
|---|
| 5 |
|
|---|
| 6 | struct point {
|
|---|
| 7 | double x;
|
|---|
| 8 | double y;
|
|---|
| 9 | };
|
|---|
| 10 |
|
|---|
| 11 | using ring = std::vector<point>;
|
|---|
| 12 | using polygon = std::vector<ring>;
|
|---|
| 13 |
|
|---|
| 14 | namespace boost {
|
|---|
| 15 | namespace geometry {
|
|---|
| 16 | namespace traits {
|
|---|
| 17 |
|
|---|
| 18 | template <>
|
|---|
| 19 | struct tag<point>
|
|---|
| 20 | {
|
|---|
| 21 | using type = point_tag;
|
|---|
| 22 | };
|
|---|
| 23 |
|
|---|
| 24 | template <>
|
|---|
| 25 | struct coordinate_type<point>
|
|---|
| 26 | {
|
|---|
| 27 | using type = double;
|
|---|
| 28 | };
|
|---|
| 29 |
|
|---|
| 30 | template <>
|
|---|
| 31 | struct coordinate_system<point>
|
|---|
| 32 | {
|
|---|
| 33 | using type = boost::geometry::cs::cartesian;
|
|---|
| 34 | };
|
|---|
| 35 |
|
|---|
| 36 | template <>
|
|---|
| 37 | struct dimension<point>
|
|---|
| 38 | : boost::mpl::int_<2>
|
|---|
| 39 | {
|
|---|
| 40 | };
|
|---|
| 41 |
|
|---|
| 42 | template <>
|
|---|
| 43 | struct 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 |
|
|---|
| 56 | template <>
|
|---|
| 57 | struct 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 |
|
|---|
| 70 | template <>
|
|---|
| 71 | struct tag<ring>
|
|---|
| 72 | {
|
|---|
| 73 | using type = ring_tag;
|
|---|
| 74 | };
|
|---|
| 75 |
|
|---|
| 76 | template <>
|
|---|
| 77 | struct tag<polygon>
|
|---|
| 78 | {
|
|---|
| 79 | using type = polygon_tag;
|
|---|
| 80 | };
|
|---|
| 81 |
|
|---|
| 82 | template <>
|
|---|
| 83 | struct ring_mutable_type<polygon>
|
|---|
| 84 | {
|
|---|
| 85 | using type = ring&;
|
|---|
| 86 | };
|
|---|
| 87 |
|
|---|
| 88 | template <>
|
|---|
| 89 | struct ring_const_type<polygon>
|
|---|
| 90 | {
|
|---|
| 91 | using type = ring const&;
|
|---|
| 92 | };
|
|---|
| 93 |
|
|---|
| 94 | template <>
|
|---|
| 95 | struct interior_mutable_type<polygon>
|
|---|
| 96 | {
|
|---|
| 97 | using type = boost::iterator_range<typename polygon::iterator>;
|
|---|
| 98 | };
|
|---|
| 99 |
|
|---|
| 100 | template <>
|
|---|
| 101 | struct interior_const_type<polygon>
|
|---|
| 102 | {
|
|---|
| 103 | using type = boost::iterator_range<typename polygon::const_iterator>;
|
|---|
| 104 | };
|
|---|
| 105 |
|
|---|
| 106 | template <>
|
|---|
| 107 | struct 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 |
|
|---|
| 120 | template <>
|
|---|
| 121 | struct 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 |
|
|---|
| 138 | void testBoost() {
|
|---|
| 139 | polygon a;
|
|---|
| 140 | polygon b;
|
|---|
| 141 | std::vector<polygon> result;
|
|---|
| 142 | boost::geometry::intersection(a, b, result);
|
|---|
| 143 | }
|
|---|