Optimize cuboid region contains

This commit is contained in:
Jesse Boyd 2017-03-11 15:11:35 +11:00
parent 36f973e36c
commit cf0bd96308
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F

View File

@ -397,10 +397,29 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
@Override
public boolean contains(Vector position) {
int x = position.getBlockX();
int y = position.getBlockY();
int z = position.getBlockZ();
return x >= this.minX && x <= this.maxX && z >= this.minZ && z <= this.maxZ && y >= this.minY && y <= this.maxY;
return contains(position.getBlockX(), position.getBlockY(), position.getBlockZ());
}
private int ly = Integer.MIN_VALUE;
private int lz = Integer.MIN_VALUE;
private boolean lr, lry, lrz;
public boolean contains(int x, int y, int z) {
// return x >= this.minX && x <= this.maxX && z >= this.minZ && z <= this.maxZ && y >= this.minY && y <= this.maxY;
if (z != lz) {
lz = z;
lrz = z >= this.minZ && z <= this.maxZ;
if (y != ly) {
ly = y;
lry = y >= this.minY && y <= this.maxY;
}
lr = lrz && lry;
} else if (y != ly) {
ly = y;
lry = y >= this.minY && y <= this.maxY;
lr = lrz && lry;
}
return lr && (x >= this.minX && x <= this.maxX);
}
@Override