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

The following examples show how to use java.lang.Math#abs() . 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: ListenerIdMap.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Removes the mapping for the given key.  Returns the object to
 * which the key was mapped, or <code>null</code> otherwise.
 */
public Object remove(int key) {
  Entry[] table = this.table;
  int bucket = Math.abs(key) % table.length;

  for (Entry e = table[bucket], prev = null; e != null;
       prev = e, e = e.next) {
    if (key == e.key) {
      if (prev != null)
        prev.next = e.next;
      else
        table[bucket] = e.next;

      count--;
      Object oldValue = e.value;
      e.value = null;
      return oldValue;
    }
  }

  return null;
}
 
Example 2
Source File: Adap_Sel.java    From KEEL with GNU General Public License v3.0 6 votes vote down vote up
double eval_EC_cubr(char[] cromosoma) {
  int i;
  double ec, fitness;

  /* Se calcula la adecuacion de la base de conocimiento codificada en el
     cromosoma actual, se estudia la posible penalizacion del mismo y se
     devuelve el valor final */
  Decodifica(cromosoma);
  Cubrimientos_Base();

  if (mincb >= tau && min_reglas <= base_reglas.n_reglas) {
    ec = ErrorCuadratico();
    fitness = (1 + Math.abs(1.0 - medcb)) * ec * P(cromosoma);
  }
  else {
    fitness = maxEC;
  }

  return (fitness);
}
 
Example 3
Source File: ULight.java    From ure with MIT License 6 votes vote down vote up
public boolean canTouch(UCamera camera) {
    if (type == POINT) {
        int circleDistX = Math.abs(x - camera.getCenterColumn());
        int circleDistY = Math.abs(y - camera.getCenterRow());
        if (circleDistX > (camera.columns / 2 + getRange())) return false;
        if (circleDistY > (camera.rows / 2 + getRange())) return false;
        if (circleDistX <= (camera.columns / 2)) return true;
        if (circleDistY <= (camera.rows / 2)) return true;
        double cornerDistSq = Math.pow(circleDistX - camera.columns / 2, 2) + Math.pow(circleDistY - camera.rows / 2, 2);
        if (cornerDistSq <= Math.pow(getRange(), 2)) return true;
        return false;
    } else {
        int x1 = x-falloff; int x2 = x+width+falloff;
        int y1 = y-falloff; int y2 = y+height+falloff;
        if (x2 < camera.leftEdge) return false;
        if (y2 < camera.topEdge) return false;
        if (x1 > camera.rightEdge) return false;
        if (y1 > camera.bottomEdge) return false;
        return true;
    }
}
 
Example 4
Source File: BluetoothScanner.java    From Rumble with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
    long curTime = System.currentTimeMillis();
    if ((curTime - lastUpdate) > 100) {
        lastUpdate = curTime;

        gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
        gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
        gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];

        float x =  event.values[0] - gravity[0];
        float y = event.values[1] - gravity[1];
        float z = event.values[2] - gravity[2];

        float speed = Math.abs(x+y+z-linear_acceleration[0]-linear_acceleration[1]-linear_acceleration[2]);

        if(speed > 2) {
            if(trickleTimer > RESET_TRICKLE_THRESHOLD) {
                Log.d(TAG, "[!] phone moved, reset trickle timer");
                forceDiscovery();
            }
        }

        linear_acceleration[0] = x;
        linear_acceleration[1] = y;
        linear_acceleration[2] = z;
    }
}
 
Example 5
Source File: ListenerIdMap.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the object to which the given key is mapped.  If no
 * object is mapped to the given key, <code>null</code> is returned.
 *
 * @throws IllegalArgumentException
 *         <code>key</code> is less than zero
 */
public Object get(int key) {
 
  Entry[] table = this.table;
  int bucket = Math.abs(key) % table.length;
  for (Entry e = table[bucket]; e != null; e = e.next) {
    if (e.key == key) {
      return e.value;
    }
  }

  return null;
}
 
Example 6
Source File: Adap_M2TSK.java    From KEEL with GNU General Public License v3.0 5 votes vote down vote up
/** Mean Square Error(MSE) and Mean Linear Error(MLE) by test */
public void Error_tst () {
	int i, j;
	double suma1, suma2, fuerza;

	for (j=0,suma1=suma2=0.0; j<tabla_tst.long_tabla; j++) {
		fuerza=base_reglas.FLC_TSK (tabla_tst.datos[j].ejemplo);
		suma1 += Math.pow (tabla_tst.datos[j].ejemplo[tabla.n_var_estado]-fuerza,2.0);
		suma2 += Math.abs (tabla_tst.datos[j].ejemplo[tabla.n_var_estado]-fuerza);
	}

	EC = suma1 / (double)tabla_tst.long_tabla;
	EL = suma2 / (double)tabla_tst.long_tabla;
}
 
Example 7
Source File: Abs.java    From Llunatic with GNU General Public License v3.0 5 votes vote down vote up
public Object abs(Object param)
	throws ParseException
{
	if (param instanceof Complex)
	{
		return new Double(((Complex)param).abs());
	}
	else if (param instanceof Number)
	{
		return new Double(Math.abs(((Number)param).doubleValue()));
	}

	throw new ParseException("Invalid parameter type");
}
 
Example 8
Source File: Utils.java    From KEEL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Rounds a double to the next nearest integer value. The JDK version
 * of it doesn't work properly.
 *
 * @param value the double value
 * @return the resulting integer value
 */
public static /*@pure@*/ int round(double value) {

  int roundedValue = value > 0
    ? (int)(value + 0.5)
    : -(int)(Math.abs(value) + 0.5);

  return roundedValue;
}
 
Example 9
Source File: Adap_Sel.java    From KEEL with GNU General Public License v3.0 5 votes vote down vote up
void Error_tra() {
  int i, j;
  double suma1, suma2, fuerza;

  for (j = 0, suma1 = suma2 = 0.0; j < tabla.long_tabla; j++) {
    fuerza = base_reglas.FLC(tabla.datos[j].ejemplo);
    suma1 +=
        Math.pow(tabla.datos[j].ejemplo[tabla.n_var_estado] - fuerza, 2.0);
    suma2 += Math.abs(tabla.datos[j].ejemplo[tabla.n_var_estado] - fuerza);
  }

  EC = suma1 / (double) tabla.long_tabla;
  EL = suma2 / (double) tabla.long_tabla;
}
 
Example 10
Source File: Adap_Sel.java    From KEEL with GNU General Public License v3.0 5 votes vote down vote up
void Error_tst() {
  int i, j;
  double suma1, suma2, fuerza;

  for (j = 0, suma1 = suma2 = 0.0; j < tabla_tst.long_tabla; j++) {
    fuerza = base_reglas.FLC_TSK(tabla_tst.datos[j].ejemplo);
    suma1 +=
        Math.pow(tabla_tst.datos[j].ejemplo[tabla.n_var_estado] - fuerza, 2.0);
    suma2 += Math.abs(tabla_tst.datos[j].ejemplo[tabla.n_var_estado] - fuerza);
  }

  EC = suma1 / (double) tabla_tst.long_tabla;
  EL = suma2 / (double) tabla_tst.long_tabla;
}
 
Example 11
Source File: moments.java    From groovy with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
String line;
Vector nums = new Vector();
double num, sum = 0.0;
double mean = 0.0;
double average_deviation = 0.0;
double standard_deviation = 0.0;
double variance = 0.0;
double skew = 0.0;
double kurtosis = 0.0;
double median = 0.0;
double deviation = 0.0;
int i, n, mid = 0;

    try {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        while ((line = in.readLine()) != null) {
    num = Double.parseDouble(line);
    sum += num;
    nums.add(new Double(num));
        }
    } catch (IOException e) {
        System.err.println(e);
        return;
    }

n = nums.size();
mean = sum/n;
for (i=0; i<n; i++) {
    deviation = ((Double)nums.get(i)).doubleValue() - mean;
    average_deviation += Math.abs(deviation);
    variance += Math.pow(deviation,2);
    skew += Math.pow(deviation,3);
    kurtosis += Math.pow(deviation,4);
}
average_deviation /= n;
variance /= (n - 1);
standard_deviation = Math.sqrt(variance);
if (variance != 0.0) {
    skew /= (n * variance * standard_deviation);
    kurtosis = kurtosis/(n * variance * variance) - 3.0;
}

Collections.sort(nums);

mid = (n/2);
median = (n % 2 != 0) ?
    ((Double)nums.get(mid)).doubleValue() :
    (((Double)nums.get(mid)).doubleValue() +
     ((Double)nums.get(mid-1)).doubleValue())/2;

NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(13);
nf.setGroupingUsed(false);
nf.setMaximumFractionDigits(6);
nf.setMinimumFractionDigits(6);

System.out.println("n:                  " + n);
System.out.println("median:             " + nf.format(median));
System.out.println("mean:               " + nf.format(mean));
System.out.println("average_deviation:  " + nf.format(average_deviation));
System.out.println("standard_deviation: " + nf.format(standard_deviation));
System.out.println("variance:           " + nf.format(variance));
System.out.println("skew:               " + nf.format(skew));
System.out.println("kurtosis:           " + nf.format(kurtosis));
}
 
Example 12
Source File: Bearing.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/** @deprecated do not use */
@Deprecated
public static Bearing calculateBearing(Earth e, double lat1, double lon1, double lat2, double lon2, Bearing result) {
  if (result == null) {
    result = new Bearing();
  }

  if ((lat1 == lat2) && (lon1 == lon2)) {
    result.distance = 0;
    result.azimuth = 0;
    result.backazimuth = 0;
    return result;
  }

  double A = e.getMajor(); // Earth radius
  double F = e.getFlattening(); // Earth flattening value
  double R = 1.0 - F;

  double GLAT1 = DEGREES_TO_RADIANS * lat1;
  double GLAT2 = DEGREES_TO_RADIANS * lat2;
  double TU1 = R * Math.sin(GLAT1) / Math.cos(GLAT1);
  double TU2 = R * Math.sin(GLAT2) / Math.cos(GLAT2);
  double CU1 = 1. / Math.sqrt(TU1 * TU1 + 1.);
  double SU1 = CU1 * TU1;
  double CU2 = 1. / Math.sqrt(TU2 * TU2 + 1.);
  double S = CU1 * CU2;
  double BAZ = S * TU2;
  double FAZ = BAZ * TU1;
  double GLON1 = DEGREES_TO_RADIANS * lon1;
  double GLON2 = DEGREES_TO_RADIANS * lon2;
  double X = GLON2 - GLON1;
  double D, SX, CX, SY, CY, Y, SA, C2A, CZ, E, C;
  int loopCnt = 0;
  do {
    loopCnt++;
    // Check for an infinite loop
    if (loopCnt > 1000) {
      throw new IllegalArgumentException(
          "Too many iterations calculating bearing:" + lat1 + " " + lon1 + " " + lat2 + " " + lon2);
    }
    SX = Math.sin(X);
    CX = Math.cos(X);
    TU1 = CU2 * SX;
    TU2 = BAZ - SU1 * CU2 * CX;
    SY = Math.sqrt(TU1 * TU1 + TU2 * TU2);
    CY = S * CX + FAZ;
    Y = Math.atan2(SY, CY);
    SA = S * SX / SY;
    C2A = -SA * SA + 1.;
    CZ = FAZ + FAZ;
    if (C2A > 0.) {
      CZ = -CZ / C2A + CY;
    }
    E = CZ * CZ * 2. - 1.;
    C = ((-3. * C2A + 4.) * F + 4.) * C2A * F / 16.;
    D = X;
    X = ((E * CY * C + CZ) * SY * C + Y) * SA;
    X = (1. - C) * X * F + GLON2 - GLON1;
  } while (Math.abs(D - X) > EPS);

  FAZ = Math.atan2(TU1, TU2);
  BAZ = Math.atan2(CU1 * SX, BAZ * CX - SU1 * CU2) + Math.PI;
  X = Math.sqrt((1. / R / R - 1.) * C2A + 1.) + 1.;
  X = (X - 2.) / X;
  C = 1. - X;
  C = (X * X / 4. + 1.) / C;
  D = (0.375 * X * X - 1.) * X;
  X = E * CY;
  S = 1. - E - E;
  S = ((((SY * SY * 4. - 3.) * S * CZ * D / 6. - X) * D / 4. + CZ) * SY * D + Y) * C * A * R;

  result.distance = S / 1000.0; // meters to km
  result.azimuth = FAZ * RADIANS_TO_DEGREES; // radians to degrees

  if (result.azimuth < 0.0) {
    result.azimuth += 360.0; // reset azs from -180 to 180 to 0 to 360
  }

  result.backazimuth = BAZ * RADIANS_TO_DEGREES; // radians to degrees; already in 0 to 360 range

  return result;
}
 
Example 13
Source File: M5StaticUtils.java    From KEEL with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Rounds a double and converts it into String.
 *
 * @param value the double value
 * @param afterDecimalPoint the (maximum) number of digits permitted
 * after the decimal point
 * @return the double as a formatted string
 */
