fix intersections counting for ellipses

This commit is contained in:
Scott Williams 2017-02-03 19:08:05 +00:00
Родитель e7fb320fb4
Коммит a0edf9eaa3
4 изменённых файлов: 29 добавлений и 10 удалений

Просмотреть файл

@ -19,7 +19,7 @@ namespace SixLabors.Shapes
/// <summary>
/// The epsilon for float comparison
/// </summary>
private const float Epsilon = 0.0001f;
private const float Epsilon = 0.001f;
/// <summary>
/// The maximum vector
@ -234,11 +234,11 @@ namespace SixLabors.Shapes
{
// hit the same point a second time do we need to remove the old one if just clipping
var side = SideOfLine(this.points[last], start, end);
if (side != Side.Same && side == SideOfLine(this.points[next], start, end))
if(side != Side.Same && side == SideOfLine(this.points[next], start, end))
{
// same side we don't bother adding the crossing
position--; // move back one and the next hist will replace it
count++;
buffer[position + offset] = point;
position++;
count--;
}
}
else
@ -254,6 +254,7 @@ namespace SixLabors.Shapes
lastPoint = point;
}
}
// don't trim the last point
if(position > 1 && this.closedPath && buffer[offset].Equivelent(buffer[position + offset -1], Epsilon) )
{

Просмотреть файл

@ -170,7 +170,7 @@ namespace SixLabors.Shapes
/// <value>
/// The center.
/// </value>
public Vector2 Center => this.topLeft + (this.bottomRight / 2);
public Vector2 Center => (this.topLeft + this.bottomRight) / 2;
/// <summary>
/// Determines if the specified point is contained within the rectangular region defined by

Просмотреть файл

@ -49,5 +49,23 @@ namespace SixLabors.Shapes.Tests
Assert.NotNull(p);
}
}
}
[Fact]
public void ClippingCornerShouldReturn1Points()
{
var poly = new Ellipse(50, 50, 30, 50);
var points = poly.FindIntersections(new Vector2(0, 75), new Vector2(100, 75)).ToArray();
Assert.Equal(1, points.Length);
}
[Fact]
public void AcrossEllipsShouldReturn2()
{
var poly = new Ellipse(50, 50, 30, 50);
var points = poly.FindIntersections(new Vector2(0, 49), new Vector2(100, 49)).ToArray();
Assert.Equal(2, points.Length);
}
}
}

Просмотреть файл

@ -218,7 +218,7 @@ namespace SixLabors.Shapes.Tests
var intersections = poly.FindIntersections(new Vector2(float.MinValue, 137), new Vector2(float.MaxValue, 137));
// returns an even number of points
Assert.Equal(2, intersections.Count());
Assert.Equal(4, intersections.Count());
}
@ -245,7 +245,7 @@ namespace SixLabors.Shapes.Tests
var intersections = simplePath.FindIntersections(new Vector2(float.MinValue, 20), new Vector2(float.MaxValue, 20));
// returns an even number of points
Assert.Equal(2, intersections.Count());
Assert.Equal(4, intersections.Count());
}
[Fact]
@ -280,7 +280,7 @@ namespace SixLabors.Shapes.Tests
var intersections = poly.FindIntersections(new Vector2(float.MinValue, 300), new Vector2(float.MaxValue, 300));
// returns an even number of points
Assert.Equal(0, intersections.Count());
Assert.Equal(1, intersections.Count());
}
[Fact]