X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fstencil.cc;h=dd3bb2626ea93f5559672a062c1a6769dc3726f0;hb=ed1d216fea92ba4166562c29e9bd797e526276f0;hp=2fad44274d43f0a99c685a143c5598be51dd2f34;hpb=ebe3e7dfa38d450fcf05298224949ad57da45668;p=lilypond.git diff --git a/lily/stencil.cc b/lily/stencil.cc index 2fad44274d..dd3bb2626e 100644 --- a/lily/stencil.cc +++ b/lily/stencil.cc @@ -78,6 +78,44 @@ 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 Stencil::translate (Offset o) {