|
Geometry : |
Subject: [ggl] Problems with the difference between two polygons
From: Enrico Leoni (lions.forever)
Date: 2011-07-17 05:49:04
Hi, in the example below I am having problems.
s1, the difference between pa and pb, should have three polygons (each
with an outer ring) but one is missing (this also happens with
ttmath).
Furthermore s1 seems to be self-intersecting but it shouldn't.
I'm using the last trunk revision and Visual Studio 2010.
Thanks, Enrico
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp>
//#include <boost/geometry/extensions/contrib/ttmath_stub.hpp>
#include <boost/geometry/geometries/adapted/c_array.hpp>
BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
using namespace boost::geometry;
//typedef model::d2::point_xy<ttmath_big> point_2d;
typedef model::d2::point_xy<double> point_2d;
typedef model::polygon<point_2d> polygon_2d;
typedef model::multi_polygon<polygon_2d> polygon_set;
int main(void)
{
const double cao[][2] =
{{1.83690953073357E-14,-300}, {-259.807621135332,-150},
{-259.807621135332,150}, {-5.5107285922007E-14,300},
{259.807621135331,150}, {259.807621135332,-150},
{9.18454765366783E-14,-300}};
const double cai[][2] =
{{7.65378971138986E-14,-250}, {216.50635094611,-125},
{216.50635094611,125}, {-4.59227382683391E-14,250},
{-216.50635094611,125}, {-216.50635094611,-125},
{1.53075794227797E-14,-250}};
polygon_2d pa;
pa.inners().resize(1);
assign_points(pa.outer(), cao);
assign_points(pa.inners()[0], cai);
const double cbo[][2] =
{{1.83690953073357E-14,-300}, {-259.807621135332,-150},
{-216.50635094611,-125}, {-216.50635094611,125},
{-259.807621135332,150}, {-5.5107285922007E-14,300},
{-4.59227382683391E-14,250}, {216.50635094611,125},
{259.807621135331,150}, {259.807621135332,-150},
{216.50635094611,-125}, {7.65378971138986E-14,-250},
{9.18454765366783E-14,-300}};
const double cbi[][2] =
{{6.12303176911189E-14,-200},
{173.205080756888,-99.9999999999999}, {173.205080756888,100},
{-3.67381906146713E-14,200}, {-173.205080756888,99.9999999999999},
{-173.205080756888,-100}, {1.22460635382238E-14,-200}};
polygon_2d pb;
pb.inners().resize(1);
assign_points(pb.outer(), cbo);
assign_points(pb.inners()[0], cbi);
polygon_set s1;
difference(pa, pb, s1);
bool r = intersects(s1);
polygon_set s2;
difference(pa, s1, s2);
return 0;
}
Geometry list run by mateusz at loskot.net