Skip to content

Commit

Permalink
Restored check that it is the end of edges being connected
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jan 3, 2025
1 parent 48712f2 commit 61e94bd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Binary file added Tests/images/imagedraw_polygon3_RGB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions Tests/test_imagedraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,14 @@ def test_polygon2() -> 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))
Expand Down
6 changes: 4 additions & 2 deletions src/libImaging/Draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 61e94bd

Please sign in to comment.