Example usage for java.lang Math max

List of usage examples for java.lang Math max

Introduction

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

Prototype

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

Source Link

Document

Returns the greater of two double values.

Usage

From source file:com.gordoni.opal.TriInterpolator.java

public double value(double[] p) {
    double x = p[0];
    x = Math.max(x, mp.floor[0]);
    x = Math.min(x, mp.ceiling[0]);
    double y = p[1];
    y = Math.max(y, mp.floor[1]);
    y = Math.min(y, mp.ceiling[1]);
    double z = p[2];
    z = Math.max(z, mp.floor[2]);
    z = Math.min(z, mp.ceiling[2]);
    double v = f.value(x, y, z);
    int xindex = Arrays.binarySearch(xval, x);
    if (xindex < 0)
        xindex = -xindex - 2;// w w  w .  j a  v a  2  s .co m
    int yindex = Arrays.binarySearch(yval, y);
    if (yindex < 0)
        yindex = -yindex - 2;
    int zindex = Arrays.binarySearch(zval, z);
    if (zindex < 0)
        zindex = -zindex - 2;
    double fmin = fval[xindex][yindex][zindex];
    double fmax = fval[xindex][yindex][zindex];
    if (xindex + 1 < xval.length) {
        fmin = Math.min(fmin, fval[xindex + 1][yindex][zindex]);
        fmax = Math.max(fmax, fval[xindex + 1][yindex][zindex]);
    }
    if (yindex + 1 < yval.length) {
        fmin = Math.min(fmin, fval[xindex][yindex + 1][zindex]);
        fmax = Math.max(fmax, fval[xindex][yindex + 1][zindex]);
    }
    if (zindex + 1 < zval.length) {
        fmin = Math.min(fmin, fval[xindex][yindex][zindex + 1]);
        fmax = Math.max(fmax, fval[xindex][yindex][zindex + 1]);
    }
    if (xindex + 1 < xval.length && yindex + 1 < yval.length) {
        fmin = Math.min(fmin, fval[xindex + 1][yindex + 1][zindex]);
        fmax = Math.max(fmax, fval[xindex + 1][yindex + 1][zindex]);
    }
    if (xindex + 1 < xval.length && zindex + 1 < zval.length) {
        fmin = Math.min(fmin, fval[xindex + 1][yindex][zindex + 1]);
        fmax = Math.max(fmax, fval[xindex + 1][yindex][zindex + 1]);
    }
    if (yindex + 1 < yval.length && zindex + 1 < zval.length) {
        fmin = Math.min(fmin, fval[xindex][yindex + 1][zindex + 1]);
        fmax = Math.max(fmax, fval[xindex][yindex + 1][zindex + 1]);
    }
    if (xindex + 1 < xval.length && yindex + 1 < yval.length && zindex + 1 < zval.length) {
        fmin = Math.min(fmin, fval[xindex + 1][yindex + 1][zindex + 1]);
        fmax = Math.max(fmax, fval[xindex + 1][yindex + 1][zindex + 1]);
    }
    v = Math.max(v, fmin);
    v = Math.min(v, fmax);
    return v;
}

From source file:org.openmeetings.test.poll.TestPollManagement.java

@Test
public void addPollType() {
    long maxId = 1;
    for (PollType pt : pollManagement.getPollTypes()) {
        maxId = Math.max(maxId, pt.getPollTypesId());
    }//from   w  w w  .  j av  a 2 s.  co m
    assertNotNull("Poll created is null", pollManagement.addPollType(26L, false));
}

From source file:Main.java

/**
 * Positions the specified dialog at a position relative to its parent.
 *
 * @param dialog            the dialog to be positioned.
 * @param horizontalPercent the relative location.
 * @param verticalPercent   the relative location.
 *//*from  w ww.j a v  a 2s. c  o  m*/
public static void positionDialogRelativeToParent(final Dialog dialog, final double horizontalPercent,
        final double verticalPercent) {
    final Container parent = dialog.getParent();
    if (parent == null || (parent.isVisible() == false)) {
        positionFrameOnScreen(dialog, horizontalPercent, verticalPercent);
        return;
    }

    final Dimension d = dialog.getSize();
    final Dimension p = parent.getSize();

    final int baseX = parent.getX();
    final int baseY = parent.getY();

    final int parentPointX = baseX + (int) (horizontalPercent * p.width);
    final int parentPointY = baseY + (int) (verticalPercent * p.height);

    final int dialogPointX = Math.max(0, parentPointX - (int) (horizontalPercent * d.width));
    final int dialogPointY = Math.max(0, parentPointY - (int) (verticalPercent * d.height));

    // make sure the dialog fits completely on the screen...
    final Rectangle s = parent.getGraphicsConfiguration().getBounds();
    final Rectangle r = new Rectangle(dialogPointX, dialogPointY, d.width, d.height);
    final Rectangle intersectedDialogBounds = r.intersection(s);
    if (intersectedDialogBounds.width < d.width) {
        r.x = s.width - d.width;
        r.width = d.width;
    }
    if (intersectedDialogBounds.height < d.height) {
        r.y = s.height - d.height;
        r.height = d.height;
    }
    final Rectangle finalIntersection = r.intersection(s);
    dialog.setBounds(finalIntersection);
}

