Hi, I played around with the new passvariable() option and ran into errors when passing a path. Used the latest beta (01.10.2013). Can someone confirm this? Peter
On 10/4/2013 2:52 PM, Peter Rolf wrote:
Hi,
I played around with the new passvariable() option and ran into errors when passing a path. Used the latest beta (01.10.2013). Can someone confirm this?
in mp-mlib.mpiv: vardef mfun_path_to_string(expr p) = mfun_point_to_string(p,1) for i=2 upto length(p) : & " " & mfun_point_to_string(p,i) endfor enddef ; vardef mfun_boolean_to_string(expr b) = if b : "true" else : "false" fi enddef ; (i forgot to rename the argument when outlining the code) fwiw: in your case you still get an (empty) graphic, use \startMPcalculation ... when you don't want that Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Am 04.10.2013 16:15, schrieb Hans Hagen:
On 10/4/2013 2:52 PM, Peter Rolf wrote:
Hi,
I played around with the new passvariable() option and ran into errors when passing a path. Used the latest beta (01.10.2013). Can someone confirm this?
in mp-mlib.mpiv:
vardef mfun_path_to_string(expr p) = mfun_point_to_string(p,1) for i=2 upto length(p) : & " " & mfun_point_to_string(p,i) endfor enddef ;
vardef mfun_boolean_to_string(expr b) = if b : "true" else : "false" fi enddef ;
(i forgot to rename the argument when outlining the code)
fwiw: in your case you still get an (empty) graphic, use \startMPcalculation ... when you don't want that
Many thanks! Good to know, but in this case I just need the path.
Hans
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | 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://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
Am 04.10.2013 16:47, schrieb Peter Rolf:
Am 04.10.2013 16:15, schrieb Hans Hagen:
On 10/4/2013 2:52 PM, Peter Rolf wrote:
Hi,
I played around with the new passvariable() option and ran into errors when passing a path. Used the latest beta (01.10.2013). Can someone confirm this?
in mp-mlib.mpiv:
vardef mfun_path_to_string(expr p) = mfun_point_to_string(p,1) for i=2 upto length(p) : & " " & mfun_point_to_string(p,i) endfor enddef ;
vardef mfun_boolean_to_string(expr b) = if b : "true" else : "false" fi enddef ;
(i forgot to rename the argument when outlining the code)
fwiw: in your case you still get an (empty) graphic, use \startMPcalculation ... when you don't want that
Many thanks! Good to know, but in this case I just need the path.
:-D now I know what you mean...
Hans
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | 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://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
___________________________________________________________________________________ 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://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
I played around with it, but I have problems to understand the format of the returned path. Example: % -------- \setuppagenumber[state=stop] \starttext \nopdfcompression \startMPpage path p; p:= (20,20){up} .. {down}(200,100); passvariable("path",p); draw p ; \stopMPpage \ctxlua{inspect{metapost.variables["path"]}} \stoptext % ------- The PDF code of the path is (mainly) 20.000000 20.000000 m 20.000000 190.342880 200.000000 184.016693 200.000000 100.000000 c "path" contains table={ { { 200, 100, 200, 184.0167, 200, 100 }, }, } The end point and the second control point are the same, as in the PDF code. But how do I calculate the starting point and the first control point from the returned values? And is the type of operation (line, curve,..) given by the number of values? Peter Am 04.10.2013 16:15, schrieb Hans Hagen:
On 10/4/2013 2:52 PM, Peter Rolf wrote:
Hi,
I played around with the new passvariable() option and ran into errors when passing a path. Used the latest beta (01.10.2013). Can someone confirm this?
in mp-mlib.mpiv:
vardef mfun_path_to_string(expr p) = mfun_point_to_string(p,1) for i=2 upto length(p) : & " " & mfun_point_to_string(p,i) endfor enddef ;
vardef mfun_boolean_to_string(expr b) = if b : "true" else : "false" fi enddef ;
(i forgot to rename the argument when outlining the code)
fwiw: in your case you still get an (empty) graphic, use \startMPcalculation ... when you don't want that
Hans
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | 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://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
On 10/5/2013 5:52 PM, Peter Rolf wrote:
I played around with it, but I have problems to understand the format of the returned path.
Example: % -------- \setuppagenumber[state=stop]
\starttext \nopdfcompression
\startMPpage path p; p:= (20,20){up} .. {down}(200,100); passvariable("path",p); draw p ; \stopMPpage
\ctxlua{inspect{metapost.variables["path"]}} \stoptext % -------
The PDF code of the path is (mainly)
20.000000 20.000000 m 20.000000 190.342880 200.000000 184.016693 200.000000 100.000000 c
"path" contains
table={ { { 200, 100, 200, 184.0167, 200, 100 }, }, }
The end point and the second control point are the same, as in the PDF code. But how do I calculate the starting point and the first control point from the returned values?
something local prev = nil for i=1,#path do local current = path[i] if not prev then print(current[1],current[2],"m") else print(prev[5],prev[6],prev[3],prev[4],current[1],current[2],"c") end prev = current end -- close last to first if needed
And is the type of operation (line, curve,..) given by the number of values?
by analyzing using thresholds (one can just use "c" always, as "l" is an optimization) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Am 06.10.2013 00:37, schrieb Hans Hagen:
On 10/5/2013 5:52 PM, Peter Rolf wrote:
I played around with it, but I have problems to understand the format of the returned path.
Example: % -------- \setuppagenumber[state=stop]
\starttext \nopdfcompression
\startMPpage path p; p:= (20,20){up} .. {down}(200,100); passvariable("path",p); draw p ; \stopMPpage
\ctxlua{inspect{metapost.variables["path"]}} \stoptext % -------
The PDF code of the path is (mainly)
20.000000 20.000000 m 20.000000 190.342880 200.000000 184.016693 200.000000 100.000000 c
"path" contains
table={ { { 200, 100, 200, 184.0167, 200, 100 }, }, }
The end point and the second control point are the same, as in the PDF code. But how do I calculate the starting point and the first control point from the returned values?
something
local prev = nil for i=1,#path do local current = path[i] if not prev then print(current[1],current[2],"m") else print(prev[5],prev[6],prev[3],prev[4],current[1],current[2],"c") end prev = current end -- close last to first if needed
And is the type of operation (line, curve,..) given by the number of values?
by analyzing using thresholds (one can just use "c" always, as "l" is an optimization)
Hans
Thanks for the explanation. I think I have understood the scheme (but I might be wrong, because this doesn't help me with my example). Where is the starting point['20 20'] in the returned example path? Same is true for the first control point ['20 190.34']. Either I'm missing something, or the returned path data is incomplete. Peter
On 10/6/2013 3:05 PM, Peter Rolf wrote:
Thanks for the explanation. I think I have understood the scheme (but I might be wrong, because this doesn't help me with my example).
Where is the starting point['20 20'] in the returned example path? Same is true for the first control point ['20 190.34']. Either I'm missing something, or the returned path data is incomplete.
you get just the value of the path variable in your mp code, not a ps or whatever representation and in mp a path has just points so the starting point is the x y of the first point ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Am 06.10.2013 17:06, schrieb Hans Hagen:
On 10/6/2013 3:05 PM, Peter Rolf wrote:
Thanks for the explanation. I think I have understood the scheme (but I might be wrong, because this doesn't help me with my example).
Where is the starting point['20 20'] in the returned example path? Same is true for the first control point ['20 190.34']. Either I'm missing something, or the returned path data is incomplete.
you get just the value of the path variable in your mp code, not a ps or whatever representation and in mp a path has just points so the starting point is the x y of the first point
I tested several examples and the only time that the starting point was part of the returned path was, when the path only consists of one point. In all other cases it was missing. This is a bit contrary to my definition of a (complete) path. Anyhow, thanks for the pointer :-) Peter
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | 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://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
On Mon, Oct 7, 2013 at 10:48 AM, Peter Rolf
Am 06.10.2013 17:06, schrieb Hans Hagen:
On 10/6/2013 3:05 PM, Peter Rolf wrote:
Thanks for the explanation. I think I have understood the scheme (but I might be wrong, because this doesn't help me with my example).
Where is the starting point['20 20'] in the returned example path? Same is true for the first control point ['20 190.34']. Either I'm missing something, or the returned path data is incomplete.
you get just the value of the path variable in your mp code, not a ps or whatever representation and in mp a path has just points so the starting point is the x y of the first point
I tested several examples and the only time that the starting point was part of the returned path was, when the path only consists of one point. In all other cases it was missing.
This is a bit contrary to my definition of a (complete) path. Anyhow, thanks for the pointer :-)
in mp-mlib.mpiv should be : vardef mfun_path_to_string(expr p) = mfun_point_to_string(p,0) for i=1 upto length(p) : & " " & mfun_point_to_string(p,i) endfor enddef ; (You can fix it and rebuild the format. To understand the output, is better to know that mfun_point_to_string is vardef mfun_point_to_string(expr p,i) = decimal xpart (point i of p) & " " & decimal ypart (point i of p) & " " & decimal xpart (precontrol i of p) & " " & decimal ypart (precontrol i of p) & " " & decimal xpart (postcontrol i of p) & " " & decimal ypart (postcontrol i of p) enddef ; ) -- luigi
On 10/7/2013 11:47 AM, luigi scarso wrote:
(You can fix it and rebuild the format. To understand the output, is better to know that mfun_point_to_string is
no need to rebuild the format (at least not currently) as mp loads runtime the next beta will have (the somewhat useless) helper: \starttext \startluacode local result = metapost.quickanddirty("metafun",[[ draw fullcircle scaled 1cm ;]]) context("% t",result.bbox) context.par() context("% t",result.code) context.par() \stopluacode \stoptext ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Am 07.10.2013 11:47, schrieb luigi scarso:
On Mon, Oct 7, 2013 at 10:48 AM, Peter Rolf
mailto:indiego@gmx.net> wrote: Am 06.10.2013 17:06, schrieb Hans Hagen: > On 10/6/2013 3:05 PM, Peter Rolf wrote: > >> Thanks for the explanation. I think I have understood the scheme (but I >> might be wrong, because this doesn't help me with my example). >> >> Where is the starting point['20 20'] in the returned example path? Same >> is true for the first control point ['20 190.34']. Either I'm missing >> something, or the returned path data is incomplete. > > you get just the value of the path variable in your mp code, not a ps or > whatever representation and in mp a path has just points so the starting > point is the x y of the first point >
I tested several examples and the only time that the starting point was part of the returned path was, when the path only consists of one point. In all other cases it was missing.
This is a bit contrary to my definition of a (complete) path. Anyhow, thanks for the pointer :-)
in mp-mlib.mpiv should be : vardef mfun_path_to_string(expr p) = mfun_point_to_string(p,0) for i=1 upto length(p) : & " " & mfun_point_to_string(p,i) endfor enddef ;
(You can fix it and rebuild the format. To understand the output, is better to know that mfun_point_to_string is
vardef mfun_point_to_string(expr p,i) = decimal xpart (point i of p) & " " & decimal ypart (point i of p) & " " & decimal xpart (precontrol i of p) & " " & decimal ypart (precontrol i of p) & " " & decimal xpart (postcontrol i of p) & " " & decimal ypart (postcontrol i of p) enddef ;
)
-- luigi
@Luigi: thanks for the fix! @Hans: quickanddirty sounds promising (bbox is needed anyway) :-D
participants (3)
-
Hans Hagen
-
luigi scarso
-
Peter Rolf