diff --git a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h index 7bc920bd961..44dfe560667 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h @@ -2741,6 +2741,7 @@ namespace CartesianKernelFunctors { { typedef typename K::FT FT; typedef typename K::Point_2 Point_2; + typedef typename K::Segment_2 Segment_2; public: typedef Point_2 result_type; @@ -2752,6 +2753,17 @@ namespace CartesianKernelFunctors { midpointC2(p.x(), p.y(), q.x(), q.y(), x, y); return construct_point_2(x, y); } + + Point_2 + operator()(const Segment_2& s) const + { + typename K::Construct_point_2 construct_point_2; + FT x, y; + const Point_2& p = s.source(); + const Point_2& q = s.target(); + midpointC2(p.x(), p.y(), q.x(), q.y(), x, y); + return construct_point_2(x, y); + } }; template @@ -2759,6 +2771,7 @@ namespace CartesianKernelFunctors { { typedef typename K::FT FT; typedef typename K::Point_3 Point_3; + typedef typename K::Segment_3 Segment_3; public: typedef Point_3 result_type; @@ -2770,6 +2783,17 @@ namespace CartesianKernelFunctors { midpointC3(p.x(), p.y(), p.z(), q.x(), q.y(), q.z(), x, y, z); return construct_point_3(x, y, z); } + + Point_3 + operator()(const Segment_3& s) const + { + const Point_3& p = s.source(); + const Point_3& q = s.target(); + typename K::Construct_point_3 construct_point_3; + FT x, y, z; + midpointC3(p.x(), p.y(), p.z(), q.x(), q.y(), q.z(), x, y, z); + return construct_point_3(x, y, z); + } }; template diff --git a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h index 2868dd8f7d2..2f62b8ffb85 100644 --- a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h +++ b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h @@ -2950,6 +2950,7 @@ namespace HomogeneousKernelFunctors { { typedef typename K::FT FT; typedef typename K::Point_2 Point_2; + typedef typename K::Segment_2 Segment_2; public: typedef Point_2 result_type; @@ -2963,6 +2964,19 @@ namespace HomogeneousKernelFunctors { p.hy()*qhw + q.hy()*phw, phw * qhw * RT( 2)); } + + Point_2 + operator()(const Segment_2& s) const + { + typedef typename K::RT RT; + const Point_2& p = s.source(); + const Point_2& q = s.target(); + const RT& phw = p.hw(); + const RT& qhw = q.hw(); + return Point_2( p.hx()*qhw + q.hx()*phw, + p.hy()*qhw + q.hy()*phw, + phw * qhw * RT( 2)); + } }; template @@ -2970,6 +2984,7 @@ namespace HomogeneousKernelFunctors { { typedef typename K::FT FT; typedef typename K::Point_3 Point_3; + typedef typename K::Segment_3 Segment_3; public: typedef Point_3 result_type; @@ -2984,6 +2999,20 @@ namespace HomogeneousKernelFunctors { p.hz()*qhw + q.hz()*phw, RT(2) * phw * qhw ); } + + Point_3 + operator()(const Segment_3& s) const + { + typedef typename K::RT RT; + const Point_3& p = s.source(); + const Point_3& q = s.target(); + RT phw = p.hw(); + RT qhw = q.hw(); + return Point_3( p.hx()*qhw + q.hx()*phw, + p.hy()*qhw + q.hy()*phw, + p.hz()*qhw + q.hz()*phw, + RT(2) * phw * qhw ); + } }; // TODO ... diff --git a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h index bb63612593e..de21eb21c62 100644 --- a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h +++ b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h @@ -2242,12 +2242,25 @@ template CGAL::Point_2 midpoint( const CGAL::Point_2& p, const CGAL::Point_2& q ); + + /*! +computes the midpoint of the segment `s`. +*/ +template +CGAL::Point_2 midpoint( const CGAL::Segment_2& s); + /*! computes the midpoint of the segment `pq`. */ template CGAL::Point_3 midpoint( const CGAL::Point_3& p, const CGAL::Point_3& q ); +/*! +computes the midpoint of the segment `s`. +*/ +template +CGAL::Point_3 midpoint( const CGAL::Segment_3& s ); + /// @} /// \defgroup min_vertex_grp CGAL::min_vertex() diff --git a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h index 43441f7fac7..96dea893001 100644 --- a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h +++ b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h @@ -4996,6 +4996,10 @@ public: */ Kernel::Point_2 operator()(const Kernel::Point_2& p, const Kernel::Point_2& q ); + /*! + computes the midpoint of the segment `s`. + */ + Kernel::Point_2 operator()(const Kernel::Segment_2& s); /// @} @@ -5023,6 +5027,11 @@ public: Kernel::Point_3 operator()(const Kernel::Point_3& p, const Kernel::Point_3& q ); + /*! + computes the midpoint of the segment `s`. + */ + Kernel::Point_3 operator()(const Kernel::Segment_3& s); + /// @} diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_2.h b/Kernel_23/include/CGAL/Kernel/global_functions_2.h index 0e736be48d6..6cc0d7c8808 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_2.h @@ -754,6 +754,12 @@ midpoint(const Point_2 &p, const Point_2 &q) return internal::midpoint(p, q, K()); } +template < class K > +inline typename K::Point_2 midpoint(const Segment_2 &s) +{ + return internal::midpoint(s, K()); +} + template < class K > inline typename K::Point_2 diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_3.h b/Kernel_23/include/CGAL/Kernel/global_functions_3.h index 72a1ad72af1..21db33bec8d 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_3.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_3.h @@ -738,6 +738,12 @@ midpoint(const Point_3 &p, const Point_3 &q) return internal::midpoint(p, q, K()); } +template < class K > +inline typename K::Point_3 midpoint(const Segment_3 &s) +{ + return internal::midpoint(s, K()); +} + template < class K > inline typename K::Point_3 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..a9e659f704c 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h @@ -788,6 +788,14 @@ midpoint(const typename K::Point_2 &p, return k.construct_midpoint_2_object()(p, q); } +template < class K > +inline +typename K::Point_2 +midpoint(const typename K::Segment_2 &s, const K &k) +{ + return k.construct_midpoint_2_object()(s); +} + template < class K > inline typename K::Point_2 diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h b/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h index 7096bff956c..8beb0d396d5 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h @@ -829,6 +829,14 @@ midpoint(const typename K::Point_3 &p, return k.construct_midpoint_3_object()(p, q); } +template < class K > +inline +typename K::Point_3 +midpoint(const typename K::Segment_3 &s, const K &k) +{ + return k.construct_midpoint_3_object()(s); +} + template < class K > inline typename K::Point_3 diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_constructions_2.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_constructions_2.h index 33f33a4986e..288d6a55dfd 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_constructions_2.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_constructions_2.h @@ -24,6 +24,7 @@ _test_fct_constructions_2(const R&) { typedef typename R::RT RT; typedef CGAL::Point_2 Point; + typedef CGAL::Segment_2 Segment; typedef CGAL::Weighted_point_2 Weighted_Point; typedef CGAL::Triangle_2 Triangle; typedef CGAL::Vector_2 Vector; @@ -52,6 +53,7 @@ _test_fct_constructions_2(const R&) // midpoint assert( CGAL::midpoint( pne, psw) == p); assert( CGAL::midpoint( pnw, pse) == p); + assert( CGAL::midpoint( Segment{pnw, pse}) == p); // circumcenter assert( CGAL::circumcenter( pne, pne ) == pne); diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_constructions_3.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_constructions_3.h index 42f3598d57a..e45abb683e9 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_constructions_3.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_constructions_3.h @@ -69,6 +69,7 @@ _test_fct_constructions_3(const R& r) assert( CGAL::midpoint( p110, p001) == p); assert( CGAL::midpoint( p010, p101) == p); assert( CGAL::midpoint( p100, p011) == p); + assert( CGAL::midpoint( Segment{p100, p011}) == p); // circumcenter assert( CGAL::circumcenter( p111, p001, p010, p000) == p);