From: tgdwyer Date: Mon, 17 Jul 2006 02:25:52 +0000 (+0000) Subject: Constraints are now properly divided up between the connected components X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7201e2073c415e91642d7704773ab7e0c24b7654;p=inkscape.git Constraints are now properly divided up between the connected components --- diff --git a/src/graphlayout/graphlayout.cpp b/src/graphlayout/graphlayout.cpp index 72c47d9bf..ec5c780c7 100644 --- a/src/graphlayout/graphlayout.cpp +++ b/src/graphlayout/graphlayout.cpp @@ -91,7 +91,7 @@ void graphlayout(GSList const *const items) { rs.push_back(new Rectangle(ll[0],ur[0],ll[1],ur[1])); } - SimpleConstraints scy; + SimpleConstraints scx,scy; double ideal_connector_length = prefs_get_double_attribute("tools.connector","length",100); double directed_edge_height_modifier = 1.0; gchar const *directed_str = NULL, *overlaps_str = NULL; @@ -154,7 +154,7 @@ void graphlayout(GSList const *const items) { double eweights[E]; fill(eweights,eweights+E,1); vector cs; - connectedComponents(rs,es,cs); + connectedComponents(rs,es,scx,scy,cs); for(unsigned i=0;irects,c->edges,eweights,ideal_connector_length); alg.setupConstraints(NULL,NULL,avoid_overlaps, - NULL,NULL,NULL,&scy,NULL,NULL); + NULL,NULL,&c->scx,&c->scy,NULL,NULL); alg.run(); } @@ -183,6 +183,15 @@ void graphlayout(GSList const *const items) { sp_item_move_rel(u, NR::translate(dest - curr)); } } + for(unsigned i=0;i node_ids; vector rects; vector edges; + SimpleConstraints scx, scy; + ~Component() { + for(unsigned i=0;i &rs, - vector &es, + const vector &rs, + const vector &es, + const SimpleConstraints &scx, + const SimpleConstraints &scy, vector &components); // defines references to three variables for which the goal function diff --git a/src/libcola/connected_components.cpp b/src/libcola/connected_components.cpp index 8450e4874..5eb9d07ab 100644 --- a/src/libcola/connected_components.cpp +++ b/src/libcola/connected_components.cpp @@ -33,8 +33,10 @@ namespace cola { // for a graph of n nodes, return connected components void connectedComponents( - vector &rs, - vector &es, + const vector &rs, + const vector &es, + const SimpleConstraints &scx, + const SimpleConstraints &scy, vector &components) { unsigned n=rs.size(); vector vs(n); @@ -45,7 +47,7 @@ namespace cola { vs[i].r=rs[i]; remaining.insert(&vs[i]); } - for(vector::iterator e=es.begin();e!=es.end();e++) { + for(vector::const_iterator e=es.begin();e!=es.end();e++) { vs[e->first].neighbours.push_back(&vs[e->second]); vs[e->second].neighbours.push_back(&vs[e->first]); } @@ -56,12 +58,28 @@ namespace cola { dfs(v,remaining,component,cmap); components.push_back(component); } - for(vector::iterator e=es.begin();e!=es.end();e++) { + for(vector::const_iterator e=es.begin();e!=es.end();e++) { pair u=cmap[e->first], v=cmap[e->second]; assert(u.first==v.first); u.first->edges.push_back(make_pair(u.second,v.second)); } + for(SimpleConstraints::const_iterator ci=scx.begin();ci!=scx.end();ci++) { + SimpleConstraint *c=*ci; + pair u=cmap[c->left], + v=cmap[c->right]; + assert(u.first==v.first); + u.first->scx.push_back( + new SimpleConstraint(u.second,v.second,c->gap)); + } + for(SimpleConstraints::const_iterator ci=scy.begin();ci!=scy.end();ci++) { + SimpleConstraint *c=*ci; + pair u=cmap[c->left], + v=cmap[c->right]; + assert(u.first==v.first); + u.first->scy.push_back( + new SimpleConstraint(u.second,v.second,c->gap)); + } } } // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4