diff --git a/Bounding_volumes/test/Bounding_volumes/min_sphere_test.cpp b/Bounding_volumes/test/Bounding_volumes/min_sphere_test.cpp index 82b71269443..ff82ea1bdb0 100644 --- a/Bounding_volumes/test/Bounding_volumes/min_sphere_test.cpp +++ b/Bounding_volumes/test/Bounding_volumes/min_sphere_test.cpp @@ -33,10 +33,12 @@ #include #include #include -#include -#include #include #include +#include + +#include +#include using namespace CGAL; diff --git a/Cartesian_kernel/include/CGAL/Cartesian_converter.h b/Cartesian_kernel/include/CGAL/Cartesian_converter.h index 65a68c612fb..946dc51ce4b 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian_converter.h +++ b/Cartesian_kernel/include/CGAL/Cartesian_converter.h @@ -39,6 +39,8 @@ #include #include +#include + 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 > - class Converter> + class Converter /*= typename internal::Default_converter::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 + T + operator()(const T t, + typename std::enable_if::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_3 - operator()(const typename K1::Aff_transformation_3 &a) const + typename K2::Aff_transformation_2 + operator()(const typename K1::Aff_transformation_2& 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)); + 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 + { + typedef typename K2::Aff_transformation_3 Aff_transformation_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; diff --git a/Homogeneous_kernel/include/CGAL/Homogeneous_converter.h b/Homogeneous_kernel/include/CGAL/Homogeneous_converter.h index 601d9ac504f..22edf4e3e18 100644 --- a/Homogeneous_kernel/include/CGAL/Homogeneous_converter.h +++ b/Homogeneous_kernel/include/CGAL/Homogeneous_converter.h @@ -28,6 +28,9 @@ #include #include #include +#include + +#include 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 + T + operator()(const T t, + typename std::enable_if::value>::type* = nullptr) const + { + return t; } typename K2::Point_2 diff --git a/Kernel_23/test/Kernel_23/test_converter.cpp b/Kernel_23/test/Kernel_23/test_converter.cpp new file mode 100644 index 00000000000..8a94f9845cf --- /dev/null +++ b/Kernel_23/test/Kernel_23/test_converter.cpp @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include + +#include +#include + +#ifdef CGAL_USE_CORE +#include +#endif + +#include + +int main() +{ + using EPICK = CGAL::Exact_predicates_inexact_constructions_kernel; + using EPECK = CGAL::Exact_predicates_exact_constructions_kernel; + using SCLD = CGAL::Simple_cartesian; + using SCI = CGAL::Simple_cartesian >; + using SHI = CGAL::Simple_homogeneous >; + using NT_exact = CGAL::internal::Exact_field_selector::Type; + using SHD = CGAL::Simple_homogeneous; + using SHE = CGAL::Simple_homogeneous; + + CGAL::Cartesian_converter sci_to_epick; + CGAL::Cartesian_converter scld_to_epick; + CGAL::Cartesian_converter sci_to_epeck; + CGAL::Cartesian_converter epeck_to_epick; + CGAL::Homogeneous_converter shi_to_shd; + CGAL::Homogeneous_converter she_to_shd; + CGAL::Homogeneous_converter 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; + CGAL::Cartesian_converter 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 > qnte_to_qnte; + assert(qnte_to_qnte(2.) == CGAL::Quotient(2.)); + + std::cout << "Done" << std::endl; + + return EXIT_SUCCESS; +} diff --git a/Kernel_d/include/CGAL/Kernel_d/Cartesian_converter_d.h b/Kernel_d/include/CGAL/Kernel_d/Cartesian_converter_d.h index a136b3da81d..e38fea77163 100644 --- a/Kernel_d/include/CGAL/Kernel_d/Cartesian_converter_d.h +++ b/Kernel_d/include/CGAL/Kernel_d/Cartesian_converter_d.h @@ -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 + T + operator()(const T t, + typename std::enable_if::value>::type* = nullptr) const + { + return t; + } + std::vector operator()(const std::vector& 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 { diff --git a/Number_types/include/CGAL/NT_converter.h b/Number_types/include/CGAL/NT_converter.h index ac225f1e0cb..37f259abf80 100644 --- a/Number_types/include/CGAL/NT_converter.h +++ b/Number_types/include/CGAL/NT_converter.h @@ -13,16 +13,20 @@ #ifndef CGAL_NT_CONVERTER_H #define CGAL_NT_CONVERTER_H -#include #include #include -template class Interval_nt; +#include namespace CGAL { -// A number type converter usable as default, using the conversion operator. +template +class Interval_nt; +template +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, Interval_nt > } }; +template < class NT > +struct NT_converter < Quotient, Quotient > + : public CGAL::cpp98::unary_function< Quotient, Quotient > +{ + const Quotient& + operator()(const Quotient & q) const + { + return q; + } +}; + +template < class NT1, class NT2 > +struct NT_converter < Quotient, Quotient > + : public CGAL::cpp98::unary_function< Quotient, Quotient > +{ + Quotient + operator()(const Quotient & q) const + { + NT_converter < NT1, NT2 > nt; + return Quotient(nt(q.numerator()), nt(q.denominator())); + } +}; + } //namespace CGAL #endif // CGAL_NT_CONVERTER_H