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.
6 // Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
8 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
15 #ifndef BOOST_GEOMETRY_ALGORITHMS_UNIQUE_HPP
16 #define BOOST_GEOMETRY_ALGORITHMS_UNIQUE_HPP
20 #include <boost/range.hpp>
21 #include <boost/type_traits/remove_reference.hpp>
23 #include <boost/geometry/algorithms/detail/interior_iterator.hpp>
24 #include <boost/geometry/core/interior_rings.hpp>
25 #include <boost/geometry/core/mutable_range.hpp>
26 #include <boost/geometry/core/tags.hpp>
27 #include <boost/geometry/geometries/concepts/check.hpp>
28 #include <boost/geometry/policies/compare.hpp>
31 namespace boost { namespace geometry
35 #ifndef DOXYGEN_NO_DETAIL
36 namespace detail { namespace unique
42 template <typename Range, typename ComparePolicy>
43 static inline void apply(Range& range, ComparePolicy const& policy)
45 typename boost::range_iterator<Range>::type it
53 traits::resize<Range>::apply(range, it - boost::begin(range));
60 template <typename Polygon, typename ComparePolicy>
61 static inline void apply(Polygon& polygon, ComparePolicy const& policy)
63 range_unique::apply(exterior_ring(polygon), policy);
65 typename interior_return_type<Polygon>::type
66 rings = interior_rings(polygon);
68 for (typename detail::interior_iterator<Polygon>::type
69 it = boost::begin(rings); it != boost::end(rings); ++it)
71 range_unique::apply(*it, policy);
77 template <typename Policy>
80 template <typename MultiGeometry, typename ComparePolicy>
81 static inline void apply(MultiGeometry& multi, ComparePolicy const& compare)
83 for (typename boost::range_iterator<MultiGeometry>::type
84 it = boost::begin(multi);
85 it != boost::end(multi);
88 Policy::apply(*it, compare);
94 }} // namespace detail::unique
95 #endif // DOXYGEN_NO_DETAIL
99 #ifndef DOXYGEN_NO_DISPATCH
107 typename Tag = typename tag<Geometry>::type
111 template <typename ComparePolicy>
112 static inline void apply(Geometry&, ComparePolicy const& )
117 template <typename Ring>
118 struct unique<Ring, ring_tag>
119 : detail::unique::range_unique
123 template <typename LineString>
124 struct unique<LineString, linestring_tag>
125 : detail::unique::range_unique
129 template <typename Polygon>
130 struct unique<Polygon, polygon_tag>
131 : detail::unique::polygon_unique
135 // For points, unique is not applicable and does nothing
136 // (Note that it is not "spatially unique" but that it removes duplicate coordinates,
137 // like std::unique does). Spatially unique is "dissolve" which can (or will be)
138 // possible for multi-points as well, removing points at the same location.
141 template <typename MultiLineString>
142 struct unique<MultiLineString, multi_linestring_tag>
143 : detail::unique::multi_unique<detail::unique::range_unique>
147 template <typename MultiPolygon>
148 struct unique<MultiPolygon, multi_polygon_tag>
149 : detail::unique::multi_unique<detail::unique::polygon_unique>
153 } // namespace dispatch
158 \brief \brief_calc{minimal set}
160 \details \details_calc{unique,minimal set (where duplicate consecutive points are removed)}.
161 \tparam Geometry \tparam_geometry
162 \param geometry \param_geometry which will be made unique
164 \qbk{[include reference/algorithms/unique.qbk]}
166 template <typename Geometry>
167 inline void unique(Geometry& geometry)
169 concepts::check<Geometry>();
171 // Default strategy is the default point-comparison policy
172 typedef geometry::equal_to
174 typename geometry::point_type<Geometry>::type
178 dispatch::unique<Geometry>::apply(geometry, policy());
181 }} // namespace boost::geometry
184 #endif // BOOST_GEOMETRY_ALGORITHMS_UNIQUE_HPP