 # Geometry :

Subject: [ggl] Polygon, points and accessing elements
From: Barend Gehrels (Barend.Gehrels)
Date: 2009-10-22 12:15:43

Hi Ivan,

>
> I'm using now the polygon template to construct several polygons on a
> groundware simulation. But I need to, given one point, access the
> previous and the nex point, for each point in the polygon. Is that
> possible?
Eehm, by chance I worked today on the "for_each" function. It iterates
over all points of a geometry, OR over all segments. You need to iterate
over three points at a time.

That is also needed by the (upcoming) is_convex algorithm, and probably
more algorithms. So I pondered modifying / extending for_each such that
it can iterate:
- per point
- per three points (what is needed by you)

Anyway, that is not (yet) implemented. You might consider such a loop
(which here takes a ring, so e.g. ggl::exterior_ring(poly), for a
complete polygon you've to do interior rings as well, if you have them):

if (boost::size(ring) >= 2)
{
typedef typename boost::range_const_iterator<Ring>::type iterator;

iterator next = boost::begin(ring);
iterator previous = next++;
iterator current = next++;

for (; current != boost::end(ring); ++next, ++current, ++previous)
{
// Be sure that if last point is reached, also second point is
done again
if (next == boost::end(ring))
{
next = boost::begin(ring) + 1;
}
std::cout
<< " " << ggl::wkt(*previous)
<< " " << ggl::wkt(*current)
<< " " << ggl::wkt(*next)
<< std::endl;
}

where *it2 is the middle-point

> Also, it seems that ggl is getting a lot of changes now.
Sure, in preparation for the review starting November 5

> Could basic structures, like point_2d, polygon_2d and the access
> methods change?

That is unlikely. Most changes are internal. The "breaking" changes are
if you're using internal features, or (as yesterday) registering own
geometries without macro's.
There are some breaking changes:
simplify using output iterator is now simplify_inserter
convex_hull using output iterator is now convex_hull_inserter

If for_each per segment changes, then that will be another breaking
change. I don't think that function is used a lot. (Please report me if
you do)

I'm doing my best to prepare for the review and don't break things.
However, there might be some errors or deviations.

>
> I would consider changing all the coordinates and geometric elements
> in my simulation to ggl if it's possible to access the coordinates in
> the polygon.
Accessing coordinates is possible, using the method above (plus that
holes should be handled as well), or for_each. Actually a ggl::polygon
is just a structure containing a vector-of-points (the outer ring) and a
vector-of-vectors-of-points (the inner rings). It will stay like that.

Regards, Barend

Geometry list run by mateusz at loskot.net