]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
3 | // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. | |
4 | // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. | |
5 | // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. | |
6 | ||
20effc67 TL |
7 | // This file was modified by Oracle on 2020. |
8 | // Modifications copyright (c) 2020, Oracle and/or its affiliates. | |
9 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle | |
10 | ||
7c673cae FG |
11 | // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library |
12 | // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. | |
13 | ||
14 | // Use, modification and distribution is subject to the Boost Software License, | |
15 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
16 | // http://www.boost.org/LICENSE_1_0.txt) | |
17 | ||
18 | #ifndef BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP | |
19 | #define BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP | |
20 | ||
21 | ||
20effc67 | 22 | #include <type_traits> |
7c673cae FG |
23 | |
24 | #include <boost/variant/apply_visitor.hpp> | |
25 | #include <boost/variant/static_visitor.hpp> | |
26 | #include <boost/variant/variant_fwd.hpp> | |
27 | ||
28 | #include <boost/geometry/algorithms/not_implemented.hpp> | |
29 | #include <boost/geometry/core/access.hpp> | |
30 | #include <boost/geometry/core/exterior_ring.hpp> | |
31 | #include <boost/geometry/core/interior_rings.hpp> | |
32 | #include <boost/geometry/core/mutable_range.hpp> | |
33 | #include <boost/geometry/core/tag_cast.hpp> | |
34 | #include <boost/geometry/core/tags.hpp> | |
35 | #include <boost/geometry/geometries/concepts/check.hpp> | |
36 | ||
37 | ||
38 | namespace boost { namespace geometry | |
39 | { | |
40 | ||
41 | #ifndef DOXYGEN_NO_DETAIL | |
42 | namespace detail { namespace clear | |
43 | { | |
44 | ||
45 | template <typename Geometry> | |
46 | struct collection_clear | |
47 | { | |
48 | static inline void apply(Geometry& geometry) | |
49 | { | |
50 | traits::clear<Geometry>::apply(geometry); | |
51 | } | |
52 | }; | |
53 | ||
54 | template <typename Polygon> | |
55 | struct polygon_clear | |
56 | { | |
57 | static inline void apply(Polygon& polygon) | |
58 | { | |
59 | traits::clear | |
60 | < | |
20effc67 | 61 | typename std::remove_reference |
7c673cae FG |
62 | < |
63 | typename traits::interior_mutable_type<Polygon>::type | |
64 | >::type | |
65 | >::apply(interior_rings(polygon)); | |
66 | traits::clear | |
67 | < | |
20effc67 | 68 | typename std::remove_reference |
7c673cae FG |
69 | < |
70 | typename traits::ring_mutable_type<Polygon>::type | |
71 | >::type | |
72 | >::apply(exterior_ring(polygon)); | |
73 | } | |
74 | }; | |
75 | ||
76 | template <typename Geometry> | |
77 | struct no_action | |
78 | { | |
79 | static inline void apply(Geometry& ) | |
80 | { | |
81 | } | |
82 | }; | |
83 | ||
84 | ||
85 | }} // namespace detail::clear | |
86 | #endif // DOXYGEN_NO_DETAIL | |
87 | ||
88 | #ifndef DOXYGEN_NO_DISPATCH | |
89 | namespace dispatch | |
90 | { | |
91 | ||
92 | template | |
93 | < | |
94 | typename Geometry, | |
95 | typename Tag = typename tag_cast<typename tag<Geometry>::type, multi_tag>::type | |
96 | > | |
97 | struct clear: not_implemented<Tag> | |
98 | {}; | |
99 | ||
100 | // Point/box/segment do not have clear. So specialize to do nothing. | |
101 | template <typename Geometry> | |
102 | struct clear<Geometry, point_tag> | |
103 | : detail::clear::no_action<Geometry> | |
104 | {}; | |
105 | ||
106 | template <typename Geometry> | |
107 | struct clear<Geometry, box_tag> | |
108 | : detail::clear::no_action<Geometry> | |
109 | {}; | |
110 | ||
111 | template <typename Geometry> | |
112 | struct clear<Geometry, segment_tag> | |
113 | : detail::clear::no_action<Geometry> | |
114 | {}; | |
115 | ||
116 | template <typename Geometry> | |
117 | struct clear<Geometry, linestring_tag> | |
118 | : detail::clear::collection_clear<Geometry> | |
119 | {}; | |
120 | ||
121 | template <typename Geometry> | |
122 | struct clear<Geometry, ring_tag> | |
123 | : detail::clear::collection_clear<Geometry> | |
124 | {}; | |
125 | ||
126 | ||
127 | // Polygon can (indirectly) use std for clear | |
128 | template <typename Polygon> | |
129 | struct clear<Polygon, polygon_tag> | |
130 | : detail::clear::polygon_clear<Polygon> | |
131 | {}; | |
132 | ||
133 | ||
134 | template <typename Geometry> | |
135 | struct clear<Geometry, multi_tag> | |
136 | : detail::clear::collection_clear<Geometry> | |
137 | {}; | |
138 | ||
139 | ||
140 | } // namespace dispatch | |
141 | #endif // DOXYGEN_NO_DISPATCH | |
142 | ||
143 | ||
144 | namespace resolve_variant { | |
145 | ||
146 | template <typename Geometry> | |
147 | struct clear | |
148 | { | |
149 | static inline void apply(Geometry& geometry) | |
150 | { | |
151 | dispatch::clear<Geometry>::apply(geometry); | |
152 | } | |
153 | }; | |
154 | ||
155 | template <BOOST_VARIANT_ENUM_PARAMS(typename T)> | |
156 | struct clear<variant<BOOST_VARIANT_ENUM_PARAMS(T)> > | |
157 | { | |
158 | struct visitor: static_visitor<void> | |
159 | { | |
160 | template <typename Geometry> | |
161 | inline void operator()(Geometry& geometry) const | |
162 | { | |
163 | clear<Geometry>::apply(geometry); | |
164 | } | |
165 | }; | |
166 | ||
167 | static inline void apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry) | |
168 | { | |
169 | boost::apply_visitor(visitor(), geometry); | |
170 | } | |
171 | }; | |
172 | ||
173 | } // namespace resolve_variant | |
174 | ||
175 | ||
176 | /*! | |
177 | \brief Clears a linestring, ring or polygon (exterior+interiors) or multi* | |
178 | \details Generic function to clear a geometry. All points will be removed from the collection or collections | |
179 | making up the geometry. In most cases this is equivalent to the .clear() method of a std::vector<...>. In | |
180 | the case of a polygon, this clear functionality is automatically called for the exterior ring, and for the | |
181 | interior ring collection. In the case of a point, boxes and segments, nothing will happen. | |
182 | \ingroup clear | |
183 | \tparam Geometry \tparam_geometry | |
184 | \param geometry \param_geometry which will be cleared | |
185 | \note points and boxes cannot be cleared, instead they can be set to zero by "assign_zero" | |
186 | ||
187 | \qbk{[include reference/algorithms/clear.qbk]} | |
188 | */ | |
189 | template <typename Geometry> | |
190 | inline void clear(Geometry& geometry) | |
191 | { | |
192 | concepts::check<Geometry>(); | |
193 | ||
194 | resolve_variant::clear<Geometry>::apply(geometry); | |
195 | } | |
196 | ||
197 | ||
198 | }} // namespace boost::geometry | |
199 | ||
200 | ||
201 | #endif // BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP |