Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
geometry.h
Go to the documentation of this file.
1
33#pragma once
34
35#include <ogdf/basic/Array.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
47namespace ogdf {
48enum class Shape;
49template<class K>
50class DefHashFunc;
51
52extern OGDF_EXPORT const EpsilonTest OGDF_GEOM_ET;
53
61
63enum class IntersectionType {
64 None,
67};
68
80template<typename T>
82public:
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)
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
190 return GenericPoint<T>(c * p.m_x, c * p.m_y);
191 }
192
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
234template<typename T>
235std::ostream& operator<<(std::ostream& os, const GenericPoint<T>& p) {
236 os << "(" << p.m_x << "," << p.m_y << ")";
237 return os;
238}
239
242
245
246template<>
248public:
249 int hash(const IPoint& ip) const { return 7 * ip.m_x + 23 * ip.m_y; }
250};
251
260template<class PointType>
261class GenericPolyline : public List<PointType> {
262public:
265
267 GenericPolyline(const List<PointType>& pl) : List<PointType>(pl) { }
268
270 GenericPolyline(const GenericPolyline<PointType>& pl) : List<PointType>(pl) { }
271
277
279 double length() const {
280 OGDF_ASSERT(!this->empty());
281
282 double len = 0.0;
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;
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
372protected:
378 void normalizeUnified(double minAngle) {
379 OGDF_ASSERT(OGDF_GEOM_ET.geq(minAngle, 0.0));
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
411public:
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
455template<class PointType>
457public:
458 using numberType = typename PointType::numberType;
459
460protected:
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
470public:
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
616template<class PointType>
617std::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
630template<class PointType>
631class GenericSegment : public GenericLine<PointType> {
632private:
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
655public:
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
671
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
706 bool endpoints = true) const {
707 IntersectionType lineIntersection = GenericLine<PointType>::intersection(segment, inter);
708
709 if (lineIntersection == 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)) {
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 {
753 if (result != IntersectionType::SinglePoint) {
754 return result;
755 } else if (inBoundingRect(DPoint(crossing, horAxis))) {
757 } else {
758 crossing = 0.0;
760 }
761 }
762
772 IntersectionType verIntersection(const double verAxis, double& crossing) const override {
774 if (result != IntersectionType::SinglePoint) {
775 return result;
776 } else if (inBoundingRect(DPoint(verAxis, crossing))) {
778 } else {
779 crossing = 0.0;
781 }
782 }
783};
784
786template<class PointType>
787std::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
801protected:
804
805public:
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
906protected:
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
933
934public:
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
978
980 double distance(const DIntersectableRect& other) const;
981
983 void move(const DPoint& point);
984};
985
990protected:
992
993public:
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
1014 m_counterclock = dop.m_counterclock;
1015 return *this;
1016 }
1017
1019 DPolygon& operator=(const DRect& rect);
1020
1023
1026
1034
1036 void insertCrossPoint(const DPoint& p);
1037
1039 int getCrossPoints(const DPolygon& p, List<DPoint>& crossPoints) const;
1040
1042 void unify();
1043
1046
1053 bool containsPoint(DPoint& p) const;
1054};
1055
1057OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const DPolygon& dop);
1058
1059int orientation(const DPoint& p, const DPoint& q, const DPoint& r);
1060
1061inline int orientation(const DSegment& s, const DPoint& p) {
1062 return orientation(s.start(), s.end(), p);
1063}
1064
1075OGDF_EXPORT bool isPointCoveredByNode(const DPoint& point, const DPoint& v, const DPoint& vSize,
1076 const Shape& shape);
1077
1087OGDF_EXPORT DPoint contourPointFromAngle(double angle, int n, double rotationOffset = 0,
1088 const DPoint& center = DPoint(), const DPoint& vSize = DPoint(1, 1));
1089
1098OGDF_EXPORT DPoint contourPointFromAngle(double angle, Shape shape, const DPoint& center = DPoint(),
1099 const DPoint& vSize = DPoint(1, 1));
1100}
Declaration and implementation of Array class and Array algorithms.
Compare floating point numbers with epsilons and integral numbers with normal compare operators.
Declaration of doubly linked lists and iterators.
Mathematical Helpers.
Basic declarations, included by all source files.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
Rectangles with real coordinates.
Definition geometry.h:922
DIntersectableRect()=default
Creates a rectangle with lower left and upper right point (0,0).
DPoint center() const
Center of the rectangle.
Definition geometry.h:966
double area() const
Area of the rectangle.
Definition geometry.h:969
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
DIntersectableRect(const DPoint &p1, const DPoint &p2)
Creates a rectangle with lower left point p1 and upper right point p2.
Definition geometry.h:939
void move(const DPoint &point)
Moves the rectangle such that its center is at the given point.
friend std::ostream & operator<<(std::ostream &os, const DIntersectableRect &dr)
double distance(const DIntersectableRect &other) const
Computes distance between two rectangles.
DIntersectableRect(const DIntersectableRect &dr)
Copy constructor.
Definition geometry.h:946
bool intersects(const DIntersectableRect &rectangle) const
Tests if this and the argument rectangle intersect.
DIntersectableRect & operator=(const DIntersectableRect &dr)
Assignment operator.
Definition geometry.h:955
DIntersectableRect intersection(const DIntersectableRect &other) const
Returns the rectangle resulting from intersection of this and other. Returns a rectangle with zero wi...
void initAreaAndCenter()
Normalizes the rectangle.
DIntersectableRect(const DPoint &center, double width, double height)
Constructs a rectangle from the center point, width and height.
Definition geometry.h:950
Polygons with real coordinates.
Definition geometry.h:989
DPolygon(const DRect &rect, bool cc=true)
Creates a polgon from a rectangle.
Definition geometry.h:1003
ListIterator< DPoint > insertPoint(const DPoint &p, ListIterator< DPoint > p1, ListIterator< DPoint > p2)
Inserts point p, but just searching from point p1 to p2.
DSegment segment(ListConstIterator< DPoint > it) const
Returns the line segment that starts at position it.
bool counterclock()
Returns true iff points are given in counter-clockwise order.
Definition geometry.h:1009
int getCrossPoints(const DPolygon &p, List< DPoint > &crossPoints) const
Returns the list of intersection points of this polygon with p.
void insertCrossPoint(const DPoint &p)
Inserts point p on every segment (a,b) with p in the open range ]a, b[.
DPolygon & operator=(const DPolygon &dop)
Assignment operator.
Definition geometry.h:1012
DPolygon(bool cc=true)
Creates an empty polygon.
Definition geometry.h:1000
bool containsPoint(DPoint &p) const
Checks whether a Point /a p is inside the Polygon or not.
bool m_counterclock
If true points are given in conter-clockwise order.
Definition geometry.h:991
DPolygon & operator=(const DRect &rect)
Assignment operator (for assigning from a rectangle).
DPolygon(const DPolygon &dop)
Copy constructor.
Definition geometry.h:1006
void normalize()
Deletes all points, which are not facets.
ListIterator< DPoint > insertPoint(const DPoint &p)
Inserts point p, that must lie on a polygon segment.
Definition geometry.h:1025
void unify()
Deletes all consecutive points that are equal.
Rectangles with real coordinates.
Definition geometry.h:798
double parallelDist(const DSegment &d1, const DSegment &d2) const
Computes distance between parallel line segments.
bool operator==(const DRect &dr) const
Equality operator: both rectangles have the same coordinates.
Definition geometry.h:824
virtual ~DRect()=default
const DSegment bottom() const
Returns the bottom side of the rectangle.
Definition geometry.h:881
double pointDist(const DPoint &p1, const DPoint &p2) const
Computes distance between two points.
Definition geometry.h:911
DRect()=default
Creates a rectangle with lower left and upper right point (0,0).
bool intersection(const DSegment &segment) const
Returns true iff segment intersects this DRect.
Definition geometry.h:898
void normalize()
Normalizes the rectangle.
Definition geometry.h:850
void xInvert()
Swaps the x-coordinates of the two points.
Definition geometry.h:889
double height() const
Returns the height of the rectangle.
Definition geometry.h:842
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
void yInvert()
Swaps the y-coordinates of the two points.
Definition geometry.h:886
const DSegment right() const
Returns the right side of the rectangle.
Definition geometry.h:871
const DPoint & p1() const
Returns the lower left point of the rectangle.
Definition geometry.h:860
const DSegment top() const
Returns the top side of the rectangle.
Definition geometry.h:866
DRect(const DSegment &dl)
Creates a rectangle defined by the end points of line segment dl.
Definition geometry.h:819
DPoint m_p2
The upper right point of the rectangle.
Definition geometry.h:803
friend std::ostream & operator<<(std::ostream &os, const DRect &dr)
bool operator!=(const DRect &dr) const
Inequality operator.
Definition geometry.h:827
DPoint m_p1
The lower left point of the rectangle.
Definition geometry.h:802
const DPoint & p2() const
Returns the upper right point of the rectangle.
Definition geometry.h:863
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
DRect(const DRect &dr)
Copy constructor.
Definition geometry.h:813
DRect(const DPoint &p1, const DPoint &p2)
Creates a rectangle with lower left point p1 and upper right point p2.
Definition geometry.h:810
DRect & operator=(const DRect &dr)
Assignment operator.
Definition geometry.h:830
const DSegment left() const
Returns the left side of the rectangle.
Definition geometry.h:876
double width() const
Returns the width of the rectangle.
Definition geometry.h:839
int hash(const IPoint &ip) const
Definition geometry.h:249
Default hash functions.
Definition Hashing.h:216
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
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.
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
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.
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.
Infinite lines.
Definition geometry.h:456
bool operator!=(const GenericLine< PointType > &dl) const
Inequality operator.
Definition geometry.h:491
GenericLine< PointType > & operator=(const GenericLine< PointType > &dl)
Assignment operator.
Definition geometry.h:494
PointType m_p1
The first point of the line.
Definition geometry.h:461
PointType m_p2
The second point of the line.
Definition geometry.h:462
numberType dx() const
Returns the x-coordinate of the difference (second point - first point).
Definition geometry.h:465
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
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
numberType dy() const
Returns the y-coordinate of the difference (second point - first point).
Definition geometry.h:468
double slope() const
Returns the slope of the line.
Definition geometry.h:509
GenericLine(const GenericLine< PointType > &dl)
Copy constructor.
Definition geometry.h:478
GenericLine(const PointType &p1, const PointType &p2)
Creates a line through the points p1 and p2.
Definition geometry.h:475
GenericLine(numberType x1, numberType y1, numberType x2, numberType y2)
Creates a line through the points (x1,y1) and (x2,y2).
Definition geometry.h:481
virtual bool contains(const DPoint &p) const
Returns true iff p lies on this line.
Definition geometry.h:560
GenericLine()
Creates an empty line.
Definition geometry.h:472
bool isVertical() const
Returns true iff this line runs vertically.
Definition geometry.h:503
bool isHorizontal() const
Returns true iff this line runs horizontally.
Definition geometry.h:506
IntersectionType intersection(const GenericLine< PointType > &line, DPoint &inter) const
Returns an IntersectionType specifying whether line and this line intersect.
Definition geometry.h:536
bool operator==(const GenericLine< PointType > &dl) const
Equality operator.
Definition geometry.h:485
typename PointType::numberType numberType
Definition geometry.h:458
double det(const GenericLine< PointType > &line) const
Determines if line is left or right of this line.
Definition geometry.h:524
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
Parameterized base class for points.
Definition geometry.h:81
double norm() const
Returns the norm of the point.
Definition geometry.h:165
T operator*(const GenericPoint< T > &dv) const
Returns the scalar product of this and dv.
Definition geometry.h:214
GenericPoint< T > & operator*=(T c)
Point-wise multiplies this with c.
Definition geometry.h:182
GenericPoint< T > & operator/=(T c)
Point-wise divide this by c.
Definition geometry.h:199
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
GenericPoint< T > & operator-=(const GenericPoint< T > &p)
Subtracts p from this.
Definition geometry.h:175
GenericPoint(T x=0, T y=0)
Creates a generic point (x,y).
Definition geometry.h:90
double angle(GenericPoint< T > q, GenericPoint< T > r) const
Compute angle (in radians) between vectors.
Definition geometry.h:135
friend GenericPoint< T > operator*(T c, const GenericPoint< T > &p)
Point-wise multiplies p with c.
Definition geometry.h:189
GenericPoint< T > & operator+=(const GenericPoint< T > &p)
Adds p to this.
Definition geometry.h:168
friend GenericPoint< T > operator*(const GenericPoint< T > &p, T c)
Point-wise multiplies p with c.
Definition geometry.h:194
bool operator==(const GenericPoint< T > &dp) const
Equality operator.
Definition geometry.h:105
T m_y
The y-coordinate.
Definition geometry.h:87
double angleDegrees(GenericPoint< T > q, GenericPoint< T > r) const
Compute angle (in degrees) between vectors.
Definition geometry.h:153
GenericPoint< T > orthogonal() const
Returns a vector that is orthogonal to this vector.
Definition geometry.h:222
T determinant(const GenericPoint< T > &dv) const
Returns the determinant of the matrix (this, dv).
Definition geometry.h:211
double distance(const GenericPoint< T > &p) const
Returns the Euclidean distance between p and this point.
Definition geometry.h:158
T m_x
The x-coordinate.
Definition geometry.h:86
GenericPoint< T > & operator=(const GenericPoint< T > &p)
Assignment operator.
Definition geometry.h:96
bool operator>(const GenericPoint< T > &p) const
Operator 'greater'. Returns true iff p is less than this.
Definition geometry.h:122
GenericPoint(const GenericPoint< T > &p)
Copy constructor.
Definition geometry.h:93
bool operator!=(const GenericPoint< T > &p) const
Inequality operator.
Definition geometry.h:111
T numberType
The type for coordinates of the point.
Definition geometry.h:84
friend GenericPoint< T > operator/(const GenericPoint< T > &p, double c)
Point-wise divide p by c.
Definition geometry.h:206
GenericPoint< T > operator+(const GenericPoint< T > &p) const
Addition of points.
Definition geometry.h:125
GenericPoint< T > operator-(const GenericPoint< T > &p) const
Subtraction of points.
Definition geometry.h:130
Polylines with PointType points.
Definition geometry.h:261
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
GenericPolyline< PointType > & operator=(const GenericPolyline &pl)
Assignment operator.
Definition geometry.h:273
GenericPolyline()
Creates an empty polyline.
Definition geometry.h:264
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
GenericPolyline(const GenericPolyline< PointType > &pl)
Copy constructor.
Definition geometry.h:270
void unify()
Deletes all successive points with equal coordinates.
Definition geometry.h:357
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
GenericPolyline(const List< PointType > &pl)
Creates a polyline using the list of points pl.
Definition geometry.h:267
double length() const
Returns the Euclidean length of the polyline.
Definition geometry.h:279
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
Finite line segments.
Definition geometry.h:631
bool operator==(const GenericSegment< PointType > &dl) const
Equality operator.
Definition geometry.h:676
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
GenericSegment()
Creates an empty line segment.
Definition geometry.h:657
bool operator!=(const GenericSegment< PointType > &dl) const
Inequality operator.
Definition geometry.h:681
GenericLine< PointType >::numberType dx() const
Returns the x-coordinate of the difference (end point - start point).
Definition geometry.h:690
double length() const
Returns the length (Euclidean distance between start and end point) of this line segment.
Definition geometry.h:740
GenericSegment(const GenericSegment< PointType > &ds)=default
Copy constructor.
GenericLine< PointType >::numberType dy() const
Returns the y-coordinate of the difference (end point - start point).
Definition geometry.h:693
GenericSegment(const PointType &p1, const PointType &p2)
Creates a line segment from p1 to p2.
Definition geometry.h:660
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
const PointType & start() const
Returns the start point of the line segment.
Definition geometry.h:684
GenericSegment(double x1, double y1, double x2, double y2)
Creates a line segment from (x1,y1) to (x2,y2).
Definition geometry.h:666
bool contains(const PointType &p) const override
Returns true iff p lies on this line segment.
Definition geometry.h:735
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
GenericSegment & operator=(const GenericSegment< PointType > &ds)=default
Copy assignment operator.
GenericSegment(const GenericLine< PointType > &dl)
Creates a line segment defined by the start and end point of line dl.
Definition geometry.h:663
const PointType & end() const
Returns the end point of the line segment.
Definition geometry.h:687
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
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
void popFront()
Removes the first element from the list.
Definition List.h:1585
int size() const
Returns the number of elements in the list.
Definition List.h:1488
iterator pushBack(const PointType &x)
Adds element x at the end of the list.
Definition List.h:1547
void del(iterator it)
Removes it from the list.
Definition List.h:1611
List< E > & operator=(const List< E > &L)
Assignment operator.
Definition List.h:1501
iterator pushFront(const PointType &x)
Adds element x at the beginning of the list.
Definition List.h:1534
void popBack()
Removes the last element from the list.
Definition List.h:1598
Encapsulates a pointer to a list element.
Definition List.h:113
bool valid() const
Returns true iff the iterator points to an element.
Definition List.h:153
iterator begin()
Returns an iterator to the first element of the list.
Definition List.h:391
int pos(const_iterator it) const
Returns the position (starting with 0) of iterator it in the list.
Definition List.h:369
reverse_iterator rbegin()
Returns an iterator to the last element of the list.
Definition List.h:427
bool empty() const
Returns true iff the list is empty.
Definition List.h:286
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
Shape
Types for node shapes.
Definition graphics.h:120
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
constexpr double pi
The constant .
Definition Math.h:63
double radiansToDegrees(const double &angleInRadians)
Converts an angle from radians to degrees.
Definition Math.h:134
The namespace for all OGDF objects.
IntersectionType
Determines the type of intersection of two geometric objects.
Definition geometry.h:63
@ SinglePoint
Two geometric objects intersect in a single point.
@ None
Two geometric objects do not intersect.
@ Overlapping
Two geometric objects intersect in infinitely many points.
int orientation(const DPoint &p, const DPoint &q, const DPoint &r)
GenericPoint< double > DPoint
Representing two-dimensional point with real coordinates.
Definition geometry.h:244
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition Array.h:983
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).
HypergraphRegistry< HypernodeElement >::iterator begin(const HypergraphRegistry< HypernodeElement > &self)
Orientation
Determines the orientation in hierarchical layouts.
Definition geometry.h:55
@ rightToLeft
Edges are oriented from right to left.
@ bottomToTop
Edges are oriented from bottom to top.
@ leftToRight
Edges are oriented from left to right.
@ topToBottom
Edges are oriented from top to bottom.
const EpsilonTest OGDF_GEOM_ET
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...
HypergraphRegistry< HypernodeElement >::iterator end(const HypergraphRegistry< HypernodeElement > &self)