/* * remove overlaps between a set of rectangles. * * Authors: * Tim Dwyer * * Copyright (C) 2005 Authors * * Released under GNU LGPL. Read the file 'COPYING' for more information. */ #include #include #include "generate-constraints.h" #include "solve_VPSC.h" #include "variable.h" #include "constraint.h" #ifdef RECTANGLE_OVERLAP_LOGGING #include #include "blocks.h" using std::ios; using std::ofstream; using std::endl; #endif #define EXTRA_GAP 0.0001 using namespace vpsc; double Rectangle::xBorder=0; double Rectangle::yBorder=0; void removeRectangleOverlap(unsigned n, Rectangle *rs[], double xBorder, double yBorder) { try { // The extra gap avoids numerical imprecision problems Rectangle::setXBorder(xBorder+EXTRA_GAP); Rectangle::setYBorder(yBorder+EXTRA_GAP); Variable **vs=new Variable*[n]; for(unsigned i=0;idesiredPosition; } Solver vpsc_x(n,vs,m,cs); #ifdef RECTANGLE_OVERLAP_LOGGING ofstream f(LOGFILE,ios::app); f<<"Calling VPSC: Horizontal pass 1"<moveCentreX(vs[i]->position()); } for(unsigned i = 0; i < m; ++i) { delete cs[i]; } delete [] cs; // Removing the extra gap here ensures things that were moved to be adjacent to // one another above are not considered overlapping Rectangle::setXBorder(Rectangle::xBorder-EXTRA_GAP); m=generateYConstraints(n,rs,vs,cs); Solver vpsc_y(n,vs,m,cs); #ifdef RECTANGLE_OVERLAP_LOGGING f.open(LOGFILE,ios::app); f<<"Calling VPSC: Vertical pass"<moveCentreY(vs[i]->position()); rs[i]->moveCentreX(oldX[i]); } delete [] oldX; for(unsigned i = 0; i < m; ++i) { delete cs[i]; } delete [] cs; Rectangle::setYBorder(Rectangle::yBorder-EXTRA_GAP); m=generateXConstraints(n,rs,vs,cs,false); Solver vpsc_x2(n,vs,m,cs); #ifdef RECTANGLE_OVERLAP_LOGGING f.open(LOGFILE,ios::app); f<<"Calling VPSC: Horizontal pass 2"<moveCentreX(vs[i]->position()); delete vs[i]; } delete [] vs; } catch (char const *str) { std::cerr<