Java Code Examples for java.lang.Math#round()

The following examples show how to use java.lang.Math#round() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Compiler.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
private BufferedImage produceRoundIcon(BufferedImage icon) {
  int imageWidth = icon.getWidth();
  // Ratio of icon size to png image size for round icon is 0.80
  double iconWidth = imageWidth * 0.80;
  // Round iconWidth value to even int for a centered png
  int intIconWidth = ((int)Math.round(iconWidth / 2) * 2);
  Image tmp = icon.getScaledInstance(intIconWidth, intIconWidth, Image.SCALE_SMOOTH);
  int marginWidth = ((imageWidth - intIconWidth) / 2);
  BufferedImage roundIcon = new BufferedImage(imageWidth, imageWidth, BufferedImage.TYPE_INT_ARGB);
  Graphics2D g2 = roundIcon.createGraphics();
  g2.setClip(new Ellipse2D.Float(marginWidth, marginWidth, intIconWidth, intIconWidth));
  g2.drawImage(tmp, marginWidth, marginWidth, null);
  return roundIcon;
}
 
Example 2
Source File: AG.java    From KEEL with GNU General Public License v3.0 5 votes vote down vote up
private int ceil(double v) {
  int valor;

  valor = (int) Math.round(v);
  if ( (double) valor < v) {
    valor++;
  }

  return (valor);
}
 
Example 3
Source File: AG.java    From KEEL with GNU General Public License v3.0 5 votes vote down vote up
private int ceil (double v) {
	int valor;

	valor = (int) Math.round(v);
	if ((double)valor < v) valor++;

	return (valor);
}
 
Example 4
Source File: AG.java    From KEEL with GNU General Public License v3.0 5 votes vote down vote up
private int ceil (double v) {
	int valor;

	valor = (int) Math.round(v);
	if ((double)valor < v) valor++;

	return (valor);
}
 
Example 5
Source File: AG.java    From KEEL with GNU General Public License v3.0 5 votes vote down vote up
private int ceil (double v) {
	int valor;

	valor = (int) Math.round(v);
	if ((double)valor < v) valor++;

	return (valor);
}
 
Example 6
Source File: GA_Tun.java    From KEEL with GNU General Public License v3.0 5 votes vote down vote up
private int ceil(double v) {
    int valor;

    valor = (int) Math.round(v);
    if ((double) valor < v) {
        valor++;
    }

    return (valor);
}
 
Example 7
Source File: GA.java    From KEEL with GNU General Public License v3.0 5 votes vote down vote up
private int ceil(double v) {
    int valor;

    valor = (int) Math.round(v);
    if ((double) valor < v) {
        valor++;
    }

    return (valor);
}
 
Example 8
Source File: Compiler.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
private BufferedImage produceForegroundImageIcon(BufferedImage icon) {
  int imageWidth = icon.getWidth();
  // According to the adaptive icon documentation, both layers are 108x108dp but only the inner
  // 72x72dp appears in the masked viewport, so we shrink down the size of the image accordingly.
  double iconWidth = imageWidth * 72.0 / 108.0;
  // Round iconWidth value to even int for a centered png
  int intIconWidth = ((int)Math.round(iconWidth / 2) * 2);
  Image tmp = icon.getScaledInstance(intIconWidth, intIconWidth, Image.SCALE_SMOOTH);
  int marginWidth = ((imageWidth - intIconWidth) / 2);
  BufferedImage foregroundImageIcon = new BufferedImage(imageWidth, imageWidth, BufferedImage.TYPE_INT_ARGB);
  Graphics2D g2 = foregroundImageIcon.createGraphics();
  g2.drawImage(tmp, marginWidth, marginWidth, null);
  return foregroundImageIcon;
}
 
Example 9
Source File: Compiler.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
private BufferedImage produceRoundedCornerIcon(BufferedImage icon) {
  int imageWidth = icon.getWidth();
  // Ratio of icon size to png image size for roundRect icon is 0.93
  double iconWidth = imageWidth * 0.93;
  // Round iconWidth value to even int for a centered png
  int intIconWidth = ((int)Math.round(iconWidth / 2) * 2);
  Image tmp = icon.getScaledInstance(intIconWidth, intIconWidth, Image.SCALE_SMOOTH);
  int marginWidth = ((imageWidth - intIconWidth) / 2);
  // Corner radius of roundedCornerIcon needs to be 1/12 of width according to Android material guidelines
  float cornerRadius = intIconWidth / 12;
  BufferedImage roundedCornerIcon = new BufferedImage(imageWidth, imageWidth, BufferedImage.TYPE_INT_ARGB);
  Graphics2D g2 = roundedCornerIcon.createGraphics();
  g2.setClip(new RoundRectangle2D.Float(marginWidth, marginWidth, intIconWidth, intIconWidth, cornerRadius, cornerRadius));
  g2.drawImage(tmp, marginWidth, marginWidth, null);
  return roundedCornerIcon;
}
 