public static String doubleToString(double value, int afterDecimalPoint) {

    StringBuffer stringBuffer;
    double temp;
    int i, dotPosition;
    long precisionValue;

    temp = value * Math.pow(10.0, afterDecimalPoint);
    if (Math.abs(temp) < Long.MAX_VALUE) {
        precisionValue = (temp > 0) ? (long) (temp + 0.5)
                         : -(long) (Math.abs(temp) + 0.5);
        if (precisionValue == 0) {
            stringBuffer = new StringBuffer(String.valueOf(0));
        } else {
            stringBuffer = new StringBuffer(String.valueOf(precisionValue));
        }
        if (afterDecimalPoint == 0) {
            return stringBuffer.toString();
        }
        dotPosition = stringBuffer.length() - afterDecimalPoint;
        while (((precisionValue < 0) && (dotPosition < 1)) ||
               (dotPosition < 0)) {
            if (precisionValue < 0) {
                stringBuffer.insert(1, 0);
            } else {
                stringBuffer.insert(0, 0);
            }
            dotPosition++;
        }
        stringBuffer.insert(dotPosition, '.');
        if ((precisionValue < 0) && (stringBuffer.charAt(1) == '.')) {
            stringBuffer.insert(1, 0);
        } else if (stringBuffer.charAt(0) == '.') {
            stringBuffer.insert(0, 0);
        }
        int currentPos = stringBuffer.length() - 1;
        while ((currentPos > dotPosition) &&
               (stringBuffer.charAt(currentPos) == '0')) {
            stringBuffer.setCharAt(currentPos--, ' ');
        }
        if (stringBuffer.charAt(currentPos) == '.') {
            stringBuffer.setCharAt(currentPos, ' ');
        }

        return stringBuffer.toString().trim();
    }
    return new String("" + value);
}
 
Example 14
Source File: Moments.java    From faceswap with Apache License 2.0 4 votes vote down vote up
protected void completeState()
{
    double cx = 0, cy = 0;
    double mu20, mu11, mu02;
    double inv_m00 = 0.0;

    if( Math.abs(this.m00) > 0.00000001 )
    {
        inv_m00 = 1. / this.m00;
        cx = this.m10 * inv_m00;
        cy = this.m01 * inv_m00;
    }

    // mu20 = m20 - m10*cx
    mu20 = this.m20 - this.m10 * cx;
    // mu11 = m11 - m10*cy
    mu11 = this.m11 - this.m10 * cy;
    // mu02 = m02 - m01*cy
    mu02 = this.m02 - this.m01 * cy;

    this.mu20 = mu20;
    this.mu11 = mu11;
    this.mu02 = mu02;

    // mu30 = m30 - cx*(3*mu20 + cx*m10)
    this.mu30 = this.m30 - cx * (3 * mu20 + cx * this.m10);
    mu11 += mu11;
    // mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20
    this.mu21 = this.m21 - cx * (mu11 + cx * this.m01) - cy * mu20;
    // mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02
    this.mu12 = this.m12 - cy * (mu11 + cy * this.m10) - cx * mu02;
    // mu03 = m03 - cy*(3*mu02 + cy*m01)
    this.mu03 = this.m03 - cy * (3 * mu02 + cy * this.m01);


    double inv_sqrt_m00 = Math.sqrt(Math.abs(inv_m00));
    double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00;

    this.nu20 = this.mu20*s2;
    this.nu11 = this.mu11*s2;
    this.nu02 = this.mu02*s2;
    this.nu30 = this.mu30*s3;
    this.nu21 = this.mu21*s3;
    this.nu12 = this.mu12*s3;
    this.nu03 = this.mu03*s3;

}
 
