Chris@16
|
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
|
Chris@16
|
2
|
Chris@16
|
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
Chris@16
|
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
|
Chris@16
|
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
|
Chris@101
|
6 // Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
|
Chris@16
|
7
|
Chris@16
|
8 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
Chris@16
|
9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
Chris@16
|
10
|
Chris@16
|
11 // Use, modification and distribution is subject to the Boost Software License,
|
Chris@16
|
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
13 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_GEOMETRY_ALGORITHMS_REVERSE_HPP
|
Chris@16
|
16 #define BOOST_GEOMETRY_ALGORITHMS_REVERSE_HPP
|
Chris@16
|
17
|
Chris@16
|
18 #include <algorithm>
|
Chris@16
|
19
|
Chris@16
|
20 #include <boost/range.hpp>
|
Chris@101
|
21 #include <boost/type_traits/remove_reference.hpp>
|
Chris@16
|
22
|
Chris@101
|
23 #include <boost/variant/apply_visitor.hpp>
|
Chris@101
|
24 #include <boost/variant/static_visitor.hpp>
|
Chris@101
|
25 #include <boost/variant/variant_fwd.hpp>
|
Chris@101
|
26
|
Chris@101
|
27 #include <boost/geometry/algorithms/detail/interior_iterator.hpp>
|
Chris@101
|
28 #include <boost/geometry/algorithms/detail/multi_modify.hpp>
|
Chris@16
|
29 #include <boost/geometry/core/interior_rings.hpp>
|
Chris@101
|
30 #include <boost/geometry/core/tags.hpp>
|
Chris@16
|
31 #include <boost/geometry/geometries/concepts/check.hpp>
|
Chris@16
|
32
|
Chris@16
|
33
|
Chris@16
|
34 namespace boost { namespace geometry
|
Chris@16
|
35 {
|
Chris@16
|
36
|
Chris@16
|
37
|
Chris@16
|
38 #ifndef DOXYGEN_NO_DETAIL
|
Chris@16
|
39 namespace detail { namespace reverse
|
Chris@16
|
40 {
|
Chris@16
|
41
|
Chris@16
|
42
|
Chris@16
|
43 struct range_reverse
|
Chris@16
|
44 {
|
Chris@16
|
45 template <typename Range>
|
Chris@16
|
46 static inline void apply(Range& range)
|
Chris@16
|
47 {
|
Chris@16
|
48 std::reverse(boost::begin(range), boost::end(range));
|
Chris@16
|
49 }
|
Chris@16
|
50 };
|
Chris@16
|
51
|
Chris@16
|
52
|
Chris@16
|
53 struct polygon_reverse: private range_reverse
|
Chris@16
|
54 {
|
Chris@16
|
55 template <typename Polygon>
|
Chris@16
|
56 static inline void apply(Polygon& polygon)
|
Chris@16
|
57 {
|
Chris@16
|
58 range_reverse::apply(exterior_ring(polygon));
|
Chris@16
|
59
|
Chris@101
|
60 typename interior_return_type<Polygon>::type
|
Chris@101
|
61 rings = interior_rings(polygon);
|
Chris@101
|
62
|
Chris@101
|
63 for (typename detail::interior_iterator<Polygon>::type
|
Chris@101
|
64 it = boost::begin(rings); it != boost::end(rings); ++it)
|
Chris@16
|
65 {
|
Chris@16
|
66 range_reverse::apply(*it);
|
Chris@16
|
67 }
|
Chris@16
|
68 }
|
Chris@16
|
69 };
|
Chris@16
|
70
|
Chris@16
|
71
|
Chris@16
|
72 }} // namespace detail::reverse
|
Chris@16
|
73 #endif // DOXYGEN_NO_DETAIL
|
Chris@16
|
74
|
Chris@16
|
75
|
Chris@16
|
76 #ifndef DOXYGEN_NO_DISPATCH
|
Chris@16
|
77 namespace dispatch
|
Chris@16
|
78 {
|
Chris@16
|
79
|
Chris@16
|
80
|
Chris@16
|
81 template <typename Geometry, typename Tag = typename tag<Geometry>::type>
|
Chris@16
|
82 struct reverse
|
Chris@16
|
83 {
|
Chris@16
|
84 static inline void apply(Geometry&)
|
Chris@16
|
85 {}
|
Chris@16
|
86 };
|
Chris@16
|
87
|
Chris@16
|
88
|
Chris@16
|
89 template <typename Ring>
|
Chris@16
|
90 struct reverse<Ring, ring_tag>
|
Chris@16
|
91 : detail::reverse::range_reverse
|
Chris@16
|
92 {};
|
Chris@16
|
93
|
Chris@16
|
94
|
Chris@16
|
95 template <typename LineString>
|
Chris@16
|
96 struct reverse<LineString, linestring_tag>
|
Chris@16
|
97 : detail::reverse::range_reverse
|
Chris@16
|
98 {};
|
Chris@16
|
99
|
Chris@16
|
100
|
Chris@16
|
101 template <typename Polygon>
|
Chris@16
|
102 struct reverse<Polygon, polygon_tag>
|
Chris@16
|
103 : detail::reverse::polygon_reverse
|
Chris@16
|
104 {};
|
Chris@16
|
105
|
Chris@16
|
106
|
Chris@101
|
107 template <typename Geometry>
|
Chris@101
|
108 struct reverse<Geometry, multi_linestring_tag>
|
Chris@101
|
109 : detail::multi_modify
|
Chris@101
|
110 <
|
Chris@101
|
111 Geometry,
|
Chris@101
|
112 detail::reverse::range_reverse
|
Chris@101
|
113 >
|
Chris@101
|
114 {};
|
Chris@101
|
115
|
Chris@101
|
116
|
Chris@101
|
117 template <typename Geometry>
|
Chris@101
|
118 struct reverse<Geometry, multi_polygon_tag>
|
Chris@101
|
119 : detail::multi_modify
|
Chris@101
|
120 <
|
Chris@101
|
121 Geometry,
|
Chris@101
|
122 detail::reverse::polygon_reverse
|
Chris@101
|
123 >
|
Chris@101
|
124 {};
|
Chris@101
|
125
|
Chris@101
|
126
|
Chris@101
|
127
|
Chris@16
|
128 } // namespace dispatch
|
Chris@16
|
129 #endif
|
Chris@16
|
130
|
Chris@16
|
131
|
Chris@101
|
132 namespace resolve_variant
|
Chris@101
|
133 {
|
Chris@101
|
134
|
Chris@101
|
135 template <typename Geometry>
|
Chris@101
|
136 struct reverse
|
Chris@101
|
137 {
|
Chris@101
|
138 static void apply(Geometry& geometry)
|
Chris@101
|
139 {
|
Chris@101
|
140 concept::check<Geometry>();
|
Chris@101
|
141 dispatch::reverse<Geometry>::apply(geometry);
|
Chris@101
|
142 }
|
Chris@101
|
143 };
|
Chris@101
|
144
|
Chris@101
|
145 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
|
Chris@101
|
146 struct reverse<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
|
Chris@101
|
147 {
|
Chris@101
|
148 struct visitor: boost::static_visitor<void>
|
Chris@101
|
149 {
|
Chris@101
|
150 template <typename Geometry>
|
Chris@101
|
151 void operator()(Geometry& geometry) const
|
Chris@101
|
152 {
|
Chris@101
|
153 reverse<Geometry>::apply(geometry);
|
Chris@101
|
154 }
|
Chris@101
|
155 };
|
Chris@101
|
156
|
Chris@101
|
157 static inline void apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry)
|
Chris@101
|
158 {
|
Chris@101
|
159 boost::apply_visitor(visitor(), geometry);
|
Chris@101
|
160 }
|
Chris@101
|
161 };
|
Chris@101
|
162
|
Chris@101
|
163 } // namespace resolve_variant
|
Chris@101
|
164
|
Chris@101
|
165
|
Chris@16
|
166 /*!
|
Chris@16
|
167 \brief Reverses the points within a geometry
|
Chris@16
|
168 \details Generic function to reverse a geometry. It resembles the std::reverse
|
Chris@16
|
169 functionality, but it takes the geometry type into account. Only for a ring
|
Chris@16
|
170 or for a linestring it is the same as the std::reverse.
|
Chris@16
|
171 \ingroup reverse
|
Chris@16
|
172 \tparam Geometry \tparam_geometry
|
Chris@16
|
173 \param geometry \param_geometry which will be reversed
|
Chris@16
|
174
|
Chris@16
|
175 \qbk{[include reference/algorithms/reverse.qbk]}
|
Chris@16
|
176 */
|
Chris@16
|
177 template <typename Geometry>
|
Chris@16
|
178 inline void reverse(Geometry& geometry)
|
Chris@16
|
179 {
|
Chris@101
|
180 resolve_variant::reverse<Geometry>::apply(geometry);
|
Chris@16
|
181 }
|
Chris@16
|
182
|
Chris@16
|
183 }} // namespace boost::geometry
|
Chris@16
|
184
|
Chris@16
|
185
|
Chris@16
|
186 #endif // BOOST_GEOMETRY_ALGORITHMS_REVERSE_HPP
|