Diana Software
QInterval.hh
Go to the documentation of this file.
1 
9 #ifndef _Q_INTERVAL_HH_
10 #define _Q_INTERVAL_HH_
11 
12 #include "QDiana.hh"
13 #include "QObject.hh"
14 
16 
17 class QInterval : public QObject {
18  public:
20  QInterval(const double min, const double max);
21 
23  QInterval();
24 
26  virtual ~QInterval();
27 
29  void Clear() {
32  }
33 
35  bool operator<(const QInterval& interval) const
36  {return ( (GetMin() < interval.GetMin())
37  ||
38  (!(interval.GetMin() < GetMin())
39  && GetMax() < interval.GetMax()) );}
40 
42  bool operator==(const QInterval& other) const { return fMax == other.fMax && fMin == other.fMin; }
43 
45  bool Contains(const double value) const
46  {return (GetMin() <= value && value <= GetMax());}
47 
49  bool Contains(const QInterval& interval) const
50  {return (GetMin() <= interval.GetMin()
51  && interval.GetMax() <= GetMax());}
52 
54  double GetMax() const {return fMax;}
55 
57  double GetMin() const {return fMin;}
58 
60  bool Intersects(const QInterval& interval) const
61  {return (Contains(interval.GetMin()) || Contains(interval.GetMax())
62  || interval.Contains(*this));}
63 
65  double Length() const {return (GetMax() - GetMin());}
66 
68  void SetMax(const double max) {fMax = max;}
69 
71  void SetMin(const double min) {fMin = min;}
72 
73  protected:
75  double fMax;
76 
78  double fMin;
79 
81 };
82 
84 
85 #endif
double max
Definition: CheckOF.C:53
#define Q_DOUBLE_DEFAULT
Definition: QDiana.hh:24
#define Q_END_NAMESPACE
Definition: QDiana.hh:22
#define Q_BEGIN_NAMESPACE
Definition: QDiana.hh:20
double min(const Diana::QVector &v)
Definition: QVector.cc:878
Interval of real numbers.
Definition: QInterval.hh:17
bool operator<(const QInterval &interval) const
Less than operator like std::pair.
Definition: QInterval.hh:35
void Clear()
Clear.
Definition: QInterval.hh:29
bool Contains(const QInterval &interval) const
Return whether the interval contains another interval.
Definition: QInterval.hh:49
double fMin
Minimum of interval.
Definition: QInterval.hh:78
QObjectDef(QInterval, 1)
double Length() const
Get length of interval.
Definition: QInterval.hh:65
bool Contains(const double value) const
Return whether the interval contains a value.
Definition: QInterval.hh:45
double fMax
Maximum of interval.
Definition: QInterval.hh:75
void SetMin(const double min)
Set minimum of the interval.
Definition: QInterval.hh:71
void SetMax(const double max)
Set maximum of the interval.
Definition: QInterval.hh:68
virtual ~QInterval()
Destructor.
Definition: QInterval.cc:26
double GetMax() const
Get maximum of interval.
Definition: QInterval.hh:54
double GetMin() const
Get minimum of interval.
Definition: QInterval.hh:57
bool operator==(const QInterval &other) const
operator==
Definition: QInterval.hh:42
bool Intersects(const QInterval &interval) const
Return whether the interval intersects another interval.
Definition: QInterval.hh:60
QInterval()
constructor
Definition: QInterval.cc:19
base class for objects handled by QEvent and QGlobalDataManager.
Definition: QObject.hh:76