]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/algorithms/detail/sections/range_by_section.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / detail / sections / range_by_section.hpp
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
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
9
10 // This file was modified by Oracle on 2013-2020.
11 // Modifications copyright (c) 2013-2020, Oracle and/or its affiliates.
12 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
13
14 // Use, modification and distribution is subject to the Boost Software License,
15 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
16 // http://www.boost.org/LICENSE_1_0.txt)
17
18 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_SECTIONS_RANGE_BY_SECTION_HPP
19 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_SECTIONS_RANGE_BY_SECTION_HPP
20
21 #include <boost/range/size.hpp>
22 #include <boost/range/value_type.hpp>
23
24 #include <boost/geometry/core/access.hpp>
25 #include <boost/geometry/core/assert.hpp>
26 #include <boost/geometry/core/closure.hpp>
27 #include <boost/geometry/core/exterior_ring.hpp>
28 #include <boost/geometry/core/interior_rings.hpp>
29 #include <boost/geometry/core/ring_type.hpp>
30 #include <boost/geometry/core/static_assert.hpp>
31 #include <boost/geometry/core/tags.hpp>
32 #include <boost/geometry/geometries/concepts/check.hpp>
33 #include <boost/geometry/util/range.hpp>
34
35
36 namespace boost { namespace geometry
37 {
38
39 #ifndef DOXYGEN_NO_DETAIL
40 namespace detail { namespace section
41 {
42
43
44 template <typename Range, typename Section>
45 struct full_section_range
46 {
47 static inline Range const& apply(Range const& range, Section const& )
48 {
49 return range;
50 }
51 };
52
53
54 template <typename Polygon, typename Section>
55 struct full_section_polygon
56 {
57 static inline typename ring_return_type<Polygon const>::type apply(Polygon const& polygon, Section const& section)
58 {
59 return section.ring_id.ring_index < 0
60 ? geometry::exterior_ring(polygon)
61 : range::at(geometry::interior_rings(polygon),
62 static_cast<std::size_t>(section.ring_id.ring_index));
63 }
64 };
65
66
67 template
68 <
69 typename MultiGeometry,
70 typename Section,
71 typename Policy
72 >
73 struct full_section_multi
74 {
75 static inline typename ring_return_type<MultiGeometry const>::type apply(
76 MultiGeometry const& multi, Section const& section)
77 {
78 typedef typename boost::range_size<MultiGeometry>::type size_type;
79
80 BOOST_GEOMETRY_ASSERT
81 (
82 section.ring_id.multi_index >= 0
83 && size_type(section.ring_id.multi_index) < boost::size(multi)
84 );
85
86 return Policy::apply(range::at(multi, size_type(section.ring_id.multi_index)), section);
87 }
88 };
89
90
91 }} // namespace detail::section
92 #endif
93
94
95 #ifndef DOXYGEN_NO_DISPATCH
96 namespace dispatch
97 {
98
99
100 template
101 <
102 typename Tag,
103 typename Geometry,
104 typename Section
105 >
106 struct range_by_section
107 {
108 BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
109 "Not or not yet implemented for this Geometry type.",
110 Tag, Geometry, Section);
111 };
112
113
114 template <typename LineString, typename Section>
115 struct range_by_section<linestring_tag, LineString, Section>
116 : detail::section::full_section_range<LineString, Section>
117 {};
118
119
120 template <typename Ring, typename Section>
121 struct range_by_section<ring_tag, Ring, Section>
122 : detail::section::full_section_range<Ring, Section>
123 {};
124
125
126 template <typename Polygon, typename Section>
127 struct range_by_section<polygon_tag, Polygon, Section>
128 : detail::section::full_section_polygon<Polygon, Section>
129 {};
130
131
132 template <typename MultiPolygon, typename Section>
133 struct range_by_section<multi_polygon_tag, MultiPolygon, Section>
134 : detail::section::full_section_multi
135 <
136 MultiPolygon,
137 Section,
138 detail::section::full_section_polygon
139 <
140 typename boost::range_value<MultiPolygon>::type,
141 Section
142 >
143 >
144 {};
145
146 template <typename MultiLinestring, typename Section>
147 struct range_by_section<multi_linestring_tag, MultiLinestring, Section>
148 : detail::section::full_section_multi
149 <
150 MultiLinestring,
151 Section,
152 detail::section::full_section_range
153 <
154 typename boost::range_value<MultiLinestring>::type,
155 Section
156 >
157 >
158 {};
159
160
161 } // namespace dispatch
162 #endif
163
164
165 /*!
166 \brief Get full ring (exterior, one of interiors, one from multi)
167 indicated by the specified section
168 \ingroup sectionalize
169 \tparam Geometry type
170 \tparam Section type of section to get from
171 \param geometry geometry to take section of
172 \param section structure with section
173 */
174 template <typename Geometry, typename Section>
175 inline typename ring_return_type<Geometry const>::type
176 range_by_section(Geometry const& geometry, Section const& section)
177 {
178 concepts::check<Geometry const>();
179
180 return dispatch::range_by_section
181 <
182 typename tag<Geometry>::type,
183 Geometry,
184 Section
185 >::apply(geometry, section);
186 }
187
188
189 }} // namespace boost::geometry
190
191 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_SECTIONS_RANGE_BY_SECTION_HPP