2 offset.hh -- part of GNU LilyPond
4 (c) 1996--2009 Han-Wen Nienhuys
11 #include "std-string.hh"
16 This is a mixture a 2D vector. Sometimes it can
17 also be convenient to think of 2D vectors as complex numbers
18 (ie. x + i y). The naming of some methods reflects that.
23 Real coordinate_a_[NO_AXES];
25 Real &operator [] (Axis i)
27 return coordinate_a_[i];
30 Real operator [] (Axis i) const
32 return coordinate_a_[i];
35 Offset &operator += (Offset o)
37 (*this)[X_AXIS] += o[X_AXIS];
38 (*this)[Y_AXIS] += o[Y_AXIS];
42 Offset operator - () const
46 o[X_AXIS] = -o[X_AXIS];
47 o[Y_AXIS] = -o[Y_AXIS];
51 Offset &operator -= (Offset o)
53 (*this)[X_AXIS] -= o[X_AXIS];
54 (*this)[Y_AXIS] -= o[Y_AXIS];
59 Offset &scale (Offset o)
61 (*this)[X_AXIS] *= o[X_AXIS];
62 (*this)[Y_AXIS] *= o[Y_AXIS];
67 Offset &operator /= (Real a)
73 Offset &operator *= (Real a)
81 Offset (Real ix, Real iy)
83 coordinate_a_[X_AXIS] = ix;
84 coordinate_a_[Y_AXIS] = iy;
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];
99 Offset direction () const;
100 Offset swapped () const;
103 Real angle_degrees () const;
104 Real length () const;
105 bool is_sane () const;
106 Offset operator *= (Offset z2);
109 #include "arithmetic-operator.hh"
110 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, +);
111 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, -);
112 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, *);
116 Offset complex_multiply (Offset, Offset);
117 Offset complex_divide (Offset, Offset);
118 Offset complex_exp (Offset);
121 Offset::operator *= (Offset z2)
123 *this = complex_multiply (*this, z2);
128 operator * (Real o1, Offset o2)
135 operator / (Offset o1, Real a)
142 operator * (Offset o1, Real o2)
149 mirror (Offset o, Axis a)
157 dot_product (Offset o1, Offset o2)
159 return o1[X_AXIS] * o2[X_AXIS] + o1[Y_AXIS] * o2[Y_AXIS];
162 #endif /* OFFSET_HH */