From b8f63200f0dde97e6d066e5f1082808e224d9774 Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Thu, 7 Dec 2006 00:16:28 +0200 Subject: [PATCH] make max-slope configurable on skylines --- lily/accidental-placement.cc | 6 +++--- lily/axis-group-interface.cc | 10 ++++++---- lily/include/skyline.hh | 7 +++---- lily/separation-item.cc | 3 ++- lily/skyline.cc | 31 ++++++++++++------------------- lily/system.cc | 5 +++-- lily/tie-formatting-problem.cc | 2 +- scm/define-grob-properties.scm | 1 + 8 files changed, 31 insertions(+), 34 deletions(-) diff --git a/lily/accidental-placement.cc b/lily/accidental-placement.cc index f8245b0cbf..bc091cb6af 100644 --- a/lily/accidental-placement.cc +++ b/lily/accidental-placement.cc @@ -340,8 +340,8 @@ Accidental_placement::calc_positioning_done (SCM smob) ape->extents_.insert (ape->extents_.end (), boxes.begin (), boxes.end ()); } - ape->left_skyline_ = Skyline (ape->extents_, Y_AXIS, LEFT); - ape->right_skyline_ = Skyline (ape->extents_, Y_AXIS, RIGHT); + ape->left_skyline_ = Skyline (ape->extents_, 4, Y_AXIS, LEFT); + ape->right_skyline_ = Skyline (ape->extents_, 4, Y_AXIS, RIGHT); } Interval total; @@ -373,7 +373,7 @@ Accidental_placement::calc_positioning_done (SCM smob) stems[i]->pure_height (common[Y_AXIS], 0, very_large))); } - head_ape->left_skyline_ = Skyline (head_extents, Y_AXIS, LEFT); + head_ape->left_skyline_ = Skyline (head_extents, 4, Y_AXIS, LEFT); head_ape->offset_ = 0.0; Real padding = robust_scm2double (me->get_property ("padding"), 0.2); diff --git a/lily/axis-group-interface.cc b/lily/axis-group-interface.cc index 7edb236e5e..6d7074fe98 100644 --- a/lily/axis-group-interface.cc +++ b/lily/axis-group-interface.cc @@ -293,6 +293,7 @@ Axis_group_interface::skyline_spacing (Grob *me, vector elements) vector_sort (elements, staff_priority_less); Grob *x_common = common_refpoint_of_array (elements, me, X_AXIS); Grob *y_common = common_refpoint_of_array (elements, me, Y_AXIS); + Real max_slope = robust_scm2double (me->get_property ("skyline-max-slope"), 4); vsize i = 0; vector boxes; @@ -301,8 +302,8 @@ Axis_group_interface::skyline_spacing (Grob *me, vector elements) && !scm_is_number (elements[i]->get_property ("outside-staff-priority")); i++) add_boxes (elements[i], x_common, y_common, &boxes); - Drul_array skylines (Skyline (boxes, X_AXIS, DOWN), - Skyline (boxes, X_AXIS, UP)); + Drul_array skylines (Skyline (boxes, max_slope, X_AXIS, DOWN), + Skyline (boxes, max_slope, X_AXIS, UP)); for (; i < elements.size (); i++) { Direction dir = get_grob_direction (elements[i]); @@ -322,7 +323,7 @@ Axis_group_interface::skyline_spacing (Grob *me, vector elements) boxes.clear (); boxes.push_back (b); - Skyline other = Skyline (boxes, X_AXIS, -dir); + Skyline other = Skyline (boxes, max_slope, X_AXIS, -dir); Real padding = robust_scm2double (elements[i]->get_property ("outside-staff-padding"), 0.5); Real dist = skylines[dir].distance (other) + padding; @@ -331,7 +332,7 @@ Axis_group_interface::skyline_spacing (Grob *me, vector elements) b.translate (Offset (0, dir*dist)); elements[i]->translate_axis (dir*dist, Y_AXIS); } - skylines[dir].insert (b, X_AXIS); + skylines[dir].insert (b, max_slope, X_AXIS); } } @@ -344,6 +345,7 @@ ADD_INTERFACE (Axis_group_interface, "elements " "common-refpoint-of-elements " "pure-relevant-elements " + "skyline-max-slope " "skyline-spacing " "cached-pure-extents " ); diff --git a/lily/include/skyline.hh b/lily/include/skyline.hh index be426185f0..de38eae318 100644 --- a/lily/include/skyline.hh +++ b/lily/include/skyline.hh @@ -41,11 +41,10 @@ class Skyline private: list buildings_; Direction sky_; - Real max_slope_; // fixme: not part of skyline per se? void internal_merge_skyline (list*, list*, list *const result); - void internal_build_skyline (list*, + void internal_build_skyline (list*, Real max_slope, list *const result); bool is_legal_skyline () const; @@ -54,11 +53,11 @@ public: Skyline (); Skyline (Skyline const &src); Skyline (Direction sky); - Skyline (vector const &bldgs, Axis a, Direction sky); + Skyline (vector const &bldgs, Real max_slope, Axis a, Direction sky); Skyline (vector const &points, Real max_slope, Direction sky); vector to_points () const; void merge (Skyline const &); - void insert (Box const &, Axis); + void insert (Box const &, Real max_slope, Axis); void print () const; void raise (Real); Real distance (Skyline const &) const; diff --git a/lily/separation-item.cc b/lily/separation-item.cc index 4a7f0f0672..03996bae89 100644 --- a/lily/separation-item.cc +++ b/lily/separation-item.cc @@ -128,7 +128,8 @@ Separation_item::calc_skylines (SCM smob) vector bs = boxes (me); do { - Skyline l (bs, Y_AXIS, d); + /* todo: make skyline max-slope configurable? */ + Skyline l (bs, 2, Y_AXIS, d); index_set_cell (lines, d, l.smobbed_copy ()); } while (flip (&d) != LEFT); diff --git a/lily/skyline.cc b/lily/skyline.cc index 8fdaeedd0c..fd8c1357ef 100644 --- a/lily/skyline.cc +++ b/lily/skyline.cc @@ -228,7 +228,7 @@ single_skyline (Building const &b, list *const ret, Real max_slope) } void -Skyline::internal_build_skyline (list *buildings, list *const result) +Skyline::internal_build_skyline (list *buildings, Real max_slope, list *const result) { vsize size = buildings->size (); @@ -239,7 +239,7 @@ Skyline::internal_build_skyline (list *buildings, list *cons } else if (size == 1) { - single_skyline (buildings->front (), result, max_slope_); + single_skyline (buildings->front (), result, max_slope); return; } @@ -252,23 +252,19 @@ Skyline::internal_build_skyline (list *buildings, list *cons list right; list left; - internal_build_skyline (&right_half, &right); - internal_build_skyline (buildings, &left); + internal_build_skyline (&right_half, max_slope, &right); + internal_build_skyline (buildings, max_slope, &left); internal_merge_skyline (&right, &left, result); } Skyline::Skyline () { - max_slope_ = 2; sky_ = UP; - empty_skyline (&buildings_); - - + empty_skyline (&buildings_); } Skyline::Skyline (Skyline const &src) { - max_slope_ = src.max_slope_; sky_ = src.sky_; for (list::const_iterator i = src.buildings_.begin (); @@ -280,7 +276,6 @@ Skyline::Skyline (Skyline const &src) Skyline::Skyline (Direction sky) { - max_slope_ = 2; sky_ = sky; empty_skyline (&buildings_); } @@ -290,11 +285,10 @@ Skyline::Skyline (Direction sky) Boxes should have fatness in the horizon_axis, otherwise they are ignored. */ -Skyline::Skyline (vector const &boxes, Axis horizon_axis, Direction sky) +Skyline::Skyline (vector const &boxes, Real max_slope, Axis horizon_axis, Direction sky) { list bldgs; sky_ = sky; - max_slope_ = 2; for (vsize i = 0; i < boxes.size (); i++) { @@ -302,23 +296,22 @@ Skyline::Skyline (vector const &boxes, Axis horizon_axis, Direction sky) Real height = sky * boxes[i][other_axis (horizon_axis)][sky]; if (!iv.is_empty () && !isinf (height) && !equal (iv[LEFT], iv[RIGHT])) bldgs.push_front (Building (iv[LEFT], height, height, iv[RIGHT], - max_slope_)); + max_slope)); } - internal_build_skyline (&bldgs, &buildings_); + internal_build_skyline (&bldgs, max_slope, &buildings_); assert (is_legal_skyline ()); } Skyline::Skyline (vector const &points, Real max_slope, Direction sky) { sky_ = sky; - max_slope_ = max_slope; for (vsize i = 1; i < points.size (); i++) { - buildings_.push_back (Building (points[i-1][X_AXIS], sky * points[i-1][Y_AXIS], + buildings_.push_back (Building (points[i-1][X_AXIS], + sky * points[i-1][Y_AXIS], sky * points[i][Y_AXIS], - points[i][X_AXIS], max_slope)); @@ -340,7 +333,7 @@ Skyline::merge (Skyline const &other) } void -Skyline::insert (Box const &b, Axis a) +Skyline::insert (Box const &b, Real max_slope, Axis a) { list other_bld; list my_bld; @@ -350,7 +343,7 @@ Skyline::insert (Box const &b, Axis a) assert (!iv.is_empty ()); my_bld.splice (my_bld.begin (), buildings_); - single_skyline (Building (iv[LEFT], height, height, iv[RIGHT], max_slope_), &other_bld, max_slope_); + single_skyline (Building (iv[LEFT], height, height, iv[RIGHT], max_slope), &other_bld, max_slope); internal_merge_skyline (&other_bld, &my_bld, &buildings_); assert (is_legal_skyline ()); } diff --git a/lily/system.cc b/lily/system.cc index c53099257f..b8557a6f04 100644 --- a/lily/system.cc +++ b/lily/system.cc @@ -531,8 +531,9 @@ System::build_skylines () boxes.push_back (Box (xiv, yiv)); } - skylines_[UP] = Skyline (boxes, X_AXIS, UP); - skylines_[DOWN] = Skyline (boxes, X_AXIS, DOWN); + /* todo: make skyline slope configurable? */ + skylines_[UP] = Skyline (boxes, 2, X_AXIS, UP); + skylines_[DOWN] = Skyline (boxes, 2, X_AXIS, DOWN); } diff --git a/lily/tie-formatting-problem.cc b/lily/tie-formatting-problem.cc index 9f05c5b807..60d9e1bc11 100644 --- a/lily/tie-formatting-problem.cc +++ b/lily/tie-formatting-problem.cc @@ -175,7 +175,7 @@ Tie_formatting_problem::set_column_chord_outline (vector bounds, } while (flip (&updowndir) != DOWN); - chord_outlines_[key] = Skyline (boxes, Y_AXIS, -dir); + chord_outlines_[key] = Skyline (boxes, 4, Y_AXIS, -dir); if (bounds[0]->break_status_dir ()) { Real x = robust_relative_extent (bounds[0], x_refpoint_, X_AXIS)[-dir]; diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index 0081da0636..25861affa5 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -556,6 +556,7 @@ than a whole rest.") (spaceable-staves ,ly:grob-array? "Objects to be spaced during page layout.") (skyline-distance ,number? "The distance between this staff and the next one, as determined by a skyline algorithm.") + (skyline-max-slope ,number? "The maximum slope of buildings in the skyline used in skyline-spacing. If this is small, grobs will be placed away from the staff is there is another grob within a short horizontal distance (even if there would be no collision). If this is large (100, say), grobs will be placed close to the staff even if it means packing them in tightly horizontally.") (skyline-spacing ,boolean? "When true, this axis-group will vertically space its children using a skyline algorithm.") -- 2.39.2