From 46ff5e800676d7ffdaf1465664898fac89ae7b83 Mon Sep 17 00:00:00 2001
From: Han-Wen Nienhuys <hanwen@xs4all.nl>
Date: Fri, 23 Dec 2005 13:03:36 +0000
Subject: [PATCH] * lily/slur-configuration.cc (fit_factor): more robust check
 for point in curve X-extent.

* lily/slur.cc (outside_slur_callback): return offset_scm, not 0.
(outside_slur_callback): check for 'outside avoidance.

* lily/slur-configuration.cc (score_extra_encompass): don't use
bound->column() == avoid->column() for checking extents, as this
doesn't work for accidentals.

* lily/slur-engraver.cc (acknowledge_extra_object): remove
DynamicText hardcoding.
---
 ChangeLog                  | 6 ++++++
 lily/slur-configuration.cc | 6 +++++-
 lily/slur.cc               | 9 +++++----
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ae9f2b229e..3ce49ae40b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2005-12-23  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
+	* lily/slur-configuration.cc (fit_factor): more robust check for
+	point in curve X-extent.
+
+	* lily/slur.cc (outside_slur_callback): return offset_scm, not 0.
+	(outside_slur_callback): check for 'outside avoidance.
+
 	* lily/slur-configuration.cc (score_extra_encompass): don't use
 	bound->column() == avoid->column() for checking extents, as this
 	doesn't work for accidentals. 
diff --git a/lily/slur-configuration.cc b/lily/slur-configuration.cc
index 4d32a9a545..cdd1d56736 100644
--- a/lily/slur-configuration.cc
+++ b/lily/slur-configuration.cc
@@ -81,7 +81,11 @@ fit_factor (Offset dz_unit, Offset dz_perp,
       Offset z = (avoid[i] - x0);
       Offset p (dot_product (z, dz_unit),
 		d * dot_product (z, dz_perp));
-      if (!curve_xext.contains (p[X_AXIS]))
+
+      Real eps = 0.01;
+      Interval pext = eps * Interval (-1,1) + p[X_AXIS];
+      pext.intersect (curve_xext);
+      if (pext.is_empty () || pext.length () <= 2.1* eps)
 	continue;
 
       Real y = curve.get_other_coordinate (X_AXIS, p[X_AXIS]);
diff --git a/lily/slur.cc b/lily/slur.cc
index 1672032d40..82f0e050c5 100644
--- a/lily/slur.cc
+++ b/lily/slur.cc
@@ -152,14 +152,15 @@ SCM
 Slur::outside_slur_callback (SCM grob, SCM offset_scm)
 {
   Grob *script = unsmob_grob (grob);
-  Grob *slur = unsmob_grob (script->get_object ("slur"));
+  Grob *slur = unsmob_grob (script->get_object ("slur")); 
 
   if (!slur)
     return offset_scm;
 
   SCM avoid = script->get_property ("avoid-slur");
-  if (avoid != ly_symbol2scm ("outside"))
-    return scm_from_int (0);
+  if (avoid != ly_symbol2scm ("outside")
+      && avoid != ly_symbol2scm ("around"))
+    return offset_scm;
   
   Direction dir = get_grob_direction (script);
   if (dir == CENTER)
@@ -208,7 +209,7 @@ Slur::outside_slur_callback (SCM grob, SCM offset_scm)
 	  /* Request shift if slur is contained script's Y, or if
 	     script is inside slur and avoid == outside.  */
 	  if (yext.contains (ys[k])
-	      || dir * ys[k] > dir * yext[-dir])
+	      || (dir * ys[k] > dir * yext[-dir] && avoid == ly_symbol2scm ("outside")))
 	    do_shift = true;
 	}
     }
-- 
2.39.5