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

public static Bitmap getCircleCroppedBitmap(Bitmap bitmap) {
    if (bitmap == null)
        return null;
    final int srcSize = Math.min(bitmap.getWidth(), bitmap.getHeight());
    return getScaledCircleCroppedBitmap(bitmap, srcSize);
}

From source file:Main.java

/**
 * If value >= max returns max. If value <= min returns min. Otherwise returns value.
 *//*from w w  w .j a v a  2  s  . c  om*/
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 int[] copyOf(int[] original, int newLength) {
    int[] copy = new int[newLength];
    System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
    return copy;/* w w w  . j a va2s .c  o m*/
}

From source file:Main.java

private static double boundaryRestrict(double f, double e, double d) {
    return Math.max(Math.min(f, d), e);
}

From source file:Main.java

public static void pack(Component c) {
    Window window = getFrame(c);/*from  w  w w.  j  av  a  2 s  .c om*/
    window.pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension bounds = new Dimension();
    bounds.width = Math.min(window.getWidth(), screenSize.width * 8 / 10);
    bounds.height = Math.min(window.getHeight(), screenSize.height * 8 / 10);
    window.setSize(bounds);
}

From source file:Main.java

public static Collection<Integer> seq(int start, int stop) {
    List<Integer> l = new ArrayList<Integer>(Math.abs(stop - start));
    for (int i = Math.min(start, stop); i <= Math.max(start, stop); i++) {
        l.add(i);//from w  w w . ja  va 2  s.  c o  m
    }
    if (stop < start)
        Collections.reverse(l);
    return l;

}

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./*ww w  . j a v a  2 s . co m*/
 * @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

private static int minimum(int a, int b, int c) {
    return Math.min(Math.min(a, b), c);
}

From source file:Main.java

public static Bitmap getRoundImage(Bitmap oriImg, boolean recycleOld) {

    Bitmap targetBitmap = null;/*w  ww.  ja  v a 2s  .  c o m*/

    if (oriImg != null && !oriImg.isRecycled()) {
        int size = Math.min(oriImg.getWidth(), oriImg.getHeight());
        int targetWidth = size;
        int targetHeight = size;

        targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(targetBitmap);

        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setFilterBitmap(true);
        canvas.drawARGB(0, 0, 0, 0);
        canvas.drawCircle(targetWidth / 2f, targetHeight / 2f, targetWidth / 2f, paint);

        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(oriImg, new Rect(0, 0, size, size), new Rect(0, 0, targetWidth, targetHeight), paint);

        if (recycleOld) {
            oriImg.recycle();
        }
    }
    return targetBitmap;
}

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 w  w  .j a v a  2  s .  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;
}