Debian Codegraph @

lib/vpsc/generate-constraints.h

raw
1 /**
2 * \brief Functions to automatically generate constraints for the rectangular
3 * node overlap removal problem.
4 *
5 * Authors:
6 * Tim Dwyer <[email protected]>
7 *
8 * Copyright (C) 2005 Authors
9 *
10 * This version is released under the CPL (Common Public License) with
11 * the Graphviz distribution.
12 * A version is also available under the LGPL as part of the Adaptagrams
13 * project: https://github.com/mjwybrow/adaptagrams.
14 * If you make improvements or bug fixes to this code it would be much
15 * appreciated if you could also contribute those changes back to the
16 * Adaptagrams repository.
17 */
18 #pragma once
19 #include <iostream>
20 #include <vector>
21
22 class Rectangle {
23 friend std::ostream& operator <<(std::ostream &os, const Rectangle &r);
24 public:
25 Rectangle(double x, double X, double y, double Y);
26 double getMaxX() const { return maxX; }
27 double getMaxY() const { return maxY; }
28 double getMinX() const { return minX; }
29 double getMinY() const { return minY; }
30 double getCentreX() const { return minX+width()/2.0; }
31 double getCentreY() const { return minY+height()/2.0; }
32 double width() const { return getMaxX()-minX; }
33 double height() const { return getMaxY()-minY; }
34 double overlapX(const Rectangle &r) const {
35 if (getCentreX() <= r.getCentreX() && r.minX < getMaxX())
36 return getMaxX() - r.minX;
37 if (r.getCentreX() <= getCentreX() && minX < r.getMaxX())
38 return r.getMaxX() - minX;
39 return 0;
40 }
41 double overlapY(const Rectangle &r) const {
42 if (getCentreY() <= r.getCentreY() && r.minY < getMaxY())
43 return getMaxY() - r.minY;
44 if (r.getCentreY() <= getCentreY() && minY < r.getMaxY())
45 return r.getMaxY() - minY;
46 return 0;
47 }
48 private:
49 double minX,maxX,minY,maxY;
50 };
51
52
53 struct Variable;
54 struct Constraint;
55
56 // returns number of constraints generated
57 int generateXConstraints(const std::vector<Rectangle> &rs, Variable** vars,
58 Constraint** &cs, const bool useNeighbourLists);
59 int generateYConstraints(const std::vector<Rectangle> &rs, Variable** vars,
60 Constraint** &cs);