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 rect intersection #436

Merged
merged 2 commits into from Apr 2, 2020
Merged

Conversation

michaelkirk
Copy link
Member

Addendum to #420

This fixes the intersection test for Rect when self is contained
wholly within arg - it was already working for when arg was within
self as of #420

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
Copy link
Member Author

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
Copy link
Member Author

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.

Copy link
Member

@frewsxcv frewsxcv left a 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 🙇

@frewsxcv
Copy link
Member

frewsxcv commented Apr 2, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Apr 2, 2020

Build succeeded

@bors bors bot merged commit 7ce9530 into georust:master Apr 2, 2020
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.

None yet

2 participants