mirror of https://github.com/CGAL/cgal
adding a specialization for Sqrt_extension for NT_converter
and its test
This commit is contained in:
parent
1ebfa4025e
commit
e0a34e1dc8
|
|
@ -40,6 +40,7 @@
|
||||||
#include <CGAL/Sqrt_extension_fwd.h>
|
#include <CGAL/Sqrt_extension_fwd.h>
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
#include <boost/type_traits/is_same.hpp>
|
#include <boost/type_traits/is_same.hpp>
|
||||||
|
#include <CGAL/NT_converter.h>
|
||||||
|
|
||||||
#define CGAL_int(T) typename First_if_different<int, T>::Type
|
#define CGAL_int(T) typename First_if_different<int, T>::Type
|
||||||
|
|
||||||
|
|
@ -672,6 +673,48 @@ Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG> square (const Sqrt_extension<NT,ROOT,ACD
|
||||||
x.gamma()));
|
x.gamma()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//NT_converter specializations
|
||||||
|
template <class NT1,class ROOT1,class NT2,class ROOT2,class ACDE_TAG,class FP_TAG>
|
||||||
|
struct NT_converter < Sqrt_extension<NT1,ROOT1,ACDE_TAG,FP_TAG> , Sqrt_extension<NT2,ROOT2,ACDE_TAG,FP_TAG> >
|
||||||
|
: public std::unary_function< NT1, NT2 >
|
||||||
|
{
|
||||||
|
Sqrt_extension<NT2,ROOT2,ACDE_TAG,FP_TAG>
|
||||||
|
operator()(const Sqrt_extension<NT1,ROOT1,ACDE_TAG,FP_TAG> &a) const
|
||||||
|
{
|
||||||
|
if(!a.is_extended()) {
|
||||||
|
return Sqrt_extension<NT2,ROOT2,ACDE_TAG,FP_TAG>(NT_converter<NT1,NT2>()(a.a0()));
|
||||||
|
} else {
|
||||||
|
return Sqrt_extension<NT2,ROOT2,ACDE_TAG,FP_TAG>
|
||||||
|
(NT_converter<NT1,NT2>()(a.a0()),
|
||||||
|
NT_converter<NT1,NT2>()(a.a1()),
|
||||||
|
NT_converter<ROOT1,ROOT2>()(a.root()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class NT1,class NT2,class ROOT2,class ACDE_TAG,class FP_TAG>
|
||||||
|
struct NT_converter < NT1 , Sqrt_extension<NT2,ROOT2,ACDE_TAG,FP_TAG> >
|
||||||
|
: public std::unary_function< NT1, NT2 >
|
||||||
|
{
|
||||||
|
Sqrt_extension<NT2,ROOT2,ACDE_TAG,FP_TAG>
|
||||||
|
operator()(const NT1 &a) const
|
||||||
|
{
|
||||||
|
return Sqrt_extension<NT2,ROOT2,ACDE_TAG,FP_TAG>(NT_converter<NT1,NT2>()(a));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//needed because it's a better match than the specialization <NT1,NT1>
|
||||||
|
template <class NT1,class ROOT1,class ACDE_TAG,class FP_TAG>
|
||||||
|
struct NT_converter < Sqrt_extension<NT1,ROOT1,ACDE_TAG,FP_TAG>, Sqrt_extension<NT1,ROOT1,ACDE_TAG,FP_TAG> >
|
||||||
|
: public std::unary_function< NT1, NT1 >
|
||||||
|
{
|
||||||
|
const Sqrt_extension<NT1,ROOT1,ACDE_TAG,FP_TAG>&
|
||||||
|
operator()(const Sqrt_extension<NT1,ROOT1,ACDE_TAG,FP_TAG> &a) const
|
||||||
|
{
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// UNARY
|
// UNARY
|
||||||
template <class NT,class ROOT,class ACDE_TAG,class FP_TAG> Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>
|
template <class NT,class ROOT,class ACDE_TAG,class FP_TAG> Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>
|
||||||
operator + (const Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>& p) { return p; }
|
operator + (const Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>& p) { return p; }
|
||||||
|
|
|
||||||
|
|
@ -726,7 +726,20 @@ void sqrt_extension_test(){
|
||||||
scalar_factor_traits_test<AT,ACDE_TAG>();
|
scalar_factor_traits_test<AT,ACDE_TAG>();
|
||||||
test_algebraic_extension_traits<AT,ACDE_TAG>();
|
test_algebraic_extension_traits<AT,ACDE_TAG>();
|
||||||
|
|
||||||
test_get_arithmetic_kernel<AT,ACDE_TAG>();
|
test_get_arithmetic_kernel<AT,ACDE_TAG>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <CGAL/internal/Exact_type_selector.h>
|
||||||
|
void test_nt_converter()
|
||||||
|
{
|
||||||
|
typedef CGAL::internal::Exact_type_selector<int>::Type NT;
|
||||||
|
typedef CGAL::Sqrt_extension<double,double> Source;
|
||||||
|
typedef CGAL::Sqrt_extension<NT,NT> Target;
|
||||||
|
|
||||||
|
CGAL::NT_converter<Source,Target> converter;
|
||||||
|
|
||||||
|
Source s;
|
||||||
|
Target t=converter(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
|
@ -739,7 +752,8 @@ int main(){
|
||||||
sqrt_extension_test<CGAL::CORE_arithmetic_kernel,CGAL::Tag_false>();
|
sqrt_extension_test<CGAL::CORE_arithmetic_kernel,CGAL::Tag_false>();
|
||||||
sqrt_extension_test<CGAL::CORE_arithmetic_kernel,CGAL::Tag_true>();
|
sqrt_extension_test<CGAL::CORE_arithmetic_kernel,CGAL::Tag_true>();
|
||||||
#endif // CGAL_HAS_CORE_ARITHMETIC_KERNEL
|
#endif // CGAL_HAS_CORE_ARITHMETIC_KERNEL
|
||||||
return 0;
|
test_nt_converter();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue