hex::Boundary Class Reference

#include <hex.h>

Inheritance diagram for hex::Boundary:

hex::svg::Identity List of all members.

Detailed Description

A sequence of adjacent edges.

Definition at line 337 of file hex.h.

Public Member Functions

int length (void) const
 < in units of K
bool is_closed (void) const
 has no endpoints
bool is_container (void) const
 contains finite area
Boundary complement (void) const throw (hex::out_of_range)
const std::list< Edge * > & edges (void) const
Path to_path (void) const
bool clockwise (void) const
 normally false.
std::string str (void) const
std::list< Pointstroke (float bias=0.0) const
 Calculate the set of points required to draw this boundary.
Area area (void) const
 Returns the area enclosed by the boundary.
 Boundary (void)
 Required for list<Boundary>.
 Boundary (const std::list< Edge * > &edges)


Constructor & Destructor Documentation

hex::Boundary::Boundary ( void   )  [inline]

Required for list<Boundary>.

Definition at line 355 of file hex.h.

hex::Boundary::Boundary ( const std::list< Edge * > &  edges  )  [inline]

Definition at line 356 of file hex.h.

00356 : _edges(edges) {}


Member Function Documentation

int hex::Boundary::length ( void   )  const

< in units of K

Definition at line 32 of file boundary.cc.

00033 {
00034   return int( _edges.size() );
00035 }

bool hex::Boundary::is_closed ( void   )  const

has no endpoints

Definition at line 39 of file boundary.cc.

Referenced by area(), hex::svg::Document::draw_boundary(), is_container(), and stroke().

00040 {
00041   return( _edges.size()>2 && _edges.front()->is_next( *_edges.back() ) );
00042 }

bool hex::Boundary::is_container ( void   )  const

contains finite area

Definition at line 46 of file boundary.cc.

References complement(), is_closed(), hex::Path::length(), and to_path().

00047 {
00048   if(is_closed())
00049   {
00050     try {
00051       Path p1 =complement().to_path();
00052       Path p0 =to_path();
00053       return( p0.length() < p1.length() );
00054     }
00055     catch(hex::out_of_range) {
00056       // If is_closed AND there is no complement, then the boundary must
00057       // be at the very edge of the grid... it MUST be a container.
00058       return true;
00059     }
00060   }
00061   return false;
00062 }

Boundary hex::Boundary::complement ( void   )  const throw (hex::out_of_range)

Definition at line 66 of file boundary.cc.

References complement().

Referenced by complement(), and is_container().

00067 {
00068   std::list<Edge*> result;
00069   for(std::list<Edge*>::const_iterator e=_edges.begin(); e!=_edges.end(); ++e)
00070   {
00071     Edge* c =(**e).complement();
00072     if(c)
00073         result.push_back( c );
00074     else
00075         throw hex::out_of_range("Boundary complement out of range.");
00076   }
00077   return result;
00078 }

const std::list<Edge*>& hex::Boundary::edges ( void   )  const [inline]

Definition at line 345 of file hex.h.

Referenced by hex::move::Topography::increase_cost(), and hex::move::Topography::override_cost().

00345 { return _edges; }

Path hex::Boundary::to_path ( void   )  const

Definition at line 82 of file boundary.cc.

Referenced by is_container().

00083 {
00084   std::list<Hex*> result;
00085   for(std::list<Edge*>::const_iterator e=_edges.begin(); e!=_edges.end(); ++e)
00086     if( result.empty() || (**e).hex() != result.back() )
00087         result.push_back( (**e).hex() );
00088   return result;
00089 }

bool hex::Boundary::clockwise ( void   )  const

normally false.

Definition at line 93 of file boundary.cc.

References hex::Edge::next_in(), and hex::Edge::next_out().

Referenced by str(), and stroke().

00094 {
00095   // Boundaries usually go round in a positive (anti-clockwise) direction.
00096   if(_edges.size() > 1)
00097   {
00098     std::list<Edge*>::const_iterator e =_edges.begin();
00099     Edge* e0 = *e;
00100     Edge* e1 = *(++e);
00101     return( e0==e1->next_in() || e0==e1->next_out() );
00102   }
00103   return false;
00104 }

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

Definition at line 108 of file boundary.cc.

References clockwise(), and hex::to_char().

00109 {
00110   assert(!_edges.empty());
00111   std::string result =_edges.front()->hex()->str() + (clockwise()?"-":"+");
00112   for(std::list<Edge*>::const_iterator e=_edges.begin(); e!=_edges.end(); ++e)
00113       result += to_char( (**e).direction() );
00114   return result;
00115 }

std::list< Point > hex::Boundary::stroke ( float  bias = 0.0  )  const

Calculate the set of points required to draw this boundary.

Definition at line 119 of file boundary.cc.

References clockwise(), hex::Edge::end_point(), is_closed(), and hex::Edge::join_point().

Referenced by hex::svg::Document::draw_boundary(), hex::svg::Document::draw_complex_area(), and hex::svg::Document::draw_simple_area().

00120 {
00121   std::list<Point> result;
00122   bool cw =this->clockwise();
00123   if(bias==0.0)
00124   {
00125     if(!_edges.empty())
00126     {
00127       std::list<Edge*>::const_iterator e =_edges.begin();
00128       result.push_back( (**e).start_point(0.0,cw) );
00129       while(e!=_edges.end())
00130       {
00131         result.push_back( (**e).end_point(0.0,cw) );
00132         ++e;
00133       }
00134     }
00135   }
00136   else
00137   {
00138     Edge* last =NULL;
00139     for(std::list<Edge*>::const_iterator e=_edges.begin(); e!=_edges.end(); ++e)
00140     {
00141       if(last)
00142           result.push_back( last->join_point(*e,bias) );
00143       last = *e;
00144     }
00145     if(is_closed())
00146     {
00147       Point p =last->join_point(_edges.front(),bias);
00148       result.push_front( p );
00149       result.push_back( p );
00150     }
00151     else
00152     {
00153       result.push_front( _edges.front()->start_point(bias,cw) );
00154       result.push_back( last->end_point(bias,cw) );
00155     }
00156   }
00157   return result;
00158 }

Area hex::Boundary::area ( void   )  const

Returns the area enclosed by the boundary.

It is an error to call this function when is_closed()==false

Definition at line 162 of file boundary.cc.

References hex::fill(), and is_closed().

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

00163 {
00164   assert(is_closed());
00165   std::set<Hex*> beyond;
00166   std::set<Hex*> queue;
00167   for(std::list<Edge*>::const_iterator e=_edges.begin(); e!=_edges.end(); ++e)
00168   {
00169     queue.insert(  (**e).hex() );
00170     beyond.insert( (**e).hex()->go( (**e).direction() ) ); // NULL is OK.
00171   }
00172   return fill(beyond,queue);
00173 }


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