generate-constraints.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. class Rectangle {
  22. friend std::ostream& operator <<(std::ostream &os, const Rectangle &r);
  23. public:
  24. Rectangle(double x, double X, double y, double Y);
  25. double getMaxX() const { return maxX; }
  26. double getMaxY() const { return maxY; }
  27. double getMinX() const { return minX; }
  28. double getMinY() const { return minY; }
  29. double getCentreX() const { return minX+width()/2.0; }
  30. double getCentreY() const { return minY+height()/2.0; }
  31. double width() const { return getMaxX()-minX; }
  32. double height() const { return getMaxY()-minY; }
  33. double overlapX(const Rectangle &r) const {
  34. if (getCentreX() <= r.getCentreX() && r.minX < getMaxX())
  35. return getMaxX() - r.minX;
  36. if (r.getCentreX() <= getCentreX() && minX < r.getMaxX())
  37. return r.getMaxX() - minX;
  38. return 0;
  39. }
  40. double overlapY(const Rectangle &r) const {
  41. if (getCentreY() <= r.getCentreY() && r.minY < getMaxY())
  42. return getMaxY() - r.minY;
  43. if (r.getCentreY() <= getCentreY() && minY < r.getMaxY())
  44. return r.getMaxY() - minY;
  45. return 0;
  46. }
  47. private:
  48. double minX,maxX,minY,maxY;
  49. };
  50. struct Variable;
  51. struct Constraint;
  52. // returns number of constraints generated
  53. int generateXConstraints(const std::vector<Rectangle> &rs, Variable** vars,
  54. Constraint** &cs, const bool useNeighbourLists);
  55. int generateYConstraints(const std::vector<Rectangle> &rs, Variable** vars,
  56. Constraint** &cs);