getDirections() {
return directions;
}
@@ -86,29 +85,29 @@ public abstract class BreadthFirstSearch implements Operation {
* Add the directions along the axes as directions to visit.
*/
protected void addAxes() {
- directions.add(new Vector(0, -1, 0));
- directions.add(new Vector(0, 1, 0));
- directions.add(new Vector(-1, 0, 0));
- directions.add(new Vector(1, 0, 0));
- directions.add(new Vector(0, 0, -1));
- directions.add(new Vector(0, 0, 1));
+ directions.add(new BlockVector3(0, -1, 0));
+ directions.add(new BlockVector3(0, 1, 0));
+ directions.add(new BlockVector3(-1, 0, 0));
+ directions.add(new BlockVector3(1, 0, 0));
+ directions.add(new BlockVector3(0, 0, -1));
+ directions.add(new BlockVector3(0, 0, 1));
}
/**
* Add the diagonal directions as directions to visit.
*/
protected void addDiagonal() {
- directions.add(new Vector(1, 0, 1));
- directions.add(new Vector(-1, 0, -1));
- directions.add(new Vector(1, 0, -1));
- directions.add(new Vector(-1, 0, 1));
+ directions.add(new BlockVector3(1, 0, 1));
+ directions.add(new BlockVector3(-1, 0, -1));
+ directions.add(new BlockVector3(1, 0, -1));
+ directions.add(new BlockVector3(-1, 0, 1));
}
/**
* Add the given location to the list of locations to visit, provided
* that it has not been visited. The position passed to this method
* will still be visited even if it fails
- * {@link #isVisitable(com.sk89q.worldedit.Vector, com.sk89q.worldedit.Vector)}.
+ * {@link #isVisitable(BlockVector3, BlockVector3)}.
*
* This method should be used before the search begins, because if
* the position does fail the test, and the search has already
@@ -118,8 +117,8 @@ public abstract class BreadthFirstSearch implements Operation {
*
* @param position the position
*/
- public void visit(Vector position) {
- BlockVector blockVector = position.toBlockVector();
+ public void visit(BlockVector3 position) {
+ BlockVector3 blockVector = position;
if (!visited.contains(blockVector)) {
queue.add(blockVector);
visited.add(blockVector);
@@ -132,8 +131,8 @@ public abstract class BreadthFirstSearch implements Operation {
* @param from the origin block
* @param to the block under question
*/
- private void visit(Vector from, Vector to) {
- BlockVector blockVector = to.toBlockVector();
+ private void visit(BlockVector3 from, BlockVector3 to) {
+ BlockVector3 blockVector = to;
if (!visited.contains(blockVector)) {
visited.add(blockVector);
if (isVisitable(from, to)) {
@@ -150,7 +149,7 @@ public abstract class BreadthFirstSearch implements Operation {
* @param to the block under question
* @return true if the 'to' block should be visited
*/
- protected abstract boolean isVisitable(Vector from, Vector to);
+ protected abstract boolean isVisitable(BlockVector3 from, BlockVector3 to);
/**
* Get the number of affected objects.
@@ -163,14 +162,14 @@ public abstract class BreadthFirstSearch implements Operation {
@Override
public Operation resume(RunContext run) throws WorldEditException {
- Vector position;
+ BlockVector3 position;
while ((position = queue.poll()) != null) {
if (function.apply(position)) {
affected++;
}
- for (Vector dir : directions) {
+ for (BlockVector3 dir : directions) {
visit(position, position.add(dir));
}
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java
index 3788d547d..62363a205 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java
@@ -21,9 +21,9 @@ package com.sk89q.worldedit.function.visitor;
import static com.google.common.base.Preconditions.checkNotNull;
-import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.mask.Mask;
+import com.sk89q.worldedit.math.BlockVector3;
import java.util.Collection;
@@ -51,17 +51,17 @@ public class DownwardVisitor extends RecursiveVisitor {
this.baseY = baseY;
- Collection directions = getDirections();
+ Collection directions = getDirections();
directions.clear();
- directions.add(new Vector(1, 0, 0));
- directions.add(new Vector(-1, 0, 0));
- directions.add(new Vector(0, 0, 1));
- directions.add(new Vector(0, 0, -1));
- directions.add(new Vector(0, -1, 0));
+ directions.add(new BlockVector3(1, 0, 0));
+ directions.add(new BlockVector3(-1, 0, 0));
+ directions.add(new BlockVector3(0, 0, 1));
+ directions.add(new BlockVector3(0, 0, -1));
+ directions.add(new BlockVector3(0, -1, 0));
}
@Override
- protected boolean isVisitable(Vector from, Vector to) {
+ protected boolean isVisitable(BlockVector3 from, BlockVector3 to) {
int fromY = from.getBlockY();
return (fromY == baseY || to.subtract(from).getBlockY() < 0) && super.isVisitable(from, to);
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java
index 1f0d96e42..46ef33dc0 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java
@@ -21,11 +21,11 @@ package com.sk89q.worldedit.function.visitor;
import static com.google.common.base.Preconditions.checkNotNull;
-import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.FlatRegionFunction;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.RunContext;
+import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.regions.FlatRegion;
import java.util.List;
@@ -64,7 +64,7 @@ public class FlatRegionVisitor implements Operation {
@Override
public Operation resume(RunContext run) throws WorldEditException {
- for (Vector2D pt : flatRegion.asFlatRegion()) {
+ for (BlockVector2 pt : flatRegion.asFlatRegion()) {
if (function.apply(pt)) {
affected++;
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/LayerVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/LayerVisitor.java
index b6dcf4882..f3a191e12 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/LayerVisitor.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/LayerVisitor.java
@@ -22,14 +22,14 @@ package com.sk89q.worldedit.function.visitor;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.LayerFunction;
import com.sk89q.worldedit.function.mask.Mask2D;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.RunContext;
+import com.sk89q.worldedit.math.BlockVector2;
+import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.FlatRegion;
import java.util.List;
@@ -92,20 +92,20 @@ public class LayerVisitor implements Operation {
@Override
public Operation resume(RunContext run) throws WorldEditException {
- for (Vector2D column : flatRegion.asFlatRegion()) {
+ for (BlockVector2 column : flatRegion.asFlatRegion()) {
if (!mask.test(column)) {
continue;
}
// Abort if we are underground
- if (function.isGround(column.toVector(maxY + 1))) {
+ if (function.isGround(column.toBlockVector3(maxY + 1))) {
return null;
}
boolean found = false;
int groundY = 0;
for (int y = maxY; y >= minY; --y) {
- Vector test = column.toVector(y);
+ BlockVector3 test = column.toBlockVector3(y);
if (!found) {
if (function.isGround(test)) {
found = true;
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/NonRisingVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/NonRisingVisitor.java
index 8be7466b1..21aa8b6f6 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/NonRisingVisitor.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/NonRisingVisitor.java
@@ -19,9 +19,9 @@
package com.sk89q.worldedit.function.visitor;
-import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.mask.Mask;
+import com.sk89q.worldedit.math.BlockVector3;
import java.util.Collection;
@@ -38,13 +38,13 @@ public class NonRisingVisitor extends RecursiveVisitor {
*/
public NonRisingVisitor(Mask mask, RegionFunction function) {
super(mask, function);
- Collection directions = getDirections();
+ Collection directions = getDirections();
directions.clear();
- directions.add(new Vector(1, 0, 0));
- directions.add(new Vector(-1, 0, 0));
- directions.add(new Vector(0, 0, 1));
- directions.add(new Vector(0, 0, -1));
- directions.add(new Vector(0, -1, 0));
+ directions.add(new BlockVector3(1, 0, 0));
+ directions.add(new BlockVector3(-1, 0, 0));
+ directions.add(new BlockVector3(0, 0, 1));
+ directions.add(new BlockVector3(0, 0, -1));
+ directions.add(new BlockVector3(0, -1, 0));
}
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RecursiveVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RecursiveVisitor.java
index ac89393a3..d3dda04f7 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RecursiveVisitor.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RecursiveVisitor.java
@@ -21,9 +21,9 @@ package com.sk89q.worldedit.function.visitor;
import static com.google.common.base.Preconditions.checkNotNull;
-import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.mask.Mask;
+import com.sk89q.worldedit.math.BlockVector3;
/**
* An implementation of an {@link BreadthFirstSearch} that uses a mask to
@@ -46,7 +46,7 @@ public class RecursiveVisitor extends BreadthFirstSearch {
}
@Override
- protected boolean isVisitable(Vector from, Vector to) {
+ protected boolean isVisitable(BlockVector3 from, BlockVector3 to) {
return mask.test(to);
}
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java
index d6fc7d45c..12a955c0d 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java
@@ -19,11 +19,11 @@
package com.sk89q.worldedit.function.visitor;
-import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
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.regions.Region;
import java.util.List;
@@ -53,7 +53,7 @@ public class RegionVisitor implements Operation {
@Override
public Operation resume(RunContext run) throws WorldEditException {
- for (Vector pt : region) {
+ for (BlockVector3 pt : region) {
if (function.apply(pt)) {
affected++;
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/BlockChange.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/BlockChange.java
index 4bb94aa09..1bbef8ab0 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/BlockChange.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/BlockChange.java
@@ -21,10 +21,10 @@ package com.sk89q.worldedit.history.change;
import static com.google.common.base.Preconditions.checkNotNull;
-import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.history.UndoContext;
+import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
/**
@@ -36,7 +36,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
*/
public class BlockChange implements Change {
- private final BlockVector position;
+ private final BlockVector3 position;
private final BlockStateHolder previous;
private final BlockStateHolder current;
@@ -47,7 +47,7 @@ public class BlockChange implements Change {
* @param previous the previous block
* @param current the current block
*/
- public BlockChange(BlockVector position, BlockStateHolder previous, BlockStateHolder current) {
+ public BlockChange(BlockVector3 position, BlockStateHolder previous, BlockStateHolder current) {
checkNotNull(position);
checkNotNull(previous);
checkNotNull(current);
@@ -61,7 +61,7 @@ public class BlockChange implements Change {
*
* @return the position
*/
- public BlockVector getPosition() {
+ public BlockVector3 getPosition() {
return position;
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java
index 23f724110..9c9ad2a85 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java
@@ -22,9 +22,9 @@ package com.sk89q.worldedit.history.changeset;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Iterators;
-import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.history.change.BlockChange;
import com.sk89q.worldedit.history.change.Change;
+import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.LocatedBlock;
import com.sk89q.worldedit.util.collection.LocatedBlockList;
@@ -42,7 +42,7 @@ import java.util.Iterator;
public class BlockOptimizedHistory extends ArrayListHistory {
private static Change createChange(LocatedBlock block) {
- return new BlockChange(block.getLocation().toBlockPoint(), block.getBlock(), block.getBlock());
+ return new BlockChange(block.getLocation(), block.getBlock(), block.getBlock());
}
private final LocatedBlockList previous = new LocatedBlockList();
@@ -54,7 +54,7 @@ public class BlockOptimizedHistory extends ArrayListHistory {
if (change instanceof BlockChange) {
BlockChange blockChange = (BlockChange) change;
- BlockVector position = blockChange.getPosition();
+ BlockVector3 position = blockChange.getPosition();
previous.add(position, blockChange.getPrevious());
current.add(position, blockChange.getCurrent());
} else {
@@ -80,5 +80,4 @@ public class BlockOptimizedHistory extends ArrayListHistory {
public int size() {
return super.size() + previous.size();
}
-
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/annotation/Direction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/annotation/Direction.java
index eac88237c..7f42b3a36 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/annotation/Direction.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/annotation/Direction.java
@@ -19,7 +19,7 @@
package com.sk89q.worldedit.internal.annotation;
-import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.math.Vector3;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -27,7 +27,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
- * Annotates a {@link Vector} parameter to inject a direction.
+ * Annotates a {@link Vector3} parameter to inject a direction.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java
index a6371961f..262bdd0af 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java
@@ -26,10 +26,10 @@ import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
-import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
+import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.command.parametric.AbstractInvokeListener;
import com.sk89q.worldedit.util.command.parametric.InvokeHandler;
import com.sk89q.worldedit.util.command.parametric.ParameterData;
@@ -102,13 +102,13 @@ public class CommandLoggingHandler extends AbstractInvokeListener implements Inv
}
if (logMode != null && sender.isPlayer()) {
- Vector position = player.getLocation().toVector();
+ Vector3 position = player.getLocation().toVector();
LocalSession session = worldEdit.getSessionManager().get(player);
switch (logMode) {
case PLACEMENT:
try {
- position = session.getPlacementPosition(player);
+ position = session.getPlacementPosition(player).toVector3();
} catch (IncompleteRegionException e) {
break;
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java
index 1bdeee5c5..4cdebe5cb 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java
@@ -23,10 +23,8 @@ import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.UnknownDirectionException;
-import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
-import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.NoMatchException;
@@ -38,6 +36,7 @@ import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.annotation.Direction;
import com.sk89q.worldedit.internal.annotation.Selection;
+import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
@@ -49,6 +48,7 @@ import com.sk89q.worldedit.util.command.parametric.ParameterException;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.biome.Biomes;
+import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
@@ -258,10 +258,10 @@ public class WorldEditBinding extends BindingHelper {
* @throws UnknownDirectionException on an unknown direction
*/
@BindingMatch(classifier = Direction.class,
- type = Vector.class,
+ type = BlockVector3.class,
behavior = BindingBehavior.CONSUMES,
consumedCount = 1)
- public Vector getDirection(ArgumentStack context, Direction direction)
+ public BlockVector3 getDirection(ArgumentStack context, Direction direction)
throws ParameterException, UnknownDirectionException {
Player sender = getPlayer(context);
return worldEdit.getDirection(sender, context.next());
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionCylinderEvent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionCylinderEvent.java
index d23fd9a74..d10f5fb68 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionCylinderEvent.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionCylinderEvent.java
@@ -21,15 +21,15 @@
package com.sk89q.worldedit.internal.cui;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.Vector2D;
+import com.sk89q.worldedit.math.BlockVector3;
+import com.sk89q.worldedit.math.Vector2;
public class SelectionCylinderEvent implements CUIEvent {
- protected final Vector pos;
- protected final Vector2D radius;
+ protected final BlockVector3 pos;
+ protected final Vector2 radius;
- public SelectionCylinderEvent(Vector pos, Vector2D radius) {
+ public SelectionCylinderEvent(BlockVector3 pos, Vector2 radius) {
this.pos = pos;
this.radius = radius;
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionEllipsoidPointEvent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionEllipsoidPointEvent.java
index 3e371b105..e8c051040 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionEllipsoidPointEvent.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionEllipsoidPointEvent.java
@@ -19,14 +19,14 @@
package com.sk89q.worldedit.internal.cui;
-import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.math.BlockVector3;
public class SelectionEllipsoidPointEvent implements CUIEvent {
protected final int id;
- protected final Vector pos;
+ protected final BlockVector3 pos;
- public SelectionEllipsoidPointEvent(int id, Vector pos) {
+ public SelectionEllipsoidPointEvent(int id, BlockVector3 pos) {
this.id = id;
this.pos = pos;
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionPoint2DEvent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionPoint2DEvent.java
index dc4d0adaa..1586dced9 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionPoint2DEvent.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionPoint2DEvent.java
@@ -19,27 +19,27 @@
package com.sk89q.worldedit.internal.cui;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.Vector2D;
+import com.sk89q.worldedit.math.BlockVector2;
+import com.sk89q.worldedit.math.BlockVector3;
public class SelectionPoint2DEvent implements CUIEvent {
protected final int id;
- protected final int blockx;
- protected final int blockz;
+ protected final int blockX;
+ protected final int blockZ;
protected final int area;
- public SelectionPoint2DEvent(int id, Vector2D pos, int area) {
+ public SelectionPoint2DEvent(int id, BlockVector2 pos, int area) {
this.id = id;
- this.blockx = pos.getBlockX();
- this.blockz = pos.getBlockZ();
+ this.blockX = pos.getX();
+ this.blockZ = pos.getZ();
this.area = area;
}
- public SelectionPoint2DEvent(int id, Vector pos, int area) {
+ public SelectionPoint2DEvent(int id, BlockVector3 pos, int area) {
this.id = id;
- this.blockx = pos.getBlockX();
- this.blockz = pos.getBlockZ();
+ this.blockX = pos.getX();
+ this.blockZ = pos.getZ();
this.area = area;
}
@@ -52,8 +52,8 @@ public class SelectionPoint2DEvent implements CUIEvent {
public String[] getParameters() {
return new String[] {
String.valueOf(id),
- String.valueOf(blockx),
- String.valueOf(blockz),
+ String.valueOf(blockX),
+ String.valueOf(blockZ),
String.valueOf(area)
};
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionPointEvent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionPointEvent.java
index e719b1855..baac3ab1f 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionPointEvent.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionPointEvent.java
@@ -19,15 +19,15 @@
package com.sk89q.worldedit.internal.cui;
-import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.math.BlockVector3;
public class SelectionPointEvent implements CUIEvent {
protected final int id;
- protected final Vector pos;
+ protected final BlockVector3 pos;
protected final int area;
- public SelectionPointEvent(int id, Vector pos, int area) {
+ public SelectionPointEvent(int id, BlockVector3 pos, int area) {
this.id = id;
this.pos = pos;
this.area = area;
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java
index af63bebe0..5a13140db 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java
@@ -26,9 +26,9 @@ import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
-import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player;
+import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
@@ -85,7 +85,7 @@ public class ServerCUIHandler {
}
} else {
CuboidRegion region = ((CuboidRegionSelector) regionSelector).getIncompleteRegion();
- Vector point;
+ BlockVector3 point;
if (region.getPos1() != null) {
point = region.getPos1();
} else if (region.getPos2() != null) {
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Functions.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Functions.java
index 4b4cbad13..9f7eaceb1 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Functions.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Functions.java
@@ -19,9 +19,9 @@
package com.sk89q.worldedit.internal.expression.runtime;
-import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.internal.expression.runtime.Function.Dynamic;
+import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.noise.PerlinNoise;
import com.sk89q.worldedit.math.noise.RidgedMultiFractalNoise;
import com.sk89q.worldedit.math.noise.VoronoiNoise;
@@ -392,7 +392,7 @@ public final class Functions {
} catch (IllegalArgumentException e) {
throw new EvaluationException(0, "Perlin noise error: " + e.getMessage());
}
- return perlin.noise(new Vector(x.getValue(), y.getValue(), z.getValue()));
+ return perlin.noise(new Vector3(x.getValue(), y.getValue(), z.getValue()));
}
private static final ThreadLocal localVoronoi = ThreadLocal.withInitial(VoronoiNoise::new);
@@ -405,7 +405,7 @@ public final class Functions {
} catch (IllegalArgumentException e) {
throw new EvaluationException(0, "Voronoi error: " + e.getMessage());
}
- return voronoi.noise(new Vector(x.getValue(), y.getValue(), z.getValue()));
+ return voronoi.noise(new Vector3(x.getValue(), y.getValue(), z.getValue()));
}
private static final ThreadLocal localRidgedMulti = ThreadLocal.withInitial(RidgedMultiFractalNoise::new);
@@ -419,7 +419,7 @@ public final class Functions {
} catch (IllegalArgumentException e) {
throw new EvaluationException(0, "Ridged multi error: " + e.getMessage());
}
- return ridgedMulti.noise(new Vector(x.getValue(), y.getValue(), z.getValue()));
+ return ridgedMulti.noise(new Vector3(x.getValue(), y.getValue(), z.getValue()));
}
private static double queryInternal(RValue type, RValue data, double typeId, double dataValue) throws EvaluationException {
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java
new file mode 100644
index 000000000..864e8c19c
--- /dev/null
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java
@@ -0,0 +1,529 @@
+/*
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q
+ * Copyright (C) WorldEdit team and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.worldedit.math;
+
+import com.google.common.collect.ComparisonChain;
+import com.sk89q.worldedit.math.transform.AffineTransform;
+
+import java.util.Comparator;
+
+/**
+ * An immutable 2-dimensional vector.
+ */
+public final class BlockVector2 {
+
+ public static final BlockVector2 ZERO = new BlockVector2(0, 0);
+ public static final BlockVector2 UNIT_X = new BlockVector2(1, 0);
+ public static final BlockVector2 UNIT_Z = new BlockVector2(0, 1);
+ public static final BlockVector2 ONE = new BlockVector2(1, 1);
+
+ /**
+ * A comparator for BlockVector2ds that orders the vectors by rows, with x as the
+ * column and z as the row.
+ *
+ * For example, if x is the horizontal axis and z is the vertical axis, it
+ * sorts like so:
+ *
+ *
+ * 0123
+ * 4567
+ * 90ab
+ * cdef
+ *
+ */
+ public static final Comparator COMPARING_GRID_ARRANGEMENT = (a, b) -> {
+ return ComparisonChain.start()
+ .compare(a.getBlockZ(), b.getBlockZ())
+ .compare(a.getBlockX(), b.getBlockX())
+ .result();
+ };
+
+ private final int x, z;
+
+ /**
+ * Construct an instance.
+ *
+ * @param x the X coordinate
+ * @param z the Z coordinate
+ */
+ public BlockVector2(double x, double z) {
+ this((int) Math.floor(x), (int) Math.floor(z));
+ }
+
+ /**
+ * Construct an instance.
+ *
+ * @param x the X coordinate
+ * @param z the Z coordinate
+ */
+ public BlockVector2(int x, int z) {
+ this.x = x;
+ this.z = z;
+ }
+
+ /**
+ * Get the X coordinate.
+ *
+ * @return the x coordinate
+ */
+ public int getX() {
+ return x;
+ }
+
+ /**
+ * Get the X coordinate.
+ *
+ * @return the x coordinate
+ */
+ public int getBlockX() {
+ return x;
+ }
+
+ /**
+ * Set the X coordinate.
+ *
+ * @param x the new X
+ * @return a new vector
+ */
+ public BlockVector2 withX(int x) {
+ return new BlockVector2(x, z);
+ }
+
+ /**
+ * Get the Z coordinate.
+ *
+ * @return the z coordinate
+ */
+ public int getZ() {
+ return z;
+ }
+
+ /**
+ * Get the Z coordinate.
+ *
+ * @return the z coordinate
+ */
+ public int getBlockZ() {
+ return z;
+ }
+
+ /**
+ * Set the Z coordinate.
+ *
+ * @param z the new Z
+ * @return a new vector
+ */
+ public BlockVector2 withZ(int z) {
+ return new BlockVector2(x, z);
+ }
+
+ /**
+ * Add another vector to this vector and return the result as a new vector.
+ *
+ * @param other the other vector
+ * @return a new vector
+ */
+ public BlockVector2 add(BlockVector2 other) {
+ return add(other.x, other.z);
+ }
+
+ /**
+ * Add another vector to this vector and return the result as a new vector.
+ *
+ * @param x the value to add
+ * @param z the value to add
+ * @return a new vector
+ */
+ public BlockVector2 add(int x, int z) {
+ return new BlockVector2(this.x + x, this.z + z);
+ }
+
+ /**
+ * Add a list of vectors to this vector and return the
+ * result as a new vector.
+ *
+ * @param others an array of vectors
+ * @return a new vector
+ */
+ public BlockVector2 add(BlockVector2... others) {
+ int newX = x, newZ = z;
+
+ for (BlockVector2 other : others) {
+ newX += other.x;
+ newZ += other.z;
+ }
+
+ return new BlockVector2(newX, newZ);
+ }
+
+ /**
+ * Subtract another vector from this vector and return the result
+ * as a new vector.
+ *
+ * @param other the other vector
+ * @return a new vector
+ */
+ public BlockVector2 subtract(BlockVector2 other) {
+ return subtract(other.x, other.z);
+ }
+
+ /**
+ * Subtract another vector from this vector and return the result
+ * as a new vector.
+ *
+ * @param x the value to subtract
+ * @param z the value to subtract
+ * @return a new vector
+ */
+ public BlockVector2 subtract(int x, int z) {
+ return new BlockVector2(this.x - x, this.z - z);
+ }
+
+ /**
+ * Subtract a list of vectors from this vector and return the result
+ * as a new vector.
+ *
+ * @param others an array of vectors
+ * @return a new vector
+ */
+ public BlockVector2 subtract(BlockVector2... others) {
+ int newX = x, newZ = z;
+
+ for (BlockVector2 other : others) {
+ newX -= other.x;
+ newZ -= other.z;
+ }
+
+ return new BlockVector2(newX, newZ);
+ }
+
+ /**
+ * Multiply this vector by another vector on each component.
+ *
+ * @param other the other vector
+ * @return a new vector
+ */
+ public BlockVector2 multiply(BlockVector2 other) {
+ return multiply(other.x, other.z);
+ }
+
+ /**
+ * Multiply this vector by another vector on each component.
+ *
+ * @param x the value to multiply
+ * @param z the value to multiply
+ * @return a new vector
+ */
+ public BlockVector2 multiply(int x, int z) {
+ return new BlockVector2(this.x * x, this.z * z);
+ }
+
+ /**
+ * Multiply this vector by zero or more vectors on each component.
+ *
+ * @param others an array of vectors
+ * @return a new vector
+ */
+ public BlockVector2 multiply(BlockVector2... others) {
+ int newX = x, newZ = z;
+
+ for (BlockVector2 other : others) {
+ newX *= other.x;
+ newZ *= other.z;
+ }
+
+ return new BlockVector2(newX, newZ);
+ }
+
+ /**
+ * Perform scalar multiplication and return a new vector.
+ *
+ * @param n the value to multiply
+ * @return a new vector
+ */
+ public BlockVector2 multiply(int n) {
+ return multiply(n, n);
+ }
+
+ /**
+ * Divide this vector by another vector on each component.
+ *
+ * @param other the other vector
+ * @return a new vector
+ */
+ public BlockVector2 divide(BlockVector2 other) {
+ return divide(other.x, other.z);
+ }
+
+ /**
+ * Divide this vector by another vector on each component.
+ *
+ * @param x the value to divide by
+ * @param z the value to divide by
+ * @return a new vector
+ */
+ public BlockVector2 divide(int x, int z) {
+ return new BlockVector2(this.x / x, this.z / z);
+ }
+
+ /**
+ * Perform scalar division and return a new vector.
+ *
+ * @param n the value to divide by
+ * @return a new vector
+ */
+ public BlockVector2 divide(int n) {
+ return divide(n, n);
+ }
+
+ /**
+ * Get the length of the vector.
+ *
+ * @return length
+ */
+ public double length() {
+ return Math.sqrt(lengthSq());
+ }
+
+ /**
+ * Get the length, squared, of the vector.
+ *
+ * @return length, squared
+ */
+ public int lengthSq() {
+ return x * x + z * z;
+ }
+
+ /**
+ * Get the distance between this vector and another vector.
+ *
+ * @param other the other vector
+ * @return distance
+ */
+ public double distance(BlockVector2 other) {
+ return Math.sqrt(distanceSq(other));
+ }
+
+ /**
+ * Get the distance between this vector and another vector, squared.
+ *
+ * @param other the other vector
+ * @return distance
+ */
+ public int distanceSq(BlockVector2 other) {
+ int dx = other.x - x;
+ int dz = other.z - z;
+ return dx * dx + dz * dz;
+ }
+
+ /**
+ * Get the normalized vector, which is the vector divided by its
+ * length, as a new vector.
+ *
+ * @return a new vector
+ */
+ public BlockVector2 normalize() {
+ double len = length();
+ double x = this.x / len;
+ double z = this.z / len;
+ return new BlockVector2(x, z);
+ }
+
+ /**
+ * Gets the dot product of this and another vector.
+ *
+ * @param other the other vector
+ * @return the dot product of this and the other vector
+ */
+ public int dot(BlockVector2 other) {
+ return x * other.x + z * other.z;
+ }
+
+ /**
+ * Checks to see if a vector is contained with another.
+ *
+ * @param min the minimum point (X, Y, and Z are the lowest)
+ * @param max the maximum point (X, Y, and Z are the lowest)
+ * @return true if the vector is contained
+ */
+ public boolean containedWithin(BlockVector2 min, BlockVector2 max) {
+ return x >= min.x && x <= max.x
+ && z >= min.z && z <= max.z;
+ }
+
+ /**
+ * Floors the values of all components.
+ *
+ * @return a new vector
+ */
+ public BlockVector2 floor() {
+ // already floored, kept for feature parity with Vector2
+ return this;
+ }
+
+ /**
+ * Rounds all components up.
+ *
+ * @return a new vector
+ */
+ public BlockVector2 ceil() {
+ // already raised, kept for feature parity with Vector2
+ return this;
+ }
+
+ /**
+ * Rounds all components to the closest integer.
+ *
+ * Components < 0.5 are rounded down, otherwise up.
+ *
+ * @return a new vector
+ */
+ public BlockVector2 round() {
+ // already rounded, kept for feature parity with Vector2
+ return this;
+ }
+
+ /**
+ * Returns a vector with the absolute values of the components of
+ * this vector.
+ *
+ * @return a new vector
+ */
+ public BlockVector2 abs() {
+ return new BlockVector2(Math.abs(x), Math.abs(z));
+ }
+
+ /**
+ * Perform a 2D transformation on this vector and return a new one.
+ *
+ * @param angle in degrees
+ * @param aboutX about which x coordinate to rotate
+ * @param aboutZ about which z coordinate to rotate
+ * @param translateX what to add after rotation
+ * @param translateZ what to add after rotation
+ * @return a new vector
+ * @see AffineTransform another method to transform vectors
+ */
+ public BlockVector2 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
+ angle = Math.toRadians(angle);
+ double x = this.x - aboutX;
+ double z = this.z - aboutZ;
+ double cos = Math.cos(angle);
+ double sin = Math.sin(angle);
+ double x2 = x * cos - z * sin;
+ double z2 = x * sin + z * cos;
+ return new BlockVector2(
+ x2 + aboutX + translateX,
+ z2 + aboutZ + translateZ);
+ }
+
+ /**
+ * Gets the minimum components of two vectors.
+ *
+ * @param v2 the second vector
+ * @return minimum
+ */
+ public BlockVector2 getMinimum(BlockVector2 v2) {
+ return new BlockVector2(
+ Math.min(x, v2.x),
+ Math.min(z, v2.z)
+ );
+ }
+
+ /**
+ * Gets the maximum components of two vectors.
+ *
+ * @param v2 the second vector
+ * @return maximum
+ */
+ public BlockVector2 getMaximum(BlockVector2 v2) {
+ return new BlockVector2(
+ Math.max(x, v2.x),
+ Math.max(z, v2.z)
+ );
+ }
+
+ public Vector2 toVector2() {
+ return new Vector2(x, z);
+ }
+
+ /**
+ * Creates a 3D vector by adding a zero Y component to this vector.
+ *
+ * @return a new vector
+ */
+ public Vector3 toVector3() {
+ return toVector3(0);
+ }
+
+ /**
+ * Creates a 3D vector by adding the specified Y component to this vector.
+ *
+ * @param y the Y component
+ * @return a new vector
+ */
+ public Vector3 toVector3(double y) {
+ return new Vector3(x, y, z);
+ }
+
+ /**
+ * Creates a 3D vector by adding a zero Y component to this vector.
+ *
+ * @return a new vector
+ */
+ public BlockVector3 toBlockVector3() {
+ return toBlockVector3(0);
+ }
+
+ /**
+ * Creates a 3D vector by adding the specified Y component to this vector.
+ *
+ * @param y the Y component
+ * @return a new vector
+ */
+ public BlockVector3 toBlockVector3(int y) {
+ return new BlockVector3(x, y, z);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof BlockVector2)) {
+ return false;
+ }
+
+ BlockVector2 other = (BlockVector2) obj;
+ return other.x == this.x && other.z == this.z;
+
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 17;
+ hash = 31 * hash + Integer.hashCode(x);
+ hash = 31 * hash + Integer.hashCode(z);
+ return hash;
+ }
+
+ @Override
+ public String toString() {
+ return "(" + x + ", " + z + ")";
+ }
+
+}
\ No newline at end of file
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java
new file mode 100644
index 000000000..efe56e8af
--- /dev/null
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java
@@ -0,0 +1,613 @@
+/*
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q
+ * Copyright (C) WorldEdit team and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.worldedit.math;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import com.google.common.collect.ComparisonChain;
+import com.sk89q.worldedit.math.transform.AffineTransform;
+
+import java.util.Comparator;
+
+/**
+ * An immutable 3-dimensional vector.
+ */
+public final class BlockVector3 {
+
+ public static final BlockVector3 ZERO = new BlockVector3(0, 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_Z = new BlockVector3(0, 0, 1);
+ public static final BlockVector3 ONE = new BlockVector3(1, 1, 1);
+
+ // thread-safe initialization idiom
+ private static final class YzxOrderComparator {
+ private static final Comparator YZX_ORDER = (a, b) -> {
+ return ComparisonChain.start()
+ .compare(a.y, b.y)
+ .compare(a.z, b.z)
+ .compare(a.x, b.x)
+ .result();
+ };
+ }
+
+ /**
+ * Returns a comparator that sorts vectors first by Y, then Z, then X.
+ *
+ *
+ * Useful for sorting by chunk block storage order.
+ */
+ public static Comparator sortByCoordsYzx() {
+ return YzxOrderComparator.YZX_ORDER;
+ }
+
+ private final int x, y, z;
+
+ /**
+ * Construct an instance.
+ *
+ * @param x the X coordinate
+ * @param y the Y coordinate
+ * @param z the Z coordinate
+ */
+ public BlockVector3(double x, double y, double z) {
+ this((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z));
+ }
+
+ /**
+ * Construct an instance.
+ *
+ * @param x the X coordinate
+ * @param y the Y coordinate
+ * @param z the Z coordinate
+ */
+ public BlockVector3(int x, int y, int z) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+
+ /**
+ * Get the X coordinate.
+ *
+ * @return the x coordinate
+ */
+ public int getX() {
+ return x;
+ }
+
+ /**
+ * Get the X coordinate.
+ *
+ * @return the x coordinate
+ */
+ public int getBlockX() {
+ return x;
+ }
+
+ /**
+ * Set the X coordinate.
+ *
+ * @param x the new X
+ * @return a new vector
+ */
+ public BlockVector3 withX(int x) {
+ return new BlockVector3(x, y, z);
+ }
+
+ /**
+ * Get the Y coordinate.
+ *
+ * @return the y coordinate
+ */
+ public int getY() {
+ return y;
+ }
+
+ /**
+ * Get the Y coordinate.
+ *
+ * @return the y coordinate
+ */
+ public int getBlockY() {
+ return y;
+ }
+
+ /**
+ * Set the Y coordinate.
+ *
+ * @param y the new Y
+ * @return a new vector
+ */
+ public BlockVector3 withY(int y) {
+ return new BlockVector3(x, y, z);
+ }
+
+ /**
+ * Get the Z coordinate.
+ *
+ * @return the z coordinate
+ */
+ public int getZ() {
+ return z;
+ }
+
+ /**
+ * Get the Z coordinate.
+ *
+ * @return the z coordinate
+ */
+ public int getBlockZ() {
+ return z;
+ }
+
+ /**
+ * Set the Z coordinate.
+ *
+ * @param z the new Z
+ * @return a new vector
+ */
+ public BlockVector3 withZ(int z) {
+ return new BlockVector3(x, y, z);
+ }
+
+ /**
+ * Add another vector to this vector and return the result as a new vector.
+ *
+ * @param other the other vector
+ * @return a new vector
+ */
+ public BlockVector3 add(BlockVector3 other) {
+ return add(other.x, other.y, other.z);
+ }
+
+ /**
+ * Add another vector to this vector and return the result as a new vector.
+ *
+ * @param x the value to add
+ * @param y the value to add
+ * @param z the value to add
+ * @return a new vector
+ */
+ public BlockVector3 add(int x, int y, int z) {
+ return new BlockVector3(this.x + x, this.y + y, this.z + z);
+ }
+
+ /**
+ * Add a list of vectors to this vector and return the
+ * result as a new vector.
+ *
+ * @param others an array of vectors
+ * @return a new vector
+ */
+ public BlockVector3 add(BlockVector3... others) {
+ int newX = x, newY = y, newZ = z;
+
+ for (BlockVector3 other : others) {
+ newX += other.x;
+ newY += other.y;
+ newZ += other.z;
+ }
+
+ return new BlockVector3(newX, newY, newZ);
+ }
+
+ /**
+ * Subtract another vector from this vector and return the result
+ * as a new vector.
+ *
+ * @param other the other vector
+ * @return a new vector
+ */
+ public BlockVector3 subtract(BlockVector3 other) {
+ return subtract(other.x, other.y, other.z);
+ }
+
+ /**
+ * Subtract another vector from this vector and return the result
+ * as a new vector.
+ *
+ * @param x the value to subtract
+ * @param y the value to subtract
+ * @param z the value to subtract
+ * @return a new vector
+ */
+ public BlockVector3 subtract(int x, int y, int z) {
+ return new BlockVector3(this.x - x, this.y - y, this.z - z);
+ }
+
+ /**
+ * Subtract a list of vectors from this vector and return the result
+ * as a new vector.
+ *
+ * @param others an array of vectors
+ * @return a new vector
+ */
+ public BlockVector3 subtract(BlockVector3... others) {
+ int newX = x, newY = y, newZ = z;
+
+ for (BlockVector3 other : others) {
+ newX -= other.x;
+ newY -= other.y;
+ newZ -= other.z;
+ }
+
+ return new BlockVector3(newX, newY, newZ);
+ }
+
+ /**
+ * Multiply this vector by another vector on each component.
+ *
+ * @param other the other vector
+ * @return a new vector
+ */
+ public BlockVector3 multiply(BlockVector3 other) {
+ return multiply(other.x, other.y, other.z);
+ }
+
+ /**
+ * Multiply this vector by another vector on each component.
+ *
+ * @param x the value to multiply
+ * @param y the value to multiply
+ * @param z the value to multiply
+ * @return a new vector
+ */
+ public BlockVector3 multiply(int x, int y, int z) {
+ return new BlockVector3(this.x * x, this.y * y, this.z * z);
+ }
+
+ /**
+ * Multiply this vector by zero or more vectors on each component.
+ *
+ * @param others an array of vectors
+ * @return a new vector
+ */
+ public BlockVector3 multiply(BlockVector3... others) {
+ int newX = x, newY = y, newZ = z;
+
+ for (BlockVector3 other : others) {
+ newX *= other.x;
+ newY *= other.y;
+ newZ *= other.z;
+ }
+
+ return new BlockVector3(newX, newY, newZ);
+ }
+
+ /**
+ * Perform scalar multiplication and return a new vector.
+ *
+ * @param n the value to multiply
+ * @return a new vector
+ */
+ public BlockVector3 multiply(int n) {
+ return multiply(n, n, n);
+ }
+
+ /**
+ * Divide this vector by another vector on each component.
+ *
+ * @param other the other vector
+ * @return a new vector
+ */
+ public BlockVector3 divide(BlockVector3 other) {
+ return divide(other.x, other.y, other.z);
+ }
+
+ /**
+ * Divide this vector by another vector on each component.
+ *
+ * @param x the value to divide by
+ * @param y the value to divide by
+ * @param z the value to divide by
+ * @return a new vector
+ */
+ public BlockVector3 divide(int x, int y, int z) {
+ return new BlockVector3(this.x / x, this.y / y, this.z / z);
+ }
+
+ /**
+ * Perform scalar division and return a new vector.
+ *
+ * @param n the value to divide by
+ * @return a new vector
+ */
+ public BlockVector3 divide(int n) {
+ return divide(n, n, n);
+ }
+
+ /**
+ * Get the length of the vector.
+ *
+ * @return length
+ */
+ public double length() {
+ return Math.sqrt(lengthSq());
+ }
+
+ /**
+ * Get the length, squared, of the vector.
+ *
+ * @return length, squared
+ */
+ public int lengthSq() {
+ return x * x + y * y + z * z;
+ }
+
+ /**
+ * Get the distance between this vector and another vector.
+ *
+ * @param other the other vector
+ * @return distance
+ */
+ public double distance(BlockVector3 other) {
+ return Math.sqrt(distanceSq(other));
+ }
+
+ /**
+ * Get the distance between this vector and another vector, squared.
+ *
+ * @param other the other vector
+ * @return distance
+ */
+ public int distanceSq(BlockVector3 other) {
+ int dx = other.x - x;
+ int dy = other.y - y;
+ int dz = other.z - z;
+ return dx * dx + dy * dy + dz * dz;
+ }
+
+ /**
+ * Get the normalized vector, which is the vector divided by its
+ * length, as a new vector.
+ *
+ * @return a new vector
+ */
+ public BlockVector3 normalize() {
+ double len = length();
+ double x = this.x / len;
+ double y = this.y / len;
+ double z = this.z / len;
+ return new BlockVector3(x, y, z);
+ }
+
+ /**
+ * Gets the dot product of this and another vector.
+ *
+ * @param other the other vector
+ * @return the dot product of this and the other vector
+ */
+ public double dot(BlockVector3 other) {
+ return x * other.x + y * other.y + z * other.z;
+ }
+
+ /**
+ * Gets the cross product of this and another vector.
+ *
+ * @param other the other vector
+ * @return the cross product of this and the other vector
+ */
+ public BlockVector3 cross(BlockVector3 other) {
+ return new BlockVector3(
+ y * other.z - z * other.y,
+ z * other.x - x * other.z,
+ x * other.y - y * other.x
+ );
+ }
+
+ /**
+ * Checks to see if a vector is contained with another.
+ *
+ * @param min the minimum point (X, Y, and Z are the lowest)
+ * @param max the maximum point (X, Y, and Z are the lowest)
+ * @return true if the vector is contained
+ */
+ public boolean containedWithin(BlockVector3 min, BlockVector3 max) {
+ return x >= min.x && x <= max.x && y >= min.y && y <= max.y && z >= min.z && z <= max.z;
+ }
+
+ /**
+ * Clamp the Y component.
+ *
+ * @param min the minimum value
+ * @param max the maximum value
+ * @return a new vector
+ */
+ public BlockVector3 clampY(int min, int max) {
+ checkArgument(min <= max, "minimum cannot be greater than maximum");
+ if (y < min) {
+ return new BlockVector3(x, min, z);
+ }
+ if (y > max) {
+ return new BlockVector3(x, max, z);
+ }
+ return this;
+ }
+
+ /**
+ * Floors the values of all components.
+ *
+ * @return a new vector
+ */
+ public BlockVector3 floor() {
+ // already floored, kept for feature parity with Vector3
+ return this;
+ }
+
+ /**
+ * Rounds all components up.
+ *
+ * @return a new vector
+ */
+ public BlockVector3 ceil() {
+ // already raised, kept for feature parity with Vector3
+ return this;
+ }
+
+ /**
+ * Rounds all components to the closest integer.
+ *
+ * Components < 0.5 are rounded down, otherwise up.
+ *
+ * @return a new vector
+ */
+ public BlockVector3 round() {
+ // already rounded, kept for feature parity with Vector3
+ return this;
+ }
+
+ /**
+ * Returns a vector with the absolute values of the components of
+ * this vector.
+ *
+ * @return a new vector
+ */
+ public BlockVector3 abs() {
+ return new BlockVector3(Math.abs(x), Math.abs(y), Math.abs(z));
+ }
+
+ /**
+ * Perform a 2D transformation on this vector and return a new one.
+ *
+ * @param angle in degrees
+ * @param aboutX about which x coordinate to rotate
+ * @param aboutZ about which z coordinate to rotate
+ * @param translateX what to add after rotation
+ * @param translateZ what to add after rotation
+ * @return a new vector
+ * @see AffineTransform another method to transform vectors
+ */
+ public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
+ angle = Math.toRadians(angle);
+ double x = this.x - aboutX;
+ double z = this.z - aboutZ;
+ double cos = Math.cos(angle);
+ double sin = Math.sin(angle);
+ double x2 = x * cos - z * sin;
+ double z2 = x * sin + z * cos;
+
+ return new BlockVector3(
+ x2 + aboutX + translateX,
+ y,
+ z2 + aboutZ + translateZ
+ );
+ }
+
+ /**
+ * Get this vector's pitch as used within the game.
+ *
+ * @return pitch in radians
+ */
+ public double toPitch() {
+ double x = getX();
+ double z = getZ();
+
+ if (x == 0 && z == 0) {
+ return getY() > 0 ? -90 : 90;
+ } else {
+ double x2 = x * x;
+ double z2 = z * z;
+ double xz = Math.sqrt(x2 + z2);
+ return Math.toDegrees(Math.atan(-getY() / xz));
+ }
+ }
+
+ /**
+ * Get this vector's yaw as used within the game.
+ *
+ * @return yaw in radians
+ */
+ public double toYaw() {
+ double x = getX();
+ double z = getZ();
+
+ double t = Math.atan2(-x, z);
+ double tau = 2 * Math.PI;
+
+ return Math.toDegrees(((t + tau) % tau));
+ }
+
+ /**
+ * Gets the minimum components of two vectors.
+ *
+ * @param v2 the second vector
+ * @return minimum
+ */
+ public BlockVector3 getMinimum(BlockVector3 v2) {
+ return new BlockVector3(
+ Math.min(x, v2.x),
+ Math.min(y, v2.y),
+ Math.min(z, v2.z)
+ );
+ }
+
+ /**
+ * Gets the maximum components of two vectors.
+ *
+ * @param v2 the second vector
+ * @return maximum
+ */
+ public BlockVector3 getMaximum(BlockVector3 v2) {
+ return new BlockVector3(
+ Math.max(x, v2.x),
+ Math.max(y, v2.y),
+ Math.max(z, v2.z)
+ );
+ }
+
+ /**
+ * Creates a 2D vector by dropping the Y component from this vector.
+ *
+ * @return a new {@link BlockVector2}
+ */
+ public BlockVector2 toBlockVector2() {
+ return new BlockVector2(x, z);
+ }
+
+ public Vector3 toVector3() {
+ return new Vector3(x, y, z);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof BlockVector3)) {
+ return false;
+ }
+
+ BlockVector3 other = (BlockVector3) obj;
+ return other.x == this.x && other.y == this.y && other.z == this.z;
+ }
+
+ @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;
+ }
+
+ @Override
+ public String toString() {
+ return "(" + x + ", " + y + ", " + z + ")";
+ }
+
+}
\ No newline at end of file
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java
new file mode 100644
index 000000000..e403cc5ea
--- /dev/null
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java
@@ -0,0 +1,471 @@
+/*
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q
+ * Copyright (C) WorldEdit team and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.worldedit.math;
+
+import com.sk89q.worldedit.math.transform.AffineTransform;
+
+/**
+ * An immutable 2-dimensional vector.
+ */
+public final class Vector2 {
+
+ public static final Vector2 ZERO = new Vector2(0, 0);
+ public static final Vector2 UNIT_X = new Vector2(1, 0);
+ public static final Vector2 UNIT_Z = new Vector2(0, 1);
+ public static final Vector2 ONE = new Vector2(1, 1);
+
+ private final double x, z;
+
+ /**
+ * Construct an instance.
+ *
+ * @param x the X coordinate
+ * @param z the Z coordinate
+ */
+ public Vector2(double x, double z) {
+ this.x = x;
+ this.z = z;
+ }
+
+ /**
+ * Copy another vector.
+ *
+ * @param other the other vector
+ */
+ public Vector2(Vector2 other) {
+ this.x = other.x;
+ this.z = other.z;
+ }
+
+ /**
+ * Get the X coordinate.
+ *
+ * @return the x coordinate
+ */
+ public double getX() {
+ return x;
+ }
+
+ /**
+ * Set the X coordinate.
+ *
+ * @param x the new X
+ * @return a new vector
+ */
+ public Vector2 withX(double x) {
+ return new Vector2(x, z);
+ }
+
+ /**
+ * Get the Z coordinate.
+ *
+ * @return the z coordinate
+ */
+ public double getZ() {
+ return z;
+ }
+
+ /**
+ * Set the Z coordinate.
+ *
+ * @param z the new Z
+ * @return a new vector
+ */
+ public Vector2 withZ(double z) {
+ return new Vector2(x, z);
+ }
+
+ /**
+ * Add another vector to this vector and return the result as a new vector.
+ *
+ * @param other the other vector
+ * @return a new vector
+ */
+ public Vector2 add(Vector2 other) {
+ return add(other.x, other.z);
+ }
+
+ /**
+ * Add another vector to this vector and return the result as a new vector.
+ *
+ * @param x the value to add
+ * @param z the value to add
+ * @return a new vector
+ */
+ public Vector2 add(double x, double z) {
+ return new Vector2(this.x + x, this.z + z);
+ }
+
+ /**
+ * Add a list of vectors to this vector and return the
+ * result as a new vector.
+ *
+ * @param others an array of vectors
+ * @return a new vector
+ */
+ public Vector2 add(Vector2... others) {
+ double newX = x, newZ = z;
+
+ for (Vector2 other : others) {
+ newX += other.x;
+ newZ += other.z;
+ }
+
+ return new Vector2(newX, newZ);
+ }
+
+ /**
+ * Subtract another vector from this vector and return the result
+ * as a new vector.
+ *
+ * @param other the other vector
+ * @return a new vector
+ */
+ public Vector2 subtract(Vector2 other) {
+ return subtract(other.x, other.z);
+ }
+
+ /**
+ * Subtract another vector from this vector and return the result
+ * as a new vector.
+ *
+ * @param x the value to subtract
+ * @param z the value to subtract
+ * @return a new vector
+ */
+ public Vector2 subtract(double x, double z) {
+ return new Vector2(this.x - x, this.z - z);
+ }
+
+ /**
+ * Subtract a list of vectors from this vector and return the result
+ * as a new vector.
+ *
+ * @param others an array of vectors
+ * @return a new vector
+ */
+ public Vector2 subtract(Vector2... others) {
+ double newX = x, newZ = z;
+
+ for (Vector2 other : others) {
+ newX -= other.x;
+ newZ -= other.z;
+ }
+
+ return new Vector2(newX, newZ);
+ }
+
+ /**
+ * Multiply this vector by another vector on each component.
+ *
+ * @param other the other vector
+ * @return a new vector
+ */
+ public Vector2 multiply(Vector2 other) {
+ return multiply(other.x, other.z);
+ }
+
+ /**
+ * Multiply this vector by another vector on each component.
+ *
+ * @param x the value to multiply
+ * @param z the value to multiply
+ * @return a new vector
+ */
+ public Vector2 multiply(double x, double z) {
+ return new Vector2(this.x * x, this.z * z);
+ }
+
+ /**
+ * Multiply this vector by zero or more vectors on each component.
+ *
+ * @param others an array of vectors
+ * @return a new vector
+ */
+ public Vector2 multiply(Vector2... others) {
+ double newX = x, newZ = z;
+
+ for (Vector2 other : others) {
+ newX *= other.x;
+ newZ *= other.z;
+ }
+
+ return new Vector2(newX, newZ);
+ }
+
+ /**
+ * Perform scalar multiplication and return a new vector.
+ *
+ * @param n the value to multiply
+ * @return a new vector
+ */
+ public Vector2 multiply(double n) {
+ return multiply(n, n);
+ }
+
+ /**
+ * Divide this vector by another vector on each component.
+ *
+ * @param other the other vector
+ * @return a new vector
+ */
+ public Vector2 divide(Vector2 other) {
+ return divide(other.x, other.z);
+ }
+
+ /**
+ * Divide this vector by another vector on each component.
+ *
+ * @param x the value to divide by
+ * @param z the value to divide by
+ * @return a new vector
+ */
+ public Vector2 divide(double x, double z) {
+ return new Vector2(this.x / x, this.z / z);
+ }
+
+ /**
+ * Perform scalar division and return a new vector.
+ *
+ * @param n the value to divide by
+ * @return a new vector
+ */
+ public Vector2 divide(double n) {
+ return divide(n, n);
+ }
+
+ /**
+ * Get the length of the vector.
+ *
+ * @return length
+ */
+ public double length() {
+ return Math.sqrt(lengthSq());
+ }
+
+ /**
+ * Get the length, squared, of the vector.
+ *
+ * @return length, squared
+ */
+ public double lengthSq() {
+ return x * x + z * z;
+ }
+
+ /**
+ * Get the distance between this vector and another vector.
+ *
+ * @param other the other vector
+ * @return distance
+ */
+ public double distance(Vector2 other) {
+ return Math.sqrt(distanceSq(other));
+ }
+
+ /**
+ * Get the distance between this vector and another vector, squared.
+ *
+ * @param other the other vector
+ * @return distance
+ */
+ public double distanceSq(Vector2 other) {
+ double dx = other.x - x;
+ double dz = other.z - z;
+ return dx * dx + dz * dz;
+ }
+
+ /**
+ * Get the normalized vector, which is the vector divided by its
+ * length, as a new vector.
+ *
+ * @return a new vector
+ */
+ public Vector2 normalize() {
+ return divide(length());
+ }
+
+ /**
+ * Gets the dot product of this and another vector.
+ *
+ * @param other the other vector
+ * @return the dot product of this and the other vector
+ */
+ public double dot(Vector2 other) {
+ return x * other.x + z * other.z;
+ }
+
+ /**
+ * Checks to see if a vector is contained with another.
+ *
+ * @param min the minimum point (X, Y, and Z are the lowest)
+ * @param max the maximum point (X, Y, and Z are the lowest)
+ * @return true if the vector is contained
+ */
+ public boolean containedWithin(Vector2 min, Vector2 max) {
+ return x >= min.x && x <= max.x
+ && z >= min.z && z <= max.z;
+ }
+
+ /**
+ * Floors the values of all components.
+ *
+ * @return a new vector
+ */
+ public Vector2 floor() {
+ return new Vector2(Math.floor(x), Math.floor(z));
+ }
+
+ /**
+ * Rounds all components up.
+ *
+ * @return a new vector
+ */
+ public Vector2 ceil() {
+ return new Vector2(Math.ceil(x), Math.ceil(z));
+ }
+
+ /**
+ * Rounds all components to the closest integer.
+ *
+ * Components < 0.5 are rounded down, otherwise up.
+ *
+ * @return a new vector
+ */
+ public Vector2 round() {
+ return new Vector2(Math.floor(x + 0.5), Math.floor(z + 0.5));
+ }
+
+ /**
+ * Returns a vector with the absolute values of the components of
+ * this vector.
+ *
+ * @return a new vector
+ */
+ public Vector2 abs() {
+ return new Vector2(Math.abs(x), Math.abs(z));
+ }
+
+ /**
+ * Perform a 2D transformation on this vector and return a new one.
+ *
+ * @param angle in degrees
+ * @param aboutX about which x coordinate to rotate
+ * @param aboutZ about which z coordinate to rotate
+ * @param translateX what to add after rotation
+ * @param translateZ what to add after rotation
+ * @return a new vector
+ * @see AffineTransform another method to transform vectors
+ */
+ public Vector2 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
+ angle = Math.toRadians(angle);
+ double x = this.x - aboutX;
+ double z = this.z - aboutZ;
+ double cos = Math.cos(angle);
+ double sin = Math.sin(angle);
+ double x2 = x * cos - z * sin;
+ double z2 = x * sin + z * cos;
+ return new Vector2(
+ x2 + aboutX + translateX,
+ z2 + aboutZ + translateZ);
+ }
+
+ /**
+ * Gets the minimum components of two vectors.
+ *
+ * @param v2 the second vector
+ * @return minimum
+ */
+ public Vector2 getMinimum(Vector2 v2) {
+ return new Vector2(
+ Math.min(x, v2.x),
+ Math.min(z, v2.z)
+ );
+ }
+
+ /**
+ * Gets the maximum components of two vectors.
+ *
+ * @param v2 the second vector
+ * @return maximum
+ */
+ public Vector2 getMaximum(Vector2 v2) {
+ return new Vector2(
+ Math.max(x, v2.x),
+ Math.max(z, v2.z)
+ );
+ }
+
+ public static BlockVector2 toBlockPoint(double x, double z) {
+ return new BlockVector2(x, z);
+ }
+
+ /**
+ * Create a new {@link BlockVector2} from this vector.
+ *
+ * @return a new {@link BlockVector2}
+ */
+ public BlockVector2 toBlockPoint() {
+ return toBlockPoint(x, z);
+ }
+
+ /**
+ * Creates a 3D vector by adding a zero Y component to this vector.
+ *
+ * @return a new vector
+ */
+ public Vector3 toVector3() {
+ return toVector3(0);
+ }
+
+ /**
+ * Creates a 3D vector by adding the specified Y component to this vector.
+ *
+ * @param y the Y component
+ * @return a new vector
+ */
+ public Vector3 toVector3(double y) {
+ return new Vector3(x, y, z);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Vector2)) {
+ return false;
+ }
+
+ Vector2 other = (Vector2) obj;
+ return other.x == this.x && other.z == this.z;
+
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 17;
+ hash = 31 * hash + Double.hashCode(x);
+ hash = 31 * hash + Double.hashCode(z);
+ return hash;
+ }
+
+ @Override
+ public String toString() {
+ return "(" + x + ", " + z + ")";
+ }
+
+}
\ No newline at end of file
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java
new file mode 100644
index 000000000..59847cbf2
--- /dev/null
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java
@@ -0,0 +1,596 @@
+/*
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q
+ * Copyright (C) WorldEdit team and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.worldedit.math;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import com.google.common.collect.ComparisonChain;
+import com.sk89q.worldedit.math.transform.AffineTransform;
+
+import java.util.Comparator;
+
+/**
+ * An immutable 3-dimensional vector.
+ */
+public final class Vector3 {
+
+ public static final Vector3 ZERO = new Vector3(0, 0, 0);
+ public static final Vector3 UNIT_X = new Vector3(1, 0, 0);
+ public static final Vector3 UNIT_Y = new Vector3(0, 1, 0);
+ public static final Vector3 UNIT_Z = new Vector3(0, 0, 1);
+ public static final Vector3 ONE = new Vector3(1, 1, 1);
+
+ // thread-safe initialization idiom
+ private static final class YzxOrderComparator {
+ private static final Comparator YZX_ORDER = (a, b) -> {
+ return ComparisonChain.start()
+ .compare(a.y, b.y)
+ .compare(a.z, b.z)
+ .compare(a.x, b.x)
+ .result();
+ };
+ }
+
+ /**
+ * Returns a comparator that sorts vectors first by Y, then Z, then X.
+ *
+ *
+ * Useful for sorting by chunk block storage order.
+ */
+ public static Comparator sortByCoordsYzx() {
+ return YzxOrderComparator.YZX_ORDER;
+ }
+
+ private final double x, y, z;
+
+ /**
+ * Construct an instance.
+ *
+ * @param x the X coordinate
+ * @param y the Y coordinate
+ * @param z the Z coordinate
+ */
+ public Vector3(double x, double y, double z) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+
+ /**
+ * Copy another vector.
+ *
+ * @param other another vector to make a copy of
+ */
+ public Vector3(Vector3 other) {
+ this.x = other.x;
+ this.y = other.y;
+ this.z = other.z;
+ }
+
+ /**
+ * Get the X coordinate.
+ *
+ * @return the x coordinate
+ */
+ public double getX() {
+ return x;
+ }
+
+ /**
+ * Set the X coordinate.
+ *
+ * @param x the new X
+ * @return a new vector
+ */
+ public Vector3 withX(double x) {
+ return new Vector3(x, y, z);
+ }
+
+ /**
+ * Get the Y coordinate.
+ *
+ * @return the y coordinate
+ */
+ public double getY() {
+ return y;
+ }
+
+ /**
+ * Set the Y coordinate.
+ *
+ * @param y the new Y
+ * @return a new vector
+ */
+ public Vector3 withY(double y) {
+ return new Vector3(x, y, z);
+ }
+
+ /**
+ * Get the Z coordinate.
+ *
+ * @return the z coordinate
+ */
+ public double getZ() {
+ return z;
+ }
+
+ /**
+ * Set the Z coordinate.
+ *
+ * @param z the new Z
+ * @return a new vector
+ */
+ public Vector3 withZ(double z) {
+ return new Vector3(x, y, z);
+ }
+
+ /**
+ * Add another vector to this vector and return the result as a new vector.
+ *
+ * @param other the other vector
+ * @return a new vector
+ */
+ public Vector3 add(Vector3 other) {
+ return add(other.x, other.y, other.z);
+ }
+
+ /**
+ * Add another vector to this vector and return the result as a new vector.
+ *
+ * @param x the value to add
+ * @param y the value to add
+ * @param z the value to add
+ * @return a new vector
+ */
+ public Vector3 add(double x, double y, double z) {
+ return new Vector3(this.x + x, this.y + y, this.z + z);
+ }
+
+ /**
+ * Add a list of vectors to this vector and return the
+ * result as a new vector.
+ *
+ * @param others an array of vectors
+ * @return a new vector
+ */
+ public Vector3 add(Vector3... others) {
+ double newX = x, newY = y, newZ = z;
+
+ for (Vector3 other : others) {
+ newX += other.x;
+ newY += other.y;
+ newZ += other.z;
+ }
+
+ return new Vector3(newX, newY, newZ);
+ }
+
+ /**
+ * Subtract another vector from this vector and return the result
+ * as a new vector.
+ *
+ * @param other the other vector
+ * @return a new vector
+ */
+ public Vector3 subtract(Vector3 other) {
+ return subtract(other.x, other.y, other.z);
+ }
+
+ /**
+ * Subtract another vector from this vector and return the result
+ * as a new vector.
+ *
+ * @param x the value to subtract
+ * @param y the value to subtract
+ * @param z the value to subtract
+ * @return a new vector
+ */
+ public Vector3 subtract(double x, double y, double z) {
+ return new Vector3(this.x - x, this.y - y, this.z - z);
+ }
+
+ /**
+ * Subtract a list of vectors from this vector and return the result
+ * as a new vector.
+ *
+ * @param others an array of vectors
+ * @return a new vector
+ */
+ public Vector3 subtract(Vector3... others) {
+ double newX = x, newY = y, newZ = z;
+
+ for (Vector3 other : others) {
+ newX -= other.x;
+ newY -= other.y;
+ newZ -= other.z;
+ }
+
+ return new Vector3(newX, newY, newZ);
+ }
+
+ /**
+ * Multiply this vector by another vector on each component.
+ *
+ * @param other the other vector
+ * @return a new vector
+ */
+ public Vector3 multiply(Vector3 other) {
+ return multiply(other.x, other.y, other.z);
+ }
+
+ /**
+ * Multiply this vector by another vector on each component.
+ *
+ * @param x the value to multiply
+ * @param y the value to multiply
+ * @param z the value to multiply
+ * @return a new vector
+ */
+ public Vector3 multiply(double x, double y, double z) {
+ return new Vector3(this.x * x, this.y * y, this.z * z);
+ }
+
+ /**
+ * Multiply this vector by zero or more vectors on each component.
+ *
+ * @param others an array of vectors
+ * @return a new vector
+ */
+ public Vector3 multiply(Vector3... others) {
+ double newX = x, newY = y, newZ = z;
+
+ for (Vector3 other : others) {
+ newX *= other.x;
+ newY *= other.y;
+ newZ *= other.z;
+ }
+
+ return new Vector3(newX, newY, newZ);
+ }
+
+ /**
+ * Perform scalar multiplication and return a new vector.
+ *
+ * @param n the value to multiply
+ * @return a new vector
+ */
+ public Vector3 multiply(double n) {
+ return multiply(n, n, n);
+ }
+
+ /**
+ * Divide this vector by another vector on each component.
+ *
+ * @param other the other vector
+ * @return a new vector
+ */
+ public Vector3 divide(Vector3 other) {
+ return divide(other.x, other.y, other.z);
+ }
+
+ /**
+ * Divide this vector by another vector on each component.
+ *
+ * @param x the value to divide by
+ * @param y the value to divide by
+ * @param z the value to divide by
+ * @return a new vector
+ */
+ public Vector3 divide(double x, double y, double z) {
+ return new Vector3(this.x / x, this.y / y, this.z / z);
+ }
+
+ /**
+ * Perform scalar division and return a new vector.
+ *
+ * @param n the value to divide by
+ * @return a new vector
+ */
+ public Vector3 divide(double n) {
+ return divide(n, n, n);
+ }
+
+ /**
+ * Get the length of the vector.
+ *
+ * @return length
+ */
+ public double length() {
+ return Math.sqrt(lengthSq());
+ }
+
+ /**
+ * Get the length, squared, of the vector.
+ *
+ * @return length, squared
+ */
+ public double lengthSq() {
+ return x * x + y * y + z * z;
+ }
+
+ /**
+ * Get the distance between this vector and another vector.
+ *
+ * @param other the other vector
+ * @return distance
+ */
+ public double distance(Vector3 other) {
+ return Math.sqrt(distanceSq(other));
+ }
+
+ /**
+ * Get the distance between this vector and another vector, squared.
+ *
+ * @param other the other vector
+ * @return distance
+ */
+ public double distanceSq(Vector3 other) {
+ double dx = other.x - x;
+ double dy = other.y - y;
+ double dz = other.z - z;
+ return dx * dx + dy * dy + dz * dz;
+ }
+
+ /**
+ * Get the normalized vector, which is the vector divided by its
+ * length, as a new vector.
+ *
+ * @return a new vector
+ */
+ public Vector3 normalize() {
+ return divide(length());
+ }
+
+ /**
+ * Gets the dot product of this and another vector.
+ *
+ * @param other the other vector
+ * @return the dot product of this and the other vector
+ */
+ public double dot(Vector3 other) {
+ return x * other.x + y * other.y + z * other.z;
+ }
+
+ /**
+ * Gets the cross product of this and another vector.
+ *
+ * @param other the other vector
+ * @return the cross product of this and the other vector
+ */
+ public Vector3 cross(Vector3 other) {
+ return new Vector3(
+ y * other.z - z * other.y,
+ z * other.x - x * other.z,
+ x * other.y - y * other.x
+ );
+ }
+
+ /**
+ * Checks to see if a vector is contained with another.
+ *
+ * @param min the minimum point (X, Y, and Z are the lowest)
+ * @param max the maximum point (X, Y, and Z are the lowest)
+ * @return true if the vector is contained
+ */
+ public boolean containedWithin(Vector3 min, Vector3 max) {
+ return x >= min.x && x <= max.x && y >= min.y && y <= max.y && z >= min.z && z <= max.z;
+ }
+
+ /**
+ * Clamp the Y component.
+ *
+ * @param min the minimum value
+ * @param max the maximum value
+ * @return a new vector
+ */
+ public Vector3 clampY(int min, int max) {
+ checkArgument(min <= max, "minimum cannot be greater than maximum");
+ if (y < min) {
+ return new Vector3(x, min, z);
+ }
+ if (y > max) {
+ return new Vector3(x, max, z);
+ }
+ return this;
+ }
+
+ /**
+ * Floors the values of all components.
+ *
+ * @return a new vector
+ */
+ public Vector3 floor() {
+ return new Vector3(Math.floor(x), Math.floor(y), Math.floor(z));
+ }
+
+ /**
+ * Rounds all components up.
+ *
+ * @return a new vector
+ */
+ public Vector3 ceil() {
+ return new Vector3(Math.ceil(x), Math.ceil(y), Math.ceil(z));
+ }
+
+ /**
+ * Rounds all components to the closest integer.
+ *
+ * Components < 0.5 are rounded down, otherwise up.
+ *
+ * @return a new vector
+ */
+ public Vector3 round() {
+ return new Vector3(Math.floor(x + 0.5), Math.floor(y + 0.5), Math.floor(z + 0.5));
+ }
+
+ /**
+ * Returns a vector with the absolute values of the components of
+ * this vector.
+ *
+ * @return a new vector
+ */
+ public Vector3 abs() {
+ return new Vector3(Math.abs(x), Math.abs(y), Math.abs(z));
+ }
+
+ /**
+ * Perform a 2D transformation on this vector and return a new one.
+ *
+ * @param angle in degrees
+ * @param aboutX about which x coordinate to rotate
+ * @param aboutZ about which z coordinate to rotate
+ * @param translateX what to add after rotation
+ * @param translateZ what to add after rotation
+ * @return a new vector
+ * @see AffineTransform another method to transform vectors
+ */
+ public Vector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
+ angle = Math.toRadians(angle);
+ double x = this.x - aboutX;
+ double z = this.z - aboutZ;
+ double cos = Math.cos(angle);
+ double sin = Math.sin(angle);
+ double x2 = x * cos - z * sin;
+ double z2 = x * sin + z * cos;
+
+ return new Vector3(
+ x2 + aboutX + translateX,
+ y,
+ z2 + aboutZ + translateZ
+ );
+ }
+
+ /**
+ * Get this vector's pitch as used within the game.
+ *
+ * @return pitch in radians
+ */
+ public double toPitch() {
+ double x = getX();
+ double z = getZ();
+
+ if (x == 0 && z == 0) {
+ return getY() > 0 ? -90 : 90;
+ } else {
+ double x2 = x * x;
+ double z2 = z * z;
+ double xz = Math.sqrt(x2 + z2);
+ return Math.toDegrees(Math.atan(-getY() / xz));
+ }
+ }
+
+ /**
+ * Get this vector's yaw as used within the game.
+ *
+ * @return yaw in radians
+ */
+ public double toYaw() {
+ double x = getX();
+ double z = getZ();
+
+ double t = Math.atan2(-x, z);
+ double tau = 2 * Math.PI;
+
+ return Math.toDegrees(((t + tau) % tau));
+ }
+
+ /**
+ * Gets the minimum components of two vectors.
+ *
+ * @param v2 the second vector
+ * @return minimum
+ */
+ public Vector3 getMinimum(Vector3 v2) {
+ return new Vector3(
+ Math.min(x, v2.x),
+ Math.min(y, v2.y),
+ Math.min(z, v2.z)
+ );
+ }
+
+ /**
+ * Gets the maximum components of two vectors.
+ *
+ * @param v2 the second vector
+ * @return maximum
+ */
+ public Vector3 getMaximum(Vector3 v2) {
+ return new Vector3(
+ Math.max(x, v2.x),
+ Math.max(y, v2.y),
+ Math.max(z, v2.z)
+ );
+ }
+
+ /**
+ * Create a new {@code BlockVector} using the given components.
+ *
+ * @param x the X coordinate
+ * @param y the Y coordinate
+ * @param z the Z coordinate
+ * @return a new {@code BlockVector}
+ */
+ public static BlockVector3 toBlockPoint(double x, double y, double z) {
+ return new BlockVector3(x, y, z);
+ }
+
+ /**
+ * Create a new {@code BlockVector} from this vector.
+ *
+ * @return a new {@code BlockVector}
+ */
+ public BlockVector3 toBlockPoint() {
+ return toBlockPoint(x, y, z);
+ }
+
+ /**
+ * Creates a 2D vector by dropping the Y component from this vector.
+ *
+ * @return a new {@link Vector2}
+ */
+ public Vector2 toVector2() {
+ return new Vector2(x, z);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Vector3)) {
+ return false;
+ }
+
+ Vector3 other = (Vector3) obj;
+ return other.x == this.x && other.y == this.y && other.z == this.z;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 17;
+ hash = 31 * hash + Double.hashCode(x);
+ hash = 31 * hash + Double.hashCode(y);
+ hash = 31 * hash + Double.hashCode(z);
+ return hash;
+ }
+
+ @Override
+ public String toString() {
+ return "(" + x + ", " + y + ", " + z + ")";
+ }
+
+}
\ No newline at end of file
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java
index 0cfd4c35f..c12beee56 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java
@@ -23,7 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
-import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
@@ -105,7 +105,7 @@ public class HeightMap {
public int apply(int[] data) throws MaxChangedBlocksException {
checkNotNull(data);
- Vector minY = region.getMinimumPoint();
+ BlockVector3 minY = region.getMinimumPoint();
int originX = minY.getBlockX();
int originY = minY.getBlockY();
int originZ = minY.getBlockZ();
@@ -134,17 +134,17 @@ public class HeightMap {
// Depending on growing or shrinking we need to start at the bottom or top
if (newHeight > curHeight) {
// Set the top block of the column to be the same type (this might go wrong with rounding)
- BlockState existing = session.getBlock(new Vector(xr, curHeight, zr));
+ BlockState existing = session.getBlock(new BlockVector3(xr, curHeight, zr));
// Skip water/lava
if (existing.getBlockType() != BlockTypes.WATER && existing.getBlockType() != BlockTypes.LAVA) {
- session.setBlock(new Vector(xr, newHeight, zr), existing);
+ session.setBlock(new BlockVector3(xr, newHeight, zr), existing);
++blocksChanged;
// Grow -- start from 1 below top replacing airblocks
for (int y = newHeight - 1 - originY; y >= 0; --y) {
int copyFrom = (int) (y * scale);
- session.setBlock(new Vector(xr, originY + y, zr), session.getBlock(new Vector(xr, originY + copyFrom, zr)));
+ session.setBlock(new BlockVector3(xr, originY + y, zr), session.getBlock(new BlockVector3(xr, originY + copyFrom, zr)));
++blocksChanged;
}
}
@@ -152,18 +152,18 @@ public class HeightMap {
// Shrink -- start from bottom
for (int y = 0; y < newHeight - originY; ++y) {
int copyFrom = (int) (y * scale);
- session.setBlock(new Vector(xr, originY + y, zr), session.getBlock(new Vector(xr, originY + copyFrom, zr)));
+ session.setBlock(new BlockVector3(xr, originY + y, zr), session.getBlock(new BlockVector3(xr, originY + copyFrom, zr)));
++blocksChanged;
}
// Set the top block of the column to be the same type
// (this could otherwise go wrong with rounding)
- session.setBlock(new Vector(xr, newHeight, zr), session.getBlock(new Vector(xr, curHeight, zr)));
+ session.setBlock(new BlockVector3(xr, newHeight, zr), session.getBlock(new BlockVector3(xr, curHeight, zr)));
++blocksChanged;
// Fill rest with air
for (int y = newHeight + 1; y <= curHeight; ++y) {
- session.setBlock(new Vector(xr, y, zr), fillerAir);
+ session.setBlock(new BlockVector3(xr, y, zr), fillerAir);
++blocksChanged;
}
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/geom/Polygons.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/geom/Polygons.java
index 007977d58..af191dc72 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/geom/Polygons.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/geom/Polygons.java
@@ -19,8 +19,8 @@
package com.sk89q.worldedit.math.geom;
-import com.sk89q.worldedit.BlockVector2D;
-import com.sk89q.worldedit.Vector2D;
+import com.sk89q.worldedit.math.BlockVector2;
+import com.sk89q.worldedit.math.Vector2;
import java.util.ArrayList;
import java.util.List;
@@ -40,9 +40,9 @@ public final class Polygons {
* @param center the center point of the cylinder
* @param radius the radius of the cylinder
* @param maxPoints max points to be used for the calculation
- * @return a list of {@link BlockVector2D} which resemble the shape as a polygon
+ * @return a list of {@link BlockVector2} which resemble the shape as a polygon
*/
- public static List polygonizeCylinder(Vector2D center, Vector2D radius, int maxPoints) {
+ public static List polygonizeCylinder(BlockVector2 center, Vector2 radius, int maxPoints) {
int nPoints = (int) Math.ceil(Math.PI*radius.length());
// These strange semantics for maxPoints are copied from the selectSecondary method.
@@ -50,11 +50,11 @@ public final class Polygons {
nPoints = maxPoints - 1;
}
- final List points = new ArrayList<>(nPoints);
+ final List points = new ArrayList<>(nPoints);
for (int i = 0; i < nPoints; ++i) {
double angle = i * (2.0 * Math.PI) / nPoints;
- final Vector2D pos = new Vector2D(Math.cos(angle), Math.sin(angle));
- final BlockVector2D blockVector2D = pos.multiply(radius).add(center).toBlockVector2D();
+ final Vector2 pos = new Vector2(Math.cos(angle), Math.sin(angle));
+ final BlockVector2 blockVector2D = pos.multiply(radius).toBlockPoint().add(center);
points.add(blockVector2D);
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Interpolation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Interpolation.java
index 68df24b0d..28ce2c492 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Interpolation.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Interpolation.java
@@ -21,7 +21,7 @@
package com.sk89q.worldedit.math.interpolation;
-import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.math.Vector3;
import java.util.List;
@@ -44,7 +44,7 @@ public interface Interpolation {
* @param position the position to interpolate
* @return the result
*/
- Vector getPosition(double position);
+ Vector3 getPosition(double position);
/**
* Gets the result of f'(position).
@@ -52,7 +52,7 @@ public interface Interpolation {
* @param position the position to interpolate
* @return the result
*/
- Vector get1stDerivative(double position);
+ Vector3 get1stDerivative(double position);
/**
* Gets the result of ∫ab|f'(t)| dt.
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/KochanekBartelsInterpolation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/KochanekBartelsInterpolation.java
index f5f41313b..3d87135f9 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/KochanekBartelsInterpolation.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/KochanekBartelsInterpolation.java
@@ -23,7 +23,7 @@ package com.sk89q.worldedit.math.interpolation;
import static com.google.common.base.Preconditions.checkNotNull;
-import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.math.Vector3;
import java.util.Collections;
import java.util.List;
@@ -37,10 +37,10 @@ import java.util.List;
public class KochanekBartelsInterpolation implements Interpolation {
private List nodes;
- private Vector[] coeffA;
- private Vector[] coeffB;
- private Vector[] coeffC;
- private Vector[] coeffD;
+ private Vector3[] coeffA;
+ private Vector3[] coeffB;
+ private Vector3[] coeffC;
+ private Vector3[] coeffD;
private double scaling;
public KochanekBartelsInterpolation() {
@@ -57,10 +57,10 @@ public class KochanekBartelsInterpolation implements Interpolation {
private void recalc() {
final int nNodes = nodes.size();
- coeffA = new Vector[nNodes];
- coeffB = new Vector[nNodes];
- coeffC = new Vector[nNodes];
- coeffD = new Vector[nNodes];
+ coeffA = new Vector3[nNodes];
+ coeffB = new Vector3[nNodes];
+ coeffC = new Vector3[nNodes];
+ coeffD = new Vector3[nNodes];
if (nNodes == 0)
return;
@@ -107,11 +107,11 @@ public class KochanekBartelsInterpolation implements Interpolation {
* @param f4 coefficient for baseIndex+2
* @return linear combination of nodes[n-1..n+2] with f1..4
*/
- private Vector linearCombination(int baseIndex, double f1, double f2, double f3, double f4) {
- final Vector r1 = retrieve(baseIndex - 1).multiply(f1);
- final Vector r2 = retrieve(baseIndex ).multiply(f2);
- final Vector r3 = retrieve(baseIndex + 1).multiply(f3);
- final Vector r4 = retrieve(baseIndex + 2).multiply(f4);
+ private Vector3 linearCombination(int baseIndex, double f1, double f2, double f3, double f4) {
+ final Vector3 r1 = retrieve(baseIndex - 1).multiply(f1);
+ final Vector3 r2 = retrieve(baseIndex ).multiply(f2);
+ final Vector3 r3 = retrieve(baseIndex + 1).multiply(f3);
+ final Vector3 r4 = retrieve(baseIndex + 2).multiply(f4);
return r1.add(r2).add(r3).add(r4);
}
@@ -122,7 +122,7 @@ public class KochanekBartelsInterpolation implements Interpolation {
* @param index node index to retrieve
* @return nodes[clamp(0, nodes.length-1)]
*/
- private Vector retrieve(int index) {
+ private Vector3 retrieve(int index) {
if (index < 0)
return fastRetrieve(0);
@@ -132,12 +132,12 @@ public class KochanekBartelsInterpolation implements Interpolation {
return fastRetrieve(index);
}
- private Vector fastRetrieve(int index) {
+ private Vector3 fastRetrieve(int index) {
return nodes.get(index).getPosition();
}
@Override
- public Vector getPosition(double position) {
+ public Vector3 getPosition(double position) {
if (coeffA == null)
throw new IllegalStateException("Must call setNodes first.");
@@ -149,16 +149,16 @@ public class KochanekBartelsInterpolation implements Interpolation {
final int index = (int) Math.floor(position);
final double remainder = position - index;
- final Vector a = coeffA[index];
- final Vector b = coeffB[index];
- final Vector c = coeffC[index];
- final Vector d = coeffD[index];
+ final Vector3 a = coeffA[index];
+ final Vector3 b = coeffB[index];
+ final Vector3 c = coeffC[index];
+ final Vector3 d = coeffD[index];
return a.multiply(remainder).add(b).multiply(remainder).add(c).multiply(remainder).add(d);
}
@Override
- public Vector get1stDerivative(double position) {
+ public Vector3 get1stDerivative(double position) {
if (coeffA == null)
throw new IllegalStateException("Must call setNodes first.");
@@ -170,9 +170,9 @@ public class KochanekBartelsInterpolation implements Interpolation {
final int index = (int) Math.floor(position);
//final double remainder = position - index;
- final Vector a = coeffA[index];
- final Vector b = coeffB[index];
- final Vector c = coeffC[index];
+ final Vector3 a = coeffA[index];
+ final Vector3 b = coeffB[index];
+ final Vector3 c = coeffC[index];
return a.multiply(1.5*position - 3.0*index).add(b).multiply(2.0*position).add(a.multiply(1.5*index).subtract(b).multiply(2.0*index)).add(c).multiply(scaling);
}
@@ -219,9 +219,9 @@ public class KochanekBartelsInterpolation implements Interpolation {
}
private double arcLengthRecursive(int index, double remainderLeft, double remainderRight) {
- final Vector a = coeffA[index].multiply(3.0);
- final Vector b = coeffB[index].multiply(2.0);
- final Vector c = coeffC[index];
+ final Vector3 a = coeffA[index].multiply(3.0);
+ final Vector3 b = coeffB[index].multiply(2.0);
+ final Vector3 c = coeffC[index];
final int nPoints = 8;
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/LinearInterpolation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/LinearInterpolation.java
index ea1962119..7b701f5fe 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/LinearInterpolation.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/LinearInterpolation.java
@@ -23,7 +23,7 @@ package com.sk89q.worldedit.math.interpolation;
import static com.google.common.base.Preconditions.checkNotNull;
-import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.math.Vector3;
import java.util.List;
@@ -42,7 +42,7 @@ public class LinearInterpolation implements Interpolation {
}
@Override
- public Vector getPosition(double position) {
+ public Vector3 getPosition(double position) {
if (nodes == null)
throw new IllegalStateException("Must call setNodes first.");
@@ -54,8 +54,8 @@ public class LinearInterpolation implements Interpolation {
final int index1 = (int) Math.floor(position);
final double remainder = position - index1;
- final Vector position1 = nodes.get(index1).getPosition();
- final Vector position2 = nodes.get(index1 + 1).getPosition();
+ final Vector3 position1 = nodes.get(index1).getPosition();
+ final Vector3 position2 = nodes.get(index1 + 1).getPosition();
return position1.multiply(1.0 - remainder).add(position2.multiply(remainder));
}
@@ -76,7 +76,7 @@ public class LinearInterpolation implements Interpolation {
*/
@Override
- public Vector get1stDerivative(double position) {
+ public Vector3 get1stDerivative(double position) {
if (nodes == null)
throw new IllegalStateException("Must call setNodes first.");
@@ -87,8 +87,8 @@ public class LinearInterpolation implements Interpolation {
final int index1 = (int) Math.floor(position);
- final Vector position1 = nodes.get(index1).getPosition();
- final Vector position2 = nodes.get(index1 + 1).getPosition();
+ final Vector3 position1 = nodes.get(index1).getPosition();
+ final Vector3 position2 = nodes.get(index1 + 1).getPosition();
return position2.subtract(position1);
}
@@ -135,8 +135,8 @@ public class LinearInterpolation implements Interpolation {
}
private double arcLengthRecursive(int index, double remainderA, double remainderB) {
- final Vector position1 = nodes.get(index).getPosition();
- final Vector position2 = nodes.get(index + 1).getPosition();
+ final Vector3 position1 = nodes.get(index).getPosition();
+ final Vector3 position2 = nodes.get(index + 1).getPosition();
return position1.distance(position2) * (remainderB - remainderA);
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Node.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Node.java
index ce604824c..c2bc1e93b 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Node.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Node.java
@@ -21,7 +21,7 @@
package com.sk89q.worldedit.math.interpolation;
-import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.math.Vector3;
/**
* Represents a node for interpolation.
@@ -31,14 +31,14 @@ import com.sk89q.worldedit.Vector;
*/
public class Node {
- private Vector position;
+ private Vector3 position;
private double tension;
private double bias;
private double continuity;
public Node() {
- this(new Vector(0, 0, 0));
+ this(new Vector3(0, 0, 0));
}
public Node(Node other) {
@@ -49,16 +49,16 @@ public class Node {
this.continuity = other.continuity;
}
- public Node(Vector position) {
+ public Node(Vector3 position) {
this.position = position;
}
- public Vector getPosition() {
+ public Vector3 getPosition() {
return position;
}
- public void setPosition(Vector position) {
+ public void setPosition(Vector3 position) {
this.position = position;
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/ReparametrisingInterpolation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/ReparametrisingInterpolation.java
index d6920b829..29a3ee5ee 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/ReparametrisingInterpolation.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/ReparametrisingInterpolation.java
@@ -23,7 +23,7 @@ package com.sk89q.worldedit.math.interpolation;
import static com.google.common.base.Preconditions.checkNotNull;
-import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.math.Vector3;
import java.util.List;
import java.util.Map.Entry;
@@ -65,7 +65,7 @@ public class ReparametrisingInterpolation implements Interpolation {
}
@Override
- public Vector getPosition(double position) {
+ public Vector3 getPosition(double position) {
if (position > 1)
return null;
@@ -73,7 +73,7 @@ public class ReparametrisingInterpolation implements Interpolation {
}
@Override
- public Vector get1stDerivative(double position) {
+ public Vector3 get1stDerivative(double position) {
if (position > 1)
return null;
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/JLibNoiseGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/JLibNoiseGenerator.java
index dbf7720fd..1da9d5b2d 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/JLibNoiseGenerator.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/JLibNoiseGenerator.java
@@ -19,8 +19,9 @@
package com.sk89q.worldedit.math.noise;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.Vector2D;
+import com.sk89q.worldedit.math.Vector2;
+import com.sk89q.worldedit.math.Vector3;
+
import net.royawesome.jlibnoise.module.Module;
import java.util.Random;
@@ -46,12 +47,12 @@ abstract class JLibNoiseGenerator implements NoiseGenerator {
public abstract int getSeed();
@Override
- public float noise(Vector2D position) {
+ public float noise(Vector2 position) {
return forceRange(module.GetValue(position.getX(), 0, position.getZ()));
}
@Override
- public float noise(Vector position) {
+ public float noise(Vector3 position) {
return forceRange(module.GetValue(position.getX(), position.getY(), position.getZ()));
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/NoiseGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/NoiseGenerator.java
index bb57d23f0..185e41fbb 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/NoiseGenerator.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/NoiseGenerator.java
@@ -19,8 +19,8 @@
package com.sk89q.worldedit.math.noise;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.Vector2D;
+import com.sk89q.worldedit.math.Vector2;
+import com.sk89q.worldedit.math.Vector3;
/**
* Generates noise in a deterministic or non-deterministic manner.
@@ -34,7 +34,7 @@ public interface NoiseGenerator {
* @param position the position
* @return a noise value between 0 (inclusive) and 1 (inclusive)
*/
- float noise(Vector2D position);
+ float noise(Vector2 position);
/**
* Get the noise value for the given position. The returned value may
@@ -43,6 +43,6 @@ public interface NoiseGenerator {
* @param position the position
* @return a noise value between 0 (inclusive) and 1 (inclusive)
*/
- float noise(Vector position);
+ float noise(Vector3 position);
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/RandomNoise.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/RandomNoise.java
index 6daed2841..ff3421404 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/RandomNoise.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/RandomNoise.java
@@ -19,8 +19,8 @@
package com.sk89q.worldedit.math.noise;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.Vector2D;
+import com.sk89q.worldedit.math.Vector2;
+import com.sk89q.worldedit.math.Vector3;
import java.util.Random;
@@ -50,12 +50,12 @@ public class RandomNoise implements NoiseGenerator {
}
@Override
- public float noise(Vector2D position) {
+ public float noise(Vector2 position) {
return random.nextFloat();
}
@Override
- public float noise(Vector position) {
+ public float noise(Vector3 position) {
return random.nextFloat();
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java
index 36db0566c..376fd0b33 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java
@@ -19,8 +19,9 @@
package com.sk89q.worldedit.math.transform;
-import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MathUtils;
+import com.sk89q.worldedit.math.Vector3;
/**
* An affine transform.
@@ -236,7 +237,11 @@ public class AffineTransform implements Transform {
n20, n21, n22, n23);
}
- public AffineTransform translate(Vector vec) {
+ public AffineTransform translate(Vector3 vec) {
+ return translate(vec.getX(), vec.getY(), vec.getZ());
+ }
+
+ public AffineTransform translate(BlockVector3 vec) {
return translate(vec.getX(), vec.getY(), vec.getZ());
}
@@ -282,13 +287,13 @@ public class AffineTransform implements Transform {
return concatenate(new AffineTransform(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0));
}
- public AffineTransform scale(Vector vec) {
+ public AffineTransform scale(Vector3 vec) {
return scale(vec.getX(), vec.getY(), vec.getZ());
}
@Override
- public Vector apply(Vector vector) {
- return new Vector(
+ public Vector3 apply(Vector3 vector) {
+ return new Vector3(
vector.getX() * m00 + vector.getY() * m01 + vector.getZ() * m02 + m03,
vector.getX() * m10 + vector.getY() * m11 + vector.getZ() * m12 + m13,
vector.getX() * m20 + vector.getY() * m21 + vector.getZ() * m22 + m23);
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/CombinedTransform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/CombinedTransform.java
index 646e2a209..e5f2a2586 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/CombinedTransform.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/CombinedTransform.java
@@ -21,7 +21,7 @@ package com.sk89q.worldedit.math.transform;
import static com.google.common.base.Preconditions.checkNotNull;
-import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.math.Vector3;
import java.util.ArrayList;
import java.util.Arrays;
@@ -66,7 +66,7 @@ public class CombinedTransform implements Transform {
}
@Override
- public Vector apply(Vector vector) {
+ public Vector3 apply(Vector3 vector) {
for (Transform transform : transforms) {
vector = transform.apply(vector);
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Identity.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Identity.java
index b0f4dddef..f9f1ed125 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Identity.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Identity.java
@@ -19,7 +19,7 @@
package com.sk89q.worldedit.math.transform;
-import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.math.Vector3;
/**
* Makes no transformation to given vectors.
@@ -32,7 +32,7 @@ public class Identity implements Transform {
}
@Override
- public Vector apply(Vector vector) {
+ public Vector3 apply(Vector3 vector) {
return vector;
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Transform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Transform.java
index b8df8bcbd..e12030022 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Transform.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Transform.java
@@ -19,10 +19,10 @@
package com.sk89q.worldedit.math.transform;
-import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.math.Vector3;
/**
- * Makes a transformation of {@link Vector}s.
+ * Makes a transformation of {@link Vector3}s.
*/
public interface Transform {
@@ -41,7 +41,7 @@ public interface Transform {
* @param input the input
* @return the result
*/
- Vector apply(Vector input);
+ Vector3 apply(Vector3 input);
/**
* Create a new inverse transform.
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java
index 44f7070cb..cdaf362db 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java
@@ -19,10 +19,9 @@
package com.sk89q.worldedit.regions;
-import com.sk89q.worldedit.BlockVector;
-import com.sk89q.worldedit.BlockVector2D;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.Vector2D;
+import com.sk89q.worldedit.math.BlockVector2;
+import com.sk89q.worldedit.math.BlockVector3;
+import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.iterator.RegionIterator;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.storage.ChunkStore;
@@ -42,8 +41,8 @@ public abstract class AbstractRegion implements Region {
}
@Override
- public Vector getCenter() {
- return getMinimumPoint().add(getMaximumPoint()).divide(2);
+ public Vector3 getCenter() {
+ return getMinimumPoint().add(getMaximumPoint()).toVector3().divide(2);
}
/**
@@ -52,7 +51,7 @@ public abstract class AbstractRegion implements Region {
* @return iterator of points inside the region
*/
@Override
- public Iterator iterator() {
+ public Iterator iterator() {
return new RegionIterator(this);
}
@@ -67,7 +66,7 @@ public abstract class AbstractRegion implements Region {
}
@Override
- public void shift(Vector change) throws RegionOperationException {
+ public void shift(BlockVector3 change) throws RegionOperationException {
expand(change);
contract(change);
}
@@ -82,20 +81,20 @@ public abstract class AbstractRegion implements Region {
}
@Override
- public List polygonize(int maxPoints) {
+ public List polygonize(int maxPoints) {
if (maxPoints >= 0 && maxPoints < 4) {
throw new IllegalArgumentException("Cannot polygonize an AbstractRegion with no overridden polygonize method into less than 4 points.");
}
- final BlockVector min = getMinimumPoint().toBlockVector();
- final BlockVector max = getMaximumPoint().toBlockVector();
+ final BlockVector3 min = getMinimumPoint();
+ final BlockVector3 max = getMaximumPoint();
- final List points = new ArrayList<>(4);
+ final List points = new ArrayList<>(4);
- points.add(new BlockVector2D(min.getX(), min.getZ()));
- points.add(new BlockVector2D(min.getX(), max.getZ()));
- points.add(new BlockVector2D(max.getX(), max.getZ()));
- points.add(new BlockVector2D(max.getX(), min.getZ()));
+ points.add(new BlockVector2(min.getX(), min.getZ()));
+ points.add(new BlockVector2(min.getX(), max.getZ()));
+ points.add(new BlockVector2(max.getX(), max.getZ()));
+ points.add(new BlockVector2(max.getX(), min.getZ()));
return points;
}
@@ -107,12 +106,12 @@ public abstract class AbstractRegion implements Region {
*/
@Override
public int getArea() {
- Vector min = getMinimumPoint();
- Vector max = getMaximumPoint();
+ BlockVector3 min = getMinimumPoint();
+ BlockVector3 max = getMaximumPoint();
- return (int)((max.getX() - min.getX() + 1) *
- (max.getY() - min.getY() + 1) *
- (max.getZ() - min.getZ() + 1));
+ return (max.getX() - min.getX() + 1) *
+ (max.getY() - min.getY() + 1) *
+ (max.getZ() - min.getZ() + 1);
}
/**
@@ -122,10 +121,10 @@ public abstract class AbstractRegion implements Region {
*/
@Override
public int getWidth() {
- Vector min = getMinimumPoint();
- Vector max = getMaximumPoint();
+ BlockVector3 min = getMinimumPoint();
+ BlockVector3 max = getMaximumPoint();
- return (int) (max.getX() - min.getX() + 1);
+ return max.getX() - min.getX() + 1;
}
/**
@@ -135,10 +134,10 @@ public abstract class AbstractRegion implements Region {
*/
@Override
public int getHeight() {
- Vector min = getMinimumPoint();
- Vector max = getMaximumPoint();
+ BlockVector3 min = getMinimumPoint();
+ BlockVector3 max = getMaximumPoint();
- return (int) (max.getY() - min.getY() + 1);
+ return max.getY() - min.getY() + 1;
}
/**
@@ -148,10 +147,10 @@ public abstract class AbstractRegion implements Region {
*/
@Override
public int getLength() {
- Vector min = getMinimumPoint();
- Vector max = getMaximumPoint();
+ BlockVector3 min = getMinimumPoint();
+ BlockVector3 max = getMaximumPoint();
- return (int) (max.getZ() - min.getZ() + 1);
+ return max.getZ() - min.getZ() + 1;
}
/**
@@ -160,21 +159,21 @@ public abstract class AbstractRegion implements Region {
* @return a set of chunks
*/
@Override
- public Set getChunks() {
- final Set chunks = new HashSet<>();
+ public Set getChunks() {
+ final Set chunks = new HashSet<>();
- final Vector min = getMinimumPoint();
- final Vector max = getMaximumPoint();
+ final BlockVector3 min = getMinimumPoint();
+ final BlockVector3 max = getMaximumPoint();
final int minY = min.getBlockY();
for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
- if (!contains(new Vector(x, minY, z))) {
+ if (!contains(new BlockVector3(x, minY, z))) {
continue;
}
- chunks.add(new BlockVector2D(
+ chunks.add(new BlockVector2(
x >> ChunkStore.CHUNK_SHIFTS,
z >> ChunkStore.CHUNK_SHIFTS
));
@@ -185,20 +184,20 @@ public abstract class AbstractRegion implements Region {
}
@Override
- public Set getChunkCubes() {
- final Set chunks = new HashSet<>();
+ public Set getChunkCubes() {
+ final Set chunks = new HashSet<>();
- final Vector min = getMinimumPoint();
- final Vector max = getMaximumPoint();
+ final BlockVector3 min = getMinimumPoint();
+ final BlockVector3 max = getMaximumPoint();
for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
- if (!contains(new Vector(x, y, z))) {
+ if (!contains(new BlockVector3(x, y, z))) {
continue;
}
- chunks.add(new BlockVector(
+ chunks.add(new BlockVector3(
x >> ChunkStore.CHUNK_SHIFTS,
y >> ChunkStore.CHUNK_SHIFTS,
z >> ChunkStore.CHUNK_SHIFTS
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegion.java
index fce016e23..ce1fc5b22 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegion.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegion.java
@@ -21,7 +21,8 @@ package com.sk89q.worldedit.regions;
import static com.google.common.base.Preconditions.checkNotNull;
-import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.math.BlockVector3;
+import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.polyhedron.Edge;
import com.sk89q.worldedit.regions.polyhedron.Triangle;
import com.sk89q.worldedit.world.World;
@@ -40,7 +41,7 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
/**
* Vertices that are contained in the convex hull.
*/
- private final Set vertices = new LinkedHashSet<>();
+ private final Set vertices = new LinkedHashSet<>();
/**
* Triangles that form the convex hull.
@@ -50,25 +51,25 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
/**
* Vertices that are coplanar to the first 3 vertices.
*/
- private final Set vertexBacklog = new LinkedHashSet<>();
+ private final Set vertexBacklog = new LinkedHashSet<>();
/**
* Minimum point of the axis-aligned bounding box.
*/
- private Vector minimumPoint;
+ private BlockVector3 minimumPoint;
/**
* Maximum point of the axis-aligned bounding box.
*/
- private Vector maximumPoint;
+ private BlockVector3 maximumPoint;
/**
* Accumulator for the barycenter of the polyhedron. Divide by vertices.size() to get the actual center.
*/
- private Vector centerAccum = Vector.ZERO;
+ private BlockVector3 centerAccum = BlockVector3.ZERO;
/**
- * The last triangle that caused a {@link #contains(Vector)} to classify a point as "outside". Used for optimization.
+ * The last triangle that caused a {@link #contains(Vector3)} to classify a point as "outside". Used for optimization.
*/
private Triangle lastTriangle;
@@ -108,7 +109,7 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
minimumPoint = null;
maximumPoint = null;
- centerAccum = Vector.ZERO;
+ centerAccum = BlockVector3.ZERO;
lastTriangle = null;
}
@@ -118,7 +119,7 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
* @param vertex the vertex
* @return true, if something changed.
*/
- public boolean addVertex(Vector vertex) {
+ public boolean addVertex(BlockVector3 vertex) {
checkNotNull(vertex);
lastTriangle = null; // Probably not necessary
@@ -132,7 +133,7 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
return false;
}
- if (containsRaw(vertex)) {
+ if (containsRaw(vertex.toVector3())) {
return vertexBacklog.add(vertex);
}
}
@@ -144,8 +145,8 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
if (minimumPoint == null) {
minimumPoint = maximumPoint = vertex;
} else {
- minimumPoint = Vector.getMinimum(minimumPoint, vertex);
- maximumPoint = Vector.getMaximum(maximumPoint, vertex);
+ minimumPoint = minimumPoint.getMinimum(vertex);
+ maximumPoint = maximumPoint.getMaximum(vertex);
}
@@ -158,10 +159,10 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
case 3:
// Generate minimal mesh to start from
- final Vector[] v = vertices.toArray(new Vector[vertices.size()]);
+ final BlockVector3[] v = vertices.toArray(new BlockVector3[vertices.size()]);
- triangles.add((new Triangle(v[0], v[1], v[2])));
- triangles.add((new Triangle(v[0], v[2], v[1])));
+ triangles.add((new Triangle(v[0].toVector3(), v[1].toVector3(), v[2].toVector3())));
+ triangles.add((new Triangle(v[0].toVector3(), v[2].toVector3(), v[1].toVector3())));
return true;
}
@@ -171,7 +172,7 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
final Triangle triangle = it.next();
// If the triangle can't be seen, it's not relevant
- if (!triangle.above(vertex)) {
+ if (!triangle.above(vertex.toVector3())) {
continue;
}
@@ -191,7 +192,7 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
// Add triangles between the remembered edges and the new vertex.
for (Edge edge : borderEdges) {
- triangles.add(edge.createTriangle(vertex));
+ triangles.add(edge.createTriangle(vertex.toVector3()));
}
if (!vertexBacklog.isEmpty()) {
@@ -199,9 +200,9 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
vertices.remove(vertex);
// Clone, clear and work through the backlog
- final List vertexBacklog2 = new ArrayList<>(vertexBacklog);
+ final List vertexBacklog2 = new ArrayList<>(vertexBacklog);
vertexBacklog.clear();
- for (Vector vertex2 : vertexBacklog2) {
+ for (BlockVector3 vertex2 : vertexBacklog2) {
addVertex(vertex2);
}
@@ -217,39 +218,40 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
}
@Override
- public Vector getMinimumPoint() {
+ public BlockVector3 getMinimumPoint() {
return minimumPoint;
}
@Override
- public Vector getMaximumPoint() {
+ public BlockVector3 getMaximumPoint() {
return maximumPoint;
}
@Override
- public Vector getCenter() {
- return centerAccum.divide(vertices.size());
+ public Vector3 getCenter() {
+ return centerAccum.toVector3().divide(vertices.size());
}
@Override
- public void expand(Vector... changes) throws RegionOperationException {
+ public void expand(BlockVector3... changes) throws RegionOperationException {
}
@Override
- public void contract(Vector... changes) throws RegionOperationException {
+ public void contract(BlockVector3... changes) throws RegionOperationException {
}
@Override
- public void shift(Vector change) throws RegionOperationException {
+ public void shift(BlockVector3 change) throws RegionOperationException {
+ Vector3 vec = change.toVector3();
shiftCollection(vertices, change);
shiftCollection(vertexBacklog, change);
for (int i = 0; i < triangles.size(); ++i) {
final Triangle triangle = triangles.get(i);
- final Vector v0 = change.add(triangle.getVertex(0));
- final Vector v1 = change.add(triangle.getVertex(1));
- final Vector v2 = change.add(triangle.getVertex(2));
+ final Vector3 v0 = vec.add(triangle.getVertex(0));
+ final Vector3 v1 = vec.add(triangle.getVertex(1));
+ final Vector3 v2 = vec.add(triangle.getVertex(2));
triangles.set(i, new Triangle(v0, v1, v2));
}
@@ -260,16 +262,16 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
lastTriangle = null;
}
- private static void shiftCollection(Collection collection, Vector change) {
- final List tmp = new ArrayList<>(collection);
+ private static void shiftCollection(Collection collection, BlockVector3 change) {
+ final List tmp = new ArrayList<>(collection);
collection.clear();
- for (Vector vertex : tmp) {
+ for (BlockVector3 vertex : tmp) {
collection.add(change.add(vertex));
}
}
@Override
- public boolean contains(Vector position) {
+ public boolean contains(BlockVector3 position) {
if (!isDefined()) {
return false;
}
@@ -278,8 +280,8 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
final int y = position.getBlockY();
final int z = position.getBlockZ();
- final Vector min = getMinimumPoint();
- final Vector max = getMaximumPoint();
+ final BlockVector3 min = getMinimumPoint();
+ final BlockVector3 max = getMaximumPoint();
if (x < min.getBlockX()) return false;
if (x > max.getBlockX()) return false;
@@ -288,10 +290,10 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
if (z < min.getBlockZ()) return false;
if (z > max.getBlockZ()) return false;
- return containsRaw(position);
+ return containsRaw(position.toVector3());
}
- private boolean containsRaw(Vector pt) {
+ private boolean containsRaw(Vector3 pt) {
if (lastTriangle != null && lastTriangle.above(pt)) {
return false;
}
@@ -310,12 +312,12 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
return true;
}
- public Collection getVertices() {
+ public Collection getVertices() {
if (vertexBacklog.isEmpty()) {
return vertices;
}
- final List ret = new ArrayList<>(vertices);
+ final List ret = new ArrayList<>(vertices);
ret.addAll(vertexBacklog);
return ret;
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java
index 942e92d6e..cebd62098 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java
@@ -22,15 +22,14 @@ package com.sk89q.worldedit.regions;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
-import com.sk89q.worldedit.BlockVector;
-import com.sk89q.worldedit.BlockVector2D;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.Vector2D;
+import com.sk89q.worldedit.math.BlockVector2;
+import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.storage.ChunkStore;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.NoSuchElementException;
import java.util.Set;
/**
@@ -38,8 +37,8 @@ import java.util.Set;
*/
public class CuboidRegion extends AbstractRegion implements FlatRegion {
- private Vector pos1;
- private Vector pos2;
+ private BlockVector3 pos1;
+ private BlockVector3 pos2;
/**
* Construct a new instance of this cuboid using two corners of the cuboid.
@@ -47,7 +46,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
* @param pos1 the first position
* @param pos2 the second position
*/
- public CuboidRegion(Vector pos1, Vector pos2) {
+ public CuboidRegion(BlockVector3 pos1, BlockVector3 pos2) {
this(null, pos1, pos2);
}
@@ -58,7 +57,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
* @param pos1 the first position
* @param pos2 the second position
*/
- public CuboidRegion(World world, Vector pos1, Vector pos2) {
+ public CuboidRegion(World world, BlockVector3 pos1, BlockVector3 pos2) {
super(world);
checkNotNull(pos1);
checkNotNull(pos2);
@@ -72,7 +71,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
*
* @return a position
*/
- public Vector getPos1() {
+ public BlockVector3 getPos1() {
return pos1;
}
@@ -81,7 +80,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
*
* @param pos1 a position
*/
- public void setPos1(Vector pos1) {
+ public void setPos1(BlockVector3 pos1) {
this.pos1 = pos1;
}
@@ -90,7 +89,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
*
* @return a position
*/
- public Vector getPos2() {
+ public BlockVector3 getPos2() {
return pos2;
}
@@ -99,7 +98,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
*
* @param pos2 a position
*/
- public void setPos2(Vector pos2) {
+ public void setPos2(BlockVector3 pos2) {
this.pos2 = pos2;
}
@@ -117,21 +116,21 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
* @return a new complex region
*/
public Region getFaces() {
- Vector min = getMinimumPoint();
- Vector max = getMaximumPoint();
+ BlockVector3 min = getMinimumPoint();
+ BlockVector3 max = getMaximumPoint();
return new RegionIntersection(
// Project to Z-Y plane
- new CuboidRegion(pos1.setX(min.getX()), pos2.setX(min.getX())),
- new CuboidRegion(pos1.setX(max.getX()), pos2.setX(max.getX())),
+ new CuboidRegion(pos1.withX(min.getX()), pos2.withX(min.getX())),
+ new CuboidRegion(pos1.withX(max.getX()), pos2.withX(max.getX())),
// Project to X-Y plane
- new CuboidRegion(pos1.setZ(min.getZ()), pos2.setZ(min.getZ())),
- new CuboidRegion(pos1.setZ(max.getZ()), pos2.setZ(max.getZ())),
+ new CuboidRegion(pos1.withZ(min.getZ()), pos2.withZ(min.getZ())),
+ new CuboidRegion(pos1.withZ(max.getZ()), pos2.withZ(max.getZ())),
// Project to the X-Z plane
- new CuboidRegion(pos1.setY(min.getY()), pos2.setY(min.getY())),
- new CuboidRegion(pos1.setY(max.getY()), pos2.setY(max.getY())));
+ new CuboidRegion(pos1.withY(min.getY()), pos2.withY(min.getY())),
+ new CuboidRegion(pos1.withY(max.getY()), pos2.withY(max.getY())));
}
/**
@@ -141,31 +140,27 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
* @return a new complex region
*/
public Region getWalls() {
- Vector min = getMinimumPoint();
- Vector max = getMaximumPoint();
+ BlockVector3 min = getMinimumPoint();
+ BlockVector3 max = getMaximumPoint();
return new RegionIntersection(
// Project to Z-Y plane
- new CuboidRegion(pos1.setX(min.getX()), pos2.setX(min.getX())),
- new CuboidRegion(pos1.setX(max.getX()), pos2.setX(max.getX())),
+ new CuboidRegion(pos1.withX(min.getX()), pos2.withX(min.getX())),
+ new CuboidRegion(pos1.withX(max.getX()), pos2.withX(max.getX())),
// Project to X-Y plane
- new CuboidRegion(pos1.setZ(min.getZ()), pos2.setZ(min.getZ())),
- new CuboidRegion(pos1.setZ(max.getZ()), pos2.setZ(max.getZ())));
+ new CuboidRegion(pos1.withZ(min.getZ()), pos2.withZ(min.getZ())),
+ new CuboidRegion(pos1.withZ(max.getZ()), pos2.withZ(max.getZ())));
}
@Override
- public Vector getMinimumPoint() {
- return new Vector(Math.min(pos1.getX(), pos2.getX()),
- Math.min(pos1.getY(), pos2.getY()),
- Math.min(pos1.getZ(), pos2.getZ()));
+ public BlockVector3 getMinimumPoint() {
+ return pos1.getMinimum(pos2);
}
@Override
- public Vector getMaximumPoint() {
- return new Vector(Math.max(pos1.getX(), pos2.getX()),
- Math.max(pos1.getY(), pos2.getY()),
- Math.max(pos1.getZ(), pos2.getZ()));
+ public BlockVector3 getMaximumPoint() {
+ return pos1.getMaximum(pos2);
}
@Override
@@ -179,49 +174,49 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public void expand(Vector... changes) {
+ public void expand(BlockVector3... changes) {
checkNotNull(changes);
- for (Vector change : changes) {
+ for (BlockVector3 change : changes) {
if (change.getX() > 0) {
if (Math.max(pos1.getX(), pos2.getX()) == pos1.getX()) {
- pos1 = pos1.add(new Vector(change.getX(), 0, 0));
+ pos1 = pos1.add(change.getX(), 0, 0);
} else {
- pos2 = pos2.add(new Vector(change.getX(), 0, 0));
+ pos2 = pos2.add(change.getX(), 0, 0);
}
} else {
if (Math.min(pos1.getX(), pos2.getX()) == pos1.getX()) {
- pos1 = pos1.add(new Vector(change.getX(), 0, 0));
+ pos1 = pos1.add(change.getX(), 0, 0);
} else {
- pos2 = pos2.add(new Vector(change.getX(), 0, 0));
+ pos2 = pos2.add(change.getX(), 0, 0);
}
}
if (change.getY() > 0) {
if (Math.max(pos1.getY(), pos2.getY()) == pos1.getY()) {
- pos1 = pos1.add(new Vector(0, change.getY(), 0));
+ pos1 = pos1.add(0, change.getY(), 0);
} else {
- pos2 = pos2.add(new Vector(0, change.getY(), 0));
+ pos2 = pos2.add(0, change.getY(), 0);
}
} else {
if (Math.min(pos1.getY(), pos2.getY()) == pos1.getY()) {
- pos1 = pos1.add(new Vector(0, change.getY(), 0));
+ pos1 = pos1.add(0, change.getY(), 0);
} else {
- pos2 = pos2.add(new Vector(0, change.getY(), 0));
+ pos2 = pos2.add(0, change.getY(), 0);
}
}
if (change.getZ() > 0) {
if (Math.max(pos1.getZ(), pos2.getZ()) == pos1.getZ()) {
- pos1 = pos1.add(new Vector(0, 0, change.getZ()));
+ pos1 = pos1.add(0, 0, change.getZ());
} else {
- pos2 = pos2.add(new Vector(0, 0, change.getZ()));
+ pos2 = pos2.add(0, 0, change.getZ());
}
} else {
if (Math.min(pos1.getZ(), pos2.getZ()) == pos1.getZ()) {
- pos1 = pos1.add(new Vector(0, 0, change.getZ()));
+ pos1 = pos1.add(0, 0, change.getZ());
} else {
- pos2 = pos2.add(new Vector(0, 0, change.getZ()));
+ pos2 = pos2.add(0, 0, change.getZ());
}
}
}
@@ -230,49 +225,49 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public void contract(Vector... changes) {
+ public void contract(BlockVector3... changes) {
checkNotNull(changes);
- for (Vector change : changes) {
+ for (BlockVector3 change : changes) {
if (change.getX() < 0) {
if (Math.max(pos1.getX(), pos2.getX()) == pos1.getX()) {
- pos1 = pos1.add(new Vector(change.getX(), 0, 0));
+ pos1 = pos1.add(change.getX(), 0, 0);
} else {
- pos2 = pos2.add(new Vector(change.getX(), 0, 0));
+ pos2 = pos2.add(change.getX(), 0, 0);
}
} else {
if (Math.min(pos1.getX(), pos2.getX()) == pos1.getX()) {
- pos1 = pos1.add(new Vector(change.getX(), 0, 0));
+ pos1 = pos1.add(change.getX(), 0, 0);
} else {
- pos2 = pos2.add(new Vector(change.getX(), 0, 0));
+ pos2 = pos2.add(change.getX(), 0, 0);
}
}
if (change.getY() < 0) {
if (Math.max(pos1.getY(), pos2.getY()) == pos1.getY()) {
- pos1 = pos1.add(new Vector(0, change.getY(), 0));
+ pos1 = pos1.add(0, change.getY(), 0);
} else {
- pos2 = pos2.add(new Vector(0, change.getY(), 0));
+ pos2 = pos2.add(0, change.getY(), 0);
}
} else {
if (Math.min(pos1.getY(), pos2.getY()) == pos1.getY()) {
- pos1 = pos1.add(new Vector(0, change.getY(), 0));
+ pos1 = pos1.add(0, change.getY(), 0);
} else {
- pos2 = pos2.add(new Vector(0, change.getY(), 0));
+ pos2 = pos2.add(0, change.getY(), 0);
}
}
if (change.getZ() < 0) {
if (Math.max(pos1.getZ(), pos2.getZ()) == pos1.getZ()) {
- pos1 = pos1.add(new Vector(0, 0, change.getZ()));
+ pos1 = pos1.add(0, 0, change.getZ());
} else {
- pos2 = pos2.add(new Vector(0, 0, change.getZ()));
+ pos2 = pos2.add(0, 0, change.getZ());
}
} else {
if (Math.min(pos1.getZ(), pos2.getZ()) == pos1.getZ()) {
- pos1 = pos1.add(new Vector(0, 0, change.getZ()));
+ pos1 = pos1.add(0, 0, change.getZ());
} else {
- pos2 = pos2.add(new Vector(0, 0, change.getZ()));
+ pos2 = pos2.add(0, 0, change.getZ());
}
}
}
@@ -281,7 +276,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public void shift(Vector change) throws RegionOperationException {
+ public void shift(BlockVector3 change) throws RegionOperationException {
pos1 = pos1.add(change);
pos2 = pos2.add(change);
@@ -289,15 +284,15 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public Set getChunks() {
- Set chunks = new HashSet<>();
+ public Set getChunks() {
+ Set chunks = new HashSet<>();
- Vector min = getMinimumPoint();
- Vector max = getMaximumPoint();
+ BlockVector3 min = getMinimumPoint();
+ BlockVector3 max = getMaximumPoint();
for (int x = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x <= max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; ++x) {
for (int z = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z <= max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; ++z) {
- chunks.add(new BlockVector2D(x, z));
+ chunks.add(new BlockVector2(x, z));
}
}
@@ -305,16 +300,16 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public Set getChunkCubes() {
- Set chunks = new HashSet<>();
+ public Set getChunkCubes() {
+ Set chunks = new HashSet<>();
- Vector min = getMinimumPoint();
- Vector max = getMaximumPoint();
+ BlockVector3 min = getMinimumPoint();
+ BlockVector3 max = getMaximumPoint();
for (int x = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x <= max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; ++x) {
for (int z = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z <= max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; ++z) {
for (int y = min.getBlockY() >> ChunkStore.CHUNK_SHIFTS; y <= max.getBlockY() >> ChunkStore.CHUNK_SHIFTS; ++y) {
- chunks.add(new BlockVector(x, y, z));
+ chunks.add(new BlockVector3(x, y, z));
}
}
}
@@ -323,24 +318,18 @@ 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();
+ public boolean contains(BlockVector3 position) {
+ BlockVector3 min = getMinimumPoint();
+ BlockVector3 max = getMaximumPoint();
- Vector min = getMinimumPoint();
- Vector max = getMaximumPoint();
-
- return x >= min.getBlockX() && x <= max.getBlockX()
- && y >= min.getBlockY() && y <= max.getBlockY()
- && z >= min.getBlockZ() && z <= max.getBlockZ();
+ return position.containedWithin(min, max);
}
@Override
- public Iterator iterator() {
- return new Iterator() {
- private Vector min = getMinimumPoint();
- private Vector max = getMaximumPoint();
+ public Iterator iterator() {
+ return new Iterator() {
+ private BlockVector3 min = getMinimumPoint();
+ private BlockVector3 max = getMaximumPoint();
private int nextX = min.getBlockX();
private int nextY = min.getBlockY();
private int nextZ = min.getBlockZ();
@@ -351,9 +340,9 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public BlockVector next() {
- if (!hasNext()) throw new java.util.NoSuchElementException();
- BlockVector answer = new BlockVector(nextX, nextY, nextZ);
+ public BlockVector3 next() {
+ if (!hasNext()) throw new NoSuchElementException();
+ BlockVector3 answer = new BlockVector3(nextX, nextY, nextZ);
if (++nextX > max.getBlockX()) {
nextX = min.getBlockX();
if (++nextY > max.getBlockY()) {
@@ -365,19 +354,14 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
return answer;
}
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
};
}
@Override
- public Iterable asFlatRegion() {
- return () -> new Iterator() {
- private Vector min = getMinimumPoint();
- private Vector max = getMaximumPoint();
+ public Iterable asFlatRegion() {
+ return () -> new Iterator() {
+ private BlockVector3 min = getMinimumPoint();
+ private BlockVector3 max = getMaximumPoint();
private int nextX = min.getBlockX();
private int nextZ = min.getBlockZ();
@@ -387,9 +371,9 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public Vector2D next() {
- if (!hasNext()) throw new java.util.NoSuchElementException();
- Vector2D answer = new Vector2D(nextX, nextZ);
+ public BlockVector2 next() {
+ if (!hasNext()) throw new NoSuchElementException();
+ BlockVector2 answer = new BlockVector2(nextX, nextZ);
if (++nextX > max.getBlockX()) {
nextX = min.getBlockX();
if (++nextZ > max.getBlockZ()) {
@@ -398,11 +382,6 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
return answer;
}
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
};
}
@@ -435,10 +414,10 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
* @param apothem the apothem, where 0 is the minimum value to make a 1x1 cuboid
* @return a cuboid region
*/
- public static CuboidRegion fromCenter(Vector origin, int apothem) {
+ public static CuboidRegion fromCenter(BlockVector3 origin, int apothem) {
checkNotNull(origin);
checkArgument(apothem >= 0, "apothem => 0 required");
- Vector size = new Vector(1, 1, 1).multiply(apothem);
+ BlockVector3 size = BlockVector3.ONE.multiply(apothem);
return new CuboidRegion(origin.subtract(size), origin.add(size));
}
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java
index ed0e70822..acff65c3a 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java
@@ -21,11 +21,11 @@ package com.sk89q.worldedit.regions;
import static com.google.common.base.Preconditions.checkNotNull;
-import com.sk89q.worldedit.BlockVector;
-import com.sk89q.worldedit.BlockVector2D;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.extent.Extent;
+import com.sk89q.worldedit.math.BlockVector3;
+import com.sk89q.worldedit.math.BlockVector2;
+import com.sk89q.worldedit.math.Vector2;
+import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.geom.Polygons;
import com.sk89q.worldedit.regions.iterator.FlatRegion3DIterator;
import com.sk89q.worldedit.regions.iterator.FlatRegionIterator;
@@ -39,8 +39,8 @@ import java.util.List;
*/
public class CylinderRegion extends AbstractRegion implements FlatRegion {
- private Vector2D center;
- private Vector2D radius;
+ private BlockVector2 center;
+ private Vector2 radius;
private int minY;
private int maxY;
private boolean hasY = false;
@@ -58,7 +58,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
* @param world the world
*/
public CylinderRegion(World world) {
- this(world, new Vector(), new Vector2D(), 0, 0);
+ this(world, BlockVector3.ZERO, Vector2.ZERO, 0, 0);
hasY = false;
}
@@ -71,9 +71,9 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
* @param minY the minimum Y, inclusive
* @param maxY the maximum Y, inclusive
*/
- public CylinderRegion(World world, Vector center, Vector2D radius, int minY, int maxY) {
+ public CylinderRegion(World world, BlockVector3 center, Vector2 radius, int minY, int maxY) {
super(world);
- setCenter(center.toVector2D());
+ setCenter(center.toBlockVector2());
setRadius(radius);
this.minY = minY;
this.maxY = maxY;
@@ -88,9 +88,9 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
* @param minY the minimum Y, inclusive
* @param maxY the maximum Y, inclusive
*/
- public CylinderRegion(Vector center, Vector2D radius, int minY, int maxY) {
+ public CylinderRegion(BlockVector3 center, Vector2 radius, int minY, int maxY) {
super(null);
- setCenter(center.toVector2D());
+ setCenter(center.toBlockVector2());
setRadius(radius);
this.minY = minY;
this.maxY = maxY;
@@ -98,13 +98,13 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
}
public CylinderRegion(CylinderRegion region) {
- this(region.world, region.getCenter(), region.getRadius(), region.minY, region.maxY);
+ this(region.world, region.getCenter().toBlockPoint(), region.getRadius(), region.minY, region.maxY);
hasY = region.hasY;
}
@Override
- public Vector getCenter() {
- return center.toVector((maxY + minY) / 2);
+ public Vector3 getCenter() {
+ return center.toVector3((maxY + minY) / 2);
}
/**
@@ -112,7 +112,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
*
* @param center the center point
*/
- public void setCenter(Vector2D center) {
+ public void setCenter(BlockVector2 center) {
this.center = center;
}
@@ -121,7 +121,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
*
* @return the radius along the X and Z axes
*/
- public Vector2D getRadius() {
+ public Vector2 getRadius() {
return radius.subtract(0.5, 0.5);
}
@@ -130,7 +130,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
*
* @param radius the radius along the X and Z axes
*/
- public void setRadius(Vector2D radius) {
+ public void setRadius(Vector2 radius) {
this.radius = radius.add(0.5, 0.5);
}
@@ -139,8 +139,8 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
*
* @param minRadius the minimum radius
*/
- public void extendRadius(Vector2D minRadius) {
- setRadius(Vector2D.getMaximum(minRadius, getRadius()));
+ public void extendRadius(Vector2 minRadius) {
+ setRadius(minRadius.getMaximum(getRadius()));
}
/**
@@ -164,13 +164,13 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public Vector getMinimumPoint() {
- return center.subtract(getRadius()).toVector(minY);
+ public BlockVector3 getMinimumPoint() {
+ return center.toVector2().subtract(getRadius()).toVector3(minY).toBlockPoint();
}
@Override
- public Vector getMaximumPoint() {
- return center.add(getRadius()).toVector(maxY);
+ public BlockVector3 getMaximumPoint() {
+ return center.toVector2().add(getRadius()).toVector3(maxY).toBlockPoint();
}
@Override
@@ -203,10 +203,10 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
return (int) (2 * radius.getZ());
}
- private Vector2D calculateDiff2D(Vector... changes) throws RegionOperationException {
- Vector2D diff = new Vector2D();
- for (Vector change : changes) {
- diff = diff.add(change.toVector2D());
+ private BlockVector2 calculateDiff2D(BlockVector3... changes) throws RegionOperationException {
+ BlockVector2 diff = BlockVector2.ZERO;
+ for (BlockVector3 change : changes) {
+ diff = diff.add(change.toBlockVector2());
}
if ((diff.getBlockX() & 1) + (diff.getBlockZ() & 1) != 0) {
@@ -216,10 +216,10 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
return diff.divide(2).floor();
}
- private Vector2D calculateChanges2D(Vector... changes) {
- Vector2D total = new Vector2D();
- for (Vector change : changes) {
- total = total.add(change.toVector2D().positive());
+ private BlockVector2 calculateChanges2D(BlockVector3... changes) {
+ BlockVector2 total = BlockVector2.ZERO;
+ for (BlockVector3 change : changes) {
+ total = total.add(change.toBlockVector2().abs());
}
return total.divide(2).floor();
@@ -233,10 +233,10 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
* @throws RegionOperationException
*/
@Override
- public void expand(Vector... changes) throws RegionOperationException {
+ public void expand(BlockVector3... changes) throws RegionOperationException {
center = center.add(calculateDiff2D(changes));
- radius = radius.add(calculateChanges2D(changes));
- for (Vector change : changes) {
+ radius = radius.add(calculateChanges2D(changes).toVector2());
+ for (BlockVector3 change : changes) {
int changeY = change.getBlockY();
if (changeY > 0) {
maxY += changeY;
@@ -253,11 +253,11 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
* @throws RegionOperationException
*/
@Override
- public void contract(Vector... changes) throws RegionOperationException {
+ public void contract(BlockVector3... changes) throws RegionOperationException {
center = center.subtract(calculateDiff2D(changes));
- Vector2D newRadius = radius.subtract(calculateChanges2D(changes));
- radius = Vector2D.getMaximum(new Vector2D(1.5, 1.5), newRadius);
- for (Vector change : changes) {
+ Vector2 newRadius = radius.subtract(calculateChanges2D(changes).toVector2());
+ radius = new Vector2(1.5, 1.5).getMaximum(newRadius);
+ for (BlockVector3 change : changes) {
int height = maxY - minY;
int changeY = change.getBlockY();
if (changeY > 0) {
@@ -269,8 +269,8 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public void shift(Vector change) throws RegionOperationException {
- center = center.add(change.toVector2D());
+ public void shift(BlockVector3 change) throws RegionOperationException {
+ center = center.add(change.toBlockVector2());
int changeY = change.getBlockY();
maxY += changeY;
@@ -281,13 +281,13 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
* Checks to see if a point is inside this region.
*/
@Override
- public boolean contains(Vector position) {
+ public boolean contains(BlockVector3 position) {
final int blockY = position.getBlockY();
if (blockY < minY || blockY > maxY) {
return false;
}
- return position.toVector2D().subtract(center).divide(radius).lengthSq() <= 1;
+ return position.toBlockVector2().subtract(center).toVector2().divide(radius).lengthSq() <= 1;
}
@@ -315,12 +315,12 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public Iterator iterator() {
+ public Iterator iterator() {
return new FlatRegion3DIterator(this);
}
@Override
- public Iterable asFlatRegion() {
+ public Iterable asFlatRegion() {
return () -> new FlatRegionIterator(CylinderRegion.this);
}
@@ -341,7 +341,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public List polygonize(int maxPoints) {
+ public List polygonize(int maxPoints) {
return Polygons.polygonizeCylinder(center, radius, maxPoints);
}
@@ -355,10 +355,10 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
* @param radius the radius in the X and Z axes
* @return a region
*/
- public static CylinderRegion createRadius(Extent extent, Vector center, double radius) {
+ public static CylinderRegion createRadius(Extent extent, BlockVector3 center, double radius) {
checkNotNull(extent);
checkNotNull(center);
- Vector2D radiusVec = new Vector2D(radius, radius);
+ Vector2 radiusVec = new Vector2(radius, radius);
int minY = extent.getMinimumPoint().getBlockY();
int maxY = extent.getMaximumPoint().getBlockY();
return new CylinderRegion(center, radiusVec, minY, maxY);
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java
index 069cdaff3..0cf5e4b59 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java
@@ -19,10 +19,9 @@
package com.sk89q.worldedit.regions;
-import com.sk89q.worldedit.BlockVector;
-import com.sk89q.worldedit.BlockVector2D;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.Vector2D;
+import com.sk89q.worldedit.math.BlockVector2;
+import com.sk89q.worldedit.math.BlockVector3;
+import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.storage.ChunkStore;
@@ -37,12 +36,12 @@ public class EllipsoidRegion extends AbstractRegion {
/**
* Stores the center.
*/
- private Vector center;
+ private BlockVector3 center;
/**
* Stores the radii plus 0.5 on each axis.
*/
- private Vector radius;
+ private Vector3 radius;
/**
* Construct a new instance of this ellipsoid region.
@@ -50,7 +49,7 @@ public class EllipsoidRegion extends AbstractRegion {
* @param pos1 the first position
* @param pos2 the second position
*/
- public EllipsoidRegion(Vector pos1, Vector pos2) {
+ public EllipsoidRegion(BlockVector3 pos1, Vector3 pos2) {
this(null, pos1, pos2);
}
@@ -61,7 +60,7 @@ public class EllipsoidRegion extends AbstractRegion {
* @param center the center
* @param radius the radius
*/
- public EllipsoidRegion(World world, Vector center, Vector radius) {
+ public EllipsoidRegion(World world, BlockVector3 center, Vector3 radius) {
super(world);
this.center = center;
setRadius(radius);
@@ -72,13 +71,13 @@ public class EllipsoidRegion extends AbstractRegion {
}
@Override
- public Vector getMinimumPoint() {
- return center.subtract(getRadius());
+ public BlockVector3 getMinimumPoint() {
+ return center.toVector3().subtract(getRadius()).toBlockPoint();
}
@Override
- public Vector getMaximumPoint() {
- return center.add(getRadius());
+ public BlockVector3 getMaximumPoint() {
+ return center.toVector3().add(getRadius()).toBlockPoint();
}
@Override
@@ -101,8 +100,8 @@ public class EllipsoidRegion extends AbstractRegion {
return (int) (2 * radius.getZ());
}
- private Vector calculateDiff(Vector... changes) throws RegionOperationException {
- Vector diff = new Vector().add(changes);
+ private BlockVector3 calculateDiff(BlockVector3... changes) throws RegionOperationException {
+ BlockVector3 diff = BlockVector3.ZERO.add(changes);
if ((diff.getBlockX() & 1) + (diff.getBlockY() & 1) + (diff.getBlockZ() & 1) != 0) {
throw new RegionOperationException(
@@ -112,30 +111,30 @@ public class EllipsoidRegion extends AbstractRegion {
return diff.divide(2).floor();
}
- private Vector calculateChanges(Vector... changes) {
- Vector total = new Vector();
- for (Vector change : changes) {
- total = total.add(change.positive());
+ private Vector3 calculateChanges(BlockVector3... changes) {
+ Vector3 total = Vector3.ZERO;
+ for (BlockVector3 change : changes) {
+ total = total.add(change.abs().toVector3());
}
return total.divide(2).floor();
}
@Override
- public void expand(Vector... changes) throws RegionOperationException {
+ public void expand(BlockVector3... changes) throws RegionOperationException {
center = center.add(calculateDiff(changes));
radius = radius.add(calculateChanges(changes));
}
@Override
- public void contract(Vector... changes) throws RegionOperationException {
+ public void contract(BlockVector3... changes) throws RegionOperationException {
center = center.subtract(calculateDiff(changes));
- Vector newRadius = radius.subtract(calculateChanges(changes));
- radius = Vector.getMaximum(new Vector(1.5, 1.5, 1.5), newRadius);
+ Vector3 newRadius = radius.subtract(calculateChanges(changes));
+ radius = new Vector3(1.5, 1.5, 1.5).getMaximum(newRadius);
}
@Override
- public void shift(Vector change) throws RegionOperationException {
+ public void shift(BlockVector3 change) throws RegionOperationException {
center = center.add(change);
}
@@ -145,8 +144,8 @@ public class EllipsoidRegion extends AbstractRegion {
* @return center
*/
@Override
- public Vector getCenter() {
- return center;
+ public Vector3 getCenter() {
+ return center.toVector3();
}
/**
@@ -154,7 +153,7 @@ public class EllipsoidRegion extends AbstractRegion {
*
* @param center the center
*/
- public void setCenter(Vector center) {
+ public void setCenter(BlockVector3 center) {
this.center = center;
}
@@ -163,7 +162,7 @@ public class EllipsoidRegion extends AbstractRegion {
*
* @return radii
*/
- public Vector getRadius() {
+ public Vector3 getRadius() {
return radius.subtract(0.5, 0.5, 0.5);
}
@@ -172,25 +171,25 @@ public class EllipsoidRegion extends AbstractRegion {
*
* @param radius the radius
*/
- public void setRadius(Vector radius) {
+ public void setRadius(Vector3 radius) {
this.radius = radius.add(0.5, 0.5, 0.5);
}
@Override
- public Set getChunks() {
- final Set chunks = new HashSet<>();
+ public Set getChunks() {
+ final Set chunks = new HashSet<>();
- final Vector min = getMinimumPoint();
- final Vector max = getMaximumPoint();
- final int centerY = getCenter().getBlockY();
+ final BlockVector3 min = getMinimumPoint();
+ final BlockVector3 max = getMaximumPoint();
+ final int centerY = center.getBlockY();
for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
- if (!contains(new BlockVector(x, centerY, z))) {
+ if (!contains(new BlockVector3(x, centerY, z))) {
continue;
}
- chunks.add(new BlockVector2D(
+ chunks.add(new BlockVector2(
x >> ChunkStore.CHUNK_SHIFTS,
z >> ChunkStore.CHUNK_SHIFTS
));
@@ -201,8 +200,8 @@ public class EllipsoidRegion extends AbstractRegion {
}
@Override
- public boolean contains(Vector position) {
- return position.subtract(center).divide(radius).lengthSq() <= 1;
+ public boolean contains(BlockVector3 position) {
+ return position.subtract(center).toVector3().divide(radius).lengthSq() <= 1;
}
/**
@@ -216,8 +215,8 @@ public class EllipsoidRegion extends AbstractRegion {
return center + " - " + getRadius();
}
- public void extendRadius(Vector minRadius) {
- setRadius(Vector.getMaximum(minRadius, getRadius()));
+ public void extendRadius(Vector3 minRadius) {
+ setRadius(minRadius.getMaximum(getRadius()));
}
@Override
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/FlatRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/FlatRegion.java
index 92cdf6e36..bd4561e4d 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/FlatRegion.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/FlatRegion.java
@@ -19,7 +19,7 @@
package com.sk89q.worldedit.regions;
-import com.sk89q.worldedit.Vector2D;
+import com.sk89q.worldedit.math.BlockVector2;
public interface FlatRegion extends Region {
@@ -42,5 +42,5 @@ public interface FlatRegion extends Region {
*
* @return a flat region iterable
*/
- Iterable asFlatRegion();
+ Iterable asFlatRegion();
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/NullRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/NullRegion.java
index 5f1c9653e..58e1d2197 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/NullRegion.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/NullRegion.java
@@ -19,10 +19,9 @@
package com.sk89q.worldedit.regions;
-import com.sk89q.worldedit.BlockVector;
-import com.sk89q.worldedit.BlockVector2D;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.Vector2D;
+import com.sk89q.worldedit.math.BlockVector2;
+import com.sk89q.worldedit.math.BlockVector3;
+import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.World;
import java.util.Collections;
@@ -39,18 +38,18 @@ public class NullRegion implements Region {
private World world;
@Override
- public Vector getMinimumPoint() {
- return new Vector(0, 0, 0);
+ public BlockVector3 getMinimumPoint() {
+ return BlockVector3.ZERO;
}
@Override
- public Vector getMaximumPoint() {
- return new Vector(0, 0, 0);
+ public BlockVector3 getMaximumPoint() {
+ return BlockVector3.ZERO;
}
@Override
- public Vector getCenter() {
- return new Vector(0, 0, 0);
+ public Vector3 getCenter() {
+ return Vector3.ZERO;
}
@Override
@@ -74,32 +73,32 @@ public class NullRegion implements Region {
}
@Override
- public void expand(Vector... changes) throws RegionOperationException {
+ public void expand(BlockVector3... changes) throws RegionOperationException {
throw new RegionOperationException("Cannot change NullRegion");
}
@Override
- public void contract(Vector... changes) throws RegionOperationException {
+ public void contract(BlockVector3... changes) throws RegionOperationException {
throw new RegionOperationException("Cannot change NullRegion");
}
@Override
- public void shift(Vector change) throws RegionOperationException {
+ public void shift(BlockVector3 change) throws RegionOperationException {
throw new RegionOperationException("Cannot change NullRegion");
}
@Override
- public boolean contains(Vector position) {
+ public boolean contains(BlockVector3 position) {
return false;
}
@Override
- public Set getChunks() {
+ public Set getChunks() {
return Collections.emptySet();
}
@Override
- public Set getChunkCubes() {
+ public Set getChunkCubes() {
return Collections.emptySet();
}
@@ -119,27 +118,22 @@ public class NullRegion implements Region {
}
@Override
- public List polygonize(int maxPoints) {
+ public List polygonize(int maxPoints) {
return Collections.emptyList();
}
@Override
- public Iterator iterator() {
- return new Iterator() {
+ public Iterator iterator() {
+ return new Iterator() {
@Override
public boolean hasNext() {
return false;
}
@Override
- public BlockVector next() {
+ public BlockVector3 next() {
throw new NoSuchElementException();
}
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException("Cannot remove");
- }
};
}
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java
index b7d607d9d..41cdeebff 100644
--- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java
+++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java
@@ -19,10 +19,9 @@
package com.sk89q.worldedit.regions;
-import com.sk89q.worldedit.BlockVector;
-import com.sk89q.worldedit.BlockVector2D;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.Vector2D;
+import com.sk89q.worldedit.math.BlockVector2;
+import com.sk89q.worldedit.math.BlockVector3;
+import com.sk89q.worldedit.math.Vector2;
import com.sk89q.worldedit.regions.iterator.FlatRegion3DIterator;
import com.sk89q.worldedit.regions.iterator.FlatRegionIterator;
import com.sk89q.worldedit.world.World;
@@ -37,9 +36,9 @@ import java.util.List;
*/
public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
- private List points;
- private Vector2D min;
- private Vector2D max;
+ private List points;
+ private BlockVector2 min;
+ private BlockVector2 max;
private int minY;
private int maxY;
private boolean hasY = false;
@@ -57,7 +56,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
* @param world the world
*/
public Polygonal2DRegion(World world) {
- this(world, Collections.emptyList(), 0, 0);
+ this(world, Collections.emptyList(), 0, 0);
hasY = false;
}
@@ -69,7 +68,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
* @param minY minimum Y
* @param maxY maximum Y
*/
- public Polygonal2DRegion(World world, List points, int minY, int maxY) {
+ public Polygonal2DRegion(World world, List points, int minY, int maxY) {
super(world);
this.points = new ArrayList<>(points);
this.minY = minY;
@@ -93,7 +92,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
*
* @return a list of points
*/
- public List getPoints() {
+ public List getPoints() {
return Collections.unmodifiableList(points);
}
@@ -103,9 +102,9 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
*/
protected void recalculate() {
if (points.isEmpty()) {
- min = new Vector2D(0, 0);
+ min = BlockVector2.ZERO;
minY = 0;
- max = new Vector2D(0, 0);
+ max = BlockVector2.ZERO;
maxY = 0;
return;
}
@@ -115,7 +114,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
int maxX = points.get(0).getBlockX();
int maxZ = points.get(0).getBlockZ();
- for (BlockVector2D v : points) {
+ for (BlockVector2 v : points) {
int x = v.getBlockX();
int z = v.getBlockZ();
if (x < minX) minX = x;
@@ -132,8 +131,8 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
minY = Math.min(Math.max(0, minY), world == null ? 255 : world.getMaxY());
maxY = Math.min(Math.max(0, maxY), world == null ? 255 : world.getMaxY());
- min = new Vector2D(minX, minZ);
- max = new Vector2D(maxX, maxZ);
+ min = new BlockVector2(minX, minZ);
+ max = new BlockVector2(maxX, maxZ);
}
/**
@@ -141,17 +140,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
*
* @param position the position
*/
- public void addPoint(Vector2D position) {
- points.add(position.toBlockVector2D());
- recalculate();
- }
-
- /**
- * Add a point to the list.
- *
- * @param position the position
- */
- public void addPoint(BlockVector2D position) {
+ public void addPoint(BlockVector2 position) {
points.add(position);
recalculate();
}
@@ -161,8 +150,8 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
*
* @param position the position
*/
- public void addPoint(Vector position) {
- points.add(new BlockVector2D(position.getBlockX(), position.getBlockZ()));
+ public void addPoint(BlockVector3 position) {
+ points.add(new BlockVector2(position.getBlockX(), position.getBlockZ()));
recalculate();
}
@@ -199,13 +188,13 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public Vector getMinimumPoint() {
- return min.toVector(minY);
+ public BlockVector3 getMinimumPoint() {
+ return min.toBlockVector3(minY);
}
@Override
- public Vector getMaximumPoint() {
- return max.toVector(maxY);
+ public BlockVector3 getMaximumPoint() {
+ return max.toBlockVector3(maxY);
}
@Override
@@ -239,14 +228,11 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public void expand(Vector... changes) throws RegionOperationException {
- for (Vector change : changes) {
+ public void expand(BlockVector3... changes) throws RegionOperationException {
+ for (BlockVector3 change : changes) {
if (change.getBlockX() != 0 || change.getBlockZ() != 0) {
throw new RegionOperationException("Polygons can only be expanded vertically.");
}
- }
-
- for (Vector change : changes) {
int changeY = change.getBlockY();
if (changeY > 0) {
maxY += changeY;
@@ -258,14 +244,11 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public void contract(Vector... changes) throws RegionOperationException {
- for (Vector change : changes) {
+ public void contract(BlockVector3... changes) throws RegionOperationException {
+ for (BlockVector3 change : changes) {
if (change.getBlockX() != 0 || change.getBlockZ() != 0) {
throw new RegionOperationException("Polygons can only be contracted vertically.");
}
- }
-
- for (Vector change : changes) {
int changeY = change.getBlockY();
if (changeY > 0) {
minY += changeY;
@@ -277,14 +260,14 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public void shift(Vector change) throws RegionOperationException {
+ public void shift(BlockVector3 change) throws RegionOperationException {
final double changeX = change.getX();
final double changeY = change.getY();
final double changeZ = change.getZ();
for (int i = 0; i < points.size(); ++i) {
- BlockVector2D point = points.get(i);
- points.set(i, new BlockVector2D(point.getX() + changeX, point.getZ() + changeZ));
+ BlockVector2 point = points.get(i);
+ points.set(i, new BlockVector2(point.getX() + changeX, point.getZ() + changeZ));
}
minY += changeY;
@@ -294,7 +277,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public boolean contains(Vector position) {
+ public boolean contains(BlockVector3 position) {
return contains(points, minY, maxY, position);
}
@@ -307,7 +290,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
* @param pt the position to check
* @return true if the given polygon contains the given point
*/
- public static boolean contains(List points, int minY, int maxY, Vector pt) {
+ public static boolean contains(List points, int minY, int maxY, BlockVector3 pt) {
if (points.size() < 3) {
return false;
}
@@ -398,12 +381,12 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
}
@Override
- public Iterator iterator() {
+ public Iterator iterator() {
return new FlatRegion3DIterator(this);
}
@Override
- public Iterable asFlatRegion() {
+ public Iterable asFlatRegion() {
return () -> new FlatRegionIterator(Polygonal2DRegion.this);
}
@@ -416,10 +399,10 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
- List