]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/geometry/algorithms/unique.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / unique.hpp
CommitLineData
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// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
7
20effc67
TL
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
11
7c673cae
FG
12// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
14
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)
18
19#ifndef BOOST_GEOMETRY_ALGORITHMS_UNIQUE_HPP
20#define BOOST_GEOMETRY_ALGORITHMS_UNIQUE_HPP
21
22#include <algorithm>
23
20effc67
TL
24#include <boost/range/begin.hpp>
25#include <boost/range/end.hpp>
7c673cae
FG
26
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>
33
34
35namespace boost { namespace geometry
36{
37
38
39#ifndef DOXYGEN_NO_DETAIL
40namespace detail { namespace unique
41{
42
43
44struct range_unique
45{
46 template <typename Range, typename ComparePolicy>
47 static inline void apply(Range& range, ComparePolicy const& policy)
48 {
49 typename boost::range_iterator<Range>::type it
50 = std::unique
51 (
52 boost::begin(range),
53 boost::end(range),
54 policy
55 );
56
57 traits::resize<Range>::apply(range, it - boost::begin(range));
58 }
59};
60
61
62struct polygon_unique
63{
64 template <typename Polygon, typename ComparePolicy>
65 static inline void apply(Polygon& polygon, ComparePolicy const& policy)
66 {
67 range_unique::apply(exterior_ring(polygon), policy);
68
69 typename interior_return_type<Polygon>::type
70 rings = interior_rings(polygon);
71
72 for (typename detail::interior_iterator<Polygon>::type
73 it = boost::begin(rings); it != boost::end(rings); ++it)
74 {
75 range_unique::apply(*it, policy);
76 }
77 }
78};
79
80
81template <typename Policy>
82struct multi_unique
83{
84 template <typename MultiGeometry, typename ComparePolicy>
85 static inline void apply(MultiGeometry& multi, ComparePolicy const& compare)
86 {
87 for (typename boost::range_iterator<MultiGeometry>::type
88 it = boost::begin(multi);
89 it != boost::end(multi);
90 ++it)
91 {
92 Policy::apply(*it, compare);
93 }
94 }
95};
96
97
98}} // namespace detail::unique
99#endif // DOXYGEN_NO_DETAIL
100
101
102
103#ifndef DOXYGEN_NO_DISPATCH
104namespace dispatch
105{
106
107
108template
109<
110 typename Geometry,
111 typename Tag = typename tag<Geometry>::type
112>
113struct unique
114{
115 template <typename ComparePolicy>
116 static inline void apply(Geometry&, ComparePolicy const& )
117 {}
118};
119
120
121template <typename Ring>
122struct unique<Ring, ring_tag>
123 : detail::unique::range_unique
124{};
125
126
127template <typename LineString>
128struct unique<LineString, linestring_tag>
129 : detail::unique::range_unique
130{};
131
132
133template <typename Polygon>
134struct unique<Polygon, polygon_tag>
135 : detail::unique::polygon_unique
136{};
137
138
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.
143
144
145template <typename MultiLineString>
146struct unique<MultiLineString, multi_linestring_tag>
147 : detail::unique::multi_unique<detail::unique::range_unique>
148{};
149
150
151template <typename MultiPolygon>
152struct unique<MultiPolygon, multi_polygon_tag>
153 : detail::unique::multi_unique<detail::unique::polygon_unique>
154{};
155
156
157} // namespace dispatch
158#endif
159
160
161/*!
162\brief \brief_calc{minimal set}
163\ingroup unique
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
167
168\qbk{[include reference/algorithms/unique.qbk]}
169*/
170template <typename Geometry>
171inline void unique(Geometry& geometry)
172{
173 concepts::check<Geometry>();
174
175 // Default strategy is the default point-comparison policy
176 typedef geometry::equal_to
177 <
178 typename geometry::point_type<Geometry>::type
179 > policy;
180
181
182 dispatch::unique<Geometry>::apply(geometry, policy());
183}
184
185}} // namespace boost::geometry
186
187
188#endif // BOOST_GEOMETRY_ALGORITHMS_UNIQUE_HPP