Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/ImageSharp.Drawing/Shapes/InternalPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,21 @@ private InternalPath(PointData[] points, bool isClosedPath)
this.points = points;
this.closedPath = isClosedPath;

float minX = this.points.Min(x => x.Point.X);
float maxX = this.points.Max(x => x.Point.X);
float minY = this.points.Min(x => x.Point.Y);
float maxY = this.points.Max(x => x.Point.Y);
if (this.points.Length > 0)
{
float minX = this.points.Min(x => x.Point.X);
float maxX = this.points.Max(x => x.Point.X);
float minY = this.points.Min(x => x.Point.Y);
float maxY = this.points.Max(x => x.Point.Y);

this.Bounds = new RectangleF(minX, minY, maxX - minX, maxY - minY);
this.Length = this.points.Sum(x => x.Length);
this.Bounds = new RectangleF(minX, minY, maxX - minX, maxY - minY);
Comment thread
dlemstra marked this conversation as resolved.
this.Length = this.points.Sum(x => x.Length);
}
else
{
this.Bounds = RectangleF.Empty;
this.Length = 0;
}
}

/// <summary>
Expand Down Expand Up @@ -684,10 +692,14 @@ private static PointData[] Simplify(IEnumerable<ILineSegment> segments, bool isC
private static PointData[] Simplify(IEnumerable<PointF> vectors, bool isClosed)
{
PointF[] points = vectors.ToArray();
var results = new List<PointData>();

int polyCorners = points.Length;
if (polyCorners == 0)
{
return Array.Empty<PointData>();
}

var results = new List<PointData>();
Vector2 lastPoint = points[0];

if (!isClosed)
Expand Down
20 changes: 20 additions & 0 deletions tests/ImageSharp.Drawing.Tests/Issues/Issues-48.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using Xunit;

namespace SixLabors.ImageSharp.Drawing.Tests.Issues
{
// https://github.com/SixLabors/ImageSharp.Drawing/issues/48
// index out of rang error if zero length ChildPath of a ComplexPolygon
public class Issues_48
{
[Fact]
public void DoNotThowIfPolygonHasZeroLength()
{
var emptyPoly = new ComplexPolygon(new Polygon());
emptyPoly.FindIntersections(new PointF(0, 0), new PointF(100, 100));
}
}
}