X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=lily%2Fmolecule.cc;h=45fa78b7ec5a5a019fd9a87d263e799beaf12ecc;hb=01e85a02b5866e42e2ef822797f3986f06289bc0;hp=4dfe7d6c1309dd0e130530e04fd7e12f26329ca8;hpb=86d86173c41d3a4b832ce67768d58c6416c71d4e;p=lilypond.git diff --git a/lily/molecule.cc b/lily/molecule.cc index 4dfe7d6c13..45fa78b7ec 100644 --- a/lily/molecule.cc +++ b/lily/molecule.cc @@ -3,99 +3,170 @@ source file of the GNU LilyPond music typesetter - (c) 1997 Han-Wen Nienhuys + (c) 1997--2000 Han-Wen Nienhuys */ +#include #include "interval.hh" -#include "dimen.hh" #include "string.hh" #include "molecule.hh" #include "atom.hh" #include "debug.hh" -#include "tex.hh" +#include "killing-cons.tcc" -String -Molecule::TeX_string() const -{ - String s; - for (iter_top (ats,c); c.ok(); c++) - s+=c->TeX_string(); - return s; -} Box Molecule::extent() const { - Box b; - for (iter_top (ats,c); c.ok(); c++) - b.unite (c->extent()); - return b; + return dim_; +} + +Interval +Molecule::extent(Axis a) const +{ + return dim_[a]; } void Molecule::translate (Offset o) { - for (iter_top (ats,c); c.ok(); c++) - c->translate (o); + if (isinf (o.length ())) + { + programming_error ("Translating infinitely. Ignore."); + return; + } + + for (SCM ptr = gh_cdr (atom_list_); ptr != SCM_EOL; ptr = gh_cdr(ptr)) + { + unsmob_atom (gh_car (ptr))->off_ += o; + } + if (!empty_b ()) + dim_.translate (o); } void -Molecule::translate (Real x,Axis a) +Molecule::translate_axis (Real x,Axis a) { - for (iter_top (ats,c); c.ok(); c++) - c->translate (x,a); + if (isinf (x)) + { + programming_error ("Translating infinitely. Ignore."); + return; + } + for (SCM ptr = gh_cdr (atom_list_); ptr != SCM_EOL; ptr = gh_cdr(ptr)) + { + unsmob_atom (gh_car (ptr))->off_[a] += x; + } + + if (!dim_[a].empty_b ()) + dim_[a] += x; } void -Molecule::add (Molecule const &m) +Molecule::add_molecule (Molecule const &m) { - for (iter_top (m.ats,c); c.ok(); c++) + for (SCM ptr = gh_cdr (m.atom_list_); ptr != SCM_EOL; ptr = gh_cdr(ptr)) { - add (**c); + Atom *a = new Atom (*unsmob_atom (gh_car (ptr))); + add_atom (a->self_scm_); } + dim_.unite (m.dim_); } +void +Molecule::add_atom (SCM atomsmob) +{ + gh_set_cdr_x (atom_list_, + gh_cons (atomsmob, gh_cdr (atom_list_))); + + scm_unprotect_object (atomsmob); +} void -Molecule::add_at_edge (Axis a, Direction d, Molecule const &m) +Molecule::operator=(Molecule const & src) { - if (!ats.size()) + if (&src == this) + return; + + atom_list_ = gh_cons (SCM_EOL,SCM_EOL); + dim_= src.dim_; + add_molecule (src); +} + +void +Molecule::set_empty (bool e) +{ + if (e) { - add (m); - return; + dim_[X_AXIS].set_empty (); + dim_[Y_AXIS].set_empty (); + } + else + { + dim_[X_AXIS] = Interval(0,0); + dim_[Y_AXIS] = Interval (0,0); } - Real offset = extent ()[a][d] - m.extent ()[a][-d]; - Molecule toadd (m); - toadd.translate (offset, a); - add (toadd); } - - void -Molecule::operator = (Molecule const &) +Molecule::print () const { - assert (false); +#ifndef NPRINT + for (SCM ptr = gh_cdr (atom_list_); ptr != SCM_EOL; ptr = gh_cdr(ptr)) + gh_display (gh_car (ptr)); +#endif } Molecule::Molecule (Molecule const &s) { - add (s); + atom_list_ = gh_cons (SCM_EOL, SCM_EOL); + set_empty (true); + add_molecule (s); } +Molecule::~Molecule () +{ +} + + void -Molecule::print() const +Molecule::align_to (Axis a, Direction d) { -#ifndef NPRINT - if (! check_debug) - return; - for (iter_top (ats,c); c.ok(); c++) - c->print(); -#endif + if (d == CENTER) + { + Interval i (extent (a)); + translate_axis (-i.center (), a); + } + else + { + translate_axis (-extent (a)[d], a); + } +} + +Molecule::Molecule () +{ + dim_[X_AXIS].set_empty (); + dim_[Y_AXIS].set_empty (); + atom_list_ = gh_cons (SCM_EOL, SCM_EOL); } + void -Molecule::add (Atom const &a) +Molecule::add_at_edge (Axis a, Direction d, Molecule const &m, Real padding) +{ + Real my_extent= empty_b () ? 0.0 : dim_[a][d]; + Interval i (m.extent ()[a]); + if (i.empty_b ()) + programming_error ("Molecule::add_at_edge: adding empty molecule."); + + Real his_extent = i[-d]; + Real offset = my_extent - his_extent; + Molecule toadd (m); + toadd.translate_axis (offset + d * padding, a); + add_molecule (toadd); +} + +bool +Molecule::empty_b () const { - ats.bottom().add (new Atom (a)); + return gh_cdr (atom_list_) == SCM_EOL; }