From a5aef82319c40d7c147edfdab10d5146d2541cb0 Mon Sep 17 00:00:00 2001 From: Neil Puttock Date: Tue, 7 Oct 2008 21:34:05 +0100 Subject: [PATCH] Fix arpeggio overshoot for some chords which reach centre line. This patch fixes a rounding error in Arpeggio::print () that occurs when a chord reaches the centre line, resulting in an extra squiggle being added. --- input/regression/arpeggio-no-overshoot.ly | 15 +++++++++++++++ lily/arpeggio.cc | 17 ++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 input/regression/arpeggio-no-overshoot.ly diff --git a/input/regression/arpeggio-no-overshoot.ly b/input/regression/arpeggio-no-overshoot.ly new file mode 100644 index 0000000000..ec47ee1181 --- /dev/null +++ b/input/regression/arpeggio-no-overshoot.ly @@ -0,0 +1,15 @@ +\version "2.11.62" + +\header { + texidoc = "Arpeggios do not overshoot the highest note head. +The first chord in this example simulates overshoot using +@code{'positions} for comparison with the correct behaviour." +} + +\relative c' { + % simulate overshoot for comparison + \once \override Arpeggio #'positions = #'(-3 . 1) + 1\arpeggio + 1\arpeggio + 2\arpeggio \arpeggio +} diff --git a/lily/arpeggio.cc b/lily/arpeggio.cc index 80858426bc..22351d3b13 100644 --- a/lily/arpeggio.cc +++ b/lily/arpeggio.cc @@ -97,6 +97,16 @@ Arpeggio::print (SCM smob) Font_metric *fm = Font_interface::get_default_font (me); Stencil squiggle = fm->find_by_name ("scripts.arpeggio"); + /* + Compensate for rounding error which may occur when a chord + reaches the center line, resulting in an extra squiggle + being added to the arpeggio stencil. This value is appreciably + larger than the rounding error, which is in the region of 1e-16 + for a global-staff-size of 20, but small enough that it does not + interfere with smaller staff sizes. + */ + const Real epsilon = 1e-3; + Stencil arrow; if (dir) { @@ -104,9 +114,10 @@ Arpeggio::print (SCM smob) heads[dir] -= dir * arrow.extent (Y_AXIS).length (); } - for (Real y = heads[LEFT]; y < heads[RIGHT]; - y += squiggle.extent (Y_AXIS).length ()) - mol.add_at_edge (Y_AXIS, UP, squiggle, 0.0); + while (mol.extent (Y_AXIS).length () + epsilon < heads.length ()) + { + mol.add_at_edge (Y_AXIS, UP, squiggle, 0.0); + } mol.translate_axis (heads[LEFT], Y_AXIS); if (dir) -- 2.39.2