List of usage examples for org.apache.commons.lang.math NumberUtils min
public static float min(float a, float b, float c)
Gets the minimum of three float values.
If any value is NaN, NaN is returned.
From source file:com.livinglogic.ul4.Color.java
public Vector<Double> hls() { int maxc = NumberUtils.max((int) r, (int) g, (int) b); int minc = NumberUtils.min((int) r, (int) g, (int) b); double dmaxc = maxc / 255.; double dminc = minc / 255.; double l = (dminc + dmaxc) / 2.0; if (minc == maxc) { Vector retVal = new Vector(3); retVal.add(new Double(0.0)); retVal.add(new Double(l)); retVal.add(new Double(0.0)); return retVal; }/* w w w. ja v a 2 s. co m*/ double s = l <= 0.5 ? (dmaxc - dminc) / (dmaxc + dminc) : (dmaxc - dminc) / (2.0 - dmaxc - dminc); double rc = (dmaxc - r / 255.) / (dmaxc - dminc); double gc = (dmaxc - g / 255.) / (dmaxc - dminc); double bc = (dmaxc - b / 255.) / (dmaxc - dminc); double h; if (r == maxc) h = bc - gc; else if (g == maxc) h = 2.0 + rc - bc; else h = 4.0 + gc - rc; h = (h / 6.0) % 1.0; Vector retVal = new Vector(3); retVal.add(new Double(h)); retVal.add(new Double(l)); retVal.add(new Double(s)); return retVal; }
From source file:com.livinglogic.ul4.Color.java
public Vector<Double> hsv() { int maxc = NumberUtils.max((int) r, (int) g, (int) b); int minc = NumberUtils.min((int) r, (int) g, (int) b); double dmaxc = maxc / 255.; double dminc = minc / 255.; double v = dmaxc; if (minc == maxc) { Vector retVal = new Vector(3); retVal.add(0.0d);/*from w w w .j ava 2 s. co m*/ retVal.add(0.0d); retVal.add(v); return retVal; } double s = (dmaxc - dminc) / dmaxc; double rc = (dmaxc - r / 255.) / (dmaxc - dminc); double gc = (dmaxc - g / 255.) / (dmaxc - dminc); double bc = (dmaxc - b / 255.) / (dmaxc - dminc); double h; if (r == maxc) h = bc - gc; else if (g == maxc) h = 2.0 + rc - bc; else h = 4.0 + gc - rc; h = (h / 6.0) % 1.0; Vector retVal = new Vector(3); retVal.add(h); retVal.add(s); retVal.add(v); return retVal; }
From source file:com.livinglogic.ul4.Color.java
public double lum() { int maxc = NumberUtils.max((int) r, (int) g, (int) b); int minc = NumberUtils.min((int) r, (int) g, (int) b); double dmaxc = maxc / 255.; double dminc = minc / 255.; return (dminc + dmaxc) / 2.0; }
From source file:com.livinglogic.ul4.Color.java
public Color withlum(double lum) { int maxc = NumberUtils.max((int) r, (int) g, (int) b); int minc = NumberUtils.min((int) r, (int) g, (int) b); double dmaxc = maxc / 255.; double dminc = minc / 255.; double l = (dminc + dmaxc) / 2.0; if (minc == maxc) return fromhls(0., lum, 0., a); double s = l <= 0.5 ? (dmaxc - dminc) / (dmaxc + dminc) : (dmaxc - dminc) / (2.0 - dmaxc - dminc); double rc = (dmaxc - r / 255.) / (dmaxc - dminc); double gc = (dmaxc - g / 255.) / (dmaxc - dminc); double bc = (dmaxc - b / 255.) / (dmaxc - dminc); double h;/* w w w .j av a 2s .c o m*/ if (r == maxc) h = bc - gc; else if (g == maxc) h = 2.0 + rc - bc; else h = 4.0 + gc - rc; h = (h / 6.0) % 1.0; return fromhls(h, lum, s, a); }
From source file:org.hydracache.data.partitioning.ConsistentHashNodePartitionTest.java
private void assertUniformedDistribution(final int sampleSize, final ServerNode A, final ServerNode B, final ServerNode C, final HashMap<ServerNode, Integer> counterMap) { final int maxCounter = NumberUtils.max(counterMap.get(A), counterMap.get(B), counterMap.get(C)); final int minCounter = NumberUtils.min(counterMap.get(A), counterMap.get(B), counterMap.get(C)); final int counterDifference = maxCounter - minCounter; assertTrue("Distribution difference is greater than 20%", counterDifference < (sampleSize * 0.20)); }