Skip to content

Commit 8f9696f

Browse files
committed
Fix ClipTest.Issue250
* Initialized clip and subject with empty polygon add a contour per path
1 parent 6c6ff30 commit 8f9696f

File tree

5 files changed

+7
-75
lines changed

5 files changed

+7
-75
lines changed

src/ImageSharp.Drawing/Shapes/ISimplePath.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,15 @@ public interface ISimplePath
2727
/// Converts to <see cref="SixLabors.PolygonClipper.Polygon"/>
2828
/// </summary>
2929
/// <returns>The converted polygon.</returns>
30-
internal SixLabors.PolygonClipper.Polygon ToPolygon()
30+
internal SixLabors.PolygonClipper.Contour ToContour()
3131
{
32-
SixLabors.PolygonClipper.Polygon polygon = [];
3332
Contour contour = new();
34-
polygon.Add(contour);
3533

3634
foreach (PointF point in this.Points.Span)
3735
{
3836
contour.AddVertex(new Vertex(point.X, point.Y));
3937
}
4038

41-
return polygon;
39+
return contour;
4240
}
4341
}

src/ImageSharp.Drawing/Shapes/PolygonClipper/Clipper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace SixLabors.ImageSharp.Drawing.Shapes.PolygonClipper;
1010
/// </summary>
1111
internal class Clipper
1212
{
13-
private SixLabors.PolygonClipper.Polygon? subject;
14-
private SixLabors.PolygonClipper.Polygon? clip;
13+
private SixLabors.PolygonClipper.Polygon subject = [];
14+
private SixLabors.PolygonClipper.Polygon clip = [];
1515

1616
/// <summary>
1717
/// Generates the clipped shapes from the previously provided paths.
@@ -85,15 +85,15 @@ public void AddPath(IPath path, ClippingType clippingType)
8585
/// <param name="clippingType">Type of the poly.</param>
8686
internal void AddPath(ISimplePath path, ClippingType clippingType)
8787
{
88-
SixLabors.PolygonClipper.Polygon polygon = path.ToPolygon();
88+
Contour contour = path.ToContour();
8989

9090
switch (clippingType)
9191
{
9292
case ClippingType.Clip:
93-
this.clip = polygon;
93+
this.clip.Add(contour);
9494
break;
9595
case ClippingType.Subject:
96-
this.subject = polygon;
96+
this.subject.Add(contour);
9797
break;
9898
default:
9999
throw new ArgumentOutOfRangeException(nameof(clippingType), clippingType, null);

src/ImageSharp.Drawing/Shapes/PolygonClipper/FillRule.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/ImageSharp.Drawing/Shapes/PolygonClipper/JoinWith.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/ImageSharp.Drawing/Shapes/PolygonClipper/VertexFlags.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)