Skip to content

Commit cf09e8e

Browse files
authored
Merge pull request #8620 from radarhere/polygon
2 parents 86d396a + fb3d80e commit cf09e8e

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed
Loading

Tests/test_imagedraw.py

+3
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,9 @@ def test_continuous_horizontal_edges_polygon() -> None:
16741674
def test_discontiguous_corners_polygon() -> None:
16751675
img, draw = create_base_image_draw((84, 68))
16761676
draw.polygon(((1, 21), (34, 4), (71, 1), (38, 18)), BLACK)
1677+
draw.polygon(
1678+
((82, 29), (82, 26), (82, 24), (67, 22), (52, 29), (52, 15), (67, 22)), BLACK
1679+
)
16771680
draw.polygon(((71, 44), (38, 27), (1, 24)), BLACK)
16781681
draw.polygon(
16791682
((38, 66), (5, 49), (77, 49), (47, 66), (82, 63), (82, 47), (1, 47), (1, 63)),

src/libImaging/Draw.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,8 @@ polygon_generic(
501501
// Needed to draw consistent polygons
502502
xx[j] = xx[j - 1];
503503
j++;
504-
} else if (current->dx != 0 && roundf(xx[j - 1]) == xx[j - 1]) {
504+
} else if (current->dx != 0 && j % 2 == 1 &&
505+
roundf(xx[j - 1]) == xx[j - 1]) {
505506
// Connect discontiguous corners
506507
for (k = 0; k < i; k++) {
507508
Edge *other_edge = edge_table[k];
@@ -510,10 +511,8 @@ polygon_generic(
510511
continue;
511512
}
512513
// Check if the two edges join to make a corner
513-
if (((ymin == current->ymin && ymin == other_edge->ymin) ||
514-
(ymin == current->ymax && ymin == other_edge->ymax)) &&
515-
xx[j - 1] == (ymin - other_edge->y0) * other_edge->dx +
516-
other_edge->x0) {
514+
if (xx[j - 1] ==
515+
(ymin - other_edge->y0) * other_edge->dx + other_edge->x0) {
517516
// Determine points from the edges on the next row
518517
// Or if this is the last row, check the previous row
519518
int offset = ymin == ymax ? -1 : 1;

0 commit comments

Comments
 (0)