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 "staff-symbol-referencer.hh"
16 Dot_configuration::badness () const
19 for (Dot_configuration::const_iterator i (begin ());
23 int demerit = sqr (p - i->second.pos_) * 2;
25 int dot_move_dir = sign (p - i->second.pos_);
26 if (i->second.extremal_head_)
29 && dot_move_dir != i->second.dir_)
31 else if (dot_move_dir != UP)
34 else if (dot_move_dir != UP)
44 Dot_configuration::print () const
46 printf ("dotconf { ");
47 for (Dot_configuration::const_iterator i (begin ());
49 printf ("%d, ", i->first);
54 Shift K and following (preceding) entries up (down) as necessary to
55 prevent staffline collisions if D is up (down).
57 If K is in CFG, then do nothing.
61 Dot_configuration::shifted (int k, Direction d) const
63 Dot_configuration new_cfg;
68 for (Dot_configuration::const_iterator i (begin ());
74 if (Staff_symbol_referencer::on_line (i->second.dot_, p))
81 new_cfg[p] = i->second;
85 if (new_cfg.find (p) == new_cfg.end ())
87 new_cfg[p + offset] = i->second;
93 Dot_configuration::const_iterator i (end ());
101 if (Staff_symbol_referencer::on_line (i->second.dot_, p))
108 new_cfg[p] = i->second;
112 if (new_cfg.find (p) == new_cfg.end ())
115 new_cfg[p + offset] = i->second;
118 while (i != begin ());
125 Remove the collision in CFG either by shifting up or down, whichever
129 Dot_configuration::remove_collision (int p)
131 bool collide = find (p) != end ();
135 Dot_configuration cfg_up = shifted (p, UP);
136 Dot_configuration cfg_down = shifted (p, DOWN);
138 int b_up = cfg_up.badness ();
139 int b_down = cfg_down.badness ();
141 *this = (b_up < b_down) ? cfg_up : cfg_down;