Skip to content

Commit b832b05

Browse files
Use ShapeOptions directly.
1 parent b45e6d2 commit b832b05

3 files changed

Lines changed: 23 additions & 15 deletions

File tree

src/ImageSharp.Drawing/Processing/ShapeOptions.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,21 @@ public ShapeOptions()
1515
{
1616
}
1717

18-
private ShapeOptions(ShapeOptions source) => this.IntersectionRule = source.IntersectionRule;
18+
private ShapeOptions(ShapeOptions source)
19+
{
20+
this.IntersectionRule = source.IntersectionRule;
21+
this.ClippingOperation = source.ClippingOperation;
22+
}
23+
24+
/// <summary>
25+
/// Gets or sets the clipping operation.
26+
/// <para/>
27+
/// Defaults to <see cref="ClippingOperation.Difference"/>.
28+
/// </summary>
29+
public ClippingOperation ClippingOperation { get; set; } = ClippingOperation.Difference;
1930

2031
/// <summary>
21-
/// Gets or sets a value indicating whether antialiasing should be applied.
32+
/// Gets or sets the rule for calculating intersection points.
2233
/// <para/>
2334
/// Defaults to <see cref="IntersectionRule.EvenOdd"/>.
2435
/// </summary>

src/ImageSharp.Drawing/Shapes/ClipPathExtensions.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
using System.Collections.Generic;
5+
using SixLabors.ImageSharp.Drawing.Processing;
56
using SixLabors.ImageSharp.Drawing.Shapes.PolygonClipper;
67

78
namespace SixLabors.ImageSharp.Drawing
@@ -25,17 +26,15 @@ public static IPath Clip(this IPath subjectPath, params IPath[] clipPaths)
2526
/// Clips the specified subject path with the provided clipping paths.
2627
/// </summary>
2728
/// <param name="subjectPath">The subject path.</param>
28-
/// <param name="operation">The clipping operation.</param>
29-
/// <param name="rule">The intersection rule.</param>
29+
/// <param name="options">The shape options.</param>
3030
/// <param name="clipPaths">The clipping paths.</param>
3131
/// <returns>The clipped <see cref="IPath"/>.</returns>
3232
/// <exception cref="ClipperException">Thrown when an error occured while attempting to clip the polygon.</exception>
3333
public static IPath Clip(
3434
this IPath subjectPath,
35-
ClippingOperation operation,
36-
IntersectionRule rule,
35+
ShapeOptions options,
3736
params IPath[] clipPaths)
38-
=> subjectPath.Clip(operation, rule, (IEnumerable<IPath>)clipPaths);
37+
=> subjectPath.Clip(options, (IEnumerable<IPath>)clipPaths);
3938

4039
/// <summary>
4140
/// Clips the specified subject path with the provided clipping paths.
@@ -45,29 +44,27 @@ public static IPath Clip(
4544
/// <returns>The clipped <see cref="IPath"/>.</returns>
4645
/// <exception cref="ClipperException">Thrown when an error occured while attempting to clip the polygon.</exception>
4746
public static IPath Clip(this IPath subjectPath, IEnumerable<IPath> clipPaths)
48-
=> subjectPath.Clip(ClippingOperation.Difference, IntersectionRule.EvenOdd, clipPaths);
47+
=> subjectPath.Clip(new(), clipPaths);
4948

5049
/// <summary>
5150
/// Clips the specified subject path with the provided clipping paths.
5251
/// </summary>
5352
/// <param name="subjectPath">The subject path.</param>
54-
/// <param name="operation">The clipping operation.</param>
55-
/// <param name="rule">The intersection rule.</param>
53+
/// <param name="options">The shape options.</param>
5654
/// <param name="clipPaths">The clipping paths.</param>
5755
/// <returns>The clipped <see cref="IPath"/>.</returns>
5856
/// <exception cref="ClipperException">Thrown when an error occured while attempting to clip the polygon.</exception>
5957
public static IPath Clip(
6058
this IPath subjectPath,
61-
ClippingOperation operation,
62-
IntersectionRule rule,
59+
ShapeOptions options,
6360
IEnumerable<IPath> clipPaths)
6461
{
6562
Clipper clipper = new();
6663

6764
clipper.AddPath(subjectPath, ClippingType.Subject);
6865
clipper.AddPaths(clipPaths, ClippingType.Clip);
6966

70-
IPath[] result = clipper.GenerateClippedShapes(operation, rule);
67+
IPath[] result = clipper.GenerateClippedShapes(options.ClippingOperation, options.IntersectionRule);
7168

7269
return new ComplexPolygon(result);
7370
}

tests/ImageSharp.Drawing.Tests/Drawing/FillPolygonTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Numerics;
66
using SixLabors.ImageSharp.Drawing.Processing;
7-
using SixLabors.ImageSharp.Drawing.Shapes.PolygonClipper;
87
using SixLabors.ImageSharp.Drawing.Tests.TestUtilities.ImageComparison;
98
using SixLabors.ImageSharp.PixelFormats;
109
using SixLabors.ImageSharp.Processing;
@@ -195,7 +194,8 @@ public void FillPolygon_StarCircle_AllOperations(TestImageProvider<Rgba32> provi
195194
// See http://www.angusj.com/clipper2/Docs/Units/Clipper/Types/ClipType.htm for reference.
196195
foreach (ClippingOperation operation in (ClippingOperation[])Enum.GetValues(typeof(ClippingOperation)))
197196
{
198-
IPath shape = star.Clip(operation, IntersectionRule.EvenOdd, circle);
197+
ShapeOptions options = new() { ClippingOperation = operation };
198+
IPath shape = star.Clip(options, circle);
199199

200200
provider.RunValidatingProcessorTest(
201201
c => c.Fill(Color.DeepPink, circle).Fill(Color.LightGray, star).Fill(Color.ForestGreen, shape),

0 commit comments

Comments
 (0)