/* constrainX: * Create the X constrains and solve. We use a linear objective function * (absolute values rather than squares), so we can reuse network simplex. * The constraints are encoded as a dag with edges having a minimum length. */ static void constrainX(graph_t* g, nitem* nlist, int nnodes, intersectfn ifn, int ortho) { Dt_t *list = dtopen(&constr, Dtobag); nitem *p = nlist; graph_t *cg; int i; for (i = 0; i < nnodes; i++) { p->val = p->pos.x; dtinsert(list, p); p++; } if (ortho) cg = mkConstraintG(g, list, ifn, distX); else cg = mkNConstraintG(g, list, ifn, distX); rank(cg, 2, INT_MAX); p = nlist; for (i = 0; i < nnodes; i++) { int newpos, oldpos, delta; oldpos = p->pos.x; newpos = ND_rank(p->cnode); delta = newpos - oldpos; p->pos.x = newpos; p->bb.LL.x += delta; p->bb.UR.x += delta; p++; } closeGraph(cg); dtclose(list); }
/* constrainY: * See constrainX. */ static void constrainY(graph_t* g, nitem* nlist, int nnodes, intersectfn ifn, int ortho) { Dt_t *list = dtopen(&constr, Dtobag); nitem *p = nlist; graph_t *cg; int i; for (i = 0; i < nnodes; i++) { p->val = p->pos.y; dtinsert(list, p); p++; } if (ortho) cg = mkConstraintG(g, list, ifn, distY); else cg = mkNConstraintG(g, list, ifn, distY); rank(cg, 2, INT_MAX); #ifdef DEBUG { Agsym_t *mlsym = agedgeattr(cg, "minlen", ""); Agsym_t *rksym = agnodeattr(cg, "rank", ""); char buf[100]; node_t *n; edge_t *e; for (n = agfstnode(cg); n; n = agnxtnode(cg, n)) { sprintf(buf, "%d", ND_rank(n)); agxset(n, rksym->index, buf); for (e = agfstedge(cg, n); e; e = agnxtedge(cg, e, n)) { sprintf(buf, "%d", ED_minlen(e)); agxset(e, mlsym->index, buf); } } } #endif p = nlist; for (i = 0; i < nnodes; i++) { int newpos, oldpos, delta; oldpos = p->pos.y; newpos = ND_rank(p->cnode); delta = newpos - oldpos; p->pos.y = newpos; p->bb.LL.y += delta; p->bb.UR.y += delta; p++; } closeGraph(cg); dtclose(list); }
static void constrainX (graph_t * g, nitem * nlist, int nnodes, intersectfn ifn, int ortho) { Dt_t *list = dtopen (&constr, Dtobag); nitem *p = nlist; graph_t *cg; int i; for (i = 0; i < nnodes; i++) { (*(((Dt_t *) (list))->searchf)) ((list), (void *) (p), 0000001); p++; } if (ortho) cg = mkConstraintG (g, list, ifn, distX); else cg = mkNConstraintG (g, list, ifn, distX); }