X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fsimple-spacer.cc;h=cf4fd5849e35601ad8cf839394d7f6d6ba407c8e;hb=5d84bfad4626892bcffd05adcced53c8a2329047;hp=4644ad7c4b952a98b7d17c567b7eae321ef09c45;hpb=9b279fe458c4dd2ed9550670ea521e29bad57cd0;p=lilypond.git diff --git a/lily/simple-spacer.cc b/lily/simple-spacer.cc index 4644ad7c4b..cf4fd5849e 100644 --- a/lily/simple-spacer.cc +++ b/lily/simple-spacer.cc @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 1999--2011 Han-Wen Nienhuys + Copyright (C) 1999--2015 Han-Wen Nienhuys TODO: - add support for different stretch/shrink constants? @@ -160,6 +160,12 @@ Simple_spacer::configuration_length (Real force) const return l; } +void +Simple_spacer::set_force (Real force) +{ + force_ = force; +} + void Simple_spacer::solve (Real line_len, bool ragged) { @@ -187,9 +193,10 @@ Simple_spacer::expand_line () inv_hooke += springs_[i].inverse_stretch_strength (); if (inv_hooke == 0.0) /* avoid division by zero. If springs are infinitely stiff */ - return 0.0; /* anyway, then it makes no difference what the force is */ + inv_hooke = 1e-6; /* then report a very large stretching force */ - assert (cur_len <= line_len_); + if (cur_len > (1 + 1e-6) * line_len_) + programming_error ("misuse of expand_line"); return (line_len_ - cur_len) / inv_hooke + force_; } @@ -213,8 +220,8 @@ Simple_spacer::compress_line () fits_ = true; - assert (line_len_ <= cur_len); - + if (line_len_ > (1 + 1e-6) * cur_len) + programming_error ("misuse of compress_line"); vector sorted_springs = springs_; sort (sorted_springs.begin (), sorted_springs.end (), greater ()); @@ -242,7 +249,9 @@ Simple_spacer::compress_line () /* Paranoia check. */ - assert (fabs (configuration_length (cur_force) - cur_len) < 1e-6); + if (fabs (configuration_length (cur_force) - cur_len) > 1e-6 * cur_len) + programming_error (to_string ("mis-predicted force, %.6f ~= %.6f", + cur_len, configuration_length(cur_force))); return cur_force; } @@ -364,20 +373,26 @@ get_column_description (vector const &cols, vsize col_index, bool line_s if (next_col) description.spring_ = Spaceable_grob::get_spring (col, next_col); - Grob *end_col = dynamic_cast (cols[col_index + 1])->find_prebroken_piece (LEFT); - if (end_col) - description.end_spring_ = Spaceable_grob::get_spring (col, end_col); + if (col_index + 1 < cols.size ()) + { + Grob *end_col = dynamic_cast (cols[col_index + 1])->find_prebroken_piece (LEFT); + if (end_col) + description.end_spring_ = Spaceable_grob::get_spring (col, end_col); + } for (SCM s = Spaceable_grob::get_minimum_distances (col); scm_is_pair (s); s = scm_cdr (s)) { - Grob *other = unsmob_grob (scm_caar (s)); + Grob *other = unsmob (scm_caar (s)); vsize j = binary_search (cols, other, Paper_column::less_than, col_index); if (j != VPOS) { if (cols[j] == other) description.rods_.push_back (Rod_description (j, scm_to_double (scm_cdar (s)))); else /* it must end at the LEFT prebroken_piece */ + /* see Spanner::set_spacing_rods for more comments on how + to deal with situations where we don't know if we're + ending yet on the left prebroken piece */ description.end_rods_.push_back (Rod_description (j, scm_to_double (scm_cdar (s)))); } } @@ -455,7 +470,7 @@ get_line_forces (vector const &columns, force[b * breaks.size () + c] = infinity_f; break; } - if (end < cols.size () && cols[end].break_permission_ == force_break) + if (end < cols.size () && scm_is_eq (cols[end].break_permission_, force_break)) break; } } @@ -516,29 +531,9 @@ get_line_configuration (vector const &columns, for (vsize i = 1; i + 1 < ret.cols_.size (); i++) { SCM p = ret.cols_[i]->get_property ("line-break-permission"); - if (p == ly_symbol2scm ("force")) + if (scm_is_eq (p, ly_symbol2scm ("force"))) ret.satisfies_constraints_ = false; } return ret; } - - -#include "ly-smobs.icc" - -IMPLEMENT_SIMPLE_SMOBS (Simple_spacer); -IMPLEMENT_DEFAULT_EQUAL_P (Simple_spacer); - -SCM -Simple_spacer::mark_smob (SCM /* x */) -{ - return SCM_EOL; -} - -int -Simple_spacer::print_smob (SCM /* x */, SCM p, scm_print_state *) -{ - scm_puts ("#", p); - return 1; -} -