/** * This method updates current image corners and center points that are stored in * {@link #mCurrentImageCorners} and {@link #mCurrentImageCenter} arrays. * Those are used for several calculations. */ private void updateCurrentImagePoints() { mCurrentImageMatrix.mapPoints(mCurrentImageCorners, mInitialImageCorners); mCurrentImageMatrix.mapPoints(mCurrentImageCenter, mInitialImageCenter); }
/** * Transform an array of points with all matrices. VERY IMPORTANT: Keep * matrix order "value-touch-offset" when transforming. * * @param pts */ public void pointValuesToPixel(float[] pts) { mMatrixValueToPx.mapPoints(pts); mViewPortHandler.getMatrixTouch().mapPoints(pts); mMatrixOffset.mapPoints(pts); }
public static float getScale(Matrix matrix) { points[0] = 0; points[1] = 0; // Use sqrt(2) so that the hypotenuse is of length 1. points[2] = SQRT_2; points[3] = SQRT_2; matrix.mapPoints(points); float dx = points[2] - points[0]; float dy = points[3] - points[1]; // TODO: figure out why the result needs to be divided by 2. return (float) Math.hypot(dx, dy) / 2f; }
private void mapPoints(Matrix matrix) { float[] src = {pivotX, pivotY}; matrix.mapPoints(src); pivotX = src[0]; pivotY = src[1]; }
/** * Transforms the given array of touch positions (pixels) (x, y, x, y, ...) * into values on the chart. * * @param pixels */ public void pixelsToValue(float[] pixels) { Matrix tmp = mPixelToValueMatrixBuffer; tmp.reset(); // invert all matrixes to convert back to the original value mMatrixOffset.invert(tmp); tmp.mapPoints(pixels); mViewPortHandler.getMatrixTouch().invert(tmp); tmp.mapPoints(pixels); mMatrixValueToPx.invert(tmp); tmp.mapPoints(pixels); }
parentMatrix.mapPoints(points); path.reset(); path.moveTo(points[0], points[1]);
public void extend(float x, float y) { tmpPointArr[0] = x; tmpPointArr[1] = y; if (boundsRotation != 0f) { // Rotating given point so we can add it to bounds tmpMatrix.setRotate(-boundsRotation, boundsPivotX, boundsPivotY); tmpMatrix.mapPoints(tmpPointArr); } bounds.union(tmpPointArr[0], tmpPointArr[1]); }
/** * This methods checks whether a rectangle that is represented as 4 corner points (8 floats) * fills the crop bounds rectangle. * * @param imageCorners - corners of a rectangle * @return - true if it wraps crop bounds, false - otherwise */ protected boolean isImageWrapCropBounds(float[] imageCorners) { mTempMatrix.reset(); mTempMatrix.setRotate(-getCurrentAngle()); float[] unrotatedImageCorners = Arrays.copyOf(imageCorners, imageCorners.length); mTempMatrix.mapPoints(unrotatedImageCorners); float[] unrotatedCropBoundsCorners = RectUtils.getCornersFromRect(mCropRect); mTempMatrix.mapPoints(unrotatedCropBoundsCorners); return RectUtils.trapToRect(unrotatedImageCorners).contains(RectUtils.trapToRect(unrotatedCropBoundsCorners)); }
@Test(expected = Exception.class) public void mapPointsWithIndicesNull() { new Matrix().mapPoints(null, 0, new float[9], 0, 1); }
@Test(expected = Exception.class) public void mapPointsArraysMismatch() { new Matrix().mapPoints(new float[8], new float[9]); }
@Test(expected = Exception.class) public void mapPointsNull() { new Matrix().mapPoints(null); }
@Test public void mapPointsWithIndices() { float[] dst = new float[9]; dst[0] = 100f; float[] src = new float[9]; src[0] = 200f; new Matrix().mapPoints(dst, 0, src, 0, 9 >> 1); assertThat(dst[0]).isEqualTo(200f); }
@Test public void mapPoints2() { float[] dst = new float[9]; dst[0] = 100f; float[] src = new float[9]; src[0] = 200f; new Matrix().mapPoints(dst, src); assertThat(dst[0]).isEqualTo(200f); }
/** * Transforms an List of Entry into a float array containing the x and * y values transformed with all matrices for the SCATTERCHART. * * @param data * @return */ public float[] generateTransformedValuesScatter(IScatterDataSet data, float phaseX, float phaseY, int from, int to) { final int count = (int) ((to - from) * phaseX + 1) * 2; if (valuePointsForGenerateTransformedValuesScatter.length != count) { valuePointsForGenerateTransformedValuesScatter = new float[count]; } float[] valuePoints = valuePointsForGenerateTransformedValuesScatter; for (int j = 0; j < count; j += 2) { Entry e = data.getEntryForIndex(j / 2 + from); if (e != null) { valuePoints[j] = e.getX(); valuePoints[j + 1] = e.getY() * phaseY; } else { valuePoints[j] = 0; valuePoints[j + 1] = 0; } } getValueToPixelMatrix().mapPoints(valuePoints); return valuePoints; }
/** * Transforms an List of Entry into a float array containing the x and * y values transformed with all matrices for the CANDLESTICKCHART. * * @param data * @return */ public float[] generateTransformedValuesCandle(ICandleDataSet data, float phaseX, float phaseY, int from, int to) { final int count = (int) ((to - from) * phaseX + 1) * 2; if (valuePointsForGenerateTransformedValuesCandle.length != count) { valuePointsForGenerateTransformedValuesCandle = new float[count]; } float[] valuePoints = valuePointsForGenerateTransformedValuesCandle; for (int j = 0; j < count; j += 2) { CandleEntry e = data.getEntryForIndex(j / 2 + from); if (e != null) { valuePoints[j] = e.getX(); valuePoints[j + 1] = e.getHigh() * phaseY; } else { valuePoints[j] = 0; valuePoints[j + 1] = 0; } } getValueToPixelMatrix().mapPoints(valuePoints); return valuePoints; }
/** * Transforms an List of Entry into a float array containing the x and * y values transformed with all matrices for the LINECHART. * * @param data * @return */ public float[] generateTransformedValuesLine(ILineDataSet data, float phaseX, float phaseY, int min, int max) { final int count = ((int) ((max - min) * phaseX) + 1) * 2; if (valuePointsForGenerateTransformedValuesLine.length != count) { valuePointsForGenerateTransformedValuesLine = new float[count]; } float[] valuePoints = valuePointsForGenerateTransformedValuesLine; for (int j = 0; j < count; j += 2) { Entry e = data.getEntryForIndex(j / 2 + min); if (e != null) { valuePoints[j] = e.getX(); valuePoints[j + 1] = e.getY() * phaseY; } else { valuePoints[j] = 0; valuePoints[j + 1] = 0; } } getValueToPixelMatrix().mapPoints(valuePoints); return valuePoints; }
/** * Transforms an List of Entry into a float array containing the x and * y values transformed with all matrices for the BUBBLECHART. * * @param data * @return */ public float[] generateTransformedValuesBubble(IBubbleDataSet data, float phaseY, int from, int to) { final int count = (to - from + 1) * 2; // (int) Math.ceil((to - from) * phaseX) * 2; if (valuePointsForGenerateTransformedValuesBubble.length != count) { valuePointsForGenerateTransformedValuesBubble = new float[count]; } float[] valuePoints = valuePointsForGenerateTransformedValuesBubble; for (int j = 0; j < count; j += 2) { Entry e = data.getEntryForIndex(j / 2 + from); if (e != null) { valuePoints[j] = e.getX(); valuePoints[j + 1] = e.getY() * phaseY; } else { valuePoints[j] = 0; valuePoints[j + 1] = 0; } } getValueToPixelMatrix().mapPoints(valuePoints); return valuePoints; }
@Test public void mapPoints() { float[] value = new float[9]; value[0] = 100f; new Matrix().mapPoints(value); assertThat(value[0]).isEqualTo(100f); }
@Test public void testMapPoints() { final Matrix matrix = new Matrix(); matrix.postTranslate(-1.0f, -2.0f); matrix.postScale(2.0f, 3.0f); final float[] input = { 0.0f, 0.0f, 1.0f, 2.0f }; final float[] output = new float[input.length]; matrix.mapPoints(output, input); assertThat(output) .usingExactEquality() .containsExactly(-2.0f, -6.0f, 0.0f, 0.0f); }