]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4965: Create and use Grob::parent_relative
authorDavid Kastrup <dak@gnu.org>
Fri, 2 Sep 2016 21:11:53 +0000 (23:11 +0200)
committerDavid Kastrup <dak@gnu.org>
Thu, 8 Sep 2016 10:28:04 +0000 (12:28 +0200)
This function checks for the existence of a Grob parent before
calculating a coordinate relative to it.  This should hopefully
clean up the most relevant problems caused by issue 4814
and the original GCC 6 optimization causing it.

lily/beam.cc
lily/fingering-column.cc
lily/grob.cc
lily/include/grob.hh
lily/side-position-interface.cc
lily/tuplet-bracket.cc

index a20530c0f3e0afdbd8adc7aa12a8a8802aa9115c..a50f2904bc0b00e4a497c16c908b13cabf38d96b 100644 (file)
@@ -1280,7 +1280,7 @@ Beam::rest_collision_callback (SCM smob, SCM prev_offset)
 
   Real offset = robust_scm2double (prev_offset, 0.0);
   Interval rest_extent = rest->extent (rest, Y_AXIS);
-  rest_extent.translate (offset + rest->get_parent (Y_AXIS)->relative_coordinate (common_y, Y_AXIS));
+  rest_extent.translate (offset + rest->parent_relative (common_y, Y_AXIS));
 
   Real rest_dim = rest_extent[d];
   Real minimum_distance
index c9db28baf93e8bb26ff6810cc28d43770247292e..c069fb7c74c61c8a033c7ec833151c75ffe748a4 100644 (file)
@@ -99,8 +99,7 @@ Fingering_column::do_y_positioning (Grob *me)
         {
           Interval x_ext = fingerings[i]->extent(common[X_AXIS], X_AXIS);
           Interval y_ext = fingerings[i]->extent(fingerings[i], Y_AXIS);
-          Real parent_y = fingerings[i]->get_parent(Y_AXIS)
-                         ->relative_coordinate(common[Y_AXIS], Y_AXIS);
+          Real parent_y = fingerings[i]->parent_relative (common[Y_AXIS], Y_AXIS);
 
           // Checking only between sequential neighbors, seems good enough
           if (!intersection(x_ext, prev_x_ext).is_empty())
index eafa66288efdab93c9ab72bf49a3831c749c24b2..23a1cafae48730885fb7068346750e1f114ec35a 100644 (file)
@@ -338,14 +338,16 @@ Grob::relative_coordinate (Grob const *refp, Axis a) const
 
   /* We catch PARENT_L_ == nil case with this, but we crash if we did
      not ask for the absolute coordinate (ie. REFP == nil.)  */
-  Real off = get_offset (a);
-  if (refp == dim_cache_[a].parent_)
-    return off;
 
-  if (dim_cache_[a].parent_ != NULL)
-    off += dim_cache_[a].parent_->relative_coordinate (refp, a);
+  return get_offset (a) + parent_relative (refp, a);
+}
 
-  return off;
+Real
+Grob::parent_relative (Grob const *refp, Axis a) const
+{
+  if (Grob *p = get_parent (a))
+    return p->relative_coordinate (refp, a);
+  return 0.0;
 }
 
 Real
index a9408f09a2ac1cbc6beb21a9766526c3d3af5914..5da4dff74ec6107c242754e6c60b2eddefa90848 100644 (file)
@@ -141,6 +141,7 @@ public:
   /* offsets */
   void translate_axis (Real, Axis);
   Real relative_coordinate (Grob const *refp, Axis) const;
+  Real parent_relative (Grob const *refp, Axis) const;
   Real pure_relative_y_coordinate (Grob const *refp, int start, int end);
   Real maybe_pure_coordinate (Grob const *refp, Axis a, bool pure, int start, int end);
 
index 16e2929a6699001fd029f7e43548097ec62031c6..52551e8b5286452342d4eae53dbc1f9396efef36 100644 (file)
@@ -220,7 +220,7 @@ Side_position_interface::aligned_side (Grob *me, Axis a, bool pure, int start, i
       // skyline will likely be of infinite width anyway
       // and we don't want to prematurely trigger H spacing
       Real xc = a == X_AXIS || (pure && dynamic_cast<Spanner *> (me))
-                ? me->get_parent (X_AXIS)->relative_coordinate (common[X_AXIS], X_AXIS)
+                ? me->parent_relative (common[X_AXIS], X_AXIS)
                 : me->relative_coordinate (common[X_AXIS], X_AXIS);
       // same here, for X_AXIS spacing, if it's happening, it should only be
       // before line breaking.  because there is no thing as "pure" x spacing,
@@ -274,7 +274,7 @@ Side_position_interface::aligned_side (Grob *me, Axis a, bool pure, int start, i
            if (unsmob<Skyline_pair> (sp))
              {
                Real xc = pure && dynamic_cast<Spanner *> (e)
-                         ? e->get_parent (X_AXIS)->relative_coordinate (common[X_AXIS], X_AXIS)
+                         ? e->parent_relative (common[X_AXIS], X_AXIS)
                          : e->relative_coordinate (common[X_AXIS], X_AXIS);
                // same logic as above
                // we assume horizontal spacing is always pure
index 17e1194de80762822da92ed5e7d8767bc6a8a7d0..340b017723753e5431ecce6379129f65ad212caf 100644 (file)
@@ -540,7 +540,7 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy)
           if (Grob *beam = Stem::get_beam (stems[side]))
             (void) beam->get_property ("quantized-positions");
           poss[side] = stems[side]->extent (stems[side], Y_AXIS)[get_grob_direction (stems[side])]
-                       + stems[side]->get_parent (Y_AXIS)->relative_coordinate (commony, Y_AXIS);
+                       + stems[side]->parent_relative (commony, Y_AXIS);
         }
 
       *dy = poss[RIGHT] - poss[LEFT];