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);
18 This is a mixture a 2D vector. Sometimes it can
19 also be convenient to think of 2D vectors as complex numbers
20 (ie. x + i y). The naming of some methods reflects that.
25 Real coordinate_a_[NO_AXES];
27 Real &operator [] (Axis i)
29 return coordinate_a_[i];
32 Real operator [] (Axis i) const
34 return coordinate_a_[i];
37 Offset &operator += (Offset o)
39 (*this)[X_AXIS] += o[X_AXIS];
40 (*this)[Y_AXIS] += o[Y_AXIS];
44 Offset operator - () const
48 o[X_AXIS] = -o[X_AXIS];
49 o[Y_AXIS] = -o[Y_AXIS];
53 Offset &operator -= (Offset o)
55 (*this)[X_AXIS] -= o[X_AXIS];
56 (*this)[Y_AXIS] -= o[Y_AXIS];
61 Offset &scale (Offset o)
63 (*this)[X_AXIS] *= o[X_AXIS];
64 (*this)[Y_AXIS] *= o[Y_AXIS];
69 Offset &operator *= (Real a)
77 Offset (Real ix, Real iy)
79 coordinate_a_[X_AXIS] = ix;
80 coordinate_a_[Y_AXIS] = iy;
85 coordinate_a_[X_AXIS] = coordinate_a_[Y_AXIS] = 0.0;
88 String to_string () const;
90 Offset &mirror (Axis a)
92 coordinate_a_[a] = -coordinate_a_[a];
99 Offset operator *= (Offset z2)
101 *this = complex_multiply (*this, z2);
106 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, +);
107 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, -);
108 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, *);
111 operator * (Real o1, Offset o2)
118 operator * (Offset o1, Real o2)
125 mirror (Offset o, Axis a)
133 dot_product (Offset o1, Offset o2)
135 return o1[X_AXIS] * o2[X_AXIS] + o1[Y_AXIS] * o2[Y_AXIS];
138 #endif /* OFFSET_HH */