]> git.donarmstrong.com Git - lilypond.git/blob - flower/offset.cc
*** empty log message ***
[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
25 bool
26 isinf_b (Real r)
27 {
28   return (fabs (r) > 1e20);
29 }
30
31 /*
32   free bsd fix by John Galbraith
33  */
34   
35 Offset
36 complex_multiply (Offset z1, Offset z2)
37 {
38   Offset z;
39   if (!isinf_b (z2[Y_AXIS]))
40   {
41       z[X_AXIS] = z1[X_AXIS] * z2[X_AXIS] - z1[Y_AXIS]*z2[Y_AXIS];
42       z[Y_AXIS] = z1[X_AXIS] * z2[Y_AXIS] + z1[Y_AXIS] * z2[X_AXIS];
43   }
44   return z;
45 }
46
47
48 Offset
49 complex_conjugate (Offset o)
50 {
51   o[Y_AXIS] = - o[Y_AXIS];
52   return o;
53 }
54
55 Offset
56 complex_divide (Offset z1, Offset z2)
57 {
58   z2 = complex_conjugate (z2);
59   Offset z = complex_multiply (z1, z2);
60   z *= 1/z2.length ();
61   return z;
62 }
63
64
65
66 Offset
67 complex_exp (Offset o)
68 {
69   Real s = sin (o[Y_AXIS]);
70   Real c = cos (o[Y_AXIS]);
71   
72   Real r = exp (o[X_AXIS]);
73
74   return Offset (r*c, r*s);
75 }
76
77 Real
78 Offset::arg () const
79 {
80   return atan2 (coordinate_a_[Y_AXIS], coordinate_a_[X_AXIS]);
81 }
82
83 /**
84    euclidian vector length / complex modulus
85  */
86 Real
87 Offset::length () const
88 {
89   return sqrt (sqr (coordinate_a_[X_AXIS]) + sqr (coordinate_a_[Y_AXIS]));
90 }