99namespace SixLabors . ImageSharp . Drawing
1010{
1111 /// <summary>
12- /// Path extensions to generate outlines of paths .
12+ /// Extensions to <see cref="IPath"/> that allow the generation of outlines .
1313 /// </summary>
1414 public static class OutlinePathExtensions
1515 {
1616 private const double MiterOffsetDelta = 20 ;
17+ private const JointStyle DefaultJointStyle = JointStyle . Square ;
18+ private const EndCapStyle DefaultEndCapStyle = EndCapStyle . Butt ;
1719
1820 /// <summary>
19- /// Generates a outline of the path with alternating on and off segments based on the pattern .
21+ /// Generates an outline of the path.
2022 /// </summary>
21- /// <param name="path">the path to outline</param>
22- /// <param name="width">The final width outline</param>
23- /// <param name="pattern">The pattern made of multiples of the width.</param>
24- /// <returns>A new path representing the outline.</returns>
25- /// <exception cref="ClipperException">Couldn't calculate offset.</exception>
26- public static IPath GenerateOutline ( this IPath path , float width , float [ ] pattern )
27- => path . GenerateOutline ( width , new ReadOnlySpan < float > ( pattern ) ) ;
23+ /// <param name="path">The path to outline</param>
24+ /// <param name="width">The outline width.</param>
25+ /// <returns>A new <see cref="IPath"/> representing the outline.</returns>
26+ /// <exception cref="ClipperException">Thrown when an offset cannot be calculated.</exception>
27+ public static IPath GenerateOutline ( this IPath path , float width ) => GenerateOutline ( path , width , DefaultJointStyle , DefaultEndCapStyle ) ;
2828
2929 /// <summary>
30- /// Generates a outline of the path with alternating on and off segments based on the pattern .
30+ /// Generates an outline of the path.
3131 /// </summary>
32- /// <param name="path">the path to outline</param>
33- /// <param name="width">The final width outline</param>
34- /// <param name="pattern">The pattern made of multiples of the width.</param>
35- /// <returns>A new path representing the outline.</returns>
36- /// <exception cref="ClipperException">Couldn't calculate offset.</exception>
37- public static IPath GenerateOutline ( this IPath path , float width , ReadOnlySpan < float > pattern )
38- => path . GenerateOutline ( width , pattern , false ) ;
32+ /// <param name="path">The path to outline</param>
33+ /// <param name="width">The outline width.</param>
34+ /// <param name="jointStyle">The style to apply to the joints.</param>
35+ /// <param name="endCapStyle">The style to apply to the end caps.</param>
36+ /// <returns>A new <see cref="IPath"/> representing the outline.</returns>
37+ /// <exception cref="ClipperException">Thrown when an offset cannot be calculated.</exception>
38+ public static IPath GenerateOutline ( this IPath path , float width , JointStyle jointStyle , EndCapStyle endCapStyle )
39+ {
40+ ClipperOffset offset = new ( MiterOffsetDelta ) ;
41+ offset . AddPath ( path , jointStyle , endCapStyle ) ;
42+
43+ return offset . Execute ( width ) ;
44+ }
3945
4046 /// <summary>
41- /// Generates a outline of the path with alternating on and off segments based on the pattern.
47+ /// Generates an outline of the path with alternating on and off segments based on the pattern.
4248 /// </summary>
43- /// <param name="path">the path to outline</param>
44- /// <param name="width">The final width outline </param>
49+ /// <param name="path">The path to outline</param>
50+ /// <param name="width">The outline width. </param>
4551 /// <param name="pattern">The pattern made of multiples of the width.</param>
46- /// <param name="startOff">Weather the first item in the pattern is on or off.</param>
47- /// <returns>A new path representing the outline.</returns>
48- /// <exception cref="ClipperException">Couldn't calculate offset.</exception>
49- public static IPath GenerateOutline ( this IPath path , float width , float [ ] pattern , bool startOff )
50- => path . GenerateOutline ( width , new ReadOnlySpan < float > ( pattern ) , startOff ) ;
52+ /// <returns>A new <see cref="IPath"/> representing the outline.</returns>
53+ /// <exception cref="ClipperException">Thrown when an offset cannot be calculated.</exception>
54+ public static IPath GenerateOutline ( this IPath path , float width , ReadOnlySpan < float > pattern )
55+ => path . GenerateOutline ( width , pattern , false ) ;
5156
5257 /// <summary>
53- /// Generates a outline of the path with alternating on and off segments based on the pattern.
58+ /// Generates an outline of the path with alternating on and off segments based on the pattern.
5459 /// </summary>
55- /// <param name="path">the path to outline</param>
56- /// <param name="width">The final width outline </param>
60+ /// <param name="path">The path to outline</param>
61+ /// <param name="width">The outline width. </param>
5762 /// <param name="pattern">The pattern made of multiples of the width.</param>
58- /// <param name="startOff">Weather the first item in the pattern is on or off.</param>
59- /// <returns>A new path representing the outline.</returns>
60- /// <exception cref="ClipperException">Couldn't calculate offset.</exception>
63+ /// <param name="startOff">Whether the first item in the pattern is on or off.</param>
64+ /// <returns>A new <see cref="IPath"/> representing the outline.</returns>
65+ /// <exception cref="ClipperException">Thrown when an offset cannot be calculated .</exception>
6166 public static IPath GenerateOutline ( this IPath path , float width , ReadOnlySpan < float > pattern , bool startOff )
62- => GenerateOutline ( path , width , pattern , startOff , JointStyle . Square , EndCapStyle . Butt ) ;
67+ => GenerateOutline ( path , width , pattern , startOff , DefaultJointStyle , DefaultEndCapStyle ) ;
6368
6469 /// <summary>
65- /// Generates a outline of the path with alternating on and off segments based on the pattern.
70+ /// Generates an outline of the path with alternating on and off segments based on the pattern.
6671 /// </summary>
67- /// <param name="path">the path to outline</param>
68- /// <param name="width">The final width outline </param>
72+ /// <param name="path">The path to outline</param>
73+ /// <param name="width">The outline width. </param>
6974 /// <param name="pattern">The pattern made of multiples of the width.</param>
70- /// <param name="jointStyle">The style to render the joints.</param>
71- /// <param name="patternSectionCapStyle ">The style to render between sections of the specified pattern .</param>
72- /// <returns>A new path representing the outline.</returns>
73- /// <exception cref="ClipperException">Couldn't calculate offset.</exception>
74- public static IPath GenerateOutline ( this IPath path , float width , ReadOnlySpan < float > pattern , JointStyle jointStyle , EndCapStyle patternSectionCapStyle )
75- => GenerateOutline ( path , width , pattern , false , jointStyle , patternSectionCapStyle ) ;
75+ /// <param name="jointStyle">The style to apply to the joints.</param>
76+ /// <param name="endCapStyle ">The style to apply to the end caps .</param>
77+ /// <returns>A new <see cref="IPath"/> representing the outline.</returns>
78+ /// <exception cref="ClipperException">Thrown when an offset cannot be calculated .</exception>
79+ public static IPath GenerateOutline ( this IPath path , float width , ReadOnlySpan < float > pattern , JointStyle jointStyle , EndCapStyle endCapStyle )
80+ => GenerateOutline ( path , width , pattern , false , jointStyle , endCapStyle ) ;
7681
7782 /// <summary>
78- /// Generates a outline of the path with alternating on and off segments based on the pattern.
83+ /// Generates an outline of the path with alternating on and off segments based on the pattern.
7984 /// </summary>
80- /// <param name="path">the path to outline</param>
81- /// <param name="width">The final width outline </param>
85+ /// <param name="path">The path to outline</param>
86+ /// <param name="width">The outline width. </param>
8287 /// <param name="pattern">The pattern made of multiples of the width.</param>
83- /// <param name="startOff">Weather the first item in the pattern is on or off.</param>
84- /// <param name="jointStyle">The style to render the joints.</param>
85- /// <param name="patternSectionCapStyle ">The style to render between sections of the specified pattern .</param>
86- /// <returns>A new path representing the outline.</returns>
87- /// <exception cref="ClipperException">Couldn't calculate offset.</exception>
88- public static IPath GenerateOutline ( this IPath path , float width , ReadOnlySpan < float > pattern , bool startOff , JointStyle jointStyle = JointStyle . Square , EndCapStyle patternSectionCapStyle = EndCapStyle . Butt )
88+ /// <param name="startOff">Whether the first item in the pattern is on or off.</param>
89+ /// <param name="jointStyle">The style to apply to the joints.</param>
90+ /// <param name="endCapStyle ">The style to apply to the end caps .</param>
91+ /// <returns>A new <see cref="IPath"/> representing the outline.</returns>
92+ /// <exception cref="ClipperException">Thrown when an offset cannot be calculated .</exception>
93+ public static IPath GenerateOutline ( this IPath path , float width , ReadOnlySpan < float > pattern , bool startOff , JointStyle jointStyle , EndCapStyle endCapStyle )
8994 {
9095 if ( pattern . Length < 2 )
9196 {
92- return path . GenerateOutline ( width , jointStyle : jointStyle ) ;
97+ return path . GenerateOutline ( width , jointStyle , endCapStyle ) ;
9398 }
9499
95100 IEnumerable < ISimplePath > paths = path . Flatten ( ) ;
96101
97- var offset = new ClipperOffset ( MiterOffsetDelta ) ;
98- var buffer = new List < PointF > ( ) ;
102+ ClipperOffset offset = new ( MiterOffsetDelta ) ;
103+ List < PointF > buffer = new ( ) ;
99104 foreach ( ISimplePath p in paths )
100105 {
101106 bool online = ! startOff ;
@@ -130,7 +135,7 @@ public static IPath GenerateOutline(this IPath path, float width, ReadOnlySpan<f
130135 // we now inset a line joining
131136 if ( online )
132137 {
133- offset . AddPath ( new ReadOnlySpan < PointF > ( buffer . ToArray ( ) ) , jointStyle , patternSectionCapStyle ) ;
138+ offset . AddPath ( new ReadOnlySpan < PointF > ( buffer . ToArray ( ) ) , jointStyle , endCapStyle ) ;
134139 }
135140
136141 online = ! online ;
@@ -165,7 +170,7 @@ public static IPath GenerateOutline(this IPath path, float width, ReadOnlySpan<f
165170
166171 if ( online )
167172 {
168- offset . AddPath ( new ReadOnlySpan < PointF > ( buffer . ToArray ( ) ) , jointStyle , patternSectionCapStyle ) ;
173+ offset . AddPath ( new ReadOnlySpan < PointF > ( buffer . ToArray ( ) ) , jointStyle , endCapStyle ) ;
169174 }
170175
171176 online = ! online ;
@@ -178,31 +183,5 @@ public static IPath GenerateOutline(this IPath path, float width, ReadOnlySpan<f
178183
179184 return offset . Execute ( width ) ;
180185 }
181-
182- /// <summary>
183- /// Generates a solid outline of the path.
184- /// </summary>
185- /// <param name="path">the path to outline</param>
186- /// <param name="width">The final width outline</param>
187- /// <returns>A new path representing the outline.</returns>
188- /// <exception cref="ClipperException">Couldn't calculate offset.</exception>
189- public static IPath GenerateOutline ( this IPath path , float width ) => GenerateOutline ( path , width , JointStyle . Square , EndCapStyle . Butt ) ;
190-
191- /// <summary>
192- /// Generates a solid outline of the path.
193- /// </summary>
194- /// <param name="path">the path to outline</param>
195- /// <param name="width">The final width outline</param>
196- /// <param name="jointStyle">The style to render the joints.</param>
197- /// <param name="endCapStyle">The style to render the end caps of open paths (ignored on closed paths).</param>
198- /// <returns>A new path representing the outline.</returns>
199- /// <exception cref="ClipperException">Couldn't calculate offset.</exception>
200- public static IPath GenerateOutline ( this IPath path , float width , JointStyle jointStyle = JointStyle . Square , EndCapStyle endCapStyle = EndCapStyle . Square )
201- {
202- var offset = new ClipperOffset ( MiterOffsetDelta ) ;
203- offset . AddPath ( path , jointStyle , endCapStyle ) ;
204-
205- return offset . Execute ( width ) ;
206- }
207186 }
208187}
0 commit comments