Can this rectangle to rectangle intersection code still work?

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:37 UTC
Read the original article Hit count: 268

I was looking for a fast performing code 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++.

Can this thing still work? Can you make it work?

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

Related posts about graphics

Related posts about rectangle