Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:23

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
0004 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
0005 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
0006 // Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
0007 
0008 // This file was modified by Oracle on 2020.
0009 // Modifications copyright (c) 2020 Oracle and/or its affiliates.
0010 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0011 
0012 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
0013 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
0014 
0015 // Use, modification and distribution is subject to the Boost Software License,
0016 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0017 // http://www.boost.org/LICENSE_1_0.txt)
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 }} // namespace detail::unique
0093 #endif // DOXYGEN_NO_DETAIL
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 // For points, unique is not applicable and does nothing
0134 // (Note that it is not "spatially unique" but that it removes duplicate coordinates,
0135 //  like std::unique does). Spatially unique is "dissolve" which can (or will be)
0136 //  possible for multi-points as well, removing points at the same location.
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 } // namespace dispatch
0152 #endif
0153 
0154 
0155 /*!
0156 \brief \brief_calc{minimal set}
0157 \ingroup unique
0158 \details \details_calc{unique,minimal set (where duplicate consecutive points are removed)}.
0159 \tparam Geometry \tparam_geometry
0160 \param geometry \param_geometry which will be made unique
0161 
0162 \qbk{[include reference/algorithms/unique.qbk]}
0163 */
0164 template <typename Geometry>
0165 inline void unique(Geometry& geometry)
0166 {
0167     concepts::check<Geometry>();
0168 
0169     // Default strategy is the default point-comparison policy
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 }} // namespace boost::geometry
0180 
0181 
0182 #endif // BOOST_GEOMETRY_ALGORITHMS_UNIQUE_HPP