From 61e94bdf6fafcb1aa6bde36b905945046280753d Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 3 Jan 2025 12:30:18 +1100 Subject: [PATCH] Restored check that it is the end of edges being connected --- Tests/images/imagedraw_polygon3_RGB.png | Bin 0 -> 477 bytes Tests/test_imagedraw.py | 8 ++++++++ src/libImaging/Draw.c | 6 ++++-- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 Tests/images/imagedraw_polygon3_RGB.png diff --git a/Tests/images/imagedraw_polygon3_RGB.png b/Tests/images/imagedraw_polygon3_RGB.png new file mode 100644 index 0000000000000000000000000000000000000000..97bf57dc1ba6f550cef841b89120d5ccd33db061 GIT binary patch literal 477 zcmV<30V4j1P)J89h=_>x^mYI8_3-_lc4dC@eK+6x z9r;7lI}7XIvAS;}*7fUgR1>k1dai#E*7Hum3R&uLSl5f^6B>t=Q55IGPYqoIc?XqwRN&u>cMLN z|KPKjEJqDkOUKIUvGz(CYv`&JYxP)JCDwK+V+~yuVF`?t)nI8z8Efb&9ZP1cEE`Kn z%2-2JiCAJ|WqDY7QpOs(O2LvGE6c!Al`_`QRWO$DSXnHVwv@4kuEMb7$I7CxPLMLz z&{Y7|A!B9FvCfe)*3cDLj=*vRmLsqnf#nD+M_@Su%Mn None: assert_image_similar_tofile(im, expected, 1) +def test_polygon3() -> None: + im = Image.new("RGB", (W, H)) + draw = ImageDraw.Draw(im) + draw.polygon([(10, 10), (10, 90), (90, 90), (90, 10), (80, 10), (60, 50), (50, 10), (40, 50), (20, 80), (20, 10)], "red") + expected = "Tests/images/imagedraw_polygon3_RGB.png" + assert_image_equal_tofile(im, expected) + + @pytest.mark.parametrize("xy", ((1, 1, 0, 1), (1, 1, 1, 0))) def test_incorrectly_ordered_coordinates(xy: tuple[int, int, int, int]) -> None: im = Image.new("RGB", (W, H)) diff --git a/src/libImaging/Draw.c b/src/libImaging/Draw.c index ea6f8805efb..829de735489 100644 --- a/src/libImaging/Draw.c +++ b/src/libImaging/Draw.c @@ -511,8 +511,10 @@ polygon_generic( 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;