private static Size clampSize(Size original,double maxArea,Size maxSize){
  if (original.getWidth() * original.getHeight() < maxArea && original.getWidth() < maxSize.getWidth() && original.getHeight() < maxSize.getHeight()) {
    return original;
  }
  double ratio=Math.min(Math.sqrt(maxArea / original.area()),1.0f);
  int width=(int)Math.round(original.width() * ratio);
  int height=(int)Math.round(original.height() * ratio);
  if (width > maxSize.width() || height > maxSize.height()) {
    return computeFitWithinSize(original,maxSize);
  }
  return new Size(width,height);
}

private static Size clampSize ( Size original , double maxArea , Size maxSize ) { if ( original . getWidth ( ) * original . getHeight ( ) < maxArea && original . getWidth ( ) < maxSize . getWidth ( ) && original . getHeight ( ) < maxSize . getHeight ( ) ) { return original ; } double ratio = Math . min ( Math . sqrt ( maxArea / original . area ( ) ) , 1.0f ) ; int width = ( int ) Math . round ( original . width ( ) * ratio ) ; int height = ( int ) Math . round ( original . height ( ) * ratio ) ; if ( width > maxSize . width ( ) || height > maxSize . height ( ) ) { return computeFitWithinSize ( original , maxSize ) ; } return new Size ( width , height ) ; }
given a size , compute a value such that it will downscale the original size to fit within the maxsize bounding box and to be less than the provided area . this will never upscale sizes .
