3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-25 18:40:05 +01:00

Extracted an AbstractRegion class with some common functionality of all the region types.

Dieser Commit ist enthalten in:
TomyLobo 2012-01-03 15:57:29 +01:00
Ursprung 2cc0087524
Commit 4d708a5003
4 geänderte Dateien mit 42 neuen und 52 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,34 @@
package com.sk89q.worldedit.regions;
import java.util.Iterator;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.LocalWorld;
public abstract class AbstractRegion implements Region {
/**
* Stores the world.
*/
protected LocalWorld world;
public AbstractRegion(LocalWorld world) {
this.world = world;
}
/**
* Get the iterator.
*
* @return iterator of points inside the region
*/
public Iterator<BlockVector> iterator() {
return new RegionIterator(this);
}
public LocalWorld getWorld() {
return world;
}
public void setWorld(LocalWorld world) {
this.world = world;
}
}

Datei anzeigen

@ -32,7 +32,7 @@ import java.util.HashSet;
* *
* @author sk89q * @author sk89q
*/ */
public class CuboidRegion implements Region { public class CuboidRegion extends AbstractRegion {
/** /**
* Store the first point. * Store the first point.
*/ */
@ -41,11 +41,6 @@ public class CuboidRegion implements Region {
* Store the second point. * Store the second point.
*/ */
private Vector pos2; private Vector pos2;
/**
* Stores the world.
*/
private LocalWorld world;
/** /**
* Construct a new instance of this cuboid region. * Construct a new instance of this cuboid region.
* *
@ -64,8 +59,8 @@ public class CuboidRegion implements Region {
* @param pos2 * @param pos2
*/ */
public CuboidRegion(LocalWorld world, Vector pos1, Vector pos2) { public CuboidRegion(LocalWorld world, Vector pos1, Vector pos2) {
super(world);
this.pos1 = pos1; this.pos1 = pos1;
this.world = world;
this.pos2 = pos2; this.pos2 = pos2;
} }
@ -327,6 +322,7 @@ public class CuboidRegion implements Region {
* *
* @return iterator of points inside the region * @return iterator of points inside the region
*/ */
@Override
public Iterator<BlockVector> iterator() { public Iterator<BlockVector> iterator() {
return new Iterator<BlockVector>() { return new Iterator<BlockVector>() {
private Vector min = getMinimumPoint(); private Vector min = getMinimumPoint();
@ -370,12 +366,4 @@ public class CuboidRegion implements Region {
public String toString() { public String toString() {
return getMinimumPoint() + " - " + getMaximumPoint(); return getMinimumPoint() + " - " + getMaximumPoint();
} }
public LocalWorld getWorld() {
return world;
}
public void setWorld(LocalWorld world) {
this.world = world;
}
} }

Datei anzeigen

@ -19,12 +19,10 @@
package com.sk89q.worldedit.regions; package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.data.ChunkStore; import com.sk89q.worldedit.data.ChunkStore;
import java.util.Iterator;
import java.util.Set; import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
@ -32,7 +30,7 @@ import java.util.HashSet;
* *
* @author TomyLobo * @author TomyLobo
*/ */
public class EllipsoidRegion implements Region { public class EllipsoidRegion extends AbstractRegion {
/** /**
* Stores the center. * Stores the center.
*/ */
@ -41,11 +39,6 @@ public class EllipsoidRegion implements Region {
* Stores the radiuses plus 0.5 on each axis. * Stores the radiuses plus 0.5 on each axis.
*/ */
private Vector radius; private Vector radius;
/**
* Stores the world.
*/
private LocalWorld world;
/** /**
* Construct a new instance of this ellipsoid region. * Construct a new instance of this ellipsoid region.
* *
@ -64,7 +57,7 @@ public class EllipsoidRegion implements Region {
* @param radius * @param radius
*/ */
public EllipsoidRegion(LocalWorld world, Vector center, Vector radius) { public EllipsoidRegion(LocalWorld world, Vector center, Vector radius) {
this.world = world; super(world);
this.center = center; this.center = center;
this.radius = radius; this.radius = radius;
} }
@ -211,15 +204,6 @@ public class EllipsoidRegion implements Region {
return pt.subtract(center).divide(radius).lengthSq() <= 1; return pt.subtract(center).divide(radius).lengthSq() <= 1;
} }
/**
* Get the iterator.
*
* @return iterator of points inside the region
*/
public Iterator<BlockVector> iterator() {
return new RegionIterator(this);
}
/** /**
* Returns string representation in the format * Returns string representation in the format
* "(centerX, centerY, centerZ) - (radiusX, radiusY, radiusZ)". * "(centerX, centerY, centerZ) - (radiusX, radiusY, radiusZ)".
@ -231,14 +215,6 @@ public class EllipsoidRegion implements Region {
return center + " - " + getRadius(); return center + " - " + getRadius();
} }
public LocalWorld getWorld() {
return world;
}
public void setWorld(LocalWorld world) {
this.world = world;
}
public void extendRadius(Vector minRadius) { public void extendRadius(Vector minRadius) {
setRadius(Vector.getMaximum(minRadius, getRadius())); setRadius(Vector.getMaximum(minRadius, getRadius()));
} }

Datei anzeigen

@ -37,14 +37,13 @@ import com.sk89q.worldedit.data.ChunkStore;
* *
* @author sk89q * @author sk89q
*/ */
public class Polygonal2DRegion implements Region { public class Polygonal2DRegion extends AbstractRegion {
private List<BlockVector2D> points; private List<BlockVector2D> points;
private BlockVector min; private BlockVector min;
private BlockVector max; private BlockVector max;
private int minY; private int minY;
private int maxY; private int maxY;
private boolean hasY = false; private boolean hasY = false;
private LocalWorld world;
/** /**
* Construct the region * Construct the region
@ -72,11 +71,11 @@ public class Polygonal2DRegion implements Region {
* @param maxY * @param maxY
*/ */
public Polygonal2DRegion(LocalWorld world, List<BlockVector2D> points, int minY, int maxY) { public Polygonal2DRegion(LocalWorld world, List<BlockVector2D> points, int minY, int maxY) {
super(world);
this.points = new ArrayList<BlockVector2D>(points); this.points = new ArrayList<BlockVector2D>(points);
this.minY = minY; this.minY = minY;
this.maxY = maxY; this.maxY = maxY;
hasY = true; hasY = true;
this.world = world;
recalculate(); recalculate();
} }
@ -440,6 +439,7 @@ public class Polygonal2DRegion implements Region {
* *
* @return iterator of points inside the region * @return iterator of points inside the region
*/ */
@Override
public Iterator<BlockVector> iterator() { public Iterator<BlockVector> iterator() {
return new Polygonal2DRegionIterator(this); return new Polygonal2DRegionIterator(this);
@ -603,12 +603,4 @@ public class Polygonal2DRegion implements Region {
throw new UnsupportedOperationException("Not supported"); throw new UnsupportedOperationException("Not supported");
} }
} }
public LocalWorld getWorld() {
return world;
}
public void setWorld(LocalWorld world) {
this.world = world;
}
} }