texlive[70723] Master/texmf-dist: bezierplot (22mar24)

commits+karl at tug.org commits+karl at tug.org
Fri Mar 22 22:36:23 CET 2024


Revision: 70723
          https://tug.org/svn/texlive?view=revision&revision=70723
Author:   karl
Date:     2024-03-22 22:36:23 +0100 (Fri, 22 Mar 2024)
Log Message:
-----------
bezierplot (22mar24)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/lualatex/bezierplot/README
    trunk/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.pdf
    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-03-22 21:36:08 UTC (rev 70722)
+++ trunk/Master/texmf-dist/doc/lualatex/bezierplot/README	2024-03-22 21:36:23 UTC (rev 70723)
@@ -8,13 +8,13 @@
 number of used points.
 
 VERSION:
-1.4 2019-06-18
+1.5 2024-03-21
 
 LICENSE:
 The package and the program are distributed on CTAN under the terms of 
 the LaTeX Project Public License (LPPL) version 1.3c.
 
-Copyright (c) 2018 Linus Romer
+Copyright (c) 2018-2024 Linus Romer
 
 Please write to 
 linus dot romer at gmx dot ch

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

Modified: trunk/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua	2024-03-22 21:36:08 UTC (rev 70722)
+++ trunk/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua	2024-03-22 21:36:23 UTC (rev 70723)
@@ -1,6 +1,6 @@
 #!/usr/bin/env lua
 -- Linus Romer, published 2018 under LPPL Version 1.3c
--- version 1.4 2019-06-18
+-- version 1.5 2024-03-31
 abs = math.abs
 acos = math.acos
 asin = math.asin
@@ -277,99 +277,25 @@
 
 -- f(x)=a*x^3+b*x+c
 local function parameters_cubic(xp,yp,xq,yq,xr,yr,xs,ys)
