0

When I compute the difference between two shapes which touches one another (for example a rectangle A in a bigger rectangle B with a hole at rectangle A) and a clip shape (rectangle C) the two touching shapes are merged because their share the same edges and then the clipping is executed.

Is it possible to avoid merging touching shapes when clipping?

Here is an example of the difference between two shapes (A in green and B in red) and a clip (so the operation is: A & B - Clip), it returns the blue shape:

Difference (Blue) two touching shapes (A in green and B in red) with a clip

Instead of the blue rectangle, I would like to have those two shapes:

Expected result

And the intersection would give:

Intersection

This would give me the four shapes I want:

Expected result

I know I could perform the operations on each shape separately, but I am afraid it will be more costly.

Note

Here is the result of a XOR:

XOR

arthur.sw
  • 11,052
  • 9
  • 47
  • 104
  • Use XOR instead of Difference. – Angus Johnson Nov 11 '15 at 14:53
  • I forgot something in my question so I edited it, now it should be more clear. The XOR does not help... I think the only solution is to perform operations separately, which is what I do for now. – arthur.sw Nov 12 '15 at 09:18
  • I've posted a similar question at https://stackoverflow.com/questions/46235176/clipperlib-clip-multiple-squares-with-rectangle-produces-1-result Did you ever find a solution? In the end I'll be processing over 2 million shapes. I don't think clipping them seperately would be good for performance. – Paul Meems Sep 15 '17 at 09:20
  • I didn't find a solution with Clipper lib, but I compute the operation myself, see the following answer. – arthur.sw Sep 15 '17 at 12:38

1 Answers1

0

In the hand I compute the operation myself:

  1. compute the intersections between edges (of the clip shape and other shapes).
  2. for each vertex: sort its edges by angle (mandatory)
  3. walk through each edge clockwise and counterclockwise to compute the new polygons with their holes

This is efficient enough, but I need a space-partitioning data structure to sort edges and quickly their intersections.

arthur.sw
  • 11,052
  • 9
  • 47
  • 104