-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Changes from 1 commit
2e76417
6c6ff30
8f9696f
087f480
8e7164e
ef89dd0
26ead24
5b2179b
bf57cfe
f976353
de7fa43
ac98cc6
33afe06
20f6460
1174d90
52312a1
49aaf25
1006631
3b1b88d
f41dc74
6b42ee3
e5ada72
a8be3f9
ce69978
2cf5aea
815b1e6
ed7c042
4df8f1a
1714a6e
c852e15
38e9d2d
48b4236
8c84666
35acddc
f1d51f9
7a983d3
cc44415
3b457fb
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.