# HG changeset patch
# User gyorokp
# Date 1270898683 -7200
# Node ID ece0de9a63f86df029e092cdcf0b8949606992bc
# Parent 873b8d0104e73ab66cacb90ff7e6e2de6122eb81
CommonFacesIt, CommonNodesIt fixes (#363)
diff -r 873b8d0104e7 -r ece0de9a63f8 lemon/planar_graph.h
a
|
b
|
|
1284 | 1284 | class CommonFacesIt : public Face { |
1285 | 1285 | const Graph* _graph; |
1286 | 1286 | const Node _n1, _n2; |
1287 | | Arc _i2; |
1288 | | std::set<Face> _f1; |
| 1287 | std::set<Face> _f1, _f2; |
| 1288 | typename std::set<Face>::const_iterator _fi2; |
1289 | 1289 | public: |
1290 | 1290 | |
1291 | 1291 | CommonFacesIt() {} |
… |
… |
|
1293 | 1293 | CommonFacesIt(Invalid i) : Face(i) { } |
1294 | 1294 | |
1295 | 1295 | explicit CommonFacesIt(const Graph& graph, Node n1, Node n2) : _graph( |
1296 | | &graph), _n1(n1), _n2(n2), _i2(), _f1(){ |
| 1296 | &graph), _n1(n1), _n2(n2), _f1(), _f2(){ |
1297 | 1297 | Arc _i1; |
1298 | 1298 | _graph->firstOut(_i1,_n1); |
1299 | 1299 | while (_i1 != INVALID) { |
1300 | 1300 | _f1.insert(_graph->leftFace(_i1)); |
1301 | 1301 | _graph->nextOut(_i1); |
1302 | 1302 | } |
| 1303 | Arc _i2; |
1303 | 1304 | _graph->firstOut(_i2,_n2); |
1304 | | _graph->firstOut(_i2,_n2); |
1305 | | while (_i2 != INVALID && _f1.count(_graph->leftFace(_i2)) == 0) |
| 1305 | while (_i2 != INVALID) { |
| 1306 | _f2.insert(_graph->leftFace(_i2)); |
1306 | 1307 | _graph->nextOut(_i2); |
1307 | | static_cast<Face&>(*this) = (_i2 != INVALID)?_graph->leftFace(_i2): |
1308 | | INVALID; |
| 1308 | } |
| 1309 | |
| 1310 | _fi2 = _f2.begin(); |
| 1311 | while (_fi2 != _f2.end() && _f1.count(*_fi2) == 0) |
| 1312 | ++_fi2; |
| 1313 | static_cast<Face&>(*this) = (_fi2 != _f2.end())?*_fi2:INVALID; |
1309 | 1314 | } |
1310 | 1315 | |
1311 | 1316 | CommonFacesIt& operator++() { |
1312 | | _graph->nextOut(_i2); |
1313 | | while (_i2 != INVALID && _f1.count(_graph->leftFace(_i2)) == 0) |
1314 | | _graph->nextOut(_i2); |
1315 | | static_cast<Face&>(*this) = (_i2 != INVALID)?_graph->leftFace(_i2): |
1316 | | INVALID; |
| 1317 | ++_fi2; |
| 1318 | while (_fi2 != _f2.end() && _f1.count(*_fi2) == 0) |
| 1319 | ++_fi2; |
| 1320 | static_cast<Face&>(*this) = (_fi2 != _f2.end())?*_fi2:INVALID; |
1317 | 1321 | return *this; |
1318 | 1322 | } |
1319 | 1323 | |
… |
… |
|
1325 | 1329 | class CommonNodesIt : public Node { |
1326 | 1330 | const Graph* _graph; |
1327 | 1331 | const Face _f1, _f2; |
1328 | | Arc _i2; |
1329 | | std::set<Node> _ns; |
| 1332 | std::set<Node> _ns1,_ns2; |
| 1333 | typename std::set<Node>::const_iterator _ni2; |
1330 | 1334 | public: |
1331 | 1335 | |
1332 | 1336 | CommonNodesIt() {} |
… |
… |
|
1334 | 1338 | CommonNodesIt(Invalid i) : Face(i) { } |
1335 | 1339 | |
1336 | 1340 | explicit CommonNodesIt(const Graph& graph, Face f1, Face f2) : _graph( |
1337 | | &graph), _f1(f1), _f2(f2), _i2(), _ns(){ |
| 1341 | &graph), _f1(f1), _f2(f2), _ns1(), _ns2(){ |
1338 | 1342 | Arc _i1; |
1339 | 1343 | _graph->firstCwF(_i1,_f1); |
1340 | 1344 | while (_i1 != INVALID) { |
1341 | | _ns.insert(_graph->source(_i1)); |
| 1345 | _ns1.insert(_graph->source(_i1)); |
1342 | 1346 | _graph->nextCwF(_i1); |
1343 | 1347 | } |
| 1348 | Arc _i2; |
| 1349 | _graph->firstCwF(_i2,_f2); |
| 1350 | while (_i2 != INVALID) { |
| 1351 | _ns2.insert(_graph->source(_i2)); |
| 1352 | _graph->nextCwF(_i2); |
| 1353 | } |
1344 | 1354 | |
1345 | | _graph->firstCwF(_i2,_f2); |
1346 | | while (_i2 != INVALID && _ns.count(_graph->source(_i2)) == 0) |
1347 | | _graph->nextCwF(_i2); |
1348 | | static_cast<Node&>(*this) = (_i2 != INVALID)?_graph->source(_i2): |
1349 | | INVALID; |
| 1355 | _ni2 = _ns2.begin(); |
| 1356 | while (_ni2 != _ns2.end() && _ns1.count(*_ni2) == 0) |
| 1357 | ++_ni2; |
| 1358 | static_cast<Node&>(*this) = (_ni2 != _ns2.end())?*_ni2:INVALID; |
1350 | 1359 | } |
1351 | 1360 | |
1352 | 1361 | CommonNodesIt& operator++() { |
1353 | | _graph->nextCwF(_i2); |
1354 | | while (_i2 != INVALID && _ns.count(_graph->source(_i2)) == 0) |
1355 | | _graph->nextCwF(_i2); |
1356 | | static_cast<Node&>(*this) = (_i2 != INVALID)?_graph->source(_i2): |
1357 | | INVALID; |
| 1362 | ++_ni2; |
| 1363 | while (_ni2 != _ns2.end() && _ns1.count(*_ni2) == 0) |
| 1364 | ++_ni2; |
| 1365 | static_cast<Node&>(*this) = (_ni2 != _ns2.end())?*_ni2:INVALID; |
1358 | 1366 | return *this; |
1359 | 1367 | } |
1360 | 1368 | |
diff -r 873b8d0104e7 -r ece0de9a63f8 test/planar_graph_test.cc
a
|
b
|
|
228 | 228 | checkGraphBoundaryArcList(G, G.leftFace(G.direct(a2,false)), 3); |
229 | 229 | checkGraphBoundaryArcList(G, G.leftFace(G.direct(a3,true)), 4); |
230 | 230 | |
| 231 | checkGraphCommonFaceList(G, n0, n2, 2); |
| 232 | checkGraphCommonFaceList(G, n0, n3, 2); |
| 233 | checkGraphCommonFaceList(G, n2, n3, 1); |
| 234 | |
| 235 | checkGraphCommonNodeList(G, G.leftFace(G.direct(a3,true)), G.leftFace(G. |
| 236 | direct(a3,false)), 2); |
| 237 | checkGraphCommonNodeList(G, G.leftFace(G.direct(a1,false)), G.leftFace(G. |
| 238 | direct(a2,true)), 1); |
| 239 | |
231 | 240 | } |
232 | 241 | |
233 | 242 | template <class Graph> |
diff -r 873b8d0104e7 -r ece0de9a63f8 test/planar_graph_test.h
a
|
b
|
|
141 | 141 | void checkGraphBoundaryArcList(const Graph &G, typename Graph::Face n, int |
142 | 142 | cnt) |
143 | 143 | { |
144 | | // std::cout << G.id(n) << ' '; |
145 | | // int alma = countBoundaryArcs(G,n); |
146 | | // std::cout << alma << ':'; |
147 | 144 | typename Graph::CwBoundaryArcIt e(G,n); |
148 | 145 | for(int i=0;i<cnt;i++) { |
149 | | // std::cout << ',' << G.id(e); |
150 | 146 | check(e!=INVALID,"Wrong CwBoundaryArc list linking."); |
151 | 147 | check(n==G.w1(e) || n==G.w2(e),"Wrong CwBoundaryArc list linking."); |
152 | 148 | ++e; |
153 | 149 | } |
154 | | // std::cout << std::endl; |
155 | 150 | check(e==INVALID,"Wrong BoundaryArc list linking."); |
156 | 151 | check(countBoundaryArcs(G,n)==cnt,"Wrong IncEdge number."); |
157 | 152 | } |
… |
… |
|
186 | 181 | check(2 * cnt == i, "Wrong iterator."); |
187 | 182 | } |
188 | 183 | |
| 184 | template<class Graph> |
| 185 | void checkGraphCommonNodeList(const Graph &G, typename Graph::Face f1, |
| 186 | typename Graph::Face f2, int cnt) |
| 187 | { |
| 188 | typename Graph::CommonNodesIt e(G,f1,f2); |
| 189 | for(int i=0;i<cnt;i++) { |
| 190 | check(e!=INVALID,"Wrong CommonNodeIt."); |
| 191 | ++e; |
| 192 | } |
| 193 | check(e==INVALID,"Wrong CommonNodeIt."); |
| 194 | } |
| 195 | |
| 196 | template<class Graph> |
| 197 | void checkGraphCommonFaceList(const Graph &G, typename Graph::Node n1, |
| 198 | typename Graph::Node n2, int cnt) |
| 199 | { |
| 200 | typename Graph::CommonFacesIt e(G,n1,n2); |
| 201 | for(int i=0;i<cnt;i++) { |
| 202 | check(e!=INVALID,"Wrong CommonNodeIt."); |
| 203 | ++e; |
| 204 | } |
| 205 | check(e==INVALID,"Wrong CommonNodeIt."); |
| 206 | } |
| 207 | |
189 | 208 | template <typename Graph> |
190 | 209 | void checkArcDirections(const Graph& G) { |
191 | 210 | for (typename Graph::ArcIt a(G); a != INVALID; ++a) { |