Optimized //(h)sphere a bit and made the shell for //hsphere as thin as possible.

Dieser Commit ist enthalten in:
TomyLobo 2011-08-12 08:16:53 +02:00
Ursprung b74670fda6
Commit af2429467d

Datei anzeigen

@ -1813,15 +1813,28 @@ public class EditSession {
boolean filled) throws MaxChangedBlocksException { boolean filled) throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
int ceilRadius = (int) Math.ceil(radius); radius += 0.5;
final double radiusSq = radius*radius;
final double radius1Sq = (radius - 1)*(radius - 1);
final int ceilRadius = (int) Math.ceil(radius);
for (int x = 0; x <= ceilRadius; ++x) { for (int x = 0; x <= ceilRadius; ++x) {
for (int y = 0; y <= ceilRadius; ++y) { for (int y = 0; y <= ceilRadius; ++y) {
for (int z = 0; z <= ceilRadius; ++z) { for (int z = 0; z <= ceilRadius; ++z) {
Vector vec = pos.add(x, y, z); double dSq = lengthSq(x, y, z);
double d = vec.distance(pos);
if (d <= radius + 0.5 && (filled || d >= radius - 0.5)) { if (dSq > radiusSq)
if (setBlock(vec, block)) { continue;
if (!filled) {
if (dSq < radius1Sq)
continue;
if (lengthSq(x+1, y, z) <= radiusSq && lengthSq(x, y+1, z) <= radiusSq && lengthSq(x, y, z+1) <= radiusSq)
continue;
}
if (setBlock(pos.add(x, y, z), block)) {
++affected; ++affected;
} }
if (setBlock(pos.add(-x, y, z), block)) { if (setBlock(pos.add(-x, y, z), block)) {
@ -1848,11 +1861,14 @@ public class EditSession {
} }
} }
} }
}
return affected; return affected;
} }
private static final double lengthSq(int x, int y, int z) {
return x*x + y*y + z*z;
}
/** /**
* Makes a pyramid. * Makes a pyramid.
* *