Class CoordArea

java.lang.Object
org.rspeer.game.coord.shape.CoordArea
All Implemented Interfaces:
CoordShape

public class CoordArea extends Object implements CoordShape
Represents an axis-aligned rectangular area of world coordinates on a single floor level.

A CoordArea is defined by two corner Coord values and a target floor. X- and Y-spans are automatically normalized via Range.ordered(int, int), ensuring minimum() <= maximum() for both axes.

All coordinates are inclusive: an area from (10, 20) to (12, 23) contains 3 × 4 = 12 tiles.

Floor-level handling

By default, the area only matches coordinates on the same floor level. Calling ignoreFloorLevel() allows contains(SceneNode) to match regardless of floor.
  • Method Details

    • surrounding

      public static CoordArea surrounding(Coord origin, int distance)
    • from

      public static CoordArea from(Coord a, Coord b, int floorLevel)
      Constructs a rectangular coordinate area from two opposite corner coordinates.

      The X and Y ranges are normalized so that the rectangle always spans:

        xs.minimum() .. xs.maximum()
        ys.minimum() .. ys.maximum()
      
      Parameters:
      a - one corner of the rectangle
      b - the opposite corner of the rectangle
      floorLevel - the floor level this area applies to
    • from

      public static CoordArea from(Coord a, Coord b)
      Constructs a rectangular coordinate area from two opposite corner coordinates, using the floor of the coord as the area floor

      The X and Y ranges are normalized so that the rectangle always spans:

        xs.minimum() .. xs.maximum()
        ys.minimum() .. ys.maximum()
      
      Parameters:
      a - one corner of the rectangle
      b - the opposite corner of the rectangle
    • from

      public static CoordArea from(Coord coord)
      Creates a CoordArea representing exactly one tile — the given Coord.

      This is equivalent to constructing an area where both corners are the same coordinate:

      new CoordArea(coord, coord, coord.getFloorLevel())
      

      The resulting area has:

      • width = 1
      • height = 1
      • floor level taken from the provided coord
      • exactly one tile returned by getCoords()
      Parameters:
      coord - the coordinate defining the single-tile area (must not be null)
      Returns:
      a CoordArea containing only the specified coordinate
    • toArea

      @Deprecated public Area toArea()
      Deprecated.
    • ignoreFloorLevel

      public CoordArea ignoreFloorLevel()
      Allows the area to match coordinates on any floor level instead of only the configured floorLevel.
      Returns:
      this area (for chaining)
    • getXs

      public org.rspeer.commons.math.Range getXs()
      Returns:
      the inclusive X-range for this area
    • getYs

      public org.rspeer.commons.math.Range getYs()
      Returns:
      the inclusive Y-range for this area
    • getBottomLeft

      public Coord getBottomLeft()
    • getBottomRight

      public Coord getBottomRight()
    • getTopLeft

      public Coord getTopLeft()
    • getTopRight

      public Coord getTopRight()
    • getWidth

      public int getWidth()
      Returns the width of the area in tiles.

      Because the range is inclusive, width is computed as:

        maxX - minX + 1
      
      Returns:
      the number of tiles spanned along the X axis
    • getHeight

      public int getHeight()
      Returns the height of the area in tiles.
      Returns:
      the number of tiles spanned along the Y axis
    • contains

      public boolean contains(SceneNode node)
      Checks whether the given coordinate lies inside this rectangular area.

      If ignoreFloorLevel() was called, the floor does not matter.

      Specified by:
      contains in interface CoordShape
      Parameters:
      node - the node to test
      Returns:
      true if inside the rectangle
    • getVertices

      public Set<Coord> getVertices()
      Returns the four rectangle corner coordinates in a fixed order: bottom-left, top-left, bottom-right, top-right.
      Specified by:
      getVertices in interface CoordShape
      Returns:
      an immutable set of the rectangle's vertices
    • getBoundary

      public Set<Coord> getBoundary(boolean outer)
      Returns all coordinates forming the perimeter of the rectangle.
      Specified by:
      getBoundary in interface CoordShape
      Parameters:
      outer - if true, returns the outer boundary (one tile outside the rectangle);
      if false, returns the perimeter tiles on the rectangle itself.
      Returns:
      a set of perimeter coordinates
    • getEast

      public Set<Coord> getEast(boolean outer)
      Returns the coordinates along the east side of this area.
      Parameters:
      outer - if true, returns the outside strip at maxX + 1; otherwise returns the inside edge at maxX
      Returns:
      the one-tile-wide east line
    • getWest

      public Set<Coord> getWest(boolean outer)
      Returns the coordinates along the west side of this area.
      Parameters:
      outer - if true, returns the outside strip at minX - 1; otherwise returns the inside edge at minX
      Returns:
      the one-tile-wide west line
    • getSouth

      public Set<Coord> getSouth(boolean outer)
      Returns the coordinates along the south side of this area.
      Parameters:
      outer - if true, returns the outside strip at minY - 1; otherwise returns the inside edge at minY
      Returns:
      the one-tile-wide south line
    • getNorth

      public Set<Coord> getNorth(boolean outer)
      Returns the coordinates along the north side of this area.
      Parameters:
      outer - if true, returns the outside strip at maxY + 1; otherwise returns the inside edge at maxY
      Returns:
      the one-tile-wide north line
    • getCoords

      public Set<Coord> getCoords()
      Returns all coordinates contained within this rectangular area.

      For large rectangles, this may be a large set. The set is pre-sized to avoid internal resizing.

      Specified by:
      getCoords in interface CoordShape
      Returns:
      all coordinates inside the area
    • getFloorLevel

      public int getFloorLevel()
      Specified by:
      getFloorLevel in interface CoordShape
    • getAreaView

      public CoordAreaView getAreaView()