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

rectangle overlap when no corners within bug fix #99

Merged
merged 1 commit into from
Oct 9, 2023

Conversation

AnushaTiwari5
Copy link
Collaborator

Fixed and tested, I believe this should detect collision even when the corners of the bounding boxes are not within the other.

@AnushaTiwari5 AnushaTiwari5 added the Bug Something isn't working. Rightmost number in semantic versioning label Oct 9, 2023
@AnushaTiwari5 AnushaTiwari5 added this to the Sprint 10/9 milestone Oct 9, 2023
@AnushaTiwari5 AnushaTiwari5 self-assigned this Oct 9, 2023
@AnushaTiwari5 AnushaTiwari5 linked an issue Oct 9, 2023 that may be closed by this pull request
Comment on lines +105 to +141
/**
* Checks if any of the horizontal edges of the other rectangle lie within the horizontal
* boundaries of this rectangle
* @param otherRect The other rectangle
* @returns True, if the other edges lie within this boundary. Else, false
*/
private checkHorizontalEdgeOverlap(otherRect: Rectangle): boolean {
const thisCorners = this.getCorners();
const otherCorners = otherRect.getCorners();

if (thisCorners[0].y <= otherCorners[0].y && thisCorners[2].y >= otherCorners[0].y) {
return true;
} else if (thisCorners[0].y <= otherCorners[2].y && thisCorners[2].y >= otherCorners[2].y) {
return true;
}

return false;
}

/**
* Checks if any of the vertical edges of the other rectangle lie within the vertical
* boundaries of this rectangle
* @param otherRect The other rectangle
* @returns True, if the other edges lie within this boundary. Else, false
*/
private checkVerticalEdgeOverlap(otherRect: Rectangle): boolean {
const thisCorners = this.getCorners();
const otherCorners = otherRect.getCorners();

if (thisCorners[0].x <= otherCorners[0].x && thisCorners[1].x >= otherCorners[0].x) {
return true;
} else if (thisCorners[0].x <= otherCorners[1].x && thisCorners[1].x >= otherCorners[1].x) {
return true;
}

return false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is repetitive, we can abstract this into a single function.

@James-Oswald James-Oswald merged commit 593bc9a into master Oct 9, 2023
@James-Oswald James-Oswald deleted the 98-ellipse-collision-not-detecting branch October 9, 2023 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working. Rightmost number in semantic versioning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ellipse collision not detecting
2 participants