lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Arrowlines patch version 2


From: Jonatan Liljedahl
Subject: Re: Arrowlines patch version 2
Date: Mon, 18 Apr 2005 00:45:55 -0300

On Sun, 17 Apr 2005 23:22:38 +0200
Han-Wen Nienhuys <address@hidden> wrote:

> Op zo, 17-04-2005 te 18:26 -0300, schreef Jonatan Liljedahl:
> > Here's the new version of my arrowline patch.
> > 
> > It lets you put arrows at the head or tail of a line.
> > The arrow is rotated correctly if the line isn't straight.
> > Arrow width and length is tunable.
> > 
> > Patch attached,
> 
> comments follow,
> 
> >+  static Stencil make_arrow (Offset &from, Offset &to, int dir, Real
> length, Real width);
> 
> don't use & . If you want to modify, use * . Use const& for big
> structures. In this case, just copy the arguments. 

I tried that first (since I'm used to C where there isn't any
&arg declarations),
but it bailed out with "no operator* for Offset".

> >+    for(d=0;d<2;d++) if(dir&(1<<d)) {
> 
> what's this? If you want to do left and right, use
> 
>  Direction d = LEFT;
>  do { 
>    ..
>  } while (flip (&d) != LEFT);

dir is holding two bits, one for each end of the line. Setting dir to 3
means to make arrows at both ends.
So I check dir with dir&(1<<d), instead of

   do { if ((d==LEFT && dir&1) || (d==RIGHT && dir&2)) ... } while ...
 
> >+        // calculate the coordinates
> >+        Real slopy = atan2(d?(y2-y1):(y1-y2),d?(x2-x1):(x1-x2));
> >+        Real lcos = cos(slopy)*length, lsin = sin(slopy)*length;
> >+        Real wcos = cos(slopy)*width, wsin = sin(slopy)*width;
> >+        Real x=d?x1:x2, y=d?y1:y2;
> 
> can you look into using 
> 
>   angle = (to -from).arg()
>   // construct horizontal arrow
>   // rotate arrow
>   for (int i = 0; i < points.size() ; i++)
>     points[i] = points[i] * complex_exp (Offset (0, angle))
> 
> this will make the code simpler.

Ok. 
I'm sorry about my C-ish code. This is actually the first time I do
anything in C++ and even more my first encounter with scheme. =)
 
> >+     (arrow ,integer? "Add an arrow to the line at 1: end, 2: start,
> 3: both.")
> 
> This is not done. We do not have magical number constants in lilypond.

I see. What about symbols: 'head-arrow 'tail-arrow 'both-arrow 'no-arrow
?
Or perhaps just a pair of booleans?
 
> finally, can you reformat your code according to our standards? i.e.
> 
>   for (d = 0; d < 2; d++)
>     {
>       func (d, x);
>     } 
> 
> notice the use of spaces and newlines around , and { } 

I'll do that.

/Jonatan    -=( http://kymatica.com )=-




reply via email to

[Prev in Thread] Current Thread [Next in Thread]