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 "font-metric.hh"
+#include "dimensions.hh"
#include "interval.hh"
#include "string.hh"
#include "molecule.hh"
-#include "atom.hh"
-#include "debug.hh"
+#include "debug.hh"
#include "killing-cons.tcc"
+
Box
Molecule::extent() const
{
return dim_[a];
}
-void
-Molecule::translate (Offset o)
+Molecule::Molecule (Box b, SCM func)
{
- for (Cons<Atom> * ptr = atom_list_; ptr; ptr = ptr->next_)
- {
- ptr->car_->off_ += o;
- }
- dim_.translate (o);
+ expr_ = func;
+ dim_ = b ;
}
-void
-Molecule::translate_axis (Real x,Axis a)
+Molecule::Molecule()
{
- for (Cons<Atom> * ptr = atom_list_; ptr; ptr = ptr->next_)
- ptr->car_->off_[a] += x;
-
- dim_[a] += x;
+ expr_ = SCM_EOL;
+ set_empty (true);
}
void
-Molecule::add_molecule (Molecule const &m)
+Molecule::translate (Offset o)
{
- Cons_list<Atom> al (copy_killing_cons_list (m.atom_list_));
-
- if (al.head_)
+ Axis a = X_AXIS;
+ while (a < NO_AXES)
{
- *al.tail_ = atom_list_;
- atom_list_ = al.head_;
+ if (abs(o[a]) > 30 CM
+ || isinf (o[a]) || isnan (o[a]))
+ {
+ programming_error ("Improbable offset for translation: setting to zero");
+ o[a] = 0.0;
+ }
+ incr (a);
}
- dim_.unite (m.dim_);
+
+ expr_ = gh_list (ly_symbol2scm ("translate-molecule"),
+ to_scm (o),
+ expr_, SCM_UNDEFINED);
+ if (!empty_b ())
+ dim_.translate (o);
}
+
void
-Molecule::add_atom (Atom const *al)
+Molecule::translate_axis (Real x,Axis a)
{
- Atom *a = new Atom(*al);
+ Offset o(0,0);
+ o[a] = x;
+ translate (o);
+}
- atom_list_ = new Killing_cons<Atom> (a, atom_list_);
-}
-void
-Molecule::operator=(Molecule const & src)
-{
- if (&src == this) return;
- delete atom_list_;
- atom_list_ = 0;
- dim_= src.dim_;
- add_molecule (src);
-}
-Molecule::Molecule (Molecule const &s)
+void
+Molecule::add_molecule (Molecule const &m)
{
- atom_list_ = 0;
- add_molecule (s);
+ expr_ = gh_list (ly_symbol2scm ("combine-molecule"),
+ m.expr_,
+ expr_, SCM_UNDEFINED);
+ dim_.unite (m.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 ();
+ gh_display (expr_);
#endif
}
void
-Molecule::do_center (Axis a)
+Molecule::align_to (Axis a, Direction d)
{
Interval i (extent (a));
- translate_axis (-i.center (), a);
-}
-
-Molecule::Molecule ()
-{
- dim_ = Box (Interval(0,0),Interval( 0,0 ));
- atom_list_ = 0;
+ Real r = (d == CENTER) ? i.center () : i[d];
+ translate_axis (-r, a);
}
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 expr_ == SCM_EOL;
+}
+
+
+SCM
+fontify_atom(Font_metric * met, SCM f)
+{
+ return gh_list (ly_symbol2scm ("fontify"),
+ ly_quote_scm (met->description ()), f, SCM_UNDEFINED);
+}