1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/**
* \brief Functions to automatically generate constraints for the
* rectangular node overlap removal problem.
*
* Authors:
* Tim Dwyer <tgdwyer@gmail.com>
*
* Copyright (C) 2005 Authors
*
* Released under GNU LGPL. Read the file 'COPYING' for more information.
*/
#ifndef SEEN_REMOVEOVERLAP_GENERATE_CONSTRAINTS_H
#define SEEN_REMOVEOVERLAP_GENERATE_CONSTRAINTS_H
#include <iostream>
namespace vpsc {
class Rectangle {
friend std::ostream& operator <<(std::ostream &os, const Rectangle &r);
public:
static double xBorder,yBorder;
Rectangle(double x, double X, double y, double Y);
double getMaxX() const { return maxX+xBorder; }
double getMaxY() const { return maxY+yBorder; }
double getMinX() const { return minX; }
double getMinY() const { return minY; }
double getMinD(unsigned const d) const {
return ( d == 0 ? getMinX() : getMinY() );
}
double getMaxD(unsigned const d) const {
return ( d == 0 ? getMaxX() : getMaxY() );
}
double getCentreX() const { return minX+width()/2.0; }
double getCentreY() const { return minY+height()/2.0; }
double width() const { return getMaxX()-minX; }
double height() const { return getMaxY()-minY; }
static void setXBorder(double x) {xBorder=x;}
static void setYBorder(double y) {yBorder=y;}
void moveCentreX(double x) {
moveMinX(x-width()/2.0);
}
void moveCentreY(double y) {
moveMinY(y-height()/2.0);
}
void moveMinX(double x) {
maxX=x+width()-xBorder;
minX=x;
}
void moveMinY(double y) {
maxY=y+height()-yBorder;
minY=y;
}
inline double overlapX(Rectangle *r) const {
if (getCentreX() <= r->getCentreX() && r->minX < getMaxX())
return getMaxX() - r->minX;
if (r->getCentreX() <= getCentreX() && minX < r->getMaxX())
return r->getMaxX() - minX;
return 0;
}
inline double overlapY(Rectangle *r) const {
if (getCentreY() <= r->getCentreY() && r->minY < getMaxY())
return getMaxY() - r->minY;
if (r->getCentreY() <= getCentreY() && minY < r->getMaxY())
return r->getMaxY() - minY;
return 0;
}
private:
double minX,maxX,minY,maxY;
};
class Variable;
class Constraint;
// returns number of constraints generated
int generateXConstraints(const int n, Rectangle** rs, Variable** vars, Constraint** &cs, const bool useNeighbourLists);
int generateYConstraints(const int n, Rectangle** rs, Variable** vars, Constraint** &cs);
}
#endif // SEEN_REMOVEOVERLAP_GENERATE_CONSTRAINTS_H
|