
Geometry : 
Subject: Re: [geometry] [point_iterator] make point iterator bidirectional
From: Barend Gehrels (barend_at_[hidden])
Date: 20140505 14:50:06
Hi Menelaos,
Menelaos Karavelas wrote On 552014 9:21:
> Hello all.
>
> Before getting into the details, let me give some background. During
> the past couple of months I have implemented an iterator for the
> points of a geometry. The code is already in the develop branch, but
> it is not yet documented (which means "use at your own risk", at least
> for now...). The idea is to have an iterator to iterate over all
> points of a geometry, and the supported geometries are: linestrings,
> rings, polygons, multipoints, multilinestrings and multipolygons.
> To use the iterator one can simply write:
> bg::point_iterator<Geometry> first = bg::points_begin(g); //
> nonconst first
> bg::point_iterator<Geometry> last = bg::points_end(g); //
> nonconst pasttheend
>
> bg::point_iterator<Geometry const> const_first =
> bg::points_begin(g); // const first
> bg::point_iterator<Geometry const> const_last = bg::points_end(g);
> // const pasttheend
> The points' iterator was implemented as a forward iterator.
> The corresponding implementation file is:
> *
> https://github.com/boostorg/geometry/blob/develop/include/boost/geometry/iterators/point_iterator.hpp
> but there is also:
> *
> https://github.com/boostorg/geometry/blob/develop/include/boost/geometry/iterators/point_iterator_type.hpp
> and other source code files involved....
> If people are interested I can describe the implementation design in
> detail.
>
>
> This email is about followup work in this direction. During the past
> couple of days I changed/modified/updated the implementation to make
> the point iterator bidirectional. So now one can use operator on
> point iterators, can use it in algorithms that require a bidirectional
> iterator (such std::reverse), etc. In addition, I have implemented two
> new free functions (the supported geometries are as above):
> ** points_front: returns the first point of a (nonempty) geometry
> ** points_back: returns the last point of a (nonempty) geometry
> So in order to use them, you may simply write:
> bg::point_type<Geometry>::type p = bg::points_front(g);
> bg::point_type<Geometry>::type q = bg::points_back(g);
> (I have omitted the "typename" keyword upfront).
>
> Finally, I have implemented a reverse iterator for points, and the
> corresponding free functions: points_rbegin and points_rend. To use
> them simply do:
> bg::point_reverse_iterator<Geometry> rfirst =
> bg::points_rbegin(g); // nonconst reverse first
> bg::point_reverse_iterator<Geometry> rlast = bg::points_rend(g);
> // nonconst reverse pasttheend
>
> bg::point_reverse_iterator<Geometry const> const_rfirst =
> bg::points_rbegin(g); // const reverse first
> bg::point_reverse_iterator<Geometry const> const_rlast =
> bg::points_rend(g); // const reverse pasttheend
>
> I have created a pull request for this:
> https://github.com/boostorg/geometry/pull/21
>
> In there you will find:
> ** changes in the unit tests (rearranged/refactored code; added
> tests for points_front/back and point_reverse_iterator; added code to
> test the iterators as bidirectional). The corresponding files are in
> test/iterators:
> *
> https://github.com/mkaravel/geometry/blob/feature/point_iterator/test/iterators/concatenate_iterator.cpp
> *
> https://github.com/mkaravel/geometry/blob/feature/point_iterator/test/iterators/flatten_iterator.cpp
> *
> https://github.com/mkaravel/geometry/blob/feature/point_iterator/test/iterators/point_iterator.cpp
> *
> https://github.com/mkaravel/geometry/blob/feature/point_iterator/test/iterators/test_iterator_common.hpp
> (contains common factoredout code)
>
> ** changes in the implementation:
> *
> https://github.com/mkaravel/geometry/blob/feature/point_iterator/include/boost/geometry/iterators/concatenate_iterator.hpp
> *
> https://github.com/mkaravel/geometry/blob/feature/point_iterator/include/boost/geometry/iterators/flatten_iterator.hpp
> *
> https://github.com/mkaravel/geometry/blob/feature/point_iterator/include/boost/geometry/iterators/point_iterator.hpp
> (contains points_front/points_back)
> *
> https://github.com/mkaravel/geometry/blob/feature/point_iterator/include/boost/geometry/iterators/point_reverse_iterator.hpp
> (contains implementation of reverse iterator)
>
> I look forward to comments/suggestions. I would suggest to put your
> comments/suggestions on GitHub, using GitHub's comments' feature
> available through the pull request.
Thanks a lot for this new functionality. I already liked the
points_begin and points_end, and bidirectional functionality makes it
more complete.
I think the point iterators are very useful for end users too, so if we
could create enduser documentation and some concise examples, would be
great.
If I have more remarks I will let you know.
Regards, Barend
Geometry list run by mateusz at loskot.net