-
Notifications
You must be signed in to change notification settings - Fork 0
/
embedding_demo.4.py
69 lines (49 loc) · 1.93 KB
/
embedding_demo.4.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
''' embedding_demo.py '''
import io
#include "util.py"
#include "undirected_graph.py"
#include "ps.py"
def print_to_string(*args, **kwargs):
output = io.StringIO()
print(*args, file=output, **kwargs)
contents = output.getvalue()
output.close()
return contents
ps = ps()
K4me = [[1, 2], [2, 0, 3], [0, 3, 1], [1, 2]]
K4noemb = [[3, 1, 2], [2, 0, 3], [0, 3, 1], [1, 2, 0]]
F = [ K4me, K4noemb ]
acoords = [ [[0.5, 0, -0.3, 0.7], [-0.8, 0.9, -0.8, -0.6]], [[0.9,0,-0.9,0.8], [-0.8,0.9,-0.8,0]] ]
def draw(x):
coords = acoords[x]
G = from_adjacency_list(F[x])
size = 592
r = 12
da = 15
ps.set_(size, r)
ps.straight_line_drawing(G, coords, [], size, r, [], False)
def draw_vertex_edge_label(G, v, e, l):
w = opposite(G, v, e)
cx = (ps.scrx(coords[0][v]) + ps.scrx(coords[0][w])) / 2
cy = (ps.scry(coords[1][v]) + ps.scry(coords[1][w])) / 2
deg = ps.r2d(math.atan2(coords[1][v] - coords[1][w], coords[0][w] - coords[0][v]))
print("12 " + ps.frm(deg) + " (" + l + ") " +
ps.frm(cx) + " " + ps.frm(cy) + " txtdistdeg")
ps.vertex_indicator(G, v, e, coords, r, da)
r = 18
last_face = [-1]
cnt = [-1]
pftv = planar_face_traversal_visitor()
pftv.begin_face = lambda: (incr(last_face), aset(cnt,0))
pftv.next_vertex_edge = lambda v, e: (draw_vertex_edge_label(G, v, e,
str(last_face[0])+"_"+chr(97+cnt[0])),
incr(cnt))
planar_face_traversal(G, pftv)
print("0 0 (is_embedding=" + str(is_embedding(G)) + ",")
print(" n_faces_planar=" + str(n_faces_planar(G)) + ",")
print(" traversed faces=" + str(last_face[0]+1) +") 300 20 txtdistdeg")
print(r"0 0 (from_adjacency_list( " + print_to_string(F[x], end="") + r" )) 300 570 txtdistdeg")
print("showpage")
ps.header()
ps.header2()
draw(0)