]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/offset.hh
* lily/include/audio-column.hh: remove unused variables.
[lilypond.git] / flower / include / offset.hh
1 /*
2   offset.hh -- part of GNU LilyPond
3
4   (c) 1996--2004 Han-Wen Nienhuys
5 */
6
7 #ifndef OFFSET_HH
8 #define OFFSET_HH
9
10 #include "flower-proto.hh"
11 #include "real.hh"
12 #include "axes.hh"
13 #include "arithmetic-operator.hh"
14 #include "string.hh"
15
16 Offset complex_multiply (Offset, Offset);
17 Offset complex_divide (Offset, Offset);
18 Offset complex_exp (Offset);
19
20
21 /** 2d vector
22     should change to Complex -- how is vector == complex?
23
24     ughr wat een beerput
25 */
26 class Offset 
27 {
28 public:
29   Real coordinate_a_[NO_AXES];
30     
31   Real &operator[] (Axis i) 
32   {
33     return coordinate_a_[i];
34   }
35
36   Real operator[] (Axis i) const
37   {
38     return coordinate_a_[i];
39   }
40     
41   Offset& operator+= (Offset o) 
42   {
43     (*this)[X_AXIS] += o[X_AXIS];
44     (*this)[Y_AXIS] += o[Y_AXIS];
45     return *this;
46   }
47
48   Offset operator - () const 
49   {
50     Offset o = *this;
51     
52     o[X_AXIS]  = - o[X_AXIS];
53     o[Y_AXIS]  = - o[Y_AXIS];
54     return o;
55   }
56
57   Offset& operator-= (Offset o) 
58   {
59     (*this)[X_AXIS] -= o[X_AXIS];
60     (*this)[Y_AXIS] -= o[Y_AXIS];
61
62     return *this;
63   }
64   
65   Offset &scale (Offset o) 
66   {
67     (*this)[X_AXIS] *= o[X_AXIS];
68     (*this)[Y_AXIS] *= o[Y_AXIS];
69
70     return *this;
71   }
72
73   Offset &operator *= (Real a) 
74   {
75     (*this)[X_AXIS] *= a;
76     (*this)[Y_AXIS] *= a;
77
78     return *this;
79   }
80       
81   Offset (Real ix , Real iy) 
82   {
83     coordinate_a_[X_AXIS] =ix;
84     coordinate_a_[Y_AXIS] =iy;    
85   }
86
87   Offset () 
88   {
89     coordinate_a_[X_AXIS] = coordinate_a_[Y_AXIS]= 0.0;
90   }
91
92   String to_string () const;
93
94   Offset& mirror (Axis a)
95   {
96     coordinate_a_[a] = - coordinate_a_[a];
97     return *this;
98   }
99   
100   Real  arg () const;
101   Real length () const;
102
103   //wtf, How is Offset a Complex? is this used?
104   Offset operator *= (Offset z2) 
105   {
106     *this = complex_multiply (*this,z2);
107     return *this;
108   }
109
110 };
111
112 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, +);
113 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, -);
114 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, *);
115
116 inline Offset
117 operator* (Real o1, Offset o2)
118 {
119   o2 *= o1;
120   return o2;
121 }
122
123 inline Offset
124 operator* (Offset o1, Real o2)
125 {
126   o1 *= o2;
127   return o1;
128 }
129
130 inline Offset
131 mirror (Offset o, Axis a)
132 {
133   o.mirror (a);
134   return o;
135 }
136
137
138 #endif /* OFFSET_HH */
139
140