vinnythepoo
vinnythepoo

Reputation: 39

clipper lib problems when using holes

I am working on a gis-type 2d map generator, I am using the clipper lib. I noticed some errors during the construction and I thought I was doing something wrong, so I ran the example and the problem is that the inner triangle, which should be an hole isn't taken into consideration and it is added as a full polygon to the solution. If I reverse the polygon using the function form the lib, the triangle disappears totally. I am running through this problem since yesterday day and I haven't figured out what I am doing wrong. Has anybody had ever any problem with this library? is this a common bug '?


I have used this snippet of code, taken directly from yout site

include "clipper.hpp"

//from clipper.hpp ...
//typedef signed long long long64;
//struct IntPoint {long64 X; long64 Y;};
//typedef std::vector<IntPoint> Polygon;
//typedef std::vector<Polygon> Polygons;
...
using namespace ClipperLib;

Polygons subj(2), clip(1), solution;

//define outer blue 'subject' polygon
subj[0].push_back(IntPoint(180,200));
subj[0].push_back(IntPoint(260,200));
subj[0].push_back(IntPoint(260,150));
subj[0].push_back(IntPoint(180,150));

//define subject's inner triangular 'hole' (with reverse orientation)
subj[1].push_back(IntPoint(215,160));
subj[1].push_back(IntPoint(230,190));
subj[1].push_back(IntPoint(200,190));

//define orange 'clipping' polygon
clip[0].push_back(IntPoint(190,210));
clip[0].push_back(IntPoint(240,210));
clip[0].push_back(IntPoint(240,130));
clip[0].push_back(IntPoint(190,130));

DrawPolygons(subj, 0x160000FF, 0x600000FF); //blue
DrawPolygons(clip, 0x20FFFF00, 0x30FF0000); //orange

//perform intersection ...
Clipper c;
c.AddPolygons(subj, ptSubject);
c.AddPolygons(clip, ptClip);
c.Execute(ctIntersection, solution, pftNonZero, pftNonZero);
DrawPolygons(solution, 0x3000FF00, 0xFF006600); //solution shaded green

I should see through the hole , carved out by the triangle, correct? I tried a simpler scenario, a single square and a triangle inside it and I performed different operations like subtraction xor and difference I get always 2 polygons, looks like the operations aren't performed at all.

Upvotes: 1

Views: 1829

Answers (2)

Juicebox
Juicebox

Reputation: 442

Execute() with PolyTree output argument must be used instead of Paths argument (old Polygons) to have a full Contour + Hole solution.

Upvotes: 0

Angus Johnson
Angus Johnson

Reputation: 4643

The Clipper library has been extensively tested and has a fairly large number of users too, so I'm confident the problem will turn out to be in your code. Also, I'm not sure which sample code you've tried, but all the supplied samples have been fully tested (in C++, C# and Delphi).

Angus - author of the Clipper library

Upvotes: 1

Related Questions