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 void smoothFillInverseHorGradient(Graphics g, Color[] colors, int x, int y, int w, int h) {
    Graphics2D g2D = (Graphics2D) g;
    Paint savedPaint = g2D.getPaint();
    int steps = colors.length;
    double dy = (double) h / (double) steps;
    int y1 = y;/*w  ww.  j a  va  2 s  . c om*/
    for (int i = 0; i < steps; i++) {
        int y2 = y + (int) Math.round((double) i * dy);
        g.setColor(colors[colors.length - i - 1]);
        if (i == (steps - 1)) {
            g2D.setPaint(null);
            g2D.setColor(colors[colors.length - i - 1]);
            g.fillRect(x, y1, w, y + h - y1);
        } else {
            g2D.setPaint(new GradientPaint(0, y1, colors[colors.length - i - 1], 0, y2,
                    colors[colors.length - i - 2]));
            g.fillRect(x, y1, w, y2 - y1);
        }
        y1 = y2;
    }
    g2D.setPaint(savedPaint);
}

From source file:org.eclipse.swt.snippets.Snippet285.java

static void loadPath(Region region, float[] points, byte[] types) {
    int start = 0, end = 0;
    for (int i = 0; i < types.length; i++) {
        switch (types[i]) {
        case SWT.PATH_MOVE_TO: {
            if (start != end) {
                int n = 0;
                int[] temp = new int[end - start];
                for (int k = start; k < end; k++) {
                    temp[n++] = Math.round(points[k]);
                }/*from  w  ww. j ava  2  s  . c  o m*/
                region.add(temp);
            }
            start = end;
            end += 2;
            break;
        }
        case SWT.PATH_LINE_TO: {
            end += 2;
            break;
        }
        case SWT.PATH_CLOSE: {
            if (start != end) {
                int n = 0;
                int[] temp = new int[end - start];
                for (int k = start; k < end; k++) {
                    temp[n++] = Math.round(points[k]);
                }
                region.add(temp);
            }
            start = end;
            break;
        }
        }
    }
}

From source file:Main.java

public static final double toFixed(final double d, final double precision) {
    final double pow = Math.pow(10, precision);
    return Math.round(d * pow) / pow;
}

From source file:Main.java

public static Bitmap resizeBitmapByScale(Bitmap bitmap, float scale, boolean recycle) {
    int width = Math.round(bitmap.getWidth() * scale);
    int height = Math.round(bitmap.getHeight() * scale);
    if (width == bitmap.getWidth() && height == bitmap.getHeight())
        return bitmap;
    Bitmap target = Bitmap.createBitmap(width, height, getConfig(bitmap));
    Canvas canvas = new Canvas(target);
    canvas.scale(scale, scale);//from   w w  w  . j a v  a2  s.  c  om
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    if (recycle)
        bitmap.recycle();
    return target;
}

From source file:net.gtaun.wl.common.textdraw.TextDrawUtils.java

public static PlayerTextdraw createPlayerTextBG(Player player, float x, float y, float w, float h) {
     int lines = Math.round((h - 5) / 5.0f);
     PlayerTextdraw textdraw = PlayerTextdraw.create(player, x + 4, (y - 50) / 1.075f + 50,
             StringUtils.repeat("~n~", lines));
     textdraw.setUseBox(true);/*from ww  w .  j a v  a2s. com*/
     textdraw.setLetterSize(0.1f, 0.5f);
     textdraw.setTextSize(x + w - 4, h - 7);
     return textdraw;
 }

From source file:Main.java

private static int ave(int src, int dst, float p) {
    return src + Math.round(p * (dst - src));
}

From source file:Main.java

public static Bitmap resizeBitmapByScale(final Bitmap bitmap, final float scale, final boolean recycle) {
    final int width = Math.round(bitmap.getWidth() * scale);
    final int height = Math.round(bitmap.getHeight() * scale);
    if (width == bitmap.getWidth() && height == bitmap.getHeight())
        return bitmap;
    final Bitmap target = Bitmap.createBitmap(width, height, getConfig(bitmap));
    final Canvas canvas = new Canvas(target);
    canvas.scale(scale, scale);//from w ww  .  j a  va2s  .c o m
    final Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    if (recycle) {
        bitmap.recycle();
    }
    return target;
}

From source file:com.castlabs.csf.manifest.ManifestHelper.java

public static String convertFramerate(double vrate) {
    vrate = (double) Math.round(vrate * 1000) / 1000;
    String frameRate = null;/*from   ww  w  . jav a  2  s  .c  o m*/
    if ((vrate > 14) && (vrate < 15)) {
        frameRate = "15000/1001";
    } else if ((vrate == 15)) {
        frameRate = "15000/1000";
    } else if ((vrate > 23) && (vrate < 24)) {
        frameRate = "24000/1001";
    } else if (vrate == 24) {
        frameRate = "24000/1000";
    } else if ((vrate > 24) && ((vrate < 25) || (vrate == 25))) {
        frameRate = "25000/1000";
    } else if ((vrate > 29) && (vrate < 30)) {
        frameRate = "30000/1001";
    } else if (vrate == 30) {
        frameRate = "30000/1000";
    } else if (vrate == 50) {
        frameRate = "50000/1000";
    } else if ((vrate > 59) && (vrate < 60)) {
        frameRate = "60000/1001";
    } else if (vrate == 60) {
        frameRate = "60000/1000";
    } else {
        System.out.println("Framerate " + vrate + " is not supported");
        System.exit(1);
    }
    return frameRate;
}

From source file:Main.java

public static void setBestExposure(Camera.Parameters parameters, boolean lightOn) {
    int minExposure = parameters.getMinExposureCompensation();
    int maxExposure = parameters.getMaxExposureCompensation();
    float step = parameters.getExposureCompensationStep();
    if ((minExposure != 0 || maxExposure != 0) && step > 0.0f) {
        // Set low when light is on
        float targetCompensation = lightOn ? MIN_EXPOSURE_COMPENSATION : MAX_EXPOSURE_COMPENSATION;
        int compensationSteps = Math.round(targetCompensation / step);
        //            float actualCompensation = step * compensationSteps;
        // Clamp value:
        compensationSteps = Math.max(Math.min(compensationSteps, maxExposure), minExposure);
        if (parameters.getExposureCompensation() != compensationSteps) {
            //                Log.i(TAG, "Exposure compensation already set to " + compensationSteps + " / " + actualCompensation);
            //            } else {
            //                Log.i(TAG, "Setting exposure compensation to " + compensationSteps + " / " + actualCompensation);
            parameters.setExposureCompensation(compensationSteps);
        }//  w w  w .  ja va2 s .  c  om
        //        } else {
        //            Log.i(TAG, "Camera does not support exposure compensation");
    }
}

From source file:Main.java

public static double translatePixelsToInchesRound(double pixels) {
    double inches = pixels / 72.0;
    inches = (Math.round(inches * 100.0)) / 100.0;
    return inches;
}