public class Location
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Location.CompassDirection
Class to represent the 8 compass directions.
|
Modifier and Type | Field and Description |
---|---|
static Location.CompassDirection |
EAST
The compass direction for east.
|
static Location.CompassDirection |
NORTH
The compass direction for north.
|
static Location.CompassDirection |
NORTHEAST
The compass direction for northeast.
|
static Location.CompassDirection |
NORTHWEST
The compass direction for northwest.
|
static Location.CompassDirection |
SOUTH
The compass direction for south.
|
static Location.CompassDirection |
SOUTHEAST
The compass direction for southeast.
|
static Location.CompassDirection |
SOUTHWEST
The compass direction for southwest.
|
static Location.CompassDirection |
WEST
The compass direction for west.
|
int |
x
The public horizontal coordinate (cell index) of the location.
|
int |
y
The public vertical coordinate (cell index) of the location.
|
Constructor and Description |
---|
Location()
Constructs a location at (0, 0).
|
Location(int x,
int y)
Constructs a location with given horizontal and vertical cell coordinates.
|
Location(Location location)
Constructs a location with the coordinates of the given location.
|
Modifier and Type | Method and Description |
---|---|
Location |
clone()
Returns a new location with duplicated coordinates.
|
boolean |
equals(java.lang.Object obj)
Checks whether the x-y-coordinates of the given location
are equal to the x-y-coordinates of the current location
(overrides Object.equals()).
|
Location.CompassDirection |
get4CompassDirectionTo(Location location)
Returns the compass direction restricted to 4 sectors from the current location the given location.
|
Location |
getAdjacentLocation(double direction)
Same as getAdjacentLocation(double direction, 5).
|
Location |
getAdjacentLocation(double direction,
int distance)
Gets the adjacent location of a cell where a displacement arrow from the
current center of the current cell with given direction and
length = (distance + epsilon) * cellSize ends up.
|
Location |
getAdjacentLocation(Location.CompassDirection compassDir)
Same as getAdjacentLocation(double direction, 5) with given
compass direction.
|
Location |
getAdjacentLocation(Location.CompassDirection compassDir,
int distance)
Same as getAdjacentLocation(double direction, int distance) with
given compass direction.
|
Location.CompassDirection |
getCompassDirectionTo(Location location)
Returns the compass direction restricted to 8 sectors from the current location the given location.
|
double |
getDirectionTo(Location location)
Returns the direction from the current location to the given location.
|
int |
getDistanceTo(Location location)
Returns the distance from the current location to the given location
(in cellsize units, rounded to integer).
|
Location |
getNeighbourLocation(double direction)
Gets one of the 8 surrounding cells in given direction 45 degrees wide.
|
Location |
getNeighbourLocation(Location.CompassDirection compassDir)
Gets one of the 8 surrounding cells in the given compass directions.
|
java.util.ArrayList<Location> |
getNeighbourLocations(double distance)
Returns all locations in a specified distance.
|
int |
getX()
Gets the horizontal cell coordinate (index).
|
int |
getY()
Gets the vertical cell coordinate (index).
|
int |
hashCode()
Returns a hash code value for the object.
|
java.lang.String |
toString()
Returns a string that represents this location.
|
public int x
public int y
public static final Location.CompassDirection EAST
public static final Location.CompassDirection SOUTHEAST
public static final Location.CompassDirection SOUTH
public static final Location.CompassDirection SOUTHWEST
public static final Location.CompassDirection WEST
public static final Location.CompassDirection NORTHWEST
public static final Location.CompassDirection NORTH
public static final Location.CompassDirection NORTHEAST
public Location()
public Location(int x, int y)
x
- the horizontal cell coordinatey
- the vertical cell coordinatepublic Location(Location location)
location
- the location where to take the horizontal and vertical cell coordinatespublic int getX()
public int getY()
public Location getAdjacentLocation(double direction, int distance)
direction
- the direction in which to find a adjacent locationdistance
- the distance to the requested cell location in cell units.public Location getAdjacentLocation(Location.CompassDirection compassDir, int distance)
compassDir
- the compass direction in which to find a adjacent locationdistance
- the distance to the requested cell locationpublic Location getAdjacentLocation(double direction)
direction
- the direction in which to find a adjacent locationpublic Location getAdjacentLocation(Location.CompassDirection compassDir)
compassDir
- the compass direction in which to find a adjacent locationpublic Location getNeighbourLocation(double direction)
direction
- the direction in which to find a neighbour locationpublic Location getNeighbourLocation(Location.CompassDirection compassDir)
compassDir
- the compass direction in which to find a neighbour locationpublic double getDirectionTo(Location location)
location
- the target locationpublic int getDistanceTo(Location location)
location
- the remote locationpublic Location.CompassDirection get4CompassDirectionTo(Location location)
location
- the target locationpublic Location.CompassDirection getCompassDirectionTo(Location location)
location
- the target locationpublic int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the object whose location is checkedpublic java.util.ArrayList<Location> getNeighbourLocations(double distance)
distance
- the distance in (fractional) cell unitspublic java.lang.String toString()
toString
in class java.lang.Object
public Location clone()
clone
in class java.lang.Object