TriangleVerticesCalculator { public float[] getAspectRatioVerticesData(int widthIn, int heightIn, int widthOut, int heightOut) { System.arraycopy(defaultTriangleVerticesData, 0, triangleVerticesData, 0, defaultTriangleVerticesData.length); float aspectRatioIn = (float) widthIn / heightIn; float heightOutCalculated = (float) widthOut / aspectRatioIn; if (heightOutCalculated < heightOut) { float deltaHeight = (heightOut - heightOutCalculated) / heightOut; GetMinMax vertical = new GetMinMax(1).invoke(); triangleVerticesData[vertical.getMin1()] += deltaHeight; triangleVerticesData[vertical.getMin2()] += deltaHeight; triangleVerticesData[vertical.getMax1()] -= deltaHeight; triangleVerticesData[vertical.getMax2()] -= deltaHeight; } else { float deltaWidth = (widthOut - heightOut * aspectRatioIn) / widthOut; GetMinMax horizontal = new GetMinMax(0).invoke(); triangleVerticesData[horizontal.getMin1()] += deltaWidth; triangleVerticesData[horizontal.getMin2()] += deltaWidth; triangleVerticesData[horizontal.getMax1()] -= deltaWidth; triangleVerticesData[horizontal.getMax2()] -= deltaWidth; } return triangleVerticesData; } 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 testVerticalBlackBarsWhenRotate90() { TriangleVerticesCalculator calculator = new TriangleVerticesCalculator(verticalBlackBarsRotated90); float[] verticesData = calculator.getAspectRatioVerticesData(5, 10, 10, 10); assertAlmostEqual(verticesData, verticalBlackBarsRotated90ArCorrected, 1e-7); }
@Test public void testVerticalBlackBars() { TriangleVerticesCalculator calculator = new TriangleVerticesCalculator(); float[] verticesData = calculator.getAspectRatioVerticesData(1280, 720, 640, 480); assertAlmostEqual(verticesData, verticalBlackBars, 0.01); }
@Test public void testHorizontalBlackBars() { TriangleVerticesCalculator calculator = new TriangleVerticesCalculator(); float[] verticesData = calculator.getAspectRatioVerticesData(640, 480, 1280, 720); assertAlmostEqual(verticesData, horizontalBlackBars, 0.01); }
@Test public void testHorizontalThanVerticalBlackBars() { TriangleVerticesCalculator calculator = new TriangleVerticesCalculator(); float[] verticesData = calculator.getAspectRatioVerticesData(1280, 720, 640, 480); assertAlmostEqual(verticesData, verticalBlackBars, 0.01); verticesData = calculator.getAspectRatioVerticesData(640, 480, 1280, 720); assertAlmostEqual(verticesData, horizontalBlackBars, 0.01); }