From 1e66ec17ffe6cdca9a35522a9e391ebe9d11f0d6 Mon Sep 17 00:00:00 2001
From: Han-Wen Nienhuys <hanwen@xs4all.nl>
Date: Tue, 13 Jun 2006 12:24:23 +0000
Subject: [PATCH] (stem_dir_correction): don't inspect stem_end_position if
 correct_stem_dirs isn't set. Backportme.

---
 ChangeLog             |  3 +++
 lily/least-squares.cc | 13 +++++++------
 lily/note-spacing.cc  |  6 ++++--
 lily/stem.cc          |  9 +++++++++
 4 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 364957f6b6..b642a390cf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2006-06-13  Han-Wen Nienhuys  <hanwen@lilypond.org>
 
+	* lily/note-spacing.cc (stem_dir_correction): don't inspect
+	stem_end_position if correct_stem_dirs isn't set. Backportme. 
+
 	* lily/tuplet-bracket.cc (calc_positions): look at
 	stem-end-position for tuplet bracket slope. Fixes sloped tuplet
 	brackets narrower than beams. Backportme.
diff --git a/lily/least-squares.cc b/lily/least-squares.cc
index c7ca185bbf..2e0bcab3c6 100644
--- a/lily/least-squares.cc
+++ b/lily/least-squares.cc
@@ -28,22 +28,23 @@ minimise_least_squares (Real *coef, Real *offset,
       sqx += sqr (x);
       sxy += x*y;
     }
-  int N = input.size ();
+
+  int count = input.size ();
 
   *coef = 0.0;
   *offset = 0.;
 
-  Real den = (N * sqx - sqr (sx));
-  if (!N || !den)
+  Real den = (count * sqx - sqr (sx));
+  if (!count || !den)
     {
       programming_error ("minimise_least_squares ():  Nothing to minimise");
       *coef = 0.0;
-      *offset = N ? sy / N : 0.0;
+      *offset = count ? sy / count : 0.0;
     }
   else
     {
-      *coef = (N *sxy - sx * sy) / den;
-      *offset = (sy - (*coef) * sx) / N;
+      *coef = (count * sxy - sx * sy) / den;
+      *offset = (sy - (*coef) * sx) / count;
     }
 }
 
diff --git a/lily/note-spacing.cc b/lily/note-spacing.cc
index 8586cc5f4c..cb68f6b2df 100644
--- a/lily/note-spacing.cc
+++ b/lily/note-spacing.cc
@@ -323,12 +323,14 @@ Note_spacing::stem_dir_correction (Grob *me, Item *rcolumn,
 	    correct_stem_dirs = false;
 
 	  Interval hp = Stem::head_positions (stem);
-	  if (!hp.is_empty ())
+	  if (correct_stem_dirs
+	      && !hp.is_empty ())
 	    {
 	      Real chord_start = hp[sd];
 	      Real stem_end = Stem::stem_end_position (stem);
 
-	      stem_posns[d] = Interval (min (chord_start, stem_end), max (chord_start, stem_end));
+	      stem_posns[d] = Interval (min (chord_start, stem_end),
+					max (chord_start, stem_end));
 	      head_posns[d].unite (hp);
 	    }
 	}
diff --git a/lily/stem.cc b/lily/stem.cc
index 05fc5e7417..8527a21553 100644
--- a/lily/stem.cc
+++ b/lily/stem.cc
@@ -229,6 +229,10 @@ MAKE_SCHEME_CALLBACK (Stem, pure_height, 3)
 SCM
 Stem::pure_height (SCM smob, SCM start, SCM end)
 {
+  (void) start;
+  (void) end;
+  
+  
   Grob *me = unsmob_grob (smob);
   Real ss = Staff_symbol_referencer::staff_space (me);
   Real len = scm_to_double (calc_length (smob)) * ss / 2;
@@ -256,6 +260,11 @@ Stem::calc_stem_end_position (SCM smob)
   if (!head_count (me))
     return scm_from_double (0.0);
 
+  if (Grob *beam = unsmob_grob (me->get_object ("beam")))
+    {
+      (void) beam->get_property ("quantized-positions");
+      return me->get_property ("stem-end-position");
+    }
   
   Real ss = Staff_symbol_referencer::staff_space (me);
   int durlog = duration_log (me);
-- 
2.39.5