From 82fe4c5f04f1ac89c72f102e457e64c50e0570c4 Mon Sep 17 00:00:00 2001 From: Michael Hemmer Date: Tue, 13 May 2008 08:42:27 +0000 Subject: [PATCH] added Interval_traits and test for intervals - boost::numeric::interval - CORE::BigFloat is considered as an Interval adapted Coercion_traits/Arithmetik_kernel --- Number_types/include/CGAL/Arithmetic_kernel.h | 26 ++- Number_types/include/CGAL/CORE_BigFloat.h | 4 + .../include/CGAL/CORE_coercion_traits.h | 122 +++++++--- Number_types/include/CGAL/Interval_traits.h | 204 ++++++++++++++++ .../include/CGAL/core_interval_support.h | 54 +++-- Number_types/include/CGAL/interval_support.h | 145 ++---------- Number_types/include/CGAL/leda_bigfloat.h | 3 + .../include/CGAL/leda_bigfloat_interval.h | 88 +++++++ .../include/CGAL/leda_coercion_traits.h | 2 +- .../include/CGAL/leda_interval_support.h | 130 +++++------ .../test/Number_types/CORE_BigFloat.cpp | 3 +- .../test/Number_types/Coercion_traits.cpp | 143 +++++++----- .../include/CGAL/Test/_test_interval.h | 221 ++++++++++++++++++ .../test/Number_types/interval_support.cpp | 8 +- .../Number_types/leda_bigfloat_interval.cpp | 31 +++ 15 files changed, 867 insertions(+), 317 deletions(-) create mode 100644 Number_types/include/CGAL/Interval_traits.h create mode 100644 Number_types/test/Number_types/include/CGAL/Test/_test_interval.h create mode 100644 Number_types/test/Number_types/leda_bigfloat_interval.cpp diff --git a/Number_types/include/CGAL/Arithmetic_kernel.h b/Number_types/include/CGAL/Arithmetic_kernel.h index dd991755907..4e222487502 100644 --- a/Number_types/include/CGAL/Arithmetic_kernel.h +++ b/Number_types/include/CGAL/Arithmetic_kernel.h @@ -59,11 +59,25 @@ CGAL_BEGIN_NAMESPACE +namespace CGALi { + +class Arithmetic_kernel_base{ +public: + typedef CGAL::Null_tag Integer; + typedef CGAL::Null_tag Rational; + typedef CGAL::Null_tag Field_with_sqrt; + typedef CGAL::Null_tag Field_with_kth_root; + typedef CGAL::Null_tag Field_with_root_of; + typedef CGAL::Null_tag Bigfloat; + typedef CGAL::Null_tag Bigfloat_interval; +}; + +} #ifdef CGAL_USE_LEDA /*! \ingroup CGAL_Arithmetic_kernel * \brief The LEDA set of exact number types */ -class LEDA_arithmetic_kernel { +class LEDA_arithmetic_kernel : public CGALi::Arithmetic_kernel_base { public: //! exact integers typedef leda_integer Integer; @@ -85,7 +99,7 @@ public: /*! \ingroup CGAL_Arithmetic_kernel * \brief The CORE set of exact number types */ -class CORE_arithmetic_kernel { +class CORE_arithmetic_kernel : public CGALi::Arithmetic_kernel_base { public: //! exact integers typedef CORE::BigInt Integer; @@ -96,7 +110,7 @@ public: //! exact root expressions, constructible from integers and rationals typedef CORE::Expr Field_with_sqrt; // undocumented - typedef CORE::BigFloat Bigfloat; + //typedef CORE::BigFloat Bigfloat; typedef CORE::BigFloat Bigfloat_interval; }; @@ -106,7 +120,7 @@ public: /*! \ingroup CGAL_Arithmetic_kernel * \brief The GMP set of exact number types */ -class GMP_arithmetic_kernel { +class GMP_arithmetic_kernel : public CGALi::Arithmetic_kernel_base { public: //! exact integers typedef CGAL::Gmpz Integer; @@ -116,6 +130,8 @@ public: typedef CGAL::Gmpq Rational; //! exact root expressions, constructible from integers and rationals typedef CGAL::Null_tag Field_with_sqrt; + typedef CGAL::Null_tag Field_with_kth_root; + typedef CGAL::Null_tag Field_with_root_of; }; #endif // CGAL_USE_GMP @@ -123,7 +139,7 @@ public: /*! \ingroup CGAL_Arithmetic_kernel * \brief The GMP set of exact number types */ -class GMPXX_arithmetic_kernel { +class GMPXX_arithmetic_kernel : public CGALi::Arithmetic_kernel_base { public: //! exact integers typedef mpz_class Integer; diff --git a/Number_types/include/CGAL/CORE_BigFloat.h b/Number_types/include/CGAL/CORE_BigFloat.h index f458e74bd88..828d6e159fb 100644 --- a/Number_types/include/CGAL/CORE_BigFloat.h +++ b/Number_types/include/CGAL/CORE_BigFloat.h @@ -143,6 +143,8 @@ template <> class Real_embeddable_traits< CORE::BigFloat > const Type& y ) const { return (Comparison_result) sign( (x-y).sign()); } + CGAL_IMPLICIT_INTEROPERABLE_BINARY_OPERATOR_WITH_RT( Type, + Comparison_result ); }; class To_double @@ -179,6 +181,8 @@ template <> class Real_embeddable_traits< CORE::BigFloat > }; }; + + CGAL_END_NAMESPACE //since types are included by CORE_coercion_traits.h: diff --git a/Number_types/include/CGAL/CORE_coercion_traits.h b/Number_types/include/CGAL/CORE_coercion_traits.h index 9a65c94ab2e..1fb9392675d 100644 --- a/Number_types/include/CGAL/CORE_coercion_traits.h +++ b/Number_types/include/CGAL/CORE_coercion_traits.h @@ -38,14 +38,6 @@ CGAL_BEGIN_NAMESPACE //CORE internal coercions: - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigInt,::CORE::BigFloat) - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigInt,::CORE::BigRat) - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigInt,::CORE::Expr) - - // CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigFloat,::CORE::BigRat) - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigFloat,::CORE::Expr) - - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigRat,::CORE::Expr) // The following definitions reflect the interaction of the CORE number types // with the built in types, @@ -56,27 +48,103 @@ CGAL_BEGIN_NAMESPACE // CORE BigRat: - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,::CORE::BigRat) - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,::CORE::BigRat) - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,::CORE::BigRat) - - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::CORE::BigRat) - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::CORE::BigRat) - - -// CORE BigFloat: : - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,::CORE::BigFloat) - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,::CORE::BigFloat) - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,::CORE::BigFloat) - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::CORE::BigFloat) - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::CORE::BigFloat) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,::CORE::BigRat) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,::CORE::BigRat) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,::CORE::BigRat) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::CORE::BigRat) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::CORE::BigRat) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigInt,::CORE::BigRat) // CORE Expr: - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,::CORE::Expr) - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,::CORE::Expr) - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,::CORE::Expr) - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::CORE::Expr) - CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::CORE::Expr) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,::CORE::Expr) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,::CORE::Expr) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,::CORE::Expr) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::CORE::Expr) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::CORE::Expr) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigInt,::CORE::Expr) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::CORE::BigRat,::CORE::Expr) + + + +// NOTE that CORE::BigFloat counts as an interval ! + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,::CORE::BigFloat) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,::CORE::BigFloat) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,::CORE::BigFloat) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::CORE::BigFloat) + CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::CORE::BigFloat); + +template <> +struct Coercion_traits{ + typedef Tag_true Are_explicit_interoperable; + typedef Tag_false Are_implicit_interoperable; + typedef CORE::BigFloat Type; + + struct Cast{ + typedef Type result_type; + Type operator()(const CORE::BigFloat& x) const { return x;} + Type operator()(const ::CORE::BigInt x) const { + CORE::BigFloat result; + result.approx(x,CORE::defRelPrec.toLong(),1024); + // Do not use MakeFloorExact as it changes the Bigfloat + CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()-result.err(),0,result.exp())) <= x ); + CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()+result.err(),0,result.exp())) >= x ); + return result; + } + }; +}; + +template <> +struct Coercion_traits{ + typedef Tag_true Are_explicit_interoperable; + typedef Tag_false Are_implicit_interoperable; + typedef CORE::BigFloat Type; + + struct Cast{ + typedef Type result_type; + Type operator()(const CORE::BigFloat& x) const { return x;} + Type operator()(const ::CORE::BigRat x) const { + + CORE::BigFloat result(x,CORE::defRelPrec.toLong(),1024); + // Do not use MakeFloorExact as it changes the Bigfloat + CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()-result.err(),0,result.exp())) <= x ); + CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()+result.err(),0,result.exp())) >= x ); + return result; + } + }; +}; + +template <> +struct Coercion_traits{ + typedef Tag_true Are_explicit_interoperable; + typedef Tag_false Are_implicit_interoperable; + typedef CORE::BigFloat Type; + + struct Cast{ + typedef Type result_type; + Type operator()(const CORE::BigFloat& x) const { return x;} + Type operator()(const ::CORE::Expr x) const { + CORE::BigFloat result(x, CORE::defRelPrec.toLong(),1024); + // Do not use MakeFloorExact as it changes the Bigfloat + CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()-result.err(),0,result.exp())) <= x ); + CGAL_postcondition( ::CORE::BigRat(::CORE::BigFloat(result.m()+result.err(),0,result.exp())) >= x ); + return result; + } + }; +}; + +template <> struct Coercion_traits< ::CORE::BigInt, CORE::BigFloat > + :public Coercion_traits< CORE::BigFloat , ::CORE::BigInt >{}; + +template <> struct Coercion_traits< ::CORE::BigRat, CORE::BigFloat > + :public Coercion_traits< CORE::BigFloat , ::CORE::BigRat >{}; + +template <> struct Coercion_traits< ::CORE::Expr, CORE::BigFloat > + :public Coercion_traits< CORE::BigFloat , ::CORE::Expr>{}; + + + + + // not provieded by CORE // Note that this is not symmetric to LEDA diff --git a/Number_types/include/CGAL/Interval_traits.h b/Number_types/include/CGAL/Interval_traits.h new file mode 100644 index 00000000000..fa9332448d2 --- /dev/null +++ b/Number_types/include/CGAL/Interval_traits.h @@ -0,0 +1,204 @@ +// TODO: Add licence +// +// 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) : Michael Hemmer +// +// ============================================================================ + + +/*! \file CGAL/Interval_traits.h + This is experimental +*/ + + +/* bounds-related Interval functions */ +// template T lower(const Interval& x); +// template T upper(const Interval& x); +// template T width(const Interval& x); +// template T median(const Interval& x); +// template T norm(const Interval& x); + +/* bounds-related Interval functions */ +//// template bool empty(const Interval& b); +// template bool singleton(const Interval& x); +// template bool zero_in(const Interval& b); +// template bool in(const T& r, const Interval& b); +// template bool equal(const Interval& x, const Interval& y); +// template bool overlap(const Interval& x, const Interval& y); +// template bool subset(const Interval& a, const Interval& b); +// template bool proper_subset(const Interval& a, const Interval& b); + +/* set manipulation interval functions */ +// template Interval intersection(const Interval& x, const Interval& y); +// template Interval hull(const Interval& x, const Interval& y); + + +#ifndef CGAL_INTERVAL_TRAITS_H +#define CGAL_INTERVAL_TRAITS_H + +#include +#include + +CGAL_BEGIN_NAMESPACE + +namespace CGALi{ + +template struct Interval_traits_base{ + + typedef Interval_traits_base Self; + typedef T Interval; + typedef CGAL::Null_functor Boundary; + typedef CGAL::Tag_false Is_interval; + typedef CGAL::Tag_false With_empty_interval; + + typedef CGAL::Null_functor Lower; + typedef CGAL::Null_functor Upper; + typedef CGAL::Null_functor Width; + typedef CGAL::Null_functor Median; + typedef CGAL::Null_functor Norm; + typedef CGAL::Null_functor Empty; + typedef CGAL::Null_functor Singleton; + typedef CGAL::Null_functor In; + typedef CGAL::Null_functor Zero_in; + typedef CGAL::Null_functor Equal; + typedef CGAL::Null_functor Overlap; + typedef CGAL::Null_functor Subset; + typedef CGAL::Null_functor Proper_Subset; + typedef CGAL::Null_functor Intersection; + typedef CGAL::Null_functor Hull; +}; +} + +template struct Interval_traits; +class Exception_intersection_is_empty{}; + +// function returning type Boundary +template inline +typename Interval_traits::Boundary +lower(const Interval& interval) { + typename Interval_traits::Lower lower; + return lower(interval); +} + +template inline +typename Interval_traits::Boundary +upper(const Interval& interval) { + typename Interval_traits::Upper upper; + return upper(interval); +} + +template inline +typename Interval_traits::Boundary +width(Interval interval) { + typename Interval_traits::Width width; + return width(interval); +} + +template inline +typename Interval_traits::Boundary +median(Interval interval) { + typename Interval_traits::Median median; + return median(interval); +} + +template inline +typename Interval_traits::Boundary +norm(Interval interval) { + typename Interval_traits::Norm norm; + return norm(interval); +} + + +// functions returning bool + +template inline +typename Interval_traits::Empty::result_type +empty(Interval interval) { + typename Interval_traits::Empty empty; + return empty(interval); +} + +template inline +typename Interval_traits::Singleton::result_type +singleton(Interval interval) { + typename Interval_traits::Singleton singleton; + return singleton(interval); +} + +template inline +typename Interval_traits::In::result_type +in(typename Interval_traits::Boundary x, Interval interval) { + typename Interval_traits::In in; + return in(x,interval); +} + +template inline +typename Interval_traits::Zero_in::result_type +zero_in(Interval interval) { + typename Interval_traits::Zero_in zero_in; + return zero_in(interval); +} + +// This ones should be removed, since even boost_1_35_0 has changed to zero_in +template inline +typename Interval_traits::Zero_in::result_type +in_zero(Interval interval) { + typename Interval_traits::Zero_in zero_in; + return zero_in(interval); +} + +template inline +typename Interval_traits::Equal::result_type +equal(Interval interval1,Interval interval2) { + typename Interval_traits::Equal equal; + return equal(interval1,interval2); +} + +template inline +typename Interval_traits::Overlap::result_type +overlap(Interval interval1, Interval interval2) { + typename Interval_traits::Overlap overlap; + return overlap(interval1, interval2); +} + +template inline +typename Interval_traits::Subset::result_type +subset(Interval interval1, Interval interval2) { + typename Interval_traits::Subset subset; + return subset(interval1, interval2); +} + +template inline +typename Interval_traits::Proper_subset::result_type +proper_subset(Interval interval1, Interval interval2) { + typename Interval_traits::Proper_subset proper_subset; + return proper_subset(interval1, interval2); +} + + +// Set operations, functions returing Interval +template inline +typename Interval_traits::Intersection::result_type +intersection(Interval interval1, Interval interval2) { + typename Interval_traits::Intersection intersection; + return intersection(interval1, interval2); +} + +template inline +typename Interval_traits::Hull::result_type +hull(Interval interval1, Interval interval2) { + typename Interval_traits::Hull hull; + return hull(interval1, interval2); +} + + + +CGAL_END_NAMESPACE + +#endif // CGAL_INTERVAL_TRAITS_H diff --git a/Number_types/include/CGAL/core_interval_support.h b/Number_types/include/CGAL/core_interval_support.h index 825182f582a..974f7fc8f0c 100644 --- a/Number_types/include/CGAL/core_interval_support.h +++ b/Number_types/include/CGAL/core_interval_support.h @@ -30,11 +30,14 @@ CGAL_BEGIN_NAMESPACE template<> -class Interval_traits { +class Interval_traits + : public CGALi::Interval_traits_base{ public: + + typedef Interval_traits Self; typedef CORE::BigFloat Interval; typedef CORE::BigFloat Boundary; - typedef Interval_traits Self; + typedef CGAL::Tag_true Is_interval; struct Lower :public Unary_function{ Boundary operator() ( Interval x ) const { @@ -176,12 +179,7 @@ public: } }; - struct Singleton { - // type for the \c AdaptableUnaryFunction concept. - typedef Interval argument_type; - // type for the \c AdaptableUnaryFunction concept. - typedef bool result_type; - + struct Singleton :public Unary_function { bool operator() ( Interval x ) const { return (x.err() == 0); } @@ -203,27 +201,36 @@ template long get_significant_bits(BFI bfi); CORE::BigFloat inline round(const CORE::BigFloat& x, long rel_prec = CORE::defRelPrec.toLong() ){CGAL_postcondition(rel_prec >= 0); + + + // since there is not rel prec defined if Zero_in(x) if (x.isZeroIn()) return x; if (CGAL::get_significant_bits(x) <= rel_prec) return x; +// if 1 + BigFloat xr; + xr.approx(x,rel_prec,1024); typedef CORE::BigFloat BF; - typedef CORE::BigFloat BFI; - typedef CORE::BigInt Integer; - BF xr; +// else +// typedef CORE::BigFloat BF; +// typedef CORE::BigFloat BFI; +// typedef CORE::BigInt Integer; +// BF xr; - CORE::BigInt m = x.m(); - long err = x.err(); - long exp = x.exp(); +// CORE::BigInt m = x.m(); +// long err = x.err(); +// long exp = x.exp(); - long shift = ::CORE::bitLength(m) - rel_prec - 1; - if( shift > 0 ){ Integer new_m = m >> shift ; - if(err == 0){ xr = BF(new_m,1,0)*BF::exp2(exp*14+shift); - }else{ xr = BF(new_m,2,0)*BF::exp2(exp*14+shift); - } - }else{ // noting to do - xr = x; - } +// long shift = ::CORE::bitLength(m) - rel_prec - 1; +// if( shift > 0 ){ Integer new_m = m >> shift ; +// if(err == 0){ xr = BF(new_m,1,0)*BF::exp2(exp*14+shift); +// }else{ xr = BF(new_m,2,0)*BF::exp2(exp*14+shift); +// } +// }else{ // noting to do +// xr = x; +// } +// endif CGAL_postcondition(CGAL::abs(CGAL::get_significant_bits(xr) - rel_prec) <= 1); CGAL_postcondition(BF(xr.m()-xr.err(),0,xr.exp()) <= BF(x.m()-x.err(),0,x.exp())); @@ -232,6 +239,7 @@ round(const CORE::BigFloat& x, long rel_prec = CORE::defRelPrec.toLong() ){CGAL_ } template<> class Bigfloat_interval_traits +:public Interval_traits { public: typedef CORE::BigFloat NT; @@ -280,8 +288,6 @@ public: }; struct Convert_to_bfi { - - typedef NT result_type; NT operator() (const ::CORE::Expr& x){ diff --git a/Number_types/include/CGAL/interval_support.h b/Number_types/include/CGAL/interval_support.h index e59548082f7..d90ab595212 100644 --- a/Number_types/include/CGAL/interval_support.h +++ b/Number_types/include/CGAL/interval_support.h @@ -43,135 +43,11 @@ #define CGAL_INTERVAL_SUPPORT_H #include +#include CGAL_BEGIN_NAMESPACE -template class Interval_traits; -class Exception_intersection_is_empty{}; - -// function returning type Boundary -template inline -typename Interval_traits::Boundary -lower(const Interval& interval) { - typename Interval_traits::Lower lower; - return lower(interval); -} - -template inline -typename Interval_traits::Boundary -upper(const Interval& interval) { - typename Interval_traits::Upper upper; - return upper(interval); -} - -template inline -typename Interval_traits::Boundary -width(Interval interval) { - typename Interval_traits::Width width; - return width(interval); -} - -template inline -typename Interval_traits::Boundary -median(Interval interval) { - typename Interval_traits::Median median; - return median(interval); -} - -template inline -typename Interval_traits::Boundary -norm(Interval interval) { - typename Interval_traits::Norm norm; - return norm(interval); -} - - -// functions returning bool - -template inline -typename Interval_traits::Empty::result_type -empty(Interval interval) { - typename Interval_traits::Empty empty; - return empty(interval); -} - -template inline -typename Interval_traits::Singleton::result_type -singleton(Interval interval) { - typename Interval_traits::Singleton singleton; - return singleton(interval); -} - -template inline -typename Interval_traits::In::result_type -in(typename Interval_traits::Boundary x, Interval interval) { - typename Interval_traits::In in; - return in(x,interval); -} - -template inline -typename Interval_traits::Zero_in::result_type -zero_in(Interval interval) { - typename Interval_traits::Zero_in zero_in; - return zero_in(interval); -} - -// This ones should be removed, since even boost_1_35_0 has changed to zero_in -template inline -typename Interval_traits::Zero_in::result_type -in_zero(Interval interval) { - typename Interval_traits::Zero_in zero_in; - return zero_in(interval); -} - -template inline -typename Interval_traits::Equal::result_type -equal(Interval interval1,Interval interval2) { - typename Interval_traits::Equal equal; - return equal(interval1,interval2); -} - -template inline -typename Interval_traits::Overlap::result_type -overlap(Interval interval1, Interval interval2) { - typename Interval_traits::Overlap overlap; - return overlap(interval1, interval2); -} - -template inline -typename Interval_traits::Subset::result_type -subset(Interval interval1, Interval interval2) { - typename Interval_traits::Subset subset; - return subset(interval1, interval2); -} - -template inline -typename Interval_traits::Proper_subset::result_type -proper_subset(Interval interval1, Interval interval2) { - typename Interval_traits::Proper_Subset proper_subset; - return proper_subset(interval1, interval2); -} - - -// Set operations, functions returing Interval -template inline -typename Interval_traits::Intersection::result_type -intersection(Interval interval1, Interval interval2) { - typename Interval_traits::Intersection intersection; - return intersection(interval1, interval2); -} - -template inline -typename Interval_traits::Hull::result_type -hull(Interval interval1, Interval interval2) { - typename Interval_traits::Hull hull; - return hull(interval1, interval2); -} - - - - -// This will go intro bigfloat_interval_support.h +// This will go into bigfloat_interval_support.h //////////////////////////////// BFI Traits @@ -184,12 +60,12 @@ template inline long get_significant_bits(BFI bfi) { return get_significant_bits(bfi); } -template inline long set_precision(BFI bfi,long prec) { +template inline long set_precision(BFI,long prec) { typename Bigfloat_interval_traits::Set_precision set_precision; return set_precision(prec); } -template inline long get_precision(BFI bfi) { +template inline long get_precision(BFI) { typename Bigfloat_interval_traits::Get_precision get_precision; return get_precision(); } @@ -200,10 +76,15 @@ template struct Get_arithmetic_kernel; template typename Get_arithmetic_kernel::Arithmetic_kernel::Bigfloat_interval convert_to_bfi(const NTX& x) { - typedef typename Get_arithmetic_kernel::Arithmetic_kernel AT; - typedef typename AT::Bigfloat_interval BFI; - typename Bigfloat_interval_traits::Convert_to_bfi convert_to_bfi; - return convert_to_bfi(x); + typedef typename Get_arithmetic_kernel::Arithmetic_kernel AK; + typedef typename AK::Bigfloat_interval BFI; + typedef CGAL::Coercion_traits CT; + return typename CT::Cast()(x); + + // typedef typename Get_arithmetic_kernel::Arithmetic_kernel AT; + // typedef typename AT::Bigfloat_interval BFI; + // typename Bigfloat_interval_traits::Convert_to_bfi convert_to_bfi; + // return convert_to_bfi(x); } // TODO: move this to sqrt_extension ? diff --git a/Number_types/include/CGAL/leda_bigfloat.h b/Number_types/include/CGAL/leda_bigfloat.h index 423d85e1926..03b970ffb4b 100644 --- a/Number_types/include/CGAL/leda_bigfloat.h +++ b/Number_types/include/CGAL/leda_bigfloat.h @@ -101,6 +101,9 @@ template <> class Real_embeddable_traits< leda_bigfloat > const Type& y ) const { return (Comparison_result) CGAL_LEDA_SCOPE::compare( x, y ); } + + CGAL_IMPLICIT_INTEROPERABLE_BINARY_OPERATOR_WITH_RT( Type, + Comparison_result ); }; class To_double diff --git a/Number_types/include/CGAL/leda_bigfloat_interval.h b/Number_types/include/CGAL/leda_bigfloat_interval.h index 92d000f2600..e2f6781fac0 100644 --- a/Number_types/include/CGAL/leda_bigfloat_interval.h +++ b/Number_types/include/CGAL/leda_bigfloat_interval.h @@ -17,6 +17,10 @@ #include #endif +#include +#include +#include +#include #include CGAL_BEGIN_NAMESPACE @@ -192,6 +196,90 @@ public: }; +// Coercion traits: +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,leda_bigfloat_interval); +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,leda_bigfloat_interval); +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,leda_bigfloat_interval); +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,leda_bigfloat_interval); +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,leda_bigfloat_interval); +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(::leda::bigfloat ,leda_bigfloat_interval); + +template <> +struct Coercion_traits< leda_bigfloat_interval , ::leda::integer >{ + typedef Tag_true Are_explicit_interoperable; + typedef Tag_false Are_implicit_interoperable; + + typedef leda_bigfloat_interval Type; + + struct Cast{ + typedef Type result_type; + Type operator()(const leda_bigfloat_interval& x) const { return x;} + Type operator()(const ::leda::integer x) const { + leda::bigfloat tmp(x); + leda_bigfloat_interval result( + round(tmp,leda::bigfloat::get_precision(),leda::TO_N_INF), + round(tmp,leda::bigfloat::get_precision(),leda::TO_P_INF)); + CGAL_postcondition( result.lower() <= x ); + CGAL_postcondition( result.upper() >= x ); + return result; + } + }; +}; + +template <> +struct Coercion_traits< leda_bigfloat_interval , ::leda::rational >{ + typedef Tag_true Are_explicit_interoperable; + typedef Tag_false Are_implicit_interoperable; + + typedef leda_bigfloat_interval Type; + + struct Cast{ + typedef Type result_type; + Type operator()(const leda_bigfloat_interval& x) const { return x;} + Type operator()(const ::leda::rational x) const { + leda_bigfloat_interval result ( + leda_bigfloat::from_rational(x, ::leda::bigfloat::get_precision(), leda::TO_N_INF), + leda_bigfloat::from_rational(x, ::leda::bigfloat::get_precision(), leda::TO_P_INF)); + CGAL_postcondition( result.lower() <= x ); + CGAL_postcondition( result.upper() >= x ); + return result; + } + }; +}; + +template <> +struct Coercion_traits< leda_bigfloat_interval , ::leda::real >{ + typedef Tag_true Are_explicit_interoperable; + typedef Tag_false Are_implicit_interoperable; + + typedef leda_bigfloat_interval Type; + + struct Cast{ + typedef Type result_type; + Type operator()(const leda_bigfloat_interval& x) const { return x;} + Type operator()(const ::leda::real x) const { + long current_prec = ::leda::bigfloat::get_precision(); + x.guarantee_relative_error(current_prec); + leda_bigfloat_interval result(x.get_lower_bound(), x.get_upper_bound()); + CGAL_postcondition( result.lower() <= x ); + CGAL_postcondition( result.upper() >= x ); + return result; + } + }; +}; + +template <> struct Coercion_traits< ::leda::integer, leda_bigfloat_interval > + :public Coercion_traits< leda_bigfloat_interval , ::leda::integer >{}; + +template <> struct Coercion_traits< ::leda::rational, leda_bigfloat_interval > + :public Coercion_traits< leda_bigfloat_interval , ::leda::rational >{}; + +template <> struct Coercion_traits< ::leda::real, leda_bigfloat_interval > + :public Coercion_traits< leda_bigfloat_interval , ::leda::real>{}; + + + + CGAL_END_NAMESPACE #endif // CGAL_USE_LEDA #endif // CGAL_LEDA_BIGFLOAT_INTERVAL_H diff --git a/Number_types/include/CGAL/leda_coercion_traits.h b/Number_types/include/CGAL/leda_coercion_traits.h index 4dd722d677b..0b0e646af15 100644 --- a/Number_types/include/CGAL/leda_coercion_traits.h +++ b/Number_types/include/CGAL/leda_coercion_traits.h @@ -43,7 +43,6 @@ #include #endif - CGAL_BEGIN_NAMESPACE @@ -87,6 +86,7 @@ CGAL_BEGIN_NAMESPACE CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,::leda::real) CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,::leda::real) + //not provided by LEDA //Note that this is not symmetric to CORE //CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long long,::leda::integer); diff --git a/Number_types/include/CGAL/leda_interval_support.h b/Number_types/include/CGAL/leda_interval_support.h index 7ba642f2559..81c0e7c982e 100644 --- a/Number_types/include/CGAL/leda_interval_support.h +++ b/Number_types/include/CGAL/leda_interval_support.h @@ -34,7 +34,8 @@ public: typedef Interval_traits Self; typedef leda_bigfloat_interval Interval; typedef leda::bigfloat Boundary; - + typedef CGAL::Tag_true Is_interval; + typedef CGAL::Tag_true With_empty_interval; struct Construct :public Binary_function{ Interval operator()( const Boundary& l,const Boundary& r) const { @@ -129,9 +130,7 @@ public: struct Intersection :public Binary_function{ Interval operator()( const Interval& a, const Interval& b ) const { - Interval r = ::boost::numeric::intersect(a,b); - if (::boost::numeric::empty(r)) - throw Exception_intersection_is_empty(); + Interval r = ::boost::numeric::intersect(a,b); return r; } }; @@ -186,78 +185,79 @@ public: } }; - struct Convert_to_bfi { +/* + struct Convert_to_bfi { + + typedef NT result_type; - typedef NT result_type; - - NT operator()( const leda::real& x ) { - long current_prec = ::leda::bigfloat::get_precision(); - //x.improve_approximation_to(current_prec); - x.guarantee_relative_error(current_prec); + NT operator()( const leda::real& x ) { + long current_prec = ::leda::bigfloat::get_precision(); + //x.improve_approximation_to(current_prec); + x.guarantee_relative_error(current_prec); - leda::bigfloat bnum = x.to_bigfloat(); - leda::bigfloat berr = x.get_bigfloat_error(); + leda::bigfloat bnum = x.to_bigfloat(); + leda::bigfloat berr = x.get_bigfloat_error(); - leda::bigfloat low - = leda::sub(bnum,berr,current_prec,LEDA::TO_N_INF); - leda::bigfloat upp - = leda::add(bnum,berr,current_prec,LEDA::TO_P_INF); - leda_bigfloat_interval bfi(low,upp) ; + leda::bigfloat low + = leda::sub(bnum,berr,current_prec,LEDA::TO_N_INF); + leda::bigfloat upp + = leda::add(bnum,berr,current_prec,LEDA::TO_P_INF); + leda_bigfloat_interval bfi(low,upp) ; - // std::cout <<"x: "<< x << std::endl; - // std::cout <<"bfi.lower(): "<< bfi.lower() << std::endl; - // std::cout <<"bfi.upper(): "<< bfi.upper() << std::endl; + // std::cout <<"x: "<< x << std::endl; + // std::cout <<"bfi.lower(): "<< bfi.lower() << std::endl; + // std::cout <<"bfi.upper(): "<< bfi.upper() << std::endl; - CGAL_postcondition( bfi.lower() <= x ); - CGAL_postcondition( bfi.upper() >= x ); + CGAL_postcondition( bfi.lower() <= x ); + CGAL_postcondition( bfi.upper() >= x ); - return bfi; - } + return bfi; + } - NT operator()(const ::leda::integer& x) { - long current_prec = ::leda::bigfloat::get_precision(); - leda_bigfloat_interval bfi; - long length = x.length(); + NT operator()(const ::leda::integer& x) { + long current_prec = ::leda::bigfloat::get_precision(); + leda_bigfloat_interval bfi; + long length = x.length(); - if(length > current_prec) { - ::leda::integer significant - = CGAL::abs(x) >> (length - current_prec); - ::leda::bigfloat lower,upper; - if(x > 0){ - lower = ::leda::bigfloat(significant,length - current_prec); - upper = ::leda::bigfloat(significant+1,length - current_prec); - }else{ - lower - = -::leda::bigfloat(significant+1,length - current_prec); - upper - = -::leda::bigfloat(significant,length - current_prec); - } - bfi = leda_bigfloat_interval(lower,upper); - }else{ - ::leda::bigfloat bf(x); - bfi = leda_bigfloat_interval(bf,bf); - } - CGAL_postcondition( bfi.lower() <= x ); - CGAL_postcondition( bfi.upper() >= x ); - return bfi; - } + if(length > current_prec) { + ::leda::integer significant + = CGAL::abs(x) >> (length - current_prec); + ::leda::bigfloat lower,upper; + if(x > 0){ + lower = ::leda::bigfloat(significant,length - current_prec); + upper = ::leda::bigfloat(significant+1,length - current_prec); + }else{ + lower + = -::leda::bigfloat(significant+1,length - current_prec); + upper + = -::leda::bigfloat(significant,length - current_prec); + } + bfi = leda_bigfloat_interval(lower,upper); + }else{ + ::leda::bigfloat bf(x); + bfi = leda_bigfloat_interval(bf,bf); + } + CGAL_postcondition( bfi.lower() <= x ); + CGAL_postcondition( bfi.upper() >= x ); + return bfi; + } - NT operator()(const ::leda::rational& x) { - long old_prec = ::leda::bigfloat::get_precision(); - ::leda::bigfloat::set_precision(old_prec*2); - Bigfloat_interval_traits::Convert_to_bfi convert_to_bfi; - leda_bigfloat_interval num = convert_to_bfi(x.numerator()); - leda_bigfloat_interval den = convert_to_bfi(x.denominator()); - ::leda::bigfloat::set_precision(old_prec); - leda_bigfloat_interval bfi = num/den; - CGAL_postcondition( bfi.lower() <= x ); - CGAL_postcondition( bfi.upper() >= x ); - return bfi; - } - - }; + NT operator()(const ::leda::rational& x) { + long old_prec = ::leda::bigfloat::get_precision(); + ::leda::bigfloat::set_precision(old_prec*2); + Bigfloat_interval_traits::Convert_to_bfi convert_to_bfi; + leda_bigfloat_interval num = convert_to_bfi(x.numerator()); + leda_bigfloat_interval den = convert_to_bfi(x.denominator()); + ::leda::bigfloat::set_precision(old_prec); + leda_bigfloat_interval bfi = num/den; + CGAL_postcondition( bfi.lower() <= x ); + CGAL_postcondition( bfi.upper() >= x ); + return bfi; + } + }; +*/ }; diff --git a/Number_types/test/Number_types/CORE_BigFloat.cpp b/Number_types/test/Number_types/CORE_BigFloat.cpp index ad30bd09913..aa8a9498080 100644 --- a/Number_types/test/Number_types/CORE_BigFloat.cpp +++ b/Number_types/test/Number_types/CORE_BigFloat.cpp @@ -6,6 +6,7 @@ #include #include #include +#include int main() { typedef CORE::BigFloat NT; @@ -22,7 +23,7 @@ int main() { CGAL::test_algebraic_structure(NT(-4),NT(-6),NT(-15)); CGAL::test_real_embeddable(); - + CGAL::test_interval(); return 0; } diff --git a/Number_types/test/Number_types/Coercion_traits.cpp b/Number_types/test/Number_types/Coercion_traits.cpp index d1aa57aca0d..d2aed613913 100644 --- a/Number_types/test/Number_types/Coercion_traits.cpp +++ b/Number_types/test/Number_types/Coercion_traits.cpp @@ -32,66 +32,91 @@ typedef CGAL::Interval_nt Interval; -template -void AT_coercion_test_at_int(){ - typedef typename AT::Integer Integer; - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); -} +void test_coercion_from_to(CGAL::Null_tag, CGAL::Null_tag){}; +template void test_coercion_from_to(A, CGAL::Null_tag){}; +template void test_coercion_from_to(CGAL::Null_tag, B){}; +template void test_coercion_from_to(A, B){ + CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); +}; template -void AT_coercion_test_at_bf(){ - AT_coercion_test_at_int(); - - typedef typename AT::Integer Integer; - typedef typename AT::Exact_float_number Bigfloat; - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); -} - - - -template -void AT_coercion_test_at_rat(){ - AT_coercion_test_at_bf();; - typedef typename AT::Integer Integer; - typedef typename AT::Exact_float_number Bigfloat; - typedef typename AT::Rational Rational; - - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); -} - -template -void AT_coercion_test_at_fws(){ - AT_coercion_test_at_rat(); +void check_type_coercion_at(){ + typedef typename AT::Integer Integer; + typedef typename AT::Rational Rational; + typedef typename AT::Field_with_sqrt Field_with_sqrt; + typedef typename AT::Field_with_kth_root Field_with_kth_root; + typedef typename AT::Field_with_root_of Field_with_root_of; + typedef typename AT::Bigfloat Bigfloat; + typedef typename AT::Bigfloat_interval Bigfloat_interval; - typedef typename AT::Integer Integer; - typedef typename AT::Exact_float_number Bigfloat; - typedef typename AT::Rational Rational; - typedef typename AT::Field_with_sqrt Real; - - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); + test_coercion_from_to(int(),Integer()); + test_coercion_from_to(short(),Integer()); + test_coercion_from_to(Integer(),Integer()); + + test_coercion_from_to(int(),Rational()); + test_coercion_from_to(short(),Rational()); + test_coercion_from_to(float(),Rational()); + test_coercion_from_to(double(),Rational()); + test_coercion_from_to(Integer(),Rational()); + test_coercion_from_to(Bigfloat(),Rational()); + test_coercion_from_to(Rational(),Rational()); + + test_coercion_from_to(int(),Field_with_sqrt()); + test_coercion_from_to(short(),Field_with_sqrt()); + test_coercion_from_to(float(),Field_with_sqrt()); + test_coercion_from_to(double(),Field_with_sqrt()); + test_coercion_from_to(Integer(),Field_with_sqrt()); + test_coercion_from_to(Bigfloat(),Field_with_sqrt()); + test_coercion_from_to(Rational(),Field_with_sqrt()); + test_coercion_from_to(Field_with_sqrt(),Field_with_sqrt()); + + test_coercion_from_to(int(),Field_with_kth_root()); + test_coercion_from_to(short(),Field_with_kth_root()); + test_coercion_from_to(float(),Field_with_kth_root()); + test_coercion_from_to(double(),Field_with_kth_root()); + test_coercion_from_to(Integer(),Field_with_kth_root()); + test_coercion_from_to(Bigfloat(),Field_with_kth_root()); + test_coercion_from_to(Rational(),Field_with_kth_root()); + test_coercion_from_to(Field_with_sqrt(),Field_with_kth_root()); + test_coercion_from_to(Field_with_kth_root(),Field_with_kth_root()); + + + test_coercion_from_to(int(),Field_with_root_of()); + test_coercion_from_to(short(),Field_with_root_of()); + test_coercion_from_to(float(),Field_with_root_of()); + test_coercion_from_to(double(),Field_with_root_of()); + test_coercion_from_to(Integer(),Field_with_root_of()); + test_coercion_from_to(Bigfloat(),Field_with_root_of()); + test_coercion_from_to(Rational(),Field_with_root_of()); + test_coercion_from_to(Field_with_sqrt(),Field_with_root_of()); + test_coercion_from_to(Field_with_kth_root(),Field_with_root_of()); + test_coercion_from_to(Field_with_root_of(),Field_with_root_of()); + + + test_coercion_from_to(int(),Bigfloat()); + test_coercion_from_to(short(),Bigfloat()); + test_coercion_from_to(float(),Bigfloat()); + test_coercion_from_to(double(),Bigfloat()); + test_coercion_from_to(Integer(),Bigfloat()); + test_coercion_from_to(Bigfloat(),Bigfloat()); + + + test_coercion_from_to(int(),Bigfloat_interval()); + test_coercion_from_to(short(),Bigfloat_interval()); + test_coercion_from_to(float(),Bigfloat_interval()); + test_coercion_from_to(double(),Bigfloat_interval()); + test_coercion_from_to(Integer(),Bigfloat_interval()); + test_coercion_from_to(Bigfloat(),Bigfloat_interval()); + test_coercion_from_to(Rational(),Bigfloat_interval()); + test_coercion_from_to(Field_with_sqrt(),Bigfloat_interval()); + test_coercion_from_to(Field_with_kth_root(),Bigfloat_interval()); + test_coercion_from_to(Field_with_root_of(),Bigfloat_interval()); + test_coercion_from_to(Bigfloat_interval(),Bigfloat_interval()); + } + template void AT_coercion_test_for_cgal_types_int(){ typedef typename AT::Integer Integer; @@ -376,7 +401,6 @@ int main(){ CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); - CGAL::INTERN_COERCION_TRAITS::direct_coercion_from_to_test(); @@ -415,15 +439,18 @@ int main(){ #endif // CGAL_HAVE_DEFAULT_ARITHMETIC_KERNEL #ifdef CGAL_USE_LEDA - AT_coercion_test_at_fws(); + check_type_coercion_at(); + AT_coercion_test_for_cgal_types_fws(); #endif // CGAL_USE_LEDA #ifdef CGAL_USE_CORE - AT_coercion_test_at_fws(); + check_type_coercion_at(); + AT_coercion_test_for_cgal_types_fws(); #endif // CGAL_USE_CORE #ifdef CGAL_USE_GMP - AT_coercion_test_at_rat(); + check_type_coercion_at(); + AT_coercion_test_for_cgal_types_rat(); #endif // CGAL_USE_GMP return EXIT_SUCCESS; diff --git a/Number_types/test/Number_types/include/CGAL/Test/_test_interval.h b/Number_types/test/Number_types/include/CGAL/Test/_test_interval.h new file mode 100644 index 00000000000..6183f7b6825 --- /dev/null +++ b/Number_types/test/Number_types/include/CGAL/Test/_test_interval.h @@ -0,0 +1,221 @@ +// TODO: Add licence +// +// 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) : Michael Hemmer +// +// ============================================================================ +// +// \brief provides test functions for the \c Interval concept. + +// TODO: Add Is_empty? + +#include +#include + +#include +#include +#include + +#include +#include + +#include + + + +#ifndef CGAL_TEST_INTERVAL_H +#define CGAL_TEST_INTERVAL_H + +CGAL_BEGIN_NAMESPACE + +template +void test_with_empty_interval(CGAL::Tag_false) { + typedef CGAL::Interval_traits IT; + typedef typename IT::Empty Empty; + BOOST_STATIC_ASSERT( + (::boost::is_same< Empty, CGAL::Null_functor>::value)); + + // this part chages in case we allow empty intersection + // which seems to be not possible for CORE::BigFloat as Interval + try{ + try{ + typename IT::Intersection()(Interval(1),Interval(2)); + assert(false); // it should not reach this + } + catch(CGAL::Exception_intersection_is_empty){} // it throws the right exception + }catch(...){ + assert(false); // seems to be the wrong exception + } +} + +template +void test_with_empty_interval(CGAL::Tag_true) { + + typedef CGAL::Interval_traits IT; + typedef typename IT::Empty Empty; + Test_functor_arity()(1); + const Empty empty = Empty(); + + assert(empty(typename IT::Intersection()(Interval(1),Interval(2)))); + +} + + +template +void test_interval() { + + typedef CGAL::Interval_traits IT; + typedef typename IT::Boundary Boundary; + typedef typename IT::Is_interval Is_interval; + typedef typename IT::With_empty_interval With_empty_interval; + + using CGAL::Tag_true; + BOOST_STATIC_ASSERT(( ::boost::is_same< Is_interval, Tag_true>::value)); + + test_with_empty_interval(With_empty_interval()); + + typedef typename IT::Construct Construct; + typedef typename IT::Lower Lower; + typedef typename IT::Upper Upper; + typedef typename IT::Width Width; + typedef typename IT::Median Median; + typedef typename IT::Norm Norm; + typedef typename IT::Singleton Singleton; + typedef typename IT::In In; + typedef typename IT::Zero_in Zero_in; + typedef typename IT::Equal Equal; + typedef typename IT::Overlap Overlap; + typedef typename IT::Subset Subset; + typedef typename IT::Proper_subset Proper_subset; + typedef typename IT::Intersection Intersection; + typedef typename IT::Hull Hull; + + Test_functor_arity()(2); + Test_functor_arity()(1); + Test_functor_arity()(1); + Test_functor_arity()(1); + Test_functor_arity()(1); + Test_functor_arity()(1); + + Test_functor_arity()(1); + Test_functor_arity()(2); + Test_functor_arity()(1); + Test_functor_arity()(2); + Test_functor_arity()(2); + Test_functor_arity()(2); + Test_functor_arity()(2); + Test_functor_arity()(2); + Test_functor_arity()(2); + + const Construct construct = Construct(); + const Lower lower = Lower(); + const Upper upper = Upper(); + const Width width = Width(); + const Median median = Median(); + const Norm norm = Norm(); + + const Singleton singleton = Singleton(); + const In in = In(); + const Zero_in zero_in = Zero_in(); + const Equal equal = Equal(); + const Overlap overlap = Overlap(); + const Subset subset = Subset(); + const Proper_subset proper_subset = Proper_subset(); + const Intersection intersection = Intersection(); + const Hull hull = Hull(); + + + Interval a(construct(Boundary(-7),Boundary(-5))); + Interval b(construct(Boundary(0),Boundary(4))); + Interval c(construct(Boundary(2),Boundary(6))); + + assert(lower(a) == Boundary(-7)); + assert(upper(a) == Boundary(-5)); + assert(lower(b) == Boundary( 0)); + assert(upper(b) == Boundary( 4)); + assert(lower(c) == Boundary( 2)); + assert(upper(c) == Boundary( 6)); + + assert(width(a) == Boundary( 2)); + assert(median(a) == Boundary(-6)); + assert(norm(a) == Boundary( 7)); + + // assert(!empty(a)); + assert( singleton(Interval(1))); + assert(!singleton(a)); + assert(!singleton(b)); + assert(!singleton(c)); + + assert(!zero_in(Interval(1))); + assert( zero_in(Interval(0))); + assert(!zero_in(a)); + assert( zero_in(b)); + assert(!zero_in(c)); + +//######## + // to be remove again + assert(!CGAL::in_zero(Interval(1))); + assert( CGAL::in_zero(Interval(0))); + assert(!CGAL::in_zero(a)); + assert( CGAL::in_zero(b)); + assert(!CGAL::in_zero(c)); +//######### + + assert(!in(Boundary( 3),a)); + assert( in(Boundary(-7),a)); + + + assert( equal(a,a)); + assert( equal(b,b)); + assert( equal(c,c)); + assert(!equal(a,b)); + assert(!equal(a,c)); + + assert(!overlap(a,b)); + assert( overlap(b,c)); + Interval I25 = construct(Boundary(2),Boundary(5)); + assert(overlap(I25, construct(Boundary(6),Boundary(7))) == false); + assert(overlap(I25, construct(Boundary(5),Boundary(6))) == true); + assert(overlap(I25, construct(Boundary(4),Boundary(5))) == true); + assert(overlap(I25, construct(Boundary(3),Boundary(4))) == true); + assert(overlap(I25, construct(Boundary(2),Boundary(3))) == true); + assert(overlap(I25, construct(Boundary(1),Boundary(2))) == true); + assert(overlap(I25, construct(Boundary(0),Boundary(1))) == false); + + assert(!subset(a,b)); + assert( subset(a,a)); + assert( subset(Interval(-6),a)); + + assert(!proper_subset(a,b)); + assert(!proper_subset(a,a)); + assert( proper_subset(Interval(-6),a)); + + // assert( empty(intersection(a,b))); + assert( lower(intersection(b,c)) == Boundary(2)); + assert( upper(intersection(b,c)) == Boundary(4)); + + // hull + assert(lower(hull(b,c)) == Boundary(0)); + assert(upper(hull(b,c)) == Boundary(6)); + assert(lower(hull(Interval(2),Interval(5))) >= Boundary(1)); + assert(lower(hull(Interval(2),Interval(5))) <= Boundary(2)); + assert(upper(hull(Interval(2),Interval(5))) >= Boundary(5)); + assert(upper(hull(Interval(2),Interval(5))) <= Boundary(6)); + + // singleton + assert(singleton(hull(Interval(2),Interval(2))) == true); + assert(singleton(hull(Interval(2),Interval(3))) == false); + + // width + assert(width(hull(Interval(2),Interval(2))) == Boundary(0)); + assert(width(hull(Interval(2),Interval(3))) == Boundary(1)); +} + +CGAL_END_NAMESPACE + +#endif // CGAL_TEST_REAL_COMPARABLE_H diff --git a/Number_types/test/Number_types/interval_support.cpp b/Number_types/test/Number_types/interval_support.cpp index fb7327a81ee..7def55f29d2 100644 --- a/Number_types/test/Number_types/interval_support.cpp +++ b/Number_types/test/Number_types/interval_support.cpp @@ -10,6 +10,8 @@ #include #endif +#include + template void generic_test_interval(){ @@ -176,14 +178,12 @@ void generic_test_convert_to_bfi(){ int main(){ #ifdef CGAL_USE_LEDA - generic_test_interval(); + CGAL::test_interval(); generic_test_bigfloat_interval(); - - #endif #ifdef CGAL_USE_CORE - generic_test_interval(); + CGAL::test_interval(); generic_test_bigfloat_interval(); #endif diff --git a/Number_types/test/Number_types/leda_bigfloat_interval.cpp b/Number_types/test/Number_types/leda_bigfloat_interval.cpp new file mode 100644 index 00000000000..614295fb4d8 --- /dev/null +++ b/Number_types/test/Number_types/leda_bigfloat_interval.cpp @@ -0,0 +1,31 @@ +#include +#include +#ifdef CGAL_USE_LEDA +#include +#include +#include +#include + +int main() { + typedef CGAL::leda_bigfloat_interval NT; + typedef CGAL::Field_with_sqrt_tag Tag; + typedef CGAL::Tag_false Is_exact; + CGAL::test_algebraic_structure(); + CGAL::test_algebraic_structure(NT(4),NT(6),NT(15)); + CGAL::test_algebraic_structure(NT(-4),NT(6),NT(15)); + CGAL::test_algebraic_structure(NT(4),NT(-6),NT(15)); + CGAL::test_algebraic_structure(NT(-4),NT(-6),NT(15)); + CGAL::test_algebraic_structure(NT(4),NT(6),NT(-15)); + CGAL::test_algebraic_structure(NT(-4),NT(6), NT(15)); + CGAL::test_algebraic_structure(NT(4),NT(-6),NT(-15)); + CGAL::test_algebraic_structure(NT(-4),NT(-6),NT(-15)); + + CGAL::test_real_embeddable(); + CGAL::test_interval(); + + return 0; +} + +#else +int main() { return 0; } +#endif