Skip to content

Commit e67e392

Browse files
Fix #108
1 parent 4c554d1 commit e67e392

File tree

2 files changed

+32
-66
lines changed

2 files changed

+32
-66
lines changed

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

Lines changed: 3 additions & 3 deletions
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 && i0 < this.edges.Length)
143+
while (this.SubPixelY < this.minY)
144144
{
145145
this.EnterEdges();
146146
this.LeaveEdges();
@@ -151,12 +151,12 @@ private void SkipEdgesBeforeMinY()
151151

152152
if (y0 < y1)
153153
{
154-
this.SubPixelY = y0;
154+
this.SubPixelY = y1;
155155
i0++;
156156
}
157157
else
158158
{
159-
this.SubPixelY = y1;
159+
this.SubPixelY = y0;
160160
i1++;
161161
}
162162
}

tests/ImageSharp.Drawing.Tests/Issues/Issue_28.cs renamed to tests/ImageSharp.Drawing.Tests/Issues/Issue_28_108.cs

Lines changed: 29 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,121 +10,87 @@
1010

1111
namespace SixLabors.ImageSharp.Drawing.Tests.Issues
1212
{
13-
public class Issue_28
13+
public class Issue_28_108
1414
{
1515
private Rgba32 red = Color.Red.ToRgba32();
1616

17-
[Fact]
18-
public void DrawingLineAtTopShouldDisplay()
17+
[Theory]
18+
[InlineData(1F)]
19+
[InlineData(1.5F)]
20+
[InlineData(2F)]
21+
[InlineData(3F)]
22+
public void DrawingLineAtTopShouldDisplay(float stroke)
1923
{
2024
using var image = new Image<Rgba32>(Configuration.Default, 100, 100, Color.Black);
2125
image.Mutate(x => x
2226
.SetGraphicsOptions(g => g.Antialias = false)
2327
.DrawLines(
2428
this.red,
25-
1f,
29+
stroke,
2630
new PointF(0, 0),
2731
new PointF(100, 0)));
2832

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

33-
[Fact]
34-
public void DrawingLineAtBottomShouldDisplay()
37+
[Theory]
38+
[InlineData(1F)]
39+
[InlineData(1.5F)]
40+
[InlineData(2F)]
41+
[InlineData(3F)]
42+
public void DrawingLineAtBottomShouldDisplay(float stroke)
3543
{
3644
using var image = new Image<Rgba32>(Configuration.Default, 100, 100, Color.Black);
3745
image.Mutate(x => x
3846
.SetGraphicsOptions(g => g.Antialias = false)
3947
.DrawLines(
4048
this.red,
41-
1f,
49+
stroke,
4250
new PointF(0, 99),
4351
new PointF(100, 99)));
4452

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

49-
[Fact]
50-
public void DrawingLineAtLeftShouldDisplay()
57+
[Theory]
58+
[InlineData(1F)]
59+
[InlineData(1.5F)]
60+
[InlineData(2F)]
61+
[InlineData(3F)]
62+
public void DrawingLineAtLeftShouldDisplay(float stroke)
5163
{
5264
using var image = new Image<Rgba32>(Configuration.Default, 100, 100, Color.Black);
5365
image.Mutate(x => x
5466
.SetGraphicsOptions(g => g.Antialias = false)
5567
.DrawLines(
5668
this.red,
57-
1f,
69+
stroke,
5870
new PointF(0, 0),
5971
new PointF(0, 99)));
6072

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

65-
[Fact]
66-
public void DrawingLineAtRightShouldDisplay()
77+
[Theory]
78+
[InlineData(1F)]
79+
[InlineData(1.5F)]
80+
[InlineData(2F)]
81+
[InlineData(3F)]
82+
public void DrawingLineAtRightShouldDisplay(float stroke)
6783
{
6884
using var image = new Image<Rgba32>(Configuration.Default, 100, 100, Color.Black);
6985
image.Mutate(x => x
7086
.SetGraphicsOptions(g => g.Antialias = false)
7187
.DrawLines(
7288
this.red,
73-
1f,
89+
stroke,
7490
new PointF(99, 0),
7591
new PointF(99, 99)));
7692

7793
IEnumerable<(int x, int y)> locations = Enumerable.Range(0, 100).Select(i => (x: 99, y: i));
78-
79-
Assert.All(locations, l => Assert.Equal(this.red, image[l.x, l.y]));
80-
}
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)));
12894
Assert.All(locations, l => Assert.Equal(this.red, image[l.x, l.y]));
12995
}
13096
}

0 commit comments

Comments
 (0)