From fffc55d677db6015a3593223b6d55a8f241a25de Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Mon, 14 Apr 2014 10:00:08 +0300 Subject: [PATCH] [set ops] polish/simplify follow L/L code; change some vairable names that are confusing; --- .../detail/overlay/follow_linear_linear.hpp | 93 ++++++++----------- 1 file changed, 39 insertions(+), 54 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/overlay/follow_linear_linear.hpp b/include/boost/geometry/algorithms/detail/overlay/follow_linear_linear.hpp index b90214d49..f0612f102 100644 --- a/include/boost/geometry/algorithms/detail/overlay/follow_linear_linear.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/follow_linear_linear.hpp @@ -184,7 +184,7 @@ protected: static inline OutputIterator process_turn(TurnIterator it, TurnOperationIterator op_it, - bool& first, bool& entered, + bool& entered, std::size_t& enter_count, Linestring const& linestring, LinestringOut& current_piece, @@ -244,7 +244,6 @@ protected: entered = true; } - first = false; return oit; } @@ -281,17 +280,9 @@ public: template static inline OutputIterator apply(Linestring const& linestring, Linear const& linear, - TurnIterator start, TurnIterator beyond, + TurnIterator first, TurnIterator beyond, OutputIterator oit) { - typedef typename boost::range_iterator - < - typename std::iterator_traits - < - TurnIterator - >::value_type::container_type const - >::type turn_operation_iterator; - // Iterate through all intersection points (they are // ordered along the each line) @@ -299,15 +290,12 @@ public: geometry::segment_identifier current_segment_id(0, -1, -1, -1); bool entered = false; - bool first = true; std::size_t enter_count = 0; - for (TurnIterator it = start; it != beyond; ++it) + for (TurnIterator it = first; it != beyond; ++it) { - turn_operation_iterator op_it = boost::begin(it->operations); - - oit = process_turn(it, op_it, - first, entered, enter_count, + oit = process_turn(it, boost::begin(it->operations), + entered, enter_count, linestring, current_piece, current_segment_id, oit); @@ -365,8 +353,7 @@ protected: struct copy_linestrings_in_range { static inline OutputIt - apply(linestring_iterator begin, linestring_iterator beyond, - OutputIt oit) + apply(linestring_iterator, linestring_iterator, OutputIt oit) { return oit; } @@ -376,10 +363,10 @@ protected: struct copy_linestrings_in_range { static inline OutputIt - apply(linestring_iterator begin, linestring_iterator beyond, + apply(linestring_iterator first, linestring_iterator beyond, OutputIt oit) { - for (linestring_iterator ls_it = begin; ls_it != beyond; ++ls_it) + for (linestring_iterator ls_it = first; ls_it != beyond; ++ls_it) { LinestringOut line_out; geometry::convert(*ls_it, line_out); @@ -389,68 +376,66 @@ protected: } }; + template + static inline int get_multi_index(TurnIterator it) + { + return boost::begin(it->operations)->seg_id.multi_index; + } + public: template static inline OutputIterator apply(MultiLinestring const& multilinestring, Linear const& linear, - TurnIterator start, TurnIterator beyond, + TurnIterator first, TurnIterator beyond, OutputIterator oit) { - BOOST_ASSERT( start != beyond ); + BOOST_ASSERT( first != beyond ); typedef copy_linestrings_in_range < OutputIterator, OverlayType > copy_linestrings; - linestring_iterator ls_begin = boost::begin(multilinestring); - linestring_iterator ls_end = boost::end(multilinestring); + linestring_iterator ls_first = boost::begin(multilinestring); + linestring_iterator ls_beyond = boost::end(multilinestring); // Iterate through all intersection points (they are - // ordered along the each line) + // ordered along the each linestring) - int current_multi_id = - boost::begin(start->operations)->seg_id.multi_index; + int current_multi_id = get_multi_index(first); - oit = copy_linestrings::apply(ls_begin, - ls_begin + current_multi_id, + oit = copy_linestrings::apply(ls_first, + ls_first + current_multi_id, oit); - TurnIterator turns_begin = start, turns_end; + TurnIterator per_ls_first, per_ls_beyond = first; do { // find last turn with this multi-index - turns_end = turns_begin; - ++turns_end; - while ( turns_end != beyond ) + per_ls_first = per_ls_beyond; + do { - if ( boost::begin(turns_end->operations)->seg_id.multi_index - != current_multi_id ) - { - break; - } - ++turns_end; + ++per_ls_beyond; } + while ( per_ls_beyond != beyond + && get_multi_index(per_ls_beyond) == current_multi_id ); - oit = Base::apply(*(boost::begin(multilinestring) - + current_multi_id), - linear, turns_begin, turns_end, oit); + oit = Base::apply(*(ls_first + current_multi_id), + linear, per_ls_first, per_ls_beyond, oit); - int new_multi_id(0); - linestring_iterator ls_beyond_last = ls_end; - if ( turns_end != beyond ) + int next_multi_id(-1); + linestring_iterator ls_next = ls_beyond; + if ( per_ls_beyond != beyond ) { - new_multi_id = - boost::begin(turns_end->operations)->seg_id.multi_index; - ls_beyond_last = ls_begin + new_multi_id; + next_multi_id = get_multi_index(per_ls_beyond); + ls_next = ls_first + next_multi_id; } - oit = copy_linestrings::apply(ls_begin + current_multi_id + 1, - ls_beyond_last, + oit = copy_linestrings::apply(ls_first + current_multi_id + 1, + ls_next, oit); - current_multi_id = new_multi_id; - turns_begin = turns_end; + current_multi_id = next_multi_id; } - while ( turns_end != beyond ); + while ( per_ls_beyond != beyond ); return oit; }