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 rect intersection #436
Conversation
This fixes the intersection test for Rect when `self` is contained wholly within `arg` - it was already working for when `arg` was within `self`. Also simplifies math - rather than doing min+width, we can just use max.
let x_overlap = value_in_range( | ||
self.min().x, | ||
bounding_rect.min().x, | ||
bounding_rect.max().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.
Simplified this math a bit.
width is computed as self.max().x - self.min().x
So this:
self.min().x + self.width()
previously expanded as:
self.min().x + self.max().x - self.min().x
Which is more simply self.max().x
@@ -211,32 +211,27 @@ where | |||
T: Float, | |||
{ | |||
fn intersects(&self, bounding_rect: &Rect<T>) -> bool { | |||
// line intersects inner or outer polygon edge | |||
if bounding_rect.contains(self) { | |||
false |
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.
This contains
check is backwards. If a
contains b
then we should always consider the rects to intersect.
We could fix it by changing this to return true, but it's wholly redundant with the subsequent check for overlap, so I removed it altogether.
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.
wow great catch, thanks so much for fixing this 🙇
bors r+ |
Build succeeded |
Addendum to #420
This fixes the intersection test for Rect when
self
is containedwholly within
arg
- it was already working for whenarg
was withinself
as of #420