Having a set of adjacent rectangles, what would be the algorithm that gets the rectilinear polygon wrapping around them?
- Form a list of the $4n$ edges making up the $n$ rectangles.
- Delete every edge that appears twice.
The edges that remain describe the outside of the polygon. If you want to list these edges in clockwise or anticlockwise order, that's easy enough to do -- just pick an arbitrary starting vertex and find one of the two edges it is incident on, then find the other edge that the other vertex of that edge is incident on, repeating this until you hit the original vertex again. If you encounter two edges in the same direction, you might want to turn them into a single, longer edge as you go.