-	local a = (((xp^2 * xq) * yr) - ((xp^2 * xq) * ys) 
-	- ((xp^2 * xr) * yq) + ((xp^2 * xr) * ys) + ((xp^2 * xs) * yq)
-	- ((xp^2 * xs) * yr) - ((xp * xq^2) * yr) + ((xp * xq^2) * ys) 
-	+ ((xp * xr^2) * yq) - ((xp * xr^2) * ys) - ((xp * xs^2) * yq) 
-	+ ((xp * xs^2) * yr) + ((xq^2 * xr) * yp) - ((xq^2 * xr) * ys) 
-	- ((xq^2 * xs) * yp) + ((xq^2 * xs) * yr) - ((xq * xr^2) * yp) 
-	+ ((xq * xr^2) * ys) + ((xq * xs^2) * yp) - ((xq * xs^2) * yr) 
-	+ ((xr^2 * xs) * yp) - ((xr^2 * xs) * yq) - ((xr * xs^2) * yp) 
-	+ ((xr * xs^2) * yq)) / 
-	(((xp^3 * xq^2) * xr) - ((xp^3 * xq^2) * xs) 
-	- ((xp^3 * xq) * xr^2) + ((xp^3 * xq) * xs^2) 
-	+ ((xp^3 * xr^2) * xs) - ((xp^3 * xr) * xs^2) 
-	- ((xp^2 * xq^3) * xr) + ((xp^2 * xq^3) * xs) 
-	+ ((xp^2 * xq) * xr^3) - ((xp^2 * xq) * xs^3) 
-	- ((xp^2 * xr^3) * xs) + ((xp^2 * xr) * xs^3) 
-	+ ((xp * xq^3) * xr^2) - ((xp * xq^3) * xs^2) 
-	- ((xp * xq^2) * xr^3) + ((xp * xq^2) * xs^3) 
-	+ ((xp * xr^3) * xs^2) - ((xp * xr^2) * xs^3) 
-	- ((xq^3 * xr^2) * xs) + ((xq^3 * xr) * xs^2) 
-	+ ((xq^2 * xr^3) * xs) - ((xq^2 * xr) * xs^3) 
-	- ((xq * xr^3) * xs^2) + ((xq * xr^2) * xs^3))
-	local b = ((((-xp^3) * xq) * yr) + ((xp^3 * xq) * ys) 
-	+ ((xp^3 * xr) * yq) - ((xp^3 * xr) * ys) - ((xp^3 * xs) * yq) 
-	+ ((xp^3 * xs) * yr) + ((xp * xq^3) * yr) - ((xp * xq^3) * ys) 
-	- ((xp * xr^3) * yq) + ((xp * xr^3) * ys) + ((xp * xs^3) * yq) 
-	- ((xp * xs^3) * yr) - ((xq^3 * xr) * yp) + ((xq^3 * xr) * ys) 
-	+ ((xq^3 * xs) * yp) - ((xq^3 * xs) * yr) + ((xq * xr^3) * yp) 
-	- ((xq * xr^3) * ys) - ((xq * xs^3) * yp) + ((xq * xs^3) * yr) 
-	- ((xr^3 * xs) * yp) + ((xr^3 * xs) * yq) + ((xr * xs^3) * yp) 
-	- ((xr * xs^3) * yq)) / 
-	(((xp^3 * xq^2) * xr) - ((xp^3 * xq^2) * xs) 
-	- ((xp^3 * xq) * xr^2) + ((xp^3 * xq) * xs^2) 
-	+ ((xp^3 * xr^2) * xs) - ((xp^3 * xr) * xs^2) 
-	- ((xp^2 * xq^3) * xr) + ((xp^2 * xq^3) * xs) 
-	+ ((xp^2 * xq) * xr^3) - ((xp^2 * xq) * xs^3) 
-	- ((xp^2 * xr^3) * xs) + ((xp^2 * xr) * xs^3) 
-	+ ((xp * xq^3) * xr^2) - ((xp * xq^3) * xs^2) 
-	- ((xp * xq^2) * xr^3) + ((xp * xq^2) * xs^3) 
-	+ ((xp * xr^3) * xs^2) - ((xp * xr^2) * xs^3) 
-	- ((xq^3 * xr^2) * xs) + ((xq^3 * xr) * xs^2) 
-	+ ((xq^2 * xr^3) * xs) - ((xq^2 * xr) * xs^3) 
-	- ((xq * xr^3) * xs^2) + ((xq * xr^2) * xs^3))
-	local c = (((xp^3 * xq^2) * yr) - ((xp^3 * xq^2) * ys) 
-	- ((xp^3 * xr^2) * yq) + ((xp^3 * xr^2) * ys) 
-	+ ((xp^3 * xs^2) * yq) - ((xp^3 * xs^2) * yr) 
-	- ((xp^2 * xq^3) * yr) + ((xp^2 * xq^3) * ys) 
-	+ ((xp^2 * xr^3) * yq) - ((xp^2 * xr^3) * ys) 
-	- ((xp^2 * xs^3) * yq) + ((xp^2 * xs^3) * yr) 
-	+ ((xq^3 * xr^2) * yp) - ((xq^3 * xr^2) * ys) 
-	- ((xq^3 * xs^2) * yp) + ((xq^3 * xs^2) * yr) 
-	- ((xq^2 * xr^3) * yp) + ((xq^2 * xr^3) * ys) 
-	+ ((xq^2 * xs^3) * yp) - ((xq^2 * xs^3) * yr) 
-	+ ((xr^3 * xs^2) * yp) - ((xr^3 * xs^2) * yq) 
-	- ((xr^2 * xs^3) * yp) + ((xr^2 * xs^3) * yq)) / 
-	(((xp^3 * xq^2) * xr) - ((xp^3 * xq^2) * xs) 
-	- ((xp^3 * xq) * xr^2) + ((xp^3 * xq) * xs^2) 
-	+ ((xp^3 * xr^2) * xs) - ((xp^3 * xr) * xs^2) 
-	- ((xp^2 * xq^3) * xr) + ((xp^2 * xq^3) * xs) 
-	+ ((xp^2 * xq) * xr^3) - ((xp^2 * xq) * xs^3) 
-	- ((xp^2 * xr^3) * xs) + ((xp^2 * xr) * xs^3) 
-	+ ((xp * xq^3) * xr^2) - ((xp * xq^3) * xs^2) 
-	- ((xp * xq^2) * xr^3) + ((xp * xq^2) * xs^3) 
-	+ ((xp * xr^3) * xs^2) - ((xp * xr^2) * xs^3) 
-	- ((xq^3 * xr^2) * xs) + ((xq^3 * xr) * xs^2) 
-	+ ((xq^2 * xr^3) * xs) - ((xq^2 * xr) * xs^3) 
-	- ((xq * xr^3) * xs^2) + ((xq * xr^2) * xs^3))
-	local d = ((((xp^(3) * xq^(2)) * xr) * ys) 
-	- (((xp^(3) * xq^(2)) * xs) * yr) - (((xp^(3) * xq) * xr^(2)) * ys) 
-	+ (((xp^(3) * xq) * xs^(2)) * yr) + (((xp^(3) * xr^(2)) * xs) * yq) 
-	- (((xp^(3) * xr) * xs^(2)) * yq) - (((xp^(2) * xq^(3)) * xr) * ys) 
-	+ (((xp^(2) * xq^(3)) * xs) * yr) + (((xp^(2) * xq) * xr^(3)) * ys) 
-	- (((xp^(2) * xq) * xs^(3)) * yr) - (((xp^(2) * xr^(3)) * xs) * yq) 
-	+ (((xp^(2) * xr) * xs^(3)) * yq) + (((xp * xq^(3)) * xr^(2)) * ys) 
-	- (((xp * xq^(3)) * xs^(2)) * yr) - (((xp * xq^(2)) * xr^(3)) * ys) 
-	+ (((xp * xq^(2)) * xs^(3)) * yr) + (((xp * xr^(3)) * xs^(2)) * yq) 
-	- (((xp * xr^(2)) * xs^(3)) * yq) - (((xq^(3) * xr^(2)) * xs) * yp) 
-	+ (((xq^(3) * xr) * xs^(2)) * yp) + (((xq^(2) * xr^(3)) * xs) * yp) 
-	- (((xq^(2) * xr) * xs^(3)) * yp) - (((xq * xr^(3)) * xs^(2)) * yp) 
-	+ (((xq * xr^(2)) * xs^(3)) * yp)) / 
-	(((xp^(3) * xq^(2)) * xr) - 
-	((xp^(3) * xq^(2)) * xs) - ((xp^(3) * xq) * xr^(2)) 
-	+ ((xp^(3) * xq) * xs^(2)) + ((xp^(3) * xr^(2)) * xs) 
-	- ((xp^(3) * xr) * xs^(2)) - ((xp^(2) * xq^(3)) * xr) 
-	+ ((xp^(2) * xq^(3)) * xs) + ((xp^(2) * xq) * xr^(3)) 
-	- ((xp^(2) * xq) * xs^(3)) - ((xp^(2) * xr^(3)) * xs) 
-	+ ((xp^(2) * xr) * xs^(3)) + ((xp * xq^(3)) * xr^(2)) 
-	- ((xp * xq^(3)) * xs^(2)) - ((xp * xq^(2)) * xr^(3)) 
-	+ ((xp * xq^(2)) * xs^(3)) + ((xp * xr^(3)) * xs^(2)) 
-	- ((xp * xr^(2)) * xs^(3)) - ((xq^(3) * xr^(2)) * xs) 
-	+ ((xq^(3) * xr) * xs^(2)) + ((xq^(2) * xr^(3)) * xs) 
-	- ((xq^(2) * xr) * xs^(3)) - ((xq * xr^(3)) * xs^(2)) 
-	+ ((xq * xr^(2)) * xs^(3)))
-	return a, b, c, d
+	return (((xq-xp)*xr^2+(xp^2-xq^2)*xr+xp*xq^2-xp^2*xq)*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q*xr^3-xq^3*xr)*xs^2+(xq^3*xr^2-xq^2*xr^3)*xs)*yp)/((xq-xp)
+	*(xr-xp)*(xr-xq)*(xs-xp)*(xs-xq)*(xs-xr))
 end
 
 -- f(x)=a*x+b
