Class BoxSurfaceIterator

java.lang.Object
net.apartium.cocoabeans.space.iterator.BoxSurfaceIterator
All Implemented Interfaces:
Iterator<Position>

@AvailableSince("0.0.49") public final class BoxSurfaceIterator extends Object implements Iterator<Position>
Iterates over all positions on the surface of an axis-aligned box.

A position is included if at least one of its coordinates is equal to the minimum or maximum bound of the box. Interior positions are skipped.

Positions are emitted face by face. The iterator adjusts the coordinate ranges per face so edges and corners are not returned more than once.

If min and max describe the same position, the iterator returns that single position.

  • Constructor Details

    • BoxSurfaceIterator

      public BoxSurfaceIterator(int radius)
      Creates an iterator over a cube shell centered at 0 with the given radius.
      Parameters:
      radius - the cube radius (range will be [-radius, radius])
    • BoxSurfaceIterator

      public BoxSurfaceIterator(int min, int max)
      Creates an iterator over a cube shell in the range [min, max] using the default AxisOrder.XYZ.
      Parameters:
      min - the minimum coordinate (inclusive)
      max - the maximum coordinate (inclusive)
    • BoxSurfaceIterator

      public BoxSurfaceIterator(AxisOrder axisOrder, int min, int max)
      Creates an iterator over a cube shell in the range [min, max].
      Parameters:
      axisOrder - the axis order used to construct positions
      min - the minimum coordinate (inclusive)
      max - the maximum coordinate (inclusive)
      Throws:
      IllegalArgumentException - if max < min
      NullPointerException - if axisOrder is null
    • BoxSurfaceIterator

      public BoxSurfaceIterator(AxisOrder axisOrder, Position min, Position max)
      Creates an iterator over the surface of a rectangular box.

      The given bounds are normalized with Position.floor() and then stored as immutable positions.

      Parameters:
      axisOrder - the axis order used when constructing returned positions
      min - the minimum corner, inclusive
      max - the maximum corner, inclusive
      Throws:
      IllegalArgumentException - if any coordinate in max is smaller than the corresponding coordinate in min
      NullPointerException - if axisOrder, min, or max is null
  • Method Details

    • hasNext

      public boolean hasNext()
      Returns whether another surface position is available.
      Specified by:
      hasNext in interface Iterator<Position>
      Returns:
      true if the iterator has more positions
    • next

      public Position next()
      Returns the next surface position.
      Specified by:
      next in interface Iterator<Position>
      Returns:
      the next position on the box surface
      Throws:
      NoSuchElementException - if no more positions are available
    • peek

      public Position peek()
      Returns the next surface position without advancing the iterator.
      Returns:
      the next position on the box surface