From 4276f5773e501be12a3fbabf179ca95fbf031ad1 Mon Sep 17 00:00:00 2001 From: erg Date: Thu, 17 Feb 2005 15:34:31 +0000 Subject: [PATCH] Unify code for getting expansion factor for overlap removal and spline routing; move some verbose messages lesser importance; separate node overlap removal into getting the parameter and applying it to allow fdp to use a prefix on "overlap" for 2 passes; fix some warnings. --- lib/neatogen/adjust.c | 58 ++++++++++++++++++++++++++------------- lib/neatogen/adjust.h | 2 ++ lib/neatogen/constraint.c | 30 ++++++-------------- 3 files changed, 50 insertions(+), 40 deletions(-) diff --git a/lib/neatogen/adjust.c b/lib/neatogen/adjust.c index b79958628..ee3c787dd 100644 --- a/lib/neatogen/adjust.c +++ b/lib/neatogen/adjust.c @@ -145,7 +145,6 @@ static void makeInfo(Agraph_t * graph) Agnode_t *node; int i; Info_t *ip; - char *marg; nsites = agnnodes(graph); geominit(); @@ -155,18 +154,7 @@ static void makeInfo(Agraph_t * graph) node = agfstnode(graph); ip = nodeInfo; -#ifdef OLD - marg = agget(graph, "voro_pmargin"); - if (marg && (*marg != '\0')) { - pmargin = atof(marg); - } -#else - if ((marg = agget(graph, "sep"))) { - pmargin = 1.0 + atof(marg); - } else - pmargin = 1.01; -#endif - + pmargin = expFactor (graph); for (i = 0; i < nsites; i++) { ip->site.coord.x = ND_pos(node)[0]; ip->site.coord.y = ND_pos(node)[1]; @@ -602,7 +590,7 @@ static int sAdjust() int overlapCnt = 0; int cnt; Point center; - double sc; + /* double sc; */ if (!useIter || (iterations > 0)) overlapCnt = countOverlap(iterCnt); @@ -614,7 +602,7 @@ static int sAdjust() center.x = (pxmin + pxmax) / 2.0; center.y = (pymin + pymax) / 2.0; while (1) { - sc = rePos(center); + /* sc = */ rePos(center); iterCnt++; if (useIter && (iterCnt == iterations)) @@ -714,9 +702,14 @@ static adjust_data adjustMode[] = { {AM_NONE, 0, 0} }; +/* getAdjustMode: + * Convert string value to internal value of adjustment mode. + * Assume s != NULL. + */ static adjust_data *getAdjustMode(char *s) { adjust_data *ap = adjustMode + 2; + if (*s == '\0') return adjustMode; while (ap->attrib) { if (!strcasecmp(s, ap->attrib)) return ap; @@ -728,10 +721,14 @@ static adjust_data *getAdjustMode(char *s) return adjustMode + 1; } -void removeOverlap(graph_t * G) +/* removeOverlapAs: + * Use flag value to determine if and how to remove + * node overlaps. + */ +void +removeOverlapAs(graph_t * G, char* flag) { /* int userWindow = 0; */ - char *flag; int ret; extern void cAdjust(graph_t *, int); extern void scAdjust(graph_t *, int); @@ -741,7 +738,6 @@ void removeOverlap(graph_t * G) if (agnnodes(G) < 2) return; - flag = agget(G, "overlap"); if (flag == NULL) return; @@ -750,7 +746,7 @@ void removeOverlap(graph_t * G) return; if (Verbose) - fprintf(stderr, "Adjusting nodes using %s\n", am->print); + fprintf(stderr, "Adjusting %s using %s\n", G->name, am->print); if (am->mode > AM_SCALE) { /* start_timer(); */ @@ -805,6 +801,14 @@ void removeOverlap(graph_t * G) } +/* removeOverlap: + */ +void +removeOverlap(graph_t * G) +{ + removeOverlapAs(G, agget(G, "overlap")); +} + void adjustNodes(graph_t * G) { if (agnnodes(G) < 2) @@ -813,3 +817,19 @@ void adjustNodes(graph_t * G) removeOverlap (G); } +/* expFactor: + * Return factor by which to scale up nodes. + */ +double +expFactor(graph_t* g) +{ + double pmargin; + char* marg; + + if ((marg = agget(g, "sep"))) { + pmargin = 1.0 + atof(marg); + } else + pmargin = 1.01; + return pmargin; +} + diff --git a/lib/neatogen/adjust.h b/lib/neatogen/adjust.h index 4168e8c9b..5b41685f9 100644 --- a/lib/neatogen/adjust.h +++ b/lib/neatogen/adjust.h @@ -23,9 +23,11 @@ extern "C" { #endif + extern double expFactor(graph_t * G); extern void adjustNodes(graph_t * G); extern void normalize(graph_t * g); extern void removeOverlap(graph_t * G); + extern void removeOverlapAs(graph_t*, char*); #ifdef __cplusplus } diff --git a/lib/neatogen/constraint.c b/lib/neatogen/constraint.c index 885aa6e08..a3eda101d 100644 --- a/lib/neatogen/constraint.c +++ b/lib/neatogen/constraint.c @@ -20,7 +20,7 @@ #endif #include "neato.h" -/* #include "utils.h" */ +#include "adjust.h" #define SCALE 10 #define SCALE2 (SCALE/2) @@ -133,7 +133,9 @@ static graph_t *mkConstraintG(graph_t * g, Dt_t * list, edge_t *e; int lcnt, cnt; int oldval = -MAXINT; +#ifdef OLD double root_val; +#endif node_t *lastn = NULL; /* count distinct nodes */ @@ -161,7 +163,9 @@ static graph_t *mkConstraintG(graph_t * g, Dt_t * list, lastn = n; } else { root = n; +#ifdef OLD root_val = p->val; +#endif lastn = GD_nlist(cg) = n; } alloc_elist(lcnt, ND_in(n)); @@ -400,21 +404,13 @@ static void initItem(node_t * n, nitem * p, double margin) */ void cAdjust(graph_t * g, int xy) { - char *marg; - double margin = 0; + double margin; int i, nnodes = agnnodes(g); nitem *nlist = N_GNEW(nnodes, nitem); nitem *p = nlist; node_t *n; - marg = agget(g, "sep"); - if (marg && *marg) { - margin = atof(marg); - if (margin > 0) - margin += 1.0; - } - if (margin == 0.0) - margin = 1.01; + margin = expFactor (g); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { initItem(n, p, margin); @@ -610,19 +606,11 @@ void scAdjust(graph_t * g, int equal) node_t *n; pointf s; int i; - char *marg; - double margin = 0; + double margin; pointf *aarr; int m; - marg = agget(g, "sep"); - if (marg && *marg) { - margin = atof(marg); - if (margin > 0) - margin += 1.0; - } - if (margin == 0.0) - margin = 1.02; + margin = expFactor (g); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { double w2 = margin * ND_width(n) / 2.0; -- 2.40.0