summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2024-11-02 19:39:04 +0000
committerKarl Berry <karl@freefriends.org>2024-11-02 19:39:04 +0000
commitc383fc9a37cb31e1cbdda4e657a9c328255ccb44 (patch)
treeb0e866fda2d9e8fba3eb07837806007e339c3fe2
parent7e7ae82f05b2429a8eb499599e9b666c4c92553c (diff)
bezierplot (2nov24)
git-svn-id: svn://tug.org/texlive/trunk@72750 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/lualatex/bezierplot/README2
-rw-r--r--Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.pdfbin266461 -> 271692 bytes
-rw-r--r--Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.tex19
-rwxr-xr-xMaster/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua36
-rw-r--r--Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty4
5 files changed, 32 insertions, 29 deletions
diff --git a/Master/texmf-dist/doc/lualatex/bezierplot/README b/Master/texmf-dist/doc/lualatex/bezierplot/README
index c472443d7a3..92d669a9b6e 100644
--- a/Master/texmf-dist/doc/lualatex/bezierplot/README
+++ b/Master/texmf-dist/doc/lualatex/bezierplot/README
@@ -8,7 +8,7 @@ points such as extreme points and inflection points and reduces the
number of used points.
VERSION:
-1.5 2024-03-21
+1.6 2024-11-02
LICENSE:
The package and the program are distributed on CTAN under the terms of
diff --git a/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.pdf b/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.pdf
index 7ebb1dbcddd..5beb4d71969 100644
--- a/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.pdf
+++ b/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.tex b/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.tex
index a1239b6e574..b23f919cca3 100644
--- a/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.tex
+++ b/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.tex
@@ -134,18 +134,6 @@ will set $0\leq x\leq 1$ and leave the default $-5\leq y\leq 5$. The variables \
\begin{verbatim}
lua bezierplot.lua "sin(x)" -pi pi
\end{verbatim}
-You may use \verb|huge| for $\infty$:
-\begin{verbatim}
-lua bezierplot "1/x" 0 1 0 huge
-\end{verbatim}
-As \verb|huge| is very huge and \verb|bezierplot| uses recursive calls for nontrivial functions and non--fixed samples, this can last very long:
-\begin{verbatim}
-lua bezierplot "1/x" -5 5 -huge huge
-\end{verbatim}
-But if you set fixed samples, it will be fast again (as this does not use recursive calls):
-\begin{verbatim}
-lua bezierplot "1/x" -5 5 -huge huge 100
-\end{verbatim}
\subsection{Notation Of Functions}
The function term given to \verb|bezierplot| must contain at most one variable: $x$. E.g. \verb|"2.3*(x-1)^2-3"|. You must not omit \verb|*| operators:
\begin{center}
@@ -164,15 +152,20 @@ The following functions and constants are possible:
\verb|atan| & $\tan^{-1}$ inverse function of tangent in radians\\
\verb|cbrt| & cube root $\sqrt[3]{\quad}$ that works for negative numbers, too\\
\verb|cos| & cosine for angles in radians\\
+ \verb|cosh| & hyperbolic cosine\\
+ \verb|deg| & converts from radians to degrees\\
\verb|exp| & the exponential function $e^{(\;)}$\\
\verb|huge| & the numerical $\infty$\\
\verb|e| & the euler constant $e=\mathrm{exp}(1)$\\
\verb|log| & the natural logarithm $\mathrm{log}_e(\;)$\\
\verb|pi| & Archimedes’ constant $\pi\approx 3.14$\\
+ \verb|rad| & converts from degrees to radians\\
\verb|sgn| & sign function\\
\verb|sin| & sine for angles in radians\\
+ \verb|sinh| & hyperbolic sine\\
\verb|sqrt| & square root $\sqrt{\quad}$\\
- \verb|tan| & tangent for angles in radians
+ \verb|tan| & tangent for angles in radians\\
+ \verb|tanh| & hyperbolic tangent
\end{tabular}
\end{center}
%
diff --git a/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua b/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua
index d023923d455..d8d18441403 100755
--- a/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua
+++ b/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua
@@ -1,19 +1,24 @@
#!/usr/bin/env lua
-- Linus Romer, published 2018 under LPPL Version 1.3c
--- version 1.5 2024-03-31
+-- version 1.6 2024-11-02
abs = math.abs
acos = math.acos
asin = math.asin
atan = math.atan
cos = math.cos
+cosh = math.cosh
+deg = math.deg
exp = math.exp
e = math.exp(1)
+huge = math.huge
log = math.log
pi = math.pi
+rad = math.rad
sin = math.sin
+sinh = math.sinh
sqrt = math.sqrt
tan = math.tan
-huge = math.huge
+tanh = math.tanh
-- just a helper for debugging:
local function printdifftable(t)
@@ -54,8 +59,8 @@ end
local function round(num, decimals)
local result = tonumber(string.format("%." .. (decimals or 0) .. "f", num))
- if abs(result) == 0 then
- return 0
+ if math.floor(result) == result then
+ return math.floor(result)
else
return result
end
@@ -275,7 +280,7 @@ local function do_parameters_fit(a,b,c,d,funcstring,funcgraph,maxerror,isinverse
return true
end
--- f(x)=a*x^3+b*x+c
+-- f(x)=a*x^3+b*x^2+c*x +d
local function parameters_cubic(xp,yp,xq,yq,xr,yr,xs,ys)
return (((xq-xp)*xr^2+(xp^2-xq^2)*xr+xp*xq^2-xp^2*xq)*ys+((xp-xq)
*xs^2+(xq^2-xp^2)*xs-xp*xq^2+xp^2*xq)*yr+((xr-xp)*xs^2+(xp^2-xr^2)
@@ -437,7 +442,7 @@ end
-- and try to approximate it with a cubic bezier curve
-- (round to rndx and rndy when printing)
-- if maxerror <= 0, the function will not be recursive anymore
-local function graphtobezierapprox(f,g,starti,endi,maxerror)
+local function graphtobezierapprox(f,g,starti,endi,maxerror,recursiondepth)
local px = g[starti][1]
local py = g[starti][2]
local dp = g[starti][3]
@@ -496,7 +501,7 @@ local function graphtobezierapprox(f,g,starti,endi,maxerror)
end
end
end
- if maxerror > 0 then
+ if maxerror > 0 and recursiondepth > 0 then
-- check if it is close enough: (recycling err, xa, ya)
err = 0
for t = .1, .9, .1 do
@@ -526,8 +531,8 @@ local function graphtobezierapprox(f,g,starti,endi,maxerror)
interindex = i
end
end
- local left = graphtobezierapprox(f,g,starti,interindex,maxerror)
- local right = graphtobezierapprox(f,g,interindex,endi,maxerror)
+ local left = graphtobezierapprox(f,g,starti,interindex,maxerror,recursiondepth-1)
+ local right = graphtobezierapprox(f,g,interindex,endi,maxerror,recursiondepth-1)
for i=1, #right do --now append the right to the left:
left[#left+1] = right[i]
end
@@ -803,7 +808,12 @@ function bezierplot(functionstring,xminstring,xmaxstring,yminstring,ymaxstring,s
else
---------- generic case (no special function) ----------------
if arbitrary_samples then
- -- go through the connected parts
+ -- go through the connected parts...
+ -- due to numerical errors we have to use a maximal
+ -- recursion depth, which is hard wired here
+ -- (a small number should suffice since there are
+ -- no extrema nor inflection points inbetween)
+ local maxrecursiondepth = 2
for part = 1, #graphs do
local dg = diffgraph(f,graphs[part],xstep)
--printdifftable(dg) -- for debugging
@@ -812,9 +822,9 @@ function bezierplot(functionstring,xminstring,xmaxstring,yminstring,ymaxstring,s
for k = 2, #dg do
if dg[k][5] or dg[k][6] then -- extrema and inflection points
local tobeadded = graphtobezierapprox(
- f,dg,startindex,k,10*yerror)
+ f,dg,startindex,k,10*yerror,maxrecursiondepth)
-- tobeadded may contain a multiple of 6 entries
- -- e.g. {1,2,3,4,5,6,7,8,9,10,11,12}
+ -- e.g. {1,2,3,4,5,6,7,8,9,10,11,12}
for i = 1, math.floor(#tobeadded/6) do
bezierpoints[#bezierpoints+1] = {}
for j = 1, 6 do
@@ -826,7 +836,7 @@ function bezierplot(functionstring,xminstring,xmaxstring,yminstring,ymaxstring,s
end
if startindex ~= #dg then -- if no special points inbetween
local tobeadded = graphtobezierapprox(f,dg,
- startindex,#dg,10*yerror)
+ startindex,#dg,10*yerror,maxrecursiondepth)
-- tobeadded may contain a multiple of 6 entries
-- e.g. {1,2,3,4,5,6,7,8,9,10,11,12}
for i = 1, math.floor(#tobeadded/6) do
diff --git a/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty b/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty
index c3d0963de2a..86eb49e5245 100644
--- a/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty
+++ b/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty
@@ -1,7 +1,7 @@
% Linus Romer, published 2018 under LPPL Version 1.3c
-% version 1.5 2024-03-31
+% version 1.6 2024-11-02
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{bezierplot}[2024/03/21 bezierplot]
+\ProvidesPackage{bezierplot}[2024/11/02 bezierplot]
\RequirePackage{xparse}
\RequirePackage{iftex}
\ifLuaTeX