Class Area

java.lang.Object
com.valhalla.sdk.api.math.Area
All Implemented Interfaces:
Locatable

public final class Area extends Object implements Locatable
An immutable rectangular or polygonal world area on one plane.
  • Constructor Details

    • Area

      public Area(int x1, int y1, int x2, int y2)
      Creates an inclusive rectangular area on plane zero.
      Parameters:
      x1 - first corner X
      y1 - first corner Y
      x2 - opposite corner X
      y2 - opposite corner Y
    • Area

      public Area(int x1, int y1, int x2, int y2, int plane)
      Creates an inclusive rectangular area; corner order does not matter.
      Parameters:
      x1 - first corner X
      y1 - first corner Y
      x2 - opposite corner X
      y2 - opposite corner Y
      plane - world plane shared by the area
    • Area

      public Area(Tile firstCorner, Tile secondCorner)
      Creates an inclusive rectangle from two same-plane corners.
      Parameters:
      firstCorner - one rectangle corner
      secondCorner - opposite rectangle corner
      Throws:
      IllegalArgumentException - when the corners use different planes
    • Area

      public Area(Tile... vertices)
      Creates a polygon whose edges and interior tiles are included.
      Parameters:
      vertices - at least three same-plane vertices in boundary order
      Throws:
      IllegalArgumentException - when fewer than three vertices are supplied or their planes differ
  • Method Details

    • getPlane

      public int getPlane()
      Returns the area's world plane.
      Specified by:
      getPlane in interface Locatable
      Returns:
      world plane shared by every tile in this area
    • getMinX

      public int getMinX()
      Returns the left bounding coordinate.
      Returns:
      inclusive minimum world X
    • getMaxX

      public int getMaxX()
      Returns the right bounding coordinate.
      Returns:
      inclusive maximum world X
    • getMinY

      public int getMinY()
      Returns the lower bounding coordinate.
      Returns:
      inclusive minimum world Y
    • getMaxY

      public int getMaxY()
      Returns the upper bounding coordinate.
      Returns:
      inclusive maximum world Y
    • getVertices

      public Tile[] getVertices()
      Returns the declared geometry vertices.
      Returns:
      defensive copy of rectangle corners or polygon vertices
    • getBoundaryPoints

      public List<Tile> getBoundaryPoints()
      Returns the declared vertices as an immutable list.
      Returns:
      boundary vertices; this does not enumerate every tile along each edge
    • getCenter

      public Tile getCenter()
      Returns the bounding-box midpoint.
      Returns:
      midpoint of the area's bounding box on its plane
    • getTile

      public Tile getTile()
      Returns this area's representative location.
      Specified by:
      getTile in interface Locatable
      Returns:
      the bounding-box center used as this area's representative location
    • generateArea

      public static Area generateArea(int radius, Tile center)
      Creates an inclusive square around a center tile.
      Parameters:
      radius - non-negative tile radius
      center - square center and plane
      Returns:
      square area spanning center +/- radius
    • contains

      public boolean contains(Tile tile)
      Tests whether a tile lies on the same plane and inside or on the boundary.
      Parameters:
      tile - tile to test
      Returns:
      true when contained; false for null
    • contains

      public boolean contains(Locatable locatable)
      Tests whether a locatable's tile is contained.
      Parameters:
      locatable - value to test
      Returns:
      true when its tile is contained; false for null
    • contains

      public boolean contains(int x, int y)
      Tests X/Y containment on this area's plane.
      Parameters:
      x - world X
      y - world Y
      Returns:
      true for interior and boundary coordinates
    • getNearestTile

      public Tile getNearestTile(Tile origin)
      Selects the contained tile nearest to an origin by squared X/Y distance.

      Polygon scans are limited to 65,536 bounding-box tiles to prevent accidental expensive enumeration.

      Parameters:
      origin - comparison origin; its plane does not alter the returned plane
      Returns:
      nearest contained tile on this area's plane
      Throws:
      IllegalStateException - when a polygon's bounding box is too large to scan
    • getNearestTile

      public Tile getNearestTile(Locatable origin)
      Selects the contained tile nearest to a locatable.
      Parameters:
      origin - comparison origin
      Returns:
      nearest contained tile on this area's plane
    • withPlane

      public Area withPlane(int newPlane)
      Copies this area's geometry onto another plane.
      Parameters:
      newPlane - replacement plane
      Returns:
      area with identical X/Y geometry
    • distanceTo

      public int distanceTo(Tile origin)
      Measures Chebyshev distance to the nearest contained tile.
      Specified by:
      distanceTo in interface Locatable
      Parameters:
      origin - comparison tile
      Returns:
      zero when the origin is contained, otherwise nearest tile distance
    • getRandomTile

      public Tile getRandomTile()
      Selects a random contained tile.
      Returns:
      a random contained tile using the thread-local random source
    • getRandomTile

      public Tile getRandomTile(Random random)
      Selects a random contained tile.
      Parameters:
      random - random source
      Returns:
      contained tile; falls back to the nearest center tile after bounded sampling
    • getTiles

      public List<Tile> getTiles()
      Enumerates every contained tile in X-major order.
      Returns:
      immutable tile list
      Throws:
      IllegalStateException - when the bounding box exceeds 65,536 tiles
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object value)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object