Change Vector hash codes (#456)

And add additional unit vectors where needed.
Dieser Commit ist enthalten in:
Jesse Boyd 2019-04-04 23:36:19 +11:00 committet von wizjany
Ursprung 35bb4deee9
Commit 4de5487c51
9 geänderte Dateien mit 37 neuen und 38 gelöschten Zeilen

Datei anzeigen

@ -1182,7 +1182,7 @@ public class EditSession implements Extent, AutoCloseable {
checkNotNull(pattern); checkNotNull(pattern);
BlockReplace replace = new BlockReplace(this, 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); GroundFunction ground = new GroundFunction(new ExistingBlockMask(this), offset);
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground); LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
Operations.completeLegacy(visitor); Operations.completeLegacy(visitor);

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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