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