Is it possible for the polygon to "enclose" a hole [keyholing]? #820
-
Hello, I've been using GDSpy, which utilizes Clipper1 for Boolean operations to make GDS. Recently, I've been considering implementing my own solution based on Clipper2 for improved performance. However, I've observed that in Clipper2, a hole is represented by another (inner) polygon, which isn't compatible with KLayout. In KLayout, the polygon needs to 'enclose' the hole (an ordinary unicursal boundary path as shown in the image below). Is there a way to achieve this behavior in Clipper2? If not, do you have any alternative solutions? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 1 reply
-
I believe the usual way to describe joining a hole polygon contour with its outer contour is "keyholing". One approach might be to get the clipping solutions as Polytree structures, not as Paths. |
Beta Was this translation helpful? Give feedback.
-
I've written a keyholer as part of one of my projects. It's a fairly interesting undertaking - you can see an overview of the approach I took here : #713 (comment) and also here : #759 (comment) |
Beta Was this translation helpful? Give feedback.
-
I've created a fairly simple keyholing solution in the attached zip file (based on the logic I outlined above). [Zip file removed - see updates below] Edit: While the code is fairly simple, I haven't (yet) separated out the various components into separate files (so there's currently keyholing code and Polytree text streaming code and testing code all mixed together). |
Beta Was this translation helpful? Give feedback.
-
I've just made major changes (including bugfixes) to my keyholing code above. |
Beta Was this translation helpful? Give feedback.
-
And here's a C# version (with only minimal testing so far) ... |
Beta Was this translation helpful? Give feedback.
-
And 2 more revisions ... |
Beta Was this translation helpful? Give feedback.
-
okay i was gonna ask how to use it but awesome i got it working, i'm very happy as many times i have tried to get these things working, the slight puzzle for me was okay you need to build a PolyTree64, shown in the Clipper2 docs, so okay it's make the polygons in reverse and it works now really clean code thanks, fits in perfect maybe this sort of code could go in the library standard? |
Beta Was this translation helpful? Give feedback.
I've created a fairly simple keyholing solution in the attached zip file (based on the logic I outlined above).
It also allows for any level of nested polygons (where holes contain inner polygons etc).
And I'm fairly confident (but not certain) that solutions won't contain self intersections.
[Zip file removed - see updates below]
Edit: While the code is fairly simple, I haven't (yet) separated out the various components into separate files (so there's currently keyholing code and Polytree text streaming code and testing code all mixed together).