Fast rectangle to rectangle intersection
- by Jeremy Rudd
What's a fast way to test if 2 rectangles are intersecting?
A search on the internet came up with this one-liner (WOOT!), but I don't understand how to write it in Javascript, it seems to be written in an ancient form of C++.
struct
{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT;
bool IntersectRect(const RECT * r1, const RECT * r2)
{
return ! ( r2->left > r1->right
|| r2->right left
|| r2->top > r1->bottom
|| r2->bottom top
);
}