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 int resizeTextSize(int screenWidth, int screenHeight, int textSize) {
    float ratio = 1;
    try {//from   www .j a va2 s. c  o  m
        float ratioWidth = (float) screenWidth / 480;
        float ratioHeight = (float) screenHeight / 800;
        ratio = Math.min(ratioWidth, ratioHeight);
    } catch (Exception e) {
    }
    return Math.round(textSize * ratio);
}

From source file:Main.java

public static float[] vectorSum(float[] vector, float[] vector2) {
    float[] ret = new float[vector.length];
    for (int i = 0; i < Math.min(vector.length, vector2.length); i++) {
        ret[i] += vector[i] + vector2[i];
    }/*w w w  . j  ava2s .  c  o m*/
    return ret;
}

From source file:Main.java

static public void centerOnParent(final Window child, final boolean absolute) {
    child.pack();//from   www.  j a v  a2 s.  c o m
    boolean useChildsOwner = child.getOwner() != null
            ? ((child.getOwner() instanceof JFrame) || (child.getOwner() instanceof JDialog))
            : false;
    final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    final Dimension parentSize = useChildsOwner ? child.getOwner().getSize() : screenSize;
    final Point parentLocationOnScreen = useChildsOwner ? child.getOwner().getLocationOnScreen()
            : new Point(0, 0);
    final Dimension childSize = child.getSize();
    childSize.width = Math.min(childSize.width, screenSize.width);
    childSize.height = Math.min(childSize.height, screenSize.height);
    child.setSize(childSize);
    int x;
    int y;
    if ((child.getOwner() != null) && child.getOwner().isShowing()) {
        x = (parentSize.width - childSize.width) / 2;
        y = (parentSize.height - childSize.height) / 2;
        x += parentLocationOnScreen.x;
        y += parentLocationOnScreen.y;
    } else {
        x = (screenSize.width - childSize.width) / 2;
        y = (screenSize.height - childSize.height) / 2;
    }
    if (!absolute) {
        x /= 2;
        y /= 2;
    }
    child.setLocation(x, y);
}

From source file:Main.java

public static Bitmap getScaled(Bitmap bm, int sidePx, boolean max) {
    float w = bm.getWidth();
    float h = bm.getHeight();
    float wRatio = sidePx / w;
    float hRatio = sidePx / h;
    float ratio = max ? Math.min(wRatio, hRatio) : Math.max(wRatio, hRatio);
    w = ratio * w;/*from  ww  w.jav  a 2s .co m*/
    h = ratio * h;
    return Bitmap.createScaledBitmap(bm, (int) w, (int) h, true);
}

From source file:Main.java

public static float hue(int argb) {
    int r = (argb >> 16) & 0xFF;
    int g = (argb >> 8) & 0xFF;
    int b = argb & 0xFF;

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

    float H;// ww w. j a  va  2s. c om

    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

/**
 * clip source bitmap into a circle bitmap
 *
 * @param src     the source bitmap//www . jav a 2 s .c o  m
 * @param recycle whether recycle the source bitmap
 * @param config  bitmap config
 * @return clipped  circle bitmap
 */
public static Bitmap createCircleBitmap(Bitmap src, boolean recycle, Bitmap.Config config) {
    if (src == null) {
        return null;
    }
    if (config == null) {
        config = Bitmap.Config.ARGB_8888;
    }
    Bitmap out = Bitmap.createBitmap(src.getWidth(), src.getHeight(), config);
    final Rect rect = new Rect(0, 0, Math.min(src.getWidth(), src.getHeight()),
            Math.min(src.getWidth(), src.getHeight()));
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    Canvas canvas = new Canvas(out);
    canvas.drawARGB(0, 0, 0, 0);
    RectF rectF = new RectF(rect);
    canvas.drawOval(rectF, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(src, rect, rect, paint);

    if (recycle) {
        src.recycle();
    }

    return out;

}

From source file:Main.java

public static float clamp(float value, float min, float max) {
    return Math.min(Math.max(value, min), max);
}

From source file:Main.java

/**
 * Provides a consistent ordering over lists. First compares by the first
 * element. If that element is equal, the next element is considered, and so
 * on.//from  www.  jav  a2 s  . c  o m
 */
public static <T extends Comparable<T>> int compareLists(List<T> list1, List<T> list2) {
    if (list1 == null && list2 == null)
        return 0;
    if (list1 == null || list2 == null) {
        throw new IllegalArgumentException();
    }
    int size1 = list1.size();
    int size2 = list2.size();
    int size = Math.min(size1, size2);
    for (int i = 0; i < size; i++) {
        int c = list1.get(i).compareTo(list2.get(i));
        if (c != 0)
            return c;
    }
    if (size1 < size2)
        return -1;
    if (size1 > size2)
        return 1;
    return 0;
}

From source file:Main.java

public static Bitmap scaleBitmap(Bitmap src, int maxWidth, int maxHeight) {
    if (src == null)
        return null;
    double scaleFactor = Math.min(((double) maxWidth) / src.getWidth(), ((double) maxHeight) / src.getHeight());
    return Bitmap.createScaledBitmap(src, (int) (src.getWidth() * scaleFactor),
            (int) (src.getHeight() * scaleFactor), false);
}

From source file:Main.java

public static int brighter(int color, float factor) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= (1f + factor); // value component
    for (int i = 1; i < hsv.length; i++) {
        hsv[i] = Math.min(1.0f, hsv[i]);
    }//  ww  w  .j ava  2 s .c o m
    color = Color.HSVToColor(hsv);
    return color;
}