X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fstencil-scheme.cc;h=da9f0a8214afcdf7d9fc74d8c9691542ad74a7ac;hb=5d84bfad4626892bcffd05adcced53c8a2329047;hp=33ae3f5d9442b2d2f85e2434a689f25518d9cd5a;hpb=1de3d397c18622b6061402fef18e625701712bc5;p=lilypond.git diff --git a/lily/stencil-scheme.cc b/lily/stencil-scheme.cc index 33ae3f5d94..da9f0a8214 100644 --- a/lily/stencil-scheme.cc +++ b/lily/stencil-scheme.cc @@ -20,9 +20,79 @@ #include "font-metric.hh" #include "libc-extension.hh" #include "lookup.hh" +#include "offset.hh" #include "stencil.hh" -using std::vector; +/* + * A few general helpers in degrees + */ + +LY_DEFINE (ly_angle, "ly:angle", + 1, 1, 0, (SCM x, SCM y), + "Calculates angle in degrees of given vector. With one argument," + " @var{x} is a number pair indicating the vector. With two" + " arguments, @var{x} and @var{y} specify the respective coordinates.") +{ + Offset off; + if (SCM_UNBNDP (y)) { + LY_ASSERT_TYPE (is_number_pair, x, 1); + off = ly_scm2offset (x); + } else { + LY_ASSERT_TYPE (scm_is_number, x, 1); + LY_ASSERT_TYPE (scm_is_number, y, 2); + off = Offset (scm_to_double (x), scm_to_double (y)); + } + return scm_from_double (off.angle_degrees ()); +} + +LY_DEFINE (ly_length, "ly:length", + 1, 1, 0, (SCM x, SCM y), + "Calculates magnitude of given vector. With one argument," + " @var{x} is a number pair indicating the vector. With two" + " arguments, @var{x} and @var{y} specify the respective coordinates.") +{ + Offset off; + if (SCM_UNBNDP (y)) { + LY_ASSERT_TYPE (is_number_pair, x, 1); + off = ly_scm2offset (x); + } else { + LY_ASSERT_TYPE (scm_is_number, x, 1); + LY_ASSERT_TYPE (scm_is_number, y, 2); + off = Offset (scm_to_double (x), scm_to_double (y)); + } + return scm_from_double (off.length ()); +} + +LY_DEFINE (ly_directed, "ly:directed", + 1, 1, 0, (SCM direction, SCM magnitude), + "Calculates an @code{(x . y)} pair with optional @var{magnitude}" + " (defaulting to @code{1.0}) and @var{direction} specified either" + " as an angle in degrees or a coordinate pair giving the direction. " + " If @var{magnitude} is a pair, the respective coordinates are" + " scaled independently, useful for ellipse drawings.") +{ + Offset res; + if (scm_is_pair (direction)) + { + LY_ASSERT_TYPE (is_number_pair, direction, 1); + res = ly_scm2offset (direction).direction (); + } + else + { + LY_ASSERT_TYPE (scm_is_number, direction, 1); + res = offset_directed (scm_to_double (direction)); + } + if (SCM_UNBNDP (magnitude)) + return ly_offset2scm (res); + if (scm_is_pair (magnitude)) + { + LY_ASSERT_TYPE (is_number_pair, magnitude, 2); + return ly_offset2scm (res.scale (ly_scm2offset (magnitude))); + } + LY_ASSERT_TYPE (scm_is_number, magnitude, 2); + return ly_offset2scm (scm_to_double (magnitude) * res); +} + /* TODO: naming add/combine. @@ -485,3 +555,14 @@ LY_DEFINE (ly_stencil_scale, "ly:stencil-scale", q->scale (scm_to_double (x), scm_to_double (y)); return new_s; } + +LY_DEFINE (ly_stencil_outline, "ly:stencil-outline", + 2, 0, 0, (SCM stil, SCM outline), + "Return a stencil with the stencil expression (inking)" + " of stencil @var{stil} but with outline and dimensions" + " from stencil @var{outline}.") +{ + Stencil s = *LY_ASSERT_SMOB (Stencil, stil, 1); + Stencil o = *LY_ASSERT_SMOB (Stencil, outline, 2); + return s.with_outline (o).smobbed_copy (); +}