]> git.donarmstrong.com Git - lilypond.git/commitdiff
(rest_collision_callback): Fixed: partial rewrite.
authorJan Nieuwenhuizen <janneke@gnu.org>
Thu, 3 Oct 2002 16:33:51 +0000 (16:33 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Thu, 3 Oct 2002 16:33:51 +0000 (16:33 +0000)
ChangeLog
lily/beam.cc

index 96d453bc1ca410f1588e936eda3dc398aca4368e..d28a769b8fdb79113b60314bf7c6cda7b48fb2d0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2002-10-03  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+       * lily/beam.cc (rest_collision_callback): Fixed: partial rewrite.
+
 2002-10-02  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
 
        * lily/part-combine-music-iterator.cc (get_state): cleanup
index 333b623e49cd12bc2e4889fda428958f78933f2b..975b6685c2f7a3107624314920a5606668f65777 100644 (file)
@@ -1382,10 +1382,6 @@ Beam::rest_collision_callback (SCM element_smob, SCM axis)
       || !Beam::visible_stem_count (beam))
     return gh_double2scm (0.0);
 
-  // make callback for rest from this.
-  // todo: make sure this calced already.
-
-  //  Interval pos = ly_scm2interval (beam->get_grob_property ("positions"));
   Interval pos (0, 0);
   SCM s = beam->get_grob_property ("positions");
   if (gh_pair_p (s) && gh_number_p (ly_car (s)))
@@ -1398,28 +1394,47 @@ Beam::rest_collision_callback (SCM element_smob, SCM axis)
   Real dydx = dy && dx ? dy/dx : 0;
   
   Direction d = Stem::get_direction (stem);
-  Real beamy = (stem->relative_coordinate (0, X_AXIS) - x0) * dydx + pos[LEFT];
+  Real stem_y = (pos[LEFT]
+                + (stem->relative_coordinate (0, X_AXIS) - x0) * dydx)
+    * d;
+  
+  Real beam_translation = get_beam_translation (beam);
+  Real beam_thickness = gh_scm2double (beam->get_grob_property ("thickness"));
+  int beam_count = get_direction_beam_count (beam, d);
+  Real height_of_my_beams = beam_thickness
+    + (beam_count - 1) * beam_translation;
+  Real beam_y = stem_y - height_of_my_beams + beam_thickness / 2.0;
 
   Real staff_space = Staff_symbol_referencer::staff_space (rest);
 
-  
-  Real rest_dim = rest->extent (rest, Y_AXIS)[d]*2.0 / staff_space; // refp??
+  /* Better calculate relative-distance directly, rather than using
+     rest_dim? */
+  Grob *common_x = rest->common_refpoint (beam, Y_AXIS);
+  Real rest_dim = rest->extent (common_x, Y_AXIS)[d] / staff_space * d;
 
-  Real minimum_dist
-    = gh_scm2double (rest->get_grob_property ("minimum-beam-collision-distance"));
-  Real dist =
-    minimum_dist +  -d  * (beamy - rest_dim) >? 0;
+  Real minimum_distance = gh_scm2double
+    (rest->get_grob_property ("minimum-beam-collision-distance"));
 
+  Real distance = beam_y - rest_dim;
+  Real shift = 0;
+  if (distance < 0)
+    shift = minimum_distance - distance;
+  else if (minimum_distance > distance)
+    shift = minimum_distance - distance;
+      
   int stafflines = Staff_symbol_referencer::line_count (rest);
 
-  // move discretely by half spaces.
-  int discrete_dist = int (ceil (dist));
+  /* Always move discretely by half spaces */
+  Real discrete_shift = ceil (shift * 2.0) / 2.0;
 
-  // move by whole spaces inside the staff.
-  if (discrete_dist < stafflines+1)
-    discrete_dist = int (ceil (discrete_dist / 2.0)* 2.0);
+  /* Inside staff, move by whole spaces*/
+  if ((rest->extent (common_x, Y_AXIS)[d] + discrete_shift) * d
+      < stafflines / 2.0
+      ||(rest->extent (common_x, Y_AXIS)[-d] + discrete_shift) * -d
+      < stafflines / 2.0)
+    discrete_shift = ceil (discrete_shift);
 
-  return gh_double2scm (-d *  discrete_dist);
+  return gh_double2scm (-d * discrete_shift);
 }
 
 bool