com.strangelight.misc.hex
Class HexGrid.Location

java.lang.Object
  |
  +--com.strangelight.misc.hex.HexGrid.Location
All Implemented Interfaces:
_Testable, java.lang.Cloneable
Enclosing class:
HexGrid

public class HexGrid.Location
extends java.lang.Object
implements java.lang.Cloneable, _Testable

A single hexagonal cell location.


Constructor Summary
HexGrid.Location(int column, int diagonal)
          constructs a new HexGrid.Location object representing an hexagonal cell at the given coordinates.
 
Method Summary
 boolean equals(java.lang.Object location)
          tests if two HexGrid.Location objects represent the same location.
 float geomDistanceTo(HexGrid.Location the_location)
          gets the geometric (Cartesian) distance between this HexGrid.Location and another HexGrid.Location.
 java.awt.geom.Point2D.Float getCenterPoint()
          get the center point of this cell as a Point2D.Float object.
 int getColumn()
          the column number of this cell.
 int getDiagonal()
          the diagonal number of this cell.
 HexGrid.Location getNeighbor(HexDirection direction)
          gets the HexGrid.Location which is adjacent to this HexGrid.Location in the given direction.
 HexGrid.Location getNeighborClosestTo(HexGrid.Location target)
          I can't believe I'm writing code when I'm this stoned...
 HexPath getShortestPathTo(HexGrid.Location target)
          gets a HexPath which most closely approximates a straight line between this HexGrid.Location and the target.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HexGrid.Location

public HexGrid.Location(int column,
                        int diagonal)
constructs a new HexGrid.Location object representing an hexagonal cell at the given coordinates.

Parameters:
diagonal - the cell diagonal. Numbers increase to the South (HexDirection.S).
column - the cell column. Numbers increase to the East (HexDirection.NE and HexDirection.SE).
Method Detail

toString

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

getDiagonal

public int getDiagonal()
the diagonal number of this cell.

Returns:
the diagonal number of this cell.

getColumn

public int getColumn()
the column number of this cell.

Returns:
the column number of this cell.

getCenterPoint

public java.awt.geom.Point2D.Float getCenterPoint()
get the center point of this cell as a Point2D.Float object.

Returns:
the center point of this cell as a Point2D.Float object.

equals

public boolean equals(java.lang.Object location)
tests if two HexGrid.Location objects represent the same location.

Overrides:
equals in class java.lang.Object
Returns:
true if and only if this cell and location have the same coordinates, and thus represent the same cell on our grid.
Throws:
java.lang.ClassCastException - if location is not a HexGrid.Location object.

geomDistanceTo

public float geomDistanceTo(HexGrid.Location the_location)
gets the geometric (Cartesian) distance between this HexGrid.Location and another HexGrid.Location. Distances are computed from the HexGrid.Locations' center-points.

Parameters:
the_location - the other HexGrid.Location to which to compute the distance.
Returns:
the geometric (Cartesian) distance between this HexGrid.Location and another HexGrid.Location.
See Also:
getCenterPoint()

getShortestPathTo

public HexPath getShortestPathTo(HexGrid.Location target)
gets a HexPath which most closely approximates a straight line between this HexGrid.Location and the target.

Parameters:
target - the other HexGrid.Location to which to find a path.
Returns:
a HexPath representing a sequence of HexLocations which most closely approximates a straight line between this HexGrid.Location and the target. Note that multiple paths may satisfy these criteria, and that this method offers no guarantees about which of these best approximations will be returned, only that one of them will be. Note in particular that there is no guarantee that A.getShortestPathTo(B) will contain the same cells as B.getShortestPathTo(A) .

getNeighborClosestTo

public HexGrid.Location getNeighborClosestTo(HexGrid.Location target)
I can't believe I'm writing code when I'm this stoned... Okay, so like, this routine um... returns a HexGrid.Location which is adjacent to this and which is closer to target than this is.

Parameters:
target - a HexGrid.Location that we want to get closer to.
Returns:
a HexGrid.Location which is adjacent to this and which is closer to target than this is.(Returns this if and only if target.equals(this) ).

getNeighbor

public HexGrid.Location getNeighbor(HexDirection direction)
gets the HexGrid.Location which is adjacent to this HexGrid.Location in the given direction.

Parameters:
direction - the HexDirection from which to fetch the adjacent cell.
Returns:
the HexGrid.Location which is adjacent to this HexGrid.Location in the given direction.