From source file:eu.geopaparazzi.library.routing.osmbonuspack.BonusPackHelper.java

/** @return the BoundingBox enclosing bb1 and bb2 BoundingBoxes */
public static BoundingBoxE6 concatBoundingBoxE6(BoundingBoxE6 bb1, BoundingBoxE6 bb2) {
    return new BoundingBoxE6(Math.max(bb1.getLatNorthE6(), bb2.getLatNorthE6()),
            Math.max(bb1.getLonEastE6(), bb2.getLonEastE6()),
            Math.min(bb1.getLatSouthE6(), bb2.getLatSouthE6()),
            Math.min(bb1.getLonWestE6(), bb2.getLonWestE6()));
}

From source file:Main.java

@Override
public void moveDot(NavigationFilter.FilterBypass fb, int dot, Position.Bias bias) {
    fb.moveDot(Math.max(dot, prefixLength), bias);
}

From source file:Main.java

/**
 *  Convert HSL values to a RGB Color./*from   w w w. j  av  a2  s  .co  m*/
 *
 *  @param h Hue is specified as degrees in the range 0 - 360.
 *  @param s Saturation is specified as a percentage in the range 1 - 100.
 *  @param l Lumanance is specified as a percentage in the range 1 - 100.
 */
private static int hslToRGB(int hInt, int sInt, int lInt) {
    float h, s, l;

    h = (float) hInt;
    s = (float) sInt;
    l = (float) lInt;

    if (s < 0.0f || s > 100.0f) {
        String message = "Color parameter outside of expected range - Saturation";
        throw new IllegalArgumentException(message);
    }

    if (l < 0.0f || l > 100.0f) {
        String message = "Color parameter outside of expected range - Luminance";
        throw new IllegalArgumentException(message);
    }

    //  Formula needs all values between 0 - 1.

    h = h % 360.0f;
    h /= 360f;
    s /= 100f;
    l /= 100f;

    float q = 0;

    if (l < 0.5)
        q = l * (1 + s);
    else
        q = (l + s) - (s * l);

    float p = 2 * l - q;

    int r = (int) (Math.max(0, HUEtoRGB(p, q, h + (1.0f / 3.0f))) * 255);
    int g = (int) (Math.max(0, HUEtoRGB(p, q, h)) * 255);
    int b = (int) (Math.max(0, HUEtoRGB(p, q, h - (1.0f / 3.0f))) * 255);

    return Color.rgb(r, g, b);
}

From source file:com.google.pubsub.flic.common.LatencyDistribution.java

public static double getNthPercentileUpperBound(long[] bucketValues, double percentile) {
    return LATENCY_BUCKETS[Math.max(0, getNthPercentileIndex(bucketValues, percentile))];
}

From source file:Main.java

