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