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