2 offset.cc -- implement Offset
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
13 Offset::to_string () const
16 s
= string (" (") + ::to_string (coordinate_a_
[X_AXIS
]) + ", "
17 + ::to_string (coordinate_a_
[Y_AXIS
]) + ")";
23 free bsd fix by John Galbraith
27 complex_multiply (Offset z1
, Offset z2
)
30 if (!isinf (z2
[Y_AXIS
]))
32 z
[X_AXIS
] = z1
[X_AXIS
] * z2
[X_AXIS
] - z1
[Y_AXIS
] * z2
[Y_AXIS
];
33 z
[Y_AXIS
] = z1
[X_AXIS
] * z2
[Y_AXIS
] + z1
[Y_AXIS
] * z2
[X_AXIS
];
39 complex_conjugate (Offset o
)
41 o
[Y_AXIS
] = -o
[Y_AXIS
];
46 complex_divide (Offset z1
, Offset z2
)
48 z2
= complex_conjugate (z2
);
49 Offset z
= complex_multiply (z1
, z2
);
50 z
*= 1 / z2
.length ();
55 complex_exp (Offset o
)
57 Real s
= sin (o
[Y_AXIS
]);
58 Real c
= cos (o
[Y_AXIS
]);
60 Real r
= exp (o
[X_AXIS
]);
62 return Offset (r
* c
, r
* s
);
68 return atan2 (coordinate_a_
[Y_AXIS
], coordinate_a_
[X_AXIS
]);
72 Offset::angle_degrees () const
74 return arg () * 180 / M_PI
;
77 euclidian vector length / complex modulus
80 Offset::length () const
82 return sqrt (sqr (coordinate_a_
[X_AXIS
])
83 + sqr (coordinate_a_
[Y_AXIS
]));
87 Offset::is_sane () const
89 return !isnan (coordinate_a_
[X_AXIS
])
90 && !isnan (coordinate_a_
[Y_AXIS
])
91 && !isinf (coordinate_a_
[X_AXIS
])
92 && !isinf (coordinate_a_
[Y_AXIS
]);
96 Offset::direction () const
104 Offset::swapped () const
106 return Offset (coordinate_a_
[Y_AXIS
], coordinate_a_
[X_AXIS
]);