33 #ifdef OGDF_INCLUDE_CGAL
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>
51 template<
typename kernel>
52 using Point_t = CGAL::Point_2<kernel>;
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();
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)));
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));
70 template<
typename kernel>
71 inline bool is_valid(
const Point_t<kernel>& p) {
73 return CGAL::is_finite(p.x()) && CGAL::is_finite(p.y()) && CGAL::is_valid(p.x())
74 && CGAL::is_valid(p.y());
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()));
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()));
89 template<
typename Kernel>
90 struct ExactPointComparison {
91 using Point = Point_t<Kernel>;
93 static bool equal(
const Point& p1,
const Point& p2) {
return is_the_same(p1, p2); }
95 static bool less(
const Point& p1,
const Point& p2) {
96 return p1.x() < p2.x() || (p1.x() == p2.x() && p1.y() < p2.y());
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());
103 static bool greater(
const Point& p1,
const Point& p2) {
104 return p1.x() > p2.x() || (p1.x() == p2.x() && p1.y() > p2.y());
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());
111 bool operator()(
const Point& p1,
const Point& p2)
const {
return less(p1, p2); }
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())};
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()};
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);
130 template<
typename kernel>
131 inline Point_t<kernel> operator*(
const typename kernel::FT v,
const Point_t<kernel>& p) {