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--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "dot-configuration.hh"
12 #include "dot-formatting-problem.hh"
13 #include "staff-symbol-referencer.hh"
17 Dot_configuration::badness () const
20 for (Dot_configuration::const_iterator i (begin ());
24 int demerit = sqr (p - i->second.pos_) * 2;
26 int dot_move_dir = sign (p - i->second.pos_);
27 if (i->second.extremal_head_)
30 && dot_move_dir != i->second.dir_)
32 else if (dot_move_dir != UP)
35 else if (dot_move_dir != UP)
45 Dot_configuration::print () const
47 printf ("dotconf { ");
48 for (Dot_configuration::const_iterator i (begin ());
50 printf ("%d, ", i->first);
55 Shift K and following (preceding) entries up (down) as necessary to
56 prevent staffline collisions if D is up (down).
58 If K is in CFG, then do nothing.
62 Dot_configuration::shifted (int k, Direction d) const
64 Dot_configuration new_cfg (*problem_);
69 for (Dot_configuration::const_iterator i (begin ());
75 if (Staff_symbol_referencer::on_line (i->second.dot_, p))
82 new_cfg[p] = i->second;
86 if (new_cfg.find (p) == new_cfg.end ())
88 new_cfg[p + offset] = i->second;
94 Dot_configuration::const_iterator i (end ());
102 if (Staff_symbol_referencer::on_line (i->second.dot_, p))
109 new_cfg[p] = i->second;
113 if (new_cfg.find (p) == new_cfg.end ())
116 new_cfg[p + offset] = i->second;
119 while (i != begin ());
126 Remove the collision in CFG either by shifting up or down, whichever
130 Dot_configuration::remove_collision (int p)
132 bool collide = find (p) != end ();
136 Dot_configuration cfg_up = shifted (p, UP);
137 Dot_configuration cfg_down = shifted (p, DOWN);
139 int b_up = cfg_up.badness ();
140 int b_down = cfg_down.badness ();
142 *this = (b_up < b_down) ? cfg_up : cfg_down;
146 Dot_configuration::Dot_configuration (Dot_formatting_problem const &problem)
152 Dot_configuration::x_offset () const
155 for (Dot_configuration::const_iterator i (begin ());
157 off = max (off, problem_->head_skyline_.height ((*i).first));