]> git.donarmstrong.com Git - lilypond.git/blob - lily/idealspacing.cc
release: 1.0.1
[lilypond.git] / lily / idealspacing.cc
1 /*
2   idealspacing.cc -- implement Idealspacing
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996, 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "idealspacing.hh"
10 #include "p-col.hh"
11 #include "p-score.hh"
12 #include "debug.hh"
13
14 void
15 Idealspacing::print() const
16 {
17 #ifndef NPRINT
18   DOUT << "idealspacing {" ;
19   DOUT << "distance " << space_f_ << " strength " << hooke_f_;
20   DOUT << "left " << left_i_ << " right " << right_i_ << "}\n";
21 #endif
22 }
23
24 Idealspacing::Idealspacing()
25 {
26   space_f_ = 0.0;
27   hooke_f_ = 0.0;
28   left_i_ = -1;
29   right_i_ = -1;
30 }
31
32 void
33 Idealspacing::OK() const
34 {
35   assert (hooke_f_ >= 0);
36 }
37
38 Real
39 Idealspacing::energy_f(Real x) const
40 {
41   Real dx = (space_f_ - x);
42   
43   Real e =  sqr(dx);
44   if ( dx < 0)
45     e *= 4;                     // ugh.
46   
47   return hooke_f_ * e;
48 }