Add PolygonStroker and RemoveSelfIntersections for robust, high-performance stroke normalization#22
Merged
JimBobSquarePants merged 87 commits intomainfrom Feb 18, 2026
Merged
Conversation
Contributor
|
I like the third Party notices 👍 |
Member
Author
|
OK. I'm merging this. Super happy with the result! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites
This PR adds stroking and normalization to
SixLabors.PolygonClipperfor handling non-simple, real-world geometry.What’s Included
PolygonClipper.Normalize(Polygon)New explicit normalization API that resolves self-intersections and overlaps into canonical positive-winding output.
PolygonStroker+StrokeOptionsNew stroke-geometry pipeline for polygons/contours, with configurable join/cap behavior and optional output normalization.
Behavior and Compatibility
Normalize(...).Why This Matters
Many production inputs are not simple polygons (self-intersections, touching edges, compound paths), especially from text outlines and imported vector artwork. This pipeline provides a practical preprocessing/geometry-generation path that improves robustness for downstream operations.
Validation and Docs
Performance Note
In the
ImageSharp.DrawingDrawPolygonMediumThickbenchmark, replacing the default stroker/clipper path with this implementation reduced runtime from ~14 ms to ~3 ms (about 79% faster) and also reduced allocation pressure.CC @stefannikolei