From f76770152ccc1c13efef55eff1ebe724cf9ca5ab Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Fri, 1 Dec 2006 14:43:24 +0100 Subject: [PATCH] smobify skyline, add copy ctor, move stenciling out of skyline. --- lily/include/skyline.hh | 6 ++-- lily/include/stencil.hh | 2 ++ lily/line-interface.cc | 19 ++++++++++++ lily/skyline.cc | 66 ++++++++++++++++++++++++++++------------- lily/system.cc | 4 +-- 5 files changed, 71 insertions(+), 26 deletions(-) diff --git a/lily/include/skyline.hh b/lily/include/skyline.hh index d1a7de3384..49b6ebebee 100644 --- a/lily/include/skyline.hh +++ b/lily/include/skyline.hh @@ -16,7 +16,7 @@ #include "interval.hh" #include "direction.hh" #include "std-vector.hh" -#include "stencil.hh" +#include "smobs.hh" struct Building { @@ -50,8 +50,10 @@ private: list *const result); bool is_legal_skyline () const; + DECLARE_SIMPLE_SMOBS(Skyline); public: Skyline (); + Skyline (Skyline const &src); Skyline (Direction sky); Skyline (vector const &bldgs, Axis a, Direction sky); Skyline (vector const &points, Real max_slope, Direction sky); @@ -66,7 +68,5 @@ public: void set_minimum_height (Real height); }; -Stencil to_stencil (Skyline const &line); - #endif /* SKYLINE_HH */ diff --git a/lily/include/stencil.hh b/lily/include/stencil.hh index c887be149c..b80bcc1c3d 100644 --- a/lily/include/stencil.hh +++ b/lily/include/stencil.hh @@ -95,4 +95,6 @@ void register_stencil_head (SCM symbol); bool is_stencil_head (SCM symbol); SCM all_stencil_heads (); +Stencil points_to_line_stencil (vector points); + #endif /* STENCIL_HH */ diff --git a/lily/line-interface.cc b/lily/line-interface.cc index 74b8c034bc..f65dc946f2 100644 --- a/lily/line-interface.cc +++ b/lily/line-interface.cc @@ -155,3 +155,22 @@ ADD_INTERFACE (Line_interface, "style " "arrow-length " "arrow-width") + + + +/* todo: move this somewhere else? */ +Stencil +points_to_line_stencil (vector points) +{ + Stencil ret; + for (vsize i = 1; i < points.size (); i++) + { + if (points[i-1].is_sane () && points[i].is_sane ()) + { + Stencil line + = Line_interface::make_line (0.1, points[i-1], points[i]); + ret.add_stencil (line); + } + } + return ret; +} diff --git a/lily/skyline.cc b/lily/skyline.cc index 26188e7ec9..c6ec8c4229 100644 --- a/lily/skyline.cc +++ b/lily/skyline.cc @@ -7,7 +7,7 @@ #include "skyline.hh" -#include "line-interface.hh" +#include "ly-smobs.icc" /* A skyline is a sequence of non-overlapping buildings: something like this: @@ -218,10 +218,12 @@ static void single_skyline (Building const &b, list *const ret, Real max_slope) { if (!isinf (b.iv_[RIGHT])) - ret->push_front (Building (b.iv_[RIGHT], b.end_height_, -infinity_f, infinity_f, max_slope)); + ret->push_front (Building (b.iv_[RIGHT], b.end_height_, + -infinity_f, infinity_f, max_slope)); ret->push_front (b); if (!isinf (b.iv_[LEFT])) - ret->push_front (Building (-infinity_f, -infinity_f, b.start_height_, b.iv_[LEFT], max_slope)); + ret->push_front (Building (-infinity_f, -infinity_f, + b.start_height_, b.iv_[LEFT], max_slope)); } void @@ -259,6 +261,20 @@ Skyline::Skyline () max_slope_ = 2; sky_ = UP; empty_skyline (&buildings_); + + +} + +Skyline::Skyline (Skyline const &src) +{ + max_slope_ = src.max_slope_; + sky_ = src.sky_; + + for (list::const_iterator i = src.buildings_.begin (); + i != src.buildings_.end (); i++) + { + buildings_.push_back (Building ((*i))); + } } Skyline::Skyline (Direction sky) @@ -284,8 +300,10 @@ 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]; if (!iv.is_empty () && !isinf (height) && !equal (iv[LEFT], iv[RIGHT])) - bldgs.push_front (Building (iv[LEFT], height, height, iv[RIGHT], max_slope_)); + bldgs.push_front (Building (iv[LEFT], height, height, iv[RIGHT], + max_slope_)); } + internal_build_skyline (&bldgs, &buildings_); assert (is_legal_skyline ()); } @@ -402,23 +420,6 @@ Skyline::set_minimum_height (Real h) merge (s); } -Stencil -to_stencil (Skyline const &line) -{ - vector points (line.to_points ()); - - Stencil ret; - for (vsize i = 1; i < points.size (); i++) - { - if (points[i-1].is_sane () && points[i].is_sane ()) - { - Stencil line - = Line_interface::make_line (0.1, points[i-1], points[i]); - ret.add_stencil (line); - } - } - return ret; -} vector Skyline::to_points () const @@ -439,3 +440,26 @@ Skyline::to_points () const return out; } +/****************************************************************/ + + +IMPLEMENT_SIMPLE_SMOBS (Skyline); +IMPLEMENT_TYPE_P (Skyline, "ly:skyline?"); +IMPLEMENT_DEFAULT_EQUAL_P (Skyline); + +SCM +Skyline::mark_smob (SCM) +{ + 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; +} diff --git a/lily/system.cc b/lily/system.cc index 2a869c4501..3451ec6de1 100644 --- a/lily/system.cc +++ b/lily/system.cc @@ -402,8 +402,8 @@ System::get_paper_system () exprs)); if (debug_skylines) { - sys_stencil.add_stencil (to_stencil (skylines_[UP]).in_color (255, 0, 0)); - sys_stencil.add_stencil (to_stencil (skylines_[DOWN]).in_color (0, 255, 0)); + sys_stencil.add_stencil (points_to_line_stencil (skylines_[UP].to_points ()).in_color (255, 0, 0)); + sys_stencil.add_stencil (points_to_line_stencil (skylines_[DOWN].to_points ()).in_color (0, 255, 0)); } Grob *left_bound = this->get_bound (LEFT); -- 2.39.5