]> git.donarmstrong.com Git - lilypond.git/blob - flower/offset.cc
release: 1.0.1
[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--1998 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 Offset
28 complex_multiply (Offset z1, Offset z2)
29 {
30   Offset z;
31   z[X_AXIS] = z1[X_AXIS] * z2[X_AXIS] - z1[Y_AXIS]*z2[Y_AXIS];
32   z[Y_AXIS] = z1[X_AXIS] * z2[Y_AXIS] + z1[Y_AXIS] * z2[X_AXIS];
33   return z;
34 }
35
36 Offset
37 complex_exp (Offset o)
38 {
39   Real s = sin (o[Y_AXIS]);
40   Real c = cos (o[Y_AXIS]);
41   
42   Real r = exp (o[X_AXIS]);
43
44   return Offset(r*c, r*s);
45 }
46
47 Real
48 Offset::arg () const
49 {
50   return atan2 (y (), x());
51 }
52
53 /**
54    euclidian vector length / complex modulus
55  */
56 Real
57 Offset::length () const
58 {
59   return sqrt (sqr (x()) + sqr (y()));
60 }
61 void
62 Offset::mirror (Axis a)
63 {
64   coordinate_a_[a] = - coordinate_a_[a];
65 }