texlive[72750] Master/texmf-dist: bezierplot (2nov24)

commits+karl at tug.org commits+karl at tug.org
Sat Nov 2 20:39:04 CET 2024


Revision: 72750
          https://tug.org/svn/texlive?view=revision&revision=72750
Author:   karl
Date:     2024-11-02 20:39:04 +0100 (Sat, 02 Nov 2024)
Log Message:
-----------
bezierplot (2nov24)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/lualatex/bezierplot/README
    trunk/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.pdf
    trunk/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.tex
    trunk/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua
    trunk/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty

Modified: trunk/Master/texmf-dist/doc/lualatex/bezierplot/README
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/bezierplot/README	2024-11-02 19:38:51 UTC (rev 72749)
+++ trunk/Master/texmf-dist/doc/lualatex/bezierplot/README	2024-11-02 19:39:04 UTC (rev 72750)
@@ -8,7 +8,7 @@
 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 

Modified: trunk/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.tex	2024-11-02 19:38:51 UTC (rev 72749)
+++ trunk/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.tex	2024-11-02 19:39:04 UTC (rev 72750)
@@ -134,18 +134,6 @@
 \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 @@
 	\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}
 %

Modified: trunk/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua	2024-11-02 19:38:51 UTC (rev 72749)
+++ trunk/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua	2024-11-02 19:39:04 UTC (rev 72750)
@@ -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 @@
 
 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 @@
 	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 @@
 -- 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 @@
 			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 @@
 					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 @@
 	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 @@
 				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 @@
 				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

Modified: trunk/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty	2024-11-02 19:38:51 UTC (rev 72749)
+++ trunk/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty	2024-11-02 19:39:04 UTC (rev 72750)
@@ -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



More information about the tex-live-commits mailing list.