From af40071956ab22eae0d446cced49296afc407c1e Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 18 Jun 2019 22:29:39 +0000 Subject: bezierplot (18jun19) git-svn-id: svn://tug.org/texlive/trunk@51398 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/lualatex/bezierplot/README | 2 +- .../doc/lualatex/bezierplot/bezierplot-doc.pdf | Bin 251986 -> 251276 bytes .../doc/lualatex/bezierplot/bezierplot-doc.tex | 6 +-- .../tex/lualatex/bezierplot/bezierplot.lua | 46 ++++++++++++++------- .../tex/lualatex/bezierplot/bezierplot.sty | 2 +- 5 files changed, 37 insertions(+), 19 deletions(-) (limited to 'Master') diff --git a/Master/texmf-dist/doc/lualatex/bezierplot/README b/Master/texmf-dist/doc/lualatex/bezierplot/README index 38f7ba74266..493bfe5c651 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.3 2018-09-03 +1.4 2019-06-18 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 a74e699da23..c93fd5f1021 100644 Binary files a/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.pdf and b/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.pdf differ diff --git a/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.tex b/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.tex index a079bce18cf..a1239b6e574 100644 --- a/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.tex +++ b/Master/texmf-dist/doc/lualatex/bezierplot/bezierplot-doc.tex @@ -23,7 +23,7 @@ \section{Introduction} \texttt{bezierplot} is a Lua program as well as a (Lua)\LaTeX{} package. This document describes both. -Given a smooth function, \texttt{bezierplot} returns a smooth bezier path written in Ti\emph{k}Z notation (which also matches \MP{}) that approximates the graph of the function. For polynomial functions of degree $\leq 3$ and inverses of them, the approximation is exact. \texttt{bezierplot} finds special graph points such as extreme points and inflection points and reduces the number of used points. +Given a smooth function, \texttt{bezierplot} returns a smooth bezier path written in Ti\emph{k}Z notation (which also matches \MP{}) that approximates the graph of the function. For polynomial functions of degree $\leq 3$ and inverses of them, the approximation is exact (up to numeric precision). \texttt{bezierplot} finds special graph points such as extreme points and inflection points and reduces the number of used points. The following example will show a comparison of \textsc{gnuplot} with \verb|bezierplot| for the function $y=\sqrt{x}$ for $0\leq x \leq 5$: \begin{center} @@ -39,7 +39,7 @@ The following example will show a comparison of \textsc{gnuplot} with \verb|bezi \end{scope} \end{tikzpicture} \end{center} -\textsc{gnuplot} used 51 samples (no smoothing) and is still quite inexact at the beginning, whereas \verb|bezierplot| uses 4 points only and is exact! +\textsc{gnuplot} used 51 samples (no smoothing) and is still quite inexact at the beginning, whereas \verb|bezierplot| uses 4 points only and is exact (up to numeric precision)! \section{Installation} As \texttt{bezierplot} is written in Lua, the installation depends whether you are using Lua\LaTeX{} or another \LaTeX{} engine. \subsection{Installation For Lua\LaTeX{}} @@ -179,7 +179,7 @@ The following functions and constants are possible: \newpage % \section{Examples of \texttt{bezierplot} in Comparison with \textsc{gnuplot}} -The following graphs are drawn with \texttt{bezierplot} (black) and \textsc{gnuplot} (red). \textsc{gnuplot} used 1000 samples per example. The functions are given below the pictures (left: bezierplot, right: \textsc{gnuplot}). +The following graphs are drawn with \texttt{bezierplot} (black) and \textsc{gnuplot} (red). You may not recognize the red behind the black unless you zoom in. \textsc{gnuplot} used 1000 samples per example. The functions are given below the pictures (left: bezierplot, right: \textsc{gnuplot}). \begin{multicols}{3} \graphcomparison{0.32*x-0.7}{0.32*x-0.7} \graphcomparison{-x^2+4}{-x**2+4} diff --git a/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua b/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.lua index af7dd887b85..382da2d74ea 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.3 2018-09-03 +-- version 1.4 2019-06-18 abs = math.abs acos = math.acos asin = math.asin @@ -15,6 +15,24 @@ sqrt = math.sqrt tan = math.tan huge = math.huge +-- just a helper for debugging: +local function printdifftable(t) + for i = 1,#t do + for j = 1, 6 do + if j < 5 then + io.write(t[i][j].." ") + else + if t[i][j] then + io.write("true ") + else + io.write("false ") + end + end + end + io.write("\n") + end +end + -- cube root defined for all real numbers x function cbrt(x) if x < 0 then @@ -66,7 +84,7 @@ local function diffgraph(func,graph,h) local l = #graph if l < 4 then -- this is not worth the pain... for i = 1, l do - table.insert(dgraph,{graph[i][1],graph[i][2],0,0,0,0}) + table.insert(dgraph,{graph[i][1],graph[i][2],0,0,false,false}) end else local yh = func(graph[1][1]-h) @@ -540,7 +558,12 @@ local function graphtobezierapprox(f,g,starti,endi,maxerror) err = abs(ya-f(xa)) end end - if err <= maxerror then + if (err <= maxerror) + and qx > -math.huge and qx < math.huge + and qy > -math.huge and qy < math.huge + and rx > -math.huge and ry < math.huge + and sx > -math.huge and sy < math.huge + then return {qx,qy,rx,ry,sx,sy} else -- search for an intermediate point where the graph has the same @@ -561,7 +584,11 @@ local function graphtobezierapprox(f,g,starti,endi,maxerror) end return left end - else + elseif qx > -math.huge and qx < math.huge + and qy > -math.huge and qy < math.huge + and rx > -math.huge and ry < math.huge + and sx > -math.huge and sy < math.huge + then return {qx,qy,rx,ry,sx,sy} end end @@ -586,16 +613,6 @@ local function graphtobezier(g,starti,endi,isinverse) end end --- just for debugging: -local function printtable(t) - for i = 1,#t do - for j = 1, #t[i] do - io.write(t[i][j].." ") - end - io.write("\n") - end -end - -- main function function bezierplot(functionstring,xminstring,xmaxstring,yminstring,ymaxstring,samplesstring,notation) local fstringreplaced = string.gsub(functionstring, "%*%*", "^") @@ -840,6 +857,7 @@ function bezierplot(functionstring,xminstring,xmaxstring,yminstring,ymaxstring,s -- go through the connected parts for part = 1, #graphs do local dg = diffgraph(f,graphs[part],xstep) + --printdifftable(dg) -- for debugging bezierpoints[#bezierpoints+1] = {dg[1][1],dg[1][2]} local startindex = 1 for k = 2, #dg do diff --git a/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty b/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty index 4584777e476..94be30b4dce 100644 --- a/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty +++ b/Master/texmf-dist/tex/lualatex/bezierplot/bezierplot.sty @@ -1,5 +1,5 @@ \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{bezierplot}[2018/09/03 bezierplot] +\ProvidesPackage{bezierplot}[2019/06/18 bezierplot] \RequirePackage{xparse} \RequirePackage{iftex} \ifLuaTeX -- cgit v1.2.3