diff --git a/NewKernel_d/include/CGAL/Kernel_d/Kernel_d_interface.h b/NewKernel_d/include/CGAL/Kernel_d/Kernel_d_interface.h index b63e708cb07..2ba2dcf6732 100644 --- a/NewKernel_d/include/CGAL/Kernel_d/Kernel_d_interface.h +++ b/NewKernel_d/include/CGAL/Kernel_d/Kernel_d_interface.h @@ -117,9 +117,9 @@ template struct Kernel_d_interface : public Base_ { //typedef typename Get_functor::type Oriented_side_d; //typedef typename Get_functor::type Side_of_bounded_sphere_d; - //typedef typename Get_functor::type Center_of_sphere_d; + typedef typename Get_functor::type Center_of_sphere_d; //typedef typename Get_functor::type Value_at_d; - //typedef typename Get_functor::type Point_of_sphere_d; + typedef typename Get_functor::type Point_of_sphere_d; typedef typename Get_functor::type Orthogonal_vector_d; //typedef typename Get_functor::type Linear_base_d; diff --git a/NewKernel_d/include/CGAL/Kernel_d/Types/Sphere.h b/NewKernel_d/include/CGAL/Kernel_d/Types/Sphere.h index cc9c163b58b..dabae71f8cb 100644 --- a/NewKernel_d/include/CGAL/Kernel_d/Types/Sphere.h +++ b/NewKernel_d/include/CGAL/Kernel_d/Types/Sphere.h @@ -1,6 +1,7 @@ #ifndef CGAL_KD_TYPE_SPHERE_H #define CGAL_KD_TYPE_SPHERE_H #include +#include namespace CGAL { template class Sphere { typedef typename Get_type::type FT_; @@ -12,8 +13,8 @@ template class Sphere { Sphere(Point_ const&p, FT_ const&r2): c_(p), r2_(r2) {} // TODO: Add a piecewise constructor? - Point_ center()const{return c_;} - FT_ squared_radius()const{return r2_;} + Point_ const& center()const{return c_;} + FT_ const& squared_radius()const{return r2_;} }; namespace CartesianDKernelFunctors { template struct Construct_sphere : Store_kernel { @@ -33,7 +34,7 @@ template struct Construct_sphere : Store_kernel { template struct Center_of_sphere { CGAL_FUNCTOR_INIT_IGNORE(Center_of_sphere) typedef typename Get_type::type Sphere; - typedef typename Get_type::type result_type; + typedef typename Get_type::type const& result_type; result_type operator()(Sphere const&s)const{ return s.center(); } @@ -41,16 +42,49 @@ template struct Center_of_sphere { template struct Squared_radius { CGAL_FUNCTOR_INIT_IGNORE(Squared_radius) typedef typename Get_type::type Sphere; - typedef typename Get_type::type result_type; + typedef typename Get_type::type const& result_type; // TODO: Is_exact? result_type operator()(Sphere const&s)const{ return s.squared_radius(); } }; +// FIXME: Move it to the generic functors, using the two above and conditional to the existence of sqrt(FT) +template struct Point_of_sphere : private Store_kernel { + CGAL_FUNCTOR_INIT_STORE(Point_of_sphere) + typedef R_ R; + typedef typename Get_type::type FT; + typedef typename Get_type::type RT; + typedef typename Get_type::type Point; + typedef typename Get_type::type Sphere; + typedef typename Get_functor >::type CP; + typedef typename Get_functor >::type CI; + typedef typename Get_functor::type PD; + typedef Point result_type; + typedef Sphere first_argument_type; + typedef int second_argument_type; + struct Trans : std::binary_function { + FT const& r_; int idx; bool sgn; + Trans (int n, FT const& r, bool b) : r_(r), idx(n), sgn(b) {} + FT operator()(FT const&x, int i)const{ + return (i == idx) ? sgn ? x + r_ : x - r_ : x; + } + }; + result_type operator()(Sphere const&s, int i)const{ + CI ci(this->kernel()); + PD pd(this->kernel()); + typedef boost::counting_iterator Count; + Point const&c = s.center(); + int d=pd(c); + bool last = (i == d); + Trans t(last ? 0 : i, sqrt(s.radius()), !last); + return CP(this->kernel())(make_transforming_pair_iterator(ci(c,Begin_tag()),Count(0),t),make_transforming_pair_iterator(ci(c,End_tag()),Count(d+1),t)); + } +}; } CGAL_KD_DEFAULT_TYPE(Sphere_tag,(CGAL::Sphere),(Point_tag),()); CGAL_KD_DEFAULT_FUNCTOR(Construct_ttag,(CartesianDKernelFunctors::Construct_sphere),(Sphere_tag,Point_tag),()); CGAL_KD_DEFAULT_FUNCTOR(Center_of_sphere_tag,(CartesianDKernelFunctors::Center_of_sphere),(Sphere_tag,Point_tag),()); CGAL_KD_DEFAULT_FUNCTOR(Squared_radius_tag,(CartesianDKernelFunctors::Squared_radius),(Sphere_tag),()); +CGAL_KD_DEFAULT_FUNCTOR(Point_of_sphere_tag,(CartesianDKernelFunctors::Point_of_sphere),(Sphere_tag,Point_tag),(Construct_ttag, Construct_ttag)); } // namespace CGAL #endif diff --git a/NewKernel_d/include/CGAL/functor_tags.h b/NewKernel_d/include/CGAL/functor_tags.h index 92ecb43359d..e29397eb4ad 100644 --- a/NewKernel_d/include/CGAL/functor_tags.h +++ b/NewKernel_d/include/CGAL/functor_tags.h @@ -214,11 +214,13 @@ namespace CGAL { // Really? templatestruct Get_functor_category,B,C>{typedef Misc_tag type;}; + #define DECL_CONSTRUCT(X,Y) struct X##_tag {}; \ template<>struct map_result_tag{typedef Y##_tag type;}; \ templatestruct Get_functor_category{typedef Construct_tag type;} DECL_CONSTRUCT(Midpoint,Point); DECL_CONSTRUCT(Center_of_sphere,Point); + DECL_CONSTRUCT(Point_of_sphere,Point); DECL_CONSTRUCT(Segment_extremity,Point); DECL_CONSTRUCT(Sum_of_vectors,Vector); DECL_CONSTRUCT(Difference_of_vectors,Vector);