]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/algorithms/detail/recalculate.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / detail / recalculate.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2013 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2013 Bruno Lalande, Paris, France.
5 // Copyright (c) 2013 Mateusz Loskot, London, UK.
6 // Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland.
7
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
12 // Use, modification and distribution is subject to the Boost Software License,
13 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
14 // http://www.boost.org/LICENSE_1_0.txt)
15
16 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_RECALCULATE_HPP
17 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_RECALCULATE_HPP
18
19
20 #include <cstddef>
21
22 #include <boost/concept/requires.hpp>
23 #include <boost/concept_check.hpp>
24 #include <boost/numeric/conversion/bounds.hpp>
25 #include <boost/numeric/conversion/cast.hpp>
26 #include <boost/range/begin.hpp>
27 #include <boost/range/end.hpp>
28 #include <boost/range/size.hpp>
29
30 #include <boost/geometry/arithmetic/arithmetic.hpp>
31 #include <boost/geometry/algorithms/append.hpp>
32 #include <boost/geometry/algorithms/clear.hpp>
33 #include <boost/geometry/core/access.hpp>
34 #include <boost/geometry/core/interior_rings.hpp>
35 #include <boost/geometry/core/exterior_ring.hpp>
36 #include <boost/geometry/core/tags.hpp>
37
38 #include <boost/geometry/geometries/concepts/check.hpp>
39
40
41 namespace boost { namespace geometry
42 {
43
44 #ifndef DOXYGEN_NO_DETAIL
45 namespace detail { namespace recalculate
46 {
47
48 template <std::size_t Dimension>
49 struct recalculate_point
50 {
51 template <typename Point1, typename Point2, typename Strategy>
52 static inline void apply(Point1& point1, Point2 const& point2, Strategy const& strategy)
53 {
54 std::size_t const dim = Dimension - 1;
55 geometry::set<dim>(point1, strategy.template apply<dim>(geometry::get<dim>(point2)));
56 recalculate_point<dim>::apply(point1, point2, strategy);
57 }
58 };
59
60 template <>
61 struct recalculate_point<0>
62 {
63 template <typename Point1, typename Point2, typename Strategy>
64 static inline void apply(Point1&, Point2 const&, Strategy const&)
65 {
66 }
67 };
68
69
70 template <std::size_t Dimension>
71 struct recalculate_indexed
72 {
73 template <typename Geometry1, typename Geometry2, typename Strategy>
74 static inline void apply(Geometry1& geometry1, Geometry2 const& geometry2, Strategy const& strategy)
75 {
76 // Do it for both indices in one dimension
77 static std::size_t const dim = Dimension - 1;
78 geometry::set<0, dim>(geometry1, strategy.template apply<dim>(geometry::get<0, dim>(geometry2)));
79 geometry::set<1, dim>(geometry1, strategy.template apply<dim>(geometry::get<1, dim>(geometry2)));
80 recalculate_indexed<dim>::apply(geometry1, geometry2, strategy);
81 }
82 };
83
84 template <>
85 struct recalculate_indexed<0>
86 {
87
88 template <typename Geometry1, typename Geometry2, typename Strategy>
89 static inline void apply(Geometry1& , Geometry2 const& , Strategy const& )
90 {
91 }
92 };
93
94 struct range_to_range
95 {
96 template
97 <
98 typename Range1,
99 typename Range2,
100 typename Strategy
101 >
102 static inline void apply(Range1& destination, Range2 const& source,
103 Strategy const& strategy)
104 {
105 typedef typename geometry::point_type<Range2>::type point_type;
106 typedef recalculate_point<geometry::dimension<point_type>::value> per_point;
107 geometry::clear(destination);
108
109 for (typename boost::range_iterator<Range2 const>::type it
110 = boost::begin(source);
111 it != boost::end(source);
112 ++it)
113 {
114 point_type p;
115 per_point::apply(p, *it, strategy);
116 geometry::append(destination, p);
117 }
118 }
119 };
120
121 struct polygon_to_polygon
122 {
123 private:
124 template
125 <
126 typename IteratorIn,
127 typename IteratorOut,
128 typename Strategy
129 >
130 static inline void iterate(IteratorIn begin, IteratorIn end,
131 IteratorOut it_out,
132 Strategy const& strategy)
133 {
134 for (IteratorIn it_in = begin; it_in != end; ++it_in, ++it_out)
135 {
136 range_to_range::apply(*it_out, *it_in, strategy);
137 }
138 }
139
140 template
141 <
142 typename InteriorRingsOut,
143 typename InteriorRingsIn,
144 typename Strategy
145 >
146 static inline void apply_interior_rings(
147 InteriorRingsOut& interior_rings_out,
148 InteriorRingsIn const& interior_rings_in,
149 Strategy const& strategy)
150 {
151 traits::resize<InteriorRingsOut>::apply(interior_rings_out,
152 boost::size(interior_rings_in));
153
154 iterate(
155 boost::begin(interior_rings_in), boost::end(interior_rings_in),
156 boost::begin(interior_rings_out),
157 strategy);
158 }
159
160 public:
161 template
162 <
163 typename Polygon1,
164 typename Polygon2,
165 typename Strategy
166 >
167 static inline void apply(Polygon1& destination, Polygon2 const& source,
168 Strategy const& strategy)
169 {
170 range_to_range::apply(geometry::exterior_ring(destination),
171 geometry::exterior_ring(source), strategy);
172
173 apply_interior_rings(geometry::interior_rings(destination),
174 geometry::interior_rings(source), strategy);
175 }
176 };
177
178 }} // namespace detail::recalculate
179 #endif // DOXYGEN_NO_DETAIL
180
181 #ifndef DOXYGEN_NO_DISPATCH
182 namespace dispatch
183 {
184
185 template
186 <
187 typename Geometry1,
188 typename Geometry2,
189 typename Tag1 = typename geometry::tag<Geometry1>::type,
190 typename Tag2 = typename geometry::tag<Geometry2>::type
191 >
192 struct recalculate : not_implemented<Tag1, Tag2>
193 {};
194
195 template <typename Point1, typename Point2>
196 struct recalculate<Point1, Point2, point_tag, point_tag>
197 : detail::recalculate::recalculate_point<geometry::dimension<Point1>::value>
198 {};
199
200 template <typename Box1, typename Box2>
201 struct recalculate<Box1, Box2, box_tag, box_tag>
202 : detail::recalculate::recalculate_indexed<geometry::dimension<Box1>::value>
203 {};
204
205 template <typename Segment1, typename Segment2>
206 struct recalculate<Segment1, Segment2, segment_tag, segment_tag>
207 : detail::recalculate::recalculate_indexed<geometry::dimension<Segment1>::value>
208 {};
209
210 template <typename Polygon1, typename Polygon2>
211 struct recalculate<Polygon1, Polygon2, polygon_tag, polygon_tag>
212 : detail::recalculate::polygon_to_polygon
213 {};
214
215 } // namespace dispatch
216 #endif // DOXYGEN_NO_DISPATCH
217
218
219
220 template <typename Geometry1, typename Geometry2, typename Strategy>
221 inline void recalculate(Geometry1& geometry1, Geometry2 const& geometry2, Strategy const& strategy)
222 {
223 concepts::check<Geometry1>();
224 concepts::check<Geometry2 const>();
225
226 // static assert dimensions (/types) are the same
227
228 dispatch::recalculate<Geometry1, Geometry2>::apply(geometry1, geometry2, strategy);
229 }
230
231
232 }} // namespace boost::geometry
233
234
235 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_RECALCULATE_HPP