]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/offset.hh
partial: 0.1.57.jcn
[lilypond.git] / lily / include / offset.hh
1 /*
2   offset.hh -- part of GNU LilyPond
3
4   (c) 1996,97 Han-Wen Nienhuys
5 */
6
7 #ifndef OFFSET_HH
8 #define OFFSET_HH
9
10 #include "real.hh"
11 #include "axes.hh"
12
13
14 /// 2d vector 
15 struct Offset {
16   Real coordinate_a_[NO_AXES];
17     
18   Real &y() { return coordinate_a_[Y_AXIS]; }
19   Real &x() { return coordinate_a_[X_AXIS]; }
20   Real y() const { return coordinate_a_[Y_AXIS]; }
21   Real x() const { return coordinate_a_[X_AXIS]; }
22     
23   Real &operator[](Axis i) {
24     return coordinate_a_[i];
25   }
26   Real operator[](Axis i) const{
27     return coordinate_a_[i];
28   }
29   String str () const;
30     
31   Offset operator+=(Offset o) {
32     x()+=o.x ();
33     y()+=o.y ();
34     return *this;
35   }
36   Offset (Real ix , Real iy) {
37     x()=ix;
38     y()=iy;
39   }
40   Offset() {
41     x()=0.0;
42     y()=0.0;
43   }
44 };
45
46 inline Offset
47 operator+ (Offset o1, Offset const& o2)
48 {
49   o1 += o2;
50   return o1;
51 }
52     
53 #endif // OFFSET_HH
54
55