Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ImageDrawRectangleRec #3721

Merged
merged 1 commit into from
Jan 11, 2024
Merged

Fix ImageDrawRectangleRec #3721

merged 1 commit into from
Jan 11, 2024

Conversation

Bigfoot71
Copy link
Contributor

There seems to be an error in ImageDrawRectangleRec where we should subtract the absolute values of rec.x and rec.y from rec.width and rec.height when they are negative.

Currently, we are subtracting the negative values, which is equivalent to addition. For example, in the current implementation:
GIF1

If we replace size -= position with size += position, considering that the position is negative, we correctly subtract the difference as desired. This results (the visual glitches are from my screen recorder):
GIF2

@Bigfoot71
Copy link
Contributor Author

Bigfoot71 commented Jan 11, 2024

And for the remaining visible pixel line in the second gif, this can be resolved by replacing the condition:

if (((rec.x + rec.width) < 0) || (rec.y + rec.height < 0)) return;

With:

if (((rec.x + rec.width) <= 0) || (rec.y + rec.height <= 0)) return;

I can also make the modification if you prefer.

This would be the simplest solution, but the best would surely be to rethink this sequence of conditions I think.

@raysan5
Copy link
Owner

raysan5 commented Jan 11, 2024

@Bigfoot71 Oh! Good catch! Thanks for the review!

About the second proposed change:

if (((rec.x + rec.width) <= 0) || (rec.y + rec.height <= 0)) return;

Did you verify the drawn rectangle is not one pixel wider or higher?

@raysan5 raysan5 merged commit 746f129 into raysan5:master Jan 11, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants