noise2 method

  1. @override
double noise2(
  1. double x,
  2. double y
)
override

Implementation

@override
double noise2(double x, double y) {
  int xr = round(x);
  int yr = round(y);
  double distance = 999999;
  double distance2 = 999999;
  for (int xi = xr - 1; xi <= xr + 1; xi++) {
    for (int yi = yr - 1; yi <= yr + 1; yi++) {
      D2 vec = CELL_2D[hash2D(seed, xi, yi) & 255];
      double vecX = xi - x + vec.x;
      double vecY = yi - y + vec.y;
      double newDistance =
          (vecX.abs() + vecY.abs()) + (vecX * vecX + vecY * vecY);
      distance2 = max(min(distance2, newDistance), distance);
      distance = min(distance, newDistance);
    }
  }

  return distance2 - distance - 1;
}