polygondifferenceclipperlib

Clipperlib polygon difference issue


I am having trouble calculating the difference between two simple polygons.

Here is a drawing of the case I was testing when the problem appeared enter image description here

The red polygon on the left is the subject polygon The yellow polygon is the clip polygon The polygon on the right is the result after using the clipper lib polygon difference.

Instead of having 2 squares (the red squares on the middle shape) I'm having this (the red polygon on the right). I tested with the intersection operation and it gives me the yellow polygon which is fine so no problem with intersection. I also tested with XOR operation whose output should be the same as difference in this specific case and actually it is the same (wrong) output.

Did anyone experience this?

EDIT: Ok actually the output polytree contains 1 polynode with a contour of 8 points. The (2,2) point appears twice in this contour. I log the contour below: (2,2) (3,2) (3,3) (2,3) (2,2) (1,2) (1,1) (2,1)

So I guess this is ok and i can handle the output data to draw 2 squares by changing my drawing method (like using the ClipperLib SimplifyPolygon method)


Solution

  • Problem Solved (see EDIT in the previous message)