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