-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.convex_face_straight_line_drawing.js
124 lines (104 loc) · 2.69 KB
/
node.convex_face_straight_line_drawing.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
#include "assert.js"
#include "util.js"
#include "gauss-jordan.js"
#include "undirected_graph.js"
#include "tutte.js"
#include "ps.js"
#include "fullerenes.js"
var G;
var K4 = [[1, 3, 2], [2, 3, 0], [0, 3, 1], [0, 1, 2]];
var K4noemb = [[3, 1, 2], [2, 0, 3], [0, 3, 1], [0, 1, 2]];
var coords;
function doi(x) {
var e;
G = from_adjacency_list(F[x]);
assert.assert(is_embedding(G));
e = (
(n_edges(G) > 9)
? 9
: any_edge(G)
);
doit(G, source(G, e), e);
}
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;
ps.set_(size, r)
var visited = filled_array(n_edges(G), 2, false);
var face = [];
var deg;
traverse_face(G, visited, v, e, ind(G, v, e), {next_vertex: function (v) {
face.push(v);
}});
assert.assert(face.length > 0);
coords = tutte.convex_face_coordinates(G, face, slider / 100.0);
forall_edges(G, function (e) {
v = source(G, e);
w = target(G, e);
cx = scrx(coords[0][v]);
cy = scry(coords[1][v]);
dx = scrx(coords[0][w]);
dy = 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.straight_line_drawing(G, coords, pent, size, r, (
(face.length === 5)
? face
: []
), false);
forall_edges(G, function (e) {
v = source(G, e);
w = target(G, e);
cx = (scrx(coords[0][v]) + scrx(coords[0][w])) / 2;
cy = (scry(coords[1][v]) + scry(coords[1][w])) / 2;
console.log("() 1 " + frm(cx) + " " + frm(cy) + " vertex");
deg = ps.r2d(Math.atan2(coords[1][v] - coords[1][w], coords[0][w] - coords[0][v]));
console.log("9 " + frm(deg) + " (" + e + ") " + frm(cx) + " " + frm(cy) + " txtdistdeg");
});
console.log("showpage");
}
doi(2);