]> git.donarmstrong.com Git - lilypond.git/blob - flower/offset.cc
patch::: 1.3.136.jcn3
[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--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include <math.h>
9
10 #ifndef STANDALONE
11 #include "string.hh"
12 #endif
13 #include "offset.hh"
14
15
16 #ifndef STANDALONE
17 String
18 Offset::str () const
19 {
20   String s;
21   s = String (" (") + to_str (coordinate_a_[X_AXIS]) + ", " 
22     + to_str (coordinate_a_[Y_AXIS]) + ")";
23   return s;
24 }
25 #endif
26
27
28 bool
29 isinf_b (Real r)
30 {
31   return (fabs (r) > 1e20);
32 }
33
34 /*
35   free bsd fix by John Galbraith
36  */
37   
38 Offset
39 complex_multiply (Offset z1, Offset z2)
40 {
41   Offset z;
42   if (!isinf_b (z2[Y_AXIS]))
43   {
44       z[X_AXIS] = z1[X_AXIS] * z2[X_AXIS] - z1[Y_AXIS]*z2[Y_AXIS];
45       z[Y_AXIS] = z1[X_AXIS] * z2[Y_AXIS] + z1[Y_AXIS] * z2[X_AXIS];
46   }
47   return z;
48 }
49
50
51 Offset
52 complex_conjugate (Offset o)
53 {
54   o[Y_AXIS] = - o[Y_AXIS];
55   return o;
56 }
57
58 Offset
59 complex_divide (Offset z1, Offset z2)
60 {
61   z2 = complex_conjugate (z2);
62   Offset z = complex_multiply (z1, z2);
63   z *= 1/z2.length ();
64   return z;
65 }
66
67
68
69 Offset
70 complex_exp (Offset o)
71 {
72   Real s = sin (o[Y_AXIS]);
73   Real c = cos (o[Y_AXIS]);
74   
75   Real r = exp (o[X_AXIS]);
76
77   return Offset (r*c, r*s);
78 }
79
80 Real
81 Offset::arg () const
82 {
83   return atan2 (coordinate_a_[Y_AXIS], coordinate_a_[X_AXIS]);
84 }
85
86 /**
87    euclidian vector length / complex modulus
88  */
89 Real
90 Offset::length () const
91 {
92   return sqrt (sqr (coordinate_a_[X_AXIS]) + sqr (coordinate_a_[Y_AXIS]));
93 }
94 void
95 Offset::mirror (Axis a)
96 {
97   coordinate_a_[a] = - coordinate_a_[a];
98 }