Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

geometry.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/basic/Array.h>
36 #include <ogdf/basic/EpsilonTest.h>
37 #include <ogdf/basic/List.h>
38 #include <ogdf/basic/Math.h>
39 #include <ogdf/basic/basic.h>
40 
41 #include <algorithm>
42 #include <cmath>
43 #include <limits>
44 #include <ostream>
45 #include <utility>
46 
47 namespace ogdf {
48 enum class Shape;
49 template<class K>
51 
53 
55 enum class Orientation {
56  topToBottom,
57  bottomToTop,
58  leftToRight,
60 };
61 
63 enum class IntersectionType {
64  None,
65  SinglePoint,
67 };
68 
80 template<typename T>
81 class GenericPoint {
82 public:
84  using numberType = T;
85 
86  T m_x;
87  T m_y;
88 
90  explicit GenericPoint(T x = 0, T y = 0) : m_x(x), m_y(y) { }
91 
93  GenericPoint(const GenericPoint<T>& p) : m_x(p.m_x), m_y(p.m_y) { }
94 
97  if (this != &p) {
98  m_x = p.m_x;
99  m_y = p.m_y;
100  }
101  return *this;
102  }
103 
105  bool operator==(const GenericPoint<T>& dp) const {
106  // OGDF_GEOM_ET uses different methods for integers and floats
107  return OGDF_GEOM_ET.equal(m_x, dp.m_x) && OGDF_GEOM_ET.equal(m_y, dp.m_y);
108  }
109 
111  bool operator!=(const GenericPoint<T>& p) const { return !(*this == p); }
112 
115  bool operator<(const GenericPoint<T>& p) const {
116  // OGDF_GEOM_ET uses different methods for integers and floats
117  return OGDF_GEOM_ET.less(m_x, p.m_x)
118  || (OGDF_GEOM_ET.equal(m_x, p.m_x) && OGDF_GEOM_ET.less(m_y, p.m_y));
119  }
120 
122  bool operator>(const GenericPoint<T>& p) const { return p < *this; }
123 
126  return GenericPoint<T>(m_x + p.m_x, m_y + p.m_y);
127  }
128 
131  return GenericPoint<T>(m_x - p.m_x, m_y - p.m_y);
132  }
133 
136  const double dx1 = q.m_x - m_x, dy1 = q.m_y - m_y;
137  const double dx2 = r.m_x - m_x, dy2 = r.m_y - m_y;
138 
139  // two vertices on the same place!
140  if ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)) {
141  return 0.0;
142  }
143 
144  double phi = std::atan2(dy2, dx2) - std::atan2(dy1, dx1);
145  if (phi < 0) {
146  phi += 2 * Math::pi;
147  }
148 
149  return phi;
150  }
151 
154  return Math::radiansToDegrees(angle(q, r));
155  }
156 
158  double distance(const GenericPoint<T>& p) const {
159  double dx = p.m_x - m_x;
160  double dy = p.m_y - m_y;
161  return sqrt(dx * dx + dy * dy);
162  }
163 
165  double norm() const { return sqrt(m_x * m_x + m_y * m_y); }
166 
169  m_x += p.m_x;
170  m_y += p.m_y;
171  return *this;
172  }
173 
176  m_x -= p.m_x;
177  m_y -= p.m_y;
178  return *this;
179  }
180 
183  m_x *= c;
184  m_y *= c;
185  return *this;
186  }
187 
189  friend GenericPoint<T> operator*(T c, const GenericPoint<T>& p) {
190  return GenericPoint<T>(c * p.m_x, c * p.m_y);
191  }
192 
194  friend GenericPoint<T> operator*(const GenericPoint<T>& p, T c) {
195  return GenericPoint<T>(c * p.m_x, c * p.m_y);
196  }
197 
200  m_x /= c;
201  m_y /= c;
202  return *this;
203  }
204 
206  friend GenericPoint<T> operator/(const GenericPoint<T>& p, double c) {
207  return GenericPoint<T>(p.m_x / c, p.m_y / c);
208  }
209 
211  T determinant(const GenericPoint<T>& dv) const { return (m_x * dv.m_y) - (m_y * dv.m_x); }
212 
214  T operator*(const GenericPoint<T>& dv) const { return (m_x * dv.m_x) + (m_y * dv.m_y); }
215 
223  GenericPoint<T> ret(1, 1);
224  if (m_x != 0.0) {
225  ret.m_x = -m_y / m_x;
226  } else {
227  ret.m_y = 0.0;
228  }
229  return ret;
230  }
231 };
232 
234 template<typename T>
235 std::ostream& operator<<(std::ostream& os, const GenericPoint<T>& p) {
236  os << "(" << p.m_x << "," << p.m_y << ")";
237  return os;
238 }
239 
242 
245 
246 template<>
248 public:
249  int hash(const IPoint& ip) const { return 7 * ip.m_x + 23 * ip.m_y; }
250 };
251 
260 template<class PointType>
261 class GenericPolyline : public List<PointType> {
262 public:
265 
267  GenericPolyline(const List<PointType>& pl) : List<PointType>(pl) { }
268 
270  GenericPolyline(const GenericPolyline<PointType>& pl) : List<PointType>(pl) { }
271 
275  return *this;
276  }
277 
279  double length() const {
280  OGDF_ASSERT(!this->empty());
281 
282  double len = 0.0;
283  ListConstIterator<PointType> pred, iter;
284 
285  pred = iter = this->begin();
286  ++iter;
287 
288  while (iter.valid()) {
289  len += (*iter).distance(*pred);
290  ++pred;
291  ++iter;
292  }
293 
294  return len;
295  }
296 
304  DPoint position(const double fraction, double len = -1.0) const {
305  OGDF_ASSERT(!this->empty());
306  OGDF_ASSERT(fraction >= 0.0);
307  OGDF_ASSERT(fraction <= 1.0);
308  if (len < 0.0) {
309  len = length();
310  }
311  OGDF_ASSERT(len >= 0.0);
312 
313  DPoint p = *(this->begin());
314  double liter = 0.0;
315  double pos = len * fraction;
316  double seglen = 0.0;
317  ListConstIterator<PointType> pred, iter;
318 
319  pred = iter = this->begin();
320  ++iter;
321 
322  // search the segment, which contains the desired point
323  double DX = 0, DY = 0; // for further use
324  while (iter.valid()) {
325  DX = (*iter).m_x - (*pred).m_x;
326  DY = (*iter).m_y - (*pred).m_y;
327  seglen = sqrt(DX * DX + DY * DY);
328  liter += seglen;
329  if (liter >= pos) {
330  break;
331  }
332  ++pred;
333  ++iter;
334  }
335 
336  if (!iter.valid()) { // position not inside the polyline, return last point!
337  p = *(this->rbegin());
338  } else {
339  if (seglen == 0.0) { // *pred == *iter and pos is inbetween
340  return *pred;
341  }
342 
343  double segpos = seglen + pos - liter;
344 
345  double dx = DX * segpos / seglen;
346  double dy = DY * segpos / seglen;
347 
348  p = *pred;
349  p.m_x += dx;
350  p.m_y += dy;
351  }
352 
353  return p;
354  }
355 
357  void unify() {
358  if (this->empty()) {
359  return;
360  }
361  ListIterator<PointType> iter, next;
362  for (iter = next = this->begin(), ++next; next.valid() && (this->size() > 2); ++next) {
363  if (*iter == *next) {
364  this->del(next);
365  next = iter;
366  } else {
367  iter = next;
368  }
369  }
370  }
371 
372 protected:
378  void normalizeUnified(double minAngle) {
379  OGDF_ASSERT(OGDF_GEOM_ET.geq(minAngle, 0.0));
380  OGDF_ASSERT(OGDF_GEOM_ET.leq(minAngle, Math::pi));
381 
382  double maxAngle = 2 * Math::pi - minAngle;
383  ListIterator<PointType> iter = this->begin();
384  ListIterator<PointType> next, onext;
385 
386  while (iter.valid()) {
387  next = iter;
388  ++next;
389  if (!next.valid()) {
390  break;
391  }
392  onext = next;
393  ++onext;
394  if (!onext.valid()) {
395  break;
396  }
397  double phi = (*next).angle(*iter, *onext);
398 
399  // Is *next on the way from *iter to *onext?
400  if (OGDF_GEOM_ET.geq(phi, minAngle) && OGDF_GEOM_ET.leq(phi, maxAngle)) {
401  this->del(next);
402  if (iter != this->begin()) {
403  --iter;
404  }
405  } else {
406  ++iter;
407  }
408  }
409  }
410 
411 public:
414 
428  void normalize(double minAngle = Math::pi) {
429  unify();
430  normalizeUnified(minAngle);
431  }
432 
438  void normalize(PointType src, PointType tgt, double minAngle = Math::pi) {
439  unify();
440  this->pushFront(src);
441  this->pushBack(tgt);
442  normalize(minAngle);
443  this->popFront();
444  this->popBack();
445  }
446 };
447 
450 
453 
455 template<class PointType>
456 class GenericLine {
457 public:
458  using numberType = typename PointType::numberType;
459 
460 protected:
461  PointType m_p1;
462  PointType m_p2;
463 
465  numberType dx() const { return m_p2.m_x - m_p1.m_x; }
466 
468  numberType dy() const { return m_p2.m_y - m_p1.m_y; }
469 
470 public:
472  GenericLine() : m_p1(), m_p2() { }
473 
475  GenericLine(const PointType& p1, const PointType& p2) : m_p1(p1), m_p2(p2) { }
476 
479 
482  : GenericLine(PointType(x1, y1), PointType(x2, y2)) { }
483 
485  bool operator==(const GenericLine<PointType>& dl) const {
486  return isVertical() ? dl.isVertical() && m_p1.m_x == dl.m_p1.m_x
487  : slope() == dl.slope() && yAbs() == dl.yAbs();
488  }
489 
491  bool operator!=(const GenericLine<PointType>& dl) const { return !(*this == dl); }
492 
495  if (this != &dl) { // don't assign myself
496  m_p1 = dl.m_p1;
497  m_p2 = dl.m_p2;
498  }
499  return *this;
500  }
501 
503  bool isVertical() const { return OGDF_GEOM_ET.equal(dx(), 0.0); }
504 
506  bool isHorizontal() const { return OGDF_GEOM_ET.equal(dy(), 0.0); }
507 
509  double slope() const { return isVertical() ? std::numeric_limits<double>::max() : dy() / dx(); }
510 
513  double yAbs() const {
514  return isVertical() ? std::numeric_limits<double>::max() : m_p1.m_y - (slope() * m_p1.m_x);
515  }
516 
524  double det(const GenericLine<PointType>& line) const {
525  return dx() * line.dy() - dy() * line.dx();
526  }
527 
537  if (isVertical() && line.isVertical()) {
538  inter = m_p1;
541  } else if (isVertical()) {
542  inter = DPoint(m_p1.m_x, line.slope() * m_p1.m_x + line.yAbs());
544  } else if (line.isVertical()) {
545  inter = DPoint(line.m_p1.m_x, slope() * line.m_p1.m_x + yAbs());
547  } else if (OGDF_GEOM_ET.equal(slope(), line.slope())) {
548  // For parallel lines only return true if the lines are equal.
549  inter = m_p1;
552  } else {
553  double ix = (line.yAbs() - yAbs()) / (slope() - line.slope());
554  inter = DPoint(ix, slope() * ix + yAbs());
556  }
557  }
558 
560  virtual bool contains(const DPoint& p) const {
561  if (p == m_p1 || p == m_p2) {
562  return true;
563  }
564 
565  if (isVertical()) {
566  return OGDF_GEOM_ET.equal(p.m_x, m_p1.m_x);
567  }
568 
569  double dx2p = p.m_x - m_p1.m_x;
570  double dy2p = p.m_y - m_p1.m_y;
571 
572  // dx() != 0.0 since this line is not vertical.
573  if (dx2p == 0.0) {
574  return false;
575  }
576 
577  return OGDF_GEOM_ET.equal(slope(), (dy2p / dx2p));
578  }
579 
588  virtual IntersectionType horIntersection(const double horAxis, double& crossing) const {
589  if (isHorizontal()) {
590  crossing = 0.0;
592  }
593  crossing = (m_p1.m_x * (m_p2.m_y - horAxis) - m_p2.m_x * (m_p1.m_y - horAxis)) / dy();
595  }
596 
605  virtual IntersectionType verIntersection(const double verAxis, double& crossing) const {
606  if (isVertical()) {
607  crossing = 0.0;
609  }
610  crossing = (m_p1.m_y * (m_p2.m_x - verAxis) - m_p2.m_y * (m_p1.m_x - verAxis)) / dx();
612  }
613 };
614 
616 template<class PointType>
617 std::ostream& operator<<(std::ostream& os, const GenericLine<PointType>& line) {
618  if (line.isVertical()) {
619  os << "Line: vertical with x = " << line.m_p1.m_x;
620  } else {
621  os << "Line: f(x) = " << line.slope() << "x + " << line.yAbs();
622  }
623  return os;
624 }
625 
628 
630 template<class PointType>
631 class GenericSegment : public GenericLine<PointType> {
632 private:
635 
640  bool inBoundingRect(const PointType& p, bool includeBorders = true) const {
641  double minx = min(this->m_p1.m_x, this->m_p2.m_x);
642  double miny = min(this->m_p1.m_y, this->m_p2.m_y);
643  double maxx = max(this->m_p1.m_x, this->m_p2.m_x);
644  double maxy = max(this->m_p1.m_y, this->m_p2.m_y);
645 
646  if (includeBorders) {
647  return OGDF_GEOM_ET.geq(p.m_x, minx) && OGDF_GEOM_ET.leq(p.m_x, maxx)
648  && OGDF_GEOM_ET.geq(p.m_y, miny) && OGDF_GEOM_ET.leq(p.m_y, maxy);
649  } else {
650  return OGDF_GEOM_ET.greater(p.m_x, minx) && OGDF_GEOM_ET.less(p.m_x, maxx)
651  && OGDF_GEOM_ET.greater(p.m_y, miny) && OGDF_GEOM_ET.less(p.m_y, maxy);
652  }
653  }
654 
655 public:
657  GenericSegment() : GenericLine<PointType>() { }
658 
660  GenericSegment(const PointType& p1, const PointType& p2) : GenericLine<PointType>(p1, p2) { }
661 
663  explicit GenericSegment(const GenericLine<PointType>& dl) : GenericLine<PointType>(dl) { }
664 
666  GenericSegment(double x1, double y1, double x2, double y2)
667  : GenericLine<PointType>(x1, y1, x2, y2) { }
668 
670  GenericSegment(const GenericSegment<PointType>& ds) = default;
671 
673  GenericSegment& operator=(const GenericSegment<PointType>& ds) = default;
674 
676  bool operator==(const GenericSegment<PointType>& dl) const {
677  return this->m_p1 == dl.m_p1 && this->m_p2 == dl.m_p2;
678  }
679 
681  bool operator!=(const GenericSegment<PointType>& dl) const { return !(*this == dl); }
682 
684  const PointType& start() const { return this->m_p1; }
685 
687  const PointType& end() const { return this->m_p2; }
688 
691 
694 
705  IntersectionType intersection(const GenericSegment<PointType>& segment, PointType& inter,
706  bool endpoints = true) const {
707  IntersectionType lineIntersection = GenericLine<PointType>::intersection(segment, inter);
708 
709  if (lineIntersection == IntersectionType::None) {
710  return IntersectionType::None;
711  } else if (lineIntersection == IntersectionType::SinglePoint) {
712  return inBoundingRect(inter, endpoints) && segment.inBoundingRect(inter, endpoints)
715  } else {
716  // Let inter be the second smallest point of this/the given segment.
717  Array<DPoint> points({this->m_p1, this->m_p2, segment.m_p1, segment.m_p2});
718  std::sort(points.begin(), points.end(), [](DPoint p1, DPoint p2) { return p1 < p2; });
719  inter = points[1];
720 
721  if (!inBoundingRect(inter, endpoints) || !segment.inBoundingRect(inter, endpoints)) {
722  return IntersectionType::None;
723  } else if (points[1] == points[2] && !(this->m_p1 == inter && this->m_p2 == inter)
724  && !(segment.m_p1 == inter && segment.m_p2 == inter)) {
725  // There is an intersection at a single point inter, which is
726  // both an endpoint of this and an endpoint of the other segment.
728  } else {
730  }
731  }
732  }
733 
735  bool contains(const PointType& p) const override {
737  }
738 
740  double length() const { return this->m_p1.distance(this->m_p2); }
741 
751  IntersectionType horIntersection(const double horAxis, double& crossing) const override {
752  IntersectionType result = GenericLine<PointType>::horIntersection(horAxis, crossing);
753  if (result != IntersectionType::SinglePoint) {
754  return result;
755  } else if (inBoundingRect(DPoint(crossing, horAxis))) {
757  } else {
758  crossing = 0.0;
759  return IntersectionType::None;
760  }
761  }
762 
772  IntersectionType verIntersection(const double verAxis, double& crossing) const override {
773  IntersectionType result = GenericLine<PointType>::verIntersection(verAxis, crossing);
774  if (result != IntersectionType::SinglePoint) {
775  return result;
776  } else if (inBoundingRect(DPoint(verAxis, crossing))) {
778  } else {
779  crossing = 0.0;
780  return IntersectionType::None;
781  }
782  }
783 };
784 
786 template<class PointType>
787 std::ostream& operator<<(std::ostream& os, const GenericSegment<PointType>& dl) {
788  os << "Segment-Start: " << dl.start() << ", Segment-End: " << dl.end();
789  return os;
790 }
791 
794 
799  friend OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const DRect& dr);
800 
801 protected:
804 
805 public:
807  DRect() = default;
808 
810  DRect(const DPoint& p1, const DPoint& p2) : m_p1(p1), m_p2(p2) { normalize(); }
811 
813  DRect(const DRect& dr) : m_p1(dr.m_p1), m_p2(dr.m_p2) { }
814 
816  DRect(double x1, double y1, double x2, double y2) : DRect(DPoint(x1, y1), DPoint(x2, y2)) { }
817 
819  explicit DRect(const DSegment& dl) : DRect(dl.start(), dl.end()) { }
820 
821  virtual ~DRect() = default;
822 
824  bool operator==(const DRect& dr) const { return m_p1 == dr.m_p1 && m_p2 == dr.m_p2; }
825 
827  bool operator!=(const DRect& dr) const { return !(*this == dr); }
828 
830  DRect& operator=(const DRect& dr) {
831  if (this != &dr) { // don't assign myself
832  m_p1 = dr.m_p1;
833  m_p2 = dr.m_p2;
834  }
835  return *this;
836  }
837 
839  double width() const { return m_p2.m_x - m_p1.m_x; }
840 
842  double height() const { return m_p2.m_y - m_p1.m_y; }
843 
850  void normalize() {
851  if (width() < 0) {
852  std::swap(m_p2.m_x, m_p1.m_x);
853  }
854  if (height() < 0) {
855  std::swap(m_p2.m_y, m_p1.m_y);
856  }
857  }
858 
860  const DPoint& p1() const { return m_p1; }
861 
863  const DPoint& p2() const { return m_p2; }
864 
866  const DSegment top() const {
867  return DSegment(DPoint(m_p1.m_x, m_p2.m_y), DPoint(m_p2.m_x, m_p2.m_y));
868  }
869 
871  const DSegment right() const {
872  return DSegment(DPoint(m_p2.m_x, m_p2.m_y), DPoint(m_p2.m_x, m_p1.m_y));
873  }
874 
876  const DSegment left() const {
877  return DSegment(DPoint(m_p1.m_x, m_p1.m_y), DPoint(m_p1.m_x, m_p2.m_y));
878  }
879 
881  const DSegment bottom() const {
882  return DSegment(DPoint(m_p2.m_x, m_p1.m_y), DPoint(m_p1.m_x, m_p1.m_y));
883  }
884 
886  void yInvert() { std::swap(m_p1.m_y, m_p2.m_y); }
887 
889  void xInvert() { std::swap(m_p1.m_x, m_p2.m_x); }
890 
892  bool contains(const DPoint& p) const {
893  return OGDF_GEOM_ET.geq(p.m_x, m_p1.m_x) && OGDF_GEOM_ET.leq(p.m_x, m_p2.m_x)
894  && OGDF_GEOM_ET.geq(p.m_y, m_p1.m_y) && OGDF_GEOM_ET.leq(p.m_y, m_p2.m_y);
895  }
896 
898  bool intersection(const DSegment& segment) const {
899  DPoint inter;
900  return segment.intersection(top(), inter) != IntersectionType::None
901  || segment.intersection(bottom(), inter) != IntersectionType::None
902  || segment.intersection(right(), inter) != IntersectionType::None
903  || segment.intersection(left(), inter) != IntersectionType::None;
904  }
905 
906 protected:
908  double parallelDist(const DSegment& d1, const DSegment& d2) const;
909 
911  double pointDist(const DPoint& p1, const DPoint& p2) const {
912  return sqrt((p1.m_y - p2.m_y) * (p1.m_y - p2.m_y) + (p1.m_x - p2.m_x) * (p1.m_x - p2.m_x));
913  }
914 };
915 
923  friend OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const DIntersectableRect& dr);
924 
925  double m_area = 0.0;
927 
932  void initAreaAndCenter();
933 
934 public:
936  DIntersectableRect() = default;
937 
939  DIntersectableRect(const DPoint& p1, const DPoint& p2) : DRect(p1, p2) { initAreaAndCenter(); }
940 
942  DIntersectableRect(double x1, double y1, double x2, double y2)
943  : DIntersectableRect(DPoint(x1, y1), DPoint(x2, y2)) { }
944 
947  : DRect(static_cast<DRect>(dr)), m_area(dr.m_area), m_center(dr.m_center) { }
948 
950  DIntersectableRect(const DPoint& center, double width, double height)
951  : DIntersectableRect(DPoint(center.m_x - width / 2, center.m_y - height / 2),
952  DPoint(center.m_x + width / 2, center.m_y + height / 2)) {};
953 
956  if (this != &dr) { // don't assign myself
957  m_p1 = dr.m_p1;
958  m_p2 = dr.m_p2;
959  m_center = dr.m_center;
960  m_area = dr.m_area;
961  }
962  return *this;
963  }
964 
966  DPoint center() const { return m_center; }
967 
969  double area() const { return m_area; }
970 
972  bool intersects(const DIntersectableRect& rectangle) const;
973 
977  DIntersectableRect intersection(const DIntersectableRect& other) const;
978 
980  double distance(const DIntersectableRect& other) const;
981 
983  void move(const DPoint& point);
984 };
985 
990 protected:
992 
993 public:
1000  DPolygon(bool cc = true) : m_counterclock(cc) { }
1001 
1003  explicit DPolygon(const DRect& rect, bool cc = true) : m_counterclock(cc) { operator=(rect); }
1004 
1006  DPolygon(const DPolygon& dop) : DPolyline(dop), m_counterclock(dop.m_counterclock) { }
1007 
1009  bool counterclock() { return m_counterclock; }
1010 
1012  DPolygon& operator=(const DPolygon& dop) {
1014  m_counterclock = dop.m_counterclock;
1015  return *this;
1016  }
1017 
1019  DPolygon& operator=(const DRect& rect);
1020 
1022  DSegment segment(ListConstIterator<DPoint> it) const;
1023 
1026 
1032  ListIterator<DPoint> insertPoint(const DPoint& p, ListIterator<DPoint> p1,
1034 
1036  void insertCrossPoint(const DPoint& p);
1037 
1039  int getCrossPoints(const DPolygon& p, List<DPoint>& crossPoints) const;
1040 
1042  void unify();
1043 
1045  void normalize();
1046 
1053  bool containsPoint(DPoint& p) const;
1054 };
1055 
1057 OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const DPolygon& dop);
1058 
1059 int orientation(const DPoint& p, const DPoint& q, const DPoint& r);
1060 
1061 inline int orientation(const DSegment& s, const DPoint& p) {
1062  return orientation(s.start(), s.end(), p);
1063 }
1064 
1075 OGDF_EXPORT bool isPointCoveredByNode(const DPoint& point, const DPoint& v, const DPoint& vSize,
1076  const Shape& shape);
1077 
1087 OGDF_EXPORT DPoint contourPointFromAngle(double angle, int n, double rotationOffset = 0,
1088  const DPoint& center = DPoint(), const DPoint& vSize = DPoint(1, 1));
1089 
1098 OGDF_EXPORT DPoint contourPointFromAngle(double angle, Shape shape, const DPoint& center = DPoint(),
1099  const DPoint& vSize = DPoint(1, 1));
1100 }
ogdf::DPolygon::DPolygon
DPolygon(const DRect &rect, bool cc=true)
Creates a polgon from a rectangle.
Definition: geometry.h:1003
ogdf::DSegment
GenericSegment< DPoint > DSegment
Segments with real coordinates.
Definition: geometry.h:793
ogdf::GenericSegment::GenericSegment
GenericSegment(const GenericLine< PointType > &dl)
Creates a line segment defined by the start and end point of line dl.
Definition: geometry.h:663
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::DIntersectableRect::DIntersectableRect
DIntersectableRect(const DPoint &center, double width, double height)
Constructs a rectangle from the center point, width and height.
Definition: geometry.h:950
ogdf::DRect::xInvert
void xInvert()
Swaps the x-coordinates of the two points.
Definition: geometry.h:889
ogdf::GenericPolyline::GenericPolyline
GenericPolyline()
Creates an empty polyline.
Definition: geometry.h:264
ogdf::GenericLine::det
double det(const GenericLine< PointType > &line) const
Determines if line is left or right of this line.
Definition: geometry.h:524
ogdf::GenericSegment::dx
GenericLine< PointType >::numberType dx() const
Returns the x-coordinate of the difference (end point - start point).
Definition: geometry.h:690
ogdf::GenericPoint::operator/
friend GenericPoint< T > operator/(const GenericPoint< T > &p, double c)
Point-wise divide p by c.
Definition: geometry.h:206
ogdf::DRect::operator==
bool operator==(const DRect &dr) const
Equality operator: both rectangles have the same coordinates.
Definition: geometry.h:824
ogdf::GenericPoint::operator+=
GenericPoint< T > & operator+=(const GenericPoint< T > &p)
Adds p to this.
Definition: geometry.h:168
ogdf::DefHashFunc
Default hash functions.
Definition: geometry.h:50
EpsilonTest.h
Compare floating point numbers with epsilons and integral numbers with normal compare operators.
ogdf::Orientation::bottomToTop
@ bottomToTop
Edges are oriented from bottom to top.
ogdf::GenericPoint
Parameterized base class for points.
Definition: geometry.h:81
ogdf::GenericPoint::GenericPoint
GenericPoint(T x=0, T y=0)
Creates a generic point (x,y).
Definition: geometry.h:90
ogdf::DPolygon::DPolygon
DPolygon(const DPolygon &dop)
Copy constructor.
Definition: geometry.h:1006
ogdf::EpsilonTest
Definition: EpsilonTest.h:39
ogdf::GenericSegment::horIntersection
IntersectionType horIntersection(const double horAxis, double &crossing) const override
Computes the intersection of this line segment and the horizontal line through y = horAxis.
Definition: geometry.h:751
ogdf::DRect::DRect
DRect(double x1, double y1, double x2, double y2)
Creates a rectangle with lower left point (x1,y1) and upper right point (x2,y2).
Definition: geometry.h:816
ogdf::DRect::DRect
DRect(const DPoint &p1, const DPoint &p2)
Creates a rectangle with lower left point p1 and upper right point p2.
Definition: geometry.h:810
ogdf::GenericLine::m_p2
PointType m_p2
The second point of the line.
Definition: geometry.h:462
ogdf::GenericSegment::intersection
IntersectionType intersection(const GenericSegment< PointType > &segment, PointType &inter, bool endpoints=true) const
Returns an IntersectionType specifying whether segment and this line segment intersect.
Definition: geometry.h:705
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::GenericLine::GenericLine
GenericLine(const GenericLine< PointType > &dl)
Copy constructor.
Definition: geometry.h:478
ogdf::List< PointType >::popFront
void popFront()
Removes the first element from the list.
Definition: List.h:1585
ogdf::DPolygon::insertPoint
ListIterator< DPoint > insertPoint(const DPoint &p)
Inserts point p, that must lie on a polygon segment.
Definition: geometry.h:1025
ogdf::GenericLine::operator==
bool operator==(const GenericLine< PointType > &dl) const
Equality operator.
Definition: geometry.h:485
ogdf::GenericSegment::start
const PointType & start() const
Returns the start point of the line segment.
Definition: geometry.h:684
ogdf::begin
HypergraphRegistry< HypernodeElement >::iterator begin(const HypergraphRegistry< HypernodeElement > &self)
ogdf::GenericPoint::m_y
T m_y
The y-coordinate.
Definition: geometry.h:87
ogdf::GenericPoint::operator*
friend GenericPoint< T > operator*(T c, const GenericPoint< T > &p)
Point-wise multiplies p with c.
Definition: geometry.h:189
ogdf::GenericPolyline::unify
void unify()
Deletes all successive points with equal coordinates.
Definition: geometry.h:357
ogdf::GenericLine
Infinite lines.
Definition: geometry.h:456
ogdf::GenericPolyline
Polylines with PointType points.
Definition: geometry.h:261
ogdf::DIntersectableRect::operator=
DIntersectableRect & operator=(const DIntersectableRect &dr)
Assignment operator.
Definition: geometry.h:955
ogdf::GenericLine::isHorizontal
bool isHorizontal() const
Returns true iff this line runs horizontally.
Definition: geometry.h:506
ogdf::DRect::m_p2
DPoint m_p2
The upper right point of the rectangle.
Definition: geometry.h:803
ogdf::DIntersectableRect::DIntersectableRect
DIntersectableRect(const DPoint &p1, const DPoint &p2)
Creates a rectangle with lower left point p1 and upper right point p2.
Definition: geometry.h:939
ogdf::DRect::contains
bool contains(const DPoint &p) const
Returns true iff p lies within this rectangle, modulo the comparison epsilon OGDF_GEOM_ET.
Definition: geometry.h:892
ogdf::GenericPolyline::position
DPoint position(const double fraction, double len=-1.0) const
Returns a point on the polyline which is fraction * len away from the start point.
Definition: geometry.h:304
ogdf::GenericPoint::operator!=
bool operator!=(const GenericPoint< T > &p) const
Inequality operator.
Definition: geometry.h:111
ogdf::DRect::height
double height() const
Returns the height of the rectangle.
Definition: geometry.h:842
ogdf::DPolygon
Polygons with real coordinates.
Definition: geometry.h:989
ogdf::DIntersectableRect::area
double area() const
Area of the rectangle.
Definition: geometry.h:969
ogdf::ListIteratorBase::valid
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:153
ogdf::GenericLine::GenericLine
GenericLine()
Creates an empty line.
Definition: geometry.h:472
ogdf::GenericPoint::operator-=
GenericPoint< T > & operator-=(const GenericPoint< T > &p)
Subtracts p from this.
Definition: geometry.h:175
ogdf::GenericPolyline::normalizeUnified
void normalizeUnified(double minAngle)
Deletes all redundant points on the polyline that lie on a (nearly) straight line given by their adja...
Definition: geometry.h:378
ogdf::DRect::yInvert
void yInvert()
Swaps the y-coordinates of the two points.
Definition: geometry.h:886
ogdf::DRect::normalize
void normalize()
Normalizes the rectangle.
Definition: geometry.h:850
ogdf::List::operator=
List< E > & operator=(const List< E > &L)
Assignment operator.
Definition: List.h:1501
ogdf::GenericPoint::operator*=
GenericPoint< T > & operator*=(T c)
Point-wise multiplies this with c.
Definition: geometry.h:182
ogdf::DRect::top
const DSegment top() const
Returns the top side of the rectangle.
Definition: geometry.h:866
ogdf::GenericSegment::contains
bool contains(const PointType &p) const override
Returns true iff p lies on this line segment.
Definition: geometry.h:735
ogdf::DIntersectableRect
Rectangles with real coordinates.
Definition: geometry.h:922
ogdf::GenericLine::contains
virtual bool contains(const DPoint &p) const
Returns true iff p lies on this line.
Definition: geometry.h:560
ogdf::IntersectionType::SinglePoint
@ SinglePoint
Two geometric objects intersect in a single point.
ogdf::DRect::left
const DSegment left() const
Returns the left side of the rectangle.
Definition: geometry.h:876
ogdf::GenericPoint::distance
double distance(const GenericPoint< T > &p) const
Returns the Euclidean distance between p and this point.
Definition: geometry.h:158
ogdf::EpsilonTest::less
std::enable_if< std::is_integral< T >::value, bool >::type less(const T &x, const T &y) const
Compare if x is LESS than y for integral types.
Definition: EpsilonTest.h:55
ogdf::GenericPoint::m_x
T m_x
The x-coordinate.
Definition: geometry.h:86
Minisat::Internal::sort
void sort(T *array, int size, LessThan lt)
Definition: Sort.h:57
ogdf::Math::radiansToDegrees
double radiansToDegrees(const double &angleInRadians)
Converts an angle from radians to degrees.
Definition: Math.h:134
ogdf::GenericSegment
Finite line segments.
Definition: geometry.h:631
ogdf::GenericLine::dy
numberType dy() const
Returns the y-coordinate of the difference (second point - first point).
Definition: geometry.h:468
ogdf::GenericPoint::operator/=
GenericPoint< T > & operator/=(T c)
Point-wise divide this by c.
Definition: geometry.h:199
r
int r[]
Definition: hierarchical-ranking.cpp:13
ogdf::GenericLine::slope
double slope() const
Returns the slope of the line.
Definition: geometry.h:509
ogdf::OGDF_GEOM_ET
const EpsilonTest OGDF_GEOM_ET
ogdf::DRect::DRect
DRect(const DSegment &dl)
Creates a rectangle defined by the end points of line segment dl.
Definition: geometry.h:819
ogdf::DIntersectableRect::m_area
double m_area
Definition: geometry.h:925
ogdf::List< PointType >::pushFront
iterator pushFront(const PointType &x)
Adds element x at the beginning of the list.
Definition: List.h:1534
ogdf::DRect::m_p1
DPoint m_p1
The lower left point of the rectangle.
Definition: geometry.h:802
ogdf::DRect::p1
const DPoint & p1() const
Returns the lower left point of the rectangle.
Definition: geometry.h:860
backward::details::move
const T & move(const T &v)
Definition: backward.hpp:243
ogdf::Array
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:219
ogdf::GenericSegment::length
double length() const
Returns the length (Euclidean distance between start and end point) of this line segment.
Definition: geometry.h:740
ogdf::DRect
Rectangles with real coordinates.
Definition: geometry.h:798
ogdf::GenericPoint::norm
double norm() const
Returns the norm of the point.
Definition: geometry.h:165
ogdf::DPolygon::counterclock
bool counterclock()
Returns true iff points are given in counter-clockwise order.
Definition: geometry.h:1009
ogdf::GenericPolyline::normalize
void normalize(double minAngle=Math::pi)
Deletes all redundant points on the polyline that lie on a (nearly) straight line given by their adja...
Definition: geometry.h:428
ogdf::DRect::bottom
const DSegment bottom() const
Returns the bottom side of the rectangle.
Definition: geometry.h:881
ogdf::GenericLine::horIntersection
virtual IntersectionType horIntersection(const double horAxis, double &crossing) const
Computes the intersection of this line and the horizontal line through y = horAxis.
Definition: geometry.h:588
ogdf::GenericLine::intersection
IntersectionType intersection(const GenericLine< PointType > &line, DPoint &inter) const
Returns an IntersectionType specifying whether line and this line intersect.
Definition: geometry.h:536
ogdf::GenericPoint< int >::numberType
int numberType
The type for coordinates of the point.
Definition: geometry.h:84
ogdf::GenericPoint::GenericPoint
GenericPoint(const GenericPoint< T > &p)
Copy constructor.
Definition: geometry.h:93
ogdf::GenericLine::operator=
GenericLine< PointType > & operator=(const GenericLine< PointType > &dl)
Assignment operator.
Definition: geometry.h:494
ogdf::GenericPoint::operator*
T operator*(const GenericPoint< T > &dv) const
Returns the scalar product of this and dv.
Definition: geometry.h:214
ogdf::IntersectionType::Overlapping
@ Overlapping
Two geometric objects intersect in infinitely many points.
ogdf::GenericSegment::verIntersection
IntersectionType verIntersection(const double verAxis, double &crossing) const override
Computes the intersection between this line segment and the vertical line through x = verAxis.
Definition: geometry.h:772
ogdf::DIntersectableRect::DIntersectableRect
DIntersectableRect(double x1, double y1, double x2, double y2)
Creates a rectangle with lower left point (x1,y1) and upper right point (x1,y2).
Definition: geometry.h:942
ogdf::operator<<
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:983
ogdf::GenericPolyline::GenericPolyline
GenericPolyline(const GenericPolyline< PointType > &pl)
Copy constructor.
Definition: geometry.h:270
ogdf::DRect::DRect
DRect(const DRect &dr)
Copy constructor.
Definition: geometry.h:813
ogdf::GenericSegment::GenericSegment
GenericSegment()
Creates an empty line segment.
Definition: geometry.h:657
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: DfsMakeBiconnected.h:40
ogdf::GenericPolyline::GenericPolyline
GenericPolyline(const List< PointType > &pl)
Creates a polyline using the list of points pl.
Definition: geometry.h:267
ogdf::orientation
int orientation(const DPoint &p, const DPoint &q, const DPoint &r)
ogdf::EpsilonTest::greater
std::enable_if< std::is_integral< T >::value, bool >::type greater(const T &x, const T &y) const
Compare if x is GREATER than y for integral types.
Definition: EpsilonTest.h:159
ogdf::Math::pi
constexpr double pi
The constant .
Definition: Math.h:63
ogdf::Orientation::leftToRight
@ leftToRight
Edges are oriented from left to right.
ogdf::DRect::pointDist
double pointDist(const DPoint &p1, const DPoint &p2) const
Computes distance between two points.
Definition: geometry.h:911
ogdf::DPolygon::m_counterclock
bool m_counterclock
If true points are given in conter-clockwise order.
Definition: geometry.h:991
ogdf::IntersectionType
IntersectionType
Determines the type of intersection of two geometric objects.
Definition: geometry.h:63
Math.h
Mathematical Helpers.
ogdf::GenericPolyline::operator=
GenericPolyline< PointType > & operator=(const GenericPolyline &pl)
Assignment operator.
Definition: geometry.h:273
ogdf::GenericPoint::angle
double angle(GenericPoint< T > q, GenericPoint< T > r) const
Compute angle (in radians) between vectors.
Definition: geometry.h:135
ogdf::EpsilonTest::leq
std::enable_if< std::is_integral< T >::value, bool >::type leq(const T &x, const T &y) const
Compare if x is LEQ than y for integral types.
Definition: EpsilonTest.h:81
ogdf::Orientation
Orientation
Determines the orientation in hierarchical layouts.
Definition: geometry.h:55
ogdf::DRect::intersection
bool intersection(const DSegment &segment) const
Returns true iff segment intersects this DRect.
Definition: geometry.h:898
ogdf::GenericLine::yAbs
double yAbs() const
Returns the value y' such that (0,y') lies on the unlimited straight-line defined by this line.
Definition: geometry.h:513
ogdf::DIntersectableRect::DIntersectableRect
DIntersectableRect(const DIntersectableRect &dr)
Copy constructor.
Definition: geometry.h:946
ogdf::DPoint
GenericPoint< double > DPoint
Representing two-dimensional point with real coordinates.
Definition: geometry.h:244
ogdf::GenericPoint::operator=
GenericPoint< T > & operator=(const GenericPoint< T > &p)
Assignment operator.
Definition: geometry.h:96
ogdf::GenericPolyline::length
double length() const
Returns the Euclidean length of the polyline.
Definition: geometry.h:279
ogdf::GenericLine::GenericLine
GenericLine(numberType x1, numberType y1, numberType x2, numberType y2)
Creates a line through the points (x1,y1) and (x2,y2).
Definition: geometry.h:481
ogdf::EpsilonTest::equal
std::enable_if< std::is_integral< T >::value, bool >::type equal(const T &x, const T &y) const
Compare if x is EQUAL to y for integral types.
Definition: EpsilonTest.h:107
ogdf::DPolygon::operator=
DPolygon & operator=(const DPolygon &dop)
Assignment operator.
Definition: geometry.h:1012
ogdf::GenericPoint::angleDegrees
double angleDegrees(GenericPoint< T > q, GenericPoint< T > r) const
Compute angle (in degrees) between vectors.
Definition: geometry.h:153
ogdf::GenericPoint::operator+
GenericPoint< T > operator+(const GenericPoint< T > &p) const
Addition of points.
Definition: geometry.h:125
ogdf::Orientation::rightToLeft
@ rightToLeft
Edges are oriented from right to left.
ogdf::GenericPoint::operator-
GenericPoint< T > operator-(const GenericPoint< T > &p) const
Subtraction of points.
Definition: geometry.h:130
ogdf::GenericPolyline::normalize
void normalize(PointType src, PointType tgt, double minAngle=Math::pi)
Deletes all redundant points on the polyline that lie on a (nearly) straight line given by their adja...
Definition: geometry.h:438
ogdf::List< PointType >::del
void del(iterator it)
Removes it from the list.
Definition: List.h:1611
ogdf::DPolygon::DPolygon
DPolygon(bool cc=true)
Creates an empty polygon.
Definition: geometry.h:1000
basic.h
Basic declarations, included by all source files.
ogdf::List< PointType >::popBack
void popBack()
Removes the last element from the list.
Definition: List.h:1598
ogdf::end
HypergraphRegistry< HypernodeElement >::iterator end(const HypergraphRegistry< HypernodeElement > &self)
ogdf::DIntersectableRect::center
DPoint center() const
Center of the rectangle.
Definition: geometry.h:966
ogdf::GenericSegment::operator!=
bool operator!=(const GenericSegment< PointType > &dl) const
Inequality operator.
Definition: geometry.h:681
ogdf::GenericLine::numberType
typename PointType::numberType numberType
Definition: geometry.h:458
ogdf::GenericPoint::determinant
T determinant(const GenericPoint< T > &dv) const
Returns the determinant of the matrix (this, dv).
Definition: geometry.h:211
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::DRect::p2
const DPoint & p2() const
Returns the upper right point of the rectangle.
Definition: geometry.h:863
ogdf::DefHashFunc< IPoint >::hash
int hash(const IPoint &ip) const
Definition: geometry.h:249
ogdf::GenericLine::m_p1
PointType m_p1
The first point of the line.
Definition: geometry.h:461
ogdf::isPointCoveredByNode
bool isPointCoveredByNode(const DPoint &point, const DPoint &v, const DPoint &vSize, const Shape &shape)
Check whether this point lies within a node (using node shapes with same size and aspect as in TikZ).
Array.h
Declaration and implementation of Array class and Array algorithms.
ogdf::GenericLine::isVertical
bool isVertical() const
Returns true iff this line runs vertically.
Definition: geometry.h:503
ogdf::Shape
Shape
Types for node shapes.
Definition: graphics.h:120
List.h
Declaration of doubly linked lists and iterators.
ogdf::GenericPoint::operator==
bool operator==(const GenericPoint< T > &dp) const
Equality operator.
Definition: geometry.h:105
ogdf::GenericPoint::orthogonal
GenericPoint< T > orthogonal() const
Returns a vector that is orthogonal to this vector.
Definition: geometry.h:222
ogdf::DRect::width
double width() const
Returns the width of the rectangle.
Definition: geometry.h:839
ogdf::GenericSegment::dy
GenericLine< PointType >::numberType dy() const
Returns the y-coordinate of the difference (end point - start point).
Definition: geometry.h:693
ogdf::DRect::operator=
DRect & operator=(const DRect &dr)
Assignment operator.
Definition: geometry.h:830
ogdf::contourPointFromAngle
DPoint contourPointFromAngle(double angle, int n, double rotationOffset=0, const DPoint &center=DPoint(), const DPoint &vSize=DPoint(1, 1))
returns the point where a vector, pointing from center in direction of angle, intersects with the con...
ogdf::GenericLine::dx
numberType dx() const
Returns the x-coordinate of the difference (second point - first point).
Definition: geometry.h:465
ogdf::DRect::right
const DSegment right() const
Returns the right side of the rectangle.
Definition: geometry.h:871
ogdf::Orientation::topToBottom
@ topToBottom
Edges are oriented from top to bottom.
ogdf::List< PointType >::size
int size() const
Returns the number of elements in the list.
Definition: List.h:1488
ogdf::DIntersectableRect::m_center
DPoint m_center
Definition: geometry.h:926
ogdf::GenericSegment::inBoundingRect
bool inBoundingRect(const PointType &p, bool includeBorders=true) const
Returns whether p lies in the rectangle which has m_p1 and m_p2 as opposing corners.
Definition: geometry.h:640
ogdf::EpsilonTest::geq
std::enable_if< std::is_integral< T >::value, bool >::type geq(const T &x, const T &y) const
Compare if x is GEQ to y for integral types.
Definition: EpsilonTest.h:133
ogdf::GenericSegment::operator==
bool operator==(const GenericSegment< PointType > &dl) const
Equality operator.
Definition: geometry.h:676
ogdf::GenericLine::GenericLine
GenericLine(const PointType &p1, const PointType &p2)
Creates a line through the points p1 and p2.
Definition: geometry.h:475
ogdf::ListIteratorBase
Encapsulates a pointer to a list element.
Definition: List.h:51
ogdf::GenericLine::operator!=
bool operator!=(const GenericLine< PointType > &dl) const
Inequality operator.
Definition: geometry.h:491
ogdf::GenericSegment::end
const PointType & end() const
Returns the end point of the line segment.
Definition: geometry.h:687
ogdf::GenericSegment::GenericSegment
GenericSegment(const PointType &p1, const PointType &p2)
Creates a line segment from p1 to p2.
Definition: geometry.h:660
ogdf::GenericLine::verIntersection
virtual IntersectionType verIntersection(const double verAxis, double &crossing) const
Computes the intersection between this line and the vertical line through x = verAxis.
Definition: geometry.h:605
ogdf::GenericPoint::operator*
friend GenericPoint< T > operator*(const GenericPoint< T > &p, T c)
Point-wise multiplies p with c.
Definition: geometry.h:194
ogdf::IntersectionType::None
@ None
Two geometric objects do not intersect.
ogdf::GenericPoint::operator>
bool operator>(const GenericPoint< T > &p) const
Operator 'greater'. Returns true iff p is less than this.
Definition: geometry.h:122
ogdf::DRect::operator!=
bool operator!=(const DRect &dr) const
Inequality operator.
Definition: geometry.h:827
ogdf::GenericSegment::GenericSegment
GenericSegment(double x1, double y1, double x2, double y2)
Creates a line segment from (x1,y1) to (x2,y2).
Definition: geometry.h:666
ogdf::GenericPoint::operator<
bool operator<(const GenericPoint< T > &p) const
Operator 'less'. Returns true iff the x coordinate of this is less than the x coordinate of p or,...
Definition: geometry.h:115
ogdf::GenericSegment::operator=
GenericSegment & operator=(const GenericSegment< PointType > &ds)=default
Copy assignment operator.
ogdf::List< PointType >::pushBack
iterator pushBack(const PointType &x)
Adds element x at the end of the list.
Definition: List.h:1547