singleCellular2Edge3 method

double singleCellular2Edge3(
  1. double x,
  2. double y,
  3. double z
)

Implementation

double singleCellular2Edge3(double x, double y, double z) {
  final xr = x.round();
  final yr = y.round();
  final zr = z.round();
  var distance = 999999.0;
  var distance2 = 999999.0;

  switch (cellularDistanceFunction) {
    case CellularDistanceFunction.euclidean:
      for (var xi = xr - 1; xi <= xr + 1; xi++) {
        for (var yi = yr - 1; yi <= yr + 1; yi++) {
          for (var zi = zr - 1; zi <= zr + 1; zi++) {
            final vec = cell3d[hash3D(seed, xi, yi, zi) & 255];

            final vecX = xi - x + vec.x;
            final vecY = yi - y + vec.y;
            final vecZ = zi - z + vec.z;
            final newDistance = vecX * vecX + vecY * vecY + vecZ * vecZ;

            distance2 = math.max(math.min(distance2, newDistance), distance);
            distance = math.min(distance, newDistance);
          }
        }
      }
      break;
    case CellularDistanceFunction.manhattan:
      for (var xi = xr - 1; xi <= xr + 1; xi++) {
        for (var yi = yr - 1; yi <= yr + 1; yi++) {
          for (var zi = zr - 1; zi <= zr + 1; zi++) {
            final vec = cell3d[hash3D(seed, xi, yi, zi) & 255];

            final vecX = xi - x + vec.x;
            final vecY = yi - y + vec.y;
            final vecZ = zi - z + vec.z;
            final newDistance = vecX.abs() + vecY.abs() + vecZ.abs();

            distance2 = math.max(math.min(distance2, newDistance), distance);
            distance = math.min(distance, newDistance);
          }
        }
      }
      break;
    case CellularDistanceFunction.natural:
      for (var xi = xr - 1; xi <= xr + 1; xi++) {
        for (var yi = yr - 1; yi <= yr + 1; yi++) {
          for (var zi = zr - 1; zi <= zr + 1; zi++) {
            final vec = cell3d[hash3D(seed, xi, yi, zi) & 255];

            final vecX = xi - x + vec.x;
            final vecY = yi - y + vec.y;
            final vecZ = zi - z + vec.z;
            final newDistance = (vecX.abs() + vecY.abs() + vecZ.abs()) +
                (vecX * vecX + vecY * vecY + vecZ * vecZ);

            distance2 = math.max(math.min(distance2, newDistance), distance);
            distance = math.min(distance, newDistance);
          }
        }
      }
      break;
    default:
      break;
  }

  switch (cellularReturnType) {
    case CellularReturnType.distance2:
      return distance2 - 1.0;
    case CellularReturnType.distance2Add:
      return distance2 + distance - 1.0;
    case CellularReturnType.distance2Sub:
      return distance2 - distance - 1.0;
    case CellularReturnType.distance2Mul:
      return distance2 * distance - 1.0;
    case CellularReturnType.distance2Div:
      return distance / distance2 - 1.0;
    default:
      return .0;
  }
}