2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
21 #include "dot-configuration.hh"
22 #include "dot-formatting-problem.hh"
23 #include "staff-symbol-referencer.hh"
27 Dot_configuration::badness () const
30 for (Dot_configuration::const_iterator
i (begin ());
34 int demerit
= sqr (p
- i
->second
.pos_
) * 2;
36 int dot_move_dir
= sign (p
- i
->second
.pos_
);
37 if (i
->second
.extremal_head_
)
40 && dot_move_dir
!= i
->second
.dir_
)
42 else if (dot_move_dir
!= UP
)
45 else if (dot_move_dir
!= UP
)
55 Dot_configuration::print () const
57 printf ("dotconf { ");
58 for (Dot_configuration::const_iterator
i (begin ());
60 printf ("%d, ", i
->first
);
65 Shift K and following (preceding) entries up (down) as necessary to
66 prevent staffline collisions if D is up (down).
68 If K is in CFG, then do nothing.
72 Dot_configuration::shifted (int k
, Direction d
) const
74 Dot_configuration
new_cfg (*problem_
);
79 for (Dot_configuration::const_iterator
i (begin ());
85 if (Staff_symbol_referencer::on_line (i
->second
.dot_
, p
))
92 new_cfg
[p
] = i
->second
;
96 if (new_cfg
.find (p
) == new_cfg
.end ())
98 new_cfg
[p
+ offset
] = i
->second
;
104 Dot_configuration::const_iterator
i (end ());
112 if (Staff_symbol_referencer::on_line (i
->second
.dot_
, p
))
119 new_cfg
[p
] = i
->second
;
123 if (new_cfg
.find (p
) == new_cfg
.end ())
126 new_cfg
[p
+ offset
] = i
->second
;
129 while (i
!= begin ());
136 Remove the collision in CFG either by shifting up or down, whichever
140 Dot_configuration::remove_collision (int p
)
142 bool collide
= find (p
) != end ();
146 Dot_configuration cfg_up
= shifted (p
, UP
);
147 Dot_configuration cfg_down
= shifted (p
, DOWN
);
149 int b_up
= cfg_up
.badness ();
150 int b_down
= cfg_down
.badness ();
152 *this = (b_up
< b_down
) ? cfg_up
: cfg_down
;
156 Dot_configuration::Dot_configuration (Dot_formatting_problem
const &problem
)
162 Dot_configuration::x_offset () const
165 for (Dot_configuration::const_iterator
i (begin ());
167 off
= max (off
, problem_
->head_skyline_
.height ((*i
).first
));