Example usage for java.lang Double isInfinite

List of usage examples for java.lang Double isInfinite

Introduction

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

Prototype

public static boolean isInfinite(double v) 

Source Link

Document

Returns true if the specified number is infinitely large in magnitude, false otherwise.

Usage

From source file:com.bazaarvoice.jackson.rison.RisonGenerator.java

@Override
public void writeNumber(double d) throws IOException, JsonGenerationException {
    if (_cfgNumbersAsStrings ||
    // [JACKSON-139]
            (((Double.isNaN(d) || Double.isInfinite(d))
                    && isEnabled(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS)))) {
        writeString(Double.toString(d));
        return;/*from w  w  w. ja v  a2s. c o m*/
    }
    // What is the max length for doubles? 40 chars?
    _verifyValueWrite("write number");
    _writeRaw(formatDouble(d));
}

From source file:org.jfree.data.time.TimeSeries.java

/**
 * Finds the range of y-values that fall within the specified range of
 * x-values (where the x-values are interpreted as milliseconds since the
 * epoch and converted to time periods using the specified timezone).
 * //from w w w . j a  v a  2  s  .  co  m
 * @param xRange  the subset of x-values to use (<code>null</code> not
 *     permitted).
 * @param xAnchor  the anchor point for the x-values (<code>null</code>
 *     not permitted).
 * @param zone  the time zone (<code>null</code> not permitted).
 * 
 * @return The range of y-values.
 * 
 * @since 1.0.18
 */
public Range findValueRange(Range xRange, TimePeriodAnchor xAnchor, TimeZone zone) {
    ParamChecks.nullNotPermitted(xRange, "xRange");
    ParamChecks.nullNotPermitted(xAnchor, "xAnchor");
    ParamChecks.nullNotPermitted(zone, "zone");
    if (this.data.isEmpty()) {
        return null;
    }
    Calendar calendar = Calendar.getInstance(zone);
    // since the items are ordered, we could be more clever here and avoid
    // iterating over all the data
    double lowY = Double.POSITIVE_INFINITY;
    double highY = Double.NEGATIVE_INFINITY;
    for (int i = 0; i < this.data.size(); i++) {
        TimeSeriesDataItem item = (TimeSeriesDataItem) this.data.get(i);
        long millis = item.getPeriod().getMillisecond(xAnchor, calendar);
        if (xRange.contains(millis)) {
            Number n = item.getValue();
            if (n != null) {
                double v = n.doubleValue();
                lowY = Math.min(lowY, v);
                highY = Math.max(highY, v);
            }
        }
    }
    if (Double.isInfinite(lowY) && Double.isInfinite(highY)) {
        if (lowY < highY) {
            return new Range(lowY, highY);
        } else {
            return new Range(Double.NaN, Double.NaN);
        }
    }
    return new Range(lowY, highY);
}

From source file:org.broadinstitute.gatk.engine.recalibration.RecalDatum.java

static protected double log10QempLikelihood(final double Qempirical, long nObservations, long nErrors) {
    if (nObservations == 0)
        return 0.0;

    // the binomial code requires ints as input (because it does caching).  This should theoretically be fine because
    // there is plenty of precision in 2^31 observations, but we need to make sure that we don't have overflow
    // before casting down to an int.
    if (nObservations > MAX_NUMBER_OF_OBSERVATIONS) {
        // we need to decrease nErrors by the same fraction that we are decreasing nObservations
        final double fraction = (double) MAX_NUMBER_OF_OBSERVATIONS / (double) nObservations;
        nErrors = Math.round((double) nErrors * fraction);
        nObservations = MAX_NUMBER_OF_OBSERVATIONS;
    }/*from  w w w . jav  a 2s.  co m*/

    // this is just a straight binomial PDF
    double log10Prob = MathUtils.log10BinomialProbability((int) nObservations, (int) nErrors,
            QualityUtils.qualToErrorProbLog10(Qempirical));
    if (Double.isInfinite(log10Prob) || Double.isNaN(log10Prob))
        log10Prob = -Double.MAX_VALUE;

    //if ( DEBUG )
    //    System.out.println(String.format("Qemp = %f, log10Likelihood = %f", Qempirical, log10Prob));

    return log10Prob;
}

From source file:com.jskaleel.xml.JSONObject.java

/**
 * Produce a string from a double. The string "null" will be returned if the
 * number is not finite.//w ww .j a  va  2s. c  om
 *
 * @param d
 *            A double.
 * @return A String.
 */
