Make regions Cloneable

This commit is contained in:
aumgn 2012-03-20 15:14:41 +01:00 committed by zml2008
parent 56a8574129
commit 842c469285
6 changed files with 29 additions and 1 deletions

View File

@ -66,4 +66,12 @@ public abstract class AbstractRegion implements Region {
expand(change);
contract(change);
}
public AbstractRegion clone() {
try {
return (AbstractRegion) super.clone();
} catch (CloneNotSupportedException exc) {
return null;
}
}
}

View File

@ -434,4 +434,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
public String toString() {
return getMinimumPoint() + " - " + getMaximumPoint();
}
public CuboidRegion clone() {
return (CuboidRegion) super.clone();
}
}

View File

@ -388,4 +388,8 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
public String toString() {
return center + " - " + radius;
}
public CylinderRegion clone() {
return (CylinderRegion) super.clone();
}
}

View File

@ -275,4 +275,8 @@ public class EllipsoidRegion extends AbstractRegion {
public void extendRadius(Vector minRadius) {
setRadius(Vector.getMaximum(minRadius, getRadius()));
}
public EllipsoidRegion clone() {
return (EllipsoidRegion) super.clone();
}
}

View File

@ -519,4 +519,10 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
sb.append(" * (" + minY + " - " + maxY + ")");
return sb.toString();
}
public Polygonal2DRegion clone() {
Polygonal2DRegion clone = (Polygonal2DRegion) super.clone();
clone.points = new ArrayList<BlockVector2D>(points);
return clone;
}
}

View File

@ -29,7 +29,7 @@ import java.util.Set;
*
* @author sk89q
*/
public interface Region extends Iterable<BlockVector> {
public interface Region extends Iterable<BlockVector>, Cloneable {
/**
* Get the lower point of a region.
*
@ -151,4 +151,6 @@ public interface Region extends Iterable<BlockVector> {
* @return
*/
public void setWorld(LocalWorld world);
public Region clone();
}