]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/algorithms/buffer.hpp
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / buffer.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 // This file was modified by Oracle on 2017-2021.
8 // Modifications copyright (c) 2017-2021 Oracle and/or its affiliates.
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10
11 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
12 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
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_BUFFER_HPP
19 #define BOOST_GEOMETRY_ALGORITHMS_BUFFER_HPP
20
21 #include <cstddef>
22
23 #include <boost/numeric/conversion/cast.hpp>
24
25 #include <boost/range/value_type.hpp>
26
27 #include <boost/variant/apply_visitor.hpp>
28 #include <boost/variant/static_visitor.hpp>
29 #include <boost/variant/variant_fwd.hpp>
30
31 #include <boost/geometry/algorithms/clear.hpp>
32 #include <boost/geometry/algorithms/envelope.hpp>
33 #include <boost/geometry/algorithms/is_empty.hpp>
34 #include <boost/geometry/algorithms/not_implemented.hpp>
35 #include <boost/geometry/arithmetic/arithmetic.hpp>
36 #include <boost/geometry/geometries/concepts/check.hpp>
37 #include <boost/geometry/geometries/box.hpp>
38 #include <boost/geometry/util/math.hpp>
39
40 #include <boost/geometry/algorithms/detail/buffer/buffer_box.hpp>
41 #include <boost/geometry/algorithms/detail/buffer/buffer_inserter.hpp>
42
43 #include <boost/geometry/strategies/buffer/cartesian.hpp>
44 #include <boost/geometry/strategies/buffer/geographic.hpp>
45 #include <boost/geometry/strategies/buffer/spherical.hpp>
46
47 namespace boost { namespace geometry
48 {
49
50 #ifndef DOXYGEN_NO_DISPATCH
51 namespace dispatch
52 {
53
54 template
55 <
56 typename Input,
57 typename Output,
58 typename TagIn = typename tag<Input>::type,
59 typename TagOut = typename tag<Output>::type
60 >
61 struct buffer: not_implemented<TagIn, TagOut>
62 {};
63
64
65 template <typename BoxIn, typename BoxOut>
66 struct buffer<BoxIn, BoxOut, box_tag, box_tag>
67 {
68 template <typename Distance>
69 static inline void apply(BoxIn const& box_in, Distance const& distance,
70 Distance const& , BoxOut& box_out)
71 {
72 detail::buffer::buffer_box(box_in, distance, box_out);
73 }
74 };
75
76 } // namespace dispatch
77 #endif // DOXYGEN_NO_DISPATCH
78
79
80 namespace resolve_variant {
81
82 template <typename Geometry>
83 struct buffer
84 {
85 template <typename Distance, typename GeometryOut>
86 static inline void apply(Geometry const& geometry,
87 Distance const& distance,
88 Distance const& chord_length,
89 GeometryOut& out)
90 {
91 dispatch::buffer<Geometry, GeometryOut>::apply(geometry, distance, chord_length, out);
92 }
93 };
94
95 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
96 struct buffer<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
97 {
98 template <typename Distance, typename GeometryOut>
99 struct visitor: boost::static_visitor<void>
100 {
101 Distance const& m_distance;
102 Distance const& m_chord_length;
103 GeometryOut& m_out;
104
105 visitor(Distance const& distance,
106 Distance const& chord_length,
107 GeometryOut& out)
108 : m_distance(distance),
109 m_chord_length(chord_length),
110 m_out(out)
111 {}
112
113 template <typename Geometry>
114 void operator()(Geometry const& geometry) const
115 {
116 buffer<Geometry>::apply(geometry, m_distance, m_chord_length, m_out);
117 }
118 };
119
120 template <typename Distance, typename GeometryOut>
121 static inline void apply(
122 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
123 Distance const& distance,
124 Distance const& chord_length,
125 GeometryOut& out
126 )
127 {
128 boost::apply_visitor(visitor<Distance, GeometryOut>(distance, chord_length, out), geometry);
129 }
130 };
131
132 } // namespace resolve_variant
133
134
135 /*!
136 \brief \brief_calc{buffer}
137 \ingroup buffer
138 \details \details_calc{buffer, \det_buffer}.
139 \tparam Input \tparam_geometry
140 \tparam Output \tparam_geometry
141 \tparam Distance \tparam_numeric
142 \param geometry_in \param_geometry
143 \param geometry_out \param_geometry
144 \param distance The distance to be used for the buffer
145 \param chord_length (optional) The length of the chord's in the generated arcs around points or bends
146
147 \qbk{[include reference/algorithms/buffer.qbk]}
148 */
149 template <typename Input, typename Output, typename Distance>
150 inline void buffer(Input const& geometry_in, Output& geometry_out,
151 Distance const& distance, Distance const& chord_length = -1)
152 {
153 concepts::check<Input const>();
154 concepts::check<Output>();
155
156 resolve_variant::buffer<Input>::apply(geometry_in, distance, chord_length, geometry_out);
157 }
158
159 /*!
160 \brief \brief_calc{buffer}
161 \ingroup buffer
162 \details \details_calc{return_buffer, \det_buffer}. \details_return{buffer}.
163 \tparam Input \tparam_geometry
164 \tparam Output \tparam_geometry
165 \tparam Distance \tparam_numeric
166 \param geometry \param_geometry
167 \param distance The distance to be used for the buffer
168 \param chord_length (optional) The length of the chord's in the generated arcs
169 around points or bends (RESERVED, NOT YET USED)
170 \return \return_calc{buffer}
171 */
172 template <typename Output, typename Input, typename Distance>
173 Output return_buffer(Input const& geometry, Distance const& distance, Distance const& chord_length = -1)
174 {
175 concepts::check<Input const>();
176 concepts::check<Output>();
177
178 Output geometry_out;
179
180 resolve_variant::buffer<Input>::apply(geometry, distance, chord_length, geometry_out);
181
182 return geometry_out;
183 }
184
185 /*!
186 \brief \brief_calc{buffer}
187 \ingroup buffer
188 \details \details_calc{buffer, \det_buffer}.
189 \tparam GeometryIn \tparam_geometry
190 \tparam MultiPolygon \tparam_geometry{MultiPolygon}
191 \tparam DistanceStrategy A strategy defining distance (or radius)
192 \tparam SideStrategy A strategy defining creation along sides
193 \tparam JoinStrategy A strategy defining creation around convex corners
194 \tparam EndStrategy A strategy defining creation at linestring ends
195 \tparam PointStrategy A strategy defining creation around points
196 \param geometry_in \param_geometry
197 \param geometry_out output multi polygon (or std:: collection of polygons),
198 will contain a buffered version of the input geometry
199 \param distance_strategy The distance strategy to be used
200 \param side_strategy The side strategy to be used
201 \param join_strategy The join strategy to be used
202 \param end_strategy The end strategy to be used
203 \param point_strategy The point strategy to be used
204
205 \qbk{distinguish,with strategies}
206 \qbk{[include reference/algorithms/buffer_with_strategies.qbk]}
207 */
208 template
209 <
210 typename GeometryIn,
211 typename MultiPolygon,
212 typename DistanceStrategy,
213 typename SideStrategy,
214 typename JoinStrategy,
215 typename EndStrategy,
216 typename PointStrategy
217 >
218 inline void buffer(GeometryIn const& geometry_in,
219 MultiPolygon& geometry_out,
220 DistanceStrategy const& distance_strategy,
221 SideStrategy const& side_strategy,
222 JoinStrategy const& join_strategy,
223 EndStrategy const& end_strategy,
224 PointStrategy const& point_strategy)
225 {
226 typedef typename boost::range_value<MultiPolygon>::type polygon_type;
227 concepts::check<GeometryIn const>();
228 concepts::check<polygon_type>();
229
230 typedef typename point_type<GeometryIn>::type point_type;
231 typedef typename rescale_policy_type
232 <
233 point_type,
234 typename geometry::cs_tag<point_type>::type
235 >::type rescale_policy_type;
236
237 geometry_out.clear();
238
239 if (geometry::is_empty(geometry_in))
240 {
241 // Then output geometry is kept empty as well
242 return;
243 }
244
245 model::box<point_type> box;
246 geometry::envelope(geometry_in, box);
247 geometry::buffer(box, box, distance_strategy.max_distance(join_strategy, end_strategy));
248
249 typename strategies::buffer::services::default_strategy
250 <
251 GeometryIn
252 >::type strategies;
253
254 rescale_policy_type rescale_policy
255 = boost::geometry::get_rescale_policy<rescale_policy_type>(
256 box, strategies);
257
258 detail::buffer::buffer_inserter<polygon_type>(geometry_in,
259 range::back_inserter(geometry_out),
260 distance_strategy,
261 side_strategy,
262 join_strategy,
263 end_strategy,
264 point_strategy,
265 strategies,
266 rescale_policy);
267 }
268
269
270 }} // namespace boost::geometry
271
272 #endif // BOOST_GEOMETRY_ALGORITHMS_BUFFER_HPP