[metapost] turning number -- the neverending story?

Boguslaw Jackowski B_Jackowski at GUST.org.pl
Thu Jan 5 17:55:12 CET 2012


Hello, dear (meta)fonters,

I spotted a nasty bug in Metapost -- sorry, Taco, for spoiling
the beginning of the new year... I hope that the bug will
be easy to fix.

For the following code

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% FILE turnnum-err.mp
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if known mitered:
  beginfig(100)
fi
save a,i,p,q; pair p; path q;
p=right scaled 100; a=-90;

i:=0; z0=origin;
for f:=0, 1, 2, 2, -1, -1, 0, 0:
  i:=i+1; z[i]=z[i-1] + p rotated (f*a);
endfor

q=z1 .. controls z2 ..
   z3 .. controls z4 ..
   z5 .. controls z6 ..
   z7 .. controls z8 .. z1 & cycle;

show turningnumber q;

if known mitered:
  draw q; labels(1,2,3,4,5,6,7,8);
  endfig;
fi

end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% END OF FILE turnnum-err.mp
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

the Metapost returns the ZERO value of the turning number for the path
in question (Metafont returns -1 for a=-90, and 1 for a=90 and that's
what one would expect).

The only peculiarity of the path is that the precontrols and
postcontrols coincide (i.e., it is actually a so called b-spline).

Replacing the line

   q=z1 .. controls z2 ..

by

   q=z1 .. controls z2 and (z2+(0,epsilon)) ..

[but not by q=z1 .. controls z2 and (z2+(epsilon,0)) .. ]
improves the situation for a=-90 [but not for a=90].

Cheers -- Jacko

Ps. We've checked this behavior also for the latest version of MP.

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  Bogus\l{}aw Jackowski: B_Jackowski at GUST.ORG.PL
----------------------------------------------------------------
  Hofstadter's Law: It always takes longer than you expect, even
                    when you take into account Hofstadter's Law.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-




More information about the metapost mailing list