2 spaceable-grob.cc -- implement Spaceable_grob
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "spaceable-grob.hh"
17 #include "pointer-group-interface.hh"
19 #include "paper-column.hh"
22 Spaceable_grob::get_minimum_distances (Grob *me)
24 return me->get_object ("minimum-distances");
27 /*todo: merge code of spring & rod?
30 Spaceable_grob::add_rod (Grob *me, Grob *p, Real d)
32 // printf ("rod %lf\n", d);
37 programming_error ("infinite rod");
39 SCM mins = get_minimum_distances (me);
40 SCM newdist = scm_from_double (d);
41 for (SCM s = mins; scm_is_pair (s); s = scm_cdr (s))
43 SCM dist = scm_car (s);
44 if (scm_car (dist) == p->self_scm ())
46 scm_set_cdr_x (dist, scm_max (scm_cdr (dist),
52 if (Paper_column::get_rank (p) < Paper_column::get_rank (me))
53 programming_error ("Adding reverse rod");
55 mins = scm_cons (scm_cons (p->self_scm (), newdist), mins);
56 me->set_object ("minimum-distances", mins);
60 Spaceable_grob::add_spring (Grob *me, Grob *other,
61 Real distance, Real inverse_strength)
63 if (distance <= 0.0 || inverse_strength < 0.0)
65 programming_error ("adding reverse spring, setting to unit");
67 inverse_strength = 1.0;
70 if (isinf (distance) || isnan (distance)
71 || isnan (inverse_strength))
73 /* strength == INF is possible. It means fixed distance. */
74 programming_error ("insane distance found");
76 inverse_strength = 1.0;
80 SCM mins = me->get_object ("ideal-distances");
81 for (SCM s = mins; scm_is_pair (s); s = scm_cdr (s))
83 Spring_smob *sp = unsmob_spring (scm_car (s));
84 if (sp->other_ == other)
86 programming_error ("already have that spring");
93 spring.inverse_strength_ = inverse_strength;
94 spring.distance_ = distance;
95 spring.other_ = other;
97 SCM ideal = me->get_object ("ideal-distances");
98 ideal = scm_cons (spring.smobbed_copy (), ideal);
99 me->set_object ("ideal-distances", ideal);
103 Spaceable_grob::get_spring (Grob *me, Grob *other, Real *dist, Real *inv_strength)
105 for (SCM s = me->get_object ("ideal-distances");
106 scm_is_pair (s); s = scm_cdr (s))
108 Spring_smob *spring = unsmob_spring (scm_car (s));
109 if (spring && spring->other_ == other)
111 *dist = spring->distance_;
112 *inv_strength = spring->inverse_strength_;
118 Spaceable_grob::remove_interface (Grob *me)
120 me->set_object ("minimum-distances", SCM_EOL);
121 me->set_object ("spacing-wishes", SCM_EOL);
122 me->set_object ("ideal-distances", SCM_EOL);
125 ADD_INTERFACE (Spaceable_grob, "spaceable-grob-interface",
126 "A layout object that takes part in the spacing problem. ",
127 "measure-length spacing-wishes penalty minimum-distances ideal-distances "
128 "keep-inside-line left-neighbors right-neighbors");