Boost logo

Geometry :

Subject: [ggl] Keeping information for points when running algorithms
From: Mateusz Łoskot (mateusz)
Date: 2011-11-03 01:56:25


On 2 November 2011 03:57, V D <zedxz2_at_[hidden]> wrote:

>
> Let's say I have a custom point type (it's a point, but it has flags, see
> code below).
>
> My problem is that I have some flags on some of those points, and when I'm
> running
>
bg::intersection I am losing those flags, even if the point is part of the
> output, ie: it is not chopped.
>
I would have thought that non-chopped points in the intersection would
>
have been copy constructed, therefore preserving my flags.
>
> I'm assuming bg creates new points and just assign the coordinates via the
> setters ?
>

I'm most likely missing important assumptions of the algorithm
implementation.
However, I presume you can't rely on "even if the point is part of the
output".
First, algorithms calculate new points.
Second, algorithm may calculate points which are geometrically equivalent
to its input,
but does not preserve C++ objects identity, "sameness" of input.

If you look at policies/relate/intersection_points.hpp what is happening
inside segments_intersect()
you see point of intersection is calculated:

set<0>(result.intersections[0],
      boost::numeric_cast<coordinate_type>(s1x + r * promoted_type(dx1)));
set<1>(result.intersections[0],
      boost::numeric_cast<coordinate_type>(s1y + r * promoted_type(dy1)));

At this point, s1 (s1x and s1y are derived values only) as well as s2, these
segments do carry identities of input objects.

I'd speculate we could initialise intersection result with equal copy of
input:

result.intersections[0] = s1.first; // decide which point?
// write new coordinates only
set<0>(result.intersections[0],
      boost::numeric_cast<coordinate_type>(s1x + r * promoted_type(dx1)));
set<1>(result.intersections[0],
      boost::numeric_cast<coordinate_type>(s1y + r * promoted_type(dy1)));

Also, in many if not most places in the library, the point assignment
policy used
is coordinate-wise, not datum-wise (member-wise).

Best regards,

-- 
Mateusz Loskot,
http://mateusz.loskot.net>
Charter Member of OSGeo,
http://osgeo.org>
Member of ACCU,
http://accu.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/ggl/attachments/20111102/ea8a4164/attachment-0001.html

Geometry list run by mateusz at loskot.net