From d981e2a1298923d26de7b972dd0156d632e17183 Mon Sep 17 00:00:00 2001
From: fred <fred>
Date: Wed, 27 Mar 2002 01:52:03 +0000
Subject: [PATCH] lilypond-1.5.10

---
 input/regression/collision-2.ly    |  9 +++
 input/regression/collision-mesh.ly | 24 +++++---
 input/regression/collisions.ly     | 51 ++++++++-------
 lily/collision.cc                  | 99 ++++++++++++++----------------
 4 files changed, 94 insertions(+), 89 deletions(-)
 create mode 100644 input/regression/collision-2.ly

diff --git a/input/regression/collision-2.ly b/input/regression/collision-2.ly
new file mode 100644
index 0000000000..04b9f80c94
--- /dev/null
+++ b/input/regression/collision-2.ly
@@ -0,0 +1,9 @@
+
+\score { \notes
+
+  \context Staff \notes <  
+	% the f and g on 4th beat are exceptionally ugh.
+	\context Voice=i { \stemUp c4 d e f g2 g4 a | }
+	\context Voice=ii { \stemDown g4 f e g  g2 g2 } 
+>}
+}
diff --git a/input/regression/collision-mesh.ly b/input/regression/collision-mesh.ly
index 25881933f7..571183ebc5 100644
--- a/input/regression/collision-mesh.ly
+++ b/input/regression/collision-mesh.ly
@@ -4,17 +4,25 @@ are resolved."
 }
 
 \score {
-  \context Staff \notes \relative c' {
+  \context Staff \notes \transpose c'' {
      \time 3/4
      % Here's what I was trying to do:
-     < \context Voice  = VI {\stemDown <g4 b g'> 
-     r4 r4 }
-       \context Voice=VII {\stemUp d'2.} >
+     < \context Voice  = VI {\stemDown
+       <g4 b g'>
+       <g4. b g'>       
+       <g4 b d'>
+       d'4
+       d'4.       
+       }
+       
+       \context Voice=VII {\stemUp
+         d'4
+         d'4.	 
+	 <a4 c'>
+	 <g4 b g'>
+	 <g4. b g'>	 	 
+	   } >
 
-     % Or:
-
-     <\context Voice = VI {\stemUp <g4 b g'>  r r}
-       \context Voice= VII {\stemDown d'2.} >
   }
 }
 
diff --git a/input/regression/collisions.ly b/input/regression/collisions.ly
index 89332dee95..2f1467326d 100644
--- a/input/regression/collisions.ly
+++ b/input/regression/collisions.ly
@@ -12,56 +12,52 @@ Tested = 	 "test the Collision resolution "
 }
 
 
-twovoice =  \context Staff \notes < 
-	\context Voice=i { \stemDown c4 d e f g2~  g4 a [c8 d e f] c2| }
-	\context Voice=ii { \stemUp g4 f e g ~ g2 g2  c4 g4 g2 } 
+twovoice =
+\notes \relative c' \context Staff \notes < 
+	\context Voice=i { \stemDown c4 c  d d e e f f }
+	\context Voice=ii { \stemUp g4 f f e e d d c } 
 >
 
-twovoicesteminvert =  \context Staff \notes <  
-	% the f and g on 4th beat are exceptionally ugh.
-	\context Voice=i { \stemUp c4 d e f g2 g4 a | }
-	\context Voice=ii { \stemDown g4 f e g  g2 g2 } 
+twovoicechords = \context Staff \notes <
+	\context Voice = i \relative c' {
+		\stemUp e4 d c b a g f
+	}
+	\context Voice = ii \relative c' {
+		\stemDown <a4 c> <a4 c> <a4 c> <a4 c> <a c>
+		<a c> <a c>  
+	}
 >
 
+
 threevoice =  \context Staff \notes <
 	\context Voice=i { \stemUp g4 f e f g a g2 }
-	\context Voice=ii { \stemUp \property Voice.NoteColumn \override #'horizontal-shift = #1
-		e2  e2  e2  e2 }
+	\context Voice=ii { \stemUp \shiftOn
+		e4 e e e e e e e  }
 	\context Voice=iii { \stemDown c4 d e d c d es }
 >
 
-chordstest =  \context Staff \notes <
-	\context Voice = i \relative c {
-		\stemUp e4 dis c f g f a b b
-	}
-	\context Voice = ii \relative c {
-		\stemDown <a4 c> <a4 c> <a4 e'> <a4 c> <e' a> <e a> <e a> <a c> <a d>
-	}
->
-
 hairyChord =  \context Staff \notes\relative c' <
      \context Voice=one {
- \property Voice.NoteColumn \override #'horizontal-shift = #0
+\shiftOff
 	\stemUp 
 	e4 
      }
      
      \context Voice=two {
 	\stemUp
+	\shiftOn
  \property Voice.NoteColumn \override #'horizontal-shift = #1
 	cis
      }
      
