X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Foffset.cc;h=67b97865e55ebe5f723fd2f717616257b72f9d48;hb=5b4b0d6e9a197e8f9eb085b7c2ad78b8be3e5cfc;hp=3fecbe70dae6e561682a5f508a5e4a13a672e616;hpb=161b1f2747316ea1652f080d3b7d0ae7848ed441;p=lilypond.git diff --git a/flower/offset.cc b/flower/offset.cc index 3fecbe70da..67b97865e5 100644 --- a/flower/offset.cc +++ b/flower/offset.cc @@ -3,29 +3,22 @@ source file of the GNU LilyPond music typesetter - (c) 1997--2005 Han-Wen Nienhuys + (c) 1997--2008 Han-Wen Nienhuys */ #include "offset.hh" - #ifndef STANDALONE -String +string Offset::to_string () const { - String s; - s = String (" (") + ::to_string (coordinate_a_[X_AXIS]) + ", " + string s; + s = string (" (") + ::to_string (coordinate_a_[X_AXIS]) + ", " + ::to_string (coordinate_a_[Y_AXIS]) + ")"; return s; } #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]); }