public static class SquidIterators.CenteredSquare extends java.lang.Object implements SquidIterator
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.
Modifier and Type | Field and Description |
---|---|
protected boolean |
done |
protected int |
height |
protected Coord |
previous |
protected int |
size |
protected int |
width |
protected int |
xstart |
protected int |
ystart |
Constructor and Description |
---|
CenteredSquare(int width,
int height,
Coord start,
int size)
An iterator to iterate in the square of size
size around
start . |
CenteredSquare(int width,
int height,
int x,
int y,
int size)
An iterator to iterate in the square of size
size around
(x, y) . |
Modifier and Type | Method and Description |
---|---|
protected Coord |
findNext(boolean mute) |
protected Coord |
findNext0() |
boolean |
hasNext() |
protected boolean |
isInGrid(int x,
int y) |
Coord |
next() |
void |
remove() |
protected final int width
protected final int height
protected Coord previous
protected final int xstart
protected final int ystart
protected final int size
protected boolean done
public CenteredSquare(int width, int height, int x, int y, int size)
size
around
(x, y)
.width
- The map's widthheight
- The map's heightx
- The starting x coordinate.y
- The starting y coordinate.size
- The square's size. Can be 0
but not negative.java.lang.IllegalStateException
- If width <= 0 || height <= 0 || size < 0
.public CenteredSquare(int width, int height, Coord start, int size)
size
around
start
.width
- The grid's widthheight
- The grid's heightstart
- The starting coordinate.public boolean hasNext()
hasNext
in interface java.util.Iterator<Coord>
public void remove()
remove
in interface java.util.Iterator<Coord>
protected Coord findNext(boolean mute)
protected Coord findNext0()
protected boolean isInGrid(int x, int y)
Copyright © Eben Howard 2012–2022. All rights reserved.