Fix SDL gradient overlaps + SDL rendering of sector-wide gradients #2597
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.
This was discovered by FrostC.
Due to the conversion from floating point to integer values, there was a "build-up" of rounding errors when splitting gradients to single-colour rectangles for rendering, which caused that some of the rectangles would overlap by one pixel. This PR adds a check that ensures that the next step always starts at previous step + previous height/width (both of those are already integers), plus it always shortens the height/width by one when the rounding error exceeds one (checks the actual position of the rectangle calculated by adding the width/height of the previous one to its starting position against the position calculated directly using the floats), so the gradient isn't stretched. This is the point at which the overlap would previously occur.
This bug was introduced in #2549 . I didn't notice it because the overlap can only be seen when the overlapping rectangles change the rendering outcome, i.e. when using the Additive blend mode.
before:
now:
EDIT:
While testing this PR, I found another bug. This one would cause sector-wide gradients (VERTICAL_SECTOR and HORIZONTAL_SECTOR) to render incorrectly, so I also fixed that (see the video in the fourth comment).