Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64590 - in sandbox/geometry: boost/geometry/iterators boost/geometry/ranges libs/geometry/test/ranges
From: barend.gehrels_at_[hidden]
Date: 2010-08-04 05:36:48


Author: barendgehrels
Date: 2010-08-04 05:17:31 EDT (Wed, 04 Aug 2010)
New Revision: 64590
URL: http://svn.boost.org/trac/boost/changeset/64590

Log:
Made box/segment iterators random access
Text files modified:
   sandbox/geometry/boost/geometry/iterators/box_iterator.hpp | 7 ++++++-
   sandbox/geometry/boost/geometry/iterators/segment_range_iterator.hpp | 9 +++++++--
   sandbox/geometry/boost/geometry/ranges/box_range.hpp | 2 +-
   sandbox/geometry/libs/geometry/test/ranges/box_range.cpp | 6 ++++++
   sandbox/geometry/libs/geometry/test/ranges/segment_range.cpp | 6 ++++++
   5 files changed, 26 insertions(+), 4 deletions(-)

Modified: sandbox/geometry/boost/geometry/iterators/box_iterator.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/iterators/box_iterator.hpp (original)
+++ sandbox/geometry/boost/geometry/iterators/box_iterator.hpp 2010-08-04 05:17:31 EDT (Wed, 04 Aug 2010)
@@ -32,7 +32,7 @@
     <
         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 @@
         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

Modified: sandbox/geometry/boost/geometry/iterators/segment_range_iterator.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/iterators/segment_range_iterator.hpp (original)
+++ sandbox/geometry/boost/geometry/iterators/segment_range_iterator.hpp 2010-08-04 05:17:31 EDT (Wed, 04 Aug 2010)
@@ -32,7 +32,7 @@
     <
         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 @@
         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];

Modified: sandbox/geometry/boost/geometry/ranges/box_range.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/ranges/box_range.hpp (original)
+++ sandbox/geometry/boost/geometry/ranges/box_range.hpp 2010-08-04 05:17:31 EDT (Wed, 04 Aug 2010)
@@ -43,7 +43,7 @@
 };
 
 
-// All box ranges can be handled as linestrings
+// All box ranges can be handled as rings
 namespace traits
 {
     template<typename Box>

Modified: sandbox/geometry/libs/geometry/test/ranges/box_range.cpp
==============================================================================
--- sandbox/geometry/libs/geometry/test/ranges/box_range.cpp (original)
+++ sandbox/geometry/libs/geometry/test/ranges/box_range.cpp 2010-08-04 05:17:31 EDT (Wed, 04 Aug 2010)
@@ -46,6 +46,12 @@
         it--;
         // Not verified further, same as segment
     }
+
+ {
+ // Check random access behaviour
+ int const n = boost::size(range);
+ BOOST_CHECK_EQUAL(n, 5);
+ }
 }
 
 

Modified: sandbox/geometry/libs/geometry/test/ranges/segment_range.cpp
==============================================================================
--- sandbox/geometry/libs/geometry/test/ranges/segment_range.cpp (original)
+++ sandbox/geometry/libs/geometry/test/ranges/segment_range.cpp 2010-08-04 05:17:31 EDT (Wed, 04 Aug 2010)
@@ -52,6 +52,12 @@
         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);
+ }
 }
 
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk