// Compatiblity layer with ibex for the simple interval library from Luc JAULIN, with minor modifications from Fabrice LE BARS and Jeremy NICOLA.

#ifndef __INTERVAL__
#define __INTERVAL__

#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <math.h>

#define oo 1.0/0.0

class QDataStream;
class QDebug;

using namespace std;

//----------------------------------------------------------------------
// Definition de intervalle
//----------------------------------------------------------------------

class interval
{
public:
    double inf;
    double sup;
    bool isEmpty;

public:
    //--------------------------------------------------------------------------
    //                           CONSTRUCTEURS
    //--------------------------------------------------------------------------
    interval ();
    interval (const double&);    // Pas const pour conversion double -> interval
    interval (const double&, const double&);
    interval (const interval&);
    interval& operator= (const interval&);
    interval& Intersect(const interval&);

    //--------------------------------------------------------------------------
    //                          OPERATEURS
    //--------------------------------------------------------------------------
    friend interval operator& (const interval&,const interval&);
    friend interval operator+ (const interval&,const interval&);
    friend interval operator- (const interval&);
    friend interval operator- (const interval&, const interval&);
    friend interval operator* (const double, const interval&);
    friend interval operator* (const interval&, const double);
    friend interval operator* (const interval&, const interval&);
    friend interval operator/ (const interval& ,const interval&);
    friend std::ostream& operator<< (std::ostream&, const interval&);
    friend QDataStream & operator<< (QDataStream &, const interval&);
    friend QDataStream & operator>> (QDataStream &, interval&);
    friend QDebug operator<< (QDebug, const interval&);
};



//----------------------------------------------------------------------
// Interval-valued functions
//----------------------------------------------------------------------
interval Min(const interval& x, const interval& y);
interval Min(const interval& x, const interval& y, const interval& z);
interval Max(const interval& x, const interval& y);
interval Max(const interval& x, const interval& y, const interval& z);

interval Det(interval&, interval&, interval&, interval&);
interval Det(interval& ux, interval& uy, double& vx, double& vy);
interval Step(const interval&);
interval Inter(const interval&, const interval&);
interval Inter(std::vector<interval> x);
interval Union(const interval&, const interval&);
interval Union(std::vector<interval> x);
interval Inflate(const interval&, double);
//----------------------------------------------------------------------
// Other functions
//----------------------------------------------------------------------
double Inf(const interval&);
double Sup(const interval&);
double Center(const interval&);
double Width(const interval&);
double Volume(const interval&);
double Rad(const interval&);
double ToReal(const interval&);
bool Disjoint(const interval& a, const interval& b);
bool Subset(const interval& a, const interval& b);
bool In(double, const interval&);

interval  Sqr        (const interval&);
interval  Sqrt       (const interval&);
interval  Cos        (const interval&);
interval  Sin        (const interval&);
double      Rand       (const interval&);
//----------------------------------------------------------------------
// Contractors
//----------------------------------------------------------------------
void Cadd(interval& Z, interval& X, interval& Y);
void Cadd(interval& Z, double x, interval& Y);
void Cadd(interval& Z, interval& X, double y);
void Csub(interval& Z, interval& X, interval& Y);
void Csub(interval& Z, double x, interval& Y);
void Csub(interval& Z, interval& X, double y);
void Cmul(interval& Z, interval& X, interval& Y);
void Cmul(interval& Z, double x, interval& Y);
void Cmul(interval& Z, interval& X, double y);
void Cdiv(interval& Z, interval& X, interval& Y);
void Csqr(interval& Y, interval& X);
void Cpow(interval& Y, interval& X, int n);
void Cnorm(interval& N, interval& X, interval& Y);
void Cnorm(interval& N, interval& X, interval& Y, interval& Z);
void CinRing(interval& X, interval& Y, double cx, double cy, interval R);
void CinCircle(interval& mx, interval& my, double cx, double cy, double r);


#endif // __INTERVAL__
