MapUtils { public static int[] getWidthHeight( Integer maxWidth, Integer maxHeight, int subtractWidth, int subtractHeight, double widthFactor ) { if ( maxWidth == null && maxHeight == null ) { throw new IllegalArgumentException( "At least one of width and height must be specified" ); } if ( maxWidth == null ) { maxHeight -= subtractHeight; maxWidth = (int) Math.ceil( maxHeight * widthFactor ); } else if ( maxHeight == null ) { maxWidth -= subtractWidth; maxHeight = (int) Math.ceil( maxWidth / widthFactor ); } else { maxWidth -= subtractWidth; maxHeight -= subtractHeight; double maxWidthFactor = (double) maxWidth / maxHeight; if ( maxWidthFactor > widthFactor ) { maxWidth = (int) Math.ceil( maxHeight * widthFactor ); } else { maxHeight = (int) Math.ceil( maxWidth / widthFactor ); } } int[] result = { maxWidth, maxHeight }; return result; }  static int lerp( int a, int b, double t ); static double lerp( double a, double b, double t ); static Color lerp( Color a, Color b, double t ); static Color createColorFromString( String string ); static int getNonEmptyNodes( JsonNode json ); static boolean nodeIsNonEmpty( JsonNode json ); static BufferedImage render( InternalMap map, Integer maxWidth, Integer maxHeight ); static BufferedImage renderTitle( String title, Integer width ); static int[] getWidthHeight( Integer maxWidth, Integer maxHeight, int subtractWidth, int subtractHeight, double widthFactor ); static Layer createFeatureLayerFromMapObject( InternalMapObject mapObject ); static BufferedImage createErrorImage( String error ); static final int DEFAULT_MAP_WIDTH; static final int TITLE_HEIGHT; }
@Test public void testGetWidthHeight() { assertEquals( 150, getWidthHeight( 200, 300, 0, 0, 0.5 )[0] ); assertEquals( 300, getWidthHeight( 200, 300, 0, 0, 0.5 )[1] ); assertEquals( 200, getWidthHeight( 200, 300, 0, 0, 2 )[0] ); assertEquals( 100, getWidthHeight( 200, 300, 0, 0, 2 )[1] ); assertEquals( 300, getWidthHeight( 600, 300, 0, 0, 1d )[0] ); assertEquals( 300, getWidthHeight( 600, 300, 0, 0, 1d )[1] ); assertEquals( 200, getWidthHeight( 200, null, 0, 0, 0.5 )[0] ); assertEquals( 400, getWidthHeight( 200, null, 0, 0, 0.5 )[1] ); assertEquals( 200, getWidthHeight( 200, null, 0, 0, 2 )[0] ); assertEquals( 100, getWidthHeight( 200, null, 0, 0, 2 )[1] ); assertEquals( 150, getWidthHeight( null, 300, 0, 0, 0.5 )[0] ); assertEquals( 300, getWidthHeight( null, 300, 0, 0, 0.5 )[1] ); assertEquals( 600, getWidthHeight( null, 300, 0, 0, 2 )[0] ); assertEquals( 300, getWidthHeight( null, 300, 0, 0, 2 )[1] ); }
@Test( expected = IllegalArgumentException.class ) public void testGetWidthHeightIllegalArgument() { getWidthHeight( null, null, 0, 0, 0.5 ); }