]> git.donarmstrong.com Git - lilypond.git/blob - src/break.cc
release: 0.0.26
[lilypond.git] / src / break.cc
1 /*
2     do calculations for breaking problem
3     
4     */
5 #include "break.hh"
6 #include "paper.hh"
7 #include "linespace.hh"
8 #include "debug.hh"
9 #include "scoreline.hh"
10 #include "pscore.hh"
11
12
13 /*
14   return all breakable columns
15  */
16 Array<PCol *>
17 Break_algorithm::find_breaks() const
18 {
19     Array<PCol *> retval;
20     for (iter_top(pscore_.cols,c); c.ok(); c++)
21         if (c->breakable())
22             retval.push(c);
23
24     return retval;
25 }
26
27 // construct an appropriate Spacing_problem and solve it. 
28 Array<Real>
29 Break_algorithm::solve_line(Line_of_cols curline) const
30 {
31    Spacing_problem sp;
32
33    sp.add_column(curline[0], true, 0.0);
34    for (int i=1; i< curline.size()-1; i++)
35        sp.add_column(curline[i]);
36    sp.add_column(curline.last(), true, linelength);
37
38    // misschien  moeven uit Spacing_problem? 
39    for (iter_top(pscore_.suz,i); i.ok(); i++) {
40        sp.add_ideal(i);
41    }
42    Array<Real> the_sol=sp.solve();
43    return the_sol;
44 }
45
46 Break_algorithm::Break_algorithm(PScore&s)
47     :pscore_(s)
48 {
49     linelength = s.paper_l_->linewidth;
50 }
51
52 bool
53 Break_algorithm::feasible(Line_of_cols curline) const
54 {
55     Real l =0;
56     for (int i=0; i < curline.size(); i++)
57         l +=curline[i]->width().length();
58     return l < linelength;    
59 }
60
61 void
62 Break_algorithm::problem_OK() const
63 {
64     if (!pscore_.cols.size())
65         error("Score does not have any columns");
66 #ifndef NDEBUG
67     iter_top(pscore_.cols,start);
68     PCursor<PCol *> end (pscore_.cols.bottom());
69     
70     assert(start->breakable());    
71     assert(end->breakable());
72 #endif
73 }
74
75 /****************/
76
77 Col_configuration::Col_configuration()
78 {
79     energy = INFTY;
80 }
81
82 void
83 Col_configuration::add( PCol*c)
84 {
85     cols.push(c);
86 }
87
88 void
89 Col_configuration::setsol(Array<Real> sol)
90 {
91     config = sol;
92     energy = config.last();
93     config.pop();
94 }
95
96 void
97 Col_configuration::print() const
98 {
99 #ifndef NPRINT
100     mtor << "energy : " << energy << '\n';
101     mtor << "line of " << config.size() << " cols\n";
102 #endif
103 }
104 void
105 Col_configuration::OK()const
106 {
107 #ifndef NDEBUG
108     assert(config.size() == cols.size());
109 #endif
110 }