From: Han-Wen Nienhuys <hanwen@lilypond.org>
Date: Mon, 18 Apr 2011 02:47:29 +0000 (-0300)
Subject: Handle situations that either one of above and below is a valid
X-Git-Tag: release/2.15.0-1~95
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=0c50b37efbd1fd0171d09eac35c97c38ac807461;p=lilypond.git

Handle situations that either one of above and below is a valid
configuration in Beam::shift_region_to_valid().

This fixes the regression introduced in
bf707a03756021f69e3f5d1a8246639a6a601099, leading to random quanting
(-O2 build) or crashes (debug build.)
---

diff --git a/lily/beam.cc b/lily/beam.cc
index 6845b1346b..627ffac0f0 100644
--- a/lily/beam.cc
+++ b/lily/beam.cc
@@ -1299,14 +1299,24 @@ Beam::shift_region_to_valid (SCM grob, SCM posns)
     {
       // We're good to go. Do nothing.
     }
+  else if (collision_free[DOWN].is_empty() != collision_free[UP].is_empty())
+    {
+      // Only one of them offers is feasible solution. Pick that one.
+      Interval v =
+        (!collision_free[DOWN].is_empty()) ?
+        collision_free[DOWN] : 
+        collision_free[UP];
+
+      beam_left_y = point_in_interval (v, 2.0);
+    }
   else if (!collision_free[DOWN].is_empty ()
-           || !collision_free[UP].is_empty ())
+           && !collision_free[UP].is_empty ())
     {
-      // We have space above or below collisions (or, no collisions at
-      // all).  Should we factor in the size of the collision_free
-      // interval as well?
+      // Above and below are candidates, take the one closest to the
+      // starting solution.
       Interval best =  
-        (collision_free[DOWN].distance(beam_left_y) < collision_free[UP].distance (beam_left_y)) ?
+        (collision_free[DOWN].distance (beam_left_y)
+         < collision_free[UP].distance (beam_left_y)) ?
         collision_free[DOWN] : collision_free[UP];
 
       beam_left_y = point_in_interval (best, 2.0);