Example usage for java.lang Double MAX_VALUE

List of usage examples for java.lang Double MAX_VALUE

Introduction

In this page you can find the example usage for java.lang Double MAX_VALUE.

Prototype

double MAX_VALUE

To view the source code for java.lang Double MAX_VALUE.

Click Source Link

Document

A constant holding the largest positive finite value of type double , (2-2-52)·21023.

Usage

From source file:Main.java

public static double getMindouble(double[] arr) {
    double min = Double.MAX_VALUE;

    for (int i = 0; i < arr.length; i++) {

        if (arr[i] < min)
            min = arr[i];//  w w  w.  j a  v  a 2  s.c  om
    }

    return min;
}

From source file:Main.java

public static Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int targetHeight) {
    final double MIN_ASPECT_RATIO = 1.0;
    final double MAX_ASPECT_RATIO = 1.5;
    Camera.Size optimalSize = null;//from w  w  w.  j a  v a  2 s  .co m
    double minDiff = Double.MAX_VALUE;
    for (Camera.Size size : sizes) {
        double ratio = (double) size.width / size.height;
        if (ratio <= MIN_ASPECT_RATIO || ratio > MAX_ASPECT_RATIO)
            continue;
        if (Math.abs(size.height - targetHeight) < minDiff) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
        }
    }
    if (optimalSize == null) {
        minDiff = Double.MAX_VALUE;
        for (Camera.Size size : sizes) {
            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }
    }
    return optimalSize;
}

From source file:Main.java

public static double getMindouble(ArrayList<Double> arr) {
    double min = Double.MAX_VALUE;

    for (int i = 0; i < arr.size(); i++) {
        double d = arr.get(i);
        if (d < min)
            min = d;//  w  ww  . j a v  a2 s.c om
    }

    return min;
}

From source file:Main.java

/**
 * Creates a two-element array of default min and max values, typically used to initialize extreme values searches.
 *
 * @return a two-element array of extreme values. Entry 0 is the maximum double value; entry 1 is the negative of
 *         the maximum double value;//from   w  ww.j a  v a2  s .  c  o  m
 */
public static double[] defaultMinMix() {
    return new double[] { Double.MAX_VALUE, -Double.MAX_VALUE };
}

From source file:Main.java

public static Camera.Size getOptimalPreviewSize2(List<Camera.Size> sizes, double targetRatio) {
    final double SMALL_VALUE = 0.001;
    if (sizes == null)
        return null;

    Camera.Size optimalSize = null;/*w  ww. j  ava  2s . c  o  m*/
    double optimalRatio = 0;
    double minRatioDiff = Double.MAX_VALUE;

    // Try to find a size which is close to the targetRatio and has the biggest possible resolution
    for (Camera.Size size : sizes) {
        double ratio = (double) size.width / size.height;
        if (Math.abs(targetRatio - ratio) <= minRatioDiff) {
            if (optimalSize != null && Math.abs(ratio - optimalRatio) < SMALL_VALUE) {
                if (size.width < optimalSize.width)
                    continue;
            }
            optimalSize = size;
            optimalRatio = (double) size.width / size.height;
            minRatioDiff = Math.abs(targetRatio - ratio);
        }
    }
    return optimalSize;
}

From source file:Main.java

/**
 * computes the minimal value of a passed array
 * @param _arr the array to get the minimum from
 * @return a double[] of size 2. the first index holds the minimum value of the passed array,
 * the second index holds the index where the minimum value is in the passed array
 *//*from   w  w  w  .j  ava  2s. co m*/
public static double[] min(double[] _arr) {
    double min = Double.MAX_VALUE;
    double minIdx = -1;

    for (int i = 0; i < _arr.length; i++) {
        if (_arr[i] < min) {
            min = _arr[i];
            minIdx = i;
        }
    }
    return new double[] { min, minIdx };
}

From source file:Main.java

