From 62c7ee0f00c715e51e73b338a40d4a438f6bc5ca Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 16 May 2022 22:31:49 +1000 Subject: [PATCH 1/2] Only try to connect discontiguous corners at the end of edges --- Tests/test_imagedraw.py | 6 ++++++ src/libImaging/Draw.c | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 6755d94b895..5db4fbf6134 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -1452,3 +1452,9 @@ def test_discontiguous_corners_polygon(): ) expected = os.path.join(IMAGES_PATH, "discontiguous_corners_polygon.png") assert_image_similar_tofile(img, expected, 1) + + im = Image.new("RGB", (W, H)) + draw = ImageDraw.Draw(im) + draw.polygon([(18, 30), (19, 31), (18, 30), (85, 30), (60, 72)], "red") + expected = "Tests/images/imagedraw_outline_polygon_RGB.png" + assert_image_similar_tofile(im, expected, 1) diff --git a/src/libImaging/Draw.c b/src/libImaging/Draw.c index 86cd6c3a058..2fcd380480a 100644 --- a/src/libImaging/Draw.c +++ b/src/libImaging/Draw.c @@ -513,7 +513,9 @@ polygon_generic(Imaging im, int n, Edge *e, int ink, int eofill, hline_handler h continue; } // Check if the two edges join to make a corner - if (xx[j-1] == (ymin - other_edge->y0) * other_edge->dx + other_edge->x0) { + if (((ymin == current->ymin && ymin == other_edge->ymin) || + (ymin == current->ymax && ymin == other_edge->ymax)) && + xx[j-1] == (ymin - other_edge->y0) * other_edge->dx + other_edge->x0) { // Determine points from the edges on the next row // Or if this is the last row, check the previous row int offset = ymin == ymax ? -1 : 1; From cb4b5f212d5a81cc8300d5438287b5a7b9d9661d Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 28 May 2022 15:25:19 +1000 Subject: [PATCH 2/2] Separated test --- Tests/test_imagedraw.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 5db4fbf6134..59af64bbac7 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -1453,6 +1453,8 @@ def test_discontiguous_corners_polygon(): expected = os.path.join(IMAGES_PATH, "discontiguous_corners_polygon.png") assert_image_similar_tofile(img, expected, 1) + +def test_polygon(): im = Image.new("RGB", (W, H)) draw = ImageDraw.Draw(im) draw.polygon([(18, 30), (19, 31), (18, 30), (85, 30), (60, 72)], "red")