Package net.sf.freecol.common.model
Class Map.Position
- java.lang.Object
-
- net.sf.freecol.common.model.Map.Position
-
- Enclosing class:
- Map
public static final class Map.Position extends java.lang.ObjectA position on the Map.
-
-
Constructor Summary
Constructors Constructor Description Position(int posX, int posY)Creates a newPositionobject with the given coordinates.Position(Map.Position start, Direction direction)Creates a newPositionfrom an existing one with an optional step in a given direction.Position(Tile tile)Creates a newPositionobject with the coordinates of a supplied tile.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)DirectiongetDirection(Map.Position other)Get the direction from this position to an adjacent position.intgetDistance(Map.Position position)Gets the distance in tiles between two map positions.intgetX()Gets the x-coordinate of this Position.static intgetXYDistance(int ax, int ay, int bx, int by)Gets the distance in tiles between two map positions.intgetY()Gets the y-coordinate of this Position.inthashCode()booleanisValid(int width, int height)Checks whether a position is valid within a given map size.java.lang.StringtoString()
-
-
-
Constructor Detail
-
Position
public Position(int posX, int posY)Creates a newPositionobject with the given coordinates.- Parameters:
posX- The x-coordinate for this position.posY- The y-coordinate for this position.
-
Position
public Position(Tile tile)
Creates a newPositionobject with the coordinates of a supplied tile.- Parameters:
tile- TheTileto extract coordinates from.
-
Position
public Position(Map.Position start, Direction direction)
Creates a newPositionfrom an existing one with an optional step in a given direction.- Parameters:
start- The startingPosition.direction- An optionalDirectionto step.
-
-
Method Detail
-
getX
public int getX()
Gets the x-coordinate of this Position.- Returns:
- The x-coordinate of this Position.
-
getY
public int getY()
Gets the y-coordinate of this Position.- Returns:
- The y-coordinate of this Position.
-
isValid
public boolean isValid(int width, int height)Checks whether a position is valid within a given map size.- Parameters:
width- The width of the map.height- The height of the map.- Returns:
- True if the given position is within the bounds of the map.
-
getXYDistance
public static int getXYDistance(int ax, int ay, int bx, int by)Gets the distance in tiles between two map positions. With an isometric map this is a non-trivial task. The formula below has been developed largely through trial and error. It should cover all cases, but I wouldn't bet my life on it.- Parameters:
ax- The x-coordinate of the first position.ay- The y-coordinate of the first position.bx- The x-coordinate of the second position.by- The y-coordinate of the second position.- Returns:
- The distance in tiles between the positions.
-
getDistance
public int getDistance(Map.Position position)
Gets the distance in tiles between two map positions. With an isometric map this is a non-trivial task. The formula below has been developed largely through trial and error. It should cover all cases, but I wouldn't bet my life on it.- Parameters:
position- The otherPositionto compare.- Returns:
- The distance in tiles to the other position.
-
getDirection
public Direction getDirection(Map.Position other)
Get the direction from this position to an adjacent position.- Parameters:
other- The adjacentPosition.- Returns:
- The
Direction, or null if not adjacent.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-