Debian Codegraph @

texmf-dist/source/latex/spath3/spath3_code.dtx

raw
1 % \iffalse meta-comment
2 %<*internal>
3 \iffalse
4 %</internal>
5 %<*readme>
6 ----------------------------------------------------------------
7 spath3 --- LaTeX3 functions for manipulating PGF soft paths
8 E-mail: Andrew Stacey <[email protected]>
9 Released under the LaTeX Project Public License v1.3c or later
10 See http://www.latex-project.org/lppl.txt
11 ----------------------------------------------------------------
12
13 This package defines some functions used to manipulate PGFs soft paths.
14 As applications of its use, included are a package for drawing calligraphic paths and a package for drawing knot diagrams.
15 %</readme>
16 %<*internal>
17 \fi
18 \def\nameofplainTeX{plain}
19 \ifx\fmtname\nameofplainTeX\else
20 \expandafter\begingroup
21 \fi
22 %</internal>
23 %<*install>
24 \input l3docstrip.tex
25 \keepsilent
26 \askforoverwritefalse
27 \preamble
28 ----------------------------------------------------------------
29 spath3 --- Functions for manipulating PGF soft paths
30 E-mail: Andrew Stacey <[email protected]>
31 Released under the LaTeX Project Public License v1.3c or later
32 See http://www.latex-project.org/lppl.txt
33 ----------------------------------------------------------------
34
35 \endpreamble
36 \postamble
37
38 Copyright (C) 2011-2024 by Andrew Stacey <[email protected]>
39
40 This work may be distributed and/or modified under the
41 conditions of the LaTeX Project Public License (LPPL), either
42 version 1.3c of this license or (at your option) any later
43 version. The latest version of this license is in the file:
44
45 http://www.latex-project.org/lppl.txt
46
47 This work is "maintained" (as per LPPL maintenance status) by
48 Andrew Stacey.
49
50 This work consists of the files spath3_code.dtx
51 calligraphy_doc.tex
52 knots_doc.tex
53 spath3.tex
54 and the derived files spath3.ins,
55 spath3_code.pdf,
56 spath3.sty,
57 tikzlibrarycalligraphy.code.tex
58 tikzlibraryknots.code.tex
59 tikzlibraryspath3.code.tex
60 calligraphy.pdf
61 knots.pdf
62 spath3.pdf
63 README.txt
64
65 \endpostamble
66 \usedir{tex/latex/spath3}
67 \generate{
68 \file{spath3.sty}{\from{\jobname.dtx}{spath3}}
69 }
70 \generate{
71 \file{tikzlibrarycalligraphy.code.tex}{\from{\jobname.dtx}{calligraphy}}
72 }
73 \generate{
74 \file{tikzlibraryknots.code.tex}{\from{\jobname.dtx}{knots}}
75 }
76 \generate{
77 \file{tikzlibraryspath3.code.tex}{\from{\jobname.dtx}{tikzspath3}}
78 }
79 %</install>
80 %<install>\endbatchfile
81 %<*internal>
82 \usedir{source/latex/spath3}
83 \generate{
84 \file{\jobname.ins}{\from{\jobname.dtx}{install}}
85 }
86 \nopreamble\nopostamble
87 \usedir{doc/latex/demopkg}
88 \generate{
89 \file{README.txt}{\from{\jobname.dtx}{readme}}
90 }
91 \ifx\fmtname\nameofplainTeX
92 \expandafter\endbatchfile
93 \else
94 \expandafter\endgroup
95 \fi
96 %</internal>
97 %<*driver>
98 \documentclass[full]{l3doc}
99 \usepackage[T1]{fontenc}
100 \usepackage{lmodern}
101 %\usepackage{morefloats}
102 \usepackage{tikz}
103 \usepackage{trace}
104 \usepackage{spath3}
105 %\traceoff
106 %\usepackage[numbered]{hypdoc}
107 \definecolor{lstbgcolor}{rgb}{0.9,0.9,0.9}
108
109 \usepackage{listings}
110 \lstloadlanguages{[LaTeX]TeX}
111 \lstset{
112 breakatwhitespace=true,
113 breaklines=true,
114 language=[LaTeX]TeX,
115 basicstyle=\small\ttfamily,
116 keepspaces=true,
117 columns=fullflexible
118 }
119
120 \usepackage{fancyvrb}
121
122 \newenvironment{example}
123 {\VerbatimEnvironment
124 \begin{VerbatimOut}[gobble=2]{example.out}}
125 {\end{VerbatimOut}
126 \begin{center}
127 % \setlength{\parindent}{0pt}
128 \fbox{\begin{minipage}{.9\linewidth}
129 \lstinputlisting[]{example.out}
130 \end{minipage}}
131 \fbox{\begin{minipage}{.9\linewidth}
132 \centering
133 \input{example.out}
134 \end{minipage}}
135 \end{center}
136 }
137 \EnableCrossrefs
138 \CodelineIndex
139 \RecordChanges
140 \begin{document}
141 \DocInput{\jobname.dtx}
142 \end{document}
143 %</driver>
144 % \fi
145 %
146 % \CheckSum{10278}
147 %
148 % \CharacterTable
149 % {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
150 % 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
151 % Digits \0\1\2\3\4\5\6\7\8\9
152 % Exclamation \! Double quote \" Hash (number) \#
153 % Dollar \$ Percent \% Ampersand \&
154 % Acute accent \' Left paren \( Right paren \)
155 % Asterisk \* Plus \+ Comma \,
156 % Minus \- Point \. Solidus \/
157 % Colon \: Semicolon \; Less than \<
158 % Equals \= Greater than \> Question mark \?
159 % Commercial at \@ Left bracket \[ Backslash \\
160 % Right bracket \] Circumflex \^ Underscore \_
161 % Grave accent \` Left brace \{ Vertical bar \|
162 % Right brace \} Tilde \~}
163 %
164 %
165 % \changes{1.0}{2011/05/03}{Converted to DTX file}
166 % \changes{1.1}{2016/02/19}{Fixes due to changes in LaTeX3}
167 % \changes{1.2}{2019/02/12}{More fixes due to changes in LaTeX3}
168 % \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.}
169 % \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.}
170 % \changes{2.2}{2021/02/05}{Bugfixes and improvements, mainly with regard to the intersection and splitting routines.}
171 % \changes{2.4}{2021/02/21}{Rejigged how the routines for using paths were implemented, added some more routines for joining paths.}
172 % \changes{2.6}{2021/11/23}{Modified core routines to cope with a "true rectangle" path; added routines for splitting at a parametrised point.}
173 % \changes{2.7}{2022/08/24}{Bug fixes}
174 % \changes{2.8}{2024/05/31}{Routine to disable arrow shortening, bug fixes}
175 %
176 % \DoNotIndex{\newcommand,\newenvironment}
177 %
178 % \pdfstringdefDisableCommands{%
179 % \def\\{}%
180 % \def\url#1{<#1>}%
181 % }
182 %
183 % \providecommand*{\url}{\texttt}
184 % \GetFileInfo{spath3.sty}
185 % \title{The \textsf{spath3} package: code}
186 % \author{Andrew Stacey \\ \url{[email protected]}}
187 % \date{\fileversion~from \filedate}
188 %
189 %
190 % \maketitle
191 %
192 %
193 % \section{Introduction}
194 %
195 % The \Verb+spath3+ package is intended as a library for manipulating PGF's \emph{soft paths}.
196 % 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.
197 % 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.
198 % This package provides some methods for working with these paths.
199 % It was originally not really intended for use by end users but as a foundation on which other packages can be built.
200 % 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.
201 %
202 % It also provides the engine that drives a few other packages, such as the \Verb+calligraphy+, \Verb+knot+, and \Verb+tilings+ (formerly, \Verb+penrose+) packages.
203 % The first two of these are subpackages of this one.
204 % The \Verb+calligraphy+ package simulates a calligraphic pen stroking a path.
205 % The \Verb+knots+ package can be used to draw knot (and similar) diagrams.
206 %
207 % For usage, see the documentation of the following packages (\Verb+texdoc <package>+):
208 %
209 % \begin{itemize}
210 % \item \Verb+calligraphy+
211 % \item \Verb+knots+
212 % \item \Verb+tilings+
213 % \item \Verb+spath3+ (\emph{this} document is the code, there's another which focusses on usage)
214 % \end{itemize}
215 %
216 % \section{Technical Details}
217 %
218 % The format of a soft path is a sequence of triples of the form \Verb+\macro {dimension}{dimension}+.
219 % The macro is one of a short list, the dimensions are coordinates in points.
220 % There are certain further restrictions, particularly that every path must begin with a \Verb+move to+, and B\'ezier curves consist of three triples.
221 %
222 % In the original implementation, I wrapped this token list in a \Verb+prop+ to store useful information along with the path.
223 % 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.
224 %
225 % A frequent use of this package is to break a path into pieces and do something with each of those pieces.
226 % To that end, there are various words that I use to describe the levels of the structure of a path.
227 %
228 % At the top level is the path itself.
229 % At the bottom level are the triples of the form \Verb+\macro{dim}{dim}+, as described above.
230 % In between these are the \emph{segments} and \emph{components}.
231 %
232 % A \emph{segment} is a minimal drawing piece.
233 % Thus it might be a straight line or a B\'ezier curve.
234 % 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.
235 %
236 % A \emph{component} is a minimal connected section of the path.
237 % So every component starts with a move command and continues until the next move command.
238 % For ease of implementation (and to enable a copperplate pen in the calligraphy package!), an isolated move is considered as a component.
239 % Thus the following path consists of three components:
240 %
241 % \begin{Verbatim}
242 % \path (0,0) -- (1,0) (2,0) (3,0) to[out=0,in=90] (4,0);
243 % \end{Verbatim}
244 %
245 % \StopEventually{}
246 %
247 % \section{Implementation}
248 %
249 % \iffalse
250 %<*spath3>
251 % \fi
252 % \subsection{Initialisation}
253 %
254 % \begin{macrocode}
255 %<@@=spath>
256 % \end{macrocode}
257 %
258 % Load the \LaTeX3 foundation and register us as a \LaTeX3\ package.
259 % \begin{macrocode}
260 \NeedsTeXFormat{LaTeX2e}
261 \RequirePackage{expl3}
262 \RequirePackage{pgf}
263 \ProvidesExplPackage {spath3} {2024/05/31} {2.8} {Functions for
264 manipulating PGF soft paths}
265 \RequirePackage{xparse}
266 % \end{macrocode}
267 %
268 % Utilities copied from \url{https://github.com/loopspace/LaTeX3-Utilities} for adding something in braces to a token list.
269 % I find I use this quite a lot in my packages.
270 % \begin{macrocode}
271 \cs_new_protected:Nn \@@_tl_put_right_braced:Nn
272 {
273 \tl_put_right:Nn #1 { { #2 } }
274 }
275 \cs_generate_variant:Nn \@@_tl_put_right_braced:Nn { NV, cV, cv, Nx, cx }
276
277 \cs_new_protected:Nn \@@_tl_gput_right_braced:Nn
278 {
279 \tl_gput_right:Nn #1 { { #2 } }
280 }
281 \cs_generate_variant:Nn \@@_tl_gput_right_braced:Nn { NV, cV, cv, Nx, cx }
282 \cs_new_protected:Nn \@@_tl_put_left_braced:Nn
283 {
284 \tl_put_left:Nn #1 { { #2 } }
285 }
286 \cs_generate_variant:Nn \@@_tl_put_left_braced:Nn { NV, cV, cv, Nx, cx }
287
288 \cs_new_protected:Nn \@@_tl_gput_left_braced:Nn
289 {
290 \tl_gput_left:Nn #1 { { #2 } }
291 }
292 \cs_generate_variant:Nn \@@_tl_gput_left_braced:Nn { NV, cV, cv, Nx, cx }
293 % \end{macrocode}
294 %
295 %
296 % I had to think a bit about how to get \TeX\ to work the way I wanted.
297 % I'm really defining \emph{functions} but \TeX\ doesn't really have that concept, even with all the amazing \LaTeX3 stuff.
298 % The main issue I had was with scoping and return values.
299 % By default, \TeX\ functions aren't scoped -- they work on the same level as the calling functions.
300 % To protect the internals from being overwritten, each core function works inside a group.
301 % But then I have to work to get the answer out of it.
302 % So each of my core functions finishes by storing its return value in an appropriate \Verb+output+ variable.
303 % The core functions are then wrapped in a more user friendly interface that will take that output and assign it to a variable.
304 % This also means that I can deal with local and global versions without duplicating code.
305 %
306 % \begin{macrocode}
307 \tl_new:N \g_@@_output_tl
308 \int_new:N \g_@@_output_int
309 \seq_new:N \g_@@_output_seq
310 \bool_new:N \g_@@_output_bool
311 % \end{macrocode}
312 %
313 % To avoid creating vast numbers of variables, we provide ourselves with a few that we reuse frequently.
314 % For that reason, most of them don't have very exciting names.
315 %
316 % These are general purpose variables.
317 % \begin{macrocode}
318 \tl_new:N \l_@@_tmpa_tl
319 \tl_new:N \l_@@_tmpb_tl
320 \tl_new:N \l_@@_tmpc_tl
321 \tl_new:N \l_@@_tmpd_tl
322 \tl_new:N \l_@@_tmpe_tl
323 \tl_new:N \l_@@_tmpf_tl
324 \tl_new:N \l_@@_tmpg_tl
325 \tl_new:N \l_@@_tmph_tl
326 \tl_new:N \l_@@_tmpi_tl
327
328 \seq_new:N \l_@@_tmpa_seq
329 \seq_new:N \l_@@_tmpb_seq
330 \seq_new:N \l_@@_tmpc_seq
331
332 \dim_new:N \l_@@_tmpa_dim
333 \dim_new:N \l_@@_tmpb_dim
334
335 \fp_new:N \l_@@_tmpa_fp
336 \fp_new:N \l_@@_tmpb_fp
337 \fp_new:N \l_@@_tmpc_fp
338 \fp_new:N \l_@@_tmpd_fp
339 \fp_new:N \l_@@_tmpe_fp
340 \fp_new:N \l_@@_tmpf_fp
341
342 \int_new:N \l_@@_tmpa_int
343 \int_new:N \l_@@_tmpb_int
344
345 \bool_new:N \l_@@_tmpa_bool
346 % \end{macrocode}
347 %
348 % Whenever I need more than two \Verb+dim+ variables it is because I need to remember the position of a move.
349 %
350 % \begin{macrocode}
351 \dim_new:N \l_@@_move_x_dim
352 \dim_new:N \l_@@_move_y_dim
353 % \end{macrocode}
354 %
355 % Closed paths often need special handling.
356 % When it's needed, this will say whether the path is closed or not.
357 %
358 % \begin{macrocode}
359 \bool_new:N \l_@@_closed_bool
360 % \end{macrocode}
361 %
362 % True rectangles are rare, but need special handling.
363 % They are specified by two tokens, the first specifies the lower left corner which can be handled pretty much as other tokens but the second specifies the width and height meaning that it transforms differently.
364 % So when encountering on, the coordinates of the lower left corner are useful to remember.
365 %
366 % \begin{macrocode}
367 \dim_new:N \l_@@_rectx_dim
368 \dim_new:N \l_@@_recty_dim
369
370 \bool_new:N \l_@@_rect_bool
371 % \end{macrocode}
372 %
373 % When restoring a path we need to know whether to update the stored moveto.
374 %
375 % \begin{macrocode}
376 \bool_new:N \l_spath_movetorelevant_bool
377 % \end{macrocode}
378 %
379 % When manipulating soft paths, we might need to separate the shortening due to an arrow from when the path is rendered.
380 %
381 % \begin{macrocode}
382 \bool_new:N \l_spath_arrow_shortening_bool
383 \bool_set_true:N \l_spath_arrow_shortening_bool
384 % \end{macrocode}
385 %
386 % The intersection routine can't happen inside a group so we need two token lists to hold the paths that we'll intersect.
387 %
388 % \begin{macrocode}
389 \tl_new:N \l_@@_intersecta_tl
390 \tl_new:N \l_@@_intersectb_tl
391 % \end{macrocode}
392 %
393 % We need to be able to compare against the macros that can occur in a soft path so these token lists contain them.
394 % These are global constants so that they can be used in other packages.
395 % \begin{macrocode}
396 \tl_const:Nn \c_spath_moveto_tl {\pgfsyssoftpath@movetotoken}
397 \tl_const:Nn \c_spath_lineto_tl {\pgfsyssoftpath@linetotoken}
398 \tl_const:Nn \c_spath_curveto_tl {\pgfsyssoftpath@curvetotoken}
399 \tl_const:Nn \c_spath_curvetoa_tl {\pgfsyssoftpath@curvetosupportatoken}
400 \tl_const:Nn \c_spath_curvetob_tl {\pgfsyssoftpath@curvetosupportbtoken}
401 \tl_const:Nn \c_spath_closepath_tl {\pgfsyssoftpath@closepathtoken}
402 \tl_const:Nn \c_spath_rectcorner_tl {\pgfsyssoftpath@rectcornertoken}
403 \tl_const:Nn \c_spath_rectsize_tl {\pgfsyssoftpath@rectsizetoken}
404 % \end{macrocode}
405 %
406 % 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.
407 % \begin{macrocode}
408 \int_new:N \g_@@_anon_int
409 \int_gzero:N \g_@@_anon_int
410 % \end{macrocode}
411 %
412 % \begin{macro}[internal]{
413 % \spath_anonymous:N,
414 % \spath_ganonymous:N
415 % }
416 % Set the token list to the next anonymous name.
417 % \begin{macrocode}
418 \cs_new_protected_nopar:Npn \spath_anonymous:N #1
419 {
420 \tl_set:Nx #1 {anonymous_\int_use:N \g_@@_anon_int}
421 \int_gincr:N \g_@@_anon_int
422 }
423 \cs_new_protected_nopar:Npn \spath_ganonymous:N #1
424 {
425 \tl_gset:Nx #1 {anonymous_\int_use:N \g_@@_anon_int}
426 \int_gincr:N \g_@@_anon_int
427 }
428 \cs_generate_variant:Nn \spath_anonymous:N {c}
429 \cs_generate_variant:Nn \spath_ganonymous:N {c}
430 % \end{macrocode}
431 % \end{macro}
432 %
433 % And some error messages
434 % \begin{macrocode}
435 \msg_new:nnn { spath3 } { unknown path construction }
436 { The~ path~ construction~ element~ #1~ is~ not~ currently~ supported.}
437 % \end{macrocode}
438 %
439 %
440 % \subsection{Functional Implementation}
441 %
442 % 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).
443 % We then store that information, or the manipulated path, in an appropriate macro.
444 % The macro to store it in is the first argument.
445 % These functions occur in two versions, the one with the \texttt{g} makes the assignment global.
446 %
447 % \begin{macro}[internal]{
448 % \spath_segments_to_seq:Nn,
449 % \spath_segments_gto_seq:Nn
450 %}
451 % Splits a soft path into \emph{segments}, storing the result in a sequence.
452 % \begin{macrocode}
453 \cs_new_protected_nopar:Npn \@@_segments_to_seq:n #1
454 {
455 \group_begin:
456 \tl_set:Nn \l_@@_tmpa_tl {#1}
457 \tl_clear:N \l_@@_tmpb_tl
458 \seq_clear:N \l_@@_tmpa_seq
459 \dim_zero:N \l_@@_tmpa_dim
460 \dim_zero:N \l_@@_tmpb_dim
461
462 \bool_until_do:nn {
463 \tl_if_empty_p:N \l_@@_tmpa_tl
464 }
465 {
466 \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
467 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
468 \token_case_meaning:NnF \l_@@_tmpc_tl
469 {
470 \c_spath_moveto_tl
471 {
472 \tl_set_eq:NN \l_@@_tmpb_tl \c_spath_moveto_tl
473 \tl_put_right:Nx \l_@@_tmpb_tl {{\tl_head:N \l_@@_tmpa_tl}}
474 \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
475 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
476
477 \tl_put_right:Nx \l_@@_tmpb_tl {{\tl_head:N \l_@@_tmpa_tl}}
478 \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
479 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
480
481 \tl_set:Nx \l_@@_tmpd_tl {\tl_head:N \l_@@_tmpa_tl}
482 \tl_if_eq:NNF \l_@@_tmpd_tl \c_spath_moveto_tl
483 {
484 \tl_clear:N \l_@@_tmpb_tl
485 }
486
487 }
488
489 \c_spath_lineto_tl
490 {
491 \tl_set_eq:NN \l_@@_tmpb_tl \c_spath_moveto_tl
492 \tl_put_right:Nx \l_@@_tmpb_tl
493 {
494 {\dim_use:N \l_@@_tmpa_dim}
495 {\dim_use:N \l_@@_tmpb_dim}
496 }
497 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_lineto_tl
498
499 \tl_put_right:Nx \l_@@_tmpb_tl {{\tl_head:N \l_@@_tmpa_tl}}
500 \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
501 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
502
503 \tl_put_right:Nx \l_@@_tmpb_tl {{\tl_head:N \l_@@_tmpa_tl}}
504 \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
505 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
506
507 }
508
509 \c_spath_curvetoa_tl
510 {
511 \tl_set_eq:NN \l_@@_tmpb_tl \c_spath_moveto_tl
512 \tl_put_right:Nx \l_@@_tmpb_tl
513 {
514 {\dim_use:N \l_@@_tmpa_dim}
515 {\dim_use:N \l_@@_tmpb_dim}
516 }
517 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetoa_tl
518
519 \prg_replicate:nn {2} {
520 \tl_put_right:Nx \l_@@_tmpb_tl {{\tl_head:N \l_@@_tmpa_tl}}
521 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
522 \tl_put_right:Nx \l_@@_tmpb_tl {{\tl_head:N \l_@@_tmpa_tl}}
523 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
524 \tl_put_right:Nx \l_@@_tmpb_tl {\tl_head:N \l_@@_tmpa_tl}
525 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
526 }
527
528 \tl_put_right:Nx \l_@@_tmpb_tl {{\tl_head:N \l_@@_tmpa_tl}}
529 \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
530 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
531
532 \tl_put_right:Nx \l_@@_tmpb_tl {{\tl_head:N \l_@@_tmpa_tl}}
533 \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
534 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
535
536 }
537
538 \c_spath_rectcorner_tl
539 {
540 \tl_set_eq:NN \l_@@_tmpb_tl \c_spath_rectcorner_tl
541
542 \tl_put_right:Nx \l_@@_tmpb_tl {{\tl_head:N \l_@@_tmpa_tl}}
543 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
544 \tl_put_right:Nx \l_@@_tmpb_tl {{\tl_head:N \l_@@_tmpa_tl}}
545 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
546 \tl_put_right:Nx \l_@@_tmpb_tl {\tl_head:N \l_@@_tmpa_tl}
547 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
548
549 \tl_put_right:Nx \l_@@_tmpb_tl {{\tl_head:N \l_@@_tmpa_tl}}
550 \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
551 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
552
553 \tl_put_right:Nx \l_@@_tmpb_tl {{\tl_head:N \l_@@_tmpa_tl}}
554 \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
555 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
556
557 }
558
559 \c_spath_closepath_tl
560 {
561 \tl_set_eq:NN \l_@@_tmpb_tl \c_spath_moveto_tl
562 \tl_put_right:Nx \l_@@_tmpb_tl
563 {
564 {\dim_use:N \l_@@_tmpa_dim}
565 {\dim_use:N \l_@@_tmpb_dim}
566 }
567 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_lineto_tl
568
569 \tl_put_right:Nx \l_@@_tmpb_tl {{\tl_head:N \l_@@_tmpa_tl}}
570 \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
571 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
572
573 \tl_put_right:Nx \l_@@_tmpb_tl {{\tl_head:N \l_@@_tmpa_tl}}
574 \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
575 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
576
577 }
578
579 }
580 {
581
582 \tl_set_eq:NN \l_@@_tmpb_tl \l_@@_tmpc_tl
583 \tl_put_right:Nx \l_@@_tmpb_tl {{\tl_head:N \l_@@_tmpa_tl}}
584 \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
585 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
586
587 \tl_put_right:Nx \l_@@_tmpb_tl {{\tl_head:N \l_@@_tmpa_tl}}
588 \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
589 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
590
591 }
592
593 \tl_if_empty:NF \l_@@_tmpb_tl
594 {
595 \seq_put_right:NV \l_@@_tmpa_seq \l_@@_tmpb_tl
596 }
597 \tl_clear:N \l_@@_tmpb_tl
598 }
599
600 \seq_gclear:N \g_@@_output_seq
601 \seq_gset_eq:NN \g_@@_output_seq \l_@@_tmpa_seq
602 \group_end:
603 }
604 \cs_new_protected_nopar:Npn \spath_segments_to_seq:Nn #1#2
605 {
606 \@@_segments_to_seq:n {#2}
607 \seq_clear_new:N #1
608 \seq_set_eq:NN #1 \g_@@_output_seq
609 \seq_gclear:N \g_@@_output_seq
610 }
611 \cs_generate_variant:Nn \spath_segments_to_seq:Nn {NV, cn, cV, Nv, cv}
612 \cs_new_protected_nopar:Npn \spath_segments_gto_seq:Nn #1#2
613 {
614 \@@_segments_to_seq:n {#2}
615 \seq_clear_new:N #1
616 \seq_gset_eq:NN #1 \g_@@_output_seq
617 \seq_gclear:N \g_@@_output_seq
618 }
619 \cs_generate_variant:Nn \spath_segments_gto_seq:Nn {NV, cn, cV, Nv, cv}
620 % \end{macrocode}
621 % \end{macro}
622 %
623 % \begin{macro}[internal]{
624 % \spath_components_to_seq:Nn,
625 % \spath_components_gto_seq:Nn,
626 % \spath_components_to_clist:Nn,
627 % \spath_components_gto_clist:Nn,
628 % }
629 % Splits a soft path into \emph{components}, storing the result in a sequence or a clist.
630 % \begin{macrocode}
631 \cs_new_protected_nopar:Npn \@@_components_to_seq:n #1
632 {
633 \group_begin:
634 \tl_set:Nn \l_@@_tmpa_tl {#1}
635 \seq_clear:N \l_@@_tmpa_seq
636 \tl_set:Nx \l_@@_tmpb_tl {\tl_head:N \l_@@_tmpa_tl}
637 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
638
639 \tl_put_right:NV \l_@@_tmpa_tl \c_spath_moveto_tl
640
641 \bool_do_until:nn {
642 \tl_if_empty_p:N \l_@@_tmpa_tl
643 }
644 {
645 \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
646 \tl_if_eq:NNT \l_@@_tmpc_tl \c_spath_moveto_tl
647 {
648 \seq_put_right:NV \l_@@_tmpa_seq \l_@@_tmpb_tl
649 \tl_clear:N \l_@@_tmpb_tl
650 }
651 \tl_if_eq:NNT \l_@@_tmpc_tl \c_spath_rectcorner_tl
652 {
653 \seq_put_right:NV \l_@@_tmpa_seq \l_@@_tmpb_tl
654 \tl_clear:N \l_@@_tmpb_tl
655 }
656 \tl_if_single:NTF \l_@@_tmpc_tl
657 {
658 \tl_put_right:NV \l_@@_tmpb_tl \l_@@_tmpc_tl
659 }
660 {
661 \tl_put_right:Nx \l_@@_tmpb_tl {{\l_@@_tmpc_tl}}
662 }
663 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
664 }
665
666 \seq_gclear:N \g_@@_output_seq
667 \seq_gset_eq:NN \g_@@_output_seq \l_@@_tmpa_seq
668 \group_end:
669 }
670 \cs_new_protected_nopar:Npn \spath_components_to_seq:Nn #1#2
671 {
672 \@@_components_to_seq:n {#2}
673 \seq_clear_new:N #1
674 \seq_set_eq:NN #1 \g_@@_output_seq
675 \seq_gclear:N \g_@@_output_seq
676 }
677 \cs_generate_variant:Nn \spath_components_to_seq:Nn {NV, cn, cV, cv, Nv}
678 \cs_new_protected_nopar:Npn \spath_components_gto_seq:Nn #1#2
679 {
680 \@@_components_to_seq:n {#2}
681 \seq_clear_new:N #1
682 \seq_gset_eq:NN #1 \g_@@_output_seq
683 \seq_gclear:N \g_@@_output_seq
684 }
685 \cs_generate_variant:Nn \spath_components_gto_seq:Nn {NV, cn, cV, cv, Nv}
686 \cs_new_protected_nopar:Npn \spath_components_to_clist:Nn #1#2
687 {
688 \@@_components_to_seq:n {#2}
689 \clist_clear_new:N #1
690 \clist_set_from_seq:NN #1 \g_@@_output_seq
691 \seq_gclear:N \g_@@_output_seq
692 }
693 \cs_generate_variant:Nn \spath_components_to_clist:Nn {NV, cn, cV, cv, Nv}
694 \cs_new_protected_nopar:Npn \spath_components_gto_clist:Nn #1#2
695 {
696 \@@_components_to_seq:n {#2}
697 \clist_clear_new:N #1
698 \clist_gset_from_seq:NN #1 \g_@@_output_seq
699 \seq_gclear:N \g_@@_output_seq
700 }
701 \cs_generate_variant:Nn \spath_components_gto_clist:Nn {NV, cn, cV, cv, Nv}
702 % \end{macrocode}
703 % \end{macro}
704 %
705 %
706 % \begin{macro}[internal]{\spath_length:n}
707 % Counts the number of triples in the path.
708 % \begin{macrocode}
709 \cs_new_protected_nopar:Npn \spath_length:n #1
710 {
711 \int_eval:n {\tl_count:n {#1} / 3}
712 }
713 \cs_generate_variant:Nn \spath_length:n {V}
714 % \end{macrocode}
715 % \end{macro}
716 %
717 % \begin{macro}[internal]{
718 % \spath_reallength:Nn,
719 % \spath_greallength:Nn
720 % }
721 % The real length of a path is the number of triples that actually draw something (that is, the number of lines, curves, rectangles, and closepaths).
722 % \begin{macrocode}
723 \cs_new_protected_nopar:Npn \@@_reallength:n #1
724 {
725 \group_begin:
726 \int_set:Nn \l_@@_tmpa_int {0}
727 \tl_map_inline:nn {#1} {
728 \tl_set:Nn \l_@@_tmpa_tl {##1}
729 \token_case_meaning:NnT \l_@@_tmpa_tl
730 {
731 \c_spath_lineto_tl {}
732 \c_spath_curveto_tl {}
733 \c_spath_closepath_tl {}
734 \c_spath_rectsize_tl {}
735 }
736 {
737 \int_incr:N \l_@@_tmpa_int
738 }
739 }
740 \int_gzero:N \g_@@_output_int
741 \int_gset_eq:NN \g_@@_output_int \l_@@_tmpa_int
742 \group_end:
743 }
744 \cs_new_protected_nopar:Npn \spath_reallength:Nn #1#2
745 {
746 \@@_reallength:n {#2}
747 \int_set_eq:NN #1 \g_@@_output_int
748 \int_gzero:N \g_@@_output_int
749 }
750 \cs_generate_variant:Nn \spath_reallength:Nn {NV, cn, cV, Nv, cv}
751 \cs_new_protected_nopar:Npn \spath_greallength:Nn #1#2
752 {
753 \@@_reallength:n {#2}
754 \int_gset_eq:NN #1 \g_@@_output_int
755 \int_gzero:N \g_@@_output_int
756 }
757 \cs_generate_variant:Nn \spath_greallength:Nn {NV, cn, cV}
758 % \end{macrocode}
759 % \end{macro}
760 %
761 % \begin{macro}[internal]{
762 % \spath_numberofcomponents:Nn,
763 % \spath_gnumberofcomponents:Nn
764 % }
765 % A component is a continuous segment of the path, separated by moves.
766 % Successive moves are not collapsed, and zero length moves count.
767 % \begin{macrocode}
768 \cs_new_protected_nopar:Npn \@@_numberofcomponents:n #1
769 {
770 \group_begin:
771 \int_set:Nn \l_@@_tmpa_int {0}
772 \tl_map_inline:nn {#1} {
773 \tl_set:Nn \l_@@_tmpa_tl {##1}
774 \token_case_meaning:Nn \l_@@_tmpa_tl
775 {
776 \c_spath_moveto_tl
777 {
778 \int_incr:N \l_@@_tmpa_int
779 }
780 \c_spath_rectcorner_tl
781 {
782 \int_incr:N \l_@@_tmpa_int
783 }
784 }
785 }
786 \int_gzero:N \g_@@_output_int
787 \int_gset_eq:NN \g_@@_output_int \l_@@_tmpa_int
788 \group_end:
789 }
790 \cs_new_protected_nopar:Npn \spath_numberofcomponents:Nn #1#2
791 {
792 \@@_numberofcomponents:n {#2}
793 \int_set_eq:NN #1 \g_@@_output_int
794 \int_gzero:N \g_@@_output_int
795 }
796 \cs_generate_variant:Nn \spath_numberofcomponents:Nn {NV, cn, cV, Nv}
797 \cs_new_protected_nopar:Npn \spath_gnumberofcomponents:Nn #1#2
798 {
799 \@@_numberofcomponents:n {#2}
800 \int_gset_eq:NN #1 \g_@@_output_int
801 \int_gzero:N \g_@@_output_int
802 }
803 \cs_generate_variant:Nn \spath_gnumberofcomponents:Nn {NV, cn, cV, Nv}
804 % \end{macrocode}
805 % \end{macro}
806 %
807 % \begin{macro}[internal]{
808 % \spath_initialpoint:Nn,
809 % \spath_ginitialpoint:Nn
810 % }
811 % The starting point of the path.
812 % \begin{macrocode}
813 \cs_new_protected_nopar:Npn \@@_initialpoint:n #1
814 {
815 \group_begin:
816 \tl_clear:N \l_@@_tmpa_tl
817 \tl_set:Nx \l_@@_tmpa_tl
818 {
819 { \tl_item:nn {#1} {2} }
820 { \tl_item:nn {#1} {3} }
821 }
822 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
823 \group_end:
824 }
825 \cs_new_protected_nopar:Npn \spath_initialpoint:Nn #1#2
826 {
827 \@@_initialpoint:n {#2}
828 \tl_set_eq:NN #1 \g_@@_output_tl
829 \tl_gclear:N \g_@@_output_tl
830 }
831 \cs_generate_variant:Nn \spath_initialpoint:Nn {NV, cn, cV, Nv}
832 \cs_new_protected_nopar:Npn \spath_ginitialpoint:Nn #1#2
833 {
834 \@@_initialpoint:n {#2}
835 \tl_gset_eq:NN #1 \g_@@_output_tl
836 \tl_gclear:N \g_@@_output_tl
837 }
838 \cs_generate_variant:Nn \spath_ginitialpoint:Nn {NV, cn, cV, Nv}
839 % \end{macrocode}
840 % \end{macro}
841 %
842 % \begin{macro}[internal]{
843 % \spath_finalpoint:Nn,
844 % \spath_gfinalpoint:Nn,
845 % }
846 % The final point of the path.
847 % \begin{macrocode}
848 \cs_new_protected_nopar:Npn \@@_finalpoint:n #1
849 {
850 \group_begin:
851 \tl_set:Nn \l_@@_tmpa_tl {#1}
852 \tl_reverse:N \l_@@_tmpa_tl
853 \tl_clear:N \l_@@_tmpb_tl
854 \tl_set:Nx \l_@@_tmpc_tl {\tl_item:Nn \l_@@_tmpa_tl {3}}
855 \tl_if_eq:NNTF \l_@@_tmpc_tl \c_spath_rectsize_tl
856 {
857 \tl_set:Nx \l_@@_tmpb_tl
858 {
859 {
860 \dim_eval:n
861 {
862 \tl_item:Nn \l_@@_tmpa_tl {2}
863 +
864 \tl_item:Nn \l_@@_tmpa_tl {5}
865 }
866 }
867 {
868 \dim_eval:n
869 {
870 \tl_item:Nn \l_@@_tmpa_tl {1}
871 +
872 \tl_item:Nn \l_@@_tmpa_tl {4}
873 }
874 }
875 }
876 }
877 {
878 \tl_set:Nx \l_@@_tmpb_tl
879 {
880 { \tl_item:Nn \l_@@_tmpa_tl {2} }
881 { \tl_item:Nn \l_@@_tmpa_tl {1} }
882 }
883 }
884 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
885 \group_end:
886 }
887 \cs_new_protected_nopar:Npn \spath_finalpoint:Nn #1#2
888 {
889 \@@_finalpoint:n {#2}
890 \tl_set_eq:NN #1 \g_@@_output_tl
891 \tl_gclear:N \g_@@_output_tl
892 }
893 \cs_generate_variant:Nn \spath_finalpoint:Nn {NV, cn, cV, Nv}
894 \cs_new_protected_nopar:Npn \spath_gfinalpoint:Nn #1#2
895 {
896 \@@_finalpoint:n {#2}
897 \tl_gset_eq:NN #1 \g_@@_output_tl
898 \tl_gclear:N \g_@@_output_tl
899 }
900 \cs_generate_variant:Nn \spath_gfinalpoint:Nn {NV, cn, cV, Nv}
901 % \end{macrocode}
902 % \end{macro}
903 %
904 % \begin{macro}[internal]{
905 % \spath_finalmovepoint:Nn,
906 % \spath_gfinalmovepoint:Nn
907 % }
908 % Get the last move on the path.
909 % \begin{macrocode}
910 \cs_new_protected_nopar:Npn \@@_finalmovepoint:n #1
911 {
912 \group_begin:
913 \tl_set:Nn \l_@@_tmpc_tl { {0pt} {0pt} }
914 \tl_set:Nn \l_@@_tmpa_tl {#1}
915 \bool_do_until:nn
916 {
917 \tl_if_empty_p:N \l_@@_tmpa_tl
918 }
919 {
920 \tl_set:Nx \l_@@_tmpb_tl {\tl_head:N \l_@@_tmpa_tl}
921 \token_case_meaning:Nn \l_@@_tmpb_tl
922 {
923 \c_spath_moveto_tl
924 {
925 \tl_set:Nx \l_@@_tmpc_tl
926 {
927 { \tl_item:Nn \l_@@_tmpa_tl {2} }
928 { \tl_item:Nn \l_@@_tmpa_tl {3} }
929 }
930 }
931
932 \c_spath_rectcorner_tl
933 {
934 \tl_set:Nx \l_@@_tmpc_tl
935 {
936 { \tl_item:Nn \l_@@_tmpa_tl {2} }
937 { \tl_item:Nn \l_@@_tmpa_tl {3} }
938 }
939 }
940
941 }
942 \prg_replicate:nn {3}
943 {
944 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
945 }
946 }
947 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpc_tl
948 \group_end:
949 }
950 \cs_new_protected_nopar:Npn \spath_finalmovepoint:Nn #1#2
951 {
952 \@@_finalmovepoint:n {#2}
953 \tl_set_eq:NN #1 \g_@@_output_tl
954 \tl_gclear:N \g_@@_output_tl
955 }
956 \cs_generate_variant:Nn \spath_finalmovepoint:Nn {NV, cn, cV}
957 \cs_new_protected_nopar:Npn \spath_gfinalmovepoint:Nn #1#2
958 {
959 \@@_finalmovepoint:n {#2}
960 \tl_gset_eq:NN #1 \g_@@_output_tl
961 \tl_gclear:N \g_@@_output_tl
962 }
963 \cs_generate_variant:Nn \spath_gfinalmovepoint:Nn {NV, cn, cV}
964 % \end{macrocode}
965 % \end{macro}
966 %
967 % \begin{macro}[internal]{
968 % \spath_initialtangent:Nn,
969 % \spath_ginitialtangent:Nn
970 % }
971 % The starting tangent of the path.
972 % \begin{macrocode}
973 \cs_new_protected_nopar:Npn \@@_initialtangent:n #1
974 {
975 \group_begin:
976 \tl_set:Nx \l_@@_tmpb_tl {\tl_item:nn {#1} {4}}
977 \tl_if_eq:NNTF \l_@@_tmpb_tl \c_spath_curvetoa_tl
978 {
979 \fp_set:Nn \l_@@_tmpa_fp {3}
980 }
981 {
982 \fp_set:Nn \l_@@_tmpa_fp {1}
983 }
984 \tl_clear:N \l_@@_tmpa_tl
985 \tl_set:Nx \l_@@_tmpa_tl
986 {
987 {
988 \fp_to_dim:n {
989 \l_@@_tmpa_fp
990 *
991 (
992 \tl_item:nn {#1} {5}
993 -
994 \tl_item:nn {#1} {2}
995 )
996 }
997 }
998 {
999 \fp_to_dim:n {
1000 \l_@@_tmpa_fp
1001 *
1002 (
1003 \tl_item:nn {#1} {6}
1004 -
1005 \tl_item:nn {#1} {3}
1006 )
1007 }
1008 }
1009 }
1010 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
1011 \group_end:
1012 }
1013 \cs_new_protected_nopar:Npn \spath_initialtangent:Nn #1#2
1014 {
1015 \@@_initialtangent:n {#2}
1016 \tl_set_eq:NN #1 \g_@@_output_tl
1017 \tl_gclear:N \g_@@_output_tl
1018 }
1019 \cs_generate_variant:Nn \spath_initialtangent:Nn {NV, cn, cV, Nv}
1020 \cs_new_protected_nopar:Npn \spath_ginitialtangent:Nn #1#2
1021 {
1022 \@@_initialtangent:n {#2}
1023 \tl_gset_eq:NN #1 \g_@@_output_tl
1024 \tl_gclear:N \g_@@_output_tl
1025 }
1026 \cs_generate_variant:Nn \spath_ginitialtangent:Nn {NV, cn, cV, Nv}
1027 % \end{macrocode}
1028 % \end{macro}
1029 %
1030 % \begin{macro}[internal]{
1031 % \spath_finaltangent:Nn,
1032 % \spath_gfinaltangent:Nn,
1033 % }
1034 % The final tangent of the path.
1035 % \begin{macrocode}
1036 \cs_new_protected_nopar:Npn \@@_finaltangent:n #1
1037 {
1038 \group_begin:
1039 \tl_set:Nn \l_@@_tmpa_tl {#1}
1040 \tl_reverse:N \l_@@_tmpa_tl
1041 \tl_set:Nx \l_@@_tmpb_tl {\tl_item:nn {#1} {6}}
1042 \tl_if_eq:NNTF \l_@@_tmpb_tl \c_spath_curveto_tl
1043 {
1044 \fp_set:Nn \l_@@_tmpa_fp {3}
1045 }
1046 {
1047 \fp_set:Nn \l_@@_tmpa_fp {1}
1048 }
1049 \tl_clear:N \l_@@_tmpb_tl
1050 \tl_set:Nx \l_@@_tmpb_tl
1051 {
1052 {
1053 \fp_to_dim:n {
1054 \l_@@_tmpa_fp
1055 *
1056 (
1057 \tl_item:Nn \l_@@_tmpa_tl {2}
1058 -
1059 \tl_item:Nn \l_@@_tmpa_tl {5}
1060 )
1061 }
1062 }
1063 {
1064 \fp_to_dim:n {
1065 \l_@@_tmpa_fp
1066 *
1067 (
1068 \tl_item:Nn \l_@@_tmpa_tl {1}
1069 -
1070 \tl_item:Nn \l_@@_tmpa_tl {4}
1071 )
1072 }
1073 }
1074 }
1075 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
1076 \group_end:
1077 }
1078 \cs_new_protected_nopar:Npn \spath_finaltangent:Nn #1#2
1079 {
1080 \@@_finaltangent:n {#2}
1081 \tl_set_eq:NN #1 \g_@@_output_tl
1082 \tl_gclear:N \g_@@_output_tl
1083 }
1084 \cs_generate_variant:Nn \spath_finaltangent:Nn {NV, cn, cV, Nv}
1085 \cs_new_protected_nopar:Npn \spath_gfinaltangent:Nn #1#2
1086 {
1087 \@@_finaltangent:n {#2}
1088 \tl_gset_eq:NN #1 \g_@@_output_tl
1089 \tl_gclear:N \g_@@_output_tl
1090 }
1091 \cs_generate_variant:Nn \spath_gfinaltangent:Nn {NV, cn, cV, Nv}
1092 % \end{macrocode}
1093 % \end{macro}
1094 %
1095 %
1096 % \begin{macro}[internal]{
1097 % \spath_finalmovetangent:Nn,
1098 % \spath_gfinalmovetangent:Nn
1099 % }
1100 % Get the last move on the path.
1101 % \begin{macrocode}
1102 \cs_new_protected_nopar:Npn \@@_finalmovetangent:n #1
1103 {
1104 \group_begin:
1105 \tl_set:Nn \l_@@_tmpc_tl { {0pt} {0pt} }
1106 \tl_set:Nn \l_@@_tmpa_tl {#1}
1107 \bool_do_until:nn
1108 {
1109 \tl_if_empty_p:N \l_@@_tmpa_tl
1110 }
1111 {
1112 \tl_set:Nx \l_@@_tmpb_tl {\tl_head:N \l_@@_tmpa_tl}
1113 \token_case_meaning:Nn \l_@@_tmpb_tl
1114 {
1115 \c_spath_moveto_tl
1116 {
1117 \tl_set:Nx \l_@@_tmpd_tl { \tl_item:Nn \l_@@_tmpa_tl {4} }
1118 \tl_if_eq:NNTF \l_@@_tmpd_tl \c_spath_curveto_tl
1119 {
1120 \fp_set:Nn \l_@@_tmpa_fp {3}
1121 }
1122 {
1123 \fp_set:Nn \l_@@_tmpa_fp {1}
1124 }
1125 \tl_set:Nx \l_@@_tmpc_tl
1126 {
1127 {
1128 \fp_to_dim:n
1129 {
1130 \l_@@_tmpa_fp
1131 *
1132 (
1133 \tl_item:Nn \l_@@_tmpa_tl {5}
1134 -
1135 \tl_item:Nn \l_@@_tmpa_tl {2}
1136 )
1137 }
1138 }
1139 {
1140 \fp_to_dim:n
1141 {
1142 \l_@@_tmpa_fp
1143 *
1144 (
1145 \tl_item:Nn \l_@@_tmpa_tl {6}
1146 -
1147 \tl_item:Nn \l_@@_tmpa_tl {3}
1148 )
1149 }
1150 }
1151 }
1152 }
1153 }
1154 \prg_replicate:nn {3}
1155 {
1156 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1157 }
1158 }
1159 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpc_tl
1160 \group_end:
1161 }
1162 \cs_new_protected_nopar:Npn \spath_finalmovetangent:Nn #1#2
1163 {
1164 \@@_finalmovetangent:n {#2}
1165 \tl_set_eq:NN #1 \g_@@_output_tl
1166 \tl_gclear:N \g_@@_output_tl
1167 }
1168 \cs_generate_variant:Nn \spath_finalmovetangent:Nn {NV, cn, cV}
1169 \cs_new_protected_nopar:Npn \spath_gfinalmovetangent:Nn #1#2
1170 {
1171 \@@_finalmovetangent:n {#2}
1172 \tl_gset_eq:NN #1 \g_@@_output_tl
1173 \tl_gclear:N \g_@@_output_tl
1174 }
1175 \cs_generate_variant:Nn \spath_gfinalmovetangent:Nn {NV, cn, cV}
1176 % \end{macrocode}
1177 % \end{macro}
1178 %
1179 % \begin{macro}[internal]{
1180 % \spath_reverse:Nn,
1181 % \spath_greverse:Nn
1182 % }
1183 % This computes the reverse of the path.
1184 % \begin{macrocode}
1185 \cs_new_protected_nopar:Npn \@@_reverse:n #1
1186 {
1187 \group_begin:
1188 \tl_set:Nn \l_@@_tmpa_tl {#1}
1189
1190 \tl_clear:N \l_@@_tmpb_tl
1191 \tl_clear:N \l_@@_tmpd_tl
1192
1193 \bool_set_false:N \l_@@_rect_bool
1194
1195 \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
1196 \bool_while_do:nn {
1197 \tl_if_eq_p:NN \l_@@_tmpc_tl \c_spath_rectcorner_tl
1198 }
1199 {
1200 \tl_put_left:Nx \l_@@_tmpd_tl
1201 {
1202 \tl_item:Nn \l_@@_tmpa_tl {1}
1203 {\tl_item:Nn \l_@@_tmpa_tl {2}}
1204 {\tl_item:Nn \l_@@_tmpa_tl {3}}
1205 \tl_item:Nn \l_@@_tmpa_tl {4}
1206 {\tl_item:Nn \l_@@_tmpa_tl {5}}
1207 {\tl_item:Nn \l_@@_tmpa_tl {6}}
1208 }
1209 \prg_replicate:nn {6}
1210 {
1211 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1212 }
1213 \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
1214 \bool_set_true:N \l_@@_rect_bool
1215 }
1216
1217 \tl_if_empty:NF \l_@@_tmpa_tl
1218 {
1219 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1220 \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
1221 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1222 \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
1223 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1224
1225 \tl_put_left:Nx \l_@@_tmpd_tl
1226 {
1227 {\dim_use:N \l_@@_tmpa_dim}
1228 {\dim_use:N \l_@@_tmpb_dim}
1229 }
1230
1231 \bool_set_false:N \l_@@_closed_bool
1232
1233 \bool_until_do:nn {
1234 \tl_if_empty_p:N \l_@@_tmpa_tl
1235 }
1236 {
1237 \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
1238 \bool_set_false:N \l_@@_rect_bool
1239
1240 \token_case_meaning:NnTF \l_@@_tmpc_tl
1241 {
1242 \c_spath_moveto_tl {
1243
1244 \bool_if:NT \l_@@_closed_bool
1245 {
1246 \tl_put_right:NV \l_@@_tmpd_tl \c_spath_closepath_tl
1247 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpd_tl}
1248 \tl_put_right:Nx \l_@@_tmpd_tl
1249 {
1250 { \tl_head:N \l_@@_tmpd_tl }
1251 { \tl_head:N \l_@@_tmpe_tl }
1252 }
1253 }
1254 \bool_set_false:N \l_@@_closed_bool
1255 \tl_put_left:NV \l_@@_tmpd_tl \c_spath_moveto_tl
1256 \tl_put_left:NV \l_@@_tmpb_tl \l_@@_tmpd_tl
1257 \tl_clear:N \l_@@_tmpd_tl
1258 }
1259 \c_spath_rectcorner_tl {
1260
1261 \bool_if:NT \l_@@_closed_bool
1262 {
1263 \tl_put_right:NV \l_@@_tmpd_tl \c_spath_closepath_tl
1264 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpd_tl}
1265 \tl_put_right:Nx \l_@@_tmpd_tl
1266 {
1267 { \tl_head:N \l_@@_tmpd_tl }
1268 { \tl_head:N \l_@@_tmpe_tl }
1269 }
1270 }
1271 \bool_set_false:N \l_@@_closed_bool
1272 \tl_put_left:NV \l_@@_tmpd_tl \c_spath_moveto_tl
1273 \tl_put_left:NV \l_@@_tmpb_tl \l_@@_tmpd_tl
1274 \tl_clear:N \l_@@_tmpd_tl
1275
1276 \bool_while_do:nn {
1277 \tl_if_eq_p:NN \l_@@_tmpc_tl \c_spath_rectcorner_tl
1278 }
1279 {
1280 \tl_put_left:Nx \l_@@_tmpb_tl
1281 {
1282 \tl_item:Nn \l_@@_tmpa_tl {1}
1283 {\tl_item:Nn \l_@@_tmpa_tl {2}}
1284 {\tl_item:Nn \l_@@_tmpa_tl {3}}
1285 \tl_item:Nn \l_@@_tmpa_tl {4}
1286 {\tl_item:Nn \l_@@_tmpa_tl {5}}
1287 {\tl_item:Nn \l_@@_tmpa_tl {6}}
1288 }
1289 \prg_replicate:nn {6}
1290 {
1291 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1292 }
1293 \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
1294 }
1295 \bool_set_true:N \l_@@_rect_bool
1296
1297 }
1298 \c_spath_lineto_tl {
1299 \tl_put_left:NV \l_@@_tmpd_tl \c_spath_lineto_tl
1300 }
1301 \c_spath_curveto_tl {
1302 \tl_put_left:NV \l_@@_tmpd_tl \c_spath_curvetoa_tl
1303 }
1304 \c_spath_curvetoa_tl {
1305 \tl_put_left:NV \l_@@_tmpd_tl \c_spath_curveto_tl
1306 }
1307 \c_spath_curvetob_tl {
1308 \tl_put_left:NV \l_@@_tmpd_tl \c_spath_curvetob_tl
1309 }
1310 }
1311 {
1312 \tl_if_empty:NF \l_@@_tmpa_tl
1313 {
1314 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1315
1316 \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
1317 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1318 \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
1319 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1320
1321 \tl_put_left:Nx \l_@@_tmpd_tl
1322 {
1323 {\dim_use:N \l_@@_tmpa_dim}
1324 {\dim_use:N \l_@@_tmpb_dim}
1325 }
1326 }
1327 }
1328 {
1329 \tl_if_eq:NNTF \l_@@_tmpc_tl \c_spath_closepath_tl
1330 {
1331 \bool_set_true:N \l_@@_closed_bool
1332 }
1333 {
1334 \msg_warning:nnx
1335 { spath3 }
1336 { unknown path construction }
1337 { \l_@@_tmpc_tl }
1338 }
1339
1340 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1341 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1342 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1343
1344 }
1345 }
1346
1347 \bool_if:NT \l_@@_closed_bool
1348 {
1349 \tl_put_right:NV \l_@@_tmpd_tl \c_spath_closepath_tl
1350 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpd_tl}
1351 \tl_put_right:Nx \l_@@_tmpd_tl
1352 {
1353 { \tl_head:N \l_@@_tmpd_tl }
1354 { \tl_head:N \l_@@_tmpe_tl }
1355 }
1356 }
1357
1358 \bool_set_false:N \l_@@_closed_bool
1359 \bool_if:NF \l_@@_rect_bool
1360 {
1361 \tl_put_left:NV \l_@@_tmpd_tl \c_spath_moveto_tl
1362 }
1363 }
1364
1365 \tl_put_left:NV \l_@@_tmpb_tl \l_@@_tmpd_tl
1366 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
1367 \group_end:
1368 }
1369 \cs_new_protected_nopar:Npn \spath_reverse:Nn #1#2
1370 {
1371 \@@_reverse:n {#2}
1372 \tl_set_eq:NN #1 \g_@@_output_tl
1373 \tl_gclear:N \g_@@_output_tl
1374 }
1375 \cs_generate_variant:Nn \spath_reverse:Nn {NV, cn, cV, Nv}
1376 \cs_new_protected_nopar:Npn \spath_reverse:N #1
1377 {
1378 \spath_reverse:NV #1#1
1379 }
1380 \cs_generate_variant:Nn \spath_reverse:N {c}
1381 \cs_new_protected_nopar:Npn \spath_greverse:Nn #1#2
1382 {
1383 \@@_reverse:n {#2}
1384 \tl_gset_eq:NN #1 \g_@@_output_tl
1385 \tl_gclear:N \g_@@_output_tl
1386 }
1387 \cs_generate_variant:Nn \spath_greverse:Nn {NV, cn, cV, Nv}
1388 \cs_new_protected_nopar:Npn \spath_greverse:N #1
1389 {
1390 \spath_greverse:NV #1#1
1391 }
1392 \cs_generate_variant:Nn \spath_greverse:N {c}
1393 % \end{macrocode}
1394 % \end{macro}
1395 %
1396 % \begin{macro}[internal]{
1397 % \spath_initialaction:Nn,
1398 % \spath_ginitialaction:Nn,
1399 % }
1400 % This is the first thing that the path does (after the initial move).
1401 % \begin{macrocode}
1402 \cs_new_protected_nopar:Npn \@@_initialaction:n #1
1403 {
1404 \group_begin:
1405 \tl_clear:N \l_@@_tmpa_tl
1406 \tl_set:Nx \l_@@_tmpb_tl {\tl_head:n {#1}}
1407 \tl_if_eq:NNTF \l_@@_tmpb_tl \c_spath_rectcorner_tl
1408 {
1409 \tl_set_eq:NN \l_@@_tmpa_tl \c_spath_rectcorner_tl
1410 }
1411 {
1412 \int_compare:nT
1413 {
1414 \tl_count:n {#1} > 3
1415 }
1416 {
1417 \tl_set:Nx \l_@@_tmpa_tl
1418 {
1419 \tl_item:Nn {#1} {4}
1420 }
1421 }
1422 }
1423 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
1424 \group_end:
1425 }
1426 \cs_new_protected_nopar:Npn \spath_initialaction:Nn #1#2
1427 {
1428 \@@_initialaction:n {#2}
1429 \tl_set_eq:NN #1 \g_@@_output_tl
1430 \tl_gclear:N \g_@@_output_tl
1431 }
1432 \cs_generate_variant:Nn \spath_initialaction:Nn {NV}
1433 \cs_new_protected_nopar:Npn \spath_ginitialaction:Nn #1#2
1434 {
1435 \@@_initialaction:n {#2}
1436 \tl_gset_eq:NN #1 \g_@@_output_tl
1437 \tl_gclear:N \g_@@_output_tl
1438 }
1439 \cs_generate_variant:Nn \spath_ginitialaction:Nn {NV}
1440 % \end{macrocode}
1441 % \end{macro}
1442 %
1443 % \begin{macro}[internal]{
1444 % \spath_finalaction:Nn,
1445 % \spath_gfinalaction:Nn
1446 % }
1447 % This is the last thing that the path does.
1448 % \begin{macrocode}
1449 \cs_new_protected_nopar:Npn \@@_finalaction:n #1
1450 {
1451 \group_begin:
1452 \tl_clear:N \l_@@_tmpb_tl
1453 \int_compare:nT
1454 {
1455 \tl_count:n {#1} > 3
1456 }
1457 {
1458 \tl_set:Nn \l_@@_tmpa_tl {#1}
1459 \tl_reverse:N \l_@@_tmpa_tl
1460 \tl_set:Nx \l_@@_tmpb_tl
1461 {
1462 \tl_item:Nn \l_@@_tmpa_tl {3}
1463 }
1464 \tl_if_eq:NNT \l_@@_tmpb_tl \c_spath_curvetoa_tl
1465 {
1466 \tl_set_eq:NN \l_@@_tmpb_tl \c_spath_curveto_tl
1467 }
1468 \tl_if_eq:NNT \l_@@_tmpb_tl \c_spath_rectsize_tl
1469 {
1470 \tl_set_eq:NN \l_@@_tmpb_tl \c_spath_rectcorner_tl
1471 }
1472 }
1473 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
1474 \group_end:
1475 }
1476 \cs_new_protected_nopar:Npn \spath_finalaction:Nn #1#2
1477 {
1478 \@@_finalaction:n {#2}
1479 \tl_set_eq:NN #1 \g_@@_output_tl
1480 \tl_gclear:N \g_@@_output_tl
1481 }
1482 \cs_generate_variant:Nn \spath_finalaction:Nn {NV}
1483 \cs_new_protected_nopar:Npn \spath_gfinalaction:Nn #1#2
1484 {
1485 \@@_finalaction:n {#2}
1486 \tl_gset_eq:NN #1 \g_@@_output_tl
1487 \tl_gclear:N \g_@@_output_tl
1488 }
1489 \cs_generate_variant:Nn \spath_gfinalaction:Nn {NV}
1490 % \end{macrocode}
1491 % \end{macro}
1492 %
1493 % \begin{macro}[internal]{
1494 % \spath_minbb:Nn,
1495 % \spath_gminbb:Nn
1496 % }
1497 % This computes the minimum (bottom left) of the bounding box of the path.
1498 % \begin{macrocode}
1499 \cs_new_protected_nopar:Npn \@@_minbb:n #1
1500 {
1501 \group_begin:
1502 \tl_set:Nn \l_@@_tmpa_tl {#1}
1503
1504 \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
1505 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1506
1507 \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
1508 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1509
1510 \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
1511 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1512
1513 \tl_if_eq:NNT \l_@@_tmpc_tl \c_spath_rectcorner_tl
1514 {
1515 \dim_set_eq:NN \l_@@_rectx_dim \l_@@_tmpa_dim
1516 \dim_set_eq:NN \l_@@_recty_dim \l_@@_tmpb_dim
1517 }
1518 \bool_until_do:nn {
1519 \tl_if_empty_p:N \l_@@_tmpa_tl
1520 }
1521 {
1522 \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
1523 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1524
1525 \tl_if_eq:NNTF \l_@@_tmpc_tl \c_spath_rectsize_tl
1526 {
1527 \dim_set:Nn \l_@@_tmpa_dim
1528 {\dim_min:nn
1529 {\tl_head:N \l_@@_tmpa_tl + \l_@@_rectx_dim} {\l_@@_tmpa_dim}
1530 }
1531 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1532
1533 \dim_set:Nn \l_@@_tmpb_dim
1534 {\dim_min:nn
1535 {\tl_head:N \l_@@_tmpa_tl + \l_@@_recty_dim} {\l_@@_tmpb_dim}
1536 }
1537 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1538 }
1539 {
1540 \dim_set:Nn \l_@@_tmpa_dim
1541 {\dim_min:nn {\tl_head:N \l_@@_tmpa_tl} {\l_@@_tmpa_dim}}
1542 \tl_if_eq:NNT \l_@@_tmpc_tl \c_spath_rectcorner_tl
1543 {
1544 \dim_set:Nn \l_@@_rectx_dim {\tl_head:N \l_@@_tmpa_tl}
1545 }
1546 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1547
1548 \dim_set:Nn \l_@@_tmpb_dim
1549 {\dim_min:nn {\tl_head:N \l_@@_tmpa_tl} {\l_@@_tmpb_dim}}
1550 \tl_if_eq:NNT \l_@@_tmpc_tl \c_spath_rectcorner_tl
1551 {
1552 \dim_set:Nn \l_@@_recty_dim {\tl_head:N \l_@@_tmpa_tl}
1553 }
1554 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1555 }
1556
1557 }
1558 \tl_clear:N \l_@@_tmpb_tl
1559 \tl_put_right:Nx \l_@@_tmpb_tl
1560 {
1561 {\dim_use:N \l_@@_tmpa_dim}
1562 {\dim_use:N \l_@@_tmpb_dim}
1563 }
1564 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
1565 \group_end:
1566 }
1567 \cs_new_protected_nopar:Npn \spath_minbb:Nn #1#2
1568 {
1569 \@@_minbb:n {#2}
1570 \tl_set_eq:NN #1 \g_@@_output_tl
1571 \tl_gclear:N \g_@@_output_tl
1572 }
1573 \cs_generate_variant:Nn \spath_minbb:Nn {NV, cn, cV}
1574 \cs_new_protected_nopar:Npn \spath_gminbb:Nn #1#2
1575 {
1576 \@@_minbb:n {#2}
1577 \tl_gset_eq:NN #1 \g_@@_output_tl
1578 \tl_gclear:N \g_@@_output_tl
1579 }
1580 \cs_generate_variant:Nn \spath_gminbb:Nn {NV, cn, cV}
1581 % \end{macrocode}
1582 % \end{macro}
1583 %
1584 % \begin{macro}[internal]{
1585 % \spath_maxbb:Nn,
1586 % \spath_gmaxbb:Nn,
1587 % }
1588 % This computes the maximum (top right) of the bounding box of the path.
1589 % \begin{macrocode}
1590 \cs_new_protected_nopar:Npn \@@_maxbb:n #1
1591 {
1592 \group_begin:
1593 \tl_set:Nn \l_@@_tmpa_tl {#1}
1594
1595 \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
1596 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1597
1598 \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
1599 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1600
1601 \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
1602 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1603
1604 \tl_if_eq:NNT \l_@@_tmpc_tl \c_spath_rectcorner_tl
1605 {
1606 \dim_set_eq:NN \l_@@_rectx_dim \l_@@_tmpa_dim
1607 \dim_set_eq:NN \l_@@_recty_dim \l_@@_tmpb_dim
1608 }
1609 \bool_until_do:nn {
1610 \tl_if_empty_p:N \l_@@_tmpa_tl
1611 }
1612 {
1613 \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
1614 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1615
1616 \tl_if_eq:NNTF \l_@@_tmpc_tl \c_spath_rectsize_tl
1617 {
1618 \dim_set:Nn \l_@@_tmpa_dim
1619 {\dim_max:nn
1620 {\tl_head:N \l_@@_tmpa_tl + \l_@@_rectx_dim} {\l_@@_tmpa_dim}
1621 }
1622 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1623
1624 \dim_set:Nn \l_@@_tmpb_dim
1625 {\dim_max:nn
1626 {\tl_head:N \l_@@_tmpa_tl + \l_@@_recty_dim} {\l_@@_tmpb_dim}
1627 }
1628 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1629 }
1630 {
1631 \dim_set:Nn \l_@@_tmpa_dim
1632 {\dim_max:nn {\tl_head:N \l_@@_tmpa_tl} {\l_@@_tmpa_dim}}
1633 \tl_if_eq:NNT \l_@@_tmpc_tl \c_spath_rectcorner_tl
1634 {
1635 \dim_set:Nn \l_@@_rectx_dim {\tl_head:N \l_@@_tmpa_tl}
1636 }
1637 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1638
1639 \dim_set:Nn \l_@@_tmpb_dim
1640 {\dim_max:nn {\tl_head:N \l_@@_tmpa_tl} {\l_@@_tmpb_dim}}
1641 \tl_if_eq:NNT \l_@@_tmpc_tl \c_spath_rectcorner_tl
1642 {
1643 \dim_set:Nn \l_@@_recty_dim {\tl_head:N \l_@@_tmpa_tl}
1644 }
1645 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1646 }
1647
1648 }
1649 \tl_clear:N \l_@@_tmpb_tl
1650 \tl_set:Nx \l_@@_tmpb_tl
1651 {
1652 {\dim_use:N \l_@@_tmpa_dim}
1653 {\dim_use:N \l_@@_tmpb_dim}
1654 }
1655 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
1656 \group_end:
1657 }
1658 \cs_new_protected_nopar:Npn \spath_maxbb:Nn #1#2
1659 {
1660 \@@_maxbb:n {#2}
1661 \tl_set_eq:NN #1 \g_@@_output_tl
1662 \tl_gclear:N \g_@@_output_tl
1663 }
1664 \cs_generate_variant:Nn \spath_maxbb:Nn {NV, cn, cV}
1665 \cs_new_protected_nopar:Npn \spath_gmaxbb:Nn #1#2
1666 {
1667 \@@_maxbb:n {#2}
1668 \tl_gset_eq:NN #1 \g_@@_output_tl
1669 \tl_gclear:N \g_@@_output_tl
1670 }
1671 \cs_generate_variant:Nn \spath_gmaxbb:Nn {NV, cn, cV}
1672 % \end{macrocode}
1673 % \end{macro}
1674 %
1675 % \begin{macro}[internal]{
1676 % \spath_save_to_aux:Nn,
1677 % \spath_save_to_aux:N
1678 % }
1679 % This saves a soft path to the auxfile.
1680 % The first argument is the macro that will be assigned to the soft path when the aux file is read back in.
1681 % \begin{macrocode}
1682 \int_set:Nn \l_@@_tmpa_int {\char_value_catcode:n {`@}}
1683 \char_set_catcode_letter:N @
1684 \cs_new_protected_nopar:Npn \spath_save_to_aux:Nn #1#2 {
1685 \tl_if_empty:nF {#2}
1686 {
1687 \tl_clear:N \l_@@_tmpa_tl
1688 \tl_put_right:Nn \l_@@_tmpa_tl {
1689 \ExplSyntaxOn
1690 \tl_gclear_new:N #1
1691 \tl_gset:Nn #1 {#2}
1692 \ExplSyntaxOff
1693 }
1694 \protected@write\@auxout{}{
1695 \tl_to_str:N \l_@@_tmpa_tl
1696 }
1697 }
1698 }
1699 \char_set_catcode:nn {`@} {\l_@@_tmpa_int}
1700 \cs_generate_variant:Nn \spath_save_to_aux:Nn {cn, cV, NV}
1701 \cs_new_protected_nopar:Npn \spath_save_to_aux:N #1
1702 {
1703 \tl_if_exist:NT #1
1704 {
1705 \spath_save_to_aux:NV #1#1
1706 }
1707 }
1708 \cs_generate_variant:Nn \spath_save_to_aux:N {c}
1709 % \end{macrocode}
1710 % \end{macro}
1711 %
1712 %
1713 % \subsection{Path Manipulation}
1714 %
1715 % These functions all manipulate a soft path.
1716 % They come with a variety of different argument specifications.
1717 % 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.
1718 % There is always a variant in which the path is specified by a macro and restored back in that same macro.
1719 %
1720 %
1721 % \begin{macro}[internal]{
1722 % \spath_translate:Nnnn,
1723 % \spath_translate:Nnn,
1724 % \spath_gtranslate:Nnnn,
1725 % \spath_gtranslate:Nnn
1726 % }
1727 % Translates a path by an amount.
1728 % \begin{macrocode}
1729 \cs_new_protected_nopar:Npn \@@_translate:nnn #1#2#3
1730 {
1731 \group_begin:
1732 \tl_set:Nn \l_@@_tmpa_tl {#1}
1733 \tl_clear:N \l_@@_tmpb_tl
1734 \bool_until_do:nn {
1735 \tl_if_empty_p:N \l_@@_tmpa_tl
1736 }
1737 {
1738 \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
1739
1740 \tl_put_right:Nx \l_@@_tmpb_tl {\tl_head:N \l_@@_tmpa_tl}
1741 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1742
1743 \tl_if_eq:NNTF \l_@@_tmpc_tl \c_spath_rectsize_tl
1744 {
1745 \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
1746 }
1747 {
1748 \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl + #2}
1749 }
1750 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1751
1752 \tl_if_eq:NNTF \l_@@_tmpc_tl \c_spath_rectsize_tl
1753 {
1754 \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
1755 }
1756 {
1757 \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl + #3}
1758 }
1759 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1760
1761 \tl_put_right:Nx \l_@@_tmpb_tl
1762 {
1763 {\dim_use:N \l_@@_tmpa_dim}
1764 {\dim_use:N \l_@@_tmpb_dim}
1765 }
1766 }
1767 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
1768 \group_end:
1769 }
1770 \cs_generate_variant:Nn \@@_translate:nnn {nVV}
1771 \cs_new_protected_nopar:Npn \spath_translate:Nnnn #1#2#3#4
1772 {
1773 \@@_translate:nnn {#2}{#3}{#4}
1774 \tl_set_eq:NN #1 \g_@@_output_tl
1775 \tl_gclear:N \g_@@_output_tl
1776 }
1777 \cs_generate_variant:Nn \spath_translate:Nnnn {NVxx, NVVV, NVnn}
1778 \cs_new_protected_nopar:Npn \spath_translate:Nnn #1#2#3
1779 {
1780 \spath_translate:NVnn #1#1{#2}{#3}
1781 }
1782 \cs_generate_variant:Nn \spath_translate:Nnn {NVV, cnn, cVV}
1783 \cs_new_protected_nopar:Npn \spath_gtranslate:Nnnn #1#2#3#4
1784 {
1785 \@@_translate:nnn {#2}{#3}{#4}
1786 \tl_gset_eq:NN #1 \g_@@_output_tl
1787 \tl_gclear:N \g_@@_output_tl
1788 }
1789 \cs_generate_variant:Nn \spath_gtranslate:Nnnn {NVxx, NVVV, NVnn}
1790 \cs_new_protected_nopar:Npn \spath_gtranslate:Nnn #1#2#3
1791 {
1792 \spath_gtranslate:NVnn #1#1{#2}{#3}
1793 }
1794 \cs_generate_variant:Nn \spath_gtranslate:Nnn {NVV, cnn, cVV}
1795 % \end{macrocode}
1796 %
1797 % This variant allows for passing the coordinates as a single braced group as it strips off the outer braces of the second argument.
1798 % \begin{macrocode}
1799 \cs_new_protected_nopar:Npn \spath_translate:Nn #1#2
1800 {
1801 \spath_translate:Nnn #1 #2
1802 }
1803 \cs_generate_variant:Nn \spath_translate:Nn {NV}
1804 \cs_new_protected_nopar:Npn \spath_gtranslate:Nn #1#2
1805 {
1806 \spath_gtranslate:Nnn #1 #2
1807 }
1808 \cs_generate_variant:Nn \spath_gtranslate:Nn {NV}
1809 % \end{macrocode}
1810 % \end{macro}
1811 %
1812 %
1813 %
1814 % \begin{macro}[internal]{
1815 % \spath_translate_to:Nnnn,
1816 % \spath_translate_to:Nnn,
1817 % \spath_gtranslate_to:Nnnn,
1818 % \spath_gtranslate_to:Nnn
1819 % }
1820 % Translates a path so that it starts at a point.
1821 % \begin{macrocode}
1822 \cs_new_protected_nopar:Npn \@@_translate_to:nnn #1#2#3
1823 {
1824 \group_begin:
1825 \spath_initialpoint:Nn \l_@@_tmpa_tl {#1}
1826
1827 \dim_set:Nn \l_@@_tmpa_dim
1828 {
1829 #2
1830 -
1831 \tl_item:Nn \l_@@_tmpa_tl {1}
1832 }
1833 \dim_set:Nn \l_@@_tmpb_dim
1834 {
1835 #3
1836 -
1837 \tl_item:Nn \l_@@_tmpa_tl {2}
1838 }
1839
1840 \@@_translate:nVV {#1} \l_@@_tmpa_dim \l_@@_tmpb_dim
1841 \group_end:
1842 }
1843 \cs_new_protected_nopar:Npn \spath_translate_to:Nnnn #1#2#3#4
1844 {
1845 \@@_translate_to:nnn {#2}{#3}{#4}
1846 \tl_set_eq:NN #1 \g_@@_output_tl
1847 \tl_gclear:N \g_@@_output_tl
1848 }
1849 \cs_generate_variant:Nn \spath_translate_to:Nnnn {NVxx, NVVV, NVnn}
1850 \cs_new_protected_nopar:Npn \spath_translate_to:Nnn #1#2#3
1851 {
1852 \spath_translate_to:NVnn #1#1{#2}{#3}
1853 }
1854 \cs_generate_variant:Nn \spath_translate_to:Nnn {NVV, cnn, cVV}
1855 \cs_new_protected_nopar:Npn \spath_gtranslate_to:Nnnn #1#2#3#4
1856 {
1857 \@@_translate_to:nnn {#2}{#3}{#4}
1858 \tl_gset_eq:NN #1 \g_@@_output_tl
1859 \tl_gclear:N \g_@@_output_tl
1860 }
1861 \cs_generate_variant:Nn \spath_gtranslate_to:Nnnn {NVxx, NVVV, NVnn}
1862 \cs_new_protected_nopar:Npn \spath_gtranslate_to:Nnn #1#2#3
1863 {
1864 \spath_gtranslate_to:NVnn #1#1{#2}{#3}
1865 }
1866 \cs_generate_variant:Nn \spath_gtranslate_to:Nnn {NVV, cnn, cVV}
1867 % \end{macrocode}
1868 %
1869 % This variant allows for passing the coordinates as a single braced group as it strips off the outer braces of the second argument.
1870 % \begin{macrocode}
1871 \cs_new_protected_nopar:Npn \spath_translate_to:Nn #1#2
1872 {
1873 \spath_translate_to:Nnn #1 #2
1874 }
1875 \cs_generate_variant:Nn \spath_translate_to:Nn {NV}
1876 \cs_new_protected_nopar:Npn \spath_gtranslate_to:Nn #1#2
1877 {
1878 \spath_gtranslate_to:Nnn #1 #2
1879 }
1880 \cs_generate_variant:Nn \spath_gtranslate_to:Nn {NV}
1881 % \end{macrocode}
1882 % \end{macro}
1883 %
1884 %
1885 % \begin{macro}[internal]{
1886 % \spath_scale:Nnnn,
1887 % \spath_scale:Nnn,
1888 % \spath_gscale:Nnnn,
1889 % \spath_gscale:Nnn
1890 % }
1891 % Scale a path.
1892 % \begin{macrocode}
1893 \cs_new_protected_nopar:Npn \@@_scale:nnn #1#2#3
1894 {
1895 \group_begin:
1896 \tl_set:Nn \l_@@_tmpa_tl {#1}
1897 \tl_clear:N \l_@@_tmpb_tl
1898 \bool_until_do:nn {
1899 \tl_if_empty_p:N \l_@@_tmpa_tl
1900 }
1901 {
1902 \tl_put_right:Nx \l_@@_tmpb_tl {\tl_head:N \l_@@_tmpa_tl}
1903 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1904
1905 \fp_set:Nn \l_@@_tmpa_fp {\tl_head:N \l_@@_tmpa_tl * #2}
1906 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1907
1908 \fp_set:Nn \l_@@_tmpb_fp {\tl_head:N \l_@@_tmpa_tl * #3}
1909 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1910
1911 \tl_put_right:Nx \l_@@_tmpb_tl
1912 {
1913 {\fp_to_dim:N \l_@@_tmpa_fp}
1914 {\fp_to_dim:N \l_@@_tmpb_fp}
1915 }
1916 }
1917 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
1918 \group_end:
1919 }
1920 \cs_new_protected_nopar:Npn \spath_scale:Nnnn #1#2#3#4
1921 {
1922 \@@_scale:nnn {#2}{#3}{#4}
1923 \tl_set_eq:NN #1 \g_@@_output_tl
1924 \tl_gclear:N \g_@@_output_tl
1925 }
1926 \cs_generate_variant:Nn \spath_scale:Nnnn {NVnn, Nnxx}
1927 \cs_new_protected_nopar:Npn \spath_scale:Nnn #1#2#3
1928 {
1929 \spath_scale:NVnn #1#1{#2}{#3}
1930 }
1931 \cs_generate_variant:Nn \spath_scale:Nnn {cnn, cVV, NVV}
1932 \cs_new_protected_nopar:Npn \spath_gscale:Nnnn #1#2#3#4
1933 {
1934 \@@_scale:nnn {#2}{#3}{#4}
1935 \tl_gset_eq:NN #1 \g_@@_output_tl
1936 \tl_gclear:N \g_@@_output_tl
1937 }
1938 \cs_generate_variant:Nn \spath_gscale:Nnnn {NVnn, Nnxx}
1939 \cs_new_protected_nopar:Npn \spath_gscale:Nnn #1#2#3
1940 {
1941 \spath_gscale:NVnn #1#1{#2}{#3}
1942 }
1943 \cs_generate_variant:Nn \spath_gscale:Nnn {cnn, cVV, NVV}
1944 % \end{macrocode}
1945 %
1946 % This variant allows for passing the coordinates as a single braced group as it strips off the outer braces of the second argument.
1947 % \begin{macrocode}
1948 \cs_new_protected_nopar:Npn \spath_scale:Nn #1#2
1949 {
1950 \spath_scale:Nnn #1 #2
1951 }
1952
1953 \cs_generate_variant:Nn \spath_scale:Nn {NV}
1954 \cs_new_protected_nopar:Npn \spath_gscale:Nn #1#2
1955 {
1956 \spath_gscale:Nnn #1 #2
1957 }
1958
1959 \cs_generate_variant:Nn \spath_gscale:Nn {NV}
1960 % \end{macrocode}
1961 % \end{macro}
1962 %
1963 % \begin{macro}[internal]{
1964 % \spath_transform:Nnnnnnnn,
1965 % \spath_transform:Nnnnnnn,
1966 % \spath_gtransform:Nnnnnnnn,
1967 % \spath_gtransform:Nnnnnnn,
1968 % }
1969 % Applies an affine (matrix and vector) transformation to path.
1970 % The matrix is specified in rows first.
1971 % \begin{macrocode}
1972 \cs_new_protected_nopar:Npn \@@_transform:nnnnnnn #1#2#3#4#5#6#7
1973 {
1974 \group_begin:
1975 \tl_set:Nn \l_@@_tmpa_tl {#1}
1976 \tl_clear:N \l_@@_tmpb_tl
1977 \bool_until_do:nn {
1978 \tl_if_empty_p:N \l_@@_tmpa_tl
1979 }
1980 {
1981 \tl_set:Nx \l_@@_tmpe_tl {\tl_head:N \l_@@_tmpa_tl}
1982
1983 \tl_put_right:Nx \l_@@_tmpb_tl {\tl_head:N \l_@@_tmpa_tl}
1984 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1985 \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
1986 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1987 \tl_set:Nx \l_@@_tmpd_tl {\tl_head:N \l_@@_tmpa_tl}
1988 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
1989
1990 \tl_if_eq:NNTF \l_@@_tmpe_tl \c_spath_rectsize_tl
1991 {
1992 \fp_set:Nn \l_@@_tmpa_fp
1993 {\l_@@_tmpc_tl * #2 + \l_@@_tmpd_tl * #4}
1994 \fp_set:Nn \l_@@_tmpb_fp
1995 {\l_@@_tmpc_tl * #3 + \l_@@_tmpd_tl * #5}
1996 }
1997 {
1998 \fp_set:Nn \l_@@_tmpa_fp
1999 {\l_@@_tmpc_tl * #2 + \l_@@_tmpd_tl * #4 + #6}
2000 \fp_set:Nn \l_@@_tmpb_fp
2001 {\l_@@_tmpc_tl * #3 + \l_@@_tmpd_tl * #5 + #7}
2002 }
2003
2004 \tl_put_right:Nx \l_@@_tmpb_tl
2005 {
2006 {\fp_to_dim:N \l_@@_tmpa_fp}
2007 {\fp_to_dim:N \l_@@_tmpb_fp}
2008 }
2009 }
2010
2011 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
2012 \group_end:
2013 }
2014 \cs_new_protected_nopar:Npn \spath_transform:Nnnnnnnn #1#2#3#4#5#6#7#8
2015 {
2016 \@@_transform:nnnnnnn {#2}{#3}{#4}{#5}{#6}{#7}{#8}
2017 \tl_set_eq:NN #1 \g_@@_output_tl
2018 \tl_gclear:N \g_@@_output_tl
2019 }
2020 \cs_generate_variant:Nn \spath_transform:Nnnnnnnn
2021 {NVnnnnnn, Nnxxxxxx, cnnnnnnn}
2022 \cs_new_protected_nopar:Npn \spath_transform:Nnnnnnn #1#2#3#4#5#6#7
2023 {
2024 \spath_transform:NVnnnnnn #1#1{#2}{#3}{#4}{#5}{#6}{#7}
2025 }
2026 \cs_generate_variant:Nn \spath_transform:Nnnnnnn {cnnnnnn}
2027 \cs_new_protected_nopar:Npn \spath_transform:Nnn #1#2#3
2028 {
2029 \spath_transform:Nnnnnnnn #1{#2}#3
2030 }
2031 \cs_generate_variant:Nn \spath_transform:Nnn {cnn, cVn, NVn, NnV}
2032 \cs_new_protected_nopar:Npn \spath_transform:Nn #1#2
2033 {
2034 \spath_transform:NVnnnnnn #1#1#2
2035 }
2036 \cs_generate_variant:Nn \spath_transform:Nn {cn, cV, NV}
2037
2038 \cs_new_protected_nopar:Npn \spath_gtransform:Nnnnnnnn #1#2#3#4#5#6#7#8
2039 {
2040 \@@_transform:nnnnnnn {#2}{#3}{#4}{#5}{#6}{#7}{#8}
2041 \tl_gset_eq:NN #1 \g_@@_output_tl
2042 \tl_gclear:N \g_@@_output_tl
2043 }
2044 \cs_generate_variant:Nn \spath_gtransform:Nnnnnnnn {NVnnnnnn, Nnxxxxxx, cnnnnnnn}
2045 \cs_new_protected_nopar:Npn \spath_gtransform:Nnnnnnn #1#2#3#4#5#6#7
2046 {
2047 \spath_gtransform:NVnnnnnn #1#1{#2}{#3}{#4}{#5}{#6}{#7}
2048 }
2049 \cs_generate_variant:Nn \spath_gtransform:Nnnnnnn {cnnnnnn}
2050 \cs_new_protected_nopar:Npn \spath_gtransform:Nnn #1#2#3
2051 {
2052 \spath_gtransform:Nnnnnnnn #1{#2}#3
2053 }
2054 \cs_generate_variant:Nn \spath_gtransform:Nnn {cnn, cVn, NVn, NnV}
2055 \cs_new_protected_nopar:Npn \spath_gtransform:Nn #1#2
2056 {
2057 \spath_gtransform:NVnnnnnn #1#1#2
2058 }
2059 \cs_generate_variant:Nn \spath_gtransform:Nn {cn, cV, NV}
2060 % \end{macrocode}
2061 % \end{macro}
2062 %
2063 % \begin{macro}[internal]{
2064 % \spath_span:Nnnn,
2065 % \spath_span:Nnn,
2066 % \spath_gspan:Nnnn,
2067 % \spath_gspan:Nnn,
2068 % \spath_normalise:Nn,
2069 % \spath_normalise:N,
2070 % \spath_gnormalise:Nn,
2071 % \spath_gnormalise:N
2072 % }
2073 % The \Verb+span+ functions transform a path to start and end at specified points.
2074 % The \Verb+normalise+ functions transform it to start at the origin and end at \((1\mathrm{pt},0\mathrm{pt})\).
2075 %
2076 % If the path starts and ends at the same point then it is translated to the specified point (or origin) but not otherwise changed.
2077 % \begin{macrocode}
2078 \cs_new_protected_nopar:Npn \@@_span:nnn #1#2#3
2079 {
2080 \group_begin:
2081 \spath_initialpoint:Nn \l_@@_tmpa_tl {#1}
2082 \spath_finalpoint:Nn \l_@@_tmpb_tl {#1}
2083
2084 \fp_set:Nn \l_@@_tmpa_fp
2085 {
2086 (\tl_item:Nn \l_@@_tmpb_tl {1}) -
2087 (\tl_item:Nn \l_@@_tmpa_tl {1})
2088 }
2089 \fp_set:Nn \l_@@_tmpb_fp
2090 {
2091 (\tl_item:Nn \l_@@_tmpb_tl {2}) -
2092 (\tl_item:Nn \l_@@_tmpa_tl {2})
2093 }
2094 \fp_set:Nn \l_@@_tmpc_fp
2095 {
2096 (\l_@@_tmpa_fp) * (\l_@@_tmpa_fp)
2097 +
2098 (\l_@@_tmpb_fp * \l_@@_tmpb_fp)
2099 }
2100
2101 \fp_compare:nTF
2102 {
2103 \l_@@_tmpc_fp < 0.001
2104 }
2105 {
2106 \spath_translate_to:Nnnn \l_@@_tmpd_tl {#1} #2
2107 }
2108 {
2109 \fp_set:Nn \l_@@_tmpa_fp
2110 {
2111 (
2112 ((\tl_item:nn {#3} {1})
2113 -
2114 (\tl_item:nn {#2} {1}))
2115 *
2116 ((\tl_item:Nn \l_@@_tmpb_tl {1})
2117 -
2118 (\tl_item:Nn \l_@@_tmpa_tl {1}))
2119 +
2120 ((\tl_item:nn {#3} {2})
2121 -
2122 (\tl_item:nn {#2} {2}))
2123 *
2124 ((\tl_item:Nn \l_@@_tmpb_tl {2})
2125 -
2126 (\tl_item:Nn \l_@@_tmpa_tl {2}))
2127 )
2128 /
2129 \l_@@_tmpc_fp
2130 }
2131 \fp_set:Nn \l_@@_tmpb_fp
2132 {
2133 (
2134 ((\tl_item:nn {#3} {2})
2135 -
2136 (\tl_item:nn {#2} {2}))
2137 *
2138 ((\tl_item:Nn \l_@@_tmpb_tl {1})
2139 -
2140 (\tl_item:Nn \l_@@_tmpa_tl {1}))
2141 -
2142 ((\tl_item:nn {#3} {1})
2143 -
2144 (\tl_item:nn {#2} {1}))
2145 *
2146 ((\tl_item:Nn \l_@@_tmpb_tl {2})
2147 -
2148 (\tl_item:Nn \l_@@_tmpa_tl {2}))
2149 )
2150 /
2151 \l_@@_tmpc_fp
2152 }
2153
2154 \tl_set:Nx \l_@@_tmpc_tl
2155 {
2156 {
2157 \fp_to_decimal:N \l_@@_tmpa_fp
2158 }
2159 {
2160 \fp_to_decimal:N \l_@@_tmpb_fp
2161 }
2162 {
2163 \fp_eval:n { - \l_@@_tmpb_fp }
2164 }
2165 {
2166 \fp_to_decimal:N \l_@@_tmpa_fp
2167 }
2168 {
2169 \fp_to_dim:n
2170 {
2171 \tl_item:nn {#2} {1}
2172 -
2173 \l_@@_tmpa_fp * (\tl_item:Nn \l_@@_tmpa_tl {1})
2174 +
2175 \l_@@_tmpb_fp * (\tl_item:Nn \l_@@_tmpa_tl {2})
2176 }
2177 }
2178 {
2179 \fp_to_dim:n
2180 {
2181 \tl_item:nn {#2} {2}
2182 -
2183 \l_@@_tmpb_fp * (\tl_item:Nn \l_@@_tmpa_tl {1})
2184 -
2185 \l_@@_tmpa_fp * (\tl_item:Nn \l_@@_tmpa_tl {2})
2186 }
2187 }
2188 }
2189 \spath_transform:NnV \l_@@_tmpd_tl {#1} \l_@@_tmpc_tl
2190 }
2191 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpd_tl
2192 \group_end:
2193 }
2194 \cs_new_protected_nopar:Npn \spath_span:Nnnn #1#2#3#4
2195 {
2196 \@@_span:nnn {#2}{#3}{#4}
2197 \tl_set_eq:NN #1 \g_@@_output_tl
2198 \tl_gclear:N \g_@@_output_tl
2199 }
2200 \cs_generate_variant:Nn \spath_span:Nnnn {NVnn, NVVV, NnVV}
2201 \cs_new_protected_nopar:Npn \spath_span:Nnn #1#2#3
2202 {
2203 \spath_span:NVnn #1#1{#2}{#3}
2204 }
2205 \cs_generate_variant:Nn \spath_span:Nnn {NVV, cnn, cvv, cVV}
2206 \cs_new_protected_nopar:Npn \spath_gspan:Nnnn #1#2#3#4
2207 {
2208 \@@_span:nnn {#2}{#3}{#4}
2209 \tl_gset_eq:NN #1 \g_@@_output_tl
2210 \tl_gclear:N \g_@@_output_tl
2211 }
2212 \cs_generate_variant:Nn \spath_gspan:Nnnn {NVnn, NVVV}
2213 \cs_new_protected_nopar:Npn \spath_gspan:Nnn #1#2#3
2214 {
2215 \spath_gspan:NVnn #1#1{#2}{#3}
2216 }
2217 \cs_generate_variant:Nn \spath_gspan:Nnn {NVV, cnn, cvv, cVV}
2218 \cs_new_protected_nopar:Npn \@@_normalise:n #1
2219 {
2220 \@@_span:nnn {#1}{{0pt}{0pt}}{{1pt}{0pt}}
2221 }
2222 \cs_new_protected_nopar:Npn \spath_normalise:Nn #1#2
2223 {
2224 \@@_normalise:n {#2}
2225 \tl_set_eq:NN #1 \g_@@_output_tl
2226 \tl_gclear:N \g_@@_output_tl
2227 }
2228 \cs_generate_variant:Nn \spath_normalise:Nn {cn,NV, cV, cv}
2229 \cs_new_protected_nopar:Npn \spath_normalise:N #1
2230 {
2231 \spath_normalise:NV #1#1
2232 }
2233 \cs_generate_variant:Nn \spath_normalise:N {c}
2234 \cs_new_protected_nopar:Npn \spath_gnormalise:Nn #1#2
2235 {
2236 \@@_normalise:n {#2}
2237 \tl_gset_eq:NN #1 \g_@@_output_tl
2238 \tl_gclear:N \g_@@_output_tl
2239 }
2240 \cs_generate_variant:Nn \spath_gnormalise:Nn {cn,NV, cV, cv}
2241 \cs_new_protected_nopar:Npn \spath_gnormalise:N #1
2242 {
2243 \spath_gnormalise:NV #1#1
2244 }
2245 \cs_generate_variant:Nn \spath_gnormalise:N {c}
2246 % \end{macrocode}
2247 % \end{macro}
2248 %
2249 %
2250 % \begin{macro}[internal]{
2251 % \spath_splice_between:Nnnn,
2252 % \spath_splice_between:Nnn,
2253 % \spath_gsplice_between:Nnnn,
2254 % \spath_gsplice_between:Nnn
2255 % }
2256 % This takes three paths and returns a single path in which the middle one is adjusted (and welded) so that it joins the first path to the third.
2257 % \begin{macrocode}
2258 \cs_new_protected_nopar:Npn \@@_splice_between:nnn #1#2#3
2259 {
2260 \group_begin:
2261 \spath_finalpoint:Nn \l_@@_tmpd_tl {#1}
2262 \spath_initialpoint:Nn \l_@@_tmpe_tl {#3}
2263 \spath_span:NnVV \l_@@_tmpb_tl {#2} \l_@@_tmpd_tl \l_@@_tmpe_tl
2264 \spath_append_no_move:NnV \l_@@_tmpa_tl {#1} \l_@@_tmpb_tl
2265 \spath_append_no_move:Nn \l_@@_tmpa_tl {#3}
2266 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
2267 \group_end:
2268 }
2269 \cs_new_protected_nopar:Npn \spath_splice_between:Nnnn #1#2#3#4
2270 {
2271 \@@_splice_between:nnn {#2}{#3}{#4}
2272 \tl_set_eq:NN #1 \g_@@_output_tl
2273 \tl_gclear:N \g_@@_output_tl
2274 }
2275 \cs_generate_variant:Nn \spath_splice_between:Nnnn {NVnn, NVVV}
2276 \cs_new_protected_nopar:Npn \spath_splice_between:Nnn #1#2#3
2277 {
2278 \spath_splice_between:NVnn #1#1{#2}{#3}
2279 }
2280 \cs_generate_variant:Nn \spath_splice_between:Nnn {NVV, cnn, cvv, Nvn, NVn}
2281 \cs_new_protected_nopar:Npn \spath_gsplice_between:Nnnn #1#2#3#4
2282 {
2283 \@@_splice_between:nnn {#2}{#3}{#4}
2284 \tl_gset_eq:NN #1 \g_@@_output_tl
2285 \tl_gclear:N \g_@@_output_tl
2286 }
2287 \cs_generate_variant:Nn \spath_gsplice_between:Nnnn {NVnn, NVVV}
2288 \cs_new_protected_nopar:Npn \spath_gsplice_between:Nnn #1#2#3
2289 {
2290 \spath_gsplice_between:NVnn #1#1{#2}{#3}
2291 }
2292 \cs_generate_variant:Nn \spath_gsplice_between:Nnn {NVV, cnn, cvv, Nvn, NVn}
2293 % \end{macrocode}
2294 % \end{macro}
2295 %
2296 % \begin{macro}[internal]{
2297 % \spath_hobby_curve:Nnnnn
2298 % }
2299 % Construct the curve from Hobby's algorithm given the start, end, and tangent directions.
2300 % \begin{macrocode}
2301 \cs_new_protected_nopar:Npn \@@_hobby_curve:nnnn #1#2#3#4
2302 {
2303 \group_begin:
2304 % \end{macrocode}
2305 % First tangent vector projected onto vector between endpoints
2306 %
2307 % Something a bit weird here as the components are opposite to how I thought they should be ...
2308 % \begin{macrocode}
2309 \fp_set:Nn \l_@@_tmpa_fp
2310 {
2311 (
2312 (\tl_item:nn {#2} {1})
2313 *
2314 (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})
2315 +
2316 (\tl_item:nn {#2} {2})
2317 *
2318 (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})
2319 )
2320 /
2321 sqrt
2322 (
2323 (
2324 (\tl_item:nn {#2} {1})^2
2325 +
2326 (\tl_item:nn {#2} {2})^2
2327 )
2328 *
2329 (
2330 (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})^2
2331 +
2332 (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})^2
2333 )
2334 )
2335 }
2336 \fp_set:Nn \l_@@_tmpb_fp
2337 {
2338 (
2339 -
2340 (\tl_item:nn {#2} {1})
2341 *
2342 (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})
2343 +
2344 (\tl_item:nn {#2} {2})
2345 *
2346 (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})
2347 )
2348 /
2349 sqrt
2350 (
2351 (
2352 (\tl_item:nn {#2} {1})^2
2353 +
2354 (\tl_item:nn {#2} {2})^2
2355 )
2356 *
2357 (
2358 (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})^2
2359 +
2360 (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})^2
2361 )
2362 )
2363 }
2364 % \end{macrocode}
2365 % Second tangent vector projected onto vector between endpoints
2366 % \begin{macrocode}
2367 \fp_set:Nn \l_@@_tmpc_fp
2368 {
2369 (
2370 (\tl_item:nn {#3} {1})
2371 *
2372 (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})
2373 +
2374 (\tl_item:nn {#3} {2})
2375 *
2376 (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})
2377 )
2378 /
2379 sqrt
2380 (
2381 (
2382 (\tl_item:nn {#3} {1})^2
2383 +
2384 (\tl_item:nn {#3} {2})^2
2385 )
2386 *
2387 (
2388 (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})^2
2389 +
2390 (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})^2
2391 )
2392 )
2393 }
2394 \fp_set:Nn \l_@@_tmpd_fp
2395 {
2396 (
2397 (\tl_item:nn {#3} {1})
2398 *
2399 (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})
2400 -
2401 (\tl_item:nn {#3} {2})
2402 *
2403 (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})
2404 )
2405 /
2406 sqrt
2407 (
2408 (
2409 (\tl_item:nn {#3} {1})^2
2410 +
2411 (\tl_item:nn {#3} {2})^2
2412 )
2413 *
2414 (
2415 (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})^2
2416 +
2417 (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})^2
2418 )
2419 )
2420 }
2421
2422 \fp_set:Nn \l_@@_tmpe_fp
2423 {
2424 (
2425 2 + sqrt(2) *
2426 (\l_@@_tmpb_fp - 1/16 * \l_@@_tmpd_fp)
2427 *
2428 (\l_@@_tmpd_fp - 1/16 * \l_@@_tmpb_fp)
2429 *
2430 (\l_@@_tmpa_fp - \l_@@_tmpc_fp)
2431 )
2432 /
2433 (
2434 1
2435 +
2436 (1 - (3 - sqrt(5))/2)
2437 *
2438 \l_@@_tmpa_fp
2439 +
2440 (3 - sqrt(5))/2
2441 *
2442 \l_@@_tmpc_fp
2443 )
2444 *
2445 sqrt
2446 (
2447 (
2448 (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})^2
2449 +
2450 (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})^2
2451 )
2452 /
2453 (
2454 (\tl_item:nn {#2} {1})^2
2455 +
2456 (\tl_item:nn {#2} {2})^2
2457 )
2458 )
2459 /3
2460 }
2461 \fp_set:Nn \l_@@_tmpf_fp
2462 {
2463 (
2464 2 - sqrt(2) *
2465 (\l_@@_tmpb_fp - 1/16 * \l_@@_tmpd_fp)
2466 *
2467 (\l_@@_tmpd_fp - 1/16 * \l_@@_tmpb_fp)
2468 *
2469 (\l_@@_tmpa_fp - \l_@@_tmpc_fp)
2470 )
2471 /
2472 (
2473 1
2474 +
2475 (1 - (3 - sqrt(5))/2)
2476 *
2477 \l_@@_tmpc_fp
2478 +
2479 (3 - sqrt(5))/2
2480 *
2481 \l_@@_tmpa_fp
2482 )
2483 *
2484 sqrt
2485 (
2486 (
2487 (\tl_item:nn {#4} {1} - \tl_item:nn {#1} {1})^2
2488 +
2489 (\tl_item:nn {#4} {2} - \tl_item:nn {#1} {2})^2
2490 )
2491 /
2492 (
2493 (\tl_item:nn {#3} {1})^2
2494 +
2495 (\tl_item:nn {#3} {2})^2
2496 )
2497 )
2498 /3
2499 }
2500
2501 \tl_set:Nx \l_@@_tmpa_tl
2502 {
2503 {
2504 \fp_to_dim:n
2505 {
2506 \tl_item:nn {#1} {1}
2507 +
2508 \l_@@_tmpe_fp
2509 *
2510 (\tl_item:nn {#2} {1})
2511 }
2512 }
2513 {
2514 \fp_to_dim:n
2515 {
2516 \tl_item:nn {#1} {2}
2517 +
2518 \l_@@_tmpe_fp
2519 *
2520 (\tl_item:nn {#2} {2})
2521 }
2522 }
2523 }
2524 \tl_set:Nx \l_@@_tmpb_tl
2525 {
2526 {
2527 \fp_to_dim:n
2528 {
2529 \tl_item:nn {#4} {1}
2530 -
2531 \l_@@_tmpf_fp
2532 *
2533 (\tl_item:nn {#3} {1})
2534 }
2535 }
2536 {
2537 \fp_to_dim:n
2538 {
2539 \tl_item:nn {#4} {2}
2540 -
2541 \l_@@_tmpf_fp
2542 *
2543 (\tl_item:nn {#3} {2})
2544 }
2545 }
2546 }
2547
2548 \tl_clear:N \l_@@_tmpc_tl
2549 \tl_set:NV \l_@@_tmpc_tl \c_spath_moveto_tl
2550 \tl_put_right:Nn \l_@@_tmpc_tl {#1}
2551 \tl_put_right:NV \l_@@_tmpc_tl \c_spath_curvetoa_tl
2552 \tl_put_right:NV \l_@@_tmpc_tl \l_@@_tmpa_tl
2553 \tl_put_right:NV \l_@@_tmpc_tl \c_spath_curvetob_tl
2554 \tl_put_right:NV \l_@@_tmpc_tl \l_@@_tmpb_tl
2555 \tl_put_right:NV \l_@@_tmpc_tl \c_spath_curveto_tl
2556 \tl_put_right:Nn \l_@@_tmpc_tl {#4}
2557 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpc_tl
2558 \group_end:
2559 }
2560 \cs_new_protected_nopar:Npn \spath_hobby_curve:Nnnnn #1#2#3#4#5
2561 {
2562 \@@_hobby_curve:nnnn {#2}{#3}{#4}{#5}
2563 \tl_set_eq:NN #1 \g_@@_output_tl
2564 \tl_gclear:N \g_@@_output_tl
2565 }
2566 \cs_generate_variant:Nn \spath_hobby_curve:Nnnnn {NVVVV}
2567 \cs_new_protected_nopar:Npn \spath_ghobby_curve:Nnnnn #1#2#3#4#5
2568 {
2569 \@@_hobby_curve:nnnn {#2}{#3}{#4}{#5}
2570 \tl_gset_eq:NN #1 \g_@@_output_tl
2571 \tl_gclear:N \g_@@_output_tl
2572 }
2573 \cs_generate_variant:Nn \spath_ghobby_curve:Nnnnn {NVVVV}
2574 % \end{macrocode}
2575 % \end{macro}
2576 %
2577 %
2578 % \begin{macro}[internal]{
2579 % \spath_curve_between:Nnn,
2580 % \spath_curve_between:Nn,
2581 % \spath_gcurve_between:Nnn,
2582 % \spath_gcurve_between:Nn
2583 % }
2584 % This takes two paths and returns a single path formed by joining the two paths by a curve.
2585 % \begin{macrocode}
2586 \cs_new_protected_nopar:Npn \@@_curve_between:nn #1#2
2587 {
2588 \group_begin:
2589 \spath_finalpoint:Nn \l_@@_tmpa_tl {#1}
2590 \spath_finaltangent:Nn \l_@@_tmpb_tl {#1}
2591 \spath_initialpoint:Nn \l_@@_tmpc_tl {#2}
2592 \spath_initialtangent:Nn \l_@@_tmpd_tl {#2}
2593
2594 \spath_hobby_curve:NVVVV \l_@@_tmpe_tl
2595 \l_@@_tmpa_tl \l_@@_tmpb_tl \l_@@_tmpd_tl \l_@@_tmpc_tl
2596
2597 \tl_set:Nn \l_@@_tmpa_tl {#1}
2598 \spath_append_no_move:NV \l_@@_tmpa_tl \l_@@_tmpe_tl
2599 \spath_append_no_move:Nn \l_@@_tmpa_tl {#2}
2600 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
2601 \group_end:
2602 }
2603 \cs_new_protected_nopar:Npn \spath_curve_between:Nnn #1#2#3
2604 {
2605 \@@_curve_between:nn {#2}{#3}
2606 \tl_set_eq:NN #1 \g_@@_output_tl
2607 \tl_gclear:N \g_@@_output_tl
2608 }
2609 \cs_generate_variant:Nn \spath_curve_between:Nnn {NVn, NVV}
2610 \cs_new_protected_nopar:Npn \spath_curve_between:Nn #1#2
2611 {
2612 \spath_curve_between:NVn #1#1{#2}
2613 }
2614 \cs_generate_variant:Nn \spath_curve_between:Nn {NV, cn, cv}
2615 \cs_new_protected_nopar:Npn \spath_gcurve_between:Nnn #1#2#3
2616 {
2617 \@@_curve_between:nn {#2}
2618 \tl_gset_eq:NN #1 \g_@@_output_tl
2619 \tl_gclear:N \g_@@_output_tl
2620 }
2621 \cs_generate_variant:Nn \spath_gcurve_between:Nnn {NVn, NVV}
2622 \cs_new_protected_nopar:Npn \spath_gcurve_between:Nn #1#2
2623 {
2624 \spath_gcurve_between:NVnn #1#1{#2}
2625 }
2626 \cs_generate_variant:Nn \spath_gcurve_between:Nn {NV, cn, cv}
2627 % \end{macrocode}
2628 % \end{macro}
2629 %
2630 % \begin{macro}[internal]{
2631 % \spath_close_with:Nn,
2632 % \spath_gclose_with:Nn
2633 % }
2634 % Closes the first path by splicing in the second.
2635 % \begin{macrocode}
2636 \cs_new_protected_nopar:Npn \@@_close_with:nn #1#2
2637 {
2638 \group_begin:
2639 \spath_finalmovepoint:Nn \l_@@_tmpa_tl {#1}
2640 \spath_finalpoint:Nn \l_@@_tmpb_tl {#1}
2641 \dim_compare:nTF
2642 {
2643 \dim_abs:n
2644 {
2645 \tl_item:Nn \l_@@_tmpa_tl {1}
2646 -
2647 \tl_item:Nn \l_@@_tmpb_tl {1}
2648 }
2649 +
2650 \dim_abs:n
2651 {
2652 \tl_item:Nn \l_@@_tmpa_tl {2}
2653 -
2654 \tl_item:Nn \l_@@_tmpb_tl {2}
2655 }
2656 < 0.01pt
2657 }
2658 {
2659 \@@_close:n {#1}
2660 }
2661 {
2662 \spath_span:NnVV \l_@@_tmpc_tl {#2} \l_@@_tmpb_tl \l_@@_tmpa_tl
2663 \spath_append_no_move:NnV \l_@@_tmpd_tl {#1} \l_@@_tmpc_tl
2664 \@@_close:V \l_@@_tmpd_tl
2665 }
2666 \group_end:
2667 }
2668 \cs_new_protected_nopar:Npn \spath_close_with:Nnn #1#2#3
2669 {
2670 \@@_close_with:nn {#2}{#3}
2671 \tl_set_eq:NN #1 \g_@@_output_tl
2672 \tl_gclear:N \g_@@_output_tl
2673 }
2674 \cs_generate_variant:Nn \spath_close_with:Nnn {cnn, cVV, cvv, NVn}
2675 \cs_new_protected_nopar:Npn \spath_close_with:Nn #1#2
2676 {
2677 \spath_close_with:NVn #1#1{#2}
2678 }
2679 \cs_generate_variant:Nn \spath_close_with:Nn {cn, cV, cv, NV}
2680 \cs_new_protected_nopar:Npn \spath_gclose_with:Nnn #1#2#3
2681 {
2682 \@@_close_with:nn {#2}{#3}
2683 \tl_gset_eq:NN #1 \g_@@_output_tl
2684 \tl_gclear:N \g_@@_output_tl
2685 }
2686 \cs_generate_variant:Nn \spath_gclose_with:Nnn {cnn, cVV, cvv, NVn}
2687 \cs_new_protected_nopar:Npn \spath_gclose_with:Nn #1#2
2688 {
2689 \spath_gclose_with:NVn #1#1{#2}
2690 }
2691 \cs_generate_variant:Nn \spath_gclose_with:Nn {cn, cV, cv, NV}
2692 % \end{macrocode}
2693 % \end{macro}
2694 %
2695 % \begin{macro}[internal]{
2696 % \spath_close_with_curve:N,
2697 % \spath_gclose_with_curve:N
2698 % }
2699 % Closes the path with a curve.
2700 % \begin{macrocode}
2701 \cs_new_protected_nopar:Npn \@@_close_with_curve:n #1
2702 {
2703 \group_begin:
2704 \spath_finalpoint:Nn \l_@@_tmpa_tl {#1}
2705 \spath_finaltangent:Nn \l_@@_tmpb_tl {#1}
2706 \spath_finalmovepoint:Nn \l_@@_tmpc_tl {#1}
2707 \spath_finalmovetangent:Nn \l_@@_tmpd_tl {#1}
2708 \dim_compare:nTF
2709 {
2710 \dim_abs:n
2711 {
2712 \tl_item:Nn \l_@@_tmpa_tl {1}
2713 -
2714 \tl_item:Nn \l_@@_tmpc_tl {1}
2715 }
2716 +
2717 \dim_abs:n
2718 {
2719 \tl_item:Nn \l_@@_tmpa_tl {2}
2720 -
2721 \tl_item:Nn \l_@@_tmpc_tl {2}
2722 }
2723 < 0.01pt
2724 }
2725 {
2726 \@@_close:n {#1}
2727 }
2728 {
2729
2730 \spath_hobby_curve:NVVVV \l_@@_tmpe_tl
2731 \l_@@_tmpa_tl \l_@@_tmpb_tl \l_@@_tmpd_tl \l_@@_tmpc_tl
2732
2733 \tl_set:Nn \l_@@_tmpa_tl {#1}
2734 \spath_append_no_move:NV \l_@@_tmpa_tl \l_@@_tmpe_tl
2735 \@@_close:V \l_@@_tmpa_tl
2736 }
2737 \group_end:
2738 }
2739 \cs_new_protected_nopar:Npn \spath_close_with_curve:Nn #1#2
2740 {
2741 \@@_close_with_curve:n {#2}
2742 \tl_set_eq:NN #1 \g_@@_output_tl
2743 \tl_gclear:N \g_@@_output_tl
2744 }
2745 \cs_generate_variant:Nn \spath_close_with_curve:Nn {cn, cV, cv, NV}
2746 \cs_new_protected_nopar:Npn \spath_close_with_curve:N #1
2747 {
2748 \spath_close_with_curve:NV #1#1
2749 }
2750 \cs_generate_variant:Nn \spath_close_with_curve:N {c}
2751 \cs_new_protected_nopar:Npn \spath_gclose_with_curve:Nn #1#2
2752 {
2753 \@@_close_with_curve:n {#2}
2754 \tl_gset_eq:NN #1 \g_@@_output_tl
2755 \tl_gclear:N \g_@@_output_tl
2756 }
2757 \cs_generate_variant:Nn \spath_gclose_with_curve:Nn {cn, cV, cv, NV}
2758 \cs_new_protected_nopar:Npn \spath_gclose_with_curve:N #1
2759 {
2760 \spath_gclose_with_curve:NV #1#1
2761 }
2762 \cs_generate_variant:Nn \spath_gclose_with_curve:N {c}
2763 % \end{macrocode}
2764 % \end{macro}
2765 %
2766 % \begin{macro}[internal]{
2767 % \spath_weld:Nnn,
2768 % \spath_weld:Nn,
2769 % \spath_gweld:Nnn,
2770 % \spath_gweld:Nn
2771 % }
2772 % This welds one path to another, moving the second so that its initial point coincides with the first's final point.
2773 % It is called a \emph{weld} because the initial move of the second path is removed.
2774 % \begin{macrocode}
2775 \cs_new_protected_nopar:Npn \@@_weld:nn #1#2
2776 {
2777 \group_begin:
2778 \tl_set:Nn \l_@@_tmpa_tl {#1}
2779 \tl_set:Nn \l_@@_tmpb_tl {#2}
2780 \spath_finalpoint:Nn \l_@@_tmpc_tl {#1}
2781 \spath_translate_to:NV \l_@@_tmpb_tl \l_@@_tmpc_tl
2782
2783 \@@_append_no_move:VV \l_@@_tmpa_tl \l_@@_tmpb_tl
2784 \group_end:
2785 }
2786 \cs_new_protected_nopar:Npn \spath_weld:Nnn #1#2#3
2787 {
2788 \@@_weld:nn {#2}{#3}
2789 \tl_set_eq:NN #1 \g_@@_output_tl
2790 \tl_gclear:N \g_@@_output_tl
2791 }
2792 \cs_generate_variant:Nn \spath_weld:Nnn {NVV,NVn}
2793 \cs_new_protected_nopar:Npn \spath_weld:Nn #1#2
2794 {
2795 \spath_weld:NVn #1#1{#2}
2796 }
2797 \cs_generate_variant:Nn \spath_weld:Nn {NV, Nv, cV, cv}
2798 \cs_new_protected_nopar:Npn \spath_gweld:Nnn #1#2#3
2799 {
2800 \@@_weld:nn {#2}{#3}
2801 \tl_gset_eq:NN #1 \g_@@_output_tl
2802 \tl_gclear:N \g_@@_output_tl
2803 }
2804 \cs_generate_variant:Nn \spath_gweld:Nnn {NVV, NVn}
2805 \cs_new_protected_nopar:Npn \spath_gweld:Nn #1#2
2806 {
2807 \spath_gweld:NVn #1#1{#2}
2808 }
2809 \cs_generate_variant:Nn \spath_gweld:Nn {NV, Nv, cV, cv}
2810 % \end{macrocode}
2811 % \end{macro}
2812 %
2813 %
2814 % \begin{macro}[internal]{
2815 % \spath_append_no_move:Nnn,
2816 % \spath_append_no_move:Nn,
2817 % \spath_gappend_no_move:Nnn,
2818 % \spath_gappend_no_move:Nn,
2819 % }
2820 % Append the path from the second \Verb+spath+ to the first, removing
2821 % the adjoining move if neither path has a rectangle either side of the join or if the first path isn't closed.
2822 % \begin{macrocode}
2823 \cs_new_protected_nopar:Npn \@@_append_no_move:nn #1#2
2824 {
2825 \group_begin:
2826 \tl_set:Nn \l_@@_tmpa_tl {#1}
2827 \tl_set:Nn \l_@@_tmpb_tl {#2}
2828 \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpb_tl}
2829 \spath_finalaction:Nn \l_@@_tmpd_tl {#1}
2830 \bool_if:nT {
2831 ! \tl_if_eq_p:NN \l_@@_tmpd_tl \c_spath_closepath_tl
2832 &&
2833 ! \tl_if_eq_p:NN \l_@@_tmpd_tl \c_spath_rectcorner_tl
2834 &&
2835 \tl_if_eq_p:NN \l_@@_tmpc_tl \c_spath_moveto_tl
2836 }
2837 {
2838 \tl_set:Nx \l_@@_tmpb_tl {\tl_tail:N \l_@@_tmpb_tl}
2839 \tl_set:Nx \l_@@_tmpb_tl {\tl_tail:N \l_@@_tmpb_tl}
2840 \tl_set:Nx \l_@@_tmpb_tl {\tl_tail:N \l_@@_tmpb_tl}
2841 }
2842
2843 \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpb_tl
2844 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
2845 \group_end:
2846 }
2847 \cs_generate_variant:Nn \@@_append_no_move:nn {VV}
2848 \cs_new_protected_nopar:Npn \spath_append_no_move:Nnn #1#2#3
2849 {
2850 \@@_append_no_move:nn {#2}{#3}
2851 \tl_set_eq:NN #1 \g_@@_output_tl
2852 \tl_gclear:N \g_@@_output_tl
2853 }
2854 \cs_generate_variant:Nn \spath_append_no_move:Nnn {NVV, NVn, NnV}
2855 \cs_new_protected_nopar:Npn \spath_append_no_move:Nn #1#2
2856 {
2857 \spath_append_no_move:NVn #1#1{#2}
2858 }
2859 \cs_generate_variant:Nn \spath_append_no_move:Nn {NV, cv, Nv, cV}
2860 \cs_new_protected_nopar:Npn \spath_gappend_no_move:Nnn #1#2#3
2861 {
2862 \@@_append_no_move:nn {#2}{#3}
2863 \tl_gset_eq:NN #1 \g_@@_output_tl
2864 \tl_gclear:N \g_@@_output_tl
2865 }
2866 \cs_generate_variant:Nn \spath_gappend_no_move:Nnn {NVV, NVn}
2867 \cs_new_protected_nopar:Npn \spath_gappend_no_move:Nn #1#2
2868 {
2869 \spath_gappend_no_move:NVn #1#1{#2}
2870 }
2871 \cs_generate_variant:Nn \spath_gappend_no_move:Nn {NV, cv, Nv, cV}
2872 % \end{macrocode}
2873 % \end{macro}
2874 %
2875 % \begin{macro}[internal]{
2876 % \spath_append:Nnn,
2877 % \spath_append:Nn,
2878 % \spath_gappend:Nnn,
2879 % \spath_gappend:Nn,
2880 % }
2881 % Prepend the path from the second \Verb+spath+ to the first.
2882 % \begin{macrocode}
2883 \cs_new_protected_nopar:Npn \spath_append:Nnn #1#2#3
2884 {
2885 \tl_set:Nn #1 {#2}
2886 \tl_put_right:Nn #1 {#3}
2887 }
2888 \cs_generate_variant:Nn \spath_append:Nnn {NVV, NVn}
2889 \cs_new_protected_nopar:Npn \spath_append:Nn #1#2
2890 {
2891 \spath_append:NVn #1#1{#2}
2892 }
2893 \cs_generate_variant:Nn \spath_append:Nn {NV, Nv, cv, cV}
2894 \cs_new_protected_nopar:Npn \spath_gappend:Nnn #1#2#3
2895 {
2896 \tl_gset:Nn #1 {#2}
2897 \tl_gput_right:Nn #1 {#3}
2898 }
2899 \cs_generate_variant:Nn \spath_gappend:Nnn {NVV, NVn}
2900 \cs_new_protected_nopar:Npn \spath_gappend:Nn #1#2
2901 {
2902 \spath_gappend:NVn #1#1{#2}
2903 }
2904 \cs_generate_variant:Nn \spath_gappend:Nn {NV, Nv, cv, cV}
2905 % \end{macrocode}
2906 % \end{macro}
2907 %
2908 %
2909 % \begin{macro}[internal]{
2910 % \spath_prepend_no_move:Nnn,
2911 % \spath_prepend_no_move:Nn,
2912 % \spath_gprepend_no_move:Nnn,
2913 % \spath_gprepend_no_move:Nn,
2914 % }
2915 % Prepend the path from the second \Verb+spath+ to the first, removing
2916 % the adjoining move.
2917 % \begin{macrocode}
2918 \cs_new_protected_nopar:Npn \spath_prepend_no_move:Nnn #1#2#3
2919 {
2920 \spath_append_no_move:Nnn #1{#3}{#2}
2921 }
2922 \cs_generate_variant:Nn \spath_prepend_no_move:Nnn {NVV, NVn}
2923 \cs_new_protected_nopar:Npn \spath_prepend_no_move:Nn #1#2
2924 {
2925 \spath_prepend_no_move:NVn #1#1{#2}
2926 }
2927 \cs_generate_variant:Nn \spath_prepend_no_move:Nn {NV, cv}
2928 \cs_new_protected_nopar:Npn \spath_gprepend_no_move:Nnn #1#2#3
2929 {
2930 \spath_gappend_no_move:Nnn #1{#3}{#2}
2931 }
2932 \cs_generate_variant:Nn \spath_gprepend_no_move:Nnn {NVV, NVn}
2933 \cs_new_protected_nopar:Npn \spath_gprepend_no_move:Nn #1#2
2934 {
2935 \spath_gprepend_no_move:NVn #1#1{#2}
2936 }
2937 \cs_generate_variant:Nn \spath_gprepend_no_move:Nn {NV, cv}
2938 % \end{macrocode}
2939 % \end{macro}
2940 %
2941 % \begin{macro}[internal]{
2942 % \spath_prepend:Nnn,
2943 % \spath_prepend:Nn,
2944 % \spath_gprepend:Nnn,
2945 % \spath_gprepend:Nn
2946 % }
2947 % Prepend the path from the second \Verb+spath+ to the first.
2948 % \begin{macrocode}
2949 \cs_new_protected_nopar:Npn \spath_prepend:Nnn #1#2#3
2950 {
2951 \spath_append:Nnn #1{#3}{#2}
2952 }
2953 \cs_generate_variant:Nn \spath_prepend:Nnn {NVV, NVn}
2954 \cs_new_protected_nopar:Npn \spath_prepend:Nn #1#2
2955 {
2956 \spath_prepend:NVn #1#1{#2}
2957 }
2958 \cs_generate_variant:Nn \spath_prepend:Nn {NV}
2959 \cs_new_protected_nopar:Npn \spath_gprepend:Nnn #1#2#3
2960 {
2961 \spath_gappend:Nnn #1{#3}{#2}
2962 }
2963 \cs_generate_variant:Nn \spath_gprepend:Nnn {NVV, NVn}
2964 \cs_new_protected_nopar:Npn \spath_gprepend:Nn #1#2
2965 {
2966 \spath_gprepend:NVn #1#1{#2}
2967 }
2968 \cs_generate_variant:Nn \spath_gprepend:Nn {NV}
2969 % \end{macrocode}
2970 % \end{macro}
2971 %
2972 % \begin{macro}[internal]{
2973 % \spath_bake_round:Nn,
2974 % \spath_bake_round:N,
2975 % \spath_gbake_round:Nn,
2976 % \spath_gbake_round:N
2977 % }
2978 %
2979 % The corner rounding routine is applied quite late in the process of building a soft path so this ensures that it is done.
2980 %
2981 % \begin{macrocode}
2982 \cs_new_protected_nopar:Npn \@@_bake_round:n #1
2983 {
2984 \group_begin:
2985 \tl_set:Nn \l_@@_tmpa_tl {#1}
2986 \pgf@@@@processround \l_@@_tmpa_tl\l_@@_tmpb_tl
2987 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
2988 \group_end:
2989 }
2990 \cs_new_protected_nopar:Npn \spath_bake_round:Nn #1#2
2991 {
2992 \@@_bake_round:n {#2}
2993 \tl_set_eq:NN #1 \g_@@_output_tl
2994 \tl_gclear:N \g_@@_output_tl
2995 }
2996 \cs_generate_variant:Nn \spath_bake_round:Nn {NV}
2997 \cs_new_protected_nopar:Npn \spath_bake_round:N #1
2998 {
2999 \spath_bake_round:NV #1#1
3000 }
3001 \cs_generate_variant:Nn \spath_bake_round:N {c}
3002 \cs_new_protected_nopar:Npn \spath_gbake_round:Nn #1#2
3003 {
3004 \@@_bake_round:n {#2}
3005 \tl_gset_eq:NN #1 \g_@@_output_tl
3006 \tl_gclear:N \g_@@_output_tl
3007 }
3008 \cs_generate_variant:Nn \spath_gbake_round:Nn {NV}
3009 \cs_new_protected_nopar:Npn \spath_gbake_round:N #1
3010 {
3011 \spath_gbake_round:NV #1#1
3012 }
3013 \cs_generate_variant:Nn \spath_gbake_round:N {c}
3014 % \end{macrocode}
3015 % \end{macro}
3016 %
3017 % \begin{macro}[internal]{
3018 % \spath_bake_shorten:Nn,
3019 % \spath_bake_shorten:N,
3020 % \spath_gbake_shorten:Nn,
3021 % \spath_gbake_shorten:N
3022 % }
3023 %
3024 % The shortening routine is applied quite late in the process of building a soft path so this ensures that it is done.
3025 %
3026 % \begin{macrocode}
3027 \cs_new_protected_nopar:Npn \@@_bake_shorten:n #1
3028 {
3029 \group_begin:
3030 \tl_set:Nn \l_@@_tmpa_tl {#1}
3031 \pgfsyssoftpath@getcurrentpath\l_@@_tmpb_tl
3032 \pgfsyssoftpath@setcurrentpath\l_@@_tmpa_tl
3033 \pgf@prepare@end@of@path
3034 \pgf@prepare@start@of@path
3035 \pgfsyssoftpath@getcurrentpath\l_@@_tmpa_tl
3036 \pgfsyssoftpath@setcurrentpath\l_@@_tmpb_tl
3037 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
3038 \group_end:
3039 }
3040 \cs_new_protected_nopar:Npn \spath_bake_shorten:Nn #1#2
3041 {
3042 \@@_bake_shorten:n {#2}
3043 \tl_set_eq:NN #1 \g_@@_output_tl
3044 \tl_gclear:N \g_@@_output_tl
3045 }
3046 \cs_generate_variant:Nn \spath_bake_shorten:Nn {NV}
3047 \cs_new_protected_nopar:Npn \spath_bake_shorten:N #1
3048 {
3049 \spath_bake_shorten:NV #1#1
3050 }
3051 \cs_generate_variant:Nn \spath_bake_shorten:N {c}
3052 \cs_new_protected_nopar:Npn \spath_gbake_shorten:Nn #1#2
3053 {
3054 \@@_bake_shorten:n {#2}
3055 \tl_gset_eq:NN #1 \g_@@_output_tl
3056 \tl_gclear:N \g_@@_output_tl
3057 }
3058 \cs_generate_variant:Nn \spath_gbake_shorten:Nn {NV}
3059 \cs_new_protected_nopar:Npn \spath_gbake_shorten:N #1
3060 {
3061 \spath_gbake_shorten:NV #1#1
3062 }
3063 \cs_generate_variant:Nn \spath_gbake_shorten:N {c}
3064 % \end{macrocode}
3065 %
3066 % Shortening the path when it is baked can cause issues with arrows.
3067 % Putting an arrow in a path definition affects the path because the path gets shortened so that the arrow ends where the path was meant to end.
3068 % So an arrow affects the path definition, but the arrow is not itself part of the path so if an arrow is used when the path is defined and again when the path is used, the path will be shortened twice which might not be what is intended.
3069 % Therefore it is useful to have a way to disable the shortening and place an arrow tip at the actual end of the line.
3070 % The following code achieves that.
3071 %
3072 % Save the original command that computes the arrow shortening.
3073 % \begin{macrocode}
3074 \cs_set_eq:Nc \@@_pgf_arrow_compute_shortening:n {pgf@arrow@compute@shortening}
3075 % \end{macrocode}
3076 %
3077 % After \verb+\pgf@arrow@compute@shortening+ then \verb+\pgf@xa+ is the amount to shorten the line by, so we will be setting that to 0pt.
3078 % Then \verb+\pgf@xb+ is the length of the arrow head which is used to position the arrow and so before zeroing \verb+\pgf@xa+ we subtract it from \verb+\pgf@xb+ so that the arrow is placed so that its back point is at the current position.
3079 %
3080 % \begin{macrocode}
3081 \cs_new_nopar:Npn \@@_arrow_compute_shortening:n #1
3082 {
3083 \@@_pgf_arrow_compute_shortening:n {#1}
3084 \bool_if:NF \l_spath_arrow_shortening_bool
3085 {
3086 \dim_sub:cn {pgf@xb} {\dim_use:c {pgf@xa}}
3087 \dim_zero:c {pgf@xa}
3088 }
3089 }
3090
3091 \cs_set_eq:cN {pgf@arrow@compute@shortening} \@@_arrow_compute_shortening:n
3092 % \end{macrocode}
3093 %
3094 % \end{macro}
3095 %
3096 % \begin{macro}[internal]{
3097 % \spath_close:Nn,
3098 % \spath_close:N,
3099 % \spath_gclose:Nn,
3100 % \spath_gclose:N
3101 % }
3102 % Appends a close path to the end of the path.
3103 % \begin{macrocode}
3104 \cs_new_protected_nopar:Npn \@@_close:n #1
3105 {
3106 \group_begin:
3107 \tl_set:Nn \l_@@_tmpa_tl {#1}
3108 \spath_finalmovepoint:NV \l_@@_tmpb_tl \l_@@_tmpa_tl
3109 \tl_put_right:NV \l_@@_tmpa_tl \c_spath_closepath_tl
3110 \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpb_tl
3111 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
3112 \group_end:
3113 }
3114 \cs_generate_variant:Nn \@@_close:n {V}
3115 \cs_new_protected_nopar:Npn \spath_close:Nn #1#2
3116 {
3117 \@@_close:n {#2}
3118 \tl_set_eq:NN #1 \g_@@_output_tl
3119 \tl_gclear:N \g_@@_output_tl
3120 }
3121 \cs_generate_variant:Nn \spath_close:Nn {NV}
3122 \cs_new_protected_nopar:Npn \spath_close:N #1
3123 {
3124 \spath_close:NV #1#1
3125 }
3126 \cs_generate_variant:Nn \spath_close:N {c}
3127 \cs_new_protected_nopar:Npn \spath_gclose:Nn #1#2
3128 {
3129 \@@_close:n {#2}
3130 \tl_gset_eq:NN #1 \g_@@_output_tl
3131 \tl_gclear:N \g_@@_output_tl
3132 }
3133 \cs_generate_variant:Nn \spath_gclose:Nn {NV}
3134 \cs_new_protected_nopar:Npn \spath_gclose:N #1
3135 {
3136 \spath_gclose:NV #1#1
3137 }
3138 \cs_generate_variant:Nn \spath_gclose:N {c}
3139 % \end{macrocode}
3140 % \end{macro}
3141 %
3142 % \begin{macro}[internal]{
3143 % \spath_adjust_close:Nn,
3144 % \spath_adjust_close:N,
3145 % \spath_adjust_gclose:Nn,
3146 % \spath_adjust_gclose:N
3147 % }
3148 % This closes a path and adjusts the end point to be where the final move point (so where the close points to) is.
3149 % The intention is that this should be used if the two points are visually the same point but mathematically different.
3150 % \begin{macrocode}
3151 \cs_new_protected_nopar:Npn \@@_adjust_close:n #1
3152 {
3153 \group_begin:
3154 \tl_set:Nn \l_@@_tmpa_tl {#1}
3155 \spath_finalmovepoint:NV \l_@@_tmpb_tl \l_@@_tmpa_tl
3156 \spath_finalpoint:NV \l_@@_tmpc_tl \l_@@_tmpa_tl
3157 \tl_reverse:N \l_@@_tmpa_tl
3158 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
3159 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
3160 \tl_set:Nx \l_@@_tmpd_tl {\tl_head:N \l_@@_tmpa_tl}
3161 \tl_if_eq:NNT \l_@@_tmpd_tl \c_spath_curveto_tl
3162 {
3163 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
3164 \tl_clear:N \l_@@_tmpe_tl
3165 \tl_set:Nx \l_@@_tmpe_tl {
3166 {
3167 \dim_eval:n
3168 {
3169 \tl_item:Nn \l_@@_tmpa_tl {1}
3170 -
3171 \tl_item:Nn \l_@@_tmpc_tl {2}
3172 +
3173 \tl_item:Nn \l_@@_tmpb_tl {2}
3174 }
3175 }
3176 {
3177 \dim_eval:n
3178 {
3179 \tl_item:Nn \l_@@_tmpa_tl {2}
3180 -
3181 \tl_item:Nn \l_@@_tmpc_tl {1}
3182 +
3183 \tl_item:Nn \l_@@_tmpb_tl {1}
3184 }
3185 }
3186 }
3187 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
3188 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
3189 \tl_put_left:NV \l_@@_tmpa_tl \l_@@_tmpe_tl
3190 \tl_put_left:NV \l_@@_tmpa_tl \l_@@_tmpd_tl
3191 }
3192 \tl_reverse:N \l_@@_tmpa_tl
3193 \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpb_tl
3194 \tl_put_right:NV \l_@@_tmpa_tl \c_spath_closepath_tl
3195 \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpb_tl
3196 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
3197 \group_end:
3198 }
3199 \cs_generate_variant:Nn \@@_adjust_close:n {V}
3200 \cs_new_protected_nopar:Npn \spath_adjust_close:Nn #1#2
3201 {
3202 \@@_adjust_close:n {#2}
3203 \tl_set_eq:NN #1 \g_@@_output_tl
3204 \tl_gclear:N \g_@@_output_tl
3205 }
3206 \cs_generate_variant:Nn \spath_adjust_close:Nn {NV}
3207 \cs_new_protected_nopar:Npn \spath_adjust_close:N #1
3208 {
3209 \spath_adjust_close:NV #1#1
3210 }
3211 \cs_generate_variant:Nn \spath_adjust_close:N {c}
3212 \cs_new_protected_nopar:Npn \spath_adjust_gclose:Nn #1#2
3213 {
3214 \@@_adjust_close:n {#2}
3215 \tl_gset_eq:NN #1 \g_@@_output_tl
3216 \tl_gclear:N \g_@@_output_tl
3217 }
3218 \cs_generate_variant:Nn \spath_adjust_gclose:Nn {NV}
3219 \cs_new_protected_nopar:Npn \spath_adjust_gclose:N #1
3220 {
3221 \spath_adjust_gclose:NV #1#1
3222 }
3223 \cs_generate_variant:Nn \spath_adjust_gclose:N {c}
3224 % \end{macrocode}
3225 % \end{macro}
3226 %
3227 %
3228 % \begin{macro}[internal]{
3229 % \spath_open:Nn,
3230 % \spath_open:N,
3231 % \spath_gopen:Nn,
3232 % \spath_gopen:N
3233 % }
3234 % Removes all close paths from the path, replacing them by \Verb+lineto+ if they move any distance.
3235 % Rectangles are replaced by lines with the start/end at the lower left corner.
3236 % \begin{macrocode}
3237 \cs_new_protected_nopar:Npn \@@_open:n #1
3238 {
3239 \group_begin:
3240 \spath_replace_rectangles:Nn \l_@@_tmpa_tl {#1}
3241 \tl_clear:N \l_@@_tmpb_tl
3242 \bool_until_do:nn {
3243 \tl_if_empty_p:N \l_@@_tmpa_tl
3244 }
3245 {
3246 \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
3247 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
3248
3249 \token_case_meaning:NnF \l_@@_tmpc_tl
3250 {
3251 \c_spath_closepath_tl {
3252
3253 \bool_if:nF
3254 {
3255 \dim_compare_p:n
3256 {
3257 \l_@@_move_x_dim == \l_@@_tmpa_dim
3258 }
3259 &&
3260 \dim_compare_p:n
3261 {
3262 \l_@@_move_y_dim == \l_@@_tmpb_dim
3263 }
3264 }
3265 {
3266 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_lineto_tl
3267
3268 \tl_put_right:Nx \l_@@_tmpb_tl {
3269 { \dim_use:N \l_@@_move_x_dim }
3270 { \dim_use:N \l_@@_move_y_dim }
3271 }
3272 }
3273
3274 \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
3275 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
3276 \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
3277 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
3278 }
3279
3280 \c_spath_moveto_tl {
3281 \tl_put_right:NV \l_@@_tmpb_tl \l_@@_tmpc_tl
3282
3283 \dim_set:Nn \l_@@_move_x_dim {\tl_head:N \l_@@_tmpa_tl}
3284 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
3285 \dim_set:Nn \l_@@_move_y_dim {\tl_head:N \l_@@_tmpa_tl}
3286 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
3287
3288 \tl_put_right:Nx \l_@@_tmpb_tl {
3289 { \dim_use:N \l_@@_move_x_dim }
3290 { \dim_use:N \l_@@_move_y_dim }
3291 }
3292
3293 \dim_set_eq:NN \l_@@_tmpa_dim \l_@@_move_x_dim
3294 \dim_set_eq:NN \l_@@_tmpb_dim \l_@@_move_y_dim
3295 }
3296 }
3297 {
3298 \tl_put_right:NV \l_@@_tmpb_tl \l_@@_tmpc_tl
3299
3300 \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpa_tl}
3301 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
3302 \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpa_tl}
3303 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
3304
3305 \tl_put_right:Nx \l_@@_tmpb_tl {
3306 { \dim_use:N \l_@@_tmpa_dim }
3307 { \dim_use:N \l_@@_tmpb_dim }
3308 }
3309 }
3310 }
3311 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
3312 \group_end:
3313 }
3314 \cs_generate_variant:Nn \@@_open:n {V}
3315 \cs_new_protected_nopar:Npn \spath_open:Nn #1#2
3316 {
3317 \@@_open:n {#2}
3318 \tl_set_eq:NN #1 \g_@@_output_tl
3319 \tl_gclear:N \g_@@_output_tl
3320 }
3321 \cs_generate_variant:Nn \spath_open:Nn {NV}
3322 \cs_new_protected_nopar:Npn \spath_open:N #1
3323 {
3324 \spath_open:NV #1#1
3325 }
3326 \cs_new_protected_nopar:Npn \spath_gopen:Nn #1#2
3327 {
3328 \@@_open:n {#2}
3329 \tl_gset_eq:NN #1 \g_@@_output_tl
3330 \tl_gclear:N \g_@@_output_tl
3331 }
3332 \cs_generate_variant:Nn \spath_gopen:Nn {NV}
3333 \cs_new_protected_nopar:Npn \spath_gopen:N #1
3334 {
3335 \spath_gopen:NV #1#1
3336 }
3337 \cs_generate_variant:Nn \spath_open:N {c}
3338 \cs_generate_variant:Nn \spath_gopen:N {c}
3339 % \end{macrocode}
3340 % \end{macro}
3341 %
3342 % \begin{macro}[internal]{
3343 % \spath_replace_lines:Nn,
3344 % \spath_replace_lines:Nn,
3345 % \spath_replace_lines:Nn,
3346 % \spath_replace_lines:Nn,
3347 % }
3348 % Replace any line segments by B\'ezier curves.
3349 % \begin{macrocode}
3350 \cs_new_protected_nopar:Npn \@@_replace_lines:n #1
3351 {
3352 \group_begin:
3353 \tl_set:Nn \l_@@_tmpa_tl {#1}
3354 \tl_clear:N \l_@@_tmpb_tl
3355 \dim_set:Nn \l_@@_tmpa_dim {0pt}
3356 \dim_set:Nn \l_@@_tmpb_dim {0pt}
3357
3358 \bool_do_until:nn
3359 {
3360 \tl_if_empty_p:N \l_@@_tmpa_tl
3361 }
3362 {
3363 \tl_set:Nx \l_@@_tmpc_tl {\tl_item:Nn \l_@@_tmpa_tl {1}}
3364 \tl_set:Nx \l_@@_tmpd_tl {\tl_item:Nn \l_@@_tmpa_tl {2}}
3365 \tl_set:Nx \l_@@_tmpe_tl {\tl_item:Nn \l_@@_tmpa_tl {3}}
3366
3367 \tl_if_eq:NNTF \l_@@_tmpc_tl \c_spath_lineto_tl
3368 {
3369 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetoa_tl
3370 \tl_put_right:Nx \l_@@_tmpb_tl
3371 {
3372 {
3373 \fp_to_dim:n
3374 {
3375 2/3 * (\l_@@_tmpa_dim)
3376 +
3377 1/3 * (\l_@@_tmpd_tl)
3378 }
3379 }
3380 }
3381 \tl_put_right:Nx \l_@@_tmpb_tl
3382 {
3383 {
3384 \fp_to_dim:n
3385 {
3386 2/3 * (\l_@@_tmpb_dim)
3387 +
3388 1/3 * (\l_@@_tmpe_tl)
3389 }
3390 }
3391 }
3392 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetob_tl
3393 \tl_put_right:Nx \l_@@_tmpb_tl
3394 {
3395 {
3396 \fp_to_dim:n
3397 {
3398 1/3 * (\l_@@_tmpa_dim)
3399 +
3400 2/3 * (\l_@@_tmpd_tl)
3401 }
3402 }
3403 }
3404 \tl_put_right:Nx \l_@@_tmpb_tl
3405 {
3406 {
3407 \fp_to_dim:n
3408 {
3409 1/3 * (\l_@@_tmpb_dim)
3410 +
3411 2/3 * (\l_@@_tmpe_tl)
3412 }
3413 }
3414 }
3415 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curveto_tl
3416 \@@_tl_put_right_braced:NV \l_@@_tmpb_tl \l_@@_tmpd_tl
3417 \@@_tl_put_right_braced:NV \l_@@_tmpb_tl \l_@@_tmpe_tl
3418 }
3419 {
3420 \tl_put_right:NV \l_@@_tmpb_tl \l_@@_tmpc_tl
3421 \@@_tl_put_right_braced:NV \l_@@_tmpb_tl \l_@@_tmpd_tl
3422 \@@_tl_put_right_braced:NV \l_@@_tmpb_tl \l_@@_tmpe_tl
3423 }
3424
3425 \dim_set:Nn \l_@@_tmpa_dim {\l_@@_tmpd_tl}
3426 \dim_set:Nn \l_@@_tmpb_dim {\l_@@_tmpe_tl}
3427
3428 \prg_replicate:nn {3}
3429 {
3430 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
3431 }
3432 }
3433 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
3434 \group_end:
3435 }
3436 \cs_generate_variant:Nn \@@_replace_lines:n {V}
3437 \cs_new_protected_nopar:Npn \spath_replace_lines:Nn #1#2
3438 {
3439 \@@_replace_lines:n {#2}
3440 \tl_set_eq:NN #1 \g_@@_output_tl
3441 \tl_gclear:N \g_@@_output_tl
3442 }
3443 \cs_generate_variant:Nn \spath_replace_lines:Nn {NV, cV, cv, Nv}
3444 \cs_new_protected_nopar:Npn \spath_replace_lines:N #1
3445 {
3446 \spath_replace_lines:NV #1#1
3447 }
3448 \cs_generate_variant:Nn \spath_replace_lines:N {c}
3449 \cs_new_protected_nopar:Npn \spath_greplace_lines:Nn #1#2
3450 {
3451 \@@_replace_lines:n {#2}
3452 \tl_gset_eq:NN #1 \g_@@_output_tl
3453 \tl_gclear:N \g_@@_output_tl
3454 }
3455 \cs_generate_variant:Nn \spath_greplace_lines:Nn {NV, cV, cv, Nv}
3456 \cs_new_protected_nopar:Npn \spath_greplace_lines:N #1
3457 {
3458 \spath_greplace_lines:NV #1#1
3459 }
3460 \cs_generate_variant:Nn \spath_greplace_lines:N {c}
3461 % \end{macrocode}
3462 % \end{macro}
3463 %
3464 % \begin{macro}[internal]{
3465 % \spath_replace_rectangles:Nn,
3466 % \spath_replace_rectangles:Nn,
3467 % \spath_replace_rectangles:Nn,
3468 % \spath_replace_rectangles:Nn,
3469 % }
3470 % Replace any rectangle components by lines.
3471 % \begin{macrocode}
3472 \cs_new_protected_nopar:Npn \@@_replace_rectangles:n #1
3473 {
3474 \group_begin:
3475 \tl_set:Nn \l_@@_tmpa_tl {#1}
3476 \tl_clear:N \l_@@_tmpb_tl
3477
3478 \bool_do_until:nn
3479 {
3480 \tl_if_empty_p:N \l_@@_tmpa_tl
3481 }
3482 {
3483 \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl }
3484 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl }
3485 \tl_set:Nx \l_@@_tmpd_tl {\tl_head:N \l_@@_tmpa_tl }
3486 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl }
3487 \tl_set:Nx \l_@@_tmpe_tl {\tl_head:N \l_@@_tmpa_tl }
3488 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl }
3489
3490 \tl_if_eq:NNTF \l_@@_tmpc_tl \c_spath_rectcorner_tl
3491 {
3492
3493 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl }
3494 \dim_set:Nn \l_@@_tmpa_dim
3495 {
3496 \tl_item:Nn \l_@@_tmpa_tl {1}
3497 }
3498 \dim_set:Nn \l_@@_tmpb_dim
3499 {
3500 \tl_item:Nn \l_@@_tmpa_tl {2}
3501 }
3502
3503 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl }
3504 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl }
3505
3506 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_moveto_tl
3507 \@@_tl_put_right_braced:NV \l_@@_tmpb_tl \l_@@_tmpd_tl
3508 \@@_tl_put_right_braced:NV \l_@@_tmpb_tl \l_@@_tmpe_tl
3509
3510 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_lineto_tl
3511 \tl_put_right:Nx \l_@@_tmpb_tl
3512 {
3513 {
3514 \fp_to_dim:n { \l_@@_tmpd_tl + \l_@@_tmpa_dim }
3515 }
3516 }
3517 \@@_tl_put_right_braced:NV \l_@@_tmpb_tl \l_@@_tmpe_tl
3518
3519 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_lineto_tl
3520 \tl_put_right:Nx \l_@@_tmpb_tl
3521 {
3522 {
3523 \fp_to_dim:n { \l_@@_tmpd_tl + \l_@@_tmpa_dim }
3524 }
3525 }
3526 \tl_put_right:Nx \l_@@_tmpb_tl
3527 {
3528 {
3529 \fp_to_dim:n { \l_@@_tmpe_tl + \l_@@_tmpb_dim }
3530 }
3531 }
3532
3533 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_lineto_tl
3534 \@@_tl_put_right_braced:NV \l_@@_tmpb_tl \l_@@_tmpd_tl
3535 \tl_put_right:Nx \l_@@_tmpb_tl
3536 {
3537 {
3538 \fp_to_dim:n { \l_@@_tmpe_tl + \l_@@_tmpb_dim }
3539 }
3540 }
3541
3542 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_closepath_tl
3543 \@@_tl_put_right_braced:NV \l_@@_tmpb_tl \l_@@_tmpd_tl
3544 \@@_tl_put_right_braced:NV \l_@@_tmpb_tl \l_@@_tmpe_tl
3545
3546 }
3547 {
3548 \tl_put_right:NV \l_@@_tmpb_tl \l_@@_tmpc_tl
3549 \@@_tl_put_right_braced:NV \l_@@_tmpb_tl \l_@@_tmpd_tl
3550 \@@_tl_put_right_braced:NV \l_@@_tmpb_tl \l_@@_tmpe_tl
3551 }
3552 }
3553 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
3554 \group_end:
3555 }
3556 \cs_generate_variant:Nn \@@_replace_rectangles:n {V}
3557 \cs_new_protected_nopar:Npn \spath_replace_rectangles:Nn #1#2
3558 {
3559 \@@_replace_rectangles:n {#2}
3560 \tl_set_eq:NN #1 \g_@@_output_tl
3561 \tl_gclear:N \g_@@_output_tl
3562 }
3563 \cs_generate_variant:Nn \spath_replace_rectangles:Nn {NV, cV, cv, Nv}
3564 \cs_new_protected_nopar:Npn \spath_replace_rectangles:N #1
3565 {
3566 \spath_replace_rectangles:NV #1#1
3567 }
3568 \cs_generate_variant:Nn \spath_replace_rectangles:N {c}
3569 \cs_new_protected_nopar:Npn \spath_greplace_rectangles:Nn #1#2
3570 {
3571 \@@_replace_rectangles:n {#2}
3572 \tl_gset_eq:NN #1 \g_@@_output_tl
3573 \tl_gclear:N \g_@@_output_tl
3574 }
3575 \cs_generate_variant:Nn \spath_greplace_rectangles:Nn {NV, cV, cv, Nv}
3576 \cs_new_protected_nopar:Npn \spath_greplace_rectangles:N #1
3577 {
3578 \spath_greplace_rectangles:NV #1#1
3579 }
3580 \cs_generate_variant:Nn \spath_greplace_rectangles:N {c}
3581 % \end{macrocode}
3582 % \end{macro}
3583 %
3584 % \begin{macro}[internal]{
3585 % \spath_remove_empty_components:Nn,
3586 % \spath_remove_empty_components:N,
3587 % \spath_gremove_empty_components:Nn,
3588 % \spath_gremove_empty_components:N
3589 % }
3590 % Remove any component that is simply a moveto.
3591 % \begin{macrocode}
3592 \cs_new_protected_nopar:Npn \@@_remove_empty_components:n #1
3593 {
3594 \group_begin:
3595 \spath_components_to_seq:Nn \l_@@_tmpa_seq {#1}
3596 \tl_clear:N \l_@@_tmpa_tl
3597 \seq_map_inline:Nn \l_@@_tmpa_seq
3598 {
3599 \int_compare:nF
3600 {
3601 \tl_count:n {##1} == 3
3602 }
3603 {
3604 \tl_put_right:Nn \l_@@_tmpa_tl {##1}
3605 }
3606 }
3607 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
3608 \group_end:
3609 }
3610 \cs_new_protected_nopar:Npn \spath_remove_empty_components:Nn #1#2
3611 {
3612 \@@_remove_empty_components:n {#2}
3613 \tl_set_eq:NN #1 \g_@@_output_tl
3614 \tl_gclear:N \g_@@_output_tl
3615 }
3616 \cs_generate_variant:Nn \spath_remove_empty_components:Nn {NV}
3617 \cs_new_protected_nopar:Npn \spath_remove_empty_components:N #1
3618 {
3619 \spath_remove_empty_components:NV #1#1
3620 }
3621 \cs_generate_variant:Nn \spath_remove_empty_components:N {c}
3622 \cs_new_protected_nopar:Npn \spath_gremove_empty_components:Nn #1#2
3623 {
3624 \@@_remove_empty_components:n {#2}
3625 \tl_gset_eq:NN #1 \g_@@_output_tl
3626 \tl_gclear:N \g_@@_output_tl
3627 }
3628 \cs_generate_variant:Nn \spath_gremove_empty_components:Nn {NV}
3629 \cs_new_protected_nopar:Npn \spath_gremove_empty_components:N #1
3630 {
3631 \spath_gremove_empty_components:NV #1#1
3632 }
3633 \cs_generate_variant:Nn \spath_gremove_empty_components:N {c}
3634 % \end{macrocode}
3635 % \end{macro}
3636 %
3637 % \begin{macro}[internal]{\spath_if_eq:nn}
3638 % Test if two soft paths are equal, we allow a little tolerance on the calculations.
3639 % \begin{macrocode}
3640 \prg_new_protected_conditional:Npnn \spath_if_eq:nn #1#2 { T, F, TF }
3641 {
3642 \group_begin:
3643 \tl_set:Nn \l_@@_tmpa_tl {#1}
3644 \tl_set:Nn \l_@@_tmpb_tl {#2}
3645 \bool_gset_true:N \g_@@_tmpa_bool
3646 \int_compare:nNnTF
3647 {\tl_count:N \l_@@_tmpa_tl}
3648 =
3649 {\tl_count:N \l_@@_tmpb_tl}
3650 {
3651 \int_step_inline:nnnn {1} {3} {\tl_count:N \l_@@_tmpa_tl}
3652 {
3653 \tl_set:Nx \l_@@_tmpc_tl {\tl_item:Nn \l_@@_tmpa_tl {##1}}
3654 \tl_set:Nx \l_@@_tmpd_tl {\tl_item:Nn \l_@@_tmpb_tl {##1}}
3655 \tl_if_eq:NNF \l_@@_tmpc_tl \l_@@_tmpd_tl
3656 {
3657 \bool_gset_false:N \g_@@_tmpa_bool
3658 }
3659 \dim_set:Nn \l_@@_tmpa_dim {\tl_item:Nn \l_@@_tmpa_tl {##1+1}}
3660 \dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpb_tl {##1+1}}
3661 \dim_compare:nF
3662 {
3663 \dim_abs:n
3664 {
3665 \l_@@_tmpa_dim - \l_@@_tmpb_dim
3666 }
3667 < 0.001pt
3668 }
3669 {
3670 \bool_gset_false:N \g_@@_tmpa_bool
3671 }
3672 \dim_set:Nn \l_@@_tmpa_dim {\tl_item:Nn \l_@@_tmpa_tl {##1+2}}
3673 \dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpb_tl {##1+2}}
3674 \dim_compare:nF
3675 {
3676 \dim_abs:n
3677 {
3678 \l_@@_tmpa_dim - \l_@@_tmpb_dim
3679 }
3680 < 0.001pt
3681 }
3682 {
3683 \bool_gset_false:N \g_@@_tmpa_bool
3684 }
3685 }
3686 }
3687 {
3688 \bool_gset_false:N \g_@@_tmpa_bool
3689 }
3690 \group_end:
3691 \bool_if:NTF \g_@@_tmpa_bool
3692 {
3693 \prg_return_true:
3694 }
3695 {
3696 \prg_return_false:
3697 }
3698 }
3699 \prg_generate_conditional_variant:Nnn \spath_if_eq:nn {VV, Vn, nV, vv} {TF, T, F}
3700 % \end{macrocode}
3701 % \end{macro}
3702 %
3703 % \subsection{Splitting Commands}
3704 %
3705 % \begin{macro}[internal]{
3706 % \spath_split_curve:NNnn,
3707 % \spath_gsplit_curve:NNnn
3708 % }
3709 % Splits a Bezier cubic into pieces, storing the pieces in the first two arguments.
3710 % \begin{macrocode}
3711 \cs_new_protected_nopar:Npn \@@_split_curve:nn #1#2
3712 {
3713 \group_begin:
3714 \tl_set_eq:NN \l_@@_tmpa_tl \c_spath_moveto_tl
3715 \tl_put_right:Nx \l_@@_tmpa_tl {
3716 {\tl_item:nn {#1} {2}}
3717 {\tl_item:nn {#1} {3}}
3718 }
3719 \tl_put_right:NV \l_@@_tmpa_tl \c_spath_curvetoa_tl
3720 \tl_put_right:Nx \l_@@_tmpa_tl
3721 {
3722 {\fp_to_dim:n
3723 {
3724 (1 - #2) * \tl_item:nn {#1} {2} + (#2) * \tl_item:nn {#1} {5}
3725 }}
3726 {\fp_to_dim:n
3727 {
3728 (1 - #2) * \tl_item:nn {#1} {3} + (#2) * \tl_item:nn {#1} {6}
3729 }}
3730 }
3731
3732 \tl_put_right:NV \l_@@_tmpa_tl \c_spath_curvetob_tl
3733 \tl_put_right:Nx \l_@@_tmpa_tl
3734 {
3735 {\fp_to_dim:n
3736 {
3737 (1 - #2)^2 * \tl_item:nn {#1} {2}
3738 + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {5}
3739 + (#2)^2 * \tl_item:nn {#1} {8}
3740 }}
3741 {\fp_to_dim:n
3742 {
3743 (1 - #2)^2 * \tl_item:nn {#1} {3}
3744 + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {6}
3745 + (#2)^2 * \tl_item:nn {#1} {9}
3746 }}
3747 }
3748
3749 \tl_put_right:NV \l_@@_tmpa_tl \c_spath_curveto_tl
3750 \tl_put_right:Nx \l_@@_tmpa_tl
3751 {
3752 {\fp_to_dim:n
3753 {
3754 (1 - #2)^3 * \tl_item:nn {#1} {2}
3755 + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {5}
3756 + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {8}
3757 + (#2)^3 * \tl_item:nn {#1} {11}
3758 }}
3759 {\fp_to_dim:n
3760 {
3761 (1 - #2)^3 * \tl_item:nn {#1} {3}
3762 + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {6}
3763 + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {9}
3764 + (#2)^3 * \tl_item:nn {#1} {12}
3765 }}
3766 }
3767
3768 \tl_gclear:N \g_@@_output_tl
3769 \@@_tl_gput_right_braced:NV \g_@@_output_tl \l_@@_tmpa_tl
3770
3771 \tl_clear:N \l_@@_tmpa_tl
3772 \tl_set_eq:NN \l_@@_tmpa_tl \c_spath_moveto_tl
3773 \tl_put_right:Nx \l_@@_tmpa_tl
3774 {
3775 {\fp_to_dim:n
3776 {
3777 (1 - #2)^3 * \tl_item:nn {#1} {2}
3778 + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {5}
3779 + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {8}
3780 + (#2)^3 * \tl_item:nn {#1} {11}
3781 }}
3782 {\fp_to_dim:n
3783 {
3784 (1 - #2)^3 * \tl_item:nn {#1} {3}
3785 + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {6}
3786 + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {9}
3787 + (#2)^3 * \tl_item:nn {#1} {12}
3788 }}
3789 }
3790
3791 \tl_put_right:NV \l_@@_tmpa_tl \c_spath_curvetoa_tl
3792 \tl_put_right:Nx \l_@@_tmpa_tl
3793 {
3794 {\fp_to_dim:n
3795 {
3796 (1 - #2)^2 * \tl_item:nn {#1} {5}
3797 + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {8}
3798 + (#2)^2 * \tl_item:nn {#1} {11}
3799 }}
3800 {\fp_to_dim:n
3801 {
3802 (1 - #2)^2 * \tl_item:nn {#1} {6}
3803 + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {9}
3804 + (#2)^2 * \tl_item:nn {#1} {12}
3805 }}
3806 }
3807 \tl_put_right:NV \l_@@_tmpa_tl \c_spath_curvetob_tl
3808 \tl_put_right:Nx \l_@@_tmpa_tl
3809 {
3810 {\fp_to_dim:n
3811 {
3812 (1 - #2) * \tl_item:nn {#1} {8} + (#2) * \tl_item:nn {#1} {11}
3813 }}
3814 {\fp_to_dim:n
3815 {
3816 (1 - #2) * \tl_item:nn {#1} {9} + (#2) * \tl_item:nn {#1} {12}
3817 }}
3818 }
3819 \tl_put_right:NV \l_@@_tmpa_tl \c_spath_curveto_tl
3820 \tl_put_right:Nx \l_@@_tmpa_tl {
3821 {\tl_item:nn {#1} {11}}
3822 {\tl_item:nn {#1} {12}}
3823 }
3824
3825 \@@_tl_gput_right_braced:NV \g_@@_output_tl \l_@@_tmpa_tl
3826 \group_end:
3827 }
3828 \cs_generate_variant:Nn \@@_split_curve:nn {nv, nV}
3829 \cs_new_protected_nopar:Npn \spath_split_curve:NNnn #1#2#3#4
3830 {
3831 \@@_split_curve:nn {#3}{#4}
3832 \tl_set:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
3833 \tl_set:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
3834 \tl_gclear:N \g_@@_output_tl
3835 }
3836 \cs_generate_variant:Nn \spath_split_curve:NNnn {NNnV, NNVn, NNVV}
3837 \cs_new_protected_nopar:Npn \spath_gsplit_curve:NNnn #1#2#3#4
3838 {
3839 \@@_split_curve:nn {#3}{#4}
3840 \tl_gset:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
3841 \tl_gset:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
3842 \tl_gclear:N \g_@@_output_tl
3843 }
3844 \cs_generate_variant:Nn \spath_gsplit_curve:NNnn {NNnV, NNVn, NNVV}
3845 % \end{macrocode}
3846 % \end{macro}
3847 %
3848 %
3849 % \begin{macro}[internal]{
3850 % \spath_maybe_split_curve:Nn,
3851 % \spath_maybe_gsplit_curve:Nn,
3852 % }
3853 % Possibly splits a bezier curve to ensure that the pieces don't self-intersect.
3854 % Figuring out whether a Bezier cubic self intersects is apparently a difficult problem so we don't bother.
3855 % We compute a point such that if there is an intersection then it lies on either side of the point.
3856 % I don't recall where the formula came from!
3857 % \begin{macrocode}
3858 \cs_new_protected_nopar:Npn \@@_maybe_split_curve:n #1
3859 {
3860 \group_begin:
3861 \fp_set:Nn \l_@@_tmpa_fp
3862 {
3863 (
3864 \tl_item:nn {#1} {3}
3865 - 3 * \tl_item:nn {#1} {6}
3866 + 3 * \tl_item:nn {#1} {9}
3867 - \tl_item:nn {#1} {12}
3868 )
3869 *
3870 (3 * \tl_item:nn {#1} {8} - 3 * \tl_item:nn {#1} {11})
3871 -
3872 (
3873 \tl_item:nn {#1} {2}
3874 - 3 * \tl_item:nn {#1} {5}
3875 + 3 * \tl_item:nn {#1} {8}
3876 - \tl_item:nn {#1} {11}
3877 )
3878 *
3879 (3 * \tl_item:nn {#1} {9} - 3 * \tl_item:nn {#1} {12})
3880 }
3881 \fp_set:Nn \l_@@_tmpb_fp
3882 {
3883 (
3884 \tl_item:nn {#1} {2}
3885 - 3 * \tl_item:nn {#1} {5}
3886 + 3 * \tl_item:nn {#1} {8}
3887 - \tl_item:nn {#1} {11}
3888 )
3889 *
3890 (
3891 3 * \tl_item:nn {#1} {6}
3892 - 6 * \tl_item:nn {#1} {9}
3893 + 3 * \tl_item:nn {#1} {12}
3894 )
3895 -
3896 (
3897 \tl_item:nn {#1} {3}
3898 - 3 * \tl_item:nn {#1} {6}
3899 + 3 * \tl_item:nn {#1} {9}
3900 - \tl_item:nn {#1} {12}
3901 )
3902 *
3903 (
3904 3 * \tl_item:nn {#1} {5}
3905 - 6 * \tl_item:nn {#1} {8}
3906 + 3 * \tl_item:nn {#1} {11}
3907 )
3908 }
3909 \fp_compare:nTF
3910 {
3911 \l_@@_tmpb_fp != 0
3912 }
3913 {
3914 \fp_set:Nn \l_@@_tmpa_fp {.5 * \l_@@_tmpa_fp / \l_@@_tmpb_fp}
3915 \bool_if:nTF
3916 {
3917 \fp_compare_p:n {0 < \l_@@_tmpa_fp}
3918 &&
3919 \fp_compare_p:n {\l_@@_tmpa_fp < 1}
3920 }
3921 {
3922 \@@_split_curve:nV {#1} \l_@@_tmpa_fp
3923 }
3924 {
3925 \tl_gset:Nn \g_@@_output_tl { {#1} {} }
3926 }
3927 }
3928 {
3929 \tl_gset:Nn \g_@@_output_tl { {#1} {} }
3930 }
3931 \group_end:
3932 }
3933 \cs_new_protected_nopar:Npn \spath_maybe_split_curve:NNn #1#2#3
3934 {
3935 \@@_maybe_split_curve:n {#3}
3936 \tl_set:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
3937 \tl_set:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
3938 \tl_gclear:N \g_@@_output_tl
3939 }
3940 \cs_generate_variant:Nn \spath_maybe_split_curve:NNn {NNn, NNV }
3941 \cs_new_protected_nopar:Npn \spath_maybe_gsplit_curve:NNn #1#2#3
3942 {
3943 \@@_maybe_split_curve:n {#3}
3944 \tl_gset:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
3945 \tl_gset:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
3946 \tl_gclear:N \g_@@_output_tl
3947 }
3948 \cs_generate_variant:Nn \spath_maybe_gsplit_curve:NNn {NNn, NNV}
3949 % \end{macrocode}
3950 % \end{macro}
3951 %
3952 % \begin{macro}[internal]{
3953 % \spath_split_curves:Nn,
3954 % \spath_gsplit_curves:Nn,
3955 % }
3956 % Slurp through the path ensuring that beziers don't self-intersect.
3957 % \begin{macrocode}
3958 \cs_new_protected_nopar:Npn \@@_split_curves:n #1
3959 {
3960 \group_begin:
3961 \tl_set:Nn \l_@@_tmpa_tl {#1}
3962 \tl_clear:N \l_@@_tmpb_tl
3963 \tl_clear:N \l_@@_tmpc_tl
3964 \bool_do_until:nn
3965 {
3966 \tl_if_empty_p:N \l_@@_tmpa_tl
3967 }
3968 {
3969 \tl_set:Nx \l_@@_tmpc_tl {\tl_head:N \l_@@_tmpa_tl}
3970 \token_case_meaning:NnF \l_@@_tmpc_tl
3971 {
3972 \c_spath_curvetoa_tl
3973 {
3974 \tl_clear:N \l_@@_tmpd_tl
3975 \tl_set_eq:NN \l_@@_tmpd_tl \c_spath_moveto_tl
3976 \tl_put_right:Nx \l_@@_tmpd_tl
3977 {
3978 { \dim_use:N \l_@@_tmpa_dim }
3979 { \dim_use:N \l_@@_tmpb_dim }
3980 }
3981 \dim_set:Nn \l_@@_tmpa_dim
3982 {
3983 \tl_item:Nn \l_@@_tmpa_tl {8}
3984 }
3985 \dim_set:Nn \l_@@_tmpb_dim
3986 {
3987 \tl_item:Nn \l_@@_tmpa_tl {9}
3988 }
3989 \prg_replicate:nn {3}
3990 {
3991 \tl_put_right:Nx \l_@@_tmpd_tl
3992 {
3993 \tl_item:Nn \l_@@_tmpa_tl {1}
3994 {\tl_item:Nn \l_@@_tmpa_tl {2}}
3995 {\tl_item:Nn \l_@@_tmpa_tl {3}}
3996 }
3997 \prg_replicate:nn {3}
3998 {
3999 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
4000 }
4001 }
4002
4003 \spath_maybe_split_curve:NNV
4004 \l_@@_tmpd_tl
4005 \l_@@_tmpe_tl
4006 \l_@@_tmpd_tl
4007 \prg_replicate:nn {3}
4008 {
4009 \tl_set:Nx \l_@@_tmpd_tl {\tl_tail:N \l_@@_tmpd_tl}
4010 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl}
4011 }
4012 \tl_put_right:NV \l_@@_tmpb_tl \l_@@_tmpd_tl
4013 \tl_put_right:NV \l_@@_tmpb_tl \l_@@_tmpe_tl
4014 }
4015 }
4016 {
4017 \dim_set:Nn \l_@@_tmpa_dim
4018 {
4019 \tl_item:Nn \l_@@_tmpa_tl {2}
4020 }
4021 \dim_set:Nn \l_@@_tmpb_dim
4022 {
4023 \tl_item:Nn \l_@@_tmpa_tl {3}
4024 }
4025 \tl_put_right:Nx \l_@@_tmpb_tl
4026 {
4027 \tl_item:Nn \l_@@_tmpa_tl {1}
4028 {\tl_item:Nn \l_@@_tmpa_tl {2}}
4029 {\tl_item:Nn \l_@@_tmpa_tl {3}}
4030 }
4031 \prg_replicate:nn {3}
4032 {
4033 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
4034 }
4035 }
4036 }
4037 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
4038 \group_end:
4039 }
4040 \cs_new_protected_nopar:Npn \spath_split_curves:Nn #1#2
4041 {
4042 \@@_split_curves:n {#2}
4043 \tl_set_eq:NN #1 \g_@@_output_tl
4044 \tl_gclear:N \g_@@_output_tl
4045 }
4046 \cs_generate_variant:Nn \spath_split_curves:Nn {NV, cV, cn, cv }
4047 \cs_new_protected_nopar:Npn \spath_split_curves:N #1
4048 {
4049 \spath_split_curves:NV #1#1
4050 }
4051 \cs_generate_variant:Nn \spath_split_curves:N {c}
4052 \cs_new_protected_nopar:Npn \spath_gsplit_curves:Nn #1#2
4053 {
4054 \@@_split_curves:n {#2}
4055 \tl_gset_eq:NN #1 \g_@@_output_tl
4056 \tl_gclear:N \g_@@_output_tl
4057 }
4058 \cs_generate_variant:Nn \spath_gsplit_curves:Nn {NV, cV, cn, cv }
4059 \cs_new_protected_nopar:Npn \spath_gsplit_curves:N #1
4060 {
4061 \spath_gsplit_curves:NV #1#1
4062 }
4063 \cs_generate_variant:Nn \spath_gsplit_curves:N {c}
4064 % \end{macrocode}
4065 % \end{macro}
4066 %
4067 % \begin{macro}[internal]{
4068 % \spath_split_line:NNnn,
4069 % \spath_gsplit_line:NNnn
4070 % }
4071 % Splits a line segment.
4072 % \begin{macrocode}
4073 \cs_new_protected_nopar:Npn \@@_split_line:nn #1#2
4074 {
4075 \group_begin:
4076 \tl_set_eq:NN \l_@@_tmpa_tl \c_spath_moveto_tl
4077 \tl_put_right:Nx \l_@@_tmpa_tl {
4078 {\tl_item:nn {#1} {2}}
4079 {\tl_item:nn {#1} {3}}
4080 }
4081 \tl_put_right:NV \l_@@_tmpa_tl \c_spath_lineto_tl
4082 \tl_put_right:Nx \l_@@_tmpa_tl
4083 {
4084 {\fp_to_dim:n
4085 {
4086 (1 - #2) * \tl_item:nn {#1} {2} + (#2) * \tl_item:nn {#1} {5}
4087 }}
4088 {\fp_to_dim:n
4089 {
4090 (1 - #2) * \tl_item:nn {#1} {3} + (#2) * \tl_item:nn {#1} {6}
4091 }}
4092 }
4093 \tl_gclear:N \g_@@_output_tl
4094 \@@_tl_gput_right_braced:NV \g_@@_output_tl \l_@@_tmpa_tl
4095
4096 \tl_clear:N \l_@@_tmpa_tl
4097 \tl_set_eq:NN \l_@@_tmpa_tl \c_spath_moveto_tl
4098 \tl_put_right:Nx \l_@@_tmpa_tl
4099 {
4100 {\fp_to_dim:n
4101 {
4102 (1 - #2) * \tl_item:nn {#1} {2} + (#2) * \tl_item:nn {#1} {5}
4103 }}
4104 {\fp_to_dim:n
4105 {
4106 (1 - #2) * \tl_item:nn {#1} {3} + (#2) * \tl_item:nn {#1} {6}
4107 }}
4108 }
4109 \tl_put_right:NV \l_@@_tmpa_tl \c_spath_lineto_tl
4110 \tl_put_right:Nx \l_@@_tmpa_tl {
4111 {\tl_item:nn {#1} {5}}
4112 {\tl_item:nn {#1} {6}}
4113 }
4114
4115 \@@_tl_gput_right_braced:NV \g_@@_output_tl \l_@@_tmpa_tl
4116 \group_end:
4117 }
4118 \cs_new_protected_nopar:Npn \spath_split_line:NNnn #1#2#3#4
4119 {
4120 \@@_split_line:nn {#3}{#4}
4121 \tl_set:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
4122 \tl_set:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
4123 \tl_gclear:N \g_@@_output_tl
4124 }
4125 \cs_generate_variant:Nn \spath_split_line:NNnn {NNnV, NNVn, NNVV}
4126 \cs_new_protected_nopar:Npn \spath_gsplit_line:NNnn #1#2#3#4
4127 {
4128 \@@_split_line:nn {#3}{#4}
4129 \tl_gset:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
4130 \tl_gset:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
4131 \tl_gclear:N \g_@@_output_tl
4132 }
4133 \cs_generate_variant:Nn \spath_gsplit_line:NNnn {NNnV, NNVn, NNVV}
4134 % \end{macrocode}
4135 % \end{macro}
4136 %
4137 %
4138 % \begin{macro}[internal]{
4139 % \spath_split_rectangle:Nnn,
4140 % \spath_gsplit_rectangle:Nnn
4141 % }
4142 % Cuts a rectangle at a point.
4143 % \begin{macrocode}
4144 \cs_new_protected_nopar:Npn \@@_split_rectangle:nn #1#2
4145 {
4146 \group_begin:
4147 \spath_open:Nn \l_@@_tmpa_tl {#1}
4148 \fp_set:Nn \l_@@_tmpa_fp {4*(#2)}
4149 \spath_split_at:NNVV
4150 \l_@@_tmpa_tl \l_@@_tmpb_tl \l_@@_tmpa_tl \l_@@_tmpa_fp
4151 \@@_append_no_move:VV \l_@@_tmpb_tl \l_@@_tmpa_tl
4152 \group_end:
4153 }
4154 \cs_new_protected_nopar:Npn \spath_split_rectangle:Nnn #1#2#3
4155 {
4156 \@@_split_rectangle:nn {#2}{#3}
4157 \tl_set_eq:NN #1 \g_@@_output_tl
4158 \tl_gclear:N \g_@@_output_tl
4159 }
4160 \cs_generate_variant:Nn \spath_split_rectangle:Nnn {NnV, NVn, NVV}
4161 \cs_new_protected_nopar:Npn \spath_gsplit_rectangle:Nnn #1#2#3
4162 {
4163 \@@_split_rectangle:nn {#2}{#3}
4164 \tl_gset_eq:NN #1 \g_@@_output_tl
4165 \tl_gclear:N \g_@@_output_tl
4166 }
4167 \cs_generate_variant:Nn \spath_gsplit_rectangle:Nnn {NnV, NVn, NVV}
4168 % \end{macrocode}
4169 % \end{macro}
4170 %
4171 %
4172 % \begin{macro}[internal]{
4173 % \spath_split_at:NNnn,
4174 % \spath_split_at:Nnn,
4175 % \spath_split_at:Nn,
4176 % \spath_gsplit_at:NNnn
4177 % \spath_gsplit_at:Nnn,
4178 % \spath_gsplit_at:Nn,
4179 % \spath_split_at_keep_start:Nnn,
4180 % \spath_split_at_keep_start:Nn,
4181 % \spath_gsplit_at_keep_start:Nnn,
4182 % \spath_gsplit_at_keep_start:Nn,
4183 % \spath_split_at_keep_end:Nnn,
4184 % \spath_split_at_keep_end:Nn,
4185 % \spath_gsplit_at_keep_end:Nnn,
4186 % \spath_gsplit_at_keep_end:Nn,
4187 % \spath_split_at_normalised:NNnn,
4188 % \spath_split_at_normalised:Nnn,
4189 % \spath_split_at_normalised:Nn,
4190 % \spath_gsplit_at_normalised:NNnn
4191 % \spath_gsplit_at_normalised:Nnn,
4192 % \spath_gsplit_at_normalised:Nn,
4193 % \spath_split_at_normalised_keep_start:Nnn,
4194 % \spath_split_at_normalised_keep_start:Nn,
4195 % \spath_gsplit_at_normalised_keep_start:Nnn,
4196 % \spath_gsplit_at_normalised_keep_start:Nn,
4197 % \spath_split_at_normalised_keep_end:Nnn,
4198 % \spath_split_at_normalised_keep_end:Nn,
4199 % \spath_gsplit_at_normalised_keep_end:Nnn,
4200 % \spath_gsplit_at_normalised_keep_end:Nn,
4201 % }
4202 % Split a path according to the parameter generated by the intersection routine.
4203 % 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).
4204 % The \texttt{keep} versions throw away the other part of the curve.
4205 % \begin{macrocode}
4206 \cs_new_protected_nopar:Npn \@@_split_at:nn #1#2
4207 {
4208 \group_begin:
4209 \int_set:Nn \l_@@_tmpa_int {\fp_to_int:n {floor(#2) + 1}}
4210 \fp_set:Nn \l_@@_tmpa_fp {#2 - floor(#2)}
4211
4212 % Is split point near one end or other of a component?
4213 \fp_compare:nT
4214 {
4215 \l_@@_tmpa_fp < 0.01
4216 }
4217 {
4218 % Near the start, so we'll place it at the start
4219 \fp_set:Nn \l_@@_tmpa_fp {0}
4220 }
4221 \fp_compare:nT
4222 {
4223 \l_@@_tmpa_fp > 0.99
4224 }
4225 {
4226 % Near the end, so we'll place it at the end
4227 \fp_set:Nn \l_@@_tmpa_fp {0}
4228 \int_incr:N \l_@@_tmpa_int
4229 }
4230
4231 \int_zero:N \l_@@_tmpb_int
4232 \bool_set_true:N \l_@@_tmpa_bool
4233
4234 \tl_set:Nn \l_@@_tmpe_tl {#1}
4235
4236 \dim_zero:N \l_@@_tmpa_dim
4237 \dim_zero:N \l_@@_tmpb_dim
4238
4239 % Remember if the component is closed
4240 \spath_finalaction:NV \l_@@_tmpa_tl \l_@@_tmpe_tl
4241
4242 \bool_set:Nn \l_@@_closed_bool
4243 {
4244 \tl_if_eq_p:NN \l_@@_tmpa_tl \c_spath_closepath_tl
4245 ||
4246 \tl_if_eq_p:NN \l_@@_tmpa_tl \c_spath_rectcorner_tl
4247 }
4248
4249 % Open it
4250 \spath_open:N \l_@@_tmpe_tl
4251
4252 \tl_clear:N \l_@@_tmpa_tl
4253 \tl_clear:N \l_@@_tmpb_tl
4254 \tl_clear:N \l_@@_tmpc_tl
4255 \tl_clear:N \l_@@_tmpd_tl
4256
4257 \bool_until_do:nn {
4258 \tl_if_empty_p:N \l_@@_tmpe_tl
4259 ||
4260 \int_compare_p:n { \l_@@_tmpa_int == \l_@@_tmpb_int }
4261 }
4262 {
4263 \tl_set:Nx \l_@@_tmpf_tl {\tl_head:N \l_@@_tmpe_tl}
4264 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl }
4265 \token_case_meaning:Nn \l_@@_tmpf_tl
4266 {
4267 \c_spath_lineto_tl
4268 {
4269 \int_incr:N \l_@@_tmpb_int
4270 }
4271 \c_spath_curvetoa_tl
4272 {
4273 \int_incr:N \l_@@_tmpb_int
4274 }
4275 \c_spath_rectcorner_tl
4276 {
4277 \int_incr:N \l_@@_tmpb_int
4278 }
4279 }
4280 \int_compare:nT { \l_@@_tmpb_int < \l_@@_tmpa_int }
4281 {
4282 \tl_put_right:NV \l_@@_tmpc_tl \l_@@_tmpf_tl
4283
4284 \tl_put_right:Nx \l_@@_tmpc_tl
4285 {{ \tl_head:N \l_@@_tmpe_tl }}
4286 \dim_set:Nn \l_@@_tmpa_dim {\tl_head:N \l_@@_tmpe_tl}
4287 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl }
4288
4289 \tl_put_right:Nx \l_@@_tmpc_tl
4290 {{ \tl_head:N \l_@@_tmpe_tl }}
4291 \dim_set:Nn \l_@@_tmpb_dim {\tl_head:N \l_@@_tmpe_tl}
4292 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl }
4293
4294 }
4295 }
4296
4297 \tl_clear:N \l_@@_tmpd_tl
4298 \tl_put_right:NV \l_@@_tmpd_tl \c_spath_moveto_tl
4299 \tl_put_right:Nx \l_@@_tmpd_tl
4300 {
4301 {\dim_use:N \l_@@_tmpa_dim}
4302 {\dim_use:N \l_@@_tmpb_dim}
4303 }
4304
4305 \fp_compare:nTF
4306 {
4307 \l_@@_tmpa_fp == 0
4308 }
4309 {
4310 \tl_set_eq:NN \l_@@_tmpb_tl \l_@@_tmpd_tl
4311 \tl_if_empty:NF \l_@@_tmpe_tl
4312 {
4313 \tl_put_right:NV \l_@@_tmpb_tl \l_@@_tmpf_tl
4314 \tl_put_right:NV \l_@@_tmpb_tl \l_@@_tmpe_tl
4315 }
4316 }
4317 {
4318
4319 \token_case_meaning:Nn \l_@@_tmpf_tl
4320 {
4321 \c_spath_lineto_tl
4322 {
4323 \tl_put_right:NV \l_@@_tmpd_tl \l_@@_tmpf_tl
4324 \tl_put_right:Nx \l_@@_tmpd_tl
4325 {{ \tl_head:N \l_@@_tmpe_tl }}
4326 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl }
4327
4328 \tl_put_right:Nx \l_@@_tmpd_tl
4329 {{ \tl_head:N \l_@@_tmpe_tl }}
4330 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl }
4331
4332 \spath_split_line:NNVV
4333 \l_@@_tmpa_tl
4334 \l_@@_tmpb_tl
4335 \l_@@_tmpd_tl
4336 \l_@@_tmpa_fp
4337
4338 \prg_replicate:nn {3} {
4339 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
4340 }
4341
4342 \tl_put_right:NV \l_@@_tmpc_tl \l_@@_tmpa_tl
4343 \tl_put_right:NV \l_@@_tmpb_tl \l_@@_tmpe_tl
4344 }
4345 \c_spath_curvetoa_tl
4346 {
4347 \tl_put_right:NV \l_@@_tmpd_tl \l_@@_tmpf_tl
4348 \tl_put_right:Nx \l_@@_tmpd_tl
4349 {{ \tl_head:N \l_@@_tmpe_tl }}
4350 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl }
4351
4352 \tl_put_right:Nx \l_@@_tmpd_tl
4353 {{ \tl_head:N \l_@@_tmpe_tl }}
4354 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl }
4355
4356 \prg_replicate:nn {2} {
4357
4358 \tl_put_right:Nx \l_@@_tmpd_tl
4359 { \tl_head:N \l_@@_tmpe_tl }
4360 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl }
4361
4362 \tl_put_right:Nx \l_@@_tmpd_tl
4363 {{ \tl_head:N \l_@@_tmpe_tl }}
4364 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl }
4365
4366 \tl_put_right:Nx \l_@@_tmpd_tl
4367 {{ \tl_head:N \l_@@_tmpe_tl }}
4368 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl }
4369 }
4370
4371 \spath_split_curve:NNVV
4372 \l_@@_tmpa_tl
4373 \l_@@_tmpb_tl
4374 \l_@@_tmpd_tl \l_@@_tmpa_fp
4375
4376 \prg_replicate:nn {3} {
4377 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
4378 }
4379
4380 \tl_put_right:NV \l_@@_tmpc_tl \l_@@_tmpa_tl
4381 \tl_put_right:NV \l_@@_tmpb_tl \l_@@_tmpe_tl
4382 }
4383
4384 \c_spath_rectcorner_tl
4385 {
4386 \tl_clear:N \l_@@_tmpd_tl
4387 \tl_put_right:NV \l_@@_tmpd_tl \l_@@_tmpf_tl
4388
4389 \tl_put_right:Nx \l_@@_tmpd_tl {{\tl_head:N \l_@@_tmpe_tl}}
4390 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl}
4391 \tl_put_right:Nx \l_@@_tmpd_tl {{\tl_head:N \l_@@_tmpe_tl}}
4392 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl}
4393
4394 \tl_put_right:Nx \l_@@_tmpd_tl {\tl_head:N \l_@@_tmpe_tl}
4395 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl}
4396
4397 \tl_put_right:Nx \l_@@_tmpd_tl {{\tl_head:N \l_@@_tmpe_tl}}
4398 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl}
4399 \tl_put_right:Nx \l_@@_tmpd_tl {{\tl_head:N \l_@@_tmpe_tl}}
4400 \tl_set:Nx \l_@@_tmpe_tl {\tl_tail:N \l_@@_tmpe_tl}
4401
4402 \spath_split_rectangle:NVV
4403 \l_@@_tmpa_tl
4404 \l_@@_tmpd_tl
4405 \l_@@_tmpa_fp
4406
4407 \tl_put_right:NV \l_@@_tmpc_tl \l_@@_tmpa_tl
4408 \tl_put_right:NV \l_@@_tmpb_tl \l_@@_tmpe_tl
4409 }
4410
4411 }
4412 }
4413
4414 \bool_if:NT \l_@@_closed_bool
4415 {
4416 \prg_replicate:nn {3}
4417 {
4418 \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
4419 }
4420 \tl_put_right:NV \l_@@_tmpb_tl \l_@@_tmpc_tl
4421 \tl_set_eq:NN \l_@@_tmpc_tl \l_@@_tmpb_tl
4422 \tl_clear:N \l_@@_tmpb_tl
4423 }
4424
4425 \tl_gclear:N \g_@@_output_tl
4426 \@@_tl_gput_right_braced:NV \g_@@_output_tl \l_@@_tmpc_tl
4427 \@@_tl_gput_right_braced:NV \g_@@_output_tl \l_@@_tmpb_tl
4428 \group_end:
4429 }
4430 \cs_generate_variant:Nn \@@_split_at:nn {nV, VV}
4431 \cs_new_protected_nopar:Npn \@@_split_at_normalised:nn #1#2
4432 {
4433 \group_begin:
4434 \spath_reallength:Nn \l_@@_tmpa_int {#1}
4435
4436 \tl_set:Nx \l_@@_tmpa_tl
4437 {\fp_to_decimal:n {(#2) * (\l_@@_tmpa_int)}}
4438 \@@_split_at:nV {#1} \l_@@_tmpa_tl
4439 \group_end:
4440 }
4441 \cs_generate_variant:Nn \@@_split_at_normalised:nn {nV}
4442 \cs_new_protected_nopar:Npn \spath_split_at:NNnn #1#2#3#4
4443 {
4444 \@@_split_at:nn {#3}{#4}
4445 \tl_set:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
4446 \tl_set:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
4447 \tl_gclear:N \g_@@_output_tl
4448 }
4449 \cs_generate_variant:Nn \spath_split_at:NNnn {NNVn, NNVV, NNnV}
4450 \cs_new_protected_nopar:Npn \spath_gsplit_at:NNnn #1#2#3#4
4451 {
4452 \@@_split_at:nn {#3}{#4}
4453 \tl_gset:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
4454 \tl_gset:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
4455 \tl_gclear:N \g_@@_output_tl
4456 }
4457 \cs_generate_variant:Nn \spath_gsplit_at:NNnn {NNVn, NNVV, NNnV}
4458 \cs_new_protected_nopar:Npn \spath_split_at_keep_start:Nnn #1#2#3
4459 {
4460 \@@_split_at:nn {#2}{#3}
4461 \tl_set:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
4462 \tl_gclear:N \g_@@_output_tl
4463 }
4464 \cs_generate_variant:Nn \spath_split_at_keep_start:Nnn {NVn}
4465 \cs_new_protected_nopar:Npn \spath_split_at_keep_start:Nn #1#2
4466 {
4467 \spath_split_at_keep_start:NVn #1#1{#2}
4468 }
4469 \cs_new_protected_nopar:Npn \spath_gsplit_at_keep_start:Nnn #1#2#3
4470 {
4471 \@@_split_at:nn {#2}{#3}
4472 \tl_gset:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
4473 \tl_gclear:N \g_@@_output_tl
4474 }
4475 \cs_generate_variant:Nn \spath_gsplit_at_keep_start:Nnn {NVn}
4476 \cs_new_protected_nopar:Npn \spath_gsplit_at_keep_start:Nn #1#2
4477 {
4478 \spath_gsplit_at_keep_start:NVn #1#1{#2}
4479 }
4480 \cs_new_protected_nopar:Npn \spath_split_at_keep_end:Nnn #1#2#3
4481 {
4482 \@@_split_at:nn {#2}{#3}
4483 \tl_set:Nx #1 {\tl_item:Nn \g_@@_output_tl {2}}
4484 \tl_gclear:N \g_@@_output_tl
4485 }
4486 \cs_generate_variant:Nn \spath_split_at_keep_end:Nnn {NVn}
4487 \cs_new_protected_nopar:Npn \spath_split_at_keep_end:Nn #1#2
4488 {
4489 \spath_split_at_keep_end:NVn #1#1{#2}
4490 }
4491 \cs_new_protected_nopar:Npn \spath_gsplit_at_keep_end:Nnn #1#2#3
4492 {
4493 \@@_split_at:nn {#2}{#3}
4494 \tl_gset:Nx #1 {\tl_item:Nn \g_@@_output_tl {2}}
4495 \tl_gclear:N \g_@@_output_tl
4496 }
4497 \cs_generate_variant:Nn \spath_gsplit_at_keep_end:Nnn {NVn}
4498 \cs_new_protected_nopar:Npn \spath_gsplit_at_keep_end:Nn #1#2
4499 {
4500 \spath_gsplit_at_keep_end:NVn #1#1{#2}
4501 }
4502 \cs_new_protected_nopar:Npn \spath_split_at_normalised:NNnn #1#2#3#4
4503 {
4504 \@@_split_at_normalised:nn {#3}{#4}
4505 \tl_set:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
4506 \tl_set:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
4507 \tl_gclear:N \g_@@_output_tl
4508 }
4509 \cs_generate_variant:Nn \spath_split_at_normalised:NNnn {NNVn, NNVV, NNnV, ccvn}
4510 \cs_new_protected_nopar:Npn \spath_gsplit_at_normalised:NNnn #1#2#3#4
4511 {
4512 \@@_split_at_normalised:nn {#3}{#4}
4513 \tl_gset:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
4514 \tl_gset:Nx #2 {\tl_item:Nn \g_@@_output_tl {2}}
4515 \tl_gclear:N \g_@@_output_tl
4516 }
4517 \cs_generate_variant:Nn \spath_gsplit_at_normalised:NNnn {NNVn, NNVV, NNnV, ccvn}
4518 \cs_new_protected_nopar:Npn \spath_split_at_normalised_keep_start:Nnn #1#2#3
4519 {
4520 \@@_split_at_normalised:nn {#2}{#3}
4521 \tl_set:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
4522 \tl_gclear:N \g_@@_output_tl
4523 }
4524 \cs_generate_variant:Nn \spath_split_at_normalised_keep_start:Nnn {NVn}
4525 \cs_new_protected_nopar:Npn \spath_split_at_normalised_keep_start:Nn #1#2
4526 {
4527 \spath_split_at_normalised_keep_start:NVn #1#1{#2}
4528 }
4529 \cs_generate_variant:Nn \spath_split_at_normalised_keep_start:Nn {cn}
4530 \cs_new_protected_nopar:Npn \spath_gsplit_at_normalised_keep_start:Nnn #1#2#3
4531 {
4532 \@@_split_at_normalised:nn {#2}{#3}
4533 \tl_gset:Nx #1 {\tl_item:Nn \g_@@_output_tl {1}}
4534 \tl_gclear:N \g_@@_output_tl
4535 }
4536 \cs_generate_variant:Nn \spath_gsplit_at_normalised_keep_start:Nnn {NVn}
4537 \cs_new_protected_nopar:Npn \spath_gsplit_at_normalised_keep_start:Nn #1#2
4538 {
4539 \spath_gsplit_at_normalised_keep_start:NVn #1#1{#2}
4540 }
4541 \cs_generate_variant:Nn \spath_gsplit_at_normalised_keep_start:Nn {cn}
4542 \cs_new_protected_nopar:Npn \spath_split_at_normalised_keep_end:Nnn #1#2#3
4543 {
4544 \@@_split_at_normalised:nn {#2}{#3}
4545 \tl_set:Nx #1 {\tl_item:Nn \g_@@_output_tl {2}}
4546 \tl_gclear:N \g_@@_output_tl
4547 }
4548 \cs_generate_variant:Nn \spath_split_at_normalised_keep_end:Nnn {NVn}
4549 \cs_new_protected_nopar:Npn \spath_split_at_normalised_keep_end:Nn #1#2
4550 {
4551 \spath_split_at_normalised_keep_end:NVn #1#1{#2}
4552 }
4553 \cs_generate_variant:Nn \spath_split_at_normalised_keep_end:Nn {cn}
4554 \cs_new_protected_nopar:Npn \spath_gsplit_at_normalised_keep_end:Nnn #1#2#3
4555 {
4556 \@@_split_at_normalised:nn {#2}{#3}
4557 \tl_gset:Nx #1 {\tl_item:Nn \g_@@_output_tl {2}}
4558 \tl_gclear:N \g_@@_output_tl
4559 }
4560 \cs_generate_variant:Nn \spath_gsplit_at_normalised_keep_end:Nnn {NVn}
4561 \cs_new_protected_nopar:Npn \spath_gsplit_at_normalised_keep_end:Nn #1#2
4562 {
4563 \spath_gsplit_at_normalised_keep_end:NVn #1#1{#2}
4564 }
4565 \cs_generate_variant:Nn \spath_gsplit_at_normalised_keep_end:Nn {cn}
4566 % \end{macrocode}
4567 %
4568 %
4569 % \begin{macrocode}
4570 \cs_new_protected_nopar:Npn \spath_split_at:Nnn #1#2#3
4571 {
4572 \@@_split_at:nn {#2}{#3}
4573 \tl_set:Nx #1
4574 {
4575 \tl_item:Nn \g_@@_output_tl {1}
4576 \tl_item:Nn \g_@@_output_tl {2}
4577 }
4578 \tl_gclear:N \g_@@_output_tl
4579 }
4580 \cs_generate_variant:Nn \spath_split_at:Nnn {NVn, NVV}
4581 \cs_new_protected_nopar:Npn \spath_split_at:Nn #1#2
4582 {
4583 \spath_split_at:NVn #1#1{#2}
4584 }
4585 \cs_new_protected_nopar:Npn \spath_gsplit_at:Nnn #1#2#3
4586 {
4587 \@@_split_at:nn {#2}{#3}
4588 \tl_gset:Nx #1
4589 {
4590 \tl_item:Nn \g_@@_output_tl {1}
4591 \tl_item:Nn \g_@@_output_tl {2}
4592 }
4593 \tl_gclear:N \g_@@_output_tl
4594 }
4595 \cs_generate_variant:Nn \spath_gsplit_at:Nnn {NVn, NVV}
4596 \cs_new_protected_nopar:Npn \spath_gsplit_at:Nn #1#2
4597 {
4598 \spath_gsplit_at:NVn #1#1{#2}
4599 }
4600 \cs_new_protected_nopar:Npn \spath_split_at_normalised:Nnn #1#2#3
4601 {
4602 \@@_split_at_normalised:nn {#2}{#3}
4603 \tl_set:Nx #1
4604 {
4605 \tl_item:Nn \g_@@_output_tl {1}
4606 \tl_item:Nn \g_@@_output_tl {2}
4607 }
4608 \tl_gclear:N \g_@@_output_tl
4609 }
4610 \cs_generate_variant:Nn \spath_split_at_normalised:Nnn {NVn, NVV}
4611 \cs_new_protected_nopar:Npn \spath_split_at_normalised:Nn #1#2
4612 {
4613 \spath_split_at_normalised:NVn #1#1{#2}
4614 }
4615 \cs_generate_variant:Nn \spath_split_at_normalised:Nn {cn}
4616 \cs_new_protected_nopar:Npn \spath_gsplit_at_normalised:Nnn #1#2#3
4617 {
4618 \@@_split_at_normalised:nn {#2}{#3}
4619 \tl_gset:Nx #1
4620 {
4621 \tl_item:Nn \g_@@_output_tl {1}
4622 \tl_item:Nn \g_@@_output_tl {2}
4623 }
4624 \tl_gclear:N \g_@@_output_tl
4625 }
4626 \cs_generate_variant:Nn \spath_gsplit_at_normalised:Nnn {NVn, NVV}
4627 \cs_new_protected_nopar:Npn \spath_gsplit_at_normalised:Nn #1#2
4628 {
4629 \spath_gsplit_at_normalised:NVn #1#1{#2}
4630 }
4631 \cs_generate_variant:Nn \spath_gsplit_at_normalised:Nn {cn}
4632 % \end{macrocode}
4633 % \end{macro}
4634 %
4635 %
4636 % \subsection{Shortening Paths}
4637 %
4638 % This code relates to shortening paths.
4639 % For curved paths, the routine uses the derivative at the end to figure out how far back to shorten.
4640 % This means that the actual length that it shortens by is approximate, but it is guaranteed to be along its length.
4641 %
4642 % As in the previous section, there are various versions.
4643 % In particular, there are versions where the path can be specified by a macro and is saved back into that macro.
4644 %
4645 % \begin{macro}[internal]{
4646 % \spath_shorten_at_end:Nnn
4647 % }
4648 % This macro shortens a path from the end by a dimension.
4649 %
4650 % \begin{macrocode}
4651 \cs_new_protected_nopar:Npn \@@_shorten_at_end:nn #1#2
4652 {
4653 \int_compare:nTF
4654 {
4655 \tl_count:n {#1} > 3
4656 }
4657 {
4658 \group_begin:
4659 \tl_set:Nn \l_@@_tmpa_tl {#1}
4660 \tl_reverse:N \l_@@_tmpa_tl
4661
4662 \tl_set:Nx \l_@@_tmpb_tl {\tl_item:Nn \l_@@_tmpa_tl {3}}
4663
4664 \tl_clear:N \l_@@_tmpe_tl
4665 \tl_if_eq:NNTF \l_@@_tmpb_tl \c_spath_curveto_tl
4666 {
4667 \int_set:Nn \l_@@_tmpa_int {3}
4668 }
4669 {
4670 \int_set:Nn \l_@@_tmpa_int {1}
4671 }
4672
4673 \prg_replicate:nn { \l_@@_tmpa_int }
4674 {
4675 \tl_put_right:Nx \l_@@_tmpe_tl
4676 {
4677 {\tl_head:N \l_@@_tmpa_tl}
4678 }
4679 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
4680 \tl_put_right:Nx \l_@@_tmpe_tl
4681 {
4682 {\tl_head:N \l_@@_tmpa_tl}
4683 }
4684 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
4685 \tl_put_right:Nx \l_@@_tmpe_tl
4686 {
4687 \tl_head:N \l_@@_tmpa_tl
4688 }
4689 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
4690 }
4691
4692 \tl_put_right:Nx \l_@@_tmpe_tl
4693 {
4694 {\tl_item:Nn \l_@@_tmpa_tl {1}}
4695 {\tl_item:Nn \l_@@_tmpa_tl {2}}
4696 }
4697 \tl_put_right:NV \l_@@_tmpe_tl \c_spath_moveto_tl
4698
4699 \tl_reverse:N \l_@@_tmpa_tl
4700
4701 \fp_set:Nn \l_@@_tmpa_fp
4702 {
4703 \dim_to_fp:n {\tl_item:Nn \l_@@_tmpe_tl {4}}
4704 -
4705 \dim_to_fp:n {\tl_item:Nn \l_@@_tmpe_tl {1}}
4706 }
4707
4708 \fp_set:Nn \l_@@_tmpb_fp
4709 {
4710 \dim_to_fp:n {\tl_item:Nn \l_@@_tmpe_tl {5}}
4711 -
4712 \dim_to_fp:n {\tl_item:Nn \l_@@_tmpe_tl {2}}
4713 }
4714
4715 \fp_set:Nn \l_@@_tmpc_fp
4716 {
4717 sqrt(
4718 \l_@@_tmpa_fp * \l_@@_tmpa_fp
4719 +
4720 \l_@@_tmpb_fp * \l_@@_tmpb_fp
4721 ) * \l_@@_tmpa_int
4722 }
4723
4724 \fp_compare:nTF
4725 {
4726 \l_@@_tmpc_fp > #2
4727 }
4728 {
4729
4730 \fp_set:Nn \l_@@_tmpc_fp
4731 {
4732 (\l_@@_tmpc_fp - #2)/ \l_@@_tmpc_fp
4733 }
4734
4735 \tl_reverse:N \l_@@_tmpe_tl
4736
4737 \tl_if_eq:NNTF \l_@@_tmpb_tl \c_spath_curveto_tl
4738 {
4739 \spath_split_curve:NNVV
4740 \l_@@_tmpc_tl
4741 \l_@@_tmpd_tl
4742 \l_@@_tmpe_tl
4743 \l_@@_tmpc_fp
4744 }
4745 {
4746 \spath_split_line:NNVV
4747 \l_@@_tmpc_tl
4748 \l_@@_tmpd_tl
4749 \l_@@_tmpe_tl
4750 \l_@@_tmpc_fp
4751 }
4752
4753 \prg_replicate:nn {3}
4754 {
4755 \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
4756 }
4757
4758 \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpc_tl
4759
4760 }
4761 {
4762
4763 \int_compare:nT
4764 {
4765 \tl_count:N \l_@@_tmpa_tl > 3
4766 }
4767 {
4768 \dim_set:Nn \l_@@_tmpa_dim {\fp_to_dim:n {#2 - \l_@@_tmpc_fp } }
4769 \spath_shorten_at_end:NV \l_@@_tmpa_tl \l_@@_tmpa_dim
4770 }
4771 }
4772
4773 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
4774 \group_end:
4775 }
4776 {
4777 \tl_gset:Nn \g_@@_output_tl {#1}
4778 }
4779 }
4780 \cs_new_protected_nopar:Npn \spath_shorten_at_end:Nnn #1#2#3
4781 {
4782 \@@_shorten_at_end:nn {#2}{#3}
4783 \tl_set_eq:NN #1 \g_@@_output_tl
4784 \tl_gclear:N \g_@@_output_tl
4785 }
4786 \cs_generate_variant:Nn \spath_shorten_at_end:Nnn {NVV, cnn, cVV, NVn}
4787 \cs_new_protected_nopar:Npn \spath_shorten_at_end:Nn #1#2
4788 {
4789 \spath_shorten_at_end:NVn #1#1{#2}
4790 }
4791 \cs_generate_variant:Nn \spath_shorten_at_end:Nn {cn, cV, NV}
4792 \cs_new_protected_nopar:Npn \spath_gshorten_at_end:Nnn #1#2#3
4793 {
4794 \@@_shorten_at_end:nn {#2}{#3}
4795 \tl_gset_eq:NN #1 \g_@@_output_tl
4796 \tl_gclear:N \g_@@_output_tl
4797 }
4798 \cs_generate_variant:Nn \spath_gshorten_at_end:Nnn {NVV, cnn, cVV, NVn}
4799 \cs_new_protected_nopar:Npn \spath_gshorten_at_end:Nn #1#2
4800 {
4801 \spath_gshorten_at_end:NVn #1#1{#2}
4802 }
4803 \cs_generate_variant:Nn \spath_gshorten_at_end:Nn {cn, cV, NV}
4804 % \end{macrocode}
4805 % \end{macro}
4806 %
4807 % \begin{macro}[internal]{
4808 % \spath_shorten_at_start:Nnn,
4809 % \spath_shorten_at_start:Nn,
4810 % \spath_gshorten_at_start:Nnn,
4811 % \spath_gshorten_at_start:Nn
4812 % }
4813 %
4814 % This macro shortens a path from the start by a dimension.
4815 %
4816 % \begin{macrocode}
4817 \cs_new_protected_nopar:Npn \@@_shorten_at_start:nn #1#2
4818 {
4819 \int_compare:nTF
4820 {
4821 \tl_count:n {#1} > 3
4822 }
4823 {
4824 \group_begin:
4825 \tl_set:Nn \l_@@_tmpa_tl {#1}
4826
4827 \tl_set:Nx \l_@@_tmpb_tl {\tl_item:Nn \l_@@_tmpa_tl {4}}
4828
4829 \tl_clear:N \l_@@_tmpe_tl
4830
4831 \tl_if_eq:NNTF \l_@@_tmpb_tl \c_spath_curvetoa_tl
4832 {
4833 \int_set:Nn \l_@@_tmpa_int {3}
4834 }
4835 {
4836 \int_set:Nn \l_@@_tmpa_int {1}
4837 }
4838
4839 \tl_set_eq:NN \l_@@_tmpe_tl \c_spath_moveto_tl
4840 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl }
4841
4842 \prg_replicate:nn { \l_@@_tmpa_int }
4843 {
4844 \@@_tl_put_right_braced:Nx
4845 \l_@@_tmpe_tl
4846 {\tl_item:Nn \l_@@_tmpa_tl {1}}
4847 \@@_tl_put_right_braced:Nx
4848 \l_@@_tmpe_tl
4849 {\tl_item:Nn \l_@@_tmpa_tl {2}}
4850 \tl_put_right:Nx \l_@@_tmpe_tl {\tl_item:Nn \l_@@_tmpa_tl {3}}
4851
4852 \prg_replicate:nn {3}
4853 {
4854 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl }
4855 }
4856 }
4857 \@@_tl_put_right_braced:Nx
4858 \l_@@_tmpe_tl
4859 {\tl_item:Nn \l_@@_tmpa_tl {1}}
4860 \@@_tl_put_right_braced:Nx
4861 \l_@@_tmpe_tl
4862 {\tl_item:Nn \l_@@_tmpa_tl {2}}
4863
4864 \fp_set:Nn \l_@@_tmpa_fp
4865 {
4866 \dim_to_fp:n {\tl_item:Nn \l_@@_tmpe_tl {5}}
4867 -
4868 \dim_to_fp:n {\tl_item:Nn \l_@@_tmpe_tl {2}}
4869 }
4870
4871 \fp_set:Nn \l_@@_tmpb_fp
4872 {
4873 \dim_to_fp:n {\tl_item:Nn \l_@@_tmpe_tl {6}}
4874 -
4875 \dim_to_fp:n {\tl_item:Nn \l_@@_tmpe_tl {3}}
4876 }
4877
4878 \fp_set:Nn \l_@@_tmpc_fp
4879 {
4880 sqrt(
4881 \l_@@_tmpa_fp * \l_@@_tmpa_fp
4882 +
4883 \l_@@_tmpb_fp * \l_@@_tmpb_fp
4884 )
4885 *
4886 \l_@@_tmpa_int
4887 }
4888
4889 \fp_compare:nTF
4890 {
4891 \l_@@_tmpc_fp > #2
4892 }
4893 {
4894
4895 \fp_set:Nn \l_@@_tmpc_fp
4896 {
4897 #2/ \l_@@_tmpc_fp
4898 }
4899
4900 \tl_if_eq:NNTF \l_@@_tmpb_tl \c_spath_curvetoa_tl
4901 {
4902 \spath_split_curve:NNVV
4903 \l_@@_tmpc_tl
4904 \l_@@_tmpd_tl
4905 \l_@@_tmpe_tl
4906 \l_@@_tmpc_fp
4907 }
4908 {
4909 \spath_split_line:NNVV
4910 \l_@@_tmpc_tl
4911 \l_@@_tmpd_tl
4912 \l_@@_tmpe_tl
4913 \l_@@_tmpc_fp
4914 }
4915
4916 \prg_replicate:nn {2}
4917 {
4918 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
4919 }
4920
4921 \tl_put_left:NV \l_@@_tmpa_tl \l_@@_tmpd_tl
4922
4923 }
4924 {
4925
4926 \tl_put_left:NV \l_@@_tmpa_tl \c_spath_moveto_tl
4927
4928 \int_compare:nT
4929 {
4930 \tl_count:N \l_@@_tmpa_tl > 3
4931 }
4932 {
4933 \dim_set:Nn \l_@@_tmpa_dim {\fp_to_dim:n {#2 - \l_@@_tmpc_fp } }
4934 \spath_shorten_at_start:NV \l_@@_tmpa_tl \l_@@_tmpa_dim
4935 }
4936 }
4937
4938 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
4939 \group_end:
4940 }
4941 {
4942 \tl_gset:Nn \g_@@_output_tl {#1}
4943 }
4944 }
4945 \cs_new_protected_nopar:Npn \spath_shorten_at_start:Nnn #1#2#3
4946 {
4947 \@@_shorten_at_start:nn {#2}{#3}
4948 \tl_set_eq:NN #1 \g_@@_output_tl
4949 \tl_gclear:N \g_@@_output_tl
4950 }
4951 \cs_generate_variant:Nn \spath_shorten_at_start:Nnn {NVV, cnn, cVV, NVn}
4952 \cs_new_protected_nopar:Npn \spath_shorten_at_start:Nn #1#2
4953 {
4954 \spath_shorten_at_start:NVn #1#1{#2}
4955 }
4956 \cs_generate_variant:Nn \spath_shorten_at_start:Nn {cn, cV, NV}
4957 \cs_new_protected_nopar:Npn \spath_gshorten_at_start:Nnn #1#2#3
4958 {
4959 \@@_shorten_at_start:nn {#2}{#3}
4960 \tl_gset_eq:NN #1 \g_@@_output_tl
4961 \tl_gclear:N \g_@@_output_tl
4962 }
4963 \cs_generate_variant:Nn \spath_gshorten_at_start:Nnn {NVV, cnn, cVV, NVn}
4964 \cs_new_protected_nopar:Npn \spath_gshorten_at_start:Nn #1#2
4965 {
4966 \spath_gshorten_at_start:NVn #1#1{#2}
4967 }
4968 \cs_generate_variant:Nn \spath_gshorten_at_start:Nn {cn, cV, NV}
4969 % \end{macrocode}
4970 % \end{macro}
4971 %
4972 % \begin{macro}[internal]{
4973 % \spath_shorten_at_both_ends:Nnn,
4974 % \spath_shorten_at_both_ends:Nn,
4975 % \spath_gshorten_at_both_ends:Nnn,
4976 % \spath_gshorten_at_both_ends:Nn
4977 % }
4978 %
4979 % This macro shortens a path from the start by a dimension.
4980 %
4981 % \begin{macrocode}
4982 \cs_new_protected_nopar:Npn \spath_shorten_at_both_ends:Nnn #1#2#3
4983 {
4984 \spath_shorten_at_start:Nnn #1{#2}{#3}
4985 \spath_shorten_at_end:Nnn #1{#2}{#3}
4986 }
4987 \cs_new_protected_nopar:Npn \spath_shorten_at_both_ends:Nn #1#2
4988 {
4989 \spath_shorten_at_start:Nn #1{#2}
4990 \spath_shorten_at_end:Nn #1{#2}
4991 }
4992 \cs_generate_variant:Nn \spath_shorten_at_both_ends:Nn {cn, cV, NV}
4993 \cs_new_protected_nopar:Npn \spath_gshorten_at_both_ends:Nnn #1#2#3
4994 {
4995 \spath_gshorten_at_start:Nnn #1{#2}{#3}
4996 \spath_gshorten_at_end:Nnn #1{#2}{#3}
4997 }
4998 \cs_new_protected_nopar:Npn \spath_gshorten_at_both_ends:Nn #1#2
4999 {
5000 \spath_gshorten_at_start:Nn #1{#2}
5001 \spath_gshorten_at_end:Nn #1{#2}
5002 }
5003 \cs_generate_variant:Nn \spath_gshorten_at_both_ends:Nn {cn, cV, NV}
5004 % \end{macrocode}
5005 % \end{macro}
5006 %
5007 % \subsection{Points on a Path}
5008 %
5009 % \begin{macro}[internal]{
5010 % \spath_point_at:Nnn,
5011 % \spath_gpoint_at:Nnn,
5012 % }
5013 %
5014 % Get the location of a point on a path, using the same location specification as the intersection library.
5015 % \begin{macrocode}
5016 \cs_new_protected_nopar:Npn \@@_point_at:nn #1#2
5017 {
5018 \group_begin:
5019 \int_set:Nn \l_@@_tmpa_int {\fp_to_int:n {floor(#2) + 1}}
5020 \fp_set:Nn \l_@@_tmpa_fp {#2 - floor(#2)}
5021
5022 \spath_segments_to_seq:Nn \l_@@_tmpa_seq {#1}
5023
5024 \int_compare:nTF
5025 {
5026 \l_@@_tmpa_int < 1
5027 }
5028 {
5029 \spath_initialpoint:Nn \l_@@_tmpc_tl {#1}
5030 }
5031 {
5032 \int_compare:nTF
5033 {
5034 \l_@@_tmpa_int > \seq_count:N \l_@@_tmpa_seq
5035 }
5036 {
5037 \spath_finalpoint:Nn \l_@@_tmpc_tl {#1}
5038 }
5039 {
5040
5041 \tl_set:Nx
5042 \l_@@_tmpa_tl
5043 {\seq_item:Nn \l_@@_tmpa_seq { \l_@@_tmpa_int} }
5044
5045 \int_compare:nTF
5046 {
5047 \tl_count:N \l_@@_tmpa_tl > 3
5048 }
5049 {
5050 \tl_set:Nx \l_@@_tmpb_tl {\tl_item:Nn \l_@@_tmpa_tl {4}}
5051 }
5052 {
5053 \tl_set:Nx \l_@@_tmpb_tl {\tl_item:Nn \l_@@_tmpa_tl {1}}
5054 }
5055
5056 \tl_clear:N \l_@@_tmpc_tl
5057
5058 \token_case_meaning:Nn \l_@@_tmpb_tl
5059 {
5060 \c_spath_moveto_tl
5061 {
5062 \tl_set:Nx \l_@@_tmpc_tl
5063 {
5064 {
5065 \tl_item:Nn \l_@@_tmpa_tl {2}
5066 }
5067 {
5068 \tl_item:Nn \l_@@_tmpa_tl {3}
5069 }
5070 }
5071 }
5072
5073 \c_spath_lineto_tl
5074 {
5075 \tl_set:Nx \l_@@_tmpc_tl
5076 {
5077 {\fp_to_dim:n
5078 {
5079 (1 - \l_@@_tmpa_fp) * ( \tl_item:Nn \l_@@_tmpa_tl {2} )
5080 +
5081 \l_@@_tmpa_fp * ( \tl_item:Nn \l_@@_tmpa_tl {5} )
5082 }
5083 }
5084 {\fp_to_dim:n
5085 {
5086 (1 - \l_@@_tmpa_fp) * ( \tl_item:Nn \l_@@_tmpa_tl {3} )
5087 +
5088 \l_@@_tmpa_fp * ( \tl_item:Nn \l_@@_tmpa_tl {6} )
5089 }
5090 }
5091 }
5092 }
5093
5094 \c_spath_rectsize_tl
5095 {
5096 \fp_compare:nTF
5097 {
5098 \l_@@_tmpa_fp <= .25
5099 }
5100 {
5101 \tl_set:Nx \l_@@_tmpc_tl
5102 {
5103 {\fp_to_dim:n
5104 {
5105 ( \tl_item:Nn \l_@@_tmpa_tl {2} )
5106 +
5107 4 * \l_@@_tmpa_fp * ( \tl_item:Nn \l_@@_tmpa_tl {5} )
5108 }
5109 }
5110 {\fp_to_dim:n {\tl_item:Nn \l_@@_tmpa_tl {3} } }
5111 }
5112 }
5113 {
5114 \fp_compare:nTF
5115 {
5116 \l_@@_tmpa_fp <= .5
5117 }
5118 {
5119 \tl_set:Nx \l_@@_tmpc_tl
5120 {
5121 {\fp_to_dim:n
5122 {
5123 ( \tl_item:Nn \l_@@_tmpa_tl {2} )
5124 +
5125 ( \tl_item:Nn \l_@@_tmpa_tl {5} )
5126 }
5127 }
5128 {\fp_to_dim:n
5129 {
5130 ( \tl_item:Nn \l_@@_tmpa_tl {3} )
5131 +
5132 (4 * (\l_@@_tmpa_fp) - 1) * ( \tl_item:Nn \l_@@_tmpa_tl {6} )
5133 }
5134 }
5135 }
5136 }
5137 {
5138 \fp_compare:nTF
5139 {
5140 \l_@@_tmpa_fp <= .75
5141 }
5142 {
5143 \tl_set:Nx \l_@@_tmpc_tl
5144 {
5145 {\fp_to_dim:n
5146 {
5147 ( \tl_item:Nn \l_@@_tmpa_tl {2} )
5148 +
5149 (3 - 4 * (\l_@@_tmpa_fp)) *( \tl_item:Nn \l_@@_tmpa_tl {5} )
5150 }
5151 }
5152 {\fp_to_dim:n
5153 {
5154 ( \tl_item:Nn \l_@@_tmpa_tl {3} )
5155 +
5156 ( \tl_item:Nn \l_@@_tmpa_tl {6} )
5157 }
5158 }
5159 }
5160
5161 }
5162 {
5163 \tl_set:Nx \l_@@_tmpc_tl
5164 {
5165 {\fp_to_dim:n
5166 {
5167 ( \tl_item:Nn \l_@@_tmpa_tl {2} )
5168 }
5169 }
5170 {\fp_to_dim:n
5171 {
5172 ( \tl_item:Nn \l_@@_tmpa_tl {3} )
5173 +
5174 (4 - 4 *(\l_@@_tmpa_fp)) * ( \tl_item:Nn \l_@@_tmpa_tl {6} )
5175 }
5176 }
5177 }
5178 }
5179 }
5180 }
5181 }
5182
5183 \c_spath_closepath_tl
5184 {
5185 \tl_set:Nx \l_@@_tmpc_tl
5186 {
5187 {\fp_to_dim:n
5188 {
5189 (1 - \l_@@_tmpa_fp) * ( \tl_item:Nn \l_@@_tmpa_tl {2} )
5190 +
5191 \l_@@_tmpa_fp * ( \tl_item:Nn \l_@@_tmpa_tl {5} )
5192 }
5193 }
5194 {\fp_to_dim:n
5195 {
5196 (1 - \l_@@_tmpa_fp) * ( \tl_item:Nn \l_@@_tmpa_tl {3} )
5197 +
5198 \l_@@_tmpa_fp * ( \tl_item:Nn \l_@@_tmpa_tl {6} )
5199 }
5200 }
5201 }
5202 }
5203
5204 \c_spath_curvetoa_tl
5205 {
5206 \tl_set:Nx \l_@@_tmpc_tl
5207 {
5208 {\fp_to_dim:n
5209 {
5210 (1 - \l_@@_tmpa_fp)^3 * \tl_item:Nn \l_@@_tmpa_tl {2}
5211 + 3 * (1 - \l_@@_tmpa_fp)^2 * (\l_@@_tmpa_fp)
5212 * \tl_item:Nn \l_@@_tmpa_tl {5}
5213 + 3 * (1 - \l_@@_tmpa_fp) * (\l_@@_tmpa_fp)^2
5214 * \tl_item:Nn \l_@@_tmpa_tl {8}
5215 + (\l_@@_tmpa_fp)^3 * \tl_item:Nn \l_@@_tmpa_tl {11}
5216 }}
5217 {\fp_to_dim:n
5218 {
5219 (1 - \l_@@_tmpa_fp)^3 * \tl_item:Nn \l_@@_tmpa_tl {3}
5220 + 3 * (1 - \l_@@_tmpa_fp)^2 * (\l_@@_tmpa_fp)
5221 * \tl_item:Nn \l_@@_tmpa_tl {6}
5222 + 3 * (1 - \l_@@_tmpa_fp) * (\l_@@_tmpa_fp)^2
5223 * \tl_item:Nn \l_@@_tmpa_tl {9}
5224 + (\l_@@_tmpa_fp)^3 * \tl_item:Nn \l_@@_tmpa_tl {12}
5225 }}
5226 }
5227 }
5228 }
5229 }
5230 }
5231
5232 \tl_gclear:N \g_@@_output_tl
5233 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpc_tl
5234 \group_end:
5235 }
5236 \cs_new_protected_nopar:Npn \spath_point_at:Nnn #1#2#3
5237 {
5238 \@@_point_at:nn {#2}{#3}
5239 \tl_set_eq:NN #1 \g_@@_output_tl
5240 \tl_gclear:N \g_@@_output_tl
5241 }
5242 \cs_generate_variant:Nn \spath_point_at:Nnn {NVn, NVV, NnV}
5243 \cs_new_protected_nopar:Npn \spath_gpoint_at:Nnn #1#2#3
5244 {
5245 \@@_point_at:nn {#2}{#3}
5246 \tl_gset_eq:NN #1 \g_@@_output_tl
5247 \tl_gclear:N \g_@@_output_tl
5248 }
5249 \cs_generate_variant:Nn \spath_gpoint_at:Nnn {NVn, NVV, NnV}
5250 % \end{macrocode}
5251 % \end{macro}
5252 %
5253 %
5254 % \begin{macro}[internal]{
5255 % \spath_tangent_at:Nnn,
5256 % \spath_gtangent_at:Nnn,
5257 % }
5258 %
5259 % Get the tangent at a point on a path, using the same location specification as the intersection library.
5260 % \begin{macrocode}
5261 \cs_new_protected_nopar:Npn \@@_tangent_at:nn #1#2
5262 {
5263 \group_begin:
5264 \int_set:Nn \l_@@_tmpa_int {\fp_to_int:n {floor(#2) + 1}}
5265 \fp_set:Nn \l_@@_tmpa_fp {#2 - floor(#2)}
5266
5267 \spath_segments_to_seq:Nn \l_@@_tmpa_seq {#1}
5268
5269 \int_compare:nTF
5270 {
5271 \l_@@_tmpa_int < 1
5272 }
5273 {
5274 \spath_initialpoint:Nn \l_@@_tmpc_tl {#1}
5275 }
5276 {
5277 \int_compare:nTF
5278 {
5279 \l_@@_tmpa_int > \seq_count:N \l_@@_tmpa_seq
5280 }
5281 {
5282 \spath_finalpoint:Nn \l_@@_tmpc_tl {#1}
5283 }
5284 {
5285
5286 \tl_set:Nx
5287 \l_@@_tmpa_tl
5288 {\seq_item:Nn \l_@@_tmpa_seq { \l_@@_tmpa_int} }
5289
5290 \int_compare:nTF
5291 {
5292 \tl_count:N \l_@@_tmpa_tl > 3
5293 }
5294 {
5295 \tl_set:Nx \l_@@_tmpb_tl {\tl_item:Nn \l_@@_tmpa_tl {4}}
5296 }
5297 {
5298 \tl_set:Nx \l_@@_tmpb_tl {\tl_item:Nn \l_@@_tmpa_tl {1}}
5299 }
5300
5301 \tl_clear:N \l_@@_tmpc_tl
5302
5303 \token_case_meaning:Nn \l_@@_tmpb_tl
5304 {
5305 \c_spath_moveto_tl
5306 {
5307 \tl_set:Nx \l_@@_tmpc_tl
5308 {
5309 {
5310 \tl_item:Nn \l_@@_tmpa_tl {2}
5311 }
5312 {
5313 \tl_item:Nn \l_@@_tmpa_tl {3}
5314 }
5315 }
5316 }
5317
5318 \c_spath_lineto_tl
5319 {
5320 \tl_set:Nx \l_@@_tmpc_tl
5321 {
5322 {\fp_to_dim:n
5323 {
5324 ( \tl_item:Nn \l_@@_tmpa_tl {5} )
5325 -
5326 ( \tl_item:Nn \l_@@_tmpa_tl {2} )
5327 }
5328 }
5329 {\fp_to_dim:n
5330 {
5331 ( \tl_item:Nn \l_@@_tmpa_tl {6} )
5332 -
5333 ( \tl_item:Nn \l_@@_tmpa_tl {3} )
5334 }
5335 }
5336 }
5337 }
5338
5339 \c_spath_rectsize_tl
5340 {
5341 \fp_compare:nTF
5342 {
5343 \l_@@_tmpa_fp <= .25
5344 }
5345 {
5346 \tl_set:Nx \l_@@_tmpc_tl
5347 {
5348 {\fp_to_dim:n
5349 {
5350 \tl_item:Nn \l_@@_tmpa_tl {5}
5351 }
5352 }
5353 {0pt}
5354 }
5355 }
5356 {
5357 \fp_compare:nTF
5358 {
5359 \l_@@_tmpa_fp <= .5
5360 }
5361 {
5362 \tl_set:Nx \l_@@_tmpc_tl
5363 {
5364 {0pt}
5365 {\fp_to_dim:n
5366 {
5367 ( \tl_item:Nn \l_@@_tmpa_tl {6} )
5368 }
5369 }
5370 }
5371 }
5372 {
5373 \fp_compare:nTF
5374 {
5375 \l_@@_tmpa_fp <= .75
5376 }
5377 {
5378 \tl_set:Nx \l_@@_tmpc_tl
5379 {
5380 {\fp_to_dim:n
5381 {
5382 -( \tl_item:Nn \l_@@_tmpa_tl {5} )
5383 }
5384 }
5385 {0pt}
5386 }
5387
5388 }
5389 {
5390 \tl_set:Nx \l_@@_tmpc_tl
5391 {
5392 {0pt}
5393 {\fp_to_dim:n
5394 {
5395 - ( \tl_item:Nn \l_@@_tmpa_tl {6} )
5396 }
5397 }
5398 }
5399 }
5400 }
5401 }
5402 }
5403
5404 \c_spath_closepath_tl
5405 {
5406 \tl_set:Nx \l_@@_tmpc_tl
5407 {
5408 {\fp_to_dim:n
5409 {
5410 ( \tl_item:Nn \l_@@_tmpa_tl {5} )
5411 -
5412 ( \tl_item:Nn \l_@@_tmpa_tl {2} )
5413 }
5414 }
5415 {\fp_to_dim:n
5416 {
5417 ( \tl_item:Nn \l_@@_tmpa_tl {6} )
5418 -
5419 ( \tl_item:Nn \l_@@_tmpa_tl {3} )
5420 }
5421 }
5422 }
5423 }
5424
5425 \c_spath_curvetoa_tl
5426 {
5427 \tl_set:Nx \l_@@_tmpc_tl
5428 {
5429 {\fp_to_dim:n
5430 {
5431 3*(1 - \l_@@_tmpa_fp)^2 * (\tl_item:Nn \l_@@_tmpa_tl {5}
5432 - \tl_item:Nn \l_@@_tmpa_tl {2})
5433 + 6 * (1 - \l_@@_tmpa_fp) * (\l_@@_tmpa_fp) *
5434 (\tl_item:Nn \l_@@_tmpa_tl {8}
5435 - \tl_item:Nn \l_@@_tmpa_tl {5})
5436 + 3*(\l_@@_tmpa_fp)^2 * (\tl_item:Nn \l_@@_tmpa_tl {11}
5437 - \tl_item:Nn \l_@@_tmpa_tl {8})
5438 }
5439 }
5440 {\fp_to_dim:n
5441 {
5442 3*(1 - \l_@@_tmpa_fp)^2 * (\tl_item:Nn \l_@@_tmpa_tl {6}
5443 - \tl_item:Nn \l_@@_tmpa_tl {3})
5444 + 6 * (1 - \l_@@_tmpa_fp) * (\l_@@_tmpa_fp) *
5445 (\tl_item:Nn \l_@@_tmpa_tl {9}
5446 - \tl_item:Nn \l_@@_tmpa_tl {6})
5447 + 3*(\l_@@_tmpa_fp)^2 * (\tl_item:Nn \l_@@_tmpa_tl {12}
5448 - \tl_item:Nn \l_@@_tmpa_tl {9})
5449 }}
5450 }
5451 }
5452 }
5453 }
5454 }
5455
5456 \tl_gclear:N \g_@@_output_tl
5457 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpc_tl
5458 \group_end:
5459 }
5460 \cs_new_protected_nopar:Npn \spath_tangent_at:Nnn #1#2#3
5461 {
5462 \@@_tangent_at:nn {#2}{#3}
5463 \tl_set_eq:NN #1 \g_@@_output_tl
5464 \tl_gclear:N \g_@@_output_tl
5465 }
5466 \cs_generate_variant:Nn \spath_tangent_at:Nnn {NVn, NVV, NnV}
5467 \cs_new_protected_nopar:Npn \spath_gtangent_at:Nnn #1#2#3
5468 {
5469 \@@_tangent_at:nn {#2}{#3}
5470 \tl_gset_eq:NN #1 \g_@@_output_tl
5471 \tl_gclear:N \g_@@_output_tl
5472 }
5473 \cs_generate_variant:Nn \spath_gtangent_at:Nnn {NVn, NVV, NnV}
5474 % \end{macrocode}
5475 % \end{macro}
5476 %
5477 %
5478 % \begin{macro}[internal]{
5479 % \spath_transformation_at:Nnn,
5480 % \spath_gtransformation_at:Nnn
5481 % }
5482 % Gets a transformation that will align to a point on the path with the x-axis along the path.
5483 % \begin{macrocode}
5484 \cs_new_protected_nopar:Npn \@@_transformation_at:nn #1#2
5485 {
5486 \group_begin:
5487 \tl_clear:N \l_@@_tmpa_tl
5488 \@@_tangent_at:nn {#1}{#2}
5489 \tl_set_eq:NN \l_@@_tmpb_tl \g_@@_output_tl
5490 \fp_set:Nn \l_@@_tmpa_fp
5491 {
5492 sqrt(
5493 (\tl_item:Nn \l_@@_tmpb_tl {1})^2
5494 +
5495 (\tl_item:Nn \l_@@_tmpb_tl {2})^2
5496 )
5497 }
5498 \fp_compare:nTF {\l_@@_tmpa_fp = 0}
5499 {
5500 \fp_set:Nn \l_@@_tmpa_fp {1}
5501 \fp_set:Nn \l_@@_tmpb_fp {0}
5502 }
5503 {
5504 \fp_set:Nn \l_@@_tmpb_fp
5505 { (\tl_item:Nn \l_@@_tmpb_tl {2}) / \l_@@_tmpa_fp }
5506 \fp_set:Nn \l_@@_tmpa_fp
5507 { (\tl_item:Nn \l_@@_tmpb_tl {1}) / \l_@@_tmpa_fp }
5508 }
5509 \tl_set:Nx \l_@@_tmpa_tl
5510 {
5511 { \fp_to_decimal:n { \l_@@_tmpa_fp } }
5512 { \fp_to_decimal:n { \l_@@_tmpb_fp } }
5513 { \fp_to_decimal:n {- \l_@@_tmpb_fp } }
5514 { \fp_to_decimal:n { \l_@@_tmpa_fp } }
5515 }
5516 \@@_point_at:nn {#1}{#2}
5517 \tl_put_right:NV \l_@@_tmpa_tl \g_@@_output_tl
5518 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
5519 \group_end:
5520 }
5521 \cs_new_protected_nopar:Npn \spath_transformation_at:Nnn #1#2#3
5522 {
5523 \@@_transformation_at:nn {#2}{#3}
5524 \tl_set_eq:NN #1 \g_@@_output_tl
5525 \tl_gclear:N \g_@@_output_tl
5526 }
5527 \cs_generate_variant:Nn \spath_transformation_at:Nnn {NVn, NVV, NnV, NvV}
5528 \cs_new_protected_nopar:Npn \spath_gtransformation_at:Nnn #1#2#3
5529 {
5530 \@@_transformation_at:nn {#2}{#3}
5531 \tl_gset_eq:NN #1 \g_@@_output_tl
5532 \tl_gclear:N \g_@@_output_tl
5533 }
5534 \cs_generate_variant:Nn \spath_gtransformation_at:Nnn {NVn, NVV, NnV}
5535 % \end{macrocode}
5536 % \end{macro}
5537 %
5538 % \subsection{Intersection Routines}
5539 %
5540 % Note: I'm not consistent with number schemes.
5541 % 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).
5542 % This should be more consistent.
5543 %
5544 % \begin{macro}[internal]{
5545 % \spath_intersect:NN,
5546 % \spath_intersect:nn,
5547 % }
5548 % Pass two spaths to pgf's intersection routine.
5549 % \begin{macrocode}
5550 \cs_new_protected_nopar:Npn \spath_intersect:NN #1#2
5551 {
5552 \pgfintersectionofpaths%
5553 {%
5554 \pgfsetpath #1
5555 }{%
5556 \pgfsetpath #2
5557 }
5558 }
5559 \cs_new_protected_nopar:Npn \spath_intersect:nn #1#2
5560 {
5561 \tl_set:Nn \l_@@_intersecta_tl {#1}
5562 \tl_set:Nn \l_@@_intersectb_tl {#2}
5563 \spath_intersect:NN \l_@@_intersecta_tl \l_@@_intersectb_tl
5564 }
5565 % \end{macrocode}
5566 % \end{macro}
5567 %
5568 % \begin{macro}[internal]{
5569 % \spath_split_component_at_intersections:Nnn
5570 % }
5571 % Split a component where it intersects a path.
5572 % Key assumption is that the first path is a single component, so if it is closed then the end joins up to the beginning.
5573 % The component is modified but the path is not.
5574 % \begin{macrocode}
5575 \cs_new_protected_nopar:Npn \@@_split_component_at_intersections:nn #1#2
5576 {
5577 \group_begin:
5578 \tl_clear:N \l_@@_tmpe_tl
5579 \seq_clear:N \l_@@_tmpb_seq
5580
5581 % Find the intersections of these segments
5582 \tl_set:Nn \l_@@_tmpb_tl {#1}
5583 \tl_set:Nn \l_@@_tmpc_tl {#2}
5584
5585 % Remember if the component is closed
5586 \spath_finalaction:NV \l_@@_tmpa_tl \l_@@_tmpb_tl
5587
5588 \bool_set:Nn \l_@@_closed_bool
5589 {
5590 \tl_if_eq_p:NN \l_@@_tmpa_tl \c_spath_closepath_tl
5591 ||
5592 \tl_if_eq_p:NN \l_@@_tmpa_tl \c_spath_rectcorner_tl
5593 }
5594
5595 % Open it
5596 \spath_open:N \l_@@_tmpb_tl
5597
5598 \spath_reallength:NV \l_@@_tmpa_int \l_@@_tmpb_tl
5599
5600 % Sort intersections along the component
5601 \pgfintersectionsortbyfirstpath
5602 \spath_intersect:NN \l_@@_tmpb_tl \l_@@_tmpc_tl
5603
5604 % If we get intersections
5605 \int_compare:nT {\pgfintersectionsolutions > 0}
5606 {
5607 % Find the times of the intersections on the component
5608 \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions}
5609 {
5610 \pgfintersectiongetsolutiontimes{##1}{\l_@@_tmph_tl}{\l_@@_tmpi_tl}
5611 \seq_put_left:NV \l_@@_tmpb_seq \l_@@_tmph_tl
5612 }
5613
5614 \seq_get_left:NN \l_@@_tmpb_seq \l_@@_tmpa_tl
5615 \fp_compare:nT
5616 {
5617 \l_@@_tmpa_tl > \l_@@_tmpa_int - .01
5618 }
5619 {
5620 \bool_set_false:N \l_@@_closed_bool
5621 }
5622
5623 \seq_get_right:NN \l_@@_tmpb_seq \l_@@_tmpa_tl
5624 \fp_compare:nT
5625 {
5626 \l_@@_tmpa_tl < .01
5627 }
5628 {
5629 \bool_set_false:N \l_@@_closed_bool
5630 }
5631
5632 \tl_set:Nn \l_@@_tmpg_tl {-1}
5633
5634 \seq_map_inline:Nn \l_@@_tmpb_seq
5635 {
5636 \tl_set:Nn \l_@@_tmph_tl {##1}
5637
5638 \tl_set_eq:NN \l_@@_tmpa_tl \l_@@_tmph_tl
5639 \int_compare:nT
5640 {
5641 \fp_to_int:n {floor( \l_@@_tmph_tl) }
5642 =
5643 \fp_to_int:n {floor( \l_@@_tmpg_tl) }
5644 }
5645 {
5646 \tl_set:Nx \l_@@_tmph_tl
5647 {
5648 \fp_eval:n {
5649 floor( \l_@@_tmph_tl )
5650 +
5651 ( \l_@@_tmph_tl - floor( \l_@@_tmph_tl) )
5652 /
5653 ( \l_@@_tmpg_tl - floor( \l_@@_tmpg_tl) )
5654 }
5655 }
5656 }
5657 \tl_set_eq:NN \l_@@_tmpg_tl \l_@@_tmpa_tl
5658
5659 \spath_split_at:NNVV
5660 \l_@@_tmpd_tl
5661 \l_@@_tmpf_tl
5662 \l_@@_tmpb_tl
5663 \l_@@_tmph_tl
5664
5665 \tl_put_left:NV \l_@@_tmpe_tl \l_@@_tmpf_tl
5666 \tl_set_eq:NN \l_@@_tmpb_tl \l_@@_tmpd_tl
5667
5668 }
5669
5670
5671 \tl_put_left:NV \l_@@_tmpe_tl \l_@@_tmpb_tl
5672
5673 \spath_remove_empty_components:N \l_@@_tmpe_tl
5674
5675 \tl_set_eq:NN \l_@@_tmpb_tl \l_@@_tmpe_tl
5676 }
5677
5678
5679 \bool_if:NT \l_@@_closed_bool
5680 {
5681 \spath_join_component:Nn \l_@@_tmpb_tl {1}
5682 }
5683
5684 \tl_gclear:N \g_@@_output_tl
5685 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpb_tl
5686
5687 \group_end:
5688 }
5689 \cs_new_protected_nopar:Npn \spath_split_component_at_intersections:Nnn #1#2#3
5690 {
5691 \@@_split_component_at_intersections:nn {#2}{#3}
5692 \tl_set_eq:NN #1 \g_@@_output_tl
5693 \tl_gclear:N \g_@@_output_tl
5694 }
5695 \cs_generate_variant:Nn \spath_split_component_at_intersections:Nnn {NVn, NVV}
5696 \cs_new_protected_nopar:Npn \spath_split_component_at_intersections:Nn #1#2
5697 {
5698 \spath_split_component_at_intersections:NVn #1#1{#2}
5699 }
5700 \cs_generate_variant:Nn \spath_split_component_at_intersections:Nn {cn, cv}
5701 \cs_new_protected_nopar:Npn \spath_gsplit_component_at_intersections:Nnn #1#2#3
5702 {
5703 \@@_split_component_at_intersections:nn {#2}{#3}
5704 \tl_gset_eq:NN #1 \g_@@_output_tl
5705 \tl_gclear:N \g_@@_output_tl
5706 }
5707 \cs_generate_variant:Nn \spath_gsplit_component_at_intersections:Nnn {NVn, NVV}
5708 \cs_new_protected_nopar:Npn \spath_gsplit_component_at_intersections:Nn #1#2
5709 {
5710 \spath_gsplit_component_at_intersections:NVn #1#1{#2}
5711 }
5712 \cs_generate_variant:Nn \spath_gsplit_component_at_intersections:Nn {cn, cv}
5713 % \end{macrocode}
5714 % \end{macro}
5715 %
5716 %
5717 % \begin{macro}[internal]{
5718 % \spath_split_path_at_intersections:Nnn,
5719 % \spath_split_path_at_intersections:Nn,
5720 % \spath_gsplit_path_at_intersections:Nnn,
5721 % \spath_gsplit_path_at_intersections:Nn,
5722 % \spath_split_at_intersections:NNnn,
5723 % \spath_split_at_intersections:NN,
5724 % \spath_gsplit_at_intersections:NNnn,
5725 % \spath_gsplit_at_intersections:NN,
5726 % }
5727 % Split paths at their intersections.
5728 % The \Verb+path+ versions only split the first path.
5729 % The others split both paths.
5730 % \begin{macrocode}
5731 \cs_new_protected_nopar:Npn \@@_split_path_at_intersections:nn #1#2
5732 {
5733 \group_begin:
5734
5735 \seq_clear:N \l_@@_tmpa_seq
5736 \seq_clear:N \l_@@_tmpb_seq
5737
5738 \spath_components_to_seq:Nn \l_@@_tmpa_seq {#1}
5739 \seq_map_inline:Nn \l_@@_tmpa_seq
5740 {
5741 \spath_split_component_at_intersections:Nnn \l_@@_tmpa_tl {##1} {#2}
5742 \seq_put_right:NV \l_@@_tmpb_seq \l_@@_tmpa_tl
5743 }
5744
5745 \tl_gclear:N \g_@@_output_tl
5746 \tl_gset:Nx \g_@@_output_tl {\seq_use:Nn \l_@@_tmpb_seq {} }
5747 \group_end:
5748 }
5749 \cs_new_protected_nopar:Npn \spath_split_path_at_intersections:Nnn #1#2#3
5750 {
5751 \@@_split_path_at_intersections:nn {#2}{#3}
5752 \tl_set_eq:NN #1 \g_@@_output_tl
5753 \tl_gclear:N \g_@@_output_tl
5754 }
5755 \cs_generate_variant:Nn \spath_split_path_at_intersections:Nnn
5756 {NVn, NVV, cVn, cVV, cvn, cvv}
5757 \cs_new_protected_nopar:Npn \spath_split_path_at_intersections:Nn #1#2
5758 {
5759 \spath_split_path_at_intersections:NVn #1#1{#2}
5760 }
5761 \cs_generate_variant:Nn \spath_split_path_at_intersections:Nn {cv, NV}
5762 \cs_new_protected_nopar:Npn \spath_gsplit_path_at_intersections:Nnn #1#2#3
5763 {
5764 \@@_split_path_at_intersections:nn {#2}{#3}
5765 \tl_gset_eq:NN #1 \g_@@_output_tl
5766 \tl_gclear:N \g_@@_output_tl
5767 }
5768 \cs_generate_variant:Nn \spath_gsplit_path_at_intersections:Nnn
5769 {NVn, NVV, cVn, cVV, cvn, cvv}
5770 \cs_new_protected_nopar:Npn \spath_gsplit_path_at_intersections:Nn #1#2
5771 {
5772 \spath_gsplit_path_at_intersections:NVn #1#1{#2}
5773 }
5774 \cs_generate_variant:Nn \spath_gsplit_path_at_intersections:Nn {cv, NV}
5775 \cs_new_protected_nopar:Npn \spath_split_at_intersections:NNnn #1#2#3#4
5776 {
5777 \@@_split_path_at_intersections:nn {#3}{#4}
5778 \tl_set_eq:NN #1 \g_@@_output_tl
5779 \@@_split_path_at_intersections:nn {#4}{#3}
5780 \tl_set_eq:NN #2 \g_@@_output_tl
5781 \tl_gclear:N \g_@@_output_tl
5782 }
5783 \cs_generate_variant:Nn \spath_split_at_intersections:NNnn
5784 {NNVn, NNVV, ccVn, ccVV, ccvn, ccvv}
5785 \cs_new_protected_nopar:Npn \spath_split_at_intersections:NN #1#2
5786 {
5787 \spath_split_at_intersections:NNVV #1#2#1#2
5788 }
5789 \cs_generate_variant:Nn \spath_split_at_intersections:NN {cc}
5790 \cs_new_protected_nopar:Npn \spath_gsplit_at_intersections:NNnn #1#2#3#4
5791 {
5792 \@@_split_path_at_intersections:nn {#3}{#4}
5793 \tl_gset_eq:NN #1 \g_@@_output_tl
5794 \@@_split_path_at_intersections:nn {#4}{#3}
5795 \tl_gset_eq:NN #2 \g_@@_output_tl
5796 \tl_gclear:N \g_@@_output_tl
5797 }
5798 \cs_generate_variant:Nn \spath_gsplit_at_intersections:NNnn
5799 {NNVn, NNVV, ccVn, ccVV, ccvn, ccvv}
5800 \cs_new_protected_nopar:Npn \spath_gsplit_at_intersections:NN #1#2
5801 {
5802 \spath_gsplit_at_intersections:NNVV #1#2#1#2
5803 }
5804 \cs_generate_variant:Nn \spath_gsplit_at_intersections:NN {cc}
5805 % \end{macrocode}
5806 % \end{macro}
5807 %
5808 %
5809 % \begin{macro}[internal]{
5810 % \spath_split_component_at_self_intersections:Nn,
5811 % \spath_split_component_at_self_intersections:N,
5812 % \spath_gsplit_component_at_self_intersections:Nn,
5813 % \spath_gsplit_component_at_self_intersections:N,
5814 % }
5815 % Given a component of a path, split it at points where it self-intersects.
5816 % \begin{macrocode}
5817 \cs_new_protected_nopar:Npn \@@_split_component_at_self_intersections:n #1
5818 {
5819 \group_begin:
5820 \tl_set:Nn \l_@@_tmpe_tl {#1}
5821
5822 % Remember if the component is closed
5823 \spath_finalaction:NV \l_@@_tmpa_tl \l_@@_tmpe_tl
5824
5825 \bool_set:Nn \l_@@_closed_bool
5826 {
5827 \tl_if_eq_p:NN \l_@@_tmpa_tl \c_spath_closepath_tl
5828 }
5829
5830 % Copy the path
5831 \tl_set:Nn \l_@@_tmpe_tl {#1}
5832
5833 % Open the path
5834 \spath_open:N \l_@@_tmpe_tl
5835 % Ensure beziers don't self-intersect
5836 \spath_split_curves:N \l_@@_tmpe_tl
5837
5838 % Make a copy for later
5839 \tl_set_eq:NN \l_@@_tmpg_tl \l_@@_tmpe_tl
5840
5841 % Clear some token lists and sequences
5842 \tl_clear:N \l_@@_tmpd_tl
5843 \seq_clear:N \l_@@_tmpb_seq
5844 \int_zero:N \l_@@_tmpa_int
5845
5846 \pgfintersectionsortbyfirstpath
5847
5848 % Split the path into a sequence of segments
5849 \spath_segments_to_seq:NV \l_@@_tmpa_seq \l_@@_tmpe_tl
5850
5851 \seq_map_indexed_inline:Nn \l_@@_tmpa_seq
5852 {
5853 \seq_map_indexed_inline:Nn \l_@@_tmpa_seq
5854 {
5855 % Don't intersect a segment with itself
5856 \int_compare:nF
5857 {
5858 ##1 == ####1
5859 }
5860 {
5861 \spath_intersect:nn {##2} {####2}
5862
5863 \int_compare:nT {\pgfintersectionsolutions > 0}
5864 {
5865 % Find the times of the intersections on each path
5866 \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions}
5867 {
5868 \pgfintersectiongetsolutiontimes
5869 {########1}{\l_@@_tmpb_tl}{\l_@@_tmpc_tl}
5870
5871 \bool_if:nT
5872 {
5873 !(
5874 \fp_compare_p:n { \l_@@_tmpb_tl > .99 }
5875 &&
5876 \int_compare_p:n {##1 + 1 == ####1}
5877 )
5878 &&
5879 !(
5880 \fp_compare_p:n { \l_@@_tmpb_tl < .01 }
5881 &&
5882 \int_compare_p:n {##1 - 1 == ####1}
5883 )
5884 &&
5885 !(
5886 \l_@@_closed_bool
5887 &&
5888 \fp_compare_p:n { \l_@@_tmpb_tl < .01 }
5889 &&
5890 \int_compare_p:n {##1 == 1}
5891 &&
5892 \int_compare_p:n {\seq_count:N \l_@@_tmpa_seq == ####1}
5893 )
5894 &&
5895 !(
5896 \l_@@_closed_bool
5897 &&
5898 \fp_compare_p:n { \l_@@_tmpb_tl > .99 }
5899 &&
5900 \int_compare_p:n {####1 == 1}
5901 &&
5902 \int_compare_p:n {\seq_count:N \l_@@_tmpa_seq == ##1}
5903 )
5904 }
5905 {
5906 \tl_set:Nx \l_@@_tmpa_tl
5907 {\fp_to_decimal:n {\l_@@_tmpb_tl + ##1 - 1}}
5908 \seq_put_right:NV \l_@@_tmpb_seq \l_@@_tmpa_tl
5909 }
5910 }
5911 }
5912 }
5913 }
5914 }
5915
5916 % Sort the sequence by reverse order along the path
5917 \seq_sort:Nn \l_@@_tmpb_seq
5918 {
5919 \fp_compare:nNnTF { ##1 } < { ##2 }
5920 { \sort_return_swapped: }
5921 { \sort_return_same: }
5922 }
5923
5924 \seq_get_left:NN \l_@@_tmpb_seq \l_@@_tmpa_tl
5925 \fp_compare:nT
5926 {
5927 \l_@@_tmpa_tl > \seq_count:N \l_@@_tmpa_seq - .01
5928 }
5929 {
5930 \bool_set_false:N \l_@@_closed_bool
5931 }
5932 \seq_get_right:NN \l_@@_tmpb_seq \l_@@_tmpa_tl
5933 \fp_compare:nT
5934 {
5935 \l_@@_tmpa_tl < .01
5936 }
5937 {
5938 \bool_set_false:N \l_@@_closed_bool
5939 }
5940
5941 % Restore the original copy of the path
5942 \tl_set_eq:NN \l_@@_tmpe_tl \l_@@_tmpg_tl
5943
5944 % Clear the token lists
5945 \tl_clear:N \l_@@_tmpf_tl
5946 \tl_clear:N \l_@@_tmph_tl
5947 \tl_clear:N \l_@@_tmpg_tl
5948
5949 \tl_set:Nn \l_@@_tmpi_tl {-1}
5950
5951 \seq_map_inline:Nn \l_@@_tmpb_seq
5952 {
5953 \tl_set:Nn \l_@@_tmpb_tl {##1}
5954 \tl_set_eq:NN \l_@@_tmpa_tl \l_@@_tmpb_tl
5955 \int_compare:nT
5956 {
5957 \fp_to_int:n {floor( \l_@@_tmpb_tl ) }
5958 =
5959 \fp_to_int:n {floor( \l_@@_tmpi_tl) }
5960 }
5961 {
5962 \tl_set:Nx \l_@@_tmpb_tl
5963 {
5964 \fp_eval:n {
5965 floor( \l_@@_tmpb_tl )
5966 +
5967 ( \l_@@_tmpb_tl - floor( \l_@@_tmpb_tl) )
5968 /
5969 ( \l_@@_tmpi_tl - floor( \l_@@_tmpi_tl) )
5970 }
5971 }
5972 }
5973 \tl_set_eq:NN \l_@@_tmpi_tl \l_@@_tmpa_tl
5974
5975 \spath_split_at:NNVV
5976 \l_@@_tmpf_tl
5977 \l_@@_tmph_tl
5978 \l_@@_tmpe_tl
5979 \l_@@_tmpb_tl
5980
5981 \tl_put_left:NV \l_@@_tmpg_tl \l_@@_tmph_tl
5982 \tl_set_eq:NN \l_@@_tmpe_tl \l_@@_tmpf_tl
5983
5984 }
5985
5986 \tl_put_left:NV \l_@@_tmpg_tl \l_@@_tmpe_tl
5987
5988 \tl_if_empty:NT \l_@@_tmpg_tl
5989 {
5990 \tl_set_eq:NN \l_@@_tmpg_tl \l_@@_tmpe_tl
5991 }
5992
5993 \spath_remove_empty_components:N \l_@@_tmpg_tl
5994
5995 % Do something with closed
5996 \bool_if:NT \l_@@_closed_bool
5997 {
5998 \spath_join_component:Nn \l_@@_tmpg_tl {1}
5999 }
6000
6001 \tl_gclear:N \g_@@_output_tl
6002 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpg_tl
6003 \group_end:
6004 }
6005 \cs_new_protected_nopar:Npn \spath_split_component_at_self_intersections:Nn #1#2
6006 {
6007 \@@_split_component_at_self_intersections:n {#2}
6008 \tl_set_eq:NN #1 \g_@@_output_tl
6009 \tl_gclear:N \g_@@_output_tl
6010 }
6011 \cs_generate_variant:Nn \spath_split_component_at_self_intersections:Nn {NV}
6012 \cs_new_protected_nopar:Npn \spath_split_component_at_self_intersections:N #1
6013 {
6014 \spath_split_component_at_self_intersections:NV #1#1
6015 }
6016 \cs_generate_variant:Nn \spath_split_component_at_self_intersections:N {c}
6017 \cs_new_protected_nopar:Npn \spath_gsplit_component_at_self_intersections:Nn #1#2
6018 {
6019 \@@_split_component_at_self_intersections:n {#2}
6020 \tl_gset_eq:NN #1 \g_@@_output_tl
6021 \tl_gclear:N \g_@@_output_tl
6022 }
6023 \cs_generate_variant:Nn \spath_gsplit_component_at_self_intersections:Nn {NV}
6024 \cs_new_protected_nopar:Npn \spath_gsplit_component_at_self_intersections:N #1
6025 {
6026 \spath_gsplit_component_at_self_intersections:NV #1#1
6027 }
6028 \cs_generate_variant:Nn \spath_gsplit_component_at_self_intersections:N {c}
6029 % \end{macrocode}
6030 % \end{macro}
6031 %
6032 % \begin{macro}[internal]{
6033 % \spath_split_at_self_intersections:Nn,
6034 % \spath_split_at_self_intersections:N,
6035 % \spath_gsplit_at_self_intersections:Nn,
6036 % \spath_gsplit_at_self_intersections:N,
6037 % }
6038 % Split a path at its self intersections.
6039 % We iterate over the components, splitting each where it meets all the others and itself.
6040 % To make this more efficient, we split against the components of the original path rather than updating each time.
6041 %
6042 % \begin{macrocode}
6043 \cs_new_protected_nopar:Npn \@@_split_at_self_intersections:n #1
6044 {
6045 \group_begin:
6046 \spath_components_to_seq:Nn \l_@@_tmpa_seq {#1}
6047 \seq_clear:N \l_@@_tmpb_seq
6048 \seq_clear:N \l_@@_tmpc_seq
6049
6050 % Iterate over the components of the original path.
6051 \bool_do_until:nn
6052 {
6053 \seq_if_empty_p:N \l_@@_tmpa_seq
6054 }
6055 {
6056 % Get the next component
6057 \seq_pop_left:NN \l_@@_tmpa_seq \l_@@_tmpa_tl
6058 % Copy for later
6059 \tl_set_eq:NN \l_@@_tmpc_tl \l_@@_tmpa_tl
6060 \int_compare:nT
6061 {
6062 \tl_count:N \l_@@_tmpa_tl > 3
6063 }
6064 {
6065
6066 % Split against itself
6067 \spath_split_component_at_self_intersections:N \l_@@_tmpa_tl
6068 % Grab the rest of the path
6069 \tl_set:Nx \l_@@_tmpb_tl
6070 {
6071 \seq_use:Nn \l_@@_tmpb_seq {}
6072 \seq_use:Nn \l_@@_tmpa_seq {}
6073 }
6074 % Split against the rest of the path
6075 \spath_split_path_at_intersections:NV \l_@@_tmpa_tl \l_@@_tmpb_tl
6076 }
6077 % Save the split path
6078 \seq_put_right:NV \l_@@_tmpc_seq \l_@@_tmpa_tl
6079 % Add the original copy to the sequence of processed components
6080 \seq_put_right:NV \l_@@_tmpb_seq \l_@@_tmpc_tl
6081 }
6082
6083 \tl_gclear:N \g_@@_output_tl
6084 \tl_gset:Nx \g_@@_output_tl {\seq_use:Nn \l_@@_tmpc_seq {} }
6085 \group_end:
6086 }
6087 \cs_generate_variant:Nn \@@_split_at_self_intersections:n {V, v}
6088 \cs_new_protected_nopar:Npn \spath_split_at_self_intersections:Nn #1#2
6089 {
6090 \@@_split_at_self_intersections:n {#2}
6091 \tl_set_eq:NN #1 \g_@@_output_tl
6092 \tl_gclear:N \g_@@_output_tl
6093 }
6094 \cs_generate_variant:Nn \spath_split_at_self_intersections:Nn {NV, cn, cV, cv}
6095 \cs_new_protected_nopar:Npn \spath_split_at_self_intersections:N #1
6096 {
6097 \spath_split_at_self_intersections:NV #1#1
6098 }
6099 \cs_generate_variant:Nn \spath_split_at_self_intersections:N {c}
6100 \cs_new_protected_nopar:Npn \spath_gsplit_at_self_intersections:Nn #1#2
6101 {
6102 \@@_split_at_self_intersections:n {#2}
6103 \tl_gset_eq:NN #1 \g_@@_output_tl
6104 \tl_gclear:N \g_@@_output_tl
6105 }
6106 \cs_generate_variant:Nn \spath_gsplit_at_self_intersections:Nn {NV, cn, cV, cv}
6107 \cs_new_protected_nopar:Npn \spath_gsplit_at_self_intersections:N #1
6108 {
6109 \spath_gsplit_at_self_intersections:NV #1#1
6110 }
6111 \cs_generate_variant:Nn \spath_gsplit_at_self_intersections:N {c}
6112 % \end{macrocode}
6113 % \end{macro}
6114 %
6115 % \begin{macro}[internal]{
6116 % \spath_join_component:Nnn,
6117 % \spath_join_component:Nn,
6118 % \spath_gjoin_component:Nnn,
6119 % \spath_gjoin_component:Nn,
6120 % }
6121 % Join the specified component of the spath to its predecessor.
6122 % \begin{macrocode}
6123 \cs_new_protected_nopar:Npn \@@_join_component:nn #1#2
6124 {
6125 \group_begin:
6126 \spath_numberofcomponents:Nn \l_@@_tmpa_int {#1}
6127
6128 \bool_if:nTF
6129 {
6130 \int_compare_p:n { #2 >= 1 }
6131 &&
6132 \int_compare_p:n { #2 <= \l_@@_tmpa_int }
6133 }
6134 {
6135 \int_compare:nTF
6136 {
6137 #2 == 1
6138 }
6139 {
6140 \int_compare:nTF
6141 {
6142 \l_@@_tmpa_int == 1
6143 }
6144 {
6145 \tl_set:Nn \l_@@_tmpa_tl {#1}
6146 \spath_initialpoint:Nn \l_@@_tmpb_tl {#1}
6147 \tl_put_right:NV \l_@@_tmpa_tl \c_spath_closepath_tl
6148 \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpb_tl
6149 \tl_gclear:N \g_@@_output_tl
6150 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
6151 }
6152 {
6153 \spath_components_to_seq:Nn \l_@@_tmpa_seq {#1}
6154 \seq_pop_left:NN \l_@@_tmpa_seq \l_@@_tmpa_tl
6155
6156 \prg_replicate:nn {3}
6157 {
6158 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
6159 }
6160
6161 \seq_put_right:NV \l_@@_tmpa_seq \l_@@_tmpa_tl
6162
6163 \tl_gclear:N \g_@@_output_tl
6164 \tl_gset:Nx \g_@@_output_tl {\seq_use:Nn \l_@@_tmpa_seq {}}
6165 }
6166 }
6167 {
6168 \spath_components_to_seq:Nn \l_@@_tmpa_seq {#1}
6169
6170 \seq_clear:N \l_@@_tmpb_seq
6171 \seq_map_indexed_inline:Nn \l_@@_tmpa_seq
6172 {
6173 \tl_set:Nn \l_@@_tmpa_tl {##2}
6174 \int_compare:nT {##1 = #2}
6175 {
6176 \prg_replicate:nn {3}
6177 {
6178 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
6179 }
6180 }
6181 \seq_put_right:NV \l_@@_tmpb_seq \l_@@_tmpa_tl
6182 }
6183
6184 \tl_gclear:N \g_@@_output_tl
6185 \tl_gset:Nx \g_@@_output_tl {\seq_use:Nn \l_@@_tmpb_seq {}}
6186 }
6187 }
6188 {
6189 \tl_gclear:N \g_@@_output_tl
6190 \tl_gset:Nn \g_@@_output_tl {#1}
6191 }
6192
6193 \group_end:
6194 }
6195 \cs_new_protected_nopar:Npn \spath_join_component:Nnn #1#2#3
6196 {
6197 \@@_join_component:nn {#2}{#3}
6198 \tl_set_eq:NN #1 \g_@@_output_tl
6199 \tl_gclear:N \g_@@_output_tl
6200 }
6201 \cs_generate_variant:Nn \spath_join_component:Nnn {NVn, NVV}
6202 \cs_new_protected_nopar:Npn \spath_join_component:Nn #1#2
6203 {
6204 \spath_join_component:NVn #1#1{#2}
6205 }
6206 \cs_generate_variant:Nn \spath_join_component:Nn {cn, NV, cV}
6207 \cs_new_protected_nopar:Npn \spath_gjoin_component:Nnn #1#2#3
6208 {
6209 \@@_join_component:nn {#2}{#3}
6210 \tl_gset_eq:NN #1 \g_@@_output_tl
6211 \tl_gclear:N \g_@@_output_tl
6212 }
6213 \cs_generate_variant:Nn \spath_gjoin_component:Nnn {NVn, NVV}
6214 \cs_new_protected_nopar:Npn \spath_gjoin_component:Nn #1#2
6215 {
6216 \spath_gjoin_component:NVn #1#1{#2}
6217 }
6218 \cs_generate_variant:Nn \spath_gjoin_component:Nn {cn, NV, cV}
6219 % \end{macrocode}
6220 % \end{macro}
6221 %
6222 % \begin{macro}[internal]{
6223 % \spath_spot_weld_components:Nn,
6224 % \spath_spot_weld_components:N,
6225 % \spath_spot_gweld_components:Nn,
6226 % \spath_spot_gweld_components:N,
6227 % }
6228 % Weld together any components where the last point of one is at the start point of the next (within a tolerance).
6229 % \begin{macrocode}
6230 \cs_new_protected_nopar:Npn \@@_spot_weld_components:n #1
6231 {
6232 \group_begin:
6233 \dim_zero:N \l_@@_move_x_dim
6234 \dim_zero:N \l_@@_move_y_dim
6235
6236 \spath_components_to_seq:Nn \l_@@_tmpa_seq {#1}
6237 \seq_clear:N \l_@@_tmpb_seq
6238 \dim_set:Nn \l_@@_move_x_dim {\tl_item:nn {#1} {2} + 10 pt}
6239 \dim_set:Nn \l_@@_move_y_dim {\tl_item:nn {#1} {3} + 10 pt}
6240
6241 \int_set:Nn \l_@@_tmpa_int {\seq_count:N \l_@@_tmpa_seq}
6242
6243 \seq_map_inline:Nn \l_@@_tmpa_seq
6244 {
6245 \tl_set:Nn \l_@@_tmpa_tl {##1}
6246 \bool_if:nT
6247 {
6248 \dim_compare_p:n
6249 {
6250 \dim_abs:n
6251 {\l_@@_move_x_dim - \tl_item:Nn \l_@@_tmpa_tl {2} }
6252 < 0.01pt
6253 }
6254 &&
6255 \dim_compare_p:n
6256 {
6257 \dim_abs:n
6258 {\l_@@_move_y_dim - \tl_item:Nn \l_@@_tmpa_tl {3} }
6259 < 0.01pt
6260 }
6261 }
6262 {
6263 \prg_replicate:nn {3}
6264 {
6265 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
6266 }
6267 \int_decr:N \l_@@_tmpa_int
6268 }
6269 \tl_reverse:N \l_@@_tmpa_tl
6270 \dim_set:Nn \l_@@_move_x_dim {\tl_item:Nn \l_@@_tmpa_tl {2}}
6271 \dim_set:Nn \l_@@_move_y_dim {\tl_item:Nn \l_@@_tmpa_tl {1}}
6272 \tl_reverse:N \l_@@_tmpa_tl
6273 \seq_put_right:NV \l_@@_tmpb_seq \l_@@_tmpa_tl
6274 }
6275
6276 \tl_set:Nx \l_@@_tmpa_tl {\seq_use:Nn \l_@@_tmpb_seq {} }
6277 \spath_components_to_seq:NV \l_@@_tmpb_seq \l_@@_tmpa_tl
6278
6279
6280 \spath_initialpoint:Nn \l_@@_tmpa_tl {#1}
6281 \spath_finalpoint:Nn \l_@@_tmpb_tl {#1}
6282
6283 \bool_if:nT
6284 {
6285 \dim_compare_p:n
6286 {
6287 \dim_abs:n
6288 {
6289 \tl_item:Nn \l_@@_tmpa_tl {1} - \tl_item:Nn \l_@@_tmpb_tl {1}
6290 }
6291 <
6292 0.01pt
6293 }
6294 &&
6295 \dim_compare_p:n
6296 {
6297 \dim_abs:n
6298 {
6299 \tl_item:Nn \l_@@_tmpa_tl {2} - \tl_item:Nn \l_@@_tmpb_tl {2}
6300 }
6301 <
6302 0.01pt
6303 }
6304 }
6305 {
6306 \int_compare:nTF
6307 {
6308 \seq_count:N \l_@@_tmpb_seq > 1
6309 }
6310 {
6311 \seq_pop_left:NN \l_@@_tmpb_seq \l_@@_tmpb_tl
6312
6313 \prg_replicate:nn {3}
6314 {
6315 \tl_set:Nx \l_@@_tmpb_tl {\tl_tail:N \l_@@_tmpb_tl}
6316 }
6317 \seq_put_right:NV \l_@@_tmpb_seq \l_@@_tmpb_tl
6318 }
6319 {
6320 \tl_set:NV \l_@@_tmpb_tl \c_spath_closepath_tl
6321 \tl_put_right:Nx \l_@@_tmpb_tl
6322 {
6323 { \tl_item:Nn \l_@@_tmpa_tl {1} }
6324 { \tl_item:Nn \l_@@_tmpa_tl {2} }
6325 }
6326 \seq_put_right:NV \l_@@_tmpb_seq \l_@@_tmpb_tl
6327 }
6328 }
6329
6330 \tl_gset:Nx \g_@@_output_tl {\seq_use:Nn \l_@@_tmpb_seq {}}
6331 \group_end:
6332 }
6333 \cs_new_protected_nopar:Npn \spath_spot_weld_components:Nn #1#2
6334 {
6335 \@@_spot_weld_components:n {#2}
6336 \tl_set_eq:NN #1 \g_@@_output_tl
6337 \tl_gclear:N \g_@@_output_tl
6338 }
6339 \cs_generate_variant:Nn \spath_spot_weld_components:Nn {NV, cV, cn}
6340 \cs_new_protected_nopar:Npn \spath_spot_weld_components:N #1
6341 {
6342 \spath_spot_weld_components:NV #1#1
6343 }
6344 \cs_generate_variant:Nn \spath_spot_weld_components:N {c}
6345 \cs_new_protected_nopar:Npn \spath_spot_gweld_components:Nn #1#2
6346 {
6347 \@@_spot_weld_components:n {#2}
6348 \tl_gset_eq:NN #1 \g_@@_output_tl
6349 \tl_gclear:N \g_@@_output_tl
6350 }
6351 \cs_generate_variant:Nn \spath_spot_gweld_components:Nn {NV, cV, cn}
6352 \cs_new_protected_nopar:Npn \spath_spot_gweld_components:N #1
6353 {
6354 \spath_spot_gweld_components:NV #1#1
6355 }
6356 \cs_generate_variant:Nn \spath_spot_gweld_components:N {c}
6357 % \end{macrocode}
6358 % \end{macro}
6359 %
6360 % \subsection{Exporting Commands}
6361 %
6362 % \begin{macro}[internal]{
6363 % \spath_convert_to_svg:Nn,
6364 % \spath_gconvert_to_svg:Nn,
6365 % }
6366 % Convert the soft path to an SVG document.
6367 % \begin{macrocode}
6368 \cs_new_protected_nopar:Npn \@@_convert_to_svg:n #1
6369 {
6370 \group_begin:
6371 \tl_clear:N \l_@@_tmpa_tl
6372 \tl_put_right:Nn \l_@@_tmpa_tl
6373 {
6374 <?xml~ version="1.0"~ standalone="no"?>
6375 \iow_newline:
6376 <!DOCTYPE~ svg~ PUBLIC~ "-//W3C//DTD SVG 1.1//EN"~
6377 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
6378 \iow_newline:
6379 <svg~ xmlns="http://www.w3.org/2000/svg"~ version="1.1"~viewBox="
6380 }
6381
6382 \spath_minbb:Nn \l_@@_tmpb_tl {#1}
6383 \spath_maxbb:Nn \l_@@_tmpc_tl {#1}
6384 \tl_put_right:Nx \l_@@_tmpa_tl
6385 {
6386 \dim_to_decimal:n
6387 {
6388 \tl_item:Nn \l_@@_tmpb_tl {1} - 10pt
6389 }
6390 \exp_not:n {~}
6391 \dim_to_decimal:n
6392 {
6393 \tl_item:Nn \l_@@_tmpb_tl {2} - 10pt
6394 }
6395 \exp_not:n {~}
6396 \dim_to_decimal:n
6397 {
6398 \tl_item:Nn \l_@@_tmpc_tl {1}
6399 -
6400 \tl_item:Nn \l_@@_tmpb_tl {1}
6401 + 20pt
6402 }
6403 \exp_not:n {~}
6404 \dim_to_decimal:n
6405 {
6406 \tl_item:Nn \l_@@_tmpc_tl {2}
6407 -
6408 \tl_item:Nn \l_@@_tmpb_tl {2}
6409 + 20pt
6410 }
6411 }
6412
6413 \tl_put_right:Nn \l_@@_tmpa_tl
6414 {
6415 ">
6416 \iow_newline:
6417 <path~ d="
6418 }
6419 \tl_set:Nn \l_@@_tmpc_tl {use:n}
6420 \tl_map_inline:nn {#1}
6421 {
6422 \tl_set:Nn \l_@@_tmpb_tl {##1}
6423 \token_case_meaning:NnF \l_@@_tmpb_tl
6424 {
6425 \c_spath_moveto_tl
6426 {
6427 \tl_put_right:Nn \l_@@_tmpa_tl {M~}
6428 \tl_set:Nn \l_@@_tmpc_tl {use:n}
6429 }
6430 \c_spath_lineto_tl
6431 {
6432 \tl_put_right:Nn \l_@@_tmpa_tl {L~}
6433 \tl_set:Nn \l_@@_tmpc_tl {use:n}
6434 }
6435 \c_spath_closepath_tl
6436 {
6437 \tl_put_right:Nn \l_@@_tmpa_tl {Z~}
6438 \tl_set:Nn \l_@@_tmpc_tl {use_none:n}
6439 }
6440 \c_spath_curvetoa_tl
6441 {
6442 \tl_put_right:Nn \l_@@_tmpa_tl {C~}
6443 \tl_set:Nn \l_@@_tmpc_tl {use:n}
6444 }
6445 \c_spath_curvetob_tl {
6446 \tl_set:Nn \l_@@_tmpc_tl {use:n}
6447 }
6448 \c_spath_curveto_tl {
6449 \tl_set:Nn \l_@@_tmpc_tl {use:n}
6450 }
6451 }
6452 {
6453 \tl_put_right:Nx
6454 \l_@@_tmpa_tl
6455 {\use:c { \l_@@_tmpc_tl } {\dim_to_decimal:n {##1}} ~}
6456 }
6457 }
6458 \tl_put_right:Nn \l_@@_tmpa_tl
6459 {
6460 "~ fill="none"~ stroke="black"~ />
6461 \iow_newline:
6462 </svg>
6463 \iow_newline:
6464 }
6465 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
6466 \group_end:
6467 }
6468 \cs_new_protected_nopar:Npn \spath_convert_to_svg:Nn #1#2
6469 {
6470 \@@_convert_to_svg:n {#2}
6471 \tl_set_eq:NN #1 \g_@@_output_tl
6472 \tl_gclear:N \g_@@_output_tl
6473 }
6474 \cs_new_protected_nopar:Npn \spath_gconvert_to_svg:Nn #1#2
6475 {
6476 \@@_convert_to_svg:n {#2}
6477 \tl_gset_eq:NN #1 \g_@@_output_tl
6478 \tl_gclear:N \g_@@_output_tl
6479 }
6480 % \end{macrocode}
6481 % \end{macro}
6482 %
6483 % \begin{macro}[internal]{
6484 % \spath_export_to_svg:nn
6485 % }
6486 % Save a soft path to an SVG file.
6487 % \begin{macrocode}
6488 \iow_new:N \g_@@_stream
6489 \cs_new_protected_nopar:Npn \spath_export_to_svg:nn #1#2
6490 {
6491 \group_begin:
6492 \spath_convert_to_svg:Nn \l_@@_tmpa_tl {#2}
6493 \iow_open:Nn \g_@@_stream {#1 .svg}
6494 \iow_now:Nx \g_@@_stream
6495 {
6496 \tl_use:N \l_@@_tmpa_tl
6497 }
6498 \iow_close:N \g_@@_stream
6499 \group_end:
6500 }
6501 \cs_generate_variant:Nn \spath_export_to_svg:nn {nv, nV}
6502 % \end{macrocode}
6503 % \end{macro}
6504 %
6505 % \begin{macro}[internal]{\spath_show:n}
6506 % Displays the soft path on the terminal.
6507 % \begin{macrocode}
6508 \cs_new_protected_nopar:Npn \spath_show:n #1
6509 {
6510 \int_step_inline:nnnn {1} {3} {\tl_count:n {#1}}
6511 {
6512 \iow_term:x {
6513 \tl_item:nn {#1} {##1}
6514 {\tl_item:nn {#1} {##1+1}}
6515 {\tl_item:nn {#1} {##1+2}}
6516 }
6517 }
6518 }
6519 \cs_generate_variant:Nn \spath_show:n {V, v}
6520 % \end{macrocode}
6521 % \end{macro}
6522 %
6523 % \subsection{PGF and TikZ Interface Functions}
6524 %
6525 % Spaths come from PGF so we need some functions that get and set spaths from the pgf system.
6526 %
6527 % \begin{macro}[internal]{
6528 % \spath_get_current_path:N,
6529 % \spath_gget_current_path:N
6530 % }
6531 % Grab the current soft path from PGF.
6532 % \begin{macrocode}
6533 \cs_new_protected_nopar:Npn \spath_get_current_path:N #1
6534 {
6535 \pgfsyssoftpath@getcurrentpath #1
6536 }
6537 \cs_generate_variant:Nn \spath_get_current_path:N {c}
6538 % \end{macrocode}
6539 %
6540 % \begin{macrocode}
6541 \cs_new_protected_nopar:Npn \spath_gget_current_path:N #1
6542 {
6543 \pgfsyssoftpath@getcurrentpath #1
6544 \tl_gset_eq:NN #1 #1
6545 }
6546 \cs_generate_variant:Nn \spath_gget_current_path:N {c}
6547 % \end{macrocode}
6548 % \end{macro}
6549 %
6550 % \begin{macro}[internal]{\spath_protocol_path:n}
6551 % This feeds the bounding box of the soft path to PGF to ensure that its current bounding box contains the soft path.
6552 % \begin{macrocode}
6553 \cs_new_protected_nopar:Npn \spath_protocol_path:n #1
6554 {
6555 \spath_minbb:Nn \l_@@_tmpa_tl {#1}
6556 \dim_set:Nn \l_@@_tmpa_dim {\tl_item:Nn \l_@@_tmpa_tl {1}}
6557 \dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpa_tl {2}}
6558 \pgf@protocolsizes\l_@@_tmpa_dim\l_@@_tmpb_dim
6559
6560 \spath_maxbb:Nn \l_@@_tmpa_tl {#1}
6561 \dim_set:Nn \l_@@_tmpa_dim {\tl_item:Nn \l_@@_tmpa_tl {1}}
6562 \dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpa_tl {2}}
6563 \pgf@protocolsizes\l_@@_tmpa_dim\l_@@_tmpb_dim
6564 }
6565 \cs_generate_variant:Nn \spath_protocol_path:n {V}
6566 % \end{macrocode}
6567 % \end{macro}
6568 %
6569 % \begin{macro}[internal]{
6570 % \spath_set_current_path:n,
6571 % \spath_set_current_path:N
6572 % }
6573 % Sets the current path to the specified soft path.
6574 % \begin{macrocode}
6575 \cs_new_protected_nopar:Npn \spath_set_current_path:n #1
6576 {
6577 \spath_protocol_path:n {#1}
6578 \tl_set:Nn \l_@@_tmpa_tl {#1}
6579 \pgfsyssoftpath@setcurrentpath\l_@@_tmpa_tl
6580 }
6581 \cs_new_protected_nopar:Npn \spath_set_current_path:N #1
6582 {
6583 \spath_protocol_path:V #1
6584 \pgfsyssoftpath@setcurrentpath #1
6585 }
6586 \cs_generate_variant:Nn \spath_set_current_path:N {c}
6587 % \end{macrocode}
6588 % \end{macro}
6589 %
6590 % \begin{macro}[internal]{
6591 % \spath_use_path:nn
6592 % }
6593 % Uses the given soft path at the PGF level.
6594 % \begin{macrocode}
6595 \cs_new_protected_nopar:Npn \spath_use_path:nn #1#2
6596 {
6597 \spath_set_current_path:n {#1}
6598 \pgfusepath{#2}
6599 }
6600 % \end{macrocode}
6601 % \end{macro}
6602 %
6603 % \begin{macro}[internal]{\spath_tikz_path:nn}
6604 % Uses the given soft path at the TikZ level.
6605 % \begin{macrocode}
6606 \cs_new_protected_nopar:Npn \spath_tikz_path:nn #1#2
6607 {
6608 \tl_if_empty:nF {#2}
6609 {
6610 \path[#1] \pgfextra{
6611 \spath_set_current_path:n {#2}
6612 \tl_put_left:Nn \tikz@preactions {\def\tikz@actions@path{#2}}
6613 };
6614 }
6615 }
6616 \cs_generate_variant:Nn \spath_tikz_path:nn {Vn, VV, nv, Vv, nV}
6617 % \end{macrocode}
6618 % \end{macro}
6619 %
6620 % \begin{macro}[internal]{\spath_set_tikz_data:n}
6621 % Sets the \Verb+\tikz@lastx+ and other coordinates from the soft path.
6622 % \begin{macrocode}
6623 \cs_new_protected_nopar:Npn \spath_set_tikz_data:n #1
6624 {
6625 \spath_finalpoint:Nn \l_@@_tmpa_tl {#1}
6626 \tl_set:Nx \l_@@_tmpa_tl
6627 {
6628 \exp_not:c {pgf@x}=\tl_item:Nn \l_@@_tmpa_tl {1} \relax
6629 \exp_not:c {pgf@y}=\tl_item:Nn \l_@@_tmpa_tl {2} \relax
6630 }
6631 \use:c {pgf@process}{%
6632 \tl_use:N \l_@@_tmpa_tl
6633 \pgftransforminvert
6634 \use:c {pgf@pos@transform@glob}
6635 }
6636 \tl_set:Nx \l_@@_tmpa_tl
6637 {
6638 \exp_not:c {tikz@lastx}=\exp_not:c {pgf@x} \relax
6639 \exp_not:c {tikz@lasty}=\exp_not:c {pgf@y} \relax
6640 \exp_not:c {tikz@lastxsaved}=\exp_not:c {pgf@x} \relax
6641 \exp_not:c {tikz@lastysaved}=\exp_not:c {pgf@y} \relax
6642 }
6643 \tl_use:N \l_@@_tmpa_tl
6644 \spath_finalmovepoint:Nn \l_@@_tmpa_tl {#1}
6645 \bool_if:NT \l_spath_movetorelevant_bool
6646 {
6647 \ifpgfsyssoftpathmovetorelevant%
6648 \tl_gset_eq:cN {pgfsyssoftpath@lastmoveto} \l_@@_tmpa_tl
6649 \fi
6650 }
6651 \tl_set:Nx \l_@@_tmpa_tl
6652 {
6653 \exp_not:c {pgf@x}=\tl_item:Nn \l_@@_tmpa_tl {1} \relax
6654 \exp_not:c {pgf@y}=\tl_item:Nn \l_@@_tmpa_tl {2} \relax
6655 }
6656 \use:c {pgf@process}{%
6657 \tl_use:N \l_@@_tmpa_tl
6658 \pgftransforminvert
6659 \use:c {pgf@pos@transform@glob}
6660 }
6661 \bool_if:NT \l_spath_movetorelevant_bool
6662 {
6663 \dim_if_exist:cT {tikz@lastmovetox}
6664 {
6665 \tl_set:Nx \l_@@_tmpa_tl
6666 {
6667 \exp_not:c {tikz@lastmovetox}=\exp_not:c {pgf@x} \relax
6668 \exp_not:c {tikz@lastmovetoy}=\exp_not:c {pgf@y} \relax
6669 }
6670 \tl_use:N \l_@@_tmpa_tl
6671 }
6672 }
6673 \tl_clear_new:c {tikz@timer}
6674 \tl_set:cn {tikz@timer}
6675 {
6676 \pgftransformreset
6677 \spath_reallength:Nn \l_@@_tmpa_int {#1}
6678 \tl_set_eq:Nc \l_@@_tmpb_tl {tikz@time}
6679 \tl_set:Nx \l_@@_tmpb_tl
6680 {\fp_to_decimal:n {(\l_@@_tmpb_tl) * (\l_@@_tmpa_int)}}
6681 \spath_transformation_at:NnV \l_@@_tmpc_tl {#1} \l_@@_tmpb_tl
6682
6683 \tl_set:Nx \l_@@_tmpa_tl
6684 {
6685 \exp_not:N \pgfpoint
6686 { \tl_item:Nn \l_@@_tmpc_tl {5} }
6687 { \tl_item:Nn \l_@@_tmpc_tl {6} }
6688 }
6689 \exp_args:NV \pgftransformshift \l_@@_tmpa_tl
6690
6691 \ifpgfresetnontranslationattime
6692 \pgftransformresetnontranslations
6693 \fi
6694
6695 \ifpgfslopedattime
6696
6697 \tl_set:Nx \l_@@_tmpa_tl
6698 {
6699 { \tl_item:Nn \l_@@_tmpc_tl {1} }
6700 { \tl_item:Nn \l_@@_tmpc_tl {2} }
6701 { \tl_item:Nn \l_@@_tmpc_tl {3} }
6702 { \tl_item:Nn \l_@@_tmpc_tl {4} }
6703 }
6704 \ifpgfallowupsidedownattime
6705 \else
6706 \fp_compare:nT { \tl_item:Nn \l_@@_tmpc_tl {4} < 0}
6707 {
6708 \tl_set:Nx \l_@@_tmpa_tl
6709 {
6710 { \fp_eval:n { - (\tl_item:Nn \l_@@_tmpc_tl {1})} }
6711 { \fp_eval:n { - (\tl_item:Nn \l_@@_tmpc_tl {2})} }
6712 { \fp_eval:n { - (\tl_item:Nn \l_@@_tmpc_tl {3})} }
6713 { \fp_eval:n { - (\tl_item:Nn \l_@@_tmpc_tl {4})} }
6714 }
6715 }
6716 \fi
6717 \tl_put_right:Nn \l_@@_tmpa_tl {{\pgfpointorigin}}
6718 \exp_last_unbraced:NV \pgftransformcm \l_@@_tmpa_tl
6719 \fi
6720 }
6721 }
6722 \cs_generate_variant:Nn \spath_set_tikz_data:n {V, v}
6723 % \end{macrocode}
6724 % \end{macro}
6725 %
6726 % \iffalse
6727 %</spath3>
6728 % \fi
6729 %
6730 % \section{The TikZ interface}
6731 %
6732 % \iffalse
6733 %<*tikzspath3>
6734 % \fi
6735 %
6736 % \begin{macrocode}
6737 %<@@=tikzspath>
6738 % \end{macrocode}
6739 %
6740 %
6741 % This provides an interface to the soft path manipulation routines via a series of TikZ keys.
6742 % They all live in the \texttt{spath} family.
6743 %
6744 %
6745 % \begin{macrocode}
6746 \RequirePackage{spath3}
6747 \RequirePackage{expl3}
6748 \ExplSyntaxOn
6749
6750 \tl_new:N \l_@@_tmpa_tl
6751 \tl_new:N \l_@@_tmpb_tl
6752 \tl_new:N \l_@@_tmpc_tl
6753 \tl_new:N \l_@@_tmpd_tl
6754 \tl_new:N \l_@@_tmpe_tl
6755 \tl_new:N \l_@@_tmpf_tl
6756
6757 \int_new:N \l_@@_tmpa_int
6758 \seq_new:N \l_@@_tmpa_seq
6759 \seq_new:N \l_@@_tmpb_seq
6760 \seq_new:N \l_@@_tmpc_seq
6761 \seq_new:N \l_@@_tmpd_seq
6762
6763 \tl_new:N \l_@@_current_tl
6764 \tl_new:N \l_@@_reverse_tl
6765 \tl_new:N \l_@@_prefix_tl
6766 \tl_new:N \l_@@_suffix_tl
6767 \tl_new:N \g_@@_smuggle_tl
6768 \tl_new:N \g_@@_output_tl
6769 \tl_new:N \l_@@_check_tl
6770 \clist_new:N \g_@@_output_clist
6771 \seq_new:N \g_@@_tmpa_seq
6772 \seq_new:N \g_@@_tmpb_seq
6773 \seq_new:N \g_@@_output_seq
6774 \bool_new:N \l_@@_draft_bool
6775 % \end{macrocode}
6776 %
6777 % We surround all the keys with checks to ensure that the soft path under consideration does actually exist, but if it doesn't we should warn the user.
6778 %
6779 % \begin{macrocode}
6780 \msg_new:nnn { spath3 } { missing soft path }
6781 { Soft~ path~ #1~ doesn't~ exist~ \msg_line_context:}
6782 \msg_new:nnnn { spath3 } { empty soft path }
6783 { Soft~ path~ #1~ is~ empty~ \msg_line_context:}
6784 {If~ it~ was~ defined~ inside~ a~ group,~ try~ using~ "save~ global". }
6785 \msg_new:nnn { spath3 } { load intersections }
6786 { You~ need~ to~ load~ the~ "intersections"~ library~
6787 to~ work~ with~ intersections }
6788 % \end{macrocode}
6789 %
6790 % 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.
6791 %
6792 % \begin{macrocode}
6793 \tl_set:Nn \l_@@_prefix_tl {tikz@intersect@path@name@}
6794 \tl_set:Nn \l_@@_suffix_tl {}
6795 % \end{macrocode}
6796 %
6797 % 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.
6798 %
6799 % Interestingly, the intersections library doesn't clear its naming code once it is used meaning that it keeps resetting the definition of a path back to its original one every time a path command is called.
6800 %
6801 % Also, when the hook is restored outside a scope then no check is made to ensure that the inner one was actually invoked.
6802 % This can cause issues when the syntax \Verb!\tikz .. ;! is used since the end of the path coincides with the end of the picture.
6803 % \begin{macrocode}
6804 \tl_new:N \g_@@_tikzfinish_tl
6805 \tl_new:N \l_@@_tikzfinish_outside_tl
6806 \cs_new_protected_nopar:Npn \spath_at_end_of_path:
6807 {
6808 \tl_use:N \g_@@_tikzfinish_tl
6809 \tl_gclear:N \g_@@_tikzfinish_tl
6810 }
6811 \tl_put_right:Nn \tikz@finish {\spath_at_end_of_path:}
6812
6813 \tikzset{
6814 every~ scope/.append~ style={
6815 execute~ at~ begin~ scope={
6816 \tl_set_eq:NN \l_@@_tikzfinish_outside_tl \g_@@_tikzfinish_tl
6817 },
6818 execute~ at~ end~ scope={
6819 \tl_use:N \g_@@_tikzfinish_tl
6820 \tl_gclear:N \g_@@_tikzfinish_tl
6821 \tl_gset_eq:NN \g_@@_tikzfinish_tl \l_@@_tikzfinish_outside_tl
6822 },
6823 },
6824 }
6825 % \end{macrocode}
6826 %
6827 % This is for delaying something until the path is fully constructed (but no later), sometimes useful to be able to specify this in the path options rather than directly at the end of the path.
6828 %
6829 % \begin{macrocode}
6830 \tl_new:N \l_@@_tikzpath_finish_tl
6831
6832 \cs_new_protected_nopar:Npn \@@_at_end_of_path_construction:
6833 {
6834 \tl_use:N \l_@@_tikzpath_finish_tl
6835 \tl_clear:N \l_@@_tikzpath_finish_tl
6836 }
6837
6838 \tl_put_left:Nn \tikz@finish {\@@_at_end_of_path_construction:}
6839 % \end{macrocode}
6840 %
6841 % Code for saving a path
6842 %
6843 % \begin{macrocode}
6844 \cs_new_protected_nopar:Npn \spath_save_path:Nn #1#2
6845 {
6846 \tl_if_empty:NF \g_@@_tikzfinish_tl
6847 {
6848 \tl_use:N \g_@@_tikzfinish_tl
6849 }
6850 \tl_gput_right:Nn \g_@@_tikzfinish_tl
6851 {
6852 \tl_clear_new:N #1
6853 \tl_set:Nn #1 {#2}
6854 }
6855 }
6856 \cs_generate_variant:Nn \spath_save_path:Nn {cn, NV, cV}
6857
6858 \cs_new_protected_nopar:Npn \spath_gsave_path:Nn #1#2
6859 {
6860 \tl_gput_right:Nn \g_@@_tikzfinish_tl
6861 {
6862 \tl_gclear_new:N #1
6863 \tl_gset:Nn #1 {#2}
6864 }
6865 }
6866 \cs_generate_variant:Nn \spath_gsave_path:Nn {cn, NV, cV}
6867 % \end{macrocode}
6868 %
6869 % \begin{macro}[internal]{
6870 % \@@_process_tikz_point:Nn
6871 % }
6872 % Process a point via TikZ and store the resulting dimensions.
6873 % \begin{macrocode}
6874 \cs_new_protected_nopar:Npn \@@_process_tikz_point:Nn #1#2
6875 {
6876 \group_begin:
6877 \use:c {tikz@scan@one@point} \use:n #2 \scan_stop:
6878 \tl_gset:Nx \g_@@_output_tl
6879 {
6880 { \dim_use:c {pgf@x} }
6881 { \dim_use:c {pgf@y} }
6882 }
6883 \group_end:
6884 \tl_set_eq:NN #1 \g_@@_output_tl
6885 \tl_gclear:N \g_@@_output_tl
6886 }
6887 % \end{macrocode}
6888 % \end{macro}
6889 %
6890 % \begin{macro}[internal]{
6891 % \@@_tikzset:n
6892 % }
6893 % Wrapper around \Verb+\tikzset+ for expansion.
6894 % \begin{macrocode}
6895 \cs_set_eq:NN \@@_tikzset:n \tikzset
6896 \cs_generate_variant:Nn \@@_tikzset:n {V, v}
6897 % \end{macrocode}
6898 % \end{macro}
6899 %
6900 % \begin{macro}[internal]{
6901 % \@@_check_path:nnn
6902 % \@@_check_two_paths:nnnn
6903 % \@@_check_three_paths:nnnnn
6904 % }
6905 % Given a path name as the second argument, check if it exists and is not empty, and if so reinsert it after the first argument.
6906 % The third argument is code to be executed in case of a missing or empty path.
6907 % \begin{macrocode}
6908 \cs_new_protected_nopar:Npn \@@_check_path:nnn #1#2#3
6909 {
6910 \tl_set:Nn \l_@@_check_tl {#3}
6911 \tl_if_exist:cTF {\@@_path_name:n {#2}}
6912 {
6913 \tl_if_empty:cTF {\@@_path_name:n {#2}}
6914 {
6915 \msg_warning:nnn { spath3 } { empty soft path } { #2 }
6916 }
6917 {
6918 \tl_set:Nn \l_@@_check_tl {
6919 #1 {\@@_path_name:n {#2}}
6920 }
6921 }
6922 }
6923 {
6924 \msg_warning:nnx { spath3 } { missing soft path } { #2 }
6925 }
6926 \tl_use:N \l_@@_check_tl
6927 }
6928 \cs_new_protected_nopar:Npn \@@_check_two_paths:nnnn #1#2#3#4
6929 {
6930 \@@_check_path:nnn {
6931 \@@_check_path:nnn {#1}{#2}{#4}
6932 }{#3}{#4}
6933 }
6934 \cs_new_protected_nopar:Npn \@@_check_three_paths:nnnnn #1#2#3#4#5
6935 {
6936 \@@_check_path:nnn {
6937 \@@_check_path:nnn {
6938 \@@_check_path:nnn {#1}{#2}{#5}
6939 }{#3}{#5}
6940 }{#4}{#5}
6941 }
6942 \cs_generate_variant:Nn \@@_check_path:nnn {nVn}
6943 \cs_generate_variant:Nn \@@_check_two_paths:nnnn {nnVn}
6944 % \end{macrocode}
6945 % \end{macro}
6946 %
6947 % \begin{macro}[internal]{
6948 % \@@_maybe_current_path:nn
6949 % \@@_maybe_current_path_reuse:nnn
6950 % \@@_maybe_current_two_paths_reuse_both:nnnn
6951 % \@@_maybe_current_two_paths_reuse_first:nnnn
6952 % \@@_maybe_current_two_paths_reuse_second:nnnn
6953 % }
6954 % If the named path is ``current'' then get the current path and use that.
6955 % The second version puts the resulting path back as the current path.
6956 % \begin{macrocode}
6957 \cs_new_protected_nopar:Npn \@@_maybe_current_path:nn #1#2
6958 {
6959 \tl_if_eq:nnT {#2} {current}
6960 {
6961 \spath_get_current_path:c {\@@_path_name:n {#2}}
6962 }
6963 #1 {#2}
6964 }
6965 \cs_new_protected_nopar:Npn \@@_maybe_current_path_reuse:nnn #1#2#3
6966 {
6967 \bool_set_true:N \l_spath_movetorelevant_bool
6968 \tl_if_eq:nnT {#2} {current}
6969 {
6970 \spath_get_current_path:c {\@@_path_name:n {#2}}
6971 }
6972 #1 {#2} #3
6973 \tl_if_eq:nnT {#2} {current}
6974 {
6975 \tl_if_empty:cF {\@@_path_name:n {#2}}
6976 {
6977 \spath_set_current_path:c {\@@_path_name:n {#2}}
6978 \spath_set_tikz_data:v {\@@_path_name:n {#2}}
6979 }
6980 }
6981 }
6982 \cs_new_protected_nopar:Npn \@@_maybe_current_two_paths_reuse_both:nnnn #1#2#3#4
6983 {
6984 \bool_set_true:N \l_spath_movetorelevant_bool
6985 \tl_if_eq:nnT {#2} {current}
6986 {
6987 \spath_get_current_path:c {\@@_path_name:n {#2}}
6988 }
6989 \tl_if_eq:nnT {#3} {current}
6990 {
6991 \spath_get_current_path:c {\@@_path_name:n {#3}}
6992 }
6993 #1 {#2} {#3} #4
6994 \tl_if_eq:nnT {#2} {current}
6995 {
6996 \tl_if_empty:cF {\@@_path_name:n {#2}}
6997 {
6998 \spath_set_current_path:c {\@@_path_name:n {#2}}
6999 \spath_set_tikz_data:v {\@@_path_name:n {#2}}
7000 }
7001 }
7002 \tl_if_eq:nnT {#3} {current}
7003 {
7004 \tl_if_empty:cF {\@@_path_name:n {#3}}
7005 {
7006 \spath_set_current_path:c {\@@_path_name:n {#3}}
7007 \spath_set_tikz_data:v {\@@_path_name:n {#3}}
7008 }
7009 }
7010 }
7011 \cs_new_protected_nopar:Npn \@@_maybe_current_two_paths_reuse_first:nnnn #1#2#3#4
7012 {
7013 \bool_set_true:N \l_spath_movetorelevant_bool
7014 \tl_if_eq:nnT {#2} {current}
7015 {
7016 \spath_get_current_path:c {\@@_path_name:n {#2}}
7017 }
7018 \tl_if_eq:nnT {#3} {current}
7019 {
7020 \spath_get_current_path:c {\@@_path_name:n {#3}}
7021 }
7022 #1 {#2} {#3} #4
7023 \tl_if_eq:nnT {#2} {current}
7024 {
7025 \tl_if_empty:cF {\@@_path_name:n {#2}}
7026 {
7027 \spath_set_current_path:c {\@@_path_name:n {#2}}
7028 \spath_set_tikz_data:v {\@@_path_name:n {#2}}
7029 }
7030 }
7031 }
7032 \cs_new_protected_nopar:Npn \@@_maybe_current_two_paths_reuse_second:nnnn #1#2#3#4
7033 {
7034 \bool_set_true:N \l_spath_movetorelevant_bool
7035 \tl_if_eq:nnT {#2} {current}
7036 {
7037 \spath_get_current_path:c {\@@_path_name:n {#2}}
7038 }
7039 \tl_if_eq:nnT {#3} {current}
7040 {
7041 \spath_get_current_path:c {\@@_path_name:n {#3}}
7042 }
7043 #1 {#2} {#3} #4
7044 \tl_if_eq:nnT {#3} {current}
7045 {
7046 \tl_if_empty:cF {\@@_path_name:n {#3}}
7047 {
7048 \spath_set_current_path:c {\@@_path_name:n {#3}}
7049 \spath_set_tikz_data:v {\@@_path_name:n {#3}}
7050 }
7051 }
7052 }
7053 \cs_generate_variant:Nn \@@_maybe_current_path:nn {nV}
7054 \cs_generate_variant:Nn \@@_maybe_current_path_reuse:nnn {nVn}
7055 % \end{macrocode}
7056 % \end{macro}
7057 %
7058 %
7059 %
7060 % \begin{macro}{
7061 % \@@_seq_from_foreach:NNn
7062 % }
7063 %
7064 % Convert a PGF foreach list, as the third argument, to a sequence.
7065 % The second argument is the maximum number on the list.
7066 % \begin{macrocode}
7067 \cs_new_protected_nopar:Npn \@@_seq_from_foreach:Nnn #1#2#3
7068 {
7069 \group_begin:
7070 \seq_gclear:N \g_@@_output_seq
7071
7072 \tl_if_empty:nTF {#3}
7073 {
7074 \int_step_inline:nnnn {1}{1} {#2}
7075 {
7076 \seq_gput_right:Nn \g_@@_output_seq {##1}
7077 }
7078 }
7079 {
7080 \foreach \l_@@_tmpa_tl in {#3}
7081 {
7082 \int_compare:nTF { \l_@@_tmpa_tl > 0 }
7083 {
7084 \seq_gput_right:NV \g_@@_output_seq \l_@@_tmpa_tl
7085 }
7086 {
7087 \seq_gput_right:Nx \g_@@_output_seq
7088 {\int_eval:n {#2 - \l_@@_tmpa_tl}}
7089 }
7090 }
7091 \seq_gsort:Nn \g_@@_output_seq
7092 {
7093 \int_compare:nNnTF {##1} < {##2}
7094 { \sort_return_same: }
7095 { \sort_return_swapped: }
7096 }
7097 }
7098 \group_end:
7099 \seq_set_eq:NN #1 \g_@@_output_seq
7100 \seq_gclear:N \g_@@_output_seq
7101 }
7102 \cs_generate_variant:Nn \@@_seq_from_foreach:Nnn {NVV, NVn}
7103 %
7104 % \end{macrocode}
7105 % \end{macro}
7106 %
7107 % \begin{macro}[internal]{
7108 % \@@_path_name:n
7109 % }
7110 % Wrap the argument in the prefix and suffix to generate the proper name.
7111 % \begin{macrocode}
7112 \cs_new:Npn \@@_path_name:n #1
7113 {
7114 \tl_use:N \l_@@_prefix_tl
7115 #1
7116 \tl_use:N \l_@@_suffix_tl
7117 }
7118 \cs_generate_variant:Nn \@@_path_name:n {V}
7119 % \end{macrocode}
7120 % \end{macro}
7121 %
7122 % When joining two paths we provide a set of options for how to process the second path.
7123 %
7124 % \begin{macrocode}
7125 \bool_new:N \l_@@_reverse_bool
7126 \bool_new:N \l_@@_weld_bool
7127 \bool_new:N \l_@@_move_bool
7128 \bool_new:N \l_@@_global_bool
7129 \bool_new:N \l_@@_current_transformation_bool
7130 \tl_new:N \l_@@_joinpath_tl
7131 \tl_new:N \l_@@_transformation_tl
7132
7133 \cs_new_protected_nopar:Npn \@@_set_bool:Nn #1#2
7134 {
7135 \tl_if_eq:nnTF {#2}{false}
7136 {
7137 \bool_set_false:N #1
7138 }
7139 {
7140 \bool_set_true:N #1
7141 }
7142 }
7143 \tikzset {
7144 spath/join/.is~ family,
7145 spath/join/.cd,
7146 reverse/.code = {
7147 \@@_set_bool:Nn \l_@@_reverse_bool {#1}
7148 },
7149 reverse/.default = true,
7150 weld/.code = {
7151 \@@_set_bool:Nn \l_@@_weld_bool {#1}
7152 },
7153 weld/.default = true,
7154 no~ weld/.code = {
7155 \@@_set_bool:Nn \l_@@_weld_bool {#1}
7156 \bool_set:Nn \l_@@_weld_bool {! \l_@@_weld_bool}
7157 },
7158 no~ weld/.default = true,
7159 move/.code = {
7160 \@@_set_bool:Nn \l_@@_move_bool {#1}
7161 },
7162 move/.default = true,
7163 no~ move/.code = {
7164 \@@_set_bool:Nn \l_@@_move_bool {#1}
7165 \bool_set:Nn \l_@@_move_bool {! \l_@@_move_bool}
7166 },
7167 no~ move/.default = true,
7168 global/.code = {
7169 \@@_set_bool:Nn \l_@@_global_bool {#1}
7170 },
7171 global/.default = true,
7172 use~ current~ transformation/.code={
7173 \@@_set_bool:Nn \l_@@_current_transformation_bool {#1}
7174 },
7175 use~ current~ transformation/.default = true,
7176 transform/.store~in=\l_@@_transformation_tl,
7177 .unknown/.code = {
7178 \tl_set_eq:NN \l_@@_joinpath_tl \pgfkeyscurrentname
7179 }
7180 }
7181 % \end{macrocode}
7182 %
7183 %
7184 % When we split a soft path into components, we make it a comma separated list so that it can be fed into a \Verb+\foreach+ loop.
7185 % This can also make it possible to extract a single component, but to do this we need a wrapper around \Verb+\clist_item:Nn+ (there doesn't appear to be a PGF way of getting an item of a CS list).
7186 %
7187 % \begin{macrocode}
7188 \cs_set_eq:NN \getComponentOf \clist_item:Nn
7189 % \end{macrocode}
7190 %
7191 % \subsection{Helper Functions}
7192 %
7193 % \begin{macro}[internal]{
7194 % \@@_use_path:n
7195 % }
7196 % Use a path, possibly manipulating it first.
7197 % \begin{macrocode}
7198 \cs_new_protected_nopar:Npn \@@_use_path:n #1
7199 {
7200 \tl_set:Nn \l_@@_joinpath_tl {#1}
7201 \spath_get_current_path:N \l_@@_current_tl
7202
7203 \bool_if:NT \l_@@_reverse_bool
7204 {
7205 \spath_reverse:N \l_@@_joinpath_tl
7206 }
7207
7208 \bool_if:NT \l_@@_current_transformation_bool
7209 {
7210 \pgfgettransform \l_@@_tmpa_tl
7211 \spath_transform:NV
7212 \l_@@_joinpath_tl
7213 \l_@@_tmpa_tl
7214 }
7215
7216 \tl_if_empty:NF \l_@@_transformation_tl
7217 {
7218 \group_begin:
7219 \pgftransformreset
7220 \@@_tikzset:V \l_@@_transformation_tl
7221 \pgfgettransform \l_@@_tmpa_tl
7222 \tl_gset:Nn \g_@@_smuggle_tl
7223 {
7224 \spath_transform:Nnnnnnn
7225 \l_@@_joinpath_tl
7226 }
7227 \tl_gput_right:NV \g_@@_smuggle_tl \l_@@_tmpa_tl
7228 \group_end:
7229 \tl_use:N \g_@@_smuggle_tl
7230 }
7231
7232 \bool_if:NT \l_@@_move_bool
7233 {
7234 \tl_if_empty:NTF \l_@@_current_tl
7235 {
7236 \tl_set:Nn \l_@@_tmpc_tl { {0pt} {0pt} }
7237 }
7238 {
7239 \spath_finalpoint:NV
7240 \l_@@_tmpc_tl
7241 \l_@@_current_tl
7242 }
7243 \spath_translate_to:NV \l_@@_joinpath_tl \l_@@_tmpc_tl
7244 }
7245
7246 \tl_if_empty:NTF \l_@@_current_tl
7247 {
7248 \tl_if_empty:NTF \l_@@_joinpath_tl
7249 {
7250 \tl_set_eq:NN \l_@@_current_tl \c_spath_moveto_tl
7251 \tl_put_right:Nn \l_@@_current_tl {{0pt}{0pt}}
7252 }
7253 {
7254 \tl_set_eq:NN \l_@@_current_tl \l_@@_joinpath_tl
7255 }
7256 }
7257 {
7258
7259 \tl_clear:N \l_@@_tmpa_tl
7260 \tl_set:Nn \l_@@_tmpa_tl {spath_}
7261
7262 \tl_put_right:Nn \l_@@_tmpa_tl {append}
7263
7264 \bool_if:NT \l_@@_weld_bool
7265 {
7266 \tl_put_right:Nn \l_@@_tmpa_tl {_no_move}
7267 \spath_numberofcomponents:NV \l_@@_tmpa_int \l_@@_joinpath_tl
7268 \int_compare:nT {\l_@@_tmpa_int == 1}
7269 {
7270 \bool_set_false:N \l_spath_movetorelevant_bool
7271 }
7272 }
7273 \tl_put_right:Nn \l_@@_tmpa_tl {:NV}
7274
7275 \use:c {\tl_use:N \l_@@_tmpa_tl }
7276 \l_@@_current_tl
7277 \l_@@_joinpath_tl
7278 }
7279
7280 \spath_set_current_path:N \l_@@_current_tl
7281 \spath_set_tikz_data:V \l_@@_joinpath_tl
7282 }
7283 \cs_generate_variant:Nn \@@_use_path:n {V, v}
7284 % \end{macrocode}
7285 % \end{macro}
7286 %
7287 %
7288 % \begin{macro}[internal]{
7289 % \@@_join_with:nn
7290 % }
7291 % \begin{macrocode}
7292 \cs_new_protected_nopar:Npn \@@_join_with:Nn #1#2
7293 {
7294 \tl_set:Nn \l_@@_joinpath_tl {#2}
7295
7296 \bool_if:NT \l_@@_reverse_bool
7297 {
7298 \spath_reverse:N \l_@@_joinpath_tl
7299 }
7300
7301 \tl_if_empty:NF \l_@@_transformation_tl
7302 {
7303 \group_begin:
7304 \pgftransformreset
7305 \@@_tikzset:V \l_@@_transformation_tl
7306 \pgfgettransform \l_@@_tmpa_tl
7307 \tl_gset:Nn \g_@@_smuggle_tl
7308 {
7309 \spath_transform:Nnnnnnn
7310 \l_@@_joinpath_tl
7311 }
7312 \tl_gput_right:NV \g_@@_smuggle_tl \l_@@_tmpa_tl
7313 \group_end:
7314 \tl_use:N \g_@@_smuggle_tl
7315 }
7316
7317 \bool_if:NT \l_@@_move_bool
7318 {
7319 \spath_finalpoint:NV
7320 \l_@@_tmpc_tl
7321 #1
7322 \spath_translate_to:NV \l_@@_joinpath_tl \l_@@_tmpc_tl
7323 }
7324
7325 \tl_clear:N \l_@@_tmpa_tl
7326 \tl_set:Nn \l_@@_tmpa_tl {spath_}
7327
7328 \bool_if:NT \l_@@_global_bool
7329 {
7330 \tl_put_right:Nn \l_@@_tmpa_tl {g}
7331 }
7332
7333 \tl_put_right:Nn \l_@@_tmpa_tl {append}
7334
7335 \bool_if:NT \l_@@_weld_bool
7336 {
7337 \tl_put_right:Nn \l_@@_tmpa_tl {_no_move}
7338 }
7339 \tl_put_right:Nn \l_@@_tmpa_tl {:NV}
7340
7341 \cs_if_exist:cF {\tl_use:N \l_@@_tmpa_tl}
7342 {
7343 \tl_show:N \l_@@_tmpa_tl
7344 }
7345
7346 \use:c {\tl_use:N \l_@@_tmpa_tl } #1
7347 \l_@@_joinpath_tl
7348 }
7349 \cs_generate_variant:Nn \@@_join_with:Nn {cv, cn}
7350 % \end{macrocode}
7351 % \end{macro}
7352 %
7353 % \begin{macro}{
7354 % \@@_join_components_with:Nnn
7355 % \@@_join_components_upright_with:Nnn
7356 % }
7357 % Join the specified components of the first path by splicing in the second.
7358 % \begin{macrocode}
7359 \cs_new_protected_nopar:Npn \@@_join_components_with_aux:nnn #1#2#3
7360 {
7361 \group_begin:
7362 \tl_set:Nn \l_@@_tmpc_tl {#1}
7363 \tl_if_empty:nT {#3}
7364 {
7365 \spath_spot_weld_components:N \l_@@_tmpc_tl
7366 }
7367
7368 \spath_numberofcomponents:NV \l_@@_tmpa_int \l_@@_tmpc_tl
7369 \@@_seq_from_foreach:NVn \l_@@_tmpb_seq \l_@@_tmpa_int {#3}
7370
7371 \spath_components_to_seq:NV \l_@@_tmpa_seq \l_@@_tmpc_tl
7372
7373 \seq_pop_left:NN \l_@@_tmpa_seq \l_@@_tmpa_tl
7374 \seq_pop_left:NN \l_@@_tmpb_seq \l_@@_tmpb_tl
7375
7376 \seq_map_indexed_inline:Nn \l_@@_tmpa_seq
7377 {
7378 \int_compare:nTF
7379 {
7380 ##1 == \l_@@_tmpb_tl
7381 }
7382 {
7383 \seq_pop_left:NNF \l_@@_tmpb_seq \l_@@_tmpb_tl
7384 {
7385 \tl_set:Nn \l_@@_tmpb_tl {-1}
7386 }
7387 \spath_splice_between:Nnn \l_@@_tmpa_tl {#2} {##2}
7388 }
7389 {
7390 \tl_put_right:Nn \l_@@_tmpa_tl {##2}
7391 }
7392 }
7393 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
7394 \group_end:
7395 }
7396 \cs_new_protected_nopar:Npn \@@_join_components_with:Nnnn #1#2#3#4
7397 {
7398 \@@_join_components_with_aux:nnn {#2}{#3}{#4}
7399 \tl_set_eq:NN #1 \g_@@_output_tl
7400 \tl_gclear:N \g_@@_output_tl
7401 }
7402 \cs_generate_variant:Nn \@@_join_components_with:Nnnn {NVnn}
7403 \cs_new_protected_nopar:Npn \@@_join_components_with:Nnn #1#2#3
7404 {
7405 \@@_join_components_with:NVnn #1#1{#2}{#3}
7406 }
7407 \cs_generate_variant:Nn \@@_join_components_with:Nnn {cvV}
7408 \cs_new_protected_nopar:Npn \@@_gjoin_components_with:Nnnn #1#2#3#4
7409 {
7410 \@@_join_components_with_aux:nnn {#2}{#3}{#4}
7411 \tl_gset_eq:NN #1 \g_@@_output_tl
7412 \tl_gclear:N \g_@@_output_tl
7413 }
7414 \cs_generate_variant:Nn \@@_gjoin_components_with:Nnnn {NVnn}
7415 \cs_new_protected_nopar:Npn \@@_gjoin_components_with:Nnn #1#2#3
7416 {
7417 \@@_gjoin_components_with:NVnn #1#1{#2}{#3}
7418 }
7419 \cs_generate_variant:Nn \@@_gjoin_components_with:Nnn {cvV}
7420 \cs_new_protected_nopar:Npn \@@_join_components_upright_with_aux:nnn #1#2#3
7421 {
7422 \group_begin:
7423 \tl_set:Nn \l_@@_tmpc_tl {#1}
7424 \tl_if_empty:nT {#3}
7425 {
7426 \spath_spot_weld_components:N \l_@@_tmpc_tl
7427 }
7428
7429 \spath_numberofcomponents:NV \l_@@_tmpa_int \l_@@_tmpc_tl
7430 \@@_seq_from_foreach:NVn \l_@@_tmpb_seq \l_@@_tmpa_int {#3}
7431
7432 \spath_components_to_seq:NV \l_@@_tmpa_seq \l_@@_tmpc_tl
7433
7434 \seq_pop_left:NN \l_@@_tmpa_seq \l_@@_tmpa_tl
7435 \seq_pop_left:NN \l_@@_tmpb_seq \l_@@_tmpb_tl
7436
7437 \tl_set:Nn \l_@@_tmpc_tl {#2}
7438 \spath_transform:NVnnnnnn \l_@@_tmpd_tl \l_@@_tmpc_tl {1}{0}{0}{-1}{0pt}{0pt}
7439
7440 \seq_map_indexed_inline:Nn \l_@@_tmpa_seq
7441 {
7442 \int_compare:nTF
7443 {
7444 ##1 == \l_@@_tmpb_tl
7445 }
7446 {
7447 \seq_pop_left:NNF \l_@@_tmpb_seq \l_@@_tmpb_tl
7448 {
7449 \tl_set:Nn \l_@@_tmpb_tl {-1}
7450 }
7451
7452 \spath_finalpoint:NV \l_@@_tmpe_tl \l_@@_tmpa_tl
7453 \spath_initialpoint:Nn \l_@@_tmpf_tl {##2}
7454
7455 \dim_compare:nTF
7456 {
7457 \tl_item:Nn \l_@@_tmpe_tl {1}
7458 >
7459 \tl_item:Nn \l_@@_tmpf_tl {1}
7460 }
7461 {
7462 \spath_splice_between:NVn
7463 \l_@@_tmpa_tl
7464 \l_@@_tmpd_tl
7465 {##2}
7466 }
7467 {
7468 \spath_splice_between:NVn
7469 \l_@@_tmpa_tl
7470 \l_@@_tmpc_tl
7471 {##2}
7472 }
7473 }
7474 {
7475 \tl_put_right:Nn \l_@@_tmpa_tl {##2}
7476 }
7477 }
7478 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
7479 \group_end:
7480 }
7481 \cs_new_protected_nopar:Npn \@@_join_components_upright_with:Nnnn #1#2#3#4
7482 {
7483 \@@_join_components_upright_with_aux:nnn {#2}{#3}{#4}
7484 \tl_set_eq:NN #1 \g_@@_output_tl
7485 \tl_gclear:N \g_@@_output_tl
7486 }
7487 \cs_generate_variant:Nn \@@_join_components_upright_with:Nnnn {NVnn}
7488 \cs_new_protected_nopar:Npn \@@_join_components_upright_with:Nnn #1#2#3
7489 {
7490 \@@_join_components_upright_with:NVnn #1#1{#2}{#3}
7491 }
7492 \cs_generate_variant:Nn \@@_join_components_upright_with:Nnn {cvV}
7493 \cs_new_protected_nopar:Npn \@@_gjoin_components_upright_with:Nnnn #1#2#3#4
7494 {
7495 \@@_join_components_upright_with_aux:nnn {#2}{#3}{#4}
7496 \tl_gset_eq:NN #1 \g_@@_output_tl
7497 \tl_gclear:N \g_@@_output_tl
7498 }
7499 \cs_generate_variant:Nn \@@_gjoin_components_upright_with:Nnnn {NVnn}
7500 \cs_new_protected_nopar:Npn \@@_gjoin_components_upright_with:Nnn #1#2#3
7501 {
7502 \@@_gjoin_components_upright_with:NVnn #1#1{#2}{#3}
7503 }
7504 \cs_generate_variant:Nn \@@_gjoin_components_upright_with:Nnn {cvV}
7505 % \end{macrocode}
7506 % \end{macro}
7507 %
7508 %
7509 % \begin{macro}{
7510 % \@@_get_components:Nn
7511 % }
7512 % Get the components of the named path to the token list.
7513 % \begin{macrocode}
7514 \cs_new_protected_nopar:Npn \@@_get_components_aux:n #1
7515 {
7516 \clist_gclear_new:N \g_@@_output_clist
7517 \spath_components_to_seq:Nn \l_@@_tmpa_seq {#1}
7518
7519 \seq_map_inline:Nn \l_@@_tmpa_seq
7520 {
7521 \spath_anonymous:N \l_@@_tmpa_tl
7522 \tl_new:c {\@@_path_name:V \l_@@_tmpa_tl}
7523 \tl_set:cn {\@@_path_name:V \l_@@_tmpa_tl} {##1}
7524 \clist_gput_right:NV \g_@@_output_clist \l_@@_tmpa_tl
7525 }
7526 }
7527 \cs_new_protected_nopar:Npn \@@_get_components:Nn #1#2
7528 {
7529 \clist_clear_new:N #1
7530 \@@_get_components_aux:n {#2}
7531 \clist_set_eq:NN #1 \g_@@_output_clist
7532 \clist_gclear:N \g_@@_output_clist
7533 }
7534 \cs_generate_variant:Nn \@@_get_components:Nn {NV, Nv}
7535 \cs_new_protected_nopar:Npn \@@_gget_components:Nn #1#2
7536 {
7537 \clist_gclear_new:N #1
7538 \@@_get_components_aux:n {#2}
7539 \clist_gset_eq:NN #1 \g_@@_output_clist
7540 \clist_gclear:N \g_@@_output_clist
7541 }
7542 \cs_generate_variant:Nn \@@_gget_components:Nn {NV, Nv}
7543 % \end{macrocode}
7544 % \end{macro}
7545 %
7546 %
7547 % \begin{macro}{
7548 % \@@_render_components:n
7549 % }
7550 % \begin{macrocode}
7551 \cs_new_protected_nopar:Npn \@@_render_components:nn #1#2
7552 {
7553 \group_begin:
7554 \spath_components_to_seq:Nn \l_@@_tmpa_seq {#2}
7555 \seq_map_indexed_inline:Nn \l_@@_tmpa_seq
7556 {
7557 \spath_tikz_path:nn
7558 {
7559 every~ spath~ component/.try,
7560 spath ~component~ ##1/.try,
7561 spath ~component/.try={##1},
7562 every~ #1~ component/.try,
7563 #1 ~component~ ##1/.try,
7564 #1 ~component/.try={##1},
7565 }
7566 {
7567 ##2
7568 }
7569 }
7570 \group_end:
7571 }
7572 \cs_generate_variant:Nn \@@_render_components:nn {nv}
7573 % \end{macrocode}
7574 % \end{macro}
7575 %
7576 % \begin{macro}[internal]{
7577 % \@@_insert_gaps_after_components:nn
7578 % }
7579 %
7580 % \begin{macrocode}
7581 \cs_new_protected_nopar:Npn \@@_insert_gaps_after_components_aux:nnn #1#2#3
7582 {
7583 \group_begin:
7584 \spath_numberofcomponents:Nn \l_@@_tmpa_int {#1}
7585 \@@_seq_from_foreach:NVn \l_@@_tmpa_seq \l_@@_tmpa_int {#3}
7586
7587 \tl_if_empty:nT {#3}
7588 {
7589 \seq_pop_right:NN \l_@@_tmpa_seq \l_@@_tmpa_tl
7590 }
7591
7592 \seq_clear:N \l_@@_tmpb_seq
7593 \seq_map_inline:Nn \l_@@_tmpa_seq {
7594 \seq_put_right:Nx
7595 \l_@@_tmpb_seq
7596 {\int_eval:n
7597 {
7598 \int_mod:nn { ##1 }{ \l_@@_tmpa_int } + 1
7599 }
7600 }
7601 }
7602
7603 \spath_components_to_seq:Nn \l_@@_tmpc_seq {#1}
7604
7605 \seq_clear:N \l_@@_tmpd_seq
7606 \seq_map_indexed_inline:Nn \l_@@_tmpc_seq
7607 {
7608 \tl_set:Nn \l_@@_tmpa_tl {##2}
7609 \seq_if_in:NnT \l_@@_tmpa_seq {##1}
7610 {
7611 \spath_shorten_at_end:Nn \l_@@_tmpa_tl {(#2)/2}
7612 }
7613 \seq_if_in:NnT \l_@@_tmpb_seq {##1}
7614 {
7615 \spath_shorten_at_start:Nn \l_@@_tmpa_tl {(#2)/2}
7616 }
7617 \seq_put_right:NV \l_@@_tmpd_seq \l_@@_tmpa_tl
7618 }
7619 \tl_gset:Nx \g_@@_output_tl {\seq_use:Nn \l_@@_tmpd_seq {} }
7620 \group_end:
7621 }
7622 \cs_new_protected_nopar:Npn \@@_insert_gaps_after_components:Nnnn #1#2#3#4
7623 {
7624 \@@_insert_gaps_after_components_aux:nnn {#2}{#3}{#4}
7625 \tl_set_eq:NN #1 \g_@@_output_tl
7626 \tl_gclear:N \g_@@_output_tl
7627 }
7628 \cs_generate_variant:Nn \@@_insert_gaps_after_components:Nnnn {NVnn}
7629 \cs_new_protected_nopar:Npn \@@_insert_gaps_after_components:Nnn #1#2#3
7630 {
7631 \@@_insert_gaps_after_components:NVnn #1#1{#2}{#3}
7632 }
7633 \cs_generate_variant:Nn \@@_insert_gaps_after_components:Nnn {cnn, cVV}
7634 \cs_new_protected_nopar:Npn \@@_ginsert_gaps_after_components:Nnnn #1#2#3#4
7635 {
7636 \@@_insert_gaps_after_components_aux:nnn {#2}{#3}{#4}
7637 \tl_gset_eq:NN #1 \g_@@_output_tl
7638 \tl_gclear:N \g_@@_output_tl
7639 }
7640 \cs_generate_variant:Nn \@@_ginsert_gaps_after_components:Nnnn {NVnn}
7641 \cs_new_protected_nopar:Npn \@@_ginsert_gaps_after_components:Nnn #1#2#3
7642 {
7643 \@@_ginsert_gaps_after_components:NVnn #1#1{#2}{#3}
7644 }
7645 \cs_generate_variant:Nn \@@_ginsert_gaps_after_components:Nnn {cnn, cVV}
7646 % \end{macrocode}
7647 % \end{macro}
7648 %
7649 % \begin{macro}{
7650 % \@@_insert_gaps_after_segments:Nn
7651 % }
7652 % \begin{macrocode}
7653 \cs_new_protected_nopar:Npn \@@_insert_gaps_after_segments_aux:nnn #1#2#3
7654 {
7655 \group_begin:
7656 \spath_reallength:Nn \l_@@_tmpa_int {#1}
7657 \@@_seq_from_foreach:NVn \l_@@_tmpa_seq \l_@@_tmpa_int {#3}
7658
7659 \tl_if_empty:nT {#3}
7660 {
7661 \seq_pop_right:NN \l_@@_tmpb_seq \l_@@_tmpa_tl
7662 }
7663
7664 \seq_clear:N \l_@@_tmpb_seq
7665 \seq_map_inline:Nn \l_@@_tmpa_seq {
7666 \seq_put_right:Nx
7667 \l_@@_tmpb_seq
7668 {\int_eval:n
7669 {
7670 \int_mod:nn { ##1 }{ \l_@@_tmpa_int } + 1
7671 }
7672 }
7673 }
7674
7675 \spath_segments_to_seq:Nn \l_@@_tmpc_seq {#1}
7676
7677 \seq_clear:N \l_@@_tmpd_seq
7678 \seq_map_indexed_inline:Nn \l_@@_tmpc_seq
7679 {
7680 \tl_set:Nn \l_@@_tmpa_tl {##2}
7681 \seq_if_in:NnT \l_@@_tmpa_seq {##1}
7682 {
7683 \spath_shorten_at_end:Nn \l_@@_tmpa_tl {(#2)/2}
7684 }
7685 \seq_if_in:NnT \l_@@_tmpb_seq {##1}
7686 {
7687 \spath_shorten_at_start:Nn \l_@@_tmpa_tl {(#2)/2}
7688 }
7689 \seq_put_right:NV \l_@@_tmpd_seq \l_@@_tmpa_tl
7690 }
7691 \tl_gset:Nx \g_@@_output_tl {\seq_use:Nn \l_@@_tmpd_seq {} }
7692 \group_end:
7693 }
7694 \cs_new_protected_nopar:Npn \@@_insert_gaps_after_segments:Nnnn #1#2#3#4
7695 {
7696 \@@_insert_gaps_after_segments_aux:nnn {#2}{#3}{#4}
7697 \tl_set_eq:NN #1 \g_@@_output_tl
7698 \tl_gclear:N \g_@@_output_tl
7699 }
7700 \cs_generate_variant:Nn \@@_insert_gaps_after_segments:Nnnn {NVnn}
7701 \cs_new_protected_nopar:Npn \@@_insert_gaps_after_segments:Nnn #1#2#3
7702 {
7703 \@@_insert_gaps_after_segments:NVnn #1#1{#2}{#3}
7704 }
7705 \cs_generate_variant:Nn \@@_insert_gaps_after_segments:Nnn {cnn, cVV}
7706 \cs_new_protected_nopar:Npn \@@_ginsert_gaps_after_segments:Nnnn #1#2#3#4
7707 {
7708 \@@_insert_gaps_after_segments_aux:nnn {#2}{#3}{#4}
7709 \tl_gset_eq:NN #1 \g_@@_output_tl
7710 \tl_gclear:N \g_@@_output_tl
7711 }
7712 \cs_generate_variant:Nn \@@_ginsert_gaps_after_segments:Nnnn {NVnn}
7713 \cs_new_protected_nopar:Npn \@@_ginsert_gaps_after_segments:Nnn #1#2#3
7714 {
7715 \@@_ginsert_gaps_after_segments:NVnn #1#1{#2}{#3}
7716 }
7717 \cs_generate_variant:Nn \@@_ginsert_gaps_after_segments:Nnn {cnn, cVV}
7718 % \end{macrocode}
7719 % \end{macro}
7720 %
7721 % \begin{macro}{
7722 % \@@_join_components:Nn
7723 % }
7724 % \begin{macrocode}
7725 \cs_new_protected_nopar:Npn \@@_join_components_aux:nn #1#2
7726 {
7727 \group_begin:
7728
7729 \tl_set:Nn \l_@@_tmpa_tl {#1}
7730 \spath_numberofcomponents:NV \l_@@_tmpa_int \l_@@_tmpa_tl
7731 \@@_seq_from_foreach:NVn \l_@@_tmpa_seq \l_@@_tmpa_int {#2}
7732
7733 \seq_reverse:N \l_@@_tmpa_seq
7734
7735 \seq_map_inline:Nn \l_@@_tmpa_seq
7736 {
7737 \spath_join_component:Nn \l_@@_tmpa_tl {##1}
7738 }
7739 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
7740 \group_end:
7741 }
7742 \cs_new_protected_nopar:Npn \@@_join_components:Nnn #1#2#3
7743 {
7744 \@@_join_components_aux:nn {#2}{#3}
7745 \tl_set_eq:NN #1 \g_@@_output_tl
7746 \tl_gclear:N \g_@@_output_tl
7747 }
7748 \cs_generate_variant:Nn \@@_join_components:Nnn {NVn}
7749 \cs_new_protected_nopar:Npn \@@_join_components:Nn #1#2
7750 {
7751 \@@_join_components:NVn #1#1{#2}
7752 }
7753 \cs_generate_variant:Nn \@@_join_components:Nn {cn}
7754 \cs_new_protected_nopar:Npn \@@_gjoin_components:Nnn #1#2#3
7755 {
7756 \@@_join_components_aux:nn {#2}{#3}
7757 \tl_gset_eq:NN #1 \g_@@_output_tl
7758 \tl_gclear:N \g_@@_output_tl
7759 }
7760 \cs_generate_variant:Nn \@@_gjoin_components:Nnn {NVn}
7761 \cs_new_protected_nopar:Npn \@@_gjoin_components:Nn #1#2
7762 {
7763 \@@_gjoin_components:NVn #1#1{#2}
7764 }
7765 \cs_generate_variant:Nn \@@_gjoin_components:Nn {cn}
7766 % \end{macrocode}
7767 % \end{macro}
7768 %
7769 % \begin{macro}{
7770 % \@@_join_components_with_bezier:Nn
7771 % }
7772 % \begin{macrocode}
7773 \cs_new_protected_nopar:Npn \@@_join_components_with_bezier_aux:nn #1#2
7774 {
7775 \group_begin:
7776 \tl_set:Nn \l_@@_tmpc_tl {#1}
7777 \tl_if_empty:nT {#2}
7778 {
7779 \spath_spot_weld_components:N \l_@@_tmpc_tl
7780 }
7781
7782 \spath_numberofcomponents:NV \l_@@_tmpa_int \l_@@_tmpc_tl
7783 \@@_seq_from_foreach:NVn \l_@@_tmpb_seq \l_@@_tmpa_int {#2}
7784
7785 \spath_components_to_seq:NV \l_@@_tmpa_seq \l_@@_tmpc_tl
7786
7787 \seq_pop_left:NN \l_@@_tmpa_seq \l_@@_tmpa_tl
7788 \seq_pop_left:NN \l_@@_tmpb_seq \l_@@_tmpb_tl
7789
7790 \seq_map_indexed_inline:Nn \l_@@_tmpa_seq
7791 {
7792 \int_compare:nTF
7793 {
7794 ##1 == \l_@@_tmpb_tl
7795 }
7796 {
7797 \seq_pop_left:NNF \l_@@_tmpb_seq \l_@@_tmpb_tl
7798 {
7799 \tl_set:Nn \l_@@_tmpb_tl {-1}
7800 }
7801 \spath_curve_between:Nn \l_@@_tmpa_tl {##2}
7802 }
7803 {
7804 \tl_put_right:Nn \l_@@_tmpa_tl {##2}
7805 }
7806 }
7807 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpa_tl
7808 \group_end:
7809 }
7810 \cs_new_protected_nopar:Npn \@@_join_components_with_bezier:Nnn #1#2#3
7811 {
7812 \@@_join_components_with_bezier_aux:nn {#2}{#3}
7813 \tl_set_eq:NN #1 \g_@@_output_tl
7814 \tl_gclear:N \g_@@_output_tl
7815 }
7816 \cs_generate_variant:Nn \@@_join_components_with_bezier:Nnn {NVn}
7817 \cs_new_protected_nopar:Npn \@@_join_components_with_bezier:Nn #1#2
7818 {
7819 \@@_join_components_with_bezier:NVn #1#1{#2}
7820 }
7821 \cs_generate_variant:Nn \@@_join_components_with_bezier:Nn {cV}
7822 \cs_new_protected_nopar:Npn \@@_gjoin_components_with_bezier:Nnn #1#2#3
7823 {
7824 \@@_join_components_with_bezier_aux:nn {#2}{#3}
7825 \tl_gset_eq:NN #1 \g_@@_output_tl
7826 \tl_gclear:N \g_@@_output_tl
7827 }
7828 \cs_generate_variant:Nn \@@_gjoin_components_with_bezier:Nnn {NVn}
7829 \cs_new_protected_nopar:Npn \@@_gjoin_components_with_bezier:Nn #1#2
7830 {
7831 \@@_gjoin_components_with_bezier:NVn #1#1{#2}
7832 }
7833 \cs_generate_variant:Nn \@@_gjoin_components_with_bezier:Nn {cV}
7834 % \end{macrocode}
7835 % \end{macro}
7836 %
7837 % \begin{macro}[internal]{
7838 % \@@_remove_components:nn
7839 % }
7840 %
7841 % \begin{macrocode}
7842 \cs_new_protected_nopar:Npn \@@_remove_components_aux:nn #1#2
7843 {
7844 \group_begin:
7845
7846 \spath_numberofcomponents:Nn \l_@@_tmpa_int {#1}
7847 \@@_seq_from_foreach:NVn \l_@@_tmpa_seq \l_@@_tmpa_int {#2}
7848
7849 \spath_components_to_seq:Nn \l_@@_tmpb_seq {#1}
7850
7851 \seq_pop_left:NNF \l_@@_tmpa_seq \l_@@_tmpa_tl
7852 {
7853 \tl_clear:N \l_@@_tmpa_tl
7854 }
7855
7856 \seq_clear:N \l_@@_tmpc_seq
7857 \seq_map_indexed_inline:Nn \l_@@_tmpb_seq
7858 {
7859 \tl_set:Nn \l_@@_tmpb_tl {##1}
7860 \tl_if_eq:NNTF \l_@@_tmpb_tl \l_@@_tmpa_tl
7861 {
7862 \seq_pop_left:NNF \l_@@_tmpa_seq \l_@@_tmpa_tl
7863 {
7864 \tl_clear:N \l_@@_tmpa_tl
7865 }
7866 }
7867 {
7868 \seq_put_right:Nn \l_@@_tmpc_seq {##2}
7869 }
7870 }
7871
7872 \tl_gset:Nx \g_@@_output_tl {\seq_use:Nn \l_@@_tmpc_seq {} }
7873 \group_end:
7874 }
7875 \cs_new_protected_nopar:Npn \@@_remove_components:Nnn #1#2#3
7876 {
7877 \@@_remove_components_aux:nn {#2}{#3}
7878 \tl_set_eq:NN #1 \g_@@_output_tl
7879 \tl_gclear:N \g_@@_output_tl
7880 }
7881 \cs_generate_variant:Nn \@@_remove_components:Nnn {NVn}
7882 \cs_new_protected_nopar:Npn \@@_remove_components:Nn #1#2
7883 {
7884 \@@_remove_components:NVn #1#1{#2}
7885 }
7886 \cs_generate_variant:Nn \@@_remove_components:Nn {cn}
7887 \cs_new_protected_nopar:Npn \@@_gremove_components:Nnn #1#2#3
7888 {
7889 \@@_remove_components_aux:nn {#2}{#3}
7890 \tl_gset_eq:NN #1 \g_@@_output_tl
7891 \tl_gclear:N \g_@@_output_tl
7892 }
7893 \cs_generate_variant:Nn \@@_gremove_components:Nnn {NVn}
7894 \cs_new_protected_nopar:Npn \@@_gremove_components:Nn #1#2
7895 {
7896 \@@_gremove_components:NVn #1#1{#2}
7897 }
7898 \cs_generate_variant:Nn \@@_gremove_components:Nn {cn}
7899 % \end{macrocode}
7900 % \end{macro}
7901 %
7902 %
7903 % \begin{macro}[internal]{
7904 % \@@_transform_to:nn,
7905 % \@@_transform_upright_to:nn
7906 % }
7907 % \begin{macrocode}
7908 \cs_new_protected_nopar:Npn \@@_transform_to_aux:nn #1#2
7909 {
7910 \group_begin:
7911 \spath_reallength:Nn \l_@@_tmpa_int {#2}
7912
7913 \tl_set:Nx \l_@@_tmpb_tl
7914 {\fp_to_decimal:n {(#1) * (\l_@@_tmpa_int)}}
7915 \spath_transformation_at:NnV \l_@@_tmpc_tl {#2} \l_@@_tmpb_tl
7916 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpc_tl
7917 \group_end:
7918 }
7919 \cs_new_protected_nopar:Npn \@@_transform_to:nn #1#2
7920 {
7921 \@@_transform_to_aux:nn {#1}{#2}
7922 \exp_last_unbraced:NV \pgfsettransformentries \g_@@_output_tl
7923 \tl_gclear:N \g_@@_output_tl
7924 }
7925 \cs_generate_variant:Nn \@@_transform_to:nn {nv}
7926 \cs_new_protected_nopar:Npn \@@_transform_upright_to:nn #1#2
7927 {
7928 \@@_transform_to_aux:nn {#1}{#2}
7929 \fp_compare:nT { \tl_item:Nn \g_@@_output_tl {4} < 0}
7930 {
7931 \tl_gset:Nx \g_@@_output_tl
7932 {
7933 { \fp_eval:n { - (\tl_item:Nn \g_@@_output_tl {1})} }
7934 { \fp_eval:n { - (\tl_item:Nn \g_@@_output_tl {2})} }
7935 { \fp_eval:n { - (\tl_item:Nn \g_@@_output_tl {3})} }
7936 { \fp_eval:n { - (\tl_item:Nn \g_@@_output_tl {4})} }
7937 { \tl_item:Nn \g_@@_output_tl {5} }
7938 { \tl_item:Nn \g_@@_output_tl {6} }
7939 }
7940 }
7941 \exp_last_unbraced:NV \pgfsettransformentries \g_@@_output_tl
7942 \tl_gclear:N \g_@@_output_tl
7943 }
7944 \cs_generate_variant:Nn \@@_transform_upright_to:nn {nv}
7945 % \end{macrocode}
7946 % \end{macro}
7947 %
7948 %
7949 %
7950 % \subsection{Keys}
7951 % Now we define all of our keys.
7952 %
7953 % \begin{macrocode}
7954 \tikzset{
7955 % \end{macrocode}
7956 %
7957 % We're in the \texttt{spath} key family.
7958 %
7959 % \begin{macrocode}
7960 spath/.is~family,
7961 spath/.cd,
7962 % \end{macrocode}
7963 %
7964 % We provide for saving soft paths with a specific prefix and suffix in the name.
7965 % The default is to make it compatible with the intersections library.
7966 %
7967 % \begin{macrocode}
7968 set~ prefix/.store~ in=\l_@@_prefix_tl,
7969 prefix/.is~choice,
7970 prefix/default/.style={
7971 /tikz/spath/set~ prefix=tikz@intersect@path@name@
7972 },
7973 set~ suffix/.store~ in=\l_@@_suffix_tl,
7974 suffix/.is~choice,
7975 suffix/default/.style={
7976 /tikz/spath/set~ suffix={}
7977 },
7978 set~ name/.style={
7979 /tikz/spath/prefix=#1,
7980 /tikz/spath/suffix=#1
7981 },
7982 % \end{macrocode}
7983 %
7984 % Hook in to the end of the path construction
7985 %
7986 % \begin{macrocode}
7987 at~ end~ path~ construction/.code={
7988 \tl_put_right:Nn \l_@@_tikzpath_finish_tl {#1}
7989 },
7990 % \end{macrocode}
7991 %
7992 % Keys for saving and cloning a soft path.
7993 %
7994 % \begin{macrocode}
7995 save/.code={
7996 \tikz@addmode{
7997 \spath_get_current_path:N \l_@@_tmpa_tl
7998 \spath_bake_round:NV \l_@@_tmpa_tl \l_@@_tmpa_tl
7999 \spath_bake_shorten:NV \l_@@_tmpa_tl \l_@@_tmpa_tl
8000 \spath_save_path:cV {\@@_path_name:n {#1}}
8001 \l_@@_tmpa_tl
8002 }
8003 },
8004 save~ global/.code={
8005 \tikz@addmode{
8006 \spath_get_current_path:N \l_@@_tmpa_tl
8007 \spath_bake_round:NV \l_@@_tmpa_tl \l_@@_tmpa_tl
8008 \spath_bake_shorten:NV \l_@@_tmpa_tl \l_@@_tmpa_tl
8009 \spath_gsave_path:cV {\@@_path_name:n {#1}}
8010 \l_@@_tmpa_tl
8011 }
8012 },
8013 clone/.code~ 2~ args={
8014 \@@_maybe_current_path:nn
8015 {
8016 \@@_check_path:nnn {
8017 \tl_clear_new:c {\@@_path_name:n {#1}}
8018 \tl_set_eq:cc {\@@_path_name:n {#1}}
8019 }
8020 }
8021 {#2}{}
8022 },
8023 clone~ global/.code~ 2~ args={
8024 \@@_maybe_current_path:nn
8025 {
8026 \@@_check_path:nnn {
8027 \tl_gclear_new:c {\@@_path_name:n {#1}}
8028 \tl_gset_eq:cc {\@@_path_name:n {#1}}
8029 }
8030 }
8031 {#2}{}
8032 },
8033 % \end{macrocode}
8034 %
8035 % Saves a soft path to the aux file.
8036 %
8037 % \begin{macrocode}
8038 save~ to~ aux/.code={
8039 \@@_maybe_current_path:nn
8040 {
8041 \@@_check_path:nnn {
8042 \spath_save_to_aux:c
8043 }
8044 }
8045 {#1}
8046 {}
8047 },
8048 % \end{macrocode}
8049 %
8050 % Exports the path as an SVG file.
8051 %
8052 % \begin{macrocode}
8053 export~ to~ svg/.code={
8054 \@@_maybe_current_path:nn
8055 {
8056 \@@_check_path:nnn {
8057 \spath_export_to_svg:nv {#1}
8058 }
8059 }
8060 {#1}
8061 {}
8062 },
8063 % \end{macrocode}
8064 %
8065 % Inserts the named path at the current point in the path, with options for how this is accomplished.
8066 % The inserted path can be transformed, reversed, moved to the current point, and welded to the current path.
8067 % If this is used before the path has been started then it becomes the start of the path (and the ``current point'' is taken as the origin).
8068 %
8069 %
8070 % \begin{macrocode}
8071 use/.code={
8072 \bool_set_false:N \l_@@_reverse_bool
8073 \bool_set_false:N \l_@@_weld_bool
8074 \bool_set_false:N \l_@@_move_bool
8075 \bool_set_false:N \l_@@_current_transformation_bool
8076 \bool_set_true:N \l_spath_movetorelevant_bool
8077 \tl_clear:N \l_@@_joinpath_tl
8078 \tl_clear:N \l_@@_transformation_tl
8079 \tikzset{
8080 spath/join/.cd,
8081 #1
8082 }
8083
8084 \@@_check_path:nVn
8085 {
8086 \@@_use_path:v
8087 } \l_@@_joinpath_tl {}
8088
8089 },
8090 % \end{macrocode}
8091 %
8092 % Some aliases for the above.
8093 %
8094 % \begin{macrocode}
8095 restore/.style={/tikz/spath/use={#1}},
8096 restore~ reverse/.style={/tikz/spath/use={reverse, #1}},
8097 append/.style={/tikz/spath/use={move, weld, #1}},
8098 append~ no~ move/.style={/tikz/spath/use={weld, #1}},
8099 append~ reverse/.style={/tikz/spath/use={move, weld, reverse, #1}},
8100 append~ reverse~ no~ move/.style={/tikz/spath/use={weld, reverse, #1}},
8101 insert/.style={/tikz/spath/use={#1}},
8102 insert~ reverse/.style={/tikz/spath/use={reverse, #1}},
8103 % \end{macrocode}
8104 %
8105 % Diagnostic, show the current path in the terminal and log.
8106 %
8107 % \begin{macrocode}
8108 show~current~path/.code={
8109 \tikz@addmode{
8110 \pgfsyssoftpath@getcurrentpath\l_@@_tmpa_tl
8111 \iow_term:n {---~ current~ soft~ path~ ---}
8112 \spath_show:V \l_@@_tmpa_tl
8113 }
8114 },
8115 % \end{macrocode}
8116 %
8117 % Diagnostic, show the named soft path in the terminal and log.
8118 %
8119 % \begin{macrocode}
8120 show/.code={
8121 \@@_check_path:nnn {
8122 \iow_term:n {---~ soft~ path~ #1~ ---}
8123 \spath_show:v
8124 } {#1} {}
8125 },
8126 % \end{macrocode}
8127 %
8128 % This joins a path on to an existing path, possibly modifying it first.
8129 % The possible options are the same as those for \Verb+use+.
8130 % It is possible to specify the same path both for the initial and the joining path as a copy is made internally first.
8131 %
8132 % \begin{macrocode}
8133 join~ with/.code~ 2~ args={
8134 \bool_set_false:N \l_@@_reverse_bool
8135 \bool_set_false:N \l_@@_weld_bool
8136 \bool_set_false:N \l_@@_move_bool
8137 \bool_set_false:N \l_@@_global_bool
8138 \bool_set_false:N \l_@@_current_transformation_bool
8139 \tl_clear:N \l_@@_joinpath_tl
8140 \tl_clear:N \l_@@_transformation_tl
8141 \tikzset{
8142 spath/join/.cd,
8143 #2
8144 }
8145
8146 \@@_maybe_current_path_reuse:nnn
8147 {
8148 \@@_check_two_paths:nnVn
8149 {
8150 \@@_join_with:cv
8151 }
8152 } {#1} { \l_@@_joinpath_tl {} }
8153 },
8154 % \end{macrocode}
8155 %
8156 % Does a ``spot weld'' on a soft path, which means that any components that start where the previous component ends are welded together.
8157 %
8158 % \begin{macrocode}
8159 spot~ weld/.code={
8160 \@@_maybe_current_path_reuse:nnn
8161 {
8162 \@@_check_path:nnn
8163 {
8164 \spath_spot_weld_components:c
8165 }
8166 } {#1} { {} }
8167 },
8168 spot~ weld~ globally/.code={
8169 \@@_maybe_current_path_reuse:nnn
8170 {
8171 \@@_check_path:nnn
8172 {
8173 \spath_spot_gweld_components:c
8174 }
8175 } {#1} { {} }
8176 },
8177 % \end{macrocode}
8178 %
8179 % Reverses the named path.
8180 %
8181 % \begin{macrocode}
8182 reverse/.code={
8183 \@@_maybe_current_path_reuse:nnn
8184 {
8185 \@@_check_path:nnn
8186 {
8187 \spath_reverse:c
8188 }
8189 } {#1} { {} }
8190 },
8191 reverse~ globally/.code={
8192 \@@_maybe_current_path_reuse:nnn
8193 {
8194 \@@_check_path:nnn
8195 {
8196 \spath_greverse:c
8197 }
8198 } {#1} { {} }
8199 },
8200 % \end{macrocode}
8201 %
8202 % Adjust a path to span between two points.
8203 %
8204 % \begin{macrocode}
8205 span/.code ~n~ args={3}{
8206 \@@_maybe_current_path_reuse:nnn
8207 {
8208 \@@_check_path:nnn
8209 {
8210 \@@_process_tikz_point:Nn \l_@@_tmpa_tl {#2}
8211 \@@_process_tikz_point:Nn \l_@@_tmpb_tl {#3}
8212 \spath_span:cVV
8213 }
8214 } {#1} { {} \l_@@_tmpa_tl \l_@@_tmpb_tl }
8215 },
8216 span~ global/.code ~n~ args={3}{
8217 \@@_maybe_current_path_reuse:nnn
8218 {
8219 \@@_check_path:nnn
8220 {
8221 \@@_process_tikz_point:Nn \l_@@_tmpa_tl {#2}
8222 \@@_process_tikz_point:Nn \l_@@_tmpb_tl {#3}
8223 \spath_span:cVV
8224 }
8225 } {#1} { {} \l_@@_tmpa_tl \l_@@_tmpb_tl }
8226 },
8227 % \end{macrocode}
8228 %
8229 % Defines a to path
8230 %
8231 % \begin{macrocode}
8232 to/.style={
8233 to~path={
8234 [
8235 spath/span={#1}{(\tikztostart)}{(\tikztotarget)},
8236 spath/use={#1,weld},
8237 ]
8238 \tikztonodes
8239 }
8240 },
8241 % \end{macrocode}
8242 %
8243 %
8244 % Splice three paths together, transforming the middle one so that it exactly fits between the first and third.
8245 %
8246 % \begin{macrocode}
8247 splice/.code ~n~ args={3}{
8248 \@@_maybe_current_path_reuse:nnn
8249 {
8250 \@@_check_three_paths:nnnnn
8251 {
8252 \spath_splice_between:cvv
8253 }
8254 } {#1} { {#2} {#3} {} }
8255 },
8256 splice~ global/.code ~n~ args={3}{
8257 \@@_maybe_current_path_reuse:nnn
8258 {
8259 \@@_check_three_paths:nnnnn
8260 {
8261 \spath_gsplice_between:cvv
8262 }
8263 } {#1} { {#2} {#3} {} }
8264 },
8265 % \end{macrocode}
8266 %
8267 % Join the components of a path by splicing in the second path whenever the components are sufficiently far apart.
8268 % The third argument is a list of components to splice after, if it is empty then all components are used and a spot weld is done first so that the splicing only happens if there is an actual gap.
8269 %
8270 % The \Verb+upright+ versions will join with the reflection of the splice path if it detects that the gap is ``upside-down''.
8271 %
8272 %
8273 % \begin{macrocode}
8274 join~ components~ with/.code~2~args={
8275 \tl_if_head_is_group:nTF {#2}
8276 {
8277 \tl_set:Nx \l_@@_tmpc_tl { \tl_item:nn {#2} {1} }
8278 \tl_set:Nx \l_@@_tmpd_tl { \tl_item:nn {#2} {2} }
8279 }
8280 {
8281 \tl_set:Nn \l_@@_tmpc_tl {#2}
8282 \tl_clear:N \l_@@_tmpd_tl
8283 }
8284
8285 \@@_maybe_current_path_reuse:nnn
8286 {
8287 \@@_check_two_paths:nnVn
8288 {
8289 \@@_join_components_with:cvV
8290 }
8291 } {#1} { \l_@@_tmpc_tl {} \l_@@_tmpd_tl }
8292 },
8293 join~ components~ globally~ with/.code~2~args={
8294 \tl_if_head_is_group:nTF {#2}
8295 {
8296 \tl_set:Nx \l_@@_tmpc_tl { \tl_item:nn {#2} {1} }
8297 \tl_set:Nx \l_@@_tmpd_tl { \tl_item:nn {#2} {2} }
8298 }
8299 {
8300 \tl_set:Nn \l_@@_tmpc_tl {#2}
8301 \tl_clear:N \l_@@_tmpd_tl
8302 }
8303
8304 \@@_maybe_current_path_reuse:nnn
8305 {
8306 \@@_check_two_paths:nnVn
8307 {
8308 \@@_gjoin_components_with:cvV
8309 }
8310 } {#1} { \l_@@_tmpc_tl {} \l_@@_tmpd_tl }
8311 },
8312 join~ components~ upright~ with/.code~2~args={
8313 \tl_if_head_is_group:nTF {#2}
8314 {
8315 \tl_set:Nx \l_@@_tmpc_tl { \tl_item:nn {#2} {1} }
8316 \tl_set:Nx \l_@@_tmpd_tl { \tl_item:nn {#2} {2} }
8317 }
8318 {
8319 \tl_set:Nn \l_@@_tmpc_tl {#2}
8320 \tl_clear:N \l_@@_tmpd_tl
8321 }
8322
8323 \@@_maybe_current_path_reuse:nnn
8324 {
8325 \@@_check_two_paths:nnVn
8326 {
8327 \@@_join_components_upright_with:cvV
8328 }
8329 } {#1} { \l_@@_tmpc_tl {} \l_@@_tmpd_tl }
8330 },
8331 join~ components~ globally~ upright~ with/.code~2~args={
8332 \tl_if_head_is_group:nTF {#2}
8333 {
8334 \tl_set:Nx \l_@@_tmpc_tl { \tl_item:nn {#2} {1} }
8335 \tl_set:Nx \l_@@_tmpd_tl { \tl_item:nn {#2} {2} }
8336 }
8337 {
8338 \tl_set:Nn \l_@@_tmpc_tl {#2}
8339 \tl_clear:N \l_@@_tmpd_tl
8340 }
8341
8342 \@@_maybe_current_path_reuse:nnn
8343 {
8344 \@@_check_two_paths:nnVn
8345 {
8346 \@@_gjoin_components_upright_with:cvV
8347 }
8348 } {#1} { \l_@@_tmpc_tl {} \l_@@_tmpd_tl }
8349 },
8350 join~ components~ with~ bezier/.code={
8351 \tl_if_head_is_group:nTF {#1}
8352 {
8353 \tl_set:Nx \l_@@_tmpc_tl { \tl_item:nn {#1} {1} }
8354 \tl_set:Nx \l_@@_tmpd_tl { \tl_item:nn {#1} {2} }
8355 }
8356 {
8357 \tl_set:Nn \l_@@_tmpc_tl {#1}
8358 \tl_clear:N \l_@@_tmpd_tl
8359 }
8360
8361 \@@_maybe_current_path_reuse:nVn
8362 {
8363 \@@_check_path:nnn
8364 {
8365 \@@_join_components_with_bezier:cV
8366 }
8367 } \l_@@_tmpc_tl { {} \l_@@_tmpd_tl }
8368 },
8369 join~ components~ globally~ with~ bezier/.code~2~args={
8370 \@@_maybe_current_path_reuse:nnn
8371 {
8372 \@@_check_path:nnn
8373 {
8374 \@@_gjoin_components_with_bezier:cn
8375 }
8376 } {#1} { {} {#2} }
8377 },
8378 % \end{macrocode}
8379 %
8380 % Close a path.
8381 %
8382 % \begin{macrocode}
8383 close/.code={
8384 \@@_maybe_current_path_reuse:nnn
8385 {
8386 \@@_check_path:nnn
8387 {
8388 \spath_close:c
8389 }
8390 } {#1} { {} }
8391 },
8392 close~ globally/.code={
8393 \@@_maybe_current_path_reuse:nnn
8394 {
8395 \@@_check_path:nnn
8396 {
8397 \spath_gclose:c
8398 }
8399 } {#1} { {} }
8400 },
8401 % \end{macrocode}
8402 %
8403 % Open a path.
8404 %
8405 % \begin{macrocode}
8406 open/.code={
8407 \@@_maybe_current_path_reuse:nnn
8408 {
8409 \@@_check_path:nnn
8410 {
8411 \spath_open:c
8412 }
8413 } {#1} { {} }
8414 },
8415 open~ globally/.code={
8416 \@@_maybe_current_path_reuse:nnn
8417 {
8418 \@@_check_path:nnn
8419 {
8420 \spath_gopen:c
8421 }
8422 } {#1} { {} }
8423 },
8424 % \end{macrocode}
8425 %
8426 % Close a path, ensuring that the end point is exactly where it will close up to.
8427 %
8428 % \begin{macrocode}
8429 adjust~ and~ close/.code={
8430 \@@_maybe_current_path_reuse:nnn
8431 {
8432 \@@_check_path:nnn
8433 {
8434 \spath_adjust_close:c
8435 }
8436 } {#1} { {} }
8437 },
8438 adjust~ and~ close~ globally/.code={
8439 \@@_maybe_current_path_reuse:nnn
8440 {
8441 \@@_check_path:nnn
8442 {
8443 \spath_adjust_gclose:c
8444 }
8445 } {#1} { {} }
8446 },
8447 % \end{macrocode}
8448 %
8449 % Close a path with another path.
8450 %
8451 % \begin{macrocode}
8452 close~ with/.code~ 2~ args={
8453 \@@_maybe_current_path_reuse:nnn
8454 {
8455 \@@_check_two_paths:nnnn
8456 {
8457 \spath_close_with:cv
8458 }
8459 } {#1} { {#2} {} }
8460 },
8461 close~ globally~ with/.code~ 2~ args={
8462 \@@_maybe_current_path_reuse:nnn
8463 {
8464 \@@_check_two_paths:nnnn
8465 {
8466 \spath_gclose_with:cv
8467 }
8468 } {#1} { {#2} {} }
8469 },
8470 % \end{macrocode}
8471 %
8472 % Close a path with a curve.
8473 %
8474 % \begin{macrocode}
8475 close~ with~ curve/.code={
8476 \@@_maybe_current_path_reuse:nnn
8477 {
8478 \@@_check_path:nnn
8479 {
8480 \spath_close_with_curve:c
8481 }
8482 } {#1} { {} }
8483 },
8484 close~ globally~ with~ curve/.code={
8485 \@@_maybe_current_path_reuse:nnn
8486 {
8487 \@@_check_path:nnn
8488 {
8489 \spath_gclose_with_curve:c
8490 }
8491 } {#1} { {} }
8492 },
8493 % \end{macrocode}
8494 %
8495 % These keys shorten the path by a dimension.
8496 %
8497 % \begin{macrocode}
8498 shorten~ at~ end/.code~ 2~ args={
8499 \@@_maybe_current_path_reuse:nnn
8500 {
8501 \@@_check_path:nnn
8502 {
8503 \spath_shorten_at_end:cn
8504 }
8505 } {#1} { {} {#2} }
8506 },
8507 shorten~ at~ start/.code~ 2~ args ={
8508 \@@_maybe_current_path_reuse:nnn
8509 {
8510 \@@_check_path:nnn
8511 {
8512 \spath_shorten_at_start:cn
8513 }
8514 } {#1} { {} {#2} }
8515 },
8516 shorten~ at~ both~ ends/.code~ 2~ args={
8517 \@@_maybe_current_path_reuse:nnn
8518 {
8519 \@@_check_path:nnn
8520 {
8521 \spath_shorten_at_both_ends:cn
8522 }
8523 } {#1} { {} {#2} }
8524 },
8525 shorten~ globally~ at~ end/.code~ 2~ args={
8526 \@@_maybe_current_path_reuse:nnn
8527 {
8528 \@@_check_path:nnn
8529 {
8530 \spath_gshorten_at_end:cn
8531 }
8532 } {#1} { {} {#2} }
8533 },
8534 shorten~ globally~ at~ start/.code~ 2~ args ={
8535 \@@_maybe_current_path_reuse:nnn
8536 {
8537 \@@_check_path:nnn
8538 {
8539 \spath_gshorten_at_start:cn
8540 }
8541 } {#1} { {} {#2} }
8542 },
8543 shorten~ globally~ at~ both~ ends/.code~ 2~ args={
8544 \@@_maybe_current_path_reuse:nnn
8545 {
8546 \@@_check_path:nnn
8547 {
8548 \spath_gshorten_at_both_ends:cn
8549 }
8550 } {#1} { {} {#2} }
8551 },
8552 % \end{macrocode}
8553 %
8554 % These keys split a path at a parameter, the \texttt{keep} versions only keep one part of the resultant path.
8555 %
8556 % \begin{macrocode}
8557 split~ at/.code~ 2~ args={
8558 \@@_maybe_current_path_reuse:nnn
8559 {
8560 \@@_check_path:nnn
8561 {
8562 \spath_split_at_normalised:cn
8563 }
8564 } {#1} { {} {#2} }
8565 },
8566 split~ globally~ at/.code~ 2~ args={
8567 \@@_maybe_current_path_reuse:nnn
8568 {
8569 \@@_check_path:nnn
8570 {
8571 \spath_gsplit_at_normalised:cn
8572 }
8573 } {#1} { {} {#2} }
8574 },
8575 split~ at~ into/.code~ n~ args={4}{
8576 \@@_maybe_current_path_reuse:nnn
8577 {
8578 \@@_check_path:nnn
8579 {
8580 \spath_split_at_normalised:ccvn {\@@_path_name:n {#1}}
8581 {\@@_path_name:n {#2}}
8582 }
8583 } {#3} { {} {#4} }
8584 },
8585 split~ globally~ at~ into/.code~ n~ args={4}{
8586 \@@_maybe_current_path_reuse:nnn
8587 {
8588 \@@_check_path:nnn
8589 {
8590 \spath_gsplit_at_normalised:ccvn {\@@_path_name:n {#1}}
8591 {\@@_path_name:n {#2}}
8592 }
8593 } {#3} { {} {#4} }
8594 },
8595 split~ at~ keep~ start/.code~ 2~ args={
8596 \@@_maybe_current_path_reuse:nnn
8597 {
8598 \@@_check_path:nnn
8599 {
8600 \spath_split_at_normalised_keep_start:cn
8601 }
8602 } {#1} { {} {#2} }
8603 },
8604 split~ globally~ at~ keep~ start/.code~ 2~ args={
8605 \@@_maybe_current_path_reuse:nnn
8606 {
8607 \@@_check_path:nnn
8608 {
8609 \spath_gsplit_at_normalised_keep_start:cn
8610 }
8611 } {#1} { {} {#2} }
8612 },
8613 split~ at~ keep~ end/.code~ 2~ args={
8614 \@@_maybe_current_path_reuse:nnn
8615 {
8616 \@@_check_path:nnn
8617 {
8618 \spath_split_at_normalised_keep_end:cn
8619 }
8620 } {#1} { {} {#2} }
8621 },
8622 split~ globally~ at~ keep~ end/.code~ 2~ args={
8623 \@@_maybe_current_path_reuse:nnn
8624 {
8625 \@@_check_path:nnn
8626 {
8627 \spath_gsplit_at_normalised_keep_end:cn
8628 }
8629 } {#1} { {} {#2} }
8630 },
8631 split~ at~ keep~ middle/.style~ n~ args={3}{
8632 /tikz/spath/split~ at~ keep~ start={#1}{#3},
8633 /tikz/spath/split~ at~ keep~ end={#1}{(#2)/(#3)},
8634 },
8635 split~ globally~ at~ keep~ middle/.style~ n~ args={3}{
8636 /tikz/spath/split~ globally~ at~ keep~ start={#1}{#3},
8637 /tikz/spath/split~ globally~ at~ keep~ end={#1}{(#2)/(#3)},
8638 },
8639 % \end{macrocode}
8640 %
8641 % This translates the named path.
8642 %
8643 % \begin{macrocode}
8644 translate/.code~ n~ args={3}{
8645 \@@_maybe_current_path_reuse:nnn
8646 {
8647 \@@_check_path:nnn
8648 {
8649 \spath_translate:cnn
8650 }
8651 } {#1} { {} {#2}{#3} }
8652 },
8653 translate~ globally/.code~ n~ args={3}{
8654 \@@_maybe_current_path_reuse:nnn
8655 {
8656 \@@_check_path:nnn
8657 {
8658 \spath_gtranslate:cnn
8659 }
8660 } {#1} { {} {#2}{#3} }
8661 },
8662 % \end{macrocode}
8663 %
8664 % This normalises the named path.
8665 %
8666 % \begin{macrocode}
8667 normalise/.code={
8668 \@@_maybe_current_path_reuse:nnn
8669 {
8670 \@@_check_path:nnn
8671 {
8672 \spath_normalise:c
8673 }
8674 } {#1} { {} }
8675 },
8676 normalise~ globally/.code={
8677 \@@_maybe_current_path_reuse:nnn
8678 {
8679 \@@_check_path:nnn
8680 {
8681 \spath_gnormalise:c
8682 }
8683 } {#1} { {} }
8684 },
8685 % \end{macrocode}
8686 %
8687 % Transforms the named path using TikZ transformation specifications.
8688 %
8689 % \begin{macrocode}
8690 transform/.code~ 2~ args={
8691 \group_begin:
8692 \pgftransformreset
8693 \tikzset{#2}
8694 \pgfgettransform \l_@@_tmpa_tl
8695 \tl_gset_eq:NN \g_@@_smuggle_tl \l_@@_tmpa_tl
8696 \group_end:
8697
8698 \@@_maybe_current_path_reuse:nnn
8699 {
8700 \@@_check_path:nnn
8701 {
8702 \spath_transform:cV
8703 }
8704 } {#1} { {} \g_@@_smuggle_tl }
8705 },
8706 transform~globally/.code~ 2~ args={
8707 \group_begin:
8708 \pgftransformreset
8709 \tikzset{#2}
8710 \pgfgettransform \l_@@_tmpa_tl
8711 \tl_gset_eq:NN \g_@@_smuggle_tl \l_@@_tmpa_tl
8712 \group_end:
8713
8714 \@@_maybe_current_path_reuse:nnn
8715 {
8716 \@@_check_path:nnn
8717 {
8718 \spath_gtransform:cV
8719 }
8720 } {#1} { {} \g_@@_smuggle_tl }
8721 },
8722 % \end{macrocode}
8723 %
8724 % Splits first path where it intersects with the second.
8725 %
8726 % \begin{macrocode}
8727 split~ at~ intersections~ with/.code~ 2~ args={
8728 \tl_if_exist:cTF
8729 {
8730 tikz@library@intersections@loaded
8731 }
8732 {
8733 \@@_maybe_current_two_paths_reuse_first:nnnn
8734 {
8735 \@@_check_two_paths:nnnn
8736 {
8737 \spath_split_path_at_intersections:cv
8738 }
8739 } {#1} {#2} { {} }
8740 }
8741 {
8742 \msg_warning:nn { spath3 } { load intersections }
8743 }
8744 },
8745 split~ globally~ at~ intersections~ with/.code~ n~ args={2}{
8746 \tl_if_exist:cTF
8747 {
8748 tikz@library@intersections@loaded
8749 }
8750 {
8751 \@@_maybe_current_two_paths_reuse_first:nnnn
8752 {
8753 \@@_check_two_paths:nnnn
8754 {
8755 \spath_gsplit_path_at_intersections:cv
8756 }
8757 } {#1} {#2} { {} }
8758 }
8759 {
8760 \msg_warning:nn { spath3 } { load intersections }
8761 }
8762 },
8763 % \end{macrocode}
8764 %
8765 % Splits two paths at their mutual intersections.
8766 %
8767 % \begin{macrocode}
8768 split~ at~ intersections/.code~ n~ args={2}{
8769 \tl_if_exist:cTF
8770 {
8771 tikz@library@intersections@loaded
8772 }
8773 {
8774 \@@_maybe_current_two_paths_reuse_both:nnnn
8775 {
8776 \@@_check_two_paths:nnnn
8777 {
8778 \spath_split_at_intersections:cc
8779 }
8780 } {#1} {#2} { {} }
8781 }
8782 {
8783 \msg_warning:nn { spath3 } { load intersections }
8784 }
8785 },
8786 split~ globally~ at~ intersections/.code~ n~ args={2}{
8787 \tl_if_exist:cTF
8788 {
8789 tikz@library@intersections@loaded
8790 }
8791 {
8792 \@@_maybe_current_two_paths_reuse_both:nnnn
8793 {
8794 \@@_check_two_paths:nnnn
8795 {
8796 \spath_gsplit_at_intersections:cc
8797 }
8798 } {#1} {#2} { {} }
8799 }
8800 {
8801 \msg_warning:nn { spath3 } { load intersections }
8802 }
8803 },
8804 % \end{macrocode}
8805 %
8806 % Splits a path at its self-intersections.
8807 %
8808 % \begin{macrocode}
8809 split~ at~ self~ intersections/.code={
8810 \tl_if_exist:cTF
8811 {
8812 tikz@library@intersections@loaded
8813 }
8814 {
8815 \@@_maybe_current_path_reuse:nnn
8816 {
8817 \@@_check_path:nnn
8818 {
8819 \spath_split_at_self_intersections:c
8820 }
8821 } {#1} { {} }
8822 }
8823 {
8824 \msg_warning:nn { spath3 } { load intersections }
8825 }
8826 },
8827 split~ globally~ at~ self~ intersections/.code={
8828 \tl_if_exist:cTF
8829 {
8830 tikz@library@intersections@loaded
8831 }
8832 {
8833 \@@_maybe_current_path_reuse:nnn
8834 {
8835 \@@_check_path:nnn
8836 {
8837 \spath_gsplit_at_self_intersections:c
8838 }
8839 } {#1} { {} }
8840 }
8841 {
8842 \msg_warning:nn { spath3 } { load intersections }
8843 }
8844 },
8845 % \end{macrocode}
8846 %
8847 % Extract the components of a path into a comma separated list (suitable for using in a \Verb+\foreach+ loop).
8848 %
8849 % \begin{macrocode}
8850 get~ components~ of/.code~ 2~ args={
8851 \@@_maybe_current_path:nn
8852 {
8853 \@@_check_path:nnn {
8854 \@@_get_components:Nv #2
8855 }
8856 }
8857 {#1}
8858 {}
8859 },
8860 get~ components~ of~ globally/.code~ 2~ args={
8861 \@@_maybe_current_path:nn
8862 {
8863 \@@_check_path:nnn {
8864 \@@_gget_components:Nv #2
8865 }
8866 }
8867 {#1}
8868 {}
8869 },
8870 % \end{macrocode}
8871 %
8872 % Loop through the components of a soft path and render each as a separate TikZ path so that they can be individually styled.
8873 %
8874 % \begin{macrocode}
8875 render~ components/.code={
8876 \@@_maybe_current_path:nn
8877 {
8878 \@@_check_path:nnn {
8879 \@@_render_components:nv {#1}
8880 }
8881 }
8882 {#1}
8883 {}
8884 },
8885 % \end{macrocode}
8886 %
8887 % This puts gaps between components of a soft path.
8888 % The list of components is passed through a \Verb+\foreach+ loop so can use the shortcut syntax from those loops.
8889 %
8890 % \begin{macrocode}
8891 insert~ gaps~ after~ components/.code~ 2~ args={
8892 \tl_if_head_is_group:nTF {#2}
8893 {
8894 \tl_set:Nx \l_@@_tmpc_tl { \tl_item:nn {#2} {1} }
8895 \tl_set:Nx \l_@@_tmpd_tl { \tl_item:nn {#2} {2} }
8896 }
8897 {
8898 \tl_set:Nn \l_@@_tmpc_tl {#2}
8899 \tl_clear:N \l_@@_tmpd_tl
8900 }
8901
8902 \@@_maybe_current_path_reuse:nnn
8903 {
8904 \@@_check_path:nnn
8905 {
8906 \@@_insert_gaps_after_components:cVV
8907 }
8908 } {#1} { {} \l_@@_tmpc_tl \l_@@_tmpd_tl }
8909 },
8910 insert~ gaps~ globally~ after~ components/.code~ 2~ args={
8911 \tl_if_head_is_group:nTF {#2}
8912 {
8913 \tl_set:Nx \l_@@_tmpc_tl { \tl_item:nn {#2} {1} }
8914 \tl_set:Nx \l_@@_tmpd_tl { \tl_item:nn {#2} {2} }
8915 }
8916 {
8917 \tl_set:Nn \l_@@_tmpc_tl {#2}
8918 \tl_clear:N \l_@@_tmpd_tl
8919 }
8920
8921 \@@_maybe_current_path_reuse:nnn
8922 {
8923 \@@_check_path:nnn
8924 {
8925 \@@_ginsert_gaps_after_components:cVV
8926 }
8927 } {#1} { {} \l_@@_tmpc_tl \l_@@_tmpd_tl }
8928 },
8929 % \end{macrocode}
8930 %
8931 % This puts gaps between segments of a soft path.
8932 % The list of segments is passed through a \Verb+\foreach+ loop so can use the shortcut syntax from those loops.
8933 %
8934 % \begin{macrocode}
8935 insert~ gaps~ after~ segments/.code~ 2~ args={
8936 \tl_if_head_is_group:nTF {#2}
8937 {
8938 \tl_set:Nx \l_@@_tmpc_tl { \tl_item:nn {#2} {1} }
8939 \tl_set:Nx \l_@@_tmpd_tl { \tl_item:nn {#2} {2} }
8940 }
8941 {
8942 \tl_set:Nn \l_@@_tmpc_tl {#2}
8943 \tl_clear:N \l_@@_tmpd_tl
8944 }
8945
8946 \@@_maybe_current_path_reuse:nnn
8947 {
8948 \@@_check_path:nnn
8949 {
8950 \@@_insert_gaps_after_segments:cVV
8951 }
8952 } {#1} { {} \l_@@_tmpc_tl \l_@@_tmpd_tl }
8953 },
8954 insert~ gaps~ globally~ after~ segments/.code~ 2~ args={
8955 \tl_if_head_is_group:nTF {#2}
8956 {
8957 \tl_set:Nx \l_@@_tmpc_tl { \tl_item:nn {#2} {1} }
8958 \tl_set:Nx \l_@@_tmpd_tl { \tl_item:nn {#2} {2} }
8959 }
8960 {
8961 \tl_set:Nn \l_@@_tmpc_tl {#2}
8962 \tl_clear:N \l_@@_tmpd_tl
8963 }
8964
8965 \@@_maybe_current_path_reuse:nnn
8966 {
8967 \@@_check_path:nnn
8968 {
8969 \@@_ginsert_gaps_after_segments:cVV
8970 }
8971 } {#1} { {} \l_@@_tmpc_tl \l_@@_tmpd_tl }
8972 },
8973 % \end{macrocode}
8974 %
8975 % Join the specified components together, joining each to its previous one.
8976 %
8977 % \begin{macrocode}
8978 join~ components/.code~ 2~ args={
8979 \@@_maybe_current_path_reuse:nnn
8980 {
8981 \@@_check_path:nnn
8982 {
8983 \@@_join_components:cn
8984 }
8985 } {#1} { {} {#2} }
8986 },
8987 join~ components~ globally/.code~ 2~ args={
8988 \@@_maybe_current_path_reuse:nnn
8989 {
8990 \@@_check_path:nnn
8991 {
8992 \@@_gjoin_components:cn
8993 }
8994 } {#1} { {} {#2} }
8995 },
8996 % \end{macrocode}
8997 %
8998 % Remove all components of the path that don't actually draw anything.
8999 %
9000 % \begin{macrocode}
9001 remove~ empty~ components/.code={
9002 \@@_maybe_current_path_reuse:nnn
9003 {
9004 \@@_check_path:nnn
9005 {
9006 \spath_remove_empty_components:c
9007 }
9008 } {#1} { {} }
9009 },
9010 remove~ empty~ components~ globally/.code={
9011 \@@_maybe_current_path_reuse:nnn
9012 {
9013 \@@_check_path:nnn
9014 {
9015 \spath_gremove_empty_components:c
9016 }
9017 } {#1} { {} }
9018 },
9019 % \end{macrocode}
9020 %
9021 % Replace all line segments by B\'ezier curves.
9022 %
9023 % \begin{macrocode}
9024 replace~ lines/.code={
9025 \@@_maybe_current_path_reuse:nnn
9026 {
9027 \@@_check_path:nnn
9028 {
9029 \spath_replace_lines:c
9030 }
9031 } {#1} { {} }
9032 },
9033 replace~ lines~ globally/.code={
9034 \@@_maybe_current_path_reuse:nnn
9035 {
9036 \@@_check_path:nnn
9037 {
9038 \spath_greplace_lines:c
9039 }
9040 } {#1} { {} }
9041 },
9042 % \end{macrocode}
9043 %
9044 %
9045 % Remove the specified components.
9046 %
9047 % \begin{macrocode}
9048 remove~ components/.code~ 2~ args={
9049 \@@_maybe_current_path_reuse:nnn
9050 {
9051 \@@_check_path:nnn
9052 {
9053 \@@_remove_components:cn
9054 }
9055 } {#1} { {} {#2} }
9056 },
9057 remove~ components~ globally/.code~ 2~ args={
9058 \@@_maybe_current_path_reuse:nnn
9059 {
9060 \@@_check_path:nnn
9061 {
9062 \@@_gremove_components:cn
9063 }
9064 } {#1} { {} {#2} }
9065 },
9066 % \end{macrocode}
9067 %
9068 % 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.
9069 %
9070 % \begin{macrocode}
9071 draft~ mode/.code={
9072 \@@_set_bool:Nn \l_@@_draft_bool {#1}
9073 },
9074 maybe~ spot~ weld/.code={
9075 \bool_if:NF \l_@@_draft_bool
9076 {
9077 \@@_maybe_current_path_reuse:nnn
9078 {
9079 \@@_check_path:nnn
9080 {
9081 \spath_spot_weld_components:c
9082 }
9083 } {#1} { {} }
9084 }
9085 },
9086 maybe~ spot~ weld~ globally/.code={
9087 \bool_if:NF \l_@@_draft_bool
9088 {
9089 \@@_maybe_current_path_reuse:nnn
9090 {
9091 \@@_check_path:nnn
9092 {
9093 \spath_spot_gweld_components:c
9094 }
9095 } {#1} { {} }
9096 }
9097 },
9098 % \end{macrocode}
9099 %
9100 % Set the transformation to lie along a path.
9101 %
9102 % \begin{macrocode}
9103 transform~ to/.code~ 2~ args={
9104 \@@_maybe_current_path:nn
9105 {
9106 \@@_check_path:nnn {
9107 \@@_transform_to:nv {#2}
9108 }
9109 }
9110 {#1}
9111 {
9112 \pgfsettransformentries {1}{0}{0}{1}{0pt}{0pt}
9113 }
9114 },
9115 % \end{macrocode}
9116 %
9117 % As above, but with a possible extra \(180^\circ\) rotation if needed to ensure that the new \(y\)--axis points vaguely upwards.
9118 %
9119 % \begin{macrocode}
9120 upright~ transform~ to/.code~ 2~ args={
9121 \@@_maybe_current_path:nn
9122 {
9123 \@@_check_path:nnn {
9124 \@@_transform_upright_to:nv {#2}
9125 }
9126 }
9127 {#1}
9128 {
9129 \pgfsettransformentries {1}{0}{0}{1}{0pt}{0pt}
9130 }
9131 },
9132 % \end{macrocode}
9133 %
9134 % This is a useful set of styles for drawing a knot diagram.
9135 %
9136 % \begin{macrocode}
9137 knot/.style~ n~ args={3}{
9138 /tikz/spath/split~ at~ self~ intersections=#1,
9139 /tikz/spath/remove~ empty~ components=#1,
9140 /tikz/spath/insert~ gaps~ after~ components={#1}{#2}{#3},
9141 /tikz/spath/maybe~ spot~ weld=#1,
9142 /tikz/spath/render~ components=#1
9143 },
9144 global~ knot/.style~ n~ args={3}{
9145 /tikz/spath/split~ globally~ at~ self~ intersections=#1,
9146 /tikz/spath/remove~ empty~ components~ globally=#1,
9147 /tikz/spath/insert~ gaps~ globally ~after~ components={#1}{#2}{#3},
9148 /tikz/spath/maybe~ spot~ weld~ globally=#1,
9149 /tikz/spath/render~ components=#1
9150 },
9151 % \end{macrocode}
9152 %
9153 % \begin{macrocode}
9154 arrow~ shortening/.code={
9155 \@@_set_bool:Nn \l_spath_arrow_shortening_bool {#1}
9156 },
9157 % \end{macrocode}
9158 %
9159 % For single argument commands which take a path as their argument, set the default to be \Verb+current+ so that they use the current path.
9160 %
9161 % \begin{macrocode}
9162 show/.default=current,
9163 spot~ weld/.default=current,
9164 spot~ weld~ globally/.default=current,
9165 reverse/.default=current,
9166 reverse~ globally/.default=current,
9167 close/.default=current,
9168 close~ globally/.default=current,
9169 open/.default=current,
9170 open~ globally/.default=current,
9171 adjust~ and~ close/.default=current,
9172 adjust~ and~ close~ globally/.default=current,
9173 close~ with~ curve/.default=current,
9174 close~ globally~ with~ curve/.default=current,
9175 remove~ empty~ components/.default=current,
9176 remove~ empty~ components~ globally/.default=current,
9177 replace~ lines/.default=current,
9178 replace~ lines~ globally/.default=current,
9179 maybe~ spot~ weld/.default=current,
9180 maybe~ spot~ weld~ globally/.default=current,
9181 }
9182 % \end{macrocode}
9183 %
9184 % This defines a coordinate system that finds a position on a soft path.
9185 %
9186 % \begin{macrocode}
9187 \cs_new_protected_nopar:Npn \@@_get_point_at:nn #1#2
9188 {
9189 \group_begin:
9190 \spath_reallength:Nn \l_@@_tmpa_int {#2}
9191 \tl_set:Nx \l_@@_tmpb_tl
9192 {\fp_to_decimal:n {(#1) * (\l_@@_tmpa_int)}}
9193 \spath_point_at:NnV \l_@@_tmpc_tl {#2} \l_@@_tmpb_tl
9194
9195 \tl_clear:N \l_@@_tmpd_tl
9196 \tl_put_right:Nn \l_@@_tmpd_tl {\pgf@x=}
9197 \tl_put_right:Nx \l_@@_tmpd_tl {\tl_item:Nn \l_@@_tmpc_tl {1}}
9198 \tl_put_right:Nn \l_@@_tmpd_tl {\relax}
9199 \tl_put_right:Nn \l_@@_tmpd_tl {\pgf@y=}
9200 \tl_put_right:Nx \l_@@_tmpd_tl {\tl_item:Nn \l_@@_tmpc_tl {2}}
9201 \tl_put_right:Nn \l_@@_tmpd_tl {\relax}
9202
9203 \tl_gset_eq:NN \g_@@_output_tl \l_@@_tmpd_tl
9204 \group_end:
9205 }
9206 \cs_generate_variant:Nn \@@_get_point_at:nn {VV, Vn, Vv}
9207
9208 \tikzdeclarecoordinatesystem{spath}{%
9209 \group_begin:
9210 \tl_set:Nn \l_@@_tmpa_tl {#1}
9211 \tl_trim_spaces:N \l_@@_tmpa_tl
9212
9213 \seq_set_split:NnV \l_@@_tmpa_seq {~} \l_@@_tmpa_tl
9214 \seq_pop_right:NN \l_@@_tmpa_seq \l_@@_tmpb_tl
9215
9216 \tl_set:Nx \l_@@_tmpa_tl { \seq_use:Nn \l_@@_tmpa_seq {~} }
9217
9218 \@@_maybe_current_path:nV
9219 {
9220 \@@_check_path:nnn {
9221 \@@_get_point_at:Vv \l_@@_tmpb_tl
9222 }
9223 }
9224 \l_@@_tmpa_tl
9225 {
9226 \tl_gset_eq:NN \g_@@_output_tl \pgfpointorigin
9227 }
9228
9229 \group_end:
9230 \use:c {pgf@process}{%
9231 \tl_use:N \g_@@_output_tl
9232 \pgftransforminvert
9233 \use:c {pgf@pos@transform@glob}
9234 }
9235 \tl_gclear:N \g_@@_output_tl
9236 }
9237
9238 \ExplSyntaxOff
9239 % \end{macrocode}
9240 % \iffalse
9241 %</tikzspath3>
9242 % \fi
9243 %
9244 % \iffalse
9245 %<*calligraphy>
9246 % \fi
9247 %
9248 % \section{The Calligraphy Package}
9249 %
9250 % \begin{macrocode}
9251 %<@@=cal>
9252 % \end{macrocode}
9253 %
9254 % \subsection{Initialisation}
9255 % \begin{macrocode}
9256 \RequirePackage{spath3}
9257 \ExplSyntaxOn
9258
9259 \tl_new:N \l_@@_tmpa_tl
9260 \tl_new:N \l_@@_tmpb_tl
9261 \tl_new:N \l_@@_tmp_path_tl
9262 \tl_new:N \l_@@_tmp_rpath_tl
9263 \tl_new:N \l_@@_tmp_rpathb_tl
9264 \tl_new:N \l_@@_tmp_patha_tl
9265
9266 \seq_new:N \l_@@_tmpa_seq
9267
9268 \int_new:N \l_@@_tmpa_int
9269 \int_new:N \l_@@_tmpb_int
9270 \int_new:N \g_@@_path_component_int
9271 \int_new:N \g_@@_label_int
9272
9273 \fp_new:N \l_@@_tmpa_fp
9274 \fp_new:N \l_@@_tmpb_fp
9275 \fp_new:N \l_@@_tmpc_fp
9276 \fp_new:N \l_@@_tmpd_fp
9277 \fp_new:N \l_@@_tmpe_fp
9278
9279 \dim_new:N \l_@@_tmpa_dim
9280 \dim_new:N \l_@@_tmpb_dim
9281 \dim_new:N \l_@@_tmpc_dim
9282 \dim_new:N \l_@@_tmpd_dim
9283 \dim_new:N \l_@@_tmpe_dim
9284 \dim_new:N \l_@@_tmpf_dim
9285 \dim_new:N \l_@@_tmpg_dim
9286 \dim_new:N \l_@@_tmph_dim
9287
9288 \bool_new:N \l_@@_annotate_bool
9289 \bool_new:N \l_@@_taper_start_bool
9290 \bool_new:N \l_@@_taper_end_bool
9291 \bool_new:N \l_@@_taperable_bool
9292
9293 \dim_new:N \l_@@_taper_width_dim
9294 \dim_new:N \l_@@_line_width_dim
9295
9296 \bool_set_true:N \l_@@_taper_start_bool
9297 \bool_set_true:N \l_@@_taper_end_bool
9298
9299 \cs_generate_variant:Nn \tl_put_right:Nn {Nv}
9300
9301 \msg_new:nnn { calligraphy } { undefined pen } { The~ pen~ "#1"~ is~ not~ defined. }
9302 % \end{macrocode}
9303 %
9304 % \subsection{TikZ Keys}
9305 %
9306 % The public interface to this package is through TikZ keys and styles.
9307 % \begin{macrocode}
9308 \tikzset{
9309 define~pen/.code={
9310 \tikzset{pen~name=#1}
9311 \pgf@relevantforpicturesizefalse
9312 \tikz@addmode{
9313 \pgfsyssoftpath@getcurrentpath\l_@@_tmpa_tl
9314 \spath_components_to_seq:NV \l_@@_tmpa_seq \l_@@_tmpa_tl
9315 \seq_gclear_new:c {g_@@_pen_\pgfkeysvalueof{/tikz/pen~name}_seq}
9316 \seq_gset_eq:cN
9317 {g_@@_pen_\pgfkeysvalueof{/tikz/pen~name}_seq} \l_@@_tmpa_seq
9318 \pgfusepath{discard}%
9319 }
9320 },
9321 define~pen/.default={default},
9322 use~pen/.code={
9323 \tikzset{pen~name=#1}
9324 \int_gzero:N \g_@@_path_component_int
9325 \cs_set_eq:NN \pgfpathmoveto \cal_moveto:n
9326 \tikz@addmode{
9327 \pgfsyssoftpath@getcurrentpath\l_@@_tmpa_tl
9328 \spath_components_to_seq:NV \l_@@_tmpa_seq \l_@@_tmpa_tl
9329 \tl_if_exist:cTF {g_@@_pen_\pgfkeysvalueof{/tikz/pen~name}_seq}
9330 {
9331 \cal_path_create:Nc \l_@@_tmpa_seq
9332 {g_@@_pen_\pgfkeysvalueof{/tikz/pen~name}_seq}
9333 }
9334 {
9335 \msg_warning:nnx { calligraphy } { undefined pen }
9336 { \pgfkeysvalueof{/tikz/pen~name} }
9337 }
9338 }
9339 },
9340 use~pen/.default={default},
9341 pen~name/.initial={default},
9342 copperplate/.style={pen~name=copperplate},
9343 pen~colour/.initial={black},
9344 weight/.is~choice,
9345 weight/heavy/.style={
9346 line~width=\pgfkeysvalueof{/tikz/heavy~line~width},
9347 taper~width=\pgfkeysvalueof{/tikz/light~line~width},
9348 },
9349 weight/light/.style={
9350 line~width=\pgfkeysvalueof{/tikz/light~line~width},
9351 taper~width=0pt,
9352 },
9353 heavy/.style={
9354 weight=heavy
9355 },
9356 light/.style={
9357 weight=light
9358 },
9359 heavy~line~width/.initial=2pt,
9360 light~line~width/.initial=1pt,
9361 taper/.is~choice,
9362 taper/.default=both,
9363 taper/none/.style={
9364 taper~start=false,
9365 taper~end=false,
9366 },
9367 taper/both/.style={
9368 taper~start=true,
9369 taper~end=true,
9370 },
9371 taper/start/.style={
9372 taper~start=true,
9373 taper~end=false,
9374 },
9375 taper/end/.style={
9376 taper~start=false,
9377 taper~end=true,
9378 },
9379 taper~start/.code={
9380 \tl_if_eq:nnTF {#1} {true}
9381 {
9382 \bool_set_true:N \l_@@_taper_start_bool
9383 }
9384 {
9385 \bool_set_false:N \l_@@_taper_start_bool
9386 }
9387 },
9388 taper~start/.default={true},
9389 taper~end/.code={
9390 \tl_if_eq:nnTF {#1} {true}
9391 {
9392 \bool_set_true:N \l_@@_taper_end_bool
9393 }
9394 {
9395 \bool_set_false:N \l_@@_taper_end_bool
9396 }
9397 },
9398 taper~end/.default={true},
9399 taper~width/.code={\dim_set:Nn \l_@@_taper_width_dim {#1}},
9400 nib~style/.code~2~args={
9401 \tl_clear_new:c {l_@@_nib_style_#1}
9402 \tl_set:cn {l_@@_nib_style_#1} {#2}
9403 },
9404 stroke~style/.code~2~args={
9405 \tl_clear_new:c {l_@@_stroke_style_#1}
9406 \tl_set:cn {l_@@_stroke_style_#1} {#2}
9407 },
9408 this~stroke~style/.code={
9409 \tl_clear_new:c
9410 {l_@@_stroke_inline_style_ \int_use:N \g_@@_path_component_int}
9411 \tl_set:cn
9412 {l_@@_stroke_inline_style_ \int_use:N \g_@@_path_component_int} {#1}
9413 },
9414 annotate/.style={
9415 annotate~if,
9416 annotate~reset,
9417 annotation~style/.update~value={#1},
9418 },
9419 annotate~if/.default={true},
9420 annotate~if/.code={
9421 \tl_if_eq:nnTF {#1} {true}
9422 {
9423 \bool_set_true:N \l_@@_annotate_bool
9424 }
9425 {
9426 \bool_set_false:N \l_@@_annotate_bool
9427 }
9428 },
9429 annotate~reset/.code={
9430 \int_gzero:N \g_@@_label_int
9431 },
9432 annotation~style/.initial={draw,->},
9433 annotation~shift/.initial={(0,1ex)},
9434 every~annotation~node/.initial={anchor=south~west},
9435 annotation~node~style/.code~2~args={
9436 \tl_clear_new:c {l_@@_annotation_style_ #1 _tl}
9437 \tl_set:cn {l_@@_annotation_style_ #1 _tl}{#2}
9438 },
9439 tl~use:N/.code={
9440 \exp_args:NV \pgfkeysalso #1
9441 },
9442 tl~use:c/.code={
9443 \tl_if_exist:cT {#1}
9444 {
9445 \exp_args:Nv \pgfkeysalso {#1}
9446 }
9447 },
9448 /handlers/.update~style/.code={
9449 \tl_if_eq:nnF {#1} {\pgfkeysnovalue}
9450 {
9451 \pgfkeys{\pgfkeyscurrentpath/.code=\pgfkeysalso{#1}}
9452 }
9453 },
9454 /handlers/.update~value/.code={
9455 \tl_if_eq:nnF {#1} {\pgfkeysnovalue}
9456 {
9457 \pgfkeyssetvalue{\pgfkeyscurrentpath}{#1}
9458 }
9459 },
9460 }
9461 % \end{macrocode}
9462 %
9463 % Some wrappers around the TikZ keys.
9464 % \begin{macrocode}
9465 \NewDocumentCommand \pen { O{} }
9466 {
9467 \path[define~ pen,every~ calligraphy~ pen/.try,#1]
9468 }
9469
9470 \NewDocumentCommand \definepen { O{} }
9471 {
9472 \tikz \path[define~ pen,every~ calligraphy~ pen/.try,#1]
9473 }
9474
9475 \NewDocumentCommand \calligraphy { O{} }
9476 {
9477 \path[use~ pen,every~ calligraphy/.try,#1]
9478 }
9479 % \end{macrocode}
9480 %
9481 % \subsection{The Path Creation}
9482 %
9483 % \begin{macro}[internal]{\cal_path_create:NN}
9484 % This is the main command for creating the calligraphic paths.
9485 % First argument is the given path
9486 % Second argument is the pen path
9487 % \begin{macrocode}
9488 \cs_new_protected_nopar:Npn \cal_path_create:NN #1#2
9489 {
9490 \int_zero:N \l_@@_tmpa_int
9491 \seq_map_inline:Nn #1
9492 {
9493 \int_compare:nT {\tl_count:n {##1} > 3}
9494 {
9495
9496 \int_incr:N \l_@@_tmpa_int
9497 \int_zero:N \l_@@_tmpb_int
9498
9499 \tl_set:Nn \l_@@_tmp_path_tl {##1}
9500 \spath_open:N \l_@@_tmp_path_tl
9501 \spath_reverse:NV \l_@@_tmp_rpath_tl \l_@@_tmp_path_tl
9502
9503 \seq_map_inline:Nn #2
9504 {
9505 \int_incr:N \l_@@_tmpb_int
9506 \group_begin:
9507 \pgfsys@beginscope
9508 \cal_apply_style:c {l_@@_stroke_style_ \int_use:N \l_@@_tmpa_int}
9509 \cal_apply_style:c {l_@@_stroke_inline_style_ \int_use:N \l_@@_tmpa_int}
9510 \cal_apply_style:c {l_@@_nib_style_ \int_use:N \l_@@_tmpb_int}
9511
9512 \spath_initialpoint:Nn \l_@@_tmpa_tl {####1}
9513 \tl_set_eq:NN \l_@@_tmp_patha_tl \l_@@_tmp_path_tl
9514 \spath_translate:NV \l_@@_tmp_patha_tl \l_@@_tmpa_tl
9515
9516 \int_compare:nTF {\tl_count:n {####1} == 3}
9517 {
9518 \cal_at_least_three:N \l_@@_tmp_patha_tl
9519 \spath_protocol_path:V \l_@@_tmp_patha_tl
9520
9521 \tikz@options
9522 \dim_set:Nn \l_@@_line_width_dim {\pgflinewidth}
9523 \cal_maybe_taper:N \l_@@_tmp_patha_tl
9524 }
9525 {
9526 \spath_weld:Nn \l_@@_tmp_patha_tl {####1}
9527 \spath_weld:NV \l_@@_tmp_patha_tl \l_@@_tmp_rpath_tl
9528 \spath_reverse:Nn \l_@@_tmp_rpathb_tl {####1}
9529 \spath_weld:NV \l_@@_tmp_patha_tl \l_@@_tmp_rpathb_tl
9530
9531 \tl_clear:N \l_@@_tmpa_tl
9532 \tl_set:Nn \l_@@_tmpa_tl
9533 {
9534 fill=\pgfkeysvalueof{/tikz/pen~colour},
9535 draw=none
9536 }
9537 \tl_if_exist:cT {l_@@_stroke_style_ \int_use:N \l_@@_tmpa_int}
9538 {
9539 \tl_put_right:Nv \l_@@_tmpa_tl
9540 {l_@@_stroke_style_ \int_use:N \l_@@_tmpa_int}
9541 }
9542 \tl_if_exist:cT {l_@@_stroke_inline_style_ \int_use:N \l_@@_tmpa_int}
9543 {
9544 \tl_put_right:Nn \l_@@_tmpa_tl {,}
9545 \tl_put_right:Nv \l_@@_tmpa_tl
9546 {l_@@_stroke_inline_style_ \int_use:N \l_@@_tmpa_int}
9547 }
9548 \tl_if_exist:cT {l_@@_nib_style_ \int_use:N \l_@@_tmpb_int}
9549 {
9550 \tl_put_right:Nn \l_@@_tmpa_tl {,}
9551 \tl_put_right:Nv \l_@@_tmpa_tl
9552 {l_@@_nib_style_ \int_use:N \l_@@_tmpb_int}
9553 }
9554 \spath_tikz_path:VV \l_@@_tmpa_tl \l_@@_tmp_patha_tl
9555 }
9556 \pgfsys@endscope
9557 \group_end:
9558 }
9559
9560 \bool_if:NT \l_@@_annotate_bool
9561 {
9562 \seq_get_right:NN #2 \l_@@_tmpa_tl
9563 \spath_finalpoint:NV \l_@@_tmpa_tl \l_@@_tmpa_tl
9564 \spath_translate:NV \l_@@_tmp_path_tl \l_@@_tmpa_tl
9565 \tikz@scan@one@point
9566 \pgfutil@firstofone
9567 \pgfkeysvalueof{/tikz/annotation~shift}
9568
9569 \spath_translate:Nnn \l_@@_tmp_path_tl {\pgf@x} {\pgf@y}
9570
9571 \pgfkeysgetvalue{/tikz/annotation~style}{\l_@@_tmpa_tl}
9572 \spath_tikz_path:VV \l_@@_tmpa_tl \l_@@_tmp_path_tl
9573
9574 \spath_finalpoint:NV \l_@@_tmpa_tl \l_@@_tmp_path_tl
9575
9576 \exp_last_unbraced:NV \pgfqpoint \l_@@_tmpa_tl
9577 \begin{scope}[reset~ cm]
9578 \node[
9579 every~annotation~node/.try,
9580 tl~use:c = {l_@@_annotation_style_ \int_use:N \l_@@_tmpa_int _tl}
9581 ] at (\pgf@x,\pgf@y) {\int_use:N \l_@@_tmpa_int};
9582 \end{scope}
9583 }
9584 }
9585 }
9586 }
9587 \cs_generate_variant:Nn \cal_path_create:NN {Nc}
9588 % \end{macrocode}
9589 % \end{macro}
9590 %
9591 % \begin{macro}[internal]{\cal_moveto:n}
9592 % When creating the path, we need to keep track of the number of components so that we can apply styles accordingly.
9593 % \begin{macrocode}
9594 \cs_new_eq:NN \cal_orig_moveto:n \pgfpathmoveto
9595 \cs_new_nopar:Npn \cal_moveto:n #1
9596 {
9597 \int_gincr:N \g_@@_path_component_int
9598 \cal_orig_moveto:n {#1}
9599 }
9600 % \end{macrocode}
9601 % \end{macro}
9602 %
9603 % \begin{macro}[internal]{\cal_apply_style:N}
9604 % Interface for applying \Verb+\tikzset+ to a token list.
9605 % \begin{macrocode}
9606 \cs_new_nopar:Npn \cal_apply_style:N #1
9607 {
9608 \tl_if_exist:NT #1 {
9609 \exp_args:NV \tikzset #1
9610 }
9611 }
9612 \cs_generate_variant:Nn \cal_apply_style:N {c}
9613 % \end{macrocode}
9614 % \end{macro}
9615 %
9616 % \begin{macro}[internal]{\cal_at_least_three:Nn}
9617 % A tapered path has to have at least three components.
9618 % This figures out if it is necessary and sets up the splitting.
9619 % \begin{macrocode}
9620 \cs_new_protected_nopar:Npn \cal_at_least_three:Nn #1#2
9621 {
9622 \spath_reallength:Nn \l_@@_tmpa_int {#2}
9623 \tl_clear:N \l_@@_tmpb_tl
9624 \tl_set:Nn \l_@@_tmpb_tl {#2}
9625 \int_compare:nTF {\l_@@_tmpa_int = 1}
9626 {
9627 \spath_split_at:Nn \l_@@_tmpb_tl {2/3}
9628 \spath_split_at:Nn \l_@@_tmpb_tl {1/2}
9629 }
9630 {
9631 \int_compare:nT {\l_@@_tmpa_int = 2}
9632 {
9633 \spath_split_at:Nn \l_@@_tmpb_tl {1.5}
9634 \spath_split_at:Nn \l_@@_tmpb_tl {.5}
9635 }
9636 }
9637 \tl_set_eq:NN #1 \l_@@_tmpb_tl
9638 }
9639 \cs_generate_variant:Nn \cal_at_least_three:Nn {NV}
9640 \cs_new_protected_nopar:Npn \cal_at_least_three:N #1
9641 {
9642 \cal_at_least_three:NV #1#1
9643 }
9644 \cs_generate_variant:Nn \cal_at_least_three:N {c}
9645 % \end{macrocode}
9646 % \end{macro}
9647 %
9648 % \begin{macro}[internal]{\cal_maybe_taper:N}
9649 % Possibly tapers the path, depending on the booleans.
9650 % \begin{macrocode}
9651 \cs_new_protected_nopar:Npn \cal_maybe_taper:N #1
9652 {
9653 \tl_set_eq:NN \l_@@_tmpa_tl #1
9654
9655 \bool_if:NT \l_@@_taper_start_bool
9656 {
9657
9658 \dim_set:Nn \l_@@_tmpa_dim {\tl_item:Nn \l_@@_tmpa_tl {2}}
9659 \dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpa_tl {3}}
9660 \tl_set:Nx \l_@@_tmpb_tl {\tl_item:Nn \l_@@_tmpa_tl {4}}
9661
9662 \token_case_meaning:NnF \l_@@_tmpb_tl
9663 {
9664 \c_spath_lineto_tl
9665 {
9666
9667 \bool_set_true:N \l_@@_taperable_bool
9668 \dim_set:Nn \l_@@_tmpg_dim {\tl_item:Nn \l_@@_tmpa_tl {5}}
9669 \dim_set:Nn \l_@@_tmph_dim {\tl_item:Nn \l_@@_tmpa_tl {6}}
9670 \dim_set:Nn \l_@@_tmpc_dim {(2\l_@@_tmpa_dim + \l_@@_tmpg_dim)/3}
9671 \dim_set:Nn \l_@@_tmpd_dim {(2\l_@@_tmpb_dim + \l_@@_tmph_dim)/3}
9672 \dim_set:Nn \l_@@_tmpe_dim {(\l_@@_tmpa_dim + 2\l_@@_tmpg_dim)/3}
9673 \dim_set:Nn \l_@@_tmpf_dim {(\l_@@_tmpb_dim + 2\l_@@_tmph_dim)/3}
9674 \prg_replicate:nn {4}
9675 {
9676 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
9677 }
9678 \tl_put_left:NV \l_@@_tmpa_tl \c_spath_moveto_tl
9679 }
9680 \c_spath_curvetoa_tl
9681 {
9682 \bool_set_true:N \l_@@_taperable_bool
9683 \dim_set:Nn \l_@@_tmpc_dim {\tl_item:Nn \l_@@_tmpa_tl {5}}
9684 \dim_set:Nn \l_@@_tmpd_dim {\tl_item:Nn \l_@@_tmpa_tl {6}}
9685 \dim_set:Nn \l_@@_tmpe_dim {\tl_item:Nn \l_@@_tmpa_tl {8}}
9686 \dim_set:Nn \l_@@_tmpf_dim {\tl_item:Nn \l_@@_tmpa_tl {9}}
9687 \dim_set:Nn \l_@@_tmpg_dim {\tl_item:Nn \l_@@_tmpa_tl {11}}
9688 \dim_set:Nn \l_@@_tmph_dim {\tl_item:Nn \l_@@_tmpa_tl {12}}
9689 \prg_replicate:nn {10}
9690 {
9691 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
9692 }
9693 \tl_put_left:NV \l_@@_tmpa_tl \c_spath_moveto_tl
9694 }
9695 }
9696 {
9697 \bool_set_false:N \l_@@_taperable_bool
9698 }
9699
9700 \bool_if:NT \l_@@_taperable_bool
9701 {
9702 \@@_taper_aux:
9703 }
9704
9705 }
9706
9707 \bool_if:NT \l_@@_taper_end_bool
9708 {
9709
9710 \dim_set:Nn \l_@@_tmpa_dim {\tl_item:Nn \l_@@_tmpa_tl {-2}}
9711 \dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpa_tl {-1}}
9712 \tl_set:Nx \l_@@_tmpb_tl {\tl_item:Nn \l_@@_tmpa_tl {-3}}
9713
9714 \token_case_meaning:NnF \l_@@_tmpb_tl
9715 {
9716 \c_spath_lineto_tl
9717 {
9718
9719 \bool_set_true:N \l_@@_taperable_bool
9720 \dim_set:Nn \l_@@_tmpg_dim {\tl_item:Nn \l_@@_tmpa_tl {-5}}
9721 \dim_set:Nn \l_@@_tmph_dim {\tl_item:Nn \l_@@_tmpa_tl {-4}}
9722 \dim_set:Nn \l_@@_tmpc_dim {(2\l_@@_tmpa_dim + \l_@@_tmpg_dim)/3}
9723 \dim_set:Nn \l_@@_tmpd_dim {(2\l_@@_tmpb_dim + \l_@@_tmph_dim)/3}
9724 \dim_set:Nn \l_@@_tmpe_dim {(\l_@@_tmpa_dim + 2\l_@@_tmpg_dim)/3}
9725 \dim_set:Nn \l_@@_tmpf_dim {(\l_@@_tmpb_dim + 2\l_@@_tmph_dim)/3}
9726 \tl_reverse:N \l_@@_tmpa_tl
9727 \prg_replicate:nn {3}
9728 {
9729 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
9730 }
9731 \tl_reverse:N \l_@@_tmpa_tl
9732 }
9733 \c_spath_curveto_tl
9734 {
9735 \bool_set_true:N \l_@@_taperable_bool
9736 \dim_set:Nn \l_@@_tmpc_dim {\tl_item:Nn \l_@@_tmpa_tl {-5}}
9737 \dim_set:Nn \l_@@_tmpd_dim {\tl_item:Nn \l_@@_tmpa_tl {-4}}
9738 \dim_set:Nn \l_@@_tmpe_dim {\tl_item:Nn \l_@@_tmpa_tl {-8}}
9739 \dim_set:Nn \l_@@_tmpf_dim {\tl_item:Nn \l_@@_tmpa_tl {-7}}
9740 \dim_set:Nn \l_@@_tmpg_dim {\tl_item:Nn \l_@@_tmpa_tl {-11}}
9741 \dim_set:Nn \l_@@_tmph_dim {\tl_item:Nn \l_@@_tmpa_tl {-10}}
9742 \tl_reverse:N \l_@@_tmpa_tl
9743 \prg_replicate:nn {9}
9744 {
9745 \tl_set:Nx \l_@@_tmpa_tl {\tl_tail:N \l_@@_tmpa_tl}
9746 }
9747 \tl_reverse:N \l_@@_tmpa_tl
9748 }
9749 }
9750 {
9751 \bool_set_false:N \l_@@_taperable_bool
9752 }
9753
9754 \bool_if:NT \l_@@_taperable_bool
9755 {
9756 \@@_taper_aux:
9757 }
9758
9759 }
9760
9761 \pgfsyssoftpath@setcurrentpath\l_@@_tmpa_tl
9762 \pgfsetstrokecolor{\pgfkeysvalueof{/tikz/pen~colour}}
9763 \pgfusepath{stroke}
9764
9765 }
9766 % \end{macrocode}
9767 % \end{macro}
9768 %
9769 % \begin{macro}[internal]{\@@_taper_aux:}
9770 % Auxiliary macro to avoid unnecessary code duplication.
9771 % \begin{macrocode}
9772 \cs_new_protected_nopar:Npn \@@_taper_aux:
9773 {
9774 \tl_clear:N \l_@@_tmpb_tl
9775 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_moveto_tl
9776
9777 \fp_set:Nn \l_@@_tmpa_fp
9778 {
9779 \l_@@_tmpd_dim - \l_@@_tmpb_dim
9780 }
9781 \fp_set:Nn \l_@@_tmpb_fp
9782 {
9783 \l_@@_tmpa_dim - \l_@@_tmpc_dim
9784 }
9785 \fp_set:Nn \l_@@_tmpe_fp
9786 {
9787 (\l_@@_tmpa_fp^2 + \l_@@_tmpb_fp^2)^.5
9788 }
9789
9790 \fp_set:Nn \l_@@_tmpa_fp
9791 {
9792 .5*\l_@@_taper_width_dim
9793 *
9794 \l_@@_tmpa_fp / \l_@@_tmpe_fp
9795 }
9796 \fp_set:Nn \l_@@_tmpb_fp
9797 {
9798 .5*\l_@@_taper_width_dim
9799 *
9800 \l_@@_tmpb_fp / \l_@@_tmpe_fp
9801 }
9802
9803 \fp_set:Nn \l_@@_tmpc_fp
9804 {
9805 \l_@@_tmph_dim - \l_@@_tmpf_dim
9806 }
9807 \fp_set:Nn \l_@@_tmpd_fp
9808 {
9809 \l_@@_tmpe_dim - \l_@@_tmpg_dim
9810 }
9811 \fp_set:Nn \l_@@_tmpe_fp
9812 {
9813 (\l_@@_tmpc_fp^2 + \l_@@_tmpd_fp^2)^.5
9814 }
9815
9816 \fp_set:Nn \l_@@_tmpc_fp
9817 {
9818 .5*\l_@@_line_width_dim
9819 *
9820 \l_@@_tmpc_fp / \l_@@_tmpe_fp
9821 }
9822 \fp_set:Nn \l_@@_tmpd_fp
9823 {
9824 .5*\l_@@_line_width_dim
9825 *
9826 \l_@@_tmpd_fp / \l_@@_tmpe_fp
9827 }
9828
9829 \tl_put_right:Nx \l_@@_tmpb_tl
9830 {
9831 {\dim_eval:n { \fp_to_dim:N \l_@@_tmpa_fp + \l_@@_tmpa_dim}}
9832 {\dim_eval:n { \fp_to_dim:N \l_@@_tmpb_fp + \l_@@_tmpb_dim}}
9833 }
9834
9835 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetoa_tl
9836
9837 \tl_put_right:Nx \l_@@_tmpb_tl
9838 {
9839 {\dim_eval:n { \fp_to_dim:N \l_@@_tmpa_fp + \l_@@_tmpc_dim}}
9840 {\dim_eval:n { \fp_to_dim:N \l_@@_tmpb_fp + \l_@@_tmpd_dim}}
9841 }
9842
9843 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetob_tl
9844
9845 \tl_put_right:Nx \l_@@_tmpb_tl
9846 {
9847 {\dim_eval:n { \fp_to_dim:N \l_@@_tmpc_fp + \l_@@_tmpe_dim}}
9848 {\dim_eval:n { \fp_to_dim:N \l_@@_tmpd_fp + \l_@@_tmpf_dim}}
9849 }
9850
9851 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curveto_tl
9852
9853 \tl_put_right:Nx \l_@@_tmpb_tl
9854 {
9855 {\dim_eval:n { \fp_to_dim:N \l_@@_tmpc_fp + \l_@@_tmpg_dim}}
9856 {\dim_eval:n { \fp_to_dim:N \l_@@_tmpd_fp + \l_@@_tmph_dim}}
9857 }
9858
9859 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetoa_tl
9860
9861 \tl_put_right:Nx \l_@@_tmpb_tl
9862 {
9863 {
9864 \dim_eval:n
9865 {
9866 \fp_to_dim:N \l_@@_tmpc_fp + \l_@@_tmpg_dim
9867 - \fp_to_dim:n{ 1.32 * \l_@@_tmpd_fp
9868 }
9869 }
9870 }
9871 {
9872 \dim_eval:n
9873 {
9874 \fp_to_dim:N \l_@@_tmpd_fp + \l_@@_tmph_dim
9875 + \fp_to_dim:n {1.32* \l_@@_tmpc_fp
9876 }
9877 }
9878 }
9879 }
9880
9881 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetob_tl
9882
9883 \tl_put_right:Nx \l_@@_tmpb_tl
9884 {
9885 {
9886 \dim_eval:n
9887 {
9888 -\fp_to_dim:N \l_@@_tmpc_fp + \l_@@_tmpg_dim
9889 - \fp_to_dim:n {1.32 * \l_@@_tmpd_fp
9890 }
9891 }
9892 }
9893 {
9894 \dim_eval:n
9895 {
9896 -\fp_to_dim:N \l_@@_tmpd_fp + \l_@@_tmph_dim
9897 + \fp_to_dim:n {1.32 * \l_@@_tmpc_fp
9898 }
9899 }
9900 }
9901 }
9902
9903 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curveto_tl
9904
9905 \tl_put_right:Nx \l_@@_tmpb_tl
9906 {
9907 {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpc_fp + \l_@@_tmpg_dim}}
9908 {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpd_fp + \l_@@_tmph_dim}}
9909 }
9910
9911 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetoa_tl
9912
9913 \tl_put_right:Nx \l_@@_tmpb_tl
9914 {
9915 {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpc_fp + \l_@@_tmpe_dim}}
9916 {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpd_fp + \l_@@_tmpf_dim}}
9917 }
9918
9919 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetob_tl
9920
9921 \tl_put_right:Nx \l_@@_tmpb_tl
9922 {
9923 {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpa_fp + \l_@@_tmpc_dim}}
9924 {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpb_fp + \l_@@_tmpd_dim}}
9925 }
9926
9927 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curveto_tl
9928
9929 \tl_put_right:Nx \l_@@_tmpb_tl
9930 {
9931 {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpa_fp + \l_@@_tmpa_dim}}
9932 {\dim_eval:n { -\fp_to_dim:N \l_@@_tmpb_fp + \l_@@_tmpb_dim}}
9933 }
9934
9935 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetoa_tl
9936
9937 \tl_put_right:Nx \l_@@_tmpb_tl
9938 {
9939 {
9940 \dim_eval:n
9941 {
9942 -\fp_to_dim:N \l_@@_tmpa_fp + \l_@@_tmpa_dim
9943 + \fp_to_dim:n{ 1.32 * \l_@@_tmpb_fp}
9944 }
9945 }
9946 {
9947 \dim_eval:n
9948 {
9949 -\fp_to_dim:N \l_@@_tmpb_fp + \l_@@_tmpb_dim
9950 - \fp_to_dim:n {1.32* \l_@@_tmpa_fp}
9951 }
9952 }
9953 }
9954
9955 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curvetob_tl
9956
9957 \tl_put_right:Nx \l_@@_tmpb_tl
9958 {
9959 {
9960 \dim_eval:n
9961 {
9962 \fp_to_dim:N \l_@@_tmpa_fp + \l_@@_tmpa_dim
9963 + \fp_to_dim:n {1.32 * \l_@@_tmpb_fp}
9964 }
9965 }
9966 {
9967 \dim_eval:n
9968 {
9969 \fp_to_dim:N \l_@@_tmpb_fp + \l_@@_tmpb_dim
9970 - \fp_to_dim:n {1.32 * \l_@@_tmpa_fp}
9971 }
9972 }
9973 }
9974
9975 \tl_put_right:NV \l_@@_tmpb_tl \c_spath_curveto_tl
9976
9977 \tl_put_right:Nx \l_@@_tmpb_tl
9978 {
9979 {\dim_eval:n { \fp_to_dim:N \l_@@_tmpa_fp + \l_@@_tmpa_dim}}
9980 {\dim_eval:n { \fp_to_dim:N \l_@@_tmpb_fp + \l_@@_tmpb_dim}}
9981 }
9982
9983 \pgfsyssoftpath@setcurrentpath\l_@@_tmpb_tl
9984 \pgfsetfillcolor{\pgfkeysvalueof{/tikz/pen~colour}}
9985 \pgfusepath{fill}
9986 }
9987 % \end{macrocode}
9988 % \end{macro}
9989 %
9990 % Defines a copperplate pen.
9991 % \begin{macrocode}
9992 \tl_set:Nn \l_@@_tmpa_tl {\pgfsyssoftpath@movetotoken{0pt}{0pt}}
9993 \spath_components_to_seq:NV \l_@@_tmpa_seq \l_@@_tmpa_tl
9994 \seq_gclear_new:N \g_@@_pen_copperplate_seq
9995 \seq_gset_eq:NN \g_@@_pen_copperplate_seq \l_@@_tmpa_seq
9996 % \end{macrocode}
9997 %
9998 % \begin{macro}[internal]{\CopperplatePath}
9999 % This is used in the decorations section to convert a path to a copperplate path.
10000 % \begin{macrocode}
10001 \DeclareDocumentCommand \CopperplatePath { m }
10002 {
10003 \spath_components_to_seq:NV \l_@@_tmpa_seq #1
10004 \cal_path_create:NN \l_@@_tmpa_seq \g_@@_pen_copperplate_seq
10005 }
10006 % \end{macrocode}
10007 % \end{macro}
10008 %
10009 % \begin{macrocode}
10010 \ExplSyntaxOff
10011 % \end{macrocode}
10012 %
10013 % \subsection{Decorations}
10014 %
10015 % If a decoration library is loaded we define some decorations that use the calligraphy library, specifically the copperplate pen with its tapering.
10016 %
10017 % First, a brace decoration.
10018 % \begin{macrocode}
10019 \expandafter\ifx\csname pgfdeclaredecoration\endcsname\relax
10020 \else
10021 \pgfdeclaredecoration{calligraphic brace}{brace}%
10022 {%
10023 \state{brace}[width=+\pgfdecoratedremainingdistance,next state=final]%
10024 {%
10025 \pgfsyssoftpath@setcurrentpath{\pgfutil@empty}%
10026 \pgfpathmoveto{\pgfpointorigin}%
10027 \pgfpathcurveto%
10028 {%
10029 \pgfqpoint%
10030 {.15\pgfdecorationsegmentamplitude}%
10031 {.3\pgfdecorationsegmentamplitude}%
10032 }%
10033 {%
10034 \pgfqpoint%
10035 {.5\pgfdecorationsegmentamplitude}%
10036 {.5\pgfdecorationsegmentamplitude}%
10037 }%
10038 {%
10039 \pgfqpoint%
10040 {\pgfdecorationsegmentamplitude}%
10041 {.5\pgfdecorationsegmentamplitude}%
10042 }%
10043 {%
10044 \pgftransformxshift%
10045 {+\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance}%
10046 \pgfpathlineto%
10047 {%
10048 \pgfqpoint%
10049 {-\pgfdecorationsegmentamplitude}%
10050 {.5\pgfdecorationsegmentamplitude}%
10051 }%
10052 \pgfpathcurveto
10053 {%
10054 \pgfqpoint%
10055 {-.5\pgfdecorationsegmentamplitude}%
10056 {.5\pgfdecorationsegmentamplitude}%
10057 }%
10058 {%
10059 \pgfqpoint%
10060 {-.15\pgfdecorationsegmentamplitude}%
10061 {.7\pgfdecorationsegmentamplitude}%
10062 }%
10063 {%
10064 \pgfqpoint%
10065 {0\pgfdecorationsegmentamplitude}%
10066 {1\pgfdecorationsegmentamplitude}%
10067 }%
10068 \pgfpathmoveto%
10069 {%
10070 \pgfqpoint%
10071 {0\pgfdecorationsegmentamplitude}%
10072 {1\pgfdecorationsegmentamplitude}%
10073 }%
10074 \pgfpathcurveto%
10075 {%
10076 \pgfqpoint%
10077 {.15\pgfdecorationsegmentamplitude}%
10078 {.7\pgfdecorationsegmentamplitude}%
10079 }%
10080 {%
10081 \pgfqpoint%
10082 {.5\pgfdecorationsegmentamplitude}%
10083 {.5\pgfdecorationsegmentamplitude}%
10084 }%
10085 {%
10086 \pgfqpoint%
10087 {\pgfdecorationsegmentamplitude}%
10088 {.5\pgfdecorationsegmentamplitude}%
10089 }%
10090 }%
10091 {%
10092 \pgftransformxshift{+\pgfdecoratedremainingdistance}%
10093 \pgfpathlineto%
10094 {%
10095 \pgfqpoint%
10096 {-\pgfdecorationsegmentamplitude}%
10097 {.5\pgfdecorationsegmentamplitude}%
10098 }%
10099 \pgfpathcurveto%
10100 {%
10101 \pgfqpoint%
10102 {-.5\pgfdecorationsegmentamplitude}%
10103 {.5\pgfdecorationsegmentamplitude}%
10104 }%
10105 {%
10106 \pgfqpoint%
10107 {-.15\pgfdecorationsegmentamplitude}%
10108 {.3\pgfdecorationsegmentamplitude}%
10109 }%
10110 {\pgfqpoint{0pt}{0pt}}%
10111 }%
10112 \tikzset{%
10113 taper width=.5\pgflinewidth,%
10114 taper%
10115 }%%
10116 \pgfsyssoftpath@getcurrentpath\cal@tmp@path%
10117 \CopperplatePath{\cal@tmp@path}%
10118 }%
10119 \state{final}{}%
10120 }%
10121 % \end{macrocode}
10122 %
10123 % The second is a straightened parenthesis (so that when very large it doesn't bow out too far).
10124 % \begin{macrocode}
10125 \pgfdeclaredecoration{calligraphic straight parenthesis}{brace}
10126 {
10127 \state{brace}[width=+\pgfdecoratedremainingdistance,next state=final]%
10128 {%
10129 \pgfsyssoftpath@setcurrentpath{\pgfutil@empty}%
10130 \pgfpathmoveto{\pgfpointorigin}%
10131 \pgfpathcurveto%
10132 {%
10133 \pgfqpoint%
10134 {.76604\pgfdecorationsegmentamplitude}%
10135 {.64279\pgfdecorationsegmentamplitude}%
10136 }%
10137 {%
10138 \pgfqpoint%
10139 {2.3333\pgfdecorationsegmentamplitude}%
10140 {\pgfdecorationsegmentamplitude}%
10141 }%
10142 {%
10143 \pgfqpoint%
10144 {3.3333\pgfdecorationsegmentamplitude}%
10145 {\pgfdecorationsegmentamplitude}%
10146 }%
10147 {%
10148 \pgftransformxshift{+\pgfdecoratedremainingdistance}%
10149 \pgfpathlineto%
10150 {%
10151 \pgfqpoint%
10152 {-3.3333\pgfdecorationsegmentamplitude}%
10153 {\pgfdecorationsegmentamplitude}%
10154 }%
10155 \pgfpathcurveto%
10156 {%
10157 \pgfqpoint%
10158 {-2.3333\pgfdecorationsegmentamplitude}%
10159 {\pgfdecorationsegmentamplitude}%
10160 }%
10161 {%
10162 \pgfqpoint%
10163 {-.76604\pgfdecorationsegmentamplitude}%
10164 {.64279\pgfdecorationsegmentamplitude}%
10165 }%
10166 {\pgfqpoint{0pt}{0pt}}%
10167 }%
10168 \tikzset{%
10169 taper width=.5\pgflinewidth,%
10170 taper%
10171 }%
10172 \pgfsyssoftpath@getcurrentpath\cal@tmp@path%
10173 \CopperplatePath{\cal@tmp@path}%
10174 }%
10175 \state{final}{}%
10176 }
10177 % \end{macrocode}
10178 %
10179 % The third is a curved parenthesis.
10180 % \begin{macrocode}
10181 \pgfdeclaredecoration{calligraphic curved parenthesis}{brace}
10182 {
10183 \state{brace}[width=+\pgfdecoratedremainingdistance,next state=final]%
10184 {%
10185 \pgfsyssoftpath@setcurrentpath{\pgfutil@empty}%
10186 \pgfpathmoveto{\pgfpointorigin}%
10187 \pgf@xa=\pgfdecoratedremainingdistance\relax%
10188 \advance\pgf@xa by -1.5890\pgfdecorationsegmentamplitude\relax%
10189 \edef\cgrphy@xa{\the\pgf@xa}%
10190 \pgfpathcurveto%
10191 {%
10192 \pgfqpoint%
10193 {1.5890\pgfdecorationsegmentamplitude}%
10194 {1.3333\pgfdecorationsegmentamplitude}%
10195 }%
10196 {\pgfqpoint{\cgrphy@xa}{1.3333\pgfdecorationsegmentamplitude}}%
10197 {\pgfqpoint{\pgfdecoratedremainingdistance}{0pt}}%
10198 \tikzset{%
10199 taper width=.5\pgflinewidth,%
10200 taper%
10201 }%
10202 \pgfsyssoftpath@getcurrentpath\cal@tmp@path%
10203 \CopperplatePath{\cal@tmp@path}%
10204 }%
10205 \state{final}{}%
10206 }
10207 % \end{macrocode}
10208 % End the conditional for if pgfdecoration module is loaded
10209 % \begin{macrocode}
10210 \fi
10211 % \end{macrocode}
10212 % \iffalse
10213 %</calligraphy>
10214 % \fi
10215 %
10216 %
10217 % \iffalse
10218 %<*knots>
10219 % \fi
10220 %%
10221 % \section{Drawing Knots}
10222 %
10223 % \begin{macrocode}
10224 %<@@=knot>
10225 % \end{macrocode}
10226 %
10227 % \subsection{Initialisation}
10228 %
10229 % We load the \Verb+spath3+ library and the \Verb+intersections+ TikZ library.
10230 % Then we get going.
10231 % \begin{macrocode}
10232 \RequirePackage{spath3}
10233 \usetikzlibrary{intersections,spath3}
10234
10235 \ExplSyntaxOn
10236
10237 \tl_new:N \l_@@_tmpa_tl
10238 \tl_new:N \l_@@_tmpb_tl
10239 \tl_new:N \l_@@_tmpc_tl
10240 \tl_new:N \l_@@_tmpd_tl
10241 \tl_new:N \l_@@_tmpg_tl
10242 \tl_new:N \l_@@_redraws_tl
10243 \tl_new:N \l_@@_clip_width_tl
10244 \tl_new:N \l_@@_name_tl
10245 \tl_new:N \l_@@_node_tl
10246 \tl_new:N \l_@@_aux_tl
10247 \tl_new:N \l_@@_auxa_tl
10248 \tl_new:N \l_@@_prefix_tl
10249
10250 \seq_new:N \l_@@_segments_seq
10251
10252 \int_new:N \l_@@_tmpa_int
10253 \int_new:N \l_@@_strands_int
10254 \int_new:N \g_@@_intersections_int
10255 \int_new:N \g_@@_filaments_int
10256 \int_new:N \l_@@_component_start_int
10257
10258 \fp_new:N \l_@@_tmpa_fp
10259 \fp_new:N \l_@@_tmpb_fp
10260
10261 \dim_new:N \l_@@_tmpa_dim
10262 \dim_new:N \l_@@_tmpb_dim
10263 \dim_new:N \l_@@_tolerance_dim
10264 \dim_new:N \l_@@_redraw_tolerance_dim
10265 \dim_new:N \l_@@_clip_bg_radius_dim
10266 \dim_new:N \l_@@_clip_draw_radius_dim
10267
10268 \bool_new:N \l_@@_draft_bool
10269 \bool_new:N \l_@@_ignore_ends_bool
10270 \bool_new:N \l_@@_self_intersections_bool
10271 \bool_new:N \l_@@_splits_bool
10272 \bool_new:N \l_@@_super_draft_bool
10273
10274 \bool_new:N \l_@@_prepend_prev_bool
10275 \bool_new:N \l_@@_append_next_bool
10276 \bool_new:N \l_@@_skip_bool
10277 \bool_new:N \l_@@_save_bool
10278 \bool_new:N \l_@@_debugging_bool
10279
10280 \seq_new:N \g_@@_nodes_seq
10281
10282 \bool_set_true:N \l_@@_ignore_ends_bool
10283 % \end{macrocode}
10284 %
10285 % Configuration is via TikZ keys and styles.
10286 % \begin{macrocode}
10287 \tikzset{
10288 spath/prefix/knot/.style={
10289 spath/set~ prefix=knot strand,
10290 },
10291 spath/suffix/knot/.style={
10292 spath/set~ suffix={},
10293 },
10294 knot/.code={
10295 \tl_if_eq:nnTF {#1} {none}
10296 {
10297 \tikz@addmode{\tikz@mode@doublefalse}
10298 }
10299 {
10300 \tikz@addmode{\tikz@mode@doubletrue}
10301 \tl_if_eq:nnTF {\pgfkeysnovalue} {#1}
10302 {
10303 \tikz@addoption{\pgfsetinnerstrokecolor{.}}
10304 }
10305 {
10306 \pgfsetinnerstrokecolor{#1}
10307 }
10308 \tikz@addoption{
10309 \pgfsetstrokecolor{knotbg}
10310 }
10311 \tl_set:Nn \tikz@double@setup{
10312 \pgfsetinnerlinewidth{\pgflinewidth}
10313 \pgfsetlinewidth{\dim_eval:n {\tl_use:N \l_@@_gap_tl \pgflinewidth}}
10314 }
10315 }
10316 },
10317 knot~ gap/.store~ in=\l_@@_gap_tl,
10318 knot~ gap=3,
10319 knot~ diagram/.is~family,
10320 knot~ diagram/.unknown/.code={
10321 \tl_set_eq:NN \l_@@_tmpa_tl \pgfkeyscurrentname
10322 \pgfkeysalso{
10323 /tikz/\l_@@_tmpa_tl=#1
10324 }
10325 },
10326 background~ colour/.code={%
10327 \colorlet{knotbg}{#1}%
10328 },
10329 background~ color/.code={%
10330 \colorlet{knotbg}{#1}%
10331 },
10332 background~ colour=white,
10333 knot~ diagram,
10334 name/.store~ in=\l_@@_name_tl,
10335 name={knot},
10336 save~ intersections/.is~ choice,
10337 save~ intersections/.default=true,
10338 save~ intersections/true/.code={
10339 \bool_set_true:N \l_@@_save_bool
10340 },
10341 save~ intersections/false/.code={
10342 \bool_set_false:N \l_@@_save_bool
10343 },
10344 every~ strand/.style={draw},
10345 ignore~ endpoint~ intersections/.code={
10346 \tl_if_eq:nnTF {#1} {true}
10347 {
10348 \bool_set_true:N \l_@@_ignore_ends_bool
10349 }
10350 {
10351 \bool_set_false:N \l_@@_ignore_ends_bool
10352 }
10353 },
10354 ignore~ endpoint~ intersections/.default=true,
10355 consider~ self~ intersections/.is~choice,
10356 consider~ self~ intersections/true/.code={
10357 \bool_set_true:N \l_@@_self_intersections_bool
10358 \bool_set_true:N \l_@@_splits_bool
10359 },
10360 consider~ self~ intersections/false/.code={
10361 \bool_set_false:N \l_@@_self_intersections_bool
10362 \bool_set_false:N \l_@@_splits_bool
10363 },
10364 consider~ self~ intersections/no~ splits/.code={
10365 \bool_set_true:N \l_@@_self_intersections_bool
10366 \bool_set_false:N \l_@@_splits_bool
10367 },
10368 consider~ self~ intersections/.default={true},
10369 clip~ radius/.code={
10370 \dim_set:Nn \l_@@_clip_bg_radius_dim {#1}
10371 \dim_set:Nn \l_@@_clip_draw_radius_dim {#1+2pt}
10372 },
10373 clip~ draw~ radius/.code={
10374 \dim_set:Nn \l_@@_clip_draw_radius_dim {#1}
10375 },
10376 clip~ background~ radius/.code={
10377 \dim_set:Nn \l_@@_clip_bg_radius_dim {#1}
10378 },
10379 clip~ radius=10pt,
10380 end~ tolerance/.code={
10381 \dim_set:Nn \l_@@_tolerance_dim {#1}
10382 },
10383 end~ tolerance=14pt,
10384 clip/.style={
10385 clip
10386 },
10387 background~ clip/.style={
10388 clip
10389 },
10390 clip~ width/.code={
10391 \tl_set:Nn \l_@@_clip_width_tl {#1}
10392 },
10393 clip~ width=3,
10394 flip~ crossing/.code={%
10395 \tl_clear_new:c {l_@@_crossing_#1}
10396 \tl_set:cn {l_@@_crossing_#1} {x}
10397 },
10398 ignore~ crossing/.code={%
10399 \tl_clear_new:c {l_@@_ignore_crossing_#1}
10400 \tl_set:cn {l_@@_ignore_crossing_#1} {x}
10401 },
10402 draft~ mode/.is~ choice,
10403 draft~ mode/off/.code={%
10404 \bool_set_false:N \l_@@_draft_bool
10405 \bool_set_false:N \l_@@_super_draft_bool
10406 },
10407 draft~ mode/crossings/.code={%
10408 \bool_set_true:N \l_@@_draft_bool
10409 \bool_set_false:N \l_@@_super_draft_bool
10410 },
10411 draft~ mode/strands/.code={%
10412 \bool_set_true:N \l_@@_draft_bool
10413 \bool_set_true:N \l_@@_super_draft_bool
10414 },
10415 debug/.is~ choice,
10416 debug/true/.code={
10417 \bool_set_true:N \l_@@_debugging_bool
10418 },
10419 debug/false/.code={
10420 \bool_set_false:N \l_@@_debugging_bool
10421 },
10422 debug/.default=true,
10423 draft/.is~ family,
10424 draft,
10425 crossing~ label/.style={
10426 overlay,
10427 fill=white,
10428 fill~ opacity=.5,
10429 text~ opacity=1,
10430 text=blue,
10431 pin~ edge={blue,<-}
10432 },
10433 strand~ label/.style={
10434 overlay,
10435 circle,
10436 draw=purple,
10437 fill=white,
10438 fill~ opacity=.5,
10439 text~ opacity=1,
10440 text=purple,
10441 inner~ sep=0pt
10442 },
10443 }
10444 % \end{macrocode}
10445 %
10446 % \begin{macro}[internal]{\knot_debug:n}
10447 % Debugging
10448 % \begin{macrocode}
10449 \cs_new_nopar:Npn \knot_debug:n #1
10450 {
10451 \bool_if:NT \l_@@_debugging_bool
10452 {
10453 \iow_term:n {===Knot~ debug: #1===}
10454 }
10455 }
10456
10457 \cs_new_nopar:Npn \knot_show_strand:n #1
10458 {
10459 \bool_if:NT \l_@@_debugging_bool
10460 {
10461 \iow_term:n {===Knot~ debug: #1===}
10462 \spath_show:v {knot #1}
10463 }
10464 }
10465
10466 \cs_generate_variant:Nn \knot_debug:n {x}
10467 % \end{macrocode}
10468 % \end{macro}
10469 %
10470 % Wrapper around \Verb+\tikzset+ for applying keys from a token list, checking for if the given token list exists.
10471 % \begin{macrocode}
10472 \cs_new_nopar:Npn \knot_apply_style:N #1
10473 {
10474 \knot_debug:n {knot~ apply~ style}
10475 \tl_if_exist:NT #1 {
10476 \exp_args:NV \tikzset #1
10477 }
10478 }
10479 \cs_generate_variant:Nn \knot_apply_style:N {c}
10480 % \end{macrocode}
10481 %
10482 %\begin{macro}[internal]{\flipcrossings}
10483 % The user can specify a comma separated list of crossings to flip.
10484 % \begin{macrocode}
10485 \NewDocumentCommand \flipcrossings {m}
10486 {
10487 \tikzset{knot~ diagram/flip~ crossing/.list={#1}}%
10488 }
10489 % \end{macrocode}
10490 % \end{macro}
10491 %
10492 % \begin{macro}[internal]{\strand}
10493 % This is how the user specifies a strand of the knot.
10494 % \begin{macrocode}
10495 \NewDocumentCommand \strand { O{} }
10496 {
10497 \int_incr:N \l_@@_strands_int
10498 \tl_clear_new:c {l_@@_options_strand \int_use:N \l_@@_strands_int}
10499 \tl_set:cn {l_@@_options_strand \int_use:N \l_@@_strands_int} {#1}
10500 \path[#1,spath/set~ name=knot,spath/save=\int_use:N \l_@@_strands_int]
10501 }
10502 % \end{macrocode}
10503 % \end{macro}
10504 %
10505 % \begin{macro}[internal]{knot}
10506 % This is the wrapper environment that calls the knot generation code.
10507 % \begin{macrocode}
10508 \NewDocumentEnvironment{knot} { O{} }
10509 {
10510 \knot_initialise:n {#1}
10511 }
10512 {
10513 \knot_render:
10514 }
10515 % \end{macrocode}
10516 % \end{macro}
10517 %
10518 % \begin{macro}[internal]{\knot_initialise:n}
10519 % Set up some stuff before loading in the strands.
10520 % \begin{macrocode}
10521 \cs_new_protected_nopar:Npn \knot_initialise:n #1
10522 {
10523 \knot_debug:n {knot~ initialise}
10524 \tikzset{knot~ diagram/.cd,every~ knot~ diagram/.try,#1}
10525 \int_zero:N \l_@@_strands_int
10526 \tl_clear:N \l_@@_redraws_tl
10527 \seq_gclear:N \g_@@_nodes_seq
10528 }
10529 % \end{macrocode}
10530 % \end{macro}
10531 %
10532 % \begin{macro}[internal]{\knot_render:}
10533 % This is the code that starts the work of rendering the knot.
10534 % \begin{macrocode}
10535 \cs_new_protected_nopar:Npn \knot_render:
10536 {
10537 \knot_debug:n {knot~ render}
10538 % \end{macrocode}
10539 % Start a scope and reset the transformation (since all transformations have already been taken into account when defining the strands).
10540 % \begin{macrocode}
10541 \pgfscope
10542 \pgftransformreset
10543 % \end{macrocode}
10544 % Set the dimension for deciding when to include neighbouring strands
10545 % \begin{macrocode}
10546 \dim_set:Nn \l_@@_redraw_tolerance_dim {\fp_to_dim:n
10547 {
10548 sqrt(2) * max(\l_@@_clip_bg_radius_dim, \l_@@_clip_draw_radius_dim)
10549 }
10550 }
10551 % \end{macrocode}
10552 % Loop through the strands drawing each one for the first time.
10553 % \begin{macrocode}
10554 \int_step_function:nnnN {1} {1} {\l_@@_strands_int} \knot_draw_strand:n
10555 % \end{macrocode}
10556 % In super draft mode we don't do anything else.
10557 % \begin{macrocode}
10558 \bool_if:NF \l_@@_super_draft_bool
10559 {
10560 % \end{macrocode}
10561 % 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.
10562 % \begin{macrocode}
10563 \int_step_function:nnnN {1} {1} {\l_@@_strands_int} \knot_draw_labels:n
10564 % \end{macrocode}
10565 % If we're considering self intersections we need to split the strands into filaments.
10566 % \begin{macrocode}
10567 \bool_if:NTF \l_@@_self_intersections_bool
10568 {
10569 \knot_split_strands:
10570 \int_set_eq:NN \l_@@_tmpa_int \g_@@_filaments_int
10571 \tl_set:Nn \l_@@_prefix_tl {filament}
10572 }
10573 {
10574 \int_set_eq:NN \l_@@_tmpa_int \l_@@_strands_int
10575 \tl_set:Nn \l_@@_prefix_tl {strand}
10576 }
10577 % \end{macrocode}
10578 % Initialise the intersection count.
10579 % \begin{macrocode}
10580 \int_gzero:N \g_@@_intersections_int
10581 % \end{macrocode}
10582 % If in draft mode we label the intersections, otherwise we just stick a coordinate at each one.
10583 % \begin{macrocode}
10584 \tl_clear:N \l_@@_node_tl
10585 \bool_if:NT \l_@@_draft_bool
10586 {
10587 \tl_set:Nn \l_@@_node_tl {
10588 \exp_not:N \node[coordinate,
10589 pin={[
10590 node~ contents={\int_use:N \g_@@_intersections_int},
10591 knot~ diagram/draft/crossing~ label,
10592 knot~ diagram/draft/crossing~
10593 \int_use:N \g_@@_intersections_int \c_space_tl label/.try
10594 ]
10595 }]
10596 }
10597 }
10598 % \end{macrocode}
10599 % This double loop steps through the pieces (strands or filaments) and computes the intersections and does stuff with those.
10600 % \begin{macrocode}
10601 \int_step_variable:nnnNn {1} {1} {\l_@@_tmpa_int - 1} \l_@@_tmpa_tl
10602 {
10603 \int_step_variable:nnnNn
10604 {\tl_use:N \l_@@_tmpa_tl + 1}
10605 {1}
10606 {\l_@@_tmpa_int} \l_@@_tmpb_tl
10607 {
10608 \knot_intersections:VV \l_@@_tmpa_tl \l_@@_tmpb_tl
10609 }
10610 }
10611 % \end{macrocode}
10612 % If any redraws were requested, do them here.
10613 % \begin{macrocode}
10614 \tl_use:N \l_@@_redraws_tl
10615 % \end{macrocode}
10616 % Draw the crossing nodes
10617 % \begin{macrocode}
10618 \seq_use:Nn \g_@@_nodes_seq {}
10619 }
10620 % \end{macrocode}
10621 % Close the scope
10622 % \begin{macrocode}
10623 \endpgfscope
10624 \knot_debug:x {knot~rendered,
10625 ~found~\int_use:N \g_@@_intersections_int \c_space_tl~intersections}
10626 }
10627 % \end{macrocode}
10628 % \end{macro}
10629 %
10630 % \begin{macro}[internal]{\knot_draw_strand:n}
10631 % This renders a strand using the options originally specified.
10632 % \begin{macrocode}
10633 \cs_new_protected_nopar:Npn \knot_draw_strand:n #1
10634 {
10635 \knot_debug:n {knot~ draw~ strand~ #1}
10636 \pgfscope
10637 \group_begin:
10638 \spath_bake_round:c {knot strand #1}
10639 \tl_set:Nn \l_@@_tmpa_tl {knot~ diagram/every~ strand/.try,}
10640 \tl_put_right:Nv \l_@@_tmpa_tl {l_@@_options_strand #1}
10641 \tl_put_right:Nn \l_@@_tmpa_tl
10642 {
10643 ,
10644 knot~ diagram/only~ when~ rendering/.try,
10645 only~ when~ rendering/.try,
10646 }
10647 \knot_show_strand:n {strand #1}
10648 \spath_tikz_path:Vv \l_@@_tmpa_tl {knot strand #1}
10649 \group_end:
10650 \endpgfscope
10651 }
10652 \cs_generate_variant:Nn \tl_put_right:Nn {Nv}
10653 % \end{macrocode}
10654 % \end{macro}
10655 %
10656 % \begin{macro}[internal]{\knot_draw_labels:n}
10657 % Draw a label at each end of each strand, if in draft mode.
10658 % Also, if requested, split potentially self intersecting Bezier curves.
10659 % \begin{macrocode}
10660 \cs_new_protected_nopar:Npn \knot_draw_labels:n #1
10661 {
10662 \knot_debug:n {knot~ draw~ labels}
10663 \bool_if:NT \l_@@_draft_bool
10664 {
10665 \spath_finalpoint:Nv \l_@@_tmpb_tl {knot strand #1}
10666 \dim_set:Nn \l_@@_tmpa_dim {\tl_item:Nn \l_@@_tmpb_tl {1}}
10667 \dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpb_tl {2}}
10668 \node[
10669 knot~ diagram/draft/strand~label
10670 ] at (\l_@@_tmpa_dim,\l_@@_tmpb_dim) {#1};
10671 \spath_initialpoint:Nv \l_@@_tmpb_tl {knot strand #1}
10672 \dim_set:Nn \l_@@_tmpa_dim {\tl_item:Nn \l_@@_tmpb_tl {1}}
10673 \dim_set:Nn \l_@@_tmpb_dim {\tl_item:Nn \l_@@_tmpb_tl {2}}
10674 \node[
10675 knot~ diagram/draft/strand~label
10676 ] at (\l_@@_tmpa_dim,\l_@@_tmpb_dim) {#1};
10677 }
10678 \bool_if:nT {
10679 \l_@@_self_intersections_bool
10680 &&
10681 \l_@@_splits_bool
10682 }
10683 {
10684 \tl_clear:N \l_@@_tmpa_tl
10685 \spath_remove_empty_components:c {knot strand #1}
10686 \spath_initialpoint:Nv \l_@@_tmpa_tl {knot strand #1}
10687 \tl_put_left:NV \l_@@_tmpa_tl \c_spath_moveto_tl
10688 \spath_segments_to_seq:Nv \l_@@_segments_seq {knot strand #1}
10689 \seq_map_function:NN \l_@@_segments_seq \knot_split_self_intersects:N
10690 \tl_set_eq:cN {knot strand #1} \l_@@_tmpa_tl
10691 }
10692 }
10693 % \end{macrocode}
10694 % \end{macro}
10695 %
10696 % \begin{macro}[internal]{\knot_split_self_intersects:N}
10697 % This is the macro that does the split.
10698 % Figuring out whether a Bezier cubic self intersects is apparently a difficult problem so we don't bother.
10699 % We compute a point such that if there is an intersection then it lies on either side of the point.
10700 % I don't recall where the formula came from!
10701 % \begin{macrocode}
10702 \cs_new_protected_nopar:Npn \knot_split_self_intersects:N #1
10703 {
10704 \knot_debug:n {knot~ split~ self~ intersects}
10705 \tl_set:Nx \l_@@_tmpc_tl {\tl_item:nn {#1} {4}}
10706 \token_case_meaning:NnF \l_@@_tmpc_tl
10707 {
10708 \c_spath_curvetoa_tl
10709 {
10710 \fp_set:Nn \l_@@_tmpa_fp
10711 {
10712 (\tl_item:nn {#1} {3} - 3 * \tl_item:nn {#1} {6}
10713 + 3 * \tl_item:nn {#1} {9} - \tl_item:nn {#1} {12})
10714 *
10715 (3 * \tl_item:nn {#1} {8} - 3 * \tl_item:nn {#1} {11})
10716 -
10717 (\tl_item:nn {#1} {2} - 3 * \tl_item:nn {#1} {5}
10718 + 3 * \tl_item:nn {#1} {8} - \tl_item:nn {#1} {11})
10719 *
10720 (3 * \tl_item:nn {#1} {9} - 3 * \tl_item:nn {#1} {12})
10721 }
10722 \fp_set:Nn \l_@@_tmpb_fp
10723 {
10724 (\tl_item:nn {#1} {2} - 3 * \tl_item:nn {#1} {5}
10725 + 3 * \tl_item:nn {#1} {8} - \tl_item:nn {#1} {11})
10726 *
10727 (3 * \tl_item:nn {#1} {6} - 6 * \tl_item:nn {#1} {9}
10728 + 3 * \tl_item:nn {#1} {12})
10729 -
10730 (\tl_item:nn {#1} {3} - 3 * \tl_item:nn {#1} {6}
10731 + 3 * \tl_item:nn {#1} {9} - \tl_item:nn {#1} {12})
10732 *
10733 (3 * \tl_item:nn {#1} {5} - 6 * \tl_item:nn {#1} {8}
10734 + 3 * \tl_item:nn {#1} {11})
10735 }
10736 \fp_compare:nTF
10737 {
10738 \l_@@_tmpb_fp != 0
10739 }
10740 {
10741 \fp_set:Nn \l_@@_tmpa_fp {.5 * \l_@@_tmpa_fp / \l_@@_tmpb_fp}
10742 \bool_if:nTF
10743 {
10744 \fp_compare_p:n {0 < \l_@@_tmpa_fp}
10745 &&
10746 \fp_compare_p:n {\l_@@_tmpa_fp < 1}
10747 }
10748 {
10749 \spath_split_curve:NNnV
10750 \l_@@_tmpc_tl
10751 \l_@@_tmpd_tl
10752 {#1}
10753 \l_@@_tmpa_fp
10754 \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
10755 \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
10756 \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
10757 \tl_set:Nx \l_@@_tmpd_tl {\tl_tail:N \l_@@_tmpd_tl}
10758 \tl_set:Nx \l_@@_tmpd_tl {\tl_tail:N \l_@@_tmpd_tl}
10759 \tl_set:Nx \l_@@_tmpd_tl {\tl_tail:N \l_@@_tmpd_tl}
10760 \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpc_tl
10761 \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpd_tl
10762 }
10763 {
10764 \tl_set:Nn \l_@@_tmpc_tl {#1}
10765 \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
10766 \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
10767 \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
10768 \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpc_tl
10769 }
10770 }
10771 {
10772 \tl_set:Nn \l_@@_tmpc_tl {#1}
10773 \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
10774 \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
10775 \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
10776 \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpc_tl
10777 }
10778 }
10779 \c_spath_lineto_tl
10780 {
10781 \tl_set:Nn \l_@@_tmpc_tl {#1}
10782 \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
10783 \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
10784 \tl_set:Nx \l_@@_tmpc_tl {\tl_tail:N \l_@@_tmpc_tl}
10785 \tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpc_tl
10786 }
10787 }
10788 {
10789 \tl_put_right:Nn \l_@@_tmpa_tl {#1}
10790 }
10791 }
10792 % \end{macrocode}
10793 % \end{macro}
10794 %
10795 % \begin{macro}[internal]{\knot_intersections:nn}
10796 % This computes the intersections of two pieces and steps through them.
10797 % \begin{macrocode}
10798 \cs_new_protected_nopar:Npn \knot_intersections:nn #1#2
10799 {
10800 \knot_debug:x {knot~ intersections~ between~
10801 \l_@@_prefix_tl \c_space_tl #1~ and~ #2}
10802 \group_begin:
10803 \tl_set_eq:NN \l_@@_tmpa_tl \l_@@_prefix_tl
10804 \tl_put_right:Nn \l_@@_tmpa_tl {#1}
10805 \tl_set_eq:NN \l_@@_tmpb_tl \l_@@_prefix_tl
10806 \tl_put_right:Nn \l_@@_tmpb_tl {#2}
10807 \tl_set_eq:Nc \l_@@_tmpc_tl {knot \tl_use:N \l_@@_tmpa_tl}
10808 \tl_set_eq:Nc \l_@@_tmpd_tl {knot \tl_use:N \l_@@_tmpb_tl}
10809
10810 \bool_if:nTF {
10811 \l_@@_save_bool
10812 &&
10813 \tl_if_exist_p:c {
10814 knot~ intersections~
10815 \tl_use:N \l_@@_name_tl -
10816 \tl_use:N \l_@@_tmpa_tl -
10817 \tl_use:N \l_@@_tmpb_tl
10818 }
10819 }
10820 {
10821 \tl_use:c
10822 {
10823 knot~ intersections~ \tl_use:N \l_@@_name_tl -
10824 \tl_use:N \l_@@_tmpa_tl -
10825 \tl_use:N \l_@@_tmpb_tl
10826 }
10827 }
10828 {
10829 \pgfintersectionofpaths{\pgfsetpath\l_@@_tmpc_tl}{\pgfsetpath\l_@@_tmpd_tl}
10830
10831 }
10832
10833 \knot_debug:x {found~\pgfintersectionsolutions\c_space_tl~ intersections}
10834 \int_compare:nT {\pgfintersectionsolutions > 0}
10835 {
10836 \int_step_function:nnnN
10837 {1}
10838 {1}
10839 {\pgfintersectionsolutions}
10840 \knot_do_intersection:n
10841 }
10842
10843 \knot_save_intersections:VV \l_@@_tmpa_tl \l_@@_tmpb_tl
10844 \group_end:
10845 }
10846 % \end{macrocode}
10847 % \end{macro}
10848 %
10849 % \begin{macro}[internal]{\knot_save_intersections:nn}
10850 % \begin{macrocode}
10851 \cs_new_protected_nopar:Npn \knot_save_intersections:nn #1#2
10852 {
10853 \knot_debug:n {knot~ save~ intersections}
10854 \bool_if:NT \l_@@_save_bool
10855 {
10856 \tl_clear:N \l_@@_aux_tl
10857 \tl_put_right:Nn \l_@@_aux_tl
10858 {
10859 \def\pgfintersectionsolutions
10860 }
10861 \tl_put_right:Nx \l_@@_aux_tl
10862 {
10863 {\int_eval:n {\pgfintersectionsolutions}}
10864 }
10865 \int_compare:nT {\pgfintersectionsolutions > 0}
10866 {
10867 \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions}
10868 {
10869 \pgfpointintersectionsolution{##1}
10870 \dim_set:Nn \l_@@_tmpa_dim {\pgf@x}
10871 \dim_set:Nn \l_@@_tmpb_dim {\pgf@y}
10872 \tl_put_right:Nn \l_@@_aux_tl
10873 {
10874 \expandafter\def\csname pgfpoint@intersect@solution@##1\endcsname
10875 }
10876 \tl_put_right:Nx \l_@@_aux_tl
10877 {
10878 {
10879 \exp_not:N \pgf@x
10880 =
10881 \dim_use:N \l_@@_tmpa_dim
10882 \exp_not:N \relax
10883 \exp_not:N \pgf@y
10884 =
10885 \dim_use:N \l_@@_tmpb_dim
10886 \exp_not:N \relax
10887 }
10888 }
10889 }
10890 \tl_set:Nn \l_@@_auxa_tl {\expandafter \gdef \csname knot~ intersections~}
10891 \tl_put_right:Nx \l_@@_auxa_tl {\tl_use:N \l_@@_name_tl - #1 - #2}
10892 \tl_put_right:Nn \l_@@_auxa_tl {\endcsname}
10893 \tl_put_right:Nx \l_@@_auxa_tl {{\tl_to_str:N \l_@@_aux_tl}}
10894 \protected@write\@auxout{}{\tl_to_str:N \l_@@_auxa_tl}
10895 }
10896 }
10897 }
10898 \cs_generate_variant:Nn \knot_save_intersections:nn {VV}
10899 % \end{macrocode}
10900 % \end{macro}
10901 %
10902 % \begin{macro}[internal]{\knot_do_intersection:n}
10903 % This handles a specific intersection.
10904 % \begin{macrocode}
10905 \cs_new_protected_nopar:Npn \knot_do_intersection:n #1
10906 {
10907 \knot_debug:n {knot~ do~ intersection~ #1}
10908 % \end{macrocode}
10909 % Get the intersection coordinates.
10910 % \begin{macrocode}
10911 \pgfpointintersectionsolution{#1}
10912 \dim_set:Nn \l_@@_tmpa_dim {\pgf@x}
10913 \dim_set:Nn \l_@@_tmpb_dim {\pgf@y}
10914 \knot_debug:x {intersection~at~
10915 (\dim_use:N \l_@@_tmpa_dim,\dim_use:N \l_@@_tmpb_dim)}
10916 % \end{macrocode}
10917 % If we're dealing with filaments, we can get false positives from the end points.
10918 % \begin{macrocode}
10919 \bool_set_false:N \l_@@_skip_bool
10920 \bool_if:NT \l_@@_self_intersections_bool
10921 {
10922 % \end{macrocode}
10923 % If one filament preceded the other, test for the intersection being at the relevant end point.
10924 % \begin{macrocode}
10925 \tl_set:Nn \l_@@_tmpc_tl {knot previous}
10926 \tl_put_right:NV \l_@@_tmpc_tl \l_@@_tmpa_tl
10927 \tl_set:Nv \l_@@_tmpc_tl \l_@@_tmpc_tl
10928 \tl_if_eq:NNT \l_@@_tmpc_tl \l_@@_tmpb_tl
10929 {
10930 \knot_test_endpoint:NVnT \l_@@_tolerance_dim \l_@@_tmpb_tl {final point}
10931 {
10932 \bool_set_true:N \l_@@_skip_bool
10933 }
10934 }
10935
10936 \tl_set:Nn \l_@@_tmpc_tl {knot previous}
10937 \tl_put_right:NV \l_@@_tmpc_tl \l_@@_tmpb_tl
10938 \tl_set:Nv \l_@@_tmpc_tl \l_@@_tmpc_tl
10939 \tl_if_eq:NNT \l_@@_tmpc_tl \l_@@_tmpa_tl
10940 {
10941 \knot_test_endpoint:NVnT \l_@@_tolerance_dim \l_@@_tmpa_tl {final point}
10942 {
10943 \bool_set_true:N \l_@@_skip_bool
10944 }
10945 }
10946 }
10947 % \end{macrocode}
10948 % The user can also say that end points of filaments (or strands) should simply be ignored anyway.
10949 % \begin{macrocode}
10950 \bool_if:NT \l_@@_ignore_ends_bool
10951 {
10952 \knot_test_endpoint:NVnT \l_@@_tolerance_dim \l_@@_tmpa_tl {initial point}
10953 {
10954 \bool_set_true:N \l_@@_skip_bool
10955 }
10956 \knot_test_endpoint:NVnT \l_@@_tolerance_dim \l_@@_tmpa_tl {final point}
10957 {
10958 \bool_set_true:N \l_@@_skip_bool
10959 }
10960 \knot_test_endpoint:NVnT \l_@@_tolerance_dim \l_@@_tmpb_tl {initial point}
10961 {
10962 \bool_set_true:N \l_@@_skip_bool
10963 }
10964 \knot_test_endpoint:NVnT \l_@@_tolerance_dim \l_@@_tmpb_tl {final point}
10965 {
10966 \bool_set_true:N \l_@@_skip_bool
10967 }
10968 }
10969 % \end{macrocode}
10970 % Assuming that we passed all the above tests, we render the crossing.
10971 % \begin{macrocode}
10972 \bool_if:NF \l_@@_skip_bool
10973 {
10974
10975 \int_gincr:N \g_@@_intersections_int
10976 \knot_debug:x {Processing~intersection~\int_use:N \g_@@_intersections_int}
10977 % \end{macrocode}
10978 % This is the intersection test.
10979 % If the intersection finder finds too many, it might be useful to ignore some.
10980 % \begin{macrocode}
10981 \bool_if:nF
10982 {
10983 \tl_if_exist_p:c {l_@@_ignore_crossing_ \int_use:N
10984 \g_@@_intersections_int}
10985 &&
10986 ! \tl_if_empty_p:c {l_@@_ignore_crossing_ \int_use:N
10987 \g_@@_intersections_int}
10988 }
10989 {
10990 % \end{macrocode}
10991 % This is the flip test.
10992 % We only render one of the paths.
10993 % The ``flip'' swaps which one we render.
10994 % \begin{macrocode}
10995 \bool_if:nTF
10996 {
10997 \tl_if_exist_p:c {l_@@_crossing_ \int_use:N
10998 \g_@@_intersections_int}
10999 &&
11000 ! \tl_if_empty_p:c {l_@@_crossing_ \int_use:N
11001 \g_@@_intersections_int}
11002 }
11003 {
11004 \tl_set_eq:NN \l_@@_tmpg_tl \l_@@_tmpb_tl
11005 }
11006 {
11007 \tl_set_eq:NN \l_@@_tmpg_tl \l_@@_tmpa_tl
11008 }
11009 % \end{macrocode}
11010 % 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.
11011 % \begin{macrocode}
11012 \bool_if:NT \l_@@_self_intersections_bool
11013 {
11014 \knot_test_endpoint:NVnT
11015 \l_@@_redraw_tolerance_dim \l_@@_tmpg_tl {initial point}
11016 {
11017 \bool_set_true:N \l_@@_prepend_prev_bool
11018 }
11019 {
11020 \bool_set_false:N \l_@@_prepend_prev_bool
11021 }
11022 \knot_test_endpoint:NVnT
11023 \l_@@_redraw_tolerance_dim \l_@@_tmpg_tl {final point}
11024 {
11025 \bool_set_true:N \l_@@_append_next_bool
11026 }
11027 {
11028 \bool_set_false:N \l_@@_append_next_bool
11029 }
11030 % \end{macrocode}
11031 % If either of those tests succeeded, do the appending or prepending.
11032 % \begin{macrocode}
11033 \bool_if:nT
11034 {
11035 \l_@@_prepend_prev_bool || \l_@@_append_next_bool
11036 }
11037 {
11038 \tl_clear_new:c {knot \tl_use:N \l_@@_prefix_tl -1}
11039 \tl_set_eq:cc
11040 {knot \tl_use:N \l_@@_prefix_tl -1}
11041 {knot \tl_use:N \l_@@_tmpg_tl}
11042
11043 \tl_clear_new:c {l_@@_options_ \tl_use:N \l_@@_prefix_tl -1}
11044 \tl_set_eq:cc
11045 {l_@@_options_ \tl_use:N \l_@@_prefix_tl -1}
11046 {l_@@_options_ \tl_use:N \l_@@_tmpg_tl}
11047
11048 \bool_if:nT
11049 {
11050 \l_@@_prepend_prev_bool
11051 &&
11052 \tl_if_exist_p:c {knot previous \tl_use:N \l_@@_tmpg_tl}
11053 &&
11054 !\tl_if_empty_p:c {knot previous \tl_use:N \l_@@_tmpg_tl}
11055 }
11056 {
11057 \knot_debug:x {Prepending~
11058 \tl_use:c {knot previous \tl_use:N \l_@@_tmpg_tl}}
11059 \spath_prepend_no_move:cv
11060 {knot \tl_use:N \l_@@_prefix_tl -1}
11061 {knot \tl_use:c {knot previous \tl_use:N \l_@@_tmpg_tl}}
11062 % \end{macrocode}
11063 % If we split potentially self intersecting curves, we test to see if we should prepend yet another segment.
11064 % \begin{macrocode}
11065 \bool_if:nT
11066 {
11067 \l_@@_splits_bool
11068 &&
11069 \tl_if_exist_p:c {knot previous
11070 \tl_use:c {knot previous \tl_use:N \l_@@_tmpg_tl}
11071 }
11072 &&
11073 !\tl_if_empty_p:c {knot previous
11074 \tl_use:c {knot previous \tl_use:N \l_@@_tmpg_tl}
11075 }
11076 }
11077 {
11078 \knot_test_endpoint:NvnT
11079 \l_@@_redraw_tolerance_dim
11080 {knot previous \tl_use:N \l_@@_tmpg_tl}
11081 {initial point}
11082 {
11083 \knot_debug:x {Prepending~
11084 \tl_use:c {knot previous
11085 \tl_use:c {knot previous \tl_use:N \l_@@_tmpg_tl}
11086 }
11087 }
11088 \spath_prepend_no_move:cv
11089 {knot \tl_use:N \l_@@_prefix_tl -1}
11090 {knot \tl_use:c
11091 {knot previous \tl_use:c
11092 {knot previous \tl_use:N \l_@@_tmpg_tl}
11093 }
11094 }
11095 \tl_set_eq:Nc \l_@@_tmpa_tl
11096 {knot \tl_use:N \l_@@_prefix_tl -1}
11097 }
11098 }
11099 }
11100
11101 % \end{macrocode}
11102 % Now the same for appending.
11103 % \begin{macrocode}
11104 \bool_if:nT
11105 {
11106 \l_@@_append_next_bool
11107 &&
11108 \tl_if_exist_p:c {knot next \tl_use:N \l_@@_tmpg_tl}
11109 &&
11110 !\tl_if_empty_p:c {knot next \tl_use:N \l_@@_tmpg_tl}
11111 }
11112 {
11113 \knot_debug:x {Appending~
11114 \tl_use:c {knot next \tl_use:N \l_@@_tmpg_tl}}
11115 \spath_append_no_move:cv
11116 {knot \tl_use:N \l_@@_prefix_tl -1}
11117 {knot \tl_use:c {knot next \tl_use:N \l_@@_tmpg_tl}}
11118 \bool_if:nT
11119 {
11120 \l_@@_splits_bool
11121 &&
11122 \tl_if_exist_p:c {knot next \tl_use:c { knot next \tl_use:N
11123 \l_@@_tmpg_tl}}
11124 &&
11125 !\tl_if_empty_p:c {knot next
11126 \tl_use:c { knot next \tl_use:N \l_@@_tmpg_tl}
11127 }
11128 }
11129 {
11130 \knot_debug:x {Testing~ whether~ to~ append~
11131 {knot next \tl_use:c { knot next \tl_use:N \l_@@_tmpg_tl}}
11132 }
11133 \knot_test_endpoint:NvnT
11134 \l_@@_redraw_tolerance_dim
11135 {knot next \tl_use:N \l_@@_tmpg_tl}
11136 {final point}
11137 {
11138 \knot_debug:x {Appending~
11139 {knot next \tl_use:c { knot next \tl_use:N \l_@@_tmpg_tl}}
11140 }
11141 \spath_append_no_move:cv
11142 {knot \tl_use:N \l_@@_prefix_tl -1}
11143 {knot \tl_use:c
11144 {knot next \tl_use:c
11145 {knot next \tl_use:N \l_@@_tmpg_tl}
11146 }
11147 }
11148 }
11149 }
11150 }
11151 \tl_set:Nn \l_@@_tmpg_tl {\tl_use:N \l_@@_prefix_tl -1}
11152 }
11153 }
11154 % \end{macrocode}
11155 % Now we render the crossing.
11156 % \begin{macrocode}
11157 \pgfscope
11158 \group_begin:
11159 \tikzset{
11160 knot~ diagram/every~ intersection/.try,
11161 every~ intersection/.try,
11162 knot~ diagram/intersection~ \int_use:N \g_@@_intersections_int/.try
11163 }
11164 \knot_draw_crossing:VVV \l_@@_tmpg_tl \l_@@_tmpa_dim \l_@@_tmpb_dim
11165 \coordinate
11166 (\l_@@_name_tl \c_space_tl \int_use:N \g_@@_intersections_int)
11167 at (\dim_use:N \l_@@_tmpa_dim, \dim_use:N \l_@@_tmpb_dim);
11168 \group_end:
11169 \endpgfscope
11170 % \end{macrocode}
11171 % This ends the boolean as to whether to consider the intersection at all
11172 % \begin{macrocode}
11173 }
11174 % \end{macrocode}
11175 % And possibly stick a coordinate with a label at the crossing.
11176 % \begin{macrocode}
11177 \tl_if_empty:NF \l_@@_node_tl
11178 {
11179 \seq_gpush:Nx
11180 \g_@@_nodes_seq
11181 {
11182 \l_@@_node_tl
11183 at
11184 (\dim_use:N \l_@@_tmpa_dim, \dim_use:N \l_@@_tmpb_dim) {};
11185 }
11186 }
11187 }
11188 }
11189
11190 \cs_generate_variant:Nn \knot_intersections:nn {VV}
11191 % \end{macrocode}
11192 % \end{macro}
11193 %
11194 % \begin{macro}[internal]{\knot_test_endpoint:N}
11195 % Test whether the point is near the intersection point.
11196 % \begin{macrocode}
11197 \prg_new_conditional:Npnn \knot_test_endpoint:NN #1#2 {p,T,F,TF}
11198 {
11199 \dim_compare:nTF
11200 {
11201 \dim_abs:n { \l_@@_tmpa_dim - \tl_item:Nn #2 {1}}
11202 +
11203 \dim_abs:n { \l_@@_tmpb_dim - \tl_item:Nn #2 {2}}
11204 <
11205 #1
11206 }
11207 {
11208 \prg_return_true:
11209 }
11210 {
11211 \prg_return_false:
11212 }
11213 }
11214 % \end{macrocode}
11215 % \end{macro}
11216 %
11217 % \begin{macro}[internal]{\knot_test_endpoint:nn}
11218 % Wrapper around the above.
11219 % \begin{macrocode}
11220 \prg_new_protected_conditional:Npnn \knot_test_endpoint:Nnn #1#2#3 {T,F,TF}
11221 {
11222 \use:c {spath_#3:Nv} \l_@@_tmpd_tl {knot #2}
11223 \knot_test_endpoint:NNTF #1 \l_@@_tmpd_tl
11224 {
11225 \prg_return_true:
11226 }
11227 {
11228 \prg_return_false:
11229 }
11230 }
11231
11232 \cs_generate_variant:Nn \knot_test_endpoint:NnnT {NVnT,NvnT}
11233 \cs_generate_variant:Nn \knot_test_endpoint:NnnF {NVnF,NvnF}
11234 \cs_generate_variant:Nn \knot_test_endpoint:NnnTF {NVnTF,NvnTF}
11235 % \end{macrocode}
11236 % \end{macro}
11237 %
11238 % \begin{macro}[internal]{\knot_draw_crossing:nnn}
11239 % This is the code that actually renders a crossing.
11240 % \begin{macrocode}
11241 \cs_new_protected_nopar:Npn \knot_draw_crossing:nnn #1#2#3
11242 {
11243 \knot_debug:n {knot~ draw~ crossing}
11244 \group_begin:
11245 \pgfscope
11246 \path[knot~ diagram/background~ clip] (#2, #3)
11247 circle[radius=\l_@@_clip_bg_radius_dim];
11248
11249 \tl_set:Nn \l_@@_tmpa_tl {knot~ diagram/every~ strand/.try,}
11250 \tl_if_exist:cT {l_@@_options_ #1}
11251 {
11252 \tl_put_right:Nv \l_@@_tmpa_tl {l_@@_options_ #1}
11253 }
11254 \tl_put_right:Nn \l_@@_tmpa_tl
11255 {
11256 ,knotbg
11257 ,line~ width= \tl_use:N \l_@@_clip_width_tl * \pgflinewidth
11258 }
11259 \spath_tikz_path:Vv \l_@@_tmpa_tl {knot #1}
11260
11261 \endpgfscope
11262
11263 \pgfscope
11264 \path[knot~ diagram/clip] (#2, #3)
11265 circle[radius=\l_@@_clip_draw_radius_dim];
11266
11267 \tl_set:Nn \l_@@_tmpa_tl {knot~ diagram/every~ strand/.try,}
11268 \tl_if_exist:cT {l_@@_options_ #1}
11269 {
11270 \tl_put_right:Nv \l_@@_tmpa_tl {l_@@_options_ #1}
11271 }
11272 \tl_put_right:Nn \l_@@_tmpa_tl
11273 {
11274 ,knot~ diagram/only~ when~ rendering/.try
11275 ,only~ when~ rendering/.try
11276 }
11277 \spath_tikz_path:Vv \l_@@_tmpa_tl {knot #1}
11278
11279 \endpgfscope
11280 \group_end:
11281 }
11282
11283 \cs_generate_variant:Nn \knot_draw_crossing:nnn {nVV, VVV}
11284
11285 \cs_new_protected_nopar:Npn \knot_draw_crossing:nn #1#2
11286 {
11287 \tikz@scan@one@point\pgfutil@firstofone #2 \relax
11288 \knot_draw_crossing:nVV {#1} \pgf@x \pgf@y
11289 }
11290 % \end{macrocode}
11291 % \end{macro}
11292 %
11293 % \begin{macro}[internal]{\knot_split_strands:}
11294 % This, and the following macros, are for splitting strands into filaments.
11295 % \begin{macrocode}
11296 \cs_new_protected_nopar:Npn \knot_split_strands:
11297 {
11298 \knot_debug:n {knot~ split~ strands}
11299 \int_gzero:N \g_@@_filaments_int
11300 \int_step_function:nnnN {1} {1} {\l_@@_strands_int} \knot_split_strand:n
11301 \int_step_function:nnnN {1} {1} {\g_@@_filaments_int} \knot_compute_nexts:n
11302 }
11303 % \end{macrocode}
11304 % \end{macro}
11305 %
11306 % \begin{macro}[internal]{\knot_compute_nexts:n}
11307 % Each filament needs to know its predecessor and successor.
11308 % We work out the predecessors as we go along, this fills in the successors.
11309 % \begin{macrocode}
11310 \cs_new_protected_nopar:Npn \knot_compute_nexts:n #1
11311 {
11312 \knot_debug:n {knot~ compute~ nexts}
11313 \tl_clear_new:c {knot next \tl_use:c {knot previous filament #1}}
11314 \tl_set:cn {knot next \tl_use:c {knot previous filament #1}} {filament #1}
11315 }
11316 % \end{macrocode}
11317 % \end{macro}
11318 %
11319 % \begin{macro}[internal]{\knot_split_strand:n}
11320 % Sets up the split for a single strand.
11321 % \begin{macrocode}
11322 \cs_new_protected_nopar:Npn \knot_split_strand:n #1
11323 {
11324 \knot_debug:n {knot~ split~ strand}
11325 \int_set_eq:NN \l_@@_component_start_int \g_@@_filaments_int
11326 \int_incr:N \l_@@_component_start_int
11327 \tl_set_eq:Nc \l_@@_tmpa_tl {l_@@_options_strand #1}
11328 \spath_remove_empty_components:c {knot strand #1}
11329 \spath_segments_to_seq:Nv \l_@@_segments_seq {knot strand #1}
11330 \seq_map_function:NN \l_@@_segments_seq \knot_save_filament:N
11331 }
11332 % \end{macrocode}
11333 % \end{macro}
11334 %
11335 % \begin{macro}[internal]{\knot_save_filament:N}
11336 % Saves a filament as a new \Verb+spath+ object.
11337 % \begin{macrocode}
11338 \cs_new_protected_nopar:Npn \knot_save_filament:N #1
11339 {
11340 \knot_debug:n {knot~ save~ filament}
11341 \tl_set:Nx \l_@@_tmpb_tl {\tl_item:nn {#1} {4}}
11342 \token_case_meaning:NnF \l_@@_tmpb_tl
11343 {
11344 \c_spath_moveto_tl
11345 {
11346 \int_compare:nT {\l_@@_component_start_int < \g_@@_filaments_int}
11347 {
11348 \int_set_eq:NN \l_@@_component_start_int \g_@@_filaments_int
11349 }
11350 }
11351 \c_spath_lineto_tl
11352 {
11353 \int_gincr:N \g_@@_filaments_int
11354 \tl_clear_new:c {knot filament \int_use:N \g_@@_filaments_int}
11355 \tl_set:cn {knot filament \int_use:N \g_@@_filaments_int} {#1}
11356
11357 \tl_clear_new:c {l_@@_options_filament \int_use:N \g_@@_filaments_int}
11358 \tl_set_eq:cN {l_@@_options_filament \int_use:N \g_@@_filaments_int}
11359 \l_@@_tmpa_tl
11360
11361 \tl_clear_new:c {knot previous filament \int_use:N \g_@@_filaments_int}
11362 \int_compare:nF {\l_@@_component_start_int == \g_@@_filaments_int}
11363 {
11364 \tl_set:cx {knot previous filament \int_use:N \g_@@_filaments_int}
11365 {filament \int_eval:n {\g_@@_filaments_int - 1}}
11366 }
11367 }
11368 \c_spath_curvetoa_tl
11369 {
11370 \int_gincr:N \g_@@_filaments_int
11371 \tl_clear_new:c {knot filament \int_use:N \g_@@_filaments_int}
11372 \tl_set:cn {knot filament \int_use:N \g_@@_filaments_int} {#1}
11373 \tl_clear_new:c {l_@@_options_filament \int_use:N \g_@@_filaments_int}
11374 \tl_set_eq:cN {l_@@_options_filament \int_use:N \g_@@_filaments_int}
11375 \l_@@_tmpa_tl
11376
11377 \tl_clear_new:c {knot previous filament \int_use:N \g_@@_filaments_int}
11378 \int_compare:nF {\l_@@_component_start_int == \g_@@_filaments_int}
11379 {
11380 \tl_set:cx
11381 {knot previous filament \int_use:N \g_@@_filaments_int}
11382 {filament \int_eval:n {\g_@@_filaments_int - 1}}
11383 }
11384 }
11385 \c_spath_closepath_tl
11386 {
11387 \int_gincr:N \g_@@_filaments_int
11388 \tl_clear_new:c {knot filament \int_use:N \g_@@_filaments_int}
11389 \tl_clear:N \l_@@_tmpa_tl
11390 \tl_put_right:Nx
11391 {
11392 \tl_item:nn {#1} {1}\tl_item:nn {#1} {2}\tl_item:nn {#1} {3}
11393 }
11394 \tl_put_right:NV \l_@@_tmpa_tl \c_spath_lineto_tl
11395 \tl_put_right:Nx {\tl_item:nn {#1} {5}\tl_item:nn {#1} {6}}
11396
11397 \tl_set:cV {knot filament \int_use:N \g_@@_filaments_int} \l_@@_tmpa_tl
11398 \tl_set_eq:cN {l_@@_options_filament \int_use:N \g_@@_filaments_int}
11399 \l_@@_tmpa_tl
11400 \tl_clear_new:c {knot previous filament \int_use:N \g_@@_filaments_int}
11401 \int_compare:nF {\l_@@_component_start_int == \g_@@_filaments_int}
11402 {
11403 \tl_set:cx
11404 {knot previous filament \int_use:N \g_@@_filaments_int}
11405 {filament \int_eval:n {\g_@@_filaments_int - 1}}
11406 }
11407 \tl_set:cx
11408 {knot previous filament \int_use:N \l_@@_component_start_int}
11409 {filament \int_use:N \g_@@_filaments_int}
11410 }
11411 }
11412 {
11413 }
11414 }
11415 % \end{macrocode}
11416 % \end{macro}
11417 %
11418 % \begin{macro}[internal]{\redraw}
11419 % The user can redraw segments of the strands at specific locations.
11420 % \begin{macrocode}
11421 \NewDocumentCommand \redraw { m m }
11422 {
11423 % \tikz@scan@one@point\pgfutil@firstofone #2 \relax
11424 \tl_put_right:Nn \l_@@_redraws_tl {\knot_draw_crossing:nn}
11425 \tl_put_right:Nx \l_@@_redraws_tl {
11426 {strand #1} {#2}% {\dim_use:N \pgf@x} {\dim_use:N \pgf@y}
11427 }
11428 }
11429 % \end{macrocode}
11430 % \end{macro}
11431 %
11432 % \begin{macrocode}
11433 \ExplSyntaxOff
11434 % \end{macrocode}
11435 %<@@=>
11436 %
11437 % \begin{macro}[internal]{\pgf@sh@@knotanchor}
11438 % Add the extra anchors for the knot crossing nodes.
11439 % \begin{macrocode}
11440 \def\pgf@sh@@knotanchor#1#2{%
11441 \anchor{#2 north west}{%
11442 \csname pgf@anchor@knot #1@north west\endcsname%
11443 \pgf@x=#2\pgf@x%
11444 \pgf@y=#2\pgf@y%
11445 }%
11446 \anchor{#2 north east}{%
11447 \csname pgf@anchor@knot #1@north east\endcsname%
11448 \pgf@x=#2\pgf@x%
11449 \pgf@y=#2\pgf@y%
11450 }%
11451 \anchor{#2 south west}{%
11452 \csname pgf@anchor@knot #1@south west\endcsname%
11453 \pgf@x=#2\pgf@x%
11454 \pgf@y=#2\pgf@y%
11455 }%
11456 \anchor{#2 south east}{%
11457 \csname pgf@anchor@knot #1@south east\endcsname%
11458 \pgf@x=#2\pgf@x%
11459 \pgf@y=#2\pgf@y%
11460 }%
11461 \anchor{#2 north}{%
11462 \csname pgf@anchor@knot #1@north\endcsname%
11463 \pgf@x=#2\pgf@x%
11464 \pgf@y=#2\pgf@y%
11465 }%
11466 \anchor{#2 east}{%
11467 \csname pgf@anchor@knot #1@east\endcsname%
11468 \pgf@x=#2\pgf@x%
11469 \pgf@y=#2\pgf@y%
11470 }%
11471 \anchor{#2 west}{%
11472 \csname pgf@anchor@knot #1@west\endcsname%
11473 \pgf@x=#2\pgf@x%
11474 \pgf@y=#2\pgf@y%
11475 }%
11476 \anchor{#2 south}{%
11477 \csname pgf@anchor@knot #1@south\endcsname%
11478 \pgf@x=#2\pgf@x%
11479 \pgf@y=#2\pgf@y%
11480 }%
11481 }
11482 % \end{macrocode}
11483 % \end{macro}
11484 %
11485 % \begin{macro}[internal]{knot crossing}
11486 % \begin{macrocode}
11487 \pgfdeclareshape{knot crossing}
11488 {
11489 \inheritsavedanchors[from=circle] % this is nearly a circle
11490 \inheritanchorborder[from=circle]
11491 \inheritanchor[from=circle]{north}
11492 \inheritanchor[from=circle]{north west}
11493 \inheritanchor[from=circle]{north east}
11494 \inheritanchor[from=circle]{center}
11495 \inheritanchor[from=circle]{west}
11496 \inheritanchor[from=circle]{east}
11497 \inheritanchor[from=circle]{mid}
11498 \inheritanchor[from=circle]{mid west}
11499 \inheritanchor[from=circle]{mid east}
11500 \inheritanchor[from=circle]{base}
11501 \inheritanchor[from=circle]{base west}
11502 \inheritanchor[from=circle]{base east}
11503 \inheritanchor[from=circle]{south}
11504 \inheritanchor[from=circle]{south west}
11505 \inheritanchor[from=circle]{south east}
11506 \inheritanchorborder[from=circle]
11507 \pgf@sh@@knotanchor{crossing}{2}
11508 \pgf@sh@@knotanchor{crossing}{3}
11509 \pgf@sh@@knotanchor{crossing}{4}
11510 \pgf@sh@@knotanchor{crossing}{8}
11511 \pgf@sh@@knotanchor{crossing}{16}
11512 \pgf@sh@@knotanchor{crossing}{32}
11513 \backgroundpath{
11514 \pgfutil@tempdima=\radius%
11515 \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%
11516 \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%
11517 \ifdim\pgf@xb<\pgf@yb%
11518 \advance\pgfutil@tempdima by-\pgf@yb%
11519 \else%
11520 \advance\pgfutil@tempdima by-\pgf@xb%
11521 \fi%
11522 }
11523 }
11524 % \end{macrocode}
11525 % \end{macro}
11526 %
11527 % \begin{macro}[internal]{knot over cross}
11528 % \begin{macrocode}
11529 \pgfdeclareshape{knot over cross}
11530 {
11531 \inheritsavedanchors[from=rectangle] % this is nearly a circle
11532 \inheritanchorborder[from=rectangle]
11533 \inheritanchor[from=rectangle]{north}
11534 \inheritanchor[from=rectangle]{north west}
11535 \inheritanchor[from=rectangle]{north east}
11536 \inheritanchor[from=rectangle]{center}
11537 \inheritanchor[from=rectangle]{west}
11538 \inheritanchor[from=rectangle]{east}
11539 \inheritanchor[from=rectangle]{mid}
11540 \inheritanchor[from=rectangle]{mid west}
11541 \inheritanchor[from=rectangle]{mid east}
11542 \inheritanchor[from=rectangle]{base}
11543 \inheritanchor[from=rectangle]{base west}
11544 \inheritanchor[from=rectangle]{base east}
11545 \inheritanchor[from=rectangle]{south}
11546 \inheritanchor[from=rectangle]{south west}
11547 \inheritanchor[from=rectangle]{south east}
11548 \inheritanchorborder[from=rectangle]
11549 \backgroundpath{
11550 \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
11551 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
11552 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
11553 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
11554 }
11555 \foregroundpath{
11556 % store lower right in xa/ya and upper right in xb/yb
11557 \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
11558 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
11559 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
11560 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
11561 }
11562 }
11563 % \end{macrocode}
11564 % \end{macro}
11565 %
11566 % \begin{macro}[internal]{knot under cross}
11567 % \begin{macrocode}
11568 \pgfdeclareshape{knot under cross}
11569 {
11570 \inheritsavedanchors[from=rectangle] % this is nearly a circle
11571 \inheritanchorborder[from=rectangle]
11572 \inheritanchor[from=rectangle]{north}
11573 \inheritanchor[from=rectangle]{north west}
11574 \inheritanchor[from=rectangle]{north east}
11575 \inheritanchor[from=rectangle]{center}
11576 \inheritanchor[from=rectangle]{west}
11577 \inheritanchor[from=rectangle]{east}
11578 \inheritanchor[from=rectangle]{mid}
11579 \inheritanchor[from=rectangle]{mid west}
11580 \inheritanchor[from=rectangle]{mid east}
11581 \inheritanchor[from=rectangle]{base}
11582 \inheritanchor[from=rectangle]{base west}
11583 \inheritanchor[from=rectangle]{base east}
11584 \inheritanchor[from=rectangle]{south}
11585 \inheritanchor[from=rectangle]{south west}
11586 \inheritanchor[from=rectangle]{south east}
11587 \inheritanchorborder[from=rectangle]
11588 \backgroundpath{
11589 \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
11590 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
11591 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
11592 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
11593 }
11594 \foregroundpath{
11595 % store lower right in xa/ya and upper right in xb/yb
11596 \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
11597 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
11598 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
11599 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
11600 }
11601 }
11602 % \end{macrocode}
11603 % \end{macro}
11604 %
11605 % \begin{macro}[internal]{knot vert}
11606 % \begin{macrocode}
11607 \pgfdeclareshape{knot vert}
11608 {
11609 \inheritsavedanchors[from=rectangle] % this is nearly a circle
11610 \inheritanchorborder[from=rectangle]
11611 \inheritanchor[from=rectangle]{north}
11612 \inheritanchor[from=rectangle]{north west}
11613 \inheritanchor[from=rectangle]{north east}
11614 \inheritanchor[from=rectangle]{center}
11615 \inheritanchor[from=rectangle]{west}
11616 \inheritanchor[from=rectangle]{east}
11617 \inheritanchor[from=rectangle]{mid}
11618 \inheritanchor[from=rectangle]{mid west}
11619 \inheritanchor[from=rectangle]{mid east}
11620 \inheritanchor[from=rectangle]{base}
11621 \inheritanchor[from=rectangle]{base west}
11622 \inheritanchor[from=rectangle]{base east}
11623 \inheritanchor[from=rectangle]{south}
11624 \inheritanchor[from=rectangle]{south west}
11625 \inheritanchor[from=rectangle]{south east}
11626 \inheritanchorborder[from=rectangle]
11627 \backgroundpath{
11628 % store lower right in xa/ya and upper right in xb/yb
11629 \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
11630 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
11631 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
11632 \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
11633 \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
11634 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
11635 }
11636 }
11637 % \end{macrocode}
11638 % \end{macro}
11639 %
11640 % \begin{macro}[internal]{knot horiz}
11641 % \begin{macrocode}
11642 \pgfdeclareshape{knot horiz}
11643 {
11644 \inheritsavedanchors[from=rectangle] % this is nearly a circle
11645 \inheritanchorborder[from=rectangle]
11646 \inheritanchor[from=rectangle]{north}
11647 \inheritanchor[from=rectangle]{north west}
11648 \inheritanchor[from=rectangle]{north east}
11649 \inheritanchor[from=rectangle]{center}
11650 \inheritanchor[from=rectangle]{west}
11651 \inheritanchor[from=rectangle]{east}
11652 \inheritanchor[from=rectangle]{mid}
11653 \inheritanchor[from=rectangle]{mid west}
11654 \inheritanchor[from=rectangle]{mid east}
11655 \inheritanchor[from=rectangle]{base}
11656 \inheritanchor[from=rectangle]{base west}
11657 \inheritanchor[from=rectangle]{base east}
11658 \inheritanchor[from=rectangle]{south}
11659 \inheritanchor[from=rectangle]{south west}
11660 \inheritanchor[from=rectangle]{south east}
11661 \inheritanchorborder[from=rectangle]
11662 \foregroundpath{
11663 % store lower right in xa/ya and upper right in xb/yb
11664 \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
11665 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
11666 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
11667 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
11668 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
11669 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
11670 }
11671 }
11672 % \end{macrocode}
11673 % \end{macro}
11674 %
11675 % \iffalse
11676 %</knots>
11677 % \fi
11678 %\Finale
11679 \endinput