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"
26 Dot_configuration::badness () const
29 for (Dot_configuration::const_iterator i (begin ());
33 int demerit = sqr (p - i->second.pos_) * 2;
35 int dot_move_dir = sign (p - i->second.pos_);
37 && dot_move_dir != i->second.dir_)
39 else if (dot_move_dir != UP)
49 Dot_configuration::print () const
51 printf ("dotconf { ");
52 for (Dot_configuration::const_iterator i (begin ());
54 printf ("%d, ", i->first);
59 Shift K and following (preceding) entries up (down) as necessary to
60 prevent staffline collisions if D is up (down).
62 If K is in CFG, then do nothing.
66 Dot_configuration::shifted (int k, Direction d) const
68 Dot_configuration new_cfg (*problem_);
73 for (Dot_configuration::const_iterator i (begin ());
79 if (Staff_symbol_referencer::on_line (i->second.dot_, p))
86 new_cfg[p] = i->second;
90 if (new_cfg.find (p) == new_cfg.end ())
92 new_cfg[p + offset] = i->second;
98 Dot_configuration::const_iterator i (end ());
106 if (Staff_symbol_referencer::on_line (i->second.dot_, p))
113 new_cfg[p] = i->second;
117 if (new_cfg.find (p) == new_cfg.end ())
120 new_cfg[p + offset] = i->second;
123 while (i != begin ());
130 Remove the collision in CFG either by shifting up or down, whichever
134 Dot_configuration::remove_collision (int p)
136 bool collide = find (p) != end ();
140 Dot_configuration cfg_up = shifted (p, UP);
141 Dot_configuration cfg_down = shifted (p, DOWN);
143 int b_up = cfg_up.badness ();
144 int b_down = cfg_down.badness ();
146 *this = (b_up < b_down) ? cfg_up : cfg_down;
150 Dot_configuration::Dot_configuration (Dot_formatting_problem const &problem)
156 Dot_configuration::x_offset () const
159 for (Dot_configuration::const_iterator i (begin ());
161 off = max (off, problem_->head_skyline_.height ((*i).first));