double maxSum = 0;
double minSum = 0;
double weightSum = 0;
for (int sx = -SMOOTH_SIZE; sx <= SMOOTH_SIZE; sx++) {
for (int sz = -SMOOTH_SIZE; sz <= SMOOTH_SIZE; sz++) {
final NormalBiome adjacent;
if (xx + sx < 0 || zz + sz < 0
|| xx + sx >= sizeX || zz + sz >= sizeZ) {
if (biomeCache.containsKey(x + xx + sx, z + zz + sz)) {
adjacent = biomeCache.get(x + xx + sx, z + zz + sz);
} else {
adjacent = (NormalBiome) selector.pickBiome(x + xx + sx, y, z + zz + sz, seed);
biomeCache.put(x + xx + sx, z + zz + sz, adjacent);
}
} else {
adjacent = (NormalBiome) biomes.getBiome(xx + sx, y, zz + sz);
}
final double weight = GAUSSIAN_KERNEL[sx + SMOOTH_SIZE][sz + SMOOTH_SIZE];
minSum += adjacent.getMinElevation() * weight;
maxSum += adjacent.getMaxElevation() * weight;
weightSum += weight;
}
}
final double minElevation = minSum / weightSum;
final double smoothHeight = (maxSum / weightSum - minElevation) / 2;