@@ -521,24 +447,31 @@
 	-- we compute the corner point c, where the controls would meet
 	local cx = ((dp * px) - (ds * sx) - py + sy) / (dp - ds)
 	local cy = (dp * ((ds * px) - (ds * sx) - py + sy) / (dp - ds)) + py
+	local delta_cpx = .01*(cx-px)
+	local delta_cpy = .01*(cy-py)
+	local delta_csx = .01*(cx-sx)
+	local delta_csy = .01*(cy-sy)
 	-- now we slide q between p and c & r between s and c
 	-- and search for the best qx and best rx
-	local qx = px+.01*(cx-px)
-	local qy = py+.01*(cy-py)
-	local rx = sx+.01*(cx-sx)
-	local ry = sy+.01*(cy-sy)
+	local qx = px+delta_cpx
+	local qy = py+delta_cpy
+	local rx = sx+delta_csx
+	local ry = sy+delta_csy
 	local err = squareerror(f,g,starti,endi,qx,qy,rx,ry)
+	local newerror
+	local best_j = 1
 	for i = 2, 99 do
-		for j = 2, 99 do
-			xa = px+i*.01*(cx-px)
-			ya = py+i*.01*(cy-py)
-			xb = sx+j*.01*(cx-sx)
-			yb = sy+j*.01*(cy-sy)
+		xa = px+i*delta_cpx
+		ya = py+i*delta_cpy
+		for j = 10, 90, 10 do -- determine j roughly
+			xb = sx+j*delta_csx
+			yb = sy+j*delta_csy
 			-- now check, if xa and xb fit better
 			-- than the last qx and rx did
 			-- (sum of squares must be smaller)
