From 42af962bc2d47173efa564dbd81c82b5e20e41af Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 23 Nov 2018 13:06:55 +0100 Subject: [PATCH] Add overload for two vectors --- .../Concepts/FunctionObjectConcepts.h | 14 ++++++++--- .../include/CGAL/Kernel/function_objects.h | 24 +++++++++++++------ .../include/CGAL/Kernel/global_functions_3.h | 9 +++++++ .../CGAL/Kernel/global_functions_internal_3.h | 9 +++++++ .../test/Kernel_23/include/CGAL/_test_angle.h | 1 + 5 files changed, 47 insertions(+), 10 deletions(-) diff --git a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h index f1c7470995f..79f74ce3a0e 100644 --- a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h +++ b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h @@ -1782,10 +1782,18 @@ public: /// A model of this concept must provide: /// @{ + /*! + returns an approximation of the angle between `u` and `v`. + The angle is given in degrees. + \pre `u`and `v` are not equal to the null vector. + */ + Kernel::FT operator()(const Kernel::Vector_3& u, + const Kernel::Vector_3& v) const; + /*! returns an approximation of the angle between `p-q` and `r-q`. The angle is given in degrees. - \pre `p`and `r` are not equal to `q`. + \pre `p` and `r` are not equal to `q`. */ Kernel::FT operator()(const Kernel::Point_3& p, const Kernel::Point_3& q, @@ -6920,7 +6928,7 @@ public: Kernel::Vector_2 operator()(const Kernel::Line_2 &l); /*! - introduces a null vector . + introduces a null vector. */ Kernel::Vector_2 operator()(const Null_vector &NULL_VECTOR); @@ -6979,7 +6987,7 @@ public: Kernel::Vector_3 operator()(const Kernel::Line_3 &l); /*! - introduces a null vector . + introduces a null vector. */ Kernel::Vector_3 operator()(const Null_vector &NULL_VECTOR); diff --git a/Kernel_23/include/CGAL/Kernel/function_objects.h b/Kernel_23/include/CGAL/Kernel/function_objects.h index 3d49c063a9d..d1e8959f5a7 100644 --- a/Kernel_23/include/CGAL/Kernel/function_objects.h +++ b/Kernel_23/include/CGAL/Kernel/function_objects.h @@ -832,21 +832,18 @@ namespace CommonKernelFunctors { template class Compute_approximate_angle_3 { - typedef typename K::Point_3 Point_3; + typedef typename K::Point_3 Point_3; + typedef typename K::Vector_3 Vector_3; + public: typedef typename K::FT result_type; result_type - operator()(const Point_3& p, const Point_3& q, const Point_3& r) const + operator()(const Vector_3& u, const Vector_3& v) const { K k; - typename K::Construct_vector_3 vector = k.construct_vector_3_object(); typename K::Compute_scalar_product_3 scalar_product = k.compute_scalar_product_3_object(); - typedef typename K::Vector_3 Vector_3; - - Vector_3 u = vector(q,p); - Vector_3 v = vector(q,r); double product = CGAL::sqrt(to_double(scalar_product(u,u))) * CGAL::sqrt(to_double(scalar_product(v,v))); @@ -866,6 +863,19 @@ namespace CommonKernelFunctors { return std::acos(cosine) * 180./CGAL_PI; } + + + result_type + operator()(const Point_3& p, const Point_3& q, const Point_3& r) const + { + K k; + typename K::Construct_vector_3 vector = k.construct_vector_3_object(); + + Vector_3 u = vector(q,p); + Vector_3 v = vector(q,r); + + return this->operator()(u,v); + } }; template diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_3.h b/Kernel_23/include/CGAL/Kernel/global_functions_3.h index 4ca56b312a4..ab7af514c4f 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_3.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_3.h @@ -69,6 +69,15 @@ angle(const Point_3 &p, const Point_3 &q, return internal::angle(p, q, r, v, K()); } +template < class K > +inline +typename K::FT +approximate_angle(const Vector_3 &u, + const Vector_3 &v) +{ + return internal::approximate_angle(u, v, K()); +} + template < class K > inline typename K::FT 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 7cce51f08d4..d243e8b1974 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h @@ -83,6 +83,15 @@ angle(const typename K::Point_3 &p, return k.angle_3_object()(p, q, r, v); } +template < class K > +inline +typename K::FT +approximate_angle(const typename K::Vector_3 &u, + const typename K::Vector_3 &v , const K& k) +{ + return k.compute_approximate_angle_3_object()(u, v); +} + template < class K > inline typename K::FT diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_angle.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_angle.h index d12e122334c..4a4166ad8c5 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_angle.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_angle.h @@ -77,6 +77,7 @@ _test_angle(const R&) assert( CGAL::angle( org3, sx, sy, vcoplanar) == CGAL::RIGHT ); assert( CGAL::angle( org3, sx, sy, vmz) == CGAL::OBTUSE ); assert( CGAL::approximate_angle( sx, org3, sy ) > RT(89.9) ); + assert( CGAL::approximate_angle( sx-org3, sy-org3 ) > RT(89.9) ); assert( CGAL::approximate_angle( sx, org3, sy ) < RT(90.1) ); assert( CGAL::approximate_angle( sx, org3, sx ) == RT(0) ); assert( CGAL::approximate_angle( sx, org3, msx ) > RT(179.9) );