Example usage for java.lang Math min

List of usage examples for java.lang Math min

Introduction

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

Prototype

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

Source Link

Document

Returns the smaller of two double values.

Usage

From source file:Main.java

/**
 * Computes the lightness value in HSL standard for the given color.
 *///from   w  ww.j  av a 2  s .c om
public static float getLightnessForColor(int color) {
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    int largest = Math.max(red, Math.max(green, blue));
    int smallest = Math.min(red, Math.min(green, blue));
    int average = (largest + smallest) / 2;
    return average / 255.0f;
}

From source file:Main.java

public static int getScreenMinWidth(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);//from   ww w . j ava 2 s. c  om
    return Math.min(size.x, size.y);
}

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//from ww  w .  j a  va2 s  . co 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

public static Bitmap getRoundedCircleBitmap(Bitmap scaleBitmapImage) {
    int targetWidth = 150;
    int targetHeight = 150;
    Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(targetBitmap);
    Path path = new Path();
    path.addCircle(((float) targetWidth - 1) / 2, ((float) targetHeight - 1) / 2,
            (Math.min(((float) targetWidth), ((float) targetHeight)) / 2), Path.Direction.CCW);

    canvas.clipPath(path);/*from   w  w w .j  a v  a  2 s .  com*/
    Bitmap sourceBitmap = scaleBitmapImage;
    canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()),
            new Rect(0, 0, targetWidth, targetHeight), null);
    return targetBitmap;
}

From source file:Main.java

/**
 * Converts the given pair of arrays into a map that maps each keys[i] to
 * the corresponding values[i].//  w w w  .ja va  2 s  .  c o  m
 * @return the map (empty map if keys == null or values == null)
 */
public static <K, V> Map<K, V> asMap(K[] keys, V[] values) {
    Map<K, V> map = new LinkedHashMap<K, V>();
    if (keys == null || values == null) {
        return map;
    }

    for (int i = 0, len = Math.min(keys.length, values.length); i < len; i++) {
        map.put(keys[i], values[i]);
    }
    return map;
}

From source file:Main.java

public static int min(final int... values) {
    int min = Integer.MAX_VALUE;
    for (final int v : values) {
        min = Math.min(v, min);
    }//from   ww  w . j a  v a  2s . c  o  m
    return min;
}

From source file:Main.java

public static Bitmap GetBitmapClippedCircle(Bitmap bitmap) {

    final int width = bitmap.getWidth();
    final int height = bitmap.getHeight();
    final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    final Path path = new Path();
    path.addCircle((float) (width / 2), (float) (height / 2), (float) Math.min(width, (height / 2)),
            Path.Direction.CCW);/*from   w  w  w .j a v  a2s.  co m*/

    final Canvas canvas = new Canvas(outputBitmap);
    canvas.clipPath(path);
    canvas.drawBitmap(bitmap, 0, 0, null);
    return outputBitmap;
}

From source file:Main.java

public static float getScreenSmallestWidth() {
    DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();

    int widthPixels = metrics.widthPixels;
    int heightPixels = metrics.heightPixels;

    float scaleFactor = metrics.density;

    float widthDp = widthPixels / scaleFactor;
    float heightDp = heightPixels / scaleFactor;

    return Math.min(widthDp, heightDp);
}

From source file:Main.java

/**
 * Test a value in specified range, returning minimum if it's below, and maximum if it's above
 *
 * @param value Value to test/*from w  w w .j  a v a 2  s.com*/
 * @param min   Minimum value of range
 * @param max   Maximum value of range
 * @return value if it's between min and max, min if it's below, max if it's above
 */
public static double clamp(double value, double min, double max) {
    return Math.max(min, Math.min(max, value));
}

From source file:Main.java

public static Pair<Integer, Integer> getScreenDimensions(Context paramContext) {
    WindowManager localWindowManager = (WindowManager) paramContext.getSystemService("window");
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    localWindowManager.getDefaultDisplay().getMetrics(localDisplayMetrics);
    int i = Math.min(localDisplayMetrics.widthPixels, localDisplayMetrics.heightPixels);
    int j = Math.max(localDisplayMetrics.widthPixels, localDisplayMetrics.heightPixels);
    return new Pair(Integer.valueOf(i), Integer.valueOf(j));
}