Notes on the Martinez-Rueda Polygon Clipping Algorithm: Segments to Paths liorsi...

@best

Notes on the Martinez-Rueda Polygon Clipping Algorithm: Segments to Paths liorsinai.github.io · 13 points · 1 comments · HN thread

TL;DR The author describes how the PolygonAlgorithms.jl Julia package converts the segment output of the Martinez-Rueda polygon boolean algorithm into closed paths. The old segment-chaining method failed on improper self-intersecting polygons, so it was replaced with a graph faces computation that walks half-edges and classifies faces as holes or fills.

  • Martinez-Rueda outputs unordered segments, so a separate step is needed to turn them into ordered point lists (paths).
  • The earlier segment-chaining approach assumes exactly two segments meet at each vertex, which fails for improper polygons and caused 'open chains' errors.
  • Graph faces computation builds a directed graph of half-edges sorted clockwise around each node, then walks the next-edge map to extract all faces in O(E) time.
  • The directed graph alone cannot say whether a face is a hole, so fill annotations (filled above/below) are carried through each edge and used in an 'Is hole?' test.
  • Two modes are offered: MERGE_FACES returns fewer, larger polygons with explicit holes, while SPLIT_FACES returns more, smaller polygons.
  • Snap-to-grid rounding with a half-spacing check is used to avoid numeric errors creating spurious vertices.

Discussion The thread is very short and has a single comment. A user says they used the library the day before while designing a Wi-Fi antenna in FairBeam, where they needed to union two complex polygons and found that the simpler approach they tried first failed badly. The tone is practical and appreciative, pointing to a real-world use case rather than debating the algorithm.

  • Practical use case: unioning complex polygons for RF antenna design (most): The sole commenter reports using the library for a union of two complex polygons in antenna design. They say a simpler method they tried first failed, which suggests the more robust approach matters in practice.

#polygonClipping #computationalGeometry #Julia #graphAlgorithms #GIS