X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Foffset.cc;h=4693c113ef05b488d7cae97ea3f8da09e7852a28;hb=36b9825a04fd050c1de107b5d68db3c13916fe33;hp=f578b191f9a4c8b93f4f694a8b8f06beefb522c8;hpb=87eedcd59f4082cb0841528ad5bc82cb1d1191e3;p=lilypond.git diff --git a/flower/offset.cc b/flower/offset.cc index f578b191f9..4693c113ef 100644 --- a/flower/offset.cc +++ b/flower/offset.cc @@ -3,12 +3,11 @@ source file of the GNU LilyPond music typesetter - (c) 1997--2007 Han-Wen Nienhuys + (c) 1997--2009 Han-Wen Nienhuys */ #include "offset.hh" - #ifndef STANDALONE string Offset::to_string () const @@ -20,12 +19,6 @@ Offset::to_string () const } #endif -bool -isinf_b (Real r) -{ - return (fabs (r) > 1e20); -} - /* free bsd fix by John Galbraith */ @@ -34,7 +27,7 @@ Offset complex_multiply (Offset z1, Offset z2) { Offset z; - if (!isinf_b (z2[Y_AXIS])) + if (!isinf (z2[Y_AXIS])) { z[X_AXIS] = z1[X_AXIS] * z2[X_AXIS] - z1[Y_AXIS] * z2[Y_AXIS]; z[Y_AXIS] = z1[X_AXIS] * z2[Y_AXIS] + z1[Y_AXIS] * z2[X_AXIS]; @@ -75,6 +68,11 @@ Offset::arg () const return atan2 (coordinate_a_[Y_AXIS], coordinate_a_[X_AXIS]); } +Real +Offset::angle_degrees () const +{ + return arg () * 180 / M_PI; +} /** euclidian vector length / complex modulus */ @@ -91,5 +89,19 @@ Offset::is_sane () const return !isnan (coordinate_a_[X_AXIS]) && !isnan (coordinate_a_ [Y_AXIS]) && !isinf (coordinate_a_[X_AXIS]) - && !isnan (coordinate_a_[Y_AXIS]); + && !isinf (coordinate_a_[Y_AXIS]); +} + +Offset +Offset::direction () const +{ + Offset d = *this; + d /= length (); + return d; +} + +Offset +Offset::swapped () const +{ + return Offset (coordinate_a_[Y_AXIS], coordinate_a_[X_AXIS]); }