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
    • clockwise

      protected boolean clockwise
  • 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). This uses a clockwise spiral, assuming y points up.
      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. This uses a clockwise spiral, assuming y points up.
      Parameters:
      width - The grid's width
      height - The grid's height
      start - The starting coordinate.
    • SquareSpiral

      public SquareSpiral(int width, int height, int x, int y, boolean clockwise)
      An iterator to iterate in the square of size size around (x, y). If clockwise is true, this uses a clockwise spiral, assuming y points up.
      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, boolean clockwise)
      An iterator to iterate in the square of size size around start. If clockwise is true, this uses a clockwise spiral, assuming y points up.
      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)