Package com.valhalla.sdk.api.math
Class Tile
java.lang.Object
com.valhalla.sdk.api.math.Tile
- All Implemented Interfaces:
Locatable
Immutable world coordinate expressed as X, Y, and plane.
Distance helpers use Chebyshev distance unless their name explicitly refers to walking or squared Euclidean distance. Equality includes the plane.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Clones this coordinate.copy()Copies this coordinate.intdistance()Measures direct distance to the local player.intMeasures Chebyshev distance, ignoring plane.longdistanceSquaredTo(Tile other) Computes squared Euclidean X/Y distance without taking a square root.intdistanceTo(Tile other) Measures Chebyshev distance, ignoring plane.booleangetArea(int radius) Creates an inclusive square area centered on this tile.intgetGridX()Returns the scene-local X coordinate.intgetGridY()Returns the scene-local Y coordinate.intgetPlane()Returns the world plane.Randomizes this tile with the default deviation.getRandomized(int deviation) Randomizes X and Y independently within an inclusive deviation.intReturns the map-region identifier.getTile()Returns this location as a tile.intgetX()Returns the world X coordinate.intgetY()Returns the world Y coordinate.intgetZ()Returns the world plane using Z terminology.inthashCode()booleanisWithinDistance(Tile other, int distance) Tests same-plane Chebyshev proximity.toString()translate(int deltaX, int deltaY) Translates X and Y while retaining the plane.translate(int deltaX, int deltaY, int deltaPlane) Translates all three coordinates.Treats another tile as an X/Y/plane offset.intwalkingDistance(Tile other) Returns exact local collision distance when available, otherwise a conservative estimate.withPlane(int newPlane) Changes only this coordinate's plane.
-
Field Details
-
x
public final int xWorld X coordinate. -
y
public final int yWorld Y coordinate. -
plane
public final int planeWorld plane, conventionally from 0 through 3.
-
-
Constructor Details
-
Tile
public Tile()Creates the origin tile(0, 0, 0). -
Tile
public Tile(int x, int y) Creates a tile on plane zero.- Parameters:
x- world X coordinatey- world Y coordinate
-
Tile
public Tile(int x, int y, int plane) Creates a world tile.- Parameters:
x- world X coordinatey- world Y coordinateplane- world plane
-
-
Method Details
-
getX
public int getX()Returns the world X coordinate. -
getY
public int getY()Returns the world Y coordinate. -
getPlane
public int getPlane()Returns the world plane. -
getZ
public int getZ()Returns the world plane using Z terminology.- Specified by:
getZin interfaceLocatable- Returns:
- world plane; alias for
getPlane()
-
getTile
Returns this location as a tile. -
copy
Copies this coordinate.- Returns:
- a distinct tile with the same coordinates
-
clone
Clones this coordinate. -
translate
Translates X and Y while retaining the plane.- Parameters:
deltaX- X offsetdeltaY- Y offset- Returns:
- translated tile
-
translate
Treats another tile as an X/Y/plane offset.- Parameters:
delta- coordinate offsets- Returns:
- translated tile
-
translate
Translates all three coordinates.- Parameters:
deltaX- X offsetdeltaY- Y offsetdeltaPlane- plane offset- Returns:
- translated tile
-
withPlane
Changes only this coordinate's plane.- Parameters:
newPlane- replacement plane- Returns:
- tile with unchanged X/Y and the supplied plane
-
getArea
Creates an inclusive square area centered on this tile.- Parameters:
radius- non-negative tile radius- Returns:
- square area on this tile's plane
-
getGridX
public int getGridX()Returns the scene-local X coordinate. -
getGridY
public int getGridY()Returns the scene-local Y coordinate. -
getRandomized
Randomizes this tile with the default deviation.- Returns:
- a tile randomized by at most two tiles on each axis
-
getRandomized
Randomizes X and Y independently within an inclusive deviation.- Parameters:
deviation- non-negative maximum axis offset- Returns:
- randomized tile on the same plane
-
distanceTo
Measures Chebyshev distance, ignoring plane.- Specified by:
distanceToin interfaceLocatable- Parameters:
other- comparison tile- Returns:
- maximum absolute X/Y difference
-
distance
public int distance()Measures direct distance to the local player. -
distance
Measures Chebyshev distance, ignoring plane.- Parameters:
other- comparison tile- Returns:
- maximum absolute X/Y difference
-
walkingDistance
Returns exact local collision distance when available, otherwise a conservative estimate.- Specified by:
walkingDistancein interfaceLocatable- Parameters:
other- destination tile- Returns:
- path length, or three times Chebyshev distance when no exact route is available
-
distanceSquaredTo
Computes squared Euclidean X/Y distance without taking a square root.- Parameters:
other- comparison tile- Returns:
- squared X/Y distance as a
long
-
isWithinDistance
Tests same-plane Chebyshev proximity.- Specified by:
isWithinDistancein interfaceLocatable- Parameters:
other- comparison tiledistance- inclusive, non-negative radius- Returns:
truewhen the plane matches and distance is within the radius
-
getRegionId
public int getRegionId()Returns the map-region identifier.- Specified by:
getRegionIdin interfaceLocatable- Returns:
- packed 64-by-64 map-region identifier
-
equals
-
hashCode
public int hashCode() -
toString
-