Logic for adjoining rectangles