summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJon A. Cruz <jon@joncruz.org>2011-06-27 06:32:42 +0000
committerJon A. Cruz <jon@joncruz.org>2011-06-27 06:32:42 +0000
commit419fa66edd4abd4a1227030b75ca163335891548 (patch)
treefb43784fc99931b3c50cb660c8e5e271178c0cad /src
parentLPE PowerStroke: add linecap (let's see how well this behaves, it has some bu... (diff)
downloadinkscape-419fa66edd4abd4a1227030b75ca163335891548.tar.gz
inkscape-419fa66edd4abd4a1227030b75ca163335891548.zip
Remove "using namespace" from libcola headers.
(bzr r10374)
Diffstat (limited to 'src')
-rw-r--r--src/libcola/cola.cpp52
-rw-r--r--src/libcola/cola.h34
-rw-r--r--src/libcola/gradient_projection.h44
-rw-r--r--src/libcola/shortest_paths.h23
-rw-r--r--src/libcola/straightener.cpp2
-rw-r--r--src/libcola/straightener.h26
6 files changed, 92 insertions, 89 deletions
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<Rectangle*>& rs,
- vector<Edge>& es,
+ std::vector<Rectangle*>& rs,
+ std::vector<Edge>& 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<straightener::Edge*>& sedges, Dim dim) {
- vector<straightener::Node*> snodes;
- for (unsigned i=0;i<lapSize;i++) {
- snodes.push_back(new straightener::Node(i,boundingBoxes[i]));
- }
+void ConstrainedMajorizationLayout::straighten(std::vector<straightener::Edge*>& sedges, Dim dim) {
+ std::vector<straightener::Node*> snodes;
+ for (unsigned i=0;i<lapSize;i++) {
+ snodes.push_back(new straightener::Node(i,boundingBoxes[i]));
+ }
SimpleConstraints cs;
straightener::generateConstraints(snodes,sedges,cs,dim);
n=snodes.size();
@@ -244,7 +246,7 @@ void ConstrainedMajorizationLayout::straighten(vector<straightener::Edge*>& sedg
LinearConstraints linearConstraints;
for(unsigned i=0;i<sedges.size();i++) {
sedges[i]->nodePath(snodes);
- vector<unsigned>& path=sedges[i]->path;
+ std::vector<unsigned>& 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<straightener::Edge*>& sedg
//cout << "Generated "<<linearConstraints.size()<< " linear constraints"<<endl;
assert(snodes.size()==lapSize+linearConstraints.size());
double b[n],*coords=dim==HORIZONTAL?X:Y,dist_ub,dist_bv;
- fill(b,b+n,0);
+ std::fill(b,b+n,0);
for(LinearConstraints::iterator i=linearConstraints.begin();
i!= linearConstraints.end();i++) {
LinearConstraint* c=*i;
@@ -286,10 +288,10 @@ void ConstrainedMajorizationLayout::straighten(vector<straightener::Edge*>& 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<straightener::Edge*>& 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<sedges.size();i++) {
@@ -337,16 +339,14 @@ void ConstrainedMajorizationLayout::setupConstraints(
PageBoundaryConstraints* pbcx, PageBoundaryConstraints* pbcy,
SimpleConstraints* scx, SimpleConstraints* scy,
Clusters* cs,
- vector<straightener::Edge*>* straightenEdges) {
+ std::vector<straightener::Edge*>* 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<unsigned> Cluster;
-typedef vector<Cluster*> Clusters;
+typedef std::vector<unsigned> Cluster;
+typedef std::vector<Cluster*> Clusters;
namespace vpsc { class Rectangle; }
namespace cola {
using vpsc::Rectangle;
- typedef pair<unsigned, unsigned> Edge;
+ typedef std::pair<unsigned, unsigned> 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<unsigned> node_ids;
- vector<Rectangle*> rects;
- vector<Edge> edges;
+ std::vector<unsigned> node_ids;
+ std::vector<Rectangle*> rects;
+ std::vector<Edge> 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<Rectangle*> &rs,
- const vector<Edge> &es,
+ const std::vector<Rectangle*> &rs,
+ const std::vector<Edge> &es,
const SimpleConstraints &scx,
const SimpleConstraints &scy,
- vector<Component*> &components);
+ std::vector<Component*> &components);
// move the contents of each component so that the components do not
// overlap.
- void separateComponents(const vector<Component*> &components);
+ void separateComponents(const std::vector<Component*> &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<LinearConstraint*> LinearConstraints;
+ typedef std::vector<LinearConstraint*> LinearConstraints;
class TestConvergence {
public:
@@ -150,8 +150,8 @@ static TestConvergence defaultTest(0.0001,100);
class ConstrainedMajorizationLayout {
public:
ConstrainedMajorizationLayout(
- vector<Rectangle*>& rs,
- vector<Edge>& es,
+ std::vector<Rectangle*>& rs,
+ std::vector<Edge>& es,
double* eweights,
double idealLength,
TestConvergence& done=defaultTest);
@@ -171,7 +171,7 @@ public:
SimpleConstraints* scx = NULL,
SimpleConstraints* scy = NULL,
Clusters* cs = NULL,
- vector<straightener::Edge*>* straightenEdges = NULL);
+ std::vector<straightener::Edge*>* straightenEdges = NULL);
void addLinearConstraints(LinearConstraints* linearConstraints);
@@ -195,7 +195,7 @@ public:
delete [] Y;
}
bool run();
- void straighten(vector<straightener::Edge*>&, Dim);
+ void straighten(std::vector<straightener::Edge*>&, 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<straightener::Edge*>* straightenEdges;
+ std::vector<straightener::Edge*>* 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 <iostream>
#include <math.h>
-using namespace std;
-
-typedef vector<vpsc::Constraint*> Constraints;
-typedef vector<vpsc::Variable*> Variables;
-typedef vector<pair<unsigned,double> > OffsetList;
+typedef std::vector<vpsc::Constraint*> Constraints;
+typedef std::vector<vpsc::Variable*> Variables;
+typedef std::vector<std::pair<unsigned, double> > OffsetList;
class SimpleConstraint {
public:
@@ -23,7 +21,7 @@ public:
unsigned right;
double gap;
};
-typedef vector<SimpleConstraint*> SimpleConstraints;
+typedef std::vector<SimpleConstraint*> SimpleConstraints;
class AlignmentConstraint {
friend class GradientProjection;
public:
@@ -37,7 +35,7 @@ public:
private:
vpsc::Variable* variable;
};
-typedef vector<AlignmentConstraint*> AlignmentConstraints;
+typedef std::vector<AlignmentConstraint*> AlignmentConstraints;
class PageBoundaryConstraints {
public:
@@ -63,7 +61,7 @@ private:
double weight;
};
-typedef vector<pair<unsigned,double> > CList;
+typedef std::vector<std::pair<unsigned, double> > 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<DummyVarPair*> DummyVars;
+typedef std::vector<DummyVarPair*> 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 <vector>
-using namespace std;
+
template <class T>
class PairNode;
namespace shortest_paths {
@@ -9,20 +9,23 @@ namespace shortest_paths {
struct Node {
unsigned id;
double d;
- Node* p; // predecessor
- vector<Node*> neighbours;
- vector<double> nweights;
- PairNode<Node*>* qnode;
+ Node *p; // predecessor
+ std::vector<Node*> neighbours;
+ std::vector<double> nweights;
+ PairNode<Node*> *qnode;
};
inline bool compareNodes(Node *const &u, Node *const &v) {
- return u->d < v->d;
+ return u->d < v->d;
}
-typedef pair<unsigned,unsigned> Edge;
+typedef std::pair<unsigned,unsigned> Edge;
+
void floyd_warshall(unsigned n, double** D,
- vector<Edge>& es,double* eweights);
+ std::vector<Edge>& es,double* eweights);
+
void johnsons(unsigned n, double** D,
- vector<Edge>& es, double* eweights);
+ std::vector<Edge>& es, double* eweights);
+
void dijkstra(unsigned s, unsigned n, double* d,
- vector<Edge>& es, double* eweights);
+ std::vector<Edge>& 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<n;i++) {
- xmin=min(xmin,xs[i]);
- xmax=max(xmax,xs[i]);
- ymin=min(ymin,ys[i]);
- ymax=max(ymax,ys[i]);
+ xmin = std::min(xmin,xs[i]);
+ xmax = std::max(xmax,xs[i]);
+ ymin = std::min(ymin,ys[i]);
+ ymax = std::max(ymax,ys[i]);
}
}
unsigned n;
@@ -35,8 +35,8 @@ namespace straightener {
unsigned startNode, endNode;
Route* route;
double xmin, xmax, ymin, ymax;
- vector<unsigned> dummyNodes;
- vector<unsigned> path;
+ std::vector<unsigned> dummyNodes;
+ std::vector<unsigned> 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<Node*>& nodes);
+ void nodePath(std::vector<Node*>& nodes);
void createRouteFromPath(double* X, double* Y) {
Route* r=new Route(path.size());
for(unsigned i=0;i<path.size();i++) {
@@ -63,7 +63,7 @@ namespace straightener {
}
setRoute(r);
}
- void xpos(double y, vector<double>& xs) {
+ void xpos(double y, std::vector<double>& xs) {
// search line segments for intersection points with y pos
for(unsigned i=1;i<route->n;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<double>& ys) {
+ void ypos(double x, std::vector<double>& ys) {
// search line segments for intersection points with x pos
for(unsigned i=1;i<route->n;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<Edge*>& openEdges,
- vector<Node*>& L,vector<Node*>& nodes, Dim dim);
+ double conjpos, std::vector<Edge*>& openEdges,
+ std::vector<Node*>& L, std::vector<Node*>& 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<Node*,CmpNodePos> NodeSet;
- void generateConstraints(vector<Node*>& nodes, vector<Edge*>& edges,vector<SimpleConstraint*>& cs, Dim dim);
- void nodePath(Edge& e,vector<Node*>& nodes, vector<unsigned>& path);
+ void generateConstraints(std::vector<Node*>& nodes, std::vector<Edge*>& edges, std::vector<SimpleConstraint*>& cs, Dim dim);
+ void nodePath(Edge& e, std::vector<Node*>& nodes, std::vector<unsigned>& path);
}
#endif