Improved connecting discontiguous corners by radarhere · Pull Request #8659 · python-pillow/Pillow
Resolves #8616
#8620 was flawed, primarily because I didn't notice when updating the test image that the corners were no longer connected. Searching back through Pillow versions though, I don't actually think this ever worked as intended, and this was obscured by assert_image_similar_tofile(img, expected, 1).
So this PR serves as a rethinking of #5980, and changes to assert_image_equal_tofile(img, expected) to ensure that the result is actually correct.
Here is how discontiguous corners are now connected to the rest of the polygon.
- Check that the horizontal row being processed is the start or end of the edge in question, and that it's not a horizontal edge.
- Find another edge matching the same conditions. You will see I have abandoned considering whether the slope of the line is positive or negative.
- Check that the rounded co-ordinates of the end of the two edges match.
- Consider the pixels from either the next row (or if it is the last row of the current edge, the previous row)
- Check that the second edge actually continues into that other row, and didn't end first
- If the position of both edges in that other row are greater (or are both less) than the position in this row, then extend the pixels in this row to meet it.