]> git.donarmstrong.com Git - lilypond.git/blob - lily/molecule.cc
4e0bb337667a553918cbc633908ce4a51183e2be
[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 Interval
25 Molecule::extent(Axis a) const
26 {
27   Interval i;
28   for (iter_top (atoms_,c); c.ok(); c++)
29     i.unite (c->extent(a));
30   return i;
31 }
32
33 void
34 Molecule::translate (Offset o)
35 {
36   for (iter_top (atoms_,c); c.ok(); c++)
37     c->translate (o);
38 }
39
40 void
41 Molecule::translate_axis (Real x,Axis a)
42 {
43   for (iter_top (atoms_,c); c.ok(); c++)
44     c->translate_axis (x,a);
45 }
46
47 void
48 Molecule::add_molecule (Molecule const &m)
49 {
50   for (iter_top (m.atoms_,c); c.ok(); c++) 
51     {
52       add_atom (**c);
53     }
54 }
55
56
57 void
58 Molecule::add_at_edge (Axis a, Direction d, Molecule const &m, Real padding)
59 {
60   Real my_extent= atoms_.size()
61     ? extent ()[a][d] 
62     : 0.0;
63   
64   Real offset = my_extent -  m.extent ()[a][-d];
65   Molecule toadd (m);
66   toadd.translate_axis (offset + d * padding, a);
67   add_molecule (toadd);
68 }
69
70   
71   
72 void
73 Molecule::operator = (Molecule const &)
74 {
75   assert (false);
76 }
77
78 Molecule::Molecule (Molecule const &s)
79 {
80   add_molecule (s);
81 }
82
83 void
84 Molecule::print() const
85 {
86 #ifndef NPRINT
87   if (! check_debug)
88     return;
89   for (iter_top (atoms_,c); c.ok(); c++)
90     c->print();
91 #endif
92 }
93
94 void
95 Molecule::add_atom (Atom const &a)
96 {
97   atoms_.bottom().add (new Atom (a)); 
98 }
99
100 Molecule::Molecule (Atom const &a)
101 {
102   add_atom (a) ;
103 }