lilypond-1.1.23
[lilypond.git] / src / break.cc
blob7d219186372aa1ed179bea4fc310bc3e988c3c64
1 /*
2 do calculations for breaking problem
3 */
4 #include "break.hh"
5 #include "paper-def.hh"
6 #include "linespace.hh"
7 #include "debug.hh"
8 #include "scoreline.hh"
9 #include "pscore.hh"
13 return all breakable columns
15 Line_of_cols
16 Break_algorithm::find_breaks() const
18 Line_of_cols retval;
19 for (iter_top(pscore_.cols,c); c.ok(); c++)
20 if (c->breakable_b())
21 retval.push(c);
22 assert(retval.top() == pscore_.cols.bottom().ptr());
23 return retval;
26 // construct an appropriate Spacing_problem and solve it.
27 Col_hpositions
28 Break_algorithm::solve_line(Line_of_cols curline) const
30 Spacing_problem sp;
32 sp.add_column(curline[0], true, 0.0);
33 for (int i=1; i< curline.size()-1; i++)
34 sp.add_column(curline[i]);
35 sp.add_column(curline.top(), true, linelength);
37 // misschien moeven uit Spacing_problem?
38 for (iter_top(pscore_.suz,i); i.ok(); i++) {
39 sp.add_ideal(i);
41 Array<Real> the_sol=sp.solve();
42 Col_hpositions col_hpos;
43 col_hpos.cols = curline;
44 col_hpos.energy = the_sol.pop();
45 col_hpos.config = the_sol;
46 col_hpos.OK();
47 return col_hpos;
50 Break_algorithm::Break_algorithm(PScore&s)
51 :pscore_(s)
53 linelength = s.paper_l_->linewidth;
56 bool
57 Break_algorithm::feasible(Line_of_cols curline) const
59 Real l =0;
60 for (int i=0; i < curline.size(); i++)
61 l +=curline[i]->width().length();
62 return l < linelength;
65 void
66 Break_algorithm::problem_OK() const
68 if (!pscore_.cols.size())
69 error("Score does not have any columns");
70 #ifndef NDEBUG
71 iter_top(pscore_.cols,start);
72 PCursor<PCol *> end (pscore_.cols.bottom());
74 assert(start->breakable_b());
75 assert(end->breakable_b());
76 #endif