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"
15 #include "libc-extension.hh"
17 #include "note-head.hh"
18 #include "rhythmic-head.hh"
20 #include "staff-symbol-referencer.hh"
22 #include "tie-configuration.hh"
28 Tie_formatting_problem::print_ties_configuration (Ties_configuration const *ties)
30 for (vsize i = 0; i < ties->size (); i++)
32 char const *man_pos = (specifications_[i].has_manual_position_) ? "(M)" : "";
33 char const *man_dir = (specifications_[i].has_manual_dir_) ? "(M)" : "";
34 char const *dir = (ties->at (i).dir_ == UP) ? "up" : "dn";
36 printf ("(P%d%s, %s%s) ", ties->at (i).position_, man_pos, dir, man_dir);
42 Tie_formatting_problem::get_attachment (Real y, Drul_array<int> columns) const
44 Interval attachments (0,0);
48 Tuple2<int> key (columns[d], int (d));
49 Chord_outline_map::const_iterator i (chord_outlines_.find (key));
50 if (i == chord_outlines_.end ())
51 programming_error ("Cannot find chord outline");
53 attachments[d] = i->second.height (y);
55 while (flip (&d) != LEFT);
60 Tie_formatting_problem::Tie_formatting_problem()
65 Tie_formatting_problem::~Tie_formatting_problem ()
67 for (Tie_configuration_map::const_iterator i (possibilities_.begin ());
68 i != possibilities_.end (); i++)
73 Tie_formatting_problem::set_column_chord_outline (vector<Item*> bounds,
77 Real staff_space = Staff_symbol_referencer::staff_space (bounds[0]);
80 vector<Box> head_boxes;
83 for (vsize i = 0; i < bounds.size (); i++)
85 Grob *head = bounds[i];
86 if (!Note_head::has_interface (head))
90 stem = unsmob_grob (head->get_object ("stem"));
92 Real p = Staff_symbol_referencer::get_position (head);
93 Interval y ((p-1) * 0.5 * staff_space,
94 (p+1) * 0.5 * staff_space);
96 Interval x = head->extent (x_refpoint_, X_AXIS);
97 head_boxes.push_back (Box (x, y));
98 boxes.push_back (Box (x, y));
100 Grob *dots = Rhythmic_head::get_dots (head);
101 if (dir == LEFT && dots)
103 Interval x = dots->extent (x_refpoint_, X_AXIS);
104 int p = int (Staff_symbol_referencer::get_position (dots));
106 dot_positions_.insert (p);
109 Interval y (dots->extent (dots, Y_AXIS));
110 y.translate (p * staff_space * 0.5);
112 boxes.push_back (Box (x, y));
116 Tuple2<int> key (column_rank, int (dir));
119 && !Stem::is_invisible (stem))
122 x.add_point (stem->relative_coordinate (x_refpoint_, X_AXIS));
123 x.widen (staff_space / 20); // ugh.
125 y.add_point (Stem::stem_end_position (stem) * staff_space * .5);
127 Direction stemdir = get_grob_direction (stem);
128 y.add_point (Stem::head_positions (stem)[-stemdir]
131 boxes.push_back (Box (x, y));
133 stem_extents_[key].unite (Box (x,y));
137 Box flag_box = Stem::get_translated_flag (stem).extent_box ();
138 flag_box.translate( Offset (x[RIGHT], X_AXIS));
139 boxes.push_back (flag_box);
144 Grob *head = Stem::support_head (stem);
147 In case of invisible stem, don't pass x-center of heads.
149 Real x_center = head->extent (x_refpoint_, X_AXIS).center ();
151 x_ext[-dir] = x_center;
153 for (vsize j = 0; j < head_boxes.size (); j++)
154 y_ext.unite (head_boxes[j][Y_AXIS]);
156 boxes.push_back (Box (x_ext, y_ext));
159 Direction updowndir = DOWN;
164 if (head_boxes.size())
166 Box b = boundary (head_boxes, updowndir, 0);
168 x[-dir] = b[X_AXIS].linear_combination (-dir / 2);
169 y[-updowndir] = b[Y_AXIS][updowndir];
170 y[updowndir] = updowndir * infinity_f;
174 boxes.push_back (Box (x, y));
176 while (flip (&updowndir) != DOWN);
178 /* todo: the horizon_padding is somewhat arbitrary */
179 chord_outlines_[key] = Skyline (boxes, 0.1, 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 Column_extent_map::const_iterator i = head_extents_.find (Tuple2<int> (col, int (d)));
498 if (i != head_extents_.end ())
499 return (*i).second[a];
505 Tie_formatting_problem::get_stem_extent (int col, Direction d, Axis a) const
507 Column_extent_map::const_iterator i = stem_extents_.find (Tuple2<int> (col, int (d)));
508 if (i != stem_extents_.end ())
509 return (*i).second[a];
515 TIE_IDX and TIES_CONF are optional.
518 Tie_formatting_problem::score_aptitude (Tie_configuration *conf,
519 Tie_specification const &spec,
520 Ties_configuration *ties_conf, int tie_idx) const
523 Real curve_y = conf->position_ * details_.staff_space_ * 0.5 + conf->delta_y_;
524 Real tie_y = spec.position_ * details_.staff_space_ * 0.5;
525 if (sign (curve_y - tie_y) != conf->dir_)
527 Real p = details_.wrong_direction_offset_penalty_;
529 ties_conf->add_tie_score (p, tie_idx, "wrong dir");
535 Real p = details_.vertical_distance_penalty_factor_ * fabs (curve_y - tie_y);
537 ties_conf->add_tie_score (p, tie_idx, "vdist");
545 if (!spec.note_head_drul_[d])
548 Interval head_x = spec.note_head_drul_[d]->extent (x_refpoint_, X_AXIS);
549 Real dist = head_x.distance (conf->attachment_x_[d]);
552 TODO: flatten with log or sqrt.
554 Real p = details_.horizontal_distance_penalty_factor_ * dist;
556 ties_conf->add_tie_score (p, tie_idx,
557 (d == LEFT) ? "lhdist" : "rhdist");
561 while (flip (&d) != LEFT);
567 Tie_formatting_problem::score_configuration (Tie_configuration *conf) const
574 Real length = conf->attachment_x_.length ();
576 conf->add_score (details_.min_length_penalty_factor_
577 * peak_around (0.33 * details_.min_length_, details_.min_length_, length),
580 Real tip_pos = conf->position_ + conf->delta_y_ / 0.5 * details_.staff_space_;
581 Real tip_y = tip_pos * details_.staff_space_ * 0.5;
582 Real height = conf->height (details_);
584 Real top_y = tip_y + conf->dir_ * height;
585 Real top_pos = 2 * top_y / details_.staff_space_;
586 Real round_top_pos = rint (top_pos);
587 if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_,
589 && Staff_symbol_referencer::staff_radius (details_.staff_symbol_referencer_) > top_y)
592 details_.staff_line_collision_penalty_
593 * peak_around (0.1 * details_.center_staff_line_clearance_,
594 details_.center_staff_line_clearance_,
595 fabs (top_pos - round_top_pos)),
599 if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_,
600 int (rint (tip_pos))))
602 conf->add_score (details_.staff_line_collision_penalty_
603 * peak_around (0.1 * details_.tip_staff_line_clearance_,
604 details_.tip_staff_line_clearance_,
605 fabs (tip_pos - rint (tip_pos))),
609 if (!dot_x_.is_empty ())
612 Real x = dot_x_.center ();
614 Bezier b = conf->get_transformed_bezier (details_);
615 if (b.control_point_extent (X_AXIS).contains (x))
617 Real y = b.get_other_coordinate (X_AXIS, x);
619 for (set<int>::const_iterator i (dot_positions_.begin ());
620 i != dot_positions_.end (); i ++)
623 conf->add_score (details_.dot_collision_penalty_
624 * peak_around (.1 * details_.dot_collision_clearance_,
625 details_.dot_collision_clearance_,
626 fabs (dot_pos * details_.staff_space_ * 0.5 - y)),
632 conf->scored_ = true;
636 Tie_formatting_problem::find_optimal_tie_configuration (Tie_specification const &spec) const
638 vector<Tie_configuration*> confs;
640 int pos = spec.position_;
641 Direction dir = spec.manual_dir_;
643 for (int i = 0; i < details_.single_tie_region_size_; i ++)
645 confs.push_back (generate_configuration (pos + i * dir, dir,
646 spec.column_ranks_));
648 if (spec.has_manual_position_)
650 confs.back ()->delta_y_
651 = (spec.manual_position_ - spec.position_)
652 * 0.5 * details_.staff_space_;
661 Real best_score = 1e6;
662 for (vsize i = 0; i < confs.size (); i ++)
664 score_configuration (confs[i]);
665 Real score = score_aptitude (confs[i], spec, 0, 0)
666 + confs[i]->score ();
668 if (score < best_score)
676 programming_error ("No best tie configuration found.");
678 Tie_configuration best
679 = (best_idx >= 0) ? *confs[best_idx] : *confs[0];
681 for (vsize i = 0; i < confs.size (); i++)
687 Tie_specification::Tie_specification ()
689 has_manual_position_ = false;
690 has_manual_dir_ = false;
692 manual_position_ = 0;
693 manual_dir_ = CENTER;
694 note_head_drul_[LEFT] =
695 note_head_drul_[RIGHT] = 0;
696 column_ranks_[RIGHT] =
697 column_ranks_[LEFT] = 0;
702 Tie_specification::get_tie_manual_settings (Grob *tie)
704 if (scm_is_number (tie->get_property_data ("direction")))
706 manual_dir_ = to_dir (tie->get_property ("direction"));
707 has_manual_dir_ = true;
710 position_ = Tie::get_position (tie);
711 if (scm_is_number (tie->get_property ("staff-position")))
713 manual_position_ = scm_to_double (tie->get_property ("staff-position"));
714 has_manual_position_ = true;
715 position_ = int (my_round (manual_position_));
720 Tie_specification::column_span () const
722 return column_ranks_[RIGHT] - column_ranks_[LEFT];
726 Tie_formatting_problem::score_ties_aptitude (Ties_configuration *ties) const
728 if (ties->size () != specifications_.size ())
730 programming_error ("Huh? Mismatch between sizes.");
734 for (vsize i = 0; i < ties->size (); i++)
735 score_aptitude (&ties->at (i), specifications_[i],
740 Tie_formatting_problem::score_ties (Ties_configuration *ties) const
745 score_ties_configuration (ties);
746 score_ties_aptitude (ties);
747 ties->scored_ = true;
751 Tie_formatting_problem::score_ties_configuration (Ties_configuration *ties) const
753 for (vsize i = 0; i < ties->size (); i++)
755 score_configuration (&ties->at (i));
756 ties->add_tie_score (ties->at (i).score (), i, "conf");
759 Real last_edge = 0.0;
760 Real last_center = 0.0;
761 for (vsize i = 0; i < ties->size (); i++)
763 Bezier b (ties->at (i).get_transformed_bezier (details_));
765 Real center = b.curve_point (0.5)[Y_AXIS];
766 Real edge = b.curve_point (0.0)[Y_AXIS];
770 if (edge <= last_edge)
771 ties->add_score (details_.tie_column_monotonicity_penalty_, "monoton edge");
772 if (center <= last_center)
773 ties->add_score (details_.tie_column_monotonicity_penalty_, "monoton cent");
775 ties->add_score (details_.tie_tie_collision_penalty_ *
776 peak_around (0.1 * details_.tie_tie_collision_distance_,
777 details_.tie_tie_collision_distance_,
778 fabs (center - last_center)),
780 ties->add_score (details_.tie_tie_collision_penalty_ *
781 peak_around (0.1 * details_.tie_tie_collision_distance_,
782 details_.tie_tie_collision_distance_,
783 fabs (edge - last_edge)), "tietie edge");
787 last_center = center;
790 ties->add_score (details_.outer_tie_length_symmetry_penalty_factor_
791 * fabs (ties->at (0).attachment_x_.length () - ties->back ().attachment_x_.length ()),
794 ties->add_score (details_.outer_tie_vertical_distance_symmetry_penalty_factor_
795 * fabs (fabs (specifications_[0].position_ * 0.5 * details_.staff_space_
796 - (ties->at (0).position_ * 0.5 * details_.staff_space_
797 + ties->at (0).delta_y_))
799 fabs (specifications_.back ().position_ * 0.5 * details_.staff_space_
800 - (ties->back ().position_ * 0.5 * details_.staff_space_
801 + ties->back ().delta_y_))),
806 Generate with correct X-attachments and beziers, copying delta_y_
807 from TIES_CONFIG if necessary.
810 Tie_formatting_problem::generate_ties_configuration (Ties_configuration const &ties_config)
812 Ties_configuration copy;
813 for (vsize i = 0; i < ties_config.size (); i++)
815 Tie_configuration * ptr = get_configuration (ties_config[i].position_, ties_config[i].dir_,
816 ties_config[i].column_ranks_);
817 if (specifications_[i].has_manual_position_)
820 = (specifications_[i].manual_position_ - ties_config[i].position_)
821 * 0.5 * details_.staff_space_;
823 copy.push_back (*ptr);
830 Tie_formatting_problem::generate_base_chord_configuration ()
832 Ties_configuration ties_config;
833 for (vsize i = 0; i < specifications_.size (); i ++)
835 Tie_configuration conf;
836 if (specifications_[i].has_manual_dir_)
837 conf.dir_ = specifications_[i].manual_dir_;
838 if (specifications_[i].has_manual_position_)
840 conf.position_ = (int) my_round (specifications_[i].manual_position_);
841 conf.delta_y_ = (specifications_[i].manual_position_ - conf.position_)
842 * 0.5 * details_.staff_space_;
846 conf.position_ = specifications_[i].position_;
849 conf.column_ranks_ = specifications_[i].column_ranks_;
850 ties_config.push_back (conf);
853 set_ties_config_standard_directions (&ties_config);
854 for (vsize i = 0; i < ties_config.size (); i++)
855 if (!specifications_[i].manual_position_)
856 ties_config[i].position_ += ties_config[i].dir_;
858 ties_config = generate_ties_configuration (ties_config);
864 Tie_formatting_problem::find_best_variation (Ties_configuration const &base,
865 vector<Tie_configuration_variation> vars)
867 Ties_configuration best = base;
870 This simply is 1-opt: we have K substitions, and we try applying
871 exactly every one for each.
873 for (vsize i = 0; i < vars.size (); i++)
875 Ties_configuration variant (base);
876 variant[vars[i].index_] = *vars[i].suggestion_;
878 variant.reset_score ();
879 score_ties (&variant);
881 if (variant.score () < best.score ())
893 Tie_formatting_problem::generate_optimal_chord_configuration ()
895 Ties_configuration base = generate_base_chord_configuration ();
896 vector<Tie_configuration_variation> vars = generate_collision_variations (base);
899 Ties_configuration best = find_best_variation (base, vars);
900 vars = generate_extremal_tie_variations (best);
901 best = find_best_variation (best, vars);
907 Tie_formatting_problem::set_ties_config_standard_directions (Ties_configuration *tie_configs)
909 if (tie_configs->empty ())
912 if (!tie_configs->at (0).dir_)
914 if (tie_configs->size () == 1)
915 tie_configs->at (0).dir_ = Direction (sign (tie_configs->at (0).position_));
917 if (!tie_configs->at (0).dir_)
918 tie_configs->at (0).dir_ = DOWN;
921 if (!tie_configs->back ().dir_)
922 tie_configs->back ().dir_ = UP;
927 for (vsize i = 1; i < tie_configs->size (); i++)
929 Real diff = (tie_configs->at (i).position_
930 -tie_configs->at (i-1).position_);
933 = specifications_[i].column_span () - specifications_[i-1].column_span ();
934 if (span_diff && fabs (diff) <= 2)
937 tie_configs->at (i).dir_ = UP;
938 else if (span_diff < 0)
939 tie_configs->at (i-1).dir_ = DOWN;
941 else if (fabs (diff) <= 1)
943 if (!tie_configs->at (i-1).dir_)
944 tie_configs->at (i-1).dir_ = DOWN;
945 if (!tie_configs->at (i).dir_)
946 tie_configs->at (i).dir_ = UP;
950 for (vsize i = 1; i < tie_configs->size() - 1; i++)
952 Tie_configuration &conf = tie_configs->at (i);
956 Direction position_dir =
957 Direction (sign (conf.position_));
961 conf.dir_ = position_dir;
965 Tie_configuration_variation::Tie_configuration_variation ()
971 vector<Tie_configuration_variation>
972 Tie_formatting_problem::generate_extremal_tie_variations (Ties_configuration const &ties) const
974 vector<Tie_configuration_variation> vars;
978 if (boundary (ties, d, 0).dir_ == d
979 && !boundary (specifications_, d, 0).has_manual_position_)
980 for (int i = 1; i <= details_.multi_tie_region_size_; i++)
982 Tie_configuration_variation var;
983 var.index_ = (d == DOWN) ? 0 : ties.size () - 1;
984 var.suggestion_ = get_configuration (boundary (ties, d, 0).position_
986 boundary (ties, d, 0).column_ranks_);
987 vars.push_back (var);
990 while (flip (&d) != DOWN);
996 vector<Tie_configuration_variation>
997 Tie_formatting_problem::generate_collision_variations (Ties_configuration const &ties) const
999 Real center_distance_tolerance = 0.25;
1001 vector<Tie_configuration_variation> vars;
1002 Real last_center = 0.0;
1003 for (vsize i = 0; i < ties.size (); i++)
1005 Bezier b (ties[i].get_transformed_bezier (details_));
1007 Real center = b.curve_point (0.5)[Y_AXIS];
1011 if (center <= last_center + center_distance_tolerance)
1013 if (!specifications_[i].has_manual_dir_)
1015 Tie_configuration_variation var;
1017 var.suggestion_ = get_configuration (specifications_[i].position_
1021 ties[i].column_ranks_
1024 vars.push_back (var);
1027 if (!specifications_[i-1].has_manual_dir_)
1029 Tie_configuration_variation var;
1031 var.suggestion_ = get_configuration (specifications_[i-1].position_
1034 specifications_[i-1].column_ranks_);
1036 vars.push_back (var);
1039 if (i == 1 && !specifications_[i-1].has_manual_position_
1040 && ties[i-1].dir_ == DOWN)
1042 Tie_configuration_variation var;
1044 var.suggestion_ = get_configuration (specifications_[i-1].position_ - 1, DOWN,
1045 specifications_[i-1].column_ranks_);
1046 vars.push_back (var);
1048 if (i == ties.size() && !specifications_[i].has_manual_position_
1049 && ties[i].dir_ == UP)
1051 Tie_configuration_variation var;
1053 var.suggestion_ = get_configuration (specifications_[i].position_
1055 specifications_[i].column_ranks_);
1056 vars.push_back (var);
1059 else if (dot_positions_.find (ties[i].position_) != dot_positions_.end ()
1060 && !specifications_[i].has_manual_position_)
1062 Tie_configuration_variation var;
1064 var.suggestion_ = get_configuration (ties[i].position_ + ties[i].dir_,
1066 ties[i].column_ranks_);
1067 vars.push_back (var);
1072 last_center = center;
1080 Tie_formatting_problem::set_manual_tie_configuration (SCM manual_configs)
1083 for (SCM s = manual_configs;
1084 scm_is_pair (s) && k < specifications_.size (); s = scm_cdr (s))
1086 SCM entry = scm_car (s);
1087 if (scm_is_pair (entry))
1089 Tie_specification &spec = specifications_[k];
1091 if (scm_is_number (scm_car (entry)))
1093 spec.has_manual_position_ = true;
1094 spec.manual_position_ = scm_to_double (scm_car (entry));
1096 if (scm_is_number (scm_cdr (entry)))
1098 spec.has_manual_dir_ = true;
1099 spec.manual_dir_ = Direction (scm_to_int (scm_cdr (entry)));