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