X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=boost%2Fgeometry%2Falgorithms%2Ftransform.hpp;h=1d6e8d0a35b337bddfc03d37cf01671c50550f6b;hb=08c1e93fa36a49f49325a07fe91ff92c964c2b6c;hp=22b45dc77ee1eb33772bdc3460e2dcd3541dad3b;hpb=bb4dd8289b351fae6b55e303f189127a394a1edd;p=platform%2Fupstream%2Fboost.git diff --git a/boost/geometry/algorithms/transform.hpp b/boost/geometry/algorithms/transform.hpp index 22b45dc..1d6e8d0 100644 --- a/boost/geometry/algorithms/transform.hpp +++ b/boost/geometry/algorithms/transform.hpp @@ -3,6 +3,7 @@ // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. @@ -18,10 +19,14 @@ #include #include -#include +#include +#include +#include +#include #include #include +#include #include #include @@ -30,7 +35,9 @@ #include #include #include +#include #include +#include #include @@ -41,9 +48,9 @@ namespace boost { namespace geometry namespace detail { namespace transform { -template struct transform_point { + template static inline bool apply(Point1 const& p1, Point2& p2, Strategy const& strategy) { @@ -52,9 +59,9 @@ struct transform_point }; -template struct transform_box { + template static inline bool apply(Box1 const& b1, Box2& b2, Strategy const& strategy) { @@ -91,9 +98,9 @@ struct transform_box } }; -template struct transform_box_or_segment { + template static inline bool apply(Geometry1 const& source, Geometry2& target, Strategy const& strategy) { @@ -133,12 +140,7 @@ inline bool transform_range_out(Range const& range, it != boost::end(range); ++it) { - if (! transform_point - < - typename point_type::type, - PointOut, - Strategy - >::apply(*it, point_out, strategy)) + if (! transform_point::apply(*it, point_out, strategy)) { return false; } @@ -148,14 +150,12 @@ inline bool transform_range_out(Range const& range, } -template struct transform_polygon { + template static inline bool apply(Polygon1 const& poly1, Polygon2& poly2, Strategy const& strategy) { - typedef typename ring_type::type ring1_type; - typedef typename ring_type::type ring2_type; typedef typename point_type::type point2_type; geometry::clear(poly2); @@ -175,16 +175,20 @@ struct transform_polygon >::type >::apply(interior_rings(poly2), num_interior_rings(poly1)); - typename interior_return_type::type rings1 - = interior_rings(poly1); - typename interior_return_type::type rings2 - = interior_rings(poly2); - BOOST_AUTO_TPL(it1, boost::begin(rings1)); - BOOST_AUTO_TPL(it2, boost::begin(rings2)); - for ( ; it1 != boost::end(interior_rings(poly1)); ++it1, ++it2) + typename interior_return_type::type + rings1 = interior_rings(poly1); + typename interior_return_type::type + rings2 = interior_rings(poly2); + + typename detail::interior_iterator::type + it1 = boost::begin(rings1); + typename detail::interior_iterator::type + it2 = boost::begin(rings2); + for ( ; it1 != boost::end(rings1); ++it1, ++it2) { - if (!transform_range_out(*it1, - std::back_inserter(*it2), strategy)) + if ( ! transform_range_out(*it1, + std::back_inserter(*it2), + strategy) ) { return false; } @@ -211,9 +215,9 @@ struct select_strategy >::type type; }; -template struct transform_range { + template static inline bool apply(Range1 const& range1, Range2& range2, Strategy const& strategy) { @@ -226,6 +230,36 @@ struct transform_range } }; + +/*! + \brief Is able to transform any multi-geometry, calling the single-version as policy +*/ +template +struct transform_multi +{ + template + static inline bool apply(Multi1 const& multi1, Multi2& multi2, S const& strategy) + { + traits::resize::apply(multi2, boost::size(multi1)); + + typename boost::range_iterator::type it1 + = boost::begin(multi1); + typename boost::range_iterator::type it2 + = boost::begin(multi2); + + for (; it1 != boost::end(multi1); ++it1, ++it2) + { + if (! Policy::apply(*it1, *it2, strategy)) + { + return false; + } + } + + return true; + } +}; + + }} // namespace detail::transform #endif // DOXYGEN_NO_DETAIL @@ -236,58 +270,166 @@ namespace dispatch template < - typename Tag1, typename Tag2, typename Geometry1, typename Geometry2, - typename Strategy + typename Tag1 = typename tag_cast::type, multi_tag>::type, + typename Tag2 = typename tag_cast::type, multi_tag>::type > struct transform {}; -template -struct transform - : detail::transform::transform_point +template +struct transform + : detail::transform::transform_point { }; -template +template struct transform < - linestring_tag, linestring_tag, - Linestring1, Linestring2, Strategy + Linestring1, Linestring2, + linestring_tag, linestring_tag > - : detail::transform::transform_range + : detail::transform::transform_range { }; -template -struct transform - : detail::transform::transform_range +template +struct transform + : detail::transform::transform_range { }; -template -struct transform - : detail::transform::transform_polygon +template +struct transform + : detail::transform::transform_polygon { }; -template -struct transform - : detail::transform::transform_box +template +struct transform + : detail::transform::transform_box { }; -template -struct transform - : detail::transform::transform_box_or_segment +template +struct transform + : detail::transform::transform_box_or_segment { }; +template +struct transform + < + Multi1, Multi2, + multi_tag, multi_tag + > + : detail::transform::transform_multi + < + dispatch::transform + < + typename boost::range_value::type, + typename boost::range_value::type + > + > +{}; + } // namespace dispatch #endif // DOXYGEN_NO_DISPATCH +namespace resolve_strategy { + +struct transform +{ + template + static inline bool apply(Geometry1 const& geometry1, + Geometry2& geometry2, + Strategy const& strategy) + { + concept::check(); + concept::check(); + + return dispatch::transform::apply( + geometry1, + geometry2, + strategy + ); + } + + template + static inline bool apply(Geometry1 const& geometry1, + Geometry2& geometry2, + default_strategy) + { + return apply( + geometry1, + geometry2, + typename detail::transform::select_strategy::type() + ); + } +}; + +} // namespace resolve_strategy + + +namespace resolve_variant { + +template +struct transform +{ + template + static inline bool apply(Geometry1 const& geometry1, + Geometry2& geometry2, + Strategy const& strategy) + { + return resolve_strategy::transform::apply( + geometry1, + geometry2, + strategy + ); + } +}; + +template +struct transform, Geometry2> +{ + template + struct visitor: static_visitor + { + Geometry2& m_geometry2; + Strategy const& m_strategy; + + visitor(Geometry2& geometry2, Strategy const& strategy) + : m_geometry2(geometry2) + , m_strategy(strategy) + {} + + template + inline bool operator()(Geometry1 const& geometry1) const + { + return transform::apply( + geometry1, + m_geometry2, + m_strategy + ); + } + }; + + template + static inline bool apply( + boost::variant const& geometry1, + Geometry2& geometry2, + Strategy const& strategy + ) + { + return apply_visitor(visitor(geometry2, strategy), geometry1); + } +}; + +} // namespace resolve_variant + + /*! \brief Transforms from one geometry to another geometry \brief_strategy \ingroup transform @@ -307,19 +449,8 @@ template inline bool transform(Geometry1 const& geometry1, Geometry2& geometry2, Strategy const& strategy) { - concept::check(); - concept::check(); - - typedef dispatch::transform - < - typename tag_cast::type, multi_tag>::type, - typename tag_cast::type, multi_tag>::type, - Geometry1, - Geometry2, - Strategy - > transform_type; - - return transform_type::apply(geometry1, geometry2, strategy); + return resolve_variant::transform + ::apply(geometry1, geometry2, strategy); } @@ -337,11 +468,7 @@ inline bool transform(Geometry1 const& geometry1, Geometry2& geometry2, template inline bool transform(Geometry1 const& geometry1, Geometry2& geometry2) { - concept::check(); - concept::check(); - - typename detail::transform::select_strategy::type strategy; - return transform(geometry1, geometry2, strategy); + return transform(geometry1, geometry2, default_strategy()); }