lilypond-1.1.44
[lilypond.git] / flower / offset.cc
blob4e4e1e3bb0275bd98392d077b1ae03ab2e00ead3
1 /*
2 offset.cc -- implement Offset
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include <math.h>
10 #ifndef STANDALONE
11 #include "string.hh"
12 #endif
13 #include "offset.hh"
16 #ifndef STANDALONE
17 String
18 Offset::str () const
20 String s;
21 s = String("(") + to_str (coordinate_a_[X_AXIS]) + ", "
22 + to_str (coordinate_a_[Y_AXIS]) + ")";
23 return s;
25 #endif
28 bool
29 isinf_b (Real r)
31 return (fabs (r) > 1e20);
35 free bsd fix by John Galbraith
38 Offset
39 complex_multiply (Offset z1, Offset z2)
41 Offset z;
42 if(!isinf_b(z2[Y_AXIS]))
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];
47 return z;
52 Offset
53 complex_exp (Offset o)
55 Real s = sin (o[Y_AXIS]);
56 Real c = cos (o[Y_AXIS]);
58 Real r = exp (o[X_AXIS]);
60 return Offset(r*c, r*s);
63 Real
64 Offset::arg () const
66 return atan2 (y (), x());
69 /**
70 euclidian vector length / complex modulus
72 Real
73 Offset::length () const
75 return sqrt (sqr (x()) + sqr (y()));
77 void
78 Offset::mirror (Axis a)
80 coordinate_a_[a] = - coordinate_a_[a];