]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/offset.hh
release: 0.1.57
[lilypond.git] / flower / 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 /** 2d vector
14     should change to Complex
15 */
16 struct Offset {
17 public:
18
19   Real coordinate_a_[NO_AXES];
20     
21   Real &y() { return coordinate_a_[Y_AXIS]; }
22   Real &x() { return coordinate_a_[X_AXIS]; }
23   Real y() const { return coordinate_a_[Y_AXIS]; }
24   Real x() const { return coordinate_a_[X_AXIS]; }
25     
26   Real &operator[](Axis i) {
27     return coordinate_a_[i];
28   }
29   Real operator[](Axis i) const{
30     return coordinate_a_[i];
31   }
32     
33   Offset& operator+=(Offset o) {
34     x()+=o.x ();
35     y()+=o.y ();
36     return *this;
37   }
38   Offset operator - () const {
39     Offset o = *this;
40     o.x () = - o.x ();
41     o.y () = - o.y ();
42     return *this;
43   }
44   Offset& operator-=(Offset o) {
45     x()-=o.x ();
46     y()-=o.y ();
47     return *this;
48   }
49   
50   Offset &scale (Offset o) {
51     x()*=o.x ();
52     y()*=o.y ();
53     return *this;
54   }
55   Offset &operator *=(Real a) {
56     y() *= a;
57     x() *= a;
58     return *this;
59   }
60       
61   Offset (Real ix , Real iy) {
62     x()=ix;
63     y()=iy;
64   }
65   Offset() {
66     x()=0.0;
67     y()=0.0;
68   }
69 #ifndef STANDALONE
70   String str () const;
71 #endif
72
73   void mirror (Axis);
74   Real  arg () const;
75   Real length () const;
76 };
77
78 Offset complex_multiply (Offset, Offset);
79 Offset complex_exp (Offset);
80
81
82 inline Offset
83 operator* (Offset z1, Offset z2)
84 {
85   return complex_multiply (z1,z2);
86 }
87
88 inline Offset
89 operator+ (Offset o1, Offset const& o2)
90 {
91   o1 += o2;
92   return o1;
93 }
94
95 inline Offset
96 operator- (Offset o1, Offset const& o2)
97 {
98   o1 -= o2;
99   return o1;
100 }
101
102
103 inline Offset
104 operator* (Real o1, Offset o2)
105 {
106   o2 *= o1;
107   return o2;
108 }
109
110 inline Offset
111 operator* (Offset o1, Real o2)
112 {
113   o1 *= o2;
114   return o1;
115 }
116
117
118 #endif // OFFSET_HH
119
120