LayoutManager { public static Dimension scaleToFit(Dimension canvas, Dimension d) { final double scaleToWidth = d(canvas.getWidth()) / d(d.getWidth()); if (d.getHeight() * scaleToWidth > canvas.getHeight()) { final double scaleToHeight = d(canvas.getHeight()) / d(d.getHeight()); return scale(canvas, d, scaleToHeight); } else { return scale(canvas, d, scaleToWidth); } } private  LayoutManager(); static TwoShapeLayout twoShapeLayout(Dimension canvas,
                                              Dimension upper,
                                              Dimension lower,
                                              TwoShapeLayouts.TwoShapeLayoutSpec spec); static MultiShapeLayout multiShapeLayout(final Dimension canvas,
                                                  final List<Tuple<Dimension, HorizontalCoverageLayoutSpec>> shapes); static MultiShapeLayout absoluteMultiShapeLayout(
          final Dimension canvas,
          final List<Tuple<Dimension, AbsolutePositionLayoutSpec>> shapes); static int limitMax(double v, int max); static int limitMin(double v, int min); static boolean fits(Dimension into, Dimension shape); static int area(Dimension a); static Dimension max(Dimension a, Dimension b); static double aspectRatio(Dimension a); static boolean overlap(Layout a, Layout b); static int left(Layout a); static int right(Layout a); static int top(Layout a); static int bottom(Layout a); static Offset offset(Anchor a, Dimension dim); static Dimension scale(Dimension limit, Dimension shape, double scale); static Dimension scaleToFit(Dimension canvas, Dimension d); static boolean between(int a, int b, int x);  }
@Test public void testScaleToFit() { assertEquals(dimension(100, 100), scaleToFit(dimension(100, 100), dimension(10, 10))); assertEquals(dimension(50, 100), scaleToFit(dimension(100, 100), dimension(10, 20))); assertEquals(dimension(100, 50), scaleToFit(dimension(100, 100), dimension(20, 10))); assertEquals(dimension(100, 1), scaleToFit(dimension(100, 500), dimension(1000, 10))); }