remove_rectangle_overlap.cpp revision d1c7cc7eb10f1bf5756d299e4a1e4f3060bfed8f
/**
* \brief remove overlaps between a set of rectangles.
*
* Authors:
* Tim Dwyer <tgdwyer@gmail.com>
*
* Copyright (C) 2005 Authors
*
* Released under GNU LGPL. Read the file 'COPYING' for more information.
*/
#include <iostream>
#include <cassert>
#include "generate-constraints.h"
#include "solve_VPSC.h"
#include "variable.h"
#include "constraint.h"
#ifdef RECTANGLE_OVERLAP_LOGGING
#include <fstream>
#include "blocks.h"
#endif
#define EXTRA_GAP 0.0001
using namespace vpsc;
/**
* Takes an array of n rectangles and moves them as little as possible
* such that rectangles are separated by at least xBorder horizontally
* and yBorder vertically
*
* Works in three passes:
* 1) removes some overlap horizontally
* 2) removes remaining overlap vertically
* 3) a last horizontal pass removes all overlap starting from original
* x-positions - this corrects the case where rectangles were moved
* too much in the first pass.
*/
try {
// The extra gap avoids numerical imprecision problems
for(unsigned i=0;i<n;i++) {
}
Constraint **cs;
double *oldX = new double[n];
for(unsigned i=0;i<n;i++) {
}
#ifdef RECTANGLE_OVERLAP_LOGGING
f<<"Calling VPSC: Horizontal pass 1"<<endl;
f.close();
#endif
for(unsigned i=0;i<n;i++) {
}
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
#ifdef RECTANGLE_OVERLAP_LOGGING
f<<"Calling VPSC: Vertical pass"<<endl;
f.close();
#endif
for(unsigned i=0;i<n;i++) {
}
delete [] oldX;
for(unsigned i = 0; i < m; ++i) {
delete cs[i];
}
delete [] cs;
#ifdef RECTANGLE_OVERLAP_LOGGING
f<<"Calling VPSC: Horizontal pass 2"<<endl;
f.close();
#endif
for(unsigned i = 0; i < m; ++i) {
delete cs[i];
}
delete [] cs;
for(unsigned i=0;i<n;i++) {
delete vs[i];
}
delete [] vs;
} catch (char const *str) {
for(unsigned i=0;i<n;i++) {
}
}
}