SixLabors.PolygonClipper 1.0.0

Prefix Reserved
dotnet add package SixLabors.PolygonClipper --version 1.0.0
                    
NuGet\Install-Package SixLabors.PolygonClipper -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SixLabors.PolygonClipper" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SixLabors.PolygonClipper" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SixLabors.PolygonClipper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SixLabors.PolygonClipper --version 1.0.0
                    
#r "nuget: SixLabors.PolygonClipper, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SixLabors.PolygonClipper@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SixLabors.PolygonClipper&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SixLabors.PolygonClipper&version=1.0.0
                    
Install as a Cake Tool

SixLabors.PolygonClipper

SixLabors.PolygonClipper

Build Status codecov License: Six Labors Split

SixLabors.PolygonClipper provides high-performance polygon clipping and stroking in C#. Boolean operations (union, intersection, difference, xor) are implemented with a Martínez-Rueda sweep-line pipeline for complex polygons with holes and multiple contours. Contour normalization is handled by a dedicated Vatti/Clipper2-inspired pipeline (PolygonClipper.Normalize) that resolves self-intersections/overlaps into positive-winding output. PolygonStroker can optionally run that normalization pass on emitted stroke geometry.

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
  • Includes PolygonClipper.Normalize (Clipper2-inspired) for positive-winding contour normalization
  • Includes PolygonStroker for configurable geometric stroking (joins, caps, miter limits)
  • Uses double precision geometry without coordinate quantization

Usage

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

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

Boolean operations can process self-intersecting inputs directly. Use normalization when you want canonical positive-winding contours (for example, before export or rendering pipelines that rely on winding semantics):

Polygon clean = PolygonClipper.Normalize(input);

Normalize uses a fixed positive-winding normalization path.

Stroking

Use PolygonStroker to generate filled stroke polygons from input contours:

Polygon stroked = PolygonStroker.Stroke(input, width: 12);

Configure join/cap behavior through StrokeOptions:

StrokeOptions options = new()
{
    LineJoin = LineJoin.Round,
    LineCap = LineCap.Round,
    MiterLimit = 4,
    ArcDetailScale = 1
};

Polygon stroked = PolygonStroker.Stroke(input, width: 12, options);

Algorithm References

This project draws on the following algorithm and implementation references:

  1. Martínez et al., "A simple algorithm for Boolean operations on polygons", Advances in Engineering Software, 64 (2013), pp. 11-19.
    https://doi.org/10.1016/j.advengsoft.2013.04.004
    1. Vatti, "A generic solution to polygon clipping", Communications of the ACM, 35(7), 1992, pp. 56-63.
      https://dl.acm.org/doi/pdf/10.1145/129902.129906

21re, rust-geo-booleanop (Rust Martínez-Rueda implementation reference).
https://github.com/21re/rust-geo-booleanop

Angus Johnson, Clipper2 polygon clipping library (reference implementation for the normalization pipeline).
https://github.com/AngusJohnson/Clipper2

License

Six Labors Split License. See LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SixLabors.PolygonClipper:

Package Downloads
SixLabors.ImageSharp.Drawing

Drawing extensions for ImageSharp with support for shapes, paths, text, and image rendering.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on SixLabors.PolygonClipper:

Repository Stars
SixLabors/ImageSharp.Drawing
:pen: Extensions to ImageSharp containing a cross-platform 2D polygon manipulation API and drawing operations.
Version Downloads Last Updated
1.0.0 0 5/12/2026