3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-10 05:20:04 +01:00

Removed Polygonal2DRegionIterator.

Dieser Commit ist enthalten in:
TomyLobo 2012-01-23 01:57:46 +01:00
Ursprung eee02565ca
Commit 06e9a3b175

Datei anzeigen

@ -458,64 +458,7 @@ public class Polygonal2DRegion extends AbstractRegion {
*/ */
@Override @Override
public Iterator<BlockVector> iterator() { public Iterator<BlockVector> iterator() {
return new Polygonal2DRegionIterator(this); return new RegionIterator(this);
/*
Incomplete iterator. Where's my yield?!
ArrayList<BlockVector> items = new ArrayList<BlockVector>();
int nodes, pixelZ, i, j, swap;
int n = points.size();
int[] nodeX = new int[n];
int minZ = getMinimumPoint().getBlockZ();
int maxZ = getMaximumPoint().getBlockZ();
for (pixelZ = minZ; pixelZ < maxZ; ++pixelZ) {
// Build a list of nodes
nodes = 0;
j = n - 1;
for (i = 0; i < n; ++i) {
if (points.get(i).getBlockZ() < (double) pixelZ
&& points.get(j).getBlockZ() >= (double) pixelZ
|| points.get(j).getBlockZ() < (double) pixelZ
&& points.get(i).getBlockZ() >= (double) pixelZ) {
nodeX[nodes++] = (int) (points.get(i).getBlockX()
+ (pixelZ - points.get(i).getBlockZ())
/ (points.get(j).getBlockZ() - points.get(i)
.getBlockZ())
* (points.get(j).getBlockX() - points.get(i)
.getBlockX()));
}
j = i;
}
// Sort the nodes, via a simple bubble sort
i = 0;
while (i < nodes - 1) {
if (nodeX[i] > nodeX[i + 1]) {
swap = nodeX[i];
nodeX[i] = nodeX[i + 1];
nodeX[i + 1] = swap;
if (i > 0)
--i;
} else {
++i;
}
}
// Fill the pixels between node pairs
for (i = 0; i < nodes; i += 2) {
for (j = nodeX[i]; j < nodeX[i + 1]; ++j) {
for (int y = minY; y >= maxY; ++y) {
items.add(new BlockVector(j, y, pixelZ));
}
}
}
}
return items.iterator();*/
} }
/** /**
@ -537,87 +480,4 @@ public class Polygonal2DRegion extends AbstractRegion {
sb.append(" * (" + minY + " - " + maxY + ")"); sb.append(" * (" + minY + " - " + maxY + ")");
return sb.toString(); return sb.toString();
} }
/**
* A terrible polygonal region iterator.
*/
public class Polygonal2DRegionIterator implements Iterator<BlockVector> {
protected List<BlockVector2D> points = new ArrayList<BlockVector2D>();
protected int minX;
protected int minY;
protected int minZ;
protected int maxX;
protected int maxY;
protected int maxZ;
protected int n;
protected int i;
protected int curX;
protected int curZ;
protected int curY;
protected BlockVector next;
public Polygonal2DRegionIterator(Polygonal2DRegion region) {
points = new ArrayList<BlockVector2D>(region.points);
Vector min = region.getMinimumPoint();
Vector max = region.getMaximumPoint();
minX = min.getBlockX();
minY = min.getBlockY();
minZ = min.getBlockZ();
maxX = max.getBlockX();
maxY = max.getBlockY();
maxZ = max.getBlockZ();
n = (maxX - minX + 1) * (maxZ - minZ + 1);
i = 0;
curX = 0;
curZ = 0;
curY = minY;
next = null;
findNext();
}
private void findNext() {
if (i >= n) {
next = null;
return;
}
if (next != null && curY <= maxY) {
++curY;
next = new BlockVector(curX, curY, curZ);
if (curY > maxY) {
++i;
curY = minY;
} else {
return;
}
}
while (i < n) {
curZ = i / (maxX - minX + 1) + minZ;
curX = (i % (maxX - minX + 1)) + minX;
BlockVector pt = new BlockVector(curX, minY, curZ);
if (contains(points, minY, maxY, pt)) {
next = pt;
return;
}
++i;
}
next = null;
}
public boolean hasNext() {
return next != null;
}
public BlockVector next() {
BlockVector next = this.next;
findNext();
return next;
}
public void remove() {
throw new UnsupportedOperationException("Not supported");
}
}
} }