-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.convex_face_straight_line_drawing.2.js
151 lines (128 loc) · 3.21 KB
/
node.convex_face_straight_line_drawing.2.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "assert.js"
#include "util.js"
#include "gauss-jordan.js"
#include "undirected_graph.js"
#include "tutte.js"
#include "ps.js"
var sel = (
(process.argv.length > 2)
? process.argv[2]
: "graphs/C30.a"
);
var dual = false;
var arrows = true;
var print = false;
if (process.argv.length > 3) {
dual = process.argv[3].includes("d");
arrows = !process.argv[3].includes("n");
print = process.argv[3].includes("p");
}
var G;
function doi(x) {
var e;
var L;
L = parse2file(x);
G = from_adjacency_list(L);
if (dual) {
assert.assert(is_embedding(G));
G = dual_graph(G);
}
assert.assert(is_embedding(G));
e = (
(n_edges(G) > 9)
? 9
: any_edge(G)
);
doit(G, source(G, e), e);
if (print) {
print_graph(G);
}
}
function doit(G, v, e) {
var slider = 100;
var slider2 = 592;
var selInd = 0;
var size = slider2;
var r = 12;
var pent;
var spl = -1;
var tst;
var lmin = 99999;
var lcur;
var cx;
var cy;
var dx;
var dy;
var w;
var visited = filled_array(n_edges(G), 2, false);
var face = [];
var deg;
var last_face;
ps.set_(size, r);
traverse_face(G, visited, v, e, ind(G, v, e), {next_vertex: function (v) {
face.push(v);
}});
assert.assert(face.length > 0);
var coords = tutte.convex_face_coordinates(G, face, slider / 100.0);
forall_edges(G, function (e) {
v = source(G, e);
w = target(G, e);
cx = ps.scrx(coords[0][v]);
cy = ps.scry(coords[1][v]);
dx = ps.scrx(coords[0][w]);
dy = ps.scry(coords[1][w]);
dx -= cx;
dy -= cy;
lcur = Math.sqrt(dx * dx + dy * dy);
if (lcur < lmin) {
lmin = lcur;
}
});
if (lmin < 2 * r + 2) {
r = lmin / 3;
ps.set_(size, r);
}
pent = pentagons(G);
if (face.length === 5) {
tst = filled_array(n_vertices(G), 1, false);
face.forEach(function (v) {
tst[v] = true;
});
pent.forEach(function (c, i) {
var good = true;
c.forEach(function (v) {
if (!tst[v]) {
good = false;
}
});
if (good) {
spl = i;
}
});
if (spl !== -1) {
pent.splice(spl, 1);
}
}
ps.header();
ps.header2();
ps.straight_line_drawing(G, coords, pent, size, r, (
(face.length === 5)
? face
: []
), false);
if (arrows) {
last_face = -1;
planar_face_traversal(G, {begin_face: function () {
last_face += 1;
}, next_vertex_edge: function (v, e) {
var rgb = ["0 0 1", "0 1 0", "1 0 0", "0.5 0.5 1"];
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]));
console.log("15 15 " + rgb[last_face % rgb.length] + " " + ps.frm(deg) + " " + ps.frm(cx) + " " + ps.frm(cy) + " parrow");
}});
}
console.log("showpage");
}
doi(sel);