2 molecule.cc -- implement Molecule
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include <libc-extension.hh> // isinf
12 #include "font-metric.hh"
13 #include "dimensions.hh"
14 #include "interval.hh"
16 #include "molecule.hh"
20 #include "ly-smobs.icc"
24 Molecule::smobbed_copy () const
26 Molecule * m = new Molecule (*this);
28 return m->smobbed_self ();
32 Molecule::extent (Axis a) const
37 Molecule::Molecule (Box b, SCM func)
50 Molecule::translate (Offset o)
55 if (abs (o[a]) > 100 CM
56 || isinf (o[a]) || isnan (o[a]))
58 programming_error ("Improbable offset for translation: setting to zero");
64 expr_ = scm_list_n (ly_symbol2scm ("translate-molecule"),
66 expr_, SCM_UNDEFINED);
73 Molecule::translate_axis (Real x,Axis a)
83 Molecule::add_molecule (Molecule const &m)
85 expr_ = scm_list_n (ly_symbol2scm ("combine-molecule"),
87 expr_, SCM_UNDEFINED);
92 Molecule::set_empty (bool e)
96 dim_[X_AXIS].set_empty ();
97 dim_[Y_AXIS].set_empty ();
101 dim_[X_AXIS] = Interval (0,0);
102 dim_[Y_AXIS] = Interval (0,0);
108 Molecule::align_to (Axis a, Direction d)
113 Interval i (extent (a));
114 Real r = (d == CENTER) ? i.center () : i[d];
115 translate_axis (-r, a);
122 Molecule::add_at_edge (Axis a, Direction d, Molecule const &m, Real padding,
125 Real my_extent= empty_b () ? 0.0 : dim_[a][d];
126 Interval i (m.extent (a));
130 programming_error ("Molecule::add_at_edge: adding empty molecule.");
136 Real offset = (my_extent - his_extent) + d*padding;
137 if (minimum > 0 && fabs (offset) < minimum)
138 offset = sign (offset) * minimum;
141 toadd.translate_axis (offset, a);
142 add_molecule (toadd);
148 Hmm... maybe this is not such a good idea ; stuff can be empty,
152 Molecule::empty_b () const
154 return expr_ == SCM_EOL;
158 Molecule::get_expr () const
166 Molecule::extent_box () const
170 IMPLEMENT_SIMPLE_SMOBS (Molecule);
174 Molecule::print_smob (SCM , SCM port, scm_print_state *)
176 scm_puts ("#<Molecule ", port);
178 Molecule *r = (Molecule *) ly_cdr (s);
179 String string (r->to_string ());
180 scm_puts ((char *)str.to_str0 (), port);
182 scm_puts (" >", port);
189 Molecule::mark_smob (SCM s)
191 Molecule *r = (Molecule *) ly_cdr (s);
196 IMPLEMENT_TYPE_P (Molecule, "ly:molecule?");
197 IMPLEMENT_DEFAULT_EQUAL_P (Molecule);