File indexing completed on 2025-01-18 09:35:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef BOOST_GEOMETRY_ALGORITHMS_UNIQUE_HPP
0020 #define BOOST_GEOMETRY_ALGORITHMS_UNIQUE_HPP
0021
0022 #include <algorithm>
0023
0024 #include <boost/range/begin.hpp>
0025 #include <boost/range/end.hpp>
0026
0027 #include <boost/geometry/core/interior_rings.hpp>
0028 #include <boost/geometry/core/mutable_range.hpp>
0029 #include <boost/geometry/core/tags.hpp>
0030 #include <boost/geometry/geometries/concepts/check.hpp>
0031 #include <boost/geometry/policies/compare.hpp>
0032
0033
0034 namespace boost { namespace geometry
0035 {
0036
0037
0038 #ifndef DOXYGEN_NO_DETAIL
0039 namespace detail { namespace unique
0040 {
0041
0042
0043 struct range_unique
0044 {
0045 template <typename Range, typename ComparePolicy>
0046 static inline void apply(Range& range, ComparePolicy const& policy)
0047 {
0048 auto it
0049 = std::unique
0050 (
0051 boost::begin(range),
0052 boost::end(range),
0053 policy
0054 );
0055
0056 traits::resize<Range>::apply(range, it - boost::begin(range));
0057 }
0058 };
0059
0060
0061 struct polygon_unique
0062 {
0063 template <typename Polygon, typename ComparePolicy>
0064 static inline void apply(Polygon& polygon, ComparePolicy const& policy)
0065 {
0066 range_unique::apply(exterior_ring(polygon), policy);
0067
0068 auto&& rings = interior_rings(polygon);
0069
0070 for (auto it = boost::begin(rings); it != boost::end(rings); ++it)
0071 {
0072 range_unique::apply(*it, policy);
0073 }
0074 }
0075 };
0076
0077
0078 template <typename Policy>
0079 struct multi_unique
0080 {
0081 template <typename MultiGeometry, typename ComparePolicy>
0082 static inline void apply(MultiGeometry& multi, ComparePolicy const& compare)
0083 {
0084 for (auto it = boost::begin(multi); it != boost::end(multi); ++it)
0085 {
0086 Policy::apply(*it, compare);
0087 }
0088 }
0089 };
0090
0091
0092 }}
0093 #endif
0094
0095
0096
0097 #ifndef DOXYGEN_NO_DISPATCH
0098 namespace dispatch
0099 {
0100
0101
0102 template
0103 <
0104 typename Geometry,
0105 typename Tag = typename tag<Geometry>::type
0106 >
0107 struct unique
0108 {
0109 template <typename ComparePolicy>
0110 static inline void apply(Geometry&, ComparePolicy const& )
0111 {}
0112 };
0113
0114
0115 template <typename Ring>
0116 struct unique<Ring, ring_tag>
0117 : detail::unique::range_unique
0118 {};
0119
0120
0121 template <typename LineString>
0122 struct unique<LineString, linestring_tag>
0123 : detail::unique::range_unique
0124 {};
0125
0126
0127 template <typename Polygon>
0128 struct unique<Polygon, polygon_tag>
0129 : detail::unique::polygon_unique
0130 {};
0131
0132
0133
0134
0135
0136
0137
0138
0139 template <typename MultiLineString>
0140 struct unique<MultiLineString, multi_linestring_tag>
0141 : detail::unique::multi_unique<detail::unique::range_unique>
0142 {};
0143
0144
0145 template <typename MultiPolygon>
0146 struct unique<MultiPolygon, multi_polygon_tag>
0147 : detail::unique::multi_unique<detail::unique::polygon_unique>
0148 {};
0149
0150
0151 }
0152 #endif
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164 template <typename Geometry>
0165 inline void unique(Geometry& geometry)
0166 {
0167 concepts::check<Geometry>();
0168
0169
0170 typedef geometry::equal_to
0171 <
0172 typename geometry::point_type<Geometry>::type
0173 > policy;
0174
0175
0176 dispatch::unique<Geometry>::apply(geometry, policy());
0177 }
0178
0179 }}
0180
0181
0182 #endif