1 #ifndef MATH_INTERVAL_H 2 #define MATH_INTERVAL_H 11 struct ClosedInterval;
20 inline void set(Real a, Real b);
21 inline void setFull();
22 inline void setEmpty();
23 inline bool isFull()
const;
37 inline void expand(Real x);
38 inline bool isEmpty()
const;
39 inline bool contains(Real x)
const;
55 inline void expand(Real x);
56 inline bool isEmpty()
const;
57 inline bool contains(Real x)
const;
58 inline bool contains(
const Interval&)
const;
66 Interval::Interval(Real _a, Real _b)
70 void Interval::set(Real _a, Real _b)
76 void Interval::setFull()
82 void Interval::setEmpty()
88 bool Interval::isFull()
const 95 OpenInterval::OpenInterval()
98 OpenInterval::OpenInterval(Real _a, Real _b)
114 void OpenInterval::expand(Real x)
117 else if (x > b) b = x;
120 bool OpenInterval::isEmpty()
const 125 bool OpenInterval::contains(Real x)
const 129 return (x > a && x < b) || isFull();
132 bool OpenInterval::contains(
const OpenInterval& i)
const 135 return a <= i.a && i.b <= b;
141 if(
IsInf(b))
return true;
144 else if(
IsInf(b))
return (a < i.a);
145 else return (a < i.a && i.b < b);
148 bool OpenInterval::intersects(
const OpenInterval& i)
const 151 if(
IsInf(b) == 1)
return !i.isEmpty();
154 else if(
IsInf(b))
return (a < i.b);
155 else return (a < i.b && i.a < b);
160 ClosedInterval::ClosedInterval()
163 ClosedInterval::ClosedInterval(Real _a, Real _b)
179 void ClosedInterval::expand(Real x)
182 else if (x > b) b = x;
185 bool ClosedInterval::isEmpty()
const 190 bool ClosedInterval::contains(Real x)
const 192 return x >= a && x <= b;
195 bool ClosedInterval::contains(
const Interval& i)
const 197 return a <= i.a && i.b <= b;
202 return a <= i.b && i.a <= b;
205 bool ClosedInterval::intersects(
const OpenInterval& i)
const 208 if(
IsInf(b) == 1)
return !i.isEmpty();
211 else if(
IsInf(b) == 1)
return (a < i.b);
212 else return (a < i.b && i.a < b);
Common math typedefs, constants, functions.
int IsInf(double x)
Returns +1 if x is +inf, -1 if x is -inf, and 0 otherwise.
Definition: infnan.cpp:40
Cross-platform infinity and not-a-number routines.
An open interval (a,b)
Definition: Interval.h:31
A generic interval {a,b}, where { and } can be either (,[ or ),].
Definition: Interval.h:16
A closed interval [a,b].
Definition: Interval.h:49
Contains all definitions in the Math package.
Definition: WorkspaceBound.h:12