diff --git a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs index 8224b234d..f2e09d289 100644 --- a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs @@ -154,13 +154,11 @@ namespace ImageSharp.Drawing.Processors int nextX = startX + 1; endX = Math.Min(endX, scanline.Length); // reduce to end to the right edge - if (nextX >= 0) + nextX = Math.Max(nextX, 0); + for (int x = nextX; x < endX; x++) { - for (int x = nextX; x < endX; x++) - { - scanline[x] += subpixelFraction; - scanlineDirty = true; - } + scanline[x] += subpixelFraction; + scanlineDirty = true; } } } diff --git a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs index a3911ac3e..4ba4a3a83 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs @@ -13,6 +13,7 @@ namespace ImageSharp.Tests.Drawing using ImageSharp.PixelFormats; using Xunit; + using ImageSharp.Drawing.Pens; public class DrawPathTests : FileTestBase { @@ -98,5 +99,32 @@ namespace ImageSharp.Tests.Drawing } } + + [Fact] + public void PathExtendingOffEdgeOfImageShouldNotBeCropped() + { + + string path = this.CreateOutputDirectory("Drawing", "Path"); + using (var image = new Image(256, 256)) + { + image.Fill(Rgba32.Black); + var pen = Pens.Solid(Rgba32.White, 5f); + + for (int i = 0; i < 300; i += 20) + { + image.DrawLines(pen, new Vector2[] { new Vector2(100, 2), new Vector2(-10, i) }); + } + + using (FileStream output = File.OpenWrite($"{path}/ClippedLines.png")) + { + image + .Save(output); + } + using (PixelAccessor sourcePixels = image.Lock()) + { + Assert.Equal(Rgba32.White, sourcePixels[0, 90]); + } + } + } } } \ No newline at end of file