Skip to content

Commit 2a6cbd4

Browse files
committed
Change ClipperLib.ClipperExcpetion to public, remove the try..catch and adjust documentation
1 parent 1738d9d commit 2a6cbd4

6 files changed

Lines changed: 31 additions & 45 deletions

File tree

src/ImageSharp.Drawing/ImageSharp.Drawing.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1;netstandard2.1;netstandard2.0;netstandard1.3;net472</TargetFrameworks>
1616
</PropertyGroup>
1717

18+
<ItemGroup>
19+
<Compile Remove="Shapes\PolygonClipper\ClipperException.cs" />
20+
</ItemGroup>
21+
1822
<ItemGroup>
1923
<None Include="..\..\shared-infrastructure\branding\icons\imagesharp.drawing\sixlabors.imagesharp.drawing.128.png" Pack="true" PackagePath="" />
2024
</ItemGroup>

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <auto-generated />
1+
// <auto-generated />
22
// not really auto generated but is a code based dependency from https://sourceforge.net/projects/polyclipping/
33
// only update is to make everything internal
44
/*******************************************************************************
@@ -4987,9 +4987,20 @@ internal void DoRound(int j, int k)
49874987
//------------------------------------------------------------------------------
49884988
}
49894989

4990-
class ClipperException : Exception
4990+
/// <summary>
4991+
/// Clipper Exception
4992+
/// </summary>
4993+
/// <seealso cref="System.Exception" />
4994+
public class ClipperException : Exception
49914995
{
4992-
public ClipperException(string description) : base(description) { }
4996+
/// <summary>
4997+
/// Initializes a new instance of the <see cref="ClipperException"/> class.
4998+
/// </summary>
4999+
/// <param name="description">The description.</param>
5000+
public ClipperException(string description)
5001+
: base(description)
5002+
{
5003+
}
49935004
}
49945005
//------------------------------------------------------------------------------
49955006

src/ImageSharp.Drawing/Shapes/OutlinePathExtensions.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static class OutlinePathExtensions
2222
/// <param name="width">The final width outline</param>
2323
/// <param name="pattern">The pattern made of multiples of the width.</param>
2424
/// <returns>A new path representing the outline.</returns>
25-
/// <exception cref="ClipperException">Execute: Couldn't caculate Offset</exception>
25+
/// <exception cref="ClipperException">Calculate: Couldn't caculate Offset</exception>
2626
public static IPath GenerateOutline(this IPath path, float width, float[] pattern)
2727
=> path.GenerateOutline(width, new ReadOnlySpan<float>(pattern));
2828

@@ -33,7 +33,7 @@ public static IPath GenerateOutline(this IPath path, float width, float[] patter
3333
/// <param name="width">The final width outline</param>
3434
/// <param name="pattern">The pattern made of multiples of the width.</param>
3535
/// <returns>A new path representing the outline.</returns>
36-
/// <exception cref="ClipperException">Execute: Couldn't caculate Offset</exception>
36+
/// <exception cref="ClipperException">Calculate: Couldn't caculate Offset</exception>
3737
public static IPath GenerateOutline(this IPath path, float width, ReadOnlySpan<float> pattern)
3838
=> path.GenerateOutline(width, pattern, false);
3939

@@ -45,7 +45,7 @@ public static IPath GenerateOutline(this IPath path, float width, ReadOnlySpan<f
4545
/// <param name="pattern">The pattern made of multiples of the width.</param>
4646
/// <param name="startOff">Weather the first item in the pattern is on or off.</param>
4747
/// <returns>A new path representing the outline.</returns>
48-
/// <exception cref="ClipperException">Execute: Couldn't caculate Offset</exception>
48+
/// <exception cref="ClipperException">Calculate: Couldn't caculate Offset</exception>
4949
public static IPath GenerateOutline(this IPath path, float width, float[] pattern, bool startOff)
5050
=> path.GenerateOutline(width, new ReadOnlySpan<float>(pattern), startOff);
5151

@@ -57,7 +57,7 @@ public static IPath GenerateOutline(this IPath path, float width, float[] patter
5757
/// <param name="pattern">The pattern made of multiples of the width.</param>
5858
/// <param name="startOff">Weather the first item in the pattern is on or off.</param>
5959
/// <returns>A new path representing the outline.</returns>
60-
/// <exception cref="ClipperException">Execute: Couldn't caculate Offset</exception>
60+
/// <exception cref="ClipperException">Calculate: Couldn't caculate Offset</exception>
6161
public static IPath GenerateOutline(this IPath path, float width, ReadOnlySpan<float> pattern, bool startOff)
6262
=> GenerateOutline(path, width, pattern, startOff, JointStyle.Square, EndCapStyle.Butt);
6363

@@ -71,7 +71,7 @@ public static IPath GenerateOutline(this IPath path, float width, ReadOnlySpan<f
7171
/// <param name="jointStyle">The style to render the joints.</param>
7272
/// <param name="patternSectionCapStyle">The style to render between sections of the specified pattern.</param>
7373
/// <returns>A new path representing the outline.</returns>
74-
/// <exception cref="ClipperException">Execute: Couldn't caculate Offset</exception>
74+
/// <exception cref="ClipperException">Calculate: Couldn't caculate Offset</exception>
7575
public static IPath GenerateOutline(this IPath path, float width, ReadOnlySpan<float> pattern, bool startOff, JointStyle jointStyle = JointStyle.Square, EndCapStyle patternSectionCapStyle = EndCapStyle.Butt)
7676
{
7777
if (pattern.Length < 2)
@@ -172,7 +172,7 @@ public static IPath GenerateOutline(this IPath path, float width, ReadOnlySpan<f
172172
/// <param name="path">the path to outline</param>
173173
/// <param name="width">The final width outline</param>
174174
/// <returns>A new path representing the outline.</returns>
175-
/// <exception cref="ClipperException">Execute: Couldn't caculate Offset</exception>
175+
/// <exception cref="ClipperException">Calculate: Couldn't caculate Offset</exception>
176176
public static IPath GenerateOutline(this IPath path, float width) => GenerateOutline(path, width, JointStyle.Square, EndCapStyle.Butt);
177177

178178
/// <summary>
@@ -183,7 +183,7 @@ public static IPath GenerateOutline(this IPath path, float width, ReadOnlySpan<f
183183
/// <param name="jointStyle">The style to render the joints.</param>
184184
/// <param name="endCapStyle">The style to render the end caps of open paths (ignored on closed paths).</param>
185185
/// <returns>A new path representing the outline.</returns>
186-
/// <exception cref="ClipperException">Execute: Couldn't caculate Offset</exception>
186+
/// <exception cref="ClipperException">Calculate: Couldn't caculate Offset</exception>
187187
public static IPath GenerateOutline(this IPath path, float width, JointStyle jointStyle = JointStyle.Square, EndCapStyle endCapStyle = EndCapStyle.Square)
188188
{
189189
var offset = new ClipperOffset(MiterOffsetDelta);

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,7 @@ public IPath[] GenerateClippedShapes()
4949

5050
lock (this.syncRoot)
5151
{
52-
try
53-
{
54-
this.innerClipper.Execute(ClipType.ctDifference, results);
55-
}
56-
catch (ClipperLib.ClipperException exception)
57-
{
58-
throw new PolygonClipper.ClipperException(exception.Message);
59-
}
52+
this.innerClipper.Execute(ClipType.ctDifference, results);
6053
}
6154

6255
var shapes = new IPath[results.Count];
@@ -151,14 +144,7 @@ internal void AddPath(ISimplePath path, ClippingType clippingType)
151144
PolyType type = clippingType == ClippingType.Clip ? PolyType.ptClip : PolyType.ptSubject;
152145
lock (this.syncRoot)
153146
{
154-
try
155-
{
156-
this.innerClipper.AddPath(points, type, path.IsClosed);
157-
}
158-
catch (ClipperLib.ClipperException exception)
159-
{
160-
throw new PolygonClipper.ClipperException(exception.Message);
161-
}
147+
this.innerClipper.AddPath(points, type, path.IsClosed);
162148
}
163149
}
164150
}

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,13 @@ internal class ClipperOffset
3030
/// </summary>
3131
/// <param name="width">Width</param>
3232
/// <returns>path offset</returns>
33-
/// <exception cref="ClipperException">Execute: Couldn't caculate Offset</exception>
33+
/// <exception cref="ClipperException">Calculate: Couldn't caculate Offset</exception>
3434
public ComplexPolygon Execute(float width)
3535
{
3636
var tree = new List<List<IntPoint>>();
3737
lock (this.syncRoot)
3838
{
39-
try
40-
{
41-
this.innerClipperOffest.Execute(ref tree, width * ScalingFactor / 2);
42-
}
43-
catch (ClipperLib.ClipperException exception)
44-
{
45-
throw new PolygonClipper.ClipperException(exception.Message);
46-
}
39+
this.innerClipperOffest.Execute(ref tree, width * ScalingFactor / 2);
4740
}
4841

4942
var polygons = new List<Polygon>();
@@ -113,14 +106,7 @@ private void AddPath(ReadOnlySpan<PointF> pathPoints, JointStyle jointStyle, End
113106

114107
lock (this.syncRoot)
115108
{
116-
try
117-
{
118-
this.innerClipperOffest.AddPath(points, this.Convert(jointStyle), endCapStyle);
119-
}
120-
catch (ClipperLib.ClipperException exception)
121-
{
122-
throw new PolygonClipper.ClipperException(exception.Message);
123-
}
109+
this.innerClipperOffest.AddPath(points, this.Convert(jointStyle), endCapStyle);
124110
}
125111
}
126112

tests/ImageSharp.Drawing.Tests/Shapes/PolygonClipper/ClipperTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,13 @@ public void ClipperOffsetThrowsPublicException()
138138
PointF naan = new PointF(float.NaN, float.NaN);
139139
Polygon path = new Polygon(new LinearLineSegment(new[] { naan, naan, naan, naan }));
140140

141-
// Throws internal exception:
142141
try
143142
{
144143
path.GenerateOutline(10);
145144
}
146145
catch (System.Exception ex)
147146
{
148-
Assert.True(ex is ClipperException);
147+
Assert.True(ex is ClipperLib.ClipperException);
149148
}
150149
}
151150
}

0 commit comments

Comments
 (0)