From ecde3b27ef910d586ba89dfedeb73278e48efed2 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Tue, 13 Dec 2005 10:28:11 +0000 Subject: [PATCH] * input/regression/tie-dot.ly: new file. * lily/tie-formatting-problem.cc (score_configuration): score tie/dot collisions. * lily/tie-helper.cc (get_transformed_bezier): new function --- ChangeLog | 7 +++++++ input/regression/tie-dot.ly | 16 ++++++++++++++ lily/bezier.cc | 13 +++++++++++- lily/include/bezier.hh | 4 +++- lily/include/tie-formatting-problem.hh | 2 ++ lily/include/tie.hh | 4 +++- lily/tie-formatting-problem.cc | 29 +++++++++++++++++++++++++- lily/tie-helper.cc | 20 +++++++++++++++--- lily/tie.cc | 11 +++------- 9 files changed, 91 insertions(+), 15 deletions(-) create mode 100644 input/regression/tie-dot.ly diff --git a/ChangeLog b/ChangeLog index 60082afa2c..bf2afb8259 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2005-12-13 Han-Wen Nienhuys + * input/regression/tie-dot.ly: new file. + + * lily/tie-formatting-problem.cc (score_configuration): score + tie/dot collisions. + + * lily/tie-helper.cc (get_transformed_bezier): new function + * Documentation/topdocs/NEWS.tely (Top): strip out-www. * stepmake/stepmake/python-module-vars.make (SHARED_FLAGS): use diff --git a/input/regression/tie-dot.ly b/input/regression/tie-dot.ly new file mode 100644 index 0000000000..6338fb7f1b --- /dev/null +++ b/input/regression/tie-dot.ly @@ -0,0 +1,16 @@ + +\header { + texidoc = "Ties avoid collisions with dots." +} + +\version "2.7.23" + +\paper { raggedright = ##T } + +\relative c'' { + \time 12/8 + d4*3/2~ d8[ e] r8 + d4.~ d8 e f +} + + diff --git a/lily/bezier.cc b/lily/bezier.cc index 1b73404b77..ab79ed91b4 100644 --- a/lily/bezier.cc +++ b/lily/bezier.cc @@ -66,7 +66,7 @@ translate (Array *array, Offset o) Real Bezier::get_other_coordinate (Axis a, Real x) const { - Axis other = Axis ((a +1)%NO_AXES); + Axis other = Axis ((a +1) % NO_AXES); Array ts = solve_point (a, x); if (ts.size () == 0) @@ -228,6 +228,17 @@ Bezier::extent (Axis a) const return iv; } +Interval +Bezier::control_point_extent (Axis a) const +{ + Interval ext; + for (int i = CONTROL_COUNT; i--;) + ext.add_point (control_[i][a]); + + return ext; +} + + /** Flip around axis A */ diff --git a/lily/include/bezier.hh b/lily/include/bezier.hh index 60d175a976..79c311dced 100644 --- a/lily/include/bezier.hh +++ b/lily/include/bezier.hh @@ -26,7 +26,9 @@ public: Real get_other_coordinate (Axis a, Real x) const; Array solve_point (Axis, Real coordinate) const; Array solve_derivative (Offset) const; - Interval extent (Axis)const; + Interval extent (Axis) const; + Interval control_point_extent (Axis) const; + Polynomial polynomial (Axis)const; Offset curve_point (Real t) const; Real curve_coordinate (Real t, Axis) const; diff --git a/lily/include/tie-formatting-problem.hh b/lily/include/tie-formatting-problem.hh index c3cc58926f..36afc52ff6 100644 --- a/lily/include/tie-formatting-problem.hh +++ b/lily/include/tie-formatting-problem.hh @@ -38,6 +38,8 @@ class Tie_formatting_problem { Drul_array< Array > chord_outlines_; set dot_positions_; + Interval dot_x_; + Tie_configuration_map possibilities_; Tie_configuration *get_configuration (int position, Direction dir); diff --git a/lily/include/tie.hh b/lily/include/tie.hh index 30be579611..d78e5e1b14 100644 --- a/lily/include/tie.hh +++ b/lily/include/tie.hh @@ -23,13 +23,15 @@ public: Real delta_y_; + /* computed. */ Interval attachment_x_; Grob *tie_; int head_position_; Tie_configuration (); void center_tie_vertically (Tie_details const &); - Bezier get_bezier (Tie_details const &) const; + Bezier get_transformed_bezier (Tie_details const &) const; + Bezier get_untransformed_bezier (Tie_details const &) const; Real height (Tie_details const&) const; static int compare (Tie_configuration const &a, diff --git a/lily/tie-formatting-problem.cc b/lily/tie-formatting-problem.cc index 36c81fe0a2..2fd6b6063b 100644 --- a/lily/tie-formatting-problem.cc +++ b/lily/tie-formatting-problem.cc @@ -15,7 +15,7 @@ #include "item.hh" #include "spanner.hh" - +#include "bezier.hh" #include "stem.hh" #include "note-head.hh" #include "rhythmic-head.hh" @@ -80,6 +80,7 @@ Tie_formatting_problem::set_chord_outline (Link_array bounds, y.translate (p); dot_positions_.insert (p); + dot_x_.unite (x); y *= staff_space * 0.5; // boxes.push (Box (x, y)); @@ -264,6 +265,7 @@ Tie_formatting_problem::generate_configuration (int pos, Direction dir) { conf->delta_y_ += 0.25 * details_.staff_space_; } + conf->attachment_x_ = get_attachment (y + conf->delta_y_); Real h = conf->height (details_); @@ -313,6 +315,9 @@ Tie_formatting_problem::score_configuration (Tie_configuration const &conf) Real min_length = 0.333; Real staff_line_clearance = 0.1; Real staff_line_collision_penalty = 5; + Real dot_collision_clearance = 0.25; + Real dot_collision_penalty = 10; + Real penalty = 0.0; Real length = conf.attachment_x_.length (); @@ -340,6 +345,28 @@ Tie_formatting_problem::score_configuration (Tie_configuration const &conf) { penalty += staff_line_collision_penalty; } + + if (!dot_x_.is_empty ()) + { + /* use left edge? */ + Real x = dot_x_.center (); + + Bezier b = conf.get_transformed_bezier (details_); + if (b.control_point_extent (X_AXIS).contains (x)) + { + Real y = b.get_other_coordinate (X_AXIS, x); + + for (set::const_iterator i (dot_positions_.begin ()); + i != dot_positions_.end (); i ++) + { + int dot_pos = (*i); + if (fabs (dot_pos * details_.staff_space_ * 0.5 - y) < dot_collision_clearance) + { + penalty += dot_collision_penalty; + } + } + } + } return penalty; } diff --git a/lily/tie-helper.cc b/lily/tie-helper.cc index 23915a1d05..b0ec652d2b 100644 --- a/lily/tie-helper.cc +++ b/lily/tie-helper.cc @@ -35,10 +35,9 @@ Tie_configuration::Tie_configuration () void Tie_configuration::center_tie_vertically (Tie_details const &details) { - Bezier b = get_bezier (details); + Bezier b = get_untransformed_bezier (details); Offset middle = b.curve_point (0.5); Offset edge = b.curve_point (0.0); - Real center = (edge[Y_AXIS] + middle[Y_AXIS])/2.0; delta_y_ = - dir_ * center; @@ -49,7 +48,22 @@ Tie_configuration::center_tie_vertically (Tie_details const &details) Get bezier with left control at (0,0) */ Bezier -Tie_configuration::get_bezier (Tie_details const &details) const +Tie_configuration::get_transformed_bezier (Tie_details const &details) const +{ + Bezier b (get_untransformed_bezier (details)); + + b.scale (1, dir_); + b.translate (Offset (attachment_x_[LEFT], + delta_y_ + details.staff_space_ * 0.5 * position_)); + + return b; +} + +/* + Get bezier with left control at (0,0) + */ +Bezier +Tie_configuration::get_untransformed_bezier (Tie_details const &details) const { Real l = attachment_x_.length(); if (isnan (l) || isnan (l)) diff --git a/lily/tie.cc b/lily/tie.cc index 5c756b7686..2b743a30ca 100644 --- a/lily/tie.cc +++ b/lily/tie.cc @@ -424,14 +424,9 @@ Tie::set_control_points (Grob *me, Tie_details const &details ) { - Bezier b = conf.get_bezier (details); - b.scale (1, conf.dir_); - b.translate (Offset (conf.attachment_x_[LEFT] - - me->relative_coordinate (common, X_AXIS), - 0.5 * conf.position_ * details.staff_space_ - + conf.delta_y_ - )); - + Bezier b = conf.get_transformed_bezier (details); + b.translate (Offset (- me->relative_coordinate (common, X_AXIS), 0)); + SCM controls = SCM_EOL; for (int i = 4; i--;) { -- 2.39.2