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] = skyline_height ((*i).second, y, -d);
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));
119 chord_outlines_[key] = empty_skyline (-dir);
121 if (bounds[0]->break_status_dir ())
123 Real x = robust_relative_extent (bounds[0], x_refpoint_, X_AXIS)[-dir];
124 chord_outlines_[key].at (0).height_ = x;
129 for (vsize j = 0; j < head_boxes.size (); j++)
131 x.unite (head_boxes[j][X_AXIS]);
134 chord_outlines_[key].at (0).height_ = x[dir];
137 for (vsize i = 0; i < boxes.size (); i++)
138 insert_extent_into_skyline (&chord_outlines_[key] ,
139 boxes[i], Y_AXIS, -dir);
142 && !Stem::is_invisible (stem))
145 x.add_point (stem->relative_coordinate (x_refpoint_, X_AXIS));
146 x.widen (staff_space / 20); // ugh.
148 y.add_point (Stem::stem_end_position (stem) * staff_space * .5);
150 Direction stemdir = get_grob_direction (stem);
151 y.add_point (Stem::head_positions (stem)[-stemdir]
154 insert_extent_into_skyline (&chord_outlines_[key], Box (x,y), Y_AXIS, -dir);
156 stem_extents_[key].unite (Box (x,y));
160 Box flag_box = Stem::get_translated_flag (stem).extent_box ();
161 flag_box.translate( Offset (x[RIGHT], X_AXIS));
162 insert_extent_into_skyline (&chord_outlines_[key], flag_box,
167 Direction updowndir = DOWN;
172 if (head_boxes.size())
174 Box b = boundary (head_boxes, updowndir, 0);
176 x[-dir] = b[X_AXIS].linear_combination (-dir / 2);
177 y[-updowndir] = b[Y_AXIS][updowndir];
178 y[updowndir] = updowndir * infinity_f;
182 insert_extent_into_skyline (&chord_outlines_[key],
186 while (flip (&updowndir) != DOWN);
188 head_extents_[key].set_empty ();
189 for (vsize i = 0; i < head_boxes.size (); i++)
191 head_extents_[key].unite (head_boxes[i]);
196 Tie_formatting_problem::set_chord_outline (vector<Item*> bounds,
201 for (vsize i = 0; i < bounds.size (); i++)
202 ranks.push_back (bounds[i]->get_column ()->get_rank ());
204 vector_sort (ranks, default_compare);
207 for (vsize i = 0; i < ranks.size (); i++)
209 vector<Item*> col_items;
210 for (vsize j = 0; j < bounds.size (); j ++)
212 if (bounds[j]->get_column ()->get_rank () == ranks[i])
213 col_items.push_back (bounds[j]);
216 set_column_chord_outline (col_items, dir, ranks[i]);
223 Tie_formatting_problem::from_tie (Grob *tie)
226 ties.push_back (tie);
229 details_.from_grob (tie);
233 Tie_formatting_problem::common_x_refpoint () const
239 Tie_formatting_problem::from_ties (vector<Grob*> const &ties)
244 x_refpoint_ = ties[0];
245 for (vsize i = 0; i < ties.size (); i++)
247 x_refpoint_ = dynamic_cast<Spanner*> (ties[i])->get_bound (LEFT)->common_refpoint (x_refpoint_, X_AXIS);
248 x_refpoint_ = dynamic_cast<Spanner*> (ties[i])->get_bound (RIGHT)->common_refpoint (x_refpoint_, X_AXIS);
251 details_.from_grob (ties[0]);
256 vector<Item*> bounds;
258 for (vsize i = 0; i < ties.size (); i++)
260 Item *it = dynamic_cast<Spanner*> (ties[i])->get_bound (d);
262 bounds.push_back (it);
265 set_chord_outline (bounds, d);
267 while (flip (&d) != LEFT);
270 for (vsize i = 0; i < ties.size (); i++)
272 Tie_specification spec;
274 if (scm_is_number (ties[i]->get_property_data (ly_symbol2scm ("direction"))))
276 spec.manual_dir_ = to_dir (ties[i]->get_property ("direction"));
277 spec.has_manual_dir_ = true;
280 spec.position_ = Tie::get_position (ties[i]);
281 if (scm_is_number (ties[i]->get_property ("staff-position")))
283 spec.manual_position_ = scm_to_double (ties[i]->get_property ("staff-position"));
284 spec.has_manual_position_ = true;
285 spec.position_ = int (my_round (spec.manual_position_));
290 spec.note_head_drul_[d] = Tie::head (ties[i], d);
291 spec.column_ranks_[d] =
292 dynamic_cast<Spanner*> (ties[i])->get_bound (d)->get_column ()->get_rank ();
294 while (flip (&d) != LEFT);
295 specifications_.push_back (spec);
300 Tie_formatting_problem::from_semi_ties (vector<Grob*> const &lv_ties, Direction head_dir)
302 if (lv_ties.empty ())
305 details_.from_grob (lv_ties[0]);
308 int column_rank = -1;
309 for (vsize i = 0; i < lv_ties.size (); i++)
311 Tie_specification spec;
312 Item *head = unsmob_item (lv_ties[i]->get_object ("note-head"));
315 programming_error ("LV tie without head?!");
319 spec.position_ = int (Staff_symbol_referencer::get_position (head));
323 spec.note_head_drul_[head_dir] = head;
324 column_rank = dynamic_cast<Item*> (head)->get_column ()->get_rank ();
325 spec.column_ranks_ = Drul_array<int> (column_rank, column_rank);
326 heads.push_back (head);
327 specifications_.push_back (spec);
330 x_refpoint_ = lv_ties [0];
331 for (vsize i = 0; i < lv_ties.size (); i++)
332 x_refpoint_ = lv_ties[i]->common_refpoint (x_refpoint_, X_AXIS);
333 for (vsize i = 0; i < heads.size (); i++)
334 x_refpoint_ = heads[i]->common_refpoint (x_refpoint_, X_AXIS);
336 set_chord_outline (heads, head_dir);
338 Real extremal = head_dir * infinity_f;
340 Tuple2<int> head_key (column_rank, head_dir);
341 Tuple2<int> open_key (column_rank, -head_dir);
343 for (vsize i = 0; i < chord_outlines_[head_key].size (); i++)
345 extremal = head_dir * min (head_dir * extremal,
346 head_dir * chord_outlines_[head_key][i].height_);
349 Skyline_entry right_entry;
350 right_entry.width_.set_full ();
351 right_entry.height_ = extremal - head_dir * 1.5;
353 chord_outlines_[open_key].push_back (right_entry);
358 Tie_formatting_problem::get_tie_specification (int i) const
360 return specifications_[i];
365 Return configuration, create it if necessary.
368 Tie_formatting_problem::get_configuration (int pos, Direction dir, Drul_array<int> columns) const
370 int key_components[] = {
371 pos, dir, columns[LEFT], columns[RIGHT]
373 Tuple<int,4> key (key_components);
375 Tie_configuration_map::const_iterator f = possibilities_.find (key);
376 if (f != possibilities_.end ())
382 Tie_configuration *conf = generate_configuration (pos, dir, columns);
383 ((Tie_formatting_problem*) this)->possibilities_[key] = conf;
388 Tie_formatting_problem::generate_configuration (int pos, Direction dir,
389 Drul_array<int> columns) const
391 Tie_configuration *conf = new Tie_configuration;
392 conf->position_ = pos;
395 conf->column_ranks_ = columns;
397 Real y = conf->position_ * 0.5 * details_.staff_space_;
400 if (dot_positions_.find (pos) != dot_positions_.end ())
402 conf->delta_y_ += dir * 0.25 * details_.staff_space_;
407 && max (fabs (get_head_extent (columns[LEFT], LEFT, Y_AXIS)[dir] - y),
408 fabs (get_head_extent (columns[RIGHT], RIGHT, Y_AXIS)[dir] - y)) < 0.25
409 && !Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, pos))
412 (get_head_extent (columns[LEFT], LEFT, Y_AXIS)[dir] - y)
413 + dir * details_.outer_tie_vertical_gap_;
418 conf->attachment_x_ = get_attachment (y + conf->delta_y_, conf->column_ranks_);
419 Real h = conf->height (details_);
424 - should make sliding criterion, should flatten ties if
426 - they're just the wrong (ie. touching line at top & bottom)
430 if (h < details_.intra_space_threshold_ * 0.5 * details_.staff_space_)
432 if (!Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, pos)
433 && abs (pos) < 2 * Staff_symbol_referencer::staff_radius (details_.staff_symbol_referencer_))
435 conf->center_tie_vertically (details_);
437 else if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, pos))
439 conf->delta_y_ += dir *
440 details_.tip_staff_line_clearance_ * 0.5 * details_.staff_space_;
445 Real top_y = y + conf->delta_y_ + conf->dir_ * h;
446 Real top_pos = top_y / (0.5*details_.staff_space_);
447 int round_pos = int (my_round (top_pos));
449 /* TODO: should use other variable? */
450 Real clearance = details_.center_staff_line_clearance_;
451 if (fabs (top_pos - round_pos) < clearance
452 && Staff_symbol_referencer::on_staff_line (details_.staff_symbol_referencer_,
455 Real new_y = (round_pos + clearance * conf->dir_) * 0.5 * details_.staff_space_;
456 conf->delta_y_ = (new_y - top_y);
461 conf->attachment_x_ = get_attachment (y + conf->delta_y_, conf->column_ranks_);
462 if (conf->height (details_) < details_.intra_space_threshold_ * 0.5 * details_.staff_space_)
465 This is less sensible for long ties, since those are more
468 Interval close_by = get_attachment (y
470 + (dir * details_.intra_space_threshold_ * 0.25
471 * details_.staff_space_),
472 conf->column_ranks_);
474 conf->attachment_x_.intersect (close_by);
477 conf->attachment_x_.widen ( - details_.x_gap_);
482 Real y = conf->position_ * details_.staff_space_ * 0.5 + conf->delta_y_;
483 if (get_stem_extent (conf->column_ranks_[d], d, X_AXIS).is_empty ()
484 || !get_stem_extent (conf->column_ranks_[d], d, Y_AXIS).contains (y))
487 conf->attachment_x_[d] =
488 d * min (d * conf->attachment_x_[d],
489 d * (get_stem_extent (conf->column_ranks_[d], d, X_AXIS)[-d] - d * details_.stem_gap_));
491 while (flip (&d) != LEFT);
497 Tie_formatting_problem::get_head_extent (int col, Direction d, Axis a) const
499 return (*head_extents_.find (Tuple2<int> (col, int (d)))).second[a];
503 Tie_formatting_problem::get_stem_extent (int col, Direction d, Axis a) const
505 return (*stem_extents_.find (Tuple2<int> (col, int (d)))).second[a];
509 TIE_IDX and TIES_CONF are optional.
512 Tie_formatting_problem::score_aptitude (Tie_configuration *conf,
513 Tie_specification const &spec,
514 Ties_configuration *ties_conf, int tie_idx) const
517 Real curve_y = conf->position_ * details_.staff_space_ * 0.5 + conf->delta_y_;
518 Real tie_y = spec.position_ * details_.staff_space_ * 0.5;
519 if (sign (curve_y - tie_y) != conf->dir_)
521 Real p = details_.wrong_direction_offset_penalty_;
523 ties_conf->add_tie_score (p, tie_idx, "wrong dir");
529 Real p = details_.vertical_distance_penalty_factor_ * fabs (curve_y - tie_y);
531 ties_conf->add_tie_score (p, tie_idx, "vdist");
539 if (!spec.note_head_drul_[d])
542 Interval head_x = spec.note_head_drul_[d]->extent (x_refpoint_, X_AXIS);
543 Real dist = head_x.distance (conf->attachment_x_[d]);
546 TODO: flatten with log or sqrt.
548 Real p = details_.horizontal_distance_penalty_factor_ * dist;
550 ties_conf->add_tie_score (p, tie_idx,
551 (d == LEFT) ? "lhdist" : "rhdist");
555 while (flip (&d) != LEFT);
561 Tie_formatting_problem::score_configuration (Tie_configuration *conf) const
568 Real length = conf->attachment_x_.length ();
570 conf->add_score (details_.min_length_penalty_factor_
571 * peak_around (0.33 * details_.min_length_, details_.min_length_, length),
574 Real tip_pos = conf->position_ + conf->delta_y_ / 0.5 * details_.staff_space_;
575 Real tip_y = tip_pos * details_.staff_space_ * 0.5;
576 Real height = conf->height (details_);
578 Real top_y = tip_y + conf->dir_ * height;
579 Real top_pos = 2 * top_y / details_.staff_space_;
580 Real round_top_pos = rint (top_pos);
581 if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_,
583 && Staff_symbol_referencer::staff_radius (details_.staff_symbol_referencer_) > top_y)
586 details_.staff_line_collision_penalty_
587 * peak_around (0.1 * details_.center_staff_line_clearance_,
588 details_.center_staff_line_clearance_,
589 fabs (top_pos - round_top_pos)),
593 if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_,
594 int (rint (tip_pos))))
596 conf->add_score (details_.staff_line_collision_penalty_
597 * peak_around (0.1 * details_.tip_staff_line_clearance_,
598 details_.tip_staff_line_clearance_,
599 fabs (tip_pos - rint (tip_pos))),
603 if (!dot_x_.is_empty ())
606 Real x = dot_x_.center ();
608 Bezier b = conf->get_transformed_bezier (details_);
609 if (b.control_point_extent (X_AXIS).contains (x))
611 Real y = b.get_other_coordinate (X_AXIS, x);
613 for (set<int>::const_iterator i (dot_positions_.begin ());
614 i != dot_positions_.end (); i ++)
617 conf->add_score (details_.dot_collision_penalty_
618 * peak_around (.1 * details_.dot_collision_clearance_,
619 details_.dot_collision_clearance_,
620 fabs (dot_pos * details_.staff_space_ * 0.5 - y)),
626 conf->scored_ = true;
630 Tie_formatting_problem::find_optimal_tie_configuration (Tie_specification const &spec) const
632 vector<Tie_configuration*> confs;
634 int pos = spec.position_;
635 Direction dir = spec.manual_dir_;
637 for (int i = 0; i < details_.single_tie_region_size_; i ++)
639 confs.push_back (generate_configuration (pos + i * dir, dir,
640 spec.column_ranks_));
642 if (spec.has_manual_position_)
644 confs.back ()->delta_y_
645 = (spec.manual_position_ - spec.position_)
646 * 0.5 * details_.staff_space_;
655 Real best_score = 1e6;
656 for (vsize i = 0; i < confs.size (); i ++)
658 score_configuration (confs[i]);
659 Real score = score_aptitude (confs[i], spec, 0, 0)
660 + confs[i]->score ();
662 if (score < best_score)
670 programming_error ("No best tie configuration found.");
672 Tie_configuration best
673 = (best_idx >= 0) ? *confs[best_idx] : *confs[0];
675 for (vsize i = 0; i < confs.size (); i++)
681 Tie_specification::Tie_specification ()
683 has_manual_position_ = false;
684 has_manual_dir_ = false;
686 manual_position_ = 0;
687 manual_dir_ = CENTER;
688 note_head_drul_[LEFT] =
689 note_head_drul_[RIGHT] = 0;
690 column_ranks_[RIGHT] =
691 column_ranks_[LEFT] = 0;
695 Tie_specification::column_span () const
697 return column_ranks_[RIGHT] - column_ranks_[LEFT];
701 Tie_formatting_problem::score_ties_aptitude (Ties_configuration *ties) const
703 if (ties->size () != specifications_.size ())
705 programming_error ("Huh? Mismatch between sizes.");
709 for (vsize i = 0; i < ties->size (); i++)
710 score_aptitude (&ties->at (i), specifications_[i],
715 Tie_formatting_problem::score_ties (Ties_configuration *ties) const
720 score_ties_configuration (ties);
721 score_ties_aptitude (ties);
722 ties->scored_ = true;
726 Tie_formatting_problem::score_ties_configuration (Ties_configuration *ties) const
728 for (vsize i = 0; i < ties->size (); i++)
730 score_configuration (&ties->at (i));
731 ties->add_tie_score (ties->at (i).score (), i, "conf");
734 Real last_edge = 0.0;
735 Real last_center = 0.0;
736 for (vsize i = 0; i < ties->size (); i++)
738 Bezier b (ties->at (i).get_transformed_bezier (details_));
740 Real center = b.curve_point (0.5)[Y_AXIS];
741 Real edge = b.curve_point (0.0)[Y_AXIS];
745 if (edge <= last_edge)
746 ties->add_score (details_.tie_column_monotonicity_penalty_, "monoton edge");
747 if (center <= last_center)
748 ties->add_score (details_.tie_column_monotonicity_penalty_, "monoton cent");
750 ties->add_score (details_.tie_tie_collision_penalty_ *
751 peak_around (0.1 * details_.tie_tie_collision_distance_,
752 details_.tie_tie_collision_distance_,
753 fabs (center - last_center)),
755 ties->add_score (details_.tie_tie_collision_penalty_ *
756 peak_around (0.1 * details_.tie_tie_collision_distance_,
757 details_.tie_tie_collision_distance_,
758 fabs (edge - last_edge)), "tietie edge");
762 last_center = center;
765 ties->add_score (details_.outer_tie_length_symmetry_penalty_factor_
766 * fabs (ties->at (0).attachment_x_.length () - ties->back ().attachment_x_.length ()),
769 ties->add_score (details_.outer_tie_vertical_distance_symmetry_penalty_factor_
770 * fabs (fabs (specifications_[0].position_ * 0.5 * details_.staff_space_
771 - (ties->at (0).position_ * 0.5 * details_.staff_space_
772 + ties->at (0).delta_y_))
774 fabs (specifications_.back ().position_ * 0.5 * details_.staff_space_
775 - (ties->back ().position_ * 0.5 * details_.staff_space_
776 + ties->back ().delta_y_))),
781 Generate with correct X-attachments and beziers, copying delta_y_
782 from TIES_CONFIG if necessary.
785 Tie_formatting_problem::generate_ties_configuration (Ties_configuration const &ties_config)
787 Ties_configuration copy;
788 for (vsize i = 0; i < ties_config.size (); i++)
790 Tie_configuration * ptr = get_configuration (ties_config[i].position_, ties_config[i].dir_,
791 ties_config[i].column_ranks_);
792 if (specifications_[i].has_manual_position_)
795 = (specifications_[i].manual_position_ - ties_config[i].position_)
796 * 0.5 * details_.staff_space_;
798 copy.push_back (*ptr);
805 Tie_formatting_problem::generate_base_chord_configuration ()
807 Ties_configuration ties_config;
808 for (vsize i = 0; i < specifications_.size (); i ++)
810 Tie_configuration conf;
811 if (specifications_[i].has_manual_dir_)
812 conf.dir_ = specifications_[i].manual_dir_;
813 if (specifications_[i].has_manual_position_)
815 conf.position_ = (int) my_round (specifications_[i].manual_position_);
816 conf.delta_y_ = (specifications_[i].manual_position_ - conf.position_)
817 * 0.5 * details_.staff_space_;
821 conf.position_ = specifications_[i].position_;
824 conf.column_ranks_ = specifications_[i].column_ranks_;
825 ties_config.push_back (conf);
828 set_ties_config_standard_directions (&ties_config);
829 for (vsize i = 0; i < ties_config.size (); i++)
830 if (!specifications_[i].manual_position_)
831 ties_config[i].position_ += ties_config[i].dir_;
833 ties_config = generate_ties_configuration (ties_config);
839 Tie_formatting_problem::find_best_variation (Ties_configuration const &base,
840 vector<Tie_configuration_variation> vars)
842 Ties_configuration best = base;
845 This simply is 1-opt: we have K substitions, and we try applying
846 exactly every one for each.
848 for (vsize i = 0; i < vars.size (); i++)
850 Ties_configuration variant (base);
851 variant[vars[i].index_] = *vars[i].suggestion_;
853 variant.reset_score ();
854 score_ties (&variant);
856 if (variant.score () < best.score ())
868 Tie_formatting_problem::generate_optimal_chord_configuration ()
871 Ties_configuration base = generate_base_chord_configuration ();
872 vector<Tie_configuration_variation> vars = generate_collision_variations (base);
875 Ties_configuration best = find_best_variation (base, vars);
876 vars = generate_extremal_tie_variations (best);
877 best = find_best_variation (best, vars);
883 Tie_formatting_problem::set_ties_config_standard_directions (Ties_configuration *tie_configs)
885 if (tie_configs->empty ())
888 if (!tie_configs->at (0).dir_)
889 tie_configs->at (0).dir_ = DOWN;
890 if (!tie_configs->back ().dir_)
891 tie_configs->back ().dir_ = UP;
896 for (vsize i = 1; i < tie_configs->size (); i++)
898 Real diff = (tie_configs->at (i).position_
899 -tie_configs->at (i-1).position_);
902 = specifications_[i].column_span () - specifications_[i-1].column_span ();
903 if (span_diff && fabs (diff) <= 2)
906 tie_configs->at (i).dir_ = UP;
907 else if (span_diff < 0)
908 tie_configs->at (i-1).dir_ = DOWN;
910 else if (fabs (diff) <= 1)
912 if (!tie_configs->at (i-1).dir_)
913 tie_configs->at (i-1).dir_ = DOWN;
914 if (!tie_configs->at (i).dir_)
915 tie_configs->at (i).dir_ = UP;
919 for (vsize i = 1; i < tie_configs->size() - 1; i++)
921 Tie_configuration &conf = tie_configs->at (i);
925 Direction position_dir =
926 Direction (sign (conf.position_));
930 conf.dir_ = position_dir;
934 Tie_configuration_variation::Tie_configuration_variation ()
940 vector<Tie_configuration_variation>
941 Tie_formatting_problem::generate_extremal_tie_variations (Ties_configuration const &ties) const
943 vector<Tie_configuration_variation> vars;
947 if (boundary (ties, d, 0).dir_ == d
948 && !boundary (specifications_, d, 0).has_manual_position_)
949 for (int i = 1; i <= details_.multi_tie_region_size_; i++)
951 Tie_configuration_variation var;
952 var.index_ = (d == DOWN) ? 0 : ties.size () - 1;
953 var.suggestion_ = get_configuration (boundary (ties, d, 0).position_
955 boundary (ties, d, 0).column_ranks_);
956 vars.push_back (var);
959 while (flip (&d) != DOWN);
965 vector<Tie_configuration_variation>
966 Tie_formatting_problem::generate_collision_variations (Ties_configuration const &ties) const
968 Real center_distance_tolerance = 0.25;
970 vector<Tie_configuration_variation> vars;
971 Real last_center = 0.0;
972 for (vsize i = 0; i < ties.size (); i++)
974 Bezier b (ties[i].get_transformed_bezier (details_));
976 Real center = b.curve_point (0.5)[Y_AXIS];
980 if (center <= last_center + center_distance_tolerance)
982 if (!specifications_[i].has_manual_dir_)
984 Tie_configuration_variation var;
986 var.suggestion_ = get_configuration (specifications_[i].position_
990 ties[i].column_ranks_
993 vars.push_back (var);
996 if (!specifications_[i-1].has_manual_dir_)
998 Tie_configuration_variation var;
1000 var.suggestion_ = get_configuration (specifications_[i-1].position_
1003 specifications_[i-1].column_ranks_);
1005 vars.push_back (var);
1008 if (i == 1 && !specifications_[i-1].has_manual_position_
1009 && ties[i-1].dir_ == DOWN)
1011 Tie_configuration_variation var;
1013 var.suggestion_ = get_configuration (specifications_[i-1].position_ - 1, DOWN,
1014 specifications_[i-1].column_ranks_);
1015 vars.push_back (var);
1017 if (i == ties.size() && !specifications_[i].has_manual_position_
1018 && ties[i].dir_ == UP)
1020 Tie_configuration_variation var;
1022 var.suggestion_ = get_configuration (specifications_[i].position_
1024 specifications_[i].column_ranks_);
1025 vars.push_back (var);
1028 else if (dot_positions_.find (ties[i].position_) != dot_positions_.end ()
1029 && !specifications_[i].has_manual_position_)
1031 Tie_configuration_variation var;
1033 var.suggestion_ = get_configuration (ties[i].position_ + ties[i].dir_,
1035 ties[i].column_ranks_);
1036 vars.push_back (var);
1041 last_center = center;
1049 Tie_formatting_problem::set_manual_tie_configuration (SCM manual_configs)
1052 for (SCM s = manual_configs;
1053 scm_is_pair (s) && k < specifications_.size (); s = scm_cdr (s))
1055 SCM entry = scm_car (s);
1056 if (scm_is_pair (entry))
1058 Tie_specification &spec = specifications_[k];
1060 if (scm_is_number (scm_car (entry)))
1062 spec.has_manual_position_ = true;
1063 spec.manual_position_ = scm_to_double (scm_car (entry));
1065 if (scm_is_number (scm_cdr (entry)))
1067 spec.has_manual_dir_ = true;
1068 spec.manual_dir_ = Direction (scm_to_int (scm_cdr (entry)));