public final class MapLocation extends Object implements Serializable, Comparable<MapLocation>
| Modifier and Type | Field and Description |
|---|---|
int |
x
The x-coordinate.
|
int |
y
The y-coordinate.
|
| Constructor and Description |
|---|
MapLocation(int x,
int y)
Creates a new MapLocation representing the location
with the given coordinates.
|
| Modifier and Type | Method and Description |
|---|---|
MapLocation |
add(Direction direction)
Returns a new MapLocation object representing a location
one square from this one in the given direction.
|
MapLocation |
add(Direction direction,
int multiple)
Returns a new MapLocation object representing a location
multiple squares from this one in the given direction. |
MapLocation |
add(int dx,
int dy)
Returns a new MapLocation object translated from this location
by a fixed amount
|
int |
compareTo(MapLocation other)
A comparison function for MapLocations.
|
Direction |
directionTo(MapLocation location)
Returns the Direction from this MapLocation to
location. |
int |
distanceSquaredTo(MapLocation location)
Computes the square of the distance from this location to the specified
location.
|
boolean |
equals(Object obj)
Two MapLocations are regarded as equal iff
their coordinates are the same.
|
static MapLocation[] |
getAllMapLocationsWithinRadiusSq(MapLocation center,
int radiusSquared)
Returns an array of all MapLocations within a certain radius squared
of a specified location (cannot be called with radiusSquared greater than 100).
|
int |
hashCode() |
boolean |
isAdjacentTo(MapLocation location)
Determines whether this location is adjacent to the specified
location.
|
MapLocation |
subtract(Direction direction)
Returns a new MapLocation object representing a location
one square from this one in the opposite of the given direction.
|
String |
toString() |
static MapLocation |
valueOf(String s) |
public MapLocation(int x,
int y)
x - the x-coordinate of the locationy - the y-coordinate of the locationpublic int compareTo(MapLocation other)
compareTo in interface Comparable<MapLocation>other - the MapLocation to compare to.public boolean equals(Object obj)
public static MapLocation valueOf(String s)
public final int distanceSquaredTo(MapLocation location)
location - the location to compute the distance squared topublic final boolean isAdjacentTo(MapLocation location)
location - the location to testpublic final Direction directionTo(MapLocation location)
location.
If the locations are equal this method returns Direction.OMNI. If
location is null then the return value is Direction.NONE.location - The location to which the Direction will be calculatedlocation from this MapLocation.public final MapLocation add(Direction direction)
direction - the direction to add to this locationpublic final MapLocation add(Direction direction, int multiple)
multiple squares from this one in the given direction.direction - the direction to add to this locationmultiple - the number of squares to addpublic final MapLocation add(int dx, int dy)
dx - the amount to translate in the x directiondy - the amount to translate in the y directionpublic final MapLocation subtract(Direction direction)
direction - the direction to subtract from this locationpublic static MapLocation[] getAllMapLocationsWithinRadiusSq(MapLocation center, int radiusSquared)
center - the center of the searchradiusSquared - the radius of the search, which must be at most 100.IllegalArgumentException - if the radiusSquared is greater than 100 or is negative.