2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1996--2009 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"
29 This is a mixture a 2D vector. Sometimes it can
30 also be convenient to think of 2D vectors as complex numbers
31 (ie. x + i y). The naming of some methods reflects that.
36 Real coordinate_a_
[NO_AXES
];
38 Real
&operator [] (Axis i
)
40 return coordinate_a_
[i
];
43 Real
operator [] (Axis i
) const
45 return coordinate_a_
[i
];
48 Offset
&operator += (Offset o
)
50 (*this)[X_AXIS
] += o
[X_AXIS
];
51 (*this)[Y_AXIS
] += o
[Y_AXIS
];
55 Offset
operator - () const
59 o
[X_AXIS
] = -o
[X_AXIS
];
60 o
[Y_AXIS
] = -o
[Y_AXIS
];
64 Offset
&operator -= (Offset o
)
66 (*this)[X_AXIS
] -= o
[X_AXIS
];
67 (*this)[Y_AXIS
] -= o
[Y_AXIS
];
72 Offset
&scale (Offset o
)
74 (*this)[X_AXIS
] *= o
[X_AXIS
];
75 (*this)[Y_AXIS
] *= o
[Y_AXIS
];
80 Offset
&operator /= (Real a
)
86 Offset
&operator *= (Real a
)
94 Offset (Real ix
, Real iy
)
96 coordinate_a_
[X_AXIS
] = ix
;
97 coordinate_a_
[Y_AXIS
] = iy
;
102 coordinate_a_
[X_AXIS
] = coordinate_a_
[Y_AXIS
] = 0.0;
105 string
to_string () const;
107 Offset
&mirror (Axis a
)
109 coordinate_a_
[a
] = -coordinate_a_
[a
];
112 Offset
direction () const;
113 Offset
swapped () const;
116 Real
angle_degrees () const;
117 Real
length () const;
118 bool is_sane () const;
119 Offset
operator *= (Offset z2
);
122 #include "arithmetic-operator.hh"
123 IMPLEMENT_ARITHMETIC_OPERATOR (Offset
, +);
124 IMPLEMENT_ARITHMETIC_OPERATOR (Offset
, -);
125 IMPLEMENT_ARITHMETIC_OPERATOR (Offset
, *);
129 Offset
complex_multiply (Offset
, Offset
);
130 Offset
complex_divide (Offset
, Offset
);
131 Offset
complex_exp (Offset
);
134 Offset::operator *= (Offset z2
)
136 *this = complex_multiply (*this, z2
);
141 operator * (Real o1
, Offset o2
)
148 operator / (Offset o1
, Real a
)
155 operator * (Offset o1
, Real o2
)
162 mirror (Offset o
, Axis a
)
170 dot_product (Offset o1
, Offset o2
)
172 return o1
[X_AXIS
] * o2
[X_AXIS
] + o1
[Y_AXIS
] * o2
[Y_AXIS
];
175 #endif /* OFFSET_HH */