-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Rect2::has_point() breaks with negative size fixed #38310
Rect2::has_point() breaks with negative size fixed #38310
Conversation
core/math/rect2.h
Outdated
Point2 _position; | ||
Size2 _size; | ||
|
||
_position.x = MIN(position.x, position.x + size.x); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this code could simply be replaced by a call to Rect2.abs()
on a copy of the rect. And then the remaining code could be left intact if ran on the copy instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@groud I've simplified the code with abs()
and not modifying the negative size ( unless there is no way to tell if the rect is flipped )
8d00871
to
a21df38
Compare
a21df38
to
46c0fc0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only question left on this PR is likely the cost of creating a "duplicate" abs() rect every time. Maybe we should add a check on the size signs first to allow the creation of a new object only when required ?
Anyway, this kind of fix is, for me, preferred over #37626. The documentation might be updated though, to explain what a negative size means on such Rect2.
I guess we could cache the abs rect as an alternative representation of the negative sized rect, and use it in the methods that wouldn't work with negative size. But that depends on what the final consensus on #37626 would be indeed. |
I think it would be better to require the user to write Therefore, this should either be a debug warning (as I propose in #37626), or stated in the documentation (or both). |
I disagree on that, it's not doing something in the user back. For me, a Rect2d with a negative size is a perfectly valid use case for which all API functions should work correctly. Whether or not we use abs() internally to implement the function or not is not important, as it does not change anything to the end user. |
This is an interesting discussion. I am more in favor of thinking that if you use negative size values, has_point should always return false, so I think the current behavior is the expected one. |
Closing, we discussed in a PR meeting and decided to go ahead with #37626 instead. |
Fix: #37617
Bugsquad edit: Mutually exclusive with at least a part of #37626