Skip to content

Commit 319b80d

Browse files
Wire up options
1 parent 3c8b5d3 commit 319b80d

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

src/ImageSharp.Drawing/Shapes/JointStyle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public enum JointStyle
1919
Round = 1,
2020

2121
/// <summary>
22-
/// Joints will generate to a long point unless the end of the point will exceed 20 times the width then we generate the joint using <see cref="Square"/>.
22+
/// Joints will generate to a long point unless the end of the point will exceed 4 times the width then we generate the joint using <see cref="Square"/>.
2323
/// </summary>
2424
Miter = 2
2525
}

src/ImageSharp.Drawing/Shapes/OutlinePathExtensions.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ public static IPath GenerateOutline(this IPath path, float width)
3434
/// <param name="endCapStyle">The style to apply to the end caps.</param>
3535
/// <returns>A new <see cref="IPath"/> representing the outline.</returns>
3636
/// <exception cref="ClipperException">Thrown when an offset cannot be calculated.</exception>
37-
#pragma warning disable RCS1163 // Unused parameter
38-
#pragma warning disable IDE0060 // Remove unused parameter
3937
public static IPath GenerateOutline(this IPath path, float width, JointStyle jointStyle, EndCapStyle endCapStyle)
40-
#pragma warning restore IDE0060 // Remove unused parameter
41-
#pragma warning restore RCS1163 // Unused parameter
4238
{
4339
if (width <= 0)
4440
{
@@ -47,11 +43,10 @@ public static IPath GenerateOutline(this IPath path, float width, JointStyle joi
4743

4844
List<Polygon> stroked = [];
4945

50-
// TODO: Wire up options
51-
PolygonStroker stroker = new() { Width = width, LineJoin = LineJoin.BevelJoin, LineCap = LineCap.Butt };
46+
PolygonStroker stroker = new() { Width = width, LineJoin = GetLineJoin(jointStyle), LineCap = GetLineCap(endCapStyle) };
5247
foreach (ISimplePath simplePath in path.Flatten())
5348
{
54-
stroked.Add(new Polygon(stroker.ProcessPath(simplePath.Points.Span, simplePath.IsClosed).ToArray()));
49+
stroked.Add(new Polygon(stroker.ProcessPath(simplePath.Points.Span, simplePath.IsClosed || endCapStyle is EndCapStyle.Polygon or EndCapStyle.Joined).ToArray()));
5550
}
5651

5752
return new ComplexPolygon(stroked);
@@ -116,14 +111,11 @@ public static IPath GenerateOutline(this IPath path, float width, ReadOnlySpan<f
116111
return path.GenerateOutline(width, jointStyle, endCapStyle);
117112
}
118113

119-
IEnumerable<ISimplePath> paths = path.Flatten();
120-
121-
// TODO: Wire up options
122-
PolygonStroker stroker = new() { Width = width, LineJoin = LineJoin.BevelJoin, LineCap = LineCap.Butt };
123-
114+
PolygonStroker stroker = new() { Width = width, LineJoin = GetLineJoin(jointStyle), LineCap = GetLineCap(endCapStyle) };
124115
PathsF stroked = [];
125116
List<PointF> buffer = [];
126-
foreach (ISimplePath simplePath in paths)
117+
118+
foreach (ISimplePath simplePath in path.Flatten())
127119
{
128120
bool online = !invert;
129121
float targetLength = pattern[0] * width;
@@ -226,4 +218,20 @@ public static IPath GenerateOutline(this IPath path, float width, ReadOnlySpan<f
226218

227219
return new ComplexPolygon(result);
228220
}
221+
222+
private static LineJoin GetLineJoin(JointStyle value)
223+
=> value switch
224+
{
225+
JointStyle.Square => LineJoin.BevelJoin,
226+
JointStyle.Round => LineJoin.RoundJoin,
227+
_ => LineJoin.MiterJoin,
228+
};
229+
230+
private static LineCap GetLineCap(EndCapStyle value)
231+
=> value switch
232+
{
233+
EndCapStyle.Round => LineCap.Round,
234+
EndCapStyle.Square => LineCap.Square,
235+
_ => LineCap.Butt,
236+
};
229237
}

0 commit comments

Comments
 (0)