Skip to content

SixLabors/PolygonClipper

Repository files navigation

PolygonClipper

License: Six Labors Split

A C# implementation of the Martínez–Rueda algorithm for performing Boolean operations on polygons. This library supports union, intersection, difference, and xor operations on complex polygons with holes, multiple contours, and self-intersections.

Features

  • Works with non-convex polygons, including holes and multiple disjoint regions
  • Handles edge cases like overlapping edges and vertical segments
  • Preserves topology: output polygons include hole/contour hierarchy
  • Deterministic and robust sweep line algorithm with O((n + k) log n) complexity

Usage

The API centers around Polygon and Contour types. Construct input polygons using contours, then apply Boolean operations via the PolygonClipper class:

Polygon result = PolygonClipper.Intersect(subject, clipping);

Based On

This implementation is based on the algorithm described in:

F. Martínez et al., "A simple algorithm for Boolean operations on polygons", Advances in Engineering Software, 64 (2013), pp. 11–19.
https://sci-hub.se/10.1016/j.advengsoft.2013.04.004

License

Six Labors Split License. See LICENSE for details.

About

A simple algorithm for Boolean operations on polygons

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages