]> git.donarmstrong.com Git - lilypond.git/blob - hdr/boxes.hh
release: 0.0.9
[lilypond.git] / hdr / 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     Interval &operator += (Real r) {
63         min += r;
64         max +=r;
65         return *this;
66     }
67 };
68
69
70 /// a 4-tuple of #Real#s
71 struct Box {
72     Interval x, y;
73     
74     void translate(Offset o) {
75         x.translate(o.x);
76         y.translate(o.y);
77     }
78     void unite(Box b) {
79         x.unite(b.x);
80         y.unite(b.y);
81     }
82     Box(svec<Real> );
83     Box();
84     Box(Interval ix, Interval iy);
85 };
86
87
88 #endif