]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/molecule.cc
release: 1.3.40
[lilypond.git] / lily / molecule.cc
index 032f0742fb037d0e44f2ee94412f602a26c4628f..db6472b9e547804ba21e6227505e00a2b6b16505 100644 (file)
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1998 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 "dimension.hh"
 #include "string.hh"
 #include "molecule.hh"
-#include "atom.hh"
+
 #include "debug.hh"
-#include "tex.hh"
+#include "killing-cons.tcc"
+
 
 Box
 Molecule::extent() const
 {
-  Box b;
-  for (iter_top (atoms_,c); c.ok(); c++)
-    b.unite (c->extent());
-  return b;
+  return dim_;
+}
+
+Interval
+Molecule::extent(Axis a) const
+{
+  return dim_[a];
+}
+
+Molecule::Molecule (Box b, SCM func)
+{
+  expr_ = func;
+  dim_ = b ;
+}
+
+Molecule::Molecule()
+{
+  expr_ = SCM_EOL;
+  set_empty (true);
 }
 
 void
 Molecule::translate (Offset o)
 {
-  for (iter_top (atoms_,c); c.ok(); c++)
-    c->translate (o);
+  Axis a = X_AXIS;
+  while (a < NO_AXES)
+    {
+      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);
+    }
+
+  expr_ = gh_list (ly_symbol2scm ("translate-molecule"),
+                  ly_offset2scm (o),
+                  expr_, SCM_UNDEFINED);
+  if (!empty_b ())
+    dim_.translate (o);
 }
+  
 
 void
 Molecule::translate_axis (Real x,Axis a)
 {
-  for (iter_top (atoms_,c); c.ok(); c++)
-    c->translate_axis (x,a);
-}
+  Offset o(0,0);
+  o[a] = x;
+  translate (o);
+}  
+
+
 
 void
 Molecule::add_molecule (Molecule const &m)
 {
-  for (iter_top (m.atoms_,c); c.ok(); c++) 
-    {
-      add_atom (**c);
-    }
+  expr_ = gh_list (ly_symbol2scm ("combine-molecule"),
+                  m.expr_,
+                  expr_, SCM_UNDEFINED);
+  dim_.unite (m.dim_);
 }
 
-
 void
-Molecule::add_at_edge (Axis a, Direction d, Molecule const &m)
+Molecule::set_empty (bool e)
 {
-  if (!atoms_.size()) 
+  if (e)
     {
-      add_molecule (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_axis (offset, a);
-  add_molecule (toadd);
 }
 
-  
-  
+
 void
-Molecule::operator = (Molecule const &)
+Molecule::align_to (Axis a, Direction d)
 {
-  assert (false);
+  Interval i (extent (a));
+  Real r =  (d == CENTER) ? i.center () : i[d];
+  translate_axis (-r, a);
 }
 
-Molecule::Molecule (Molecule const &s)
-{
-  add_molecule (s);
-}
 
 void
-Molecule::print() const
+Molecule::add_at_edge (Axis a, Direction d, Molecule const &m, Real padding)
 {
-#ifndef NPRINT
-  if (! check_debug)
-    return;
-  for (iter_top (atoms_,c); c.ok(); c++)
-    c->print();
-#endif
+  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);
 }
 
-void
-Molecule::add_atom (Atom const &a)
+bool
+Molecule::empty_b () const
 {
-  atoms_.bottom().add (new Atom (a)); 
+  return expr_ == SCM_EOL;
 }
 
-Molecule::Molecule (Atom const &a)
+
+SCM
+fontify_atom(Font_metric * met, SCM f)
 {
-  add_atom (a) ;
+  return  gh_list (ly_symbol2scm ("fontify"),
+                  ly_quote_scm (met->description ()), f, SCM_UNDEFINED);
 }