[metapost] Fwd: Bug with the binary operator `point ... on ...` from Metafun
franck.pastor at me.com
Fri Apr 10 14:52:32 CEST 2015
Début du message réexpédié :
> De : Franck Pastor <franck.pastor at me.com>
> Objet : Rép : [metapost] Bug with the binary operator `point ... on ...` from Metafun
> Date : 9 mars 2015 18:05:16 UTC+01:00
> À : Hans Hagen <pragma at wxs.nl>
>> Le 9 mars 2015 à 17:17, Hans Hagen <pragma at wxs.nl> a écrit :
>> On 3/9/2015 5:01 PM, Franck Pastor wrote:
>>> I’ve just encountered a very puzzling bug with the binary operator `point <len> of <path>` defined in the Metafun format.
>>> In the Metafun manual (http://www.pragma-ade.com/general/manuals/metafun-p.pdf), p. 61, this binary operator is defined as such:
>>> primarydef len of pat =
>>> (arctime len of pat) of pat
>>> So if I write `point 0 on pat`, it should return the starting point of the path <pat>, right? But n. To the contrary, it returns the end point of <pat>! Stranger yet, if I try `point (arctime 0 of pat) of pat`, it returns the starting point, as expected.
>> change > into >= in mp-tool.*
>> primarydef len on pat = % no outer ( ) .. somehow fails
>> (arctime if len>=0 : len else : (arclength(pat)+len) fi of pat) of pat
>> enddef ;
I've just noticed that the oversight above about the "on" binary operator triggered another bug, concerning this time the "cutends" binary operator, which is defined as such in the mp-tool files:
% this cuts of a piece from both ends
tertiarydef pat cutends len =
save tap ; path tap ;
tap := pat cutbefore (point (xpart paired(len)) on pat) ;
(tap cutafter (point -(ypart paired(len)) on tap))
More precisely, the unpleasant consequence of the "on"-bug on the "cutends" macro it is that each time you use the cutends operator with 0 as the first coordinate of the second argument, it makes the path disappear completely! E.g.
path pat; pat = origin -- (4cm, 0);
draw pat cutends (0, 1cm) ;
makes the path simply vanish. (As a direct following from the instruction "tap := pat cutbefore (point (xpart paired(len)) on pat) ; ")
Another (much more anecdotical) consequence: if you enter
draw pat cutends (length pat, 0) ;
which should make the path vanish, then it is left unchanged. This comes this time from the instruction (tap cutafter (point -(ypart paired(len)) on tap)) in the cutends definition.
I stumbled on this phenomenon when working with one of my computers on which I had forgotten to correct the "on" bug. It took me a while to figure it out.
So people, if you use "cutends" (or anything based on the "on" operator), do not hesitate to correct the "on"-bug in the mp-tool files!
More information about the metapost