-
-
Notifications
You must be signed in to change notification settings - Fork 43
Integrate SixLabors.PolygonClipper #364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
2e76417
6c6ff30
8f9696f
087f480
8e7164e
ef89dd0
26ead24
5b2179b
bf57cfe
f976353
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,59 +1,46 @@ | ||
| // Copyright (c) Six Labors. | ||
| // Licensed under the Six Labors Split License. | ||
|
|
||
| using SixLabors.PolygonClipper; | ||
|
|
||
| namespace SixLabors.ImageSharp.Drawing.Shapes.PolygonClipper; | ||
|
|
||
| /// <summary> | ||
| /// Library to clip polygons. | ||
| /// </summary> | ||
| internal class Clipper | ||
| { | ||
| private readonly PolygonClipper polygonClipper; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="Clipper"/> class. | ||
| /// </summary> | ||
| public Clipper() | ||
| => this.polygonClipper = new PolygonClipper(); | ||
| private SixLabors.PolygonClipper.Polygon? subject; | ||
| private SixLabors.PolygonClipper.Polygon? clip; | ||
|
|
||
| /// <summary> | ||
| /// Generates the clipped shapes from the previously provided paths. | ||
| /// </summary> | ||
| /// <param name="operation">The clipping operation.</param> | ||
| /// <param name="rule">The intersection rule.</param> | ||
|
Check failure on line 20 in src/ImageSharp.Drawing/Shapes/PolygonClipper/Clipper.cs
|
||
| /// <returns>The <see cref="T:IPath[]"/>.</returns> | ||
| public IPath[] GenerateClippedShapes(ClippingOperation operation, IntersectionRule rule) | ||
| public IPath[] GenerateClippedShapes(BooleanOperation operation) | ||
| { | ||
| PathsF closedPaths = []; | ||
| PathsF openPaths = []; | ||
| ArgumentNullException.ThrowIfNull(this.subject); | ||
| ArgumentNullException.ThrowIfNull(this.clip); | ||
|
|
||
| FillRule fillRule = rule == IntersectionRule.EvenOdd ? FillRule.EvenOdd : FillRule.NonZero; | ||
| this.polygonClipper.Execute(operation, fillRule, closedPaths, openPaths); | ||
| SixLabors.PolygonClipper.PolygonClipper polygonClipper = new(this.subject, this.clip, operation); | ||
|
|
||
| IPath[] shapes = new IPath[closedPaths.Count + openPaths.Count]; | ||
| SixLabors.PolygonClipper.Polygon result = polygonClipper.Run(); | ||
|
|
||
|
Check failure on line 30 in src/ImageSharp.Drawing/Shapes/PolygonClipper/Clipper.cs
|
||
| int index = 0; | ||
| for (int i = 0; i < closedPaths.Count; i++) | ||
| { | ||
| PathF path = closedPaths[i]; | ||
| PointF[] points = new PointF[path.Count]; | ||
|
|
||
| for (int j = 0; j < path.Count; j++) | ||
| { | ||
| points[j] = path[j]; | ||
| } | ||
| IPath[] shapes = new IPath[result.Count]; | ||
|
|
||
| shapes[index++] = new Polygon(points); | ||
| } | ||
|
|
||
| for (int i = 0; i < openPaths.Count; i++) | ||
| int index = 0; | ||
| for (int i = 0; i < result.Count; i++) | ||
| { | ||
| PathF path = openPaths[i]; | ||
| PointF[] points = new PointF[path.Count]; | ||
| Contour contour = result[i]; | ||
| PointF[] points = new PointF[contour.Count]; | ||
|
|
||
| for (int j = 0; j < path.Count; j++) | ||
| for (int j = 0; j < contour.Count; j++) | ||
| { | ||
| points[j] = path[j]; | ||
| Vertex vertex = contour[j]; | ||
| points[j] = new PointF((float)vertex.X, (float)vertex.Y); | ||
| } | ||
|
|
||
| shapes[index++] = new Polygon(points); | ||
|
|
@@ -100,12 +87,25 @@ | |
| internal void AddPath(ISimplePath path, ClippingType clippingType) | ||
| { | ||
| ReadOnlySpan<PointF> vectors = path.Points.Span; | ||
| PathF points = new(vectors.Length); | ||
| for (int i = 0; i < vectors.Length; i++) | ||
| SixLabors.PolygonClipper.Polygon polygon = []; | ||
| Contour contour = new(); | ||
| polygon.Add(contour); | ||
|
|
||
| foreach (PointF point in vectors) | ||
| { | ||
| points.Add(vectors[i]); | ||
| contour.AddVertex(new Vertex(point.X, point.Y)); | ||
| } | ||
|
|
||
| this.polygonClipper.AddPath(points, clippingType, !path.IsClosed); | ||
| switch (clippingType) | ||
| { | ||
| case ClippingType.Clip: | ||
| this.clip = polygon; | ||
| break; | ||
| case ClippingType.Subject: | ||
| this.subject = polygon; | ||
| break; | ||
| default: | ||
| throw new ArgumentOutOfRangeException(nameof(clippingType), clippingType, null); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.