diff --git a/NewKernel_d/include/CGAL/Dimension.h b/NewKernel_d/include/CGAL/Dimension.h new file mode 100644 index 00000000000..66609cf95c3 --- /dev/null +++ b/NewKernel_d/include/CGAL/Dimension.h @@ -0,0 +1,123 @@ +// Copyright (c) 2008 INRIA Sophia-Antipolis (France). +// Aviv University (Israel). All rights reserved. +// +// 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 +// published by the Free Software Foundation; version 2.1 of the License. +// See the file LICENSE.LGPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Sylvain Pion + +#ifndef CGAL_DIMENSION_H +#define CGAL_DIMENSION_H + +#include +#include +#include +#ifdef CGAL_USE_EIGEN +#include +#endif + +namespace CGAL { + +#ifdef CGAL_USE_EIGEN +const int UNKNOWN_DIMENSION=Eigen::Dynamic; +#else +const int UNKNOWN_DIMENSION=std::numeric_limits::max(); +#endif + +bool check_dimension(int d1, int d2){ + //return (d2==UNKNOWN_DIMENSION)||(d1<=d2); + return d1<=d2; +} + +// These tag classes help dispatching functions based on a geometric dimension. + +template < int dim > +struct Dimension_tag +{ + static const int value = dim; +}; + +struct Dynamic_dimension_tag { + static const int value = UNKNOWN_DIMENSION; +}; + + +namespace internal { + + template < typename D > + struct Dim_value { + static const int value = D::value; + }; + + template <> + struct Dim_value {}; + +} // namespace internal + + +// Ambient_dimension gives access to the dimension of the ambient space of an object. + +template < typename T, typename K = typename Kernel_traits::Kernel > +struct Ambient_dimension + : public internal::Dim_value< typename K::template Ambient_dimension::type > +{ + typedef typename K::template Ambient_dimension::type type; +}; + + +// Feature_dimension gives access to the dimension of an object. + +template < typename T, typename K = typename Kernel_traits::Kernel > +struct Feature_dimension + : public internal::Dim_value< typename K::template Feature_dimension::type > +{ + typedef typename K::template Feature_dimension::type type; +}; + +// Change the dimension +templatestruct Increment_dimension { + typedef Dynamic_dimension_tag type; +}; +templatestruct Increment_dimension,i> { + typedef Dimension_tag type; +}; + +templatestruct Product_dimension { + typedef Dynamic_dimension_tag type; +}; +templatestruct Product_dimension,Dimension_tag > { + typedef Dimension_tag type; +}; + +#ifdef CGAL_USE_EIGEN +// Convert to Eigen's notion of dimension +template struct Eigen_dimension { + enum { value=Eigen::Dynamic }; +}; +template struct Eigen_dimension > { + enum { value=d }; +}; + +// and convert back +template struct Dimension_eigen { + typedef Dimension_tag type; +}; +template <> struct Dimension_eigen { + typedef Dynamic_dimension_tag type; +}; +#endif + +} //namespace CGAL + +#endif // CGAL_DIMENSION_H diff --git a/NewKernel_d/include/CGAL/Kernel_d/Cartesian_LA_base.h b/NewKernel_d/include/CGAL/Kernel_d/Cartesian_LA_base.h new file mode 100644 index 00000000000..518d9957514 --- /dev/null +++ b/NewKernel_d/include/CGAL/Kernel_d/Cartesian_LA_base.h @@ -0,0 +1,112 @@ +#ifndef CGAL_KERNEL_D_CARTESIAN_LA_BASE_H +#define CGAL_KERNEL_D_CARTESIAN_LA_BASE_H + +#include + +#include +#include +#include +#include +#include +#ifdef CGAL_USE_EIGEN +#include +#else +#include +#endif + +namespace CGAL { + +template < typename FT_, typename Dim_> +struct Cartesian_LA_base_d : public Dimension_base +{ + typedef FT_ FT; + typedef Cartesian_LA_base_d Self; + typedef Cartesian_tag Rep_tag; + typedef Cartesian_tag Kernel_tag; + typedef Dim_ Default_ambient_dimension; + typedef Dim_ Max_ambient_dimension; +#ifdef CGAL_USE_EIGEN + typedef CGAL::LA_eigen LA; +#else + typedef CGAL::LA_default LA; +#endif + + typedef typename Same_uncertainty_nt::type + Boolean; + typedef typename Same_uncertainty_nt::type + Sign; + typedef typename Same_uncertainty_nt::type + Comparison_result; + typedef typename Same_uncertainty_nt::type + Orientation; + typedef typename Same_uncertainty_nt::type + Oriented_side; + typedef typename Same_uncertainty_nt::type + Bounded_side; + typedef typename Same_uncertainty_nt::type + Angle; + + typedef typename LA::template Vector LA_vector_selector; + typedef typename LA_vector_selector::type LA_vector; + typedef typename LA_vector_selector::Constructor Constructor; + typedef typename LA_vector_selector::const_iterator Cartesian_const_iterator; + + // convert types to the new way? painful to use... + typedef LA_vector Point; + typedef LA_vector Vector; + + // old way + typedef CartesianDVectorBase::Construct_LA_vector Construct_point; + typedef CartesianDVectorBase::Construct_LA_vector Construct_vector; + typedef CartesianDVectorBase::Construct_cartesian_const_iterator Construct_cartesian_const_iterator; + typedef CartesianDVectorBase::Construct_sum_of_vectors Construct_sum_of_vectors; + typedef CartesianDVectorBase::Construct_difference_of_vectors Construct_difference_of_vectors; + typedef CartesianDVectorBase::Construct_opposite_vector Construct_opposite_vector; + typedef CartesianDVectorBase::Construct_midpoint Construct_midpoint; + + typedef CartesianDVectorBase::Compute_cartesian_coordinate Compute_cartesian_coordinate; + + // new way + template struct Construct { + typedef Null_functor type; + }; + template struct Construct { + typedef CartesianDVectorBase::Construct_LA_vector type; + }; + template struct Construct { + typedef CartesianDVectorBase::Construct_LA_vector type; + }; + template struct Construct { + typedef CartesianDVectorBase::Construct_cartesian_const_iterator type; + }; + template struct Construct { + typedef CartesianDVectorBase::Construct_sum_of_vectors type; + }; + template struct Construct { + typedef CartesianDVectorBase::Construct_difference_of_vectors type; + }; + template struct Construct { + typedef CartesianDVectorBase::Construct_opposite_vector type; + }; + template struct Construct { + typedef CartesianDVectorBase::Construct_midpoint type; + }; + + template struct Compute { + typedef Null_functor type; + }; + template struct Compute { + typedef CartesianDVectorBase::Compute_cartesian_coordinate type; + }; + + template struct Predicate { + typedef Null_functor type; + }; + + CGAL_CONSTEXPR Cartesian_LA_base_d(){} + CGAL_CONSTEXPR Cartesian_LA_base_d(int d):Dimension_base(d){} +}; + +} //namespace CGAL + +#endif // CGAL_KERNEL_D_CARTESIAN_LA_BASE_H diff --git a/NewKernel_d/include/CGAL/Kernel_d/Cartesian_LA_functors.h b/NewKernel_d/include/CGAL/Kernel_d/Cartesian_LA_functors.h new file mode 100644 index 00000000000..84f0f045b1e --- /dev/null +++ b/NewKernel_d/include/CGAL/Kernel_d/Cartesian_LA_functors.h @@ -0,0 +1,192 @@ +#ifndef CGAL_CARTESIAN_LA_FUNCTORS_H +#define CGAL_CARTESIAN_LA_FUNCTORS_H + +#include +#include +#include +#include +#include + +namespace CGAL { +namespace CartesianDVectorBase { +#ifndef CGAL_CXX0X +namespace internal { +template struct Construct_LA_vector_; +#define CODE(Z,N,_) template struct Construct_LA_vector_ { \ + typedef typename R::Constructor Constructor; \ + typedef typename R::FT FT; \ + typedef typename R::LA_vector result_type; \ + result_type operator() \ + (BOOST_PP_ENUM_PARAMS(N,FT const& t)) const { \ + return typename Constructor::Values()(BOOST_PP_ENUM_PARAMS(N,t)); \ + } \ + result_type operator() \ + (BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(N),FT const& t)) const { \ + return typename Constructor::Values_divide()(t##N,BOOST_PP_ENUM_PARAMS(N,t)); \ + } \ + }; +BOOST_PP_REPEAT_FROM_TO(2, 11, CODE, _ ) +#undef CODE +} +#endif + +template struct Construct_LA_vector +#ifndef CGAL_CXX0X +: internal::Construct_LA_vector_ +#endif +{ + typedef R_ R; + typedef typename R::Constructor Constructor; + typedef typename R::FT FT; + typedef typename R::LA_vector result_type; + typedef typename R_::Default_ambient_dimension Dimension; + static const int dim=Dimension::value; + result_type operator()(int d)const{ + CGAL_assertion(d==dim); + return typename Constructor::Dimension()(d); + } + result_type operator()()const{ + return typename Constructor::Dimension()(dim); + } + result_type operator()(result_type const& v)const{ + return v; + } +#ifdef CGAL_CXX0X + result_type operator()(result_type&& v)const{ + return std::move(v); + } +#endif +#ifdef CGAL_CXX0X + template + typename std::enable_if::value && + (sizeof...(U)==dim), result_type>::type + operator()(U&&...u)const{ + return typename Constructor::Values()(std::forward(u)...); + } + //template::value>::type,class=typename std::enable_if<(sizeof...(U)==dim+1)>::type,class=void> + template + typename std::enable_if::value && + (sizeof...(U)==dim+1), result_type>::type + operator()(U&&...u)const{ + return Apply_to_last_then_rest()(typename Constructor::Values_divide(),std::forward(u)...); + } +#else + using internal::Construct_LA_vector_::operator(); +#endif + template typename boost::enable_if,result_type>::type operator() + (Iter const&f,Iter const&g,Cartesian_tag)const + { + int d=std::distance(f,g); + CGAL_assertion(d==dim); + return typename Constructor::Iterator()(dim,f,g); + } + template typename boost::enable_if,result_type>::type operator() + (Iter const&f,Iter g,Homogeneous_tag)const + { + --g; + return this->operator()(f,g,*g); + } + template typename boost::enable_if,result_type>::type operator() + (Iter const&f,Iter const&g)const + { + return this->operator()(f,g,typename R::Rep_tag()); + } + template typename boost::enable_if,result_type>::type operator() + (Iter const&f,Iter const&g,NT const&l)const + { + int d=std::distance(f,g); + CGAL_assertion(d==dim); + return typename Constructor::Iterator()(dim,CGAL::make_transforming_iterator(f,Divide(l)),CGAL::make_transforming_iterator(g,Divide(l))); + } +}; + +template struct Compute_cartesian_coordinate { + typedef R_ R; + typedef typename R_::FT FT; + typedef typename R::LA_vector first_argument_type; + typedef int second_argument_type; + typedef Tag_true Is_exact; +#ifdef CGAL_CXX0X + typedef decltype(std::declval()[0]) result_type; +#else + typedef FT result_type; // FT const& doesn't work with some LA +#endif + + result_type operator()(first_argument_type const& v,int i)const{ + return v[i]; + } +}; + +template struct Construct_cartesian_const_iterator { + typedef R_ R; + typedef typename R::LA_vector argument_type; + typedef typename R::LA_vector_selector S_; + typedef typename R::Cartesian_const_iterator result_type; + + result_type begin(argument_type const& v)const{ + return S_::vector_begin(v); + } + result_type end(argument_type const& v)const{ + return S_::vector_end(v); + } +}; + +template struct Construct_midpoint { + typedef R_ R; + typedef typename R::Point first_argument_type; + typedef typename R::Point second_argument_type; + typedef typename R::Point result_type; + + result_type operator()(result_type const& a, result_type const& b)const{ + return (a+b)/2; + } +}; + +template struct Construct_sum_of_vectors { + typedef R_ R; + typedef typename R::Vector first_argument_type; + typedef typename R::Vector second_argument_type; + typedef typename R::Vector result_type; + + result_type operator()(result_type const& a, result_type const& b)const{ + return a+b; + } +}; + +template struct Construct_difference_of_vectors { + typedef R_ R; + typedef typename R::Vector first_argument_type; + typedef typename R::Vector second_argument_type; + typedef typename R::Vector result_type; + + result_type operator()(result_type const& a, result_type const& b)const{ + return a-b; + } +}; + +template struct Construct_opposite_vector { + typedef R_ R; + typedef typename R::Vector result_type; + typedef typename R::Vector argument_type; + + result_type operator()(result_type const& v)const{ + return -v; + } +}; + +template struct Compute_scalar_product { + typedef R_ R; + typedef typename R::LA LA; + typedef typename R::FT result_type; + typedef typename R::Vector first_argument_type; + typedef typename R::Vector second_argument_type; + + result_type operator()(first_argument_type const& a, second_argument_type const& b)const{ + return LA::dot_product(a,b); + } +}; + + +} +} // namespace CGAL +#endif // CGAL_CARTESIAN_LA_FUNCTORS_H diff --git a/NewKernel_d/include/CGAL/Kernel_d/Cartesian_base.h b/NewKernel_d/include/CGAL/Kernel_d/Cartesian_base.h new file mode 100644 index 00000000000..c86cc88a8f3 --- /dev/null +++ b/NewKernel_d/include/CGAL/Kernel_d/Cartesian_base.h @@ -0,0 +1,28 @@ +#ifndef CGAL_KERNEL_D_CARTESIAN_BASE_H +#define CGAL_KERNEL_D_CARTESIAN_BASE_H + +#include +#include +#include + +namespace CGAL { + +template < typename FT_, typename Dim_> +struct Cartesian_base_d : public +Cartesian_complete_predicates< +Cartesian_complete_constructors< +Cartesian_complete_computes< +Cartesian_complete_types< + Cartesian_LA_base_d +>, false, Cartesian_base_d +>, false, Cartesian_base_d +>, false, Cartesian_base_d +> +{ + CGAL_CONSTEXPR Cartesian_base_d(){} + CGAL_CONSTEXPR Cartesian_base_d(int d):Dimension_base(d){} +}; + +} //namespace CGAL + +#endif // CGAL_KERNEL_D_CARTESIAN_BASE_H diff --git a/NewKernel_d/include/CGAL/Kernel_d/Cartesian_change_FT.h b/NewKernel_d/include/CGAL/Kernel_d/Cartesian_change_FT.h new file mode 100644 index 00000000000..21883e6c454 --- /dev/null +++ b/NewKernel_d/include/CGAL/Kernel_d/Cartesian_change_FT.h @@ -0,0 +1,92 @@ +#ifndef CGAL_KERNEL_D_CARTESIAN_CHANGE_FT_H +#define CGAL_KERNEL_D_CARTESIAN_CHANGE_FT_H + +#include +#include +#include +#include + +namespace CGAL { + +template < typename Base_, typename FT_> +struct Cartesian_change_FT_base : public + Base_ +{ + CGAL_CONSTEXPR Cartesian_change_FT_base(){} + CGAL_CONSTEXPR Cartesian_change_FT_base(int d):Base_(d){} + + typedef Base_ Kernel_base; + typedef FT_ RT; + typedef FT_ FT; + typedef CGAL::LA_eigen LA; + + typedef typename Same_uncertainty_nt::type + Boolean; + typedef typename Same_uncertainty_nt::type + Sign; + typedef typename Same_uncertainty_nt::type + Comparison_result; + typedef typename Same_uncertainty_nt::type + Orientation; + typedef typename Same_uncertainty_nt::type + Oriented_side; + typedef typename Same_uncertainty_nt::type + Bounded_side; + typedef typename Same_uncertainty_nt::type + Angle; + + typedef NT_converter FT_converter; + typedef transforming_iterator Cartesian_const_iterator; + + //FIXME: what if the functor's constructor takes a kernel as argument? + struct Construct_cartesian_const_iterator { + typedef typename Kernel_base::template Construct::type Functor_base; + Functor_base f; + typedef Cartesian_const_iterator result_type; + template + result_type begin(T const& v)const{ + return make_transforming_iterator(f.begin(v),FT_converter()); + } + template + result_type end(T const& v)const{ + return make_transforming_iterator(f.end(v),FT_converter()); + } + }; + + struct Compute_cartesian_coordinate { + typedef typename Kernel_base::template Compute::type Functor_base; + Functor_base f; + typedef FT result_type; + template + result_type operator()(Obj_ const& v,int i)const{ + return FT_converter()(f(v,i)); + } + }; + + template struct Compute { typedef Null_functor type; }; + template struct Compute { + typedef Compute_cartesian_coordinate type; + }; + template struct Predicate { typedef Null_functor type; }; + template struct Construct : + Kernel_base::template Construct { }; + template struct Construct { + typedef Construct_cartesian_const_iterator type; + }; +}; + +template < typename Base_, typename FT_> +struct Cartesian_change_FT : public +Cartesian_complete_predicates< +Cartesian_complete_computes< + Cartesian_change_FT_base +, true, Cartesian_change_FT > +, true, Cartesian_change_FT > +{ + CGAL_CONSTEXPR Cartesian_change_FT(){} + CGAL_CONSTEXPR Cartesian_change_FT(int d):Cartesian_change_FT_base(d){} +}; + +} //namespace CGAL + +#endif // CGAL_KERNEL_D_CARTESIAN_CHANGE_FT_H diff --git a/NewKernel_d/include/CGAL/Kernel_d/Cartesian_complete.h b/NewKernel_d/include/CGAL/Kernel_d/Cartesian_complete.h new file mode 100644 index 00000000000..683931c6174 --- /dev/null +++ b/NewKernel_d/include/CGAL/Kernel_d/Cartesian_complete.h @@ -0,0 +1,118 @@ +#ifndef CGAL_KERNEL_D_CARTESIAN_COMPLETE_H +#define CGAL_KERNEL_D_CARTESIAN_COMPLETE_H + +#include +#include +#include +#include +#include + + +namespace CGAL { +namespace internal { +BOOST_MPL_HAS_XXX_TRAIT_DEF(Segment) +BOOST_MPL_HAS_XXX_TRAIT_DEF(Ray) +BOOST_MPL_HAS_XXX_TRAIT_DEF(Direction) +BOOST_MPL_HAS_XXX_TRAIT_DEF(Line) +} + +template struct Cartesian_complete_types +: public R_ +{ + typedef R_ Kernel_base; +#define CGAL_Kernel_obj2(X) typedef typename boost::mpl::if_c::value,X##Cd,R_>::type::X X; +#include +}; + + +template struct Cartesian_complete_constructors +: public R_ +{ + typedef R_ Kernel_base; + template struct Construct { + typedef typename Kernel_base::template Construct::type Base_functor; + typedef typename boost::mpl::if_, + typename Cartesian_complete_constructors::template Construct::type, + Base_functor>::type type; + }; + +}; + +template struct Cartesian_complete_constructors +: public R_ +{ + typedef R_ Kernel_base; + template struct Construct + : Kernel_base::template Construct + { }; +#define CGAL_Kernel_cons2(F,f) \ + template struct Construct { \ + typedef CartesianDKernelFunctors::F type; \ + type f() const { return type(); } \ + }; +#include + +}; + + +template struct Cartesian_complete_predicates +: public R_ +{ + typedef R_ Kernel_base; + template struct Predicate { + typedef typename Kernel_base::template Predicate::type Base_functor; + typedef typename boost::mpl::if_, + typename Cartesian_complete_predicates::template Predicate::type, + Base_functor>::type type; + }; + +}; + +template struct Cartesian_complete_predicates +: public R_ +{ + typedef R_ Kernel_base; + template struct Predicate + : Kernel_base::template Predicate + { }; +#define CGAL_Kernel_pred(F,f) \ + template struct Predicate { \ + typedef CartesianDKernelFunctors::F type; \ + type f() const { return type(); } \ + }; +#include + +}; + + +template struct Cartesian_complete_computes +: public R_ +{ + typedef R_ Kernel_base; + template struct Compute { + typedef typename Kernel_base::template Compute::type Base_functor; + typedef typename boost::mpl::if_, + typename Cartesian_complete_computes::template Compute::type, + Base_functor>::type type; + }; + +}; + +template struct Cartesian_complete_computes +: public R_ +{ + typedef R_ Kernel_base; + template struct Compute + : Kernel_base::template Compute + { }; +#define CGAL_Kernel_comp2(F,f) \ + template struct Compute { \ + typedef CartesianDKernelFunctors::F type; \ + type f() const { return type(); } \ + }; +#include + +}; +} + +#endif // CGAL_KERNEL_D_CARTESIAN_COMPLETE_H diff --git a/NewKernel_d/include/CGAL/Kernel_d/Cartesian_filter_NT.h b/NewKernel_d/include/CGAL/Kernel_d/Cartesian_filter_NT.h new file mode 100644 index 00000000000..29c70024ce6 --- /dev/null +++ b/NewKernel_d/include/CGAL/Kernel_d/Cartesian_filter_NT.h @@ -0,0 +1,77 @@ +#ifndef CGAL_KERNEL_D_CARTESIAN_FILTER_NT_H +#define CGAL_KERNEL_D_CARTESIAN_FILTER_NT_H + +#include +#include +#include + +namespace CGAL { + +template < typename Base_ > +struct Cartesian_filter_NT : public Base_ +{ + CGAL_CONSTEXPR Cartesian_filter_NT(){} + CGAL_CONSTEXPR Cartesian_filter_NT(int d):Base_(d){} + typedef Base_ Kernel_base; + typedef Cartesian_change_FT K1; + typedef typename internal::Exact_type_selector::Type Exact_nt; + typedef Cartesian_change_FT K2; + + template struct Predicate { + struct type { + //TODO: use compression (derive from a compressed_pair?) + typedef typename K1::template Predicate::type P1; P1 p1; + typedef typename K2::template Predicate::type P2; P2 p2; + typedef typename P2::result_type result_type; + + //FIXME: if predicate's constructor takes a kernel as argument, how do we translate that? +#ifdef CGAL_CXX0X + template type(U&&...u):p1(std::forward(u)...),p2(std::forward(u)...){} +#else + //FIXME: usual boost preprocessor magic +#endif + +#ifdef CGAL_CXX0X + template result_type operator()(U&&...u)const{ + { + Protect_FPU_rounding p; + try { + typename P1::result_type res=p1(u...); // don't forward as u may be reused + if(is_certain(res)) return get_certain(res); + } catch (Uncertain_conversion_exception) {} + } + return p2(std::forward(u)...); + } +#else + //FIXME: usual boost preprocessor magic + result_type operator()()const{ // does it make sense to have 0 argument? + { + Protect_FPU_rounding p; + try { + typename P1::result_type res=p1(); + if(is_certain(res)) return get_certain(res); + } catch (Uncertain_conversion_exception) {} + } + return p2(); + } +#define CODE(Z,N,_) template result_type operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,const&t))const{ \ + { \ + Protect_FPU_rounding p; \ + try { \ + typename P1::result_type res=p1(BOOST_PP_ENUM_PARAMS(N,t)); \ + if(is_certain(res)) return get_certain(res); \ + } catch (Uncertain_conversion_exception) {} \ + } \ + return p2(BOOST_PP_ENUM_PARAMS(N,t)); \ + } + BOOST_PP_REPEAT_FROM_TO(1,11,CODE,_) +#undef CODE + +#endif + }; + }; +}; + +} //namespace CGAL + +#endif // CGAL_KERNEL_D_CARTESIAN_FILTER_NT_H diff --git a/NewKernel_d/include/CGAL/Kernel_d/Dimension_base.h b/NewKernel_d/include/CGAL/Kernel_d/Dimension_base.h new file mode 100644 index 00000000000..9788ee1867e --- /dev/null +++ b/NewKernel_d/include/CGAL/Kernel_d/Dimension_base.h @@ -0,0 +1,23 @@ +#ifndef bd_h +#define db_h +#include +#include +#include +namespace CGAL { +template struct Dimension_base { + //TODO: add some assertions + Dimension_base(int dim=-1):dim_(dim){} + int dimension()const{return dim_;} + void set_dimension(int dim){dim_=dim;} + private: + int dim_; +}; +template struct Dimension_base > { + Dimension_base(){} + Dimension_base(int dim){CGAL_assertion(dim_==dim);} + int dimension()const{return dim_;} + void set_dimension(int dim){CGAL_assertion(dim_==dim);} +}; +} +#endif + diff --git a/NewKernel_d/include/CGAL/Kernel_d/Segmentd.h b/NewKernel_d/include/CGAL/Kernel_d/Segmentd.h new file mode 100644 index 00000000000..875fe3f6c51 --- /dev/null +++ b/NewKernel_d/include/CGAL/Kernel_d/Segmentd.h @@ -0,0 +1,45 @@ +#ifndef CGAL_KERNELD_SEGMENTD_H +#define CGAL_KERNELD_SEGMENTD_H +#include +#define Segmentd SegmentCd +namespace CGAL { +template class Segmentd { + typedef typename R_::FT FT_; + typedef typename R_::Point Point_; + typedef typename R_::Vector Vector_; + typedef typename R_::Construct_vector Cv_; +// typedef typename R_::Compute_squared_distance Csd_; + typedef std::pair Data_; + Data_ data; + public: + typedef Segmentd Segment; +#ifdef CGAL_CXX0X + template + Segmentd(U&&...u):data(std::forward(u)...){} +#else + Segmentd(){} + Segmentd(Point_ const&a, Point_ const&b): data(a,b) {} +#endif + Point_ source()const{return data.first;} + Point_ target()const{return data.second;} + Point_ operator[](int i)const{ + if((i%2)==0) + return data.first; + else + return data.second; + } + Segmentd opposite()const{ + return Segmentd(data.second,data.first); + } + Vector_ vector()const{ + return Cv_()(data.first,data.second); + } +// FT_ squared_length()const{ +// return Csd_()(data.first,data.second); +// } +}; + +} // namespace CGAL + +#undef Segmentd +#endif // CGAL_KERNELD_SEGMENTD_H diff --git a/NewKernel_d/include/CGAL/Kernel_d/function_objects_cartesian.h b/NewKernel_d/include/CGAL/Kernel_d/function_objects_cartesian.h new file mode 100644 index 00000000000..80f158a999c --- /dev/null +++ b/NewKernel_d/include/CGAL/Kernel_d/function_objects_cartesian.h @@ -0,0 +1,183 @@ +#ifndef CGAL_KERNEL_D_FUNCTION_OBJECTS_CARTESIAN_H +#define CGAL_KERNEL_D_FUNCTION_OBJECTS_CARTESIAN_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace CGAL { +namespace CartesianDKernelFunctors { + +template struct Orientation { + typedef R_ R; + typedef typename R_::FT FT; + typedef typename R::Vector Vector; + typedef typename R::Point Point; + typedef typename R::Orientation result_type; + typedef typename R::LA::template Matrix::type Matrix; + + template + result_type operator()(Iter f, Iter const& e, Vector_tag)const{ + typename R::template Compute::type c; + Matrix m(R().dimension(),R().dimension()); + for(int i=0;f!=e;++f,++i) { + for(int j=0;j + result_type operator()(Iter f, Iter const& e, Point_tag)const{ + typename R::template Compute::type c; + Matrix m(R().dimension(),R().dimension()); + Point const& p0=*f++; + for(int i=0;f!=e;++f,++i) { + for(int j=0;j + result_type operator()(Iter const&f, Iter const& e)const{ + typename std::iterator_traits::difference_type d=std::distance(f,e); + int dim=R().dimension(); + if(d==dim) return operator()(f,e,Vector_tag()); + CGAL_assertion(d==dim+1); + return operator()(f,e,Point_tag()); + } + + //TODO: version that takes objects directly instead of iterators +}; + + +template struct Construct_opposite_vector { + typedef R_ R; + typedef typename R_::FT FT; + typedef typename R::Vector Vector; + typedef typename R::template Construct::type CV; + typedef typename R::template Construct::type CI; + typedef Vector result_type; + typedef Vector argument_type; + result_type operator()(Vector const&v)const{ + CI ci; + return CV()(make_transforming_iterator(ci.begin(v),std::negate()),make_transforming_iterator(ci.end(v),std::negate())); + } +}; + +template struct Construct_sum_of_vectors { + typedef R_ R; + typedef typename R_::FT FT; + typedef typename R::Vector Vector; + typedef typename R::template Construct::type CV; + typedef typename R::template Construct::type CI; + typedef Vector result_type; + typedef Vector first_argument_type; + typedef Vector second_argument_type; + result_type operator()(Vector const&a, Vector const&b)const{ + CI ci; + return CV()(make_transforming_pair_iterator(ci.begin(a),ci.begin(b),std::plus()),make_transforming_pair_iterator(ci.end(a),ci.end(b),std::plus())); + } +}; + +template struct Construct_difference_of_vectors { + typedef R_ R; + typedef typename R_::FT FT; + typedef typename R::Vector Vector; + typedef typename R::template Construct::type CV; + typedef typename R::template Construct::type CI; + typedef Vector result_type; + typedef Vector first_argument_type; + typedef Vector second_argument_type; + result_type operator()(Vector const&a, Vector const&b)const{ + CI ci; + return CV()(make_transforming_pair_iterator(ci.begin(a),ci.begin(b),std::minus()),make_transforming_pair_iterator(ci.end(a),ci.end(b),std::minus())); + } +}; + +template struct Construct_midpoint { + typedef R_ R; + typedef typename R_::FT FT; + typedef typename R::Point Point; + typedef typename R::template Construct::type CP; + typedef typename R::template Construct::type CI; + typedef Point result_type; + typedef Point first_argument_type; + typedef Point second_argument_type; + struct Average : std::binary_function { + FT operator()(FT const&a, FT const&b)const{ + return (a+b)/2; + } + }; + result_type operator()(Point const&a, Point const&b)const{ + CI ci; + //Divide half(2); + //return CP()(make_transforming_iterator(make_transforming_pair_iterator(ci.begin(a),ci.begin(b),std::plus()),half),make_transforming_iterator(make_transforming_pair_iterator(ci.end(a),ci.end(b),std::plus()),half)); + return CP()(make_transforming_pair_iterator(ci.begin(a),ci.begin(b),Average()),make_transforming_pair_iterator(ci.end(a),ci.end(b),Average())); + } +}; + +template struct Compute_squared_length { + typedef R_ R; + typedef typename R_::FT FT; + typedef typename R::Vector Vector; + typedef typename R::template Construct::type CI; + typedef FT result_type; + typedef Vector argument_type; + result_type operator()(Vector const&a)const{ + CI ci; + typename Algebraic_structure_traits::Square f; + // TODO: avoid this FT(0)+... + return std::accumulate(make_transforming_iterator(ci.begin(a),f),make_transforming_iterator(ci.end(a),f),FT(0)); + } +}; + +template struct Compute_squared_distance { + typedef R_ R; + typedef typename R_::FT FT; + typedef typename R::Point Point; + typedef typename R::template Construct::type CI; + typedef FT result_type; + typedef Point first_argument_type; + typedef Point second_argument_type; + struct Sq_diff : std::binary_function { + FT operator()(FT const&a, FT const&b)const{ + return CGAL::square(a-b); + } + }; + result_type operator()(Point const&a, Point const&b)const{ + CI ci; + Sq_diff f; + // TODO: avoid this FT(0)+... + return std::accumulate(make_transforming_pair_iterator(ci.begin(a),ci.begin(b),f),make_transforming_pair_iterator(ci.end(a),ci.end(b),f),FT(0)); + } +}; + +template struct Less_coordinate { + typedef R_ R; + typedef typename R_::FT FT; + typedef typename R::Comparison_result result_type; + typedef typename R::template Compute::type Cc; + typedef typename CGAL::Is_exact::type Is_exact; + + template + result_type operator()(V const&a, V const&b, I i)const{ + Cc c; + return c(a,i) +#include +#include +#include +#include +#include + +namespace CGAL { + +template struct LA_eigen { + typedef NT_ NT; + // Dim_ real dimension + // Max_dim_ upper bound on the dimension + template struct Vector { + typedef Eigen::Matrix::value,1,Eigen::ColMajor|Eigen::AutoAlign,Eigen_dimension::value,1> type; + typedef Construct_eigen Constructor; + //typedef NT const* const_iterator; + //FIXME: use Matrix_base instead in the iterator? + typedef Iterator_from_indices const_iterator; + + templatestatic const_iterator vector_begin(Vec_ const&a){ + return const_iterator(a,0); + } + + templatestatic const_iterator vector_end(Vec_ const&a){ + return const_iterator(a,a.size()); + } + + }; + template struct Matrix { + //TODO: don't pass on the values of Max_* for an expensive NT + typedef Eigen::Matrix::value,Eigen_dimension::value,Eigen::ColMajor|Eigen::AutoAlign,Eigen_dimension::value,Eigen_dimension::value> type; + // typedef ... Constructor + // typedef ... Accessor + }; + private: + template class Canonicalize_vector { + typedef typename Dimension_eigen::type S1; + typedef typename Dimension_eigen::type S2; + public: + typedef typename Vector::type type; + }; + public: + + templatestatic NT dot_product(Vec_ const&a,Vec_ const&b){ + return a.dot(b); + } + + template static NT determinant(Mat_ const&m,bool=false){ + return m.determinant(); + } + + template static typename + Same_uncertainty_nt::type + sign_of_determinant(Mat_ const&m,bool=false) + { + return CGAL::sign(m.determinant()); + } + + template static typename Canonicalize_vector::type homogeneous_add(Vec1 const&a,Vec2 const&b){ + //TODO: use compile-time size when available + int d=a.size(); + typename Canonicalize_vector::type v(d); + v << b[d-1]*a.topRows(d-1)+a[d-1]*b.topRows(d-1), a[d-1]*b[d-1]; + return v; + } + + template static typename Canonicalize_vector::type homogeneous_sub(Vec1 const&a,Vec2 const&b){ + int d=a.size(); + typename Canonicalize_vector::type v(d); + v << b[d-1]*a.topRows(d-1)-a[d-1]*b.topRows(d-1), a[d-1]*b[d-1]; + return v; + } + + template static std::pair homogeneous_dot_product(Vec1 const&a,Vec2 const&b){ + int d=a.size(); + return make_pair(a.topRows(d-1).dot(b.topRows(d-1)), a[d-1]*b[d-1]); + } + +}; +} +#endif diff --git a/NewKernel_d/include/CGAL/LA_eigen/constructors.h b/NewKernel_d/include/CGAL/LA_eigen/constructors.h new file mode 100644 index 00000000000..d30a3637ddf --- /dev/null +++ b/NewKernel_d/include/CGAL/LA_eigen/constructors.h @@ -0,0 +1,110 @@ +#ifndef ecs_h +#define ecs_h +#include +#include +#include +#include + +namespace CGAL { +template struct Construct_eigen { + typedef Vector_ result_type; + typedef typename Vector_::Scalar NT; + + struct Dimension { + result_type operator()(int d) const { + return result_type(d); + } + }; + + struct Iterator { + template + result_type operator()(int d,Iter const& f,Iter const& e) const { + CGAL_assertion(d==std::distance(f,e)); + CGAL_assertion(d<=std::min(result_type::SizeAtCompileTime,result_type::MaxSizeAtCompileTime)); + result_type a(d); + // TODO: check the right way to do this + std::copy(f,e,&a[0]); + return a; + } + }; + +#if 0 + struct Iterator_add_one { + template + result_type operator()(int d,Iter const& f,Iter const& e) const { + CGAL_assertion(d==std::distance(f,e)+1); + CGAL_assertion(d<=std::min(result_type::SizeAtCompileTime,result_type::MaxSizeAtCompileTime)); + result_type a; + std::copy(f,e,&a[0]); + a[d-1]=1; + return a; + } + }; +#endif + + struct Iterator_and_last { + template + result_type operator()(int d,Iter const& f,Iter const& e,CGAL_FORWARDABLE(T) t) const { + CGAL_assertion(d==std::distance(f,e)+1); + CGAL_assertion(d<=std::min(result_type::SizeAtCompileTime,result_type::MaxSizeAtCompileTime)); + result_type a; + std::copy(f,e,&a[0]); + a[d-1]=CGAL_FORWARD(T,t); + return a; + } + }; + +#ifdef CGAL_CXX0X + struct Initializer_list { + template + result_type operator()(std::initializer_list l) const { + return Iterator()(l.size(),l.begin(),l.end()); + } + }; +#endif + + struct Values { +#ifdef CGAL_CXX0X + template + result_type operator()(U&&...u) const { + return Initializer_list()({forward_safe(u)...}); + } +#else + +#define CODE(Z,N,_) result_type operator()(BOOST_PP_ENUM_PARAMS(N,NT const& t)) const { \ + CGAL_assertion(N<=std::min(result_type::SizeAtCompileTime,result_type::MaxSizeAtCompileTime)); \ + result_type a(N); \ + a << BOOST_PP_ENUM_PARAMS(N,t); \ + return a; \ +} +BOOST_PP_REPEAT_FROM_TO(1, 11, CODE, _ ) +#undef CODE + +#endif + }; + + struct Values_divide { +#ifdef CGAL_CXX0X + template + result_type operator()(H const&h,U&&...u) const { + return Initializer_list()({Rational_traits().make_rational(std::forward(u),h)...}); + } +#else + +#define VAR(Z,N,_) ( t##N / h ) +#define CODE(Z,N,_) template result_type \ + operator()(H const&h, BOOST_PP_ENUM_PARAMS(N,NT const& t)) const { \ + CGAL_assertion(N<=std::min(result_type::SizeAtCompileTime,result_type::MaxSizeAtCompileTime)); \ + result_type a(N); \ + a << BOOST_PP_ENUM(N,VAR,); \ + return a; \ +} +BOOST_PP_REPEAT_FROM_TO(1, 11, CODE, _ ) +#undef CODE +#undef VAR + +#endif + }; +}; +} +#endif diff --git a/NewKernel_d/include/CGAL/argument_swaps.h b/NewKernel_d/include/CGAL/argument_swaps.h new file mode 100644 index 00000000000..66192f0ec9f --- /dev/null +++ b/NewKernel_d/include/CGAL/argument_swaps.h @@ -0,0 +1,69 @@ +#ifndef CGAL_ARGUMENT_SWAPS_H +#define CGAL_ARGUMENT_SWAPS_H + +#include +#include + +#ifndef CGAL_CXX0X +#include +#include +#endif + +namespace CGAL { + +#ifdef CGAL_CXX0X + +namespace internal { + +template struct Apply_to_last_then_rest_; + +template +struct Apply_to_last_then_rest_ { + typedef typename Apply_to_last_then_rest_::result_type result_type; + inline result_type operator()(F&&f,T&&t,U&&...u)const{ + return Apply_to_last_then_rest_()( + std::forward(f), + std::forward(u)..., + std::forward(t)); + } +}; + +template +struct Apply_to_last_then_rest_<0,F,T,U...> { + typedef decltype(std::declval()(std::declval(), std::declval()...)) result_type; + inline result_type operator()(F&&f,T&&t,U&&...u)const{ + return std::forward(f)(std::forward(t), std::forward(u)...); + } +}; + +} // namespace internal + + +struct Apply_to_last_then_rest { + template inline + typename internal::Apply_to_last_then_rest_::result_type + operator()(F&&f,T&&t,U&&...u)const{ + return internal::Apply_to_last_then_rest_()( + std::forward(f), + std::forward(t), + std::forward(u)...); + } +}; + +#else // CGAL_CXX0X + +struct Apply_to_last_then_rest { +#define CODE(Z,N,_) template \ + typename boost::result_of::type \ + operator()(F const&f, BOOST_PP_ENUM_BINARY_PARAMS(N,T,const&t), T const&t) const { \ + return f(t,BOOST_PP_ENUM_PARAMS(N,t)); \ + } + BOOST_PP_REPEAT_FROM_TO(1,11,CODE,_) +#undef CODE +}; + +#endif // CGAL_CXX0X + +} // namespace CGAL + +#endif // CGAL_ARGUMENT_SWAPS_H diff --git a/NewKernel_d/include/CGAL/exactness.h b/NewKernel_d/include/CGAL/exactness.h new file mode 100644 index 00000000000..3dddca8123b --- /dev/null +++ b/NewKernel_d/include/CGAL/exactness.h @@ -0,0 +1,19 @@ +#ifndef CGAL_EXACTNESS_H +#define CGAL_EXACTNESS_H +#include +#include +namespace CGAL { +namespace internal { +BOOST_MPL_HAS_XXX_TRAIT_DEF(Is_exact) +} +template::value> struct Is_exact { + enum { value=false }; + typedef Tag_false type; +}; +template struct Is_exact { + typedef typename T::Is_exact type; + enum { value=type::value }; +}; + +} +#endif // CGAL_EXACTNESS_H diff --git a/NewKernel_d/include/CGAL/functor_tags.h b/NewKernel_d/include/CGAL/functor_tags.h new file mode 100644 index 00000000000..c9ca87e58a9 --- /dev/null +++ b/NewKernel_d/include/CGAL/functor_tags.h @@ -0,0 +1,37 @@ +#ifndef CGAL_FUNCTOR_TAGS_H +#define CGAL_FUNCTOR_TAGS_H +namespace CGAL { + class Null_type {~Null_type();}; // no such object should be created + + struct Vector_tag {}; + struct Point_tag {}; + struct Segment_tag {}; + struct Line_tag {}; + struct Direction_tag {}; + struct Ray_tag {}; + struct Bbox_tag {}; + + struct Construct_vector_tag {}; + struct Construct_point_tag {}; + struct Construct_segment_tag {}; + struct Construct_line_tag {}; + struct Construct_direction_tag {}; + struct Construct_ray_tag {}; + struct Construct_cartesian_const_iterator_tag {}; + struct Construct_midpoint_tag {}; + struct Construct_sum_of_vectors_tag {}; + struct Construct_difference_of_vectors_tag {}; + struct Construct_opposite_vector_tag {}; + + struct Compute_cartesian_coordinate_tag {}; + struct Compute_homogeneous_coordinate_tag {}; + struct Compute_squared_distance_tag {}; + struct Compute_squared_length_tag {}; + + struct Predicate_less_cartesian_coordinate_tag {}; + //FIXME: choose a convention + struct Predicate_orientation_tag {}; + struct Orientation_tag {}; + struct Predicate_in_sphere_tag {}; +} +#endif // CGAL_FUNCTOR_TAGS_H diff --git a/NewKernel_d/include/CGAL/iterator_from_indices.h b/NewKernel_d/include/CGAL/iterator_from_indices.h new file mode 100644 index 00000000000..bdea272a71b --- /dev/null +++ b/NewKernel_d/include/CGAL/iterator_from_indices.h @@ -0,0 +1,41 @@ +#ifndef CGAL_ITERATOR_FROM_INDICES_H +#define CGAL_ITERATOR_FROM_INDICES_H +#include +namespace CGAL { +//TODO: default type for Value_: typename same_cv::type::value_type>::type +template ()[0]) +#else + Value_& +#endif + > +class Iterator_from_indices +: public boost::iterator_facade, + Value_, std::bidirectional_iterator_tag, Ref_> +{ + friend class boost::iterator_core_access; + //FIXME: use int to save space + //FIXME: use a signed type + typedef std::size_t index_t; + Container_& cont; + index_t index; + void increment(){ ++index; } + void decrement(){ --index; } + void advance(std::ptrdiff_t n){ index+=n; } + ptrdiff_t distance_to(Iterator_from_indices const& other)const{ + return static_cast(other.index) + -static_cast(index); + } + bool equal(Iterator_from_indices const& other)const{ + return index==other.index; + } + Ref_ dereference()const{ + return cont[index]; + } + public: + Iterator_from_indices(Container_& cont_,std::size_t n) + : cont(cont_), index(n) {} +}; +} +#endif // CGAL_ITERATOR_FROM_INDICES_H diff --git a/NewKernel_d/include/CGAL/marcutils.h b/NewKernel_d/include/CGAL/marcutils.h new file mode 100644 index 00000000000..b12db5ff1ae --- /dev/null +++ b/NewKernel_d/include/CGAL/marcutils.h @@ -0,0 +1,129 @@ +#ifndef marcutils +#define marcutils + +#ifdef CGAL_CXX0X +#include +#include +#define CGAL_FORWARDABLE(T) T&& +#define CGAL_FORWARD(T,t) std::forward(t) +#define CGAL_MOVE(t) std::move(t) +#define CGAL_CONSTEXPR constexpr +#else +#define CGAL_FORWARDABLE(T) T const& +#define CGAL_FORWARD(T,t) t +#define CGAL_MOVE(t) t +#define CGAL_CONSTEXPR +#endif +#include +#include +#include + + +namespace CGAL { + // tell a function f(a,b,c) that its real argument is a(b,c) + struct Eval_functor {}; + + // forget the first argument. Useful to make something dependant + // (and thus usable in SFINAE), although that's not a great design. + template struct Second_arg { + typedef B type; + }; + + // like std::forward, except for basic types where it does a cast, to + // avoid issues with narrowing conversions +#ifdef CGAL_CXX0X + template + typename std::conditional::value&&std::is_arithmetic::type>::value,T,U&&>::type + forward_safe(V&& u) { return std::forward(u); } +#else + template U const& forward_safe(U const& u) { + return u; + } +#endif + +#ifdef CGAL_CXX0X + template struct Constructible_from_each; + template struct Constructible_from_each{ + enum { value=std::is_convertible::value&&Constructible_from_each::value }; + }; + template struct Constructible_from_each{ + enum { value=true }; + }; +#else +// currently only used in C++0X code +#endif + + template struct Scale { + T const& scale; + Scale(T const& t):scale(t){} + template +#ifdef CGAL_CXX0X + auto operator()(FT&& x)const->decltype(scale*std::forward(x)) +#else + FT operator()(FT const& x)const +#endif + { + return scale*CGAL_FORWARD(FT,x); + } + }; + template struct Divide { +#if !defined(CGAL_CXX0X) || !defined(BOOST_RESULT_OF_USE_DECLTYPE) + // requires boost > 1.44 + // shouldn't be needed with C++0X + //template struct result; + //template struct result { + // typedef FT type; + //}; + typedef NT result_type; +#endif + T const& scale; + Divide(T const& t):scale(t){} + template +#ifdef CGAL_CXX0X + //FIXME: gcc complains for Gmpq + //auto operator()(FT&& x)const->decltype(Rational_traits().make_rational(std::forward(x),scale)) + NT operator()(FT&& x)const +#else + NT operator()(FT const& x)const +#endif + { + return Rational_traits(). + make_rational(CGAL_FORWARD(FT,x),scale); + } + }; + + template struct has_cheap_constructor : boost::is_arithmetic{}; + template struct has_cheap_constructor > { + enum { value=true }; + }; + + // like std::multiplies but allows mixing types + // in C++0x in doesn't need to be a template + template < class Ret > + struct multiplies { + template +#ifdef CGAL_CXX0X + auto operator()(A&&a,B&&b)const->decltype(std::forward(a)*std::forward(b)) +#else + Ret operator()(A const& a, B const& b)const +#endif + { + return CGAL_FORWARD(A,a)*CGAL_FORWARD(B,b); + } + }; + template < class Ret > + struct division { + template +#ifdef CGAL_CXX0X + auto operator()(A&&a,B&&b)const->decltype(std::forward(a)/std::forward(b)) +#else + Ret operator()(A const& a, B const& b)const +#endif + { + return CGAL_FORWARD(A,a)/CGAL_FORWARD(B,b); + } + }; + +} + +#endif diff --git a/NewKernel_d/include/CGAL/myeigen.h b/NewKernel_d/include/CGAL/myeigen.h new file mode 100644 index 00000000000..c8f2af8fa63 --- /dev/null +++ b/NewKernel_d/include/CGAL/myeigen.h @@ -0,0 +1,43 @@ +#ifndef myeigen_h +#define myeigen_h +#include +#include +#include + +namespace Eigen { + + template<> struct NumTraits + { + typedef CGAL::Gmpq Real; + typedef CGAL::Gmpq NonInteger; + typedef CGAL::Gmpq Nested; + + enum { + IsComplex = 0, + IsInteger = 0, + IsSigned, + ReadCost = 10, + AddCost = 100, + MulCost = 1000 + }; + }; + + template<> struct NumTraits + { + typedef CGAL::Interval_nt_advanced Real; + typedef CGAL::Interval_nt_advanced NonInteger; + typedef CGAL::Interval_nt_advanced Nested; + + enum { + IsComplex = 0, + IsInteger = 0, + IsSigned, + ReadCost = 2, + AddCost = 2, + MulCost = 10 + }; + }; + +} + +#endif diff --git a/NewKernel_d/include/CGAL/static_int.h b/NewKernel_d/include/CGAL/static_int.h new file mode 100644 index 00000000000..16a8f174c9d --- /dev/null +++ b/NewKernel_d/include/CGAL/static_int.h @@ -0,0 +1,42 @@ +#ifndef CGAL_STATIC_INT_H +#define CGAL_STATIC_INT_H +#include + +namespace CGAL { +template struct static_zero { + operator NT() const { return constant(); } +}; +template struct static_one { + operator NT() const { return constant(); } +}; + +template static_zero operator-(static_zero) { return static_zero(); } + +template NT operator+(NT const& x, static_zero) { return x; } +template NT operator+(static_zero, NT const& x) { return x; } +template static_zero operator+(static_zero, static_zero) { return static_zero(); } +template static_one operator+(static_zero, static_one) { return static_one(); } +template static_one operator+(static_one, static_zero) { return static_one(); } + +template NT operator-(NT const& x, static_zero) { return x; } +template NT operator-(static_zero, NT const& x) { return -x; } +template static_zero operator-(static_zero, static_zero) { return static_zero(); } +template static_zero operator-(static_one, static_one) { return static_zero(); } +template static_one operator-(static_one, static_zero) { return static_one(); } + +template NT operator*(NT const& x, static_one) { return x; } +template NT operator*(static_one, NT const& x) { return x; } +template static_zero operator*(NT const&, static_zero) { return static_zero(); } +template static_zero operator*(static_zero, NT const&) { return static_zero(); } +template static_zero operator*(static_zero, static_zero) { return static_zero(); } +template static_one operator*(static_one, static_one) { return static_one(); } +template static_zero operator*(static_zero, static_one) { return static_zero(); } +template static_zero operator*(static_one, static_zero) { return static_zero(); } + +template NT operator/(NT const& x, static_one) { return x; } +template static_zero operator/(static_zero, NT const&) { return static_zero(); } +template static_zero operator/(static_zero, static_one) { return static_zero(); } +template static_one operator/(static_one, static_one) { return static_one(); } + +} +#endif // CGAL_STATIC_INT_H diff --git a/NewKernel_d/include/CGAL/transforming_iterator.h b/NewKernel_d/include/CGAL/transforming_iterator.h new file mode 100644 index 00000000000..2e5473b0476 --- /dev/null +++ b/NewKernel_d/include/CGAL/transforming_iterator.h @@ -0,0 +1,92 @@ +#ifndef CGAL_TRANSFORMING_ITERATOR_H +#define CGAL_TRANSFORMING_ITERATOR_H +#include +#include +#include +#include +#include + +// Inspired by the boost version, but more compact and +// without any iterator_category games. + +namespace CGAL { +namespace internal { + +// non-empty case +template::value> struct Functor_as_base { + Functor_as_base(){} + Functor_as_base(T const& t):f(t){} + //template Functor_as_base(Functor_as_base const&g):f(g.functor()){} + T const& functor()const{return f;} + T & functor() {return f;} + private: + T f; +}; + +// empty case +template struct Functor_as_base : public T { + Functor_as_base(){} + Functor_as_base(T const& t):T(t){} + //template Functor_as_base(Functor_as_base const&g):T(g.functor()){} + T const& functor()const{return *this;} + T & functor() {return *this;} +}; + +template +class transforming_iterator_helper +{ + typedef typename Default::Get()(std::declval::reference>())) +#else + typename boost::result_of::value_type)>::type + // should be reference instead of value_type +#endif + >::type reference; + + typedef typename Default::Get::type>::type>::type value_type; + + public: + typedef boost::iterator_adaptor< + Derived, + Iter, + value_type, + typename std::iterator_traits::iterator_category, + reference + > type; +}; +} + +template +class transforming_iterator +: public internal::transforming_iterator_helper,F,Iter,Ref,Val>::type, +private internal::Functor_as_base +{ + friend class boost::iterator_core_access; + typedef typename internal::transforming_iterator_helper::type Base; + typedef internal::Functor_as_base Functor_base; + typename Base::reference dereference()const{ + return functor()(*this->base_reference()); + } + public: + using Functor_base::functor; + transforming_iterator(){} + explicit transforming_iterator(Iter const&i,F const& f=F()) + :Base(i),Functor_base(f){} + template + transforming_iterator( + transforming_iterator const&i, + typename boost::enable_if_convertible::type* = 0, + typename boost::enable_if_convertible::type* = 0) + : Base(i.base()),Functor_base(i.functor()) {} + +}; + +template +transforming_iterator make_transforming_iterator(Iter const&i, F const&f=F()) { + return transforming_iterator(i,f); +} + +} + +#endif // CGAL_TRANSFORMING_ITERATOR_H diff --git a/NewKernel_d/include/CGAL/transforming_pair_iterator.h b/NewKernel_d/include/CGAL/transforming_pair_iterator.h new file mode 100644 index 00000000000..45908b10640 --- /dev/null +++ b/NewKernel_d/include/CGAL/transforming_pair_iterator.h @@ -0,0 +1,107 @@ +#ifndef CGAL_TRANSFORMING_PAIR_ITERATOR_H +#define CGAL_TRANSFORMING_PAIR_ITERATOR_H +// Should be a combination of transform_iterator and zip_iterator, +// but boost's iterator_category games are a pain. + +#include +#include +#include + + + +namespace CGAL { +namespace internal { +template ::value> +struct Min_category { + BOOST_STATIC_ASSERT((boost::is_convertible::value)); + typedef Cat1 type; +}; + +template +struct Min_category { + typedef Cat2 type; +}; + + +template +class transforming_pair_iterator_helper +{ + typedef typename Min_category< + typename std::iterator_traits::iterator_category, + typename std::iterator_traits::iterator_category> + ::type iterator_category; + + typedef typename Default::Get()(std::declval::reference>(),std::declval::reference>())) +#else + typename boost::result_of::value_type,typename std::iterator_traits::value_type)>::type + // should be reference instead of value_type +#endif + >::type reference; + + typedef typename Default::Get::type>::type>::type value_type; + + public: + typedef boost::iterator_facade< + Derived, + value_type, + iterator_category, + reference + // expect ptrdiff_t is good enough for difference + > type; +}; +} + +template +class transforming_pair_iterator +: public internal::transforming_pair_iterator_helper,F,It1,It2,Ref,Val>::type, +private internal::Functor_as_base +{ + It1 iter1; It2 iter2; + friend class boost::iterator_core_access; + typedef typename internal::transforming_pair_iterator_helper::type Base; + typedef internal::Functor_as_base Functor_base; + typename Base::reference dereference()const{ + return functor()(*iter1,*iter2); + } + bool equal(transforming_pair_iterator const&i)const{ + bool b=(iter1==i.iter1); + CGAL_assertion(b==(iter2==i.iter2)); + //FIXME: or do we want only one driving iterator + return b; + } + void increment(){ ++iter1; ++iter2; } + void decrement(){ --iter1; --iter2; } + void advance(std::ptrdiff_t n){ + std::advance(iter1,n); + std::advance(iter2,n); + } + std::ptrdiff_t distance_to(transforming_pair_iterator const&i)const{ + std::ptrdiff_t dist=std::distance(iter1,i.iter1); + CGAL_assertion(dist==std::distance(iter2,i.iter2)); + return dist; + } + public: + using Functor_base::functor; + transforming_pair_iterator(){} + explicit transforming_pair_iterator(It1 const&i1,It2 const&i2,F const& f=F()) + :Functor_base(f),iter1(i1),iter2(i2){} + template + transforming_pair_iterator( + transforming_pair_iterator const&i, + typename boost::enable_if_convertible::type* = 0, + typename boost::enable_if_convertible::type* = 0, + typename boost::enable_if_convertible::type* = 0) + : Functor_base(i.functor()),iter1(i.iter1),iter2(i.iter2) {} + +}; + +template +transforming_pair_iterator make_transforming_pair_iterator(It1 const&i1, It2 const&i2, F const&f=F()) { + return transforming_pair_iterator(i1,i2,f); +} + +} + +#endif // CGAL_TRANSFORMING_PAIR_ITERATOR_H