If all measurements are not null, I would use the following code (which essentially matches your code).
scaleFactor = (outerWidth / outerHeight > innerWidth / innerHeight) ? outerHeight / innerHeight : outerWidth / innerWidth
This can also be changed so that, if necessary, any measurement is zero.
Daniel BrΓΌckner Sep 03 '09 at 12:41 2009-09-03 12:41
source share