Package squidpony.squidgrid.iterator
Class SquidIterators.CenteredSquare
java.lang.Object
squidpony.squidgrid.iterator.SquidIterators.CenteredSquare
- All Implemented Interfaces:
Iterator<Coord>
,SquidIterator
- Enclosing class:
- SquidIterators
public static class SquidIterators.CenteredSquare extends Object implements SquidIterator
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.
- Author:
- smelC
-
Field Summary
-
Constructor Summary
Constructors Constructor Description CenteredSquare(int width, int height, int x, int y, int size)
An iterator to iterate in the square of sizesize
around(x, y)
.CenteredSquare(int width, int height, Coord start, int size)
An iterator to iterate in the square of sizesize
aroundstart
. -
Method Summary
-
Field Details
-
Constructor Details
-
CenteredSquare
An iterator to iterate in the square of sizesize
around(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 be0
but not negative.- Throws:
IllegalStateException
- Ifwidth <= 0 || height <= 0 || size < 0
.
-
CenteredSquare
An iterator to iterate in the square of sizesize
aroundstart
.- Parameters:
width
- The grid's widthheight
- The grid's heightstart
- The starting coordinate.
-
-
Method Details