intersects method
Checks if this rectangle intersects with another rectangle
Mathematical Operation: Separating axis theorem implementation: Two rectangles DON'T intersect if:
- One is completely to the left of the other OR
- One is completely above the other OR
- One is completely to the right of the other OR
- One is completely below the other
Implementation
bool intersects(Rectangle other) {
return !(other.x >= x + width || // Other is right of us
other.x + other.width <= x || // Other is left of us
other.y >= y + height || // Other is below us
other.y + other.height <= y); // Other is above us
}