+
+ /*
+ This is incomplete: in case of an uneven number of rests, the
+ center one should be centered on the staff.
+ */
+ Drul_array< Link_array <Grob > > ordered_rests;
+ for (int i= 0; i < rests.size (); i++)
+ {
+ Grob * r = Note_column::get_rest (rests[i]);
+
+ Direction d = get_grob_direction (r);
+ if (d)
+ {
+ ordered_rests[d].push (rests[i]);
+ }
+ else
+ rests[d]->warning (_("rest direction not set. Cannot resolve collision."));
+ }
+
+ Direction d = LEFT;
+ do {
+ ordered_rests[d].sort (Note_column::shift_compare);
+ } while (flip (&d) != LEFT);
+
+ if (ordered_rests[UP].size () + ordered_rests[DOWN].size () < 2)
+ return SCM_UNSPECIFIED;
+
+ Grob *common = common_refpoint_of_array (ordered_rests[DOWN], me, Y_AXIS);
+ common = common_refpoint_of_array (ordered_rests[UP], common, Y_AXIS);
+
+ Real diff =
+ (ordered_rests[DOWN].top ()->extent (common, Y_AXIS)[UP]
+ - ordered_rests[UP].top ()->extent (common, Y_AXIS)[DOWN]) /staff_space;
+
+ if (diff > 0)
+ {
+ int amount_down = (int) ceil (diff / 2);
+ diff -= amount_down;
+ Note_column::translate_rests (ordered_rests[DOWN].top (),
+ -2 * amount_down);
+ if (diff > 0)
+ Note_column::translate_rests (ordered_rests[UP].top (),
+ 2 * int (ceil (diff)));
+ }
+
+ do {
+ for (int i = ordered_rests[d].size () -1; i-- > 0;)
+ {
+ Real last_y = ordered_rests[d][i+1]->extent (common, Y_AXIS)[d];
+ Real y = ordered_rests[d][i]->extent (common, Y_AXIS)[-d];
+
+ Real diff = d * ((last_y - y) /staff_space);
+ if (diff > 0)
+ Note_column::translate_rests (ordered_rests[d][i],d * (int) ceil (diff) * 2);
+ }
+ } while (flip (&d) != LEFT);