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 // This file was modified by Oracle on 2020.
9 // Modifications copyright (c) 2020 Oracle and/or its affiliates.
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
19 #ifndef BOOST_GEOMETRY_ALGORITHMS_UNIQUE_HPP
20 #define BOOST_GEOMETRY_ALGORITHMS_UNIQUE_HPP
24 #include <boost/range/begin.hpp>
25 #include <boost/range/end.hpp>
27 #include <boost/geometry/algorithms/detail/interior_iterator.hpp>
28 #include <boost/geometry/core/interior_rings.hpp>
29 #include <boost/geometry/core/mutable_range.hpp>
30 #include <boost/geometry/core/tags.hpp>
31 #include <boost/geometry/geometries/concepts/check.hpp>
32 #include <boost/geometry/policies/compare.hpp>
35 namespace boost { namespace geometry
39 #ifndef DOXYGEN_NO_DETAIL
40 namespace detail { namespace unique
46 template <typename Range, typename ComparePolicy>
47 static inline void apply(Range& range, ComparePolicy const& policy)
49 typename boost::range_iterator<Range>::type it
57 traits::resize<Range>::apply(range, it - boost::begin(range));
64 template <typename Polygon, typename ComparePolicy>
65 static inline void apply(Polygon& polygon, ComparePolicy const& policy)
67 range_unique::apply(exterior_ring(polygon), policy);
69 typename interior_return_type<Polygon>::type
70 rings = interior_rings(polygon);
72 for (typename detail::interior_iterator<Polygon>::type
73 it = boost::begin(rings); it != boost::end(rings); ++it)
75 range_unique::apply(*it, policy);
81 template <typename Policy>
84 template <typename MultiGeometry, typename ComparePolicy>
85 static inline void apply(MultiGeometry& multi, ComparePolicy const& compare)
87 for (typename boost::range_iterator<MultiGeometry>::type
88 it = boost::begin(multi);
89 it != boost::end(multi);
92 Policy::apply(*it, compare);
98 }} // namespace detail::unique
99 #endif // DOXYGEN_NO_DETAIL
103 #ifndef DOXYGEN_NO_DISPATCH
111 typename Tag = typename tag<Geometry>::type
115 template <typename ComparePolicy>
116 static inline void apply(Geometry&, ComparePolicy const& )
121 template <typename Ring>
122 struct unique<Ring, ring_tag>
123 : detail::unique::range_unique
127 template <typename LineString>
128 struct unique<LineString, linestring_tag>
129 : detail::unique::range_unique
133 template <typename Polygon>
134 struct unique<Polygon, polygon_tag>
135 : detail::unique::polygon_unique
139 // For points, unique is not applicable and does nothing
140 // (Note that it is not "spatially unique" but that it removes duplicate coordinates,
141 // like std::unique does). Spatially unique is "dissolve" which can (or will be)
142 // possible for multi-points as well, removing points at the same location.
145 template <typename MultiLineString>
146 struct unique<MultiLineString, multi_linestring_tag>
147 : detail::unique::multi_unique<detail::unique::range_unique>
151 template <typename MultiPolygon>
152 struct unique<MultiPolygon, multi_polygon_tag>
153 : detail::unique::multi_unique<detail::unique::polygon_unique>
157 } // namespace dispatch
162 \brief \brief_calc{minimal set}
164 \details \details_calc{unique,minimal set (where duplicate consecutive points are removed)}.
165 \tparam Geometry \tparam_geometry
166 \param geometry \param_geometry which will be made unique
168 \qbk{[include reference/algorithms/unique.qbk]}
170 template <typename Geometry>
171 inline void unique(Geometry& geometry)
173 concepts::check<Geometry>();
175 // Default strategy is the default point-comparison policy
176 typedef geometry::equal_to
178 typename geometry::point_type<Geometry>::type
182 dispatch::unique<Geometry>::apply(geometry, policy());
185 }} // namespace boost::geometry
188 #endif // BOOST_GEOMETRY_ALGORITHMS_UNIQUE_HPP