From cf0bd963084c580151c9300fd15a44fd1c94a0b0 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 11 Mar 2017 15:11:35 +1100 Subject: [PATCH] Optimize cuboid region contains --- .../sk89q/worldedit/regions/CuboidRegion.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java b/core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java index ed83ac25..3e3a81f0 100644 --- a/core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java +++ b/core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java @@ -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