2 tie-formatting-problem.cc -- implement Tie_formatting_problem
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "tie-formatting-problem.hh"
12 #include "paper-column.hh"
14 #include "directional-element-interface.hh"
16 #include "libc-extension.hh"
18 #include "note-head.hh"
19 #include "rhythmic-head.hh"
21 #include "staff-symbol-referencer.hh"
23 #include "tie-configuration.hh"
29 Tie_formatting_problem::print_ties_configuration (Ties_configuration const *ties)
31 for (vsize i = 0; i < ties->size (); i++)
33 char const *man_pos = (specifications_[i].has_manual_position_) ? "(M)" : "";
34 char const *man_dir = (specifications_[i].has_manual_dir_) ? "(M)" : "";
35 char const *dir = (ties->at (i).dir_ == UP) ? "up" : "dn";
37 printf ("(P%d%s, %s%s) ", ties->at (i).position_, man_pos, dir, man_dir);
43 Tie_formatting_problem::get_attachment (Real y, Drul_array<int> columns) const
45 Interval attachments (0,0);
49 Tuple2<int> key (columns[d], int (d));
50 Chord_outline_map::const_iterator i (chord_outlines_.find (key));
51 if (i == chord_outlines_.end ())
52 programming_error ("Can't find chord outline");
54 attachments[d] = i->second.height (y);
56 while (flip (&d) != LEFT);
61 Tie_formatting_problem::Tie_formatting_problem()
66 Tie_formatting_problem::~Tie_formatting_problem ()
68 for (Tie_configuration_map::const_iterator i (possibilities_.begin ());
69 i != possibilities_.end (); i++)
74 Tie_formatting_problem::set_column_chord_outline (vector<Item*> bounds,
78 Real staff_space = Staff_symbol_referencer::staff_space (bounds[0]);
81 vector<Box> head_boxes;
84 for (vsize i = 0; i < bounds.size (); i++)
86 Grob *head = bounds[i];
87 if (!Note_head::has_interface (head))
91 stem = unsmob_grob (head->get_object ("stem"));
93 Real p = Staff_symbol_referencer::get_position (head);
94 Interval y ((p-1) * 0.5 * staff_space,
95 (p+1) * 0.5 * staff_space);
97 Interval x = head->extent (x_refpoint_, X_AXIS);
98 head_boxes.push_back (Box (x, y));
99 boxes.push_back (Box (x, y));
101 Grob *dots = Rhythmic_head::get_dots (head);
102 if (dir == LEFT && dots)
104 Interval x = dots->extent (x_refpoint_, X_AXIS);
105 int p = int (Staff_symbol_referencer::get_position (dots));
107 dot_positions_.insert (p);
110 Interval y (dots->extent (dots, Y_AXIS));
111 y.translate (p * staff_space * 0.5);
113 boxes.push_back (Box (x, y));
117 Tuple2<int> key (column_rank, int (dir));
120 && !Stem::is_invisible (stem))
123 x.add_point (stem->relative_coordinate (x_refpoint_, X_AXIS));
124 x.widen (staff_space / 20); // ugh.
126 y.add_point (Stem::stem_end_position (stem) * staff_space * .5);
128 Direction stemdir = get_grob_direction (stem);
129 y.add_point (Stem::head_positions (stem)[-stemdir]
132 boxes.push_back (Box (x, y));
134 stem_extents_[key].unite (Box (x,y));
138 Box flag_box = Stem::get_translated_flag (stem).extent_box ();
139 flag_box.translate( Offset (x[RIGHT], X_AXIS));
140 boxes.push_back (flag_box);
145 Grob *head = Stem::support_head (stem);
148 In case of invisible stem, don't pass x-center of heads.
150 Real x_center = head->extent (x_refpoint_, X_AXIS).center ();
152 x_ext[-dir] = x_center;
154 for (vsize j = 0; j < head_boxes.size (); j++)
155 y_ext.unite (head_boxes[j][Y_AXIS]);
157 boxes.push_back (Box (x_ext, y_ext));
160 Direction updowndir = DOWN;
165 if (head_boxes.size())
167 Box b = boundary (head_boxes, updowndir, 0);
169 x[-dir] = b[X_AXIS].linear_combination (-dir / 2);
170 y[-updowndir] = b[Y_AXIS][updowndir];
171 y[updowndir] = updowndir * infinity_f;
175 boxes.push_back (Box (x, y));
177 while (flip (&updowndir) != DOWN);
179 chord_outlines_[key] = Skyline (boxes, Y_AXIS, -dir);
180 if (bounds[0]->break_status_dir ())
182 Real x = robust_relative_extent (bounds[0], x_refpoint_, X_AXIS)[-dir];
183 chord_outlines_[key].set_minimum_height (x);
188 for (vsize j = 0; j < head_boxes.size (); j++)
190 x.unite (head_boxes[j][X_AXIS]);
193 chord_outlines_[key].set_minimum_height (x[dir]);
196 head_extents_[key].set_empty ();
197 for (vsize i = 0; i < head_boxes.size (); i++)
199 head_extents_[key].unite (head_boxes[i]);
204 Tie_formatting_problem::set_chord_outline (vector<Item*> bounds,
209 for (vsize i = 0; i < bounds.size (); i++)
210 ranks.push_back (bounds[i]->get_column ()->get_rank ());
212 vector_sort (ranks, less<int> ());
215 for (vsize i = 0; i < ranks.size (); i++)
217 vector<Item*> col_items;
218 for (vsize j = 0; j < bounds.size (); j ++)
220 if (bounds[j]->get_column ()->get_rank () == ranks[i])
221 col_items.push_back (bounds[j]);
224 set_column_chord_outline (col_items, dir, ranks[i]);
231 Tie_formatting_problem::from_tie (Grob *tie)
234 ties.push_back (tie);
237 details_.from_grob (tie);
241 Tie_formatting_problem::common_x_refpoint () const
247 Tie_formatting_problem::from_ties (vector<Grob*> const &ties)
252 x_refpoint_ = ties[0];
253 for (vsize i = 0; i < ties.size (); i++)
255 x_refpoint_ = dynamic_cast<Spanner*> (ties[i])->get_bound (LEFT)->common_refpoint (x_refpoint_, X_AXIS);
256 x_refpoint_ = dynamic_cast<Spanner*> (ties[i])->get_bound (RIGHT)->common_refpoint (x_refpoint_, X_AXIS);
259 details_.from_grob (ties[0]);
264 vector<Item*> bounds;
266 for (vsize i = 0; i < ties.size (); i++)
268 Item *it = dynamic_cast<Spanner*> (ties[i])->get_bound (d);
270 bounds.push_back (it);
273 set_chord_outline (bounds, d);
275 while (flip (&d) != LEFT);
278 for (vsize i = 0; i < ties.size (); i++)
280 Tie_specification spec;
282 spec.get_tie_manual_settings (ties[i]);
288 spec.note_head_drul_[d] = Tie::head (ties[i], d);
289 spec.column_ranks_[d] =
290 dynamic_cast<Spanner*> (ties[i])->get_bound (d)->get_column ()->get_rank ();
292 while (flip (&d) != LEFT);
293 specifications_.push_back (spec);
298 Tie_formatting_problem::from_semi_ties (vector<Grob*> const &semi_ties, Direction head_dir)
300 if (semi_ties.empty ())
303 details_.from_grob (semi_ties[0]);
306 int column_rank = -1;
307 for (vsize i = 0; i < semi_ties.size (); i++)
309 Tie_specification spec;
310 Item *head = unsmob_item (semi_ties[i]->get_object ("note-head"));
313 programming_error ("LV tie without head?!");
317 spec.position_ = int (Staff_symbol_referencer::get_position (head));
320 spec.get_tie_manual_settings (semi_ties[i]);
322 spec.note_head_drul_[head_dir] = head;
323 column_rank = dynamic_cast<Item*> (head)->get_column ()->get_rank ();
324 spec.column_ranks_ = Drul_array<int> (column_rank, column_rank);
325 heads.push_back (head);
326 specifications_.push_back (spec);
329 x_refpoint_ = semi_ties [0];
330 for (vsize i = 0; i < semi_ties.size (); i++)
331 x_refpoint_ = semi_ties[i]->common_refpoint (x_refpoint_, X_AXIS);
332 for (vsize i = 0; i < heads.size (); i++)
333 x_refpoint_ = heads[i]->common_refpoint (x_refpoint_, X_AXIS);
335 set_chord_outline (heads, head_dir);
337 Tuple2<int> head_key (column_rank, head_dir);
338 Tuple2<int> open_key (column_rank, -head_dir);
339 Real extremal = chord_outlines_[head_key].max_height ();
341 chord_outlines_[open_key] = Skyline (head_dir);
342 chord_outlines_[open_key].set_minimum_height (extremal - head_dir * 1.5);
347 Tie_formatting_problem::get_tie_specification (int i) const
349 return specifications_[i];
354 Return configuration, create it if necessary.
357 Tie_formatting_problem::get_configuration (int pos, Direction dir, Drul_array<int> columns) const
359 int key_components[] = {
360 pos, dir, columns[LEFT], columns[RIGHT]
362 Tuple<int,4> key (key_components);
364 Tie_configuration_map::const_iterator f = possibilities_.find (key);
365 if (f != possibilities_.end ())
371 Tie_configuration *conf = generate_configuration (pos, dir, columns);
372 ((Tie_formatting_problem*) this)->possibilities_[key] = conf;
377 Tie_formatting_problem::generate_configuration (int pos, Direction dir,
378 Drul_array<int> columns) const
380 Tie_configuration *conf = new Tie_configuration;
381 conf->position_ = pos;
384 conf->column_ranks_ = columns;
386 Real y = conf->position_ * 0.5 * details_.staff_space_;
389 if (dot_positions_.find (pos) != dot_positions_.end ())
391 conf->delta_y_ += dir * 0.25 * details_.staff_space_;
396 && max (fabs (get_head_extent (columns[LEFT], LEFT, Y_AXIS)[dir] - y),
397 fabs (get_head_extent (columns[RIGHT], RIGHT, Y_AXIS)[dir] - y)) < 0.25
398 && !Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, pos))
401 (get_head_extent (columns[LEFT], LEFT, Y_AXIS)[dir] - y)
402 + dir * details_.outer_tie_vertical_gap_;
407 conf->attachment_x_ = get_attachment (y + conf->delta_y_, conf->column_ranks_);
408 Real h = conf->height (details_);
413 - should make sliding criterion, should flatten ties if
415 - they're just the wrong (ie. touching line at top & bottom)
419 if (h < details_.intra_space_threshold_ * 0.5 * details_.staff_space_)
421 if (!Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, pos)
422 && abs (pos) < 2 * Staff_symbol_referencer::staff_radius (details_.staff_symbol_referencer_))
424 conf->center_tie_vertically (details_);
426 else if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, pos))
428 conf->delta_y_ += dir *
429 details_.tip_staff_line_clearance_ * 0.5 * details_.staff_space_;
434 Real top_y = y + conf->delta_y_ + conf->dir_ * h;
435 Real top_pos = top_y / (0.5*details_.staff_space_);
436 int round_pos = int (my_round (top_pos));
438 /* TODO: should use other variable? */
439 Real clearance = details_.center_staff_line_clearance_;
440 if (fabs (top_pos - round_pos) < clearance
441 && Staff_symbol_referencer::on_staff_line (details_.staff_symbol_referencer_,
444 Real new_y = (round_pos + clearance * conf->dir_) * 0.5 * details_.staff_space_;
445 conf->delta_y_ = (new_y - top_y);
450 conf->attachment_x_ = get_attachment (y + conf->delta_y_, conf->column_ranks_);
451 if (conf->height (details_) < details_.intra_space_threshold_ * 0.5 * details_.staff_space_)
454 This is less sensible for long ties, since those are more
457 Interval close_by = get_attachment (y
459 + (dir * details_.intra_space_threshold_ * 0.25
460 * details_.staff_space_),
461 conf->column_ranks_);
463 conf->attachment_x_.intersect (close_by);
466 conf->attachment_x_.widen ( - details_.x_gap_);
468 if (conf->column_span_length ())
471 avoid the stems that we attach to as well. We don't do this
472 for semities (span length = 0)
474 It would be better to check D against HEAD-DIRECTION if
480 Real y = conf->position_ * details_.staff_space_ * 0.5 + conf->delta_y_;
481 if (get_stem_extent (conf->column_ranks_[d], d, X_AXIS).is_empty ()
482 || !get_stem_extent (conf->column_ranks_[d], d, Y_AXIS).contains (y))
485 conf->attachment_x_[d] =
486 d * min (d * conf->attachment_x_[d],
487 d * (get_stem_extent (conf->column_ranks_[d], d, X_AXIS)[-d] - d * details_.stem_gap_));
489 while (flip (&d) != LEFT);
495 Tie_formatting_problem::get_head_extent (int col, Direction d, Axis a) const
497 return (*head_extents_.find (Tuple2<int> (col, int (d)))).second[a];
501 Tie_formatting_problem::get_stem_extent (int col, Direction d, Axis a) const
503 return (*stem_extents_.find (Tuple2<int> (col, int (d)))).second[a];
507 TIE_IDX and TIES_CONF are optional.
510 Tie_formatting_problem::score_aptitude (Tie_configuration *conf,
511 Tie_specification const &spec,
512 Ties_configuration *ties_conf, int tie_idx) const
515 Real curve_y = conf->position_ * details_.staff_space_ * 0.5 + conf->delta_y_;
516 Real tie_y = spec.position_ * details_.staff_space_ * 0.5;
517 if (sign (curve_y - tie_y) != conf->dir_)
519 Real p = details_.wrong_direction_offset_penalty_;
521 ties_conf->add_tie_score (p, tie_idx, "wrong dir");
527 Real p = details_.vertical_distance_penalty_factor_ * fabs (curve_y - tie_y);
529 ties_conf->add_tie_score (p, tie_idx, "vdist");
537 if (!spec.note_head_drul_[d])
540 Interval head_x = spec.note_head_drul_[d]->extent (x_refpoint_, X_AXIS);
541 Real dist = head_x.distance (conf->attachment_x_[d]);
544 TODO: flatten with log or sqrt.
546 Real p = details_.horizontal_distance_penalty_factor_ * dist;
548 ties_conf->add_tie_score (p, tie_idx,
549 (d == LEFT) ? "lhdist" : "rhdist");
553 while (flip (&d) != LEFT);
559 Tie_formatting_problem::score_configuration (Tie_configuration *conf) const
566 Real length = conf->attachment_x_.length ();
568 conf->add_score (details_.min_length_penalty_factor_
569 * peak_around (0.33 * details_.min_length_, details_.min_length_, length),
572 Real tip_pos = conf->position_ + conf->delta_y_ / 0.5 * details_.staff_space_;
573 Real tip_y = tip_pos * details_.staff_space_ * 0.5;
574 Real height = conf->height (details_);
576 Real top_y = tip_y + conf->dir_ * height;
577 Real top_pos = 2 * top_y / details_.staff_space_;
578 Real round_top_pos = rint (top_pos);
579 if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_,
581 && Staff_symbol_referencer::staff_radius (details_.staff_symbol_referencer_) > top_y)
584 details_.staff_line_collision_penalty_
585 * peak_around (0.1 * details_.center_staff_line_clearance_,
586 details_.center_staff_line_clearance_,
587 fabs (top_pos - round_top_pos)),
591 if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_,
592 int (rint (tip_pos))))
594 conf->add_score (details_.staff_line_collision_penalty_
595 * peak_around (0.1 * details_.tip_staff_line_clearance_,
596 details_.tip_staff_line_clearance_,
597 fabs (tip_pos - rint (tip_pos))),
601 if (!dot_x_.is_empty ())
604 Real x = dot_x_.center ();
606 Bezier b = conf->get_transformed_bezier (details_);
607 if (b.control_point_extent (X_AXIS).contains (x))
609 Real y = b.get_other_coordinate (X_AXIS, x);
611 for (set<int>::const_iterator i (dot_positions_.begin ());
612 i != dot_positions_.end (); i ++)
615 conf->add_score (details_.dot_collision_penalty_
616 * peak_around (.1 * details_.dot_collision_clearance_,
617 details_.dot_collision_clearance_,
618 fabs (dot_pos * details_.staff_space_ * 0.5 - y)),
624 conf->scored_ = true;
628 Tie_formatting_problem::find_optimal_tie_configuration (Tie_specification const &spec) const
630 vector<Tie_configuration*> confs;
632 int pos = spec.position_;
633 Direction dir = spec.manual_dir_;
635 for (int i = 0; i < details_.single_tie_region_size_; i ++)
637 confs.push_back (generate_configuration (pos + i * dir, dir,
638 spec.column_ranks_));
640 if (spec.has_manual_position_)
642 confs.back ()->delta_y_
643 = (spec.manual_position_ - spec.position_)
644 * 0.5 * details_.staff_space_;
653 Real best_score = 1e6;
654 for (vsize i = 0; i < confs.size (); i ++)
656 score_configuration (confs[i]);
657 Real score = score_aptitude (confs[i], spec, 0, 0)
658 + confs[i]->score ();
660 if (score < best_score)
668 programming_error ("No best tie configuration found.");
670 Tie_configuration best
671 = (best_idx >= 0) ? *confs[best_idx] : *confs[0];
673 for (vsize i = 0; i < confs.size (); i++)
679 Tie_specification::Tie_specification ()
681 has_manual_position_ = false;
682 has_manual_dir_ = false;
684 manual_position_ = 0;
685 manual_dir_ = CENTER;
686 note_head_drul_[LEFT] =
687 note_head_drul_[RIGHT] = 0;
688 column_ranks_[RIGHT] =
689 column_ranks_[LEFT] = 0;
694 Tie_specification::get_tie_manual_settings (Grob *tie)
696 if (scm_is_number (tie->get_property_data ("direction")))
698 manual_dir_ = to_dir (tie->get_property ("direction"));
699 has_manual_dir_ = true;
702 position_ = Tie::get_position (tie);
703 if (scm_is_number (tie->get_property ("staff-position")))
705 manual_position_ = scm_to_double (tie->get_property ("staff-position"));
706 has_manual_position_ = true;
707 position_ = int (my_round (manual_position_));
712 Tie_specification::column_span () const
714 return column_ranks_[RIGHT] - column_ranks_[LEFT];
718 Tie_formatting_problem::score_ties_aptitude (Ties_configuration *ties) const
720 if (ties->size () != specifications_.size ())
722 programming_error ("Huh? Mismatch between sizes.");
726 for (vsize i = 0; i < ties->size (); i++)
727 score_aptitude (&ties->at (i), specifications_[i],
732 Tie_formatting_problem::score_ties (Ties_configuration *ties) const
737 score_ties_configuration (ties);
738 score_ties_aptitude (ties);
739 ties->scored_ = true;
743 Tie_formatting_problem::score_ties_configuration (Ties_configuration *ties) const
745 for (vsize i = 0; i < ties->size (); i++)
747 score_configuration (&ties->at (i));
748 ties->add_tie_score (ties->at (i).score (), i, "conf");
751 Real last_edge = 0.0;
752 Real last_center = 0.0;
753 for (vsize i = 0; i < ties->size (); i++)
755 Bezier b (ties->at (i).get_transformed_bezier (details_));
757 Real center = b.curve_point (0.5)[Y_AXIS];
758 Real edge = b.curve_point (0.0)[Y_AXIS];
762 if (edge <= last_edge)
763 ties->add_score (details_.tie_column_monotonicity_penalty_, "monoton edge");
764 if (center <= last_center)
765 ties->add_score (details_.tie_column_monotonicity_penalty_, "monoton cent");
767 ties->add_score (details_.tie_tie_collision_penalty_ *
768 peak_around (0.1 * details_.tie_tie_collision_distance_,
769 details_.tie_tie_collision_distance_,
770 fabs (center - last_center)),
772 ties->add_score (details_.tie_tie_collision_penalty_ *
773 peak_around (0.1 * details_.tie_tie_collision_distance_,
774 details_.tie_tie_collision_distance_,
775 fabs (edge - last_edge)), "tietie edge");
779 last_center = center;
782 ties->add_score (details_.outer_tie_length_symmetry_penalty_factor_
783 * fabs (ties->at (0).attachment_x_.length () - ties->back ().attachment_x_.length ()),
786 ties->add_score (details_.outer_tie_vertical_distance_symmetry_penalty_factor_
787 * fabs (fabs (specifications_[0].position_ * 0.5 * details_.staff_space_
788 - (ties->at (0).position_ * 0.5 * details_.staff_space_
789 + ties->at (0).delta_y_))
791 fabs (specifications_.back ().position_ * 0.5 * details_.staff_space_
792 - (ties->back ().position_ * 0.5 * details_.staff_space_
793 + ties->back ().delta_y_))),
798 Generate with correct X-attachments and beziers, copying delta_y_
799 from TIES_CONFIG if necessary.
802 Tie_formatting_problem::generate_ties_configuration (Ties_configuration const &ties_config)
804 Ties_configuration copy;
805 for (vsize i = 0; i < ties_config.size (); i++)
807 Tie_configuration * ptr = get_configuration (ties_config[i].position_, ties_config[i].dir_,
808 ties_config[i].column_ranks_);
809 if (specifications_[i].has_manual_position_)
812 = (specifications_[i].manual_position_ - ties_config[i].position_)
813 * 0.5 * details_.staff_space_;
815 copy.push_back (*ptr);
822 Tie_formatting_problem::generate_base_chord_configuration ()
824 Ties_configuration ties_config;
825 for (vsize i = 0; i < specifications_.size (); i ++)
827 Tie_configuration conf;
828 if (specifications_[i].has_manual_dir_)
829 conf.dir_ = specifications_[i].manual_dir_;
830 if (specifications_[i].has_manual_position_)
832 conf.position_ = (int) my_round (specifications_[i].manual_position_);
833 conf.delta_y_ = (specifications_[i].manual_position_ - conf.position_)
834 * 0.5 * details_.staff_space_;
838 conf.position_ = specifications_[i].position_;
841 conf.column_ranks_ = specifications_[i].column_ranks_;
842 ties_config.push_back (conf);
845 set_ties_config_standard_directions (&ties_config);
846 for (vsize i = 0; i < ties_config.size (); i++)
847 if (!specifications_[i].manual_position_)
848 ties_config[i].position_ += ties_config[i].dir_;
850 ties_config = generate_ties_configuration (ties_config);
856 Tie_formatting_problem::find_best_variation (Ties_configuration const &base,
857 vector<Tie_configuration_variation> vars)
859 Ties_configuration best = base;
862 This simply is 1-opt: we have K substitions, and we try applying
863 exactly every one for each.
865 for (vsize i = 0; i < vars.size (); i++)
867 Ties_configuration variant (base);
868 variant[vars[i].index_] = *vars[i].suggestion_;
870 variant.reset_score ();
871 score_ties (&variant);
873 if (variant.score () < best.score ())
885 Tie_formatting_problem::generate_optimal_chord_configuration ()
887 Ties_configuration base = generate_base_chord_configuration ();
888 vector<Tie_configuration_variation> vars = generate_collision_variations (base);
891 Ties_configuration best = find_best_variation (base, vars);
892 vars = generate_extremal_tie_variations (best);
893 best = find_best_variation (best, vars);
899 Tie_formatting_problem::set_ties_config_standard_directions (Ties_configuration *tie_configs)
901 if (tie_configs->empty ())
904 if (!tie_configs->at (0).dir_)
906 if (tie_configs->size () == 1)
907 tie_configs->at (0).dir_ = Direction (sign (tie_configs->at (0).position_));
909 if (!tie_configs->at (0).dir_)
910 tie_configs->at (0).dir_ = DOWN;
913 if (!tie_configs->back ().dir_)
914 tie_configs->back ().dir_ = UP;
919 for (vsize i = 1; i < tie_configs->size (); i++)
921 Real diff = (tie_configs->at (i).position_
922 -tie_configs->at (i-1).position_);
925 = specifications_[i].column_span () - specifications_[i-1].column_span ();
926 if (span_diff && fabs (diff) <= 2)
929 tie_configs->at (i).dir_ = UP;
930 else if (span_diff < 0)
931 tie_configs->at (i-1).dir_ = DOWN;
933 else if (fabs (diff) <= 1)
935 if (!tie_configs->at (i-1).dir_)
936 tie_configs->at (i-1).dir_ = DOWN;
937 if (!tie_configs->at (i).dir_)
938 tie_configs->at (i).dir_ = UP;
942 for (vsize i = 1; i < tie_configs->size() - 1; i++)
944 Tie_configuration &conf = tie_configs->at (i);
948 Direction position_dir =
949 Direction (sign (conf.position_));
953 conf.dir_ = position_dir;
957 Tie_configuration_variation::Tie_configuration_variation ()
963 vector<Tie_configuration_variation>
964 Tie_formatting_problem::generate_extremal_tie_variations (Ties_configuration const &ties) const
966 vector<Tie_configuration_variation> vars;
970 if (boundary (ties, d, 0).dir_ == d
971 && !boundary (specifications_, d, 0).has_manual_position_)
972 for (int i = 1; i <= details_.multi_tie_region_size_; i++)
974 Tie_configuration_variation var;
975 var.index_ = (d == DOWN) ? 0 : ties.size () - 1;
976 var.suggestion_ = get_configuration (boundary (ties, d, 0).position_
978 boundary (ties, d, 0).column_ranks_);
979 vars.push_back (var);
982 while (flip (&d) != DOWN);
988 vector<Tie_configuration_variation>
989 Tie_formatting_problem::generate_collision_variations (Ties_configuration const &ties) const
991 Real center_distance_tolerance = 0.25;
993 vector<Tie_configuration_variation> vars;
994 Real last_center = 0.0;
995 for (vsize i = 0; i < ties.size (); i++)
997 Bezier b (ties[i].get_transformed_bezier (details_));
999 Real center = b.curve_point (0.5)[Y_AXIS];
1003 if (center <= last_center + center_distance_tolerance)
1005 if (!specifications_[i].has_manual_dir_)
1007 Tie_configuration_variation var;
1009 var.suggestion_ = get_configuration (specifications_[i].position_
1013 ties[i].column_ranks_
1016 vars.push_back (var);
1019 if (!specifications_[i-1].has_manual_dir_)
1021 Tie_configuration_variation var;
1023 var.suggestion_ = get_configuration (specifications_[i-1].position_
1026 specifications_[i-1].column_ranks_);
1028 vars.push_back (var);
1031 if (i == 1 && !specifications_[i-1].has_manual_position_
1032 && ties[i-1].dir_ == DOWN)
1034 Tie_configuration_variation var;
1036 var.suggestion_ = get_configuration (specifications_[i-1].position_ - 1, DOWN,
1037 specifications_[i-1].column_ranks_);
1038 vars.push_back (var);
1040 if (i == ties.size() && !specifications_[i].has_manual_position_
1041 && ties[i].dir_ == UP)
1043 Tie_configuration_variation var;
1045 var.suggestion_ = get_configuration (specifications_[i].position_
1047 specifications_[i].column_ranks_);
1048 vars.push_back (var);
1051 else if (dot_positions_.find (ties[i].position_) != dot_positions_.end ()
1052 && !specifications_[i].has_manual_position_)
1054 Tie_configuration_variation var;
1056 var.suggestion_ = get_configuration (ties[i].position_ + ties[i].dir_,
1058 ties[i].column_ranks_);
1059 vars.push_back (var);
1064 last_center = center;
1072 Tie_formatting_problem::set_manual_tie_configuration (SCM manual_configs)
1075 for (SCM s = manual_configs;
1076 scm_is_pair (s) && k < specifications_.size (); s = scm_cdr (s))
1078 SCM entry = scm_car (s);
1079 if (scm_is_pair (entry))
1081 Tie_specification &spec = specifications_[k];
1083 if (scm_is_number (scm_car (entry)))
1085 spec.has_manual_position_ = true;
1086 spec.manual_position_ = scm_to_double (scm_car (entry));
1088 if (scm_is_number (scm_cdr (entry)))
1090 spec.has_manual_dir_ = true;
1091 spec.manual_dir_ = Direction (scm_to_int (scm_cdr (entry)));