hex::Hex Class Reference

#include <hex.h>

List of all members.


Detailed Description

A single hexagonal quanta of area.

Definition at line 260 of file hex.h.

Public Member Functions

const Gridgrid (void) const
const Edgeedge (const Direction &d) const
Edgeedge (const Direction &d)
Hexgo (const Direction &d, int distance=1) const
Hexgo (const std::string &steps) const
Point centre (void) const
std::string str (void) const
 Hex (const Grid &grid, int i_, int j_)

Static Public Member Functions

static int _key (int i, int j)
 Generates a unique key for co-ordinates i,j.

Public Attributes

const int i
 in units of I
const int j
 in units of J

Friends

class Grid


Constructor & Destructor Documentation

hex::Hex::Hex ( const Grid grid,
int  i_,
int  j_ 
)

Definition at line 109 of file hex.cc.

00109                                         :
00110   _edgeA(this,A), _edgeB(this,B), _edgeC(this,C),
00111   _edgeD(this,D), _edgeE(this,E), _edgeF(this,F),
00112   _grid(grid), i(i_), j(j_)
00113 {}


Member Function Documentation

const Grid& hex::Hex::grid ( void   )  const [inline]

Definition at line 267 of file hex.h.

Referenced by hex::Area::boundary(), and hex::range().

00267 { return _grid; }

const Edge * hex::Hex::edge ( const Direction d  )  const

Definition at line 47 of file hex.cc.

Referenced by hex::Area::boundary(), hex::Edge::complement(), hex::move::Topography::increase_hex_cost(), hex::Edge::next_in(), hex::Edge::next_out(), hex::move::Topography::override_hex_cost(), and hex::move::Topography::step().

00048 {
00049   return const_cast<Edge*>( const_cast<Hex*>(this)->edge( d ) );
00050 }

Edge * hex::Hex::edge ( const Direction d  ) 

Definition at line 32 of file hex.cc.

References hex::A, hex::B, hex::C, hex::D, and hex::E.

00033 {
00034   switch(d)
00035   {
00036     case A:  return &_edgeA;
00037     case B:  return &_edgeB;
00038     case C:  return &_edgeC;
00039     case D:  return &_edgeD;
00040     case E:  return &_edgeE;
00041     default: return &_edgeF;
00042   }
00043 }

Hex * hex::Hex::go ( const Direction d,
int  distance = 1 
) const

Definition at line 54 of file hex.cc.

References hex::go(), hex::Grid::hex(), i, and j.

Referenced by hex::Grid::area(), hex::Edge::complement(), hex::Area::fillpaths(), and hex::move::Topography::step().

00055 {
00056   int i_ =this->i;
00057   int j_ =this->j;
00058   hex::go(i_,j_,d,distance); // in/out: i_,j_ 
00059   try
00060   {
00061     return _grid.hex(i_,j_);
00062   }
00063   catch(hex::out_of_range)
00064   {
00065     return NULL;
00066   }
00067 }

Hex * hex::Hex::go ( const std::string &  steps  )  const

Definition at line 71 of file hex.cc.

References hex::go(), hex::Grid::hex(), i, and j.

00072 {
00073   int i_ =this->i;
00074   int j_ =this->j;
00075   hex::go(i_,j_,steps); // in/out: i_,j_ 
00076   try
00077   {
00078     return _grid.hex(i_,j_);
00079   }
00080   catch(hex::out_of_range)
00081   {
00082     return NULL;
00083   }
00084 }

Point hex::Hex::centre ( void   )  const

Definition at line 88 of file hex.cc.

References i, hex::I, j, hex::J, hex::K, hex::Point::x, and hex::Point::y.

Referenced by hex::move::_Route::distance(), hex::Edge::join_point(), and hex::Edge::start_point().

00089 {
00090   Point result;
00091   if(this->j % 2)
00092       result.x = I * (1 + this->i); // odd rows
00093   else 
00094       result.x = I/2.0 + I * this->i; // even rows
00095   result.y = K + J * this->j;
00096   return result;
00097 }

std::string hex::Hex::str ( void   )  const

Definition at line 101 of file hex.cc.

References i, and j.

Referenced by hex::Area::str().

00102 {
00103   std::ostringstream ss;
00104   ss<< this->i <<"_"<< this->j;
00105   return ss.str();
00106 }

static int hex::Hex::_key ( int  i,
int  j 
) [inline, static]

Generates a unique key for co-ordinates i,j.

(i,j < 2^14)

Definition at line 275 of file hex.h.

Referenced by hex::Grid::hex().

00275 { return (i<<14) | j; }


Friends And Related Function Documentation

friend class Grid [friend]

Definition at line 279 of file hex.h.


Member Data Documentation

const int hex::Hex::i

in units of I

Definition at line 265 of file hex.h.

Referenced by hex::Area::boundary(), centre(), go(), hex::range(), hex::steps(), and str().

const int hex::Hex::j

in units of J

Definition at line 266 of file hex.h.

Referenced by hex::Area::boundary(), centre(), go(), hex::range(), hex::steps(), and str().


The documentation for this class was generated from the following files:
Generated on Thu Feb 21 00:00:55 2008 for libhex by  doxygen 1.5.1