2 offset.hh -- part of GNU LilyPond
4 (c) 1996--2006 Han-Wen Nienhuys
11 #include "std-string.hh"
15 Offset complex_multiply (Offset, Offset);
16 Offset complex_divide (Offset, Offset);
17 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.
27 Real coordinate_a_[NO_AXES];
29 Real &operator [] (Axis i)
31 return coordinate_a_[i];
34 Real operator [] (Axis i) const
36 return coordinate_a_[i];
39 Offset &operator += (Offset o)
41 (*this)[X_AXIS] += o[X_AXIS];
42 (*this)[Y_AXIS] += o[Y_AXIS];
46 Offset operator - () const
50 o[X_AXIS] = -o[X_AXIS];
51 o[Y_AXIS] = -o[Y_AXIS];
55 Offset &operator -= (Offset o)
57 (*this)[X_AXIS] -= o[X_AXIS];
58 (*this)[Y_AXIS] -= o[Y_AXIS];
63 Offset &scale (Offset o)
65 (*this)[X_AXIS] *= o[X_AXIS];
66 (*this)[Y_AXIS] *= o[Y_AXIS];
71 Offset &operator /= (Real a)
77 Offset &operator *= (Real a)
85 Offset (Real ix, Real iy)
87 coordinate_a_[X_AXIS] = ix;
88 coordinate_a_[Y_AXIS] = iy;
93 coordinate_a_[X_AXIS] = coordinate_a_[Y_AXIS] = 0.0;
96 string to_string () const;
98 Offset &mirror (Axis a)
100 coordinate_a_[a] = -coordinate_a_[a];
105 Real length () const;
106 bool is_sane () const;
107 Offset operator *= (Offset z2)
109 *this = complex_multiply (*this, z2);
114 #include "arithmetic-operator.hh"
115 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, +);
116 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, -);
117 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, *);
120 operator * (Real o1, Offset o2)
127 operator / (Offset o1, Real a)
134 operator * (Offset o1, Real o2)
141 mirror (Offset o, Axis a)
149 dot_product (Offset o1, Offset o2)
151 return o1[X_AXIS] * o2[X_AXIS] + o1[Y_AXIS] * o2[Y_AXIS];
154 #endif /* OFFSET_HH */