2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1996--2012 Han-Wen Nienhuys
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
24 #include "std-string.hh"
28 This is a mixture a 2D vector. Sometimes it can
29 also be convenient to think of 2D vectors as complex numbers
30 (ie. x + i y). The naming of some methods reflects that.
35 Real coordinate_a_[NO_AXES];
37 Real &operator [] (Axis i)
39 return coordinate_a_[i];
42 Real operator [] (Axis i) const
44 return coordinate_a_[i];
47 Offset &operator += (Offset o)
49 (*this)[X_AXIS] += o[X_AXIS];
50 (*this)[Y_AXIS] += o[Y_AXIS];
54 Offset operator - () const
58 o[X_AXIS] = -o[X_AXIS];
59 o[Y_AXIS] = -o[Y_AXIS];
63 Offset &operator -= (Offset o)
65 (*this)[X_AXIS] -= o[X_AXIS];
66 (*this)[Y_AXIS] -= o[Y_AXIS];
71 Offset &scale (Offset o)
73 (*this)[X_AXIS] *= o[X_AXIS];
74 (*this)[Y_AXIS] *= o[Y_AXIS];
79 Offset &operator /= (Real a)
85 Offset &operator *= (Real a)
93 Offset (Real ix, Real iy)
95 coordinate_a_[X_AXIS] = ix;
96 coordinate_a_[Y_AXIS] = iy;
101 coordinate_a_[X_AXIS] = coordinate_a_[Y_AXIS] = 0.0;
104 string to_string () const;
106 Offset &mirror (Axis a)
108 coordinate_a_[a] = -coordinate_a_[a];
111 Offset direction () const;
112 Offset swapped () const;
115 Real angle_degrees () const;
116 Real length () const;
117 bool is_sane () const;
118 Offset operator *= (Offset z2);
121 #include "arithmetic-operator.hh"
122 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, +);
123 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, -);
124 IMPLEMENT_ARITHMETIC_OPERATOR (Offset, *);
126 Offset complex_multiply (Offset, Offset);
127 Offset complex_divide (Offset, Offset);
128 Offset complex_exp (Offset);
131 Offset::operator *= (Offset z2)
133 *this = complex_multiply (*this, z2);
138 operator * (Real o1, Offset o2)
145 operator / (Offset o1, Real a)
152 operator * (Offset o1, Real o2)
159 mirror (Offset o, Axis a)
167 dot_product (Offset o1, Offset o2)
169 return o1[X_AXIS] * o2[X_AXIS] + o1[Y_AXIS] * o2[Y_AXIS];
172 #endif /* OFFSET_HH */