List of usage examples for java.lang Math min
@HotSpotIntrinsicCandidate public static double min(double a, double b)
From source file:Main.java
/** * Convert RGB components to HSL (hue-saturation-lightness). * <ul>/* w ww . j a va 2 s.co m*/ * <li>hsl[0] is Hue [0 .. 360)</li> * <li>hsl[1] is Saturation [0...1]</li> * <li>hsl[2] is Lightness [0...1]</li> * </ul> * * @param r red component value [0..255] * @param g green component value [0..255] * @param b blue component value [0..255] * @param hsl 3 element array which holds the resulting HSL components. */ public static void RGBToHSL(int r, int g, int b, float[] hsl) { final float rf = r / 255f; final float gf = g / 255f; final float bf = b / 255f; final float max = Math.max(rf, Math.max(gf, bf)); final float min = Math.min(rf, Math.min(gf, bf)); final float deltaMaxMin = max - min; float h, s; float l = (max + min) / 2f; if (max == min) { // Monochromatic h = s = 0f; } else { if (max == rf) { h = ((gf - bf) / deltaMaxMin) % 6f; } else if (max == gf) { h = ((bf - rf) / deltaMaxMin) + 2f; } else { h = ((rf - gf) / deltaMaxMin) + 4f; } s = deltaMaxMin / (1f - Math.abs(2f * l - 1f)); } hsl[0] = (h * 60f) % 360f; hsl[1] = s; hsl[2] = l; }
From source file:Main.java
/** * Expands an array of floats to double its current size. * * @param f Array to be expanded./*w w w .j a v a2 s .c o m*/ * @return Array of floats with f.length*2 length. */ static public float[] expandArray(float[] f) { int newSize = f.length * 2; float[] newf = new float[newSize]; System.arraycopy(f, 0, newf, 0, Math.min(f.length, newSize)); return newf; }
From source file:Main.java
/** * <p>//from w ww. j av a 2 s.co m * Reverses the order of the given array in the given range. * </p> * <p> * This method does nothing for a {@code null} input array. * </p> * * @param array the array to reverse, may be {@code null} * @param startIndexInclusive the starting index. Undervalue (<0) is * promoted to 0, overvalue (>array.length) results in no * change. * @param endIndexExclusive elements up to endIndex-1 are reversed in the * array. Undervalue (< start index) results in no change. * Overvalue (>array.length) is demoted to array length. * @since 3.2 */ public static void reverse(final int[] array, int startIndexInclusive, int endIndexExclusive) { if (array == null) { return; } int i = startIndexInclusive < 0 ? 0 : startIndexInclusive; int j = Math.min(array.length, endIndexExclusive) - 1; int tmp; while (j > i) { tmp = array[j]; array[j] = array[i]; array[i] = tmp; j--; i++; } }
From source file:Main.java
/** * Lighten a color by percent./*w w w .j a v a2s . com*/ * * @param color * @param percent 0.0 - 1.0 * @return A new, lighter color. */ public static int lightterByPercent(int color, float percent) { // TODO We may try an HSV approach... // float[] hsv = new float[3]; // Color.colorToHSV(color, hsv); // hsv[2] *= (1 + percent); // return Color.HSVToColor(hsv); float r = Color.red(color) * (1 + percent); float g = Color.green(color) * (1 + percent); float b = Color.blue(color) * (1 + percent); int ir = Math.min(255, (int) r); int ig = Math.min(255, (int) g); int ib = Math.min(255, (int) b); int ia = Color.alpha(color); return (Color.argb(ia, ir, ig, ib)); }
From source file:Main.java
/** * Determining the smallest size of the screen to detect "real small devices", * the dpi modifier is not reliable on Samsung devices * * @param activity - current activity// w w w . j a v a 2 s . co m * @return the size of the smallest edge of default display in pixels */ private static int getSmallestScreenSize(Activity activity) { Display display = activity.getWindowManager().getDefaultDisplay(); Point point = new Point(); display.getSize(point); return Math.min(point.x, point.y); }
From source file:com.fortydegree.ra.data.JsonUnmarshaller.java
public static List<Marker> load(JSONObject root) throws JSONException { JSONObject jo = null;//w w w . java 2 s . co m JSONArray dataArray = null; List<Marker> markers = new ArrayList<Marker>(); if (root.has("results")) { dataArray = root.getJSONArray("results"); int top = Math.min(MAX_JSON_OBJECTS, dataArray.length()); for (int i = 0; i < top; i++) { jo = dataArray.getJSONObject(i); Marker ma = processGeoserviceJSONObject(jo); if (ma != null) markers.add(ma); } } return markers; }
From source file:Main.java
/** * //from w w w . ja v a 2s . c om * */ @SuppressWarnings("unchecked") public static <T> T[] toArray(Collection<T> collection, Class<T> elementClass, int index, int count) { int n = collection.size(); int end = Math.min(index + count, n); Object result = Array.newInstance(elementClass, end - index); Iterator<T> it = collection.iterator(); int resultIndex = 0; for (int i = 0; i < end; i++) { if (!it.hasNext()) break; Object value = it.next(); if (i < index) continue; Array.set(result, resultIndex, value); resultIndex++; } return (T[]) result; }
From source file:Main.java
/** * Calculates the number of threads to use. * * @param numThreads the requested number of threads (-1 for # of cores/cpus) * @param maxThreads the maximum to ask for * @return the actual number of threads to use, (1 = single thread) *//*from w w w .j av a2 s. c o m*/ public static int getActualNumThreads(int numThreads, int maxThreads) { int result; if (numThreads == ALL) result = getAvailableProcessors(); else if (numThreads > SEQUENTIAL) result = Math.min(numThreads, maxThreads); else result = SEQUENTIAL; if (result > getAvailableProcessors()) result = getAvailableProcessors(); return result; }
From source file:com.metamx.collections.spatial.RTreeUtils.java
public static double getEnclosingArea(Node a, Node b) { Preconditions.checkArgument(a.getNumDims() == b.getNumDims()); double[] minCoords = new double[a.getNumDims()]; double[] maxCoords = new double[a.getNumDims()]; for (int i = 0; i < minCoords.length; i++) { minCoords[i] = Math.min(a.getMinCoordinates()[i], b.getMinCoordinates()[i]); maxCoords[i] = Math.max(a.getMaxCoordinates()[i], b.getMaxCoordinates()[i]); }//from w w w . j a v a2 s. co m double area = 1.0; for (int i = 0; i < minCoords.length; i++) { area *= (maxCoords[i] - minCoords[i]); } return area; }
From source file:com.linkedin.pinot.core.segment.memory.PinotDataBufferTest.java
static void loadVerifyLong(PinotDataBuffer buffer) { final int fieldSize = 8; int maxElementCount = (int) (buffer.size() / fieldSize); int elemCount = Math.min(100_000, maxElementCount); Map<Integer, Long> positionValues = new HashMap<>(elemCount); for (long i = 0; i < elemCount; i++) { int pos = random.nextInt(elemCount); long val = random.nextLong(); positionValues.put(pos, val); buffer.putLong(pos * fieldSize, val); }/*from w w w. j a v a2s .c om*/ for (Map.Entry<Integer, Long> entry : positionValues.entrySet()) { Assert.assertEquals(buffer.getLong(entry.getKey() * fieldSize), (long) entry.getValue()); } }