From: Han-Wen Nienhuys Date: Wed, 24 Jan 2007 01:26:17 +0000 (+0100) Subject: interval template and offset tweaks. X-Git-Tag: release/2.11.14-1~53 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=94fdd3f7932666ac1b3169854ea0a9964b5d32f3;p=lilypond.git interval template and offset tweaks. --- diff --git a/flower/include/interval.hh b/flower/include/interval.hh index ba28b1c76c..33e7c01630 100644 --- a/flower/include/interval.hh +++ b/flower/include/interval.hh @@ -103,11 +103,7 @@ struct Interval_t : public Drul_array return *this; } - Real linear_combination (Real x) const - { - Drul_array da (at (LEFT), at (RIGHT)); - return ::linear_combination (da, x); - } + Real linear_combination (Real x) const; string to_string () const; bool contains (T r) const; diff --git a/flower/include/offset.hh b/flower/include/offset.hh index 1995dd2554..0975e292b6 100644 --- a/flower/include/offset.hh +++ b/flower/include/offset.hh @@ -11,10 +11,6 @@ #include "std-string.hh" #include "real.hh" -class Offset; -Offset complex_multiply (Offset, Offset); -Offset complex_divide (Offset, Offset); -Offset complex_exp (Offset); /* This is a mixture a 2D vector. Sometimes it can @@ -100,15 +96,12 @@ public: coordinate_a_[a] = -coordinate_a_[a]; return *this; } - + Offset direction () const; + Real arg () const; Real length () const; bool is_sane () const; - Offset operator *= (Offset z2) - { - *this = complex_multiply (*this, z2); - return *this; - } + Offset operator *= (Offset z2); }; #include "arithmetic-operator.hh" @@ -116,6 +109,19 @@ IMPLEMENT_ARITHMETIC_OPERATOR (Offset, +); IMPLEMENT_ARITHMETIC_OPERATOR (Offset, -); IMPLEMENT_ARITHMETIC_OPERATOR (Offset, *); + + +Offset complex_multiply (Offset, Offset); +Offset complex_divide (Offset, Offset); +Offset complex_exp (Offset); + +inline Offset +Offset::operator *= (Offset z2) +{ + *this = complex_multiply (*this, z2); + return *this; +} + inline Offset operator * (Real o1, Offset o2) { diff --git a/flower/offset.cc b/flower/offset.cc index f578b191f9..d7ba419283 100644 --- a/flower/offset.cc +++ b/flower/offset.cc @@ -8,7 +8,6 @@ #include "offset.hh" - #ifndef STANDALONE string Offset::to_string () const @@ -93,3 +92,11 @@ Offset::is_sane () const && !isinf (coordinate_a_[X_AXIS]) && !isnan (coordinate_a_[Y_AXIS]); } + +Offset +Offset::direction () const +{ + Offset d = *this; + d /= length (); + return d; +} diff --git a/lily/template5.cc b/lily/template5.cc index cbf4f3bfa7..b669abb899 100644 --- a/lily/template5.cc +++ b/lily/template5.cc @@ -7,6 +7,8 @@ */ #include "moment.hh" +#include "real.hh" +#include "interval.hh" #include "interval.tcc" @@ -19,6 +21,7 @@ Interval_t::infinity () return infty; } + template<> string Interval_t::T_to_string (Rational a) @@ -27,3 +30,32 @@ Interval_t::T_to_string (Rational a) } template INTERVAL__INSTANTIATE (Rational); + + +template<> +Moment +Interval_t::infinity () +{ + Moment infty; + + infty.main_part_.set_infinite (1); + return infty; +} + + +template<> +string +Interval_t::T_to_string (Moment a) +{ + return a.to_string (); +} + +template INTERVAL__INSTANTIATE (Moment); + +template<> +Real +Interval_t::linear_combination (Real x) const +{ + Drul_array da (at (LEFT), at (RIGHT)); + return ::linear_combination (da, x); +}