1if not modules then modules = { } end modules [ ' meta-fun ' ] = {
2 version = 1 . 001 ,
3 comment = " companion to meta-fun.mkiv " ,
4 author = " Hans Hagen, PRAGMA-ADE, Hasselt NL " ,
5 copyright = " PRAGMA ADE / ConTeXt Development Team " ,
6 license = " see context related readme files " ,
7}
8
9
10
11local format , load , type = string . format , load , type
12
13local context = context
14local metapost = metapost
15
16metapost . metafun = metapost . metafun or { }
17local metafun = metapost . metafun
18
19function metafun . topath ( t , connector )
20 context ( " ( " )
21 if # t > 0 then
22 for i = 1 , # t do
23 if i > 1 then
24 context ( connector or " .. " )
25 end
26 local ti = t [ i ]
27 if type ( ti ) = = " string " then
28 context ( ti )
29 else
30 context ( " (%F,%F) " , ti . x or ti [ 1 ] or 0 , ti . y or ti [ 2 ] or 0 )
31 end
32 end
33 else
34 context ( " origin " )
35 end
36 context ( " ) " )
37end
38
39function metafun . interpolate ( f , b , e , s , c )
40 local done = false
41 context ( " ( " )
42 for i = b , e , ( e - b ) / s do
43 local d = load ( format ( " return function(x) return %s end " , f ) )
44 if d then
45 d = d ( )
46 if done then
47 context ( c or " ... " )
48 else
49 done = true
50 end
51 context ( " (%F,%F) " , i , d ( i ) )
52 end
53 end
54 if not done then
55 context ( " origin " )
56 end
57 context ( " ) " )
58end
59 |