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