From 3656d856dbaff6ad279c8d1cff660fa57b63bb86 Mon Sep 17 00:00:00 2001 From: Keith OHara Date: Sat, 28 May 2011 23:38:34 -0700 Subject: [PATCH] Vertical spacing, distinguish stretchability/compressibility When stretchability is changed, leave inverse_compression_strength alone. --- .../regression/page-breaking-min-distance2.ly | 3 +- lily/align-interface.cc | 3 -- lily/page-layout-problem.cc | 10 +------ lily/simple-spacer.cc | 18 ++++++------ lily/spring.cc | 29 ++++++++++--------- 5 files changed, 27 insertions(+), 36 deletions(-) diff --git a/input/regression/page-breaking-min-distance2.ly b/input/regression/page-breaking-min-distance2.ly index 90224e3957..94e93ea1c2 100644 --- a/input/regression/page-breaking-min-distance2.ly +++ b/input/regression/page-breaking-min-distance2.ly @@ -8,8 +8,7 @@ \context { \Score \override VerticalAxisGroup #'staff-staff-spacing = - #'((basic-distance . 20) - (stretchability . 0)) + #'((minimum-distance . 20)) } } diff --git a/lily/align-interface.cc b/lily/align-interface.cc index 2fd49f5162..403f903e49 100644 --- a/lily/align-interface.cc +++ b/lily/align-interface.cc @@ -226,9 +226,6 @@ Align_interface::internal_get_minimum_translations (Grob *me, if (Page_layout_problem::read_spacing_spec (spec, &min_distance, ly_symbol2scm ("minimum-distance"))) dy = max (dy, min_distance); - if (include_fixed_spacing) - dy = max (dy, Page_layout_problem::get_fixed_spacing (elems[j-1], elems[j], spaceable_count, pure, start, end)); - if (include_fixed_spacing && Page_layout_problem::is_spaceable (elems[j]) && last_spaceable_element) { // Spaceable staves may have diff --git a/lily/page-layout-problem.cc b/lily/page-layout-problem.cc index 9ee2b3fea1..07c99586ee 100644 --- a/lily/page-layout-problem.cc +++ b/lily/page-layout-problem.cc @@ -775,12 +775,7 @@ Page_layout_problem::get_fixed_spacing (Grob *before, Grob *after, int spaceable return robust_scm2double (cached, 0.0); } - SCM spec = Page_layout_problem::get_spacing_spec (before, after, pure, start, end); Real ret = -infinity_f; - Real stretchability = 0; - if (Page_layout_problem::read_spacing_spec (spec, &stretchability, ly_symbol2scm ("stretchability")) - && stretchability == 0) - Page_layout_problem::read_spacing_spec (spec, &ret, ly_symbol2scm ("basic-distance")); // If we're pure, then paper-columns have not had their systems set, // and so elts[i]->get_system () is unreliable. @@ -894,10 +889,7 @@ Page_layout_problem::alter_spring_from_spacing_spec (SCM spec, Spring* spring) spring->set_default_strength (); if (read_spacing_spec (spec, &stretch, ly_symbol2scm ("stretchability"))) - { - spring->set_inverse_stretch_strength (stretch); - spring->set_inverse_compress_strength (stretch); - } + spring->set_inverse_stretch_strength (stretch); } vector diff --git a/lily/simple-spacer.cc b/lily/simple-spacer.cc index 14c7cbeebd..4376b0133c 100644 --- a/lily/simple-spacer.cc +++ b/lily/simple-spacer.cc @@ -196,7 +196,6 @@ Simple_spacer::expand_line () Real Simple_spacer::compress_line () { - double inv_hooke = 0; double cur_len = configuration_length (force_); double cur_force = force_; bool compressed = false; @@ -213,23 +212,24 @@ Simple_spacer::compress_line () } fits_ = true; - for (vsize i=0; i < springs_.size (); i++) - inv_hooke += compressed - ? springs_[i].inverse_compress_strength () - : springs_[i].inverse_stretch_strength (); assert (line_len_ <= cur_len); vector sorted_springs = springs_; sort (sorted_springs.begin (), sorted_springs.end (), greater ()); - for (vsize i = 0; i < sorted_springs.size (); i++) + /* inv_hooke is the total flexibility of currently-active springs */ + double inv_hooke = 0; + vsize i = sorted_springs.size (); + for ( ; i && sorted_springs[i - 1].blocking_force () < cur_force; i--) + inv_hooke += compressed + ? sorted_springs[i - 1].inverse_compress_strength () + : sorted_springs[i - 1].inverse_stretch_strength (); + /* i now indexes the first active spring, so */ + for ( ; i < sorted_springs.size (); i++) { Spring sp = sorted_springs[i]; - if (sp.blocking_force () > cur_force) - continue; - if (isinf (sp.blocking_force ())) break; diff --git a/lily/spring.cc b/lily/spring.cc index 60bc0aec77..c576da3743 100644 --- a/lily/spring.cc +++ b/lily/spring.cc @@ -45,20 +45,23 @@ Spring::Spring (Real dist, Real min_dist) void Spring::update_blocking_force () { + // blocking_force_ is the value of force + // below which length(force) is constant, and + // above which length(force) varies according to inverse_*_strength. + // Simple_spacer::compress_line() depends on the condition above. + // We assume inverse_*_strength are non-negative. if (min_distance_ > distance_) - blocking_force_ = (min_distance_ - distance_) / inverse_stretch_strength_; + if (inverse_stretch_strength_ > 0.0) + blocking_force_ = (min_distance_ - distance_) / inverse_stretch_strength_; + else + // Conceptually, this should be +inf, but 0.0 meets the requirements + // of Simple_spacer and creates fewer cases of 0.0*inf to handle. + blocking_force_ = 0.0; else - blocking_force_ = (min_distance_ - distance_) / inverse_compress_strength_; - - // If the spring is fixed, it's not clear what the natural value - // of blocking_force_ would be (because it always blocks). - // -infinity_f works fine for now. - // If inverse_stretch_strength > 0, the spring is not fixed (because it can stretch). - if (isnan (blocking_force_) || blocking_force_ == infinity_f) - blocking_force_ = (inverse_stretch_strength_ > 0) ? 0.0 : -infinity_f; - - if (blocking_force_ >= 0) - inverse_compress_strength_ = 0; + if (inverse_compress_strength_ > 0.0) + blocking_force_ = (min_distance_ - distance_) / inverse_compress_strength_; + else + blocking_force_ = 0.0; } /* scale a spring, but in a way that doesn't violate min_distance */ @@ -200,7 +203,7 @@ Spring::length (Real f) const Real force = max (f, blocking_force_); Real inv_k = force < 0.0 ? inverse_compress_strength_ : inverse_stretch_strength_; - if (force == infinity_f) + if (isinf(force)) { programming_error ("cruelty to springs"); force = 0.0; -- 2.39.2