Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Cone.h
Go to the documentation of this file.
1 
31 #pragma once
32 
33 #ifdef OGDF_INCLUDE_CGAL
34 
37 
38 namespace ogdf {
39 namespace internal {
40 namespace gcm {
41 namespace geometry {
42 
43 /*
44  * A cone through the origin defined by two vectors. Everything that is counter clockwise in between the left and right
45  * is within the cone. left and right are not supposed to be parallel
46  * A cone is not necessarly acute / convex
47  */
48 template<typename Kernel>
49 class Cone_t {
50 private:
51  using Vector = Vector_t<Kernel>;
52  using Direction = Direction_t<Kernel>;
53  Direction m_left;
54  Direction m_right;
55 
56 public:
57  Cone_t(const Vector& left, const Vector& right) : Cone_t(left.direction, right.direction()) {
58  // nothing to do
59  }
60 
61  Cone_t(const Direction& left, const Direction& right) : m_left(left), m_right(right) {
62  OGDF_ASSERT(left != right);
63  // nothing to do
64  }
65 
66  const Direction& left() const { return m_left; }
67 
68  const Direction& right() const { return m_right; }
69 };
70 
71 /*
72  * is c_1 subset of c_2
73  */
74 template<typename Kernel>
75 bool is_subset(const Cone_t<Kernel>& c_1, const Cone_t<Kernel>& c_2) {
76  return c_1.left().counterclockwise_in_between(c_2.left(), c_2.right())
77  && c_1.right().counterclockwise_in_between(c_2.left(), c_2.right());
78 }
79 
80 template<typename Kernel>
81 bool is_in(const Direction_t<Kernel>& d, const Cone_t<Kernel>& c) {
82  return d.counterclockwise_in_between(c.left(), c.right());
83 }
84 
85 template<typename Kernel>
86 bool do_intersect(const Cone_t<Kernel>& c_1, const Cone_t<Kernel>& c_2) {
87  return is_in(c_1.left(), c_2) || is_in(c_1.right(), c_2) || is_in(c_2.left(), c_1)
88  || is_in(c_2.right(), c_1);
89 }
90 
91 template<typename kernel>
92 std::ostream& operator<<(std::ostream& os, const Cone_t<kernel>& c) {
93  os << "cone[(" << c.left().vector() << ", " << c.right().vector() << ")]";
94  return os;
95 }
96 
97 }
98 }
99 }
100 }
101 
102 #endif
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::Direction
Direction
Definition: basic.h:150
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
Vector.h
ogdf::operator<<
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:983
Direction.h