]> git.donarmstrong.com Git - lilypond.git/blob - lily/page-layout-problem.cc
Refactor distribute_loose_lines.
[lilypond.git] / lily / page-layout-problem.cc
1 /*
2   page-layout-problem.cc -- space systems nicely on a page. If systems can
3   be stretched, do that too.
4
5   source file of the GNU LilyPond music typesetter
6
7   (c) 2009 Joe Neeman <joeneeman@gmail.com>
8 */
9
10 #include "page-layout-problem.hh"
11
12 #include "align-interface.hh"
13 #include "international.hh"
14 #include "item.hh"
15 #include "output-def.hh"
16 #include "paper-book.hh"
17 #include "pointer-group-interface.hh"
18 #include "prob.hh"
19 #include "skyline-pair.hh"
20 #include "system.hh"
21
22 Page_layout_problem::Page_layout_problem (Paper_book *pb, SCM page_scm, SCM systems)
23   : bottom_skyline_ (DOWN)
24 {
25   Prob *page = unsmob_prob (page_scm);
26   header_height_ = 0;
27   footer_height_ = 0;
28   page_height_ = 100;
29
30   if (page)
31     {
32       Stencil *head = unsmob_stencil (page->get_property ("head-stencil"));
33       Stencil *foot = unsmob_stencil (page->get_property ("foot-stencil"));
34
35       header_height_ = head ? head->extent (Y_AXIS).length () : 0;
36       footer_height_ = foot ? foot->extent (Y_AXIS).length () : 0;
37       page_height_ = robust_scm2double (page->get_property ("paper-height"), 100);
38     }
39
40   // Initially, bottom_skyline_ represents the top of the page. Make
41   // it solid, so that the top of the first system will be forced
42   // below the top of the printable area.
43   bottom_skyline_.set_minimum_height (-header_height_);
44
45   SCM between_system_spacing = SCM_EOL;
46   SCM after_title_spacing = SCM_EOL;
47   SCM before_title_spacing = SCM_EOL;
48   SCM between_title_spacing = SCM_EOL;
49
50   // first_system_spacing controls the spring from the top of the printable
51   // area to the first staff. It allows the user to control the offset of
52   // the first staff (as opposed to the top of the first system) from the
53   // top of the page. Similarly for last_system_spacing.
54   SCM first_system_spacing = SCM_EOL;
55   SCM last_system_spacing = SCM_EOL;
56   if (pb && pb->paper_)
57     {
58       Output_def *paper = pb->paper_;
59       between_system_spacing = paper->c_variable ("between-system-spacing");
60       after_title_spacing = paper->c_variable ("after-title-spacing");
61       before_title_spacing = paper->c_variable ("before-title-spacing");
62       between_title_spacing = paper->c_variable ("between-title-spacing");
63       last_system_spacing = paper->c_variable ("last-system-spacing");
64       first_system_spacing = paper->c_variable ("first-system-spacing");
65       if (scm_is_pair (systems) && unsmob_prob (scm_car (systems)))
66         first_system_spacing = paper->c_variable ("first-system-title-spacing");
67
68       // Note: the page height here does _not_ reserve space for headers and
69       // footers. This is because we want to anchor the first-system-spacing
70       // spring at the _top_ of the header.
71       page_height_ -= robust_scm2double (paper->c_variable ("top-margin"), 0)
72         + robust_scm2double (paper->c_variable ("bottom-margin"), 0);
73     }
74   bool last_system_was_title = false;
75
76
77   for (SCM s = systems; scm_is_pair (s); s = scm_cdr (s))
78     {
79       bool first = (s == systems);
80
81       if (Grob *g = unsmob_grob (scm_car (s)))
82         {
83           System *sys = dynamic_cast<System*> (g);
84           if (!sys)
85             {
86               programming_error ("got a grob for vertical spacing that wasn't a System");
87               continue;
88             }
89
90           SCM spec = first ? first_system_spacing
91             : (last_system_was_title ? after_title_spacing : between_system_spacing);
92           Spring spring (first ? 0 : 1, 0.0);
93           Real padding = 0.0;
94           alter_spring_from_spacing_spec (spec, &spring);
95           read_spacing_spec (spec, &padding, ly_symbol2scm ("padding"));
96
97           append_system (sys, spring, padding);
98           last_system_was_title = false;
99         }
100       else if (Prob *p = unsmob_prob (scm_car (s)))
101         {
102           SCM spec = first ? first_system_spacing
103             : (last_system_was_title ? between_title_spacing : before_title_spacing);
104           Spring spring (first ? 0 : 1, 0.0);
105           Real padding = 0.0;
106           alter_spring_from_spacing_spec (spec, &spring);
107           read_spacing_spec (spec, &padding, ly_symbol2scm ("padding"));
108
109           append_prob (p, spring, padding);
110           last_system_was_title = true;
111         }
112       else
113         programming_error ("got a system that was neither a Grob nor a Prob");
114     }
115
116   Spring last_spring (0, 0);
117   Real last_padding = 0;
118   alter_spring_from_spacing_spec (last_system_spacing, &last_spring);
119   read_spacing_spec (last_system_spacing, &last_padding, ly_symbol2scm ("padding"));
120   last_spring.ensure_min_distance (last_padding - bottom_skyline_.max_height () + footer_height_);
121   springs_.push_back (last_spring);
122 }
123
124 void
125 Page_layout_problem::set_header_height (Real height)
126 {
127   header_height_ = height;
128 }
129
130 void
131 Page_layout_problem::set_footer_height (Real height)
132 {
133   footer_height_ = height;
134 }
135
136 Grob*
137 Page_layout_problem::find_vertical_alignment (System *sys)
138 {
139   extract_grob_set (sys, "elements", elts);
140   for (vsize i = 0; i < elts.size (); ++i)
141     if (Align_interface::has_interface (elts[i]))
142       return elts[i];
143
144   return 0;
145 }
146
147 void
148 Page_layout_problem::append_system (System *sys, Spring const& spring, Real padding)
149 {
150   Grob *align = find_vertical_alignment (sys);
151   if (!align)
152     {
153       sys->programming_error ("no VerticalAlignment in system: can't do vertical spacing");
154       return;
155     }
156
157   align->set_property ("positioning-done", SCM_BOOL_T);
158
159   extract_grob_set (align, "elements", elts);
160   vector<Real> minimum_offsets = Align_interface::get_minimum_translations (align, elts, Y_AXIS,
161                                                                             false, 0, 0);
162
163   Skyline up_skyline (UP);
164   Skyline down_skyline (DOWN);
165   build_system_skyline (elts, minimum_offsets, &up_skyline, &down_skyline);
166
167   Real minimum_distance = up_skyline.distance (bottom_skyline_) + padding;
168
169   Spring spring_copy = spring;
170   spring_copy.ensure_min_distance (minimum_distance);
171   springs_.push_back (spring_copy);
172
173   bottom_skyline_ = down_skyline;
174   elements_.push_back (Element (elts, minimum_offsets));
175
176   // Add the springs for the VerticalAxisGroups in this system.
177
178   // If the user has specified the offsets of the individual staves, fix the
179   // springs at the given distances. Otherwise, use stretchable springs.
180   SCM details = get_details (elements_.back ());
181   SCM manual_dists = ly_assoc_get (ly_symbol2scm ("alignment-distances"), details, SCM_EOL);
182   vsize last_spaceable_staff = 0;
183   bool first_live_element = true;
184   for (vsize i = 0; i < elts.size (); ++i)
185     {
186       if (elts[i]->is_live () && is_spaceable (elts[i]))
187         {
188           // We don't add a spring for the first live element, since
189           // we are only adding springs _between_ staves here.
190           if (first_live_element)
191             {
192               if (i > 0)
193                 add_loose_lines_as_spaceable_lines (elts, minimum_offsets, 0, i-1);
194
195               first_live_element = false;
196               last_spaceable_staff = i;
197               continue;
198             }
199
200           Spring spring (0.5, 0.0);
201           SCM spec = elts[last_spaceable_staff]->get_property ("next-staff-spacing");
202           alter_spring_from_spacing_spec (spec, &spring);
203
204           springs_.push_back (spring);
205           Real min_distance = minimum_offsets[last_spaceable_staff] - minimum_offsets[i];
206           springs_.back ().ensure_min_distance (min_distance);
207
208           if (scm_is_pair (manual_dists))
209             {
210               if (scm_is_number (scm_car (manual_dists)))
211                 {
212                   Real dy = scm_to_double (scm_car (manual_dists));
213
214                   springs_.back ().set_distance (dy);
215                   springs_.back ().set_min_distance (dy);
216                   springs_.back ().set_inverse_stretch_strength (0);
217                 }
218               manual_dists = scm_cdr (manual_dists);
219             }
220           last_spaceable_staff = i;
221         }
222     }
223   // Any loose lines hanging off the end are treated as spaceable
224   // lines.  This might give slightly weird results if the hanging
225   // systems have staff-affinity != UP. It's not quite clear what
226   // should happen in that case, though.
227   if (last_spaceable_staff + 1 < elts.size ())
228     add_loose_lines_as_spaceable_lines (elts, minimum_offsets,
229                                         first_live_element ? 0 : last_spaceable_staff + 1,
230                                         elts.size () - 1);
231 }
232
233 void
234 Page_layout_problem::add_loose_lines_as_spaceable_lines (vector<Grob*> const& elts,
235                                                          vector<Real> const& minimum_offsets,
236                                                          vsize first, vsize last)
237 {
238   Direction last_affinity = UP;
239   SCM last_spec = SCM_EOL;
240   bool found_live_line = false;
241   for (vsize i = first; i <= last; ++i)
242     {
243       if (elts[i]->is_live ())
244         {
245           Direction affinity = robust_scm2dir (elts[i]->get_property ("staff-affinity"), CENTER);
246           if (affinity > last_affinity)
247             {
248               warning (_ ("staff-affinities should only decrease"));
249               affinity = last_affinity;
250             }
251
252           SCM spec = elts[i]->get_property ("inter-staff-spacing");
253           if ((affinity != DOWN && found_live_line)
254               || (affinity == DOWN && i != last)) // FIXME: we want to know if we are the last _live_ line.
255             spec = elts[i]->get_property ("inter-loose-line-spacing");
256
257           Spring spring (1.0, 0.0);
258           // When affinity == DOWN, the spacing spec specifies the
259           // spacing to the staff below.
260           if (affinity == DOWN)
261             alter_spring_from_spacing_spec (last_spec, &spring);
262           else
263             alter_spring_from_spacing_spec (spec, &spring);
264
265           Real min_distance = (i > 0 ? minimum_offsets[i-1] : 0) - minimum_offsets[i];
266           spring.ensure_min_distance (min_distance);
267
268           // The first line in a system doesn't get a spring.
269           if (first > 0 || found_live_line)
270             springs_.push_back (spring);
271
272           mark_as_spaceable (elts[i]);
273           last_spec = spec;
274           last_affinity = affinity;
275           found_live_line = true;
276         }
277     }
278
279   if (found_live_line && last + 1 < elts.size ())
280     {
281       Spring spring (1.0, 0.0);
282       if (last_affinity == UP)
283         warning (_ ("a system with staff-affinity UP is stranded above the system"));
284       alter_spring_from_spacing_spec (last_spec, &spring);
285
286       Real min_distance = minimum_offsets[last] - minimum_offsets[last+1];
287       spring.ensure_min_distance (min_distance);
288       springs_.push_back (spring);
289     }
290 }
291
292 void
293 Page_layout_problem::append_prob (Prob *prob, Spring const& spring, Real padding)
294 {
295   Skyline_pair *sky = Skyline_pair::unsmob (prob->get_property ("vertical-skylines"));
296   Real minimum_distance = 0;
297   if (sky)
298     {
299       minimum_distance = (*sky)[UP].distance (bottom_skyline_);
300       bottom_skyline_ = (*sky)[DOWN];
301     }
302   else if (Stencil *sten = unsmob_stencil (prob->get_property ("stencil")))
303     {
304       Interval iv = sten->extent (Y_AXIS);
305       minimum_distance = iv[UP] - bottom_skyline_.max_height ();
306
307       bottom_skyline_.clear ();
308       bottom_skyline_.set_minimum_height (iv[DOWN]);
309     }
310   minimum_distance += padding;
311
312   Spring spring_copy = spring;
313   spring_copy.ensure_min_distance (minimum_distance);
314   springs_.push_back (spring_copy);
315   elements_.push_back (Element (prob));
316 }
317
318 void
319 Page_layout_problem::solve_rod_spring_problem (bool ragged)
320 {
321   Simple_spacer spacer;
322
323   for (vsize i = 0; i < springs_.size (); ++i)
324     spacer.add_spring (springs_[i]);
325
326   Real bottom_padding = 0;
327   Interval first_staff_iv (0, 0);
328   Interval last_staff_iv (0, 0);
329   if (elements_.size ())
330     {
331       first_staff_iv = first_staff_extent (elements_[0]);
332       last_staff_iv = last_staff_extent (elements_.back ());
333
334       // TODO: junk bottom-space now that we have last-spring-spacing?
335       // bottom-space has the flexibility that one can do it per-system.
336       // NOTE: bottom-space is misnamed since it is not stretchable space.
337       if (Prob *p = elements_.back ().prob)
338         bottom_padding = robust_scm2double (p->get_property ("bottom-space"), 0);
339       else if (elements_.back ().staves.size ())
340         {
341           SCM details = get_details (elements_.back ());
342           bottom_padding = robust_scm2double (ly_assoc_get (ly_symbol2scm ("bottom-space"),
343                                                             details,
344                                                             SCM_BOOL_F),
345                                               0.0);
346         }
347     }
348
349   spacer.solve (page_height_ - bottom_padding, ragged);
350   solution_ = spacer.spring_positions ();
351 }
352
353 // The solution_ vector stores the position of every live VerticalAxisGroup
354 // and every title. From that information,
355 // 1) within each system, stretch the staves so they land at the right position
356 // 2) find the offset of each system (relative to the printable area of the page).
357 // TODO: this function is getting too long, maybe split it up?
358 SCM
359 Page_layout_problem::find_system_offsets ()
360 {
361   SCM system_offsets = SCM_EOL;
362   SCM *tail = &system_offsets;
363
364   // spring_idx 0 is the top of the page. Interesting values start from 1.
365   vsize spring_idx = 1;
366   for (vsize i = 0; i < elements_.size (); ++i)
367     {
368       if (elements_[i].prob)
369         {
370           *tail = scm_cons (scm_from_double (solution_[spring_idx]), SCM_EOL);
371           tail = SCM_CDRLOC (*tail);
372           spring_idx++;
373         }
374       else
375         {
376           // Getting this signs right here is a little tricky. The configuration
377           // we return has zero at the top of the page and positive numbers further
378           // down, as does the solution_ vector.  Within a staff, however, positive
379           // numbers are up.
380           // TODO: perhaps change the way the page 'configuration variable works so
381           // that it is consistent with the usual up/down sign conventions in
382           // Lilypond. Then this would be less confusing.
383
384           // These two positions are relative to the page (with positive numbers being
385           // down).
386           Real first_staff_position = solution_[spring_idx];
387           Real first_staff_min_translation = elements_[i].min_offsets.size () ? elements_[i].min_offsets[0] : 0;
388           Real system_position = first_staff_position + first_staff_min_translation;
389
390           // Position the staves within this system.
391           Real translation = 0;
392           bool found_live_staff = false;
393           vector<Grob*> loose_lines;
394           vector<Real> const& min_offsets = elements_[i].min_offsets;
395           vector<Real> loose_line_min_distances;
396           Grob *last_spaceable_line = 0;
397           Real last_spaceable_line_translation = 0;
398           vsize last_live_staff = 0;
399           for (vsize staff_idx = 0; staff_idx < elements_[i].staves.size (); ++staff_idx)
400             {
401               Grob *staff = elements_[i].staves[staff_idx];
402
403               // Dead VerticalAxisGroups didn't participate in the
404               // rod-and-spring problem, but they still need to be
405               // translated. We translate them by the same amount as
406               // the VerticalAxisGroup directly before.  (but we don't
407               // increment spring_idx!)
408               if (is_spaceable (staff) || !staff->is_live ())
409                 {
410                   if (staff->is_live ())
411                     {
412                       // this is relative to the system: negative numbers are down.
413                       translation = system_position - solution_[spring_idx];
414                       found_live_staff = true;
415                       spring_idx++;
416
417                       // Lay out any non-spaceable lines between this line and
418                       // the last one.
419                       if (loose_lines.size ())
420                         {
421                           loose_line_min_distances.push_back (min_offsets[last_live_staff] - min_offsets[staff_idx]);
422                           loose_lines.push_back (staff);
423                           distribute_loose_lines (loose_lines, loose_line_min_distances,
424                                                   last_spaceable_line_translation, translation);
425                           loose_lines.clear ();
426                           loose_line_min_distances.clear ();
427                         }
428                       last_spaceable_line = staff;
429                       last_spaceable_line_translation = translation;
430                       last_live_staff = staff_idx;
431                     }
432
433                   staff->translate_axis (translation, Y_AXIS);
434                 }
435               // We only need to deal with loose lines if we've
436               // already found a live staff (because any loose lines
437               // that occur before our first live staff are treated as
438               // spaced lines anyway).
439               else if (found_live_staff)
440                 {
441                   if (loose_lines.empty ())
442                     loose_lines.push_back (last_spaceable_line);
443
444                   loose_lines.push_back (staff);
445                   loose_line_min_distances.push_back (min_offsets[last_live_staff] - min_offsets[staff_idx]);
446                   last_live_staff = staff_idx;
447                 }
448             }
449
450           // Corner case: even if a system has no live staves, it still takes up
451           // one spring (a system with one live staff also takes up one spring),
452           // which we need to increment past.
453           if (!found_live_staff)
454             spring_idx++;
455
456           *tail = scm_cons (scm_from_double (system_position), SCM_EOL);
457           tail = SCM_CDRLOC (*tail);
458         }
459     }
460
461   assert (spring_idx == solution_.size () - 1);
462   return system_offsets;
463 }
464
465 // Given two lines that are already spaced (the first and last
466 // elements of loose_lines), distribute some unspaced lines between
467 // them.
468 void
469 Page_layout_problem::distribute_loose_lines (vector<Grob*> const &loose_lines,
470                                              vector<Real> const &min_distances,
471                                              Real first_translation, Real last_translation)
472 {
473   Simple_spacer spacer;
474   for (vsize i = 0; i + 1 < loose_lines.size (); ++i)
475     {
476       SCM spec = get_spacing_spec (loose_lines[i], loose_lines[i+1]);
477       Spring spring (1.0, 0.0);
478       alter_spring_from_spacing_spec (spec, &spring);
479       spring.ensure_min_distance (min_distances[i]);
480
481       if (spec == SCM_BOOL_F)
482         {
483           // Insert a very flexible spring, so it doesn't have much effect.
484           spring.set_inverse_stretch_strength (100000);
485           spring.set_inverse_compress_strength (100000);
486         }
487
488       spacer.add_spring (spring);
489     }
490
491   // Remember: offsets are decreasing, since we're going from UP to DOWN!
492   spacer.solve (first_translation - last_translation, false);
493
494   vector<Real> solution = spacer.spring_positions ();
495   for (vsize i = 1; i + 1 < solution.size (); ++i)
496     loose_lines[i]->translate_axis (first_translation - solution[i], Y_AXIS);
497 }
498
499 SCM
500 Page_layout_problem::solution (bool ragged)
501 {
502   solve_rod_spring_problem (ragged);
503   return find_system_offsets ();
504 }
505
506 // Build upper and lower skylines for a system. We don't yet know the positions
507 // of the staves within the system, so we make the skyline as conservative as
508 // possible. That is, for the upper skyline, we pretend that all of the staves
509 // in the system are packed together close to the top system; for the lower
510 // skyline, we pretend that all of the staves are packed together close to
511 // the bottom system.
512 //
513 // The upper skyline is relative to the top staff; the lower skyline is relative to
514 // the bottom staff.
515 void
516 Page_layout_problem::build_system_skyline (vector<Grob*> const& staves,
517                                            vector<Real> const& minimum_translations,
518                                            Skyline *up,
519                                            Skyline *down)
520 {
521   if (minimum_translations.empty ())
522     return;
523
524   assert (staves.size () == minimum_translations.size ());
525   Real first_translation = minimum_translations[0];
526   Real last_dy = 0;
527
528   for (vsize i = 0; i < staves.size (); ++i)
529     {
530       Real dy = minimum_translations[i] - first_translation;
531       Grob *g = staves[i];
532       Skyline_pair *sky = Skyline_pair::unsmob (g->get_property ("vertical-skylines"));
533       if (sky)
534         {
535           up->raise (-dy);
536           up->merge ((*sky)[UP]);
537           up->raise (dy);
538
539           down->raise (-dy);
540           down->merge ((*sky)[DOWN]);
541           down->raise (dy);
542
543           last_dy = dy;
544         }
545     }
546
547   // Leave the down skyline at a position
548   // relative to the bottom staff.
549   down->raise (-last_dy);
550 }
551
552 Interval
553 Page_layout_problem::prob_extent (Prob *p)
554 {
555   Stencil *sten = unsmob_stencil (p->get_property ("stencil"));
556   return sten ? sten->extent (Y_AXIS) : Interval (0, 0);
557 }
558
559 Interval
560 Page_layout_problem::first_staff_extent (Element const& e)
561 {
562   if (e.prob)
563     return prob_extent (e.prob);
564   else if (e.staves.size ())
565     return e.staves[0]->extent (e.staves[0], Y_AXIS);
566
567   return Interval (0, 0);
568 }
569
570 Interval
571 Page_layout_problem::last_staff_extent (Element const& e)
572 {
573   if (e.prob)
574     return prob_extent (e.prob);
575   else if (e.staves.size ())
576     return e.staves.back ()->extent (e.staves.back (), Y_AXIS);
577
578   return Interval (0, 0);
579 }
580
581 SCM
582 Page_layout_problem::get_details (Element const& elt)
583 {
584   if (elt.staves.empty ())
585     return SCM_EOL;
586
587   return get_details (elt.staves.back ()->get_system ());
588 }
589
590 SCM
591 Page_layout_problem::get_details (Grob *g)
592 {
593   Grob *left_bound = dynamic_cast<Spanner*> (g)->get_bound (LEFT);
594   return left_bound->get_property ("line-break-system-details");
595 }
596
597 bool
598 Page_layout_problem::is_spaceable (Grob *g)
599 {
600   return !scm_is_number (g->get_property ("staff-affinity"));
601 }
602
603 void
604 Page_layout_problem::mark_as_spaceable (Grob *g)
605 {
606   g->set_property ("staff-affinity", SCM_BOOL_F);
607 }
608
609 bool
610 Page_layout_problem::read_spacing_spec (SCM spec, Real* dest, SCM sym)
611 {
612   SCM pair = scm_sloppy_assq (sym, spec);
613   if (scm_is_pair (pair) && scm_is_number (scm_cdr (pair)))
614     {
615       *dest = scm_to_double (scm_cdr (pair));
616       return true;
617     }
618   return false;
619 }
620
621 // Returns the spacing spec connecting BEFORE to AFTER.  A return
622 // value of SCM_BOOL_F means that there should be no spring (in
623 // practice, this means that we use a very flexible spring).
624 SCM
625 Page_layout_problem::get_spacing_spec (Grob *before, Grob *after)
626 {
627   if (is_spaceable (before))
628     {
629       if (is_spaceable (after))
630         return before->get_property ("next-staff-spacing");
631       else
632         {
633           Direction affinity = to_dir (after->get_property ("staff-affinity"));
634           return (affinity == DOWN) ? SCM_BOOL_F : after->get_property ("inter-staff-spacing");
635         }
636     }
637   else
638     {
639       if (is_spaceable (after))
640         {
641           Direction affinity = to_dir (before->get_property ("staff-affinity"));
642           return (affinity == UP) ? SCM_BOOL_F : before->get_property ("inter-staff-spacing");
643         }
644       else
645         {
646           Direction before_affinity = to_dir (before->get_property ("staff-affinity"));
647           Direction after_affinity = to_dir (after->get_property ("staff-affinity"));
648           if (after_affinity > before_affinity)
649             {
650               warning (_ ("staff-affinities should only decrease"));
651               after_affinity = before_affinity;
652             }
653           if (before_affinity != UP)
654             return before->get_property ("inter-loose-line-spacing");
655           else if (after_affinity != DOWN)
656             return before->get_property ("inter-loose-line-spacing");
657         }
658     }
659   return SCM_BOOL_F;
660 }
661
662 void
663 Page_layout_problem::alter_spring_from_spacing_spec (SCM spec, Spring* spring)
664 {
665   Real space;
666   Real stretch;
667   Real min_dist;
668   if (read_spacing_spec (spec, &space, ly_symbol2scm ("space")))
669     spring->set_distance (space);
670   if (read_spacing_spec (spec, &min_dist, ly_symbol2scm ("minimum-distance")))
671     spring->set_min_distance (min_dist);
672   spring->set_default_strength ();
673
674   if (read_spacing_spec (spec, &stretch, ly_symbol2scm ("stretchability")))
675     {
676       spring->set_inverse_stretch_strength (stretch);
677       spring->set_inverse_compress_strength (stretch);
678     }
679 }