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 byte[] copyOfRange(byte[] original, int from, int to) {
    int newLength = to - from;
    if (newLength < 0) {
        throw new IllegalArgumentException(from + " > " + to);
    } else {// w w w . j  a v a2s . co  m
        byte[] copy = new byte[newLength];
        System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
        return copy;
    }
}

From source file:Main.java

public static int darkenColor(int color) {
    float[] hsv = new float[3];
    int alpha = Color.alpha(color);
    Color.colorToHSV(color, hsv);
    hsv[1] = Math.min(hsv[1] * DARKEN_SATURATION, 1.0f);
    hsv[2] = hsv[2] * DARKEN_INTENSITY;/* w w  w . j  a  va 2 s  .c o  m*/
    int tempColor = Color.HSVToColor(hsv);
    return Color.argb(alpha, Color.red(tempColor), Color.green(tempColor), Color.blue(tempColor));
}

From source file:Main.java

public static int darkenColor(int color) {
    float[] hsv = new float[3];
    int alpha = Color.alpha(color);
    Color.colorToHSV(color, hsv);
    hsv[1] = Math.min(hsv[1] * SATURATION_DARKEN, 1.0f);
    hsv[2] = hsv[2] * INTENSITY_DARKEN;//from   w  w  w. j ava  2  s. c  o m
    int tempColor = Color.HSVToColor(hsv);
    return Color.argb(alpha, Color.red(tempColor), Color.green(tempColor), Color.blue(tempColor));
}

From source file:Main.java

/**
 * Expands an array of floats to double its current size.
 *
 * @param f Array to be expanded./* www.  ja va  2  s  .  co  m*/
 * @return Array of floats with f.length*2 length. 
 */
static public float[] resizeArrayFloat(float[] f, int newSize) {
    float[] newf = new float[newSize];
    System.arraycopy(f, 0, newf, 0, Math.min(f.length, newSize));
    return newf;
}

From source file:Main.java

public static Collection<String> splitStringBySize(String str, int size) {
    ArrayList<String> split = new ArrayList<>();
    for (int i = 0; i <= str.length() / size; i++) {
        split.add(str.substring(i * size, Math.min((i + 1) * size, str.length())));
    }/*from  w  w w .j av  a2  s.  co  m*/
    return split;
}

From source file:Main.java

static float getAnimatedFraction(ValueAnimator animator) {
    float fraction = animator.getDuration() > 0L
            ? (float) animator.getCurrentPlayTime() / (float) animator.getDuration()
            : 0.0F;/*from   w w  w .ja  va  2s .co m*/

    fraction = Math.min(fraction, 1.0F);
    fraction = animator.getInterpolator().getInterpolation(fraction);
    return fraction;
}

From source file:Main.java

public static void RGBtoHSL(int r, int g, int b, float[] hsl) {
    final float rf = r / 255f;
    final float gf = g / 255f;
    final float bf = b / 255f;

    final float max = Math.max(rf, Math.max(gf, bf));
    final float min = Math.min(rf, Math.min(gf, bf));
    final float deltaMaxMin = max - min;

    float h, s;/*from w  ww .  j  a  v a 2s  .c o m*/
    float l = (max + min) / 2f;

    if (max == min) {
        // Monochromatic
        h = s = 0f;
    } else {
        if (max == rf) {
            h = ((gf - bf) / deltaMaxMin) % 6f;
        } else if (max == gf) {
            h = ((bf - rf) / deltaMaxMin) + 2f;
        } else {
            h = ((rf - gf) / deltaMaxMin) + 4f;
        }

        s = deltaMaxMin / (1f - Math.abs(2f * l - 1f));
    }

    hsl[0] = (h * 60f) % 360f;
    hsl[1] = s;
    hsl[2] = l;
}

From source file:Main.java

public static List<String> splitOnChars(String text) {
    final int stringSize = 300;
    List<String> strings = new ArrayList<>(text.length() / stringSize + 1);
    int index = 0;
    while (index < text.length()) {
        strings.add(text.substring(index, Math.min(index + stringSize, text.length())));
        index += stringSize;/* w w w  . j av a  2 s  . co m*/
    }
    return strings;
}

From source file:Main.java

public static int getSampleSizeAutoFitToScreen(int vWidth, int vHeight, int bWidth, int bHeight) {
    if (vHeight == 0 || vWidth == 0) {
        return 1;
    }//  w w  w .  java  2  s  . c  o m

    int ratio = Math.max(bWidth / vWidth, bHeight / vHeight);

    int ratioAfterRotate = Math.max(bHeight / vWidth, bWidth / vHeight);

    return Math.min(ratio, ratioAfterRotate);
}

From source file:Main.java

public static int getScreenWidth(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    int width = wm.getDefaultDisplay().getWidth();
    int height = wm.getDefaultDisplay().getHeight();

    return Math.min(width, height);
}