I have a rectangle, and a list of other rectangles. I want to get the rectangle from the list, that has the best width, height, and aspect ratio according to my rectangle.
Example
After I run my code, the best rectangle should be rectangle 3.
Note that the rectangle 1 is my rectangle but rotated.
What I tried (checking for closest width + height value )
Rectangle myRectangle = new Rectangle(......)
Rectangle[] rectangles = new Rectangle[] {
new Rectangle(.....), new Rectangle(....).......
};
int bestRectangle = 0;
float min = 999999;
for (int i = 0; i < rectangles.length; i++) {
float difference = myRectange.width + myRectangle.height - rectangles[i].width - rectangles[i].height;
if (Math.abs(difference) < min) {
min = (Math.abs(difference); bestRectangle = i;
}
}
The problem with this, is that the best rectangle from my image will be rectangle 1..
Has anyone got a better ideea?