List of usage examples for java.lang Math max
@HotSpotIntrinsicCandidate public static double max(double a, double b)
From source file:Main.java
/** * Method returning given color modified to lighter color (positive translation) or darker * (negative translation).// w ww . j a v a2 s . c o m * * @param primaryColor basic color * @param translation positive or negative value of color translation * @return lighter/darker color */ public static int getColorWithTranslateBrightness(int primaryColor, int translation) { if (translation >= 0) { return Color.argb(Color.alpha(primaryColor), Math.min(Color.red(primaryColor) + translation, 255), Math.min(Color.green(primaryColor) + translation, 255), Math.min(Color.blue(primaryColor) + translation, 255)); } else { return Color.argb(Color.alpha(primaryColor), Math.max(Color.red(primaryColor) + translation, 0), Math.max(Color.green(primaryColor) + translation, 0), Math.max(Color.blue(primaryColor) + translation, 0)); } }
From source file:Main.java
public static Bitmap decodeFileFromDrawable(int id, int maxSize, Context context) { Bitmap b = null;/*from w w w.jav a 2 s. co m*/ try { // Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; InputStream inputStream = context.getResources().openRawResource(id); BitmapFactory.decodeStream(inputStream, null, o); inputStream.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; inputStream = context.getResources().openRawResource(id); b = BitmapFactory.decodeStream(inputStream, null, o2); inputStream.close(); } catch (IOException e) { } return b; }
From source file:Main.java
public static int getInsoleAngle(int axisX, int axisY, int axisZ) { int etalon = 4300; if (axisZ < 0) { return -1; }/*from w w w.j a v a 2s . c o m*/ axisX = Math.abs(axisX); axisY = Math.abs(axisY); axisZ = Math.abs(axisZ); int maxAxis = Math.max(axisY, axisX); double maxAngle = ((double) ((axisZ - maxAxis) * 100)) / etalon; return (int) (90 - maxAngle) / 2; }
From source file:Main.java
public static boolean pointAtELine(double x, double y, double x1, double y1, double x2, double y2) { double result = (x - x1) * (y2 - y1) - (y - y1) * (x2 - x1); if (result == 0) { return x >= Math.min(x1, x2) && x <= Math.max(x1, x2) && y >= Math.min(y1, y2) && y <= Math.max(y1, y2); } else {// www. j a va 2 s .c om return false; } }
From source file:Main.java
public static boolean pointAtELine(double x, double y, double x1, double y1, double x2, double y2) { double result = (x - x1) * (y2 - y1) - (y - y1) * (x2 - x1); if (result == 0) { if (x >= Math.min(x1, x2) && x <= Math.max(x1, x2) && y >= Math.min(y1, y2) && y <= Math.max(y1, y2)) { return true; } else {//www .j a v a2 s .co m return false; } } else { return false; } }
From source file:Main.java
/** * Create a darker color using a factor. * * @param color/*w w w .jav a 2 s. c o m*/ * @param factor * @return darker color */ public static Color darker(final Color color, float factor) { return new Color(Math.max((int) (color.getRed() * factor), 0), Math.max((int) (color.getGreen() * factor), 0), Math.max((int) (color.getBlue() * factor), 0)); }
From source file:Main.java
/** * Create a lighter color using a factor. * * @param color/* w w w . j ava2 s .c o m*/ * @param factor * @return lighter color */ public static Color lighter(final Color color, float factor) { return new Color(Math.max((int) (color.getRed() / factor), 0), Math.max((int) (color.getGreen() / factor), 0), Math.max((int) (color.getBlue() / factor), 0)); }
From source file:Main.java
public static int countComponents(int[][] image) { int n = 0;/*from w ww. j a v a 2s .c om*/ for (int y = 0; y < image.length; y++) { for (int x = 0; x < image[y].length; x++) { n = Math.max(n, image[y][x] + 1); } } return n; }
From source file:Main.java
public static float clamp(float value, float min, float max) { return Math.min(Math.max(value, min), max); }
From source file:Main.java
public static Bitmap getScaled(Bitmap bm, int sidePx, boolean max) { float w = bm.getWidth(); float h = bm.getHeight(); float wRatio = sidePx / w; float hRatio = sidePx / h; float ratio = max ? Math.min(wRatio, hRatio) : Math.max(wRatio, hRatio); w = ratio * w;//from w w w .j ava 2s .co m h = ratio * h; return Bitmap.createScaledBitmap(bm, (int) w, (int) h, true); }