Fixed drawing translucent 1px high polygons #6278
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #6275. It doesn't change the behaviour of the code from that issue, but it addresses a concern raised there.
Background
PR #4333 adjusted
polygon_generic
to only draw each pixel once, so that repeated translucent pixels do not combine to produce a different final opacity.PR #5835 limited this new approach to only run when there was translucency involved, for the sake of performance.
Issue #6275 has found a situation where #4333 changed not just the final opacity, but which pixels were drawn. Because #6275 doesn't involve translucency, #5835 changed it back, but the missing pixels are still missing when there is translucency involved.
This PR fixes that unexpected change.
The scanline algorithm detects where edges intersect with each row of an image, storing them in
xx
.It works its way along each row, keeping track with
x_pos
of the current position, so that pixels are not redrawn.Horizontal lines do not contribute to the intersections, so it draws them separately as it goes, both partway through the row and at the end.
However, if there are no intersections (if
j
is zero), then when it goes to draw those end lines, they are skipped, as it thinks they are still to come.So this PR instead sets
x_pos
to a special value if there are no intersections. If there are no intersections in this row, then the horizontal lines should just be drawn.