]> git.donarmstrong.com Git - lilypond.git/blob - flower/offset.cc
(make-ps-images): use png16m again, for sake
[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--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "offset.hh"
10
11
12 #include <math.h>
13 #include <cmath>
14
15 #ifndef STANDALONE
16 String
17 Offset::to_string () const
18 {
19   String s;
20   s = String (" (") + ::to_string (coordinate_a_[X_AXIS]) + ", "
21     + ::to_string (coordinate_a_[Y_AXIS]) + ")";
22   return s;
23 }
24 #endif
25
26 bool
27 isinf_b (Real r)
28 {
29   return (fabs (r) > 1e20);
30 }
31
32 /*
33   free bsd fix by John Galbraith
34 */
35
36 Offset
37 complex_multiply (Offset z1, Offset z2)
38 {
39   Offset z;
40   if (!isinf_b (z2[Y_AXIS]))
41     {
42       z[X_AXIS] = z1[X_AXIS] * z2[X_AXIS] - z1[Y_AXIS] * z2[Y_AXIS];
43       z[Y_AXIS] = z1[X_AXIS] * z2[Y_AXIS] + z1[Y_AXIS] * z2[X_AXIS];
44     }
45   return z;
46 }
47
48 Offset
49 complex_conjugate (Offset o)
50 {
51   o[Y_AXIS] = -o[Y_AXIS];
52   return o;
53 }
54
55 Offset
56 complex_divide (Offset z1, Offset z2)
57 {
58   z2 = complex_conjugate (z2);
59   Offset z = complex_multiply (z1, z2);
60   z *= 1 / z2.length ();
61   return z;
62 }
63
64 Offset
65 complex_exp (Offset o)
66 {
67   Real s = sin (o[Y_AXIS]);
68   Real c = cos (o[Y_AXIS]);
69
70   Real r = exp (o[X_AXIS]);
71
72   return Offset (r * c, r * s);
73 }
74
75 Real
76 Offset::arg () const
77 {
78   return atan2 (coordinate_a_[Y_AXIS], coordinate_a_[X_AXIS]);
79 }
80
81 /**
82    euclidian vector length / complex modulus
83 */
84 Real
85 Offset::length () const
86 {
87   return sqrt (sqr (coordinate_a_[X_AXIS]) + sqr (coordinate_a_[Y_AXIS]));
88 }
89
90 bool
91 Offset::is_sane () const
92 {
93   return !isnan (coordinate_a_[X_AXIS])
94     && !isnan (coordinate_a_ [Y_AXIS])
95     && !isinf (coordinate_a_[X_AXIS]) 
96     && !isnan (coordinate_a_[Y_AXIS]);
97 }