1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
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
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)
16 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_RECALCULATE_HPP
17 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_RECALCULATE_HPP
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>
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>
38 #include <boost/geometry/geometries/concepts/check.hpp>
41 namespace boost { namespace geometry
44 #ifndef DOXYGEN_NO_DETAIL
45 namespace detail { namespace recalculate
48 template <std::size_t Dimension>
49 struct recalculate_point
51 template <typename Point1, typename Point2, typename Strategy>
52 static inline void apply(Point1& point1, Point2 const& point2, Strategy const& strategy)
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);
61 struct recalculate_point<0>
63 template <typename Point1, typename Point2, typename Strategy>
64 static inline void apply(Point1&, Point2 const&, Strategy const&)
70 template <std::size_t Dimension>
71 struct recalculate_indexed
73 template <typename Geometry1, typename Geometry2, typename Strategy>
74 static inline void apply(Geometry1& geometry1, Geometry2 const& geometry2, Strategy const& strategy)
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);
85 struct recalculate_indexed<0>
88 template <typename Geometry1, typename Geometry2, typename Strategy>
89 static inline void apply(Geometry1& , Geometry2 const& , Strategy const& )
102 static inline void apply(Range1& destination, Range2 const& source,
103 Strategy const& strategy)
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);
109 for (typename boost::range_iterator<Range2 const>::type it
110 = boost::begin(source);
111 it != boost::end(source);
115 per_point::apply(p, *it, strategy);
116 geometry::append(destination, p);
121 struct polygon_to_polygon
127 typename IteratorOut,
130 static inline void iterate(IteratorIn begin, IteratorIn end,
132 Strategy const& strategy)
134 for (IteratorIn it_in = begin; it_in != end; ++it_in, ++it_out)
136 range_to_range::apply(*it_out, *it_in, strategy);
142 typename InteriorRingsOut,
143 typename InteriorRingsIn,
146 static inline void apply_interior_rings(
147 InteriorRingsOut& interior_rings_out,
148 InteriorRingsIn const& interior_rings_in,
149 Strategy const& strategy)
151 traits::resize<InteriorRingsOut>::apply(interior_rings_out,
152 boost::size(interior_rings_in));
155 boost::begin(interior_rings_in), boost::end(interior_rings_in),
156 boost::begin(interior_rings_out),
167 static inline void apply(Polygon1& destination, Polygon2 const& source,
168 Strategy const& strategy)
170 range_to_range::apply(geometry::exterior_ring(destination),
171 geometry::exterior_ring(source), strategy);
173 apply_interior_rings(geometry::interior_rings(destination),
174 geometry::interior_rings(source), strategy);
178 }} // namespace detail::recalculate
179 #endif // DOXYGEN_NO_DETAIL
181 #ifndef DOXYGEN_NO_DISPATCH
189 typename Tag1 = typename geometry::tag<Geometry1>::type,
190 typename Tag2 = typename geometry::tag<Geometry2>::type
192 struct recalculate : not_implemented<Tag1, Tag2>
195 template <typename Point1, typename Point2>
196 struct recalculate<Point1, Point2, point_tag, point_tag>
197 : detail::recalculate::recalculate_point<geometry::dimension<Point1>::value>
200 template <typename Box1, typename Box2>
201 struct recalculate<Box1, Box2, box_tag, box_tag>
202 : detail::recalculate::recalculate_indexed<geometry::dimension<Box1>::value>
205 template <typename Segment1, typename Segment2>
206 struct recalculate<Segment1, Segment2, segment_tag, segment_tag>
207 : detail::recalculate::recalculate_indexed<geometry::dimension<Segment1>::value>
210 template <typename Polygon1, typename Polygon2>
211 struct recalculate<Polygon1, Polygon2, polygon_tag, polygon_tag>
212 : detail::recalculate::polygon_to_polygon
215 } // namespace dispatch
216 #endif // DOXYGEN_NO_DISPATCH
220 template <typename Geometry1, typename Geometry2, typename Strategy>
221 inline void recalculate(Geometry1& geometry1, Geometry2 const& geometry2, Strategy const& strategy)
223 concepts::check<Geometry1>();
224 concepts::check<Geometry2 const>();
226 // static assert dimensions (/types) are the same
228 dispatch::recalculate<Geometry1, Geometry2>::apply(geometry1, geometry2, strategy);
232 }} // namespace boost::geometry
235 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_RECALCULATE_HPP