Example 15
Source File: Moments.java    From OpenCV-Android-Object-Detection with MIT License 4 votes vote down vote up
protected void completeState()
{
    double cx = 0, cy = 0;
    double mu20, mu11, mu02;
    double inv_m00 = 0.0;

    if( Math.abs(this.m00) > 0.00000001 )
    {
        inv_m00 = 1. / this.m00;
        cx = this.m10 * inv_m00;
        cy = this.m01 * inv_m00;
    }

    // mu20 = m20 - m10*cx
    mu20 = this.m20 - this.m10 * cx;
    // mu11 = m11 - m10*cy
    mu11 = this.m11 - this.m10 * cy;
    // mu02 = m02 - m01*cy
    mu02 = this.m02 - this.m01 * cy;

    this.mu20 = mu20;
    this.mu11 = mu11;
    this.mu02 = mu02;

    // mu30 = m30 - cx*(3*mu20 + cx*m10)
    this.mu30 = this.m30 - cx * (3 * mu20 + cx * this.m10);
    mu11 += mu11;
    // mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20
    this.mu21 = this.m21 - cx * (mu11 + cx * this.m01) - cy * mu20;
    // mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02
    this.mu12 = this.m12 - cy * (mu11 + cy * this.m10) - cx * mu02;
    // mu03 = m03 - cy*(3*mu02 + cy*m01)
    this.mu03 = this.m03 - cy * (3 * mu02 + cy * this.m01);


    double inv_sqrt_m00 = Math.sqrt(Math.abs(inv_m00));
    double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00;

    this.nu20 = this.mu20*s2;
    this.nu11 = this.mu11*s2;
    this.nu02 = this.mu02*s2;
    this.nu30 = this.mu30*s3;
    this.nu21 = this.mu21*s3;
    this.nu12 = this.mu12*s3;
    this.nu03 = this.mu03*s3;

}
 
Example 16
Source File: Moments.java    From LPR with Apache License 2.0 4 votes vote down vote up
protected void completeState()
{
    double cx = 0, cy = 0;
    double mu20, mu11, mu02;
    double inv_m00 = 0.0;

    if( Math.abs(this.m00) > 0.00000001 )
    {
        inv_m00 = 1. / this.m00;
        cx = this.m10 * inv_m00;
        cy = this.m01 * inv_m00;
    }

    // mu20 = m20 - m10*cx
    mu20 = this.m20 - this.m10 * cx;
    // mu11 = m11 - m10*cy
    mu11 = this.m11 - this.m10 * cy;
    // mu02 = m02 - m01*cy
    mu02 = this.m02 - this.m01 * cy;

    this.mu20 = mu20;
    this.mu11 = mu11;
    this.mu02 = mu02;

    // mu30 = m30 - cx*(3*mu20 + cx*m10)
    this.mu30 = this.m30 - cx * (3 * mu20 + cx * this.m10);
    mu11 += mu11;
    // mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20
    this.mu21 = this.m21 - cx * (mu11 + cx * this.m01) - cy * mu20;
    // mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02
    this.mu12 = this.m12 - cy * (mu11 + cy * this.m10) - cx * mu02;
    // mu03 = m03 - cy*(3*mu02 + cy*m01)
    this.mu03 = this.m03 - cy * (3 * mu02 + cy * this.m01);


    double inv_sqrt_m00 = Math.sqrt(Math.abs(inv_m00));
    double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00;

    this.nu20 = this.mu20*s2;
    this.nu11 = this.mu11*s2;
    this.nu02 = this.mu02*s2;
    this.nu30 = this.mu30*s3;
    this.nu21 = this.mu21*s3;
    this.nu12 = this.mu12*s3;
    this.nu03 = this.mu03*s3;

}
 
Example 17
Source File: Moments.java    From MOAAP with MIT License 4 votes vote down vote up
protected void completeState()
{
    double cx = 0, cy = 0;
    double mu20, mu11, mu02;
    double inv_m00 = 0.0;

    if( Math.abs(this.m00) > 0.00000001 )
    {
        inv_m00 = 1. / this.m00;
        cx = this.m10 * inv_m00;
        cy = this.m01 * inv_m00;
    }

    // mu20 = m20 - m10*cx
    mu20 = this.m20 - this.m10 * cx;
    // mu11 = m11 - m10*cy
    mu11 = this.m11 - this.m10 * cy;
    // mu02 = m02 - m01*cy
    mu02 = this.m02 - this.m01 * cy;

    this.mu20 = mu20;
    this.mu11 = mu11;
    this.mu02 = mu02;

    // mu30 = m30 - cx*(3*mu20 + cx*m10)
    this.mu30 = this.m30 - cx * (3 * mu20 + cx * this.m10);
    mu11 += mu11;
    // mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20
    this.mu21 = this.m21 - cx * (mu11 + cx * this.m01) - cy * mu20;
    // mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02
    this.mu12 = this.m12 - cy * (mu11 + cy * this.m10) - cx * mu02;
    // mu03 = m03 - cy*(3*mu02 + cy*m01)
    this.mu03 = this.m03 - cy * (3 * mu02 + cy * this.m01);


    double inv_sqrt_m00 = Math.sqrt(Math.abs(inv_m00));
    double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00;

    this.nu20 = this.mu20*s2;
    this.nu11 = this.mu11*s2;
    this.nu02 = this.mu02*s2;
    this.nu30 = this.mu30*s3;
    this.nu21 = this.mu21*s3;
    this.nu12 = this.mu12*s3;
    this.nu03 = this.mu03*s3;

}
 
