summaryrefslogtreecommitdiff
path: root/metapost/context/base/mp-func.mpiv
blob: 81b37fd1c2fd71b58bc70f7cbe23ff9ac8b713af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
%D \module
%D   [       file=mp-func.mpiv,
%D        version=2001.12.29,
%D          title=\CONTEXT\ \METAPOST\ graphics,
%D       subtitle=function hacks,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See licen-en.pdf for
%C details.

%D Under construction.

if known context_func : endinput ; fi ;

boolean context_func ; context_func := true ;

string mfun_pathconnectors[] ;

mfun_pathconnectors[0] := ","   ;
mfun_pathconnectors[1] := "--"  ;
mfun_pathconnectors[2] := ".."  ;
mfun_pathconnectors[3] := "..." ;
mfun_pathconnectors[4] := "---" ;

def pathconnectors = mfun_pathconnectors enddef ;

vardef mfun_function (expr f) (expr u, t, b, e, s) =
    save x ; numeric x ;
    for xx := b step s until e :
        hide (x := xx ;)
        if xx > b :
          scantokens(mfun_pathconnectors[f])
        fi
        (scantokens(u),scantokens(t))
    endfor
enddef ;

def function         = mfun_function     enddef ; % let doesn't work here
def straightfunction = mfun_function (1) enddef ;
def curvedfunction   = mfun_function (2) enddef ;

% def punkedfunction   = mfun_function (1) enddef ; % same as straightfunction
% def tightfunction    = mfun_function (3) enddef ; % same as curvedfunction

vardef mfun_constructedpath (expr f) (text t) =
    save ok ; boolean ok ; ok := false ;
    for i=t :
        if ok :
            scantokens(mfun_pathconnectors[f])
        else :
            ok := true ;
        fi
        i
    endfor
enddef ;

def constructedpath = mfun_constructedpath     enddef ; % let doesn't work here
def straightpath    = mfun_constructedpath (1) enddef ;
def curvedpath      = mfun_constructedpath (2) enddef ;

def punkedpath      = mfun_constructedpath (1) enddef ; % same as straightpath
def tightpath       = mfun_constructedpath (3) enddef ; % same as curvedpath

vardef mfun_constructedpairs (expr f) (text p) =
    save i ; i := -1 ;
    forever :
        exitif unknown p[incr(i)] ;
        if i>0 :
            scantokens(mfun_pathconnectors[f])
        fi
        p[i]
    endfor
enddef ;

def constructedpairs = mfun_constructedpairs     enddef ; % let doesn't work here
def straightpairs    = mfun_constructedpairs (1) enddef ;
def curvedpairs      = mfun_constructedpairs (2) enddef ;

def punkedpairs      = mfun_constructedpairs (1) enddef ; % same as straightpairs
def tightpairs       = mfun_constructedpairs (3) enddef ; % same as curvedpairs