From beedd09c78a7725d0d52b93c59e3d9840681c3e5 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 17 Apr 2011 23:47:29 -0300 Subject: [PATCH] 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.) --- lily/beam.cc | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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); -- 2.39.2