Cleanup
This commit is contained in:
@@ -97,7 +97,7 @@ public class CuboidRegion implements Region {
|
||||
Vector min = getMinimumPoint();
|
||||
Vector max = getMaximumPoint();
|
||||
|
||||
return (int)(max.getX() - min.getX() + 1);
|
||||
return (int) (max.getX() - min.getX() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +109,7 @@ public class CuboidRegion implements Region {
|
||||
Vector min = getMinimumPoint();
|
||||
Vector max = getMaximumPoint();
|
||||
|
||||
return (int)(max.getY() - min.getY() + 1);
|
||||
return (int) (max.getY() - min.getY() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,7 +121,7 @@ public class CuboidRegion implements Region {
|
||||
Vector min = getMinimumPoint();
|
||||
Vector max = getMaximumPoint();
|
||||
|
||||
return (int)(max.getZ() - min.getZ() + 1);
|
||||
return (int) (max.getZ() - min.getZ() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,7 +44,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion
|
||||
return false;
|
||||
}
|
||||
pos1 = pos.toBlockVector();
|
||||
region.setPos1(pos1);
|
||||
region.setPos1(pos1);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion
|
||||
} else {
|
||||
player.print("First position set to " + pos1 + ".");
|
||||
}
|
||||
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getArea()));
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion
|
||||
} else {
|
||||
player.print("Second position set to " + pos2 + ".");
|
||||
}
|
||||
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getArea()));
|
||||
}
|
||||
|
||||
@@ -89,15 +89,15 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos2, getArea()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
|
||||
if (pos1 == null) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
|
||||
return pos1;
|
||||
}
|
||||
|
||||
|
||||
public boolean isDefined() {
|
||||
return pos1 != null && pos2 != null;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion
|
||||
if (pos1 == null || pos2 == null) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion
|
||||
pos1 = region.getPos1().toBlockVector();
|
||||
pos2 = region.getPos2().toBlockVector();
|
||||
}
|
||||
|
||||
|
||||
public void clear() {
|
||||
pos1 = null;
|
||||
pos2 = null;
|
||||
@@ -130,15 +130,15 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion
|
||||
|
||||
public List<String> getInformationLines() {
|
||||
List<String> lines = new ArrayList<String>();
|
||||
|
||||
|
||||
if (pos1 != null) {
|
||||
lines.add("Position 1: " + pos1);
|
||||
}
|
||||
|
||||
|
||||
if (pos2 != null) {
|
||||
lines.add("Position 2: " + pos2);
|
||||
}
|
||||
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion
|
||||
if (pos1 != null && pos2 != null) {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class Polygonal2DRegion implements Region {
|
||||
protected int minY;
|
||||
protected int maxY;
|
||||
protected boolean hasY = false;
|
||||
|
||||
|
||||
/**
|
||||
* Construct the region.
|
||||
*/
|
||||
@@ -54,7 +54,7 @@ public class Polygonal2DRegion implements Region {
|
||||
hasY = false;
|
||||
recalculate();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct the region.
|
||||
*
|
||||
@@ -69,7 +69,7 @@ public class Polygonal2DRegion implements Region {
|
||||
hasY = true;
|
||||
recalculate();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the list of points.
|
||||
*
|
||||
@@ -78,7 +78,7 @@ public class Polygonal2DRegion implements Region {
|
||||
public List<BlockVector2D> getPoints() {
|
||||
return Collections.unmodifiableList(points);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Recalculate the bounding box of this polygonal region. This should be
|
||||
* called after points have been changed.
|
||||
@@ -89,12 +89,12 @@ public class Polygonal2DRegion implements Region {
|
||||
max = new BlockVector(0, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int minX = points.get(0).getBlockX();
|
||||
int minZ = points.get(0).getBlockZ();
|
||||
int maxX = points.get(0).getBlockX();
|
||||
int maxZ = points.get(0).getBlockZ();
|
||||
|
||||
|
||||
for (BlockVector2D v : points) {
|
||||
int x = v.getBlockX();
|
||||
int z = v.getBlockZ();
|
||||
@@ -112,7 +112,7 @@ public class Polygonal2DRegion implements Region {
|
||||
min = new BlockVector(minX, minY, minZ);
|
||||
max = new BlockVector(maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a point to the list.
|
||||
*
|
||||
@@ -122,7 +122,7 @@ public class Polygonal2DRegion implements Region {
|
||||
points.add(pt.toBlockVector2D());
|
||||
recalculate();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a point to the list.
|
||||
*
|
||||
@@ -132,7 +132,7 @@ public class Polygonal2DRegion implements Region {
|
||||
points.add(pt);
|
||||
recalculate();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a point to the list.
|
||||
*
|
||||
@@ -142,7 +142,7 @@ public class Polygonal2DRegion implements Region {
|
||||
points.add(new BlockVector2D(pt.getBlockX(), pt.getBlockZ()));
|
||||
recalculate();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the minimum Y.
|
||||
*
|
||||
@@ -153,7 +153,7 @@ public class Polygonal2DRegion implements Region {
|
||||
minY = y;
|
||||
recalculate();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Se the maximum Y.
|
||||
*
|
||||
@@ -198,7 +198,7 @@ public class Polygonal2DRegion implements Region {
|
||||
j = i;
|
||||
}
|
||||
|
||||
return (int)Math.floor(Math.abs(area * 0.5)
|
||||
return (int) Math.floor(Math.abs(area * 0.5)
|
||||
* (maxY - minY + 1));
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ public class Polygonal2DRegion implements Region {
|
||||
if (change.getBlockX() != 0 || change.getBlockZ() != 0) {
|
||||
throw new RegionOperationException("Polygons can only be expanded vertically.");
|
||||
}
|
||||
|
||||
|
||||
int changeY = change.getBlockY();
|
||||
if (changeY > 0) {
|
||||
maxY += changeY;
|
||||
@@ -257,7 +257,7 @@ public class Polygonal2DRegion implements Region {
|
||||
if (change.getBlockX() != 0 || change.getBlockZ() != 0) {
|
||||
throw new RegionOperationException("Polygons can only be contracted vertically.");
|
||||
}
|
||||
|
||||
|
||||
int changeY = change.getBlockY();
|
||||
if (changeY > 0) {
|
||||
minY += changeY;
|
||||
@@ -291,11 +291,11 @@ public class Polygonal2DRegion implements Region {
|
||||
int targetX = pt.getBlockX(); //wide
|
||||
int targetY = pt.getBlockY(); //height
|
||||
int targetZ = pt.getBlockZ(); //depth
|
||||
|
||||
|
||||
if (targetY < minY || targetY > maxY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
boolean inside = false;
|
||||
int npoints = points.size();
|
||||
int xNew, zNew;
|
||||
@@ -328,7 +328,7 @@ public class Polygonal2DRegion implements Region {
|
||||
}
|
||||
if (x1 <= targetX && targetX <= x2) {
|
||||
crossproduct = ((long) targetZ - (long) z1) * (long) (x2 - x1)
|
||||
- ((long) z2 - (long) z1) * (long) (targetX - x1);
|
||||
- ((long) z2 - (long) z1) * (long) (targetX - x1);
|
||||
if (crossproduct == 0) {
|
||||
if ((z1 <= targetZ) == (targetZ <= z2)) return true; //on edge
|
||||
} else if (crossproduct < 0 && (x1 != targetX)) {
|
||||
@@ -341,7 +341,7 @@ public class Polygonal2DRegion implements Region {
|
||||
|
||||
return inside;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of chunks.
|
||||
*
|
||||
@@ -366,7 +366,7 @@ public class Polygonal2DRegion implements Region {
|
||||
|
||||
return chunks;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the number of points.
|
||||
*
|
||||
@@ -375,7 +375,7 @@ public class Polygonal2DRegion implements Region {
|
||||
public int size() {
|
||||
return points.size();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expand the height of the polygon to fit the specified Y.
|
||||
*
|
||||
@@ -395,7 +395,7 @@ public class Polygonal2DRegion implements Region {
|
||||
maxY = y;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -406,7 +406,7 @@ public class Polygonal2DRegion implements Region {
|
||||
*/
|
||||
public Iterator<BlockVector> iterator() {
|
||||
return new Polygonal2DRegionIterator(this);
|
||||
|
||||
|
||||
/*
|
||||
Incomplete iterator. Where's my yield?!
|
||||
|
||||
@@ -501,7 +501,7 @@ public class Polygonal2DRegion implements Region {
|
||||
protected int curZ;
|
||||
protected int curY;
|
||||
protected BlockVector next;
|
||||
|
||||
|
||||
public Polygonal2DRegionIterator(Polygonal2DRegion region) {
|
||||
points = new ArrayList<BlockVector2D>(region.points);
|
||||
Vector min = region.getMinimumPoint();
|
||||
@@ -520,13 +520,13 @@ public class Polygonal2DRegion implements Region {
|
||||
next = null;
|
||||
findNext();
|
||||
}
|
||||
|
||||
|
||||
private void findNext() {
|
||||
if (i >= n) {
|
||||
next = null;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (next != null && curY <= maxY) {
|
||||
++curY;
|
||||
next = new BlockVector(curX, curY, curZ);
|
||||
@@ -536,8 +536,8 @@ public class Polygonal2DRegion implements Region {
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
while (i < n) {
|
||||
curZ = i / (maxX - minX + 1) + minZ;
|
||||
curX = (i % (maxX - minX + 1)) + minX;
|
||||
@@ -548,7 +548,7 @@ public class Polygonal2DRegion implements Region {
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
|
||||
next = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import com.sk89q.worldedit.cui.SelectionShapeEvent;
|
||||
public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedRegion {
|
||||
protected BlockVector pos1;
|
||||
protected Polygonal2DRegion region = new Polygonal2DRegion();
|
||||
|
||||
|
||||
public boolean selectPrimary(Vector pos) {
|
||||
if (pos1 != null && pos1.equals(pos)) {
|
||||
return false;
|
||||
@@ -51,7 +51,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedR
|
||||
region.expandY(pos.getBlockY());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean selectSecondary(Vector pos) {
|
||||
if (region.size() > 0) {
|
||||
List<BlockVector2D> points = region.getPoints();
|
||||
@@ -60,12 +60,12 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedR
|
||||
&& lastPoint.getBlockZ() == pos.getBlockZ()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (points.size() >= 20) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
region.addPoint(pos);
|
||||
region.expandY(pos.getBlockY());
|
||||
return true;
|
||||
@@ -101,7 +101,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedR
|
||||
if (!isDefined()) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedR
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
|
||||
public int getPointCount() {
|
||||
return region.getPoints().size();
|
||||
}
|
||||
|
||||
@@ -35,36 +35,42 @@ public interface Region extends Iterable<BlockVector> {
|
||||
* @return min. point
|
||||
*/
|
||||
public Vector getMinimumPoint();
|
||||
|
||||
/**
|
||||
* Get the upper point of a region.
|
||||
*
|
||||
* @return max. point
|
||||
*/
|
||||
public Vector getMaximumPoint();
|
||||
|
||||
/**
|
||||
* Get the number of blocks in the region.
|
||||
*
|
||||
* @return number of blocks
|
||||
*/
|
||||
public int getArea();
|
||||
|
||||
/**
|
||||
* Get X-size.
|
||||
*
|
||||
* @return width
|
||||
*/
|
||||
public int getWidth();
|
||||
|
||||
/**
|
||||
* Get Y-size.
|
||||
*
|
||||
* @return height
|
||||
*/
|
||||
public int getHeight();
|
||||
|
||||
/**
|
||||
* Get Z-size.
|
||||
*
|
||||
* @return length
|
||||
*/
|
||||
public int getLength();
|
||||
|
||||
/**
|
||||
* Expand the region.
|
||||
*
|
||||
@@ -72,6 +78,7 @@ public interface Region extends Iterable<BlockVector> {
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
public void expand(Vector change) throws RegionOperationException;
|
||||
|
||||
/**
|
||||
* Contract the region.
|
||||
*
|
||||
@@ -79,6 +86,7 @@ public interface Region extends Iterable<BlockVector> {
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
public void contract(Vector change) throws RegionOperationException;
|
||||
|
||||
/**
|
||||
* Returns true based on whether the region contains the point,
|
||||
*
|
||||
@@ -86,6 +94,7 @@ public interface Region extends Iterable<BlockVector> {
|
||||
* @return
|
||||
*/
|
||||
public boolean contains(Vector pt);
|
||||
|
||||
/**
|
||||
* Get a list of chunks.
|
||||
*
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
public class RegionOperationException extends WorldEditException {
|
||||
private static final long serialVersionUID = -6180325009115242142L;
|
||||
|
||||
|
||||
public RegionOperationException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public interface RegionSelector {
|
||||
* @return true if something changed
|
||||
*/
|
||||
public boolean selectPrimary(Vector pos);
|
||||
|
||||
|
||||
/**
|
||||
* Called when the second point is selected.
|
||||
*
|
||||
@@ -55,7 +55,7 @@ public interface RegionSelector {
|
||||
* @param session
|
||||
* @param pos
|
||||
*/
|
||||
public void explainPrimarySelection(LocalPlayer player,
|
||||
public void explainPrimarySelection(LocalPlayer player,
|
||||
LocalSession session, Vector pos);
|
||||
|
||||
/**
|
||||
@@ -67,7 +67,7 @@ public interface RegionSelector {
|
||||
*/
|
||||
public void explainSecondarySelection(LocalPlayer player,
|
||||
LocalSession session, Vector pos);
|
||||
|
||||
|
||||
/**
|
||||
* The the player information about the region's changes. This may resend
|
||||
* all the defining region information if needed.
|
||||
@@ -76,7 +76,7 @@ public interface RegionSelector {
|
||||
* @param session
|
||||
*/
|
||||
public void explainRegionAdjust(LocalPlayer player, LocalSession session);
|
||||
|
||||
|
||||
/**
|
||||
* Get the primary position.
|
||||
*
|
||||
@@ -84,7 +84,7 @@ public interface RegionSelector {
|
||||
* @throws IncompleteRegionException
|
||||
*/
|
||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException;
|
||||
|
||||
|
||||
/**
|
||||
* Get the selection.
|
||||
*
|
||||
@@ -92,52 +92,52 @@ public interface RegionSelector {
|
||||
* @throws IncompleteRegionException
|
||||
*/
|
||||
public Region getRegion() throws IncompleteRegionException;
|
||||
|
||||
|
||||
/**
|
||||
* Get the region even if it's not fully defined.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Region getIncompleteRegion();
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether the region has been fully defined.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isDefined();
|
||||
|
||||
|
||||
/**
|
||||
* Get the number of blocks inside the region.
|
||||
*
|
||||
* @return number of blocks or -1 if undefined
|
||||
*/
|
||||
public int getArea();
|
||||
|
||||
|
||||
/**
|
||||
* Update the selector with changes to the region.
|
||||
*/
|
||||
public void learnChanges();
|
||||
|
||||
|
||||
/**
|
||||
* Clear the selection.
|
||||
*/
|
||||
public void clear();
|
||||
|
||||
|
||||
/**
|
||||
* Get a lowercase name of this region selector type.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTypeName();
|
||||
|
||||
|
||||
/**
|
||||
* Get a lowecase space-less ID.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTypeId();
|
||||
|
||||
|
||||
/**
|
||||
* Get lines of information about the selection.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user