]> git.donarmstrong.com Git - lilypond.git/blob - src/break.cc
release: 0.0.32
[lilypond.git] / src / break.cc
1 /*
2     do calculations for breaking problem    
3     */
4 #include "break.hh"
5 #include "paperdef.hh"
6 #include "linespace.hh"
7 #include "debug.hh"
8 #include "scoreline.hh"
9 #include "pscore.hh"
10
11
12 /*
13   return all breakable columns
14  */
15 Line_of_cols
16 Break_algorithm::find_breaks() const
17 {
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;
24 }
25
26 // construct an appropriate Spacing_problem and solve it. 
27 Col_hpositions
28 Break_algorithm::solve_line(Line_of_cols curline) const
29 {
30    Spacing_problem sp;
31
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);
36
37    // misschien  moeven uit Spacing_problem? 
38    for (iter_top(pscore_.suz,i); i.ok(); i++) {
39        sp.add_ideal(i);
40    }
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;
48 }
49
50 Break_algorithm::Break_algorithm(PScore&s)
51     :pscore_(s)
52 {
53     linelength = s.paper_l_->linewidth;
54 }
55
56 bool
57 Break_algorithm::feasible(Line_of_cols curline) const
58 {
59     Real l =0;
60     for (int i=0; i < curline.size(); i++)
61         l +=curline[i]->width().length();
62     return l < linelength;    
63 }
64
65 void
66 Break_algorithm::problem_OK() const
67 {
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());
73     
74     assert(start->breakable_b());    
75     assert(end->breakable_b());
76 #endif
77 }