drlukeparry / pyclipr

Python Polygon Clipping and Offsetting based on Clipper2 Library
Boost Software License 1.0
21 stars 6 forks source link

Issue with polygon merging #5

Open edumur opened 10 months ago

edumur commented 10 months ago

Hi,

I am having issue with polygons merging.

If a create a bunch of polygons as:

# Make a bunch of rectangles
tot = []
tot.append(np.array([[  -5., -100.],
                     [   5., -100.],
                     [   5.,  100.],
                     [  -5.,  100.]]))

tot.append(np.array([[  45., -100.],
                     [  55., -100.],
                     [  55.,  100.],
                     [  45.,  100.]]))

tot.append(np.array([[-100.,   -5.],
                     [ 100.,   -5.],
                     [ 100.,    5.],
                     [-100.,    5.]]))

tot.append(np.array([[-100.,   45.],
                     [ 100.,   45.],
                     [ 100.,   55.],
                     [-100.,   55.]]))

I obtain this: image

If I "merge" the polygons to have only one left as:

# Execute the  merge
pc = pyclipr.Clipper()
pc.scaleFactor = int(1000)

pc.addPaths(tot, pyclipr.Subject)

tot = pc.execute(pyclipr.Union,
                pyclipr.FillRule.EvenOdd)

I get this: image

You can remark the holes at the intersections of the polygons. I was expected something like this: image

Which is something I get by using Klayout and click on: edit -> selection -> merge image

If you can help me to get the same result as with Klayout that would be really helpful.

josephduchesne commented 2 weeks ago

You probably want FillRule.NonZero

See the docs here: https://www.angusj.com/clipper2/Docs/Units/Clipper/Types/FillRule.htm

edumur commented 2 weeks ago

Unfortunately no. When I use FillRule.NonZero, I got: image

Is is, in fact, a known issue, see this discussion: https://github.com/AngusJohnson/Clipper2/discussions/820.