remove_rectangle_overlap.cpp revision 1ec681f88b68c6186b267afcce12c7fd667cc9f8
/**
* \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
/**
* 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.
*/
assert(0 <= n);
try {
// The extra gap avoids numerical imprecision problems
for(int i=0;i<n;i++) {
}
Constraint **cs;
double *oldX = new double[n];
for(int i=0;i<n;i++) {
}
#ifdef RECTANGLE_OVERLAP_LOGGING
f<<"Calling VPSC: Horizontal pass 1"<<endl;
f.close();
#endif
for(int i=0;i<n;i++) {
}
for(int 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(int i=0;i<n;i++) {
}
delete [] oldX;
for(int 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(int i = 0; i < m; ++i) {
delete cs[i];
}
delete [] cs;
for(int i=0;i<n;i++) {
delete vs[i];
}
delete [] vs;
} catch (char const *str) {
for(int i=0;i<n;i++) {
}
}
}