ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <j.hagen@xs4all.nl>
To: Taco Hoekwater <taco@bittext.nl>,
	mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Metapost: directionpoint gives unexpected point(?)
Date: Fri, 12 Feb 2021 11:03:05 +0100	[thread overview]
Message-ID: <91278517-bf06-bd22-5621-c5ca15a7a9a7@xs4all.nl> (raw)
In-Reply-To: <648158d2-9752-b793-5540-998959fcab66@xs4all.nl>

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
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

      reply	other threads:[~2021-02-12 10:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05 16:48 Mikael Sundqvist
2021-02-05 16:51 ` Mikael Sundqvist
2021-02-11 13:45   ` Mikael Sundqvist
2021-02-11 14:54     ` Hans Hagen
2021-02-11 16:41       ` Mikael Sundqvist
2021-02-12  8:35         ` Taco Hoekwater
2021-02-12  9:31           ` Mikael Sundqvist
2021-02-12  9:55             ` Taco Hoekwater
2021-02-12  9:53           ` Hans Hagen
2021-02-12 10:03             ` Hans Hagen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=91278517-bf06-bd22-5621-c5ca15a7a9a7@xs4all.nl \
    --to=j.hagen@xs4all.nl \
    --cc=ntg-context@ntg.nl \
    --cc=taco@bittext.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).