This commit is contained in:
TomyLobo
2011-11-23 02:29:48 +01:00
parent 1a57f6e95d
commit 7e13b60a51
161 changed files with 1433 additions and 1412 deletions

View File

@ -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;
}