From e313fdc697b531f2e7e3ca564f8568c6cd8ab2e5 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Mon, 20 Mar 2023 16:25:57 +0100 Subject: [PATCH] Add Compare_xy_2 to TriangulationTraits_2 This enables customization of projection traits for CDT_2s and facilitates unification with the predicates utilized in 3D triangulations. --- .../Kernel_23/internal/Projection_traits_3.h | 5 +++++ .../internal/Projection_traits_base_3.h | 4 ++++ .../Concepts/TriangulationTraits_2.h | 18 ++++++++++++++++++ Triangulation_2/include/CGAL/Triangulation_2.h | 9 ++------- .../include/CGAL/_test_traits.h | 18 ++++++++++++++++++ 5 files changed, 47 insertions(+), 7 deletions(-) diff --git a/Kernel_23/include/CGAL/Kernel_23/internal/Projection_traits_3.h b/Kernel_23/include/CGAL/Kernel_23/internal/Projection_traits_3.h index 1cc09421944..bc691bf27d7 100644 --- a/Kernel_23/include/CGAL/Kernel_23/internal/Projection_traits_3.h +++ b/Kernel_23/include/CGAL/Kernel_23/internal/Projection_traits_3.h @@ -971,6 +971,7 @@ public: typedef typename Rp::Construct_triangle_3 Construct_triangle_2; typedef typename Rp::Construct_line_3 Construct_line_2; + typedef typename Rp::Compare_xyz_3 Compare_xy_2; struct Less_xy_2 { typedef typename R::Boolean result_type; @@ -1065,6 +1066,10 @@ public: less_x_2_object() const { return Less_x_2();} + Compare_xy_2 + compare_xy_2_object() const + { return Compare_xy_2();} + Less_xy_2 less_xy_2_object() const { return Less_xy_2();} diff --git a/Kernel_23/include/CGAL/Kernel_23/internal/Projection_traits_base_3.h b/Kernel_23/include/CGAL/Kernel_23/internal/Projection_traits_base_3.h index 089fe5ba6cb..e179fecc677 100644 --- a/Kernel_23/include/CGAL/Kernel_23/internal/Projection_traits_base_3.h +++ b/Kernel_23/include/CGAL/Kernel_23/internal/Projection_traits_base_3.h @@ -426,6 +426,7 @@ public: typedef typename K::Line_3 Line_2; typedef typename K::Angle_3 Angle_2; + typedef typename K::Compare_xyz_3 Compare_xy_2; typedef TriangulationProjectionTraitsCartesianFunctors:: Compare_along_axis Compare_x_2; @@ -524,6 +525,9 @@ public: Angle_2 angle_2_object() const {return Angle_2();} + Compare_xy_2 compare_xy_2_object() const + {return Compare_xy_2();} + Construct_point_2 construct_point_2_object() const {return Construct_point_2();} diff --git a/Triangulation_2/doc/Triangulation_2/Concepts/TriangulationTraits_2.h b/Triangulation_2/doc/Triangulation_2/Concepts/TriangulationTraits_2.h index 0d810e92288..68d24483b34 100644 --- a/Triangulation_2/doc/Triangulation_2/Concepts/TriangulationTraits_2.h +++ b/Triangulation_2/doc/Triangulation_2/Concepts/TriangulationTraits_2.h @@ -144,6 +144,19 @@ according to the */ typedef unspecified_type Compare_y_2; +/*! +A function object that lexicographically compares two points by their Cartesian +coordinates. +It provides the operator: + +`Comparison_result operator()(Point p, Point q)` + +which returns +(`SMALLER, EQUAL` or `LARGER`) +according to the lexicographical order of points `p` and `q`. +*/ +typedef unspecified_type Compare_xy_2; + /*! A function object to compute the orientation of three points. @@ -245,6 +258,11 @@ Compare_y_2 compare_y_2_object(); /*! +*/ +Compare_xy_2 compare_xy_2_object(); + +/*! + */ Orientation_2 orientation_2_object(); diff --git a/Triangulation_2/include/CGAL/Triangulation_2.h b/Triangulation_2/include/CGAL/Triangulation_2.h index c0f2c7ba50e..d367ad58778 100644 --- a/Triangulation_2/include/CGAL/Triangulation_2.h +++ b/Triangulation_2/include/CGAL/Triangulation_2.h @@ -3671,13 +3671,8 @@ Comparison_result Triangulation_2:: compare_xy(const Point& p, const Point& q) const { - Comparison_result res = geom_traits().compare_x_2_object()(construct_point(p), - construct_point(q)); - if(res == EQUAL){ - return geom_traits().compare_y_2_object()(construct_point(p), - construct_point(q)); - } - return res; + return geom_traits().compare_xy_2_object()(construct_point(p), + construct_point(q)); } template diff --git a/Triangulation_2/test/Triangulation_2/include/CGAL/_test_traits.h b/Triangulation_2/test/Triangulation_2/include/CGAL/_test_traits.h index 29e66a38e1b..bb3087c11ef 100644 --- a/Triangulation_2/test/Triangulation_2/include/CGAL/_test_traits.h +++ b/Triangulation_2/test/Triangulation_2/include/CGAL/_test_traits.h @@ -188,6 +188,19 @@ public: } }; +class Triangulation_test_Compare_xy_2{ +public: + typedef Triangulation_test_point Point; + CGAL::Comparison_result operator()( const Point& p, const Point& q) const + { + if (p.test_x() < q.test_x()) return CGAL::SMALLER; + if (p.test_x() > q.test_x()) return CGAL::LARGER; + if (p.test_y() < q.test_y()) return CGAL::SMALLER; + if (p.test_y() > q.test_y()) return CGAL::LARGER; + else return CGAL::EQUAL; + } +}; + class Triangulation_test_Orientation_2 { public: @@ -416,6 +429,7 @@ public: typedef Triangulation_test_Less_y_2 Less_y_2; typedef Triangulation_test_Compare_x_2 Compare_x_2; typedef Triangulation_test_Compare_y_2 Compare_y_2; + typedef Triangulation_test_Compare_xy_2 Compare_xy_2; typedef Triangulation_test_Orientation_2 Orientation_2; typedef Triangulation_test_Side_of_oriented_circle_2 Side_of_oriented_circle_2; @@ -450,6 +464,10 @@ public: compare_y_2_object() const { return Compare_y_2();} + Compare_xy_2 + compare_xy_2_object() const + { return Compare_xy_2();} + Orientation_2 orientation_2_object() const { return Orientation_2();}