List of usage examples for java.lang Math floor
public static double floor(double a)
From source file:Main.java
public static Bitmap resize(Bitmap src, int w2, int h2) { int w1 = src.getWidth(); int h1 = src.getHeight(); int[] pxSource = new int[w1 * h1]; int[] pxResult = new int[w2 * h2]; src.getPixels(pxSource, 0, w1, 0, 0, w1, h1); double x_ratio = w1 / (double) w2; double y_ratio = h1 / (double) h2; double px, py; for (int i = 0; i < h2; i++) { for (int j = 0; j < w2; j++) { px = Math.floor(j * x_ratio); py = Math.floor(i * y_ratio); pxResult[(i * w2) + j] = pxSource[(int) ((py * w1) + px)]; }/*from ww w. j a va2s . com*/ } return Bitmap.createBitmap(pxResult, w2, h2, Config.ARGB_8888); }
From source file:Main.java
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { //https://github.com/square/picasso/blob/master/picasso/src/main/java/com/squareup/picasso/RequestHandler.java#L161 if (reqHeight == 0) { inSampleSize = (int) Math.floor((float) width / (float) reqWidth); } else if (reqWidth == 0) { inSampleSize = (int) Math.floor((float) height / (float) reqHeight); } else {// www . j ava 2 s. c om int heightRatio = (int) Math.floor((float) height / (float) reqHeight); int widthRatio = (int) Math.floor((float) width / (float) reqWidth); inSampleSize = Math.max(heightRatio, widthRatio); } } return inSampleSize; }
From source file:Main.java
public static int[] getMapTileFromCoordinates(final double aLat, final double aLon, final int zoom) { final int[] out = new int[2]; final double E2 = (double) aLat * Math.PI / 180; final long sradiusa = 6378137; final long sradiusb = 6356752; final double J2 = (double) Math.sqrt(sradiusa * sradiusa - sradiusb * sradiusb) / sradiusa; final double M2 = (double) Math.log((1 + Math.sin(E2)) / (1 - Math.sin(E2))) / 2 - J2 * Math.log((1 + J2 * Math.sin(E2)) / (1 - J2 * Math.sin(E2))) / 2; final double B2 = (double) (1 << zoom); out[0] = (int) Math.floor(B2 / 2 - M2 * B2 / 2 / Math.PI); out[1] = (int) Math.floor((aLon + 180) / 360 * (1 << zoom)); return out;// ww w .ja v a 2 s . co m }
From source file:Main.java
public static RectF round(final RectF rect) { rect.left = (float) Math.floor(rect.left); rect.top = (float) Math.floor(rect.top); rect.right = (float) Math.ceil(rect.right); rect.bottom = (float) Math.ceil(rect.bottom); return rect;/*from ww w. j a v a 2 s . c om*/ }
From source file:Main.java
public static double roundDistance(double val) { return (Math.floor(val * 10)) / 10; }
From source file:Main.java
public static <T> T random(List<T> list) { return list.get((int) Math.floor(Math.random() * list.size())); }
From source file:AIR.Common.Utilities.MathUtils.java
public static double truncate(double d) { if (d < 0) return -1 * Math.floor(d * -1); else// ww w. j a v a 2 s .co m return Math.floor(d); }
From source file:Main.java
public static int getTileSize(double zoomLevel, int tileSize) { double f = zoomLevel - Math.floor(zoomLevel); f = f < .5f ? f + 1f : .5f * (f + 1f); return (int) (tileSize * f); }
From source file:Main.java
/** * Convert the given Julian Day to Gregorian Date (in UT time zone). * Based on the formula given in the Explanitory Supplement to the * Astronomical Almanac, pg 604./* w ww . j a v a2 s . com*/ */ public static Date calculateGregorianDate(double jd) { int l = (int) jd + 68569; int n = (4 * l) / 146097; l = l - (146097 * n + 3) / 4; int i = (4000 * (l + 1)) / 1461001; l = l - (1461 * i) / 4 + 31; int j = (80 * l) / 2447; int d = l - (2447 * j) / 80; l = j / 11; int m = j + 2 - 12 * l; int y = 100 * (n - 49) + i + l; double fraction = jd - Math.floor(jd); double dHours = fraction * 24.0; int hours = (int) dHours; double dMinutes = (dHours - hours) * 60.0; int minutes = (int) dMinutes; int seconds = (int) ((dMinutes - minutes) * 60.0); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UT")); cal.set(y, m - 1, d, hours + 12, minutes, seconds); return cal.getTime(); }
From source file:Main.java
/** * date into display date// w w w. j a va 2s. com * * @serverDateStr server date in string format * @return display time (Like 1 second ago, 2 months ago etc.) * */ public static String convertDateToDisplayFormat(Date serverDate) { // current date Date endDate = new Date(); long different = endDate.getTime() - serverDate.getTime(); long seconds = TimeUnit.MILLISECONDS.toSeconds(different); long minutes = TimeUnit.MILLISECONDS.toMinutes(different); long hrs = TimeUnit.MILLISECONDS.toHours(different); long days = TimeUnit.MILLISECONDS.toDays(different); int months = (int) Math.floor(days / 30); int years = (int) Math.floor(months / 12); if (years != 0) { if (years == 1) { return "1 year ago"; } else { return years + " years ago"; } } else if (months != 0) { if (months == 1) { return "1 month ago"; } else { return months + " months ago"; } } else if (days != 0) { if (days == 1) { return "Yesterday"; } else { return days + " Days ago"; } } else if (hrs != 0) { if (hrs == 1) { return hrs + " hour ago"; } else { return hrs + " hours ago"; } } else if (minutes != 0) { if (minutes == 1) { return minutes + " minute ago"; } else { return minutes + " minutes ago"; } } else { if (seconds == 0) { return "Now"; } else if (seconds == 1) { return "1 sec ago"; } else if (seconds > 0) { return seconds + " seconds ago"; } else { return "Now"; } } }