TriangleVerticesCalculator { public float[] getScale_PreserveAspectFit(int angle, int widthIn, int heightIn, int widthOut, int heightOut) { scale[0] = scale[1] = 1; if (angle == 90 || angle == 270) { int cx = widthIn; widthIn = heightIn; heightIn = cx; } float aspectRatioIn = (float) widthIn / (float) heightIn; float heightOutCalculated = (float) widthOut / aspectRatioIn; if (heightOutCalculated < heightOut) { scale[1] = heightOutCalculated / heightOut; } else { scale[0] = heightOut * aspectRatioIn / widthOut; } return scale; } TriangleVerticesCalculator();  TriangleVerticesCalculator(float[] triangleVerticesData); float[] getScale_PreserveAspectFit(int angle, int widthIn, int heightIn, int widthOut, int heightOut); float[] getScale_PreserveAspectCrop(int angle, int widthIn, int heightIn, int widthOut, int heightOut); float[] getAspectRatioVerticesData(int widthIn, int heightIn, int widthOut, int heightOut); static float[] getDefaultTriangleVerticesData();  }
@Test public void testScaleHorizontally() { int inWidth = 10; int inheight = 5; int outWidth = 20; int outheight = 5; TriangleVerticesCalculator calculator = new TriangleVerticesCalculator(); float scale [] = calculator.getScale_PreserveAspectFit(0, inWidth, inheight, outWidth, outheight); assertAlmostEqual(scale, new float[] {0.5f, 1f}, 1e-7); }
@Test public void testScaleVertically() { int inWidth = 10; int inheight = 5; int outWidth = 5; int outheight = 20; TriangleVerticesCalculator calculator = new TriangleVerticesCalculator(); float scale [] = calculator.getScale_PreserveAspectFit(0, inWidth, inheight, outWidth, outheight); assertAlmostEqual(scale, new float[] {1f, 0.125f}, 1e-7); }
@Test public void testScaleHorizontallyThenVertically() { int inWidth = 10; int inheight = 5; int outWidth = 20; int outheight = 5; TriangleVerticesCalculator calculator = new TriangleVerticesCalculator(); float scale [] = calculator.getScale_PreserveAspectFit(0, inWidth, inheight, outWidth, outheight); assertAlmostEqual(scale, new float[] {0.5f, 1f}, 1e-7); inWidth = 10; inheight = 5; outWidth = 5; outheight = 20; scale = calculator.getScale_PreserveAspectFit(0, inWidth, inheight, outWidth, outheight); assertAlmostEqual(scale, new float[] {1f, 0.125f}, 1e-7); }
@Test public void testScaleVerticallyRotate270() { int inWidth = 10; int inheight = 5; int outWidth = 5; int outheight = 20; TriangleVerticesCalculator calculator = new TriangleVerticesCalculator(); float scale [] = calculator.getScale_PreserveAspectFit(270, inWidth, inheight, outWidth, outheight); assertAlmostEqual(scale, new float[] {1f, 0.5f}, 1e-7); }