Example 18
Source File: DrawCommand.java    From fabric-carpet with MIT License 4 votes vote down vote up
private static int drawDiamond(CommandContext<ServerCommandSource> ctx, boolean solid) throws CommandSyntaxException
{
    BlockPos pos;
    int radius;
    BlockStateArgument block;
    Predicate<CachedBlockPosition> replacement;
    try
    {
        pos = getArg(ctx, BlockPosArgumentType::getBlockPos, "center");
        radius = getArg(ctx, IntegerArgumentType::getInteger, "radius");
        block = getArg(ctx, BlockStateArgumentType::getBlockState, "block");
        replacement = getArg(ctx, BlockPredicateArgumentType::getBlockPredicate, "filter", true);
    }
    catch (ErrorHandled ignored) { return 0; }

    ServerCommandSource source = ctx.getSource();

    int affected=0;

    BlockPos.Mutable mbpos = new BlockPos.Mutable(pos);
    List<BlockPos> list = Lists.newArrayList();

    ServerWorld world = source.getWorld();

    CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates;

    for (int r = 0; r < radius; ++r)
    {
        int y=r-radius+1;
        for (int x = -r; x <= r; ++x)
        {
            int z=r-Math.abs(x);

            affected+= setBlock(world, mbpos, pos.getX()+x, pos.getY()-y, pos.getZ()+z, block, replacement, list);
            affected+= setBlock(world, mbpos, pos.getX()+x, pos.getY()-y, pos.getZ()-z, block, replacement, list);
            affected+= setBlock(world, mbpos, pos.getX()+x, pos.getY()+y, pos.getZ()+z, block, replacement, list);
            affected+= setBlock(world, mbpos, pos.getX()+x, pos.getY()+y, pos.getZ()-z, block, replacement, list);
        }
    }

    CarpetSettings.impendingFillSkipUpdates = false;

    if (CarpetSettings.fillUpdates)
    {
        list.forEach(p -> world.updateNeighbors(p, world.getBlockState(p).getBlock()));
    }

    Messenger.m(source, "gi Filled " + affected + " blocks");

    return affected;
}
 
Example 19
Source File: Moments.java    From pasm-yolov3-Android with GNU General Public License v3.0 4 votes vote down vote up
protected void completeState()
{
    double cx = 0, cy = 0;
    double mu20, mu11, mu02;
    double inv_m00 = 0.0;

    if( Math.abs(this.m00) > 0.00000001 )
    {
        inv_m00 = 1. / this.m00;
        cx = this.m10 * inv_m00;
        cy = this.m01 * inv_m00;
    }

    // mu20 = m20 - m10*cx
    mu20 = this.m20 - this.m10 * cx;
    // mu11 = m11 - m10*cy
    mu11 = this.m11 - this.m10 * cy;
    // mu02 = m02 - m01*cy
    mu02 = this.m02 - this.m01 * cy;

    this.mu20 = mu20;
    this.mu11 = mu11;
    this.mu02 = mu02;

    // mu30 = m30 - cx*(3*mu20 + cx*m10)
    this.mu30 = this.m30 - cx * (3 * mu20 + cx * this.m10);
    mu11 += mu11;
    // mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20
    this.mu21 = this.m21 - cx * (mu11 + cx * this.m01) - cy * mu20;
    // mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02
    this.mu12 = this.m12 - cy * (mu11 + cy * this.m10) - cx * mu02;
    // mu03 = m03 - cy*(3*mu02 + cy*m01)
    this.mu03 = this.m03 - cy * (3 * mu02 + cy * this.m01);


    double inv_sqrt_m00 = Math.sqrt(Math.abs(inv_m00));
    double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00;

    this.nu20 = this.mu20*s2;
    this.nu11 = this.mu11*s2;
    this.nu02 = this.mu02*s2;
    this.nu30 = this.mu30*s3;
    this.nu21 = this.mu21*s3;
    this.nu12 = this.mu12*s3;
    this.nu03 = this.mu03*s3;

}
 
Example 20
Source File: SystemFunctions.java    From incubator-retired-mrql with Apache License 2.0 votes vote down vote up
public static MR_int abs ( MR_int x ) { return new MR_int(Math.abs(x.get())); }