Example usage for java.lang Math ceil

List of usage examples for java.lang Math ceil

Introduction

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

Prototype

public static double ceil(double a) 

Source Link

Document

Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.

Usage

From source file:com.adobe.acs.commons.images.transformers.impl.ScaleImageTransformerImpl.java

@Override
public final Layer transform(Layer layer, final ValueMap properties) {

    if (properties == null || properties.isEmpty()) {
        log.warn("Transform [ {} ] requires parameters.", TYPE);
        return layer;
    }//  www . j a  v  a2  s  .c  om

    log.debug("Transforming with [ {} ]", TYPE);

    Double scale = properties.get(KEY_SCALE, 1D);
    String round = StringUtils.trim(properties.get(KEY_ROUND, String.class));

    if (scale == null) {
        log.warn("Could not derive a Double value for key [ {} ] from value [ {} ]", KEY_SCALE,
                properties.get(KEY_SCALE, String.class));
        scale = 1D;
    }

    if (scale != 1D) {

        int currentWidth = layer.getWidth();
        int currentHeight = layer.getHeight();

        double newWidth = scale * currentWidth;
        double newHeight = scale * currentHeight;

        if (StringUtils.equals(ROUND_UP, round)) {
            newWidth = (int) Math.ceil(newWidth);
            newHeight = (int) Math.ceil(newHeight);
        } else if (StringUtils.equals(ROUND_DOWN, round)) {
            newWidth = (int) Math.floor(newWidth);
            newHeight = (int) Math.floor(newHeight);
        } else {
            // "round"
            newWidth = (int) Math.round(newWidth);
            newHeight = (int) Math.round(newHeight);
        }

        // Invoke the ResizeImageTransformer with the new values

        final ValueMap params = new ValueMapDecorator(new HashMap<String, Object>());
        params.put(ResizeImageTransformerImpl.KEY_WIDTH, (int) newWidth);
        params.put(ResizeImageTransformerImpl.KEY_HEIGHT, (int) newHeight);

        layer = resizeImageTransformer.transform(layer, params);
    }

    return layer;
}

From source file:gedi.util.math.stat.distributions.PoissonBinomial.java

private void preprocess() {
    int n = pp.length;
    m = n + 1;/*from   w  ww  .j ava  2 s .c o m*/
    int nextPowerOf2 = Integer.highestOneBit(m);
    if (nextPowerOf2 != m)
        nextPowerOf2 <<= 1;
    m = nextPowerOf2;
    n = m - 1;

    int ins = 0;
    int start = 0;
    for (int i = 1; i < pp.length; i++) {
        if (Math.abs(pp[i] - pp[start]) > 1E-10) {
            if (i - start > 1) {
                double p = pp[start];
                pp[ins++] = -(i - start);
                pp[ins++] = p;
            } else {
                pp[ins++] = pp[i - 1];
            }
            start = i;
        }
    }

    if (pp.length - start > 1) {
        double p = pp[start];
        pp[ins++] = -(pp.length - start);
        pp[ins++] = p;
    } else {
        pp[ins++] = pp[pp.length - 1];
    }

    double delta = 2 * Math.PI / m;
    z = new Complex[m];
    z[0] = new Complex(1, 0);

    for (int i = 1; i <= Math.ceil(n / 2.0); i++) {
        double tt = i * delta;

        //         for(int j=0;j<pp.length;j++)
        //         {
        //            double pj=j<opp.length?opp[j]:0;
        //            double ax=1-pj+pj*Math.cos(tt);
        //            double bx=pj*Math.sin(tt);
        //            double tmp1=Math.sqrt(ax*ax+bx*bx);
        //            double tmp2=Math.atan2(bx,ax); //atan2(x,y)
        //            c1o+=Math.log(tmp1);
        //            c2o+=tmp2;
        //         }

        double c1 = 0.00;
        double c2 = 0.00;
        for (int j = 0; j < ins; j++) {
            double pj = pp[j];
            double f = 1;
            if (pj < 0) {
                f = -pj;
                pj = pp[++j];
            }

            double ax = 1 - pj + pj * Math.cos(tt);
            double bx = pj * Math.sin(tt);
            double tmp1 = Math.sqrt(ax * ax + bx * bx);
            double tmp2 = Math.atan2(bx, ax); //atan2(x,y)
            c1 += Math.log(tmp1) * f;
            c2 += tmp2 * f;
        }
        z[i] = new Complex(Math.exp(c1) * Math.cos(c2), Math.exp(c1) * Math.sin(c2));
        z[z.length - i] = z[i].conjugate();
    }
    FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);
    z = fft.transform(z, TransformType.FORWARD);
}

