diff --git a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h index c1d1e7ae132..629ee3bd422 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h @@ -409,6 +409,13 @@ namespace CartesianKernelFunctors { { return cmp_dist_to_pointC2(p.x(), p.y(), q.x(), q.y(), r.x(), r.y()); } + + template + result_type + operator()(const T1& p, const T2& q, const T3& r, const T4& s) const + { + return CGAL_NTS compare(squared_distance(p, q), squared_distance(r, s)); + } }; template @@ -425,6 +432,13 @@ namespace CartesianKernelFunctors { q.x(), q.y(), q.z(), r.x(), r.y(), r.z()); } + + template + result_type + operator()(const T1& p, const T2& q, const T3& r, const T4& s) const + { + return CGAL_NTS compare(squared_distance(p, q), squared_distance(r, s)); + } }; template diff --git a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h index 18ee40dfbc0..954a8c9062e 100644 --- a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h +++ b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h @@ -647,6 +647,13 @@ namespace HomogeneousKernelFunctors { return CGAL_NTS sign(dosd); } + + template + result_type + operator()(const T1& p, const T2& q, const T3& r, const T4& s) const + { + return CGAL_NTS compare(squared_distance(p, q), squared_distance(r, s)); + } }; template @@ -685,6 +692,13 @@ namespace HomogeneousKernelFunctors { return CGAL_NTS sign(dosd); } + + template + result_type + operator()(const T1& p, const T2& q, const T3& r, const T4& s) const + { + return CGAL_NTS compare(squared_distance(p, q), squared_distance(r, s)); + } }; template diff --git a/Kernel_23/doc_tex/Kernel_23_ref/Kernel_CompareDistance_2.tex b/Kernel_23/doc_tex/Kernel_23_ref/Kernel_CompareDistance_2.tex index c2888f49d6a..db5bcfbeba6 100644 --- a/Kernel_23/doc_tex/Kernel_23_ref/Kernel_CompareDistance_2.tex +++ b/Kernel_23/doc_tex/Kernel_23_ref/Kernel_CompareDistance_2.tex @@ -8,6 +8,22 @@ A model for this must provide: const Kernel::Point_2&r);} {compares the distances of points \ccc{q} and \ccc{r} to point \ccc{p}} +\ccMemberFunction{Comparison_result operator()(const Type1& obj1, + const Type2& obj2, + const Type3& obj3, + const Type4& obj4);} + {compares the squared distance between \ccc{obj1} and \ccc{obj2} to + the squared distance between \ccc{obj3} and \ccc{obj4}} +for all tuples of types \ccStyle{Type1}, \ccStyle{Type2}, \ccStyle{Type3} +and \ccStyle{Type4} in the following set of types: +\begin{itemize}\ccTexHtml{\itemsep0pt\topsep0pt\partopsep0pt\parskip0pt\parsep0pt}{} +\item \ccStyle{Kernel::Point_2} +\item \ccStyle{Kernel::Line_2} +\item \ccStyle{Kernel::Ray_2} +\item \ccStyle{Kernel::Segment_2} +\item \ccStyle{Kernel::Triangle_2} +\end{itemize} + \ccRefines \ccc{AdaptableFunctor} (with three arguments) diff --git a/Kernel_23/doc_tex/Kernel_23_ref/Kernel_CompareDistance_3.tex b/Kernel_23/doc_tex/Kernel_23_ref/Kernel_CompareDistance_3.tex index 3e143b1f871..a8eed468f91 100644 --- a/Kernel_23/doc_tex/Kernel_23_ref/Kernel_CompareDistance_3.tex +++ b/Kernel_23/doc_tex/Kernel_23_ref/Kernel_CompareDistance_3.tex @@ -8,6 +8,22 @@ A model for this must provide: const Kernel::Point_3&r);} {compares the distances of points \ccc{q} and \ccc{r} to point \ccc{p}} +\ccMemberFunction{Comparison_result operator()(const Type1& obj1, + const Type2& obj2, + const Type3& obj3, + const Type4& obj4);} + {compares the squared distance between \ccc{obj1} and \ccc{obj2} to + the squared distance between \ccc{obj3} and \ccc{obj4}} +for all tuples of types \ccStyle{Type1}, \ccStyle{Type2}, \ccStyle{Type3} +and \ccStyle{Type4} in the following set of types: +\begin{itemize}\ccTexHtml{\itemsep0pt\topsep0pt\partopsep0pt\parskip0pt\parsep0pt}{} +\item \ccStyle{Kernel::Point_3} +\item \ccStyle{Kernel::Line_3} +\item \ccStyle{Kernel::Ray_3} +\item \ccStyle{Kernel::Segment_3} +\item \ccStyle{Kernel::Plane_3} +\end{itemize} + \ccRefines \ccc{AdaptableFunctor} (with three arguments) diff --git a/Kernel_23/doc_tex/Kernel_23_ref/Kernel_CompareSquaredDistance_2.tex b/Kernel_23/doc_tex/Kernel_23_ref/Kernel_CompareSquaredDistance_2.tex index 5714714d314..4a962317060 100644 --- a/Kernel_23/doc_tex/Kernel_23_ref/Kernel_CompareSquaredDistance_2.tex +++ b/Kernel_23/doc_tex/Kernel_23_ref/Kernel_CompareSquaredDistance_2.tex @@ -19,21 +19,22 @@ following: \item \ccStyle{Kernel::Triangle_2} \end{itemize} -\ccMemberFunction{Comparison_result operator()(const Type1& obj1, - const Type2& obj2, - const Type3& obj3, - const Type4& obj4);} - {compares the squared distance between \ccc{obj1} and \ccc{obj2} to - the squared distance between \ccc{obj3} and \ccc{obj4}} -for all tuples of types \ccStyle{Type1}, \ccStyle{Type2}, \ccStyle{Type3} -and \ccStyle{Type4} in the following set of types: -\begin{itemize}\ccTexHtml{\itemsep0pt\topsep0pt\partopsep0pt\parskip0pt\parsep0pt}{} -\item \ccStyle{Kernel::Point_2} -\item \ccStyle{Kernel::Line_2} -\item \ccStyle{Kernel::Ray_2} -\item \ccStyle{Kernel::Segment_2} -\item \ccStyle{Kernel::Triangle_2} -\end{itemize} +% Deprecated: use Kernel::CompareDistance_2 instead +% \ccMemberFunction{Comparison_result operator()(const Type1& obj1, +% const Type2& obj2, +% const Type3& obj3, +% const Type4& obj4);} +% {compares the squared distance between \ccc{obj1} and \ccc{obj2} to +% the squared distance between \ccc{obj3} and \ccc{obj4}} +% for all tuples of types \ccStyle{Type1}, \ccStyle{Type2}, \ccStyle{Type3} +% and \ccStyle{Type4} in the following set of types: +% \begin{itemize}\ccTexHtml{\itemsep0pt\topsep0pt\partopsep0pt\parskip0pt\parsep0pt}{} +% \item \ccStyle{Kernel::Point_2} +% \item \ccStyle{Kernel::Line_2} +% \item \ccStyle{Kernel::Ray_2} +% \item \ccStyle{Kernel::Segment_2} +% \item \ccStyle{Kernel::Triangle_2} +% \end{itemize} \ccRefines \ccc{AdaptableFunctor} (with three arguments) diff --git a/Kernel_23/doc_tex/Kernel_23_ref/Kernel_CompareSquaredDistance_3.tex b/Kernel_23/doc_tex/Kernel_23_ref/Kernel_CompareSquaredDistance_3.tex index 3c3a96c51a5..6785977f962 100644 --- a/Kernel_23/doc_tex/Kernel_23_ref/Kernel_CompareSquaredDistance_3.tex +++ b/Kernel_23/doc_tex/Kernel_23_ref/Kernel_CompareSquaredDistance_3.tex @@ -19,21 +19,22 @@ following: \item \ccStyle{Kernel::Plane_3} \end{itemize} -\ccMemberFunction{Comparison_result operator()(const Type1& obj1, - const Type2& obj2, - const Type3& obj3, - const Type4& obj4);} - {compares the squared distance between \ccc{obj1} and \ccc{obj2} to - the squared distance between \ccc{obj3} and \ccc{obj4}} -for all tuples of types \ccStyle{Type1}, \ccStyle{Type2}, \ccStyle{Type3} -and \ccStyle{Type4} in the following set of types: -\begin{itemize}\ccTexHtml{\itemsep0pt\topsep0pt\partopsep0pt\parskip0pt\parsep0pt}{} -\item \ccStyle{Kernel::Point_3} -\item \ccStyle{Kernel::Line_3} -\item \ccStyle{Kernel::Ray_3} -\item \ccStyle{Kernel::Segment_3} -\item \ccStyle{Kernel::Plane_3} -\end{itemize} +% Deprecated: use Kernel::CompareDistance_3 instead +% \ccMemberFunction{Comparison_result operator()(const Type1& obj1, +% const Type2& obj2, +% const Type3& obj3, +% const Type4& obj4);} +% {compares the squared distance between \ccc{obj1} and \ccc{obj2} to +% the squared distance between \ccc{obj3} and \ccc{obj4}} +% for all tuples of types \ccStyle{Type1}, \ccStyle{Type2}, \ccStyle{Type3} +% and \ccStyle{Type4} in the following set of types: +% \begin{itemize}\ccTexHtml{\itemsep0pt\topsep0pt\partopsep0pt\parskip0pt\parsep0pt}{} +% \item \ccStyle{Kernel::Point_3} +% \item \ccStyle{Kernel::Line_3} +% \item \ccStyle{Kernel::Ray_3} +% \item \ccStyle{Kernel::Segment_3} +% \item \ccStyle{Kernel::Plane_3} +% \end{itemize} \ccRefines \ccc{AdaptableFunctor} (with three arguments) diff --git a/Kernel_23/doc_tex/Kernel_23_ref/Kernel_ComputeSquaredDistance_2.tex b/Kernel_23/doc_tex/Kernel_23_ref/Kernel_ComputeSquaredDistance_2.tex index ed2a73b3a75..092e6fed5d7 100644 --- a/Kernel_23/doc_tex/Kernel_23_ref/Kernel_ComputeSquaredDistance_2.tex +++ b/Kernel_23/doc_tex/Kernel_23_ref/Kernel_ComputeSquaredDistance_2.tex @@ -16,7 +16,8 @@ following: \item \ccStyle{Kernel::Ray_2} \item \ccStyle{Kernel::Segment_2} \item \ccStyle{Kernel::Triangle_2} -% If this list is changed, please change also in Kernel_CompareSquaredDistance_2.tex +% If this list is changed, please change also in +% Kernel_CompareDistance_2.tex and compare_distance.tex \end{itemize} \ccRefines diff --git a/Kernel_23/doc_tex/Kernel_23_ref/Kernel_ComputeSquaredDistance_3.tex b/Kernel_23/doc_tex/Kernel_23_ref/Kernel_ComputeSquaredDistance_3.tex index 3ef0f11d00f..fda19ad8ac3 100644 --- a/Kernel_23/doc_tex/Kernel_23_ref/Kernel_ComputeSquaredDistance_3.tex +++ b/Kernel_23/doc_tex/Kernel_23_ref/Kernel_ComputeSquaredDistance_3.tex @@ -17,7 +17,7 @@ following: \item \ccStyle{Kernel::Segment_3} \item \ccStyle{Kernel::Plane_3} % If this list is changed, please change also in -% Kernel_CompareSquaredDistance_3.tex +% Kernel_CompareDistance_3.tex and compare_distance.tex \end{itemize} \ccRefines diff --git a/Kernel_23/doc_tex/Kernel_23_ref/compare_distance.tex b/Kernel_23/doc_tex/Kernel_23_ref/compare_distance.tex new file mode 100644 index 00000000000..d0c9fb4c841 --- /dev/null +++ b/Kernel_23/doc_tex/Kernel_23_ref/compare_distance.tex @@ -0,0 +1,39 @@ +\begin{ccRefFunction}{compare_distance} + +\ccFunction{Comparison_result +compare_distance(const Type1& obj1, const Type2& obj2, + const Type3& obj3, const Type4& obj4);} + {compares the distance between \ccc{obj1} and \ccc{obj2} to + the distance between \ccc{obj3} and \ccc{obj4}} +for all tuples of types \ccStyle{Type1}, \ccStyle{Type2}, \ccStyle{Type3} +and \ccStyle{Type4} in the following set of 2D types: +\begin{itemize}\ccTexHtml{\itemsep0pt\topsep0pt\partopsep0pt\parskip0pt\parsep0pt}{} +\item \ccStyle{Kernel::Point_2} +\item \ccStyle{Kernel::Line_2} +\item \ccStyle{Kernel::Ray_2} +\item \ccStyle{Kernel::Segment_2} +\item \ccStyle{Kernel::Triangle_2} +\end{itemize} +or in the following set of 3D types: +\begin{itemize}\ccTexHtml{\itemsep0pt\topsep0pt\partopsep0pt\parskip0pt\parsep0pt}{} +\item \ccStyle{Kernel::Point_3} +\item \ccStyle{Kernel::Line_3} +\item \ccStyle{Kernel::Ray_3} +\item \ccStyle{Kernel::Segment_3} +\item \ccStyle{Kernel::Plane_3} +\end{itemize} + +\ccSeeAlso +\ccRefIdfierPage{CGAL::compare_squared_distance} \\ +\ccRefIdfierPage{CGAL::compare_distance_to_point}\\ +\ccRefIdfierPage{CGAL::compare_signed_distance_to_line} \\ +\ccRefIdfierPage{CGAL::compare_signed_distance_to_plane} \\ +\ccRefIdfierPage{CGAL::has_larger_distance_to_point} \\ +\ccRefIdfierPage{CGAL::has_larger_signed_distance_to_line} \\ +\ccRefIdfierPage{CGAL::has_larger_signed_distance_to_plane} \\ +\ccRefIdfierPage{CGAL::has_smaller_distance_to_point} \\ +\ccRefIdfierPage{CGAL::has_smaller_signed_distance_to_line} \\ +\ccRefIdfierPage{CGAL::has_smaller_signed_distance_to_plane} \\ + +\end{ccRefFunction} + diff --git a/Kernel_23/doc_tex/Kernel_23_ref/compare_squared_distance.tex b/Kernel_23/doc_tex/Kernel_23_ref/compare_squared_distance.tex index 3d6a4f3fcd9..67268d3226e 100644 --- a/Kernel_23/doc_tex/Kernel_23_ref/compare_squared_distance.tex +++ b/Kernel_23/doc_tex/Kernel_23_ref/compare_squared_distance.tex @@ -14,14 +14,15 @@ compare_squared_distance(const Point_3& p, {compares the squared distance of points \ccStyle{p} and \ccStyle{q} to \ccStyle{d2}.} -\ccFunction{Comparison_result -compare_squared_distance(const Point_3& p, - const Point_3& q, - const Point_3& r, - const Point_3& s);} - {compares the squared distance of points \ccStyle{p} and - \ccStyle{q} to the squared distance of points \ccStyle{r} and - \ccStyle{s}.} +% Deprecated: use compare_distance(..) instead +% \ccFunction{Comparison_result +% compare_squared_distance(const Point_3& p, +% const Point_3& q, +% const Point_3& r, +% const Point_3& s);} +% {compares the squared distance of points \ccStyle{p} and +% \ccStyle{q} to the squared distance of points \ccStyle{r} and +% \ccStyle{s}.} \ccSeeAlso \ccRefIdfierPage{CGAL::compare_distance_to_point} \\ diff --git a/Kernel_23/include/CGAL/Kernel/global_functions.h b/Kernel_23/include/CGAL/Kernel/global_functions.h index b81ab8d5c1e..e5a1f66e585 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions.h @@ -32,6 +32,18 @@ namespace CGAL { +template +inline +Comparison_result +compare_distance(const T1 &o1, + const T2 &o2, + const T3 &o3, + const T4 &o4) +{ + typedef typename Kernel_traits::Kernel K; + return internal::compare_distance(o1, o2, o3, o4, K()); +} + template inline bool 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 95367065db6..9843eebec89 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h @@ -3,6 +3,7 @@ // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria), // and Tel-Aviv University (Israel). All rights reserved. +// Copyright (c) 2010 GeometryFactory Sarl (France) // // This file is part of CGAL (www.cgal.org); you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public License as @@ -30,6 +31,10 @@ // These functions are not documented for now, but could be as some point. #include +#include +#include "boost/mpl/equal_to.hpp" +#include +#include namespace CGAL { @@ -253,6 +258,22 @@ compare_angle_with_x_axis(const typename K::Direction_2& d1, return k.compare_angle_with_x_axis_2_object()(d1, d2); } +template +inline +typename boost::enable_if< + boost::mpl::equal_to::type::value>, + boost::mpl::integral_c >, + typename K::Comparison_result> +::type +compare_distance(const T1 &o1, + const T2 &o2, + const T3 &o3, + const T4 &o4, const K& k) +{ + return k.compare_distance_2_object()(o1, o2, o3, o4); +} + template inline typename K::Comparison_result 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 7842408a309..6ebfb970c28 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h @@ -3,6 +3,7 @@ // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria), // and Tel-Aviv University (Israel). All rights reserved. +// Copyright (c) 2010 GeometryFactory Sarl (France) // // This file is part of CGAL (www.cgal.org); you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public License as @@ -27,6 +28,11 @@ // Generic functions calling the kernel functor. // See comments in CGAL/Kernel/global_functions_internal_3.h. +#include +#include +#include "boost/mpl/equal_to.hpp" +#include + namespace CGAL { namespace internal { @@ -314,6 +320,25 @@ compare_dihedral_angle(const typename K::Vector_3& ab1, return k.compare_dihedral_angle_3_object()(ab1, ac1, ad1, cosine); } +template +inline +typename boost::enable_if< + boost::mpl::equal_to::type::value>, + boost::mpl::integral_c >, + typename K::Comparison_result> +::type + // boost::mpl::equal_to::type, + // boost::mpl::int_<3> >, + // typename K::Comparison_result>::type +compare_distance(const T1 &o1, + const T2 &o2, + const T3 &o3, + const T4 &o4, const K& k) +{ + return k.compare_distance_3_object()(o1, o2, o3, o4); +} + 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 8d0bd22be3e..0755f45ec44 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 @@ -456,15 +456,17 @@ test_new_2(const R& rep) typename R::Compare_squared_distance_2 compare_sq_dist = rep.compare_squared_distance_2_object(); - tmp34ab = compare_sq_dist(p1,p2,FT(1)); - tmp34ab = compare_sq_dist(p1, l2, FT(1)); - tmp34ab = compare_sq_dist(p2, p1, FT(1)); - tmp34ab = compare_sq_dist(l1, l2, FT(1)); - tmp34ab = compare_sq_dist(p1, s1, FT(1)); - tmp34ab = compare_sq_dist(p1, t2, FT(1)); - tmp34ab = compare_sq_dist(t2, s1, FT(1)); - tmp34ab = compare_sq_dist(t2, l1, FT(1)); - tmp34ab = compare_sq_dist(t2, l1, s1, p1); + tmp34ab = compare_sq_dist(p1,p2,FT(1)); + tmp34ab = compare_sq_dist(p1, l2, FT(1)); + tmp34ab = compare_sq_dist(p2, p1, FT(1)); + tmp34ab = compare_sq_dist(l1, l2, FT(1)); + tmp34ab = compare_sq_dist(p1, s1, FT(1)); + tmp34ab = compare_sq_dist(p1, t2, FT(1)); + tmp34ab = compare_sq_dist(t2, s1, FT(1)); + tmp34ab = compare_sq_dist(t2, l1, FT(1)); + + tmp34ab = CGAL::compare_distance(t2, l1, s1, p1); + tmp34ab = CGAL::compare_distance(t2, l1, s1, p1); typename R::Compare_angle_with_x_axis_2 compare_angle = rep.compare_angle_with_x_axis_2_object(); diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_new_3.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_new_3.h index 172151cf5c3..48a571ea1b9 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_new_3.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_new_3.h @@ -572,13 +572,16 @@ test_new_3(const R& rep) typename R::Compare_squared_distance_3 compare_sq_dist = rep.compare_squared_distance_3_object(); - tmp34ab = compare_sq_dist(p2,p3,FT(1)); - tmp34ab = compare_sq_dist(p2,p3,p2,p3); - tmp34ab = compare_sq_dist(p1, l2, FT(1)); - tmp34ab = compare_sq_dist(p2, p1, FT(1)); - tmp34ab = compare_sq_dist(l2, l3, FT(1)); - tmp34ab = compare_sq_dist(p1, s2, FT(1)); - tmp34ab = compare_sq_dist(p1, p2, p3, p4); + tmp34ab = compare_sq_dist(p2,p3,FT(1)); + tmp34ab = compare_sq_dist(p2,p3,p2,p3); + tmp34ab = compare_sq_dist(p1, l2, FT(1)); + tmp34ab = compare_sq_dist(p2, p1, FT(1)); + tmp34ab = compare_sq_dist(l2, l3, FT(1)); + tmp34ab = compare_sq_dist(p1, s2, FT(1)); + tmp34ab = compare_sq_dist(p1, p2, p3, p4); + + tmp34ab = CGAL::compare_distance(p2,p3,p2,p3); + tmp34ab = CGAL::compare_distance(p1, p2, p3, p4); typename R::Compare_squared_radius_3 compare_sq_radius = rep.compare_squared_radius_3_object();