List of usage examples for java.lang Math max
@HotSpotIntrinsicCandidate public static double max(double a, double b)
From source file:Main.java
public static boolean pointOnRect(double x, double y, double x1, double y1, double x2, double y2) { if (x >= Math.min(x1, x2) && x <= Math.max(x1, x2) && y >= Math.min(y1, y2) && y <= Math.max(y1, y2)) { return true; } else {/*ww w .j ava 2 s .com*/ return false; } }
From source file:Main.java
public static Bitmap scaleCenterCrop(Bitmap source, int newHeight, int newWidth) { int sourceWidth = source.getWidth(); int sourceHeight = source.getHeight(); // Compute the scaling factors to fit the new height and width, respectively. // To cover the final image, the final scaling will be the bigger // of these two. float xScale = (float) newWidth / sourceWidth; float yScale = (float) newHeight / sourceHeight; float scale = Math.max(xScale, yScale); // Now get the size of the source bitmap when scaled float scaledWidth = scale * sourceWidth; float scaledHeight = scale * sourceHeight; // Let's find out the upper left coordinates if the scaled bitmap // should be centered in the new size give by the parameters float left = (newWidth - scaledWidth) / 2; float top = (newHeight - scaledHeight) / 2; // The target rectangle for the new, scaled version of the source bitmap will now // be// ww w . j a v a2s. c o m RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight); // Finally, we create a new bitmap of the specified size and draw our new, // scaled bitmap onto it. Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, CONFIG); Canvas canvas = new Canvas(dest); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setFilterBitmap(true); paint.setDither(true); canvas.drawBitmap(source, null, targetRect, paint); return dest; }
From source file:Main.java
public static int clamp(int value, int low, int high) { return Math.min(Math.max(value, low), high); }
From source file:Main.java
public static float maxDistanceToCorner(int x, int y, int left, int top, int right, int bottom) { float maxDistance = 0; maxDistance = Math.max(maxDistance, (float) Math.hypot(x - left, y - top)); maxDistance = Math.max(maxDistance, (float) Math.hypot(x - right, y - top)); maxDistance = Math.max(maxDistance, (float) Math.hypot(x - left, y - bottom)); maxDistance = Math.max(maxDistance, (float) Math.hypot(x - right, y - bottom)); return maxDistance; }
From source file:Main.java
public static void enterReveal(final View view) { view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override/*from ww w. j a v a 2 s .c om*/ public void onGlobalLayout() { Animator animator = null; view.getViewTreeObserver().removeOnGlobalLayoutListener(this); int cx = view.getMeasuredWidth() / 2; int cy = view.getMeasuredHeight() / 2; try { final int finalRadius = Math.max(view.getWidth(), view.getHeight()) / 2 + 125; animator = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); } }); } catch (Exception ignored) { } view.setVisibility(View.VISIBLE); if (animator != null) { animator.start(); } } }); }
From source file:Main.java
public static int getMatchingThresholdFromString(String value) throws ParseException { char percent = new DecimalFormatSymbols().getPercent(); value = value.replace(percent, ' '); Number number = NumberFormat.getNumberInstance().parse(value); double parse = number.doubleValue(); double p = Math.log10(Math.max(Double.MIN_VALUE, Math.min(1, parse / 100))); return Math.max(0, (int) Math.round(-12 * p)); }
From source file:Main.java
public static File downSample(Context context, Uri uri) throws Exception { Bitmap b = null;/*from w ww. j av a 2 s.c o m*/ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; int scale = 1; if (o.outHeight > MAX_SIZE || o.outWidth > MAX_SIZE) { scale = (int) Math.pow(2, (int) Math .round(Math.log(MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5))); } //Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; InputStream is = context.getContentResolver().openInputStream(uri); b = BitmapFactory.decodeStream(is, null, o2); is.close(); File outputDir = context.getCacheDir(); File outputFile = File.createTempFile("avatar", ".jpg", outputDir); FileOutputStream fos = new FileOutputStream(outputFile); b.compress(Bitmap.CompressFormat.JPEG, 80, fos); fos.close(); return outputFile; }
From source file:Main.java
public static Bitmap decodeFile(File f, int maxSize) { Bitmap b = null;//from w w w .j a va 2s . com try { //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; FileInputStream fis = new FileInputStream(f); BitmapFactory.decodeStream(fis, null, o); fis.close(); int scale = 1; if (o.outHeight > maxSize || o.outWidth > maxSize) { scale = (int) Math.pow(2, (int) Math .round(Math.log(maxSize / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5))); } //Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; fis = new FileInputStream(f); b = BitmapFactory.decodeStream(fis, null, o2); fis.close(); } catch (IOException e) { } return b; }
From source file:Main.java
public static int clamp(int value, int min, int max) { return Math.min(Math.max(value, min), max); }
From source file:Main.java
/** * Scales the provided dimension such that it is just large enough to fit * the target width and height.// ww w . ja v a 2s .com * * @param dimensions The dimensions to scale * @param targetWidth The target width * @param targetHeight The target height * @return The scale factor applied to dimensions */ public static float scaleToFitTargetSize(int[] dimensions, int targetWidth, int targetHeight) { if (dimensions.length < 2 || dimensions[0] <= 0 || dimensions[1] <= 0) { throw new IllegalArgumentException( "Expected dimensions to have length >= 2 && dimensions[0] > 0 && " + "dimensions[1] > 0"); } float scale = Math.max((float) targetWidth / dimensions[0], (float) targetHeight / dimensions[1]); dimensions[0] *= scale; dimensions[1] *= scale; return scale; }