noise method

  1. @override
double noise(
  1. double x,
  2. double y,
  3. double z
)

Implementation

@override
double noise(double x, double y, double z) {
  int xr = round(x);
  int yr = round(y);
  int zr = round(z);
  double distance = 999999;
  int xc = 0, yc = 0, zc = 0;
  for (int xi = xr - 1; xi <= xr + 1; xi++) {
    for (int yi = yr - 1; yi <= yr + 1; yi++) {
      for (int zi = zr - 1; zi <= zr + 1; zi++) {
        D3 vec = CELL_3D[hash3D(seed, xi, yi, zi) & 255];
        double vecX = xi - x + vec.x;
        double vecY = yi - y + vec.y;
        double vecZ = zi - z + vec.z;
        double newDistance = (vecX.abs() + vecY.abs() + vecZ.abs()) +
            (vecX * vecX + vecY * vecY + vecZ * vecZ);

        if (newDistance < distance) {
          distance = newDistance;
          xc = xi;
          yc = yi;
          zc = zi;
        }
      }
    }
  }

  return valCoord3D(0, xc, yc, zc);
}