summaryrefslogtreecommitdiff
path: root/Master/texmf-dist
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2024-03-22 21:36:23 +0000
committerKarl Berry <karl@freefriends.org>2024-03-22 21:36:23 +0000
commite12995c4719b9e25dcd6b9c9eeeec776ebe780c1 (patch)
tree9768657c0b1b6974cb619d71e5153c7a2db28605 /Master/texmf-dist
parent09bf1575132c1764f181dbffb5f5544f66365644 (diff)
bezierplot (22mar24)
git-svn-id: svn://tug.org/texlive/trunk@70723 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r--Master/texmf-dist/doc/lualatex/bezierplot/README4
-rw-r--r--Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.pdfbin251276 -> 266461 bytes
-rwxr-xr-xMaster/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua176
-rw-r--r--Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty4
4 files changed, 71 insertions, 113 deletions
diff --git a/Master/texmf-dist/doc/lualatex/bezierplot/README b/Master/texmf-dist/doc/lualatex/bezierplot/README
index 493bfe5c651..c472443d7a3 100644
--- a/Master/texmf-dist/doc/lualatex/bezierplot/README
+++ b/Master/texmf-dist/doc/lualatex/bezierplot/README
@@ -8,13 +8,13 @@ points such as extreme points and inflection points and reduces the
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
diff --git a/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.pdf b/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.pdf
index c93fd5f1021..7ebb1dbcddd 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/tex/lualatex/bezierplot/bezierplot.lua b/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua
index 382da2d74ea..d023923d455 100755
--- a/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua
+++ b/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua
@@ -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 @@ end
-- 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)))
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2+(xp^2*xr^3-xp^3*xr^2)*xs)*yq+((xq^2*xr-xq*xr^2)*xs^3
+ +(xq*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,47 @@ local function graphtobezierapprox(f,g,starti,endi,maxerror)
-- 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
+ ry = yb
+ 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
@@ -903,10 +852,20 @@ function bezierplot(functionstring,xminstring,xmaxstring,yminstring,ymaxstring,s
return beziertabletostring(bezierpoints,rndx,rndy,isreverse,notation)
end
--- main program --
+-- 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.
-if not pcall(debug.getlocal, 4, 1) then
---if debug.getinfo(3) == nil then
+-- main program --
+if (arg ~= nil and arg[-1] ~= nil) then
if #arg >= 1 then
local xmin = -5
local xmax = 5
@@ -935,6 +894,3 @@ if not pcall(debug.getlocal, 4, 1) then
print(bezierplot(arg[1],xmin,xmax,ymin,ymax,samples,notation))
end
end
-
-
-
diff --git a/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty b/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty
index 94be30b4dce..c3d0963de2a 100644
--- a/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty
+++ b/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty
@@ -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