]> git.donarmstrong.com Git - lilypond.git/blob - flower/offset.cc
Update.
[lilypond.git] / flower / offset.cc
1 /*
2   offset.cc -- implement Offset
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "offset.hh"
10
11 #include <cmath>
12
13 #ifndef STANDALONE
14 String
15 Offset::to_string () const
16 {
17   String s;
18   s = String (" (") + ::to_string (coordinate_a_[X_AXIS]) + ", "
19     + ::to_string (coordinate_a_[Y_AXIS]) + ")";
20   return s;
21 }
22 #endif
23
24 bool
25 isinf_b (Real r)
26 {
27   return (fabs (r) > 1e20);
28 }
29
30 /*
31   free bsd fix by John Galbraith
32 */
33
34 Offset
35 complex_multiply (Offset z1, Offset z2)
36 {
37   Offset z;
38   if (!isinf_b (z2[Y_AXIS]))
39     {
40       z[X_AXIS] = z1[X_AXIS] * z2[X_AXIS] - z1[Y_AXIS] * z2[Y_AXIS];
41       z[Y_AXIS] = z1[X_AXIS] * z2[Y_AXIS] + z1[Y_AXIS] * z2[X_AXIS];
42     }
43   return z;
44 }
45
46 Offset
47 complex_conjugate (Offset o)
48 {
49   o[Y_AXIS] = -o[Y_AXIS];
50   return o;
51 }
52
53 Offset
54 complex_divide (Offset z1, Offset z2)
55 {
56   z2 = complex_conjugate (z2);
57   Offset z = complex_multiply (z1, z2);
58   z *= 1 / z2.length ();
59   return z;
60 }
61
62 Offset
63 complex_exp (Offset o)
64 {
65   Real s = sin (o[Y_AXIS]);
66   Real c = cos (o[Y_AXIS]);
67
68   Real r = exp (o[X_AXIS]);
69
70   return Offset (r * c, r * s);
71 }
72
73 Real
74 Offset::arg () const
75 {
76   return atan2 (coordinate_a_[Y_AXIS], coordinate_a_[X_AXIS]);
77 }
78
79 /**
80    euclidian vector length / complex modulus
81 */
82 Real
83 Offset::length () const
84 {
85   return sqrt (sqr (coordinate_a_[X_AXIS]) + sqr (coordinate_a_[Y_AXIS]));
86 }