From fd8697791360a26a2b9cc888dbc125cefedfcd42 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Sun, 29 Sep 2019 16:35:50 +0200 Subject: 2019-09-29 14:42:00 --- .../documents/general/manuals/luametafun.pdf | Bin 1514692 -> 1900844 bytes doc/context/documents/general/qrcs/setup-cs.pdf | Bin 887655 -> 887655 bytes doc/context/documents/general/qrcs/setup-de.pdf | Bin 889580 -> 889352 bytes doc/context/documents/general/qrcs/setup-en.pdf | Bin 893435 -> 893435 bytes doc/context/documents/general/qrcs/setup-fr.pdf | Bin 885603 -> 885608 bytes doc/context/documents/general/qrcs/setup-it.pdf | Bin 891252 -> 891253 bytes .../documents/general/qrcs/setup-mapping-cs.pdf | Bin 383751 -> 383751 bytes .../documents/general/qrcs/setup-mapping-de.pdf | Bin 471430 -> 471471 bytes .../documents/general/qrcs/setup-mapping-en.pdf | Bin 380397 -> 380397 bytes .../documents/general/qrcs/setup-mapping-fr.pdf | Bin 384093 -> 384095 bytes .../documents/general/qrcs/setup-mapping-it.pdf | Bin 383246 -> 383246 bytes .../documents/general/qrcs/setup-mapping-nl.pdf | Bin 382225 -> 382230 bytes .../documents/general/qrcs/setup-mapping-ro.pdf | Bin 620289 -> 620289 bytes doc/context/documents/general/qrcs/setup-nl.pdf | Bin 881208 -> 881207 bytes doc/context/documents/general/qrcs/setup-ro.pdf | Bin 885570 -> 885570 bytes .../manuals/luametafun/luametafun-surface.tex | 110 ++++++++++ .../general/manuals/luametafun/luametafun.tex | 9 +- metapost/context/base/mpiv/mp-lmtx.mpxl | 96 ++++++++- metapost/context/base/mpiv/mp-mlib.mpiv | 5 + tex/context/base/mkii/cont-new.mkii | 2 +- tex/context/base/mkii/context.mkii | 2 +- tex/context/base/mkii/mult-cs.mkii | 1 + tex/context/base/mkiv/cont-new.mkiv | 2 +- tex/context/base/mkiv/context.mkiv | 2 +- tex/context/base/mkiv/context.mkxl | 2 +- tex/context/base/mkiv/mlib-cnt.lua | 221 ++++++++++++++++++++- tex/context/base/mkiv/mlib-ctx.mkiv | 2 +- tex/context/base/mkiv/status-files.pdf | Bin 26690 -> 26684 bytes tex/context/base/mkiv/status-lua.pdf | Bin 267983 -> 268841 bytes tex/context/interface/mkii/keys-cs.xml | 1 + tex/context/interface/mkiv/i-context.pdf | Bin 893435 -> 893435 bytes tex/context/interface/mkiv/i-readme.pdf | Bin 61165 -> 61165 bytes tex/generic/context/luatex/luatex-fonts-merged.lua | 2 +- 33 files changed, 432 insertions(+), 25 deletions(-) create mode 100644 doc/context/sources/general/manuals/luametafun/luametafun-surface.tex diff --git a/doc/context/documents/general/manuals/luametafun.pdf b/doc/context/documents/general/manuals/luametafun.pdf index e2b99ab2f..cc530630e 100644 Binary files a/doc/context/documents/general/manuals/luametafun.pdf and b/doc/context/documents/general/manuals/luametafun.pdf differ diff --git a/doc/context/documents/general/qrcs/setup-cs.pdf b/doc/context/documents/general/qrcs/setup-cs.pdf index d2f987d97..20a61013b 100644 Binary files a/doc/context/documents/general/qrcs/setup-cs.pdf and b/doc/context/documents/general/qrcs/setup-cs.pdf differ diff --git a/doc/context/documents/general/qrcs/setup-de.pdf b/doc/context/documents/general/qrcs/setup-de.pdf index 320d8ca11..12f539a54 100644 Binary files a/doc/context/documents/general/qrcs/setup-de.pdf and b/doc/context/documents/general/qrcs/setup-de.pdf differ diff --git a/doc/context/documents/general/qrcs/setup-en.pdf b/doc/context/documents/general/qrcs/setup-en.pdf index 5c0fba19a..f76346da3 100644 Binary files a/doc/context/documents/general/qrcs/setup-en.pdf and b/doc/context/documents/general/qrcs/setup-en.pdf differ diff --git a/doc/context/documents/general/qrcs/setup-fr.pdf b/doc/context/documents/general/qrcs/setup-fr.pdf index 30c60469e..176571e80 100644 Binary files a/doc/context/documents/general/qrcs/setup-fr.pdf and b/doc/context/documents/general/qrcs/setup-fr.pdf differ diff --git a/doc/context/documents/general/qrcs/setup-it.pdf b/doc/context/documents/general/qrcs/setup-it.pdf index f02842253..ac7d33b6a 100644 Binary files a/doc/context/documents/general/qrcs/setup-it.pdf and b/doc/context/documents/general/qrcs/setup-it.pdf differ diff --git a/doc/context/documents/general/qrcs/setup-mapping-cs.pdf b/doc/context/documents/general/qrcs/setup-mapping-cs.pdf index fb720a611..e91b973d2 100644 Binary files a/doc/context/documents/general/qrcs/setup-mapping-cs.pdf and b/doc/context/documents/general/qrcs/setup-mapping-cs.pdf differ diff --git a/doc/context/documents/general/qrcs/setup-mapping-de.pdf b/doc/context/documents/general/qrcs/setup-mapping-de.pdf index 225593507..8dc0271b8 100644 Binary files a/doc/context/documents/general/qrcs/setup-mapping-de.pdf and b/doc/context/documents/general/qrcs/setup-mapping-de.pdf differ diff --git a/doc/context/documents/general/qrcs/setup-mapping-en.pdf b/doc/context/documents/general/qrcs/setup-mapping-en.pdf index ad12ac66c..1323e0a59 100644 Binary files a/doc/context/documents/general/qrcs/setup-mapping-en.pdf and b/doc/context/documents/general/qrcs/setup-mapping-en.pdf differ diff --git a/doc/context/documents/general/qrcs/setup-mapping-fr.pdf b/doc/context/documents/general/qrcs/setup-mapping-fr.pdf index 07e1a5f7c..296fb3395 100644 Binary files a/doc/context/documents/general/qrcs/setup-mapping-fr.pdf and b/doc/context/documents/general/qrcs/setup-mapping-fr.pdf differ diff --git a/doc/context/documents/general/qrcs/setup-mapping-it.pdf b/doc/context/documents/general/qrcs/setup-mapping-it.pdf index 97b9586f7..14a763fce 100644 Binary files a/doc/context/documents/general/qrcs/setup-mapping-it.pdf and b/doc/context/documents/general/qrcs/setup-mapping-it.pdf differ diff --git a/doc/context/documents/general/qrcs/setup-mapping-nl.pdf b/doc/context/documents/general/qrcs/setup-mapping-nl.pdf index 3a7de7431..803262009 100644 Binary files a/doc/context/documents/general/qrcs/setup-mapping-nl.pdf and b/doc/context/documents/general/qrcs/setup-mapping-nl.pdf differ diff --git a/doc/context/documents/general/qrcs/setup-mapping-ro.pdf b/doc/context/documents/general/qrcs/setup-mapping-ro.pdf index 9f837fa1b..b67a37612 100644 Binary files a/doc/context/documents/general/qrcs/setup-mapping-ro.pdf and b/doc/context/documents/general/qrcs/setup-mapping-ro.pdf differ diff --git a/doc/context/documents/general/qrcs/setup-nl.pdf b/doc/context/documents/general/qrcs/setup-nl.pdf index 1718a6b3d..05c21c685 100644 Binary files a/doc/context/documents/general/qrcs/setup-nl.pdf and b/doc/context/documents/general/qrcs/setup-nl.pdf differ diff --git a/doc/context/documents/general/qrcs/setup-ro.pdf b/doc/context/documents/general/qrcs/setup-ro.pdf index 6682a9bcb..7434d5d3a 100644 Binary files a/doc/context/documents/general/qrcs/setup-ro.pdf and b/doc/context/documents/general/qrcs/setup-ro.pdf differ diff --git a/doc/context/sources/general/manuals/luametafun/luametafun-surface.tex b/doc/context/sources/general/manuals/luametafun/luametafun-surface.tex new file mode 100644 index 000000000..427187f95 --- /dev/null +++ b/doc/context/sources/general/manuals/luametafun/luametafun-surface.tex @@ -0,0 +1,110 @@ +% language=us + +\environment luametafun-style + +\startcomponent luametafun-surface + +\startchapter[title={Surface}] + +This is work in progress so only some examples are shown here. Yet to be decided +is how we deal with axis and such. + +In \in {figure} [surface:1] we see an example of a plot with axis as well as +lines drawn. + +\startbuffer[1] +\startMPcode{doublefun} + draw lmt_surface [ + preamble = "local sin, cos = math.sin, math.cos", + code = "sin(x*x) - cos(y*y)" + xmin = -3, + xmax = 3, + ymin = -3, + ymax = 3, + xvector = { -0.3, -0.3 }, + height = 5cm, + axis = { 40mm, 40mm, 30mm }, + clipaxis = true, + axiscolor = "gray", + ] xsized .8TextWidth ; +\stopMPcode +\stopbuffer + +\typebuffer[1] + +\startplacefigure[reference=surface:1] + \getbuffer[1] +\stopplacefigure + +In \in {figure} [surface:2] we don't draw the axis and lines. We also use a high +resolution. + +\startbuffer[2] +\startMPcode{doublefun} + draw lmt_surface [ + preamble = "local sin, cos = math.sin, math.cos", + code = "sin(x*x) - cos(y*y)" + color = "f, f/2, 1-f" + color = "f, f, 0" + xstep = .02, + ystep = .02, + xvector = { -0.4, -0.4 }, + height = 5cm, + lines = false, + ] xsized .8TextWidth ; +\stopMPcode +\stopbuffer + +\typebuffer[2] + +\startplacefigure[reference=surface:2] + \getbuffer[2] +\stopplacefigure + +The preliminary set of parameters is: + +\starttabulate[|T|T|T|p|] +\FL +\BC name \BC type \BC default \BC comment \NC \NR +\ML +\NC code \NC string \NC +\NC color \NC string \NC \type {"f, 0, 0"} \NC \NC \NR +\NC linecolor \NC numeric \NC \type {1} \NC gray scale \NC \NR +\NC xmin \NC numeric \NC \type {-1} \NC \NC \NR +\NC xmax \NC numeric \NC \type { 1} \NC \NC \NR +\NC ymin \NC numeric \NC \type {-1} \NC \NC \NR +\NC ymax \NC numeric \NC \type { 1} \NC \NC \NR +\NC xstep \NC numeric \NC \type {.1} \NC \NC \NR +\NC ystep \NC numeric \NC \type {.1} \NC \NC \NR +\NC snap \NC numeric \NC \type {.01} \NC \NC \NR +\NC xvector \NC list \NC \type {{ -0.7, -0.7 }} \NC \NC \NR +\NC yvector \NC list \NC \type {{ 1, 0 }} \NC \NC \NR +\NC zvector \NC list \NC \type {{ 0, 1 }} \NC \NC \NR +\NC light \NC list \NC \type {{ 3, 3, 10 }} \NC \NC \NR +\NC bright \NC numeric \NC \type {100} \NC \NC \NR +\NC clip \NC boolean \NC \type {false} \NC \NC \NR +\NC lines \NC boolean \NC \type {true} \NC \NC \NR +\NC axis \NC list \NC \type {{ }} \NC \NC \NR +\NC clipaxis \NC boolean \NC \type {false} \NC \NC \NR +\NC axiscolor \NC string \NC \type {"gray"} \NC \NC \NR +\NC axislinewidth \NC numeric \NC \type {1/2} \NC \NC \NR +\LL +\stoptabulate + +\startplacefigure[reference=contour:10] + \startcombination[3*3] + {\getbuffer[10a]} {\bf bitmap edge} + {\getbuffer[10b]} {\bf bitmap cell} + {\getbuffer[10c]} {\bf bitmap none} + {\getbuffer[10d]} {\bf shape shape} + {\getbuffer[10e]} {\bf shape edge} + {\getbuffer[10f]} {\bf shape none} + {\getbuffer[10g]} {\bf band edge} + {\getbuffer[10h]} {\bf band cell} + {\getbuffer[10i]} {\bf band none} + \stopcombination +\stopplacefigure + +\stopchapter + +\stopcomponent diff --git a/doc/context/sources/general/manuals/luametafun/luametafun.tex b/doc/context/sources/general/manuals/luametafun/luametafun.tex index 0e298dcd0..6f5aff173 100644 --- a/doc/context/sources/general/manuals/luametafun/luametafun.tex +++ b/doc/context/sources/general/manuals/luametafun/luametafun.tex @@ -13,17 +13,18 @@ \startbodymatter \component luametafun-text - \component luametafun-function - \component luametafun-contour % \component luametafun-grid \component luametafun-axis \component luametafun-outline \component luametafun-followtext \component luametafun-placeholder \component luametafun-arrow - \component luametafun-chart - \component luametafun-mesh \component luametafun-shade + \component luametafun-contour + \component luametafun-surface + \component luametafun-mesh + \component luametafun-function + \component luametafun-chart \component luametafun-svg \component luametafun-interface \stopbodymatter diff --git a/metapost/context/base/mpiv/mp-lmtx.mpxl b/metapost/context/base/mpiv/mp-lmtx.mpxl index 359c60921..46f399dc9 100644 --- a/metapost/context/base/mpiv/mp-lmtx.mpxl +++ b/metapost/context/base/mpiv/mp-lmtx.mpxl @@ -1496,10 +1496,9 @@ presetparameters "contour" [ def lmt_contour = applyparameters "contour" "lmt_do_contour" enddef ; -boolean lmx_contour_loaded ; lmx_contour_loaded := false ; - def mfun_only_draw = addto currentpicture doublepath enddef ; def mfun_only_fill = addto currentpicture contour enddef ; +def mfun_only_fillup text t = addto currentpicture doublepath t withpostscript "both" enddef ; def mfun_only_nodraw text t = addto currentpicture doublepath t withpostscript "collect" enddef ; def mfun_only_nofill text t = addto currentpicture contour t withpostscript "evenodd" enddef ; def mfun_only_eofill text t = addto currentpicture contour t withpostscript "collect" enddef ; @@ -1508,10 +1507,13 @@ def lmt_do_contour_shortcuts = save D ; let D = mfun_only_draw ; save E ; let E = mfun_only_eofill ; save F ; let F = mfun_only_fill ; + save U ; let U = mfun_only_fillup ; save d ; let d = mfun_only_nodraw ; save e ; let f = mfun_only_eofill ; save f ; let f = mfun_only_nofill ; save C ; let C = cycle ; + save B ; let B = controls ; + save A ; let A = and ; enddef ; def lmt_do_contour_band = @@ -1638,15 +1640,17 @@ def lmt_do_contour_shades(expr outlines) = fi ; enddef ; +def lmt_load_mlib_cnt = + runscript("lua.registercode('mlib-cnt')"); + extra_beginfig := extra_beginfig & % todo: use different hook + "runscript(" & ditto & "mp.lmt_contours_cleanup()" & ditto & ")" ; + let lmt_load_mlib_cnt = relax ; +enddef ; + vardef lmt_do_contour = image ( - if not lmx_contour_loaded : - lmx_contour_loaded := true ; - runscript("lua.registercode('mlib-cnt')"); - extra_beginfig := extra_beginfig & % todo: use different hook - "runscript(" & ditto & "mp.lmt_contours_cleanup()" & ditto & ")" ; - fi + lmt_load_mlib_cnt ; pushparameters "contour" ; @@ -2028,3 +2032,79 @@ vardef lmt_do_svg = fi enddef ; +% Another experiment. Parameters might change pending a discussion between Alan +% and me. + +presetparameters "surface" [ + code = "x + y", + color = "f, 0, 0", + linecolor = 1, + xmin = -1, + xmax = 1, + ymin = -1, + ymax = 1, + xstep = .1, + ystep = .1, + snap = .01, + xvector = { -0.7, -0.7 }, + yvector = { 1, 0 }, + zvector = { 0, 1 }, + light = { 3, 3, 10 }, + bright = 100, + clip = false, + lines = true, + linecolor = 1, + % axis = { } + % clipaxis = false + axiscolor = "gray" + axislinewidth = 1/2, +] ; + +def lmt_surface = applyparameters "surface" "lmt_do_surface" enddef ; + +vardef lmt_do_surface = + image ( + + lmt_load_mlib_cnt ; + + pushparameters "surface" ; + + save currentpen; pen currentpen ; + currentpen := pencircle scaled .25 ; + + interim linejoin := butt ; + + lmt_do_contour_shortcuts ; + + lua.mp.lmt_surface_do() ; + + currentpicture := currentpicture ysized getparameter "height" ; + + if hasparameter "axis" : + + save p ; picture p ; p := image ( + if hasparameter "axis" 1 : + draw ((origin) -- unitvector(getparameter "xvector")) scaled (getparameter "axis" 1) ; + fi ; + if hasparameter "axis" 2 : + draw ((origin) -- unitvector(getparameter "yvector")) scaled (getparameter "axis" 2) ; + fi ; + if hasparameter "axis" 3 : + draw ((origin) -- unitvector(getparameter "zvector")) scaled (getparameter "axis" 3) ; + fi ; + ) ; + + if getparameterdefault "clipaxis" false : + clip p to boundingbox currentpicture ; + fi ; + + draw p + withpen pencircle scaled getparameter "axislinewidth" + withcolor getparameter "axiscolor" + ; + + fi ; + + popparameters ; + ) +enddef ; diff --git a/metapost/context/base/mpiv/mp-mlib.mpiv b/metapost/context/base/mpiv/mp-mlib.mpiv index 286e4e495..88bf56674 100644 --- a/metapost/context/base/mpiv/mp-mlib.mpiv +++ b/metapost/context/base/mpiv/mp-mlib.mpiv @@ -1696,6 +1696,11 @@ def nodraw text t = draw t withpostscript "collect" enddef ; def dodraw text t = draw t withpostscript "flush" enddef ; def dofill text t = fill t withpostscript "flush" enddef ; +% maybe (saves a bogus path but the problem is that it can influence the dimensions): + +% def dodraw text t = draw center currentpicture withpostscript "flush" enddef ; +% def dofill text t = fill center currentpicture --cycle withpostscript "flush" enddef ; + if contextlmtxmode : def eoclip text t = clip t withpostscript "evenodd" enddef ; else : diff --git a/tex/context/base/mkii/cont-new.mkii b/tex/context/base/mkii/cont-new.mkii index a1f67933b..0de119aa2 100644 --- a/tex/context/base/mkii/cont-new.mkii +++ b/tex/context/base/mkii/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2019.09.27 17:59} +\newcontextversion{2019.09.29 14:34} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/mkii/context.mkii b/tex/context/base/mkii/context.mkii index 2a4b1588d..422ee53a9 100644 --- a/tex/context/base/mkii/context.mkii +++ b/tex/context/base/mkii/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2019.09.27 17:59} +\edef\contextversion{2019.09.29 14:34} %D For those who want to use this: diff --git a/tex/context/base/mkii/mult-cs.mkii b/tex/context/base/mkii/mult-cs.mkii index fe02205ee..374f96c7c 100644 --- a/tex/context/base/mkii/mult-cs.mkii +++ b/tex/context/base/mkii/mult-cs.mkii @@ -234,6 +234,7 @@ \setinterfacevariable{hanging}{visici} \setinterfacevariable{head}{hlavicka} \setinterfacevariable{header}{zahlavi} +\setinterfacevariable{headintext}{headintext} \setinterfacevariable{height}{vyska} \setinterfacevariable{helptext}{textnapovedy} \setinterfacevariable{hencefore}{vyse} diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv index 6b05f4174..0f68e30c3 100644 --- a/tex/context/base/mkiv/cont-new.mkiv +++ b/tex/context/base/mkiv/cont-new.mkiv @@ -13,7 +13,7 @@ % \normalend % uncomment this to get the real base runtime -\newcontextversion{2019.09.27 17:59} +\newcontextversion{2019.09.29 14:34} %D This file is loaded at runtime, thereby providing an excellent place for %D hacks, patches, extensions and new features. diff --git a/tex/context/base/mkiv/context.mkiv b/tex/context/base/mkiv/context.mkiv index 907985beb..b255f6bcc 100644 --- a/tex/context/base/mkiv/context.mkiv +++ b/tex/context/base/mkiv/context.mkiv @@ -45,7 +45,7 @@ %D {YYYY.MM.DD HH:MM} format. \edef\contextformat {\jobname} -\edef\contextversion{2019.09.27 17:59} +\edef\contextversion{2019.09.29 14:34} \edef\contextkind {beta} %D Kind of special: diff --git a/tex/context/base/mkiv/context.mkxl b/tex/context/base/mkiv/context.mkxl index 6651995c2..9086b1faf 100644 --- a/tex/context/base/mkiv/context.mkxl +++ b/tex/context/base/mkiv/context.mkxl @@ -29,7 +29,7 @@ %D {YYYY.MM.DD HH:MM} format. \edef\contextformat {\jobname} -\edef\contextversion{2019.09.27 17:59} +\edef\contextversion{2019.09.29 14:34} \edef\contextkind {beta} %D Kind of special: diff --git a/tex/context/base/mkiv/mlib-cnt.lua b/tex/context/base/mkiv/mlib-cnt.lua index 5bd27dbfd..f257c0a6e 100644 --- a/tex/context/base/mkiv/mlib-cnt.lua +++ b/tex/context/base/mkiv/mlib-cnt.lua @@ -48,6 +48,8 @@ local next, type, tostring = next, type, tostring local round, abs, min, max, floor = math.round, math.abs, math.min, math.max, math.floor local concat, move = table.concat, table.move +local bor = bit32.bor -- it's really time to ditch support for luajit + local starttiming = statistics.starttiming local stoptiming = statistics.stoptiming local elapsedtime = statistics.elapsedtime @@ -115,13 +117,13 @@ local f_function_y = formatters [ [[ if n == nan then er = er + 1 if er < 10 then - report("nan at (%s,%s) -> ",x,y,mx,my) + report("nan at (%s,%s)",x,y) end n = dnan elseif n == inf then er = er + 1 if er < 10 then - report("inf at (%s,%s) -> ",x,y,mx,my) + report("inf at (%s,%s)",x,y) end n = dinf end @@ -336,8 +338,8 @@ function mp.lmt_contours_start() local functionlist = functionrange and p.functions local preamble = p.preamble - if xstep == 0 then xstep = (xmax - xmin)/200 end - if ystep == 0 then ystep = (ymax - ymin)/200 end + if xstep == 0 then xstep = (xmax - xmin)/100 end + if ystep == 0 then ystep = (ymax - ymin)/100 end local nxmin = round(xmin/xstep) local nxmax = round(xmax/xstep) @@ -369,7 +371,6 @@ function mp.lmt_contours_start() end end - -- for i=1,nx do -- data[i] = lua.newtable(ny,0) -- end @@ -411,7 +412,7 @@ function mp.lmt_contours_start() for j=1,ny do local f = fi[j] if f >= minr and f <= maxr then - di[j] = di[j] | bit + di[j] = bor(di[j],bit) end end end @@ -1768,3 +1769,211 @@ function mp.lmt_contours_edge_get_band(value) mpfill(getparameterset().result.bands[value],true) mpflush() end + +-- Because we share some code surface plots also end up here. When working on the +-- contour macros by concidence I ran into a 3D plot in +-- +-- https://staff.science.uva.nl/a.j.p.heck/Courses/mptut.pdf +-- +-- The code is pure MetaPost and works quite well. With a bit of optimization +-- performance is also ok, but in the end a Lua solution is twice as fast and also +-- permits some more tweaking at no cost. So, below is an adaptation of an example +-- in the mentioned link. It's one of these cases where access to pseudo arrays +-- is slowing down MP. + +local sqrt, sin, cos = math.sqrt, math.sin, math.cos + +local f_fill = string.formatters["F (%.6N,%.6N)--(%.6N,%.6N)--(%.6N,%.6N)--(%.6N,%.6N)--C withcolor (%.3N,%.3N,%.3N) ;"] +local f_draw = string.formatters["D (%.6N,%.6N)--(%.6N,%.6N)--(%.6N,%.6N)--(%.6N,%.6N)--C withcolor %.3F ;"] +local f_mesh = string.formatters["U (%.6N,%.6N)--(%.6N,%.6N)--(%.6N,%.6N)--(%.6N,%.6N)--C withcolor (%.3N,%.3N,%.3N) ;"] + +local f_function_n = formatters [ [[ + local math = math + local round = math.round + %s + return function(x,y) + return %s + end +]] ] + +local f_function_y = formatters [ [[ + local math = math + local round = math.round + local nan = NaN + local inf = math.huge + local er = 0 + %s + return function(x,y,dnan,dinf,report) + local n = %s + if n == nan then + er = er + 1 + if er < 10 then + report("nan at (%s,%s)",x,y) + end + n = dnan + elseif n == inf then + er = er + 1 + if er < 10 then + report("inf at (%s,%s)",x,y) + end + n = dinf + end + dx[my] = n + sy = sy + 1 + end + return n, er +end +]] ] + +local f_color = formatters [ [[ + local math = math + return function(f) + return %s + end +]] ] + +function mp.lmt_surface_do(specification) + -- + -- The projection and color brightness calculation have been inlined. We also store + -- differently. + -- + -- todo: ignore weird paths + -- + -- The prototype is now converted to use lmt parameter sets. + -- + local p = getparameterset("surface") + -- + local preamble = p.preamble or "" + local code = p.code or "return x + y" + local colorcode = p.color or "return f, f, f" + local linecolor = p.linecolor or 1 + local xmin = p.xmin or -1 + local xmax = p.xmax or 1 + local ymin = p.ymin or -1 + local ymax = p.ymax or 1 + local xstep = p.xstep or .1 + local ystep = p.ystep or .1 + local bf = p.brightness or 100 + local clip = p.clip or false + local lines = p.lines + local ha = p.snap or 0.01 + local hb = 2 * ha + -- + if lines == nil then lines = true end + -- + if xstep == 0 then xstep = (xmax - xmin)/100 end + if ystep == 0 then ystep = (ymax - ymin)/100 end + + local nxmin = round(xmin/xstep) + local nxmax = round(xmax/xstep) + local nymin = round(ymin/ystep) + local nymax = round(ymax/ystep) + local nx = nxmax - nxmin + 1 + local ny = nymax - nymin + 1 + -- + local xvector = p.xvector or { -0.7, -0.7 } + local yvector = p.yvector or { 1, 0 } + local zvector = p.zvector or { 0, 1 } + local light = p.light or { 3, 3, 10 } + -- + local xrx, xry = xvector[1], xvector[2] + local yrx, yry = yvector[1], yvector[2] + local zrx, zry = zvector[1], zvector[2] + local xp, yp, zp = light[1], light[2], light[3] + -- + local data = setmetatableindex("table") + local dx = (xmax - xmin) / nx + local dy = (ymax - ymin) / ny + local xt = xmin + -- + local minf, maxf + -- + -- similar as contours but no data loop here + -- + local fcode = load((p.check and f_function_y or f_function_n)(preamble,code)) + local func = type(fcode) == "function" and fcode() + if type(func) ~= "function" then + return false -- fatal error + end + -- + local ccode = load(f_color(colorcode)) + local color = type(ccode) == "function" and ccode() + if type(color) ~= "function" then + return false -- fatal error + end + -- + for i=0,nx do + local yt = ymin + for j=0,ny do + local zt = func(xt,yt) + -- projection from 3D to 2D coordinates + local x = xt * xrx + yt * yrx + zt * zrx + local y = xt * xry + yt * yry + zt * zry + local z = zt + -- numerical derivatives by central differences + local dfx = (func(xt+ha,yt) - func(xt-ha,yt)) / hb + local dfy = (func(xt,yt+ha) - func(xt,yt-ha)) / hb + -- compute brightness factor at a point + local ztp = zt - zp + local ytp = yt - yp + local xtp = xt - xp + local ztp = zt - zp + local ytp = yt - yp + local xtp = xt - xp + local ca = -ztp + dfy*ytp + dfx*xtp + local cb = sqrt(1+dfx*dfx+dfy*dfy) + local cc = sqrt(ztp*ztp + ytp*ytp + xtp*xtp) + local fac = bf*ca/(cb*cc*cc*cc) + -- addition: check range + if not minf then + minf = fac + maxf = fac + elseif fac < minf then + minf = fac + elseif fac > maxf then + maxf = fac + end + -- + data[i][j] = { x, y, fac } + -- + yt = yt + dy + end + xt = xt + dx + end + local result = { } + local r = 0 + local range = maxf - minf + local cl = linecolor + for i=0,nx-1 do + for j=0,ny-1 do + -- points + local z1 = data[i] [j] + local z2 = data[i] [j+1] + local z3 = data[i+1][j+1] + local z4 = data[i+1][j] + -- color + local cf = z1[3] + if clip then + -- best clip here if needed + if cf < 0 then + cf = 0 + elseif cf > 1 then + cf = 1 + end + else + -- or remap when we want to + cf = (z1[3] - minf) / range + end + local cr, cg, cb = color(cf) + if lines then + -- fill first and draw then, previous shapes can be covered + r = r + 1 ; result[r] = f_fill(z1[1],z1[2],z2[1],z2[2],z3[1],z3[2],z4[1],z4[2],cr or 0,cg or 0,cb or 0) + r = r + 1 ; result[r] = f_draw(z1[1],z1[2],z2[1],z2[2],z3[1],z3[2],z4[1],z4[2],cl or 1) + else + -- fill and draw in one go to prevent artifacts + r = r + 1 ; result[r] = f_mesh(z1[1],z1[2],z2[1],z2[2],z3[1],z3[2],z4[1],z4[2],cr or 0,cg or 0,cb or 0) + end + end + end + mp.direct(concat(result)) +end diff --git a/tex/context/base/mkiv/mlib-ctx.mkiv b/tex/context/base/mkiv/mlib-ctx.mkiv index c90536937..860cb688c 100644 --- a/tex/context/base/mkiv/mlib-ctx.mkiv +++ b/tex/context/base/mkiv/mlib-ctx.mkiv @@ -19,7 +19,7 @@ \registerctxluafile{mlib-lmp}{} \registerctxluafile{mlib-int}{} -\doifelsefileexists{mlib-cnt.lua}{\registerctxluafile{mlib-cnt}{}}{} +\doifelsefileexists{mlib-cnt.lua}{\registerctxluafile{mlib-cnt}{optimize}}{} \doifelsefileexists{mlib-svg.lua}{\registerctxluafile{mlib-svg}{}}{} \unprotect diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf index 410f87641..13226aea6 100644 Binary files a/tex/context/base/mkiv/status-files.pdf and b/tex/context/base/mkiv/status-files.pdf differ diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf index 8008a61ee..71314c8ea 100644 Binary files a/tex/context/base/mkiv/status-lua.pdf and b/tex/context/base/mkiv/status-lua.pdf differ diff --git a/tex/context/interface/mkii/keys-cs.xml b/tex/context/interface/mkii/keys-cs.xml index 358100151..5f8f2ff5e 100644 --- a/tex/context/interface/mkii/keys-cs.xml +++ b/tex/context/interface/mkii/keys-cs.xml @@ -237,6 +237,7 @@ + diff --git a/tex/context/interface/mkiv/i-context.pdf b/tex/context/interface/mkiv/i-context.pdf index 5c0fba19a..f76346da3 100644 Binary files a/tex/context/interface/mkiv/i-context.pdf and b/tex/context/interface/mkiv/i-context.pdf differ diff --git a/tex/context/interface/mkiv/i-readme.pdf b/tex/context/interface/mkiv/i-readme.pdf index db5adf50d..ceb80af79 100644 Binary files a/tex/context/interface/mkiv/i-readme.pdf and b/tex/context/interface/mkiv/i-readme.pdf differ diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index b538d1f3b..d9de24400 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : c:/data/develop/context/sources/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/sources/luatex-fonts.lua --- merge date : 09/27/19 17:59:57 +-- merge date : 09/29/19 14:34:09 do -- begin closure to overcome local limits and interference -- cgit v1.2.3