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

Rect2::has_point() breaks with negative size fixed #38310

Closed

Conversation

ThakeeNathees
Copy link
Contributor

@ThakeeNathees ThakeeNathees commented Apr 28, 2020

Fix: #37617

Bugsquad edit: Mutually exclusive with at least a part of #37626

Point2 _position;
Size2 _size;

_position.x = MIN(position.x, position.x + size.x);
Copy link
Member

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.

Copy link
Contributor Author

@ThakeeNathees ThakeeNathees Apr 28, 2020

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 )

Copy link
Member

@groud groud left a 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.

@akien-mga
Copy link
Member

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 ?

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.

@aaronfranke
Copy link
Member

aaronfranke commented Aug 28, 2020

I think it would be better to require the user to write .abs().has_point() if there is a negative size. Doing this automatically can be bad for performance, and it does things behind the user's back (I know @reduz hates doing things behind the user's back).

Therefore, this should either be a debug warning (as I propose in #37626), or stated in the documentation (or both).

@groud
Copy link
Member

groud commented Aug 31, 2020

Doing this automatically can be bad for performance, and it does things behind the user's back (I know @reduz hates doing things behind the user's back).

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.

@reduz
Copy link
Member

reduz commented Aug 30, 2021

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.

@mhilbrunner
Copy link
Member

mhilbrunner commented Dec 2, 2021

Closing, we discussed in a PR meeting and decided to go ahead with #37626 instead.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rect2D .has_point() breaks with negative size values
7 participants