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
, Real x
)
113 Interval
i (extent (a
));
114 translate_axis (-i
.linear_combination (x
), a
);
121 Molecule::add_at_edge (Axis a
, Direction d
, Molecule
const &m
, Real padding
,
124 Real my_extent
= empty_b () ? 0.0 : dim_
[a
][d
];
125 Interval
i (m
.extent (a
));
129 programming_error ("Molecule::add_at_edge: adding empty molecule.");
135 Real offset
= (my_extent
- his_extent
) + d
*padding
;
136 if (minimum
> 0 && fabs (offset
) < minimum
)
137 offset
= sign (offset
) * minimum
;
140 toadd
.translate_axis (offset
, a
);
141 add_molecule (toadd
);
147 Hmm... maybe this is not such a good idea ; stuff can be empty,
151 Molecule::empty_b () const
153 return expr_
== SCM_EOL
;
157 Molecule::get_expr () const
165 Molecule::extent_box () const
169 IMPLEMENT_SIMPLE_SMOBS (Molecule
);
173 Molecule::print_smob (SCM
, SCM port
, scm_print_state
*)
175 scm_puts ("#<Molecule ", port
);
177 Molecule
*r
= (Molecule
*) ly_cdr (s
);
178 String
string (r
->to_string ());
179 scm_puts ((char *)str
.to_str0 (), port
);
181 scm_puts (" >", port
);
188 Molecule::mark_smob (SCM s
)
190 Molecule
*r
= (Molecule
*) ly_cdr (s
);
195 IMPLEMENT_TYPE_P (Molecule
, "ly:molecule?");
196 IMPLEMENT_DEFAULT_EQUAL_P (Molecule
);