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