base function implemented for perfect set of rectangles