mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Slightly improve FlatRegion iteration
This commit is contained in:
parent
a7b49ff793
commit
d43e233a42
@ -368,6 +368,11 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<BlockVector> iterator() {
|
||||||
|
return new FlatRegion3DIterator(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<Vector2D> asFlatRegion() {
|
public Iterable<Vector2D> asFlatRegion() {
|
||||||
return new Iterable<Vector2D>() {
|
return new Iterable<Vector2D>() {
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -492,7 +492,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Iterator<BlockVector> iterator() {
|
public Iterator<BlockVector> iterator() {
|
||||||
return new RegionIterator(this);
|
return new FlatRegion3DIterator(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user