private static Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int w, int h) {
    final double ASPECT_TOLERANCE = 0.05;
    double targetRatio = (double) w / h;

    if (sizes == null) {
        return null;
    }/* w  w  w.ja  v  a 2 s .  c  om*/

    Camera.Size optimalSize = null;

    double minDiff = Double.MAX_VALUE;

    int targetHeight = h;

    // Find size
    for (Camera.Size size : sizes) {
        double ratio = (double) size.width / size.height;
        if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) {
            continue;
        }
        if (Math.abs(size.height - targetHeight) < minDiff) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
        }
    }

    if (optimalSize == null) {
        minDiff = Double.MAX_VALUE;
        for (Camera.Size size : sizes) {
            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }
    }
    return optimalSize;
}

From source file:Main.java

public static Camera.Size getOptimalPreviewSize(int displayOrientation, int width, int height,
        Camera.Parameters parameters) {/*from  www.j  av a 2 s.c  o  m*/
    double targetRatio = (double) width / height;
    List<Camera.Size> sizes = parameters.getSupportedPreviewSizes();
    Camera.Size optimalSize = null;
    double minDiff = Double.MAX_VALUE;
    int targetHeight = height;

    if (displayOrientation == 90 || displayOrientation == 270) {
        targetRatio = (double) height / width;
    }

    // Try to find an size match aspect ratio and size

    for (Camera.Size size : sizes) {
        double ratio = (double) size.width / size.height;

        if (Math.abs(ratio - targetRatio) <= ASPECT_TOLERANCE) {
            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }
    }

    // Cannot find the one match the aspect ratio, ignore
    // the requirement

    if (optimalSize == null) {
        minDiff = Double.MAX_VALUE;

        for (Camera.Size size : sizes) {
            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }
    }

    return (optimalSize);
}

From source file:Main.java

/**
 * calcs the optimal dimension for the camera preview on the display
 * //from   w w  w.  j  a  v a2  s .c  o m
 * @param sizes
 * @param w
 * @param h
 * @return
 */
public static Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
    final double ASPECT_TOLERANCE = 0.1;
    double targetRatio = (double) w / h;
    if (sizes == null)
        return null;

    Size optimalSize = null;
    double minDiff = Double.MAX_VALUE;

    int targetHeight = h;

    // Try to find an size match aspect ratio and size
    for (Size size : sizes) {
        double ratio = (double) size.width / size.height;
        if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
            continue;
        if (Math.abs(size.height - targetHeight) < minDiff) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
        }
    }

    // Cannot find the one match the aspect ratio, ignore the requirement
    if (optimalSize == null) {
        minDiff = Double.MAX_VALUE;
        for (Size size : sizes) {
            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }
    }
    return optimalSize;
}

From source file:Main.java

public static Camera.Size getOptimalPreviewSize(Activity currentActivity, List<Camera.Size> sizes,
        double targetRatio) {
    // Use a very small tolerance because we want an exact match.
    final double ASPECT_TOLERANCE = 0.001;
    if (sizes == null)
        return null;

    Camera.Size optimalSize = null;/*  w w w . j a  v  a2 s  .c om*/
    double minDiff = Double.MAX_VALUE;

    // Because of bugs of overlay and layout, we sometimes will try to
    // layout the viewfinder in the portrait orientation and thus get the
    // wrong size of preview surface. When we change the preview size, the
    // new overlay will be created before the old one closed, which causes
    // an exception. For now, just get the screen size.
    Point point = getDefaultDisplaySize(currentActivity, new Point());
    int targetHeight = Math.min(point.x, point.y);
    // Try to find an size match aspect ratio and size
    for (Camera.Size size : sizes) {
        double ratio = (double) size.width / size.height;
        if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
            continue;
        if (Math.abs(size.height - targetHeight) < minDiff) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
        }
    }
    // Cannot find the one match the aspect ratio. This should not happen.
    // Ignore the requirement.
    if (optimalSize == null) {
        minDiff = Double.MAX_VALUE;
        for (Camera.Size size : sizes) {
            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }
    }
    return optimalSize;
}