Boost logo

Geometry :

Subject: [ggl] geometry::intersection
From: Barend Gehrels (barend)
Date: 2011-03-27 16:38:55


Hi Adam,

On 27-3-2011 15:47, Adam Wulkiewicz wrote:
> Hi,
>
> I noticed that geometry::intersection(box1, box2, out_box) don't
> modifies out_box if boxes don't overlap. E.g. for following code:
>
> typedef boost::geometry::model::point<float, 2,
> boost::geometry::cs::cartesian> P;
> typedef boost::geometry::model::box<P> B;
>
> B b1(P(1, 1),P(3, 3));
> B b2(P(4, 4),P(5, 5));
> B inters;
> boost::geometry::intersection(b1, b2, inters);

Right. This was discussed earlier, suggestion to return bool. I took
that over but it is a little inconsistent with the other functions
(difference, union_) so it might be reverted. And your question shows
that its behaviour is now not clear neither.

>
> Is this intentional? Shouldn't this produce box 0,0 x 0,0 ?

0,0 x 0,0 is not a correct result neither. It might produce an "inverse"
box, so (max,max) x (min,min)

If the result is a multi-polygon, the multi-polygon would be empty
(indicating no output).
For a box there is no empty. Inverse indicates empty, more or less.

Another scenario is the user calling if (intersects(b1,b2)) {
intersection(b1,b2,inters); }. This is how it is originally intended.

Other libraries (as geos, sql server spatial, etc) return a null value
in similar cases. But in our template world we don't have that option,
and an extra parameter is a little awkward.

> Btw this is the reason of std::length_exception throwing or heap
> corruption in rtree. I've commited a patch.

OK, good that it is solved. Thanks for your new version, hope to have a
close look soon.

Regards, Barend


Geometry list run by mateusz at loskot.net