X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmolecule.cc;h=bfbc525666c0bff128e1972ef5c701adb86ff08d;hb=ea9e5d2536fd8234d1c7e48acc26e161d1df90d4;hp=6a7709a5bce23ffc323dfc4cca2cf3004103f330;hpb=b02bb98ffea2c376ba67eb049b8ba6b04d76e084;p=lilypond.git diff --git a/lily/molecule.cc b/lily/molecule.cc index 6a7709a5bc..bfbc525666 100644 --- a/lily/molecule.cc +++ b/lily/molecule.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 1997--2002 Han-Wen Nienhuys + (c) 1997--2003 Han-Wen Nienhuys */ #include @@ -14,7 +14,7 @@ #include "interval.hh" #include "string.hh" #include "molecule.hh" -#include "debug.hh" +#include "warn.hh" #include "ly-smobs.icc" @@ -52,7 +52,7 @@ Molecule::translate (Offset o) Axis a = X_AXIS; while (a < NO_AXES) { - if (abs (o[a]) > 30 CM + if (abs (o[a]) > 100 CM || isinf (o[a]) || isnan (o[a])) { programming_error ("Improbable offset for translation: setting to zero"); @@ -64,7 +64,7 @@ Molecule::translate (Offset o) expr_ = scm_list_n (ly_symbol2scm ("translate-molecule"), ly_offset2scm (o), expr_, SCM_UNDEFINED); - if (!empty_b ()) + if (!is_empty ()) dim_.translate (o); } @@ -105,20 +105,26 @@ Molecule::set_empty (bool e) void -Molecule::align_to (Axis a, Direction d) +Molecule::align_to (Axis a, Real x) { + if (is_empty ()) + return ; + Interval i (extent (a)); - Real r = (d == CENTER) ? i.center () : i[d]; - translate_axis (-r, a); + translate_axis (-i.linear_combination (x), a); } +/* + See scheme Function. + */ void -Molecule::add_at_edge (Axis a, Direction d, Molecule const &m, Real padding) +Molecule::add_at_edge (Axis a, Direction d, Molecule const &m, Real padding, + Real minimum) { - Real my_extent= empty_b () ? 0.0 : dim_[a][d]; + Real my_extent= is_empty () ? 0.0 : dim_[a][d]; Interval i (m.extent (a)); Real his_extent; - if (i.empty_b ()) + if (i.is_empty ()) { programming_error ("Molecule::add_at_edge: adding empty molecule."); his_extent = 0.0; @@ -126,123 +132,23 @@ Molecule::add_at_edge (Axis a, Direction d, Molecule const &m, Real padding) else his_extent = i[-d]; - Real offset = my_extent - his_extent; + Real offset = (my_extent - his_extent) + d*padding; + if (minimum > 0 && fabs (offset) < minimum) + offset = sign (offset) * minimum; + Molecule toadd (m); - toadd.translate_axis (offset + d * padding, a); + toadd.translate_axis (offset, a); add_molecule (toadd); } -/* ly_? Thought we had the ly_ prefix for wrapping/adding to gh_ */ -SCM -Molecule::ly_set_molecule_extent_x (SCM mol, SCM axis, SCM np) -{ - Molecule* m = unsmob_molecule (mol); - SCM_ASSERT_TYPE (m, mol, SCM_ARG1, __FUNCTION__, "molecule"); - SCM_ASSERT_TYPE (ly_axis_p(axis), axis, SCM_ARG2, __FUNCTION__, "axis"); - SCM_ASSERT_TYPE (ly_number_pair_p (np), np, SCM_ARG3, __FUNCTION__, "number pair"); - - Interval iv = ly_scm2interval (np); - m->dim_[Axis (gh_scm2int (axis))] = iv; - - return SCM_UNDEFINED; -} - -SCM -Molecule::ly_get_molecule_extent (SCM mol, SCM axis) -{ - Molecule *m = unsmob_molecule (mol); - - if (!m || !ly_axis_p (axis)) - { - warning ("ly-get-molecule-extent: invalid arguments"); - return ly_interval2scm (Interval (0,0)); - } - - return ly_interval2scm (m->extent (Axis (gh_scm2int (axis)))); -} - - -SCM -Molecule::ly_molecule_combined_at_edge (SCM first, SCM axis, SCM direction, - SCM second, SCM padding) - -{ - Molecule * m1 = unsmob_molecule (first); - Molecule * m2 = unsmob_molecule (second); - Molecule result; - - - SCM_ASSERT_TYPE(ly_axis_p(axis), axis, SCM_ARG2, __FUNCTION__, "axis"); - SCM_ASSERT_TYPE(isdir_b (direction), direction, SCM_ARG3, __FUNCTION__, "dir"); - SCM_ASSERT_TYPE(gh_number_p(padding), padding, SCM_ARG4, __FUNCTION__, "number"); - - if (m1) - result = *m1; - if (m2) - result.add_at_edge (Axis (gh_scm2int (axis)), Direction (gh_scm2int (direction)), - *m2, gh_scm2double (padding)); - - return result.smobbed_copy (); -} - - -SCM -make_molecule (SCM expr, SCM xext, SCM yext) -{ - /* - TODO: typechecking. - */ - Box b (ly_scm2interval (xext), ly_scm2interval(yext)); - Molecule m (b, expr); - return m.smobbed_copy (); -} - -SCM -fontify_atom (Font_metric * met, SCM f) -{ - if (f == SCM_EOL) - return f; - else - return scm_list_n (ly_symbol2scm ("fontify"), - ly_quote_scm (met->description_), f, SCM_UNDEFINED); -} - -SCM -ly_fontify_atom (SCM met, SCM f) -{ - SCM_ASSERT_TYPE(unsmob_metrics (met), met, SCM_ARG1, __FUNCTION__, "font metric"); - - return fontify_atom (unsmob_metrics (met), f); -} - -SCM -ly_align_to_x (SCM mol, SCM axis, SCM dir) -{ - SCM_ASSERT_TYPE(unsmob_molecule (mol), mol, SCM_ARG1, __FUNCTION__, "molecule"); - SCM_ASSERT_TYPE(ly_axis_p(axis), axis, SCM_ARG2, __FUNCTION__, "axis"); - SCM_ASSERT_TYPE(isdir_b (dir), dir, SCM_ARG3, __FUNCTION__, "dir"); - - unsmob_molecule (mol)->align_to ((Axis)gh_scm2int (axis), Direction (gh_scm2int (dir))); - - return SCM_UNDEFINED; -} - - -static void -molecule_init () -{ - scm_c_define_gsubr ("ly-make-molecule", 3, 0, 0, (Scheme_function_unknown) make_molecule); - scm_c_define_gsubr ("ly-fontify-atom", 2, 0, 0, (Scheme_function_unknown) ly_fontify_atom); - scm_c_define_gsubr ("ly-align-to!", 3, 0, 0, (Scheme_function_unknown) ly_align_to_x); - scm_c_define_gsubr ("ly-combine-molecule-at-edge", 5 , 0, 0, (Scheme_function_unknown) Molecule::ly_molecule_combined_at_edge); - scm_c_define_gsubr ("ly-set-molecule-extent!", 3 , 0, 0, (Scheme_function_unknown) Molecule::ly_set_molecule_extent_x); - scm_c_define_gsubr ("ly-get-molecule-extent", 2 , 0, 0, (Scheme_function_unknown) Molecule::ly_get_molecule_extent); -} -ADD_SCM_INIT_FUNC (molecule,molecule_init); +/* + Hmm... maybe this is not such a good idea ; stuff can be empty, + while expr_ == '() + */ bool -Molecule::empty_b () const +Molecule::is_empty () const { return expr_ == SCM_EOL; } @@ -264,15 +170,9 @@ IMPLEMENT_SIMPLE_SMOBS (Molecule); int -Molecule::print_smob (SCM s, SCM port, scm_print_state *) +Molecule::print_smob (SCM , SCM port, scm_print_state *) { - scm_puts ("#str ()); - scm_puts ((char *)str.ch_C (), port); -#endif scm_puts (" >", port); return 1; @@ -287,6 +187,6 @@ Molecule::mark_smob (SCM s) return r->expr_; } -IMPLEMENT_TYPE_P (Molecule, "molecule?"); +IMPLEMENT_TYPE_P (Molecule, "ly:molecule?"); IMPLEMENT_DEFAULT_EQUAL_P (Molecule);