From e98bc7bfabf41d75aa1e80f37cec7957065f9396 Mon Sep 17 00:00:00 2001 From: Nicolas Sceaux Date: Sun, 10 Jun 2007 00:11:00 +0200 Subject: [PATCH] Allow null spacing and padding in vertical spacing: - the `spring' argument of ly:solve-spring-and-rod-problem now is a list of (ideal-distance inverse-hooke) elements, instead of (ideal-distance hooke), to avoid infinite value when space=0; - do not try to expand the spacing when all inter line spaces are null. --- lily/simple-spacer-scheme.cc | 6 +++--- lily/simple-spacer.cc | 5 ++++- scm/layout-page-layout.scm | 28 +++++++++++++--------------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lily/simple-spacer-scheme.cc b/lily/simple-spacer-scheme.cc index 6f76106706..db326704fc 100644 --- a/lily/simple-spacer-scheme.cc +++ b/lily/simple-spacer-scheme.cc @@ -17,7 +17,7 @@ LY_DEFINE (ly_solve_spring_rod_problem, "ly:solve-spring-rod-problem", 4, 1, 0, (SCM springs, SCM rods, SCM length, SCM ragged), "Solve a spring and rod problem for @var{count} objects, that " "are connected by @var{count-1} springs, and an arbitrary number of rods " - "Springs have the format (ideal, hooke) and rods (idx1, idx2, distance) " + "Springs have the format (ideal, inverse_hooke) and rods (idx1, idx2, distance) " "@var{length} is a number, @var{ragged} a boolean " "Return: a list containing the force (positive for stretching, " "negative for compressing and #f for non-satisfied constraints) " @@ -36,9 +36,9 @@ LY_DEFINE (ly_solve_spring_rod_problem, "ly:solve-spring-rod-problem", for (SCM s = springs; scm_is_pair (s); s = scm_cdr (s)) { Real ideal = scm_to_double (scm_caar (s)); - Real hooke = scm_to_double (scm_cadar (s)); + Real inv_hooke = scm_to_double (scm_cadar (s)); - spacer.add_spring (ideal, 1 / hooke); + spacer.add_spring (ideal, inv_hooke); } for (SCM s = rods; scm_is_pair (s); s = scm_cdr (s)) diff --git a/lily/simple-spacer.cc b/lily/simple-spacer.cc index 3f4e678cd6..04c35dd4e5 100644 --- a/lily/simple-spacer.cc +++ b/lily/simple-spacer.cc @@ -144,10 +144,13 @@ void Simple_spacer::solve (Real line_len, bool ragged) { Real conf = configuration_length (force_); + double inv_hooke = 0; + for (vsize i=0; i < springs_.size (); i++) + inv_hooke += springs_[i].inverse_hooke_; ragged_ = ragged; line_len_ = line_len; - if (conf < line_len_) + if ((inv_hooke > 0) && (conf < line_len_)) force_ = expand_line (); else if (conf > line_len_) force_ = compress_line (); diff --git a/scm/layout-page-layout.scm b/scm/layout-page-layout.scm index 6c1f605b0d..91742ef315 100644 --- a/scm/layout-page-layout.scm +++ b/scm/layout-page-layout.scm @@ -156,16 +156,13 @@ `next-line' can be #f, meaning that `line' is the last line." (let* ((title (paper-system-title? line)) (next-title (and next-line (paper-system-title? next-line)))) - (cond ((and title next-title) - (ly:output-def-lookup layout 'between-title-space)) - (title - (ly:output-def-lookup layout 'after-title-space)) - (next-title - (ly:output-def-lookup layout 'before-title-space)) - (else - (ly:prob-property - line 'next-space - (ly:output-def-lookup layout 'between-system-space)))))) + (ly:prob-property + line 'next-space + (ly:output-def-lookup layout + (cond ((and title next-title) 'between-title-space) + (title 'after-title-space) + (next-title 'before-title-space) + (else 'between-system-space)))))) (define (line-next-padding line next-line layout) "Return padding to use between `line' and `next-line'. @@ -198,10 +195,11 @@ "Ideal distance between `line' reference position and `next-line' reference position. If next-line is #f, return #f." (and next-line - (+ (max 0 (- (+ (interval-end (paper-system-staff-extents next-line)) - (if ignore-padding 0 (line-next-padding line next-line layout))) - (interval-start (paper-system-staff-extents line)))) - (line-next-space line next-line layout)))) + (max (+ (max 0 (- (+ (interval-end (paper-system-staff-extents next-line)) + (if ignore-padding 0 (line-next-padding line next-line layout))) + (interval-start (paper-system-staff-extents line)))) + (line-next-space line next-line layout)) + (line-minimum-distance line next-line layout ignore-padding)))) (define (first-line-position line layout) "Position of the first line on page" @@ -287,7 +285,7 @@ '()))) (springs (map (lambda (prev-line line) (list (line-ideal-distance prev-line line paper ignore-padding) - (/ 1.0 (line-next-space prev-line line paper)))) + (line-next-space prev-line line paper))) lines cdr-lines)) (rods (map (let ((i -1)) -- 2.39.5