|
2 | 2 | // Licensed under the Apache License, Version 2.0. |
3 | 3 |
|
4 | 4 | using System.Collections.Generic; |
5 | | -using SixLabors.ImageSharp.Drawing.PolygonClipper; |
| 5 | +using SixLabors.ImageSharp.Drawing.Processing; |
| 6 | +using SixLabors.ImageSharp.Drawing.Shapes.PolygonClipper; |
6 | 7 |
|
7 | 8 | namespace SixLabors.ImageSharp.Drawing |
8 | 9 | { |
9 | 10 | /// <summary> |
10 | | - /// Path extensions to clip paths. |
| 11 | + /// Provides extension methods to <see cref="IPath"/> that allow the clipping of shapes. |
11 | 12 | /// </summary> |
12 | 13 | public static class ClipPathExtensions |
13 | 14 | { |
14 | 15 | /// <summary> |
15 | | - /// Clips the specified holes. |
| 16 | + /// Clips the specified subject path with the provided clipping paths. |
16 | 17 | /// </summary> |
17 | | - /// <param name="shape">The shape.</param> |
18 | | - /// <param name="holes">The holes.</param> |
19 | | - /// <returns>Returns a new shape with the holes clipped out of the shape.</returns> |
20 | | - /// <exception cref="ClipperException">Open paths have been disabled.</exception> |
21 | | - public static IPath Clip(this IPath shape, IEnumerable<IPath> holes) |
| 18 | + /// <param name="subjectPath">The subject path.</param> |
| 19 | + /// <param name="clipPaths">The clipping paths.</param> |
| 20 | + /// <returns>The clipped <see cref="IPath"/>.</returns> |
| 21 | + /// <exception cref="ClipperException">Thrown when an error occured while attempting to clip the polygon.</exception> |
| 22 | + public static IPath Clip(this IPath subjectPath, params IPath[] clipPaths) |
| 23 | + => subjectPath.Clip((IEnumerable<IPath>)clipPaths); |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Clips the specified subject path with the provided clipping paths. |
| 27 | + /// </summary> |
| 28 | + /// <param name="subjectPath">The subject path.</param> |
| 29 | + /// <param name="options">The shape options.</param> |
| 30 | + /// <param name="clipPaths">The clipping paths.</param> |
| 31 | + /// <returns>The clipped <see cref="IPath"/>.</returns> |
| 32 | + /// <exception cref="ClipperException">Thrown when an error occured while attempting to clip the polygon.</exception> |
| 33 | + public static IPath Clip( |
| 34 | + this IPath subjectPath, |
| 35 | + ShapeOptions options, |
| 36 | + params IPath[] clipPaths) |
| 37 | + => subjectPath.Clip(options, (IEnumerable<IPath>)clipPaths); |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Clips the specified subject path with the provided clipping paths. |
| 41 | + /// </summary> |
| 42 | + /// <param name="subjectPath">The subject path.</param> |
| 43 | + /// <param name="clipPaths">The clipping paths.</param> |
| 44 | + /// <returns>The clipped <see cref="IPath"/>.</returns> |
| 45 | + /// <exception cref="ClipperException">Thrown when an error occured while attempting to clip the polygon.</exception> |
| 46 | + public static IPath Clip(this IPath subjectPath, IEnumerable<IPath> clipPaths) |
| 47 | + => subjectPath.Clip(new(), clipPaths); |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// Clips the specified subject path with the provided clipping paths. |
| 51 | + /// </summary> |
| 52 | + /// <param name="subjectPath">The subject path.</param> |
| 53 | + /// <param name="options">The shape options.</param> |
| 54 | + /// <param name="clipPaths">The clipping paths.</param> |
| 55 | + /// <returns>The clipped <see cref="IPath"/>.</returns> |
| 56 | + /// <exception cref="ClipperException">Thrown when an error occured while attempting to clip the polygon.</exception> |
| 57 | + public static IPath Clip( |
| 58 | + this IPath subjectPath, |
| 59 | + ShapeOptions options, |
| 60 | + IEnumerable<IPath> clipPaths) |
22 | 61 | { |
23 | | - var clipper = new Clipper(); |
| 62 | + Clipper clipper = new(); |
24 | 63 |
|
25 | | - clipper.AddPath(shape, ClippingType.Subject); |
26 | | - clipper.AddPaths(holes, ClippingType.Clip); |
| 64 | + clipper.AddPath(subjectPath, ClippingType.Subject); |
| 65 | + clipper.AddPaths(clipPaths, ClippingType.Clip); |
27 | 66 |
|
28 | | - IPath[] result = clipper.GenerateClippedShapes(); |
| 67 | + IPath[] result = clipper.GenerateClippedShapes(options.ClippingOperation, options.IntersectionRule); |
29 | 68 |
|
30 | 69 | return new ComplexPolygon(result); |
31 | 70 | } |
32 | | - |
33 | | - /// <summary> |
34 | | - /// Clips the specified holes. |
35 | | - /// </summary> |
36 | | - /// <param name="shape">The shape.</param> |
37 | | - /// <param name="holes">The holes.</param> |
38 | | - /// <returns>Returns a new shape with the holes clipped out of the shape.</returns> |
39 | | - /// <exception cref="ClipperException">Open paths have been disabled.</exception> |
40 | | - public static IPath Clip(this IPath shape, params IPath[] holes) |
41 | | - => shape.Clip((IEnumerable<IPath>)holes); |
42 | 71 | } |
43 | 72 | } |
0 commit comments