Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
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
46namespace ogdf {
47namespace internal {
48namespace gcm {
49namespace geometry {
50
51template<typename kernel>
52using Point_t = CGAL::Point_2<kernel>;
53
54template<typename kernel>
55inline 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
59template<typename kernel>
60inline 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
64template<typename kernel, typename precision>
65inline 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
70template<typename kernel>
71inline 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
77template<typename kernel>
78void 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
83template<typename kernel>
84void 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
89template<typename Kernel>
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
114template<typename Kernel, typename T>
115inline 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
119template<typename t>
120inline 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
124template<typename kernel>
125inline 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
130template<typename kernel>
131inline 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
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
MDMFLengthAttribute operator+(MDMFLengthAttribute x, const MDMFLengthAttribute &y)
bool equal(const node a, const node b)
Definition Universal.h:42
The namespace for all OGDF objects.