+ Grob *head_up = Note_column::first_head (clash_up);
+ Grob *head_down = Note_column::first_head (clash_down);
+
+ vector<int> ups = Stem::note_head_positions (Note_column::get_stem (clash_up));
+ vector<int> dps = Stem::note_head_positions (Note_column::get_stem (clash_down));
+
+ /* Too far apart to collide. */
+ if (ups[0] > dps.back () + 1)
+ return;
+
+ /* Merge heads if the notes lie the same line, or if the "stem-up-note" is
+ above the "stem-down-note". */
+ bool merge_possible = (ups[0] >= dps[0]) && (ups.back () >= dps.back ());
+
+ /* Do not merge notes typeset in different style. */
+ if (!ly_is_equal (head_up->get_property ("style"),
+ head_down->get_property ("style")))
+ merge_possible = false;
+
+ int up_ball_type = Rhythmic_head::duration_log (head_up);
+ int down_ball_type = Rhythmic_head::duration_log (head_down);
+
+ /* Do not merge whole notes (or longer, like breve, longa, maxima). */
+ if (merge_possible && (up_ball_type <= 0 || down_ball_type <= 0))
+ merge_possible = false;
+
+ if (merge_possible
+ && Rhythmic_head::dot_count (head_up) != Rhythmic_head::dot_count (head_down)
+ && !to_boolean (me->get_property ("merge-differently-dotted")))
+ merge_possible = false;
+
+ /* Can only merge different heads if merge-differently-headed is
+ set. */
+ if (merge_possible
+ && up_ball_type != down_ball_type
+ && !to_boolean (me->get_property ("merge-differently-headed")))
+ merge_possible = false;
+
+ /* Should never merge quarter and half notes, as this would make
+ them indistinguishable. */
+ if (merge_possible
+ && ((Stem::duration_log (stems[UP]) == 1
+ && Stem::duration_log (stems[DOWN]) == 2)
+ || (Stem::duration_log (stems[UP]) == 2
+ && Stem::duration_log (stems[DOWN]) == 1)))
+ merge_possible = false;