From 4375dd04c3e627af0cfe41c83bb799cfef2a6db2 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Fri, 13 Jun 2014 13:11:45 +0300 Subject: [PATCH] [algorithms][is_valid] has_spikes: re-factor and polish implementation --- .../algorithms/detail/is_valid/has_spikes.hpp | 58 ++++++++----------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/is_valid/has_spikes.hpp b/include/boost/geometry/algorithms/detail/is_valid/has_spikes.hpp index 57cfe666e..d0733fe8d 100644 --- a/include/boost/geometry/algorithms/detail/is_valid/has_spikes.hpp +++ b/include/boost/geometry/algorithms/detail/is_valid/has_spikes.hpp @@ -15,14 +15,15 @@ #include #include -#include #include +#include + +#include + #include #include -#include - namespace boost { namespace geometry { @@ -66,27 +67,27 @@ struct not_equal_to -template +template struct has_spikes { static inline bool apply(Range const& range) { - typedef typename point_type::type point; - typedef typename boost::range_iterator::type iterator; + typedef not_equal_to::type> not_equal; - typedef not_equal_to not_equal; + typedef typename closeable_view::type view_type; + typedef typename boost::range_iterator::type iterator; - BOOST_ASSERT( boost::size(range) > 2 ); + view_type const view(range); - iterator prev = boost::begin(range); + iterator prev = boost::begin(view); - iterator cur = std::find_if(prev, boost::end(range), not_equal(*prev)); - BOOST_ASSERT( cur != boost::end(range) ); + iterator cur = std::find_if(prev, boost::end(view), not_equal(*prev)); + BOOST_ASSERT( cur != boost::end(view) ); - iterator next = std::find_if(cur, boost::end(range), not_equal(*cur)); - BOOST_ASSERT( next != boost::end(range) ); + iterator next = std::find_if(cur, boost::end(view), not_equal(*cur)); + BOOST_ASSERT( next != boost::end(view) ); - while ( next != boost::end(range) ) + while ( next != boost::end(view) ) { if ( geometry::detail::point_is_spike_or_equal(*prev, *next, @@ -96,19 +97,20 @@ struct has_spikes } prev = cur; cur = next; - next = std::find_if(cur, boost::end(range), not_equal(*cur)); + next = std::find_if(cur, boost::end(view), not_equal(*cur)); } - if ( geometry::equals(*boost::begin(range), *boost::rbegin(range)) ) + if ( geometry::equals(range::front(view), range::back(view)) ) { - iterator cur = boost::begin(range); + iterator cur = boost::begin(view); typename boost::range_reverse_iterator < - Range const - >::type prev = std::find_if(boost::rbegin(range), - boost::rend(range), - not_equal(*boost::rbegin(range))); - iterator next = std::find_if(cur, boost::end(range), not_equal(*cur)); + view_type const + >::type prev = std::find_if(boost::rbegin(view), + boost::rend(view), + not_equal(range::back(view))); + iterator next = + std::find_if(cur, boost::end(view), not_equal(*cur)); return detail::point_is_spike_or_equal(*prev, *next, *cur); } @@ -117,18 +119,6 @@ struct has_spikes }; -template -struct has_spikes -{ - static inline bool apply(Range const& range) - { - typedef typename closeable_view::type closed_view_type; - - closed_view_type closed_range(const_cast(range)); - return has_spikes::apply(closed_range); - } - -}; }} // namespace detail::is_valid #endif // DOXYGEN_NO_DETAIL