27 #ifndef VPSC_RECTANGLE_H 28 #define VPSC_RECTANGLE_H 36 #include "libvpsc/assertions.h" 54 inline Dim conjugate(
Dim d) {
55 return static_cast<Dim>(!d);
59 struct RectangleIntersections {
60 bool intersects, top, bottom, left, right;
61 double topX, topY, bottomX, bottomY, leftX, leftY, rightX, rightY;
62 RectangleIntersections()
63 : intersects(false),top(false),bottom(false),left(false),right(false),
64 topX(0),topY(0),bottomX(0),bottomY(0),leftX(0),leftY(0),rightX(0),rightY(0) {}
65 int countIntersections() {
66 return left+right+top+bottom;
68 void printIntersections(
void);
71 void nearest(
double x,
double y,
double & xi,
double & yi);
90 Rectangle(
double x,
double X,
double y,
double Y,
91 bool allowOverlap =
false);
97 , overlap(Other.overlap) { }
99 bool isValid(
void)
const;
107 void reset(
const unsigned d,
double x,
double X);
108 double getMaxX()
const {
return maxX+xBorder; }
109 double getMaxY()
const {
return maxY+yBorder; }
110 double getMinX()
const {
return minX-xBorder; }
111 double getMinY()
const {
return minY-yBorder; }
115 double getMinD(
unsigned const d)
const {
116 COLA_ASSERT(d==0||d==1);
117 return ( d == 0 ? getMinX() : getMinY() );
122 double getMaxD(
unsigned const d)
const {
123 COLA_ASSERT(d==0||d==1);
124 return ( d == 0 ? getMaxX() : getMaxY() );
126 void setMinD(
unsigned const d,
const double val)
127 {
if ( d == 0) { minX = val; }
else { minY = val; } }
128 void setMaxD(
unsigned const d,
const double val)
129 {
if ( d == 0) { maxX = val; }
else { maxY = val; } }
130 double getCentreX()
const {
return getMinX()+width()/2.0; }
131 double getCentreY()
const {
return getMinY()+height()/2.0; }
135 double getCentreD(
unsigned const d)
const {
136 COLA_ASSERT(d==0||d==1);
137 return getMinD(d)+length(d)/2.0;
139 double width()
const {
return getMaxX()-getMinX(); }
140 double height()
const {
return getMaxY()-getMinY(); }
145 double length(
unsigned const d)
const {
146 COLA_ASSERT(d==0||d==1);
147 return ( d == 0 ? width() : height() );
149 void set_width(
double w) { maxX = minX + w - 2.0*xBorder; }
150 void set_height(
double h) { maxY = minY + h - 2.0*yBorder; }
151 void moveCentreD(
const unsigned d,
double p) {
152 COLA_ASSERT(d==0||d==1);
153 if(d == 0) { moveCentreX(p);
154 }
else { moveCentreY(p); }
156 void moveCentreX(
double x) {
157 moveMinX(x-width()/2.0);
159 void moveCentreY(
double y) {
160 moveMinY(y-height()/2.0);
162 void moveCentre(
double x,
double y) {
166 void moveMinX(
double x) {
170 COLA_ASSERT(fabs(width()-w)<1e-9);
172 void moveMinY(
double y) {
176 COLA_ASSERT(fabs(height()-h)<1e-9);
178 double overlapD(
const unsigned d,
Rectangle* r) {
186 double ux=getCentreX(), vx=r->getCentreX();
187 if (ux <= vx && r->getMinX() < getMaxX())
188 return getMaxX() - r->getMinX();
189 if (vx <= ux && getMinX() < r->getMaxX())
190 return r->getMaxX() - getMinX();
194 double uy=getCentreY(), vy=r->getCentreY();
195 if (uy <= vy && r->getMinY() < getMaxY()) {
196 return getMaxY() - r->getMinY();
198 if (vy <= uy && getMinY() < r->getMaxY()) {
199 return r->getMaxY() - getMinY();
203 bool allowOverlap() {
206 void offset(
double dx,
double dy) {
216 void lineIntersections(
double x1,
double y1,
double x2,
double y2, RectangleIntersections &ri)
const;
217 bool inside(
double x,
double y)
const {
218 return x>getMinX() && x<getMaxX() && y>getMinY() && y<getMaxY();
222 bool overlaps(
double x1,
double y1,
double x2,
double y2);
225 void routeAround(
double x1,
double y1,
double x2,
double y2,
226 std::vector<double> &xs, std::vector<double> &ys);
236 static double xBorder,yBorder;
237 static void setXBorder(
double x) {xBorder=x;}
238 static void setYBorder(
double y) {yBorder=y;}
241 double minX,maxX,minY,maxY;
251 typedef std::vector<Variable *>
Variables;
290 bool thirdPass =
true);
293 bool noRectangleOverlaps(
const Rectangles& rs);
297 template <
typename T>
298 void operator()(T *ptr){
delete ptr;}
302 #endif // VPSC_RECTANGLE_H A variable is comprised of an ideal position, final position and a weight.
Definition: variable.h:44
The x-dimension (0).
Definition: rectangle.h:45
libvpsc: Variable Placement with Separation Constraints quadratic program solver library.
Definition: assertions.h:61
std::vector< Variable * > Variables
A vector of pointers to Variable objects.
Definition: constraint.h:38
std::vector< Constraint * > Constraints
A vector of pointers to Constraint objects.
Definition: constraint.h:125
std::vector< Rectangle * > Rectangles
A vector of pointers to Rectangle objects.
Definition: rectangle.h:246
A constraint determines a minimum or exact spacing required between two Variable objects.
Definition: constraint.h:44
void removeoverlaps(Rectangles &rs)
Uses VPSC to remove overlaps between rectangles.
Definition: rectangle.cpp:563
A rectangle represents a fixed-size shape in the diagram that may be moved to prevent overlaps and sa...
Definition: rectangle.h:78
The y-dimension (1).
Definition: rectangle.h:47
The x-dimension (0).
Definition: rectangle.h:43
Dim
Indicates the x- or y-dimension.
Definition: rectangle.h:41
The y-dimension (1).
Definition: rectangle.h:49