2 molecule.cc -- implement Molecule
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "interval.hh"
12 #include "molecule.hh"
15 #include "killing-cons.tcc"
19 Molecule::extent() const
25 Molecule::extent(Axis a) const
31 Molecule::translate (Offset o)
33 if (isinf (o.length ()))
35 programming_error ("Translating infinitely. Ignore.");
39 for (SCM ptr = gh_cdr (atom_list_); ptr != SCM_EOL; ptr = gh_cdr(ptr))
41 unsmob_atom (gh_car (ptr))->off_ += o;
48 Molecule::translate_axis (Real x,Axis a)
52 programming_error ("Translating infinitely. Ignore.");
55 for (SCM ptr = gh_cdr (atom_list_); ptr != SCM_EOL; ptr = gh_cdr(ptr))
57 unsmob_atom (gh_car (ptr))->off_[a] += x;
60 if (!dim_[a].empty_b ())
65 Molecule::add_molecule (Molecule const &m)
67 for (SCM ptr = gh_cdr (m.atom_list_); ptr != SCM_EOL; ptr = gh_cdr(ptr))
69 Atom *a = new Atom (*unsmob_atom (gh_car (ptr)));
70 add_atom (a->self_scm_);
76 Molecule::add_atom (SCM atomsmob)
78 gh_set_cdr_x (atom_list_,
79 gh_cons (atomsmob, gh_cdr (atom_list_)));
81 scm_unprotect_object (atomsmob);
85 Molecule::operator=(Molecule const & src)
90 atom_list_ = gh_cons (SCM_EOL,SCM_EOL);
96 Molecule::set_empty (bool e)
100 dim_[X_AXIS].set_empty ();
101 dim_[Y_AXIS].set_empty ();
105 dim_[X_AXIS] = Interval(0,0);
106 dim_[Y_AXIS] = Interval (0,0);
111 Molecule::print () const
114 for (SCM ptr = gh_cdr (atom_list_); ptr != SCM_EOL; ptr = gh_cdr(ptr))
115 gh_display (gh_car (ptr));
119 Molecule::Molecule (Molecule const &s)
121 atom_list_ = gh_cons (SCM_EOL, SCM_EOL);
126 Molecule::~Molecule ()
132 Molecule::align_to (Axis a, Direction d)
136 Interval i (extent (a));
137 translate_axis (-i.center (), a);
141 translate_axis (-extent (a)[d], a);
145 Molecule::Molecule ()
147 dim_[X_AXIS].set_empty ();
148 dim_[Y_AXIS].set_empty ();
149 atom_list_ = gh_cons (SCM_EOL, SCM_EOL);
154 Molecule::add_at_edge (Axis a, Direction d, Molecule const &m, Real padding)
156 Real my_extent= empty_b () ? 0.0 : dim_[a][d];
157 Interval i (m.extent ()[a]);
159 programming_error ("Molecule::add_at_edge: adding empty molecule.");
161 Real his_extent = i[-d];
162 Real offset = my_extent - his_extent;
164 toadd.translate_axis (offset + d * padding, a);
165 add_molecule (toadd);
169 Molecule::empty_b () const
171 return gh_cdr (atom_list_) == SCM_EOL;