summaryrefslogtreecommitdiffstats
path: root/src/libcola
diff options
context:
space:
mode:
authorKrzysztof Kosi??ski <tweenk.pl@gmail.com>2011-07-06 01:59:32 +0000
committerKrzysztof KosiƄski <tweenk.pl@gmail.com>2011-07-06 01:59:32 +0000
commite65a02ed32b78534739aba24929ece7c44dd967f (patch)
tree13cf022f18f6b5bae46aad4bc339e512f069a514 /src/libcola
parentPull 2Geom revision 2013 (extra constructors for Rect). (diff)
parentText edit dialog: Apply button should grab default only after adding to window (diff)
downloadinkscape-e65a02ed32b78534739aba24929ece7c44dd967f.tar.gz
inkscape-e65a02ed32b78534739aba24929ece7c44dd967f.zip
Merge from trunk
(bzr r10347.1.5)
Diffstat (limited to 'src/libcola')
-rw-r--r--src/libcola/cola.cpp52
-rw-r--r--src/libcola/cola.h157
-rw-r--r--src/libcola/gradient_projection.h44
-rw-r--r--src/libcola/shortest_paths.cpp18
-rw-r--r--src/libcola/shortest_paths.h23
-rw-r--r--src/libcola/straightener.cpp8
-rw-r--r--src/libcola/straightener.h26
7 files changed, 173 insertions, 155 deletions
diff --git a/src/libcola/cola.cpp b/src/libcola/cola.cpp
index 62771ece2..87fbf9f79 100644
--- a/src/libcola/cola.cpp
+++ b/src/libcola/cola.cpp
@@ -4,6 +4,8 @@
#include "shortest_paths.h"
#include <2geom/math-utils.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 eda64cb5f..e1f19994e 100644
--- a/src/libcola/cola.h
+++ b/src/libcola/cola.h
@@ -12,47 +12,48 @@
#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);
Rectangle* getBoundingBox();
};
+
// 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);
+ const SimpleConstraints &scy,
+ 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
// 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,67 +109,69 @@ namespace cola {
double frac_bv;
bool tAtProjection;
};
- typedef vector<LinearConstraint*> 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="<<iterations<<", new_stress="<<new_stress<<std::endl;
- if (old_stress == DBL_MAX) {
- old_stress = new_stress;
- if(++iterations>=maxiterations) {;
- return true;
- } else {
- return false;
- }
- }
- bool converged =
- fabs(new_stress - old_stress) / (new_stress + 1e-10) < tolerance
- || ++iterations > maxiterations;
+
+ typedef std::vector<LinearConstraint*> 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="<<iterations<<", new_stress="<<new_stress<<std::endl;
+ if (old_stress == DBL_MAX) {
old_stress = new_stress;
- return converged;
- }
- void reset() {
- old_stress = DBL_MAX;
- iterations = 0;
- }
- private:
- const double tolerance;
- const unsigned maxiterations;
- unsigned iterations;
- };
- static TestConvergence defaultTest(0.0001,100);
- class ConstrainedMajorizationLayout {
- public:
- ConstrainedMajorizationLayout(
- vector<Rectangle*>& rs,
- vector<Edge>& es,
- double* eweights,
- double idealLength,
- TestConvergence& done=defaultTest);
-
- void moveBoundingBoxes() {
- for(unsigned i=0;i<lapSize;i++) {
- boundingBoxes[i]->moveCentreX(X[i]);
- boundingBoxes[i]->moveCentreY(Y[i]);
+ if(++iterations>=maxiterations) {;
+ return true;
+ } else {
+ return false;
}
}
+ bool converged =
+ fabs(new_stress - old_stress) / (new_stress + 1e-10) < tolerance
+ || ++iterations > maxiterations;
+ old_stress = new_stress;
+ return converged;
+ }
+ void reset() {
+ old_stress = DBL_MAX;
+ iterations = 0;
+ }
+private:
+ const double tolerance;
+ const unsigned maxiterations;
+ unsigned iterations;
+};
+
+static TestConvergence defaultTest(0.0001,100);
+class ConstrainedMajorizationLayout {
+public:
+ ConstrainedMajorizationLayout(
+ std::vector<Rectangle*>& rs,
+ std::vector<Edge>& es,
+ double* eweights,
+ double idealLength,
+ TestConvergence& done=defaultTest);
+
+ void moveBoundingBoxes() {
+ for(unsigned i=0;i<lapSize;i++) {
+ boundingBoxes[i]->moveCentreX(X[i]);
+ boundingBoxes[i]->moveCentreY(Y[i]);
+ }
+ }
void setupConstraints(
AlignmentConstraints* acsx, AlignmentConstraints* acsy,
- bool avoidOverlaps,
+ bool avoidOverlaps,
PageBoundaryConstraints* pbcx = NULL,
PageBoundaryConstraints* pbcy = NULL,
SimpleConstraints* scx = NULL,
SimpleConstraints* scy = NULL,
Clusters* cs = NULL,
- vector<straightener::Edge*>* straightenEdges = NULL);
+ std::vector<straightener::Edge*>* straightenEdges = NULL);
void addLinearConstraints(LinearConstraints* linearConstraints);
@@ -191,8 +194,8 @@ namespace cola {
delete [] X;
delete [] Y;
}
- bool run();
- void straighten(vector<straightener::Edge*>&, Dim);
+ bool run();
+ void straighten(std::vector<straightener::Edge*>&, Dim);
bool avoidOverlaps;
bool constrainedLayout;
private:
@@ -203,7 +206,7 @@ namespace cola {
}
double compute_stress(double **Dij);
void majlayout(double** Dij,GradientProjection* gp, double* coords);
- void majlayout(double** Dij,GradientProjection* gp, double* coords,
+ void majlayout(double** Dij,GradientProjection* gp, double* coords,
double* b);
unsigned n; // is lapSize + dummyVars
unsigned lapSize; // lapSize is the number of variables for actual nodes
@@ -211,15 +214,25 @@ namespace cola {
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;
+};
+
}
-#endif // COLA_H
+#endif // COLA_H
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
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.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<Edge>& es,
double* eweights)
{
- assert(s<n);
- Node vs[n];
- dijkstra_init(vs,es,eweights);
- dijkstra(s,n,vs,d);
+ assert(s < n);
+ std::vector<Node> vs(n);
+ dijkstra_init(&vs[0], es, eweights);
+ dijkstra(s, n, &vs[0], d);
}
+
void johnsons(
unsigned n,
double** D,
vector<Edge>& es,
double* eweights)
{
- Node vs[n];
- dijkstra_init(vs,es,eweights);
- for(unsigned k=0;k<n;k++) {
- dijkstra(k,n,vs,D[k]);
+ std::vector<Node> vs(n);
+ dijkstra_init(&vs[0], es, eweights);
+ for (unsigned k = 0; k < n; k++) {
+ dijkstra(k,n,&vs[0],D[k]);
}
}
}
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 e237c03c3..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 {
@@ -108,7 +110,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 +265,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));
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