From eeb9e719e33b26907cbfbf859d4c9e0c3224307c Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 7 Jun 2020 12:07:13 +1000 Subject: [PATCH] Fixed drawing a 1px high polygon --- Tests/images/imagedraw_polygon_1px_high.png | Bin 0 -> 73 bytes Tests/test_imagedraw.py | 14 ++++++++++++++ src/libImaging/Draw.c | 6 +++--- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 Tests/images/imagedraw_polygon_1px_high.png diff --git a/Tests/images/imagedraw_polygon_1px_high.png b/Tests/images/imagedraw_polygon_1px_high.png new file mode 100644 index 0000000000000000000000000000000000000000..e06508a0af0a8baa0adeed753157ad0b0536664e GIT binary patch literal 73 zcmeAS@N?(olHy`uVBq!ia0vp^%plCc1SD^IDZKzv0-i38Ar*6y6B-zg{pXQjU=WsP VWZd*(1qV=$!PC{xWt~$(69Dik5B>lE literal 0 HcmV?d00001 diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 7ecec48d3..74b0b8ff3 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -531,6 +531,20 @@ def test_polygon_kite(): assert_image_equal(im, Image.open(expected)) +def test_polygon_1px_high(): + # Test drawing a 1px high polygon + # Arrange + im = Image.new("RGB", (3, 3)) + draw = ImageDraw.Draw(im) + expected = "Tests/images/imagedraw_polygon_1px_high.png" + + # Act + draw.polygon([(0, 1), (0, 1), (2, 1), (2, 1)], "#f00") + + # Assert + assert_image_equal(im, Image.open(expected)) + + def helper_rectangle(bbox): # Arrange im = Image.new("RGB", (W, H)) diff --git a/src/libImaging/Draw.c b/src/libImaging/Draw.c index 10aaae1f2..947d7f70f 100644 --- a/src/libImaging/Draw.c +++ b/src/libImaging/Draw.c @@ -489,15 +489,15 @@ polygon_generic(Imaging im, int n, Edge *e, int ink, int eofill, } for (i = 0; i < n; i++) { - if (e[i].ymin == e[i].ymax) { - continue; - } if (ymin > e[i].ymin) { ymin = e[i].ymin; } if (ymax < e[i].ymax) { ymax = e[i].ymax; } + if (e[i].ymin == e[i].ymax) { + continue; + } edge_table[edge_count++] = (e + i); } if (ymin < 0) {