Fix off-by-one in area calculation.

Even the volume calculation had it correct.
Also fix code style in contains.
This commit is contained in:
Wizjany 2018-01-21 00:31:47 -05:00 committed by GitHub
parent 0f72811bfc
commit 3a332fd87d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -125,9 +125,9 @@ public boolean contains(Vector pt) {
final double x = pt.getX(); final double x = pt.getX();
final double y = pt.getY(); final double y = pt.getY();
final double z = pt.getZ(); final double z = pt.getZ();
return x >= min.getBlockX() && x < max.getBlockX()+1 return x >= min.getBlockX() && x < max.getBlockX() + 1
&& y >= min.getBlockY() && y < max.getBlockY()+1 && y >= min.getBlockY() && y < max.getBlockY() + 1
&& z >= min.getBlockZ() && z < max.getBlockZ()+1; && z >= min.getBlockZ() && z < max.getBlockZ() + 1;
} }
@Override @Override
@ -139,8 +139,8 @@ public RegionType getType() {
Area toArea() { Area toArea() {
int x = getMinimumPoint().getBlockX(); int x = getMinimumPoint().getBlockX();
int z = getMinimumPoint().getBlockZ(); int z = getMinimumPoint().getBlockZ();
int width = getMaximumPoint().getBlockX() - x; int width = getMaximumPoint().getBlockX() - x + 1;
int height = getMaximumPoint().getBlockZ() - z; int height = getMaximumPoint().getBlockZ() - z + 1;
return new Area(new Rectangle(x, z, width, height)); return new Area(new Rectangle(x, z, width, height));
} }
@ -172,4 +172,4 @@ public int volume() {
} }
} }
} }