Change Vector hash codes (#456)

And add additional unit vectors where needed.
This commit is contained in:
Jesse Boyd 2019-04-04 23:36:19 +11:00 committed by wizjany
parent 35bb4deee9
commit 4de5487c51
9 changed files with 37 additions and 38 deletions

View File

@ -1182,7 +1182,7 @@ public class EditSession implements Extent, AutoCloseable {
checkNotNull(pattern);
BlockReplace replace = new BlockReplace(this, pattern);
RegionOffset offset = new RegionOffset(BlockVector3.at(0, 1, 0), replace);
RegionOffset offset = new RegionOffset(BlockVector3.UNIT_Y, replace);
GroundFunction ground = new GroundFunction(new ExistingBlockMask(this), offset);
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
Operations.completeLegacy(visitor);

View File

@ -568,15 +568,15 @@ public class SelectionCommands {
int change = args.getInteger(0);
if (!args.hasFlag('h')) {
changes.add((BlockVector3.at(0, 1, 0)).multiply(change));
changes.add((BlockVector3.at(0, -1, 0)).multiply(change));
changes.add((BlockVector3.UNIT_Y).multiply(change));
changes.add((BlockVector3.UNIT_MINUS_Y).multiply(change));
}
if (!args.hasFlag('v')) {
changes.add((BlockVector3.at(1, 0, 0)).multiply(change));
changes.add((BlockVector3.at(-1, 0, 0)).multiply(change));
changes.add((BlockVector3.at(0, 0, 1)).multiply(change));
changes.add((BlockVector3.at(0, 0, -1)).multiply(change));
changes.add((BlockVector3.UNIT_X).multiply(change));
changes.add((BlockVector3.UNIT_MINUS_X).multiply(change));
changes.add((BlockVector3.UNIT_Z).multiply(change));
changes.add((BlockVector3.UNIT_MINUS_Z).multiply(change));
}
return changes.toArray(new BlockVector3[0]);

View File

@ -26,6 +26,7 @@ import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.RunContext;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.Direction;
import java.util.ArrayDeque;
import java.util.ArrayList;
@ -85,22 +86,22 @@ public abstract class BreadthFirstSearch implements Operation {
* Add the directions along the axes as directions to visit.
*/
protected void addAxes() {
directions.add(BlockVector3.at(0, -1, 0));
directions.add(BlockVector3.at(0, 1, 0));
directions.add(BlockVector3.at(-1, 0, 0));
directions.add(BlockVector3.at(1, 0, 0));
directions.add(BlockVector3.at(0, 0, -1));
directions.add(BlockVector3.at(0, 0, 1));
directions.add(BlockVector3.UNIT_MINUS_Y);
directions.add(BlockVector3.UNIT_Y);
directions.add(BlockVector3.UNIT_MINUS_X);
directions.add(BlockVector3.UNIT_X);
directions.add(BlockVector3.UNIT_MINUS_Z);
directions.add(BlockVector3.UNIT_Z);
}
/**
* Add the diagonal directions as directions to visit.
*/
protected void addDiagonal() {
directions.add(BlockVector3.at(1, 0, 1));
directions.add(BlockVector3.at(-1, 0, -1));
directions.add(BlockVector3.at(1, 0, -1));
directions.add(BlockVector3.at(-1, 0, 1));
directions.add(Direction.NORTHEAST.toBlockVector());
directions.add(Direction.SOUTHEAST.toBlockVector());
directions.add(Direction.SOUTHWEST.toBlockVector());
directions.add(Direction.NORTHWEST.toBlockVector());
}
/**

View File

@ -53,11 +53,11 @@ public class DownwardVisitor extends RecursiveVisitor {
Collection<BlockVector3> directions = getDirections();
directions.clear();
directions.add(BlockVector3.at(1, 0, 0));
directions.add(BlockVector3.at(-1, 0, 0));
directions.add(BlockVector3.at(0, 0, 1));
directions.add(BlockVector3.at(0, 0, -1));
directions.add(BlockVector3.at(0, -1, 0));
directions.add(BlockVector3.UNIT_X);
directions.add(BlockVector3.UNIT_MINUS_X);
directions.add(BlockVector3.UNIT_Z);
directions.add(BlockVector3.UNIT_MINUS_Z);
directions.add(BlockVector3.UNIT_MINUS_Y);
}
@Override

View File

@ -40,11 +40,11 @@ public class NonRisingVisitor extends RecursiveVisitor {
super(mask, function);
Collection<BlockVector3> directions = getDirections();
directions.clear();
directions.add(BlockVector3.at(1, 0, 0));
directions.add(BlockVector3.at(-1, 0, 0));
directions.add(BlockVector3.at(0, 0, 1));
directions.add(BlockVector3.at(0, 0, -1));
directions.add(BlockVector3.at(0, -1, 0));
directions.add(BlockVector3.UNIT_X);
directions.add(BlockVector3.UNIT_MINUS_X);
directions.add(BlockVector3.UNIT_Z);
directions.add(BlockVector3.UNIT_MINUS_Z);
directions.add(BlockVector3.UNIT_MINUS_Y);
}
}

View File

@ -525,10 +525,7 @@ public final class BlockVector2 {
@Override
public int hashCode() {
int hash = 17;
hash = 31 * hash + Integer.hashCode(x);
hash = 31 * hash + Integer.hashCode(z);
return hash;
return (x << 16) ^ z;
}
@Override

View File

@ -35,6 +35,9 @@ public final class BlockVector3 {
public static final BlockVector3 UNIT_X = new BlockVector3(1, 0, 0);
public static final BlockVector3 UNIT_Y = new BlockVector3(0, 1, 0);
public static final BlockVector3 UNIT_Z = new BlockVector3(0, 0, 1);
public static final BlockVector3 UNIT_MINUS_X = new BlockVector3(-1, 0, 0);
public static final BlockVector3 UNIT_MINUS_Y = new BlockVector3(0, -1, 0);
public static final BlockVector3 UNIT_MINUS_Z = new BlockVector3(0, 0, -1);
public static final BlockVector3 ONE = new BlockVector3(1, 1, 1);
public static BlockVector3 at(double x, double y, double z) {
@ -609,11 +612,7 @@ public final class BlockVector3 {
@Override
public int hashCode() {
int hash = 17;
hash = 31 * hash + Integer.hashCode(x);
hash = 31 * hash + Integer.hashCode(y);
hash = 31 * hash + Integer.hashCode(z);
return hash;
return (x ^ (z << 12)) ^ (y << 24);
}
@Override

View File

@ -38,7 +38,7 @@ public class Node {
private double continuity;
public Node() {
this(Vector3.at(0, 0, 0));
this(Vector3.ZERO);
}
public Node(Node other) {

View File

@ -58,8 +58,10 @@ public enum Direction {
private final Vector3 direction;
private final int flags;
private final BlockVector3 blockPoint;
Direction(Vector3 vector, int flags) {
this.blockPoint = vector.toBlockPoint();
this.direction = vector.normalize();
this.flags = flags;
}
@ -121,7 +123,7 @@ public enum Direction {
* @return the vector
*/
public BlockVector3 toBlockVector() {
return direction.toBlockPoint();
return blockPoint;
}
/**