]> git.donarmstrong.com Git - lilypond.git/blob - boxes.hh
release: 0.0.5
[lilypond.git] / boxes.hh
1 /*
2     some 2D geometrical concepts
3 */
4
5 #ifndef BOXES_HH
6 #define BOXES_HH
7
8 #include "textdb.hh"
9 #include "real.hh"
10 #include "vray.hh"
11
12 /// 2d vector 
13 struct Offset {
14     Real x,y;
15
16     Offset operator+(Offset o)const {
17         Offset r(*this);
18         r+=o;
19         return r;
20     }
21     
22     Offset operator+=(Offset o) {
23         x+=o.x;
24         y+=o.y;
25         return *this;
26     }
27     Offset(Real ix , Real iy) {
28         x=ix;
29         y=iy;
30     }
31     Offset() {
32         x=0.0;
33         y=0.0;
34     }
35 };
36
37 /// a Real interval
38 struct Interval {
39     Real min, max;
40
41     void translate(Real t) {
42         min += t;
43         max += t;
44     }
45
46     void unite(Interval h) {
47         if (h.min<min)
48             min = h.min;
49         if (h.max>max)
50             max = h.max;
51     }
52     Real length() const;
53     void set_empty() ;
54     bool empty() { return min > max; }
55     Interval() {
56         set_empty();
57     }
58     Interval(Real m, Real M) {
59         min =m;
60         max = M;
61     }
62 };
63
64
65 /// a 4-tuple of #Real#s
66 struct Box {
67     Interval x, y;
68     
69     void translate(Offset o) {
70         x.translate(o.x);
71         y.translate(o.y);
72     }
73     void unite(Box b) {
74         x.unite(b.x);
75         y.unite(b.y);
76     }
77     Box(svec<Real> );
78     Box();
79     Box(Interval ix, Interval iy);
80 };
81
82
83 #endif