Skip to content

Commit

Permalink
Merge pull request svg-net#285 from LightningDragon/master
Browse files Browse the repository at this point in the history
Added array caching to AddToPath for a significant performance increase.
  • Loading branch information
tebjan committed Mar 2, 2017
2 parents df31b65 + f1a927c commit 0b727f1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Source/Paths/SvgClosePathSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ public sealed class SvgClosePathSegment : SvgPathSegment
public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath graphicsPath)
{
// Important for custom line caps. Force the path the close with an explicit line, not just an implicit close of the figure.
if (graphicsPath.PointCount > 0 && !graphicsPath.PathPoints[0].Equals(graphicsPath.PathPoints[graphicsPath.PathPoints.Length - 1]))
var pathPoints = graphicsPath.PathPoints;

if (pathPoints.Length > 0 && !pathPoints[0].Equals(pathPoints[pathPoints.Length - 1]))
{
int i = graphicsPath.PathTypes.Length - 1;
while (i >= 0 && graphicsPath.PathTypes[i] > 0) i--;
var pathTypes = graphicsPath.PathTypes;
int i = pathPoints.Length - 1;
while (i >= 0 && pathTypes[i] > 0) i--;
if (i < 0) i = 0;
graphicsPath.AddLine(graphicsPath.PathPoints[graphicsPath.PathPoints.Length - 1], graphicsPath.PathPoints[i]);
graphicsPath.AddLine(pathPoints[pathPoints.Length - 1], pathPoints[i]);
}

graphicsPath.CloseFigure();
}

Expand Down

0 comments on commit 0b727f1

Please sign in to comment.