* [NTG-context] MetaFun path joiners && and &&&& do not like single point paths
@ 2023-12-31 2:31 Gavin via ntg-context
2023-12-31 7:06 ` [NTG-context] " Mikael Sundqvist
0 siblings, 1 reply; 5+ messages in thread
From: Gavin via ntg-context @ 2023-12-31 2:31 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Gavin
Hi MetaFun fans,
Following a suggestion of Hans, I experimented with && and &&& and &&&& for joining paths in MetaFun. The joiner &&& produces one long path, but && and &&&& seem to produce a disconnected path which includes all the original paths. However, if one of the paths is a single point, then it connects it. MWE below.
I spotted this on my globes module, where we saw an extra line appear for a very specific orientation of the globe. I guessed that this orientation had an island right on the horizon, so that only one boundary point was visible, creating a singe point path for that island. I should probably fix my module so it doesn’t do that. However, it might be nice to have && and &&&& deal with this situation gracefully.
Gavin
\startMPpage
path p[], q ;
p1 = fullcircle scaled 3cm ;
p2 = fullcircle scaled 2cm shifted (3cm,0) ;
p3 = (3cm,2cm) ;
q = for i = 1 upto 3 :
p[i] &&
endfor
cycle ;
draw p1 withpen pencircle scaled 2pt withcolor .7 ;
draw p2 withpen pencircle scaled 2pt withcolor .7 ;
draw p3 withpen pencircle scaled 2pt withcolor .7 ;
draw q withcolor red ;
eofill q withcolor 0.9 ;
draw fullcircle scaled 6cm shifted (1.25cm,0) ;
\stopMPpage
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* [NTG-context] Re: MetaFun path joiners && and &&&& do not like single point paths
2023-12-31 2:31 [NTG-context] MetaFun path joiners && and &&&& do not like single point paths Gavin via ntg-context
@ 2023-12-31 7:06 ` Mikael Sundqvist
2023-12-31 11:14 ` Hans Hagen via ntg-context
0 siblings, 1 reply; 5+ messages in thread
From: Mikael Sundqvist @ 2023-12-31 7:06 UTC (permalink / raw)
To: mailing list for ConTeXt users
Hi
On Sun, Dec 31, 2023 at 3:33 AM Gavin via ntg-context
<ntg-context@ntg.nl> wrote:
>
> Hi MetaFun fans,
>
> Following a suggestion of Hans, I experimented with && and &&& and &&&& for joining paths in MetaFun. The joiner &&& produces one long path, but && and &&&& seem to produce a disconnected path which includes all the original paths. However, if one of the paths is a single point, then it connects it. MWE below.
>
> I spotted this on my globes module, where we saw an extra line appear for a very specific orientation of the globe. I guessed that this orientation had an island right on the horizon, so that only one boundary point was visible, creating a singe point path for that island. I should probably fix my module so it doesn’t do that. However, it might be nice to have && and &&&& deal with this situation gracefully.
>
> Gavin
>
>
> \startMPpage
> path p[], q ;
> p1 = fullcircle scaled 3cm ;
> p2 = fullcircle scaled 2cm shifted (3cm,0) ;
> p3 = (3cm,2cm) ;
> q = for i = 1 upto 3 :
> p[i] &&
> endfor
> cycle ;
> draw p1 withpen pencircle scaled 2pt withcolor .7 ;
> draw p2 withpen pencircle scaled 2pt withcolor .7 ;
> draw p3 withpen pencircle scaled 2pt withcolor .7 ;
> draw q withcolor red ;
> eofill q withcolor 0.9 ;
> draw fullcircle scaled 6cm shifted (1.25cm,0) ;
> \stopMPpage
Not beautiful, but this seems to do what you want in this particular case:
\startMPpage
path p[], q ;
p1 = fullcircle scaled 3cm ;
p2 = fullcircle scaled 2cm shifted (3cm,0) ;
p3 = (3cm,2cm) ;
p4 = fullcircle ;
q = p[1] for i = 2 upto 3:
if (length(p[i]) == 0): &&& else: && fi p[i]
endfor
&& cycle ;
eofill q withcolor 0.9 ;
draw p1 withpen pencircle scaled 2pt withcolor .7 ;
draw p2 withpen pencircle scaled 2pt withcolor .7 ;
draw p3 withpen pencircle scaled 2pt withcolor .7 ;
draw q withcolor red ;
draw fullcircle scaled 6cm shifted (1.25cm,0) ;
\stopMPpage
This gives
q = p1 && p2 &&& p3 && cycle ;
/Mikael
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* [NTG-context] Re: MetaFun path joiners && and &&&& do not like single point paths
2023-12-31 7:06 ` [NTG-context] " Mikael Sundqvist
@ 2023-12-31 11:14 ` Hans Hagen via ntg-context
2023-12-31 14:10 ` Gavin via ntg-context
0 siblings, 1 reply; 5+ messages in thread
From: Hans Hagen via ntg-context @ 2023-12-31 11:14 UTC (permalink / raw)
To: ntg-context; +Cc: Hans Hagen
On 12/31/2023 8:06 AM, Mikael Sundqvist wrote:
> \startMPpage
> path p[], q ;
> p1 = fullcircle scaled 3cm ;
> p2 = fullcircle scaled 2cm shifted (3cm,0) ;
> p3 = (3cm,2cm) ;
> p4 = fullcircle ;
> q = p[1] for i = 2 upto 3:
> if (length(p[i]) == 0): &&& else: && fi p[i]
> endfor
> && cycle ;
> eofill q withcolor 0.9 ;
> draw p1 withpen pencircle scaled 2pt withcolor .7 ;
> draw p2 withpen pencircle scaled 2pt withcolor .7 ;
> draw p3 withpen pencircle scaled 2pt withcolor .7 ;
> draw q withcolor red ;
> draw fullcircle scaled 6cm shifted (1.25cm,0) ;
> \stopMPpage
maybe this is a bit more beautiful then
q = for i = 1 upto 3 :
if length(p[i]) == 0 : % todo: a fast nolength
(p[i] -- p[i] shifted 5(eps,eps))
else:
p[i]
fi &&
endfor cycle ;
(i'm not sure if we should change the implementation, probably not
unless we have &&&&& -- actually we could have proper keywords which
makes it less clumsy. Or 'recycle' that does the ugly eps job when we
have a zero length path but we can move that over the year boundary.)
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 / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* [NTG-context] Re: MetaFun path joiners && and &&&& do not like single point paths
2023-12-31 11:14 ` Hans Hagen via ntg-context
@ 2023-12-31 14:10 ` Gavin via ntg-context
2024-01-09 1:19 ` [NTG-context] Lua and inject.path to make a disconnected MetaPost path? Gavin via ntg-context
0 siblings, 1 reply; 5+ messages in thread
From: Gavin via ntg-context @ 2023-12-31 14:10 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Gavin
Hi Hans and Mikael,
Thanks for your solutions. I’m happy to discard paths that have no area, so I used:
q = for i = 1 upto 3 :
if (length(p[i]) > 1): p[i] && fi
endfor
cycle ;
This worked in the MWE, but it didn’t solve my problem in the globes module. Something else must be happening there. I’ll keep looking.
Gavin
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* [NTG-context] Lua and inject.path to make a disconnected MetaPost path?
2023-12-31 14:10 ` Gavin via ntg-context
@ 2024-01-09 1:19 ` Gavin via ntg-context
0 siblings, 0 replies; 5+ messages in thread
From: Gavin via ntg-context @ 2024-01-09 1:19 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Gavin
Hello LuaMetaFun Fans,
Can I use mp.inject.path in Lua to create a disconnected path in MetaPost?
This is for my module that draws globes. I currently do something like this for drawing the continents. (This MWE has two triangular continents.)
\startluacode
continents = {}
continents[1] = {{0,0}, {-1,-1}, {-1,0}, cycle = true }
continents[2] = {{0,1}, {1,0}, {1,-1}, cycle = true }
function mp.getglobepath(continentnum)
mp.inject.path(continents[continentnum])
end
\stopluacode
\startMPpage
path p[], q ;
p1 = (lua.mp.getglobepath(1) scaled 1cm) ;
p2 = (lua.mp.getglobepath(2) scaled 1cm) ;
q = p1 && p2 && cycle ;
draw p1 withpen pencircle scaled 2pt withcolor .7 ;
draw p2 withpen pencircle scaled 2pt withcolor .7 ;
fill q withcolor 0.9 ;
draw q withcolor red ;
\stopMPpage
The path q has both of the continents, disconnected.
I’d like to produce the two continents in Lua and pass them to MetaPost as a single disconnected path, using something like this:
\startluacode
continents = {
{0,0}, {-1,-1}, {-1,0}, — Change this to make a disconnected path!
{0,1}, {1,0}, {1,-1},
cycle = true }
function mp.getglobepath()
mp.inject.path(continents)
end
\stopluacode
\startMPpage
path p ;
p = (lua.mp.getglobepath() scaled 1cm) ;
fill p withcolor 0.9 ;
draw p withcolor red ;
\stopMPpage
If I can make the path p disconnected, this would allow me to make exactly the path I want in Lua, before passing it to MetaPost, rather than passing lots of paths and connecting them in MetaPost with the mysterious (to me) && or &&&&.
Thanks!
Gavin
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-01-09 1:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-31 2:31 [NTG-context] MetaFun path joiners && and &&&& do not like single point paths Gavin via ntg-context
2023-12-31 7:06 ` [NTG-context] " Mikael Sundqvist
2023-12-31 11:14 ` Hans Hagen via ntg-context
2023-12-31 14:10 ` Gavin via ntg-context
2024-01-09 1:19 ` [NTG-context] Lua and inject.path to make a disconnected MetaPost path? Gavin via ntg-context
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).