]> git.donarmstrong.com Git - lilypond.git/blob - flower/offset.cc
release: 0.1.57
[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 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8 #include <math.h>
9
10 #include "string.hh"
11 #include "offset.hh"
12
13
14 String
15 Offset::str () const
16 {
17   String s;
18   s = String("(") + coordinate_a_[X_AXIS] + ", " + coordinate_a_[Y_AXIS] + ")";
19   return s;
20 }
21
22
23 Offset
24 complex_multiply (Offset z1, Offset z2)
25 {
26   Offset z;
27   z[X_AXIS] = z1[X_AXIS] * z2[X_AXIS] - z1[Y_AXIS]*z2[Y_AXIS];
28   z[Y_AXIS] = z1[X_AXIS] * z2[Y_AXIS] - z1[Y_AXIS] * z2[X_AXIS];
29   return z;
30 }
31
32 Offset
33 complex_exp (Offset o)
34 {
35   Real s = sin (o[Y_AXIS]);
36   Real c = cos (o[Y_AXIS]);
37   
38   Real r = exp (o[X_AXIS]);
39
40   return Offset(r*c, r*s);
41 }
42
43 Real
44 Offset::arg () const
45 {
46   return atan2 (y (), x());
47 }
48
49 /**
50    euclidian vector length / complex modulus
51  */
52 Real
53 Offset::length () const
54 {
55   return sqrt (sqr (x()) + sqr (y()));
56 }
57 void
58 Offset::mirror (Axis a)
59 {
60   coordinate_a_[a] = - coordinate_a_[a];
61 }