blob: 950945ca873216dd4b0c4e75b3a6c7a6222304bc (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
/*
interval.hh -- part of flowerlib
(c) 1996 Han-Wen Nienhuys
*/
#ifndef INTERVAL_HH
#define INTERVAL_HH
#include <assert.h>
#include "real.hh"
/// a Real interval
struct Interval {
Real min, max;
void translate(Real t) {
min += t;
max += t;
}
Real operator[](int j) {
if (j==-1)
return min;
else if (j==1)
return max;
else
assert(false);
return 0.0;
}
void unite(Interval h) {
if (h.min<min)
min = h.min;
if (h.max>max)
max = h.max;
}
Real length() const;
void set_empty() ;
bool empty() { return min > max; }
Interval() {
set_empty();
}
Interval(Real m, Real M) {
min =m;
max = M;
}
Interval &operator += (Real r) {
min += r;
max +=r;
return *this;
}
};
#endif // INTERVAL_HH
|