2 offset.cc -- implement Offset
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
13 Offset::to_string () const
16 s = string (" (") + ::to_string (coordinate_a_[X_AXIS]) + ", "
17 + ::to_string (coordinate_a_[Y_AXIS]) + ")";
25 return (fabs (r) > 1e20);
29 free bsd fix by John Galbraith
33 complex_multiply (Offset z1, Offset z2)
36 if (!isinf_b (z2[Y_AXIS]))
38 z[X_AXIS] = z1[X_AXIS] * z2[X_AXIS] - z1[Y_AXIS] * z2[Y_AXIS];
39 z[Y_AXIS] = z1[X_AXIS] * z2[Y_AXIS] + z1[Y_AXIS] * z2[X_AXIS];
45 complex_conjugate (Offset o)
47 o[Y_AXIS] = -o[Y_AXIS];
52 complex_divide (Offset z1, Offset z2)
54 z2 = complex_conjugate (z2);
55 Offset z = complex_multiply (z1, z2);
56 z *= 1 / z2.length ();
61 complex_exp (Offset o)
63 Real s = sin (o[Y_AXIS]);
64 Real c = cos (o[Y_AXIS]);
66 Real r = exp (o[X_AXIS]);
68 return Offset (r * c, r * s);
74 return atan2 (coordinate_a_[Y_AXIS], coordinate_a_[X_AXIS]);
78 euclidian vector length / complex modulus
81 Offset::length () const
83 return sqrt (sqr (coordinate_a_[X_AXIS])
84 + sqr (coordinate_a_[Y_AXIS]));
88 Offset::is_sane () const
90 return !isnan (coordinate_a_[X_AXIS])
91 && !isnan (coordinate_a_ [Y_AXIS])
92 && !isinf (coordinate_a_[X_AXIS])
93 && !isnan (coordinate_a_[Y_AXIS]);
97 Offset::direction () const