public static String doubleToString(double d) {
    if (Double.isInfinite(d) || Double.isNaN(d)) {
        return "null";
    }

    // Shave off trailing zeros and decimal point, if possible.

    String string = Double.toString(d);
    if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) {
        while (string.endsWith("0")) {
            string = string.substring(0, string.length() - 1);
        }
        if (string.endsWith(".")) {
            string = string.substring(0, string.length() - 1);
        }
    }
    return string;
}

From source file:geogebra.common.kernel.implicit.GeoImplicitPoly.java

/**
 * @param c assigns given coefficient-array to be the coefficients of this Polynomial.
 * @param calcPath : the path should be calculated "new".
 *//*from  ww  w.  j  a v a  2s  .c o m*/
public void setCoeff(double[][] c, boolean calcPath) {
    isConstant = true;
    degX = -1;
    degY = -1;
    coeffSquarefree = null;
    degX = c.length - 1;
    coeff = new double[c.length][];
    for (int i = 0; i < c.length; i++) {
        coeff[i] = new double[c[i].length];
        if (c[i].length > degY + 1)
            degY = c[i].length - 1;
        for (int j = 0; j < c[i].length; j++) {
            coeff[i][j] = c[i][j];
            if (Double.isInfinite(coeff[i][j])) {
                setUndefined();
            }
            isConstant = isConstant && (c[i][j] == 0 || (i == 0 && j == 0));
        }
    }
    if (calcPath && this.calcPath)
        updatePath();
}

From source file:net.sourceforge.processdash.ui.web.reports.RadarPlot.java

protected void drawRadar(Graphics2D g2, Rectangle2D plotArea, PlotRenderingInfo info, int pieIndex,
        PieDataset data) {//from ww w  .j a va  2 s. c  o m

    // adjust the plot area by the interior spacing value
    double gapHorizontal = plotArea.getWidth() * this.interiorGap;
    double gapVertical = plotArea.getHeight() * this.interiorGap;
    double radarX = plotArea.getX() + gapHorizontal / 2;
    double radarY = plotArea.getY() + gapVertical / 2;
    double radarW = plotArea.getWidth() - gapHorizontal;
    double radarH = plotArea.getHeight() - gapVertical;

    // make the radar area a square if the radar chart is to be circular...
    // NOTE that non-circular radar charts are not currently supported.
    if (true) { //circular) {
        double min = Math.min(radarW, radarH) / 2;
        radarX = (radarX + radarX + radarW) / 2 - min;
        radarY = (radarY + radarY + radarH) / 2 - min;
        radarW = 2 * min;
        radarH = 2 * min;
    }

    double radius = radarW / 2;
    double centerX = radarX + radarW / 2;
    double centerY = radarY + radarH / 2;

    Rectangle2D radarArea = new Rectangle2D.Double(radarX, radarY, radarW, radarH);

    // plot the data (unless the dataset is null)...
    if ((data != null) && (data.getKeys().size() > 0)) {

        // get a list of categories...
        List keys = data.getKeys();
        int numAxes = keys.size();

        // draw each of the axes on the radar chart, and register
        // the shape of the radar line.

        double multiplier = 1.0;
        GeneralPath lineShape = new GeneralPath(GeneralPath.WIND_NON_ZERO, numAxes + 1);
        GeneralPath gridShape = new GeneralPath(GeneralPath.WIND_NON_ZERO, numAxes + 1);

        int axisNumber = -1;
        Iterator iterator = keys.iterator();
        while (iterator.hasNext()) {
            Comparable currentKey = (Comparable) iterator.next();
            axisNumber++;
            Number dataValue = data.getValue(currentKey);

            double value = (dataValue != null ? dataValue.doubleValue() : 0);
            if (value > 1 || Double.isNaN(value) || Double.isInfinite(value))
                value = 1.0;
            if (value < 0)
                value = 0.0;
            multiplier *= value;

            double angle = 2 * Math.PI * axisNumber / numAxes;
            double deltaX = Math.sin(angle) * radius;
            double deltaY = -Math.cos(angle) * radius;

            // draw the spoke
            g2.setPaint(axisPaint);
            g2.setStroke(axisStroke);
            Line2D line = new Line2D.Double(centerX, centerY, centerX + deltaX, centerY + deltaY);
            g2.draw(line);

            // register the grid line and the shape line
            if (axisNumber == 0) {
                gridShape.moveTo((float) deltaX, (float) deltaY);
                lineShape.moveTo((float) (deltaX * value), (float) (deltaY * value));
            } else {
                gridShape.lineTo((float) deltaX, (float) deltaY);
                lineShape.lineTo((float) (deltaX * value), (float) (deltaY * value));
            }

            if (showAxisLabels) {
                // draw the label
                double labelX = centerX + deltaX * (1 + axisLabelGap);
                double labelY = centerY + deltaY * (1 + axisLabelGap);
                String label = currentKey.toString();
                drawLabel(g2, radarArea, label, axisNumber, labelX, labelY);
            }

        }
        gridShape.closePath();
        lineShape.closePath();

        // draw five gray concentric gridlines
        g2.translate(centerX, centerY);
        g2.setPaint(gridLinePaint);
        g2.setStroke(gridLineStroke);
        for (int i = 5; i > 0; i--) {
            Shape scaledGrid = gridShape
                    .createTransformedShape(AffineTransform.getScaleInstance(i / 5.0, i / 5.0));
            g2.draw(scaledGrid);
        }

        // get the color for the plot shape.
        Paint dataPaint = plotLinePaint;
        if (dataPaint == ADAPTIVE_COLORING) {
            //multiplier = Math.exp(Math.log(multiplier) * 2 / numAxes);
            dataPaint = getMultiplierColor((float) multiplier);
        }

        // compute a slightly transparent version of the plot color for
        // the fill.
        Paint dataFill = null;
        if (dataPaint instanceof Color && getForegroundAlpha() != 1.0)
            dataFill = new Color(((Color) dataPaint).getRed() / 255f, ((Color) dataPaint).getGreen() / 255f,
                    ((Color) dataPaint).getBlue() / 255f, getForegroundAlpha());
        else
            dataFill = dataPaint;

        // draw the plot shape.  First fill with a parially
        // transparent color, then stroke with the opaque color.
        g2.setPaint(dataFill);
        g2.fill(lineShape);
        g2.setPaint(dataPaint);
        g2.setStroke(plotLineStroke);
        g2.draw(lineShape);

        // cleanup the graphics context.
        g2.translate(-centerX, -centerY);
    }
}

