Example usage for org.apache.commons.math3.util FastMath min

List of usage examples for org.apache.commons.math3.util FastMath min

Introduction

In this page you can find the example usage for org.apache.commons.math3.util FastMath min.

Prototype

public static double min(final double a, final double b) 

Source Link

Document

Compute the minimum of two values

Usage

From source file:com.sandbox.utils.HSLColor.java

/**
 * Convert a RGB Color to it corresponding HSL values.
 *
 * @param color the color to convert.//ww w .jav a2s  . c  o m
 * @param dest  the optional array to store the result in.
 * @return an array containing the 3 HSL values.
 */
public static float[] fromRGB(final Color color, float[] dest) {
    // Get RGB values in the range 0 - 1

    final float r = color.getRed() / 255f;
    final float g = color.getGreen() / 255f;
    final float b = color.getBlue() / 255f;

    // Minimum and Maximum RGB values are used in the HSL calculations

    final float min = FastMath.min(r, FastMath.min(g, b));
    final float max = FastMath.max(r, FastMath.max(g, b));

    // Calculate the Hue

    float h = 0;

    if (max == min)
        h = 0;
    else if (max == r)
        h = ((g - b) / (max - min) / 6f + 1) % 1;
    else if (max == g)
        h = (b - r) / (max - min) / 6f + 1f / 3f;
    else if (max == b)
        h = (r - g) / (max - min) / 6f + 2f / 3f;

    // Calculate the Luminance

    final float l = (max + min) / 2;

    // Calculate the Saturation

    float s = 0;

    if (max == min)
        s = 0;
    else if (l <= .5f)
        s = (max - min) / (max + min);
    else
        s = (max - min) / (2 - max - min);

    if (dest == null)
        dest = new float[3];
    dest[0] = h;
    dest[1] = s;
    dest[2] = l;

    return dest;
}

From source file:cloudnet.provisioners.GreedyProvisioner.java

@Override
public long provisionResource(long requested, long overall) {
    return FastMath.min(requested, overall);
}

From source file:fuzzy.mf.TriangularMembershipFunction.java

public Double evaluate(Double x) {
    return FastMath.max(FastMath.min((x - a) / (b - a), (c - x) / (c - b)), 0.0);
}

From source file:com.tussle.main.Utility.java

public static double addTowards(double value, double addend, double base) {
    if (addend == 0)
        return value;
    if (addend * (base - value - addend) > 0)
        return value + addend;
    else// w w w  .j a  v a  2  s  . co  m
        return addend > 0 ? FastMath.max(base, value) : FastMath.min(base, value);
}

From source file:gdsc.core.clustering.TimeCluster.java

/**
 * Get the time gap between the two clusters. If the clusters overlap then return 0.
 * /*from   www .j  ava2 s  .c  om*/
 * @param other
 * @return
 */
public int gap(TimeCluster other) {
    // Overlap:
    // |-----------|
    //         |---------|
    //
    // Gap:
    // |-----------|
    //                  |---------|
    return FastMath.max(0, FastMath.max(start, other.start) - FastMath.min(end, other.end));
}

From source file:com.tussle.stream.PipeBufferReader.java

public int read(char[] buf, int off, int len) {
    if (buffer.length() == 0)
        return -1;
    int tryLen = FastMath.min(len, buffer.length());
    buffer.getChars(0, tryLen, buf, off);
    buffer.delete(0, tryLen);/*ww w .  ja v  a  2  s  .  com*/
    return tryLen;
}

From source file:cloudnet.workloads.WorkloadModelBase.java

protected double adjustToBounds(double input) {
    if (minValue != null) {
        input = FastMath.max(input, minValue);
    }// w  ww .  j av  a 2  s  . c o m
    if (maxValue != null) {
        input = FastMath.min(input, maxValue);
    }

    return input;
}

From source file:com.tussle.main.Utility.java

public static double addFrom(double value, double amount, double base) {
    if (amount < 0 && FastMath.min(value - base, base - value) > amount)
        return base;
    else/*  w w  w.j  a  v a 2  s.  c om*/
        return amount * FastMath.copySign(1, value - base) + value;
}

From source file:cloudnet.examples.elasticity.bn.WorkloadLevel.java

public static double getWorkload(String level) {
    Ensure.NotNullOrEmpty(level, "level");

    int index = Arrays.asList(WorkloadLevelsWithOverusage).indexOf(level);

    if (index == -1) {
        throw new IllegalArgumentException("Unexisted level specified.");
    }/*from  w w w . j a  v  a2s  .c om*/

    double workload = FastMath.min(1.0, 0.1 * (index + 1));
    return workload;
}

From source file:com.clust4j.algo.KMedoidsTests.java

/**
 * This is the method as it is used in the KMedoids class,
 * except that the distance matrix is passed in
 * @param indices// w w w .  ja  v a  2 s.c o  m
 * @param med_idx
 * @return
 */
protected static double getCost(ArrayList<Integer> indices, final int med_idx, final double[][] dist_mat) {
    double cost = 0;
    for (Integer idx : indices)
        cost += dist_mat[FastMath.min(idx, med_idx)][FastMath.max(idx, med_idx)];
    return cost;
}