source file of the GNU LilyPond music typesetter
- (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
+/*
+ ugh. Rewrite not finished yet. Still must copy atom lists.
+ */
+
+#include <math.h>
+
#include "interval.hh"
#include "string.hh"
#include "molecule.hh"
#include "atom.hh"
#include "debug.hh"
-
#include "killing-cons.tcc"
+
Box
Molecule::extent() const
{
void
Molecule::translate (Offset o)
{
- for (Cons<Atom> * ptr = atom_list_; ptr; ptr = ptr->next_)
+ if (isinf (o.length ()))
{
- ptr->car_->off_ += o;
+ programming_error ("Translating infinitely. Ignore.");
+ return;
}
- dim_.translate (o);
+
+ for (SCM ptr = gh_cdr (atom_list_); ptr != SCM_EOL; ptr = gh_cdr(ptr))
+ {
+ gh_set_car_x (ptr, translate_atom (o, gh_car (ptr)));
+ }
+ if (!empty_b ())
+ dim_.translate (o);
}
void
Molecule::translate_axis (Real x,Axis a)
{
- for (Cons<Atom> * ptr = atom_list_; ptr; ptr = ptr->next_)
- ptr->car_->off_[a] += x;
+ if (isinf (x))
+ {
+ programming_error ("Translating infinitely. Ignore.");
+ return;
+ }
+ for (SCM ptr = gh_cdr (atom_list_); ptr != SCM_EOL; ptr = gh_cdr(ptr))
+ {
+ gh_set_car_x (ptr, translate_atom_axis (x, a, gh_car (ptr)));
+ }
- dim_[a] += x;
+ if (!dim_[a].empty_b ())
+ dim_[a] += x;
}
void
Molecule::add_molecule (Molecule const &m)
{
- Cons_list<Atom> al;
- copy_killing_cons_list (al, m.atom_list_);
-
- if (al.head_)
+ for (SCM ptr = gh_cdr (m.atom_list_); ptr != SCM_EOL; ptr = gh_cdr(ptr))
{
- *al.tail_ = atom_list_;
- atom_list_ = al.head_;
- al.head_ =0;
+ add_atom (gh_car (ptr));
}
dim_.unite (m.dim_);
}
void
-Molecule::add_atom (Atom const *al)
+Molecule::add_atom (SCM atomsmob)
{
- Atom *a = new Atom(*al);
-
- atom_list_ = new Killing_cons<Atom> (a, atom_list_);
+ gh_set_cdr_x (atom_list_,
+ gh_cons (atomsmob, gh_cdr (atom_list_)));
}
void
Molecule::operator=(Molecule const & src)
{
- if (&src == this) return;
- delete atom_list_;
- atom_list_ = 0;
- dim_= src.dim_;
- add_molecule (src);
-}
+ if (&src == this)
+ return;
-Molecule::Molecule (Molecule const &s)
-{
- atom_list_ = 0;
- add_molecule (s);
+ atom_list_ = gh_cons (SCM_EOL,scm_list_copy (gh_cdr (src.atom_list_)));
+ dim_= src.dim_;
}
-Molecule::~Molecule ()
+void
+Molecule::set_empty (bool e)
{
- delete atom_list_;
+ if (e)
+ {
+ dim_[X_AXIS].set_empty ();
+ dim_[Y_AXIS].set_empty ();
+ }
+ else
+ {
+ dim_[X_AXIS] = Interval(0,0);
+ dim_[Y_AXIS] = Interval (0,0);
+ }
}
void
-Molecule::print() const
+Molecule::print () const
{
#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 ();
+ 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)
+{
+ atom_list_ = gh_cons (SCM_EOL, scm_list_copy (gh_cdr (s.atom_list_)));
+ dim_ = s.dim_;
+}
+
+Molecule::~Molecule ()
+{
+}
+
+
void
-Molecule::do_center (Axis a)
+Molecule::align_to (Axis a, Direction d)
{
- Interval i (extent (a));
- translate_axis (-i.center (), a);
+ if (d == CENTER)
+ {
+ Interval i (extent (a));
+ translate_axis (-i.center (), a);
+ }
+ else
+ {
+ translate_axis (-extent (a)[d], a);
+ }
}
Molecule::Molecule ()
{
- dim_ = Box (Interval(0,0),Interval( 0,0 ));
- atom_list_ = 0;
+ dim_[X_AXIS].set_empty ();
+ dim_[Y_AXIS].set_empty ();
+ atom_list_ = gh_cons (SCM_EOL, SCM_EOL);
}
void
Molecule::add_at_edge (Axis a, Direction d, Molecule const &m, Real padding)
{
- Real my_extent= dim_[a][d];
+ 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 offset = my_extent - m.extent ()[a][-d];
+ 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
+{
+ return gh_cdr (atom_list_) == SCM_EOL;
+}