+ Drul_array<Skyline> skys = Spacing_interface::skylines (me, right_col);
+ Real distance = skys[LEFT].distance (skys[RIGHT]);
+ Real min_dist = max (0.0, distance);
+ Real min_desired_space = left_head_end + (min_dist - left_head_end + base_space - increment) / 2;
+ Real ideal = base_space - increment + left_head_end;
+
+ /* If we have a NonMusical column on the right, we measure the ideal distance
+ to the bar-line (if present), not the start of the column. */
+ if (!Paper_column::is_musical (right_col)
+ && !skys[RIGHT].is_empty ()
+ && to_boolean (me->get_property ("space-to-barline")))
+ {
+ Grob *bar = Pointer_group_interface::find_grob (right_col,
+ ly_symbol2scm ("elements"),
+ Bar_line::non_empty_barline);
+
+ if (bar)
+ {
+ Real shift = bar->extent (right_col, X_AXIS)[LEFT];
+ ideal -= shift;
+ min_desired_space -= max (shift, 0.0);
+ }
+ else
+ ideal -= right_col->extent (right_col, X_AXIS)[RIGHT];
+ }
+
+ ideal = max (ideal, min_desired_space);
+ stem_dir_correction (me, right_col, increment, &ideal, &min_desired_space);
+
+ /* TODO: grace notes look bad when things are stretched. Should we increase
+ their stretch strength? */
+ Spring ret (max (0.0, ideal), min_dist);
+ ret.set_inverse_compress_strength (max (0.0, ideal - min_desired_space));
+ ret.set_inverse_stretch_strength (max (0.1, base_space - increment));
+ return ret;
+}
+
+static Real
+knee_correction (Grob *note_spacing, Grob *right_stem, Real increment)
+{
+ Real note_head_width = increment;
+ Grob *head = right_stem ? Stem::support_head (right_stem) : 0;
+ Grob *rcolumn = dynamic_cast<Item *> (head)->get_column ();
+
+ Interval head_extent;
+ if (head)
+ {
+ head_extent = head->extent (rcolumn, X_AXIS);
+
+ if (!head_extent.is_empty ())
+ note_head_width = head_extent[RIGHT];
+
+ note_head_width -= Stem::thickness (right_stem);
+ }
+
+ return -note_head_width * get_grob_direction (right_stem)
+ * robust_scm2double (note_spacing->get_property ("knee-spacing-correction"), 0);
+}
+
+static Real
+different_directions_correction (Grob *note_spacing,
+ Drul_array<Interval> stem_posns,
+ Direction left_stem_dir)
+{
+ Real ret = 0.0;
+ Interval intersect = stem_posns[LEFT];
+ intersect.intersect (stem_posns[RIGHT]);