summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/spath3/spath3.tex
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/pgf/contrib/spath3/spath3.tex')
-rw-r--r--graphics/pgf/contrib/spath3/spath3.tex319
1 files changed, 258 insertions, 61 deletions
diff --git a/graphics/pgf/contrib/spath3/spath3.tex b/graphics/pgf/contrib/spath3/spath3.tex
index 86f925ba9e..49b897c481 100644
--- a/graphics/pgf/contrib/spath3/spath3.tex
+++ b/graphics/pgf/contrib/spath3/spath3.tex
@@ -1,5 +1,5 @@
-\RequirePackage{shellesc}
-\immediate\write18{tex spath3_code.dtx}
+%\RequirePackage{shellesc}
+%\immediate\write18{tex spath3_code.dtx}
\documentclass{l3doc}
\usepackage{tikz}
\usetikzlibrary{
@@ -43,6 +43,11 @@
\providecommand*{\url}{\texttt}
\GetFileInfo{spath3.sty}
+\pdfstringdefDisableCommands{%
+ \def\\{}%
+ \def\url#1{<#1>}%
+}
+
\title{The \textsf{spath3} Package: Documentation}
\author{Andrew Stacey \\ \url{loopspace@mathforge.org}}
\date{\fileversion~from \filedate}
@@ -63,13 +68,17 @@
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}.
+ To clarify some terminology used in this document (and more generally, this package), I regard paths as being composed of \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.
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.
+There are no doubt bugs in this package, and useful things that I haven't implemented.
+If you have found one of either of these, please let me know!
+The best way is to open an issue at the code repository on github, at \href{https://github.com/loopspace/spath3}{https://github.com/loopspace/spath3}.
+
\section{TikZ Keys}
@@ -78,19 +87,26 @@ For ease of implementation (and to enable a copperplate pen in the calligraphy p
\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.
+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 (but note that as yet I haven't implemented sending unknown keys back to the main \Verb+tikz+ directory).
+
+The keys try to gracefully fail if the path doesn't exist or is empty.
+The intention is that the document should still compile with a warning in the log file (and on the console output).
+If this doesn't happen, please report it.
+
\subsection{Saving and Using Soft Paths}
-\begin{function}{save}
+\begin{function}{save, save global}
\begin{syntax}
|save=|\meta{name}
+|save global=|\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 |global| version saves the path globally which is useful when the original path is inside a scope or even another tikzpicture.
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.
@@ -98,122 +114,204 @@ One is so that it is compatible with the \texttt{intersections} library -- by de
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{function}{clone, clone globally}
\begin{syntax}
|clone=|\marg{target}\marg{source}
+|clone globally=|\marg{target}\marg{source}
\end{syntax}
Clones one soft path into another.
+In the second, the clone is global (the original need not be).
\end{function}
-\begin{function}{restore}
+\begin{function}{restore, restore reverse}
\begin{syntax}
|restore=|\meta{name}
+|restore reverse=|\meta{name}
\end{syntax}
Restores a previously saved soft path to the current path.
+The \Verb+reverse+ version reverses the soft path first.
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.
+When restoring a path then the library tries to set up various internals of TikZ correctly, but there may be some things I've overlooked or not accounted for particularly with regard to existing transformations; if you spot anything working oddly then please report it to me.
+
+Restoring a path also sets things right for positioning nodes along the path.
+Using the \Verb+pos=D+ key on a node positions that node at a particular point on the path.
+Exactly how the parameter is interpreted is the same as for the \Verb+spath+ coordinate system described in Section~\ref{sec:coordinates}.
\end{function}
-\begin{function}{append}
+\begin{function}{
+ append,
+ append reverse,
+ append no move,
+ append reverse no move
+}
\begin{syntax}
|append=|\meta{name}
+|append reverse=|\meta{name}
+|append no move=|\meta{name}
+|append reverse no move=|\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.
+This inserts a soft path, or its reverse, 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}.
+The path is \emph{welded} on to the current path, meaning that the intervening \Verb+move+ is removed.
This is particularly useful for creating filled regions.
+The first two versions translate the path so that it starts at the last point on the existing path, the second two versions don't do this translation (the intention being that in such a case the translation is omitted because it is \emph{unnecessary} rather than simply not wanted because the effect of removing the intervening move will adjust the initial segment of the appended path otherwise).
+
+As with restoring a path, the last point and node positioning machinery is established.
+The positioning is relative to the appended part of the path, not the full path.
\end{function}
-\begin{function}{reverse}
+\begin{function}{insert, insert reverse}
\begin{syntax}
-|reverse=|\meta{name}
+|insert=|\meta{name}
+|insert 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.
+Like \Verb+append+ except that it doesn't remove the intervening \Verb+move+ and doesn't translate the inserted path.
+The \Verb+reverse+ version reverses the path first.
\end{function}
-\begin{function}{append reverse}
+\begin{function}{to}
\begin{syntax}
-|append reverse=|\meta{name}
+|to=|\marg{name}
\end{syntax}
-Like \texttt{append} except that the inserted path is reversed first.
+This defines a \Verb+to+ path from a soft path, so it inserts the soft path into the current path to span the gap between the start and end.
+The path is transformed by rotation, translation, and uniform scaling so that it exactly spans the gap required by the \Verb+to+ syntax.
+(If the start and end point of the soft path are very close together then it won't span the gap.)
\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}
+\subsection{Transformation Routines}
-\begin{function}{
- shorten at end,
-shorten at start,
-shorten at both ends
-}
+The following keys all apply some sort of transformation to the soft path.
+They do not render the path, but simply adjust it.
+The global versions apply their transformation globally, otherwise it is local to the current group (or scope).
+
+\begin{function}{reverse, reverse global}
\begin{syntax}
-|shorten at end=|\marg{name}\marg{dimen}
+|reverse=|\meta{name}
+|reverse globally=|\meta{name}
\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.
+Reverses the soft path in place.
+If you want to use the original path and its reversal in the same path (for example, for constructing a region to fill) then use the \texttt{clone} key to copy it first.
\end{function}
-\begin{function}{translate}
+
+\begin{function}{translate, translate global}
\begin{syntax}
|translate=|\marg{name}\marg{x-dimen}\marg{y-dimen}
+|translate globally=|\marg{name}\marg{x-dimen}\marg{y-dimen}
\end{syntax}
Translates the soft path by the given dimensions.
\end{function}
-\begin{function}{transform}
+\begin{function}{transform, transform global}
\begin{syntax}
|transform=|\marg{name}\marg{transformations}
+|transform globally=|\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}
+\begin{function}{span, span global}
+\begin{syntax}
+|span=|\marg{name}\marg{start point}\marg{end point}
+|span globally=|\marg{name}\marg{start point}\marg{end point}
+\end{syntax}
+
+This transforms the named path so that it goes from the start point to the end point.
+As with the \Verb+to+ path construction and the \Verb+splice+ method, this won't work if the path ends very close to where it starts.
+\end{function}
+
+\begin{function}{splice, splice global}
+\begin{syntax}
+|splice=|\marg{initial path}\marg{splice path}\marg{final path}
+|splice globally=|\marg{initial path}\marg{splice path}\marg{final path}
+\end{syntax}
+
+This splices the middle path into the gap between the initial and final paths.
+The middle path is transformed to fit (don't try this with a path whose starting and ending points are close together) and the paths are joined so that the last component of the initial path and the first component of the splice path become a single component, and similarly at the other end.
+\end{function}
+
+\begin{function}{join components with, join components globally with}
+\begin{syntax}
+|join components with=|\marg{path}\marg{splice path}
+|join components globally with=|\marg{path}\marg{splice path}
+\end{syntax}
+
+This inserts the |splice path| in the gaps between components of |path|.
+A \emph{spot weld} is performed first to join any components where the end of one is the start of the next.
+The result is a single component path.
+This does \emph{not} close the resulting path, for that see the key |close with|.
+\end{function}
+
+\begin{function}{close, close globally, close with, close globally with}
+\begin{syntax}
+|close=|\marg{path}
+|close globally=|\marg{path}
+|close with=|\marg{path}\marg{splice path}
+|close globally with=|\marg{path}\marg{splice path}
+\end{syntax}
+
+These all close the last component of the given path.
+The first two will insert a line segment if the initial and final points of the component are not sufficiently close.
+The latter two allow you to specify another path to insert.
+\end{function}
+
\subsection{Intersection Routines}
To use these features you need to use the \texttt{intersections} library.
+Note that there is currently an issue with the intersections routine when trying to intersect two parallel (or near parallel) lines.
+One workaround is to replace one of the lines by a B\'ezier curve along the same path.
+The best such replacement is to put the control points at one third and two thirds between the start and end.
-\begin{function}{split at self intersections}
+\begin{function}{
+ split at self intersections,
+ split globally at self intersections
+}
\begin{syntax}
|split at self intersections=|\meta{path}
+|split globally at self intersections=|\meta{path}
\end{syntax}
This inserts breaks into the named soft path at the points where it intersects itself.
+The breaks are not gaps, to achieve that use the shortening routines after this, rather they are a change of component.
+Think of it as if you took the pen off the page at that point and then put it straight back down again.
\end{function}
-\begin{function}{split at intersections}
+\begin{function}{
+ split at intersections with,
+ split globally at intersections with
+}
+\begin{syntax}
+|split at intersections with=|\marg{first}\marg{second}
+|split globally at intersections with=|\marg{first}\marg{second}
+\end{syntax}
+
+This inserts breaks into the first path where it intersects with the second.
+The second path is not changed.
+\end{function}
+
+\begin{function}{
+ split at intersections,
+ split globally at intersections
+}
\begin{syntax}
|split at intersections=|\marg{first}\marg{second}
+|split globally at intersections=|\marg{first}\marg{second}
\end{syntax}
This inserts breaks into a pair of paths at their mutual intersections.
@@ -221,13 +319,26 @@ This inserts breaks into a pair of paths at their mutual intersections.
\subsection{Working with Components}
-\begin{function}{get components of}
+\begin{function}{
+ get components of,
+ get components of globally,
+ \getComponentOf
+}
\begin{syntax}
-|get components of=|\marg{macro}\marg{path}
+|get components of=|\marg{path}\marg{macro}
+|get components of globally=|\marg{path}\marg{macro}
+|\getComponentOf|\marg{macro}\marg{number}
\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|.
+
+The macro consists of a comma separated list of names of the components (the actual names used are of the form \Verb+anonymous_N+).
+To access an individual component, use the command \Verb+\getComponentOf+.
+This can be used directly in place of a path name in any other key, such as \Verb+restore+, (it is just the \LaTeX3 command \Verb+\clist_item:Nn+).
+
+Note that these are \emph{copies} of the components of the original path.
+Changing a component doesn't update the original path.
\end{function}
\begin{function}{render components}
@@ -248,49 +359,87 @@ It applies the following styles (in this order):
\end{enumerate}
\end{function}
-\begin{function}{insert gaps after components}
+\begin{function}{
+ insert gaps after components,
+ insert gaps globally after components
+}
\begin{syntax}
|insert gaps after components=|\marg{path}\marg{gap}\marg{components}
+|insert gaps globally 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|.
+The list of components is passed through a |\foreach| loop so that syntax like |2,4,...,16| can be used.
\end{function}
-\begin{function}{join components}
+\begin{function}{
+ join components,
+ join components globally
+}
\begin{syntax}
|join components=|\marg{path}\marg{components}
+|join components globally=|\marg{path}\marg{components}
\end{syntax}
-This removes the \texttt{move} between the given component and the previous one.
+This removes the |move| between each of the given components and the previous one.
+The list of components is processed by |\foreach|.
If the component is the first one then it is joined to the last component.
\end{function}
-\begin{function}{spot weld}
+\begin{function}{
+ spot weld,
+ spot weld globally
+}
\begin{syntax}
|spot weld=|\meta{path}
+|spot weld globally=|\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{function}{
+ remove empty components,
+ remove empty components globally
+}
\begin{syntax}
|remove empty components=|\meta{path}
+|remove empty components globally=|\meta{path}
\end{syntax}
This removes empty components of the path (which consist of simply a move).
\end{function}
+\begin{function}{
+ remove components,
+ remove components globally
+}
+\begin{syntax}
+|remove components=|\marg{path}\marg{list}
+|remove components globally=|\marg{path}\marg{list}
+\end{syntax}
+
+This removes the listed components of the path.
+As with other list routines, the list is parsed via |foreach| first.
+\end{function}
+
\subsection{Shortening Paths}
\begin{function}{
-shorten path at end,
-shorten path at start,
-shorten path at both ends
+shorten at end,
+shorten at start,
+shorten at both ends,
+shorten globally at end,
+shorten globally at start,
+shorten globally at both ends,
}
\begin{syntax}
-|shorten path at end=|\marg{path}\marg{length}
+|shorten at start=|\marg{path}\marg{length}
+|shorten at end=|\marg{path}\marg{length}
+|shorten at both ends=|\marg{path}\marg{length}
+|shorten globally at start=|\marg{path}\marg{length}
+|shorten globally at end=|\marg{path}\marg{length}
+|shorten globally at both ends=|\marg{path}\marg{length}
\end{syntax}
This shortens a path by the given amount from the specified end.
@@ -298,6 +447,7 @@ The shortening is done so that it guarantees that it lies along the original pat
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.
+If wanting to shorten by a large amount it is better to shorten by a small amount a number of times.
\end{function}
\subsection{Exporting Paths}
@@ -322,9 +472,14 @@ Saves the path to the file \texttt{path.svg} as an SVG document.
\subsection{Knots}
-\begin{function}{knot}
+\begin{function}{
+ global knot,
+ knot,
+ draft mode
+}
\begin{syntax}
|knot=|\meta{path}\meta{gap}\meta{components}
+|global 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.
@@ -340,6 +495,8 @@ knot/.style n args={3}{
}
\end{lstlisting}
+(The \Verb+global+ version makes the path manipulating commands work globally.)
+
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.
@@ -349,8 +506,9 @@ The components can be styled using the keys as described in |render components|.
\end{function}
\subsection{Coordinates}
+\label{sec: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.
+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 (though I've done my best to make that work).
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}
@@ -444,6 +602,45 @@ The intention with the second key is that it is similar to what happens with the
\end{tikzpicture}
\end{example}
+\begin{example}
+\begin{tikzpicture}
+\path[draw=orange,ultra thick,spath/save=a] (3,2) -- ++(1,1) to[out=90,in=-90] ++(3,0);
+
+\tikzset{
+ spath/span={a}{(4,5)}{(7,1)}
+}
+
+\fill
+(4,5) circle[radius=3pt]
+(7,1) circle[radius=3pt]
+;
+
+\draw[spath/restore=a];
+\end{tikzpicture}
+\end{example}
+
+
+\item To paths.
+
+\begin{example}
+\begin{tikzpicture}
+\path[draw=orange,ultra thick,spath/save=a] (3,2) -- ++(1,1) to[out=90,in=-90] ++(3,0);
+
+\draw (0,0) -- +(1,1) to[spath/to={a}] node[pos=.6,auto] {node} ++(2,-1) -- +(3,1);
+\end{tikzpicture}
+\end{example}
+
+\item Node placement.
+
+\begin{example}
+\begin{tikzpicture}
+\path[spath/save=curve] (0,0) to[out=0,in=180] +(1,1);
+
+\draw (0,0) -- (2,0) [spath/append=curve] node[pos=.5,auto,sloped] {node} -- +(2,0);
+
+\end{tikzpicture}
+\end{example}
+
\item Shortening.
\begin{example}