From 20d1629e1b271d94bfc8cc84d38a5abf3f4329b6 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 30 Apr 2021 17:39:57 +0200 Subject: [PATCH] Add compare_slope with 4 points --- .../include/CGAL/Cartesian/function_objects.h | 10 ++++ .../CGAL/Homogeneous/function_objects.h | 52 +++++++++++-------- .../Concepts/FunctionObjectConcepts.h | 10 ++++ .../include/CGAL/Kernel/global_functions_2.h | 9 ++++ .../CGAL/Kernel/global_functions_internal_2.h | 11 ++++ .../test/Kernel_23/include/CGAL/_test_new_2.h | 3 +- 6 files changed, 72 insertions(+), 23 deletions(-) diff --git a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h index 7bc920bd961..2508e6f8f81 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h @@ -606,6 +606,7 @@ namespace CartesianKernelFunctors { template class Compare_slope_2 { + typedef typename K::Point_2 Point_2; typedef typename K::Line_2 Line_2; typedef typename K::Segment_2 Segment_2; public: @@ -625,6 +626,15 @@ namespace CartesianKernelFunctors { s2.source().x(), s2.source().y(), s2.target().x(), s2.target().y()); } + + result_type + operator()(const Point_2& s1s, const Point_2& s1t, const Point_2& s2s, const Point_2& s2t) const + { + return compare_slopesC2(s1s.x(), s1s.y(), + s1t.x(), s1t.y(), + s2s.x(), s2s.y(), + s2t.x(), s2t.y()); + } }; template diff --git a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h index 2868dd8f7d2..7123511b4d5 100644 --- a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h +++ b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h @@ -810,6 +810,7 @@ namespace HomogeneousKernelFunctors { template class Compare_slope_2 { + typedef typename K::Point_2 Point_2; typedef typename K::Line_2 Line_2; typedef typename K::Segment_2 Segment_2; public: @@ -842,48 +843,55 @@ namespace HomogeneousKernelFunctors { result_type operator()(const Segment_2& s1, const Segment_2& s2) const + { + return (*this)(s1.source(), s1.target(), + s2.source(), s2.target()); + } + + result_type + operator()(const Point_2& s1s, const Point_2& s1t, const Point_2& s2s, const Point_2& s2t) const { typedef typename K::FT FT; - typename K::Comparison_result cmp_y1 = compare_y(s1.source(), s1.target()); + typename K::Comparison_result cmp_y1 = compare_y(s1s, s1t); if (cmp_y1 == EQUAL) // horizontal { - typename K::Comparison_result cmp_x2 = compare_x(s2.source(), s2.target()); + typename K::Comparison_result cmp_x2 = compare_x(s2s, s2t); if (cmp_x2 == EQUAL) return SMALLER; - FT s_hw = s2.source().hw(); - FT t_hw = s2.target().hw(); - return - CGAL_NTS sign(s2.source().hy()*t_hw - s2.target().hy()*s_hw) * - CGAL_NTS sign(s2.source().hx()*t_hw - s2.target().hx()*s_hw); + FT s_hw = s2s.hw(); + FT t_hw = s2t.hw(); + return - CGAL_NTS sign(s2s.hy()*t_hw - s2t.hy()*s_hw) * + CGAL_NTS sign(s2s.hx()*t_hw - s2t.hx()*s_hw); } - typename K::Comparison_result cmp_y2 = compare_y(s2.source(), s2.target()); + typename K::Comparison_result cmp_y2 = compare_y(s2s, s2t); if (cmp_y2 == EQUAL) { - typename K::Comparison_result cmp_x1 = compare_x(s1.source(), s1.target()); + typename K::Comparison_result cmp_x1 = compare_x(s1s, s1t); if (cmp_x1 == EQUAL) return LARGER; - FT s_hw = s1.source().hw(); - FT t_hw = s1.target().hw(); - return CGAL_NTS sign(s1.source().hy()*t_hw - s1.target().hy()*s_hw) * - CGAL_NTS sign(s1.source().hx()*t_hw - s1.target().hx()*s_hw); + FT s_hw = s1s.hw(); + FT t_hw = s1t.hw(); + return CGAL_NTS sign(s1s.hy()*t_hw - s1t.hy()*s_hw) * + CGAL_NTS sign(s1s.hx()*t_hw - s1t.hx()*s_hw); } - typename K::Comparison_result cmp_x1 = compare_x(s1.source(), s1.target()); - typename K::Comparison_result cmp_x2 = compare_x(s2.source(), s2.target()); + typename K::Comparison_result cmp_x1 = compare_x(s1s, s1t); + typename K::Comparison_result cmp_x2 = compare_x(s2s, s2t); if (cmp_x1 == EQUAL) return cmp_x2 == EQUAL ? EQUAL : LARGER; if (cmp_x2 == EQUAL) return SMALLER; - FT s1_s_hw = s1.source().hw(); - FT s1_t_hw = s1.target().hw(); - FT s2_s_hw = s2.source().hw(); - FT s2_t_hw = s2.target().hw(); - FT s1_xdiff = s1.source().hx()*s1_t_hw - s1.target().hx()*s1_s_hw; - FT s1_ydiff = s1.source().hy()*s1_t_hw - s1.target().hy()*s1_s_hw; - FT s2_xdiff = s2.source().hx()*s2_t_hw - s2.target().hx()*s2_s_hw; - FT s2_ydiff = s2.source().hy()*s2_t_hw - s2.target().hy()*s2_s_hw; + FT s1_s_hw = s1s.hw(); + FT s1_t_hw = s1t.hw(); + FT s2_s_hw = s2s.hw(); + FT s2_t_hw = s2t.hw(); + FT s1_xdiff = s1s.hx()*s1_t_hw - s1t.hx()*s1_s_hw; + FT s1_ydiff = s1s.hy()*s1_t_hw - s1t.hy()*s1_s_hw; + FT s2_xdiff = s2s.hx()*s2_t_hw - s2t.hx()*s2_s_hw; + FT s2_ydiff = s2s.hy()*s2_t_hw - s2t.hy()*s2_s_hw; typename K::Sign s1_sign = CGAL_NTS sign(s1_ydiff * s1_xdiff); typename K::Sign s2_sign = CGAL_NTS sign(s2_ydiff * s2_xdiff); diff --git a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h index 43441f7fac7..20ef94b7df1 100644 --- a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h +++ b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h @@ -1040,6 +1040,16 @@ public: */ Comparison_result operator()(const Kernel::Segment_2& s1, const Kernel::Segment_2& s2); + + /*! + compares the slopes of the segments `(s1s,s1t)` and `(s2s,s2t)`, + where the slope is the variation of the `y`-coordinate + from the left to the right endpoint of the segments. + */ + Comparison_result operator()(const Kernel::Point_2& s1s, + const Kernel::Point_2& s1t, + const Kernel::Point_2& s2s, + const Kernel::Point_2& s2t)); /// @} diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_2.h b/Kernel_23/include/CGAL/Kernel/global_functions_2.h index 0e736be48d6..a3a173a4446 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_2.h @@ -347,6 +347,15 @@ compare_slope(const Segment_2 &s1, const Segment_2 &s2) return internal::compare_slope(s1, s2, K()); } +template < class K > +inline +typename K::Comparison_result +compare_slope(const Point_2 &s1s, const Point_2 &s1t, + const Point_2 &s2s, const Point_2 &s2t) +{ + return internal::compare_slope(s1s, s1t, s2s, s2t, K()); +} + #ifndef CGAL_NO_DEPRECATED_CODE // kept for backward compatibility diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h b/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h index 42c1ac639ca..d25ad829947 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h @@ -373,6 +373,17 @@ compare_slope(const typename K::Segment_2 &s1, return k.compare_slope_2_object()(s1, s2); } +template < class K > +inline +typename K::Comparison_result +compare_slope(const typename K::Point_2 &s1s, + const typename K::Point_2 &s1t, + const typename K::Point_2 &s2s, + const typename K::Point_2 &s2t,const K& k) +{ + return k.compare_slope_2_object()(s1s, s1t, s2s, s2t); +} + template < class K > inline typename K::Comparison_result diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_new_2.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_new_2.h index efbae8e7e89..367be24d322 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_new_2.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_new_2.h @@ -477,6 +477,7 @@ test_new_2(const R& rep) = rep.compare_slope_2_object(); Comparison_result tmp34ee = compare_slope(l1, l2); Comparison_result tmp34ff = compare_slope(s1, s2); + Comparison_result tmp34gg = compare_slope(p3, p5, p2, p3); typename R::Less_distance_to_point_2 less_distance_to_point = rep.less_distance_to_point_2_object(); @@ -680,7 +681,7 @@ test_new_2(const R& rep) use(tmp32a); use(tmp31d); use(tmp31c); use(tmp31b); use(tmp31a); use(tmp30); use(tmp26); use(tmp25); use(tmp24); use(tmp29); use(tmp28); use(tmp33a); use(tmp33b); use(tmp34ab); use(tmp34ac); - use(tmp34ff); use(tmp34ee); use(tmp34dd); use(tmp34cc); use(tmp34bb); + use(tmp34ff); use(tmp34gg); use(tmp34ee); use(tmp34dd); use(tmp34cc); use(tmp34bb); use(tmp34aa); use(tmp39a); use(tmp36a); use(tmp48c); use(tmp49c); use(tmp50c); use(tmp24a); use(tmp24b); use(tmp24c); use(tmp24d); use(tmp24e); use(tmp24f);