public static Bitmap fastblur(Bitmap sentBitmap, int radius) {

    // Stack Blur v1.0 from
    // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
    // Java Author: Mario Klingemann <mario at quasimondo.com>
    // http://incubator.quasimondo.com

    // created Feburary 29, 2004
    // Android port : Yahel Bouaziz <yahel at kayenko.com>
    // http://www.kayenko.com
    // ported april 5th, 2012

    // This is a compromise between Gaussian Blur and Box blur
    // It creates much better looking blurs than Box Blur, but is
    // 7x faster than my Gaussian Blur implementation.

    // I called it Stack Blur because this describes best how this
    // filter works internally: it creates a kind of moving stack
    // of colors whilst scanning through the image. Thereby it
    // just has to add one new block of color to the right side
    // of the stack and remove the leftmost color. The remaining
    // colors on the topmost layer of the stack are either added on
    // or reduced by one, depending on if they are on the right or
    // on the left side of the stack.

    // If you are using this algorithm in your code please add
    // the following line:
    // Stack Blur Algorithm by Mario Klingemann <mario@quasimondo.com>

    Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);

    if (radius < 1) {
        return (null);
    }/*from   w  ww.  j a  va  2 s  .  c  o  m*/

    int w = bitmap.getWidth();
    int h = bitmap.getHeight();

    int[] pix = new int[w * h];

    bitmap.getPixels(pix, 0, w, 0, 0, w, h);

    int wm = w - 1;
    int hm = h - 1;
    int wh = w * h;
    int div = radius + radius + 1;

    int r[] = new int[wh];
    int g[] = new int[wh];
    int b[] = new int[wh];
    int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
    int vmin[] = new int[Math.max(w, h)];

    int divsum = (div + 1) >> 1;
    divsum *= divsum;
    int dv[] = new int[256 * divsum];
    for (i = 0; i < 256 * divsum; i++) {
        dv[i] = (i / divsum);
    }

    yw = yi = 0;

    int[][] stack = new int[div][3];
    int stackpointer;
    int stackstart;
    int[] sir;
    int rbs;
    int r1 = radius + 1;
    int routsum, goutsum, boutsum;
    int rinsum, ginsum, binsum;

    for (y = 0; y < h; y++) {
        rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
        for (i = -radius; i <= radius; i++) {
            p = pix[yi + Math.min(wm, Math.max(i, 0))];
            sir = stack[i + radius];
            sir[0] = (p & 0xff0000) >> 16;
            sir[1] = (p & 0x00ff00) >> 8;
            sir[2] = (p & 0x0000ff);
            rbs = r1 - Math.abs(i);
            rsum += sir[0] * rbs;
            gsum += sir[1] * rbs;
            bsum += sir[2] * rbs;
            if (i > 0) {
                rinsum += sir[0];
                ginsum += sir[1];
                binsum += sir[2];
            } else {
                routsum += sir[0];
                goutsum += sir[1];
                boutsum += sir[2];
            }
        }
        stackpointer = radius;

        for (x = 0; x < w; x++) {

            r[yi] = dv[rsum];
            g[yi] = dv[gsum];
            b[yi] = dv[bsum];

            rsum -= routsum;
            gsum -= goutsum;
            bsum -= boutsum;

            stackstart = stackpointer - radius + div;
            sir = stack[stackstart % div];

            routsum -= sir[0];
            goutsum -= sir[1];
            boutsum -= sir[2];

            if (y == 0) {
                vmin[x] = Math.min(x + radius + 1, wm);
            }
            p = pix[yw + vmin[x]];

            sir[0] = (p & 0xff0000) >> 16;
            sir[1] = (p & 0x00ff00) >> 8;
            sir[2] = (p & 0x0000ff);

            rinsum += sir[0];
            ginsum += sir[1];
            binsum += sir[2];

            rsum += rinsum;
            gsum += ginsum;
            bsum += binsum;

            stackpointer = (stackpointer + 1) % div;
            sir = stack[(stackpointer) % div];

            routsum += sir[0];
            goutsum += sir[1];
            boutsum += sir[2];

            rinsum -= sir[0];
            ginsum -= sir[1];
            binsum -= sir[2];

            yi++;
        }
        yw += w;
    }
    for (x = 0; x < w; x++) {
        rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
        yp = -radius * w;
        for (i = -radius; i <= radius; i++) {
            yi = Math.max(0, yp) + x;

            sir = stack[i + radius];

            sir[0] = r[yi];
            sir[1] = g[yi];
            sir[2] = b[yi];

            rbs = r1 - Math.abs(i);

            rsum += r[yi] * rbs;
            gsum += g[yi] * rbs;
            bsum += b[yi] * rbs;

            if (i > 0) {
                rinsum += sir[0];
                ginsum += sir[1];
                binsum += sir[2];
            } else {
                routsum += sir[0];
                goutsum += sir[1];
                boutsum += sir[2];
            }

            if (i < hm) {
                yp += w;
            }
        }
        yi = x;
        stackpointer = radius;
        for (y = 0; y < h; y++) {
            // Preserve alpha channel: ( 0xff000000 & pix[yi] )
            pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];

            rsum -= routsum;
            gsum -= goutsum;
            bsum -= boutsum;

            stackstart = stackpointer - radius + div;
            sir = stack[stackstart % div];

            routsum -= sir[0];
            goutsum -= sir[1];
            boutsum -= sir[2];

            if (x == 0) {
                vmin[y] = Math.min(y + r1, hm) * w;
            }
            p = x + vmin[y];

            sir[0] = r[p];
            sir[1] = g[p];
            sir[2] = b[p];

            rinsum += sir[0];
            ginsum += sir[1];
            binsum += sir[2];

            rsum += rinsum;
            gsum += ginsum;
            bsum += binsum;

            stackpointer = (stackpointer + 1) % div;
            sir = stack[stackpointer];

            routsum += sir[0];
            goutsum += sir[1];
            boutsum += sir[2];

            rinsum -= sir[0];
            ginsum -= sir[1];
            binsum -= sir[2];

            yi += w;
        }
    }

    bitmap.setPixels(pix, 0, w, 0, 0, w, h);

    return (bitmap);
}

From source file:Main.java

public static Bitmap decodeFile(File theFile, int IMAGE_MAX_SIZE) {
    Bitmap bmp = null;/*from w w  w. j a va 2 s  .com*/
    try {
        // Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;

        FileInputStream fis = new FileInputStream(theFile);
        BitmapFactory.decodeStream(fis, null, o);
        fis.close();

        int scale = 1;
        if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
            scale = (int) Math.pow(2, (int) Math.round(
                    Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
        }

        // Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        fis = new FileInputStream(theFile);
        bmp = BitmapFactory.decodeStream(fis, null, o2);

        fis.close();
    } catch (IOException e) {
    }
    return bmp;
}

From source file:com.addthis.bundle.value.DefaultLong.java

@Override
public ValueLong avg(int count) {
    return new DefaultLong(value / Math.max(count, 1));
}