If you already use sorting by axes, then presumably you have calculated a list of your rectangles sorted by their positions.
Perhaps I misunderstand, but could you just look at the two rectangles before and after the rectangle in question and decide which one is closer? If you're talking about finding the closest rectangle to an arbitrary point, you can just go through the list until you find the first rectangle with a larger position than your arbitrary point, and use this rectangle and the one in front of it as two for comparison.
source share