def overlap(r1, r2):
    if r1.left > r2.right or r1.right < r2.left:
        return False
if r1.top < r2.bottom or r1.bottom > r2.top:
    return False
return True
Efficent way to find overlapping of N rectangles