List of usage examples for java.lang Math ceil
public static double ceil(double a)
From source file:Main.java
public static RectF round(final RectF rect) { rect.left = (float) Math.floor(rect.left); rect.top = (float) Math.floor(rect.top); rect.right = (float) Math.ceil(rect.right); rect.bottom = (float) Math.ceil(rect.bottom); return rect;/*from ww w . j a va 2 s . c o m*/ }
From source file:Main.java
public static float getDesiredHeight(TextPaint paint) { FontMetrics fm = paint.getFontMetrics(); return (float) Math.ceil(fm.descent - fm.ascent); }
From source file:Main.java
private static int computeInitialSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) { double w = options.outWidth; double h = options.outHeight; int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels)); int upperBound = (minSideLength == -1) ? 128 : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength)); if (upperBound < lowerBound) { // return the larger one when there is no overlapping zone. return lowerBound; }/*w w w . ja v a 2 s. co m*/ if ((maxNumOfPixels == -1) && (minSideLength == -1)) { return 1; } else if (minSideLength == -1) { return lowerBound; } else { return upperBound; } }
From source file:Main.java
private static int computeInitialSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) { double w = options.outWidth; double h = options.outHeight; int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels)); int upperBound = (minSideLength == -1) ? 1280 : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength)); if (upperBound < lowerBound) { // return the larger one when there is no overlapping zone. return lowerBound; }/*from w w w . ja v a2s. c o m*/ if ((maxNumOfPixels == -1) && (minSideLength == -1)) { return 1; } else if (minSideLength == -1) { return lowerBound; } else { return upperBound; } }
From source file:Main.java
private static int computeInitialSampleSize(Options options, int minSideLength, int maxNumOfPixels) { double w = options.outWidth; double h = options.outHeight; int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels)); int upperBound = (minSideLength == -1) ? 128 : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength)); if (upperBound < lowerBound) { // return the larger one when there is no overlapping zone. return lowerBound; }/*from w w w .j a v a 2 s . co m*/ if ((maxNumOfPixels == -1) && (minSideLength == -1)) { return 1; } else if (minSideLength == -1) { return lowerBound; } else { return upperBound; } }
From source file:Main.java
public static int getInSampleSize(double scale) { double log = Math.log(scale) / Math.log(2); double logCeil = Math.ceil(log); return ((int) Math.pow(2, logCeil) + 1); }
From source file:Main.java
public static double getRoundedDistance(double distance) { return Math.ceil(distance * 100.0D) / 100.0D; }
From source file:Main.java
public static int getScaledImageSize(int maxZoomLevel, int currZoomLevel, int size) { double scale = 1.0 / Math.pow(2, maxZoomLevel - currZoomLevel); return (int) Math.ceil(size * scale); }
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 . ja v a2 s . com*/ * @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; }
From source file:Main.java
private static int computeInitialSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) { double w = options.outWidth; double h = options.outHeight; int lowerBound = (maxNumOfPixels < 0) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels)); int upperBound = (minSideLength < 0) ? 128 : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength)); if (upperBound < lowerBound) { // return the larger one when there is no overlapping zone. return lowerBound; }/*from w w w . ja v a 2 s . c om*/ if (maxNumOfPixels < 0 && minSideLength < 0) { return 1; } else if (minSideLength < 0) { return lowerBound; } else { return upperBound; } }