]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/molecule.cc
release: 1.0.1
[lilypond.git] / lily / molecule.cc
index ff047f2c771f89a4bbce7469a21b76f3cfc2105a..032f0742fb037d0e44f2ee94412f602a26c4628f 100644 (file)
-#include "varray.hh"
+/*
+  molecule.cc -- implement Molecule
+
+  source file of the GNU LilyPond music typesetter
+
+  (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
 #include "interval.hh"
-#include "dimen.hh"
+#include "dimension.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";    
-}
-
-Box
-Atom::extent() const
-{
-    Box b( sym.dim);
-    b.translate(off);
-    return b;
-}
-
-Atom::Atom(Symbol s)
-{
-    sym=s;
-}
-
-
-String
-Atom::TeX_string() 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);
-}
-
-/* *************** */
-
-String
-Molecule::TeX_string() const
-{
-    String s;
-    for(iter_top(ats,c); c.ok(); c++)
-       s+=c->TeX_string();
-    return s;
-}
-
 Box
 Molecule::extent() const
 {
-    Box b;
-    for(iter_top(ats,c); c.ok(); c++)
-       b.unite(c->extent());
-    return b;
+  Box b;
+  for (iter_top (atoms_,c); c.ok(); c++)
+    b.unite (c->extent());
+  return b;
 }
 
 void
-Molecule::translate(Offset o)
+Molecule::translate (Offset o)
 {
-    for (iter_top(ats,c); c.ok(); c++)
-       c->translate(o);
+  for (iter_top (atoms_,c); c.ok(); c++)
+    c->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 (iter_top (atoms_,c); c.ok(); c++)
+    c->translate_axis (x,a);
 }
 
 void
-Molecule::add_right(Molecule const &m)
+Molecule::add_molecule (Molecule const &m)
 {
-     if (!ats.size()) {
-       add(m);
-       return;
+  for (iter_top (m.atoms_,c); c.ok(); c++) 
+    {
+      add_atom (**c);
     }
-   Real xof=extent().x.right - m.extent().x.left;
-    Molecule toadd(m);
-    toadd.translate(Offset(xof, 0.0));
-    add(toadd);
 }
 
+
 void
-Molecule::add_left(Molecule const &m)
+Molecule::add_at_edge (Axis a, Direction d, Molecule const &m)
 {
-    if (!ats.size()) {
-       add(m);
-       return;
+  if (!atoms_.size()) 
+    {
+      add_molecule (m);
+      return;
     }
-    Real xof=extent().x.left - m.extent().x.right;
-    Molecule toadd(m);
-    toadd.translate(Offset(xof, 0.0));
-    add(toadd);
+  Real offset = extent ()[a][d] - m.extent ()[a][-d];
+  Molecule toadd (m);
+  toadd.translate_axis (offset, a);
+  add_molecule (toadd);
 }
 
-
+  
+  
 void
-Molecule::add_top(Molecule const &m)
+Molecule::operator = (Molecule const &)
 {
-      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);
+  assert (false);
 }
 
-void
-Molecule::add_bottom(Molecule const &m)
+Molecule::Molecule (Molecule const &s)
 {
-    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);
+  add_molecule (s);
 }
 
 void
-Molecule::operator = (Molecule const &)
+Molecule::print() const
 {
-    assert(false);
+#ifndef NPRINT
+  if (! check_debug)
+    return;
+  for (iter_top (atoms_,c); c.ok(); c++)
+    c->print();
+#endif
 }
 
-Molecule::Molecule(Molecule const &s)
+void
+Molecule::add_atom (Atom const &a)
 {
-    add(s);
+  atoms_.bottom().add (new Atom (a)); 
 }
 
-void
-Molecule::print() const
+Molecule::Molecule (Atom const &a)
 {
-    for (iter_top(ats,c); c.ok(); c++)
-       c->print();
+  add_atom (a) ;
 }