[algorithms][is_valid] re-implement has_spikes to return false if

the range has one or two distinct points (instead of calling
BOOST_ASSERT)
This commit is contained in:
Menelaos Karavelas
2014-06-16 03:30:53 +03:00
parent 8200c0c0a7
commit a4b42e8bbc

View File

@@ -12,7 +12,6 @@
#include <algorithm>
#include <boost/assert.hpp>
#include <boost/range.hpp>
#include <boost/geometry/core/point_type.hpp>
@@ -82,10 +81,20 @@ struct has_spikes
iterator prev = boost::begin(view);
iterator cur = std::find_if(prev, boost::end(view), not_equal(*prev));
BOOST_ASSERT( cur != boost::end(view) );
if ( cur == boost::end(view) )
{
// the range has only one distinct point, so it
// cannot have a spike
return false;
}
iterator next = std::find_if(cur, boost::end(view), not_equal(*cur));
BOOST_ASSERT( next != boost::end(view) );
if ( next == boost::end(view) )
{
// the range has only two distinct points, so it
// cannot have a spike
return false;
}
while ( next != boost::end(view) )
{