@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); }
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 { 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 { 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); }
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(); }
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();  }