+ x_span_ is a single scalar, cumulatively summing the length of all the
+ segments the parent beam was broken-into.
+ */
+ x_span_ = 0.0;
+ is_knee_ = false;
+ normal_stem_count_ = 0;
+ for (vsize i = 0; i < beams.size (); i++)
+ {
+ extract_grob_set (beams[i], "stems", stems);
+ extract_grob_set (beams[i], "covered-grobs", fake_collisions);
+ vector<Grob *> collisions;
+
+ for (vsize j = 0; j < fake_collisions.size (); j++)
+ if (fake_collisions[j]->get_system () == beams[i]->get_system ())
+ collisions.push_back (fake_collisions[j]);
+
+ Grob *common[2];
+ for (int a = 2; a--;)
+ common[a] = common_refpoint_of_array (stems, beams[i], Axis (a));
+
+ for (LEFT_and_RIGHT (d))
+ common[X_AXIS] = beams[i]->get_bound (d)->common_refpoint (common[X_AXIS], X_AXIS);
+
+ // positions of the endpoints of this beam segment, including any overhangs
+ const Interval x_pos = robust_scm2interval (beams[i]->get_property ("X-positions"),
+ Interval (0.0, 0.0));
+
+ Drul_array<Grob *> edge_stems (Beam::first_normal_stem (beams[i]),
+ Beam::last_normal_stem (beams[i]));
+
+ Drul_array<bool> dirs_found (0, 0);
+
+ Real my_y = beams[i]->relative_coordinate (common[Y_AXIS], Y_AXIS);
+
+ Interval beam_width (-1.0, -1.0);
+ for (vsize j = 0; j < stems.size (); j++)
+ {
+ Grob *s = stems[j];
+ beam_multiplicity_.push_back (Stem::beam_multiplicity (stems[j]));
+ head_positions_.push_back (Stem::head_positions (stems[j]));
+ is_normal_.push_back (Stem::is_normal_stem (stems[j]));
+
+ Stem_info si (Stem::get_stem_info (s));
+ si.scale (1 / staff_space_);
+ stem_infos_.push_back (si);
+ chord_start_y_.push_back (Stem::chord_start_y (s));
+ dirs_found[si.dir_] = true;
+
+ bool f = to_boolean (s->get_property ("french-beaming"))
+ && s != edge_stems[LEFT] && s != edge_stems[RIGHT];
+
+ Real y = Beam::calc_stem_y (beams[i], s, common, x_pos[LEFT], x_pos[RIGHT], CENTER,
+ Interval (0, 0), f);
+ base_lengths_.push_back (y / staff_space_);
+ stem_xpositions_.push_back (s->relative_coordinate (common[X_AXIS], X_AXIS) - x_pos[LEFT] + x_span_);
+ stem_ypositions_.push_back (s->relative_coordinate (common[Y_AXIS], Y_AXIS) - my_y);
+
+ if (is_normal_.back ())
+ {
+ if (beam_width[LEFT] == -1.0)
+ beam_width[LEFT] = stem_xpositions_.back ();
+ beam_width[RIGHT] = stem_xpositions_.back ();
+ }
+ }
+
+ 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 ();
+ }
+}