singleCellular2Edge2 method
Implementation
double singleCellular2Edge2(double x, double y) {
final xr = x.round();
final yr = y.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++) {
final vec = cell2d[hash2D(seed, xi, yi) & 255];
final vecX = xi - x + vec.x;
final vecY = yi - y + vec.y;
final newDistance = vecX * vecX + vecY * vecY;
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++) {
final vec = cell2d[hash2D(seed, xi, yi) & 255];
final vecX = xi - x + vec.x;
final vecY = yi - y + vec.y;
final newDistance = vecX.abs() + vecY.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++) {
final vec = cell2d[hash2D(seed, xi, yi) & 255];
final vecX = xi - x + vec.x;
final vecY = yi - y + vec.y;
final newDistance =
(vecX.abs() + vecY.abs()) + (vecX * vecX + vecY * vecY);
distance2 = math.max(math.min(distance2, newDistance), distance);
distance = math.min(distance, newDistance);
}
}
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;
}
}