Example usage for java.lang Math round

List of usage examples for java.lang Math round

Introduction

In this page you can find the example usage for java.lang Math round.

Prototype

public static long round(double a) 

Source Link

Document

Returns the closest long to the argument, with ties rounding to positive infinity.

Usage

From source file:Main.java

public static double getGeoDistance(double longitude1, double latitude1, double longitude2, double latitude2) {
    double EARTH_RADIUS = 6378137;
    double radLat1 = rad(latitude1);
    double radLat2 = rad(latitude2);
    double a = radLat1 - radLat2;
    double b = rad(longitude1) - rad(longitude2);
    double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
            + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
    s = s * EARTH_RADIUS;/*from  www.  j av  a 2 s  .c  o m*/
    s = Math.round(s * 10000) / 10000;
    return s;
}

From source file:Main.java

public static void fillInverseVerGradient(Graphics g, Color[] colors, int x, int y, int w, int h) {
    int steps = colors.length;
    double dx = (double) w / (double) steps;
    int x1 = x;/*ww w  .  j  a  va 2s  .  c  o m*/
    for (int i = 0; i < steps; i++) {
        int x2 = x + (int) Math.round((double) i * dx);
        g.setColor(colors[colors.length - i - 1]);
        if (i == (steps - 1)) {
            g.fillRect(x1, y, x + w - x1, h);
        } else {
            g.fillRect(x1, y, x2 - x1, h);
        }
        x1 = x2;
    }
}

From source file:Main.java

private static int calculateSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (height > reqHeight || width > reqWidth) {
        if (width > height) {
            inSampleSize = Math.round((float) height / (float) reqHeight);
        } else {//from w w  w  .ja  va  2 s  .c  om
            inSampleSize = Math.round((float) width / (float) reqWidth);
        }
    }
    int scale = 1;
    while (inSampleSize > scale) {
        scale *= 2;
    }
    // is it needed?
    // if (inSampleSize < scale) {
    // scale /= 2;
    // }
    return scale;
    // return inSampleSize;
}

From source file:Main.java

public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {

    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (height > reqHeight || width > reqWidth) {

        // Calculate ratios of height and width to requested height and width
        final int heightRatio = Math.round((float) height / (float) reqHeight);
        final int widthRatio = Math.round((float) width / (float) reqWidth);

        // Choose the smallest ratio as inSampleSize value, this will guarantee
        // a final image with both dimensions larger than or equal to the
        // requested height and width.
        inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
    }//from w ww. j  av  a 2s . c  o m
    return inSampleSize;

}

From source file:Main.java

public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;
    if (height > reqHeight || width > reqWidth) {
        // Calculate ratios of height and width to requested height and width
        final int heightRatio = Math.round((float) height / (float) reqHeight);
        final int widthRatio = Math.round((float) width / (float) reqWidth);

        // Choose the smallest ratio as inSampleSize value, this will guarantee
        // a final image with both dimensions larger than or equal to the
        // requested height and width.
        inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
    }//  ww  w .  j  av a  2 s . c o m
    return inSampleSize;
}

From source file:Main.java

static String applyHash(String string) {
    if (string == null)
        return null;

    double[] hashedStrings = new double[HASH_CONSTANTS.length];
    for (int i = 0; i < hashedStrings.length; i++) {
        hashedStrings[i] = applyUserHash(HASH_CONSTANTS[i], string);
    }/*w  w w . ja  v a  2  s . co  m*/

    double product = 1;
    for (double hashedString : hashedStrings) {
        product *= hashedString;
    }

    return Long.toHexString(Math.round(Math.abs(product) / 65536d));
}

From source file:Main.java

public static long roundEven(double d) {
    return Math.round(d / 2) * 2;
}

From source file:Main.java

public static int XYZToColor(double x, double y, double z) {
    double r = (x * 3.2406 + y * -1.5372 + z * -0.4986) / 100;
    double g = (x * -0.9689 + y * 1.8758 + z * 0.0415) / 100;
    double b = (x * 0.0557 + y * -0.2040 + z * 1.0570) / 100;

    r = r > 0.0031308 ? 1.055 * Math.pow(r, 1 / 2.4) - 0.055 : 12.92 * r;
    g = g > 0.0031308 ? 1.055 * Math.pow(g, 1 / 2.4) - 0.055 : 12.92 * g;
    b = b > 0.0031308 ? 1.055 * Math.pow(b, 1 / 2.4) - 0.055 : 12.92 * b;

    return Color.rgb(constrain((int) Math.round(r * 255), 0, 255), constrain((int) Math.round(g * 255), 0, 255),
            constrain((int) Math.round(b * 255), 0, 255));
}

From source file:Main.java

public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if ((height > reqHeight) || (width > reqWidth)) {
        if (width > height) {
            inSampleSize = Math.round((float) height / (float) reqHeight);
        } else {/*from  w  ww . j a  v  a2s .c o m*/
            inSampleSize = Math.round((float) width / (float) reqWidth);
        }
    }
    return inSampleSize;
}

From source file:Main.java

private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (height > reqHeight || width > reqWidth) {

        // Calculate ratios of height and width to requested height and
        // width//from  w ww .java 2s.  c o  m
        final int heightRatio = Math.round((float) height / (float) reqHeight);
        final int widthRatio = Math.round((float) width / (float) reqWidth);

        // Choose the smallest ratio as inSampleSize value, this will
        // guarantee
        // a final image with both dimensions larger than or equal to the
        // requested height and width.
        inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
    }

    return inSampleSize;
}