mp-func.mpxl /size: 2887 b    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=mp-func.mpiv,
3%D        version=2001.12.29,
4%D          title=\CONTEXT\ \METAPOST\ graphics,
5%D       subtitle=function hacks,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See licen-en.pdf for
12%C details.
13
14%D Under construction.
15
16if known metafun_loaded_func : endinput ; fi ;
17
18newinternal boolean metafun_loaded_func ; metafun_loaded_func := true ; immutable metafun_loaded_func ;
19
20string mfun_pathconnectors[] ;
21
22mfun_pathconnectors[0] := ","   ;
23mfun_pathconnectors[1] := "--"  ;
24mfun_pathconnectors[2] := ".."  ;
25mfun_pathconnectors[3] := "..." ;
26mfun_pathconnectors[4] := "---" ;
27
28def pathconnectors = mfun_pathconnectors enddef ;
29
30vardef mfun_function (expr f) (expr u, t, b, e, s) =
31    save x ; numeric x ;
32    save c ; string c ; c := if string f : f else : mfun_pathconnectors[f] fi ;
33    for xx := b step s until e :
34        hide (x := xx ;)
35        if xx > b :
36          scantokens(c)
37        fi
38        (scantokens(u),scantokens(t))
39    endfor
40enddef ;
41
42def function            = mfun_function     enddef ; % let doesn't work here
43def constructedfunction = mfun_function     enddef ;
44def straightfunction    = mfun_function (1) enddef ;
45def curvedfunction      = mfun_function (2) enddef ;
46
47% def punkedfunction   = mfun_function (1) enddef ; % same as straightfunction
48% def tightfunction    = mfun_function (3) enddef ; % same as curvedfunction
49
50vardef mfun_constructedpath (expr f) (text t) =
51    save ok ; boolean ok ; ok := false ;
52    save c ; string c ; c := if string f : f else : mfun_pathconnectors[f] fi ;
53    for i=t :
54        if ok :
55            scantokens(c)
56        else :
57            ok := true ;
58        fi
59        i
60    endfor
61enddef ;
62
63def constructedpath = mfun_constructedpath     enddef ; % let doesn't work here
64def straightpath    = mfun_constructedpath (1) enddef ;
65def curvedpath      = mfun_constructedpath (2) enddef ;
66
67% def punkedpath      = mfun_constructedpath (1) enddef ; % same as straightpath
68% def tightpath       = mfun_constructedpath (3) enddef ; % same as curvedpath
69
70vardef mfun_constructedpairs (expr f) (text p) =
71    save i ; i := -1 ;
72    save c ; string c ; c := if string f : f else : mfun_pathconnectors[f] fi ;
73    forever :
74        exitif unknown p[incr(i)] ;
75        if i>0 :
76            scantokens(c)
77        fi
78        p[i]
79    endfor
80enddef ;
81
82def constructedpairs = mfun_constructedpairs     enddef ; % let doesn't work here
83def straightpairs    = mfun_constructedpairs (1) enddef ;
84def curvedpairs      = mfun_constructedpairs (2) enddef ;
85
86% def punkedpairs      = mfun_constructedpairs (1) enddef ; % same as straightpairs
87% def tightpairs       = mfun_constructedpairs (3) enddef ; % same as curvedpairs
88