Skip to content

Commit 71d6a7b

Browse files
authored
Merge pull request #6303 from radarhere/disconnected
Only try to connect discontiguous corners at the end of edges
2 parents 9c25fc6 + cb4b5f2 commit 71d6a7b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Tests/test_imagedraw.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,3 +1452,11 @@ def test_discontiguous_corners_polygon():
14521452
)
14531453
expected = os.path.join(IMAGES_PATH, "discontiguous_corners_polygon.png")
14541454
assert_image_similar_tofile(img, expected, 1)
1455+
1456+
1457+
def test_polygon():
1458+
im = Image.new("RGB", (W, H))
1459+
draw = ImageDraw.Draw(im)
1460+
draw.polygon([(18, 30), (19, 31), (18, 30), (85, 30), (60, 72)], "red")
1461+
expected = "Tests/images/imagedraw_outline_polygon_RGB.png"
1462+
assert_image_similar_tofile(im, expected, 1)

src/libImaging/Draw.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,9 @@ polygon_generic(Imaging im, int n, Edge *e, int ink, int eofill, hline_handler h
513513
continue;
514514
}
515515
// Check if the two edges join to make a corner
516-
if (xx[j-1] == (ymin - other_edge->y0) * other_edge->dx + other_edge->x0) {
516+
if (((ymin == current->ymin && ymin == other_edge->ymin) ||
517+
(ymin == current->ymax && ymin == other_edge->ymax)) &&
518+
xx[j-1] == (ymin - other_edge->y0) * other_edge->dx + other_edge->x0) {
517519
// Determine points from the edges on the next row
518520
// Or if this is the last row, check the previous row
519521
int offset = ymin == ymax ? -1 : 1;

0 commit comments

Comments
 (0)