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
4 changes: 2 additions & 2 deletions src/ImageSharp.Drawing/Shapes/Rasterization/PolygonScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ private void SkipEdgesBeforeMinY()

if (y0 < y1)
{
this.SubPixelY = y0;
this.SubPixelY = y1;
Copy link
Member

@antonfirsov antonfirsov Jan 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

y0 is the smaller Y coord of a line, Y1 is the bigger one. What I'm trying to achive in the method is to feed all start & endpoints to EnterEdges and LeaveEdges.

I think I chose y0 so we can jump to the smaller coord to not miss anything, however if we already visited it y1 makes more sense.

i0++;
}
else
{
this.SubPixelY = y1;
this.SubPixelY = y0;
i1++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,87 @@

namespace SixLabors.ImageSharp.Drawing.Tests.Issues
{
public class Issue_28
public class Issue_28_108
{
private Rgba32 red = Color.Red.ToRgba32();

[Fact]
public void DrawingLineAtTopShouldDisplay()
[Theory]
[InlineData(1F)]
[InlineData(1.5F)]
[InlineData(2F)]
[InlineData(3F)]
public void DrawingLineAtTopShouldDisplay(float stroke)
{
using var image = new Image<Rgba32>(Configuration.Default, 100, 100, Color.Black);
image.Mutate(x => x
.SetGraphicsOptions(g => g.Antialias = false)
.DrawLines(
this.red,
1f,
stroke,
new PointF(0, 0),
new PointF(100, 0)));

IEnumerable<(int x, int y)> locations = Enumerable.Range(0, 100).Select(i => (x: i, y: 0));
Assert.All(locations, l => Assert.Equal(this.red, image[l.x, l.y]));
}

[Fact]
public void DrawingLineAtBottomShouldDisplay()
[Theory]
[InlineData(1F)]
[InlineData(1.5F)]
[InlineData(2F)]
[InlineData(3F)]
public void DrawingLineAtBottomShouldDisplay(float stroke)
{
using var image = new Image<Rgba32>(Configuration.Default, 100, 100, Color.Black);
image.Mutate(x => x
.SetGraphicsOptions(g => g.Antialias = false)
.DrawLines(
this.red,
1f,
stroke,
new PointF(0, 99),
new PointF(100, 99)));

IEnumerable<(int x, int y)> locations = Enumerable.Range(0, 100).Select(i => (x: i, y: 99));
Assert.All(locations, l => Assert.Equal(this.red, image[l.x, l.y]));
}

[Fact]
public void DrawingLineAtLeftShouldDisplay()
[Theory]
[InlineData(1F)]
[InlineData(1.5F)]
[InlineData(2F)]
[InlineData(3F)]
public void DrawingLineAtLeftShouldDisplay(float stroke)
{
using var image = new Image<Rgba32>(Configuration.Default, 100, 100, Color.Black);
image.Mutate(x => x
.SetGraphicsOptions(g => g.Antialias = false)
.DrawLines(
this.red,
1f,
stroke,
new PointF(0, 0),
new PointF(0, 99)));

IEnumerable<(int x, int y)> locations = Enumerable.Range(0, 100).Select(i => (x: 0, y: i));
Assert.All(locations, l => Assert.Equal(this.red, image[l.x, l.y]));
}

[Fact]
public void DrawingLineAtRightShouldDisplay()
[Theory]
[InlineData(1F)]
[InlineData(1.5F)]
[InlineData(2F)]
[InlineData(3F)]
public void DrawingLineAtRightShouldDisplay(float stroke)
{
using var image = new Image<Rgba32>(Configuration.Default, 100, 100, Color.Black);
image.Mutate(x => x
.SetGraphicsOptions(g => g.Antialias = false)
.DrawLines(
this.red,
1f,
stroke,
new PointF(99, 0),
new PointF(99, 99)));

IEnumerable<(int x, int y)> locations = Enumerable.Range(0, 100).Select(i => (x: 99, y: i));

Assert.All(locations, l => Assert.Equal(this.red, image[l.x, l.y]));
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/ImageSharp.Drawing.Tests/Shapes/Scan/PolygonScannerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,25 @@ public void NegativeOrientation01(IntersectionRule intersectionRule)
this.TestScan(poly, 0, 2, 2, expected, intersectionRule);
}

[Fact]
public void OutOfBounds()
{
IPath poly = PolygonFactory.CreatePolygon((1, -5), (5, -5), (5, -3), (10, -1), (10, 2), (12, 4), (1, 4));

FuzzyFloat[][] exected =
{
new FuzzyFloat[] { 1, 10 },
new FuzzyFloat[] { 1, 10 },
new FuzzyFloat[] { 1, 10 },
new FuzzyFloat[] { 1, 10 },
new FuzzyFloat[] { 1, 10 },
new FuzzyFloat[] { 1, 10.5 },
new FuzzyFloat[] { 1, 11 },
};

this.TestScan(poly, 0, 3, 2, exected);
}

private static (float y, FuzzyFloat[] x) Empty(float y) => (y, new FuzzyFloat[0]);

private static FuzzyFloat F(float x, float eps) => new FuzzyFloat(x, eps);
Expand Down