diff --git a/include/boost/geometry/algorithms/detail/overlay/sort_by_side.hpp b/include/boost/geometry/algorithms/detail/overlay/sort_by_side.hpp index 895652f89..78c168b5d 100644 --- a/include/boost/geometry/algorithms/detail/overlay/sort_by_side.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/sort_by_side.hpp @@ -237,64 +237,6 @@ struct side_sorter } } - // Returns first index which is outgoing, and all incoming arcs are balanced - // by outgoing arcs - std::size_t first_open_index() - { - // map source index to state - typedef std::map map_type; - map_type state; - bool free = false; - std::size_t result = m_ranked_points.size(); - std::size_t last_main_rank = 0; - - for (std::size_t i = 0; i < m_ranked_points.size(); i++) - { - const rp& ranked = m_ranked_points[i]; - - if (free && ranked.main_rank > last_main_rank) - { - return result; - } - free = false; - - if (ranked.index == index_from) - { - state[ranked.seg_id.source_index]++; - } - else - { - state[ranked.seg_id.source_index]--; - } - - if (ranked.index == index_to) - { - int sum = 0; - for (map_type::const_iterator it = state.begin(); - it != state.end(); ++it) - { - sum += it->second; - } - - if (sum == 0) - { - // It is open. If next is a new main rank, - // then this is the result - free = true; - result = i; - last_main_rank = ranked.main_rank; - } - } - } - - if (free) - { - return result; - } - - return m_ranked_points.size(); - } - template void find_open_generic(Map& handled) { diff --git a/include/boost/geometry/algorithms/detail/overlay/traverse.hpp b/include/boost/geometry/algorithms/detail/overlay/traverse.hpp index 0b1291e51..fedf06eb7 100644 --- a/include/boost/geometry/algorithms/detail/overlay/traverse.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/traverse.hpp @@ -257,7 +257,7 @@ struct traversal inline bool select_from_cluster(signed_size_type& turn_index, int& op_index, signed_size_type start_turn_index, - sbs_type const& sbs) + sbs_type const& sbs, bool allow_pass_rank) { bool const is_union = OperationType == operation_union; bool const is_intersection = OperationType == operation_intersection; @@ -314,7 +314,7 @@ struct traversal result = true; selected_rank = ranked_point.main_rank; } - else + else if (! allow_pass_rank) { return result; } @@ -396,20 +396,10 @@ struct traversal if (open_count > 1) { sbs.reverse(); - - std::size_t index = sbs.first_open_index(); - if (index < sbs.m_ranked_points.size()) - { - typename sbs_type::rp const& ranked_point = sbs.m_ranked_points[index]; - turn_index = ranked_point.turn_index; - op_index = ranked_point.op_index; - return true; - } - return false; + return select_from_cluster(turn_index, op_index, start_turn_index, sbs, true); } - - return select_from_cluster(turn_index, op_index, start_turn_index, sbs); + return select_from_cluster(turn_index, op_index, start_turn_index, sbs, false); } inline void change_index_for_self_turn(signed_size_type& to_vertex_index,