I have put myself in a conundrum here, where I have 50 rects in one array and 50 rects in another. I need to find the two rects that are the closest to each other.
So I use this code:
for(int i=0;i<49;i++)
{
for(int j=0;j<49;j++)
{
double distance = Math.sqrt(Math.pow(rectF1.get(i).centerX() - rectF2.get(j).centerX(), 2)
+ Math.pow(rectF1.get(i).centerY() - rectF2.get(j).centerY(), 2));
}
}
It works but I have to check through 2500 times! And if the rects move (they do) then it's possible I won't catch the closest rects at the right moment! X.X