From source file:ImageUtils.java

/**
 * Resizes an image./*  w  w  w .  j  a  v a  2 s. c  o m*/
 * 
 * @param image
 *            The image to resize
 * @param maxWidth
 *            The image's max width
 * @param maxHeight
 *            The image's max height
 * @return A resized <code>BufferedImage</code>
 * @param type
 *            int
 */
public static BufferedImage resizeImage(BufferedImage image, int type, int maxWidth, int maxHeight) {
    Dimension largestDimension = new Dimension(maxWidth, maxHeight);

    // Original size
    int imageWidth = image.getWidth(null);
    int imageHeight = image.getHeight(null);

    float aspectRatio = (float) imageWidth / imageHeight;

    if (imageWidth > maxWidth || imageHeight > maxHeight) {
        if ((float) largestDimension.width / largestDimension.height > aspectRatio) {
            largestDimension.width = (int) Math.ceil(largestDimension.height * aspectRatio);
        } else {
            largestDimension.height = (int) Math.ceil(largestDimension.width / aspectRatio);
        }

        imageWidth = largestDimension.width;
        imageHeight = largestDimension.height;
    }

    return createHeadlessSmoothBufferedImage(image, type, imageWidth, imageHeight);
}

From source file:com.owncloud.android.lib.resources.files.ChunkedUploadRemoteFileOperation.java

@Override
protected int uploadFile(OwnCloudClient client) throws HttpException, IOException {
    int status = -1;

    FileChannel channel = null;/*  ww w .  j  a  v a  2  s .  c om*/
    RandomAccessFile raf = null;
    try {
        File file = new File(mLocalPath);
        raf = new RandomAccessFile(file, "r");
        channel = raf.getChannel();
        mEntity = new ChunkFromFileChannelRequestEntity(channel, mMimeType, CHUNK_SIZE, file);
        //((ProgressiveDataTransferer)mEntity).addDatatransferProgressListeners(getDataTransferListeners());
        synchronized (mDataTransferListeners) {
            ((ProgressiveDataTransferer) mEntity).addDatatransferProgressListeners(mDataTransferListeners);
        }

        long offset = 0;
        String uriPrefix = client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath) + "-chunking-"
                + Math.abs((new Random()).nextInt(9000) + 1000) + "-";
        long chunkCount = (long) Math.ceil((double) file.length() / CHUNK_SIZE);
        for (int chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++, offset += CHUNK_SIZE) {
            if (mPutMethod != null) {
                mPutMethod.releaseConnection(); // let the connection available for other methods
            }
            mPutMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex);
            mPutMethod.addRequestHeader(OC_CHUNKED_HEADER, OC_CHUNKED_HEADER);
            ((ChunkFromFileChannelRequestEntity) mEntity).setOffset(offset);
            mPutMethod.setRequestEntity(mEntity);
            status = client.executeMethod(mPutMethod);
            client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
            Log_OC.d(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ", chunk index " + chunkIndex
                    + ", count " + chunkCount + ", HTTP result status " + status);
            if (!isSuccess(status))
                break;
        }

    } finally {
        if (channel != null)
            channel.close();
        if (raf != null)
            raf.close();
        if (mPutMethod != null)
            mPutMethod.releaseConnection(); // let the connection available for other methods
    }
    return status;
}

From source file:com.linkedin.pinot.core.index.writer.impl.FixedBitSkipListSCMVWriter.java