-			local newerror = squareerror(f,g,starti,endi,xa,ya,xb,yb)
+			newerror = squareerror(f,g,starti,endi,xa,ya,xb,yb)
 			if newerror < err then
+				best_j = j
 				qx = xa
 				qy = ya
 				rx = xb
@@ -546,6 +479,22 @@
 				err = newerror
 			end
 		end
+		for j = best_j-9, best_j+9 do -- determine j better
+			xb = sx+j*delta_csx
+			yb = sy+j*delta_csy
+			-- now check, if xa and xb fit better
+			-- than the last qx and rx did
+			-- (sum of squares must be smaller)
+			newerror = squareerror(f,g,starti,endi,xa,ya,xb,yb)
+			if newerror < err then
+				best_j = j
+				qx = xa
+				qy = ya
+				rx = xb
+				ry = yb
+				err = newerror
+			end
+		end
 	end
 	if maxerror > 0 then
 		-- check if it is close enough: (recycling err, xa, ya)
@@ -903,10 +852,20 @@
 	return beziertabletostring(bezierpoints,rndx,rndy,isreverse,notation)		
 end
 
+-- This Lua script has to work as a "main" with an external
+-- call from pdfLaTeX as well as a "library" with a direct lua use
+-- of the function bezierplot() when used with LuaLaTeX
+-- However, Lua does not seem to support a natural distinction
+-- of the main and the library:
+-- https://stackoverflow.com/questions/4521085/main-function-in-lua
+-- As https://www.tug.org/pipermail/luatex/2024-February/007935.html
+-- states, LuaTeX 1.18 has disabled the use of the debug library.
+-- Hence, using "pcall(debug.getlocal, 4, 1)" is no longer possible
+-- without restriction. The problem with the now chosen method is
+-- that arg could be defined as a global variable in the calling code.
+
 -- main program --
-
-if not pcall(debug.getlocal, 4, 1) then
---if debug.getinfo(3) == nil then
+if (arg ~= nil and arg[-1] ~= nil) then 
 	if #arg >= 1 then
 		local xmin = -5
 		local xmax = 5
@@ -935,6 +894,3 @@
 		print(bezierplot(arg[1],xmin,xmax,ymin,ymax,samples,notation))
 	end
 end
-
-
-

Modified: trunk/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty	2024-03-22 21:36:08 UTC (rev 70722)
+++ trunk/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty	2024-03-22 21:36:23 UTC (rev 70723)
@@ -1,5 +1,7 @@
+% Linus Romer, published 2018 under LPPL Version 1.3c
+% version 1.5 2024-03-31
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{bezierplot}[2019/06/18 bezierplot]
+\ProvidesPackage{bezierplot}[2024/03/21 bezierplot]
 \RequirePackage{xparse}
 \RequirePackage{iftex}
 \ifLuaTeX



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