List of usage examples for java.lang Math min
@HotSpotIntrinsicCandidate public static double min(double a, double b)
From source file:Main.java
/** * Create a color integer value with specified alpha. * This may be useful to change alpha value of background color. * * @param alpha alpha value from 0.0f to 1.0f. * @param baseColor base color. alpha value will be ignored. * @return a color with alpha made from base color *///from w w w .j a v a 2s. c o m public static int getColorWithAlpha(float alpha, int baseColor) { int a = Math.min(255, Math.max(0, (int) (alpha * 255))) << 24; int rgb = 0x00ffffff & baseColor; return a + rgb; }
From source file:Main.java
public static double calculateDifferenceBetweenAngles(double firstAngle, double secondAngle) { double difference1 = (secondAngle - firstAngle) % 360; if (difference1 < 0) { difference1 += 360;/* w ww . java 2 s .c o m*/ } double difference2 = (firstAngle - secondAngle) % 360; if (difference2 < 0) { difference2 += 360; } return Math.min(difference1, difference2); }
From source file:Main.java
public static int imageDifference(BufferedImage imgA, BufferedImage imgB) { int dHeight = Math.abs(imgA.getHeight() - imgB.getHeight()); int dWidth = Math.abs(imgA.getWidth() - imgB.getWidth()); int diff = 3 * 255 * dHeight * dWidth; for (int y = 0; y < Math.min(imgA.getHeight(), imgB.getHeight()); y++) { for (int x = 0; x < Math.min(imgA.getWidth(), imgB.getWidth()); x++) { final int colourA = imgA.getRGB(x, y); final int colourB = imgB.getRGB(x, y); diff += Math.abs((int) ((colourA & 0x00ff0000) >> 16) - (int) ((colourB & 0x00ff0000) >> 16)); diff += Math.abs((int) ((colourA & 0x0000ff00) >> 8) - (int) ((colourB & 0x0000ff00) >> 8)); diff += Math.abs((int) (colourA & 0x000000ff) - (int) (colourB & 0x000000ff)); }//from ww w. ja v a 2 s .c o m } return diff; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T, U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) { T[] copy = ((Object) newType == (Object) Object[].class) ? (T[]) new Object[newLength] : (T[]) Array.newInstance(newType.getComponentType(), newLength); System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength)); return copy;//w ww .j a v a 2 s .c o m }
From source file:Main.java
public static Bitmap makeBitmap(String filePath, int maxNumOfPixels) { try {//from ww w .j a va 2s .c o m BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(filePath, options); if (options.mCancel || options.outWidth == -1 || options.outHeight == -1) { return null; } options.inSampleSize = computeSampleSize(options, -1, maxNumOfPixels); options.inJustDecodeBounds = false; options.inDither = false; options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap b = BitmapFactory.decodeFile(filePath, options); b = formatBitmap(b, Math.min(options.outHeight, options.outWidth)); return b; } catch (OutOfMemoryError ex) { Log.e(TAG, "Got oom exception ", ex); return null; } }
From source file:Main.java
/** * Converts the given pair of lists into a map that maps each keys[i] to * the corresponding values[i]./*from w ww. ja v a 2 s. c om*/ * @return the map (empty map if keys == null or values == null) */ public static <K, V> Map<K, V> asMap(List<K> keys, List<V> values) { Map<K, V> map = new LinkedHashMap<K, V>(); if (keys == null || values == null) { return map; } for (int i = 0, len = Math.min(keys.size(), values.size()); i < len; i++) { map.put(keys.get(i), values.get(i)); } return map; }
From source file:Main.java
public static boolean isPolygonContainPoint(PointF point, PointF[] vertexPoints) { int nCross = 0; for (int i = 0; i < vertexPoints.length; i++) { PointF p1 = vertexPoints[i];//from ww w. j a v a2s. c o m PointF p2 = vertexPoints[(i + 1) % vertexPoints.length]; if (p1.y == p2.y) continue; if (point.y < Math.min(p1.y, p2.y)) continue; if (point.y >= Math.max(p1.y, p2.y)) continue; double x = (double) (point.y - p1.y) * (double) (p2.x - p1.x) / (double) (p2.y - p1.y) + p1.x; if (x > point.x) nCross++; } return (nCross % 2 == 1); }
From source file:Main.java
public static boolean isNewer(String version, String compareVersion) { if (version.equals(compareVersion)) return false; boolean numericalCompare = isNumericalVersion(version) && isNumericalVersion(compareVersion); String[] versionParts = versionSplitting(version, versionDelimiters); String[] compareVersionParts = versionSplitting(compareVersion, versionDelimiters); // ignore versions with different numbers of tokens // because they are false positives more often than not if (versionParts.length != compareVersionParts.length) return false; if (numericalCompare) { for (int i = 0; i < Math.min(versionParts.length, compareVersionParts.length); i++) { Integer currentVersionNumber = Integer.parseInt(versionParts[i]); Integer currentCompareNumber = Integer.parseInt(compareVersionParts[i]); if (currentVersionNumber > currentCompareNumber) { return true; } else if (currentVersionNumber < currentCompareNumber) { return false; }//from www . jav a 2 s. c o m } return false; } else { for (int i = 0; i < Math.min(versionParts.length, compareVersionParts.length); i++) { String currentVersionPart = versionParts[i]; String currentComparePart = compareVersionParts[i]; for (int c = 0; c < Math.min(currentVersionPart.length(), currentComparePart.length()); c++) { if (currentVersionPart.charAt(c) > currentComparePart.charAt(c)) { return true; } else if (currentVersionPart.charAt(c) < currentComparePart.charAt(c)) { return false; } } if (currentVersionPart.length() > currentComparePart.length()) { return true; } else if (currentVersionPart.length() < currentComparePart.length()) { return false; } } return false; } }
From source file:io.fabric8.maven.core.util.VersionUtil.java
/** * Compares two version strings such that "1.10.1" > "1.4" etc *//*from w w w. j a va2 s .c o m*/ public static int compareVersions(String v1, String v2) { String[] components1 = split(v1); String[] components2 = split(v2); int diff; int length = Math.min(components1.length, components2.length); for (int i = 0; i < length; i++) { String s1 = components1[i]; String s2 = components2[i]; Integer i1 = tryParseInteger(s1); Integer i2 = tryParseInteger(s2); if (i1 != null && i2 != null) { diff = i1.compareTo(i2); } else { // lets assume strings instead diff = s1.compareTo(s2); } if (diff != 0) { return diff; } } diff = Integer.compare(components1.length, components2.length); if (diff == 0) { if (v1 == v2) { return 0; } /* if v1 == null then v2 can't be null here (see 'if' above). So for v1 == null its always smaller than v2 */; return v1 != null ? v1.compareTo(v2) : -1; } return diff; }
From source file:Main.java
private static Bitmap decodeBitmapWithSize(String pathName, int width, int height, boolean useBigger) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;/*ww w . ja v a2s . c o m*/ options.inInputShareable = true; options.inPurgeable = true; BitmapFactory.decodeFile(pathName, options); int decodeWidth = width, decodeHeight = height; final int degrees = getImageDegrees(pathName); if (degrees == 90 || degrees == 270) { decodeWidth = height; decodeHeight = width; } if (useBigger) { options.inSampleSize = (int) Math.min(((float) options.outWidth / decodeWidth), ((float) options.outHeight / decodeHeight)); } else { options.inSampleSize = (int) Math.max(((float) options.outWidth / decodeWidth), ((float) options.outHeight / decodeHeight)); } options.inJustDecodeBounds = false; Bitmap sourceBm = BitmapFactory.decodeFile(pathName, options); return imageWithFixedRotation(sourceBm, degrees); }