Hex Class Reference

#include <Hex.h>

List of all members.


Public Member Functions

 Hex ()
 Pulic constructor.
 Hex (int x, int y)
 Creates hex at given location.
 ~Hex ()
 Virtual destructor.
Hex NeighborHex (int dir) const
 Gets neighbor hex in given direction.
int HexRange (Hex hex) const
 Gets range to given hex.
void NextHexes (Hex h0, Hex h1, Hex prev1, Hex prev2, Hex &next1, Hex &next2) const
 Gets next hexes between two hexes.
bool IntersectsLine (double x0, double y0, double x1, double y1) const
 Checks if line intersects hex.
bool IsEmpty () const
 Checks if hex is empty.
void SetEmpty ()
 Mark hex as empty.
bool operator== (const Hex &hex) const
 Checks for equality with another hex.
bool operator!= (const Hex &hex) const
 Checks for inequality with another hex.
int GetHexX ()
 Gets X coordinate in hex units.
int GetHexY ()
 Gets Y coordinate in hex coordinates.

Private Attributes

bool m_IsEmpty
 Indicates that hex is empty.
int m_HexX
 X coordinate in hex units.
int m_HexY
 Y coordinate in hex units.
double m_CenterX
 X coordinate of hex center.
double m_CenterY
 Y coordinate of hex center.
double m_PointX [6]
 Array of X coordinates for hex corners.
double m_PointY [6]
 Array of Y coordinates for hex corners.

Detailed Description

(*** add brief description here ***)
Full Description
(*** add full description here ***)

Constructor & Destructor Documentation

Hex (  )  [inline]

Pulic constructor.

Hex ( int  x,
int  y 
)

Creates hex at given location.

Full Description
This method creates a new hex. Hexes are created with coordinate pairs that are laid out on a grid as follows:

  -x\__/  \__/  \__/  \__/+y  <-- 'hy' axis
  __/-x\__/  \__/  \__/+y\__ 
    \__/-x\__/  \__/+y\__/   
  __/  \__/-x\__/+y\__/  \__ 
    \__/  \__/00\__/  \__/   
  __/  \__/-y\__/+x\__/  \__ 
    \__/-y\__/  \__/+x\__/   
  __/-y\__/  \__/  \__/+x\__ 
  -y\  /  \  /  \  /  \  /+x  <-- 'hx' axis

The vertices are stored counter-clockwise as follows:

    2---1       x
   /     \      x
  3       0     x
   \     /      x 
    4---5       x

The center point of hex(0,0) is at cartesian coordinate (0,0). The cartesian coordinate system is scaled such that all centers and vertex coordinates lie on integral values to eliminate precision loss during cross-product calculations.

Returns:
New hex at given coordinate.
Parameters:
x  X coordinate in hex units.
y  Y coordinate in hex units.

~Hex (  ) 

Virtual destructor.

Full Description
This method destroys an existing instance of the class.
Returns:
None.


Member Function Documentation

Hex NeighborHex ( int  dir  )  const

Gets neighbor hex in given direction.

Full Description
Returns the neighboring hex in the given direction. Neighboring hex directions are laid counter-clockwise as follows:

         \__/          dir  pa  pb  dx  dy
      \__/1 \__/
     _/2 \__/0 \_       0    0   1   0  +1
      \__/  \__/        1    1   2  -1  +1
     _/3 \__/5 \_       2    2   3  -1   0
      \__/4 \__/        3    3   4   0  -1
      /  \__/  \        4    4   5  +1  -1
         /  \           5    5   0  +1   0

Where 'dir' is the direction, 'pa' and 'pb' are the indexes of the endpoints of the face seperating the hexes, and 'dx' and 'dy' are the hex coordinate deltas.

Note that the index of the first endpoint of a face is equal to the direction used to exit through that face.

Returns:
Hex representing the neighbor in the given direction.
Parameters:
dir  direction of neighboring hex.

int HexRange ( Hex  hex  )  const

Gets range to given hex.

Full Description
This method calculates the range to another hex.
Returns:
Range in hexes to the given hex.
Parameters:
hex  Target hex for range calculations.

void NextHexes ( Hex  h0,
Hex  h1,
Hex  prev1,
Hex  prev2,
Hex next1,
Hex next2 
) const

Gets next hexes between two hexes.

Full Description
Gets the next hex(es) touching the line connecting the centers of hexes h0 and h1.
Returns:
None.
Parameters:
h0  Start hex.
h1  End hex.
prev1  First previous hex.
prev2  Second previous hex.
next1  First next hex.
next2  Second next hex.

bool IntersectsLine ( double  x0,
double  y0,
double  x1,
double  y1 
) const

Checks if line intersects hex.

Full Description
Determines if a hex intersects a line by calculating cross products between the original line and lines between (x0,y0) and the vertices. The function returns zero if no vertex is on the line and all vertecies are on one side of the line. Otherwise the function returns non-zero.

Returns:
True if the line intersects the hex, false otherwise.
Parameters:
x0  First X coordinate.
y0  First Y coordinate.
x1  Second X coordinate.
y1  Second Y coordinate.

bool IsEmpty (  )  const [inline]

Checks if hex is empty.

void SetEmpty (  )  [inline]

Mark hex as empty.

bool operator== ( const Hex hex  )  const [inline]

Checks for equality with another hex.

bool operator!= ( const Hex hex  )  const [inline]

Checks for inequality with another hex.

int GetHexX (  )  [inline]

Gets X coordinate in hex units.

int GetHexY (  )  [inline]

Gets Y coordinate in hex coordinates.


Member Data Documentation

bool m_IsEmpty [private]

Indicates that hex is empty.

int m_HexX [private]

X coordinate in hex units.

int m_HexY [private]

Y coordinate in hex units.

double m_CenterX [private]

X coordinate of hex center.

double m_CenterY [private]

Y coordinate of hex center.

double m_PointX[6] [private]

Array of X coordinates for hex corners.

double m_PointY[6] [private]

Array of Y coordinates for hex corners.


The documentation for this class was generated from the following files: