Added Region.shift

- Provided a default implementation using expand+contract in AbstractRegion
- Overrid the implementation in the subtypes
This commit is contained in:
TomyLobo 2012-01-03 16:13:50 +01:00
parent 4d708a5003
commit 3a828c9759
6 changed files with 51 additions and 5 deletions

View File

@ -407,10 +407,9 @@ public class SelectionCommands {
try {
Region region = session.getSelection(player.getWorld());
region.expand(dir.multiply(change));
region.contract(dir.multiply(change));
region.shift(dir.multiply(change));
session.getRegionSelector(player.getWorld()).learnChanges();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
player.print("Region shifted.");

View File

@ -4,6 +4,7 @@ import java.util.Iterator;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
public abstract class AbstractRegion implements Region {
/**
@ -31,4 +32,9 @@ public abstract class AbstractRegion implements Region {
public void setWorld(LocalWorld world) {
this.world = world;
}
public void shift(Vector change) throws RegionOperationException {
expand(change);
contract(change);
}
}

View File

@ -184,8 +184,7 @@ public class CuboidRegion extends AbstractRegion {
}
}
pos1 = pos1.clampY(0, world == null ? 127 : world.getMaxY());
pos2 = pos2.clampY(0, world == null ? 127 : world.getMaxY());
recalculate();
}
/**
@ -236,10 +235,22 @@ public class CuboidRegion extends AbstractRegion {
}
}
recalculate();
}
private void recalculate() {
pos1 = pos1.clampY(0, world == null ? 127 : world.getMaxY());
pos2 = pos2.clampY(0, world == null ? 127 : world.getMaxY());
}
@Override
public void shift(Vector change) throws RegionOperationException {
pos1 = pos1.add(change);
pos2 = pos2.add(change);
recalculate();
}
/**
* Get position 1.
*

View File

@ -136,6 +136,11 @@ public class EllipsoidRegion extends AbstractRegion {
public void contract(Vector change) {
}
@Override
public void shift(Vector change) throws RegionOperationException {
center = center.add(change);
}
/**
* Get the center.
*

View File

@ -302,6 +302,23 @@ public class Polygonal2DRegion extends AbstractRegion {
recalculate();
}
@Override
public void shift(Vector 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));
}
minY += changeY;
maxY += changeY;
recalculate();
}
/**
* Checks to see if a point is inside this region.
*/

View File

@ -88,6 +88,14 @@ public interface Region extends Iterable<BlockVector> {
*/
public void contract(Vector change) throws RegionOperationException;
/**
* Shift the region.
*
* @param change
* @throws RegionOperationException
*/
public void shift(Vector multiply) throws RegionOperationException;
/**
* Returns true based on whether the region contains the point,
*