[metapost] polygonal pen bugs (was: a message for prof. Knuth?)
Stephan Hennig
mailing_list at arcor.de
Tue Jun 18 15:44:53 CEST 2013
[fullquote, moving to the MetaPost list]
Hi all,
Am 18.06.2013 12:00, schrieb Boguslaw Jackowski:
>
> Dear Karl, dear CCers
>
> KB:
>> do you have any sense of whether the pensquare bug
>> Stephan reported on mp-implementors a few days ago could be present in
>> mf, and hence sendable to Knuth? If not, perhaps we could ask Hobby.
>> In any case, I suspect you are one of the few people in the world who
>> might understand what's going on, especially mathematically ...
>
> It seems to be a "chronic" (I dare not say "incurable") error in MP.
> Actually, I reported it in my email of 16 Jan 2001 to JDH; two of a few
> flaws I listed then are still alive and kicking, namely:
>
> % file err-pen1.mp
> beginfig(100) draw origin..(100bp,0){up}..cycle withpen pensquare scaled 3mm; endfig; % WRONG
> beginfig(101) draw origin..(100bp,0){up}..cycle withpen pensquare rotated eps scaled 3mm; endfig; % OK
> end.
> % EOF
>
> % file err-pen2.mp
> linecap:=butt;
> beginfig(100) draw (0,0)--(5cm,0) withpen pensquare scaled 3mm; endfig; % WRONG (oblique ends)
> beginfig(101) draw (0,0)--(5cm,0) withpen pencircle scaled 3mm; endfig; % OK
> end.
> % EOF
>
> The former of the two examples cotresponds actually to the bug reported by
> Stephan.
Just a short explanation of my example. I have only recently noticed
that MetaPost gained an envelope primitive/macro(?) in MetaPost 1.100,
my very first experiment with that failing badly. What I didn't
realise, but the example sent by me already shows, is that the error is
not in the envelope command exclusively, but the stroked path is also
wrong. So, yes, my example is just another instance of the polygonal
pen bug(s) listed, e.g., here
<URL:http://www.tug.org/TUGboat/tb27-0/hoekwater.pdf>.
I have one more instance to add to that list with a squared linecap.
Additionally, MetaPost versions differ in how they exhibit the bug(s).
I have attached another file to this mail, this time drawing three paths
with linecap set to butt, rounded and squared, resp. The output file
name contains the value of variable mpversion, so that compiling the
example with different MetaPost versions and then running
pdftex mpsproof sq*.mps
results in a chart for easy cross-checking MetaPost versions. The
attached PDF contains output of MetaPost 1.504 and 1.802. Not, how the
half circles turn out better with 1.802, but the ends of the straight
line are even more distorted for a squared linecap.
Best regards,
Stephan Hennig
> John's answer was not particularly comforting:
>
>> The implementation of pensquare is radically different from
>> pencircle and it involves a lot of tricky code that uses convolution
>> tracings. The implementation of turningnumber shares much of this
>> complicated convolution tracing code. I have known for some time
>> that it is slightly buggy. I'm sorry, but I don't have time to work
>> on it any time soon.
> [...]
>> I wish I could be more helpful...
>
> Needless to say, so do I...
>
> The incriminated error is MP-specific; as far as I understand, MF avoids
> computing the pen envelope explicitly; instead, it uses polygonal pens
> (always!) for darkening a bitmap which, as it turns out, is a significantly
> more "robust" approach. Stephen's example, transferred to MF
>
> % File pensquare.mf
> mode_setup; designsize:=10pt#; u=1/4pt; u#=1/4pt#;
> beginchar("a", 100u#,100u#,0);
> path p, e, s;
> pen sqpen;
> sqpen := pensquare scaled 10u;
> p := ((-100u,100u){right}..origin..{right}(100u,100u)) shifted (100u,0);
> draw p withpen sqpen;
> endchar;
> end.
> % EOF
>
> works correctly; see the enclosed PDF file being the result
> of the following TeX one-liner:
>
> % File pensquare.tex
> \nopagenumbers \font\f pensquare scaled 5000 \f a \end
> % EOF
>
> Perhaps Dan has more to say about bugs related to drawing
> with polygonal pens (and about the turning number issue)
> in MP -- hence CC.
>
> Cheers -- Jacko
>
> Ps. The example err-pen1 is sensitive also to the direction of the path,
> in the new(est) MP -- to the double precision math, and perhaps to
> a few more factors... Occasionally occurring an infinity symbol
> as the result of err-pen1 example does not bode well... ;-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1504-vs-1802.pdf
Type: application/pdf
Size: 32852 bytes
Desc: not available
URL: <http://tug.org/pipermail/metapost/attachments/20130618/8f8a87b2/attachment-0001.pdf>
-------------- next part --------------
outputtemplate := "%j-" & mpversion & "-%c.mps";
%%% setup test paths
path p[];
p1 := (0,0){up}..{down}(100,0);% half circle
p2 := ((0,0)--(100,0)) shifted 50down;% horizontal line
p3 := (origin..(100bp,0){up}..cycle) shifted 150down;% loop
%%% captions describing linecap
string lncap[];
lncap[butt] := "butt";
lncap[rounded] := "rounded";
lncap[squared] := "squared";
%%% polygonal test pen
pen mypen;
mypen := pensquare scaled 10;
beginfig(1);
numeric i;
pickup mypen;
i := 0;
for cap = butt, rounded, squared:
% linecap
linecap := cap;
% draw paths
draw p1 shifted (150i*right);
draw p2 shifted (150i*right);
draw p3 shifted (150i*right);
%draw label
label.bot(lncap[cap], origin shifted (150i, 100));
i := i + 1;
endfor
endfig;
end
More information about the metapost
mailing list