AspectHelper { public static RectangleF fitInside(RectangleF src, RectangleF dest) { return scaleAndCenterRect(src, dest, minScale(src, dest)); }  static boolean is_4_3(float ar); static boolean is_16_9(float ar); static boolean is_ar_equals(float ar1, float ar2); static float minScale(RectangleF src, RectangleF dest); static float maxScale(RectangleF src, RectangleF dest); static RectangleF fitInside(RectangleF src, RectangleF dest); static RectangleF fitOutside(RectangleF src, RectangleF dest); static RectangleF fitWidth(RectangleF src, RectangleF dest); static RectangleF fitHeight(RectangleF src, RectangleF dest); static RectangleF scaleAndCenterRect(RectangleF src, RectangleF dest, float scale); static RectangleF stretch(RectangleF src, float ar); static RectangleF zoom(RectangleF src, float ar); static final RectangleF RectF_4_3; static final RectangleF RectF_16_9; static final float ar_4_3; static final float ar_16_9; static final float ar_tolerance; }
@Test public void test4_3FitInside16_9() throws Exception { RectangleF r169 = new RectangleF(0,0,720 * AspectHelper.ar_16_9, 720); RectangleF r43 = AspectHelper.fitInside(AspectHelper.RectF_4_3, r169); System.out.println(r169); System.out.println(r43); Rectangle r = r43.asIntRect(); assertEquals(160, r.x); assertEquals(0, r.y); assertEquals(960, r.width); assertEquals(720, r.height); assertEquals(r.height, (int)r169.height); }
@Test public void test16_9FitInside4_3() throws Exception { RectangleF r43 = new RectangleF(0,0,480 * AspectHelper.ar_4_3, 480); RectangleF r169 = AspectHelper.fitInside(AspectHelper.RectF_16_9, r43); System.out.println(r43); System.out.println(r169); Rectangle r = r169.asIntRect(); assertEquals(0, r.x); assertEquals(60, r.y); assertEquals(640, r.width); assertEquals(360, r.height); assertEquals(r.width, (int)r169.width); }