X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=lily%2Fskyline.cc;h=0250fc07f4743ba44e7bc1ac8af23ed6057aa435;hb=0d13da15da86d830bc2ae00da6cfc38b99653d6d;hp=d508450cba3c80e3b94e361ee06a91628e2f3689;hpb=e28484ea68c8cbcdaa5edfe7211b11f0d1779ff9;p=lilypond.git diff --git a/lily/skyline.cc b/lily/skyline.cc index d508450cba..0250fc07f4 100644 --- a/lily/skyline.cc +++ b/lily/skyline.cc @@ -1,21 +1,37 @@ -/* skyline.cc -- implement the Skyline class +/* + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter - - (c) 2006 Joe Neeman + Copyright (C) 2006--2012 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. + + 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" /* A skyline is a sequence of non-overlapping buildings: something like this: - _________ - | | ________ - | | _________| | - /| | \ | | - / |------- \ | | - / \ | | - / --------------- ------- + _______ + | \ ________ + | \ ________/ \ + /\ | \ / \ + / -------- \ / \ + / \ / \ + / ------------/ ---- -- Each building has a starting position, and ending position, a starting height and an ending height. @@ -39,171 +55,180 @@ but the distance routine does. */ -#define EPS 1e-10 +/* If we start including very thin buildings, numerical accuracy errors can + arise. Therefore, we ignore all buildings that are less than epsilon wide. */ +#define EPS 1e-5 -static inline bool -equal (Real x, Real y) +static void +print_buildings (list const &b) { - return abs (x - y) < EPS || (isinf (x) && isinf (y) && ((x > 0) == (y > 0))); + for (list::const_iterator i = b.begin (); i != b.end (); i++) + i->print (); } -bool -Skyline::is_legal_skyline () const +void +Skyline::print () const { - list::const_iterator i; - Real last_x = -infinity_f; - for (i = buildings_.begin (); i != buildings_.end (); i++) - { - if (isinf (i->start_height_) != isinf (i->end_height_)) - return false; - if (i->iv_[LEFT] != last_x) - return false; - if (isinf (i->iv_.length ()) && i->start_height_ != i->end_height_) - return false; - last_x = i->iv_[RIGHT]; - } - return last_x == infinity_f; + print_buildings (buildings_); +} + +void +Skyline::print_points () const +{ + vector ps (to_points (X_AXIS)); + + for (vsize i = 0; i < ps.size (); i++) + printf ("(%f,%f)%s", ps[i][X_AXIS], ps[i][Y_AXIS], + (i % 2) == 1 ? "\n" : " "); } Building::Building (Real start, Real start_height, Real end_height, Real end) - : iv_ (start, end) { - start_height_ = start_height; - end_height_ = end_height; + if (isinf (start) || isinf (end)) + assert (start_height == end_height); + + end_ = end; + precompute (start, start_height, end_height, end); +} + +Building::Building (Box const &b, Real horizon_padding, Axis horizon_axis, Direction sky) +{ + Real start = b[horizon_axis][LEFT] - horizon_padding; + Real end = b[horizon_axis][RIGHT] + horizon_padding; + Real height = sky * b[other_axis (horizon_axis)][sky]; + + end_ = end; + precompute (start, height, height, end); +} - if (isinf (start_height) || isinf (start) || isinf (end)) - end_height_ = start_height; - else if (isinf (end_height)) - start_height_ = end_height; +void +Building::precompute (Real start, Real start_height, Real end_height, Real end) +{ + slope_ = (end_height - start_height) / (end - start); + if (start_height == end_height) /* if they were both infinite, we would get nan, not 0, from the prev line */ + slope_ = 0; - m_ = (end_height - start_height) / (end - start); - b_ = start_height - m_*start; + assert (!isinf (slope_) && !isnan (slope_)); - if (isinf (start_height) || isinf (start) || isinf (end)) + if (isinf (start)) { - m_ = 0; - b_ = start_height; + assert (start_height == end_height); + y_intercept_ = start_height; } + else + y_intercept_ = start_height - slope_ * start; } -Real +Real Building::height (Real x) const { - if (isinf (x)) - return start_height_; - return m_*x + b_; + return isinf (x) ? y_intercept_ : slope_ * x + y_intercept_; +} + +void +Building::print () const +{ + printf ("%f x + %f ends at %f\n", slope_, y_intercept_, end_); } Real -Building::intersection (Building const &other) const +Building::intersection_x (Building const &other) const { - return (b_ - other.b_) / (other.m_ - m_); + Real ret = (y_intercept_ - other.y_intercept_) / (other.slope_ - slope_); + return isnan (ret) ? -infinity_f : ret; } void Building::leading_part (Real chop) { - assert (chop > iv_[LEFT] && chop <= iv_[RIGHT] && !equal (chop, iv_[LEFT])); - iv_[RIGHT] = chop; - end_height_ = height (chop); + assert (chop <= end_); + end_ = chop; } -static void -skyline_trailing_part (list *sky, Real x) +Building +Building::sloped_neighbour (Real start, Real horizon_padding, Direction d) const { - if (equal (x, sky->front ().iv_[RIGHT])) - sky->pop_front (); - else - assert (x < sky->front ().iv_[RIGHT]); - - if (!sky->empty ()) + Real x = (d == LEFT) ? start : end_; + Real left = x; + Real right = x + d * horizon_padding; + Real left_height = height (x); + Real right_height = left_height - horizon_padding; + if (d == LEFT) { - sky->front ().iv_[LEFT] = x; - sky->front ().start_height_ = sky->front ().height (x); + swap (left, right); + swap (left_height, right_height); } + return Building (left, left_height, right_height, right); } -bool -Building::obstructs (Building const &other) const +static Real +first_intersection (Building const &b, list *const s, Real start_x) { - if (equal (intersection (other), iv_[LEFT]) || equal (start_height_, other.start_height_)) - return m_ > other.m_; - return start_height_ > other.start_height_; -} + while (!s->empty () && start_x < b.end_) + { + Building c = s->front (); + if (c.conceals (b, start_x)) + return start_x; + Real i = b.intersection_x (c); + if (i > start_x && i <= b.end_ && i <= c.end_) + return i; -/* precondition: the building should be visible above the first - building in skyline. The building and the skyline should - start at the same point. + start_x = c.end_; + if (b.end_ > c.end_) + s->pop_front (); + } + return b.end_; +} - return the point at which the building b is no longer visible, - either because it has ended or because the skyline has risen - above it. Truncate the skyline at that point. -*/ -Real -Skyline::last_visible_point (Building const &b, list *const skyline) +bool +Building::conceals (Building const &other, Real x) const { - assert (!skyline->front ().obstructs (b)); - while (1) - { - Building other = skyline->front (); - - /* there are 3 interesting cases: - 1) the roofs intersect within the spans of the buildings */ - Real intersect = b.intersection (other); - if (intersection (b.iv_, other.iv_).contains (intersect)) - { - if (equal (intersect, b.iv_[LEFT])) - { - /* if the buildings have almost the same starting height, we can find - that their intersection "equals" the start point. In this case, we - just skip the intersection. - */ - assert (b.m_ >= other.m_); - } - else - { - skyline_trailing_part (skyline, intersect); - return intersect; - } - } - - /* 2) the first building ends. This is guaranteed to happen before - the skyline becomes empty because it has to end at infinity */ - if (skyline->empty () && !other.iv_.contains (b.iv_[RIGHT])) - assert (0); - if (other.iv_.contains (b.iv_[RIGHT])) - { - skyline_trailing_part (skyline, b.iv_[RIGHT]); - return b.iv_[RIGHT]; - } - - assert (!skyline->empty ()); - skyline->pop_front (); - other = skyline->front (); - - /* 3) the next building in the skyline starts above b */ - if (other.start_height_ > b.height (other.iv_[LEFT])) - return other.iv_[LEFT]; - } + if (slope_ == other.slope_) + return y_intercept_ > other.y_intercept_; + + /* their slopes were not equal, so there is an intersection point */ + Real i = intersection_x (other); + return (i <= x && slope_ > other.slope_) + || (i > x && slope_ < other.slope_); } void Skyline::internal_merge_skyline (list *s1, list *s2, - list *const result) + list *const result) { + if (s1->empty () || s2->empty ()) + { + programming_error ("tried to merge an empty skyline"); + return; + } + + Real x = -infinity_f; while (!s1->empty ()) { - if (s2->front ().obstructs (s1->front ())) - swap (s1, s2); + if (s2->front ().conceals (s1->front (), x)) + swap (s1, s2); Building b = s1->front (); - Real end = last_visible_point (b, s2); + Real end = first_intersection (b, s2, x); - b.leading_part (end); - result->push_front (b); + if (s2->empty ()) + { + result->push_front (b); + break; + } - skyline_trailing_part (s1, end); + /* only include buildings wider than epsilon */ + if (end > x + EPS) + { + b.leading_part (end); + result->push_front (b); + } + + if (end >= s1->front ().end_) + s1->pop_front (); + + x = end; } result->reverse (); } @@ -214,44 +239,128 @@ empty_skyline (list *const ret) ret->push_front (Building (-infinity_f, -infinity_f, -infinity_f, infinity_f)); } +/* + Given Building 'b' with starting wall location 'start', extend each side + with a sloped roofline of width 'horizon_padding'; put the skyline in 'ret' +*/ static void -single_skyline (Building const &b, list *const ret) +single_skyline (Building b, Real start, Real horizon_padding, list *const ret) { - if (!isinf (b.iv_[RIGHT])) - ret->push_front (Building (b.iv_[RIGHT], -infinity_f, -infinity_f, infinity_f)); - ret->push_front (b); - if (!isinf (b.iv_[LEFT])) - ret->push_front (Building (-infinity_f, -infinity_f, -infinity_f, b.iv_[LEFT])); + bool sloped_neighbours = horizon_padding > 0 && !isinf (start) && !isinf (b.end_); + if (!isinf (b.end_)) + ret->push_front (Building (b.end_ + horizon_padding, -infinity_f, + -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); + + if (sloped_neighbours) + ret->push_front (b.sloped_neighbour (start, horizon_padding, LEFT)); + + if (!isinf (start)) + ret->push_front (Building (-infinity_f, -infinity_f, + -infinity_f, start - horizon_padding)); } -void -Skyline::internal_build_skyline (list *buildings, list *const result) +/* remove a non-overlapping set of boxes from BOXES and build a skyline + out of them */ +static list +non_overlapping_skyline (list *const boxes, Real horizon_padding, Axis horizon_axis, Direction sky) { - vsize size = buildings->size (); + list result; + Real last_end = -infinity_f; + list::iterator i = boxes->begin (); + while (i != boxes->end ()) + { + Interval iv = (*i)[horizon_axis]; + + if (iv[LEFT] - horizon_padding < last_end) + { + i++; + continue; + } + + if (iv[LEFT] - horizon_padding > last_end + EPS) + 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 ()); + if (sloped_neighbours) + result.push_front (b.sloped_neighbour (iv[LEFT] - horizon_padding, horizon_padding, LEFT)); + result.push_front (b); + if (sloped_neighbours) + result.push_front (b.sloped_neighbour (iv[LEFT] - horizon_padding, horizon_padding, RIGHT)); + + list::iterator j = i++; + boxes->erase (j); + last_end = result.front ().end_; + } + if (last_end < infinity_f) + result.push_front (Building (last_end, -infinity_f, -infinity_f, infinity_f)); + result.reverse (); + return result; +} + +class LessThanBox +{ + Axis a_; + +public: + LessThanBox (Axis a) + { + a_ = a; + } + + bool operator () (Box const &b1, Box const &b2) + { + return b1[a_][LEFT] < b2[a_][LEFT]; + } +}; + +list +Skyline::internal_build_skyline (list *boxes, Real horizon_padding, Axis horizon_axis, Direction sky) +{ + vsize size = boxes->size (); if (size == 0) { - empty_skyline (result); - return; + list result; + empty_skyline (&result); + return result; } else if (size == 1) { - single_skyline (buildings->front (), result); - return; + list result; + single_skyline (Building (boxes->front (), horizon_padding, horizon_axis, sky), + boxes->front ()[horizon_axis][LEFT] - horizon_padding, + horizon_padding, &result); + return result; } - list right_half; - list::iterator i = buildings->begin (); - - for (vsize s = 0; s < size/2; s++) - i++; - right_half.splice (right_half.end (), *buildings, i, buildings->end ()); + deque > partials; + boxes->sort (LessThanBox (horizon_axis)); + while (!boxes->empty ()) + partials.push_back (non_overlapping_skyline (boxes, horizon_padding, horizon_axis, sky)); - list right; - list left; - internal_build_skyline (&right_half, &right); - internal_build_skyline (buildings, &left); - internal_merge_skyline (&right, &left, result); + /* we'd like to say while (partials->size () > 1) but that's O (n). + Instead, we exit in the middle of the loop */ + while (!partials.empty ()) + { + list merged; + list one = partials.front (); + partials.pop_front (); + if (partials.empty ()) + return one; + + list two = partials.front (); + partials.pop_front (); + internal_merge_skyline (&one, &two, &merged); + partials.push_back (merged); + } + assert (0); + return list (); } Skyline::Skyline () @@ -260,26 +369,87 @@ Skyline::Skyline () empty_skyline (&buildings_); } +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++) + { + buildings_.push_back (Building ((*i))); + } +} + Skyline::Skyline (Direction sky) { sky_ = sky; empty_skyline (&buildings_); } -Skyline::Skyline (vector const &boxes, Axis a, Direction sky) +/* + build padded skyline from an existing skyline with padding + added to it. +*/ + +Skyline::Skyline (Skyline const &src, Real horizon_padding, Axis /*a*/) { - list bldgs; + /* + 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 + // FIXME: This has hardcoded logic, assuming a == X_AXIS! + 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 + 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 (after they are expanded by + horizon_padding), otherwise they are ignored. + */ +Skyline::Skyline (vector const &boxes, Real horizon_padding, Axis horizon_axis, Direction sky) +{ + list filtered_boxes; sky_ = sky; + Axis vert_axis = other_axis (horizon_axis); for (vsize i = 0; i < boxes.size (); i++) { - Interval iv = boxes[i][a]; - Real height = sky * boxes[i][other_axis (a)][sky]; - if (!iv.is_empty () && !isinf (height) && !equal (iv[LEFT], iv[RIGHT])) - bldgs.push_front (Building (iv[LEFT], height, height, iv[RIGHT])); + Interval iv = boxes[i][horizon_axis]; + iv.widen (horizon_padding); + if (iv.length () > EPS && !boxes[i][vert_axis].is_empty ()) + filtered_boxes.push_front (boxes[i]); } - internal_build_skyline (&bldgs, &buildings_); - assert (is_legal_skyline ()); + + buildings_ = internal_build_skyline (&filtered_boxes, horizon_padding, horizon_axis, sky); +} + +Skyline::Skyline (Box const &b, Real horizon_padding, Axis horizon_axis, Direction sky) +{ + sky_ = sky; + Building front (b, horizon_padding, horizon_axis, sky); + single_skyline (front, b[horizon_axis][LEFT] - horizon_padding, + horizon_padding, &buildings_); } void @@ -291,56 +461,121 @@ Skyline::merge (Skyline const &other) list my_bld; my_bld.splice (my_bld.begin (), buildings_); internal_merge_skyline (&other_bld, &my_bld, &buildings_); - assert (is_legal_skyline ()); } void -Skyline::insert (Box const &b, Axis a) +Skyline::insert (Box const &b, Real horizon_padding, Axis a) { list other_bld; - list my_bld (buildings_); + 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]; - Real height = sky_ * b[other_axis (a)][sky_]; + iv.widen (horizon_padding); + if (iv.length () <= EPS || b[other_axis (a)].is_empty ()) + return; - single_skyline (Building (iv[LEFT], height, height, iv[RIGHT]), &other_bld); + my_bld.splice (my_bld.begin (), buildings_); + single_skyline (Building (b, horizon_padding, a, sky_), b[a][LEFT] - horizon_padding, + horizon_padding, &other_bld); internal_merge_skyline (&other_bld, &my_bld, &buildings_); - assert (is_legal_skyline ()); } void Skyline::raise (Real r) +{ + list::iterator end = buildings_.end (); + for (list::iterator i = buildings_.begin (); i != end; i++) + i->y_intercept_ += sky_ * r; +} + +void +Skyline::shift (Real s) { list::iterator end = buildings_.end (); for (list::iterator i = buildings_.begin (); i != end; i++) { - i->start_height_ += sky_ * r; - i->end_height_ += sky_ * r; - i->b_ += sky_ * r; + i->end_ += s; + i->y_intercept_ -= s * i->slope_; } - assert (is_legal_skyline ()); } Real -Skyline::distance (Skyline const &other) const +Skyline::distance (Skyline const &other, Real horizon_padding) const +{ + Real dummy; + return internal_distance (other, horizon_padding, &dummy); +} + +Real +Skyline::touching_point (Skyline const &other, Real horizon_padding) const +{ + Real touch; + internal_distance (other, horizon_padding, &touch); + return touch; +} + +Real +Skyline::internal_distance (Skyline const &other, Real horizon_padding, Real *touch_point) 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; + bool created_tmp_skylines = false; + + /* + 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); + created_tmp_skylines = true; + } + + list::const_iterator i = padded_this->buildings_.begin (); + list::const_iterator j = padded_other->buildings_.begin (); Real dist = -infinity_f; - for (; i != buildings_.end () && j != other.buildings_.end (); i++) + Real start = -infinity_f; + Real touch = -infinity_f; + 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); + Real end_dist = i->height (end) + j->height (end); + dist = max (dist, max (start_dist, end_dist)); + + if (end_dist == dist) + touch = end; + else if (start_dist == dist) + touch = start; + + if (i->end_ <= j->end_) + i++; + else + j++; + start = end; + } + + if (created_tmp_skylines) { - while (j->iv_[RIGHT] < i->iv_[LEFT]) - j++; - - list::const_iterator k; - for (k = j; k->iv_[LEFT] <= i->iv_[RIGHT] && k != other.buildings_.end (); k++) - { - Interval iv = intersection (i->iv_, k->iv_); - dist = max (dist, max (i->height (iv[LEFT]) + k->height (iv[LEFT]), - i->height (iv[RIGHT]) + k->height (iv[RIGHT]))); - } + delete padded_this; + delete padded_other; } + + *touch_point = touch; return dist; } @@ -352,16 +587,10 @@ Skyline::height (Real airplane) const list::const_iterator i; for (i = buildings_.begin (); i != buildings_.end (); i++) { - if (i->iv_[RIGHT] > airplane) - return sky_ * i->height (airplane); - if (i->iv_[RIGHT] == airplane) - { - assert (i != buildings_.end ()); - list::const_iterator j = i; - j++; - return sky_ * (max (i->end_height_, j->start_height_)); - } + if (i->end_ >= airplane) + return sky_ * i->height (airplane); } + assert (0); return 0; } @@ -374,12 +603,135 @@ Skyline::max_height () const return sky_ * distance (s); } +Real +Skyline::max_height_position () const +{ + Skyline s (-sky_); + s.set_minimum_height (0); + return touching_point (s); +} + void Skyline::set_minimum_height (Real h) { Skyline s (sky_); - s.buildings_.front ().start_height_ = h*sky_; - s.buildings_.front ().end_height_ = h*sky_; - s.buildings_.front ().b_ = h*sky_; + s.buildings_.front ().y_intercept_ = h * sky_; merge (s); } + +vector +Skyline::to_points (Axis horizon_axis) const +{ + vector out; + + Real start = -infinity_f; + for (list::const_iterator i (buildings_.begin ()); + i != buildings_.end (); i++) + { + out.push_back (Offset (start, sky_ * i->height (start))); + out.push_back (Offset (i->end_, sky_ * i->height (i->end_))); + start = i->end_; + } + + if (horizon_axis == Y_AXIS) + for (vsize i = 0; i < out.size (); i++) + out[i] = out[i].swapped (); + + return out; +} + +bool +Skyline::is_empty () const +{ + Building b = buildings_.front (); + return b.end_ == infinity_f && b.y_intercept_ == -infinity_f; +} + +void +Skyline::clear () +{ + buildings_.clear (); + empty_skyline (&buildings_); +} + +/****************************************************************/ + +IMPLEMENT_SIMPLE_SMOBS (Skyline); +IMPLEMENT_TYPE_P (Skyline, "ly:skyline?"); +IMPLEMENT_DEFAULT_EQUAL_P (Skyline); + +SCM +Skyline::mark_smob (SCM s) +{ + ASSERT_LIVE_IS_ALLOWED (s); + return SCM_EOL; +} + +int +Skyline::print_smob (SCM s, SCM port, scm_print_state *) +{ + Skyline *r = (Skyline *) SCM_CELL_WORD_1 (s); + (void) r; + + scm_puts ("#", port); + + return 1; +} + +MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Skyline, get_touching_point, 3, 1, "") +SCM +Skyline::get_touching_point (SCM skyline_scm, SCM other_skyline_scm, SCM horizon_padding_scm) +{ + LY_ASSERT_SMOB (Skyline, other_skyline_scm, 1); + + Real horizon_padding = 0; + if (horizon_padding_scm != SCM_UNDEFINED) + { + LY_ASSERT_TYPE (scm_is_number, horizon_padding_scm, 3); + horizon_padding = scm_to_double (horizon_padding_scm); + } + + Skyline *skyline = Skyline::unsmob (skyline_scm); + Skyline *other_skyline = Skyline::unsmob (other_skyline_scm); + return scm_from_double (skyline->touching_point (*other_skyline, horizon_padding)); +} + +MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Skyline, get_distance, 3, 1, "") +SCM +Skyline::get_distance (SCM skyline_scm, SCM other_skyline_scm, SCM horizon_padding_scm) +{ + LY_ASSERT_SMOB (Skyline, other_skyline_scm, 1); + + Real horizon_padding = 0; + if (horizon_padding_scm != SCM_UNDEFINED) + { + LY_ASSERT_TYPE (scm_is_number, horizon_padding_scm, 3); + horizon_padding = scm_to_double (horizon_padding_scm); + } + + Skyline *skyline = Skyline::unsmob (skyline_scm); + Skyline *other_skyline = Skyline::unsmob (other_skyline_scm); + return scm_from_double (skyline->distance (*other_skyline, horizon_padding)); +} + +MAKE_SCHEME_CALLBACK (Skyline, get_max_height, 1) +SCM +Skyline::get_max_height (SCM skyline_scm) +{ + return scm_from_double (Skyline::unsmob (skyline_scm)->max_height ()); +} + +MAKE_SCHEME_CALLBACK (Skyline, get_max_height_position, 1) +SCM +Skyline::get_max_height_position (SCM skyline_scm) +{ + return scm_from_double (Skyline::unsmob (skyline_scm)->max_height_position ()); +} + +MAKE_SCHEME_CALLBACK (Skyline, get_height, 2) +SCM +Skyline::get_height (SCM skyline_scm, SCM x_scm) +{ + Real x = robust_scm2double (x_scm, 0.0); + return scm_from_double (Skyline::unsmob (skyline_scm)->height (x)); +}