Debian Codegraph @

texmf-dist/tex/latex/spath3/tikzlibraryknots.code.tex

raw
1 %%
2 %% This is file `tikzlibraryknots.code.tex',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% spath3_code.dtx (with options: `knots')
8 %% ----------------------------------------------------------------
9 %% spath3 --- Functions for manipulating PGF soft paths
10 %% E-mail: Andrew Stacey <[email protected]>
11 %% Released under the LaTeX Project Public License v1.3c or later
12 %% See http://www.latex-project.org/lppl.txt
13 %% ----------------------------------------------------------------
14 %%
15 %%
16 \RequirePackage{spath3}
17 \usetikzlibrary{intersections,spath3}
18
19 \ExplSyntaxOn
20
21 \tl_new:N \l__knot_tmpa_tl
22 \tl_new:N \l__knot_tmpb_tl
23 \tl_new:N \l__knot_tmpc_tl
24 \tl_new:N \l__knot_tmpd_tl
25 \tl_new:N \l__knot_tmpg_tl
26 \tl_new:N \l__knot_redraws_tl
27 \tl_new:N \l__knot_clip_width_tl
28 \tl_new:N \l__knot_name_tl
29 \tl_new:N \l__knot_node_tl
30 \tl_new:N \l__knot_aux_tl
31 \tl_new:N \l__knot_auxa_tl
32 \tl_new:N \l__knot_prefix_tl
33
34 \seq_new:N \l__knot_segments_seq
35
36 \int_new:N \l__knot_tmpa_int
37 \int_new:N \l__knot_strands_int
38 \int_new:N \g__knot_intersections_int
39 \int_new:N \g__knot_filaments_int
40 \int_new:N \l__knot_component_start_int
41
42 \fp_new:N \l__knot_tmpa_fp
43 \fp_new:N \l__knot_tmpb_fp
44
45 \dim_new:N \l__knot_tmpa_dim
46 \dim_new:N \l__knot_tmpb_dim
47 \dim_new:N \l__knot_tolerance_dim
48 \dim_new:N \l__knot_redraw_tolerance_dim
49 \dim_new:N \l__knot_clip_bg_radius_dim
50 \dim_new:N \l__knot_clip_draw_radius_dim
51
52 \bool_new:N \l__knot_draft_bool
53 \bool_new:N \l__knot_ignore_ends_bool
54 \bool_new:N \l__knot_self_intersections_bool
55 \bool_new:N \l__knot_splits_bool
56 \bool_new:N \l__knot_super_draft_bool
57
58 \bool_new:N \l__knot_prepend_prev_bool
59 \bool_new:N \l__knot_append_next_bool
60 \bool_new:N \l__knot_skip_bool
61 \bool_new:N \l__knot_save_bool
62 \bool_new:N \l__knot_debugging_bool
63
64 \seq_new:N \g__knot_nodes_seq
65
66 \bool_set_true:N \l__knot_ignore_ends_bool
67 \tikzset{
68 spath/prefix/knot/.style={
69 spath/set~ prefix=knot strand,
70 },
71 spath/suffix/knot/.style={
72 spath/set~ suffix={},
73 },
74 knot/.code={
75 \tl_if_eq:nnTF {#1} {none}
76 {
77 \tikz@addmode{\tikz@mode@doublefalse}
78 }
79 {
80 \tikz@addmode{\tikz@mode@doubletrue}
81 \tl_if_eq:nnTF {\pgfkeysnovalue} {#1}
82 {
83 \tikz@addoption{\pgfsetinnerstrokecolor{.}}
84 }
85 {
86 \pgfsetinnerstrokecolor{#1}
87 }
88 \tikz@addoption{
89 \pgfsetstrokecolor{knotbg}
90 }
91 \tl_set:Nn \tikz@double@setup{
92 \pgfsetinnerlinewidth{\pgflinewidth}
93 \pgfsetlinewidth{\dim_eval:n {\tl_use:N \l__knot_gap_tl \pgflinewidth}}
94 }
95 }
96 },
97 knot~ gap/.store~ in=\l__knot_gap_tl,
98 knot~ gap=3,
99 knot~ diagram/.is~family,
100 knot~ diagram/.unknown/.code={
101 \tl_set_eq:NN \l__knot_tmpa_tl \pgfkeyscurrentname
102 \pgfkeysalso{
103 /tikz/\l__knot_tmpa_tl=#1
104 }
105 },
106 background~ colour/.code={%
107 \colorlet{knotbg}{#1}%
108 },
109 background~ color/.code={%
110 \colorlet{knotbg}{#1}%
111 },
112 background~ colour=white,
113 knot~ diagram,
114 name/.store~ in=\l__knot_name_tl,
115 name={knot},
116 save~ intersections/.is~ choice,
117 save~ intersections/.default=true,
118 save~ intersections/true/.code={
119 \bool_set_true:N \l__knot_save_bool
120 },
121 save~ intersections/false/.code={
122 \bool_set_false:N \l__knot_save_bool
123 },
124 every~ strand/.style={draw},
125 ignore~ endpoint~ intersections/.code={
126 \tl_if_eq:nnTF {#1} {true}
127 {
128 \bool_set_true:N \l__knot_ignore_ends_bool
129 }
130 {
131 \bool_set_false:N \l__knot_ignore_ends_bool
132 }
133 },
134 ignore~ endpoint~ intersections/.default=true,
135 consider~ self~ intersections/.is~choice,
136 consider~ self~ intersections/true/.code={
137 \bool_set_true:N \l__knot_self_intersections_bool
138 \bool_set_true:N \l__knot_splits_bool
139 },
140 consider~ self~ intersections/false/.code={
141 \bool_set_false:N \l__knot_self_intersections_bool
142 \bool_set_false:N \l__knot_splits_bool
143 },
144 consider~ self~ intersections/no~ splits/.code={
145 \bool_set_true:N \l__knot_self_intersections_bool
146 \bool_set_false:N \l__knot_splits_bool
147 },
148 consider~ self~ intersections/.default={true},
149 clip~ radius/.code={
150 \dim_set:Nn \l__knot_clip_bg_radius_dim {#1}
151 \dim_set:Nn \l__knot_clip_draw_radius_dim {#1+2pt}
152 },
153 clip~ draw~ radius/.code={
154 \dim_set:Nn \l__knot_clip_draw_radius_dim {#1}
155 },
156 clip~ background~ radius/.code={
157 \dim_set:Nn \l__knot_clip_bg_radius_dim {#1}
158 },
159 clip~ radius=10pt,
160 end~ tolerance/.code={
161 \dim_set:Nn \l__knot_tolerance_dim {#1}
162 },
163 end~ tolerance=14pt,
164 clip/.style={
165 clip
166 },
167 background~ clip/.style={
168 clip
169 },
170 clip~ width/.code={
171 \tl_set:Nn \l__knot_clip_width_tl {#1}
172 },
173 clip~ width=3,
174 flip~ crossing/.code={%
175 \tl_clear_new:c {l__knot_crossing_#1}
176 \tl_set:cn {l__knot_crossing_#1} {x}
177 },
178 ignore~ crossing/.code={%
179 \tl_clear_new:c {l__knot_ignore_crossing_#1}
180 \tl_set:cn {l__knot_ignore_crossing_#1} {x}
181 },
182 draft~ mode/.is~ choice,
183 draft~ mode/off/.code={%
184 \bool_set_false:N \l__knot_draft_bool
185 \bool_set_false:N \l__knot_super_draft_bool
186 },
187 draft~ mode/crossings/.code={%
188 \bool_set_true:N \l__knot_draft_bool
189 \bool_set_false:N \l__knot_super_draft_bool
190 },
191 draft~ mode/strands/.code={%
192 \bool_set_true:N \l__knot_draft_bool
193 \bool_set_true:N \l__knot_super_draft_bool
194 },
195 debug/.is~ choice,
196 debug/true/.code={
197 \bool_set_true:N \l__knot_debugging_bool
198 },
199 debug/false/.code={
200 \bool_set_false:N \l__knot_debugging_bool
201 },
202 debug/.default=true,
203 draft/.is~ family,
204 draft,
205 crossing~ label/.style={
206 overlay,
207 fill=white,
208 fill~ opacity=.5,
209 text~ opacity=1,
210 text=blue,
211 pin~ edge={blue,<-}
212 },
213 strand~ label/.style={
214 overlay,
215 circle,
216 draw=purple,
217 fill=white,
218 fill~ opacity=.5,
219 text~ opacity=1,
220 text=purple,
221 inner~ sep=0pt
222 },
223 }
224 \cs_new_nopar:Npn \knot_debug:n #1
225 {
226 \bool_if:NT \l__knot_debugging_bool
227 {
228 \iow_term:n {===Knot~ debug: #1===}
229 }
230 }
231
232 \cs_new_nopar:Npn \knot_show_strand:n #1
233 {
234 \bool_if:NT \l__knot_debugging_bool
235 {
236 \iow_term:n {===Knot~ debug: #1===}
237 \spath_show:v {knot #1}
238 }
239 }
240
241 \cs_generate_variant:Nn \knot_debug:n {x}
242 \cs_new_nopar:Npn \knot_apply_style:N #1
243 {
244 \knot_debug:n {knot~ apply~ style}
245 \tl_if_exist:NT #1 {
246 \exp_args:NV \tikzset #1
247 }
248 }
249 \cs_generate_variant:Nn \knot_apply_style:N {c}
250 \NewDocumentCommand \flipcrossings {m}
251 {
252 \tikzset{knot~ diagram/flip~ crossing/.list={#1}}%
253 }
254 \NewDocumentCommand \strand { O{} }
255 {
256 \int_incr:N \l__knot_strands_int
257 \tl_clear_new:c {l__knot_options_strand \int_use:N \l__knot_strands_int}
258 \tl_set:cn {l__knot_options_strand \int_use:N \l__knot_strands_int} {#1}
259 \path[#1,spath/set~ name=knot,spath/save=\int_use:N \l__knot_strands_int]
260 }
261 \NewDocumentEnvironment{knot} { O{} }
262 {
263 \knot_initialise:n {#1}
264 }
265 {
266 \knot_render:
267 }
268 \cs_new_protected_nopar:Npn \knot_initialise:n #1
269 {
270 \knot_debug:n {knot~ initialise}
271 \tikzset{knot~ diagram/.cd,every~ knot~ diagram/.try,#1}
272 \int_zero:N \l__knot_strands_int
273 \tl_clear:N \l__knot_redraws_tl
274 \seq_gclear:N \g__knot_nodes_seq
275 }
276 \cs_new_protected_nopar:Npn \knot_render:
277 {
278 \knot_debug:n {knot~ render}
279 \pgfscope
280 \pgftransformreset
281 \dim_set:Nn \l__knot_redraw_tolerance_dim {\fp_to_dim:n
282 {
283 sqrt(2) * max(\l__knot_clip_bg_radius_dim, \l__knot_clip_draw_radius_dim)
284 }
285 }
286 \int_step_function:nnnN {1} {1} {\l__knot_strands_int} \knot_draw_strand:n
287 \bool_if:NF \l__knot_super_draft_bool
288 {
289 \int_step_function:nnnN {1} {1} {\l__knot_strands_int} \knot_draw_labels:n
290 \bool_if:NTF \l__knot_self_intersections_bool
291 {
292 \knot_split_strands:
293 \int_set_eq:NN \l__knot_tmpa_int \g__knot_filaments_int
294 \tl_set:Nn \l__knot_prefix_tl {filament}
295 }
296 {
297 \int_set_eq:NN \l__knot_tmpa_int \l__knot_strands_int
298 \tl_set:Nn \l__knot_prefix_tl {strand}
299 }
300 \int_gzero:N \g__knot_intersections_int
301 \tl_clear:N \l__knot_node_tl
302 \bool_if:NT \l__knot_draft_bool
303 {
304 \tl_set:Nn \l__knot_node_tl {
305 \exp_not:N \node[coordinate,
306 pin={[
307 node~ contents={\int_use:N \g__knot_intersections_int},
308 knot~ diagram/draft/crossing~ label,
309 knot~ diagram/draft/crossing~
310 \int_use:N \g__knot_intersections_int \c_space_tl label/.try
311 ]
312 }]
313 }
314 }
315 \int_step_variable:nnnNn {1} {1} {\l__knot_tmpa_int - 1} \l__knot_tmpa_tl
316 {
317 \int_step_variable:nnnNn
318 {\tl_use:N \l__knot_tmpa_tl + 1}
319 {1}
320 {\l__knot_tmpa_int} \l__knot_tmpb_tl
321 {
322 \knot_intersections:VV \l__knot_tmpa_tl \l__knot_tmpb_tl
323 }
324 }
325 \tl_use:N \l__knot_redraws_tl
326 \seq_use:Nn \g__knot_nodes_seq {}
327 }
328 \endpgfscope
329 \knot_debug:x {knot~rendered,
330 ~found~\int_use:N \g__knot_intersections_int \c_space_tl~intersections}
331 }
332 \cs_new_protected_nopar:Npn \knot_draw_strand:n #1
333 {
334 \knot_debug:n {knot~ draw~ strand~ #1}
335 \pgfscope
336 \group_begin:
337 \spath_bake_round:c {knot strand #1}
338 \tl_set:Nn \l__knot_tmpa_tl {knot~ diagram/every~ strand/.try,}
339 \tl_put_right:Nv \l__knot_tmpa_tl {l__knot_options_strand #1}
340 \tl_put_right:Nn \l__knot_tmpa_tl
341 {
342 ,
343 knot~ diagram/only~ when~ rendering/.try,
344 only~ when~ rendering/.try,
345 }
346 \knot_show_strand:n {strand #1}
347 \spath_tikz_path:Vv \l__knot_tmpa_tl {knot strand #1}
348 \group_end:
349 \endpgfscope
350 }
351 \cs_generate_variant:Nn \tl_put_right:Nn {Nv}
352 \cs_new_protected_nopar:Npn \knot_draw_labels:n #1
353 {
354 \knot_debug:n {knot~ draw~ labels}
355 \bool_if:NT \l__knot_draft_bool
356 {
357 \spath_finalpoint:Nv \l__knot_tmpb_tl {knot strand #1}
358 \dim_set:Nn \l__knot_tmpa_dim {\tl_item:Nn \l__knot_tmpb_tl {1}}
359 \dim_set:Nn \l__knot_tmpb_dim {\tl_item:Nn \l__knot_tmpb_tl {2}}
360 \node[
361 knot~ diagram/draft/strand~label
362 ] at (\l__knot_tmpa_dim,\l__knot_tmpb_dim) {#1};
363 \spath_initialpoint:Nv \l__knot_tmpb_tl {knot strand #1}
364 \dim_set:Nn \l__knot_tmpa_dim {\tl_item:Nn \l__knot_tmpb_tl {1}}
365 \dim_set:Nn \l__knot_tmpb_dim {\tl_item:Nn \l__knot_tmpb_tl {2}}
366 \node[
367 knot~ diagram/draft/strand~label
368 ] at (\l__knot_tmpa_dim,\l__knot_tmpb_dim) {#1};
369 }
370 \bool_if:nT {
371 \l__knot_self_intersections_bool
372 &&
373 \l__knot_splits_bool
374 }
375 {
376 \tl_clear:N \l__knot_tmpa_tl
377 \spath_remove_empty_components:c {knot strand #1}
378 \spath_initialpoint:Nv \l__knot_tmpa_tl {knot strand #1}
379 \tl_put_left:NV \l__knot_tmpa_tl \c_spath_moveto_tl
380 \spath_segments_to_seq:Nv \l__knot_segments_seq {knot strand #1}
381 \seq_map_function:NN \l__knot_segments_seq \knot_split_self_intersects:N
382 \tl_set_eq:cN {knot strand #1} \l__knot_tmpa_tl
383 }
384 }
385 \cs_new_protected_nopar:Npn \knot_split_self_intersects:N #1
386 {
387 \knot_debug:n {knot~ split~ self~ intersects}
388 \tl_set:Nx \l__knot_tmpc_tl {\tl_item:nn {#1} {4}}
389 \token_case_meaning:NnF \l__knot_tmpc_tl
390 {
391 \c_spath_curvetoa_tl
392 {
393 \fp_set:Nn \l__knot_tmpa_fp
394 {
395 (\tl_item:nn {#1} {3} - 3 * \tl_item:nn {#1} {6}
396 + 3 * \tl_item:nn {#1} {9} - \tl_item:nn {#1} {12})
397 *
398 (3 * \tl_item:nn {#1} {8} - 3 * \tl_item:nn {#1} {11})
399 -
400 (\tl_item:nn {#1} {2} - 3 * \tl_item:nn {#1} {5}
401 + 3 * \tl_item:nn {#1} {8} - \tl_item:nn {#1} {11})
402 *
403 (3 * \tl_item:nn {#1} {9} - 3 * \tl_item:nn {#1} {12})
404 }
405 \fp_set:Nn \l__knot_tmpb_fp
406 {
407 (\tl_item:nn {#1} {2} - 3 * \tl_item:nn {#1} {5}
408 + 3 * \tl_item:nn {#1} {8} - \tl_item:nn {#1} {11})
409 *
410 (3 * \tl_item:nn {#1} {6} - 6 * \tl_item:nn {#1} {9}
411 + 3 * \tl_item:nn {#1} {12})
412 -
413 (\tl_item:nn {#1} {3} - 3 * \tl_item:nn {#1} {6}
414 + 3 * \tl_item:nn {#1} {9} - \tl_item:nn {#1} {12})
415 *
416 (3 * \tl_item:nn {#1} {5} - 6 * \tl_item:nn {#1} {8}
417 + 3 * \tl_item:nn {#1} {11})
418 }
419 \fp_compare:nTF
420 {
421 \l__knot_tmpb_fp != 0
422 }
423 {
424 \fp_set:Nn \l__knot_tmpa_fp {.5 * \l__knot_tmpa_fp / \l__knot_tmpb_fp}
425 \bool_if:nTF
426 {
427 \fp_compare_p:n {0 < \l__knot_tmpa_fp}
428 &&
429 \fp_compare_p:n {\l__knot_tmpa_fp < 1}
430 }
431 {
432 \spath_split_curve:NNnV
433 \l__knot_tmpc_tl
434 \l__knot_tmpd_tl
435 {#1}
436 \l__knot_tmpa_fp
437 \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
438 \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
439 \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
440 \tl_set:Nx \l__knot_tmpd_tl {\tl_tail:N \l__knot_tmpd_tl}
441 \tl_set:Nx \l__knot_tmpd_tl {\tl_tail:N \l__knot_tmpd_tl}
442 \tl_set:Nx \l__knot_tmpd_tl {\tl_tail:N \l__knot_tmpd_tl}
443 \tl_put_right:NV \l__knot_tmpa_tl \l__knot_tmpc_tl
444 \tl_put_right:NV \l__knot_tmpa_tl \l__knot_tmpd_tl
445 }
446 {
447 \tl_set:Nn \l__knot_tmpc_tl {#1}
448 \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
449 \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
450 \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
451 \tl_put_right:NV \l__knot_tmpa_tl \l__knot_tmpc_tl
452 }
453 }
454 {
455 \tl_set:Nn \l__knot_tmpc_tl {#1}
456 \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
457 \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
458 \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
459 \tl_put_right:NV \l__knot_tmpa_tl \l__knot_tmpc_tl
460 }
461 }
462 \c_spath_lineto_tl
463 {
464 \tl_set:Nn \l__knot_tmpc_tl {#1}
465 \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
466 \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
467 \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl}
468 \tl_put_right:NV \l__knot_tmpa_tl \l__knot_tmpc_tl
469 }
470 }
471 {
472 \tl_put_right:Nn \l__knot_tmpa_tl {#1}
473 }
474 }
475 \cs_new_protected_nopar:Npn \knot_intersections:nn #1#2
476 {
477 \knot_debug:x {knot~ intersections~ between~
478 \l__knot_prefix_tl \c_space_tl #1~ and~ #2}
479 \group_begin:
480 \tl_set_eq:NN \l__knot_tmpa_tl \l__knot_prefix_tl
481 \tl_put_right:Nn \l__knot_tmpa_tl {#1}
482 \tl_set_eq:NN \l__knot_tmpb_tl \l__knot_prefix_tl
483 \tl_put_right:Nn \l__knot_tmpb_tl {#2}
484 \tl_set_eq:Nc \l__knot_tmpc_tl {knot \tl_use:N \l__knot_tmpa_tl}
485 \tl_set_eq:Nc \l__knot_tmpd_tl {knot \tl_use:N \l__knot_tmpb_tl}
486
487 \bool_if:nTF {
488 \l__knot_save_bool
489 &&
490 \tl_if_exist_p:c {
491 knot~ intersections~
492 \tl_use:N \l__knot_name_tl -
493 \tl_use:N \l__knot_tmpa_tl -
494 \tl_use:N \l__knot_tmpb_tl
495 }
496 }
497 {
498 \tl_use:c
499 {
500 knot~ intersections~ \tl_use:N \l__knot_name_tl -
501 \tl_use:N \l__knot_tmpa_tl -
502 \tl_use:N \l__knot_tmpb_tl
503 }
504 }
505 {
506 \pgfintersectionofpaths{\pgfsetpath\l__knot_tmpc_tl}{\pgfsetpath\l__knot_tmpd_tl}
507
508 }
509
510 \knot_debug:x {found~\pgfintersectionsolutions\c_space_tl~ intersections}
511 \int_compare:nT {\pgfintersectionsolutions > 0}
512 {
513 \int_step_function:nnnN
514 {1}
515 {1}
516 {\pgfintersectionsolutions}
517 \knot_do_intersection:n
518 }
519
520 \knot_save_intersections:VV \l__knot_tmpa_tl \l__knot_tmpb_tl
521 \group_end:
522 }
523 \cs_new_protected_nopar:Npn \knot_save_intersections:nn #1#2
524 {
525 \knot_debug:n {knot~ save~ intersections}
526 \bool_if:NT \l__knot_save_bool
527 {
528 \tl_clear:N \l__knot_aux_tl
529 \tl_put_right:Nn \l__knot_aux_tl
530 {
531 \def\pgfintersectionsolutions
532 }
533 \tl_put_right:Nx \l__knot_aux_tl
534 {
535 {\int_eval:n {\pgfintersectionsolutions}}
536 }
537 \int_compare:nT {\pgfintersectionsolutions > 0}
538 {
539 \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions}
540 {
541 \pgfpointintersectionsolution{##1}
542 \dim_set:Nn \l__knot_tmpa_dim {\pgf@x}
543 \dim_set:Nn \l__knot_tmpb_dim {\pgf@y}
544 \tl_put_right:Nn \l__knot_aux_tl
545 {
546 \expandafter\def\csname pgfpoint@intersect@solution@##1\endcsname
547 }
548 \tl_put_right:Nx \l__knot_aux_tl
549 {
550 {
551 \exp_not:N \pgf@x
552 =
553 \dim_use:N \l__knot_tmpa_dim
554 \exp_not:N \relax
555 \exp_not:N \pgf@y
556 =
557 \dim_use:N \l__knot_tmpb_dim
558 \exp_not:N \relax
559 }
560 }
561 }
562 \tl_set:Nn \l__knot_auxa_tl {\expandafter \gdef \csname knot~ intersections~}
563 \tl_put_right:Nx \l__knot_auxa_tl {\tl_use:N \l__knot_name_tl - #1 - #2}
564 \tl_put_right:Nn \l__knot_auxa_tl {\endcsname}
565 \tl_put_right:Nx \l__knot_auxa_tl {{\tl_to_str:N \l__knot_aux_tl}}
566 \protected@write\@auxout{}{\tl_to_str:N \l__knot_auxa_tl}
567 }
568 }
569 }
570 \cs_generate_variant:Nn \knot_save_intersections:nn {VV}
571 \cs_new_protected_nopar:Npn \knot_do_intersection:n #1
572 {
573 \knot_debug:n {knot~ do~ intersection~ #1}
574 \pgfpointintersectionsolution{#1}
575 \dim_set:Nn \l__knot_tmpa_dim {\pgf@x}
576 \dim_set:Nn \l__knot_tmpb_dim {\pgf@y}
577 \knot_debug:x {intersection~at~
578 (\dim_use:N \l__knot_tmpa_dim,\dim_use:N \l__knot_tmpb_dim)}
579 \bool_set_false:N \l__knot_skip_bool
580 \bool_if:NT \l__knot_self_intersections_bool
581 {
582 \tl_set:Nn \l__knot_tmpc_tl {knot previous}
583 \tl_put_right:NV \l__knot_tmpc_tl \l__knot_tmpa_tl
584 \tl_set:Nv \l__knot_tmpc_tl \l__knot_tmpc_tl
585 \tl_if_eq:NNT \l__knot_tmpc_tl \l__knot_tmpb_tl
586 {
587 \knot_test_endpoint:NVnT \l__knot_tolerance_dim \l__knot_tmpb_tl {final point}
588 {
589 \bool_set_true:N \l__knot_skip_bool
590 }
591 }
592
593 \tl_set:Nn \l__knot_tmpc_tl {knot previous}
594 \tl_put_right:NV \l__knot_tmpc_tl \l__knot_tmpb_tl
595 \tl_set:Nv \l__knot_tmpc_tl \l__knot_tmpc_tl
596 \tl_if_eq:NNT \l__knot_tmpc_tl \l__knot_tmpa_tl
597 {
598 \knot_test_endpoint:NVnT \l__knot_tolerance_dim \l__knot_tmpa_tl {final point}
599 {
600 \bool_set_true:N \l__knot_skip_bool
601 }
602 }
603 }
604 \bool_if:NT \l__knot_ignore_ends_bool
605 {
606 \knot_test_endpoint:NVnT \l__knot_tolerance_dim \l__knot_tmpa_tl {initial point}
607 {
608 \bool_set_true:N \l__knot_skip_bool
609 }
610 \knot_test_endpoint:NVnT \l__knot_tolerance_dim \l__knot_tmpa_tl {final point}
611 {
612 \bool_set_true:N \l__knot_skip_bool
613 }
614 \knot_test_endpoint:NVnT \l__knot_tolerance_dim \l__knot_tmpb_tl {initial point}
615 {
616 \bool_set_true:N \l__knot_skip_bool
617 }
618 \knot_test_endpoint:NVnT \l__knot_tolerance_dim \l__knot_tmpb_tl {final point}
619 {
620 \bool_set_true:N \l__knot_skip_bool
621 }
622 }
623 \bool_if:NF \l__knot_skip_bool
624 {
625
626 \int_gincr:N \g__knot_intersections_int
627 \knot_debug:x {Processing~intersection~\int_use:N \g__knot_intersections_int}
628 \bool_if:nF
629 {
630 \tl_if_exist_p:c {l__knot_ignore_crossing_ \int_use:N
631 \g__knot_intersections_int}
632 &&
633 ! \tl_if_empty_p:c {l__knot_ignore_crossing_ \int_use:N
634 \g__knot_intersections_int}
635 }
636 {
637 \bool_if:nTF
638 {
639 \tl_if_exist_p:c {l__knot_crossing_ \int_use:N
640 \g__knot_intersections_int}
641 &&
642 ! \tl_if_empty_p:c {l__knot_crossing_ \int_use:N
643 \g__knot_intersections_int}
644 }
645 {
646 \tl_set_eq:NN \l__knot_tmpg_tl \l__knot_tmpb_tl
647 }
648 {
649 \tl_set_eq:NN \l__knot_tmpg_tl \l__knot_tmpa_tl
650 }
651 \bool_if:NT \l__knot_self_intersections_bool
652 {
653 \knot_test_endpoint:NVnT
654 \l__knot_redraw_tolerance_dim \l__knot_tmpg_tl {initial point}
655 {
656 \bool_set_true:N \l__knot_prepend_prev_bool
657 }
658 {
659 \bool_set_false:N \l__knot_prepend_prev_bool
660 }
661 \knot_test_endpoint:NVnT
662 \l__knot_redraw_tolerance_dim \l__knot_tmpg_tl {final point}
663 {
664 \bool_set_true:N \l__knot_append_next_bool
665 }
666 {
667 \bool_set_false:N \l__knot_append_next_bool
668 }
669 \bool_if:nT
670 {
671 \l__knot_prepend_prev_bool || \l__knot_append_next_bool
672 }
673 {
674 \tl_clear_new:c {knot \tl_use:N \l__knot_prefix_tl -1}
675 \tl_set_eq:cc
676 {knot \tl_use:N \l__knot_prefix_tl -1}
677 {knot \tl_use:N \l__knot_tmpg_tl}
678
679 \tl_clear_new:c {l__knot_options_ \tl_use:N \l__knot_prefix_tl -1}
680 \tl_set_eq:cc
681 {l__knot_options_ \tl_use:N \l__knot_prefix_tl -1}
682 {l__knot_options_ \tl_use:N \l__knot_tmpg_tl}
683
684 \bool_if:nT
685 {
686 \l__knot_prepend_prev_bool
687 &&
688 \tl_if_exist_p:c {knot previous \tl_use:N \l__knot_tmpg_tl}
689 &&
690 !\tl_if_empty_p:c {knot previous \tl_use:N \l__knot_tmpg_tl}
691 }
692 {
693 \knot_debug:x {Prepending~
694 \tl_use:c {knot previous \tl_use:N \l__knot_tmpg_tl}}
695 \spath_prepend_no_move:cv
696 {knot \tl_use:N \l__knot_prefix_tl -1}
697 {knot \tl_use:c {knot previous \tl_use:N \l__knot_tmpg_tl}}
698 \bool_if:nT
699 {
700 \l__knot_splits_bool
701 &&
702 \tl_if_exist_p:c {knot previous
703 \tl_use:c {knot previous \tl_use:N \l__knot_tmpg_tl}
704 }
705 &&
706 !\tl_if_empty_p:c {knot previous
707 \tl_use:c {knot previous \tl_use:N \l__knot_tmpg_tl}
708 }
709 }
710 {
711 \knot_test_endpoint:NvnT
712 \l__knot_redraw_tolerance_dim
713 {knot previous \tl_use:N \l__knot_tmpg_tl}
714 {initial point}
715 {
716 \knot_debug:x {Prepending~
717 \tl_use:c {knot previous
718 \tl_use:c {knot previous \tl_use:N \l__knot_tmpg_tl}
719 }
720 }
721 \spath_prepend_no_move:cv
722 {knot \tl_use:N \l__knot_prefix_tl -1}
723 {knot \tl_use:c
724 {knot previous \tl_use:c
725 {knot previous \tl_use:N \l__knot_tmpg_tl}
726 }
727 }
728 \tl_set_eq:Nc \l__knot_tmpa_tl
729 {knot \tl_use:N \l__knot_prefix_tl -1}
730 }
731 }
732 }
733
734 \bool_if:nT
735 {
736 \l__knot_append_next_bool
737 &&
738 \tl_if_exist_p:c {knot next \tl_use:N \l__knot_tmpg_tl}
739 &&
740 !\tl_if_empty_p:c {knot next \tl_use:N \l__knot_tmpg_tl}
741 }
742 {
743 \knot_debug:x {Appending~
744 \tl_use:c {knot next \tl_use:N \l__knot_tmpg_tl}}
745 \spath_append_no_move:cv
746 {knot \tl_use:N \l__knot_prefix_tl -1}
747 {knot \tl_use:c {knot next \tl_use:N \l__knot_tmpg_tl}}
748 \bool_if:nT
749 {
750 \l__knot_splits_bool
751 &&
752 \tl_if_exist_p:c {knot next \tl_use:c { knot next \tl_use:N
753 \l__knot_tmpg_tl}}
754 &&
755 !\tl_if_empty_p:c {knot next
756 \tl_use:c { knot next \tl_use:N \l__knot_tmpg_tl}
757 }
758 }
759 {
760 \knot_debug:x {Testing~ whether~ to~ append~
761 {knot next \tl_use:c { knot next \tl_use:N \l__knot_tmpg_tl}}
762 }
763 \knot_test_endpoint:NvnT
764 \l__knot_redraw_tolerance_dim
765 {knot next \tl_use:N \l__knot_tmpg_tl}
766 {final point}
767 {
768 \knot_debug:x {Appending~
769 {knot next \tl_use:c { knot next \tl_use:N \l__knot_tmpg_tl}}
770 }
771 \spath_append_no_move:cv
772 {knot \tl_use:N \l__knot_prefix_tl -1}
773 {knot \tl_use:c
774 {knot next \tl_use:c
775 {knot next \tl_use:N \l__knot_tmpg_tl}
776 }
777 }
778 }
779 }
780 }
781 \tl_set:Nn \l__knot_tmpg_tl {\tl_use:N \l__knot_prefix_tl -1}
782 }
783 }
784 \pgfscope
785 \group_begin:
786 \tikzset{
787 knot~ diagram/every~ intersection/.try,
788 every~ intersection/.try,
789 knot~ diagram/intersection~ \int_use:N \g__knot_intersections_int/.try
790 }
791 \knot_draw_crossing:VVV \l__knot_tmpg_tl \l__knot_tmpa_dim \l__knot_tmpb_dim
792 \coordinate
793 (\l__knot_name_tl \c_space_tl \int_use:N \g__knot_intersections_int)
794 at (\dim_use:N \l__knot_tmpa_dim, \dim_use:N \l__knot_tmpb_dim);
795 \group_end:
796 \endpgfscope
797 }
798 \tl_if_empty:NF \l__knot_node_tl
799 {
800 \seq_gpush:Nx
801 \g__knot_nodes_seq
802 {
803 \l__knot_node_tl
804 at
805 (\dim_use:N \l__knot_tmpa_dim, \dim_use:N \l__knot_tmpb_dim) {};
806 }
807 }
808 }
809 }
810
811 \cs_generate_variant:Nn \knot_intersections:nn {VV}
812 \prg_new_conditional:Npnn \knot_test_endpoint:NN #1#2 {p,T,F,TF}
813 {
814 \dim_compare:nTF
815 {
816 \dim_abs:n { \l__knot_tmpa_dim - \tl_item:Nn #2 {1}}
817 +
818 \dim_abs:n { \l__knot_tmpb_dim - \tl_item:Nn #2 {2}}
819 <
820 #1
821 }
822 {
823 \prg_return_true:
824 }
825 {
826 \prg_return_false:
827 }
828 }
829 \prg_new_protected_conditional:Npnn \knot_test_endpoint:Nnn #1#2#3 {T,F,TF}
830 {
831 \use:c {spath_#3:Nv} \l__knot_tmpd_tl {knot #2}
832 \knot_test_endpoint:NNTF #1 \l__knot_tmpd_tl
833 {
834 \prg_return_true:
835 }
836 {
837 \prg_return_false:
838 }
839 }
840
841 \cs_generate_variant:Nn \knot_test_endpoint:NnnT {NVnT,NvnT}
842 \cs_generate_variant:Nn \knot_test_endpoint:NnnF {NVnF,NvnF}
843 \cs_generate_variant:Nn \knot_test_endpoint:NnnTF {NVnTF,NvnTF}
844 \cs_new_protected_nopar:Npn \knot_draw_crossing:nnn #1#2#3
845 {
846 \knot_debug:n {knot~ draw~ crossing}
847 \group_begin:
848 \pgfscope
849 \path[knot~ diagram/background~ clip] (#2, #3)
850 circle[radius=\l__knot_clip_bg_radius_dim];
851
852 \tl_set:Nn \l__knot_tmpa_tl {knot~ diagram/every~ strand/.try,}
853 \tl_if_exist:cT {l__knot_options_ #1}
854 {
855 \tl_put_right:Nv \l__knot_tmpa_tl {l__knot_options_ #1}
856 }
857 \tl_put_right:Nn \l__knot_tmpa_tl
858 {
859 ,knotbg
860 ,line~ width= \tl_use:N \l__knot_clip_width_tl * \pgflinewidth
861 }
862 \spath_tikz_path:Vv \l__knot_tmpa_tl {knot #1}
863
864 \endpgfscope
865
866 \pgfscope
867 \path[knot~ diagram/clip] (#2, #3)
868 circle[radius=\l__knot_clip_draw_radius_dim];
869
870 \tl_set:Nn \l__knot_tmpa_tl {knot~ diagram/every~ strand/.try,}
871 \tl_if_exist:cT {l__knot_options_ #1}
872 {
873 \tl_put_right:Nv \l__knot_tmpa_tl {l__knot_options_ #1}
874 }
875 \tl_put_right:Nn \l__knot_tmpa_tl
876 {
877 ,knot~ diagram/only~ when~ rendering/.try
878 ,only~ when~ rendering/.try
879 }
880 \spath_tikz_path:Vv \l__knot_tmpa_tl {knot #1}
881
882 \endpgfscope
883 \group_end:
884 }
885
886 \cs_generate_variant:Nn \knot_draw_crossing:nnn {nVV, VVV}
887
888 \cs_new_protected_nopar:Npn \knot_draw_crossing:nn #1#2
889 {
890 \tikz@scan@one@point\pgfutil@firstofone #2 \relax
891 \knot_draw_crossing:nVV {#1} \pgf@x \pgf@y
892 }
893 \cs_new_protected_nopar:Npn \knot_split_strands:
894 {
895 \knot_debug:n {knot~ split~ strands}
896 \int_gzero:N \g__knot_filaments_int
897 \int_step_function:nnnN {1} {1} {\l__knot_strands_int} \knot_split_strand:n
898 \int_step_function:nnnN {1} {1} {\g__knot_filaments_int} \knot_compute_nexts:n
899 }
900 \cs_new_protected_nopar:Npn \knot_compute_nexts:n #1
901 {
902 \knot_debug:n {knot~ compute~ nexts}
903 \tl_clear_new:c {knot next \tl_use:c {knot previous filament #1}}
904 \tl_set:cn {knot next \tl_use:c {knot previous filament #1}} {filament #1}
905 }
906 \cs_new_protected_nopar:Npn \knot_split_strand:n #1
907 {
908 \knot_debug:n {knot~ split~ strand}
909 \int_set_eq:NN \l__knot_component_start_int \g__knot_filaments_int
910 \int_incr:N \l__knot_component_start_int
911 \tl_set_eq:Nc \l__knot_tmpa_tl {l__knot_options_strand #1}
912 \spath_remove_empty_components:c {knot strand #1}
913 \spath_segments_to_seq:Nv \l__knot_segments_seq {knot strand #1}
914 \seq_map_function:NN \l__knot_segments_seq \knot_save_filament:N
915 }
916 \cs_new_protected_nopar:Npn \knot_save_filament:N #1
917 {
918 \knot_debug:n {knot~ save~ filament}
919 \tl_set:Nx \l__knot_tmpb_tl {\tl_item:nn {#1} {4}}
920 \token_case_meaning:NnF \l__knot_tmpb_tl
921 {
922 \c_spath_moveto_tl
923 {
924 \int_compare:nT {\l__knot_component_start_int < \g__knot_filaments_int}
925 {
926 \int_set_eq:NN \l__knot_component_start_int \g__knot_filaments_int
927 }
928 }
929 \c_spath_lineto_tl
930 {
931 \int_gincr:N \g__knot_filaments_int
932 \tl_clear_new:c {knot filament \int_use:N \g__knot_filaments_int}
933 \tl_set:cn {knot filament \int_use:N \g__knot_filaments_int} {#1}
934
935 \tl_clear_new:c {l__knot_options_filament \int_use:N \g__knot_filaments_int}
936 \tl_set_eq:cN {l__knot_options_filament \int_use:N \g__knot_filaments_int}
937 \l__knot_tmpa_tl
938
939 \tl_clear_new:c {knot previous filament \int_use:N \g__knot_filaments_int}
940 \int_compare:nF {\l__knot_component_start_int == \g__knot_filaments_int}
941 {
942 \tl_set:cx {knot previous filament \int_use:N \g__knot_filaments_int}
943 {filament \int_eval:n {\g__knot_filaments_int - 1}}
944 }
945 }
946 \c_spath_curvetoa_tl
947 {
948 \int_gincr:N \g__knot_filaments_int
949 \tl_clear_new:c {knot filament \int_use:N \g__knot_filaments_int}
950 \tl_set:cn {knot filament \int_use:N \g__knot_filaments_int} {#1}
951 \tl_clear_new:c {l__knot_options_filament \int_use:N \g__knot_filaments_int}
952 \tl_set_eq:cN {l__knot_options_filament \int_use:N \g__knot_filaments_int}
953 \l__knot_tmpa_tl
954
955 \tl_clear_new:c {knot previous filament \int_use:N \g__knot_filaments_int}
956 \int_compare:nF {\l__knot_component_start_int == \g__knot_filaments_int}
957 {
958 \tl_set:cx
959 {knot previous filament \int_use:N \g__knot_filaments_int}
960 {filament \int_eval:n {\g__knot_filaments_int - 1}}
961 }
962 }
963 \c_spath_closepath_tl
964 {
965 \int_gincr:N \g__knot_filaments_int
966 \tl_clear_new:c {knot filament \int_use:N \g__knot_filaments_int}
967 \tl_clear:N \l__knot_tmpa_tl
968 \tl_put_right:Nx
969 {
970 \tl_item:nn {#1} {1}\tl_item:nn {#1} {2}\tl_item:nn {#1} {3}
971 }
972 \tl_put_right:NV \l__knot_tmpa_tl \c_spath_lineto_tl
973 \tl_put_right:Nx {\tl_item:nn {#1} {5}\tl_item:nn {#1} {6}}
974
975 \tl_set:cV {knot filament \int_use:N \g__knot_filaments_int} \l__knot_tmpa_tl
976 \tl_set_eq:cN {l__knot_options_filament \int_use:N \g__knot_filaments_int}
977 \l__knot_tmpa_tl
978 \tl_clear_new:c {knot previous filament \int_use:N \g__knot_filaments_int}
979 \int_compare:nF {\l__knot_component_start_int == \g__knot_filaments_int}
980 {
981 \tl_set:cx
982 {knot previous filament \int_use:N \g__knot_filaments_int}
983 {filament \int_eval:n {\g__knot_filaments_int - 1}}
984 }
985 \tl_set:cx
986 {knot previous filament \int_use:N \l__knot_component_start_int}
987 {filament \int_use:N \g__knot_filaments_int}
988 }
989 }
990 {
991 }
992 }
993 \NewDocumentCommand \redraw { m m }
994 {
995 \tl_put_right:Nn \l__knot_redraws_tl {\knot_draw_crossing:nn}
996 \tl_put_right:Nx \l__knot_redraws_tl {
997 {strand #1} {#2}% {\dim_use:N \pgf@x} {\dim_use:N \pgf@y}
998 }
999 }
1000 \ExplSyntaxOff
1001 \def\pgf@sh@@knotanchor#1#2{%
1002 \anchor{#2 north west}{%
1003 \csname pgf@anchor@knot #1@north west\endcsname%
1004 \pgf@x=#2\pgf@x%
1005 \pgf@y=#2\pgf@y%
1006 }%
1007 \anchor{#2 north east}{%
1008 \csname pgf@anchor@knot #1@north east\endcsname%
1009 \pgf@x=#2\pgf@x%
1010 \pgf@y=#2\pgf@y%
1011 }%
1012 \anchor{#2 south west}{%
1013 \csname pgf@anchor@knot #1@south west\endcsname%
1014 \pgf@x=#2\pgf@x%
1015 \pgf@y=#2\pgf@y%
1016 }%
1017 \anchor{#2 south east}{%
1018 \csname pgf@anchor@knot #1@south east\endcsname%
1019 \pgf@x=#2\pgf@x%
1020 \pgf@y=#2\pgf@y%
1021 }%
1022 \anchor{#2 north}{%
1023 \csname pgf@anchor@knot #1@north\endcsname%
1024 \pgf@x=#2\pgf@x%
1025 \pgf@y=#2\pgf@y%
1026 }%
1027 \anchor{#2 east}{%
1028 \csname pgf@anchor@knot #1@east\endcsname%
1029 \pgf@x=#2\pgf@x%
1030 \pgf@y=#2\pgf@y%
1031 }%
1032 \anchor{#2 west}{%
1033 \csname pgf@anchor@knot #1@west\endcsname%
1034 \pgf@x=#2\pgf@x%
1035 \pgf@y=#2\pgf@y%
1036 }%
1037 \anchor{#2 south}{%
1038 \csname pgf@anchor@knot #1@south\endcsname%
1039 \pgf@x=#2\pgf@x%
1040 \pgf@y=#2\pgf@y%
1041 }%
1042 }
1043 \pgfdeclareshape{knot crossing}
1044 {
1045 \inheritsavedanchors[from=circle] % this is nearly a circle
1046 \inheritanchorborder[from=circle]
1047 \inheritanchor[from=circle]{north}
1048 \inheritanchor[from=circle]{north west}
1049 \inheritanchor[from=circle]{north east}
1050 \inheritanchor[from=circle]{center}
1051 \inheritanchor[from=circle]{west}
1052 \inheritanchor[from=circle]{east}
1053 \inheritanchor[from=circle]{mid}
1054 \inheritanchor[from=circle]{mid west}
1055 \inheritanchor[from=circle]{mid east}
1056 \inheritanchor[from=circle]{base}
1057 \inheritanchor[from=circle]{base west}
1058 \inheritanchor[from=circle]{base east}
1059 \inheritanchor[from=circle]{south}
1060 \inheritanchor[from=circle]{south west}
1061 \inheritanchor[from=circle]{south east}
1062 \inheritanchorborder[from=circle]
1063 \pgf@sh@@knotanchor{crossing}{2}
1064 \pgf@sh@@knotanchor{crossing}{3}
1065 \pgf@sh@@knotanchor{crossing}{4}
1066 \pgf@sh@@knotanchor{crossing}{8}
1067 \pgf@sh@@knotanchor{crossing}{16}
1068 \pgf@sh@@knotanchor{crossing}{32}
1069 \backgroundpath{
1070 \pgfutil@tempdima=\radius%
1071 \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%
1072 \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%
1073 \ifdim\pgf@xb<\pgf@yb%
1074 \advance\pgfutil@tempdima by-\pgf@yb%
1075 \else%
1076 \advance\pgfutil@tempdima by-\pgf@xb%
1077 \fi%
1078 }
1079 }
1080 \pgfdeclareshape{knot over cross}
1081 {
1082 \inheritsavedanchors[from=rectangle] % this is nearly a circle
1083 \inheritanchorborder[from=rectangle]
1084 \inheritanchor[from=rectangle]{north}
1085 \inheritanchor[from=rectangle]{north west}
1086 \inheritanchor[from=rectangle]{north east}
1087 \inheritanchor[from=rectangle]{center}
1088 \inheritanchor[from=rectangle]{west}
1089 \inheritanchor[from=rectangle]{east}
1090 \inheritanchor[from=rectangle]{mid}
1091 \inheritanchor[from=rectangle]{mid west}
1092 \inheritanchor[from=rectangle]{mid east}
1093 \inheritanchor[from=rectangle]{base}
1094 \inheritanchor[from=rectangle]{base west}
1095 \inheritanchor[from=rectangle]{base east}
1096 \inheritanchor[from=rectangle]{south}
1097 \inheritanchor[from=rectangle]{south west}
1098 \inheritanchor[from=rectangle]{south east}
1099 \inheritanchorborder[from=rectangle]
1100 \backgroundpath{
1101 \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1102 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1103 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
1104 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
1105 }
1106 \foregroundpath{
1107 \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1108 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1109 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
1110 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
1111 }
1112 }
1113 \pgfdeclareshape{knot under cross}
1114 {
1115 \inheritsavedanchors[from=rectangle] % this is nearly a circle
1116 \inheritanchorborder[from=rectangle]
1117 \inheritanchor[from=rectangle]{north}
1118 \inheritanchor[from=rectangle]{north west}
1119 \inheritanchor[from=rectangle]{north east}
1120 \inheritanchor[from=rectangle]{center}
1121 \inheritanchor[from=rectangle]{west}
1122 \inheritanchor[from=rectangle]{east}
1123 \inheritanchor[from=rectangle]{mid}
1124 \inheritanchor[from=rectangle]{mid west}
1125 \inheritanchor[from=rectangle]{mid east}
1126 \inheritanchor[from=rectangle]{base}
1127 \inheritanchor[from=rectangle]{base west}
1128 \inheritanchor[from=rectangle]{base east}
1129 \inheritanchor[from=rectangle]{south}
1130 \inheritanchor[from=rectangle]{south west}
1131 \inheritanchor[from=rectangle]{south east}
1132 \inheritanchorborder[from=rectangle]
1133 \backgroundpath{
1134 \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1135 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1136 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
1137 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
1138 }
1139 \foregroundpath{
1140 \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1141 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1142 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
1143 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
1144 }
1145 }
1146 \pgfdeclareshape{knot vert}
1147 {
1148 \inheritsavedanchors[from=rectangle] % this is nearly a circle
1149 \inheritanchorborder[from=rectangle]
1150 \inheritanchor[from=rectangle]{north}
1151 \inheritanchor[from=rectangle]{north west}
1152 \inheritanchor[from=rectangle]{north east}
1153 \inheritanchor[from=rectangle]{center}
1154 \inheritanchor[from=rectangle]{west}
1155 \inheritanchor[from=rectangle]{east}
1156 \inheritanchor[from=rectangle]{mid}
1157 \inheritanchor[from=rectangle]{mid west}
1158 \inheritanchor[from=rectangle]{mid east}
1159 \inheritanchor[from=rectangle]{base}
1160 \inheritanchor[from=rectangle]{base west}
1161 \inheritanchor[from=rectangle]{base east}
1162 \inheritanchor[from=rectangle]{south}
1163 \inheritanchor[from=rectangle]{south west}
1164 \inheritanchor[from=rectangle]{south east}
1165 \inheritanchorborder[from=rectangle]
1166 \backgroundpath{
1167 \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1168 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1169 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
1170 \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
1171 \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
1172 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
1173 }
1174 }
1175 \pgfdeclareshape{knot horiz}
1176 {
1177 \inheritsavedanchors[from=rectangle] % this is nearly a circle
1178 \inheritanchorborder[from=rectangle]
1179 \inheritanchor[from=rectangle]{north}
1180 \inheritanchor[from=rectangle]{north west}
1181 \inheritanchor[from=rectangle]{north east}
1182 \inheritanchor[from=rectangle]{center}
1183 \inheritanchor[from=rectangle]{west}
1184 \inheritanchor[from=rectangle]{east}
1185 \inheritanchor[from=rectangle]{mid}
1186 \inheritanchor[from=rectangle]{mid west}
1187 \inheritanchor[from=rectangle]{mid east}
1188 \inheritanchor[from=rectangle]{base}
1189 \inheritanchor[from=rectangle]{base west}
1190 \inheritanchor[from=rectangle]{base east}
1191 \inheritanchor[from=rectangle]{south}
1192 \inheritanchor[from=rectangle]{south west}
1193 \inheritanchor[from=rectangle]{south east}
1194 \inheritanchorborder[from=rectangle]
1195 \foregroundpath{
1196 \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
1197 \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
1198 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
1199 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
1200 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
1201 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
1202 }
1203 }
1204 %%
1205 %% Copyright (C) 2011-2024 by Andrew Stacey <[email protected]>
1206 %%
1207 %% This work may be distributed and/or modified under the
1208 %% conditions of the LaTeX Project Public License (LPPL), either
1209 %% version 1.3c of this license or (at your option) any later
1210 %% version. The latest version of this license is in the file:
1211 %%
1212 %% http://www.latex-project.org/lppl.txt
1213 %%
1214 %% This work is "maintained" (as per LPPL maintenance status) by
1215 %% Andrew Stacey.
1216 %%
1217 %% This work consists of the files spath3_code.dtx
1218 %% calligraphy_doc.tex
1219 %% knots_doc.tex
1220 %% spath3.tex
1221 %% and the derived files spath3.ins,
1222 %% spath3_code.pdf,
1223 %% spath3.sty,
1224 %% tikzlibrarycalligraphy.code.tex
1225 %% tikzlibraryknots.code.tex
1226 %% tikzlibraryspath3.code.tex
1227 %% calligraphy.pdf
1228 %% knots.pdf
1229 %% spath3.pdf
1230 %% README.txt
1231 %%
1232 %%
1233 %% End of file `tikzlibraryknots.code.tex'.