X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fstencil.cc;h=b88b0c8bdebb50581e275babe0a9fdb819e17f23;hb=87eedcd59f4082cb0841528ad5bc82cb1d1191e3;hp=2fad44274d43f0a99c685a143c5598be51dd2f34;hpb=ebe3e7dfa38d450fcf05298224949ad57da45668;p=lilypond.git diff --git a/lily/stencil.cc b/lily/stencil.cc index 2fad44274d..b88b0c8bde 100644 --- a/lily/stencil.cc +++ b/lily/stencil.cc @@ -3,14 +3,14 @@ source file of the GNU LilyPond music typesetter - (c) 1997--2006 Han-Wen Nienhuys + (c) 1997--2007 Han-Wen Nienhuys */ #include "stencil.hh" #include "main.hh" #include "font-metric.hh" -#include "input-smob.hh" +#include "input.hh" #include "string-convert.hh" #include "warn.hh" @@ -72,10 +72,43 @@ Stencil::extent_box () const { return dim_; } -Offset -Stencil::origin () const -{ - return origin_; + +/* + * Rotate this stencil around the point [x, y] + */ +void +Stencil::rotate (Real a, Offset off) +{ + const Real x_cen = extent (X_AXIS).center (); + const Real y_cen = extent (Y_AXIS).center (); + + /* + * Calculate the center of rotation + */ + const Real x = x_cen + off[X_AXIS] * x_cen; + const Real y = y_cen + off[Y_AXIS] * y_cen; + + /* + * Build scheme expression (processed in stencil-interpret.cc) + */ + expr_ = scm_list_n (ly_symbol2scm ("rotate-stencil"), + scm_list_2 (scm_from_double (a), + scm_cons (scm_from_double (x), scm_from_double (y))), + expr_, SCM_UNDEFINED); + + /* + * Calculate the new bounding box + */ + vector pts; + pts.push_back (Offset (-x_cen, -y_cen)); + pts.push_back (Offset (x_cen, -y_cen)); + pts.push_back (Offset (x_cen, y_cen)); + pts.push_back (Offset (-x_cen, y_cen)); + + const Offset rot = complex_exp (Offset (0, a * M_PI / 180.0)); + dim_.set_empty (); + for (vsize i = 0; i < pts.size (); i++) + dim_.add_point (pts[i] * rot + Offset (x_cen, y_cen)); } void @@ -105,7 +138,6 @@ Stencil::translate (Offset o) expr_, SCM_UNDEFINED); if (!is_empty ()) dim_.translate (o); - origin_ += o; } void @@ -148,13 +180,9 @@ Stencil::align_to (Axis a, Real x) translate_axis (-i.linear_combination (x), a); } -/* FIXME: unintuitive naming, you would expect *this to be moved. - Kept (keeping?) API for compat with add_at_edge (). - - What is PADDING, what is MINIMUM, exactly? */ -Stencil -Stencil::moved_to_edge (Axis a, Direction d, Stencil const &s, - Real padding, Real minimum) const +/* See scheme Function. */ +void +Stencil::add_at_edge (Axis a, Direction d, Stencil const &s, Real padding) { Interval my_extent = dim_[a]; Interval i (s.extent (a)); @@ -163,7 +191,6 @@ Stencil::moved_to_edge (Axis a, Direction d, Stencil const &s, { programming_error ("Stencil::moved_to_edge: adding empty stencil."); his_extent = 0.0; - // SCM_ASSERT_TYPE (0, s.expr (), SCM_ARG1, __FUNCTION__, "non-empty stencil"); } else his_extent = i[-d]; @@ -173,20 +200,7 @@ Stencil::moved_to_edge (Axis a, Direction d, Stencil const &s, Stencil toadd (s); toadd.translate_axis (offset, a); - - if (minimum > 0 && d * (-origin ()[a] + toadd.origin ()[a]) < minimum) - toadd.translate_axis (-toadd.origin ()[a] - + origin ()[a] + d * minimum, a); - - return toadd; -} - -/* See scheme Function. */ -void -Stencil::add_at_edge (Axis a, Direction d, Stencil const &s, Real padding, - Real minimum) -{ - add_stencil (moved_to_edge (a, d, s, padding, minimum)); + add_stencil (toadd); } Stencil @@ -200,3 +214,12 @@ Stencil::in_color (Real r, Real g, Real b) const expr ())); return new_stencil; } + +/* convenience */ +Stencil +Stencil::translated (Offset z) const +{ + Stencil s (*this); + s.translate (z); + return s; +}