+
+ edge_dirs_ = Drul_array<Direction> (CENTER, CENTER);
+ normal_stem_count_ += Beam::normal_stem_count (beams[i]);
+ if (normal_stem_count_)
+ edge_dirs_ = Drul_array<Direction> (stem_infos_[0].dir_,
+ stem_infos_.back ().dir_);
+
+ is_xstaff_ = has_interface<Align_interface> (common[Y_AXIS]);
+ is_knee_ |= dirs_found[DOWN] && dirs_found[UP];
+
+ staff_radius_ = Staff_symbol_referencer::staff_radius (beams[i]);
+ edge_beam_counts_ = Drul_array<int>
+ (Stem::beam_multiplicity (stems[0]).length () + 1,
+ Stem::beam_multiplicity (stems.back ()).length () + 1);
+
+ // TODO - why are we dividing by staff_space_?
+ beam_translation_ = Beam::get_beam_translation (beams[i]) / staff_space_;
+
+ for (LEFT_and_RIGHT (d))
+ {
+ quant_range_[d].set_full ();
+ if (!edge_stems[d])
+ continue;
+
+ Real stem_offset = edge_stems[d]->relative_coordinate (common[Y_AXIS], Y_AXIS)
+ - beams[i]->relative_coordinate (common[Y_AXIS], Y_AXIS);
+ Interval heads = Stem::head_positions (edge_stems[d]) * 0.5 * staff_space_;
+
+ Direction ed = edge_dirs_[d];
+ heads.widen (0.5 * staff_space_
+ + (edge_beam_counts_[d] - 1) * beam_translation_ + beam_thickness_ * .5);
+ quant_range_[d][-ed] = heads[ed] + stem_offset;
+ }
+
+ segments_ = Beam::get_beam_segments (beams[i]);
+ vector_sort (segments_, beam_segment_less);
+ for (vsize j = 0; j < segments_.size (); j++)
+ segments_[j].horizontal_ += (x_span_ - x_pos[LEFT]);
+
+ set<Grob *> colliding_stems;
+ for (vsize j = 0; j < collisions.size (); j++)
+ {
+ if (!collisions[j]->is_live ())
+ continue;
+
+ if (has_interface<Beam> (collisions[j]) && Beam::is_cross_staff (collisions[j]))
+ continue;
+
+ Box b;
+ for (Axis a = X_AXIS; a < NO_AXES; incr (a))
+ b[a] = collisions[j]->extent (common[a], a);
+
+ if (b[X_AXIS][RIGHT] < x_pos[LEFT] || b[X_AXIS][LEFT] > x_pos[RIGHT])
+ continue;
+ if (b[X_AXIS].is_empty () || b[Y_AXIS].is_empty ())
+ continue;
+
+ b[X_AXIS] += (x_span_ - x_pos[LEFT]);
+ b[Y_AXIS] -= my_y;
+ Real width = b[X_AXIS].length ();
+ Real width_factor = sqrt (width / staff_space_);
+
+ for (LEFT_and_RIGHT (d))
+ add_collision (b[X_AXIS][d], b[Y_AXIS], width_factor);
+
+ Grob *stem = unsmob<Grob> (collisions[j]->get_object ("stem"));
+ if (has_interface<Stem> (stem) && Stem::is_normal_stem (stem))
+ {
+ colliding_stems.insert (stem);
+ }
+ }
+
+ for (set<Grob *>::const_iterator it (colliding_stems.begin ()); it != colliding_stems.end (); it++)
+ {
+ Grob *s = *it;
+ Real x = (robust_relative_extent (s, common[X_AXIS], X_AXIS) - x_pos[LEFT] + x_span_).center ();
+
+ Direction stem_dir = get_grob_direction (*it);
+ Interval y;
+ y.set_full ();
+ y[-stem_dir] = Stem::chord_start_y (*it) + (*it)->relative_coordinate (common[Y_AXIS], Y_AXIS)
+ - my_y;
+
+ Real factor = parameters_.STEM_COLLISION_FACTOR;
+ if (!unsmob<Grob> (s->get_object ("beam")))
+ factor = 1.0;
+ add_collision (x, y, factor);
+ }
+ x_span_ += beams[i]->spanner_length ();