Skip to content

Commit a31cb87

Browse files
Cleanup
1 parent a50a5be commit a31cb87

2 files changed

Lines changed: 22 additions & 26 deletions

File tree

src/ImageSharp.Drawing/Shapes/Path.cs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Diagnostics.CodeAnalysis;
76
using System.Linq;
87
using System.Numerics;
9-
using System.Runtime.CompilerServices;
108

119
namespace SixLabors.ImageSharp.Drawing
1210
{
@@ -161,15 +159,15 @@ public static bool TryParseSvgPath(ReadOnlySpan<char> data, out IPath value)
161159
char ch = data[0];
162160
if (char.IsDigit(ch) || ch == '-' || ch == '+' || ch == '.')
163161
{
164-
// are we are the end of the string or we are at the end of the path
162+
// Are we are the end of the string or we are at the end of the path?
165163
if (data.Length == 0 || op == 'Z')
166164
{
167165
return false;
168166
}
169167
}
170-
else if (IsSeperator(ch))
168+
else if (IsSeparator(ch))
171169
{
172-
data = TrimSeperator(data);
170+
data = TrimSeparator(data);
173171
}
174172
else
175173
{
@@ -181,7 +179,7 @@ public static bool TryParseSvgPath(ReadOnlySpan<char> data, out IPath value)
181179
relative = true;
182180
}
183181

184-
data = TrimSeperator(data.Slice(1));
182+
data = TrimSeparator(data.Slice(1));
185183
}
186184

187185
switch (op)
@@ -262,16 +260,16 @@ public static bool TryParseSvgPath(ReadOnlySpan<char> data, out IPath value)
262260
break;
263261
case 'A':
264262
data = FindScaler(data, out float radiiX);
265-
data = TrimSeperator(data);
263+
data = TrimSeparator(data);
266264
data = FindScaler(data, out float radiiY);
267-
data = TrimSeperator(data);
265+
data = TrimSeparator(data);
268266
data = FindScaler(data, out float angle);
269-
data = TrimSeperator(data);
267+
data = TrimSeparator(data);
270268
data = FindScaler(data, out float largeArc);
271-
data = TrimSeperator(data);
269+
data = TrimSeparator(data);
272270
data = FindScaler(data, out float sweep);
273271

274-
data = FindPoint(data, out var point, relative, c);
272+
data = FindPoint(data, out PointF point, relative, c);
275273
if (data.Length > 0)
276274
{
277275
builder.ArcTo(radiiX, radiiY, angle, largeArc == 1, sweep == 1, point);
@@ -304,10 +302,10 @@ public static bool TryParseSvgPath(ReadOnlySpan<char> data, out IPath value)
304302
value = builder.Build();
305303
return true;
306304

307-
static bool IsSeperator(char ch)
305+
static bool IsSeparator(char ch)
308306
=> char.IsWhiteSpace(ch) || ch == ',';
309307

310-
static ReadOnlySpan<char> TrimSeperator(ReadOnlySpan<char> data)
308+
static ReadOnlySpan<char> TrimSeparator(ReadOnlySpan<char> data)
311309
{
312310
if (data.Length == 0)
313311
{
@@ -317,7 +315,7 @@ static ReadOnlySpan<char> TrimSeperator(ReadOnlySpan<char> data)
317315
int idx = 0;
318316
for (; idx < data.Length; idx++)
319317
{
320-
if (!IsSeperator(data[idx]))
318+
if (!IsSeparator(data[idx]))
321319
{
322320
break;
323321
}
@@ -326,7 +324,7 @@ static ReadOnlySpan<char> TrimSeperator(ReadOnlySpan<char> data)
326324
return data.Slice(idx);
327325
}
328326

329-
static ReadOnlySpan<char> FindPoint(ReadOnlySpan<char> str, out PointF value, bool isRelative, in PointF relative)
327+
static ReadOnlySpan<char> FindPoint(ReadOnlySpan<char> str, out PointF value, bool isRelative, PointF relative)
330328
{
331329
str = FindScaler(str, out float x);
332330
str = FindScaler(str, out float y);
@@ -342,16 +340,15 @@ static ReadOnlySpan<char> FindPoint(ReadOnlySpan<char> str, out PointF value, bo
342340

343341
static ReadOnlySpan<char> FindScaler(ReadOnlySpan<char> str, out float scaler)
344342
{
345-
str = TrimSeperator(str);
343+
str = TrimSeparator(str);
346344
scaler = 0;
347345

348-
for (var i = 0; i < str.Length; i++)
346+
for (int i = 0; i < str.Length; i++)
349347
{
350-
if (IsSeperator(str[i]) || i == str.Length)
348+
if (IsSeparator(str[i]) || i == str.Length)
351349
{
352350
scaler = ParseFloat(str.Slice(0, i));
353-
str = str.Slice(i);
354-
return str;
351+
return str.Slice(i);
355352
}
356353
}
357354

@@ -360,8 +357,7 @@ static ReadOnlySpan<char> FindScaler(ReadOnlySpan<char> str, out float scaler)
360357
scaler = ParseFloat(str);
361358
}
362359

363-
str = ReadOnlySpan<char>.Empty;
364-
return str;
360+
return ReadOnlySpan<char>.Empty;
365361
}
366362

367363
#if !NETCOREAPP2_1_OR_GREATER

tests/ImageSharp.Drawing.Tests/Drawing/FillPathTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@ public void FillPathSVGArcs<TPixel>(TestImageProvider<TPixel> provider)
2323
pb.MoveTo(new Vector2(80, 80))
2424
.ArcTo(45, 45, 0, false, false, new Vector2(125, 125))
2525
.LineTo(new Vector2(125, 80))
26-
.LineTo(new Vector2(80, 80));
26+
.CloseFigure();
2727

2828
IPath path = pb.Build();
2929

3030
pb = new PathBuilder();
3131
pb.MoveTo(new Vector2(230, 80))
3232
.ArcTo(45, 45, 0, true, false, new Vector2(275, 125))
3333
.LineTo(new Vector2(275, 80))
34-
.LineTo(new Vector2(230, 80));
34+
.CloseFigure();
3535

3636
IPath path2 = pb.Build();
3737

3838
pb = new PathBuilder();
3939
pb.MoveTo(new Vector2(80, 230))
4040
.ArcTo(45, 45, 0, false, true, new Vector2(125, 275))
4141
.LineTo(new Vector2(125, 230))
42-
.LineTo(new Vector2(80, 230));
42+
.CloseFigure();
4343

4444
IPath path3 = pb.Build();
4545

4646
pb = new PathBuilder();
4747
pb.MoveTo(new Vector2(230, 230))
4848
.ArcTo(45, 45, 0, true, true, new Vector2(275, 275))
4949
.LineTo(new Vector2(275, 230))
50-
.LineTo(new Vector2(230, 230));
50+
.CloseFigure();
5151

5252
IPath path4 = pb.Build();
5353

0 commit comments

Comments
 (0)