2 dot-implement.cc -- declare Dot_configuration
4 Source file of the GNU LilyPond music typesetter. Distributed under
5 terms of the GNU General Public License. LilyPond comes with NO
8 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
12 #include "dot-configuration.hh"
13 #include "dot-formatting-problem.hh"
14 #include "staff-symbol-referencer.hh"
18 Dot_configuration::badness () const
21 for (Dot_configuration::const_iterator i (begin ());
25 int demerit = sqr (p - i->second.pos_) * 2;
27 int dot_move_dir = sign (p - i->second.pos_);
28 if (i->second.extremal_head_)
31 && dot_move_dir != i->second.dir_)
33 else if (dot_move_dir != UP)
36 else if (dot_move_dir != UP)
46 Dot_configuration::print () const
48 printf ("dotconf { ");
49 for (Dot_configuration::const_iterator i (begin ());
51 printf ("%d, ", i->first);
56 Shift K and following (preceding) entries up (down) as necessary to
57 prevent staffline collisions if D is up (down).
59 If K is in CFG, then do nothing.
63 Dot_configuration::shifted (int k, Direction d) const
65 Dot_configuration new_cfg (*problem_);
70 for (Dot_configuration::const_iterator i (begin ());
76 if (Staff_symbol_referencer::on_line (i->second.dot_, p))
83 new_cfg[p] = i->second;
87 if (new_cfg.find (p) == new_cfg.end ())
89 new_cfg[p + offset] = i->second;
95 Dot_configuration::const_iterator i (end ());
103 if (Staff_symbol_referencer::on_line (i->second.dot_, p))
110 new_cfg[p] = i->second;
114 if (new_cfg.find (p) == new_cfg.end ())
117 new_cfg[p + offset] = i->second;
120 while (i != begin ());
127 Remove the collision in CFG either by shifting up or down, whichever
131 Dot_configuration::remove_collision (int p)
133 bool collide = find (p) != end ();
137 Dot_configuration cfg_up = shifted (p, UP);
138 Dot_configuration cfg_down = shifted (p, DOWN);
140 int b_up = cfg_up.badness ();
141 int b_down = cfg_down.badness ();
143 *this = (b_up < b_down) ? cfg_up : cfg_down;
147 Dot_configuration::Dot_configuration (Dot_formatting_problem const &problem)
153 Dot_configuration::x_offset () const
156 for (Dot_configuration::const_iterator i (begin ());
158 off = max (off, problem_->head_skyline_.height ((*i).first));