Skip to content

Commit

Permalink
Fixed connecting discontiguous corners
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Dec 23, 2024
1 parent 0e3f51d commit fb3d80e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Binary file modified Tests/images/imagedraw/discontiguous_corners_polygon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions Tests/test_imagedraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,9 @@ def test_continuous_horizontal_edges_polygon() -> None:
def test_discontiguous_corners_polygon() -> None:
img, draw = create_base_image_draw((84, 68))
draw.polygon(((1, 21), (34, 4), (71, 1), (38, 18)), BLACK)
draw.polygon(
((82, 29), (82, 26), (82, 24), (67, 22), (52, 29), (52, 15), (67, 22)), BLACK
)
draw.polygon(((71, 44), (38, 27), (1, 24)), BLACK)
draw.polygon(
((38, 66), (5, 49), (77, 49), (47, 66), (82, 63), (82, 47), (1, 47), (1, 63)),
Expand Down
9 changes: 4 additions & 5 deletions src/libImaging/Draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ polygon_generic(
// Needed to draw consistent polygons
xx[j] = xx[j - 1];
j++;
} else if (current->dx != 0 && roundf(xx[j - 1]) == xx[j - 1]) {
} else if (current->dx != 0 && j % 2 == 1 &&
roundf(xx[j - 1]) == xx[j - 1]) {
// Connect discontiguous corners
for (k = 0; k < i; k++) {
Edge *other_edge = edge_table[k];
Expand All @@ -510,10 +511,8 @@ polygon_generic(
continue;
}
// Check if the two edges join to make a corner
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) {
if (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;
Expand Down

0 comments on commit fb3d80e

Please sign in to comment.