[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Centering a stencil on another stencil
From: |
Paul Morris |
Subject: |
Re: Centering a stencil on another stencil |
Date: |
Wed, 12 Aug 2015 10:58:07 -0400 |
> On Aug 11, 2015, at 8:23 PM, Thomas Morley <address@hidden> wrote:
>>
>> I'm still not happy with the example, because the second stencil, the
>> circle, is centered already.
Ah, right, so your two squares example is better than the circle one. Lets use
it for the LSR snippet.
>> As a thought I extended the coding to get the possibility of a
>> centered stencil in both directions in one go:
Makes sense, although I think I’d prefer two separate functions (see below),
following the pattern of ly:stencil-translate and ly:stencil-translate-axis.
For one thing that prevents someone from trying (center-stencil-on-stencil #f
square circle) with your combined function, with an invalid argument of #f.
%%%%%%%%%%%%%%%%%%%%%%%%%
\version "2.19.22"
#(define (center-stencil-on-stencil-axis axis stil-a stil-b)
"Return a copy of stencil @var{stil-b} that has been
moved so it is centered on stencil @var{stil-a} on
@var{axis}. @var{axis} is 0 for X axis, 1 for Y axis."
(ly:stencil-translate-axis
(ly:stencil-aligned-to stil-b axis CENTER)
(interval-center (ly:stencil-extent stil-a axis))
axis))
% one way:
#(define (center-stencil-on-stencil stil-a stil-b)
"Return a copy of stencil @var{stil-b} that has been
moved so it is centered on stencil @var{stil-a} on
both X and Y axes."
(center-stencil-on-stencil-axis Y stil-a
(center-stencil-on-stencil-axis X stil-a stil-b)))
% but your way is probably better:
#(define (center-stencil-on-stencil stil-a stil-b)
"Return a copy of stencil @var{stil-b} that has been
moved so it is centered on stencil @var{stil-a} on
both X and Y axes."
(ly:stencil-translate
(centered-stencil stil-b)
(cons
(interval-center (ly:stencil-extent stil-a X))
(interval-center (ly:stencil-extent stil-a Y)))))
test =
#(define-scheme-function (parser location stil-1 stil-2)
(ly:stencil? ly:stencil?)
#{
\markup
\override #'(word-space . 3)
\line {
\stencil #(ly:stencil-add stil-1 stil-2)
\stencil #(ly:stencil-add stil-1
(center-stencil-on-stencil-axis X stil-1 stil-2))
\stencil #(ly:stencil-add stil-1
(center-stencil-on-stencil-axis Y stil-1 stil-2))
\stencil #(ly:stencil-add stil-1
(center-stencil-on-stencil stil-1 stil-2))
}
#})
square =
#(make-connected-path-stencil
'((0 0) (4 0) (4 4) (0 4) (0 0))
0.4 1 1 #f #f)
green-square =
#(stencil-with-color (make-filled-box-stencil '(0 . 2) '(0 . 2)) green)
circle =
#(stencil-with-color (make-circle-stencil 1 0.3 #f) green)
\test #square #circle
\test #square #green-square
%%%%%%%%%%%%%%%%%%%%%%%%%
I don’t think we need both circle and square examples in the LSR snippet.
In that case we can simplify by not including the test function?
Either way \override #'(word-space . 3) is a nice improvement.
Let me know what you think and I’ll update the LSR snippet.
Cheers,
-Paul
- Re: Centering a stencil on another stencil, Paul Morris, 2015/08/07
- Re: Centering a stencil on another stencil, Thomas Morley, 2015/08/07
- Re: Centering a stencil on another stencil, Paul Morris, 2015/08/10
- Re: Centering a stencil on another stencil, Thomas Morley, 2015/08/11
- Re: Centering a stencil on another stencil, Paul Morris, 2015/08/11
- Re: Centering a stencil on another stencil, Thomas Morley, 2015/08/11
- Re: Centering a stencil on another stencil, Thomas Morley, 2015/08/11
- Re: Centering a stencil on another stencil,
Paul Morris <=
- Re: Centering a stencil on another stencil, Paul Morris, 2015/08/13
- Re: Centering a stencil on another stencil, Thomas Morley, 2015/08/13
- Re: Centering a stencil on another stencil, Paul Morris, 2015/08/13
- Re: Centering a stencil on another stencil, Thomas Morley, 2015/08/13