summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex')
-rw-r--r--Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex423
1 files changed, 417 insertions, 6 deletions
diff --git a/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex
index 2dacf8f7458..0c1f8dc41fe 100644
--- a/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex
+++ b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex
@@ -144,7 +144,8 @@
}{%
\let#1=\tikz@plot@handler
}%
-}%
+}
+
% Converts an arbitrary command (without arguments) to a string in which all characters
@@ -426,16 +427,20 @@
\expandafter\let\csname #1\endcsname=\pgfplots@loc@TMPc
}%
-% I have introduced this macro to allow optimizations of (x,y)
-% coordinate processing. Use it for everything which is directly plot
-% related.
-%
-% @see \pgfplotsqpointxy@orthogonal
+% Inside of a pgfplots axis, this method (together with
+% \pgfplotsqpointxyz for 3d axes) is THE
+% point method. If you override the mapping to PGF coordinates here,
+% all other \pgfplotspoint* commands should inherit the changes as well.
\def\pgfplotsqpointxy#1#2{%
\global\pgf@x=#1\pgf@xx%
\global\advance\pgf@x by #2\pgf@yx%
\global\pgf@y=#1\pgf@xy%
\global\advance\pgf@y by #2\pgf@yy}
+
+% Inside of a pgfplots axis, this method (together with
+% \pgfplotsqpointxy for 2d axes) is THE
+% point method. If you override the mapping to PGF coordinates here,
+% all other \pgfplotspoint* commands should inherit the changes as well.
\def\pgfplotsqpointxyz#1#2#3{%
\global\pgf@x=#1\pgf@xx%
\global\advance\pgf@x by #2\pgf@yx%
@@ -860,6 +865,69 @@
\ifx\pgfplots@loc@TMPa\pgfutil@empty #2\else #3\fi
}%
+{
+ \catcode`\#=12
+ \catcode`\1=12
+ \gdef\pgfplotsutil@add@to@macro@@one{#1}%
+ \gdef\pgfplotsutil@add@to@macro@@two{#1#2}%
+}
+
+\def\pgfplotsutil@ifmacrodependsononearg#1#2#3{%
+ \edef\pgfplots@loc@TMPa{\noexpand\pgfutil@in@{\pgfplotsutil@add@to@macro@@one}{\meaning#1}}%
+ \pgfplots@loc@TMPa
+ \ifpgfutil@in@
+ #2%
+ \else
+ #3%
+ \fi
+}%
+
+\def\pgfplotsutil@ifmacrodependsontwoargs#1#2#3{%
+ \edef\pgfplots@util@add@to@macro@@{\noexpand\pgfutil@in@{\pgfplotsutil@add@to@macro@@two}{\meaning#1}}%
+ \pgfplots@util@add@to@macro@@
+ \ifpgfutil@in@
+ #2%
+ \else
+ #3%
+ \fi
+}%
+
+% Appends '#2' to macro '#1'.
+%
+% #1: a macro which takes either no arguments or exactly one.
+% #2: some token text. May depend on '#1' if #1 is a macro which
+% depends on one arg.
+\def\pgfplotsutil@add@to@macro#1#2{%
+ \pgfplotsutil@ifmacrodependsononearg#1{%
+ \pgfplotsutil@ifmacrodependsontwoargs#1{%
+ \pgfplotsutil@add@to@macro@twoargs{#1}{#2}%
+ }{%
+ \pgfplotsutil@add@to@macro@onearg{#1}{#2}%
+ }%
+ }{%
+ \pgfplotsutil@add@to@macro@noargs{#1}{#2}%
+ }%
+}%
+
+\def\pgfplotsutil@add@to@macro@twoargs#1#2{%
+ \t@pgfplots@tokc=\expandafter{#1{##1}{##2}}%
+ \t@pgfplots@tokb={#2}%
+ \edef\pgfplots@util@add@to@macro@@{\the\t@pgfplots@tokc\the\t@pgfplots@tokb}%
+ \expandafter\def\expandafter#1\expandafter##\expandafter1\expandafter##\expandafter2\expandafter{\pgfplots@util@add@to@macro@@}%
+}
+
+\def\pgfplotsutil@add@to@macro@onearg#1#2{%
+ \t@pgfplots@tokc=\expandafter{#1{##1}}%
+ \t@pgfplots@tokb={#2}%
+ \edef\pgfplots@util@add@to@macro@@{\the\t@pgfplots@tokc\the\t@pgfplots@tokb}%
+ \expandafter\def\expandafter#1\expandafter##\expandafter1\expandafter{\pgfplots@util@add@to@macro@@}%
+}
+
+\def\pgfplotsutil@add@to@macro@noargs#1#2{%
+ \t@pgfplots@tokc=\expandafter{#1}%
+ \t@pgfplots@tokb=\expandafter{#2}%
+ \edef#1{\the\t@pgfplots@tokc\the\t@pgfplots@tokb}%
+}
\def\pgfplots@logfileopen#1{%
\immediate\write-1{PGFPlots: reading {#1}}%
\pgfutil@ifundefined{tikzifexternalizingcurrent}{%
@@ -1551,6 +1619,349 @@
\def\:{\pgfplotsutil@xifnch} \expandafter\gdef\: {\futurelet\pgfplotsutil@let@token\pgfplotsutil@ifnch}
}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% basic 3d linear algebra utils.
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Converts a 3d vectors to string.
+% #1: a vector which expands to the form 'x,y,z'
+% on output, \pgfplotsretval will contain the result vector.
+% #3: the argument for \pgfplotscoordmath (such as 'default')
+%
+\def\pgfplotsmathvectortostring#1#2{%
+ \begingroup
+ \edef\pgfplots@loc@TMPa{#1}%
+ \expandafter\pgfplotsmathvectorcompwiseop@unary\pgfplots@loc@TMPa\pgfplots@EOI{#2}{{tostring}}%
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+}%
+
+% Reads a 3d vector's coordinates.
+% #1: a vector which expands to the form 'x,y,z'
+% on output, \pgfplotsretval will contain the result vector.
+% #2: the argument for \pgfplotscoordmath (such as 'default')
+%
+% Example:
+% \pgfplotsmathvectorfromstring{1,4,5}{default}
+% will parse each component
+\def\pgfplotsmathvectorfromstring#1#2{%
+ \begingroup
+ \edef\pgfplots@loc@TMPa{#1}%
+ \expandafter\pgfplotsmathvectorcompwiseop@unary\pgfplots@loc@TMPa\pgfplots@EOI{#2}{{parsenumber}}%
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+}%
+
+% Takes two 3d vectors and subtracts them.
+% #1: a vector which expands to the form 'x,y,z'
+% #2: a vector which expands to the form 'x,y,z'
+% on output, \pgfplotsretval will contain the difference vector.
+% #3: the argument for \pgfplotscoordmath (such as 'default')
+%
+\def\pgfplotsmathvectorsubtract#1#2#3{%
+ \begingroup
+ \edef\pgfplots@loc@TMPa{#1:#2}%
+ \expandafter\pgfplotsmathvectorcompwiseop@binary\pgfplots@loc@TMPa\pgfplots@EOI{#3}{subtract}%
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+}%
+\def\pgfplotsmathvectorcompwiseop@binary#1,#2,#3:#4,#5,#6\pgfplots@EOI#7#8{%
+ \def\Ax{#1}%
+ \def\Ay{#2}%
+ \def\Az{#3}%
+ \def\Bx{#4}%
+ \def\By{#5}%
+ \def\Bz{#6}%
+ \pgfplotscoordmath{#7}{op}{#8}{{\Ax}{\Bx}}%
+ \let\pgfplots@loc@TMPa=\pgfmathresult
+ \pgfplotscoordmath{#7}{op}{#8}{{\Ay}{\By}}%
+ \let\pgfplots@loc@TMPb=\pgfmathresult
+ \pgfplotscoordmath{#7}{op}{#8}{{\Az}{\Bz}}%
+ \let\pgfplots@loc@TMPc=\pgfmathresult
+ \edef\pgfplotsretval{\pgfplots@loc@TMPa,\pgfplots@loc@TMPb,\pgfplots@loc@TMPc}%
+}%
+
+% #5: an operation ENCLOSED IN BRACES!
+% like '{tostring}' or '{op}{<someunaryop>}'
+\def\pgfplotsmathvectorcompwiseop@unary#1,#2,#3\pgfplots@EOI#4#5{%
+ \def\Ax{#1}%
+ \def\Ay{#2}%
+ \def\Az{#3}%
+ \pgfplotscoordmath{#4}#5{\Ax}%
+ \let\pgfplots@loc@TMPa=\pgfmathresult
+ \pgfplotscoordmath{#4}#5{\Ay}%
+ \let\pgfplots@loc@TMPb=\pgfmathresult
+ \pgfplotscoordmath{#4}#5{\Az}%
+ \let\pgfplots@loc@TMPc=\pgfmathresult
+ \edef\pgfplotsretval{\pgfplots@loc@TMPa,\pgfplots@loc@TMPb,\pgfplots@loc@TMPc}%
+}%
+
+% Takes two 3d vectors and adds them.
+% #1: a vector which expands to the form 'x,y,z'
+% #2: a vector which expands to the form 'x,y,z'
+% on output, \pgfplotsretval will contain the added vector.
+% #3: the argument for \pgfplotscoordmath (such as 'default')
+%
+\def\pgfplotsmathvectoradd#1#2#3{%
+ \begingroup
+ \edef\pgfplots@loc@TMPa{#1:#2}%
+ \expandafter\pgfplotsmathvectorcompwiseop@binary\pgfplots@loc@TMPa\pgfplots@EOI{#3}{add}%
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+}%
+
+% Takes two 3d vectors and applies a component-wise operation.
+% #1: a vector which expands to the form 'x,y,z'
+% #2: a vector which expands to the form 'x,y,z'
+% on output, \pgfplotsretval will contain a boolean vector with three
+% entries.
+% #3: a scalar operation which takes two arguments (such as "add", "subtract", "equal")
+% #4 the argument for \pgfplotscoordmath (such as 'default')
+%
+% Example: \pgfplotsmathvectorcompwise{1,1,1}{0,1,0}{add}{pgfbasic}
+% -> \pgfplotsretval={1.0,2.0,1.0}
+\def\pgfplotsmathvectorcompwise#1#2#3#4{%
+ \begingroup
+ \edef\pgfplots@loc@TMPa{#1:#2}%
+ \expandafter\pgfplotsmathvectorcompwiseop@binary\pgfplots@loc@TMPa\pgfplots@EOI{#4}{#3}%
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+}%
+
+% Defines \pgfplotsretval to x+y+z
+% #1: a vector which expands to the form 'x,y,z'
+% on output, \pgfplotsretval will contain the result scalar.
+% #2: the argument for \pgfplotscoordmath (such as 'default')
+%
+% Example:
+% \pgfplotsmathvectorsum{1,4,5}{default}
+% \pgfplotsretval = 10 (in that format)
+\def\pgfplotsmathvectorsum#1#2{%
+ \begingroup
+ \edef\pgfplots@loc@TMPa{#1}%
+ \expandafter\pgfplotsmathvectorsum@\pgfplots@loc@TMPa\pgfplots@EOI{#2}%
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+}%
+
+\def\pgfplotsmathvectorsum@#1,#2,#3\pgfplots@EOI#4{%
+ \def\Ax{#1}%
+ \def\Ay{#2}%
+ \def\Az{#3}%
+ \pgfplotscoordmath{#4}{op}{add}{{\Ax}{\Ay}}%
+ \let\pgfplotsretval=\pgfmathresult
+ \pgfplotscoordmath{#4}{op}{add}{{\pgfplotsretval}{\Az}}%
+ \let\pgfplotsretval=\pgfmathresult
+}%
+
+% Computes the euclidean scalar product of two 3d vectors #1 and #2 in math
+% format #3.
+\def\pgfplotsmathvectorscalarproduct#1#2#3{%
+ \pgfplotsmathvectorscaleindividually{#1}{#2}{#3}%
+ \pgfplotsmathvectorsum{\pgfplotsretval}{#3}%
+}%
+
+% takes a vector #1 and defines three new macros
+% \csname #2x\endcsname,
+% \csname #2y\endcsname,
+% \csname #2z\endcsname,
+% with the components.
+% #3: the math format
+\def\pgfplotsmathvectortocomponents#1#2#3{%
+ \edef\pgfplots@loc@TMPa{#1}%
+ \expandafter\pgfplotsmathvectortocomponents@\pgfplots@loc@TMPa\pgfplots@EOI{#3}{#2}%
+}%
+\def\pgfplotsmathvectortocomponents@#1,#2,#3\pgfplots@EOI#4#5{%
+ \expandafter\def\csname #5x\endcsname{#1}%
+ \expandafter\def\csname #5y\endcsname{#2}%
+ \expandafter\def\csname #5z\endcsname{#3}%
+}%
+
+
+% Takes two 3d vectors and computes their cross product.
+% #1: a vector which expands to the form 'x,y,z'
+% #2: a vector which expands to the form 'x,y,z'
+% on output, \pgfplotsretval will contain the result vector.
+% #3: the argument for \pgfplotscoordmath (such as 'default')
+%
+\def\pgfplotsmathvectorcrossprod#1#2#3{%
+ \begingroup
+ \edef\pgfplots@loc@TMPa{#1:#2}%
+ \expandafter\pgfplotsmathvectorcrossprod@\pgfplots@loc@TMPa\pgfplots@EOI{#3}%
+%\message{\string\pgfplotsmathvectorcrossprod{#1}{#2} = \pgfplotsretval^^J}%
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+}%
+\def\pgfplotsmathvectorcrossprod@#1,#2,#3:#4,#5,#6\pgfplots@EOI#7{%
+ \def\Ax{#1}%
+ \def\Ay{#2}%
+ \def\Az{#3}%
+ \def\Bx{#4}%
+ \def\By{#5}%
+ \def\Bz{#6}%
+ %
+ \pgfplotscoordmath{#7}{op}{multiply}{{\Ay}{\Bz}}\let\AyBz=\pgfmathresult
+ \pgfplotscoordmath{#7}{op}{multiply}{{\Az}{\By}}\let\AzBy=\pgfmathresult
+ \pgfplotscoordmath{#7}{op}{multiply}{{\Az}{\Bx}}\let\AzBx=\pgfmathresult
+ \pgfplotscoordmath{#7}{op}{multiply}{{\Ax}{\Bz}}\let\AxBz=\pgfmathresult
+ \pgfplotscoordmath{#7}{op}{multiply}{{\Ax}{\By}}\let\AxBy=\pgfmathresult
+ \pgfplotscoordmath{#7}{op}{multiply}{{\Ay}{\Bx}}\let\AyBx=\pgfmathresult
+ %
+ \pgfplotscoordmath{#7}{op}{subtract}{{\AyBz}{\AzBy}}\let\pgfplots@loc@TMPa=\pgfmathresult%
+ \pgfplotscoordmath{#7}{op}{subtract}{{\AzBx}{\AxBz}}\let\pgfplots@loc@TMPb=\pgfmathresult%
+ \pgfplotscoordmath{#7}{op}{subtract}{{\AxBy}{\AyBx}}\let\pgfplots@loc@TMPc=\pgfmathresult%
+ \edef\pgfplotsretval{\pgfplots@loc@TMPa,\pgfplots@loc@TMPb,\pgfplots@loc@TMPc}%
+}%
+
+% Takes two 3d vectors and defines a new vector (Ax*Bx,Ay*By,Az*Bz)
+% #1: a vector which expands to the form 'x,y,z'
+% #2: a vector which expands to the form 'x,y,z'
+% on output, \pgfplotsretval will contain the result vector.
+% #3: the argument for \pgfplotscoordmath (such as 'default')
+%
+\def\pgfplotsmathvectorscaleindividually#1#2#3{%
+ \begingroup
+ \edef\pgfplots@loc@TMPa{#1:#2}%
+ \expandafter\pgfplotsmathvectorscaleindividually@\pgfplots@loc@TMPa\pgfplots@EOI{#3}%
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+}%
+\def\pgfplotsmathvectorscaleindividually@#1,#2,#3:#4,#5,#6\pgfplots@EOI#7{%
+ \def\Ax{#1}%
+ \def\Ay{#2}%
+ \def\Az{#3}%
+ \def\Bx{#4}%
+ \def\By{#5}%
+ \def\Bz{#6}%
+ %
+ \pgfplotscoordmath{#7}{op}{multiply}{{\Ax}{\Bx}}\let\Cx=\pgfmathresult
+ \pgfplotscoordmath{#7}{op}{multiply}{{\Ay}{\By}}\let\Cy=\pgfmathresult
+ \pgfplotscoordmath{#7}{op}{multiply}{{\Az}{\Bz}}\let\Cz=\pgfmathresult
+ %
+ \edef\pgfplotsretval{\Cx,\Cy,\Cz}%
+}%
+
+% #1 a vector as x,y,z
+% #2 the math format of its components
+\def\pgfplotspointfromcsvvector#1#2{%
+ \begingroup
+ \edef\pgfplots@loc@TMPa{#1}%
+ \expandafter\pgfplotspointfromcsvvector@\pgfplots@loc@TMPa\pgfplots@EOI{#2}
+ \endgroup
+}%
+\def\pgfplotspointfromcsvvector@#1,#2,#3\pgfplots@EOI#4{%
+ \pgfplotscoordmath{#4}{tofixed}{#1}\let\Ax=\pgfmathresult
+ \pgfplotscoordmath{#4}{tofixed}{#2}\let\Ay=\pgfmathresult
+ \pgfplotscoordmath{#4}{tofixed}{#3}\let\Az=\pgfmathresult
+ \pgfplotsqpointxyz\Ax\Ay\Az
+ \pgf@process{}%
+}%
+
+% #1 a vector as (x,y,z)
+% #2 a coordmath value
+% defines \pgfplotsretval to contain the vector length
+\def\pgfplotsmathvectorlength#1#2{%
+ \begingroup
+ \edef\pgfplots@loc@TMPa{#1}%
+ \expandafter\pgfplotsmathvectorlength@\pgfplots@loc@TMPa\pgfplots@EOI{#2}%
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+}%
+\def\pgfplotsmathvectorlength@#1,#2,#3\pgfplots@EOI#4{%
+ \begingroup
+ \def\Ax{#1}%
+ \def\Ay{#2}%
+ \def\Az{#3}%
+ %
+ \pgfplotscoordmath{#4}{op}{multiply}{{\Ax}{\Ax}}\let\Axx=\pgfmathresult
+ \pgfplotscoordmath{#4}{op}{multiply}{{\Ay}{\Ay}}\let\Ayy=\pgfmathresult
+ \pgfplotscoordmath{#4}{op}{multiply}{{\Az}{\Az}}\let\Azz=\pgfmathresult
+ %
+ \pgfplotscoordmath{#4}{op}{add}{{\Axx}{\Ayy}}%
+ \pgfplotscoordmath{#4}{op}{add}{{\Azz}{\pgfmathresult}}%
+ \pgfplotscoordmath{#4}{op}{sqrt}{{\pgfmathresult}}%
+ \let\pgfplotsretval=\pgfmathresult
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+}%
+
+% #1 a vector as (x,y,z)
+% #2 a scale
+% #3 a coordmath value
+% defines \pgfplotsretval to contain the scaled vector
+\def\pgfplotsmathvectorscale#1#2#3{%
+ \begingroup
+ \edef\pgfplots@loc@TMPa{#1:#2}%
+ \expandafter\pgfplotsmathvectorscale@\pgfplots@loc@TMPa\pgfplots@EOI{#3}%
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+}%
+\def\pgfplotsmathvectorscale@#1,#2,#3:#4\pgfplots@EOI#5{%
+ \begingroup
+ \def\Ax{#1}%
+ \def\Ay{#2}%
+ \def\Az{#3}%
+ \pgfplotscoordmath{#5}{parsenumber}{#4}\let\S\pgfmathresult
+ %
+ \pgfplotscoordmath{#5}{op}{multiply}{{\Ax}{\S}}\let\Ax=\pgfmathresult
+ \pgfplotscoordmath{#5}{op}{multiply}{{\Ay}{\S}}\let\Ay=\pgfmathresult
+ \pgfplotscoordmath{#5}{op}{multiply}{{\Az}{\S}}\let\Az=\pgfmathresult
+ %
+ \edef\pgfplotsretval{\Ax,\Ay,\Az}%
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+}%
+
+% Takes an input vector #1 = x,y,z and applies the inverse data scale
+% trafo.
+%
+% The result is \pgfplotsretval; it will be in '#2' coordmath for
+% every component.
+\def\pgfplotsmathvectordatascaletrafoinverse#1#2{%
+ \begingroup
+ \edef\pgfplots@loc@TMPa{#1}%
+ \expandafter\pgfplotsmathvectordatascaletrafoinverse@\pgfplots@loc@TMPa\pgfplots@EOI{#2}%
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+}
+\def\pgfplotsmathvectordatascaletrafoinverse@#1,#2,#3\pgfplots@EOI#4{%
+ \begingroup
+ \def\Ax{#1}%
+ \def\Ay{#2}%
+ \def\Az{#3}%
+ \ifpgfplots@apply@datatrafo@x
+ \pgfplotscoordmath{x}{datascaletrafo inverse}{\Ax}\let\Ax=\pgfmathresult
+ \fi
+ \ifpgfplots@apply@datatrafo@y
+ \pgfplotscoordmath{y}{datascaletrafo inverse}{\Ay}\let\Ay=\pgfmathresult
+ \fi
+ \ifpgfplots@curplot@threedim
+ \ifpgfplots@apply@datatrafo@z
+ \pgfplotscoordmath{z}{datascaletrafo inverse}{\Az}\let\Az=\pgfmathresult
+ \fi
+ \fi
+ \pgfplotsmathvectorfromstring{\Ax,\Ay,\Az}{#4}%
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+}%
+
+
+{
+\catcode`\"=12
+\gdef\pgfplotsDQ{"}%
+\catcode`\|=12
+\gdef\pgfplotsVERTBAR{|}%
+\catcode`\#=12
+\gdef\pgfplotsHASH{#}%
+\catcode`\%=12 \gdef\pgfplotsPERCENT{%}}
+
+\pgfutil@ifundefined{directlua}{}{%
+ \directlua{require(\pgfplotsDQ pgfplots.lua\pgfplotsDQ)}%
+}%
+
\input pgfplotsliststructure.code.tex
\input pgfplotsliststructureext.code.tex
\input pgfplotsarray.code.tex