// Boost.Geometry (aka GGL, Generic Geometry Library) // Copyright (c) 2013 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2013 Bruno Lalande, Paris, France. // Copyright (c) 2013 Mateusz Loskot, London, UK. // Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland. // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_RECALCULATE_HPP #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_RECALCULATE_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace geometry { #ifndef DOXYGEN_NO_DETAIL namespace detail { namespace recalculate { template struct recalculate_point { template static inline void apply(Point1& point1, Point2 const& point2, Strategy const& strategy) { std::size_t const dim = Dimension - 1; geometry::set(point1, strategy.template apply(geometry::get(point2))); recalculate_point::apply(point1, point2, strategy); } }; template <> struct recalculate_point<0> { template static inline void apply(Point1&, Point2 const&, Strategy const&) { } }; template struct recalculate_indexed { template static inline void apply(Geometry1& geometry1, Geometry2 const& geometry2, Strategy const& strategy) { // Do it for both indices in one dimension static std::size_t const dim = Dimension - 1; geometry::set<0, dim>(geometry1, strategy.template apply(geometry::get<0, dim>(geometry2))); geometry::set<1, dim>(geometry1, strategy.template apply(geometry::get<1, dim>(geometry2))); recalculate_indexed::apply(geometry1, geometry2, strategy); } }; template <> struct recalculate_indexed<0> { template static inline void apply(Geometry1& , Geometry2 const& , Strategy const& ) { } }; struct range_to_range { template < typename Range1, typename Range2, typename Strategy > static inline void apply(Range1& destination, Range2 const& source, Strategy const& strategy) { typedef typename geometry::point_type::type point_type; typedef recalculate_point::value> per_point; geometry::clear(destination); for (typename boost::range_iterator::type it = boost::begin(source); it != boost::end(source); ++it) { point_type p; per_point::apply(p, *it, strategy); geometry::append(destination, p); } } }; struct polygon_to_polygon { private: template < typename IteratorIn, typename IteratorOut, typename Strategy > static inline void iterate(IteratorIn begin, IteratorIn end, IteratorOut it_out, Strategy const& strategy) { for (IteratorIn it_in = begin; it_in != end; ++it_in, ++it_out) { range_to_range::apply(*it_out, *it_in, strategy); } } template < typename InteriorRingsOut, typename InteriorRingsIn, typename Strategy > static inline void apply_interior_rings( InteriorRingsOut& interior_rings_out, InteriorRingsIn const& interior_rings_in, Strategy const& strategy) { traits::resize::apply(interior_rings_out, boost::size(interior_rings_in)); iterate( boost::begin(interior_rings_in), boost::end(interior_rings_in), boost::begin(interior_rings_out), strategy); } public: template < typename Polygon1, typename Polygon2, typename Strategy > static inline void apply(Polygon1& destination, Polygon2 const& source, Strategy const& strategy) { range_to_range::apply(geometry::exterior_ring(destination), geometry::exterior_ring(source), strategy); apply_interior_rings(geometry::interior_rings(destination), geometry::interior_rings(source), strategy); } }; }} // namespace detail::recalculate #endif // DOXYGEN_NO_DETAIL #ifndef DOXYGEN_NO_DISPATCH namespace dispatch { template < typename Geometry1, typename Geometry2, typename Tag1 = typename geometry::tag::type, typename Tag2 = typename geometry::tag::type > struct recalculate : not_implemented {}; template struct recalculate : detail::recalculate::recalculate_point::value> {}; template struct recalculate : detail::recalculate::recalculate_indexed::value> {}; template struct recalculate : detail::recalculate::recalculate_indexed::value> {}; template struct recalculate : detail::recalculate::polygon_to_polygon {}; } // namespace dispatch #endif // DOXYGEN_NO_DISPATCH template inline void recalculate(Geometry1& geometry1, Geometry2 const& geometry2, Strategy const& strategy) { concept::check(); concept::check(); // static assert dimensions (/types) are the same dispatch::recalculate::apply(geometry1, geometry2, strategy); } }} // namespace boost::geometry #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_RECALCULATE_HPP