+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]);
+
+ if (!intersect.is_empty ())
+ {
+ ret = abs (intersect.length ());
+
+ /*
+ Ugh. 7 is hardcoded.
+ */
+ ret = min (ret / 7, 1.0)
+ * left_stem_dir
+ * robust_scm2double (note_spacing->get_property ("stem-spacing-correction"), 0);
+ }
+ return ret;
+}
+
+static Real
+same_direction_correction (Grob *note_spacing, Drul_array<Interval> head_posns)
+{
+ /*
+ Correct for the following situation:
+
+ X X
+ | |
+ | |
+ | X |
+ | | |
+ ========
+
+ ^ move the center one to the left.
+
+
+ this effect seems to be much more subtle than the
+ stem-direction stuff (why?), and also does not scale with the
+ difference in stem length.
+
+ */
+
+ Interval hp = head_posns[LEFT];
+ hp.intersect (head_posns[RIGHT]);
+ if (!hp.is_empty ())
+ return 0;
+
+ Direction lowest
+ = (head_posns[LEFT][DOWN] > head_posns[RIGHT][UP]) ? RIGHT : LEFT;
+
+ Real delta = head_posns[-lowest][DOWN] - head_posns[lowest][UP];
+ Real corr = robust_scm2double (note_spacing->get_property ("same-direction-correction"), 0);
+
+ return (delta > 1) ? -lowest * corr : 0;
+}
+