4
#include <stdio.h> /* temporary for debugging */
21
static Ppoint_t cvt2Ppoint(ilcoord_t p) {Ppoint_t rv; rv.x = p.x; rv.y = p.y; return rv;}
23
static ilcurve_t *cvt2ilcurve(Ppolyline_t spline)
28
rv = il_newcurve(vmregion(spline.ps), IL_SPLINE, spline.pn);
29
for (i = 0; i < spline.pn; i++) {
30
rv->p[i].x = spline.ps[i].x;
31
rv->p[i].y = spline.ps[i].y;
37
static polylist buildpolylist(ILview_t *view)
40
int i, pi, nnodes, sides;
47
nnodes = agnnodes(ilmodel(view));
48
obs = malloc(nnodes * sizeof(obs[0]));
49
lst = malloc(nnodes * sizeof(lst[0]));
51
adj = drand48() * 0.01;
52
nspec = NIL(ILnode_t*);
53
while ((nspec = ilnextnode(view,nspec))) {
54
for (shape = nspec->shape; shape; shape = shape->next) {
55
if (shape->type == IL_POLYGON)
56
sides = shape->def.curve.n;
57
else /* assume ellipse */
62
obs[i].ps = vmalloc(agheap(ilmodel(view)),sizeof(Ppoint_t)*obs[i].pn);
63
cntr.x = cntr.y = 0.0;
64
if (shape->type == IL_POLYGON) {
65
for (pi = 0; pi < obs[i].pn; pi++) {
66
cntr.x += shape->def.curve.p[pi].x;
67
cntr.y += shape->def.curve.p[pi].y;
69
cntr.x = cntr.x / obs[i].pn;
70
cntr.y = cntr.y / obs[i].pn;
73
for (pi = 0; pi < obs[i].pn; pi++) {
74
if (shape->type == IL_POLYGON) {
75
obs[i].ps[pi].x = nspec->pos.x + 1.1 * shape->def.curve.p[pi].x;
76
obs[i].ps[pi].y = nspec->pos.y + 1.1 * shape->def.curve.p[pi].y;
80
c = cos(2.0 * M_PI * pi / sides + adj);
81
s = sin(2.0 * M_PI * pi / sides + adj);
82
obs[i].ps[pi].x = nspec->pos.x + c * 1.1 * shape->def.ellipse.radius_a;
83
obs[i].ps[pi].y = nspec->pos.y + c * 1.1 * shape->def.ellipse.radius_b;
96
static int horrible_find_polyid(ILview_t *view, ILnode_t *target)
101
nspec = NIL(ILnode_t*);
103
while ((nspec = ilnextnode(view,nspec))) {
104
if (nspec == target) return i;
110
static void route_edges_of(ILview_t *view, Agraph_t *subg)
116
Ppolyline_t polyline;
118
ilcurve_t *unclipped;
119
ilcurve_t *clipped_spline;
121
Pvector_t endslope[2];
127
vc = NIL(vconfig_t*);
128
for (n = agfstnode(subg); n; n = agnxtnode(n)) {
129
for (e = agfstout(n); e; e = agnxtout(e)) {
130
if (vc == NIL(vconfig_t*)) {
131
obs = buildpolylist(view);
132
vc = Pobsopen(obs.list, obs.n);
133
(void) Ppolybarriers(obs.list, obs.n, &barriers.list, &barriers.n);
137
tl= ((ILnode_t*)(espec->tail.term));
138
hd = ((ILnode_t*)(espec->head.term));
139
p[0] = cvt2Ppoint(tl->pos);
140
p[1] = cvt2Ppoint(hd->pos);
141
endslope[0].x = endslope[0].y = 0.0;
142
endslope[1].x = endslope[1].y = 0.0;
144
/* when erg fixes Pobspath, this will be unnecessary */
145
id0 = horrible_find_polyid(view,tl);
146
id1 = horrible_find_polyid(view,hd);
147
Pobspath(vc, p[0], id0, p[1], id1, &polyline);
148
(void) Proutespline(barriers.list, barriers.n, polyline, endslope, &spline);
149
unclipped = cvt2ilcurve(spline);
150
clipped_spline = il_clip_endpoints(view->pvt,unclipped,tl,hd);
154
fprintf(stderr,"0 1 0 setrgbcolor\nnewpath");
155
for (i = 0; i < clipped_spline->n; i++) {
156
fprintf(stderr," %.3lf %.3lf",
157
clipped_spline->p[i].x,clipped_spline->p[i].y);
158
if (i == 0) fprintf(stderr," moveto");
159
else if (i % 3 == 0) fprintf(stderr," curveto");
161
fprintf(stderr," stroke\n");
164
if (espec->pos) il_freeshape(vmregion(espec->pos),espec->pos);
165
espec->pos = il_newshape(agheap(ilmodel(view)),clipped_spline,NIL(ilshape_t*));
171
#include <sys/time.h>
172
#include <sys/resource.h>
175
void ilroutem(ILview_t *view)
179
struct rusage ru0, ru1;
180
getrusage(RUSAGE_SELF, &ru0);
183
route_edges_of(view,view->pvt->model.e[IL_INS]);
184
route_edges_of(view,view->pvt->model.e[IL_MOD]);
186
getrusage(RUSAGE_SELF, &ru1);
187
fprintf(stderr,"%% timing %d usecs\n",
188
ru1.ru_utime.tv_usec - ru0.ru_utime.tv_usec);