Made box/segment iterators random access

[SVN r64590]
This commit is contained in:
Barend Gehrels
2010-08-04 09:17:31 +00:00
parent 694c501f2e
commit e3406eada4
5 changed files with 26 additions and 4 deletions

View File

@@ -32,7 +32,7 @@ struct box_iterator
<
box_iterator<Box>,
typename point_type<Box>::type const,
boost::bidirectional_traversal_tag
boost::random_access_traversal_tag
>
{
explicit inline box_iterator(Box const& box)
@@ -80,6 +80,11 @@ private:
m_index--;
}
inline difference_type distance_to(box_iterator<Box> const& other) const
{
return other.m_index - this->m_index;
}
inline void init(Box const& box)
{
// asb -> lower_left, lower_right, upper_left, upper_right

View File

@@ -32,7 +32,7 @@ struct segment_range_iterator
<
segment_range_iterator<Segment>,
typename point_type<Segment>::type const,
boost::bidirectional_traversal_tag
boost::random_access_traversal_tag
>
{
// Default constructor is required to check concept of Range
@@ -90,13 +90,18 @@ private:
m_index--;
}
inline difference_type distance_to(segment_range_iterator<Segment> const& other) const
{
return other.m_index - this->m_index;
}
inline void init(Segment const& segment)
{
assign_point_from_index<0>(segment, m_points[0]);
assign_point_from_index<1>(segment, m_points[1]);
}
// We HAVE TO copy the points, because a segment does not need
// We HAVE TO copy the points, because a segment does not need
// to consist of two points,
// and we are expected to return a point here
point_type m_points[2];

View File

@@ -43,7 +43,7 @@ private :
};
// All box ranges can be handled as linestrings
// All box ranges can be handled as rings
namespace traits
{
template<typename Box>

View File

@@ -46,6 +46,12 @@ void test_geometry(std::string const& wkt, std::string const& expected)
it--;
// Not verified further, same as segment
}
{
// Check random access behaviour
int const n = boost::size(range);
BOOST_CHECK_EQUAL(n, 5);
}
}

View File

@@ -52,6 +52,12 @@ void test_geometry(std::string const& wkt, std::string const& expected)
out << " " << boost::geometry::get<0>(*it2) << boost::geometry::get<1>(*it2);
BOOST_CHECK_EQUAL(out.str(), expected);
}
{
// Check random access behaviour
int const n = boost::size(range);
BOOST_CHECK_EQUAL(n, 2);
}
}