-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplanar.cpp
42 lines (33 loc) · 920 Bytes
/
planar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "algo.h"
#include <lemon/planarity.h>
#include <lemon/math.h>
#include <lemon/graph_to_eps.h>
#include <lemon/list_graph.h>
#include <vector>
using namespace lemon;
bool algo::drawPlanar(graph& g) {
if (g.size < 3) {
return false;
}
typedef ListGraph::Node Node;
ListGraph lgraph;
std::vector<Node> nodes;
for (int i = 0; i < g.size; i++) {
nodes.push_back(lgraph.addNode());
}
for (auto edge : g.edges) {
lgraph.addEdge(nodes[edge.first], nodes[edge.second]);
}
PlanarEmbedding<ListGraph> embedding(lgraph);
if (!embedding.run(false)) {
return false;
}
PlanarDrawing<ListGraph> drawing(lgraph);
drawing.run(embedding.embeddingMap());
for (int i = 0; i < g.size; i++) {
double x = drawing[nodes[i]].x;
double y = drawing[nodes[i]].y;
g.positions[i] = { x, y };
}
return true;
}