From f4e19a4b25dd4a6c372f27f238e0737e63cf2e0c Mon Sep 17 00:00:00 2001
From: hanwen <hanwen>
Date: Sun, 15 Jun 2003 19:49:17 +0000
Subject: [PATCH] * scm/define-grobs.scm (all-grob-descriptions): set
 knee-spacing-correction to 1.0

* lily/note-spacing.cc (stem_dir_correction): compute knee
correction using stem-thickness and head width.

* scm/define-grobs.scm (all-grob-descriptions): set
beamed-extreme-minimum-free-lengths to 1.25 for 32nd beams.
This fixes 32nd beams for noteheads in spaces quants.
---
 ChangeLog                        |  6 ++++++
 input/regression/spacing-knee.ly |  9 +++++++--
 input/test/knee-sym.ly           |  2 +-
 lily/note-spacing.cc             | 30 ++++++++++++++++++++++++++----
 scm/define-grobs.scm             |  8 ++++++--
 5 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f8c6c5a166..ca43ff3871 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2003-06-15  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
 
+	* scm/define-grobs.scm (all-grob-descriptions): set
+	knee-spacing-correction to 1.0
+
+	* lily/note-spacing.cc (stem_dir_correction): compute knee
+	correction using stem-thickness and head width.
+
 	* input/regression/beam-quanting-horizontal.ly: update texidoc
 
 	* scm/define-grobs.scm (all-grob-descriptions): set
diff --git a/input/regression/spacing-knee.ly b/input/regression/spacing-knee.ly
index f6176b5293..300f8c96ed 100644
--- a/input/regression/spacing-knee.ly
+++ b/input/regression/spacing-knee.ly
@@ -1,13 +1,18 @@
 \version "1.7.18"
 \header {
-texidoc = "For knees, the spacing correction is such that the
-stems are put at regular distances.
+
+    texidoc = "For knees, the spacing correction is such that the
+stems are put at regular distances. This effect takes into account the
+width of the note heads and the thickness of the stem.
 "
     }
 \score { \notes
 {
+g'8-[ g'8-]     
  g''8-[ g g'' g''] 
 
+ %\property Voice.Stem \override #'thickness = #10 
+ %g''8-[ g g'' g''] 
     }
 \paper { raggedright = ##t}
      }
diff --git a/input/test/knee-sym.ly b/input/test/knee-sym.ly
index 132b648db7..6e618eedbb 100644
--- a/input/test/knee-sym.ly
+++ b/input/test/knee-sym.ly
@@ -6,6 +6,6 @@
 	\stemUp [ b8 \stemDown b'']
     }
     \paper{
-	linewidth = 0.0
+	raggedright = ##t 
     }
 }%% new-chords-done %%
diff --git a/lily/note-spacing.cc b/lily/note-spacing.cc
index 8c291dbad3..9aa593f669 100644
--- a/lily/note-spacing.cc
+++ b/lily/note-spacing.cc
@@ -18,6 +18,7 @@
 #include "separation-item.hh"
 #include "staff-spacing.hh"
 #include "accidental-placement.hh"
+#include "paper-def.hh"
 
 void
 Note_spacing::get_spacing (Grob *me, Item* right_col,
@@ -227,6 +228,7 @@ Note_spacing::stem_dir_correction (Grob*me, Item * rcolumn,
 			me->get_grob_property ("right-items"));
 
   Drul_array<Grob*> beams_drul(0,0);
+  Drul_array<Grob*> stems_drul(0,0);
   
   stem_dirs[LEFT] = stem_dirs[RIGHT] = CENTER;
   Interval intersect;
@@ -274,6 +276,7 @@ Note_spacing::stem_dir_correction (Grob*me, Item * rcolumn,
 	      continue;
 	    }
 
+	  stems_drul[d] = stem;
 	  beams_drul[d] = Stem::get_beam (stem);
 	    
 	  
@@ -295,8 +298,6 @@ Note_spacing::stem_dir_correction (Grob*me, Item * rcolumn,
 	      correct_stem_dirs = false;
 	    }
 	  
-
-	  
 	  Interval hp  = Stem::head_positions (stem);
 	  Real chord_start = hp[sd];	  
 	  Real stem_end = Stem::stem_end_position (stem);
@@ -326,11 +327,32 @@ Note_spacing::stem_dir_correction (Grob*me, Item * rcolumn,
     {
       if (beams_drul[LEFT] && beams_drul[LEFT] == beams_drul[RIGHT])
 	{
+	  
 	  /*
 	    this is a knee: maximal correction.
 	  */
-	  
-	  correction = increment* stem_dirs[LEFT];
+	  Real note_head_width = increment;
+	  Grob * st = stems_drul[RIGHT];
+	  Grob * head = st ? Stem::support_head (st)  : 0;
+
+	  Interval head_extent;
+	  if (head)
+	    {
+	      head_extent = head->extent (rcolumn, X_AXIS);
+
+	      if (!head_extent.empty_b())
+		note_head_width = head_extent[RIGHT];
+
+	      if (st)
+		{
+		  Real thick = gh_scm2double (st->get_grob_property ("thickness"))
+		    * st->get_paper ()->get_var ("linethickness");
+
+		  note_head_width -= thick;
+		}
+	    }
+
+	  correction = note_head_width* stem_dirs[LEFT];
 	  correction *= gh_scm2double (me->get_grob_property ("knee-spacing-correction"));
 	  *fixed += correction;
 	}
diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm
index e2e527b4e5..f560463d0e 100644
--- a/scm/define-grobs.scm
+++ b/scm/define-grobs.scm
@@ -851,13 +851,17 @@
      . (
 	(breakable . #t)
 	(stem-spacing-correction . 0.4)
-	(knee-spacing-correction . 0.75)
+
 	(meta . ((interfaces . (spacing-interface staff-spacing-interface item-interface ))))
 	))
     (NoteSpacing
      . (
 	(stem-spacing-correction . 0.5)
-	(knee-spacing-correction . 0.75)
+
+	;; Changed this from 0.75.
+	;; If you ever change this back, please document! --hwn
+	
+	(knee-spacing-correction . 1.0)
 	(meta . ((interfaces . (spacing-interface note-spacing-interface item-interface ))))
 	))
 
-- 
2.39.5