]> git.donarmstrong.com Git - lilypond.git/commitdiff
* input/regression/tie-dot.ly: new file.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 13 Dec 2005 10:28:11 +0000 (10:28 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 13 Dec 2005 10:28:11 +0000 (10:28 +0000)
* lily/tie-formatting-problem.cc (score_configuration): score
tie/dot collisions.

* lily/tie-helper.cc (get_transformed_bezier): new function

ChangeLog
input/regression/tie-dot.ly [new file with mode: 0644]
lily/bezier.cc
lily/include/bezier.hh
lily/include/tie-formatting-problem.hh
lily/include/tie.hh
lily/tie-formatting-problem.cc
lily/tie-helper.cc
lily/tie.cc

index 60082afa2c1132dbad6028b8738e1ad55dd63939..bf2afb82590f972c475e932f7332ba8786ce81ad 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2005-12-13  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
+       * 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 (file)
index 0000000..6338fb7
--- /dev/null
@@ -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
+}
+
+
index 1b73404b776dde613408eb5668e6ec6e913b075b..ab79ed91b47f3485e5ce0195be6411835c95dd05 100644 (file)
@@ -66,7 +66,7 @@ translate (Array<Offset> *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<Real> 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
 */
index 60d175a9762106e3876cdfe924a95ec8ffd7a05c..79c311dced0d541bc88f103ff4c966142310d32a 100644 (file)
@@ -26,7 +26,9 @@ public:
   Real get_other_coordinate (Axis a, Real x) const;
   Array<Real> solve_point (Axis, Real coordinate) const;
   Array<Real> 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;
index c3cc58926f36474d1b0cf870cbfdd40fb8677ba7..36afc52ff615edb16359e7b8bdae6850589c4fd8 100644 (file)
@@ -38,6 +38,8 @@ class Tie_formatting_problem
 {
   Drul_array< Array<Skyline_entry> > chord_outlines_;
   set<int> dot_positions_;
+  Interval dot_x_;
+  
   Tie_configuration_map possibilities_;
 
   Tie_configuration *get_configuration (int position, Direction dir);
index 30be5796113207dfa0fcc11a93435ee0aea43263..d78e5e1b142724016e4d44090b18e25f62a3fa8d 100644 (file)
@@ -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,
index 36c81fe0a2b1a4d25d0b42dc6e5d043814d37509..2fd6b6063b766aea9bd2394c6dfe89f90b13f62d 100644 (file)
@@ -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<Item> 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<int>::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;
 }
index 23915a1d05a925c44d954da6a360f7d104625733..b0ec652d2bb18a150641d219fa0a079c2c9fb98e 100644 (file)
@@ -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))
index 5c756b7686a585f2e5fe8f848bd7578f31aeb7dc..2b743a30ca956b89900c4b217f8c0d46d9df5f13 100644 (file)
@@ -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--;)
     {