Wrong output when using ctDifference
Polygon and line clipping and offsetting library (C++, C#, Delphi)
Brought to you by:
angusj
Hello! I found some wrong solution when I use two triangles for test. Subj:[(1, 0),(4, 1.73),(4, -1.73)], Clip:[(1, 0),(4, 1),(4, -1)]. I want to use "ctDifference" function. The C++ output shows no solution. I think there are problems. What should I do to output right solution?
Anonymous
I think you'll find that if you sensibly scale your polygons, you'll get the result you're expecting.
To be clearer, ClipperLib works with integers. You'll need to scale up your geometry so that the minimum resolution sits on an integer interval (e.g. if you need to represent 0.001, you'll need to scale all of your geometry by at least 1000). You can then use this scaled geometry with ClipperLib and scale the result back down again afterwards.
The main reason for this is to avoid errors from floating point precision.
I didn't know that it only works with integers. I rewrite the codes and it works! Thank you!