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