mp-func.mpiv /size: 2822 b    last modification: 2020-07-01 14:35
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 16
if
known
context_func
:
endinput
;
fi
;
17 18
boolean
context_func
;
context_func
:
=
true
;
19 20
string
mfun_pathconnectors
[
]
;
21 22
mfun_pathconnectors
[
0
]
:
=
"
,
"
;
23
mfun_pathconnectors
[
1
]
:
=
"
--
"
;
24
mfun_pathconnectors
[
2
]
:
=
"
..
"
;
25
mfun_pathconnectors
[
3
]
:
=
"
...
"
;
26
mfun_pathconnectors
[
4
]
:
=
"
---
"
;
27 28
def
pathconnectors
=
mfun_pathconnectors
enddef
;
29 30
vardef
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
40
enddef
;
41 42
def
function
=
mfun_function
enddef
;
% let doesn't work here
43
def
constructedfunction
=
mfun_function
enddef
;
44
def
straightfunction
=
mfun_function
(
1
)
enddef
;
45
def
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 50
vardef
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
61
enddef
;
62 63
def
constructedpath
=
mfun_constructedpath
enddef
;
% let doesn't work here
64
def
straightpath
=
mfun_constructedpath
(
1
)
enddef
;
65
def
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 70
vardef
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
80
enddef
;
81 82
def
constructedpairs
=
mfun_constructedpairs
enddef
;
% let doesn't work here
83
def
straightpairs
=
mfun_constructedpairs
(
1
)
enddef
;
84
def
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