#include <hex.h>
Inheritance diagram for hex::Area:
Definition at line 288 of file hex.h.
Public Member Functions | |
int | size (void) const |
bool | contains (Hex *h) const |
Boundary | boundary (void) const |
const std::set< Hex * > & | hexes (void) const |
std::list< Area > | enclosed_areas (void) const |
std::list< Boundary > | skeleton (bool include_boundary=true) const |
For drawing the structure. | |
std::list< hex::Path > | fillpaths (Hex *origin=NULL) const |
A list of one or more paths that include every hex in the area once. | |
std::string | str (Hex *origin=NULL) const |
Area | go (const Direction &d, int distance=1) const throw (hex::out_of_range) |
Area | go (const std::string &steps) const throw (hex::out_of_range) |
Area (void) | |
Required for list<Area>. | |
Area (const std::set< Hex * > &hexes) | |
Area (Hex *h) | |
Area (Hex *h, int distance) | |
All hexes <= distance from h. |
hex::Area::Area | ( | const std::set< Hex * > & | hexes | ) |
Definition at line 173 of file area.cc.
References hex::is_connected().
00173 : _hexes(hexes) 00174 { 00175 #ifdef HEX_PARANOID_CHECKS 00176 assert(is_connected(hexes)); 00177 #endif 00178 }
hex::Area::Area | ( | Hex * | h | ) | [inline] |
hex::Area::Area | ( | Hex * | h, | |
int | distance | |||
) |
All hexes <= distance from h.
Definition at line 181 of file area.cc.
References hex::range().
00181 : _hexes() 00182 { 00183 for(int i=0; i<=distance; ++i) 00184 { 00185 std::set<Hex*> s =range(h,i); 00186 std::copy(s.begin(),s.end(),inserter(_hexes,_hexes.end())); 00187 } 00188 }
int hex::Area::size | ( | void | ) | const [inline] |
bool hex::Area::contains | ( | Hex * | h | ) | const [inline] |
Boundary hex::Area::boundary | ( | void | ) | const |
Definition at line 33 of file area.cc.
References contains(), hex::D, hex::Hex::edge(), hex::Hex::grid(), hex::Edge::hex(), hex::Grid::hex(), hex::Hex::i, hex::Hex::j, and hex::Edge::next_in().
Referenced by hex::svg::Document::draw_complex_area(), hex::svg::Document::draw_simple_area(), enclosed_areas(), main(), and skeleton().
00034 { 00035 // Start with a random hex. 00036 Hex* h =*_hexes.begin(); 00037 const Grid& grid =h->grid(); 00038 const int i0 =h->i; 00039 const int j0 =h->j; 00040 // Find an edge. 00041 int i=0; 00042 while(i<=i0 && !contains(grid.hex(i,j0))) 00043 ++i; 00044 std::list<Edge*> result; 00045 result.push_back( grid.hex(i,j0)->edge(D) ); 00046 // Follow the edge round. 00047 while(true) 00048 { 00049 Edge* e =result.back()->next_out(); 00050 if( !e || !contains(e->hex()) ) 00051 e = result.back()->next_in(); 00052 if(e == result.front()) 00053 break; 00054 result.push_back(e); 00055 } 00056 return result; 00057 }
const std::set<Hex*>& hex::Area::hexes | ( | void | ) | const [inline] |
Definition at line 295 of file hex.h.
Referenced by hex::fill(), hex::move::Topography::increase_cost(), and hex::move::Topography::override_cost().
std::list< Area > hex::Area::enclosed_areas | ( | void | ) | const |
Definition at line 61 of file area.cc.
References _hexes, hex::Boundary::area(), hex::areas(), boundary(), and hex::set_difference().
Referenced by hex::svg::Document::draw_complex_area().
00062 { 00063 Area a =boundary().area(); 00064 return areas( set_difference( a._hexes, _hexes ) ); 00065 }
std::list< Boundary > hex::Area::skeleton | ( | bool | include_boundary = true |
) | const |
For drawing the structure.
If include_boundary is TRUE, then the last item in the list is the external boundary of the area.
Definition at line 69 of file area.cc.
References hex::A, hex::B, boundary(), and hex::C.
Referenced by hex::svg::Document::draw_skeleton().
00070 { 00071 std::list<Boundary> result; 00072 for(std::set<Hex*>::const_iterator h=_hexes.begin(); h!=_hexes.end(); ++h) 00073 { 00074 std::list<Edge*> edges; 00075 edges.push_back( (**h).edge(A) ); 00076 edges.push_back( (**h).edge(B) ); 00077 edges.push_back( (**h).edge(C) ); 00078 result.push_back(edges); 00079 } 00080 if(include_boundary) 00081 result.push_back(boundary()); 00082 return result; 00083 }
A list of one or more paths that include every hex in the area once.
Definition at line 87 of file area.cc.
References hex::F, hex::Hex::go(), and hex::path().
Referenced by str().
00088 { 00089 // Try to calculate a path that fills area. 00090 std::set<Hex*> queue =_hexes; 00091 std::set<Hex*> seen; 00092 std::list<Path> result; 00093 std::list<Hex*> path; 00094 Hex* hex = origin? origin: *queue.begin(); 00095 Direction dir =F; 00096 while(!queue.empty()) 00097 { 00098 path.push_back( hex ); 00099 queue.erase( hex ); 00100 seen.insert( hex ); 00101 Direction d=dir+1; 00102 while(true) 00103 { 00104 if(d==dir) 00105 { 00106 result.push_back( path ); 00107 path.clear(); 00108 hex = *queue.begin(); 00109 break; 00110 } 00111 Hex* hd =hex->go(d); 00112 if(queue.count(hd) && !seen.count(hd)) 00113 { 00114 hex = hd; 00115 dir = d+3; 00116 break; 00117 } 00118 ++d; 00119 } 00120 } 00121 return result; 00122 }
std::string hex::Area::str | ( | Hex * | origin = NULL |
) | const |
Definition at line 126 of file area.cc.
References fillpaths(), hex::steps(), and hex::Hex::str().
Referenced by main().
00127 { 00128 if(!origin) 00129 origin=*_hexes.begin(); 00130 std::ostringstream result; 00131 std::list<Path> paths =this->fillpaths(origin); 00132 result << origin->str(); 00133 for(std::list<Path>::const_iterator p =paths.begin(); p!=paths.end(); ++p) 00134 { 00135 if(p->hexes().front()!=origin) 00136 result << ">" << hex::steps(origin,p->hexes().front()); 00137 result << ":" << p->steps(); 00138 } 00139 return result.str(); 00140 }
Area hex::Area::go | ( | const Direction & | d, | |
int | distance = 1 | |||
) | const throw (hex::out_of_range) |
Definition at line 144 of file area.cc.
References _hexes, and hex::distance().
00145 { 00146 Area result; 00147 for(std::set<Hex*>::const_iterator h=_hexes.begin(); h!=_hexes.end(); ++h) 00148 { 00149 Hex* hex =(**h).go(d,distance); 00150 if(!hex) 00151 throw hex::out_of_range("Area::go"); 00152 result._hexes.insert(hex); 00153 } 00154 return result; 00155 }
Area hex::Area::go | ( | const std::string & | steps | ) | const throw (hex::out_of_range) |
Definition at line 159 of file area.cc.
References _hexes, and hex::steps().
00160 { 00161 Area result; 00162 for(std::set<Hex*>::const_iterator h=_hexes.begin(); h!=_hexes.end(); ++h) 00163 { 00164 Hex* hex =(**h).go(steps); 00165 if(!hex) 00166 throw hex::out_of_range("Area::go"); 00167 result._hexes.insert(hex); 00168 } 00169 return result; 00170 }