Class GridIterator.SquareSpiral

java.lang.Object
com.github.yellowstonegames.grid.GridIterator
com.github.yellowstonegames.grid.GridIterator.SquareSpiral
All Implemented Interfaces:
Iterator<Coord>
Enclosing class:
GridIterator

public static class GridIterator.SquareSpiral extends GridIterator
Iterates in a square spiral going outward from a starting position. Iteration stops once a position would be out of bounds.
  • Field Details

    • previous

      protected Coord previous
    • xStart

      protected int xStart
    • yStart

      protected int yStart
    • index

      protected int index
    • done

      protected boolean done
  • Constructor Details

    • SquareSpiral

      public SquareSpiral(int width, int height, int x, int y)
      An iterator to iterate in the square of size size around (x, y).
      Parameters:
      width - The map's width
      height - The map's height
      x - The starting x coordinate.
      y - The starting y coordinate.
      Throws:
      IllegalStateException - If width <= 0 || height <= 0 || size < 0.
    • SquareSpiral

      public SquareSpiral(int width, int height, Coord start)
      An iterator to iterate in the square of size size around start.
      Parameters:
      width - The grid's width
      height - The grid's height
      start - The starting coordinate.
  • Method Details

    • hasNext

      public boolean hasNext()
    • next

      public Coord next()
    • remove

      public void remove()
    • findNext

      protected Coord findNext(boolean mutate)
    • findNextCandidate

      protected Coord findNextCandidate()
    • isInGrid

      protected boolean isInGrid(int x, int y)