|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ch.aplu.jgamegrid.Location
public class Location
Class to represent the position of a cell (in cell coordinates). Directions are measured in degrees clockwise from the positive x-axis.
Nested Class Summary | |
---|---|
static class |
Location.CompassDirection
Class to represent the 8 compass directions. |
Field Summary | |
---|---|
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 Summary | |
---|---|
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. |
Method Summary | |
---|---|
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. |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
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
Constructor Detail |
---|
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 coordinatesMethod Detail |
---|
public 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 location
public Location getAdjacentLocation(double direction)
direction
- the direction in which to find a adjacent location
public Location getAdjacentLocation(Location.CompassDirection compassDir)
compassDir
- the compass direction in which to find a adjacent location
public Location getNeighbourLocation(double direction)
direction
- the direction in which to find a neighbour location
public Location getNeighbourLocation(Location.CompassDirection compassDir)
compassDir
- the compass direction in which to find a neighbour location
public double getDirectionTo(Location location)
location
- the target location
public int getDistanceTo(Location location)
location
- the remote location
public Location.CompassDirection get4CompassDirectionTo(Location location)
location
- the target location
public Location.CompassDirection getCompassDirectionTo(Location location)
location
- the target location
public 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 checked
public 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
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |