Package com.valhalla.sdk.api.math
Class Area
java.lang.Object
com.valhalla.sdk.api.math.Area
- All Implemented Interfaces:
Locatable
An immutable rectangular or polygonal world area on one plane.
-
Constructor Summary
ConstructorsConstructorDescriptionArea(int x1, int y1, int x2, int y2) Creates an inclusive rectangular area on plane zero.Area(int x1, int y1, int x2, int y2, int plane) Creates an inclusive rectangular area; corner order does not matter.Creates a polygon whose edges and interior tiles are included.Creates an inclusive rectangle from two same-plane corners. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(int x, int y) Tests X/Y containment on this area's plane.booleanTests whether a locatable's tile is contained.booleanTests whether a tile lies on the same plane and inside or on the boundary.intdistanceTo(Tile origin) Measures Chebyshev distance to the nearest contained tile.booleanstatic AreagenerateArea(int radius, Tile center) Creates an inclusive square around a center tile.Returns the declared vertices as an immutable list.Returns the bounding-box midpoint.intgetMaxX()Returns the right bounding coordinate.intgetMaxY()Returns the upper bounding coordinate.intgetMinX()Returns the left bounding coordinate.intgetMinY()Returns the lower bounding coordinate.getNearestTile(Locatable origin) Selects the contained tile nearest to a locatable.getNearestTile(Tile origin) Selects the contained tile nearest to an origin by squared X/Y distance.intgetPlane()Returns the area's world plane.Selects a random contained tile.getRandomTile(Random random) Selects a random contained tile.getTile()Returns this area's representative location.getTiles()Enumerates every contained tile in X-major order.Tile[]Returns the declared geometry vertices.inthashCode()toString()withPlane(int newPlane) Copies this area's geometry onto another plane.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.valhalla.sdk.api.entities.Locatable
canReach, canReach, distance, getGridX, getGridY, getRegionId, getX, getY, getZ, isInArea, isWithinDistance, walkingDistance
-
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 Xy1- first corner Yx2- opposite corner Xy2- 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 Xy1- first corner Yx2- opposite corner Xy2- opposite corner Yplane- world plane shared by the area
-
Area
Creates an inclusive rectangle from two same-plane corners.- Parameters:
firstCorner- one rectangle cornersecondCorner- opposite rectangle corner- Throws:
IllegalArgumentException- when the corners use different planes
-
Area
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. -
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
Returns the declared geometry vertices.- Returns:
- defensive copy of rectangle corners or polygon vertices
-
getBoundaryPoints
Returns the declared vertices as an immutable list.- Returns:
- boundary vertices; this does not enumerate every tile along each edge
-
getCenter
Returns the bounding-box midpoint.- Returns:
- midpoint of the area's bounding box on its plane
-
getTile
Returns this area's representative location. -
generateArea
Creates an inclusive square around a center tile.- Parameters:
radius- non-negative tile radiuscenter- square center and plane- Returns:
- square area spanning
center +/- radius
-
contains
Tests whether a tile lies on the same plane and inside or on the boundary.- Parameters:
tile- tile to test- Returns:
truewhen contained;falsefornull
-
contains
Tests whether a locatable's tile is contained.- Parameters:
locatable- value to test- Returns:
truewhen its tile is contained;falsefornull
-
contains
public boolean contains(int x, int y) Tests X/Y containment on this area's plane.- Parameters:
x- world Xy- world Y- Returns:
truefor interior and boundary coordinates
-
getNearestTile
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
Selects the contained tile nearest to a locatable.- Parameters:
origin- comparison origin- Returns:
- nearest contained tile on this area's plane
-
withPlane
Copies this area's geometry onto another plane.- Parameters:
newPlane- replacement plane- Returns:
- area with identical X/Y geometry
-
distanceTo
Measures Chebyshev distance to the nearest contained tile.- Specified by:
distanceToin interfaceLocatable- Parameters:
origin- comparison tile- Returns:
- zero when the origin is contained, otherwise nearest tile distance
-
getRandomTile
Selects a random contained tile.- Returns:
- a random contained tile using the thread-local random source
-
getRandomTile
Selects a random contained tile.- Parameters:
random- random source- Returns:
- contained tile; falls back to the nearest center tile after bounded sampling
-
getTiles
Enumerates every contained tile in X-major order.- Returns:
- immutable tile list
- Throws:
IllegalStateException- when the bounding box exceeds 65,536 tiles
-
toString
-
equals
-
hashCode
public int hashCode()
-