Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Line.h
Go to the documentation of this file.
1 
31 #pragma once
32 
33 #ifdef OGDF_INCLUDE_CGAL
34 
37 
38 # include <CGAL/Line_2.h>
39 # include <math.h>
40 
41 namespace ogdf {
42 namespace internal {
43 namespace gcm {
44 namespace geometry {
45 using namespace tools;
46 template<typename kernel>
47 using Line_t = CGAL::Line_2<kernel>;
48 
49 template<typename kernel>
50 inline bool turn(const Line_t<kernel>& l1, const Line_t<kernel>& l2) {
51  return turn(l1.to_vector(), l2.to_vector());
52 }
53 
54 template<typename kernel>
55 inline bool left_turn(const Line_t<kernel>& l1, const Line_t<kernel>& l2) {
56  return left_turn(l1.to_vector(), l2.to_vector());
57 }
58 
59 template<typename kernel>
60 inline bool right_turn(const Line_t<kernel>& l1, const Line_t<kernel>& l2) {
61  return right_turn(l1.to_vector(), l2.to_vector());
62 }
63 
64 template<typename kernel>
65 inline bool turn(const Line_t<kernel>& l, const Point_t<kernel>& p) {
66  return turn(l.to_vector(), p - l.point(0));
67 }
68 
69 template<typename kernel>
70 inline bool left_turn(const Line_t<kernel>& l, const Point_t<kernel>& p) {
71  return left_turn(l.to_vector(), p - l.point(0));
72 }
73 
74 template<typename kernel>
75 inline bool right_turn(const Line_t<kernel>& l, const Point_t<kernel>& p) {
76  return right_turn(l.to_vector(), p - l.point(0));
77 }
78 
79 template<typename kernel>
80 inline Point_t<kernel> intersect(const Line_t<kernel>& l1, const Line_t<kernel>& l2) {
81  OGDF_ASSERT(!l1.is_degenerate());
82  OGDF_ASSERT(!l2.is_degenerate());
83  auto result = CGAL::intersection(l1, l2);
84  if (!result) {
85  return Point_t<kernel>(std::numeric_limits<unsigned int>::max(),
86  std::numeric_limits<unsigned int>::max());
87  }
88 
89  Point_t<kernel> intersection;
90  if (boost::get<Line_t<kernel>>(&*result)) {
91  auto s = boost::get<Line_t<kernel>>(&*result);
92  intersection = s->point(0);
93  } else {
94  intersection = *boost::get<Point_t<kernel>>(&*result);
95  }
96  return intersection;
97 }
98 
99 } /* namespace geometry */
100 }
101 }
102 }
103 
104 #endif
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
Point.h
Vector.h