rl.common.mapping
Class Coordinate

java.lang.Object
  extended by rl.common.mapping.Coordinate
All Implemented Interfaces:
java.io.Serializable

public class Coordinate
extends java.lang.Object
implements java.io.Serializable

Coords stores x and y values. Since these are hexes, coordinates with odd x values are a half-hex down. Directions work clockwise around the hex, starting with zero at the top. -y 0 _____ 5 / \ 1 -x / \ +x \ / 4 \_____/ 2 3 +y Code in this class copyright BMazur and curtesy of the MegaMek project http://megamek.sourceforge.org portions based off of http://www.rossmack.com/ab/RPG/traveller/AstroHexDistance.asp

See Also:
Serialized Form

Field Summary
static double HEXSIDE
           
(package private) static long serialVersionUID
           
 int x
           
 int y
           
 
Constructor Summary
Coordinate()
          Constructs a new coordinate pair at (0, 0).
Coordinate(Coordinate c)
          Constructs a new coordinate pair that is a duplicate of the parameter.
Coordinate(int x, int y)
          Constructs a new coordinate pair at (x, y).
 
Method Summary
 boolean equals(java.lang.Object object)
          Coordinate are equal if their x and y components are equal
 java.lang.String getBoardNum()
          Returns a string representing a coordinate in "board number" format.
 int hashCode()
          Add by Daniel Cleyne.
 boolean isXOdd()
          Tests whether the x coordinate of this coordinate is odd.
 void setCoordinate(int x, int y)
           
 java.lang.String toShortString()
           
 java.lang.String toString()
           
 Coordinate translated(int dir)
          Returns a new coordinate that represents the coordinate 1 unit in the specified direction.
static int xInDir(int x, int y, int dir)
          Returns the x parameter of the coordinates in the direction
static int yInDir(int x, int y, int dir)
          Returns the y parameter of the coordinates in the direction
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

x

public int x

y

public int y

HEXSIDE

public static final double HEXSIDE
See Also:
Constant Field Values
Constructor Detail

Coordinate

public Coordinate()
Constructs a new coordinate pair at (0, 0).


Coordinate

public Coordinate(int x,
                  int y)
Constructs a new coordinate pair at (x, y).


Coordinate

public Coordinate(Coordinate c)
Constructs a new coordinate pair that is a duplicate of the parameter.

Method Detail

hashCode

public int hashCode()
Add by Daniel Cleyne. Allows the Coordinate object to be used as a reliable key in HashMap.

Overrides:
hashCode in class java.lang.Object

setCoordinate

public void setCoordinate(int x,
                          int y)

translated

public final Coordinate translated(int dir)
Returns a new coordinate that represents the coordinate 1 unit in the specified direction.

Parameters:
dir - the direction.
Returns:
the new coordinate, if the direction is valid; otherwise, a new copy of this coordinate.

xInDir

public static final int xInDir(int x,
                               int y,
                               int dir)
Returns the x parameter of the coordinates in the direction


yInDir

public static final int yInDir(int x,
                               int y,
                               int dir)
Returns the y parameter of the coordinates in the direction


isXOdd

public boolean isXOdd()
Tests whether the x coordinate of this coordinate is odd. This is significant in determining where this coordinate lies in relation to other coordinates.


getBoardNum

public final java.lang.String getBoardNum()
Returns a string representing a coordinate in "board number" format.


equals

public boolean equals(java.lang.Object object)
Coordinate are equal if their x and y components are equal

Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toShortString

public java.lang.String toShortString()