From 258183d7aa4ea54a545a8de780eaff82ee38cb3d Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Wed, 27 Apr 2016 14:18:47 +0200 Subject: [PATCH] [traverse] move counting open spaces to sort_by_side structure --- .../detail/overlay/sort_by_side.hpp | 29 +++++++++++++++++++ .../algorithms/detail/overlay/traversal.hpp | 24 ++------------- 2 files changed, 31 insertions(+), 22 deletions(-) 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 894cddab8..1227e09b3 100644 --- a/include/boost/geometry/algorithms/detail/overlay/sort_by_side.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/sort_by_side.hpp @@ -330,6 +330,35 @@ struct side_sorter } } + //! Check how many open spaces there are + template + std::size_t open_count(Turns const& turns) const + { + typedef typename boost::range_value::type turn_type; + typedef typename turn_type::turn_operation_type turn_operation_type; + + std::size_t result = 0; + std::size_t last_rank = 0; + for (std::size_t i = 0; i < m_ranked_points.size(); i++) + { + rp const& ranked_point = m_ranked_points[i]; + + if (ranked_point.main_rank > last_rank + && ranked_point.index == sort_by_side::index_to) + { + turn_type const& ranked_turn = turns[ranked_point.turn_index]; + turn_operation_type const& ranked_op = ranked_turn.operations[ranked_point.op_index]; + if (ranked_op.enriched.count_left == 0 + && ranked_op.enriched.count_right > 0) + { + result++; + last_rank = ranked_point.main_rank; + } + } + } + return result; + } + //protected : typedef std::vector container_type; diff --git a/include/boost/geometry/algorithms/detail/overlay/traversal.hpp b/include/boost/geometry/algorithms/detail/overlay/traversal.hpp index 3f8f73f2f..51f014cd9 100644 --- a/include/boost/geometry/algorithms/detail/overlay/traversal.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/traversal.hpp @@ -493,30 +493,10 @@ struct traversal sbs.apply(turn.point); - int open_count = 0; + std::size_t open_count = 0; if (is_union) // && ! cinfo.switch_source) { - // Check how many open spaces there are. - // TODO: might be moved to sbs itself, though it also uses turns - - std::size_t last_rank = 0; - for (std::size_t i = 0; i < sbs.m_ranked_points.size(); i++) - { - typename sbs_type::rp const& ranked_point = sbs.m_ranked_points[i]; - - if (ranked_point.main_rank > last_rank - && ranked_point.index == sort_by_side::index_to) - { - turn_type const& ranked_turn = m_turns[ranked_point.turn_index]; - turn_operation_type const& ranked_op = ranked_turn.operations[ranked_point.op_index]; - if (ranked_op.enriched.count_left == 0 - && ranked_op.enriched.count_right > 0) - { - open_count++; - last_rank = ranked_point.main_rank; - } - } - } + open_count = sbs.open_count(m_turns); } is_touching = open_count > 1;