Example 10
Source File: GamePadActivity.java    From bombsquad-remote-android with Apache License 2.0 5 votes vote down vote up
void _doStateChangeV1(boolean force) {

    // compile our state value
    short s = _buttonStateV1; // buttons
    s |= (_dPadStateH > 0 ? 1 : 0) << 5; // sign bit
    s |= ((int) (Math.round(Math.min(1.0, Math.abs(_dPadStateH)) * 15.0))) <<
        6; // mag
    s |= (_dPadStateV > 0 ? 1 : 0) << 10; // sign bit
    s |= ((int) (Math.round(Math.min(1.0, Math.abs(_dPadStateV)) * 15.0))) <<
        11; // mag

    // if our compiled state value hasn't changed, don't send.
    // (analog joystick noise can send a bunch of redundant states through here)
    // The exception is if forced is true, which is the case with packets that
    // double as keepalives.
    if ((s == _lastSentState) && (!force)) {
      return;
    }

    _stateBirthTimes[_nextState] = SystemClock.uptimeMillis();
    _stateLastSentTimes[_nextState] = 0;

    if (debug) {
      Log.v(TAG, "STORING NEXT STATE: " + _nextState);
    }
    _statesV1[_nextState] = s;
    _nextState = (_nextState + 1) % 256;
    _lastSentState = s;

    // if we're pretty up to date as far as state acks, lets go ahead
    // and send out this state immediately..
    // (keeps us nice and responsive on low latency networks)
    int unackedCount = (_nextState - _requestedState) & 0xFF; // upcast to
    // get
    // unsigned
    if (unackedCount < 3) {
      _shipUnAckedStatesV1();
    }
  }
 
Example 11
Source File: Utils.java    From iview-android-tv with MIT License 4 votes vote down vote up
public static int convertDpToPixel(Context ctx, int dp) {
    float density = ctx.getResources().getDisplayMetrics().density;
    return Math.round((float) dp * density);
}
 
Example 12
Source File: ReactVideoView.java    From react-native-video with MIT License 4 votes vote down vote up
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
    selectTimedMetadataTrack(mp);
    mVideoBufferedDuration = (int) Math.round((double) (mVideoDuration * percent) / 100.0);
}
 
Example 13
Source File: Utils.java    From KEEL with GNU General Public License v3.0 1 votes vote down vote up
/**
 * Rounds a double to the given number of decimal places.
 *
 * @param value the double value
 * @param afterDecimalPoint the number of digits after the decimal point
 * @return the double rounded to the given precision
 */
public static /*@pure@*/ double roundDouble(double value,int afterDecimalPoint) {

  double mask = Math.pow(10.0, (double)afterDecimalPoint);

  return (double)(Math.round(value * mask)) / mask;
}
 
Example 14
Source File: Utils.java    From KEEL with GNU General Public License v3.0 1 votes vote down vote up
/**
 * Rounds a double to the given number of decimal places.
 *
 * @param value the double value
 * @param afterDecimalPoint the number of digits after the decimal point
 * @return the double rounded to the given precision
 */
public static /*@pure@*/ double roundDouble(double value,int afterDecimalPoint) {

  double mask = Math.pow(10.0, (double)afterDecimalPoint);

  return (double)(Math.round(value * mask)) / mask;
}
 
Example 15
Source File: Utils.java    From KEEL with GNU General Public License v3.0 1 votes vote down vote up
/**
 * Rounds a double to the given number of decimal places.
 *
 * @param value the double value
 * @param afterDecimalPoint the number of digits after the decimal point
 * @return the double rounded to the given precision
 */
public static /*@pure@*/ double roundDouble(double value,int afterDecimalPoint) {

  double mask = Math.pow(10.0, (double)afterDecimalPoint);

  return (double)(Math.round(value * mask)) / mask;
}
 
Example 16
Source File: M5StaticUtils.java    From KEEL with GNU General Public License v3.0 1 votes vote down vote up
/**
 * Rounds a double to the given number of decimal places.
 *
 * @param value the double value
 * @param afterDecimalPoint the number of digits after the decimal point
 * @return the double rounded to the given precision
 */
public static double roundDouble(double value, int afterDecimalPoint) {

    double mask = Math.pow(10.0, (double) afterDecimalPoint);

    return (double) (Math.round(value * mask)) / mask;
}
 
Example 17
Source File: SystemFunctions.java    From incubator-retired-mrql with Apache License 2.0 votes vote down vote up
public static MR_int round ( MR_float x ) { return new MR_int((int)Math.round(x.get())); } 
Example 18
Source File: SystemFunctions.java    From incubator-retired-mrql with Apache License 2.0 votes vote down vote up
public static MR_long round ( MR_double x ) { return new MR_long(Math.round(x.get())); }