Class GridIterator.CenteredSquare
java.lang.Object
com.github.yellowstonegames.grid.GridIterator
com.github.yellowstonegames.grid.GridIterator.CenteredSquare
- Enclosing class:
GridIterator
An iterator that returns cells in a square around a location. Cells are
iterated from bottom left to top right in this square. A square size of
0 creates an iterator that returns one location (the starting
one); a square of size 1 is an iterator that returns at most 9
locations, (start.x-1,start.y+1), (start.x,start.y+1), ...; a square of
size 2 returns at most ((2*2)+1)*((2*2)+1) = 25 locations, etc.
Instances of this iterator never return a coordinate outside the map.
-
Nested Class Summary
Nested classes/interfaces inherited from class GridIterator
GridIterator.CenteredSquare, GridIterator.SquareSpiral, GridIterator.VerticalUp -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected Coordprotected intprotected intprotected intFields inherited from class GridIterator
height, width -
Constructor Summary
ConstructorsConstructorDescriptionCenteredSquare(int width, int height, int x, int y, int size) An iterator to iterate in the square of sizesizearound(x, y).CenteredSquare(int width, int height, Coord start, int size) An iterator to iterate in the square of sizesizearoundstart. -
Method Summary
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterator
forEachRemaining
-
Field Details
-
previous
-
xStart
protected int xStart -
yStart
protected int yStart -
size
protected int size -
done
protected boolean done
-
-
Constructor Details
-
CenteredSquare
public CenteredSquare(int width, int height, int x, int y, int size) An iterator to iterate in the square of sizesizearound(x, y).- Parameters:
width- The map's widthheight- The map's heightx- The starting x coordinate.y- The starting y coordinate.size- The square's size. Can be0but not negative.- Throws:
IllegalStateException- Ifwidth <= 0 || height <= 0 || size < 0.
-
CenteredSquare
An iterator to iterate in the square of sizesizearoundstart.- Parameters:
width- The grid's widthheight- The grid's heightstart- The starting coordinate.
-
-
Method Details
-
hasNext
public boolean hasNext() -
next
-
remove
public void remove() -
findNext
-
findNextCandidate
-
isInGrid
protected boolean isInGrid(int x, int y)
-