From 6cecfeea9f894c5bef766589896fcfdd151db393 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 18 Jun 2014 04:34:45 +0300 Subject: [PATCH] [algorithms][is_valid] move implementation of number_of_distinct_points in separate file; re-design implementation of is_valid for linestrings; --- .../algorithms/detail/is_valid/linear.hpp | 66 ++++--------------- 1 file changed, 11 insertions(+), 55 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/is_valid/linear.hpp b/include/boost/geometry/algorithms/detail/is_valid/linear.hpp index 8286d1a5c..59dac713b 100644 --- a/include/boost/geometry/algorithms/detail/is_valid/linear.hpp +++ b/include/boost/geometry/algorithms/detail/is_valid/linear.hpp @@ -11,9 +11,7 @@ #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_LINEAR_HPP #include -#include -#include #include #include @@ -25,6 +23,7 @@ #include #include #include +#include #include @@ -37,69 +36,26 @@ namespace detail { namespace is_valid { -// returns the number of distinct points in the range; -// return values are zero, one, two, three_or_more -template -struct number_of_distinct_points -{ - static inline std::size_t apply(Range const& range) - { - typedef typename point_type::type point; - typedef typename boost::range_iterator::type iterator; - - std::size_t size = boost::size(range); - - if ( size < 2u ) - { - return size; - } - - iterator it1 = - std::find_if(boost::begin(range), - boost::end(range), - not_equal_to(range::front(range))); - - if ( it1 == boost::end(range) ) - { - return 1u; - } - - iterator it2 = - std::find_if(it1, boost::end(range), not_equal_to(*it1)); - - return - ( it2 == boost::end(range) - || geometry::equals(range::front(range), *it2) ) - ? - 2u - : - 3u - ; - } -}; - - template struct is_valid_linestring { static inline bool apply(Linestring const& linestring) { - typedef number_of_distinct_points num_distinct; + std::size_t num_distinct = number_of_distinct_values + < + Linestring, + 3u, + true, + not_equal_to::type> + >::apply(linestring); - std::size_t linestring_size = num_distinct::apply(linestring); - - if ( linestring_size < 2u ) + if ( num_distinct < 2u ) { return false; } - if ( !AllowSpikes && linestring_size == 2u ) - { - return !geometry::equals(range::front(linestring), - range::back(linestring)); - } - - return AllowSpikes + return num_distinct == 2u + || AllowSpikes || !has_spikes::apply(linestring); } };