Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Point.h
Go to the documentation of this file.
1 
31 #pragma once
32 
33 #ifdef OGDF_INCLUDE_CGAL
34 
37 
38 # include <limits>
39 # include <sstream>
40 
41 # include <CGAL/Aff_transformation_2.h>
42 # include <CGAL/Point_2.h>
43 # include <CGAL/aff_transformation_tags.h>
44 # include <CGAL/squared_distance_2.h>
45 
46 namespace ogdf {
47 namespace internal {
48 namespace gcm {
49 namespace geometry {
50 
51 template<typename kernel>
52 using Point_t = CGAL::Point_2<kernel>;
53 
54 template<typename kernel>
55 inline bool is_the_same(const Point_t<kernel>& p1, const Point_t<kernel>& p2) {
56  return p1.x() == p2.x() && p1.y() == p2.y();
57 }
58 
59 template<typename kernel>
60 inline typename kernel::FT distance(const Point_t<kernel>& p1, const Point_t<kernel>& p2) {
61  return CGAL::sqrt(CGAL::to_double(CGAL::squared_distance(p1, p2)));
62 }
63 
64 template<typename kernel, typename precision>
65 inline Point_t<kernel> rotate(const Point_t<kernel>& p, precision angle) {
66  CGAL::Aff_transformation_2<kernel> rotate(CGAL::ROTATION, sin(angle), cos(angle));
67  return std::move(rotate(p));
68 }
69 
70 template<typename kernel>
71 inline bool is_valid(const Point_t<kernel>& p) {
72  //return !isinf(p.x()) && !isinf(p.y()) && !isnan(p.x()) && !isnan(p.y());
73  return CGAL::is_finite(p.x()) && CGAL::is_finite(p.y()) && CGAL::is_valid(p.x())
74  && CGAL::is_valid(p.y());
75 }
76 
77 template<typename kernel>
78 void serialize(const Point_t<kernel>& p, std::ostream& os) {
79  os.write(reinterpret_cast<const char*>(&p.x()), sizeof(p.x()));
80  os.write(reinterpret_cast<const char*>(&p.y()), sizeof(p.y()));
81 }
82 
83 template<typename kernel>
84 void deserialize(Point_t<kernel>& p, std::istream& in) {
85  in.read(reinterpret_cast<char*>(&p.x()), sizeof(p.x()));
86  in.read(reinterpret_cast<char*>(&p.y()), sizeof(p.y()));
87 }
88 
89 template<typename Kernel>
90 struct ExactPointComparison {
91  using Point = Point_t<Kernel>;
92 
93  static bool equal(const Point& p1, const Point& p2) { return is_the_same(p1, p2); }
94 
95  static bool less(const Point& p1, const Point& p2) {
96  return p1.x() < p2.x() || (p1.x() == p2.x() && p1.y() < p2.y());
97  }
98 
99  static bool less_equal(const Point& p1, const Point& p2) {
100  return p1.x() < p2.x() || (p1.x() == p2.x() && p1.y() <= p2.y());
101  }
102 
103  static bool greater(const Point& p1, const Point& p2) {
104  return p1.x() > p2.x() || (p1.x() == p2.x() && p1.y() > p2.y());
105  }
106 
107  static bool greater_equal(const Point& p1, const Point& p2) {
108  return p1.x() > p2.x() || (p1.x() == p2.x() && p1.y() >= p2.y());
109  }
110 
111  bool operator()(const Point& p1, const Point& p2) const { return less(p1, p2); }
112 };
113 
114 template<typename Kernel, typename T>
115 inline geometry::Point_t<Kernel> cast(const geometry::Point_t<T>& p) {
116  return {(typename Kernel::FT)(p.x()), (typename Kernel::FT)(p.y())};
117 }
118 
119 template<typename t>
120 inline Point_t<t> operator+(const Point_t<t>& p1, const Point_t<t>& p2) {
121  return {p1.x() + p2.x(), p1.y() + p2.y()};
122 }
123 
124 template<typename kernel>
125 inline Point_t<kernel> operator*(const Point_t<kernel>& p, const typename kernel::FT v) {
126  CGAL::Aff_transformation_2<kernel> scale(CGAL::SCALING, v);
127  return std::move(scale(p));
128 }
129 
130 template<typename kernel>
131 inline Point_t<kernel> operator*(const typename kernel::FT v, const Point_t<kernel>& p) {
132  return std::move(p * v);
133 }
134 
135 
136 } //namespace
137 }
138 }
139 }
140 
141 #endif
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
math.h
ogdf::internal::gcm::tools::equal
bool equal(const node a, const node b)
Definition: Universal.h:42
ogdf::embedder::operator+
MDMFLengthAttribute operator+(MDMFLengthAttribute x, const MDMFLengthAttribute &y)
Definition: MDMFLengthAttribute.h:104
Vector.h
backward::details::move
const T & move(const T &v)
Definition: backward.hpp:243
ogdf::gml::Key::Point
@ Point