Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

geometry.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/basic/List.h>
36 #include <ogdf/basic/Hashing.h>
37 #include <ogdf/basic/Math.h>
38 #include <ogdf/basic/EpsilonTest.h>
39 #include <cfloat>
40 
41 namespace ogdf {
42 
43 extern OGDF_EXPORT const EpsilonTest OGDF_GEOM_ET;
44 
46 enum class Orientation {
47  topToBottom,
48  bottomToTop,
49  leftToRight,
51 };
52 
54 enum class IntersectionType {
55  None,
56  SinglePoint,
58 };
59 
71 template<typename T>
73 {
74 public:
76  using numberType = T;
77 
78  T m_x;
79  T m_y;
80 
82  explicit GenericPoint(T x = 0, T y = 0) : m_x(x), m_y(y) { }
83 
85  GenericPoint(const GenericPoint<T> &p) : m_x(p.m_x), m_y(p.m_y) { }
86 
89  if (this != &p) {
90  m_x = p.m_x;
91  m_y = p.m_y;
92  }
93  return *this;
94  }
95 
97  bool operator==(const GenericPoint<T> &dp) const {
98  // OGDF_GEOM_ET uses different methods for integers and floats
99  return OGDF_GEOM_ET.equal(m_x, dp.m_x) && OGDF_GEOM_ET.equal(m_y,dp.m_y);
100  }
101 
103  bool operator!=(const GenericPoint<T> &p) const {
104  return !(*this == p);
105  }
106 
109  bool operator<(const GenericPoint<T> &p) const {
110  // OGDF_GEOM_ET uses different methods for integers and floats
111  return OGDF_GEOM_ET.less(m_x, p.m_x)
112  || (OGDF_GEOM_ET.equal(m_x, p.m_x) && OGDF_GEOM_ET.less(m_y, p.m_y));
113  }
114 
116  bool operator>(const GenericPoint<T> &p) const {
117  return p < *this;
118  }
119 
122  return GenericPoint<T>(m_x + p.m_x, m_y + p.m_y);
123  }
124 
127  return GenericPoint<T>(m_x - p.m_x, m_y - p.m_y);
128  }
129 
131  double angle(GenericPoint<T> q, GenericPoint<T> r) const {
132  const double dx1 = q.m_x - m_x, dy1 = q.m_y - m_y;
133  const double dx2 = r.m_x - m_x, dy2 = r.m_y - m_y;
134 
135  // two vertices on the same place!
136  if ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)) {
137  return 0.0;
138  }
139 
140  double phi = std::atan2(dy2, dx2) - std::atan2(dy1, dx1);
141  if (phi < 0) { phi += 2*Math::pi; }
142 
143  return phi;
144  }
145 
148  return Math::radiansToDegrees(angle(q, r));
149  }
150 
152  double distance(const GenericPoint<T> &p) const {
153  double dx = p.m_x - m_x;
154  double dy = p.m_y - m_y;
155  return sqrt( dx * dx + dy * dy );
156  }
157 
159  double norm() const {
160  return sqrt(m_x*m_x + m_y*m_y);
161  }
162 
165  m_x += p.m_x;
166  m_y += p.m_y;
167  return *this;
168  }
169 
172  m_x -= p.m_x;
173  m_y -= p.m_y;
174  return *this;
175  }
176 
179  m_x *= c;
180  m_y *= c;
181  return *this;
182  }
183 
185  friend GenericPoint<T> operator*(T c, const GenericPoint<T> &p) {
186  return GenericPoint<T>(c*p.m_x, c*p.m_y);
187  }
188 
190  friend GenericPoint<T> operator*(const GenericPoint<T> &p, T c) {
191  return GenericPoint<T>(c*p.m_x, c*p.m_y);
192  }
193 
196  m_x /= c;
197  m_y /= c;
198  return *this;
199  }
200 
202  friend GenericPoint<T> operator/(const GenericPoint<T> &p, double c) {
203  return GenericPoint<T>(p.m_x/c, p.m_y/c);
204  }
205 
207  T determinant(const GenericPoint<T> &dv) const {
208  return (m_x * dv.m_y) - (m_y * dv.m_x);
209  }
210 
212  T operator*(const GenericPoint<T> &dv) const {
213  return (m_x * dv.m_x) + (m_y * dv.m_y);
214  }
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<> class DefHashFunc<IPoint>
247 {
248 public:
249  int hash(const IPoint &ip) const {
250  return 7*ip.m_x + 23*ip.m_y;
251  }
252 };
253 
262 template<class PointType>
263 class GenericPolyline : public List<PointType> {
264 public:
267 
269  GenericPolyline(const List<PointType> &pl) : List<PointType>(pl) { }
270 
272  GenericPolyline(const GenericPolyline<PointType> &pl) : List<PointType>(pl) { }
273 
277  return *this;
278  }
279 
281  double length() const {
282  OGDF_ASSERT(!this->empty());
283 
284  double len = 0.0;
285  ListConstIterator<PointType> pred, iter;
286 
287  pred = iter = this->begin();
288  ++iter;
289 
290  while (iter.valid()) {
291  len += (*iter).distance(*pred);
292  ++pred;
293  ++iter;
294  }
295 
296  return len;
297  }
298 
306  DPoint position(const double fraction, double len = -1.0) const {
307  OGDF_ASSERT( !this->empty() );
308  OGDF_ASSERT( fraction >= 0.0 );
309  OGDF_ASSERT( fraction <= 1.0 );
310  if (len < 0.0) { len = length(); }
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  ++pred;
332  ++iter;
333  }
334 
335  if (!iter.valid()) { // position not inside the polyline, return last point!
336  p = *(this->rbegin());
337  } else {
338  if (seglen == 0.0) // *pred == *iter and pos is inbetween
339  return *pred;
340 
341  double segpos = seglen + pos - liter;
342 
343  double dx = DX * segpos / seglen;
344  double dy = DY * segpos / seglen;
345 
346  p = *pred;
347  p.m_x += dx;
348  p.m_y += dy;
349  }
350 
351  return p;
352  }
353 
355  void unify() {
356  if (this->empty()) return;
357  ListIterator<PointType> iter, next;
358  for (iter = next = this->begin(), ++next; next.valid() && (this->size() > 2); ++next) {
359  if (*iter == *next) {
360  this->del(next);
361  next = iter;
362  } else
363  iter = next;
364  }
365  }
366 
367 protected:
373  void normalizeUnified(double minAngle) {
374  OGDF_ASSERT(OGDF_GEOM_ET.geq(minAngle, 0.0));
375  OGDF_ASSERT(OGDF_GEOM_ET.leq(minAngle, Math::pi));
376 
377  double maxAngle = 2*Math::pi - minAngle;
378  ListIterator<PointType> iter = this->begin();
379  ListIterator<PointType> next, onext;
380 
381  while (iter.valid()) {
382  next = iter; ++next;
383  if (!next.valid()) { break; }
384  onext = next; ++onext;
385  if (!onext.valid()) { break; }
386  double phi = (*next).angle(*iter, *onext);
387 
388  // Is *next on the way from *iter to *onext?
389  if (OGDF_GEOM_ET.geq(phi, minAngle) &&
390  OGDF_GEOM_ET.leq(phi, maxAngle)) {
391  this->del(next);
392  if (iter != this->begin()) {
393  --iter;
394  }
395  } else {
396  ++iter;
397  }
398  }
399  }
400 
401 public:
404 
418  void normalize(double minAngle = Math::pi) {
419  unify();
420  normalizeUnified(minAngle);
421  }
422 
428  void normalize(PointType src, PointType tgt, double minAngle = Math::pi) {
429  unify();
430  this->pushFront(src);
431  this->pushBack(tgt);
432  normalize(minAngle);
433  this->popFront();
434  this->popBack();
435  }
436 };
437 
440 
443 
445 template<class PointType>
446 class GenericLine {
447 
448 public:
449  using numberType = typename PointType::numberType;
450 
451 protected:
452  PointType m_p1;
453  PointType m_p2;
454 
456  numberType dx() const { return m_p2.m_x - m_p1.m_x; }
457 
459  numberType dy() const { return m_p2.m_y - m_p1.m_y; }
460 
461 public:
463  GenericLine() : m_p1(), m_p2() {}
464 
466  GenericLine(const PointType &p1, const PointType &p2) : m_p1(p1), m_p2(p2) {}
467 
469  GenericLine(const GenericLine<PointType> &dl) : m_p1(dl.m_p1), m_p2(dl.m_p2) {}
470 
473  : GenericLine(PointType(x1, y1), PointType(x2, y2)) {}
474 
476  bool operator==(const GenericLine<PointType> &dl) const {
477  return isVertical() ? dl.isVertical() && m_p1.m_x == dl.m_p1.m_x :
478  slope() == dl.slope() && yAbs() == dl.yAbs();
479  }
480 
482  bool operator!=(const GenericLine<PointType> &dl) const {
483  return !(*this == dl);
484  }
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 {
503  return isVertical() ? std::numeric_limits<double>::max() : dy()/dx();
504  }
505 
508  double yAbs() const {
509  return isVertical() ? std::numeric_limits<double>::max() : m_p1.m_y - (slope() * m_p1.m_x);
510  }
511 
519  double det(const GenericLine<PointType> &line) const {
520  return dx() * line.dy() - dy() * line.dx();
521  }
522 
532  if (isVertical() && line.isVertical()) {
533  inter = m_p1;
534  return OGDF_GEOM_ET.equal(m_p1.m_x, line.m_p1.m_x) ?
536  } else if (isVertical()) {
537  inter = DPoint(m_p1.m_x, line.slope() * m_p1.m_x + line.yAbs());
539  } else if (line.isVertical()) {
540  inter = DPoint(line.m_p1.m_x, slope() * line.m_p1.m_x + yAbs());
542  } else if (OGDF_GEOM_ET.equal(slope(), line.slope())) {
543  // For parallel lines only return true if the lines are equal.
544  inter = m_p1;
545  return OGDF_GEOM_ET.equal(yAbs(), line.yAbs()) ?
547  } else {
548  double ix = (line.yAbs() - yAbs()) / (slope() - line.slope());
549  inter = DPoint(ix, slope() * ix + yAbs());
551  }
552  }
553 
555  virtual bool contains(const DPoint &p) const {
556  if (p == m_p1 || p == m_p2) {
557  return true;
558  }
559 
560  if (isVertical()) {
561  return OGDF_GEOM_ET.equal(p.m_x, m_p1.m_x);
562  }
563 
564  double dx2p = p.m_x - m_p1.m_x;
565  double dy2p = p.m_y - m_p1.m_y;
566 
567  // dx() != 0.0 since this line is not vertical.
568  if (dx2p == 0.0) {
569  return false;
570  }
571 
572  return OGDF_GEOM_ET.equal(slope(), (dy2p/dx2p));
573  }
574 
575 
584  virtual IntersectionType horIntersection(const double horAxis, double &crossing) const {
585  if (isHorizontal()) {
586  crossing = 0.0;
587  return m_p1.m_y == horAxis ? IntersectionType::Overlapping : IntersectionType::None;
588  }
589  crossing = (m_p1.m_x * (m_p2.m_y - horAxis) -
590  m_p2.m_x * (m_p1.m_y - horAxis) ) / dy();
592  }
593 
602  virtual IntersectionType verIntersection(const double verAxis, double &crossing) const {
603  if (isVertical()) {
604  crossing = 0.0;
605  return m_p1.m_x == verAxis ? IntersectionType::Overlapping : IntersectionType::None;
606  }
607  crossing = (m_p1.m_y * (m_p2.m_x - verAxis) -
608  m_p2.m_y * (m_p1.m_x - verAxis) ) / dx();
610  }
611 };
612 
614 template<class PointType>
615 std::ostream &operator<<(std::ostream &os, const GenericLine<PointType> &line) {
616  if (line.isVertical()) {
617  os << "Line: vertical with x = " << line.m_p1.m_x ;
618  } else {
619  os << "Line: f(x) = " << line.slope() << "x + " << line.yAbs() ;
620  }
621  return os;
622 }
623 
626 
628 template<class PointType>
629 class GenericSegment : public GenericLine<PointType> {
630 
631 private:
634 
639  bool inBoundingRect(const PointType &p, bool includeBorders = true) const {
640  double minx = min(this->m_p1.m_x, this->m_p2.m_x);
641  double miny = min(this->m_p1.m_y, this->m_p2.m_y);
642  double maxx = max(this->m_p1.m_x, this->m_p2.m_x);
643  double maxy = max(this->m_p1.m_y, this->m_p2.m_y);
644 
645  if (includeBorders) {
646  return OGDF_GEOM_ET.geq(p.m_x, minx) &&
647  OGDF_GEOM_ET.leq(p.m_x, maxx) &&
648  OGDF_GEOM_ET.geq(p.m_y, miny) &&
649  OGDF_GEOM_ET.leq(p.m_y, maxy);
650  } else {
651  return OGDF_GEOM_ET.greater(p.m_x, minx) &&
652  OGDF_GEOM_ET.less (p.m_x, maxx) &&
653  OGDF_GEOM_ET.greater(p.m_y, miny) &&
654  OGDF_GEOM_ET.less (p.m_y, maxy);
655  }
656  }
657 
658 public:
659 
661  GenericSegment() : GenericLine<PointType>() {}
662 
664  GenericSegment(const PointType &p1, const PointType &p2)
665  : GenericLine<PointType>(p1, p2) {}
666 
669  : GenericLine<PointType>(dl) {}
670 
672  GenericSegment(double x1, double y1, double x2, double y2)
673  : GenericLine<PointType>(x1, y1, x2, y2) {}
674 
676  GenericSegment(const GenericSegment<PointType> &ds) = default;
677 
679  GenericSegment& operator=(const GenericSegment<PointType> &ds) = default;
680 
682  bool operator==(const GenericSegment<PointType> &dl) const {
683  return this->m_p1 == dl.m_p1 && this->m_p2 == dl.m_p2;
684  }
685 
687  bool operator!=(const GenericSegment<PointType> &dl) const {
688  return !(*this == dl);
689  }
690 
692  const PointType &start() const { return this->m_p1; }
693 
695  const PointType &end() const { return this->m_p2; }
696 
700  }
701 
705  }
706 
717  IntersectionType intersection(const GenericSegment<PointType> &segment, PointType &inter, bool endpoints = true) const {
718  IntersectionType lineIntersection = GenericLine<PointType>::intersection(segment, inter);
719 
720  if (lineIntersection == IntersectionType::None) {
721  return IntersectionType::None;
722  } else if (lineIntersection == IntersectionType::SinglePoint) {
723  return inBoundingRect(inter, endpoints)
724  && segment.inBoundingRect(inter, endpoints) ?
726  } else {
727  // Let inter be the second smallest point of this/the given segment.
728  Array<DPoint> points({this->m_p1, this->m_p2, segment.m_p1, segment.m_p2});
729  std::sort(points.begin(), points.end(), [](DPoint p1, DPoint p2) {
730  return p1 < p2;
731  });
732  inter = points[1];
733 
734  if (!inBoundingRect(inter, endpoints) ||
735  !segment.inBoundingRect(inter, endpoints)) {
736  return IntersectionType::None;
737  } else if (points[1] == points[2] &&
738  !(this->m_p1 == inter && this->m_p2 == inter) &&
739  !(segment.m_p1 == inter && segment.m_p2 == inter)) {
740  // There is an intersection at a single point inter, which is
741  // both an endpoint of this and an endpoint of the other segment.
743  } else {
745  }
746  }
747  }
748 
750  bool contains(const PointType &p) const override {
751  return GenericLine<PointType>::contains(p) && inBoundingRect(p);
752  }
753 
755  double length() const {
756  return this->m_p1.distance(this->m_p2);
757  }
758 
768  IntersectionType horIntersection(const double horAxis, double &crossing) const override {
769  IntersectionType result = GenericLine<PointType>::horIntersection(horAxis, crossing);
770  if (result != IntersectionType::SinglePoint) {
771  return result;
772  } else if (inBoundingRect(DPoint(crossing, horAxis))) {
774  } else {
775  crossing = 0.0;
776  return IntersectionType::None;
777  }
778  }
779 
789  IntersectionType verIntersection(const double verAxis, double &crossing) const override {
790  IntersectionType result = GenericLine<PointType>::verIntersection(verAxis, crossing);
791  if (result != IntersectionType::SinglePoint) {
792  return result;
793  } else if (inBoundingRect(DPoint(verAxis, crossing))) {
795  } else {
796  crossing = 0.0;
797  return IntersectionType::None;
798  }
799  }
800 };
801 
803 template<class PointType>
804 std::ostream &operator<<(std::ostream &os, const GenericSegment<PointType> &dl) {
805  os << "Segment-Start: " << dl.start() << ", Segment-End: " << dl.end();
806  return os;
807 }
808 
811 
816 
817  friend OGDF_EXPORT std::ostream &operator<<(std::ostream &os, const DRect &dr);
818 
819 protected:
822 
823 public:
825  DRect() = default;
826 
828  DRect(const DPoint &p1, const DPoint &p2)
829  : m_p1(p1)
830  , m_p2(p2)
831  { normalize(); }
832 
834  DRect(const DRect& dr)
835  : m_p1(dr.m_p1)
836  , m_p2(dr.m_p2) {}
837 
839  DRect(double x1, double y1, double x2, double y2)
840  : DRect(DPoint(x1,y1), DPoint(x2,y2)) {}
841 
843  explicit DRect(const DSegment &dl)
844  : DRect(dl.start(), dl.end()) {}
845 
846  virtual ~DRect() = default;
847 
849  bool operator==(const DRect &dr) const {
850  return m_p1 == dr.m_p1 && m_p2 == dr.m_p2;
851  }
852 
854  bool operator!=(const DRect &dr) const {
855  return !(*this == dr);
856  }
857 
859  DRect &operator= (const DRect &dr) {
860  if (this != &dr) { // don't assign myself
861  m_p1 = dr.m_p1;
862  m_p2 = dr.m_p2;
863  }
864  return *this;
865  }
866 
868  double width() const {
869  return m_p2.m_x - m_p1.m_x;
870  }
871 
873  double height() const {
874  return m_p2.m_y - m_p1.m_y;
875  }
876 
883  void normalize() {
884  if (width() < 0) std::swap(m_p2.m_x, m_p1.m_x);
885  if (height() < 0) std::swap(m_p2.m_y, m_p1.m_y);
886  }
887 
889  const DPoint &p1() const { return m_p1; }
890 
892  const DPoint &p2() const { return m_p2; }
893 
895  const DSegment top() const {
896  return DSegment( DPoint(m_p1.m_x, m_p2.m_y), DPoint(m_p2.m_x, m_p2.m_y));
897  }
898 
900  const DSegment right() const {
901  return DSegment( DPoint(m_p2.m_x, m_p2.m_y), DPoint(m_p2.m_x, m_p1.m_y));
902  }
903 
905  const DSegment left() const {
906  return DSegment( DPoint(m_p1.m_x, m_p1.m_y), DPoint(m_p1.m_x, m_p2.m_y));
907  }
908 
910  const DSegment bottom() const {
911  return DSegment( DPoint(m_p2.m_x, m_p1.m_y), DPoint(m_p1.m_x, m_p1.m_y));
912  }
913 
915  void yInvert() { std::swap(m_p1.m_y, m_p2.m_y); }
916 
918  void xInvert() { std::swap(m_p1.m_x, m_p2.m_x); }
919 
921  bool contains(const DPoint &p) const {
922  return OGDF_GEOM_ET.geq(p.m_x, m_p1.m_x)
923  && OGDF_GEOM_ET.leq(p.m_x, m_p2.m_x)
924  && OGDF_GEOM_ET.geq(p.m_y, m_p1.m_y)
925  && OGDF_GEOM_ET.leq(p.m_y, m_p2.m_y);
926  }
927 
929  bool intersection(const DSegment &segment) const {
930  DPoint inter;
931  return segment.intersection(top(), inter) != IntersectionType::None
932  || segment.intersection(bottom(), inter) != IntersectionType::None
933  || segment.intersection(right(), inter) != IntersectionType::None
934  || segment.intersection(left(), inter) != IntersectionType::None;
935  }
936 
937 protected:
939  double parallelDist(const DSegment &d1, const DSegment &d2) const;
940 
942  double pointDist(const DPoint &p1, const DPoint &p2) const {
943  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));
944  }
945 };
946 
954 
955  friend OGDF_EXPORT std::ostream &operator<<(std::ostream &os, const DIntersectableRect &dr);
956 
957  double m_area = 0.0;
959 
964  void initAreaAndCenter();
965 
966 public:
968  DIntersectableRect() = default;
969 
971  DIntersectableRect(const DPoint &p1, const DPoint &p2)
972  : DRect(p1, p2)
973  { initAreaAndCenter(); }
974 
976  DIntersectableRect(double x1, double y1, double x2, double y2)
977  : DIntersectableRect(DPoint(x1,y1), DPoint(x2,y2)) {}
978 
981  : DRect(static_cast<DRect>(dr))
982  , m_area(dr.m_area)
983  , m_center(dr.m_center) {}
984 
986  DIntersectableRect(const DPoint &center, double width, double height)
987  : DIntersectableRect(DPoint(center.m_x-width/2,center.m_y-height/2),
988  DPoint(center.m_x+width/2,center.m_y+height/2)) {};
989 
991  DIntersectableRect &operator= (const DIntersectableRect &dr) {
992  if (this != &dr) { // don't assign myself
993  m_p1 = dr.m_p1;
994  m_p2 = dr.m_p2;
995  m_center = dr.m_center;
996  m_area = dr.m_area;
997  }
998  return *this;
999  }
1000 
1002  DPoint center() const { return m_center; }
1003 
1005  double area() const { return m_area; }
1006 
1008  bool intersects(const DIntersectableRect &rectangle) const;
1009 
1013  DIntersectableRect intersection(const DIntersectableRect &other) const;
1014 
1016  double distance(const DIntersectableRect &other) const;
1017 
1019  void move(const DPoint &point);
1020 };
1021 
1026 
1027 protected:
1028 
1030 
1031 public:
1038  DPolygon(bool cc = true) : m_counterclock(cc) { }
1039 
1041  explicit DPolygon(const DRect &rect, bool cc = true) : m_counterclock(cc) {
1042  operator=(rect);
1043  }
1044 
1046  DPolygon(const DPolygon &dop) : DPolyline(dop), m_counterclock(dop.m_counterclock) { }
1047 
1049  bool counterclock() { return m_counterclock; }
1050 
1052  DPolygon &operator=(const DPolygon &dop) {
1054  m_counterclock = dop.m_counterclock;
1055  return *this;
1056  }
1057 
1059  DPolygon &operator=(const DRect &rect);
1060 
1062  DSegment segment(ListConstIterator<DPoint> it) const;
1063 
1064 
1067  return insertPoint(p, begin(), begin());
1068  }
1069 
1075  ListIterator<DPoint> insertPoint(const DPoint &p,
1078 
1080  void insertCrossPoint(const DPoint &p);
1081 
1083  int getCrossPoints(const DPolygon &p, List<DPoint> &crossPoints) const;
1084 
1086  void unify();
1087 
1089  void normalize();
1090 
1097  bool containsPoint(DPoint &p) const;
1098 };
1099 
1101 OGDF_EXPORT std::ostream &operator<<(std::ostream &os, const DPolygon &dop);
1102 
1103 int orientation(const DPoint &p, const DPoint &q, const DPoint &r);
1104 
1105 
1106 inline int orientation(const DSegment &s, const DPoint &p)
1107 {
1108  return orientation(s.start(), s.end(), p);
1109 }
1110 
1111 }
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:976
DRect(const DSegment &dl)
Creates a rectangle defined by the end points of line segment dl.
Definition: geometry.h:843
double slope() const
Returns the slope of the line.
Definition: geometry.h:502
bool isVertical() const
Returns true iff this line runs vertically.
Definition: geometry.h:496
bool operator!=(const GenericPoint< T > &p) const
Inequality operator.
Definition: geometry.h:103
DPolygon(const DPolygon &dop)
Copy constructor.
Definition: geometry.h:1046
const DSegment top() const
Returns the top side of the rectangle.
Definition: geometry.h:895
GenericPolyline(const List< PointType > &pl)
Creates a polyline using the list of points pl.
Definition: geometry.h:269
const DSegment bottom() const
Returns the bottom side of the rectangle.
Definition: geometry.h:910
Default hash functions.
Definition: Hashing.h:218
void normalize()
Normalizes the rectangle.
Definition: geometry.h:883
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:306
double distance(const GenericPoint< T > &p) const
Returns the Euclidean distance between p and this point.
Definition: geometry.h:152
GenericSegment()
Creates an empty line segment.
Definition: geometry.h:661
void unify()
Deletes all successive points with equal coordinates.
Definition: geometry.h:355
GenericPolyline(const GenericPolyline< PointType > &pl)
Copy constructor.
Definition: geometry.h:272
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:200
int hash(const IPoint &ip) const
Definition: geometry.h:249
T operator*(const GenericPoint< T > &dv) const
Returns the scalar product of this and dv.
Definition: geometry.h:212
IntersectionType
Determines the type of intersection of two geometric objects.
Definition: geometry.h:54
GenericLine(numberType x1, numberType y1, numberType x2, numberType y2)
Creates a line through the points (x1,y1) and (x2,y2).
Definition: geometry.h:472
bool m_counterclock
If true points are given in conter-clockwise order.
Definition: geometry.h:1029
DIntersectableRect(const DPoint &center, double width, double height)
Constructs a rectangle from the center point, width and height.
Definition: geometry.h:986
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:639
double height() const
Returns the height of the rectangle.
Definition: geometry.h:873
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:789
Polygons with real coordinates.
Definition: geometry.h:1025
double pointDist(const DPoint &p1, const DPoint &p2) const
Computes distance between two points.
Definition: geometry.h:942
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
GenericPoint< double > DPoint
Representing two-dimensional point with real coordinates.
Definition: geometry.h:244
DIntersectableRect(const DPoint &p1, const DPoint &p2)
Creates a rectangle with lower left point p1 and upper right point p2.
Definition: geometry.h:971
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:768
double width() const
Returns the width of the rectangle.
Definition: geometry.h:868
double yAbs() const
Returns the value y&#39; such that (0,y&#39;) lies on the unlimited straight-line defined by this line...
Definition: geometry.h:508
GenericPoint< T > operator+(const GenericPoint< T > &p) const
Addition of points.
Definition: geometry.h:121
PointType m_p1
The first point of the line.
Definition: geometry.h:452
const DSegment right() const
Returns the right side of the rectangle.
Definition: geometry.h:900
bool counterclock()
Returns true iff points are given in counter-clockwise order.
Definition: geometry.h:1049
const PointType & start() const
Returns the start point of the line segment.
Definition: geometry.h:692
Rectangles with real coordinates.
Definition: geometry.h:815
DIntersectableRect(const DIntersectableRect &dr)
Copy constructor.
Definition: geometry.h:980
IntersectionType intersection(const GenericLine< PointType > &line, DPoint &inter) const
Returns an IntersectionType specifying whether line and this line intersect.
Definition: geometry.h:531
Declaration of classes used for hashing.
DPoint center() const
Center of the rectangle.
Definition: geometry.h:1002
Two geometric objects intersect in a single point.
Rectangles with real coordinates.
Definition: geometry.h:953
GenericLine< PointType >::numberType dy() const
Returns the y-coordinate of the difference (end point - start point).
Definition: geometry.h:703
GenericPoint(const GenericPoint< T > &p)
Copy constructor.
Definition: geometry.h:85
PointType m_p2
The second point of the line.
Definition: geometry.h:453
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:584
bool operator!=(const GenericLine< PointType > &dl) const
Inequality operator.
Definition: geometry.h:482
GenericLine()
Creates an empty line.
Definition: geometry.h:463
GenericLine(const PointType &p1, const PointType &p2)
Creates a line through the points p1 and p2.
Definition: geometry.h:466
double radiansToDegrees(const double &angleInRadians)
Converts an angle from radians to degrees.
Definition: Math.h:133
const DSegment left() const
Returns the left side of the rectangle.
Definition: geometry.h:905
Compare floating point numbers with epsilons and integral numbers with normal compare operators...
int numberType
The type for coordinates of the point.
Definition: geometry.h:76
bool operator==(const GenericPoint< T > &dp) const
Equality operator.
Definition: geometry.h:97
void yInvert()
Swaps the y-coordinates of the two points.
Definition: geometry.h:915
friend GenericPoint< T > operator*(const GenericPoint< T > &p, T c)
Point-wise multiplies p with c.
Definition: geometry.h:190
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:124
GenericLine(const GenericLine< PointType > &dl)
Copy constructor.
Definition: geometry.h:469
double length() const
Returns the length (Euclidean distance between start and end point) of this line segment.
Definition: geometry.h:755
constexpr double pi
The constant .
Definition: Math.h:62
Orientation
Determines the orientation in hierarchical layouts.
Definition: geometry.h:46
bool operator==(const DRect &dr) const
Equality operator: both rectangles have the same coordinates.
Definition: geometry.h:849
void sort(T *array, int size, LessThan lt)
Definition: Sort.h:57
GenericPolyline()
Creates an empty polyline.
Definition: geometry.h:266
const EpsilonTest OGDF_GEOM_ET
const DPoint & p1() const
Returns the lower left point of the rectangle.
Definition: geometry.h:889
bool operator>(const GenericPoint< T > &p) const
Operator &#39;greater&#39;. Returns true iff p is less than this.
Definition: geometry.h:116
numberType dx() const
Returns the x-coordinate of the difference (second point - first point).
Definition: geometry.h:456
GenericPoint(T x=0, T y=0)
Creates a generic point (x,y).
Definition: geometry.h:82
const PointType & end() const
Returns the end point of the line segment.
Definition: geometry.h:695
GenericPoint< T > & operator/=(T c)
Point-wise divide this by c.
Definition: geometry.h:195
double length() const
Returns the Euclidean length of the polyline.
Definition: geometry.h:281
T determinant(const GenericPoint< T > &dv) const
Returns the determinant of the matrix (this, dv).
Definition: geometry.h:207
Mathematical Helpers.
virtual bool contains(const DPoint &p) const
Returns true iff p lies on this line.
Definition: geometry.h:555
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:418
Finite line segments.
Definition: geometry.h:629
Doubly linked lists (maintaining the length of the list).
Definition: List.h:40
GenericPoint< T > & operator+=(const GenericPoint< T > &p)
Adds p to this.
Definition: geometry.h:164
DRect(const DPoint &p1, const DPoint &p2)
Creates a rectangle with lower left point p1 and upper right point p2.
Definition: geometry.h:828
GenericLine< PointType > & operator=(const GenericLine< PointType > &dl)
Assignment operator.
Definition: geometry.h:487
Edges are oriented from left to right.
bool contains(const DPoint &p) const
Returns true iff p lies within this rectangle, modulo the comparison epsilon OGDF_GEOM_ET.
Definition: geometry.h:921
DPolygon(const DRect &rect, bool cc=true)
Creates a polgon from a rectangle.
Definition: geometry.h:1041
bool intersection(const DSegment &segment) const
Returns true iff segment intersects this DRect.
Definition: geometry.h:929
double angleDegrees(GenericPoint< T > q, GenericPoint< T > r) const
Compute angle (in degrees) between vectors.
Definition: geometry.h:147
GenericPoint< T > orthogonal() const
Returns a vector that is orthogonal to this vector.
Definition: geometry.h:222
friend GenericPoint< T > operator/(const GenericPoint< T > &p, double c)
Point-wise divide p by c.
Definition: geometry.h:202
Encapsulates a pointer to a list element.
Definition: List.h:42
Polylines with PointType points.
Definition: geometry.h:263
double area() const
Area of the rectangle.
Definition: geometry.h:1005
T m_y
The y-coordinate.
Definition: geometry.h:79
GenericSegment< DPoint > DSegment
Segments with real coordinates.
Definition: geometry.h:810
const T & move(const T &v)
Definition: backward.hpp:243
GenericPoint< T > & operator-=(const GenericPoint< T > &p)
Subtracts p from this.
Definition: geometry.h:171
void xInvert()
Swaps the x-coordinates of the two points.
Definition: geometry.h:918
DPolygon & operator=(const DPolygon &dop)
Assignment operator.
Definition: geometry.h:1052
Edges are oriented from right to left.
bool contains(const PointType &p) const override
Returns true iff p lies on this line segment.
Definition: geometry.h:750
GenericSegment(const PointType &p1, const PointType &p2)
Creates a line segment from p1 to p2.
Definition: geometry.h:664
Two geometric objects intersect in infinitely many points.
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:602
GenericPoint< T > & operator=(const GenericPoint< T > &p)
Assignment operator.
Definition: geometry.h:88
GenericPoint< T > & operator*=(T c)
Point-wise multiplies this with c.
Definition: geometry.h:178
bool isHorizontal() const
Returns true iff this line runs horizontally.
Definition: geometry.h:499
bool operator==(const GenericSegment< PointType > &dl) const
Equality operator.
Definition: geometry.h:682
Two geometric objects do not intersect.
Parameterized base class for points.
Definition: geometry.h:72
typename PointType::numberType numberType
Definition: geometry.h:449
Edges are oriented from top to bottom.
GenericLine< PointType >::numberType dx() const
Returns the x-coordinate of the difference (end point - start point).
Definition: geometry.h:698
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:839
bool operator!=(const DRect &dr) const
Inequality operator.
Definition: geometry.h:854
double det(const GenericLine< PointType > &line) const
Determines if line is left or right of this line.
Definition: geometry.h:519
DRect(const DRect &dr)
Copy constructor.
Definition: geometry.h:834
friend GenericPoint< T > operator*(T c, const GenericPoint< T > &p)
Point-wise multiplies p with c.
Definition: geometry.h:185
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:428
The namespace for all OGDF objects.
GenericSegment(double x1, double y1, double x2, double y2)
Creates a line segment from (x1,y1) to (x2,y2).
Definition: geometry.h:672
GenericPoint< T > operator-(const GenericPoint< T > &p) const
Subtraction of points.
Definition: geometry.h:126
List< E > & operator=(const List< E > &L)
Assignment operator.
Definition: List.h:1325
const DPoint & p2() const
Returns the upper right point of the rectangle.
Definition: geometry.h:892
GenericPolyline< PointType > & operator=(const GenericPolyline &pl)
Assignment operator.
Definition: geometry.h:275
numberType dy() const
Returns the y-coordinate of the difference (second point - first point).
Definition: geometry.h:459
DPolygon(bool cc=true)
Creates an empty polygon.
Definition: geometry.h:1038
bool operator==(const GenericLine< PointType > &dl) const
Equality operator.
Definition: geometry.h:476
double norm() const
Returns the norm of the point.
Definition: geometry.h:159
bool operator!=(const GenericSegment< PointType > &dl) const
Inequality operator.
Definition: geometry.h:687
GenericSegment(const GenericLine< PointType > &dl)
Creates a line segment defined by the start and end point of line dl.
Definition: geometry.h:668
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:717
DPoint m_p2
The upper right point of the rectangle.
Definition: geometry.h:821
Infinite lines.
Definition: geometry.h:446
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:373
ListIterator< DPoint > insertPoint(const DPoint &p)
Inserts point p, that must lie on a polygon segment.
Definition: geometry.h:1066
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:942
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
double angle(GenericPoint< T > q, GenericPoint< T > r) const
Compute angle (in radians) between vectors.
Definition: geometry.h:131
Declaration of doubly linked lists and iterators.
T m_x
The x-coordinate.
Definition: geometry.h:78
Edges are oriented from bottom to top.
DPoint m_p1
The lower left point of the rectangle.
Definition: geometry.h:820
int orientation(const DPoint &p, const DPoint &q, const DPoint &r)