-#include "varray.hh"
+/*
+ molecule.cc -- implement Molecule
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
#include "interval.hh"
-#include "dimen.hh"
#include "string.hh"
#include "molecule.hh"
-#include "symbol.hh"
+#include "atom.hh"
#include "debug.hh"
-#include "tex.hh"
-
-void
-Atom::print() const
-{
- mtor << "texstring: " <<sym.tex<<"\n";
-}
+#include "killing-cons.tcc"
Box
-Atom::extent() const
-{
- Box b( sym.dim);
- b.translate(off);
- return b;
-}
-
-Atom::Atom(Symbol s)
-{
- sym=s;
-}
-
-
-String
-Atom::TeXstring() const
+Molecule::extent() const
{
- /* infinity checks. */
- assert( abs(off.x) < 100 CM);
- assert( abs(off.y) < 100 CM);
-
- // whugh.. Hard coded...
- String s("\\placebox{%}{%}{%}");
- Array<String> a;
- a.push(print_dimen(off.y));
- a.push(print_dimen(off.x));
- a.push(sym.tex);
- return substitute_args(s, a);
+ return dim_;
}
-/* *************** */
-
-String
-Molecule::TeXstring() const
+Interval
+Molecule::extent(Axis a) const
{
- String s;
- for(iter_top(ats,c); c.ok(); c++)
- s+=c->TeXstring();
- return s;
+ return dim_[a];
}
-Box
-Molecule::extent() const
+void
+Molecule::translate (Offset o)
{
- Box b;
- for(iter_top(ats,c); c.ok(); c++)
- b.unite(c->extent());
- return b;
+ for (Cons<Atom> * ptr = atom_list_; ptr; ptr = ptr->next_)
+ {
+ ptr->car_->off_ += o;
+ }
+ dim_.translate (o);
}
void
-Molecule::translate(Offset o)
+Molecule::translate_axis (Real x,Axis a)
{
- for (iter_top(ats,c); c.ok(); c++)
- c->translate(o);
+ for (Cons<Atom> * ptr = atom_list_; ptr; ptr = ptr->next_)
+ {
+ ptr->car_->off_[a] += x;
+ }
+ dim_[a] += x;
}
void
-Molecule::add(Molecule const &m)
+Molecule::add_molecule (Molecule const &m)
{
- for (iter_top(m.ats,c); c.ok(); c++) {
- add(**c);
+ for (Cons<Atom> * ptr = m.atom_list_; ptr; ptr = ptr->next_)
+ {
+ add_atom (ptr->car_);
}
+
+ dim_.unite (m.dim_);
}
void
-Molecule::add_right(Molecule const &m)
+Molecule::add_atom (Atom const *al)
{
- if (!ats.size()) {
- add(m);
- return;
- }
- Real xof=extent().x.right - m.extent().x.left;
- Molecule toadd(m);
- toadd.translate(Offset(xof, 0.0));
- add(toadd);
+ Atom *a = new Atom(*al);
+
+ atom_list_ = new Killing_cons<Atom> (a, atom_list_);
}
void
-Molecule::add_left(Molecule const &m)
+Molecule::operator=(Molecule const & src)
{
- if (!ats.size()) {
- add(m);
- return;
- }
- Real xof=extent().x.left - m.extent().x.right;
- Molecule toadd(m);
- toadd.translate(Offset(xof, 0.0));
- add(toadd);
+ if (&src == this) return;
+ delete atom_list_;
+ atom_list_ = 0;
+ dim_= src.dim_;
+ add_molecule (src);
}
+Molecule::Molecule (Molecule const &s)
+{
+ atom_list_ = 0;
+ add_molecule (s);
+}
-void
-Molecule::add_top(Molecule const &m)
+Molecule::~Molecule ()
{
- if (!ats.size()) {
- add(m);
- return;
- }
- Real yof=extent().y.right - m.extent().y.left;
- Molecule toadd(m);
- toadd.translate(Offset(0,yof));
- add(toadd);
+ delete atom_list_;
}
void
-Molecule::add_bottom(Molecule const &m)
+Molecule::print() const
{
- if (!ats.size()) {
- add(m);
- return;
- }
- Real yof=extent().y.left- m.extent().y.right;
- Molecule toadd(m);
- toadd.translate(Offset(0,yof));
- add(toadd);
+#ifndef NPRINT
+ if (! check_debug)
+ return;
+ DOUT << "dim:";
+ for (Axis i=X_AXIS; i < NO_AXES; incr (i))
+ DOUT << axis_name_str (i) << " = " << dim_[i].str ();
+#endif
}
void
-Molecule::operator = (Molecule const &)
+Molecule::do_center (Axis a)
{
- assert(false);
+ Interval i (extent (a));
+ translate_axis (-i.center (), a);
}
-Molecule::Molecule(Molecule const &s)
+Molecule::Molecule ()
{
- add(s);
+ dim_ = Box (Interval(0,0),Interval( 0,0 ));
+ atom_list_ = 0;
}
+
void
-Molecule::print() const
+Molecule::add_at_edge (Axis a, Direction d, Molecule const &m, Real padding)
{
- for (iter_top(ats,c); c.ok(); c++)
- c->print();
+ Real my_extent= dim_[a][d];
+
+ Real offset = my_extent - m.extent ()[a][-d];
+ Molecule toadd (m);
+ toadd.translate_axis (offset + d * padding, a);
+ add_molecule (toadd);
}