3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-24 18:10:08 +01:00

Slightly improve FlatRegion iteration

Dieser Commit ist enthalten in:
aumgn 2012-04-16 08:47:43 +02:00
Ursprung a7b49ff793
Commit d43e233a42
3 geänderte Dateien mit 69 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -368,6 +368,11 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
return false;
}
@Override
public Iterator<BlockVector> iterator() {
return new FlatRegion3DIterator(this);
}
@Override
public Iterable<Vector2D> asFlatRegion() {
return new Iterable<Vector2D>() {

Datei anzeigen

@ -0,0 +1,63 @@
package com.sk89q.worldedit.regions;
import java.util.Iterator;
import java.util.NoSuchElementException;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector2D;
public class FlatRegion3DIterator implements Iterator<BlockVector> {
private Iterator<Vector2D> flatIterator;
private int minY;
private int maxY;
private Vector2D next2D;
private int nextY;
public FlatRegion3DIterator(FlatRegion region, Iterator<Vector2D> flatIterator) {
this.flatIterator = flatIterator;
this.minY = region.getMinimumY();
this.maxY = region.getMaximumY();
if (flatIterator.hasNext()) {
this.next2D = flatIterator.next();
} else {
this.next2D = null;
}
this.nextY = minY;
}
public FlatRegion3DIterator(FlatRegion region) {
this(region, region.asFlatRegion().iterator());
}
@Override
public boolean hasNext() {
return next2D != null;
}
@Override
public BlockVector next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
BlockVector current = new BlockVector(next2D.getBlockX(), nextY, next2D.getBlockZ());
if (nextY < maxY) {
nextY++;
} else if (flatIterator.hasNext()) {
next2D = flatIterator.next();
nextY = minY;
} else {
next2D = null;
}
return current;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}

Datei anzeigen

@ -492,7 +492,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
*/
@Override
public Iterator<BlockVector> iterator() {
return new RegionIterator(this);
return new FlatRegion3DIterator(this);
}
@Override