1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP
15 #define BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP
18 #include <boost/type_traits/remove_const.hpp>
20 #include <boost/variant/apply_visitor.hpp>
21 #include <boost/variant/static_visitor.hpp>
22 #include <boost/variant/variant_fwd.hpp>
24 #include <boost/geometry/algorithms/not_implemented.hpp>
25 #include <boost/geometry/core/access.hpp>
26 #include <boost/geometry/core/exterior_ring.hpp>
27 #include <boost/geometry/core/interior_rings.hpp>
28 #include <boost/geometry/core/mutable_range.hpp>
29 #include <boost/geometry/core/tag_cast.hpp>
30 #include <boost/geometry/core/tags.hpp>
31 #include <boost/geometry/geometries/concepts/check.hpp>
34 namespace boost { namespace geometry
37 #ifndef DOXYGEN_NO_DETAIL
38 namespace detail { namespace clear
41 template <typename Geometry>
42 struct collection_clear
44 static inline void apply(Geometry& geometry)
46 traits::clear<Geometry>::apply(geometry);
50 template <typename Polygon>
53 static inline void apply(Polygon& polygon)
57 typename boost::remove_reference
59 typename traits::interior_mutable_type<Polygon>::type
61 >::apply(interior_rings(polygon));
64 typename boost::remove_reference
66 typename traits::ring_mutable_type<Polygon>::type
68 >::apply(exterior_ring(polygon));
72 template <typename Geometry>
75 static inline void apply(Geometry& )
81 }} // namespace detail::clear
82 #endif // DOXYGEN_NO_DETAIL
84 #ifndef DOXYGEN_NO_DISPATCH
91 typename Tag = typename tag_cast<typename tag<Geometry>::type, multi_tag>::type
93 struct clear: not_implemented<Tag>
96 // Point/box/segment do not have clear. So specialize to do nothing.
97 template <typename Geometry>
98 struct clear<Geometry, point_tag>
99 : detail::clear::no_action<Geometry>
102 template <typename Geometry>
103 struct clear<Geometry, box_tag>
104 : detail::clear::no_action<Geometry>
107 template <typename Geometry>
108 struct clear<Geometry, segment_tag>
109 : detail::clear::no_action<Geometry>
112 template <typename Geometry>
113 struct clear<Geometry, linestring_tag>
114 : detail::clear::collection_clear<Geometry>
117 template <typename Geometry>
118 struct clear<Geometry, ring_tag>
119 : detail::clear::collection_clear<Geometry>
123 // Polygon can (indirectly) use std for clear
124 template <typename Polygon>
125 struct clear<Polygon, polygon_tag>
126 : detail::clear::polygon_clear<Polygon>
130 template <typename Geometry>
131 struct clear<Geometry, multi_tag>
132 : detail::clear::collection_clear<Geometry>
136 } // namespace dispatch
137 #endif // DOXYGEN_NO_DISPATCH
140 namespace resolve_variant {
142 template <typename Geometry>
145 static inline void apply(Geometry& geometry)
147 dispatch::clear<Geometry>::apply(geometry);
151 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
152 struct clear<variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
154 struct visitor: static_visitor<void>
156 template <typename Geometry>
157 inline void operator()(Geometry& geometry) const
159 clear<Geometry>::apply(geometry);
163 static inline void apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)>& geometry)
165 boost::apply_visitor(visitor(), geometry);
169 } // namespace resolve_variant
173 \brief Clears a linestring, ring or polygon (exterior+interiors) or multi*
174 \details Generic function to clear a geometry. All points will be removed from the collection or collections
175 making up the geometry. In most cases this is equivalent to the .clear() method of a std::vector<...>. In
176 the case of a polygon, this clear functionality is automatically called for the exterior ring, and for the
177 interior ring collection. In the case of a point, boxes and segments, nothing will happen.
179 \tparam Geometry \tparam_geometry
180 \param geometry \param_geometry which will be cleared
181 \note points and boxes cannot be cleared, instead they can be set to zero by "assign_zero"
183 \qbk{[include reference/algorithms/clear.qbk]}
185 template <typename Geometry>
186 inline void clear(Geometry& geometry)
188 concepts::check<Geometry>();
190 resolve_variant::clear<Geometry>::apply(geometry);
194 }} // namespace boost::geometry
197 #endif // BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP