]> git.donarmstrong.com Git - lilypond.git/blob - lily/molecule.cc
release: 1.1.28
[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 #include "killing-cons.tcc"
15
16 Box
17 Molecule::extent() const
18 {
19   return dim_;
20 }
21
22 Interval
23 Molecule::extent(Axis a) const
24 {
25   return dim_[a];
26 }
27
28 void
29 Molecule::translate (Offset o)
30 {
31   for (Cons<Atom> *  ptr = atom_list_; ptr; ptr = ptr->next_)
32     {
33       ptr->car_->off_ += o;
34     }
35   dim_.translate (o);
36 }
37
38 void
39 Molecule::translate_axis (Real x,Axis a)
40 {
41   for (Cons<Atom> *  ptr = atom_list_; ptr; ptr = ptr->next_)
42     {
43       ptr->car_->off_[a] += x;
44     }
45   dim_[a] += x;
46 }
47
48 void
49 Molecule::add_molecule (Molecule const &m)
50 {
51   for (Cons<Atom> *  ptr = m.atom_list_; ptr; ptr = ptr->next_)
52     {
53       add_atom (ptr->car_);
54     }
55
56   dim_.unite (m.dim_);
57 }
58
59 void
60 Molecule::add_atom (Atom const *al)
61 {
62   Atom *a = new Atom(*al);
63
64   atom_list_ = new Killing_cons<Atom> (a, atom_list_);
65 }
66
67 void
68 Molecule::operator=(Molecule const & src)
69 {
70   if (&src == this) return;
71   delete atom_list_;
72   atom_list_ = 0;
73   dim_= src.dim_;
74   add_molecule (src);
75 }
76
77 Molecule::Molecule (Molecule const &s)
78 {
79   atom_list_ = 0;
80   add_molecule (s);
81 }
82
83 Molecule::~Molecule ()
84 {
85   delete atom_list_;
86 }
87
88 void
89 Molecule::print() const
90 {
91 #ifndef NPRINT
92   if (! check_debug)
93     return;
94   DOUT << "dim:";
95   for (Axis i=X_AXIS; i < NO_AXES; incr (i))
96     DOUT << axis_name_str (i) << " = " << dim_[i].str ();
97 #endif
98 }
99
100 void
101 Molecule::do_center (Axis a)
102 {
103   Interval i (extent (a));
104   translate_axis (-i.center (), a);
105 }
106
107 Molecule::Molecule ()
108 {
109   dim_ = Box (Interval(0,0),Interval( 0,0  ));
110   atom_list_ = 0;
111 }
112
113
114 void
115 Molecule::add_at_edge (Axis a, Direction d, Molecule const &m, Real padding)
116 {
117   Real my_extent= dim_[a][d];
118   
119   Real offset = my_extent -  m.extent ()[a][-d];
120   Molecule toadd (m);
121   toadd.translate_axis (offset + d * padding, a);
122   add_molecule (toadd);
123 }