summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-04-13 22:56:07 +0000
committerKarl Berry <karl@freefriends.org>2013-04-13 22:56:07 +0000
commit658facdfe16a2d2b43c7312b9b15bebbf3c89d8e (patch)
tree6b219a6bd62fa7eda6d3aa87fccf509cc3fc7191
parent5ffaf0fed7a947071a4ad491d01164a10e97b7ed (diff)
hobby (13apr13)
git-svn-id: svn://tug.org/texlive/trunk@29895 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/latex/hobby/README.txt (renamed from Master/texmf-dist/doc/latex/hobby/README)0
-rw-r--r--Master/texmf-dist/doc/latex/hobby/hobby_doc.pdfbin397455 -> 510319 bytes
-rw-r--r--Master/texmf-dist/doc/latex/hobby/hobby_doc.tex515
-rw-r--r--Master/texmf-dist/source/latex/hobby/hobby.dtx2120
-rw-r--r--Master/texmf-dist/tex/latex/hobby/hobby.code.tex419
-rw-r--r--Master/texmf-dist/tex/latex/hobby/pgflibraryhobby.code.tex179
-rw-r--r--Master/texmf-dist/tex/latex/hobby/pml3array.sty161
-rw-r--r--Master/texmf-dist/tex/latex/hobby/tikzlibraryhobby.code.tex594
8 files changed, 3066 insertions, 922 deletions
diff --git a/Master/texmf-dist/doc/latex/hobby/README b/Master/texmf-dist/doc/latex/hobby/README.txt
index d48c4b90e17..d48c4b90e17 100644
--- a/Master/texmf-dist/doc/latex/hobby/README
+++ b/Master/texmf-dist/doc/latex/hobby/README.txt
diff --git a/Master/texmf-dist/doc/latex/hobby/hobby_doc.pdf b/Master/texmf-dist/doc/latex/hobby/hobby_doc.pdf
index 3f17f5112bd..8a21dc7f065 100644
--- a/Master/texmf-dist/doc/latex/hobby/hobby_doc.pdf
+++ b/Master/texmf-dist/doc/latex/hobby/hobby_doc.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/hobby/hobby_doc.tex b/Master/texmf-dist/doc/latex/hobby/hobby_doc.tex
index 073c9d8c32b..fa5fa58087c 100644
--- a/Master/texmf-dist/doc/latex/hobby/hobby_doc.tex
+++ b/Master/texmf-dist/doc/latex/hobby/hobby_doc.tex
@@ -4,14 +4,37 @@
\usepackage{csquotes}
\usepackage{lmodern}
\usepackage{tikz}
+\usepackage{pgfplots}
\usepackage{amsmath}
\usepackage{fancyvrb}
\usetikzlibrary{hobby,decorations.pathreplacing}
-\usepackage[margin=3cm]{geometry}
+\usepackage{listings}
+\lstloadlanguages{[LaTeX]TeX}
+\lstset{breakatwhitespace=true,breaklines=true,language=TeX}
+
\EnableCrossrefs
\CodelineIndex
\RecordChanges
+\newenvironment{example}
+ {\VerbatimEnvironment
+ \begin{VerbatimOut}{example.out}}
+ {\end{VerbatimOut}
+ \begin{center}
+ \setlength{\parindent}{0pt}
+ \fbox{\begin{minipage}{.9\linewidth}
+ \lstset{breakatwhitespace=true,breaklines=true,language=TeX,basicstyle=\small}
+ \lstinputlisting[]{example.out}
+ \end{minipage}}
+ \fbox{\begin{minipage}{.9\linewidth}
+ \centering
+ \input{example.out}
+ \end{minipage}}
+\end{center}
+}
+
+
+
\tikzset{
show curve controls/.style={
decoration={
@@ -28,13 +51,14 @@
},
}
-
%\bibliographystyle{plain}
+\renewcommand{\thefootnote}{\fnsymbol{footnote}}
\providecommand*{\url}{\texttt}
\title{The \textsf{Hobby} package}
\author{Andrew Stacey \\ \url{stacey@math.ntnu.no}}
+\date{v1.2 from 2013/04/12}
\begin{document}
\maketitle
@@ -54,15 +78,21 @@ These are all allowed in this implementation.
There is also a ``quick'' version presented here.
This is a modification of Hobby's algorithm with the feature that any point only influences a finite number (in fact, two) of the previous segments (in Hobby's algorithm the influence of a point dies out exponentially but never completely).
This is achieved by applying Hobby's algorithm to subpaths.
+The resulting path produced with this ``quick'' version is not as ideal as that produced by Hobby's full algorithm, but is still much better than that produced by the \Verb+plot[smooth]+ method in TikZ/PGF, as can be seen in Figure~\ref{fig:comparison}.
As this is intended as a simpler method, it does not (at present) admit the same level of customisation as the full implementation.
+The ``quick'' algorithm is described in full in Section~\ref{sec:quick}.
-The full algorithm is implemented in \LaTeX3 and makes extensive use of the \Verb+fp+ and \Verb+prop+ libraries for the computation steps.
+The full algorithm is implemented in \LaTeX3 with (almost\footnote{At the moment, \LaTeX3 lacks a \Verb+atan2+ function so \Verb+PGFMath+ is used to remedy that.}) no reference to TikZ or PGF.
+It makes extensive use of the \Verb+fp+ and \Verb+prop+ libraries for the computation steps.
+The TikZ library is simply a wrapper that takes the user's input, converts it into the right format for the \LaTeX3 code, and then calls that code to generate the path.
The ``quick'' version does not use \LaTeX3 and relies instead on the \Verb+PGFMath+ library for the computation.
+
Figure~\ref{fig:comparison} is a comparison of the three methods.
The red curve is drawn using Hobby's algorithm.
The blue curve is drawn with the \Verb+plot[smooth]+ method from TikZ/PGF.
The green curve uses the ``quick'' version.
+Figure~\ref{fig:metapost} compares the implementation with that given by MetaPost.
\begin{figure}
\centering
@@ -106,7 +136,9 @@ The green curve uses the ``quick'' version.
\end{scope}
\end{tikzpicture}
\caption{Hobby's algorithm in TikZ overlaying the output of MetaPost}
+\label{fig:metapost}
\end{figure}
+
\section{Usage}
The package is provided in form of a TikZ library.
It can be loaded with
@@ -114,204 +146,390 @@ It can be loaded with
\usetikzlibrary{hobby}
\end{verbatim}
%%
-The TikZ library installs a \Verb+to path+ which draws a smooth curve through the given points:
-%%
-\begin{verbatim}
-\begin{tikzpicture}
-\draw (0,0) to[curve through={(6,4) .. (4,9) .. (1,7)}] (3,5);
-\end{tikzpicture}
-\end{verbatim}
-\begin{center}
+There are a variety of ways of specifying the data to the algorithm to generate the curve.
+
+\subsection{As a \textsf{to path}.}
+
+The key \Verb+curve through={<points>}+ installs a \Verb+to path+ which draws a smooth curve through the given points.
+The points should be specified as a list which can be optionally separated by dots.
+The purpose of allowing the dots is to make it simpler to switch between the \Verb+to path+ method and the \Verb+shortcut+ method (described in Section~\ref{sec:shortcut}).
+However, note that the two methods are not completely synonymous due to how one can specify options so care must still be taken when switching.
+
+\begin{example}
\begin{tikzpicture}[scale=.5]
\draw (0,0) to[curve through={(6,4) .. (4,9) .. (1,7)}] (3,5);
\end{tikzpicture}
-\end{center}
-The path can be open, as above, or closed:
-%%
-\begin{verbatim}
-\begin{tikzpicture}
-\draw (0,0) to[closed,curve through={(6,4) .. (4,9) .. (1,7)}] (3,5);
+\end{example}
+
+\begin{example}
+\begin{tikzpicture}[scale=.5]
+\draw (0,0) to[curve through={(6,4) (4,9) (1,7)}] (3,5);
\end{tikzpicture}
-\end{verbatim}
-\begin{center}
+\end{example}
+
+There is a corresponding key \Verb+quick curve through={<points>}+ which uses the ``quick'' algorithm.
+Again, the dots are optional.
+
+\begin{example}
\begin{tikzpicture}[scale=.5]
-\draw (0,0) to[closed,curve through={(6,4) .. (4,9) .. (1,7)}] (3,5);
+\draw (0,0) to[quick curve through={(6,4) .. (4,9) .. (1,7)}] (3,5);
\end{tikzpicture}
-\end{center}
+\end{example}
+
+\subsection{The \textsf{shortcut} Method}
+\label{sec:shortcut}
There is also the facility to subvert TikZ's path processor and define curves simply using the \Verb+..+ separator between points.
Note that this relies on something a little special in TikZ: the syntax \Verb+(0,0) .. (2,3)+ is currently detected and processed but there is no action assigned to that syntax.
-As a later version of TikZ may assign some action to that syntax, this package makes its override optional via the key \Verb+use Hobby shortcut+.
-\begin{verbatim}
-\begin{tikzpicture}[use Hobby shortcut]
+As a later version of TikZ may assign some action to that syntax, this package makes its override optional via the key \Verb+use Hobby shortcut+ (which can be set globally if so desired).
+
+\begin{example}
+\begin{tikzpicture}[scale=.5,use Hobby shortcut]
\draw (-3,0) -- (0,0) .. (6,4) .. (4,9) .. (1,7) .. (3,5) -- ++(2,0);
\end{tikzpicture}
-\end{verbatim}
-\begin{center}
-\begin{tikzpicture}[scale=.5,use Hobby shortcut]
+\end{example}
+
+\begin{example}
+\begin{tikzpicture}[scale=.5,use quick Hobby shortcut]
\draw (-3,0) -- (0,0) .. (6,4) .. (4,9) .. (1,7) .. (3,5) -- ++(2,0);
\end{tikzpicture}
-\end{center}
-The algorithm can deal with open or closed paths, it is possible to vary the ``tensions'' between the specified points of the paths, and for an open path it is possible to specify the incoming and outgoing angles either directly or via certain ``curl'' parameters.
-See the Examples section for more examples.
-The algorithm is actually implemented in \LaTeX3 with (almost\footnote{At the moment, \LaTeX3 lacks a \Verb+atan2+ function so \Verb+PGFMath+ is used to remedy that.}) no reference to TikZ or PGF.
-The TikZ library is simply a wrapper that takes the user's input, converts it into the right format for the \LaTeX3 code, and then calls that code to generate the path.
-There is also a ``quick'' version of Hobby's algorithm.
-This is described in Section~\ref{sec:quick}.
-The reason for this modification of Hobby's algorithm was to find a variant in which adding more points does not change the path between earlier points (or rather that there is some point earlier than which the path is not changed).
-The resulting path produced with this ``quick'' version is not as ideal as that produced by Hobby's full algorithm, but is still much better than that produced by the \Verb+plot[smooth]+ method in TikZ/PGF, as can be seen in Figure~\ref{fig:comparison}.
+\end{example}
+
+\subsection{The \textsf{Plot Handler} Method}
-\section{Examples}
+The algorithms can also be used via the \Verb+plot handler+ syntax.
+This library registers three plot handlers: \Verb+hobby+, \Verb+closed hobby+, and \Verb+quick hobby+.
+The first is an open curve through the points using the full algorithm, the second is a closed curve, and the third uses the quick algorithm (and is thus an open curve).
+
+\begin{example}
+\tikz[smooth] \draw plot coordinates {(0,0) (1,1) (2,0) (3,1) (2,1) (10:2cm)};
+
+\tikz[hobby] \draw plot coordinates {(0,0) (1,1) (2,0) (3,1) (2,1) (10:2cm)};
+
+\tikz[closed hobby] \draw plot coordinates {(0,0) (1,1) (2,0) (3,1) (2,1) (10:2cm)};
+
+\tikz[quick hobby] \draw plot coordinates {(0,0) (1,1) (2,0) (3,1) (2,1) (10:2cm)};
+\end{example}
+
+This has the side effect that these can be used with the \Verb+pgfplots+ package.
+However, the Hobby algorithm is designed to draw a curve in 2D-{}space and does not take into account the fact that when plotting a graph then the two dimensions are treated differently.
+
+\begin{example}
+\begin{tikzpicture}
+\begin{axis}
+\addplot +[smooth] {rnd};
+\addplot +[hobby] {rnd};
+\end{axis}
+\end{tikzpicture}
+\end{example}
+
+\section{Customisation}
+
+There are various ways to customise the path generated by the Hobby algorithms.
+The full algorithm has a variety of parameters which can be varied to produce different paths through the same points.
+These vary from specifying that the path be open or closed, to specifying ``tensions'' at each point to change how the path approaches or leaves it.
+
+\subsection{Algorithm Customisations}
+
+The main algorithm (i.e., not the ``quick'' variant) can deal with open or closed paths, it is possible to vary the ``tensions'' between the specified points of the paths, and for an open path it is possible to specify the incoming and outgoing angles either directly or via certain ``curl'' parameters.
+When using the \Verb+to path+ specification, the parameters can be specified before or after the \Verb+curve through+ key or as options to the coordinates.
+When using the \Verb+shortcut+ specification, the parameters can be given on the path or on coordinates.
+
+On occasion, it is ambiguous which curve an option belongs to.
+This is most likely if a coordinate happens to belong to two curves, or if a coordinate is parsed before TikZ knows that it is constructing a curve using this library.
+The simplest solution is to move the option to a place where there is no ambiguity.
+Other solutions to this problem will be detailed later.
+
+Let us start with the customisations to the algorithm.
\begin{itemize}
\item Basic curve.
-\begin{verbatim}
+\begin{example}
\begin{tikzpicture}
\draw[postaction=show curve controls]
(0,0) to[curve through={(1,.5) .. (2,0) .. (3,.5)}] (4,0);
+\draw[xshift=5cm,use Hobby shortcut,postaction=show curve controls]
+(0,0) .. (1,.5) .. (2,0) .. (3,.5) .. (4,0);
\end{tikzpicture}
-\end{verbatim}
-\begin{center}
-\begin{tikzpicture}
+\end{example}
+
+\item The path can be open, as above, or closed.
+%%
+\begin{example}
+\begin{tikzpicture}[scale=.5]
\draw[postaction=show curve controls]
-(0,0) to[curve through={(1,.5) .. (2,0) .. (3,.5)}] (4,0);
+(0,0) to[closed,curve through={(1,.5) .. (2,0) .. (3,.5)}] (4,0);
+\draw[xshift=5cm,use Hobby shortcut,postaction=show curve controls]
+([closed]0,0) .. (1,.5) .. (2,0) .. (3,.5) .. (4,0);
\end{tikzpicture}
-\end{center}
+\end{example}
+
\item Specifying the angle at which the curve goes \emph{out} and at which it comes \emph{in}.
The angles given are absolute.
-\begin{verbatim}
+\begin{example}
\begin{tikzpicture}
\draw[postaction=show curve controls]
(0,0) to[out angle=0,in angle=180,curve through={(1,.5) .. (2,0) .. (3,.5)}] (4,0);
+\draw[xshift=5cm,use Hobby shortcut,postaction=show curve controls]
+([out angle=0,in angle=180]0,0) .. (1,.5) .. (2,0) .. (3,.5) .. (4,0);
\end{tikzpicture}
-\end{verbatim}
-\begin{center}
-\begin{tikzpicture}
-\draw[postaction=show curve controls]
-(0,0) to[out angle=0,in angle=180,curve through={(1,.5) .. (2,0) .. (3,.5)}] (4,0);
-\end{tikzpicture}
-\end{center}
+\end{example}
+
\item Applying tension as the curve comes in to a point.
-\begin{verbatim}
-\begin{tikzpicture}
-\draw[postaction=show curve controls]
-(0,0) to[curve through={(1,.5) .. ([tension in=2]2,0) .. (3,.5)}] (4,0);
-\end{tikzpicture}
-\end{verbatim}
-\begin{center}
+\begin{example}
\begin{tikzpicture}
\draw[postaction=show curve controls]
(0,0) to[curve through={(1,.5) .. ([tension in=2]2,0) .. (3,.5)}] (4,0);
+\draw[xshift=5cm,use Hobby shortcut,postaction=show curve controls]
+(0,0) .. (1,.5) .. ([tension in=2]2,0) .. (3,.5) .. (4,0);
\end{tikzpicture}
-\end{center}
+\end{example}
+
\item Applying the same tension as a curve comes in and goes out of a point.
-\begin{verbatim}
+\begin{example}
\begin{tikzpicture}
\draw[postaction=show curve controls]
(0,0) to[curve through={(1,.5) .. ([tension=2]2,0) .. (3,.5)}] (4,0);
\end{tikzpicture}
-\end{verbatim}
-\begin{center}
+\end{example}
+
+\item Specifying the \emph{curl} parameters.
+\begin{example}
\begin{tikzpicture}
\draw[postaction=show curve controls]
-(0,0) to[curve through={(1,.5) .. ([tension=2]2,0) .. (3,.5)}] (4,0);
-\end{tikzpicture}
-\end{center}
-\item Specifying the \emph{curl} parameters (if using the shortcut, these have to be passed via one of the points but obviously apply to the whole curve).
-\begin{verbatim}
-\begin{tikzpicture}[use Hobby shortcut]
-\draw[postaction=show curve controls]
-(0,0) to[curve through={(1,.5) .. (2,0) .. (3,.5)},in curl=.1,out curl=3] (4,0);
-\begin{scope}[yshift=-1cm]
-\draw[postaction=show curve controls]
+(0,0) to[in curl=.1,out curl=3,curve through={(1,.5) .. (2,0) .. (3,.5)}] (4,0);
+\draw[xshift=5cm,use Hobby shortcut,postaction=show curve controls]
(0,0) .. ([in curl=.1,out curl=3]1,.5) .. (2,0) .. (3,.5) .. (4,0);
-\end{scope}
\end{tikzpicture}
-\end{verbatim}
-\begin{center}
-\begin{tikzpicture}[use Hobby shortcut]
-\draw[postaction=show curve controls]
-(0,0) to[curve through={(1,.5) .. (2,0) .. (3,.5)},in curl=.1,out curl=3] (4,0);
-\begin{scope}[yshift=-1cm]
-\draw[postaction=show curve controls]
-(0,0) .. ([in curl=.1,out curl=3]1,.5) .. (2,0) .. (3,.5) .. (4,0);
-\end{scope}
-\end{tikzpicture}
-\end{center}
-\item Closed curve.
-\begin{verbatim}
-\begin{tikzpicture}[scale=.5,use Hobby shortcut]
-\draw (0,0) .. (6,4) .. (4,9) .. (1,7) .. (3,5) .. cycle;
-\end{tikzpicture}
-\end{verbatim}
-\begin{center}
-\begin{tikzpicture}[scale=.5,use Hobby shortcut]
-\draw (0,0) .. (6,4) .. (4,9) .. (1,7) .. (3,5) .. cycle;
-\end{tikzpicture}
-\end{center}
+\end{example}
\end{itemize}
-\section{Edge Cases}
+\subsection{Edge Cases}
+
Angles are constrained to lie in the interval \((-\pi,\pi]\).
This can introduce edge cases as there is a point where we have to compare an angle with \(-\pi\) and if it is equal, add \(2 \pi\).
This will occur if the path ``doubles back'' on itself as in the next example.
By nudging the repeated point slightly, the behaviour changes drastically.
-\begin{verbatim}
-\begin{tikzpicture}[use Hobby shortcut]
-\draw (0,0) .. (1,0) .. (0,0) .. (0,-1);
-\draw[xshift=2cm] (0,0) .. (1,0) .. (0,0.1) .. (0,-1);
-\draw[xshift=4cm] (0,0) .. (1,0) .. (0,-0.1) .. (0,-1);
-\end{tikzpicture}
-\end{verbatim}
-\begin{center}
+
+\begin{example}
\begin{tikzpicture}[use Hobby shortcut]
\draw (0,0) .. (1,0) .. (0,0) .. (0,-1);
\draw[xshift=2cm] (0,0) .. (1,0) .. (0,0.1) .. (0,-1);
\draw[xshift=4cm] (0,0) .. (1,0) .. (0,-0.1) .. (0,-1);
\end{tikzpicture}
-\end{center}
+\end{example}
+
Due to the precision of the computations, it is not possible to always get this test correct.
The simplest solution is to nudge the repeated point in one direction or the other.
Experimenting shows that the ``nudge factor'' can be extremely small (note that it will be proportional to the distance between the specified points).
It is best to nudge it in the direction most normal to the line between the specified points as the goal is to nudge the difference of the angles.
An alternative solution is to add an additional point for the curve to go through.
-\begin{verbatim}
+\begin{example}
\begin{tikzpicture}[use Hobby shortcut]
\draw (0,0) .. (1,0) .. (0,0) .. (0,-1);
\draw[xshift=2cm] (0,0) .. (1,0) .. (0,0.002) .. (0,-1);
\draw[xshift=4cm] (0,0) .. (1,0) .. (0,-0.002) .. (0,-1);
\end{tikzpicture}
-\end{verbatim}
-\begin{center}
-\begin{tikzpicture}[use Hobby shortcut]
-\draw (0,0) .. (1,0) .. (0,0) .. (0,-1);
-\draw[xshift=2cm] (0,0) .. (1,0) .. (0,0.002) .. (0,-1);
-\draw[xshift=4cm] (0,0) .. (1,0) .. (0,-0.002) .. (0,-1);
-\end{tikzpicture}
-\end{center}
+\end{example}
+
Lastly, it is possible to add an \Verb+excess angle+ key to a coordinate.
This will add the corresponding multiple of \(2\pi\) to the angle difference.
-\begin{verbatim}
+\begin{example}
\begin{tikzpicture}[use Hobby shortcut]
\draw (0,0) .. (1,0) .. (0,0) .. (0,-1);
\draw[xshift=2cm] (0,0) .. ([excess angle=1]1,0) .. (0,0) .. (0,-1);
\draw[xshift=4cm] (0,0) .. ([excess angle=-1]1,0) .. (0,0) .. (0,-1);
\end{tikzpicture}
-\end{verbatim}
-\begin{center}
+\end{example}
+
+Although this is intended to be an integer, no check is done and so some quite odd curves can result from changing this parameter.
+
+\subsection{Reusing Paths}
+
+Although the (full) algorithm has good theoretical computation time, using \TeX\ for its implementation does not provide for fast runs.
+The externalisation library of TikZ/PGF can be used to save whole pictures, but it can be useful to save a generated path within a single \Verb+tikzpicture+ for later use within that same picture.
+The implementation allows for this by separating the generation of the path from its use.
+
+\begin{example}
+\begin{tikzpicture}
+\draw[line width=3mm,red,use Hobby shortcut,save Hobby path={saved}] (0,0) .. (1,1) .. (2,0);
+\draw[xshift=2cm,ultra thick,yellow] (0,0) [restore and use Hobby path={saved}{}];
+\end{tikzpicture}
+\end{example}
+%
+
+Note that the key \Verb+restore and use Hobby path+ is given \emph{after} the initial \Verb+(0,0)+.
+This is because by default the path generated by the Hobby algorithm does not start with an explicit \Verb+moveto+ since that is the standard behaviour of all of PGF's path construction macros.
+So the \Verb+(0,0)+ ensures that our path is well-{}formed by issuing an initial \Verb+moveto+.
+An alternative would be to use the key \Verb+disjoint+ which does add an initial \Verb+moveto+.
+
+\begin{example}
+\begin{tikzpicture}
+\draw[line width=3mm,red,use Hobby shortcut,save Hobby path={saved}] (0,0) .. (1,1) .. (2,0);
+\draw[xshift=2cm,ultra thick,yellow,restore and use Hobby path={saved}{disjoint}];
+\end{tikzpicture}
+\end{example}
+%
+
+An example of where this is useful is in drawing knot diagrams.
+When so doing, it is sometimes convenient to draw a path (or segment of a path) twice in order to get the under/over crossings correct.
+For this situation, it can be useful to designate certain parts of the path as \Verb+blank+, whereby we mean to redraw them later.
+The point of a blank segment of a curve is that it is still taken into account when computing the algorithm but is left blank when it comes to rendering.
+A path can then be redrawn with the blank/non-{}blank segments reversed.
+As it might be desired to have only some blank segments drawn the second time, there are two types of blank.
+Only a \Verb+soft+ blank will be reversed in these circumstances.
+
+\begin{example}
+\begin{tikzpicture}[use Hobby shortcut,line width=1mm,rotate=90]
+\draw[blue,save Hobby path={left}]
+ ([out angle=90,in angle=-90]1,0) .. (1,1) .. ([blank=soft]0,2) .. (1,3) .. (1,4);
+\draw[red] ([out angle=90,in angle=-90]0,0) .. (0,1) .. (1,2) .. (0,3) .. (0,4);
+\draw[blue,restore and use Hobby path={left}{disjoint,invert soft blanks}];
+\end{tikzpicture}
+\end{example}
+%
+
+This can be taken a step further.
+The generated data can be saved to the \Verb+aux+ file and read back in, avoiding the need to regenerate it on each run.
+To engage this facility, the Hobby path has to be named (via \Verb+save Hobby path+) and the key \Verb+Hobby externalise+ (or \Verb+Hobby externalize+) must be given in a context that applies (such as on the path or on the surrounding scope).
+
+\bigskip
+
+
+The relevant keys are the following.
+
+\begin{itemize}
+\item \Verb+use previous Hobby path[=<options>]+.
+This (re)uses the previously generated Hobby path.
+As all the data is globally stored, this can technically be in a different \Verb+tikzpicture+.
+The \Verb+<options>+ will be applied, in so far as they are options that can be applied after the algorithm has run.
+
+\item \Verb+save Hobby path=<name>+.
+Saves a path for later use.
+The path is saved in a global macro so can be reused in another picture.
+
+\item \Verb+restore Hobby path=<name>+.
+This restores the named Hobby path (if it exists).
+It does not \emph{use} it.
+After this key, \Verb+use previous Hobby path+ will use the restored path.
+
+\item \Verb+restore and use Hobby path={<name>}{<options>}+.
+This restores the named path and uses it with \Verb+<options>+ applied.
+
+\item \Verb+Hobby externalise+ or \Verb+Hobby externalize+.
+This puts in place the code for saving the generated data to the \Verb+aux+ file.
+On subsequent runs, it uses the saved data rather than the current data.
+For a curve to make use of this, it has to be named via the \Verb+save Hobby path+ key.
+So to regenerate the data, either delete the \Verb+aux+ file or remove the \Verb+save Hobby path+ key for one compilation run.
+\end{itemize}
+
+The options that can be applied are those that affect the rendering of the curve but not its generation.
+When the curve is rendered (or \emph{used}, in the above parlance), \TeX\ steps along the coordinates of the generated curve and carries out an action for each piece.
+This action can be modified after the curve has been generated.
+The action will be one of:
+%
+\begin{itemize}
+\item Move to the end point (ignoring the control points).
+\item Draw a Bezier curve to the end point through the control points.
+\item Draw a Bezier curve to the end point through the control points and then move to the end point.
+\end{itemize}
+%
+The last is subtle: the move doesn't actually go anywhere but it ``breaks'' the curve at the designated point.
+In particular, a later \Verb+cycle+ would return to this point (or a later break) rather than to the start of the curve.
+
+These actions are triggered by the keys \Verb+blank+ and \Verb+break+.
+Each should be specified to the coordinate at the \emph{end} of the segment under consideration.
+The \Verb+blank+ key can be given the argument \Verb+soft+.
+The effect of this is seen when the key \Verb+invert soft blanks+ is used.
+This swaps the drawing action so that non-{}blank segments are skipped and \emph{soft} blanks are drawn.
+Non-{}soft-{}blank segments are still not drawn.
+
+\begin{example}
\begin{tikzpicture}[use Hobby shortcut]
-\draw (0,0) .. (1,0) .. (0,0) .. (0,-1);
-\draw[xshift=2cm] (0,0) .. ([excess angle=1]1,0) .. (0,0) .. (0,-1);
-\draw[xshift=4cm] (0,0) .. ([excess angle=-1]1,0) .. (0,0) .. (0,-1);
+\draw (0,0) .. (1,1) .. ([blank=soft]2,0) .. (3,1) .. ([blank]4,0) .. (5,1);
+\draw[red,use previous Hobby path={invert soft blanks,disjoint}];
\end{tikzpicture}
-\end{center}
-Although this is intended to be an integer, no check is done and so some quite odd curves can result from changing this parameter.
+\end{example}
+%
+
+As a more practical application, consider the following rendering of a trefoil knot.
+
+\begin{example}
+\begin{tikzpicture}[
+ use Hobby shortcut,
+ every path/.style={
+ line width=1mm,
+ white,
+ double=red,
+ double distance=.5mm
+ }
+]
+\draw ([closed]0,2) .. ([blank=soft]210:.5) .. (-30:2) ..
+([blank=soft]0,.5) .. (210:2) .. ([blank=soft]-30:.5);
+\draw[use previous Hobby path={invert soft blanks,disjoint}];
+\end{tikzpicture}
+\end{example}
+%
+
+This could easily be generalised using the \Verb+\foreach+ command, as demonstrated in the next code.
+
+\begin{example}
+\begin{tikzpicture}[
+ use Hobby shortcut,
+ every path/.style={
+ line width=1mm,
+ white,
+ double=red,
+ double distance=.5mm
+ }
+]
+\def\nfoil{9}
+\draw ([closed]0,2)
+\foreach \k in {1,...,\nfoil} {
+ .. ([blank=soft]90+360*\k/\nfoil-180/\nfoil:-.5) .. (90+360*\k/\nfoil:2)
+};
+\draw[use previous Hobby path={invert soft blanks,disjoint}];
+\end{tikzpicture}
+\end{example}
+%
+
+\subsection{Breaking the Path}
+
+One issue with the shortcut notation is that it is not possible (using this notation) to have two sets of curves following directly on from each other because there is no clear demarcation of the boundary.
+To make this possible, there is a key \Verb+Hobby action+, which installs an action to be taken after the point has been processed.
+The general key \Verb+Hobby action={code}+ can install arbitrary code.
+Probably the more useful variant is \Verb+Hobby finish+ which runs the algorithm on the points gathered so far.
+An example of the use of this is to make it possible to specify tangencies at certain points.
+Technically, once a tangent direction has been specified, the Hobby algorithm splits the set of points there and works on each piece separately.
+The following key implements this, the technicalities are due to the fact that the tangent angle has to be used twice: once to specify the angle of the path coming in to that point and once to specify the angle of the path coming out.
+Note that specifying the tangent vector at every point means that the algorithm is not actually being used.
+However, Hobby's formulae for the lengths of the control points is still being used.
+
+\begin{example}
+\begin{tikzpicture}[
+ use Hobby shortcut,
+ tangent/.style={%
+ in angle={(180+#1)},
+ Hobby finish,
+ designated Hobby path=next,
+ out angle=#1,
+ },
+]
+\draw[help lines] (-5,-5) grid (5,5);
+\draw (-5,0) -- (5,0) (0,-5) -- (0,5);
+\draw[thick] (-5,2) .. ([tangent=0]-3,3) .. (-1,1) .. (0,-1.3) .. %
+([tangent=0]1,-2) .. ([tangent=45]2,-1.5) .. ([tangent=0]3,-2) .. (5,-4);
+\end{tikzpicture}
+\end{example}
+%
+
+
\section{Implementing Hobby's Algorithm}
We start with a list of \(n+1\) points, \(z_0, \dotsc, z_n\).
-The base code assumes that these are already stored in two arrays\footnote{Arrays are thinly disguised property lists}: the \(x\)--coordinates in \Verb+\l_hobby_points_x_array+ and the \(y\)--coordinates in \Verb+\l_hobby_points_y_array+.
+The base code assumes that these are already stored in two arrays\footnote{Arrays are thinly disguised property lists.}: the \(x\)--coordinates in \Verb+\l_hobby_points_x_array+ and the \(y\)--coordinates in \Verb+\l_hobby_points_y_array+.
As our arrays are \(0\)--indexed, the actual number of points is one more than this.
-For a closed curve, we have \(z_n = z_0\)\footnote{Note that there is a difference between a closed curve and an open curve whose endpoints happen to overlap}.
+For a closed curve, we have \(z_n = z_0\)\footnote{Note that there is a difference between a closed curve and an open curve whose endpoints happen to overlap.}.
For closed curves it will be convenient to add an additional point at \(z_1\): thus \(z_{n+1} = z_1\).
This makes \(z_n\) an internal point and makes the algorithms for closed paths and open paths agree longer than they would otherwise.
The number of apparent points is stored as \Verb+\l_hobby_npoints_int+.
@@ -322,7 +540,7 @@ Following Hobby, let us write \(n'\) for \(n\) if the path is open and \(n+1\) i
From this we compute the distances and angles between successive points, storing these again as arrays.
These are \Verb+\l_hobby_distances_array+ and \Verb+\l_hobby_angles_array+.
The term indexed by \(k\) is the distance (or angle) of the line between the \(k\)th point and the \(k+1\)th point.
-For the internal nodes\footnote{Hobby calls the specified points \emph{knots}}, we store the difference in the angles in \Verb+\l_hobby_psi_array+.
+For the internal nodes\footnote{Hobby calls the specified points \emph{knots}.}, we store the difference in the angles in \Verb+\l_hobby_psi_array+.
The \(k\)th value on this is the angle subtended at the \(k\)th node.
This is thus indexed from \(1\) to \(n'-1\).
The bulk of the work consists in setting up a linear system to compute the angles of the control points.
@@ -338,7 +556,7 @@ At a node, say \(z_i\), we have various pieces of information:
The tensions are known at the start.
The speeds are computed from the angles.
Thus the key thing to compute is the angles.
-This is done by imposing a ``mock curvature'' condition.%
+This is done by imposing a ``mock curvature'' condition.
The formula for the mock curvature is:
%%
\[
@@ -362,35 +580,35 @@ Let us rearrange that to the following:
\begin{align*}
d_i \overline{\tau}_{i+1} \overline{\tau}_i^2 &\theta_{i-1} \\
%%
-+
+{}+
d_i \overline{\tau}_{i+1} \overline{\tau}_i^2 (1 - 3 \tau_{i-1}) &\phi_i \\
%%
--
+{}-
d_{i-1} \tau_{i-1} \tau_i^2 (1 - 3 \overline{\tau}_{i+1}) &\theta_i \\
%%
--
+{}-
d_{i-1} \tau_{i-1} \tau_i^2 &\phi_{i+1} \\
%%
-=
+&\qquad =
0
\end{align*}
%%
For both open and closed paths this holds for \(i=1\) to \(i=n' - 1\).
We also have the condition that \(\theta_i + \phi_i = -\psi_i\) where \(\psi_i\) is the angle subtended at a node by the lines to the adjacent nodes.
-This holds for the internal nodes\footnote{Recall that by dint of repetition, all nodes are effectively internal for a closed path}.
+This holds for the internal nodes\footnote{Recall that by dint of repetition, all nodes are effectively internal for a closed path.}.
Therefore for \(i=1\) to \(n'-1\) the above simplifies to the following:
%
\begin{align*}
d_i \overline{\tau}_{i+1} \overline{\tau}_i^2 &\theta_{i-1} \\
-+
+{}+
(d_i \overline{\tau}_{i+1} \overline{\tau}_i^2 (3 \tau_{i-1} - 1)
-+
+{}+
d_{i-1} \tau_{i-1} \tau_i^2 (3 \overline{\tau}_{i+1} - 1)) &\theta_i \\
-+
+{}+
d_{i-1} \tau_{i-1} \tau_i^2 & \theta_{i+1} \\
=
- d_i \overline{\tau}_{i+1} \overline{\tau}_i^2 (3 \tau_{i-1} - 1) &\psi_i \\
-- d_{i-1} \tau_{i-1} \tau_i^2& \psi_{i+1}
+{}- d_{i-1} \tau_{i-1} \tau_i^2& \psi_{i+1}
\end{align*}
For an open path we have two more equations.
One involves \(\theta_0\).
@@ -416,11 +634,11 @@ This yields:
%%
\begin{align*}
d_{n-1} \overline{\tau}_{n} \overline{\tau}_{n-1}^2 &\theta_{n-2} \\
-+
-(d_{n-1} \overline{\tau}_{n} \overline{\tau}_{n-1}^2 (3 \tau_{n-2} - 1)
-+
+{}+
+\big(d_{n-1} \overline{\tau}_{n} \overline{\tau}_{n-1}^2 (3 \tau_{n-2} - 1)
+{}+
d_{n-2} \tau_{n-2} \tau_{n-1}^2 (3 \overline{\tau}_{n} - 1) \\
-- d_{n-2} \tau_{n-2} \tau_{n-1}^2 \frac{\overline{\tau}_n^3 + \chi_n \tau_{n-1}^3(3 \overline{\tau}_n - 1)}{\overline{\tau}_n^3(3 \tau_{n-1} - 1) + \chi_n \tau_{n-1}^3}) & \theta_{n-1} \\
+{}- d_{n-2} \tau_{n-2} \tau_{n-1}^2 \frac{\overline{\tau}_n^3 + \chi_n \tau_{n-1}^3(3 \overline{\tau}_n - 1)}{\overline{\tau}_n^3(3 \tau_{n-1} - 1) + \chi_n \tau_{n-1}^3}\big) & \theta_{n-1} \\
=
- d_{n-1} \overline{\tau}_{n} \overline{\tau}_{n-1}^2 (3 \tau_{n-2} - 1) &\psi_{n-1}
\end{align*}
@@ -522,18 +740,18 @@ We now substitute these into Hobby's formulae for the lengths:
\begin{align*}
\rho_i &= \frac{2 + \alpha_i}{1 + (1 - c) \cos \theta_i + c \cos \phi_{i+1}} \\
\sigma_{i+1} &= \frac{2 - \alpha_i}{1 + (1 - c) \cos \phi_{i+1} + c \cos \theta_i} \\
-\alpha_i &= a (\sin \theta_i - b \sin \phi_{i+1})(\sin \phi_{i+1} - b \sin \theta_i)(\cos \theta_i - \cos \phi_{i+1})
+\text{where} \;\alpha_i &= a (\sin \theta_i - b \sin \phi_{i+1})(\sin \phi_{i+1} - b \sin \theta_i)(\cos \theta_i - \cos \phi_{i+1})
\end{align*}
%%
-where \(a = \sqrt{2}\), \(b = 1/16\), and \(c = (3 - \sqrt{5})/2\).
+and \(a = \sqrt{2}\), \(b = 1/16\), and \(c = (3 - \sqrt{5})/2\).
These are actually the \emph{relative} lengths so need to be adjusted by a factor of \(d_i/3\).
Now \(\theta_i\) is the angle relative to the line from \(z_i\) to \(z_{i+1}\), so to get the true angle we need to add back that angle.
Fortunately, we stored those angles at the start.
So the control points are:
%%
\begin{gather*}
-d_i \rho_i (\cos (\theta_i + \omega_i), \sin (\omega_{i+1} - \phi_{i+1}))/3 + z_i \\
-- d_i \sigma_{i+1} (\cos(\omega_{i+1} - \phi_{i+1}), \sin(\theta_i + \omega_i))/3 + z_{i+1}
+d_i \rho_i (\cos (\theta_i + \omega_i), \sin (\theta_i + \omega_i))/3 + z_i \\
+- d_i \sigma_{i+1} (\cos(\omega_i - \phi_{i+1}), \sin(\omega_i - \phi_{i+1}))/3 + z_{i+1}
\end{gather*}
\section{A Piecewise Version of Hobby's Algorithm}
@@ -543,10 +761,10 @@ One difficulty with Hobby's algorithm is that it works with the path as a whole.
It is therefore not possible to build up a path piecewise.
We therefore modify it to correct for this.
Obviously, the resulting path will be less ``ideal'', but will have the property that adding new points will not affect earlier segments.
-The method we use is to employ Hobby's algorithm on the two-{}segment subpaths.
-This provides two cubic Bezier curves: one from the \(k\)th point to the \(k+1\)st point and the second from the \(k+1\)st to the \(k+2\)nd.
+The method we use is to employ Hobby's algorithm on two-{}segment subpaths.
+When applied to a two-{}segment subpath, the algorithm provides two cubic Bezier curves: one from the \(k\)th point to the \(k+1\)st point and the second from the \(k+1\)st to the \(k+2\)nd.
Of this data, we keep the first segment and use that for the path between the \(k\)th and \(k+1\)st points.
-We also remember the outgoing angle of the first segment and use that as the incoming angle on the next computation (which will involve the \(k+1\)st, \(k+2\)nd, and \(k+3\)rd) points.
+We also remember the outgoing angle of the first segment and use that as the incoming angle on the next computation (which will involve the \(k+1\)st, \(k+2\)nd, and \(k+3\)rd points).
The two ends are slightly different to the middle segments.
On the first segment, we might have no incoming angle.
On the last segment, we render both pieces.
@@ -640,6 +858,11 @@ Again, let us consider the simpler case.
Then \(A_1 = d_1\), \(B_1 = 2 d_1 + d_0\), and \(D_1 = - 2 d_1 \psi_1\).
Thus \(\theta_1 = (-2 d_1 \psi_1 - d_1 \theta_0)/(2 d_1 + d_0) = - (2 \psi_1 + \theta_0) \frac{d_1}{2 d_1 + d_0}\).
We compute \(\phi_1 = -\psi_1 - \theta_1 = \frac{- \psi_1 d_0 + \theta_0 d_1}{2 d_1 + d_0}\) and \(\phi_2 = \theta_1\).
+Then we store \(\theta_1\) for the next iteration.
+
+The actual curves are then produced from the angles using the same formulae for the lengths of the control points as in the main algorithm.
+
+At the last stage, we render both segments of the generated curve.
\begin{thebibliography}{1} \bibitem{MR834054} John~D. Hobby. \newblock Smooth, easy to compute interpolating splines. \newblock {\em Discrete Comput. Geom.}, 1:123--140, 1986. \end{thebibliography}
diff --git a/Master/texmf-dist/source/latex/hobby/hobby.dtx b/Master/texmf-dist/source/latex/hobby/hobby.dtx
index 9815d005536..c41e8f8d9fc 100644
--- a/Master/texmf-dist/source/latex/hobby/hobby.dtx
+++ b/Master/texmf-dist/source/latex/hobby/hobby.dtx
@@ -110,7 +110,7 @@ and the derived files hobby.code.tex
%</driver>
% \fi
%
-% \CheckSum{1767}
+% \CheckSum{3002}
%
% \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
@@ -157,6 +157,8 @@ and the derived files hobby.code.tex
%
% \begin{macrocode}
\cs_generate_variant:Nn \fp_set:Nn {Nx}
+\cs_generate_variant:Nn \tl_if_eq:nnTF {VnTF}
+\cs_generate_variant:Nn \tl_if_eq:nnTF {xnTF}
% \end{macrocode}
%
% \subsubsection{Initialisation}
@@ -179,21 +181,21 @@ and the derived files hobby.code.tex
%
% Now we define our objects for use in generating the path.
%
-% \begin{function}{\l_hobby_closed_bool}
+% \begin{macro}{\l_hobby_closed_bool}
% \Verb+\l_hobby_closed_bool+ is \Verb+true+ if the path is closed.
% \begin{macrocode}
\bool_new:N \l_hobby_closed_bool
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_disjoint_bool}
+% \begin{macro}{\l_hobby_disjoint_bool}
% \Verb+\l_hobby_disjoint_bool+ is \Verb+true+ if the path should start with a \Verb+moveto+ command.
% \begin{macrocode}
\bool_new:N \l_hobby_disjoint_bool
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_points_array}
+% \begin{macro}{\l_hobby_points_array}
% \Verb+\l_hobby_points_array+ is an array holding the specified points on the path.
% In the \LaTeX3 code, a ``point'' is a token list of the form \Verb+x = <number>, y = <number>+.
% This gives us the greatest flexibility in passing points back and forth between the \LaTeX3 code and any calling code.
@@ -202,95 +204,102 @@ and the derived files hobby.code.tex
% \begin{macrocode}
\array_new:N \l_hobby_points_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_points_x_array}
+% \begin{macro}{\l_hobby_points_x_array}
% \Verb+\l_hobby_points_x_array+ is an array holding the \(x\)--{}coordinates of the specified points.
% \begin{macrocode}
\array_new:N \l_hobby_points_x_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_points_y_array}
+% \begin{macro}{\l_hobby_points_y_array}
% \Verb+\l_hobby_points_y_array+ is an array holding the \(y\)--{}coordinates of the specified points.
% \begin{macrocode}
\array_new:N \l_hobby_points_y_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_angles_array}
+% \begin{macro}{\l_hobby_actions_array}
+% \Verb+\l_hobby_actions_array+ is an array holding the (encoded) action to be taken out on the segment of the path ending at that point.
+% \begin{macrocode}
+\array_new:N \l_hobby_actions_array
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\l_hobby_angles_array}
% \Verb+\l_hobby_angles_array+ is an array holding the angles of the lines between the points.
% Specifically, the angle indexed by \(k\) is the angle in radians of the line from \(z_k\) to \(z_{k+1}\).
% \begin{macrocode}
\array_new:N \l_hobby_angles_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_distances_array}
+% \begin{macro}{\l_hobby_distances_array}
% \Verb+\l_hobby_distances_array+ is an array holding the distances between the points.
% Specifically, the distance indexed by \(k\), which we will write as \(d_k\), is the length of the line from \(z_k\) to \(z_{k+1}\).
% \begin{macrocode}
\array_new:N \l_hobby_distances_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_tension_out_array}
+% \begin{macro}{\l_hobby_tension_out_array}
% \Verb+\l_hobby_tension_out_array+ is an array holding the tension for the path as it leaves each point.
% This is a parameter that controls how much the curve ``flexes'' as it leaves the point.
% In the following, this will be written \(\tau_k\).
% \begin{macrocode}
\array_new:N \l_hobby_tension_out_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_tension_in_array}
+% \begin{macro}{\l_hobby_tension_in_array}
% \Verb+\l_hobby_tension_in_array+ is an array holding the tension for the path as it arrives at each point.
% This is a parameter that controls how much the curve ``flexes'' as it gets to the point.
% In the following, this will be written \(\overline{\tau}_k\).
% \begin{macrocode}
\array_new:N \l_hobby_tension_in_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_matrix_a_array}
+% \begin{macro}{\l_hobby_matrix_a_array}
% \Verb+\l_hobby_matrix_a_array+ is an array holding the subdiagonal of the linear system that has to be solved to find the angles of the control points.
% In the following, this will be denoted by \(A_i\).
% The first index is \(1\).
% \begin{macrocode}
\array_new:N \l_hobby_matrix_a_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_matrix_b_array}
+% \begin{macro}{\l_hobby_matrix_b_array}
% \Verb+\l_hobby_matrix_b_array+ is an array holding the diagonal of the linear system that has to be solved to find the angles of the control points.
% In the following, this will be denoted by \(B_i\).
% The first index is \(0\).
% \begin{macrocode}
\array_new:N \l_hobby_matrix_b_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_matrix_c_array}
+% \begin{macro}{\l_hobby_matrix_c_array}
% \Verb+\l_hobby_matrix_c_array+ is an array holding the superdiagonal of the linear system that has to be solved to find the angles of the control points.
% In the following, this will be denoted by \(C_i\).
% The first index is \(0\).
% \begin{macrocode}
\array_new:N \l_hobby_matrix_c_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_matrix_d_array}
+% \begin{macro}{\l_hobby_matrix_d_array}
% \Verb+\l_hobby_matrix_d_array+ is an array holding the target vector of the linear system that has to be solved to find the angles of the control points.
% In the following, this will be denoted by \(D_i\).
% The first index is \(1\).
% \begin{macrocode}
\array_new:N \l_hobby_matrix_d_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_vector_u_array}
+% \begin{macro}{\l_hobby_vector_u_array}
% \Verb+\l_hobby_vector_u_array+ is an array holding the perturbation of the linear system for closed paths.
-% The coefficient matrix for a \emph{open} path is tridiagonal and that means that Gaussian elimination runs faster than expected (\(O(n)\) instead of \(O(n^3)\)).
+% The coefficient matrix for an \emph{open} path is tridiagonal and that means that Gaussian elimination runs faster than expected (\(O(n)\) instead of \(O(n^3)\)).
% The matrix for a closed path is not tridiagonal but is not far off.
% It can be solved by perturbing it to a tridiagonal matrix and then modifying the result.
% This array represents a utility vector in that perturbation.
@@ -299,138 +308,138 @@ and the derived files hobby.code.tex
% \begin{macrocode}
\array_new:N \l_hobby_vector_u_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_excess_angle_array}
+% \begin{macro}{\l_hobby_excess_angle_array}
% \Verb+\l_hobby_excess_angle_array+ is an array that allows the user to say that the algorithm should add a multiple of \(2 \pi\) to the angle differences.
% This is because these angles are wrapped to the interval \((-\pi,\pi]\) but the wrapping might go wrong near the end points due to computation accuracy.
% The first index is \(1\).
% \begin{macrocode}
\array_new:N \l_hobby_excess_angle_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_psi_array}
+% \begin{macro}{\l_hobby_psi_array}
% \Verb+\l_hobby_psi_array+ is an array holding the difference of the angles of the lines entering and exiting a point.
% That is, \(\psi_k\) is the angle between the lines joining \(z_k\) to \(z_{k-1}\) and \(z_{k+1}\).
% The first index is \(1\).
% \begin{macrocode}
\array_new:N \l_hobby_psi_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_theta_array}
+% \begin{macro}{\l_hobby_theta_array}
% \Verb+\l_hobby_theta_array+ is an array holding the angles of the outgoing control points for the generated path.
% These are measured relative to the line joining the point to the next point on the path.
% The first index is \(0\).
% \begin{macrocode}
\array_new:N \l_hobby_theta_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_phi_array}
+% \begin{macro}{\l_hobby_phi_array}
% \Verb+\l_hobby_phi_array+ is an array holding the angles of the incoming control points for the generated path.
% These are measured relative to the line joining the point to the previous point on the path.
% The first index is \(1\).
% \begin{macrocode}
\array_new:N \l_hobby_phi_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_sigma_array}
+% \begin{macro}{\l_hobby_sigma_array}
% \Verb+\l_hobby_sigma_array+ is an array holding the lengths of the outgoing control points for the generated path.
% The units are such that the length of the line to the next specified point is one unit.
% \begin{macrocode}
\array_new:N \l_hobby_sigma_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_rho_array}
+% \begin{macro}{\l_hobby_rho_array}
% \Verb+\l_hobby_rho_array+ is an array holding the lengths of the incoming control points for the generated path.
% The units are such that the length of the line to the previous specified point is one unit.
% \begin{macrocode}
\array_new:N \l_hobby_rho_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_controla_array}
+% \begin{macro}{\l_hobby_controla_array}
% \Verb+\l_hobby_controla_array+ is an array holding the coordinates of the first control points on the curves.
% The format is the same as for \Verb+\l_hobby_points_array+.
% \begin{macrocode}
\array_new:N \l_hobby_controla_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_controlb_array}
+% \begin{macro}{\l_hobby_controlb_array}
% \Verb+\l_hobby_controlb_array+ is an array holding the coordinates of the second control points on the curves.
% The format is the same as for \Verb+\l_hobby_points_array+.
% \begin{macrocode}
\array_new:N \l_hobby_controlb_array
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_matrix_v_fp}
+% \begin{macro}{\l_hobby_matrix_v_fp}
% \Verb+\l_hobby_matrix_v_fp+ is a number which is used when doing the perturbation of the solution of the linear system for a closed curve.
% There is actually a vector, \(v\), that this corresponds to but that vector only has one component that needs computation.
% \begin{macrocode}
\fp_new:N \l_hobby_matrix_v_fp
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_tempa_fp}
+% \begin{macro}{\l_hobby_tempa_fp}
% \Verb+\l_hobby_tempa_fp+ is a temporary variable of type \Verb+fp+.
% \begin{macrocode}
\fp_new:N \l_hobby_tempa_fp
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_tempb_fp}
+% \begin{macro}{\l_hobby_tempb_fp}
% \Verb+\l_hobby_tempb_fp+ is a temporary variable of type \Verb+fp+.
% \begin{macrocode}
\fp_new:N \l_hobby_tempb_fp
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_tempc_fp}
+% \begin{macro}{\l_hobby_tempc_fp}
% \Verb+\l_hobby_tempc_fp+ is a temporary variable of type \Verb+fp+.
% \begin{macrocode}
\fp_new:N \l_hobby_tempc_fp
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_tempd_fp}
+% \begin{macro}{\l_hobby_tempd_fp}
% \Verb+\l_hobby_tempd_fp+ is a temporary variable of type \Verb+fp+.
% \begin{macrocode}
\fp_new:N \l_hobby_tempd_fp
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_temps_fp}
+% \begin{macro}{\l_hobby_temps_fp}
% \Verb+\l_hobby_temps_fp+ is a temporary variable of type \Verb+fp+.
% \begin{macrocode}
\fp_new:N \l_hobby_temps_fp
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_in_curl_fp}
+% \begin{macro}{\l_hobby_in_curl_fp}
% \Verb+\l_hobby_in_curl_fp+ is the ``curl'' at the end of an open path.
% This is used if the angle at the end is not specified.
% \begin{macrocode}
\fp_new:N \l_hobby_in_curl_fp
\fp_set:Nn \l_hobby_in_curl_fp {1}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_out_curl_fp}
+% \begin{macro}{\l_hobby_out_curl_fp}
% \Verb+\l_hobby_out_curl_fp+ is the ``curl'' at the start of an open path.
% This is used if the angle at the start is not specified.
% \begin{macrocode}
\fp_new:N \l_hobby_out_curl_fp
\fp_set:Nn \l_hobby_out_curl_fp {1}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_in_angle_fp}
+% \begin{macro}{\l_hobby_in_angle_fp}
% \Verb+\l_hobby_in_angle_fp+ is the angle at the end of an open path.
% If this is not specified, it will be computed automatically.
% It is set to \Verb+\c_undefined_fp+ to allow easy detection of when it has been specified.
@@ -438,9 +447,9 @@ and the derived files hobby.code.tex
\fp_new:N \l_hobby_in_angle_fp
\fp_set_eq:NN \l_hobby_in_angle_fp \c_undefined_fp
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_out_angle_fp}
+% \begin{macro}{\l_hobby_out_angle_fp}
% \Verb+\l_hobby_out_angle_fp+ is the angle at the start of an open path.
% If this is not specified, it will be computed automatically.
% It is set to \Verb+\c_undefined_fp+ to allow easy detection of when it has been specified.
@@ -448,16 +457,22 @@ and the derived files hobby.code.tex
\fp_new:N \l_hobby_out_angle_fp
\fp_set_eq:NN \l_hobby_out_angle_fp \c_undefined_fp
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\l_hobby_npoints_int}
+% \begin{macro}{\l_hobby_npoints_int}
% \Verb+\l_hobby_npoints_int+ is one less than the number of points on the curve.
% As our list of points starts at \(0\), this is the index of the last point.
% In the algorithm for a closed curve, some points are repeated whereupon this is incremented so that it is always the index of the last point.
% \begin{macrocode}
\int_new:N \l_hobby_npoints_int
% \end{macrocode}
-% \end{function}
+% \end{macro}
+%
+% \begin{macro}{\l_hobby_draw_int}
+% \begin{macrocode}
+\int_new:N \l_hobby_draw_int
+% \end{macrocode}
+% \end{macro}
%
% A ``point'' is a key-value list setting the x-value, the y-value, and the tensions at that point.
% Using keys makes it easier to pass points from the algorithm code to the calling code and vice versa without either knowing too much about the other.
@@ -468,34 +483,78 @@ and the derived files hobby.code.tex
tension~out .fp_set:N = \l_hobby_tempc_fp,
tension~in .fp_set:N = \l_hobby_tempd_fp,
excess~angle .fp_set:N = \l_hobby_temps_fp,
+ break .tl_set:N = \l_tmpb_tl,
+ blank .tl_set:N = \l_tmpa_tl,
tension .meta:n = { tension~out=#1, tension~in=#1 },
+ break .default:n = false,
+ blank .default:n = false,
+ invert~soft~blanks .choice:,
+ invert~soft~blanks / true .code:n = {
+ \int_gset:Nn \l_hobby_draw_int {0}
+ },
+ invert~soft~blanks / false .code:n = {
+ \int_gset:Nn \l_hobby_draw_int {1}
+ },
+ invert~soft~blanks .default:n = true,
tension~out .default:n = 1,
tension~in .default:n = 1,
excess~angle .default:n = 0,
- in~angle .fp_set:N = \l_hobby_in_angle_fp,
- out~angle .fp_set:N = \l_hobby_out_angle_fp,
- in~curl .fp_set:N = \l_hobby_in_curl_fp,
- out~curl .fp_set:N = \l_hobby_out_curl_fp,
- closed .bool_set:N = \l_hobby_closed_bool,
+ in~angle .fp_gset:N = \l_hobby_in_angle_fp,
+ out~angle .fp_gset:N = \l_hobby_out_angle_fp,
+ in~curl .fp_gset:N = \l_hobby_in_curl_fp,
+ out~curl .fp_gset:N = \l_hobby_out_curl_fp,
+ closed .bool_gset:N = \l_hobby_closed_bool,
closed .default:n = true,
- disjoint .bool_set:N = \l_hobby_disjoint_bool,
+ disjoint .bool_gset:N = \l_hobby_disjoint_bool,
disjoint .default:n = true,
+ break~default .code:n = {
+ \keys_define:nn { hobby / read in all }
+ {
+ break .default:n = #1
+ }
+ },
+ blank~default .code:n = {
+ \keys_define:nn { hobby / read in all }
+ {
+ blank .default:n = #1
+ }
+ },
}
% \end{macrocode}
-% There are certain other parameters than can be set for a give curve.
+% There are certain other parameters that can be set for a given curve.
% \begin{macrocode}
\keys_define:nn { hobby / read in params} {
- in~angle .fp_set:N = \l_hobby_in_angle_fp,
- out~angle .fp_set:N = \l_hobby_out_angle_fp,
- in~curl .fp_set:N = \l_hobby_in_curl_fp,
- out~curl .fp_set:N = \l_hobby_out_curl_fp,
- closed .bool_set:N = \l_hobby_closed_bool,
+ in~angle .fp_gset:N = \l_hobby_in_angle_fp,
+ out~angle .fp_gset:N = \l_hobby_out_angle_fp,
+ in~curl .fp_gset:N = \l_hobby_in_curl_fp,
+ out~curl .fp_gset:N = \l_hobby_out_curl_fp,
+ closed .bool_gset:N = \l_hobby_closed_bool,
closed .default:n = true,
- disjoint .bool_set:N = \l_hobby_disjoint_bool,
+ disjoint .bool_gset:N = \l_hobby_disjoint_bool,
disjoint .default:n = true,
+ break~default .code:n = {
+ \keys_define:nn { hobby / read in all }
+ {
+ break .default:n = #1
+ }
+ },
+ blank~default .code:n = {
+ \keys_define:nn { hobby / read in all }
+ {
+ blank .default:n = #1
+ }
+ },
+ invert~soft~blanks .choice:,
+ invert~soft~blanks / true .code:n = {
+ \int_gset:Nn \l_hobby_draw_int {0}
+ },
+ invert~soft~blanks / false .code:n = {
+ \int_gset:Nn \l_hobby_draw_int {1}
+ },
+ invert~soft~blanks .default:n = true,
}
% \end{macrocode}
-% \begin{function}{\hobby_distangle:n}
+% \begin{macro}{\hobby_distangle:n}
% Computes the distance and angle between successive points.
% The argument given is the index of the current point.
% Assumptions: the points are in \Verb+\l_hobby_points_x_array+ and \Verb+\l_hobby_points_y_array+ and the index of the last point is \Verb+\l_hobby_npoints_int+.
@@ -516,10 +575,10 @@ and the derived files hobby.code.tex
\array_push:Nx \l_hobby_distances_array {\fp_to_tl:N \l_hobby_tempd_fp}
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
%
-% \begin{function}{\fp_atantwo:NNN}
+% \begin{macro}{\fp_atantwo:NNN}
% Computes the angle of the point specified by the latter two arguments, storing the answer in the first.
% The inverse tangent function is not yet implemented in \LaTeX3 so for now we use the \Verb+pgfmath+ function.
% When this is implemented in \LaTeX3 this should be replaced.
@@ -529,9 +588,9 @@ and the derived files hobby.code.tex
\exp_args:NNo \fp_set:Nn #1 {\pgfmathresult}
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\fp_veclen:NVV}
+% \begin{macro}{\fp_veclen:NVV}
% Computes the length of the vector specified by the latter two arguments, storing the answer in the first.
% \begin{macrocode}
\cs_new:Nn \fp_veclen:Nnn {
@@ -539,9 +598,9 @@ and the derived files hobby.code.tex
}
\cs_generate_variant:Nn \fp_veclen:Nnn {NVV}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby_ctrllen:Nnn}
+% \begin{macro}{\hobby_ctrllen:Nnn}
% Computes the length of the control point vector from the two angles, storing the answer in the first argument given.
% \begin{macrocode}
\cs_new:Nn \hobby_ctrllen:Nnn {
@@ -553,9 +612,9 @@ and the derived files hobby.code.tex
}
\cs_generate_variant:Nn \hobby_ctrllen:Nnn {NVV}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby_append_point_copy:n}
+% \begin{macro}{\hobby_append_point_copy:n}
% This function adds a copy of the point (numbered by its argument) to the end of the list of points, copying all the relevant data (coordinates, tension, etc.).
%
% Originally from Bruno Le Foch on TeX-SX.
@@ -568,13 +627,14 @@ and the derived files hobby.code.tex
\hobby_append_point_copy_aux:Nn \l_hobby_tension_in_array {#1}
\hobby_append_point_copy_aux:Nn \l_hobby_tension_out_array {#1}
\hobby_append_point_copy_aux:Nn \l_hobby_excess_angle_array {#1}
+ \hobby_append_point_copy_aux:Nn \l_hobby_actions_array {#1}
}
\cs_new_protected:Npn \hobby_append_point_copy_aux:Nn #1#2
- { \array_push:Nx #1 { \array_get:Nn #1 {#2} } }
+ { \array_gpush:Nx #1 { \array_get:Nn #1 {#2} } }
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby_genpath:}
+% \begin{macro}{\hobby_gen_path:}
% This is the curve generation function.
% We assume at the start that we have an array containing all the points that the curve must go through, and the various curve parameters have been initialised.
% So these must be set up by a wrapper function which then calls this one.
@@ -590,10 +650,11 @@ and the derived files hobby.code.tex
% \item \Verb+\l_hobby_in_angle_fp+
% \item \Verb+\l_hobby_out_angle_fp+
% \item \Verb+\l_hobby_closed_bool+
+% \item \Verb+\l_hobby_actions_array+
% \end{enumerate}
%
% \begin{macrocode}
-\cs_new:Nn \hobby_genpath:
+\cs_new:Nn \hobby_gen_path:
{
% \end{macrocode}
% For much of the time, we can pretend that a closed path is the same as an open path.
@@ -639,20 +700,109 @@ and the derived files hobby.code.tex
%
% Set \Verb+\l_hobby_npoints_int+ to the number of points (minus one).
% \begin{macrocode}
-\int_set:Nn \l_hobby_npoints_int {\array_length:N \l_hobby_points_y_array}
+\int_gset:Nn \l_hobby_npoints_int {\array_length:N \l_hobby_points_y_array}
+% \end{macrocode}
+% At this point, we need to decide what to do.
+% This will depend on whether we have any intermediate points.
+% \begin{macrocode}
+\int_compare:nNnTF {\l_hobby_npoints_int} = {0} {
+% \end{macrocode}
+% Only one point, do nothing
+% \begin{macrocode}
+}
+{
+ \int_compare:nNnTF {\l_hobby_npoints_int} = {1} {
+% \end{macrocode}
+% Only two points, skip processing.
+% Just need to set the incoming and outgoing angles
+% \begin{macrocode}
+\hobby_distangle:n {0}
+\fp_if_undefined:NF \l_hobby_out_angle_fp
+{
+ \fp_set:Nn \l_hobby_tempa_fp { \l_hobby_out_angle_fp
+ - \array_get:Nn \l_hobby_angles_array {0} }
+% \end{macrocode}
+% We want to ensure that these angles lie in the range \((-\pi,\pi]\).
+% So if the angle is bigger than \(\pi\), we subtract \(2 \pi\).
+% (It shouldn't be that we can get bigger than \(3 \pi\) - check this)
+% \begin{macrocode}
+ \fp_compare:nT {\l_hobby_tempa_fp > \c_pi_fp }
+ {
+ \fp_sub:Nn \l_hobby_tempa_fp {2 * \c_pi_fp}
+ }
+% \end{macrocode}
+% Similarly, we check to see if the angle is less than \(-\pi\).
+% \begin{macrocode}
+ \fp_compare:nT {\l_hobby_tempa_fp < -\c_pi_fp }
+ {
+ \fp_add:Nn \l_hobby_tempa_fp {2 * \c_pi_fp}
+ }
+ \array_put:Nnx \l_hobby_theta_array {0} {\fp_to_tl:N \l_hobby_tempa_fp}
+ \fp_if_undefined:NT \l_hobby_in_angle_fp
+ {
+%^^A \fp_mul:Nn \l_hobby_tempa_fp {-1}
+ \array_put:Nnx \l_hobby_phi_array {1}{ \fp_to_tl:N \l_hobby_tempa_fp}
+ }
+ }
+\fp_if_undefined:NTF \l_hobby_in_angle_fp
+{
+ \fp_if_undefined:NT \l_hobby_out_angle_fp
+ {
+ \array_put:Nnx \l_hobby_phi_array {1} {0}
+ \array_put:Nnx \l_hobby_theta_array {0} {0}
+ }
+}
+{
+ \fp_set:Nn \l_hobby_tempa_fp { - \l_hobby_in_angle_fp + \c_pi_fp
++ (\array_get:Nn \l_hobby_angles_array {0})}
+ \fp_compare:nT {\l_hobby_tempa_fp > \c_pi_fp }
+ {
+ \fp_sub:Nn \l_hobby_tempa_fp {2 * \c_pi_fp}
+ }
+ \fp_compare:nT {\l_hobby_tempa_fp < -\c_pi_fp }
+ {
+ \fp_add:Nn \l_hobby_tempa_fp {2 * \c_pi_fp}
+ }
+
+ \array_put:Nnx \l_hobby_phi_array {1}
+ {\fp_to_tl:N \l_hobby_tempa_fp}
+ \fp_if_undefined:NT \l_hobby_out_angle_fp
+ {
+%^^A \fp_mul:Nn \l_hobby_tempa_fp {-1}
+ \array_put:Nnx \l_hobby_theta_array {0}{ \fp_to_tl:N \l_hobby_tempa_fp}
+ }
+}
+
+ }
+ {
+% \end{macrocode}
+% Got enough points, go on with processing
+% \begin{macrocode}
+ \hobby_compute_path:
+ }
+ \hobby_build_path:
+}
+}
% \end{macrocode}
+% \end{macro}
%
+%
+% \begin{macro}{\hobby_compute_path:}
+% This is the path builder where we have enough points to run the algorithm.
+% \begin{macrocode}
+\cs_new:Nn \hobby_compute_path:
+{
+% \end{macrocode}
% Our first step is to go through the list of points and compute the distances and angles between successive points.
% Thus \(d_i\) is the distance from \(z_i\) to \(z_{i+1}\) and the angle is the angle of the line from \(z_i\) to \(z_{i+1}\).
-
% \begin{macrocode}
-\prg_stepwise_function:nnnN {0} {1} {\l_hobby_npoints_int - 1} \hobby_distangle:n
+\int_step_function:nnnN {0} {1} {\l_hobby_npoints_int - 1} \hobby_distangle:n
% \end{macrocode}
%
% For the majority of the code, we're only really interested in the differences of the angles.
% So for each internal point we compute the differences in the angles.
% \begin{macrocode}
- \prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
+ \int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
\fp_set:Nx \l_hobby_tempa_fp {
\array_get:Nn \l_hobby_angles_array {##1}
- \array_get:Nn \l_hobby_angles_array {##1 - 1}}
@@ -699,7 +849,7 @@ and the derived files hobby.code.tex
% We start with the subdiagonal.
% This is indexed from \(1\) to \(n-1\).
% \begin{macrocode}
- \prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
+ \int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
\array_put:Nnx \l_hobby_matrix_a_array {##1} {\fp_to_tl:n {
\array_get:Nn \l_hobby_tension_in_array {##1}^2
* \array_get:Nn \l_hobby_distances_array {##1}
@@ -711,7 +861,7 @@ and the derived files hobby.code.tex
% Next, we attack main diagonal.
% We might need to adjust the first and last terms, but we'll do that in a minute.
% \begin{macrocode}
- \prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
+ \int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
\array_put:Nnx \l_hobby_matrix_b_array {##1} {\fp_to_tl:n
{(3 * (\array_get:Nn \l_hobby_tension_in_array {##1 + 1}) - 1) *
@@ -729,7 +879,7 @@ and the derived files hobby.code.tex
%
% Next, the superdiagonal.
% \begin{macrocode}
- \prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int - 2} {
+ \int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int - 2} {
\array_put:Nnx \l_hobby_matrix_c_array {##1} {\fp_to_tl:n
{(\array_get:Nn \l_hobby_tension_in_array {##1})^2
@@ -742,7 +892,7 @@ and the derived files hobby.code.tex
%
% Lastly (before the adjustments), the target vector.
% \begin{macrocode}
- \prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int - 2} {
+ \int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int - 2} {
\array_put:Nnx \l_hobby_matrix_d_array {##1} {\fp_to_tl:n
{
@@ -798,7 +948,7 @@ and the derived files hobby.code.tex
% \begin{macrocode}
\array_put:Nnn \l_hobby_vector_u_array {0} {1}
\array_put:Nnn \l_hobby_vector_u_array {\l_hobby_npoints_int - 1} {1}
- \prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int - 2} {
+ \int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int - 2} {
\array_put:Nnn \l_hobby_vector_u_array {##1} {0}
}
% \end{macrocode}
@@ -937,7 +1087,7 @@ and the derived files hobby.code.tex
% Now we have the tridiagonal matrix in place, we implement the solution.
% We start with the forward eliminations.
% \begin{macrocode}
-\prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
+\int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
\array_put:Nnx \l_hobby_matrix_b_array {##1} {\fp_to_tl:n {
(\array_get:Nn \l_hobby_matrix_b_array {##1 - 1})
@@ -997,7 +1147,7 @@ and the derived files hobby.code.tex
% \end{macrocode}
% Now we iterate over the vectors, doing the remaining back substitutions.
% \begin{macrocode}
-\prg_stepwise_inline:nnnn {\l_hobby_npoints_int - 2} {-1} {0} {
+\int_step_inline:nnnn {\l_hobby_npoints_int - 2} {-1} {0} {
\array_put:Nnx \l_hobby_theta_array {##1} {\fp_to_tl:n {
( (\array_get:Nn \l_hobby_matrix_d_array {##1})
@@ -1010,7 +1160,7 @@ and the derived files hobby.code.tex
% \end{macrocode}
% On a closed path, we also need to work out \(M^{-1} u\).
% \begin{macrocode}
-\prg_stepwise_inline:nnnn {\l_hobby_npoints_int - 2} {-1} {0} {
+\int_step_inline:nnnn {\l_hobby_npoints_int - 2} {-1} {0} {
\array_put:Nnx \l_hobby_vector_u_array {##1} {\fp_to_tl:n
{
((\array_get:Nn \l_hobby_vector_u_array {##1})
@@ -1035,7 +1185,7 @@ and the derived files hobby.code.tex
+ 1
)}
-\prg_stepwise_inline:nnnn {0} {1} {\l_hobby_npoints_int - 1} {
+\int_step_inline:nnnn {0} {1} {\l_hobby_npoints_int - 1} {
\array_put:Nnx \l_hobby_theta_array {##1} {\fp_to_tl:n {
(\array_get:Nn \l_hobby_theta_array {##1})
@@ -1049,7 +1199,7 @@ and the derived files hobby.code.tex
% Now that we have computed the \(\theta_i\)s, we can quickly compute the \(\phi_i\)s.
%
% \begin{macrocode}
-\prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
+\int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
\array_put:Nnx \l_hobby_phi_array {##1} {\fp_to_tl:n {
- (\array_get:Nn \l_hobby_psi_array {##1})
@@ -1063,7 +1213,7 @@ and the derived files hobby.code.tex
% Cheaply, of course.
% \begin{macrocode}
\bool_if:NTF \l_hobby_closed_bool {
- \int_decr:N \l_hobby_npoints_int
+ \int_gdecr:N \l_hobby_npoints_int
}{
% \end{macrocode}
% If \(\phi_n\) was not given, we compute it from \(\theta_{n-1}\).
@@ -1087,11 +1237,20 @@ and the derived files hobby.code.tex
}}
}
}
+}
% \end{macrocode}
+% \end{macro}
%
+%
+% \begin{macro}{\hobby_build_path:}
+% Once we've computed the angles, we build the actual path.
+% \begin{macrocode}
+\cs_new:Nn \hobby_build_path:
+{
+% \end{macrocode}
% Next task is to compute the \(\rho_i\) and \(\sigma_i\).
% \begin{macrocode}
-\prg_stepwise_inline:nnnn {0} {1} {\l_hobby_npoints_int - 1} {
+\int_step_inline:nnnn {0} {1} {\l_hobby_npoints_int - 1} {
\fp_set:Nn \l_hobby_tempa_fp {\array_get:Nn \l_hobby_theta_array {##1}}
@@ -1109,9 +1268,8 @@ and the derived files hobby.code.tex
% \end{macrocode}
% Lastly, we generate the coordinates of the control points.
% \begin{macrocode}
-\prg_stepwise_inline:nnnn {0} {1} {\l_hobby_npoints_int - 1} {
-
-\array_put:Nnx \l_hobby_controla_array {##1 + 1} {x = \fp_eval:n {
+\int_step_inline:nnnn {0} {1} {\l_hobby_npoints_int - 1} {
+\array_gput:Nnx \l_hobby_controla_array {##1 + 1} {x = \fp_eval:n {
(\array_get:Nn \l_hobby_points_x_array {##1})
+
(\array_get:Nn \l_hobby_distances_array {##1}) *
@@ -1131,9 +1289,8 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
}
}
}
-
-\prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int} {
- \array_put:Nnx \l_hobby_controlb_array {##1} {
+\int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int} {
+ \array_gput:Nnx \l_hobby_controlb_array {##1} {
x = \fp_eval:n {\array_get:Nn \l_hobby_points_x_array {##1}
- (\array_get:Nn \l_hobby_distances_array {##1 - 1})
* (\array_get:Nn \l_hobby_sigma_array {##1})
@@ -1149,46 +1306,19 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
}
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobbyinit}
+% \begin{macro}{\hobbyinit}
% Initialise the settings for Hobby's algorithm
% \begin{macrocode}
\NewDocumentCommand \hobbyinit {m m m} {
-\hobby_set_cmds:nnn#1#2#3
-\array_clear:N \l_hobby_points_array
-\array_clear:N \l_hobby_points_x_array
-\array_clear:N \l_hobby_points_y_array
-\array_clear:N \l_hobby_angles_array
-\array_clear:N \l_hobby_distances_array
-\array_clear:N \l_hobby_tension_out_array
-\array_clear:N \l_hobby_tension_in_array
-\array_clear:N \l_hobby_excess_angle_array
-\array_clear:N \l_hobby_matrix_a_array
-\array_clear:N \l_hobby_matrix_b_array
-\array_clear:N \l_hobby_matrix_c_array
-\array_clear:N \l_hobby_matrix_d_array
-\array_clear:N \l_hobby_vector_u_array
-\array_clear:N \l_hobby_psi_array
-\array_clear:N \l_hobby_theta_array
-\array_clear:N \l_hobby_phi_array
-\array_clear:N \l_hobby_sigma_array
-\array_clear:N \l_hobby_rho_array
-\array_clear:N \l_hobby_controla_array
-\array_clear:N \l_hobby_controlb_array
-\bool_set_false:N \l_hobby_closed_bool
-\bool_set_false:N \l_hobby_disjoint_bool
-
- \int_set:Nn \l_hobby_npoints_int {-1}
- \fp_set_eq:NN \l_hobby_in_angle_fp \c_undefined_fp
- \fp_set_eq:NN \l_hobby_out_angle_fp \c_undefined_fp
- \fp_set_eq:NN \l_hobby_in_curl_fp \c_one_fp
- \fp_set_eq:NN \l_hobby_out_curl_fp \c_one_fp
+ \hobby_set_cmds:nnn#1#2#3
+ \hobby_clear_path:
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobbyaddpoint}
+% \begin{macro}{\hobbyaddpoint}
% This adds a point, possibly with tensions, to the current stack.
% \begin{macrocode}
\NewDocumentCommand \hobbyaddpoint { m } {
@@ -1197,21 +1327,34 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
tension~out,
tension~in,
excess~angle,
+ blank,
+ break,
#1
}
- \array_push:Nx \l_hobby_tension_out_array {\fp_to_tl:N \l_hobby_tempc_fp}
- \array_push:Nx \l_hobby_tension_in_array {\fp_to_tl:N \l_hobby_tempd_fp}
- \array_push:Nx \l_hobby_excess_angle_array {\fp_to_tl:N \l_hobby_temps_fp}
- \array_push:Nx \l_hobby_points_array {
+ \tl_if_eq:VnTF {\l_tmpa_tl} {true}
+ {\tl_set:Nn \l_tmpa_tl {2}}
+ {
+ \tl_if_eq:VnTF {\l_tmpa_tl} {soft}
+ {\tl_set:Nn \l_tmpa_tl {0}}
+ {\tl_set:Nn \l_tmpa_tl {1}}
+ }
+ \tl_if_eq:VnTF {\l_tmpb_tl} {true}
+ {\tl_put_right:Nn \l_tmpa_tl {1}}
+ {\tl_put_right:Nn \l_tmpa_tl {0}}
+ \array_gpush:Nx \l_hobby_actions_array {\l_tmpa_tl}
+ \array_gpush:Nx \l_hobby_tension_out_array {\fp_to_tl:N \l_hobby_tempc_fp}
+ \array_gpush:Nx \l_hobby_tension_in_array {\fp_to_tl:N \l_hobby_tempd_fp}
+ \array_gpush:Nx \l_hobby_excess_angle_array {\fp_to_tl:N \l_hobby_temps_fp}
+ \array_gpush:Nx \l_hobby_points_array {
x = \fp_use:N \l_hobby_tempa_fp,
y = \fp_use:N \l_hobby_tempb_fp }
- \array_push:Nx \l_hobby_points_x_array {\fp_to_tl:N \l_hobby_tempa_fp}
- \array_push:Nx \l_hobby_points_y_array {\fp_to_tl:N \l_hobby_tempb_fp}
+ \array_gpush:Nx \l_hobby_points_x_array {\fp_to_tl:N \l_hobby_tempa_fp}
+ \array_gpush:Nx \l_hobby_points_y_array {\fp_to_tl:N \l_hobby_tempb_fp}
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobbysetparams}
+% \begin{macro}{\hobbysetparams}
% This sets the parameters for the curve.
% \begin{macrocode}
\NewDocumentCommand \hobbysetparams { m } {
@@ -1221,42 +1364,286 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
}
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby_set_cmds:nnn}
+% \begin{macro}{\hobby_set_cmds:nnn}
% The path-generation code doesn't know what to actually do with the path so the initialisation code will set some macros to do that.
% This is an auxiliary command that sets these macros.
% \begin{macrocode}
\cs_new:Nn \hobby_set_cmds:nnn {
- \cs_set_eq:NN \hobby_moveto:n #1
- \cs_set_eq:NN \hobby_curveto:nnn #2
- \cs_set_eq:NN \hobby_close:n #3
+ \cs_gset_eq:NN \hobby_moveto:n #1
+ \cs_gset_eq:NN \hobby_curveto:nnn #2
+ \cs_gset_eq:NN \hobby_close:n #3
}
% \end{macrocode}
-% \end{function}
-% \begin{function}{\hobbygenpath}
-% This is the user (well, sort of) command that generates and uses the curve.
+% \end{macro}
+%
+% \begin{macro}{\hobbygenpath}
+% This is the user (well, sort of) command that generates the curve.
% \begin{macrocode}
-\tl_new:N \l_tmpc_tl
\NewDocumentCommand \hobbygenpath { } {
- \hobby_genpath:
+ \array_if_empty:NF \l_hobby_points_array {
+ \hobby_gen_path:
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\hobbygenifnecpath}
+% If the named path doesn't exist, it is generated and named.
+% If it does exist, we restore it.
+% Either way, we save it to the aux file.
+% \begin{macrocode}
+\NewDocumentCommand \hobbygenifnecpath { m } {
+ \tl_if_exist:cTF {g_hobby_#1_path}
+ {
+ \tl_use:c {g_hobby_#1_path}
+ }
+ {
+ \hobby_gen_path:
+ }
+ \hobby_save_path:n {#1}
+ \hobby_save_path_to_aux:x {#1}
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\hobbygenifnecusepath}
+% If the named path doesn't exist, it is generated and named.
+% If it does exist, we restore it.
+% Either way, we save it to the aux file.
+% \begin{macrocode}
+\NewDocumentCommand \hobbygenuseifnecpath { m } {
+ \tl_if_exist:cTF {g_hobby_#1_path}
+ {
+ \tl_use:c {g_hobby_#1_path}
+ }
+ {
+ \hobby_gen_path:
+ }
+ \hobby_save_path:n {#1}
+ \hobby_save_path_to_aux:x {#1}
+ \hobby_use_path:
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\hobbyusepath}
+% This is the user (well, sort of) command that uses the last generated curve.
+% \begin{macrocode}
+\NewDocumentCommand \hobbyusepath { m } {
+ \hobbysetparams{#1}
+ \hobby_use_path:
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\hobbysavepath}
+% This is the user (well, sort of) command that uses the last generated curve.
+% \begin{macrocode}
+\NewDocumentCommand \hobbysavepath { m } {
+ \hobby_save_path:n {#1}
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\hobbyrestorepath}
+% This is the user (well, sort of) command that uses the last generated curve.
+% \begin{macrocode}
+\NewDocumentCommand \hobbyrestorepath { m } {
+ \tl_if_exist:cT {g_hobby_#1_path} {
+ \tl_use:c {g_hobby_#1_path}
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\hobbyshowpath}
+% This is the user (well, sort of) command that uses the last generated curve.
+% \begin{macrocode}
+\NewDocumentCommand \hobbyshowpath { m } {
+ \tl_if_exist:cT {g_hobby_#1_path} {
+ \tl_show:c {g_hobby_#1_path}
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\hobbygenusepath}
+% This is the user (well, sort of) command that generates a curve and uses it.
+% \begin{macrocode}
+\NewDocumentCommand \hobbygenusepath { } {
+ \array_if_empty:NF \l_hobby_points_array {
+ \hobby_gen_path:
+ \hobby_use_path:
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\hobbyclearpath}
+% This is the user (well, sort of) command that generates a curve and uses it.
+% \begin{macrocode}
+\NewDocumentCommand \hobbyclearpath { } {
+ \hobby_clear_path:
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\hobby_use_path:}
+% This is the command that uses the curve.
+% As the curve data is stored globally, the same data can be reused by calling this function more than once without calling the generating function.
+% \begin{macrocode}
+\tl_new:N \l_tmpc_tl
+\cs_new:Nn \hobby_use_path: {
\bool_if:NT \l_hobby_disjoint_bool {
\array_get:NnN \l_hobby_points_array {0} \l_tmpa_tl
\exp_args:No \hobby_moveto:n {\l_tmpa_tl}
}
- \prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int} {
+ \int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int} {
\array_get:NnN \l_hobby_controla_array {##1} \l_tmpa_tl
\array_get:NnN \l_hobby_controlb_array {##1} \l_tmpb_tl
\array_get:NnN \l_hobby_points_array {##1} \l_tmpc_tl
- \exp_args:Nooo \hobby_curveto:nnn {\l_tmpa_tl} {\l_tmpb_tl} {\l_tmpc_tl}
-}
+ \array_get:NnN \l_hobby_actions_array {##1} \l_tmpd_tl
+ \int_compare:nNnTF {\tl_item:Nn \l_tmpd_tl {1}} = {\l_hobby_draw_int} {
+ \exp_args:Nooo \hobby_curveto:nnn {\l_tmpa_tl} {\l_tmpb_tl} {\l_tmpc_tl}
+ }{
+ \bool_gset_false:N \l_hobby_closed_bool
+ \exp_args:No \hobby_moveto:n {\l_tmpc_tl}
+ }
+ \tl_if_eq:xnTF {\tl_item:Nn \l_tmpd_tl {2}} {1} {
+ \bool_gset_false:N \l_hobby_closed_bool
+ \exp_args:No \hobby_moveto:n {\l_tmpc_tl}
+ }{}
+ }
\bool_if:NT \l_hobby_closed_bool {
\array_get:NnN \l_hobby_points_array {0} \l_tmpa_tl
\exp_args:No \hobby_close:n {\l_tmpa_tl}
}
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
+%
+% \begin{macro}{\hobby_save_path:n}
+% This command saves all the data needed to reinvoke the curve in a global token list that can be used to restore it afterwards.
+% \begin{macrocode}
+\cs_new:Nn \hobby_save_path:n {
+ \tl_clear:N \l_tmpa_tl
+ \tl_put_right:Nn \l_tmpa_tl {\int_gset:Nn \l_hobby_npoints_int}
+ \tl_put_right:Nx \l_tmpa_tl {{\int_use:N \l_hobby_npoints_int}}
+ \bool_if:NTF \l_hobby_disjoint_bool {
+ \tl_put_right:Nn \l_tmpa_tl {\bool_gset_true:N}
+ }{
+ \tl_put_right:Nn \l_tmpa_tl {\bool_gset_false:N}
+ }
+ \tl_put_right:Nn \l_tmpa_tl {\l_hobby_disjoint_bool}
+ \bool_if:NTF \l_hobby_closed_bool {
+ \tl_put_right:Nn \l_tmpa_tl {\bool_gset_true:N}
+ }{
+ \tl_put_right:Nn \l_tmpa_tl {\bool_gset_false:N}
+ }
+ \tl_put_right:Nn \l_tmpa_tl {\l_hobby_closed_bool}
+ \tl_put_right:Nn \l_tmpa_tl {\array_gclear:N \l_hobby_points_array}
+ \array_map_inline:Nn \l_hobby_points_array {
+ \tl_put_right:Nn \l_tmpa_tl {
+ \array_gput:Nnn \l_hobby_points_array {##1} {##2}
+ }
+ }
+ \tl_put_right:Nn \l_tmpa_tl {\array_gclear:N \l_hobby_actions_array}
+ \array_map_inline:Nn \l_hobby_actions_array {
+ \tl_put_right:Nn \l_tmpa_tl {
+ \array_gput:Nnn \l_hobby_actions_array {##1} {##2}
+ }
+ }
+ \tl_put_right:Nn \l_tmpa_tl {\array_gclear:N \l_hobby_controla_array}
+ \array_map_inline:Nn \l_hobby_controla_array {
+ \tl_put_right:Nn \l_tmpa_tl {
+ \array_gput:Nnn \l_hobby_controla_array {##1} {##2}
+ }
+ }
+ \tl_put_right:Nn \l_tmpa_tl {\array_gclear:N \l_hobby_controlb_array}
+ \array_map_inline:Nn \l_hobby_controlb_array {
+ \tl_put_right:Nn \l_tmpa_tl {
+ \array_gput:Nnn \l_hobby_controlb_array {##1} {##2}
+ }
+ }
+ \tl_gclear_new:c {g_hobby_#1_path}
+ \tl_gset_eq:cN {g_hobby_#1_path} \l_tmpa_tl
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\hobby_save_path_to_aux:n}
+% \begin{macrocode}
+\int_set:Nn \l_tmpa_int {\char_value_catcode:n {`@}}
+\char_set_catcode_letter:N @
+\cs_new:Npn \hobby_save_path_to_aux:n #1 {
+ \bool_if:nT {
+ \tl_if_exist_p:c {g_hobby_#1_path}
+ &&
+ ! \tl_if_exist_p:c {g_hobby_#1_path_saved}
+ }
+ {
+ \tl_clear:N \l_tmpa_tl
+ \tl_put_right:Nn \l_tmpa_tl {
+ \ExplSyntaxOn
+ \tl_gclear_new:c {g_hobby_#1_path}
+ \tl_gput_right:cn {g_hobby_#1_path}
+ }
+ \tl_put_right:Nx \l_tmpa_tl {
+ {\tl_to_str:c {g_hobby_#1_path}}
+ }
+ \tl_put_right:Nn \l_tmpa_tl {
+ \ExplSyntaxOff
+ }
+ \protected@write\@auxout{}{
+ \tl_to_str:N \l_tmpa_tl
+ }
+ \tl_new:c {g_hobby_#1_path_saved}
+ }
+}
+\char_set_catcode:nn {`@} {\l_tmpa_int}
+\cs_generate_variant:Nn \hobby_save_path_to_aux:n {x}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\hobby_clear_path:}
+% \begin{macrocode}
+\cs_new:Nn \hobby_clear_path:
+{
+\array_gclear:N \l_hobby_points_array
+\array_gclear:N \l_hobby_points_x_array
+\array_gclear:N \l_hobby_points_y_array
+\array_gclear:N \l_hobby_angles_array
+\array_gclear:N \l_hobby_actions_array
+\array_gclear:N \l_hobby_distances_array
+\array_gclear:N \l_hobby_tension_out_array
+\array_gclear:N \l_hobby_tension_in_array
+\array_gclear:N \l_hobby_excess_angle_array
+\array_gclear:N \l_hobby_matrix_a_array
+\array_gclear:N \l_hobby_matrix_b_array
+\array_gclear:N \l_hobby_matrix_c_array
+\array_gclear:N \l_hobby_matrix_d_array
+\array_gclear:N \l_hobby_vector_u_array
+\array_gclear:N \l_hobby_psi_array
+\array_gclear:N \l_hobby_theta_array
+\array_gclear:N \l_hobby_phi_array
+\array_gclear:N \l_hobby_sigma_array
+\array_gclear:N \l_hobby_rho_array
+\array_gclear:N \l_hobby_controla_array
+\array_gclear:N \l_hobby_controlb_array
+\bool_gset_false:N \l_hobby_closed_bool
+\bool_gset_false:N \l_hobby_disjoint_bool
+
+ \int_gset:Nn \l_hobby_npoints_int {-1}
+ \int_gset:Nn \l_hobby_draw_int {1}
+ \fp_gset_eq:NN \l_hobby_in_angle_fp \c_undefined_fp
+ \fp_gset_eq:NN \l_hobby_out_angle_fp \c_undefined_fp
+ \fp_gset_eq:NN \l_hobby_in_curl_fp \c_one_fp
+ \fp_gset_eq:NN \l_hobby_out_curl_fp \c_one_fp
+}
+% \end{macrocode}
+% \end{macro}
% \begin{macrocode}
\ExplSyntaxOff
% \end{macrocode}
@@ -1282,44 +1669,359 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
/pgf/hobby/.is family,
/pgf/hobby/.cd,
x/.code={\pgf@x=#1cm},
- y/.code={\pgf@y=#1cm},
+ y/.code={\pgf@y=#1cm}
}
% \end{macrocode}
-% \begin{function}{\hobby@curveto}
+%
+% \begin{macro}{\hobby@curveto}
% This is passed to the path-generation code to translate the path into a PGF path.
% \begin{macrocode}
\def\hobby@curveto#1#2#3{%
\pgfpathcurveto{\hobby@topgf{#1}}{\hobby@topgf{#2}}{\hobby@topgf{#3}}%
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby@moveto}
+% \begin{macro}{\hobby@moveto}
% This is passed to the path-generation code to translate the path into a PGF path.
% \begin{macrocode}
\def\hobby@moveto#1{%
\pgfpathmoveto{\hobby@topgf{#1}}%
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby@topgf}
+% \begin{macro}{\hobby@topgf}
% Translates a \LaTeX3 point to a PGF point.
% \begin{macrocode}
\def\hobby@topgf#1{%
\pgfqkeys{/pgf/hobby}{#1}%
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby@close}
+% \begin{macro}{\hobby@close}
% Closes a path.
% \begin{macrocode}
\def\hobby@close#1{%
\pgfpathclose
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
+%
+% Plot handlers
+%
+% \begin{macro}{\pgfplothanderhobby}
+% Basic plot handler; uses full algorithm but therefore expensive
+% \begin{macrocode}
+\def\pgfplothandlerhobby{%
+ \def\pgf@plotstreamstart{%
+ \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
+ \global\let\pgf@plotstreampoint=\pgf@plot@hobby@firstpt
+ \global\let\pgf@plotstreamspecial=\pgfutil@gobble
+ \gdef\pgf@plotstreamend{%
+ \ifhobby@externalise
+ \ifx\hobby@path@name\pgfutil@empty
+ \hobbygenusepath
+ \else
+ \hobbygenuseifnecpath{\hobby@path@name}%
+ \fi
+ \else
+ \hobbygenusepath
+ \fi
+ \ifx\hobby@path@name\pgfutil@empty
+ \else
+ \hobbysavepath{\hobby@path@name}%
+ \fi
+ \global\let\hobby@path@name=\pgfutil@empty
+ }%
+ \let\tikz@scan@point@options=\pgfutil@empty
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\pgfplothandlerclosedhobby}
+% Same as above but produces a closed curve
+% \begin{macrocode}
+\def\pgfplothandlerclosedhobby{%
+ \def\pgf@plotstreamstart{%
+ \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
+ \hobbysetparams{closed=true,disjoint=true}%
+ \global\let\pgf@plotstreampoint=\pgf@plot@hobby@firstpt
+ \global\let\pgf@plotstreamspecial=\pgfutil@gobble
+ \gdef\pgf@plotstreamend{%
+ \ifhobby@externalise
+ \ifx\hobby@path@name\pgfutil@empty
+ \hobbygenusepath
+ \else
+ \hobbygenuseifnecpath{\hobby@path@name}%
+ \fi
+ \else
+ \hobbygenusepath
+ \fi
+ \ifx\hobby@path@name\pgfutil@empty
+ \else
+ \hobbysavepath{\hobby@path@name}%
+ \fi
+ \global\let\hobby@path@name=\pgfutil@empty
+ }%
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\pgf@plot@hobby@firstpt}
+% First point, move or line as appropriate and then start the algorithm.
+% \begin{macrocode}
+\def\pgf@plot@hobby@firstpt#1{%
+ \pgf@plot@first@action{#1}%
+ \pgf@plot@hobby@handler{#1}%
+ \global\let\pgf@plotstreampoint=\pgf@plot@hobby@handler
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\pgf@plot@hobby@handler}
+% Add points to the array for the algorithm to work on.
+% \begin{macrocode}
+\def\pgf@plot@hobby@handler#1{%
+ #1%
+ \pgfmathsetmacro\hobby@x{\the\pgf@x/1cm}%
+ \pgfmathsetmacro\hobby@y{\the\pgf@y/1cm}%
+ \hobbyaddpoint{x = \hobby@x, y = \hobby@y}%
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\pgfplothandlerquickhobby}
+% Uses the ``quick'' algorithm.
+% \begin{macrocode}
+\def\pgfplothandlerquickhobby{%
+ \def\pgf@plotstreamstart{%
+ \global\let\hobby@quick@curveto=\pgfpathcurveto
+ \global\let\pgf@plotstreampoint=\pgf@plot@qhobby@firstpt
+ \global\let\pgf@plotstreamspecial=\pgfutil@gobble
+ \global\let\pgf@plotstreamend=\pgf@plot@qhobby@end
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\pgf@plot@qhobby@firstpt}
+% Carry out first action (move or line) and save point.
+% \begin{macrocode}
+\def\pgf@plot@qhobby@firstpt#1{%
+ #1%
+ \edef\hobby@temp{\noexpand\pgf@plot@first@action{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}\hobby@temp%
+ \xdef\hobby@qpoints{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ \gdef\hobby@qpointa{}%
+ \gdef\hobby@angle{}%
+ \global\let\pgf@plotstreampoint=\pgf@plot@qhobby@secondpt
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\pgf@plot@qhobby@secondpt}
+% Also need to save second point.
+% \begin{macrocode}
+\def\pgf@plot@qhobby@secondpt#1{%
+ #1%
+ \xdef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ \global\let\pgf@plotstreampoint=\pgf@plot@qhobby@handler
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\pgf@plot@qhobby@handler}
+% Wrapper around the computation macro that saves the variables globally.
+% \begin{macrocode}
+\def\pgf@plot@qhobby@handler#1{%
+ #1
+ \edef\hobby@temp{\noexpand\hobby@quick@compute{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}\hobby@temp
+ \global\let\hobby@qpointa=\hobby@qpointa
+ \global\let\hobby@qpoints=\hobby@qpoints
+ \global\let\hobby@angle=\hobby@angle
+% \end{macrocode}
+% Also need to save some data for the last point
+% \begin{macrocode}
+ \global\let\hobby@thetaone=\hobby@thetaone
+ \global\let\hobby@phitwo=\hobby@phitwo
+ \global\let\hobby@done=\hobby@done
+ \global\let\hobby@omegaone=\hobby@omegaone
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\pgf@plot@qhobby@end}
+% Wrapper around the finalisation step.
+% \begin{macrocode}
+\def\pgf@plot@qhobby@end{%
+ \hobby@quick@computeend
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\hobby@sf}
+% Working with points leads to computations out of range so we scale to get them into the computable arena.
+% \begin{macrocode}
+\pgfmathsetmacro\hobby@sf{10cm}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\hobby@quick@compute}
+% This is the macro that does all the work of computing the control points.
+% The argument is the current point, \Verb+\hobby@qpointa+ is the middle point, and \Verb+\hobby@qpoints+ is the first point.
+% \begin{macrocode}
+\def\hobby@quick@compute#1{%
+% \end{macrocode}
+% Save the current (second - counting from zero) point in \Verb+\pgf@xb+ and \Verb+\pgf@yb+.
+% \begin{macrocode}
+ #1%
+ \pgf@xb=\pgf@x
+ \pgf@yb=\pgf@y
+% \end{macrocode}
+% Save the previous (first) point in \Verb+\pgf@xa+ and \Verb+\pgf@ya+.
+% \begin{macrocode}
+ \hobby@qpointa
+ \pgf@xa=\pgf@x
+ \pgf@ya=\pgf@y
+% \end{macrocode}
+% Adjust so that \Verb+(\pgf@xb,\pgf@yb)+ is the vector from second to third.
+% Then compute and store the distance and angle of this vector.
+% We view this as the vector \emph{from} the midpoint and everything to do with that point has the suffix \Verb+one+.
+% Note that we divide by the scale factor here.
+% \begin{macrocode}
+ \advance\pgf@xb by -\pgf@xa
+ \advance\pgf@yb by -\pgf@ya
+ \pgfmathsetmacro\hobby@done{sqrt((\pgf@xb/\hobby@sf)^2 + (\pgf@yb/\hobby@sf)^2)}%
+ \pgfmathsetmacro\hobby@omegaone{rad(atan2(\pgf@xb,\pgf@yb))}%
+% \end{macrocode}
+% Now we do the same with the vector from the zeroth to the first point.
+% \begin{macrocode}
+ \hobby@qpoints
+ \advance\pgf@xa by -\pgf@x
+ \advance\pgf@ya by -\pgf@y
+ \pgfmathsetmacro\hobby@dzero{sqrt((\pgf@xa/\hobby@sf)^2 + (\pgf@ya/\hobby@sf)^2)}%
+ \pgfmathsetmacro\hobby@omegazero{rad(atan2(\pgf@xa,\pgf@ya))}%
+% \end{macrocode}
+% \Verb+\hobby@psi+ is the angle subtended at the midpoint.
+% We adjust to ensure that it is in the right range.
+% \begin{macrocode}
+ \pgfmathsetmacro\hobby@psi{\hobby@omegaone - \hobby@omegazero}%
+ \pgfmathsetmacro\hobby@psi{\hobby@psi > pi ? \hobby@psi - 2*pi : \hobby@psi}%
+ \pgfmathsetmacro\hobby@psi{\hobby@psi < -pi ? \hobby@psi + 2*pi : \hobby@psi}%
+% \end{macrocode}
+% Now we test to see if we're on the first run or not.
+% If the first, we have no incoming angle.
+% \begin{macrocode}
+ \ifx\hobby@angle\pgfutil@empty
+% \end{macrocode}
+% First.
+% \begin{macrocode}
+ \pgfmathsetmacro\hobby@thetaone{-\hobby@psi * \hobby@done%
+/(\hobby@done + \hobby@dzero)}%
+ \pgfmathsetmacro\hobby@thetazero{-\hobby@psi - \hobby@thetaone}%
+ \let\hobby@phione=\hobby@thetazero
+ \let\hobby@phitwo=\hobby@thetaone
+ \else
+% \end{macrocode}
+% Second or later.
+% \begin{macrocode}
+ \let\hobby@thetazero=\hobby@angle
+ \pgfmathsetmacro\hobby@thetaone{%
+ -(2 * \hobby@psi + \hobby@thetazero) * \hobby@done%
+ / (2 * \hobby@done + \hobby@dzero)}%
+ \pgfmathsetmacro\hobby@phione{-\hobby@psi - \hobby@thetaone}%
+ \let\hobby@phitwo=\hobby@thetaone
+ \fi
+% \end{macrocode}
+% Save the outgoing angle.
+% \begin{macrocode}
+ \let\hobby@angle=\hobby@thetaone
+% \end{macrocode}
+% Compute the control points from the angles.
+% \begin{macrocode}
+ \hobby@quick@ctrlpts{\hobby@thetazero}{\hobby@phione}{\hobby@qpoints}{\hobby@qpointa}{\hobby@dzero}{\hobby@omegazero}%
+% \end{macrocode}
+% Now call the call-back function
+% \begin{macrocode}
+ \edef\hobby@temp{\noexpand\hobby@quick@curveto{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}{\noexpand\pgfqpoint{\the\pgf@xb}{\the\pgf@yb}}{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}%
+\hobby@temp
+% \end{macrocode}
+% Cycle the points round for the next iteration.
+% \begin{macrocode}
+ \global\let\hobby@qpoints=\hobby@qpointa
+ #1
+ \xdef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+% \end{macrocode}
+% Save needed values in global macros
+% \begin{macrocode}
+ \global\let\hobby@angle=\hobby@angle
+ \global\let\hobby@phitwo=\hobby@phitwo
+ \global\let\hobby@thetaone=\hobby@thetaone
+\global\let\hobby@done=\hobby@done
+\global\let\hobby@omegaone=\hobby@omegaone
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\hobby@wuick@computeend}
+% This is the additional code for the final run.
+% \begin{macrocode}
+\def\hobby@quick@computeend{%
+% \end{macrocode}
+% Compute the control points for the second part of the curve and add that to the path.
+% \begin{macrocode}
+ \hobby@quick@ctrlpts{\hobby@thetaone}{\hobby@phitwo}{\hobby@qpoints}{\hobby@qpointa}{\hobby@done}{\hobby@omegaone}%
+% \end{macrocode}
+% Now call the call-back function
+% \begin{macrocode}
+ \edef\hobby@temp{\noexpand\hobby@quick@curveto{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}{\noexpand\pgfqpoint{\the\pgf@xb}{\the\pgf@yb}}{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}%
+\hobby@temp
+}%
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\hobby@quick@ctrlpts}
+% Compute the control points from the angles and points given.
+% \begin{macrocode}
+\def\hobby@quick@ctrlpts#1#2#3#4#5#6{%
+ \pgfmathsetmacro\hobby@alpha{%
+ sqrt(2) * (sin(#1 r) - 1/16 * sin(#2 r))%
+* (sin(#2 r) - 1/16 * sin(#1 r))%
+ * (cos(#1 r) - cos(#2 r))}%
+ \pgfmathsetmacro\hobby@rho{%
+ (2 + \hobby@alpha)/(1 + (1 - (3 - sqrt(5))/2)%
+ * cos(#1 r) + (3 - sqrt(5))/2 * cos(#2 r))}%
+ \pgfmathsetmacro\hobby@sigma{%
+ (2 - \hobby@alpha)/(1 + (1 - (3 - sqrt(5))/2)%
+ * cos(#2 r) + (3 - sqrt(5))/2 * cos(#1 r))}%
+ #3%
+ \pgf@xa=\pgf@x
+ \pgf@ya=\pgf@y
+ \pgfmathsetlength\pgf@xa{%
+ \pgf@xa + #5 * \hobby@rho%
+ * cos((#1 + #6) r)/3*\hobby@sf}%
+ \pgfmathsetlength\pgf@ya{%
+ \pgf@ya + #5 * \hobby@rho%
+ * sin((#1 + #6) r)/3*\hobby@sf}%
+ #4%
+ \pgf@xb=\pgf@x
+ \pgf@yb=\pgf@y
+ \pgfmathsetlength\pgf@xb{%
+ \pgf@xb - #5 * \hobby@sigma%
+ * cos((-#2 + #6) r)/3*\hobby@sf}%
+ \pgfmathsetlength\pgf@yb{%
+ \pgf@yb - #5 * \hobby@sigma%
+ * sin((-#2 + #6) r)/3*\hobby@sf}%
+ #4%
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
% \iffalse
%</pgflibrary>
% \fi
@@ -1332,136 +2034,236 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
%
% \begin{macrocode}
\usepgflibrary{hobby}
-\let\hobby@opts=\pgfutil@empty
+\let\hobby@this@opts=\pgfutil@empty
+\let\hobby@next@opts=\pgfutil@empty
+\let\hobby@action=\pgfutil@empty
+\let\hobby@path@name=\pgfutil@empty
+\newif\ifhobby@externalise
% \end{macrocode}
%
% We set various TikZ keys.
% These include the \Verb+to path+ constructor and all the various parameters that will eventually get passed to the path-generation code.
% \begin{macrocode}
+\def\hobby@point@options{}%
\tikzset{
curve through/.style={
to path={
\pgfextra{
- \expandafter\curvethrough\expandafter[\hobby@opts]{%
+ \expandafter\curvethrough\expandafter[\hobby@next@opts]{%
(\tikztostart) .. #1 .. (\tikztotarget)%
}
}
}
},
- tension in/.code = {},
- tension out/.code = {},
- tension/.code = {},
- excess angle/.code = {},
- closed/.code = {%
- \expandafter\def\expandafter\hobby@opts\expandafter{\hobby@opts%
- closed=#1,disjoint=#1}%
+ tension in/.code = {%
+ \expandafter\gdef\expandafter\hobby@point@options\expandafter%
+ {\hobby@point@options,tension in=#1}%
+ },
+ tension out/.code = {%
+ \expandafter\gdef\expandafter\hobby@point@options\expandafter%
+ {\hobby@point@options,tension out=#1}%
+ },
+ tension/.code = {%
+ \expandafter\gdef\expandafter\hobby@point@options\expandafter%
+ {\hobby@point@options,tension=#1}%
+ },
+ excess angle/.code = {%
+ \expandafter\gdef\expandafter\hobby@point@options\expandafter%
+ {\hobby@point@options,excess angle=#1}%
+ },
+ break/.code = {%
+ \expandafter\gdef\expandafter\hobby@point@options\expandafter%
+ {\hobby@point@options,break=#1}%
+ },
+ blank/.code = {%
+ \expandafter\gdef\expandafter\hobby@point@options\expandafter%
+ {\hobby@point@options,blank=#1}%
+ },
+ designated Hobby path/.initial={next},
+ clear next Hobby path options/.code={%
+ \gdef\hobby@next@opts{}%
+ },
+ clear this Hobby path options/.code={%
+ \gdef\hobby@this@opts{}%
+ },
+ clear Hobby path options/.style={%
+ clear \pgfkeysvalueof{/tikz/designated Hobby path} Hobby path options
+ },
+ add option to this Hobby path/.code={%
+ \expandafter\gdef\expandafter\hobby@this@opts\expandafter{\hobby@this@opts#1,}%
+ },
+ add option to next Hobby path/.code={%
+ \expandafter\gdef\expandafter\hobby@next@opts\expandafter{\hobby@next@opts#1,}%
+ },
+ add option to Hobby path/.style={%
+ add option to \pgfkeysvalueof{/tikz/designated Hobby path} Hobby path={#1}%
+ },
+ closed/.style = {%
+ add option to Hobby path={closed=#1,disjoint=#1}%
+ },
+ invert blank/.style = {%
+ add option to Hobby path={invert blank=#1}%
},
closed/.default = true,
+ blank/.default = true,
+ break/.default = true,
+ invert blank/.default = true,
in angle/.code = {%
\pgfmathparse{#1*pi/180}%
- \edef\@temp{ in angle=\pgfmathresult,}%
- \expandafter\expandafter\expandafter%
- \def%
- \expandafter\expandafter\expandafter%
- \hobby@opts%
- \expandafter\expandafter\expandafter%
- {\expandafter\hobby@opts\@temp}%
+ \edef\@temp{in angle=\pgfmathresult,}%
+ \pgfkeysalso{add option to Hobby path/.expand once=\@temp}%
},
out angle/.code = {%
\pgfmathparse{#1*pi/180}%
- \edef\@temp{ out angle=\pgfmathresult,}%
- \expandafter\expandafter\expandafter%
- \def%
- \expandafter\expandafter\expandafter%
- \hobby@opts%
- \expandafter\expandafter\expandafter%
- {\expandafter\hobby@opts\@temp}%
+ \edef\@temp{out angle=\pgfmathresult,}%
+ \pgfkeysalso{add option to Hobby path/.expand once=\@temp}%
},
- in curl/.code = {%
- \expandafter\def\expandafter\hobby@opts\expandafter{\hobby@opts in curl=#1,}%
+ in curl/.style = {%
+ add option to Hobby path={in curl=#1}%
},
out curl/.code = {%
- \expandafter\def\expandafter\hobby@opts\expandafter{\hobby@opts out curl=#1,}%
+ add option to Hobby path={out curl=#1}%
},
use Hobby shortcut/.code={%
- \let\tikz@curveto@auto=\hobby@curveto@auto
- }
+ \let\tikz@curveto@auto=\hobby@curveto@override
+ \global\let\hobby@curveto@delegate=\hobby@curveto@auto
+ },
+ use quick Hobby shortcut/.code={%
+ \let\tikz@curveto@auto=\hobby@curveto@override
+ \global\let\hobby@curveto@delegate=\hobby@qcurveto@auto
+ },
+ use previous Hobby path/.code={%
+ \pgfextra{\hobbyusepath{#1}}
+ },
+ use previous Hobby path/.default={},%
+ save Hobby path/.code={%
+ \xdef\hobby@path@name{#1}%
+ },
+ restore Hobby path/.code={%
+ \pgfextra{%
+ \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
+ \hobbyrestorepath{#1}}
+ },
+ restore and use Hobby path/.code 2 args={%
+ \pgfextra{%
+ \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
+ \hobbyrestorepath{#1}%
+ \hobbyusepath{#2}%
+ }
+ },
+ show Hobby path/.code={%
+ \pgfextra{\hobbyshowpath{#1}}
+ },
+ Hobby action/.code={%
+ \expandafter\gdef\expandafter\hobby@action\expandafter{\hobby@action#1}%
+ },
+ Hobby finish/.style={%
+ Hobby action=\hobby@finish%
+ },
+ Hobby externalise/.is if=hobby@externalise,
+ Hobby externalize/.is if=hobby@externalise
}
% \end{macrocode}
-% \begin{function}{\curvethrough}
+% \begin{macro}{\curvethrough}
% This is the parent command.
% We initialise the path-generation code, set any parameters, and then hand over control to the point processing macro.
% \begin{macrocode}
\newcommand\curvethrough[2][]{%
\hobbyinit\hobby@moveto\hobby@curveto\hobby@close
\hobbysetparams{#1}%
- \hobby@processpts{#2}%
+ \tikzset{designated Hobby path=this}%
+ \global\let\hobby@this@opts=\pgfutil@empty
+ \global\let\hobby@next@opts=\pgfutil@empty
+ \let\tikz@scan@point@options=\pgfutil@empty
+ \def\hobby@point@options{}%
+ \tikz@scan@one@point\hobby@processpt #2 \relax%
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby@processpts}
-% This processes a list of points in the format \Verb+(0,0) .. (1,1)+.
+% \begin{macro}{\hobby@processpt}
+% This processes a list of points in the format \Verb+(0,0) [..] (1,1)+.
% Each point is scanned by TikZ and then added to the stack to be built into the path.
% If there are any remaining points, we call ourself again with them.
% Otherwise, we hand over control to the path-generation code.
% \begin{macrocode}
-\newcommand\hobby@processpts[1]{%
- \pgfutil@in@{..}{#1}%
- \ifpgfutil@in@%
- \hobby@getonepoint #1 \relax
- \let\hobby@next=\hobby@processpts
- \else
- \def\hobby@pt{#1}%
- \def\hobby@rest{}%
- \let\hobby@next=\hobbygenpath
- \fi
- \let\tikz@scan@point@options=\pgfutil@empty
- \expandafter\tikz@scan@one@point\expandafter\pgfutil@firstofone\hobby@pt\relax
+\newcommand\hobby@processpt[1]{%
+ #1%
\pgfmathsetmacro\hobby@x{\the\pgf@x/1cm}%
\pgfmathsetmacro\hobby@y{\the\pgf@y/1cm}%
- \expandafter\hobbyaddpoint\expandafter{\tikz@scan@point@options,%
+ \expandafter\hobbyaddpoint\expandafter{\hobby@point@options,%
x = \hobby@x, y = \hobby@y}%
- \expandafter\hobby@next\expandafter{\hobby@rest}%
-}
+ \def\hobby@point@options{}%
+ \let\tikz@scan@point@options=\pgfutil@empty
+ \pgfutil@ifnextchar\relax{%
+ \expandafter\hobbysetparams\expandafter{\hobby@this@opts}%
+ \ifhobby@externalise
+ \ifx\hobby@path@name\pgfutil@empty
+ \hobbygenusepath
+ \else
+ \hobbygenuseifnecpath{\hobby@path@name}%
+ \fi
+ \else
+ \hobbygenusepath
+ \fi
+ \ifx\hobby@path@name\pgfutil@empty
+ \else
+ \hobbysavepath{\hobby@path@name}%
+ \fi
+ \global\let\hobby@path@name=\pgfutil@empty
+ }{%
+ \pgfutil@ifnextchar.{%
+ \hobby@swallowdots}{%
+ \tikz@scan@one@point\hobby@processpt}}}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby@onepoint}
-% This strips off the next point.
+% \begin{macro}{\hobby@swallowdots}
+% Remove dots from the input stream.
% \begin{macrocode}
-\def\hobby@getonepoint#1..#2\relax{%
- \def\hobby@pt{#1}%
- \def\hobby@rest{#2}%
-}
+\def\hobby@swallowdots.{%
+ \pgfutil@ifnextchar.{%
+ \hobby@swallowdots}{%
+ \tikz@scan@one@point\hobby@processpt}}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
% There is a ``spare hook'' in the TikZ path processing code.
% If TikZ encounters a path of the form \Verb+(0,0) .. (1,1)+ then it calls a macro \Verb+\tikz@curveto@auto+.
% However, that macro is not defined in the TikZ code.
% The following code provides a suitable definition.
% To play nice, we don't install it by default but define a key (defined above) that installs it.
-% \begin{function}{\hobby@curveto@auto}
+%
+% \begin{macro}{\hobby@curveto@override}
+% \begin{macrocode}
+\def\hobby@curveto@override{%
+ \hobby@curveto@delegate}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\hobby@curveto@auto}
% When we're called by TikZ, we initialise the path generation code and start adding points.
-% We want to be sure that we're only called once so we don't had control back to TikZ but use our own parser to process the rest of the curve until we reach a syntax that we don't understand.
+% To ensure that the generation code is called, we add a lot of hooks to lots of TikZ commands.
% \begin{macrocode}
\def\hobby@curveto@auto{%
- \hobbyinit\pgfutil@gobble\hobby@curveto\hobby@close
+ \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
\pgfmathsetmacro\hobby@x{\the\tikz@lastx/1cm}%
\pgfmathsetmacro\hobby@y{\the\tikz@lasty/1cm}%
- \pgfutil@ifundefined{tikz@scan@point@options}{%
- \hobbyaddpoint{x = \hobby@x, y = \hobby@y}%
- }{%
- \expandafter\hobbyaddpoint\expandafter{\tikz@scan@point@options,%
+ \expandafter\hobbysetparams\expandafter{\hobby@next@opts}%
+ \expandafter\hobbyaddpoint\expandafter{\hobby@point@options,%
x = \hobby@x, y = \hobby@y}%
- }%
+ \hobby@init@tikz@commands
+ \tikzset{designated Hobby path=this}%
\let\tikz@scan@point@options=\pgfutil@empty
+ \global\let\hobby@action=\pgfutil@empty
+ \global\let\hobby@this@opts=\pgfutil@empty
+ \global\let\hobby@next@opts=\pgfutil@empty
+ \global\let\hobby@point@options=\pgfutil@empty
\tikz@scan@one@point\hobby@addfromtikz}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby@addfromtikz}
+% \begin{macro}{\hobby@addfromtikz}
% This adds our current point to the stack.
% \begin{macrocode}
\def\hobby@addfromtikz#1{%
@@ -1469,77 +2271,116 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
\tikz@make@last@position{#1}%
\pgfmathsetmacro\hobby@x{\the\pgf@x/1cm}%
\pgfmathsetmacro\hobby@y{\the\pgf@y/1cm}%
- \expandafter\hobbyaddpoint\expandafter{\tikz@scan@point@options,%
+ \expandafter\hobbysetparams\expandafter{\hobby@this@opts}%
+ \expandafter\hobbyaddpoint\expandafter{\hobby@point@options,%
x = \hobby@x, y = \hobby@y}%
- \hobby@donext}
+ \hobby@action
+ \global\let\hobby@this@opts=\pgfutil@empty
+ \global\let\hobby@action=\pgfutil@empty
+ \global\let\hobby@point@options=\pgfutil@empty
+ \tikz@scan@next@command%
+}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby@donext}
-% Now we look to see if the next character is a dot.
-% If not, we're done so generate the path.
+% \begin{macro}{\hobby@init@tikz@commands}
% \begin{macrocode}
-\def\hobby@donext{%
- \pgfutil@ifnextchar.%
- {\hobby@curveto@check}%
- {\hobby@finish@auto}}%
+\def\hobby@init@tikz@commands{%
+ \hobby@init@tikz@modcmd\tikz@movetoabs
+ \hobby@init@tikz@modcmd\tikz@movetorel
+ \hobby@init@tikz@modcmd\tikz@lineto
+ \hobby@init@tikz@modcmd\tikz@rect
+ \hobby@init@tikz@modcmd\tikz@cchar
+ \hobby@init@tikz@modcmd\tikz@finish
+ \hobby@init@tikz@modcmd\tikz@arcA
+ \hobby@init@tikz@modcmd\tikz@e@char
+ \hobby@init@tikz@modcmd\tikz@g@char
+ \hobby@init@tikz@modcmd\tikz@schar
+ \hobby@init@tikz@modcmd\tikz@vh@lineto
+ \hobby@init@tikz@modcmd\tikz@pchar
+ \hobby@init@tikz@modcmd\tikz@to
+ \hobby@init@tikz@modcmd\pgf@stop
+ \hobby@init@tikz@modcmd\tikz@decoration
+ \global\let\hobby@curveto@delegate=\hobby@midcurveto@auto
+}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby@curveto@check}
-% It was a dot, so look at what comes after.
-% It might be \Verb+.. c+ in which case we might be done.
-% If not, we assume we're still adding points.
+% \begin{macro}{\hobby@restore@tikz@commands}
% \begin{macrocode}
-\def\hobby@curveto@check..{%
- \pgfutil@ifnextchar c%
- {\hobby@maybefinish@auto}%
- {\hobby@curveto@continue}}%
+\def\hobby@restore@tikz@commands{%
+ \hobby@restore@tikz@modcmd\tikz@movetoabs
+ \hobby@restore@tikz@modcmd\tikz@movetorel
+ \hobby@restore@tikz@modcmd\tikz@lineto
+ \hobby@restore@tikz@modcmd\tikz@rect
+ \hobby@restore@tikz@modcmd\tikz@cchar
+ \hobby@restore@tikz@modcmd\tikz@finish
+ \hobby@restore@tikz@modcmd\tikz@arcA
+ \hobby@restore@tikz@modcmd\tikz@e@char
+ \hobby@restore@tikz@modcmd\tikz@g@char
+ \hobby@restore@tikz@modcmd\tikz@schar
+ \hobby@restore@tikz@modcmd\tikz@vh@lineto
+ \hobby@restore@tikz@modcmd\tikz@pchar
+ \hobby@restore@tikz@modcmd\tikz@to
+ \hobby@restore@tikz@modcmd\pgf@stop
+ \hobby@restore@tikz@modcmd\tikz@decoration
+ \global\let\hobby@curveto@delegate=\hobby@curveto@auto
+}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby@maybefinish@auto}
-% We got \Verb+.. c+.
-% It might be \Verb+.. controls+ in which case we're done.
-% It might be \Verb+.. cycle+ in which case we have a closed path, after which we're done.
+% \begin{macro}{\hobby@init@tikz@modcmd}
% \begin{macrocode}
-\def\hobby@maybefinish@auto c{%
- \pgfutil@ifnextchar o%
- {\hobby@finish@auto .. c}%
- {\hobby@closeandfinish@auto}}
+\def\hobby@init@tikz@modcmd#1{%
+ \expandafter\global\expandafter\let\csname hobby@orig@\string#1\endcsname=#1%
+ \gdef#1{\hobby@finish#1}%
+}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby@closeandfinish@auto}
-% We got \Verb+.. cycle+ so eat it, flag the path as closed, and generate it.
+% \begin{macro}{\hobby@restore@tikz@modcmd}
% \begin{macrocode}
-\def\hobby@closeandfinish@auto ycle{%
- \hobbysetparams{closed=true,disjoint=true}%
- \hobby@finish@auto%
+\def\hobby@restore@tikz@modcmd#1{%
+ \expandafter\global\expandafter\let\expandafter#1\csname hobby@orig@\string#1\endcsname%
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby@curveto@continue}
-% Scan next coordinate and repeat the cycle.
+% \begin{macro}{\hobby@midcurveto@auto}
% \begin{macrocode}
-\def\hobby@curveto@continue{%
+\def\hobby@midcurveto@auto{%
\let\tikz@scan@point@options=\pgfutil@empty
- \tikz@scan@one@point\hobby@addfromtikz}
+ \global\let\hobby@action=\pgfutil@empty
+ \global\let\hobby@this@opts=\pgfutil@empty
+ \global\let\hobby@point@options=\pgfutil@empty
+ \tikz@scan@one@point\hobby@addfromtikz%
+}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby@finish@auto}
-% Generate the path and then hand control back to TikZ.
+% \begin{macro}{\hobby@finish}
% \begin{macrocode}
-\def\hobby@finish@auto{%
- \hobbygenpath
- \tikz@scan@next@command%
+\def\hobby@finish{%
+ \ifhobby@externalise
+ \ifx\hobby@path@name\pgfutil@empty
+ \hobbygenusepath
+ \else
+ \hobbygenuseifnecpath{\hobby@path@name}%
+ \fi
+ \else
+ \hobbygenusepath
+ \fi
+ \ifx\hobby@path@name\pgfutil@empty
+ \else
+ \hobbysavepath{\hobby@path@name}%
+ \fi
+ \global\let\hobby@path@name=\pgfutil@empty
+ \hobby@restore@tikz@commands
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{quick curve through}
+% \begin{macro}{quick curve through}
% The \Verb+quick curve through+ is a \Verb+to path+ which does the ``quick'' version of Hobby's algorithm.
% The syntax is as with the \Verb+curve through+: to pass the midpoints as the argument to the style.
% We need to pass three points to the auxiliary macro.
@@ -1555,7 +2396,10 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
% \end{macrocode}
% Scan the starting point and store the coordinates in \Verb+\hobby@qpointa+
% \begin{macrocode}
+ \let\hobby@next@qbreak=\relax
+ \let\hobby@next@qblank=\relax
\tikz@scan@one@point\pgfutil@firstofone(\tikztostart)%
+ \tikz@make@last@position{\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
\edef\hobby@qpoints{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
% \end{macrocode}
% Blank the path and auxiliary macros.
@@ -1563,6 +2407,7 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
\def\hobby@qpointa{}%
\def\hobby@quick@path{}%
\def\hobby@angle{}%
+ \let\hobby@quick@curveto=\hobby@quick@makepath
% \end{macrocode}
% Now start parsing the rest of the coordinates.
% \begin{macrocode}
@@ -1573,24 +2418,73 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
% \begin{macrocode}
\hobby@quick@path
}
- }
+ },
+ quick hobby/blank curve/.is choice,
+ quick hobby/blank curve/true/.code={%
+ \gdef\hobby@next@qblank{%
+ \qhobby@blanktrue
+ \global\let\hobby@next@qblank=\relax
+ }%
+ },
+ quick hobby/blank curve/false/.code={%
+ \gdef\hobby@next@qblank{%
+ \qhobby@blankfalse
+ \global\let\hobby@next@qblank=\relax
+ }%
+ },
+ quick hobby/blank curve/once/.code={%
+ \gdef\hobby@next@qblank{%
+ \qhobby@blanktrue
+ \gdef\hobby@next@qblank{%
+ \qhobby@blankfalse
+ \global\let\hobby@next@qblank=\relax
+ }%
+ }%
+ },
+ quick hobby/blank curve/.default=true,
+ quick hobby/break curve/.is choice,
+ quick hobby/break curve/true/.code={%
+ \gdef\hobby@next@qbreak{%
+ \qhobby@breaktrue
+ \global\let\hobby@next@qbreak=\relax
+ }%
+ },
+ quick hobby/break curve/false/.code={%
+ \gdef\hobby@next@qbreak{%
+ \qhobby@breakfalse
+ \global\let\hobby@next@qbreak=\relax
+ }%
+ },
+ quick hobby/break curve/once/.code={%
+ \gdef\hobby@next@qbreak{%
+ \qhobby@breaktrue
+ \gdef\hobby@next@qbreak{%
+ \qhobby@breakfalse
+ \global\let\hobby@next@qbreak=\relax
+ }%
+ }%
+ },
+ quick hobby/break curve/.default=true,
}
+\newif\ifqhobby@break
+\newif\ifqhobby@blank
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby@sf}
-% Working with points leads to computations out of range so we scale to get them into the computable arena.
+% Add plot handlers
% \begin{macrocode}
-\pgfmathsetmacro\hobby@sf{10cm}
+\tikzoption{hobby}[]{\let\tikz@plot@handler=\pgfplothandlerhobby}
+\tikzoption{quick hobby}[]{\let\tikz@plot@handler=\pgfplothandlerquickhobby}
+\tikzoption{closed hobby}[]{\let\tikz@plot@handler=\pgfplothandlerclosedhobby}
% \end{macrocode}
-% \end{function}
%
-% \begin{function}{\hobby@quickfirst}
+% \begin{macro}{\hobby@quickfirst}
% The first time around we just set the next point.
% \begin{macrocode}
\def\hobby@quickfirst#1{%
#1%
- \edef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ \xdef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ \tikz@make@last@position{\hobby@qpointa}%
% \end{macrocode}
% Now a check to ensure that we have more points.
% \begin{macrocode}
@@ -1600,180 +2494,230 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
% That's not good.
% Bail-out.
% \begin{macrocode}
- \edef\hobby@quick@path{ -- (\the\pgf@x,\the\pgf@y)}%
+ \xdef\hobby@quick@path{ -- (\the\pgf@x,\the\pgf@y)}%
}{%
% \end{macrocode}
% Okay, have more points.
% Phew.
% Call the next round.
+% If we have dots, swallow them.
+% \begin{macrocode}
+ \pgfutil@ifnextchar.{%
+ \hobby@qswallowdots}{%
+ \tikz@scan@one@point\hobby@quick}}}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\hobby@qswallowdots}
+% Remove dots from the input stream.
% \begin{macrocode}
+\def\hobby@qswallowdots.{%
+ \pgfutil@ifnextchar.{%
+ \hobby@qswallowdots}{%
\tikz@scan@one@point\hobby@quick}}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\hobby@quick}
-% This is the macro that does all the work of computing the control points.
+% \begin{macro}{\hobby@quick}
+% This is our wrapper function that handles the loop.
% \begin{macrocode}
\def\hobby@quick#1{%
+ \hobby@quick@compute{#1}%
+ \tikz@make@last@position{\hobby@qpointa}%
+ \pgfutil@ifnextchar\relax{%
% \end{macrocode}
-% Save the current (second - counting from zero) point in \Verb+\pgf@xb+ and \Verb+\pgf@yb+.
+% End of loop
% \begin{macrocode}
- #1%
- \pgf@xb=\pgf@x
- \pgf@yb=\pgf@y
+ \hobby@quick@computeend%
+ }{%
% \end{macrocode}
-% Save the previous (first) point in \Verb+\pgf@xa+ and \Verb+\pgf@ya+.
+% More to go, scan in the next coordinate and off we go again.
% \begin{macrocode}
- \hobby@qpointa
- \pgf@xa=\pgf@x
- \pgf@ya=\pgf@y
+ \pgfutil@ifnextchar.{%
+ \hobby@qswallowdots}{%
+ \tikz@scan@one@point\hobby@quick}}}
% \end{macrocode}
-% Adjust so that \Verb+(\pgf@xb,\pgf@yb)+ is the vector from second to third.
-% Then compute and store the distance and angle of this vector.
-% We view this as the vector \emph{from} the midpoint and everything to do with that point has the suffix \Verb+one+.
-% Note that we divide by the scale factor here.
+% \end{macro}
+%
+% \begin{macro}{\hobby@quick@makepath}
+% Path constructor for \Verb+to path+ use.
% \begin{macrocode}
- \advance\pgf@xb by -\pgf@xa
- \advance\pgf@yb by -\pgf@ya
- \pgfmathsetmacro\hobby@done{sqrt((\pgf@xb/\hobby@sf)^2 + (\pgf@yb/\hobby@sf)^2)}%
- \pgfmathsetmacro\hobby@omegaone{rad(atan2(\pgf@xb,\pgf@yb))}%
+\def\hobby@quick@makepath#1#2#3{%
+ #1%
+ \pgf@xa=\pgf@x\relax
+ \pgf@ya=\pgf@y\relax
+ #2%
+ \pgf@xb=\pgf@x\relax
+ \pgf@yb=\pgf@y\relax
+ #3%
+ \ifqhobby@blank
+ \xdef\hobby@quick@path{\hobby@quick@path (\the\pgf@x,\the\pgf@y)}%
+ \else
+ \xdef\hobby@quick@path{\hobby@quick@path .. controls%
+ (\the\pgf@xa,\the\pgf@ya) and (\the\pgf@xb,\the\pgf@yb) .. (\the\pgf@x,\the\pgf@y) }%
+ \fi
+ \ifqhobby@break
+ \xdef\hobby@quick@path{\hobby@quick@path +(0,0)}%
+ \fi
+ \hobby@next@qbreak
+ \hobby@next@qblank
+}
% \end{macrocode}
-% Now we do the same with the vector from the zeroth to the first point.
+% \end{macro}
+%
+% \begin{macro}{\hobby@qcurveto@auto}
+% Uses the ``quick'' method for the shortcut syntax.
% \begin{macrocode}
- \hobby@qpoints
- \advance\pgf@xa by -\pgf@x
- \advance\pgf@ya by -\pgf@y
- \pgfmathsetmacro\hobby@dzero{sqrt((\pgf@xa/\hobby@sf)^2 + (\pgf@ya/\hobby@sf)^2)}%
- \pgfmathsetmacro\hobby@omegazero{rad(atan2(\pgf@xa,\pgf@ya))}%
+\def\hobby@qcurveto@auto{%
+ \global\let\hobby@next@qbreak=\relax
+ \global\let\hobby@next@qblank=\relax
+ \xdef\hobby@qpoints{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
+ \gdef\hobby@qpointa{}%
+ \gdef\hobby@quick@path{}%
+ \gdef\hobby@angle{}%
+ \global\let\hobby@quick@curveto=\hobby@quick@makepathauto
+ \hobby@qinit@tikz@commands
+ \let\tikz@scan@point@options=\pgfutil@empty
+ \global\let\hobby@action=\pgfutil@empty
+ \global\let\hobby@point@options=\pgfutil@empty
+ \tikz@scan@one@point\hobby@qfirst@auto}
% \end{macrocode}
-% \Verb+\hobby@psi+ is the angle subtended at the midpoint.
-% We adjust to ensure that it is in the right range.
+% \end{macro}
+%
+% \begin{macro}{\hobby@qmidcurveto@auto}
% \begin{macrocode}
- \pgfmathsetmacro\hobby@psi{\hobby@omegaone - \hobby@omegazero}%
- \pgfmathsetmacro\hobby@psi{\hobby@psi > pi ? \hobby@psi - 2*pi : \hobby@psi}%
- \pgfmathsetmacro\hobby@psi{\hobby@psi < -pi ? \hobby@psi + 2*pi : \hobby@psi}%
+\def\hobby@qmidcurveto@auto{%
+ \let\tikz@scan@point@options=\pgfutil@empty
+ \global\let\hobby@action=\pgfutil@empty
+ \global\let\hobby@point@options=\pgfutil@empty
+ \tikz@scan@one@point\hobby@qaddfromtikz}
% \end{macrocode}
-% Now we test to see if we're on the first run or not.
-% If the first, we have no incoming angle.
+% \end{macro}
+%
+% \begin{macro}{\hobby@qfirst@auto}
% \begin{macrocode}
- \ifx\hobby@angle\pgfutil@empty
+\def\hobby@qfirst@auto#1{%
+ #1%
+ \xdef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ \tikz@make@last@position{\hobby@qpointa}%
+ \tikz@scan@next@command%
+}
% \end{macrocode}
-% First.
+% \end{macro}
+%
+% \begin{macro}{\hobby@quick@makepathauto}
+% Path constructor for shortcut method to use.
% \begin{macrocode}
- \pgfmathsetmacro\hobby@thetaone{-\hobby@psi * \hobby@done%
-/(\hobby@done + \hobby@dzero)}%
- \pgfmathsetmacro\hobby@thetazero{-\hobby@psi - \hobby@thetaone}%
- \let\hobby@phione=\hobby@thetazero
- \let\hobby@phitwo=\hobby@thetaone
+\def\hobby@quick@makepathauto#1#2#3{%
+ #1%
+ \pgf@xa=\pgf@x\relax
+ \pgf@ya=\pgf@y\relax
+ #2%
+ \pgf@xb=\pgf@x\relax
+ \pgf@yb=\pgf@y\relax
+ #3%
+ \ifqhobby@blank
+ \edef\hobby@temp{%
+ \noexpand\pgfpathmoveto{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ }%
+ \hobby@temp
\else
-% \end{macrocode}
-% Second or later.
-% \begin{macrocode}
- \let\hobby@thetazero=\hobby@angle
- \pgfmathsetmacro\hobby@thetaone{%
- -(2 * \hobby@psi + \hobby@thetazero) * \hobby@done%
- / (2 * \hobby@done + \hobby@dzero)}%
- \pgfmathsetmacro\hobby@phione{-\hobby@psi - \hobby@thetaone}%
- \let\hobby@phitwo=\hobby@thetaone
+ \edef\hobby@temp{%
+ \noexpand\pgfpathcurveto{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}%
+ {\noexpand\pgfqpoint{\the\pgf@xb}{\the\pgf@yb}}%
+ {\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ }%
+ \hobby@temp
\fi
+ \ifqhobby@break
+ #3%
+ \edef\hobby@temp{%
+ \noexpand\pgfpathmoveto{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ }%
+ \hobby@temp
+ \fi
+ \hobby@next@qbreak
+ \hobby@next@qblank
+}
% \end{macrocode}
-% Save the outgoing angle.
-% \begin{macrocode}
- \let\hobby@angle=\hobby@thetaone
-% \end{macrocode}
-% Compute the control lengths.
-% \begin{macrocode}
- \pgfmathsetmacro\hobby@alpha{%
- sqrt(2) * (sin(\hobby@thetazero r) - 1/16 * sin(\hobby@phione r))%
-* (sin(\hobby@phione r) - 1/16 * sin(\hobby@thetazero r))%
- * (cos(\hobby@thetazero r) - cos(\hobby@phione r))}%
- \pgfmathsetmacro\hobby@rho{%
- (2 + \hobby@alpha)/(1 + (1 - (3 - sqrt(5))/2)%
- * cos(\hobby@thetazero r) + (3 - sqrt(5))/2 * cos(\hobby@phione r))}%
- \pgfmathsetmacro\hobby@sigma{%
- (2 - \hobby@alpha)/(1 + (1 - (3 - sqrt(5))/2)%
- * cos(\hobby@phione r) + (3 - sqrt(5))/2 * cos(\hobby@thetazero r))}%
-% \end{macrocode}
-% Now compute the control points.
-% \begin{macrocode}
- \hobby@qpoints
- \pgf@xa=\pgf@x
- \pgf@ya=\pgf@y
- \pgfmathsetlength\pgf@xa{%
- \pgf@xa + \hobby@dzero * \hobby@rho%
- * cos((\hobby@thetazero + \hobby@omegazero) r)/3*\hobby@sf}%
- \pgfmathsetlength\pgf@ya{%
- \pgf@ya + \hobby@dzero * \hobby@rho%
- * sin((\hobby@thetazero + \hobby@omegazero) r)/3*\hobby@sf}%
- \hobby@qpointa
- \pgf@xb=\pgf@x
- \pgf@yb=\pgf@y
- \pgfmathsetlength\pgf@xb{%
- \pgf@xb - \hobby@dzero * \hobby@sigma%
- * cos((-\hobby@phione + \hobby@omegazero) r)/3*\hobby@sf}%
- \pgfmathsetlength\pgf@yb{%
- \pgf@yb - \hobby@dzero * \hobby@sigma%
- * sin((-\hobby@phione + \hobby@omegazero) r)/3*\hobby@sf}%
-% \end{macrocode}
-% Now add the relevant part to the path.
+% \end{macro}
+%
+% \begin{macro}{\hobby@qaddfromtikz}
+% This adds our current point to the stack.
% \begin{macrocode}
- \hobby@qpointa
- \edef\hobby@quick@path{\hobby@quick@path .. controls%
- (\the\pgf@xa,\the\pgf@ya) and (\the\pgf@xb,\the\pgf@yb) .. (\the\pgf@x,\the\pgf@y) }%
+\def\hobby@qaddfromtikz#1{%
+ \hobby@quick@compute{#1}%
+ \tikz@make@last@position{\hobby@qpointa}%
+ \tikz@scan@next@command%
+}
% \end{macrocode}
-% Cycle the points round for the next iteration.
+% \end{macro}
+%
+% \begin{macro}{\hobby@qinit@tikz@commands}
% \begin{macrocode}
- \let\hobby@qpoints=\hobby@qpointa
- #1
- \edef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+\def\hobby@qinit@tikz@commands{%
+ \hobby@qinit@tikz@modcmd\tikz@movetoabs
+ \hobby@qinit@tikz@modcmd\tikz@movetorel
+ \hobby@qinit@tikz@modcmd\tikz@lineto
+ \hobby@qinit@tikz@modcmd\tikz@rect
+ \hobby@qinit@tikz@modcmd\tikz@cchar
+ \hobby@qinit@tikz@modcmd\tikz@finish
+ \hobby@qinit@tikz@modcmd\tikz@arcA
+ \hobby@qinit@tikz@modcmd\tikz@e@char
+ \hobby@qinit@tikz@modcmd\tikz@g@char
+ \hobby@qinit@tikz@modcmd\tikz@schar
+ \hobby@qinit@tikz@modcmd\tikz@vh@lineto
+ \hobby@qinit@tikz@modcmd\tikz@pchar
+ \hobby@qinit@tikz@modcmd\tikz@to
+ \hobby@qinit@tikz@modcmd\pgf@stop
+ \hobby@qinit@tikz@modcmd\tikz@decoration
+ \global\let\hobby@curveto@delegate=\hobby@qmidcurveto@auto
+}
% \end{macrocode}
-% Test to see if we have more points.
-% If not, the next thing we see will be that \Verb+\relax+.
+% \end{macro}
+%
+% \begin{macro}{\hobby@qrestore@tikz@commands}
% \begin{macrocode}
- \pgfutil@ifnextchar\relax{%
+\def\hobby@qrestore@tikz@commands{%
+ \hobby@restore@tikz@modcmd\tikz@movetoabs
+ \hobby@restore@tikz@modcmd\tikz@movetorel
+ \hobby@restore@tikz@modcmd\tikz@lineto
+ \hobby@restore@tikz@modcmd\tikz@rect
+ \hobby@restore@tikz@modcmd\tikz@cchar
+ \hobby@restore@tikz@modcmd\tikz@finish
+ \hobby@restore@tikz@modcmd\tikz@arcA
+ \hobby@restore@tikz@modcmd\tikz@e@char
+ \hobby@restore@tikz@modcmd\tikz@g@char
+ \hobby@restore@tikz@modcmd\tikz@schar
+ \hobby@restore@tikz@modcmd\tikz@vh@lineto
+ \hobby@restore@tikz@modcmd\tikz@pchar
+ \hobby@restore@tikz@modcmd\tikz@to
+ \hobby@restore@tikz@modcmd\pgf@stop
+ \hobby@restore@tikz@modcmd\tikz@decoration
+ \hobby@restore@tikz@modcmd\tikz@@close
+ \global\let\hobby@curveto@delegate=\hobby@qcurveto@auto
+}
% \end{macrocode}
-% No more points.
-% Compute the control points for the second part of the curve and add that to the path.
+% \end{macro}
+%
+% \begin{macro}{\hobby@qinit@tikz@modcmd}
% \begin{macrocode}
- \pgfmathsetmacro\hobby@alpha{%
- sqrt(2) * (sin(\hobby@thetaone r) - 1/16 * sin(\hobby@phitwo r))%
- * (sin(\hobby@phitwo r) - 1/16 * sin(\hobby@thetaone r))%
- * (cos(\hobby@thetaone r) - cos(\hobby@phitwo r))}%
- \pgfmathsetmacro\hobby@rho{%
- (2 + \hobby@alpha)/(1 + (1 - (3 - sqrt(5))/2)%
- * cos(\hobby@thetaone r) + (3 - sqrt(5))/2 * cos(\hobby@phitwo r))}%
- \pgfmathsetmacro\hobby@sigma{%
- (2 - \hobby@alpha)/(1 + (1 - (3 - sqrt(5))/2)%
- * cos(\hobby@phitwo r) + (3 - sqrt(5))/2 * cos(\hobby@thetaone r))}%
- \hobby@qpoints
- \pgf@xa=\pgf@x
- \pgf@ya=\pgf@y
- \pgfmathsetlength\pgf@xa{%
- \pgf@xa + \hobby@done * \hobby@rho%
- * cos((\hobby@thetaone + \hobby@omegaone) r)/3*\hobby@sf}%
- \pgfmathsetlength\pgf@ya{%
- \pgf@ya + \hobby@done * \hobby@rho%
- * sin((\hobby@thetaone + \hobby@omegaone) r)/3*\hobby@sf}%
- \hobby@qpointa
- \pgf@xb=\pgf@x
- \pgf@yb=\pgf@y
- \pgfmathsetlength\pgf@xb{%
- \pgf@xb - \hobby@done * \hobby@sigma%
- * cos((-\hobby@phitwo + \hobby@omegaone) r)/3*\hobby@sf}%
- \pgfmathsetlength\pgf@yb{%
- \pgf@yb - \hobby@done * \hobby@sigma%
- * sin((-\hobby@phitwo + \hobby@omegaone) r)/3*\hobby@sf}%
- \hobby@qpointa
- \edef\hobby@quick@path{\hobby@quick@path .. controls%
- (\the\pgf@xa,\the\pgf@ya) and (\the\pgf@xb,\the\pgf@yb) .. (\the\pgf@x,\the\pgf@y) }%
-}{%
+\def\hobby@qinit@tikz@modcmd#1{%
+ \expandafter\global\expandafter\let\csname hobby@orig@\string#1\endcsname=#1%
+ \gdef#1{\hobby@qfinish#1}%
+}
% \end{macrocode}
-% More to go, scan in the next coordinate and off we go again.
+% \end{macro}
+%
+% \begin{macro}{\hobby@qfinish}
% \begin{macrocode}
-\tikz@scan@one@point\hobby@quick}}
+\def\hobby@qfinish{%
+ \hobby@quick@computeend
+ \hobby@qrestore@tikz@commands
+}
% \end{macrocode}
-% \end{function}
-%
+% \end{macro}
+
% \iffalse
%</tikzlibrary>
% \fi
@@ -1806,7 +2750,7 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
\int_new:N \g_array_base_int
\int_set:Nn \g_array_base_int {0}
% \end{macrocode}
-% \begin{function}{\array_adjust_ends:Nn}
+% \begin{macro}{\array_adjust_ends:Nn}
% This ensures that the ``base'' and ``top'' are big enough to include the given index.
% \begin{macrocode}
\cs_new:Npn \array_adjust_ends:Nn #1#2 {
@@ -1834,9 +2778,40 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
}
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\array_put:Nnn}
+% \begin{macro}{\array_gadjust_ends:Nn}
+% This ensures that the ``base'' and ``top'' are big enough to include the given index.
+% (Global version)
+% \begin{macrocode}
+\cs_new:Npn \array_gadjust_ends:Nn #1#2 {
+ \prop_get:NnNTF #1 {base} \l_tmpa_tl
+ {
+ \int_compare:nNnTF {\l_tmpa_tl} > {#2}
+ {
+ \prop_gput:Nnx #1 {base} {\int_eval:n {#2}}
+ }
+ {}
+ }
+ {
+ \prop_gput:Nnx #1 {base} {\int_eval:n {#2}}
+ }
+ \prop_get:NnNTF #1 {top} \l_tmpa_tl
+ {
+ \int_compare:nNnTF {\l_tmpa_tl} < {#2}
+ {
+ \prop_gput:Nnx #1 {top} {\int_eval:n {#2}}
+ }
+ {}
+ }
+ {
+ \prop_gput:Nnx #1 {top} {\int_eval:n {#2}}
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\array_put:Nnn}
% When adding a value to an array we have to adjust the ends.
% \begin{macrocode}
\cs_new:Npn \array_put:Nnn #1#2#3 {
@@ -1845,51 +2820,76 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
}
\cs_generate_variant:Nn \array_put:Nnn {Nnx}
% \end{macrocode}
-% \end{function}
+% \end{macro}
+%
+% \begin{macro}{\array_gput:Nnn}
+% When adding a value to an array we have to adjust the ends.
+% (Global version)
+% \begin{macrocode}
+\cs_new:Npn \array_gput:Nnn #1#2#3 {
+ \exp_args:NNx \prop_gput:Nnn #1 {\int_eval:n {#2}} {#3}
+ \array_gadjust_ends:Nn #1{#2}
+}
+\cs_generate_variant:Nn \array_gput:Nnn {Nnx}
+% \end{macrocode}
+% \end{macro}
%
-% \begin{function}{\array_get:NnN}
+% \begin{macro}{\array_get:NnN}
% \begin{macrocode}
\cs_new:Npn \array_get:NnN #1#2#3 {
\exp_args:NNx \prop_get:NnN #1 {\int_eval:n {#2}} #3
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}[EXP]{\array_get:Nn}
+% \begin{macro}[EXP]{\array_get:Nn}
% \begin{macrocode}
\cs_new:Npn \array_get:Nn #1#2 {
\exp_args:NNf \prop_get:Nn #1 { \int_eval:n {#2} }
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\array_get:NnNTF}
+% \begin{macro}{\array_get:NnNTF}
% \begin{macrocode}
\cs_new:Npn \array_get:NnNTF #1#2#3#4#5 {
\exp_args:NNx \prop_get:NnNTF #1 {\int_eval:n {#2}} #3 {#4}{#5}
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\array_if_empty:NTF}
+% \begin{macro}{\array_if_empty:NTF}
% \begin{macrocode}
-\cs_new_eq:NN \array_if_empty:NTF \prop_if_empty:NTF
+\prg_new_conditional:Npnn \array_if_empty:N #1 { p, T, F, TF }
+{
+ \if_meaning:w #1 \c_empty_prop
+ \prg_return_true:
+ \else:
+ \prg_return_false:
+ \fi:
+}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\array_new:N}
+% \begin{macro}{\array_new:N}
% \begin{macrocode}
\cs_new_eq:NN \array_new:N \prop_new:N
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\array_clear:N}
+% \begin{macro}{\array_clear:N}
% \begin{macrocode}
\cs_new_eq:NN \array_clear:N \prop_clear:N
% \end{macrocode}
-% \end{function}
+% \end{macro}
+%
+% \begin{macro}{\array_gclear:N}
+% \begin{macrocode}
+\cs_new_eq:NN \array_gclear:N \prop_gclear:N
+% \end{macrocode}
+% \end{macro}
%
-% \begin{function}{\array_map_function}
+% \begin{macro}{\array_map_function}
% When stepping through an array, we want to iterate in order so a simple wrapper to \Verb+\prop_map_function+ is not enough.
% This maps through every value from the base to the top so the function should be prepared to deal with a \Verb+\q_no_value+.
% \begin{macrocode}
@@ -1906,18 +2906,18 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
}{
\int_set:Nn \l_array_top_int {0}
}
- \prg_stepwise_inline:nnnn {\l_array_base_int} {1} {\l_array_top_int} {
+ \int_step_inline:nnnn {\l_array_base_int} {1} {\l_array_top_int} {
\array_get:NnN #1 {##1} \l_array_tmp_tl
- \exp_args:Nno #2 {##1} \l_array_tmp_tl
+ \exp_args:NnV #2 {##1} \l_array_tmp_tl
}
} {}
}
\cs_generate_variant:Nn \array_map_function:NN { Nc }
\cs_generate_variant:Nn \array_map_function:NN { c , cc }
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\array_reverse_map_function}
+% \begin{macro}{\array_reverse_map_function}
% This steps through the array in reverse order.
% \begin{macrocode}
\cs_new:Npn \array_reverse_map_function:NN #1#2
@@ -1933,7 +2933,7 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
}{
\int_set:Nn \l_array_top_int {0}
}
- \prg_stepwise_inline:nnnn {\l_array_top_int} {-1} {\l_array_base_int} {
+ \int_step_inline:nnnn {\l_array_top_int} {-1} {\l_array_base_int} {
\array_get:NnN #1 {##1} \l_array_tmp_tl
\exp_args:Nno #2 {##1} \l_array_tmp_tl
}
@@ -1942,43 +2942,52 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
\cs_generate_variant:Nn \array_reverse_map_function:NN { Nc }
\cs_generate_variant:Nn \array_reverse_map_function:NN { c , cc }
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\array_map_inline:Nn}
+% \begin{macro}{\array_map_inline:Nn}
% Inline version of the above.
% \begin{macrocode}
\cs_new_protected:Npn \array_map_inline:Nn #1#2
{
- \int_gincr:N \g_prg_map_int
- \cs_gset:cpn { array_map_inline_ \int_use:N \g_prg_map_int :nn }
+ \int_gincr:N \g__prg_map_int
+ \cs_gset:cpn { array_map_inline_ \int_use:N \g__prg_map_int :nn }
##1##2 {#2}
\exp_args:NNc \array_map_function:NN #1
- { array_map_inline_ \int_use:N \g_prg_map_int :nn }
- \prg_break_point:n { \int_gdecr:N \g_prg_map_int }
+ { array_map_inline_ \int_use:N \g__prg_map_int :nn }
+ \__prg_break_point:Nn \array_map_break: { \int_gdecr:N \g__prg_map_int }
}
\cs_generate_variant:Nn \array_map_inline:Nn { c }
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\array_reverse_map_inline:Nn}
+% \begin{macro}{\array_reverse_map_inline:Nn}
% Inline version of the above.
% \begin{macrocode}
\cs_new_protected:Npn \array_reverse_map_inline:Nn #1#2
{
- \int_gincr:N \g_prg_map_int
- \cs_gset:cpn { array_map_inline_ \int_use:N \g_prg_map_int :nn }
+ \int_gincr:N \g__prg_map_int
+ \cs_gset:cpn { array_map_inline_ \int_use:N \g__prg_map_int :nn }
##1##2 {#2}
\exp_args:NNc \array_reverse_map_function:NN #1
- { array_map_inline_ \int_use:N \g_prg_map_int :nn }
- \prg_break_point:n { \int_gdecr:N \g_prg_map_int }
+ { array_map_inline_ \int_use:N \g__prg_map_int :nn }
+ \__prg_break_point:Nn \array_map_break: { \int_gdecr:N \g__prg_map_int }
}
\cs_generate_variant:Nn \array_reverse_map_inline:Nn { c }
% \end{macrocode}
-% \end{function}
+% \end{macro}
+%
+% \begin{macro}{\array_map_break:}
+% \begin{macrocode}
+\cs_new_nopar:Npn \array_map_break:
+ { \__prg_map_break:Nn \array_map_break: { } }
+\cs_new_nopar:Npn \array_map_break:n
+ { \__prg_map_break:Nn \array_map_break: }
+% \end{macrocode}
+% \end{macro}
%
% For displaying arrays, we need some messages.
% \begin{macrocode}
-\msg_new:nnn { array } { show }
+\__msg_kernel_new:nnn { kernel } { show-array }
{
The~array~\token_to_str:N #1~
\array_if_empty:NTF #1
@@ -1987,31 +2996,32 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
}
% \end{macrocode}
%
-% \begin{function}{\array_show:N}
+% \begin{macro}{\array_show:N}
% Mapping through an array isn't expandable so we have to set a token list to its contents first before passing it to the message handler.
% \begin{macrocode}
\cs_new_protected:Npn \array_show:N #1
{
\tl_clear:N \l_array_show_tl
\array_map_function:NN #1 \array_show_aux:nn
- \__msg_show_variable:Nnx
+ \__msg_show_variable:Nno
#1
{ array }
- { \l_array_show_tl }
+ { \l_array_show_tl }
}
+\cs_generate_variant:Nn \__msg_show_variable:Nnn { Nno }
\cs_new_protected:Npn \array_show_aux:nn #1#2
{
- \tl_if_eq:NNTF {#2} {\q_no_value} {}
+ \tl_if_eq:nnTF {#2} {\q_no_value} {}
{
\tl_put_right:No \l_array_show_tl {\__msg_show_item:nn {#1}{#2}}
}
}
\cs_generate_variant:Nn \array_show:N { c }
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\array_push:Nn}
+% \begin{macro}{\array_push:Nn}
% \begin{macrocode}
\cs_new_protected:Npn \array_push:Nn #1#2
{
@@ -2027,9 +3037,27 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
}
\cs_generate_variant:Nn \array_push:Nn {Nx}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\array_unshift:Nn}
+% \begin{macro}{\array_gpush:Nn}b
+% \begin{macrocode}
+\cs_new_protected:Npn \array_gpush:Nn #1#2
+{
+ \prop_get:NnNTF #1 {top} \l_array_tmp_tl
+ {
+ \int_set:Nn \l_array_tmp_int {\l_array_tmp_tl}
+ \int_incr:N \l_array_tmp_int
+ \array_gput:Nnn #1 {\l_array_tmp_int} {#2}
+ }
+ {
+ \array_gput:Nnn #1 {\g_array_base_int} {#2}
+ }
+}
+\cs_generate_variant:Nn \array_gpush:Nn {Nx}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\array_unshift:Nn}
% \begin{macrocode}
\cs_new_protected:Npn \array_unshift:Nn #1#2
{
@@ -2045,9 +3073,27 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
}
\cs_generate_variant:Nn \array_unshift:Nn {Nx}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\array_pop:NN}
+% \begin{macro}{\array_gunshift:Nn}
+% \begin{macrocode}
+\cs_new_protected:Npn \array_gunshift:Nn #1#2
+{
+ \prop_get:NnNTF #1 {base} \l_array_tmp_tl
+ {
+ \int_set:Nn \l_array_tmp_int {\l_array_tmp_tl}
+ \int_decr:N \l_array_tmp_int
+ \array_gput:Nnn #1 {\l_array_tmp_int} {#2}
+ }
+ {
+ \array_gput:Nnn #1 {\g_array_base_int} {#2}
+ }
+}
+\cs_generate_variant:Nn \array_gunshift:Nn {Nx}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\array_pop:NN}
% \begin{macrocode}
\cs_new_protected:Npn \array_pop:NN #1#2
{
@@ -2056,9 +3102,20 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
\array_del:Nn #1 {\l_array_tmp_tl}
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
+%
+% \begin{macro}{\array_gpop:NN}
+% \begin{macrocode}
+\cs_new_protected:Npn \array_gpop:NN #1#2
+{
+ \prop_get:NnN #1 {top} \l_array_tmp_tl
+ \array_get:NnN #1 {\l_array_tmp_tl} #2
+ \array_gdel:Nn #1 {\l_array_tmp_tl}
+}
+% \end{macrocode}
+% \end{macro}
%
-% \begin{function}{\array_shift:NN}
+% \begin{macro}{\array_shift:NN}
% \begin{macrocode}
\cs_new_protected:Npn \array_shift:NN #1#2
{
@@ -2067,9 +3124,20 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
\array_del:Nn #1 {\l_array_tmp_tl}
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
+%
+% \begin{macro}{\array_gshift:NN}
+% \begin{macrocode}
+\cs_new_protected:Npn \array_gshift:NN #1#2
+{
+ \prop_get:NnN #1 {base} \l_array_tmp_tl
+ \array_get:NnN #1 {\l_array_tmp_tl} #2
+ \array_gdel:Nn #1 {\l_array_tmp_tl}
+}
+% \end{macrocode}
+% \end{macro}
%
-% \begin{function}{\array_top:NN}
+% \begin{macro}{\array_top:NN}
% \begin{macrocode}
\cs_new_protected:Npn \array_top:NN #1#2
{
@@ -2077,9 +3145,9 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
\array_get:NnN #1 {\l_array_tmp_tl} #2
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\array_base:NN}
+% \begin{macro}{\array_base:NN}
% \begin{macrocode}
\cs_new_protected:Npn \array_base:NN #1#2
{
@@ -2087,31 +3155,31 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
\array_get:NnN #1 {\l_array_tmp_tl} #2
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\array_top:N}
+% \begin{macro}{\array_top:N}
% \begin{macrocode}
\cs_new:Npn \array_top:N #1
{
\array_get:Nn #1 {\prop_get:Nn #1 {top}}
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\array_base:N}
+% \begin{macro}{\array_base:N}
% \begin{macrocode}
\cs_new:Npn \array_base:N #1
{
\array_get:Nn #1 {\prop_get:Nn #1 {base}}
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
%
-% \begin{function}{\array_del:Nn}
+% \begin{macro}{\array_del:Nn}
% \begin{macrocode}
\cs_new_protected:Npn \array_del:Nn #1#2
{
- \exp_args:NNx \prop_del:Nn #1 {\int_eval:n {#2}}
+ \exp_args:NNx \prop_pop:Nn #1 {\int_eval:n {#2}}
\int_set:Nn \l_array_tmp_int {0}
\array_map_inline:Nn #1 {
\tl_if_eq:NNTF {##2} {\q_no_value} {}
@@ -2140,7 +3208,7 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
}{}
\prop_get:NnN #1 {base} \l_array_tmp_tl
\int_compare:nNnTF {#2} = {\l_array_tmp_tl} {
-p \prop_get:NnN #1 {top} \l_array_tmp_tl
+ \prop_get:NnN #1 {top} \l_array_tmp_tl
\int_set:Nn \l_array_tmp_int {\l_array_tmp_tl}
\array_map_inline:Nn #1 {
\tl_if_eq:NNTF {##2} {\q_no_value} {}
@@ -2155,16 +3223,66 @@ p \prop_get:NnN #1 {top} \l_array_tmp_tl
}
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
+%
+% \begin{macro}{\array_gdel:Nn}
+% \begin{macrocode}
+\cs_new_protected:Npn \array_gdel:Nn #1#2
+{
+ \exp_args:NNx \prop_gpop:Nn #1 {\int_eval:n {#2}}
+ \int_set:Nn \l_array_tmp_int {0}
+ \array_map_inline:Nn #1 {
+ \tl_if_eq:NNTF {##2} {\q_no_value} {}
+ {
+ \int_incr:N \l_array_tmp_int
+ }
+ }
+ \int_compare:nNnTF {\l_array_tmp_int} = {0}
+ {
+ \prop_gclear:N #1
+ }
+ {
+ \prop_get:NnN #1 {top} \l_array_tmp_tl
+ \int_compare:nNnTF {#2} = {\l_array_tmp_tl} {
+ \prop_get:NnN #1 {base} \l_array_tmp_tl
+ \int_set:Nn \l_array_tmp_int {\l_array_tmp_tl}
+ \array_map_inline:Nn #1 {
+ \tl_if_eq:NNTF {##2} {\q_no_value} {}
+ {
+ \int_compare:nNnTF {\l_array_tmp_int} < {##1} {
+ \int_set:Nn \l_array_tmp_int {##1}
+ }{}
+ }
+ }
+ \prop_gput:Nnx #1 {top} {\int_use:N \l_array_tmp_int}
+ }{}
+ \prop_get:NnN #1 {base} \l_array_tmp_tl
+ \int_compare:nNnTF {#2} = {\l_array_tmp_tl} {
+ \prop_get:NnN #1 {top} \l_array_tmp_tl
+ \int_set:Nn \l_array_tmp_int {\l_array_tmp_tl}
+ \array_map_inline:Nn #1 {
+ \tl_if_eq:NNTF {##2} {\q_no_value} {}
+ {
+ \int_compare:nNnTF {\l_array_tmp_int} > {##1} {
+ \int_set:Nn \l_array_tmp_int {##1}
+ }{}
+ }
+ }
+ \prop_gput:Nnx #1 {base} {\int_use:N \l_array_tmp_int}
+ }{}
+ }
+}
+% \end{macrocode}
+% \end{macro}
%
-% \begin{function}{\array_length:N}
+% \begin{macro}{\array_length:N}
% \begin{macrocode}
\cs_new_protected:Npn \array_length:N #1
{
\int_eval:n {\prop_get:Nn #1 {top} - \prop_get:Nn #1 {base}}
}
% \end{macrocode}
-% \end{function}
+% \end{macro}
% \begin{macrocode}
\ExplSyntaxOff
% \end{macrocode}
diff --git a/Master/texmf-dist/tex/latex/hobby/hobby.code.tex b/Master/texmf-dist/tex/latex/hobby/hobby.code.tex
index 70555c1973c..18c3409d5a3 100644
--- a/Master/texmf-dist/tex/latex/hobby/hobby.code.tex
+++ b/Master/texmf-dist/tex/latex/hobby/hobby.code.tex
@@ -18,6 +18,8 @@
\RequirePackage{pml3array}
\ExplSyntaxOn
\cs_generate_variant:Nn \fp_set:Nn {Nx}
+\cs_generate_variant:Nn \tl_if_eq:nnTF {VnTF}
+\cs_generate_variant:Nn \tl_if_eq:nnTF {xnTF}
\fp_new:N \g_hobby_parama_fp
\fp_new:N \g_hobby_paramb_fp
\fp_new:N \g_hobby_paramc_fp
@@ -32,6 +34,7 @@
\array_new:N \l_hobby_points_array
\array_new:N \l_hobby_points_x_array
\array_new:N \l_hobby_points_y_array
+\array_new:N \l_hobby_actions_array
\array_new:N \l_hobby_angles_array
\array_new:N \l_hobby_distances_array
\array_new:N \l_hobby_tension_out_array
@@ -64,34 +67,79 @@
\fp_new:N \l_hobby_out_angle_fp
\fp_set_eq:NN \l_hobby_out_angle_fp \c_undefined_fp
\int_new:N \l_hobby_npoints_int
+\int_new:N \l_hobby_draw_int
\keys_define:nn {hobby / read in all} {
x .fp_set:N = \l_hobby_tempa_fp,
y .fp_set:N = \l_hobby_tempb_fp,
tension~out .fp_set:N = \l_hobby_tempc_fp,
tension~in .fp_set:N = \l_hobby_tempd_fp,
excess~angle .fp_set:N = \l_hobby_temps_fp,
+ break .tl_set:N = \l_tmpb_tl,
+ blank .tl_set:N = \l_tmpa_tl,
tension .meta:n = { tension~out=#1, tension~in=#1 },
+ break .default:n = false,
+ blank .default:n = false,
+ invert~soft~blanks .choice:,
+ invert~soft~blanks / true .code:n = {
+ \int_gset:Nn \l_hobby_draw_int {0}
+ },
+ invert~soft~blanks / false .code:n = {
+ \int_gset:Nn \l_hobby_draw_int {1}
+ },
+ invert~soft~blanks .default:n = true,
tension~out .default:n = 1,
tension~in .default:n = 1,
excess~angle .default:n = 0,
- in~angle .fp_set:N = \l_hobby_in_angle_fp,
- out~angle .fp_set:N = \l_hobby_out_angle_fp,
- in~curl .fp_set:N = \l_hobby_in_curl_fp,
- out~curl .fp_set:N = \l_hobby_out_curl_fp,
- closed .bool_set:N = \l_hobby_closed_bool,
+ in~angle .fp_gset:N = \l_hobby_in_angle_fp,
+ out~angle .fp_gset:N = \l_hobby_out_angle_fp,
+ in~curl .fp_gset:N = \l_hobby_in_curl_fp,
+ out~curl .fp_gset:N = \l_hobby_out_curl_fp,
+ closed .bool_gset:N = \l_hobby_closed_bool,
closed .default:n = true,
- disjoint .bool_set:N = \l_hobby_disjoint_bool,
+ disjoint .bool_gset:N = \l_hobby_disjoint_bool,
disjoint .default:n = true,
+ break~default .code:n = {
+ \keys_define:nn { hobby / read in all }
+ {
+ break .default:n = #1
+ }
+ },
+ blank~default .code:n = {
+ \keys_define:nn { hobby / read in all }
+ {
+ blank .default:n = #1
+ }
+ },
}
\keys_define:nn { hobby / read in params} {
- in~angle .fp_set:N = \l_hobby_in_angle_fp,
- out~angle .fp_set:N = \l_hobby_out_angle_fp,
- in~curl .fp_set:N = \l_hobby_in_curl_fp,
- out~curl .fp_set:N = \l_hobby_out_curl_fp,
- closed .bool_set:N = \l_hobby_closed_bool,
+ in~angle .fp_gset:N = \l_hobby_in_angle_fp,
+ out~angle .fp_gset:N = \l_hobby_out_angle_fp,
+ in~curl .fp_gset:N = \l_hobby_in_curl_fp,
+ out~curl .fp_gset:N = \l_hobby_out_curl_fp,
+ closed .bool_gset:N = \l_hobby_closed_bool,
closed .default:n = true,
- disjoint .bool_set:N = \l_hobby_disjoint_bool,
+ disjoint .bool_gset:N = \l_hobby_disjoint_bool,
disjoint .default:n = true,
+ break~default .code:n = {
+ \keys_define:nn { hobby / read in all }
+ {
+ break .default:n = #1
+ }
+ },
+ blank~default .code:n = {
+ \keys_define:nn { hobby / read in all }
+ {
+ blank .default:n = #1
+ }
+ },
+ invert~soft~blanks .choice:,
+ invert~soft~blanks / true .code:n = {
+ \int_gset:Nn \l_hobby_draw_int {0}
+ },
+ invert~soft~blanks / false .code:n = {
+ \int_gset:Nn \l_hobby_draw_int {1}
+ },
+ invert~soft~blanks .default:n = true,
}
\cs_set:Nn \hobby_distangle:n {
\fp_set:Nn \l_hobby_tempa_fp {
@@ -132,10 +180,11 @@
\hobby_append_point_copy_aux:Nn \l_hobby_tension_in_array {#1}
\hobby_append_point_copy_aux:Nn \l_hobby_tension_out_array {#1}
\hobby_append_point_copy_aux:Nn \l_hobby_excess_angle_array {#1}
+ \hobby_append_point_copy_aux:Nn \l_hobby_actions_array {#1}
}
\cs_new_protected:Npn \hobby_append_point_copy_aux:Nn #1#2
- { \array_push:Nx #1 { \array_get:Nn #1 {#2} } }
-\cs_new:Nn \hobby_genpath:
+ { \array_gpush:Nx #1 { \array_get:Nn #1 {#2} } }
+\cs_new:Nn \hobby_gen_path:
{
\bool_if:NT \l_hobby_closed_bool {
\fp_compare:nTF {(\array_get:Nn \l_hobby_points_x_array {0})
@@ -156,10 +205,69 @@
}
\hobby_append_point_copy:n {1}
}
-\int_set:Nn \l_hobby_npoints_int {\array_length:N \l_hobby_points_y_array}
+\int_gset:Nn \l_hobby_npoints_int {\array_length:N \l_hobby_points_y_array}
+\int_compare:nNnTF {\l_hobby_npoints_int} = {0} {
+}
+{
+ \int_compare:nNnTF {\l_hobby_npoints_int} = {1} {
+\hobby_distangle:n {0}
+\fp_if_undefined:NF \l_hobby_out_angle_fp
+{
+ \fp_set:Nn \l_hobby_tempa_fp { \l_hobby_out_angle_fp
+ - \array_get:Nn \l_hobby_angles_array {0} }
+ \fp_compare:nT {\l_hobby_tempa_fp > \c_pi_fp }
+ {
+ \fp_sub:Nn \l_hobby_tempa_fp {2 * \c_pi_fp}
+ }
+ \fp_compare:nT {\l_hobby_tempa_fp < -\c_pi_fp }
+ {
+ \fp_add:Nn \l_hobby_tempa_fp {2 * \c_pi_fp}
+ }
+ \array_put:Nnx \l_hobby_theta_array {0} {\fp_to_tl:N \l_hobby_tempa_fp}
+ \fp_if_undefined:NT \l_hobby_in_angle_fp
+ {
+ \array_put:Nnx \l_hobby_phi_array {1}{ \fp_to_tl:N \l_hobby_tempa_fp}
+ }
+ }
+\fp_if_undefined:NTF \l_hobby_in_angle_fp
+{
+ \fp_if_undefined:NT \l_hobby_out_angle_fp
+ {
+ \array_put:Nnx \l_hobby_phi_array {1} {0}
+ \array_put:Nnx \l_hobby_theta_array {0} {0}
+ }
+}
+{
+ \fp_set:Nn \l_hobby_tempa_fp { - \l_hobby_in_angle_fp + \c_pi_fp
++ (\array_get:Nn \l_hobby_angles_array {0})}
+ \fp_compare:nT {\l_hobby_tempa_fp > \c_pi_fp }
+ {
+ \fp_sub:Nn \l_hobby_tempa_fp {2 * \c_pi_fp}
+ }
+ \fp_compare:nT {\l_hobby_tempa_fp < -\c_pi_fp }
+ {
+ \fp_add:Nn \l_hobby_tempa_fp {2 * \c_pi_fp}
+ }
-\prg_stepwise_function:nnnN {0} {1} {\l_hobby_npoints_int - 1} \hobby_distangle:n
- \prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
+ \array_put:Nnx \l_hobby_phi_array {1}
+ {\fp_to_tl:N \l_hobby_tempa_fp}
+ \fp_if_undefined:NT \l_hobby_out_angle_fp
+ {
+ \array_put:Nnx \l_hobby_theta_array {0}{ \fp_to_tl:N \l_hobby_tempa_fp}
+ }
+}
+
+ }
+ {
+ \hobby_compute_path:
+ }
+ \hobby_build_path:
+}
+}
+\cs_new:Nn \hobby_compute_path:
+{
+\int_step_function:nnnN {0} {1} {\l_hobby_npoints_int - 1} \hobby_distangle:n
+ \int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
\fp_set:Nx \l_hobby_tempa_fp {
\array_get:Nn \l_hobby_angles_array {##1}
- \array_get:Nn \l_hobby_angles_array {##1 - 1}}
@@ -178,14 +286,14 @@
}{}
\array_put:Nnx \l_hobby_psi_array {##1}{\fp_to_tl:N \l_hobby_tempa_fp}
}
- \prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
+ \int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
\array_put:Nnx \l_hobby_matrix_a_array {##1} {\fp_to_tl:n {
\array_get:Nn \l_hobby_tension_in_array {##1}^2
* \array_get:Nn \l_hobby_distances_array {##1}
* \array_get:Nn \l_hobby_tension_in_array {##1 + 1}
}}
}
- \prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
+ \int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
\array_put:Nnx \l_hobby_matrix_b_array {##1} {\fp_to_tl:n
{(3 * (\array_get:Nn \l_hobby_tension_in_array {##1 + 1}) - 1) *
@@ -199,7 +307,7 @@
* (\array_get:Nn \l_hobby_distances_array {##1})}
}
}
- \prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int - 2} {
+ \int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int - 2} {
\array_put:Nnx \l_hobby_matrix_c_array {##1} {\fp_to_tl:n
{(\array_get:Nn \l_hobby_tension_in_array {##1})^2
@@ -208,7 +316,7 @@
}}
}
- \prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int - 2} {
+ \int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int - 2} {
\array_put:Nnx \l_hobby_matrix_d_array {##1} {\fp_to_tl:n
{
@@ -253,7 +361,7 @@
}
\array_put:Nnn \l_hobby_vector_u_array {0} {1}
\array_put:Nnn \l_hobby_vector_u_array {\l_hobby_npoints_int - 1} {1}
- \prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int - 2} {
+ \int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int - 2} {
\array_put:Nnn \l_hobby_vector_u_array {##1} {0}
}
\fp_set:Nn \l_hobby_matrix_v_fp {
@@ -365,7 +473,7 @@
* (\array_get:Nn \l_hobby_distances_array {\l_hobby_npoints_int - 1}) }}
}
}
-\prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
+\int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
\array_put:Nnx \l_hobby_matrix_b_array {##1} {\fp_to_tl:n {
(\array_get:Nn \l_hobby_matrix_b_array {##1 - 1})
@@ -409,7 +517,7 @@
/ (\array_get:Nn \l_hobby_matrix_b_array {\l_hobby_npoints_int - 1})
}}
}
-\prg_stepwise_inline:nnnn {\l_hobby_npoints_int - 2} {-1} {0} {
+\int_step_inline:nnnn {\l_hobby_npoints_int - 2} {-1} {0} {
\array_put:Nnx \l_hobby_theta_array {##1} {\fp_to_tl:n {
( (\array_get:Nn \l_hobby_matrix_d_array {##1})
@@ -419,7 +527,7 @@
}}
}
\bool_if:NT \l_hobby_closed_bool {
-\prg_stepwise_inline:nnnn {\l_hobby_npoints_int - 2} {-1} {0} {
+\int_step_inline:nnnn {\l_hobby_npoints_int - 2} {-1} {0} {
\array_put:Nnx \l_hobby_vector_u_array {##1} {\fp_to_tl:n
{
((\array_get:Nn \l_hobby_vector_u_array {##1})
@@ -440,7 +548,7 @@
+ 1
)}
-\prg_stepwise_inline:nnnn {0} {1} {\l_hobby_npoints_int - 1} {
+\int_step_inline:nnnn {0} {1} {\l_hobby_npoints_int - 1} {
\array_put:Nnx \l_hobby_theta_array {##1} {\fp_to_tl:n {
(\array_get:Nn \l_hobby_theta_array {##1})
@@ -449,7 +557,7 @@
}}
}
}
-\prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
+\int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int - 1} {
\array_put:Nnx \l_hobby_phi_array {##1} {\fp_to_tl:n {
- (\array_get:Nn \l_hobby_psi_array {##1})
@@ -457,7 +565,7 @@
}}
}
\bool_if:NTF \l_hobby_closed_bool {
- \int_decr:N \l_hobby_npoints_int
+ \int_gdecr:N \l_hobby_npoints_int
}{
\fp_if_undefined:NT \l_hobby_in_angle_fp
{
@@ -478,7 +586,10 @@
}}
}
}
-\prg_stepwise_inline:nnnn {0} {1} {\l_hobby_npoints_int - 1} {
+}
+\cs_new:Nn \hobby_build_path:
+{
+\int_step_inline:nnnn {0} {1} {\l_hobby_npoints_int - 1} {
\fp_set:Nn \l_hobby_tempa_fp {\array_get:Nn \l_hobby_theta_array {##1}}
@@ -493,9 +604,8 @@
\array_put:Nnx \l_hobby_rho_array {##1} {\fp_to_tl:N \l_hobby_temps_fp}
}
-\prg_stepwise_inline:nnnn {0} {1} {\l_hobby_npoints_int - 1} {
-
-\array_put:Nnx \l_hobby_controla_array {##1 + 1} {x = \fp_eval:n {
+\int_step_inline:nnnn {0} {1} {\l_hobby_npoints_int - 1} {
+\array_gput:Nnx \l_hobby_controla_array {##1 + 1} {x = \fp_eval:n {
(\array_get:Nn \l_hobby_points_x_array {##1})
+
(\array_get:Nn \l_hobby_distances_array {##1}) *
@@ -515,9 +625,8 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
}
}
}
-
-\prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int} {
- \array_put:Nnx \l_hobby_controlb_array {##1} {
+\int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int} {
+ \array_gput:Nnx \l_hobby_controlb_array {##1} {
x = \fp_eval:n {\array_get:Nn \l_hobby_points_x_array {##1}
- (\array_get:Nn \l_hobby_distances_array {##1 - 1})
* (\array_get:Nn \l_hobby_sigma_array {##1})
@@ -533,35 +642,8 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
}
}
\NewDocumentCommand \hobbyinit {m m m} {
-\hobby_set_cmds:nnn#1#2#3
-\array_clear:N \l_hobby_points_array
-\array_clear:N \l_hobby_points_x_array
-\array_clear:N \l_hobby_points_y_array
-\array_clear:N \l_hobby_angles_array
-\array_clear:N \l_hobby_distances_array
-\array_clear:N \l_hobby_tension_out_array
-\array_clear:N \l_hobby_tension_in_array
-\array_clear:N \l_hobby_excess_angle_array
-\array_clear:N \l_hobby_matrix_a_array
-\array_clear:N \l_hobby_matrix_b_array
-\array_clear:N \l_hobby_matrix_c_array
-\array_clear:N \l_hobby_matrix_d_array
-\array_clear:N \l_hobby_vector_u_array
-\array_clear:N \l_hobby_psi_array
-\array_clear:N \l_hobby_theta_array
-\array_clear:N \l_hobby_phi_array
-\array_clear:N \l_hobby_sigma_array
-\array_clear:N \l_hobby_rho_array
-\array_clear:N \l_hobby_controla_array
-\array_clear:N \l_hobby_controlb_array
-\bool_set_false:N \l_hobby_closed_bool
-\bool_set_false:N \l_hobby_disjoint_bool
-
- \int_set:Nn \l_hobby_npoints_int {-1}
- \fp_set_eq:NN \l_hobby_in_angle_fp \c_undefined_fp
- \fp_set_eq:NN \l_hobby_out_angle_fp \c_undefined_fp
- \fp_set_eq:NN \l_hobby_in_curl_fp \c_one_fp
- \fp_set_eq:NN \l_hobby_out_curl_fp \c_one_fp
+ \hobby_set_cmds:nnn#1#2#3
+ \hobby_clear_path:
}
\NewDocumentCommand \hobbyaddpoint { m } {
\keys_set:nn { hobby/read in all }
@@ -569,16 +651,29 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
tension~out,
tension~in,
excess~angle,
+ blank,
+ break,
#1
}
- \array_push:Nx \l_hobby_tension_out_array {\fp_to_tl:N \l_hobby_tempc_fp}
- \array_push:Nx \l_hobby_tension_in_array {\fp_to_tl:N \l_hobby_tempd_fp}
- \array_push:Nx \l_hobby_excess_angle_array {\fp_to_tl:N \l_hobby_temps_fp}
- \array_push:Nx \l_hobby_points_array {
+ \tl_if_eq:VnTF {\l_tmpa_tl} {true}
+ {\tl_set:Nn \l_tmpa_tl {2}}
+ {
+ \tl_if_eq:VnTF {\l_tmpa_tl} {soft}
+ {\tl_set:Nn \l_tmpa_tl {0}}
+ {\tl_set:Nn \l_tmpa_tl {1}}
+ }
+ \tl_if_eq:VnTF {\l_tmpb_tl} {true}
+ {\tl_put_right:Nn \l_tmpa_tl {1}}
+ {\tl_put_right:Nn \l_tmpa_tl {0}}
+ \array_gpush:Nx \l_hobby_actions_array {\l_tmpa_tl}
+ \array_gpush:Nx \l_hobby_tension_out_array {\fp_to_tl:N \l_hobby_tempc_fp}
+ \array_gpush:Nx \l_hobby_tension_in_array {\fp_to_tl:N \l_hobby_tempd_fp}
+ \array_gpush:Nx \l_hobby_excess_angle_array {\fp_to_tl:N \l_hobby_temps_fp}
+ \array_gpush:Nx \l_hobby_points_array {
x = \fp_use:N \l_hobby_tempa_fp,
y = \fp_use:N \l_hobby_tempb_fp }
- \array_push:Nx \l_hobby_points_x_array {\fp_to_tl:N \l_hobby_tempa_fp}
- \array_push:Nx \l_hobby_points_y_array {\fp_to_tl:N \l_hobby_tempb_fp}
+ \array_gpush:Nx \l_hobby_points_x_array {\fp_to_tl:N \l_hobby_tempa_fp}
+ \array_gpush:Nx \l_hobby_points_y_array {\fp_to_tl:N \l_hobby_tempb_fp}
}
\NewDocumentCommand \hobbysetparams { m } {
\keys_set:nn { hobby / read in params }
@@ -587,28 +682,196 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1})
}
}
\cs_new:Nn \hobby_set_cmds:nnn {
- \cs_set_eq:NN \hobby_moveto:n #1
- \cs_set_eq:NN \hobby_curveto:nnn #2
- \cs_set_eq:NN \hobby_close:n #3
+ \cs_gset_eq:NN \hobby_moveto:n #1
+ \cs_gset_eq:NN \hobby_curveto:nnn #2
+ \cs_gset_eq:NN \hobby_close:n #3
}
-\tl_new:N \l_tmpc_tl
\NewDocumentCommand \hobbygenpath { } {
- \hobby_genpath:
+ \array_if_empty:NF \l_hobby_points_array {
+ \hobby_gen_path:
+ }
+}
+\NewDocumentCommand \hobbygenifnecpath { m } {
+ \tl_if_exist:cTF {g_hobby_#1_path}
+ {
+ \tl_use:c {g_hobby_#1_path}
+ }
+ {
+ \hobby_gen_path:
+ }
+ \hobby_save_path:n {#1}
+ \hobby_save_path_to_aux:x {#1}
+}
+\NewDocumentCommand \hobbygenuseifnecpath { m } {
+ \tl_if_exist:cTF {g_hobby_#1_path}
+ {
+ \tl_use:c {g_hobby_#1_path}
+ }
+ {
+ \hobby_gen_path:
+ }
+ \hobby_save_path:n {#1}
+ \hobby_save_path_to_aux:x {#1}
+ \hobby_use_path:
+}
+\NewDocumentCommand \hobbyusepath { m } {
+ \hobbysetparams{#1}
+ \hobby_use_path:
+}
+\NewDocumentCommand \hobbysavepath { m } {
+ \hobby_save_path:n {#1}
+}
+\NewDocumentCommand \hobbyrestorepath { m } {
+ \tl_if_exist:cT {g_hobby_#1_path} {
+ \tl_use:c {g_hobby_#1_path}
+ }
+}
+\NewDocumentCommand \hobbyshowpath { m } {
+ \tl_if_exist:cT {g_hobby_#1_path} {
+ \tl_show:c {g_hobby_#1_path}
+ }
+}
+\NewDocumentCommand \hobbygenusepath { } {
+ \array_if_empty:NF \l_hobby_points_array {
+ \hobby_gen_path:
+ \hobby_use_path:
+ }
+}
+\NewDocumentCommand \hobbyclearpath { } {
+ \hobby_clear_path:
+}
+\tl_new:N \l_tmpc_tl
+\cs_new:Nn \hobby_use_path: {
\bool_if:NT \l_hobby_disjoint_bool {
\array_get:NnN \l_hobby_points_array {0} \l_tmpa_tl
\exp_args:No \hobby_moveto:n {\l_tmpa_tl}
}
- \prg_stepwise_inline:nnnn {1} {1} {\l_hobby_npoints_int} {
+ \int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int} {
\array_get:NnN \l_hobby_controla_array {##1} \l_tmpa_tl
\array_get:NnN \l_hobby_controlb_array {##1} \l_tmpb_tl
\array_get:NnN \l_hobby_points_array {##1} \l_tmpc_tl
- \exp_args:Nooo \hobby_curveto:nnn {\l_tmpa_tl} {\l_tmpb_tl} {\l_tmpc_tl}
-}
+ \array_get:NnN \l_hobby_actions_array {##1} \l_tmpd_tl
+ \int_compare:nNnTF {\tl_item:Nn \l_tmpd_tl {1}} = {\l_hobby_draw_int} {
+ \exp_args:Nooo \hobby_curveto:nnn {\l_tmpa_tl} {\l_tmpb_tl} {\l_tmpc_tl}
+ }{
+ \bool_gset_false:N \l_hobby_closed_bool
+ \exp_args:No \hobby_moveto:n {\l_tmpc_tl}
+ }
+ \tl_if_eq:xnTF {\tl_item:Nn \l_tmpd_tl {2}} {1} {
+ \bool_gset_false:N \l_hobby_closed_bool
+ \exp_args:No \hobby_moveto:n {\l_tmpc_tl}
+ }{}
+ }
\bool_if:NT \l_hobby_closed_bool {
\array_get:NnN \l_hobby_points_array {0} \l_tmpa_tl
\exp_args:No \hobby_close:n {\l_tmpa_tl}
}
}
+\cs_new:Nn \hobby_save_path:n {
+ \tl_clear:N \l_tmpa_tl
+ \tl_put_right:Nn \l_tmpa_tl {\int_gset:Nn \l_hobby_npoints_int}
+ \tl_put_right:Nx \l_tmpa_tl {{\int_use:N \l_hobby_npoints_int}}
+ \bool_if:NTF \l_hobby_disjoint_bool {
+ \tl_put_right:Nn \l_tmpa_tl {\bool_gset_true:N}
+ }{
+ \tl_put_right:Nn \l_tmpa_tl {\bool_gset_false:N}
+ }
+ \tl_put_right:Nn \l_tmpa_tl {\l_hobby_disjoint_bool}
+ \bool_if:NTF \l_hobby_closed_bool {
+ \tl_put_right:Nn \l_tmpa_tl {\bool_gset_true:N}
+ }{
+ \tl_put_right:Nn \l_tmpa_tl {\bool_gset_false:N}
+ }
+ \tl_put_right:Nn \l_tmpa_tl {\l_hobby_closed_bool}
+ \tl_put_right:Nn \l_tmpa_tl {\array_gclear:N \l_hobby_points_array}
+ \array_map_inline:Nn \l_hobby_points_array {
+ \tl_put_right:Nn \l_tmpa_tl {
+ \array_gput:Nnn \l_hobby_points_array {##1} {##2}
+ }
+ }
+ \tl_put_right:Nn \l_tmpa_tl {\array_gclear:N \l_hobby_actions_array}
+ \array_map_inline:Nn \l_hobby_actions_array {
+ \tl_put_right:Nn \l_tmpa_tl {
+ \array_gput:Nnn \l_hobby_actions_array {##1} {##2}
+ }
+ }
+ \tl_put_right:Nn \l_tmpa_tl {\array_gclear:N \l_hobby_controla_array}
+ \array_map_inline:Nn \l_hobby_controla_array {
+ \tl_put_right:Nn \l_tmpa_tl {
+ \array_gput:Nnn \l_hobby_controla_array {##1} {##2}
+ }
+ }
+ \tl_put_right:Nn \l_tmpa_tl {\array_gclear:N \l_hobby_controlb_array}
+ \array_map_inline:Nn \l_hobby_controlb_array {
+ \tl_put_right:Nn \l_tmpa_tl {
+ \array_gput:Nnn \l_hobby_controlb_array {##1} {##2}
+ }
+ }
+ \tl_gclear_new:c {g_hobby_#1_path}
+ \tl_gset_eq:cN {g_hobby_#1_path} \l_tmpa_tl
+}
+\int_set:Nn \l_tmpa_int {\char_value_catcode:n {`@}}
+\char_set_catcode_letter:N @
+\cs_new:Npn \hobby_save_path_to_aux:n #1 {
+ \bool_if:nT {
+ \tl_if_exist_p:c {g_hobby_#1_path}
+ &&
+ ! \tl_if_exist_p:c {g_hobby_#1_path_saved}
+ }
+ {
+ \tl_clear:N \l_tmpa_tl
+ \tl_put_right:Nn \l_tmpa_tl {
+ \ExplSyntaxOn
+ \tl_gclear_new:c {g_hobby_#1_path}
+ \tl_gput_right:cn {g_hobby_#1_path}
+ }
+ \tl_put_right:Nx \l_tmpa_tl {
+ {\tl_to_str:c {g_hobby_#1_path}}
+ }
+ \tl_put_right:Nn \l_tmpa_tl {
+ \ExplSyntaxOff
+ }
+ \protected@write\@auxout{}{
+ \tl_to_str:N \l_tmpa_tl
+ }
+ \tl_new:c {g_hobby_#1_path_saved}
+ }
+}
+\char_set_catcode:nn {`@} {\l_tmpa_int}
+\cs_generate_variant:Nn \hobby_save_path_to_aux:n {x}
+\cs_new:Nn \hobby_clear_path:
+{
+\array_gclear:N \l_hobby_points_array
+\array_gclear:N \l_hobby_points_x_array
+\array_gclear:N \l_hobby_points_y_array
+\array_gclear:N \l_hobby_angles_array
+\array_gclear:N \l_hobby_actions_array
+\array_gclear:N \l_hobby_distances_array
+\array_gclear:N \l_hobby_tension_out_array
+\array_gclear:N \l_hobby_tension_in_array
+\array_gclear:N \l_hobby_excess_angle_array
+\array_gclear:N \l_hobby_matrix_a_array
+\array_gclear:N \l_hobby_matrix_b_array
+\array_gclear:N \l_hobby_matrix_c_array
+\array_gclear:N \l_hobby_matrix_d_array
+\array_gclear:N \l_hobby_vector_u_array
+\array_gclear:N \l_hobby_psi_array
+\array_gclear:N \l_hobby_theta_array
+\array_gclear:N \l_hobby_phi_array
+\array_gclear:N \l_hobby_sigma_array
+\array_gclear:N \l_hobby_rho_array
+\array_gclear:N \l_hobby_controla_array
+\array_gclear:N \l_hobby_controlb_array
+\bool_gset_false:N \l_hobby_closed_bool
+\bool_gset_false:N \l_hobby_disjoint_bool
+
+ \int_gset:Nn \l_hobby_npoints_int {-1}
+ \int_gset:Nn \l_hobby_draw_int {1}
+ \fp_gset_eq:NN \l_hobby_in_angle_fp \c_undefined_fp
+ \fp_gset_eq:NN \l_hobby_out_angle_fp \c_undefined_fp
+ \fp_gset_eq:NN \l_hobby_in_curl_fp \c_one_fp
+ \fp_gset_eq:NN \l_hobby_out_curl_fp \c_one_fp
+}
\ExplSyntaxOff
%%
%% Copyright (C) 2012 by Andrew Stacey <stacey@math.ntnu.no>
diff --git a/Master/texmf-dist/tex/latex/hobby/pgflibraryhobby.code.tex b/Master/texmf-dist/tex/latex/hobby/pgflibraryhobby.code.tex
index 3e4e609dae9..5d0f4a91996 100644
--- a/Master/texmf-dist/tex/latex/hobby/pgflibraryhobby.code.tex
+++ b/Master/texmf-dist/tex/latex/hobby/pgflibraryhobby.code.tex
@@ -18,7 +18,7 @@
/pgf/hobby/.is family,
/pgf/hobby/.cd,
x/.code={\pgf@x=#1cm},
- y/.code={\pgf@y=#1cm},
+ y/.code={\pgf@y=#1cm}
}
\def\hobby@curveto#1#2#3{%
\pgfpathcurveto{\hobby@topgf{#1}}{\hobby@topgf{#2}}{\hobby@topgf{#3}}%
@@ -32,6 +32,183 @@
\def\hobby@close#1{%
\pgfpathclose
}
+\def\pgfplothandlerhobby{%
+ \def\pgf@plotstreamstart{%
+ \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
+ \global\let\pgf@plotstreampoint=\pgf@plot@hobby@firstpt
+ \global\let\pgf@plotstreamspecial=\pgfutil@gobble
+ \gdef\pgf@plotstreamend{%
+ \ifhobby@externalise
+ \ifx\hobby@path@name\pgfutil@empty
+ \hobbygenusepath
+ \else
+ \hobbygenuseifnecpath{\hobby@path@name}%
+ \fi
+ \else
+ \hobbygenusepath
+ \fi
+ \ifx\hobby@path@name\pgfutil@empty
+ \else
+ \hobbysavepath{\hobby@path@name}%
+ \fi
+ \global\let\hobby@path@name=\pgfutil@empty
+ }%
+ \let\tikz@scan@point@options=\pgfutil@empty
+ }
+}
+\def\pgfplothandlerclosedhobby{%
+ \def\pgf@plotstreamstart{%
+ \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
+ \hobbysetparams{closed=true,disjoint=true}%
+ \global\let\pgf@plotstreampoint=\pgf@plot@hobby@firstpt
+ \global\let\pgf@plotstreamspecial=\pgfutil@gobble
+ \gdef\pgf@plotstreamend{%
+ \ifhobby@externalise
+ \ifx\hobby@path@name\pgfutil@empty
+ \hobbygenusepath
+ \else
+ \hobbygenuseifnecpath{\hobby@path@name}%
+ \fi
+ \else
+ \hobbygenusepath
+ \fi
+ \ifx\hobby@path@name\pgfutil@empty
+ \else
+ \hobbysavepath{\hobby@path@name}%
+ \fi
+ \global\let\hobby@path@name=\pgfutil@empty
+ }%
+ }
+}
+\def\pgf@plot@hobby@firstpt#1{%
+ \pgf@plot@first@action{#1}%
+ \pgf@plot@hobby@handler{#1}%
+ \global\let\pgf@plotstreampoint=\pgf@plot@hobby@handler
+}
+\def\pgf@plot@hobby@handler#1{%
+ #1%
+ \pgfmathsetmacro\hobby@x{\the\pgf@x/1cm}%
+ \pgfmathsetmacro\hobby@y{\the\pgf@y/1cm}%
+ \hobbyaddpoint{x = \hobby@x, y = \hobby@y}%
+ }
+\def\pgfplothandlerquickhobby{%
+ \def\pgf@plotstreamstart{%
+ \global\let\hobby@quick@curveto=\pgfpathcurveto
+ \global\let\pgf@plotstreampoint=\pgf@plot@qhobby@firstpt
+ \global\let\pgf@plotstreamspecial=\pgfutil@gobble
+ \global\let\pgf@plotstreamend=\pgf@plot@qhobby@end
+ }
+}
+\def\pgf@plot@qhobby@firstpt#1{%
+ #1%
+ \edef\hobby@temp{\noexpand\pgf@plot@first@action{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}\hobby@temp%
+ \xdef\hobby@qpoints{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ \gdef\hobby@qpointa{}%
+ \gdef\hobby@angle{}%
+ \global\let\pgf@plotstreampoint=\pgf@plot@qhobby@secondpt
+}
+\def\pgf@plot@qhobby@secondpt#1{%
+ #1%
+ \xdef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ \global\let\pgf@plotstreampoint=\pgf@plot@qhobby@handler
+}
+\def\pgf@plot@qhobby@handler#1{%
+ #1
+ \edef\hobby@temp{\noexpand\hobby@quick@compute{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}\hobby@temp
+ \global\let\hobby@qpointa=\hobby@qpointa
+ \global\let\hobby@qpoints=\hobby@qpoints
+ \global\let\hobby@angle=\hobby@angle
+ \global\let\hobby@thetaone=\hobby@thetaone
+ \global\let\hobby@phitwo=\hobby@phitwo
+ \global\let\hobby@done=\hobby@done
+ \global\let\hobby@omegaone=\hobby@omegaone
+}
+\def\pgf@plot@qhobby@end{%
+ \hobby@quick@computeend
+}
+\pgfmathsetmacro\hobby@sf{10cm}
+\def\hobby@quick@compute#1{%
+ #1%
+ \pgf@xb=\pgf@x
+ \pgf@yb=\pgf@y
+ \hobby@qpointa
+ \pgf@xa=\pgf@x
+ \pgf@ya=\pgf@y
+ \advance\pgf@xb by -\pgf@xa
+ \advance\pgf@yb by -\pgf@ya
+ \pgfmathsetmacro\hobby@done{sqrt((\pgf@xb/\hobby@sf)^2 + (\pgf@yb/\hobby@sf)^2)}%
+ \pgfmathsetmacro\hobby@omegaone{rad(atan2(\pgf@xb,\pgf@yb))}%
+ \hobby@qpoints
+ \advance\pgf@xa by -\pgf@x
+ \advance\pgf@ya by -\pgf@y
+ \pgfmathsetmacro\hobby@dzero{sqrt((\pgf@xa/\hobby@sf)^2 + (\pgf@ya/\hobby@sf)^2)}%
+ \pgfmathsetmacro\hobby@omegazero{rad(atan2(\pgf@xa,\pgf@ya))}%
+ \pgfmathsetmacro\hobby@psi{\hobby@omegaone - \hobby@omegazero}%
+ \pgfmathsetmacro\hobby@psi{\hobby@psi > pi ? \hobby@psi - 2*pi : \hobby@psi}%
+ \pgfmathsetmacro\hobby@psi{\hobby@psi < -pi ? \hobby@psi + 2*pi : \hobby@psi}%
+ \ifx\hobby@angle\pgfutil@empty
+ \pgfmathsetmacro\hobby@thetaone{-\hobby@psi * \hobby@done%
+/(\hobby@done + \hobby@dzero)}%
+ \pgfmathsetmacro\hobby@thetazero{-\hobby@psi - \hobby@thetaone}%
+ \let\hobby@phione=\hobby@thetazero
+ \let\hobby@phitwo=\hobby@thetaone
+ \else
+ \let\hobby@thetazero=\hobby@angle
+ \pgfmathsetmacro\hobby@thetaone{%
+ -(2 * \hobby@psi + \hobby@thetazero) * \hobby@done%
+ / (2 * \hobby@done + \hobby@dzero)}%
+ \pgfmathsetmacro\hobby@phione{-\hobby@psi - \hobby@thetaone}%
+ \let\hobby@phitwo=\hobby@thetaone
+ \fi
+ \let\hobby@angle=\hobby@thetaone
+ \hobby@quick@ctrlpts{\hobby@thetazero}{\hobby@phione}{\hobby@qpoints}{\hobby@qpointa}{\hobby@dzero}{\hobby@omegazero}%
+ \edef\hobby@temp{\noexpand\hobby@quick@curveto{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}{\noexpand\pgfqpoint{\the\pgf@xb}{\the\pgf@yb}}{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}%
+\hobby@temp
+ \global\let\hobby@qpoints=\hobby@qpointa
+ #1
+ \xdef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ \global\let\hobby@angle=\hobby@angle
+ \global\let\hobby@phitwo=\hobby@phitwo
+ \global\let\hobby@thetaone=\hobby@thetaone
+\global\let\hobby@done=\hobby@done
+\global\let\hobby@omegaone=\hobby@omegaone
+}
+\def\hobby@quick@computeend{%
+ \hobby@quick@ctrlpts{\hobby@thetaone}{\hobby@phitwo}{\hobby@qpoints}{\hobby@qpointa}{\hobby@done}{\hobby@omegaone}%
+ \edef\hobby@temp{\noexpand\hobby@quick@curveto{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}{\noexpand\pgfqpoint{\the\pgf@xb}{\the\pgf@yb}}{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}%
+\hobby@temp
+}%
+\def\hobby@quick@ctrlpts#1#2#3#4#5#6{%
+ \pgfmathsetmacro\hobby@alpha{%
+ sqrt(2) * (sin(#1 r) - 1/16 * sin(#2 r))%
+* (sin(#2 r) - 1/16 * sin(#1 r))%
+ * (cos(#1 r) - cos(#2 r))}%
+ \pgfmathsetmacro\hobby@rho{%
+ (2 + \hobby@alpha)/(1 + (1 - (3 - sqrt(5))/2)%
+ * cos(#1 r) + (3 - sqrt(5))/2 * cos(#2 r))}%
+ \pgfmathsetmacro\hobby@sigma{%
+ (2 - \hobby@alpha)/(1 + (1 - (3 - sqrt(5))/2)%
+ * cos(#2 r) + (3 - sqrt(5))/2 * cos(#1 r))}%
+ #3%
+ \pgf@xa=\pgf@x
+ \pgf@ya=\pgf@y
+ \pgfmathsetlength\pgf@xa{%
+ \pgf@xa + #5 * \hobby@rho%
+ * cos((#1 + #6) r)/3*\hobby@sf}%
+ \pgfmathsetlength\pgf@ya{%
+ \pgf@ya + #5 * \hobby@rho%
+ * sin((#1 + #6) r)/3*\hobby@sf}%
+ #4%
+ \pgf@xb=\pgf@x
+ \pgf@yb=\pgf@y
+ \pgfmathsetlength\pgf@xb{%
+ \pgf@xb - #5 * \hobby@sigma%
+ * cos((-#2 + #6) r)/3*\hobby@sf}%
+ \pgfmathsetlength\pgf@yb{%
+ \pgf@yb - #5 * \hobby@sigma%
+ * sin((-#2 + #6) r)/3*\hobby@sf}%
+ #4%
+}
%%
%% Copyright (C) 2012 by Andrew Stacey <stacey@math.ntnu.no>
%%
diff --git a/Master/texmf-dist/tex/latex/hobby/pml3array.sty b/Master/texmf-dist/tex/latex/hobby/pml3array.sty
index e704e4c41ab..3aeb1e6849b 100644
--- a/Master/texmf-dist/tex/latex/hobby/pml3array.sty
+++ b/Master/texmf-dist/tex/latex/hobby/pml3array.sty
@@ -46,11 +46,40 @@
\prop_put:Nnx #1 {top} {\int_eval:n {#2}}
}
}
+\cs_new:Npn \array_gadjust_ends:Nn #1#2 {
+ \prop_get:NnNTF #1 {base} \l_tmpa_tl
+ {
+ \int_compare:nNnTF {\l_tmpa_tl} > {#2}
+ {
+ \prop_gput:Nnx #1 {base} {\int_eval:n {#2}}
+ }
+ {}
+ }
+ {
+ \prop_gput:Nnx #1 {base} {\int_eval:n {#2}}
+ }
+ \prop_get:NnNTF #1 {top} \l_tmpa_tl
+ {
+ \int_compare:nNnTF {\l_tmpa_tl} < {#2}
+ {
+ \prop_gput:Nnx #1 {top} {\int_eval:n {#2}}
+ }
+ {}
+ }
+ {
+ \prop_gput:Nnx #1 {top} {\int_eval:n {#2}}
+ }
+}
\cs_new:Npn \array_put:Nnn #1#2#3 {
\exp_args:NNx \prop_put:Nnn #1 {\int_eval:n {#2}} {#3}
\array_adjust_ends:Nn #1{#2}
}
\cs_generate_variant:Nn \array_put:Nnn {Nnx}
+\cs_new:Npn \array_gput:Nnn #1#2#3 {
+ \exp_args:NNx \prop_gput:Nnn #1 {\int_eval:n {#2}} {#3}
+ \array_gadjust_ends:Nn #1{#2}
+}
+\cs_generate_variant:Nn \array_gput:Nnn {Nnx}
\cs_new:Npn \array_get:NnN #1#2#3 {
\exp_args:NNx \prop_get:NnN #1 {\int_eval:n {#2}} #3
}
@@ -60,9 +89,17 @@
\cs_new:Npn \array_get:NnNTF #1#2#3#4#5 {
\exp_args:NNx \prop_get:NnNTF #1 {\int_eval:n {#2}} #3 {#4}{#5}
}
-\cs_new_eq:NN \array_if_empty:NTF \prop_if_empty:NTF
+\prg_new_conditional:Npnn \array_if_empty:N #1 { p, T, F, TF }
+{
+ \if_meaning:w #1 \c_empty_prop
+ \prg_return_true:
+ \else:
+ \prg_return_false:
+ \fi:
+}
\cs_new_eq:NN \array_new:N \prop_new:N
\cs_new_eq:NN \array_clear:N \prop_clear:N
+\cs_new_eq:NN \array_gclear:N \prop_gclear:N
\cs_new:Npn \array_map_function:NN #1#2
{
\array_if_empty:NTF #1 {} {
@@ -76,9 +113,9 @@
}{
\int_set:Nn \l_array_top_int {0}
}
- \prg_stepwise_inline:nnnn {\l_array_base_int} {1} {\l_array_top_int} {
+ \int_step_inline:nnnn {\l_array_base_int} {1} {\l_array_top_int} {
\array_get:NnN #1 {##1} \l_array_tmp_tl
- \exp_args:Nno #2 {##1} \l_array_tmp_tl
+ \exp_args:NnV #2 {##1} \l_array_tmp_tl
}
} {}
}
@@ -97,7 +134,7 @@
}{
\int_set:Nn \l_array_top_int {0}
}
- \prg_stepwise_inline:nnnn {\l_array_top_int} {-1} {\l_array_base_int} {
+ \int_step_inline:nnnn {\l_array_top_int} {-1} {\l_array_base_int} {
\array_get:NnN #1 {##1} \l_array_tmp_tl
\exp_args:Nno #2 {##1} \l_array_tmp_tl
}
@@ -107,25 +144,29 @@
\cs_generate_variant:Nn \array_reverse_map_function:NN { c , cc }
\cs_new_protected:Npn \array_map_inline:Nn #1#2
{
- \int_gincr:N \g_prg_map_int
- \cs_gset:cpn { array_map_inline_ \int_use:N \g_prg_map_int :nn }
+ \int_gincr:N \g__prg_map_int
+ \cs_gset:cpn { array_map_inline_ \int_use:N \g__prg_map_int :nn }
##1##2 {#2}
\exp_args:NNc \array_map_function:NN #1
- { array_map_inline_ \int_use:N \g_prg_map_int :nn }
- \prg_break_point:n { \int_gdecr:N \g_prg_map_int }
+ { array_map_inline_ \int_use:N \g__prg_map_int :nn }
+ \__prg_break_point:Nn \array_map_break: { \int_gdecr:N \g__prg_map_int }
}
\cs_generate_variant:Nn \array_map_inline:Nn { c }
\cs_new_protected:Npn \array_reverse_map_inline:Nn #1#2
{
- \int_gincr:N \g_prg_map_int
- \cs_gset:cpn { array_map_inline_ \int_use:N \g_prg_map_int :nn }
+ \int_gincr:N \g__prg_map_int
+ \cs_gset:cpn { array_map_inline_ \int_use:N \g__prg_map_int :nn }
##1##2 {#2}
\exp_args:NNc \array_reverse_map_function:NN #1
- { array_map_inline_ \int_use:N \g_prg_map_int :nn }
- \prg_break_point:n { \int_gdecr:N \g_prg_map_int }
+ { array_map_inline_ \int_use:N \g__prg_map_int :nn }
+ \__prg_break_point:Nn \array_map_break: { \int_gdecr:N \g__prg_map_int }
}
\cs_generate_variant:Nn \array_reverse_map_inline:Nn { c }
-\msg_new:nnn { array } { show }
+\cs_new_nopar:Npn \array_map_break:
+ { \__prg_map_break:Nn \array_map_break: { } }
+\cs_new_nopar:Npn \array_map_break:n
+ { \__prg_map_break:Nn \array_map_break: }
+\__msg_kernel_new:nnn { kernel } { show-array }
{
The~array~\token_to_str:N #1~
\array_if_empty:NTF #1
@@ -136,15 +177,16 @@
{
\tl_clear:N \l_array_show_tl
\array_map_function:NN #1 \array_show_aux:nn
- \__msg_show_variable:Nnx
+ \__msg_show_variable:Nno
#1
{ array }
- { \l_array_show_tl }
+ { \l_array_show_tl }
}
+\cs_generate_variant:Nn \__msg_show_variable:Nnn { Nno }
\cs_new_protected:Npn \array_show_aux:nn #1#2
{
- \tl_if_eq:NNTF {#2} {\q_no_value} {}
+ \tl_if_eq:nnTF {#2} {\q_no_value} {}
{
\tl_put_right:No \l_array_show_tl {\__msg_show_item:nn {#1}{#2}}
}
@@ -163,6 +205,19 @@
}
}
\cs_generate_variant:Nn \array_push:Nn {Nx}
+\cs_new_protected:Npn \array_gpush:Nn #1#2
+{
+ \prop_get:NnNTF #1 {top} \l_array_tmp_tl
+ {
+ \int_set:Nn \l_array_tmp_int {\l_array_tmp_tl}
+ \int_incr:N \l_array_tmp_int
+ \array_gput:Nnn #1 {\l_array_tmp_int} {#2}
+ }
+ {
+ \array_gput:Nnn #1 {\g_array_base_int} {#2}
+ }
+}
+\cs_generate_variant:Nn \array_gpush:Nn {Nx}
\cs_new_protected:Npn \array_unshift:Nn #1#2
{
\prop_get:NnNTF #1 {base} \l_array_tmp_tl
@@ -176,18 +231,43 @@
}
}
\cs_generate_variant:Nn \array_unshift:Nn {Nx}
+\cs_new_protected:Npn \array_gunshift:Nn #1#2
+{
+ \prop_get:NnNTF #1 {base} \l_array_tmp_tl
+ {
+ \int_set:Nn \l_array_tmp_int {\l_array_tmp_tl}
+ \int_decr:N \l_array_tmp_int
+ \array_gput:Nnn #1 {\l_array_tmp_int} {#2}
+ }
+ {
+ \array_gput:Nnn #1 {\g_array_base_int} {#2}
+ }
+}
+\cs_generate_variant:Nn \array_gunshift:Nn {Nx}
\cs_new_protected:Npn \array_pop:NN #1#2
{
\prop_get:NnN #1 {top} \l_array_tmp_tl
\array_get:NnN #1 {\l_array_tmp_tl} #2
\array_del:Nn #1 {\l_array_tmp_tl}
}
+\cs_new_protected:Npn \array_gpop:NN #1#2
+{
+ \prop_get:NnN #1 {top} \l_array_tmp_tl
+ \array_get:NnN #1 {\l_array_tmp_tl} #2
+ \array_gdel:Nn #1 {\l_array_tmp_tl}
+}
\cs_new_protected:Npn \array_shift:NN #1#2
{
\prop_get:NnN #1 {base} \l_array_tmp_tl
\array_get:NnN #1 {\l_array_tmp_tl} #2
\array_del:Nn #1 {\l_array_tmp_tl}
}
+\cs_new_protected:Npn \array_gshift:NN #1#2
+{
+ \prop_get:NnN #1 {base} \l_array_tmp_tl
+ \array_get:NnN #1 {\l_array_tmp_tl} #2
+ \array_gdel:Nn #1 {\l_array_tmp_tl}
+}
\cs_new_protected:Npn \array_top:NN #1#2
{
\prop_get:NnN #1 {top} \l_array_tmp_tl
@@ -208,7 +288,7 @@
}
\cs_new_protected:Npn \array_del:Nn #1#2
{
- \exp_args:NNx \prop_del:Nn #1 {\int_eval:n {#2}}
+ \exp_args:NNx \prop_pop:Nn #1 {\int_eval:n {#2}}
\int_set:Nn \l_array_tmp_int {0}
\array_map_inline:Nn #1 {
\tl_if_eq:NNTF {##2} {\q_no_value} {}
@@ -237,7 +317,7 @@
}{}
\prop_get:NnN #1 {base} \l_array_tmp_tl
\int_compare:nNnTF {#2} = {\l_array_tmp_tl} {
-p \prop_get:NnN #1 {top} \l_array_tmp_tl
+ \prop_get:NnN #1 {top} \l_array_tmp_tl
\int_set:Nn \l_array_tmp_int {\l_array_tmp_tl}
\array_map_inline:Nn #1 {
\tl_if_eq:NNTF {##2} {\q_no_value} {}
@@ -251,6 +331,51 @@ p \prop_get:NnN #1 {top} \l_array_tmp_tl
}{}
}
}
+\cs_new_protected:Npn \array_gdel:Nn #1#2
+{
+ \exp_args:NNx \prop_gpop:Nn #1 {\int_eval:n {#2}}
+ \int_set:Nn \l_array_tmp_int {0}
+ \array_map_inline:Nn #1 {
+ \tl_if_eq:NNTF {##2} {\q_no_value} {}
+ {
+ \int_incr:N \l_array_tmp_int
+ }
+ }
+ \int_compare:nNnTF {\l_array_tmp_int} = {0}
+ {
+ \prop_gclear:N #1
+ }
+ {
+ \prop_get:NnN #1 {top} \l_array_tmp_tl
+ \int_compare:nNnTF {#2} = {\l_array_tmp_tl} {
+ \prop_get:NnN #1 {base} \l_array_tmp_tl
+ \int_set:Nn \l_array_tmp_int {\l_array_tmp_tl}
+ \array_map_inline:Nn #1 {
+ \tl_if_eq:NNTF {##2} {\q_no_value} {}
+ {
+ \int_compare:nNnTF {\l_array_tmp_int} < {##1} {
+ \int_set:Nn \l_array_tmp_int {##1}
+ }{}
+ }
+ }
+ \prop_gput:Nnx #1 {top} {\int_use:N \l_array_tmp_int}
+ }{}
+ \prop_get:NnN #1 {base} \l_array_tmp_tl
+ \int_compare:nNnTF {#2} = {\l_array_tmp_tl} {
+ \prop_get:NnN #1 {top} \l_array_tmp_tl
+ \int_set:Nn \l_array_tmp_int {\l_array_tmp_tl}
+ \array_map_inline:Nn #1 {
+ \tl_if_eq:NNTF {##2} {\q_no_value} {}
+ {
+ \int_compare:nNnTF {\l_array_tmp_int} > {##1} {
+ \int_set:Nn \l_array_tmp_int {##1}
+ }{}
+ }
+ }
+ \prop_gput:Nnx #1 {base} {\int_use:N \l_array_tmp_int}
+ }{}
+ }
+}
\cs_new_protected:Npn \array_length:N #1
{
\int_eval:n {\prop_get:Nn #1 {top} - \prop_get:Nn #1 {base}}
diff --git a/Master/texmf-dist/tex/latex/hobby/tikzlibraryhobby.code.tex b/Master/texmf-dist/tex/latex/hobby/tikzlibraryhobby.code.tex
index 9214dfd6dd3..a3fa361d216 100644
--- a/Master/texmf-dist/tex/latex/hobby/tikzlibraryhobby.code.tex
+++ b/Master/texmf-dist/tex/latex/hobby/tikzlibraryhobby.code.tex
@@ -14,251 +14,489 @@
%% ----------------------------------------------------------------
%%
\usepgflibrary{hobby}
-\let\hobby@opts=\pgfutil@empty
+\let\hobby@this@opts=\pgfutil@empty
+\let\hobby@next@opts=\pgfutil@empty
+\let\hobby@action=\pgfutil@empty
+\let\hobby@path@name=\pgfutil@empty
+\newif\ifhobby@externalise
+\def\hobby@point@options{}%
\tikzset{
curve through/.style={
to path={
\pgfextra{
- \expandafter\curvethrough\expandafter[\hobby@opts]{%
+ \expandafter\curvethrough\expandafter[\hobby@next@opts]{%
(\tikztostart) .. #1 .. (\tikztotarget)%
}
}
}
},
- tension in/.code = {},
- tension out/.code = {},
- tension/.code = {},
- excess angle/.code = {},
- closed/.code = {%
- \expandafter\def\expandafter\hobby@opts\expandafter{\hobby@opts%
- closed=#1,disjoint=#1}%
+ tension in/.code = {%
+ \expandafter\gdef\expandafter\hobby@point@options\expandafter%
+ {\hobby@point@options,tension in=#1}%
+ },
+ tension out/.code = {%
+ \expandafter\gdef\expandafter\hobby@point@options\expandafter%
+ {\hobby@point@options,tension out=#1}%
+ },
+ tension/.code = {%
+ \expandafter\gdef\expandafter\hobby@point@options\expandafter%
+ {\hobby@point@options,tension=#1}%
+ },
+ excess angle/.code = {%
+ \expandafter\gdef\expandafter\hobby@point@options\expandafter%
+ {\hobby@point@options,excess angle=#1}%
+ },
+ break/.code = {%
+ \expandafter\gdef\expandafter\hobby@point@options\expandafter%
+ {\hobby@point@options,break=#1}%
+ },
+ blank/.code = {%
+ \expandafter\gdef\expandafter\hobby@point@options\expandafter%
+ {\hobby@point@options,blank=#1}%
+ },
+ designated Hobby path/.initial={next},
+ clear next Hobby path options/.code={%
+ \gdef\hobby@next@opts{}%
+ },
+ clear this Hobby path options/.code={%
+ \gdef\hobby@this@opts{}%
+ },
+ clear Hobby path options/.style={%
+ clear \pgfkeysvalueof{/tikz/designated Hobby path} Hobby path options
+ },
+ add option to this Hobby path/.code={%
+ \expandafter\gdef\expandafter\hobby@this@opts\expandafter{\hobby@this@opts#1,}%
+ },
+ add option to next Hobby path/.code={%
+ \expandafter\gdef\expandafter\hobby@next@opts\expandafter{\hobby@next@opts#1,}%
+ },
+ add option to Hobby path/.style={%
+ add option to \pgfkeysvalueof{/tikz/designated Hobby path} Hobby path={#1}%
+ },
+ closed/.style = {%
+ add option to Hobby path={closed=#1,disjoint=#1}%
+ },
+ invert blank/.style = {%
+ add option to Hobby path={invert blank=#1}%
},
closed/.default = true,
+ blank/.default = true,
+ break/.default = true,
+ invert blank/.default = true,
in angle/.code = {%
\pgfmathparse{#1*pi/180}%
- \edef\@temp{ in angle=\pgfmathresult,}%
- \expandafter\expandafter\expandafter%
- \def%
- \expandafter\expandafter\expandafter%
- \hobby@opts%
- \expandafter\expandafter\expandafter%
- {\expandafter\hobby@opts\@temp}%
+ \edef\@temp{in angle=\pgfmathresult,}%
+ \pgfkeysalso{add option to Hobby path/.expand once=\@temp}%
},
out angle/.code = {%
\pgfmathparse{#1*pi/180}%
- \edef\@temp{ out angle=\pgfmathresult,}%
- \expandafter\expandafter\expandafter%
- \def%
- \expandafter\expandafter\expandafter%
- \hobby@opts%
- \expandafter\expandafter\expandafter%
- {\expandafter\hobby@opts\@temp}%
+ \edef\@temp{out angle=\pgfmathresult,}%
+ \pgfkeysalso{add option to Hobby path/.expand once=\@temp}%
},
- in curl/.code = {%
- \expandafter\def\expandafter\hobby@opts\expandafter{\hobby@opts in curl=#1,}%
+ in curl/.style = {%
+ add option to Hobby path={in curl=#1}%
},
out curl/.code = {%
- \expandafter\def\expandafter\hobby@opts\expandafter{\hobby@opts out curl=#1,}%
+ add option to Hobby path={out curl=#1}%
},
use Hobby shortcut/.code={%
- \let\tikz@curveto@auto=\hobby@curveto@auto
- }
+ \let\tikz@curveto@auto=\hobby@curveto@override
+ \global\let\hobby@curveto@delegate=\hobby@curveto@auto
+ },
+ use quick Hobby shortcut/.code={%
+ \let\tikz@curveto@auto=\hobby@curveto@override
+ \global\let\hobby@curveto@delegate=\hobby@qcurveto@auto
+ },
+ use previous Hobby path/.code={%
+ \pgfextra{\hobbyusepath{#1}}
+ },
+ use previous Hobby path/.default={},%
+ save Hobby path/.code={%
+ \xdef\hobby@path@name{#1}%
+ },
+ restore Hobby path/.code={%
+ \pgfextra{%
+ \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
+ \hobbyrestorepath{#1}}
+ },
+ restore and use Hobby path/.code 2 args={%
+ \pgfextra{%
+ \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
+ \hobbyrestorepath{#1}%
+ \hobbyusepath{#2}%
+ }
+ },
+ show Hobby path/.code={%
+ \pgfextra{\hobbyshowpath{#1}}
+ },
+ Hobby action/.code={%
+ \expandafter\gdef\expandafter\hobby@action\expandafter{\hobby@action#1}%
+ },
+ Hobby finish/.style={%
+ Hobby action=\hobby@finish%
+ },
+ Hobby externalise/.is if=hobby@externalise,
+ Hobby externalize/.is if=hobby@externalise
}
\newcommand\curvethrough[2][]{%
\hobbyinit\hobby@moveto\hobby@curveto\hobby@close
\hobbysetparams{#1}%
- \hobby@processpts{#2}%
-}
-\newcommand\hobby@processpts[1]{%
- \pgfutil@in@{..}{#1}%
- \ifpgfutil@in@%
- \hobby@getonepoint #1 \relax
- \let\hobby@next=\hobby@processpts
- \else
- \def\hobby@pt{#1}%
- \def\hobby@rest{}%
- \let\hobby@next=\hobbygenpath
- \fi
+ \tikzset{designated Hobby path=this}%
+ \global\let\hobby@this@opts=\pgfutil@empty
+ \global\let\hobby@next@opts=\pgfutil@empty
\let\tikz@scan@point@options=\pgfutil@empty
- \expandafter\tikz@scan@one@point\expandafter\pgfutil@firstofone\hobby@pt\relax
+ \def\hobby@point@options{}%
+ \tikz@scan@one@point\hobby@processpt #2 \relax%
+}
+\newcommand\hobby@processpt[1]{%
+ #1%
\pgfmathsetmacro\hobby@x{\the\pgf@x/1cm}%
\pgfmathsetmacro\hobby@y{\the\pgf@y/1cm}%
- \expandafter\hobbyaddpoint\expandafter{\tikz@scan@point@options,%
+ \expandafter\hobbyaddpoint\expandafter{\hobby@point@options,%
x = \hobby@x, y = \hobby@y}%
- \expandafter\hobby@next\expandafter{\hobby@rest}%
-}
-\def\hobby@getonepoint#1..#2\relax{%
- \def\hobby@pt{#1}%
- \def\hobby@rest{#2}%
-}
+ \def\hobby@point@options{}%
+ \let\tikz@scan@point@options=\pgfutil@empty
+ \pgfutil@ifnextchar\relax{%
+ \expandafter\hobbysetparams\expandafter{\hobby@this@opts}%
+ \ifhobby@externalise
+ \ifx\hobby@path@name\pgfutil@empty
+ \hobbygenusepath
+ \else
+ \hobbygenuseifnecpath{\hobby@path@name}%
+ \fi
+ \else
+ \hobbygenusepath
+ \fi
+ \ifx\hobby@path@name\pgfutil@empty
+ \else
+ \hobbysavepath{\hobby@path@name}%
+ \fi
+ \global\let\hobby@path@name=\pgfutil@empty
+ }{%
+ \pgfutil@ifnextchar.{%
+ \hobby@swallowdots}{%
+ \tikz@scan@one@point\hobby@processpt}}}
+\def\hobby@swallowdots.{%
+ \pgfutil@ifnextchar.{%
+ \hobby@swallowdots}{%
+ \tikz@scan@one@point\hobby@processpt}}
+\def\hobby@curveto@override{%
+ \hobby@curveto@delegate}
\def\hobby@curveto@auto{%
- \hobbyinit\pgfutil@gobble\hobby@curveto\hobby@close
+ \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
\pgfmathsetmacro\hobby@x{\the\tikz@lastx/1cm}%
\pgfmathsetmacro\hobby@y{\the\tikz@lasty/1cm}%
- \pgfutil@ifundefined{tikz@scan@point@options}{%
- \hobbyaddpoint{x = \hobby@x, y = \hobby@y}%
- }{%
- \expandafter\hobbyaddpoint\expandafter{\tikz@scan@point@options,%
+ \expandafter\hobbysetparams\expandafter{\hobby@next@opts}%
+ \expandafter\hobbyaddpoint\expandafter{\hobby@point@options,%
x = \hobby@x, y = \hobby@y}%
- }%
+ \hobby@init@tikz@commands
+ \tikzset{designated Hobby path=this}%
\let\tikz@scan@point@options=\pgfutil@empty
+ \global\let\hobby@action=\pgfutil@empty
+ \global\let\hobby@this@opts=\pgfutil@empty
+ \global\let\hobby@next@opts=\pgfutil@empty
+ \global\let\hobby@point@options=\pgfutil@empty
\tikz@scan@one@point\hobby@addfromtikz}
\def\hobby@addfromtikz#1{%
#1%
\tikz@make@last@position{#1}%
\pgfmathsetmacro\hobby@x{\the\pgf@x/1cm}%
\pgfmathsetmacro\hobby@y{\the\pgf@y/1cm}%
- \expandafter\hobbyaddpoint\expandafter{\tikz@scan@point@options,%
+ \expandafter\hobbysetparams\expandafter{\hobby@this@opts}%
+ \expandafter\hobbyaddpoint\expandafter{\hobby@point@options,%
x = \hobby@x, y = \hobby@y}%
- \hobby@donext}
-\def\hobby@donext{%
- \pgfutil@ifnextchar.%
- {\hobby@curveto@check}%
- {\hobby@finish@auto}}%
-\def\hobby@curveto@check..{%
- \pgfutil@ifnextchar c%
- {\hobby@maybefinish@auto}%
- {\hobby@curveto@continue}}%
-\def\hobby@maybefinish@auto c{%
- \pgfutil@ifnextchar o%
- {\hobby@finish@auto .. c}%
- {\hobby@closeandfinish@auto}}
-\def\hobby@closeandfinish@auto ycle{%
- \hobbysetparams{closed=true,disjoint=true}%
- \hobby@finish@auto%
+ \hobby@action
+ \global\let\hobby@this@opts=\pgfutil@empty
+ \global\let\hobby@action=\pgfutil@empty
+ \global\let\hobby@point@options=\pgfutil@empty
+ \tikz@scan@next@command%
+}
+\def\hobby@init@tikz@commands{%
+ \hobby@init@tikz@modcmd\tikz@movetoabs
+ \hobby@init@tikz@modcmd\tikz@movetorel
+ \hobby@init@tikz@modcmd\tikz@lineto
+ \hobby@init@tikz@modcmd\tikz@rect
+ \hobby@init@tikz@modcmd\tikz@cchar
+ \hobby@init@tikz@modcmd\tikz@finish
+ \hobby@init@tikz@modcmd\tikz@arcA
+ \hobby@init@tikz@modcmd\tikz@e@char
+ \hobby@init@tikz@modcmd\tikz@g@char
+ \hobby@init@tikz@modcmd\tikz@schar
+ \hobby@init@tikz@modcmd\tikz@vh@lineto
+ \hobby@init@tikz@modcmd\tikz@pchar
+ \hobby@init@tikz@modcmd\tikz@to
+ \hobby@init@tikz@modcmd\pgf@stop
+ \hobby@init@tikz@modcmd\tikz@decoration
+ \global\let\hobby@curveto@delegate=\hobby@midcurveto@auto
+}
+\def\hobby@restore@tikz@commands{%
+ \hobby@restore@tikz@modcmd\tikz@movetoabs
+ \hobby@restore@tikz@modcmd\tikz@movetorel
+ \hobby@restore@tikz@modcmd\tikz@lineto
+ \hobby@restore@tikz@modcmd\tikz@rect
+ \hobby@restore@tikz@modcmd\tikz@cchar
+ \hobby@restore@tikz@modcmd\tikz@finish
+ \hobby@restore@tikz@modcmd\tikz@arcA
+ \hobby@restore@tikz@modcmd\tikz@e@char
+ \hobby@restore@tikz@modcmd\tikz@g@char
+ \hobby@restore@tikz@modcmd\tikz@schar
+ \hobby@restore@tikz@modcmd\tikz@vh@lineto
+ \hobby@restore@tikz@modcmd\tikz@pchar
+ \hobby@restore@tikz@modcmd\tikz@to
+ \hobby@restore@tikz@modcmd\pgf@stop
+ \hobby@restore@tikz@modcmd\tikz@decoration
+ \global\let\hobby@curveto@delegate=\hobby@curveto@auto
}
-\def\hobby@curveto@continue{%
+\def\hobby@init@tikz@modcmd#1{%
+ \expandafter\global\expandafter\let\csname hobby@orig@\string#1\endcsname=#1%
+ \gdef#1{\hobby@finish#1}%
+}
+\def\hobby@restore@tikz@modcmd#1{%
+ \expandafter\global\expandafter\let\expandafter#1\csname hobby@orig@\string#1\endcsname%
+}
+\def\hobby@midcurveto@auto{%
\let\tikz@scan@point@options=\pgfutil@empty
- \tikz@scan@one@point\hobby@addfromtikz}
-\def\hobby@finish@auto{%
- \hobbygenpath
- \tikz@scan@next@command%
+ \global\let\hobby@action=\pgfutil@empty
+ \global\let\hobby@this@opts=\pgfutil@empty
+ \global\let\hobby@point@options=\pgfutil@empty
+ \tikz@scan@one@point\hobby@addfromtikz%
+}
+\def\hobby@finish{%
+ \ifhobby@externalise
+ \ifx\hobby@path@name\pgfutil@empty
+ \hobbygenusepath
+ \else
+ \hobbygenuseifnecpath{\hobby@path@name}%
+ \fi
+ \else
+ \hobbygenusepath
+ \fi
+ \ifx\hobby@path@name\pgfutil@empty
+ \else
+ \hobbysavepath{\hobby@path@name}%
+ \fi
+ \global\let\hobby@path@name=\pgfutil@empty
+ \hobby@restore@tikz@commands
}
\tikzset{
quick curve through/.style={%
to path={%
\pgfextra{%
+ \let\hobby@next@qbreak=\relax
+ \let\hobby@next@qblank=\relax
\tikz@scan@one@point\pgfutil@firstofone(\tikztostart)%
+ \tikz@make@last@position{\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
\edef\hobby@qpoints{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
\def\hobby@qpointa{}%
\def\hobby@quick@path{}%
\def\hobby@angle{}%
+ \let\hobby@quick@curveto=\hobby@quick@makepath
\tikz@scan@one@point\hobby@quickfirst #1 (\tikztotarget)\relax
}
\hobby@quick@path
}
- }
+ },
+ quick hobby/blank curve/.is choice,
+ quick hobby/blank curve/true/.code={%
+ \gdef\hobby@next@qblank{%
+ \qhobby@blanktrue
+ \global\let\hobby@next@qblank=\relax
+ }%
+ },
+ quick hobby/blank curve/false/.code={%
+ \gdef\hobby@next@qblank{%
+ \qhobby@blankfalse
+ \global\let\hobby@next@qblank=\relax
+ }%
+ },
+ quick hobby/blank curve/once/.code={%
+ \gdef\hobby@next@qblank{%
+ \qhobby@blanktrue
+ \gdef\hobby@next@qblank{%
+ \qhobby@blankfalse
+ \global\let\hobby@next@qblank=\relax
+ }%
+ }%
+ },
+ quick hobby/blank curve/.default=true,
+ quick hobby/break curve/.is choice,
+ quick hobby/break curve/true/.code={%
+ \gdef\hobby@next@qbreak{%
+ \qhobby@breaktrue
+ \global\let\hobby@next@qbreak=\relax
+ }%
+ },
+ quick hobby/break curve/false/.code={%
+ \gdef\hobby@next@qbreak{%
+ \qhobby@breakfalse
+ \global\let\hobby@next@qbreak=\relax
+ }%
+ },
+ quick hobby/break curve/once/.code={%
+ \gdef\hobby@next@qbreak{%
+ \qhobby@breaktrue
+ \gdef\hobby@next@qbreak{%
+ \qhobby@breakfalse
+ \global\let\hobby@next@qbreak=\relax
+ }%
+ }%
+ },
+ quick hobby/break curve/.default=true,
}
-\pgfmathsetmacro\hobby@sf{10cm}
+\newif\ifqhobby@break
+\newif\ifqhobby@blank
+\tikzoption{hobby}[]{\let\tikz@plot@handler=\pgfplothandlerhobby}
+\tikzoption{quick hobby}[]{\let\tikz@plot@handler=\pgfplothandlerquickhobby}
+\tikzoption{closed hobby}[]{\let\tikz@plot@handler=\pgfplothandlerclosedhobby}
\def\hobby@quickfirst#1{%
#1%
- \edef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ \xdef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ \tikz@make@last@position{\hobby@qpointa}%
\pgfutil@ifnextchar\relax{%
- \edef\hobby@quick@path{ -- (\the\pgf@x,\the\pgf@y)}%
+ \xdef\hobby@quick@path{ -- (\the\pgf@x,\the\pgf@y)}%
}{%
+ \pgfutil@ifnextchar.{%
+ \hobby@qswallowdots}{%
+ \tikz@scan@one@point\hobby@quick}}}
+\def\hobby@qswallowdots.{%
+ \pgfutil@ifnextchar.{%
+ \hobby@qswallowdots}{%
\tikz@scan@one@point\hobby@quick}}
\def\hobby@quick#1{%
+ \hobby@quick@compute{#1}%
+ \tikz@make@last@position{\hobby@qpointa}%
+ \pgfutil@ifnextchar\relax{%
+ \hobby@quick@computeend%
+ }{%
+ \pgfutil@ifnextchar.{%
+ \hobby@qswallowdots}{%
+ \tikz@scan@one@point\hobby@quick}}}
+\def\hobby@quick@makepath#1#2#3{%
#1%
- \pgf@xb=\pgf@x
- \pgf@yb=\pgf@y
- \hobby@qpointa
- \pgf@xa=\pgf@x
- \pgf@ya=\pgf@y
- \advance\pgf@xb by -\pgf@xa
- \advance\pgf@yb by -\pgf@ya
- \pgfmathsetmacro\hobby@done{sqrt((\pgf@xb/\hobby@sf)^2 + (\pgf@yb/\hobby@sf)^2)}%
- \pgfmathsetmacro\hobby@omegaone{rad(atan2(\pgf@xb,\pgf@yb))}%
- \hobby@qpoints
- \advance\pgf@xa by -\pgf@x
- \advance\pgf@ya by -\pgf@y
- \pgfmathsetmacro\hobby@dzero{sqrt((\pgf@xa/\hobby@sf)^2 + (\pgf@ya/\hobby@sf)^2)}%
- \pgfmathsetmacro\hobby@omegazero{rad(atan2(\pgf@xa,\pgf@ya))}%
- \pgfmathsetmacro\hobby@psi{\hobby@omegaone - \hobby@omegazero}%
- \pgfmathsetmacro\hobby@psi{\hobby@psi > pi ? \hobby@psi - 2*pi : \hobby@psi}%
- \pgfmathsetmacro\hobby@psi{\hobby@psi < -pi ? \hobby@psi + 2*pi : \hobby@psi}%
- \ifx\hobby@angle\pgfutil@empty
- \pgfmathsetmacro\hobby@thetaone{-\hobby@psi * \hobby@done%
-/(\hobby@done + \hobby@dzero)}%
- \pgfmathsetmacro\hobby@thetazero{-\hobby@psi - \hobby@thetaone}%
- \let\hobby@phione=\hobby@thetazero
- \let\hobby@phitwo=\hobby@thetaone
+ \pgf@xa=\pgf@x\relax
+ \pgf@ya=\pgf@y\relax
+ #2%
+ \pgf@xb=\pgf@x\relax
+ \pgf@yb=\pgf@y\relax
+ #3%
+ \ifqhobby@blank
+ \xdef\hobby@quick@path{\hobby@quick@path (\the\pgf@x,\the\pgf@y)}%
\else
- \let\hobby@thetazero=\hobby@angle
- \pgfmathsetmacro\hobby@thetaone{%
- -(2 * \hobby@psi + \hobby@thetazero) * \hobby@done%
- / (2 * \hobby@done + \hobby@dzero)}%
- \pgfmathsetmacro\hobby@phione{-\hobby@psi - \hobby@thetaone}%
- \let\hobby@phitwo=\hobby@thetaone
- \fi
- \let\hobby@angle=\hobby@thetaone
- \pgfmathsetmacro\hobby@alpha{%
- sqrt(2) * (sin(\hobby@thetazero r) - 1/16 * sin(\hobby@phione r))%
-* (sin(\hobby@phione r) - 1/16 * sin(\hobby@thetazero r))%
- * (cos(\hobby@thetazero r) - cos(\hobby@phione r))}%
- \pgfmathsetmacro\hobby@rho{%
- (2 + \hobby@alpha)/(1 + (1 - (3 - sqrt(5))/2)%
- * cos(\hobby@thetazero r) + (3 - sqrt(5))/2 * cos(\hobby@phione r))}%
- \pgfmathsetmacro\hobby@sigma{%
- (2 - \hobby@alpha)/(1 + (1 - (3 - sqrt(5))/2)%
- * cos(\hobby@phione r) + (3 - sqrt(5))/2 * cos(\hobby@thetazero r))}%
- \hobby@qpoints
- \pgf@xa=\pgf@x
- \pgf@ya=\pgf@y
- \pgfmathsetlength\pgf@xa{%
- \pgf@xa + \hobby@dzero * \hobby@rho%
- * cos((\hobby@thetazero + \hobby@omegazero) r)/3*\hobby@sf}%
- \pgfmathsetlength\pgf@ya{%
- \pgf@ya + \hobby@dzero * \hobby@rho%
- * sin((\hobby@thetazero + \hobby@omegazero) r)/3*\hobby@sf}%
- \hobby@qpointa
- \pgf@xb=\pgf@x
- \pgf@yb=\pgf@y
- \pgfmathsetlength\pgf@xb{%
- \pgf@xb - \hobby@dzero * \hobby@sigma%
- * cos((-\hobby@phione + \hobby@omegazero) r)/3*\hobby@sf}%
- \pgfmathsetlength\pgf@yb{%
- \pgf@yb - \hobby@dzero * \hobby@sigma%
- * sin((-\hobby@phione + \hobby@omegazero) r)/3*\hobby@sf}%
- \hobby@qpointa
- \edef\hobby@quick@path{\hobby@quick@path .. controls%
+ \xdef\hobby@quick@path{\hobby@quick@path .. controls%
(\the\pgf@xa,\the\pgf@ya) and (\the\pgf@xb,\the\pgf@yb) .. (\the\pgf@x,\the\pgf@y) }%
- \let\hobby@qpoints=\hobby@qpointa
- #1
- \edef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
- \pgfutil@ifnextchar\relax{%
- \pgfmathsetmacro\hobby@alpha{%
- sqrt(2) * (sin(\hobby@thetaone r) - 1/16 * sin(\hobby@phitwo r))%
- * (sin(\hobby@phitwo r) - 1/16 * sin(\hobby@thetaone r))%
- * (cos(\hobby@thetaone r) - cos(\hobby@phitwo r))}%
- \pgfmathsetmacro\hobby@rho{%
- (2 + \hobby@alpha)/(1 + (1 - (3 - sqrt(5))/2)%
- * cos(\hobby@thetaone r) + (3 - sqrt(5))/2 * cos(\hobby@phitwo r))}%
- \pgfmathsetmacro\hobby@sigma{%
- (2 - \hobby@alpha)/(1 + (1 - (3 - sqrt(5))/2)%
- * cos(\hobby@phitwo r) + (3 - sqrt(5))/2 * cos(\hobby@thetaone r))}%
- \hobby@qpoints
- \pgf@xa=\pgf@x
- \pgf@ya=\pgf@y
- \pgfmathsetlength\pgf@xa{%
- \pgf@xa + \hobby@done * \hobby@rho%
- * cos((\hobby@thetaone + \hobby@omegaone) r)/3*\hobby@sf}%
- \pgfmathsetlength\pgf@ya{%
- \pgf@ya + \hobby@done * \hobby@rho%
- * sin((\hobby@thetaone + \hobby@omegaone) r)/3*\hobby@sf}%
- \hobby@qpointa
- \pgf@xb=\pgf@x
- \pgf@yb=\pgf@y
- \pgfmathsetlength\pgf@xb{%
- \pgf@xb - \hobby@done * \hobby@sigma%
- * cos((-\hobby@phitwo + \hobby@omegaone) r)/3*\hobby@sf}%
- \pgfmathsetlength\pgf@yb{%
- \pgf@yb - \hobby@done * \hobby@sigma%
- * sin((-\hobby@phitwo + \hobby@omegaone) r)/3*\hobby@sf}%
- \hobby@qpointa
- \edef\hobby@quick@path{\hobby@quick@path .. controls%
- (\the\pgf@xa,\the\pgf@ya) and (\the\pgf@xb,\the\pgf@yb) .. (\the\pgf@x,\the\pgf@y) }%
-}{%
-\tikz@scan@one@point\hobby@quick}}
+ \fi
+ \ifqhobby@break
+ \xdef\hobby@quick@path{\hobby@quick@path +(0,0)}%
+ \fi
+ \hobby@next@qbreak
+ \hobby@next@qblank
+}
+\def\hobby@qcurveto@auto{%
+ \global\let\hobby@next@qbreak=\relax
+ \global\let\hobby@next@qblank=\relax
+ \xdef\hobby@qpoints{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
+ \gdef\hobby@qpointa{}%
+ \gdef\hobby@quick@path{}%
+ \gdef\hobby@angle{}%
+ \global\let\hobby@quick@curveto=\hobby@quick@makepathauto
+ \hobby@qinit@tikz@commands
+ \let\tikz@scan@point@options=\pgfutil@empty
+ \global\let\hobby@action=\pgfutil@empty
+ \global\let\hobby@point@options=\pgfutil@empty
+ \tikz@scan@one@point\hobby@qfirst@auto}
+\def\hobby@qmidcurveto@auto{%
+ \let\tikz@scan@point@options=\pgfutil@empty
+ \global\let\hobby@action=\pgfutil@empty
+ \global\let\hobby@point@options=\pgfutil@empty
+ \tikz@scan@one@point\hobby@qaddfromtikz}
+\def\hobby@qfirst@auto#1{%
+ #1%
+ \xdef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ \tikz@make@last@position{\hobby@qpointa}%
+ \tikz@scan@next@command%
+}
+\def\hobby@quick@makepathauto#1#2#3{%
+ #1%
+ \pgf@xa=\pgf@x\relax
+ \pgf@ya=\pgf@y\relax
+ #2%
+ \pgf@xb=\pgf@x\relax
+ \pgf@yb=\pgf@y\relax
+ #3%
+ \ifqhobby@blank
+ \edef\hobby@temp{%
+ \noexpand\pgfpathmoveto{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ }%
+ \hobby@temp
+ \else
+ \edef\hobby@temp{%
+ \noexpand\pgfpathcurveto{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}%
+ {\noexpand\pgfqpoint{\the\pgf@xb}{\the\pgf@yb}}%
+ {\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ }%
+ \hobby@temp
+ \fi
+ \ifqhobby@break
+ #3%
+ \edef\hobby@temp{%
+ \noexpand\pgfpathmoveto{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
+ }%
+ \hobby@temp
+ \fi
+ \hobby@next@qbreak
+ \hobby@next@qblank
+}
+\def\hobby@qaddfromtikz#1{%
+ \hobby@quick@compute{#1}%
+ \tikz@make@last@position{\hobby@qpointa}%
+ \tikz@scan@next@command%
+}
+\def\hobby@qinit@tikz@commands{%
+ \hobby@qinit@tikz@modcmd\tikz@movetoabs
+ \hobby@qinit@tikz@modcmd\tikz@movetorel
+ \hobby@qinit@tikz@modcmd\tikz@lineto
+ \hobby@qinit@tikz@modcmd\tikz@rect
+ \hobby@qinit@tikz@modcmd\tikz@cchar
+ \hobby@qinit@tikz@modcmd\tikz@finish
+ \hobby@qinit@tikz@modcmd\tikz@arcA
+ \hobby@qinit@tikz@modcmd\tikz@e@char
+ \hobby@qinit@tikz@modcmd\tikz@g@char
+ \hobby@qinit@tikz@modcmd\tikz@schar
+ \hobby@qinit@tikz@modcmd\tikz@vh@lineto
+ \hobby@qinit@tikz@modcmd\tikz@pchar
+ \hobby@qinit@tikz@modcmd\tikz@to
+ \hobby@qinit@tikz@modcmd\pgf@stop
+ \hobby@qinit@tikz@modcmd\tikz@decoration
+ \global\let\hobby@curveto@delegate=\hobby@qmidcurveto@auto
+}
+\def\hobby@qrestore@tikz@commands{%
+ \hobby@restore@tikz@modcmd\tikz@movetoabs
+ \hobby@restore@tikz@modcmd\tikz@movetorel
+ \hobby@restore@tikz@modcmd\tikz@lineto
+ \hobby@restore@tikz@modcmd\tikz@rect
+ \hobby@restore@tikz@modcmd\tikz@cchar
+ \hobby@restore@tikz@modcmd\tikz@finish
+ \hobby@restore@tikz@modcmd\tikz@arcA
+ \hobby@restore@tikz@modcmd\tikz@e@char
+ \hobby@restore@tikz@modcmd\tikz@g@char
+ \hobby@restore@tikz@modcmd\tikz@schar
+ \hobby@restore@tikz@modcmd\tikz@vh@lineto
+ \hobby@restore@tikz@modcmd\tikz@pchar
+ \hobby@restore@tikz@modcmd\tikz@to
+ \hobby@restore@tikz@modcmd\pgf@stop
+ \hobby@restore@tikz@modcmd\tikz@decoration
+ \hobby@restore@tikz@modcmd\tikz@@close
+ \global\let\hobby@curveto@delegate=\hobby@qcurveto@auto
+}
+\def\hobby@qinit@tikz@modcmd#1{%
+ \expandafter\global\expandafter\let\csname hobby@orig@\string#1\endcsname=#1%
+ \gdef#1{\hobby@qfinish#1}%
+}
+\def\hobby@qfinish{%
+ \hobby@quick@computeend
+ \hobby@qrestore@tikz@commands
+}
+
%%
%% Copyright (C) 2012 by Andrew Stacey <stacey@math.ntnu.no>
%%