Exemplo n.º 1
0
  public float evaluate(float x, float y) {
    for (int j = 0; j < results.length; j++) results[j].distance = Float.POSITIVE_INFINITY;

    int ix = (int) x;
    int iy = (int) y;
    float fx = x - ix;
    float fy = y - iy;

    float d = checkCube(fx, fy, ix, iy, results);
    if (d > fy) d = checkCube(fx, fy + 1, ix, iy - 1, results);
    if (d > 1 - fy) d = checkCube(fx, fy - 1, ix, iy + 1, results);
    if (d > fx) {
      checkCube(fx + 1, fy, ix - 1, iy, results);
      if (d > fy) d = checkCube(fx + 1, fy + 1, ix - 1, iy - 1, results);
      if (d > 1 - fy) d = checkCube(fx + 1, fy - 1, ix - 1, iy + 1, results);
    }
    if (d > 1 - fx) {
      d = checkCube(fx - 1, fy, ix + 1, iy, results);
      if (d > fy) d = checkCube(fx - 1, fy + 1, ix + 1, iy - 1, results);
      if (d > 1 - fy) d = checkCube(fx - 1, fy - 1, ix + 1, iy + 1, results);
    }

    float t = 0;
    for (int i = 0; i < 3; i++) t += coefficients[i] * results[i].distance;
    if (angleCoefficient != 0) {
      float angle = (float) Math.atan2(y - results[0].y, x - results[0].x);
      if (angle < 0) angle += 2 * (float) Math.PI;
      angle /= 4 * (float) Math.PI;
      t += angleCoefficient * angle;
    }
    if (gradientCoefficient != 0) {
      float a = 1 / (results[0].dy + results[0].dx);
      t += gradientCoefficient * a;
    }
    return t;
  }