2 break.cc -- implement Break_algorithm
4 source file of the LilyPond music typesetter
6 (c) 1996, 1997 Han-Wen Nienhuys <hanwen@stack.nl>
11 #include "paper-def.hh"
12 #include "linespace.hh"
14 #include "scoreline.hh"
18 /// return all breakable columns
20 Break_algorithm::find_breaks() const
23 for (iter_top(pscore_
.cols
,c
); c
.ok(); c
++)
26 assert(retval
.top() == pscore_
.cols
.bottom().ptr());
32 Break_algorithm::stupid_solution(Line_of_cols curline
)const
35 sp
.add_column(curline
[0], true, 0.0);
36 for (int i
=1; i
< curline
.size()-1; i
++)
37 sp
.add_column(curline
[i
]);
38 sp
.add_column(curline
.top(), true, linelength
);
39 Col_hpositions colhpos
;
40 colhpos
.cols
= curline
;
41 colhpos
.energy
= INFTY
;
42 colhpos
.ugh_b_
= true;
43 colhpos
.config
= sp
.try_initial_solution();
47 /// construct an appropriate Spacing_problem and solve it.
49 Break_algorithm::solve_line(Line_of_cols curline
) const
53 sp
.add_column(curline
[0], true, 0.0);
54 for (int i
=1; i
< curline
.size()-1; i
++)
55 sp
.add_column(curline
[i
]);
56 sp
.add_column(curline
.top(), true, linelength
);
58 // misschien moeven uit Spacing_problem?
59 for (iter_top(pscore_
.suz
,i
); i
.ok(); i
++) {
64 Array
<Real
> the_sol
=sp
.solve();
65 Col_hpositions col_hpos
;
66 col_hpos
.cols
= curline
;
67 col_hpos
.energy
= the_sol
.pop();
68 col_hpos
.config
= the_sol
;
69 col_hpos
.error_col_l_arr_
= sp
.error_pcol_l_arr();
74 Break_algorithm::Break_algorithm(PScore
&s
)
77 linelength
= s
.paper_l_
->linewidth
;
81 Break_algorithm::feasible(Line_of_cols curline
) const
84 for (int i
=0; i
< curline
.size(); i
++)
85 l
+=curline
[i
]->width().length();
86 return l
< linelength
;
90 Break_algorithm::problem_OK() const
92 if (!pscore_
.cols
.size())
93 error("Score does not have any columns");
95 iter_top(pscore_
.cols
,start
);
96 PCursor
<PCol
*> end (pscore_
.cols
.bottom());
98 assert(start
->breakable_b());
99 assert(end
->breakable_b());