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