(print): new file. Set limits to
[lilypond.git] / flower / include / offset.hh
blob8c57c3de2968d1bab7c46ff4671bb6f655fab499
1 /*
2 offset.hh -- part of GNU LilyPond
4 (c) 1996--2004 Han-Wen Nienhuys
5 */
7 #ifndef OFFSET_HH
8 #define OFFSET_HH
10 #include "flower-proto.hh"
11 #include "real.hh"
12 #include "axes.hh"
13 #include "arithmetic-operator.hh"
14 #include "string.hh"
16 Offset complex_multiply (Offset, Offset);
17 Offset complex_divide (Offset, Offset);
18 Offset complex_exp (Offset);
21 /** 2d vector
22 should change to Complex -- how is vector == complex?
24 ughr wat een beerput
26 class Offset
28 public:
29 Real coordinate_a_[NO_AXES];
31 Real &operator[] (Axis i)
33 return coordinate_a_[i];
36 Real operator[] (Axis i) const
38 return coordinate_a_[i];
41 Offset& operator+= (Offset o)
43 (*this)[X_AXIS] += o[X_AXIS];
44 (*this)[Y_AXIS] += o[Y_AXIS];
45 return *this;
48 Offset operator - () const
50 Offset o = *this;
52 o[X_AXIS] = - o[X_AXIS];
53 o[Y_AXIS] = - o[Y_AXIS];
54 return o;
57 Offset& operator-= (Offset o)
59 (*this)[X_AXIS] -= o[X_AXIS];
60 (*this)[Y_AXIS] -= o[Y_AXIS];
62 return *this;
65 Offset &scale (Offset o)
67 (*this)[X_AXIS] *= o[X_AXIS];
68 (*this)[Y_AXIS] *= o[Y_AXIS];
70 return *this;
73 Offset &operator *= (Real a)
75 (*this)[X_AXIS] *= a;
76 (*this)[Y_AXIS] *= a;
78 return *this;
81 Offset (Real ix , Real iy)
83 coordinate_a_[X_AXIS] =ix;
84 coordinate_a_[Y_AXIS] =iy;
87 Offset ()
89 coordinate_a_[X_AXIS] = coordinate_a_[Y_AXIS]= 0.0;
92 String to_string () const;
94 Offset& mirror (Axis a)
96 coordinate_a_[a] = - coordinate_a_[a];
97 return *this;
100 Real arg () const;
101 Real length () const;
103 //wtf, How is Offset a Complex? is this used?
104 Offset operator *= (Offset z2)
106 *this = complex_multiply (*this,z2);
107 return *this;
112 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, +);
113 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, -);
114 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, *);
116 inline Offset
117 operator* (Real o1, Offset o2)
119 o2 *= o1;
120 return o2;
123 inline Offset
124 operator* (Offset o1, Real o2)
126 o1 *= o2;
127 return o1;
130 inline Offset
131 mirror (Offset o, Axis a)
133 o.mirror (a);
134 return o;
138 #endif /* OFFSET_HH */