From 06e9a3b17564eabc5e6dfc0b0853d615bf0ed9ee Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Mon, 23 Jan 2012 01:57:46 +0100 Subject: [PATCH] Removed Polygonal2DRegionIterator. --- .../worldedit/regions/Polygonal2DRegion.java | 142 +----------------- 1 file changed, 1 insertion(+), 141 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java b/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java index 7fc96fc06..f4164bb01 100644 --- a/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java +++ b/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java @@ -458,64 +458,7 @@ public class Polygonal2DRegion extends AbstractRegion { */ @Override public Iterator iterator() { - return new Polygonal2DRegionIterator(this); - - /* - Incomplete iterator. Where's my yield?! - - ArrayList items = new ArrayList(); - - 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();*/ + return new RegionIterator(this); } /** @@ -537,87 +480,4 @@ public class Polygonal2DRegion extends AbstractRegion { sb.append(" * (" + minY + " - " + maxY + ")"); return sb.toString(); } - - /** - * A terrible polygonal region iterator. - */ - public class Polygonal2DRegionIterator implements Iterator { - protected List points = new ArrayList(); - 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(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"); - } - } }