-     \context Voice=three {
- \property Voice.NoteColumn \override #'horizontal-shift = #2
-
+     \context Voice=three {	\shiftOnn
 	\stemUp 
 	ais
      }
      
      \context Voice=four {
         \stemDown
- \property Voice.NoteColumn \override #'horizontal-shift = #1
+	\shiftOn
 
 	fis
      }
@@ -69,10 +65,11 @@ hairyChord =  \context Staff \notes\relative c' <
 
 
 \score{
-	\notes \transpose c'' {  \twovoice  
-	\twovoicesteminvert 
-	\threevoice \break
-	 \chordstest
+	\notes \transpose c'' {
+	   \twovoice
+	   \twovoicechords
+	
+	\threevoice 
 	 \hairyChord
 	}
 	
diff --git a/lily/collision.cc b/lily/collision.cc
index 39e906b6ab..d0bcf4eec2 100644
--- a/lily/collision.cc
+++ b/lily/collision.cc
@@ -56,8 +56,28 @@ check_meshing_chords (Grob*me,
   Grob * nd_l = Note_column::first_head (cd);
       
      
+
+  /*
+    this case (distant half collide), 
+    
+        |
+      x |
+     | x
+     |
+
+   the noteheads may be closer than this case (close half collide)
+
+       |
+       |
+      x 
+     x
+    |
+    |
+    
+   */
   
-  bool half_collide = false;
+  bool close_half_collide = false;
+  bool distant_half_collide = false;  
   bool full_collide = false;  
 
   /*
@@ -86,7 +106,7 @@ check_meshing_chords (Grob*me,
 
   bool touch = (ups[0] - dps.top () >= 0);
   
-  bool merge_possible = (ups[0] >= dps[0]) && (ups.top () <= dps.top ());
+  bool merge_possible = (ups[0] >= dps[0]) && (ups.top () >= dps.top ());
 
   merge_possible = merge_possible &&
     Rhythmic_head::balltype_i (nu_l) == Rhythmic_head::balltype_i (nd_l);
@@ -100,7 +120,10 @@ check_meshing_chords (Grob*me,
     if (abs (ups[i] - dps[j]) == 1)
       {
 	merge_possible = false;
-	half_collide = true;
+	if (ups[i] > dps[j])
+	  close_half_collide = true;
+	else
+	  distant_half_collide = true;
       }
     else if (ups[i]==dps[j])
       full_collide = true;
@@ -127,21 +150,34 @@ check_meshing_chords (Grob*me,
   
   Real shift_amount = 1;
 
-  if ( touch)
+  if (touch)
     shift_amount *= -1;
-  else
+
   /*
     for full collisions, the right hand head may obscure dots, so
     make sure the dotted heads go to the right.
    */
-    if ((Rhythmic_head::dot_count (nu_l) < Rhythmic_head::dot_count (nd_l)
-	   && full_collide))
-      shift_amount *= -1;
+  if ((Rhythmic_head::dot_count (nu_l) > Rhythmic_head::dot_count (nd_l)
+       && full_collide))
+    shift_amount = 1;
 
+  /*
+    TODO: these numbers are magic; should devise a set of grob props
+    to tune this behavior.  */
+  
   if (merge_possible)
     shift_amount *= 0.0;
-  else if (half_collide || full_collide) 
+  else if (close_half_collide && !touch)
+    shift_amount *= 0.52;
+  else if (distant_half_collide && !touch)
+    shift_amount *= 0.4;
+  else if (distant_half_collide || close_half_collide || full_collide)
     shift_amount *= 0.5;
+  /*
+    we're meshing.
+  */
+  else if (Rhythmic_head::dot_count (nu_l) || Rhythmic_head::dot_count (nd_l))
+    shift_amount *= 0.1;
   else
     shift_amount *= 0.25;
 
@@ -295,51 +331,6 @@ Collision::automatic_shift (Grob *me)
 
   check_meshing_chords (me, &offsets, extents, clash_groups);
   
-#if 0  
-  /*
-    if the up and down version are close, and can not be merged, move
-    all of them again. */
-  if (extents[UP].size () && extents[DOWN].size ())
-    {
-      Grob *cu_l =clash_groups[UP][0];
-      Grob *cd_l =clash_groups[DOWN][0];
-
-
-      /*
-	TODO.
-       */
-      Grob * nu_l= Note_column::first_head (cu_l);
-      Grob * nd_l = Note_column::first_head (cd_l);
-      
-      int downpos = Note_column::head_positions_interval (cd_l)[BIGGER];
-      int uppos = Note_column::head_positions_interval (cu_l)[SMALLER];      
-      
-      bool merge  =
-	downpos == uppos
-	&& Rhythmic_head::balltype_i (nu_l) == Rhythmic_head::balltype_i (nd_l);
-
-
-      if (!to_boolean (me->get_grob_property ("merge-differently-dotted")))
-	merge = merge && Rhythmic_head::dot_count (nu_l) == Rhythmic_head::dot_count (nd_l);
-
-      /*
-	notes are close, but can not be merged.  Shift
-       */
-      if (abs (uppos - downpos) < 2 && !merge)
-	  do
-	  {
-	    for (int i=0; i < clash_groups[d].size (); i++)
-	      {
-		if(Rhythmic_head::dot_count (nu_l) > Rhythmic_head::dot_count (nd_l))
-		  offsets[d][i] += d * 0.5;
-		else 
-		  offsets[d][i] -= d * 0.5;
-	      }
-	  }
-	  while ((flip (&d))!= UP);
-    }
-#endif
-  
   do
     {
       for (int i=0; i < clash_groups[d].size (); i++)
-- 
2.39.5