List of usage examples for java.lang Math abs
@HotSpotIntrinsicCandidate public static double abs(double a)
From source file:Main.java
/** Calculates the contrast between the given color and white, using the algorithm provided by * the WCAG v2 in http://www.w3.org/TR/WCAG20/#contrast-ratiodef. *///w w w . j av a 2 s. co m private static float getContrastForColor(int color) { float bgR = Color.red(color) / 255f; float bgG = Color.green(color) / 255f; float bgB = Color.blue(color) / 255f; bgR = (bgR < 0.03928f) ? bgR / 12.92f : (float) Math.pow((bgR + 0.055f) / 1.055f, 2.4f); bgG = (bgG < 0.03928f) ? bgG / 12.92f : (float) Math.pow((bgG + 0.055f) / 1.055f, 2.4f); bgB = (bgB < 0.03928f) ? bgB / 12.92f : (float) Math.pow((bgB + 0.055f) / 1.055f, 2.4f); float bgL = 0.2126f * bgR + 0.7152f * bgG + 0.0722f * bgB; return Math.abs((1.05f) / (bgL + 0.05f)); }
From source file:com.castlabs.dash.helpers.ManifestHelper.java
public static String convertFramerate(double vrate) { Fraction f1 = Fraction.getFraction((int) (vrate * 1001), 1001); Fraction f2 = Fraction.getFraction((int) (vrate * 1000), 1000); double d1 = Math.abs(f1.doubleValue() - vrate); double d2 = Math.abs(f2.doubleValue() - vrate); if (d1 < d2) { return f1.getNumerator() + "/" + f1.getDenominator(); } else {/*from ww w . ja va 2 s. c om*/ return f2.getNumerator() + "/" + f2.getDenominator(); } }
From source file:edu.umn.msi.tropix.proteomics.itraqquantitation.impl.RMethods.java
/** * From the following R code.// w w w.j a v a 2s .co m * * <pre> * getPvalue <- function(x){ * x_bar <- mean(x) * x_std <- sd(x) * z <- x_bar/x_std * pvalue <- pnorm(-abs(z)) * 2 * return(pvalue) * } * </pre> * * @param x * @return */ public static double getPValue(final double[] x) { final double xBar = StatUtils.mean(x); final double xStd = RUtils.sd(x); final double z = xBar / xStd; return RUtils.pnorm(-1 * Math.abs(z)) * 2; }
From source file:Data.Utilities.java
public static Integer timeDiff(GPSRec rec1, GPSRec rec2) { Double t1 = (double) rec1.getTimestamp().getTime(); Double t2 = (double) rec2.getTimestamp().getTime(); Double timeDiff = Math.abs(t2 - t1); // Double timeDiff = Math.abs(Double.longBitsToDouble( // - rec2.getTimestamp().getTime())); return (timeDiff.intValue()); }
From source file:Main.java
public static BufferedImage create(BufferedImage image, double angle, GraphicsConfiguration gc) { double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle)); int w = image.getWidth(), h = image.getHeight(); int neww = (int) Math.floor(w * cos + h * sin), newh = (int) Math.floor(h * cos + w * sin); int transparency = image.getColorModel().getTransparency(); BufferedImage result = gc.createCompatibleImage(neww, newh, transparency); Graphics2D g = result.createGraphics(); g.translate((neww - w) / 2, (newh - h) / 2); g.rotate(angle, w / 2, h / 2);/*from w ww.jav a2s . co m*/ g.drawRenderedImage(image, null); return result; }
From source file:Main.java
/** * Determines if the specified coordinate is in the target touch zone for a * horizontal bar handle./* w w w. jav a 2 s. c o m*/ * * @param x the x-coordinate of the touch point * @param y the y-coordinate of the touch point * @param handleXStart the left x-coordinate of the horizontal bar handle * @param handleXEnd the right x-coordinate of the horizontal bar handle * @param handleY the y-coordinate of the horizontal bar handle * @param targetRadius the target radius in pixels * @return true if the touch point is in the target touch zone; false * otherwise */ private static boolean isInHorizontalTargetZone(float x, float y, float handleXStart, float handleXEnd, float handleY, float targetRadius) { if (x > handleXStart && x < handleXEnd && Math.abs(y - handleY) <= targetRadius) { return true; } return false; }
From source file:Main.java
public static double getJulDate() { Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); int hour = cal.get(Calendar.HOUR_OF_DAY); int minute = cal.get(Calendar.MINUTE); int second = cal.get(Calendar.SECOND); double extra = (100.0 * year) + month - 190002.5; double julianDay = (367.0 * year) - (Math.floor(7.0 * (year + Math.floor((month + 9.0) / 12.0)) / 4.0)) + Math.floor((275.0 * month) / 9.0) + day + ((hour + ((minute + (second / 60.0)) / 60.0)) / 24.0) + 1721013.5 - ((0.5 * extra) / Math.abs(extra)) + 0.5; DecimalFormat sixDigitFormat = new DecimalFormat("#.######"); return Double.valueOf(sixDigitFormat.format(julianDay)); }
From source file:Main.java
public static float getCenteredAxis(MotionEvent event, InputDevice device, int axis, int historyPos) { if (device == null) { return 0; }// ww w . jav a 2 s . c o m final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource()); if (range != null) { final float flat = range.getFlat(); final float value = historyPos < 0 ? event.getAxisValue(axis) : event.getHistoricalAxisValue(axis, historyPos); // Ignore axis values that are within the 'flat' region of the // joystick axis center. // A joystick at rest does not always report an absolute position of // (0,0). if (Math.abs(value) > flat) { return value; } } return 0; }
From source file:Main.java
public static short[] createSequence(short begin, short end) { int sign = end > begin ? 1 : -1; int len = Math.abs(end - begin) + 1; short[] seq = new short[len]; for (int i = 0; i < len; i++) { seq[i] = (short) (begin + i * sign); }//from ww w . j ava2s.c o m return seq; }
From source file:Main.java
public static Camera.Size getOptimalPreviewSize(int displayOrientation, int width, int height, Camera.Parameters parameters) {/* w ww .j a v a2 s. c om*/ double targetRatio = (double) width / height; List<Camera.Size> sizes = parameters.getSupportedPreviewSizes(); Camera.Size optimalSize = null; double minDiff = Double.MAX_VALUE; int targetHeight = height; if (displayOrientation == 90 || displayOrientation == 270) { targetRatio = (double) height / width; } // Try to find an size match aspect ratio and size for (Size size : sizes) { double ratio = (double) size.width / size.height; if (Math.abs(ratio - targetRatio) <= ASPECT_TOLERANCE) { if (Math.abs(size.height - targetHeight) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - targetHeight); } } } // Cannot find the one match the aspect ratio, ignore // the requirement if (optimalSize == null) { minDiff = Double.MAX_VALUE; for (Size size : sizes) { if (Math.abs(size.height - targetHeight) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - targetHeight); } } } return (optimalSize); }