From 9b54173f8b2f72c6bd5ada425f195e837b4047fb Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Wed, 9 Nov 2011 12:07:58 +0000 Subject: [PATCH] Orientation taking points directly instead of iterators --- .../include/CGAL/Kernel_d/Cartesian_small.h | 51 +++++++++++++ .../Kernel_d/function_objects_cartesian.h | 71 +++++++++++++++++-- 2 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 NewKernel_d/include/CGAL/Kernel_d/Cartesian_small.h diff --git a/NewKernel_d/include/CGAL/Kernel_d/Cartesian_small.h b/NewKernel_d/include/CGAL/Kernel_d/Cartesian_small.h new file mode 100644 index 00000000000..4bd466f95ec --- /dev/null +++ b/NewKernel_d/include/CGAL/Kernel_d/Cartesian_small.h @@ -0,0 +1,51 @@ +#ifndef CGAL_KD_CARTESIAN_SMALL_H +#define CGAL_KD_CARTESIAN_SMALL_H +#include +#include + +// WARNING: not written yet, I just wanted to stick the BOOST stuff somewhere not to lose it. + +namespace CGAL { +namespace CartesianDKernelFunctors { +template +struct Orientation_of_points_small : private Store_kernel { + CGAL_FUNCTOR_INIT_STORE(Orientation_of_points_small); + typedef typename R_::template Type::type Point; + typedef typename R_::Orientation result_type; + typedef typename R_::FT FT; +#if 0 + template + result_type operator()(Iter f, Iter e)const{ + typename R_::template Functor::type c(this->kernel()); + Point const&A=*f; + FT const& ax=c(A,0); + FT const& ay=c(A,1); + Point const&B=*++f; + Point const&C=*++f; + CGAL_assertion(++f==e); + return sign_of_determinant(c(B,0)-ax,c(B,1)-ay,c(C,0)-ax,c(C,1)-ay); + } +#endif + +// TODO: iterate outside the class to have a single declaration of the right dimension. +#define VAR(Z,J,I) m(I,J)=c(p##I,J)-c(x,J); +#define VAR2(Z,I,N) BOOST_PP_ENUM(N,VAR,I) +#define CODE(Z,N,_) \ + result_type operator()(Point const&x, BOOST_PP_ENUM_PARAMS(N,Point const&p)) const { \ + typename R::template Functor::type c(this->kernel()); \ + Matrix m(N,N); \ + BOOST_PP_REPEAT(N,VAR2,N) \ + return sign_of_determinant(BOOST_PP_ENUM(N,VAR2,N)); \ + } + +BOOST_PP_REPEAT_FROM_TO(2, 10, CODE, _ ) +#undef CODE +#undef VAR2 +#undef VAR +#endif + +}; +} +} + +#endif diff --git a/NewKernel_d/include/CGAL/Kernel_d/function_objects_cartesian.h b/NewKernel_d/include/CGAL/Kernel_d/function_objects_cartesian.h index bbff4d354be..6f1c3debe77 100644 --- a/NewKernel_d/include/CGAL/Kernel_d/function_objects_cartesian.h +++ b/NewKernel_d/include/CGAL/Kernel_d/function_objects_cartesian.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace CGAL { namespace CartesianDKernelFunctors { @@ -35,11 +36,42 @@ template struct Orientation_of_points : private Store_kernel { Point const& p=*f; for(int j=0;j,typename R::Default_ambient_dimension>::value>::type> + template =3)>::type> + result_type operator()(U&&...u) const { + return operator()({std::forward(u)...}); + } + + template + result_type operator()(std::initializer_list

l) const { + return operator()(l.begin(),l.end()); + } +#else + //should we make it template to avoid instantiation for wrong dim? + //or iterate outside the class? +#define VAR(Z,J,I) m(I,J)=c(p##I,J)-c(x,J); +#define VAR2(Z,I,N) BOOST_PP_REPEAT(N,VAR,I) +#define CODE(Z,N,_) \ + result_type operator()(Point const&x, BOOST_PP_ENUM_PARAMS(N,Point const&p)) const { \ + typename R::template Functor::type c(this->kernel()); \ + Matrix m(N,N); \ + BOOST_PP_REPEAT(N,VAR2,N) \ + return R::LA::sign_of_determinant(CGAL_MOVE(m)); \ + } + +BOOST_PP_REPEAT_FROM_TO(2, 10, CODE, _ ) +#undef CODE +#undef VAR2 +#undef VAR +#endif }; template struct Orientation_of_vectors : private Store_kernel { @@ -68,7 +100,20 @@ template struct Orientation_of_vectors : private Store_kernel { } return R::LA::sign_of_determinant(CGAL_MOVE(m)); } - //TODO: version that takes objects directly instead of iterators + +#ifdef CGAL_CXX0X + template =3)>::type> + result_type operator()(U&&...u) const { + return operator()({std::forward(u)...}); + } + + template + result_type operator()(std::initializer_list l) const { + return operator()(l.begin(),l.end()); + } +#else + //TODO +#endif }; #if 0 @@ -157,7 +202,20 @@ template struct Side_of_oriented_sphere : private Store_kernel { } return R::LA::sign_of_determinant(CGAL_MOVE(m)); } - //TODO: version that takes objects directly instead of iterators + +#ifdef CGAL_CXX0X + template =4)>::type> + result_type operator()(U&&...u) const { + return operator()({std::forward(u)...}); + } + + template + result_type operator()(std::initializer_list

l) const { + return operator()(l.begin(),l.end()); + } +#else + //TODO +#endif }; template struct Construct_opposite_vector : private Store_kernel { @@ -344,10 +402,11 @@ template struct Compare_lexicographically : private Store_kernel { a_begin=c(a,Begin_tag()), b_begin=c(b,Begin_tag()), a_end=c(a,End_tag()); - result_type res=CGAL_NTS compare(*a_begin++,*b_begin++); + result_type res; // can't we do slightly better for Uncertain<*> ? - while(a_begin!=a_end && res==EQUAL) - res=CGAL_NTS compare(*a_begin++,*b_begin++); + // after res=...; if(is_uncertain(res))return indeterminate(); + do res=CGAL_NTS compare(*a_begin++,*b_begin++); + while(a_begin!=a_end && res==EQUAL); return res; } };