]> git.donarmstrong.com Git - lilypond.git/blob - lily/molecule.cc
def5674fcf2bb2c398b411352e04c1940544e9a2
[lilypond.git] / lily / molecule.cc
1 /*
2   molecule.cc -- implement Molecule
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "interval.hh"
10 #include "string.hh"
11 #include "molecule.hh"
12 #include "atom.hh"
13 #include "debug.hh"
14
15 Box
16 Molecule::extent() const
17 {
18   Box b;
19   for (iter_top (atoms_,c); c.ok(); c++)
20     b.unite (c->extent());
21   return b;
22 }
23
24 void
25 Molecule::translate (Offset o)
26 {
27   for (iter_top (atoms_,c); c.ok(); c++)
28     c->translate (o);
29 }
30
31 void
32 Molecule::translate_axis (Real x,Axis a)
33 {
34   for (iter_top (atoms_,c); c.ok(); c++)
35     c->translate_axis (x,a);
36 }
37
38 void
39 Molecule::add_molecule (Molecule const &m)
40 {
41   for (iter_top (m.atoms_,c); c.ok(); c++) 
42     {
43       add_atom (**c);
44     }
45 }
46
47
48 void
49 Molecule::add_at_edge (Axis a, Direction d, Molecule const &m)
50 {
51   if (!atoms_.size()) 
52     {
53       add_molecule (m);
54       return;
55     }
56   Real offset = extent ()[a][d] - m.extent ()[a][-d];
57   Molecule toadd (m);
58   toadd.translate_axis (offset, a);
59   add_molecule (toadd);
60 }
61
62   
63   
64 void
65 Molecule::operator = (Molecule const &)
66 {
67   assert (false);
68 }
69
70 Molecule::Molecule (Molecule const &s)
71 {
72   add_molecule (s);
73 }
74
75 void
76 Molecule::print() const
77 {
78 #ifndef NPRINT
79   if (! check_debug)
80     return;
81   for (iter_top (atoms_,c); c.ok(); c++)
82     c->print();
83 #endif
84 }
85
86 void
87 Molecule::add_atom (Atom const &a)
88 {
89   atoms_.bottom().add (new Atom (a)); 
90 }
91
92 Molecule::Molecule (Atom const &a)
93 {
94   add_atom (a) ;
95 }