2 offset.hh -- part of GNU LilyPond
4 (c) 1996--2005 Han-Wen Nienhuys
13 Offset complex_multiply (Offset, Offset);
14 Offset complex_divide (Offset, Offset);
15 Offset complex_exp (Offset);
20 This is a mixture a 2D vector. Sometimes it can
21 also be convenient to think of 2D vectors as complex numbers
22 (ie. x + i y). The naming of some methods reflects that.
28 Real coordinate_a_[NO_AXES];
30 Real &operator[] (Axis i)
32 return coordinate_a_[i];
35 Real operator[] (Axis i) const
37 return coordinate_a_[i];
40 Offset& operator+= (Offset o)
42 (*this)[X_AXIS] += o[X_AXIS];
43 (*this)[Y_AXIS] += o[Y_AXIS];
47 Offset operator - () const
51 o[X_AXIS] = - o[X_AXIS];
52 o[Y_AXIS] = - o[Y_AXIS];
56 Offset& operator-= (Offset o)
58 (*this)[X_AXIS] -= o[X_AXIS];
59 (*this)[Y_AXIS] -= o[Y_AXIS];
64 Offset &scale (Offset o)
66 (*this)[X_AXIS] *= o[X_AXIS];
67 (*this)[Y_AXIS] *= o[Y_AXIS];
72 Offset &operator *= (Real a)
80 Offset (Real ix , Real iy)
82 coordinate_a_[X_AXIS] =ix;
83 coordinate_a_[Y_AXIS] =iy;
88 coordinate_a_[X_AXIS] = coordinate_a_[Y_AXIS]= 0.0;
91 String to_string () const;
93 Offset& mirror (Axis a)
95 coordinate_a_[a] = - coordinate_a_[a];
100 Real length () const;
102 Offset operator *= (Offset z2)
104 *this = complex_multiply (*this, z2);
110 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, +);
111 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, -);
112 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, *);
115 operator* (Real o1, Offset o2)
122 operator* (Offset o1, Real o2)
129 mirror (Offset o, Axis a)
137 dot_product (Offset o1, Offset o2)
139 return o1[X_AXIS] * o2[X_AXIS] + o1[Y_AXIS] * o2[Y_AXIS];
143 #endif /* OFFSET_HH */