summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/mlib-lmt.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2019-08-09 21:12:52 +0200
committerContext Git Mirror Bot <phg@phi-gamma.net>2019-08-09 21:12:52 +0200
commit76a1861b8ff7c2befbc41270833a4a0919c93c30 (patch)
tree0053915db1de56ac3da2a1415b5447bf66acd81f /tex/context/base/mkiv/mlib-lmt.lua
parente92fac1b64f7969cadd8ae60f336c43624250d42 (diff)
downloadcontext-76a1861b8ff7c2befbc41270833a4a0919c93c30.tar.gz
2019-08-09 18:36:00
Diffstat (limited to 'tex/context/base/mkiv/mlib-lmt.lua')
-rw-r--r--tex/context/base/mkiv/mlib-lmt.lua48
1 files changed, 48 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/mlib-lmt.lua b/tex/context/base/mkiv/mlib-lmt.lua
new file mode 100644
index 000000000..774ddc8e5
--- /dev/null
+++ b/tex/context/base/mkiv/mlib-lmt.lua
@@ -0,0 +1,48 @@
+if not modules then modules = { } end modules ['mlib-lmt'] = {
+ version = 1.001,
+ comment = "companion to mlib-ctx.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files",
+}
+
+local mppath = mp.path
+
+function mp.lmt_function_x(xmin,xmax,xstep,code,shape) -- experimental
+ local code = "return function(x) return " .. code .. " end"
+ local action = load(code)
+ local points = { }
+ local nofpoints = 0
+ if action then
+ action = action()
+ end
+ if shape == "steps" then
+ local halfx = xstep / 2
+ local lastx = xmin
+ local lasty = action(xmin)
+ for xi = xmin, xmax, xstep do
+ local yi = action(xi)
+ local xx = lastx + halfx
+ nofpoints = nofpoints + 1 ; points[nofpoints] = { xx, lasty }
+ nofpoints = nofpoints + 1 ; points[nofpoints] = { xx, yi }
+ lastx = xi
+ lasty = yi
+ end
+ if points[nofpoints][1] ~= xmax then
+ local yi = action(xmax)
+ local xx = lastx + halfx
+ nofpoints = nofpoints + 1 ; points[nofpoints] = { xx, lasty }
+ nofpoints = nofpoints + 1 ; points[nofpoints] = { xx, yi }
+ lastx = xi
+ lasty = yi
+ end
+ else
+ for xi = xmin, xmax, xstep do
+ nofpoints = nofpoints + 1 ; points[nofpoints] = { xi, action(xi) }
+ end
+ if points[nofpoints][1] ~= xmax then
+ nofpoints = nofpoints + 1 ; points[nofpoints] = { xmax, action(xmax) }
+ end
+ end
+ mppath(points,shape == "curve" and ".." or "--",false)
+end