Skip to content

Commit eeb9e71

Browse files
committed
Fixed drawing a 1px high polygon
1 parent 9df95e7 commit eeb9e71

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

73 Bytes
Loading

Tests/test_imagedraw.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,20 @@ def test_polygon_kite():
531531
assert_image_equal(im, Image.open(expected))
532532

533533

534+
def test_polygon_1px_high():
535+
# Test drawing a 1px high polygon
536+
# Arrange
537+
im = Image.new("RGB", (3, 3))
538+
draw = ImageDraw.Draw(im)
539+
expected = "Tests/images/imagedraw_polygon_1px_high.png"
540+
541+
# Act
542+
draw.polygon([(0, 1), (0, 1), (2, 1), (2, 1)], "#f00")
543+
544+
# Assert
545+
assert_image_equal(im, Image.open(expected))
546+
547+
534548
def helper_rectangle(bbox):
535549
# Arrange
536550
im = Image.new("RGB", (W, H))

src/libImaging/Draw.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,15 +489,15 @@ polygon_generic(Imaging im, int n, Edge *e, int ink, int eofill,
489489
}
490490

491491
for (i = 0; i < n; i++) {
492-
if (e[i].ymin == e[i].ymax) {
493-
continue;
494-
}
495492
if (ymin > e[i].ymin) {
496493
ymin = e[i].ymin;
497494
}
498495
if (ymax < e[i].ymax) {
499496
ymax = e[i].ymax;
500497
}
498+
if (e[i].ymin == e[i].ymax) {
499+
continue;
500+
}
501501
edge_table[edge_count++] = (e + i);
502502
}
503503
if (ymin < 0) {

0 commit comments

Comments
 (0)