# HG changeset patch
# User gyorokp
# Date 1269167256 -3600
# Node ID ab0782f0c79f5dcc1418a27fa9b0b1c5255ba21c
# Parent  a58356e448fd457162c2365cb57e66cb106f079d
Added constructors PlanarGraph(PlanarEmbedding) and PlaneGraph(PlanarDrawing)

diff -r a58356e448fd -r ab0782f0c79f lemon/planar_graph.h
--- a/lemon/planar_graph.h	Sat Mar 20 16:35:27 2010 +0100
+++ b/lemon/planar_graph.h	Sun Mar 21 11:27:36 2010 +0100
@@ -26,6 +26,7 @@
 #include <lemon/core.h>
 #include <lemon/error.h>
 #include <lemon/bits/graph_extender.h>
+#include <lemon/planarity.h>
 
 #include <vector>
 #include <list>
@@ -1285,6 +1286,42 @@
     ///
     PlanarGraph() {}
 
+    ///\brief Constructor that copies a planar embedding
+
+    ///Constructor that copies a planar embedding.
+    template<typename Graph>
+    PlanarGraph(const Graph &g, const lemon::PlanarEmbedding<Graph> &em) {
+      typename Graph::template NodeMap<Node> nm(g);
+      typename Graph::template ArcMap<Arc> am(g);
+      for (typename Graph::NodeIt it(g); it != INVALID; ++it) {
+        nm[it] = addNode();
+      }
+      for (typename Graph::ArcIt it(g); it != INVALID; ++it) {
+        am[it] = INVALID;
+      }
+      for (typename Graph::ArcIt it(g); it != INVALID; ++it) {
+        am[it] = INVALID;
+      }
+      for (typename Graph::NodeIt it(g); it != INVALID; ++it) {
+        for (typename Graph::OutArcIt it2(g,it); it2 != INVALID; ++it2) {
+          if (am[it2] == INVALID) {
+            typename Graph::Arc p_u = em.next(it2);
+            while (am[p_u] == INVALID && it2 != p_u) {
+              p_u = em.next(p_u);
+            }
+            typename Graph::Arc ra = g.oppositeArc(it2);
+            typename Graph::Arc p_v = em.next(ra);
+            while (am[p_v] == INVALID && ra != p_v) {
+              p_v = em.next(p_v);
+            }
+            am[it2] = direct(addEdge(nm[g.source(it2)],nm[g.target(it2)],
+                    am[p_u],am[p_v]),nm[g.source(it2)]);
+            am[g.oppositeArc(it2)] = oppositeArc(am[it2]);
+          }
+        }
+      }
+    }
+
     typedef Parent::OutArcIt IncEdgeIt;
 
     /// \brief Add a new node to the graph.
diff -r a58356e448fd -r ab0782f0c79f lemon/plane_graph.h
--- a/lemon/plane_graph.h	Sat Mar 20 16:35:27 2010 +0100
+++ b/lemon/plane_graph.h	Sun Mar 21 11:27:36 2010 +0100
@@ -23,6 +23,7 @@
 ///\file
 ///\brief PlaneGraph classes. UNDER CONSTRUCTION.
 
+#include <lemon/planarity.h>
 #include <lemon/planar_graph.h>
 #include <lemon/dim2.h>
 #include <cmath>
@@ -54,6 +55,21 @@
     ///Constructor.
     PlaneGraph() : nodepos(*this) {}
 
+    ///\brief Constructor that copies a planar drawing
+
+    ///Constructor that copies a planar drawing.
+    template<typename Graph>
+    PlaneGraph(const Graph &graph, const lemon::PlanarDrawing<Graph> &drawing) :
+      nodepos(*this) {
+        typename Graph::template NodeMap<Node> nm(graph);
+        for (typename Graph::NodeIt it(graph); it != INVALID; ++it) {
+          nm[it] = addNode(drawing[it]);
+        }
+        for (typename Graph::EdgeIt it(graph); it != INVALID; ++it) {
+          addEdge(nm[graph.u(it)], nm[graph.v(it)]);
+        }
+    }
+
     ///Add a new node to the graph.
 
     ///PlaneGraph doesn't support this method. Use the overload that takes a
@@ -64,7 +80,7 @@
 
     ///PlaneGraph doesn't support this method. Use the overload that takes only
     ///two node parameters.
-    Arc addEdge(Node, Node, Arc, Arc) = delete;
+    Edge addEdge(Node, Node, Arc, Arc) = delete;
 
     ///Add a new node to the graph.
 