public FixedBitSkipListSCMVWriter(File file, int numDocs, int totalNumValues, int columnSizeInBits)
        throws Exception {
    float averageValuesPerDoc = totalNumValues / numDocs;
    this.docsPerChunk = (int) (Math.ceil(PREFERRED_NUM_VALUES_PER_CHUNK / averageValuesPerDoc));
    this.numChunks = (numDocs + docsPerChunk - 1) / docsPerChunk;
    chunkOffsetHeaderSize = numChunks * SIZE_OF_INT * NUM_COLS_IN_HEADER;
    bitsetSize = (totalNumValues + 7) / 8;
    rawDataSize = ((long) totalNumValues * columnSizeInBits + 7) / 8;
    totalSize = chunkOffsetHeaderSize + bitsetSize + rawDataSize;
    raf = new RandomAccessFile(file, "rw");
    chunkOffsetsBuffer = MmapUtils.mmapFile(raf, FileChannel.MapMode.READ_WRITE, 0, chunkOffsetHeaderSize, file,
            this.getClass().getSimpleName() + " chunkOffsetsBuffer");
    bitsetBuffer = MmapUtils.mmapFile(raf, FileChannel.MapMode.READ_WRITE, chunkOffsetHeaderSize, bitsetSize,
            file, this.getClass().getSimpleName() + " bitsetBuffer");
    rawDataBuffer = MmapUtils.mmapFile(raf, FileChannel.MapMode.READ_WRITE, chunkOffsetHeaderSize + bitsetSize,
            rawDataSize, file, this.getClass().getSimpleName() + " rawDataBuffer");

    chunkOffsetsWriter = new FixedByteWidthRowColDataFileWriter(chunkOffsetsBuffer, numDocs, NUM_COLS_IN_HEADER,
            new int[] { SIZE_OF_INT });

    customBitSet = CustomBitSet.withByteBuffer(bitsetSize, bitsetBuffer);
    rawDataWriter = new FixedBitWidthRowColDataFileWriter(rawDataBuffer, totalNumValues, 1,
            new int[] { columnSizeInBits });

}

From source file:de.biomedical_imaging.ij.steger.Width.java

public void bresenham(double nx, double ny, double px, double py, double length, Offset[] line,
        MutableInt num_points) {/*from  w ww .ja va 2 s.c  o  m*/
    int i, n, x, y, s1, s2, xchg, maxit;
    double e, dx, dy, t;

    x = 0;
    y = 0;
    dx = Math.abs(nx);
    dy = Math.abs(ny);
    s1 = (int) Math.signum(nx);
    s2 = (int) Math.signum(ny);
    px *= s1;
    py *= s2;
    if (dy > dx) {
        t = dx;
        dx = dy;
        dy = t;
        t = px;
        px = py;
        py = t;
        xchg = 1;
    } else {
        xchg = 0;
    }
    maxit = (int) Math.ceil(length * dx);
    e = (0.5 - px) * dy / dx - (0.5 - py);
    n = 0;
    for (i = 0; i <= maxit; i++) {
        line[n].x = x;
        line[n].y = y;
        n++;
        while (e >= -1e-8) {
            if (!(xchg == 0))
                x += s1;
            else
                y += s2;
            e--;
            if (e > -1) {
                line[n].x = x;
                line[n].y = y;
                n++;
            }
        }
        if (!(xchg == 0))
            y += s2;
        else
            x += s1;
        e += dy / dx;
    }
    num_points.setValue(n);
}

From source file:de.uniba.wiai.lspi.chord.data.ID.java

private static int ProviderMinimumBitLen() {
    final double lenMin = log2(kProviderLimit - 1) - log2(kNetworkSizeExpected) + (double) kSemanticTotalBitLen;
    return (int) Math.ceil(lenMin);
}

From source file:com.duy.pascal.interperter.libraries.math.MathLib.java

@PascalMethod(description = "Return the lowest integer number greater than or equal to argument")
public int Ceil(double d) {
    return (int) Math.ceil(d);
}

From source file:it.unibo.alchemist.modelchecker.AlchemistASMC.java

/**
 * Given the approximation and the confidence, computes an upper bound for
 * the number of runs to execute (see manual).
 * /*ww  w  . ja  v a2 s.  c o m*/
 * @param delta
 *            approximation
 * @param alpha
 *            confidence
 * @return number of runs
 */
public static int computeSampleSizeUB(final double delta, final double alpha) {
    return (int) Math.ceil(LOG_MUL * Math.log(2 / alpha) / (delta * delta));
}

From source file:de.mpicbg.knime.hcs.base.utils.MutualInformation.java

public void set_binning() {
    int bins = (int) Math.ceil(Math.pow(Math.max(x.length, y.length), 1.0 / 3.0));
    set_binning(bins);
}