Suppose I have a set of (X,Y) coordinates of 1000 boxes.
( x1, y1) ( x2, y2) Area
(0.0000,0.0000) (0.3412,0.4175)
In the scenario you describe boxes share corners, so if you computed all of the box corners then you could see which ones were touching
// O(n)
foreach box b {
// compute b's other 2 corners and save them
}
// 16 * O(n^2) = O(n^2)
foreach box b {
foreach box other {
// match if any of b's corners match any of others points
}
}
There is probably a much more efficient/elegant solution, this one is somewhat naive.