Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2013 Barend Gehrels, Amsterdam, the Netherlands.
0004 // Copyright (c) 2013 Bruno Lalande, Paris, France.
0005 // Copyright (c) 2013 Mateusz Loskot, London, UK.
0006 // Copyright (c) 2013 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 // Use, modification and distribution is subject to the Boost Software License,
0013 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0014 // http://www.boost.org/LICENSE_1_0.txt)
0015 
0016 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_RECALCULATE_HPP
0017 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_RECALCULATE_HPP
0018 
0019 
0020 #include <cstddef>
0021 
0022 #include <boost/concept/requires.hpp>
0023 #include <boost/concept_check.hpp>
0024 #include <boost/numeric/conversion/bounds.hpp>
0025 #include <boost/numeric/conversion/cast.hpp>
0026 #include <boost/range/begin.hpp>
0027 #include <boost/range/end.hpp>
0028 #include <boost/range/size.hpp>
0029 
0030 #include <boost/geometry/arithmetic/arithmetic.hpp>
0031 #include <boost/geometry/algorithms/append.hpp>
0032 #include <boost/geometry/algorithms/clear.hpp>
0033 #include <boost/geometry/core/access.hpp>
0034 #include <boost/geometry/core/interior_rings.hpp>
0035 #include <boost/geometry/core/exterior_ring.hpp>
0036 #include <boost/geometry/core/tags.hpp>
0037 
0038 #include <boost/geometry/geometries/concepts/check.hpp>
0039 
0040 
0041 namespace boost { namespace geometry
0042 {
0043 
0044 #ifndef DOXYGEN_NO_DETAIL
0045 namespace detail { namespace recalculate
0046 {
0047 
0048 template <std::size_t Dimension>
0049 struct recalculate_point
0050 {
0051     template <typename Point1, typename Point2, typename Strategy>
0052     static inline void apply(Point1& point1, Point2 const& point2, Strategy const& strategy)
0053     {
0054         std::size_t const dim = Dimension - 1;
0055         geometry::set<dim>(point1, strategy.template apply<dim>(geometry::get<dim>(point2)));
0056         recalculate_point<dim>::apply(point1, point2, strategy);
0057     }
0058 };
0059 
0060 template <>
0061 struct recalculate_point<0>
0062 {
0063     template <typename Point1, typename Point2, typename Strategy>
0064     static inline void apply(Point1&, Point2 const&, Strategy const&)
0065     {
0066     }
0067 };
0068 
0069 
0070 template <std::size_t Dimension>
0071 struct recalculate_indexed
0072 {
0073     template <typename Geometry1, typename Geometry2, typename Strategy>
0074     static inline void apply(Geometry1& geometry1, Geometry2 const& geometry2, Strategy const& strategy)
0075     {
0076         // Do it for both indices in one dimension
0077         static std::size_t const dim = Dimension - 1;
0078         geometry::set<0, dim>(geometry1, strategy.template apply<dim>(geometry::get<0, dim>(geometry2)));
0079         geometry::set<1, dim>(geometry1, strategy.template apply<dim>(geometry::get<1, dim>(geometry2)));
0080         recalculate_indexed<dim>::apply(geometry1, geometry2, strategy);
0081     }
0082 };
0083 
0084 template <>
0085 struct recalculate_indexed<0>
0086 {
0087 
0088     template <typename Geometry1, typename Geometry2, typename Strategy>
0089     static inline void apply(Geometry1& , Geometry2 const& , Strategy const& )
0090     {
0091     }
0092 };
0093 
0094 struct range_to_range
0095 {
0096     template
0097     <
0098         typename Range1,
0099         typename Range2,
0100         typename Strategy
0101     >
0102     static inline void apply(Range1& destination, Range2 const& source,
0103             Strategy const& strategy)
0104     {
0105         typedef typename geometry::point_type<Range2>::type point_type;
0106         typedef recalculate_point<geometry::dimension<point_type>::value> per_point;
0107         geometry::clear(destination);
0108 
0109         for (auto const& source_point : source)
0110         {
0111             point_type p;
0112             per_point::apply(p, source_point, strategy);
0113             geometry::append(destination, p);
0114         }
0115     }
0116 };
0117 
0118 struct polygon_to_polygon
0119 {
0120 private:
0121     template
0122     <
0123         typename IteratorIn,
0124         typename IteratorOut,
0125         typename Strategy
0126     >
0127     static inline void iterate(IteratorIn begin, IteratorIn end,
0128                     IteratorOut it_out,
0129                     Strategy const& strategy)
0130     {
0131         for (IteratorIn it_in = begin; it_in != end;  ++it_in, ++it_out)
0132         {
0133             range_to_range::apply(*it_out, *it_in, strategy);
0134         }
0135     }
0136 
0137     template
0138     <
0139         typename InteriorRingsOut,
0140         typename InteriorRingsIn,
0141         typename Strategy
0142     >
0143     static inline void apply_interior_rings(
0144                     InteriorRingsOut& interior_rings_out,
0145                     InteriorRingsIn const& interior_rings_in,
0146                     Strategy const& strategy)
0147     {
0148         traits::resize<InteriorRingsOut>::apply(interior_rings_out,
0149             boost::size(interior_rings_in));
0150 
0151         iterate(
0152             boost::begin(interior_rings_in), boost::end(interior_rings_in),
0153             boost::begin(interior_rings_out),
0154             strategy);
0155     }
0156 
0157 public:
0158     template
0159     <
0160         typename Polygon1,
0161         typename Polygon2,
0162         typename Strategy
0163     >
0164     static inline void apply(Polygon1& destination, Polygon2 const& source,
0165             Strategy const& strategy)
0166     {
0167         range_to_range::apply(geometry::exterior_ring(destination),
0168             geometry::exterior_ring(source), strategy);
0169 
0170         apply_interior_rings(geometry::interior_rings(destination),
0171             geometry::interior_rings(source), strategy);
0172     }
0173 };
0174 
0175 }} // namespace detail::recalculate
0176 #endif // DOXYGEN_NO_DETAIL
0177 
0178 #ifndef DOXYGEN_NO_DISPATCH
0179 namespace dispatch
0180 {
0181 
0182 template
0183 <
0184     typename Geometry1,
0185     typename Geometry2,
0186     typename Tag1 = typename geometry::tag<Geometry1>::type,
0187     typename Tag2 = typename geometry::tag<Geometry2>::type
0188 >
0189 struct recalculate : not_implemented<Tag1, Tag2>
0190 {};
0191 
0192 template <typename Point1, typename Point2>
0193 struct recalculate<Point1, Point2, point_tag, point_tag>
0194     : detail::recalculate::recalculate_point<geometry::dimension<Point1>::value>
0195 {};
0196 
0197 template <typename Box1, typename Box2>
0198 struct recalculate<Box1, Box2, box_tag, box_tag>
0199     : detail::recalculate::recalculate_indexed<geometry::dimension<Box1>::value>
0200 {};
0201 
0202 template <typename Segment1, typename Segment2>
0203 struct recalculate<Segment1, Segment2, segment_tag, segment_tag>
0204     : detail::recalculate::recalculate_indexed<geometry::dimension<Segment1>::value>
0205 {};
0206 
0207 template <typename Polygon1, typename Polygon2>
0208 struct recalculate<Polygon1, Polygon2, polygon_tag, polygon_tag>
0209     : detail::recalculate::polygon_to_polygon
0210 {};
0211 
0212 } // namespace dispatch
0213 #endif // DOXYGEN_NO_DISPATCH
0214 
0215 
0216 
0217 template <typename Geometry1, typename Geometry2, typename Strategy>
0218 inline void recalculate(Geometry1& geometry1, Geometry2 const& geometry2, Strategy const& strategy)
0219 {
0220     concepts::check<Geometry1>();
0221     concepts::check<Geometry2 const>();
0222 
0223     // static assert dimensions (/types) are the same
0224 
0225     dispatch::recalculate<Geometry1, Geometry2>::apply(geometry1, geometry2, strategy);
0226 }
0227 
0228 
0229 }} // namespace boost::geometry
0230 
0231 
0232 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_RECALCULATE_HPP