Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-10 05:20:04 +01:00
Slightly improve FlatRegion iteration
Dieser Commit ist enthalten in:
Ursprung
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>() {
|
||||||
|
63
src/main/java/com/sk89q/worldedit/regions/FlatRegion3DIterator.java
Normale Datei
63
src/main/java/com/sk89q/worldedit/regions/FlatRegion3DIterator.java
Normale Datei
@ -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
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren