Class Zone.Skeleton

java.lang.Object
squidpony.squidgrid.zone.Zone.Skeleton
All Implemented Interfaces:
Serializable, Iterable<Coord>, Zone
Direct Known Subclasses:
CoordPackerZone, GreasedRegion, ListZone, Rectangle.Impl
Enclosing interface:
Zone

public abstract static class Zone.Skeleton
extends Object
implements Zone
A convenience partial implementation. Please try for all new implementations of Zone to be subtypes of this class. It usually prove handy at some point to have a common superclass.
Author:
smelC
See Also:
Serialized Form
  • Field Details

  • Constructor Details

  • Method Details

    • size

      public int size()
      Specified by:
      size in interface Zone
      Returns:
      The number of cells that this zone contains (the size Zone.getAll()).
    • contains

      public boolean contains​(int x, int y)
      Specified by:
      contains in interface Zone
      Returns:
      Whether this zone contains the coordinate (x,y).
    • contains

      public boolean contains​(Coord c)
      Specified by:
      contains in interface Zone
      Returns:
      Whether this zone contains c.
    • contains

      public boolean contains​(Zone other)
      Specified by:
      contains in interface Zone
      Returns:
      true if all cells of other are in this.
    • intersectsWith

      public boolean intersectsWith​(Zone other)
      Specified by:
      intersectsWith in interface Zone
      Returns:
      true if this and other have a common cell.
    • iterator

      public Iterator<Coord> iterator()
      Specified by:
      iterator in interface Iterable<Coord>
    • getWidth

      public int getWidth()
      Specified by:
      getWidth in interface Zone
      Returns:
      The distance between the leftmost cell and the rightmost cell, or anything negative if this zone is empty; may be 0 if all cells are in one vertical line.
    • getHeight

      public int getHeight()
      Specified by:
      getHeight in interface Zone
      Returns:
      The distance between the topmost cell and the lowest cell, or anything negative if this zone is empty; may be 0 if all cells are in one horizontal line.
    • getDiagonal

      public double getDiagonal()
      Specified by:
      getDiagonal in interface Zone
      Returns:
      The approximation of the zone's diagonal, using Zone.getWidth() and Zone.getHeight().
    • xBound

      public int xBound​(boolean smallestOrBiggest)
      Specified by:
      xBound in interface Zone
      Parameters:
      smallestOrBiggest - if true, finds the smallest x-coordinate value; if false, finds the biggest.
      Returns:
      The x-coordinate of the Coord within this that has the smallest (or biggest) x-coordinate. Or -1 if the zone is empty.
    • yBound

      public int yBound​(boolean smallestOrBiggest)
      Specified by:
      yBound in interface Zone
      Parameters:
      smallestOrBiggest - if true, finds the smallest y-coordinate value; if false, finds the biggest.
      Returns:
      The y-coordinate of the Coord within this that has the smallest (or biggest) y-coordinate. Or -1 if the zone is empty.
    • getCenter

      public Coord getCenter()
      Specified by:
      getCenter in interface Zone
      Returns:
      The approximate center of this zone, or null if this zone is empty.
    • translate

      public Zone translate​(Coord c)
      Specified by:
      translate in interface Zone
      Returns:
      this shifted by (c.x,c.y)
    • translate

      public Zone translate​(int x, int y)
      Specified by:
      translate in interface Zone
      Returns:
      this shifted by (x,y)
    • getInternalBorder

      Specified by:
      getInternalBorder in interface Zone
      Returns:
      Cells in this that are adjacent to a cell not in this
    • getExternalBorder

      Description copied from interface: Zone
      Gets a Collection of Coord values that are not in this Zone, but are adjacent to it, either orthogonally or diagonally. Related to the fringe() methods in CoordPacker and GreasedRegion, but guaranteed to use 8-way adjacency and to return a new Collection of Coord.
      Specified by:
      getExternalBorder in interface Zone
      Returns:
      Cells adjacent to this (orthogonally or diagonally) that aren't in this
    • extend

      public Zone extend()
      Description copied from interface: Zone
      Gets a new Zone that contains all the Coords in this plus all neighboring Coords, which can be orthogonally or diagonally adjacent to any Coord this has in it. Related to the expand() methods in CoordPacker and GreasedRegion, but guaranteed to use 8-way adjacency and to return a new Zone.
      Specified by:
      extend in interface Zone
      Returns:
      A variant of this where cells adjacent to this (orthogonally or diagonally) have been added (i.e. it's this plus Zone.getExternalBorder()).