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