diff options
Diffstat (limited to 'metapost')
-rw-r--r-- | metapost/context/base/mpiv/metafun.mpiv | 37 | ||||
-rw-r--r-- | metapost/context/base/mpiv/metafun.mpxl | 45 | ||||
-rw-r--r-- | metapost/context/base/mpiv/minifun.mpiv | 12 | ||||
-rw-r--r-- | metapost/context/base/mpiv/minifun.mpxl | 34 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-base.mpiv | 2 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-lmtx.mpxl | 538 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-luas.mpiv | 181 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-luas.mpxl | 223 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-math.mpxl | 153 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-tool.mpiv | 15 |
10 files changed, 1042 insertions, 198 deletions
diff --git a/metapost/context/base/mpiv/metafun.mpiv b/metapost/context/base/mpiv/metafun.mpiv index 5a47280c4..346642cac 100644 --- a/metapost/context/base/mpiv/metafun.mpiv +++ b/metapost/context/base/mpiv/metafun.mpiv @@ -23,34 +23,21 @@ mpprocset := 1 ; % not used input "mp-base.mpiv" ; input "mp-tool.mpiv" ; input "mp-mlib.mpiv" ; -% "mp-core.mpiv" ; % todo: namespace and cleanup -input "mp-luas.mpiv" ; % experimental -input "mp-page.mpiv" ; % todo: namespace and cleanup -input "mp-butt.mpiv" ; % todo: namespace and cleanup -input "mp-shap.mpiv" ; % will be improved -input "mp-grph.mpiv" ; % todo: namespace and cleanup -input "mp-grid.mpiv" ; % todo: namespace and cleanup -input "mp-form.mpiv" ; % under (re)construction -input "mp-figs.mpiv" ; % obsolete, needs checking -input "mp-func.mpiv" ; % under construction -% "mp-text.mpiv" ; % loaded on demand -% "mp-char.mpiv" ; % loaded on demand -% "mp-step.mpiv" ; % loaded on demand -% "mp-chem.mpiv" ; % loaded on demand -input "mp-node.mpiv" ; % relatively small so preloaded +input "mp-luas.mpiv" ; +input "mp-page.mpiv" ; +input "mp-butt.mpiv" ; +input "mp-shap.mpiv" ; +input "mp-grph.mpiv" ; +input "mp-grid.mpiv" ; +input "mp-form.mpiv" ; +input "mp-figs.mpiv" ; +input "mp-func.mpiv" ; +input "mp-node.mpiv" ; input "mp-apos.mpiv" ; input "mp-abck.mpiv" ; input "mp-blob.mpiv" ; -string metafunversion ; metafunversion = - "metafun iv" & " " & - decimal year & "-" & - decimal month & "-" & - decimal day & " " & - if ((time div 60) < 10) : "0" & fi - decimal (time div 60) & ":" & - if ((time-(time div 60)*60) < 10) : "0" & fi - decimal (time-(time div 60)*60) ; +string metafunversion ; metafunversion = "metafun iv " & mfun_timestamp; let normalend = end ; @@ -60,5 +47,3 @@ if known mplib : else : def end = ; message "" ; message metafunversion ; message "" ; normalend ; enddef ; fi ; - -% dump ; % obsolete in mplib diff --git a/metapost/context/base/mpiv/metafun.mpxl b/metapost/context/base/mpiv/metafun.mpxl new file mode 100644 index 000000000..93fb0ab82 --- /dev/null +++ b/metapost/context/base/mpiv/metafun.mpxl @@ -0,0 +1,45 @@ +%D \module +%D [ file=metafun.mp, +%D version=2000.07.15, +%D title=\CONTEXT\ \METAPOST\ graphics, +%D subtitle=format generation file, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA / Hans Hagen \& Ton Otten}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +%D First we input John Hobby's metapost plain file. However, because we want to +%D prevent dependency problems and in the end even may use a patched version, +%D we prefer to use a copy. + +boolean contextlmtxmode ; contextlmtxmode := if known fontmaking : false else: true fi; + +input "mp-base.mpiv" ; +input "mp-tool.mpiv" ; +input "mp-mlib.mpiv" ; +input "mp-luas.mpxl" ; +input "mp-math.mpxl" ; +input "mp-page.mpiv" ; +input "mp-butt.mpiv" ; +input "mp-shap.mpiv" ; +input "mp-grph.mpiv" ; +input "mp-grid.mpiv" ; +input "mp-form.mpiv" ; +input "mp-figs.mpiv" ; +input "mp-func.mpiv" ; +input "mp-node.mpiv" ; +input "mp-apos.mpiv" ; +input "mp-abck.mpiv" ; +input "mp-blob.mpiv" ; + +input "mp-lmtx.mpxl" ; % playground, not official + +string metafunversion ; metafunversion = "metafun xl " & mfun_timestamp; + +let normalend = end ; + +def end = ; message "" ; message metafunversion ; message "" ; endinput ; enddef ; +def bye = ; message "" ; message metafunversion ; message "" ; endinput ; enddef ; diff --git a/metapost/context/base/mpiv/minifun.mpiv b/metapost/context/base/mpiv/minifun.mpiv index ea4634c85..1aa496da2 100644 --- a/metapost/context/base/mpiv/minifun.mpiv +++ b/metapost/context/base/mpiv/minifun.mpiv @@ -25,15 +25,7 @@ input "mp-mlib.mpiv" ; input "mp-luas.mpiv" ; input "mp-page.mpiv" ; -string minifunversion ; minifunversion = - "minifun iv" & " " & - decimal year & "-" & - decimal month & "-" & - decimal day & " " & - if ((time div 60) < 10) : "0" & fi - decimal (time div 60) & ":" & - if ((time-(time div 60)*60) < 10) : "0" & fi - decimal (time-(time div 60)*60) ; +string minifunversion ; minifunversion = "minifun iv " & mfun_timestamp; let normalend = end ; @@ -43,5 +35,3 @@ if known mplib : else : def end = ; message "" ; message minifunversion ; message "" ; normalend ; enddef ; fi ; - -% dump ; % obsolete in mplib diff --git a/metapost/context/base/mpiv/minifun.mpxl b/metapost/context/base/mpiv/minifun.mpxl new file mode 100644 index 000000000..ff71bdfcc --- /dev/null +++ b/metapost/context/base/mpiv/minifun.mpxl @@ -0,0 +1,34 @@ +%D \module +%D [ file=minifun.mp, +%D version=2018.06.02, +%D title=\CONTEXT\ \METAPOST\ graphics, +%D subtitle=format generation file, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA / Hans Hagen \& Ton Otten}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +%D This is a minimal \METAFUN\ instance which can be handy for isolated +%D subruns. + +boolean contextlmtxmode ; contextlmtxmode := if known fontmaking : false else: true fi; + +prologues := 0 ; +mpprocset := 1 ; + +input "mp-base.mpiv" ; +input "mp-tool.mpiv" ; +input "mp-mlib.mpiv" ; +input "mp-luas.mpxl" ; +input "mp-math.mpxl" ; +input "mp-page.mpiv" ; + +string minifunversion ; minifunversion = "minifun xl " & mfun_timestamp; + +let normalend = end ; + +def end = ; message "" ; message minifunversion ; message "" ; endinput ; enddef ; +def bye = ; message "" ; message minifunversion ; message "" ; endinput ; enddef ; diff --git a/metapost/context/base/mpiv/mp-base.mpiv b/metapost/context/base/mpiv/mp-base.mpiv index 77e92e39b..36f2d1f5f 100644 --- a/metapost/context/base/mpiv/mp-base.mpiv +++ b/metapost/context/base/mpiv/mp-base.mpiv @@ -13,7 +13,7 @@ string base_name, base_version ; base_name := "plain" ; -base_version := "1.004 for metafun iv" ; +base_version := "1.004 for metafun iv and xl" ; message "loading metafun, including plain.mp version " & base_version ; diff --git a/metapost/context/base/mpiv/mp-lmtx.mpxl b/metapost/context/base/mpiv/mp-lmtx.mpxl new file mode 100644 index 000000000..42aa54f9f --- /dev/null +++ b/metapost/context/base/mpiv/mp-lmtx.mpxl @@ -0,0 +1,538 @@ +%D \module +%D [ file=mp-luas.lmtx, +%D version=2019.06.23, +%D title=\CONTEXT\ \METAPOST\ graphics, +%D subtitle=\LUA, +%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 mreadme.pdf for +%C details. + +% This is an experimental module where I test some new interface methods; +% for real advanced graphics use the luapost module. + +if known context_lmtx : endinput ; fi ; + +boolean context_lmtx ; context_lmtx := true ; + +presetparameters "grid" [ + nx = 1, dx = 1, + ny = 1, dy = 1, +] ; + +def lmt_grid = applyparameters "grid" "lmt_do_grid" enddef ; + +vardef lmt_do_grid = + image ( + save nx; nx := getparameter "grid" "nx" ; + save ny; ny := getparameter "grid" "ny" ; + save dx; dx := getparameter "grid" "dx" ; + save dy; dy := getparameter "grid" "dy" ; + for i = 0 step dx until nx : + draw ((0,0) -- (0,ny)) shifted (i,0) ; + endfor ; + for i = 0 step dy until ny : + draw ((0,0) -- (nx,0)) shifted (0,i) ; + endfor ; + ) +enddef ; + +def lmt_axis = applyparameters "axis" "lmt_do_axis" enddef ; + +presetparameters "axis" [ + nx = 1, dx = 1, tx = 0, sx = 1, startx = 0, + ny = 1, dy = 1, ty = 0, sy = 1, starty = 0, + + samples = { }, + list = { }, + connect = false, + list = [ close = false ], + samplecolors = { "" }, + axiscolor = "", + textcolor = "", +] ; + +% vardef lmt_do_axis = +% image ( +% save nx; nx := getparameter "axis" "nx" ; +% save ny; ny := getparameter "axis" "ny" ; +% save dx; dx := getparameter "axis" "dx" ; +% save dy; dy := getparameter "axis" "dy" ; +% save tx; tx := getparameter "axis" "tx" ; +% save ty; ty := getparameter "axis" "ty" ; +% save c, startx, starty ; string c ; +% c := getparameter "axis" "axiscolor" ; +% startx := getparameter "axis" "startx" ; +% starty := getparameter "axis" "starty" ; +% draw (startx,starty) -- (startx,ny) withcolor c ; +% draw (startx,starty) -- (nx,starty) withcolor c ; +% for i = 0 step dx until nx : +% if (i > startx) or (startx = 0) : +% draw ((0,0) -- (0,-2)) shifted (i,starty) withcolor c ; +% fi ; +% endfor ; +% for i = 0 step dy until ny : +% if (i > starty) or (starty = 0) : +% draw ((0,0) -- (-2,0)) shifted (startx,i) withcolor c ; +% fi ; +% endfor ; +% if tx <> 0 : +% c := getparameter "axis" "textcolor" ; +% for i = 0 step tx until nx : +% if (i > startx) or (startx = 0) : +% draw +% textext("\strut " & decimal i) ysized 2 shifted (i,-4+starty) +% withcolor c; +% fi ; +% endfor ; +% fi ; +% if ty <> 0 : +% c := getparameter "axis" "textcolor" ; +% for i = 0 step ty until ny : +% if (i > starty) or (starty = 0) : +% draw +% textext.lft("\strut " & decimal i) ysized 2 shifted (-3+startx,i) +% withcolor c; +% fi ; +% endfor ; +% fi ; +% +% if (getparametercount "axis" "samples") > 0 : +% if getparameter "axis" "connect" : +% for s = 1 upto getparametercount "axis" "samples" : +% c := getparameter "axis" "samplecolors" s ; +% draw for i = 1 upto getparametercount "axis" "samples" s : +% if (i > 1) : -- fi (i, getparameter "axis" "samples" s i) +% endfor +% withcolor c ; +% endfor ; +% else : +% for s = 1 upto getparametercount "axis" "samples" : +% c := getparameter "axis" "samplecolors" s ; +% for i = 1 upto getparametercount "axis" "samples" s : +% draw (i, getparameter "axis" "samples" s i) +% withcolor c ; +% endfor ; +% endfor ; +% fi ; +% fi ; +% +% if (getparametercount "axis" "list") > 0 : +% +% path p ; numeric ts ; pair a, d ; +% +% ts := (getparameter "axis" "sy") / 20 ; +% +% for s = 1 upto getparametercount "axis" "list" : +% +% c := getparameter "axis" "list" s "color" ; +% +% p := for i = 1 upto getparametercount "axis" "list" s "points" : +% if (i > 1) : -- fi (getparameter "axis" "list" s "points" i) +% endfor +% if (getparameterdefault "axis" "list" s "close" false) : -- cycle fi ; +% +% draw p withcolor c ; +% +% if (getparametercount "axis" "list" s "labels") > 0 : +% for i = 1 upto getparametercount "axis" "list" s "labels" : +% draw +% textext(getparameterdefault "axis" "list" s "labels" i "") +% ysized ts +% shifted unitvector(direction (i-eps) of p) % todo +% shifted point i of p ; +% endfor ; +% fi ; +% +% % if (getparametercount "axis" "list" s "texts") > 0 : +% % for i = 1 upto getparametercount "axis" "list" s "texts" : +% % n := i + 0.5 ; +% % a := point n of p ; +% % d := direction n of p ; +% % draw textext.d(getparameterdefault "axis" "list" s "texts" i "") +% % if d < left : rotated 180 shifted (0,-5) else : shifted (0,5) fi +% % ysized ts +% % shifted a +% % rotatedaround(a,angle(d)) ; +% % endfor ; +% % fi ; +% +% pushparameters "axis" "list" s "texts" ; +% if (getparametercount) > 0 : +% for i = 1 upto getparametercount : +% n := i + 0.5 ; +% a := point n of p ; +% d := direction n of p ; +% draw textext.d(getparameterdefault i "") +% if d < left : rotated 180 shifted (0,-5) else : shifted (0,5) fi +% ysized ts +% shifted a +% rotatedaround(a,angle(d)) ; +% endfor ; +% fi ; +% popparameters ; +% +% endfor ; +% fi ; +% +% ) +% xyscaled(getparameter "axis" "sx",getparameter "axis" "sy") +% enddef ; + +vardef lmt_do_axis = + image ( + pushparameters "axis" ; + + save nx; nx := getparameter "nx" ; + save ny; ny := getparameter "ny" ; + save dx; dx := getparameter "dx" ; + save dy; dy := getparameter "dy" ; + save tx; tx := getparameter "tx" ; + save ty; ty := getparameter "ty" ; + save c, startx, starty ; string c ; + c := getparameter "axiscolor" ; + startx := getparameter "startx" ; + starty := getparameter "starty" ; + draw (startx,starty) -- (startx,ny) withcolor c ; + draw (startx,starty) -- (nx,starty) withcolor c ; + for i = 0 step dx until nx : + if (i > startx) or (startx = 0) : + draw ((0,0) -- (0,-2)) shifted (i,starty) withcolor c ; + fi ; + endfor ; + for i = 0 step dy until ny : + if (i > starty) or (starty = 0) : + draw ((0,0) -- (-2,0)) shifted (startx,i) withcolor c ; + fi ; + endfor ; + if tx <> 0 : + c := getparameter "textcolor" ; + for i = 0 step tx until nx : + if (i > startx) or (startx = 0) : + draw + textext("\strut " & decimal i) ysized 2 shifted (i,-4+starty) + withcolor c; + fi ; + endfor ; + fi ; + if ty <> 0 : + c := getparameter "textcolor" ; + for i = 0 step ty until ny : + if (i > starty) or (starty = 0) : + draw + textext.lft("\strut " & decimal i) ysized 2 shifted (-3+startx,i) + withcolor c; + fi ; + endfor ; + fi ; + + if (getparametercount "samples") > 0 : + if getparameter "connect" : + for s = 1 upto getparametercount "samples" : + c := getparameter "samplecolors" s ; + draw for i = 1 upto getparametercount "samples" s : + if (i > 1) : -- fi (i, getparameter "samples" s i) + endfor + withcolor c ; + endfor ; + else : + for s = 1 upto getparametercount "samples" : + c := getparameter "samplecolors" s ; + for i = 1 upto getparametercount "samples" s : + draw (i, getparameter "samples" s i) + withcolor c ; + endfor ; + endfor ; + fi ; + fi ; + + if (getparametercount "list") > 0 : + + path p ; numeric ts ; pair a, d ; + + ts := (getparameter "sy") / 20 ; + + pushparameters "list" ; + for s = 1 upto getparametercount : + pushparameters s ; + + c := getparameter "color" ; + + % p := for i = 1 upto getparametercount "points": + % if (i > 1) : -- fi (getparameter "points" i) + % endfor + % if (getparameterdefault "close" false) : -- cycle fi ; + + % this can become: + + % p := if (getparameterdefault "close" false) : + % % getparameterpath "points" "--" true ; + % getparameterpath "points" true ; + % else : + % % getparameterpath "points" "--" false ; + % getparameterpath "points" ; + % fi ; + + % p := getparameterpath "points" if (getparameterdefault "close" false) : true fi ; + + p := getparameterpath "points" (getparameterdefault "close" false) ; + % p := getparameterpath "points" getparameterdefault "close" false ; + + draw p withcolor c ; + + pushparameters "labels" ; + if (getparametercount) > 0 : + for i = 1 upto getparametercount: + n := i - 1 ; + a := point n of p ; + d := direction n of p ; + draw + textext(getparametertext i true) + ysized ts + shifted (a + .5 * unitvector(d) rotated 90) ; + endfor ; + fi ; + popparameters ; + + pushparameters "texts" ; + if (getparametercount) > 0 : + for i = 1 upto getparametercount : + n := i + 0.5 ; + a := point n of p ; + d := direction n of p ; + draw textext.d(getparametertext i true) + if d < left : rotated 180 shifted (0,-5) else : shifted (0,5) fi + ysized ts + shifted a + rotatedaround(a,angle(d)) ; + endfor ; + fi ; + popparameters ; + + popparameters ; + endfor ; + popparameters ; + fi ; + + popparameters ; + + ) + xyscaled(getparameter "axis" "sx",getparameter "axis" "sy") +enddef ; + +presetparameters "outline" [ + content = "", + kind = "draw", + fillcolor = "", + drawcolor = "", + rulethickness = 1/10, + align = "", + style = "", + width = 0, +] ; + +def lmt_outline = applyparameters "outline" "lmt_do_outline" enddef ; + +vardef lmt_do_outline = + image ( normaldraw image ( + save kind ; string kind ; kind := getparameter "outline" "kind" ; + save align ; string align ; align := getparameter "outline" "align" ; + save style ; string style ; style := getparameter "outline" "style" ; + save width ; numeric width ; width := getparameter "outline" "width" ; + if kind = "draw" : + kind := "d" ; + elseif kind = "fill" : + kind := "f" ; + elseif kind = "both" : + kind := "b" ; + elseif kind = "reverse" : + kind := "r" ; + fi ; + currentoutlinetext := currentoutlinetext + 1 ; + lua.mp.mf_outline_text( + currentoutlinetext, + if align = "" : + getparameter "outline" "content", + else : + "\framed[align={" & align & "}" + if width > 0 : + & ",width=" & decimal width & "bp" + fi + if style <> "" : + & ",foregroundstyle=" & style + fi + & ",offset=none,frame=off]{" + & (getparameter "outline" "content") + & "}", + fi, + kind + ) ; + save currentpen; pen currentpen ; + pickup pencircle scaled getparameter "outline" "rulethickness" ; + if kind = "f" : + mfun_do_outline_text_set_f ( + withcolor getparameter "outline" "fillcolor" + ); + elseif kind = "d" : + mfun_do_outline_text_set_d ( + withcolor getparameter "outline" "drawcolor" + ); + elseif kind = "b" : + mfun_do_outline_text_set_b ( + withcolor getparameter "outline" "fillcolor" + ) ( + withcolor getparameter "outline" "drawcolor" + ); + elseif kind = "u" : + mfun_do_outline_text_set_f ( + withcolor getparameter "outline" "fillcolor" + ); + elseif kind = "r" : + mfun_do_outline_text_set_r ( + withcolor getparameter "outline" "drawcolor" + ) ( + withcolor getparameter "outline" "fillcolor" + ) ; + elseif kind = "p" : + mfun_do_outline_text_set_p ; + else : + mfun_do_outline_text_set_n ( + % what to use here + ); + fi ; + lua.mp.mf_get_outline_text(currentoutlinetext) ; + ) ) +enddef ; + +presetparameters "followtext" [ + content = "", + spread = true, + trace = false, + reverse = false, + autoscaleup = "no", + autoscaledown = "no", + path = (fullcircle), +] ; + +def lmt_followtext = applyparameters "followtext" "lmt_do_followtext" enddef ; + +vardef lmt_do_followtext = + image ( + save s_u ; string s_u ; s_u := getparameter "followtext" "autoscaleup" ; + save s_d ; string s_d ; s_d := getparameter "followtext" "autoscaledown" ; + save followtextalternative ; followtextalternative := if getparameter "followtext" "spread" : 1 else : 0 fi ; + save tracingfollowtext ; tracingfollowtext := if getparameter "followtext" "trace" : 1 else : 0 fi ; + save autoscaleupfollowtext ; autoscaleupfollowtext := if s_u = "yes" : 1 elseif s_u = "max" : 2 else : 0 fi ; + save autoscaledownfollowtext ; autoscaledownfollowtext := if s_d = "yes" : 1 elseif s_d = "max" : 2 else : 0 fi ; + draw followtext ( + if (getparameter "followtext" "reverse") : reverse fi getparameter "followtext" "path", + getparameter "followtext" "content" + ) ; + ) +enddef ; + +presetparameters "arrow" [ + path = origin, + kind = "fill", + dimple = 1/5, + scale = 3/4, + length = 4, + angle = 45, + location = "end", % middle both + alternative = "normal", % dimpled curved + percentage = 50, + headonly = false, +] ; + +def lmt_arrow = applyparameters "arrow" "lmt_do_arrow" enddef ; + +vardef lmt_do_arrow = + image ( + save a ; string a ; a := getparameter "arrow" "alternative" ; + save l ; string l ; l := getparameter "arrow" "location" ; + save k ; string k ; k := getparameter "arrow" "kind" ; + save p ; path p ; p := getparameter "arrow" "path" ; + save ahvariant ; ahvariant := if a = "dimpled" : 1 elseif a = "curved" : 2 else : 0 fi ; + save ahdimple ; ahdimple := getparameter "arrow" "dimple" ; + save ahscale ; ahscale := getparameter "arrow" "scale" ; + save ahangle ; ahangle := getparameter "arrow" "angle" ; + save ahlength ; ahlength := getparameter "arrow" "length" ; + if not getparameter "arrow" "headonly" : + draw p ; + fi ; + if k = "draw" : draw elseif k = "both" : filldraw else : fill fi + if l = "middle" : + midarrowhead p ; + elseif l = "percentage" : + arrowheadonpath (p, (getparameter "arrow" "percentage")/100) ; + elseif l = "both" : + arrowhead p ; + if k = "draw" : draw elseif k = "both" : filldraw else : fill fi + arrowhead reverse p ; + else : + arrowhead p ; + fi ; + ) +enddef ; + +% from dum + +presetparameters "placeholder" [ + color = "red", + width = 1, + height = 1, + reduction = 0, + alternative = "circle", +] ; + +def lmt_placeholder = applyparameters "placeholder" "lmt_do_placeholder" enddef ; + +def lmt_do_placeholder = + begingroup ; + save w, h, d, r, p, c, b, s, q, a ; + numeric w, h, d, r ; path p ; string s, a ; + s := getparameter "placeholder" "color" ; + w := getparameter "placeholder" "width" ; + h := getparameter "placeholder" "height" ; + r := getparameter "placeholder" "reduction" ; + a := getparameter "placeholder" "alternative" ; + d := max(w,h) ; + if cmykcolor resolvedcolor(s) : + cmykcolor c, b ; b := (0,0,0,0) + else : + color c, b ; b := (1,1,1) + fi ; + c := resolvedcolor(s) ; + p := unitsquare xyscaled (w,h) ; + fill p withcolor r[.5c,b] ; + if a = "square" : + vardef q = fullsquare enddef ; + elseif a = "triangle" : + vardef q = fulltriangle rotated (90 * round(uniformdeviate(4))) enddef ; + else : + vardef q = fullcircle enddef ; + fi ; + for i := 1 upto 60 : + fill q + scaled (d/5 randomized (d/5)) + shifted (center p randomized (d)) + withcolor r[c randomized(.3,.9),b] ; + endfor ; + clip currentpicture to p ; + endgroup ; +enddef ; + +% maybe: + +vardef lmt_connected(text t) = + save p ; path p ; + p := origin t ; + subpath (1,length(p)) of p +enddef; + +def lmt_connection expr t = + -- t +enddef; diff --git a/metapost/context/base/mpiv/mp-luas.mpiv b/metapost/context/base/mpiv/mp-luas.mpiv index 235f713ba..57937c0c1 100644 --- a/metapost/context/base/mpiv/mp-luas.mpiv +++ b/metapost/context/base/mpiv/mp-luas.mpiv @@ -20,52 +20,10 @@ if known context_luas : endinput ; fi ; % get passed. Of course in the end the real usage got a bit beyong the intended % usage. So, in addition to some definitions here there are and will be use in % other metafun modules too. Of course in retrospect I should have done this five -% years earlier. +% years earlier. Older version sof this module show the way it evolved. boolean context_luas ; context_luas := true ; -% Experimental - -if contextlmtxmode : - - % not yet (timing issue) - - newinternal mfid_scriptindex ; - mfid_scriptindex := runscript("mp.mf_script_index('scriptindex')") ; - - def scriptindex = runscript mfid_scriptindex enddef ; - -% def scriptindex expr name = -% lua.mp.mf_script_index(name) -% enddef ; - -fi ; - -% First variant: -% -% let lua = runscript ; -% -% Second variant: -% -% vardef lua (text t) = -% runscript(for s = t : s & endfor "") -% enddef; -% -% Third variant: -% -% vardef lua (text t) = -% runscript("" for s = t : -% if string s : -% & s -% elseif numeric s : -% & decimal s -% elseif boolean s : -% & if s : "true" else "false" fi -% fi endfor) -% enddef; -% -% Fourth variant: - string mfun_lua_bs ; mfun_lua_bs := "[===[" ; string mfun_lua_es ; mfun_lua_es := "]===]" ; @@ -92,35 +50,6 @@ vardef mlib_luas_luacall(text t) = ) enddef ; -% vardef mlib_luas_lualist(expr c)(text t) = -% save b ; boolean b ; b := false ; -% runscript(c & "(" for s = t : -% if b : -% & "," -% else : -% hide(b := true) -% fi -% if string s : -% % & ditto & s & ditto -% & mfun_lua_bs & s & mfun_lua_es -% elseif numeric s : -% & decimal s -% elseif boolean s : -% & if s : "true" else : "false" fi -% elseif pair s : -% & mfun_pair_to_table(s) -% elseif path s : -% & mfun_path_to_table(s) -% elseif rgbcolor s : -% & mfun_rgb_to_table(s) -% elseif cmykcolor s : -% & mfun_cmyk_to_table(s) -% else : -% & ditto & tostring(s) & ditto -% fi endfor & ")" -% ) -% enddef ; - newinternal mfun_luas_b ; def mlib_luas_luadone = @@ -189,23 +118,13 @@ enddef ; % lua.mp.mf_named_color(s) % okay but, can also be % lua.mp("mf_named_color",s) % which gives expansion mess -if contextlmtxmode : - - newinternal mfid_resolvedcolor ; mfid_resolvedcolor := scriptindex "namedcolor" ; - - def resolvedcolor = runscript mfid_resolvedcolor enddef ; - -else : - - def resolvedcolor primary s = % no vardef - if string s : - runscript("mp.mf_named_color('" & s & "')") % faster anyway - else : - s - fi - enddef ; - -fi ; +def resolvedcolor primary s = % no vardef + if string s : + runscript("mp.mf_named_color('" & s & "')") % faster anyway + else : + s + fi +enddef ; % Modes: @@ -257,77 +176,25 @@ vardef texstr(expr name) = lua.mp.texstr(name) enddef ; %D New experimental feature for Alan-The-Number-Cruncher: -if contextlmtxmode : - - newinternal mfid_path_lengthof ; mfid_path_lengthof := scriptindex "pathlengthof" ; - newinternal mfid_path_pointof ; mfid_path_pointof := scriptindex "pathpointof" ; - newinternal mfid_path_leftof ; mfid_path_leftof := scriptindex "pathleftof" ; - newinternal mfid_path_rightof ; mfid_path_rightof := scriptindex "pathrightof" ; - newinternal mfid_path_reset ; mfid_path_reset := scriptindex "pathreset" ; - - % 25 pct gain - - def inpath = = 1 step 1 until runscript mfid_path_lengthof enddef ; - vardef pointof primary i = runscript mfid_path_pointof i enddef ; - vardef leftof primary i = runscript mfid_path_leftof i enddef ; - vardef rightof primary i = runscript mfid_path_rightof i enddef ; - - % another 10 pct gain - - % def inpath = = 1 step 1 until runscript mfid_path_lengthof enddef ; - % def pointof = runscript mfid_path_pointof enddef ; - % def leftof = runscript mfid_path_leftof enddef ; - % def rightof = runscript mfid_path_rightof enddef ; - - extra_endfig := extra_endfig & " runscript mfid_path_reset ; " ; - -else : - - def inpath suffix p = % permits p[0] - = 1 step 1 until - begingroup - save mfun_inpath_r,mfun_inpath_n ; path mfun_inpath_r ; - mfun_inpath_r = p ; - mfun_inpath_n := lua.mp.mf_path_length(str mfun_inpath_r) ; - if mfun_inpath_n = 0 : 1 else : mfun_inpath_n fi - endgroup - enddef ; - - % vardef pointof primary i = lua.mp.mf_path_point(i) enddef ; - % vardef leftof primary i = lua.mp.mf_path_left (i) enddef ; - % vardef rightof primary i = lua.mp.mf_path_right(i) enddef ; +def inpath suffix p = % permits p[0] + = 1 step 1 until + begingroup + save mfun_inpath_r,mfun_inpath_n ; path mfun_inpath_r ; + mfun_inpath_r = p ; + mfun_inpath_n := lua.mp.mf_path_length(str mfun_inpath_r) ; + if mfun_inpath_n = 0 : 1 else : mfun_inpath_n fi + endgroup +enddef ; - vardef pointof primary i = runscript("mp.mf_path_point(" & decimal i & ")") enddef ; - vardef leftof primary i = runscript("mp.mf_path_left(" & decimal i & ")") enddef ; - vardef rightof primary i = runscript("mp.mf_path_right(" & decimal i & ")") enddef ; +% vardef pointof primary i = lua.mp.mf_path_point(i) enddef ; +% vardef leftof primary i = lua.mp.mf_path_left (i) enddef ; +% vardef rightof primary i = lua.mp.mf_path_right(i) enddef ; - extra_endfig := extra_endfig & " lua.mp.mf_path_reset() ; " ; +vardef pointof primary i = runscript("mp.mf_path_point(" & decimal i & ")") enddef ; +vardef leftof primary i = runscript("mp.mf_path_left(" & decimal i & ")") enddef ; +vardef rightof primary i = runscript("mp.mf_path_right(" & decimal i & ")") enddef ; -fi ; +extra_endfig := extra_endfig & " lua.mp.mf_path_reset() ; " ; vardef utflen(expr s) = lua.mp.utflen(s) enddef ; vardef utfsub(expr s,f,t) = lua.mp.utfsub(s,f,t) enddef ; - -if contextlmtxmode : - - newinternal mfid_getparameters ; mfid_getparameters := scriptindex "getparameters" ; - newinternal mfid_presetparameters ; mfid_presetparameters := scriptindex "presetparameters" ; - newinternal mfid_getparameter ; mfid_getparameter := scriptindex "getparameter" ; - newinternal mfid_getparametercount ; mfid_getparametercount := scriptindex "getparametercount" ; - newinternal mfid_getparameterentry ; mfid_getparameterentry := scriptindex "getparameterentry" ; - newinternal mfid_getparametersets ; mfid_getparametersets := scriptindex "getparametersets" ; - newinternal mfid_getparametersetcount ; mfid_getparametersetcount := scriptindex "getparametersetcount" ; - newinternal mfid_getparametersetentry ; mfid_getparametersetentry := scriptindex "getparametersetentry" ; - newinternal mfid_applyparameters ; mfid_applyparameters := scriptindex "applyparameters" ; - - def getparameters = runscript mfid_getparameters enddef ; - def presetparameters = runscript mfid_presetparameters enddef ; - def getparameter = runscript mfid_getparameter enddef ; - def getparametercount = runscript mfid_getparametercount enddef ; - def getparameterentry = runscript mfid_getparameterentry enddef ; - def getparametersets = runscript mfid_getparametersets enddef ; - def getparametersetcount = runscript mfid_getparametersetcount enddef ; - def getparametersetentry = runscript mfid_getparametersetentry enddef ; - def applyparameters = runscript mfid_applyparameters enddef ; - -fi ; diff --git a/metapost/context/base/mpiv/mp-luas.mpxl b/metapost/context/base/mpiv/mp-luas.mpxl new file mode 100644 index 000000000..0dac5cefc --- /dev/null +++ b/metapost/context/base/mpiv/mp-luas.mpxl @@ -0,0 +1,223 @@ +%D \module +%D [ file=mp-luas.mpiv, +%D version=2014.04.14, +%D title=\CONTEXT\ \METAPOST\ graphics, +%D subtitle=\LUA, +%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 mreadme.pdf for +%C details. + +if known context_luas : endinput ; fi ; + +% When I prototyped the runscript primitive I was just thinking of a usage like +% the original \directlua primitive in luatex: genererate something and pipe +% that back to metapost, and have access to some internals. Instead of compiling +% the code a the metapost end here we delegate that to the lua end. Only strings +% get passed. Of course in the end the real usage got a bit beyong the intended +% usage. So, in addition to some definitions here there are and will be use in +% other metafun modules too. Of course in retrospect I should have done this five +% years earlier. + +boolean context_luas ; context_luas := true ; + +newinternal mfid_scriptindex ; +mfid_scriptindex := runscript("mp.mf_script_index('scriptindex')") ; + +def scriptindex = runscript mfid_scriptindex enddef ; + +string mfun_lua_bs ; mfun_lua_bs := "[===[" ; +string mfun_lua_es ; mfun_lua_es := "]===]" ; + +vardef mlib_luas_luacall(text t) = + runscript("" for s = t : + if string s : + & s + % & mfun_lua_bs & s & mfun_lua_es + elseif numeric s : + & decimal s + elseif boolean s : + & if s : "true" else : "false" fi + elseif pair s : + & mfun_pair_to_table(s) + elseif path s : + & mfun_path_to_table(s) + elseif rgbcolor s : + & mfun_rgb_to_table(s) + elseif cmykcolor s : + & mfun_cmyk_to_table(s) + else : + & ditto & tostring(s) & ditto + fi endfor + ) +enddef ; + +newinternal mfun_luas_b ; + +def mlib_luas_luadone = + exitif numeric begingroup mfun_luas_b := 1 ; endgroup ; +enddef ; + +vardef mlib_luas_lualist(expr c)(text t) = % we could use mlib_luas_s instead of c + interim mfun_luas_b := 0 ; + runscript(c & for s = t : + if mfun_luas_b = 0 : + "(" + % hide(mfun_luas_b := 1) + mlib_luas_luadone + else : + "," + fi + & + if string s : + mfun_lua_bs & s & mfun_lua_es + elseif numeric s : + decimal s + elseif boolean s : + if s : "true" else : "false" fi + elseif pair s : + mfun_pair_to_table(s) + elseif path s : + mfun_path_to_table(s) + elseif rgbcolor s : + mfun_rgb_to_table(s) + elseif cmykcolor s : + mfun_cmyk_to_table(s) + else : + ditto & tostring(s) & ditto + fi & endfor if mfun_luas_b = 0 : "()" else : ")" fi + ) +enddef ; + +def luacall = mlib_luas_luacall enddef ; % why no let + +vardef lualist@#(text t) = mlib_luas_lualist(str @#)(t) enddef ; + +string mlib_luas_s ; % saves save/restore + +vardef lua@#(text t) = + mlib_luas_s := str @# ; + if length(mlib_luas_s) > 0 : + mlib_luas_lualist(mlib_luas_s,t) + else : + mlib_luas_luacall(t) + fi +enddef ; + +vardef MP@#(text t) = + mlib_luas_lualist("MP." & str @#,t) +enddef ; + +def message expr t = + lua.mp.report(tostring(t)) ; +enddef ; + +% Color: + +% We do a low level runscript: +% +% lua.mp.namedcolor(s) % conflicts with macro namedcolor +% lua.mp.mf_named_color(s) % okay but, can also be +% lua.mp("mf_named_color",s) % which gives expansion mess + +newinternal mfid_resolvedcolor ; mfid_resolvedcolor := scriptindex "namedcolor" ; + +def resolvedcolor = runscript mfid_resolvedcolor enddef ; + +% Modes: + +vardef texmode (expr s) = lua.mp("mode", s) enddef ; +vardef systemmode(expr s) = lua.mp("systemmode",s) enddef ; + +% A few helpers + +vardef isarray suffix a = lua.mp.isarray (str a) enddef ; +vardef prefix suffix a = lua.mp.prefix (str a) enddef ; +vardef dimension suffix a = lua.mp.dimension(str a) enddef ; + +% More access + +vardef getmacro(expr k) = lua.mp._get_macro_(k) enddef ; +vardef getdimen(expr k) = lua.mp._get_dimen_(k) enddef ; +vardef getcount(expr k) = lua.mp._get_count_(k) enddef ; +vardef gettoks (expr k) = lua.mp._get_toks_ (k) enddef ; + +def setmacro(expr k,v) = lua.mp._set_macro_(k,v) enddef ; +def setdimen(expr k,v) = lua.mp._set_dimen_(k,v) enddef ; +def setcount(expr k,v) = lua.mp._set_count_(k,v) enddef ; +def settoks (expr k,v) = lua.mp._set_toks_ (k,v) enddef ; + +vardef positionpath (expr name) = lua.mp.positionpath (name) enddef ; +vardef positioncurve (expr name) = lua.mp.positioncurve (name) enddef ; +vardef positionxy (expr name) = lua.mp.positionxy (name) enddef ; +vardef positionpxy (expr name) = lua.mp.positionpxy (name) enddef ; +vardef positionwhd (expr name) = lua.mp.positionwhd (name) enddef ; +vardef positionpage (expr name) = lua.mp.positionpage (name) enddef ; +vardef positionregion(expr name) = lua.mp.positionregion(name) enddef ; +vardef positionbox (expr name) = lua.mp.positionbox (name) enddef ; +vardef positionanchor = lua.mp.positionanchor() enddef ; + +let wdpart = redpart ; +let htpart = greenpart ; +let dppart = bluepart ; + +vardef positioninregion = + currentpicture := currentpicture shifted - positionxy(positionanchor) ; +enddef ; + +vardef positionatanchor(expr name) = + currentpicture := currentpicture shifted - positionxy(name) ; +enddef ; + +vardef texvar(expr name) = lua.mp.texvar(name) enddef ; +vardef texstr(expr name) = lua.mp.texstr(name) enddef ; + +newinternal mfid_path_lengthof ; mfid_path_lengthof := scriptindex "pathlengthof" ; +newinternal mfid_path_pointof ; mfid_path_pointof := scriptindex "pathpointof" ; +newinternal mfid_path_leftof ; mfid_path_leftof := scriptindex "pathleftof" ; +newinternal mfid_path_rightof ; mfid_path_rightof := scriptindex "pathrightof" ; +newinternal mfid_path_reset ; mfid_path_reset := scriptindex "pathreset" ; + +% 25 pct gain + + def inpath = = 1 step 1 until runscript mfid_path_lengthof enddef ; +vardef pointof primary i = runscript mfid_path_pointof i enddef ; +vardef leftof primary i = runscript mfid_path_leftof i enddef ; +vardef rightof primary i = runscript mfid_path_rightof i enddef ; + +% another 10 pct gain + +% def inpath = = 1 step 1 until runscript mfid_path_lengthof enddef ; +% def pointof = runscript mfid_path_pointof enddef ; +% def leftof = runscript mfid_path_leftof enddef ; +% def rightof = runscript mfid_path_rightof enddef ; + +extra_endfig := extra_endfig & " runscript mfid_path_reset ; " ; + +vardef utflen(expr s) = lua.mp.utflen(s) enddef ; +vardef utfsub(expr s,f,t) = lua.mp.utfsub(s,f,t) enddef ; + +newinternal mfid_getparameters ; mfid_getparameters := scriptindex "getparameters" ; +newinternal mfid_presetparameters ; mfid_presetparameters := scriptindex "presetparameters" ; +newinternal mfid_getparameter ; mfid_getparameter := scriptindex "getparameter" ; +newinternal mfid_getparameterdefault ; mfid_getparameterdefault := scriptindex "getparameterdefault" ; +newinternal mfid_getparametercount ; mfid_getparametercount := scriptindex "getparametercount" ; +newinternal mfid_getparameterpath ; mfid_getparameterpath := scriptindex "getparameterpath" ; +newinternal mfid_getparametertext ; mfid_getparametertext := scriptindex "getparametertext" ; +newinternal mfid_applyparameters ; mfid_applyparameters := scriptindex "applyparameters" ; +newinternal mfid_pushparameters ; mfid_pushparameters := scriptindex "pushparameters" ; +newinternal mfid_popparameters ; mfid_popparameters := scriptindex "popparameters" ; + +def getparameters = runscript mfid_getparameters enddef ; +def presetparameters = runscript mfid_presetparameters enddef ; +def getparameter = runscript mfid_getparameter enddef ; +def getparameterdefault = runscript mfid_getparameterdefault enddef ; +def getparametercount = runscript mfid_getparametercount enddef ; +def getparameterpath = runscript mfid_getparameterpath enddef ; +def getparametertext = runscript mfid_getparametertext enddef ; +def applyparameters = runscript mfid_applyparameters enddef ; +def pushparameters = runscript mfid_pushparameters enddef ; +def popparameters = runscript mfid_popparameters enddef ; diff --git a/metapost/context/base/mpiv/mp-math.mpxl b/metapost/context/base/mpiv/mp-math.mpxl new file mode 100644 index 000000000..52fbd1615 --- /dev/null +++ b/metapost/context/base/mpiv/mp-math.mpxl @@ -0,0 +1,153 @@ +%D \module +%D [ file=mp-math.mpiv, +%D version=2019.07.26, % was mp-core: 1999.08.01, anchoring +%D title=\CONTEXT\ \METAPOST\ graphics, +%D subtitle=extra math functions, +%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 mreadme.pdf for +%C details. + +if known context_math : endinput ; fi ; + +boolean context_math ; context_math := true ; + +% draw textext(decimal runscript("mp.numeric(xmath.gamma(.12))")) ; + +newinternal mfid_m_acos ; mfid_m_acos := scriptindex "m_acos" ; def m_acos = runscript mfid_m_acos enddef ; +newinternal mfid_m_acosh ; mfid_m_acosh := scriptindex "m_acosh" ; def m_acosh = runscript mfid_m_acosh enddef ; +newinternal mfid_m_asin ; mfid_m_asin := scriptindex "m_asin" ; def m_asin = runscript mfid_m_asin enddef ; +newinternal mfid_m_asinh ; mfid_m_asinh := scriptindex "m_asinh" ; def m_asinh = runscript mfid_m_asinh enddef ; +newinternal mfid_m_atan ; mfid_m_atan := scriptindex "m_atan" ; def m_atan = runscript mfid_m_atan enddef ; +newinternal mfid_m_atantwo ; mfid_m_atantwo := scriptindex "m_atan2" ; def m_atantwo = runscript mfid_m_atantwo enddef ; % atan2 +newinternal mfid_m_atanh ; mfid_m_atanh := scriptindex "m_atanh" ; def m_atanh = runscript mfid_m_atanh enddef ; +newinternal mfid_m_cbrt ; mfid_m_cbrt := scriptindex "m_cbrt" ; def m_cbrt = runscript mfid_m_cbrt enddef ; +newinternal mfid_m_ceil ; mfid_m_ceil := scriptindex "m_ceil" ; def m_ceil = runscript mfid_m_ceil enddef ; +newinternal mfid_m_copysign ; mfid_m_copysign := scriptindex "m_copysign" ; def m_copysign = runscript mfid_m_copysign enddef ; +newinternal mfid_m_cos ; mfid_m_cos := scriptindex "m_cos" ; def m_cos = runscript mfid_m_cos enddef ; +newinternal mfid_m_cosh ; mfid_m_cosh := scriptindex "m_cosh" ; def m_cosh = runscript mfid_m_cosh enddef ; +newinternal mfid_m_deg ; mfid_m_deg := scriptindex "m_deg" ; def m_deg = runscript mfid_m_deg enddef ; +newinternal mfid_m_erf ; mfid_m_erf := scriptindex "m_erf" ; def m_erf = runscript mfid_m_erf enddef ; +newinternal mfid_m_erfc ; mfid_m_erfc := scriptindex "m_erfc" ; def m_erfc = runscript mfid_m_erfc enddef ; +newinternal mfid_m_exp ; mfid_m_exp := scriptindex "m_exp" ; def m_exp = runscript mfid_m_exp enddef ; +newinternal mfid_m_exptwo ; mfid_m_exptwo := scriptindex "m_exp2" ; def m_exptwo = runscript mfid_m_exptwo enddef ; % exp2 +newinternal mfid_m_expm ; mfid_m_expm := scriptindex "m_expm1" ; def m_expm = runscript mfid_m_expm enddef ; % expm1 +newinternal mfid_m_fabs ; mfid_m_fabs := scriptindex "m_fabs" ; def m_fabs = runscript mfid_m_fabs enddef ; +newinternal mfid_m_fdim ; mfid_m_fdim := scriptindex "m_fdim" ; def m_fdim = runscript mfid_m_fdim enddef ; +newinternal mfid_m_floor ; mfid_m_floor := scriptindex "m_floor" ; def m_floor = runscript mfid_m_floor enddef ; +newinternal mfid_m_fma ; mfid_m_fma := scriptindex "m_fma" ; def m_fma = runscript mfid_m_fma enddef ; +newinternal mfid_m_fmax ; mfid_m_fmax := scriptindex "m_fmax" ; def m_fmax = runscript mfid_m_fmax enddef ; +newinternal mfid_m_fmin ; mfid_m_fmin := scriptindex "m_fmin" ; def m_fmin = runscript mfid_m_fmin enddef ; +newinternal mfid_m_fmod ; mfid_m_fmod := scriptindex "m_fmod" ; def m_fmod = runscript mfid_m_fmod enddef ; +newinternal mfid_m_frexp ; mfid_m_frexp := scriptindex "m_frexp" ; def m_frexp = runscript mfid_m_frexp enddef ; +newinternal mfid_m_gamma ; mfid_m_gamma := scriptindex "m_gamma" ; def m_gamma = runscript mfid_m_gamma enddef ; +newinternal mfid_m_hypot ; mfid_m_hypot := scriptindex "m_hypot" ; def m_hypot = runscript mfid_m_hypot enddef ; +newinternal mfid_m_isfinite ; mfid_m_isfinite := scriptindex "m_isfinite" ; def m_isfinite = runscript mfid_m_isfinite enddef ; +newinternal mfid_m_isinf ; mfid_m_isinf := scriptindex "m_isinf" ; def m_isinf = runscript mfid_m_isinf enddef ; +newinternal mfid_m_isnan ; mfid_m_isnan := scriptindex "m_isnan" ; def m_isnan = runscript mfid_m_isnan enddef ; +newinternal mfid_m_isnormal ; mfid_m_isnormal := scriptindex "m_isnormal" ; def m_isnormal = runscript mfid_m_isnormal enddef ; +newinternal mfid_m_jz ; mfid_m_jz := scriptindex "m_j0" ; def m_jz = runscript mfid_m_jz enddef ; % j0 +newinternal mfid_m_j ; mfid_m_j := scriptindex "m_j1" ; def m_j = runscript mfid_m_j enddef ; % j1 +newinternal mfid_m_jn ; mfid_m_jn := scriptindex "m_jn" ; def m_jn = runscript mfid_m_jn enddef ; +newinternal mfid_m_ldexp ; mfid_m_ldexp := scriptindex "m_ldexp" ; def m_ldexp = runscript mfid_m_ldexp enddef ; +newinternal mfid_m_lgamma ; mfid_m_lgamma := scriptindex "m_lgamma" ; def m_lgamma = runscript mfid_m_lgamma enddef ; +newinternal mfid_m_log ; mfid_m_log := scriptindex "m_log" ; def m_log = runscript mfid_m_log enddef ; +newinternal mfid_m_logten ; mfid_m_logte := scriptindex "m_log10" ; def m_logten = runscript mfid_m_logten enddef ; % log10 +newinternal mfid_m_logp ; mfid_m_logp := scriptindex "m_log1p" ; def m_logp = runscript mfid_m_logp enddef ; % log1p +newinternal mfid_m_logtwo ; mfid_m_logtwo := scriptindex "m_log2" ; def m_logtwo = runscript mfid_m_logtwo enddef ; % log2 +newinternal mfid_m_logb ; mfid_m_logb := scriptindex "m_logb" ; def m_logb = runscript mfid_m_logb enddef ; +newinternal mfid_m_modf ; mfid_m_modf := scriptindex "m_modf" ; def m_modf = runscript mfid_m_modf enddef ; +newinternal mfid_m_nearbyint ; mfid_m_nearbyint := scriptindex "m_nearbyint" ; def m_nearbyint = runscript mfid_m_nearbyint enddef ; +newinternal mfid_m_nextafter ; mfid_m_nextafter := scriptindex "m_nextafter" ; def m_nextafter = runscript mfid_m_nextafter enddef ; +newinternal mfid_m_pow ; mfid_m_pow := scriptindex "m_pow" ; def m_pow = runscript mfid_m_pow enddef ; +newinternal mfid_m_rad ; mfid_m_rad := scriptindex "m_rad" ; def m_rad = runscript mfid_m_rad enddef ; +newinternal mfid_m_remainder ; mfid_m_remainder := scriptindex "m_remainder" ; def m_remainder = runscript mfid_m_remainder enddef ; +newinternal mfid_m_remquo ; mfid_m_remquo := scriptindex "m_remquo" ; def m_remquo = runscript mfid_m_remquo enddef ; +newinternal mfid_m_round ; mfid_m_round := scriptindex "m_round" ; def m_round = runscript mfid_m_round enddef ; +newinternal mfid_m_scalbn ; mfid_m_scalbn := scriptindex "m_scalbn" ; def m_scalbn = runscript mfid_m_scalbn enddef ; +newinternal mfid_m_sin ; mfid_m_sin := scriptindex "m_sin" ; def m_sin = runscript mfid_m_sin enddef ; +newinternal mfid_m_sinh ; mfid_m_sinh := scriptindex "m_sinh" ; def m_sinh = runscript mfid_m_sinh enddef ; +newinternal mfid_m_sqrt ; mfid_m_sqrt := scriptindex "m_sqrt" ; def m_sqrt = runscript mfid_m_sqrt enddef ; +newinternal mfid_m_tan ; mfid_m_tan := scriptindex "m_tan" ; def m_tan = runscript mfid_m_tan enddef ; +newinternal mfid_m_tanh ; mfid_m_tanh := scriptindex "m_tanh" ; def m_tanh = runscript mfid_m_tanh enddef ; +newinternal mfid_m_tgamma ; mfid_m_tgamma := scriptindex "m_tgamma" ; def m_tgamma = runscript mfid_m_tgamma enddef ; +newinternal mfid_m_trunc ; mfid_m_trunc := scriptindex "m_trunc" ; def m_trunc = runscript mfid_m_trunc enddef ; +newinternal mfid_m_yz ; mfid_m_yz := scriptindex "m_y0" ; def m_yz = runscript mfid_m_yz enddef ; % y0 +newinternal mfid_m_y ; mfid_m_y := scriptindex "m_y1" ; def m_y = runscript mfid_m_y enddef ; % y1 +newinternal mfid_m_yn ; mfid_m_yn := scriptindex "m_yn" ; def m_yn = runscript mfid_m_yn enddef ; + +newinternal mfid_c_sin ; mfid_c_asin := scriptindex "c_sin" ; def c_sin = runscript mfid_c_sin enddef ; +newinternal mfid_c_cos ; mfid_c_acos := scriptindex "c_cos" ; def c_cos = runscript mfid_c_cos enddef ; +newinternal mfid_c_tan ; mfid_c_acos := scriptindex "c_tan" ; def c_tan = runscript mfid_c_tan enddef ; +newinternal mfid_c_sinh ; mfid_c_acos := scriptindex "c_sinh" ; def c_sinh = runscript mfid_c_sinh enddef ; +newinternal mfid_c_cosh ; mfid_c_acos := scriptindex "c_cosh" ; def c_cosh = runscript mfid_c_cosh enddef ; +newinternal mfid_c_tanh ; mfid_c_acos := scriptindex "c_tanh" ; def c_tanh = runscript mfid_c_tanh enddef ; + +newinternal mfid_c_asin ; mfid_c_acos := scriptindex "c_asin" ; def c_asin = runscript mfid_c_asin enddef ; +newinternal mfid_c_acos ; mfid_c_acos := scriptindex "c_acos" ; def c_acos = runscript mfid_c_acos enddef ; +newinternal mfid_c_atan ; mfid_c_acos := scriptindex "c_atan" ; def c_atan = runscript mfid_c_atan enddef ; +newinternal mfid_c_asinh ; mfid_c_acos := scriptindex "c_asinh" ; def c_asinh = runscript mfid_c_asinh enddef ; +newinternal mfid_c_acosh ; mfid_c_acos := scriptindex "c_acosh" ; def c_acosh = runscript mfid_c_acosh enddef ; +newinternal mfid_c_atanh ; mfid_c_acos := scriptindex "c_atanh" ; def c_atanh = runscript mfid_c_atanh enddef ; + +newinternal mfid_c_sqrt ; mfid_c_acos := scriptindex "c_sqrt" ; def c_sqrt = runscript mfid_c_sqrt enddef ; +newinternal mfid_c_abs ; mfid_c_acos := scriptindex "c_abs" ; def c_abs = runscript mfid_c_abs enddef ; +newinternal mfid_c_arg ; mfid_c_acos := scriptindex "c_arg" ; def c_arg = runscript mfid_c_arg enddef ; +newinternal mfid_c_conj ; mfid_c_acos := scriptindex "c_conj" ; def c_conj = runscript mfid_c_conj enddef ; +newinternal mfid_c_exp ; mfid_c_acos := scriptindex "c_exp" ; def c_exp = runscript mfid_c_exp enddef ; +newinternal mfid_c_log ; mfid_c_acos := scriptindex "c_log" ; def c_log = runscript mfid_c_log enddef ; +newinternal mfid_c_proj ; mfid_c_acos := scriptindex "c_proj" ; def c_proj = runscript mfid_c_proj enddef ; + +newinternal mfid_c_erf ; mfid_c_erf := scriptindex "c_erf" ; def c_erf = runscript mfid_c_erf enddef ; +newinternal mfid_c_erfc ; mfid_c_erfc := scriptindex "c_erfc" ; def c_erfc = runscript mfid_c_erfc enddef ; +newinternal mfid_c_erfcx ; mfid_c_erfcx := scriptindex "c_erfcx" ; def c_erfcx = runscript mfid_c_erfcx enddef ; +newinternal mfid_c_erfi ; mfid_c_erfi := scriptindex "c_erfi" ; def c_erfi = runscript mfid_c_erfi enddef ; + +% mfid_c_imag ; mfid_c_acos := scriptindex "c_imag" ; def c_imag = runscript mfid_c_imag enddef ; +% mfid_c_real ; mfid_c_acos := scriptindex "c_real" ; def c_real = runscript mfid_c_real enddef ; +% mfid_c_neg ; mfid_c_neg := scriptindex "c_neg" ; def c_neg = runscript mfid_c_neg enddef ; + +newinternal mfid_c_pow ; mfid_c_pow := scriptindex "c_pow" ; def c_pow (expr a,b) = runscript mfid_c_pow a b enddef ; +% mfid_c_add ; mfid_c_add := scriptindex "c_add" ; def c_add (expr a,b) = runscript mfid_c_add a b enddef ; +% mfid_c_sub ; mfid_c_sub := scriptindex "c_sub" ; def c_sub (expr a,b) = runscript mfid_c_sub a b enddef ; +newinternal mfid_c_mul ; mfid_c_mul := scriptindex "c_mul" ; def c_mul (expr a,b) = runscript mfid_c_mul a b enddef ; +newinternal mfid_c_div ; mfid_c_div := scriptindex "c_div" ; def c_div (expr a,b) = runscript mfid_c_div a b enddef ; + +newinternal mfid_c_voigt ; mfid_c_voigt := scriptindex "c_voigt" ; def c_voigt (expr a,b,c) = runscript mfid_c_voigt a b c enddef ; +newinternal mfid_c_voigt_hwhm ; mfid_c_voigt_hwhm := scriptindex "c_voigt_hwhm" ; def c_voigt_hwhm(expr a,b) = runscript mfid_c_voigt_hwhm a b enddef ; + +vardef c_add (expr a, b) = a + b enddef ; +vardef c_sub (expr a, b) = a + b enddef ; +vardef c_imag(expr a) = ypart a enddef ; +vardef c_real(expr a) = xpart a enddef ; +vardef c_neg (expr a) = -a enddef ; + +% to be redefined: + +% vardef sqr primary x = x*x enddef ; +% vardef log primary x = if x=0: 0 else: mlog(x)/mlog(10) fi enddef ; +% vardef ln primary x = if x=0: 0 else: mlog(x)/256 fi enddef ; +% vardef exp primary x = (mexp 256)**x enddef ; +% vardef inv primary x = if x=0: 0 else: x**-1 fi enddef ; + +% vardef tand primary x = sind(x)/cosd(x) enddef ; +% vardef cotd primary x = cosd(x)/sind(x) enddef ; + +% vardef invsin primary x = (asin(x))/radian enddef ; +% vardef invcos primary x = (acos(x))/radian enddef ; +% vardef invtan primary x = (atan(x))/radian enddef ; + +% vardef sin primary x = m_sin x enddef ; vardef sinh primary x = m_sinh x enddef ; +% vardef cos primary x = m_cos x enddef ; vardef cosh primary x = m_cosh x enddef ; +% vardef tan primary x = m_tan x enddef ; vardef tanh primary x = m_tanh x enddef ; +% vardef asin primary x = m_asin x enddef ; vardef asinh primary x = m_asinh x enddef ; +% vardef acos primary x = m_acos x enddef ; vardef acosh primary x = m_acosh x enddef ; +% vardef atan primary x = m_atan x enddef ; vardef atanh primary x = m_atanh x enddef ; + +% vardef sind primary x = angle(m_sin x) enddef ; vardef asind primary x = angle(m_asin x) enddef ; +% vardef cosd primary x = angle(m_cos x) enddef ; vardef acosd primary x = angle(m_acos x) enddef ; +% vardef tand primary x = angle(m_tan x) enddef ; vardef atand primary x = angle(m_atan x) enddef ; + diff --git a/metapost/context/base/mpiv/mp-tool.mpiv b/metapost/context/base/mpiv/mp-tool.mpiv index f1f31e5f0..2442beb1c 100644 --- a/metapost/context/base/mpiv/mp-tool.mpiv +++ b/metapost/context/base/mpiv/mp-tool.mpiv @@ -445,7 +445,7 @@ vardef sinh primary x = save xx ; xx = exp x ; (xx-1/xx)/2 enddef ; vardef cosh primary x = save xx ; xx = exp x ; (xx+1/xx)/2 enddef ; vardef tanh primary x = save xx ; xx = exp x ; (xx-1/xx)/(xx+1/xx) enddef ; -%D Like mod, but useful for anglesl it returns (-.5d,+.5d] and is used +%D Like mod, but useful for angles, it returns (-.5d,+.5d] and is used %D in for instance mp-chem. primarydef a zmod b = (-((b/2 - a) mod b) + b/2) enddef ; @@ -1875,8 +1875,7 @@ def rightarrow (expr pat,tim,len) = pointarrow(pat,tim,len,-len) enddef ; def leftarrow (expr pat,tim,len) = pointarrow(pat,tim,len,+len) enddef ; def centerarrow (expr pat,tim,len) = pointarrow(pat,tim,len, 0) enddef ; -%D The \type {along} and \type {on} operators can be used -%D as follows: +%D The \type {along} and \type {on} operators can be used as follows: %D %D \starttyping %D drawdot point .5 along somepath ; @@ -3629,3 +3628,13 @@ enddef ; % endfor; % n % enddef; + +vardef mfun_timestamp = + decimal year & "-" & + decimal month & "-" & + decimal day & " " & + if ((time div 60) < 10) : "0" & fi + decimal (time div 60) & ":" & + if ((time-(time div 60)*60) < 10) : "0" & fi + decimal (time-(time div 60)*60) +enddef ; |