Boost logo

Geometry :

Subject: Re: [geometry] Issues with difference
From: Barend Gehrels (barend_at_[hidden])
Date: 2019-03-07 21:09:57


Hi Matthieu,

Nice use case! Thanks for your message, I give some suggestions inline.

Op 7-3-2019 om 11:44 schreef Matthieu Beghin via Geometry:
> Hi there,
>
> I'm trying to solve my geometry problems with boost::geometry. I
> really enjoy the API but I'm facing a few issues. Maybe the solutions
> are simple, but I can't find my way. My context is: users are drawing
> shapes that are combined using union / intersection / difference, I
> use "buffer" to have a feathering effect around the shapes and in the
> end I triangulate the result and render with OpenGL.
>
> Situation 1: if I do a difference between two (valid) geometries that
> share a common segment, the result is invalid (bg::is_valid return
> false, it find some "turns"):
>   Example:
> namespacebg=boost::geometry;
> typedefbg::model::d2::point_xy<double>point_xy;
> typedefbg::model::polygon<point_xy>polygon_t;
> typedefbg::model::multi_polygon<polygon_t>multiPolygon_t;
> multiPolygon_tpoly1;bg::read_wkt("MULTIPOLYGON(((-1.00000010731-0.713619134602,-1.00000012822-0.493922219801,-0.5981729252270.100631982002,-1.00000012886-0.0624283708015,-1.000000119940.0862738908136,-0.4402621077980.31341400405,-0.3608283412460.292948255722,-0.3572756418930.210997365241,-0.970143533681-0.695818118925,-1.00000010731-0.713619134602)))",poly1);
> multiPolygon_tpoly2;bg::read_wkt("MULTIPOLYGON(((-0.999999965066-0.493921978401,-0.909999987372-0.360755621066,-0.909999996424-0.91000000872,0.91000000872-0.909999996424,0.9099999964240.91000000872,-0.9099999964240.91000000872,-0.909999911756-0.0259065349961,-0.999999867625-0.0624282647935,-11,11,1-1,-1-1,-0.999999965066-0.493921978401)))",poly2);
> multiPolygon_tdiff;
> bg::difference(poly1,poly2,diff);

Are you sure the input is closed and has the right (clockwise)
orientation? If not, please call bg::correct(poly1) and
bg::correct(poly2) before, such that you are sure they are right.

Indeed, if the input geometries are valid,  then the result should be
valid. We currently have some issues with some floating point input, and
maybe this is the problem for you.

Can you try to define BOOST_GEOMETRY_NO_ROBUSTNESS and see if that
helps? This removes the rescaling (that we do internally). In a future
release, this (applying overlays without rescaling) will be the default.
I'm currently working on it.

> Situation 2: the difference between two valid geometries that have no
> common edge is invalid. The subtracted geometry has an inner hole but
> I suppose that should be supported...
>
> multiPolygon_tpoly1;bg::read_wkt("MULTIPOLYGON(((-2-2,-22,22,2-2,-2-2)))",poly1);
> multiPolygon_tpoly2;bg::read_wkt("MULTIPOLYGON(((-0.430323140092-0.999999912736,-1-1,-11,11,1-1,0.431066411049-0.999999901684,0.43106695576-1.00000010168,-0.43032321787-1.00000011274,-0.430323140092-0.999999912736),(0.1355292350050.316180944443,-0.949848473072-0.124261498451,-0.47733861208-0.590634822845,0.1355292350050.316180944443)))",poly2);
> multiPolygon_tdiff;
> bg::difference(poly1,poly2,diff);
> On this picture poly1 is in green, poly2 is in red (the red triangle is poly2 inner hole).
>

Indeed holes are supported. This is probably not a Floating Point issue,
so I guess this might be the orientation, could you try also here to
correct the input before calling difference?

If this all doesn't help, I will try to reproduce the problem.

Regards, Barend



Geometry list run by mateusz at loskot.net