From 9d1e56447d21a8a1cfbc751535183916efffe7a0 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sat, 9 Jul 2005 22:35:38 +0000 Subject: [PATCH] *** empty log message *** --- ChangeLog | 5 +++++ VERSION | 2 +- lily/coherent-ligature-engraver.cc | 6 +++--- lily/include/simple-spacer.hh | 2 +- lily/include/spring.hh | 4 ++-- lily/simple-spacer-scheme.cc | 2 +- lily/simple-spacer.cc | 25 +++++++++++++------------ lily/spaceable-grob.cc | 13 ++++++------- lily/spacing-spanner.cc | 13 +++++++------ lily/spring-smob.cc | 9 +++++++-- 10 files changed, 46 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 95783e573d..5356f333dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2005-07-09 Han-Wen Nienhuys + * lily/include/simple-spacer.hh (Module): idem. + + * lily/include/spring.hh (struct Spring): store inverse + strength. This prevents division by zero. + * lily/include/music.hh (class Music): remove Music::duration_log() * lily/stem-engraver.cc (make_stem): take duration log from event. diff --git a/VERSION b/VERSION index d2d758b365..01f3dcadba 100644 --- a/VERSION +++ b/VERSION @@ -1,6 +1,6 @@ PACKAGE_NAME=LilyPond MAJOR_VERSION=2 MINOR_VERSION=7 -PATCH_LEVEL=0 +PATCH_LEVEL=1 MY_PATCH_LEVEL= diff --git a/lily/coherent-ligature-engraver.cc b/lily/coherent-ligature-engraver.cc index 0ed1405afa..bac7e8af09 100644 --- a/lily/coherent-ligature-engraver.cc +++ b/lily/coherent-ligature-engraver.cc @@ -94,10 +94,10 @@ if (incr_scm != SCM_EOL) /* (Paper_column::is_musical (l)) */ distance = 0.1; } me->warning (_f ("distance=%f", distance));//debug - Real strength = 1.0; - Spaceable_grob::add_spring (lc, rc, distance, strength); + Real inverse_strength = 1.0; + Spaceable_grob::add_spring (lc, rc, distance, inverse_strength); if (Item *rb = r->find_prebroken_piece (LEFT)) - Spaceable_grob::add_spring (lc, rb, distance, strength); + Spaceable_grob::add_spring (lc, rb, distance, inverse_strength); continue; } diff --git a/lily/include/simple-spacer.hh b/lily/include/simple-spacer.hh index 9ffdc175fa..3b6236358a 100644 --- a/lily/include/simple-spacer.hh +++ b/lily/include/simple-spacer.hh @@ -16,7 +16,7 @@ struct Spring_description { Real ideal_; - Real hooke_; + Real inverse_hooke_; bool is_active_; Real block_force_; diff --git a/lily/include/spring.hh b/lily/include/spring.hh index c3ef5bd027..e5e42ff50c 100644 --- a/lily/include/spring.hh +++ b/lily/include/spring.hh @@ -17,7 +17,7 @@ struct Spring_smob Grob *other_; Real distance_; bool expand_only_b_; - Real strength_; + Real inverse_strength_; DECLARE_SIMPLE_SMOBS (Spring_smob, dummy); public: @@ -34,7 +34,7 @@ struct Spring /* TODO: make 2 strengths: one for stretching, and one for shrinking. */ - Real strength_; + Real inverse_strength_; void add_to_cols (); void set_to_cols (); Spring (); diff --git a/lily/simple-spacer-scheme.cc b/lily/simple-spacer-scheme.cc index 5cc4871c0d..c38d1e52ed 100644 --- a/lily/simple-spacer-scheme.cc +++ b/lily/simple-spacer-scheme.cc @@ -41,7 +41,7 @@ LY_DEFINE (ly_solve_spring_rod_problem, "ly:solve-spring-rod-problem", Real ideal = scm_to_double (scm_caar (s)); Real hooke = scm_to_double (scm_cadar (s)); - spacer.add_spring (ideal, hooke); + spacer.add_spring (ideal, 1 / 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 f23dfb8450..fb15891542 100644 --- a/lily/simple-spacer.cc +++ b/lily/simple-spacer.cc @@ -122,7 +122,7 @@ Simple_spacer::range_stiffness (int l, int r) const for (int i = l; i < r; i++) { if (springs_[i].is_active_) - den += 1 / springs_[i].hooke_; + den += 1 * springs_[i].inverse_hooke_; } return 1 / den; @@ -162,7 +162,7 @@ Simple_spacer::active_springs_stiffness () const } } - stiff = springs_[max_i].hooke_; + stiff = 1/springs_[max_i].inverse_hooke_; } return stiff; } @@ -245,7 +245,7 @@ Simple_spacer::my_solve_natural_len () Spring_description::Spring_description () { ideal_ = 0.0; - hooke_ = 0.0; + inverse_hooke_ = 0.0; is_active_ = true; block_force_ = 0.0; } @@ -253,7 +253,7 @@ Spring_description::Spring_description () bool Spring_description::is_sane () const { - return (hooke_ > 0) + return (inverse_hooke_ >= 0) && ideal_ > 0 && !isinf (ideal_) && !isnan (ideal_); } @@ -263,7 +263,7 @@ Spring_description::length (Real f) const { if (!is_active_) f = block_force_; - return ideal_ + f / hooke_; + return ideal_ + f * inverse_hooke_; } /****************************************************************/ @@ -341,21 +341,21 @@ Simple_spacer_wrapper::solve (Column_x_positions *positions, bool ragged) } void -Simple_spacer::add_spring (Real ideal, Real hooke) +Simple_spacer::add_spring (Real ideal, Real inverse_hooke) { Spring_description desc; desc.ideal_ = ideal; - desc.hooke_ = hooke; + desc.inverse_hooke_ = inverse_hooke; if (!desc.is_sane ()) { programming_error ("insane spring found, setting to unit"); - desc.hooke_ = 1.0; + desc.inverse_hooke_ = 1.0; desc.ideal_ = 1.0; } - if (isinf (hooke)) + if (!inverse_hooke) { desc.is_active_ = false; } @@ -364,7 +364,8 @@ Simple_spacer::add_spring (Real ideal, Real hooke) /* desc.is_active_ ? */ - desc.block_force_ = -desc.hooke_ * desc.ideal_; // block at distance 0 + desc.block_force_ = - desc.ideal_ / desc.inverse_hooke_; + // block at distance 0 active_count_++; } @@ -410,9 +411,9 @@ Simple_spacer_wrapper::add_columns (Link_array const &icols) Paper_column::get_rank (cols[i]))); Real ideal = (spring) ? spring->distance_ : spacer_->default_space_; - Real hooke = (spring) ? spring->strength_ : 1.0; + Real inverse_hooke = (spring) ? spring->inverse_strength_ : 1.0; - spacer_->add_spring (ideal, hooke); + spacer_->add_spring (ideal, inverse_hooke); } for (int i = 0; i < cols.size () - 1; i++) diff --git a/lily/spaceable-grob.cc b/lily/spaceable-grob.cc index df48631ff9..4149e48b32 100644 --- a/lily/spaceable-grob.cc +++ b/lily/spaceable-grob.cc @@ -51,23 +51,22 @@ Spaceable_grob::add_rod (Grob *me, Grob *p, Real d) } void -Spaceable_grob::add_spring (Grob *me, Grob *p, Real d, Real strength) +Spaceable_grob::add_spring (Grob *me, Grob *p, Real d, Real inverse_strength) { - // printf ("dist %lf, str %lf\n", d, strength); - if (d <= 0.0 || strength <= 0.0) + if (d <= 0.0 || inverse_strength < 0.0) { programming_error ("adding reverse spring, setting to unit"); d = 1.0; - strength = 1.0; + inverse_strength = 1.0; } if (isinf (d) || isnan (d) - || isnan (strength)) + || isnan (inverse_strength)) { /* strength == INF is possible. It means fixed distance. */ programming_error ("insane distance found"); d = 1.0; - strength = 1.0; + inverse_strength = 1.0; } #ifndef NDEBUG @@ -84,7 +83,7 @@ Spaceable_grob::add_spring (Grob *me, Grob *p, Real d, Real strength) #endif Spring_smob spring; - spring.strength_ = strength; + spring.inverse_strength_ = inverse_strength; spring.distance_ = d; spring.other_ = p; diff --git a/lily/spacing-spanner.cc b/lily/spacing-spanner.cc index b1a4a1867e..a9d9a500a8 100644 --- a/lily/spacing-spanner.cc +++ b/lily/spacing-spanner.cc @@ -611,7 +611,8 @@ Spacing_spanner::musical_column_spacing (Grob *me, Item *lc, Item *rc, Real incr compound_fixed_note_space = min (compound_fixed_note_space, compound_note_space); bool packed = to_boolean (me->get_layout ()->c_variable ("packed")); - Real strength, distance; + Real inverse_strength = 1.0; + Real distance = 1.0; /* TODO: make sure that the space doesn't exceed the right margin. @@ -627,16 +628,16 @@ Spacing_spanner::musical_column_spacing (Grob *me, Item *lc, Item *rc, Real incr pack as much bars of music as possible into a line, but the line will then be stretched to fill the whole linewidth. */ - strength = 1.0; + inverse_strength = 1.0; distance = compound_fixed_note_space; } else { - strength = 1 / (compound_note_space - compound_fixed_note_space); + inverse_strength = (compound_note_space - compound_fixed_note_space); distance = compound_note_space; } - Spaceable_grob::add_spring (lc, rc, distance, strength); + Spaceable_grob::add_spring (lc, rc, distance, inverse_strength); } /* @@ -776,9 +777,9 @@ Spacing_spanner::breakable_column_spacing (Grob *me, Item *l, Item *r, Moment sh Do it more cleanly, or rename the property. */ - Real strength = 1 / (compound_space - compound_fixed); + Real inverse_strength = (compound_space - compound_fixed); Real distance = compound_space; - Spaceable_grob::add_spring (l, r, distance, strength); + Spaceable_grob::add_spring (l, r, distance, inverse_strength); } /** diff --git a/lily/spring-smob.cc b/lily/spring-smob.cc index 7eb3820745..388567e793 100644 --- a/lily/spring-smob.cc +++ b/lily/spring-smob.cc @@ -13,7 +13,7 @@ Spring_smob::Spring_smob () { distance_ = 0.; - strength_ = 1.0; + inverse_strength_ = 1.0; expand_only_b_ = false; other_ = 0; } @@ -21,7 +21,12 @@ Spring_smob::Spring_smob () IMPLEMENT_SIMPLE_SMOBS (Spring_smob); SCM -Spring_smob::mark_smob (SCM) { return SCM_UNSPECIFIED; } +Spring_smob::mark_smob (SCM x) +{ + (void)x; + + return SCM_UNSPECIFIED; +} int Spring_smob::print_smob (SCM, SCM p, scm_print_state *) -- 2.39.2