X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fskyline.cc;h=6b53a62ef845174c290f8ea02462afb156392e1a;hb=9e69cb84d6ee5b0a861cd97869b10e3bdf0c833c;hp=ab877f28ce605fcb4854984c049885007007c47d;hpb=205c82276abb41482193e8e965e08bc8d0ff87f6;p=lilypond.git diff --git a/lily/skyline.cc b/lily/skyline.cc index ab877f28ce..6b53a62ef8 100644 --- a/lily/skyline.cc +++ b/lily/skyline.cc @@ -111,6 +111,19 @@ Building::Building (Real start, Real start_height, Real end_height, Real end) precompute (); } +Building::Building (Box const &b, Real horizon_padding, Axis horizon_axis, Direction sky) +{ + Real height = sky * b[other_axis (horizon_axis)][sky]; + + iv_ = b[horizon_axis]; + iv_.widen (horizon_padding + EPS); + height_[LEFT] = height; + height_[RIGHT] = height; + + if (sane ()) + precompute (); +} + void Building::precompute () { @@ -174,6 +187,14 @@ Building::sloped_neighbour (Real horizon_padding, Direction d) const return Building (left, left_height, right_height, right); } +bool +Building::sane () const +{ + return approx_less_than (iv_[LEFT], iv_[RIGHT]) + && !isinf (height_[RIGHT]) + && !isinf (height_[LEFT]); +} + static void skyline_trailing_part (list *sky, Real x) { @@ -341,14 +362,9 @@ Skyline::Skyline (vector const &boxes, Real horizon_padding, Axis horizon_a for (vsize i = 0; i < boxes.size (); i++) { - 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])) + Building front (boxes[i], horizon_padding, horizon_axis, sky); + if (front.sane ()) { - iv.widen (EPS); - Building front = Building (iv[LEFT], height, height, iv[RIGHT]); bldgs.push_front (front); if (horizon_padding > 0 && !isinf (front.iv_.length ())) { @@ -362,6 +378,13 @@ Skyline::Skyline (vector const &boxes, Real horizon_padding, Axis horizon_a assert (is_legal_skyline ()); } +Skyline::Skyline (Box const &b, Real horizon_padding, Axis horizon_axis, Direction sky) +{ + sky_ = sky; + Building front (b, 0, horizon_axis, sky); + single_skyline (front, horizon_padding, &buildings_); +} + void Skyline::merge (Skyline const &other) { @@ -379,14 +402,9 @@ Skyline::insert (Box const &b, Real horizon_padding, Axis a) { list other_bld; list my_bld; - Interval iv = b[a]; - Real height = sky_ * b[other_axis (a)][sky_]; - - assert (!iv.is_empty ()); - iv.widen (EPS); my_bld.splice (my_bld.begin (), buildings_); - single_skyline (Building (iv[LEFT], height, height, iv[RIGHT]), horizon_padding, &other_bld); + single_skyline (Building (b, 0, a, sky_), horizon_padding, &other_bld); internal_merge_skyline (&other_bld, &my_bld, &buildings_); assert (is_legal_skyline ()); } @@ -404,6 +422,17 @@ Skyline::raise (Real r) assert (is_legal_skyline ()); } +void +Skyline::shift (Real r) +{ + list::iterator end = buildings_.end (); + for (list::iterator i = buildings_.begin (); i != end; i++) + { + i->iv_[LEFT] += r; + i->iv_[RIGHT] += r; + } +} + Real Skyline::distance (Skyline const &other) const { @@ -476,6 +505,61 @@ Skyline::to_points () const return out; } +Skyline_pair::Skyline_pair () + : skylines_ (Skyline (DOWN), Skyline (UP)) +{ +} + +Skyline_pair::Skyline_pair (vector const &boxes, Real padding, Axis a) + : skylines_ (Skyline (boxes, padding, a, DOWN), Skyline (boxes, padding, a, UP)) +{ +} + +Skyline_pair::Skyline_pair (Box const &b, Real padding, Axis a) + : skylines_ (Skyline (b, padding, a, DOWN), Skyline (b, padding, a, UP)) +{ +} + +void +Skyline_pair::raise (Real r) +{ + skylines_[UP].raise (r); + skylines_[DOWN].raise (r); +} + +void +Skyline_pair::shift (Real r) +{ + skylines_[UP].shift (r); + skylines_[DOWN].shift (r); +} + +void +Skyline_pair::insert (Box const &b, Real padding, Axis a) +{ + skylines_[UP].insert (b, padding, a); + skylines_[DOWN].insert (b, padding, a); +} + +void +Skyline_pair::merge (Skyline_pair const &other) +{ + skylines_[UP].merge (other[UP]); + skylines_[DOWN].merge (other[DOWN]); +} + +Skyline& +Skyline_pair::operator [] (Direction d) +{ + return skylines_[d]; +} + +Skyline const& +Skyline_pair::operator [] (Direction d) const +{ + return skylines_[d]; +} + /****************************************************************/ @@ -483,6 +567,10 @@ IMPLEMENT_SIMPLE_SMOBS (Skyline); IMPLEMENT_TYPE_P (Skyline, "ly:skyline?"); IMPLEMENT_DEFAULT_EQUAL_P (Skyline); +IMPLEMENT_SIMPLE_SMOBS (Skyline_pair); +IMPLEMENT_TYPE_P (Skyline_pair, "ly:skyline-pair?"); +IMPLEMENT_DEFAULT_EQUAL_P (Skyline_pair); + SCM Skyline::mark_smob (SCM) { @@ -499,3 +587,19 @@ Skyline::print_smob (SCM s, SCM port, scm_print_state *) return 1; } + +SCM +Skyline_pair::mark_smob (SCM) +{ + return SCM_EOL; +} + +int +Skyline_pair::print_smob (SCM s, SCM port, scm_print_state *) +{ + Skyline_pair *r = (Skyline_pair *) SCM_CELL_WORD_1 (s); + (void) r; + + scm_puts ("#", port); + return 1; +}