[NTG-context] Metapost: directionpoint gives unexpected point(?)

Hans Hagen j.hagen at xs4all.nl
Fri Feb 12 11:03:05 CET 2021


Hi,

Like this:

metapost.registerscript("scrutenized", function()
     local p = mp.scan.path()
     local r = math.round
     local d = 10^mp.scan.numeric()
     for i=1,#p do
         local pi = p[i]
         pi[1] = r(pi[1] * d) / d
         pi[2] = r(pi[2] * d) / d
     end
     local x1 = r(p[1][1])
     local y1 = r(p[1][2])
     local n = 1
     local t = { p[1], cycle = p.cycle }
     for i=2,#p do
         local pi = p[i]
         local x2 = r(pi[1])
         local y2 = r(pi[2])
         if x1 ~= x2 or y1 ~= y2 then
             n = n + 1
             t[n] = p[i]
             x1 = x2
             y1 = y2
         end
     end
     mp.inject.path(t)
end)
\stopluacode

\startMPdefinitions{doublefun}
     newscriptindex mfid_scrutenized ; mfid_scrutenized := scriptindex 
"scrutenized" ;

     primarydef p scrutenized  n =
         runscript mfid_scrutenized p n
     enddef ;
\stopMPdefinitions

and then

p[1] := p[1] scrutenized 5 ; % 5 decimals
p[2] := p[2] scrutenized 5 ; % 5 decimals

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------


More information about the ntg-context mailing list