/** * Takes an array of 2D coordinates representing corners and returns the * smallest rectangle containing those coordinates. * * @param array array of 2D coordinates * @return smallest rectangle containing coordinates */ public static RectF trapToRect(float[] array) { RectF r = new RectF(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY); for (int i = 1; i < array.length; i += 2) { float x = Math.round(array[i - 1] * 10) / 10.f; float y = Math.round(array[i] * 10) / 10.f; r.left = (x < r.left) ? x : r.left; r.top = (y < r.top) ? y : r.top; r.right = (x > r.right) ? x : r.right; r.bottom = (y > r.bottom) ? y : r.bottom; } r.sort(); return r; }
public static void trapToRect(@NonNull RectF r, @NonNull float[] array) { r.set(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY); for (int i = 1; i < array.length; i += 2) { float x = round(array[i - 1] * 10) / 10.f; float y = round(array[i] * 10) / 10.f; r.left = (x < r.left) ? x : r.left; r.top = (y < r.top) ? y : r.top; r.right = (x > r.right) ? x : r.right; r.bottom = (y > r.bottom) ? y : r.bottom; } r.sort(); } }
public static RectF trapToRect(float[] array) { RectF r = new RectF(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY); for (int i = 1; i < array.length; i += 2) { float x = round(array[i - 1] * 10) / 10.f; float y = round(array[i] * 10) / 10.f; r.left = (x < r.left) ? x : r.left; r.top = (y < r.top) ? y : r.top; r.right = (x > r.right) ? x : r.right; r.bottom = (y > r.bottom) ? y : r.bottom; } r.sort(); return r; } }
public static RectF trapToRect(float[] array) { RectF r = new RectF(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY); for (int i = 1; i < array.length; i += 2) { float x = round(array[i - 1] * 10) / 10.f; float y = round(array[i] * 10) / 10.f; r.left = (x < r.left) ? x : r.left; r.top = (y < r.top) ? y : r.top; r.right = (x > r.right) ? x : r.right; r.bottom = (y > r.bottom) ? y : r.bottom; } r.sort(); return r; }
mRectF.sort(); int left = (int) ((mRectF.left < mRectF.right ? (int) mRectF.left : (int) mRectF.right) - width / 2); int right = (int) ((mRectF.right > mRectF.left ? (int) mRectF.right : (int) mRectF.left) + width / 2);
paint.getTextBounds(calclen.toString(), 0, calclen.length(), tRect); dRect.set(tRect); dRect.sort(); dRect.offset((int)x, (int)y + fontsize); dRect.top -= 3;
paint.getTextBounds(">" + calclen.toString(), 0, calclen.length() + 1, tRect); dRect.set(tRect); dRect.sort(); dRect.offset((int)x, (int)y); dRect.top -= 3;
arcRectF.sort();