]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/simple-spacer.cc
(move_away_from_staffline): new function.
[lilypond.git] / lily / simple-spacer.cc
index 2915219c8f9ee1fce476873490e92322250227eb..7ad8eb3795a7d79b7dbee5b9126226a4bb643644 100644 (file)
    Perhaps this is not a bad thing, because the 1st looks better anyway.  */
 
 
+/*
+
+  positive force = expanding, negative force = compressing.
+  
+*/
+
 Simple_spacer::Simple_spacer ()
 {
   /*
@@ -218,15 +224,27 @@ Simple_spacer::my_solve_linelen ()
 void
 Simple_spacer::my_solve_natural_len ()
 {
+  Real line_len_force = 0.0;
+  
   while (is_active ())
     {
       force_ = active_blocking_force () >? 0.0;
+      Real conf = configuration_length ();
 
+      if (conf < line_len_)
+       {
+         line_len_force = force_
+           + (line_len_ - conf)
+           * active_springs_stiffness();
+       }
+      
       if (force_ < 1e-8) // ugh.,
        break;
       
       set_active_states ();
     }
+
+  force_ = line_len_force;
 }
 
 LY_DEFINE(ly_solve_spring_rod_problem, "ly:solve-spring-rod-problem",
@@ -251,22 +269,22 @@ LY_DEFINE(ly_solve_spring_rod_problem, "ly:solve-spring-rod-problem",
 
   bool is_ragged   = ragged == SCM_BOOL_T; 
   Simple_spacer spacer; 
-  for (SCM s = springs; ly_c_pair_p (s); s = ly_cdr (s))
+  for (SCM s = springs; scm_is_pair (s); s = scm_cdr (s))
     {
-      Real ideal = scm_to_double (ly_caar (s));
-      Real hooke = scm_to_double (ly_cadar (s));
+      Real ideal = scm_to_double (scm_caar (s));
+      Real hooke = scm_to_double (scm_cadar (s));
 
       spacer.add_spring (ideal, hooke);
     }
 
-  for (SCM s = rods; ly_c_pair_p (s); s = ly_cdr (s))
+  for (SCM s = rods; scm_is_pair (s); s = scm_cdr (s))
     {
-      SCM entry = ly_car (s);
-      int l = scm_to_int (ly_car (entry));
-      int r = scm_to_int (ly_cadr (entry));
-      entry = ly_cddr (entry);
+      SCM entry = scm_car (s);
+      int l = scm_to_int (scm_car (entry));
+      int r = scm_to_int (scm_cadr (entry));
+      entry = scm_cddr (entry);
       
-      Real distance = scm_to_double (ly_car (entry));
+      Real distance = scm_to_double (scm_car (entry));
       spacer.add_rod (l, r, distance);
     }
 
@@ -285,20 +303,21 @@ LY_DEFINE(ly_solve_spring_rod_problem, "ly:solve-spring-rod-problem",
       posns.push (posns.top() + l);
     }
 
+
+    
   SCM force_return = SCM_BOOL_F;
-  if (is_ragged)
+  if (!isinf (spacer.force_)
+      && spacer.is_active ())
     {
-      Real len = posns.top ();
-      if (spacer.line_len_ - len  >= 0)
-       force_return  = scm_from_double ((spacer.line_len_ - len)
-                                        * spacer.active_springs_stiffness ());
+      force_return = scm_from_double (spacer.force_);
     }
-  else if (not isinf (spacer.force_)
-          && spacer.is_active ())
+
+  if (is_ragged
+      && posns.top () > spacer.line_len_)
     {
-      force_return = scm_from_double (spacer.force_);
+      force_return = SCM_BOOL_F;
     }
-  
+
   SCM retval= SCM_EOL;
   for (int i = posns.size(); i--;)
     {
@@ -384,18 +403,8 @@ Simple_spacer_wrapper::solve (Column_x_positions *positions, bool ragged)
     */
   if (ragged)
     {
-      Real len = positions->config_.top ();
-      if (spacer_->line_len_ - len  >= 0)
-       positions->force_ = ((spacer_->line_len_ - len)
-                            * spacer_->active_springs_stiffness ());
-      else
-       {
-         positions->force_ = 0.0;
-         /*
-           Don't go past end-of-line in ragged right.
-          */
-         positions->satisfies_constraints_ = false;
-       }
+      positions->satisfies_constraints_ = 
+       positions->config_.top () < spacer_->line_len_ ;
     }
 
 
@@ -463,7 +472,7 @@ Simple_spacer_wrapper::add_columns (Link_array<Grob> const &icols)
   Link_array<Grob> cols (icols);
   
   for (int i =  cols.size (); i--;)
-    if (ly_c_pair_p (cols[i]->get_property ("between-cols")))
+    if (scm_is_pair (cols[i]->get_property ("between-cols")))
       {
        loose_cols_.push (cols[i]);
        cols.del (i);
@@ -475,10 +484,10 @@ Simple_spacer_wrapper::add_columns (Link_array<Grob> const &icols)
       Spring_smob *spring = 0;
 
       for (SCM s = cols[i]->get_property ("ideal-distances");
-          !spring && ly_c_pair_p (s);
-          s = ly_cdr (s))
+          !spring && scm_is_pair (s);
+          s = scm_cdr (s))
        {
-         Spring_smob *sp = unsmob_spring (ly_car (s));
+         Spring_smob *sp = unsmob_spring (scm_car (s));
          
          
          if (sp->other_ == cols[i+1])
@@ -499,13 +508,13 @@ Simple_spacer_wrapper::add_columns (Link_array<Grob> const &icols)
   for (int i=0; i < cols.size () - 1; i++)
     {
       for (SCM s = Spaceable_grob::get_minimum_distances (cols[i]);
-          ly_c_pair_p (s); s = ly_cdr (s))
+          scm_is_pair (s); s = scm_cdr (s))
        {
-         Grob * other = unsmob_grob (ly_caar (s));
+         Grob * other = unsmob_grob (scm_caar (s));
          int oi = cols.find_index (other);
          if (oi >= 0)
            {
-             spacer_->add_rod (i, oi, scm_to_double (ly_cdar (s)));
+             spacer_->add_rod (i, oi, scm_to_double (scm_cdar (s)));
            }
        }
     }