2 linespace.hh -- declare Colinfo, Spacing_problem
4 source file of the GNU LilyPond music typesetter
6 (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
16 #include "interval.hh"
19 /// helper struct for #Spacing_problem#
25 /// did some tricks to make this column come out.
29 Colinfo(PCol *,Real const *);
32 bool fixed() const { return fixpos_p_.get_C();}
33 Real fixed_position()const { return *fixpos_p_; }
34 Real minright() const { return width.right; }
35 Real minleft() const { return -width.left; }
39 /** the problem, given by the columns (which include constraints) and
40 intercolumn spacing. The problem is:
42 Generate a spacing which
45 Satisfies spacing constraints (notes can't be printed through each other)
47 Looks good, ie tries to conform to an ideal spacing as much as possible.
49 This is converted by regarding idealspacing as "springs" attached
50 to columns. The equilibrium of one spring is the ideal
51 distance. The columns have a size, this imposes "hard" constraints
52 on the distances. This transforms the problem into a quadratic
53 programming problem with linear constraints.
55 The quality is given by the total potential energy in the
56 springs. The lower the energy, the better the configuration.
58 TODO: make item widths work per pstaff.
61 class Spacing_problem {
62 Array<Idealspacing const *> ideals;
64 Array<Colinfo> loose_col_arr_;
66 /// mark column #i# as being loose.
67 void loosen_column(int i);
68 /// the index of #c# in #cols#
69 int col_id(PCol const *c) const;
71 /// generate an (nonoptimal) solution
72 Vector find_initial_solution() const;
74 /// check if problem is too tight
75 bool check_feasible() const;
77 /// does #this# contain the column #w#?
78 bool contains(PCol const *w);
80 /// make the energy function
81 void make_matrices(Matrix &quad, Vector &lin,Real&) const;
83 /// generate the LP constraints
84 void make_constraints(Mixed_qp& lp) const;
87 void handle_loose_cols();
88 void position_loose_cols(Vector &) const;
90 Array<PCol*> error_pcol_l_arr() const;
92 /** solve the spacing problem
94 @return the column positions, and the energy (last element)
97 Array<Real> solve() const;
101 add a idealspacing to the problem.
103 One pair of columns can have no, one or more idealspacings,
104 since they can be "summed" if the columns to which #i# refers are
105 not in this problem, the spacing is ignored.
107 void add_ideal(Idealspacing const *i);
110 /** add a col to the problem. columns have to be added left to right. The column contains
111 info on it's minimum width.
113 void add_column(PCol *, bool fixed=false, Real fixpos=0.0);
117 bool check_constraints(Vector v) const;
119 Vector try_initial_solution() const;
122 void print_ideal(Idealspacing const *)const;