source file of the GNU LilyPond music typesetter
- (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ (c) 1999--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
TODO:
- add support for different stretch/shrink constants?
*/
-#include <stdio.h>
+
+#include "simple-spacer.hh"
+
+#include <cstdio>
#include <math.h>
+
#include <libc-extension.hh> // isinf
-#include "simple-spacer.hh"
#include "paper-column.hh"
#include "spring.hh"
-#include "rod.hh"
#include "warn.hh"
#include "column-x-positions.hh"
#include "spaceable-grob.hh"
#include "dimensions.hh"
-
/*
A simple spacing constraint solver. The approach:
*/
active_count_ = 0;
force_ = 0.;
- indent_ =0.0;
+ indent_ = 0.0;
default_space_ = 20 PT;
}
return;
}
- Real c = range_stiffness (l,r);
+ Real c = range_stiffness (l, r);
if (isinf (c))
{
/*
return;
}
- Real d = range_ideal_len (l,r);
+ Real d = range_ideal_len (l, r);
Real block_stretch = dist - d;
Real block_force = c * block_stretch;
force_ = force_ >? block_force;
- for (int i=l; i < r; i++)
+ for (int i = l; i < r; i++)
springs_[i].block_force_ = block_force >?
springs_[i].block_force_ ;
}
Real
Simple_spacer::range_ideal_len (int l, int r) const
{
- Real d =0.;
- for (int i=l; i < r; i++)
+ Real d = 0.;
+ for (int i = l; i < r; i++)
d += springs_[i].ideal_;
return d;
}
Real
Simple_spacer::range_stiffness (int l, int r) const
{
- Real den =0.0;
- for (int i=l; i < r; i++)
+ Real den = 0.0;
+ for (int i = l; i < r; i++)
{
if (springs_[i].is_active_)
den += 1 / springs_[i].hooke_;
Simple_spacer::active_blocking_force () const
{
Real bf = - infinity_f;
- for (int i=0; i < springs_.size (); i++)
+ for (int i = 0; i < springs_.size (); i++)
if (springs_[i].is_active_)
{
bf = bf >? springs_[i].block_force_;
Real max_block_force = -infinity_f;
int max_i = -1;
- for (int i=0; i < springs_.size (); i++)
+ for (int i = 0; i < springs_.size (); i++)
{
if (springs_[i].block_force_ > max_block_force)
{
Simple_spacer::set_active_states ()
{
/* float comparison is safe, since force is only copied. */
- for (int i=0 ; i <springs_.size (); i++)
+ for (int i = 0 ; i <springs_.size (); i++)
if (springs_[i].is_active_
&& springs_[i].block_force_ >= force_)
{
Real
Simple_spacer::configuration_length () const
{
- Real l =0.;
- for (int i=0; i < springs_.size (); i++)
+ Real l = 0.;
+ for (int i = 0; i < springs_.size (); i++)
l += springs_[i].length (force_);
return l;
"are connected by @var{count-1} springs, and an arbitrary number of rods "
"Springs have the format (ideal, hooke) and rods (idx1, idx2, distance) "
"@var{length} is a number, @var{ragged} a boolean "
- "Return: a list containing the force (#f for non-satisfied constraints) "
+ "Return: a list containing the force (positive for stretching, "
+ "negative for compressing and #f for non-satisfied constraints) "
"followed by the @var{spring-count}+1 positions of the objects. "
)
{
length, SCM_ARG3, __FUNCTION__, "number or #f");
- bool is_ragged = ragged == SCM_BOOL_T;
+ bool is_ragged = ragged == SCM_BOOL_T;
Simple_spacer spacer;
for (SCM s = springs; scm_is_pair (s); s = scm_cdr (s))
{
SCM force_return = SCM_BOOL_F;
if (!isinf (spacer.force_)
- && spacer.is_active ())
+ && (spacer.is_active () || is_ragged))
{
force_return = scm_from_double (spacer.force_);
}
force_return = SCM_BOOL_F;
}
- SCM retval= SCM_EOL;
+ SCM retval = SCM_EOL;
for (int i = posns.size(); i--;)
{
retval = scm_cons (scm_from_double (posns[i]), retval);
Spring_description::Spring_description ()
{
- ideal_ =0.0;
- hooke_ =0.0;
+ ideal_ = 0.0;
+ hooke_ = 0.0;
is_active_ = true;
block_force_ = 0.0;
}
fucked up wtk1-fugue2 (taking 3 full pages.)
*/
positions->config_.push (spacer_->indent_);
- for (int i=0; i < spacer_->springs_.size (); i++)
+ for (int i = 0; i < spacer_->springs_.size (); i++)
{
Real l = spacer_->springs_[i].length ((ragged) ? 0.0 : spacer_->force_);
positions->config_.push (positions->config_.top () + l);
positions->satisfies_constraints_ =
positions->config_.top () < spacer_->line_len_ ;
}
-
+ else
+ positions->satisfies_constraints_ = spacer_->is_active ();
positions->cols_ = spaced_cols_;
positions->loose_cols_ = loose_cols_;
- positions->satisfies_constraints_ =
- positions->satisfies_constraints_ && spacer_->is_active ();
/*
Check if breaking constraints are met.
springs_.push (desc);
}
+static int
+compare_paper_column_rank (Grob *const &a,
+ Grob *const &b)
+{
+ return Paper_column::get_rank (a) - Paper_column::get_rank (b);
+}
+
void
Simple_spacer_wrapper::add_columns (Link_array<Grob> const &icols)
{
}
spaced_cols_ = cols;
- for (int i=0; i < cols.size () - 1; i++)
+ for (int i = 0; i < cols.size () - 1; i++)
{
Spring_smob *spring = 0;
spacer_->add_spring (ideal, hooke);
}
- for (int i=0; i < cols.size () - 1; i++)
+ for (int i = 0; i < cols.size () - 1; i++)
{
for (SCM s = Spaceable_grob::get_minimum_distances (cols[i]);
scm_is_pair (s); s = scm_cdr (s))
{
Grob * other = unsmob_grob (scm_caar (s));
- int oi = cols.find_index (other);
+ int oi = binsearch_links (cols, other, &compare_paper_column_rank);
if (oi >= 0)
{
spacer_->add_rod (i, oi, scm_to_double (scm_cdar (s)));
}
}
+
+ if (i
+ && !to_boolean (cols[i]->get_property ("allow-outside-line")))
+ {
+ Interval e = cols[i]->extent (cols[i], X_AXIS);
+ if (!e.is_empty())
+ {
+ spacer_->add_rod (i, cols.size()-1, e[RIGHT]);
+ spacer_->add_rod (0, i, e[LEFT]);
+ }
+ }
}
}