fix iterators in lazy kernel, seems ok now

This commit is contained in:
Marc Glisse 2012-03-28 18:22:51 +00:00
parent 1e22b787c3
commit 7fe5e1741b
8 changed files with 81 additions and 42 deletions

View File

@ -11,7 +11,7 @@ the provision of certain types in a \ccc{Kernel}.
\ccNestedType{Type<Point_cartesian_const_iterator_tag>::type}{shall be a forward iterator (except that it may return an rvalue) whose \ccc{value_type} is \ccc{Kernel::Type<Point_tag>::type}.}
\ccNestedType{Functor<Convert_ttag<Point_tag>>::type}{[Optional] A default converter it available to \ccc{Kernel_converter}, but may be unsuitable if your Point type is too original.}
\ccNestedType{Functor<Construct_point_cartesian_const_iterator_tag>::type}{shall provide \ccc{Type<Point_cartesian_const_iterator_tag>::type operator()(Type<Point_tag>::type const&, Extremity_tag)const} where \ccc{Extemity_tag} is \ccc{Begin_tag} or \ccc{End_tag}.}
\ccNestedType{Functor<Construct_ttag<Point_cartesian_const_iterator_tag>>::type}{shall provide \ccc{Type<Point_cartesian_const_iterator_tag>::type operator()(Type<Point_tag>::type const&, Extremity_tag)const} where \ccc{Extemity_tag} is \ccc{Begin_tag} or \ccc{End_tag}.}
\ccNestedType{Functor<Compute_cartesian_coordinate_tag>::type}{shall provide \ccc{FT operator()(Type<Point_tag>::type,int k)const} which returns the $k$th Cartesian coordinate of the point.}
\ccNestedType{Functor<Point_dimension_tag>::type}{shall provide \ccc{int operator()(Type<Point_tag>::type)const} which returns the dimension of a point.}
\ccNestedType{Functor<Construct_ttag<Point_tag>>::type}{shall provide:\\

View File

@ -86,10 +86,10 @@ struct Cartesian_LA_base_d : public Dimension_base<Dim_>
template<class D> struct Functor<Construct_ttag<Point_tag>,D> {
typedef CartesianDVectorBase::Construct_LA_vector<Self,Origin> type;
};
template<class D> struct Functor<Construct_point_cartesian_const_iterator_tag,D> {
template<class D> struct Functor<Construct_ttag<Point_cartesian_const_iterator_tag>,D> {
typedef CartesianDVectorBase::Construct_cartesian_const_iterator<Self> type;
};
template<class D> struct Functor<Construct_vector_cartesian_const_iterator_tag,D> {
template<class D> struct Functor<Construct_ttag<Vector_cartesian_const_iterator_tag>,D> {
typedef CartesianDVectorBase::Construct_cartesian_const_iterator<Self> type;
};
#if 0

View File

@ -62,8 +62,8 @@ struct Cartesian_change_FT_base : public
return make_transforming_iterator(f(v,End_tag()),FT_converter());
}
};
typedef Construct_cartesian_const_iterator_<Construct_point_cartesian_const_iterator_tag,Point_cartesian_const_iterator> Construct_point_cartesian_const_iterator;
typedef Construct_cartesian_const_iterator_<Construct_vector_cartesian_const_iterator_tag,Vector_cartesian_const_iterator> Construct_vector_cartesian_const_iterator;
typedef Construct_cartesian_const_iterator_<Construct_ttag<Point_cartesian_const_iterator_tag>,Point_cartesian_const_iterator> Construct_point_cartesian_const_iterator;
typedef Construct_cartesian_const_iterator_<Construct_ttag<Vector_cartesian_const_iterator_tag>,Vector_cartesian_const_iterator> Construct_vector_cartesian_const_iterator;
template<class Tag>
struct Compute_cartesian_coordinate {
@ -90,10 +90,10 @@ struct Cartesian_change_FT_base : public
template<class D> struct Functor<Compute_vector_cartesian_coordinate_tag,D,Compute_tag> {
typedef Compute_cartesian_coordinate<Compute_vector_cartesian_coordinate_tag> type;
};
template<class D> struct Functor<Construct_point_cartesian_const_iterator_tag,D,Construct_iterator_tag> {
template<class D> struct Functor<Construct_ttag<Point_cartesian_const_iterator_tag>,D,Construct_iterator_tag> {
typedef Construct_point_cartesian_const_iterator type;
};
template<class D> struct Functor<Construct_vector_cartesian_const_iterator_tag,D,Construct_iterator_tag> {
template<class D> struct Functor<Construct_ttag<Vector_cartesian_const_iterator_tag>,D,Construct_iterator_tag> {
typedef Construct_vector_cartesian_const_iterator type;
};
};

View File

@ -16,7 +16,7 @@ struct Point_converter_help {
typedef typename K2::template Type<Point_tag>::type result_type;
template <class C>
result_type operator()(K1 const& k1, K2 const& k2, C const& conv, argument_type const& p) const {
typename K1::template Functor<Construct_point_cartesian_const_iterator_tag>::type i(k1);
typename K1::template Functor<Construct_ttag<Point_cartesian_const_iterator_tag> >::type i(k1);
typename K2::template Functor<Construct_ttag<Point_tag> >::type cp(k2);
return cp(conv(i(p,Begin_tag())),conv(i(p,End_tag())));
}
@ -57,7 +57,7 @@ template <class K1, class K2> struct KO_converter<Vector_tag,K1,K2>{
typedef typename K2::template Type<Vector_tag>::type result_type;
template <class C>
result_type operator()(K1 const& k1, K2 const& k2, C const& conv, argument_type const& v) const {
typename K1::template Functor<Construct_vector_cartesian_const_iterator_tag>::type i(k1);
typename K1::template Functor<Construct_ttag<Vector_cartesian_const_iterator_tag> >::type i(k1);
typename K2::template Functor<Construct_ttag<Vector_tag> >::type cp(k2);
return cp(conv(i(v,Begin_tag())),conv(i(v,End_tag())));
}

View File

@ -2,6 +2,7 @@
#define CGAL_KERNEL_D_LAZY_CARTESIAN_H
#include <CGAL/basic.h>
#include <CGAL/algorithm.h>
#include <CGAL/Lazy.h>
#include <CGAL/Default.h>
#include <CGAL/Filtered_predicate.h>
@ -9,6 +10,36 @@
namespace CGAL {
template<class K,class T>
struct Nth_iterator_element : private Store_kernel<K> {
Nth_iterator_element(){}
Nth_iterator_element(K const&k):Store_kernel<K>(k){}
typedef typename Read_tag_type<K, typename iterator_tag_traits<T>::value_tag>::type result_type;
template<class U> result_type operator()(CGAL_FORWARDABLE(U) u, int i) const {
typename K::template Functor<Construct_ttag<T> >::type ci(this->kernel());
return *cpp0x::next(ci(CGAL_FORWARD(U,u),Begin_tag()),i);
}
};
//typedef typename Functor<typename iterator_tag_traits<T>::nth_element>::type nth_elem;
template<class K, class T, bool = iterator_tag_traits<T>::has_nth_element>
struct Select_nth_element_functor {
typedef Nth_iterator_element<K, T> type;
};
template<class K, class T>
struct Select_nth_element_functor <K, T, true> :
K::template Functor<typename iterator_tag_traits<T>::nth_element> {};
namespace internal {
template<class A,class B,class C,bool/*is_NT=false*/>
struct Lazy_construction_maybe_nt {
typedef Lazy_construction<A,B,C> type;
};
template<class A,class B,class C>
struct Lazy_construction_maybe_nt<A,B,C,true> {
typedef Lazy_construction_nt<A,B,C> type;
};
}
template <class EK_, class AK_, class E2A_/*, class Kernel_=Default*/>
struct Lazy_cartesian : Dimension_base<typename EK_::Default_ambient_dimension>
{
@ -32,7 +63,7 @@ struct Lazy_cartesian : Dimension_base<typename EK_::Default_ambient_dimension>
typedef Approx_converter<Kernel, Approximate_kernel> C2A;
typedef Exact_converter<Kernel, Exact_kernel> C2E;
typedef CGAL::Lazy_exact_nt<typename Exact_kernel::FT> FT;
typedef FT RT;
typedef CGAL::Lazy_exact_nt<typename Exact_kernel::RT> RT;
typedef typename Exact_kernel::Rep_tag Rep_tag;
typedef typename Exact_kernel::Kernel_tag Kernel_tag;
@ -64,6 +95,9 @@ struct Lazy_cartesian : Dimension_base<typename EK_::Default_ambient_dimension>
template <class D> struct Type<FT_tag,D> {
typedef FT type;
};
template <class D> struct Type<RT_tag,D> {
typedef RT type;
};
typedef typename typeset_intersection<
typename Approximate_kernel::Object_list,
typename Exact_kernel::Object_list
@ -95,28 +129,19 @@ struct Lazy_cartesian : Dimension_base<typename EK_::Default_ambient_dimension>
>::type Iterator_list;
//TODO: handle the case without nth_element
#if 0
template<class T>struct Default_nth_element : private Store_kernel<Kernel> {
Default_nth_element(){}
Default_nth_element(Kernel const&k):Store_kernel<Kernel>(k){}
typedef /*???*/ result_type;
template<class U> result_type operator()(CGAL_FORWARDABLE(U) u, int i) {
typename /*???*/ ci(this->kernel());
std::advance(ci, i);
return *i;
}
};
#endif
template <class T> struct Iterator {
//WARNING: this fails because it is not lazy enough:
//typedef typename Read_tag_type<Self,typename iterator_tag_traits<T>::value_tag>::type V;
typedef typename Type<typename iterator_tag_traits<T>::value_tag>::type V;
typedef typename iterator_tag_traits<T>::value_tag Vt;
typedef typename Type<Vt>::type V;
typedef typename Select_nth_element_functor<Approximate_kernel,T>::type AF;
typedef typename Select_nth_element_functor<Exact_kernel,T>::type EF;
typedef typename internal::Lazy_construction_maybe_nt<
Kernel, AF, EF, is_NT_tag<Vt>::value
>::type nth_elem;
typedef Iterator_from_indices<
const typename Type<typename iterator_tag_traits<T>::container>::type,
const V, V,
typename Functor<typename iterator_tag_traits<T>::nth_element>::type
const V, V, nth_elem
> type;
};
//typedef typename Iterator<Point_cartesian_const_iterator_tag>::type Point_cartesian_const_iterator;

View File

@ -300,7 +300,7 @@ template<class R_> struct Construct_opposite_vector : private Store_kernel<R_> {
typedef typename R_::FT FT;
typedef typename R::template Type<Vector_tag>::type Vector;
typedef typename R::template Functor<Construct_ttag<Vector_tag> >::type CV;
typedef typename R::template Functor<Construct_vector_cartesian_const_iterator_tag>::type CI;
typedef typename R::template Functor<Construct_ttag<Vector_cartesian_const_iterator_tag> >::type CI;
typedef Vector result_type;
typedef Vector argument_type;
result_type operator()(Vector const&v)const{
@ -315,7 +315,7 @@ template<class R_> struct Construct_sum_of_vectors : private Store_kernel<R_> {
typedef typename R_::FT FT;
typedef typename R::template Type<Vector_tag>::type Vector;
typedef typename R::template Functor<Construct_ttag<Vector_tag> >::type CV;
typedef typename R::template Functor<Construct_vector_cartesian_const_iterator_tag>::type CI;
typedef typename R::template Functor<Construct_ttag<Vector_cartesian_const_iterator_tag> >::type CI;
typedef Vector result_type;
typedef Vector first_argument_type;
typedef Vector second_argument_type;
@ -331,7 +331,7 @@ template<class R_> struct Construct_difference_of_vectors : private Store_kernel
typedef typename R_::FT FT;
typedef typename R::template Type<Vector_tag>::type Vector;
typedef typename R::template Functor<Construct_ttag<Vector_tag> >::type CV;
typedef typename R::template Functor<Construct_vector_cartesian_const_iterator_tag>::type CI;
typedef typename R::template Functor<Construct_ttag<Vector_cartesian_const_iterator_tag> >::type CI;
typedef Vector result_type;
typedef Vector first_argument_type;
typedef Vector second_argument_type;
@ -347,7 +347,7 @@ template<class R_> struct Construct_midpoint : private Store_kernel<R_> {
typedef typename R_::FT FT;
typedef typename R::template Type<Point_tag>::type Point;
typedef typename R::template Functor<Construct_ttag<Point_tag> >::type CP;
typedef typename R::template Functor<Construct_point_cartesian_const_iterator_tag>::type CI;
typedef typename R::template Functor<Construct_ttag<Point_cartesian_const_iterator_tag> >::type CI;
typedef Point result_type;
typedef Point first_argument_type;
typedef Point second_argument_type;
@ -369,7 +369,7 @@ template<class R_> struct Compute_squared_length : private Store_kernel<R_> {
typedef R_ R;
typedef typename R_::FT FT;
typedef typename R::template Type<Vector_tag>::type Vector;
typedef typename R::template Functor<Construct_vector_cartesian_const_iterator_tag>::type CI;
typedef typename R::template Functor<Construct_ttag<Vector_cartesian_const_iterator_tag> >::type CI;
typedef FT result_type;
typedef Vector argument_type;
result_type operator()(Vector const&a)const{
@ -385,7 +385,7 @@ template<class R_> struct Compute_squared_distance : private Store_kernel<R_> {
typedef R_ R;
typedef typename R_::FT FT;
typedef typename R::template Type<Point_tag>::type Point;
typedef typename R::template Functor<Construct_point_cartesian_const_iterator_tag>::type CI;
typedef typename R::template Functor<Construct_ttag<Point_cartesian_const_iterator_tag> >::type CI;
typedef FT result_type;
typedef Point first_argument_type;
typedef Point second_argument_type;
@ -462,7 +462,7 @@ template<class R_> struct Compare_lexicographically : private Store_kernel<R_> {
typedef R_ R;
typedef typename R_::FT FT;
typedef typename R::Comparison_result result_type;
typedef typename R::template Functor<Construct_point_cartesian_const_iterator_tag>::type CI;
typedef typename R::template Functor<Construct_ttag<Point_cartesian_const_iterator_tag> >::type CI;
// TODO: This is_exact thing should be reengineered.
// the goal is to have a way to tell: don't filter this
typedef typename CGAL::Is_exact<CI>::type Is_exact;

View File

@ -13,8 +13,9 @@ namespace CGAL {
struct Misc_tag {};
struct No_filter_tag {};
struct FT_tag {};
struct RT_tag {};
template<class>struct Construct_ttag {};
template<class>struct Convert_ttag {};
template<class> struct map_functor_type { typedef Misc_tag type; };
template<class Tag, class Obj, class Base> struct Typedef_tag_type;
@ -27,6 +28,10 @@ namespace CGAL {
template<class Kernel> \
struct Read_tag_type<Kernel, X##_tag> { typedef typename Kernel::X type; }
// Not exactly objects, but the extras can't hurt.
DECL_OBJ(FT);
DECL_OBJ(RT);
DECL_OBJ(Vector);
DECL_OBJ(Point);
DECL_OBJ(Segment);
@ -36,6 +41,10 @@ namespace CGAL {
DECL_OBJ(Bbox);
#undef DECL_OBJ
template<class> struct is_NT_tag { enum { value = false }; };
template<> struct is_NT_tag<FT_tag> { enum { value = true }; };
template<> struct is_NT_tag<RT_tag> { enum { value = true }; };
template<class> struct iterator_tag_traits {
enum { is_iterator = false, has_nth_element = false };
typedef Null_tag value_tag;
@ -66,11 +75,14 @@ namespace CGAL {
DECL_ITER_OBJ(Point_cartesian_const_iterator, FT, Compute_point_cartesian_coordinate, Point);
#undef DECL_ITER_OBJ
template<class>struct Construct_ttag {};
template<class>struct Convert_ttag {};
template<class>struct map_result_tag{typedef Null_type type;};
template<class T>struct map_result_tag<Construct_ttag<T> >{typedef T type;};
template<class T>struct map_functor_type<Construct_ttag<T> >{typedef Construct_tag type;};
template<class T>struct map_functor_type<Construct_ttag<T> > :
BOOSTD conditional<iterator_tag_traits<T>::is_iterator,
Construct_iterator_tag,
Construct_tag> {};
template<class T>struct map_functor_type<Convert_ttag<T> >{typedef Misc_tag type;};
#define DECL_CONSTRUCT(X,Y) struct X##_tag {}; \
template<>struct map_result_tag<X##_tag>{typedef Y##_tag type;}; \
@ -87,12 +99,14 @@ namespace CGAL {
DECL_CONSTRUCT(Construct_difference_of_vectors,Vector);
DECL_CONSTRUCT(Construct_opposite_vector,Vector);
#undef DECL_CONSTRUCT
#if 0
#define DECL_ITER_CONSTRUCT(X,Y) struct X##_tag {}; \
template<>struct map_result_tag<X##_tag>{typedef Y##_tag type;}; \
template<>struct map_functor_type<X##_tag>{typedef Construct_iterator_tag type;}
DECL_ITER_CONSTRUCT(Construct_point_cartesian_const_iterator,Point_cartesian_const_iterator);
DECL_ITER_CONSTRUCT(Construct_vector_cartesian_const_iterator,Vector_cartesian_const_iterator);
#undef DECL_ITER_CONSTRUCT
#endif
//FIXME: choose a convention: prefix with Predicate_ ?
#define DECL_PREDICATE(X) struct X##_tag {}; \

View File

@ -76,7 +76,7 @@ typedef K1::Functor<CGAL::Construct_ttag<CGAL::Point_tag> >::type CP;
typedef K1::Functor<CGAL::Construct_ttag<CGAL::Vector_tag> >::type CV;
typedef K1::Functor<CGAL::Construct_ttag<CGAL::Segment_tag> >::type CS;
typedef K1::Functor<CGAL::Construct_segment_extremity_tag>::type CSE;
typedef K1::Functor<CGAL::Construct_point_cartesian_const_iterator_tag>::type CCI;
typedef K1::Functor<CGAL::Construct_ttag<CGAL::Point_cartesian_const_iterator_tag> >::type CCI;
typedef K1::Functor<CGAL::Orientation_of_points_tag>::type PO;
typedef K1::Functor<CGAL::Side_of_oriented_sphere_tag>::type SOS;
//typedef K1::Point_cartesian_const_iterator CI;