I have a file with a list of non-overlapping rectangles covering the entire space (they are adjacent). I would like to plot efficiently the graph edges that connect each rectangle center point with the adjacents rectangle center points. Which is the best data structure to use to load the rectangle list? Which is the best algorithm to find all the adjacent rectangles in x and y directions?
Thank you.
More details: In the picture below a visual example with 12 axis-aligned rectangles. The red paths are the desired output.
The numbering is from the random order in the input file:
rect1 (19,0) (23,19)
rect2 (0,3) (4,16)
rect3 (8,17) (11,19)
rect4 (8,6) (19,17)
rect5 (0,0) (11,3)
rect6 (4,3) (15,6)
rect7 (4,6) (8,8)
rect8 (15,3) (19,6)
rect9 (11,0) (19,3)
rect10 (0,16) (4,19)
rect11 (4,8) (8,19)
rect12 (11,17) (19,19)
The desired output is the adjacent combinations of rectangles and their length:
(1,4) (1,12) (1,8) (1,9) (2,5) (2,10) (2,11) (2,7)
(2,6) (3,4) (3,12) (3,11) (4,6) (4,7) (4,8) (4,11)
(4,12) (5,6) (5,9) (6,7) (6,8) (6,9) (7,11) (8,9) (10,11)