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/EpsilonTest.h>
36 #include <ogdf/basic/Hashing.h>
37 #include <ogdf/basic/List.h>
38 #include <ogdf/basic/Math.h>
39 #include <ogdf/basic/graphics.h>
40 
41 #include <cfloat>
42 
43 namespace ogdf {
44 
45 extern OGDF_EXPORT const EpsilonTest OGDF_GEOM_ET;
46 
48 enum class Orientation {
49  topToBottom,
50  bottomToTop,
51  leftToRight,
53 };
54 
56 enum class IntersectionType {
57  None,
58  SinglePoint,
60 };
61 
73 template<typename T>
74 class GenericPoint {
75 public:
77  using numberType = T;
78 
79  T m_x;
80  T m_y;
81 
83  explicit GenericPoint(T x = 0, T y = 0) : m_x(x), m_y(y) { }
84 
86  GenericPoint(const GenericPoint<T>& p) : m_x(p.m_x), m_y(p.m_y) { }
87 
90  if (this != &p) {
91  m_x = p.m_x;
92  m_y = p.m_y;
93  }
94  return *this;
95  }
96 
98  bool operator==(const GenericPoint<T>& dp) const {
99  // OGDF_GEOM_ET uses different methods for integers and floats
100  return OGDF_GEOM_ET.equal(m_x, dp.m_x) && OGDF_GEOM_ET.equal(m_y, dp.m_y);
101  }
102 
104  bool operator!=(const GenericPoint<T>& p) const { return !(*this == p); }
105 
108  bool operator<(const GenericPoint<T>& p) const {
109  // OGDF_GEOM_ET uses different methods for integers and floats
110  return OGDF_GEOM_ET.less(m_x, p.m_x)
111  || (OGDF_GEOM_ET.equal(m_x, p.m_x) && OGDF_GEOM_ET.less(m_y, p.m_y));
112  }
113 
115  bool operator>(const GenericPoint<T>& p) const { return p < *this; }
116 
119  return GenericPoint<T>(m_x + p.m_x, m_y + p.m_y);
120  }
121 
124  return GenericPoint<T>(m_x - p.m_x, m_y - p.m_y);
125  }
126 
129  const double dx1 = q.m_x - m_x, dy1 = q.m_y - m_y;
130  const double dx2 = r.m_x - m_x, dy2 = r.m_y - m_y;
131 
132  // two vertices on the same place!
133  if ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)) {
134  return 0.0;
135  }
136 
137  double phi = std::atan2(dy2, dx2) - std::atan2(dy1, dx1);
138  if (phi < 0) {
139  phi += 2 * Math::pi;
140  }
141 
142  return phi;
143  }
144 
147  return Math::radiansToDegrees(angle(q, r));
148  }
149 
151  double distance(const GenericPoint<T>& p) const {
152  double dx = p.m_x - m_x;
153  double dy = p.m_y - m_y;
154  return sqrt(dx * dx + dy * dy);
155  }
156 
158  double norm() const { return sqrt(m_x * m_x + m_y * m_y); }
159 
162  m_x += p.m_x;
163  m_y += p.m_y;
164  return *this;
165  }
166 
169  m_x -= p.m_x;
170  m_y -= p.m_y;
171  return *this;
172  }
173 
176  m_x *= c;
177  m_y *= c;
178  return *this;
179  }
180 
182  friend GenericPoint<T> operator*(T c, const GenericPoint<T>& p) {
183  return GenericPoint<T>(c * p.m_x, c * p.m_y);
184  }
185 
187  friend GenericPoint<T> operator*(const GenericPoint<T>& p, T c) {
188  return GenericPoint<T>(c * p.m_x, c * p.m_y);
189  }
190 
193  m_x /= c;
194  m_y /= c;
195  return *this;
196  }
197 
199  friend GenericPoint<T> operator/(const GenericPoint<T>& p, double c) {
200  return GenericPoint<T>(p.m_x / c, p.m_y / c);
201  }
202 
204  T determinant(const GenericPoint<T>& dv) const { return (m_x * dv.m_y) - (m_y * dv.m_x); }
205 
207  T operator*(const GenericPoint<T>& dv) const { return (m_x * dv.m_x) + (m_y * dv.m_y); }
208 
216  GenericPoint<T> ret(1, 1);
217  if (m_x != 0.0) {
218  ret.m_x = -m_y / m_x;
219  } else {
220  ret.m_y = 0.0;
221  }
222  return ret;
223  }
224 };
225 
227 template<typename T>
228 std::ostream& operator<<(std::ostream& os, const GenericPoint<T>& p) {
229  os << "(" << p.m_x << "," << p.m_y << ")";
230  return os;
231 }
232 
235 
238 
239 template<>
241 public:
242  int hash(const IPoint& ip) const { return 7 * ip.m_x + 23 * ip.m_y; }
243 };
244 
253 template<class PointType>
254 class GenericPolyline : public List<PointType> {
255 public:
258 
260  GenericPolyline(const List<PointType>& pl) : List<PointType>(pl) { }
261 
263  GenericPolyline(const GenericPolyline<PointType>& pl) : List<PointType>(pl) { }
264 
268  return *this;
269  }
270 
272  double length() const {
273  OGDF_ASSERT(!this->empty());
274 
275  double len = 0.0;
276  ListConstIterator<PointType> pred, iter;
277 
278  pred = iter = this->begin();
279  ++iter;
280 
281  while (iter.valid()) {
282  len += (*iter).distance(*pred);
283  ++pred;
284  ++iter;
285  }
286 
287  return len;
288  }
289 
297  DPoint position(const double fraction, double len = -1.0) const {
298  OGDF_ASSERT(!this->empty());
299  OGDF_ASSERT(fraction >= 0.0);
300  OGDF_ASSERT(fraction <= 1.0);
301  if (len < 0.0) {
302  len = length();
303  }
304  OGDF_ASSERT(len >= 0.0);
305 
306  DPoint p = *(this->begin());
307  double liter = 0.0;
308  double pos = len * fraction;
309  double seglen = 0.0;
310  ListConstIterator<PointType> pred, iter;
311 
312  pred = iter = this->begin();
313  ++iter;
314 
315  // search the segment, which contains the desired point
316  double DX = 0, DY = 0; // for further use
317  while (iter.valid()) {
318  DX = (*iter).m_x - (*pred).m_x;
319  DY = (*iter).m_y - (*pred).m_y;
320  seglen = sqrt(DX * DX + DY * DY);
321  liter += seglen;
322  if (liter >= pos) {
323  break;
324  }
325  ++pred;
326  ++iter;
327  }
328 
329  if (!iter.valid()) { // position not inside the polyline, return last point!
330  p = *(this->rbegin());
331  } else {
332  if (seglen == 0.0) { // *pred == *iter and pos is inbetween
333  return *pred;
334  }
335 
336  double segpos = seglen + pos - liter;
337 
338  double dx = DX * segpos / seglen;
339  double dy = DY * segpos / seglen;
340 
341  p = *pred;
342  p.m_x += dx;
343  p.m_y += dy;
344  }
345 
346  return p;
347  }
348 
350  void unify() {
351  if (this->empty()) {
352  return;
353  }
354  ListIterator<PointType> iter, next;
355  for (iter = next = this->begin(), ++next; next.valid() && (this->size() > 2); ++next) {
356  if (*iter == *next) {
357  this->del(next);
358  next = iter;
359  } else {
360  iter = next;
361  }
362  }
363  }
364 
365 protected:
371  void normalizeUnified(double minAngle) {
372  OGDF_ASSERT(OGDF_GEOM_ET.geq(minAngle, 0.0));
373  OGDF_ASSERT(OGDF_GEOM_ET.leq(minAngle, Math::pi));
374 
375  double maxAngle = 2 * Math::pi - minAngle;
376  ListIterator<PointType> iter = this->begin();
377  ListIterator<PointType> next, onext;
378 
379  while (iter.valid()) {
380  next = iter;
381  ++next;
382  if (!next.valid()) {
383  break;
384  }
385  onext = next;
386  ++onext;
387  if (!onext.valid()) {
388  break;
389  }
390  double phi = (*next).angle(*iter, *onext);
391 
392  // Is *next on the way from *iter to *onext?
393  if (OGDF_GEOM_ET.geq(phi, minAngle) && OGDF_GEOM_ET.leq(phi, maxAngle)) {
394  this->del(next);
395  if (iter != this->begin()) {
396  --iter;
397  }
398  } else {
399  ++iter;
400  }
401  }
402  }
403 
404 public:
407 
421  void normalize(double minAngle = Math::pi) {
422  unify();
423  normalizeUnified(minAngle);
424  }
425 
431  void normalize(PointType src, PointType tgt, double minAngle = Math::pi) {
432  unify();
433  this->pushFront(src);
434  this->pushBack(tgt);
435  normalize(minAngle);
436  this->popFront();
437  this->popBack();
438  }
439 };
440 
443 
446 
448 template<class PointType>
449 class GenericLine {
450 public:
451  using numberType = typename PointType::numberType;
452 
453 protected:
454  PointType m_p1;
455  PointType m_p2;
456 
458  numberType dx() const { return m_p2.m_x - m_p1.m_x; }
459 
461  numberType dy() const { return m_p2.m_y - m_p1.m_y; }
462 
463 public:
465  GenericLine() : m_p1(), m_p2() { }
466 
468  GenericLine(const PointType& p1, const PointType& p2) : m_p1(p1), m_p2(p2) { }
469 
472 
475  : GenericLine(PointType(x1, y1), PointType(x2, y2)) { }
476 
478  bool operator==(const GenericLine<PointType>& dl) const {
479  return isVertical() ? dl.isVertical() && m_p1.m_x == dl.m_p1.m_x
480  : slope() == dl.slope() && yAbs() == dl.yAbs();
481  }
482 
484  bool operator!=(const GenericLine<PointType>& dl) const { return !(*this == dl); }
485 
488  if (this != &dl) { // don't assign myself
489  m_p1 = dl.m_p1;
490  m_p2 = dl.m_p2;
491  }
492  return *this;
493  }
494 
496  bool isVertical() const { return OGDF_GEOM_ET.equal(dx(), 0.0); }
497 
499  bool isHorizontal() const { return OGDF_GEOM_ET.equal(dy(), 0.0); }
500 
502  double slope() const { return isVertical() ? std::numeric_limits<double>::max() : dy() / dx(); }
503 
506  double yAbs() const {
507  return isVertical() ? std::numeric_limits<double>::max() : m_p1.m_y - (slope() * m_p1.m_x);
508  }
509 
517  double det(const GenericLine<PointType>& line) const {
518  return dx() * line.dy() - dy() * line.dx();
519  }
520 
530  if (isVertical() && line.isVertical()) {
531  inter = m_p1;
534  } else if (isVertical()) {
535  inter = DPoint(m_p1.m_x, line.slope() * m_p1.m_x + line.yAbs());
537  } else if (line.isVertical()) {
538  inter = DPoint(line.m_p1.m_x, slope() * line.m_p1.m_x + yAbs());
540  } else if (OGDF_GEOM_ET.equal(slope(), line.slope())) {
541  // For parallel lines only return true if the lines are equal.
542  inter = m_p1;
545  } else {
546  double ix = (line.yAbs() - yAbs()) / (slope() - line.slope());
547  inter = DPoint(ix, slope() * ix + yAbs());
549  }
550  }
551 
553  virtual bool contains(const DPoint& p) const {
554  if (p == m_p1 || p == m_p2) {
555  return true;
556  }
557 
558  if (isVertical()) {
559  return OGDF_GEOM_ET.equal(p.m_x, m_p1.m_x);
560  }
561 
562  double dx2p = p.m_x - m_p1.m_x;
563  double dy2p = p.m_y - m_p1.m_y;
564 
565  // dx() != 0.0 since this line is not vertical.
566  if (dx2p == 0.0) {
567  return false;
568  }
569 
570  return OGDF_GEOM_ET.equal(slope(), (dy2p / dx2p));
571  }
572 
581  virtual IntersectionType horIntersection(const double horAxis, double& crossing) const {
582  if (isHorizontal()) {
583  crossing = 0.0;
585  }
586  crossing = (m_p1.m_x * (m_p2.m_y - horAxis) - m_p2.m_x * (m_p1.m_y - horAxis)) / dy();
588  }
589 
598  virtual IntersectionType verIntersection(const double verAxis, double& crossing) const {
599  if (isVertical()) {
600  crossing = 0.0;
602  }
603  crossing = (m_p1.m_y * (m_p2.m_x - verAxis) - m_p2.m_y * (m_p1.m_x - verAxis)) / dx();
605  }
606 };
607 
609 template<class PointType>
610 std::ostream& operator<<(std::ostream& os, const GenericLine<PointType>& line) {
611  if (line.isVertical()) {
612  os << "Line: vertical with x = " << line.m_p1.m_x;
613  } else {
614  os << "Line: f(x) = " << line.slope() << "x + " << line.yAbs();
615  }
616  return os;
617 }
618 
621 
623 template<class PointType>
624 class GenericSegment : public GenericLine<PointType> {
625 private:
628 
633  bool inBoundingRect(const PointType& p, bool includeBorders = true) const {
634  double minx = min(this->m_p1.m_x, this->m_p2.m_x);
635  double miny = min(this->m_p1.m_y, this->m_p2.m_y);
636  double maxx = max(this->m_p1.m_x, this->m_p2.m_x);
637  double maxy = max(this->m_p1.m_y, this->m_p2.m_y);
638 
639  if (includeBorders) {
640  return OGDF_GEOM_ET.geq(p.m_x, minx) && OGDF_GEOM_ET.leq(p.m_x, maxx)
641  && OGDF_GEOM_ET.geq(p.m_y, miny) && OGDF_GEOM_ET.leq(p.m_y, maxy);
642  } else {
643  return OGDF_GEOM_ET.greater(p.m_x, minx) && OGDF_GEOM_ET.less(p.m_x, maxx)
644  && OGDF_GEOM_ET.greater(p.m_y, miny) && OGDF_GEOM_ET.less(p.m_y, maxy);
645  }
646  }
647 
648 public:
650  GenericSegment() : GenericLine<PointType>() { }
651 
653  GenericSegment(const PointType& p1, const PointType& p2) : GenericLine<PointType>(p1, p2) { }
654 
656  explicit GenericSegment(const GenericLine<PointType>& dl) : GenericLine<PointType>(dl) { }
657 
659  GenericSegment(double x1, double y1, double x2, double y2)
660  : GenericLine<PointType>(x1, y1, x2, y2) { }
661 
663  GenericSegment(const GenericSegment<PointType>& ds) = default;
664 
666  GenericSegment& operator=(const GenericSegment<PointType>& ds) = default;
667 
669  bool operator==(const GenericSegment<PointType>& dl) const {
670  return this->m_p1 == dl.m_p1 && this->m_p2 == dl.m_p2;
671  }
672 
674  bool operator!=(const GenericSegment<PointType>& dl) const { return !(*this == dl); }
675 
677  const PointType& start() const { return this->m_p1; }
678 
680  const PointType& end() const { return this->m_p2; }
681 
684 
687 
698  IntersectionType intersection(const GenericSegment<PointType>& segment, PointType& inter,
699  bool endpoints = true) const {
700  IntersectionType lineIntersection = GenericLine<PointType>::intersection(segment, inter);
701 
702  if (lineIntersection == IntersectionType::None) {
703  return IntersectionType::None;
704  } else if (lineIntersection == IntersectionType::SinglePoint) {
705  return inBoundingRect(inter, endpoints) && segment.inBoundingRect(inter, endpoints)
708  } else {
709  // Let inter be the second smallest point of this/the given segment.
710  Array<DPoint> points({this->m_p1, this->m_p2, segment.m_p1, segment.m_p2});
711  std::sort(points.begin(), points.end(), [](DPoint p1, DPoint p2) { return p1 < p2; });
712  inter = points[1];
713 
714  if (!inBoundingRect(inter, endpoints) || !segment.inBoundingRect(inter, endpoints)) {
715  return IntersectionType::None;
716  } else if (points[1] == points[2] && !(this->m_p1 == inter && this->m_p2 == inter)
717  && !(segment.m_p1 == inter && segment.m_p2 == inter)) {
718  // There is an intersection at a single point inter, which is
719  // both an endpoint of this and an endpoint of the other segment.
721  } else {
723  }
724  }
725  }
726 
728  bool contains(const PointType& p) const override {
730  }
731 
733  double length() const { return this->m_p1.distance(this->m_p2); }
734 
744  IntersectionType horIntersection(const double horAxis, double& crossing) const override {
745  IntersectionType result = GenericLine<PointType>::horIntersection(horAxis, crossing);
746  if (result != IntersectionType::SinglePoint) {
747  return result;
748  } else if (inBoundingRect(DPoint(crossing, horAxis))) {
750  } else {
751  crossing = 0.0;
752  return IntersectionType::None;
753  }
754  }
755 
765  IntersectionType verIntersection(const double verAxis, double& crossing) const override {
766  IntersectionType result = GenericLine<PointType>::verIntersection(verAxis, crossing);
767  if (result != IntersectionType::SinglePoint) {
768  return result;
769  } else if (inBoundingRect(DPoint(verAxis, crossing))) {
771  } else {
772  crossing = 0.0;
773  return IntersectionType::None;
774  }
775  }
776 };
777 
779 template<class PointType>
780 std::ostream& operator<<(std::ostream& os, const GenericSegment<PointType>& dl) {
781  os << "Segment-Start: " << dl.start() << ", Segment-End: " << dl.end();
782  return os;
783 }
784 
787 
792  friend OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const DRect& dr);
793 
794 protected:
797 
798 public:
800  DRect() = default;
801 
803  DRect(const DPoint& p1, const DPoint& p2) : m_p1(p1), m_p2(p2) { normalize(); }
804 
806  DRect(const DRect& dr) : m_p1(dr.m_p1), m_p2(dr.m_p2) { }
807 
809  DRect(double x1, double y1, double x2, double y2) : DRect(DPoint(x1, y1), DPoint(x2, y2)) { }
810 
812  explicit DRect(const DSegment& dl) : DRect(dl.start(), dl.end()) { }
813 
814  virtual ~DRect() = default;
815 
817  bool operator==(const DRect& dr) const { return m_p1 == dr.m_p1 && m_p2 == dr.m_p2; }
818 
820  bool operator!=(const DRect& dr) const { return !(*this == dr); }
821 
823  DRect& operator=(const DRect& dr) {
824  if (this != &dr) { // don't assign myself
825  m_p1 = dr.m_p1;
826  m_p2 = dr.m_p2;
827  }
828  return *this;
829  }
830 
832  double width() const { return m_p2.m_x - m_p1.m_x; }
833 
835  double height() const { return m_p2.m_y - m_p1.m_y; }
836 
843  void normalize() {
844  if (width() < 0) {
845  std::swap(m_p2.m_x, m_p1.m_x);
846  }
847  if (height() < 0) {
848  std::swap(m_p2.m_y, m_p1.m_y);
849  }
850  }
851 
853  const DPoint& p1() const { return m_p1; }
854 
856  const DPoint& p2() const { return m_p2; }
857 
859  const DSegment top() const {
860  return DSegment(DPoint(m_p1.m_x, m_p2.m_y), DPoint(m_p2.m_x, m_p2.m_y));
861  }
862 
864  const DSegment right() const {
865  return DSegment(DPoint(m_p2.m_x, m_p2.m_y), DPoint(m_p2.m_x, m_p1.m_y));
866  }
867 
869  const DSegment left() const {
870  return DSegment(DPoint(m_p1.m_x, m_p1.m_y), DPoint(m_p1.m_x, m_p2.m_y));
871  }
872 
874  const DSegment bottom() const {
875  return DSegment(DPoint(m_p2.m_x, m_p1.m_y), DPoint(m_p1.m_x, m_p1.m_y));
876  }
877 
879  void yInvert() { std::swap(m_p1.m_y, m_p2.m_y); }
880 
882  void xInvert() { std::swap(m_p1.m_x, m_p2.m_x); }
883 
885  bool contains(const DPoint& p) const {
886  return OGDF_GEOM_ET.geq(p.m_x, m_p1.m_x) && OGDF_GEOM_ET.leq(p.m_x, m_p2.m_x)
887  && OGDF_GEOM_ET.geq(p.m_y, m_p1.m_y) && OGDF_GEOM_ET.leq(p.m_y, m_p2.m_y);
888  }
889 
891  bool intersection(const DSegment& segment) const {
892  DPoint inter;
893  return segment.intersection(top(), inter) != IntersectionType::None
894  || segment.intersection(bottom(), inter) != IntersectionType::None
895  || segment.intersection(right(), inter) != IntersectionType::None
896  || segment.intersection(left(), inter) != IntersectionType::None;
897  }
898 
899 protected:
901  double parallelDist(const DSegment& d1, const DSegment& d2) const;
902 
904  double pointDist(const DPoint& p1, const DPoint& p2) const {
905  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));
906  }
907 };
908 
916  friend OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const DIntersectableRect& dr);
917 
918  double m_area = 0.0;
920 
925  void initAreaAndCenter();
926 
927 public:
929  DIntersectableRect() = default;
930 
932  DIntersectableRect(const DPoint& p1, const DPoint& p2) : DRect(p1, p2) { initAreaAndCenter(); }
933 
935  DIntersectableRect(double x1, double y1, double x2, double y2)
936  : DIntersectableRect(DPoint(x1, y1), DPoint(x2, y2)) { }
937 
940  : DRect(static_cast<DRect>(dr)), m_area(dr.m_area), m_center(dr.m_center) { }
941 
943  DIntersectableRect(const DPoint& center, double width, double height)
944  : DIntersectableRect(DPoint(center.m_x - width / 2, center.m_y - height / 2),
945  DPoint(center.m_x + width / 2, center.m_y + height / 2)) {};
946 
949  if (this != &dr) { // don't assign myself
950  m_p1 = dr.m_p1;
951  m_p2 = dr.m_p2;
952  m_center = dr.m_center;
953  m_area = dr.m_area;
954  }
955  return *this;
956  }
957 
959  DPoint center() const { return m_center; }
960 
962  double area() const { return m_area; }
963 
965  bool intersects(const DIntersectableRect& rectangle) const;
966 
970  DIntersectableRect intersection(const DIntersectableRect& other) const;
971 
973  double distance(const DIntersectableRect& other) const;
974 
976  void move(const DPoint& point);
977 };
978 
983 protected:
985 
986 public:
993  DPolygon(bool cc = true) : m_counterclock(cc) { }
994 
996  explicit DPolygon(const DRect& rect, bool cc = true) : m_counterclock(cc) { operator=(rect); }
997 
999  DPolygon(const DPolygon& dop) : DPolyline(dop), m_counterclock(dop.m_counterclock) { }
1000 
1002  bool counterclock() { return m_counterclock; }
1003 
1005  DPolygon& operator=(const DPolygon& dop) {
1007  m_counterclock = dop.m_counterclock;
1008  return *this;
1009  }
1010 
1012  DPolygon& operator=(const DRect& rect);
1013 
1015  DSegment segment(ListConstIterator<DPoint> it) const;
1016 
1019 
1025  ListIterator<DPoint> insertPoint(const DPoint& p, ListIterator<DPoint> p1,
1027 
1029  void insertCrossPoint(const DPoint& p);
1030 
1032  int getCrossPoints(const DPolygon& p, List<DPoint>& crossPoints) const;
1033 
1035  void unify();
1036 
1038  void normalize();
1039 
1046  bool containsPoint(DPoint& p) const;
1047 };
1048 
1050 OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const DPolygon& dop);
1051 
1052 int orientation(const DPoint& p, const DPoint& q, const DPoint& r);
1053 
1054 inline int orientation(const DSegment& s, const DPoint& p) {
1055  return orientation(s.start(), s.end(), p);
1056 }
1057 
1068 OGDF_EXPORT bool isPointCoveredByNode(const DPoint& point, const DPoint& v, const DPoint& vSize,
1069  const Shape& shape);
1070 
1080 OGDF_EXPORT DPoint contourPointFromAngle(double angle, int n, double rotationOffset = 0,
1081  const DPoint& center = DPoint(), const DPoint& vSize = DPoint(1, 1));
1082 
1091 OGDF_EXPORT DPoint contourPointFromAngle(double angle, Shape shape, const DPoint& center = DPoint(),
1092  const DPoint& vSize = DPoint(1, 1));
1093 }
ogdf::DPolygon::DPolygon
DPolygon(const DRect &rect, bool cc=true)
Creates a polgon from a rectangle.
Definition: geometry.h:996
ogdf::DSegment
GenericSegment< DPoint > DSegment
Segments with real coordinates.
Definition: geometry.h:786
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:656
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::DIntersectableRect::DIntersectableRect
DIntersectableRect(const DPoint &center, double width, double height)
Constructs a rectangle from the center point, width and height.
Definition: geometry.h:943
ogdf::DRect::xInvert
void xInvert()
Swaps the x-coordinates of the two points.
Definition: geometry.h:882
ogdf::GenericPolyline::GenericPolyline
GenericPolyline()
Creates an empty polyline.
Definition: geometry.h:257
ogdf::GenericLine::det
double det(const GenericLine< PointType > &line) const
Determines if line is left or right of this line.
Definition: geometry.h:517
ogdf::GenericSegment::dx
GenericLine< PointType >::numberType dx() const
Returns the x-coordinate of the difference (end point - start point).
Definition: geometry.h:683
ogdf::GenericPoint::operator/
friend GenericPoint< T > operator/(const GenericPoint< T > &p, double c)
Point-wise divide p by c.
Definition: geometry.h:199
ogdf::DRect::operator==
bool operator==(const DRect &dr) const
Equality operator: both rectangles have the same coordinates.
Definition: geometry.h:817
ogdf::GenericPoint::operator+=
GenericPoint< T > & operator+=(const GenericPoint< T > &p)
Adds p to this.
Definition: geometry.h:161
ogdf::DefHashFunc
Default hash functions.
Definition: Hashing.h:213
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:74
ogdf::GenericPoint::GenericPoint
GenericPoint(T x=0, T y=0)
Creates a generic point (x,y).
Definition: geometry.h:83
ogdf::DPolygon::DPolygon
DPolygon(const DPolygon &dop)
Copy constructor.
Definition: geometry.h:999
graphics.h
Declaration of basic types for graphics.
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:744
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:809
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:803
ogdf::GenericLine::m_p2
PointType m_p2
The second point of the line.
Definition: geometry.h:455
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:698
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
ogdf::GenericLine::GenericLine
GenericLine(const GenericLine< PointType > &dl)
Copy constructor.
Definition: geometry.h:471
ogdf::List< PointType >::popFront
void popFront()
Removes the first element from the list.
Definition: List.h:1575
ogdf::DPolygon::insertPoint
ListIterator< DPoint > insertPoint(const DPoint &p)
Inserts point p, that must lie on a polygon segment.
Definition: geometry.h:1018
ogdf::GenericLine::operator==
bool operator==(const GenericLine< PointType > &dl) const
Equality operator.
Definition: geometry.h:478
ogdf::GenericSegment::start
const PointType & start() const
Returns the start point of the line segment.
Definition: geometry.h:677
Hashing.h
Declaration of classes used for hashing.
ogdf::begin
HypergraphRegistry< HypernodeElement >::iterator begin(const HypergraphRegistry< HypernodeElement > &self)
ogdf::GenericPoint::m_y
T m_y
The y-coordinate.
Definition: geometry.h:80
ogdf::GenericPoint::operator*
friend GenericPoint< T > operator*(T c, const GenericPoint< T > &p)
Point-wise multiplies p with c.
Definition: geometry.h:182
ogdf::GenericPolyline::unify
void unify()
Deletes all successive points with equal coordinates.
Definition: geometry.h:350
ogdf::GenericLine
Infinite lines.
Definition: geometry.h:449
ogdf::GenericPolyline
Polylines with PointType points.
Definition: geometry.h:254
ogdf::DIntersectableRect::operator=
DIntersectableRect & operator=(const DIntersectableRect &dr)
Assignment operator.
Definition: geometry.h:948
ogdf::GenericLine::isHorizontal
bool isHorizontal() const
Returns true iff this line runs horizontally.
Definition: geometry.h:499
ogdf::DRect::m_p2
DPoint m_p2
The upper right point of the rectangle.
Definition: geometry.h:796
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:932
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:885
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:297
ogdf::GenericPoint::operator!=
bool operator!=(const GenericPoint< T > &p) const
Inequality operator.
Definition: geometry.h:104
ogdf::DRect::height
double height() const
Returns the height of the rectangle.
Definition: geometry.h:835
ogdf::DPolygon
Polygons with real coordinates.
Definition: geometry.h:982
ogdf::DIntersectableRect::area
double area() const
Area of the rectangle.
Definition: geometry.h:962
ogdf::ListIteratorBase::valid
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:143
ogdf::GenericLine::GenericLine
GenericLine()
Creates an empty line.
Definition: geometry.h:465
ogdf::GenericPoint::operator-=
GenericPoint< T > & operator-=(const GenericPoint< T > &p)
Subtracts p from this.
Definition: geometry.h:168
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:371
ogdf::DRect::yInvert
void yInvert()
Swaps the y-coordinates of the two points.
Definition: geometry.h:879
ogdf::DRect::normalize
void normalize()
Normalizes the rectangle.
Definition: geometry.h:843
ogdf::List::operator=
List< E > & operator=(const List< E > &L)
Assignment operator.
Definition: List.h:1491
ogdf::GenericPoint::operator*=
GenericPoint< T > & operator*=(T c)
Point-wise multiplies this with c.
Definition: geometry.h:175
ogdf::DRect::top
const DSegment top() const
Returns the top side of the rectangle.
Definition: geometry.h:859
ogdf::GenericSegment::contains
bool contains(const PointType &p) const override
Returns true iff p lies on this line segment.
Definition: geometry.h:728
ogdf::DIntersectableRect
Rectangles with real coordinates.
Definition: geometry.h:915
ogdf::GenericLine::contains
virtual bool contains(const DPoint &p) const
Returns true iff p lies on this line.
Definition: geometry.h:553
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:869
ogdf::GenericPoint::distance
double distance(const GenericPoint< T > &p) const
Returns the Euclidean distance between p and this point.
Definition: geometry.h:151
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:57
ogdf::GenericPoint::m_x
T m_x
The x-coordinate.
Definition: geometry.h:79
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:130
ogdf::GenericSegment
Finite line segments.
Definition: geometry.h:624
ogdf::GenericLine::dy
numberType dy() const
Returns the y-coordinate of the difference (second point - first point).
Definition: geometry.h:461
ogdf::GenericPoint::operator/=
GenericPoint< T > & operator/=(T c)
Point-wise divide this by c.
Definition: geometry.h:192
r
int r[]
Definition: hierarchical-ranking.cpp:8
ogdf::GenericLine::slope
double slope() const
Returns the slope of the line.
Definition: geometry.h:502
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:812
ogdf::DIntersectableRect::m_area
double m_area
Definition: geometry.h:918
ogdf::List< PointType >::pushFront
iterator pushFront(const PointType &x)
Adds element x at the beginning of the list.
Definition: List.h:1524
ogdf::DRect::m_p1
DPoint m_p1
The lower left point of the rectangle.
Definition: geometry.h:795
ogdf::DRect::p1
const DPoint & p1() const
Returns the lower left point of the rectangle.
Definition: geometry.h:853
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:214
ogdf::GenericSegment::length
double length() const
Returns the length (Euclidean distance between start and end point) of this line segment.
Definition: geometry.h:733
ogdf::DRect
Rectangles with real coordinates.
Definition: geometry.h:791
ogdf::GenericPoint::norm
double norm() const
Returns the norm of the point.
Definition: geometry.h:158
ogdf::DPolygon::counterclock
bool counterclock()
Returns true iff points are given in counter-clockwise order.
Definition: geometry.h:1002
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:421
ogdf::DRect::bottom
const DSegment bottom() const
Returns the bottom side of the rectangle.
Definition: geometry.h:874
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:581
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:529
ogdf::GenericPoint< int >::numberType
int numberType
The type for coordinates of the point.
Definition: geometry.h:77
ogdf::GenericPoint::GenericPoint
GenericPoint(const GenericPoint< T > &p)
Copy constructor.
Definition: geometry.h:86
ogdf::GenericLine::operator=
GenericLine< PointType > & operator=(const GenericLine< PointType > &dl)
Assignment operator.
Definition: geometry.h:487
ogdf::GenericPoint::operator*
T operator*(const GenericPoint< T > &dv) const
Returns the scalar product of this and dv.
Definition: geometry.h:207
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:765
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:935
ogdf::operator<<
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:978
ogdf::GenericPolyline::GenericPolyline
GenericPolyline(const GenericPolyline< PointType > &pl)
Copy constructor.
Definition: geometry.h:263
ogdf::DRect::DRect
DRect(const DRect &dr)
Copy constructor.
Definition: geometry.h:806
ogdf::GenericSegment::GenericSegment
GenericSegment()
Creates an empty line segment.
Definition: geometry.h:650
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: List.h:42
ogdf::GenericPolyline::GenericPolyline
GenericPolyline(const List< PointType > &pl)
Creates a polyline using the list of points pl.
Definition: geometry.h:260
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:161
ogdf::Math::pi
constexpr double pi
The constant .
Definition: Math.h:59
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:904
ogdf::DPolygon::m_counterclock
bool m_counterclock
If true points are given in conter-clockwise order.
Definition: geometry.h:984
ogdf::IntersectionType
IntersectionType
Determines the type of intersection of two geometric objects.
Definition: geometry.h:56
Math.h
Mathematical Helpers.
ogdf::GenericPolyline::operator=
GenericPolyline< PointType > & operator=(const GenericPolyline &pl)
Assignment operator.
Definition: geometry.h:266
ogdf::GenericPoint::angle
double angle(GenericPoint< T > q, GenericPoint< T > r) const
Compute angle (in radians) between vectors.
Definition: geometry.h:128
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:83
ogdf::Orientation
Orientation
Determines the orientation in hierarchical layouts.
Definition: geometry.h:48
ogdf::DRect::intersection
bool intersection(const DSegment &segment) const
Returns true iff segment intersects this DRect.
Definition: geometry.h:891
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:506
ogdf::DIntersectableRect::DIntersectableRect
DIntersectableRect(const DIntersectableRect &dr)
Copy constructor.
Definition: geometry.h:939
ogdf::DPoint
GenericPoint< double > DPoint
Representing two-dimensional point with real coordinates.
Definition: geometry.h:237
ogdf::GenericPoint::operator=
GenericPoint< T > & operator=(const GenericPoint< T > &p)
Assignment operator.
Definition: geometry.h:89
ogdf::GenericPolyline::length
double length() const
Returns the Euclidean length of the polyline.
Definition: geometry.h:272
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:474
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:109
ogdf::DPolygon::operator=
DPolygon & operator=(const DPolygon &dop)
Assignment operator.
Definition: geometry.h:1005
ogdf::GenericPoint::angleDegrees
double angleDegrees(GenericPoint< T > q, GenericPoint< T > r) const
Compute angle (in degrees) between vectors.
Definition: geometry.h:146
ogdf::GenericPoint::operator+
GenericPoint< T > operator+(const GenericPoint< T > &p) const
Addition of points.
Definition: geometry.h:118
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:123
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:431
ogdf::List< PointType >::del
void del(iterator it)
Removes it from the list.
Definition: List.h:1601
ogdf::DPolygon::DPolygon
DPolygon(bool cc=true)
Creates an empty polygon.
Definition: geometry.h:993
ogdf::List< PointType >::popBack
void popBack()
Removes the last element from the list.
Definition: List.h:1588
ogdf::end
HypergraphRegistry< HypernodeElement >::iterator end(const HypergraphRegistry< HypernodeElement > &self)
ogdf::DIntersectableRect::center
DPoint center() const
Center of the rectangle.
Definition: geometry.h:959
ogdf::GenericSegment::operator!=
bool operator!=(const GenericSegment< PointType > &dl) const
Inequality operator.
Definition: geometry.h:674
ogdf::GenericLine::numberType
typename PointType::numberType numberType
Definition: geometry.h:451
ogdf::GenericPoint::determinant
T determinant(const GenericPoint< T > &dv) const
Returns the determinant of the matrix (this, dv).
Definition: geometry.h:204
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:856
ogdf::DefHashFunc< IPoint >::hash
int hash(const IPoint &ip) const
Definition: geometry.h:242
ogdf::GenericLine::m_p1
PointType m_p1
The first point of the line.
Definition: geometry.h:454
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).
ogdf::GenericLine::isVertical
bool isVertical() const
Returns true iff this line runs vertically.
Definition: geometry.h:496
ogdf::Shape
Shape
Types for node shapes.
Definition: graphics.h:116
List.h
Declaration of doubly linked lists and iterators.
ogdf::GenericPoint::operator==
bool operator==(const GenericPoint< T > &dp) const
Equality operator.
Definition: geometry.h:98
ogdf::GenericPoint::orthogonal
GenericPoint< T > orthogonal() const
Returns a vector that is orthogonal to this vector.
Definition: geometry.h:215
ogdf::DRect::width
double width() const
Returns the width of the rectangle.
Definition: geometry.h:832
ogdf::GenericSegment::dy
GenericLine< PointType >::numberType dy() const
Returns the y-coordinate of the difference (end point - start point).
Definition: geometry.h:686
ogdf::DRect::operator=
DRect & operator=(const DRect &dr)
Assignment operator.
Definition: geometry.h:823
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:458
ogdf::DRect::right
const DSegment right() const
Returns the right side of the rectangle.
Definition: geometry.h:864
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:1478
ogdf::DIntersectableRect::m_center
DPoint m_center
Definition: geometry.h:919
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:633
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:135
ogdf::GenericSegment::operator==
bool operator==(const GenericSegment< PointType > &dl) const
Equality operator.
Definition: geometry.h:669
ogdf::GenericLine::GenericLine
GenericLine(const PointType &p1, const PointType &p2)
Creates a line through the points p1 and p2.
Definition: geometry.h:468
ogdf::ListIteratorBase
Encapsulates a pointer to a list element.
Definition: List.h:46
ogdf::GenericLine::operator!=
bool operator!=(const GenericLine< PointType > &dl) const
Inequality operator.
Definition: geometry.h:484
ogdf::GenericSegment::end
const PointType & end() const
Returns the end point of the line segment.
Definition: geometry.h:680
ogdf::GenericSegment::GenericSegment
GenericSegment(const PointType &p1, const PointType &p2)
Creates a line segment from p1 to p2.
Definition: geometry.h:653
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:598
ogdf::GenericPoint::operator*
friend GenericPoint< T > operator*(const GenericPoint< T > &p, T c)
Point-wise multiplies p with c.
Definition: geometry.h:187
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:115
ogdf::DRect::operator!=
bool operator!=(const DRect &dr) const
Inequality operator.
Definition: geometry.h:820
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:659
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:108
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:1537