~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to incr/routem.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <engine.h>
 
2
#include <pathplan.h>
 
3
#include <vispath.h>
 
4
#include <stdio.h>      /* temporary for debugging */
 
5
#include <math.h>
 
6
 
 
7
#ifdef DMALLOC
 
8
#include "dmalloc.h"
 
9
#endif
 
10
 
 
11
typedef struct {
 
12
        Ppoly_t **list;
 
13
        int             n;
 
14
} polylist;
 
15
 
 
16
typedef struct {
 
17
        Pedge_t *list;
 
18
        int             n;
 
19
} seglist;
 
20
 
 
21
static Ppoint_t cvt2Ppoint(ilcoord_t p) {Ppoint_t rv; rv.x = p.x; rv.y = p.y; return rv;}
 
22
 
 
23
static ilcurve_t *cvt2ilcurve(Ppolyline_t spline)
 
24
{
 
25
        ilcurve_t       *rv;
 
26
        int                     i;
 
27
 
 
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;
 
32
        }
 
33
        rv->n = spline.pn;
 
34
        return rv;
 
35
}
 
36
 
 
37
static polylist buildpolylist(ILview_t *view)
 
38
{
 
39
        Ppoly_t         *obs,**lst;
 
40
        int                     i, pi, nnodes, sides;
 
41
        ILnode_t        *nspec;
 
42
        ilshape_t       *shape;
 
43
        polylist        rv;
 
44
        Ppoint_t        cntr;
 
45
        double          adj;
 
46
 
 
47
        nnodes = agnnodes(ilmodel(view));
 
48
        obs = malloc(nnodes * sizeof(obs[0]));
 
49
        lst = malloc(nnodes * sizeof(lst[0]));
 
50
        i = 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 */
 
58
                                sides = 8; /* ha */
 
59
 
 
60
                        lst[i] = &(obs[i]);
 
61
                        obs[i].pn = sides;
 
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;
 
68
                                }
 
69
                                cntr.x = cntr.x /  obs[i].pn;
 
70
                                cntr.y = cntr.y /  obs[i].pn;
 
71
                        }
 
72
 
 
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;
 
77
                                }
 
78
                                else {
 
79
                                        double  c, s;
 
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;
 
84
                                }
 
85
                        }
 
86
                        i++;
 
87
                        break;
 
88
                }
 
89
        }
 
90
        assert(i == nnodes);
 
91
        rv.list = lst;
 
92
        rv.n = nnodes;
 
93
        return rv;
 
94
}
 
95
 
 
96
static int horrible_find_polyid(ILview_t *view, ILnode_t *target)
 
97
{
 
98
        ILnode_t        *nspec;
 
99
        int                     i;
 
100
 
 
101
        nspec = NIL(ILnode_t*);
 
102
        i = 0;
 
103
        while ((nspec = ilnextnode(view,nspec))) {
 
104
                if (nspec == target) return i;
 
105
                i++;
 
106
        }
 
107
        return POLYID_NONE;
 
108
}
 
109
 
 
110
static void route_edges_of(ILview_t *view, Agraph_t *subg)
 
111
{
 
112
        Agnode_t        *n;
 
113
        Agedge_t        *e;
 
114
        ILnode_t        *tl, *hd;
 
115
        polylist        obs;
 
116
        Ppolyline_t     polyline;
 
117
        Ppolyline_t     spline;
 
118
        ilcurve_t       *unclipped;
 
119
        ilcurve_t       *clipped_spline;
 
120
        Ppoint_t        p[2];
 
121
        Pvector_t       endslope[2];
 
122
        ILedge_t        *espec;
 
123
        seglist         barriers;
 
124
        vconfig_t       *vc;
 
125
        int             id0,id1;
 
126
 
 
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);
 
134
                        }
 
135
 
 
136
                        espec = il_edge(e);
 
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;
 
143
 
 
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);
 
151
 
 
152
#if 0
 
153
{int i;
 
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");
 
160
        }
 
161
        fprintf(stderr," stroke\n");
 
162
}
 
163
#endif
 
164
                        if (espec->pos) il_freeshape(vmregion(espec->pos),espec->pos);      
 
165
                        espec->pos = il_newshape(agheap(ilmodel(view)),clipped_spline,NIL(ilshape_t*));
 
166
                }
 
167
        }
 
168
}
 
169
 
 
170
#ifdef TIMING
 
171
#include <sys/time.h>
 
172
#include <sys/resource.h>
 
173
#endif
 
174
 
 
175
void ilroutem(ILview_t *view)
 
176
{
 
177
 
 
178
#ifdef TIMING
 
179
struct rusage ru0, ru1;
 
180
        getrusage(RUSAGE_SELF, &ru0);
 
181
#endif
 
182
 
 
183
        route_edges_of(view,view->pvt->model.e[IL_INS]);
 
184
        route_edges_of(view,view->pvt->model.e[IL_MOD]);
 
185
#ifdef TIMING
 
186
        getrusage(RUSAGE_SELF, &ru1);
 
187
        fprintf(stderr,"%% timing %d usecs\n",
 
188
                ru1.ru_utime.tv_usec - ru0.ru_utime.tv_usec);
 
189
#endif
 
190
}