vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Interval.h
Go to the documentation of this file.
1 
13 // header definitions
14 #ifndef _INTERVAL_H_
15 #define _INTERVAL_H_
16 
17 // attributes description includes
18 #include "Range.h"
19 
20 // VRECKO namespace
21 namespace vrecko
22 {
23 
41 template <class tval, class tref = tval>
42 class Interval : public Range
43 {
44 public:
45 
52  Interval(tref lowerBound, tref upperBound) : Range(Range::RANGE_INTERVAL)
53  {
54  // set both bounds to desired values
55  this->lowerBound = lowerBound;
56  this->upperBound = upperBound;
57 
58  // implicitly set inclusive bounds
59  lowerInclusive = true;
60  upperInclusive = true;
61  }
62 
71  Interval(tref lowerBound, tref upperBound, bool lowerInclusive,
72  bool upperInclusive) : Range(Range::RANGE_INTERVAL)
73  {
74  // set both bounds to desired values
75  this->lowerBound = lowerBound;
76  this->upperBound = upperBound;
77 
78  // set flags for both bounds
79  this->lowerInclusive = lowerInclusive;
80  this->upperInclusive = upperInclusive;
81  }
82 
88  inline tref getLowerBound() const
89  {
90  return lowerBound;
91  }
92 
98  inline tref getUpperBound() const
99  {
100  return upperBound;
101  }
102 
108  inline bool isLowerInclusive() const
109  {
110  return lowerInclusive;
111  }
112 
118  inline bool isUpperInclusive() const
119  {
120  return upperInclusive;
121  }
122 
130  bool includesValue(tref value) const
131  {
132  // both bounds are inclusive
134  {
135  return (value >= getLowerBound() && value <= getUpperBound());
136  }
137 
138  // lower bound is not inclusive and the upper bound is inclusive
140  {
141  return (value > getLowerBound() && value <= getUpperBound());
142  }
143 
144  // lower bound is not inclusive and the upper bound is inclusive
146  {
147  return (value >= getLowerBound() && value < getUpperBound());
148  }
149 
150  // both bounds are not inclusive
151  return (value > getLowerBound() && value < getUpperBound());
152  }
153 
154 private:
155 
156  // bounds
157  tval lowerBound;
158  tval upperBound;
159 
160  // flags
161  bool lowerInclusive;
162  bool upperInclusive;
163 };
164 
172 
173 // end of vrecko namespace
174 }
175 
176 // end header definitions
177 #endif
178