diff --git a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h index f4ec5137e55..ae5ba565f61 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h @@ -40,13 +40,28 @@ namespace CartesianKernelFunctors { template class Angle_2 { - typedef typename K::Point_2 Point_2; + typedef typename K::Point_2 Point_2; + typedef typename K::Vector_2 Vector_2; public: typedef typename K::Angle result_type; + result_type + operator()(const Vector_2& u, const Vector_2& v) const + { return angleC2(u.x(), u.y(), v.x(), v.y()); } + result_type operator()(const Point_2& p, const Point_2& q, const Point_2& r) const { return angleC2(p.x(), p.y(), q.x(), q.y(), r.x(), r.y()); } + + result_type + operator()(const Point_2& p, const Point_2& q, + const Point_2& r, const Point_2& s) const + { + return angleC2(p.x(), p.y(), + q.x(), q.y(), + r.x(), r.y(), + s.x(), s.y()); + } }; template diff --git a/Cartesian_kernel/include/CGAL/predicates/kernel_ftC2.h b/Cartesian_kernel/include/CGAL/predicates/kernel_ftC2.h index b818a745c92..67ef5102bdd 100644 --- a/Cartesian_kernel/include/CGAL/predicates/kernel_ftC2.h +++ b/Cartesian_kernel/include/CGAL/predicates/kernel_ftC2.h @@ -420,6 +420,15 @@ orientationC2(const FT &ux, const FT &uy, const FT &vx, const FT &vy) return sign_of_determinant(ux, uy, vx, vy); } +template < class FT > +inline +typename Same_uncertainty_nt::type +angleC2(const FT &ux, const FT &uy, + const FT &vx, const FT &vy) +{ + return enum_cast(CGAL_NTS sign(ux*vx + uy*vy)); +} + template < class FT > inline typename Same_uncertainty_nt::type @@ -430,6 +439,17 @@ angleC2(const FT &px, const FT &py, return enum_cast(CGAL_NTS sign((px-qx)*(rx-qx)+(py-qy)*(ry-qy))); } +template < class FT > +inline +typename Same_uncertainty_nt::type +angleC2(const FT &px, const FT &py, + const FT &qx, const FT &qy, + const FT &rx, const FT &ry, + const FT &sx, const FT &sy) +{ + return enum_cast(CGAL_NTS sign((px-qx)*(rx-sx)+(py-qy)*(ry-sy))); +} + template < class FT > CGAL_KERNEL_MEDIUM_INLINE typename Equal_to::result_type diff --git a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h index 89ccb4a9931..8eb1217af51 100644 --- a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h +++ b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h @@ -56,6 +56,7 @@ namespace HomogeneousKernelFunctors { class Angle_2 { typedef typename K::Point_2 Point_2; + typedef typename K::Vector_2 Vector_2; typedef typename K::Construct_vector_2 Construct_vector_2; Construct_vector_2 c; public: @@ -66,7 +67,17 @@ namespace HomogeneousKernelFunctors { result_type operator()(const Point_2& p, const Point_2& q, const Point_2& r) const - { return enum_cast(CGAL_NTS sign(c(q,p) * c(q,r))); } + { return operator()(c(q,p), c(q,r)); } + + result_type + operator()(const Point_2& p, const Point_2& q, + const Point_2& r, const Point_2& s) const + { return operator()(c(q,p), c(s,r)); } + + result_type + operator()(const Vector_2& u, const Vector_2& v) const + { return enum_cast(CGAL_NTS sign(u * v)); } + // FIXME: scalar product }; diff --git a/Kernel_23/doc_tex/Kernel_23_ref/Kernel_Angle_2.tex b/Kernel_23/doc_tex/Kernel_23_ref/Kernel_Angle_2.tex index 5fcf48603fa..98c7186c446 100644 --- a/Kernel_23/doc_tex/Kernel_23_ref/Kernel_Angle_2.tex +++ b/Kernel_23/doc_tex/Kernel_23_ref/Kernel_Angle_2.tex @@ -5,15 +5,25 @@ A model for this must provide: \ccCreationVariable{fo} +\ccMemberFunction{Angle operator()(const Kernel::Vector_2&u, + const Kernel::Vector_2&v);} +{returns \ccStyle{OBTUSE}, \ccStyle{RIGHT} or \ccStyle{ACUTE} depending +on the angle formed by the two vectors $u$ and $v$.} + \ccMemberFunction{Angle operator()(const Kernel::Point_2&p, const Kernel::Point_2&q, const Kernel::Point_2&r);} {returns \ccStyle{OBTUSE}, \ccStyle{RIGHT} or \ccStyle{ACUTE} depending on the angle formed by the three points $p$, $q$, $r$ ($q$ being the vertex of -the angle).} +the angle). The returned value is the same as \ccc{operator()(p - q, r - q)}.} -\ccRefines -\ccc{AdaptableFunctor} (with three arguments) +\ccMemberFunction{Angle operator()(const Kernel::Point_2&p, + const Kernel::Point_2&q, + const Kernel::Point_2&r, + const Kernel::Point_2&s);} +{returns \ccStyle{OBTUSE}, \ccStyle{RIGHT} or \ccStyle{ACUTE} depending +on the angle formed by the two vectors $pq$, $rs$. The returned value is +the same as \ccc{operator()(q - p, s - r)}.} \ccSeeAlso \ccRefIdfierPage{CGAL::angle} \\ diff --git a/Kernel_23/doc_tex/Kernel_23_ref/angle.tex b/Kernel_23/doc_tex/Kernel_23_ref/angle.tex index 6ce1538344a..dbc6dd75016 100644 --- a/Kernel_23/doc_tex/Kernel_23_ref/angle.tex +++ b/Kernel_23/doc_tex/Kernel_23_ref/angle.tex @@ -1,13 +1,28 @@ %\ccHtmlNoRefLinks \begin{ccRefFunction}{angle} +\ccHtmlNoLinks +\ccFunction{Angle angle(const Vector_2&u, + const Vector_2&v);} +{returns \ccStyle{OBTUSE}, \ccStyle{RIGHT} or \ccStyle{ACUTE} depending +on the angle formed by the two vectors $u$ and $v$.} + \ccHtmlNoLinks \ccFunction{Angle angle(const Point_2& p, const Point_2& q, const Point_2& r);} {returns \ccStyle{OBTUSE}, \ccStyle{RIGHT} or \ccStyle{ACUTE} depending on the angle formed by the three points $p$, $q$, $r$ ($q$ being the vertex of -the angle).} +the angle). The returned value is the same as \ccc{angle(p - q, r - q)}.} + +\ccHtmlNoLinks +\ccFunction{Angle angle(const Point_2& p, + const Point_2& q, + const Point_2& r, + const Point_2& s);} +{returns \ccStyle{OBTUSE}, \ccStyle{RIGHT} or \ccStyle{ACUTE} depending +on the angle formed by the two vectors $pq$, $rs$. The returned value is +the same as \ccc{angle(q - p, s - r)}.} \ccHtmlNoLinks \ccFunction{Angle angle(const Point_3& p, diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_2.h b/Kernel_23/include/CGAL/Kernel/global_functions_2.h index c26beb4f5fc..b96a25e3010 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_2.h @@ -49,6 +49,15 @@ operator!=(const Point_2 &p, const Origin& o) return p != Point_2(o); } +template < class K > +inline +Angle +angle(const Vector_2 &u, + const Vector_2 &v) +{ + return internal::angle(u, v, K()); +} + template < class K > inline Angle @@ -59,6 +68,17 @@ angle(const Point_2 &p, return internal::angle(p, q, r, K()); } +template < class K > +inline +Angle +angle(const Point_2 &p, + const Point_2 &q, + const Point_2 &r, + const Point_2 &s) +{ + return internal::angle(p, q, r, s, K()); +} + template < class K > inline typename K::Boolean 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 53eefb23e45..913abd1b4eb 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h @@ -40,6 +40,15 @@ namespace CGAL { namespace internal { +template < class K > +inline +typename K::Angle +angle(const typename K::Vector_2 &u, + const typename K::Vector_2 &v, const K& k) +{ + return k.angle_2_object()(u, v); +} + template < class K > inline typename K::Angle @@ -50,6 +59,17 @@ angle(const typename K::Point_2 &p, return k.angle_2_object()(p, q, r); } +template < class K > +inline +typename K::Angle +angle(const typename K::Point_2 &p, + const typename K::Point_2 &q, + const typename K::Point_2 &r, + const typename K::Point_2 &s, const K& k) +{ + return k.angle_2_object()(p, q, r, s); +} + template < class K > inline typename K::Boolean 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 2d78befcddb..cbe53f8f78a 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_angle.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_angle.h @@ -32,12 +32,23 @@ _test_angle(const R&) typedef CGAL::Point_2 Point_2; typedef CGAL::Point_3 Point_3; + typedef CGAL::Vector_2 Vector_2; + typedef CGAL::Vector_3 Vector_3; + Point_2 p(RT(2),RT(1)); Point_2 q(RT(5),RT(4)); Point_2 r(RT(5),RT(10)); + Point_2 s(RT0, RT0); + + Vector_2 qp = p - q; + Vector_2 qr = r - q; assert( CGAL::angle( p, q, r ) == CGAL::OBTUSE ); + assert( CGAL::angle( qp , qr ) == CGAL::OBTUSE ); + assert( CGAL::angle( q, p, q, r ) == CGAL::OBTUSE ); assert( CGAL::angle( r, p, q ) == CGAL::ACUTE ); + assert( CGAL::angle( p, s, q , r) == CGAL::OBTUSE ); + assert( CGAL::angle( p, r, s , q) == CGAL::ACUTE ); Point_2 e0( RT1, RT0); Point_2 e1( RT0, RT1); 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 a189ef0d0e4..6110c53e416 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 @@ -611,6 +611,8 @@ test_new_2(const R& rep) typename R::Angle_2 angle = rep.angle_2_object(); Angle tmp58 = angle(p2,p3,p4); + tmp58 = angle(p1, p2, p3, p4); + tmp58 = angle(v2, v3); use(v1); use(v4); use(r1); use(d4); use(d5);