mirror of https://github.com/CGAL/cgal
Merge pull request #6120 from MaelRL/Kernel_23-Converter_fundamental_types-GF
This commit is contained in:
commit
a5a5a43205
|
|
@ -33,10 +33,12 @@
|
|||
#include <CGAL/Random.h>
|
||||
#include <CGAL/Cartesian_d.h>
|
||||
#include <CGAL/Homogeneous_d.h>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
#include <CGAL/Min_sphere_annulus_d_traits_d.h>
|
||||
#include <CGAL/Min_sphere_d.h>
|
||||
#include <CGAL/Quotient.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
|
||||
using namespace CGAL;
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@
|
|||
#include <boost/mpl/logical.hpp>
|
||||
#include <boost/mpl/remove.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
// Guess which compiler needs this work around ?
|
||||
|
|
@ -82,8 +84,7 @@ struct Converting_visitor : boost::static_visitor<> {
|
|||
} // namespace internal
|
||||
|
||||
template < class K1, class K2,
|
||||
// class Converter = NT_converter<typename K1::FT, typename K2::FT> >
|
||||
class Converter>
|
||||
class Converter /*= typename internal::Default_converter<K1, K2>::Type*/>
|
||||
class Cartesian_converter : public Enum_converter
|
||||
{
|
||||
typedef Enum_converter Base;
|
||||
|
|
@ -96,24 +97,24 @@ public:
|
|||
using Base::operator();
|
||||
|
||||
Origin
|
||||
operator()(const Origin& o) const
|
||||
operator()(Origin o) const
|
||||
{
|
||||
return o;
|
||||
}
|
||||
|
||||
Null_vector
|
||||
operator()(const Null_vector& n) const
|
||||
operator()(Null_vector n) const
|
||||
{
|
||||
return n;
|
||||
}
|
||||
|
||||
Bbox_2
|
||||
const Bbox_2&
|
||||
operator()(const Bbox_2& b) const
|
||||
{
|
||||
return b;
|
||||
}
|
||||
|
||||
Bbox_3
|
||||
const Bbox_3&
|
||||
operator()(const Bbox_3& b) const
|
||||
{
|
||||
return b;
|
||||
|
|
@ -125,6 +126,14 @@ public:
|
|||
return c(a);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T
|
||||
operator()(const T t,
|
||||
typename std::enable_if<std::is_fundamental<T>::value>::type* = nullptr) const
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
// drop the boost::detail::variant::void_ generated by the macros
|
||||
// from the sequence, transform with the type mapper and throw the
|
||||
// new list into a variant
|
||||
|
|
@ -384,24 +393,25 @@ public:
|
|||
return std::make_pair(operator()(pp.first), operator()(pp.second));
|
||||
}
|
||||
|
||||
typename K2::Aff_transformation_2
|
||||
operator()(const typename K1::Aff_transformation_2& a) const
|
||||
{
|
||||
typedef typename K2::Aff_transformation_2 Aff_transformation_2;
|
||||
return Aff_transformation_2(c(a.m(0,0)), c(a.m(0,1)), c(a.m(0,2)),
|
||||
c(a.m(1,0)), c(a.m(1,1)), c(a.m(1,2)),
|
||||
c(a.m(2,2)));
|
||||
}
|
||||
|
||||
typename K2::Aff_transformation_3
|
||||
operator()(const typename K1::Aff_transformation_3 &a) const
|
||||
operator()(const typename K1::Aff_transformation_3& a) const
|
||||
{
|
||||
typedef typename K2::Aff_transformation_3 Aff_transformation_3;
|
||||
typename K2::FT t[12];
|
||||
for(int i=0; i< 3; ++i)
|
||||
{
|
||||
for(int j=0; j<4; ++j)
|
||||
{
|
||||
t[i*4+j] = a.m(i,j);
|
||||
}
|
||||
}
|
||||
return Aff_transformation_3(
|
||||
t[0],t[1],t[2],t[3],
|
||||
t[4],t[5],t[6],t[7],
|
||||
t[8],t[9],t[10],t[11],
|
||||
a.m(3,3));
|
||||
return Aff_transformation_3(c(a.m(0,0)), c(a.m(0,1)), c(a.m(0,2)), c(a.m(0,3)),
|
||||
c(a.m(1,0)), c(a.m(1,1)), c(a.m(1,2)), c(a.m(1,3)),
|
||||
c(a.m(2,0)), c(a.m(2,1)), c(a.m(2,2)), c(a.m(2,3)),
|
||||
c(a.m(3,3)));
|
||||
}
|
||||
|
||||
private:
|
||||
Converter c;
|
||||
K2 k;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@
|
|||
#include <CGAL/Enum_converter.h>
|
||||
#include <CGAL/Bbox_2.h>
|
||||
#include <CGAL/Bbox_3.h>
|
||||
#include <CGAL/Origin.h>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
|
|
@ -47,13 +50,25 @@ public:
|
|||
|
||||
using Base::operator();
|
||||
|
||||
Bbox_2
|
||||
Origin
|
||||
operator()(Origin o) const
|
||||
{
|
||||
return o;
|
||||
}
|
||||
|
||||
Null_vector
|
||||
operator()(Null_vector n) const
|
||||
{
|
||||
return n;
|
||||
}
|
||||
|
||||
const Bbox_2&
|
||||
operator()(const Bbox_2& b)
|
||||
{
|
||||
return b;
|
||||
}
|
||||
|
||||
Bbox_3
|
||||
const Bbox_3&
|
||||
operator()(const Bbox_3& b)
|
||||
{
|
||||
return b;
|
||||
|
|
@ -62,13 +77,21 @@ public:
|
|||
typename K2::RT
|
||||
operator()(const typename K1::RT &a) const
|
||||
{
|
||||
return c(a);
|
||||
return rc(a);
|
||||
}
|
||||
|
||||
typename K2::FT
|
||||
operator()(const typename K1::FT &a) const
|
||||
{
|
||||
return c(a);
|
||||
return fc(a);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T
|
||||
operator()(const T t,
|
||||
typename std::enable_if<std::is_fundamental<T>::value>::type* = nullptr) const
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
typename K2::Point_2
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Simple_homogeneous.h>
|
||||
#include <CGAL/Interval_nt.h>
|
||||
|
||||
#include <CGAL/Cartesian_converter.h>
|
||||
#include <CGAL/Homogeneous_converter.h>
|
||||
|
||||
#ifdef CGAL_USE_CORE
|
||||
#include <CGAL/CORE_Expr.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
using EPICK = CGAL::Exact_predicates_inexact_constructions_kernel;
|
||||
using EPECK = CGAL::Exact_predicates_exact_constructions_kernel;
|
||||
using SCLD = CGAL::Simple_cartesian<long double>;
|
||||
using SCI = CGAL::Simple_cartesian<CGAL::Interval_nt<> >;
|
||||
using SHI = CGAL::Simple_homogeneous<CGAL::Interval_nt<> >;
|
||||
using NT_exact = CGAL::internal::Exact_field_selector<double>::Type;
|
||||
using SHD = CGAL::Simple_homogeneous<double>;
|
||||
using SHE = CGAL::Simple_homogeneous<NT_exact>;
|
||||
|
||||
CGAL::Cartesian_converter<SCI, EPICK> sci_to_epick;
|
||||
CGAL::Cartesian_converter<SCLD, EPICK> scld_to_epick;
|
||||
CGAL::Cartesian_converter<SCI, EPECK> sci_to_epeck;
|
||||
CGAL::Cartesian_converter<EPECK, EPICK> epeck_to_epick;
|
||||
CGAL::Homogeneous_converter<SHI, SHD> shi_to_shd;
|
||||
CGAL::Homogeneous_converter<SHE, SHD> she_to_shd;
|
||||
CGAL::Homogeneous_converter<SHE, SHE> she_to_she;
|
||||
|
||||
assert(sci_to_epick(SCI::FT(2)) == EPICK::FT(2));
|
||||
assert(scld_to_epick((long double)(2.)) /*long double is FT*/ == EPICK::FT(2));
|
||||
|
||||
// fundamental types != FT
|
||||
assert(sci_to_epick((long int)(2)) == (long int)(2));
|
||||
assert(sci_to_epick(2.) == 2.);
|
||||
assert(sci_to_epick(bool(true)) == true);
|
||||
assert(sci_to_epick(true) == true);
|
||||
assert(sci_to_epick(false) == false);
|
||||
assert(sci_to_epick(CGAL::ON_POSITIVE_SIDE) == CGAL::ON_POSITIVE_SIDE);
|
||||
|
||||
#ifdef CGAL_USE_CORE
|
||||
using SSCE = CGAL::Simple_cartesian<CORE::Expr>;
|
||||
CGAL::Cartesian_converter<SSCE, EPICK> scce_to_epick;
|
||||
|
||||
assert(scce_to_epick(2.) == 2.);
|
||||
assert(scce_to_epick((signed long long int)(1)) == 1);
|
||||
scce_to_epick(CORE::Expr(2.) == EPICK::FT(2));
|
||||
#endif
|
||||
|
||||
assert(sci_to_epeck((signed char)('a')) == (signed char)('a'));
|
||||
|
||||
assert(epeck_to_epick(EPECK::FT(2)) == EPICK::FT(2));
|
||||
assert(epeck_to_epick(2.) == 2.);
|
||||
|
||||
// Homogeneous
|
||||
assert(shi_to_shd(2.) == 2.);
|
||||
assert(shi_to_shd(SHI::RT(2.)) == SHD::RT(2.));
|
||||
|
||||
assert(she_to_shd(SHE::RT(2)) == SHD::RT(2));
|
||||
assert(she_to_shd(SHE::FT(2.)) == SHD::FT(2.));
|
||||
assert(she_to_shd(2.) == 2.);
|
||||
assert(she_to_she(SHE::RT(2)) == SHE::RT(2));
|
||||
|
||||
std::cout << "NT_exact is " << typeid(NT_exact).name() << std::endl;
|
||||
CGAL::NT_converter<CGAL::Quotient<NT_exact>, CGAL::Quotient<NT_exact> > qnte_to_qnte;
|
||||
assert(qnte_to_qnte(2.) == CGAL::Quotient<NT_exact>(2.));
|
||||
|
||||
std::cout << "Done" << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -82,13 +82,13 @@ public:
|
|||
: c(), k(), result_point_(20) {}
|
||||
|
||||
Origin
|
||||
operator()(const Origin& o) const
|
||||
operator()(Origin o) const
|
||||
{
|
||||
return o;
|
||||
}
|
||||
|
||||
Null_vector
|
||||
operator()(const Null_vector& n) const
|
||||
operator()(Null_vector n) const
|
||||
{
|
||||
return n;
|
||||
}
|
||||
|
|
@ -99,6 +99,14 @@ public:
|
|||
return c(a);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T
|
||||
operator()(const T t,
|
||||
typename std::enable_if<std::is_fundamental<T>::value>::type* = nullptr) const
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
std::vector<Object>
|
||||
operator()(const std::vector<Object>& v) const
|
||||
{
|
||||
|
|
@ -110,11 +118,6 @@ public:
|
|||
return res;
|
||||
}
|
||||
|
||||
int operator()(const int &a)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
typename K2::Point_d
|
||||
operator()(const typename K1::Point_d &a) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,16 +13,20 @@
|
|||
#ifndef CGAL_NT_CONVERTER_H
|
||||
#define CGAL_NT_CONVERTER_H
|
||||
|
||||
#include <functional>
|
||||
#include <CGAL/number_type_config.h>
|
||||
#include <CGAL/number_utils.h>
|
||||
|
||||
template <bool> class Interval_nt;
|
||||
#include <functional>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
// A number type converter usable as default, using the conversion operator.
|
||||
template <bool>
|
||||
class Interval_nt;
|
||||
|
||||
template <class NT>
|
||||
class Quotient;
|
||||
|
||||
// A number type converter usable as default, using the conversion operator.
|
||||
template < class NT1, class NT2 >
|
||||
struct NT_converter
|
||||
: public CGAL::cpp98::unary_function< NT1, NT2 >
|
||||
|
|
@ -38,6 +42,7 @@ struct NT_converter
|
|||
// - double to call to_double().
|
||||
// - Interval_nt<> to call to_interval().
|
||||
// - NT1 == NT2 to return a reference instead of copying.
|
||||
// - Quotient conversions
|
||||
|
||||
template < class NT1 >
|
||||
struct NT_converter < NT1, NT1 >
|
||||
|
|
@ -116,6 +121,29 @@ struct NT_converter < Interval_nt<b>, Interval_nt<b> >
|
|||
}
|
||||
};
|
||||
|
||||
template < class NT >
|
||||
struct NT_converter < Quotient<NT>, Quotient<NT> >
|
||||
: public CGAL::cpp98::unary_function< Quotient<NT>, Quotient<NT> >
|
||||
{
|
||||
const Quotient<NT>&
|
||||
operator()(const Quotient<NT> & q) const
|
||||
{
|
||||
return q;
|
||||
}
|
||||
};
|
||||
|
||||
template < class NT1, class NT2 >
|
||||
struct NT_converter < Quotient<NT1>, Quotient<NT2> >
|
||||
: public CGAL::cpp98::unary_function< Quotient<NT1>, Quotient<NT2> >
|
||||
{
|
||||
Quotient<NT2>
|
||||
operator()(const Quotient<NT1> & q) const
|
||||
{
|
||||
NT_converter < NT1, NT2 > nt;
|
||||
return Quotient<NT2>(nt(q.numerator()), nt(q.denominator()));
|
||||
}
|
||||
};
|
||||
|
||||
} //namespace CGAL
|
||||
|
||||
#endif // CGAL_NT_CONVERTER_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue