Example usage for java.lang Math max

List of usage examples for java.lang Math max

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double max(double a, double b) 

Source Link

Document

Returns the greater of two double values.

Usage

From source file:Main.java

/**
 * Returns the given value if between the min and max value. If lower than
 * minimum, returns minimum, if higher than maximum, returns maximum.
 *
 * @param value the value./*from   w  w w.j av a2 s.  c  om*/
 * @param min   the minimum value.
 * @param max   the maximum value.
 * @return an integer value.
 */
public static int getWithin(int value, int min, int max) {
    value = Math.max(value, min);
    value = Math.min(value, max);
    return value;
}

From source file:Main.java

/**
 * Returns the saturation component of a color int.
 *
 * @return A value between 0.0f and 1.0f
 *
 * @hide Pending API council/*from w  ww  .ja va2s .c  o m*/
 */
public static float saturation(int color) {
    int r = (color >> 16) & 0xFF;
    int g = (color >> 8) & 0xFF;
    int b = color & 0xFF;

    int V = Math.max(b, Math.max(r, g));
    int temp = Math.min(b, Math.min(r, g));

    float S;

    if (V == temp) {
        S = 0;
    } else {
        S = (V - temp) / (float) V;
    }

    return S;
}

From source file:Main.java

public static int getScreenLongSize(Context context) {
    getScreenSize(context);//from   w ww  . j av a 2 s  .  c  o m
    return Math.max(displayMetrics.widthPixels, displayMetrics.heightPixels);
}

From source file:Main.java

private static Bitmap bitmapCrop(Bitmap rawBitmap, int width, int height, int resWidth, int resHeight) {

    int cropX, cropY, cropWidth, cropHeight;

    float xScale = (float) width / (float) resWidth;
    float yScale = (float) height / (float) resHeight;
    float scale = Math.max(xScale, yScale);

    if (xScale >= yScale) {
        cropWidth = Math.round(resWidth);
        cropX = 0;// w  ww. j  av  a 2 s. co m
        cropHeight = Math.round(height / scale);
        cropY = (resHeight - cropHeight) / 2;
    } else {
        cropWidth = Math.round(width / scale);
        cropX = (resWidth - cropWidth) / 2;
        cropHeight = Math.round(resHeight);
        cropY = 0;
    }

    return Bitmap.createBitmap(rawBitmap, cropX, cropY, cropWidth, cropHeight);
}

From source file:Main.java

private static int indexOfLastSeparator(String filename) {
    if (filename == null) {
        return -1;
    } else {/*  w ww. j  a va  2  s  .  c  om*/
        int lastUnixPos = filename.lastIndexOf(UNIX_SEPARATOR);
        int lastWindowsPos = filename.lastIndexOf(WINDOWS_SEPARATOR);
        return Math.max(lastUnixPos, lastWindowsPos);
    }
}

From source file:Main.java

public static int getSecurityLevelColor(final float security) {
    if (security > 0.5) {
        return Color.HSVToColor(255, new float[] { 180f * security, 100f, 100f });
    }//from   w  w w .j a v a 2  s  . c o m
    if (security > 0.1) {
        return Color.HSVToColor(255, new float[] { Math.max(180f * security - 30f, 0f), 100f, 100f });
    }
    if (security > 0) {
        return Color.HSVToColor(255, new float[] { Math.max(180f * security - 60f, 0f), 100f, 100f });
    }
    return Color.HSVToColor(255, new float[] { 0f, 100f, 100f });
}

From source file:Main.java

/**
 * Returns the hue component of a color int.
 *
 * @return A value between 0.0f and 1.0f
 *
 * @hide Pending API council/* w w  w .j  a v a  2 s  . c o  m*/
 */
public static float hue(int color) {
    int r = (color >> 16) & 0xFF;
    int g = (color >> 8) & 0xFF;
    int b = color & 0xFF;

    int V = Math.max(b, Math.max(r, g));
    int temp = Math.min(b, Math.min(r, g));

    float H;

    if (V == temp) {
        H = 0;
    } else {
        final float vtemp = (float) (V - temp);
        final float cr = (V - r) / vtemp;
        final float cg = (V - g) / vtemp;
        final float cb = (V - b) / vtemp;

        if (r == V) {
            H = cb - cg;
        } else if (g == V) {
            H = 2 + cr - cb;
        } else {
            H = 4 + cg - cr;
        }

        H /= 6.f;
        if (H < 0) {
            H++;
        }
    }

    return H;
}

From source file:Main.java

/**
 * If value &gt;= max returns max. If value &lt;= min returns min. Otherwise returns value.
 *///  ww w  .  j  a  va 2 s  .  com
public static float clamp(float value, float min, float max) {
    return Math.max(Math.min(value, max), min);
}

From source file:Main.java

public static double colorDistanceCore(double[] lab1, double[] lab2) {
    double[] lab = new double[] { lab2[0] - lab1[0], lab2[1] - lab1[1], lab2[2] - lab1[2] };
    double C1 = Math.sqrt(lab1[1] * lab1[1] + lab1[2] * lab1[2]);
    double C2 = Math.sqrt(lab2[1] * lab2[1] + lab2[2] * lab2[2]);
    double Ci = C2 - C1;
    double Hi = Math.sqrt(Math.max(lab[1] * lab[1] + lab[2] * lab[2] - Ci * Ci, 0));

    double kL = 1, kC = 1, kH = 1, K1 = .045, K2 = .015;
    double SL = 1, SC = 1 + K1 * C2, SH = 1 + K2 * C2;
    double dL = lab[0] / (kL * SL), dC = Ci / (kC * SC), dH = Hi / (kH * SH);
    return Math.sqrt(dL * dL + dC * dC + dH * dH);
}

From source file:Main.java

public static final Bitmap getBitmap(String fileName) {
    Bitmap bitmap = null;/* w  w  w. jav a 2s.  c o  m*/
    try {
        Options options = new Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(fileName, options);
        options.inSampleSize = Math.max(1, (int) Math
                .ceil(Math.max((double) options.outWidth / 1024f, (double) options.outHeight / 1024f)));
        options.inJustDecodeBounds = false;
        bitmap = BitmapFactory.decodeFile(fileName, options);
    } catch (OutOfMemoryError error) {
        error.printStackTrace();
    }
    return bitmap;
}