texlive[57504] Master/texmf-dist: spath3 (23jan21)
commits+karl at tug.org
commits+karl at tug.org
Sat Jan 23 23:17:41 CET 2021
Revision: 57504
http://tug.org/svn/texlive?view=revision&revision=57504
Author: karl
Date: 2021-01-23 23:17:41 +0100 (Sat, 23 Jan 2021)
Log Message:
-----------
spath3 (23jan21)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/latex/spath3/README
trunk/Master/texmf-dist/doc/latex/spath3/README.txt
trunk/Master/texmf-dist/doc/latex/spath3/spath3_code.pdf
trunk/Master/texmf-dist/tex/latex/spath3/spath3.sty
trunk/Master/texmf-dist/tex/latex/spath3/tikzlibrarycalligraphy.code.tex
trunk/Master/texmf-dist/tex/latex/spath3/tikzlibraryknots.code.tex
Added Paths:
-----------
trunk/Master/texmf-dist/doc/latex/spath3/calligraphy.pdf
trunk/Master/texmf-dist/doc/latex/spath3/calligraphy.tex
trunk/Master/texmf-dist/doc/latex/spath3/knots.pdf
trunk/Master/texmf-dist/doc/latex/spath3/knots.tex
trunk/Master/texmf-dist/doc/latex/spath3/spath3.pdf
trunk/Master/texmf-dist/doc/latex/spath3/spath3.tex
trunk/Master/texmf-dist/source/latex/spath3/spath3_code.dtx
trunk/Master/texmf-dist/source/latex/spath3/spath3_code.ins
trunk/Master/texmf-dist/tex/latex/spath3/tikzlibraryspath3.code.tex
Removed Paths:
-------------
trunk/Master/texmf-dist/doc/latex/spath3/calligraphy_doc.pdf
trunk/Master/texmf-dist/doc/latex/spath3/calligraphy_doc.tex
trunk/Master/texmf-dist/doc/latex/spath3/knots_doc.pdf
trunk/Master/texmf-dist/doc/latex/spath3/knots_doc.tex
trunk/Master/texmf-dist/source/latex/spath3/spath3.dtx
trunk/Master/texmf-dist/source/latex/spath3/spath3.ins
Modified: trunk/Master/texmf-dist/doc/latex/spath3/README
===================================================================
--- trunk/Master/texmf-dist/doc/latex/spath3/README 2021-01-23 10:56:29 UTC (rev 57503)
+++ trunk/Master/texmf-dist/doc/latex/spath3/README 2021-01-23 22:17:41 UTC (rev 57504)
@@ -1,6 +1,6 @@
----------------------------------------------------------------
spath3 --- LaTeX3 functions for manipulating PGF soft paths
-E-mail: stacey at math.ntnu.no
+E-mail: loopspace at mathforge.org
Released under the LaTeX Project Public License v1.3c or later
See http://www.latex-project.org/lppl.txt
----------------------------------------------------------------
Modified: trunk/Master/texmf-dist/doc/latex/spath3/README.txt
===================================================================
--- trunk/Master/texmf-dist/doc/latex/spath3/README.txt 2021-01-23 10:56:29 UTC (rev 57503)
+++ trunk/Master/texmf-dist/doc/latex/spath3/README.txt 2021-01-23 22:17:41 UTC (rev 57504)
@@ -1,6 +1,6 @@
----------------------------------------------------------------
spath3 --- LaTeX3 functions for manipulating PGF soft paths
-E-mail: stacey at math.ntnu.no
+E-mail: loopspace at mathforge.org
Released under the LaTeX Project Public License v1.3c or later
See http://www.latex-project.org/lppl.txt
----------------------------------------------------------------
Added: trunk/Master/texmf-dist/doc/latex/spath3/calligraphy.pdf
===================================================================
(Binary files differ)
Index: trunk/Master/texmf-dist/doc/latex/spath3/calligraphy.pdf
===================================================================
--- trunk/Master/texmf-dist/doc/latex/spath3/calligraphy.pdf 2021-01-23 10:56:29 UTC (rev 57503)
+++ trunk/Master/texmf-dist/doc/latex/spath3/calligraphy.pdf 2021-01-23 22:17:41 UTC (rev 57504)
Property changes on: trunk/Master/texmf-dist/doc/latex/spath3/calligraphy.pdf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/pdf
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/spath3/calligraphy.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/spath3/calligraphy.tex (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/spath3/calligraphy.tex 2021-01-23 22:17:41 UTC (rev 57504)
@@ -0,0 +1,271 @@
+\immediate\write18{tex spath3_doc.dtx}
+\documentclass{ltxdoc}
+\usepackage[T1]{fontenc}
+\usepackage{trace}
+\usepackage{lmodern}
+\usepackage{morefloats}
+\usepackage{tikz}
+\usetikzlibrary{decorations.pathreplacing,calligraphy,matrix}
+\usepackage[numbered]{hypdoc}
+\definecolor{lstbgcolor}{rgb}{0.9,0.9,0.9}
+
+\usepackage{listings}
+\lstloadlanguages{[LaTeX]TeX}
+\lstset{
+ breakatwhitespace=true,
+ breaklines=true,
+ language=[LaTeX]TeX,
+ basicstyle=\small\ttfamily,
+ keepspaces=true,
+ columns=fullflexible
+}
+
+\usepackage{fancyvrb}
+
+\newenvironment{example}
+ {\VerbatimEnvironment
+ \begin{VerbatimOut}{example.out}}
+ {\end{VerbatimOut}
+ \begin{center}
+ \setlength{\parindent}{0pt}
+ \fbox{\begin{minipage}{.9\linewidth}
+ \lstinputlisting[]{example.out}
+ \end{minipage}}
+
+ \fbox{\begin{minipage}{.9\linewidth}
+ \input{example.out}
+ \end{minipage}}
+\end{center}
+}
+
+\providecommand*{\url}{\texttt}
+\GetFileInfo{spath3.sty}
+
+\title{The \textsf{calligraphy} Package: Documentation}
+\author{Andrew Stacey \\ \url{loopspace at mathforge.org}}
+\date{\fileversion~from \filedate}
+
+\begin{document}
+
+\maketitle
+
+ \section{Pre-Introduction}
+ This library is built on top of a package for manipulating PGF's \emph{soft paths} called \texttt{spath3}.
+ Version 2.0 of \texttt{spath3} involved considerable reorganisation of the code.
+ I tried to ensure that this didn't affect this library but it is extremely likely that I wasn't fully successful.
+ If something that used to work no longer does, please do let me know either by opening an issue on github (\url{https://github.com/loopspace/spath3}) or at the above email.
+
+ \section{Introduction}
+The \Verb+calligraphy+ TikZ library is designed to enable calligraphic style drawings in TikZ.
+The idea is to be able to ``stroke'' a line with a ``pen''.
+As a simple example, compare the two lines in the following picture.
+
+\begin{example}
+\begin{center}
+\begin{tikzpicture}
+\pen (-135:.25) -- (45:.25);
+\draw[line width=.5cm] (0,0) .. controls +(45:1) and +(-135:1) .. ++(3,0);
+\calligraphy (0,-1) .. controls +(45:1) and +(-135:1) .. ++(3,0);
+\end{tikzpicture}
+\end{center}
+\end{example}
+
+The paths are identical in definition but the first is drawn using the standard TikZ path with a line width of .5cm.
+The second is ``stroked'' with a calligraphic pen of width .5cm angled at 45 degrees.
+\section{How It Works}
+To know how to use this library, it is worth knowing a little about how it works.
+A ``pen'' is a path, as is the line that is the template for the pen stroke.
+The two paths are joined together to form a region which is filled.
+Thus in constructing the example given in the introduction, the following path is built.
+\begin{center}
+\begin{tikzpicture}
+\draw (0,-1) .. controls +(45:1) and +(-135:1) .. node (op) {} ++(3,0) -- node (pp) {} ++(45:.5) .. controls +(-135:1) and +(45:1) .. node (opr) {} ++(-3,0) -- node (ppr) {} (0,-1);
+\draw[<-] (op) -- ++(0,-.5) node[anchor=north] {original path};
+\draw[<-] (pp) -- ++(.5,0) node[anchor=west] {pen path};
+\draw[<-] (opr) -- ++(0,.5) node[anchor=south] {original path reversed};
+\draw[<-] (ppr) -- ++(-.5,0) node[anchor=east] {pen path reversed};
+\end{tikzpicture}
+\end{center}
+What is important to note about this is that the ``pen'' isn't \emph{actually} dragged along the path, it is merely a simulation.
+This can be shown with the following simple example.
+The first is a continuous path that goes past the angle of the pen and thus the upstroke would involve pushing the pen.
+The second is how it is meant to be done, the second line is drawn from top to bottom.
+However, as the direction of the path isn't important, the same effect can be obtained by ``lifting the nib'' between the lines.
+\begin{example}
+\begin{center}
+\begin{tikzpicture}
+\pen (-135:.125) -- (45:.125);
+\calligraphy (0,0) -- (1,0) -- (1,1);
+\calligraphy (2,0) -- (3,0) (3,1) -- (3,0);
+\calligraphy (4,0) -- (5,0) +(0,0) -- (5,1);
+\end{tikzpicture}
+\end{center}
+\end{example}
+It should work as expected providing the following golden rule is not violated:
+\begin{quotation}
+Never \emph{push} a calligraphic pen.
+\end{quotation}
+This is good advice for ordinary calligraphy as well, so a path that is realisable as an honest calligraphic path should be fine with this library.
+Actually since, as remarked above, the direction of the path isn't important, a more accurate golden rule would be that one should never swap from pushing to pulling or vice versa without lifting the pen off the paper; but that isn't as succinct.
+The paths for both pens and templates can be reasonably complicated.
+They can contain gaps, but should not contain closed paths, nor rectangles.
+The implementation works by breaking a path into its constituent pieces (broken up by ``move to''s) and working bit by bit.
+\begin{example}
+\begin{center}
+\begin{tikzpicture}
+\pen (-135:.25) -- (-135:.125) (45:.125) -- (45:.25);
+\calligraphy (0,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-4) (0,-4) .. controls +(45:1) and +(-135:1) .. +(3,0);
+\end{tikzpicture}
+\end{center}
+\end{example}
+\section{Copperplate}
+Copperplate pens are somewhat special.
+They are ``thin'' so don't need the same treatment as a ``thick'' pen, but one should be able to vary the pressure with a copperplate pen to get a variation of thickness.
+Specifying a copperplate pen is straightforward: it is a pen with no thickness.
+\begin{example}
+\begin{center}
+\begin{tikzpicture}[line width=2pt]
+\pen (0,0);
+\calligraphy[heavy] (0,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (0,-3) .. controls +(45:1) and +(-135:1) .. +(3,0);
+\calligraphy[light] (4,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (4,-3) .. controls +(45:1) and +(-135:1) .. +(3,0);
+\end{tikzpicture}
+\end{center}
+\end{example}
+With a copperplate pen, the segments of a path are tapered.
+Copperplate and normal pens can be mixed.
+Any part of the pen specification that has no length is treated as a copperplate pen.
+\begin{example}
+\begin{center}
+\begin{tikzpicture}[line width=1pt]
+\pen (-135:.125) -- (0,0) (45:.125);
+\calligraphy (0,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (0,-3) .. controls +(45:1) and +(-135:1) .. +(3,0);
+\end{tikzpicture}
+\end{center}
+\end{example}
+%% \section{Annotations}
+%% As an addition, calligraphic paths can be annotated to show how they were constructed.
+%% A path with an arrow is drawn at a set offset from the last part of the path.
+%% \begin{example}
+%% \begin{center}
+%% \begin{tikzpicture}[line width=1pt]
+%% \pen (-135:.125) -- (0,0) (45:.125);
+%% \calligraphy[annotate] (0,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (0,-3) .. controls +(45:1) and +(-135:1) .. +(3,0);
+%% \end{tikzpicture}
+%% \end{center}
+%% \end{example}
+\section{Style Options}
+There are plenty of options for styling the paths and pens.
+\subsection{Definition Options}
+Internally, making a pen is a two-step process.
+First a pen has to be \emph{defined} and then \emph{processed}.
+To define a pen, the user has to specify a path.
+That path is stored in a global macro and so can be accessed in throughout the document.
+However, before being used, the pen has to be processed.
+At this stage, the pen is converted from a macro in to a special object.
+These special objects are local and cannot (at present) be made global.
+Thus whilst a pen can be \emph{defined} inside a group, the \emph{processing} stage has to happen in the outermost group in which the pen is going to be used.
+There is a shortcut command that (via a bit of suspicious hackery) does all this within a \Verb+tikzpicture+ group.
+However, if a pen is to be used in several different pictures, it must be processed outside the group in which it is defined.
+The following macros and keys are used to set up and use a pen.
+%All the keys are in the \Verb+/pgf/calligraphy+ family.
+\begin{itemize}
+\item \DescribeMacro{define pen}If the \Verb+define pen+ key is specified on a path then that path will be used to define a pen.
+It can take one option which will be the pen name, if not specified then \Verb+default+ is assumed.
+The resulting path will not be counted for bounding box considerations.
+When the pen is used, the origin will correspond to the path along which it is dragged.
+\item \DescribeMacro{pen name}The key \Verb+pen name=name+ sets the name for the current pen.
+This can be used either when defining or using a pen.
+\item \DescribeMacro{\pen}\DescribeMacro{\definepen}The macros \Verb+\pen+ and \Verb+\definepen+ are analogous to the TikZ commands \Verb+\draw+ or \Verb+\fill+ in that they act like a path command but store the path as a pen.
+The difference between them is that \Verb+\definepen+ is to be used outside a TikZ picture (it contains its own \Verb+\tikz+ command) and \Verb+\pen+ inside.
+%% These macros also change the ``key family'' to \Verb+/pgf/calligraphy+ so that any further options do not need their full path.
+%% \item \DescribeMacro{\processpen}The macro \Verb+\processpen+ processes a pen so that it is set up for using later on.
+%% As remarked earlier, it has to be given at least at the outermost grouping of where it will be used.
+%% It takes an optional argument which is the pen name.
+%% This is only needed if the pen will be used in a group other than the one in which it is defined (or if the hackery that means this isn't needed with the \Verb+\pen+ command fails for some unknown reason).
+\item \DescribeMacro{use pen}The key \Verb+use pen=name+ on a path means that that path should be ``stroked'' with the pen (\Verb+default+ if no name is given, or none specified via the \Verb+pen name+ key).
+%% \item \DescribeMacro{\calligraphy}The macro \Verb+\calligraphy+ is a shortcut for specifying a path with the key \Verb+use pen+ already set.
+%% This macro also changes the ``key family'' to \Verb+/pgf/calligraphy+ so that any further options do not need their full path.
+\end{itemize}
+\subsection{Style Options}
+There are various options available for styling the calligraphic paths.
+%% All of these are in the \Verb+/pgf/calligraphy+ key family, but the \Verb+\calligraphy+ command automatically switches to that family so the key path is not needed.
+%% Any unknown keys are processed as follows:
+%% \begin{enumerate}
+%% \item A check is made to see if a pen of that name has been defined.
+%% If so, that pen is used.
+%% This is similar to the \Verb+\node[shape]+ syntax
+%% \item A check is made to see if the unknown key corresponds to a colour.
+%% If so, that colour is installed as the pen colour.
+%% This is similar to the colour handling of TikZ paths.
+%% (In fact, it uses the same code.)
+%% \item All other unknown options are passed on to TikZ.
+%% \end{enumerate}
+The style options are as follows.
+\begin{itemize}
+\item \DescribeMacro{pen colour}The \Verb+pen colour+ style defines the default colour to be used.
+Since calligraphic paths are sometimes filled and sometimes stroked, this ensures that the colour is used correctly.
+\item \DescribeMacro{nib style}It is possible to style particular ``nibs'' (i.e., segments of the pen path) separately.
+This is the \Verb+nib style+ option, which takes two arguments.
+The first is the index of the part of the nib and the second is the style options to be applied.
+\item \DescribeMacro{stroke style}It is also possible to style particular parts of the template path.
+One way to do this is to use the \Verb+stroke style+ key, which takes two arguments.
+The first is the index of the part of the stroke and the second is the style options to be applied.
+\item \DescribeMacro{this stroke style}It is also possible to style particular parts of the template path as the path is constructed.
+This is done by putting \Verb+[this stroke style={}]+ in the template path at the relevant part.
+The style is saved and applied to that segment of the template path.
+\item \DescribeMacro{taper}The tapering of copperplate paths can be controled by the \Verb+taper+ option.
+It takes arguments \Verb+none+, \Verb+both+, \Verb+start+, and \Verb+end+.
+\item \DescribeMacro{weight}\DescribeMacro{heavy}\DescribeMacro{light}Copperplate paths come in two ``weights'': \emph{heavy} and \emph{light}.
+The weight also affects the tapering: by default a light path is tapered to nothing whilst a heavy path is tapered to the width of a light path.
+Weights can be specified by either \Verb+weight=weight+ or just \Verb+heavy+ and \Verb+light+.
+It is possible to change the weight for different components of a path using the \Verb+stroke style+ key.
+With tapering, this means that one can easily vary from a light stroke to a heavy one.
+The relevant widths are controlled by the keys \DescribeMacro{heavy line width}\Verb+heavy line width+ and the \DescribeMacro{light line width}\Verb+light line width+.
+The \DescribeMacro{taper line width}\Verb+taper line width+, is set automatically by the weight but can be altered afterwards using the \Verb+taper line width+ key.
+%% \item \DescribeMacro{annotate}The key \Verb+annotate+ switches on annotations.
+%% The style of the annotations is controlled by the keys \DescribeMacro{annotation style}\Verb+annotation style+, \DescribeMacro{annotation shift}\Verb+annotation shift+ which controls how the annotation path is shifted from the final component of the calligraphic path, \DescribeMacro{annotation nodes style}\Verb+annotation nodes style+ for global style of the nodes, \DescribeMacro{annotation node style}\Verb+annotation node style+ for styling of particular nodes.
+%% This latter takes two options: the node number and the style to be applied.
+%% The annotation path and annotation node styles take ordinary TikZ styling options.
+\end{itemize}
+\begin{example}
+\begin{center}
+\begin{tikzpicture}
+\calligraphy[pen colour=green,nib style={2}{color=red}] (0,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (0,-3) .. controls +(45:1) and +(-135:1) .. +(3,0);
+\calligraphy[line width=1pt] (0,-4) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (0,-7) .. controls +(45:1) and +(-135:1) .. +(3,0);
+\end{tikzpicture}
+\end{center}
+\end{example}
+\section{Decorations}
+If a TikZ/PGF decorations library is loaded prior to this library, then the \Verb+calligraphy+ library defines some decorations that use the calligraphic paths, specifically with the copperplate nib.
+The current decorations are:
+\begin{itemize}
+\item \DescribeMacro{calligraphic brace}\Verb+calligraphic brace+ for a brace.
+\item \DescribeMacro{calligraphic straight parenthesis}\Verb+calligraphic straight parenthesis+ for a parenthesis with straight middle component.
+\item \DescribeMacro{calligraphic curved parenthesis}\Verb+calligraphic curved parenthesis+ for a parenthesis with a curved middle component.
+\end{itemize}
+All the above use the \Verb+amplitude+ option to specify their size.
+The following is an example of their use, together with the standard \Verb+brace+ and the \Verb+delimiter+ key from the \Verb+matrix+ library for comparison.
+\begin{example}
+\begin{center}
+\begin{tikzpicture}
+\draw[decorate,decoration={calligraphic brace,amplitude=4mm},ultra thick] (0,0) -- (0,8);
+\draw[line width=2pt,decorate,decoration={brace,amplitude=10},line cap=round] (1,0) -- ++(0,8);
+\node[anchor=south west,minimum height=8cm,outer sep=0pt,left delimiter=\{] (a) at (2,0) {};
+\draw[decorate,decoration={calligraphic straight parenthesis,amplitude=4mm},ultra thick] (3,0) -- ++(0,8);
+\draw[decorate,decoration={calligraphic curved parenthesis,amplitude=4mm},ultra thick] (4,0) -- ++(0,8);
+\node[anchor=south west,minimum height=8cm,outer sep=0pt,left delimiter=(] (a) at (5,0) {};
+\end{tikzpicture}
+\end{center}
+\end{example}
+\section{Pre-Defined Pens}
+The following pens are predefined:
+\begin{itemize}
+\item \DescribeMacro{copperplate}\Verb+copperplate+:
+\begin{example}
+\begin{center}
+\tikz \calligraphy[copperplate] (0,0) .. controls +(1,-1) and +(-1,1) .. ++(3,0) [this stroke style={light,taper=start}] +(0,0) .. controls +(1,-1) and +(-1,1) .. ++(3,0) [this stroke style={heavy}] +(0,0) .. controls +(1,-1) and +(-1,1) .. ++(3,0) [this stroke style={light,taper=end}];
+\end{center}
+\end{example}
+\end{itemize}
+
+\end{document}
Property changes on: trunk/Master/texmf-dist/doc/latex/spath3/calligraphy.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Deleted: trunk/Master/texmf-dist/doc/latex/spath3/calligraphy_doc.pdf
===================================================================
(Binary files differ)
Deleted: trunk/Master/texmf-dist/doc/latex/spath3/calligraphy_doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/spath3/calligraphy_doc.tex 2021-01-23 10:56:29 UTC (rev 57503)
+++ trunk/Master/texmf-dist/doc/latex/spath3/calligraphy_doc.tex 2021-01-23 22:17:41 UTC (rev 57504)
@@ -1,258 +0,0 @@
-\immediate\write18{tex spath3.dtx}
-\documentclass{ltxdoc}
-\usepackage[T1]{fontenc}
-\usepackage{trace}
-\usepackage{lmodern}
-\usepackage{morefloats}
-\usepackage{tikz}
-\usetikzlibrary{decorations.pathreplacing,calligraphy,matrix}
-\usepackage[numbered]{hypdoc}
-\definecolor{lstbgcolor}{rgb}{0.9,0.9,0.9}
-
-\usepackage{listings}
-\lstloadlanguages{[LaTeX]TeX}
-\lstset{breakatwhitespace=true,breaklines=true,language=TeX}
-
-\usepackage{fancyvrb}
-
-\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}
- \input{example.out}
- \end{minipage}}
-\end{center}
-}
-
-\providecommand*{\url}{\texttt}
-\GetFileInfo{spath3.sty}
-
-\title{The \textsf{calligraphy} Package: Documentation}
-\author{Andrew Stacey \\ \url{stacey at math.ntnu.no}}
-\date{\fileversion~from \filedate}
-
-\begin{document}
-
-\maketitle
-% \section{Introduction}
-The \Verb+calligraphy+ TikZ library is designed to enable calligraphic style drawings in TikZ.
-The idea is to be able to ``stroke'' a line with a ``pen''.
-As a simple example, compare the two lines in the following picture.
-
-\begin{example}
-\begin{center}
-\begin{tikzpicture}
-\pen (-135:.25) -- (45:.25);
-\draw[line width=.5cm] (0,0) .. controls +(45:1) and +(-135:1) .. ++(3,0);
-\calligraphy (0,-1) .. controls +(45:1) and +(-135:1) .. ++(3,0);
-\end{tikzpicture}
-\end{center}
-\end{example}
-
-The paths are identical in definition but the first is drawn using the standard TikZ path with a line width of .5cm.
-The second is ``stroked'' with a calligraphic pen of width .5cm angled at 45 degrees.
-\section{How It Works}
-To know how to use this library, it is worth knowing a little about how it works.
-A ``pen'' is a path, as is the line that is the template for the pen stroke.
-The two paths are joined together to form a region which is filled.
-Thus in constructing the example given in the introduction, the following path is built.
-\begin{center}
-\begin{tikzpicture}
-\draw (0,-1) .. controls +(45:1) and +(-135:1) .. node (op) {} ++(3,0) -- node (pp) {} ++(45:.5) .. controls +(-135:1) and +(45:1) .. node (opr) {} ++(-3,0) -- node (ppr) {} (0,-1);
-\draw[<-] (op) -- ++(0,-.5) node[anchor=north] {original path};
-\draw[<-] (pp) -- ++(.5,0) node[anchor=west] {pen path};
-\draw[<-] (opr) -- ++(0,.5) node[anchor=south] {original path reversed};
-\draw[<-] (ppr) -- ++(-.5,0) node[anchor=east] {pen path reversed};
-\end{tikzpicture}
-\end{center}
-What is important to note about this is that the ``pen'' isn't \emph{actually} dragged along the path, it is merely a simulation.
-This can be shown with the following simple example.
-The first is a continuous path that goes past the angle of the pen and thus the upstroke would involve pushing the pen.
-The second is how it is meant to be done, the second line is drawn from top to bottom.
-However, as the direction of the path isn't important, the same effect can be obtained by ``lifting the nib'' between the lines.
-\begin{example}
-\begin{center}
-\begin{tikzpicture}
-\pen (-135:.125) -- (45:.125);
-\calligraphy (0,0) -- (1,0) -- (1,1);
-\calligraphy (2,0) -- (3,0) (3,1) -- (3,0);
-\calligraphy (4,0) -- (5,0) +(0,0) -- (5,1);
-\end{tikzpicture}
-\end{center}
-\end{example}
-It should work as expected providing the following golden rule is not violated:
-\begin{quotation}
-Never \emph{push} a calligraphic pen.
-\end{quotation}
-This is good advice for ordinary calligraphy as well, so a path that is realisable as an honest calligraphic path should be fine with this library.
-Actually since, as remarked above, the direction of the path isn't important, a more accurate golden rule would be that one should never swap from pushing to pulling or vice versa without lifting the pen off the paper; but that isn't as succinct.
-The paths for both pens and templates can be reasonably complicated.
-They can contain gaps, but should not contain closed paths, nor rectangles.
-The implementation works by breaking a path into its constituent pieces (broken up by ``move to''s) and working bit by bit.
-\begin{example}
-\begin{center}
-\begin{tikzpicture}
-\pen (-135:.25) -- (-135:.125) (45:.125) -- (45:.25);
-\calligraphy (0,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-4) (0,-4) .. controls +(45:1) and +(-135:1) .. +(3,0);
-\end{tikzpicture}
-\end{center}
-\end{example}
-\section{Copperplate}
-Copperplate pens are somewhat special.
-They are ``thin'' so don't need the same treatment as a ``thick'' pen, but one should be able to vary the pressure with a copperplate pen to get a variation of thickness.
-Specifying a copperplate pen is straightforward: it is a pen with no thickness.
-\begin{example}
-\begin{center}
-\begin{tikzpicture}[line width=2pt]
-\pen (0,0);
-\calligraphy[heavy] (0,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (0,-3) .. controls +(45:1) and +(-135:1) .. +(3,0);
-\calligraphy[light] (4,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (4,-3) .. controls +(45:1) and +(-135:1) .. +(3,0);
-\end{tikzpicture}
-\end{center}
-\end{example}
-With a copperplate pen, the segments of a path are tapered.
-Copperplate and normal pens can be mixed.
-Any part of the pen specification that has no length is treated as a copperplate pen.
-\begin{example}
-\begin{center}
-\begin{tikzpicture}[line width=1pt]
-\pen (-135:.125) -- (0,0) (45:.125);
-\calligraphy (0,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (0,-3) .. controls +(45:1) and +(-135:1) .. +(3,0);
-\end{tikzpicture}
-\end{center}
-\end{example}
-%% \section{Annotations}
-%% As an addition, calligraphic paths can be annotated to show how they were constructed.
-%% A path with an arrow is drawn at a set offset from the last part of the path.
-%% \begin{example}
-%% \begin{center}
-%% \begin{tikzpicture}[line width=1pt]
-%% \pen (-135:.125) -- (0,0) (45:.125);
-%% \calligraphy[annotate] (0,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (0,-3) .. controls +(45:1) and +(-135:1) .. +(3,0);
-%% \end{tikzpicture}
-%% \end{center}
-%% \end{example}
-\section{Style Options}
-There are plenty of options for styling the paths and pens.
-\subsection{Definition Options}
-Internally, making a pen is a two-step process.
-First a pen has to be \emph{defined} and then \emph{processed}.
-To define a pen, the user has to specify a path.
-That path is stored in a global macro and so can be accessed in throughout the document.
-However, before being used, the pen has to be processed.
-At this stage, the pen is converted from a macro in to a special object.
-These special objects are local and cannot (at present) be made global.
-Thus whilst a pen can be \emph{defined} inside a group, the \emph{processing} stage has to happen in the outermost group in which the pen is going to be used.
-There is a shortcut command that (via a bit of suspicious hackery) does all this within a \Verb+tikzpicture+ group.
-However, if a pen is to be used in several different pictures, it must be processed outside the group in which it is defined.
-The following macros and keys are used to set up and use a pen.
-%All the keys are in the \Verb+/pgf/calligraphy+ family.
-\begin{itemize}
-\item \DescribeMacro{define pen}If the \Verb+define pen+ key is specified on a path then that path will be used to define a pen.
-It can take one option which will be the pen name, if not specified then \Verb+default+ is assumed.
-The resulting path will not be counted for bounding box considerations.
-When the pen is used, the origin will correspond to the path along which it is dragged.
-\item \DescribeMacro{pen name}The key \Verb+pen name=name+ sets the name for the current pen.
-This can be used either when defining or using a pen.
-\item \DescribeMacro{\pen}\DescribeMacro{\definepen}The macros \Verb+\pen+ and \Verb+\definepen+ are analogous to the TikZ commands \Verb+\draw+ or \Verb+\fill+ in that they act like a path command but store the path as a pen.
-The difference between them is that \Verb+\definepen+ is to be used outside a TikZ picture (it contains its own \Verb+\tikz+ command) and \Verb+\pen+ inside.
-%% These macros also change the ``key family'' to \Verb+/pgf/calligraphy+ so that any further options do not need their full path.
-%% \item \DescribeMacro{\processpen}The macro \Verb+\processpen+ processes a pen so that it is set up for using later on.
-%% As remarked earlier, it has to be given at least at the outermost grouping of where it will be used.
-%% It takes an optional argument which is the pen name.
-%% This is only needed if the pen will be used in a group other than the one in which it is defined (or if the hackery that means this isn't needed with the \Verb+\pen+ command fails for some unknown reason).
-\item \DescribeMacro{use pen}The key \Verb+use pen=name+ on a path means that that path should be ``stroked'' with the pen (\Verb+default+ if no name is given, or none specified via the \Verb+pen name+ key).
-%% \item \DescribeMacro{\calligraphy}The macro \Verb+\calligraphy+ is a shortcut for specifying a path with the key \Verb+use pen+ already set.
-%% This macro also changes the ``key family'' to \Verb+/pgf/calligraphy+ so that any further options do not need their full path.
-\end{itemize}
-\subsection{Style Options}
-There are various options available for styling the calligraphic paths.
-%% All of these are in the \Verb+/pgf/calligraphy+ key family, but the \Verb+\calligraphy+ command automatically switches to that family so the key path is not needed.
-%% Any unknown keys are processed as follows:
-%% \begin{enumerate}
-%% \item A check is made to see if a pen of that name has been defined.
-%% If so, that pen is used.
-%% This is similar to the \Verb+\node[shape]+ syntax
-%% \item A check is made to see if the unknown key corresponds to a colour.
-%% If so, that colour is installed as the pen colour.
-%% This is similar to the colour handling of TikZ paths.
-%% (In fact, it uses the same code.)
-%% \item All other unknown options are passed on to TikZ.
-%% \end{enumerate}
-The style options are as follows.
-\begin{itemize}
-\item \DescribeMacro{pen colour}The \Verb+pen colour+ style defines the default colour to be used.
-Since calligraphic paths are sometimes filled and sometimes stroked, this ensures that the colour is used correctly.
-\item \DescribeMacro{nib style}It is possible to style particular ``nibs'' (i.e., segments of the pen path) separately.
-This is the \Verb+nib style+ option, which takes two arguments.
-The first is the index of the part of the nib and the second is the style options to be applied.
-\item \DescribeMacro{stroke style}It is also possible to style particular parts of the template path.
-One way to do this is to use the \Verb+stroke style+ key, which takes two arguments.
-The first is the index of the part of the stroke and the second is the style options to be applied.
-\item \DescribeMacro{this stroke style}It is also possible to style particular parts of the template path as the path is constructed.
-This is done by putting \Verb+[this stroke style={}]+ in the template path at the relevant part.
-The style is saved and applied to that segment of the template path.
-\item \DescribeMacro{taper}The tapering of copperplate paths can be controled by the \Verb+taper+ option.
-It takes arguments \Verb+none+, \Verb+both+, \Verb+start+, and \Verb+end+.
-\item \DescribeMacro{weight}\DescribeMacro{heavy}\DescribeMacro{light}Copperplate paths come in two ``weights'': \emph{heavy} and \emph{light}.
-The weight also affects the tapering: by default a light path is tapered to nothing whilst a heavy path is tapered to the width of a light path.
-Weights can be specified by either \Verb+weight=weight+ or just \Verb+heavy+ and \Verb+light+.
-It is possible to change the weight for different components of a path using the \Verb+stroke style+ key.
-With tapering, this means that one can easily vary from a light stroke to a heavy one.
-The relevant widths are controlled by the keys \DescribeMacro{heavy line width}\Verb+heavy line width+ and the \DescribeMacro{light line width}\Verb+light line width+.
-The \DescribeMacro{taper line width}\Verb+taper line width+, is set automatically by the weight but can be altered afterwards using the \Verb+taper line width+ key.
-%% \item \DescribeMacro{annotate}The key \Verb+annotate+ switches on annotations.
-%% The style of the annotations is controlled by the keys \DescribeMacro{annotation style}\Verb+annotation style+, \DescribeMacro{annotation shift}\Verb+annotation shift+ which controls how the annotation path is shifted from the final component of the calligraphic path, \DescribeMacro{annotation nodes style}\Verb+annotation nodes style+ for global style of the nodes, \DescribeMacro{annotation node style}\Verb+annotation node style+ for styling of particular nodes.
-%% This latter takes two options: the node number and the style to be applied.
-%% The annotation path and annotation node styles take ordinary TikZ styling options.
-\end{itemize}
-\begin{example}
-\begin{center}
-\begin{tikzpicture}
-\calligraphy[pen colour=green,nib style={2}{color=red}] (0,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (0,-3) .. controls +(45:1) and +(-135:1) .. +(3,0);
-\calligraphy[line width=1pt] (0,-4) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (0,-7) .. controls +(45:1) and +(-135:1) .. +(3,0);
-\end{tikzpicture}
-\end{center}
-\end{example}
-\section{Decorations}
-If a TikZ/PGF decorations library is loaded prior to this library, then the \Verb+calligraphy+ library defines some decorations that use the calligraphic paths, specifically with the copperplate nib.
-The current decorations are:
-\begin{itemize}
-\item \DescribeMacro{calligraphic brace}\Verb+calligraphic brace+ for a brace.
-\item \DescribeMacro{calligraphic straight parenthesis}\Verb+calligraphic straight parenthesis+ for a parenthesis with straight middle component.
-\item \DescribeMacro{calligraphic curved parenthesis}\Verb+calligraphic curved parenthesis+ for a parenthesis with a curved middle component.
-\end{itemize}
-All the above use the \Verb+amplitude+ option to specify their size.
-The following is an example of their use, together with the standard \Verb+brace+ and the \Verb+delimiter+ key from the \Verb+matrix+ library for comparison.
-\begin{example}
-\begin{center}
-\begin{tikzpicture}
-\draw[decorate,decoration={calligraphic brace,amplitude=4mm},ultra thick] (0,0) -- (0,8);
-\draw[line width=2pt,decorate,decoration={brace,amplitude=10},line cap=round] (1,0) -- ++(0,8);
-\node[anchor=south west,minimum height=8cm,outer sep=0pt,left delimiter=\{] (a) at (2,0) {};
-\draw[decorate,decoration={calligraphic straight parenthesis,amplitude=4mm},ultra thick] (3,0) -- ++(0,8);
-\draw[decorate,decoration={calligraphic curved parenthesis,amplitude=4mm},ultra thick] (4,0) -- ++(0,8);
-\node[anchor=south west,minimum height=8cm,outer sep=0pt,left delimiter=(] (a) at (5,0) {};
-\end{tikzpicture}
-\end{center}
-\end{example}
-\section{Pre-Defined Pens}
-The following pens are predefined:
-\begin{itemize}
-\item \DescribeMacro{copperplate}\Verb+copperplate+:
-\begin{example}
-\begin{center}
-\tikz \calligraphy[copperplate] (0,0) .. controls +(1,-1) and +(-1,1) .. ++(3,0) [this stroke style={light,taper=start}] +(0,0) .. controls +(1,-1) and +(-1,1) .. ++(3,0) [this stroke style={heavy}] +(0,0) .. controls +(1,-1) and +(-1,1) .. ++(3,0) [this stroke style={light,taper=end}];
-\end{center}
-\end{example}
-\end{itemize}
-
-\end{document}
\ No newline at end of file
Added: trunk/Master/texmf-dist/doc/latex/spath3/knots.pdf
===================================================================
(Binary files differ)
Index: trunk/Master/texmf-dist/doc/latex/spath3/knots.pdf
===================================================================
--- trunk/Master/texmf-dist/doc/latex/spath3/knots.pdf 2021-01-23 10:56:29 UTC (rev 57503)
+++ trunk/Master/texmf-dist/doc/latex/spath3/knots.pdf 2021-01-23 22:17:41 UTC (rev 57504)
Property changes on: trunk/Master/texmf-dist/doc/latex/spath3/knots.pdf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/pdf
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/spath3/knots.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/spath3/knots.tex (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/spath3/knots.tex 2021-01-23 22:17:41 UTC (rev 57504)
@@ -0,0 +1,516 @@
+\immediate\write18{tex spath3_code.dtx}
+\documentclass{ltxdoc}
+\usepackage[T1]{fontenc}
+\usepackage{trace}
+\usepackage{lmodern}
+\usepackage{morefloats}
+\usepackage{tikz}
+\usetikzlibrary{knots,spath3,hobby}
+\usepackage[numbered]{hypdoc}
+\definecolor{lstbgcolor}{rgb}{0.9,0.9,0.9}
+
+\usepackage{listings}
+\lstloadlanguages{[LaTeX]TeX}
+\lstset{
+ breakatwhitespace=true,
+ breaklines=true,
+ language=[LaTeX]TeX,
+ basicstyle=\small\ttfamily,
+ keepspaces=true,
+ columns=fullflexible
+}
+
+\usepackage{fancyvrb}
+
+\newenvironment{example}
+ {\VerbatimEnvironment
+ \begin{VerbatimOut}{example.out}}
+ {\end{VerbatimOut}
+ \begin{center}
+ \setlength{\parindent}{0pt}
+ \fbox{\begin{minipage}{.9\linewidth}
+ \lstinputlisting[]{example.out}
+ \end{minipage}}
+
+ \fbox{\begin{minipage}{.9\linewidth}
+ \centering
+ \input{example.out}
+ \end{minipage}}
+\end{center}
+}
+
+\providecommand*{\url}{\texttt}
+\GetFileInfo{spath3.sty}
+
+\title{The \textsf{knots} Package: Documentation}
+\author{Andrew Stacey \\ \url{loopspace at mathforge.org}}
+\date{\fileversion~from \filedate}
+
+\begin{document}
+
+\maketitle
+
+\section{Pre-Introduction}
+
+This library is built on top of a package for manipulating PGF's \emph{soft paths} called \texttt{spath3}.
+ Version 2.0 of \texttt{spath3} involved considerable reorganisation of the code.
+ I tried to ensure that this didn't affect this library but it is extremely likely that I wasn't fully successful.
+ If something that used to work no longer does, please do let me know either by opening an issue on github (\url{https://github.com/loopspace/spath3}) or at the above email.
+
+ That version of \texttt{spath3} also introduced an alternative way of drawing knots which involves breaking the paths at their crossing points and introducing actual gaps.
+ This makes it easier to do things like have the knots on non-uniform backgrounds, and to style different parts of the knot differently such as illustrating a \(3\)--colouring.
+ To see how that works, look at the documentation of the \texttt{spath3} TikZ library.
+ Here's an example of how to draw a knot with that library.
+
+ \begin{example}
+\begin{tikzpicture}[
+ use Hobby shortcut,
+ every trefoil component/.style={ultra thick, draw},
+ trefoil component 1/.style={red},
+ trefoil component 2/.style={blue},
+ trefoil component 3/.style={green},
+]
+\path[spath/save=trefoil] ([closed]90:2) foreach \k in {1,...,3} { .. (-30+\k*240:.5) .. (90+\k*240:2) } (90:2);
+\tikzset{spath/knot={trefoil}{8pt}{1,3,5}}
+\end{tikzpicture}
+\end{example}
+
+
+\section{Introduction}
+
+The \Verb+knots+ package is a TikZ library for drawing knot (and similar) diagrams.
+It provides a few useful styles and node shapes but its main contribution is the \Verb+knot+ environment.
+The \Verb+knot+ environment allows you to draw some strands of a knot (or braid or tangle or whatever -- we shall use the imprecise term ``knot'' to refer to any similar diagram) and then to modify the crossings via a simple interface.
+
+The main part of this package was developed in response to a question on the \href{http://tex.stackexchange.com}{TeX-SX} site by Jamie Vicary.
+The original question was \href{http://tex.stackexchange.com/q/32125/86}{Braid diagrams in TikZ}.
+Jamie's comment (quoted below) was the inspiration for the mechanism of the \Verb+knot+ environment.
+
+\begin{quotation}
+[It] would be really cool if it was possible to draw the curves, let TikZ calculate all the intersection points automatically, and then tell it to redraw the intersections according to an under/over specification... do you think this is in the realm of plausibility?
+\end{quotation}
+
+\section{Examples}
+
+Let us begin with an example.
+To use the library, simply load the \Verb+tikz+ package and add \Verb+knots+ to the list of TikZ libraries that you load.
+For example, the following in your preamble would work:
+
+\begin{verbatim}
+\usepackage{tikz}
+\usetikzlibrary{knots}
+\end{verbatim}
+
+Let's draw a simple tangle (actually a braid).
+
+\begin{example}
+\begin{tikzpicture}
+\draw[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
+\draw[blue,ultra thick] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
+\end{tikzpicture}
+\end{example}
+
+Now a common way to draw crossings for knots is to draw a gap in the under strand through which the over strand passes.
+One way to achieve this in TikZ is to draw the over strand twice, the first time with a thicker line width and the colour of the background.
+We'll draw it twice, once with background a different colour to illustrate this.
+
+\begin{example}
+\begin{tikzpicture}
+\draw[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
+\draw[pink,double=blue,ultra thick,double distance=1.6pt] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
+\draw[xshift=5cm,red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
+\draw[xshift=5cm,white,double=blue,ultra thick,double distance=1.6pt] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
+\end{tikzpicture}
+\end{example}
+
+Now the problem with this method is that there is no way to draw the red and blue paths so that the blue is the over strand at the first crossing and the red at the second.
+Either the blue path is always on top (as shown) or the red.
+One way to resolve this is to split the paths and draw one of them in segments:
+
+\begin{example}
+\begin{tikzpicture}
+\draw[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1);
+\draw[white,double=blue,ultra thick,double distance=1.6pt] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
+\draw[white,double=red,double distance=1.6pt,ultra thick] (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
+\end{tikzpicture}
+\end{example}
+
+Another method (employed by the \Verb+braids+ package) is to break the under path either side of the crossing and not draw it there.
+This means that the order of drawing doesn't matter.
+
+Both of these methods have their drawbacks (particularly for general knots as opposed to the more structured braids) in that they require a detailed knowledge of the pieces of the paths and the positions of the crossings.
+As pointed out by Jamie Vicary in the above-{}quoted comment, TikZ should be able to compute these itself.
+
+That's what this package does.
+
+Let's do the above example using this package.
+The main changes to the drawing are that we use the command \Verb+\strand+ rather than \Verb+\draw+ and we enclose it in the \Verb+knot+ environment.
+When initially drawing the strands it is useful to provide the option \Verb+draft mode=strands+.
+That's because the detailed computation can take a little time and so it is best only to do it when necessary.
+So on first run through we get the following.
+
+\begin{example}
+\begin{tikzpicture}
+\begin{knot}[
+ draft mode=strands
+]
+\strand[red,thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
+\strand[blue,thick] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
+\end{knot}
+\end{tikzpicture}
+\end{example}
+
+Once we're happy with the positioning of the strands, we change the option \Verb+draft mode=strands+ to \Verb+draft mode=crossings+.
+
+\begin{example}
+\begin{tikzpicture}
+\path (2,1.5) (2,-.5);
+\begin{knot}[
+ draft mode=crossings,
+ clip width=5,
+]
+\strand[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
+\strand[blue,ultra thick] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
+\end{knot}
+\end{tikzpicture}
+\end{example}
+
+The \Verb+\path (2,1.5) (2,-.5);+ is to extend the bounding box of the picture a little upwards.
+The extra pieces are not used when computing the bounding box of the picture so that it doesn't change position on the page.
+
+The extra information is that the strands and the crossings have been numbered.
+The crossings have also been rendered (the \Verb+clip width+ option enlarges the crossing gap to make it more obvious).
+Unfortunately, for both crossings the red path is on top.
+We need to flip one of these crossings (the first).
+To do this, we either use the command \Verb+flipcrossings+ or the \Verb+flip crossing+ key.
+
+\begin{example}
+\begin{tikzpicture}
+\path (2,1.5) (2,-.5);
+\begin{knot}[
+ draft mode=crossings,
+ clip width=5,
+ flip crossing=1,
+]
+\strand[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
+\strand[blue,ultra thick] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
+\end{knot}
+\end{tikzpicture}
+\end{example}
+
+Once we're happy with it, we remove the \Verb+draft mode+ option to render it in its final form.
+
+\begin{example}
+\begin{tikzpicture}
+\begin{knot}[
+ clip width=5,
+ flip crossing=1,
+]
+\strand[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
+\strand[blue,ultra thick] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
+\end{knot}
+\end{tikzpicture}
+\end{example}
+
+Here's a more complicated example.
+
+\begin{example}
+\begin{tikzpicture}
+\node (A) at (0,4) [draw,minimum width=30pt,minimum height=10pt,thick] {};
+\begin{knot}[
+ clip width=5,
+ clip radius=8pt,
+]
+\strand [thick,only when rendering/.style={dashed}] (0,0)
+to [out=up, in=down] (-1,1)
+to [out=up, in=down] (0,2)
+to [out=up, in=down] (-1.2,4)
+to [out=up, in=down, looseness=0.7] (0,5.5)
+to [out=up, in=down] (-2,7);
+\strand [thick] (-1,0)
+to [out=up, in=down] (1,2)
+to [out=up, in=down] (A.south);
+\strand [thick,blue] (1,0)
+to [out=up, in=down] (-1,2)
+to [out=up, in=down] (1.5,4)
+to [out=up, in=right] (0,5.5)to [out=left, in=up] (-2,4)
+to [out=down, in=up] (-2,0);
+\strand [thick] (A.150)
+to [out=up, in=down] (0.7,5.5)
+to [out=up, in=down] (0,7);
+\strand [thick] (A.30)
+to [out=up, in=down] (-1,6)
+to [out=up, in=down] (2,7);
+\flipcrossings{6,2,9,5,11}
+\end{knot}
+\end{tikzpicture}
+\end{example}
+
+One feature about this example is the \Verb+only when rendering+ key.
+The gaps are made by drawing the strand again with extra thickness in the background colour.
+If the \Verb+dashed+ option were always in play for that strand, the gap would be dashed which would spoil the effect.
+So the \Verb+only when rendering+ key gathers those options (such as a dash pattern) which should only be applied to the rendered strand and not to the redraw that creates the gap.
+
+Here's another example.
+
+\begin{example}
+\newcommand{\motif}[1]{
+ to ++(180+#1:0.50) arc (270+#1:150+#1:0.15)
+ to ++( 60+#1:0.50) arc (-30+#1:150+#1:0.15)
+ to ++(240+#1:0.25) arc (150+#1:330+#1:0.25)
+ to ++( 60+#1:0.55) arc (150+#1: 30+#1:0.20)
+}
+\newcommand{\celticknot}{\motif{0}\motif{120}\motif{240}}
+\begin{tikzpicture}
+\begin{knot}[
+ line width=2pt,
+ line join=round,
+ clip width=2,
+ scale=5,
+ consider self intersections,
+ ignore endpoint intersections=false,
+ background color=white,
+ only when rendering/.style={
+ draw=red,
+ double=white,
+ double distance=6pt,
+ line cap=round,
+ }
+]
+\strand (0,0) \celticknot;
+\flipcrossings{1,3,6,8,10}
+\end{knot}
+\end{tikzpicture}
+\end{example}
+
+In this case the strand is a single path.
+In the standard case crossings are only considered between separate strands (since the algorithm used by TikZ means that a strand intersects itself infinitely often).
+The key \Verb+consider self intersections+ gets round this by ``exploding'' the strand into segments and considering each as a separate path with regard to finding the intersections.
+
+A path consists of a series of lines and B\'ezier cubics.
+The ``explosion'' of a path uses this decomposition.
+Unfortunately, even that is not always enough as it is possible for a B\'ezier cubic to self-intersect.
+The \Verb+consider self intersections+ also splits these B\'ezier curves in two to ensure that this doesn't happen\footnote{Computing when this is strictly necessary is difficult so it splits more than it needs to to ensure that enough are done.}.
+To disable this, use the \Verb+consider self intersections=no splits+ option.
+This is the recommended option.
+
+\begin{example}
+\begin{tikzpicture}
+\begin{knot}[
+ consider self intersections,
+ draft mode=crossings,
+]
+\strand (0,0) .. controls +(3,1) and +(-3,1) .. (1,0);
+\end{knot}
+\begin{knot}[
+ xshift=3cm,
+ consider self intersections=no splits,
+ draft mode=crossings,
+]
+\strand (0,0) .. controls +(3,1) and +(-3,1) .. (1,0);
+\end{knot}
+\end{tikzpicture}
+\end{example}
+
+Finally, given that TikZ has to do some heavy computation to find the intersections, it is worth considering using the \Verb+external+ library of TikZ to avoid having to do this on every run.
+
+\section{Usage}
+
+\subsection{The \texttt{knot} Environment}
+
+\DescribeMacro{knot}
+\DescribeMacro{\strand}
+This package provides a \Verb+knot+ environment for including in a \Verb+tikzpicture+ to render a knot.
+This takes an optional argument which is passed to \Verb+\tikzset+ and can be used to configure the knot.
+Within that environment, specific strands are defined using the \Verb+\strand+ command (in place of a \Verb+\path+ or \Verb+\draw+).
+Further keys can be specified on the strands.
+
+\DescribeMacro{flip crossing}
+\DescribeMacro{\flipcrossings}
+Specifying the crossings to be flipped can be done either using the key \Verb+flip crossing+ or the macro \Verb+\flipcrossings+.
+The latter can take a comma separated list of crossings to flip.
+The former takes a single crossing but can be extended to a comma separated list using the \Verb+.list+ handler as in \Verb+flip crossing/.list={1,2,3}+ (this is what \Verb+\flipcrossings+ does internally).
+
+\DescribeMacro{\redraw}
+There is also a macro \Verb+\redraw+ which redraws a strand in the neighbourhood of a point.
+This is effectively what happens for the crossings and can be used to fix something that wasn't done correctly by the main algorithm.
+It takes two arguments, the strand number and the point at which to render the strand, as in \Verb+\redraw{2}{(1,1)}+.
+
+\subsection{Keys}
+
+The various keys are as follows.
+The majority of the keys are in the \Verb+/tikz/knot diagram+ family, but it does its best to pass unknown keys down to \Verb+/tikz/+.
+The keys processed by the \Verb+knot+ environment are automatically in this family but the keys processed by the \Verb+\strand+ command are not.
+If a standard key (in the option to the \Verb+knot+ environment) doesn't work, try prefixing it with \Verb+/tikz/+ or \Verb+/pgf/+.
+
+\begin{itemize}
+\item \DescribeMacro{every knot diagram}
+The style \Verb+every knot diagram+ is executed at the start of the \Verb+knot+ environment.
+
+Note that it is inside the \Verb+knot diagram+ family so if setting it outside (say, in the preamble) use \Verb+\tikzset{knot diagram/every knot diagram}+.
+
+\item \DescribeMacro{name}
+The crossings of a knot are given coordinates of the form \Verb+<name> <number>+.
+The default name is \Verb+knot+.
+The \Verb+name+ key renames it.
+
+\item \DescribeMacro{every strand}
+The contents of \Verb+every strand+ are applied to every strand.
+By default this contains the \Verb+draw+ key so if resetting it you should probably ensure that it still has the \Verb+draw+ key.
+
+Note that it is inside the \Verb+knot diagram+ family so if setting it outside (say, in the preamble) use \Verb+\tikzset{knot diagram/every knot diagram}+.
+
+\item \DescribeMacro{only when rendering}
+The key \Verb+only when rendering={<style>}+ is applied to the strand only when it is actually drawn and not when it is used to cut out part of the underlying path.
+
+Note that there are actually two versions of this key: one in the \Verb+knot diagram+ family and one in the \Verb+/tikz+ family.
+This is so that it works equally well in the argument to the \Verb+knot+ environment and the \Verb+\strand+ command.
+
+\item \DescribeMacro{ignore endpoint intersections}
+When a strand is split into pieces then the intersection library finds ``false positives'' in that neighbouring pieces intersect at their endpoints.
+The code ignores such intersections between neighbouring pieces.
+The \Verb+ignore endpoint intersections+ (which is true by default) means that all intersections that are near an endpoint are ignored whether or not they are with the next or previous piece of that strand.
+The celtic knot example of the previous section sets this to false to ensure that it gets all intersections.
+
+\item \DescribeMacro{consider self intersections}
+The key \Verb+consider self intersections=<option>+ handles the splitting facility so that strands can self intersect.
+The options are \Verb+true+, \Verb+false+, and \Verb+no splits+.
+It is \Verb+false+ at the start, and the default option is \Verb+true+.
+The difference between \Verb+true+ and \Verb+no splits+ is as to whether segments are further split to avoid \emph{all} self intersections.
+
+\item \DescribeMacro{clip radius}
+The \Verb+clip radius=<length>+ is the radius of the clip region around each crossing.
+
+\item \DescribeMacro{end tolerance}
+The \Verb+end tolerance=<length>+ is the distance at which an intersection is considered as being near an endpoint (for simplicity, it uses the \(\ell^1\)--metric).
+
+\item \DescribeMacro{clip width}
+The \Verb+clip width=<factor>+ is the multiplier for the thickness of the ``wipeout'' path relative to the line width of the actual path.
+
+\item \DescribeMacro{flip crossing}
+The \Verb+flip crossing=<number>+ key flips the \Verb+<number>+ crossing.
+
+\item \DescribeMacro{background colour} \DescribeMacro{background color}
+The keys \Verb+background colour=<colour>+ and \Verb+background color=<color>+ set the background colour for the crossings.
+
+\item \DescribeMacro{intersection <number>}
+The style in \Verb+intersection <number>+ is applied just before that crossing is drawn so can be used to modify the crossing style just for that crossing.
+
+
+\item \DescribeMacro{draft mode}
+The key \Verb+draft mode=<option>+ sets the different styles for aiding with rendering the knot.
+The options are \Verb+strands+, \Verb+crossings+, or \Verb+off+.
+The \Verb+strands+ option just renders the strands with no crossings.
+The \Verb+crossings+ option renders the crossings and labels the strands and crossings.
+The \Verb+off+ option renders the crossings without the labels.
+
+\item \DescribeMacro{draft/crossing label}
+The style \Verb+draft/crossing label+ is applied to each of the crossing labels.
+The labels are actually \Verb+pin+s attached to coordinates at the crossings.
+This style is applied to the \Verb+pin+ itself.
+The default is:
+
+\begin{lstlisting}
+overlay,
+fill=white,
+fill opacity=.5,
+text opacity=1,
+text=blue,
+pin edge={blue,<-}
+\end{lstlisting}
+
+\item \DescribeMacro{draft/strand label}
+The style \Verb+draft/strand label+ is applied to each of the strand labels.
+The default is:
+
+\begin{lstlisting}
+overlay,
+circle,
+draw=purple,
+fill=white,
+fill opacity=.5,
+text opacity=1,
+text=purple,
+inner sep=0pt
+\end{lstlisting}
+\end{itemize}
+
+\subsection{Other Styles}
+
+The other things defined by this package are for drawing knot diagrams when the user knows in advance either the locations of the crossings or can arrange that the paths are drawn in the correct order.
+In these circumstances the \Verb+knot+ environment is overkill.
+
+\DescribeMacro{knot}
+\DescribeMacro{knot gap}
+This \Verb+knot=<colour>+ style sets up a doubled path with inner colour the given colour (or the current draw colour if not given) and outer colour the knot background colour.
+The width of the inner line is the current line width and the full width is controlled by the \Verb+knot gap=<factor>+ key which is initially set to \(3\) (thus giving a line's width either side).
+
+\begin{example}
+\begin{tikzpicture}[knot gap=7]
+\draw[thin,knot=red] (-1,-1) -- (1,1);
+\draw[thin,knot=red] (-1,1) -- (1,-1);
+\begin{scope}[xshift=2.5cm]
+\draw[knot=red] (-1,-1) -- (1,1);
+\draw[knot=red] (-1,1) -- (1,-1);
+\end{scope}
+\begin{scope}[xshift=5cm]
+\draw[thick,knot=red] (-1,-1) -- (1,1);
+\draw[thick,knot=red] (-1,1) -- (1,-1);
+\end{scope}
+\end{tikzpicture}
+\end{example}
+
+\DescribeMacro{knot crossing}
+\DescribeMacro{knot over cross}
+\DescribeMacro{knot under cross}
+\DescribeMacro{knot horiz}
+\DescribeMacro{knot vert}
+This package also defines some node shapes to help draw knot and link diagrams.
+The idea with these is to place a node of the appropriate type at each crossing and then link them accordingly.
+The node shapes are \Verb+knot crossing+, \Verb+knot over cross+, \Verb+knot under cross+, \Verb+knot vert+, \Verb+knot horiz+.
+The two styles \Verb+knot over cross+ and \Verb+knot under cross+ are crossings, \Verb+knot vert+ and \Verb+knot horiz+ are for when resolving the crossings in a diagram.
+By judicious use of the \Verb+\foreach+ command, a family of resolved link diagrams can be produced.
+
+\begin{example}
+\begin{tikzpicture}[every node/.style={draw,red}]
+\node[knot over cross] at (1,0) {};
+\node[knot under cross] at (2,0) {};
+\node[knot vert] at (3,0) {};
+\node[knot horiz] at (4,0) {};
+\end{tikzpicture}
+\end{example}
+
+The node \Verb+knot crossing+ is not meant to be drawn, it is an empty shape.
+Its value is in that it defines more anchors than the usual rectangle shape.
+For each of the 8 main compass directions, it defines anchors at 2, 4, 8, 16, and 32 times further out.
+This can be useful for designing curves that enter and exit the crossing gracefully at particular directions.
+When using this node shape, the crossing itself is easiest to draw by using the \Verb+center+ anchor for the strands that form the over cross.
+
+\begin{example}
+\begin{tikzpicture}[every path/.style={red,thick}, every node/.style={transform shape, knot crossing, inner sep=1.5pt}]
+\node[rotate=45] (tl) at (-1,1) {};
+\node[rotate=-45] (tr) at (1,1) {};
+\node (m) at (0,-1) {};
+\node (b) at (0,-2) {};
+\draw (b) .. controls (b.4 north west) and (m.4 south west) .. (m.center);
+\draw (b.center) .. controls (b.4 north east) and (m.4 south east) .. (m);
+\draw (m) .. controls (m.8 north west) and (tl.3 south west) .. (tl.center);
+\draw (m.center) .. controls (m.8 north east) and (tr.3 south east) .. (tr);
+\draw (tl.center) .. controls (tl.16 north east) and (tr.16 north west) .. (tr);
+\draw (b) .. controls (b.16 south east) and (tr.16 north east) .. (tr.center);
+\draw (b.center) .. controls (b.16 south west) and (tl.16 north west) .. (tl);
+\draw (tl) -- (tr.center);
+\end{tikzpicture}
+\end{example}
+
+\section{Other Relevant Packages by the Same Author}
+
+Another tool for drawing knot diagrams is provided by the \Verb+hobby+ package which draws smooth curves through a prescribed set of points.
+This can be combined with the facilities of this package but also has some features of its own that make it suitable for drawing knot diagrams.
+
+For braids themselves, there is the \Verb+braids+ package which allows input specification in the form of a word in the braid group.
+
+\end{document}
+% Local Variables:
+% tex-output-type: "pdf18"
+% End:
Property changes on: trunk/Master/texmf-dist/doc/latex/spath3/knots.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Deleted: trunk/Master/texmf-dist/doc/latex/spath3/knots_doc.pdf
===================================================================
(Binary files differ)
Deleted: trunk/Master/texmf-dist/doc/latex/spath3/knots_doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/spath3/knots_doc.tex 2021-01-23 10:56:29 UTC (rev 57503)
+++ trunk/Master/texmf-dist/doc/latex/spath3/knots_doc.tex 2021-01-23 22:17:41 UTC (rev 57504)
@@ -1,484 +0,0 @@
-\immediate\write18{tex spath3.dtx}
-\documentclass{ltxdoc}
-\usepackage[T1]{fontenc}
-\usepackage{trace}
-\usepackage{lmodern}
-\usepackage{morefloats}
-\usepackage{tikz}
-\usetikzlibrary{knots}
-\usepackage[numbered]{hypdoc}
-\definecolor{lstbgcolor}{rgb}{0.9,0.9,0.9}
-
-\usepackage{listings}
-\lstloadlanguages{[LaTeX]TeX}
-\lstset{breakatwhitespace=true,breaklines=true,language=TeX}
-
-\usepackage{fancyvrb}
-
-\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}
-}
-
-\providecommand*{\url}{\texttt}
-\GetFileInfo{spath3.sty}
-
-\title{The \textsf{knots} Package: Documentation}
-\author{Andrew Stacey \\ \url{stacey at math.ntnu.no}}
-\date{\fileversion~from \filedate}
-
-\begin{document}
-
-\maketitle
-
-\section{Introduction}
-
-The \Verb+knots+ package is a TikZ library for drawing knot (and similar) diagrams.
-It provides a few useful styles and node shapes but its main contribution is the \Verb+knot+ environment.
-The \Verb+knot+ environment allows you to draw some strands of a knot (or braid or tangle or whatever -- we shall use the imprecise term ``knot'' to refer to any similar diagram) and then to modify the crossings via a simple interface.
-
-The main part of this package was developed in response to a question on the \href{http://tex.stackexchange.com}{TeX-SX} site by Jamie Vicary.
-The original question was \href{http://tex.stackexchange.com/q/32125/86}{Braid diagrams in TikZ}.
-Jamie's comment (quoted below) was the inspiration for the mechanism of the \Verb+knot+ environment.
-
-\begin{quotation}
-[It] would be really cool if it was possible to draw the curves, let TikZ calculate all the intersection points automatically, and then tell it to redraw the intersections according to an under/over specification... do you think this is in the realm of plausibility?
-\end{quotation}
-
-\section{Examples}
-
-Let us begin with an example.
-To use the library, simply load the \Verb+tikz+ package and add \Verb+knots+ to the list of TikZ libraries that you load.
-For example, the following in your preamble would work:
-
-\begin{verbatim}
-\usepackage{tikz}
-\usetikzlibrary{knots}
-\end{verbatim}
-
-Let's draw a simple tangle (actually a braid).
-
-\begin{example}
-\begin{tikzpicture}
-\draw[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
-\draw[blue,ultra thick] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
-\end{tikzpicture}
-\end{example}
-
-Now a common way to draw crossings for knots is to draw a gap in the under strand through which the over strand passes.
-One way to achieve this in TikZ is to draw the over strand twice, the first time with a thicker line width and the colour of the background.
-We'll draw it twice, once with background a different colour to illustrate this.
-
-\begin{example}
-\begin{tikzpicture}
-\draw[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
-\draw[pink,double=blue,ultra thick,double distance=1.6pt] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
-\draw[xshift=5cm,red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
-\draw[xshift=5cm,white,double=blue,ultra thick,double distance=1.6pt] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
-\end{tikzpicture}
-\end{example}
-
-Now the problem with this method is that there is no way to draw the red and blue paths so that the blue is the over strand at the first crossing and the red at the second.
-Either the blue path is always on top (as shown) or the red.
-One way to resolve this is to split the paths and draw one of them in segments:
-
-\begin{example}
-\begin{tikzpicture}
-\draw[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1);
-\draw[white,double=blue,ultra thick,double distance=1.6pt] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
-\draw[white,double=red,double distance=1.6pt,ultra thick] (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
-\end{tikzpicture}
-\end{example}
-
-Another method (employed by the \Verb+braids+ package) is to break the under path either side of the crossing and not draw it there.
-This means that the order of drawing doesn't matter.
-
-Both of these methods have their drawbacks (particularly for general knots as opposed to the more structured braids) in that they require a detailed knowledge of the pieces of the paths and the positions of the crossings.
-As pointed out by Jamie Vicary in the above-{}quoted comment, TikZ should be able to compute these itself.
-
-That's what this package does.
-
-Let's do the above example using this package.
-The main changes to the drawing are that we use the command \Verb+\strand+ rather than \Verb+\draw+ and we enclose it in the \Verb+knot+ environment.
-When initially drawing the strands it is useful to provide the option \Verb+draft mode=strands+.
-That's because the detailed computation can take a little time and so it is best only to do it when necessary.
-So on first run through we get the following.
-
-\begin{example}
-\begin{tikzpicture}
-\begin{knot}[
- draft mode=strands
-]
-\strand[red,thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
-\strand[blue,thick] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
-\end{knot}
-\end{tikzpicture}
-\end{example}
-
-Once we're happy with the positioning of the strands, we change the option \Verb+draft mode=strands+ to \Verb+draft mode=crossings+.
-
-\begin{example}
-\begin{tikzpicture}
-\path (2,1.5) (2,-.5);
-\begin{knot}[
- draft mode=crossings,
- clip width=5,
-]
-\strand[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
-\strand[blue,ultra thick] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
-\end{knot}
-\end{tikzpicture}
-\end{example}
-
-The \Verb+\path (2,1.5) (2,-.5);+ is to extend the bounding box of the picture a little upwards.
-The extra pieces are not used when computing the bounding box of the picture so that it doesn't change position on the page.
-
-The extra information is that the strands and the crossings have been numbered.
-The crossings have also been rendered (the \Verb+clip width+ option enlarges the crossing gap to make it more obvious).
-Unfortunately, for both crossings the red path is on top.
-We need to flip one of these crossings (the first).
-To do this, we either use the command \Verb+flipcrossings+ or the \Verb+flip crossing+ key.
-
-\begin{example}
-\begin{tikzpicture}
-\path (2,1.5) (2,-.5);
-\begin{knot}[
- draft mode=crossings,
- clip width=5,
- flip crossing=1,
-]
-\strand[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
-\strand[blue,ultra thick] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
-\end{knot}
-\end{tikzpicture}
-\end{example}
-
-Once we're happy with it, we remove the \Verb+draft mode+ option to render it in its final form.
-
-\begin{example}
-\begin{tikzpicture}
-\begin{knot}[
- clip width=5,
- flip crossing=1,
-]
-\strand[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
-\strand[blue,ultra thick] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
-\end{knot}
-\end{tikzpicture}
-\end{example}
-
-Here's a more complicated example.
-
-\begin{example}
-\begin{tikzpicture}
-\node (A) at (0,4) [draw,minimum width=30pt,minimum height=10pt,thick] {};
-\begin{knot}[
- clip width=5,
- clip radius=8pt,
-]
-\strand [thick,only when rendering/.style={dashed}] (0,0)
-to [out=up, in=down] (-1,1)
-to [out=up, in=down] (0,2)
-to [out=up, in=down] (-1.2,4)
-to [out=up, in=down, looseness=0.7] (0,5.5)
-to [out=up, in=down] (-2,7);
-\strand [thick] (-1,0)
-to [out=up, in=down] (1,2)
-to [out=up, in=down] (A.south);
-\strand [thick,blue] (1,0)
-to [out=up, in=down] (-1,2)
-to [out=up, in=down] (1.5,4)
-to [out=up, in=right] (0,5.5)to [out=left, in=up] (-2,4)
-to [out=down, in=up] (-2,0);
-\strand [thick] (A.150)
-to [out=up, in=down] (0.7,5.5)
-to [out=up, in=down] (0,7);
-\strand [thick] (A.30)
-to [out=up, in=down] (-1,6)
-to [out=up, in=down] (2,7);
-\flipcrossings{6,2,9,5,11}
-\end{knot}
-\end{tikzpicture}
-\end{example}
-
-One feature about this example is the \Verb+only when rendering+ key.
-The gaps are made by drawing the strand again with extra thickness in the background colour.
-If the \Verb+dashed+ option were always in play for that strand, the gap would be dashed which would spoil the effect.
-So the \Verb+only when rendering+ key gathers those options (such as a dash pattern) which should only be applied to the rendered strand and not to the redraw that creates the gap.
-
-Here's another example.
-
-\begin{example}
-\newcommand{\motif}[1]{
- to ++(180+#1:0.50) arc (270+#1:150+#1:0.15)
- to ++( 60+#1:0.50) arc (-30+#1:150+#1:0.15)
- to ++(240+#1:0.25) arc (150+#1:330+#1:0.25)
- to ++( 60+#1:0.55) arc (150+#1: 30+#1:0.20)
-}
-\newcommand{\celticknot}{\motif{0}\motif{120}\motif{240}}
-\begin{tikzpicture}
-\begin{knot}[
- line width=2pt,
- line join=round,
- clip width=2,
- scale=5,
- consider self intersections,
- ignore endpoint intersections=false,
- background color=white,
- only when rendering/.style={
- draw=red,
- double=white,
- double distance=6pt,
- line cap=round,
- }
-]
-\strand (0,0) \celticknot;
-\flipcrossings{1,3,6,8,10}
-\end{knot}
-\end{tikzpicture}
-\end{example}
-
-In this case the strand is a single path.
-In the standard case crossings are only considered between separate strands (since the algorithm used by TikZ means that a strand intersects itself infinitely often).
-The key \Verb+consider self intersections+ gets round this by ``exploding'' the strand into segments and considering each as a separate path with regard to finding the intersections.
-
-A path consists of a series of lines and B\'ezier cubics.
-The ``explosion'' of a path uses this decomposition.
-Unfortunately, even that is not always enough as it is possible for a B\'ezier cubic to self-intersect.
-The \Verb+consider self intersections+ also splits these B\'ezier curves in two to ensure that this doesn't happen\footnote{Computing when this is strictly necessary is difficult so it splits more than it needs to to ensure that enough are done.}.
-To disable this, use the \Verb+consider self intersections=no splits+ option.
-This is the recommended option.
-
-\begin{example}
-\begin{tikzpicture}
-\begin{knot}[
- consider self intersections,
- draft mode=crossings,
-]
-\strand (0,0) .. controls +(3,1) and +(-3,1) .. (1,0);
-\end{knot}
-\begin{knot}[
- xshift=3cm,
- consider self intersections=no splits,
- draft mode=crossings,
-]
-\strand (0,0) .. controls +(3,1) and +(-3,1) .. (1,0);
-\end{knot}
-\end{tikzpicture}
-\end{example}
-
-Finally, given that TikZ has to do some heavy computation to find the intersections, it is worth considering using the \Verb+external+ library of TikZ to avoid having to do this on every run.
-
-\section{Usage}
-
-\subsection{The \texttt{knot} Environment}
-
-\DescribeMacro{knot}
-\DescribeMacro{\strand}
-This package provides a \Verb+knot+ environment for including in a \Verb+tikzpicture+ to render a knot.
-This takes an optional argument which is passed to \Verb+\tikzset+ and can be used to configure the knot.
-Within that environment, specific strands are defined using the \Verb+\strand+ command (in place of a \Verb+\path+ or \Verb+\draw+).
-Further keys can be specified on the strands.
-
-\DescribeMacro{flip crossing}
-\DescribeMacro{\flipcrossings}
-Specifying the crossings to be flipped can be done either using the key \Verb+flip crossing+ or the macro \Verb+\flipcrossings+.
-The latter can take a comma separated list of crossings to flip.
-The former takes a single crossing but can be extended to a comma separated list using the \Verb+.list+ handler as in \Verb+flip crossing/.list={1,2,3}+ (this is what \Verb+\flipcrossings+ does internally).
-
-\DescribeMacro{\redraw}
-There is also a macro \Verb+\redraw+ which redraws a strand in the neighbourhood of a point.
-This is effectively what happens for the crossings and can be used to fix something that wasn't done correctly by the main algorithm.
-It takes two arguments, the strand number and the point at which to render the strand, as in \Verb+\redraw{2}{(1,1)}+.
-
-\subsection{Keys}
-
-The various keys are as follows.
-The majority of the keys are in the \Verb+/tikz/knot diagram+ family, but it does its best to pass unknown keys down to \Verb+/tikz/+.
-The keys processed by the \Verb+knot+ environment are automatically in this family but the keys processed by the \Verb+\strand+ command are not.
-If a standard key (in the option to the \Verb+knot+ environment) doesn't work, try prefixing it with \Verb+/tikz/+ or \Verb+/pgf/+.
-
-\begin{itemize}
-\item \DescribeMacro{every knot diagram}
-The style \Verb+every knot diagram+ is executed at the start of the \Verb+knot+ environment.
-
-Note that it is inside the \Verb+knot diagram+ family so if setting it outside (say, in the preamble) use \Verb+\tikzset{knot diagram/every knot diagram}+.
-
-\item \DescribeMacro{name}
-The crossings of a knot are given coordinates of the form \Verb+<name> <number>+.
-The default name is \Verb+knot+.
-The \Verb+name+ key renames it.
-
-\item \DescribeMacro{every strand}
-The contents of \Verb+every strand+ are applied to every strand.
-By default this contains the \Verb+draw+ key so if resetting it you should probably ensure that it still has the \Verb+draw+ key.
-
-Note that it is inside the \Verb+knot diagram+ family so if setting it outside (say, in the preamble) use \Verb+\tikzset{knot diagram/every knot diagram}+.
-
-\item \DescribeMacro{only when rendering}
-The key \Verb+only when rendering={<style>}+ is applied to the strand only when it is actually drawn and not when it is used to cut out part of the underlying path.
-
-Note that there are actually two versions of this key: one in the \Verb+knot diagram+ family and one in the \Verb+/tikz+ family.
-This is so that it works equally well in the argument to the \Verb+knot+ environment and the \Verb+\strand+ command.
-
-\item \DescribeMacro{ignore endpoint intersections}
-When a strand is split into pieces then the intersection library finds ``false positives'' in that neighbouring pieces intersect at their endpoints.
-The code ignores such intersections between neighbouring pieces.
-The \Verb+ignore endpoint intersections+ (which is true by default) means that all intersections that are near an endpoint are ignored whether or not they are with the next or previous piece of that strand.
-The celtic knot example of the previous section sets this to false to ensure that it gets all intersections.
-
-\item \DescribeMacro{consider self intersections}
-The key \Verb+consider self intersections=<option>+ handles the splitting facility so that strands can self intersect.
-The options are \Verb+true+, \Verb+false+, and \Verb+no splits+.
-It is \Verb+false+ at the start, and the default option is \Verb+true+.
-The difference between \Verb+true+ and \Verb+no splits+ is as to whether segments are further split to avoid \emph{all} self intersections.
-
-\item \DescribeMacro{clip radius}
-The \Verb+clip radius=<length>+ is the radius of the clip region around each crossing.
-
-\item \DescribeMacro{end tolerance}
-The \Verb+end tolerance=<length>+ is the distance at which an intersection is considered as being near an endpoint (for simplicity, it uses the \(\ell^1\)--metric).
-
-\item \DescribeMacro{clip width}
-The \Verb+clip width=<factor>+ is the multiplier for the thickness of the ``wipeout'' path relative to the line width of the actual path.
-
-\item \DescribeMacro{flip crossing}
-The \Verb+flip crossing=<number>+ key flips the \Verb+<number>+ crossing.
-
-\item \DescribeMacro{background colour} \DescribeMacro{background color}
-The keys \Verb+background colour=<colour>+ and \Verb+background color=<color>+ set the background colour for the crossings.
-
-\item \DescribeMacro{intersection <number>}
-The style in \Verb+intersection <number>+ is applied just before that crossing is drawn so can be used to modify the crossing style just for that crossing.
-
-
-\item \DescribeMacro{draft mode}
-The key \Verb+draft mode=<option>+ sets the different styles for aiding with rendering the knot.
-The options are \Verb+strands+, \Verb+crossings+, or \Verb+off+.
-The \Verb+strands+ option just renders the strands with no crossings.
-The \Verb+crossings+ option renders the crossings and labels the strands and crossings.
-The \Verb+off+ option renders the crossings without the labels.
-
-\item \DescribeMacro{draft/crossing label}
-The style \Verb+draft/crossing label+ is applied to each of the crossing labels.
-The labels are actually \Verb+pin+s attached to coordinates at the crossings.
-This style is applied to the \Verb+pin+ itself.
-The default is:
-
-\begin{lstlisting}
-overlay,
-fill=white,
-fill opacity=.5,
-text opacity=1,
-text=blue,
-pin edge={blue,<-}
-\end{lstlisting}
-
-\item \DescribeMacro{draft/strand label}
-The style \Verb+draft/strand label+ is applied to each of the strand labels.
-The default is:
-
-\begin{lstlisting}
-overlay,
-circle,
-draw=purple,
-fill=white,
-fill opacity=.5,
-text opacity=1,
-text=purple,
-inner sep=0pt
-\end{lstlisting}
-\end{itemize}
-
-\subsection{Other Styles}
-
-The other things defined by this package are for drawing knot diagrams when the user knows in advance either the locations of the crossings or can arrange that the paths are drawn in the correct order.
-In these circumstances the \Verb+knot+ environment is overkill.
-
-\DescribeMacro{knot}
-\DescribeMacro{knot gap}
-This \Verb+knot=<colour>+ style sets up a doubled path with inner colour the given colour (or the current draw colour if not given) and outer colour the knot background colour.
-The width of the inner line is the current line width and the full width is controlled by the \Verb+knot gap=<factor>+ key which is initially set to \(3\) (thus giving a line's width either side).
-
-\begin{example}
-\begin{tikzpicture}[knot gap=7]
-\draw[thin,knot=red] (-1,-1) -- (1,1);
-\draw[thin,knot=red] (-1,1) -- (1,-1);
-\begin{scope}[xshift=2.5cm]
-\draw[knot=red] (-1,-1) -- (1,1);
-\draw[knot=red] (-1,1) -- (1,-1);
-\end{scope}
-\begin{scope}[xshift=5cm]
-\draw[thick,knot=red] (-1,-1) -- (1,1);
-\draw[thick,knot=red] (-1,1) -- (1,-1);
-\end{scope}
-\end{tikzpicture}
-\end{example}
-
-\DescribeMacro{knot crossing}
-\DescribeMacro{knot over cross}
-\DescribeMacro{knot under cross}
-\DescribeMacro{knot horiz}
-\DescribeMacro{knot vert}
-This package also defines some node shapes to help draw knot and link diagrams.
-The idea with these is to place a node of the appropriate type at each crossing and then link them accordingly.
-The node shapes are \Verb+knot crossing+, \Verb+knot over cross+, \Verb+knot under cross+, \Verb+knot vert+, \Verb+knot horiz+.
-The two styles \Verb+knot over cross+ and \Verb+knot under cross+ are crossings, \Verb+knot vert+ and \Verb+knot horiz+ are for when resolving the crossings in a diagram.
-By judicious use of the \Verb+\foreach+ command, a family of resolved link diagrams can be produced.
-
-\begin{example}
-\begin{tikzpicture}[every node/.style={draw,red}]
-\node[knot over cross] at (1,0) {};
-\node[knot under cross] at (2,0) {};
-\node[knot vert] at (3,0) {};
-\node[knot horiz] at (4,0) {};
-\end{tikzpicture}
-\end{example}
-
-The node \Verb+knot crossing+ is not meant to be drawn, it is an empty shape.
-Its value is in that it defines more anchors than the usual rectangle shape.
-For each of the 8 main compass directions, it defines anchors at 2, 4, 8, 16, and 32 times further out.
-This can be useful for designing curves that enter and exit the crossing gracefully at particular directions.
-When using this node shape, the crossing itself is easiest to draw by using the \Verb+center+ anchor for the strands that form the over cross.
-
-\begin{example}
-\begin{tikzpicture}[every path/.style={red,thick}, every node/.style={transform shape, knot crossing, inner sep=1.5pt}]
-\node[rotate=45] (tl) at (-1,1) {};
-\node[rotate=-45] (tr) at (1,1) {};
-\node (m) at (0,-1) {};
-\node (b) at (0,-2) {};
-\draw (b) .. controls (b.4 north west) and (m.4 south west) .. (m.center);
-\draw (b.center) .. controls (b.4 north east) and (m.4 south east) .. (m);
-\draw (m) .. controls (m.8 north west) and (tl.3 south west) .. (tl.center);
-\draw (m.center) .. controls (m.8 north east) and (tr.3 south east) .. (tr);
-\draw (tl.center) .. controls (tl.16 north east) and (tr.16 north west) .. (tr);
-\draw (b) .. controls (b.16 south east) and (tr.16 north east) .. (tr.center);
-\draw (b.center) .. controls (b.16 south west) and (tl.16 north west) .. (tl);
-\draw (tl) -- (tr.center);
-\end{tikzpicture}
-\end{example}
-
-\section{Other Relevant Packages by the Same Author}
-
-Another tool for drawing knot diagrams is provided by the \Verb+hobby+ package which draws smooth curves through a prescribed set of points.
-This can be combined with the facilities of this package but also has some features of its own that make it suitable for drawing knot diagrams.
-
-For braids themselves, there is the \Verb+braids+ package which allows input specification in the form of a word in the braid group.
-
-\end{document}
-% Local Variables:
-% tex-output-type: "pdf18"
-% End:
Added: trunk/Master/texmf-dist/doc/latex/spath3/spath3.pdf
===================================================================
(Binary files differ)
Index: trunk/Master/texmf-dist/doc/latex/spath3/spath3.pdf
===================================================================
--- trunk/Master/texmf-dist/doc/latex/spath3/spath3.pdf 2021-01-23 10:56:29 UTC (rev 57503)
+++ trunk/Master/texmf-dist/doc/latex/spath3/spath3.pdf 2021-01-23 22:17:41 UTC (rev 57504)
Property changes on: trunk/Master/texmf-dist/doc/latex/spath3/spath3.pdf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/pdf
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/spath3/spath3.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/spath3/spath3.tex (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/spath3/spath3.tex 2021-01-23 22:17:41 UTC (rev 57504)
@@ -0,0 +1,650 @@
+\RequirePackage{shellesc}
+\immediate\write18{tex spath3_code.dtx}
+\documentclass{l3doc}
+\usepackage{tikz}
+\usetikzlibrary{
+ spath3,
+ hobby,
+ patterns,
+ intersections,
+ arrows.meta,
+}
+
+\usepackage{listings}
+\lstloadlanguages{[LaTeX]TeX}
+\lstset{
+ breakatwhitespace=true,
+ breaklines=true,
+ language=[LaTeX]TeX,
+ basicstyle=\small\ttfamily,
+ keepspaces=true,
+ columns=fullflexible
+}
+
+\usepackage{fancyvrb}
+
+\newenvironment{example}
+{\VerbatimEnvironment
+\begin{VerbatimOut}[gobble=0]{example.out}}
+{\end{VerbatimOut}
+ \begin{center}
+ \setlength{\parindent}{0pt}
+ \fbox{\begin{minipage}{.9\linewidth}
+ \lstinputlisting[]{example.out}
+ \end{minipage}}
+
+ \fbox{\begin{minipage}{.9\linewidth}
+ \centering
+ \input{example.out}
+ \end{minipage}}
+\end{center}
+}
+
+\providecommand*{\url}{\texttt}
+\GetFileInfo{spath3.sty}
+
+\title{The \textsf{spath3} Package: Documentation}
+\author{Andrew Stacey \\ \url{loopspace at mathforge.org}}
+ \date{\fileversion~from \filedate}
+
+ \begin{document}
+
+ \maketitle
+
+ \section{Introduction}
+
+ The \texttt{spath3} package was originally designed as a low-level package for manipulating the \emph{soft paths} defined by PGF/TikZ.
+ Soft paths form one stage of the stack of translations between what the author writes in the \texttt{tikzpicture} environments in their \LaTeX\ document and what is eventually written to the output file.
+ Most of the complicated processing has been done by the time a soft path is constructed, but it is still very definitely a \TeX\ object and there has not, for example, been any consideration as to what the eventual output file format is (such as PDF, DVI, or SVG).
+ So it is very amenable to being modified at this stage and this package provides a set of routines for doing so.
+
+ The original purpose was to provide a common core on which other packages would be built.
+ Indeed, the packages \texttt{calligraphy}, \texttt{knots}, and \texttt{penrose} all use this package.
+ However, over time I've found myself wanting to use the routines of this package at a higher level and so have designed some user-level interfaces.
+ This document documents those.
+
+ To clarify some terminology, paths are composed of \emph{segment} and \emph{components}.
+A \emph{segment} is a minimal drawing piece.
+Thus it might be a straight line or a B\'ezier curve.
+A \emph{component} is a minimal connected section of the path.
+So every component starts with a move command and continues until the next move command.
+For ease of implementation (and to enable a copperplate pen in the calligraphy package!), an isolated move is considered as a component.
+
+
+ \section{TikZ Keys}
+
+\begin{lstlisting}
+\usetikzlibrary{spath3}
+\end{lstlisting}
+
+The \texttt{spath3} TikZ library defines a set of keys that can be issued to muck about with soft paths.
+These are all defined in the \texttt{spath} family, so all the following keys should be prefixed by \texttt{spath/}, or the key \texttt{spath/.cd} needs to be used beforehand.
+
+\subsection{Saving and Using Soft Paths}
+
+\begin{function}{save}
+\begin{syntax}
+|save=|\meta{name}
+\end{syntax}
+
+Saves the current path with name \texttt{<name>}.
+This delays until the path is fully constructed so can be issued in the options to the main command.
+
+Soft paths constructed this way are local to the group in which the path command is issued.
+
+The soft path is actually stored in a macro constructed from the name.
+There are a couple of reasons for using a \emph{name} rather than a macro directly.
+One is so that it is compatible with the \texttt{intersections} library -- by default both this package and that save their paths in the same underlying macro.
+The other is to provide a way to link a soft path with a set of TikZ styles (this is particularly useful when splitting the path into components).
+\end{function}
+
+\begin{function}{save global}
+\begin{syntax}
+|save global=|\meta{name}
+\end{syntax}
+
+Saves the current soft path globally.
+\end{function}
+
+\begin{function}{clone}
+\begin{syntax}
+|clone=|\marg{target}\marg{source}
+\end{syntax}
+
+Clones one soft path into another.
+\end{function}
+
+\begin{function}{restore}
+\begin{syntax}
+|restore=|\meta{name}
+\end{syntax}
+
+Restores a previously saved soft path to the current path.
+This happens immediately so can be issued in the options to the main command and then the path can be extended with normal drawing commands.
+Any keys that affect the soft path directly should be applied \emph{before} this one.
+
+One thing should be noted about transformations.
+By the time a soft path is built, all available transformations have been applied.
+This means that when re-inserting a soft path back into a high level command (such as |\draw|), the effect of existing transformations might produce some confusing effects.
+When restoring a path then the library tries to set the last point correctly, but depending on how this is used it can result in transformations being applied twice.
+\end{function}
+
+\begin{function}{append}
+\begin{syntax}
+|append=|\meta{name}
+\end{syntax}
+
+This inserts a soft path into the path at the current point, it is therefore more suited to being used part way through a path construction.
+In a sense, it is a little like a \texttt{pic} in that it enables the user to construct a path segment early to be reused at various places.
+
+The path is \emph{welded} on to the current path, meaning that it starts from the current point and there is no \texttt{move}.
+This is particularly useful for creating filled regions.
+\end{function}
+
+\begin{function}{reverse}
+\begin{syntax}
+|reverse=|\meta{name}
+\end{syntax}
+
+Reverses the path in the named spath object.
+This doesn't do any actually drawing.
+The effect is local, but if you want to work with both the original path and its reversal in the same path then use the \texttt{clone} key to copy it first.
+\end{function}
+
+\begin{function}{append reverse}
+\begin{syntax}
+|append reverse=|\meta{name}
+\end{syntax}
+
+Like \texttt{append} except that the inserted path is reversed first.
+\end{function}
+
+\begin{function}{insert}
+\begin{syntax}
+|insert=|\meta{name}
+\end{syntax}
+
+Like \texttt{append} except that it doesn't move the inserted path and there is a move between the current path and the inserted path.
+\end{function}
+
+\begin{function}{
+ shorten at end,
+shorten at start,
+shorten at both ends
+}
+\begin{syntax}
+|shorten at end=|\marg{name}\marg{dimen}
+\end{syntax}
+
+Shortens the soft path by the dimension from one or both ends.
+This shortens the soft path along its length so that it is guaranteed that the shorter path traces a subset of the original path.
+For B\'ezier curves, however, the amount of shortening is approximate and is better for shorter distances.
+If wanting to shorten by a large amount it is better to shorten by a small amount a number of times.
+\end{function}
+
+\begin{function}{translate}
+\begin{syntax}
+|translate=|\marg{name}\marg{x-dimen}\marg{y-dimen}
+\end{syntax}
+
+Translates the soft path by the given dimensions.
+\end{function}
+
+\begin{function}{transform}
+\begin{syntax}
+|transform=|\marg{name}\marg{transformations}
+\end{syntax}
+
+This applies the transformation to the soft path.
+The transformation is processed by TikZ so should consist of TikZ-level transformations such as |shift={(2,2)}|.
+\end{function}
+
+\subsection{Intersection Routines}
+
+To use these features you need to use the \texttt{intersections} library.
+
+\begin{function}{split at self intersections}
+\begin{syntax}
+|split at self intersections=|\meta{path}
+\end{syntax}
+
+This inserts breaks into the named soft path at the points where it intersects itself.
+\end{function}
+
+\begin{function}{split at intersections}
+\begin{syntax}
+|split at intersections=|\marg{first}\marg{second}
+\end{syntax}
+
+This inserts breaks into a pair of paths at their mutual intersections.
+\end{function}
+
+\subsection{Working with Components}
+
+\begin{function}{get components of}
+\begin{syntax}
+|get components of=|\marg{macro}\marg{path}
+\end{syntax}
+
+This splits the path into a list of its components, which are stored in the macro.
+The macro can be used in a |\foreach|.
+\end{function}
+
+\begin{function}{render components}
+\begin{syntax}
+|render components=|\meta{path}
+\end{syntax}
+
+This renders the components of a given path as separate TikZ commands, so that each can be separately styled.
+It applies the following styles (in this order):
+
+\begin{enumerate}
+\item \texttt{every spath component}
+\item \texttt{spath component <number>}
+\item \texttt{spath component=<number>}
+\item \texttt{every <path> component}
+\item \texttt{<path> component <number>}
+\item \texttt{<path> component=<number>}
+\end{enumerate}
+\end{function}
+
+\begin{function}{insert gaps after components}
+\begin{syntax}
+|insert gaps after components=|\marg{path}\marg{gap}\marg{components}
+\end{syntax}
+
+This inserts a gap between components of a path by shortening the end of the specified component and start of the next one.
+The list of components is passed through a |\foreach| loop so that syntax like |2,4,...,16|.
+\end{function}
+
+\begin{function}{join components}
+\begin{syntax}
+|join components=|\marg{path}\marg{components}
+\end{syntax}
+
+This removes the \texttt{move} between the given component and the previous one.
+If the component is the first one then it is joined to the last component.
+\end{function}
+
+\begin{function}{spot weld}
+\begin{syntax}
+|spot weld=|\meta{path}
+\end{syntax}
+
+This removes the \texttt{move} between any two components of the path where the end point of one component is the same as the initial point of the next (the tolerance on error here is \(0.01\)pt).
+\end{function}
+
+\begin{function}{remove empty components}
+\begin{syntax}
+|remove empty components=|\meta{path}
+\end{syntax}
+
+This removes empty components of the path (which consist of simply a move).
+\end{function}
+
+\subsection{Shortening Paths}
+
+\begin{function}{
+shorten path at end,
+shorten path at start,
+shorten path at both ends
+}
+\begin{syntax}
+|shorten path at end=|\marg{path}\marg{length}
+\end{syntax}
+
+This shortens a path by the given amount from the specified end.
+The shortening is done so that it guarantees that it lies along the original path, but therefore the length is not completely guaranteed to be accurate.
+This is particularly true for B\'ezier paths and if there is a very short segment at the end.
+
+It uses the derivative at the end to work out how much to shorten by.
+\end{function}
+
+\subsection{Exporting Paths}
+
+There are two keys to export a path.
+
+\begin{function}{save to aux}
+\begin{syntax}
+|save to aux=|\meta{path}
+\end{syntax}
+
+This will save the path to the auxfile so that it is available again on the next run through.
+\end{function}
+
+\begin{function}{export to svg}
+\begin{syntax}
+|export to svg=|\meta{path}
+\end{syntax}
+
+Saves the path to the file \texttt{path.svg} as an SVG document.
+\end{function}
+
+\subsection{Knots}
+
+\begin{function}{knot}
+\begin{syntax}
+|knot=|\meta{path}\meta{gap}\meta{components}
+\end{syntax}
+
+This style combines various of the above to make it simpler to draw knots and links.
+It expands to:
+
+\begin{lstlisting}
+knot/.style n args={3}{
+ spath/.cd,
+ split at self intersections=#1,
+ insert gaps after components={#1}{#2}{#3},
+ maybe spot weld=#1,
+ render components=#1
+}
+\end{lstlisting}
+
+This splits a path at the points where it self-intersects and then inserts gaps between specified components.
+The key |maybe spot weld| does a |spot weld| depending on whether or not the key |draft mode| is set to |true| or |false|.
+The point here is that when designing the knot it is useful to not weld together components since that changes the component count.
+But once the gaps are inserted in the desired places, welding the remaining components produces a nicer diagram.
+
+The components can be styled using the keys as described in |render components|.
+\end{function}
+
+\subsection{Coordinates}
+
+Soft paths are not natural TikZ objects and so when replaced back into a TikZ path construction then they don't fully interact with other TikZ things, like placing nodes at points on the path.
+To make things a little easier there is defined a coordinate system which identifies a point at a certain location along a soft path and keys which apply a transformation.
+
+\begin{function}{spath cs}
+\begin{syntax}
+|(spath cs:|\marg{name} \marg{parameter}|)|
+\end{syntax}
+
+The location specification is a little technical.
+It is specified as a number from \(0\) to \(1\), but the parameter works as follows.
+Let \(n\) be the number of \emph{segments} on the path (these are the individual drawing elements that make up the path).
+The interval from \(\frac{k-1}{n}\) to \(\frac{k}{n}\) is assigned to the \(k\)th segment of the path.
+Then for a parameter in that interval, the location uses the natural parametrisation of that segment.
+For a straight line, it is simply the proportional position along but for a B\'ezier curve then it uses the B\'ezier parametrisation.
+
+The space is vital, so if the \texttt{name} is contained in a macro then a space has to be inserted somehow.
+One option is to wrap the macro in braces, as seen in the examples in the next section.
+\end{function}
+
+\begin{function}{transform to, upright transform to}
+\begin{syntax}
+|transform to=|\marg{path}\marg{parameter}
+|upright transform to=|\marg{path}\marg{parameter}
+\end{syntax}
+
+These keys (which are in the |spath| family) set the transformation so that the origin is at the specified point of the curve (as described above) and the \(x\)--axis is tangential to the curve.
+The transformation is \emph{orthogonal} in that it is achieved by a rotation and a translation.
+
+The first key aligns the axes so that the \(x\)--axis is in the forward direction of the path as that path was constructed.
+The second key aligns the axes so that the \(y\)--axis points up the page.
+The intention with the second key is that it is similar to what happens with the |sloped| key when a node is placed on a curve.
+\end{function}
+
+\section{Examples}
+
+\begin{enumerate}
+\item Saving, restoring, inserting, and appending.
+
+\begin{example}
+\begin{tikzpicture}
+\path[spath/save=rpath] (0,0) to[out=30,in=150] (1,1);
+\foreach \k in {1,...,9} {
+ \fill[green] (spath cs:rpath 0.\k) circle[radius=3pt];
+ \node[above left] at (spath cs:rpath 0.\k) {\(0.\k\)};
+}
+\fill[green] (2,2) circle[radius=3pt];
+\draw[blue, spath/transform={rpath}{shift={(2,2)}}, spath/restore=rpath] node[right] {transform};
+\draw[orange] (3,0) [spath/insert=rpath] node[right] {insert};
+\draw[red] (3,-1) -- +(0,2) [spath/append=rpath] node[above] {append};
+\draw[spath/restore=rpath] node[right] {restore};
+\end{tikzpicture}
+\end{example}
+
+\item Reversing.
+
+\begin{example}
+\begin{tikzpicture}
+\path[spath/save=apath] (0,0) to[out=0,in=180] (2,1) to[out=0,in=180] (4,0);
+\filldraw[
+ green,
+ draw=black,
+ ultra thick,
+ spath/restore=apath
+] -- ++(0,-4) [spath/append reverse=apath] -- cycle;
+\end{tikzpicture}
+\end{example}
+
+\item Transformations.
+
+\begin{example}
+\begin{tikzpicture}
+\draw[spath/save=tpath] (0,0) rectangle +(1,1);
+\draw[rotate=45, xscale=2, yscale=3, ultra thick, red] (0,0) rectangle +(1,1);
+\draw[
+ spath/transform={tpath}{rotate=45, xscale=2, yscale=3},
+ spath/restore={tpath}];
+\end{tikzpicture}
+\end{example}
+
+\begin{example}
+\begin{tikzpicture}
+\draw[spath/save=oval] (0,0) to[out=0,in=0] (0,2) to[out=180,in=180] (0,0);
+\foreach \k in {0,...,9} {
+ \node[transform shape, spath/transform to={oval}{0.\k}] {k};
+}
+\begin{scope}[xshift = 3cm]
+\draw[spath/save=soval] (0,0) to[out=0,in=0] (0,2) to[out=180,in=180] (0,0);
+\foreach \k in {0,...,9} {
+ \node[transform shape, spath/upright transform to={soval}{0.\k}] {k};
+}
+\end{scope}
+\end{tikzpicture}
+\end{example}
+
+\item Shortening.
+
+\begin{example}
+\begin{tikzpicture}
+\path[spath/save=apath] (0,0) foreach \k in {1,...,4} { -- ++(1,0) +(0,0)};
+\draw[
+ ultra thick,
+ red,
+ spath/.cd,
+ shorten at end={apath}{7pt},
+ shorten at start={apath}{9pt},
+ translate={apath}{0pt}{1pt},
+ restore=apath,
+];
+\draw (0,0) circle[radius=9pt] [spath/insert=apath] circle[radius=7pt];
+\end{tikzpicture}
+\end{example}
+
+
+\begin{example}
+\begin{tikzpicture}
+\path[spath/save=apath] (0,0) foreach \k in {1,...,4} { to[out=0,in=180] ++(1,0) +(0,0)};
+\draw[
+ ultra thick,
+ red,
+ spath/.cd,
+ shorten at end={apath}{7pt},
+ shorten at start={apath}{9pt},
+ translate={apath}{0pt}{1pt},
+ restore=apath,
+];
+\draw (0,0) circle[radius=9pt] [spath/insert=apath] circle[radius=7pt];
+\end{tikzpicture}
+\end{example}
+
+\begin{example}
+\begin{tikzpicture}
+\draw[spath/save=npath] (0,0) foreach \k in {1,...,4} { -- ++(1,0) +(0,0)};
+\draw[green] (0,0) -- +(0,-3pt) foreach \k in {1,...,4} { -- +(0,-3pt) ++(1,0)} -- +(0,-3pt);
+
+\tikzset{
+ spath/.cd,
+ insert gaps after components={npath}{10pt}{1,3},
+ get components of={npath}\components,
+}
+
+\tikzset{
+ path 1/.style={
+ red,
+ },
+}
+
+\foreach[count=\k] \cpt in \components {
+ \path[
+ draw,
+ path \k/.try,
+ spath/.cd,
+ translate=\cpt{0pt}{\k pt},
+ restore=\cpt,
+ ] +(0,3pt) -- +(0,-3pt);
+ \node[text=red] at (spath cs:{\cpt} .5) {\(\k\)};
+}
+\end{tikzpicture}
+\end{example}
+
+\item Intersections.
+
+One of the main motivations for implementing the intersection routines was to provide a different way of drawing knots and links and similar diagrams.
+
+\begin{enumerate}
+
+\item Define the two paths for the braid (usually these will be defined with |\path|).
+\begin{example}
+\begin{tikzpicture}[
+ use Hobby shortcut,
+]
+\draw[spath/save global=pathA] (0,0) to[out=0,in=180] ++(2,1) to[out=0,in=180] ++(2,-1) to[out=0,in=180] ++(2,1) to[out=0,in=180] ++(2,-1);
+\draw[spath/save global=pathB] (0,1) to[out=0,in=180] ++(2,-1) to[out=0,in=180] ++(2,1) to[out=0,in=180] ++(2,-1) to[out=0,in=180] ++(2,1);
+\end{tikzpicture}
+\end{example}
+
+\item Split the paths at their mutual intersections and render them with a count of the components.
+
+\begin{example}
+\begin{tikzpicture}
+\tikzset{
+ spath/.cd,
+ split at intersections={pathA}{pathB},
+ get components of={pathA}\pathAcomponents,
+ get components of={pathB}\pathBcomponents,
+}
+
+\foreach[count=\k] \cpt in \pathAcomponents {
+ \draw[spath/restore=\cpt,-Circle];
+ \node[fill=white, fill opacity=.5, circle, text opacity=1] at (spath cs:{\cpt} .5) {\(\k\)};
+}
+
+\foreach[count=\k] \cpt in \pathBcomponents {
+ \draw[spath/restore=\cpt,-Circle];
+ \node[fill=white, fill opacity=.5, circle, text opacity=1] at (spath cs:{\cpt} .5) {\(\k\)};
+}
+\end{tikzpicture}
+\end{example}
+
+\item Now we insert gaps after certain components in each path and then render the components.
+To show that the gaps are genuine, we use a patterned background.
+Although the paths were defined globally, the splitting in the previous example was local so we need to repeat it in this one.
+
+\begin{example}
+\begin{tikzpicture}
+\tikzset{
+ spath/.cd,
+ split at intersections={pathA}{pathB},
+ insert gaps after components={pathA}{5pt}{1,3},
+ join components={pathA}{3,5},
+ get components of={pathA}\pathAcomponents,
+ insert gaps after components={pathB}{5pt}{2,4},
+ join components={pathB}{2,4},
+ get components of={pathB}\pathBcomponents,
+}
+
+\fill[red!50!white] (-.5,-.5) rectangle (8.5,1.5);
+\fill[pattern=bricks, pattern color=white] (-.5,-.5) rectangle (8.5,1.5);
+
+\foreach[count=\k] \cpt in \pathAcomponents {
+ \draw[blue, line width=2pt,spath/restore=\cpt];
+ \node[fill=cyan, fill opacity=.5, circle, text opacity=1] at (spath cs:{\cpt} .3) {\(\k\)};
+}
+
+\foreach[count=\k] \cpt in \pathBcomponents {
+ \draw[green, line width=2pt,spath/restore=\cpt];
+ \node[fill=green!50, fill opacity=.5, circle, text opacity=1] at (spath cs:{\cpt} .3) {\(\k\)};
+}
+\end{tikzpicture}
+\end{example}
+\end{enumerate}
+
+\item This example is notable because many of the intersection points are where segments of the path end, showing that the algorithm works well even in this circumstance.
+
+\begin{enumerate}
+\item Here's the original path.
+\begin{example}
+\begin{tikzpicture}
+\draw[spath/save global=spiral] (5,0) -- (2.5,0) -- ++(0,-.25) -- ++(-2.5,0)
+arc[radius=2.25cm,start angle=180,end angle=90]
+arc[radius=2cm,start angle=90, delta angle=-180]
+arc[radius=1.75cm,start angle=-90, delta angle=-180]
+arc[radius=1.5cm,start angle=90, delta angle=-180]
+arc[radius=1.25cm,start angle=-90, delta angle=-180]
+arc[radius=1cm,start angle=90, delta angle=-180]
+arc[radius=.75cm,start angle=-90, delta angle=-180]
+arc[radius=.5cm,start angle=90, delta angle=-180]
+;
+\end{tikzpicture}
+\end{example}
+
+\item This renders labels on each component after splitting.
+\begin{example}
+\begin{tikzpicture}
+\tikzset{
+ spath/.cd,
+ split at self intersections=spiral,
+ get components of={spiral}\pathcomponents,
+}
+
+\foreach[count=\k] \cpt in \pathcomponents {
+ \draw[spath/restore=\cpt,-|];
+ \node[fill=white, fill opacity=.5, circle, text opacity=1] at (spath cs:{\cpt} .5) {\(\k\)};
+}
+\end{tikzpicture}
+\end{example}
+
+\item Finally, we put the gaps in where we want them.
+
+\begin{example}
+\begin{tikzpicture}
+\tikzset{
+ spath/.cd,
+ split at self intersections=spiral,
+ insert gaps after components={spiral}{10pt}{1,3,5,7,10,11,14},
+ spot weld=spiral,
+ get components of={spiral}\pathcomponents,
+}
+
+\foreach[count=\k] \cpt in \pathcomponents {
+ \draw[blue, line width=2pt,spath/restore=\cpt];
+}
+\end{tikzpicture}
+\end{example}
+\end{enumerate}
+
+\item Here's a trefoil knot, demonstrating the \texttt{knot} style that simplifies creating knots.
+\begin{example}
+\begin{tikzpicture}[
+ use Hobby shortcut,
+ every trefoil component/.style={ultra thick, draw, red},
+ trefoil component 1/.style={blue},
+]
+\path[spath/save=trefoil] ([closed]90:2) foreach \k in {1,...,3} { .. (-30+\k*240:.5) .. (90+\k*240:2) } (90:2);
+\tikzset{spath/knot={trefoil}{8pt}{1,3,5}}
+\end{tikzpicture}
+\end{example}
+\end{enumerate}
+ \end{document}
Property changes on: trunk/Master/texmf-dist/doc/latex/spath3/spath3.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/doc/latex/spath3/spath3_code.pdf
===================================================================
(Binary files differ)
Deleted: trunk/Master/texmf-dist/source/latex/spath3/spath3.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/spath3/spath3.dtx 2021-01-23 10:56:29 UTC (rev 57503)
+++ trunk/Master/texmf-dist/source/latex/spath3/spath3.dtx 2021-01-23 22:17:41 UTC (rev 57504)
@@ -1,4228 +0,0 @@
-% \iffalse meta-comment
-%<*internal>
-\iffalse
-%</internal>
-%<*readme>
-----------------------------------------------------------------
-spath3 --- LaTeX3 functions for manipulating PGF soft paths
-E-mail: stacey at math.ntnu.no
-Released under the LaTeX Project Public License v1.3c or later
-See http://www.latex-project.org/lppl.txt
-----------------------------------------------------------------
-
-This package defines some functions used to manipulate PGFs soft paths.
-As applications of its use, included are a package for drawing calligraphic paths and a package for drawing knot diagrams.
-%</readme>
-%<*internal>
-\fi
-\def\nameofplainTeX{plain}
-\ifx\fmtname\nameofplainTeX\else
- \expandafter\begingroup
-\fi
-%</internal>
-%<*install>
-\input docstrip.tex
-\keepsilent
-\askforoverwritefalse
-\preamble
-----------------------------------------------------------------
-spath3 --- Functions for manipulating PGF soft paths
-E-mail: stacey at math.ntnu.no
-Released under the LaTeX Project Public License v1.3c or later
-See http://www.latex-project.org/lppl.txt
-----------------------------------------------------------------
-
-\endpreamble
-\postamble
-
-Copyright (C) 2011-2019 by Andrew Stacey <stacey at math.ntnu.no>
-
-This work may be distributed and/or modified under the
-conditions of the LaTeX Project Public License (LPPL), either
-version 1.3c of this license or (at your option) any later
-version. The latest version of this license is in the file:
-
-http://www.latex-project.org/lppl.txt
-
-This work is "maintained" (as per LPPL maintenance status) by
-Andrew Stacey.
-
-This work consists of the files spath3.dtx
- calligraphy_doc.tex
- knots_doc.tex
-and the derived files spath3.ins,
- spath3_code.pdf,
- spath3.sty,
- tikzlibrarycalligraphy.code.tex
- tikzlibraryknots.code.tex
- calligraphy.pdf
- knots.pdf
- README
-
-\endpostamble
-\usedir{tex/latex/spath3}
-\generate{
- \file{\jobname.sty}{\from{\jobname.dtx}{spath3}}
-}
-\generate{
- \file{tikzlibrarycalligraphy.code.tex}{\from{\jobname.dtx}{calligraphy}}
-}
-\generate{
- \file{tikzlibraryknots.code.tex}{\from{\jobname.dtx}{knots}}
-}
-%</install>
-%<install>\endbatchfile
-%<*internal>
-\usedir{source/latex/spath3}
-\generate{
- \file{\jobname.ins}{\from{\jobname.dtx}{install}}
-}
-\nopreamble\nopostamble
-\usedir{doc/latex/demopkg}
-\generate{
- \file{README.txt}{\from{\jobname.dtx}{readme}}
-}
-\ifx\fmtname\nameofplainTeX
- \expandafter\endbatchfile
-\else
- \expandafter\endgroup
-\fi
-%</internal>
-%<*driver>
-\documentclass[full]{l3doc}
-\usepackage[T1]{fontenc}
-\usepackage{lmodern}
-%\usepackage{morefloats}
-\usepackage{tikz}
-\usepackage{trace}
-\usepackage{spath3}
-%\traceoff
-%\usepackage[numbered]{hypdoc}
-\definecolor{lstbgcolor}{rgb}{0.9,0.9,0.9}
-
-\usepackage{listings}
-\lstloadlanguages{[LaTeX]TeX}
-\lstset{breakatwhitespace=true,breaklines=true,language=TeX}
-
-\usepackage{fancyvrb}
-
-\newenvironment{example}
- {\VerbatimEnvironment
- \begin{VerbatimOut}[gobble=2]{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}
- \input{example.out}
- \end{minipage}}
-\end{center}
-}
-\EnableCrossrefs
-\CodelineIndex
-\RecordChanges
-\begin{document}
- \DocInput{\jobname.dtx}
-\end{document}
-%</driver>
-% \fi
-%
-% \CheckSum{4488}
-%
-% \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
-% Lower-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
-% Digits \0\1\2\3\4\5\6\7\8\9
-% Exclamation \! Double quote \" Hash (number) \#
-% Dollar \$ Percent \% Ampersand \&
-% Acute accent \' Left paren \( Right paren \)
-% Asterisk \* Plus \+ Comma \,
-% Minus \- Point \. Solidus \/
-% Colon \: Semicolon \; Less than \<
-% Equals \= Greater than \> Question mark \?
-% Commercial at \@ Left bracket \[ Backslash \\
-% Right bracket \] Circumflex \^ Underscore \_
-% Grave accent \` Left brace \{ Vertical bar \|
-% Right brace \} Tilde \~}
-%
-%
-% \changes{1.0}{2011/05/03}{Converted to DTX file}
-% \changes{1.1}{2016/02/19}{Fixes due to changes in LaTeX3}
-% \changes{1.2}{2019/02/12}{More fixes due to changes in LaTeX3}
-%
-% \DoNotIndex{\newcommand,\newenvironment}
-%
-% \providecommand*{\url}{\texttt}
-% \GetFileInfo{spath3.sty}
-% \title{The \textsf{spath3} package}
-% \author{Andrew Stacey \\ \url{stacey at math.ntnu.no}}
-% \date{\fileversion~from \filedate}
-%
-%
-% \maketitle
-%
-%
-% \section{Introduction}
-%
-% The \Verb+spath3+ package is intended as a library for manipulating PGF's \emph{soft paths}.
-% In between defining a path and using it, PGF stores a path as a \emph{soft path} where all the defining structure has been resolved into the basic operations but these have not yet been written to the output file.
-% They can therefore still be manipulated by \TeX, and as they have a very rigid form (and limited vocabulary), they are relatively easy to modify.
-% This package provides some methods for working with these paths.
-% It is not really intended for use by end users but as a foundation on which other packages can be built.
-% As examples, the \Verb+calligraphy+ package and the \Verb+knot+ package are included.
-% The first of these simulates a calligraphic pen stroking a path.
-% The second can be used to draw knot (and similar) diagrams.
-%
-% The format of a soft path is a sequence of triples of the form \Verb+\macro {dimension}{dimension}+.
-% The macro is one of a short list, the dimensions are coordinates in points.
-% There are certain further restrictions, particularly that every path must begin with a \Verb+move to+, and B\'ezier curves consist of three triples.
-%
-% \StopEventually{}
-%
-% \section{Implementation}
-%
-% \iffalse
-%<*spath3>
-% \fi
-% \subsection{Initialisation}
-%
-% Load the \LaTeX3 foundation and register us as a \LaTeX3\ package.
-% \begin{macrocode}
-\NeedsTeXFormat{LaTeX2e}
-\RequirePackage{expl3}
-\RequirePackage{pgf}
-\ProvidesExplPackage {spath3} {2019/02/12} {1.2} {Functions for
-manipulating PGF soft paths}
-\RequirePackage{xparse}
-% \end{macrocode}
-%
-% We need a slew of temporary variables.
-% \begin{macrocode}
-\tl_new:N \l__spath_tmpa_tl
-\tl_new:N \l__spath_tmpb_tl
-\tl_new:N \l__spath_tmpc_tl
-\tl_new:N \l__spath_tmpd_tl
-\tl_new:N \l__spath_smuggle_tl
-\dim_new:N \l__spath_tmpa_dim
-\dim_new:N \l__spath_tmpb_dim
-\fp_new:N \l__spath_tmpa_fp
-\fp_new:N \l__spath_tmpb_fp
-\int_new:N \l__spath_tmpa_int
-\int_new:N \g__spath_map_int
-% \end{macrocode}
-%
-% We need to be able to compare against the macros that can occur in a soft path so these token lists contain them.
-% \begin{macrocode}
-\tl_new:N \g__spath_moveto_tl
-\tl_new:N \g__spath_lineto_tl
-\tl_new:N \g__spath_curveto_tl
-\tl_new:N \g__spath_curvetoa_tl
-\tl_new:N \g__spath_curvetob_tl
-\tl_new:N \g__spath_closepath_tl
-\tl_set:Nn \g__spath_moveto_tl {\pgfsyssoftpath at movetotoken}
-\tl_set:Nn \g__spath_lineto_tl {\pgfsyssoftpath at linetotoken}
-\tl_set:Nn \g__spath_curveto_tl {\pgfsyssoftpath at curvetotoken}
-\tl_set:Nn \g__spath_curvetoa_tl {\pgfsyssoftpath at curvetosupportatoken}
-\tl_set:Nn \g__spath_curvetob_tl {\pgfsyssoftpath at curvetosupportbtoken}
-\tl_set:Nn \g__spath_closepath_tl {\pgfsyssoftpath at closepathtoken}
-% \end{macrocode}
-%
-% \subsection{Basic Structure and Methods}
-%
-% A soft path is a \Verb+prop+.
-% These are lists of the attributes that we define.
-% The first consists of all attributes, the second of those that are ``moveable'' in the sense that they change if we transform the path, the third are the ones that contain actual paths.
-%
-% Note that if using these attributes outside an \Verb+expl3+ context, the spaces should be omitted.
-% \begin{macrocode}
-\tl_new:N \g__spath_attributes
-\tl_new:N \g__spath_moveable_attributes
-\tl_new:N \g__spath_path_attributes
-\tl_set:Nn \g__spath_attributes {
- {path}
- {reverse path}
- {length}
- {real length}
- {number of components}
- {initial point}
- {final point}
- {initial action}
- {final action}
- {min bb}
- {max bb}
-}
-\tl_set:Nn \g__spath_moveable_attributes {
- {initial point}
- {final point}
- {min bb}
- {max bb}
-}
-\tl_set:Nn \g__spath_path_attributes {
- {path}
- {reverse path}
-}
-% \end{macrocode}
-%
-% An \Verb+spath+ object is actually a \Verb+prop+.
-% The following functions are wrappers around the underlying \Verb+prop+ functions.
-% We prefix the names to avoid clashing with other \Verb+prop+s that might be lying around, this is why all the \Verb+spath+ methods take argument \Verb+:n+ and not \Verb+:N+.
-% Given that \Verb+spath+ objects might be created inside a group but used outside it, we work globally throughout.
-% \begin{macro}{\spath_new:n}
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_new:n #1
-{
- \prop_new:c {l__spath_#1}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_clear:n}
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_clear:n #1
-{
- \prop_gclear:c {l__spath_#1}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_clear_new:n}
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_clear_new:n #1
-{
- \prop_gclear_new:c {l__spath_#1}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_show:n}
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_show:n #1
-{
- \prop_show:c {l__spath_#1}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_put:nnn}
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_put:nnn #1#2#3
-{
- \prop_gput:cnn {l__spath_#1} {#2} {#3}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_remove:nn}
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_remove:nn #1#2
-{
- \prop_gremove:cn {l__spath_#1} {#2}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\__spath_get:nn}
-% This function is an internal one since the real \Verb+get+ function will generate its data if it does not already exist.
-% \begin{macrocode}
-\cs_new_nopar:Npn \__spath_get:nn #1#2
-{
- \prop_item:cn {l__spath_#1} {#2}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\__spath_get:nnN}
-% \begin{macrocode}
-\cs_new_nopar:Npn \__spath_get:nnN #1#2#3
-{
- \prop_get:cnN {l__spath_#1} {#2} #3
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_if_in:nn}
-% \begin{macrocode}
-\prg_new_conditional:Npnn \spath_if_in:nn #1#2 {p, T, F, TF}
-{
- \prop_if_in:cnTF {l__spath_#1} {#2}
- { \prg_return_true: }
- { \prg_return_false: }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\__spath_get:nnN}
-% \begin{macrocode}
-\cs_generate_variant:Nn \__prop_split:NnTF {cnTF}
-\prg_new_protected_conditional:Npnn \__spath_get:nnN #1#2#3 {T, F, TF}
-{
- \__prop_split:cnTF {l__spath_#1} {#2}
- {
- \tl_set:Nn #3 {##2}
- \prg_return_true:
- }
- { \prg_return_false: }
-}
-\cs_generate_variant:Nn \spath_put:nnn {nnV, nnx, nno}
-\cs_generate_variant:Nn \__spath_get:nn {Vn}
-\cs_generate_variant:Nn \__spath_get:nnN {VnN}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_if_exist:n}
-% \begin{macrocode}
-\prg_new_conditional:Npnn \spath_if_exist:n #1 {p,T,F,TF}
-{
- \prop_if_exist:cTF {l__spath_#1}
- {
- \prg_return_true:
- }
- {
- \prg_return_false:
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_clone:nn}
-% Clones an \Verb+spath+.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_clone:nn #1 #2
-{
- \spath_clear_new:n {#2}
- \tl_map_inline:Nn \g__spath_attributes
- {
- \spath_if_in:nnT {#1} {##1}
- {
- \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl
- \spath_put:nnV {#2} {##1} \l__spath_tmpa_tl
- }
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_get_current_path:n}
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \spath_get_current_path:n #1
-{
- \pgfsyssoftpath at getcurrentpath\l__spath_tmpa_tl
- \spath_clear_new:n {#1}
- \spath_put:nnV {#1} {path} \l__spath_tmpa_tl
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_set_current_path:n}
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \spath_set_current_path:n #1
-{
- \spath_get:nnN {#1} {min bb} \l__spath_tmpa_tl
- \exp_last_unbraced:NV \pgf at protocolsizes\l__spath_tmpa_tl
-
- \spath_get:nnN {#1} {max bb} \l__spath_tmpa_tl
- \exp_last_unbraced:NV \pgf at protocolsizes\l__spath_tmpa_tl
-
- \spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \pgfsyssoftpath at setcurrentpath\l__spath_tmpa_tl
- \pgfsyssoftpath at flushcurrentpath
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_use_path:nn}
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \spath_use_path:nn #1#2
-{
- \spath_set_current_path:n {#1}
- \pgfusepath{#2}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_protocol_path:n}
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \spath_protocol_path:n #1
-{
- \spath_get:nnN {#1} {min bb} \l__spath_tmpa_tl
- \exp_last_unbraced:NV \pgf at protocolsizes\l__spath_tmpa_tl
-
- \spath_get:nnN {#1} {max bb} \l__spath_tmpa_tl
- \exp_last_unbraced:NV \pgf at protocolsizes\l__spath_tmpa_tl
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_tikz_path:nn}
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \spath_tikz_path:nn #1#2
-{
- \path[#1] \pgfextra{
- \spath_get:nnN {#2} {path} \l__spath_tmpa_tl
- \pgfsyssoftpath at setcurrentpath \l__spath_tmpa_tl
- };
-}
-\cs_generate_variant:Nn \spath_tikz_path:nn {Vn}
-% \end{macrocode}
-% \end{macro}
-%
-% \subsection{Computing Information}
-%
-% \begin{macro}{\spath_get:nn}
-% The information that we store along with a soft path can be computed from it, but computing it every time is wasteful.
-% So this is the real \Verb+\spath_get:nn+ function which checks to see if we have already computed it and then either retrieves it or computes it.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_get:nn #1#2
-{
- \spath_if_in:nnF {#1} {#2}
- {
- \cs_if_exist_use:cT {spath_generate_#2:n} {{#1}}
- }
- \__spath_get:nn {#1} {#2}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_get:nnN}
-% As above but leaves the result in a token list rather than in the stream.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_get:nnN #1#2#3
-{
- \spath_if_in:nnF {#1} {#2}
- {
- \cs_if_exist_use:cT {spath_generate_#2:n} {{#1}}
- }
- \__spath_get:nnN {#1} {#2} #3
-}
-\cs_generate_variant:Nn \spath_get:nnN {VnN}
-% \end{macrocode}
-% \end{macro}
-%
-% The next slew of functions generate data from the original path, storing it in the \Verb+prop+ for further retrieval.
-% \begin{macro}{\spath_generate_length:n}
-% Counts the number of triples in the path.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_generate_length:n #1
-{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \spath_put:nnx {#1} {length} {\int_eval:n {\tl_count:N \l__spath_tmpa_tl /3 }}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_generate_reallength:n}
-% The real length of a path is the number of triples that actually draw something (that is, the number of lines and curves).
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_generate_reallength:n #1
-{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \int_set:Nn \l__spath_tmpa_int {0}
- \tl_map_inline:Nn \l__spath_tmpa_tl {
- \tl_if_eq:nnT {##1} {\pgfsyssoftpath at linetotoken}
- {
- \int_incr:N \l__spath_tmpa_int
- }
- \tl_if_eq:nnT {##1} {\pgfsyssoftpath at curvetotoken}
- {
- \int_incr:N \l__spath_tmpa_int
- }
- }
- \spath_put:nnx {#1} {real length} {\int_use:N \l__spath_tmpa_int}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_generate_numberofcomponents:n}
-% A component is a continuous segment of the path, separated by moves.
-% Successive moves are not collapsed, and zero length moves count.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_generate_numberofcomponents:n #1
-{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \int_set:Nn \l__spath_tmpa_int {0}
- \tl_map_inline:Nn \l__spath_tmpa_tl {
- \tl_if_eq:nnT {##1} {\pgfsyssoftpath at movetotoken}
- {
- \int_incr:N \l__spath_tmpa_int
- }
- }
- \spath_put:nnx {#1} {number of components} {\int_use:N \l__spath_tmpa_int}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_generate_initialpoint:n}
-% The starting point of the path.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_generate_initialpoint:n #1
-{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \tl_clear:N \l__spath_tmpb_tl
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \spath_put:nnV {#1} {initial point} \l__spath_tmpb_tl
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_generate_finalpoint:n}
-% The final point of the path.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_generate_finalpoint:n #1
-{
- \tl_clear:N \l__spath_tmpb_tl
- \spath_if_in:nnTF {#1} {reverse path}
- {
- \__spath_get:nnN {#1} {reverse path} \l__spath_tmpa_tl
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- }
- {
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \tl_reverse:N \l__spath_tmpa_tl
- \tl_put_left:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_left:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- }
- \spath_put:nnV {#1} {final point} \l__spath_tmpb_tl
-}
-\cs_generate_variant:Nn \spath_generate_finalpoint:n {V}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_generate_reversepath:n}
-% This computes the reverse of the path.
-% TODO: handle closed paths, possibly rectangles.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_generate_reversepath:n #1
-{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \tl_clear:N \l__spath_tmpb_tl
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_left:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- \bool_until_do:nn {
- \tl_if_empty_p:N \l__spath_tmpa_tl
- }
- {
- \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nn \l__spath_tmpd_tl {}
- \tl_case:NnF \l__spath_tmpc_tl
- {
- \g__spath_moveto_tl {\tl_set_eq:NN \l__spath_tmpd_tl \g__spath_moveto_tl }
- \g__spath_lineto_tl {\tl_set_eq:NN \l__spath_tmpd_tl \g__spath_lineto_tl }
- \g__spath_curveto_tl {\tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curvetoa_tl }
- \g__spath_curvetoa_tl {\tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curveto_tl }
- \g__spath_curvetob_tl {\tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curvetob_tl }
- }
- {
- \tl_show:N \l__spath_tmpc_tl
- }
- \tl_put_left:NV \l__spath_tmpb_tl \l__spath_tmpd_tl
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_left:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- }
- \tl_put_left:NV \l__spath_tmpb_tl \g__spath_moveto_tl
- \spath_put:nnV {#1} {reverse path} \l__spath_tmpb_tl
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_generate_initialaction:n}
-% This is the first thing that the path does (after the initial move).
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_generate_initialaction:n #1
-{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \tl_clear:N \l__spath_tmpb_tl
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_if_empty:NF \l__spath_tmpa_tl {
- \tl_set:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
- }
- \spath_put:nnV {#1} {initial action} \l__spath_tmpb_tl
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_generate_final action:n}
-% This is the last thing that the path does.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_generate_finalaction:n #1
-{
- \tl_clear:N \l__spath_tmpb_tl
- \spath_if_in:nnTF {#1} {reverse path}
- {
- \__spath_get:nnN {#1} {reverse path} \l__spath_tmpa_tl
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- }
- {
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \tl_reverse:N \l__spath_tmpa_tl
- }
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_if_empty:NF \l__spath_tmpa_tl {
- \tl_set:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
- }
- \tl_if_eq:NNT \l__spath_tmpa_tl \g__spath_curvetoa_tl
- {
- \tl_set_eq:NN \l__spath_tmpa_tl \g__spath_curveto_tl
- }
- \spath_put:nnV {#1} {final action} \l__spath_tmpb_tl
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_generate_minbb:n}
-% This computes the minimum (bottom left) of the bounding box of the path.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_generate_minbb:n #1
-{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \bool_until_do:nn {
- \tl_if_empty_p:N \l__spath_tmpa_tl
- }
- {
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpa_dim {\dim_min:nn {\tl_head:N \l__spath_tmpa_tl} {\l__spath_tmpa_dim}}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\dim_min:nn {\tl_head:N \l__spath_tmpa_tl} {\l__spath_tmpb_dim}}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- }
- \tl_clear:N \l__spath_tmpb_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- \spath_put:nnV {#1} {min bb} \l__spath_tmpb_tl
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_generate_max bb:n}
-% This computes the maximum (top right) of the bounding box of the path.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_generate_maxbb:n #1
-{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \bool_until_do:nn {
- \tl_if_empty_p:N \l__spath_tmpa_tl
- }
- {
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpa_dim {\dim_max:nn {\tl_head:N \l__spath_tmpa_tl} {\l__spath_tmpa_dim}}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\dim_max:nn {\tl_head:N \l__spath_tmpa_tl} {\l__spath_tmpb_dim}}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- }
- \tl_clear:N \l__spath_tmpb_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- \spath_put:nnV {#1} {max bb} \l__spath_tmpb_tl
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_generate_all:n}
-% This function generates all of the data in one fell swoop.
-% By traversing the path just once it is quicker than doing each one individually.
-% However, it does need to store a lot of data as it goes.
-% \begin{itemize}
-% \item \Verb+\l__spath_rp_tl+ will hold the reversed path
-% \item \Verb+\l__spath_l_int+ will hold the length
-% \item \Verb+\l__spath_rl_int+ will hold the real length
-% \item \Verb+\l__spath_nc_int+ will hold the number of components
-% \item \Verb+\l__spath_ip_tl+ will hold the initial point
-% \item \Verb+\l__spath_fp_tl+ will hold the final point
-% \item \Verb+\l__spath_ia_tl+ will hold the initial action
-% \item \Verb+\l__spath_fa_tl+ will hold the final action
-% \item \Verb+\l__spath_minx_dim+ will hold the min x bb
-% \item \Verb+\l__spath_miny_dim+ will hold the min y bb
-% \item \Verb+\l__spath_maxx_dim+ will hold the max x bb
-% \item \Verb+\l__spath_maxy_dim+ will hold the max y bb
-% \end{itemize}
-% \begin{macrocode}
-\tl_new:N \l__spath_rp_tl
-\int_new:N \l__spath_l_int
-\int_new:N \l__spath_rl_int
-\int_new:N \l__spath_nc_int
-\tl_new:N \l__spath_ip_tl
-\tl_new:N \l__spath_fp_tl
-\tl_new:N \l__spath_ia_tl
-\tl_new:N \l__spath_fa_tl
-\dim_new:N \l__spath_minx_dim
-\dim_new:N \l__spath_miny_dim
-\dim_new:N \l__spath_maxx_dim
-\dim_new:N \l__spath_maxy_dim
-
-\cs_new_nopar:Npn \spath_generate_all:n #1
-{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
-
- \tl_clear:N \l__spath_rp_tl
- \int_set:Nn \l__spath_l_int {1}
- \int_zero:N \l__spath_rl_int
- \int_set:Nn \l__spath_nc_int {1}
- \tl_clear:N \l__spath_ip_tl
- \tl_clear:N \l__spath_fp_tl
- \tl_clear:N \l__spath_ia_tl
- \tl_clear:N \l__spath_fa_tl
- \dim_zero:N \l__spath_minx_dim
- \dim_zero:N \l__spath_miny_dim
- \dim_zero:N \l__spath_maxx_dim
- \dim_zero:N \l__spath_maxy_dim
-
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \tl_clear:N \l__spath_ip_tl
- \tl_put_right:Nx \l__spath_ip_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
-
- \dim_set_eq:NN \l__spath_minx_dim \l__spath_tmpa_dim
- \dim_set_eq:NN \l__spath_miny_dim \l__spath_tmpb_dim
- \dim_set_eq:NN \l__spath_maxx_dim \l__spath_tmpa_dim
- \dim_set_eq:NN \l__spath_maxy_dim \l__spath_tmpb_dim
-
- \tl_put_left:Nx \l__spath_rp_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
-
- \tl_set:Nx \l__spath_ia_tl {\tl_head:N \l__spath_tmpa_tl}
-
- \bool_until_do:nn {
- \tl_if_empty_p:N \l__spath_tmpa_tl
- }
- {
- \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nn \l__spath_tmpd_tl {}
- \tl_set_eq:NN \l__spath_fa_tl \l__spath_tmpc_tl
- \int_incr:N \l__spath_l_int
-
- \tl_case:NnF \l__spath_tmpc_tl
- {
- \g__spath_moveto_tl {
- \tl_set_eq:NN \l__spath_tmpd_tl \g__spath_moveto_tl
- \int_incr:N \l__spath_nc_int
- }
- \g__spath_lineto_tl {
- \tl_set_eq:NN \l__spath_tmpd_tl \g__spath_lineto_tl
- \int_incr:N \l__spath_rl_int
- }
- \g__spath_curveto_tl {
- \tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curvetoa_tl
- \int_incr:N \l__spath_rl_int
- }
- \g__spath_curvetoa_tl {
- \tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curveto_tl
- }
- \g__spath_curvetob_tl {
- \tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curvetob_tl
- }
- }
- {
- \tl_show:N \l__spath_tmpc_tl
- }
- \tl_put_left:NV \l__spath_rp_tl \l__spath_tmpd_tl
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \dim_set:Nn \l__spath_minx_dim {\dim_min:nn { \l__spath_minx_dim} {\l__spath_tmpa_dim}}
- \dim_set:Nn \l__spath_miny_dim {\dim_min:nn { \l__spath_miny_dim} {\l__spath_tmpb_dim}}
- \dim_set:Nn \l__spath_maxx_dim {\dim_max:nn { \l__spath_maxx_dim} {\l__spath_tmpa_dim}}
- \dim_set:Nn \l__spath_maxy_dim {\dim_max:nn { \l__spath_maxy_dim} {\l__spath_tmpb_dim}}
-
- \tl_put_left:Nx \l__spath_rp_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
-
- \tl_set:Nx \l__spath_fp_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
-
- }
-
- \tl_put_left:NV \l__spath_rp_tl \g__spath_moveto_tl
-
- \spath_put:nnV {#1} {reverse path} \l__spath_rp_tl
- \spath_put:nnV {#1} {length} \l__spath_l_int
- \spath_put:nnV {#1} {real length} \l__spath_rl_int
- \spath_put:nnV {#1} {number of components} \l__spath_nc_int
- \spath_put:nnV {#1} {initial point} \l__spath_ip_tl
- \spath_put:nnV {#1} {final point} \l__spath_fp_tl
- \spath_put:nnV {#1} {initial action} \l__spath_ia_tl
- \spath_put:nnV {#1} {final action} \l__spath_fa_tl
-
- \tl_clear:N \l__spath_tmpb_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_minx_dim}
- {\dim_use:N \l__spath_miny_dim}
- }
- \spath_put:nnV {#1} {min bb} \l__spath_tmpb_tl
-
- \tl_clear:N \l__spath_tmpb_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_maxx_dim}
- {\dim_use:N \l__spath_maxy_dim}
- }
- \spath_put:nnV {#1} {max bb} \l__spath_tmpb_tl
-
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \subsection{Path Manipulation}
-%
-% \begin{macro}{\spath_translate:nnn}
-% Translates a path.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_translate:nnn #1#2#3
-{
- \tl_map_inline:Nn \g__spath_moveable_attributes
- {
- \spath_if_in:nnT {#1} {##1}
- {
- \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl
-
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl + #2}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl + #3}
- \tl_clear:N \l__spath_tmpb_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl
- }
- }
- \tl_map_inline:Nn \g__spath_path_attributes
- {
- \spath_if_in:nnT {#1} {##1}
- {
- \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl
- \tl_clear:N \l__spath_tmpb_tl
- \bool_until_do:nn {
- \tl_if_empty_p:N \l__spath_tmpa_tl
- }
- {
- \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl + #2}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl + #3}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- }
- \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl
- }
- }
-}
-
-\cs_generate_variant:Nn \spath_translate:nnn {nxx}
-% \end{macrocode}
-%
-% This variant allows for passing the coordinates as a single braced group as it strips off the outer braces of the second argument.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_translate:nn #1#2
-{
- \spath_translate:nnn {#1} #2
-}
-
-\cs_generate_variant:Nn \spath_translate:nn {nV}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_scale:nnn}
-% Scale a path.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_scale:nnn #1#2#3
-{
- \tl_map_inline:Nn \g__spath_moveable_attributes
- {
- \spath_if_in:nnT {#1} {##1}
- {
- \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl
-
- \fp_set:Nn \l__spath_tmpa_fp {\tl_head:N \l__spath_tmpa_tl * #2}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \fp_set:Nn \l__spath_tmpb_fp {\tl_head:N \l__spath_tmpa_tl * #3}
- \tl_clear:N \l__spath_tmpb_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\fp_to_dim:N \l__spath_tmpa_fp}
- {\fp_to_dim:N \l__spath_tmpb_fp}
- }
- \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl
- }
- }
- \tl_map_inline:Nn \g__spath_path_attributes
- {
- \spath_if_in:nnT {#1} {##1}
- {
- \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl
- \tl_clear:N \l__spath_tmpb_tl
- \bool_until_do:nn {
- \tl_if_empty_p:N \l__spath_tmpa_tl
- }
- {
- \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \fp_set:Nn \l__spath_tmpa_fp {\tl_head:N \l__spath_tmpa_tl * #2}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \fp_set:Nn \l__spath_tmpb_fp {\tl_head:N \l__spath_tmpa_tl * #3}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\fp_to_dim:N \l__spath_tmpa_fp}
- {\fp_to_dim:N \l__spath_tmpb_fp}
- }
- }
- \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl
- }
- }
-}
-\cs_generate_variant:Nn \spath_scale:nnn {nxx}
-% \end{macrocode}
-%
-% This variant allows for passing the coordinates as a single braced group as it strips off the outer braces of the second argument.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_scale:nn #1#2
-{
- \spath_scale:nnn {#1} #2
-}
-
-\cs_generate_variant:Nn \spath_scale:nn {nV}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_transform:nnnnnnn}
-% Applies an affine (matrix and vector) transformation to path.
-% The matrix is specified in rows first.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_transform:nnnnnnn #1#2#3#4#5#6#7
-{
- \tl_map_inline:Nn \g__spath_moveable_attributes
- {
- \spath_if_in:nnT {#1} {##1}
- {
- \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_head:N \l__spath_tmpa_tl}
- \fp_set:Nn \l__spath_tmpa_fp {\l__spath_tmpa_tl * #2 + \l__spath_tmpb_tl * #3 + #6}
- \fp_set:Nn \l__spath_tmpb_fp {\l__spath_tmpa_tl * #4 + \l__spath_tmpb_tl * #5 + #7}
- \tl_clear:N \l__spath_tmpb_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\fp_to_dim:N \l__spath_tmpa_fp}
- {\fp_to_dim:N \l__spath_tmpb_fp}
- }
- \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl
- }
- }
- \tl_map_inline:Nn \g__spath_path_attributes
- {
- \spath_if_in:nnT {#1} {##1}
- {
- \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl
- \tl_clear:N \l__spath_tmpb_tl
- \bool_until_do:nn {
- \tl_if_empty_p:N \l__spath_tmpa_tl
- }
- {
- \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \fp_set:Nn \l__spath_tmpa_fp {\l_tmpa_tl * #2 + \l_tmpb_tl * #3 + #6}
- \fp_set:Nn \l__spath_tmpb_fp {\l_tmpa_tl * #4 + \l_tmpb_tl * #5 + #7}
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\fp_to_dim:N \l__spath_tmpa_fp}
- {\fp_to_dim:N \l__spath_tmpb_fp}
- }
- }
- \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl
- }
- }
-}
-
-\cs_generate_variant:Nn \spath_transform:nnnnnnn {nxxxxxx}
-% \end{macrocode}
-%
-% This variant allows for passing the coordinates as a single braced group as it strips off the outer braces of the second argument.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_transform:nn #1#2
-{
- \spath_transform:nnnnnnn {#1} #2
-}
-
-\cs_generate_variant:Nn \spath_transform:nn {nV}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_reverse:n}
-% This reverses a path.
-% As a lot of the data is invariant under reversing, there isn't a lot to do.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_reverse:n #1
-{
- \spath_if_in:nnF {#1} {reverse path} {
- \use:c {spath_generate_reverse path:n} {#1}
- }
- \spath_swap:nnn {#1} {path} {reverse path}
- \spath_swap:nnn {#1} {initial point} {final point}
- \spath_swap:nnn {#1} {initial action} {final action}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_swap:nnn}
-% Swaps two entries, being careful to ensure that their existence (or otherwise) is preserved.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_swap:nnn #1#2#3
-{
- \__spath_get:nnNF {#1} {#2} \l__spath_tmpa_tl {\tl_clear:N \l__spath_tmpa_tl}
- \__spath_get:nnNF {#1} {#3} \l__spath_tmpb_tl {\tl_clear:N \l__spath_tmpb_tl}
- \tl_if_empty:NTF \l__spath_tmpb_tl
- {\spath_remove:nn {#1} {#2}}
- {\spath_put:nnV {#1} {#2} \l__spath_tmpb_tl}
- \tl_if_empty:NTF \l__spath_tmpa_tl
- {\spath_remove:nn {#1} {#3}}
- {\spath_put:nnV {#1} {#3} \l__spath_tmpa_tl}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_weld:nn}
-% This welds one path to another, moving the second so that it's initial point coincides with the first's final point.
-% It is called a \emph{weld} because the initial move of the second path is removed.
-% The first path is updated, the second is not modified.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_weld:nn #1#2
-{
- \spath_clone:nn {#2} {tmp_path}
- \spath_get:nnN {#1} {final point} \l__spath_tmpa_tl
-
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
-
- \spath_get:nnN {#2} {initial point} \l__spath_tmpa_tl
-
- \dim_sub:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_sub:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
-
- \spath_translate:nxx {tmp_path} {\dim_use:N \l__spath_tmpa_dim} {\dim_use:N \l__spath_tmpb_dim}
-
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \__spath_get:nnN {tmp_path} {path} \l__spath_tmpb_tl
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
-
- \spath_put:nnV {#1} {path} \l__spath_tmpa_tl
-
- \__spath_get:nnNTF {tmp_path} {final point} \l__spath_tmpa_tl
- {
- \spath_put:nnV {#1} {final point} \l__spath_tmpa_tl
- }
- {
- \spath_remove:nn {#1} {final point}
- }
-
- \__spath_get:nnNTF {tmp_path} {final action} \l__spath_tmpa_tl
- {
- \spath_put:nnV {#1} {final action} \l__spath_tmpa_tl
- }
- {
- \spath_remove:nn {#1} {final action}
- }
-
- \__spath_get:nnNT {tmp_path} {min bb} \l__spath_tmpa_tl
- {
- \__spath_get:nnNT {#1} {min bb} \l__spath_tmpb_tl
- {
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
-
- \dim_set:Nn \l__spath_tmpa_dim {\dim_min:nn {\l__spath_tmpa_dim} {\tl_head:N \l__spath_tmpb_tl}}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\dim_min:nn {\l__spath_tmpb_dim} {\tl_head:N \l__spath_tmpb_tl}}
-
- \tl_clear:N \l__spath_tmpb_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- \spath_put:nnV {#1} {min bb} \l__spath_tmpb_tl
- }
- }
-
- \__spath_get:nnNT {tmp_path} {max bb} \l__spath_tmpa_tl
- {
- \__spath_get:nnNT {#1} {max bb} \l__spath_tmpb_tl
- {
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
-
- \dim_set:Nn \l__spath_tmpa_dim {\dim_max:nn {\l__spath_tmpa_dim} {\tl_head:N \l__spath_tmpb_tl}}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\dim_max:nn {\l__spath_tmpb_dim} {\tl_head:N \l__spath_tmpb_tl}}
-
- \tl_clear:N \l__spath_tmpb_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- \spath_put:nnV {#1} {max bb} \l__spath_tmpb_tl
- }
- }
-
- \__spath_get:nnNT {tmp_path} {reverse path} \l__spath_tmpa_tl
- {
- \__spath_get:nnNT {#1} {reverse path} \l__spath_tmpb_tl
- {
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
-
- \spath_put:nnV {#1} {reverse path} \l__spath_tmpa_tl
- }
- }
-
- \__spath_get:nnNT {tmp_path} {length} \l__spath_tmpa_tl
- {
- \__spath_get:nnNT {#1} {length} \l__spath_tmpb_tl
- {
- \int_set:Nn \l__spath_tmpa_int {\l__spath_tmpa_tl + \l__spath_tmpb_tl - 1}
- \spath_put:nnV {#1} {length} \l__spath_tmpa_int
- }
- }
-
- \__spath_get:nnNT {tmp_path} {real length} \l__spath_tmpa_tl
- {
- \__spath_get:nnNT {#1} {real length} \l__spath_tmpb_tl
- {
- \int_set:Nn \l__spath_tmpa_int {\l__spath_tmpa_tl + \l__spath_tmpb_tl}
- \spath_put:nnV {#1} {real length} \l__spath_tmpa_int
- }
- }
-
- \__spath_get:nnNT {tmp_path} {number of components} \l__spath_tmpa_tl
- {
- \__spath_get:nnNT {#1} {number of components} \l__spath_tmpb_tl
- {
- \int_set:Nn \l__spath_tmpa_int {\l__spath_tmpa_tl + \l__spath_tmpb_tl - 1}
- \spath_put:nnV {#1} {number of components} \l__spath_tmpa_int
- }
- }
-
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_prepend_no_move:nn}
-% Prepend the path from the second \Verb+spath+ to the first, removing
-% the adjoining move.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_prepend_no_move:nn #1#2
-{
- \spath_if_exist:nT {#2}
- {
- \__spath_get:nnN {#2} {path} \l__spath_tmpa_tl
- \__spath_get:nnN {#1} {path} \l__spath_tmpb_tl
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
- \spath_put:nnV {#1} {path} \l__spath_tmpa_tl
-
- \spath_if_in:nnTF {#2} {initial point}
- {
- \__spath_get:nnN {#2} {initial point} \l__spath_tmpa_tl
- \spath_put:nnV {#1} {initial point} \l__spath_tmpa_tl
- }
- {
- \spath_remove:nn {#1} {initial point}
- }
-
- \spath_if_in:nnTF {#2} {initial action}
- {
- \__spath_get:nnN {#2} {initial action} \l__spath_tmpa_tl
- \spath_put:nnV {#1} {initial action} \l__spath_tmpa_tl
- }
- {
- \spath_remove:nn {#1} {initial action}
- }
-
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {length}
- &&
- \spath_if_in_p:nn {#2} {length}
- }
- {
- \__spath_get:nnN {#1} {length} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {length} \l__spath_tmpb_tl
- \spath_put:nnx {#1} {length} {\int_eval:n {\l__spath_tmpa_tl +
- \l__spath_tmpb_tl - 1}}
- }
- {
- \spath_remove:nn {#1} {length}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {real length}
- &&
- \spath_if_in_p:nn {#2} {real length}
- }
- {
- \__spath_get:nnN {#1} {real length} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {real length} \l__spath_tmpb_tl
- \spath_put:nnx {#1} {real length} {\int_eval:n {\l__spath_tmpa_tl +
- \l__spath_tmpb_tl }}
- }
- {
- \spath_remove:nn {#1} {real length}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {number of components}
- &&
- \spath_if_in_p:nn {#2} {number of components}
- }
- {
- \__spath_get:nnN {#1} {number of components} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {number of components} \l__spath_tmpb_tl
- \spath_put:nnx {#1} {number of components} {\int_eval:n {\l__spath_tmpa_tl +
- \l__spath_tmpb_tl - 1}}
- }
- {
- \spath_remove:nn {#1} {number of components}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {min bb}
- &&
- \spath_if_in_p:nn {#2} {min bb}
- }
- {
- \__spath_get:nnN {#1} {min bb} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {min bb} \l__spath_tmpb_tl
- \dim_set:Nn \l__spath_tmpa_dim {\dim_min:nn {\tl_item:Nn
- \l__spath_tmpa_tl {1}} {\tl_item:Nn
- \l__spath_tmpb_tl {1}}}
- \dim_set:Nn \l__spath_tmpb_dim {\dim_min:nn {\tl_item:Nn
- \l__spath_tmpa_tl {2}} {\tl_item:Nn
- \l__spath_tmpb_tl {2}}}
- \spath_put:nnx {#1} {min bb} {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- }
- {
- \spath_remove:nn {#1} {min bb}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {max bb}
- &&
- \spath_if_in_p:nn {#2} {max bb}
- }
- {
- \__spath_get:nnN {#1} {max bb} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {max bb} \l__spath_tmpb_tl
- \dim_set:Nn \l__spath_tmpa_dim {\dim_min:nn {\tl_item:Nn
- \l__spath_tmpa_tl {1}} {\tl_item:Nn
- \l__spath_tmpb_tl {1}}}
- \dim_set:Nn \l__spath_tmpb_dim {\dim_min:nn {\tl_item:Nn
- \l__spath_tmpa_tl {2}} {\tl_item:Nn
- \l__spath_tmpb_tl {2}}}
- \spath_put:nnx {#1} {max bb} {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- }
- {
- \spath_remove:nn {#1} {max bb}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {reverse path}
- &&
- \spath_if_in_p:nn {#2} {reverse path}
- }
- {
- \__spath_get:nnN {#1} {reverse path} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {reverse path} \l__spath_tmpb_tl
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
- \spath_put:nnV {#1} {reverse path} \l__spath_tmpb_tl
- }
- {
- \spath_remove:nn {#1} {reverse path}
- }
-
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_append_no_move:nn}
-% Append the path from the second \Verb+spath+ to the first, removing
-% the adjoining move.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_append_no_move:nn #1#2
-{
- \spath_if_exist:nT {#2}
- {
- \spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \spath_get:nnN {#2} {path} \l__spath_tmpb_tl
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
- \spath_put:nnV {#1} {path} \l__spath_tmpa_tl
- \spath_if_in:nnTF {#2} {final point}
- {
- \__spath_get:nnN {#2} {final point} \l__spath_tmpa_tl
- \spath_put:nnV {#1} {final point} \l__spath_tmpa_tl
- }
- {
- \spath_remove:nn {#1} {final point}
- }
- \spath_if_in:nnTF {#2} {final action}
- {
- \__spath_get:nnN {#2} {final action} \l__spath_tmpa_tl
- \spath_put:nnV {#1} {final action} \l__spath_tmpa_tl
- }
- {
- \spath_remove:nn {#1} {final action}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {length}
- &&
- \spath_if_in_p:nn {#2} {length}
- }
- {
- \__spath_get:nnN {#1} {length} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {length} \l__spath_tmpb_tl
- \spath_put:nnx {#1} {length} {\int_eval:n {\l__spath_tmpa_tl +
- \l__spath_tmpb_tl - 1}}
- }
- {
- \spath_remove:nn {#1} {length}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {real length}
- &&
- \spath_if_in_p:nn {#2} {real length}
- }
- {
- \__spath_get:nnN {#1} {real length} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {real length} \l__spath_tmpb_tl
- \spath_put:nnx {#1} {real length} {\int_eval:n {\l__spath_tmpa_tl +
- \l__spath_tmpb_tl }}
- }
- {
- \spath_remove:nn {#1} {real length}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {number of components}
- &&
- \spath_if_in_p:nn {#2} {number of components}
- }
- {
- \__spath_get:nnN {#1} {number of components} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {number of components} \l__spath_tmpb_tl
- \spath_put:nnx {#1} {number of components} {\int_eval:n {\l__spath_tmpa_tl +
- \l__spath_tmpb_tl - 1}}
- }
- {
- \spath_remove:nn {#1} {number of components}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {min bb}
- &&
- \spath_if_in_p:nn {#2} {min bb}
- }
- {
- \__spath_get:nnN {#1} {min bb} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {min bb} \l__spath_tmpb_tl
- \dim_set:Nn \l__spath_tmpa_dim {\dim_min:nn {\tl_item:Nn
- \l__spath_tmpa_tl {1}} {\tl_item:Nn
- \l__spath_tmpb_tl {1}}}
- \dim_set:Nn \l__spath_tmpb_dim {\dim_min:nn {\tl_item:Nn
- \l__spath_tmpa_tl {2}} {\tl_item:Nn
- \l__spath_tmpb_tl {2}}}
- \spath_put:nnx {#1} {min bb} {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- }
- {
- \spath_remove:nn {#1} {min bb}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {max bb}
- &&
- \spath_if_in_p:nn {#2} {max bb}
- }
- {
- \__spath_get:nnN {#1} {max bb} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {max bb} \l__spath_tmpb_tl
- \dim_set:Nn \l__spath_tmpa_dim {\dim_min:nn {\tl_item:Nn
- \l__spath_tmpa_tl {1}} {\tl_item:Nn
- \l__spath_tmpb_tl {1}}}
- \dim_set:Nn \l__spath_tmpb_dim {\dim_min:nn {\tl_item:Nn
- \l__spath_tmpa_tl {2}} {\tl_item:Nn
- \l__spath_tmpb_tl {2}}}
- \spath_put:nnx {#1} {max bb} {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- }
- {
- \spath_remove:nn {#1} {max bb}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {reverse path}
- &&
- \spath_if_in_p:nn {#2} {reverse path}
- }
- {
- \__spath_get:nnN {#2} {reverse path} \l__spath_tmpa_tl
- \__spath_get:nnN {#1} {reverse path} \l__spath_tmpb_tl
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
- \spath_put:nnV {#1} {reverse path} \l__spath_tmpb_tl
- }
- {
- \spath_remove:nn {#1} {reverse path}
- }
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_bake_round:n}
-% Ought to clear the reverse path, if set.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_bake_round:n #1
-{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \pgf@@processround\l__spath_tmpa_tl\l__spath_tmpb_tl
- \spath_put:nnV {#1} {path} \l__spath_tmpb_tl
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_close_path:n}
-% Appends a close path to the end of the path, and to the end of the reverse path.
-% For now, the point is the initial or final point (respectively).
-% To be future proof, it ought to be the point of the adjacent move to.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_close_path:n #1
-{
- \spath_get:nnN {#1} {initial point} \l__spath_tmpb_tl
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_closepath_tl
- \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
- \spath_put:nnV {#1} {path} \l__spath_tmpa_tl
- \spath_if_in:nnT {#1} {reverse path}
- {
- \spath_get:nnN {#1} {final point} \l__spath_tmpb_tl
- \__spath_get:nnN {#1} {reverse path} \l__spath_tmpa_tl
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_closepath_tl
- \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
- \spath_put:nnV {#1} {reverse path} \l__spath_tmpa_tl
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \subsection{Iteration Functions}
-%
-% \begin{macro}{\spath_map_component:Nn}
-% This iterates through the components of a path, applying the inline function to each.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_map_component:Nn #1#2
-{
- \int_gincr:N \g__spath_map_int
- \cs_gset:cpn { __spath_map_ \int_use:N \g__spath_map_int :w } ##1 {#2}
- \tl_set:NV \l__spath_tmpa_tl #1
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_moveto_tl
- \tl_set_eq:NN \l__spath_tmpb_tl \g__spath_moveto_tl
- \bool_until_do:nn {
- \tl_if_empty_p:N \l__spath_tmpa_tl
- }
- {
- \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_if_eq:NNT \l__spath_tmpc_tl \g__spath_moveto_tl
- {
- \exp_args:NnV \use:c { __spath_map_ \int_use:N \g__spath_map_int :w } \l__spath_tmpb_tl
-\tl_clear:N \l__spath_tmpb_tl
- }
- \tl_if_single:NTF \l__spath_tmpc_tl
- {
- \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpc_tl
- }
- {
- \tl_put_right:Nx \l__spath_tmpb_tl {{\l__spath_tmpc_tl}}
- }
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_map_segment_inline:Nn}
-% This iterates through the segments of the path, applying the inline function to each.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_map_segment_inline:Nn #1#2
-{
- \int_gincr:N \g__spath_map_int
- \cs_gset:cpn { __spath_map_ \int_use:N \g__spath_map_int :w } ##1 ##2 {#2}
- \spath_map_segment_function:Nc #1 { __spath_map_ \int_use:N \g__spath_map_int :w }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_map_segment_inline:nn}
-% This iterates through the segments of the path of the \Verb+spath+ object, applying the inline function to each.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_map_segment_inline:nn #1#2
-{
- \int_gincr:N \g__spath_map_int
- \cs_gset:cpn { __spath_map_ \int_use:N \g__spath_map_int :w } ##1 ##2 {#2}
- \spath_get:nnN {#1} {path} \l__spath_tmpd_tl
- \spath_map_segment_function:Nc \l__spath_tmpd_tl { __spath_map_ \int_use:N \g__spath_map_int :w }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\spath_map_segment_function:nN}
-% This iterates through the segments of the path of the \Verb+spath+ object, applying the specified function to each.
-% The specified function should take two \Verb+N+ type arguments.
-% The first is a token representing the type of path segment, the second is the path segment itself.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_map_segment_function:nN #1#2
-{
- \spath_get:nnN {#1} {path} \l__spath_tmpd_tl
- \spath_map_segment_function:NN \l__spath_tmpd_tl #2
-}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_map_segment_function:NN #1#2
-{
- \tl_set_eq:NN \l__spath_tmpa_tl #1
- \tl_clear:N \l__spath_tmpb_tl
- \dim_zero:N \l__spath_tmpa_dim
- \dim_zero:N \l__spath_tmpb_dim
-
- \bool_until_do:nn {
- \tl_if_empty_p:N \l__spath_tmpa_tl
- }
- {
- \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_case:NnF \l__spath_tmpc_tl
- {
- \g__spath_lineto_tl
- {
- \tl_set_eq:NN \l__spath_tmpb_tl \g__spath_moveto_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- \tl_put_right:NV \l__spath_tmpb_tl \g__spath_lineto_tl
-
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- }
-
- \g__spath_curvetoa_tl
- {
- \tl_set_eq:NN \l__spath_tmpb_tl \g__spath_moveto_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- \tl_put_right:NV \l__spath_tmpb_tl \g__spath_curvetoa_tl
-
- \prg_replicate:nn {2} {
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- }
-
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- }
-
- \g__spath_closepath_tl
- {
- \tl_set_eq:NN \l__spath_tmpb_tl \g__spath_moveto_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- \tl_put_right:NV \l__spath_tmpb_tl \g__spath_lineto_tl
-
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- }
-
- }
- {
-
- \tl_set_eq:NN \l__spath_tmpb_tl \l__spath_tmpc_tl
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- }
-
- #2 \l__spath_tmpc_tl \l__spath_tmpb_tl
- \tl_clear:N \l__spath_tmpb_tl
-
- }
-}
-\cs_generate_variant:Nn \spath_map_segment_function:NN {Nc}
-% \end{macrocode}
-% \end{macro}
-%
-% \subsection{Public Commands}
-%
-% The next functions are more ``public'' than the previous lot.
-% That said, they aren't intended for direct use in a normal document.
-%
-% Most are just wrappers around internal functions.
-%
-% \begin{macro}{\MakeSPath}
-% Constructs an \Verb+spath+ object out of the given name and path.
-% \begin{macrocode}
-\NewDocumentCommand \MakeSPath { m m }
-{
- \spath_clear_new:n {#1}
- \spath_put:nno {#1} {path} {#2}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\MakeSPathList}
-% This constructs a list of \Verb+spath+ objects from a single path by splitting it into components.
-% \begin{macrocode}
-\NewDocumentCommand \MakeSPathList { m m }
-{
- \tl_gclear_new:c {l__spath_list_#1}
- \int_zero:N \l__spath_tmpa_int
- \spath_map_component:Nn #2 {
- \spath_clear_new:n {#1 _ \int_use:N \l__spath_tmpa_int}
- \spath_put:nnn {#1 _ \int_use:N \l__spath_tmpa_int} {path} {##1}
- \tl_gput_right:cx {l__spath_list_#1} {{#1 _ \int_use:N \l__spath_tmpa_int}}
- \int_incr:N \l__spath_tmpa_int
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\CloneSPath}
-% \begin{macrocode}
-\NewDocumentCommand \CloneSPath { m m }
-{
- \spath_clone:nn {#1} {#2}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\SPathInfo}
-% \begin{macrocode}
-\NewDocumentCommand \SPathInfo { m m }
-{
- \spath_get:nn {#1} {#2}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\SPathPrepare}
-% \begin{macrocode}
-\NewDocumentCommand \SPathPrepare { m }
-{
- \spath_generate_all:n {#1}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\SPathListPrepare}
-% \begin{macrocode}
-\NewDocumentCommand \SPathListPrepare { m }
-{
- \tl_map_inline:cn {l__spath_list_#1}
- {
- \spath_generate_all:n {##1}
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\SPathInfoInto}
-% \begin{macrocode}
-\NewDocumentCommand \SPathInfoInto { m m m }
-{
- \tl_clear_new:N #3
- \spath_get:nnN {#1} {#2} #3
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\SPathShow}
-% \begin{macrocode}
-\NewDocumentCommand \SPathShow { m }
-{
- \spath_show:n {#1}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\SPathTranslate}
-% \begin{macrocode}
-\NewDocumentCommand \SPathTranslate { m m m }
-{
- \spath_translate:nnn {#1} {#2} {#3}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\SPathTranslateInto}
-% Clones the path before translating it.
-% \begin{macrocode}
-\NewDocumentCommand \SPathTranslateInto { m m m m }
-{
- \spath_clone:nn {#1} {#2}
- \spath_translate:nnn {#2} {#3} {#4}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\SPathScale}
-% \begin{macrocode}
-\NewDocumentCommand \SPathScale { m m m }
-{
- \spath_scale:nnn {#1} {#2} {#3}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\SPathScaleInto}
-% Clones the path first.
-% \begin{macrocode}
-\NewDocumentCommand \SPathScaleInto { m m m m }
-{
- \spath_clone:nn {#1} {#2}
- \spath_scale:nnn {#2} {#3} {#4}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\SPathWeld}
-% \begin{macrocode}
-\NewDocumentCommand \SPathWeld { m m }
-{
- \spath_weld:nn {#1} {#2}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\SPathWeldInto}
-% \begin{macrocode}
-\NewDocumentCommand \SPathWeldInto { m m m }
-{
- \spath_clone:nn {#1} {#2}
- \spath_weld:nn {#2} {#3}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% Interfaces via TikZ keys.
-% \begin{macrocode}
-\tikzset{
- save~spath/.code={
- \tikz at addmode{
- \spath_get_current_path:n {#1}
- }
- },
- restore~spath/.code={
- \spath_set_current_path:n {#1}
- }
-}
-% \end{macrocode}
-% \subsection{Miscellaneous Commands}
-%
-% \begin{macro}{\spath_split_curve:nnNN}
-% Splits a Bezier cubic into pieces.
-% \begin{macrocode}
-\cs_new_nopar:Npn \spath_split_curve:nnNN #1#2#3#4
-{
- \group_begin:
- \tl_gclear:N \l__spath_smuggle_tl
- \tl_set_eq:NN \l__spath_tmpa_tl \g__spath_moveto_tl
- \tl_put_right:Nx \l__spath_tmpa_tl {
- {\tl_item:nn {#2} {2}}
- {\tl_item:nn {#2} {3}}
- }
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_curvetoa_tl
- \tl_put_right:Nx \l__spath_tmpa_tl
- {
- {\fp_to_dim:n
- {
- (1 - #1) * \tl_item:nn {#2} {2} + (#1) * \tl_item:nn {#2} {5}
- }}
- {\fp_to_dim:n
- {
- (1 - #1) * \tl_item:nn {#2} {3} + (#1) * \tl_item:nn {#2} {6}
- }}
- }
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_curvetob_tl
- \tl_put_right:Nx \l__spath_tmpa_tl
- {
- {\fp_to_dim:n
- {
- (1 - #1)^2 * \tl_item:nn {#2} {2} + 2 * (1 - #1) * (#1) * \tl_item:nn {#2} {5} + (#1)^2 * \tl_item:nn {#2} {8}
- }}
- {\fp_to_dim:n
- {
- (1 - #1)^2 * \tl_item:nn {#2} {3} + 2 * (1 - #1) * (#1) * \tl_item:nn {#2} {6} + (#1)^2 * \tl_item:nn {#2} {9}
- }}
- }
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_curveto_tl
- \tl_put_right:Nx \l__spath_tmpa_tl
- {
- {\fp_to_dim:n
- {
- (1 - #1)^3 * \tl_item:nn {#2} {2} + 3 * (1 - #1)^2 * (#1) * \tl_item:nn {#2} {5} + 3 * (1 - #1) * (#1)^2 * \tl_item:nn {#2} {8} + (#1)^3 * \tl_item:nn {#2} {11}
- }}
- {\fp_to_dim:n
- {
- (1 - #1)^3 * \tl_item:nn {#2} {3} + 3 * (1 - #1)^2 * (#1) * \tl_item:nn {#2} {6} + 3 * (1 - #1) * (#1)^2 * \tl_item:nn {#2} {9} + (#1)^3 * \tl_item:nn {#2} {12}
- }}
- }
- \tl_gset_eq:NN \l__spath_smuggle_tl \l__spath_tmpa_tl
- \group_end:
- \tl_set_eq:NN #3 \l__spath_smuggle_tl
- \group_begin:
- \tl_set_eq:NN \l__spath_tmpa_tl \g__spath_moveto_tl
- \tl_put_right:Nx \l__spath_tmpa_tl
- {
- {\fp_to_dim:n
- {
- (1 - #1)^3 * \tl_item:nn {#2} {2} + 3 * (1 - #1)^2 * (#1) * \tl_item:nn {#2} {5} + 3 * (1 - #1) * (#1)^2 * \tl_item:nn {#2} {8} + (#1)^3 * \tl_item:nn {#2} {11}
- }}
- {\fp_to_dim:n
- {
- (1 - #1)^3 * \tl_item:nn {#2} {3} + 3 * (1 - #1)^2 * (#1) * \tl_item:nn {#2} {6} + 3 * (1 - #1) * (#1)^2 * \tl_item:nn {#2} {9} + (#1)^3 * \tl_item:nn {#2} {12}
- }}
- }
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_curvetoa_tl
- \tl_put_right:Nx \l__spath_tmpa_tl
- {
- {\fp_to_dim:n
- {
- (1 - #1)^2 * \tl_item:nn {#2} {5} + 2 * (1 - #1) * (#1) * \tl_item:nn {#2} {8} + (#1)^2 * \tl_item:nn {#2} {11}
- }}
- {\fp_to_dim:n
- {
- (1 - #1)^2 * \tl_item:nn {#2} {6} + 2 * (1 - #1) * (#1) * \tl_item:nn {#2} {9} + (#1)^2 * \tl_item:nn {#2} {12}
- }}
- }
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_curvetob_tl
- \tl_put_right:Nx \l__spath_tmpa_tl
- {
- {\fp_to_dim:n
- {
- (1 - #1) * \tl_item:nn {#2} {8} + (#1) * \tl_item:nn {#2} {11}
- }}
- {\fp_to_dim:n
- {
- (1 - #1) * \tl_item:nn {#2} {9} + (#1) * \tl_item:nn {#2} {12}
- }}
- }
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_curveto_tl
- \tl_put_right:Nx \l__spath_tmpa_tl {
- {\tl_item:nn {#2} {11}}
- {\tl_item:nn {#2} {12}}
- }
- \tl_gset_eq:NN \l__spath_smuggle_tl \l__spath_tmpa_tl
- \group_end:
- \tl_set_eq:NN #4 \l__spath_smuggle_tl
-}
-
-\cs_generate_variant:Nn \spath_split_curve:nnNN {nVNN, VVNN}
-% \end{macrocode}
-% \end{macro}
-% \iffalse
-%</spath3>
-% \fi
-%
-% \iffalse
-%<*calligraphy>
-% \fi
-%
-% \section{The Calligraphy Package}
-%
-% \subsection{Initialisation}
-% \begin{macrocode}
-\RequirePackage{spath3}
-\ExplSyntaxOn
-
-\tl_new:N \l__cal_tmpa_tl
-\tl_new:N \l__cal_tmpb_tl
-\int_new:N \l__cal_tmpa_int
-\int_new:N \l__cal_tmpb_int
-\int_new:N \l__cal_path_component_int
-\int_new:N \l__cal_label_int
-\dim_new:N \l__cal_tmpa_dim
-\dim_new:N \l__cal_tmpb_dim
-\dim_new:N \l__cal_tmpc_dim
-\dim_new:N \l__cal_tmpd_dim
-\dim_new:N \l__cal_tmpe_dim
-\dim_new:N \l__cal_tmpf_dim
-\dim_new:N \l__cal_tmpg_dim
-\dim_new:N \l__cal_tmph_dim
-\bool_new:N \l__cal_annotate_bool
-\bool_new:N \l__cal_taper_start_bool
-\bool_new:N \l__cal_taper_end_bool
-\bool_new:N \l__cal_taperable_bool
-\dim_new:N \l__cal_taper_width_dim
-\dim_new:N \l__cal_line_width_dim
-
-\bool_set_true:N \l__cal_taper_start_bool
-\bool_set_true:N \l__cal_taper_end_bool
-
-\cs_generate_variant:Nn \tl_put_right:Nn {Nv}
-% \end{macrocode}
-%
-% \subsection{TikZ Keys}
-%
-% The public interface to this package is through TikZ keys and styles.
-% \begin{macrocode}
-\tikzset{
- define~pen/.code={
- \tikzset{pen~name=#1}
- \pgf at relevantforpicturesizefalse
- \tikz at addmode{
- \pgfsyssoftpath at getcurrentpath\l__cal_tmpa_tl
- \MakeSPathList{calligraphy pen \pgfkeysvalueof{/tikz/pen~name}}{\l__cal_tmpa_tl}
- \SPathListPrepare{calligraphy pen \pgfkeysvalueof{/tikz/pen~name}}
- \pgfusepath{discard}%
- }
- },
- define~pen/.default={default},
- use~pen/.code={
- \tikzset{pen~name=#1}
- \int_gzero:N \l__cal_path_component_int
- \cs_set_eq:NN \pgfpathmoveto \cal_moveto:n
- \tikz at addmode{
- \pgfsyssoftpath at getcurrentpath\l__cal_tmpa_tl
- \MakeSPathList{calligraphy path}{\l__cal_tmpa_tl}
- \SPathListPrepare{calligraphy path}
- \CalligraphyPathCreate{calligraphy path}{\pgfkeysvalueof{/tikz/pen~name}}
- }
- },
- use~pen/.default={default},
- pen~name/.initial={default},
- copperplate/.style={pen~name=copperplate},
- pen~colour/.initial={black},
- weight/.is~choice,
- weight/heavy/.style={
- line~width=\pgfkeysvalueof{/tikz/heavy~line~width},
- taper~width=\pgfkeysvalueof{/tikz/light~line~width},
- },
- weight/light/.style={
- line~width=\pgfkeysvalueof{/tikz/light~line~width},
- taper~width=0pt,
- },
- heavy/.style={
- weight=heavy
- },
- light/.style={
- weight=light
- },
- heavy~line~width/.initial=2pt,
- light~line~width/.initial=1pt,
- taper/.is~choice,
- taper/.default=both,
- taper/none/.style={
- taper~start=false,
- taper~end=false,
- },
- taper/both/.style={
- taper~start=true,
- taper~end=true,
- },
- taper/start/.style={
- taper~start=true,
- taper~end=false,
- },
- taper/end/.style={
- taper~start=false,
- taper~end=true,
- },
- taper~start/.code={
- \tl_if_eq:nnTF {#1} {true}
- {
- \bool_set_true:N \l__cal_taper_start_bool
- }
- {
- \bool_set_false:N \l__cal_taper_start_bool
- }
- },
- taper~start/.default={true},
- taper~end/.code={
- \tl_if_eq:nnTF {#1} {true}
- {
- \bool_set_true:N \l__cal_taper_end_bool
- }
- {
- \bool_set_false:N \l__cal_taper_end_bool
- }
- },
- taper~end/.default={true},
- taper~width/.code={\dim_set:Nn \l__cal_taper_width_dim {#1}},
- nib~style/.code~2~args={
- \tl_clear_new:c {l__cal_nib_style_#1}
- \tl_set:cn {l__cal_nib_style_#1} {#2}
- },
- stroke~style/.code~2~args={
- \tl_clear_new:c {l__cal_stroke_style_#1}
- \tl_set:cn {l__cal_stroke_style_#1} {#2}
- },
- this~stroke~style/.code={
- \tl_clear_new:c {l__cal_stroke_inline_style_ \int_use:N \l__cal_path_component_int}
- \tl_set:cn {l__cal_stroke_inline_style_ \int_use:N \l__cal_path_component_int} {#1}
- },
- annotate/.style={
- annotate~if,
- annotate~reset,
- annotation~style/.update~value={#1},
- },
- annotate~if/.default={true},
- annotate~if/.code={
- \tl_if_eq:nnTF {#1} {true}
- {
- \bool_set_true:N \l__cal_annotate_bool
- }
- {
- \bool_set_false:N \l__cal_annotate_bool
- }
- },
- annotate~reset/.code={
- \int_gzero:N \l__cal_label_int
- },
- annotation~style/.initial={draw,->},
- annotation~shift/.initial={(0,1ex)},
- every~annotation~node/.initial={anchor=south~west},
- annotation~node~style/.code~2~args={
- \tl_set:cn {l__cal_annotation_style_ #1 _tl}{#2}
- },
- tl~use:N/.code={
- \exp_args:NV \pgfkeysalso #1
- },
- tl~use:c/.code={
- \tl_if_exist:cT {#1}
- {
- \exp_args:Nv \pgfkeysalso {#1}
- }
- },
- /handlers/.update~style/.code={
- \tl_if_eq:nnF {#1} {\pgfkeysnovalue}
- {
- \pgfkeys{\pgfkeyscurrentpath/.code=\pgfkeysalso{#1}}
- }
- },
- /handlers/.update~value/.code={
- \tl_if_eq:nnF {#1} {\pgfkeysnovalue}
- {
- \pgfkeyssetvalue{\pgfkeyscurrentpath}{#1}
- }
- }
-}
-% \end{macrocode}
-%
-% Some wrappers around the TikZ keys.
-% \begin{macrocode}
-\NewDocumentCommand \pen { O{} }
-{
- \path[define~ pen,every~ calligraphy~ pen/.try,#1]
-}
-
-\NewDocumentCommand \definepen { O{} }
-{
- \tikz \path[define~ pen,every~ calligraphy~ pen/.try,#1]
-}
-
-\NewDocumentCommand \calligraphy { O{} }
-{
- \path[use~ pen,every~ calligraphy/.try,#1]
-}
-% \end{macrocode}
-%
-% \subsection{The Path Creation}
-%
-% \begin{macro}{\CalligraphyPathCreate}
-% This is the main command for creating the calligraphic paths.
-% \begin{macrocode}
-\NewDocumentCommand \CalligraphyPathCreate { m m }
-{
- \int_zero:N \l__cal_tmpa_int
- \tl_map_inline:cn {l__spath_list_#1}
- {
- \int_incr:N \l__cal_tmpa_int
- \int_zero:N \l__cal_tmpb_int
- \tl_map_inline:cn {l__spath_list_calligraphy pen #2}
- {
- \int_incr:N \l__cal_tmpb_int
- \group_begin:
- \pgfsys at beginscope
-
- \cal_apply_style:c {l__cal_stroke_style_ \int_use:N \l__cal_tmpa_int}
- \cal_apply_style:c {l__cal_stroke_inline_style_ \int_use:N \l__cal_tmpa_int}
- \cal_apply_style:c {l__cal_nib_style_ \int_use:N \l__cal_tmpb_int}
-
- \spath_clone:nn {##1} {calligraphy temp path}
-
- \__spath_get:nnN {####1} {initial point} \l__cal_tmpa_tl
- \spath_translate:nV {calligraphy temp path} \l__cal_tmpa_tl
-
- \__spath_get:nnN {####1} {length} \l__cal_tmpa_tl
-
- \int_compare:nTF {\l__cal_tmpa_tl = 1}
- {
- \cal_at_least_three:n {calligraphy temp path}
-
- \spath_protocol_path:n {calligraphy temp path}
-
- \__spath_get:nnN {calligraphy temp path} {path} \l__cal_tmpa_tl
-
- \tikz at options
- \dim_set:Nn \l__cal_line_width_dim {\pgflinewidth}
- \cal_maybe_taper:N \l__cal_tmpa_tl
- }
- {
-
- \spath_weld:nn {calligraphy temp path} {####1}
- \spath_reverse:n {##1}
- \spath_reverse:n {####1}
- \spath_weld:nn {calligraphy temp path} {##1}
- \spath_weld:nn {calligraphy temp path} {####1}
- \spath_reverse:n {##1}
- \spath_reverse:n {####1}
-
- \tl_clear:N \l__cal_tmpa_tl
- \tl_set:Nn \l__cal_tmpa_tl {fill=\pgfkeysvalueof{/tikz/pen~colour},draw=none}
- \tl_if_exist:cT {l__cal_stroke_style_ \int_use:N \l__cal_tmpa_int}
- {
- \tl_put_right:Nv \l__cal_tmpa_tl {l__cal_stroke_style_ \int_use:N \l__cal_tmpa_int}
- }
- \tl_if_exist:cT {l__cal_stroke_inline_style_ \int_use:N \l__cal_tmpa_int}
- {
- \tl_put_right:Nn \l__cal_tmpa_tl {,}
- \tl_put_right:Nv \l__cal_tmpa_tl {l__cal_stroke_inline_style_ \int_use:N \l__cal_tmpa_int}
- }
- \tl_if_exist:cT {l__cal_nib_style_ \int_use:N \l__cal_tmpb_int}
- {
- \tl_put_right:Nn \l__cal_tmpa_tl {,}
- \tl_put_right:Nv \l__cal_tmpa_tl {l__cal_nib_style_ \int_use:N \l__cal_tmpb_int}
- }
- \spath_tikz_path:Vn \l__cal_tmpa_tl {calligraphy temp path}
-
- }
- \pgfsys at endscope
- \group_end:
- }
- \bool_if:NT \l__cal_annotate_bool
- {
- \spath_clone:nn {##1} {calligraphy temp path}
- \tl_set_eq:Nc \l_tmpa_tl {l__spath_list_calligraphy pen #2}
- \tl_reverse:N \l_tmpa_tl
- \tl_set:Nx \l_tmpa_tl {\tl_head:N \l_tmpa_tl}
- \spath_generate_finalpoint:V \l_tmpa_tl
- \spath_get:VnN \l_tmpa_tl {final point} \l_tmpa_tl
- \spath_translate:nV {calligraphy temp path} \l_tmpa_tl
- \tikz at scan@one at point\pgfutil at firstofone\pgfkeysvalueof{/tikz/annotation~shift}
- \spath_translate:nnn {calligraphy temp path} {\pgf at x} {\pgf at y}
-
- \pgfkeysgetvalue{/tikz/annotation~style}{\l_tmpa_tl}
- \spath_tikz_path:Vn \l_tmpa_tl {calligraphy temp path}
- \spath_get:nnN {calligraphy temp path} {final point} \l_tmpa_tl
- \exp_last_unbraced:NV \pgfqpoint \l_tmpa_tl
- \begin{scope}[reset~ cm]
- \node[every~annotation~node/.try,tl~use:c = {l__cal_annotation_style_ \int_use:N \l__cal_tmpa_int _tl}] at (\pgf at x,\pgf at y) {\int_use:N \l__cal_tmpa_int};
- \end{scope}
- }
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\cal_moveto:n}
-% When creating the path, we need to keep track of the number of components so that we can apply styles accordingly.
-% \begin{macrocode}
-\cs_new_eq:NN \cal_orig_moveto:n \pgfpathmoveto
-\cs_new_nopar:Npn \cal_moveto:n #1
-{
- \int_gincr:N \l__cal_path_component_int
- \cal_orig_moveto:n {#1}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\cal_apply_style:N}
-% Interface for applying \Verb+\tikzset+ to a token list.
-% \begin{macrocode}
-\cs_new_nopar:Npn \cal_apply_style:N #1
-{
- \tl_if_exist:NT #1 {
- \exp_args:NV \tikzset #1
- }
-}
-\cs_generate_variant:Nn \cal_apply_style:N {c}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\cal_at_least_three:n}
-% A tapered path has to have at least three components.
-% This figures out if it is necessary and sets up the splitting.
-% \begin{macrocode}
-\cs_new_nopar:Npn \cal_at_least_three:n #1
-{
- \spath_get:nnN {#1} {real length} \l__cal_tmpa_tl
- \tl_clear:N \l__cal_tmpb_tl
- \int_compare:nTF {\l__cal_tmpa_tl = 1}
- {
- \spath_get:nnN {#1} {path} \l__cal_tmpa_tl
- \spath_map_segment_inline:Nn \l__cal_tmpa_tl
- {
- \tl_case:NnF ##1 {
- \g__spath_lineto_tl {
- \cal_split_line_in_three:NN \l__cal_tmpb_tl ##2
- }
- \g__spath_curvetoa_tl {
- \cal_split_curve_in_three:NN \l__cal_tmpb_tl ##2
- }
- }
- {
- \tl_put_right:NV \l__cal_tmpb_tl ##2
- }
- }
- \spath_put:nnV {#1} {path} \l__cal_tmpb_tl
- }
- {
- \int_compare:nT {\l__cal_tmpa_tl = 2}
- {
- \spath_get:nnN {#1} {path} \l__cal_tmpa_tl
- \spath_map_segment_inline:Nn \l__cal_tmpa_tl
- {
- \tl_case:NnF ##1 {
- \g__spath_lineto_tl {
- \cal_split_line_in_two:NN \l__cal_tmpb_tl ##2
- }
- \g__spath_curvetoa_tl {
- \cal_split_curve_in_two:NN \l__cal_tmpb_tl ##2
- }
- }
- {
- \tl_put_right:NV \l__cal_tmpb_tl ##2
- }
- }
- \spath_put:nnV {#1} {path} \l__cal_tmpb_tl
- }
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\cal_split_line_in_two:NN}
-% Splits a line in two, adding the splits to the first token list.
-% \begin{macrocode}
-\cs_new_nopar:Npn \cal_split_line_in_two:NN #1#2
-{
- \tl_set_eq:NN \l__cal_tmpc_tl #2
-
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \dim_set:Nn \l__cal_tmpa_dim {\tl_head:N \l__cal_tmpc_tl}
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \dim_set:Nn \l__cal_tmpb_dim {\tl_head:N \l__cal_tmpc_tl}
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \dim_set:Nn \l__cal_tmpc_dim {\tl_head:N \l__cal_tmpc_tl}
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
- \dim_set:Nn \l__cal_tmpd_dim {\tl_head:N \l__cal_tmpc_tl}
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \tl_put_right:NV #1 \g__spath_lineto_tl
-
- \tl_put_right:Nx #1 {
- {\dim_eval:n {(\l__cal_tmpa_dim + \l__cal_tmpc_dim)/2}}
- {\dim_eval:n {(\l__cal_tmpb_dim + \l__cal_tmpd_dim)/2}}
- }
-
- \tl_put_right:NV #1 \g__spath_lineto_tl
- \tl_put_right:Nx #1 {
- {\dim_use:N \l__cal_tmpc_dim}
- {\dim_use:N \l__cal_tmpd_dim}
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\cal_split_line_in_three:NN}
-% Splits a line in three, adding the splits to the first token list.
-% \begin{macrocode}
-\cs_new_nopar:Npn \cal_split_line_in_three:NN #1#2
-{
- \tl_set_eq:NN \l__cal_tmpc_tl #2
-
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \dim_set:Nn \l__cal_tmpa_dim {\tl_head:N \l__cal_tmpc_tl}
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \dim_set:Nn \l__cal_tmpb_dim {\tl_head:N \l__cal_tmpc_tl}
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \dim_set:Nn \l__cal_tmpc_dim {\tl_head:N \l__cal_tmpc_tl}
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
- \dim_set:Nn \l__cal_tmpd_dim {\tl_head:N \l__cal_tmpc_tl}
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \tl_put_right:NV #1 \g__spath_lineto_tl
-
- \tl_put_right:Nx #1 {
- {\dim_eval:n {(2\l__cal_tmpa_dim + \l__cal_tmpc_dim)/3}}
- {\dim_eval:n {(2\l__cal_tmpb_dim + \l__cal_tmpd_dim)/3}}
- }
-
- \tl_put_right:NV #1 \g__spath_lineto_tl
-
- \tl_put_right:Nx #1 {
- {\dim_eval:n {(\l__cal_tmpa_dim + 2\l__cal_tmpc_dim)/3}}
- {\dim_eval:n {(\l__cal_tmpb_dim + 2\l__cal_tmpd_dim)/3}}
- }
-
- \tl_put_right:NV #1 \g__spath_lineto_tl
- \tl_put_right:Nx #1 {
- {\dim_use:N \l__cal_tmpc_dim}
- {\dim_use:N \l__cal_tmpd_dim}
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\cal_split_curve_in_two:NN}
-% Splits a curve in two, adding the splits to the first token list.
-% \begin{macrocode}
-\cs_new_nopar:Npn \cal_split_curve_in_two:NN #1#2
-{
- \spath_split_curve:nVNN {.5} #2 \l_tmpa_tl \l_tmpb_tl
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_put_right:NV #1 \l_tmpa_tl
- \tl_put_right:NV #1 \l_tmpb_tl
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\cal_split_curve_in_three:NN}
-% Splits a curve in three, adding the splits to the first token list.
-% \begin{macrocode}
-\cs_new_nopar:Npn \cal_split_curve_in_three:NN #1#2
-{
- \spath_split_curve:nVNN {1/3} #2 \l_tmpa_tl \l_tmpb_tl
-
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_put_right:NV #1 \l_tmpa_tl
-
- \spath_split_curve:nVNN {.5} \l_tmpb_tl \l_tmpa_tl \l_tmpb_tl
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_put_right:NV #1 \l_tmpa_tl
- \tl_put_right:NV #1 \l_tmpb_tl
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\cal_maybe_taper:N}
-% Possibly tapers the path, depending on the booleans.
-% \begin{macrocode}
-\cs_new_nopar:Npn \cal_maybe_taper:N #1
-{
- \tl_set_eq:NN \l__cal_tmpa_tl #1
-
- \bool_if:NT \l__cal_taper_start_bool
- {
-
- \dim_set:Nn \l__cal_tmpa_dim {\tl_item:Nn \l__cal_tmpa_tl {2}}
- \dim_set:Nn \l__cal_tmpb_dim {\tl_item:Nn \l__cal_tmpa_tl {3}}
- \tl_set:Nx \l__cal_tmpb_tl {\tl_item:Nn \l__cal_tmpa_tl {4}}
-
- \tl_case:NnF \l__cal_tmpb_tl
- {
- \g__spath_lineto_tl
- {
-
- \bool_set_true:N \l__cal_taperable_bool
- \dim_set:Nn \l__cal_tmpg_dim {\tl_item:Nn \l__cal_tmpa_tl {5}}
- \dim_set:Nn \l__cal_tmph_dim {\tl_item:Nn \l__cal_tmpa_tl {6}}
- \dim_set:Nn \l__cal_tmpc_dim {(2\l__cal_tmpa_dim + \l__cal_tmpg_dim)/3}
- \dim_set:Nn \l__cal_tmpd_dim {(2\l__cal_tmpb_dim + \l__cal_tmph_dim)/3}
- \dim_set:Nn \l__cal_tmpe_dim {(\l__cal_tmpa_dim + 2\l__cal_tmpg_dim)/3}
- \dim_set:Nn \l__cal_tmpf_dim {(\l__cal_tmpb_dim + 2\l__cal_tmph_dim)/3}
- \prg_replicate:nn {4}
- {
- \tl_set:Nx \l__cal_tmpa_tl {\tl_tail:N \l__cal_tmpa_tl}
- }
- \tl_put_left:NV \l__cal_tmpa_tl \g__spath_moveto_tl
- }
- \g__spath_curvetoa_tl
- {
- \bool_set_true:N \l__cal_taperable_bool
- \dim_set:Nn \l__cal_tmpc_dim {\tl_item:Nn \l__cal_tmpa_tl {5}}
- \dim_set:Nn \l__cal_tmpd_dim {\tl_item:Nn \l__cal_tmpa_tl {6}}
- \dim_set:Nn \l__cal_tmpe_dim {\tl_item:Nn \l__cal_tmpa_tl {8}}
- \dim_set:Nn \l__cal_tmpf_dim {\tl_item:Nn \l__cal_tmpa_tl {9}}
- \dim_set:Nn \l__cal_tmpg_dim {\tl_item:Nn \l__cal_tmpa_tl {11}}
- \dim_set:Nn \l__cal_tmph_dim {\tl_item:Nn \l__cal_tmpa_tl {12}}
- \prg_replicate:nn {10}
- {
- \tl_set:Nx \l__cal_tmpa_tl {\tl_tail:N \l__cal_tmpa_tl}
- }
- \tl_put_left:NV \l__cal_tmpa_tl \g__spath_moveto_tl
- }
- }
- {
- \bool_set_false:N \l__cal_taperable_bool
- }
-
- \bool_if:NT \l__cal_taperable_bool
- {
- \__cal_taper_aux:
- }
-
- }
-
- \bool_if:NT \l__cal_taper_end_bool
- {
-
- \dim_set:Nn \l__cal_tmpa_dim {\tl_item:Nn \l__cal_tmpa_tl {-2}}
- \dim_set:Nn \l__cal_tmpb_dim {\tl_item:Nn \l__cal_tmpa_tl {-1}}
- \tl_set:Nx \l__cal_tmpb_tl {\tl_item:Nn \l__cal_tmpa_tl {-3}}
-
- \tl_case:NnF \l__cal_tmpb_tl
- {
- \g__spath_lineto_tl
- {
-
- \bool_set_true:N \l__cal_taperable_bool
- \dim_set:Nn \l__cal_tmpg_dim {\tl_item:Nn \l__cal_tmpa_tl {-5}}
- \dim_set:Nn \l__cal_tmph_dim {\tl_item:Nn \l__cal_tmpa_tl {-4}}
- \dim_set:Nn \l__cal_tmpc_dim {(2\l__cal_tmpa_dim + \l__cal_tmpg_dim)/3}
- \dim_set:Nn \l__cal_tmpd_dim {(2\l__cal_tmpb_dim + \l__cal_tmph_dim)/3}
- \dim_set:Nn \l__cal_tmpe_dim {(\l__cal_tmpa_dim + 2\l__cal_tmpg_dim)/3}
- \dim_set:Nn \l__cal_tmpf_dim {(\l__cal_tmpb_dim + 2\l__cal_tmph_dim)/3}
- \tl_reverse:N \l__cal_tmpa_tl
- \prg_replicate:nn {3}
- {
- \tl_set:Nx \l__cal_tmpa_tl {\tl_tail:N \l__cal_tmpa_tl}
- }
- \tl_reverse:N \l__cal_tmpa_tl
- }
- \g__spath_curveto_tl
- {
- \bool_set_true:N \l__cal_taperable_bool
- \dim_set:Nn \l__cal_tmpc_dim {\tl_item:Nn \l__cal_tmpa_tl {-5}}
- \dim_set:Nn \l__cal_tmpd_dim {\tl_item:Nn \l__cal_tmpa_tl {-4}}
- \dim_set:Nn \l__cal_tmpe_dim {\tl_item:Nn \l__cal_tmpa_tl {-8}}
- \dim_set:Nn \l__cal_tmpf_dim {\tl_item:Nn \l__cal_tmpa_tl {-7}}
- \dim_set:Nn \l__cal_tmpg_dim {\tl_item:Nn \l__cal_tmpa_tl {-11}}
- \dim_set:Nn \l__cal_tmph_dim {\tl_item:Nn \l__cal_tmpa_tl {-10}}
- \tl_reverse:N \l__cal_tmpa_tl
- \prg_replicate:nn {9}
- {
- \tl_set:Nx \l__cal_tmpa_tl {\tl_tail:N \l__cal_tmpa_tl}
- }
- \tl_reverse:N \l__cal_tmpa_tl
- }
- }
- {
- \bool_set_false:N \l__cal_taperable_bool
- }
-
- \bool_if:NT \l__cal_taperable_bool
- {
- \__cal_taper_aux:
- }
-
- }
-
- \pgfsyssoftpath at setcurrentpath\l__cal_tmpa_tl
- \pgfsetstrokecolor{\pgfkeysvalueof{/tikz/pen~colour}}
- \pgfusepath{stroke}
-
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\__cal_taper_aux:}
-% Auxiliary macro to avoid unnecessary code duplication.
-% \begin{macrocode}
-\cs_new_nopar:Npn \__cal_taper_aux:
-{
- \tl_clear:N \l__cal_tmpb_tl
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_moveto_tl
-
- \fp_set:Nn \l__cal_tmpa_fp
- {
- \l__cal_tmpd_dim - \l__cal_tmpb_dim
- }
- \fp_set:Nn \l__cal_tmpb_fp
- {
- \l__cal_tmpa_dim - \l__cal_tmpc_dim
- }
- \fp_set:Nn \l__cal_tmpe_fp
- {
- (\l__cal_tmpa_fp^2 + \l__cal_tmpb_fp^2)^.5
- }
-
- \fp_set:Nn \l__cal_tmpa_fp {.5*\l__cal_taper_width_dim * \l__cal_tmpa_fp / \l__cal_tmpe_fp}
- \fp_set:Nn \l__cal_tmpb_fp {.5*\l__cal_taper_width_dim * \l__cal_tmpb_fp / \l__cal_tmpe_fp}
-
- \fp_set:Nn \l__cal_tmpc_fp
- {
- \l__cal_tmph_dim - \l__cal_tmpf_dim
- }
- \fp_set:Nn \l__cal_tmpd_fp
- {
- \l__cal_tmpe_dim - \l__cal_tmpg_dim
- }
- \fp_set:Nn \l__cal_tmpe_fp
- {
- (\l__cal_tmpc_fp^2 + \l__cal_tmpd_fp^2)^.5
- }
-
- \fp_set:Nn \l__cal_tmpc_fp {.5*\l__cal_line_width_dim * \l__cal_tmpc_fp / \l__cal_tmpe_fp}
- \fp_set:Nn \l__cal_tmpd_fp {.5*\l__cal_line_width_dim * \l__cal_tmpd_fp / \l__cal_tmpe_fp}
-
- \tl_put_right:Nx \l__cal_tmpb_tl
- {
- {\dim_eval:n { \fp_to_dim:N \l__cal_tmpa_fp + \l__cal_tmpa_dim}}
- {\dim_eval:n { \fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpb_dim}}
- }
-
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetoa_tl
-
- \tl_put_right:Nx \l__cal_tmpb_tl
- {
- {\dim_eval:n { \fp_to_dim:N \l__cal_tmpa_fp + \l__cal_tmpc_dim}}
- {\dim_eval:n { \fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpd_dim}}
- }
-
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetob_tl
-
- \tl_put_right:Nx \l__cal_tmpb_tl
- {
- {\dim_eval:n { \fp_to_dim:N \l__cal_tmpc_fp + \l__cal_tmpe_dim}}
- {\dim_eval:n { \fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmpf_dim}}
- }
-
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curveto_tl
-
- \tl_put_right:Nx \l__cal_tmpb_tl
- {
- {\dim_eval:n { \fp_to_dim:N \l__cal_tmpc_fp + \l__cal_tmpg_dim}}
- {\dim_eval:n { \fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmph_dim}}
- }
-
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetoa_tl
-
- \tl_put_right:Nx \l__cal_tmpb_tl
- {
- {\dim_eval:n { \fp_to_dim:N \l__cal_tmpc_fp + \l__cal_tmpg_dim - \fp_to_dim:n{ 1.32 * \l__cal_tmpd_fp}}}
- {\dim_eval:n { \fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmph_dim + \fp_to_dim:n {1.32* \l__cal_tmpc_fp}}}
- }
-
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetob_tl
-
- \tl_put_right:Nx \l__cal_tmpb_tl
- {
- {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpc_fp + \l__cal_tmpg_dim - \fp_to_dim:n {1.32 * \l__cal_tmpd_fp}}}
- {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmph_dim + \fp_to_dim:n {1.32 * \l__cal_tmpc_fp}}}
- }
-
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curveto_tl
-
- \tl_put_right:Nx \l__cal_tmpb_tl
- {
- {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpc_fp + \l__cal_tmpg_dim}}
- {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmph_dim}}
- }
-
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetoa_tl
-
- \tl_put_right:Nx \l__cal_tmpb_tl
- {
- {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpc_fp + \l__cal_tmpe_dim}}
- {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmpf_dim}}
- }
-
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetob_tl
-
- \tl_put_right:Nx \l__cal_tmpb_tl
- {
- {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpa_fp + \l__cal_tmpc_dim}}
- {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpd_dim}}
- }
-
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curveto_tl
-
- \tl_put_right:Nx \l__cal_tmpb_tl
- {
- {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpa_fp + \l__cal_tmpa_dim}}
- {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpb_dim}}
- }
-
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetoa_tl
-
- \tl_put_right:Nx \l__cal_tmpb_tl
- {
- {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpa_fp + \l__cal_tmpa_dim + \fp_to_dim:n{ 1.32 * \l__cal_tmpb_fp}}}
- {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpb_dim - \fp_to_dim:n {1.32* \l__cal_tmpa_fp}}}
- }
-
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetob_tl
-
- \tl_put_right:Nx \l__cal_tmpb_tl
- {
- {\dim_eval:n { \fp_to_dim:N \l__cal_tmpa_fp + \l__cal_tmpa_dim + \fp_to_dim:n {1.32 * \l__cal_tmpb_fp}}}
- {\dim_eval:n { \fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpb_dim - \fp_to_dim:n {1.32 * \l__cal_tmpa_fp}}}
- }
-
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curveto_tl
-
- \tl_put_right:Nx \l__cal_tmpb_tl
- {
- {\dim_eval:n { \fp_to_dim:N \l__cal_tmpa_fp + \l__cal_tmpa_dim}}
- {\dim_eval:n { \fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpb_dim}}
- }
-
- \pgfsyssoftpath at setcurrentpath\l__cal_tmpb_tl
- \pgfsetfillcolor{\pgfkeysvalueof{/tikz/pen~colour}}
- \pgfusepath{fill}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% Defines a copperplate pen.
-% \begin{macrocode}
-\tl_set:Nn \l__cal_tmpa_tl {\pgfsyssoftpath at movetotoken{0pt}{0pt}}
-\MakeSPathList{calligraphy pen copperplate}{\l__cal_tmpa_tl}
-\SPathListPrepare{calligraphy pen copperplate}
-% \end{macrocode}
-%
-% \begin{macrocode}
-\ExplSyntaxOff
-% \end{macrocode}
-%
-% \subsection{Decorations}
-%
-% If a decoration library is loaded we define some decorations that use the calligraphy library, specifically the copperplate pen with its tapering.
-%
-% First, a brace decoration.
-% \begin{macrocode}
-\expandafter\ifx\csname pgfdeclaredecoration\endcsname\relax
-\else
-\pgfdeclaredecoration{calligraphic brace}{brace}
-{
- \state{brace}[width=+\pgfdecoratedremainingdistance,next state=final]
- {
- \pgfsyssoftpath at setcurrentpath{\pgfutil at empty}
- \pgfpathmoveto{\pgfpointorigin}
- \pgfpathcurveto
- {\pgfqpoint{.15\pgfdecorationsegmentamplitude}{.3\pgfdecorationsegmentamplitude}}
- {\pgfqpoint{.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
- {\pgfqpoint{\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
- {
- \pgftransformxshift{+\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance}
- \pgfpathlineto{\pgfqpoint{-\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
- \pgfpathcurveto
- {\pgfqpoint{-.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
- {\pgfqpoint{-.15\pgfdecorationsegmentamplitude}{.7\pgfdecorationsegmentamplitude}}
- {\pgfqpoint{0\pgfdecorationsegmentamplitude}{1\pgfdecorationsegmentamplitude}}
- \pgfpathmoveto{\pgfqpoint{0\pgfdecorationsegmentamplitude}{1\pgfdecorationsegmentamplitude}}
- \pgfpathcurveto
- {\pgfqpoint{.15\pgfdecorationsegmentamplitude}{.7\pgfdecorationsegmentamplitude}}
- {\pgfqpoint{.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
- {\pgfqpoint{\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
- }
- {
- \pgftransformxshift{+\pgfdecoratedremainingdistance}
- \pgfpathlineto{\pgfqpoint{-\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
- \pgfpathcurveto
- {\pgfqpoint{-.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
- {\pgfqpoint{-.15\pgfdecorationsegmentamplitude}{.3\pgfdecorationsegmentamplitude}}
- {\pgfqpoint{0pt}{0pt}}
- }
- \tikzset{
- taper width=.5\pgflinewidth,
- taper
- }%
- \pgfsyssoftpath at getcurrentpath\cal at tmp@path
- \MakeSPathList{calligraphy path}{\cal at tmp@path}%
- \SPathListPrepare{calligraphy path}%
- \CalligraphyPathCreate{calligraphy path}{copperplate}%
- }
- \state{final}{}
-}
-% \end{macrocode}
-%
-% The second is a straightened parenthesis (so that when very large it doesn't bow out too far).
-% \begin{macrocode}
-\pgfdeclaredecoration{calligraphic straight parenthesis}{brace}
-{
- \state{brace}[width=+\pgfdecoratedremainingdistance,next state=final]
- {
- \pgfsyssoftpath at setcurrentpath{\pgfutil at empty}
- \pgfpathmoveto{\pgfpointorigin}
- \pgfpathcurveto
- {\pgfqpoint{.76604\pgfdecorationsegmentamplitude}{.64279\pgfdecorationsegmentamplitude}}
- {\pgfqpoint{2.3333\pgfdecorationsegmentamplitude}{\pgfdecorationsegmentamplitude}}
- {\pgfqpoint{3.3333\pgfdecorationsegmentamplitude}{\pgfdecorationsegmentamplitude}}
- {
- \pgftransformxshift{+\pgfdecoratedremainingdistance}
- \pgfpathlineto{\pgfqpoint{-3.3333\pgfdecorationsegmentamplitude}{\pgfdecorationsegmentamplitude}}
- \pgfpathcurveto
- {\pgfqpoint{-2.3333\pgfdecorationsegmentamplitude}{\pgfdecorationsegmentamplitude}}
- {\pgfqpoint{-.76604\pgfdecorationsegmentamplitude}{.64279\pgfdecorationsegmentamplitude}}
- {\pgfqpoint{0pt}{0pt}}
- }
- \tikzset{
- taper width=.5\pgflinewidth,
- taper
- }%
- \pgfsyssoftpath at getcurrentpath\cal at tmp@path
- \MakeSPathList{calligraphy path}{\cal at tmp@path}%
- \SPathListPrepare{calligraphy path}%
- \CalligraphyPathCreate{calligraphy path}{copperplate}%
- }
- \state{final}{}%
-}
-% \end{macrocode}
-%
-% The third is a curved parenthesis.
-% \begin{macrocode}
-\pgfdeclaredecoration{calligraphic curved parenthesis}{brace}
-{
- \state{brace}[width=+\pgfdecoratedremainingdistance,next state=final]
- {
- \pgfsyssoftpath at setcurrentpath{\pgfutil at empty}
- \pgfpathmoveto{\pgfpointorigin}
- \pgf at xa=\pgfdecoratedremainingdistance\relax
- \advance\pgf at xa by -1.5890\pgfdecorationsegmentamplitude\relax
- \edef\cgrphy at xa{\the\pgf at xa}
- \pgfpathcurveto
- {\pgfqpoint{1.5890\pgfdecorationsegmentamplitude}{1.3333\pgfdecorationsegmentamplitude}}
- {\pgfqpoint{\cgrphy at xa}{1.3333\pgfdecorationsegmentamplitude}}
- {\pgfqpoint{\pgfdecoratedremainingdistance}{0pt}}
- \tikzset{
- taper width=.5\pgflinewidth,
- taper
- }%
- \pgfsyssoftpath at getcurrentpath\cal at tmp@path
- \MakeSPathList{calligraphy path}{\cal at tmp@path}%
- \SPathListPrepare{calligraphy path}%
- \CalligraphyPathCreate{calligraphy path}{copperplate}%
- }
- \state{final}{}%
-}
-% \end{macrocode}
-% End the conditional for if pgfdecoration module is loaded
-% \begin{macrocode}
-\fi
-% \end{macrocode}
-% \iffalse
-%</calligraphy>
-% \fi
-%
-%
-% \iffalse
-%<*knots>
-% \fi
-%%
-% \section{Drawing Knots}
-%
-%
-% \subsection{Initialisation}
-%
-% We load the \Verb+spath3+ library and the \Verb+intersections+ TikZ library.
-% Then we get going.
-% \begin{macrocode}
-\RequirePackage{spath3}
-\usetikzlibrary{intersections}
-
-\ExplSyntaxOn
-
-\tl_new:N \l__knot_tmpa_tl
-\tl_new:N \l__knot_tmpb_tl
-\tl_new:N \l__knot_tmpc_tl
-\tl_new:N \l__knot_tmpd_tl
-\tl_new:N \l__knot_tmpe_tl
-\tl_new:N \l__knot_tmpf_tl
-\tl_new:N \l__knot_tmpg_tl
-\tl_new:N \l__knot_redraws_tl
-\tl_new:N \l__knot_clip_width_tl
-\tl_new:N \l__knot_name_tl
-\tl_new:N \l__knot_node_tl
-\tl_new:N \l__knot_aux_tl
-\tl_new:N \l__knot_auxa_tl
-
-\int_new:N \l__knot_tmpa_int
-\int_new:N \l__knot_strands_int
-\int_new:N \l__knot_intersections_int
-\int_new:N \l__knot_filaments_int
-\int_new:N \l__knot_component_start_int
-
-\dim_new:N \l__knot_tmpa_dim
-\dim_new:N \l__knot_tmpb_dim
-\dim_new:N \l__knot_tmpc_dim
-\dim_new:N \l__knot_tolerance_dim
-\dim_new:N \l__knot_clip_bg_radius_dim
-\dim_new:N \l__knot_clip_draw_radius_dim
-
-\bool_new:N \l__knot_draft_bool
-\bool_new:N \l__knot_ignore_ends_bool
-\bool_new:N \l__knot_self_intersections_bool
-\bool_new:N \l__knot_splits_bool
-\bool_new:N \l__knot_super_draft_bool
-
-\bool_new:N \l__knot_prepend_prev_bool
-\bool_new:N \l__knot_append_next_bool
-\bool_new:N \l__knot_skip_bool
-\bool_new:N \l__knot_save_bool
-
-\seq_new:N \l__knot_nodes_seq
-
-\bool_set_true:N \l__knot_ignore_ends_bool
-% \end{macrocode}
-%
-% Configuration is via TikZ keys and styles.
-% \begin{macrocode}
-\tikzset{
- knot/.code={
- \tl_if_eq:nnTF {#1} {none}
- {
- \tikz at addmode{\tikz at mode@doublefalse}
- }
- {
- \tikz at addmode{\tikz at mode@doubletrue}
- \tl_if_eq:nnTF {\pgfkeysnovalue} {#1}
- {
- \tikz at addoption{\pgfsetinnerstrokecolor{.}}
- }
- {
- \pgfsetinnerstrokecolor{#1}
- }
- \tikz at addoption{
- \pgfsetstrokecolor{knotbg}
- }
- \tl_set:Nn \tikz at double@setup{
- \pgfsetinnerlinewidth{\pgflinewidth}
- \pgfsetlinewidth{\dim_eval:n {\tl_use:N \l__knot_gap_tl \pgflinewidth}}
- }
- }
- },
- knot~ gap/.store~ in=\l__knot_gap_tl,
- knot~ gap=3,
- knot~ diagram/.is~family,
- knot~ diagram/.unknown/.code={
- \tl_set_eq:NN \l__knot_tmpa_tl \pgfkeyscurrentname
- \pgfkeysalso{
- /tikz/\l__knot_tmpa_tl=#1
- }
- },
- background~ colour/.code={%
- \colorlet{knotbg}{#1}%
- },
- background~ color/.code={%
- \colorlet{knotbg}{#1}%
- },
- background~ colour=white,
- knot~ diagram,
- name/.store~ in=\l__knot_name_tl,
- name={knot},
- save~ intersections/.is~ choice,
- save~ intersections/.default=true,
- save~ intersections/true/.code={
- \bool_set_true:N \l__knot_save_bool
- },
- save~ intersections/false/.code={
- \bool_set_false:N \l__knot_save_bool
- },
- every~ strand/.style={draw},
- ignore~ endpoint~ intersections/.code={
- \tl_if_eq:nnTF {#1} {true}
- {
- \bool_set_true:N \l__knot_ignore_ends_bool
- }
- {
- \bool_set_false:N \l__knot_ignore_ends_bool
- }
- },
- ignore~ endpoint~ intersections/.default=true,
- consider~ self~ intersections/.is~choice,
- consider~ self~ intersections/true/.code={
- \bool_set_true:N \l__knot_self_intersections_bool
- \bool_set_true:N \l__knot_splits_bool
- },
- consider~ self~ intersections/false/.code={
- \bool_set_false:N \l__knot_self_intersections_bool
- \bool_set_false:N \l__knot_splits_bool
- },
- consider~ self~ intersections/no~ splits/.code={
- \bool_set_true:N \l__knot_self_intersections_bool
- \bool_set_false:N \l__knot_splits_bool
- },
- consider~ self~ intersections/.default={true},
- clip~ radius/.code={
- \dim_set:Nn \l__knot_clip_bg_radius_dim {#1}
- \dim_set:Nn \l__knot_clip_draw_radius_dim {#1+2pt}
- },
- clip~ draw~ radius/.code={
- \dim_set:Nn \l__knot_clip_draw_radius_dim {#1}
- },
- clip~ background~ radius/.code={
- \dim_set:Nn \l__knot_clip_bg_radius_dim {#1}
- },
- clip~ radius=10pt,
- end~ tolerance/.code={
- \dim_set:Nn \l__knot_tolerance_dim {#1}
- },
- end~ tolerance=14pt,
- clip/.style={
- clip
- },
- background~ clip/.style={
- clip
- },
- clip~ width/.code={
- \tl_set:Nn \l__knot_clip_width_tl {#1}
- },
- clip~ width=3,
- flip~ crossing/.code={%
- \tl_clear_new:c {l__knot_crossing_#1}
- \tl_set:cn {l__knot_crossing_#1} {x}
- },
- ignore~ crossing/.code={%
- \tl_clear_new:c {l__knot_ignore_crossing_#1}
- \tl_set:cn {l__knot_ignore_crossing_#1} {x}
- },
- draft~ mode/.is~ choice,
- draft~ mode/off/.code={%
- \bool_set_false:N \l__knot_draft_bool
- \bool_set_false:N \l__knot_super_draft_bool
- },
- draft~ mode/crossings/.code={%
- \bool_set_true:N \l__knot_draft_bool
- \bool_set_false:N \l__knot_super_draft_bool
- },
- draft~ mode/strands/.code={%
- \bool_set_true:N \l__knot_draft_bool
- \bool_set_true:N \l__knot_super_draft_bool
- },
- draft/.is~ family,
- draft,
- crossing~ label/.style={
- overlay,
- fill=white,
- fill~ opacity=.5,
- text~ opacity=1,
- text=blue,
- pin~ edge={blue,<-}
- },
- strand~ label/.style={
- overlay,
- circle,
- draw=purple,
- fill=white,
- fill~ opacity=.5,
- text~ opacity=1,
- text=purple,
- inner~ sep=0pt
- },
-}
-% \end{macrocode}
-%
-% Wrapper around \Verb+\tikzset+ for applying keys from a token list, checking for if the given token list exists.
-% \begin{macrocode}
-\cs_new_nopar:Npn \knot_apply_style:N #1
-{
- \tl_if_exist:NT #1 {
- \exp_args:NV \tikzset #1
- }
-}
-\cs_generate_variant:Nn \knot_apply_style:N {c}
-% \end{macrocode}
-%
-%\begin{macro}{\flipcrossings}
-% The user can specify a comma separated list of crossings to flip.
-% \begin{macrocode}
-\NewDocumentCommand \flipcrossings {m}
-{
- \tikzset{knot~ diagram/flip~ crossing/.list={#1}}%
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\strand}
-% This is how the user specifies a strand of the knot.
-% \begin{macrocode}
-\NewDocumentCommand \strand { O{} }
-{
- \int_incr:N \l__knot_strands_int
- \tl_clear_new:c {l__knot_options_strand \int_use:N \l__knot_strands_int}
- \tl_set:cn {l__knot_options_strand \int_use:N \l__knot_strands_int} {#1}
- \path[#1,save~ spath=knot strand \int_use:N \l__knot_strands_int]
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{knot}
-% This is the wrapper environment that calls the knot generation code.
-% \begin{macrocode}
-\NewDocumentEnvironment{knot} { O{} }
-{
- \knot_initialise:n {#1}
-}
-{
- \knot_render:
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\knot_initialise:n}
-% Set up some stuff before loading in the strands.
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \knot_initialise:n #1
-{
- \tikzset{knot~ diagram/.cd,every~ knot~ diagram/.try,#1}
- \int_zero:N \l__knot_strands_int
- \tl_clear:N \l__knot_redraws_tl
- \seq_gclear:N \l__knot_nodes_seq
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\knot_render:}
-% This is the code that starts the work of rendering the knot.
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \knot_render:
-{
-% \end{macrocode}
-% Start a scope and reset the transformation (since all transformations have already been taken into account when defining the strands).
-% \begin{macrocode}
- \pgfscope
- \pgftransformreset
-% \end{macrocode}
-% Loop through the strands drawing each one for the first time.
-% \begin{macrocode}
- \int_step_function:nnnN {1} {1} {\l__knot_strands_int} \knot_draw_strand:n
-% \end{macrocode}
-% In super draft mode we don't do anything else.
-% \begin{macrocode}
- \bool_if:NF \l__knot_super_draft_bool
- {
-% \end{macrocode}
-% In draft mode we draw labels at the ends of the strands; this also handles splitting curves to avoid self-intersections of Bezier curves if that's requested.
-% \begin{macrocode}
- \int_step_function:nnnN {1} {1} {\l__knot_strands_int} \knot_draw_labels:n
-% \end{macrocode}
-% If we're considering self intersections we need to split the strands into filaments.
-% \begin{macrocode}
- \bool_if:NTF \l__knot_self_intersections_bool
- {
- \knot_split_strands:
- \int_set_eq:NN \l__knot_tmpa_int \l__knot_filaments_int
- \tl_set:Nn \l__knot_prefix_tl {filament}
- }
- {
- \int_set_eq:NN \l__knot_tmpa_int \l__knot_strands_int
- \tl_set:Nn \l__knot_prefix_tl {strand}
- }
-% \end{macrocode}
-% Initialise the intersection count.
-% \begin{macrocode}
- \int_gzero:N \l__knot_intersections_int
-% \end{macrocode}
-% If in draft mode we label the intersections, otherwise we just stick a coordinate at each one.
-% \begin{macrocode}
- \bool_if:NTF \l__knot_draft_bool
- {
- \tl_set:Nn \l__knot_node_tl {
- \exp_not:N \node[coordinate,
- pin={[node~ contents={\int_use:N \l__knot_intersections_int},knot~ diagram/draft/crossing~ label, knot~ diagram/draft/crossing~ \int_use:N \l__knot_intersections_int \c_space_tl label/.try]
- }]
- }
- }
- {
- \tl_set:Nn \l__knot_node_tl {\exp_not:N \node[coordinate]}
- }
-% \end{macrocode}
-% This double loop steps through the pieces (strands or filaments) and computes the intersections and does stuff with those.
-% \begin{macrocode}
- \int_step_variable:nnnNn {1} {1} {\l__knot_tmpa_int - 1} \l__knot_tmpa_tl
- {
- \int_step_variable:nnnNn {\tl_use:N \l__knot_tmpa_tl + 1} {1} {\l__knot_tmpa_int} \l__knot_tmpb_tl
- {
- \knot_intersections:VV \l__knot_tmpa_tl \l__knot_tmpb_tl
- }
- }
-% \end{macrocode}
-% If any redraws were requested, do them here.
-% \begin{macrocode}
- \tl_use:N \l__knot_redraws_tl
-% \end{macrocode}
-% Draw the crossing nodes
-% \begin{macrocode}
- \seq_use:Nn \l__knot_nodes_seq {}
- }
-% \end{macrocode}
-% Close the scope
-% \begin{macrocode}
- \endpgfscope
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\knot_draw_strand:n}
-% This renders a strand using the options originally specified.
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \knot_draw_strand:n #1
-{
- \pgfscope
- \group_begin:
- \tl_set:Nn \l_tmpa_tl {knot~ diagram/every~ strand/.try,}
- \tl_put_right:Nv \l_tmpa_tl {l__knot_options_strand #1}
- \tl_put_right:Nn \l_tmpa_tl {,knot~ diagram/only~ when~ rendering/.try,only~ when~ rendering/.try}
- \spath_bake_round:n {knot strand #1}
- \spath_tikz_path:Vn \l_tmpa_tl {knot strand #1}
- \group_end:
- \endpgfscope
-}
-\cs_generate_variant:Nn \tl_put_right:Nn {Nv}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\knot_draw_labels:n}
-% Draw a label at each end of each strand, if in draft mode.
-% Also, if requested, split potentially self intersecting Bezier curves.
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \knot_draw_labels:n #1
-{
- \bool_if:NT \l__knot_draft_bool
- {
- \spath_get:nnN {knot strand #1} {final point} \l__knot_tmpb_tl
- \dim_set:Nn \l__knot_tmpa_dim {\tl_item:Nn \l__knot_tmpb_tl {1}}
- \dim_set:Nn \l__knot_tmpb_dim {\tl_item:Nn \l__knot_tmpb_tl {2}}
- \node[knot~ diagram/draft/strand~label] at (\l__knot_tmpa_dim,\l__knot_tmpb_dim) {#1};
- \spath_get:nnN {knot strand #1} {initial point} \l__knot_tmpb_tl
- \dim_set:Nn \l__knot_tmpa_dim {\tl_item:Nn \l__knot_tmpb_tl {1}}
- \dim_set:Nn \l__knot_tmpb_dim {\tl_item:Nn \l__knot_tmpb_tl {2}}
- \node[knot~ diagram/draft/strand~label] at (\l__knot_tmpa_dim,\l__knot_tmpb_dim) {#1};
- }
- \bool_if:nT {
- \l__knot_self_intersections_bool
- &&
- \l__knot_splits_bool
- }
- {
- \tl_clear:N \l__knot_tmpa_tl
- \spath_map_segment_function:nN {knot strand #1} \knot_split_self_intersects:NN
- \spath_put:nnV {knot strand #1} {path} \l__knot_tmpa_tl
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\knot_split_self_intersects:NN}
-% This is the macro that does the split.
-% Figuring out whether a Bezier cubic self intersects is apparently a difficult problem so we don't bother.
-% We compute a point such that if there is an intersection then it lies on either side of the point.
-% I don't recall where the formula came from!
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \knot_split_self_intersects:NN #1#2
-{
- \tl_case:NnF #1
- {
- \g__spath_curvetoa_tl
- {
- \fp_set:Nn \l_tmpa_fp
- {
- (\tl_item:Nn #2 {3} - 3 * \tl_item:Nn #2 {6} + 3 * \tl_item:Nn #2 {9} - \tl_item:Nn #2 {12})
- *
- (3 * \tl_item:Nn #2 {8} - 3 * \tl_item:Nn #2 {11})
- -
- (\tl_item:Nn #2 {2} - 3 * \tl_item:Nn #2 {5} + 3 * \tl_item:Nn #2 {8} - \tl_item:Nn #2 {11})
- *
- (3 * \tl_item:Nn #2 {9} - 3 * \tl_item:Nn #2 {12})
- }
- \fp_set:Nn \l_tmpb_fp
- {
- (\tl_item:Nn #2 {2} - 3 * \tl_item:Nn #2 {5} + 3 * \tl_item:Nn #2 {8} - \tl_item:Nn #2 {11})
- *
- (3 * \tl_item:Nn #2 {6} - 6 * \tl_item:Nn #2 {9} + 3 * \tl_item:Nn #2 {12})
- -
- (\tl_item:Nn #2 {3} - 3 * \tl_item:Nn #2 {6} + 3 * \tl_item:Nn #2 {9} - \tl_item:Nn #2 {12})
- *
- (3 * \tl_item:Nn #2 {5} - 6 * \tl_item:Nn #2 {8} + 3 * \tl_item:Nn #2 {11})
- }
- \fp_compare:nTF
- {
- \l_tmpb_fp != 0
- }
- {
- \fp_set:Nn \l_tmpa_fp {.5 * \l_tmpa_fp / \l_tmpb_fp}
- \fp_compare:nTF
- {
- 0 < \l_tmpa_fp && \l_tmpa_fp < 1
- }
- {
- \spath_split_curve:VVNN \l_tmpa_fp #2 \l_tmpa_tl \l_tmpb_tl
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_put_right:NV \l__knot_tmpa_tl \l_tmpa_tl
- \tl_put_right:NV \l__knot_tmpa_tl \l_tmpb_tl
- }
- {
- \tl_set_eq:NN \l_tmpa_tl #2
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_put_right:NV \l__knot_tmpa_tl \l_tmpa_tl
- }
- }
- {
- \tl_set_eq:NN \l_tmpa_tl #2
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_put_right:NV \l__knot_tmpa_tl \l_tmpa_tl
- }
- }
- \g__spath_lineto_tl
- {
- \tl_set_eq:NN \l_tmpa_tl #2
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_put_right:NV \l__knot_tmpa_tl \l_tmpa_tl
- }
- }
- {
- \tl_put_right:NV \l__knot_tmpa_tl #2
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\knot_intersections:nn}
-% This computes the intersections of two pieces and steps through them.
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \knot_intersections:nn #1#2
-{
- \group_begin:
- \tl_set_eq:NN \l__knot_tmpa_tl \l__knot_prefix_tl
- \tl_put_right:Nn \l__knot_tmpa_tl {#1}
- \tl_set_eq:NN \l__knot_tmpb_tl \l__knot_prefix_tl
- \tl_put_right:Nn \l__knot_tmpb_tl {#2}
- \spath_get:nnN {knot \tl_use:N \l__knot_tmpa_tl} {path} \l__knot_tmpc_tl
- \spath_get:nnN {knot \tl_use:N \l__knot_tmpb_tl} {path} \l__knot_tmpd_tl
-
- \bool_if:nTF {
- \l__knot_save_bool
- &&
- \tl_if_exist_p:c {knot~ intersections~ \tl_use:N \l__knot_name_tl - \tl_use:N \l__knot_tmpa_tl - \tl_use:N \l__knot_tmpb_tl}
- }
- {
- \tl_use:c {knot~ intersections~ \tl_use:N \l__knot_name_tl - \tl_use:N \l__knot_tmpa_tl - \tl_use:N \l__knot_tmpb_tl}
- }
- {
-\pgfintersectionofpaths{\pgfsetpath\l__knot_tmpc_tl}{\pgfsetpath\l__knot_tmpd_tl}
-
- }
- \int_compare:nT {\pgfintersectionsolutions > 0}
- {
- \int_step_function:nnnN {1} {1} {\pgfintersectionsolutions} \knot_do_intersection:n
- }
- \knot_save_intersections:VV \l__knot_tmpa_tl \l__knot_tmpb_tl
- \group_end:
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\knot_save_intersections:nn}
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \knot_save_intersections:nn #1#2
-{
- \bool_if:NT \l__knot_save_bool
- {
- \tl_clear:N \l__knot_aux_tl
- \tl_put_right:Nn \l__knot_aux_tl
- {
- \def\pgfintersectionsolutions
- }
- \tl_put_right:Nx \l__knot_aux_tl
- {
- {\int_eval:n {\pgfintersectionsolutions}}
- }
- \int_compare:nT {\pgfintersectionsolutions > 0}
- {
- \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions}
- {
- \pgfpointintersectionsolution{##1}
- \dim_set:Nn \l__knot_tmpa_dim {\pgf at x}
- \dim_set:Nn \l__knot_tmpb_dim {\pgf at y}
- \tl_put_right:Nn \l__knot_aux_tl
- {
- \expandafter\def\csname pgfpoint at intersect@solution@##1\endcsname
- }
- \tl_put_right:Nx \l__knot_aux_tl
- {
- {\exp_not:N \pgf at x=\dim_use:N \l__knot_tmpa_dim\exp_not:N\relax\exp_not:N \pgf at y =\dim_use:N \l__knot_tmpb_dim\relax}
- }
- }
- \tl_set:Nn \l__knot_auxa_tl {\expandafter \gdef \csname knot~ intersections~}
- \tl_put_right:Nx \l__knot_auxa_tl {\tl_use:N \l__knot_name_tl - #1 - #2}
- \tl_put_right:Nn \l__knot_auxa_tl {\endcsname}
- \tl_put_right:Nx \l__knot_auxa_tl {{\tl_to_str:N \l__knot_aux_tl}}
- \protected at write\@auxout{}{\tl_to_str:N \l__knot_auxa_tl}
- }
- }
-}
-\cs_generate_variant:Nn \knot_save_intersections:nn {VV}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\knot_do_intersection:n}
-% This handles a specific intersection.
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \knot_do_intersection:n #1
-{
-% \end{macrocode}
-% Get the intersection coordinates.
-% \begin{macrocode}
- \pgfpointintersectionsolution{#1}
- \dim_set:Nn \l__knot_tmpa_dim {\pgf at x}
- \dim_set:Nn \l__knot_tmpb_dim {\pgf at y}
-% \end{macrocode}
-% If we're dealing with filaments, we can get false positives from the end points.
-% \begin{macrocode}
- \bool_set_false:N \l__knot_skip_bool
- \bool_if:NT \l__knot_self_intersections_bool
- {
-% \end{macrocode}
-% If one filament preceded the other, test for the intersection being at the relevant end point.
-% \begin{macrocode}
- \tl_set:Nn \l_tmpa_tl {knot previous}
- \tl_put_right:NV \l_tmpa_tl \l__knot_tmpa_tl
- \tl_set:Nv \l_tmpa_tl \l_tmpa_tl
- \tl_if_eq:NNT \l_tmpa_tl \l__knot_tmpb_tl
- {
- \knot_test_endpoint:VnT \l__knot_tmpb_tl {final point}
- {
- \bool_set_true:N \l__knot_skip_bool
- }
- }
-
- \tl_set:Nn \l_tmpa_tl {knot previous}
- \tl_put_right:NV \l_tmpa_tl \l__knot_tmpb_tl
- \tl_set:Nv \l_tmpa_tl \l_tmpa_tl
- \tl_if_eq:NNT \l_tmpa_tl \l__knot_tmpa_tl
- {
- \knot_test_endpoint:VnT \l__knot_tmpa_tl {final point}
- {
- \bool_set_true:N \l__knot_skip_bool
- }
- }
- }
-% \end{macrocode}
-% The user can also say that end points of filaments (or strands) should simply be ignored anyway.
-% \begin{macrocode}
- \bool_if:NT \l__knot_ignore_ends_bool
- {
- \knot_test_endpoint:VnT \l__knot_tmpa_tl {initial point}
- {
- \bool_set_true:N \l__knot_skip_bool
- }
- \knot_test_endpoint:VnT \l__knot_tmpa_tl {final point}
- {
- \bool_set_true:N \l__knot_skip_bool
- }
- \knot_test_endpoint:VnT \l__knot_tmpb_tl {initial point}
- {
- \bool_set_true:N \l__knot_skip_bool
- }
- \knot_test_endpoint:VnT \l__knot_tmpb_tl {final point}
- {
- \bool_set_true:N \l__knot_skip_bool
- }
- }
-% \end{macrocode}
-% Assuming that we passed all the above tests, we render the crossing.
-% \begin{macrocode}
- \bool_if:NF \l__knot_skip_bool
- {
-
- \int_gincr:N \l__knot_intersections_int
-% \end{macrocode}
-% This is the intersection test.
-% If the intersection finder finds too many, it might be useful to ignore some.
-% \begin{macrocode}
- \bool_if:nF
- {
- \tl_if_exist_p:c {l__knot_ignore_crossing_ \int_use:N
- \l__knot_intersections_int}
- &&
- ! \tl_if_empty_p:c {l__knot_ignore_crossing_ \int_use:N
- \l__knot_intersections_int}
- }
- {
-% \end{macrocode}
-% This is the flip test.
-% We only render one of the paths.
-% The ``flip'' swaps which one we render.
-% \begin{macrocode}
- \bool_if:nTF
- {
- \tl_if_exist_p:c {l__knot_crossing_ \int_use:N
- \l__knot_intersections_int}
- &&
- ! \tl_if_empty_p:c {l__knot_crossing_ \int_use:N
- \l__knot_intersections_int}
- }
- {
- \tl_set_eq:NN \l__knot_tmpg_tl \l__knot_tmpb_tl
- }
- {
- \tl_set_eq:NN \l__knot_tmpg_tl \l__knot_tmpa_tl
- }
-% \end{macrocode}
-% Now we know which one we're rendering, we test to see if we should also render its predecessor or successor to ensure that we render a path through the entire crossing region.
-% \begin{macrocode}
- \bool_if:NT \l__knot_self_intersections_bool
- {
- \knot_test_endpoint:VnT \l__knot_tmpg_tl {initial point}
- {
- \bool_set_true:N \l__knot_prepend_prev_bool
- }
- {
- \bool_set_false:N \l__knot_prepend_prev_bool
- }
- \knot_test_endpoint:VnT \l__knot_tmpg_tl {final point}
- {
- \bool_set_true:N \l__knot_append_next_bool
- }
- {
- \bool_set_false:N \l__knot_append_next_bool
- }
-% \end{macrocode}
-% If either of those tests succeeded, do the appending or prepending.
-% \begin{macrocode}
- \bool_if:nT
- {
- \l__knot_prepend_prev_bool || \l__knot_append_next_bool
- }
- {
- \spath_clone:nn {knot \tl_use:N \l__knot_tmpg_tl}
- {knot \tl_use:N \l__knot_prefix_tl -1}
-
- \tl_set_eq:cc {l__knot_options_ \tl_use:N \l__knot_prefix_tl -1} {l__knot_options_ \tl_use:N \l__knot_tmpg_tl}
-
- \bool_if:nT
- {
- \l__knot_prepend_prev_bool
- &&
- \tl_if_exist_p:c {knot previous \tl_use:N \l__knot_tmpg_tl}
- &&
- !\tl_if_empty_p:c {knot previous \tl_use:N \l__knot_tmpg_tl}
- }
- {
- \spath_prepend_no_move:nn {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot previous \tl_use:N \l__knot_tmpg_tl}}
-% \end{macrocode}
-% If we split potentially self intersecting curves, we test to see if we should prepend yet another segment.
-% \begin{macrocode}
- \bool_if:nT
- {
- \l__knot_splits_bool
- &&
- \tl_if_exist_p:c {knot previous \tl_use:N \l__knot_tmpg_tl}
- &&
- !\tl_if_empty_p:c {knot previous \tl_use:N \l__knot_tmpg_tl}
- }
- {
- \knot_test_endpoint:vnT {knot previous \tl_use:N \l__knot_tmpg_tl} {initial point}
- {
- \spath_get:nnN {knot \tl_use:N \l__knot_prefix_tl -1} {path} \l_tmpa_tl
- \spath_prepend_no_move:nn {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot previous \tl_use:c {knot previous \tl_use:N \l__knot_tmpg_tl}}}
- \spath_get:nnN {knot \tl_use:N \l__knot_prefix_tl -1} {path} \l_tmpa_tl
-
- }
- }
- }
-% \end{macrocode}
-% Now the same for appending.
-% \begin{macrocode}
- \bool_if:nT
- {
- \l__knot_append_next_bool
- &&
- \tl_if_exist_p:c {knot next \tl_use:N \l__knot_tmpg_tl}
- &&
- !\tl_if_empty_p:c {knot previous \tl_use:N \l__knot_tmpg_tl}
- }
- {
- \spath_append_no_move:nn {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot next \tl_use:N \l__knot_tmpg_tl}}
- \bool_if:nT
- {
- \l__knot_splits_bool
- &&
- \tl_if_exist_p:c {knot previous \tl_use:N
- \l__knot_tmpg_tl}
- &&
- !\tl_if_empty_p:c {knot previous \tl_use:N \l__knot_tmpg_tl}
- }
- {
- \knot_test_endpoint:vnT {knot previous \tl_use:N \l__knot_tmpg_tl} {final point}
- {
- \spath_append_no_move:nn {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot next \tl_use:c {knot next \tl_use:N \l__knot_tmpg_tl}}}
-
- }
- }
- }
-
- \tl_set:Nn \l__knot_tmpg_tl {\tl_use:N \l__knot_prefix_tl -1}
- }
- }
-% \end{macrocode}
-% Now we render the crossing.
-% \begin{macrocode}
- \pgfscope
- \group_begin:
- \tikzset{knot~ diagram/every~ intersection/.try, every~ intersection/.try, knot~ diagram/intersection~ \int_use:N \l__knot_intersections_int/.try}
- \knot_draw_crossing:nVV {\tl_use:N \l__knot_tmpg_tl} \l__knot_tmpa_dim \l__knot_tmpb_dim
- \group_end:
- \endpgfscope
-% \end{macrocode}
-% This ends the boolean as to whether to consider the intersection at all
-% \begin{macrocode}
- }
-% \end{macrocode}
-% And stick a coordinate possibly with a label at the crossing.
-% \begin{macrocode}
- \seq_gpush:Nx \l__knot_nodes_seq { \l__knot_node_tl (\l__knot_name_tl \c_space_tl \int_use:N \l__knot_intersections_int) at (\dim_use:N \l__knot_tmpa_dim, \dim_use:N \l__knot_tmpb_dim) {};}
-
- }
-}
-
-\cs_generate_variant:Nn \knot_intersections:nn {VV}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\knot_test_endpoint:N}
-% Test whether the point is near the intersection point.
-% \begin{macrocode}
-\prg_new_conditional:Npnn \knot_test_endpoint:N #1 {p,T,F,TF}
-{
- \dim_compare:nTF
- {
- \dim_abs:n { \l__knot_tmpa_dim - \tl_item:Nn #1 {1}}
- +
- \dim_abs:n { \l__knot_tmpb_dim - \tl_item:Nn #1 {2}}
- <
- \l__knot_tolerance_dim
- }
- {
- \prg_return_true:
- }
- {
- \prg_return_false:
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\knot_test_endpoint:nn}
-% Wrapper around the above.
-% \begin{macrocode}
-\prg_new_protected_conditional:Npnn \knot_test_endpoint:nn #1#2 {T,F,TF}
-{
- \spath_get:nnN {knot #1} {#2} \l__knot_tmpd_tl
- \knot_test_endpoint:NTF \l__knot_tmpd_tl
- {
- \prg_return_true:
- }
- {
- \prg_return_false:
- }
-}
-
-\cs_generate_variant:Nn \knot_test_endpoint:nnT {VnT,vnT}
-\cs_generate_variant:Nn \knot_test_endpoint:nnF {VnF,vnF}
-\cs_generate_variant:Nn \knot_test_endpoint:nnTF {VnTF,vnTF}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\knot_draw_crossing:nnn}
-% This is the code that actually renders a crossing.
-% \begin{macrocode}
-\cs_new_nopar:Npn \knot_draw_crossing:nnn #1#2#3
-{
- \group_begin:
- \pgfscope
- \path[knot~ diagram/background~ clip] (#2, #3) circle[radius=\l__knot_clip_bg_radius_dim];
-
- \tl_set:Nn \l_tmpa_tl {knot~ diagram/every~ strand/.try,}
- \tl_if_exist:cT {l__knot_options_ #1}
- {
- \tl_put_right:Nv \l_tmpa_tl {l__knot_options_ #1}
- }
- \tl_put_right:Nn \l_tmpa_tl {,knotbg,line~ width= \tl_use:N \l__knot_clip_width_tl * \pgflinewidth}
- \spath_tikz_path:Vn \l_tmpa_tl {knot #1}
-
- \endpgfscope
-
- \pgfscope
- \path[knot~ diagram/clip] (#2, #3) circle[radius=\l__knot_clip_draw_radius_dim];
-
- \tl_set:Nn \l_tmpa_tl {knot~ diagram/every~ strand/.try,}
- \tl_if_exist:cT {l__knot_options_ #1}
- {
- \tl_put_right:Nv \l_tmpa_tl {l__knot_options_ #1}
- }
- \tl_put_right:Nn \l_tmpa_tl {,knot~ diagram/only~ when~ rendering/.try,only~ when~ rendering/.try}
- \spath_tikz_path:Vn \l_tmpa_tl {knot #1}
-
- \endpgfscope
- \group_end:
-}
-
-\cs_generate_variant:Nn \knot_draw_crossing:nnn {nVV}
-
-\cs_new_nopar:Npn \knot_draw_crossing:nn #1#2
-{
- \tikz at scan@one at point\pgfutil at firstofone #2 \relax
- \knot_draw_crossing:nVV {#1} \pgf at x \pgf at y
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\knot_split_strands:}
-% This, and the following macros, are for splitting strands into filaments.
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \knot_split_strands:
-{
- \int_gzero:N \l__knot_filaments_int
- \int_step_function:nnnN {1} {1} {\l__knot_strands_int} \knot_split_strand:n
- \int_step_function:nnnN {1} {1} {\l__knot_filaments_int} \knot_compute_nexts:n
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\knot_compute_nexts:n}
-% Each filament needs to know its predecessor and successor.
-% We work out the predecessors as we go along, this fills in the successors.
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \knot_compute_nexts:n #1
-{
- \tl_clear_new:c {knot next \tl_use:c {knot previous filament #1}}
- \tl_set:cn {knot next \tl_use:c {knot previous filament #1}} {filament #1}
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\knot_split_strand:n}
-% Sets up the split for a single strand.
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \knot_split_strand:n #1
-{
- \int_set_eq:NN \l__knot_component_start_int \l__knot_filaments_int
- \int_incr:N \l__knot_component_start_int
- \tl_set_eq:Nc \l__knot_tmpa_tl {l__knot_options_strand #1}
- \spath_map_segment_function:nN {knot strand #1} \knot_save_filament:NN
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\knot_save_filament:NN}
-% Saves a filament as a new \Verb+spath+ object.
-% \begin{macrocode}
-\cs_new_protected_nopar:Npn \knot_save_filament:NN #1#2
-{
- \tl_case:NnF #1
- {
- \g__spath_moveto_tl
- {
- \int_compare:nT {\l__knot_component_start_int < \l__knot_filaments_int}
- {
- \int_set_eq:NN \l__knot_component_start_int \l__knot_filaments_int
- }
- }
- \g__spath_lineto_tl
- {
- \int_gincr:N \l__knot_filaments_int
- \spath_clear_new:n {knot filament \int_use:N \l__knot_filaments_int}
- \spath_put:nnV {knot filament \int_use:N \l__knot_filaments_int} {path} #2
- \tl_set_eq:cN {l__knot_options_filament \int_use:N \l__knot_filaments_int} \l__knot_tmpa_tl
-
- \tl_clear_new:c {knot previous filament \int_use:N \l__knot_filaments_int}
- \int_compare:nF {\l__knot_component_start_int == \l__knot_filaments_int}
- {
- \tl_set:cx {knot previous filament \int_use:N \l__knot_filaments_int} {filament \int_eval:n {\l__knot_filaments_int - 1}}
- }
- }
- \g__spath_curvetoa_tl
- {
- \int_gincr:N \l__knot_filaments_int
- \spath_clear_new:n {knot filament \int_use:N \l__knot_filaments_int}
- \spath_put:nnV {knot filament \int_use:N \l__knot_filaments_int} {path} #2
- \tl_set_eq:cN {l__knot_options_filament \int_use:N \l__knot_filaments_int} \l__knot_tmpa_tl
-
- \tl_clear_new:c {knot previous filament \int_use:N \l__knot_filaments_int}
- \int_compare:nF {\l__knot_component_start_int == \l__knot_filaments_int}
- {
- \tl_set:cx {knot previous filament \int_use:N \l__knot_filaments_int} {filament \int_eval:n {\l__knot_filaments_int - 1}}
- }
- }
- \g__spath_closepath_tl
- {
- \tl_show:N #2
- \int_gincr:N \l__knot_filaments_int
- \spath_clear_new:n {knot filament \int_use:N \l__knot_filaments_int}
- \tl_clear:N \l_tmpa_tl
- \tl_put_right:Nx {\tl_item:Nn #2 {1}\tl_item:Nn #2 {2}\tl_item:Nn #2 {3}}
- \tl_put_right:NV \l_tmpa_tl \g__spath_lineto_tl
- \tl_put_right:Nx {\tl_item:Nn #2 {5}\tl_item:Nn #2 {6}}
- \tl_show:N \l_tmpa_tl
- \spath_put:nnV {knot filament \int_use:N \l__knot_filaments_int} {path} \l_tmpa_tl
- \tl_set_eq:cN {l__knot_options_filament \int_use:N \l__knot_filaments_int} \l__knot_tmpa_tl
- \tl_clear_new:c {knot previous filament \int_use:N \l__knot_filaments_int}
- \int_compare:nF {\l__knot_component_start_int == \l__knot_filaments_int}
- {
- \tl_set:cx {knot previous filament \int_use:N \l__knot_filaments_int} {filament \int_eval:n {\l__knot_filaments_int - 1}}
- }
- \tl_set:cx {knot previous filament \int_use:N \l__knot_component_start_int} {filament \int_use:N \l__knot_filaments_int}
- }
- }
- {
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\redraw}
-% The user can redraw segments of the strands at specific locations.
-% \begin{macrocode}
-\NewDocumentCommand \redraw { m m }
-{
-% \tikz at scan@one at point\pgfutil at firstofone #2 \relax
- \tl_put_right:Nn \l__knot_redraws_tl {\knot_draw_crossing:nn}
- \tl_put_right:Nx \l__knot_redraws_tl {
- {strand #1} {#2}% {\dim_use:N \pgf at x} {\dim_use:N \pgf at y}
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macrocode}
-\ExplSyntaxOff
-% \end{macrocode}
-%
-% \begin{macro}{\pgf at sh@@knotanchor}
-% Add the extra anchors for the knot crossing nodes.
-% \begin{macrocode}
-\def\pgf at sh@@knotanchor#1#2{%
- \anchor{#2 north west}{%
- \csname pgf at anchor@knot #1 at north west\endcsname%
- \pgf at x=#2\pgf at x%
- \pgf at y=#2\pgf at y%
- }%
- \anchor{#2 north east}{%
- \csname pgf at anchor@knot #1 at north east\endcsname%
- \pgf at x=#2\pgf at x%
- \pgf at y=#2\pgf at y%
- }%
- \anchor{#2 south west}{%
- \csname pgf at anchor@knot #1 at south west\endcsname%
- \pgf at x=#2\pgf at x%
- \pgf at y=#2\pgf at y%
- }%
- \anchor{#2 south east}{%
- \csname pgf at anchor@knot #1 at south east\endcsname%
- \pgf at x=#2\pgf at x%
- \pgf at y=#2\pgf at y%
- }%
- \anchor{#2 north}{%
- \csname pgf at anchor@knot #1 at north\endcsname%
- \pgf at x=#2\pgf at x%
- \pgf at y=#2\pgf at y%
- }%
- \anchor{#2 east}{%
- \csname pgf at anchor@knot #1 at east\endcsname%
- \pgf at x=#2\pgf at x%
- \pgf at y=#2\pgf at y%
- }%
- \anchor{#2 west}{%
- \csname pgf at anchor@knot #1 at west\endcsname%
- \pgf at x=#2\pgf at x%
- \pgf at y=#2\pgf at y%
- }%
- \anchor{#2 south}{%
- \csname pgf at anchor@knot #1 at south\endcsname%
- \pgf at x=#2\pgf at x%
- \pgf at y=#2\pgf at y%
- }%
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{knot crossing}
-% \begin{macrocode}
-\pgfdeclareshape{knot crossing}
-{
- \inheritsavedanchors[from=circle] % this is nearly a circle
- \inheritanchorborder[from=circle]
- \inheritanchor[from=circle]{north}
- \inheritanchor[from=circle]{north west}
- \inheritanchor[from=circle]{north east}
- \inheritanchor[from=circle]{center}
- \inheritanchor[from=circle]{west}
- \inheritanchor[from=circle]{east}
- \inheritanchor[from=circle]{mid}
- \inheritanchor[from=circle]{mid west}
- \inheritanchor[from=circle]{mid east}
- \inheritanchor[from=circle]{base}
- \inheritanchor[from=circle]{base west}
- \inheritanchor[from=circle]{base east}
- \inheritanchor[from=circle]{south}
- \inheritanchor[from=circle]{south west}
- \inheritanchor[from=circle]{south east}
- \inheritanchorborder[from=circle]
- \pgf at sh@@knotanchor{crossing}{2}
- \pgf at sh@@knotanchor{crossing}{3}
- \pgf at sh@@knotanchor{crossing}{4}
- \pgf at sh@@knotanchor{crossing}{8}
- \pgf at sh@@knotanchor{crossing}{16}
- \pgf at sh@@knotanchor{crossing}{32}
- \backgroundpath{
- \pgfutil at tempdima=\radius%
- \pgfmathsetlength{\pgf at xb}{\pgfkeysvalueof{/pgf/outer xsep}}%
- \pgfmathsetlength{\pgf at yb}{\pgfkeysvalueof{/pgf/outer ysep}}%
- \ifdim\pgf at xb<\pgf at yb%
- \advance\pgfutil at tempdima by-\pgf at yb%
- \else%
- \advance\pgfutil at tempdima by-\pgf at xb%
- \fi%
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{knot over cross}
-% \begin{macrocode}
-\pgfdeclareshape{knot over cross}
-{
- \inheritsavedanchors[from=rectangle] % this is nearly a circle
- \inheritanchorborder[from=rectangle]
- \inheritanchor[from=rectangle]{north}
- \inheritanchor[from=rectangle]{north west}
- \inheritanchor[from=rectangle]{north east}
- \inheritanchor[from=rectangle]{center}
- \inheritanchor[from=rectangle]{west}
- \inheritanchor[from=rectangle]{east}
- \inheritanchor[from=rectangle]{mid}
- \inheritanchor[from=rectangle]{mid west}
- \inheritanchor[from=rectangle]{mid east}
- \inheritanchor[from=rectangle]{base}
- \inheritanchor[from=rectangle]{base west}
- \inheritanchor[from=rectangle]{base east}
- \inheritanchor[from=rectangle]{south}
- \inheritanchor[from=rectangle]{south west}
- \inheritanchor[from=rectangle]{south east}
- \inheritanchorborder[from=rectangle]
- \backgroundpath{
- \southwest \pgf at xa=\pgf at x \pgf at ya=\pgf at y
- \northeast \pgf at xb=\pgf at x \pgf at yb=\pgf at y
- \pgfpathmoveto{\pgfqpoint{\pgf at xa}{\pgf at ya}}
- \pgfpathlineto{\pgfqpoint{\pgf at xb}{\pgf at yb}}
- }
- \foregroundpath{
-% store lower right in xa/ya and upper right in xb/yb
- \southwest \pgf at xa=\pgf at x \pgf at ya=\pgf at y
- \northeast \pgf at xb=\pgf at x \pgf at yb=\pgf at y
- \pgfpathmoveto{\pgfqpoint{\pgf at xa}{\pgf at yb}}
- \pgfpathlineto{\pgfqpoint{\pgf at xb}{\pgf at ya}}
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{knot under cross}
-% \begin{macrocode}
-\pgfdeclareshape{knot under cross}
-{
- \inheritsavedanchors[from=rectangle] % this is nearly a circle
- \inheritanchorborder[from=rectangle]
- \inheritanchor[from=rectangle]{north}
- \inheritanchor[from=rectangle]{north west}
- \inheritanchor[from=rectangle]{north east}
- \inheritanchor[from=rectangle]{center}
- \inheritanchor[from=rectangle]{west}
- \inheritanchor[from=rectangle]{east}
- \inheritanchor[from=rectangle]{mid}
- \inheritanchor[from=rectangle]{mid west}
- \inheritanchor[from=rectangle]{mid east}
- \inheritanchor[from=rectangle]{base}
- \inheritanchor[from=rectangle]{base west}
- \inheritanchor[from=rectangle]{base east}
- \inheritanchor[from=rectangle]{south}
- \inheritanchor[from=rectangle]{south west}
- \inheritanchor[from=rectangle]{south east}
- \inheritanchorborder[from=rectangle]
- \backgroundpath{
- \southwest \pgf at xa=\pgf at x \pgf at ya=\pgf at y
- \northeast \pgf at xb=\pgf at x \pgf at yb=\pgf at y
- \pgfpathmoveto{\pgfqpoint{\pgf at xa}{\pgf at yb}}
- \pgfpathlineto{\pgfqpoint{\pgf at xb}{\pgf at ya}}
- }
- \foregroundpath{
-% store lower right in xa/ya and upper right in xb/yb
- \southwest \pgf at xa=\pgf at x \pgf at ya=\pgf at y
- \northeast \pgf at xb=\pgf at x \pgf at yb=\pgf at y
- \pgfpathmoveto{\pgfqpoint{\pgf at xa}{\pgf at ya}}
- \pgfpathlineto{\pgfqpoint{\pgf at xb}{\pgf at yb}}
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{knot vert}
-% \begin{macrocode}
-\pgfdeclareshape{knot vert}
-{
- \inheritsavedanchors[from=rectangle] % this is nearly a circle
- \inheritanchorborder[from=rectangle]
- \inheritanchor[from=rectangle]{north}
- \inheritanchor[from=rectangle]{north west}
- \inheritanchor[from=rectangle]{north east}
- \inheritanchor[from=rectangle]{center}
- \inheritanchor[from=rectangle]{west}
- \inheritanchor[from=rectangle]{east}
- \inheritanchor[from=rectangle]{mid}
- \inheritanchor[from=rectangle]{mid west}
- \inheritanchor[from=rectangle]{mid east}
- \inheritanchor[from=rectangle]{base}
- \inheritanchor[from=rectangle]{base west}
- \inheritanchor[from=rectangle]{base east}
- \inheritanchor[from=rectangle]{south}
- \inheritanchor[from=rectangle]{south west}
- \inheritanchor[from=rectangle]{south east}
- \inheritanchorborder[from=rectangle]
- \backgroundpath{
-% store lower right in xa/ya and upper right in xb/yb
- \southwest \pgf at xa=\pgf at x \pgf at ya=\pgf at y
- \northeast \pgf at xb=\pgf at x \pgf at yb=\pgf at y
- \pgfpathmoveto{\pgfqpoint{\pgf at xa}{\pgf at ya}}
- \pgfpathlineto{\pgfqpoint{\pgf at xa}{\pgf at yb}}
- \pgfpathmoveto{\pgfqpoint{\pgf at xb}{\pgf at yb}}
- \pgfpathlineto{\pgfqpoint{\pgf at xb}{\pgf at ya}}
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{knot horiz}
-% \begin{macrocode}
-\pgfdeclareshape{knot horiz}
-{
- \inheritsavedanchors[from=rectangle] % this is nearly a circle
- \inheritanchorborder[from=rectangle]
- \inheritanchor[from=rectangle]{north}
- \inheritanchor[from=rectangle]{north west}
- \inheritanchor[from=rectangle]{north east}
- \inheritanchor[from=rectangle]{center}
- \inheritanchor[from=rectangle]{west}
- \inheritanchor[from=rectangle]{east}
- \inheritanchor[from=rectangle]{mid}
- \inheritanchor[from=rectangle]{mid west}
- \inheritanchor[from=rectangle]{mid east}
- \inheritanchor[from=rectangle]{base}
- \inheritanchor[from=rectangle]{base west}
- \inheritanchor[from=rectangle]{base east}
- \inheritanchor[from=rectangle]{south}
- \inheritanchor[from=rectangle]{south west}
- \inheritanchor[from=rectangle]{south east}
- \inheritanchorborder[from=rectangle]
- \foregroundpath{
-% store lower right in xa/ya and upper right in xb/yb
- \southwest \pgf at xa=\pgf at x \pgf at ya=\pgf at y
- \northeast \pgf at xb=\pgf at x \pgf at yb=\pgf at y
- \pgfpathmoveto{\pgfqpoint{\pgf at xa}{\pgf at ya}}
- \pgfpathlineto{\pgfqpoint{\pgf at xb}{\pgf at ya}}
- \pgfpathmoveto{\pgfqpoint{\pgf at xa}{\pgf at yb}}
- \pgfpathlineto{\pgfqpoint{\pgf at xb}{\pgf at yb}}
- }
-}
-% \end{macrocode}
-% \end{macro}
-%
-% \iffalse
-%</knots>
-% \fi
-%\Finale
-\endinput
Deleted: trunk/Master/texmf-dist/source/latex/spath3/spath3.ins
===================================================================
--- trunk/Master/texmf-dist/source/latex/spath3/spath3.ins 2021-01-23 10:56:29 UTC (rev 57503)
+++ trunk/Master/texmf-dist/source/latex/spath3/spath3.ins 2021-01-23 22:17:41 UTC (rev 57504)
@@ -1,91 +0,0 @@
-%%
-%% This is file `spath3.ins',
-%% generated with the docstrip utility.
-%%
-%% The original source files were:
-%%
-%% spath3.dtx (with options: `install')
-%% ----------------------------------------------------------------
-%% spath3 --- Functions for manipulating PGF soft paths
-%% E-mail: stacey at math.ntnu.no
-%% Released under the LaTeX Project Public License v1.3c or later
-%% See http://www.latex-project.org/lppl.txt
-%% ----------------------------------------------------------------
-%%
-\input docstrip.tex
-\keepsilent
-\askforoverwritefalse
-\preamble
-----------------------------------------------------------------
-spath3 --- Functions for manipulating PGF soft paths
-E-mail: stacey at math.ntnu.no
-Released under the LaTeX Project Public License v1.3c or later
-See http://www.latex-project.org/lppl.txt
-----------------------------------------------------------------
-
-\endpreamble
-\postamble
-
-Copyright (C) 2011-2019 by Andrew Stacey <stacey at math.ntnu.no>
-
-This work may be distributed and/or modified under the
-conditions of the LaTeX Project Public License (LPPL), either
-version 1.3c of this license or (at your option) any later
-version. The latest version of this license is in the file:
-
-http://www.latex-project.org/lppl.txt
-
-This work is "maintained" (as per LPPL maintenance status) by
-Andrew Stacey.
-
-This work consists of the files spath3.dtx
- calligraphy_doc.tex
- knots_doc.tex
-and the derived files spath3.ins,
- spath3_code.pdf,
- spath3.sty,
- tikzlibrarycalligraphy.code.tex
- tikzlibraryknots.code.tex
- calligraphy.pdf
- knots.pdf
- README
-
-\endpostamble
-\usedir{tex/latex/spath3}
-\generate{
- \file{\jobname.sty}{\from{\jobname.dtx}{spath3}}
-}
-\generate{
- \file{tikzlibrarycalligraphy.code.tex}{\from{\jobname.dtx}{calligraphy}}
-}
-\generate{
- \file{tikzlibraryknots.code.tex}{\from{\jobname.dtx}{knots}}
-}
-\endbatchfile
-%%
-%% Copyright (C) 2011-2019 by Andrew Stacey <stacey at math.ntnu.no>
-%%
-%% This work may be distributed and/or modified under the
-%% conditions of the LaTeX Project Public License (LPPL), either
-%% version 1.3c of this license or (at your option) any later
-%% version. The latest version of this license is in the file:
-%%
-%% http://www.latex-project.org/lppl.txt
-%%
-%% This work is "maintained" (as per LPPL maintenance status) by
-%% Andrew Stacey.
-%%
-%% This work consists of the files spath3.dtx
-%% calligraphy_doc.tex
-%% knots_doc.tex
-%% and the derived files spath3.ins,
-%% spath3_code.pdf,
-%% spath3.sty,
-%% tikzlibrarycalligraphy.code.tex
-%% tikzlibraryknots.code.tex
-%% calligraphy.pdf
-%% knots.pdf
-%% README
-%%
-%%
-%% End of file `spath3.ins'.
Added: trunk/Master/texmf-dist/source/latex/spath3/spath3_code.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/spath3/spath3_code.dtx (rev 0)
+++ trunk/Master/texmf-dist/source/latex/spath3/spath3_code.dtx 2021-01-23 22:17:41 UTC (rev 57504)
@@ -0,0 +1,6719 @@
+% \iffalse meta-comment
+%<*internal>
+\iffalse
+%</internal>
+%<*readme>
+----------------------------------------------------------------
+spath3 --- LaTeX3 functions for manipulating PGF soft paths
+E-mail: loopspace at mathforge.org
+Released under the LaTeX Project Public License v1.3c or later
+See http://www.latex-project.org/lppl.txt
+----------------------------------------------------------------
+
+This package defines some functions used to manipulate PGFs soft paths.
+As applications of its use, included are a package for drawing calligraphic paths and a package for drawing knot diagrams.
+%</readme>
+%<*internal>
+\fi
+\def\nameofplainTeX{plain}
+\ifx\fmtname\nameofplainTeX\else
+ \expandafter\begingroup
+\fi
+%</internal>
+%<*install>
+\input l3docstrip.tex
+\keepsilent
+\askforoverwritefalse
+\preamble
+----------------------------------------------------------------
+spath3 --- Functions for manipulating PGF soft paths
+E-mail: loopspace at mathforge.org
+Released under the LaTeX Project Public License v1.3c or later
+See http://www.latex-project.org/lppl.txt
+----------------------------------------------------------------
+
+\endpreamble
+\postamble
+
+Copyright (C) 2011-2019 by Andrew Stacey <loopspace at mathforge.org>
+
+This work may be distributed and/or modified under the
+conditions of the LaTeX Project Public License (LPPL), either
+version 1.3c of this license or (at your option) any later
+version. The latest version of this license is in the file:
+
+http://www.latex-project.org/lppl.txt
+
+This work is "maintained" (as per LPPL maintenance status) by
+Andrew Stacey.
+
+This work consists of the files spath3.dtx
+ calligraphy_doc.tex
+ knots_doc.tex
+ spath3.tex
+and the derived files spath3.ins,
+ spath3_code.pdf,
+ spath3.sty,
+ tikzlibrarycalligraphy.code.tex
+ tikzlibraryknots.code.tex
+ tikzlibraryspath3.code.tex
+ calligraphy.pdf
+ knots.pdf
+ spath3.pdf
+ README
+
+\endpostamble
+\usedir{tex/latex/spath3}
+\generate{
+ \file{spath3.sty}{\from{\jobname.dtx}{spath3}}
+}
+\generate{
+ \file{tikzlibrarycalligraphy.code.tex}{\from{\jobname.dtx}{calligraphy}}
+}
+\generate{
+ \file{tikzlibraryknots.code.tex}{\from{\jobname.dtx}{knots}}
+}
+\generate{
+ \file{tikzlibraryspath3.code.tex}{\from{\jobname.dtx}{tikzspath3}}
+}
+%</install>
+%<install>\endbatchfile
+%<*internal>
+\usedir{source/latex/spath3}
+\generate{
+ \file{\jobname.ins}{\from{\jobname.dtx}{install}}
+}
+\nopreamble\nopostamble
+\usedir{doc/latex/demopkg}
+\generate{
+ \file{README.txt}{\from{\jobname.dtx}{readme}}
+}
+\ifx\fmtname\nameofplainTeX
+ \expandafter\endbatchfile
+\else
+ \expandafter\endgroup
+\fi
+%</internal>
+%<*driver>
+\documentclass[full]{l3doc}
+\usepackage[T1]{fontenc}
+\usepackage{lmodern}
+%\usepackage{morefloats}
+\usepackage{tikz}
+\usepackage{trace}
+\usepackage{spath3}
+%\traceoff
+%\usepackage[numbered]{hypdoc}
+\definecolor{lstbgcolor}{rgb}{0.9,0.9,0.9}
+
+\usepackage{listings}
+\lstloadlanguages{[LaTeX]TeX}
+\lstset{
+ breakatwhitespace=true,
+ breaklines=true,
+ language=[LaTeX]TeX,
+ basicstyle=\small\ttfamily,
+ keepspaces=true,
+ columns=fullflexible
+}
+
+\usepackage{fancyvrb}
+
+\newenvironment{example}
+ {\VerbatimEnvironment
+ \begin{VerbatimOut}[gobble=2]{example.out}}
+ {\end{VerbatimOut}
+ \begin{center}
+% \setlength{\parindent}{0pt}
+ \fbox{\begin{minipage}{.9\linewidth}
+ \lstinputlisting[]{example.out}
+ \end{minipage}}
+ \fbox{\begin{minipage}{.9\linewidth}
+ \centering
+ \input{example.out}
+ \end{minipage}}
+\end{center}
+}
+\EnableCrossrefs
+\CodelineIndex
+\RecordChanges
+\begin{document}
+ \DocInput{\jobname.dtx}
+\end{document}
+%</driver>
+% \fi
+%
+% \CheckSum{6848}
+%
+% \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
+% Lower-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
+% Digits \0\1\2\3\4\5\6\7\8\9
+% Exclamation \! Double quote \" Hash (number) \#
+% Dollar \$ Percent \% Ampersand \&
+% Acute accent \' Left paren \( Right paren \)
+% Asterisk \* Plus \+ Comma \,
+% Minus \- Point \. Solidus \/
+% Colon \: Semicolon \; Less than \<
+% Equals \= Greater than \> Question mark \?
+% Commercial at \@ Left bracket \[ Backslash \\
+% Right bracket \] Circumflex \^ Underscore \_
+% Grave accent \` Left brace \{ Vertical bar \|
+% Right brace \} Tilde \~}
+%
+%
+% \changes{1.0}{2011/05/03}{Converted to DTX file}
+% \changes{1.1}{2016/02/19}{Fixes due to changes in LaTeX3}
+% \changes{1.2}{2019/02/12}{More fixes due to changes in LaTeX3}
+% \changes{1.4}{2020/12/18}{A fair amount of code reimplementation and reorganisation, together with defining TikZ keys to make functions available for use.}
+% \changes{2.0}{2021/01/19}{Refactored the code to remove the OO approach and make it functional, introduced the spath3 TikZ library to provide a user interface.}
+%
+% \DoNotIndex{\newcommand,\newenvironment}
+%
+% \providecommand*{\url}{\texttt}
+% \GetFileInfo{spath3.sty}
+% \title{The \textsf{spath3} package: code}
+% \author{Andrew Stacey \\ \url{loopspace at mathforge.org}}
+% \date{\fileversion~from \filedate}
+%
+%
+% \maketitle
+%
+%
+% \section{Introduction}
+%
+% The \Verb+spath3+ package is intended as a library for manipulating PGF's \emph{soft paths}.
+% In between defining a path and using it, PGF stores a path as a \emph{soft path} where all the defining structure has been resolved into the basic operations but these have not yet been written to the output file.
+% They can therefore still be manipulated by \TeX, and as they have a very rigid form (and limited vocabulary), they are relatively easy to modify.
+% This package provides some methods for working with these paths.
+% It was originally not really intended for use by end users but as a foundation on which other packages can be built.
+% However, over the years I've found myself using it at ever higher levels and so a set of interfaces has been designed using TikZ keys.
+%
+% It also provides the engine that drives a few other packages, such as the \Verb+calligraphy+, \Verb+knot+, and \Verb+penrose+ packages.
+% The first two of these are subpackages of this one.
+% The \Verb+calligraphy+ package simulates a calligraphic pen stroking a path.
+% The \Verb+knots+ package can be used to draw knot (and similar) diagrams.
+%
+% For usage, see the documentation of the following packages (\Verb+texdoc <package>+):
+%
+% \begin{itemize}
+% \item \Verb+calligraphy+
+% \item \Verb+knots+
+% \item \Verb+penrose+
+% \item \Verb+spath3+ (\emph{this} document is the code, there's another which focusses on usage)
+% \end{itemize}
+%
+% \section{Technical Details}
+%
+% The format of a soft path is a sequence of triples of the form \Verb+\macro {dimension}{dimension}+.
+% The macro is one of a short list, the dimensions are coordinates in points.
+% There are certain further restrictions, particularly that every path must begin with a \Verb+move to+, and B\'ezier curves consist of three triples.
+%
+% In the original implementation, I wrapped this token list in a \Verb+prop+ to store useful information along with the path.
+% Over time, this additional structure has proved a little unwieldy and I've pared it back to working primarily with the original soft path as a token list.
+%
+% A frequent use of this package is to break a path into pieces and do something with each of those pieces.
+% To that end, there are various words that I use to describe the levels of the structure of a path.
+%
+% At the top level is the path itself.
+% At the bottom level are the triples of the form \Verb+\macro{dim}{dim}+, as described above.
+% In between these are the \emph{segments} and \emph{components}.
+%
+% A \emph{segment} is a minimal drawing piece.
+% Thus it might be a straight line or a B\'ezier curve.
+% When a path is broken into segments then each segment is a complete path so it isn't simply a selection of triples from the original path.
+%
+% A \emph{component} is a minimal connected section of the path.
+% So every component starts with a move command and continues until the next move command.
+% For ease of implementation (and to enable a copperplate pen in the calligraphy package!), an isolated move is considered as a component.
+% Thus the following path consists of three components:
+%
+% \begin{Verbatim}
+% \path (0,0) -- (1,0) (2,0) (3,0) to[out=0,in=90] (4,0);
+% \end{Verbatim}
+%
+% \StopEventually{}
+%
+% \section{Implementation}
+%
+% \iffalse
+%<*spath3>
+% \fi
+% \subsection{Initialisation}
+%
+% \begin{macrocode}
+%<@@=spath>
+% \end{macrocode}
+%
+% Load the \LaTeX3 foundation and register us as a \LaTeX3\ package.
+% \begin{macrocode}
+\NeedsTeXFormat{LaTeX2e}
+\RequirePackage{expl3}
+\RequirePackage{pgf}
+\ProvidesExplPackage {spath3} {2021/01/19} {2.0} {Functions for
+manipulating PGF soft paths}
+\RequirePackage{xparse}
+% \end{macrocode}
+%
+% Utilities copied from \url{https://github.com/loopspace/LaTeX3-Utilities} for adding something in braces to a token list.
+% \begin{macrocode}
+\cs_new_protected:Nn \@@_tl_put_right_braced:Nn
+{
+ \tl_put_right:Nn #1 { { #2 } }
+}
+\cs_generate_variant:Nn \@@_tl_put_right_braced:Nn { NV, cV, cv, Nx, cx }
+
+\cs_new_protected:Nn \@@_tl_gput_right_braced:Nn
+{
+ \tl_gput_right:Nn #1 { { #2 } }
+}
+\cs_generate_variant:Nn \@@_tl_gput_right_braced:Nn { NV, cV, cv, Nx, cx }
+\cs_new_protected:Nn \@@_tl_put_left_braced:Nn
+{
+ \tl_put_left:Nn #1 { { #2 } }
+}
+\cs_generate_variant:Nn \@@_tl_put_left_braced:Nn { NV, cV, cv, Nx, cx }
+
+\cs_new_protected:Nn \@@_tl_gput_left_braced:Nn
+{
+ \tl_gput_left:Nn #1 { { #2 } }
+}
+\cs_generate_variant:Nn \@@_tl_gput_left_braced:Nn { NV, cV, cv, Nx, cx }
+% \end{macrocode}
+%
+% We need a slew of temporary variables.
+% \begin{macrocode}
+\tl_new:N \l_@@_tmpa_tl
+\tl_new:N \l_@@_tmpb_tl
+\tl_new:N \l_@@_tmpc_tl
+\tl_new:N \l_@@_tmpd_tl
+\tl_new:N \l_@@_tmpe_tl
+
+\seq_new:N \l_@@_tmpa_seq
+\seq_new:N \l_@@_tmpb_seq
+
+\tl_new:N \g_@@_output_tl
+\int_new:N \g_@@_output_int
+\seq_new:N \g_@@_output_seq
+
+\dim_new:N \l_@@_tmpa_dim
+\dim_new:N \l_@@_tmpb_dim
+\dim_new:N \l_@@_move_x_dim
+\dim_new:N \l_@@_move_y_dim
+\fp_new:N \l_@@_tmpa_fp
+\fp_new:N \l_@@_tmpb_fp
+\int_new:N \l_@@_tmpa_int
+
+\bool_new:N \g_@@_output_bool
+\bool_new:N \l_@@_closed_bool
+% \end{macrocode}
+%
+% We need to be able to compare against the macros that can occur in a soft path so these token lists contain them.
+% These are global constants so that they can be used in other packages.
+% \begin{macrocode}
+\tl_const:Nn \c_spath_moveto_tl {\pgfsyssoftpath at movetotoken}
+\tl_const:Nn \c_spath_lineto_tl {\pgfsyssoftpath at linetotoken}
+\tl_const:Nn \c_spath_curveto_tl {\pgfsyssoftpath at curvetotoken}
+\tl_const:Nn \c_spath_curvetoa_tl {\pgfsyssoftpath at curvetosupportatoken}
+\tl_const:Nn \c_spath_curvetob_tl {\pgfsyssoftpath at curvetosupportbtoken}
+\tl_const:Nn \c_spath_closepath_tl {\pgfsyssoftpath at closepathtoken}
+% \end{macrocode}
+%
+%
+% We will want to be able to use anonymous spaths internally, so we create a global counter that we can use to refer to them.
+% \begin{macrocode}
+\int_new:N \g_@@_anon_int
+\int_gzero:N \g_@@_anon_int
+% \end{macrocode}
+%
+% Groups and iterations don't mix well and I haven't got a good scheme for protecting local calculations when iterating, so we do our best with iteration-specific variables.
+% \begin{macrocode}
+\tl_new:N \l_@@_itera_tl
+\tl_new:N \l_@@_iterb_tl
+\tl_new:N \l_@@_iterc_tl
+\tl_new:N \l_@@_iterd_tl
+\tl_new:N \l_@@_iterp_tl
+\dim_new:N \l_@@_itera_dim
+\dim_new:N \l_@@_iterb_dim
+\seq_new:N \l_@@_iter_seq
+% \end{macrocode}
+%
+% And some error messages
+% \begin{macrocode}
+\msg_new:nnn { spath3 } { unknown path construction } { The~ path~ construction~ element~ #1~ is~ not~ currently~ supported.}
+% \end{macrocode}
+%
+%
+% \subsection{Functional Implementation}
+%
+% In the functional approach, we start with a token list containing a soft path and do something to it (either calculate some information or manipulate it in some fashion).
+% We then store that information, or the manipulated path, in an appropriate macro.
+% The macro to store it in is the first argument.
+% These functions occur in two versions, the one with the \texttt{g} makes the assignment global.
+%
+% \begin{macro}{
+% \spath_segments_to_seq:Nn,
+% \spath_segments_gto_seq:Nn
+%}
+% Splits a soft path into \emph{segments}, storing the result in a sequence.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_segments_to_seq:n #1
+{
+ \group_begin:
+ \tl_set:Nn \l_@@_itera_tl {#1}
+ \tl_clear:N \l_@@_iterb_tl
+ \seq_clear:N \l_@@_iter_seq
+ \dim_zero:N \l_@@_itera_dim
+ \dim_zero:N \l_@@_iterb_dim
+
+ \bool_until_do:nn {
+ \tl_if_empty_p:N \l_@@_itera_tl
+ }
+ {
+ \tl_set:Nx \l_@@_iterc_tl {\tl_head:N \l_@@_itera_tl}
+ \tl_set:Nx \l_@@_itera_tl {\tl_tail:N \l_@@_itera_tl}
+ \tl_case:NnF \l_@@_iterc_tl
+ {
+ \c_spath_moveto_tl
+ {
+ \tl_set_eq:NN \l_@@_iterb_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l_@@_iterb_tl {{\tl_head:N \l_@@_itera_tl}}
+ \dim_set:Nn \l_@@_itera_dim {\tl_head:N \l_@@_itera_tl}
+ \tl_set:Nx \l_@@_itera_tl {\tl_tail:N \l_@@_itera_tl}
+
+ \tl_put_right:Nx \l_@@_iterb_tl {{\tl_head:N \l_@@_itera_tl}}
+ \dim_set:Nn \l_@@_iterb_dim {\tl_head:N \l_@@_itera_tl}
+ \tl_set:Nx \l_@@_itera_tl {\tl_tail:N \l_@@_itera_tl}
+
+ \tl_set:Nx \l_@@_iterd_tl {\tl_head:N \l_@@_itera_tl}
+ \tl_if_eq:NNF \l_@@_iterd_tl \c_spath_moveto_tl
+ {
+ \tl_clear:N \l_@@_iterb_tl
+ }
+
+ }
+
+ \c_spath_lineto_tl
+ {
+ \tl_set_eq:NN \l_@@_iterb_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l_@@_iterb_tl
+ {
+ {\dim_use:N \l_@@_itera_dim}
+ {\dim_use:N \l_@@_iterb_dim}
+ }
+ \tl_put_right:NV \l_@@_iterb_tl \c_spath_lineto_tl
+
+ \tl_put_right:Nx \l_@@_iterb_tl {{\tl_head:N \l_@@_itera_tl}}
+ \dim_set:Nn \l_@@_itera_dim {\tl_head:N \l_@@_itera_tl}
+ \tl_set:Nx \l_@@_itera_tl {\tl_tail:N \l_@@_itera_tl}
+
+ \tl_put_right:Nx \l_@@_iterb_tl {{\tl_head:N \l_@@_itera_tl}}
+ \dim_set:Nn \l_@@_iterb_dim {\tl_head:N \l_@@_itera_tl}
+ \tl_set:Nx \l_@@_itera_tl {\tl_tail:N \l_@@_itera_tl}
+
+ }
+
+ \c_spath_curvetoa_tl
+ {
+ \tl_set_eq:NN \l_@@_iterb_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l_@@_iterb_tl
+ {
+ {\dim_use:N \l_@@_itera_dim}
+ {\dim_use:N \l_@@_iterb_dim}
+ }
+ \tl_put_right:NV \l_@@_iterb_tl \c_spath_curvetoa_tl
+
+ \prg_replicate:nn {2} {
+ \tl_put_right:Nx \l_@@_iterb_tl {{\tl_head:N \l_@@_itera_tl}}
+ \tl_set:Nx \l_@@_itera_tl {\tl_tail:N \l_@@_itera_tl}
+ \tl_put_right:Nx \l_@@_iterb_tl {{\tl_head:N \l_@@_itera_tl}}
+ \tl_set:Nx \l_@@_itera_tl {\tl_tail:N \l_@@_itera_tl}
+ \tl_put_right:Nx \l_@@_iterb_tl {\tl_head:N \l_@@_itera_tl}
+ \tl_set:Nx \l_@@_itera_tl {\tl_tail:N \l_@@_itera_tl}
+ }
+
+ \tl_put_right:Nx \l_@@_iterb_tl {{\tl_head:N \l_@@_itera_tl}}
+ \dim_set:Nn \l_@@_itera_dim {\tl_head:N \l_@@_itera_tl}
+ \tl_set:Nx \l_@@_itera_tl {\tl_tail:N \l_@@_itera_tl}
+
+ \tl_put_right:Nx \l_@@_iterb_tl {{\tl_head:N \l_@@_itera_tl}}
+ \dim_set:Nn \l_@@_iterb_dim {\tl_head:N \l_@@_itera_tl}
+ \tl_set:Nx \l_@@_itera_tl {\tl_tail:N \l_@@_itera_tl}
+
+ }
+
+ \c_spath_closepath_tl
+ {
+ \tl_set_eq:NN \l_@@_iterb_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l_@@_iterb_tl
+ {
+ {\dim_use:N \l_@@_itera_dim}
+ {\dim_use:N \l_@@_iterb_dim}
+ }
+ \tl_put_right:NV \l_@@_iterb_tl \c_spath_lineto_tl
+
+ \tl_put_right:Nx \l_@@_iterb_tl {{\tl_head:N \l_@@_itera_tl}}
+ \dim_set:Nn \l_@@_itera_dim {\tl_head:N \l_@@_itera_tl}
+ \tl_set:Nx \l_@@_itera_tl {\tl_tail:N \l_@@_itera_tl}
+
+ \tl_put_right:Nx \l_@@_iterb_tl {{\tl_head:N \l_@@_itera_tl}}
+ \dim_set:Nn \l_@@_iterb_dim {\tl_head:N \l_@@_itera_tl}
+ \tl_set:Nx \l_@@_itera_tl {\tl_tail:N \l_@@_itera_tl}
+
+ }
+
+ }
+ {
+
+ \tl_set_eq:NN \l_@@_iterb_tl \l_@@_iterc_tl
+ \tl_put_right:Nx \l_@@_iterb_tl {{\tl_head:N \l_@@_itera_tl}}
+ \dim_set:Nn \l_@@_itera_dim {\tl_head:N \l_@@_itera_tl}
+ \tl_set:Nx \l_@@_itera_tl {\tl_tail:N \l_@@_itera_tl}
+
+ \tl_put_right:Nx \l_@@_iterb_tl {{\tl_head:N \l_@@_itera_tl}}
+ \dim_set:Nn \l_@@_iterb_dim {\tl_head:N \l_@@_itera_tl}
+ \tl_set:Nx \l_@@_itera_tl {\tl_tail:N \l_@@_itera_tl}
+
+ }
+
+ \tl_if_empty:NF \l_@@_iterb_tl
+ {
+ \seq_put_right:NV \l_@@_iter_seq \l_@@_iterb_tl
+ }
+ \tl_clear:N \l_@@_iterb_tl
+ }
+
+ \seq_gclear:N \g_@@_output_seq
+ \seq_gset_eq:NN \g_@@_output_seq \l_@@_iter_seq
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_segments_to_seq:Nn #1#2
+{
+ \@@_segments_to_seq:n {#2}
+ \seq_clear_new:N #1
+ \seq_set_eq:NN #1 \g_@@_output_seq
+ \seq_gclear:N \g_@@_output_seq
+}
+\cs_generate_variant:Nn \spath_segments_to_seq:Nn {NV, cn, cV, Nv, cv}
+\cs_new_protected_nopar:Npn \spath_segments_gto_seq:Nn #1#2
+{
+ \@@_segments_to_seq:n {#2}
+ \seq_clear_new:N #1
+ \seq_gset_eq:NN #1 \g_@@_output_seq
+ \seq_gclear:N \g_@@_output_seq
+}
+\cs_generate_variant:Nn \spath_segments_gto_seq:Nn {NV, cn, cV, Nv, cv}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_components_to_seq:Nn,
+% \spath_components_gto_seq:Nn,
+% \spath_components_to_clist:Nn,
+% \spath_components_gto_clist:Nn,
+% }
+% Splits a soft path into \emph{components}, storing the result in a sequence or a clist.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_components_to_seq:n #1
+{
+ \group_begin:
+ \tl_set:Nn \l_@@_itera_tl {#1}
+ \seq_clear:N \l_@@_iter_seq
+ \tl_set:Nx \l_@@_itera_tl {\tl_tail:N \l_@@_itera_tl}
+ \tl_put_right:NV \l_@@_itera_tl \c_spath_moveto_tl
+ \tl_set_eq:NN \l_@@_iterb_tl \c_spath_moveto_tl
+ \bool_do_until:nn {
+ \tl_if_empty_p:N \l_@@_itera_tl
+ }
+ {
+ \tl_set:Nx \l_@@_iterc_tl {\tl_head:N \l_@@_itera_tl}
+ \tl_if_eq:NNT \l_@@_iterc_tl \c_spath_moveto_tl
+ {
+ \seq_put_right:NV \l_@@_iter_seq \l_@@_iterb_tl
+ \tl_clear:N \l_@@_iterb_tl
+ }
+ \tl_if_single:NTF \l_@@_iterc_tl
+ {
+ \tl_put_right:NV \l_@@_iterb_tl \l_@@_iterc_tl
+ }
+ {
+ \tl_put_right:Nx \l_@@_iterb_tl {{\l_@@_iterc_tl}}
+ }
+ \tl_set:Nx \l_@@_itera_tl {\tl_tail:N \l_@@_itera_tl}
+ }
+
+ \seq_gclear:N \g_@@_output_seq
+ \seq_gset_eq:NN \g_@@_output_seq \l_@@_iter_seq
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_components_to_seq:Nn #1#2
+{
+ \@@_components_to_seq:n {#2}
+ \seq_clear_new:N #1
+ \seq_set_eq:NN #1 \g_@@_output_seq
+ \seq_gclear:N \g_@@_output_seq
+}
+\cs_generate_variant:Nn \spath_components_to_seq:Nn {NV, cn, cV, cv, Nv}
+\cs_new_protected_nopar:Npn \spath_components_gto_seq:Nn #1#2
+{
+ \@@_components_to_seq:n {#2}
+ \seq_clear_new:N #1
+ \seq_gset_eq:NN #1 \g_@@_output_seq
+ \seq_gclear:N \g_@@_output_seq
+}
+\cs_generate_variant:Nn \spath_components_gto_seq:Nn {NV, cn, cV, cv, Nv}
+\cs_new_protected_nopar:Npn \spath_components_to_clist:Nn #1#2
+{
+ \@@_components_to_seq:n {#2}
+ \clist_clear_new:N #1
+ \clist_set_from_seq:NN #1 \g_@@_output_seq
+ \seq_gclear:N \g_@@_output_seq
+}
+\cs_generate_variant:Nn \spath_components_to_clist:Nn {NV, cn, cV, cv, Nv}
+\cs_new_protected_nopar:Npn \spath_components_gto_clist:Nn #1#2
+{
+ \@@_components_to_seq:n {#2}
+ \clist_clear_new:N #1
+ \clist_gset_from_seq:NN #1 \g_@@_output_seq
+ \seq_gclear:N \g_@@_output_seq
+}
+\cs_generate_variant:Nn \spath_components_gto_clist:Nn {NV, cn, cV, cv, Nv}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\spath_length:n}
+% Counts the number of triples in the path.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \spath_length:n #1
+{
+ \int_eval:n {\tl_count:n {#1} / 3}
+}
+\cs_generate_variant:Nn \spath_length:n {V}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_reallength:Nn,
+% \spath_greallength:Nn
+% }
+% The real length of a path is the number of triples that actually draw something (that is, the number of lines, curves, and closepaths).
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_reallength:n #1
+{
+ \group_begin:
+ \int_set:Nn \l_@@_tmpa_int {0}
+ \tl_map_inline:nn {#1} {
+ \tl_set:Nn \l_@@_tmpc_tl {##1}
+ \tl_case:NnT \l_@@_tmpc_tl
+ {
+ \c_spath_lineto_tl {}
+ \c_spath_curveto_tl {}
+ \c_spath_closepath_tl {}
+ }
+ {
+ \int_incr:N \l_@@_tmpa_int
+ }
+ }
+ \int_gzero:N \g_@@_output_int
+ \int_gset_eq:NN \g_@@_output_int \l_@@_tmpa_int
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_reallength:Nn #1#2
+{
+ \@@_reallength:n {#2}
+ \int_set_eq:NN #1 \g_@@_output_int
+ \int_gzero:N \g_@@_output_int
+}
+\cs_generate_variant:Nn \spath_reallength:Nn {NV, cn, cV, Nv, cv}
+\cs_new_protected_nopar:Npn \spath_greallength:Nn #1#2
+{
+ \@@_reallength:n {#2}
+ \int_gset_eq:NN #1 \g_@@_output_int
+ \int_gzero:N \g_@@_output_int
+}
+\cs_generate_variant:Nn \spath_greallength:Nn {NV, cn, cV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_numberofcomponents:Nn,
+% \spath_gnumberofcomponents:Nn
+% }
+% A component is a continuous segment of the path, separated by moves.
+% Successive moves are not collapsed, and zero length moves count.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_numberofcomponents:n #1
+{
+ \group_begin:
+ \int_set:Nn \l_@@_tmpa_int {0}
+ \tl_map_inline:nn {#1} {
+ \tl_set:Nn \l_@@_tmpa_tl {##1}
+ \tl_case:Nn \l_@@_tmpa_tl
+ {
+ \c_spath_moveto_tl
+ {
+ \int_incr:N \l_@@_tmpa_int
+ }
+ }
+ }
+ \int_gzero:N \g_@@_output_int
+ \int_gset_eq:NN \g_@@_output_int \l_@@_tmpa_int
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_numberofcomponents:Nn #1#2
+{
+ \@@_numberofcomponents:n {#2}
+ \int_set_eq:NN #1 \g_@@_output_int
+ \int_gzero:N \g_@@_output_int
+}
+\cs_generate_variant:Nn \spath_numberofcomponents:Nn {NV, cn, cV}
+\cs_new_protected_nopar:Npn \spath_gnumberofcomponents:Nn #1#2
+{
+ \@@_numberofcomponents:n {#2}
+ \int_gset_eq:NN #1 \g_@@_output_int
+ \int_gzero:N \g_@@_output_int
+}
+\cs_generate_variant:Nn \spath_gnumberofcomponents:Nn {NV, cn, cV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_initialpoint:Nn,
+% \spath_ginitialpoint:Nn
+% }
+% The starting point of the path.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_initialpoint:n #1
+{
+ \group_begin:
+ \tl_clear:N \l_@@_tmpb_tl
+ \tl_set:Nx \l_@@_tmpb_tl
+ {
+ { \tl_item:nn {#1} {2} }
+ { \tl_item:nn {#1} {3} }
+ }
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_initialpoint:Nn #1#2
+{
+ \@@_initialpoint:n {#2}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_initialpoint:Nn {NV, cn, cV, Nv}
+\cs_new_protected_nopar:Npn \spath_ginitialpoint:Nn #1#2
+{
+ \@@_initialpoint:n {#2}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_ginitialpoint:Nn {NV, cn, cV, Nv}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_finalpoint:Nn,
+% \spath_gfinalpoint:Nn,
+% }
+% The final point of the path.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_finalpoint:n #1
+{
+ \group_begin:
+ \tl_set:Nn \l_@@_tmpa_tl {#1}
+ \tl_reverse:N \l_@@_tmpa_tl
+ \tl_clear:N \l_@@_tmpb_tl
+ \tl_set:Nx \l_@@_tmpb_tl
+ {
+ { \tl_item:Nn \l_@@_tmpa_tl {2} }
+ { \tl_item:Nn \l_@@_tmpa_tl {1} }
+ }
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_finalpoint:Nn #1#2
+{
+ \@@_finalpoint:n {#2}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_finalpoint:Nn {NV, cn, cV, Nv}
+\cs_new_protected_nopar:Npn \spath_gfinalpoint:Nn #1#2
+{
+ \@@_finalpoint:n {#2}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gfinalpoint:Nn {NV, cn, cV, Nv}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_reverse:Nn,
+% \spath_greverse:Nn
+% }
+% This computes the reverse of the path.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_reverse:n #1
+{
+ \group_begin:
+ \tl_set:Nn \l_@@_tmpa_tl {#1}
+
+ \tl_clear:N \l_@@_tmpb_tl
+ \tl_clear:N \l_@@_tmpd_tl
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+
+ \tl_put_left:Nx \l_@@_tmpd_tl
+ {
+ {\dim_use:N \l_@@_tmpa_dim}
+ {\dim_use:N \l_@@_tmpb_dim}
+ }
+
+ \bool_set_false:N \l_@@_closed_bool
+
+ \bool_until_do:nn {
+ \tl_if_empty_p:N \l_@@_tmpa_tl
+ }
+ {
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
+
+ \tl_case:NnTF \l_@@_tmpc_tl
+ {
+ \c_spath_moveto_tl {
+
+ \bool_if:NT \l_@@_closed_bool
+ {
+ \tl_put_right:NV \l_@@_tmpd_tl \c_spath_closepath_tl
+ \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpd_tl}
+ \tl_put_right:Nx \l_@@_tmpd_tl
+ {
+ { \tl_head:N \l_@@_tmpd_tl }
+ { \tl_head:N \l_@@_tmpe_tl }
+ }
+ }
+ \bool_set_false:N \l_@@_closed_bool
+ \tl_put_left:NV \l_@@_tmpd_tl \c_spath_moveto_tl
+ \tl_put_left:NV \l_@@_tmpb_tl \l_@@_tmpd_tl
+ \tl_clear:N \l_@@_tmpd_tl
+ }
+ \c_spath_lineto_tl {
+ \tl_put_left:NV \l_@@_tmpd_tl \c_spath_lineto_tl
+ }
+ \c_spath_curveto_tl {
+ \tl_put_left:NV \l_@@_tmpd_tl \c_spath_curvetoa_tl
+ }
+ \c_spath_curvetoa_tl {
+ \tl_put_left:NV \l_@@_tmpd_tl \c_spath_curveto_tl
+ }
+ \c_spath_curvetob_tl {
+ \tl_put_left:NV \l_@@_tmpd_tl \c_spath_curvetob_tl
+ }
+ }
+ {
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+
+ \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+
+ \tl_put_left:Nx \l_@@_tmpd_tl
+ {
+ {\dim_use:N \l_@@_tmpa_dim}
+ {\dim_use:N \l_@@_tmpb_dim}
+ }
+
+ }
+ {
+ \tl_if_eq:NNTF \l_@@_tmpc_tl \c_spath_closepath_tl
+ {
+ \bool_set_true:N \l_@@_closed_bool
+ }
+ {
+ \msg_warning:nnx { spath3 } { unknown path construction } {\l_@@_tmpc_tl }
+ }
+
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+
+ }
+ }
+
+ \bool_if:NT \l_@@_closed_bool
+ {
+ \tl_put_right:NV \l_@@_tmpd_tl \c_spath_closepath_tl
+ \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpd_tl}
+ \tl_put_right:Nx \l_@@_tmpd_tl
+ {
+ { \tl_head:N \l_@@_tmpd_tl }
+ { \tl_head:N \l_@@_tmpe_tl }
+ }
+ }
+
+ \bool_set_false:N \l_@@_closed_bool
+ \tl_put_left:NV \l_@@_tmpd_tl \c_spath_moveto_tl
+ \tl_put_left:NV \l_@@_tmpb_tl \l_@@_tmpd_tl
+
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_reverse:Nn #1#2
+{
+ \@@_reverse:n {#2}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_reverse:Nn {NV, cn, cV, Nv}
+\cs_new_protected_nopar:Npn \spath_reverse:N #1
+{
+ \spath_reverse:NV #1#1
+}
+\cs_generate_variant:Nn \spath_reverse:N {c}
+\cs_new_protected_nopar:Npn \spath_greverse:Nn #1#2
+{
+ \@@_reverse:n {#2}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_greverse:Nn {NV, cn, cV, Nv}
+\cs_new_protected_nopar:Npn \spath_greverse:N #1
+{
+ \spath_greverse:NV #1#1
+}
+\cs_generate_variant:Nn \spath_greverse:N {c}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_initialaction:Nn,
+% \spath_ginitialaction:Nn,
+% }
+% This is the first thing that the path does (after the initial move).
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_initialaction:n #1
+{
+ \group_begin:
+ \tl_clear:N \l_@@_tmpa_tl
+ \int_compare:nT
+ {
+ \tl_count:n {#1} > 3
+ }
+ {
+ \tl_set:Nx \l_@@_tmpa_tl
+ {
+ \tl_item:Nn {#1} {4}
+ }
+ }
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_initialaction:Nn #1#2
+{
+ \@@_initialaction:n {#2}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_initialaction:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_ginitialaction:Nn #1#2
+{
+ \@@_initialaction:n {#2}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_ginitialaction:Nn {NV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_finalaction:Nn,
+% \spath_gfinalaction:Nn
+% }
+% This is the last thing that the path does.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_finalaction:n #1
+{
+ \group_begin:
+ \tl_clear:N \l_@@_tmpb_tl
+ \int_compare:nT
+ {
+ \tl_count:n {#1} > 3
+ }
+ {
+ \tl_set:Nn \l_@@_tmpa_tl {#1}
+ \tl_reverse:N \l_@@_tmpa_tl
+ \tl_set:Nx \l_@@_tmpb_tl
+ {
+ \tl_item:Nn \l_@@_tmpa_tl {3}
+ }
+ \tl_if_eq:NNT \l_@@_tmpb_tl \c_spath_curvetoa_tl
+ {
+ \tl_set_eq:NN \l_@@_tmpb_tl \c_spath_curveto_tl
+ }
+ }
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_finalaction:Nn #1#2
+{
+ \@@_finalaction:n {#2}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_finalaction:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gfinalaction:Nn #1#2
+{
+ \@@_finalaction:n {#2}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gfinalaction:Nn {NV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_minbb:Nn,
+% \spath_gminbb:Nn
+% }
+% This computes the minimum (bottom left) of the bounding box of the path.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_minbb:n #1
+{
+ \group_begin:
+ \tl_set:Nn \l_@@_tmpa_tl {#1}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \bool_until_do:nn {
+ \tl_if_empty_p:N \l_@@_tmpa_tl
+ }
+ {
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \dim_set:Nn \l_@@_tmpa_dim {\dim_min:nn {\tl_head:N \l_@@_tmpa_tl} {\l_@@_tmpa_dim}}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \dim_set:Nn \l_@@_tmpb_dim {\dim_min:nn {\tl_head:N \l_@@_tmpa_tl} {\l_@@_tmpb_dim}}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ }
+ \tl_clear:N \l_@@_tmpb_tl
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\dim_use:N \l_@@_tmpa_dim}
+ {\dim_use:N \l_@@_tmpb_dim}
+ }
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_minbb:Nn #1#2
+{
+ \@@_minbb:n {#2}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_minbb:Nn {NV, cn, cV}
+\cs_new_protected_nopar:Npn \spath_gminbb:Nn #1#2
+{
+ \@@_minbb:n {#2}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gminbb:Nn {NV, cn, cV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_maxbb:Nn,
+% \spath_gmaxbb:Nn,
+% }
+% This computes the maximum (top right) of the bounding box of the path.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_maxbb:n #1
+{
+ \group_begin:
+ \tl_set:Nn \l_@@_tmpa_tl {#1}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \bool_until_do:nn {
+ \tl_if_empty_p:N \l_@@_tmpa_tl
+ }
+ {
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \dim_set:Nn \l_@@_tmpa_dim {\dim_max:nn {\tl_head:N \l_@@_tmpa_tl} {\l_@@_tmpa_dim}}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \dim_set:Nn \l_@@_tmpb_dim {\dim_max:nn {\tl_head:N \l_@@_tmpa_tl} {\l_@@_tmpb_dim}}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ }
+ \tl_clear:N \l_@@_tmpb_tl
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\dim_use:N \l_@@_tmpa_dim}
+ {\dim_use:N \l_@@_tmpb_dim}
+ }
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_maxbb:Nn #1#2
+{
+ \@@_maxbb:n {#2}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_maxbb:Nn {NV, cn, cV}
+\cs_new_protected_nopar:Npn \spath_gmaxbb:Nn #1#2
+{
+ \@@_maxbb:n {#2}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gmaxbb:Nn {NV, cn, cV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_save_to_aux:Nn,
+% \spath_save_to_aux:N
+% }
+% This saves a soft path to the auxfile.
+% The first argument is the macro that will be assigned to the soft path when the aux file is read back in.
+% \begin{macrocode}
+\int_set:Nn \l_@@_tmpa_int {\char_value_catcode:n {`@}}
+\char_set_catcode_letter:N @
+\cs_new_protected_nopar:Npn \spath_save_to_aux:Nn #1#2 {
+ \tl_if_empty:nF {#2}
+ {
+ \tl_clear:N \l_@@_tmpa_tl
+ \tl_put_right:Nn \l_@@_tmpa_tl {
+ \ExplSyntaxOn
+ \tl_clear:N #1
+ \tl_set:Nn #1 {#2}
+ \ExplSyntaxOff
+ }
+ \protected at write\@auxout{}{
+ \tl_to_str:N \l_@@_tmpa_tl
+ }
+ }
+}
+\char_set_catcode:nn {`@} {\l_@@_tmpa_int}
+\cs_generate_variant:Nn \spath_save_to_aux:Nn {cn, cV, NV}
+\cs_new_protected_nopar:Npn \spath_save_to_aux:N #1
+{
+ \tl_if_exist:NT #1
+ {
+ \spath_save_to_aux:NV #1#1
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \subsection{Path Manipulation}
+%
+% These functions all manipulate a soft path.
+% They come with a variety of different argument specifications.
+% As a general rule, the first argument is the macro in which to store the modified path, the second is the path to manipulate, and the rest are the information about what to do.
+% There is always a variant in which the path is specified by a macro and restored back in that same macro.
+%
+%
+% \begin{macro}{
+% \spath_translate:Nnnn,
+% \spath_translate:Nnn,
+% \spath_gtranslate:Nnnn,
+% \spath_gtranslate:Nnn
+% }
+% Translates a path.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_translate:nnn #1#2#3
+{
+ \group_begin:
+ \tl_set:Nn \l_@@_tmpa_tl {#1}
+ \tl_clear:N \l_@@_tmpb_tl
+ \bool_until_do:nn {
+ \tl_if_empty_p:N \l_@@_tmpa_tl
+ }
+ {
+ \tl_put_right:Nx \l_@@_tmpb_tl {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+
+ \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl + #2}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+
+ \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl + #3}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\dim_use:N \l_@@_tmpa_dim}
+ {\dim_use:N \l_@@_tmpb_dim}
+ }
+ }
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_translate:Nnnn #1#2#3#4
+{
+ \@@_translate:nnn {#2}{#3}{#4}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_translate:Nnnn {NVxx, NVVV, NVnn}
+\cs_new_protected_nopar:Npn \spath_translate:Nnn #1#2#3
+{
+ \spath_translate:NVnn #1#1{#2}{#3}
+}
+\cs_generate_variant:Nn \spath_translate:Nnn {NVV, cnn, cVV}
+\cs_new_protected_nopar:Npn \spath_gtranslate:Nnnn #1#2#3#4
+{
+ \@@_translate:nnn {#2}{#3}{#4}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gtranslate:Nnnn {NVxx, NVVV, NVnn}
+\cs_new_protected_nopar:Npn \spath_gtranslate:Nnn #1#2#3
+{
+ \spath_gtranslate:NVnn #1#1{#2}{#3}
+}
+\cs_generate_variant:Nn \spath_gtranslate:Nnn {NVV, cnn, cVV}
+% \end{macrocode}
+%
+% This variant allows for passing the coordinates as a single braced group as it strips off the outer braces of the second argument.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \spath_translate:Nn #1#2
+{
+ \spath_translate:Nnn #1 #2
+}
+\cs_generate_variant:Nn \spath_translate:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gtranslate:Nn #1#2
+{
+ \spath_gtranslate:Nnn #1 #2
+}
+\cs_generate_variant:Nn \spath_gtranslate:Nn {NV}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{
+% \spath_scale:Nnnn,
+% \spath_scale:Nnn,
+% \spath_gscale:Nnnn,
+% \spath_gscale:Nnn
+% }
+% Scale a path.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_scale:nnn #1#2#3
+{
+ \group_begin:
+ \tl_set:Nn \l_@@_tmpa_tl {#1}
+ \tl_clear:N \l_@@_tmpb_tl
+ \bool_until_do:nn {
+ \tl_if_empty_p:N \l_@@_tmpa_tl
+ }
+ {
+ \tl_put_right:Nx \l_@@_tmpb_tl {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+
+ \fp_set:Nn \l_@@_tmpa_fp {\tl_head:N \l_@@_tmpa_tl * #2}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+
+ \fp_set:Nn \l_@@_tmpb_fp {\tl_head:N \l_@@_tmpa_tl * #3}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\fp_to_dim:N \l_@@_tmpa_fp}
+ {\fp_to_dim:N \l_@@_tmpb_fp}
+ }
+ }
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_scale:Nnnn #1#2#3#4
+{
+ \@@_scale:nnn {#2}{#3}{#4}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_scale:Nnnn {NVnn, Nnxx}
+\cs_new_protected_nopar:Npn \spath_scale:Nnn #1#2#3
+{
+ \spath_scale:NVnn #1#1{#2}{#3}
+}
+\cs_generate_variant:Nn \spath_scale:Nnn {cnn, cVV, NVV}
+\cs_new_protected_nopar:Npn \spath_gscale:Nnnn #1#2#3#4
+{
+ \@@_scale:nnn {#2}{#3}{#4}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gscale:Nnnn {NVnn, Nnxx}
+\cs_new_protected_nopar:Npn \spath_gscale:Nnn #1#2#3
+{
+ \spath_gscale:NVnn #1#1{#2}{#3}
+}
+\cs_generate_variant:Nn \spath_gscale:Nnn {cnn, cVV, NVV}
+% \end{macrocode}
+%
+% This variant allows for passing the coordinates as a single braced group as it strips off the outer braces of the second argument.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \spath_scale:Nn #1#2
+{
+ \spath_scale:Nnn #1 #2
+}
+
+\cs_generate_variant:Nn \spath_scale:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gscale:Nn #1#2
+{
+ \spath_gscale:Nnn #1 #2
+}
+
+\cs_generate_variant:Nn \spath_gscale:Nn {NV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_transform:Nnnnnnnn,
+% \spath_transform:Nnnnnnn,
+% \spath_gtransform:Nnnnnnnn,
+% \spath_gtransform:Nnnnnnn,
+% }
+% Applies an affine (matrix and vector) transformation to path.
+% The matrix is specified in rows first.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_transform:nnnnnnn #1#2#3#4#5#6#7
+{
+ \group_begin:
+ \tl_set:Nn \l_@@_tmpa_tl {#1}
+ \tl_clear:N \l_@@_tmpb_tl
+ \bool_until_do:nn {
+ \tl_if_empty_p:N \l_@@_tmpa_tl
+ }
+ {
+ \tl_put_right:Nx \l_@@_tmpb_tl {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpd_tl {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+
+ \fp_set:Nn \l_@@_tmpa_fp {\l_@@_tmpc_tl * #2 + \l_@@_tmpd_tl * #4 + #6}
+ \fp_set:Nn \l_@@_tmpb_fp {\l_@@_tmpc_tl * #3 + \l_@@_tmpd_tl * #5 + #7}
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\fp_to_dim:N \l_@@_tmpa_fp}
+ {\fp_to_dim:N \l_@@_tmpb_fp}
+ }
+ }
+
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_transform:Nnnnnnnn #1#2#3#4#5#6#7#8
+{
+ \@@_transform:nnnnnnn {#2}{#3}{#4}{#5}{#6}{#7}{#8}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_transform:Nnnnnnnn {NVnnnnnn, Nnxxxxxx, cnnnnnnn}
+\cs_new_protected_nopar:Npn \spath_transform:Nnnnnnn #1#2#3#4#5#6#7
+{
+ \spath_transform:NVnnnnnn #1#1{#2}{#3}{#4}{#5}{#6}{#7}
+}
+\cs_generate_variant:Nn \spath_transform:Nnnnnnn {cnnnnnn}
+\cs_new_protected_nopar:Npn \spath_transform:Nnn #1#2#3
+{
+ \spath_transform:Nnnnnnnn #1{#2}#3
+}
+\cs_generate_variant:Nn \spath_transform:Nnn {cnn, cVn, NVn, NnV}
+\cs_new_protected_nopar:Npn \spath_transform:Nn #1#2
+{
+ \spath_transform:NVnnnnnn #1#1#2
+}
+\cs_generate_variant:Nn \spath_transform:Nn {cn, cV, NV}
+
+\cs_new_protected_nopar:Npn \spath_gtransform:Nnnnnnnn #1#2#3#4#5#6#7#8
+{
+ \@@_transform:nnnnnnn {#2}{#3}{#4}{#5}{#6}{#7}{#8}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gtransform:Nnnnnnnn {NVnnnnnn, Nnxxxxxx, cnnnnnnn}
+\cs_new_protected_nopar:Npn \spath_gtransform:Nnnnnnn #1#2#3#4#5#6#7
+{
+ \spath_gtransform:NVnnnnnn #1#1{#2}{#3}{#4}{#5}{#6}{#7}
+}
+\cs_generate_variant:Nn \spath_gtransform:Nnnnnnn {cnnnnnn}
+\cs_new_protected_nopar:Npn \spath_gtransform:Nnn #1#2#3
+{
+ \spath_gtransform:Nnnnnnnn #1{#2}#3
+}
+\cs_generate_variant:Nn \spath_gtransform:Nnn {cnn, cVn, NVn, NnV}
+\cs_new_protected_nopar:Npn \spath_gtransform:Nn #1#2
+{
+ \spath_gtransform:NVnnnnnn #1#1#2
+}
+\cs_generate_variant:Nn \spath_gtransform:Nn {cn, cV, NV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_weld:Nnn,
+% \spath_weld:Nn,
+% \spath_gweld:Nnn,
+% \spath_gweld:Nn
+% }
+% This welds one path to another, moving the second so that its initial point coincides with the first's final point.
+% It is called a \emph{weld} because the initial move of the second path is removed.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_weld:nn #1#2
+{
+ \group_begin:
+ \tl_set:Nn \l_@@_tmpa_tl {#1}
+ \tl_set:Nn \l_@@_tmpb_tl {#2}
+
+ \spath_finalpoint:NV \l_@@_tmpc_tl \l_@@_tmpa_tl
+ \spath_initialpoint:NV \l_@@_tmpd_tl \l_@@_tmpb_tl
+
+ \dim_set:Nn \l_@@_tmpa_dim
+ {
+ \tl_item:Nn \l_@@_tmpc_tl {1}
+ -
+ \tl_item:Nn \l_@@_tmpd_tl {1}
+ }
+ \dim_set:Nn \l_@@_tmpb_dim
+ {
+ \tl_item:Nn \l_@@_tmpc_tl {2}
+ -
+ \tl_item:Nn \l_@@_tmpd_tl {2}
+ }
+
+ \spath_translate:NVV \l_@@_tmpb_tl \l_@@_tmpa_dim \l_@@_tmpb_dim
+
+ \prg_replicate:nn {3}
+ {
+ \tl_set:Nx \l_@@_tmpb_tl {\tl_tail:N \l_@@_tmpb_tl}
+ }
+
+ \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpb_tl
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_weld:Nnn #1#2#3
+{
+ \@@_weld:nn {#2}{#3}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_weld:Nnn {NVV,NVn}
+\cs_new_protected_nopar:Npn \spath_weld:Nn #1#2
+{
+ \spath_weld:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_weld:Nn {NV, Nv, cV, cv}
+\cs_new_protected_nopar:Npn \spath_gweld:Nnn #1#2#3
+{
+ \@@_weld:nn {#2}{#3}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gweld:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_gweld:Nn #1#2
+{
+ \spath_gweld:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_gweld:Nn {NV, Nv, cV, cv}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{
+% \spath_append_no_move:Nnn,
+% \spath_append_no_move:Nn,
+% \spath_gappend_no_move:Nnn,
+% \spath_gappend_no_move:Nn,
+% }
+% Append the path from the second \Verb+spath+ to the first, removing
+% the adjoining move.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_append_no_move:nn #1#2
+{
+ \group_begin:
+ \tl_set:Nn \l_@@_tmpa_tl {#1}
+ \tl_set:Nn \l_@@_tmpb_tl {#2}
+ \tl_set:Nx \l_@@_tmpb_tl {\tl_tail:N \l_@@_tmpb_tl}
+ \tl_set:Nx \l_@@_tmpb_tl {\tl_tail:N \l_@@_tmpb_tl}
+ \tl_set:Nx \l_@@_tmpb_tl {\tl_tail:N \l_@@_tmpb_tl}
+
+ \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpb_tl
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_append_no_move:Nnn #1#2#3
+{
+ \@@_append_no_move:nn {#2}{#3}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_append_no_move:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_append_no_move:Nn #1#2
+{
+ \spath_append_no_move:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_append_no_move:Nn {NV, cv}
+\cs_new_protected_nopar:Npn \spath_gappend_no_move:Nnn #1#2#3
+{
+ \@@_append_no_move:nn {#2}{#3}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gappend_no_move:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_gappend_no_move:Nn #1#2
+{
+ \spath_gappend_no_move:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_gappend_no_move:Nn {NV, cv}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_append:Nnn,
+% \spath_append:Nn,
+% \spath_gappend:Nnn,
+% \spath_gappend:Nn,
+% }
+% Prepend the path from the second \Verb+spath+ to the first.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \spath_append:Nnn #1#2#3
+{
+ \tl_set:Nn #1 {#2}
+ \tl_put_right:Nn #1 {#3}
+}
+\cs_generate_variant:Nn \spath_append:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_append:Nn #1#2
+{
+ \spath_append:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_append:Nn {NV, Nv}
+\cs_new_protected_nopar:Npn \spath_gappend:Nnn #1#2#3
+{
+ \tl_gset:Nn #1 {#2}
+ \tl_gput_right:Nn #1 {#3}
+}
+\cs_generate_variant:Nn \spath_gappend:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_gappend:Nn #1#2
+{
+ \spath_gappend:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_gappend:Nn {NV, Nv}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{
+% \spath_prepend_no_move:Nnn,
+% \spath_prepend_no_move:Nn,
+% \spath_gprepend_no_move:Nnn,
+% \spath_gprepend_no_move:Nn,
+% }
+% Prepend the path from the second \Verb+spath+ to the first, removing
+% the adjoining move.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \spath_prepend_no_move:Nnn #1#2#3
+{
+ \spath_append_no_move:Nnn #1{#3}{#2}
+}
+\cs_generate_variant:Nn \spath_prepend_no_move:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_prepend_no_move:Nn #1#2
+{
+ \spath_prepend_no_move:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_prepend_no_move:Nn {NV, cv}
+\cs_new_protected_nopar:Npn \spath_gprepend_no_move:Nnn #1#2#3
+{
+ \spath_gappend_no_move:Nnn #1{#3}{#2}
+}
+\cs_generate_variant:Nn \spath_gprepend_no_move:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_gprepend_no_move:Nn #1#2
+{
+ \spath_gprepend_no_move:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_gprepend_no_move:Nn {NV, cv}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_prepend:Nnn,
+% \spath_prepend:Nn,
+% \spath_gprepend:Nnn,
+% \spath_gprepend:Nn
+% }
+% Prepend the path from the second \Verb+spath+ to the first.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \spath_prepend:Nnn #1#2#3
+{
+ \spath_append:Nnn #1{#3}{#2}
+}
+\cs_generate_variant:Nn \spath_prepend:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_prepend:Nn #1#2
+{
+ \spath_prepend:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_prepend:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gprepend:Nnn #1#2#3
+{
+ \spath_gappend:Nnn #1{#3}{#2}
+}
+\cs_generate_variant:Nn \spath_gprepend:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_gprepend:Nn #1#2
+{
+ \spath_gprepend:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_gprepend:Nn {NV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_bake_round:Nn,
+% \spath_bake_round:N,
+% \spath_gbake_round:Nn,
+% \spath_gbake_round:N
+% }
+%
+% The corner rounding routine is applied quite late in the process of building a soft path so this ensures that it is done.
+%
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_bake_round:n #1
+{
+ \group_begin:
+ \tl_set:Nn \l_@@_tmpa_tl {#1}
+ \pgf@@@@processround \l_@@_tmpa_tl\l_@@_tmpb_tl
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_bake_round:Nn #1#2
+{
+ \@@_bake_round:n {#2}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_bake_round:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_bake_round:N #1
+{
+ \spath_bake_round:NV #1#1
+}
+\cs_generate_variant:Nn \spath_bake_round:N {c}
+\cs_new_protected_nopar:Npn \spath_gbake_round:Nn #1#2
+{
+ \@@_bake_round:n {#2}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gbake_round:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gbake_round:N #1
+{
+ \spath_gbake_round:NV #1#1
+}
+\cs_generate_variant:Nn \spath_gbake_round:N {c}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_close:Nn,
+% \spath_close:N,
+% \spath_gclose:Nn,
+% \spath_gclose:N
+% }
+% Appends a close path to the end of the path.
+% For now, the point is the initial or final point (respectively).
+% To be future proof, it ought to be the point of the adjacent move to.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_close:n #1
+{
+ \group_begin:
+ \tl_set:Nn \l_@@_tmpa_tl {#1}
+ \spath_initialpoint:NV \l_@@_tmpb_tl \l_@@_tmpa_tl
+ \tl_put_right:NV \l_@@_tmpa_tl \c_spath_closepath_tl
+ \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpb_tl
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_close:Nn #1#2
+{
+ \@@_close:n {#2}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_close:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_close:N #1
+{
+ \spath_close:NV #1#1
+}
+\cs_generate_variant:Nn \spath_close:N {c}
+\cs_new_protected_nopar:Npn \spath_gclose:Nn #1#2
+{
+ \@@_close:n {#2}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gclose:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gclose:N #1
+{
+ \spath_gclose:NV #1#1
+}
+\cs_generate_variant:Nn \spath_gclose:N {c}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{
+% \spath_open:Nn,
+% \spath_open:N,
+% \spath_gopen:Nn,
+% \spath_gopen:N
+% }
+% Removes all close paths from the path, replacing them by \Verb+lineto+ if they move any distance.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_open:n #1
+{
+ \group_begin:
+ \tl_set:Nn \l_@@_tmpa_tl {#1}
+ \tl_clear:N \l_@@_tmpb_tl
+ \bool_until_do:nn {
+ \tl_if_empty_p:N \l_@@_tmpa_tl
+ }
+ {
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+
+ \tl_case:NnF \l_@@_tmpc_tl
+ {
+ \c_spath_closepath_tl {
+
+ \bool_if:nF
+ {
+ \dim_compare_p:n
+ {
+ \l_@@_move_x_dim == \l_@@_tmpa_dim
+ }
+ &&
+ \dim_compare_p:n
+ {
+ \l_@@_move_y_dim == \l_@@_tmpb_dim
+ }
+ }
+ {
+ \tl_put_right:NV \l_@@_tmpb_tl \c_spath_lineto_tl
+
+ \tl_put_right:Nx \l_@@_tmpb_tl {
+ { \dim_use:N \l_@@_move_x_dim }
+ { \dim_use:N \l_@@_move_y_dim }
+ }
+ }
+
+ \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ }
+
+ \c_spath_moveto_tl {
+ \tl_put_right:NV \l_@@_tmpb_tl \l_@@_tmpc_tl
+
+ \dim_set:Nn \l_@@_move_x_dim {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \dim_set:Nn \l_@@_move_y_dim {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+
+ \tl_put_right:Nx \l_@@_tmpb_tl {
+ { \dim_use:N \l_@@_move_x_dim }
+ { \dim_use:N \l_@@_move_y_dim }
+ }
+
+ \dim_set_eq:NN \l_@@_tmpa_dim \l_@@_move_x_dim
+ \dim_set_eq:NN \l_@@_tmpb_dim \l_@@_move_y_dim
+ }
+ }
+ {
+ \tl_put_right:NV \l_@@_tmpb_tl \l_@@_tmpc_tl
+
+ \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+
+ \tl_put_right:Nx \l_@@_tmpb_tl {
+ { \dim_use:N \l_@@_tmpa_dim }
+ { \dim_use:N \l_@@_tmpb_dim }
+ }
+ }
+ }
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_open:Nn #1#2
+{
+ \@@_open:n {#2}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_open:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_open:N #1
+{
+ \spath_open:NV #1#1
+}
+\cs_new_protected_nopar:Npn \spath_gopen:Nn #1#2
+{
+ \@@_open:n {#2}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gopen:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gopen:N #1
+{
+ \spath_gopen:NV #1#1
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_remove_empty_components:Nn,
+% \spath_remove_empty_components:N,
+% \spath_gremove_empty_components:Nn,
+% \spath_gremove_empty_components:N
+% }
+% Remove any component that is simply a moveto.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_remove_empty_components:n #1
+{
+ \group_begin:
+ \spath_components_to_seq:Nn \l_@@_tmpa_seq {#1}
+ \tl_clear:N \l_@@_tmpa_tl
+ \seq_map_inline:Nn \l_@@_tmpa_seq
+ {
+ \int_compare:nF
+ {
+ \tl_count:n {##1} == 3
+ }
+ {
+ \tl_put_right:Nn \l_@@_tmpa_tl {##1}
+ }
+ }
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_remove_empty_components:Nn #1#2
+{
+ \@@_remove_empty_components:n {#2}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_remove_empty_components:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_remove_empty_components:N #1
+{
+ \spath_remove_empty_components:NV #1#1
+}
+\cs_generate_variant:Nn \spath_remove_empty_components:N {c}
+\cs_new_protected_nopar:Npn \spath_gremove_empty_components:Nn #1#2
+{
+ \@@_remove_empty_components:n {#2}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gremove_empty_components:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gremove_empty_components:N #1
+{
+ \spath_gremove_empty_components:NV #1#1
+}
+\cs_generate_variant:Nn \spath_gremove_empty_components:N {c}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\spath_if_eq:nn}
+% Test if two soft paths are equal, we allow a little tolerance on the calculations.
+% \begin{macrocode}
+\prg_new_protected_conditional:Npnn \spath_if_eq:nn #1#2 { T, F, TF }
+{
+ \group_begin:
+ \tl_set:Nn \l_@@_tmpa_tl {#1}
+ \tl_set:Nn \l_@@_tmpb_tl {#2}
+ \bool_gset_true:N \g_@@_tmpa_bool
+ \int_compare:nNnTF {\tl_count:N \l_@@_tmpa_tl} = {\tl_count:N \l_@@_tmpb_tl}
+ {
+ \int_step_inline:nnnn {1} {3} {\tl_count:N \l_@@_tmpa_tl}
+ {
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_item:Nn \l_@@_tmpa_tl {##1}}
+ \tl_set:Nx \l_@@_tmpd_tl {\tl_item:Nn \l_@@_tmpb_tl {##1}}
+ \tl_if_eq:NNF \l_@@_tmpc_tl \l_@@_tmpd_tl
+ {
+ \bool_gset_false:N \g_@@_tmpa_bool
+ }
+ \dim_set:Nn \l_@@_tmpa_dim {\tl_item:Nn \l_@@_tmpa_tl {##1+1}}
+ \dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpb_tl {##1+1}}
+ \dim_compare:nF { \dim_abs:n { \l_@@_tmpa_dim - \l_@@_tmpb_dim} < 0.001pt }
+ {
+ \bool_gset_false:N \g_@@_tmpa_bool
+ }
+ \dim_set:Nn \l_@@_tmpa_dim {\tl_item:Nn \l_@@_tmpa_tl {##1+2}}
+ \dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpb_tl {##1+2}}
+ \dim_compare:nF { \dim_abs:n { \l_@@_tmpa_dim - \l_@@_tmpb_dim} < 0.001pt }
+ {
+ \bool_gset_false:N \g_@@_tmpa_bool
+ }
+ }
+ }
+ {
+ \bool_gset_false:N \g_@@_tmpa_bool
+ }
+ \group_end:
+ \bool_if:NTF \g_@@_tmpa_bool
+ {
+ \prg_return_true:
+ }
+ {
+ \prg_return_false:
+ }
+}
+\prg_generate_conditional_variant:Nnn \spath_if_eq:nn {VV, Vn, nV, vv} {TF, T, F}
+% \end{macrocode}
+% \end{macro}
+%
+% \subsection{Splitting Commands}
+%
+% \begin{macro}{
+% \spath_split_curve:NNnn,
+% \spath_gsplit_curve:NNnn
+% }
+% Splits a Bezier cubic into pieces, storing the pieces in the first two arguments.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_split_curve:nn #1#2
+{
+ \group_begin:
+ \tl_set_eq:NN \l_@@_tmpa_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l_@@_tmpa_tl {
+ {\tl_item:nn {#1} {2}}
+ {\tl_item:nn {#1} {3}}
+ }
+ \tl_put_right:NV \l_@@_tmpa_tl \c_spath_curvetoa_tl
+ \tl_put_right:Nx \l_@@_tmpa_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - #2) * \tl_item:nn {#1} {2} + (#2) * \tl_item:nn {#1} {5}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - #2) * \tl_item:nn {#1} {3} + (#2) * \tl_item:nn {#1} {6}
+ }}
+ }
+
+ \tl_put_right:NV \l_@@_tmpa_tl \c_spath_curvetob_tl
+ \tl_put_right:Nx \l_@@_tmpa_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - #2)^2 * \tl_item:nn {#1} {2} + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {5} + (#2)^2 * \tl_item:nn {#1} {8}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - #2)^2 * \tl_item:nn {#1} {3} + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {6} + (#2)^2 * \tl_item:nn {#1} {9}
+ }}
+ }
+
+ \tl_put_right:NV \l_@@_tmpa_tl \c_spath_curveto_tl
+ \tl_put_right:Nx \l_@@_tmpa_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - #2)^3 * \tl_item:nn {#1} {2} + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {5} + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {8} + (#2)^3 * \tl_item:nn {#1} {11}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - #2)^3 * \tl_item:nn {#1} {3} + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {6} + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {9} + (#2)^3 * \tl_item:nn {#1} {12}
+ }}
+ }
+
+ \tl_gclear:N \g_@@_output_tl
+ \@@_tl_gput_right_braced:NV \g_@@_output_tl \l_@@_tmpa_tl
+
+ \tl_clear:N \l_@@_tmpa_tl
+ \tl_set_eq:NN \l_@@_tmpa_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l_@@_tmpa_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - #2)^3 * \tl_item:nn {#1} {2} + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {5} + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {8} + (#2)^3 * \tl_item:nn {#1} {11}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - #2)^3 * \tl_item:nn {#1} {3} + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {6} + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {9} + (#2)^3 * \tl_item:nn {#1} {12}
+ }}
+ }
+
+ \tl_put_right:NV \l_@@_tmpa_tl \c_spath_curvetoa_tl
+ \tl_put_right:Nx \l_@@_tmpa_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - #2)^2 * \tl_item:nn {#1} {5} + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {8} + (#2)^2 * \tl_item:nn {#1} {11}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - #2)^2 * \tl_item:nn {#1} {6} + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {9} + (#2)^2 * \tl_item:nn {#1} {12}
+ }}
+ }
+ \tl_put_right:NV \l_@@_tmpa_tl \c_spath_curvetob_tl
+ \tl_put_right:Nx \l_@@_tmpa_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - #2) * \tl_item:nn {#1} {8} + (#2) * \tl_item:nn {#1} {11}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - #2) * \tl_item:nn {#1} {9} + (#2) * \tl_item:nn {#1} {12}
+ }}
+ }
+ \tl_put_right:NV \l_@@_tmpa_tl \c_spath_curveto_tl
+ \tl_put_right:Nx \l_@@_tmpa_tl {
+ {\tl_item:nn {#1} {11}}
+ {\tl_item:nn {#1} {12}}
+ }
+
+ \@@_tl_gput_right_braced:NV \g_@@_output_tl \l_@@_tmpa_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_split_curve:NNnn #1#2#3#4
+{
+ \@@_split_curve:nn {#3}{#4}
+ \tl_set:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
+ \tl_set:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_split_curve:NNnn {NNnV, NNVn, NNVV}
+\cs_new_protected_nopar:Npn \spath_gsplit_curve:NNnn #1#2#3#4
+{
+ \@@_split_curve:nn {#3}{#4}
+ \tl_gset:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
+ \tl_gset:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gsplit_curve:NNnn {NNnV, NNVn, NNVV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_split_line:NNnn,
+% \spath_gsplit_line:NNnn
+% }
+% Splits a line segment.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_split_line:nn #1#2
+{
+ \group_begin:
+ \tl_set_eq:NN \l_@@_tmpa_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l_@@_tmpa_tl {
+ {\tl_item:nn {#1} {2}}
+ {\tl_item:nn {#1} {3}}
+ }
+ \tl_put_right:NV \l_@@_tmpa_tl \c_spath_lineto_tl
+ \tl_put_right:Nx \l_@@_tmpa_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - #2) * \tl_item:nn {#1} {2} + (#2) * \tl_item:nn {#1} {5}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - #2) * \tl_item:nn {#1} {3} + (#2) * \tl_item:nn {#1} {6}
+ }}
+ }
+ \tl_gclear:N \g_@@_output_tl
+ \@@_tl_gput_right_braced:NV \g_@@_output_tl \l_@@_tmpa_tl
+
+ \tl_clear:N \l_@@_tmpa_tl
+ \tl_set_eq:NN \l_@@_tmpa_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l_@@_tmpa_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - #2) * \tl_item:nn {#1} {2} + (#2) * \tl_item:nn {#1} {5}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - #2) * \tl_item:nn {#1} {3} + (#2) * \tl_item:nn {#1} {6}
+ }}
+ }
+ \tl_put_right:NV \l_@@_tmpa_tl \c_spath_lineto_tl
+ \tl_put_right:Nx \l_@@_tmpa_tl {
+ {\tl_item:nn {#1} {5}}
+ {\tl_item:nn {#1} {6}}
+ }
+
+ \@@_tl_gput_right_braced:NV \g_@@_output_tl \l_@@_tmpa_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_split_line:NNnn #1#2#3#4
+{
+ \@@_split_line:nn {#3}{#4}
+ \tl_set:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
+ \tl_set:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_split_line:NNnn {NNnV, NNVn, NNVV}
+\cs_new_protected_nopar:Npn \spath_gsplit_line:NNnn #1#2#3#4
+{
+ \@@_split_line:nn {#3}{#4}
+ \tl_gset:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
+ \tl_gset:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gsplit_line:NNnn {NNnV, NNVn, NNVV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macrocode}
+\int_new:N \l_@@_split_int
+\int_new:N \l_@@_splitat_int
+\fp_new:N \l_@@_split_fp
+\bool_new:N \l_@@_split_bool
+\tl_new:N \l_@@_split_path_tl
+\tl_new:N \l_@@_split_patha_tl
+\tl_new:N \l_@@_split_pathb_tl
+\tl_new:N \l_@@_split_intoa_tl
+\tl_new:N \l_@@_split_intob_tl
+\dim_new:N \l_@@_splitx_dim
+\dim_new:N \l_@@_splity_dim
+% \end{macrocode}
+%
+% \begin{macro}{
+% \spath_split_at:NNnn,
+% \spath_split_at:Nnn,
+% \spath_split_at:Nn,
+% \spath_gsplit_at:NNnn
+% \spath_gsplit_at:Nnn,
+% \spath_gsplit_at:Nn
+% }
+% Split a path according to the parameter generated by the intersection routine.
+% The versions with two \texttt{N} arguments stores the two parts in two macros, the version with a single \texttt{N} joins them back into a single path (as separate components).
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_split_at:nn #1#2
+{
+ \group_begin:
+ \int_set:Nn \l_@@_splitat_int {\fp_to_int:n {floor(#2) + 1}}
+ \fp_set:Nn \l_@@_split_fp {#2 - floor(#2)}
+
+ % Is split point near one end or other of a component?
+ \fp_compare:nT
+ {
+ \l_@@_split_fp < 0.01
+ }
+ {
+ % Near the start, so we'll place it at the start
+ \fp_set:Nn \l_@@_split_fp {0}
+ }
+ \fp_compare:nT
+ {
+ \l_@@_split_fp > 0.99
+ }
+ {
+ % Near the end, so we'll place it at the end
+ \fp_set:Nn \l_@@_split_fp {0}
+ \int_incr:N \l_@@_splitat_int
+ }
+
+ \int_zero:N \l_@@_split_int
+ \bool_set_true:N \l_@@_split_bool
+
+ \tl_set:Nn \l_@@_split_path_tl {#1}
+ \tl_clear:N \l_@@_split_patha_tl
+
+ \dim_zero:N \l_@@_splitx_dim
+ \dim_zero:N \l_@@_splity_dim
+
+ \bool_until_do:nn {
+ \tl_if_empty_p:N \l_@@_split_path_tl
+ ||
+ \int_compare_p:n { \l_@@_splitat_int == \l_@@_split_int }
+ }
+ {
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_split_path_tl}
+ \tl_set:Nx \l_@@_split_path_tl {\tl_tail:N \l_@@_split_path_tl }
+ \tl_case:Nn \l_@@_tmpc_tl
+ {
+ \c_spath_lineto_tl
+ {
+ \int_incr:N \l_@@_split_int
+ }
+ \c_spath_curvetoa_tl
+ {
+ \int_incr:N \l_@@_split_int
+ }
+ }
+ \int_compare:nT { \l_@@_split_int < \l_@@_splitat_int }
+ {
+ \tl_put_right:NV \l_@@_split_patha_tl \l_@@_tmpc_tl
+
+ \tl_put_right:Nx \l_@@_split_patha_tl
+ {{ \tl_head:N \l_@@_split_path_tl }}
+ \dim_set:Nn \l_@@_splitx_dim {\tl_head:N \l_@@_split_path_tl}
+ \tl_set:Nx \l_@@_split_path_tl {\tl_tail:N \l_@@_split_path_tl }
+
+ \tl_put_right:Nx \l_@@_split_patha_tl
+ {{ \tl_head:N \l_@@_split_path_tl }}
+ \dim_set:Nn \l_@@_splity_dim {\tl_head:N \l_@@_split_path_tl}
+ \tl_set:Nx \l_@@_split_path_tl {\tl_tail:N \l_@@_split_path_tl }
+
+ }
+ }
+
+ \tl_clear:N \l_@@_split_pathb_tl
+ \tl_put_right:NV \l_@@_split_pathb_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l_@@_split_pathb_tl
+ {
+ {\dim_use:N \l_@@_splitx_dim}
+ {\dim_use:N \l_@@_splity_dim}
+ }
+
+ \fp_compare:nTF
+ {
+ \l_@@_split_fp == 0
+ }
+ {
+ \tl_set_eq:NN \l_@@_split_intob_tl \l_@@_split_pathb_tl
+ \tl_if_empty:NF \l_@@_split_path_tl
+ {
+ \tl_put_right:NV \l_@@_split_intob_tl \l_@@_tmpc_tl
+ \tl_put_right:NV \l_@@_split_intob_tl \l_@@_split_path_tl
+ }
+ }
+ {
+
+ \tl_case:Nn \l_@@_tmpc_tl
+ {
+ \c_spath_lineto_tl
+ {
+ \tl_put_right:NV \l_@@_split_pathb_tl \l_@@_tmpc_tl
+ \tl_put_right:Nx \l_@@_split_pathb_tl
+ {{ \tl_head:N \l_@@_split_path_tl }}
+ \tl_set:Nx \l_@@_split_path_tl {\tl_tail:N \l_@@_split_path_tl }
+
+ \tl_put_right:Nx \l_@@_split_pathb_tl
+ {{ \tl_head:N \l_@@_split_path_tl }}
+ \tl_set:Nx \l_@@_split_path_tl {\tl_tail:N \l_@@_split_path_tl }
+
+ \spath_split_line:NNVV
+ \l_@@_split_intoa_tl
+ \l_@@_split_intob_tl
+ \l_@@_split_pathb_tl
+ \l_@@_split_fp
+
+ \prg_replicate:nn {3} {
+ \tl_set:Nx \l_@@_split_intoa_tl {\tl_tail:N \l_@@_split_intoa_tl}
+ }
+
+ \tl_put_right:NV \l_@@_split_patha_tl \l_@@_split_intoa_tl
+ \tl_put_right:NV \l_@@_split_intob_tl \l_@@_split_path_tl
+ }
+ \c_spath_curvetoa_tl
+ {
+ \tl_put_right:NV \l_@@_split_pathb_tl \l_@@_tmpc_tl
+ \tl_put_right:Nx \l_@@_split_pathb_tl
+ {{ \tl_head:N \l_@@_split_path_tl }}
+ \tl_set:Nx \l_@@_split_path_tl {\tl_tail:N \l_@@_split_path_tl }
+
+ \tl_put_right:Nx \l_@@_split_pathb_tl
+ {{ \tl_head:N \l_@@_split_path_tl }}
+ \tl_set:Nx \l_@@_split_path_tl {\tl_tail:N \l_@@_split_path_tl }
+
+ \prg_replicate:nn {2} {
+
+ \tl_put_right:Nx \l_@@_split_pathb_tl
+ { \tl_head:N \l_@@_split_path_tl }
+ \tl_set:Nx \l_@@_split_path_tl {\tl_tail:N \l_@@_split_path_tl }
+
+ \tl_put_right:Nx \l_@@_split_pathb_tl
+ {{ \tl_head:N \l_@@_split_path_tl }}
+ \tl_set:Nx \l_@@_split_path_tl {\tl_tail:N \l_@@_split_path_tl }
+
+ \tl_put_right:Nx \l_@@_split_pathb_tl
+ {{ \tl_head:N \l_@@_split_path_tl }}
+ \tl_set:Nx \l_@@_split_path_tl {\tl_tail:N \l_@@_split_path_tl }
+ }
+
+ \spath_split_curve:NNVV
+ \l_@@_split_intoa_tl
+ \l_@@_split_intob_tl
+ \l_@@_split_pathb_tl \l_@@_split_fp
+
+ \prg_replicate:nn {3} {
+ \tl_set:Nx \l_@@_split_intoa_tl {\tl_tail:N \l_@@_split_intoa_tl}
+ }
+
+ \tl_put_right:NV \l_@@_split_patha_tl \l_@@_split_intoa_tl
+ \tl_put_right:NV \l_@@_split_intob_tl \l_@@_split_path_tl
+ }
+ }
+ }
+
+ \tl_gclear:N \g_@@_output_tl
+ \@@_tl_gput_right_braced:NV \g_@@_output_tl \l_@@_split_patha_tl
+ \@@_tl_gput_right_braced:NV \g_@@_output_tl \l_@@_split_intob_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_split_at:NNnn #1#2#3#4
+{
+ \@@_split_at:nn {#3}{#4}
+ \tl_set:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
+ \tl_set:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_split_at:NNnn {NNVn, NNVV, NNnV}
+\cs_new_protected_nopar:Npn \spath_gsplit_at:NNnn #1#2#3#4
+{
+ \@@_split_at:nn {#3}{#4}
+ \tl_gset:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
+ \tl_gset:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gsplit_at:NNnn {NNVn, NNVV, NNnV}
+% \end{macrocode}
+%
+%
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \spath_split_at:Nnn #1#2#3
+{
+ \@@_split_at:nn {#2}{#3}
+ \tl_set:Nx #1 {\tl_item:Nn \g_@@_output_tl {1} \tl_item:Nn \g_@@_output_tl {2}}
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_split_at:Nnn {NVn, NVV}
+\cs_new_protected_nopar:Npn \spath_split_at:Nn #1#2
+{
+ \spath_split_at:NVn #1#1{#2}
+}
+\cs_new_protected_nopar:Npn \spath_gsplit_at:Nnn #1#2#3
+{
+ \@@_split_at:nn {#2}{#3}
+ \tl_gset:Nx #1 {\tl_item:Nn \g_@@_output_tl {1} \tl_item:Nn \g_@@_output_tl {2}}
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gsplit_at:Nnn {NVn, NVV}
+\cs_new_protected_nopar:Npn \spath_gsplit_at:Nn #1#2
+{
+ \spath_gsplit_at:NVn #1#1{#2}
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \subsection{Shortening Paths}
+%
+% This code relates to shortening paths.
+% For curved paths, the routine uses the derivative at the end to figure out how far back to shorten.
+% This means that the actual length that it shortens by is approximate, but it is guaranteed to be along its length.
+%
+% As in the previous section, there are various versions.
+% In particular, there are versions where the path can be specified by a macro and is saved back into that macro.
+%
+% \begin{macrocode}
+\tl_new:N \l_@@_shorten_fa_tl
+\tl_new:N \l_@@_shorten_path_tl
+\tl_new:N \l_@@_shorten_last_tl
+\tl_new:N \l_@@_shorten_lasta_tl
+\tl_new:N \l_@@_shorten_lastb_tl
+\int_new:N \l_@@_shorten_int
+\fp_new:N \l_@@_shorten_x_fp
+\fp_new:N \l_@@_shorten_y_fp
+\fp_new:N \l_@@_shorten_len_fp
+% \end{macrocode}
+%
+% \begin{macro}{
+% \spath_shorten_at_end:Nnn
+% }
+% This macro shortens a path from the end by a dimension.
+%
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_shorten_at_end:nn #1#2
+{
+ \int_compare:nTF
+ {
+ \tl_count:n {#1} > 3
+ }
+ {
+ \group_begin:
+ \tl_set:Nn \l_@@_shorten_path_tl {#1}
+ \tl_reverse:N \l_@@_shorten_path_tl
+
+ \tl_set:Nx \l_@@_shorten_fa_tl {\tl_item:Nn \l_@@_shorten_path_tl {3}}
+
+ \tl_clear:N \l_@@_shorten_last_tl
+ \tl_if_eq:NNTF \l_@@_shorten_fa_tl \c_spath_curveto_tl
+ {
+ \int_set:Nn \l_@@_shorten_int {3}
+ }
+ {
+ \int_set:Nn \l_@@_shorten_int {1}
+ }
+
+ \prg_replicate:nn { \l_@@_shorten_int }
+ {
+ \tl_put_right:Nx \l_@@_shorten_last_tl
+ {
+ {\tl_head:N \l_@@_shorten_path_tl}
+ }
+ \tl_set:Nx \l_@@_shorten_path_tl {\tl_tail:N \l_@@_shorten_path_tl}
+ \tl_put_right:Nx \l_@@_shorten_last_tl
+ {
+ {\tl_head:N \l_@@_shorten_path_tl}
+ }
+ \tl_set:Nx \l_@@_shorten_path_tl {\tl_tail:N \l_@@_shorten_path_tl}
+ \tl_put_right:Nx \l_@@_shorten_last_tl
+ {
+ \tl_head:N \l_@@_shorten_path_tl
+ }
+ \tl_set:Nx \l_@@_shorten_path_tl {\tl_tail:N \l_@@_shorten_path_tl}
+ }
+
+ \tl_put_right:Nx \l_@@_shorten_last_tl
+ {
+ {\tl_item:Nn \l_@@_shorten_path_tl {1}}
+ {\tl_item:Nn \l_@@_shorten_path_tl {2}}
+ }
+ \tl_put_right:NV \l_@@_shorten_last_tl \c_spath_moveto_tl
+
+ \tl_reverse:N \l_@@_shorten_path_tl
+
+ \fp_set:Nn \l_@@_shorten_x_fp
+ {
+ \dim_to_fp:n {\tl_item:Nn \l_@@_shorten_last_tl {4}}
+ -
+ \dim_to_fp:n {\tl_item:Nn \l_@@_shorten_last_tl {1}}
+ }
+
+ \fp_set:Nn \l_@@_shorten_y_fp
+ {
+ \dim_to_fp:n {\tl_item:Nn \l_@@_shorten_last_tl {5}}
+ -
+ \dim_to_fp:n {\tl_item:Nn \l_@@_shorten_last_tl {2}}
+ }
+
+ \fp_set:Nn \l_@@_shorten_len_fp
+ {
+ sqrt( \l_@@_shorten_x_fp * \l_@@_shorten_x_fp + \l_@@_shorten_y_fp * \l_@@_shorten_y_fp )
+ }
+
+ \fp_compare:nTF
+ {
+ \l_@@_shorten_len_fp > #2
+ }
+ {
+
+ \fp_set:Nn \l_@@_shorten_len_fp
+ {
+ (\l_@@_shorten_len_fp - #2)/ \l_@@_shorten_len_fp
+ }
+
+ \tl_reverse:N \l_@@_shorten_last_tl
+
+ \tl_if_eq:NNTF \l_@@_shorten_fa_tl \c_spath_curveto_tl
+ {
+ \fp_set:Nn \l_@@_shorten_len_fp
+ {
+ 1 - (1 -\l_@@_shorten_len_fp)/3
+ }
+ \spath_split_curve:NNVV
+ \l_@@_shorten_lasta_tl
+ \l_@@_shorten_lastb_tl
+ \l_@@_shorten_last_tl
+ \l_@@_shorten_len_fp
+ }
+ {
+ \spath_split_line:NNVV
+ \l_@@_shorten_lasta_tl
+ \l_@@_shorten_lastb_tl
+ \l_@@_shorten_last_tl
+ \l_@@_shorten_len_fp
+ }
+
+ \prg_replicate:nn {3}
+ {
+ \tl_set:Nx \l_@@_shorten_lasta_tl {\tl_tail:N \l_@@_shorten_lasta_tl}
+ }
+
+ \tl_put_right:NV \l_@@_shorten_path_tl \l_@@_shorten_lasta_tl
+
+ }
+ {
+
+ \int_compare:nT
+ {
+ \tl_count:N \l_@@_shorten_path_tl > 3
+ }
+ {
+ \dim_set:Nn \l_@@_tmpa_dim {\fp_to_dim:n {#2 - \l_@@_shorten_len_fp } }
+ \spath_shorten_at_end:NV \l_@@_shorten_path_tl \l_@@_tmpa_dim
+ }
+ }
+
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_shorten_path_tl
+ \group_end:
+ }
+ {
+ \tl_gset:Nn \g_@@_output_tl {#1}
+ }
+}
+\cs_new_protected_nopar:Npn \spath_shorten_at_end:Nnn #1#2#3
+{
+ \@@_shorten_at_end:nn {#2}{#3}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_shorten_at_end:Nnn {NVV, cnn, cVV, NVn}
+\cs_new_protected_nopar:Npn \spath_shorten_at_end:Nn #1#2
+{
+ \spath_shorten_at_end:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_shorten_at_end:Nn {cn, cV, NV}
+\cs_new_protected_nopar:Npn \spath_gshorten_at_end:Nnn #1#2#3
+{
+ \@@_shorten_at_end:nn {#2}{#3}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gshorten_at_end:Nnn {NVV, cnn, cVV, NVn}
+\cs_new_protected_nopar:Npn \spath_gshorten_at_end:Nn #1#2
+{
+ \spath_gshorten_at_end:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_gshorten_at_end:Nn {cn, cV, NV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_shorten_at_start:Nnn,
+% \spath_shorten_at_start:Nn,
+% \spath_gshorten_at_start:Nnn,
+% \spath_gshorten_at_start:Nn
+% }
+%
+% This macro shortens a path from the start by a dimension.
+%
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_shorten_at_start:nn #1#2
+{
+ \int_compare:nTF
+ {
+ \tl_count:n {#1} > 3
+ }
+ {
+ \group_begin:
+ \tl_set:Nn \l_@@_shorten_path_tl {#1}
+
+ \tl_set:Nx \l_@@_shorten_fa_tl {\tl_item:Nn \l_@@_shorten_path_tl {4}}
+
+ \tl_clear:N \l_@@_shorten_last_tl
+
+ \tl_if_eq:NNTF \l_@@_shorten_fa_tl \c_spath_curvetoa_tl
+ {
+ \int_set:Nn \l_@@_shorten_int {3}
+ }
+ {
+ \int_set:Nn \l_@@_shorten_int {1}
+ }
+
+ \tl_set_eq:NN \l_@@_shorten_last_tl \c_spath_moveto_tl
+ \tl_set:Nx \l_@@_shorten_path_tl {\tl_tail:N \l_@@_shorten_path_tl }
+
+ \prg_replicate:nn { \l_@@_shorten_int }
+ {
+ \@@_tl_put_right_braced:Nx \l_@@_shorten_last_tl {\tl_item:Nn \l_@@_shorten_path_tl {1}}
+ \@@_tl_put_right_braced:Nx \l_@@_shorten_last_tl {\tl_item:Nn \l_@@_shorten_path_tl {2}}
+ \tl_put_right:Nx \l_@@_shorten_last_tl {\tl_item:Nn \l_@@_shorten_path_tl {3}}
+
+ \prg_replicate:nn {3}
+ {
+ \tl_set:Nx \l_@@_shorten_path_tl {\tl_tail:N \l_@@_shorten_path_tl }
+ }
+ }
+ \@@_tl_put_right_braced:Nx \l_@@_shorten_last_tl {\tl_item:Nn \l_@@_shorten_path_tl {1}}
+ \@@_tl_put_right_braced:Nx \l_@@_shorten_last_tl {\tl_item:Nn \l_@@_shorten_path_tl {2}}
+
+ \fp_set:Nn \l_@@_shorten_x_fp
+ {
+ \dim_to_fp:n {\tl_item:Nn \l_@@_shorten_last_tl {5}}
+ -
+ \dim_to_fp:n {\tl_item:Nn \l_@@_shorten_last_tl {2}}
+ }
+
+ \fp_set:Nn \l_@@_shorten_y_fp
+ {
+ \dim_to_fp:n {\tl_item:Nn \l_@@_shorten_last_tl {6}}
+ -
+ \dim_to_fp:n {\tl_item:Nn \l_@@_shorten_last_tl {3}}
+ }
+
+ \fp_set:Nn \l_@@_shorten_len_fp
+ {
+ sqrt( \l_@@_shorten_x_fp * \l_@@_shorten_x_fp + \l_@@_shorten_y_fp * \l_@@_shorten_y_fp )
+ }
+
+ \fp_compare:nTF
+ {
+ \l_@@_shorten_len_fp > #2
+ }
+ {
+
+ \fp_set:Nn \l_@@_shorten_len_fp
+ {
+ #2/ \l_@@_shorten_len_fp
+ }
+
+ \tl_if_eq:NNTF \l_@@_shorten_fa_tl \c_spath_curvetoa_tl
+ {
+ \fp_set:Nn \l_@@_shorten_len_fp
+ {
+ \l_@@_shorten_len_fp/3
+ }
+ \spath_split_curve:NNVV
+ \l_@@_shorten_lasta_tl
+ \l_@@_shorten_lastb_tl
+ \l_@@_shorten_last_tl
+ \l_@@_shorten_len_fp
+ }
+ {
+ \spath_split_line:NNVV
+ \l_@@_shorten_lasta_tl
+ \l_@@_shorten_lastb_tl
+ \l_@@_shorten_last_tl
+ \l_@@_shorten_len_fp
+ }
+
+ \prg_replicate:nn {2}
+ {
+ \tl_set:Nx \l_@@_shorten_path_tl {\tl_tail:N \l_@@_shorten_path_tl}
+ }
+
+ \tl_put_left:NV \l_@@_shorten_path_tl \l_@@_shorten_lastb_tl
+
+ }
+ {
+
+ \tl_put_left:NV \l_@@_shorten_path_tl \c_spath_moveto_tl
+
+ \int_compare:nT
+ {
+ \tl_count:N \l_@@_shorten_path_tl > 3
+ }
+ {
+ \dim_set:Nn \l_@@_tmpa_dim {\fp_to_dim:n {#2 - \l_@@_shorten_len_fp } }
+ \spath_shorten_at_start:NV \l_@@_shorten_path_tl \l_@@_tmpa_dim
+ }
+ }
+
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_shorten_path_tl
+ \group_end:
+ }
+ {
+ \tl_gset:Nn \g_@@_output_tl {#1}
+ }
+}
+\cs_new_protected_nopar:Npn \spath_shorten_at_start:Nnn #1#2#3
+{
+ \@@_shorten_at_start:nn {#2}{#3}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_shorten_at_start:Nnn {NVV, cnn, cVV, NVn}
+\cs_new_protected_nopar:Npn \spath_shorten_at_start:Nn #1#2
+{
+ \spath_shorten_at_start:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_shorten_at_start:Nn {cn, cV, NV}
+\cs_new_protected_nopar:Npn \spath_gshorten_at_start:Nnn #1#2#3
+{
+ \@@_shorten_at_start:nn {#2}{#3}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gshorten_at_start:Nnn {NVV, cnn, cVV, NVn}
+\cs_new_protected_nopar:Npn \spath_gshorten_at_start:Nn #1#2
+{
+ \spath_gshorten_at_start:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_gshorten_at_start:Nn {cn, cV, NV}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \subsection{Points on a Path}
+%
+% \begin{macro}{
+% \spath_point_at:Nnn,
+% \spath_gpoint_at:Nnn,
+% }
+%
+% Get the location of a point on a path, using the same location specification as the intersection library.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_point_at:nn #1#2
+{
+ \group_begin:
+ \int_set:Nn \l_@@_tmpa_int {\fp_to_int:n {floor(#2) + 1}}
+ \fp_set:Nn \l_@@_tmpa_fp {#2 - floor(#2)}
+
+ \spath_segments_to_seq:Nn \l_@@_tmpa_seq {#1}
+
+ \int_compare:nTF
+ {
+ \l_@@_tmpa_int < 1
+ }
+ {
+ \spath_initialpoint:Nn \l_@@_tmpc_tl {#1}
+ }
+ {
+ \int_compare:nTF
+ {
+ \l_@@_tmpa_int > \seq_count:N \l_@@_tmpa_seq
+ }
+ {
+ \spath_finalpoint:Nn \l_@@_tmpc_tl {#1}
+ }
+ {
+
+ \tl_set:Nx \l_@@_tmpa_tl {\seq_item:Nn \l_@@_tmpa_seq { \l_@@_tmpa_int} }
+
+ \int_compare:nTF
+ {
+ \tl_count:N \l_@@_tmpa_tl > 3
+ }
+ {
+ \tl_set:Nx \l_@@_tmpb_tl {\tl_item:Nn \l_@@_tmpa_tl {4}}
+ }
+ {
+ \tl_set:Nx \l_@@_tmpb_tl {\tl_item:Nn \l_@@_tmpa_tl {1}}
+ }
+
+ \tl_clear:N \l_@@_tmpc_tl
+
+ \tl_case:Nn \l_@@_tmpb_tl
+ {
+ \c_spath_moveto_tl
+ {
+ \tl_set:Nx \l_@@_tmpc_tl
+ {
+ {
+ \tl_item:Nn \l_@@_tmpa_tl {2}
+ }
+ {
+ \tl_item:Nn \l_@@_tmpa_tl {3}
+ }
+ }
+ }
+
+ \c_spath_lineto_tl
+ {
+ \tl_set:Nx \l_@@_tmpc_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - \l_@@_tmpa_fp) * ( \tl_item:Nn \l_@@_tmpa_tl {2} )
+ +
+ \l_@@_tmpa_fp * ( \tl_item:Nn \l_@@_tmpa_tl {5} )
+ }
+ }
+ {\fp_to_dim:n
+ {
+ (1 - \l_@@_tmpa_fp) * ( \tl_item:Nn \l_@@_tmpa_tl {3} )
+ +
+ \l_@@_tmpa_fp * ( \tl_item:Nn \l_@@_tmpa_tl {6} )
+ }
+ }
+ }
+ }
+
+ \c_spath_closepath_tl
+ {
+ \tl_set:Nx \l_@@_tmpc_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - \l_@@_tmpa_fp) * ( \tl_item:Nn \l_@@_tmpa_tl {2} )
+ +
+ \l_@@_tmpa_fp * ( \tl_item:Nn \l_@@_tmpa_tl {5} )
+ }
+ }
+ {\fp_to_dim:n
+ {
+ (1 - \l_@@_tmpa_fp) * ( \tl_item:Nn \l_@@_tmpa_tl {3} )
+ +
+ \l_@@_tmpa_fp * ( \tl_item:Nn \l_@@_tmpa_tl {6} )
+ }
+ }
+ }
+ }
+
+ \c_spath_curvetoa_tl
+ {
+ \tl_set:Nx \l_@@_tmpc_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - \l_@@_tmpa_fp)^3 * \tl_item:Nn \l_@@_tmpa_tl {2} + 3 * (1 - \l_@@_tmpa_fp)^2 * (\l_@@_tmpa_fp) * \tl_item:Nn \l_@@_tmpa_tl {5} + 3 * (1 - \l_@@_tmpa_fp) * (\l_@@_tmpa_fp)^2 * \tl_item:Nn \l_@@_tmpa_tl {8} + (\l_@@_tmpa_fp)^3 * \tl_item:Nn \l_@@_tmpa_tl {11}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - \l_@@_tmpa_fp)^3 * \tl_item:Nn \l_@@_tmpa_tl {3} + 3 * (1 - \l_@@_tmpa_fp)^2 * (\l_@@_tmpa_fp) * \tl_item:Nn \l_@@_tmpa_tl {6} + 3 * (1 - \l_@@_tmpa_fp) * (\l_@@_tmpa_fp)^2 * \tl_item:Nn \l_@@_tmpa_tl {9} + (\l_@@_tmpa_fp)^3 * \tl_item:Nn \l_@@_tmpa_tl {12}
+ }}
+ }
+ }
+ }
+ }
+ }
+
+ \tl_gclear:N \g_@@_output_tl
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpc_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_point_at:Nnn #1#2#3
+{
+ \@@_point_at:nn {#2}{#3}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_point_at:Nnn {NVn, NVV, NnV}
+\cs_new_protected_nopar:Npn \spath_gpoint_at:Nnn #1#2#3
+{
+ \@@_point_at:nn {#2}{#3}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gpoint_at:Nnn {NVn, NVV, NnV}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{
+% \spath_tangent_at:Nnn,
+% \spath_gtangent_at:Nnn,
+% }
+%
+% Get the tangent at a point on a path, using the same location specification as the intersection library.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_tangent_at:nn #1#2
+{
+ \group_begin:
+ \int_set:Nn \l_@@_tmpa_int {\fp_to_int:n {floor(#2) + 1}}
+ \fp_set:Nn \l_@@_tmpa_fp {#2 - floor(#2)}
+
+ \spath_segments_to_seq:Nn \l_@@_tmpa_seq {#1}
+
+ \int_compare:nTF
+ {
+ \l_@@_tmpa_int < 1
+ }
+ {
+ \spath_initialpoint:Nn \l_@@_tmpc_tl {#1}
+ }
+ {
+ \int_compare:nTF
+ {
+ \l_@@_tmpa_int > \seq_count:N \l_@@_tmpa_seq
+ }
+ {
+ \spath_finalpoint:Nn \l_@@_tmpc_tl {#1}
+ }
+ {
+
+ \tl_set:Nx \l_@@_tmpa_tl {\seq_item:Nn \l_@@_tmpa_seq { \l_@@_tmpa_int} }
+
+ \int_compare:nTF
+ {
+ \tl_count:N \l_@@_tmpa_tl > 3
+ }
+ {
+ \tl_set:Nx \l_@@_tmpb_tl {\tl_item:Nn \l_@@_tmpa_tl {4}}
+ }
+ {
+ \tl_set:Nx \l_@@_tmpb_tl {\tl_item:Nn \l_@@_tmpa_tl {1}}
+ }
+
+ \tl_clear:N \l_@@_tmpc_tl
+
+ \tl_case:Nn \l_@@_tmpb_tl
+ {
+ \c_spath_moveto_tl
+ {
+ \tl_set:Nx \l_@@_tmpc_tl
+ {
+ {
+ \tl_item:Nn \l_@@_tmpa_tl {2}
+ }
+ {
+ \tl_item:Nn \l_@@_tmpa_tl {3}
+ }
+ }
+ }
+
+ \c_spath_lineto_tl
+ {
+ \tl_set:Nx \l_@@_tmpc_tl
+ {
+ {\fp_to_dim:n
+ {
+ ( \tl_item:Nn \l_@@_tmpa_tl {5} )
+ -
+ ( \tl_item:Nn \l_@@_tmpa_tl {2} )
+ }
+ }
+ {\fp_to_dim:n
+ {
+ ( \tl_item:Nn \l_@@_tmpa_tl {6} )
+ -
+ ( \tl_item:Nn \l_@@_tmpa_tl {3} )
+ }
+ }
+ }
+ }
+
+ \c_spath_closepath_tl
+ {
+ \tl_set:Nx \l_@@_tmpc_tl
+ {
+ {\fp_to_dim:n
+ {
+ ( \tl_item:Nn \l_@@_tmpa_tl {5} )
+ -
+ ( \tl_item:Nn \l_@@_tmpa_tl {2} )
+ }
+ }
+ {\fp_to_dim:n
+ {
+ ( \tl_item:Nn \l_@@_tmpa_tl {6} )
+ -
+ ( \tl_item:Nn \l_@@_tmpa_tl {3} )
+ }
+ }
+ }
+ }
+
+ \c_spath_curvetoa_tl
+ {
+ \tl_set:Nx \l_@@_tmpc_tl
+ {
+ {\fp_to_dim:n
+ {
+ 3*(1 - \l_@@_tmpa_fp)^2 * (\tl_item:Nn \l_@@_tmpa_tl {5} - \tl_item:Nn \l_@@_tmpa_tl {2})
+ + 6 * (1 - \l_@@_tmpa_fp) * (\l_@@_tmpa_fp) * (\tl_item:Nn \l_@@_tmpa_tl {8} - \tl_item:Nn \l_@@_tmpa_tl {5})
+ + 3*(\l_@@_tmpa_fp)^2 * (\tl_item:Nn \l_@@_tmpa_tl {11} - \tl_item:Nn \l_@@_tmpa_tl {8})
+ }
+ }
+ {\fp_to_dim:n
+ {
+ 3*(1 - \l_@@_tmpa_fp)^2 * (\tl_item:Nn \l_@@_tmpa_tl {6} - \tl_item:Nn \l_@@_tmpa_tl {3})
+ + 6 * (1 - \l_@@_tmpa_fp) * (\l_@@_tmpa_fp) * (\tl_item:Nn \l_@@_tmpa_tl {9} - \tl_item:Nn \l_@@_tmpa_tl {6})
+ + 3*(\l_@@_tmpa_fp)^2 * (\tl_item:Nn \l_@@_tmpa_tl {12} - \tl_item:Nn \l_@@_tmpa_tl {9})
+ }}
+ }
+ }
+ }
+ }
+ }
+
+ \tl_gclear:N \g_@@_output_tl
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpc_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_tangent_at:Nnn #1#2#3
+{
+ \@@_tangent_at:nn {#2}{#3}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_tangent_at:Nnn {NVn, NVV, NnV}
+\cs_new_protected_nopar:Npn \spath_gtangent_at:Nnn #1#2#3
+{
+ \@@_tangent_at:nn {#2}{#3}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gtangent_at:Nnn {NVn, NVV, NnV}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{
+% \spath_transformation_at:Nnn,
+% \spath_gtransformation_at:Nnn
+% }
+% Gets a transformation that will align to a point on the path with the x-axis along the path.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_transformation_at:nn #1#2
+{
+ \group_begin:
+ \tl_clear:N \l_@@_tmpa_tl
+ \@@_tangent_at:nn {#1}{#2}
+ \tl_set_eq:NN \l_@@_tmpb_tl \g_@@_output_tl
+ \fp_set:Nn \l_@@_tmpa_fp { sqrt( (\tl_item:Nn \l_@@_tmpb_tl {1})^2 + (\tl_item:Nn \l_@@_tmpb_tl {2})^2 ) }
+ \fp_compare:nTF {\l_@@_tmpa_fp = 0}
+ {
+ \fp_set:Nn \l_@@_tmpa_fp {1}
+ \fp_set:Nn \l_@@_tmpb_fp {0}
+ }
+ {
+ \fp_set:Nn \l_@@_tmpb_fp { (\tl_item:Nn \l_@@_tmpb_tl {2}) / \l_@@_tmpa_fp }
+ \fp_set:Nn \l_@@_tmpa_fp { (\tl_item:Nn \l_@@_tmpb_tl {1}) / \l_@@_tmpa_fp }
+ }
+ \tl_set:Nx \l_@@_tmpa_tl
+ {
+ { \fp_to_decimal:n { \l_@@_tmpa_fp } }
+ { \fp_to_decimal:n { \l_@@_tmpb_fp } }
+ { \fp_to_decimal:n {- \l_@@_tmpb_fp } }
+ { \fp_to_decimal:n { \l_@@_tmpa_fp } }
+ }
+ \@@_point_at:nn {#1}{#2}
+ \tl_put_right:NV \l_@@_tmpa_tl \g_@@_output_tl
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_transformation_at:Nnn #1#2#3
+{
+ \@@_transformation_at:nn {#2}{#3}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_transformation_at:Nnn {NVn, NVV, NnV, NvV}
+\cs_new_protected_nopar:Npn \spath_gtransformation_at:Nnn #1#2#3
+{
+ \@@_transformation_at:nn {#2}{#3}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gtransformation_at:Nnn {NVn, NVV, NnV}
+% \end{macrocode}
+% \end{macro}
+%
+% \subsection{Intersection Routines}
+%
+% Note: I'm not consistent with number schemes.
+% The intersection library is 0-based, but the user interface is 1-based (since if we ``count'' in a \Verb+\foreach+ then it starts at 1).
+% This should be more consistent.
+%
+% \begin{macrocode}
+\tl_new:N \l_@@_split_path_a_tl
+\tl_new:N \l_@@_split_path_b_tl
+\tl_new:N \l_@@_split_path_a_start_tl
+\tl_new:N \l_@@_split_path_b_start_tl
+\tl_new:N \l_@@_split_path_a_end_tl
+\tl_new:N \l_@@_split_path_b_end_tl
+\tl_new:N \l_@@_split_path_a_final_tl
+\tl_new:N \l_@@_split_path_b_final_tl
+
+\tl_new:N \l_@@_split_prev_first_tl
+\tl_new:N \l_@@_split_prev_second_tl
+
+\seq_new:N \l_@@_split_first_seq
+\seq_new:N \l_@@_split_second_seq
+
+\int_new:N \l_@@_split_segment_int
+% \end{macrocode}
+%
+% \begin{macro}{
+% \spath_intersect:NN,
+% \spath_intersect:nn,
+% }
+% Pass two spaths to pgf's intersection routine.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \spath_intersect:NN #1#2
+{
+ \pgfintersectionofpaths%
+ {%
+ \pgfsetpath #1
+ }{%
+ \pgfsetpath #2
+ }
+}
+\tl_new:N \l_@@_intersecta_tl
+\tl_new:N \l_@@_intersectb_tl
+\cs_new_protected_nopar:Npn \spath_intersect:nn #1#2
+{
+ \tl_set:Nn \l_@@_intersecta_tl {#1}
+ \tl_set:Nn \l_@@_intersectb_tl {#2}
+ \spath_intersect:NN \l_@@_intersecta_tl \l_@@_intersectb_tl
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_split_at_intersections:NNnn,
+% \spath_split_at_intersections:NN,
+% \spath_gsplit_at_intersections:NNnn,
+% \spath_gsplit_at_intersections:NN
+% }
+% Given two paths, split them at points where they intersect and store them in the macros.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_split_at_intersections:nn #1#2
+{
+ \group_begin:
+
+ % Clear some token lists and sequences
+ \tl_clear:N \l_@@_split_path_a_final_tl
+ \tl_clear:N \l_@@_split_path_b_final_tl
+ \seq_clear:N \l_@@_split_first_seq
+ \seq_clear:N \l_@@_split_second_seq
+
+ \pgfintersectionsortbyfirstpath
+ % Find the intersections of these segments
+ \tl_set:Nn \l_@@_split_path_a_tl {#1}
+ \tl_set:Nn \l_@@_split_path_b_tl {#2}
+ % Remove empty components
+% \spath_path_remove_empty_components:N \l_@@_split_path_a_tl
+% \spath_path_remove_empty_components:N \l_@@_split_path_b_tl
+
+ \spath_intersect:NN \l_@@_split_path_a_tl \l_@@_split_path_b_tl
+
+ % If we get intersections
+ \int_compare:nT {\pgfintersectionsolutions > 0}
+ {
+ % Find the times of the intersections on each path
+ \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions}
+ {
+ \pgfintersectiongetsolutiontimes{##1}{\l_@@_split_first_tl}{\l_@@_split_second_tl}
+ \seq_put_left:NV \l_@@_split_first_seq \l_@@_split_first_tl
+ }
+ }
+
+ \spath_intersect:NN \l_@@_split_path_b_tl \l_@@_split_path_a_tl
+
+ % If we get intersections
+ \int_compare:nT {\pgfintersectionsolutions > 0}
+ {
+ % Find the times of the intersections on each path
+ \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions}
+ {
+ \pgfintersectiongetsolutiontimes{##1}{\l_@@_split_first_tl}{\l_@@_split_second_tl}
+ \seq_put_left:NV \l_@@_split_second_seq \l_@@_split_first_tl
+ }
+ }
+
+ \tl_set:Nn \l_@@_split_prev_first_tl {-1}
+
+ \seq_map_inline:Nn \l_@@_split_first_seq
+ {
+ \tl_set:Nn \l_@@_split_first_tl {##1}
+
+ \tl_set_eq:NN \l_@@_tmpa_tl \l_@@_split_first_tl
+ \int_compare:nT
+ {
+ \fp_to_int:n {floor( \l_@@_split_first_tl) }
+ =
+ \fp_to_int:n {floor( \l_@@_split_prev_first_tl) }
+ }
+ {
+ \tl_set:Nx \l_@@_split_first_tl
+ {
+ \fp_eval:n {
+ floor( \l_@@_split_first_tl )
+ +
+ ( \l_@@_split_first_tl - floor( \l_@@_split_first_tl) )
+ /
+ ( \l_@@_split_prev_first_tl - floor( \l_@@_split_prev_first_tl) )
+ }
+ }
+ }
+ \tl_set_eq:NN \l_@@_split_prev_first_tl \l_@@_tmpa_tl
+
+ \spath_split_at:NNVV \l_@@_split_path_a_start_tl \l_@@_split_path_a_end_tl \l_@@_split_path_a_tl \l_@@_split_first_tl
+
+ \tl_put_left:NV \l_@@_split_path_a_final_tl \l_@@_split_path_a_end_tl
+ \tl_set_eq:NN \l_@@_split_path_a_tl \l_@@_split_path_a_start_tl
+
+ }
+
+ \tl_set:Nn \l_@@_split_prev_second_tl {-1}
+
+ \seq_map_inline:Nn \l_@@_split_second_seq
+ {
+ \tl_set:Nn \l_@@_split_second_tl {##1}
+
+ \tl_set_eq:NN \l_@@_tmpa_tl \l_@@_split_second_tl
+ \int_compare:nT
+ {
+ \fp_to_int:n {floor( \l_@@_split_second_tl) }
+ =
+ \fp_to_int:n {floor( \l_@@_split_prev_second_tl) }
+ }
+ {
+ \tl_set:Nx \l_@@_split_second_tl
+ {
+ \fp_eval:n {
+ floor( \l_@@_split_second_tl )
+ +
+ ( \l_@@_split_second_tl - floor( \l_@@_split_second_tl) )
+ /
+ ( \l_@@_split_prev_second_tl - floor( \l_@@_split_prev_second_tl) )
+ }
+ }
+ }
+ \tl_set_eq:NN \l_@@_split_prev_second_tl \l_@@_tmpa_tl
+
+ \spath_split_at:NNVV \l_@@_split_path_b_start_tl \l_@@_split_path_b_end_tl \l_@@_split_path_b_tl\l_@@_split_second_tl
+
+ \tl_put_left:NV \l_@@_split_path_b_final_tl \l_@@_split_path_b_end_tl
+ \tl_set_eq:NN \l_@@_split_path_b_tl \l_@@_split_path_b_start_tl
+
+ }
+
+ \tl_put_left:NV \l_@@_split_path_a_final_tl \l_@@_split_path_a_tl
+ \tl_put_left:NV \l_@@_split_path_b_final_tl \l_@@_split_path_b_tl
+
+ \tl_if_empty:NT \l_@@_split_path_a_final_tl
+ {
+ \tl_set_eq:NN \l_@@_split_path_a_final_tl \l_@@_split_path_a_tl
+ }
+ \tl_if_empty:NT \l_@@_split_path_b_final_tl
+ {
+ \tl_set_eq:NN \l_@@_split_path_b_final_tl \l_@@_split_path_b_tl
+ }
+
+ \spath_remove_empty_components:N \l_@@_split_path_a_final_tl
+ \spath_remove_empty_components:N \l_@@_split_path_b_final_tl
+
+ \tl_gclear:N \g_@@_output_tl
+ \@@_tl_gput_right_braced:NV \g_@@_output_tl \l_@@_split_path_a_final_tl
+ \@@_tl_gput_right_braced:NV \g_@@_output_tl \l_@@_split_path_b_final_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_split_at_intersections:NNnn #1#2#3#4
+{
+ \@@_split_at_intersections:nn {#3}{#4}
+ \tl_set:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
+ \tl_set:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_split_at_intersections:NNnn {NNVV, ccVV, ccvv}
+\cs_new_protected_nopar:Npn \spath_split_at_intersections:NN #1#2
+{
+ \spath_split_at_intersections:NNVV #1#2#1#2
+}
+\cs_generate_variant:Nn \spath_split_at_intersections:NN {cc}
+\cs_new_protected_nopar:Npn \spath_gsplit_at_intersections:NNnn #1#2#3#4
+{
+ \@@_split_at_intersections:nn {#3}{#4}
+ \tl_gset:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
+ \tl_gset:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gsplit_at_intersections:NNnn {NNVV, ccVV, ccvv}
+\cs_new_protected_nopar:Npn \spath_gsplit_at_intersections:NN #1#2
+{
+ \spath_gsplit_at_intersections:NNVV #1#2#1#2
+}
+\cs_generate_variant:Nn \spath_gsplit_at_intersections:NN {cc}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_split_at_self_intersections:Nn,
+% \spath_split_at_self_intersections:N,
+% \spath_gsplit_at_self_intersections:Nn,
+% \spath_gsplit_at_self_intersections:N,
+% }
+% Given a path, split it at points where it self-intersects and store in the given macro.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_split_at_self_intersections:n #1
+{
+ \group_begin:
+
+ % Copy the path
+ \tl_set:Nn \l_@@_split_path_b_tl {#1}
+
+ % Open the path
+ \spath_open:N \l_@@_split_path_b_tl
+ % Remove empty components
+ \spath_remove_empty_components:N \l_@@_split_path_b_tl
+ % Make a copy for later
+ \tl_set_eq:NN \l_@@_split_path_b_final_tl \l_@@_split_path_b_tl
+
+ % Clear some token lists and sequences
+ \tl_clear:N \l_@@_split_path_a_tl
+ \seq_clear:N \l_@@_split_first_seq
+ \int_zero:N \l_@@_split_segment_int
+
+ \pgfintersectionsortbyfirstpath
+
+ \bool_do_until:nn
+ {
+ \int_compare_p:n
+ {
+ \tl_count:N \l_@@_split_path_b_tl < 4
+ }
+ }
+ {
+ \tl_clear:N \l_@@_split_path_a_tl
+ \tl_put_right:Nx \l_@@_split_path_a_tl
+ {
+ \tl_item:Nn \l_@@_split_path_b_tl {1}
+ {\tl_item:Nn \l_@@_split_path_b_tl {2}}
+ {\tl_item:Nn \l_@@_split_path_b_tl {3}}
+ }
+
+ \tl_set:Nx \l_@@_tmpa_tl { \tl_item:Nn \l_@@_split_path_b_tl {4} }
+
+ \tl_set:Nx \l_@@_split_path_b_tl {\tl_tail:N \l_@@_split_path_b_tl}
+
+ \int_zero:N \l_@@_tmpa_int
+
+ \tl_case:Nn \l_@@_tmpa_tl
+ {
+ \c_spath_moveto_tl
+ {
+ \tl_clear:N \l_@@_split_path_a_tl
+ \tl_set:Nx \l_@@_split_path_b_tl {\tl_tail:N \l_@@_split_path_b_tl}
+ \tl_set:Nx \l_@@_split_path_b_tl {\tl_tail:N \l_@@_split_path_b_tl}
+ \tl_set:Nx \l_@@_split_path_b_tl {\tl_tail:N \l_@@_split_path_b_tl}
+ }
+ \c_spath_lineto_tl
+ {
+ \int_set:Nn \l_@@_tmpa_int {1}
+ }
+ \c_spath_curvetoa_tl
+ {
+ \int_set:Nn \l_@@_tmpa_int {3}
+ }
+ }
+
+ \prg_replicate:nn { \l_@@_tmpa_int }
+ {
+ \tl_set:Nx \l_@@_split_path_b_tl {\tl_tail:N \l_@@_split_path_b_tl}
+ \tl_set:Nx \l_@@_split_path_b_tl {\tl_tail:N \l_@@_split_path_b_tl}
+
+ \tl_put_right:Nx \l_@@_split_path_a_tl
+ {
+ \tl_item:Nn \l_@@_split_path_b_tl {1}
+ {\tl_item:Nn \l_@@_split_path_b_tl {2}}
+ {\tl_item:Nn \l_@@_split_path_b_tl {3}}
+ }
+
+ \tl_set:Nx \l_@@_split_path_b_tl {\tl_tail:N \l_@@_split_path_b_tl}
+ }
+
+ \tl_put_left:NV \l_@@_split_path_b_tl \c_spath_moveto_tl
+
+ \tl_if_empty:NF \l_@@_split_path_a_tl
+ {
+ % Intersect the current segment with the rest of the path
+ \spath_intersect:NN \l_@@_split_path_a_tl \l_@@_split_path_b_tl
+
+
+ % If we get intersections
+ \int_compare:nT {\pgfintersectionsolutions > 0}
+ {
+ % Find the times of the intersections on each path
+ \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions}
+ {
+ \pgfintersectiongetsolutiontimes{##1}{\l_@@_split_first_tl}{\l_@@_split_second_tl}
+ \fp_compare:nT
+ {
+ \l_@@_split_first_tl < .99
+ }
+ {
+ \tl_set:Nx \l_@@_tmpa_tl {\fp_to_decimal:n {\l_@@_split_first_tl + \l_@@_split_segment_int}}
+ \seq_put_right:NV \l_@@_split_first_seq \l_@@_tmpa_tl
+ }
+ }
+ }
+
+ \spath_intersect:NN \l_@@_split_path_b_tl \l_@@_split_path_a_tl
+
+ % If we get intersections
+ \int_compare:nT {\pgfintersectionsolutions > 0}
+ {
+ % Find the times of the intersections on each path
+ \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions}
+ {
+ \pgfintersectiongetsolutiontimes{##1}{\l_@@_split_first_tl}{\l_@@_split_second_tl}
+ \fp_compare:nT
+ {
+ \l_@@_split_first_tl > .01
+ }
+ {
+ \tl_set:Nx \l_@@_tmpa_tl {\fp_to_decimal:n {\l_@@_split_first_tl + \l_@@_split_segment_int + 1}}
+ \seq_put_right:NV \l_@@_split_first_seq \l_@@_tmpa_tl
+ }
+ }
+ }
+
+ }
+ % Increment the segment counter
+ \int_incr:N \l_@@_split_segment_int
+ }
+
+ % Sort the sequence by reverse order along the path
+ \seq_sort:Nn \l_@@_split_first_seq
+ {
+ \fp_compare:nNnTF { ##1 } < { ##2 }
+ { \sort_return_swapped: }
+ { \sort_return_same: }
+ }
+
+ % Restore the original copy of the path
+ \tl_set_eq:NN \l_@@_split_path_b_tl \l_@@_split_path_b_final_tl
+
+ % Clear the token lists
+ \tl_clear:N \l_@@_split_path_b_start_tl
+ \tl_clear:N \l_@@_split_path_b_end_tl
+ \tl_clear:N \l_@@_split_path_b_final_tl
+
+ \tl_set:Nn \l_@@_split_prev_first_tl {-1}
+
+ \seq_map_inline:Nn \l_@@_split_first_seq
+ {
+ \tl_set:Nn \l_@@_split_first_tl {##1}
+ \tl_set_eq:NN \l_@@_tmpa_tl \l_@@_split_first_tl
+ \int_compare:nT
+ {
+ \fp_to_int:n {floor( \l_@@_split_first_tl ) }
+ =
+ \fp_to_int:n {floor( \l_@@_split_prev_first_tl) }
+ }
+ {
+ \tl_set:Nx \l_@@_split_first_tl
+ {
+ \fp_eval:n {
+ floor( \l_@@_split_first_tl )
+ +
+ ( \l_@@_split_first_tl - floor( \l_@@_split_first_tl) )
+ /
+ ( \l_@@_split_prev_first_tl - floor( \l_@@_split_prev_first_tl) )
+ }
+ }
+ }
+ \tl_set_eq:NN \l_@@_split_prev_first_tl \l_@@_tmpa_tl
+
+ \spath_split_at:NNVV \l_@@_split_path_b_start_tl \l_@@_split_path_b_end_tl \l_@@_split_path_b_tl \l_@@_split_first_tl
+
+ \tl_put_left:NV \l_@@_split_path_b_final_tl \l_@@_split_path_b_end_tl
+ \tl_set_eq:NN \l_@@_split_path_b_tl \l_@@_split_path_b_start_tl
+
+ }
+
+ \tl_put_left:NV \l_@@_split_path_b_final_tl \l_@@_split_path_b_tl
+
+ \tl_if_empty:NT \l_@@_split_path_b_final_tl
+ {
+ \tl_set_eq:NN \l_@@_split_path_b_final_tl \l_@@_split_path_b_tl
+ }
+
+ \spath_remove_empty_components:N \l_@@_split_path_b_final_tl
+
+ \tl_gclear:N \g_@@_output_tl
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_split_path_b_final_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_split_at_self_intersections:Nn #1#2
+{
+ \@@_split_at_self_intersections:n {#2}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_split_at_self_intersections:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_split_at_self_intersections:N #1
+{
+ \spath_split_at_self_intersections:NV #1#1
+}
+\cs_generate_variant:Nn \spath_split_at_self_intersections:N {c}
+\cs_new_protected_nopar:Npn \spath_gsplit_at_self_intersections:Nn #1#2
+{
+ \@@_split_at_self_intersections:n {#2}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gsplit_at_self_intersections:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gsplit_at_self_intersections:N #1
+{
+ \spath_gsplit_at_self_intersections:NV #1#1
+}
+\cs_generate_variant:Nn \spath_gsplit_at_self_intersections:N {c}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{
+% \spath_join_component:Nnn,
+% \spath_join_component:Nn,
+% \spath_gjoin_component:Nnn,
+% \spath_gjoin_component:Nn,
+% }
+% Join the specified component of the spath to its predecessor.
+% \begin{macrocode}
+\tl_new:N \l_@@_tmpj_tl
+\cs_new_protected_nopar:Npn \@@_join_component:nn #1#2
+{
+ \group_begin:
+ \spath_components_to_seq:Nn \l_@@_tmpa_seq {#1}
+ \int_compare:nT
+ {
+ #2 == 1
+ }
+ {
+ \tl_clear:N \l_@@_tmpj_tl
+ \seq_pop_left:NN \l_@@_tmpa_seq \l_@@_tmpj_tl
+
+ \prg_replicate:nn {3}
+ {
+ \tl_set:Nx \l_@@_tmpj_tl {\tl_tail:N \l_@@_tmpj_tl}
+ }
+
+ \seq_put_right:NV \l_@@_tmpb_seq \l_@@_tmpj_tl
+ }
+ \bool_if:nT
+ {
+ \int_compare_p:n
+ {
+ #2 > 1
+ }
+ &&
+ \int_compare_p:n
+ {
+ #2 <= \seq_count:N \l_@@_tmpa_seq
+ }
+ }
+ {
+
+ \seq_clear:N \l_@@_tmpb_seq
+ \seq_map_indexed_inline:Nn \l_@@_tmpa_seq
+ {
+ \tl_set:Nn \l_@@_tmpj_tl {##2}
+ \int_compare:nT {##1 = #2}
+ {
+ \prg_replicate:nn {3}
+ {
+ \tl_set:Nx \l_@@_tmpj_tl {\tl_tail:N \l_@@_tmpj_tl}
+ }
+ }
+ \seq_put_right:NV \l_@@_tmpb_seq \l_@@_tmpj_tl
+ }
+
+ \seq_set_eq:NN \l_@@_tmpa_seq \l_@@_tmpb_seq
+ }
+
+ \tl_gset:Nx \g_@@_output_tl {\seq_use:Nn \l_@@_tmpa_seq {} }
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_join_component:Nnn #1#2#3
+{
+ \@@_join_component:nn {#2}{#3}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_join_component:Nnn {NVn, NVV}
+\cs_new_protected_nopar:Npn \spath_join_component:Nn #1#2
+{
+ \spath_join_component:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_join_component:Nn {cn, NV, cV}
+\cs_new_protected_nopar:Npn \spath_gjoin_component:Nnn #1#2#3
+{
+ \@@_join_component:nn {#2}{#3}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_gjoin_component:Nnn {NVn, NVV}
+\cs_new_protected_nopar:Npn \spath_gjoin_component:Nn #1#2
+{
+ \spath_gjoin_component:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_gjoin_component:Nn {cn, NV, cV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_spot_weld_components:Nn,
+% \spath_spot_weld_components:N,
+% \spath_spot_gweld_components:Nn,
+% \spath_spot_gweld_components:N,
+% }
+% Weld together any components where the last point of one is at the start point of the next (within a tolerance).
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_spot_weld_components:n #1
+{
+ \group_begin:
+ \dim_zero:N \l_@@_move_x_dim
+ \dim_zero:N \l_@@_move_y_dim
+
+ \spath_components_to_seq:Nn \l_@@_tmpa_seq {#1}
+ \seq_clear:N \l_@@_tmpb_seq
+ \dim_set:Nn \l_@@_move_x_dim {\tl_item:nn {#1} {2} + 10 pt}
+ \dim_set:Nn \l_@@_move_y_dim {\tl_item:nn {#1} {3} + 10 pt}
+
+ \int_set:Nn \l_@@_tmpa_int {\seq_count:N \l_@@_tmpa_seq}
+
+ \seq_map_inline:Nn \l_@@_tmpa_seq
+ {
+ \tl_set:Nn \l_@@_tmpa_tl {##1}
+ \bool_if:nT
+ {
+ \dim_compare_p:n
+ {
+ \dim_abs:n {\l_@@_move_x_dim - \tl_item:Nn \l_@@_tmpa_tl {2} } < 0.01pt
+ }
+ &&
+ \dim_compare_p:n
+ {
+ \dim_abs:n {\l_@@_move_y_dim - \tl_item:Nn \l_@@_tmpa_tl {3} } < 0.01pt
+ }
+ }
+ {
+ \prg_replicate:nn {3}
+ {
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ }
+ \int_decr:N \l_@@_tmpa_int
+ }
+ \tl_reverse:N \l_@@_tmpa_tl
+ \dim_set:Nn \l_@@_move_x_dim {\tl_item:Nn \l_@@_tmpa_tl {2}}
+ \dim_set:Nn \l_@@_move_y_dim {\tl_item:Nn \l_@@_tmpa_tl {1}}
+ \tl_reverse:N \l_@@_tmpa_tl
+ \seq_put_right:NV \l_@@_tmpb_seq \l_@@_tmpa_tl
+ }
+
+ \tl_set:Nx \l_@@_tmpa_tl {\seq_use:Nn \l_@@_tmpb_seq {} }
+ \spath_components_to_seq:NV \l_@@_tmpb_seq \l_@@_tmpa_tl
+
+
+ \spath_initialpoint:Nn \l_@@_tmpa_tl {#1}
+ \spath_finalpoint:Nn \l_@@_tmpb_tl {#1}
+
+ \bool_if:nT
+ {
+ \dim_compare_p:n
+ {
+ \dim_abs:n {\tl_item:Nn \l_@@_tmpa_tl {1} - \tl_item:Nn \l_@@_tmpb_tl {1} } < 0.01pt
+ }
+ &&
+ \dim_compare_p:n
+ {
+ \dim_abs:n {\tl_item:Nn \l_@@_tmpa_tl {2} - \tl_item:Nn \l_@@_tmpb_tl {2} } < 0.01pt
+ }
+ }
+ {
+ \int_compare:nTF
+ {
+ \seq_count:N \l_@@_tmpb_seq > 1
+ }
+ {
+ \seq_pop_left:NN \l_@@_tmpb_seq \l_@@_tmpb_tl
+
+ \prg_replicate:nn {3}
+ {
+ \tl_set:Nx \l_@@_tmpb_tl {\tl_tail:N \l_@@_tmpb_tl}
+ }
+ \seq_put_right:NV \l_@@_tmpb_seq \l_@@_tmpb_tl
+ }
+ {
+ \tl_set:NV \l_@@_tmpb_tl \c_spath_closepath_tl
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ { \tl_item:Nn \l_@@_tmpa_tl {1} }
+ { \tl_item:Nn \l_@@_tmpa_tl {2} }
+ }
+ \seq_put_right:NV \l_@@_tmpb_seq \l_@@_tmpb_tl
+ }
+ }
+
+ \tl_gset:Nx \g_@@_output_tl {\seq_use:Nn \l_@@_tmpb_seq {}}
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_spot_weld_components:Nn #1#2
+{
+ \@@_spot_weld_components:n {#2}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_spot_weld_components:Nn {NV, cV, cn}
+\cs_new_protected_nopar:Npn \spath_spot_weld_components:N #1
+{
+ \spath_spot_weld_components:NV #1#1
+}
+\cs_generate_variant:Nn \spath_spot_weld_components:N {c}
+\cs_new_protected_nopar:Npn \spath_spot_gweld_components:Nn #1#2
+{
+ \@@_spot_weld_components:n {#2}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_generate_variant:Nn \spath_spot_gweld_components:Nn {NV, cV, cn}
+\cs_new_protected_nopar:Npn \spath_spot_gweld_components:N #1
+{
+ \spath_spot_gweld_components:NV #1#1
+}
+\cs_generate_variant:Nn \spath_spot_gweld_components:N {c}
+% \end{macrocode}
+% \end{macro}
+%
+% \subsection{Exporting Commands}
+%
+% \begin{macro}{
+% \spath_convert_to_svg:Nn,
+% \spath_gconvert_to_svg:Nn,
+% }
+% Convert the soft path to an SVG document.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_convert_to_svg:n #1
+{
+ \group_begin:
+ \tl_clear:N \l_@@_tmpa_tl
+ \tl_put_right:Nn \l_@@_tmpa_tl
+ {
+ <?xml~ version="1.0"~ standalone="no"?>
+ \iow_newline:
+ <!DOCTYPE~ svg~ PUBLIC~ "-//W3C//DTD SVG 1.1//EN"~
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+ \iow_newline:
+ <svg~ xmlns="http://www.w3.org/2000/svg"~ version="1.1"~viewBox="
+ }
+
+ \spath_minbb:Nn \l_@@_tmpb_tl {#1}
+ \spath_maxbb:Nn \l_@@_tmpc_tl {#1}
+ \tl_put_right:Nx \l_@@_tmpa_tl
+ {
+ \dim_to_decimal:n
+ {
+ \tl_item:Nn \l_@@_tmpb_tl {1} - 10pt
+ }
+ \exp_not:n {~}
+ \dim_to_decimal:n
+ {
+ \tl_item:Nn \l_@@_tmpb_tl {2} - 10pt
+ }
+ \exp_not:n {~}
+ \dim_to_decimal:n
+ {
+ \tl_item:Nn \l_@@_tmpc_tl {1}
+ -
+ \tl_item:Nn \l_@@_tmpb_tl {1}
+ + 20pt
+ }
+ \exp_not:n {~}
+ \dim_to_decimal:n
+ {
+ \tl_item:Nn \l_@@_tmpc_tl {2}
+ -
+ \tl_item:Nn \l_@@_tmpb_tl {2}
+ + 20pt
+ }
+ }
+
+ \tl_put_right:Nn \l_@@_tmpa_tl
+ {
+ ">
+ \iow_newline:
+ <path~ d="
+ }
+ \tl_set:Nn \l_@@_tmpc_tl {use:n}
+ \tl_map_inline:Nn #1
+ {
+ \tl_set:Nn \l_@@_tmpb_tl {##1}
+ \tl_case:NnF \l_@@_tmpb_tl
+ {
+ \c_spath_moveto_tl
+ {
+ \tl_put_right:Nn \l_@@_tmpa_tl {M~}
+ \tl_set:Nn \l_@@_tmpc_tl {use:n}
+ }
+ \c_spath_lineto_tl
+ {
+ \tl_put_right:Nn \l_@@_tmpa_tl {L~}
+ \tl_set:Nn \l_@@_tmpc_tl {use:n}
+ }
+ \c_spath_closepath_tl
+ {
+ \tl_put_right:Nn \l_@@_tmpa_tl {Z~}
+ \tl_set:Nn \l_@@_tmpc_tl {use_none:n}
+ }
+ \c_spath_curvetoa_tl
+ {
+ \tl_put_right:Nn \l_@@_tmpa_tl {C~}
+ \tl_set:Nn \l_@@_tmpc_tl {use:n}
+ }
+ \c_spath_curvetob_tl {
+ \tl_set:Nn \l_@@_tmpc_tl {use:n}
+ }
+ \c_spath_curveto_tl {
+ \tl_set:Nn \l_@@_tmpc_tl {use:n}
+ }
+ }
+ {
+ \tl_put_right:Nx \l_@@_tmpa_tl {\use:c { \l_@@_tmpc_tl } {\dim_to_decimal:n {##1}} ~}
+ }
+ }
+ \tl_put_right:Nn \l_@@_tmpa_tl
+ {
+ "~ fill="none"~ stroke="black"~ />
+ \iow_newline:
+ </svg>
+ \iow_newline:
+ }
+ \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_convert_to_svg:Nn #1#2
+{
+ \@@_convert_to_svg:n {#2}
+ \tl_set_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+\cs_new_protected_nopar:Npn \spath_gconvert_to_svg:Nn #1#2
+{
+ \@@_convert_to_svg:n {#2}
+ \tl_gset_eq:NN #1 \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_export_to_svg:nn
+% }
+% Save a soft path to an SVG file.
+% \begin{macrocode}
+\iow_new:N \g_@@_stream
+\cs_new_protected_nopar:Npn \spath_export_to_svg:nn #1#2
+{
+ \spath_convert_path_to_svg:Nn \l_@@_iterp_tl {#2}
+ \iow_open:Nn \g_@@_stream {#1 .svg}
+ \iow_now:Nx \g_@@_stream
+ {
+ \tl_use:N \l_@@_iterp_tl
+ }
+ \iow_close:N \g_@@_stream
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\spath_show:n}
+% Displays the soft path on the terminal.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \spath_show:n #1
+{
+ \int_step_inline:nnnn {1} {3} {\tl_count:n {#1}}
+ {
+ \iow_term:x {
+ \tl_item:Nn \l_@@_tmpa_tl {##1}
+ {\tl_item:Nn \l_@@_tmpa_tl {##1+1}}
+ {\tl_item:Nn \l_@@_tmpa_tl {##1+2}}
+ }
+ }
+}
+\cs_generate_variant:Nn \spath_show:n {V, v}
+% \end{macrocode}
+% \end{macro}
+
+% \subsubsection{PGF and TikZ Interface Functions}
+%
+% Spaths come from PGF so we need some functions that get and set spaths from the pgf system.
+%
+% \begin{macro}{
+% \spath_get_current_path:N,
+% \spath_gget_current_path:N
+% }
+% Grab the current soft path from PGF.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \spath_get_current_path:N #1
+{
+ \pgfsyssoftpath at getcurrentpath #1
+}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \spath_gget_current_path:N #1
+{
+ \pgfsyssoftpath at getcurrentpath #1
+ \tl_gset_eq:NN #1 #1
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\spath_protocol_path:n}
+% This feeds the bounding box of the soft path to PGF to ensure that its current bounding box contains the soft path.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \spath_protocol_path:n #1
+{
+ \spath_minbb:Nn \l_@@_tmpa_tl {#1}
+ \exp_last_unbraced:NV \pgf at protocolsizes\l_@@_tmpa_tl
+
+ \spath_maxbb:Nn \l_@@_tmpa_tl {#1}
+ \exp_last_unbraced:NV \pgf at protocolsizes\l_@@_tmpa_tl
+}
+\cs_generate_variant:Nn \spath_protocol_path:n {V}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_set_current_path:n,
+% \spath_set_current_path:N
+% }
+% Sets the current path to the specified soft path.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \spath_set_current_path:n #1
+{
+ \spath_protocol_path:n {#1}
+ \tl_set:Nn \l_@@_tmpa_tl {#1}
+ \pgfsyssoftpath at setcurrentpath\l_@@_tmpa_tl
+}
+\cs_new_protected_nopar:Npn \spath_set_current_path:N #1
+{
+ \spath_protocol_path:V #1
+ \pgfsyssoftpath at setcurrentpath #1
+}
+\cs_generate_variant:Nn \spath_set_current_path:N {c}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{
+% \spath_use_path:nn
+% }
+% Uses the given soft path at the PGF level.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \spath_use_path:nn #1#2
+{
+ \spath_set_current_path:n {#1}
+ \pgfusepath{#2}
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\spath_tikz_path:nn}
+% Uses the given soft path at the TikZ level.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \spath_tikz_path:nn #1#2
+{
+ \path[#1] \pgfextra{
+ \spath_set_current_path:n {#2}
+ \tl_put_right:Nn \tikz at preactions {\def\tikz at actions@path{#2}}
+ };
+}
+\cs_generate_variant:Nn \spath_tikz_path:nn {Vn, VV, nv, Vv, nV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\spath_set_tikz_coords:n}
+% Sets the \Verb+\tikz at lastx+ and other coordinates from the soft path.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \spath_set_tikz_coords:n #1
+{
+ \spath_finalpoint:Nn \l_@@_tmpa_tl {#1}
+ \tl_set:Nx \l_@@_tmpa_tl
+ {
+ \exp_not:c {tikz at lastx}=\tl_item:Nn \l_@@_tmpa_tl {1}
+ \exp_not:c {tikz at lasty}=\tl_item:Nn \l_@@_tmpa_tl {2}
+ \exp_not:c {tikz at lastxsaved}=\tl_item:Nn \l_@@_tmpa_tl {1}
+ \exp_not:c {tikz at lastysaved}=\tl_item:Nn \l_@@_tmpa_tl {2}
+ }
+ \tl_use:N \l_@@_tmpa_tl
+}
+\cs_generate_variant:Nn \spath_set_tikz_coords:n {V, v}
+% \end{macrocode}
+% \end{macro}
+%
+% \iffalse
+%</spath3>
+% \fi
+%
+% \section{The TikZ interface}
+%
+% \iffalse
+%<*tikzspath3>
+% \fi
+%
+% This provides an interface to the soft path manipulation routines via a series of TikZ keys.
+% They all live in the \texttt{spath} family.
+%
+%
+% \begin{macrocode}
+\RequirePackage{spath3}
+\RequirePackage{expl3}
+\ExplSyntaxOn
+
+\tl_new:N \l_@@_current_tl
+\tl_new:N \l_@@_reverse_tl
+\tl_new:N \l_@@_prefix_tl
+\tl_new:N \l_@@_suffix_tl
+\tl_new:N \g_@@_smuggle_tl
+\seq_new:N \g_@@_tmpa_seq
+\seq_new:N \g_@@_tmpb_seq
+\bool_new:N \l_@@_draft_bool
+% \end{macrocode}
+%
+% When saving a soft path, by default we use a naming convention that is compatible with the intersections library so that paths saved here and paths saved by the \texttt{name path} facility of the intersections library are mutually exchangeable.
+%
+% \begin{macrocode}
+\tl_set:Nn \l_@@_prefix_tl {tikz at intersect@path at name@}
+\tl_set:Nn \l_@@_suffix_tl {}
+% \end{macrocode}
+%
+% When a soft path is grabbed from TikZ we're usually deep in a group so I've adapted the code from the intersections library to dig the definition out of the group without making everything global.
+%
+% \begin{macrocode}
+\tl_new:N \g_@@_tikzfinish_tl
+\cs_new_protected_nopar:Npn \spath_at_end_of_path:
+{
+ \tl_use:N \g_@@_tikzfinish_tl
+ \tl_gclear:N \g_@@_tikzfinish_tl
+}
+\tl_put_right:Nn \tikz at finish {\spath_at_end_of_path:}
+
+\cs_new_protected_nopar:Npn \spath_save_path:Nn #1#2
+{
+ \tl_gput_right:Nn \g_@@_tikzfinish_tl
+ {
+ \tl_clear_new:N #1
+ \tl_set:Nn #1 {#2}
+ }
+}
+\cs_generate_variant:Nn \spath_save_path:Nn {cn, NV, cV}
+
+\cs_new_protected_nopar:Npn \spath_gsave_path:Nn #1#2
+{
+ \tl_gput_right:Nn \g_@@_tikzfinish_tl
+ {
+ \tl_gclear_new:N #1
+ \tl_gset:Nn #1 {#2}
+ }
+}
+\cs_generate_variant:Nn \spath_gsave_path:Nn {cn, NV, cV}
+% \end{macrocode}
+%
+% Now we define all of our keys.
+%
+% \begin{macrocode}
+\tikzset{
+% \end{macrocode}
+%
+% We're in the \texttt{spath} key family.
+%
+% \begin{macrocode}
+ spath/.is~family,
+ spath/.cd,
+% \end{macrocode}
+%
+% We provide for saving soft paths with a specific prefix and suffix in the name.
+% The default is to make it compatible with the intersections library.
+%
+% \begin{macrocode}
+ set~ prefix/.store~ in=\l_@@_prefix_tl,
+ prefix/.is~choice,
+ prefix/default/.style={
+ /tikz/spath/set~ prefix=tikz at intersect@path at name@
+ },
+ set~ suffix/.store~ in=\l_@@_suffix_tl,
+ suffix/.is~choice,
+ suffix/default/.style={
+ /tikz/spath/set~ suffix={}
+ },
+ set~ name/.style={
+ /tikz/spath/prefix=#1,
+ /tikz/spath/suffix=#1
+ },
+% \end{macrocode}
+%
+% Keys for saving and cloning a soft path.
+%
+% \begin{macrocode}
+ save/.code={
+ \tikz at addmode{
+ \spath_get_current_path:N \l_@@_tmpa_tl
+ \spath_bake_round:NV \l_@@_tmpa_tl \l_@@_tmpa_tl
+ \spath_save_path:cV {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl} \l_@@_tmpa_tl
+ }
+ },
+ clone/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #2 \tl_use:N \l_@@_suffix_tl}
+ {
+ \tl_clear_new:c
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ \tl_set_eq:cc
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {\tl_use:N \l_@@_prefix_tl #2 \tl_use:N \l_@@_suffix_tl}
+ }
+ },
+ clone~ global/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #2 \tl_use:N \l_@@_suffix_tl}
+ {
+ \tl_gclear_new:c
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ \tl_gset_eq:cc
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {\tl_use:N \l_@@_prefix_tl #2 \tl_use:N \l_@@_suffix_tl}
+ }
+ },
+ save~ global/.code={
+ \tikz at addmode{
+ \spath_get_current_path:N \l_@@_tmpa_tl
+ \spath_bake_round:NV \l_@@_tmpa_tl \l_@@_tmpa_tl
+ \spath_gsave_path:cV
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ \l_@@_tmpa_tl
+ }
+ },
+% \end{macrocode}
+%
+% Saves a soft path to the aux file.
+%
+% \begin{macrocode}
+ save~ to~ aux/.code={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_save_to_aux:c
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ }
+ },
+% \end{macrocode}
+%
+% Restores a soft path to the current path.
+%
+% \begin{macrocode}
+ restore/.code={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_set_current_path:c
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ \spath_set_tikz_coords:v
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ }
+ },
+% \end{macrocode}
+%
+% Diagnostic, show the current path in the terminal and log.
+%
+% \begin{macrocode}
+ show~current~path/.code={
+ \tikz at addmode{
+ \pgfsyssoftpath at getcurrentpath\l_@@_tmpa_tl
+ \iow_term:n {---~ current~ soft~ path~ ---}
+ \spath_show:V \l_@@_tmpa_tl
+ }
+ },
+% \end{macrocode}
+%
+% Diagnostic, show the named soft path in the terminal and log.
+%
+% \begin{macrocode}
+ show/.code={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \iow_term:n {---~ soft~ path~ #1~ ---}
+ \spath_show:v {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ }
+ },
+% \end{macrocode}
+%
+% Appends the named path to the current path with a weld.
+%
+% \begin{macrocode}
+ append/.code={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_get_current_path:N \l_@@_current_tl
+ \spath_weld:Nv
+ \l_@@_current_tl
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ \spath_set_current_path:N \l_@@_current_tl
+ \spath_set_tikz_coords:V \l_@@_current_tl
+ }
+ },
+% \end{macrocode}
+%
+% Joins the second named path to the first.
+%
+% \begin{macrocode}
+ join~ with/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #2 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_append:cv
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {\tl_use:N \l_@@_prefix_tl #2 \tl_use:N \l_@@_suffix_tl}
+ }
+ }
+ },
+% \end{macrocode}
+%
+% Does a ``spot weld'' on a soft path, which means that any components that start where the previous component ends are welded together.
+%
+% \begin{macrocode}
+ spot~ weld/.code={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_spot_weld_components:c
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ }
+ },
+% \end{macrocode}
+%
+% Reverses the named path.
+%
+% \begin{macrocode}
+ reverse/.code={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_reverse:c
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ }
+ },
+% \end{macrocode}
+%
+% Appends the reversal of the path to the current path.
+%
+% \begin{macrocode}
+ append~ reverse/.code={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_reverse:Nv
+ \l_@@_reverse_tl
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ \spath_get_current_path:N \l_@@_current_tl
+ \spath_weld:NV \l_@@_current_tl \l_@@_reverse_tl
+ \spath_set_current_path:N \l_@@_current_tl
+ \spath_set_tikz_coords:V \l_@@_current_tl
+ }
+ },
+% \end{macrocode}
+%
+% Inserts the named path into the current path as-is, meaning without transforming or welding it.
+%
+% \begin{macrocode}
+ insert/.code={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_get_current_path:N \l_@@_current_tl
+ \spath_append:Nv
+ \l_@@_current_tl
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ \spath_set_current_path:N \l_@@_current_tl
+ \spath_set_tikz_coords:V \l_@@_current_tl
+ }
+ },
+% \end{macrocode}
+%
+% Inserts the reverse of the named path.
+%
+% \begin{macrocode}
+ insert~ reverse/.code={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_reverse:Nv
+ \l_@@_reverse_tl
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ \spath_get_current_path:N \l_@@_current_tl
+ \spath_append:NV \l_@@_current_tl \l_@@_reverse_tl
+ \spath_set_current_path:N \l_@@_current_tl
+ \spath_set_tikz_coords:V \l_@@_current_tl
+ }
+ },
+% \end{macrocode}
+%
+% These keys shorten the path.
+%
+% \begin{macrocode}
+ shorten~ at~ end/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_shorten_at_end:cn
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl} {#2}
+ }
+ },
+ shorten~ at~ start/.code~ 2~ args ={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_shorten_at_start:cn
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl} {#2}
+ }
+ },
+ shorten~ at~ both~ ends/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_shorten_at_end:cn
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl} {#2}
+ \spath_shorten_at_start:cn
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl} {#2}
+ }
+ },
+% \end{macrocode}
+%
+% This translates the named path.
+%
+% \begin{macrocode}
+ translate/.code~ n~ args={3}{
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_translate:cnn
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}{#2}{#3}
+ }
+ },
+% \end{macrocode}
+%
+% Exports the path as an SVG file.
+%
+% \begin{macrocode}
+ export~ to~ svg/.code={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_export_to_svg:c
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ }
+ },
+% \end{macrocode}
+%
+% Transforms the named path using TikZ transformation specifications.
+%
+% \begin{macrocode}
+ transform/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \group_begin:
+ \pgftransformreset
+ \tikzset{#2}
+ \pgfgettransform \l_@@_tmpa_tl
+ \tl_gset:Nn \g_@@_smuggle_tl
+ {
+ \spath_transform:cnnnnnn
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ }
+ \tl_gput_right:NV \g_@@_smuggle_tl \l_@@_tmpa_tl
+ \group_end:
+ \tl_use:N \g_@@_smuggle_tl
+ }
+ },
+ transform~global/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \group_begin:
+ \pgftransformreset
+ \tikzset{#2}
+ \pgfgettransform \l_@@_tmpa_tl
+ \tl_gset:Nn \g_@@_smuggle_tl
+ {
+ \spath_gtransform:cnnnnnn
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ }
+ \tl_gput_right:NV \g_@@_smuggle_tl \l_@@_tmpa_tl
+ \group_end:
+ \tl_use:N \g_@@_smuggle_tl
+ }
+ },
+% \end{macrocode}
+%
+% Splits two paths at their mutual intersections.
+%
+% \begin{macrocode}
+ split~ at~ intersections/.code~ n~ args={2}{
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #2 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_split_at_intersections:cc
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {\tl_use:N \l_@@_prefix_tl #2 \tl_use:N \l_@@_suffix_tl}
+ }
+ }
+ },
+% \end{macrocode}
+%
+% Splits a path at its self-intersections.
+%
+% \begin{macrocode}
+ split~ at~ self~ intersections/.code={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_split_at_self_intersections:c
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ }
+ },
+% \end{macrocode}
+%
+% Extract the components of a path into a comma separated list (suitable for using in a \Verb+\foreach+ loop).
+%
+% \begin{macrocode}
+ get~ components~ of/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \clist_clear_new:N #2
+ \spath_components_to_seq:Nv
+ \l_@@_tmpa_seq
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ \seq_map_inline:Nn \l_@@_tmpa_seq
+ {
+ \tl_new:c
+ {\tl_use:N \l_@@_prefix_tl anonymous_\int_use:N \g_@@_anon_int \tl_use:N \l_@@_suffix_tl}
+ \tl_set:cn
+ {\tl_use:N \l_@@_prefix_tl anonymous_\int_use:N \g_@@_anon_int \tl_use:N \l_@@_suffix_tl} {##1}
+ \clist_put_right:Nx #2 {anonymous_\int_use:N \g_@@_anon_int}
+ \int_gincr:N \g_@@_anon_int
+ }
+ }
+ },
+% \end{macrocode}
+%
+% Loop through the components of a soft path and render each as a separate TikZ path so that they can be individually styled.
+%
+% \begin{macrocode}
+ render~ components/.code={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \group_begin:
+ \spath_components_to_seq:Nv
+ \l_@@_tmpa_seq
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ \seq_map_indexed_inline:Nn \l_@@_tmpa_seq
+ {
+ \spath_tikz_path:nn
+ {
+ every~ spath~ component/.try,
+ spath ~component~ ##1/.try,
+ spath ~component/.try={##1},
+ every~ #1~ component/.try,
+ #1 ~component~ ##1/.try,
+ #1 ~component/.try={##1},
+ }
+ {
+ ##2
+ }
+ }
+ \group_end:
+ }
+ },
+% \end{macrocode}
+%
+% This puts gaps between components of a soft path.
+% The list of components is passed through a \Verb+\foreach+ loop so can use the shortcut syntax from those loops.
+%
+% \begin{macrocode}
+ insert~ gaps~ after~ components/.code~ n~ args={3}{
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \group_begin:
+ \seq_gclear:N \g_@@_tmpa_seq
+ \seq_gclear:N \g_@@_tmpb_seq
+ \foreach \l_@@_tmpa_tl in {#3}
+ {
+ \seq_gput_right:NV \g_@@_tmpa_seq \l_@@_tmpa_tl
+ \seq_gput_right:Nx \g_@@_tmpb_seq {\int_eval:n { \l_@@_tmpa_tl + 1 }}
+ }
+ \spath_components_to_seq:Nv
+ \l_@@_tmpa_seq
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ \seq_clear:N \l_@@_tmpb_seq
+ \seq_map_indexed_inline:Nn \l_@@_tmpa_seq
+ {
+ \tl_set:Nn \l_@@_tmpa_tl {##2}
+ \seq_if_in:NnT \g_@@_tmpa_seq {##1}
+ {
+ \spath_shorten_at_end:Nn \l_@@_tmpa_tl {#2/2}
+ }
+ \seq_if_in:NnT \g_@@_tmpb_seq {##1}
+ {
+ \spath_shorten_at_start:Nn \l_@@_tmpa_tl {#2/2}
+ }
+ \seq_put_right:NV \l_@@_tmpb_seq \l_@@_tmpa_tl
+ }
+ \tl_gset:Nx \g_@@_output_tl {\seq_use:Nn \l_@@_tmpb_seq {} }
+ \group_end:
+ \tl_set_eq:cN
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ \g_@@_output_tl
+ \tl_gclear:N \g_@@_output_tl
+ }
+ },
+% \end{macrocode}
+%
+% Join the specified components together, joining each to its previous one.
+%
+% \begin{macrocode}
+ join~ components/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \seq_gclear:N \g_@@_tmpa_seq
+ \foreach \l_@@_tmpa_tl in {#2}
+ {
+ \seq_gput_right:NV \g_@@_tmpa_seq \l_@@_tmpa_tl
+ }
+ \seq_gsort:Nn \g_@@_tmpa_seq
+ {
+ \int_compare:nNnTF {##1} > {##2}
+ { \sort_return_same: }
+ { \sort_return_swapped: }
+ }
+ \seq_map_inline:Nn \g_@@_tmpa_seq
+ {
+ \spath_join_component:cn
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}{##1}
+ }
+ }
+ },
+% \end{macrocode}
+%
+% Remove all components of the path that don't actually draw anything.
+%
+% \begin{macrocode}
+ remove~ empty~ components/.code={
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_remove_empty_components:c
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ }
+ },
+% \end{macrocode}
+%
+% This puts a conditional around the \texttt{spot weld} key because when figuring out a knot drawing then we will initially want to render it without the spot weld to keep the number of components constant.
+%
+% \begin{macrocode}
+ draft~ mode/.is~ choice,
+ draft~ mode/true/.code={
+ \bool_set_true:N \l_@@_draft_bool
+ },
+ draft~ mode/false/.code={
+ \bool_set_false:N \l_@@_draft_bool
+ },
+ maybe~ spot~ weld/.code={
+ \bool_if:NF \l_@@_draft_bool
+ {
+ \tl_if_exist:cT {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ {
+ \spath_spot_weld_components:c
+ {\tl_use:N \l_@@_prefix_tl #1 \tl_use:N \l_@@_suffix_tl}
+ }
+ }
+ },
+% \end{macrocode}
+%
+% Set the transformation to lie along a path.
+%
+% \begin{macrocode}
+ transform~ to/.code~ 2~ args={
+ \group_begin:
+ \tl_if_exist:cTF
+ {
+ \tl_use:N \l_@@_prefix_tl
+ #1
+ \tl_use:N \l_@@_suffix_tl
+ }
+ {
+ \spath_reallength:Nv
+ \l_@@_tmpa_int
+ {
+ \tl_use:N \l_@@_prefix_tl
+ #1
+ \tl_use:N \l_@@_suffix_tl
+ }
+
+ \tl_set:Nx \l_@@_tmpb_tl
+ {\fp_to_decimal:n {(#2) * (\l_@@_tmpa_int)}}
+ \spath_transformation_at:NvV \l_@@_tmpc_tl
+ {
+ \tl_use:N \l_@@_prefix_tl
+ #1
+ \tl_use:N \l_@@_suffix_tl
+ }
+ \l_@@_tmpb_tl
+ \tl_gset_eq:NN \g_@@_smuggle_tl \l_@@_tmpc_tl
+ }
+ {
+ \tl_gset_eq:NN \g_@@_smuggle_tl { {1}{0}{0}{1}{0pt}{0pt} }
+ }
+ \group_end:
+ \exp_last_unbraced:NV \pgfsettransformentries \g_@@_smuggle_tl
+ \tl_gclear:N \g_@@_smuggle_tl
+ },
+% \end{macrocode}
+%
+% As above, but with a possible extra \(180^\circ\) rotation if needed to ensure that the new \(y\)--axis points vaguely upwards.
+%
+% \begin{macrocode}
+ upright~ transform~ to/.code~ 2~ args={
+ \group_begin:
+ \tl_if_exist:cTF
+ {
+ \tl_use:N \l_@@_prefix_tl
+ #1
+ \tl_use:N \l_@@_suffix_tl
+ }
+ {
+ \spath_reallength:Nv
+ \l_@@_tmpa_int
+ {
+ \tl_use:N \l_@@_prefix_tl
+ #1
+ \tl_use:N \l_@@_suffix_tl
+ }
+
+ \tl_set:Nx \l_@@_tmpb_tl
+ {\fp_to_decimal:n {(#2) * (\l_@@_tmpa_int)}}
+ \spath_transformation_at:NvV \l_@@_tmpc_tl
+ {
+ \tl_use:N \l_@@_prefix_tl
+ #1
+ \tl_use:N \l_@@_suffix_tl
+ }
+ \l_@@_tmpb_tl
+ \tl_gset_eq:NN \g_@@_smuggle_tl \l_@@_tmpc_tl
+ }
+ {
+ \tl_gset_eq:NN \g_@@_smuggle_tl { {1}{0}{0}{1}{0pt}{0pt} }
+ }
+ \fp_compare:nT { \tl_item:Nn \g_@@_smuggle_tl {4} < 0}
+ {
+ \tl_gset:Nx \g_@@_smuggle_tl
+ {
+ { \fp_eval:n { - (\tl_item:Nn \g_@@_smuggle_tl {1})} }
+ { \fp_eval:n { - (\tl_item:Nn \g_@@_smuggle_tl {2})} }
+ { \fp_eval:n { - (\tl_item:Nn \g_@@_smuggle_tl {3})} }
+ { \fp_eval:n { - (\tl_item:Nn \g_@@_smuggle_tl {4})} }
+ { \tl_item:Nn \g_@@_smuggle_tl {5} }
+ { \tl_item:Nn \g_@@_smuggle_tl {6} }
+ }
+ }
+ \group_end:
+ \exp_last_unbraced:NV \pgfsettransformentries \g_@@_smuggle_tl
+ \tl_gclear:N \g_@@_smuggle_tl
+ },
+% \end{macrocode}
+%
+% This is a useful set of styles for drawing a knot diagram.
+%
+% \begin{macrocode}
+ knot/.style~ n~ args={3}{
+ spath/.cd,
+ split~ at~ self~ intersections=#1,
+ insert~ gaps~ after~ components={#1}{#2}{#3},
+ maybe~ spot~ weld=#1,
+ render~ components=#1
+ },
+}
+% \end{macrocode}
+%
+% This defines a coordinate system that finds a position on a soft path.
+%
+% \begin{macrocode}
+\tikzdeclarecoordinatesystem{spath}{%
+ \group_begin:
+ \tl_set:Nn \l_@@_tmpa_tl {#1}
+ \tl_trim_spaces:N \l_@@_tmpa_tl
+
+ \seq_set_split:NnV \l_@@_tmpa_seq {~} \l_@@_tmpa_tl
+ \seq_pop_right:NN \l_@@_tmpa_seq \l_@@_tmpb_tl
+
+ \tl_set:Nx \l_@@_tmpa_tl { \seq_use:Nn \l_@@_tmpa_seq {~} }
+ \tl_if_exist:cTF
+ {
+ \tl_use:N \l_@@_prefix_tl
+ \tl_use:N \l_@@_tmpa_tl
+ \tl_use:N \l_@@_suffix_tl
+ }
+ {
+
+ \tl_set_eq:Nc
+ \l_@@_tmpa_tl
+ {
+ \tl_use:N \l_@@_prefix_tl
+ \tl_use:N \l_@@_tmpa_tl
+ \tl_use:N \l_@@_suffix_tl
+ }
+
+ \tl_if_empty:NTF \l_@@_tmpa_tl
+ {
+ \tl_gset_eq:NN \g_@@_smuggle_tl \pgfpointorigin
+ }
+ {
+ \spath_reallength:NV \l_@@_tmpa_int \l_@@_tmpa_tl
+ \tl_set:Nx \l_@@_tmpb_tl
+ {\fp_to_decimal:n {(\l_@@_tmpb_tl) * (\l_@@_tmpa_int)}}
+ \spath_point_at:NVV \l_@@_tmpc_tl \l_@@_tmpa_tl \l_@@_tmpb_tl
+
+ \tl_clear:N \l_@@_tmpd_tl
+ \tl_put_right:Nn \l_@@_tmpd_tl {\pgf at x=}
+ \tl_put_right:Nx \l_@@_tmpd_tl {\tl_item:Nn \l_@@_tmpc_tl {1}}
+ \tl_put_right:Nn \l_@@_tmpd_tl {\relax}
+ \tl_put_right:Nn \l_@@_tmpd_tl {\pgf at y=}
+ \tl_put_right:Nx \l_@@_tmpd_tl {\tl_item:Nn \l_@@_tmpc_tl {2}}
+ \tl_put_right:Nn \l_@@_tmpd_tl {\relax}
+ \tl_gset_eq:NN \g_@@_smuggle_tl \l_@@_tmpd_tl
+ }
+ }
+ {
+ \tl_gset_eq:NN \g_@@_smuggle_tl \pgfpointorigin
+ }
+ \group_end:
+ \tl_use:N \g_@@_smuggle_tl
+}
+
+\ExplSyntaxOff
+% \end{macrocode}
+% \iffalse
+%</tikzspath3>
+% \fi
+%
+% \iffalse
+%<*calligraphy>
+% \fi
+%
+% \section{The Calligraphy Package}
+%
+% \begin{macrocode}
+%<@@=cal>
+% \end{macrocode}
+%
+% \subsection{Initialisation}
+% \begin{macrocode}
+\RequirePackage{spath3}
+\ExplSyntaxOn
+
+\tl_new:N \l_@@_tmpa_tl
+\tl_new:N \l_@@_tmpb_tl
+\tl_new:N \l_@@_tmp_path_tl
+\tl_new:N \l_@@_tmp_rpath_tl
+\tl_new:N \l_@@_tmp_rpathb_tl
+\tl_new:N \l_@@_tmp_patha_tl
+
+\seq_new:N \l_@@_tmpa_seq
+
+\int_new:N \l_@@_tmpa_int
+\int_new:N \l_@@_tmpb_int
+\int_new:N \g_@@_path_component_int
+\int_new:N \g_@@_label_int
+
+\fp_new:N \l_@@_tmpa_fp
+\fp_new:N \l_@@_tmpb_fp
+\fp_new:N \l_@@_tmpc_fp
+\fp_new:N \l_@@_tmpd_fp
+\fp_new:N \l_@@_tmpe_fp
+
+\dim_new:N \l_@@_tmpa_dim
+\dim_new:N \l_@@_tmpb_dim
+\dim_new:N \l_@@_tmpc_dim
+\dim_new:N \l_@@_tmpd_dim
+\dim_new:N \l_@@_tmpe_dim
+\dim_new:N \l_@@_tmpf_dim
+\dim_new:N \l_@@_tmpg_dim
+\dim_new:N \l_@@_tmph_dim
+
+\bool_new:N \l_@@_annotate_bool
+\bool_new:N \l_@@_taper_start_bool
+\bool_new:N \l_@@_taper_end_bool
+\bool_new:N \l_@@_taperable_bool
+
+\dim_new:N \l_@@_taper_width_dim
+\dim_new:N \l_@@_line_width_dim
+
+\bool_set_true:N \l_@@_taper_start_bool
+\bool_set_true:N \l_@@_taper_end_bool
+
+\cs_generate_variant:Nn \tl_put_right:Nn {Nv}
+
+\msg_new:nnn { calligraphy } { undefined pen } { The~ pen~ "#1"~ is~ not~ defined. }
+% \end{macrocode}
+%
+% \subsection{TikZ Keys}
+%
+% The public interface to this package is through TikZ keys and styles.
+% \begin{macrocode}
+\tikzset{
+ define~pen/.code={
+ \tikzset{pen~name=#1}
+ \pgf at relevantforpicturesizefalse
+ \tikz at addmode{
+ \pgfsyssoftpath at getcurrentpath\l_@@_tmpa_tl
+ \spath_components_to_seq:NV \l_@@_tmpa_seq \l_@@_tmpa_tl
+ \seq_gclear_new:c {g_@@_pen_\pgfkeysvalueof{/tikz/pen~name}_seq}
+ \seq_gset_eq:cN {g_@@_pen_\pgfkeysvalueof{/tikz/pen~name}_seq} \l_@@_tmpa_seq
+ \pgfusepath{discard}%
+ }
+ },
+ define~pen/.default={default},
+ use~pen/.code={
+ \tikzset{pen~name=#1}
+ \int_gzero:N \g_@@_path_component_int
+ \cs_set_eq:NN \pgfpathmoveto \cal_moveto:n
+ \tikz at addmode{
+ \pgfsyssoftpath at getcurrentpath\l_@@_tmpa_tl
+ \spath_components_to_seq:NV \l_@@_tmpa_seq \l_@@_tmpa_tl
+ \tl_if_exist:cTF {g_@@_pen_\pgfkeysvalueof{/tikz/pen~name}_seq}
+ {
+ \cal_path_create:Nc \l_@@_tmpa_seq {g_@@_pen_\pgfkeysvalueof{/tikz/pen~name}_seq}
+ }
+ {
+ \msg_warning:nnx { calligraphy } { undefined pen } { \pgfkeysvalueof{/tikz/pen~name} }
+ }
+ }
+ },
+ use~pen/.default={default},
+ pen~name/.initial={default},
+ copperplate/.style={pen~name=copperplate},
+ pen~colour/.initial={black},
+ weight/.is~choice,
+ weight/heavy/.style={
+ line~width=\pgfkeysvalueof{/tikz/heavy~line~width},
+ taper~width=\pgfkeysvalueof{/tikz/light~line~width},
+ },
+ weight/light/.style={
+ line~width=\pgfkeysvalueof{/tikz/light~line~width},
+ taper~width=0pt,
+ },
+ heavy/.style={
+ weight=heavy
+ },
+ light/.style={
+ weight=light
+ },
+ heavy~line~width/.initial=2pt,
+ light~line~width/.initial=1pt,
+ taper/.is~choice,
+ taper/.default=both,
+ taper/none/.style={
+ taper~start=false,
+ taper~end=false,
+ },
+ taper/both/.style={
+ taper~start=true,
+ taper~end=true,
+ },
+ taper/start/.style={
+ taper~start=true,
+ taper~end=false,
+ },
+ taper/end/.style={
+ taper~start=false,
+ taper~end=true,
+ },
+ taper~start/.code={
+ \tl_if_eq:nnTF {#1} {true}
+ {
+ \bool_set_true:N \l_@@_taper_start_bool
+ }
+ {
+ \bool_set_false:N \l_@@_taper_start_bool
+ }
+ },
+ taper~start/.default={true},
+ taper~end/.code={
+ \tl_if_eq:nnTF {#1} {true}
+ {
+ \bool_set_true:N \l_@@_taper_end_bool
+ }
+ {
+ \bool_set_false:N \l_@@_taper_end_bool
+ }
+ },
+ taper~end/.default={true},
+ taper~width/.code={\dim_set:Nn \l_@@_taper_width_dim {#1}},
+ nib~style/.code~2~args={
+ \tl_clear_new:c {l_@@_nib_style_#1}
+ \tl_set:cn {l_@@_nib_style_#1} {#2}
+ },
+ stroke~style/.code~2~args={
+ \tl_clear_new:c {l_@@_stroke_style_#1}
+ \tl_set:cn {l_@@_stroke_style_#1} {#2}
+ },
+ this~stroke~style/.code={
+ \tl_clear_new:c {l_@@_stroke_inline_style_ \int_use:N \g_@@_path_component_int}
+ \tl_set:cn {l_@@_stroke_inline_style_ \int_use:N \g_@@_path_component_int} {#1}
+ },
+ annotate/.style={
+ annotate~if,
+ annotate~reset,
+ annotation~style/.update~value={#1},
+ },
+ annotate~if/.default={true},
+ annotate~if/.code={
+ \tl_if_eq:nnTF {#1} {true}
+ {
+ \bool_set_true:N \l_@@_annotate_bool
+ }
+ {
+ \bool_set_false:N \l_@@_annotate_bool
+ }
+ },
+ annotate~reset/.code={
+ \int_gzero:N \g_@@_label_int
+ },
+ annotation~style/.initial={draw,->},
+ annotation~shift/.initial={(0,1ex)},
+ every~annotation~node/.initial={anchor=south~west},
+ annotation~node~style/.code~2~args={
+ \tl_clear_new:c {l_@@_annotation_style_ #1 _tl}
+ \tl_set:cn {l_@@_annotation_style_ #1 _tl}{#2}
+ },
+ tl~use:N/.code={
+ \exp_args:NV \pgfkeysalso #1
+ },
+ tl~use:c/.code={
+ \tl_if_exist:cT {#1}
+ {
+ \exp_args:Nv \pgfkeysalso {#1}
+ }
+ },
+ /handlers/.update~style/.code={
+ \tl_if_eq:nnF {#1} {\pgfkeysnovalue}
+ {
+ \pgfkeys{\pgfkeyscurrentpath/.code=\pgfkeysalso{#1}}
+ }
+ },
+ /handlers/.update~value/.code={
+ \tl_if_eq:nnF {#1} {\pgfkeysnovalue}
+ {
+ \pgfkeyssetvalue{\pgfkeyscurrentpath}{#1}
+ }
+ },
+}
+% \end{macrocode}
+%
+% Some wrappers around the TikZ keys.
+% \begin{macrocode}
+\NewDocumentCommand \pen { O{} }
+{
+ \path[define~ pen,every~ calligraphy~ pen/.try,#1]
+}
+
+\NewDocumentCommand \definepen { O{} }
+{
+ \tikz \path[define~ pen,every~ calligraphy~ pen/.try,#1]
+}
+
+\NewDocumentCommand \calligraphy { O{} }
+{
+ \path[use~ pen,every~ calligraphy/.try,#1]
+}
+% \end{macrocode}
+%
+% \subsection{The Path Creation}
+%
+% \begin{macro}[internal]{\cal_path_create:NN}
+% This is the main command for creating the calligraphic paths.
+% First argument is the given path
+% Second argument is the pen path
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \cal_path_create:NN #1#2
+{
+ \int_zero:N \l_@@_tmpa_int
+ \seq_map_inline:Nn #1
+ {
+ \int_compare:nT {\tl_count:n {##1} > 3}
+ {
+
+ \int_incr:N \l_@@_tmpa_int
+ \int_zero:N \l_@@_tmpb_int
+
+ \tl_set:Nn \l_@@_tmp_path_tl {##1}
+ \spath_open:N \l_@@_tmp_path_tl
+ \spath_reverse:NV \l_@@_tmp_rpath_tl \l_@@_tmp_path_tl
+
+ \seq_map_inline:Nn #2
+ {
+ \int_incr:N \l_@@_tmpb_int
+ \group_begin:
+ \pgfsys at beginscope
+ \cal_apply_style:c {l_@@_stroke_style_ \int_use:N \l_@@_tmpa_int}
+ \cal_apply_style:c {l_@@_stroke_inline_style_ \int_use:N \l_@@_tmpa_int}
+ \cal_apply_style:c {l_@@_nib_style_ \int_use:N \l_@@_tmpb_int}
+
+ \spath_initialpoint:Nn \l_@@_tmpa_tl {####1}
+ \tl_set_eq:NN \l_@@_tmp_patha_tl \l_@@_tmp_path_tl
+ \spath_translate:NV \l_@@_tmp_patha_tl \l_@@_tmpa_tl
+
+ \int_compare:nTF {\tl_count:n {####1} == 3}
+ {
+ \cal_at_least_three:N \l_@@_tmp_patha_tl
+ \spath_protocol_path:V \l_@@_tmp_patha_tl
+
+ \tikz at options
+ \dim_set:Nn \l_@@_line_width_dim {\pgflinewidth}
+ \cal_maybe_taper:N \l_@@_tmp_patha_tl
+ }
+ {
+ \spath_weld:Nn \l_@@_tmp_patha_tl {####1}
+ \spath_weld:NV \l_@@_tmp_patha_tl \l_@@_tmp_rpath_tl
+ \spath_reverse:Nn \l_@@_tmp_rpathb_tl {####1}
+ \spath_weld:NV \l_@@_tmp_patha_tl \l_@@_tmp_rpathb_tl
+
+ \tl_clear:N \l_@@_tmpa_tl
+ \tl_set:Nn \l_@@_tmpa_tl {fill=\pgfkeysvalueof{/tikz/pen~colour},draw=none}
+ \tl_if_exist:cT {l_@@_stroke_style_ \int_use:N \l_@@_tmpa_int}
+ {
+ \tl_put_right:Nv \l_@@_tmpa_tl {l_@@_stroke_style_ \int_use:N \l_@@_tmpa_int}
+ }
+ \tl_if_exist:cT {l_@@_stroke_inline_style_ \int_use:N \l_@@_tmpa_int}
+ {
+ \tl_put_right:Nn \l_@@_tmpa_tl {,}
+ \tl_put_right:Nv \l_@@_tmpa_tl {l_@@_stroke_inline_style_ \int_use:N \l_@@_tmpa_int}
+ }
+ \tl_if_exist:cT {l_@@_nib_style_ \int_use:N \l_@@_tmpb_int}
+ {
+ \tl_put_right:Nn \l_@@_tmpa_tl {,}
+ \tl_put_right:Nv \l_@@_tmpa_tl {l_@@_nib_style_ \int_use:N \l_@@_tmpb_int}
+ }
+ \spath_tikz_path:VV \l_@@_tmpa_tl \l_@@_tmp_patha_tl
+
+ }
+ \pgfsys at endscope
+ \group_end:
+ }
+
+ \bool_if:NT \l_@@_annotate_bool
+ {
+ \seq_get_right:NN #2 \l_@@_tmpa_tl
+ \spath_finalpoint:NV \l_@@_tmpa_tl \l_@@_tmpa_tl
+ \spath_translate:NV \l_@@_tmp_path_tl \l_@@_tmpa_tl
+ \tikz at scan@one at point\pgfutil at firstofone\pgfkeysvalueof{/tikz/annotation~shift}
+
+ \spath_translate:Nnn \l_@@_tmp_path_tl {\pgf at x} {\pgf at y}
+
+ \pgfkeysgetvalue{/tikz/annotation~style}{\l_@@_tmpa_tl}
+ \spath_tikz_path:VV \l_@@_tmpa_tl \l_@@_tmp_path_tl
+
+ \spath_finalpoint:NV \l_@@_tmpa_tl \l_@@_tmp_path_tl
+
+ \exp_last_unbraced:NV \pgfqpoint \l_@@_tmpa_tl
+ \begin{scope}[reset~ cm]
+ \node[every~annotation~node/.try,tl~use:c = {l_@@_annotation_style_ \int_use:N \l_@@_tmpa_int _tl}] at (\pgf at x,\pgf at y) {\int_use:N \l_@@_tmpa_int};
+ \end{scope}
+ }
+ }
+ }
+}
+\cs_generate_variant:Nn \cal_path_create:NN {Nc}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\cal_moveto:n}
+% When creating the path, we need to keep track of the number of components so that we can apply styles accordingly.
+% \begin{macrocode}
+\cs_new_eq:NN \cal_orig_moveto:n \pgfpathmoveto
+\cs_new_nopar:Npn \cal_moveto:n #1
+{
+ \int_gincr:N \g_@@_path_component_int
+ \cal_orig_moveto:n {#1}
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\cal_apply_style:N}
+% Interface for applying \Verb+\tikzset+ to a token list.
+% \begin{macrocode}
+\cs_new_nopar:Npn \cal_apply_style:N #1
+{
+ \tl_if_exist:NT #1 {
+ \exp_args:NV \tikzset #1
+ }
+}
+\cs_generate_variant:Nn \cal_apply_style:N {c}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\cal_at_least_three:Nn}
+% A tapered path has to have at least three components.
+% This figures out if it is necessary and sets up the splitting.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \cal_at_least_three:Nn #1#2
+{
+ \spath_reallength:Nn \l_@@_tmpa_int {#2}
+ \tl_clear:N \l_@@_tmpb_tl
+ \tl_set:Nn \l_@@_tmpb_tl {#2}
+ \int_compare:nTF {\l_@@_tmpa_int = 1}
+ {
+ \spath_split_at:Nn \l_@@_tmpb_tl {2/3}
+ \spath_split_at:Nn \l_@@_tmpb_tl {1/2}
+ }
+ {
+ \int_compare:nT {\l_@@_tmpa_int = 2}
+ {
+ \spath_split_at:Nn \l_@@_tmpb_tl {1.5}
+ \spath_split_at:Nn \l_@@_tmpb_tl {.5}
+ }
+ }
+ \tl_set_eq:NN #1 \l_@@_tmpb_tl
+}
+\cs_generate_variant:Nn \cal_at_least_three:Nn {NV}
+\cs_new_protected_nopar:Npn \cal_at_least_three:N #1
+{
+ \cal_at_least_three:NV #1#1
+}
+\cs_generate_variant:Nn \cal_at_least_three:N {c}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\cal_maybe_taper:N}
+% Possibly tapers the path, depending on the booleans.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \cal_maybe_taper:N #1
+{
+ \tl_set_eq:NN \l_@@_tmpa_tl #1
+
+ \bool_if:NT \l_@@_taper_start_bool
+ {
+
+ \dim_set:Nn \l_@@_tmpa_dim {\tl_item:Nn \l_@@_tmpa_tl {2}}
+ \dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpa_tl {3}}
+ \tl_set:Nx \l_@@_tmpb_tl {\tl_item:Nn \l_@@_tmpa_tl {4}}
+
+ \tl_case:NnF \l_@@_tmpb_tl
+ {
+ \c_spath_lineto_tl
+ {
+
+ \bool_set_true:N \l_@@_taperable_bool
+ \dim_set:Nn \l_@@_tmpg_dim {\tl_item:Nn \l_@@_tmpa_tl {5}}
+ \dim_set:Nn \l_@@_tmph_dim {\tl_item:Nn \l_@@_tmpa_tl {6}}
+ \dim_set:Nn \l_@@_tmpc_dim {(2\l_@@_tmpa_dim + \l_@@_tmpg_dim)/3}
+ \dim_set:Nn \l_@@_tmpd_dim {(2\l_@@_tmpb_dim + \l_@@_tmph_dim)/3}
+ \dim_set:Nn \l_@@_tmpe_dim {(\l_@@_tmpa_dim + 2\l_@@_tmpg_dim)/3}
+ \dim_set:Nn \l_@@_tmpf_dim {(\l_@@_tmpb_dim + 2\l_@@_tmph_dim)/3}
+ \prg_replicate:nn {4}
+ {
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ }
+ \tl_put_left:NV \l_@@_tmpa_tl \c_spath_moveto_tl
+ }
+ \c_spath_curvetoa_tl
+ {
+ \bool_set_true:N \l_@@_taperable_bool
+ \dim_set:Nn \l_@@_tmpc_dim {\tl_item:Nn \l_@@_tmpa_tl {5}}
+ \dim_set:Nn \l_@@_tmpd_dim {\tl_item:Nn \l_@@_tmpa_tl {6}}
+ \dim_set:Nn \l_@@_tmpe_dim {\tl_item:Nn \l_@@_tmpa_tl {8}}
+ \dim_set:Nn \l_@@_tmpf_dim {\tl_item:Nn \l_@@_tmpa_tl {9}}
+ \dim_set:Nn \l_@@_tmpg_dim {\tl_item:Nn \l_@@_tmpa_tl {11}}
+ \dim_set:Nn \l_@@_tmph_dim {\tl_item:Nn \l_@@_tmpa_tl {12}}
+ \prg_replicate:nn {10}
+ {
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ }
+ \tl_put_left:NV \l_@@_tmpa_tl \c_spath_moveto_tl
+ }
+ }
+ {
+ \bool_set_false:N \l_@@_taperable_bool
+ }
+
+ \bool_if:NT \l_@@_taperable_bool
+ {
+ \@@_taper_aux:
+ }
+
+ }
+
+ \bool_if:NT \l_@@_taper_end_bool
+ {
+
+ \dim_set:Nn \l_@@_tmpa_dim {\tl_item:Nn \l_@@_tmpa_tl {-2}}
+ \dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpa_tl {-1}}
+ \tl_set:Nx \l_@@_tmpb_tl {\tl_item:Nn \l_@@_tmpa_tl {-3}}
+
+ \tl_case:NnF \l_@@_tmpb_tl
+ {
+ \c_spath_lineto_tl
+ {
+
+ \bool_set_true:N \l_@@_taperable_bool
+ \dim_set:Nn \l_@@_tmpg_dim {\tl_item:Nn \l_@@_tmpa_tl {-5}}
+ \dim_set:Nn \l_@@_tmph_dim {\tl_item:Nn \l_@@_tmpa_tl {-4}}
+ \dim_set:Nn \l_@@_tmpc_dim {(2\l_@@_tmpa_dim + \l_@@_tmpg_dim)/3}
+ \dim_set:Nn \l_@@_tmpd_dim {(2\l_@@_tmpb_dim + \l_@@_tmph_dim)/3}
+ \dim_set:Nn \l_@@_tmpe_dim {(\l_@@_tmpa_dim + 2\l_@@_tmpg_dim)/3}
+ \dim_set:Nn \l_@@_tmpf_dim {(\l_@@_tmpb_dim + 2\l_@@_tmph_dim)/3}
+ \tl_reverse:N \l_@@_tmpa_tl
+ \prg_replicate:nn {3}
+ {
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ }
+ \tl_reverse:N \l_@@_tmpa_tl
+ }
+ \c_spath_curveto_tl
+ {
+ \bool_set_true:N \l_@@_taperable_bool
+ \dim_set:Nn \l_@@_tmpc_dim {\tl_item:Nn \l_@@_tmpa_tl {-5}}
+ \dim_set:Nn \l_@@_tmpd_dim {\tl_item:Nn \l_@@_tmpa_tl {-4}}
+ \dim_set:Nn \l_@@_tmpe_dim {\tl_item:Nn \l_@@_tmpa_tl {-8}}
+ \dim_set:Nn \l_@@_tmpf_dim {\tl_item:Nn \l_@@_tmpa_tl {-7}}
+ \dim_set:Nn \l_@@_tmpg_dim {\tl_item:Nn \l_@@_tmpa_tl {-11}}
+ \dim_set:Nn \l_@@_tmph_dim {\tl_item:Nn \l_@@_tmpa_tl {-10}}
+ \tl_reverse:N \l_@@_tmpa_tl
+ \prg_replicate:nn {9}
+ {
+ \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
+ }
+ \tl_reverse:N \l_@@_tmpa_tl
+ }
+ }
+ {
+ \bool_set_false:N \l_@@_taperable_bool
+ }
+
+ \bool_if:NT \l_@@_taperable_bool
+ {
+ \@@_taper_aux:
+ }
+
+ }
+
+ \pgfsyssoftpath at setcurrentpath\l_@@_tmpa_tl
+ \pgfsetstrokecolor{\pgfkeysvalueof{/tikz/pen~colour}}
+ \pgfusepath{stroke}
+
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\@@_taper_aux:}
+% Auxiliary macro to avoid unnecessary code duplication.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_taper_aux:
+{
+ \tl_clear:N \l_@@_tmpb_tl
+ \tl_put_right:NV \l_@@_tmpb_tl \c_spath_moveto_tl
+
+ \fp_set:Nn \l_@@_tmpa_fp
+ {
+ \l_@@_tmpd_dim - \l_@@_tmpb_dim
+ }
+ \fp_set:Nn \l_@@_tmpb_fp
+ {
+ \l_@@_tmpa_dim - \l_@@_tmpc_dim
+ }
+ \fp_set:Nn \l_@@_tmpe_fp
+ {
+ (\l_@@_tmpa_fp^2 + \l_@@_tmpb_fp^2)^.5
+ }
+
+ \fp_set:Nn \l_@@_tmpa_fp {.5*\l_@@_taper_width_dim * \l_@@_tmpa_fp / \l_@@_tmpe_fp}
+ \fp_set:Nn \l_@@_tmpb_fp {.5*\l_@@_taper_width_dim * \l_@@_tmpb_fp / \l_@@_tmpe_fp}
+
+ \fp_set:Nn \l_@@_tmpc_fp
+ {
+ \l_@@_tmph_dim - \l_@@_tmpf_dim
+ }
+ \fp_set:Nn \l_@@_tmpd_fp
+ {
+ \l_@@_tmpe_dim - \l_@@_tmpg_dim
+ }
+ \fp_set:Nn \l_@@_tmpe_fp
+ {
+ (\l_@@_tmpc_fp^2 + \l_@@_tmpd_fp^2)^.5
+ }
+
+ \fp_set:Nn \l_@@_tmpc_fp {.5*\l_@@_line_width_dim * \l_@@_tmpc_fp / \l_@@_tmpe_fp}
+ \fp_set:Nn \l_@@_tmpd_fp {.5*\l_@@_line_width_dim * \l_@@_tmpd_fp / \l_@@_tmpe_fp}
+
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\dim_eval:n { \fp_to_dim:N \l_@@_tmpa_fp + \l_@@_tmpa_dim}}
+ {\dim_eval:n { \fp_to_dim:N \l_@@_tmpb_fp + \l_@@_tmpb_dim}}
+ }
+
+ \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetoa_tl
+
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\dim_eval:n { \fp_to_dim:N \l_@@_tmpa_fp + \l_@@_tmpc_dim}}
+ {\dim_eval:n { \fp_to_dim:N \l_@@_tmpb_fp + \l_@@_tmpd_dim}}
+ }
+
+ \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetob_tl
+
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\dim_eval:n { \fp_to_dim:N \l_@@_tmpc_fp + \l_@@_tmpe_dim}}
+ {\dim_eval:n { \fp_to_dim:N \l_@@_tmpd_fp + \l_@@_tmpf_dim}}
+ }
+
+ \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curveto_tl
+
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\dim_eval:n { \fp_to_dim:N \l_@@_tmpc_fp + \l_@@_tmpg_dim}}
+ {\dim_eval:n { \fp_to_dim:N \l_@@_tmpd_fp + \l_@@_tmph_dim}}
+ }
+
+ \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetoa_tl
+
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\dim_eval:n { \fp_to_dim:N \l_@@_tmpc_fp + \l_@@_tmpg_dim - \fp_to_dim:n{ 1.32 * \l_@@_tmpd_fp}}}
+ {\dim_eval:n { \fp_to_dim:N \l_@@_tmpd_fp + \l_@@_tmph_dim + \fp_to_dim:n {1.32* \l_@@_tmpc_fp}}}
+ }
+
+ \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetob_tl
+
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpc_fp + \l_@@_tmpg_dim - \fp_to_dim:n {1.32 * \l_@@_tmpd_fp}}}
+ {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpd_fp + \l_@@_tmph_dim + \fp_to_dim:n {1.32 * \l_@@_tmpc_fp}}}
+ }
+
+ \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curveto_tl
+
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpc_fp + \l_@@_tmpg_dim}}
+ {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpd_fp + \l_@@_tmph_dim}}
+ }
+
+ \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetoa_tl
+
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpc_fp + \l_@@_tmpe_dim}}
+ {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpd_fp + \l_@@_tmpf_dim}}
+ }
+
+ \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetob_tl
+
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpa_fp + \l_@@_tmpc_dim}}
+ {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpb_fp + \l_@@_tmpd_dim}}
+ }
+
+ \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curveto_tl
+
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpa_fp + \l_@@_tmpa_dim}}
+ {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpb_fp + \l_@@_tmpb_dim}}
+ }
+
+ \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetoa_tl
+
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpa_fp + \l_@@_tmpa_dim + \fp_to_dim:n{ 1.32 * \l_@@_tmpb_fp}}}
+ {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpb_fp + \l_@@_tmpb_dim - \fp_to_dim:n {1.32* \l_@@_tmpa_fp}}}
+ }
+
+ \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetob_tl
+
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\dim_eval:n { \fp_to_dim:N \l_@@_tmpa_fp + \l_@@_tmpa_dim + \fp_to_dim:n {1.32 * \l_@@_tmpb_fp}}}
+ {\dim_eval:n { \fp_to_dim:N \l_@@_tmpb_fp + \l_@@_tmpb_dim - \fp_to_dim:n {1.32 * \l_@@_tmpa_fp}}}
+ }
+
+ \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curveto_tl
+
+ \tl_put_right:Nx \l_@@_tmpb_tl
+ {
+ {\dim_eval:n { \fp_to_dim:N \l_@@_tmpa_fp + \l_@@_tmpa_dim}}
+ {\dim_eval:n { \fp_to_dim:N \l_@@_tmpb_fp + \l_@@_tmpb_dim}}
+ }
+
+ \pgfsyssoftpath at setcurrentpath\l_@@_tmpb_tl
+ \pgfsetfillcolor{\pgfkeysvalueof{/tikz/pen~colour}}
+ \pgfusepath{fill}
+}
+% \end{macrocode}
+% \end{macro}
+%
+% Defines a copperplate pen.
+% \begin{macrocode}
+\tl_set:Nn \l_@@_tmpa_tl {\pgfsyssoftpath at movetotoken{0pt}{0pt}}
+\spath_components_to_seq:NV \l_@@_tmpa_seq \l_@@_tmpa_tl
+\seq_gclear_new:N \g_@@_pen_copperplate_seq
+\seq_gset_eq:NN \g_@@_pen_copperplate_seq \l_@@_tmpa_seq
+% \end{macrocode}
+%
+% \begin{macro}{\CopperplatePath}
+% This is used in the decorations section to convert a path to a copperplate path.
+% \begin{macrocode}
+\DeclareDocumentCommand \CopperplatePath { m }
+{
+ \spath_components_to_seq:NV \l_@@_tmpa_seq #1
+ \cal_path_create:NN \l_@@_tmpa_seq \g_@@_pen_copperplate_seq
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macrocode}
+\ExplSyntaxOff
+% \end{macrocode}
+%
+% \subsection{Decorations}
+%
+% If a decoration library is loaded we define some decorations that use the calligraphy library, specifically the copperplate pen with its tapering.
+%
+% First, a brace decoration.
+% \begin{macrocode}
+\expandafter\ifx\csname pgfdeclaredecoration\endcsname\relax
+\else
+\pgfdeclaredecoration{calligraphic brace}{brace}
+{
+ \state{brace}[width=+\pgfdecoratedremainingdistance,next state=final]
+ {
+ \pgfsyssoftpath at setcurrentpath{\pgfutil at empty}
+ \pgfpathmoveto{\pgfpointorigin}
+ \pgfpathcurveto
+ {\pgfqpoint{.15\pgfdecorationsegmentamplitude}{.3\pgfdecorationsegmentamplitude}}
+ {\pgfqpoint{.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
+ {\pgfqpoint{\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
+ {
+ \pgftransformxshift{+\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance}
+ \pgfpathlineto{\pgfqpoint{-\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
+ \pgfpathcurveto
+ {\pgfqpoint{-.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
+ {\pgfqpoint{-.15\pgfdecorationsegmentamplitude}{.7\pgfdecorationsegmentamplitude}}
+ {\pgfqpoint{0\pgfdecorationsegmentamplitude}{1\pgfdecorationsegmentamplitude}}
+ \pgfpathmoveto{\pgfqpoint{0\pgfdecorationsegmentamplitude}{1\pgfdecorationsegmentamplitude}}
+ \pgfpathcurveto
+ {\pgfqpoint{.15\pgfdecorationsegmentamplitude}{.7\pgfdecorationsegmentamplitude}}
+ {\pgfqpoint{.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
+ {\pgfqpoint{\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
+ }
+ {
+ \pgftransformxshift{+\pgfdecoratedremainingdistance}
+ \pgfpathlineto{\pgfqpoint{-\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
+ \pgfpathcurveto
+ {\pgfqpoint{-.5\pgfdecorationsegmentamplitude}{.5\pgfdecorationsegmentamplitude}}
+ {\pgfqpoint{-.15\pgfdecorationsegmentamplitude}{.3\pgfdecorationsegmentamplitude}}
+ {\pgfqpoint{0pt}{0pt}}
+ }
+ \tikzset{
+ taper width=.5\pgflinewidth,
+ taper
+ }%
+ \pgfsyssoftpath at getcurrentpath\cal at tmp@path
+ \CopperplatePath{\cal at tmp@path}
+ }
+ \state{final}{}
+}
+% \end{macrocode}
+%
+% The second is a straightened parenthesis (so that when very large it doesn't bow out too far).
+% \begin{macrocode}
+\pgfdeclaredecoration{calligraphic straight parenthesis}{brace}
+{
+ \state{brace}[width=+\pgfdecoratedremainingdistance,next state=final]
+ {
+ \pgfsyssoftpath at setcurrentpath{\pgfutil at empty}
+ \pgfpathmoveto{\pgfpointorigin}
+ \pgfpathcurveto
+ {\pgfqpoint{.76604\pgfdecorationsegmentamplitude}{.64279\pgfdecorationsegmentamplitude}}
+ {\pgfqpoint{2.3333\pgfdecorationsegmentamplitude}{\pgfdecorationsegmentamplitude}}
+ {\pgfqpoint{3.3333\pgfdecorationsegmentamplitude}{\pgfdecorationsegmentamplitude}}
+ {
+ \pgftransformxshift{+\pgfdecoratedremainingdistance}
+ \pgfpathlineto{\pgfqpoint{-3.3333\pgfdecorationsegmentamplitude}{\pgfdecorationsegmentamplitude}}
+ \pgfpathcurveto
+ {\pgfqpoint{-2.3333\pgfdecorationsegmentamplitude}{\pgfdecorationsegmentamplitude}}
+ {\pgfqpoint{-.76604\pgfdecorationsegmentamplitude}{.64279\pgfdecorationsegmentamplitude}}
+ {\pgfqpoint{0pt}{0pt}}
+ }
+ \tikzset{
+ taper width=.5\pgflinewidth,
+ taper
+ }%
+ \pgfsyssoftpath at getcurrentpath\cal at tmp@path
+ \CopperplatePath{\cal at tmp@path}
+ }
+ \state{final}{}%
+}
+% \end{macrocode}
+%
+% The third is a curved parenthesis.
+% \begin{macrocode}
+\pgfdeclaredecoration{calligraphic curved parenthesis}{brace}
+{
+ \state{brace}[width=+\pgfdecoratedremainingdistance,next state=final]
+ {
+ \pgfsyssoftpath at setcurrentpath{\pgfutil at empty}
+ \pgfpathmoveto{\pgfpointorigin}
+ \pgf at xa=\pgfdecoratedremainingdistance\relax
+ \advance\pgf at xa by -1.5890\pgfdecorationsegmentamplitude\relax
+ \edef\cgrphy at xa{\the\pgf at xa}
+ \pgfpathcurveto
+ {\pgfqpoint{1.5890\pgfdecorationsegmentamplitude}{1.3333\pgfdecorationsegmentamplitude}}
+ {\pgfqpoint{\cgrphy at xa}{1.3333\pgfdecorationsegmentamplitude}}
+ {\pgfqpoint{\pgfdecoratedremainingdistance}{0pt}}
+ \tikzset{
+ taper width=.5\pgflinewidth,
+ taper
+ }%
+ \pgfsyssoftpath at getcurrentpath\cal at tmp@path
+ \CopperplatePath{\cal at tmp@path}
+ }
+ \state{final}{}%
+}
+% \end{macrocode}
+% End the conditional for if pgfdecoration module is loaded
+% \begin{macrocode}
+\fi
+% \end{macrocode}
+% \iffalse
+%</calligraphy>
+% \fi
+%
+%
+% \iffalse
+%<*knots>
+% \fi
+%%
+% \section{Drawing Knots}
+%
+% \begin{macrocode}
+%<@@=knot>
+% \end{macrocode}
+%
+% \subsection{Initialisation}
+%
+% We load the \Verb+spath3+ library and the \Verb+intersections+ TikZ library.
+% Then we get going.
+% \begin{macrocode}
+\RequirePackage{spath3}
+\usetikzlibrary{intersections,spath3}
+
+\ExplSyntaxOn
+
+\tl_new:N \l_@@_tmpa_tl
+\tl_new:N \l_@@_tmpb_tl
+\tl_new:N \l_@@_tmpc_tl
+\tl_new:N \l_@@_tmpd_tl
+\tl_new:N \l_@@_tmpg_tl
+\tl_new:N \l_@@_redraws_tl
+\tl_new:N \l_@@_clip_width_tl
+\tl_new:N \l_@@_name_tl
+\tl_new:N \l_@@_node_tl
+\tl_new:N \l_@@_aux_tl
+\tl_new:N \l_@@_auxa_tl
+\tl_new:N \l_@@_prefix_tl
+
+\seq_new:N \l_@@_segments_seq
+
+\int_new:N \l_@@_tmpa_int
+\int_new:N \l_@@_strands_int
+\int_new:N \g_@@_intersections_int
+\int_new:N \g_@@_filaments_int
+\int_new:N \l_@@_component_start_int
+
+\fp_new:N \l_@@_tmpa_fp
+\fp_new:N \l_@@_tmpb_fp
+
+\dim_new:N \l_@@_tmpa_dim
+\dim_new:N \l_@@_tmpb_dim
+\dim_new:N \l_@@_tolerance_dim
+\dim_new:N \l_@@_clip_bg_radius_dim
+\dim_new:N \l_@@_clip_draw_radius_dim
+
+\bool_new:N \l_@@_draft_bool
+\bool_new:N \l_@@_ignore_ends_bool
+\bool_new:N \l_@@_self_intersections_bool
+\bool_new:N \l_@@_splits_bool
+\bool_new:N \l_@@_super_draft_bool
+
+\bool_new:N \l_@@_prepend_prev_bool
+\bool_new:N \l_@@_append_next_bool
+\bool_new:N \l_@@_skip_bool
+\bool_new:N \l_@@_save_bool
+
+\seq_new:N \g_@@_nodes_seq
+
+\bool_set_true:N \l_@@_ignore_ends_bool
+% \end{macrocode}
+%
+% Configuration is via TikZ keys and styles.
+% \begin{macrocode}
+\tikzset{
+ spath/prefix/knot/.style={
+ spath/set~ prefix=knot strand,
+ },
+ spath/suffix/knot/.style={
+ spath/set~ suffix={},
+ },
+ knot/.code={
+ \tl_if_eq:nnTF {#1} {none}
+ {
+ \tikz at addmode{\tikz at mode@doublefalse}
+ }
+ {
+ \tikz at addmode{\tikz at mode@doubletrue}
+ \tl_if_eq:nnTF {\pgfkeysnovalue} {#1}
+ {
+ \tikz at addoption{\pgfsetinnerstrokecolor{.}}
+ }
+ {
+ \pgfsetinnerstrokecolor{#1}
+ }
+ \tikz at addoption{
+ \pgfsetstrokecolor{knotbg}
+ }
+ \tl_set:Nn \tikz at double@setup{
+ \pgfsetinnerlinewidth{\pgflinewidth}
+ \pgfsetlinewidth{\dim_eval:n {\tl_use:N \l_@@_gap_tl \pgflinewidth}}
+ }
+ }
+ },
+ knot~ gap/.store~ in=\l_@@_gap_tl,
+ knot~ gap=3,
+ knot~ diagram/.is~family,
+ knot~ diagram/.unknown/.code={
+ \tl_set_eq:NN \l_@@_tmpa_tl \pgfkeyscurrentname
+ \pgfkeysalso{
+ /tikz/\l_@@_tmpa_tl=#1
+ }
+ },
+ background~ colour/.code={%
+ \colorlet{knotbg}{#1}%
+ },
+ background~ color/.code={%
+ \colorlet{knotbg}{#1}%
+ },
+ background~ colour=white,
+ knot~ diagram,
+ name/.store~ in=\l_@@_name_tl,
+ name={knot},
+ save~ intersections/.is~ choice,
+ save~ intersections/.default=true,
+ save~ intersections/true/.code={
+ \bool_set_true:N \l_@@_save_bool
+ },
+ save~ intersections/false/.code={
+ \bool_set_false:N \l_@@_save_bool
+ },
+ every~ strand/.style={draw},
+ ignore~ endpoint~ intersections/.code={
+ \tl_if_eq:nnTF {#1} {true}
+ {
+ \bool_set_true:N \l_@@_ignore_ends_bool
+ }
+ {
+ \bool_set_false:N \l_@@_ignore_ends_bool
+ }
+ },
+ ignore~ endpoint~ intersections/.default=true,
+ consider~ self~ intersections/.is~choice,
+ consider~ self~ intersections/true/.code={
+ \bool_set_true:N \l_@@_self_intersections_bool
+ \bool_set_true:N \l_@@_splits_bool
+ },
+ consider~ self~ intersections/false/.code={
+ \bool_set_false:N \l_@@_self_intersections_bool
+ \bool_set_false:N \l_@@_splits_bool
+ },
+ consider~ self~ intersections/no~ splits/.code={
+ \bool_set_true:N \l_@@_self_intersections_bool
+ \bool_set_false:N \l_@@_splits_bool
+ },
+ consider~ self~ intersections/.default={true},
+ clip~ radius/.code={
+ \dim_set:Nn \l_@@_clip_bg_radius_dim {#1}
+ \dim_set:Nn \l_@@_clip_draw_radius_dim {#1+2pt}
+ },
+ clip~ draw~ radius/.code={
+ \dim_set:Nn \l_@@_clip_draw_radius_dim {#1}
+ },
+ clip~ background~ radius/.code={
+ \dim_set:Nn \l_@@_clip_bg_radius_dim {#1}
+ },
+ clip~ radius=10pt,
+ end~ tolerance/.code={
+ \dim_set:Nn \l_@@_tolerance_dim {#1}
+ },
+ end~ tolerance=14pt,
+ clip/.style={
+ clip
+ },
+ background~ clip/.style={
+ clip
+ },
+ clip~ width/.code={
+ \tl_set:Nn \l_@@_clip_width_tl {#1}
+ },
+ clip~ width=3,
+ flip~ crossing/.code={%
+ \tl_clear_new:c {l_@@_crossing_#1}
+ \tl_set:cn {l_@@_crossing_#1} {x}
+ },
+ ignore~ crossing/.code={%
+ \tl_clear_new:c {l_@@_ignore_crossing_#1}
+ \tl_set:cn {l_@@_ignore_crossing_#1} {x}
+ },
+ draft~ mode/.is~ choice,
+ draft~ mode/off/.code={%
+ \bool_set_false:N \l_@@_draft_bool
+ \bool_set_false:N \l_@@_super_draft_bool
+ },
+ draft~ mode/crossings/.code={%
+ \bool_set_true:N \l_@@_draft_bool
+ \bool_set_false:N \l_@@_super_draft_bool
+ },
+ draft~ mode/strands/.code={%
+ \bool_set_true:N \l_@@_draft_bool
+ \bool_set_true:N \l_@@_super_draft_bool
+ },
+ draft/.is~ family,
+ draft,
+ crossing~ label/.style={
+ overlay,
+ fill=white,
+ fill~ opacity=.5,
+ text~ opacity=1,
+ text=blue,
+ pin~ edge={blue,<-}
+ },
+ strand~ label/.style={
+ overlay,
+ circle,
+ draw=purple,
+ fill=white,
+ fill~ opacity=.5,
+ text~ opacity=1,
+ text=purple,
+ inner~ sep=0pt
+ },
+}
+% \end{macrocode}
+%
+% Wrapper around \Verb+\tikzset+ for applying keys from a token list, checking for if the given token list exists.
+% \begin{macrocode}
+\cs_new_nopar:Npn \knot_apply_style:N #1
+{
+ \tl_if_exist:NT #1 {
+ \exp_args:NV \tikzset #1
+ }
+}
+\cs_generate_variant:Nn \knot_apply_style:N {c}
+% \end{macrocode}
+%
+%\begin{macro}[internal]{\flipcrossings}
+% The user can specify a comma separated list of crossings to flip.
+% \begin{macrocode}
+\NewDocumentCommand \flipcrossings {m}
+{
+ \tikzset{knot~ diagram/flip~ crossing/.list={#1}}%
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\strand}
+% This is how the user specifies a strand of the knot.
+% \begin{macrocode}
+\NewDocumentCommand \strand { O{} }
+{
+ \int_incr:N \l_@@_strands_int
+ \tl_clear_new:c {l_@@_options_strand \int_use:N \l_@@_strands_int}
+ \tl_set:cn {l_@@_options_strand \int_use:N \l_@@_strands_int} {#1}
+ \path[#1,spath/set~ name=knot,spath/save=\int_use:N \l_@@_strands_int]
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{knot}
+% This is the wrapper environment that calls the knot generation code.
+% \begin{macrocode}
+\NewDocumentEnvironment{knot} { O{} }
+{
+ \knot_initialise:n {#1}
+}
+{
+ \knot_render:
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\knot_initialise:n}
+% Set up some stuff before loading in the strands.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \knot_initialise:n #1
+{
+ \tikzset{knot~ diagram/.cd,every~ knot~ diagram/.try,#1}
+ \int_zero:N \l_@@_strands_int
+ \tl_clear:N \l_@@_redraws_tl
+ \seq_gclear:N \g_@@_nodes_seq
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\knot_render:}
+% This is the code that starts the work of rendering the knot.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \knot_render:
+{
+% \end{macrocode}
+% Start a scope and reset the transformation (since all transformations have already been taken into account when defining the strands).
+% \begin{macrocode}
+ \pgfscope
+ \pgftransformreset
+% \end{macrocode}
+% Loop through the strands drawing each one for the first time.
+% \begin{macrocode}
+ \int_step_function:nnnN {1} {1} {\l_@@_strands_int} \knot_draw_strand:n
+% \end{macrocode}
+% In super draft mode we don't do anything else.
+% \begin{macrocode}
+ \bool_if:NF \l_@@_super_draft_bool
+ {
+% \end{macrocode}
+% In draft mode we draw labels at the ends of the strands; this also handles splitting curves to avoid self-intersections of Bezier curves if that's requested.
+% \begin{macrocode}
+ \int_step_function:nnnN {1} {1} {\l_@@_strands_int} \knot_draw_labels:n
+% \end{macrocode}
+% If we're considering self intersections we need to split the strands into filaments.
+% \begin{macrocode}
+ \bool_if:NTF \l_@@_self_intersections_bool
+ {
+ \knot_split_strands:
+ \int_set_eq:NN \l_@@_tmpa_int \g_@@_filaments_int
+ \tl_set:Nn \l_@@_prefix_tl {filament}
+ }
+ {
+ \int_set_eq:NN \l_@@_tmpa_int \l_@@_strands_int
+ \tl_set:Nn \l_@@_prefix_tl {strand}
+ }
+% \end{macrocode}
+% Initialise the intersection count.
+% \begin{macrocode}
+ \int_gzero:N \g_@@_intersections_int
+% \end{macrocode}
+% If in draft mode we label the intersections, otherwise we just stick a coordinate at each one.
+% \begin{macrocode}
+ \tl_clear:N \l_@@_node_tl
+ \bool_if:NT \l_@@_draft_bool
+ {
+ \tl_set:Nn \l_@@_node_tl {
+ \exp_not:N \node[coordinate,
+ pin={[node~ contents={\int_use:N \g_@@_intersections_int},knot~ diagram/draft/crossing~ label, knot~ diagram/draft/crossing~ \int_use:N \g_@@_intersections_int \c_space_tl label/.try]
+ }]
+ }
+ }
+% \end{macrocode}
+% This double loop steps through the pieces (strands or filaments) and computes the intersections and does stuff with those.
+% \begin{macrocode}
+ \int_step_variable:nnnNn {1} {1} {\l_@@_tmpa_int - 1} \l_@@_tmpa_tl
+ {
+ \int_step_variable:nnnNn {\tl_use:N \l_@@_tmpa_tl + 1} {1} {\l_@@_tmpa_int} \l_@@_tmpb_tl
+ {
+ \knot_intersections:VV \l_@@_tmpa_tl \l_@@_tmpb_tl
+ }
+ }
+% \end{macrocode}
+% If any redraws were requested, do them here.
+% \begin{macrocode}
+ \tl_use:N \l_@@_redraws_tl
+% \end{macrocode}
+% Draw the crossing nodes
+% \begin{macrocode}
+ \seq_use:Nn \g_@@_nodes_seq {}
+ }
+% \end{macrocode}
+% Close the scope
+% \begin{macrocode}
+ \endpgfscope
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\knot_draw_strand:n}
+% This renders a strand using the options originally specified.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \knot_draw_strand:n #1
+{
+ \pgfscope
+ \group_begin:
+ \spath_bake_round:c {knot strand #1}
+ \tl_set:Nn \l_@@_tmpa_tl {knot~ diagram/every~ strand/.try,}
+ \tl_put_right:Nv \l_@@_tmpa_tl {l_@@_options_strand #1}
+ \tl_put_right:Nn \l_@@_tmpa_tl {,knot~ diagram/only~ when~ rendering/.try,only~ when~ rendering/.try}
+ \spath_tikz_path:Vv \l_@@_tmpa_tl {knot strand #1}
+ \group_end:
+ \endpgfscope
+}
+\cs_generate_variant:Nn \tl_put_right:Nn {Nv}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\knot_draw_labels:n}
+% Draw a label at each end of each strand, if in draft mode.
+% Also, if requested, split potentially self intersecting Bezier curves.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \knot_draw_labels:n #1
+{
+ \bool_if:NT \l_@@_draft_bool
+ {
+ \spath_finalpoint:Nv \l_@@_tmpb_tl {knot strand #1}
+ \dim_set:Nn \l_@@_tmpa_dim {\tl_item:Nn \l_@@_tmpb_tl {1}}
+ \dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpb_tl {2}}
+ \node[knot~ diagram/draft/strand~label] at (\l_@@_tmpa_dim,\l_@@_tmpb_dim) {#1};
+ \spath_initialpoint:Nv \l_@@_tmpb_tl {knot strand #1}
+ \dim_set:Nn \l_@@_tmpa_dim {\tl_item:Nn \l_@@_tmpb_tl {1}}
+ \dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpb_tl {2}}
+ \node[knot~ diagram/draft/strand~label] at (\l_@@_tmpa_dim,\l_@@_tmpb_dim) {#1};
+ }
+ \bool_if:nT {
+ \l_@@_self_intersections_bool
+ &&
+ \l_@@_splits_bool
+ }
+ {
+ \tl_clear:N \l_@@_tmpa_tl
+ \spath_segments_to_seq:Nv \l_@@_segments_seq {knot strand #1}
+ \seq_map_function:NN \l_@@_segments_seq \knot_split_self_intersects:N
+ \tl_set_eq:cN {knot strand #1} \l_@@_tmpa_tl
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\knot_split_self_intersects:N}
+% This is the macro that does the split.
+% Figuring out whether a Bezier cubic self intersects is apparently a difficult problem so we don't bother.
+% We compute a point such that if there is an intersection then it lies on either side of the point.
+% I don't recall where the formula came from!
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \knot_split_self_intersects:N #1
+{
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_item:nn {#1} {4}}
+ \tl_case:NnF \l_@@_tmpc_tl
+ {
+ \c_spath_curvetoa_tl
+ {
+ \fp_set:Nn \l_@@_tmpa_fp
+ {
+ (\tl_item:nn {#1} {3} - 3 * \tl_item:nn {#1} {6} + 3 * \tl_item:nn {#1} {9} - \tl_item:nn {#1} {12})
+ *
+ (3 * \tl_item:nn {#1} {8} - 3 * \tl_item:nn {#1} {11})
+ -
+ (\tl_item:nn {#1} {2} - 3 * \tl_item:nn {#1} {5} + 3 * \tl_item:nn {#1} {8} - \tl_item:nn {#1} {11})
+ *
+ (3 * \tl_item:nn {#1} {9} - 3 * \tl_item:nn {#1} {12})
+ }
+ \fp_set:Nn \l_@@_tmpb_fp
+ {
+ (\tl_item:nn {#1} {2} - 3 * \tl_item:nn {#1} {5} + 3 * \tl_item:nn {#1} {8} - \tl_item:nn {#1} {11})
+ *
+ (3 * \tl_item:nn {#1} {6} - 6 * \tl_item:nn {#1} {9} + 3 * \tl_item:nn {#1} {12})
+ -
+ (\tl_item:nn {#1} {3} - 3 * \tl_item:nn {#1} {6} + 3 * \tl_item:nn {#1} {9} - \tl_item:nn {#1} {12})
+ *
+ (3 * \tl_item:nn {#1} {5} - 6 * \tl_item:nn {#1} {8} + 3 * \tl_item:nn {#1} {11})
+ }
+ \fp_compare:nTF
+ {
+ \l_@@_tmpb_fp != 0
+ }
+ {
+ \fp_set:Nn \l_@@_tmpa_fp {.5 * \l_@@_tmpa_fp / \l_@@_tmpb_fp}
+ \fp_compare:nTF
+ {
+ 0 < \l_@@_tmpa_fp && \l_@@_tmpa_fp < 1
+ }
+ {
+ \spath_split_curve:NNnV \l_@@_tmpc_tl \l_@@_tmpd_tl {#1} \l_@@_tmpa_fp
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
+ \tl_set:Nx \l_@@_tmpd_tl {\tl_tail:N \l_@@_tmpd_tl}
+ \tl_set:Nx \l_@@_tmpd_tl {\tl_tail:N \l_@@_tmpd_tl}
+ \tl_set:Nx \l_@@_tmpd_tl {\tl_tail:N \l_@@_tmpd_tl}
+ \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpc_tl
+ \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpd_tl
+ }
+ {
+ \tl_set:Nn \l_@@_tmpc_tl {#1}
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
+ \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpc_tl
+ }
+ }
+ {
+ \tl_set:Nn \l_@@_tmpc_tl {#1}
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
+ \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpc_tl
+ }
+ }
+ \c_spath_lineto_tl
+ {
+ \tl_set:Nn \l_@@_tmpc_tl {#1}
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
+ \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
+ \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpc_tl
+ }
+ }
+ {
+ \tl_put_right:Nn \l_@@_tmpa_tl {#1}
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\knot_intersections:nn}
+% This computes the intersections of two pieces and steps through them.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \knot_intersections:nn #1#2
+{
+ \group_begin:
+ \tl_set_eq:NN \l_@@_tmpa_tl \l_@@_prefix_tl
+ \tl_put_right:Nn \l_@@_tmpa_tl {#1}
+ \tl_set_eq:NN \l_@@_tmpb_tl \l_@@_prefix_tl
+ \tl_put_right:Nn \l_@@_tmpb_tl {#2}
+ \tl_set_eq:Nc \l_@@_tmpc_tl {knot \tl_use:N \l_@@_tmpa_tl}
+ \tl_set_eq:Nc \l_@@_tmpd_tl {knot \tl_use:N \l_@@_tmpb_tl}
+
+ \bool_if:nTF {
+ \l_@@_save_bool
+ &&
+ \tl_if_exist_p:c {knot~ intersections~ \tl_use:N \l_@@_name_tl - \tl_use:N \l_@@_tmpa_tl - \tl_use:N \l_@@_tmpb_tl}
+ }
+ {
+ \tl_use:c {knot~ intersections~ \tl_use:N \l_@@_name_tl - \tl_use:N \l_@@_tmpa_tl - \tl_use:N \l_@@_tmpb_tl}
+ }
+ {
+\pgfintersectionofpaths{\pgfsetpath\l_@@_tmpc_tl}{\pgfsetpath\l_@@_tmpd_tl}
+
+ }
+
+ \int_compare:nT {\pgfintersectionsolutions > 0}
+ {
+ \int_step_function:nnnN {1} {1} {\pgfintersectionsolutions} \knot_do_intersection:n
+ }
+
+ \knot_save_intersections:VV \l_@@_tmpa_tl \l_@@_tmpb_tl
+ \group_end:
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\knot_save_intersections:nn}
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \knot_save_intersections:nn #1#2
+{
+ \bool_if:NT \l_@@_save_bool
+ {
+ \tl_clear:N \l_@@_aux_tl
+ \tl_put_right:Nn \l_@@_aux_tl
+ {
+ \def\pgfintersectionsolutions
+ }
+ \tl_put_right:Nx \l_@@_aux_tl
+ {
+ {\int_eval:n {\pgfintersectionsolutions}}
+ }
+ \int_compare:nT {\pgfintersectionsolutions > 0}
+ {
+ \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions}
+ {
+ \pgfpointintersectionsolution{##1}
+ \dim_set:Nn \l_@@_tmpa_dim {\pgf at x}
+ \dim_set:Nn \l_@@_tmpb_dim {\pgf at y}
+ \tl_put_right:Nn \l_@@_aux_tl
+ {
+ \expandafter\def\csname pgfpoint at intersect@solution@##1\endcsname
+ }
+ \tl_put_right:Nx \l_@@_aux_tl
+ {
+ {\exp_not:N \pgf at x=\dim_use:N \l_@@_tmpa_dim\exp_not:N\relax\exp_not:N \pgf at y =\dim_use:N \l_@@_tmpb_dim\relax}
+ }
+ }
+ \tl_set:Nn \l_@@_auxa_tl {\expandafter \gdef \csname knot~ intersections~}
+ \tl_put_right:Nx \l_@@_auxa_tl {\tl_use:N \l_@@_name_tl - #1 - #2}
+ \tl_put_right:Nn \l_@@_auxa_tl {\endcsname}
+ \tl_put_right:Nx \l_@@_auxa_tl {{\tl_to_str:N \l_@@_aux_tl}}
+ \protected at write\@auxout{}{\tl_to_str:N \l_@@_auxa_tl}
+ }
+ }
+}
+\cs_generate_variant:Nn \knot_save_intersections:nn {VV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\knot_do_intersection:n}
+% This handles a specific intersection.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \knot_do_intersection:n #1
+{
+% \end{macrocode}
+% Get the intersection coordinates.
+% \begin{macrocode}
+ \pgfpointintersectionsolution{#1}
+ \dim_set:Nn \l_@@_tmpa_dim {\pgf at x}
+ \dim_set:Nn \l_@@_tmpb_dim {\pgf at y}
+% \end{macrocode}
+% If we're dealing with filaments, we can get false positives from the end points.
+% \begin{macrocode}
+ \bool_set_false:N \l_@@_skip_bool
+ \bool_if:NT \l_@@_self_intersections_bool
+ {
+% \end{macrocode}
+% If one filament preceded the other, test for the intersection being at the relevant end point.
+% \begin{macrocode}
+ \tl_set:Nn \l_@@_tmpc_tl {knot previous}
+ \tl_put_right:NV \l_@@_tmpc_tl \l_@@_tmpa_tl
+ \tl_set:Nv \l_@@_tmpc_tl \l_@@_tmpc_tl
+ \tl_if_eq:NNT \l_@@_tmpc_tl \l_@@_tmpb_tl
+ {
+ \knot_test_endpoint:VnT \l_@@_tmpb_tl {final point}
+ {
+ \bool_set_true:N \l_@@_skip_bool
+ }
+ }
+
+ \tl_set:Nn \l_@@_tmpc_tl {knot previous}
+ \tl_put_right:NV \l_@@_tmpc_tl \l_@@_tmpb_tl
+ \tl_set:Nv \l_@@_tmpc_tl \l_@@_tmpc_tl
+ \tl_if_eq:NNT \l_@@_tmpc_tl \l_@@_tmpa_tl
+ {
+ \knot_test_endpoint:VnT \l_@@_tmpa_tl {final point}
+ {
+ \bool_set_true:N \l_@@_skip_bool
+ }
+ }
+ }
+% \end{macrocode}
+% The user can also say that end points of filaments (or strands) should simply be ignored anyway.
+% \begin{macrocode}
+ \bool_if:NT \l_@@_ignore_ends_bool
+ {
+ \knot_test_endpoint:VnT \l_@@_tmpa_tl {initial point}
+ {
+ \bool_set_true:N \l_@@_skip_bool
+ }
+ \knot_test_endpoint:VnT \l_@@_tmpa_tl {final point}
+ {
+ \bool_set_true:N \l_@@_skip_bool
+ }
+ \knot_test_endpoint:VnT \l_@@_tmpb_tl {initial point}
+ {
+ \bool_set_true:N \l_@@_skip_bool
+ }
+ \knot_test_endpoint:VnT \l_@@_tmpb_tl {final point}
+ {
+ \bool_set_true:N \l_@@_skip_bool
+ }
+ }
+% \end{macrocode}
+% Assuming that we passed all the above tests, we render the crossing.
+% \begin{macrocode}
+ \bool_if:NF \l_@@_skip_bool
+ {
+
+ \int_gincr:N \g_@@_intersections_int
+% \end{macrocode}
+% This is the intersection test.
+% If the intersection finder finds too many, it might be useful to ignore some.
+% \begin{macrocode}
+ \bool_if:nF
+ {
+ \tl_if_exist_p:c {l_@@_ignore_crossing_ \int_use:N
+ \g_@@_intersections_int}
+ &&
+ ! \tl_if_empty_p:c {l_@@_ignore_crossing_ \int_use:N
+ \g_@@_intersections_int}
+ }
+ {
+% \end{macrocode}
+% This is the flip test.
+% We only render one of the paths.
+% The ``flip'' swaps which one we render.
+% \begin{macrocode}
+ \bool_if:nTF
+ {
+ \tl_if_exist_p:c {l_@@_crossing_ \int_use:N
+ \g_@@_intersections_int}
+ &&
+ ! \tl_if_empty_p:c {l_@@_crossing_ \int_use:N
+ \g_@@_intersections_int}
+ }
+ {
+ \tl_set_eq:NN \l_@@_tmpg_tl \l_@@_tmpb_tl
+ }
+ {
+ \tl_set_eq:NN \l_@@_tmpg_tl \l_@@_tmpa_tl
+ }
+% \end{macrocode}
+% Now we know which one we're rendering, we test to see if we should also render its predecessor or successor to ensure that we render a path through the entire crossing region.
+% \begin{macrocode}
+ \bool_if:NT \l_@@_self_intersections_bool
+ {
+ \knot_test_endpoint:VnT \l_@@_tmpg_tl {initial point}
+ {
+ \bool_set_true:N \l_@@_prepend_prev_bool
+ }
+ {
+ \bool_set_false:N \l_@@_prepend_prev_bool
+ }
+ \knot_test_endpoint:VnT \l_@@_tmpg_tl {final point}
+ {
+ \bool_set_true:N \l_@@_append_next_bool
+ }
+ {
+ \bool_set_false:N \l_@@_append_next_bool
+ }
+% \end{macrocode}
+% If either of those tests succeeded, do the appending or prepending.
+% \begin{macrocode}
+ \bool_if:nT
+ {
+ \l_@@_prepend_prev_bool || \l_@@_append_next_bool
+ }
+ {
+ \tl_clear_new:c {knot \tl_use:N \l_@@_prefix_tl -1}
+ \tl_set_eq:cc {knot \tl_use:N \l_@@_prefix_tl -1} {knot \tl_use:N \l_@@_tmpg_tl}
+
+ \tl_clear_new:c {l_@@_options_ \tl_use:N \l_@@_prefix_tl -1}
+ \tl_set_eq:cc {l_@@_options_ \tl_use:N \l_@@_prefix_tl -1} {l_@@_options_ \tl_use:N \l_@@_tmpg_tl}
+
+ \bool_if:nT
+ {
+ \l_@@_prepend_prev_bool
+ &&
+ \tl_if_exist_p:c {knot previous \tl_use:N \l_@@_tmpg_tl}
+ &&
+ !\tl_if_empty_p:c {knot previous \tl_use:N \l_@@_tmpg_tl}
+ }
+ {
+ \spath_prepend_no_move:cv {knot \tl_use:N \l_@@_prefix_tl -1} {knot \tl_use:c {knot previous \tl_use:N \l_@@_tmpg_tl}}
+% \end{macrocode}
+% If we split potentially self intersecting curves, we test to see if we should prepend yet another segment.
+% \begin{macrocode}
+ \bool_if:nT
+ {
+ \l_@@_splits_bool
+ &&
+ \tl_if_exist_p:c {knot previous \tl_use:N \l_@@_tmpg_tl}
+ &&
+ !\tl_if_empty_p:c {knot previous \tl_use:N \l_@@_tmpg_tl}
+ }
+ {
+ \knot_test_endpoint:vnT {knot previous \tl_use:N \l_@@_tmpg_tl} {initial point}
+ {
+
+ \spath_prepend_no_move:cv {knot \tl_use:N \l_@@_prefix_tl -1} {knot \tl_use:c {knot previous \tl_use:c {knot previous \tl_use:N \l_@@_tmpg_tl}}}
+ \tl_set_eq:Nc \l_@@_tmpa_tl {knot \tl_use:N \l_@@_prefix_tl -1}
+ }
+ }
+ }
+% \end{macrocode}
+% Now the same for appending.
+% \begin{macrocode}
+ \bool_if:nT
+ {
+ \l_@@_append_next_bool
+ &&
+ \tl_if_exist_p:c {knot next \tl_use:N \l_@@_tmpg_tl}
+ &&
+ !\tl_if_empty_p:c {knot previous \tl_use:N \l_@@_tmpg_tl}
+ }
+ {
+ \spath_append_no_move:cv {knot \tl_use:N \l_@@_prefix_tl -1} {knot \tl_use:c {knot next \tl_use:N \l_@@_tmpg_tl}}
+ \bool_if:nT
+ {
+ \l_@@_splits_bool
+ &&
+ \tl_if_exist_p:c {knot previous \tl_use:N
+ \l_@@_tmpg_tl}
+ &&
+ !\tl_if_empty_p:c {knot previous \tl_use:N \l_@@_tmpg_tl}
+ }
+ {
+ \knot_test_endpoint:vnT {knot previous \tl_use:N \l_@@_tmpg_tl} {final point}
+ {
+ \spath_append_no_move:cv {knot \tl_use:N \l_@@_prefix_tl -1} {knot \tl_use:c {knot next \tl_use:c {knot next \tl_use:N \l_@@_tmpg_tl}}}
+
+ }
+ }
+ }
+
+ \tl_set:Nn \l_@@_tmpg_tl {\tl_use:N \l_@@_prefix_tl -1}
+ }
+ }
+% \end{macrocode}
+% Now we render the crossing.
+% \begin{macrocode}
+ \pgfscope
+ \group_begin:
+ \tikzset{knot~ diagram/every~ intersection/.try, every~ intersection/.try, knot~ diagram/intersection~ \int_use:N \g_@@_intersections_int/.try}
+ \knot_draw_crossing:VVV \l_@@_tmpg_tl \l_@@_tmpa_dim \l_@@_tmpb_dim
+ \coordinate (\l_@@_name_tl \c_space_tl \int_use:N \g_@@_intersections_int) at (\dim_use:N \l_@@_tmpa_dim, \dim_use:N \l_@@_tmpb_dim);
+ \group_end:
+ \endpgfscope
+% \end{macrocode}
+% This ends the boolean as to whether to consider the intersection at all
+% \begin{macrocode}
+ }
+% \end{macrocode}
+% And possibly stick a coordinate with a label at the crossing.
+% \begin{macrocode}
+ \tl_if_empty:NF \l_@@_node_tl
+ {
+ \seq_gpush:Nx \g_@@_nodes_seq { \l_@@_node_tl at (\dim_use:N \l_@@_tmpa_dim, \dim_use:N \l_@@_tmpb_dim) {};}
+ }
+ }
+}
+
+\cs_generate_variant:Nn \knot_intersections:nn {VV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\knot_test_endpoint:N}
+% Test whether the point is near the intersection point.
+% \begin{macrocode}
+\prg_new_conditional:Npnn \knot_test_endpoint:N #1 {p,T,F,TF}
+{
+ \dim_compare:nTF
+ {
+ \dim_abs:n { \l_@@_tmpa_dim - \tl_item:Nn #1 {1}}
+ +
+ \dim_abs:n { \l_@@_tmpb_dim - \tl_item:Nn #1 {2}}
+ <
+ \l_@@_tolerance_dim
+ }
+ {
+ \prg_return_true:
+ }
+ {
+ \prg_return_false:
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\knot_test_endpoint:nn}
+% Wrapper around the above.
+% \begin{macrocode}
+\prg_new_protected_conditional:Npnn \knot_test_endpoint:nn #1#2 {T,F,TF}
+{
+ \use:c {spath_#2:Nv} \l_@@_tmpd_tl {knot #1}
+ \knot_test_endpoint:NTF \l_@@_tmpd_tl
+ {
+ \prg_return_true:
+ }
+ {
+ \prg_return_false:
+ }
+}
+
+\cs_generate_variant:Nn \knot_test_endpoint:nnT {VnT,vnT}
+\cs_generate_variant:Nn \knot_test_endpoint:nnF {VnF,vnF}
+\cs_generate_variant:Nn \knot_test_endpoint:nnTF {VnTF,vnTF}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\knot_draw_crossing:nnn}
+% This is the code that actually renders a crossing.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \knot_draw_crossing:nnn #1#2#3
+{
+ \group_begin:
+ \pgfscope
+ \path[knot~ diagram/background~ clip] (#2, #3) circle[radius=\l_@@_clip_bg_radius_dim];
+
+ \tl_set:Nn \l_@@_tmpa_tl {knot~ diagram/every~ strand/.try,}
+ \tl_if_exist:cT {l_@@_options_ #1}
+ {
+ \tl_put_right:Nv \l_@@_tmpa_tl {l_@@_options_ #1}
+ }
+ \tl_put_right:Nn \l_@@_tmpa_tl {,knotbg,line~ width= \tl_use:N \l_@@_clip_width_tl * \pgflinewidth}
+ \spath_tikz_path:Vv \l_@@_tmpa_tl {knot #1}
+
+ \endpgfscope
+
+ \pgfscope
+ \path[knot~ diagram/clip] (#2, #3) circle[radius=\l_@@_clip_draw_radius_dim];
+
+ \tl_set:Nn \l_@@_tmpa_tl {knot~ diagram/every~ strand/.try,}
+ \tl_if_exist:cT {l_@@_options_ #1}
+ {
+ \tl_put_right:Nv \l_@@_tmpa_tl {l_@@_options_ #1}
+ }
+ \tl_put_right:Nn \l_@@_tmpa_tl {,knot~ diagram/only~ when~ rendering/.try,only~ when~ rendering/.try}
+ \spath_tikz_path:Vv \l_@@_tmpa_tl {knot #1}
+
+ \endpgfscope
+ \group_end:
+}
+
+\cs_generate_variant:Nn \knot_draw_crossing:nnn {nVV, VVV}
+
+\cs_new_protected_nopar:Npn \knot_draw_crossing:nn #1#2
+{
+ \tikz at scan@one at point\pgfutil at firstofone #2 \relax
+ \knot_draw_crossing:nVV {#1} \pgf at x \pgf at y
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\knot_split_strands:}
+% This, and the following macros, are for splitting strands into filaments.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \knot_split_strands:
+{
+ \int_gzero:N \g_@@_filaments_int
+ \int_step_function:nnnN {1} {1} {\l_@@_strands_int} \knot_split_strand:n
+ \int_step_function:nnnN {1} {1} {\g_@@_filaments_int} \knot_compute_nexts:n
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\knot_compute_nexts:n}
+% Each filament needs to know its predecessor and successor.
+% We work out the predecessors as we go along, this fills in the successors.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \knot_compute_nexts:n #1
+{
+ \tl_clear_new:c {knot next \tl_use:c {knot previous filament #1}}
+ \tl_set:cn {knot next \tl_use:c {knot previous filament #1}} {filament #1}
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\knot_split_strand:n}
+% Sets up the split for a single strand.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \knot_split_strand:n #1
+{
+ \int_set_eq:NN \l_@@_component_start_int \g_@@_filaments_int
+ \int_incr:N \l_@@_component_start_int
+ \tl_set_eq:Nc \l_@@_tmpa_tl {l_@@_options_strand #1}
+ \spath_segments_to_seq:Nv \l_@@_segments_seq {knot strand #1}
+ \seq_map_function:NN \l_@@_segments_seq \knot_save_filament:N
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\knot_save_filament:N}
+% Saves a filament as a new \Verb+spath+ object.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \knot_save_filament:N #1
+{
+ \tl_set:Nx \l_@@_tmpb_tl {\tl_item:nn {#1} {4}}
+ \tl_case:NnF \l_@@_tmpb_tl
+ {
+ \c_spath_moveto_tl
+ {
+ \int_compare:nT {\l_@@_component_start_int < \g_@@_filaments_int}
+ {
+ \int_set_eq:NN \l_@@_component_start_int \g_@@_filaments_int
+ }
+ }
+ \c_spath_lineto_tl
+ {
+ \int_gincr:N \g_@@_filaments_int
+ \tl_clear_new:c {knot filament \int_use:N \g_@@_filaments_int}
+ \tl_set:cn {knot filament \int_use:N \g_@@_filaments_int} {#1}
+
+ \tl_clear_new:c {l_@@_options_filament \int_use:N \g_@@_filaments_int}
+ \tl_set_eq:cN {l_@@_options_filament \int_use:N \g_@@_filaments_int} \l_@@_tmpa_tl
+
+ \tl_clear_new:c {knot previous filament \int_use:N \g_@@_filaments_int}
+ \int_compare:nF {\l_@@_component_start_int == \g_@@_filaments_int}
+ {
+ \tl_set:cx {knot previous filament \int_use:N \g_@@_filaments_int} {filament \int_eval:n {\g_@@_filaments_int - 1}}
+ }
+ }
+ \c_spath_curvetoa_tl
+ {
+ \int_gincr:N \g_@@_filaments_int
+ \tl_clear_new:c {knot filament \int_use:N \g_@@_filaments_int}
+ \tl_set:cn {knot filament \int_use:N \g_@@_filaments_int} {#1}
+ \tl_clear_new:c {l_@@_options_filament \int_use:N \g_@@_filaments_int}
+ \tl_set_eq:cN {l_@@_options_filament \int_use:N \g_@@_filaments_int} \l_@@_tmpa_tl
+
+ \tl_clear_new:c {knot previous filament \int_use:N \g_@@_filaments_int}
+ \int_compare:nF {\l_@@_component_start_int == \g_@@_filaments_int}
+ {
+ \tl_set:cx {knot previous filament \int_use:N \g_@@_filaments_int} {filament \int_eval:n {\g_@@_filaments_int - 1}}
+ }
+ }
+ \c_spath_closepath_tl
+ {
+ \int_gincr:N \g_@@_filaments_int
+ \tl_clear_new:c {knot filament \int_use:N \g_@@_filaments_int}
+ \tl_clear:N \l_@@_tmpa_tl
+ \tl_put_right:Nx {\tl_item:nn {#1} {1}\tl_item:nn {#1} {2}\tl_item:nn {#1} {3}}
+ \tl_put_right:NV \l_@@_tmpa_tl \c_spath_lineto_tl
+ \tl_put_right:Nx {\tl_item:nn {#1} {5}\tl_item:nn {#1} {6}}
+
+ \tl_set:cV {knot filament \int_use:N \g_@@_filaments_int} \l_@@_tmpa_tl
+ \tl_set_eq:cN {l_@@_options_filament \int_use:N \g_@@_filaments_int} \l_@@_tmpa_tl
+ \tl_clear_new:c {knot previous filament \int_use:N \g_@@_filaments_int}
+ \int_compare:nF {\l_@@_component_start_int == \g_@@_filaments_int}
+ {
+ \tl_set:cx {knot previous filament \int_use:N \g_@@_filaments_int} {filament \int_eval:n {\g_@@_filaments_int - 1}}
+ }
+ \tl_set:cx {knot previous filament \int_use:N \l_@@_component_start_int} {filament \int_use:N \g_@@_filaments_int}
+ }
+ }
+ {
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\redraw}
+% The user can redraw segments of the strands at specific locations.
+% \begin{macrocode}
+\NewDocumentCommand \redraw { m m }
+{
+% \tikz at scan@one at point\pgfutil at firstofone #2 \relax
+ \tl_put_right:Nn \l_@@_redraws_tl {\knot_draw_crossing:nn}
+ \tl_put_right:Nx \l_@@_redraws_tl {
+ {strand #1} {#2}% {\dim_use:N \pgf at x} {\dim_use:N \pgf at y}
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macrocode}
+\ExplSyntaxOff
+% \end{macrocode}
+%<@@=>
+%
+% \begin{macro}[internal]{\pgf at sh@@knotanchor}
+% Add the extra anchors for the knot crossing nodes.
+% \begin{macrocode}
+\def\pgf at sh@@knotanchor#1#2{%
+ \anchor{#2 north west}{%
+ \csname pgf at anchor@knot #1 at north west\endcsname%
+ \pgf at x=#2\pgf at x%
+ \pgf at y=#2\pgf at y%
+ }%
+ \anchor{#2 north east}{%
+ \csname pgf at anchor@knot #1 at north east\endcsname%
+ \pgf at x=#2\pgf at x%
+ \pgf at y=#2\pgf at y%
+ }%
+ \anchor{#2 south west}{%
+ \csname pgf at anchor@knot #1 at south west\endcsname%
+ \pgf at x=#2\pgf at x%
+ \pgf at y=#2\pgf at y%
+ }%
+ \anchor{#2 south east}{%
+ \csname pgf at anchor@knot #1 at south east\endcsname%
+ \pgf at x=#2\pgf at x%
+ \pgf at y=#2\pgf at y%
+ }%
+ \anchor{#2 north}{%
+ \csname pgf at anchor@knot #1 at north\endcsname%
+ \pgf at x=#2\pgf at x%
+ \pgf at y=#2\pgf at y%
+ }%
+ \anchor{#2 east}{%
+ \csname pgf at anchor@knot #1 at east\endcsname%
+ \pgf at x=#2\pgf at x%
+ \pgf at y=#2\pgf at y%
+ }%
+ \anchor{#2 west}{%
+ \csname pgf at anchor@knot #1 at west\endcsname%
+ \pgf at x=#2\pgf at x%
+ \pgf at y=#2\pgf at y%
+ }%
+ \anchor{#2 south}{%
+ \csname pgf at anchor@knot #1 at south\endcsname%
+ \pgf at x=#2\pgf at x%
+ \pgf at y=#2\pgf at y%
+ }%
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{knot crossing}
+% \begin{macrocode}
+\pgfdeclareshape{knot crossing}
+{
+ \inheritsavedanchors[from=circle] % this is nearly a circle
+ \inheritanchorborder[from=circle]
+ \inheritanchor[from=circle]{north}
+ \inheritanchor[from=circle]{north west}
+ \inheritanchor[from=circle]{north east}
+ \inheritanchor[from=circle]{center}
+ \inheritanchor[from=circle]{west}
+ \inheritanchor[from=circle]{east}
+ \inheritanchor[from=circle]{mid}
+ \inheritanchor[from=circle]{mid west}
+ \inheritanchor[from=circle]{mid east}
+ \inheritanchor[from=circle]{base}
+ \inheritanchor[from=circle]{base west}
+ \inheritanchor[from=circle]{base east}
+ \inheritanchor[from=circle]{south}
+ \inheritanchor[from=circle]{south west}
+ \inheritanchor[from=circle]{south east}
+ \inheritanchorborder[from=circle]
+ \pgf at sh@@knotanchor{crossing}{2}
+ \pgf at sh@@knotanchor{crossing}{3}
+ \pgf at sh@@knotanchor{crossing}{4}
+ \pgf at sh@@knotanchor{crossing}{8}
+ \pgf at sh@@knotanchor{crossing}{16}
+ \pgf at sh@@knotanchor{crossing}{32}
+ \backgroundpath{
+ \pgfutil at tempdima=\radius%
+ \pgfmathsetlength{\pgf at xb}{\pgfkeysvalueof{/pgf/outer xsep}}%
+ \pgfmathsetlength{\pgf at yb}{\pgfkeysvalueof{/pgf/outer ysep}}%
+ \ifdim\pgf at xb<\pgf at yb%
+ \advance\pgfutil at tempdima by-\pgf at yb%
+ \else%
+ \advance\pgfutil at tempdima by-\pgf at xb%
+ \fi%
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{knot over cross}
+% \begin{macrocode}
+\pgfdeclareshape{knot over cross}
+{
+ \inheritsavedanchors[from=rectangle] % this is nearly a circle
+ \inheritanchorborder[from=rectangle]
+ \inheritanchor[from=rectangle]{north}
+ \inheritanchor[from=rectangle]{north west}
+ \inheritanchor[from=rectangle]{north east}
+ \inheritanchor[from=rectangle]{center}
+ \inheritanchor[from=rectangle]{west}
+ \inheritanchor[from=rectangle]{east}
+ \inheritanchor[from=rectangle]{mid}
+ \inheritanchor[from=rectangle]{mid west}
+ \inheritanchor[from=rectangle]{mid east}
+ \inheritanchor[from=rectangle]{base}
+ \inheritanchor[from=rectangle]{base west}
+ \inheritanchor[from=rectangle]{base east}
+ \inheritanchor[from=rectangle]{south}
+ \inheritanchor[from=rectangle]{south west}
+ \inheritanchor[from=rectangle]{south east}
+ \inheritanchorborder[from=rectangle]
+ \backgroundpath{
+ \southwest \pgf at xa=\pgf at x \pgf at ya=\pgf at y
+ \northeast \pgf at xb=\pgf at x \pgf at yb=\pgf at y
+ \pgfpathmoveto{\pgfqpoint{\pgf at xa}{\pgf at ya}}
+ \pgfpathlineto{\pgfqpoint{\pgf at xb}{\pgf at yb}}
+ }
+ \foregroundpath{
+% store lower right in xa/ya and upper right in xb/yb
+ \southwest \pgf at xa=\pgf at x \pgf at ya=\pgf at y
+ \northeast \pgf at xb=\pgf at x \pgf at yb=\pgf at y
+ \pgfpathmoveto{\pgfqpoint{\pgf at xa}{\pgf at yb}}
+ \pgfpathlineto{\pgfqpoint{\pgf at xb}{\pgf at ya}}
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{knot under cross}
+% \begin{macrocode}
+\pgfdeclareshape{knot under cross}
+{
+ \inheritsavedanchors[from=rectangle] % this is nearly a circle
+ \inheritanchorborder[from=rectangle]
+ \inheritanchor[from=rectangle]{north}
+ \inheritanchor[from=rectangle]{north west}
+ \inheritanchor[from=rectangle]{north east}
+ \inheritanchor[from=rectangle]{center}
+ \inheritanchor[from=rectangle]{west}
+ \inheritanchor[from=rectangle]{east}
+ \inheritanchor[from=rectangle]{mid}
+ \inheritanchor[from=rectangle]{mid west}
+ \inheritanchor[from=rectangle]{mid east}
+ \inheritanchor[from=rectangle]{base}
+ \inheritanchor[from=rectangle]{base west}
+ \inheritanchor[from=rectangle]{base east}
+ \inheritanchor[from=rectangle]{south}
+ \inheritanchor[from=rectangle]{south west}
+ \inheritanchor[from=rectangle]{south east}
+ \inheritanchorborder[from=rectangle]
+ \backgroundpath{
+ \southwest \pgf at xa=\pgf at x \pgf at ya=\pgf at y
+ \northeast \pgf at xb=\pgf at x \pgf at yb=\pgf at y
+ \pgfpathmoveto{\pgfqpoint{\pgf at xa}{\pgf at yb}}
+ \pgfpathlineto{\pgfqpoint{\pgf at xb}{\pgf at ya}}
+ }
+ \foregroundpath{
+% store lower right in xa/ya and upper right in xb/yb
+ \southwest \pgf at xa=\pgf at x \pgf at ya=\pgf at y
+ \northeast \pgf at xb=\pgf at x \pgf at yb=\pgf at y
+ \pgfpathmoveto{\pgfqpoint{\pgf at xa}{\pgf at ya}}
+ \pgfpathlineto{\pgfqpoint{\pgf at xb}{\pgf at yb}}
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{knot vert}
+% \begin{macrocode}
+\pgfdeclareshape{knot vert}
+{
+ \inheritsavedanchors[from=rectangle] % this is nearly a circle
+ \inheritanchorborder[from=rectangle]
+ \inheritanchor[from=rectangle]{north}
+ \inheritanchor[from=rectangle]{north west}
+ \inheritanchor[from=rectangle]{north east}
+ \inheritanchor[from=rectangle]{center}
+ \inheritanchor[from=rectangle]{west}
+ \inheritanchor[from=rectangle]{east}
+ \inheritanchor[from=rectangle]{mid}
+ \inheritanchor[from=rectangle]{mid west}
+ \inheritanchor[from=rectangle]{mid east}
+ \inheritanchor[from=rectangle]{base}
+ \inheritanchor[from=rectangle]{base west}
+ \inheritanchor[from=rectangle]{base east}
+ \inheritanchor[from=rectangle]{south}
+ \inheritanchor[from=rectangle]{south west}
+ \inheritanchor[from=rectangle]{south east}
+ \inheritanchorborder[from=rectangle]
+ \backgroundpath{
+% store lower right in xa/ya and upper right in xb/yb
+ \southwest \pgf at xa=\pgf at x \pgf at ya=\pgf at y
+ \northeast \pgf at xb=\pgf at x \pgf at yb=\pgf at y
+ \pgfpathmoveto{\pgfqpoint{\pgf at xa}{\pgf at ya}}
+ \pgfpathlineto{\pgfqpoint{\pgf at xa}{\pgf at yb}}
+ \pgfpathmoveto{\pgfqpoint{\pgf at xb}{\pgf at yb}}
+ \pgfpathlineto{\pgfqpoint{\pgf at xb}{\pgf at ya}}
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{knot horiz}
+% \begin{macrocode}
+\pgfdeclareshape{knot horiz}
+{
+ \inheritsavedanchors[from=rectangle] % this is nearly a circle
+ \inheritanchorborder[from=rectangle]
+ \inheritanchor[from=rectangle]{north}
+ \inheritanchor[from=rectangle]{north west}
+ \inheritanchor[from=rectangle]{north east}
+ \inheritanchor[from=rectangle]{center}
+ \inheritanchor[from=rectangle]{west}
+ \inheritanchor[from=rectangle]{east}
+ \inheritanchor[from=rectangle]{mid}
+ \inheritanchor[from=rectangle]{mid west}
+ \inheritanchor[from=rectangle]{mid east}
+ \inheritanchor[from=rectangle]{base}
+ \inheritanchor[from=rectangle]{base west}
+ \inheritanchor[from=rectangle]{base east}
+ \inheritanchor[from=rectangle]{south}
+ \inheritanchor[from=rectangle]{south west}
+ \inheritanchor[from=rectangle]{south east}
+ \inheritanchorborder[from=rectangle]
+ \foregroundpath{
+% store lower right in xa/ya and upper right in xb/yb
+ \southwest \pgf at xa=\pgf at x \pgf at ya=\pgf at y
+ \northeast \pgf at xb=\pgf at x \pgf at yb=\pgf at y
+ \pgfpathmoveto{\pgfqpoint{\pgf at xa}{\pgf at ya}}
+ \pgfpathlineto{\pgfqpoint{\pgf at xb}{\pgf at ya}}
+ \pgfpathmoveto{\pgfqpoint{\pgf at xa}{\pgf at yb}}
+ \pgfpathlineto{\pgfqpoint{\pgf at xb}{\pgf at yb}}
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \iffalse
+%</knots>
+% \fi
+%\Finale
+\endinput
Property changes on: trunk/Master/texmf-dist/source/latex/spath3/spath3_code.dtx
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/source/latex/spath3/spath3_code.ins
===================================================================
--- trunk/Master/texmf-dist/source/latex/spath3/spath3_code.ins (rev 0)
+++ trunk/Master/texmf-dist/source/latex/spath3/spath3_code.ins 2021-01-23 22:17:41 UTC (rev 57504)
@@ -0,0 +1,100 @@
+%%
+%% This is file `spath3_code.ins',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% spath3_code.dtx (with options: `install')
+%% ----------------------------------------------------------------
+%% spath3 --- Functions for manipulating PGF soft paths
+%% E-mail: loopspace at mathforge.org
+%% Released under the LaTeX Project Public License v1.3c or later
+%% See http://www.latex-project.org/lppl.txt
+%% ----------------------------------------------------------------
+%%
+\input l3docstrip.tex
+\keepsilent
+\askforoverwritefalse
+\preamble
+----------------------------------------------------------------
+spath3 --- Functions for manipulating PGF soft paths
+E-mail: loopspace at mathforge.org
+Released under the LaTeX Project Public License v1.3c or later
+See http://www.latex-project.org/lppl.txt
+----------------------------------------------------------------
+
+\endpreamble
+\postamble
+
+Copyright (C) 2011-2019 by Andrew Stacey <loopspace at mathforge.org>
+
+This work may be distributed and/or modified under the
+conditions of the LaTeX Project Public License (LPPL), either
+version 1.3c of this license or (at your option) any later
+version. The latest version of this license is in the file:
+
+http://www.latex-project.org/lppl.txt
+
+This work is "maintained" (as per LPPL maintenance status) by
+Andrew Stacey.
+
+This work consists of the files spath3.dtx
+ calligraphy_doc.tex
+ knots_doc.tex
+ spath3.tex
+and the derived files spath3.ins,
+ spath3_code.pdf,
+ spath3.sty,
+ tikzlibrarycalligraphy.code.tex
+ tikzlibraryknots.code.tex
+ tikzlibraryspath3.code.tex
+ calligraphy.pdf
+ knots.pdf
+ spath3.pdf
+ README
+
+\endpostamble
+\usedir{tex/latex/spath3}
+\generate{
+ \file{spath3.sty}{\from{\jobname.dtx}{spath3}}
+}
+\generate{
+ \file{tikzlibrarycalligraphy.code.tex}{\from{\jobname.dtx}{calligraphy}}
+}
+\generate{
+ \file{tikzlibraryknots.code.tex}{\from{\jobname.dtx}{knots}}
+}
+\generate{
+ \file{tikzlibraryspath3.code.tex}{\from{\jobname.dtx}{tikzspath3}}
+}
+\endbatchfile
+%%
+%% Copyright (C) 2011-2019 by Andrew Stacey <loopspace at mathforge.org>
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License (LPPL), either
+%% version 1.3c of this license or (at your option) any later
+%% version. The latest version of this license is in the file:
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This work is "maintained" (as per LPPL maintenance status) by
+%% Andrew Stacey.
+%%
+%% This work consists of the files spath3.dtx
+%% calligraphy_doc.tex
+%% knots_doc.tex
+%% spath3.tex
+%% and the derived files spath3.ins,
+%% spath3_code.pdf,
+%% spath3.sty,
+%% tikzlibrarycalligraphy.code.tex
+%% tikzlibraryknots.code.tex
+%% tikzlibraryspath3.code.tex
+%% calligraphy.pdf
+%% knots.pdf
+%% spath3.pdf
+%% README
+%%
+%%
+%% End of file `spath3_code.ins'.
Modified: trunk/Master/texmf-dist/tex/latex/spath3/spath3.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/spath3/spath3.sty 2021-01-23 10:56:29 UTC (rev 57503)
+++ trunk/Master/texmf-dist/tex/latex/spath3/spath3.sty 2021-01-23 22:17:41 UTC (rev 57504)
@@ -4,10 +4,10 @@
%%
%% The original source files were:
%%
-%% spath3.dtx (with options: `spath3')
+%% spath3_code.dtx (with options: `spath3')
%% ----------------------------------------------------------------
%% spath3 --- Functions for manipulating PGF soft paths
-%% E-mail: stacey at math.ntnu.no
+%% E-mail: loopspace at mathforge.org
%% Released under the LaTeX Project Public License v1.3c or later
%% See http://www.latex-project.org/lppl.txt
%% ----------------------------------------------------------------
@@ -15,335 +15,610 @@
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{expl3}
\RequirePackage{pgf}
-\ProvidesExplPackage {spath3} {2019/02/12} {1.2} {Functions for
+\ProvidesExplPackage {spath3} {2021/01/19} {2.0} {Functions for
manipulating PGF soft paths}
\RequirePackage{xparse}
+\cs_new_protected:Nn \__spath_tl_put_right_braced:Nn
+{
+ \tl_put_right:Nn #1 { { #2 } }
+}
+\cs_generate_variant:Nn \__spath_tl_put_right_braced:Nn { NV, cV, cv, Nx, cx }
+
+\cs_new_protected:Nn \__spath_tl_gput_right_braced:Nn
+{
+ \tl_gput_right:Nn #1 { { #2 } }
+}
+\cs_generate_variant:Nn \__spath_tl_gput_right_braced:Nn { NV, cV, cv, Nx, cx }
+\cs_new_protected:Nn \__spath_tl_put_left_braced:Nn
+{
+ \tl_put_left:Nn #1 { { #2 } }
+}
+\cs_generate_variant:Nn \__spath_tl_put_left_braced:Nn { NV, cV, cv, Nx, cx }
+
+\cs_new_protected:Nn \__spath_tl_gput_left_braced:Nn
+{
+ \tl_gput_left:Nn #1 { { #2 } }
+}
+\cs_generate_variant:Nn \__spath_tl_gput_left_braced:Nn { NV, cV, cv, Nx, cx }
\tl_new:N \l__spath_tmpa_tl
\tl_new:N \l__spath_tmpb_tl
\tl_new:N \l__spath_tmpc_tl
\tl_new:N \l__spath_tmpd_tl
-\tl_new:N \l__spath_smuggle_tl
+\tl_new:N \l__spath_tmpe_tl
+
+\seq_new:N \l__spath_tmpa_seq
+\seq_new:N \l__spath_tmpb_seq
+
+\tl_new:N \g__spath_output_tl
+\int_new:N \g__spath_output_int
+\seq_new:N \g__spath_output_seq
+
\dim_new:N \l__spath_tmpa_dim
\dim_new:N \l__spath_tmpb_dim
+\dim_new:N \l__spath_move_x_dim
+\dim_new:N \l__spath_move_y_dim
\fp_new:N \l__spath_tmpa_fp
\fp_new:N \l__spath_tmpb_fp
\int_new:N \l__spath_tmpa_int
-\int_new:N \g__spath_map_int
-\tl_new:N \g__spath_moveto_tl
-\tl_new:N \g__spath_lineto_tl
-\tl_new:N \g__spath_curveto_tl
-\tl_new:N \g__spath_curvetoa_tl
-\tl_new:N \g__spath_curvetob_tl
-\tl_new:N \g__spath_closepath_tl
-\tl_set:Nn \g__spath_moveto_tl {\pgfsyssoftpath at movetotoken}
-\tl_set:Nn \g__spath_lineto_tl {\pgfsyssoftpath at linetotoken}
-\tl_set:Nn \g__spath_curveto_tl {\pgfsyssoftpath at curvetotoken}
-\tl_set:Nn \g__spath_curvetoa_tl {\pgfsyssoftpath at curvetosupportatoken}
-\tl_set:Nn \g__spath_curvetob_tl {\pgfsyssoftpath at curvetosupportbtoken}
-\tl_set:Nn \g__spath_closepath_tl {\pgfsyssoftpath at closepathtoken}
-\tl_new:N \g__spath_attributes
-\tl_new:N \g__spath_moveable_attributes
-\tl_new:N \g__spath_path_attributes
-\tl_set:Nn \g__spath_attributes {
- {path}
- {reverse path}
- {length}
- {real length}
- {number of components}
- {initial point}
- {final point}
- {initial action}
- {final action}
- {min bb}
- {max bb}
-}
-\tl_set:Nn \g__spath_moveable_attributes {
- {initial point}
- {final point}
- {min bb}
- {max bb}
-}
-\tl_set:Nn \g__spath_path_attributes {
- {path}
- {reverse path}
-}
-\cs_new_nopar:Npn \spath_new:n #1
+
+\bool_new:N \g__spath_output_bool
+\bool_new:N \l__spath_closed_bool
+\tl_const:Nn \c_spath_moveto_tl {\pgfsyssoftpath at movetotoken}
+\tl_const:Nn \c_spath_lineto_tl {\pgfsyssoftpath at linetotoken}
+\tl_const:Nn \c_spath_curveto_tl {\pgfsyssoftpath at curvetotoken}
+\tl_const:Nn \c_spath_curvetoa_tl {\pgfsyssoftpath at curvetosupportatoken}
+\tl_const:Nn \c_spath_curvetob_tl {\pgfsyssoftpath at curvetosupportbtoken}
+\tl_const:Nn \c_spath_closepath_tl {\pgfsyssoftpath at closepathtoken}
+\int_new:N \g__spath_anon_int
+\int_gzero:N \g__spath_anon_int
+\tl_new:N \l__spath_itera_tl
+\tl_new:N \l__spath_iterb_tl
+\tl_new:N \l__spath_iterc_tl
+\tl_new:N \l__spath_iterd_tl
+\tl_new:N \l__spath_iterp_tl
+\dim_new:N \l__spath_itera_dim
+\dim_new:N \l__spath_iterb_dim
+\seq_new:N \l__spath_iter_seq
+\msg_new:nnn { spath3 } { unknown path construction } { The~ path~ construction~ element~ #1~ is~ not~ currently~ supported.}
+\cs_new_protected_nopar:Npn \__spath_segments_to_seq:n #1
{
- \prop_new:c {l__spath_#1}
+ \group_begin:
+ \tl_set:Nn \l__spath_itera_tl {#1}
+ \tl_clear:N \l__spath_iterb_tl
+ \seq_clear:N \l__spath_iter_seq
+ \dim_zero:N \l__spath_itera_dim
+ \dim_zero:N \l__spath_iterb_dim
+
+ \bool_until_do:nn {
+ \tl_if_empty_p:N \l__spath_itera_tl
+ }
+ {
+ \tl_set:Nx \l__spath_iterc_tl {\tl_head:N \l__spath_itera_tl}
+ \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl}
+ \tl_case:NnF \l__spath_iterc_tl
+ {
+ \c_spath_moveto_tl
+ {
+ \tl_set_eq:NN \l__spath_iterb_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}}
+ \dim_set:Nn \l__spath_itera_dim {\tl_head:N \l__spath_itera_tl}
+ \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl}
+
+ \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}}
+ \dim_set:Nn \l__spath_iterb_dim {\tl_head:N \l__spath_itera_tl}
+ \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl}
+
+ \tl_set:Nx \l__spath_iterd_tl {\tl_head:N \l__spath_itera_tl}
+ \tl_if_eq:NNF \l__spath_iterd_tl \c_spath_moveto_tl
+ {
+ \tl_clear:N \l__spath_iterb_tl
+ }
+
+ }
+
+ \c_spath_lineto_tl
+ {
+ \tl_set_eq:NN \l__spath_iterb_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l__spath_iterb_tl
+ {
+ {\dim_use:N \l__spath_itera_dim}
+ {\dim_use:N \l__spath_iterb_dim}
+ }
+ \tl_put_right:NV \l__spath_iterb_tl \c_spath_lineto_tl
+
+ \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}}
+ \dim_set:Nn \l__spath_itera_dim {\tl_head:N \l__spath_itera_tl}
+ \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl}
+
+ \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}}
+ \dim_set:Nn \l__spath_iterb_dim {\tl_head:N \l__spath_itera_tl}
+ \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl}
+
+ }
+
+ \c_spath_curvetoa_tl
+ {
+ \tl_set_eq:NN \l__spath_iterb_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l__spath_iterb_tl
+ {
+ {\dim_use:N \l__spath_itera_dim}
+ {\dim_use:N \l__spath_iterb_dim}
+ }
+ \tl_put_right:NV \l__spath_iterb_tl \c_spath_curvetoa_tl
+
+ \prg_replicate:nn {2} {
+ \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}}
+ \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl}
+ \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}}
+ \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl}
+ \tl_put_right:Nx \l__spath_iterb_tl {\tl_head:N \l__spath_itera_tl}
+ \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl}
+ }
+
+ \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}}
+ \dim_set:Nn \l__spath_itera_dim {\tl_head:N \l__spath_itera_tl}
+ \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl}
+
+ \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}}
+ \dim_set:Nn \l__spath_iterb_dim {\tl_head:N \l__spath_itera_tl}
+ \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl}
+
+ }
+
+ \c_spath_closepath_tl
+ {
+ \tl_set_eq:NN \l__spath_iterb_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l__spath_iterb_tl
+ {
+ {\dim_use:N \l__spath_itera_dim}
+ {\dim_use:N \l__spath_iterb_dim}
+ }
+ \tl_put_right:NV \l__spath_iterb_tl \c_spath_lineto_tl
+
+ \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}}
+ \dim_set:Nn \l__spath_itera_dim {\tl_head:N \l__spath_itera_tl}
+ \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl}
+
+ \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}}
+ \dim_set:Nn \l__spath_iterb_dim {\tl_head:N \l__spath_itera_tl}
+ \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl}
+
+ }
+
+ }
+ {
+
+ \tl_set_eq:NN \l__spath_iterb_tl \l__spath_iterc_tl
+ \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}}
+ \dim_set:Nn \l__spath_itera_dim {\tl_head:N \l__spath_itera_tl}
+ \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl}
+
+ \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}}
+ \dim_set:Nn \l__spath_iterb_dim {\tl_head:N \l__spath_itera_tl}
+ \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl}
+
+ }
+
+ \tl_if_empty:NF \l__spath_iterb_tl
+ {
+ \seq_put_right:NV \l__spath_iter_seq \l__spath_iterb_tl
+ }
+ \tl_clear:N \l__spath_iterb_tl
+ }
+
+ \seq_gclear:N \g__spath_output_seq
+ \seq_gset_eq:NN \g__spath_output_seq \l__spath_iter_seq
+ \group_end:
}
-\cs_new_nopar:Npn \spath_clear:n #1
+\cs_new_protected_nopar:Npn \spath_segments_to_seq:Nn #1#2
{
- \prop_gclear:c {l__spath_#1}
+ \__spath_segments_to_seq:n {#2}
+ \seq_clear_new:N #1
+ \seq_set_eq:NN #1 \g__spath_output_seq
+ \seq_gclear:N \g__spath_output_seq
}
-\cs_new_nopar:Npn \spath_clear_new:n #1
+\cs_generate_variant:Nn \spath_segments_to_seq:Nn {NV, cn, cV, Nv, cv}
+\cs_new_protected_nopar:Npn \spath_segments_gto_seq:Nn #1#2
{
- \prop_gclear_new:c {l__spath_#1}
+ \__spath_segments_to_seq:n {#2}
+ \seq_clear_new:N #1
+ \seq_gset_eq:NN #1 \g__spath_output_seq
+ \seq_gclear:N \g__spath_output_seq
}
-\cs_new_nopar:Npn \spath_show:n #1
+\cs_generate_variant:Nn \spath_segments_gto_seq:Nn {NV, cn, cV, Nv, cv}
+\cs_new_protected_nopar:Npn \__spath_components_to_seq:n #1
{
- \prop_show:c {l__spath_#1}
+ \group_begin:
+ \tl_set:Nn \l__spath_itera_tl {#1}
+ \seq_clear:N \l__spath_iter_seq
+ \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl}
+ \tl_put_right:NV \l__spath_itera_tl \c_spath_moveto_tl
+ \tl_set_eq:NN \l__spath_iterb_tl \c_spath_moveto_tl
+ \bool_do_until:nn {
+ \tl_if_empty_p:N \l__spath_itera_tl
+ }
+ {
+ \tl_set:Nx \l__spath_iterc_tl {\tl_head:N \l__spath_itera_tl}
+ \tl_if_eq:NNT \l__spath_iterc_tl \c_spath_moveto_tl
+ {
+ \seq_put_right:NV \l__spath_iter_seq \l__spath_iterb_tl
+ \tl_clear:N \l__spath_iterb_tl
+ }
+ \tl_if_single:NTF \l__spath_iterc_tl
+ {
+ \tl_put_right:NV \l__spath_iterb_tl \l__spath_iterc_tl
+ }
+ {
+ \tl_put_right:Nx \l__spath_iterb_tl {{\l__spath_iterc_tl}}
+ }
+ \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl}
+ }
+
+ \seq_gclear:N \g__spath_output_seq
+ \seq_gset_eq:NN \g__spath_output_seq \l__spath_iter_seq
+ \group_end:
}
-\cs_new_nopar:Npn \spath_put:nnn #1#2#3
+\cs_new_protected_nopar:Npn \spath_components_to_seq:Nn #1#2
{
- \prop_gput:cnn {l__spath_#1} {#2} {#3}
+ \__spath_components_to_seq:n {#2}
+ \seq_clear_new:N #1
+ \seq_set_eq:NN #1 \g__spath_output_seq
+ \seq_gclear:N \g__spath_output_seq
}
-\cs_new_nopar:Npn \spath_remove:nn #1#2
+\cs_generate_variant:Nn \spath_components_to_seq:Nn {NV, cn, cV, cv, Nv}
+\cs_new_protected_nopar:Npn \spath_components_gto_seq:Nn #1#2
{
- \prop_gremove:cn {l__spath_#1} {#2}
+ \__spath_components_to_seq:n {#2}
+ \seq_clear_new:N #1
+ \seq_gset_eq:NN #1 \g__spath_output_seq
+ \seq_gclear:N \g__spath_output_seq
}
-\cs_new_nopar:Npn \__spath_get:nn #1#2
+\cs_generate_variant:Nn \spath_components_gto_seq:Nn {NV, cn, cV, cv, Nv}
+\cs_new_protected_nopar:Npn \spath_components_to_clist:Nn #1#2
{
- \prop_item:cn {l__spath_#1} {#2}
+ \__spath_components_to_seq:n {#2}
+ \clist_clear_new:N #1
+ \clist_set_from_seq:NN #1 \g__spath_output_seq
+ \seq_gclear:N \g__spath_output_seq
}
-\cs_new_nopar:Npn \__spath_get:nnN #1#2#3
+\cs_generate_variant:Nn \spath_components_to_clist:Nn {NV, cn, cV, cv, Nv}
+\cs_new_protected_nopar:Npn \spath_components_gto_clist:Nn #1#2
{
- \prop_get:cnN {l__spath_#1} {#2} #3
+ \__spath_components_to_seq:n {#2}
+ \clist_clear_new:N #1
+ \clist_gset_from_seq:NN #1 \g__spath_output_seq
+ \seq_gclear:N \g__spath_output_seq
}
-\prg_new_conditional:Npnn \spath_if_in:nn #1#2 {p, T, F, TF}
+\cs_generate_variant:Nn \spath_components_gto_clist:Nn {NV, cn, cV, cv, Nv}
+\cs_new_protected_nopar:Npn \spath_length:n #1
{
- \prop_if_in:cnTF {l__spath_#1} {#2}
- { \prg_return_true: }
- { \prg_return_false: }
+ \int_eval:n {\tl_count:n {#1} / 3}
}
-\cs_generate_variant:Nn \__prop_split:NnTF {cnTF}
-\prg_new_protected_conditional:Npnn \__spath_get:nnN #1#2#3 {T, F, TF}
+\cs_generate_variant:Nn \spath_length:n {V}
+\cs_new_protected_nopar:Npn \__spath_reallength:n #1
{
- \__prop_split:cnTF {l__spath_#1} {#2}
- {
- \tl_set:Nn #3 {##2}
- \prg_return_true:
- }
- { \prg_return_false: }
-}
-\cs_generate_variant:Nn \spath_put:nnn {nnV, nnx, nno}
-\cs_generate_variant:Nn \__spath_get:nn {Vn}
-\cs_generate_variant:Nn \__spath_get:nnN {VnN}
-\prg_new_conditional:Npnn \spath_if_exist:n #1 {p,T,F,TF}
-{
- \prop_if_exist:cTF {l__spath_#1}
- {
- \prg_return_true:
- }
- {
- \prg_return_false:
- }
-}
-\cs_new_nopar:Npn \spath_clone:nn #1 #2
-{
- \spath_clear_new:n {#2}
- \tl_map_inline:Nn \g__spath_attributes
- {
- \spath_if_in:nnT {#1} {##1}
+ \group_begin:
+ \int_set:Nn \l__spath_tmpa_int {0}
+ \tl_map_inline:nn {#1} {
+ \tl_set:Nn \l__spath_tmpc_tl {##1}
+ \tl_case:NnT \l__spath_tmpc_tl
{
- \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl
- \spath_put:nnV {#2} {##1} \l__spath_tmpa_tl
+ \c_spath_lineto_tl {}
+ \c_spath_curveto_tl {}
+ \c_spath_closepath_tl {}
}
+ {
+ \int_incr:N \l__spath_tmpa_int
+ }
}
+ \int_gzero:N \g__spath_output_int
+ \int_gset_eq:NN \g__spath_output_int \l__spath_tmpa_int
+ \group_end:
}
-\cs_new_protected_nopar:Npn \spath_get_current_path:n #1
+\cs_new_protected_nopar:Npn \spath_reallength:Nn #1#2
{
- \pgfsyssoftpath at getcurrentpath\l__spath_tmpa_tl
- \spath_clear_new:n {#1}
- \spath_put:nnV {#1} {path} \l__spath_tmpa_tl
+ \__spath_reallength:n {#2}
+ \int_set_eq:NN #1 \g__spath_output_int
+ \int_gzero:N \g__spath_output_int
}
-\cs_new_protected_nopar:Npn \spath_set_current_path:n #1
+\cs_generate_variant:Nn \spath_reallength:Nn {NV, cn, cV, Nv, cv}
+\cs_new_protected_nopar:Npn \spath_greallength:Nn #1#2
{
- \spath_get:nnN {#1} {min bb} \l__spath_tmpa_tl
- \exp_last_unbraced:NV \pgf at protocolsizes\l__spath_tmpa_tl
-
- \spath_get:nnN {#1} {max bb} \l__spath_tmpa_tl
- \exp_last_unbraced:NV \pgf at protocolsizes\l__spath_tmpa_tl
-
- \spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \pgfsyssoftpath at setcurrentpath\l__spath_tmpa_tl
- \pgfsyssoftpath at flushcurrentpath
+ \__spath_reallength:n {#2}
+ \int_gset_eq:NN #1 \g__spath_output_int
+ \int_gzero:N \g__spath_output_int
}
-\cs_new_protected_nopar:Npn \spath_use_path:nn #1#2
+\cs_generate_variant:Nn \spath_greallength:Nn {NV, cn, cV}
+\cs_new_protected_nopar:Npn \__spath_numberofcomponents:n #1
{
- \spath_set_current_path:n {#1}
- \pgfusepath{#2}
+ \group_begin:
+ \int_set:Nn \l__spath_tmpa_int {0}
+ \tl_map_inline:nn {#1} {
+ \tl_set:Nn \l__spath_tmpa_tl {##1}
+ \tl_case:Nn \l__spath_tmpa_tl
+ {
+ \c_spath_moveto_tl
+ {
+ \int_incr:N \l__spath_tmpa_int
+ }
+ }
+ }
+ \int_gzero:N \g__spath_output_int
+ \int_gset_eq:NN \g__spath_output_int \l__spath_tmpa_int
+ \group_end:
}
-\cs_new_protected_nopar:Npn \spath_protocol_path:n #1
+\cs_new_protected_nopar:Npn \spath_numberofcomponents:Nn #1#2
{
- \spath_get:nnN {#1} {min bb} \l__spath_tmpa_tl
- \exp_last_unbraced:NV \pgf at protocolsizes\l__spath_tmpa_tl
-
- \spath_get:nnN {#1} {max bb} \l__spath_tmpa_tl
- \exp_last_unbraced:NV \pgf at protocolsizes\l__spath_tmpa_tl
+ \__spath_numberofcomponents:n {#2}
+ \int_set_eq:NN #1 \g__spath_output_int
+ \int_gzero:N \g__spath_output_int
}
-\cs_new_protected_nopar:Npn \spath_tikz_path:nn #1#2
+\cs_generate_variant:Nn \spath_numberofcomponents:Nn {NV, cn, cV}
+\cs_new_protected_nopar:Npn \spath_gnumberofcomponents:Nn #1#2
{
- \path[#1] \pgfextra{
- \spath_get:nnN {#2} {path} \l__spath_tmpa_tl
- \pgfsyssoftpath at setcurrentpath \l__spath_tmpa_tl
- };
+ \__spath_numberofcomponents:n {#2}
+ \int_gset_eq:NN #1 \g__spath_output_int
+ \int_gzero:N \g__spath_output_int
}
-\cs_generate_variant:Nn \spath_tikz_path:nn {Vn}
-\cs_new_nopar:Npn \spath_get:nn #1#2
+\cs_generate_variant:Nn \spath_gnumberofcomponents:Nn {NV, cn, cV}
+\cs_new_protected_nopar:Npn \__spath_initialpoint:n #1
{
- \spath_if_in:nnF {#1} {#2}
+ \group_begin:
+ \tl_clear:N \l__spath_tmpb_tl
+ \tl_set:Nx \l__spath_tmpb_tl
{
- \cs_if_exist_use:cT {spath_generate_#2:n} {{#1}}
+ { \tl_item:nn {#1} {2} }
+ { \tl_item:nn {#1} {3} }
}
- \__spath_get:nn {#1} {#2}
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
+ \group_end:
}
-\cs_new_nopar:Npn \spath_get:nnN #1#2#3
+\cs_new_protected_nopar:Npn \spath_initialpoint:Nn #1#2
{
- \spath_if_in:nnF {#1} {#2}
- {
- \cs_if_exist_use:cT {spath_generate_#2:n} {{#1}}
- }
- \__spath_get:nnN {#1} {#2} #3
+ \__spath_initialpoint:n {#2}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
}
-\cs_generate_variant:Nn \spath_get:nnN {VnN}
-\cs_new_nopar:Npn \spath_generate_length:n #1
+\cs_generate_variant:Nn \spath_initialpoint:Nn {NV, cn, cV, Nv}
+\cs_new_protected_nopar:Npn \spath_ginitialpoint:Nn #1#2
{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \spath_put:nnx {#1} {length} {\int_eval:n {\tl_count:N \l__spath_tmpa_tl /3 }}
+ \__spath_initialpoint:n {#2}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
}
-\cs_new_nopar:Npn \spath_generate_reallength:n #1
+\cs_generate_variant:Nn \spath_ginitialpoint:Nn {NV, cn, cV, Nv}
+\cs_new_protected_nopar:Npn \__spath_finalpoint:n #1
{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \int_set:Nn \l__spath_tmpa_int {0}
- \tl_map_inline:Nn \l__spath_tmpa_tl {
- \tl_if_eq:nnT {##1} {\pgfsyssoftpath at linetotoken}
- {
- \int_incr:N \l__spath_tmpa_int
- }
- \tl_if_eq:nnT {##1} {\pgfsyssoftpath at curvetotoken}
- {
- \int_incr:N \l__spath_tmpa_int
- }
+ \group_begin:
+ \tl_set:Nn \l__spath_tmpa_tl {#1}
+ \tl_reverse:N \l__spath_tmpa_tl
+ \tl_clear:N \l__spath_tmpb_tl
+ \tl_set:Nx \l__spath_tmpb_tl
+ {
+ { \tl_item:Nn \l__spath_tmpa_tl {2} }
+ { \tl_item:Nn \l__spath_tmpa_tl {1} }
}
- \spath_put:nnx {#1} {real length} {\int_use:N \l__spath_tmpa_int}
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
+ \group_end:
}
-\cs_new_nopar:Npn \spath_generate_numberofcomponents:n #1
+\cs_new_protected_nopar:Npn \spath_finalpoint:Nn #1#2
{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \int_set:Nn \l__spath_tmpa_int {0}
- \tl_map_inline:Nn \l__spath_tmpa_tl {
- \tl_if_eq:nnT {##1} {\pgfsyssoftpath at movetotoken}
- {
- \int_incr:N \l__spath_tmpa_int
- }
- }
- \spath_put:nnx {#1} {number of components} {\int_use:N \l__spath_tmpa_int}
+ \__spath_finalpoint:n {#2}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
}
-\cs_new_nopar:Npn \spath_generate_initialpoint:n #1
+\cs_generate_variant:Nn \spath_finalpoint:Nn {NV, cn, cV, Nv}
+\cs_new_protected_nopar:Npn \spath_gfinalpoint:Nn #1#2
{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \tl_clear:N \l__spath_tmpb_tl
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \spath_put:nnV {#1} {initial point} \l__spath_tmpb_tl
+ \__spath_finalpoint:n {#2}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
}
-\cs_new_nopar:Npn \spath_generate_finalpoint:n #1
+\cs_generate_variant:Nn \spath_gfinalpoint:Nn {NV, cn, cV, Nv}
+\cs_new_protected_nopar:Npn \__spath_reverse:n #1
{
+ \group_begin:
+ \tl_set:Nn \l__spath_tmpa_tl {#1}
+
\tl_clear:N \l__spath_tmpb_tl
- \spath_if_in:nnTF {#1} {reverse path}
- {
- \__spath_get:nnN {#1} {reverse path} \l__spath_tmpa_tl
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- }
- {
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \tl_reverse:N \l__spath_tmpa_tl
- \tl_put_left:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_left:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- }
- \spath_put:nnV {#1} {final point} \l__spath_tmpb_tl
-}
-\cs_generate_variant:Nn \spath_generate_finalpoint:n {V}
-\cs_new_nopar:Npn \spath_generate_reversepath:n #1
-{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \tl_clear:N \l__spath_tmpb_tl
+ \tl_clear:N \l__spath_tmpd_tl
\tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
\dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
\tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
\dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
\tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_left:Nx \l__spath_tmpb_tl
+
+ \tl_put_left:Nx \l__spath_tmpd_tl
{
{\dim_use:N \l__spath_tmpa_dim}
{\dim_use:N \l__spath_tmpb_dim}
}
+
+ \bool_set_false:N \l__spath_closed_bool
+
\bool_until_do:nn {
\tl_if_empty_p:N \l__spath_tmpa_tl
}
{
\tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nn \l__spath_tmpd_tl {}
- \tl_case:NnF \l__spath_tmpc_tl
+
+ \tl_case:NnTF \l__spath_tmpc_tl
{
- \g__spath_moveto_tl {\tl_set_eq:NN \l__spath_tmpd_tl \g__spath_moveto_tl }
- \g__spath_lineto_tl {\tl_set_eq:NN \l__spath_tmpd_tl \g__spath_lineto_tl }
- \g__spath_curveto_tl {\tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curvetoa_tl }
- \g__spath_curvetoa_tl {\tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curveto_tl }
- \g__spath_curvetob_tl {\tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curvetob_tl }
+ \c_spath_moveto_tl {
+
+ \bool_if:NT \l__spath_closed_bool
+ {
+ \tl_put_right:NV \l__spath_tmpd_tl \c_spath_closepath_tl
+ \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpd_tl}
+ \tl_put_right:Nx \l__spath_tmpd_tl
+ {
+ { \tl_head:N \l__spath_tmpd_tl }
+ { \tl_head:N \l__spath_tmpe_tl }
+ }
+ }
+ \bool_set_false:N \l__spath_closed_bool
+ \tl_put_left:NV \l__spath_tmpd_tl \c_spath_moveto_tl
+ \tl_put_left:NV \l__spath_tmpb_tl \l__spath_tmpd_tl
+ \tl_clear:N \l__spath_tmpd_tl
+ }
+ \c_spath_lineto_tl {
+ \tl_put_left:NV \l__spath_tmpd_tl \c_spath_lineto_tl
+ }
+ \c_spath_curveto_tl {
+ \tl_put_left:NV \l__spath_tmpd_tl \c_spath_curvetoa_tl
+ }
+ \c_spath_curvetoa_tl {
+ \tl_put_left:NV \l__spath_tmpd_tl \c_spath_curveto_tl
+ }
+ \c_spath_curvetob_tl {
+ \tl_put_left:NV \l__spath_tmpd_tl \c_spath_curvetob_tl
+ }
}
{
- \tl_show:N \l__spath_tmpc_tl
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+
+ \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+
+ \tl_put_left:Nx \l__spath_tmpd_tl
+ {
+ {\dim_use:N \l__spath_tmpa_dim}
+ {\dim_use:N \l__spath_tmpb_dim}
+ }
+
}
- \tl_put_left:NV \l__spath_tmpb_tl \l__spath_tmpd_tl
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_left:Nx \l__spath_tmpb_tl
{
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
+ \tl_if_eq:NNTF \l__spath_tmpc_tl \c_spath_closepath_tl
+ {
+ \bool_set_true:N \l__spath_closed_bool
+ }
+ {
+ \msg_warning:nnx { spath3 } { unknown path construction } {\l__spath_tmpc_tl }
+ }
+
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+
}
}
- \tl_put_left:NV \l__spath_tmpb_tl \g__spath_moveto_tl
- \spath_put:nnV {#1} {reverse path} \l__spath_tmpb_tl
+
+ \bool_if:NT \l__spath_closed_bool
+ {
+ \tl_put_right:NV \l__spath_tmpd_tl \c_spath_closepath_tl
+ \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpd_tl}
+ \tl_put_right:Nx \l__spath_tmpd_tl
+ {
+ { \tl_head:N \l__spath_tmpd_tl }
+ { \tl_head:N \l__spath_tmpe_tl }
+ }
+ }
+
+ \bool_set_false:N \l__spath_closed_bool
+ \tl_put_left:NV \l__spath_tmpd_tl \c_spath_moveto_tl
+ \tl_put_left:NV \l__spath_tmpb_tl \l__spath_tmpd_tl
+
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
+ \group_end:
}
-\cs_new_nopar:Npn \spath_generate_initialaction:n #1
+\cs_new_protected_nopar:Npn \spath_reverse:Nn #1#2
{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \tl_clear:N \l__spath_tmpb_tl
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_if_empty:NF \l__spath_tmpa_tl {
- \tl_set:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
+ \__spath_reverse:n {#2}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_reverse:Nn {NV, cn, cV, Nv}
+\cs_new_protected_nopar:Npn \spath_reverse:N #1
+{
+ \spath_reverse:NV #1#1
+}
+\cs_generate_variant:Nn \spath_reverse:N {c}
+\cs_new_protected_nopar:Npn \spath_greverse:Nn #1#2
+{
+ \__spath_reverse:n {#2}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_greverse:Nn {NV, cn, cV, Nv}
+\cs_new_protected_nopar:Npn \spath_greverse:N #1
+{
+ \spath_greverse:NV #1#1
+}
+\cs_generate_variant:Nn \spath_greverse:N {c}
+\cs_new_protected_nopar:Npn \__spath_initialaction:n #1
+{
+ \group_begin:
+ \tl_clear:N \l__spath_tmpa_tl
+ \int_compare:nT
+ {
+ \tl_count:n {#1} > 3
}
- \spath_put:nnV {#1} {initial action} \l__spath_tmpb_tl
+ {
+ \tl_set:Nx \l__spath_tmpa_tl
+ {
+ \tl_item:Nn {#1} {4}
+ }
+ }
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
+ \group_end:
}
-\cs_new_nopar:Npn \spath_generate_finalaction:n #1
+\cs_new_protected_nopar:Npn \spath_initialaction:Nn #1#2
{
+ \__spath_initialaction:n {#2}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_initialaction:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_ginitialaction:Nn #1#2
+{
+ \__spath_initialaction:n {#2}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_ginitialaction:Nn {NV}
+\cs_new_protected_nopar:Npn \__spath_finalaction:n #1
+{
+ \group_begin:
\tl_clear:N \l__spath_tmpb_tl
- \spath_if_in:nnTF {#1} {reverse path}
+ \int_compare:nT
{
- \__spath_get:nnN {#1} {reverse path} \l__spath_tmpa_tl
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ \tl_count:n {#1} > 3
}
{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
+ \tl_set:Nn \l__spath_tmpa_tl {#1}
\tl_reverse:N \l__spath_tmpa_tl
+ \tl_set:Nx \l__spath_tmpb_tl
+ {
+ \tl_item:Nn \l__spath_tmpa_tl {3}
+ }
+ \tl_if_eq:NNT \l__spath_tmpb_tl \c_spath_curvetoa_tl
+ {
+ \tl_set_eq:NN \l__spath_tmpb_tl \c_spath_curveto_tl
+ }
}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_if_empty:NF \l__spath_tmpa_tl {
- \tl_set:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
- }
- \tl_if_eq:NNT \l__spath_tmpa_tl \g__spath_curvetoa_tl
- {
- \tl_set_eq:NN \l__spath_tmpa_tl \g__spath_curveto_tl
- }
- \spath_put:nnV {#1} {final action} \l__spath_tmpb_tl
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
+ \group_end:
}
-\cs_new_nopar:Npn \spath_generate_minbb:n #1
+\cs_new_protected_nopar:Npn \spath_finalaction:Nn #1#2
{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
+ \__spath_finalaction:n {#2}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_finalaction:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gfinalaction:Nn #1#2
+{
+ \__spath_finalaction:n {#2}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gfinalaction:Nn {NV}
+\cs_new_protected_nopar:Npn \__spath_minbb:n #1
+{
+ \group_begin:
+ \tl_set:Nn \l__spath_tmpa_tl {#1}
\tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
\dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
\tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
@@ -365,11 +640,27 @@
{\dim_use:N \l__spath_tmpa_dim}
{\dim_use:N \l__spath_tmpb_dim}
}
- \spath_put:nnV {#1} {min bb} \l__spath_tmpb_tl
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
+ \group_end:
}
-\cs_new_nopar:Npn \spath_generate_maxbb:n #1
+\cs_new_protected_nopar:Npn \spath_minbb:Nn #1#2
{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
+ \__spath_minbb:n {#2}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_minbb:Nn {NV, cn, cV}
+\cs_new_protected_nopar:Npn \spath_gminbb:Nn #1#2
+{
+ \__spath_minbb:n {#2}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gminbb:Nn {NV, cn, cV}
+\cs_new_protected_nopar:Npn \__spath_maxbb:n #1
+{
+ \group_begin:
+ \tl_set:Nn \l__spath_tmpa_tl {#1}
\tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
\dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
\tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
@@ -391,1101 +682,2440 @@
{\dim_use:N \l__spath_tmpa_dim}
{\dim_use:N \l__spath_tmpb_dim}
}
- \spath_put:nnV {#1} {max bb} \l__spath_tmpb_tl
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
+ \group_end:
}
-\tl_new:N \l__spath_rp_tl
-\int_new:N \l__spath_l_int
-\int_new:N \l__spath_rl_int
-\int_new:N \l__spath_nc_int
-\tl_new:N \l__spath_ip_tl
-\tl_new:N \l__spath_fp_tl
-\tl_new:N \l__spath_ia_tl
-\tl_new:N \l__spath_fa_tl
-\dim_new:N \l__spath_minx_dim
-\dim_new:N \l__spath_miny_dim
-\dim_new:N \l__spath_maxx_dim
-\dim_new:N \l__spath_maxy_dim
-
-\cs_new_nopar:Npn \spath_generate_all:n #1
+\cs_new_protected_nopar:Npn \spath_maxbb:Nn #1#2
{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
-
- \tl_clear:N \l__spath_rp_tl
- \int_set:Nn \l__spath_l_int {1}
- \int_zero:N \l__spath_rl_int
- \int_set:Nn \l__spath_nc_int {1}
- \tl_clear:N \l__spath_ip_tl
- \tl_clear:N \l__spath_fp_tl
- \tl_clear:N \l__spath_ia_tl
- \tl_clear:N \l__spath_fa_tl
- \dim_zero:N \l__spath_minx_dim
- \dim_zero:N \l__spath_miny_dim
- \dim_zero:N \l__spath_maxx_dim
- \dim_zero:N \l__spath_maxy_dim
-
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \tl_clear:N \l__spath_ip_tl
- \tl_put_right:Nx \l__spath_ip_tl
+ \__spath_maxbb:n {#2}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_maxbb:Nn {NV, cn, cV}
+\cs_new_protected_nopar:Npn \spath_gmaxbb:Nn #1#2
+{
+ \__spath_maxbb:n {#2}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gmaxbb:Nn {NV, cn, cV}
+\int_set:Nn \l__spath_tmpa_int {\char_value_catcode:n {`@}}
+\char_set_catcode_letter:N @
+\cs_new_protected_nopar:Npn \spath_save_to_aux:Nn #1#2 {
+ \tl_if_empty:nF {#2}
{
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
+ \tl_clear:N \l__spath_tmpa_tl
+ \tl_put_right:Nn \l__spath_tmpa_tl {
+ \ExplSyntaxOn
+ \tl_clear:N #1
+ \tl_set:Nn #1 {#2}
+ \ExplSyntaxOff
+ }
+ \protected at write\@auxout{}{
+ \tl_to_str:N \l__spath_tmpa_tl
+ }
}
-
- \dim_set_eq:NN \l__spath_minx_dim \l__spath_tmpa_dim
- \dim_set_eq:NN \l__spath_miny_dim \l__spath_tmpb_dim
- \dim_set_eq:NN \l__spath_maxx_dim \l__spath_tmpa_dim
- \dim_set_eq:NN \l__spath_maxy_dim \l__spath_tmpb_dim
-
- \tl_put_left:Nx \l__spath_rp_tl
+}
+\char_set_catcode:nn {`@} {\l__spath_tmpa_int}
+\cs_generate_variant:Nn \spath_save_to_aux:Nn {cn, cV, NV}
+\cs_new_protected_nopar:Npn \spath_save_to_aux:N #1
+{
+ \tl_if_exist:NT #1
{
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
+ \spath_save_to_aux:NV #1#1
}
-
- \tl_set:Nx \l__spath_ia_tl {\tl_head:N \l__spath_tmpa_tl}
-
+}
+\cs_new_protected_nopar:Npn \__spath_translate:nnn #1#2#3
+{
+ \group_begin:
+ \tl_set:Nn \l__spath_tmpa_tl {#1}
+ \tl_clear:N \l__spath_tmpb_tl
\bool_until_do:nn {
\tl_if_empty_p:N \l__spath_tmpa_tl
}
{
- \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nn \l__spath_tmpd_tl {}
- \tl_set_eq:NN \l__spath_fa_tl \l__spath_tmpc_tl
- \int_incr:N \l__spath_l_int
+ \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_case:NnF \l__spath_tmpc_tl
- {
- \g__spath_moveto_tl {
- \tl_set_eq:NN \l__spath_tmpd_tl \g__spath_moveto_tl
- \int_incr:N \l__spath_nc_int
- }
- \g__spath_lineto_tl {
- \tl_set_eq:NN \l__spath_tmpd_tl \g__spath_lineto_tl
- \int_incr:N \l__spath_rl_int
- }
- \g__spath_curveto_tl {
- \tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curvetoa_tl
- \int_incr:N \l__spath_rl_int
- }
- \g__spath_curvetoa_tl {
- \tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curveto_tl
- }
- \g__spath_curvetob_tl {
- \tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curvetob_tl
- }
- }
- {
- \tl_show:N \l__spath_tmpc_tl
- }
- \tl_put_left:NV \l__spath_rp_tl \l__spath_tmpd_tl
+ \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl + #2}
\tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
+ \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl + #3}
\tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_minx_dim {\dim_min:nn { \l__spath_minx_dim} {\l__spath_tmpa_dim}}
- \dim_set:Nn \l__spath_miny_dim {\dim_min:nn { \l__spath_miny_dim} {\l__spath_tmpb_dim}}
- \dim_set:Nn \l__spath_maxx_dim {\dim_max:nn { \l__spath_maxx_dim} {\l__spath_tmpa_dim}}
- \dim_set:Nn \l__spath_maxy_dim {\dim_max:nn { \l__spath_maxy_dim} {\l__spath_tmpb_dim}}
-
- \tl_put_left:Nx \l__spath_rp_tl
+ \tl_put_right:Nx \l__spath_tmpb_tl
{
{\dim_use:N \l__spath_tmpa_dim}
{\dim_use:N \l__spath_tmpb_dim}
}
+ }
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_translate:Nnnn #1#2#3#4
+{
+ \__spath_translate:nnn {#2}{#3}{#4}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_translate:Nnnn {NVxx, NVVV, NVnn}
+\cs_new_protected_nopar:Npn \spath_translate:Nnn #1#2#3
+{
+ \spath_translate:NVnn #1#1{#2}{#3}
+}
+\cs_generate_variant:Nn \spath_translate:Nnn {NVV, cnn, cVV}
+\cs_new_protected_nopar:Npn \spath_gtranslate:Nnnn #1#2#3#4
+{
+ \__spath_translate:nnn {#2}{#3}{#4}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gtranslate:Nnnn {NVxx, NVVV, NVnn}
+\cs_new_protected_nopar:Npn \spath_gtranslate:Nnn #1#2#3
+{
+ \spath_gtranslate:NVnn #1#1{#2}{#3}
+}
+\cs_generate_variant:Nn \spath_gtranslate:Nnn {NVV, cnn, cVV}
+\cs_new_protected_nopar:Npn \spath_translate:Nn #1#2
+{
+ \spath_translate:Nnn #1 #2
+}
+\cs_generate_variant:Nn \spath_translate:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gtranslate:Nn #1#2
+{
+ \spath_gtranslate:Nnn #1 #2
+}
+\cs_generate_variant:Nn \spath_gtranslate:Nn {NV}
+\cs_new_protected_nopar:Npn \__spath_scale:nnn #1#2#3
+{
+ \group_begin:
+ \tl_set:Nn \l__spath_tmpa_tl {#1}
+ \tl_clear:N \l__spath_tmpb_tl
+ \bool_until_do:nn {
+ \tl_if_empty_p:N \l__spath_tmpa_tl
+ }
+ {
+ \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_fp_tl
+ \fp_set:Nn \l__spath_tmpa_fp {\tl_head:N \l__spath_tmpa_tl * #2}
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+
+ \fp_set:Nn \l__spath_tmpb_fp {\tl_head:N \l__spath_tmpa_tl * #3}
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+
+ \tl_put_right:Nx \l__spath_tmpb_tl
{
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
+ {\fp_to_dim:N \l__spath_tmpa_fp}
+ {\fp_to_dim:N \l__spath_tmpb_fp}
}
+ }
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_scale:Nnnn #1#2#3#4
+{
+ \__spath_scale:nnn {#2}{#3}{#4}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_scale:Nnnn {NVnn, Nnxx}
+\cs_new_protected_nopar:Npn \spath_scale:Nnn #1#2#3
+{
+ \spath_scale:NVnn #1#1{#2}{#3}
+}
+\cs_generate_variant:Nn \spath_scale:Nnn {cnn, cVV, NVV}
+\cs_new_protected_nopar:Npn \spath_gscale:Nnnn #1#2#3#4
+{
+ \__spath_scale:nnn {#2}{#3}{#4}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gscale:Nnnn {NVnn, Nnxx}
+\cs_new_protected_nopar:Npn \spath_gscale:Nnn #1#2#3
+{
+ \spath_gscale:NVnn #1#1{#2}{#3}
+}
+\cs_generate_variant:Nn \spath_gscale:Nnn {cnn, cVV, NVV}
+\cs_new_protected_nopar:Npn \spath_scale:Nn #1#2
+{
+ \spath_scale:Nnn #1 #2
+}
+\cs_generate_variant:Nn \spath_scale:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gscale:Nn #1#2
+{
+ \spath_gscale:Nnn #1 #2
+}
+
+\cs_generate_variant:Nn \spath_gscale:Nn {NV}
+\cs_new_protected_nopar:Npn \__spath_transform:nnnnnnn #1#2#3#4#5#6#7
+{
+ \group_begin:
+ \tl_set:Nn \l__spath_tmpa_tl {#1}
+ \tl_clear:N \l__spath_tmpb_tl
+ \bool_until_do:nn {
+ \tl_if_empty_p:N \l__spath_tmpa_tl
}
+ {
+ \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpd_tl {\tl_head:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_left:NV \l__spath_rp_tl \g__spath_moveto_tl
+ \fp_set:Nn \l__spath_tmpa_fp {\l__spath_tmpc_tl * #2 + \l__spath_tmpd_tl * #4 + #6}
+ \fp_set:Nn \l__spath_tmpb_fp {\l__spath_tmpc_tl * #3 + \l__spath_tmpd_tl * #5 + #7}
+ \tl_put_right:Nx \l__spath_tmpb_tl
+ {
+ {\fp_to_dim:N \l__spath_tmpa_fp}
+ {\fp_to_dim:N \l__spath_tmpb_fp}
+ }
+ }
- \spath_put:nnV {#1} {reverse path} \l__spath_rp_tl
- \spath_put:nnV {#1} {length} \l__spath_l_int
- \spath_put:nnV {#1} {real length} \l__spath_rl_int
- \spath_put:nnV {#1} {number of components} \l__spath_nc_int
- \spath_put:nnV {#1} {initial point} \l__spath_ip_tl
- \spath_put:nnV {#1} {final point} \l__spath_fp_tl
- \spath_put:nnV {#1} {initial action} \l__spath_ia_tl
- \spath_put:nnV {#1} {final action} \l__spath_fa_tl
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_transform:Nnnnnnnn #1#2#3#4#5#6#7#8
+{
+ \__spath_transform:nnnnnnn {#2}{#3}{#4}{#5}{#6}{#7}{#8}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_transform:Nnnnnnnn {NVnnnnnn, Nnxxxxxx, cnnnnnnn}
+\cs_new_protected_nopar:Npn \spath_transform:Nnnnnnn #1#2#3#4#5#6#7
+{
+ \spath_transform:NVnnnnnn #1#1{#2}{#3}{#4}{#5}{#6}{#7}
+}
+\cs_generate_variant:Nn \spath_transform:Nnnnnnn {cnnnnnn}
+\cs_new_protected_nopar:Npn \spath_transform:Nnn #1#2#3
+{
+ \spath_transform:Nnnnnnnn #1{#2}#3
+}
+\cs_generate_variant:Nn \spath_transform:Nnn {cnn, cVn, NVn, NnV}
+\cs_new_protected_nopar:Npn \spath_transform:Nn #1#2
+{
+ \spath_transform:NVnnnnnn #1#1#2
+}
+\cs_generate_variant:Nn \spath_transform:Nn {cn, cV, NV}
- \tl_clear:N \l__spath_tmpb_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
+\cs_new_protected_nopar:Npn \spath_gtransform:Nnnnnnnn #1#2#3#4#5#6#7#8
+{
+ \__spath_transform:nnnnnnn {#2}{#3}{#4}{#5}{#6}{#7}{#8}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gtransform:Nnnnnnnn {NVnnnnnn, Nnxxxxxx, cnnnnnnn}
+\cs_new_protected_nopar:Npn \spath_gtransform:Nnnnnnn #1#2#3#4#5#6#7
+{
+ \spath_gtransform:NVnnnnnn #1#1{#2}{#3}{#4}{#5}{#6}{#7}
+}
+\cs_generate_variant:Nn \spath_gtransform:Nnnnnnn {cnnnnnn}
+\cs_new_protected_nopar:Npn \spath_gtransform:Nnn #1#2#3
+{
+ \spath_gtransform:Nnnnnnnn #1{#2}#3
+}
+\cs_generate_variant:Nn \spath_gtransform:Nnn {cnn, cVn, NVn, NnV}
+\cs_new_protected_nopar:Npn \spath_gtransform:Nn #1#2
+{
+ \spath_gtransform:NVnnnnnn #1#1#2
+}
+\cs_generate_variant:Nn \spath_gtransform:Nn {cn, cV, NV}
+\cs_new_protected_nopar:Npn \__spath_weld:nn #1#2
+{
+ \group_begin:
+ \tl_set:Nn \l__spath_tmpa_tl {#1}
+ \tl_set:Nn \l__spath_tmpb_tl {#2}
+
+ \spath_finalpoint:NV \l__spath_tmpc_tl \l__spath_tmpa_tl
+ \spath_initialpoint:NV \l__spath_tmpd_tl \l__spath_tmpb_tl
+
+ \dim_set:Nn \l__spath_tmpa_dim
{
- {\dim_use:N \l__spath_minx_dim}
- {\dim_use:N \l__spath_miny_dim}
+ \tl_item:Nn \l__spath_tmpc_tl {1}
+ -
+ \tl_item:Nn \l__spath_tmpd_tl {1}
}
- \spath_put:nnV {#1} {min bb} \l__spath_tmpb_tl
+ \dim_set:Nn \l__spath_tmpb_dim
+ {
+ \tl_item:Nn \l__spath_tmpc_tl {2}
+ -
+ \tl_item:Nn \l__spath_tmpd_tl {2}
+ }
- \tl_clear:N \l__spath_tmpb_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
+ \spath_translate:NVV \l__spath_tmpb_tl \l__spath_tmpa_dim \l__spath_tmpb_dim
+
+ \prg_replicate:nn {3}
{
- {\dim_use:N \l__spath_maxx_dim}
- {\dim_use:N \l__spath_maxy_dim}
+ \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
}
- \spath_put:nnV {#1} {max bb} \l__spath_tmpb_tl
+ \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
+ \group_end:
}
-\cs_new_nopar:Npn \spath_translate:nnn #1#2#3
+\cs_new_protected_nopar:Npn \spath_weld:Nnn #1#2#3
{
- \tl_map_inline:Nn \g__spath_moveable_attributes
- {
- \spath_if_in:nnT {#1} {##1}
- {
- \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl
+ \__spath_weld:nn {#2}{#3}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_weld:Nnn {NVV,NVn}
+\cs_new_protected_nopar:Npn \spath_weld:Nn #1#2
+{
+ \spath_weld:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_weld:Nn {NV, Nv, cV, cv}
+\cs_new_protected_nopar:Npn \spath_gweld:Nnn #1#2#3
+{
+ \__spath_weld:nn {#2}{#3}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gweld:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_gweld:Nn #1#2
+{
+ \spath_gweld:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_gweld:Nn {NV, Nv, cV, cv}
+\cs_new_protected_nopar:Npn \__spath_append_no_move:nn #1#2
+{
+ \group_begin:
+ \tl_set:Nn \l__spath_tmpa_tl {#1}
+ \tl_set:Nn \l__spath_tmpb_tl {#2}
+ \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
+ \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
+ \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl + #2}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl + #3}
- \tl_clear:N \l__spath_tmpb_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl
- }
+ \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_append_no_move:Nnn #1#2#3
+{
+ \__spath_append_no_move:nn {#2}{#3}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_append_no_move:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_append_no_move:Nn #1#2
+{
+ \spath_append_no_move:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_append_no_move:Nn {NV, cv}
+\cs_new_protected_nopar:Npn \spath_gappend_no_move:Nnn #1#2#3
+{
+ \__spath_append_no_move:nn {#2}{#3}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gappend_no_move:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_gappend_no_move:Nn #1#2
+{
+ \spath_gappend_no_move:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_gappend_no_move:Nn {NV, cv}
+\cs_new_protected_nopar:Npn \spath_append:Nnn #1#2#3
+{
+ \tl_set:Nn #1 {#2}
+ \tl_put_right:Nn #1 {#3}
+}
+\cs_generate_variant:Nn \spath_append:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_append:Nn #1#2
+{
+ \spath_append:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_append:Nn {NV, Nv}
+\cs_new_protected_nopar:Npn \spath_gappend:Nnn #1#2#3
+{
+ \tl_gset:Nn #1 {#2}
+ \tl_gput_right:Nn #1 {#3}
+}
+\cs_generate_variant:Nn \spath_gappend:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_gappend:Nn #1#2
+{
+ \spath_gappend:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_gappend:Nn {NV, Nv}
+\cs_new_protected_nopar:Npn \spath_prepend_no_move:Nnn #1#2#3
+{
+ \spath_append_no_move:Nnn #1{#3}{#2}
+}
+\cs_generate_variant:Nn \spath_prepend_no_move:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_prepend_no_move:Nn #1#2
+{
+ \spath_prepend_no_move:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_prepend_no_move:Nn {NV, cv}
+\cs_new_protected_nopar:Npn \spath_gprepend_no_move:Nnn #1#2#3
+{
+ \spath_gappend_no_move:Nnn #1{#3}{#2}
+}
+\cs_generate_variant:Nn \spath_gprepend_no_move:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_gprepend_no_move:Nn #1#2
+{
+ \spath_gprepend_no_move:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_gprepend_no_move:Nn {NV, cv}
+\cs_new_protected_nopar:Npn \spath_prepend:Nnn #1#2#3
+{
+ \spath_append:Nnn #1{#3}{#2}
+}
+\cs_generate_variant:Nn \spath_prepend:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_prepend:Nn #1#2
+{
+ \spath_prepend:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_prepend:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gprepend:Nnn #1#2#3
+{
+ \spath_gappend:Nnn #1{#3}{#2}
+}
+\cs_generate_variant:Nn \spath_gprepend:Nnn {NVV, NVn}
+\cs_new_protected_nopar:Npn \spath_gprepend:Nn #1#2
+{
+ \spath_gprepend:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_gprepend:Nn {NV}
+\cs_new_protected_nopar:Npn \__spath_bake_round:n #1
+{
+ \group_begin:
+ \tl_set:Nn \l__spath_tmpa_tl {#1}
+ \pgf@@processround \l__spath_tmpa_tl\l__spath_tmpb_tl
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_bake_round:Nn #1#2
+{
+ \__spath_bake_round:n {#2}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_bake_round:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_bake_round:N #1
+{
+ \spath_bake_round:NV #1#1
+}
+\cs_generate_variant:Nn \spath_bake_round:N {c}
+\cs_new_protected_nopar:Npn \spath_gbake_round:Nn #1#2
+{
+ \__spath_bake_round:n {#2}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gbake_round:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gbake_round:N #1
+{
+ \spath_gbake_round:NV #1#1
+}
+\cs_generate_variant:Nn \spath_gbake_round:N {c}
+\cs_new_protected_nopar:Npn \__spath_close:n #1
+{
+ \group_begin:
+ \tl_set:Nn \l__spath_tmpa_tl {#1}
+ \spath_initialpoint:NV \l__spath_tmpb_tl \l__spath_tmpa_tl
+ \tl_put_right:NV \l__spath_tmpa_tl \c_spath_closepath_tl
+ \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_close:Nn #1#2
+{
+ \__spath_close:n {#2}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_close:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_close:N #1
+{
+ \spath_close:NV #1#1
+}
+\cs_generate_variant:Nn \spath_close:N {c}
+\cs_new_protected_nopar:Npn \spath_gclose:Nn #1#2
+{
+ \__spath_close:n {#2}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gclose:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gclose:N #1
+{
+ \spath_gclose:NV #1#1
+}
+\cs_generate_variant:Nn \spath_gclose:N {c}
+\cs_new_protected_nopar:Npn \__spath_open:n #1
+{
+ \group_begin:
+ \tl_set:Nn \l__spath_tmpa_tl {#1}
+ \tl_clear:N \l__spath_tmpb_tl
+ \bool_until_do:nn {
+ \tl_if_empty_p:N \l__spath_tmpa_tl
}
- \tl_map_inline:Nn \g__spath_path_attributes
{
- \spath_if_in:nnT {#1} {##1}
+ \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+
+ \tl_case:NnF \l__spath_tmpc_tl
{
- \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl
- \tl_clear:N \l__spath_tmpb_tl
- \bool_until_do:nn {
- \tl_if_empty_p:N \l__spath_tmpa_tl
- }
- {
- \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ \c_spath_closepath_tl {
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl + #2}
+ \bool_if:nF
+ {
+ \dim_compare_p:n
+ {
+ \l__spath_move_x_dim == \l__spath_tmpa_dim
+ }
+ &&
+ \dim_compare_p:n
+ {
+ \l__spath_move_y_dim == \l__spath_tmpb_dim
+ }
+ }
+ {
+ \tl_put_right:NV \l__spath_tmpb_tl \c_spath_lineto_tl
+
+ \tl_put_right:Nx \l__spath_tmpb_tl {
+ { \dim_use:N \l__spath_move_x_dim }
+ { \dim_use:N \l__spath_move_y_dim }
+ }
+ }
+
+ \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
\tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ }
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl + #3}
+ \c_spath_moveto_tl {
+ \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpc_tl
+
+ \dim_set:Nn \l__spath_move_x_dim {\tl_head:N \l__spath_tmpa_tl}
\tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ \dim_set:Nn \l__spath_move_y_dim {\tl_head:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
+ \tl_put_right:Nx \l__spath_tmpb_tl {
+ { \dim_use:N \l__spath_move_x_dim }
+ { \dim_use:N \l__spath_move_y_dim }
}
+
+ \dim_set_eq:NN \l__spath_tmpa_dim \l__spath_move_x_dim
+ \dim_set_eq:NN \l__spath_tmpb_dim \l__spath_move_y_dim
}
- \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl
}
+ {
+ \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpc_tl
+
+ \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+
+ \tl_put_right:Nx \l__spath_tmpb_tl {
+ { \dim_use:N \l__spath_tmpa_dim }
+ { \dim_use:N \l__spath_tmpb_dim }
+ }
+ }
}
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl
+ \group_end:
}
-
-\cs_generate_variant:Nn \spath_translate:nnn {nxx}
-\cs_new_nopar:Npn \spath_translate:nn #1#2
+\cs_new_protected_nopar:Npn \spath_open:Nn #1#2
{
- \spath_translate:nnn {#1} #2
+ \__spath_open:n {#2}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
}
-
-\cs_generate_variant:Nn \spath_translate:nn {nV}
-\cs_new_nopar:Npn \spath_scale:nnn #1#2#3
+\cs_generate_variant:Nn \spath_open:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_open:N #1
{
- \tl_map_inline:Nn \g__spath_moveable_attributes
+ \spath_open:NV #1#1
+}
+\cs_new_protected_nopar:Npn \spath_gopen:Nn #1#2
+{
+ \__spath_open:n {#2}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gopen:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gopen:N #1
+{
+ \spath_gopen:NV #1#1
+}
+\cs_new_protected_nopar:Npn \__spath_remove_empty_components:n #1
+{
+ \group_begin:
+ \spath_components_to_seq:Nn \l__spath_tmpa_seq {#1}
+ \tl_clear:N \l__spath_tmpa_tl
+ \seq_map_inline:Nn \l__spath_tmpa_seq
{
- \spath_if_in:nnT {#1} {##1}
+ \int_compare:nF
{
- \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl
-
- \fp_set:Nn \l__spath_tmpa_fp {\tl_head:N \l__spath_tmpa_tl * #2}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \fp_set:Nn \l__spath_tmpb_fp {\tl_head:N \l__spath_tmpa_tl * #3}
- \tl_clear:N \l__spath_tmpb_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\fp_to_dim:N \l__spath_tmpa_fp}
- {\fp_to_dim:N \l__spath_tmpb_fp}
- }
- \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl
+ \tl_count:n {##1} == 3
}
+ {
+ \tl_put_right:Nn \l__spath_tmpa_tl {##1}
+ }
}
- \tl_map_inline:Nn \g__spath_path_attributes
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_remove_empty_components:Nn #1#2
+{
+ \__spath_remove_empty_components:n {#2}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_remove_empty_components:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_remove_empty_components:N #1
+{
+ \spath_remove_empty_components:NV #1#1
+}
+\cs_generate_variant:Nn \spath_remove_empty_components:N {c}
+\cs_new_protected_nopar:Npn \spath_gremove_empty_components:Nn #1#2
+{
+ \__spath_remove_empty_components:n {#2}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gremove_empty_components:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gremove_empty_components:N #1
+{
+ \spath_gremove_empty_components:NV #1#1
+}
+\cs_generate_variant:Nn \spath_gremove_empty_components:N {c}
+\prg_new_protected_conditional:Npnn \spath_if_eq:nn #1#2 { T, F, TF }
+{
+ \group_begin:
+ \tl_set:Nn \l__spath_tmpa_tl {#1}
+ \tl_set:Nn \l__spath_tmpb_tl {#2}
+ \bool_gset_true:N \g__spath_tmpa_bool
+ \int_compare:nNnTF {\tl_count:N \l__spath_tmpa_tl} = {\tl_count:N \l__spath_tmpb_tl}
{
- \spath_if_in:nnT {#1} {##1}
+ \int_step_inline:nnnn {1} {3} {\tl_count:N \l__spath_tmpa_tl}
{
- \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl
- \tl_clear:N \l__spath_tmpb_tl
- \bool_until_do:nn {
- \tl_if_empty_p:N \l__spath_tmpa_tl
+ \tl_set:Nx \l__spath_tmpc_tl {\tl_item:Nn \l__spath_tmpa_tl {##1}}
+ \tl_set:Nx \l__spath_tmpd_tl {\tl_item:Nn \l__spath_tmpb_tl {##1}}
+ \tl_if_eq:NNF \l__spath_tmpc_tl \l__spath_tmpd_tl
+ {
+ \bool_gset_false:N \g__spath_tmpa_bool
}
+ \dim_set:Nn \l__spath_tmpa_dim {\tl_item:Nn \l__spath_tmpa_tl {##1+1}}
+ \dim_set:Nn \l__spath_tmpb_dim {\tl_item:Nn \l__spath_tmpb_tl {##1+1}}
+ \dim_compare:nF { \dim_abs:n { \l__spath_tmpa_dim - \l__spath_tmpb_dim} < 0.001pt }
{
- \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \fp_set:Nn \l__spath_tmpa_fp {\tl_head:N \l__spath_tmpa_tl * #2}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \fp_set:Nn \l__spath_tmpb_fp {\tl_head:N \l__spath_tmpa_tl * #3}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
-
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\fp_to_dim:N \l__spath_tmpa_fp}
- {\fp_to_dim:N \l__spath_tmpb_fp}
- }
+ \bool_gset_false:N \g__spath_tmpa_bool
}
- \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl
+ \dim_set:Nn \l__spath_tmpa_dim {\tl_item:Nn \l__spath_tmpa_tl {##1+2}}
+ \dim_set:Nn \l__spath_tmpb_dim {\tl_item:Nn \l__spath_tmpb_tl {##1+2}}
+ \dim_compare:nF { \dim_abs:n { \l__spath_tmpa_dim - \l__spath_tmpb_dim} < 0.001pt }
+ {
+ \bool_gset_false:N \g__spath_tmpa_bool
+ }
}
}
+ {
+ \bool_gset_false:N \g__spath_tmpa_bool
+ }
+ \group_end:
+ \bool_if:NTF \g__spath_tmpa_bool
+ {
+ \prg_return_true:
+ }
+ {
+ \prg_return_false:
+ }
}
-\cs_generate_variant:Nn \spath_scale:nnn {nxx}
-\cs_new_nopar:Npn \spath_scale:nn #1#2
+\prg_generate_conditional_variant:Nnn \spath_if_eq:nn {VV, Vn, nV, vv} {TF, T, F}
+\cs_new_protected_nopar:Npn \__spath_split_curve:nn #1#2
{
- \spath_scale:nnn {#1} #2
-}
+ \group_begin:
+ \tl_set_eq:NN \l__spath_tmpa_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l__spath_tmpa_tl {
+ {\tl_item:nn {#1} {2}}
+ {\tl_item:nn {#1} {3}}
+ }
+ \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curvetoa_tl
+ \tl_put_right:Nx \l__spath_tmpa_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - #2) * \tl_item:nn {#1} {2} + (#2) * \tl_item:nn {#1} {5}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - #2) * \tl_item:nn {#1} {3} + (#2) * \tl_item:nn {#1} {6}
+ }}
+ }
-\cs_generate_variant:Nn \spath_scale:nn {nV}
-\cs_new_nopar:Npn \spath_transform:nnnnnnn #1#2#3#4#5#6#7
-{
- \tl_map_inline:Nn \g__spath_moveable_attributes
+ \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curvetob_tl
+ \tl_put_right:Nx \l__spath_tmpa_tl
{
- \spath_if_in:nnT {#1} {##1}
+ {\fp_to_dim:n
{
- \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_head:N \l__spath_tmpa_tl}
- \fp_set:Nn \l__spath_tmpa_fp {\l__spath_tmpa_tl * #2 + \l__spath_tmpb_tl * #3 + #6}
- \fp_set:Nn \l__spath_tmpb_fp {\l__spath_tmpa_tl * #4 + \l__spath_tmpb_tl * #5 + #7}
- \tl_clear:N \l__spath_tmpb_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
+ (1 - #2)^2 * \tl_item:nn {#1} {2} + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {5} + (#2)^2 * \tl_item:nn {#1} {8}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - #2)^2 * \tl_item:nn {#1} {3} + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {6} + (#2)^2 * \tl_item:nn {#1} {9}
+ }}
+ }
+
+ \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curveto_tl
+ \tl_put_right:Nx \l__spath_tmpa_tl
+ {
+ {\fp_to_dim:n
{
- {\fp_to_dim:N \l__spath_tmpa_fp}
- {\fp_to_dim:N \l__spath_tmpb_fp}
- }
- \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl
- }
+ (1 - #2)^3 * \tl_item:nn {#1} {2} + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {5} + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {8} + (#2)^3 * \tl_item:nn {#1} {11}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - #2)^3 * \tl_item:nn {#1} {3} + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {6} + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {9} + (#2)^3 * \tl_item:nn {#1} {12}
+ }}
}
- \tl_map_inline:Nn \g__spath_path_attributes
+
+ \tl_gclear:N \g__spath_output_tl
+ \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_tmpa_tl
+
+ \tl_clear:N \l__spath_tmpa_tl
+ \tl_set_eq:NN \l__spath_tmpa_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l__spath_tmpa_tl
{
- \spath_if_in:nnT {#1} {##1}
+ {\fp_to_dim:n
+ {
+ (1 - #2)^3 * \tl_item:nn {#1} {2} + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {5} + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {8} + (#2)^3 * \tl_item:nn {#1} {11}
+ }}
+ {\fp_to_dim:n
{
- \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl
- \tl_clear:N \l__spath_tmpb_tl
- \bool_until_do:nn {
- \tl_if_empty_p:N \l__spath_tmpa_tl
- }
- {
- \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ (1 - #2)^3 * \tl_item:nn {#1} {3} + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {6} + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {9} + (#2)^3 * \tl_item:nn {#1} {12}
+ }}
+ }
- \fp_set:Nn \l__spath_tmpa_fp {\l_tmpa_tl * #2 + \l_tmpb_tl * #3 + #6}
- \fp_set:Nn \l__spath_tmpb_fp {\l_tmpa_tl * #4 + \l_tmpb_tl * #5 + #7}
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\fp_to_dim:N \l__spath_tmpa_fp}
- {\fp_to_dim:N \l__spath_tmpb_fp}
- }
- }
- \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl
- }
+ \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curvetoa_tl
+ \tl_put_right:Nx \l__spath_tmpa_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - #2)^2 * \tl_item:nn {#1} {5} + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {8} + (#2)^2 * \tl_item:nn {#1} {11}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - #2)^2 * \tl_item:nn {#1} {6} + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {9} + (#2)^2 * \tl_item:nn {#1} {12}
+ }}
}
+ \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curvetob_tl
+ \tl_put_right:Nx \l__spath_tmpa_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - #2) * \tl_item:nn {#1} {8} + (#2) * \tl_item:nn {#1} {11}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - #2) * \tl_item:nn {#1} {9} + (#2) * \tl_item:nn {#1} {12}
+ }}
+ }
+ \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curveto_tl
+ \tl_put_right:Nx \l__spath_tmpa_tl {
+ {\tl_item:nn {#1} {11}}
+ {\tl_item:nn {#1} {12}}
+ }
+
+ \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_tmpa_tl
+ \group_end:
}
-
-\cs_generate_variant:Nn \spath_transform:nnnnnnn {nxxxxxx}
-\cs_new_nopar:Npn \spath_transform:nn #1#2
+\cs_new_protected_nopar:Npn \spath_split_curve:NNnn #1#2#3#4
{
- \spath_transform:nnnnnnn {#1} #2
+ \__spath_split_curve:nn {#3}{#4}
+ \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
+ \tl_set:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
+ \tl_gclear:N \g__spath_output_tl
}
-
-\cs_generate_variant:Nn \spath_transform:nn {nV}
-\cs_new_nopar:Npn \spath_reverse:n #1
+\cs_generate_variant:Nn \spath_split_curve:NNnn {NNnV, NNVn, NNVV}
+\cs_new_protected_nopar:Npn \spath_gsplit_curve:NNnn #1#2#3#4
{
- \spath_if_in:nnF {#1} {reverse path} {
- \use:c {spath_generate_reverse path:n} {#1}
+ \__spath_split_curve:nn {#3}{#4}
+ \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
+ \tl_gset:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gsplit_curve:NNnn {NNnV, NNVn, NNVV}
+\cs_new_protected_nopar:Npn \__spath_split_line:nn #1#2
+{
+ \group_begin:
+ \tl_set_eq:NN \l__spath_tmpa_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l__spath_tmpa_tl {
+ {\tl_item:nn {#1} {2}}
+ {\tl_item:nn {#1} {3}}
}
- \spath_swap:nnn {#1} {path} {reverse path}
- \spath_swap:nnn {#1} {initial point} {final point}
- \spath_swap:nnn {#1} {initial action} {final action}
+ \tl_put_right:NV \l__spath_tmpa_tl \c_spath_lineto_tl
+ \tl_put_right:Nx \l__spath_tmpa_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - #2) * \tl_item:nn {#1} {2} + (#2) * \tl_item:nn {#1} {5}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - #2) * \tl_item:nn {#1} {3} + (#2) * \tl_item:nn {#1} {6}
+ }}
+ }
+ \tl_gclear:N \g__spath_output_tl
+ \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_tmpa_tl
+
+ \tl_clear:N \l__spath_tmpa_tl
+ \tl_set_eq:NN \l__spath_tmpa_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l__spath_tmpa_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - #2) * \tl_item:nn {#1} {2} + (#2) * \tl_item:nn {#1} {5}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - #2) * \tl_item:nn {#1} {3} + (#2) * \tl_item:nn {#1} {6}
+ }}
+ }
+ \tl_put_right:NV \l__spath_tmpa_tl \c_spath_lineto_tl
+ \tl_put_right:Nx \l__spath_tmpa_tl {
+ {\tl_item:nn {#1} {5}}
+ {\tl_item:nn {#1} {6}}
+ }
+
+ \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_tmpa_tl
+ \group_end:
}
-\cs_new_nopar:Npn \spath_swap:nnn #1#2#3
+\cs_new_protected_nopar:Npn \spath_split_line:NNnn #1#2#3#4
{
- \__spath_get:nnNF {#1} {#2} \l__spath_tmpa_tl {\tl_clear:N \l__spath_tmpa_tl}
- \__spath_get:nnNF {#1} {#3} \l__spath_tmpb_tl {\tl_clear:N \l__spath_tmpb_tl}
- \tl_if_empty:NTF \l__spath_tmpb_tl
- {\spath_remove:nn {#1} {#2}}
- {\spath_put:nnV {#1} {#2} \l__spath_tmpb_tl}
- \tl_if_empty:NTF \l__spath_tmpa_tl
- {\spath_remove:nn {#1} {#3}}
- {\spath_put:nnV {#1} {#3} \l__spath_tmpa_tl}
+ \__spath_split_line:nn {#3}{#4}
+ \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
+ \tl_set:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
+ \tl_gclear:N \g__spath_output_tl
}
-\cs_new_nopar:Npn \spath_weld:nn #1#2
+\cs_generate_variant:Nn \spath_split_line:NNnn {NNnV, NNVn, NNVV}
+\cs_new_protected_nopar:Npn \spath_gsplit_line:NNnn #1#2#3#4
{
- \spath_clone:nn {#2} {tmp_path}
- \spath_get:nnN {#1} {final point} \l__spath_tmpa_tl
+ \__spath_split_line:nn {#3}{#4}
+ \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
+ \tl_gset:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gsplit_line:NNnn {NNnV, NNVn, NNVV}
+\int_new:N \l__spath_split_int
+\int_new:N \l__spath_splitat_int
+\fp_new:N \l__spath_split_fp
+\bool_new:N \l__spath_split_bool
+\tl_new:N \l__spath_split_path_tl
+\tl_new:N \l__spath_split_patha_tl
+\tl_new:N \l__spath_split_pathb_tl
+\tl_new:N \l__spath_split_intoa_tl
+\tl_new:N \l__spath_split_intob_tl
+\dim_new:N \l__spath_splitx_dim
+\dim_new:N \l__spath_splity_dim
+\cs_new_protected_nopar:Npn \__spath_split_at:nn #1#2
+{
+ \group_begin:
+ \int_set:Nn \l__spath_splitat_int {\fp_to_int:n {floor(#2) + 1}}
+ \fp_set:Nn \l__spath_split_fp {#2 - floor(#2)}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
-
- \spath_get:nnN {#2} {initial point} \l__spath_tmpa_tl
-
- \dim_sub:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_sub:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
-
- \spath_translate:nxx {tmp_path} {\dim_use:N \l__spath_tmpa_dim} {\dim_use:N \l__spath_tmpb_dim}
-
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \__spath_get:nnN {tmp_path} {path} \l__spath_tmpb_tl
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
-
- \spath_put:nnV {#1} {path} \l__spath_tmpa_tl
-
- \__spath_get:nnNTF {tmp_path} {final point} \l__spath_tmpa_tl
+ % Is split point near one end or other of a component?
+ \fp_compare:nT
{
- \spath_put:nnV {#1} {final point} \l__spath_tmpa_tl
+ \l__spath_split_fp < 0.01
}
{
- \spath_remove:nn {#1} {final point}
+ % Near the start, so we'll place it at the start
+ \fp_set:Nn \l__spath_split_fp {0}
}
-
- \__spath_get:nnNTF {tmp_path} {final action} \l__spath_tmpa_tl
+ \fp_compare:nT
{
- \spath_put:nnV {#1} {final action} \l__spath_tmpa_tl
+ \l__spath_split_fp > 0.99
}
{
- \spath_remove:nn {#1} {final action}
+ % Near the end, so we'll place it at the end
+ \fp_set:Nn \l__spath_split_fp {0}
+ \int_incr:N \l__spath_splitat_int
}
- \__spath_get:nnNT {tmp_path} {min bb} \l__spath_tmpa_tl
- {
- \__spath_get:nnNT {#1} {min bb} \l__spath_tmpb_tl
- {
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
+ \int_zero:N \l__spath_split_int
+ \bool_set_true:N \l__spath_split_bool
- \dim_set:Nn \l__spath_tmpa_dim {\dim_min:nn {\l__spath_tmpa_dim} {\tl_head:N \l__spath_tmpb_tl}}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\dim_min:nn {\l__spath_tmpb_dim} {\tl_head:N \l__spath_tmpb_tl}}
+ \tl_set:Nn \l__spath_split_path_tl {#1}
+ \tl_clear:N \l__spath_split_patha_tl
- \tl_clear:N \l__spath_tmpb_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- \spath_put:nnV {#1} {min bb} \l__spath_tmpb_tl
- }
+ \dim_zero:N \l__spath_splitx_dim
+ \dim_zero:N \l__spath_splity_dim
+
+ \bool_until_do:nn {
+ \tl_if_empty_p:N \l__spath_split_path_tl
+ ||
+ \int_compare_p:n { \l__spath_splitat_int == \l__spath_split_int }
}
-
- \__spath_get:nnNT {tmp_path} {max bb} \l__spath_tmpa_tl
{
- \__spath_get:nnNT {#1} {max bb} \l__spath_tmpb_tl
+ \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_split_path_tl}
+ \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl }
+ \tl_case:Nn \l__spath_tmpc_tl
{
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
-
- \dim_set:Nn \l__spath_tmpa_dim {\dim_max:nn {\l__spath_tmpa_dim} {\tl_head:N \l__spath_tmpb_tl}}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \dim_set:Nn \l__spath_tmpb_dim {\dim_max:nn {\l__spath_tmpb_dim} {\tl_head:N \l__spath_tmpb_tl}}
-
- \tl_clear:N \l__spath_tmpb_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
+ \c_spath_lineto_tl
{
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
+ \int_incr:N \l__spath_split_int
}
- \spath_put:nnV {#1} {max bb} \l__spath_tmpb_tl
+ \c_spath_curvetoa_tl
+ {
+ \int_incr:N \l__spath_split_int
+ }
}
- }
-
- \__spath_get:nnNT {tmp_path} {reverse path} \l__spath_tmpa_tl
- {
- \__spath_get:nnNT {#1} {reverse path} \l__spath_tmpb_tl
+ \int_compare:nT { \l__spath_split_int < \l__spath_splitat_int }
{
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
+ \tl_put_right:NV \l__spath_split_patha_tl \l__spath_tmpc_tl
- \spath_put:nnV {#1} {reverse path} \l__spath_tmpa_tl
+ \tl_put_right:Nx \l__spath_split_patha_tl
+ {{ \tl_head:N \l__spath_split_path_tl }}
+ \dim_set:Nn \l__spath_splitx_dim {\tl_head:N \l__spath_split_path_tl}
+ \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl }
+
+ \tl_put_right:Nx \l__spath_split_patha_tl
+ {{ \tl_head:N \l__spath_split_path_tl }}
+ \dim_set:Nn \l__spath_splity_dim {\tl_head:N \l__spath_split_path_tl}
+ \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl }
+
}
}
- \__spath_get:nnNT {tmp_path} {length} \l__spath_tmpa_tl
+ \tl_clear:N \l__spath_split_pathb_tl
+ \tl_put_right:NV \l__spath_split_pathb_tl \c_spath_moveto_tl
+ \tl_put_right:Nx \l__spath_split_pathb_tl
{
- \__spath_get:nnNT {#1} {length} \l__spath_tmpb_tl
- {
- \int_set:Nn \l__spath_tmpa_int {\l__spath_tmpa_tl + \l__spath_tmpb_tl - 1}
- \spath_put:nnV {#1} {length} \l__spath_tmpa_int
- }
+ {\dim_use:N \l__spath_splitx_dim}
+ {\dim_use:N \l__spath_splity_dim}
}
- \__spath_get:nnNT {tmp_path} {real length} \l__spath_tmpa_tl
+ \fp_compare:nTF
{
- \__spath_get:nnNT {#1} {real length} \l__spath_tmpb_tl
+ \l__spath_split_fp == 0
+ }
+ {
+ \tl_set_eq:NN \l__spath_split_intob_tl \l__spath_split_pathb_tl
+ \tl_if_empty:NF \l__spath_split_path_tl
{
- \int_set:Nn \l__spath_tmpa_int {\l__spath_tmpa_tl + \l__spath_tmpb_tl}
- \spath_put:nnV {#1} {real length} \l__spath_tmpa_int
+ \tl_put_right:NV \l__spath_split_intob_tl \l__spath_tmpc_tl
+ \tl_put_right:NV \l__spath_split_intob_tl \l__spath_split_path_tl
}
}
+ {
- \__spath_get:nnNT {tmp_path} {number of components} \l__spath_tmpa_tl
- {
- \__spath_get:nnNT {#1} {number of components} \l__spath_tmpb_tl
+ \tl_case:Nn \l__spath_tmpc_tl
{
- \int_set:Nn \l__spath_tmpa_int {\l__spath_tmpa_tl + \l__spath_tmpb_tl - 1}
- \spath_put:nnV {#1} {number of components} \l__spath_tmpa_int
+ \c_spath_lineto_tl
+ {
+ \tl_put_right:NV \l__spath_split_pathb_tl \l__spath_tmpc_tl
+ \tl_put_right:Nx \l__spath_split_pathb_tl
+ {{ \tl_head:N \l__spath_split_path_tl }}
+ \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl }
+
+ \tl_put_right:Nx \l__spath_split_pathb_tl
+ {{ \tl_head:N \l__spath_split_path_tl }}
+ \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl }
+
+ \spath_split_line:NNVV
+ \l__spath_split_intoa_tl
+ \l__spath_split_intob_tl
+ \l__spath_split_pathb_tl
+ \l__spath_split_fp
+
+ \prg_replicate:nn {3} {
+ \tl_set:Nx \l__spath_split_intoa_tl {\tl_tail:N \l__spath_split_intoa_tl}
+ }
+
+ \tl_put_right:NV \l__spath_split_patha_tl \l__spath_split_intoa_tl
+ \tl_put_right:NV \l__spath_split_intob_tl \l__spath_split_path_tl
+ }
+ \c_spath_curvetoa_tl
+ {
+ \tl_put_right:NV \l__spath_split_pathb_tl \l__spath_tmpc_tl
+ \tl_put_right:Nx \l__spath_split_pathb_tl
+ {{ \tl_head:N \l__spath_split_path_tl }}
+ \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl }
+
+ \tl_put_right:Nx \l__spath_split_pathb_tl
+ {{ \tl_head:N \l__spath_split_path_tl }}
+ \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl }
+
+ \prg_replicate:nn {2} {
+
+ \tl_put_right:Nx \l__spath_split_pathb_tl
+ { \tl_head:N \l__spath_split_path_tl }
+ \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl }
+
+ \tl_put_right:Nx \l__spath_split_pathb_tl
+ {{ \tl_head:N \l__spath_split_path_tl }}
+ \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl }
+
+ \tl_put_right:Nx \l__spath_split_pathb_tl
+ {{ \tl_head:N \l__spath_split_path_tl }}
+ \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl }
+ }
+
+ \spath_split_curve:NNVV
+ \l__spath_split_intoa_tl
+ \l__spath_split_intob_tl
+ \l__spath_split_pathb_tl \l__spath_split_fp
+
+ \prg_replicate:nn {3} {
+ \tl_set:Nx \l__spath_split_intoa_tl {\tl_tail:N \l__spath_split_intoa_tl}
+ }
+
+ \tl_put_right:NV \l__spath_split_patha_tl \l__spath_split_intoa_tl
+ \tl_put_right:NV \l__spath_split_intob_tl \l__spath_split_path_tl
+ }
}
}
+ \tl_gclear:N \g__spath_output_tl
+ \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_split_patha_tl
+ \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_split_intob_tl
+ \group_end:
}
-\cs_new_nopar:Npn \spath_prepend_no_move:nn #1#2
+\cs_new_protected_nopar:Npn \spath_split_at:NNnn #1#2#3#4
{
- \spath_if_exist:nT {#2}
+ \__spath_split_at:nn {#3}{#4}
+ \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
+ \tl_set:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_split_at:NNnn {NNVn, NNVV, NNnV}
+\cs_new_protected_nopar:Npn \spath_gsplit_at:NNnn #1#2#3#4
+{
+ \__spath_split_at:nn {#3}{#4}
+ \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
+ \tl_gset:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gsplit_at:NNnn {NNVn, NNVV, NNnV}
+\cs_new_protected_nopar:Npn \spath_split_at:Nnn #1#2#3
+{
+ \__spath_split_at:nn {#2}{#3}
+ \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1} \tl_item:Nn \g__spath_output_tl {2}}
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_split_at:Nnn {NVn, NVV}
+\cs_new_protected_nopar:Npn \spath_split_at:Nn #1#2
+{
+ \spath_split_at:NVn #1#1{#2}
+}
+\cs_new_protected_nopar:Npn \spath_gsplit_at:Nnn #1#2#3
+{
+ \__spath_split_at:nn {#2}{#3}
+ \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1} \tl_item:Nn \g__spath_output_tl {2}}
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gsplit_at:Nnn {NVn, NVV}
+\cs_new_protected_nopar:Npn \spath_gsplit_at:Nn #1#2
+{
+ \spath_gsplit_at:NVn #1#1{#2}
+}
+\tl_new:N \l__spath_shorten_fa_tl
+\tl_new:N \l__spath_shorten_path_tl
+\tl_new:N \l__spath_shorten_last_tl
+\tl_new:N \l__spath_shorten_lasta_tl
+\tl_new:N \l__spath_shorten_lastb_tl
+\int_new:N \l__spath_shorten_int
+\fp_new:N \l__spath_shorten_x_fp
+\fp_new:N \l__spath_shorten_y_fp
+\fp_new:N \l__spath_shorten_len_fp
+\cs_new_protected_nopar:Npn \__spath_shorten_at_end:nn #1#2
+{
+ \int_compare:nTF
{
- \__spath_get:nnN {#2} {path} \l__spath_tmpa_tl
- \__spath_get:nnN {#1} {path} \l__spath_tmpb_tl
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
- \spath_put:nnV {#1} {path} \l__spath_tmpa_tl
+ \tl_count:n {#1} > 3
+ }
+ {
+ \group_begin:
+ \tl_set:Nn \l__spath_shorten_path_tl {#1}
+ \tl_reverse:N \l__spath_shorten_path_tl
- \spath_if_in:nnTF {#2} {initial point}
+ \tl_set:Nx \l__spath_shorten_fa_tl {\tl_item:Nn \l__spath_shorten_path_tl {3}}
+
+ \tl_clear:N \l__spath_shorten_last_tl
+ \tl_if_eq:NNTF \l__spath_shorten_fa_tl \c_spath_curveto_tl
{
- \__spath_get:nnN {#2} {initial point} \l__spath_tmpa_tl
- \spath_put:nnV {#1} {initial point} \l__spath_tmpa_tl
+ \int_set:Nn \l__spath_shorten_int {3}
}
{
- \spath_remove:nn {#1} {initial point}
+ \int_set:Nn \l__spath_shorten_int {1}
}
- \spath_if_in:nnTF {#2} {initial action}
+ \prg_replicate:nn { \l__spath_shorten_int }
{
- \__spath_get:nnN {#2} {initial action} \l__spath_tmpa_tl
- \spath_put:nnV {#1} {initial action} \l__spath_tmpa_tl
+ \tl_put_right:Nx \l__spath_shorten_last_tl
+ {
+ {\tl_head:N \l__spath_shorten_path_tl}
+ }
+ \tl_set:Nx \l__spath_shorten_path_tl {\tl_tail:N \l__spath_shorten_path_tl}
+ \tl_put_right:Nx \l__spath_shorten_last_tl
+ {
+ {\tl_head:N \l__spath_shorten_path_tl}
+ }
+ \tl_set:Nx \l__spath_shorten_path_tl {\tl_tail:N \l__spath_shorten_path_tl}
+ \tl_put_right:Nx \l__spath_shorten_last_tl
+ {
+ \tl_head:N \l__spath_shorten_path_tl
+ }
+ \tl_set:Nx \l__spath_shorten_path_tl {\tl_tail:N \l__spath_shorten_path_tl}
}
+
+ \tl_put_right:Nx \l__spath_shorten_last_tl
{
- \spath_remove:nn {#1} {initial action}
+ {\tl_item:Nn \l__spath_shorten_path_tl {1}}
+ {\tl_item:Nn \l__spath_shorten_path_tl {2}}
}
+ \tl_put_right:NV \l__spath_shorten_last_tl \c_spath_moveto_tl
- \bool_if:nTF
+ \tl_reverse:N \l__spath_shorten_path_tl
+
+ \fp_set:Nn \l__spath_shorten_x_fp
{
- \spath_if_in_p:nn {#1} {length}
- &&
- \spath_if_in_p:nn {#2} {length}
+ \dim_to_fp:n {\tl_item:Nn \l__spath_shorten_last_tl {4}}
+ -
+ \dim_to_fp:n {\tl_item:Nn \l__spath_shorten_last_tl {1}}
}
+
+ \fp_set:Nn \l__spath_shorten_y_fp
{
- \__spath_get:nnN {#1} {length} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {length} \l__spath_tmpb_tl
- \spath_put:nnx {#1} {length} {\int_eval:n {\l__spath_tmpa_tl +
- \l__spath_tmpb_tl - 1}}
+ \dim_to_fp:n {\tl_item:Nn \l__spath_shorten_last_tl {5}}
+ -
+ \dim_to_fp:n {\tl_item:Nn \l__spath_shorten_last_tl {2}}
}
+
+ \fp_set:Nn \l__spath_shorten_len_fp
{
- \spath_remove:nn {#1} {length}
+ sqrt( \l__spath_shorten_x_fp * \l__spath_shorten_x_fp + \l__spath_shorten_y_fp * \l__spath_shorten_y_fp )
}
- \bool_if:nTF
+
+ \fp_compare:nTF
{
- \spath_if_in_p:nn {#1} {real length}
- &&
- \spath_if_in_p:nn {#2} {real length}
+ \l__spath_shorten_len_fp > #2
}
{
- \__spath_get:nnN {#1} {real length} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {real length} \l__spath_tmpb_tl
- \spath_put:nnx {#1} {real length} {\int_eval:n {\l__spath_tmpa_tl +
- \l__spath_tmpb_tl }}
+
+ \fp_set:Nn \l__spath_shorten_len_fp
+ {
+ (\l__spath_shorten_len_fp - #2)/ \l__spath_shorten_len_fp
+ }
+
+ \tl_reverse:N \l__spath_shorten_last_tl
+
+ \tl_if_eq:NNTF \l__spath_shorten_fa_tl \c_spath_curveto_tl
+ {
+ \fp_set:Nn \l__spath_shorten_len_fp
+ {
+ 1 - (1 -\l__spath_shorten_len_fp)/3
+ }
+ \spath_split_curve:NNVV
+ \l__spath_shorten_lasta_tl
+ \l__spath_shorten_lastb_tl
+ \l__spath_shorten_last_tl
+ \l__spath_shorten_len_fp
+ }
+ {
+ \spath_split_line:NNVV
+ \l__spath_shorten_lasta_tl
+ \l__spath_shorten_lastb_tl
+ \l__spath_shorten_last_tl
+ \l__spath_shorten_len_fp
+ }
+
+ \prg_replicate:nn {3}
+ {
+ \tl_set:Nx \l__spath_shorten_lasta_tl {\tl_tail:N \l__spath_shorten_lasta_tl}
+ }
+
+ \tl_put_right:NV \l__spath_shorten_path_tl \l__spath_shorten_lasta_tl
+
}
{
- \spath_remove:nn {#1} {real length}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {number of components}
- &&
- \spath_if_in_p:nn {#2} {number of components}
- }
- {
- \__spath_get:nnN {#1} {number of components} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {number of components} \l__spath_tmpb_tl
- \spath_put:nnx {#1} {number of components} {\int_eval:n {\l__spath_tmpa_tl +
- \l__spath_tmpb_tl - 1}}
- }
- {
- \spath_remove:nn {#1} {number of components}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {min bb}
- &&
- \spath_if_in_p:nn {#2} {min bb}
- }
- {
- \__spath_get:nnN {#1} {min bb} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {min bb} \l__spath_tmpb_tl
- \dim_set:Nn \l__spath_tmpa_dim {\dim_min:nn {\tl_item:Nn
- \l__spath_tmpa_tl {1}} {\tl_item:Nn
- \l__spath_tmpb_tl {1}}}
- \dim_set:Nn \l__spath_tmpb_dim {\dim_min:nn {\tl_item:Nn
- \l__spath_tmpa_tl {2}} {\tl_item:Nn
- \l__spath_tmpb_tl {2}}}
- \spath_put:nnx {#1} {min bb} {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
+
+ \int_compare:nT
+ {
+ \tl_count:N \l__spath_shorten_path_tl > 3
}
+ {
+ \dim_set:Nn \l__spath_tmpa_dim {\fp_to_dim:n {#2 - \l__spath_shorten_len_fp } }
+ \spath_shorten_at_end:NV \l__spath_shorten_path_tl \l__spath_tmpa_dim
+ }
}
+
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_shorten_path_tl
+ \group_end:
+ }
+ {
+ \tl_gset:Nn \g__spath_output_tl {#1}
+ }
+}
+\cs_new_protected_nopar:Npn \spath_shorten_at_end:Nnn #1#2#3
+{
+ \__spath_shorten_at_end:nn {#2}{#3}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_shorten_at_end:Nnn {NVV, cnn, cVV, NVn}
+\cs_new_protected_nopar:Npn \spath_shorten_at_end:Nn #1#2
+{
+ \spath_shorten_at_end:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_shorten_at_end:Nn {cn, cV, NV}
+\cs_new_protected_nopar:Npn \spath_gshorten_at_end:Nnn #1#2#3
+{
+ \__spath_shorten_at_end:nn {#2}{#3}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gshorten_at_end:Nnn {NVV, cnn, cVV, NVn}
+\cs_new_protected_nopar:Npn \spath_gshorten_at_end:Nn #1#2
+{
+ \spath_gshorten_at_end:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_gshorten_at_end:Nn {cn, cV, NV}
+\cs_new_protected_nopar:Npn \__spath_shorten_at_start:nn #1#2
+{
+ \int_compare:nTF
+ {
+ \tl_count:n {#1} > 3
+ }
+ {
+ \group_begin:
+ \tl_set:Nn \l__spath_shorten_path_tl {#1}
+
+ \tl_set:Nx \l__spath_shorten_fa_tl {\tl_item:Nn \l__spath_shorten_path_tl {4}}
+
+ \tl_clear:N \l__spath_shorten_last_tl
+
+ \tl_if_eq:NNTF \l__spath_shorten_fa_tl \c_spath_curvetoa_tl
+ {
+ \int_set:Nn \l__spath_shorten_int {3}
+ }
+ {
+ \int_set:Nn \l__spath_shorten_int {1}
+ }
+
+ \tl_set_eq:NN \l__spath_shorten_last_tl \c_spath_moveto_tl
+ \tl_set:Nx \l__spath_shorten_path_tl {\tl_tail:N \l__spath_shorten_path_tl }
+
+ \prg_replicate:nn { \l__spath_shorten_int }
+ {
+ \__spath_tl_put_right_braced:Nx \l__spath_shorten_last_tl {\tl_item:Nn \l__spath_shorten_path_tl {1}}
+ \__spath_tl_put_right_braced:Nx \l__spath_shorten_last_tl {\tl_item:Nn \l__spath_shorten_path_tl {2}}
+ \tl_put_right:Nx \l__spath_shorten_last_tl {\tl_item:Nn \l__spath_shorten_path_tl {3}}
+
+ \prg_replicate:nn {3}
{
- \spath_remove:nn {#1} {min bb}
+ \tl_set:Nx \l__spath_shorten_path_tl {\tl_tail:N \l__spath_shorten_path_tl }
}
- \bool_if:nTF
+ }
+ \__spath_tl_put_right_braced:Nx \l__spath_shorten_last_tl {\tl_item:Nn \l__spath_shorten_path_tl {1}}
+ \__spath_tl_put_right_braced:Nx \l__spath_shorten_last_tl {\tl_item:Nn \l__spath_shorten_path_tl {2}}
+
+ \fp_set:Nn \l__spath_shorten_x_fp
+ {
+ \dim_to_fp:n {\tl_item:Nn \l__spath_shorten_last_tl {5}}
+ -
+ \dim_to_fp:n {\tl_item:Nn \l__spath_shorten_last_tl {2}}
+ }
+
+ \fp_set:Nn \l__spath_shorten_y_fp
+ {
+ \dim_to_fp:n {\tl_item:Nn \l__spath_shorten_last_tl {6}}
+ -
+ \dim_to_fp:n {\tl_item:Nn \l__spath_shorten_last_tl {3}}
+ }
+
+ \fp_set:Nn \l__spath_shorten_len_fp
+ {
+ sqrt( \l__spath_shorten_x_fp * \l__spath_shorten_x_fp + \l__spath_shorten_y_fp * \l__spath_shorten_y_fp )
+ }
+
+ \fp_compare:nTF
+ {
+ \l__spath_shorten_len_fp > #2
+ }
+ {
+
+ \fp_set:Nn \l__spath_shorten_len_fp
{
- \spath_if_in_p:nn {#1} {max bb}
- &&
- \spath_if_in_p:nn {#2} {max bb}
+ #2/ \l__spath_shorten_len_fp
}
+
+ \tl_if_eq:NNTF \l__spath_shorten_fa_tl \c_spath_curvetoa_tl
{
- \__spath_get:nnN {#1} {max bb} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {max bb} \l__spath_tmpb_tl
- \dim_set:Nn \l__spath_tmpa_dim {\dim_min:nn {\tl_item:Nn
- \l__spath_tmpa_tl {1}} {\tl_item:Nn
- \l__spath_tmpb_tl {1}}}
- \dim_set:Nn \l__spath_tmpb_dim {\dim_min:nn {\tl_item:Nn
- \l__spath_tmpa_tl {2}} {\tl_item:Nn
- \l__spath_tmpb_tl {2}}}
- \spath_put:nnx {#1} {max bb} {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
+ \fp_set:Nn \l__spath_shorten_len_fp
+ {
+ \l__spath_shorten_len_fp/3
}
+ \spath_split_curve:NNVV
+ \l__spath_shorten_lasta_tl
+ \l__spath_shorten_lastb_tl
+ \l__spath_shorten_last_tl
+ \l__spath_shorten_len_fp
}
{
- \spath_remove:nn {#1} {max bb}
+ \spath_split_line:NNVV
+ \l__spath_shorten_lasta_tl
+ \l__spath_shorten_lastb_tl
+ \l__spath_shorten_last_tl
+ \l__spath_shorten_len_fp
}
- \bool_if:nTF
+
+ \prg_replicate:nn {2}
{
- \spath_if_in_p:nn {#1} {reverse path}
- &&
- \spath_if_in_p:nn {#2} {reverse path}
+ \tl_set:Nx \l__spath_shorten_path_tl {\tl_tail:N \l__spath_shorten_path_tl}
}
+
+ \tl_put_left:NV \l__spath_shorten_path_tl \l__spath_shorten_lastb_tl
+
+ }
+ {
+
+ \tl_put_left:NV \l__spath_shorten_path_tl \c_spath_moveto_tl
+
+ \int_compare:nT
{
- \__spath_get:nnN {#1} {reverse path} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {reverse path} \l__spath_tmpb_tl
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
- \spath_put:nnV {#1} {reverse path} \l__spath_tmpb_tl
+ \tl_count:N \l__spath_shorten_path_tl > 3
}
{
- \spath_remove:nn {#1} {reverse path}
+ \dim_set:Nn \l__spath_tmpa_dim {\fp_to_dim:n {#2 - \l__spath_shorten_len_fp } }
+ \spath_shorten_at_start:NV \l__spath_shorten_path_tl \l__spath_tmpa_dim
}
+ }
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_shorten_path_tl
+ \group_end:
}
+ {
+ \tl_gset:Nn \g__spath_output_tl {#1}
+ }
}
-\cs_new_nopar:Npn \spath_append_no_move:nn #1#2
+\cs_new_protected_nopar:Npn \spath_shorten_at_start:Nnn #1#2#3
{
- \spath_if_exist:nT {#2}
+ \__spath_shorten_at_start:nn {#2}{#3}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_shorten_at_start:Nnn {NVV, cnn, cVV, NVn}
+\cs_new_protected_nopar:Npn \spath_shorten_at_start:Nn #1#2
+{
+ \spath_shorten_at_start:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_shorten_at_start:Nn {cn, cV, NV}
+\cs_new_protected_nopar:Npn \spath_gshorten_at_start:Nnn #1#2#3
+{
+ \__spath_shorten_at_start:nn {#2}{#3}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gshorten_at_start:Nnn {NVV, cnn, cVV, NVn}
+\cs_new_protected_nopar:Npn \spath_gshorten_at_start:Nn #1#2
+{
+ \spath_gshorten_at_start:NVn #1#1{#2}
+}
+\cs_generate_variant:Nn \spath_gshorten_at_start:Nn {cn, cV, NV}
+\cs_new_protected_nopar:Npn \__spath_point_at:nn #1#2
+{
+ \group_begin:
+ \int_set:Nn \l__spath_tmpa_int {\fp_to_int:n {floor(#2) + 1}}
+ \fp_set:Nn \l__spath_tmpa_fp {#2 - floor(#2)}
+
+ \spath_segments_to_seq:Nn \l__spath_tmpa_seq {#1}
+
+ \int_compare:nTF
{
- \spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \spath_get:nnN {#2} {path} \l__spath_tmpb_tl
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
- \spath_put:nnV {#1} {path} \l__spath_tmpa_tl
- \spath_if_in:nnTF {#2} {final point}
+ \l__spath_tmpa_int < 1
+ }
+ {
+ \spath_initialpoint:Nn \l__spath_tmpc_tl {#1}
+ }
+ {
+ \int_compare:nTF
{
- \__spath_get:nnN {#2} {final point} \l__spath_tmpa_tl
- \spath_put:nnV {#1} {final point} \l__spath_tmpa_tl
+ \l__spath_tmpa_int > \seq_count:N \l__spath_tmpa_seq
}
{
- \spath_remove:nn {#1} {final point}
+ \spath_finalpoint:Nn \l__spath_tmpc_tl {#1}
}
- \spath_if_in:nnTF {#2} {final action}
{
- \__spath_get:nnN {#2} {final action} \l__spath_tmpa_tl
- \spath_put:nnV {#1} {final action} \l__spath_tmpa_tl
- }
- {
- \spath_remove:nn {#1} {final action}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {length}
- &&
- \spath_if_in_p:nn {#2} {length}
- }
- {
- \__spath_get:nnN {#1} {length} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {length} \l__spath_tmpb_tl
- \spath_put:nnx {#1} {length} {\int_eval:n {\l__spath_tmpa_tl +
- \l__spath_tmpb_tl - 1}}
- }
- {
- \spath_remove:nn {#1} {length}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {real length}
- &&
- \spath_if_in_p:nn {#2} {real length}
- }
- {
- \__spath_get:nnN {#1} {real length} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {real length} \l__spath_tmpb_tl
- \spath_put:nnx {#1} {real length} {\int_eval:n {\l__spath_tmpa_tl +
- \l__spath_tmpb_tl }}
- }
- {
- \spath_remove:nn {#1} {real length}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {number of components}
- &&
- \spath_if_in_p:nn {#2} {number of components}
- }
- {
- \__spath_get:nnN {#1} {number of components} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {number of components} \l__spath_tmpb_tl
- \spath_put:nnx {#1} {number of components} {\int_eval:n {\l__spath_tmpa_tl +
- \l__spath_tmpb_tl - 1}}
- }
- {
- \spath_remove:nn {#1} {number of components}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {min bb}
- &&
- \spath_if_in_p:nn {#2} {min bb}
- }
- {
- \__spath_get:nnN {#1} {min bb} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {min bb} \l__spath_tmpb_tl
- \dim_set:Nn \l__spath_tmpa_dim {\dim_min:nn {\tl_item:Nn
- \l__spath_tmpa_tl {1}} {\tl_item:Nn
- \l__spath_tmpb_tl {1}}}
- \dim_set:Nn \l__spath_tmpb_dim {\dim_min:nn {\tl_item:Nn
- \l__spath_tmpa_tl {2}} {\tl_item:Nn
- \l__spath_tmpb_tl {2}}}
- \spath_put:nnx {#1} {min bb} {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
+
+ \tl_set:Nx \l__spath_tmpa_tl {\seq_item:Nn \l__spath_tmpa_seq { \l__spath_tmpa_int} }
+
+ \int_compare:nTF
+ {
+ \tl_count:N \l__spath_tmpa_tl > 3
}
+ {
+ \tl_set:Nx \l__spath_tmpb_tl {\tl_item:Nn \l__spath_tmpa_tl {4}}
+ }
+ {
+ \tl_set:Nx \l__spath_tmpb_tl {\tl_item:Nn \l__spath_tmpa_tl {1}}
+ }
+
+ \tl_clear:N \l__spath_tmpc_tl
+
+ \tl_case:Nn \l__spath_tmpb_tl
+ {
+ \c_spath_moveto_tl
+ {
+ \tl_set:Nx \l__spath_tmpc_tl
+ {
+ {
+ \tl_item:Nn \l__spath_tmpa_tl {2}
+ }
+ {
+ \tl_item:Nn \l__spath_tmpa_tl {3}
+ }
+ }
+ }
+
+ \c_spath_lineto_tl
+ {
+ \tl_set:Nx \l__spath_tmpc_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - \l__spath_tmpa_fp) * ( \tl_item:Nn \l__spath_tmpa_tl {2} )
+ +
+ \l__spath_tmpa_fp * ( \tl_item:Nn \l__spath_tmpa_tl {5} )
+ }
+ }
+ {\fp_to_dim:n
+ {
+ (1 - \l__spath_tmpa_fp) * ( \tl_item:Nn \l__spath_tmpa_tl {3} )
+ +
+ \l__spath_tmpa_fp * ( \tl_item:Nn \l__spath_tmpa_tl {6} )
+ }
+ }
+ }
+ }
+
+ \c_spath_closepath_tl
+ {
+ \tl_set:Nx \l__spath_tmpc_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - \l__spath_tmpa_fp) * ( \tl_item:Nn \l__spath_tmpa_tl {2} )
+ +
+ \l__spath_tmpa_fp * ( \tl_item:Nn \l__spath_tmpa_tl {5} )
+ }
+ }
+ {\fp_to_dim:n
+ {
+ (1 - \l__spath_tmpa_fp) * ( \tl_item:Nn \l__spath_tmpa_tl {3} )
+ +
+ \l__spath_tmpa_fp * ( \tl_item:Nn \l__spath_tmpa_tl {6} )
+ }
+ }
+ }
+ }
+
+ \c_spath_curvetoa_tl
+ {
+ \tl_set:Nx \l__spath_tmpc_tl
+ {
+ {\fp_to_dim:n
+ {
+ (1 - \l__spath_tmpa_fp)^3 * \tl_item:Nn \l__spath_tmpa_tl {2} + 3 * (1 - \l__spath_tmpa_fp)^2 * (\l__spath_tmpa_fp) * \tl_item:Nn \l__spath_tmpa_tl {5} + 3 * (1 - \l__spath_tmpa_fp) * (\l__spath_tmpa_fp)^2 * \tl_item:Nn \l__spath_tmpa_tl {8} + (\l__spath_tmpa_fp)^3 * \tl_item:Nn \l__spath_tmpa_tl {11}
+ }}
+ {\fp_to_dim:n
+ {
+ (1 - \l__spath_tmpa_fp)^3 * \tl_item:Nn \l__spath_tmpa_tl {3} + 3 * (1 - \l__spath_tmpa_fp)^2 * (\l__spath_tmpa_fp) * \tl_item:Nn \l__spath_tmpa_tl {6} + 3 * (1 - \l__spath_tmpa_fp) * (\l__spath_tmpa_fp)^2 * \tl_item:Nn \l__spath_tmpa_tl {9} + (\l__spath_tmpa_fp)^3 * \tl_item:Nn \l__spath_tmpa_tl {12}
+ }}
+ }
+ }
+ }
}
+ }
+
+ \tl_gclear:N \g__spath_output_tl
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpc_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_point_at:Nnn #1#2#3
+{
+ \__spath_point_at:nn {#2}{#3}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_point_at:Nnn {NVn, NVV, NnV}
+\cs_new_protected_nopar:Npn \spath_gpoint_at:Nnn #1#2#3
+{
+ \__spath_point_at:nn {#2}{#3}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gpoint_at:Nnn {NVn, NVV, NnV}
+\cs_new_protected_nopar:Npn \__spath_tangent_at:nn #1#2
+{
+ \group_begin:
+ \int_set:Nn \l__spath_tmpa_int {\fp_to_int:n {floor(#2) + 1}}
+ \fp_set:Nn \l__spath_tmpa_fp {#2 - floor(#2)}
+
+ \spath_segments_to_seq:Nn \l__spath_tmpa_seq {#1}
+
+ \int_compare:nTF
+ {
+ \l__spath_tmpa_int < 1
+ }
+ {
+ \spath_initialpoint:Nn \l__spath_tmpc_tl {#1}
+ }
+ {
+ \int_compare:nTF
{
- \spath_remove:nn {#1} {min bb}
+ \l__spath_tmpa_int > \seq_count:N \l__spath_tmpa_seq
}
- \bool_if:nTF
{
- \spath_if_in_p:nn {#1} {max bb}
- &&
- \spath_if_in_p:nn {#2} {max bb}
+ \spath_finalpoint:Nn \l__spath_tmpc_tl {#1}
}
{
- \__spath_get:nnN {#1} {max bb} \l__spath_tmpa_tl
- \__spath_get:nnN {#2} {max bb} \l__spath_tmpb_tl
- \dim_set:Nn \l__spath_tmpa_dim {\dim_min:nn {\tl_item:Nn
- \l__spath_tmpa_tl {1}} {\tl_item:Nn
- \l__spath_tmpb_tl {1}}}
- \dim_set:Nn \l__spath_tmpb_dim {\dim_min:nn {\tl_item:Nn
- \l__spath_tmpa_tl {2}} {\tl_item:Nn
- \l__spath_tmpb_tl {2}}}
- \spath_put:nnx {#1} {max bb} {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
+
+ \tl_set:Nx \l__spath_tmpa_tl {\seq_item:Nn \l__spath_tmpa_seq { \l__spath_tmpa_int} }
+
+ \int_compare:nTF
+ {
+ \tl_count:N \l__spath_tmpa_tl > 3
}
+ {
+ \tl_set:Nx \l__spath_tmpb_tl {\tl_item:Nn \l__spath_tmpa_tl {4}}
+ }
+ {
+ \tl_set:Nx \l__spath_tmpb_tl {\tl_item:Nn \l__spath_tmpa_tl {1}}
+ }
+
+ \tl_clear:N \l__spath_tmpc_tl
+
+ \tl_case:Nn \l__spath_tmpb_tl
+ {
+ \c_spath_moveto_tl
+ {
+ \tl_set:Nx \l__spath_tmpc_tl
+ {
+ {
+ \tl_item:Nn \l__spath_tmpa_tl {2}
+ }
+ {
+ \tl_item:Nn \l__spath_tmpa_tl {3}
+ }
+ }
+ }
+
+ \c_spath_lineto_tl
+ {
+ \tl_set:Nx \l__spath_tmpc_tl
+ {
+ {\fp_to_dim:n
+ {
+ ( \tl_item:Nn \l__spath_tmpa_tl {5} )
+ -
+ ( \tl_item:Nn \l__spath_tmpa_tl {2} )
+ }
+ }
+ {\fp_to_dim:n
+ {
+ ( \tl_item:Nn \l__spath_tmpa_tl {6} )
+ -
+ ( \tl_item:Nn \l__spath_tmpa_tl {3} )
+ }
+ }
+ }
+ }
+
+ \c_spath_closepath_tl
+ {
+ \tl_set:Nx \l__spath_tmpc_tl
+ {
+ {\fp_to_dim:n
+ {
+ ( \tl_item:Nn \l__spath_tmpa_tl {5} )
+ -
+ ( \tl_item:Nn \l__spath_tmpa_tl {2} )
+ }
+ }
+ {\fp_to_dim:n
+ {
+ ( \tl_item:Nn \l__spath_tmpa_tl {6} )
+ -
+ ( \tl_item:Nn \l__spath_tmpa_tl {3} )
+ }
+ }
+ }
+ }
+
+ \c_spath_curvetoa_tl
+ {
+ \tl_set:Nx \l__spath_tmpc_tl
+ {
+ {\fp_to_dim:n
+ {
+ 3*(1 - \l__spath_tmpa_fp)^2 * (\tl_item:Nn \l__spath_tmpa_tl {5} - \tl_item:Nn \l__spath_tmpa_tl {2})
+ + 6 * (1 - \l__spath_tmpa_fp) * (\l__spath_tmpa_fp) * (\tl_item:Nn \l__spath_tmpa_tl {8} - \tl_item:Nn \l__spath_tmpa_tl {5})
+ + 3*(\l__spath_tmpa_fp)^2 * (\tl_item:Nn \l__spath_tmpa_tl {11} - \tl_item:Nn \l__spath_tmpa_tl {8})
+ }
+ }
+ {\fp_to_dim:n
+ {
+ 3*(1 - \l__spath_tmpa_fp)^2 * (\tl_item:Nn \l__spath_tmpa_tl {6} - \tl_item:Nn \l__spath_tmpa_tl {3})
+ + 6 * (1 - \l__spath_tmpa_fp) * (\l__spath_tmpa_fp) * (\tl_item:Nn \l__spath_tmpa_tl {9} - \tl_item:Nn \l__spath_tmpa_tl {6})
+ + 3*(\l__spath_tmpa_fp)^2 * (\tl_item:Nn \l__spath_tmpa_tl {12} - \tl_item:Nn \l__spath_tmpa_tl {9})
+ }}
+ }
+ }
+ }
}
- {
- \spath_remove:nn {#1} {max bb}
- }
- \bool_if:nTF
- {
- \spath_if_in_p:nn {#1} {reverse path}
- &&
- \spath_if_in_p:nn {#2} {reverse path}
- }
- {
- \__spath_get:nnN {#2} {reverse path} \l__spath_tmpa_tl
- \__spath_get:nnN {#1} {reverse path} \l__spath_tmpb_tl
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
- \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
- \spath_put:nnV {#1} {reverse path} \l__spath_tmpb_tl
- }
- {
- \spath_remove:nn {#1} {reverse path}
- }
}
+
+ \tl_gclear:N \g__spath_output_tl
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpc_tl
+ \group_end:
}
-\cs_new_nopar:Npn \spath_bake_round:n #1
+\cs_new_protected_nopar:Npn \spath_tangent_at:Nnn #1#2#3
{
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \pgf@@processround\l__spath_tmpa_tl\l__spath_tmpb_tl
- \spath_put:nnV {#1} {path} \l__spath_tmpb_tl
+ \__spath_tangent_at:nn {#2}{#3}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
}
-\cs_new_nopar:Npn \spath_close_path:n #1
+\cs_generate_variant:Nn \spath_tangent_at:Nnn {NVn, NVV, NnV}
+\cs_new_protected_nopar:Npn \spath_gtangent_at:Nnn #1#2#3
{
- \spath_get:nnN {#1} {initial point} \l__spath_tmpb_tl
- \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_closepath_tl
- \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
- \spath_put:nnV {#1} {path} \l__spath_tmpa_tl
- \spath_if_in:nnT {#1} {reverse path}
+ \__spath_tangent_at:nn {#2}{#3}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gtangent_at:Nnn {NVn, NVV, NnV}
+\cs_new_protected_nopar:Npn \__spath_transformation_at:nn #1#2
+{
+ \group_begin:
+ \tl_clear:N \l__spath_tmpa_tl
+ \__spath_tangent_at:nn {#1}{#2}
+ \tl_set_eq:NN \l__spath_tmpb_tl \g__spath_output_tl
+ \fp_set:Nn \l__spath_tmpa_fp { sqrt( (\tl_item:Nn \l__spath_tmpb_tl {1})^2 + (\tl_item:Nn \l__spath_tmpb_tl {2})^2 ) }
+ \fp_compare:nTF {\l__spath_tmpa_fp = 0}
{
- \spath_get:nnN {#1} {final point} \l__spath_tmpb_tl
- \__spath_get:nnN {#1} {reverse path} \l__spath_tmpa_tl
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_closepath_tl
- \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl
- \spath_put:nnV {#1} {reverse path} \l__spath_tmpa_tl
+ \fp_set:Nn \l__spath_tmpa_fp {1}
+ \fp_set:Nn \l__spath_tmpb_fp {0}
}
+ {
+ \fp_set:Nn \l__spath_tmpb_fp { (\tl_item:Nn \l__spath_tmpb_tl {2}) / \l__spath_tmpa_fp }
+ \fp_set:Nn \l__spath_tmpa_fp { (\tl_item:Nn \l__spath_tmpb_tl {1}) / \l__spath_tmpa_fp }
+ }
+ \tl_set:Nx \l__spath_tmpa_tl
+ {
+ { \fp_to_decimal:n { \l__spath_tmpa_fp } }
+ { \fp_to_decimal:n { \l__spath_tmpb_fp } }
+ { \fp_to_decimal:n {- \l__spath_tmpb_fp } }
+ { \fp_to_decimal:n { \l__spath_tmpa_fp } }
+ }
+ \__spath_point_at:nn {#1}{#2}
+ \tl_put_right:NV \l__spath_tmpa_tl \g__spath_output_tl
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
+ \group_end:
}
-\cs_new_nopar:Npn \spath_map_component:Nn #1#2
+\cs_new_protected_nopar:Npn \spath_transformation_at:Nnn #1#2#3
{
- \int_gincr:N \g__spath_map_int
- \cs_gset:cpn { __spath_map_ \int_use:N \g__spath_map_int :w } ##1 {#2}
- \tl_set:NV \l__spath_tmpa_tl #1
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_moveto_tl
- \tl_set_eq:NN \l__spath_tmpb_tl \g__spath_moveto_tl
- \bool_until_do:nn {
- \tl_if_empty_p:N \l__spath_tmpa_tl
+ \__spath_transformation_at:nn {#2}{#3}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_transformation_at:Nnn {NVn, NVV, NnV, NvV}
+\cs_new_protected_nopar:Npn \spath_gtransformation_at:Nnn #1#2#3
+{
+ \__spath_transformation_at:nn {#2}{#3}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_generate_variant:Nn \spath_gtransformation_at:Nnn {NVn, NVV, NnV}
+\tl_new:N \l__spath_split_path_a_tl
+\tl_new:N \l__spath_split_path_b_tl
+\tl_new:N \l__spath_split_path_a_start_tl
+\tl_new:N \l__spath_split_path_b_start_tl
+\tl_new:N \l__spath_split_path_a_end_tl
+\tl_new:N \l__spath_split_path_b_end_tl
+\tl_new:N \l__spath_split_path_a_final_tl
+\tl_new:N \l__spath_split_path_b_final_tl
+
+\tl_new:N \l__spath_split_prev_first_tl
+\tl_new:N \l__spath_split_prev_second_tl
+
+\seq_new:N \l__spath_split_first_seq
+\seq_new:N \l__spath_split_second_seq
+
+\int_new:N \l__spath_split_segment_int
+\cs_new_protected_nopar:Npn \spath_intersect:NN #1#2
+{
+ \pgfintersectionofpaths%
+ {%
+ \pgfsetpath #1
+ }{%
+ \pgfsetpath #2
}
+}
+\tl_new:N \l__spath_intersecta_tl
+\tl_new:N \l__spath_intersectb_tl
+\cs_new_protected_nopar:Npn \spath_intersect:nn #1#2
+{
+ \tl_set:Nn \l__spath_intersecta_tl {#1}
+ \tl_set:Nn \l__spath_intersectb_tl {#2}
+ \spath_intersect:NN \l__spath_intersecta_tl \l__spath_intersectb_tl
+}
+\cs_new_protected_nopar:Npn \__spath_split_at_intersections:nn #1#2
+{
+ \group_begin:
+
+ % Clear some token lists and sequences
+ \tl_clear:N \l__spath_split_path_a_final_tl
+ \tl_clear:N \l__spath_split_path_b_final_tl
+ \seq_clear:N \l__spath_split_first_seq
+ \seq_clear:N \l__spath_split_second_seq
+
+ \pgfintersectionsortbyfirstpath
+ % Find the intersections of these segments
+ \tl_set:Nn \l__spath_split_path_a_tl {#1}
+ \tl_set:Nn \l__spath_split_path_b_tl {#2}
+ % Remove empty components
+
+ \spath_intersect:NN \l__spath_split_path_a_tl \l__spath_split_path_b_tl
+
+ % If we get intersections
+ \int_compare:nT {\pgfintersectionsolutions > 0}
{
- \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_if_eq:NNT \l__spath_tmpc_tl \g__spath_moveto_tl
+ % Find the times of the intersections on each path
+ \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions}
{
- \exp_args:NnV \use:c { __spath_map_ \int_use:N \g__spath_map_int :w } \l__spath_tmpb_tl
-\tl_clear:N \l__spath_tmpb_tl
+ \pgfintersectiongetsolutiontimes{##1}{\l__spath_split_first_tl}{\l__spath_split_second_tl}
+ \seq_put_left:NV \l__spath_split_first_seq \l__spath_split_first_tl
}
- \tl_if_single:NTF \l__spath_tmpc_tl
+ }
+
+ \spath_intersect:NN \l__spath_split_path_b_tl \l__spath_split_path_a_tl
+
+ % If we get intersections
+ \int_compare:nT {\pgfintersectionsolutions > 0}
+ {
+ % Find the times of the intersections on each path
+ \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions}
{
- \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpc_tl
+ \pgfintersectiongetsolutiontimes{##1}{\l__spath_split_first_tl}{\l__spath_split_second_tl}
+ \seq_put_left:NV \l__spath_split_second_seq \l__spath_split_first_tl
}
+ }
+
+ \tl_set:Nn \l__spath_split_prev_first_tl {-1}
+
+ \seq_map_inline:Nn \l__spath_split_first_seq
+ {
+ \tl_set:Nn \l__spath_split_first_tl {##1}
+
+ \tl_set_eq:NN \l__spath_tmpa_tl \l__spath_split_first_tl
+ \int_compare:nT
{
- \tl_put_right:Nx \l__spath_tmpb_tl {{\l__spath_tmpc_tl}}
+ \fp_to_int:n {floor( \l__spath_split_first_tl) }
+ =
+ \fp_to_int:n {floor( \l__spath_split_prev_first_tl) }
}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ {
+ \tl_set:Nx \l__spath_split_first_tl
+ {
+ \fp_eval:n {
+ floor( \l__spath_split_first_tl )
+ +
+ ( \l__spath_split_first_tl - floor( \l__spath_split_first_tl) )
+ /
+ ( \l__spath_split_prev_first_tl - floor( \l__spath_split_prev_first_tl) )
+ }
+ }
+ }
+ \tl_set_eq:NN \l__spath_split_prev_first_tl \l__spath_tmpa_tl
+
+ \spath_split_at:NNVV \l__spath_split_path_a_start_tl \l__spath_split_path_a_end_tl \l__spath_split_path_a_tl \l__spath_split_first_tl
+
+ \tl_put_left:NV \l__spath_split_path_a_final_tl \l__spath_split_path_a_end_tl
+ \tl_set_eq:NN \l__spath_split_path_a_tl \l__spath_split_path_a_start_tl
+
}
+
+ \tl_set:Nn \l__spath_split_prev_second_tl {-1}
+
+ \seq_map_inline:Nn \l__spath_split_second_seq
+ {
+ \tl_set:Nn \l__spath_split_second_tl {##1}
+
+ \tl_set_eq:NN \l__spath_tmpa_tl \l__spath_split_second_tl
+ \int_compare:nT
+ {
+ \fp_to_int:n {floor( \l__spath_split_second_tl) }
+ =
+ \fp_to_int:n {floor( \l__spath_split_prev_second_tl) }
+ }
+ {
+ \tl_set:Nx \l__spath_split_second_tl
+ {
+ \fp_eval:n {
+ floor( \l__spath_split_second_tl )
+ +
+ ( \l__spath_split_second_tl - floor( \l__spath_split_second_tl) )
+ /
+ ( \l__spath_split_prev_second_tl - floor( \l__spath_split_prev_second_tl) )
+ }
+ }
+ }
+ \tl_set_eq:NN \l__spath_split_prev_second_tl \l__spath_tmpa_tl
+
+ \spath_split_at:NNVV \l__spath_split_path_b_start_tl \l__spath_split_path_b_end_tl \l__spath_split_path_b_tl\l__spath_split_second_tl
+
+ \tl_put_left:NV \l__spath_split_path_b_final_tl \l__spath_split_path_b_end_tl
+ \tl_set_eq:NN \l__spath_split_path_b_tl \l__spath_split_path_b_start_tl
+
+ }
+
+ \tl_put_left:NV \l__spath_split_path_a_final_tl \l__spath_split_path_a_tl
+ \tl_put_left:NV \l__spath_split_path_b_final_tl \l__spath_split_path_b_tl
+
+ \tl_if_empty:NT \l__spath_split_path_a_final_tl
+ {
+ \tl_set_eq:NN \l__spath_split_path_a_final_tl \l__spath_split_path_a_tl
+ }
+ \tl_if_empty:NT \l__spath_split_path_b_final_tl
+ {
+ \tl_set_eq:NN \l__spath_split_path_b_final_tl \l__spath_split_path_b_tl
+ }
+
+ \spath_remove_empty_components:N \l__spath_split_path_a_final_tl
+ \spath_remove_empty_components:N \l__spath_split_path_b_final_tl
+
+ \tl_gclear:N \g__spath_output_tl
+ \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_split_path_a_final_tl
+ \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_split_path_b_final_tl
+ \group_end:
}
-\cs_new_nopar:Npn \spath_map_segment_inline:Nn #1#2
+\cs_new_protected_nopar:Npn \spath_split_at_intersections:NNnn #1#2#3#4
{
- \int_gincr:N \g__spath_map_int
- \cs_gset:cpn { __spath_map_ \int_use:N \g__spath_map_int :w } ##1 ##2 {#2}
- \spath_map_segment_function:Nc #1 { __spath_map_ \int_use:N \g__spath_map_int :w }
+ \__spath_split_at_intersections:nn {#3}{#4}
+ \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
+ \tl_set:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
+ \tl_gclear:N \g__spath_output_tl
}
-\cs_new_nopar:Npn \spath_map_segment_inline:nn #1#2
+\cs_generate_variant:Nn \spath_split_at_intersections:NNnn {NNVV, ccVV, ccvv}
+\cs_new_protected_nopar:Npn \spath_split_at_intersections:NN #1#2
{
- \int_gincr:N \g__spath_map_int
- \cs_gset:cpn { __spath_map_ \int_use:N \g__spath_map_int :w } ##1 ##2 {#2}
- \spath_get:nnN {#1} {path} \l__spath_tmpd_tl
- \spath_map_segment_function:Nc \l__spath_tmpd_tl { __spath_map_ \int_use:N \g__spath_map_int :w }
+ \spath_split_at_intersections:NNVV #1#2#1#2
}
-\cs_new_nopar:Npn \spath_map_segment_function:nN #1#2
+\cs_generate_variant:Nn \spath_split_at_intersections:NN {cc}
+\cs_new_protected_nopar:Npn \spath_gsplit_at_intersections:NNnn #1#2#3#4
{
- \spath_get:nnN {#1} {path} \l__spath_tmpd_tl
- \spath_map_segment_function:NN \l__spath_tmpd_tl #2
+ \__spath_split_at_intersections:nn {#3}{#4}
+ \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}}
+ \tl_gset:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}}
+ \tl_gclear:N \g__spath_output_tl
}
-\cs_new_nopar:Npn \spath_map_segment_function:NN #1#2
+\cs_generate_variant:Nn \spath_gsplit_at_intersections:NNnn {NNVV, ccVV, ccvv}
+\cs_new_protected_nopar:Npn \spath_gsplit_at_intersections:NN #1#2
{
- \tl_set_eq:NN \l__spath_tmpa_tl #1
- \tl_clear:N \l__spath_tmpb_tl
- \dim_zero:N \l__spath_tmpa_dim
- \dim_zero:N \l__spath_tmpb_dim
+ \spath_gsplit_at_intersections:NNVV #1#2#1#2
+}
+\cs_generate_variant:Nn \spath_gsplit_at_intersections:NN {cc}
+\cs_new_protected_nopar:Npn \__spath_split_at_self_intersections:n #1
+{
+ \group_begin:
- \bool_until_do:nn {
- \tl_if_empty_p:N \l__spath_tmpa_tl
+ % Copy the path
+ \tl_set:Nn \l__spath_split_path_b_tl {#1}
+
+ % Open the path
+ \spath_open:N \l__spath_split_path_b_tl
+ % Remove empty components
+ \spath_remove_empty_components:N \l__spath_split_path_b_tl
+ % Make a copy for later
+ \tl_set_eq:NN \l__spath_split_path_b_final_tl \l__spath_split_path_b_tl
+
+ % Clear some token lists and sequences
+ \tl_clear:N \l__spath_split_path_a_tl
+ \seq_clear:N \l__spath_split_first_seq
+ \int_zero:N \l__spath_split_segment_int
+
+ \pgfintersectionsortbyfirstpath
+
+ \bool_do_until:nn
+ {
+ \int_compare_p:n
+ {
+ \tl_count:N \l__spath_split_path_b_tl < 4
+ }
}
{
- \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_case:NnF \l__spath_tmpc_tl
+ \tl_clear:N \l__spath_split_path_a_tl
+ \tl_put_right:Nx \l__spath_split_path_a_tl
{
- \g__spath_lineto_tl
- {
- \tl_set_eq:NN \l__spath_tmpb_tl \g__spath_moveto_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- \tl_put_right:NV \l__spath_tmpb_tl \g__spath_lineto_tl
+ \tl_item:Nn \l__spath_split_path_b_tl {1}
+ {\tl_item:Nn \l__spath_split_path_b_tl {2}}
+ {\tl_item:Nn \l__spath_split_path_b_tl {3}}
+ }
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_tmpa_tl { \tl_item:Nn \l__spath_split_path_b_tl {4} }
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ \tl_set:Nx \l__spath_split_path_b_tl {\tl_tail:N \l__spath_split_path_b_tl}
+ \int_zero:N \l__spath_tmpa_int
+
+ \tl_case:Nn \l__spath_tmpa_tl
+ {
+ \c_spath_moveto_tl
+ {
+ \tl_clear:N \l__spath_split_path_a_tl
+ \tl_set:Nx \l__spath_split_path_b_tl {\tl_tail:N \l__spath_split_path_b_tl}
+ \tl_set:Nx \l__spath_split_path_b_tl {\tl_tail:N \l__spath_split_path_b_tl}
+ \tl_set:Nx \l__spath_split_path_b_tl {\tl_tail:N \l__spath_split_path_b_tl}
}
+ \c_spath_lineto_tl
+ {
+ \int_set:Nn \l__spath_tmpa_int {1}
+ }
+ \c_spath_curvetoa_tl
+ {
+ \int_set:Nn \l__spath_tmpa_int {3}
+ }
+ }
- \g__spath_curvetoa_tl
+ \prg_replicate:nn { \l__spath_tmpa_int }
+ {
+ \tl_set:Nx \l__spath_split_path_b_tl {\tl_tail:N \l__spath_split_path_b_tl}
+ \tl_set:Nx \l__spath_split_path_b_tl {\tl_tail:N \l__spath_split_path_b_tl}
+
+ \tl_put_right:Nx \l__spath_split_path_a_tl
{
- \tl_set_eq:NN \l__spath_tmpb_tl \g__spath_moveto_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
- {
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
- }
- \tl_put_right:NV \l__spath_tmpb_tl \g__spath_curvetoa_tl
+ \tl_item:Nn \l__spath_split_path_b_tl {1}
+ {\tl_item:Nn \l__spath_split_path_b_tl {2}}
+ {\tl_item:Nn \l__spath_split_path_b_tl {3}}
+ }
- \prg_replicate:nn {2} {
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
- }
+ \tl_set:Nx \l__spath_split_path_b_tl {\tl_tail:N \l__spath_split_path_b_tl}
+ }
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ \tl_put_left:NV \l__spath_split_path_b_tl \c_spath_moveto_tl
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ \tl_if_empty:NF \l__spath_split_path_a_tl
+ {
+ % Intersect the current segment with the rest of the path
+ \spath_intersect:NN \l__spath_split_path_a_tl \l__spath_split_path_b_tl
+ % If we get intersections
+ \int_compare:nT {\pgfintersectionsolutions > 0}
+ {
+ % Find the times of the intersections on each path
+ \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions}
+ {
+ \pgfintersectiongetsolutiontimes{##1}{\l__spath_split_first_tl}{\l__spath_split_second_tl}
+ \fp_compare:nT
+ {
+ \l__spath_split_first_tl < .99
+ }
+ {
+ \tl_set:Nx \l__spath_tmpa_tl {\fp_to_decimal:n {\l__spath_split_first_tl + \l__spath_split_segment_int}}
+ \seq_put_right:NV \l__spath_split_first_seq \l__spath_tmpa_tl
+ }
+ }
}
- \g__spath_closepath_tl
+ \spath_intersect:NN \l__spath_split_path_b_tl \l__spath_split_path_a_tl
+
+ % If we get intersections
+ \int_compare:nT {\pgfintersectionsolutions > 0}
{
- \tl_set_eq:NN \l__spath_tmpb_tl \g__spath_moveto_tl
- \tl_put_right:Nx \l__spath_tmpb_tl
+ % Find the times of the intersections on each path
+ \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions}
{
- {\dim_use:N \l__spath_tmpa_dim}
- {\dim_use:N \l__spath_tmpb_dim}
+ \pgfintersectiongetsolutiontimes{##1}{\l__spath_split_first_tl}{\l__spath_split_second_tl}
+ \fp_compare:nT
+ {
+ \l__spath_split_first_tl > .01
+ }
+ {
+ \tl_set:Nx \l__spath_tmpa_tl {\fp_to_decimal:n {\l__spath_split_first_tl + \l__spath_split_segment_int + 1}}
+ \seq_put_right:NV \l__spath_split_first_seq \l__spath_tmpa_tl
+ }
}
- \tl_put_right:NV \l__spath_tmpb_tl \g__spath_lineto_tl
+ }
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ }
+ % Increment the segment counter
+ \int_incr:N \l__spath_split_segment_int
+ }
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ % Sort the sequence by reverse order along the path
+ \seq_sort:Nn \l__spath_split_first_seq
+ {
+ \fp_compare:nNnTF { ##1 } < { ##2 }
+ { \sort_return_swapped: }
+ { \sort_return_same: }
+ }
- }
+ % Restore the original copy of the path
+ \tl_set_eq:NN \l__spath_split_path_b_tl \l__spath_split_path_b_final_tl
+ % Clear the token lists
+ \tl_clear:N \l__spath_split_path_b_start_tl
+ \tl_clear:N \l__spath_split_path_b_end_tl
+ \tl_clear:N \l__spath_split_path_b_final_tl
+
+ \tl_set:Nn \l__spath_split_prev_first_tl {-1}
+
+ \seq_map_inline:Nn \l__spath_split_first_seq
+ {
+ \tl_set:Nn \l__spath_split_first_tl {##1}
+ \tl_set_eq:NN \l__spath_tmpa_tl \l__spath_split_first_tl
+ \int_compare:nT
+ {
+ \fp_to_int:n {floor( \l__spath_split_first_tl ) }
+ =
+ \fp_to_int:n {floor( \l__spath_split_prev_first_tl) }
}
{
+ \tl_set:Nx \l__spath_split_first_tl
+ {
+ \fp_eval:n {
+ floor( \l__spath_split_first_tl )
+ +
+ ( \l__spath_split_first_tl - floor( \l__spath_split_first_tl) )
+ /
+ ( \l__spath_split_prev_first_tl - floor( \l__spath_split_prev_first_tl) )
+ }
+ }
+ }
+ \tl_set_eq:NN \l__spath_split_prev_first_tl \l__spath_tmpa_tl
- \tl_set_eq:NN \l__spath_tmpb_tl \l__spath_tmpc_tl
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ \spath_split_at:NNVV \l__spath_split_path_b_start_tl \l__spath_split_path_b_end_tl \l__spath_split_path_b_tl \l__spath_split_first_tl
- \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}}
- \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl}
- \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ \tl_put_left:NV \l__spath_split_path_b_final_tl \l__spath_split_path_b_end_tl
+ \tl_set_eq:NN \l__spath_split_path_b_tl \l__spath_split_path_b_start_tl
- }
+ }
- #2 \l__spath_tmpc_tl \l__spath_tmpb_tl
- \tl_clear:N \l__spath_tmpb_tl
+ \tl_put_left:NV \l__spath_split_path_b_final_tl \l__spath_split_path_b_tl
+ \tl_if_empty:NT \l__spath_split_path_b_final_tl
+ {
+ \tl_set_eq:NN \l__spath_split_path_b_final_tl \l__spath_split_path_b_tl
}
+
+ \spath_remove_empty_components:N \l__spath_split_path_b_final_tl
+
+ \tl_gclear:N \g__spath_output_tl
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_split_path_b_final_tl
+ \group_end:
}
-\cs_generate_variant:Nn \spath_map_segment_function:NN {Nc}
-\NewDocumentCommand \MakeSPath { m m }
+\cs_new_protected_nopar:Npn \spath_split_at_self_intersections:Nn #1#2
{
- \spath_clear_new:n {#1}
- \spath_put:nno {#1} {path} {#2}
+ \__spath_split_at_self_intersections:n {#2}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
}
-\NewDocumentCommand \MakeSPathList { m m }
+\cs_generate_variant:Nn \spath_split_at_self_intersections:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_split_at_self_intersections:N #1
{
- \tl_gclear_new:c {l__spath_list_#1}
- \int_zero:N \l__spath_tmpa_int
- \spath_map_component:Nn #2 {
- \spath_clear_new:n {#1 _ \int_use:N \l__spath_tmpa_int}
- \spath_put:nnn {#1 _ \int_use:N \l__spath_tmpa_int} {path} {##1}
- \tl_gput_right:cx {l__spath_list_#1} {{#1 _ \int_use:N \l__spath_tmpa_int}}
- \int_incr:N \l__spath_tmpa_int
- }
+ \spath_split_at_self_intersections:NV #1#1
}
-\NewDocumentCommand \CloneSPath { m m }
+\cs_generate_variant:Nn \spath_split_at_self_intersections:N {c}
+\cs_new_protected_nopar:Npn \spath_gsplit_at_self_intersections:Nn #1#2
{
- \spath_clone:nn {#1} {#2}
+ \__spath_split_at_self_intersections:n {#2}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
}
-\NewDocumentCommand \SPathInfo { m m }
+\cs_generate_variant:Nn \spath_gsplit_at_self_intersections:Nn {NV}
+\cs_new_protected_nopar:Npn \spath_gsplit_at_self_intersections:N #1
{
- \spath_get:nn {#1} {#2}
+ \spath_gsplit_at_self_intersections:NV #1#1
}
-\NewDocumentCommand \SPathPrepare { m }
+\cs_generate_variant:Nn \spath_gsplit_at_self_intersections:N {c}
+\tl_new:N \l__spath_tmpj_tl
+\cs_new_protected_nopar:Npn \__spath_join_component:nn #1#2
{
- \spath_generate_all:n {#1}
-}
-\NewDocumentCommand \SPathListPrepare { m }
-{
- \tl_map_inline:cn {l__spath_list_#1}
+ \group_begin:
+ \spath_components_to_seq:Nn \l__spath_tmpa_seq {#1}
+ \int_compare:nT
{
- \spath_generate_all:n {##1}
+ #2 == 1
}
+ {
+ \tl_clear:N \l__spath_tmpj_tl
+ \seq_pop_left:NN \l__spath_tmpa_seq \l__spath_tmpj_tl
+
+ \prg_replicate:nn {3}
+ {
+ \tl_set:Nx \l__spath_tmpj_tl {\tl_tail:N \l__spath_tmpj_tl}
+ }
+
+ \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpj_tl
+ }
+ \bool_if:nT
+ {
+ \int_compare_p:n
+ {
+ #2 > 1
+ }
+ &&
+ \int_compare_p:n
+ {
+ #2 <= \seq_count:N \l__spath_tmpa_seq
+ }
+ }
+ {
+
+ \seq_clear:N \l__spath_tmpb_seq
+ \seq_map_indexed_inline:Nn \l__spath_tmpa_seq
+ {
+ \tl_set:Nn \l__spath_tmpj_tl {##2}
+ \int_compare:nT {##1 = #2}
+ {
+ \prg_replicate:nn {3}
+ {
+ \tl_set:Nx \l__spath_tmpj_tl {\tl_tail:N \l__spath_tmpj_tl}
+ }
+ }
+ \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpj_tl
+ }
+
+ \seq_set_eq:NN \l__spath_tmpa_seq \l__spath_tmpb_seq
+ }
+
+ \tl_gset:Nx \g__spath_output_tl {\seq_use:Nn \l__spath_tmpa_seq {} }
+ \group_end:
}
-\NewDocumentCommand \SPathInfoInto { m m m }
+\cs_new_protected_nopar:Npn \spath_join_component:Nnn #1#2#3
{
- \tl_clear_new:N #3
- \spath_get:nnN {#1} {#2} #3
+ \__spath_join_component:nn {#2}{#3}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
}
-\NewDocumentCommand \SPathShow { m }
+\cs_generate_variant:Nn \spath_join_component:Nnn {NVn, NVV}
+\cs_new_protected_nopar:Npn \spath_join_component:Nn #1#2
{
- \spath_show:n {#1}
+ \spath_join_component:NVn #1#1{#2}
}
-\NewDocumentCommand \SPathTranslate { m m m }
+\cs_generate_variant:Nn \spath_join_component:Nn {cn, NV, cV}
+\cs_new_protected_nopar:Npn \spath_gjoin_component:Nnn #1#2#3
{
- \spath_translate:nnn {#1} {#2} {#3}
+ \__spath_join_component:nn {#2}{#3}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
}
-\NewDocumentCommand \SPathTranslateInto { m m m m }
+\cs_generate_variant:Nn \spath_gjoin_component:Nnn {NVn, NVV}
+\cs_new_protected_nopar:Npn \spath_gjoin_component:Nn #1#2
{
- \spath_clone:nn {#1} {#2}
- \spath_translate:nnn {#2} {#3} {#4}
+ \spath_gjoin_component:NVn #1#1{#2}
}
-\NewDocumentCommand \SPathScale { m m m }
+\cs_generate_variant:Nn \spath_gjoin_component:Nn {cn, NV, cV}
+\cs_new_protected_nopar:Npn \__spath_spot_weld_components:n #1
{
- \spath_scale:nnn {#1} {#2} {#3}
+ \group_begin:
+ \dim_zero:N \l__spath_move_x_dim
+ \dim_zero:N \l__spath_move_y_dim
+
+ \spath_components_to_seq:Nn \l__spath_tmpa_seq {#1}
+ \seq_clear:N \l__spath_tmpb_seq
+ \dim_set:Nn \l__spath_move_x_dim {\tl_item:nn {#1} {2} + 10 pt}
+ \dim_set:Nn \l__spath_move_y_dim {\tl_item:nn {#1} {3} + 10 pt}
+
+ \int_set:Nn \l__spath_tmpa_int {\seq_count:N \l__spath_tmpa_seq}
+
+ \seq_map_inline:Nn \l__spath_tmpa_seq
+ {
+ \tl_set:Nn \l__spath_tmpa_tl {##1}
+ \bool_if:nT
+ {
+ \dim_compare_p:n
+ {
+ \dim_abs:n {\l__spath_move_x_dim - \tl_item:Nn \l__spath_tmpa_tl {2} } < 0.01pt
+ }
+ &&
+ \dim_compare_p:n
+ {
+ \dim_abs:n {\l__spath_move_y_dim - \tl_item:Nn \l__spath_tmpa_tl {3} } < 0.01pt
+ }
+ }
+ {
+ \prg_replicate:nn {3}
+ {
+ \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl}
+ }
+ \int_decr:N \l__spath_tmpa_int
+ }
+ \tl_reverse:N \l__spath_tmpa_tl
+ \dim_set:Nn \l__spath_move_x_dim {\tl_item:Nn \l__spath_tmpa_tl {2}}
+ \dim_set:Nn \l__spath_move_y_dim {\tl_item:Nn \l__spath_tmpa_tl {1}}
+ \tl_reverse:N \l__spath_tmpa_tl
+ \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpa_tl
+ }
+
+ \tl_set:Nx \l__spath_tmpa_tl {\seq_use:Nn \l__spath_tmpb_seq {} }
+ \spath_components_to_seq:NV \l__spath_tmpb_seq \l__spath_tmpa_tl
+
+ \spath_initialpoint:Nn \l__spath_tmpa_tl {#1}
+ \spath_finalpoint:Nn \l__spath_tmpb_tl {#1}
+
+ \bool_if:nT
+ {
+ \dim_compare_p:n
+ {
+ \dim_abs:n {\tl_item:Nn \l__spath_tmpa_tl {1} - \tl_item:Nn \l__spath_tmpb_tl {1} } < 0.01pt
+ }
+ &&
+ \dim_compare_p:n
+ {
+ \dim_abs:n {\tl_item:Nn \l__spath_tmpa_tl {2} - \tl_item:Nn \l__spath_tmpb_tl {2} } < 0.01pt
+ }
+ }
+ {
+ \int_compare:nTF
+ {
+ \seq_count:N \l__spath_tmpb_seq > 1
+ }
+ {
+ \seq_pop_left:NN \l__spath_tmpb_seq \l__spath_tmpb_tl
+
+ \prg_replicate:nn {3}
+ {
+ \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl}
+ }
+ \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpb_tl
+ }
+ {
+ \tl_set:NV \l__spath_tmpb_tl \c_spath_closepath_tl
+ \tl_put_right:Nx \l__spath_tmpb_tl
+ {
+ { \tl_item:Nn \l__spath_tmpa_tl {1} }
+ { \tl_item:Nn \l__spath_tmpa_tl {2} }
+ }
+ \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpb_tl
+ }
+ }
+
+ \tl_gset:Nx \g__spath_output_tl {\seq_use:Nn \l__spath_tmpb_seq {}}
+ \group_end:
}
-\NewDocumentCommand \SPathScaleInto { m m m m }
+\cs_new_protected_nopar:Npn \spath_spot_weld_components:Nn #1#2
{
- \spath_clone:nn {#1} {#2}
- \spath_scale:nnn {#2} {#3} {#4}
+ \__spath_spot_weld_components:n {#2}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
}
-\NewDocumentCommand \SPathWeld { m m }
+\cs_generate_variant:Nn \spath_spot_weld_components:Nn {NV, cV, cn}
+\cs_new_protected_nopar:Npn \spath_spot_weld_components:N #1
{
- \spath_weld:nn {#1} {#2}
+ \spath_spot_weld_components:NV #1#1
}
-\NewDocumentCommand \SPathWeldInto { m m m }
+\cs_generate_variant:Nn \spath_spot_weld_components:N {c}
+\cs_new_protected_nopar:Npn \spath_spot_gweld_components:Nn #1#2
{
- \spath_clone:nn {#1} {#2}
- \spath_weld:nn {#2} {#3}
+ \__spath_spot_weld_components:n {#2}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
}
-\tikzset{
- save~spath/.code={
- \tikz at addmode{
- \spath_get_current_path:n {#1}
- }
- },
- restore~spath/.code={
- \spath_set_current_path:n {#1}
- }
+\cs_generate_variant:Nn \spath_spot_gweld_components:Nn {NV, cV, cn}
+\cs_new_protected_nopar:Npn \spath_spot_gweld_components:N #1
+{
+ \spath_spot_gweld_components:NV #1#1
}
-\cs_new_nopar:Npn \spath_split_curve:nnNN #1#2#3#4
+\cs_generate_variant:Nn \spath_spot_gweld_components:N {c}
+\cs_new_protected_nopar:Npn \__spath_convert_to_svg:n #1
{
\group_begin:
- \tl_gclear:N \l__spath_smuggle_tl
- \tl_set_eq:NN \l__spath_tmpa_tl \g__spath_moveto_tl
- \tl_put_right:Nx \l__spath_tmpa_tl {
- {\tl_item:nn {#2} {2}}
- {\tl_item:nn {#2} {3}}
+ \tl_clear:N \l__spath_tmpa_tl
+ \tl_put_right:Nn \l__spath_tmpa_tl
+ {
+ <?xml~ version="1.0"~ standalone="no"?>
+ \iow_newline:
+ <!DOCTYPE~ svg~ PUBLIC~ "-//W3C//DTD SVG 1.1//EN"~
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+ \iow_newline:
+ <svg~ xmlns="http://www.w3.org/2000/svg"~ version="1.1"~viewBox="
}
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_curvetoa_tl
+
+ \spath_minbb:Nn \l__spath_tmpb_tl {#1}
+ \spath_maxbb:Nn \l__spath_tmpc_tl {#1}
\tl_put_right:Nx \l__spath_tmpa_tl
{
- {\fp_to_dim:n
+ \dim_to_decimal:n
{
- (1 - #1) * \tl_item:nn {#2} {2} + (#1) * \tl_item:nn {#2} {5}
- }}
- {\fp_to_dim:n
+ \tl_item:Nn \l__spath_tmpb_tl {1} - 10pt
+ }
+ \exp_not:n {~}
+ \dim_to_decimal:n
{
- (1 - #1) * \tl_item:nn {#2} {3} + (#1) * \tl_item:nn {#2} {6}
- }}
- }
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_curvetob_tl
- \tl_put_right:Nx \l__spath_tmpa_tl
- {
- {\fp_to_dim:n
+ \tl_item:Nn \l__spath_tmpb_tl {2} - 10pt
+ }
+ \exp_not:n {~}
+ \dim_to_decimal:n
{
- (1 - #1)^2 * \tl_item:nn {#2} {2} + 2 * (1 - #1) * (#1) * \tl_item:nn {#2} {5} + (#1)^2 * \tl_item:nn {#2} {8}
- }}
- {\fp_to_dim:n
+ \tl_item:Nn \l__spath_tmpc_tl {1}
+ -
+ \tl_item:Nn \l__spath_tmpb_tl {1}
+ + 20pt
+ }
+ \exp_not:n {~}
+ \dim_to_decimal:n
{
- (1 - #1)^2 * \tl_item:nn {#2} {3} + 2 * (1 - #1) * (#1) * \tl_item:nn {#2} {6} + (#1)^2 * \tl_item:nn {#2} {9}
- }}
+ \tl_item:Nn \l__spath_tmpc_tl {2}
+ -
+ \tl_item:Nn \l__spath_tmpb_tl {2}
+ + 20pt
+ }
}
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_curveto_tl
- \tl_put_right:Nx \l__spath_tmpa_tl
+
+ \tl_put_right:Nn \l__spath_tmpa_tl
{
- {\fp_to_dim:n
- {
- (1 - #1)^3 * \tl_item:nn {#2} {2} + 3 * (1 - #1)^2 * (#1) * \tl_item:nn {#2} {5} + 3 * (1 - #1) * (#1)^2 * \tl_item:nn {#2} {8} + (#1)^3 * \tl_item:nn {#2} {11}
- }}
- {\fp_to_dim:n
- {
- (1 - #1)^3 * \tl_item:nn {#2} {3} + 3 * (1 - #1)^2 * (#1) * \tl_item:nn {#2} {6} + 3 * (1 - #1) * (#1)^2 * \tl_item:nn {#2} {9} + (#1)^3 * \tl_item:nn {#2} {12}
- }}
+ ">
+ \iow_newline:
+ <path~ d="
}
- \tl_gset_eq:NN \l__spath_smuggle_tl \l__spath_tmpa_tl
- \group_end:
- \tl_set_eq:NN #3 \l__spath_smuggle_tl
- \group_begin:
- \tl_set_eq:NN \l__spath_tmpa_tl \g__spath_moveto_tl
- \tl_put_right:Nx \l__spath_tmpa_tl
+ \tl_set:Nn \l__spath_tmpc_tl {use:n}
+ \tl_map_inline:Nn #1
{
- {\fp_to_dim:n
+ \tl_set:Nn \l__spath_tmpb_tl {##1}
+ \tl_case:NnF \l__spath_tmpb_tl
+ {
+ \c_spath_moveto_tl
{
- (1 - #1)^3 * \tl_item:nn {#2} {2} + 3 * (1 - #1)^2 * (#1) * \tl_item:nn {#2} {5} + 3 * (1 - #1) * (#1)^2 * \tl_item:nn {#2} {8} + (#1)^3 * \tl_item:nn {#2} {11}
- }}
- {\fp_to_dim:n
+ \tl_put_right:Nn \l__spath_tmpa_tl {M~}
+ \tl_set:Nn \l__spath_tmpc_tl {use:n}
+ }
+ \c_spath_lineto_tl
+ {
+ \tl_put_right:Nn \l__spath_tmpa_tl {L~}
+ \tl_set:Nn \l__spath_tmpc_tl {use:n}
+ }
+ \c_spath_closepath_tl
+ {
+ \tl_put_right:Nn \l__spath_tmpa_tl {Z~}
+ \tl_set:Nn \l__spath_tmpc_tl {use_none:n}
+ }
+ \c_spath_curvetoa_tl
+ {
+ \tl_put_right:Nn \l__spath_tmpa_tl {C~}
+ \tl_set:Nn \l__spath_tmpc_tl {use:n}
+ }
+ \c_spath_curvetob_tl {
+ \tl_set:Nn \l__spath_tmpc_tl {use:n}
+ }
+ \c_spath_curveto_tl {
+ \tl_set:Nn \l__spath_tmpc_tl {use:n}
+ }
+ }
{
- (1 - #1)^3 * \tl_item:nn {#2} {3} + 3 * (1 - #1)^2 * (#1) * \tl_item:nn {#2} {6} + 3 * (1 - #1) * (#1)^2 * \tl_item:nn {#2} {9} + (#1)^3 * \tl_item:nn {#2} {12}
- }}
+ \tl_put_right:Nx \l__spath_tmpa_tl {\use:c { \l__spath_tmpc_tl } {\dim_to_decimal:n {##1}} ~}
+ }
}
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_curvetoa_tl
- \tl_put_right:Nx \l__spath_tmpa_tl
+ \tl_put_right:Nn \l__spath_tmpa_tl
{
- {\fp_to_dim:n
- {
- (1 - #1)^2 * \tl_item:nn {#2} {5} + 2 * (1 - #1) * (#1) * \tl_item:nn {#2} {8} + (#1)^2 * \tl_item:nn {#2} {11}
- }}
- {\fp_to_dim:n
- {
- (1 - #1)^2 * \tl_item:nn {#2} {6} + 2 * (1 - #1) * (#1) * \tl_item:nn {#2} {9} + (#1)^2 * \tl_item:nn {#2} {12}
- }}
+ "~ fill="none"~ stroke="black"~ />
+ \iow_newline:
+ </svg>
+ \iow_newline:
}
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_curvetob_tl
- \tl_put_right:Nx \l__spath_tmpa_tl
+ \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl
+ \group_end:
+}
+\cs_new_protected_nopar:Npn \spath_convert_to_svg:Nn #1#2
+{
+ \__spath_convert_to_svg:n {#2}
+ \tl_set_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\cs_new_protected_nopar:Npn \spath_gconvert_to_svg:Nn #1#2
+{
+ \__spath_convert_to_svg:n {#2}
+ \tl_gset_eq:NN #1 \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+}
+\iow_new:N \g__spath_stream
+\cs_new_protected_nopar:Npn \spath_export_to_svg:nn #1#2
+{
+ \spath_convert_path_to_svg:Nn \l__spath_iterp_tl {#2}
+ \iow_open:Nn \g__spath_stream {#1 .svg}
+ \iow_now:Nx \g__spath_stream
{
- {\fp_to_dim:n
- {
- (1 - #1) * \tl_item:nn {#2} {8} + (#1) * \tl_item:nn {#2} {11}
- }}
- {\fp_to_dim:n
- {
- (1 - #1) * \tl_item:nn {#2} {9} + (#1) * \tl_item:nn {#2} {12}
- }}
+ \tl_use:N \l__spath_iterp_tl
}
- \tl_put_right:NV \l__spath_tmpa_tl \g__spath_curveto_tl
- \tl_put_right:Nx \l__spath_tmpa_tl {
- {\tl_item:nn {#2} {11}}
- {\tl_item:nn {#2} {12}}
+ \iow_close:N \g__spath_stream
+}
+\cs_new_protected_nopar:Npn \spath_show:n #1
+{
+ \int_step_inline:nnnn {1} {3} {\tl_count:n {#1}}
+ {
+ \iow_term:x {
+ \tl_item:Nn \l__spath_tmpa_tl {##1}
+ {\tl_item:Nn \l__spath_tmpa_tl {##1+1}}
+ {\tl_item:Nn \l__spath_tmpa_tl {##1+2}}
+ }
}
- \tl_gset_eq:NN \l__spath_smuggle_tl \l__spath_tmpa_tl
- \group_end:
- \tl_set_eq:NN #4 \l__spath_smuggle_tl
}
+\cs_generate_variant:Nn \spath_show:n {V, v}
-\cs_generate_variant:Nn \spath_split_curve:nnNN {nVNN, VVNN}
+\cs_new_protected_nopar:Npn \spath_get_current_path:N #1
+{
+ \pgfsyssoftpath at getcurrentpath #1
+}
+\cs_new_protected_nopar:Npn \spath_gget_current_path:N #1
+{
+ \pgfsyssoftpath at getcurrentpath #1
+ \tl_gset_eq:NN #1 #1
+}
+\cs_new_protected_nopar:Npn \spath_protocol_path:n #1
+{
+ \spath_minbb:Nn \l__spath_tmpa_tl {#1}
+ \exp_last_unbraced:NV \pgf at protocolsizes\l__spath_tmpa_tl
+
+ \spath_maxbb:Nn \l__spath_tmpa_tl {#1}
+ \exp_last_unbraced:NV \pgf at protocolsizes\l__spath_tmpa_tl
+}
+\cs_generate_variant:Nn \spath_protocol_path:n {V}
+\cs_new_protected_nopar:Npn \spath_set_current_path:n #1
+{
+ \spath_protocol_path:n {#1}
+ \tl_set:Nn \l__spath_tmpa_tl {#1}
+ \pgfsyssoftpath at setcurrentpath\l__spath_tmpa_tl
+}
+\cs_new_protected_nopar:Npn \spath_set_current_path:N #1
+{
+ \spath_protocol_path:V #1
+ \pgfsyssoftpath at setcurrentpath #1
+}
+\cs_generate_variant:Nn \spath_set_current_path:N {c}
+\cs_new_protected_nopar:Npn \spath_use_path:nn #1#2
+{
+ \spath_set_current_path:n {#1}
+ \pgfusepath{#2}
+}
+\cs_new_protected_nopar:Npn \spath_tikz_path:nn #1#2
+{
+ \path[#1] \pgfextra{
+ \spath_set_current_path:n {#2}
+ \tl_put_right:Nn \tikz at preactions {\def\tikz at actions@path{#2}}
+ };
+}
+\cs_generate_variant:Nn \spath_tikz_path:nn {Vn, VV, nv, Vv, nV}
+\cs_new_protected_nopar:Npn \spath_set_tikz_coords:n #1
+{
+ \spath_finalpoint:Nn \l__spath_tmpa_tl {#1}
+ \tl_set:Nx \l__spath_tmpa_tl
+ {
+ \exp_not:c {tikz at lastx}=\tl_item:Nn \l__spath_tmpa_tl {1}
+ \exp_not:c {tikz at lasty}=\tl_item:Nn \l__spath_tmpa_tl {2}
+ \exp_not:c {tikz at lastxsaved}=\tl_item:Nn \l__spath_tmpa_tl {1}
+ \exp_not:c {tikz at lastysaved}=\tl_item:Nn \l__spath_tmpa_tl {2}
+ }
+ \tl_use:N \l__spath_tmpa_tl
+}
+\cs_generate_variant:Nn \spath_set_tikz_coords:n {V, v}
%%
-%% Copyright (C) 2011-2019 by Andrew Stacey <stacey at math.ntnu.no>
+%% Copyright (C) 2011-2019 by Andrew Stacey <loopspace at mathforge.org>
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License (LPPL), either
@@ -1500,13 +3130,16 @@
%% This work consists of the files spath3.dtx
%% calligraphy_doc.tex
%% knots_doc.tex
+%% spath3.tex
%% and the derived files spath3.ins,
%% spath3_code.pdf,
%% spath3.sty,
%% tikzlibrarycalligraphy.code.tex
%% tikzlibraryknots.code.tex
+%% tikzlibraryspath3.code.tex
%% calligraphy.pdf
%% knots.pdf
+%% spath3.pdf
%% README
%%
%%
Modified: trunk/Master/texmf-dist/tex/latex/spath3/tikzlibrarycalligraphy.code.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/spath3/tikzlibrarycalligraphy.code.tex 2021-01-23 10:56:29 UTC (rev 57503)
+++ trunk/Master/texmf-dist/tex/latex/spath3/tikzlibrarycalligraphy.code.tex 2021-01-23 22:17:41 UTC (rev 57504)
@@ -4,10 +4,10 @@
%%
%% The original source files were:
%%
-%% spath3.dtx (with options: `calligraphy')
+%% spath3_code.dtx (with options: `calligraphy')
%% ----------------------------------------------------------------
%% spath3 --- Functions for manipulating PGF soft paths
-%% E-mail: stacey at math.ntnu.no
+%% E-mail: loopspace at mathforge.org
%% Released under the LaTeX Project Public License v1.3c or later
%% See http://www.latex-project.org/lppl.txt
%% ----------------------------------------------------------------
@@ -17,10 +17,24 @@
\tl_new:N \l__cal_tmpa_tl
\tl_new:N \l__cal_tmpb_tl
+\tl_new:N \l__cal_tmp_path_tl
+\tl_new:N \l__cal_tmp_rpath_tl
+\tl_new:N \l__cal_tmp_rpathb_tl
+\tl_new:N \l__cal_tmp_patha_tl
+
+\seq_new:N \l__cal_tmpa_seq
+
\int_new:N \l__cal_tmpa_int
\int_new:N \l__cal_tmpb_int
-\int_new:N \l__cal_path_component_int
-\int_new:N \l__cal_label_int
+\int_new:N \g__cal_path_component_int
+\int_new:N \g__cal_label_int
+
+\fp_new:N \l__cal_tmpa_fp
+\fp_new:N \l__cal_tmpb_fp
+\fp_new:N \l__cal_tmpc_fp
+\fp_new:N \l__cal_tmpd_fp
+\fp_new:N \l__cal_tmpe_fp
+
\dim_new:N \l__cal_tmpa_dim
\dim_new:N \l__cal_tmpb_dim
\dim_new:N \l__cal_tmpc_dim
@@ -29,10 +43,12 @@
\dim_new:N \l__cal_tmpf_dim
\dim_new:N \l__cal_tmpg_dim
\dim_new:N \l__cal_tmph_dim
+
\bool_new:N \l__cal_annotate_bool
\bool_new:N \l__cal_taper_start_bool
\bool_new:N \l__cal_taper_end_bool
\bool_new:N \l__cal_taperable_bool
+
\dim_new:N \l__cal_taper_width_dim
\dim_new:N \l__cal_line_width_dim
@@ -40,6 +56,8 @@
\bool_set_true:N \l__cal_taper_end_bool
\cs_generate_variant:Nn \tl_put_right:Nn {Nv}
+
+\msg_new:nnn { calligraphy } { undefined pen } { The~ pen~ "#1"~ is~ not~ defined. }
\tikzset{
define~pen/.code={
\tikzset{pen~name=#1}
@@ -46,8 +64,9 @@
\pgf at relevantforpicturesizefalse
\tikz at addmode{
\pgfsyssoftpath at getcurrentpath\l__cal_tmpa_tl
- \MakeSPathList{calligraphy pen \pgfkeysvalueof{/tikz/pen~name}}{\l__cal_tmpa_tl}
- \SPathListPrepare{calligraphy pen \pgfkeysvalueof{/tikz/pen~name}}
+ \spath_components_to_seq:NV \l__cal_tmpa_seq \l__cal_tmpa_tl
+ \seq_gclear_new:c {g__cal_pen_\pgfkeysvalueof{/tikz/pen~name}_seq}
+ \seq_gset_eq:cN {g__cal_pen_\pgfkeysvalueof{/tikz/pen~name}_seq} \l__cal_tmpa_seq
\pgfusepath{discard}%
}
},
@@ -54,13 +73,18 @@
define~pen/.default={default},
use~pen/.code={
\tikzset{pen~name=#1}
- \int_gzero:N \l__cal_path_component_int
+ \int_gzero:N \g__cal_path_component_int
\cs_set_eq:NN \pgfpathmoveto \cal_moveto:n
\tikz at addmode{
\pgfsyssoftpath at getcurrentpath\l__cal_tmpa_tl
- \MakeSPathList{calligraphy path}{\l__cal_tmpa_tl}
- \SPathListPrepare{calligraphy path}
- \CalligraphyPathCreate{calligraphy path}{\pgfkeysvalueof{/tikz/pen~name}}
+ \spath_components_to_seq:NV \l__cal_tmpa_seq \l__cal_tmpa_tl
+ \tl_if_exist:cTF {g__cal_pen_\pgfkeysvalueof{/tikz/pen~name}_seq}
+ {
+ \cal_path_create:Nc \l__cal_tmpa_seq {g__cal_pen_\pgfkeysvalueof{/tikz/pen~name}_seq}
+ }
+ {
+ \msg_warning:nnx { calligraphy } { undefined pen } { \pgfkeysvalueof{/tikz/pen~name} }
+ }
}
},
use~pen/.default={default},
@@ -132,8 +156,8 @@
\tl_set:cn {l__cal_stroke_style_#1} {#2}
},
this~stroke~style/.code={
- \tl_clear_new:c {l__cal_stroke_inline_style_ \int_use:N \l__cal_path_component_int}
- \tl_set:cn {l__cal_stroke_inline_style_ \int_use:N \l__cal_path_component_int} {#1}
+ \tl_clear_new:c {l__cal_stroke_inline_style_ \int_use:N \g__cal_path_component_int}
+ \tl_set:cn {l__cal_stroke_inline_style_ \int_use:N \g__cal_path_component_int} {#1}
},
annotate/.style={
annotate~if,
@@ -151,12 +175,13 @@
}
},
annotate~reset/.code={
- \int_gzero:N \l__cal_label_int
+ \int_gzero:N \g__cal_label_int
},
annotation~style/.initial={draw,->},
annotation~shift/.initial={(0,1ex)},
every~annotation~node/.initial={anchor=south~west},
annotation~node~style/.code~2~args={
+ \tl_clear_new:c {l__cal_annotation_style_ #1 _tl}
\tl_set:cn {l__cal_annotation_style_ #1 _tl}{#2}
},
tl~use:N/.code={
@@ -179,7 +204,7 @@
{
\pgfkeyssetvalue{\pgfkeyscurrentpath}{#1}
}
- }
+ },
}
\NewDocumentCommand \pen { O{} }
{
@@ -195,100 +220,99 @@
{
\path[use~ pen,every~ calligraphy/.try,#1]
}
-\NewDocumentCommand \CalligraphyPathCreate { m m }
+\cs_new_protected_nopar:Npn \cal_path_create:NN #1#2
{
\int_zero:N \l__cal_tmpa_int
- \tl_map_inline:cn {l__spath_list_#1}
+ \seq_map_inline:Nn #1
{
- \int_incr:N \l__cal_tmpa_int
- \int_zero:N \l__cal_tmpb_int
- \tl_map_inline:cn {l__spath_list_calligraphy pen #2}
+ \int_compare:nT {\tl_count:n {##1} > 3}
{
- \int_incr:N \l__cal_tmpb_int
- \group_begin:
- \pgfsys at beginscope
- \cal_apply_style:c {l__cal_stroke_style_ \int_use:N \l__cal_tmpa_int}
- \cal_apply_style:c {l__cal_stroke_inline_style_ \int_use:N \l__cal_tmpa_int}
- \cal_apply_style:c {l__cal_nib_style_ \int_use:N \l__cal_tmpb_int}
+ \int_incr:N \l__cal_tmpa_int
+ \int_zero:N \l__cal_tmpb_int
- \spath_clone:nn {##1} {calligraphy temp path}
+ \tl_set:Nn \l__cal_tmp_path_tl {##1}
+ \spath_open:N \l__cal_tmp_path_tl
+ \spath_reverse:NV \l__cal_tmp_rpath_tl \l__cal_tmp_path_tl
- \__spath_get:nnN {####1} {initial point} \l__cal_tmpa_tl
- \spath_translate:nV {calligraphy temp path} \l__cal_tmpa_tl
+ \seq_map_inline:Nn #2
+ {
+ \int_incr:N \l__cal_tmpb_int
+ \group_begin:
+ \pgfsys at beginscope
+ \cal_apply_style:c {l__cal_stroke_style_ \int_use:N \l__cal_tmpa_int}
+ \cal_apply_style:c {l__cal_stroke_inline_style_ \int_use:N \l__cal_tmpa_int}
+ \cal_apply_style:c {l__cal_nib_style_ \int_use:N \l__cal_tmpb_int}
- \__spath_get:nnN {####1} {length} \l__cal_tmpa_tl
+ \spath_initialpoint:Nn \l__cal_tmpa_tl {####1}
+ \tl_set_eq:NN \l__cal_tmp_patha_tl \l__cal_tmp_path_tl
+ \spath_translate:NV \l__cal_tmp_patha_tl \l__cal_tmpa_tl
- \int_compare:nTF {\l__cal_tmpa_tl = 1}
- {
- \cal_at_least_three:n {calligraphy temp path}
+ \int_compare:nTF {\tl_count:n {####1} == 3}
+ {
+ \cal_at_least_three:N \l__cal_tmp_patha_tl
+ \spath_protocol_path:V \l__cal_tmp_patha_tl
- \spath_protocol_path:n {calligraphy temp path}
+ \tikz at options
+ \dim_set:Nn \l__cal_line_width_dim {\pgflinewidth}
+ \cal_maybe_taper:N \l__cal_tmp_patha_tl
+ }
+ {
+ \spath_weld:Nn \l__cal_tmp_patha_tl {####1}
+ \spath_weld:NV \l__cal_tmp_patha_tl \l__cal_tmp_rpath_tl
+ \spath_reverse:Nn \l__cal_tmp_rpathb_tl {####1}
+ \spath_weld:NV \l__cal_tmp_patha_tl \l__cal_tmp_rpathb_tl
- \__spath_get:nnN {calligraphy temp path} {path} \l__cal_tmpa_tl
+ \tl_clear:N \l__cal_tmpa_tl
+ \tl_set:Nn \l__cal_tmpa_tl {fill=\pgfkeysvalueof{/tikz/pen~colour},draw=none}
+ \tl_if_exist:cT {l__cal_stroke_style_ \int_use:N \l__cal_tmpa_int}
+ {
+ \tl_put_right:Nv \l__cal_tmpa_tl {l__cal_stroke_style_ \int_use:N \l__cal_tmpa_int}
+ }
+ \tl_if_exist:cT {l__cal_stroke_inline_style_ \int_use:N \l__cal_tmpa_int}
+ {
+ \tl_put_right:Nn \l__cal_tmpa_tl {,}
+ \tl_put_right:Nv \l__cal_tmpa_tl {l__cal_stroke_inline_style_ \int_use:N \l__cal_tmpa_int}
+ }
+ \tl_if_exist:cT {l__cal_nib_style_ \int_use:N \l__cal_tmpb_int}
+ {
+ \tl_put_right:Nn \l__cal_tmpa_tl {,}
+ \tl_put_right:Nv \l__cal_tmpa_tl {l__cal_nib_style_ \int_use:N \l__cal_tmpb_int}
+ }
+ \spath_tikz_path:VV \l__cal_tmpa_tl \l__cal_tmp_patha_tl
- \tikz at options
- \dim_set:Nn \l__cal_line_width_dim {\pgflinewidth}
- \cal_maybe_taper:N \l__cal_tmpa_tl
+ }
+ \pgfsys at endscope
+ \group_end:
}
+
+ \bool_if:NT \l__cal_annotate_bool
{
+ \seq_get_right:NN #2 \l__cal_tmpa_tl
+ \spath_finalpoint:NV \l__cal_tmpa_tl \l__cal_tmpa_tl
+ \spath_translate:NV \l__cal_tmp_path_tl \l__cal_tmpa_tl
+ \tikz at scan@one at point\pgfutil at firstofone\pgfkeysvalueof{/tikz/annotation~shift}
- \spath_weld:nn {calligraphy temp path} {####1}
- \spath_reverse:n {##1}
- \spath_reverse:n {####1}
- \spath_weld:nn {calligraphy temp path} {##1}
- \spath_weld:nn {calligraphy temp path} {####1}
- \spath_reverse:n {##1}
- \spath_reverse:n {####1}
+ \spath_translate:Nnn \l__cal_tmp_path_tl {\pgf at x} {\pgf at y}
- \tl_clear:N \l__cal_tmpa_tl
- \tl_set:Nn \l__cal_tmpa_tl {fill=\pgfkeysvalueof{/tikz/pen~colour},draw=none}
- \tl_if_exist:cT {l__cal_stroke_style_ \int_use:N \l__cal_tmpa_int}
- {
- \tl_put_right:Nv \l__cal_tmpa_tl {l__cal_stroke_style_ \int_use:N \l__cal_tmpa_int}
- }
- \tl_if_exist:cT {l__cal_stroke_inline_style_ \int_use:N \l__cal_tmpa_int}
- {
- \tl_put_right:Nn \l__cal_tmpa_tl {,}
- \tl_put_right:Nv \l__cal_tmpa_tl {l__cal_stroke_inline_style_ \int_use:N \l__cal_tmpa_int}
- }
- \tl_if_exist:cT {l__cal_nib_style_ \int_use:N \l__cal_tmpb_int}
- {
- \tl_put_right:Nn \l__cal_tmpa_tl {,}
- \tl_put_right:Nv \l__cal_tmpa_tl {l__cal_nib_style_ \int_use:N \l__cal_tmpb_int}
- }
- \spath_tikz_path:Vn \l__cal_tmpa_tl {calligraphy temp path}
+ \pgfkeysgetvalue{/tikz/annotation~style}{\l__cal_tmpa_tl}
+ \spath_tikz_path:VV \l__cal_tmpa_tl \l__cal_tmp_path_tl
+ \spath_finalpoint:NV \l__cal_tmpa_tl \l__cal_tmp_path_tl
+
+ \exp_last_unbraced:NV \pgfqpoint \l__cal_tmpa_tl
+ \begin{scope}[reset~ cm]
+ \node[every~annotation~node/.try,tl~use:c = {l__cal_annotation_style_ \int_use:N \l__cal_tmpa_int _tl}] at (\pgf at x,\pgf at y) {\int_use:N \l__cal_tmpa_int};
+ \end{scope}
}
- \pgfsys at endscope
- \group_end:
}
- \bool_if:NT \l__cal_annotate_bool
- {
- \spath_clone:nn {##1} {calligraphy temp path}
- \tl_set_eq:Nc \l_tmpa_tl {l__spath_list_calligraphy pen #2}
- \tl_reverse:N \l_tmpa_tl
- \tl_set:Nx \l_tmpa_tl {\tl_head:N \l_tmpa_tl}
- \spath_generate_finalpoint:V \l_tmpa_tl
- \spath_get:VnN \l_tmpa_tl {final point} \l_tmpa_tl
- \spath_translate:nV {calligraphy temp path} \l_tmpa_tl
- \tikz at scan@one at point\pgfutil at firstofone\pgfkeysvalueof{/tikz/annotation~shift}
- \spath_translate:nnn {calligraphy temp path} {\pgf at x} {\pgf at y}
-
- \pgfkeysgetvalue{/tikz/annotation~style}{\l_tmpa_tl}
- \spath_tikz_path:Vn \l_tmpa_tl {calligraphy temp path}
- \spath_get:nnN {calligraphy temp path} {final point} \l_tmpa_tl
- \exp_last_unbraced:NV \pgfqpoint \l_tmpa_tl
- \begin{scope}[reset~ cm]
- \node[every~annotation~node/.try,tl~use:c = {l__cal_annotation_style_ \int_use:N \l__cal_tmpa_int _tl}] at (\pgf at x,\pgf at y) {\int_use:N \l__cal_tmpa_int};
- \end{scope}
- }
}
}
+\cs_generate_variant:Nn \cal_path_create:NN {Nc}
\cs_new_eq:NN \cal_orig_moveto:n \pgfpathmoveto
\cs_new_nopar:Npn \cal_moveto:n #1
{
- \int_gincr:N \l__cal_path_component_int
+ \int_gincr:N \g__cal_path_component_int
\cal_orig_moveto:n {#1}
}
\cs_new_nopar:Npn \cal_apply_style:N #1
@@ -298,155 +322,33 @@
}
}
\cs_generate_variant:Nn \cal_apply_style:N {c}
-\cs_new_nopar:Npn \cal_at_least_three:n #1
+\cs_new_protected_nopar:Npn \cal_at_least_three:Nn #1#2
{
- \spath_get:nnN {#1} {real length} \l__cal_tmpa_tl
+ \spath_reallength:Nn \l__cal_tmpa_int {#2}
\tl_clear:N \l__cal_tmpb_tl
- \int_compare:nTF {\l__cal_tmpa_tl = 1}
+ \tl_set:Nn \l__cal_tmpb_tl {#2}
+ \int_compare:nTF {\l__cal_tmpa_int = 1}
{
- \spath_get:nnN {#1} {path} \l__cal_tmpa_tl
- \spath_map_segment_inline:Nn \l__cal_tmpa_tl
- {
- \tl_case:NnF ##1 {
- \g__spath_lineto_tl {
- \cal_split_line_in_three:NN \l__cal_tmpb_tl ##2
- }
- \g__spath_curvetoa_tl {
- \cal_split_curve_in_three:NN \l__cal_tmpb_tl ##2
- }
- }
- {
- \tl_put_right:NV \l__cal_tmpb_tl ##2
- }
- }
- \spath_put:nnV {#1} {path} \l__cal_tmpb_tl
+ \spath_split_at:Nn \l__cal_tmpb_tl {2/3}
+ \spath_split_at:Nn \l__cal_tmpb_tl {1/2}
}
{
- \int_compare:nT {\l__cal_tmpa_tl = 2}
+ \int_compare:nT {\l__cal_tmpa_int = 2}
{
- \spath_get:nnN {#1} {path} \l__cal_tmpa_tl
- \spath_map_segment_inline:Nn \l__cal_tmpa_tl
- {
- \tl_case:NnF ##1 {
- \g__spath_lineto_tl {
- \cal_split_line_in_two:NN \l__cal_tmpb_tl ##2
- }
- \g__spath_curvetoa_tl {
- \cal_split_curve_in_two:NN \l__cal_tmpb_tl ##2
- }
- }
- {
- \tl_put_right:NV \l__cal_tmpb_tl ##2
- }
- }
- \spath_put:nnV {#1} {path} \l__cal_tmpb_tl
+ \spath_split_at:Nn \l__cal_tmpb_tl {1.5}
+ \spath_split_at:Nn \l__cal_tmpb_tl {.5}
}
}
+ \tl_set_eq:NN #1 \l__cal_tmpb_tl
}
-\cs_new_nopar:Npn \cal_split_line_in_two:NN #1#2
+\cs_generate_variant:Nn \cal_at_least_three:Nn {NV}
+\cs_new_protected_nopar:Npn \cal_at_least_three:N #1
{
- \tl_set_eq:NN \l__cal_tmpc_tl #2
-
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \dim_set:Nn \l__cal_tmpa_dim {\tl_head:N \l__cal_tmpc_tl}
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \dim_set:Nn \l__cal_tmpb_dim {\tl_head:N \l__cal_tmpc_tl}
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \dim_set:Nn \l__cal_tmpc_dim {\tl_head:N \l__cal_tmpc_tl}
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
- \dim_set:Nn \l__cal_tmpd_dim {\tl_head:N \l__cal_tmpc_tl}
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \tl_put_right:NV #1 \g__spath_lineto_tl
-
- \tl_put_right:Nx #1 {
- {\dim_eval:n {(\l__cal_tmpa_dim + \l__cal_tmpc_dim)/2}}
- {\dim_eval:n {(\l__cal_tmpb_dim + \l__cal_tmpd_dim)/2}}
- }
-
- \tl_put_right:NV #1 \g__spath_lineto_tl
- \tl_put_right:Nx #1 {
- {\dim_use:N \l__cal_tmpc_dim}
- {\dim_use:N \l__cal_tmpd_dim}
- }
+ \cal_at_least_three:NV #1#1
}
-\cs_new_nopar:Npn \cal_split_line_in_three:NN #1#2
+\cs_generate_variant:Nn \cal_at_least_three:N {c}
+\cs_new_protected_nopar:Npn \cal_maybe_taper:N #1
{
- \tl_set_eq:NN \l__cal_tmpc_tl #2
-
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \dim_set:Nn \l__cal_tmpa_dim {\tl_head:N \l__cal_tmpc_tl}
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \dim_set:Nn \l__cal_tmpb_dim {\tl_head:N \l__cal_tmpc_tl}
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \dim_set:Nn \l__cal_tmpc_dim {\tl_head:N \l__cal_tmpc_tl}
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
- \dim_set:Nn \l__cal_tmpd_dim {\tl_head:N \l__cal_tmpc_tl}
- \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl}
-
- \tl_put_right:NV #1 \g__spath_lineto_tl
-
- \tl_put_right:Nx #1 {
- {\dim_eval:n {(2\l__cal_tmpa_dim + \l__cal_tmpc_dim)/3}}
- {\dim_eval:n {(2\l__cal_tmpb_dim + \l__cal_tmpd_dim)/3}}
- }
-
- \tl_put_right:NV #1 \g__spath_lineto_tl
-
- \tl_put_right:Nx #1 {
- {\dim_eval:n {(\l__cal_tmpa_dim + 2\l__cal_tmpc_dim)/3}}
- {\dim_eval:n {(\l__cal_tmpb_dim + 2\l__cal_tmpd_dim)/3}}
- }
-
- \tl_put_right:NV #1 \g__spath_lineto_tl
- \tl_put_right:Nx #1 {
- {\dim_use:N \l__cal_tmpc_dim}
- {\dim_use:N \l__cal_tmpd_dim}
- }
-}
-\cs_new_nopar:Npn \cal_split_curve_in_two:NN #1#2
-{
- \spath_split_curve:nVNN {.5} #2 \l_tmpa_tl \l_tmpb_tl
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_put_right:NV #1 \l_tmpa_tl
- \tl_put_right:NV #1 \l_tmpb_tl
-}
-\cs_new_nopar:Npn \cal_split_curve_in_three:NN #1#2
-{
- \spath_split_curve:nVNN {1/3} #2 \l_tmpa_tl \l_tmpb_tl
-
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_put_right:NV #1 \l_tmpa_tl
-
- \spath_split_curve:nVNN {.5} \l_tmpb_tl \l_tmpa_tl \l_tmpb_tl
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_put_right:NV #1 \l_tmpa_tl
- \tl_put_right:NV #1 \l_tmpb_tl
-}
-\cs_new_nopar:Npn \cal_maybe_taper:N #1
-{
\tl_set_eq:NN \l__cal_tmpa_tl #1
\bool_if:NT \l__cal_taper_start_bool
@@ -458,7 +360,7 @@
\tl_case:NnF \l__cal_tmpb_tl
{
- \g__spath_lineto_tl
+ \c_spath_lineto_tl
{
\bool_set_true:N \l__cal_taperable_bool
@@ -472,9 +374,9 @@
{
\tl_set:Nx \l__cal_tmpa_tl {\tl_tail:N \l__cal_tmpa_tl}
}
- \tl_put_left:NV \l__cal_tmpa_tl \g__spath_moveto_tl
+ \tl_put_left:NV \l__cal_tmpa_tl \c_spath_moveto_tl
}
- \g__spath_curvetoa_tl
+ \c_spath_curvetoa_tl
{
\bool_set_true:N \l__cal_taperable_bool
\dim_set:Nn \l__cal_tmpc_dim {\tl_item:Nn \l__cal_tmpa_tl {5}}
@@ -487,7 +389,7 @@
{
\tl_set:Nx \l__cal_tmpa_tl {\tl_tail:N \l__cal_tmpa_tl}
}
- \tl_put_left:NV \l__cal_tmpa_tl \g__spath_moveto_tl
+ \tl_put_left:NV \l__cal_tmpa_tl \c_spath_moveto_tl
}
}
{
@@ -510,7 +412,7 @@
\tl_case:NnF \l__cal_tmpb_tl
{
- \g__spath_lineto_tl
+ \c_spath_lineto_tl
{
\bool_set_true:N \l__cal_taperable_bool
@@ -527,7 +429,7 @@
}
\tl_reverse:N \l__cal_tmpa_tl
}
- \g__spath_curveto_tl
+ \c_spath_curveto_tl
{
\bool_set_true:N \l__cal_taperable_bool
\dim_set:Nn \l__cal_tmpc_dim {\tl_item:Nn \l__cal_tmpa_tl {-5}}
@@ -560,10 +462,10 @@
\pgfusepath{stroke}
}
-\cs_new_nopar:Npn \__cal_taper_aux:
+\cs_new_protected_nopar:Npn \__cal_taper_aux:
{
\tl_clear:N \l__cal_tmpb_tl
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_moveto_tl
+ \tl_put_right:NV \l__cal_tmpb_tl \c_spath_moveto_tl
\fp_set:Nn \l__cal_tmpa_fp
{
@@ -603,7 +505,7 @@
{\dim_eval:n { \fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpb_dim}}
}
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetoa_tl
+ \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curvetoa_tl
\tl_put_right:Nx \l__cal_tmpb_tl
{
@@ -611,7 +513,7 @@
{\dim_eval:n { \fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpd_dim}}
}
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetob_tl
+ \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curvetob_tl
\tl_put_right:Nx \l__cal_tmpb_tl
{
@@ -619,7 +521,7 @@
{\dim_eval:n { \fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmpf_dim}}
}
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curveto_tl
+ \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curveto_tl
\tl_put_right:Nx \l__cal_tmpb_tl
{
@@ -627,7 +529,7 @@
{\dim_eval:n { \fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmph_dim}}
}
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetoa_tl
+ \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curvetoa_tl
\tl_put_right:Nx \l__cal_tmpb_tl
{
@@ -635,7 +537,7 @@
{\dim_eval:n { \fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmph_dim + \fp_to_dim:n {1.32* \l__cal_tmpc_fp}}}
}
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetob_tl
+ \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curvetob_tl
\tl_put_right:Nx \l__cal_tmpb_tl
{
@@ -643,7 +545,7 @@
{\dim_eval:n { -\fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmph_dim + \fp_to_dim:n {1.32 * \l__cal_tmpc_fp}}}
}
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curveto_tl
+ \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curveto_tl
\tl_put_right:Nx \l__cal_tmpb_tl
{
@@ -651,7 +553,7 @@
{\dim_eval:n { -\fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmph_dim}}
}
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetoa_tl
+ \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curvetoa_tl
\tl_put_right:Nx \l__cal_tmpb_tl
{
@@ -659,7 +561,7 @@
{\dim_eval:n { -\fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmpf_dim}}
}
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetob_tl
+ \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curvetob_tl
\tl_put_right:Nx \l__cal_tmpb_tl
{
@@ -667,7 +569,7 @@
{\dim_eval:n { -\fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpd_dim}}
}
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curveto_tl
+ \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curveto_tl
\tl_put_right:Nx \l__cal_tmpb_tl
{
@@ -675,7 +577,7 @@
{\dim_eval:n { -\fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpb_dim}}
}
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetoa_tl
+ \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curvetoa_tl
\tl_put_right:Nx \l__cal_tmpb_tl
{
@@ -683,7 +585,7 @@
{\dim_eval:n { -\fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpb_dim - \fp_to_dim:n {1.32* \l__cal_tmpa_fp}}}
}
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetob_tl
+ \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curvetob_tl
\tl_put_right:Nx \l__cal_tmpb_tl
{
@@ -691,7 +593,7 @@
{\dim_eval:n { \fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpb_dim - \fp_to_dim:n {1.32 * \l__cal_tmpa_fp}}}
}
- \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curveto_tl
+ \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curveto_tl
\tl_put_right:Nx \l__cal_tmpb_tl
{
@@ -704,8 +606,14 @@
\pgfusepath{fill}
}
\tl_set:Nn \l__cal_tmpa_tl {\pgfsyssoftpath at movetotoken{0pt}{0pt}}
-\MakeSPathList{calligraphy pen copperplate}{\l__cal_tmpa_tl}
-\SPathListPrepare{calligraphy pen copperplate}
+\spath_components_to_seq:NV \l__cal_tmpa_seq \l__cal_tmpa_tl
+\seq_gclear_new:N \g__cal_pen_copperplate_seq
+\seq_gset_eq:NN \g__cal_pen_copperplate_seq \l__cal_tmpa_seq
+\DeclareDocumentCommand \CopperplatePath { m }
+{
+ \spath_components_to_seq:NV \l__cal_tmpa_seq #1
+ \cal_path_create:NN \l__cal_tmpa_seq \g__cal_pen_copperplate_seq
+}
\ExplSyntaxOff
\expandafter\ifx\csname pgfdeclaredecoration\endcsname\relax
\else
@@ -745,9 +653,7 @@
taper
}%
\pgfsyssoftpath at getcurrentpath\cal at tmp@path
- \MakeSPathList{calligraphy path}{\cal at tmp@path}%
- \SPathListPrepare{calligraphy path}%
- \CalligraphyPathCreate{calligraphy path}{copperplate}%
+ \CopperplatePath{\cal at tmp@path}
}
\state{final}{}
}
@@ -774,9 +680,7 @@
taper
}%
\pgfsyssoftpath at getcurrentpath\cal at tmp@path
- \MakeSPathList{calligraphy path}{\cal at tmp@path}%
- \SPathListPrepare{calligraphy path}%
- \CalligraphyPathCreate{calligraphy path}{copperplate}%
+ \CopperplatePath{\cal at tmp@path}
}
\state{final}{}%
}
@@ -798,15 +702,13 @@
taper
}%
\pgfsyssoftpath at getcurrentpath\cal at tmp@path
- \MakeSPathList{calligraphy path}{\cal at tmp@path}%
- \SPathListPrepare{calligraphy path}%
- \CalligraphyPathCreate{calligraphy path}{copperplate}%
+ \CopperplatePath{\cal at tmp@path}
}
\state{final}{}%
}
\fi
%%
-%% Copyright (C) 2011-2019 by Andrew Stacey <stacey at math.ntnu.no>
+%% Copyright (C) 2011-2019 by Andrew Stacey <loopspace at mathforge.org>
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License (LPPL), either
@@ -821,13 +723,16 @@
%% This work consists of the files spath3.dtx
%% calligraphy_doc.tex
%% knots_doc.tex
+%% spath3.tex
%% and the derived files spath3.ins,
%% spath3_code.pdf,
%% spath3.sty,
%% tikzlibrarycalligraphy.code.tex
%% tikzlibraryknots.code.tex
+%% tikzlibraryspath3.code.tex
%% calligraphy.pdf
%% knots.pdf
+%% spath3.pdf
%% README
%%
%%
Modified: trunk/Master/texmf-dist/tex/latex/spath3/tikzlibraryknots.code.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/spath3/tikzlibraryknots.code.tex 2021-01-23 10:56:29 UTC (rev 57503)
+++ trunk/Master/texmf-dist/tex/latex/spath3/tikzlibraryknots.code.tex 2021-01-23 22:17:41 UTC (rev 57504)
@@ -4,10 +4,10 @@
%%
%% The original source files were:
%%
-%% spath3.dtx (with options: `knots')
+%% spath3_code.dtx (with options: `knots')
%% ----------------------------------------------------------------
%% spath3 --- Functions for manipulating PGF soft paths
-%% E-mail: stacey at math.ntnu.no
+%% E-mail: loopspace at mathforge.org
%% Released under the LaTeX Project Public License v1.3c or later
%% See http://www.latex-project.org/lppl.txt
%% ----------------------------------------------------------------
@@ -14,7 +14,7 @@
%%
%%
\RequirePackage{spath3}
-\usetikzlibrary{intersections}
+\usetikzlibrary{intersections,spath3}
\ExplSyntaxOn
@@ -22,8 +22,6 @@
\tl_new:N \l__knot_tmpb_tl
\tl_new:N \l__knot_tmpc_tl
\tl_new:N \l__knot_tmpd_tl
-\tl_new:N \l__knot_tmpe_tl
-\tl_new:N \l__knot_tmpf_tl
\tl_new:N \l__knot_tmpg_tl
\tl_new:N \l__knot_redraws_tl
\tl_new:N \l__knot_clip_width_tl
@@ -31,16 +29,21 @@
\tl_new:N \l__knot_node_tl
\tl_new:N \l__knot_aux_tl
\tl_new:N \l__knot_auxa_tl
+\tl_new:N \l__knot_prefix_tl
+\seq_new:N \l__knot_segments_seq
+
\int_new:N \l__knot_tmpa_int
\int_new:N \l__knot_strands_int
-\int_new:N \l__knot_intersections_int
-\int_new:N \l__knot_filaments_int
+\int_new:N \g__knot_intersections_int
+\int_new:N \g__knot_filaments_int
\int_new:N \l__knot_component_start_int
+\fp_new:N \l__knot_tmpa_fp
+\fp_new:N \l__knot_tmpb_fp
+
\dim_new:N \l__knot_tmpa_dim
\dim_new:N \l__knot_tmpb_dim
-\dim_new:N \l__knot_tmpc_dim
\dim_new:N \l__knot_tolerance_dim
\dim_new:N \l__knot_clip_bg_radius_dim
\dim_new:N \l__knot_clip_draw_radius_dim
@@ -56,10 +59,16 @@
\bool_new:N \l__knot_skip_bool
\bool_new:N \l__knot_save_bool
-\seq_new:N \l__knot_nodes_seq
+\seq_new:N \g__knot_nodes_seq
\bool_set_true:N \l__knot_ignore_ends_bool
\tikzset{
+ spath/prefix/knot/.style={
+ spath/set~ prefix=knot strand,
+ },
+ spath/suffix/knot/.style={
+ spath/set~ suffix={},
+ },
knot/.code={
\tl_if_eq:nnTF {#1} {none}
{
@@ -218,7 +227,7 @@
\int_incr:N \l__knot_strands_int
\tl_clear_new:c {l__knot_options_strand \int_use:N \l__knot_strands_int}
\tl_set:cn {l__knot_options_strand \int_use:N \l__knot_strands_int} {#1}
- \path[#1,save~ spath=knot strand \int_use:N \l__knot_strands_int]
+ \path[#1,spath/set~ name=knot,spath/save=\int_use:N \l__knot_strands_int]
}
\NewDocumentEnvironment{knot} { O{} }
{
@@ -232,7 +241,7 @@
\tikzset{knot~ diagram/.cd,every~ knot~ diagram/.try,#1}
\int_zero:N \l__knot_strands_int
\tl_clear:N \l__knot_redraws_tl
- \seq_gclear:N \l__knot_nodes_seq
+ \seq_gclear:N \g__knot_nodes_seq
}
\cs_new_protected_nopar:Npn \knot_render:
{
@@ -245,7 +254,7 @@
\bool_if:NTF \l__knot_self_intersections_bool
{
\knot_split_strands:
- \int_set_eq:NN \l__knot_tmpa_int \l__knot_filaments_int
+ \int_set_eq:NN \l__knot_tmpa_int \g__knot_filaments_int
\tl_set:Nn \l__knot_prefix_tl {filament}
}
{
@@ -252,18 +261,16 @@
\int_set_eq:NN \l__knot_tmpa_int \l__knot_strands_int
\tl_set:Nn \l__knot_prefix_tl {strand}
}
- \int_gzero:N \l__knot_intersections_int
- \bool_if:NTF \l__knot_draft_bool
+ \int_gzero:N \g__knot_intersections_int
+ \tl_clear:N \l__knot_node_tl
+ \bool_if:NT \l__knot_draft_bool
{
\tl_set:Nn \l__knot_node_tl {
\exp_not:N \node[coordinate,
- pin={[node~ contents={\int_use:N \l__knot_intersections_int},knot~ diagram/draft/crossing~ label, knot~ diagram/draft/crossing~ \int_use:N \l__knot_intersections_int \c_space_tl label/.try]
+ pin={[node~ contents={\int_use:N \g__knot_intersections_int},knot~ diagram/draft/crossing~ label, knot~ diagram/draft/crossing~ \int_use:N \g__knot_intersections_int \c_space_tl label/.try]
}]
}
}
- {
- \tl_set:Nn \l__knot_node_tl {\exp_not:N \node[coordinate]}
- }
\int_step_variable:nnnNn {1} {1} {\l__knot_tmpa_int - 1} \l__knot_tmpa_tl
{
\int_step_variable:nnnNn {\tl_use:N \l__knot_tmpa_tl + 1} {1} {\l__knot_tmpa_int} \l__knot_tmpb_tl
@@ -272,7 +279,7 @@
}
}
\tl_use:N \l__knot_redraws_tl
- \seq_use:Nn \l__knot_nodes_seq {}
+ \seq_use:Nn \g__knot_nodes_seq {}
}
\endpgfscope
}
@@ -280,11 +287,11 @@
{
\pgfscope
\group_begin:
- \tl_set:Nn \l_tmpa_tl {knot~ diagram/every~ strand/.try,}
- \tl_put_right:Nv \l_tmpa_tl {l__knot_options_strand #1}
- \tl_put_right:Nn \l_tmpa_tl {,knot~ diagram/only~ when~ rendering/.try,only~ when~ rendering/.try}
- \spath_bake_round:n {knot strand #1}
- \spath_tikz_path:Vn \l_tmpa_tl {knot strand #1}
+ \spath_bake_round:c {knot strand #1}
+ \tl_set:Nn \l__knot_tmpa_tl {knot~ diagram/every~ strand/.try,}
+ \tl_put_right:Nv \l__knot_tmpa_tl {l__knot_options_strand #1}
+ \tl_put_right:Nn \l__knot_tmpa_tl {,knot~ diagram/only~ when~ rendering/.try,only~ when~ rendering/.try}
+ \spath_tikz_path:Vv \l__knot_tmpa_tl {knot strand #1}
\group_end:
\endpgfscope
}
@@ -293,11 +300,11 @@
{
\bool_if:NT \l__knot_draft_bool
{
- \spath_get:nnN {knot strand #1} {final point} \l__knot_tmpb_tl
+ \spath_finalpoint:Nv \l__knot_tmpb_tl {knot strand #1}
\dim_set:Nn \l__knot_tmpa_dim {\tl_item:Nn \l__knot_tmpb_tl {1}}
\dim_set:Nn \l__knot_tmpb_dim {\tl_item:Nn \l__knot_tmpb_tl {2}}
\node[knot~ diagram/draft/strand~label] at (\l__knot_tmpa_dim,\l__knot_tmpb_dim) {#1};
- \spath_get:nnN {knot strand #1} {initial point} \l__knot_tmpb_tl
+ \spath_initialpoint:Nv \l__knot_tmpb_tl {knot strand #1}
\dim_set:Nn \l__knot_tmpa_dim {\tl_item:Nn \l__knot_tmpb_tl {1}}
\dim_set:Nn \l__knot_tmpb_dim {\tl_item:Nn \l__knot_tmpb_tl {2}}
\node[knot~ diagram/draft/strand~label] at (\l__knot_tmpa_dim,\l__knot_tmpb_dim) {#1};
@@ -309,84 +316,86 @@
}
{
\tl_clear:N \l__knot_tmpa_tl
- \spath_map_segment_function:nN {knot strand #1} \knot_split_self_intersects:NN
- \spath_put:nnV {knot strand #1} {path} \l__knot_tmpa_tl
+ \spath_segments_to_seq:Nv \l__knot_segments_seq {knot strand #1}
+ \seq_map_function:NN \l__knot_segments_seq \knot_split_self_intersects:N
+ \tl_set_eq:cN {knot strand #1} \l__knot_tmpa_tl
}
}
-\cs_new_protected_nopar:Npn \knot_split_self_intersects:NN #1#2
+\cs_new_protected_nopar:Npn \knot_split_self_intersects:N #1
{
- \tl_case:NnF #1
+ \tl_set:Nx \l__knot_tmpc_tl {\tl_item:nn {#1} {4}}
+ \tl_case:NnF \l__knot_tmpc_tl
{
- \g__spath_curvetoa_tl
+ \c_spath_curvetoa_tl
{
- \fp_set:Nn \l_tmpa_fp
+ \fp_set:Nn \l__knot_tmpa_fp
{
- (\tl_item:Nn #2 {3} - 3 * \tl_item:Nn #2 {6} + 3 * \tl_item:Nn #2 {9} - \tl_item:Nn #2 {12})
+ (\tl_item:nn {#1} {3} - 3 * \tl_item:nn {#1} {6} + 3 * \tl_item:nn {#1} {9} - \tl_item:nn {#1} {12})
*
- (3 * \tl_item:Nn #2 {8} - 3 * \tl_item:Nn #2 {11})
+ (3 * \tl_item:nn {#1} {8} - 3 * \tl_item:nn {#1} {11})
-
- (\tl_item:Nn #2 {2} - 3 * \tl_item:Nn #2 {5} + 3 * \tl_item:Nn #2 {8} - \tl_item:Nn #2 {11})
+ (\tl_item:nn {#1} {2} - 3 * \tl_item:nn {#1} {5} + 3 * \tl_item:nn {#1} {8} - \tl_item:nn {#1} {11})
*
- (3 * \tl_item:Nn #2 {9} - 3 * \tl_item:Nn #2 {12})
+ (3 * \tl_item:nn {#1} {9} - 3 * \tl_item:nn {#1} {12})
}
- \fp_set:Nn \l_tmpb_fp
+ \fp_set:Nn \l__knot_tmpb_fp
{
- (\tl_item:Nn #2 {2} - 3 * \tl_item:Nn #2 {5} + 3 * \tl_item:Nn #2 {8} - \tl_item:Nn #2 {11})
+ (\tl_item:nn {#1} {2} - 3 * \tl_item:nn {#1} {5} + 3 * \tl_item:nn {#1} {8} - \tl_item:nn {#1} {11})
*
- (3 * \tl_item:Nn #2 {6} - 6 * \tl_item:Nn #2 {9} + 3 * \tl_item:Nn #2 {12})
+ (3 * \tl_item:nn {#1} {6} - 6 * \tl_item:nn {#1} {9} + 3 * \tl_item:nn {#1} {12})
-
- (\tl_item:Nn #2 {3} - 3 * \tl_item:Nn #2 {6} + 3 * \tl_item:Nn #2 {9} - \tl_item:Nn #2 {12})
+ (\tl_item:nn {#1} {3} - 3 * \tl_item:nn {#1} {6} + 3 * \tl_item:nn {#1} {9} - \tl_item:nn {#1} {12})
*
- (3 * \tl_item:Nn #2 {5} - 6 * \tl_item:Nn #2 {8} + 3 * \tl_item:Nn #2 {11})
+ (3 * \tl_item:nn {#1} {5} - 6 * \tl_item:nn {#1} {8} + 3 * \tl_item:nn {#1} {11})
}
\fp_compare:nTF
{
- \l_tmpb_fp != 0
+ \l__knot_tmpb_fp != 0
}
{
- \fp_set:Nn \l_tmpa_fp {.5 * \l_tmpa_fp / \l_tmpb_fp}
+ \fp_set:Nn \l__knot_tmpa_fp {.5 * \l__knot_tmpa_fp / \l__knot_tmpb_fp}
\fp_compare:nTF
{
- 0 < \l_tmpa_fp && \l_tmpa_fp < 1
+ 0 < \l__knot_tmpa_fp && \l__knot_tmpa_fp < 1
}
{
- \spath_split_curve:VVNN \l_tmpa_fp #2 \l_tmpa_tl \l_tmpb_tl
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl}
- \tl_put_right:NV \l__knot_tmpa_tl \l_tmpa_tl
- \tl_put_right:NV \l__knot_tmpa_tl \l_tmpb_tl
+ \spath_split_curve:NNnV \l__knot_tmpc_tl \l__knot_tmpd_tl {#1} \l__knot_tmpa_fp
+ \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
+ \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
+ \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
+ \tl_set:Nx \l__knot_tmpd_tl {\tl_tail:N \l__knot_tmpd_tl}
+ \tl_set:Nx \l__knot_tmpd_tl {\tl_tail:N \l__knot_tmpd_tl}
+ \tl_set:Nx \l__knot_tmpd_tl {\tl_tail:N \l__knot_tmpd_tl}
+ \tl_put_right:NV \l__knot_tmpa_tl \l__knot_tmpc_tl
+ \tl_put_right:NV \l__knot_tmpa_tl \l__knot_tmpd_tl
}
{
- \tl_set_eq:NN \l_tmpa_tl #2
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_put_right:NV \l__knot_tmpa_tl \l_tmpa_tl
+ \tl_set:Nn \l__knot_tmpc_tl {#1}
+ \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
+ \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
+ \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
+ \tl_put_right:NV \l__knot_tmpa_tl \l__knot_tmpc_tl
}
}
{
- \tl_set_eq:NN \l_tmpa_tl #2
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_put_right:NV \l__knot_tmpa_tl \l_tmpa_tl
+ \tl_set:Nn \l__knot_tmpc_tl {#1}
+ \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
+ \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
+ \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
+ \tl_put_right:NV \l__knot_tmpa_tl \l__knot_tmpc_tl
}
}
- \g__spath_lineto_tl
+ \c_spath_lineto_tl
{
- \tl_set_eq:NN \l_tmpa_tl #2
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl}
- \tl_put_right:NV \l__knot_tmpa_tl \l_tmpa_tl
+ \tl_set:Nn \l__knot_tmpc_tl {#1}
+ \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
+ \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
+ \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
+ \tl_put_right:NV \l__knot_tmpa_tl \l__knot_tmpc_tl
}
}
{
- \tl_put_right:NV \l__knot_tmpa_tl #2
+ \tl_put_right:Nn \l__knot_tmpa_tl {#1}
}
}
\cs_new_protected_nopar:Npn \knot_intersections:nn #1#2
@@ -396,8 +405,8 @@
\tl_put_right:Nn \l__knot_tmpa_tl {#1}
\tl_set_eq:NN \l__knot_tmpb_tl \l__knot_prefix_tl
\tl_put_right:Nn \l__knot_tmpb_tl {#2}
- \spath_get:nnN {knot \tl_use:N \l__knot_tmpa_tl} {path} \l__knot_tmpc_tl
- \spath_get:nnN {knot \tl_use:N \l__knot_tmpb_tl} {path} \l__knot_tmpd_tl
+ \tl_set_eq:Nc \l__knot_tmpc_tl {knot \tl_use:N \l__knot_tmpa_tl}
+ \tl_set_eq:Nc \l__knot_tmpd_tl {knot \tl_use:N \l__knot_tmpb_tl}
\bool_if:nTF {
\l__knot_save_bool
@@ -411,10 +420,12 @@
\pgfintersectionofpaths{\pgfsetpath\l__knot_tmpc_tl}{\pgfsetpath\l__knot_tmpd_tl}
}
+
\int_compare:nT {\pgfintersectionsolutions > 0}
{
\int_step_function:nnnN {1} {1} {\pgfintersectionsolutions} \knot_do_intersection:n
}
+
\knot_save_intersections:VV \l__knot_tmpa_tl \l__knot_tmpb_tl
\group_end:
}
@@ -464,10 +475,10 @@
\bool_set_false:N \l__knot_skip_bool
\bool_if:NT \l__knot_self_intersections_bool
{
- \tl_set:Nn \l_tmpa_tl {knot previous}
- \tl_put_right:NV \l_tmpa_tl \l__knot_tmpa_tl
- \tl_set:Nv \l_tmpa_tl \l_tmpa_tl
- \tl_if_eq:NNT \l_tmpa_tl \l__knot_tmpb_tl
+ \tl_set:Nn \l__knot_tmpc_tl {knot previous}
+ \tl_put_right:NV \l__knot_tmpc_tl \l__knot_tmpa_tl
+ \tl_set:Nv \l__knot_tmpc_tl \l__knot_tmpc_tl
+ \tl_if_eq:NNT \l__knot_tmpc_tl \l__knot_tmpb_tl
{
\knot_test_endpoint:VnT \l__knot_tmpb_tl {final point}
{
@@ -475,10 +486,10 @@
}
}
- \tl_set:Nn \l_tmpa_tl {knot previous}
- \tl_put_right:NV \l_tmpa_tl \l__knot_tmpb_tl
- \tl_set:Nv \l_tmpa_tl \l_tmpa_tl
- \tl_if_eq:NNT \l_tmpa_tl \l__knot_tmpa_tl
+ \tl_set:Nn \l__knot_tmpc_tl {knot previous}
+ \tl_put_right:NV \l__knot_tmpc_tl \l__knot_tmpb_tl
+ \tl_set:Nv \l__knot_tmpc_tl \l__knot_tmpc_tl
+ \tl_if_eq:NNT \l__knot_tmpc_tl \l__knot_tmpa_tl
{
\knot_test_endpoint:VnT \l__knot_tmpa_tl {final point}
{
@@ -508,23 +519,23 @@
\bool_if:NF \l__knot_skip_bool
{
- \int_gincr:N \l__knot_intersections_int
+ \int_gincr:N \g__knot_intersections_int
\bool_if:nF
{
\tl_if_exist_p:c {l__knot_ignore_crossing_ \int_use:N
- \l__knot_intersections_int}
+ \g__knot_intersections_int}
&&
! \tl_if_empty_p:c {l__knot_ignore_crossing_ \int_use:N
- \l__knot_intersections_int}
+ \g__knot_intersections_int}
}
{
\bool_if:nTF
{
\tl_if_exist_p:c {l__knot_crossing_ \int_use:N
- \l__knot_intersections_int}
+ \g__knot_intersections_int}
&&
! \tl_if_empty_p:c {l__knot_crossing_ \int_use:N
- \l__knot_intersections_int}
+ \g__knot_intersections_int}
}
{
\tl_set_eq:NN \l__knot_tmpg_tl \l__knot_tmpb_tl
@@ -553,9 +564,10 @@
\l__knot_prepend_prev_bool || \l__knot_append_next_bool
}
{
- \spath_clone:nn {knot \tl_use:N \l__knot_tmpg_tl}
- {knot \tl_use:N \l__knot_prefix_tl -1}
+ \tl_clear_new:c {knot \tl_use:N \l__knot_prefix_tl -1}
+ \tl_set_eq:cc {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:N \l__knot_tmpg_tl}
+ \tl_clear_new:c {l__knot_options_ \tl_use:N \l__knot_prefix_tl -1}
\tl_set_eq:cc {l__knot_options_ \tl_use:N \l__knot_prefix_tl -1} {l__knot_options_ \tl_use:N \l__knot_tmpg_tl}
\bool_if:nT
@@ -567,7 +579,7 @@
!\tl_if_empty_p:c {knot previous \tl_use:N \l__knot_tmpg_tl}
}
{
- \spath_prepend_no_move:nn {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot previous \tl_use:N \l__knot_tmpg_tl}}
+ \spath_prepend_no_move:cv {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot previous \tl_use:N \l__knot_tmpg_tl}}
\bool_if:nT
{
\l__knot_splits_bool
@@ -579,10 +591,9 @@
{
\knot_test_endpoint:vnT {knot previous \tl_use:N \l__knot_tmpg_tl} {initial point}
{
- \spath_get:nnN {knot \tl_use:N \l__knot_prefix_tl -1} {path} \l_tmpa_tl
- \spath_prepend_no_move:nn {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot previous \tl_use:c {knot previous \tl_use:N \l__knot_tmpg_tl}}}
- \spath_get:nnN {knot \tl_use:N \l__knot_prefix_tl -1} {path} \l_tmpa_tl
+ \spath_prepend_no_move:cv {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot previous \tl_use:c {knot previous \tl_use:N \l__knot_tmpg_tl}}}
+ \tl_set_eq:Nc \l__knot_tmpa_tl {knot \tl_use:N \l__knot_prefix_tl -1}
}
}
}
@@ -595,7 +606,7 @@
!\tl_if_empty_p:c {knot previous \tl_use:N \l__knot_tmpg_tl}
}
{
- \spath_append_no_move:nn {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot next \tl_use:N \l__knot_tmpg_tl}}
+ \spath_append_no_move:cv {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot next \tl_use:N \l__knot_tmpg_tl}}
\bool_if:nT
{
\l__knot_splits_bool
@@ -608,7 +619,7 @@
{
\knot_test_endpoint:vnT {knot previous \tl_use:N \l__knot_tmpg_tl} {final point}
{
- \spath_append_no_move:nn {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot next \tl_use:c {knot next \tl_use:N \l__knot_tmpg_tl}}}
+ \spath_append_no_move:cv {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot next \tl_use:c {knot next \tl_use:N \l__knot_tmpg_tl}}}
}
}
@@ -619,13 +630,16 @@
}
\pgfscope
\group_begin:
- \tikzset{knot~ diagram/every~ intersection/.try, every~ intersection/.try, knot~ diagram/intersection~ \int_use:N \l__knot_intersections_int/.try}
- \knot_draw_crossing:nVV {\tl_use:N \l__knot_tmpg_tl} \l__knot_tmpa_dim \l__knot_tmpb_dim
+ \tikzset{knot~ diagram/every~ intersection/.try, every~ intersection/.try, knot~ diagram/intersection~ \int_use:N \g__knot_intersections_int/.try}
+ \knot_draw_crossing:VVV \l__knot_tmpg_tl \l__knot_tmpa_dim \l__knot_tmpb_dim
+ \coordinate (\l__knot_name_tl \c_space_tl \int_use:N \g__knot_intersections_int) at (\dim_use:N \l__knot_tmpa_dim, \dim_use:N \l__knot_tmpb_dim);
\group_end:
\endpgfscope
}
- \seq_gpush:Nx \l__knot_nodes_seq { \l__knot_node_tl (\l__knot_name_tl \c_space_tl \int_use:N \l__knot_intersections_int) at (\dim_use:N \l__knot_tmpa_dim, \dim_use:N \l__knot_tmpb_dim) {};}
-
+ \tl_if_empty:NF \l__knot_node_tl
+ {
+ \seq_gpush:Nx \g__knot_nodes_seq { \l__knot_node_tl at (\dim_use:N \l__knot_tmpa_dim, \dim_use:N \l__knot_tmpb_dim) {};}
+ }
}
}
@@ -649,7 +663,7 @@
}
\prg_new_protected_conditional:Npnn \knot_test_endpoint:nn #1#2 {T,F,TF}
{
- \spath_get:nnN {knot #1} {#2} \l__knot_tmpd_tl
+ \use:c {spath_#2:Nv} \l__knot_tmpd_tl {knot #1}
\knot_test_endpoint:NTF \l__knot_tmpd_tl
{
\prg_return_true:
@@ -662,19 +676,19 @@
\cs_generate_variant:Nn \knot_test_endpoint:nnT {VnT,vnT}
\cs_generate_variant:Nn \knot_test_endpoint:nnF {VnF,vnF}
\cs_generate_variant:Nn \knot_test_endpoint:nnTF {VnTF,vnTF}
-\cs_new_nopar:Npn \knot_draw_crossing:nnn #1#2#3
+\cs_new_protected_nopar:Npn \knot_draw_crossing:nnn #1#2#3
{
\group_begin:
\pgfscope
\path[knot~ diagram/background~ clip] (#2, #3) circle[radius=\l__knot_clip_bg_radius_dim];
- \tl_set:Nn \l_tmpa_tl {knot~ diagram/every~ strand/.try,}
+ \tl_set:Nn \l__knot_tmpa_tl {knot~ diagram/every~ strand/.try,}
\tl_if_exist:cT {l__knot_options_ #1}
{
- \tl_put_right:Nv \l_tmpa_tl {l__knot_options_ #1}
+ \tl_put_right:Nv \l__knot_tmpa_tl {l__knot_options_ #1}
}
- \tl_put_right:Nn \l_tmpa_tl {,knotbg,line~ width= \tl_use:N \l__knot_clip_width_tl * \pgflinewidth}
- \spath_tikz_path:Vn \l_tmpa_tl {knot #1}
+ \tl_put_right:Nn \l__knot_tmpa_tl {,knotbg,line~ width= \tl_use:N \l__knot_clip_width_tl * \pgflinewidth}
+ \spath_tikz_path:Vv \l__knot_tmpa_tl {knot #1}
\endpgfscope
@@ -681,21 +695,21 @@
\pgfscope
\path[knot~ diagram/clip] (#2, #3) circle[radius=\l__knot_clip_draw_radius_dim];
- \tl_set:Nn \l_tmpa_tl {knot~ diagram/every~ strand/.try,}
+ \tl_set:Nn \l__knot_tmpa_tl {knot~ diagram/every~ strand/.try,}
\tl_if_exist:cT {l__knot_options_ #1}
{
- \tl_put_right:Nv \l_tmpa_tl {l__knot_options_ #1}
+ \tl_put_right:Nv \l__knot_tmpa_tl {l__knot_options_ #1}
}
- \tl_put_right:Nn \l_tmpa_tl {,knot~ diagram/only~ when~ rendering/.try,only~ when~ rendering/.try}
- \spath_tikz_path:Vn \l_tmpa_tl {knot #1}
+ \tl_put_right:Nn \l__knot_tmpa_tl {,knot~ diagram/only~ when~ rendering/.try,only~ when~ rendering/.try}
+ \spath_tikz_path:Vv \l__knot_tmpa_tl {knot #1}
\endpgfscope
\group_end:
}
-\cs_generate_variant:Nn \knot_draw_crossing:nnn {nVV}
+\cs_generate_variant:Nn \knot_draw_crossing:nnn {nVV, VVV}
-\cs_new_nopar:Npn \knot_draw_crossing:nn #1#2
+\cs_new_protected_nopar:Npn \knot_draw_crossing:nn #1#2
{
\tikz at scan@one at point\pgfutil at firstofone #2 \relax
\knot_draw_crossing:nVV {#1} \pgf at x \pgf at y
@@ -702,9 +716,9 @@
}
\cs_new_protected_nopar:Npn \knot_split_strands:
{
- \int_gzero:N \l__knot_filaments_int
+ \int_gzero:N \g__knot_filaments_int
\int_step_function:nnnN {1} {1} {\l__knot_strands_int} \knot_split_strand:n
- \int_step_function:nnnN {1} {1} {\l__knot_filaments_int} \knot_compute_nexts:n
+ \int_step_function:nnnN {1} {1} {\g__knot_filaments_int} \knot_compute_nexts:n
}
\cs_new_protected_nopar:Npn \knot_compute_nexts:n #1
{
@@ -713,66 +727,70 @@
}
\cs_new_protected_nopar:Npn \knot_split_strand:n #1
{
- \int_set_eq:NN \l__knot_component_start_int \l__knot_filaments_int
+ \int_set_eq:NN \l__knot_component_start_int \g__knot_filaments_int
\int_incr:N \l__knot_component_start_int
\tl_set_eq:Nc \l__knot_tmpa_tl {l__knot_options_strand #1}
- \spath_map_segment_function:nN {knot strand #1} \knot_save_filament:NN
+ \spath_segments_to_seq:Nv \l__knot_segments_seq {knot strand #1}
+ \seq_map_function:NN \l__knot_segments_seq \knot_save_filament:N
}
-\cs_new_protected_nopar:Npn \knot_save_filament:NN #1#2
+\cs_new_protected_nopar:Npn \knot_save_filament:N #1
{
- \tl_case:NnF #1
+ \tl_set:Nx \l__knot_tmpb_tl {\tl_item:nn {#1} {4}}
+ \tl_case:NnF \l__knot_tmpb_tl
{
- \g__spath_moveto_tl
+ \c_spath_moveto_tl
{
- \int_compare:nT {\l__knot_component_start_int < \l__knot_filaments_int}
+ \int_compare:nT {\l__knot_component_start_int < \g__knot_filaments_int}
{
- \int_set_eq:NN \l__knot_component_start_int \l__knot_filaments_int
+ \int_set_eq:NN \l__knot_component_start_int \g__knot_filaments_int
}
}
- \g__spath_lineto_tl
+ \c_spath_lineto_tl
{
- \int_gincr:N \l__knot_filaments_int
- \spath_clear_new:n {knot filament \int_use:N \l__knot_filaments_int}
- \spath_put:nnV {knot filament \int_use:N \l__knot_filaments_int} {path} #2
- \tl_set_eq:cN {l__knot_options_filament \int_use:N \l__knot_filaments_int} \l__knot_tmpa_tl
+ \int_gincr:N \g__knot_filaments_int
+ \tl_clear_new:c {knot filament \int_use:N \g__knot_filaments_int}
+ \tl_set:cn {knot filament \int_use:N \g__knot_filaments_int} {#1}
- \tl_clear_new:c {knot previous filament \int_use:N \l__knot_filaments_int}
- \int_compare:nF {\l__knot_component_start_int == \l__knot_filaments_int}
+ \tl_clear_new:c {l__knot_options_filament \int_use:N \g__knot_filaments_int}
+ \tl_set_eq:cN {l__knot_options_filament \int_use:N \g__knot_filaments_int} \l__knot_tmpa_tl
+
+ \tl_clear_new:c {knot previous filament \int_use:N \g__knot_filaments_int}
+ \int_compare:nF {\l__knot_component_start_int == \g__knot_filaments_int}
{
- \tl_set:cx {knot previous filament \int_use:N \l__knot_filaments_int} {filament \int_eval:n {\l__knot_filaments_int - 1}}
+ \tl_set:cx {knot previous filament \int_use:N \g__knot_filaments_int} {filament \int_eval:n {\g__knot_filaments_int - 1}}
}
}
- \g__spath_curvetoa_tl
+ \c_spath_curvetoa_tl
{
- \int_gincr:N \l__knot_filaments_int
- \spath_clear_new:n {knot filament \int_use:N \l__knot_filaments_int}
- \spath_put:nnV {knot filament \int_use:N \l__knot_filaments_int} {path} #2
- \tl_set_eq:cN {l__knot_options_filament \int_use:N \l__knot_filaments_int} \l__knot_tmpa_tl
+ \int_gincr:N \g__knot_filaments_int
+ \tl_clear_new:c {knot filament \int_use:N \g__knot_filaments_int}
+ \tl_set:cn {knot filament \int_use:N \g__knot_filaments_int} {#1}
+ \tl_clear_new:c {l__knot_options_filament \int_use:N \g__knot_filaments_int}
+ \tl_set_eq:cN {l__knot_options_filament \int_use:N \g__knot_filaments_int} \l__knot_tmpa_tl
- \tl_clear_new:c {knot previous filament \int_use:N \l__knot_filaments_int}
- \int_compare:nF {\l__knot_component_start_int == \l__knot_filaments_int}
+ \tl_clear_new:c {knot previous filament \int_use:N \g__knot_filaments_int}
+ \int_compare:nF {\l__knot_component_start_int == \g__knot_filaments_int}
{
- \tl_set:cx {knot previous filament \int_use:N \l__knot_filaments_int} {filament \int_eval:n {\l__knot_filaments_int - 1}}
+ \tl_set:cx {knot previous filament \int_use:N \g__knot_filaments_int} {filament \int_eval:n {\g__knot_filaments_int - 1}}
}
}
- \g__spath_closepath_tl
+ \c_spath_closepath_tl
{
- \tl_show:N #2
- \int_gincr:N \l__knot_filaments_int
- \spath_clear_new:n {knot filament \int_use:N \l__knot_filaments_int}
- \tl_clear:N \l_tmpa_tl
- \tl_put_right:Nx {\tl_item:Nn #2 {1}\tl_item:Nn #2 {2}\tl_item:Nn #2 {3}}
- \tl_put_right:NV \l_tmpa_tl \g__spath_lineto_tl
- \tl_put_right:Nx {\tl_item:Nn #2 {5}\tl_item:Nn #2 {6}}
- \tl_show:N \l_tmpa_tl
- \spath_put:nnV {knot filament \int_use:N \l__knot_filaments_int} {path} \l_tmpa_tl
- \tl_set_eq:cN {l__knot_options_filament \int_use:N \l__knot_filaments_int} \l__knot_tmpa_tl
- \tl_clear_new:c {knot previous filament \int_use:N \l__knot_filaments_int}
- \int_compare:nF {\l__knot_component_start_int == \l__knot_filaments_int}
+ \int_gincr:N \g__knot_filaments_int
+ \tl_clear_new:c {knot filament \int_use:N \g__knot_filaments_int}
+ \tl_clear:N \l__knot_tmpa_tl
+ \tl_put_right:Nx {\tl_item:nn {#1} {1}\tl_item:nn {#1} {2}\tl_item:nn {#1} {3}}
+ \tl_put_right:NV \l__knot_tmpa_tl \c_spath_lineto_tl
+ \tl_put_right:Nx {\tl_item:nn {#1} {5}\tl_item:nn {#1} {6}}
+
+ \tl_set:cV {knot filament \int_use:N \g__knot_filaments_int} \l__knot_tmpa_tl
+ \tl_set_eq:cN {l__knot_options_filament \int_use:N \g__knot_filaments_int} \l__knot_tmpa_tl
+ \tl_clear_new:c {knot previous filament \int_use:N \g__knot_filaments_int}
+ \int_compare:nF {\l__knot_component_start_int == \g__knot_filaments_int}
{
- \tl_set:cx {knot previous filament \int_use:N \l__knot_filaments_int} {filament \int_eval:n {\l__knot_filaments_int - 1}}
+ \tl_set:cx {knot previous filament \int_use:N \g__knot_filaments_int} {filament \int_eval:n {\g__knot_filaments_int - 1}}
}
- \tl_set:cx {knot previous filament \int_use:N \l__knot_component_start_int} {filament \int_use:N \l__knot_filaments_int}
+ \tl_set:cx {knot previous filament \int_use:N \l__knot_component_start_int} {filament \int_use:N \g__knot_filaments_int}
}
}
{
@@ -990,7 +1008,7 @@
}
}
%%
-%% Copyright (C) 2011-2019 by Andrew Stacey <stacey at math.ntnu.no>
+%% Copyright (C) 2011-2019 by Andrew Stacey <loopspace at mathforge.org>
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License (LPPL), either
@@ -1005,13 +1023,16 @@
%% This work consists of the files spath3.dtx
%% calligraphy_doc.tex
%% knots_doc.tex
+%% spath3.tex
%% and the derived files spath3.ins,
%% spath3_code.pdf,
%% spath3.sty,
%% tikzlibrarycalligraphy.code.tex
%% tikzlibraryknots.code.tex
+%% tikzlibraryspath3.code.tex
%% calligraphy.pdf
%% knots.pdf
+%% spath3.pdf
%% README
%%
%%
Added: trunk/Master/texmf-dist/tex/latex/spath3/tikzlibraryspath3.code.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/spath3/tikzlibraryspath3.code.tex (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/spath3/tikzlibraryspath3.code.tex 2021-01-23 22:17:41 UTC (rev 57504)
@@ -0,0 +1,595 @@
+%%
+%% This is file `tikzlibraryspath3.code.tex',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% spath3_code.dtx (with options: `tikzspath3')
+%% ----------------------------------------------------------------
+%% spath3 --- Functions for manipulating PGF soft paths
+%% E-mail: loopspace at mathforge.org
+%% Released under the LaTeX Project Public License v1.3c or later
+%% See http://www.latex-project.org/lppl.txt
+%% ----------------------------------------------------------------
+%%
+\RequirePackage{spath3}
+\RequirePackage{expl3}
+\ExplSyntaxOn
+
+\tl_new:N \l__spath_current_tl
+\tl_new:N \l__spath_reverse_tl
+\tl_new:N \l__spath_prefix_tl
+\tl_new:N \l__spath_suffix_tl
+\tl_new:N \g__spath_smuggle_tl
+\seq_new:N \g__spath_tmpa_seq
+\seq_new:N \g__spath_tmpb_seq
+\bool_new:N \l__spath_draft_bool
+\tl_set:Nn \l__spath_prefix_tl {tikz at intersect@path at name@}
+\tl_set:Nn \l__spath_suffix_tl {}
+\tl_new:N \g__spath_tikzfinish_tl
+\cs_new_protected_nopar:Npn \spath_at_end_of_path:
+{
+ \tl_use:N \g__spath_tikzfinish_tl
+ \tl_gclear:N \g__spath_tikzfinish_tl
+}
+\tl_put_right:Nn \tikz at finish {\spath_at_end_of_path:}
+
+\cs_new_protected_nopar:Npn \spath_save_path:Nn #1#2
+{
+ \tl_gput_right:Nn \g__spath_tikzfinish_tl
+ {
+ \tl_clear_new:N #1
+ \tl_set:Nn #1 {#2}
+ }
+}
+\cs_generate_variant:Nn \spath_save_path:Nn {cn, NV, cV}
+
+\cs_new_protected_nopar:Npn \spath_gsave_path:Nn #1#2
+{
+ \tl_gput_right:Nn \g__spath_tikzfinish_tl
+ {
+ \tl_gclear_new:N #1
+ \tl_gset:Nn #1 {#2}
+ }
+}
+\cs_generate_variant:Nn \spath_gsave_path:Nn {cn, NV, cV}
+\tikzset{
+ spath/.is~family,
+ spath/.cd,
+ set~ prefix/.store~ in=\l__spath_prefix_tl,
+ prefix/.is~choice,
+ prefix/default/.style={
+ /tikz/spath/set~ prefix=tikz at intersect@path at name@
+ },
+ set~ suffix/.store~ in=\l__spath_suffix_tl,
+ suffix/.is~choice,
+ suffix/default/.style={
+ /tikz/spath/set~ suffix={}
+ },
+ set~ name/.style={
+ /tikz/spath/prefix=#1,
+ /tikz/spath/suffix=#1
+ },
+ save/.code={
+ \tikz at addmode{
+ \spath_get_current_path:N \l__spath_tmpa_tl
+ \spath_bake_round:NV \l__spath_tmpa_tl \l__spath_tmpa_tl
+ \spath_save_path:cV {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} \l__spath_tmpa_tl
+ }
+ },
+ clone/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #2 \tl_use:N \l__spath_suffix_tl}
+ {
+ \tl_clear_new:c
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ \tl_set_eq:cc
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {\tl_use:N \l__spath_prefix_tl #2 \tl_use:N \l__spath_suffix_tl}
+ }
+ },
+ clone~ global/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #2 \tl_use:N \l__spath_suffix_tl}
+ {
+ \tl_gclear_new:c
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ \tl_gset_eq:cc
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {\tl_use:N \l__spath_prefix_tl #2 \tl_use:N \l__spath_suffix_tl}
+ }
+ },
+ save~ global/.code={
+ \tikz at addmode{
+ \spath_get_current_path:N \l__spath_tmpa_tl
+ \spath_bake_round:NV \l__spath_tmpa_tl \l__spath_tmpa_tl
+ \spath_gsave_path:cV
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ \l__spath_tmpa_tl
+ }
+ },
+ save~ to~ aux/.code={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_save_to_aux:c
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ }
+ },
+ restore/.code={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_set_current_path:c
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ \spath_set_tikz_coords:v
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ }
+ },
+ show~current~path/.code={
+ \tikz at addmode{
+ \pgfsyssoftpath at getcurrentpath\l__spath_tmpa_tl
+ \iow_term:n {---~ current~ soft~ path~ ---}
+ \spath_show:V \l__spath_tmpa_tl
+ }
+ },
+ show/.code={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \iow_term:n {---~ soft~ path~ #1~ ---}
+ \spath_show:v {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ }
+ },
+ append/.code={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_get_current_path:N \l__spath_current_tl
+ \spath_weld:Nv
+ \l__spath_current_tl
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ \spath_set_current_path:N \l__spath_current_tl
+ \spath_set_tikz_coords:V \l__spath_current_tl
+ }
+ },
+ join~ with/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #2 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_append:cv
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {\tl_use:N \l__spath_prefix_tl #2 \tl_use:N \l__spath_suffix_tl}
+ }
+ }
+ },
+ spot~ weld/.code={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_spot_weld_components:c
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ }
+ },
+ reverse/.code={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_reverse:c
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ }
+ },
+ append~ reverse/.code={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_reverse:Nv
+ \l__spath_reverse_tl
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ \spath_get_current_path:N \l__spath_current_tl
+ \spath_weld:NV \l__spath_current_tl \l__spath_reverse_tl
+ \spath_set_current_path:N \l__spath_current_tl
+ \spath_set_tikz_coords:V \l__spath_current_tl
+ }
+ },
+ insert/.code={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_get_current_path:N \l__spath_current_tl
+ \spath_append:Nv
+ \l__spath_current_tl
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ \spath_set_current_path:N \l__spath_current_tl
+ \spath_set_tikz_coords:V \l__spath_current_tl
+ }
+ },
+ insert~ reverse/.code={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_reverse:Nv
+ \l__spath_reverse_tl
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ \spath_get_current_path:N \l__spath_current_tl
+ \spath_append:NV \l__spath_current_tl \l__spath_reverse_tl
+ \spath_set_current_path:N \l__spath_current_tl
+ \spath_set_tikz_coords:V \l__spath_current_tl
+ }
+ },
+ shorten~ at~ end/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_shorten_at_end:cn
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} {#2}
+ }
+ },
+ shorten~ at~ start/.code~ 2~ args ={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_shorten_at_start:cn
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} {#2}
+ }
+ },
+ shorten~ at~ both~ ends/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_shorten_at_end:cn
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} {#2}
+ \spath_shorten_at_start:cn
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} {#2}
+ }
+ },
+ translate/.code~ n~ args={3}{
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_translate:cnn
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}{#2}{#3}
+ }
+ },
+ export~ to~ svg/.code={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_export_to_svg:c
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ }
+ },
+ transform/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \group_begin:
+ \pgftransformreset
+ \tikzset{#2}
+ \pgfgettransform \l__spath_tmpa_tl
+ \tl_gset:Nn \g__spath_smuggle_tl
+ {
+ \spath_transform:cnnnnnn
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ }
+ \tl_gput_right:NV \g__spath_smuggle_tl \l__spath_tmpa_tl
+ \group_end:
+ \tl_use:N \g__spath_smuggle_tl
+ }
+ },
+ transform~global/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \group_begin:
+ \pgftransformreset
+ \tikzset{#2}
+ \pgfgettransform \l__spath_tmpa_tl
+ \tl_gset:Nn \g__spath_smuggle_tl
+ {
+ \spath_gtransform:cnnnnnn
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ }
+ \tl_gput_right:NV \g__spath_smuggle_tl \l__spath_tmpa_tl
+ \group_end:
+ \tl_use:N \g__spath_smuggle_tl
+ }
+ },
+ split~ at~ intersections/.code~ n~ args={2}{
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #2 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_split_at_intersections:cc
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {\tl_use:N \l__spath_prefix_tl #2 \tl_use:N \l__spath_suffix_tl}
+ }
+ }
+ },
+ split~ at~ self~ intersections/.code={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_split_at_self_intersections:c
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ }
+ },
+ get~ components~ of/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \clist_clear_new:N #2
+ \spath_components_to_seq:Nv
+ \l__spath_tmpa_seq
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ \seq_map_inline:Nn \l__spath_tmpa_seq
+ {
+ \tl_new:c
+ {\tl_use:N \l__spath_prefix_tl anonymous_\int_use:N \g__spath_anon_int \tl_use:N \l__spath_suffix_tl}
+ \tl_set:cn
+ {\tl_use:N \l__spath_prefix_tl anonymous_\int_use:N \g__spath_anon_int \tl_use:N \l__spath_suffix_tl} {##1}
+ \clist_put_right:Nx #2 {anonymous_\int_use:N \g__spath_anon_int}
+ \int_gincr:N \g__spath_anon_int
+ }
+ }
+ },
+ render~ components/.code={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \group_begin:
+ \spath_components_to_seq:Nv
+ \l__spath_tmpa_seq
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ \seq_map_indexed_inline:Nn \l__spath_tmpa_seq
+ {
+ \spath_tikz_path:nn
+ {
+ every~ spath~ component/.try,
+ spath ~component~ ##1/.try,
+ spath ~component/.try={##1},
+ every~ #1~ component/.try,
+ #1 ~component~ ##1/.try,
+ #1 ~component/.try={##1},
+ }
+ {
+ ##2
+ }
+ }
+ \group_end:
+ }
+ },
+ insert~ gaps~ after~ components/.code~ n~ args={3}{
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \group_begin:
+ \seq_gclear:N \g__spath_tmpa_seq
+ \seq_gclear:N \g__spath_tmpb_seq
+ \foreach \l__spath_tmpa_tl in {#3}
+ {
+ \seq_gput_right:NV \g__spath_tmpa_seq \l__spath_tmpa_tl
+ \seq_gput_right:Nx \g__spath_tmpb_seq {\int_eval:n { \l__spath_tmpa_tl + 1 }}
+ }
+ \spath_components_to_seq:Nv
+ \l__spath_tmpa_seq
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ \seq_clear:N \l__spath_tmpb_seq
+ \seq_map_indexed_inline:Nn \l__spath_tmpa_seq
+ {
+ \tl_set:Nn \l__spath_tmpa_tl {##2}
+ \seq_if_in:NnT \g__spath_tmpa_seq {##1}
+ {
+ \spath_shorten_at_end:Nn \l__spath_tmpa_tl {#2/2}
+ }
+ \seq_if_in:NnT \g__spath_tmpb_seq {##1}
+ {
+ \spath_shorten_at_start:Nn \l__spath_tmpa_tl {#2/2}
+ }
+ \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpa_tl
+ }
+ \tl_gset:Nx \g__spath_output_tl {\seq_use:Nn \l__spath_tmpb_seq {} }
+ \group_end:
+ \tl_set_eq:cN
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ \g__spath_output_tl
+ \tl_gclear:N \g__spath_output_tl
+ }
+ },
+ join~ components/.code~ 2~ args={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \seq_gclear:N \g__spath_tmpa_seq
+ \foreach \l__spath_tmpa_tl in {#2}
+ {
+ \seq_gput_right:NV \g__spath_tmpa_seq \l__spath_tmpa_tl
+ }
+ \seq_gsort:Nn \g__spath_tmpa_seq
+ {
+ \int_compare:nNnTF {##1} > {##2}
+ { \sort_return_same: }
+ { \sort_return_swapped: }
+ }
+ \seq_map_inline:Nn \g__spath_tmpa_seq
+ {
+ \spath_join_component:cn
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}{##1}
+ }
+ }
+ },
+ remove~ empty~ components/.code={
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_remove_empty_components:c
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ }
+ },
+ draft~ mode/.is~ choice,
+ draft~ mode/true/.code={
+ \bool_set_true:N \l__spath_draft_bool
+ },
+ draft~ mode/false/.code={
+ \bool_set_false:N \l__spath_draft_bool
+ },
+ maybe~ spot~ weld/.code={
+ \bool_if:NF \l__spath_draft_bool
+ {
+ \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ {
+ \spath_spot_weld_components:c
+ {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}
+ }
+ }
+ },
+ transform~ to/.code~ 2~ args={
+ \group_begin:
+ \tl_if_exist:cTF
+ {
+ \tl_use:N \l__spath_prefix_tl
+ #1
+ \tl_use:N \l__spath_suffix_tl
+ }
+ {
+ \spath_reallength:Nv
+ \l__spath_tmpa_int
+ {
+ \tl_use:N \l__spath_prefix_tl
+ #1
+ \tl_use:N \l__spath_suffix_tl
+ }
+
+ \tl_set:Nx \l__spath_tmpb_tl
+ {\fp_to_decimal:n {(#2) * (\l__spath_tmpa_int)}}
+ \spath_transformation_at:NvV \l__spath_tmpc_tl
+ {
+ \tl_use:N \l__spath_prefix_tl
+ #1
+ \tl_use:N \l__spath_suffix_tl
+ }
+ \l__spath_tmpb_tl
+ \tl_gset_eq:NN \g__spath_smuggle_tl \l__spath_tmpc_tl
+ }
+ {
+ \tl_gset_eq:NN \g__spath_smuggle_tl { {1}{0}{0}{1}{0pt}{0pt} }
+ }
+ \group_end:
+ \exp_last_unbraced:NV \pgfsettransformentries \g__spath_smuggle_tl
+ \tl_gclear:N \g__spath_smuggle_tl
+ },
+ upright~ transform~ to/.code~ 2~ args={
+ \group_begin:
+ \tl_if_exist:cTF
+ {
+ \tl_use:N \l__spath_prefix_tl
+ #1
+ \tl_use:N \l__spath_suffix_tl
+ }
+ {
+ \spath_reallength:Nv
+ \l__spath_tmpa_int
+ {
+ \tl_use:N \l__spath_prefix_tl
+ #1
+ \tl_use:N \l__spath_suffix_tl
+ }
+
+ \tl_set:Nx \l__spath_tmpb_tl
+ {\fp_to_decimal:n {(#2) * (\l__spath_tmpa_int)}}
+ \spath_transformation_at:NvV \l__spath_tmpc_tl
+ {
+ \tl_use:N \l__spath_prefix_tl
+ #1
+ \tl_use:N \l__spath_suffix_tl
+ }
+ \l__spath_tmpb_tl
+ \tl_gset_eq:NN \g__spath_smuggle_tl \l__spath_tmpc_tl
+ }
+ {
+ \tl_gset_eq:NN \g__spath_smuggle_tl { {1}{0}{0}{1}{0pt}{0pt} }
+ }
+ \fp_compare:nT { \tl_item:Nn \g__spath_smuggle_tl {4} < 0}
+ {
+ \tl_gset:Nx \g__spath_smuggle_tl
+ {
+ { \fp_eval:n { - (\tl_item:Nn \g__spath_smuggle_tl {1})} }
+ { \fp_eval:n { - (\tl_item:Nn \g__spath_smuggle_tl {2})} }
+ { \fp_eval:n { - (\tl_item:Nn \g__spath_smuggle_tl {3})} }
+ { \fp_eval:n { - (\tl_item:Nn \g__spath_smuggle_tl {4})} }
+ { \tl_item:Nn \g__spath_smuggle_tl {5} }
+ { \tl_item:Nn \g__spath_smuggle_tl {6} }
+ }
+ }
+ \group_end:
+ \exp_last_unbraced:NV \pgfsettransformentries \g__spath_smuggle_tl
+ \tl_gclear:N \g__spath_smuggle_tl
+ },
+ knot/.style~ n~ args={3}{
+ spath/.cd,
+ split~ at~ self~ intersections=#1,
+ insert~ gaps~ after~ components={#1}{#2}{#3},
+ maybe~ spot~ weld=#1,
+ render~ components=#1
+ },
+}
+\tikzdeclarecoordinatesystem{spath}{%
+ \group_begin:
+ \tl_set:Nn \l__spath_tmpa_tl {#1}
+ \tl_trim_spaces:N \l__spath_tmpa_tl
+
+ \seq_set_split:NnV \l__spath_tmpa_seq {~} \l__spath_tmpa_tl
+ \seq_pop_right:NN \l__spath_tmpa_seq \l__spath_tmpb_tl
+
+ \tl_set:Nx \l__spath_tmpa_tl { \seq_use:Nn \l__spath_tmpa_seq {~} }
+ \tl_if_exist:cTF
+ {
+ \tl_use:N \l__spath_prefix_tl
+ \tl_use:N \l__spath_tmpa_tl
+ \tl_use:N \l__spath_suffix_tl
+ }
+ {
+
+ \tl_set_eq:Nc
+ \l__spath_tmpa_tl
+ {
+ \tl_use:N \l__spath_prefix_tl
+ \tl_use:N \l__spath_tmpa_tl
+ \tl_use:N \l__spath_suffix_tl
+ }
+
+ \tl_if_empty:NTF \l__spath_tmpa_tl
+ {
+ \tl_gset_eq:NN \g__spath_smuggle_tl \pgfpointorigin
+ }
+ {
+ \spath_reallength:NV \l__spath_tmpa_int \l__spath_tmpa_tl
+ \tl_set:Nx \l__spath_tmpb_tl
+ {\fp_to_decimal:n {(\l__spath_tmpb_tl) * (\l__spath_tmpa_int)}}
+ \spath_point_at:NVV \l__spath_tmpc_tl \l__spath_tmpa_tl \l__spath_tmpb_tl
+
+ \tl_clear:N \l__spath_tmpd_tl
+ \tl_put_right:Nn \l__spath_tmpd_tl {\pgf at x=}
+ \tl_put_right:Nx \l__spath_tmpd_tl {\tl_item:Nn \l__spath_tmpc_tl {1}}
+ \tl_put_right:Nn \l__spath_tmpd_tl {\relax}
+ \tl_put_right:Nn \l__spath_tmpd_tl {\pgf at y=}
+ \tl_put_right:Nx \l__spath_tmpd_tl {\tl_item:Nn \l__spath_tmpc_tl {2}}
+ \tl_put_right:Nn \l__spath_tmpd_tl {\relax}
+ \tl_gset_eq:NN \g__spath_smuggle_tl \l__spath_tmpd_tl
+ }
+ }
+ {
+ \tl_gset_eq:NN \g__spath_smuggle_tl \pgfpointorigin
+ }
+ \group_end:
+ \tl_use:N \g__spath_smuggle_tl
+}
+
+\ExplSyntaxOff
+%%
+%% Copyright (C) 2011-2019 by Andrew Stacey <loopspace at mathforge.org>
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License (LPPL), either
+%% version 1.3c of this license or (at your option) any later
+%% version. The latest version of this license is in the file:
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This work is "maintained" (as per LPPL maintenance status) by
+%% Andrew Stacey.
+%%
+%% This work consists of the files spath3.dtx
+%% calligraphy_doc.tex
+%% knots_doc.tex
+%% spath3.tex
+%% and the derived files spath3.ins,
+%% spath3_code.pdf,
+%% spath3.sty,
+%% tikzlibrarycalligraphy.code.tex
+%% tikzlibraryknots.code.tex
+%% tikzlibraryspath3.code.tex
+%% calligraphy.pdf
+%% knots.pdf
+%% spath3.pdf
+%% README
+%%
+%%
+%% End of file `tikzlibraryspath3.code.tex'.
Property changes on: trunk/Master/texmf-dist/tex/latex/spath3/tikzlibraryspath3.code.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
More information about the tex-live-commits
mailing list.