optimize rectangles