I need to find the minimum size that has an aspect ratio of exactly (or within 0.001) some value. Are there any quick math tricks or framework tricks for doing this?
Here's the pseudo code for the current bad idea I had running in O(n^2)
:
epsilon = 0.001;
from x = 1 to MAX_X
{
from y = 1 to MAX_Y
{
if(Abs(x / y - aspectRatio) <= epsilon)
{
return new Size(x, y);
}
}
}
return Size.Empty;