]> git.donarmstrong.com Git - lilypond.git/commitdiff
smobify skyline, add copy ctor, move stenciling out of skyline.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 1 Dec 2006 13:43:24 +0000 (14:43 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 1 Dec 2006 13:43:24 +0000 (14:43 +0100)
lily/include/skyline.hh
lily/include/stencil.hh
lily/line-interface.cc
lily/skyline.cc
lily/system.cc

index d1a7de338493d37065f0719219d15c39dcfc2b28..49b6ebebee640d5becb0a70a9900e5096b283562 100644 (file)
@@ -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<Building> *const result);
   bool is_legal_skyline () const;
 
+  DECLARE_SIMPLE_SMOBS(Skyline);
 public:
   Skyline ();
+  Skyline (Skyline const &src);
   Skyline (Direction sky);
   Skyline (vector<Box> const &bldgs, Axis a, Direction sky);
   Skyline (vector<Offset> 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 */
 
index c887be149c7ae1b858059e381bdd0e3abe93b264..b80bcc1c3d77a281212a9701fe4ca66c926acb84 100644 (file)
@@ -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<Offset> points);
+
 #endif /* STENCIL_HH */
index 74b8c034bcff51c6fec8506c6632528c6487844b..f65dc946f2c70b62d7196f66159d99c2c1307dde 100644 (file)
@@ -155,3 +155,22 @@ ADD_INTERFACE (Line_interface,
               "style "
               "arrow-length "
               "arrow-width")
+
+
+
+/* todo: move this somewhere else? */
+Stencil
+points_to_line_stencil (vector<Offset> 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;
+}
index 26188e7ec99688a4c51b36185f7f5f0e39a2f6a5..c6ec8c4229fdb4eb4692f96d096d2309d83a63af 100644 (file)
@@ -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<Building> *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<Building>::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<Box> 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<Offset> 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<Offset>
 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 ("#<Skyline>", port);
+
+  return 1;
+}
index 2a869c450134692dc56b9492fdfdec06b5b76b31..3451ec6de1859b30f484f4748aa8616e98b9bcf5 100644 (file)
@@ -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);