2005-07-09 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * 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.
PACKAGE_NAME=LilyPond
MAJOR_VERSION=2
MINOR_VERSION=7
-PATCH_LEVEL=0
+PATCH_LEVEL=1
MY_PATCH_LEVEL=
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;
}
struct Spring_description
{
Real ideal_;
- Real hooke_;
+ Real inverse_hooke_;
bool is_active_;
Real block_force_;
Grob *other_;
Real distance_;
bool expand_only_b_;
- Real strength_;
+ Real inverse_strength_;
DECLARE_SIMPLE_SMOBS (Spring_smob, dummy);
public:
/*
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 ();
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))
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;
}
}
- stiff = springs_[max_i].hooke_;
+ stiff = 1/springs_[max_i].inverse_hooke_;
}
return stiff;
}
Spring_description::Spring_description ()
{
ideal_ = 0.0;
- hooke_ = 0.0;
+ inverse_hooke_ = 0.0;
is_active_ = true;
block_force_ = 0.0;
}
bool
Spring_description::is_sane () const
{
- return (hooke_ > 0)
+ return (inverse_hooke_ >= 0)
&& ideal_ > 0
&& !isinf (ideal_) && !isnan (ideal_);
}
{
if (!is_active_)
f = block_force_;
- return ideal_ + f / hooke_;
+ return ideal_ + f * inverse_hooke_;
}
/****************************************************************/
}
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;
}
/*
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_++;
}
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++)
}
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
#endif
Spring_smob spring;
- spring.strength_ = strength;
+ spring.inverse_strength_ = inverse_strength;
spring.distance_ = d;
spring.other_ = p;
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.
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);
}
/*
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);
}
/**
Spring_smob::Spring_smob ()
{
distance_ = 0.;
- strength_ = 1.0;
+ inverse_strength_ = 1.0;
expand_only_b_ = false;
other_ = 0;
}
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 *)