source file of the GNU LilyPond music typesetter
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+ (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"
+#include "killing-cons.tcc"
+
+#ifdef ATOM_SMOB
+#define MOL_EOL SCM_EOL
+#define NEXT_CELL(a) SCM_CDR(a)
+#define CELLTYPE SCM
+#define UNBOX_ATOM(a) Atom::atom_l (a)
+#define BOX_ATOM(a) a->make_smob ()
+#define NEWCELL(a,b) gh_cons (a,b)
+#define UNBOX_PTR(a) SCM_CAR(a)
+#else
+#define MOL_EOL 0
+#define NEXT_CELL(a) ptr->next_cons_p_
+#define CELLTYPE Cons<Atom>*
+#define UNBOX_ATOM(a) a
+#define UNBOX_PTR(a) a->car_p_
+#define BOX_ATOM(a) a
+#define NEWCELL(a,b) new Killing_cons<Atom>(a,b)
+#endif
-/* *************** */
-
-String
-Molecule::TeX_string() const
+Box
+Molecule::extent() const
{
- String s;
- for(iter_top(ats,c); c.ok(); c++)
- s+=c->TeX_string();
- return s;
+ return dim_;
}
-Box
-Molecule::extent() const
+Interval
+Molecule::extent(Axis a) const
{
- Box b;
- for(iter_top(ats,c); c.ok(); c++)
- b.unite(c->extent());
- return b;
+ return dim_[a];
}
void
-Molecule::translate(Offset o)
+Molecule::translate (Offset o)
{
- for (iter_top(ats,c); c.ok(); c++)
- c->translate(o);
+ for (CELLTYPE ptr = atom_list_; ptr != MOL_EOL; ptr = NEXT_CELL(ptr))
+ {
+ UNBOX_ATOM(UNBOX_PTR(ptr))->off_ += o;
+ }
+ dim_.translate (o);
}
void
-Molecule::add(Molecule const &m)
+Molecule::translate_axis (Real x,Axis a)
{
- for (iter_top(m.ats,c); c.ok(); c++) {
- add(**c);
- }
+ for (CELLTYPE ptr = atom_list_; ptr != MOL_EOL; ptr = NEXT_CELL(ptr))
+ UNBOX_ATOM (UNBOX_PTR(ptr))->off_[a] += x;
+
+ dim_[a] += x;
}
void
-Molecule::add_right(Molecule const &m)
+Molecule::add_molecule (Molecule const &m)
{
- 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);
+ for (CELLTYPE ptr = m.atom_list_; ptr != MOL_EOL; ptr = NEXT_CELL(ptr))
+ add_atom(UNBOX_ATOM (UNBOX_PTR(ptr)));
+
+ dim_.unite (m.dim_);
}
void
-Molecule::add_left(Molecule const &m)
+Molecule::add_atom (Atom const *al)
{
- 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);
+ Atom *a = new Atom(*al);
+
+ atom_list_ = NEWCELL(BOX_ATOM(a), atom_list_);
}
+
+
void
-Molecule::add_top(Molecule const &m)
+Molecule::operator=(Molecule const & src)
{
- 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);
+ if (&src == this)
+ return;
+
+
+
+#ifndef ATOM_SMOB
+ delete atom_list_;
+#endif
+
+ atom_list_ = MOL_EOL;
+ dim_= src.dim_;
+ add_molecule (src);
+}
+
+Molecule::Molecule (Molecule const &s)
+{
+ atom_list_ = MOL_EOL;
+ add_molecule (s);
+}
+
+Molecule::~Molecule ()
+{
+#ifndef ATOM_SMOB
+ delete atom_list_;
+#endif
}
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_ = MOL_EOL;
}
+
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);
}
-void
-Molecule::add(Atom const &a)
+bool
+Molecule::empty_b() const
{
- ats.bottom().add(new Atom(a));
+ return atom_list_ == MOL_EOL;
}