Fix missing volta bracket edge when using new double repeats.
[lilypond.git] / flower / offset.cc
blob91ff41be10bf962cab4a524f2be2ea28670c231a
1 /*
2 offset.cc -- implement Offset
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "offset.hh"
11 #ifndef STANDALONE
12 string
13 Offset::to_string () const
15 string s;
16 s = string (" (") + ::to_string (coordinate_a_[X_AXIS]) + ", "
17 + ::to_string (coordinate_a_[Y_AXIS]) + ")";
18 return s;
20 #endif
23 free bsd fix by John Galbraith
26 Offset
27 complex_multiply (Offset z1, Offset z2)
29 Offset z;
30 if (!isinf (z2[Y_AXIS]))
32 z[X_AXIS] = z1[X_AXIS] * z2[X_AXIS] - z1[Y_AXIS] * z2[Y_AXIS];
33 z[Y_AXIS] = z1[X_AXIS] * z2[Y_AXIS] + z1[Y_AXIS] * z2[X_AXIS];
35 return z;
38 Offset
39 complex_conjugate (Offset o)
41 o[Y_AXIS] = -o[Y_AXIS];
42 return o;
45 Offset
46 complex_divide (Offset z1, Offset z2)
48 z2 = complex_conjugate (z2);
49 Offset z = complex_multiply (z1, z2);
50 z *= 1 / z2.length ();
51 return z;
54 Offset
55 complex_exp (Offset o)
57 Real s = sin (o[Y_AXIS]);
58 Real c = cos (o[Y_AXIS]);
60 Real r = exp (o[X_AXIS]);
62 return Offset (r * c, r * s);
65 Real
66 Offset::arg () const
68 return atan2 (coordinate_a_[Y_AXIS], coordinate_a_[X_AXIS]);
71 Real
72 Offset::angle_degrees () const
74 return arg () * 180 / M_PI;
76 /**
77 euclidian vector length / complex modulus
79 Real
80 Offset::length () const
82 return sqrt (sqr (coordinate_a_[X_AXIS])
83 + sqr (coordinate_a_[Y_AXIS]));
86 bool
87 Offset::is_sane () const
89 return !isnan (coordinate_a_[X_AXIS])
90 && !isnan (coordinate_a_ [Y_AXIS])
91 && !isinf (coordinate_a_[X_AXIS])
92 && !isinf (coordinate_a_[Y_AXIS]);
95 Offset
96 Offset::direction () const
98 Offset d = *this;
99 d /= length ();
100 return d;
103 Offset
104 Offset::swapped () const
106 return Offset (coordinate_a_[Y_AXIS], coordinate_a_[X_AXIS]);