+ Real o = scm_to_double (general_side_position (me, a, true, true, pure, start, end, current_off));
+
+ /*
+ Maintain a minimum distance to the staff. This is similar to side
+ position with padding, but it will put adjoining objects on a row if
+ stuff sticks out of the staff a little.
+ */
+ Grob *staff = Staff_symbol_referencer::get_staff_symbol (me);
+ if (staff && a == Y_AXIS)
+ {
+ if (to_boolean (me->get_property ("quantize-position")))
+ {
+ Grob *common = me->common_refpoint (staff, Y_AXIS);
+ Real my_off = me->get_parent (Y_AXIS)->maybe_pure_coordinate (common, Y_AXIS, pure, start, end);
+ Real staff_off = staff->maybe_pure_coordinate (common, Y_AXIS, pure, start, end);
+ Real ss = Staff_symbol::staff_space (staff);
+ Real position = 2 * (my_off + o - staff_off) / ss;
+ Real rounded = directed_round (position, dir);
+ Grob *head = me->get_parent (X_AXIS);
+
+ if (fabs (position) <= 2 * Staff_symbol_referencer::staff_radius (me) + 1
+ /* In case of a ledger lines, quantize even if we're outside the staff. */
+ || (Note_head::has_interface (head)
+
+ && abs (Staff_symbol_referencer::get_position (head)) > abs (position)))
+ {
+ o += (rounded - position) * 0.5 * ss;
+ if (Staff_symbol_referencer::on_line (me, int (rounded)))
+ o += dir * 0.5 * ss;
+ }
+ }
+ else if (scm_is_number (me->get_property ("staff-padding")) && dir)
+ {
+ Interval iv = me->maybe_pure_extent (me, a, pure, start, end);
+
+ Real padding
+ = Staff_symbol_referencer::staff_space (me)
+ * scm_to_double (me->get_property ("staff-padding"));
+
+ Grob *common = me->common_refpoint (staff, Y_AXIS);
+
+ Interval staff_size = staff->maybe_pure_extent (common, Y_AXIS, pure, start, end);
+ Real diff = dir*staff_size[dir] + padding - dir * (o + iv[-dir]);
+ o += dir * max (diff, 0.0);
+ }
+ }
+ return scm_from_double (o);