]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/idealspacing.cc
release: 1.1.4
[lilypond.git] / lily / idealspacing.cc
index 3ceaff1e6d5076e94180596b033cea07498c68e8..3966c6ad44119c8837c30f59156c7ed1ef0aea6b 100644 (file)
@@ -1,31 +1,47 @@
+/*
+  idealspacing.cc -- implement Idealspacing
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1996, 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
 #include "idealspacing.hh"
-#include "pcol.hh"
-#include "pscore.hh"
-#include "pstaff.hh"
+#include "p-col.hh"
+#include "p-score.hh"
 #include "debug.hh"
 
 void
 Idealspacing::print() const
 {
 #ifndef NPRINT
-    mtor << "idealspacing {" ;
-    mtor << "distance "<<space<< " strength " << hooke ;
-    mtor << "left " << left->rank() << " right " << right->rank() << "}\n";
+  DOUT << "idealspacing {" ;
+  DOUT << "distance " << space_f_ << " strength " << hooke_f_;
+  DOUT << "left " << cols_drul_[LEFT] << " right " << cols_drul_[RIGHT] << "}\n";
 #endif
 }
 
-Idealspacing::Idealspacing(const PCol * l,const PCol * r)
+Idealspacing::Idealspacing()
 {
-    space = 0.0;
-    hooke = 0.0;
-    left = l;
-    right = r;
+  space_f_ = 0.0;
+  hooke_f_ = 0.0;
+  cols_drul_[LEFT] = cols_drul_[RIGHT] = -1;
 }
 
 void
 Idealspacing::OK() const
 {
-#ifndef NDEBUG
-    assert(hooke >= 0 && left  && right);
-#endif    
+  assert (hooke_f_ >= 0);
+}
+
+Real
+Idealspacing::energy_f(Real x) const
+{
+  Real dx = (space_f_ - x);
+  
+  Real e =  sqr(dx);
+  if ( dx < 0)
+    e *= 4;                    // ugh.
+  
+  return hooke_f_ * e;
 }