diff --git a/src/ImageSharp.Drawing/Shapes/Rasterization/PolygonScanner.cs b/src/ImageSharp.Drawing/Shapes/Rasterization/PolygonScanner.cs index b8c49691..6e45e765 100644 --- a/src/ImageSharp.Drawing/Shapes/Rasterization/PolygonScanner.cs +++ b/src/ImageSharp.Drawing/Shapes/Rasterization/PolygonScanner.cs @@ -151,12 +151,12 @@ private void SkipEdgesBeforeMinY() if (y0 < y1) { - this.SubPixelY = y0; + this.SubPixelY = y1; i0++; } else { - this.SubPixelY = y1; + this.SubPixelY = y0; i1++; } } diff --git a/tests/ImageSharp.Drawing.Tests/Issues/Issue_28.cs b/tests/ImageSharp.Drawing.Tests/Issues/Issue_28_108.cs similarity index 74% rename from tests/ImageSharp.Drawing.Tests/Issues/Issue_28.cs rename to tests/ImageSharp.Drawing.Tests/Issues/Issue_28_108.cs index 72310b9b..882e086e 100644 --- a/tests/ImageSharp.Drawing.Tests/Issues/Issue_28.cs +++ b/tests/ImageSharp.Drawing.Tests/Issues/Issue_28_108.cs @@ -10,19 +10,23 @@ 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(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))); @@ -30,15 +34,19 @@ public void DrawingLineAtTopShouldDisplay() 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(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))); @@ -46,15 +54,19 @@ public void DrawingLineAtBottomShouldDisplay() 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(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))); @@ -62,20 +74,23 @@ public void DrawingLineAtLeftShouldDisplay() 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(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])); } } diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/Scan/PolygonScannerTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/Scan/PolygonScannerTests.cs index 5ee93455..adc23a70 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/Scan/PolygonScannerTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/Scan/PolygonScannerTests.cs @@ -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);