PolygonClipper
PolygonClipper is Six Labors' high-performance focused geometry library for polygon boolean operations, contour normalization, and stroke-outline generation in managed .NET. It is designed for real 2D geometry workloads: non-convex shapes, holes, multiple contours, overlapping edges, and inputs that need canonicalized output.
The current package targets .NET 8. If you already use ImageSharp.Drawing, you may already be relying on PolygonClipper indirectly: ImageSharp.Drawing uses it internally for boolean operations against paths and for stroke geometry generation.
Under the hood, the boolean-operation pipeline is based on a Martinez-Rueda sweep-line approach for complex polygon clipping, while normalization uses a separate Vatti/Clipper2-inspired cleanup path for resolving self-intersections and overlaps into positive-winding output. You do not need to understand those algorithms to use the library well, but it helps explain why PolygonClipper is comfortable with complex contour topology.
The library works with geometry, not pixels. Coordinates are numeric vertices, contours are rings, and polygons are collections of rings with explicit hierarchy for holes. That makes PolygonClipper useful before rendering, export, hit testing, path cleanup, or any workflow where you need the region itself rather than a raster mask.
Most users should begin with the static boolean, normalization, and stroking entry points. They take ordinary polygon inputs and return new polygon geometry, so the result can be inspected, transformed, rendered, serialized, or handed to another geometry pipeline.
License
PolygonClipper is licensed under the terms of the Six Labors Split License, Version 1.0. See https://sixlabors.com/pricing for commercial licensing details.
Important
Starting with PolygonClipper 1.0.0, projects that directly depend on SixLabors.PolygonClipper require a valid Six Labors license at build time. This enforcement applies to direct dependencies only. See License Enforcement Changes and a New Subscription Tier for details.
Installation
PolygonClipper is installed via NuGet with nightly builds available on Feedz.
PM > Install-Package SixLabors.PolygonClipper -Version VERSION_NUMBER
Warning
Prerelease versions installed via the Visual Studio NuGet Package Manager require the "include prerelease" checkbox to be checked.
How to use the license file
By default, the build searches from each project directory for sixlabors.lic. Place the supplied file in the directory that contains the project file, or in a subdirectory below it. Use the file as supplied; it already contains the complete license string required by the build.
If you want to keep the file somewhere else, including a repository root that sits above the project directory, set SixLaborsLicenseFile in your project file or a shared props file:
<PropertyGroup>
<SixLaborsLicenseFile>path/to/sixlabors.lic</SixLaborsLicenseFile>
</PropertyGroup>
If you do not want to store the license on disk, pass the license string directly from an environment variable or secret store. When extracting the value from sixlabors.lic, use the full file contents, not only the Key field:
<PropertyGroup>
<SixLaborsLicenseKey>$(SIXLABORS_LICENSE_KEY)</SixLaborsLicenseKey>
</PropertyGroup>
You can also pass the key to common .NET CLI commands.
PowerShell:
dotnet build -p:SixLaborsLicenseKey="$env:SIXLABORS_LICENSE_KEY"
dotnet publish -p:SixLaborsLicenseKey="$env:SIXLABORS_LICENSE_KEY"
Bash and other shells that expand environment variables with $NAME:
dotnet build -p:SixLaborsLicenseKey="$SIXLABORS_LICENSE_KEY"
dotnet publish -p:SixLaborsLicenseKey="$SIXLABORS_LICENSE_KEY"
Build as normal after the file or property is configured. If the license is missing or invalid, the build fails with a clear error. You do not need to reference the licensing package directly; it is carried by Six Labors libraries.
Start Here
- Getting Started walks through building a polygon from contours and vertices, then running a first boolean operation.
- Polygons, Contours, and Holes explains the library's core data model and how hierarchy is represented.
- Boolean Operations covers
Intersection,Union,Difference, andXor, including subject-versus-clip semantics. - Normalization and Winding explains when to use
Normalize(...)to resolve self-intersections and overlaps into positive-winding output. - Stroking covers
PolygonStroker,StrokeOptions, joins, caps, and open-versus-closed path behavior.
How to Use These Docs
- Start with contours and polygons before choosing a boolean or stroking operation.
- Use boolean operations when combining two regions.
- Use normalization when cleaning one messy region.
- Use stroking when a line or path needs to become filled outline geometry.