From dcf765f3dcbff2e65428e0f002bb5ea3648940f0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 25 Jun 2011 15:35:01 +0000 Subject: warning cleanup (no functional changes) - enclose && / || with brackets to avoid ambiguity. - don't cast from booleans to pointers. (bzr r10359) --- src/libcola/straightener.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libcola') diff --git a/src/libcola/straightener.cpp b/src/libcola/straightener.cpp index e237c03c3..7c73cb9e9 100644 --- a/src/libcola/straightener.cpp +++ b/src/libcola/straightener.cpp @@ -108,7 +108,7 @@ namespace straightener { int compare_events(const void *a, const void *b) { Event *ea=*(Event**)a; Event *eb=*(Event**)b; - if(ea->v!=NULL&&ea->v==eb->v||ea->e!=NULL&&ea->e==eb->e) { + if((ea->v!=NULL&&ea->v==eb->v)||(ea->e!=NULL&&ea->e==eb->e)) { // when comparing opening and closing from object // open must come first if(ea->type==Open) return -1; @@ -263,8 +263,8 @@ namespace straightener { // node is on an edge Edge *edge=(*i)->edge; if(!edge->isEnd(v->id) - &&(l!=NULL&&!edge->isEnd(l->id)||l==NULL) - &&(r!=NULL&&!edge->isEnd(r->id)||r==NULL)) { + &&((l!=NULL&&!edge->isEnd(l->id))||l==NULL) + &&((r!=NULL&&!edge->isEnd(r->id))||r==NULL)) { if(lastNode!=NULL) { //printf(" Rule A: Constraint: v%d +g <= v%d\n",lastNode->id,(*i)->id); cs.push_back(createConstraint(lastNode,*i,dim)); -- cgit v1.2.3 From 75493cd96255c87027c1de0cf721271f45146be9 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sat, 25 Jun 2011 23:57:27 -0700 Subject: Whitespace cleanup. (bzr r10366) --- src/libcola/cola.h | 129 +++++++++++++++++++++++++++++------------------------ 1 file changed, 71 insertions(+), 58 deletions(-) (limited to 'src/libcola') diff --git a/src/libcola/cola.h b/src/libcola/cola.h index eda64cb5f..136c527b6 100644 --- a/src/libcola/cola.h +++ b/src/libcola/cola.h @@ -32,12 +32,13 @@ namespace cola { void moveRectangles(double x, double y); Rectangle* getBoundingBox(); }; + // for a graph of n nodes, return connected components void connectedComponents( const vector &rs, const vector &es, const SimpleConstraints &scx, - const SimpleConstraints &scy, + const SimpleConstraints &scy, vector &components); // move the contents of each component so that the components do not @@ -48,11 +49,11 @@ namespace cola { // will be altered to prefer points u-b-v are in a linear arrangement // such that b is placed at u+t(v-u). struct LinearConstraint { - LinearConstraint(unsigned u, unsigned v, unsigned b, double w, + LinearConstraint(unsigned u, unsigned v, unsigned b, double w, double frac_ub, double frac_bv, - double* X, double* Y) + double* X, double* Y) : u(u),v(v),b(b),w(w),frac_ub(frac_ub),frac_bv(frac_bv), - tAtProjection(true) + tAtProjection(true) { assert(frac_ub<=1.0); assert(frac_bv<=1.0); @@ -88,7 +89,7 @@ namespace cola { dvv=t*t; dvb=-t; dbb=1; - //printf("New LC: t=%f\n",t); + //printf("New LC: t=%f\n",t); } unsigned u; unsigned v; @@ -108,61 +109,63 @@ namespace cola { double frac_bv; bool tAtProjection; }; + typedef vector LinearConstraints; - - class TestConvergence { - public: - double old_stress; - TestConvergence(const double& tolerance = 0.001, const unsigned maxiterations = 1000) - : tolerance(tolerance), - maxiterations(maxiterations) { reset(); } - virtual ~TestConvergence() {} - - virtual bool operator()(double new_stress, double* X, double* Y) { - //std::cout<<"iteration="< Date: Sun, 26 Jun 2011 23:32:42 -0700 Subject: Remove "using namespace" from libcola headers. (bzr r10374) --- src/libcola/cola.cpp | 52 +++++++++++++++++++-------------------- src/libcola/cola.h | 34 ++++++++++++------------- src/libcola/gradient_projection.h | 44 ++++++++++++++++----------------- src/libcola/shortest_paths.h | 23 +++++++++-------- src/libcola/straightener.cpp | 2 ++ src/libcola/straightener.h | 26 ++++++++++---------- 6 files changed, 92 insertions(+), 89 deletions(-) (limited to 'src/libcola') diff --git a/src/libcola/cola.cpp b/src/libcola/cola.cpp index 2a3b525a7..e2a233b5e 100644 --- a/src/libcola/cola.cpp +++ b/src/libcola/cola.cpp @@ -4,6 +4,8 @@ #include "shortest_paths.h" #include "2geom/isnan.h" +using namespace std; + namespace cola { /** @@ -16,8 +18,8 @@ inline double dummy_var_euclidean_dist(GradientProjection* gpx, GradientProjecti } ConstrainedMajorizationLayout ::ConstrainedMajorizationLayout( - vector& rs, - vector& es, + std::vector& rs, + std::vector& es, double* eweights, double idealLength, TestConvergence& done) @@ -85,10 +87,10 @@ ConstrainedMajorizationLayout for(Cluster::iterator vit=c->begin(); vit!=c->end(); ++vit) { double pos = coords[k][*vit]; - minPos=min(pos,minPos); - maxPos=max(pos,maxPos); - p->leftof.push_back(make_pair(*vit,0)); - p->rightof.push_back(make_pair(*vit,0)); + minPos = std::min(pos, minPos); + maxPos = std::max(pos, maxPos); + p->leftof.push_back(std::make_pair(*vit,0)); + p->rightof.push_back(std::make_pair(*vit,0)); } p->place_l = minPos; p->place_r = maxPos; @@ -108,7 +110,7 @@ void ConstrainedMajorizationLayout::majlayout( double** Dij, GradientProjection* gp, double* coords) { double b[n]; - fill(b,b+n,0); + std::fill(b,b+n,0); majlayout(Dij,gp,coords,b); } void ConstrainedMajorizationLayout::majlayout( @@ -123,7 +125,7 @@ void ConstrainedMajorizationLayout::majlayout( for (unsigned j = 0; j < lapSize; j++) { if (j == i) continue; dist_ij = euclidean_distance(i, j); - if (dist_ij > 1e-30 && Dij[i][j] > 1e-30) { /* skip zero distances */ + if (dist_ij > 1e-30 && Dij[i][j] > 1e-30) { /* skip zero distances */ /* calculate L_ij := w_{ij}*d_{ij}/dist_{ij} */ L_ij = 1.0 / (dist_ij * Dij[i][j]); degree -= L_ij; @@ -216,11 +218,11 @@ bool ConstrainedMajorizationLayout::run() { return true; } static bool straightenToProjection=true; -void ConstrainedMajorizationLayout::straighten(vector& sedges, Dim dim) { - vector snodes; - for (unsigned i=0;i& sedges, Dim dim) { + std::vector snodes; + for (unsigned i=0;i& sedg LinearConstraints linearConstraints; for(unsigned i=0;inodePath(snodes); - vector& path=sedges[i]->path; + std::vector& path=sedges[i]->path; // take u and v as the ends of the line //unsigned u=path[0]; //unsigned v=path[path.size()-1]; @@ -267,7 +269,7 @@ void ConstrainedMajorizationLayout::straighten(vector& sedg //cout << "Generated "<& sedg double wbv=edge_length*c->frac_bv; dist_ub=euclidean_distance(c->u,c->b)*wub; dist_bv=euclidean_distance(c->b,c->v)*wbv; - wub=max(wub,0.00001); - wbv=max(wbv,0.00001); - dist_ub=max(dist_ub,0.00001); - dist_bv=max(dist_bv,0.00001); + wub = std::max(wub,0.00001); + wbv = std::max(wbv,0.00001); + dist_ub = std::max(dist_ub,0.00001); + dist_bv = std::max(dist_bv,0.00001); wub=1/(wub*wub); wbv=1/(wbv*wbv); Q[c->u][c->u]-=wub; @@ -306,8 +308,8 @@ void ConstrainedMajorizationLayout::straighten(vector& sedg - coords[c->b] / dist_ub - coords[c->b] / dist_bv; } } - GradientProjection gp(dim,n,Q,coords,tol,100, - (AlignmentConstraints*)NULL,false,(vpsc::Rectangle**)NULL,(PageBoundaryConstraints*)NULL,&cs); + GradientProjection gp(dim,n,Q,coords,tol,100, + (AlignmentConstraints*)NULL,false,(vpsc::Rectangle**)NULL,(PageBoundaryConstraints*)NULL,&cs); constrainedLayout = true; majlayout(Dij,&gp,coords,b); for(unsigned i=0;i* straightenEdges) { + std::vector* straightenEdges) { constrainedLayout = true; this->avoidOverlaps = avoidOverlaps; if(cs) { clusters=cs; } - gpX=new GradientProjection( - HORIZONTAL,n,Q,X,tol,100,acsx,avoidOverlaps,boundingBoxes,pbcx,scx); - gpY=new GradientProjection( - VERTICAL,n,Q,Y,tol,100,acsy,avoidOverlaps,boundingBoxes,pbcy,scy); + gpX = new GradientProjection(HORIZONTAL,n,Q,X,tol,100,acsx,avoidOverlaps,boundingBoxes,pbcx,scx); + gpY = new GradientProjection(VERTICAL,n,Q,Y,tol,100,acsy,avoidOverlaps,boundingBoxes,pbcy,scy); this->straightenEdges = straightenEdges; } } // namespace cola diff --git a/src/libcola/cola.h b/src/libcola/cola.h index 136c527b6..e1f19994e 100644 --- a/src/libcola/cola.h +++ b/src/libcola/cola.h @@ -12,21 +12,21 @@ #include "straightener.h" -typedef vector Cluster; -typedef vector Clusters; +typedef std::vector Cluster; +typedef std::vector Clusters; namespace vpsc { class Rectangle; } namespace cola { using vpsc::Rectangle; - typedef pair Edge; + typedef std::pair Edge; // a graph component with a list of node_ids giving indices for some larger list of nodes // for the nodes in this component, and a list of edges - node indices relative to this component class Component { public: - vector node_ids; - vector rects; - vector edges; + std::vector node_ids; + std::vector rects; + std::vector edges; SimpleConstraints scx, scy; virtual ~Component(); void moveRectangles(double x, double y); @@ -35,15 +35,15 @@ namespace cola { // for a graph of n nodes, return connected components void connectedComponents( - const vector &rs, - const vector &es, + const std::vector &rs, + const std::vector &es, const SimpleConstraints &scx, const SimpleConstraints &scy, - vector &components); + std::vector &components); // move the contents of each component so that the components do not // overlap. - void separateComponents(const vector &components); + void separateComponents(const std::vector &components); // defines references to three variables for which the goal function // will be altered to prefer points u-b-v are in a linear arrangement @@ -110,7 +110,7 @@ namespace cola { bool tAtProjection; }; - typedef vector LinearConstraints; + typedef std::vector LinearConstraints; class TestConvergence { public: @@ -150,8 +150,8 @@ static TestConvergence defaultTest(0.0001,100); class ConstrainedMajorizationLayout { public: ConstrainedMajorizationLayout( - vector& rs, - vector& es, + std::vector& rs, + std::vector& es, double* eweights, double idealLength, TestConvergence& done=defaultTest); @@ -171,7 +171,7 @@ public: SimpleConstraints* scx = NULL, SimpleConstraints* scy = NULL, Clusters* cs = NULL, - vector* straightenEdges = NULL); + std::vector* straightenEdges = NULL); void addLinearConstraints(LinearConstraints* linearConstraints); @@ -195,7 +195,7 @@ public: delete [] Y; } bool run(); - void straighten(vector&, Dim); + void straighten(std::vector&, Dim); bool avoidOverlaps; bool constrainedLayout; private: @@ -214,14 +214,14 @@ public: double** Q; // quadratic terms matrix used in computations double** Dij; double tol; - TestConvergence& done; + TestConvergence& done; Rectangle** boundingBoxes; double *X, *Y; Clusters* clusters; double edge_length; LinearConstraints *linearConstraints; GradientProjection *gpX, *gpY; - vector* straightenEdges; + std::vector* straightenEdges; }; } diff --git a/src/libcola/gradient_projection.h b/src/libcola/gradient_projection.h index 4ef68fc2e..9907cdb13 100644 --- a/src/libcola/gradient_projection.h +++ b/src/libcola/gradient_projection.h @@ -9,11 +9,9 @@ #include #include -using namespace std; - -typedef vector Constraints; -typedef vector Variables; -typedef vector > OffsetList; +typedef std::vector Constraints; +typedef std::vector Variables; +typedef std::vector > OffsetList; class SimpleConstraint { public: @@ -23,7 +21,7 @@ public: unsigned right; double gap; }; -typedef vector SimpleConstraints; +typedef std::vector SimpleConstraints; class AlignmentConstraint { friend class GradientProjection; public: @@ -37,7 +35,7 @@ public: private: vpsc::Variable* variable; }; -typedef vector AlignmentConstraints; +typedef std::vector AlignmentConstraints; class PageBoundaryConstraints { public: @@ -63,7 +61,7 @@ private: double weight; }; -typedef vector > CList; +typedef std::vector > CList; /** * A DummyVarPair is a pair of variables with an ideal distance between them and which have no * other interaction with other variables apart from through constraints. This means that @@ -170,19 +168,19 @@ friend class GradientProjection; double old_place_l; // old_place is where the descent vec g was computed double old_place_r; }; -typedef vector DummyVars; +typedef std::vector DummyVars; enum Dim { HORIZONTAL, VERTICAL }; class GradientProjection { public: - GradientProjection( + GradientProjection( const Dim k, - unsigned n, - double** A, - double* x, - double tol, - unsigned max_iterations, + unsigned n, + double** A, + double* x, + double tol, + unsigned max_iterations, AlignmentConstraints* acs=NULL, bool nonOverlapConstraints=false, vpsc::Rectangle** rs=NULL, @@ -222,7 +220,7 @@ public: if(!gcs.empty() || nonOverlapConstraints) { constrained=true; } - } + } virtual ~GradientProjection() { delete [] g; delete [] d; @@ -236,16 +234,16 @@ public: } } void clearDummyVars(); - unsigned solve(double* b); + unsigned solve(double* b); DummyVars dummy_vars; // special vars that must be considered in Lapl. private: vpsc::IncSolver* setupVPSC(); void destroyVPSC(vpsc::IncSolver *vpsc); Dim k; - unsigned n; // number of actual vars - double** A; // Graph laplacian matrix + unsigned n; // number of actual vars + double** A; // Graph laplacian matrix double* place; - Variables vars; // all variables + Variables vars; // all variables // computations Constraints gcs; /* global constraints - persist throughout all iterations */ @@ -255,9 +253,9 @@ private: double tolerance; AlignmentConstraints* acs; unsigned max_iterations; - double* g; /* gradient */ - double* d; - double* old_place; + double* g; /* gradient */ + double* d; + double* old_place; bool constrained; }; diff --git a/src/libcola/shortest_paths.h b/src/libcola/shortest_paths.h index 20107caf0..f376b631c 100644 --- a/src/libcola/shortest_paths.h +++ b/src/libcola/shortest_paths.h @@ -1,7 +1,7 @@ // vim: set cindent // vim: ts=4 sw=4 et tw=0 wm=0 #include -using namespace std; + template class PairNode; namespace shortest_paths { @@ -9,20 +9,23 @@ namespace shortest_paths { struct Node { unsigned id; double d; - Node* p; // predecessor - vector neighbours; - vector nweights; - PairNode* qnode; + Node *p; // predecessor + std::vector neighbours; + std::vector nweights; + PairNode *qnode; }; inline bool compareNodes(Node *const &u, Node *const &v) { - return u->d < v->d; + return u->d < v->d; } -typedef pair Edge; +typedef std::pair Edge; + void floyd_warshall(unsigned n, double** D, - vector& es,double* eweights); + std::vector& es,double* eweights); + void johnsons(unsigned n, double** D, - vector& es, double* eweights); + std::vector& es, double* eweights); + void dijkstra(unsigned s, unsigned n, double* d, - vector& es, double* eweights); + std::vector& es, double* eweights); } diff --git a/src/libcola/straightener.cpp b/src/libcola/straightener.cpp index 7c73cb9e9..7a1020781 100644 --- a/src/libcola/straightener.cpp +++ b/src/libcola/straightener.cpp @@ -25,6 +25,8 @@ using std::set; using std::vector; using std::list; +using std::pair; +using std::make_pair; namespace straightener { diff --git a/src/libcola/straightener.h b/src/libcola/straightener.h index 934be45ba..b1ce665f4 100644 --- a/src/libcola/straightener.h +++ b/src/libcola/straightener.h @@ -18,10 +18,10 @@ namespace straightener { xmin=ymin=DBL_MAX; xmax=ymax=-DBL_MAX; for(unsigned i=0;i dummyNodes; - vector path; + std::vector dummyNodes; + std::vector path; Edge(unsigned id, unsigned start, unsigned end, Route* route) : id(id), startNode(start), endNode(end), route(route) { @@ -54,7 +54,7 @@ namespace straightener { if(startNode==n||endNode==n) return true; return false; } - void nodePath(vector& nodes); + void nodePath(std::vector& nodes); void createRouteFromPath(double* X, double* Y) { Route* r=new Route(path.size()); for(unsigned i=0;i& xs) { + void xpos(double y, std::vector& xs) { // search line segments for intersection points with y pos for(unsigned i=1;in;i++) { double ax=route->xs[i-1], bx=route->xs[i], ay=route->ys[i-1], by=route->ys[i]; @@ -74,7 +74,7 @@ namespace straightener { } } } - void ypos(double x, vector& ys) { + void ypos(double x, std::vector& ys) { // search line segments for intersection points with x pos for(unsigned i=1;in;i++) { double ax=route->xs[i-1], bx=route->xs[i], ay=route->ys[i-1], by=route->ys[i]; @@ -104,8 +104,8 @@ namespace straightener { edge(NULL),dummy(false),weight(-0.1),open(false) { } private: friend void sortNeighbours(Node* v, Node* l, Node* r, - double conjpos, vector& openEdges, - vector& L,vector& nodes, Dim dim); + double conjpos, std::vector& openEdges, + std::vector& L, std::vector& nodes, Dim dim); Node(unsigned id, double x, double y, Edge* e) : id(id),x(x),y(y), width(4), height(width), xmin(x-width/2),xmax(x+width/2), @@ -126,8 +126,8 @@ namespace straightener { } }; typedef std::set NodeSet; - void generateConstraints(vector& nodes, vector& edges,vector& cs, Dim dim); - void nodePath(Edge& e,vector& nodes, vector& path); + void generateConstraints(std::vector& nodes, std::vector& edges, std::vector& cs, Dim dim); + void nodePath(Edge& e, std::vector& nodes, std::vector& path); } #endif -- cgit v1.2.3 From 07c8dea2b0361314ac4bbf0e45dd4c33ce11f206 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Fri, 1 Jul 2011 23:11:08 -0700 Subject: Applying patch from Campbell Barton to help building on other than gcc. (bzr r10399) --- src/libcola/shortest_paths.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/libcola') diff --git a/src/libcola/shortest_paths.cpp b/src/libcola/shortest_paths.cpp index 4f4183b07..ebc2c93de 100644 --- a/src/libcola/shortest_paths.cpp +++ b/src/libcola/shortest_paths.cpp @@ -73,6 +73,7 @@ void dijkstra( } } } + void dijkstra( unsigned s, unsigned n, @@ -80,21 +81,22 @@ void dijkstra( vector& es, double* eweights) { - assert(s vs(n); + dijkstra_init(&vs[0], es, eweights); + dijkstra(s, n, &vs[0], d); } + void johnsons( unsigned n, double** D, vector& es, double* eweights) { - Node vs[n]; - dijkstra_init(vs,es,eweights); - for(unsigned k=0;k vs(n); + dijkstra_init(&vs[0], es, eweights); + for (unsigned k = 0; k < n; k++) { + dijkstra(k,n,&vs[0],D[k]); } } } -- cgit v1.2.3