23 Allow sep to be absolute additive (margin of n points)
24 Increase less between tries
43 #define DFLT_overlap "9:prism"
45 #define WD2(n) (X_marg.doAdd ? (ND_width(n)/2.0 + X_marg.x): ND_width(n)*X_marg.x/2.0)
46 #define HT2(n) (X_marg.doAdd ? (ND_height(n)/2.0 + X_marg.y): ND_height(n)*X_marg.y/2.0)
57 static double X_nonov;
70 return sqrt(w * w + h * h);
80 xParams.
T0 = xpms->
T0;
84 K2 = xParams.
K * xParams.
K;
85 if (xParams.
T0 == 0.0)
86 xParams.
T0 = xParams.
K * sqrt(n) / 5;
90 fprintf(stderr,
"xLayout ");
92 fprintf(stderr,
" : n = %d K = %f T0 = %f loop %d C %f\n",
99 #define X_T0 xParams.T0
100 #define X_K xParams.K
101 #define X_numIters xParams.numIters
102 #define X_loopcnt xParams.loopcnt
103 #define X_C xParams.C
106 static double cool(
int t)
123 return (sqrt(dx * dx + dy * dy));
148 bBox(p, &p_ll, &p_ur);
149 bBox(q, &q_ll, &q_ur);
151 if (q_ll.
x > p_ur.
x) {
152 if (q_ll.
y > p_ur.
y) {
153 return (
dist(p_ur, q_ll));
154 }
else if (q_ll.
y >= p_ll.
y) {
155 return (q_ll.
x - p_ur.
x);
157 if (q_ur.
y >= p_ll.
y)
158 return (q_ll.
x - p_ur.
x);
162 return (
dist(p_ur, q_ll));
165 }
else if (q_ll.
x >= p_ll.
x) {
166 if (q_ll.
y > p_ur.
y) {
167 return (q_ll.
y - p_ur.
x);
168 }
else if (q_ll.
y >= p_ll.
y) {
171 if (q_ur.
y >= p_ll.
y)
174 return (p_ll.
y - q_ur.
y);
177 if (q_ll.
y > p_ur.
y) {
178 if (q_ur.
x >= p_ll.
x)
179 return (q_ll.
y - p_ur.
y);
183 return (
dist(p_ur, q_ll));
185 }
else if (q_ll.
y >= p_ll.
y) {
186 if (q_ur.
x >= p_ll.
x)
189 return (p_ll.
x - q_ur.
x);
191 if (q_ur.
x >= p_ll.
x) {
192 if (q_ur.
y >= p_ll.
y)
195 return (p_ll.
y - q_ur.
y);
197 if (q_ur.
y >= p_ll.
y)
198 return (p_ll.
x - q_ur.
x);
200 return (
dist(p_ll, q_ur));
213 double xdelta, ydelta;
222 ret = ((xdelta <= (
WD2(p) +
WD2(q))) && (ydelta <= (
HT2(p) +
HT2(q))));
225 double dist2, xdelta, ydelta;
228 din = RAD(p) + RAD(q);
231 dist2 = xdelta * xdelta + ydelta * ydelta;
232 return (dist2 <= (din * din));
239 static int cntOverlaps(
graph_t * g)
257 doRep(
node_t * p,
node_t * q,
double xdelta,
double ydelta,
double dist2)
262 #if defined(DEBUG) || defined(MS) || defined(ALT)
267 while (dist2 == 0.0) {
268 xdelta = 5 - rand() % 10;
269 ydelta = 5 - rand() % 10;
270 dist2 = xdelta * xdelta + ydelta * ydelta;
273 dout = boxDist(p, q);
277 force = K2 / (dout *
dist);
281 din = RAD(p) + RAD(q);
286 if (dist <= din +
X_K)
287 factor =
X_C * (
X_K - (dist - din)) /
X_K;
298 force = X_ov /
dist2;
300 force = X_nonov /
dist2;
306 fprintf(stderr,
" ov Fr %f dist %f\n", force * dist, dist);
309 DISP(q)[0] += xdelta * force;
310 DISP(q)[1] += ydelta * force;
311 DISP(p)[0] -= xdelta * force;
312 DISP(p)[1] -= ydelta * force;
322 double xdelta, ydelta;
326 return doRep(p, q, xdelta, ydelta, xdelta * xdelta + ydelta * ydelta);
331 double xdelta, ydelta;
338 dout = boxDist(p, q);
343 dist = sqrt(xdelta * xdelta + ydelta * ydelta);
344 force = (dout * dout) / (
X_K * dist);
348 dist = sqrt(xdelta * xdelta + ydelta * ydelta);
349 din = RAD(p) + RAD(q);
350 if (dist <
X_K + din)
353 force = (dout * dout) / ((
X_K + din) *
dist);
359 fprintf(stderr,
"ov 1 Fa 0 din %f\n", RAD(p) + RAD(q));
366 dist = sqrt(xdelta * xdelta + ydelta * ydelta);
367 din = RAD(p) + RAD(q);
369 force = (dout * dout) / ((
X_K + din) *
dist);
374 fprintf(stderr,
" ov 0 Fa %f din %f \n", force * dist, din);
377 DISP(q)[0] -= xdelta * force;
378 DISP(q)[1] -= ydelta * force;
379 DISP(p)[0] += xdelta * force;
380 DISP(p)[1] += ydelta * force;
387 static int adjust(
Agraph_t * g,
double temp)
400 fprintf(stderr,
"=================\n");
404 DISP(n)[0] = DISP(n)[1] = 0;
410 ov = applyRep(n, n1);
426 disp[0] = DISP(n)[0];
427 disp[1] = DISP(n)[1];
428 len2 = disp[0] * disp[0] + disp[1] * disp[1];
436 ND_pos(n)[0] += (disp[0] * temp) / len;
437 ND_pos(n)[1] += (disp[1] * temp) / len;
478 while (ov && (
try < tries)) {
479 xinit_params(g, nnodes, &xpms);
481 X_nonov = (nedges*X_ov*2.0)/(nnodes*(nnodes-1));
485 fprintf(stderr,
"try %d (%d): %d overlaps on ",
try, tries, ov);
487 fprintf(stderr,
" \n");
495 ov = adjust(g, temp);
504 fprintf(stderr,
"Warning: %d overlaps remain on ", ov);
506 fprintf(stderr,
"\n");
528 char* ovlp =
agget (g,
"overlap");
536 fprintf (stderr,
"xLayout ");
538 if (!ovlp || (*ovlp ==
'\0')) {
542 if ((cp = strchr(ovlp,
':')) && ((cp == ovlp) || isdigit(*ovlp))) {
546 if (tries < 0) tries = 0;
556 fprintf (stderr,
"tries = %d, mode = %s\n", tries, rest);
558 if (tries && !x_layout(g, xpms, tries))
expand_t sepFactor(graph_t *g)
void pr2graphs(Agraph_t *g0, Agraph_t *g1)
CGRAPH_API Agraph_t * agroot(void *obj)
CGRAPH_API Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
#define PS2INCH(a_points)
char * agget(void *obj, char *name)
int removeOverlapAs(graph_t *G, char *flag)
CGRAPH_API Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
CGRAPH_API Agnode_t * aghead(Agedge_t *e)
CGRAPH_API char * agnameof(void *)
CGRAPH_API Agnode_t * agfstnode(Agraph_t *g)
COORD dist2(Ppoint_t, Ppoint_t)
void fdp_xLayout(graph_t *g, xparams *xpms)
EXTERN unsigned char Verbose
CGRAPH_API int agnnodes(Agraph_t *g)
CGRAPH_API int agnedges(Agraph_t *g)
double dist(Site *s, Site *t)
CGRAPH_API Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)