if your bounds are reasonable use a 2D array of edge counts, otherwise you'd have to use nested dictionaries.
because all widths and heights are the same you can uniquely identify an edge by a combination of x, y, and orientation(vertical or horizontal)
sample pseudocode:
list_of_edges = new list
arr_count = new int[][][]
fill_with_zeroes(arr_count )
foreach rect
foreach edge
arr_count [edge.x][edge.y][edge.orientation] += 1
foreach edge in arr_count
if count[edge] = 1
list_of_edges.add(edge]
of course, if you want to order the edges, then you'd have to pass through the array another time
foreach edge in arr_count
if count[edge] = 1
add_recursive(edge)
add_recursive(x,y):
for both horizontal and vertical orientations of edge starting at x, y:
count[edge] = 0
if (edge.orientation is horizontal)
return add_recursive( x+1, y)
else
return add_recursive( x, y+1 )
sorry, this pseudocode is pretty sloppy, but you should get the general idea
answered 2009-03-14T02:11:55.597