hn.today

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

liorsinai.github.io16 points1 comments
Screenshot of Notes on the Martinez-Rueda Polygon Clipping Algorithm: Segments to Paths

The Martinez-Rueda algorithm performs polygon intersections, unions, differences, and XORs by selecting relevant segments during a line sweep, but its output is segments rather than ordered paths. Converting those segments into polygons becomes unreliable when more than two edges meet at a vertex, as can happen in self-intersecting or otherwise improper polygons. The usual contour-following and segment-chaining approaches assume exactly two edges per vertex, which can leave chains unfinished or produce inconsistent results. The proposed replacement computes graph faces, handles improper polygons, gives consistent orientations, and does not depend on the algorithm’s starting point.

The method turns each segment into two oppositely directed half-edges, snaps nearby coordinates to a grid, and sorts half-edges clockwise around each node. A local neighbor rule links edges into cycles, which are then walked to enumerate faces in linear time, assuming modest numbers of edges at each node. Counter-clockwise and clockwise orientation distinguishes exterior from interior faces, but graph geometry alone cannot reveal whether a region is filled or a hole. The method therefore retains the Martinez-Rueda fill annotations on edges and uses them to test whether a face’s inner region is filled, with majority voting across nonvertical edges for robustness. Finally, it offers MERGE_FACES, which tends to form fewer, larger polygons with explicit holes, and SPLIT_FACES, which produces more, smaller regions, sometimes with implied holes.

Read on liorsinai.github.io1 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

Laravel Rust

Laravel Rust

Laravel for Rust is a full-stack web framework with routing, validation, database tools, background jobs, and real-time features. It also supports Inertia for frontend integration and is released under the MIT license. (github.com)

The Uberization of Software

The Uberization of Software

Ride-hailing apps greatly expanded demand for trips but undercut the value of taxi medallions and squeezed driver earnings by removing the supply limits that had protected them. The essay argues that software engineering faces a similar paradox: rising demand can lower workers’ pay when technology rapidly expands the supply of labor. (lsrx.net)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.