]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/offset.hh
release: 0.1.11
[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     
30   Offset operator+=(Offset o) {
31     x()+=o.x ();
32     y()+=o.y ();
33     return *this;
34   }
35   Offset (Real ix , Real iy) {
36     x()=ix;
37     y()=iy;
38   }
39   Offset() {
40     x()=0.0;
41     y()=0.0;
42   }
43 };
44
45 inline Offset
46 operator+ (Offset o1, Offset const& o2)
47 {
48   o1 += o2;
49   return o1;
50 }
51     
52 #endif // OFFSET_HH
53
54