Code

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