From source file:org.jtrfp.trcl.Tunnel.java

/**
 * Tunnel items: FANBODY.BIN - fan IRIS.BIN - animated iris BEAM.BIN /
 * PIPE.BIN JAW1.BIN (right) JAW2.BIN (left) - jaws ELECTRI[0-3].RAW - force
 * field TP1.RAW - good enough for blastable door?
 * // w  w  w  .java 2 s  .  c  o  m
 * @throws IOException
 * @throws FileLoadException
 * 
 * 
 */

private void installObstacles(Segment s, ColorPaletteVectorList tunnelColorPalette,
        ColorPaletteVectorList ESTuTvPalette, TextureDescription[] tunnelTexturePalette, Vector3D heading,
        Vector3D top, Vector3D wPos, double width, double height, TR tr)
        throws IllegalAccessException, FileLoadException, IOException {
    final ColorPaletteVectorList palette = tr.getGlobalPaletteVL();
    Obstacle obs = s.getObstacle();
    WorldObject wo;
    Model m;
    switch (obs) {
    case none0:
        break;
    case doorway: {
        m = Model.buildCube(tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, .5, .5, 1, 1, tr);
        wo = new WorldObject(tr, m);
        wo.setPosition(wPos.toArray());
        wo.setHeading(heading);
        wo.setTop(top);
        add(wo);
        break;
    }
    case closedDoor: {
        BarrierCube bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, .5, .5, 0, 1, false);
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.addBehavior(new DamageableBehavior().setHealth(4096));
        bc.addBehavior(new ExplodesOnDeath(ExplosionType.Blast));
        bc.addBehavior(new DeathBehavior());
        bc.addBehavior(new DebrisOnDeathBehavior());
        bc.addBehavior(new DestructibleWallBehavior());
        bc.setTop(top);
        add(bc);
        break;
    }
    case blownOpenDoor://TODO: This is not displaying alpha
        BarrierCube bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, .5, .5, 1, 1, true);
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        add(bc);
        break;
    case movingWallLeft: {
        Vector3D endPos = wPos.add(heading.crossProduct(top).scalarMultiply(tunnelDia));
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false);
        bc.addBehavior(new ShiftingObjectBehavior(3000, wPos, endPos));
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    }
    case movingWallRight: {
        Vector3D endPos = wPos.subtract(heading.crossProduct(top).scalarMultiply(tunnelDia));
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false);
        bc.addBehavior(new ShiftingObjectBehavior(3000, wPos, endPos));
        bc.addBehavior(new CubeCollisionBehavior(bc));
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    }
    case movingWallDown: {
        Vector3D endPos = wPos.subtract(top.scalarMultiply(tunnelDia));
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false);
        bc.addBehavior(new ShiftingObjectBehavior(3000, wPos, endPos));
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    }
    case movingWallUp: {
        Vector3D endPos = wPos.add(top.scalarMultiply(tunnelDia));
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false);
        bc.addBehavior(new ShiftingObjectBehavior(3000, wPos, endPos));
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    }
    case wallLeftSTUB:
    case wallLeft:
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { 0., tunnelDia / 2., 0 },
                false);
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    case wallRightSTUB:
    case wallRight:
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia, tunnelDia / 2., 0 }, false);
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    case wallDownSTUB:
    case wallDown:
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false);
        bc.setPosition((wPos.subtract(top.scalarMultiply(tunnelDia / 2))).toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    case wallUpSTUB:
    case wallUp:
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false);
        bc.setPosition((wPos.add(top.scalarMultiply(tunnelDia / 2))).toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    case rotatingHalfWall: {
        final double rotPeriod = 32768. / (double) s.getRotationSpeed();
        final boolean rotate = !Double.isInfinite(rotPeriod);

        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { 0, tunnelDia / 2., 0 },
                false);
        if (rotate) {
            bc.addBehavior(new RotatingObjectBehavior(heading, heading, top, (int) (rotPeriod * 1000.), 0));
            bc.setTop(top);
        } else
            bc.setTop(new Rotation(heading, Math.PI + Math.PI / 2).applyTo(top));
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    }
    case rotating34Wall: {
        final double rotPeriod = 32768. / (double) s.getRotationSpeed();
        final boolean rotate = !Double.isInfinite(rotPeriod);
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { 0, tunnelDia / 2., 10 },
                false);
        if (rotate) {
            bc.addBehavior(
                    new RotatingObjectBehavior(heading, heading, top, (int) (rotPeriod * 1000.), Math.PI));
            bc.setTop(top);
        } else
            bc.setTop(new Rotation(heading, Math.PI + Math.PI / 2).applyTo(top));
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);

        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { 0, tunnelDia / 2., 0 },
                false);
        if (rotate) {
            bc.addBehavior(new RotatingObjectBehavior(heading, heading, top, (int) (rotPeriod * 1000.),
                    Math.PI + Math.PI / 2));
            bc.setTop(top);
        } else
            bc.setTop(new Rotation(heading, Math.PI * 2).applyTo(top));

        bc.setPosition((wPos.add(new Vector3D(100, 0, 0))).toArray());
        bc.setHeading(heading);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    }
    case fan:
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("BLADE.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 28, false, palette, ESTuTvPalette));
        wo.setPosition(wPos.toArray());
        wo.setHeading(heading);
        wo.setTop(top);
        wo.addBehavior(new CubeCollisionBehavior(wo));
        wo.addBehavior(new RotatingObjectBehavior(heading, heading, top, 6000, Math.random() * 2 * Math.PI));
        add(wo);
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("FANBODY.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 28, false, palette, null));//No ESTuTv for fan for now.
        wo.setPosition(wPos.toArray());
        wo.setHeading(heading);
        wo.setTop(top);
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        break;
    case jawsVertical:
        // Up jaw
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("JAW2.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette));
        wo.addBehavior(new ShiftingObjectBehavior(3000, wPos, wPos.add(top.scalarMultiply(tunnelDia / 2))));
        wo.addBehavior(new CubeCollisionBehavior(wo));
        wo.setPosition(wPos.toArray());
        wo.setHeading(heading);
        wo.setTop(heading.crossProduct(top).negate());
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        // Down jaw
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("JAW1.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette));
        wo.addBehavior(
                new ShiftingObjectBehavior(3000, wPos, wPos.subtract(top.scalarMultiply(tunnelDia / 2))));
        wo.setPosition(wPos.toArray());
        wo.setHeading(heading);
        wo.setTop(heading.crossProduct(top).negate());
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        break;
    case jawsHorizontal:
        // Left jaw
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("JAW2.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette));
        wo.addBehavior(new ShiftingObjectBehavior(3000, wPos,
                wPos.add(heading.crossProduct(top).scalarMultiply(tunnelDia / 2))));
        wo.setPosition(wPos.toArray());
        wo.setHeading(heading);
        wo.setTop(top);
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        // Right jaw
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("JAW1.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette));
        wo.addBehavior(new ShiftingObjectBehavior(3000, wPos,
                wPos.subtract(heading.crossProduct(top).scalarMultiply(tunnelDia / 2))));
        wo.setPosition(wPos.toArray());
        wo.setHeading(heading);
        wo.setTop(top);
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        break;
    case metalBeamUp:
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("BEAM.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette));
        wo.setPosition(wPos.add(new Vector3D(0, tunnelDia / 6, 0)).toArray());
        wo.setHeading(heading);
        wo.setTop(top);
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        break;
    case metalBeamDown:
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("BEAM.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette));
        wo.setPosition(wPos.add(new Vector3D(0, -tunnelDia / 6, 0)).toArray());
        wo.setHeading(heading);
        wo.setTop(top);
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        break;
    case metalBeamLeft:
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("BEAM.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette));
        wo.setPosition(wPos.add(new Vector3D(-tunnelDia / 6, 0, 0)).toArray());
        wo.setHeading(heading);
        wo.setTop(top.crossProduct(heading));
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        break;
    case metalBeamRight:
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("BEAM.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette));
        wo.setPosition(wPos.add(new Vector3D(tunnelDia / 6, 0, 0)).toArray());
        wo.setHeading(heading);
        wo.setTop(top.crossProduct(heading));
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        break;
    case forceField: {
        //ELECTRI[0-3].RAW 
        final ForceField ff = new ForceField(tr, (int) tunnelDia, (int) wallThickness);
        ff.setPosition(wPos.toArray());
        ff.setHeading(heading);
        ff.setTop(top);
        add(ff);
        break;
    }
    // Invisible walls, as far as I know, are never used.
    // This makes sense: There is nothing fun about trying to get through a
    // tunnel and crashing into invisible walls.
    case invisibleWallUp:// TODO
        break;
    case invisibleWallDown:// TODO
        break;
    case invisibleWallLeft:// TODO
        break;
    case invisibleWallRight:// TODO
        break;
    case iris: {
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("IRIS.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 4 * 256, false, palette, ESTuTvPalette));
        final Model mod = wo.getModel();
        wo.addBehavior(new IrisBehavior(new Sequencer(mod.getFrameDelayInMillis(), 2, true), width));
        wo.setPosition(wPos.toArray());
        wo.setHeading(heading);
        wo.setTop(top);
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        break;
    }
    }// end switch(obstruction)
}

From source file:com.itemanalysis.psychometrics.cmh.CochranMantelHaenszel.java

/**
 * This method provides the results in a form that can be inserted into
 * a database table./*  w w  w.j  a  v  a2s  . co m*/
 *
 * @return
 */
public String getDatabaseString() {
    String output = "";
    ChiSquaredDistribution chiSquare = new ChiSquaredDistribution(1.0);

    double cmh = cochranMantelHaenszel();
    Double pvalue = 1.0;
    pvalue = 1.0 - chiSquare.cumulativeProbability(cmh);

    double commonOddsRatio = 0.0;
    double[] tempConfInt = { 0.0, 0.0 };
    double[] confInt = { 0.0, 0.0 };
    double smd = 0.0;
    double effectSize = 0.0;
    String etsClass = "";

    if (itemVariable.getType().getItemType() == ItemType.BINARY_ITEM) {
        commonOddsRatio = commonOddsRatio();
        tempConfInt = commonOddsRatioConfidenceInterval(commonOddsRatio);
        if (etsDelta) {
            effectSize = etsDelta(commonOddsRatio);
            confInt[0] = etsDelta(tempConfInt[0]);
            confInt[1] = etsDelta(tempConfInt[1]);
        } else {
            effectSize = commonOddsRatio;
            confInt[0] = tempConfInt[0];
            confInt[1] = tempConfInt[1];
        }
        etsClass = etsBinayClassification(cmh, pvalue, commonOddsRatio);
    } else if (itemVariable.getType().getItemType() == ItemType.POLYTOMOUS_ITEM) {
        smd = pF();
        tempConfInt = smdConfidenceInterval(smd);
        confInt[0] = tempConfInt[0];
        confInt[1] = tempConfInt[1];
        effectSize = pF();
        etsClass = smdDifClass();
    }

    output += itemVariable.getName().toString() + ",";

    if (Double.isNaN(cmh)) {
        output += ",";
    } else {
        output += cmh + ",";
    }
    if (Double.isNaN(pvalue)) {
        output += ",";
    } else {
        output += pvalue + ",";
    }

    output += validSampleSize + ",";

    if (Double.isNaN(effectSize) || Double.isInfinite(cmh)) {
        output += ",";
    } else {
        output += effectSize + ",";
    }

    if (Double.isNaN(confInt[0]) || Double.isInfinite(cmh)) {
        output += ",";
    } else {
        output += confInt[0] + ",";
    }

    if (Double.isNaN(confInt[1]) || Double.isInfinite(cmh)) {
        output += ",";
    } else {
        output += confInt[1] + ",";
    }

    output += etsClass;

    return output;
}

From source file:org.orekit.time.AbsoluteDate.java

/** Build an instance from an elapsed duration since to another instant.
 * <p>It is important to note that the elapsed duration is <em>not</em>
 * the difference between two readings on a time scale. As an example,
 * the duration between the two instants leading to the readings
 * 2005-12-31T23:59:59 and 2006-01-01T00:00:00 in the {@link UTCScale UTC}
 * time scale is <em>not</em> 1 second, but a stop watch would have measured
 * an elapsed duration of 2 seconds between these two instances because a leap
 * second was introduced at the end of 2005 in this time scale.</p>
 * <p>This constructor is the reverse of the {@link #durationFrom(AbsoluteDate)}
 * method.</p>/* w w w . jav  a 2s .  c o  m*/
 * @param since start instant of the measured duration
 * @param elapsedDuration physically elapsed duration from the <code>since</code>
 * instant, as measured in a regular time scale
 * @see #durationFrom(AbsoluteDate)
 */
public AbsoluteDate(final AbsoluteDate since, final double elapsedDuration) {

    final double sum = since.offset + elapsedDuration;
    if (Double.isInfinite(sum)) {
        offset = sum;
        epoch = (sum < 0) ? Long.MIN_VALUE : Long.MAX_VALUE;
    } else {
        // compute sum exactly, using Mller-Knuth TwoSum algorithm without branching
        // the following statements must NOT be simplified, they rely on floating point
        // arithmetic properties (rounding and representable numbers)
        // at the end, the EXACT result of addition since.offset + elapsedDuration
        // is sum + residual, where sum is the closest representable number to the exact
        // result and residual is the missing part that does not fit in the first number
        final double oPrime = sum - elapsedDuration;
        final double dPrime = sum - oPrime;
        final double deltaO = since.offset - oPrime;
        final double deltaD = elapsedDuration - dPrime;
        final double residual = deltaO + deltaD;
        final long dl = (long) FastMath.floor(sum);
        offset = (sum - dl) + residual;
        epoch = since.epoch + dl;
    }
}

From source file:org.broadinstitute.sting.utils.recalibration.RecalDatumNode.java

/**
 * Calculate the phred-scaled p-value for a chi^2 test for independent among subnodes of this node.
 *
 * The chi^2 value indicates the degree of independence of the implied error rates among the
 * immediate subnodes//from w w  w .j a  v  a  2  s .  c  o m
 *
 * @return the phred-scaled p-value for chi2 penalty, or 0.0 if it cannot be calculated
 */
private double calcPenalty() {
    if (isLeaf() || freeToMerge())
        return 0.0;
    else if (subnodes.size() == 1)
        // only one value, so its free to merge away
        return 0.0;
    else {
        final long[][] counts = new long[subnodes.size()][2];

        int i = 0;
        for (final RecalDatumNode<T> subnode : subnodes) {
            // use the yates correction to help avoid all zeros => NaN
            counts[i][0] = Math.round(subnode.getRecalDatum().getNumMismatches()) + 1L;
            counts[i][1] = subnode.getRecalDatum().getNumObservations() + 2L;
            i++;
        }

        try {
            final double chi2PValue = new ChiSquareTestImpl().chiSquareTest(counts);
            final double penalty = -10.0 * Math.log10(Math.max(chi2PValue, SMALLEST_CHI2_PVALUE));

            // make sure things are reasonable and fail early if not
            if (Double.isInfinite(penalty) || Double.isNaN(penalty))
                throw new ReviewedStingException("chi2 value is " + chi2PValue + " at " + getRecalDatum());

            return penalty;
        } catch (MathException e) {
            throw new ReviewedStingException("Failed in calculating chi2 value", e);
        }
    }
}