From 31eac32495c21fc614bdd883dbcc2729de03027f Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Tue, 12 Dec 2006 16:48:19 +0200 Subject: [PATCH] add horizon_padding to skylines (although it is currently always 0) --- lily/accidental-placement.cc | 6 +-- lily/axis-group-interface.cc | 8 ++-- lily/include/skyline.hh | 6 +-- lily/separation-item.cc | 2 +- lily/skyline.cc | 78 ++++++++++++++++++++-------------- lily/system.cc | 4 +- lily/tie-formatting-problem.cc | 2 +- 7 files changed, 61 insertions(+), 45 deletions(-) diff --git a/lily/accidental-placement.cc b/lily/accidental-placement.cc index f8245b0cbf..f6bfefff5d 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_, 0, Y_AXIS, LEFT); + ape->right_skyline_ = Skyline (ape->extents_, 0, 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, 0, 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..44293f6d54 100644 --- a/lily/axis-group-interface.cc +++ b/lily/axis-group-interface.cc @@ -301,8 +301,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, 0, X_AXIS, DOWN), + Skyline (boxes, 0, X_AXIS, UP)); for (; i < elements.size (); i++) { Direction dir = get_grob_direction (elements[i]); @@ -322,7 +322,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, 0, 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 +331,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, 0, X_AXIS); } } diff --git a/lily/include/skyline.hh b/lily/include/skyline.hh index 464bd58004..7f3130ecab 100644 --- a/lily/include/skyline.hh +++ b/lily/include/skyline.hh @@ -35,6 +35,7 @@ struct Building void leading_part (Real chop); bool conceals_beginning (Building const &other) const; bool conceals (Building const &other) const; + Building sloped_neighbour (Real horizon_padding, Direction d) const; }; class Skyline @@ -53,11 +54,10 @@ public: Skyline (); Skyline (Skyline const &src); Skyline (Direction sky); - Skyline (vector const &bldgs, Axis a, Direction sky); - Skyline (vector const &points, Direction sky); + Skyline (vector const &bldgs, Real horizon_padding, Axis a, Direction sky); vector to_points () const; void merge (Skyline const &); - void insert (Box const &, Axis); + void insert (Box const &, Real horizon_padding, 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 a53917f8b2..a07668d13b 100644 --- a/lily/separation-item.cc +++ b/lily/separation-item.cc @@ -128,7 +128,7 @@ Separation_item::calc_skylines (SCM smob) vector bs = boxes (me); do { - Skyline l (bs, Y_AXIS, d); + Skyline l (bs, 0, 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 fa028562aa..6c3caab69e 100644 --- a/lily/skyline.cc +++ b/lily/skyline.cc @@ -159,6 +159,21 @@ Building::leading_part (Real chop) height_[RIGHT] = height (chop); } +Building +Building::sloped_neighbour (Real horizon_padding, Direction d) const +{ + Real left = iv_[d]; + Real right = iv_[d] + d * horizon_padding; + Real left_height = height_[d]; + Real right_height = height_[d] - horizon_padding; + if (d == LEFT) + { + swap (left, right); + swap (left_height, right_height); + } + return Building (left, left_height, right_height, right); +} + static void skyline_trailing_part (list *sky, Real x) { @@ -237,13 +252,21 @@ empty_skyline (list *const ret) } static void -single_skyline (Building const &b, list *const ret) +single_skyline (Building b, Real horizon_padding, list *const ret) { + b.iv_.widen (horizon_padding); + if (!isinf (b.iv_[RIGHT])) ret->push_front (Building (b.iv_[RIGHT], -infinity_f, -infinity_f, infinity_f)); + if (horizon_padding > 0) + ret->push_front (b.sloped_neighbour (horizon_padding, RIGHT)); + if (b.iv_[RIGHT] > b.iv_[LEFT]) ret->push_front (b); + + if (horizon_padding > 0) + ret->push_front (b.sloped_neighbour (horizon_padding, LEFT)); if (!isinf (b.iv_[LEFT])) ret->push_front (Building (-infinity_f, -infinity_f, -infinity_f, b.iv_[LEFT])); @@ -261,7 +284,7 @@ Skyline::internal_build_skyline (list *buildings, list *cons } else if (size == 1) { - single_skyline (buildings->front (), result); + single_skyline (buildings->front (), 0, result); return; } @@ -303,11 +326,15 @@ Skyline::Skyline (Direction sky) } /* - build skyline from a set of boxes. + build skyline from a set of boxes. If horizon_padding > 0, expand all the boxes + by that amount and add 45-degree sloped boxes to the edges of each box (of + width horizon_padding). That is, the total amount of horizontal expansion is + horizon_padding*4, half of which is sloped and half of which is flat. - Boxes should have fatness in the horizon_axis, otherwise they are ignored. + Boxes should have fatness in the horizon_axis (after they are expanded by + horizon_padding), otherwise they are ignored. */ -Skyline::Skyline (vector const &boxes, Axis horizon_axis, Direction sky) +Skyline::Skyline (vector const &boxes, Real horizon_padding, Axis horizon_axis, Direction sky) { list bldgs; sky_ = sky; @@ -316,10 +343,18 @@ Skyline::Skyline (vector const &boxes, Axis horizon_axis, Direction sky) { Interval iv = boxes[i][horizon_axis]; Real height = sky * boxes[i][other_axis (horizon_axis)][sky]; + + iv.widen (horizon_padding); if (!iv.is_empty () && !isinf (height) && !approx_equal (iv[LEFT], iv[RIGHT])) { iv.widen (EPS); - bldgs.push_front (Building (iv[LEFT], height, height, iv[RIGHT])); + Building front = Building (iv[LEFT], height, height, iv[RIGHT]); + bldgs.push_front (front); + if (horizon_padding > 0) + { + bldgs.push_front (front.sloped_neighbour (horizon_padding, LEFT)); + bldgs.push_front (front.sloped_neighbour (horizon_padding, RIGHT)); + } } } @@ -327,22 +362,6 @@ Skyline::Skyline (vector const &boxes, Axis horizon_axis, Direction sky) assert (is_legal_skyline ()); } -Skyline::Skyline (vector const &points, Direction sky) -{ - sky_ = sky; - - for (vsize i = 1; i < points.size (); i++) - { - buildings_.push_back (Building (points[i-1][X_AXIS], - sky * points[i-1][Y_AXIS], - sky * points[i][Y_AXIS], - points[i][X_AXIS])); - - } - - assert (is_legal_skyline ()); -} - void Skyline::merge (Skyline const &other) { @@ -356,7 +375,7 @@ Skyline::merge (Skyline const &other) } void -Skyline::insert (Box const &b, Axis a) +Skyline::insert (Box const &b, Real horizon_padding, Axis a) { list other_bld; list my_bld; @@ -367,7 +386,7 @@ Skyline::insert (Box const &b, Axis a) iv.widen (EPS); my_bld.splice (my_bld.begin (), buildings_); - single_skyline (Building (iv[LEFT], height, height, iv[RIGHT]), &other_bld); + single_skyline (Building (iv[LEFT], height, height, iv[RIGHT]), horizon_padding, &other_bld); internal_merge_skyline (&other_bld, &my_bld, &buildings_); assert (is_legal_skyline ()); } @@ -446,17 +465,14 @@ Skyline::to_points () const { vector out; - bool first = true; for (list::const_iterator i (buildings_.begin ()); i != buildings_.end (); i++) { - if (first) - out.push_back (Offset ((*i).iv_[LEFT], sky_ * (*i).height_[LEFT])); - - first = false; - out.push_back (Offset ((*i).iv_[RIGHT], sky_ * (*i).height_[RIGHT])); + if (!isinf (i->iv_[LEFT]) && !isinf (i->height_[LEFT])) + out.push_back (Offset (i->iv_[LEFT], sky_ * i->height_[LEFT])); + if (!isinf (i->iv_[RIGHT]) && !isinf (i->height_[RIGHT])) + out.push_back (Offset (i->iv_[RIGHT], sky_ * i->height_[RIGHT])); } - return out; } diff --git a/lily/system.cc b/lily/system.cc index c4aaca306a..8f375a8db8 100644 --- a/lily/system.cc +++ b/lily/system.cc @@ -532,8 +532,8 @@ System::build_skylines () boxes.push_back (Box (xiv, yiv)); } - skylines_[UP] = Skyline (boxes, X_AXIS, UP); - skylines_[DOWN] = Skyline (boxes, X_AXIS, DOWN); + skylines_[UP] = Skyline (boxes, 0, X_AXIS, UP); + skylines_[DOWN] = Skyline (boxes, 0, X_AXIS, DOWN); } diff --git a/lily/tie-formatting-problem.cc b/lily/tie-formatting-problem.cc index 9f05c5b807..3937c5194e 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, 0, Y_AXIS, -dir); if (bounds[0]->break_status_dir ()) { Real x = robust_relative_extent (bounds[0], x_refpoint_, X_AXIS)[-dir]; -- 2.39.2