List of usage examples for java.lang Math max
@HotSpotIntrinsicCandidate public static double max(double a, double b)
From source file:Main.java
/** * Get a rectangle for the given 4 points (x0,y0,x1,y1,x2,y2,x3,y3) by finding the min/max 2 points that * contains the given 4 points and is a stright rectangle. *///from w w w .java2 s. c om static Rect getRectFromPoints(float[] points, int imageWidth, int imageHeight, boolean fixAspectRatio, int aspectRatioX, int aspectRatioY) { int left = Math.round(Math.max(0, getRectLeft(points))); int top = Math.round(Math.max(0, getRectTop(points))); int right = Math.round(Math.min(imageWidth, getRectRight(points))); int bottom = Math.round(Math.min(imageHeight, getRectBottom(points))); Rect rect = new Rect(left, top, right, bottom); if (fixAspectRatio) { fixRectForAspectRatio(rect, aspectRatioX, aspectRatioY); } return rect; }
From source file:Main.java
public static void setBrightness(Activity activity, float brightness) { // Settings.System.putInt(activity.getContentResolver(), // Settings.System.SCREEN_BRIGHTNESS_MODE, // Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); WindowManager.LayoutParams lp = activity.getWindow().getAttributes(); // some ROM may ANF if set brightness to 0 lp.screenBrightness = Math.max(brightness, 0.01f); activity.getWindow().setAttributes(lp); }
From source file:Main.java
public static boolean stop(ExecutorService executorService, int waitBeforeTerminateSecs, Logger logger) /* */ {//from w w w . ja v a 2 s. co m /* 53 */int waitMillis = Math.max(1000, 1000 * waitBeforeTerminateSecs); /* */ /* */ /* 56 */executorService.shutdown(); /* */ /* */ /* 59 */boolean stopped = false; /* 60 */while ((waitMillis > 0) && (!stopped)) { /* 61 */long startMillis = System.currentTimeMillis(); /* */try { /* 63 */logger.debug("Waiting for thread pool to stop"); /* 64 */stopped = executorService.awaitTermination(waitMillis, TimeUnit.MILLISECONDS); /* */} catch (InterruptedException e) { /* 66 */logger.debug("Thread was interrupted while it was waiting for thread pool to stop", e); /* 67 */Thread.currentThread().interrupt(); /* 68 */break; /* */} /* 70 */waitMillis = (int) (waitMillis - (System.currentTimeMillis() - startMillis)); /* */} /* */ /* 73 */if (!executorService.isTerminated()) { /* 74 */logger.warn("Thread pool will be forcibly stopped now if it has not already stopped"); /* 75 */executorService.shutdownNow(); /* */try { /* 77 */stopped = executorService.awaitTermination(waitBeforeTerminateSecs, TimeUnit.SECONDS); /* */} /* */catch (InterruptedException e) { } /* */ /* 81 */if (!executorService.isTerminated()) { /* 82 */logger.warn("Could not shutdown thread pool in [{}] seconds", Integer.valueOf(waitBeforeTerminateSecs)); /* */} /* */} /* */ /* 86 */return stopped; /* */}
From source file:Main.java
public static Bitmap getMatrixBitmap(Bitmap bm, int w, int h, boolean needRecycle) { int width = bm.getWidth(); int height = bm.getHeight(); boolean isCompress = (width > w && height > h) && (w != 0 && h != 0); if (isCompress) { float scaleWidth = ((float) w) / width; float scaleHeight = ((float) h) / height; float scale = Math.max(scaleWidth, scaleHeight); Matrix matrix = new Matrix(); matrix.postScale(scale, scale);//from w ww . j a va 2 s .c o m Bitmap bitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true); if (needRecycle && bm != null && bm != bitmap) { bm.recycle(); } return bitmap; } else { return bm; } }
From source file:Main.java
/** * Clamps a value between lower and upper bounds. Formally, given value v, * and an interval [lower, upper], lower <= clamp(v, lower, upper) <= upper holds true * * @param v the value to clamp/*from w w w .j a v a 2 s .c o m*/ * @param lower the lower bound of the interval * @param upper the upper bound of the interval * @return the clamped value of v in the [lower, upper] interval */ public static float clamp(float v, float lower, float upper) { return Math.max(lower, Math.min(upper, v)); }
From source file:Main.java
public static int getInsolesMaxAngle(int insoleAxisXF, int insoleAxisYF, int insoleAxisZF, int insoleAxisXS, int insoleAxisYS, int insoleAxisZS) { int insoleAngleF = getInsoleAngle(insoleAxisXF, insoleAxisYF, insoleAxisZF); if (insoleAngleF == -1) { return insoleAngleF; }/*from w ww .j a va 2 s . c om*/ int insoleAngleS = getInsoleAngle(insoleAxisXS, insoleAxisYS, insoleAxisZS); if (insoleAngleS == -1) { return insoleAngleS; } return Math.max(insoleAngleF, insoleAngleS); }
From source file:Main.java
public static double[] minmax(List<Double> paramList) { if (paramList.size() == 0) { return new double[2]; }/*w w w . j a v a2s.c o m*/ double d1 = ((Double) paramList.get(0)).doubleValue(); double d2 = d1; int i = paramList.size(); for (int j = 1;; j++) { if (j >= i) { return new double[] { d1, d2 }; } double d3 = ((Double) paramList.get(j)).doubleValue(); d1 = Math.min(d1, d3); d2 = Math.max(d2, d3); } }
From source file:Main.java
public static Bitmap createScaledBitmap(Bitmap bitmap, int width, int height) { Bitmap background = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888); float originalWidth = bitmap.getWidth(), originalHeight = bitmap.getHeight(); Canvas canvas = new Canvas(background); float scale = Math.max(width / originalWidth, height / originalHeight); float xTranslation = 0.0f, yTranslation = (height - originalHeight * scale) / 2.0f; if (originalWidth < originalHeight) { // scale = height / originalHeight; xTranslation = (width - originalWidth * scale) / 2.0f; yTranslation = 0.0f;//from w ww . ja va 2 s . co m } Matrix transformation = new Matrix(); transformation.postTranslate(xTranslation, yTranslation); transformation.preScale(scale, scale); Paint paint = new Paint(); paint.setFilterBitmap(true); canvas.drawBitmap(bitmap, transformation, paint); return background; }
From source file:Main.java
public static Bitmap combineDrawables(Resources resources, int head, int body, int legs) { Bitmap headBitmap = getBitmap(resources, head); Bitmap bodyBitmap = getBitmap(resources, body); Bitmap legsBitmap = getBitmap(resources, legs); int height = headBitmap.getHeight() + bodyBitmap.getHeight() + legsBitmap.getHeight(); int width = Math.max(headBitmap.getWidth(), Math.max(bodyBitmap.getWidth(), legsBitmap.getWidth())); Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas comboImage = new Canvas(result); comboImage.drawBitmap(headBitmap, 0f, 0f, null); comboImage.drawBitmap(bodyBitmap, 0f, headBitmap.getHeight(), null); comboImage.drawBitmap(legsBitmap, 0f, headBitmap.getHeight() + bodyBitmap.getHeight(), null); return result; }
From source file:Main.java
/** * NOTE: Arithmetic operations in primitive types may lead to arithmetic overflow. To retain * precision, BigDecimal objects are used. * * @param rgb//from w w w . j a v a 2s . c o m * @return */ public static int[] convertRGB_8_8_8_To_HSB_32_32_32(int[] rgb) { int[] hsb = new int[3]; int maxChroma = Math.max(Math.max(rgb[0], rgb[1]), rgb[2]); int minChroma = Math.min(Math.min(rgb[0], rgb[1]), rgb[2]); int diff = maxChroma - minChroma; // Hue BigDecimal hue; if (diff == 0) { hue = BigDecimal.ZERO; } else if (maxChroma == rgb[0]) { float tmp = (rgb[1] - rgb[2]) / (float) diff; if (tmp < 0) { tmp += 6 * Math.ceil(-tmp / 6.0); } else { tmp -= 6 * Math.floor(tmp / 6.0); } hue = BigDecimal.valueOf(tmp); } else if (maxChroma == rgb[1]) { hue = BigDecimal.valueOf((rgb[2] - rgb[0]) / (float) diff + 2); } else { hue = BigDecimal.valueOf((rgb[0] - rgb[1]) / (float) diff + 4); } // [0, 360] -> [0, 0xffffffff] hue = hue.multiply(BigDecimal.valueOf(0xffffffffL)); hue = hue.divide(BigDecimal.valueOf(6), RoundingMode.FLOOR); hsb[0] = ByteBuffer.allocate(8).putLong(hue.longValue()).getInt(4); // Saturation if (maxChroma == 0) { hsb[1] = 0; } else { // [0, 1] -> [0, 0xffffffff] BigDecimal sat = BigDecimal.valueOf(diff); sat = sat.multiply(BigDecimal.valueOf(0xffffffffL)); sat = sat.divide(BigDecimal.valueOf(maxChroma), RoundingMode.FLOOR); hsb[1] = ByteBuffer.allocate(8).putLong(sat.longValue()).getInt(4); } // Brightness // [0, 255] -> [0, 0xffffffff] BigDecimal brightness = BigDecimal.valueOf(maxChroma); brightness = brightness.multiply(BigDecimal.valueOf(0xffffffffL)); brightness = brightness.divide(BigDecimal.valueOf(0xffL), RoundingMode.FLOOR); hsb[2] = ByteBuffer.allocate(8).putLong(brightness.longValue()).getInt(4); return hsb; }