X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fskyline.cc;h=608155ea3d26cfa1ef6ff3c605e443463cf8c306;hb=11d5b22d4eb69696b43e576db3d16793dd166d93;hp=de6f7d078bb706dfd35a3b1d4b71b501b41d8797;hpb=f6bd48526091ebf836ce8cbf89b83593b1549736;p=lilypond.git diff --git a/lily/skyline.cc b/lily/skyline.cc index de6f7d078b..608155ea3d 100644 --- a/lily/skyline.cc +++ b/lily/skyline.cc @@ -1,12 +1,25 @@ -/* skyline.cc -- implement the Skyline class +/* + This file is part of LilyPond, the GNU music typesetter. + + Copyright (C) 2006--2011 Joe Neeman + + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - source file of the GNU LilyPond music typesetter - - (c) 2006--2007 Joe Neeman + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ #include "skyline.hh" #include +#include #include "ly-smobs.icc" @@ -106,7 +119,7 @@ Building::precompute (Real start, Real start_height, Real end_height, Real end) y_intercept_ = start_height - slope_ * start; } -Real +Real Building::height (Real x) const { return isinf (x) ? y_intercept_ : slope_*x + y_intercept_; @@ -235,7 +248,7 @@ single_skyline (Building b, Real start, Real horizon_padding, list *co -infinity_f, infinity_f)); if (sloped_neighbours) ret->push_front (b.sloped_neighbour (start, horizon_padding, RIGHT)); - + if (b.end_ > start + EPS) ret->push_front (b); @@ -266,7 +279,7 @@ non_overlapping_skyline (list *const boxes, Real horizon_padding, Axis hori } if (iv[LEFT] - horizon_padding > last_end + EPS) - result.push_front (Building (last_end, -infinity_f, -infinity_f, iv[LEFT] - horizon_padding)); + result.push_front (Building (last_end, -infinity_f, -infinity_f, iv[LEFT] - 2*horizon_padding)); Building b (*i, horizon_padding, horizon_axis, sky); bool sloped_neighbours = horizon_padding > 0 && !isinf (iv.length ()); @@ -317,7 +330,7 @@ Skyline::internal_build_skyline (list *boxes, Real horizon_padding, Axis ho { list result; single_skyline (Building (boxes->front (), horizon_padding, horizon_axis, sky), - boxes->front ()[horizon_axis][LEFT], horizon_axis, &result); + boxes->front ()[horizon_axis][LEFT], horizon_padding, &result); return result; } @@ -354,7 +367,7 @@ Skyline::Skyline () Skyline::Skyline (Skyline const &src) { sky_ = src.sky_; - + /* doesn't a list's copy constructor do this? -- jneem */ for (list::const_iterator i = src.buildings_.begin (); i != src.buildings_.end (); i++) @@ -369,6 +382,37 @@ Skyline::Skyline (Direction sky) empty_skyline (&buildings_); } +/* + build padded skyline from an existing skyline with padding + added to it. +*/ + +Skyline::Skyline (Skyline const &src, Real horizon_padding, Axis a) +{ + /* + We extract boxes from the skyline, then build a new skyline from + the boxes. + A box is created for every horizontal portion of the skyline + Because skylines are defined positive, and then inverted if they + are to be down-facing, we create the new skyline in the UP + direction, then give it the down direction if needed. + */ + Real start = -infinity_f; + list boxes; + + // establish a baseline box + boxes.push_back (Box (Interval (-infinity_f, infinity_f), + Interval (0, 0))); + list::const_iterator end = src.buildings_.end (); + for (list::const_iterator i = src.buildings_.begin (); i != end; start=i->end_, i++ ) + if ((i->slope_ == 0) && !isinf (i->y_intercept_)) + boxes.push_back (Box (Interval (start, i->end_), + Interval (-infinity_f , i->y_intercept_))); + buildings_ = internal_build_skyline (&boxes, horizon_padding, X_AXIS, UP); + sky_ = src.sky_; +} + + /* 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 @@ -391,7 +435,7 @@ Skyline::Skyline (vector const &boxes, Real horizon_padding, Axis horizon_a if (iv.length () > EPS && !boxes[i][vert_axis].is_empty ()) filtered_boxes.push_front (boxes[i]); } - + buildings_ = internal_build_skyline (&filtered_boxes, horizon_padding, horizon_axis, sky); } @@ -419,6 +463,13 @@ Skyline::insert (Box const &b, Real horizon_padding, Axis a) list other_bld; list my_bld; + if (isnan (b[other_axis (a)][LEFT]) + || isnan (b[other_axis (a)][RIGHT])) + { + programming_error ("insane box for skyline"); + return; + } + /* do the same filtering as in Skyline (vector const&, etc.) */ Interval iv = b[a]; iv.widen (horizon_padding); @@ -450,15 +501,31 @@ Skyline::shift (Real s) } Real -Skyline::distance (Skyline const &other) const +Skyline::distance (Skyline const &other, Real horizon_padding) const { assert (sky_ == -other.sky_); - list::const_iterator i = buildings_.begin (); - list::const_iterator j = other.buildings_.begin (); + + Skyline const *padded_this = this; + Skyline const *padded_other = &other; + + /* + For systems, padding is not added at creation time. Padding is + added to AxisGroup objects when outside-staff objects are added. + Thus, when we want to place systems with horizontal padding, + we do it at distance calculation time. + */ + if (horizon_padding != 0.0) + { + padded_this = new Skyline (*padded_this, horizon_padding, X_AXIS); + padded_other = new Skyline (*padded_other, horizon_padding, X_AXIS); + } + + list::const_iterator i = padded_this->buildings_.begin (); + list::const_iterator j = padded_other->buildings_.begin (); Real dist = -infinity_f; Real start = -infinity_f; - while (i != buildings_.end () && j != other.buildings_.end ()) + while (i != padded_this->buildings_.end () && j != padded_other->buildings_.end ()) { Real end = min (i->end_, j->end_); Real start_dist = i->height (start) + j->height (start); @@ -534,66 +601,11 @@ Skyline::is_empty () const return b.end_ == infinity_f && b.y_intercept_ == -infinity_f; } -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) +Skyline::clear () { - 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]); -} - -bool -Skyline_pair::is_empty () const -{ - return skylines_[UP].is_empty () - && skylines_[DOWN].is_empty (); -} - -Skyline& -Skyline_pair::operator [] (Direction d) -{ - return skylines_[d]; -} - -Skyline const& -Skyline_pair::operator [] (Direction d) const -{ - return skylines_[d]; + buildings_.clear (); + empty_skyline (&buildings_); } /****************************************************************/ @@ -603,10 +615,6 @@ 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) { @@ -624,19 +632,3 @@ 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; -}