Skip to content

Commit 4569fe7

Browse files
committed
Cleaned up PolygonStroker.Accumulate
1 parent 99a6283 commit 4569fe7

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,22 @@ public PathF ProcessPath(ReadOnlySpan<PointF> pathPoints, bool isClosed)
6767
this.AddVertex(0, 0, PathCommand.EndPoly | (PathCommand)PathFlags.Close);
6868
}
6969

70-
double x = 0;
71-
double y = 0;
70+
PointF currentPoint = new(0, 0);
7271
int startIndex = 0;
7372
PointF? lastPoint = null;
7473
PathCommand command;
7574

7675
PathF results = new(pathPoints.Length * 3);
77-
while (!(command = this.Accumulate(ref x, ref y)).Stop())
76+
while (!(command = this.Accumulate(ref currentPoint)).Stop())
7877
{
79-
PointF currentPoint;
8078
if (command.EndPoly() && results.Count > 0)
8179
{
8280
PointF initial = results[startIndex];
83-
currentPoint = new(initial.X, initial.Y);
84-
results.Add(currentPoint);
81+
results.Add(initial);
8582
startIndex = results.Count;
8683
}
8784
else
8885
{
89-
currentPoint = new((float)x, (float)y);
9086
if (currentPoint != lastPoint)
9187
{
9288
results.Add(currentPoint);
@@ -132,7 +128,7 @@ private void AddVertex(double x, double y, PathCommand cmd)
132128
}
133129
}
134130

135-
private PathCommand Accumulate(ref double x, ref double y)
131+
private PathCommand Accumulate(ref PointF point)
136132
{
137133
PathCommand cmd = PathCommand.LineTo;
138134
while (!cmd.Stop())
@@ -255,8 +251,7 @@ ref this.srcVertices[(this.srcVertex + this.srcVertices.Length - 1) % this.srcVe
255251
else
256252
{
257253
PointF c = this.outVertices[this.outVertex++];
258-
x = c.X;
259-
y = c.Y;
254+
point = c;
260255

261256
return cmd;
262257
}
@@ -300,7 +295,6 @@ private void AddVertex(double x, double y, double distance = 0)
300295
this.srcVertices.Add(new VertexDistance(x, y, distance));
301296
}
302297

303-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
304298
private void CloseVertexPath(bool closed)
305299
{
306300
while (this.srcVertices.Length > 1)

0 commit comments

Comments
 (0)