@redbear Rotation parameters are not specified as in Left or right etc. I guess it would be something similar to AVL tree rotations which we do to balance a binary tree. Which are LL, LR , RL and RR rotations.

Every rectangle would have two intervals (y1,y2) on y axis and (x1, x2) on x axis. We need to sort all the y coordinates first based on this intervals and then x coordinates based on this interval.