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