2 offset.cc -- implement Offset
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
17 Offset::to_string () const
20 s = String (" (") + ::to_string (coordinate_a_[X_AXIS]) + ", "
21 + ::to_string (coordinate_a_[Y_AXIS]) + ")";
29 return (fabs (r) > 1e20);
33 free bsd fix by John Galbraith
37 complex_multiply (Offset z1, Offset z2)
40 if (!isinf_b (z2[Y_AXIS]))
42 z[X_AXIS] = z1[X_AXIS] * z2[X_AXIS] - z1[Y_AXIS] * z2[Y_AXIS];
43 z[Y_AXIS] = z1[X_AXIS] * z2[Y_AXIS] + z1[Y_AXIS] * z2[X_AXIS];
49 complex_conjugate (Offset o)
51 o[Y_AXIS] = -o[Y_AXIS];
56 complex_divide (Offset z1, Offset z2)
58 z2 = complex_conjugate (z2);
59 Offset z = complex_multiply (z1, z2);
60 z *= 1 / z2.length ();
65 complex_exp (Offset o)
67 Real s = sin (o[Y_AXIS]);
68 Real c = cos (o[Y_AXIS]);
70 Real r = exp (o[X_AXIS]);
72 return Offset (r * c, r * s);
78 return atan2 (coordinate_a_[Y_AXIS], coordinate_a_[X_AXIS]);
82 euclidian vector length / complex modulus
85 Offset::length () const
87 return sqrt (sqr (coordinate_a_[X_AXIS]) + sqr (coordinate_a_[Y_AXIS]));
91 Offset::is_sane () const
93 return !isnan (coordinate_a_[X_AXIS])
94 && !isnan (coordinate_a_ [Y_AXIS])
95 && !isinf (coordinate_a_[X_AXIS])
96 && !isnan (coordinate_a_[Y_AXIS]);