From ccc40d3a0bcf5a6daad5784cb6d996c1faf41d80 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Wed, 9 Apr 2014 21:53:12 +0200 Subject: [PATCH] [relate] cleanup, increase the readability of relate() dispatching, remove unneeded code --- include/boost/geometry/algorithms/crosses.hpp | 51 +---- .../algorithms/detail/relate/areal_areal.hpp | 66 +++--- .../algorithms/detail/relate/relate.hpp | 207 +++++++----------- .../algorithms/detail/relate/turns.hpp | 80 ------- 4 files changed, 112 insertions(+), 292 deletions(-) diff --git a/include/boost/geometry/algorithms/crosses.hpp b/include/boost/geometry/algorithms/crosses.hpp index 8effd3b59..caf380753 100644 --- a/include/boost/geometry/algorithms/crosses.hpp +++ b/include/boost/geometry/algorithms/crosses.hpp @@ -23,8 +23,6 @@ #include -#include - #include #include @@ -32,46 +30,6 @@ namespace boost { namespace geometry { -#ifndef DOXYGEN_NO_DETAIL -namespace detail { namespace crosses -{ - -struct use_relate -{ - template - static inline bool apply(Geometry1 const& g1, Geometry2 const& g2) - { - typedef typename detail::relate:: - static_mask_crosses_type::type static_mask; - - return detail::relate::relate(g1, g2); - } -}; - -}} // namespace detail::crosses -#endif // DOXYGEN_NO_DETAIL - -#ifndef DOXYGEN_NO_DISPATCH -namespace dispatch -{ - - -template -< - typename Geometry1, - typename Geometry2, - typename Tag1 = typename tag::type, - typename Tag2 = typename tag::type -> -struct crosses - : detail::crosses::use_relate -{}; - - -} // namespace dispatch -#endif // DOXYGEN_NO_DISPATCH - - /*! \brief \brief_check2{crosses} \ingroup crosses @@ -89,11 +47,10 @@ inline bool crosses(Geometry1 const& geometry1, Geometry2 const& geometry2) concept::check(); concept::check(); - return dispatch::crosses - < - Geometry1, - Geometry2 - >::apply(geometry1, geometry2); + typedef typename detail::relate:: + static_mask_crosses_type::type static_mask; + + return detail::relate::relate(geometry1, geometry2); } }} // namespace boost::geometry diff --git a/include/boost/geometry/algorithms/detail/relate/areal_areal.hpp b/include/boost/geometry/algorithms/detail/relate/areal_areal.hpp index e44c008a7..bc5b619a7 100644 --- a/include/boost/geometry/algorithms/detail/relate/areal_areal.hpp +++ b/include/boost/geometry/algorithms/detail/relate/areal_areal.hpp @@ -100,8 +100,9 @@ public: // Check if any interior ring is outside ring_identifier ring_id(0, -1, 0); - for ( ; ring_id.ring_index < boost::numeric_cast(geometry::num_interior_rings(areal)) ; - ++ring_id.ring_index ) + int const irings_count = boost::numeric_cast( + geometry::num_interior_rings(areal) ); + for ( ; ring_id.ring_index < irings_count ; ++ring_id.ring_index ) { typename detail::sub_range_return_type::type range_ref = detail::sub_range(areal, ring_id); @@ -135,8 +136,9 @@ public: // Check if any interior ring is inside ring_identifier ring_id(0, -1, 0); - for ( ; ring_id.ring_index < boost::numeric_cast(geometry::num_interior_rings(areal)) ; - ++ring_id.ring_index ) + int const irings_count = boost::numeric_cast( + geometry::num_interior_rings(areal) ); + for ( ; ring_id.ring_index < irings_count ; ++ring_id.ring_index ) { typename detail::sub_range_return_type::type range_ref = detail::sub_range(areal, ring_id); @@ -237,9 +239,7 @@ struct areal_areal { // analyse sorted turns turns_analyser analyser; - analyse_each_turn(result, analyser, - turns.begin(), turns.end(), - geometry1, geometry2); + analyse_each_turn(result, analyser, turns.begin(), turns.end()); if ( result.interrupt ) return; @@ -278,9 +278,7 @@ struct areal_areal { // analyse sorted turns turns_analyser analyser; - analyse_each_turn(result, analyser, - turns.begin(), turns.end(), - geometry2, geometry1); + analyse_each_turn(result, analyser, turns.begin(), turns.end()); if ( result.interrupt ) return; @@ -401,13 +399,8 @@ struct areal_areal {} template - void apply(Result & result, - TurnIt first, TurnIt it, TurnIt last, - Geometry const& geometry, - OtherGeometry const& other_geometry) + typename TurnIt> + void apply(Result & result, TurnIt it) { //BOOST_ASSERT( it != last ); @@ -499,14 +492,8 @@ struct areal_areal } // it == last - template - void apply(Result & result, - TurnIt first, TurnIt last, - Geometry const& geometry, - OtherGeometry const& other_geometry) + template + void apply(Result & result) { //BOOST_ASSERT( first != last ); @@ -548,30 +535,24 @@ struct areal_areal // call analyser.apply() for each turn in range // IMPORTANT! The analyser is also called for the end iterator - last template + typename TurnIt> static inline void analyse_each_turn(Result & res, Analyser & analyser, - TurnIt first, TurnIt last, - Geometry const& geometry, - OtherGeometry const& other_geometry) + TurnIt first, TurnIt last) { if ( first == last ) return; for ( TurnIt it = first ; it != last ; ++it ) { - analyser.apply(res, first, it, last, - geometry, other_geometry); + analyser.apply(res, it); if ( res.interrupt ) return; } - analyser.apply(res, first, last, - geometry, other_geometry); + analyser.apply(res); } template @@ -810,16 +791,21 @@ struct areal_areal template static inline void for_preceding_rings(Analyser & analyser, Turn const& turn) { - for_no_turns_rings(analyser, turn, -1, turn.operations[OpId].seg_id.ring_index); + segment_identifier const& seg_id = turn.operations[OpId].seg_id; + + for_no_turns_rings(analyser, turn, -1, seg_id.ring_index); } template static inline void for_following_rings(Analyser & analyser, Turn const& turn) { - std::size_t count = geometry::num_interior_rings( - detail::single_geometry(analyser.geometry, - turn.operations[OpId].seg_id)); - for_no_turns_rings(analyser, turn, turn.operations[OpId].seg_id.ring_index + 1, count); + segment_identifier const& seg_id = turn.operations[OpId].seg_id; + + int count = boost::numeric_cast( + geometry::num_interior_rings( + detail::single_geometry(analyser.geometry, seg_id))); + + for_no_turns_rings(analyser, turn, seg_id.ring_index + 1, count); } template diff --git a/include/boost/geometry/algorithms/detail/relate/relate.hpp b/include/boost/geometry/algorithms/detail/relate/relate.hpp index e4253daa1..2b8d96988 100644 --- a/include/boost/geometry/algorithms/detail/relate/relate.hpp +++ b/include/boost/geometry/algorithms/detail/relate/relate.hpp @@ -53,180 +53,137 @@ namespace boost { namespace geometry { #ifndef DOXYGEN_NO_DETAIL -namespace detail_dispatch { namespace relate { +namespace detail { namespace relate { + +// Those are used only to allow dispatch::relate to produce compile-time error + +template ::type> +struct is_supported_by_generic +{ + static const bool value + = boost::is_same::value + || boost::is_same::value + || boost::is_same::value + || boost::is_same::value + || boost::is_same::value; +}; template ::type, typename Tag2 = typename geometry::tag::type> +struct is_generic +{ + static const bool value = is_supported_by_generic::value + && is_supported_by_generic::value; +}; + + +template +struct is_generic +{ + static const bool value = is_supported_by_generic::value; +}; + +template +struct is_generic +{ + static const bool value = is_supported_by_generic::value; +}; + +template +struct is_generic +{ + static const bool value = false; +}; + + +}} // namespace detail::relate + +#ifndef DOXYGEN_NO_DISPATCH +namespace detail_dispatch { namespace relate { + + +template ::type, + typename Tag2 = typename geometry::tag::type, + int TopDim1 = geometry::topological_dimension::value, + int TopDim2 = geometry::topological_dimension::value, + bool IsGeneric = detail::relate::is_generic::value +> struct relate : not_implemented {}; + template -struct relate +struct relate : detail::relate::point_point {}; template -struct relate +struct relate : detail::relate::point_multipoint {}; template -struct relate +struct relate : detail::relate::multipoint_point {}; template -struct relate +struct relate : detail::relate::multipoint_multipoint {}; -//template -//struct relate +//template +//struct relate // : detail::relate::point_box //{}; // -//template -//struct relate +//template +//struct relate // : detail::relate::box_point //{}; -template -struct relate + +template +struct relate : detail::relate::point_geometry {}; -template -struct relate +template +struct relate : detail::relate::geometry_point {}; -template -struct relate - : detail::relate::linear_linear -{}; - -template -struct relate - : detail::relate::linear_linear -{}; - -template -struct relate - : detail::relate::linear_linear -{}; - -template -struct relate - : detail::relate::linear_linear +template +struct relate + : detail::relate::linear_linear {}; -template -struct relate - : detail::relate::linear_areal -{}; -template -struct relate - : detail::relate::linear_areal +template +struct relate + : detail::relate::linear_areal {}; -template -struct relate - : detail::relate::areal_linear -{}; -template -struct relate - : detail::relate::areal_linear -{}; - -template -struct relate - : detail::relate::linear_areal -{}; - -template -struct relate - : detail::relate::areal_linear -{}; - -template -struct relate - : detail::relate::linear_areal -{}; -template -struct relate - : detail::relate::linear_areal -{}; - -template -struct relate - : detail::relate::areal_linear -{}; -template -struct relate - : detail::relate::areal_linear -{}; - -template -struct relate - : detail::relate::linear_areal -{}; - -template -struct relate - : detail::relate::areal_linear +template +struct relate + : detail::relate::areal_linear {}; -template -struct relate - : detail::relate::areal_areal +template +struct relate + : detail::relate::areal_areal {}; -template -struct relate - : detail::relate::areal_areal -{}; - -template -struct relate - : detail::relate::areal_areal -{}; - -template -struct relate - : detail::relate::areal_areal -{}; - -template -struct relate - : detail::relate::areal_areal -{}; - -template -struct relate - : detail::relate::areal_areal -{}; - -template -struct relate - : detail::relate::areal_areal -{}; - -template -struct relate - : detail::relate::areal_areal -{}; - -template -struct relate - : detail::relate::areal_areal -{}; }} // namespace detail_dispatch::relate +#endif // DOXYGEN_NO_DISPATCH namespace detail { namespace relate { diff --git a/include/boost/geometry/algorithms/detail/relate/turns.hpp b/include/boost/geometry/algorithms/detail/relate/turns.hpp index 6664d4529..68eade8f0 100644 --- a/include/boost/geometry/algorithms/detail/relate/turns.hpp +++ b/include/boost/geometry/algorithms/detail/relate/turns.hpp @@ -227,86 +227,6 @@ struct less } }; -//template inline -//bool is_valid_method(Turn const& turn) -//{ -// return turn.method != detail::overlay::method_none -// && turn.method != detail::overlay::method_disjoint -// && turn.method != detail::overlay::method_error; -//} -// -//template inline -//bool is_valid_operation(Turn const& turn) -//{ -// BOOST_ASSERT(!turn.has(detail::overlay::operation_opposite)); -// return !turn.both(detail::overlay::operation_none); -//} -// -//template inline -//bool is_valid_turn(Turn const& turn) -//{ -// return is_valid_method(turn) && is_valid_operation(turn); -//} -// -//template inline -//TurnIt find_next_if(TurnIt first, TurnIt current, TurnIt last, Cond cond) -//{ -// if ( first == last ) -// return last; -// -// if ( current != last ) -// { -// TurnIt it = current; -// ++it; -// -// for ( ; it != last ; ++it ) -// if ( cond(*it) ) -// return it; -// } -// -// if ( IsCyclic ) -// { -// for ( TurnIt it = first ; it != current ; ++it ) -// if ( cond(*it) ) -// return it; -// } -// -// return last; -//} -// -//template inline -//TurnIt find_previous_if(TurnIt first, TurnIt current, TurnIt last, Cond cond) -//{ -// typedef std::reverse_iterator Rit; -// Rit rlast = Rit(first); -// if ( current == last ) -// return last; -// ++current; -// Rit res = find_next_if(Rit(last), Rit(current), rlast, cond); -// if ( res == rlast ) -// return last; -// else -// return --res.base(); -//} -// -//template inline -//TurnIt find_first_if(TurnIt first, TurnIt last, Cond cond) -//{ -// return std::find_if(first, last, cond); -//} -// -//template inline -//TurnIt find_last_if(TurnIt first, TurnIt last, Cond cond) -//{ -// typedef std::reverse_iterator Rit; -// Rit rlast = Rit(first); -// Rit res = std::find_if(Rit(last), rlast, cond); -// if ( res == rlast ) -// return last; -// else -// return --res.base(); -//} - }}} // namespace detail::relate::turns #endif // DOXYGEN_NO_DETAIL