diff --git a/Filtered_kernel/include/CGAL/Filtered_kernel/internal/Static_filters/tools.h b/Filtered_kernel/include/CGAL/Filtered_kernel/internal/Static_filters/tools.h index 6aab973bd804..6b7de531f765 100644 --- a/Filtered_kernel/include/CGAL/Filtered_kernel/internal/Static_filters/tools.h +++ b/Filtered_kernel/include/CGAL/Filtered_kernel/internal/Static_filters/tools.h @@ -19,6 +19,8 @@ namespace CGAL { +class Filtered_rational; + template < typename ET > class Lazy_exact_nt; @@ -233,6 +235,7 @@ inline bool fit_in_double(const int& i, double& r) { r = i; return true; } template < typename ET > inline bool fit_in_double(const Lazy_exact_nt&, double&); +inline bool fit_in_double(const Filtered_rational&, double&); // Auxiliary functor, to get the approximation of a kernel object: // - for a Point_3 of the Lazy_kernel<...>, one needs to call approx(), diff --git a/Number_types/include/CGAL/Filtered_rational.h b/Number_types/include/CGAL/Filtered_rational.h new file mode 100644 index 000000000000..50247efe9eff --- /dev/null +++ b/Number_types/include/CGAL/Filtered_rational.h @@ -0,0 +1,167 @@ +#ifndef CGAL_FILTERED_RATIONAL_H + +#include +#include + +namespace CGAL { + +struct Filtered_rational : boost::totally_ordered1 > + //#endif + > +{ + Interval_nt<> i; + Exact_rational rat; + + Filtered_rational() + {} + + Filtered_rational(int d) + : i(d), rat(d) + {} + + Filtered_rational(double d) + : i(d), rat(d) + {} + + + Filtered_rational(const Interval_nt<>& i, const Exact_rational& rat) + : i(i), rat(rat) + {} + + Filtered_rational operator-() const + { + return Filtered_rational(-i, -rat); + } + + Filtered_rational operator+(const Filtered_rational& b) const + { + return Filtered_rational(i + b.i, rat + b.rat); + } + + + Filtered_rational operator-(const Filtered_rational& b) const + { + return Filtered_rational(i - b.i, rat - b.rat); + } + + Filtered_rational operator*(const Filtered_rational& b) const + { + return Filtered_rational(i * b.i, rat * b.rat); + } + + Filtered_rational operator/(const Filtered_rational& b) const + { + return Filtered_rational(i / b.i, rat / b.rat); + } + + + + Filtered_rational& operator+=(const Filtered_rational &a) { return *this = *this + a; } + Filtered_rational& operator-=(const Filtered_rational &a) { return *this = *this - a; } + Filtered_rational& operator*=(const Filtered_rational &a) { return *this = *this * a; } + Filtered_rational& operator/=(const Filtered_rational &a) { return *this = *this / a; } + +}; + + +template <> class Real_embeddable_traits< Filtered_rational > + : public INTERN_RET::Real_embeddable_traits_base< Filtered_rational, CGAL::Tag_true > { + public: + + class Sgn + : public CGAL::cpp98::unary_function< Type, ::CGAL::Sign > { + public: + ::CGAL::Sign operator()( const Type& x ) const { + return sign(x); + } + }; +}; + + + +bool operator==(const Filtered_rational& a, + const Filtered_rational& b) + { + Uncertain u = a.i == b.i; + if(is_indeterminate(u)){ + return a.rat == b.rat; + } + return make_certain(u); + } + + + +bool operator<(const Filtered_rational& a, + const Filtered_rational& b) + { + Uncertain u = a.i < b.i; + if(is_indeterminate(u)){ + return a.rat < b.rat; + } + return make_certain(u); + } + + Sign sign(const Filtered_rational& a) + { + Uncertain u = sign(a.i); + if(is_indeterminate(u)){ + return CGAL::sign(a.rat); + } + return make_certain(u); + } + + Sign compare(const Filtered_rational& a, const Filtered_rational& b){ + Uncertain u = compare(a.i, b.i); + if(is_indeterminate(u)){ + return compare(a.rat, b.rat); + } + return make_certain(u); + } + + Filtered_rational square(const Filtered_rational& a) + { + return Filtered_rational(square(a.i), square(a.rat)); + } + + std::pair to_interval(const Filtered_rational& b) +{ + return std::make_pair(b.i.inf(), b.i.sup()); +} + + double to_double(const Filtered_rational& b) + { + return to_double(b.i); + } + + + std::ostream& operator<<(std::ostream& os, const Filtered_rational& ) + { + return os; + } + + std::istream& operator>>(std::istream& is, const Filtered_rational& ) + { + return is; + } + + namespace internal { + + inline bool fit_in_double(const Filtered_rational& fr, double& d) + { + return fit_in_double(fr.i, d); + } + } +CGAL_DEFINE_COERCION_TRAITS_FOR_SELF(Filtered_rational) +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short ,Filtered_rational) +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int ,Filtered_rational) +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long ,Filtered_rational) +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float ,Filtered_rational) +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double ,Filtered_rational) + +} // namespace CGAL + +#endif