Skip to content

Commit 4c554d1

Browse files
Add tests and dodgy fix
1 parent e09fe9b commit 4c554d1

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/ImageSharp.Drawing/Shapes/Rasterization/PolygonScanner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private void SkipEdgesBeforeMinY()
140140
int i1 = 0;
141141

142142
// Do fake scans for the lines belonging to edge start and endpoints before minY
143-
while (this.SubPixelY < this.minY)
143+
while (this.SubPixelY < this.minY && i0 < this.edges.Length)
144144
{
145145
this.EnterEdges();
146146
this.LeaveEdges();

tests/ImageSharp.Drawing.Tests/Issues/Issue_28.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,54 @@ public void DrawingLineAtRightShouldDisplay()
7878

7979
Assert.All(locations, l => Assert.Equal(this.red, image[l.x, l.y]));
8080
}
81+
82+
[Fact]
83+
public void DrawingLineAtTopWith1point5pxStrokeShouldDisplay()
84+
{
85+
using var image = new Image<Rgba32>(Configuration.Default, 100, 100, Color.Black);
86+
image.Mutate(x => x
87+
.SetGraphicsOptions(g => g.Antialias = false)
88+
.DrawLines(
89+
this.red,
90+
1.5f,
91+
new PointF(0, 0),
92+
new PointF(100, 0)));
93+
94+
IEnumerable<(int x, int y)> locations = Enumerable.Range(0, 100).Select(i => (x: i, y: 0));
95+
Assert.All(locations, l => Assert.Equal(this.red, image[l.x, l.y]));
96+
}
97+
98+
[Fact]
99+
public void DrawingLineAtTopWith2pxStrokeShouldDisplay()
100+
{
101+
using var image = new Image<Rgba32>(Configuration.Default, 100, 100, Color.Black);
102+
image.Mutate(x => x
103+
.SetGraphicsOptions(g => g.Antialias = false)
104+
.DrawLines(
105+
this.red,
106+
2f,
107+
new PointF(0, 0),
108+
new PointF(100, 0)));
109+
110+
IEnumerable<(int x, int y)> locations = Enumerable.Range(0, 100).Select(i => (x: i, y: 0));
111+
Assert.All(locations, l => Assert.Equal(this.red, image[l.x, l.y]));
112+
}
113+
114+
[Fact]
115+
public void DrawingLineAtTopWith3pxStrokeShouldDisplay()
116+
{
117+
using var image = new Image<Rgba32>(Configuration.Default, 100, 100, Color.Black);
118+
image.Mutate(x => x
119+
.SetGraphicsOptions(g => g.Antialias = false)
120+
.DrawLines(
121+
this.red,
122+
3f,
123+
new PointF(0, 0),
124+
new PointF(100, 0)));
125+
126+
IEnumerable<(int x, int y)> locations = Enumerable.Range(0, 100).Select(i => (x: i, y: 0))
127+
.Concat(Enumerable.Range(0, 100).Select(i => (x: i, y: 1)));
128+
Assert.All(locations, l => Assert.Equal(this.red, image[l.x, l.y]));
129+
}
81130
}
82131
}

0 commit comments

Comments
 (0)