Fast rectangle to rectangle intersection
Posted
by Jeremy Rudd
on Stack Overflow
See other posts from Stack Overflow
or by Jeremy Rudd
Published on 2010-05-02T03:32:47Z
Indexed on
2010/05/02
3:47 UTC
Read the original article
Hit count: 331
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
);
}
© Stack Overflow or respective owner