From 3fc4de03f2da103a96f5d0cc757300f8c7e311f1 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 23 Jan 2021 22:17:41 +0000 Subject: spath3 (23jan21) git-svn-id: svn://tug.org/texlive/trunk@57504 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/spath3/spath3.sty | 3837 ++++++++++++++------ .../latex/spath3/tikzlibrarycalligraphy.code.tex | 417 +-- .../tex/latex/spath3/tikzlibraryknots.code.tex | 321 +- .../tex/latex/spath3/tikzlibraryspath3.code.tex | 595 +++ 4 files changed, 3662 insertions(+), 1508 deletions(-) create mode 100644 Master/texmf-dist/tex/latex/spath3/tikzlibraryspath3.code.tex (limited to 'Master/texmf-dist/tex/latex/spath3') diff --git a/Master/texmf-dist/tex/latex/spath3/spath3.sty b/Master/texmf-dist/tex/latex/spath3/spath3.sty index 43fd64cf5e2..155441947b0 100644 --- a/Master/texmf-dist/tex/latex/spath3/spath3.sty +++ b/Master/texmf-dist/tex/latex/spath3/spath3.sty @@ -4,10 +4,10 @@ %% %% The original source files were: %% -%% spath3.dtx (with options: `spath3') +%% spath3_code.dtx (with options: `spath3') %% ---------------------------------------------------------------- %% spath3 --- Functions for manipulating PGF soft paths -%% E-mail: stacey@math.ntnu.no +%% E-mail: loopspace@mathforge.org %% Released under the LaTeX Project Public License v1.3c or later %% See http://www.latex-project.org/lppl.txt %% ---------------------------------------------------------------- @@ -15,335 +15,610 @@ \NeedsTeXFormat{LaTeX2e} \RequirePackage{expl3} \RequirePackage{pgf} -\ProvidesExplPackage {spath3} {2019/02/12} {1.2} {Functions for +\ProvidesExplPackage {spath3} {2021/01/19} {2.0} {Functions for manipulating PGF soft paths} \RequirePackage{xparse} +\cs_new_protected:Nn \__spath_tl_put_right_braced:Nn +{ + \tl_put_right:Nn #1 { { #2 } } +} +\cs_generate_variant:Nn \__spath_tl_put_right_braced:Nn { NV, cV, cv, Nx, cx } + +\cs_new_protected:Nn \__spath_tl_gput_right_braced:Nn +{ + \tl_gput_right:Nn #1 { { #2 } } +} +\cs_generate_variant:Nn \__spath_tl_gput_right_braced:Nn { NV, cV, cv, Nx, cx } +\cs_new_protected:Nn \__spath_tl_put_left_braced:Nn +{ + \tl_put_left:Nn #1 { { #2 } } +} +\cs_generate_variant:Nn \__spath_tl_put_left_braced:Nn { NV, cV, cv, Nx, cx } + +\cs_new_protected:Nn \__spath_tl_gput_left_braced:Nn +{ + \tl_gput_left:Nn #1 { { #2 } } +} +\cs_generate_variant:Nn \__spath_tl_gput_left_braced:Nn { NV, cV, cv, Nx, cx } \tl_new:N \l__spath_tmpa_tl \tl_new:N \l__spath_tmpb_tl \tl_new:N \l__spath_tmpc_tl \tl_new:N \l__spath_tmpd_tl -\tl_new:N \l__spath_smuggle_tl +\tl_new:N \l__spath_tmpe_tl + +\seq_new:N \l__spath_tmpa_seq +\seq_new:N \l__spath_tmpb_seq + +\tl_new:N \g__spath_output_tl +\int_new:N \g__spath_output_int +\seq_new:N \g__spath_output_seq + \dim_new:N \l__spath_tmpa_dim \dim_new:N \l__spath_tmpb_dim +\dim_new:N \l__spath_move_x_dim +\dim_new:N \l__spath_move_y_dim \fp_new:N \l__spath_tmpa_fp \fp_new:N \l__spath_tmpb_fp \int_new:N \l__spath_tmpa_int -\int_new:N \g__spath_map_int -\tl_new:N \g__spath_moveto_tl -\tl_new:N \g__spath_lineto_tl -\tl_new:N \g__spath_curveto_tl -\tl_new:N \g__spath_curvetoa_tl -\tl_new:N \g__spath_curvetob_tl -\tl_new:N \g__spath_closepath_tl -\tl_set:Nn \g__spath_moveto_tl {\pgfsyssoftpath@movetotoken} -\tl_set:Nn \g__spath_lineto_tl {\pgfsyssoftpath@linetotoken} -\tl_set:Nn \g__spath_curveto_tl {\pgfsyssoftpath@curvetotoken} -\tl_set:Nn \g__spath_curvetoa_tl {\pgfsyssoftpath@curvetosupportatoken} -\tl_set:Nn \g__spath_curvetob_tl {\pgfsyssoftpath@curvetosupportbtoken} -\tl_set:Nn \g__spath_closepath_tl {\pgfsyssoftpath@closepathtoken} -\tl_new:N \g__spath_attributes -\tl_new:N \g__spath_moveable_attributes -\tl_new:N \g__spath_path_attributes -\tl_set:Nn \g__spath_attributes { - {path} - {reverse path} - {length} - {real length} - {number of components} - {initial point} - {final point} - {initial action} - {final action} - {min bb} - {max bb} -} -\tl_set:Nn \g__spath_moveable_attributes { - {initial point} - {final point} - {min bb} - {max bb} -} -\tl_set:Nn \g__spath_path_attributes { - {path} - {reverse path} -} -\cs_new_nopar:Npn \spath_new:n #1 -{ - \prop_new:c {l__spath_#1} -} -\cs_new_nopar:Npn \spath_clear:n #1 -{ - \prop_gclear:c {l__spath_#1} -} -\cs_new_nopar:Npn \spath_clear_new:n #1 -{ - \prop_gclear_new:c {l__spath_#1} -} -\cs_new_nopar:Npn \spath_show:n #1 -{ - \prop_show:c {l__spath_#1} -} -\cs_new_nopar:Npn \spath_put:nnn #1#2#3 -{ - \prop_gput:cnn {l__spath_#1} {#2} {#3} -} -\cs_new_nopar:Npn \spath_remove:nn #1#2 -{ - \prop_gremove:cn {l__spath_#1} {#2} -} -\cs_new_nopar:Npn \__spath_get:nn #1#2 -{ - \prop_item:cn {l__spath_#1} {#2} -} -\cs_new_nopar:Npn \__spath_get:nnN #1#2#3 + +\bool_new:N \g__spath_output_bool +\bool_new:N \l__spath_closed_bool +\tl_const:Nn \c_spath_moveto_tl {\pgfsyssoftpath@movetotoken} +\tl_const:Nn \c_spath_lineto_tl {\pgfsyssoftpath@linetotoken} +\tl_const:Nn \c_spath_curveto_tl {\pgfsyssoftpath@curvetotoken} +\tl_const:Nn \c_spath_curvetoa_tl {\pgfsyssoftpath@curvetosupportatoken} +\tl_const:Nn \c_spath_curvetob_tl {\pgfsyssoftpath@curvetosupportbtoken} +\tl_const:Nn \c_spath_closepath_tl {\pgfsyssoftpath@closepathtoken} +\int_new:N \g__spath_anon_int +\int_gzero:N \g__spath_anon_int +\tl_new:N \l__spath_itera_tl +\tl_new:N \l__spath_iterb_tl +\tl_new:N \l__spath_iterc_tl +\tl_new:N \l__spath_iterd_tl +\tl_new:N \l__spath_iterp_tl +\dim_new:N \l__spath_itera_dim +\dim_new:N \l__spath_iterb_dim +\seq_new:N \l__spath_iter_seq +\msg_new:nnn { spath3 } { unknown path construction } { The~ path~ construction~ element~ #1~ is~ not~ currently~ supported.} +\cs_new_protected_nopar:Npn \__spath_segments_to_seq:n #1 { - \prop_get:cnN {l__spath_#1} {#2} #3 + \group_begin: + \tl_set:Nn \l__spath_itera_tl {#1} + \tl_clear:N \l__spath_iterb_tl + \seq_clear:N \l__spath_iter_seq + \dim_zero:N \l__spath_itera_dim + \dim_zero:N \l__spath_iterb_dim + + \bool_until_do:nn { + \tl_if_empty_p:N \l__spath_itera_tl + } + { + \tl_set:Nx \l__spath_iterc_tl {\tl_head:N \l__spath_itera_tl} + \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl} + \tl_case:NnF \l__spath_iterc_tl + { + \c_spath_moveto_tl + { + \tl_set_eq:NN \l__spath_iterb_tl \c_spath_moveto_tl + \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}} + \dim_set:Nn \l__spath_itera_dim {\tl_head:N \l__spath_itera_tl} + \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl} + + \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}} + \dim_set:Nn \l__spath_iterb_dim {\tl_head:N \l__spath_itera_tl} + \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl} + + \tl_set:Nx \l__spath_iterd_tl {\tl_head:N \l__spath_itera_tl} + \tl_if_eq:NNF \l__spath_iterd_tl \c_spath_moveto_tl + { + \tl_clear:N \l__spath_iterb_tl + } + + } + + \c_spath_lineto_tl + { + \tl_set_eq:NN \l__spath_iterb_tl \c_spath_moveto_tl + \tl_put_right:Nx \l__spath_iterb_tl + { + {\dim_use:N \l__spath_itera_dim} + {\dim_use:N \l__spath_iterb_dim} + } + \tl_put_right:NV \l__spath_iterb_tl \c_spath_lineto_tl + + \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}} + \dim_set:Nn \l__spath_itera_dim {\tl_head:N \l__spath_itera_tl} + \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl} + + \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}} + \dim_set:Nn \l__spath_iterb_dim {\tl_head:N \l__spath_itera_tl} + \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl} + + } + + \c_spath_curvetoa_tl + { + \tl_set_eq:NN \l__spath_iterb_tl \c_spath_moveto_tl + \tl_put_right:Nx \l__spath_iterb_tl + { + {\dim_use:N \l__spath_itera_dim} + {\dim_use:N \l__spath_iterb_dim} + } + \tl_put_right:NV \l__spath_iterb_tl \c_spath_curvetoa_tl + + \prg_replicate:nn {2} { + \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}} + \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl} + \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}} + \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl} + \tl_put_right:Nx \l__spath_iterb_tl {\tl_head:N \l__spath_itera_tl} + \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl} + } + + \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}} + \dim_set:Nn \l__spath_itera_dim {\tl_head:N \l__spath_itera_tl} + \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl} + + \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}} + \dim_set:Nn \l__spath_iterb_dim {\tl_head:N \l__spath_itera_tl} + \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl} + + } + + \c_spath_closepath_tl + { + \tl_set_eq:NN \l__spath_iterb_tl \c_spath_moveto_tl + \tl_put_right:Nx \l__spath_iterb_tl + { + {\dim_use:N \l__spath_itera_dim} + {\dim_use:N \l__spath_iterb_dim} + } + \tl_put_right:NV \l__spath_iterb_tl \c_spath_lineto_tl + + \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}} + \dim_set:Nn \l__spath_itera_dim {\tl_head:N \l__spath_itera_tl} + \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl} + + \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}} + \dim_set:Nn \l__spath_iterb_dim {\tl_head:N \l__spath_itera_tl} + \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl} + + } + + } + { + + \tl_set_eq:NN \l__spath_iterb_tl \l__spath_iterc_tl + \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}} + \dim_set:Nn \l__spath_itera_dim {\tl_head:N \l__spath_itera_tl} + \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl} + + \tl_put_right:Nx \l__spath_iterb_tl {{\tl_head:N \l__spath_itera_tl}} + \dim_set:Nn \l__spath_iterb_dim {\tl_head:N \l__spath_itera_tl} + \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl} + + } + + \tl_if_empty:NF \l__spath_iterb_tl + { + \seq_put_right:NV \l__spath_iter_seq \l__spath_iterb_tl + } + \tl_clear:N \l__spath_iterb_tl + } + + \seq_gclear:N \g__spath_output_seq + \seq_gset_eq:NN \g__spath_output_seq \l__spath_iter_seq + \group_end: } -\prg_new_conditional:Npnn \spath_if_in:nn #1#2 {p, T, F, TF} +\cs_new_protected_nopar:Npn \spath_segments_to_seq:Nn #1#2 { - \prop_if_in:cnTF {l__spath_#1} {#2} - { \prg_return_true: } - { \prg_return_false: } + \__spath_segments_to_seq:n {#2} + \seq_clear_new:N #1 + \seq_set_eq:NN #1 \g__spath_output_seq + \seq_gclear:N \g__spath_output_seq } -\cs_generate_variant:Nn \__prop_split:NnTF {cnTF} -\prg_new_protected_conditional:Npnn \__spath_get:nnN #1#2#3 {T, F, TF} +\cs_generate_variant:Nn \spath_segments_to_seq:Nn {NV, cn, cV, Nv, cv} +\cs_new_protected_nopar:Npn \spath_segments_gto_seq:Nn #1#2 { - \__prop_split:cnTF {l__spath_#1} {#2} - { - \tl_set:Nn #3 {##2} - \prg_return_true: - } - { \prg_return_false: } + \__spath_segments_to_seq:n {#2} + \seq_clear_new:N #1 + \seq_gset_eq:NN #1 \g__spath_output_seq + \seq_gclear:N \g__spath_output_seq } -\cs_generate_variant:Nn \spath_put:nnn {nnV, nnx, nno} -\cs_generate_variant:Nn \__spath_get:nn {Vn} -\cs_generate_variant:Nn \__spath_get:nnN {VnN} -\prg_new_conditional:Npnn \spath_if_exist:n #1 {p,T,F,TF} +\cs_generate_variant:Nn \spath_segments_gto_seq:Nn {NV, cn, cV, Nv, cv} +\cs_new_protected_nopar:Npn \__spath_components_to_seq:n #1 { - \prop_if_exist:cTF {l__spath_#1} - { - \prg_return_true: - } - { - \prg_return_false: + \group_begin: + \tl_set:Nn \l__spath_itera_tl {#1} + \seq_clear:N \l__spath_iter_seq + \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl} + \tl_put_right:NV \l__spath_itera_tl \c_spath_moveto_tl + \tl_set_eq:NN \l__spath_iterb_tl \c_spath_moveto_tl + \bool_do_until:nn { + \tl_if_empty_p:N \l__spath_itera_tl } -} -\cs_new_nopar:Npn \spath_clone:nn #1 #2 -{ - \spath_clear_new:n {#2} - \tl_map_inline:Nn \g__spath_attributes { - \spath_if_in:nnT {#1} {##1} + \tl_set:Nx \l__spath_iterc_tl {\tl_head:N \l__spath_itera_tl} + \tl_if_eq:NNT \l__spath_iterc_tl \c_spath_moveto_tl + { + \seq_put_right:NV \l__spath_iter_seq \l__spath_iterb_tl + \tl_clear:N \l__spath_iterb_tl + } + \tl_if_single:NTF \l__spath_iterc_tl + { + \tl_put_right:NV \l__spath_iterb_tl \l__spath_iterc_tl + } { - \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl - \spath_put:nnV {#2} {##1} \l__spath_tmpa_tl + \tl_put_right:Nx \l__spath_iterb_tl {{\l__spath_iterc_tl}} } + \tl_set:Nx \l__spath_itera_tl {\tl_tail:N \l__spath_itera_tl} } -} -\cs_new_protected_nopar:Npn \spath_get_current_path:n #1 -{ - \pgfsyssoftpath@getcurrentpath\l__spath_tmpa_tl - \spath_clear_new:n {#1} - \spath_put:nnV {#1} {path} \l__spath_tmpa_tl -} -\cs_new_protected_nopar:Npn \spath_set_current_path:n #1 -{ - \spath_get:nnN {#1} {min bb} \l__spath_tmpa_tl - \exp_last_unbraced:NV \pgf@protocolsizes\l__spath_tmpa_tl - - \spath_get:nnN {#1} {max bb} \l__spath_tmpa_tl - \exp_last_unbraced:NV \pgf@protocolsizes\l__spath_tmpa_tl - \spath_get:nnN {#1} {path} \l__spath_tmpa_tl - \pgfsyssoftpath@setcurrentpath\l__spath_tmpa_tl - \pgfsyssoftpath@flushcurrentpath -} -\cs_new_protected_nopar:Npn \spath_use_path:nn #1#2 -{ - \spath_set_current_path:n {#1} - \pgfusepath{#2} + \seq_gclear:N \g__spath_output_seq + \seq_gset_eq:NN \g__spath_output_seq \l__spath_iter_seq + \group_end: } -\cs_new_protected_nopar:Npn \spath_protocol_path:n #1 +\cs_new_protected_nopar:Npn \spath_components_to_seq:Nn #1#2 { - \spath_get:nnN {#1} {min bb} \l__spath_tmpa_tl - \exp_last_unbraced:NV \pgf@protocolsizes\l__spath_tmpa_tl - - \spath_get:nnN {#1} {max bb} \l__spath_tmpa_tl - \exp_last_unbraced:NV \pgf@protocolsizes\l__spath_tmpa_tl + \__spath_components_to_seq:n {#2} + \seq_clear_new:N #1 + \seq_set_eq:NN #1 \g__spath_output_seq + \seq_gclear:N \g__spath_output_seq } -\cs_new_protected_nopar:Npn \spath_tikz_path:nn #1#2 +\cs_generate_variant:Nn \spath_components_to_seq:Nn {NV, cn, cV, cv, Nv} +\cs_new_protected_nopar:Npn \spath_components_gto_seq:Nn #1#2 { - \path[#1] \pgfextra{ - \spath_get:nnN {#2} {path} \l__spath_tmpa_tl - \pgfsyssoftpath@setcurrentpath \l__spath_tmpa_tl - }; + \__spath_components_to_seq:n {#2} + \seq_clear_new:N #1 + \seq_gset_eq:NN #1 \g__spath_output_seq + \seq_gclear:N \g__spath_output_seq } -\cs_generate_variant:Nn \spath_tikz_path:nn {Vn} -\cs_new_nopar:Npn \spath_get:nn #1#2 +\cs_generate_variant:Nn \spath_components_gto_seq:Nn {NV, cn, cV, cv, Nv} +\cs_new_protected_nopar:Npn \spath_components_to_clist:Nn #1#2 { - \spath_if_in:nnF {#1} {#2} - { - \cs_if_exist_use:cT {spath_generate_#2:n} {{#1}} - } - \__spath_get:nn {#1} {#2} + \__spath_components_to_seq:n {#2} + \clist_clear_new:N #1 + \clist_set_from_seq:NN #1 \g__spath_output_seq + \seq_gclear:N \g__spath_output_seq } -\cs_new_nopar:Npn \spath_get:nnN #1#2#3 +\cs_generate_variant:Nn \spath_components_to_clist:Nn {NV, cn, cV, cv, Nv} +\cs_new_protected_nopar:Npn \spath_components_gto_clist:Nn #1#2 { - \spath_if_in:nnF {#1} {#2} - { - \cs_if_exist_use:cT {spath_generate_#2:n} {{#1}} - } - \__spath_get:nnN {#1} {#2} #3 + \__spath_components_to_seq:n {#2} + \clist_clear_new:N #1 + \clist_gset_from_seq:NN #1 \g__spath_output_seq + \seq_gclear:N \g__spath_output_seq } -\cs_generate_variant:Nn \spath_get:nnN {VnN} -\cs_new_nopar:Npn \spath_generate_length:n #1 +\cs_generate_variant:Nn \spath_components_gto_clist:Nn {NV, cn, cV, cv, Nv} +\cs_new_protected_nopar:Npn \spath_length:n #1 { - \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl - \spath_put:nnx {#1} {length} {\int_eval:n {\tl_count:N \l__spath_tmpa_tl /3 }} + \int_eval:n {\tl_count:n {#1} / 3} } -\cs_new_nopar:Npn \spath_generate_reallength:n #1 +\cs_generate_variant:Nn \spath_length:n {V} +\cs_new_protected_nopar:Npn \__spath_reallength:n #1 { - \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl + \group_begin: \int_set:Nn \l__spath_tmpa_int {0} - \tl_map_inline:Nn \l__spath_tmpa_tl { - \tl_if_eq:nnT {##1} {\pgfsyssoftpath@linetotoken} + \tl_map_inline:nn {#1} { + \tl_set:Nn \l__spath_tmpc_tl {##1} + \tl_case:NnT \l__spath_tmpc_tl { - \int_incr:N \l__spath_tmpa_int + \c_spath_lineto_tl {} + \c_spath_curveto_tl {} + \c_spath_closepath_tl {} } - \tl_if_eq:nnT {##1} {\pgfsyssoftpath@curvetotoken} { \int_incr:N \l__spath_tmpa_int } } - \spath_put:nnx {#1} {real length} {\int_use:N \l__spath_tmpa_int} + \int_gzero:N \g__spath_output_int + \int_gset_eq:NN \g__spath_output_int \l__spath_tmpa_int + \group_end: } -\cs_new_nopar:Npn \spath_generate_numberofcomponents:n #1 +\cs_new_protected_nopar:Npn \spath_reallength:Nn #1#2 { - \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl + \__spath_reallength:n {#2} + \int_set_eq:NN #1 \g__spath_output_int + \int_gzero:N \g__spath_output_int +} +\cs_generate_variant:Nn \spath_reallength:Nn {NV, cn, cV, Nv, cv} +\cs_new_protected_nopar:Npn \spath_greallength:Nn #1#2 +{ + \__spath_reallength:n {#2} + \int_gset_eq:NN #1 \g__spath_output_int + \int_gzero:N \g__spath_output_int +} +\cs_generate_variant:Nn \spath_greallength:Nn {NV, cn, cV} +\cs_new_protected_nopar:Npn \__spath_numberofcomponents:n #1 +{ + \group_begin: \int_set:Nn \l__spath_tmpa_int {0} - \tl_map_inline:Nn \l__spath_tmpa_tl { - \tl_if_eq:nnT {##1} {\pgfsyssoftpath@movetotoken} + \tl_map_inline:nn {#1} { + \tl_set:Nn \l__spath_tmpa_tl {##1} + \tl_case:Nn \l__spath_tmpa_tl { - \int_incr:N \l__spath_tmpa_int + \c_spath_moveto_tl + { + \int_incr:N \l__spath_tmpa_int + } } } - \spath_put:nnx {#1} {number of components} {\int_use:N \l__spath_tmpa_int} + \int_gzero:N \g__spath_output_int + \int_gset_eq:NN \g__spath_output_int \l__spath_tmpa_int + \group_end: } -\cs_new_nopar:Npn \spath_generate_initialpoint:n #1 +\cs_new_protected_nopar:Npn \spath_numberofcomponents:Nn #1#2 { - \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl - \tl_clear:N \l__spath_tmpb_tl - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}} - \spath_put:nnV {#1} {initial point} \l__spath_tmpb_tl + \__spath_numberofcomponents:n {#2} + \int_set_eq:NN #1 \g__spath_output_int + \int_gzero:N \g__spath_output_int } -\cs_new_nopar:Npn \spath_generate_finalpoint:n #1 +\cs_generate_variant:Nn \spath_numberofcomponents:Nn {NV, cn, cV} +\cs_new_protected_nopar:Npn \spath_gnumberofcomponents:Nn #1#2 { + \__spath_numberofcomponents:n {#2} + \int_gset_eq:NN #1 \g__spath_output_int + \int_gzero:N \g__spath_output_int +} +\cs_generate_variant:Nn \spath_gnumberofcomponents:Nn {NV, cn, cV} +\cs_new_protected_nopar:Npn \__spath_initialpoint:n #1 +{ + \group_begin: \tl_clear:N \l__spath_tmpb_tl - \spath_if_in:nnTF {#1} {reverse path} + \tl_set:Nx \l__spath_tmpb_tl { - \__spath_get:nnN {#1} {reverse path} \l__spath_tmpa_tl - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}} + { \tl_item:nn {#1} {2} } + { \tl_item:nn {#1} {3} } } + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_initialpoint:Nn #1#2 +{ + \__spath_initialpoint:n {#2} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_initialpoint:Nn {NV, cn, cV, Nv} +\cs_new_protected_nopar:Npn \spath_ginitialpoint:Nn #1#2 +{ + \__spath_initialpoint:n {#2} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_ginitialpoint:Nn {NV, cn, cV, Nv} +\cs_new_protected_nopar:Npn \__spath_finalpoint:n #1 +{ + \group_begin: + \tl_set:Nn \l__spath_tmpa_tl {#1} + \tl_reverse:N \l__spath_tmpa_tl + \tl_clear:N \l__spath_tmpb_tl + \tl_set:Nx \l__spath_tmpb_tl { - \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl - \tl_reverse:N \l__spath_tmpa_tl - \tl_put_left:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_put_left:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}} + { \tl_item:Nn \l__spath_tmpa_tl {2} } + { \tl_item:Nn \l__spath_tmpa_tl {1} } } - \spath_put:nnV {#1} {final point} \l__spath_tmpb_tl + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_finalpoint:Nn #1#2 +{ + \__spath_finalpoint:n {#2} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_finalpoint:Nn {NV, cn, cV, Nv} +\cs_new_protected_nopar:Npn \spath_gfinalpoint:Nn #1#2 +{ + \__spath_finalpoint:n {#2} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl } -\cs_generate_variant:Nn \spath_generate_finalpoint:n {V} -\cs_new_nopar:Npn \spath_generate_reversepath:n #1 +\cs_generate_variant:Nn \spath_gfinalpoint:Nn {NV, cn, cV, Nv} +\cs_new_protected_nopar:Npn \__spath_reverse:n #1 { - \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl + \group_begin: + \tl_set:Nn \l__spath_tmpa_tl {#1} + \tl_clear:N \l__spath_tmpb_tl + \tl_clear:N \l__spath_tmpd_tl \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl} \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_put_left:Nx \l__spath_tmpb_tl + + \tl_put_left:Nx \l__spath_tmpd_tl { {\dim_use:N \l__spath_tmpa_dim} {\dim_use:N \l__spath_tmpb_dim} } + + \bool_set_false:N \l__spath_closed_bool + \bool_until_do:nn { \tl_if_empty_p:N \l__spath_tmpa_tl } { \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nn \l__spath_tmpd_tl {} - \tl_case:NnF \l__spath_tmpc_tl + + \tl_case:NnTF \l__spath_tmpc_tl { - \g__spath_moveto_tl {\tl_set_eq:NN \l__spath_tmpd_tl \g__spath_moveto_tl } - \g__spath_lineto_tl {\tl_set_eq:NN \l__spath_tmpd_tl \g__spath_lineto_tl } - \g__spath_curveto_tl {\tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curvetoa_tl } - \g__spath_curvetoa_tl {\tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curveto_tl } - \g__spath_curvetob_tl {\tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curvetob_tl } + \c_spath_moveto_tl { + + \bool_if:NT \l__spath_closed_bool + { + \tl_put_right:NV \l__spath_tmpd_tl \c_spath_closepath_tl + \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpd_tl} + \tl_put_right:Nx \l__spath_tmpd_tl + { + { \tl_head:N \l__spath_tmpd_tl } + { \tl_head:N \l__spath_tmpe_tl } + } + } + \bool_set_false:N \l__spath_closed_bool + \tl_put_left:NV \l__spath_tmpd_tl \c_spath_moveto_tl + \tl_put_left:NV \l__spath_tmpb_tl \l__spath_tmpd_tl + \tl_clear:N \l__spath_tmpd_tl + } + \c_spath_lineto_tl { + \tl_put_left:NV \l__spath_tmpd_tl \c_spath_lineto_tl + } + \c_spath_curveto_tl { + \tl_put_left:NV \l__spath_tmpd_tl \c_spath_curvetoa_tl + } + \c_spath_curvetoa_tl { + \tl_put_left:NV \l__spath_tmpd_tl \c_spath_curveto_tl + } + \c_spath_curvetob_tl { + \tl_put_left:NV \l__spath_tmpd_tl \c_spath_curvetob_tl + } } { - \tl_show:N \l__spath_tmpc_tl + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + + \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + + \tl_put_left:Nx \l__spath_tmpd_tl + { + {\dim_use:N \l__spath_tmpa_dim} + {\dim_use:N \l__spath_tmpb_dim} + } + } - \tl_put_left:NV \l__spath_tmpb_tl \l__spath_tmpd_tl - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_put_left:Nx \l__spath_tmpb_tl { - {\dim_use:N \l__spath_tmpa_dim} - {\dim_use:N \l__spath_tmpb_dim} + \tl_if_eq:NNTF \l__spath_tmpc_tl \c_spath_closepath_tl + { + \bool_set_true:N \l__spath_closed_bool + } + { + \msg_warning:nnx { spath3 } { unknown path construction } {\l__spath_tmpc_tl } + } + + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + + } + } + + \bool_if:NT \l__spath_closed_bool + { + \tl_put_right:NV \l__spath_tmpd_tl \c_spath_closepath_tl + \tl_set:Nx \l__spath_tmpe_tl {\tl_tail:N \l__spath_tmpd_tl} + \tl_put_right:Nx \l__spath_tmpd_tl + { + { \tl_head:N \l__spath_tmpd_tl } + { \tl_head:N \l__spath_tmpe_tl } } } - \tl_put_left:NV \l__spath_tmpb_tl \g__spath_moveto_tl - \spath_put:nnV {#1} {reverse path} \l__spath_tmpb_tl + + \bool_set_false:N \l__spath_closed_bool + \tl_put_left:NV \l__spath_tmpd_tl \c_spath_moveto_tl + \tl_put_left:NV \l__spath_tmpb_tl \l__spath_tmpd_tl + + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl + \group_end: } -\cs_new_nopar:Npn \spath_generate_initialaction:n #1 +\cs_new_protected_nopar:Npn \spath_reverse:Nn #1#2 { - \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl - \tl_clear:N \l__spath_tmpb_tl - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_if_empty:NF \l__spath_tmpa_tl { - \tl_set:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl} - } - \spath_put:nnV {#1} {initial action} \l__spath_tmpb_tl + \__spath_reverse:n {#2} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl } -\cs_new_nopar:Npn \spath_generate_finalaction:n #1 +\cs_generate_variant:Nn \spath_reverse:Nn {NV, cn, cV, Nv} +\cs_new_protected_nopar:Npn \spath_reverse:N #1 { - \tl_clear:N \l__spath_tmpb_tl - \spath_if_in:nnTF {#1} {reverse path} + \spath_reverse:NV #1#1 +} +\cs_generate_variant:Nn \spath_reverse:N {c} +\cs_new_protected_nopar:Npn \spath_greverse:Nn #1#2 +{ + \__spath_reverse:n {#2} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_greverse:Nn {NV, cn, cV, Nv} +\cs_new_protected_nopar:Npn \spath_greverse:N #1 +{ + \spath_greverse:NV #1#1 +} +\cs_generate_variant:Nn \spath_greverse:N {c} +\cs_new_protected_nopar:Npn \__spath_initialaction:n #1 +{ + \group_begin: + \tl_clear:N \l__spath_tmpa_tl + \int_compare:nT { - \__spath_get:nnN {#1} {reverse path} \l__spath_tmpa_tl - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \tl_count:n {#1} > 3 } { - \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl - \tl_reverse:N \l__spath_tmpa_tl + \tl_set:Nx \l__spath_tmpa_tl + { + \tl_item:Nn {#1} {4} + } } - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_if_empty:NF \l__spath_tmpa_tl { - \tl_set:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl} + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_initialaction:Nn #1#2 +{ + \__spath_initialaction:n {#2} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_initialaction:Nn {NV} +\cs_new_protected_nopar:Npn \spath_ginitialaction:Nn #1#2 +{ + \__spath_initialaction:n {#2} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_ginitialaction:Nn {NV} +\cs_new_protected_nopar:Npn \__spath_finalaction:n #1 +{ + \group_begin: + \tl_clear:N \l__spath_tmpb_tl + \int_compare:nT + { + \tl_count:n {#1} > 3 } - \tl_if_eq:NNT \l__spath_tmpa_tl \g__spath_curvetoa_tl { - \tl_set_eq:NN \l__spath_tmpa_tl \g__spath_curveto_tl + \tl_set:Nn \l__spath_tmpa_tl {#1} + \tl_reverse:N \l__spath_tmpa_tl + \tl_set:Nx \l__spath_tmpb_tl + { + \tl_item:Nn \l__spath_tmpa_tl {3} + } + \tl_if_eq:NNT \l__spath_tmpb_tl \c_spath_curvetoa_tl + { + \tl_set_eq:NN \l__spath_tmpb_tl \c_spath_curveto_tl + } } - \spath_put:nnV {#1} {final action} \l__spath_tmpb_tl + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_finalaction:Nn #1#2 +{ + \__spath_finalaction:n {#2} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_finalaction:Nn {NV} +\cs_new_protected_nopar:Npn \spath_gfinalaction:Nn #1#2 +{ + \__spath_finalaction:n {#2} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl } -\cs_new_nopar:Npn \spath_generate_minbb:n #1 +\cs_generate_variant:Nn \spath_gfinalaction:Nn {NV} +\cs_new_protected_nopar:Npn \__spath_minbb:n #1 { - \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl + \group_begin: + \tl_set:Nn \l__spath_tmpa_tl {#1} \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} @@ -365,11 +640,27 @@ manipulating PGF soft paths} {\dim_use:N \l__spath_tmpa_dim} {\dim_use:N \l__spath_tmpb_dim} } - \spath_put:nnV {#1} {min bb} \l__spath_tmpb_tl + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_minbb:Nn #1#2 +{ + \__spath_minbb:n {#2} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_minbb:Nn {NV, cn, cV} +\cs_new_protected_nopar:Npn \spath_gminbb:Nn #1#2 +{ + \__spath_minbb:n {#2} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl } -\cs_new_nopar:Npn \spath_generate_maxbb:n #1 +\cs_generate_variant:Nn \spath_gminbb:Nn {NV, cn, cV} +\cs_new_protected_nopar:Npn \__spath_maxbb:n #1 { - \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl + \group_begin: + \tl_set:Nn \l__spath_tmpa_tl {#1} \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} @@ -391,1101 +682,2440 @@ manipulating PGF soft paths} {\dim_use:N \l__spath_tmpa_dim} {\dim_use:N \l__spath_tmpb_dim} } - \spath_put:nnV {#1} {max bb} \l__spath_tmpb_tl -} -\tl_new:N \l__spath_rp_tl -\int_new:N \l__spath_l_int -\int_new:N \l__spath_rl_int -\int_new:N \l__spath_nc_int -\tl_new:N \l__spath_ip_tl -\tl_new:N \l__spath_fp_tl -\tl_new:N \l__spath_ia_tl -\tl_new:N \l__spath_fa_tl -\dim_new:N \l__spath_minx_dim -\dim_new:N \l__spath_miny_dim -\dim_new:N \l__spath_maxx_dim -\dim_new:N \l__spath_maxy_dim - -\cs_new_nopar:Npn \spath_generate_all:n #1 -{ - \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl - - \tl_clear:N \l__spath_rp_tl - \int_set:Nn \l__spath_l_int {1} - \int_zero:N \l__spath_rl_int - \int_set:Nn \l__spath_nc_int {1} - \tl_clear:N \l__spath_ip_tl - \tl_clear:N \l__spath_fp_tl - \tl_clear:N \l__spath_ia_tl - \tl_clear:N \l__spath_fa_tl - \dim_zero:N \l__spath_minx_dim - \dim_zero:N \l__spath_miny_dim - \dim_zero:N \l__spath_maxx_dim - \dim_zero:N \l__spath_maxy_dim + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_maxbb:Nn #1#2 +{ + \__spath_maxbb:n {#2} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_maxbb:Nn {NV, cn, cV} +\cs_new_protected_nopar:Npn \spath_gmaxbb:Nn #1#2 +{ + \__spath_maxbb:n {#2} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gmaxbb:Nn {NV, cn, cV} +\int_set:Nn \l__spath_tmpa_int {\char_value_catcode:n {`@}} +\char_set_catcode_letter:N @ +\cs_new_protected_nopar:Npn \spath_save_to_aux:Nn #1#2 { + \tl_if_empty:nF {#2} + { + \tl_clear:N \l__spath_tmpa_tl + \tl_put_right:Nn \l__spath_tmpa_tl { + \ExplSyntaxOn + \tl_clear:N #1 + \tl_set:Nn #1 {#2} + \ExplSyntaxOff + } + \protected@write\@auxout{}{ + \tl_to_str:N \l__spath_tmpa_tl + } + } +} +\char_set_catcode:nn {`@} {\l__spath_tmpa_int} +\cs_generate_variant:Nn \spath_save_to_aux:Nn {cn, cV, NV} +\cs_new_protected_nopar:Npn \spath_save_to_aux:N #1 +{ + \tl_if_exist:NT #1 + { + \spath_save_to_aux:NV #1#1 + } +} +\cs_new_protected_nopar:Npn \__spath_translate:nnn #1#2#3 +{ + \group_begin: + \tl_set:Nn \l__spath_tmpa_tl {#1} + \tl_clear:N \l__spath_tmpb_tl + \bool_until_do:nn { + \tl_if_empty_p:N \l__spath_tmpa_tl + } + { + \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl + #2} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + + \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl + #3} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + + \tl_put_right:Nx \l__spath_tmpb_tl + { + {\dim_use:N \l__spath_tmpa_dim} + {\dim_use:N \l__spath_tmpb_dim} + } + } + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_translate:Nnnn #1#2#3#4 +{ + \__spath_translate:nnn {#2}{#3}{#4} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_translate:Nnnn {NVxx, NVVV, NVnn} +\cs_new_protected_nopar:Npn \spath_translate:Nnn #1#2#3 +{ + \spath_translate:NVnn #1#1{#2}{#3} +} +\cs_generate_variant:Nn \spath_translate:Nnn {NVV, cnn, cVV} +\cs_new_protected_nopar:Npn \spath_gtranslate:Nnnn #1#2#3#4 +{ + \__spath_translate:nnn {#2}{#3}{#4} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gtranslate:Nnnn {NVxx, NVVV, NVnn} +\cs_new_protected_nopar:Npn \spath_gtranslate:Nnn #1#2#3 +{ + \spath_gtranslate:NVnn #1#1{#2}{#3} +} +\cs_generate_variant:Nn \spath_gtranslate:Nnn {NVV, cnn, cVV} +\cs_new_protected_nopar:Npn \spath_translate:Nn #1#2 +{ + \spath_translate:Nnn #1 #2 +} +\cs_generate_variant:Nn \spath_translate:Nn {NV} +\cs_new_protected_nopar:Npn \spath_gtranslate:Nn #1#2 +{ + \spath_gtranslate:Nnn #1 #2 +} +\cs_generate_variant:Nn \spath_gtranslate:Nn {NV} +\cs_new_protected_nopar:Npn \__spath_scale:nnn #1#2#3 +{ + \group_begin: + \tl_set:Nn \l__spath_tmpa_tl {#1} + \tl_clear:N \l__spath_tmpb_tl + \bool_until_do:nn { + \tl_if_empty_p:N \l__spath_tmpa_tl + } + { + \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + + \fp_set:Nn \l__spath_tmpa_fp {\tl_head:N \l__spath_tmpa_tl * #2} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + + \fp_set:Nn \l__spath_tmpb_fp {\tl_head:N \l__spath_tmpa_tl * #3} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + + \tl_put_right:Nx \l__spath_tmpb_tl + { + {\fp_to_dim:N \l__spath_tmpa_fp} + {\fp_to_dim:N \l__spath_tmpb_fp} + } + } + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_scale:Nnnn #1#2#3#4 +{ + \__spath_scale:nnn {#2}{#3}{#4} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_scale:Nnnn {NVnn, Nnxx} +\cs_new_protected_nopar:Npn \spath_scale:Nnn #1#2#3 +{ + \spath_scale:NVnn #1#1{#2}{#3} +} +\cs_generate_variant:Nn \spath_scale:Nnn {cnn, cVV, NVV} +\cs_new_protected_nopar:Npn \spath_gscale:Nnnn #1#2#3#4 +{ + \__spath_scale:nnn {#2}{#3}{#4} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gscale:Nnnn {NVnn, Nnxx} +\cs_new_protected_nopar:Npn \spath_gscale:Nnn #1#2#3 +{ + \spath_gscale:NVnn #1#1{#2}{#3} +} +\cs_generate_variant:Nn \spath_gscale:Nnn {cnn, cVV, NVV} +\cs_new_protected_nopar:Npn \spath_scale:Nn #1#2 +{ + \spath_scale:Nnn #1 #2 +} + +\cs_generate_variant:Nn \spath_scale:Nn {NV} +\cs_new_protected_nopar:Npn \spath_gscale:Nn #1#2 +{ + \spath_gscale:Nnn #1 #2 +} + +\cs_generate_variant:Nn \spath_gscale:Nn {NV} +\cs_new_protected_nopar:Npn \__spath_transform:nnnnnnn #1#2#3#4#5#6#7 +{ + \group_begin: + \tl_set:Nn \l__spath_tmpa_tl {#1} + \tl_clear:N \l__spath_tmpb_tl + \bool_until_do:nn { + \tl_if_empty_p:N \l__spath_tmpa_tl + } + { + \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpd_tl {\tl_head:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + + \fp_set:Nn \l__spath_tmpa_fp {\l__spath_tmpc_tl * #2 + \l__spath_tmpd_tl * #4 + #6} + \fp_set:Nn \l__spath_tmpb_fp {\l__spath_tmpc_tl * #3 + \l__spath_tmpd_tl * #5 + #7} + \tl_put_right:Nx \l__spath_tmpb_tl + { + {\fp_to_dim:N \l__spath_tmpa_fp} + {\fp_to_dim:N \l__spath_tmpb_fp} + } + } + + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_transform:Nnnnnnnn #1#2#3#4#5#6#7#8 +{ + \__spath_transform:nnnnnnn {#2}{#3}{#4}{#5}{#6}{#7}{#8} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_transform:Nnnnnnnn {NVnnnnnn, Nnxxxxxx, cnnnnnnn} +\cs_new_protected_nopar:Npn \spath_transform:Nnnnnnn #1#2#3#4#5#6#7 +{ + \spath_transform:NVnnnnnn #1#1{#2}{#3}{#4}{#5}{#6}{#7} +} +\cs_generate_variant:Nn \spath_transform:Nnnnnnn {cnnnnnn} +\cs_new_protected_nopar:Npn \spath_transform:Nnn #1#2#3 +{ + \spath_transform:Nnnnnnnn #1{#2}#3 +} +\cs_generate_variant:Nn \spath_transform:Nnn {cnn, cVn, NVn, NnV} +\cs_new_protected_nopar:Npn \spath_transform:Nn #1#2 +{ + \spath_transform:NVnnnnnn #1#1#2 +} +\cs_generate_variant:Nn \spath_transform:Nn {cn, cV, NV} + +\cs_new_protected_nopar:Npn \spath_gtransform:Nnnnnnnn #1#2#3#4#5#6#7#8 +{ + \__spath_transform:nnnnnnn {#2}{#3}{#4}{#5}{#6}{#7}{#8} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gtransform:Nnnnnnnn {NVnnnnnn, Nnxxxxxx, cnnnnnnn} +\cs_new_protected_nopar:Npn \spath_gtransform:Nnnnnnn #1#2#3#4#5#6#7 +{ + \spath_gtransform:NVnnnnnn #1#1{#2}{#3}{#4}{#5}{#6}{#7} +} +\cs_generate_variant:Nn \spath_gtransform:Nnnnnnn {cnnnnnn} +\cs_new_protected_nopar:Npn \spath_gtransform:Nnn #1#2#3 +{ + \spath_gtransform:Nnnnnnnn #1{#2}#3 +} +\cs_generate_variant:Nn \spath_gtransform:Nnn {cnn, cVn, NVn, NnV} +\cs_new_protected_nopar:Npn \spath_gtransform:Nn #1#2 +{ + \spath_gtransform:NVnnnnnn #1#1#2 +} +\cs_generate_variant:Nn \spath_gtransform:Nn {cn, cV, NV} +\cs_new_protected_nopar:Npn \__spath_weld:nn #1#2 +{ + \group_begin: + \tl_set:Nn \l__spath_tmpa_tl {#1} + \tl_set:Nn \l__spath_tmpb_tl {#2} + + \spath_finalpoint:NV \l__spath_tmpc_tl \l__spath_tmpa_tl + \spath_initialpoint:NV \l__spath_tmpd_tl \l__spath_tmpb_tl + + \dim_set:Nn \l__spath_tmpa_dim + { + \tl_item:Nn \l__spath_tmpc_tl {1} + - + \tl_item:Nn \l__spath_tmpd_tl {1} + } + \dim_set:Nn \l__spath_tmpb_dim + { + \tl_item:Nn \l__spath_tmpc_tl {2} + - + \tl_item:Nn \l__spath_tmpd_tl {2} + } + + \spath_translate:NVV \l__spath_tmpb_tl \l__spath_tmpa_dim \l__spath_tmpb_dim + + \prg_replicate:nn {3} + { + \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} + } + + \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_weld:Nnn #1#2#3 +{ + \__spath_weld:nn {#2}{#3} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_weld:Nnn {NVV,NVn} +\cs_new_protected_nopar:Npn \spath_weld:Nn #1#2 +{ + \spath_weld:NVn #1#1{#2} +} +\cs_generate_variant:Nn \spath_weld:Nn {NV, Nv, cV, cv} +\cs_new_protected_nopar:Npn \spath_gweld:Nnn #1#2#3 +{ + \__spath_weld:nn {#2}{#3} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gweld:Nnn {NVV, NVn} +\cs_new_protected_nopar:Npn \spath_gweld:Nn #1#2 +{ + \spath_gweld:NVn #1#1{#2} +} +\cs_generate_variant:Nn \spath_gweld:Nn {NV, Nv, cV, cv} +\cs_new_protected_nopar:Npn \__spath_append_no_move:nn #1#2 +{ + \group_begin: + \tl_set:Nn \l__spath_tmpa_tl {#1} + \tl_set:Nn \l__spath_tmpb_tl {#2} + \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} + \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} + \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} + + \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_append_no_move:Nnn #1#2#3 +{ + \__spath_append_no_move:nn {#2}{#3} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_append_no_move:Nnn {NVV, NVn} +\cs_new_protected_nopar:Npn \spath_append_no_move:Nn #1#2 +{ + \spath_append_no_move:NVn #1#1{#2} +} +\cs_generate_variant:Nn \spath_append_no_move:Nn {NV, cv} +\cs_new_protected_nopar:Npn \spath_gappend_no_move:Nnn #1#2#3 +{ + \__spath_append_no_move:nn {#2}{#3} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gappend_no_move:Nnn {NVV, NVn} +\cs_new_protected_nopar:Npn \spath_gappend_no_move:Nn #1#2 +{ + \spath_gappend_no_move:NVn #1#1{#2} +} +\cs_generate_variant:Nn \spath_gappend_no_move:Nn {NV, cv} +\cs_new_protected_nopar:Npn \spath_append:Nnn #1#2#3 +{ + \tl_set:Nn #1 {#2} + \tl_put_right:Nn #1 {#3} +} +\cs_generate_variant:Nn \spath_append:Nnn {NVV, NVn} +\cs_new_protected_nopar:Npn \spath_append:Nn #1#2 +{ + \spath_append:NVn #1#1{#2} +} +\cs_generate_variant:Nn \spath_append:Nn {NV, Nv} +\cs_new_protected_nopar:Npn \spath_gappend:Nnn #1#2#3 +{ + \tl_gset:Nn #1 {#2} + \tl_gput_right:Nn #1 {#3} +} +\cs_generate_variant:Nn \spath_gappend:Nnn {NVV, NVn} +\cs_new_protected_nopar:Npn \spath_gappend:Nn #1#2 +{ + \spath_gappend:NVn #1#1{#2} +} +\cs_generate_variant:Nn \spath_gappend:Nn {NV, Nv} +\cs_new_protected_nopar:Npn \spath_prepend_no_move:Nnn #1#2#3 +{ + \spath_append_no_move:Nnn #1{#3}{#2} +} +\cs_generate_variant:Nn \spath_prepend_no_move:Nnn {NVV, NVn} +\cs_new_protected_nopar:Npn \spath_prepend_no_move:Nn #1#2 +{ + \spath_prepend_no_move:NVn #1#1{#2} +} +\cs_generate_variant:Nn \spath_prepend_no_move:Nn {NV, cv} +\cs_new_protected_nopar:Npn \spath_gprepend_no_move:Nnn #1#2#3 +{ + \spath_gappend_no_move:Nnn #1{#3}{#2} +} +\cs_generate_variant:Nn \spath_gprepend_no_move:Nnn {NVV, NVn} +\cs_new_protected_nopar:Npn \spath_gprepend_no_move:Nn #1#2 +{ + \spath_gprepend_no_move:NVn #1#1{#2} +} +\cs_generate_variant:Nn \spath_gprepend_no_move:Nn {NV, cv} +\cs_new_protected_nopar:Npn \spath_prepend:Nnn #1#2#3 +{ + \spath_append:Nnn #1{#3}{#2} +} +\cs_generate_variant:Nn \spath_prepend:Nnn {NVV, NVn} +\cs_new_protected_nopar:Npn \spath_prepend:Nn #1#2 +{ + \spath_prepend:NVn #1#1{#2} +} +\cs_generate_variant:Nn \spath_prepend:Nn {NV} +\cs_new_protected_nopar:Npn \spath_gprepend:Nnn #1#2#3 +{ + \spath_gappend:Nnn #1{#3}{#2} +} +\cs_generate_variant:Nn \spath_gprepend:Nnn {NVV, NVn} +\cs_new_protected_nopar:Npn \spath_gprepend:Nn #1#2 +{ + \spath_gprepend:NVn #1#1{#2} +} +\cs_generate_variant:Nn \spath_gprepend:Nn {NV} +\cs_new_protected_nopar:Npn \__spath_bake_round:n #1 +{ + \group_begin: + \tl_set:Nn \l__spath_tmpa_tl {#1} + \pgf@@processround \l__spath_tmpa_tl\l__spath_tmpb_tl + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_bake_round:Nn #1#2 +{ + \__spath_bake_round:n {#2} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_bake_round:Nn {NV} +\cs_new_protected_nopar:Npn \spath_bake_round:N #1 +{ + \spath_bake_round:NV #1#1 +} +\cs_generate_variant:Nn \spath_bake_round:N {c} +\cs_new_protected_nopar:Npn \spath_gbake_round:Nn #1#2 +{ + \__spath_bake_round:n {#2} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gbake_round:Nn {NV} +\cs_new_protected_nopar:Npn \spath_gbake_round:N #1 +{ + \spath_gbake_round:NV #1#1 +} +\cs_generate_variant:Nn \spath_gbake_round:N {c} +\cs_new_protected_nopar:Npn \__spath_close:n #1 +{ + \group_begin: + \tl_set:Nn \l__spath_tmpa_tl {#1} + \spath_initialpoint:NV \l__spath_tmpb_tl \l__spath_tmpa_tl + \tl_put_right:NV \l__spath_tmpa_tl \c_spath_closepath_tl + \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_close:Nn #1#2 +{ + \__spath_close:n {#2} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_close:Nn {NV} +\cs_new_protected_nopar:Npn \spath_close:N #1 +{ + \spath_close:NV #1#1 +} +\cs_generate_variant:Nn \spath_close:N {c} +\cs_new_protected_nopar:Npn \spath_gclose:Nn #1#2 +{ + \__spath_close:n {#2} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gclose:Nn {NV} +\cs_new_protected_nopar:Npn \spath_gclose:N #1 +{ + \spath_gclose:NV #1#1 +} +\cs_generate_variant:Nn \spath_gclose:N {c} +\cs_new_protected_nopar:Npn \__spath_open:n #1 +{ + \group_begin: + \tl_set:Nn \l__spath_tmpa_tl {#1} + \tl_clear:N \l__spath_tmpb_tl + \bool_until_do:nn { + \tl_if_empty_p:N \l__spath_tmpa_tl + } + { + \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + + \tl_case:NnF \l__spath_tmpc_tl + { + \c_spath_closepath_tl { + + \bool_if:nF + { + \dim_compare_p:n + { + \l__spath_move_x_dim == \l__spath_tmpa_dim + } + && + \dim_compare_p:n + { + \l__spath_move_y_dim == \l__spath_tmpb_dim + } + } + { + \tl_put_right:NV \l__spath_tmpb_tl \c_spath_lineto_tl + + \tl_put_right:Nx \l__spath_tmpb_tl { + { \dim_use:N \l__spath_move_x_dim } + { \dim_use:N \l__spath_move_y_dim } + } + } + + \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + } + + \c_spath_moveto_tl { + \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpc_tl + + \dim_set:Nn \l__spath_move_x_dim {\tl_head:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \dim_set:Nn \l__spath_move_y_dim {\tl_head:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + + \tl_put_right:Nx \l__spath_tmpb_tl { + { \dim_use:N \l__spath_move_x_dim } + { \dim_use:N \l__spath_move_y_dim } + } + + \dim_set_eq:NN \l__spath_tmpa_dim \l__spath_move_x_dim + \dim_set_eq:NN \l__spath_tmpb_dim \l__spath_move_y_dim + } + } + { + \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpc_tl + + \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + + \tl_put_right:Nx \l__spath_tmpb_tl { + { \dim_use:N \l__spath_tmpa_dim } + { \dim_use:N \l__spath_tmpb_dim } + } + } + } + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpb_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_open:Nn #1#2 +{ + \__spath_open:n {#2} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_open:Nn {NV} +\cs_new_protected_nopar:Npn \spath_open:N #1 +{ + \spath_open:NV #1#1 +} +\cs_new_protected_nopar:Npn \spath_gopen:Nn #1#2 +{ + \__spath_open:n {#2} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gopen:Nn {NV} +\cs_new_protected_nopar:Npn \spath_gopen:N #1 +{ + \spath_gopen:NV #1#1 +} +\cs_new_protected_nopar:Npn \__spath_remove_empty_components:n #1 +{ + \group_begin: + \spath_components_to_seq:Nn \l__spath_tmpa_seq {#1} + \tl_clear:N \l__spath_tmpa_tl + \seq_map_inline:Nn \l__spath_tmpa_seq + { + \int_compare:nF + { + \tl_count:n {##1} == 3 + } + { + \tl_put_right:Nn \l__spath_tmpa_tl {##1} + } + } + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_remove_empty_components:Nn #1#2 +{ + \__spath_remove_empty_components:n {#2} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_remove_empty_components:Nn {NV} +\cs_new_protected_nopar:Npn \spath_remove_empty_components:N #1 +{ + \spath_remove_empty_components:NV #1#1 +} +\cs_generate_variant:Nn \spath_remove_empty_components:N {c} +\cs_new_protected_nopar:Npn \spath_gremove_empty_components:Nn #1#2 +{ + \__spath_remove_empty_components:n {#2} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gremove_empty_components:Nn {NV} +\cs_new_protected_nopar:Npn \spath_gremove_empty_components:N #1 +{ + \spath_gremove_empty_components:NV #1#1 +} +\cs_generate_variant:Nn \spath_gremove_empty_components:N {c} +\prg_new_protected_conditional:Npnn \spath_if_eq:nn #1#2 { T, F, TF } +{ + \group_begin: + \tl_set:Nn \l__spath_tmpa_tl {#1} + \tl_set:Nn \l__spath_tmpb_tl {#2} + \bool_gset_true:N \g__spath_tmpa_bool + \int_compare:nNnTF {\tl_count:N \l__spath_tmpa_tl} = {\tl_count:N \l__spath_tmpb_tl} + { + \int_step_inline:nnnn {1} {3} {\tl_count:N \l__spath_tmpa_tl} + { + \tl_set:Nx \l__spath_tmpc_tl {\tl_item:Nn \l__spath_tmpa_tl {##1}} + \tl_set:Nx \l__spath_tmpd_tl {\tl_item:Nn \l__spath_tmpb_tl {##1}} + \tl_if_eq:NNF \l__spath_tmpc_tl \l__spath_tmpd_tl + { + \bool_gset_false:N \g__spath_tmpa_bool + } + \dim_set:Nn \l__spath_tmpa_dim {\tl_item:Nn \l__spath_tmpa_tl {##1+1}} + \dim_set:Nn \l__spath_tmpb_dim {\tl_item:Nn \l__spath_tmpb_tl {##1+1}} + \dim_compare:nF { \dim_abs:n { \l__spath_tmpa_dim - \l__spath_tmpb_dim} < 0.001pt } + { + \bool_gset_false:N \g__spath_tmpa_bool + } + \dim_set:Nn \l__spath_tmpa_dim {\tl_item:Nn \l__spath_tmpa_tl {##1+2}} + \dim_set:Nn \l__spath_tmpb_dim {\tl_item:Nn \l__spath_tmpb_tl {##1+2}} + \dim_compare:nF { \dim_abs:n { \l__spath_tmpa_dim - \l__spath_tmpb_dim} < 0.001pt } + { + \bool_gset_false:N \g__spath_tmpa_bool + } + } + } + { + \bool_gset_false:N \g__spath_tmpa_bool + } + \group_end: + \bool_if:NTF \g__spath_tmpa_bool + { + \prg_return_true: + } + { + \prg_return_false: + } +} +\prg_generate_conditional_variant:Nnn \spath_if_eq:nn {VV, Vn, nV, vv} {TF, T, F} +\cs_new_protected_nopar:Npn \__spath_split_curve:nn #1#2 +{ + \group_begin: + \tl_set_eq:NN \l__spath_tmpa_tl \c_spath_moveto_tl + \tl_put_right:Nx \l__spath_tmpa_tl { + {\tl_item:nn {#1} {2}} + {\tl_item:nn {#1} {3}} + } + \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curvetoa_tl + \tl_put_right:Nx \l__spath_tmpa_tl + { + {\fp_to_dim:n + { + (1 - #2) * \tl_item:nn {#1} {2} + (#2) * \tl_item:nn {#1} {5} + }} + {\fp_to_dim:n + { + (1 - #2) * \tl_item:nn {#1} {3} + (#2) * \tl_item:nn {#1} {6} + }} + } + + \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curvetob_tl + \tl_put_right:Nx \l__spath_tmpa_tl + { + {\fp_to_dim:n + { + (1 - #2)^2 * \tl_item:nn {#1} {2} + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {5} + (#2)^2 * \tl_item:nn {#1} {8} + }} + {\fp_to_dim:n + { + (1 - #2)^2 * \tl_item:nn {#1} {3} + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {6} + (#2)^2 * \tl_item:nn {#1} {9} + }} + } + + \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curveto_tl + \tl_put_right:Nx \l__spath_tmpa_tl + { + {\fp_to_dim:n + { + (1 - #2)^3 * \tl_item:nn {#1} {2} + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {5} + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {8} + (#2)^3 * \tl_item:nn {#1} {11} + }} + {\fp_to_dim:n + { + (1 - #2)^3 * \tl_item:nn {#1} {3} + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {6} + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {9} + (#2)^3 * \tl_item:nn {#1} {12} + }} + } + + \tl_gclear:N \g__spath_output_tl + \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_tmpa_tl + + \tl_clear:N \l__spath_tmpa_tl + \tl_set_eq:NN \l__spath_tmpa_tl \c_spath_moveto_tl + \tl_put_right:Nx \l__spath_tmpa_tl + { + {\fp_to_dim:n + { + (1 - #2)^3 * \tl_item:nn {#1} {2} + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {5} + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {8} + (#2)^3 * \tl_item:nn {#1} {11} + }} + {\fp_to_dim:n + { + (1 - #2)^3 * \tl_item:nn {#1} {3} + 3 * (1 - #2)^2 * (#2) * \tl_item:nn {#1} {6} + 3 * (1 - #2) * (#2)^2 * \tl_item:nn {#1} {9} + (#2)^3 * \tl_item:nn {#1} {12} + }} + } + + \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curvetoa_tl + \tl_put_right:Nx \l__spath_tmpa_tl + { + {\fp_to_dim:n + { + (1 - #2)^2 * \tl_item:nn {#1} {5} + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {8} + (#2)^2 * \tl_item:nn {#1} {11} + }} + {\fp_to_dim:n + { + (1 - #2)^2 * \tl_item:nn {#1} {6} + 2 * (1 - #2) * (#2) * \tl_item:nn {#1} {9} + (#2)^2 * \tl_item:nn {#1} {12} + }} + } + \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curvetob_tl + \tl_put_right:Nx \l__spath_tmpa_tl + { + {\fp_to_dim:n + { + (1 - #2) * \tl_item:nn {#1} {8} + (#2) * \tl_item:nn {#1} {11} + }} + {\fp_to_dim:n + { + (1 - #2) * \tl_item:nn {#1} {9} + (#2) * \tl_item:nn {#1} {12} + }} + } + \tl_put_right:NV \l__spath_tmpa_tl \c_spath_curveto_tl + \tl_put_right:Nx \l__spath_tmpa_tl { + {\tl_item:nn {#1} {11}} + {\tl_item:nn {#1} {12}} + } + + \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_tmpa_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_split_curve:NNnn #1#2#3#4 +{ + \__spath_split_curve:nn {#3}{#4} + \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}} + \tl_set:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}} + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_split_curve:NNnn {NNnV, NNVn, NNVV} +\cs_new_protected_nopar:Npn \spath_gsplit_curve:NNnn #1#2#3#4 +{ + \__spath_split_curve:nn {#3}{#4} + \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}} + \tl_gset:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}} + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gsplit_curve:NNnn {NNnV, NNVn, NNVV} +\cs_new_protected_nopar:Npn \__spath_split_line:nn #1#2 +{ + \group_begin: + \tl_set_eq:NN \l__spath_tmpa_tl \c_spath_moveto_tl + \tl_put_right:Nx \l__spath_tmpa_tl { + {\tl_item:nn {#1} {2}} + {\tl_item:nn {#1} {3}} + } + \tl_put_right:NV \l__spath_tmpa_tl \c_spath_lineto_tl + \tl_put_right:Nx \l__spath_tmpa_tl + { + {\fp_to_dim:n + { + (1 - #2) * \tl_item:nn {#1} {2} + (#2) * \tl_item:nn {#1} {5} + }} + {\fp_to_dim:n + { + (1 - #2) * \tl_item:nn {#1} {3} + (#2) * \tl_item:nn {#1} {6} + }} + } + \tl_gclear:N \g__spath_output_tl + \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_tmpa_tl - \tl_clear:N \l__spath_ip_tl - \tl_put_right:Nx \l__spath_ip_tl + \tl_clear:N \l__spath_tmpa_tl + \tl_set_eq:NN \l__spath_tmpa_tl \c_spath_moveto_tl + \tl_put_right:Nx \l__spath_tmpa_tl { - {\dim_use:N \l__spath_tmpa_dim} - {\dim_use:N \l__spath_tmpb_dim} + {\fp_to_dim:n + { + (1 - #2) * \tl_item:nn {#1} {2} + (#2) * \tl_item:nn {#1} {5} + }} + {\fp_to_dim:n + { + (1 - #2) * \tl_item:nn {#1} {3} + (#2) * \tl_item:nn {#1} {6} + }} + } + \tl_put_right:NV \l__spath_tmpa_tl \c_spath_lineto_tl + \tl_put_right:Nx \l__spath_tmpa_tl { + {\tl_item:nn {#1} {5}} + {\tl_item:nn {#1} {6}} } - \dim_set_eq:NN \l__spath_minx_dim \l__spath_tmpa_dim - \dim_set_eq:NN \l__spath_miny_dim \l__spath_tmpb_dim - \dim_set_eq:NN \l__spath_maxx_dim \l__spath_tmpa_dim - \dim_set_eq:NN \l__spath_maxy_dim \l__spath_tmpb_dim + \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_tmpa_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_split_line:NNnn #1#2#3#4 +{ + \__spath_split_line:nn {#3}{#4} + \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}} + \tl_set:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}} + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_split_line:NNnn {NNnV, NNVn, NNVV} +\cs_new_protected_nopar:Npn \spath_gsplit_line:NNnn #1#2#3#4 +{ + \__spath_split_line:nn {#3}{#4} + \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}} + \tl_gset:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}} + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gsplit_line:NNnn {NNnV, NNVn, NNVV} +\int_new:N \l__spath_split_int +\int_new:N \l__spath_splitat_int +\fp_new:N \l__spath_split_fp +\bool_new:N \l__spath_split_bool +\tl_new:N \l__spath_split_path_tl +\tl_new:N \l__spath_split_patha_tl +\tl_new:N \l__spath_split_pathb_tl +\tl_new:N \l__spath_split_intoa_tl +\tl_new:N \l__spath_split_intob_tl +\dim_new:N \l__spath_splitx_dim +\dim_new:N \l__spath_splity_dim +\cs_new_protected_nopar:Npn \__spath_split_at:nn #1#2 +{ + \group_begin: + \int_set:Nn \l__spath_splitat_int {\fp_to_int:n {floor(#2) + 1}} + \fp_set:Nn \l__spath_split_fp {#2 - floor(#2)} - \tl_put_left:Nx \l__spath_rp_tl + % Is split point near one end or other of a component? + \fp_compare:nT { - {\dim_use:N \l__spath_tmpa_dim} - {\dim_use:N \l__spath_tmpb_dim} + \l__spath_split_fp < 0.01 + } + { + % Near the start, so we'll place it at the start + \fp_set:Nn \l__spath_split_fp {0} + } + \fp_compare:nT + { + \l__spath_split_fp > 0.99 + } + { + % Near the end, so we'll place it at the end + \fp_set:Nn \l__spath_split_fp {0} + \int_incr:N \l__spath_splitat_int } - \tl_set:Nx \l__spath_ia_tl {\tl_head:N \l__spath_tmpa_tl} + \int_zero:N \l__spath_split_int + \bool_set_true:N \l__spath_split_bool + + \tl_set:Nn \l__spath_split_path_tl {#1} + \tl_clear:N \l__spath_split_patha_tl + + \dim_zero:N \l__spath_splitx_dim + \dim_zero:N \l__spath_splity_dim \bool_until_do:nn { - \tl_if_empty_p:N \l__spath_tmpa_tl + \tl_if_empty_p:N \l__spath_split_path_tl + || + \int_compare_p:n { \l__spath_splitat_int == \l__spath_split_int } } { - \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nn \l__spath_tmpd_tl {} - \tl_set_eq:NN \l__spath_fa_tl \l__spath_tmpc_tl - \int_incr:N \l__spath_l_int + \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_split_path_tl} + \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl } + \tl_case:Nn \l__spath_tmpc_tl + { + \c_spath_lineto_tl + { + \int_incr:N \l__spath_split_int + } + \c_spath_curvetoa_tl + { + \int_incr:N \l__spath_split_int + } + } + \int_compare:nT { \l__spath_split_int < \l__spath_splitat_int } + { + \tl_put_right:NV \l__spath_split_patha_tl \l__spath_tmpc_tl - \tl_case:NnF \l__spath_tmpc_tl + \tl_put_right:Nx \l__spath_split_patha_tl + {{ \tl_head:N \l__spath_split_path_tl }} + \dim_set:Nn \l__spath_splitx_dim {\tl_head:N \l__spath_split_path_tl} + \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl } + + \tl_put_right:Nx \l__spath_split_patha_tl + {{ \tl_head:N \l__spath_split_path_tl }} + \dim_set:Nn \l__spath_splity_dim {\tl_head:N \l__spath_split_path_tl} + \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl } + + } + } + + \tl_clear:N \l__spath_split_pathb_tl + \tl_put_right:NV \l__spath_split_pathb_tl \c_spath_moveto_tl + \tl_put_right:Nx \l__spath_split_pathb_tl + { + {\dim_use:N \l__spath_splitx_dim} + {\dim_use:N \l__spath_splity_dim} + } + + \fp_compare:nTF + { + \l__spath_split_fp == 0 + } + { + \tl_set_eq:NN \l__spath_split_intob_tl \l__spath_split_pathb_tl + \tl_if_empty:NF \l__spath_split_path_tl + { + \tl_put_right:NV \l__spath_split_intob_tl \l__spath_tmpc_tl + \tl_put_right:NV \l__spath_split_intob_tl \l__spath_split_path_tl + } + } + { + + \tl_case:Nn \l__spath_tmpc_tl { - \g__spath_moveto_tl { - \tl_set_eq:NN \l__spath_tmpd_tl \g__spath_moveto_tl - \int_incr:N \l__spath_nc_int + \c_spath_lineto_tl + { + \tl_put_right:NV \l__spath_split_pathb_tl \l__spath_tmpc_tl + \tl_put_right:Nx \l__spath_split_pathb_tl + {{ \tl_head:N \l__spath_split_path_tl }} + \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl } + + \tl_put_right:Nx \l__spath_split_pathb_tl + {{ \tl_head:N \l__spath_split_path_tl }} + \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl } + + \spath_split_line:NNVV + \l__spath_split_intoa_tl + \l__spath_split_intob_tl + \l__spath_split_pathb_tl + \l__spath_split_fp + + \prg_replicate:nn {3} { + \tl_set:Nx \l__spath_split_intoa_tl {\tl_tail:N \l__spath_split_intoa_tl} + } + + \tl_put_right:NV \l__spath_split_patha_tl \l__spath_split_intoa_tl + \tl_put_right:NV \l__spath_split_intob_tl \l__spath_split_path_tl } - \g__spath_lineto_tl { - \tl_set_eq:NN \l__spath_tmpd_tl \g__spath_lineto_tl - \int_incr:N \l__spath_rl_int + \c_spath_curvetoa_tl + { + \tl_put_right:NV \l__spath_split_pathb_tl \l__spath_tmpc_tl + \tl_put_right:Nx \l__spath_split_pathb_tl + {{ \tl_head:N \l__spath_split_path_tl }} + \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl } + + \tl_put_right:Nx \l__spath_split_pathb_tl + {{ \tl_head:N \l__spath_split_path_tl }} + \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl } + + \prg_replicate:nn {2} { + + \tl_put_right:Nx \l__spath_split_pathb_tl + { \tl_head:N \l__spath_split_path_tl } + \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl } + + \tl_put_right:Nx \l__spath_split_pathb_tl + {{ \tl_head:N \l__spath_split_path_tl }} + \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl } + + \tl_put_right:Nx \l__spath_split_pathb_tl + {{ \tl_head:N \l__spath_split_path_tl }} + \tl_set:Nx \l__spath_split_path_tl {\tl_tail:N \l__spath_split_path_tl } + } + + \spath_split_curve:NNVV + \l__spath_split_intoa_tl + \l__spath_split_intob_tl + \l__spath_split_pathb_tl \l__spath_split_fp + + \prg_replicate:nn {3} { + \tl_set:Nx \l__spath_split_intoa_tl {\tl_tail:N \l__spath_split_intoa_tl} + } + + \tl_put_right:NV \l__spath_split_patha_tl \l__spath_split_intoa_tl + \tl_put_right:NV \l__spath_split_intob_tl \l__spath_split_path_tl } - \g__spath_curveto_tl { - \tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curvetoa_tl - \int_incr:N \l__spath_rl_int + } + } + + \tl_gclear:N \g__spath_output_tl + \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_split_patha_tl + \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_split_intob_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_split_at:NNnn #1#2#3#4 +{ + \__spath_split_at:nn {#3}{#4} + \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}} + \tl_set:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}} + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_split_at:NNnn {NNVn, NNVV, NNnV} +\cs_new_protected_nopar:Npn \spath_gsplit_at:NNnn #1#2#3#4 +{ + \__spath_split_at:nn {#3}{#4} + \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}} + \tl_gset:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}} + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gsplit_at:NNnn {NNVn, NNVV, NNnV} +\cs_new_protected_nopar:Npn \spath_split_at:Nnn #1#2#3 +{ + \__spath_split_at:nn {#2}{#3} + \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1} \tl_item:Nn \g__spath_output_tl {2}} + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_split_at:Nnn {NVn, NVV} +\cs_new_protected_nopar:Npn \spath_split_at:Nn #1#2 +{ + \spath_split_at:NVn #1#1{#2} +} +\cs_new_protected_nopar:Npn \spath_gsplit_at:Nnn #1#2#3 +{ + \__spath_split_at:nn {#2}{#3} + \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1} \tl_item:Nn \g__spath_output_tl {2}} + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gsplit_at:Nnn {NVn, NVV} +\cs_new_protected_nopar:Npn \spath_gsplit_at:Nn #1#2 +{ + \spath_gsplit_at:NVn #1#1{#2} +} +\tl_new:N \l__spath_shorten_fa_tl +\tl_new:N \l__spath_shorten_path_tl +\tl_new:N \l__spath_shorten_last_tl +\tl_new:N \l__spath_shorten_lasta_tl +\tl_new:N \l__spath_shorten_lastb_tl +\int_new:N \l__spath_shorten_int +\fp_new:N \l__spath_shorten_x_fp +\fp_new:N \l__spath_shorten_y_fp +\fp_new:N \l__spath_shorten_len_fp +\cs_new_protected_nopar:Npn \__spath_shorten_at_end:nn #1#2 +{ + \int_compare:nTF + { + \tl_count:n {#1} > 3 + } + { + \group_begin: + \tl_set:Nn \l__spath_shorten_path_tl {#1} + \tl_reverse:N \l__spath_shorten_path_tl + + \tl_set:Nx \l__spath_shorten_fa_tl {\tl_item:Nn \l__spath_shorten_path_tl {3}} + + \tl_clear:N \l__spath_shorten_last_tl + \tl_if_eq:NNTF \l__spath_shorten_fa_tl \c_spath_curveto_tl + { + \int_set:Nn \l__spath_shorten_int {3} + } + { + \int_set:Nn \l__spath_shorten_int {1} + } + + \prg_replicate:nn { \l__spath_shorten_int } + { + \tl_put_right:Nx \l__spath_shorten_last_tl + { + {\tl_head:N \l__spath_shorten_path_tl} } - \g__spath_curvetoa_tl { - \tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curveto_tl + \tl_set:Nx \l__spath_shorten_path_tl {\tl_tail:N \l__spath_shorten_path_tl} + \tl_put_right:Nx \l__spath_shorten_last_tl + { + {\tl_head:N \l__spath_shorten_path_tl} } - \g__spath_curvetob_tl { - \tl_set_eq:NN \l__spath_tmpd_tl \g__spath_curvetob_tl + \tl_set:Nx \l__spath_shorten_path_tl {\tl_tail:N \l__spath_shorten_path_tl} + \tl_put_right:Nx \l__spath_shorten_last_tl + { + \tl_head:N \l__spath_shorten_path_tl } + \tl_set:Nx \l__spath_shorten_path_tl {\tl_tail:N \l__spath_shorten_path_tl} } + + \tl_put_right:Nx \l__spath_shorten_last_tl { - \tl_show:N \l__spath_tmpc_tl + {\tl_item:Nn \l__spath_shorten_path_tl {1}} + {\tl_item:Nn \l__spath_shorten_path_tl {2}} } - \tl_put_left:NV \l__spath_rp_tl \l__spath_tmpd_tl - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \tl_put_right:NV \l__spath_shorten_last_tl \c_spath_moveto_tl - \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \tl_reverse:N \l__spath_shorten_path_tl - \dim_set:Nn \l__spath_minx_dim {\dim_min:nn { \l__spath_minx_dim} {\l__spath_tmpa_dim}} - \dim_set:Nn \l__spath_miny_dim {\dim_min:nn { \l__spath_miny_dim} {\l__spath_tmpb_dim}} - \dim_set:Nn \l__spath_maxx_dim {\dim_max:nn { \l__spath_maxx_dim} {\l__spath_tmpa_dim}} - \dim_set:Nn \l__spath_maxy_dim {\dim_max:nn { \l__spath_maxy_dim} {\l__spath_tmpb_dim}} + \fp_set:Nn \l__spath_shorten_x_fp + { + \dim_to_fp:n {\tl_item:Nn \l__spath_shorten_last_tl {4}} + - + \dim_to_fp:n {\tl_item:Nn \l__spath_shorten_last_tl {1}} + } - \tl_put_left:Nx \l__spath_rp_tl + \fp_set:Nn \l__spath_shorten_y_fp { - {\dim_use:N \l__spath_tmpa_dim} - {\dim_use:N \l__spath_tmpb_dim} + \dim_to_fp:n {\tl_item:Nn \l__spath_shorten_last_tl {5}} + - + \dim_to_fp:n {\tl_item:Nn \l__spath_shorten_last_tl {2}} } - \tl_set:Nx \l__spath_fp_tl + \fp_set:Nn \l__spath_shorten_len_fp { - {\dim_use:N \l__spath_tmpa_dim} - {\dim_use:N \l__spath_tmpb_dim} + sqrt( \l__spath_shorten_x_fp * \l__spath_shorten_x_fp + \l__spath_shorten_y_fp * \l__spath_shorten_y_fp ) + } + + \fp_compare:nTF + { + \l__spath_shorten_len_fp > #2 + } + { + + \fp_set:Nn \l__spath_shorten_len_fp + { + (\l__spath_shorten_len_fp - #2)/ \l__spath_shorten_len_fp + } + + \tl_reverse:N \l__spath_shorten_last_tl + + \tl_if_eq:NNTF \l__spath_shorten_fa_tl \c_spath_curveto_tl + { + \fp_set:Nn \l__spath_shorten_len_fp + { + 1 - (1 -\l__spath_shorten_len_fp)/3 + } + \spath_split_curve:NNVV + \l__spath_shorten_lasta_tl + \l__spath_shorten_lastb_tl + \l__spath_shorten_last_tl + \l__spath_shorten_len_fp + } + { + \spath_split_line:NNVV + \l__spath_shorten_lasta_tl + \l__spath_shorten_lastb_tl + \l__spath_shorten_last_tl + \l__spath_shorten_len_fp + } + + \prg_replicate:nn {3} + { + \tl_set:Nx \l__spath_shorten_lasta_tl {\tl_tail:N \l__spath_shorten_lasta_tl} + } + + \tl_put_right:NV \l__spath_shorten_path_tl \l__spath_shorten_lasta_tl + } + { + + \int_compare:nT + { + \tl_count:N \l__spath_shorten_path_tl > 3 + } + { + \dim_set:Nn \l__spath_tmpa_dim {\fp_to_dim:n {#2 - \l__spath_shorten_len_fp } } + \spath_shorten_at_end:NV \l__spath_shorten_path_tl \l__spath_tmpa_dim + } + } + + \tl_gset_eq:NN \g__spath_output_tl \l__spath_shorten_path_tl + \group_end: + } + { + \tl_gset:Nn \g__spath_output_tl {#1} + } +} +\cs_new_protected_nopar:Npn \spath_shorten_at_end:Nnn #1#2#3 +{ + \__spath_shorten_at_end:nn {#2}{#3} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_shorten_at_end:Nnn {NVV, cnn, cVV, NVn} +\cs_new_protected_nopar:Npn \spath_shorten_at_end:Nn #1#2 +{ + \spath_shorten_at_end:NVn #1#1{#2} +} +\cs_generate_variant:Nn \spath_shorten_at_end:Nn {cn, cV, NV} +\cs_new_protected_nopar:Npn \spath_gshorten_at_end:Nnn #1#2#3 +{ + \__spath_shorten_at_end:nn {#2}{#3} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gshorten_at_end:Nnn {NVV, cnn, cVV, NVn} +\cs_new_protected_nopar:Npn \spath_gshorten_at_end:Nn #1#2 +{ + \spath_gshorten_at_end:NVn #1#1{#2} +} +\cs_generate_variant:Nn \spath_gshorten_at_end:Nn {cn, cV, NV} +\cs_new_protected_nopar:Npn \__spath_shorten_at_start:nn #1#2 +{ + \int_compare:nTF + { + \tl_count:n {#1} > 3 + } + { + \group_begin: + \tl_set:Nn \l__spath_shorten_path_tl {#1} + + \tl_set:Nx \l__spath_shorten_fa_tl {\tl_item:Nn \l__spath_shorten_path_tl {4}} + \tl_clear:N \l__spath_shorten_last_tl + + \tl_if_eq:NNTF \l__spath_shorten_fa_tl \c_spath_curvetoa_tl + { + \int_set:Nn \l__spath_shorten_int {3} + } + { + \int_set:Nn \l__spath_shorten_int {1} } - \tl_put_left:NV \l__spath_rp_tl \g__spath_moveto_tl + \tl_set_eq:NN \l__spath_shorten_last_tl \c_spath_moveto_tl + \tl_set:Nx \l__spath_shorten_path_tl {\tl_tail:N \l__spath_shorten_path_tl } - \spath_put:nnV {#1} {reverse path} \l__spath_rp_tl - \spath_put:nnV {#1} {length} \l__spath_l_int - \spath_put:nnV {#1} {real length} \l__spath_rl_int - \spath_put:nnV {#1} {number of components} \l__spath_nc_int - \spath_put:nnV {#1} {initial point} \l__spath_ip_tl - \spath_put:nnV {#1} {final point} \l__spath_fp_tl - \spath_put:nnV {#1} {initial action} \l__spath_ia_tl - \spath_put:nnV {#1} {final action} \l__spath_fa_tl + \prg_replicate:nn { \l__spath_shorten_int } + { + \__spath_tl_put_right_braced:Nx \l__spath_shorten_last_tl {\tl_item:Nn \l__spath_shorten_path_tl {1}} + \__spath_tl_put_right_braced:Nx \l__spath_shorten_last_tl {\tl_item:Nn \l__spath_shorten_path_tl {2}} + \tl_put_right:Nx \l__spath_shorten_last_tl {\tl_item:Nn \l__spath_shorten_path_tl {3}} - \tl_clear:N \l__spath_tmpb_tl - \tl_put_right:Nx \l__spath_tmpb_tl + \prg_replicate:nn {3} + { + \tl_set:Nx \l__spath_shorten_path_tl {\tl_tail:N \l__spath_shorten_path_tl } + } + } + \__spath_tl_put_right_braced:Nx \l__spath_shorten_last_tl {\tl_item:Nn \l__spath_shorten_path_tl {1}} + \__spath_tl_put_right_braced:Nx \l__spath_shorten_last_tl {\tl_item:Nn \l__spath_shorten_path_tl {2}} + + \fp_set:Nn \l__spath_shorten_x_fp { - {\dim_use:N \l__spath_minx_dim} - {\dim_use:N \l__spath_miny_dim} + \dim_to_fp:n {\tl_item:Nn \l__spath_shorten_last_tl {5}} + - + \dim_to_fp:n {\tl_item:Nn \l__spath_shorten_last_tl {2}} } - \spath_put:nnV {#1} {min bb} \l__spath_tmpb_tl - \tl_clear:N \l__spath_tmpb_tl - \tl_put_right:Nx \l__spath_tmpb_tl + \fp_set:Nn \l__spath_shorten_y_fp { - {\dim_use:N \l__spath_maxx_dim} - {\dim_use:N \l__spath_maxy_dim} + \dim_to_fp:n {\tl_item:Nn \l__spath_shorten_last_tl {6}} + - + \dim_to_fp:n {\tl_item:Nn \l__spath_shorten_last_tl {3}} } - \spath_put:nnV {#1} {max bb} \l__spath_tmpb_tl -} -\cs_new_nopar:Npn \spath_translate:nnn #1#2#3 -{ - \tl_map_inline:Nn \g__spath_moveable_attributes + \fp_set:Nn \l__spath_shorten_len_fp + { + sqrt( \l__spath_shorten_x_fp * \l__spath_shorten_x_fp + \l__spath_shorten_y_fp * \l__spath_shorten_y_fp ) + } + + \fp_compare:nTF { - \spath_if_in:nnT {#1} {##1} + \l__spath_shorten_len_fp > #2 + } + { + + \fp_set:Nn \l__spath_shorten_len_fp { - \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl + #2/ \l__spath_shorten_len_fp + } - \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl + #2} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl + #3} - \tl_clear:N \l__spath_tmpb_tl - \tl_put_right:Nx \l__spath_tmpb_tl + \tl_if_eq:NNTF \l__spath_shorten_fa_tl \c_spath_curvetoa_tl + { + \fp_set:Nn \l__spath_shorten_len_fp { - {\dim_use:N \l__spath_tmpa_dim} - {\dim_use:N \l__spath_tmpb_dim} + \l__spath_shorten_len_fp/3 } - \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl + \spath_split_curve:NNVV + \l__spath_shorten_lasta_tl + \l__spath_shorten_lastb_tl + \l__spath_shorten_last_tl + \l__spath_shorten_len_fp } - } - \tl_map_inline:Nn \g__spath_path_attributes - { - \spath_if_in:nnT {#1} {##1} { - \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl - \tl_clear:N \l__spath_tmpb_tl - \bool_until_do:nn { - \tl_if_empty_p:N \l__spath_tmpa_tl - } - { - \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \spath_split_line:NNVV + \l__spath_shorten_lasta_tl + \l__spath_shorten_lastb_tl + \l__spath_shorten_last_tl + \l__spath_shorten_len_fp + } - \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl + #2} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \prg_replicate:nn {2} + { + \tl_set:Nx \l__spath_shorten_path_tl {\tl_tail:N \l__spath_shorten_path_tl} + } - \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl + #3} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \tl_put_left:NV \l__spath_shorten_path_tl \l__spath_shorten_lastb_tl - \tl_put_right:Nx \l__spath_tmpb_tl - { - {\dim_use:N \l__spath_tmpa_dim} - {\dim_use:N \l__spath_tmpb_dim} - } - } - \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl + } + { + + \tl_put_left:NV \l__spath_shorten_path_tl \c_spath_moveto_tl + + \int_compare:nT + { + \tl_count:N \l__spath_shorten_path_tl > 3 + } + { + \dim_set:Nn \l__spath_tmpa_dim {\fp_to_dim:n {#2 - \l__spath_shorten_len_fp } } + \spath_shorten_at_start:NV \l__spath_shorten_path_tl \l__spath_tmpa_dim } } -} -\cs_generate_variant:Nn \spath_translate:nnn {nxx} -\cs_new_nopar:Npn \spath_translate:nn #1#2 + \tl_gset_eq:NN \g__spath_output_tl \l__spath_shorten_path_tl + \group_end: + } + { + \tl_gset:Nn \g__spath_output_tl {#1} + } +} +\cs_new_protected_nopar:Npn \spath_shorten_at_start:Nnn #1#2#3 { - \spath_translate:nnn {#1} #2 + \__spath_shorten_at_start:nn {#2}{#3} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl } - -\cs_generate_variant:Nn \spath_translate:nn {nV} -\cs_new_nopar:Npn \spath_scale:nnn #1#2#3 +\cs_generate_variant:Nn \spath_shorten_at_start:Nnn {NVV, cnn, cVV, NVn} +\cs_new_protected_nopar:Npn \spath_shorten_at_start:Nn #1#2 { - \tl_map_inline:Nn \g__spath_moveable_attributes + \spath_shorten_at_start:NVn #1#1{#2} +} +\cs_generate_variant:Nn \spath_shorten_at_start:Nn {cn, cV, NV} +\cs_new_protected_nopar:Npn \spath_gshorten_at_start:Nnn #1#2#3 +{ + \__spath_shorten_at_start:nn {#2}{#3} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gshorten_at_start:Nnn {NVV, cnn, cVV, NVn} +\cs_new_protected_nopar:Npn \spath_gshorten_at_start:Nn #1#2 +{ + \spath_gshorten_at_start:NVn #1#1{#2} +} +\cs_generate_variant:Nn \spath_gshorten_at_start:Nn {cn, cV, NV} +\cs_new_protected_nopar:Npn \__spath_point_at:nn #1#2 +{ + \group_begin: + \int_set:Nn \l__spath_tmpa_int {\fp_to_int:n {floor(#2) + 1}} + \fp_set:Nn \l__spath_tmpa_fp {#2 - floor(#2)} + + \spath_segments_to_seq:Nn \l__spath_tmpa_seq {#1} + + \int_compare:nTF + { + \l__spath_tmpa_int < 1 + } + { + \spath_initialpoint:Nn \l__spath_tmpc_tl {#1} + } { - \spath_if_in:nnT {#1} {##1} + \int_compare:nTF + { + \l__spath_tmpa_int > \seq_count:N \l__spath_tmpa_seq + } + { + \spath_finalpoint:Nn \l__spath_tmpc_tl {#1} + } { - \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl - \fp_set:Nn \l__spath_tmpa_fp {\tl_head:N \l__spath_tmpa_tl * #2} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \fp_set:Nn \l__spath_tmpb_fp {\tl_head:N \l__spath_tmpa_tl * #3} - \tl_clear:N \l__spath_tmpb_tl - \tl_put_right:Nx \l__spath_tmpb_tl + \tl_set:Nx \l__spath_tmpa_tl {\seq_item:Nn \l__spath_tmpa_seq { \l__spath_tmpa_int} } + + \int_compare:nTF { - {\fp_to_dim:N \l__spath_tmpa_fp} - {\fp_to_dim:N \l__spath_tmpb_fp} + \tl_count:N \l__spath_tmpa_tl > 3 } - \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl - } - } - \tl_map_inline:Nn \g__spath_path_attributes - { - \spath_if_in:nnT {#1} {##1} - { - \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl - \tl_clear:N \l__spath_tmpb_tl - \bool_until_do:nn { - \tl_if_empty_p:N \l__spath_tmpa_tl + { + \tl_set:Nx \l__spath_tmpb_tl {\tl_item:Nn \l__spath_tmpa_tl {4}} } { - \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpb_tl {\tl_item:Nn \l__spath_tmpa_tl {1}} + } + + \tl_clear:N \l__spath_tmpc_tl + + \tl_case:Nn \l__spath_tmpb_tl + { + \c_spath_moveto_tl + { + \tl_set:Nx \l__spath_tmpc_tl + { + { + \tl_item:Nn \l__spath_tmpa_tl {2} + } + { + \tl_item:Nn \l__spath_tmpa_tl {3} + } + } + } - \fp_set:Nn \l__spath_tmpa_fp {\tl_head:N \l__spath_tmpa_tl * #2} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \c_spath_lineto_tl + { + \tl_set:Nx \l__spath_tmpc_tl + { + {\fp_to_dim:n + { + (1 - \l__spath_tmpa_fp) * ( \tl_item:Nn \l__spath_tmpa_tl {2} ) + + + \l__spath_tmpa_fp * ( \tl_item:Nn \l__spath_tmpa_tl {5} ) + } + } + {\fp_to_dim:n + { + (1 - \l__spath_tmpa_fp) * ( \tl_item:Nn \l__spath_tmpa_tl {3} ) + + + \l__spath_tmpa_fp * ( \tl_item:Nn \l__spath_tmpa_tl {6} ) + } + } + } + } - \fp_set:Nn \l__spath_tmpb_fp {\tl_head:N \l__spath_tmpa_tl * #3} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \c_spath_closepath_tl + { + \tl_set:Nx \l__spath_tmpc_tl + { + {\fp_to_dim:n + { + (1 - \l__spath_tmpa_fp) * ( \tl_item:Nn \l__spath_tmpa_tl {2} ) + + + \l__spath_tmpa_fp * ( \tl_item:Nn \l__spath_tmpa_tl {5} ) + } + } + {\fp_to_dim:n + { + (1 - \l__spath_tmpa_fp) * ( \tl_item:Nn \l__spath_tmpa_tl {3} ) + + + \l__spath_tmpa_fp * ( \tl_item:Nn \l__spath_tmpa_tl {6} ) + } + } + } + } - \tl_put_right:Nx \l__spath_tmpb_tl + \c_spath_curvetoa_tl { - {\fp_to_dim:N \l__spath_tmpa_fp} - {\fp_to_dim:N \l__spath_tmpb_fp} + \tl_set:Nx \l__spath_tmpc_tl + { + {\fp_to_dim:n + { + (1 - \l__spath_tmpa_fp)^3 * \tl_item:Nn \l__spath_tmpa_tl {2} + 3 * (1 - \l__spath_tmpa_fp)^2 * (\l__spath_tmpa_fp) * \tl_item:Nn \l__spath_tmpa_tl {5} + 3 * (1 - \l__spath_tmpa_fp) * (\l__spath_tmpa_fp)^2 * \tl_item:Nn \l__spath_tmpa_tl {8} + (\l__spath_tmpa_fp)^3 * \tl_item:Nn \l__spath_tmpa_tl {11} + }} + {\fp_to_dim:n + { + (1 - \l__spath_tmpa_fp)^3 * \tl_item:Nn \l__spath_tmpa_tl {3} + 3 * (1 - \l__spath_tmpa_fp)^2 * (\l__spath_tmpa_fp) * \tl_item:Nn \l__spath_tmpa_tl {6} + 3 * (1 - \l__spath_tmpa_fp) * (\l__spath_tmpa_fp)^2 * \tl_item:Nn \l__spath_tmpa_tl {9} + (\l__spath_tmpa_fp)^3 * \tl_item:Nn \l__spath_tmpa_tl {12} + }} + } } } - \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl } } + + \tl_gclear:N \g__spath_output_tl + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpc_tl + \group_end: } -\cs_generate_variant:Nn \spath_scale:nnn {nxx} -\cs_new_nopar:Npn \spath_scale:nn #1#2 +\cs_new_protected_nopar:Npn \spath_point_at:Nnn #1#2#3 { - \spath_scale:nnn {#1} #2 + \__spath_point_at:nn {#2}{#3} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl } - -\cs_generate_variant:Nn \spath_scale:nn {nV} -\cs_new_nopar:Npn \spath_transform:nnnnnnn #1#2#3#4#5#6#7 +\cs_generate_variant:Nn \spath_point_at:Nnn {NVn, NVV, NnV} +\cs_new_protected_nopar:Npn \spath_gpoint_at:Nnn #1#2#3 +{ + \__spath_point_at:nn {#2}{#3} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gpoint_at:Nnn {NVn, NVV, NnV} +\cs_new_protected_nopar:Npn \__spath_tangent_at:nn #1#2 { - \tl_map_inline:Nn \g__spath_moveable_attributes + \group_begin: + \int_set:Nn \l__spath_tmpa_int {\fp_to_int:n {floor(#2) + 1}} + \fp_set:Nn \l__spath_tmpa_fp {#2 - floor(#2)} + + \spath_segments_to_seq:Nn \l__spath_tmpa_seq {#1} + + \int_compare:nTF { - \spath_if_in:nnT {#1} {##1} - { - \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpb_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_head:N \l__spath_tmpa_tl} - \fp_set:Nn \l__spath_tmpa_fp {\l__spath_tmpa_tl * #2 + \l__spath_tmpb_tl * #3 + #6} - \fp_set:Nn \l__spath_tmpb_fp {\l__spath_tmpa_tl * #4 + \l__spath_tmpb_tl * #5 + #7} - \tl_clear:N \l__spath_tmpb_tl - \tl_put_right:Nx \l__spath_tmpb_tl - { - {\fp_to_dim:N \l__spath_tmpa_fp} - {\fp_to_dim:N \l__spath_tmpb_fp} - } - \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl - } + \l__spath_tmpa_int < 1 + } + { + \spath_initialpoint:Nn \l__spath_tmpc_tl {#1} } - \tl_map_inline:Nn \g__spath_path_attributes { - \spath_if_in:nnT {#1} {##1} + \int_compare:nTF + { + \l__spath_tmpa_int > \seq_count:N \l__spath_tmpa_seq + } + { + \spath_finalpoint:Nn \l__spath_tmpc_tl {#1} + } { - \__spath_get:nnN {#1} {##1} \l__spath_tmpa_tl - \tl_clear:N \l__spath_tmpb_tl - \bool_until_do:nn { - \tl_if_empty_p:N \l__spath_tmpa_tl + + \tl_set:Nx \l__spath_tmpa_tl {\seq_item:Nn \l__spath_tmpa_seq { \l__spath_tmpa_int} } + + \int_compare:nTF + { + \tl_count:N \l__spath_tmpa_tl > 3 } { - \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_set:Nx \l_tmpa_tl {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_set:Nx \l_tmpb_tl {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpb_tl {\tl_item:Nn \l__spath_tmpa_tl {4}} + } + { + \tl_set:Nx \l__spath_tmpb_tl {\tl_item:Nn \l__spath_tmpa_tl {1}} + } + + \tl_clear:N \l__spath_tmpc_tl + + \tl_case:Nn \l__spath_tmpb_tl + { + \c_spath_moveto_tl + { + \tl_set:Nx \l__spath_tmpc_tl + { + { + \tl_item:Nn \l__spath_tmpa_tl {2} + } + { + \tl_item:Nn \l__spath_tmpa_tl {3} + } + } + } + + \c_spath_lineto_tl + { + \tl_set:Nx \l__spath_tmpc_tl + { + {\fp_to_dim:n + { + ( \tl_item:Nn \l__spath_tmpa_tl {5} ) + - + ( \tl_item:Nn \l__spath_tmpa_tl {2} ) + } + } + {\fp_to_dim:n + { + ( \tl_item:Nn \l__spath_tmpa_tl {6} ) + - + ( \tl_item:Nn \l__spath_tmpa_tl {3} ) + } + } + } + } + + \c_spath_closepath_tl + { + \tl_set:Nx \l__spath_tmpc_tl + { + {\fp_to_dim:n + { + ( \tl_item:Nn \l__spath_tmpa_tl {5} ) + - + ( \tl_item:Nn \l__spath_tmpa_tl {2} ) + } + } + {\fp_to_dim:n + { + ( \tl_item:Nn \l__spath_tmpa_tl {6} ) + - + ( \tl_item:Nn \l__spath_tmpa_tl {3} ) + } + } + } + } - \fp_set:Nn \l__spath_tmpa_fp {\l_tmpa_tl * #2 + \l_tmpb_tl * #3 + #6} - \fp_set:Nn \l__spath_tmpb_fp {\l_tmpa_tl * #4 + \l_tmpb_tl * #5 + #7} - \tl_put_right:Nx \l__spath_tmpb_tl + \c_spath_curvetoa_tl { - {\fp_to_dim:N \l__spath_tmpa_fp} - {\fp_to_dim:N \l__spath_tmpb_fp} + \tl_set:Nx \l__spath_tmpc_tl + { + {\fp_to_dim:n + { + 3*(1 - \l__spath_tmpa_fp)^2 * (\tl_item:Nn \l__spath_tmpa_tl {5} - \tl_item:Nn \l__spath_tmpa_tl {2}) + + 6 * (1 - \l__spath_tmpa_fp) * (\l__spath_tmpa_fp) * (\tl_item:Nn \l__spath_tmpa_tl {8} - \tl_item:Nn \l__spath_tmpa_tl {5}) + + 3*(\l__spath_tmpa_fp)^2 * (\tl_item:Nn \l__spath_tmpa_tl {11} - \tl_item:Nn \l__spath_tmpa_tl {8}) + } + } + {\fp_to_dim:n + { + 3*(1 - \l__spath_tmpa_fp)^2 * (\tl_item:Nn \l__spath_tmpa_tl {6} - \tl_item:Nn \l__spath_tmpa_tl {3}) + + 6 * (1 - \l__spath_tmpa_fp) * (\l__spath_tmpa_fp) * (\tl_item:Nn \l__spath_tmpa_tl {9} - \tl_item:Nn \l__spath_tmpa_tl {6}) + + 3*(\l__spath_tmpa_fp)^2 * (\tl_item:Nn \l__spath_tmpa_tl {12} - \tl_item:Nn \l__spath_tmpa_tl {9}) + }} + } } } - \spath_put:nnV {#1} {##1} \l__spath_tmpb_tl } } -} -\cs_generate_variant:Nn \spath_transform:nnnnnnn {nxxxxxx} -\cs_new_nopar:Npn \spath_transform:nn #1#2 -{ - \spath_transform:nnnnnnn {#1} #2 + \tl_gclear:N \g__spath_output_tl + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpc_tl + \group_end: } - -\cs_generate_variant:Nn \spath_transform:nn {nV} -\cs_new_nopar:Npn \spath_reverse:n #1 +\cs_new_protected_nopar:Npn \spath_tangent_at:Nnn #1#2#3 { - \spath_if_in:nnF {#1} {reverse path} { - \use:c {spath_generate_reverse path:n} {#1} - } - \spath_swap:nnn {#1} {path} {reverse path} - \spath_swap:nnn {#1} {initial point} {final point} - \spath_swap:nnn {#1} {initial action} {final action} + \__spath_tangent_at:nn {#2}{#3} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl } -\cs_new_nopar:Npn \spath_swap:nnn #1#2#3 +\cs_generate_variant:Nn \spath_tangent_at:Nnn {NVn, NVV, NnV} +\cs_new_protected_nopar:Npn \spath_gtangent_at:Nnn #1#2#3 { - \__spath_get:nnNF {#1} {#2} \l__spath_tmpa_tl {\tl_clear:N \l__spath_tmpa_tl} - \__spath_get:nnNF {#1} {#3} \l__spath_tmpb_tl {\tl_clear:N \l__spath_tmpb_tl} - \tl_if_empty:NTF \l__spath_tmpb_tl - {\spath_remove:nn {#1} {#2}} - {\spath_put:nnV {#1} {#2} \l__spath_tmpb_tl} - \tl_if_empty:NTF \l__spath_tmpa_tl - {\spath_remove:nn {#1} {#3}} - {\spath_put:nnV {#1} {#3} \l__spath_tmpa_tl} + \__spath_tangent_at:nn {#2}{#3} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl } -\cs_new_nopar:Npn \spath_weld:nn #1#2 +\cs_generate_variant:Nn \spath_gtangent_at:Nnn {NVn, NVV, NnV} +\cs_new_protected_nopar:Npn \__spath_transformation_at:nn #1#2 { - \spath_clone:nn {#2} {tmp_path} - \spath_get:nnN {#1} {final point} \l__spath_tmpa_tl - - \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl} - - \spath_get:nnN {#2} {initial point} \l__spath_tmpa_tl - - \dim_sub:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \dim_sub:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl} - - \spath_translate:nxx {tmp_path} {\dim_use:N \l__spath_tmpa_dim} {\dim_use:N \l__spath_tmpb_dim} - - \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl - \__spath_get:nnN {tmp_path} {path} \l__spath_tmpb_tl - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl - - \spath_put:nnV {#1} {path} \l__spath_tmpa_tl - - \__spath_get:nnNTF {tmp_path} {final point} \l__spath_tmpa_tl - { - \spath_put:nnV {#1} {final point} \l__spath_tmpa_tl - } - { - \spath_remove:nn {#1} {final point} - } - - \__spath_get:nnNTF {tmp_path} {final action} \l__spath_tmpa_tl + \group_begin: + \tl_clear:N \l__spath_tmpa_tl + \__spath_tangent_at:nn {#1}{#2} + \tl_set_eq:NN \l__spath_tmpb_tl \g__spath_output_tl + \fp_set:Nn \l__spath_tmpa_fp { sqrt( (\tl_item:Nn \l__spath_tmpb_tl {1})^2 + (\tl_item:Nn \l__spath_tmpb_tl {2})^2 ) } + \fp_compare:nTF {\l__spath_tmpa_fp = 0} { - \spath_put:nnV {#1} {final action} \l__spath_tmpa_tl + \fp_set:Nn \l__spath_tmpa_fp {1} + \fp_set:Nn \l__spath_tmpb_fp {0} } { - \spath_remove:nn {#1} {final action} + \fp_set:Nn \l__spath_tmpb_fp { (\tl_item:Nn \l__spath_tmpb_tl {2}) / \l__spath_tmpa_fp } + \fp_set:Nn \l__spath_tmpa_fp { (\tl_item:Nn \l__spath_tmpb_tl {1}) / \l__spath_tmpa_fp } } - - \__spath_get:nnNT {tmp_path} {min bb} \l__spath_tmpa_tl + \tl_set:Nx \l__spath_tmpa_tl { - \__spath_get:nnNT {#1} {min bb} \l__spath_tmpb_tl - { - \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl} - - \dim_set:Nn \l__spath_tmpa_dim {\dim_min:nn {\l__spath_tmpa_dim} {\tl_head:N \l__spath_tmpb_tl}} - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \dim_set:Nn \l__spath_tmpb_dim {\dim_min:nn {\l__spath_tmpb_dim} {\tl_head:N \l__spath_tmpb_tl}} - - \tl_clear:N \l__spath_tmpb_tl - \tl_put_right:Nx \l__spath_tmpb_tl - { - {\dim_use:N \l__spath_tmpa_dim} - {\dim_use:N \l__spath_tmpb_dim} - } - \spath_put:nnV {#1} {min bb} \l__spath_tmpb_tl - } + { \fp_to_decimal:n { \l__spath_tmpa_fp } } + { \fp_to_decimal:n { \l__spath_tmpb_fp } } + { \fp_to_decimal:n {- \l__spath_tmpb_fp } } + { \fp_to_decimal:n { \l__spath_tmpa_fp } } + } + \__spath_point_at:nn {#1}{#2} + \tl_put_right:NV \l__spath_tmpa_tl \g__spath_output_tl + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_transformation_at:Nnn #1#2#3 +{ + \__spath_transformation_at:nn {#2}{#3} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_transformation_at:Nnn {NVn, NVV, NnV, NvV} +\cs_new_protected_nopar:Npn \spath_gtransformation_at:Nnn #1#2#3 +{ + \__spath_transformation_at:nn {#2}{#3} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_generate_variant:Nn \spath_gtransformation_at:Nnn {NVn, NVV, NnV} +\tl_new:N \l__spath_split_path_a_tl +\tl_new:N \l__spath_split_path_b_tl +\tl_new:N \l__spath_split_path_a_start_tl +\tl_new:N \l__spath_split_path_b_start_tl +\tl_new:N \l__spath_split_path_a_end_tl +\tl_new:N \l__spath_split_path_b_end_tl +\tl_new:N \l__spath_split_path_a_final_tl +\tl_new:N \l__spath_split_path_b_final_tl + +\tl_new:N \l__spath_split_prev_first_tl +\tl_new:N \l__spath_split_prev_second_tl + +\seq_new:N \l__spath_split_first_seq +\seq_new:N \l__spath_split_second_seq + +\int_new:N \l__spath_split_segment_int +\cs_new_protected_nopar:Npn \spath_intersect:NN #1#2 +{ + \pgfintersectionofpaths% + {% + \pgfsetpath #1 + }{% + \pgfsetpath #2 } +} +\tl_new:N \l__spath_intersecta_tl +\tl_new:N \l__spath_intersectb_tl +\cs_new_protected_nopar:Npn \spath_intersect:nn #1#2 +{ + \tl_set:Nn \l__spath_intersecta_tl {#1} + \tl_set:Nn \l__spath_intersectb_tl {#2} + \spath_intersect:NN \l__spath_intersecta_tl \l__spath_intersectb_tl +} +\cs_new_protected_nopar:Npn \__spath_split_at_intersections:nn #1#2 +{ + \group_begin: - \__spath_get:nnNT {tmp_path} {max bb} \l__spath_tmpa_tl - { - \__spath_get:nnNT {#1} {max bb} \l__spath_tmpb_tl - { - \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl} + % Clear some token lists and sequences + \tl_clear:N \l__spath_split_path_a_final_tl + \tl_clear:N \l__spath_split_path_b_final_tl + \seq_clear:N \l__spath_split_first_seq + \seq_clear:N \l__spath_split_second_seq - \dim_set:Nn \l__spath_tmpa_dim {\dim_max:nn {\l__spath_tmpa_dim} {\tl_head:N \l__spath_tmpb_tl}} - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \dim_set:Nn \l__spath_tmpb_dim {\dim_max:nn {\l__spath_tmpb_dim} {\tl_head:N \l__spath_tmpb_tl}} + \pgfintersectionsortbyfirstpath + % Find the intersections of these segments + \tl_set:Nn \l__spath_split_path_a_tl {#1} + \tl_set:Nn \l__spath_split_path_b_tl {#2} + % Remove empty components - \tl_clear:N \l__spath_tmpb_tl - \tl_put_right:Nx \l__spath_tmpb_tl - { - {\dim_use:N \l__spath_tmpa_dim} - {\dim_use:N \l__spath_tmpb_dim} - } - \spath_put:nnV {#1} {max bb} \l__spath_tmpb_tl - } - } + \spath_intersect:NN \l__spath_split_path_a_tl \l__spath_split_path_b_tl - \__spath_get:nnNT {tmp_path} {reverse path} \l__spath_tmpa_tl + % If we get intersections + \int_compare:nT {\pgfintersectionsolutions > 0} { - \__spath_get:nnNT {#1} {reverse path} \l__spath_tmpb_tl + % Find the times of the intersections on each path + \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions} { - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl - - \spath_put:nnV {#1} {reverse path} \l__spath_tmpa_tl + \pgfintersectiongetsolutiontimes{##1}{\l__spath_split_first_tl}{\l__spath_split_second_tl} + \seq_put_left:NV \l__spath_split_first_seq \l__spath_split_first_tl } } - \__spath_get:nnNT {tmp_path} {length} \l__spath_tmpa_tl - { - \__spath_get:nnNT {#1} {length} \l__spath_tmpb_tl - { - \int_set:Nn \l__spath_tmpa_int {\l__spath_tmpa_tl + \l__spath_tmpb_tl - 1} - \spath_put:nnV {#1} {length} \l__spath_tmpa_int - } - } + \spath_intersect:NN \l__spath_split_path_b_tl \l__spath_split_path_a_tl - \__spath_get:nnNT {tmp_path} {real length} \l__spath_tmpa_tl + % If we get intersections + \int_compare:nT {\pgfintersectionsolutions > 0} { - \__spath_get:nnNT {#1} {real length} \l__spath_tmpb_tl + % Find the times of the intersections on each path + \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions} { - \int_set:Nn \l__spath_tmpa_int {\l__spath_tmpa_tl + \l__spath_tmpb_tl} - \spath_put:nnV {#1} {real length} \l__spath_tmpa_int + \pgfintersectiongetsolutiontimes{##1}{\l__spath_split_first_tl}{\l__spath_split_second_tl} + \seq_put_left:NV \l__spath_split_second_seq \l__spath_split_first_tl } } - \__spath_get:nnNT {tmp_path} {number of components} \l__spath_tmpa_tl - { - \__spath_get:nnNT {#1} {number of components} \l__spath_tmpb_tl - { - \int_set:Nn \l__spath_tmpa_int {\l__spath_tmpa_tl + \l__spath_tmpb_tl - 1} - \spath_put:nnV {#1} {number of components} \l__spath_tmpa_int - } - } + \tl_set:Nn \l__spath_split_prev_first_tl {-1} -} -\cs_new_nopar:Npn \spath_prepend_no_move:nn #1#2 -{ - \spath_if_exist:nT {#2} + \seq_map_inline:Nn \l__spath_split_first_seq { - \__spath_get:nnN {#2} {path} \l__spath_tmpa_tl - \__spath_get:nnN {#1} {path} \l__spath_tmpb_tl - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl - \spath_put:nnV {#1} {path} \l__spath_tmpa_tl + \tl_set:Nn \l__spath_split_first_tl {##1} - \spath_if_in:nnTF {#2} {initial point} + \tl_set_eq:NN \l__spath_tmpa_tl \l__spath_split_first_tl + \int_compare:nT { - \__spath_get:nnN {#2} {initial point} \l__spath_tmpa_tl - \spath_put:nnV {#1} {initial point} \l__spath_tmpa_tl + \fp_to_int:n {floor( \l__spath_split_first_tl) } + = + \fp_to_int:n {floor( \l__spath_split_prev_first_tl) } } { - \spath_remove:nn {#1} {initial point} + \tl_set:Nx \l__spath_split_first_tl + { + \fp_eval:n { + floor( \l__spath_split_first_tl ) + + + ( \l__spath_split_first_tl - floor( \l__spath_split_first_tl) ) + / + ( \l__spath_split_prev_first_tl - floor( \l__spath_split_prev_first_tl) ) + } + } } + \tl_set_eq:NN \l__spath_split_prev_first_tl \l__spath_tmpa_tl - \spath_if_in:nnTF {#2} {initial action} - { - \__spath_get:nnN {#2} {initial action} \l__spath_tmpa_tl - \spath_put:nnV {#1} {initial action} \l__spath_tmpa_tl - } - { - \spath_remove:nn {#1} {initial action} - } + \spath_split_at:NNVV \l__spath_split_path_a_start_tl \l__spath_split_path_a_end_tl \l__spath_split_path_a_tl \l__spath_split_first_tl - \bool_if:nTF - { - \spath_if_in_p:nn {#1} {length} - && - \spath_if_in_p:nn {#2} {length} - } - { - \__spath_get:nnN {#1} {length} \l__spath_tmpa_tl - \__spath_get:nnN {#2} {length} \l__spath_tmpb_tl - \spath_put:nnx {#1} {length} {\int_eval:n {\l__spath_tmpa_tl + - \l__spath_tmpb_tl - 1}} - } - { - \spath_remove:nn {#1} {length} - } - \bool_if:nTF - { - \spath_if_in_p:nn {#1} {real length} - && - \spath_if_in_p:nn {#2} {real length} - } - { - \__spath_get:nnN {#1} {real length} \l__spath_tmpa_tl - \__spath_get:nnN {#2} {real length} \l__spath_tmpb_tl - \spath_put:nnx {#1} {real length} {\int_eval:n {\l__spath_tmpa_tl + - \l__spath_tmpb_tl }} - } - { - \spath_remove:nn {#1} {real length} - } - \bool_if:nTF - { - \spath_if_in_p:nn {#1} {number of components} - && - \spath_if_in_p:nn {#2} {number of components} - } - { - \__spath_get:nnN {#1} {number of components} \l__spath_tmpa_tl - \__spath_get:nnN {#2} {number of components} \l__spath_tmpb_tl - \spath_put:nnx {#1} {number of components} {\int_eval:n {\l__spath_tmpa_tl + - \l__spath_tmpb_tl - 1}} - } - { - \spath_remove:nn {#1} {number of components} - } - \bool_if:nTF - { - \spath_if_in_p:nn {#1} {min bb} - && - \spath_if_in_p:nn {#2} {min bb} - } - { - \__spath_get:nnN {#1} {min bb} \l__spath_tmpa_tl - \__spath_get:nnN {#2} {min bb} \l__spath_tmpb_tl - \dim_set:Nn \l__spath_tmpa_dim {\dim_min:nn {\tl_item:Nn - \l__spath_tmpa_tl {1}} {\tl_item:Nn - \l__spath_tmpb_tl {1}}} - \dim_set:Nn \l__spath_tmpb_dim {\dim_min:nn {\tl_item:Nn - \l__spath_tmpa_tl {2}} {\tl_item:Nn - \l__spath_tmpb_tl {2}}} - \spath_put:nnx {#1} {min bb} { - {\dim_use:N \l__spath_tmpa_dim} - {\dim_use:N \l__spath_tmpb_dim} - } - } - { - \spath_remove:nn {#1} {min bb} - } - \bool_if:nTF - { - \spath_if_in_p:nn {#1} {max bb} - && - \spath_if_in_p:nn {#2} {max bb} - } - { - \__spath_get:nnN {#1} {max bb} \l__spath_tmpa_tl - \__spath_get:nnN {#2} {max bb} \l__spath_tmpb_tl - \dim_set:Nn \l__spath_tmpa_dim {\dim_min:nn {\tl_item:Nn - \l__spath_tmpa_tl {1}} {\tl_item:Nn - \l__spath_tmpb_tl {1}}} - \dim_set:Nn \l__spath_tmpb_dim {\dim_min:nn {\tl_item:Nn - \l__spath_tmpa_tl {2}} {\tl_item:Nn - \l__spath_tmpb_tl {2}}} - \spath_put:nnx {#1} {max bb} { - {\dim_use:N \l__spath_tmpa_dim} - {\dim_use:N \l__spath_tmpb_dim} - } - } - { - \spath_remove:nn {#1} {max bb} - } - \bool_if:nTF - { - \spath_if_in_p:nn {#1} {reverse path} - && - \spath_if_in_p:nn {#2} {reverse path} - } - { - \__spath_get:nnN {#1} {reverse path} \l__spath_tmpa_tl - \__spath_get:nnN {#2} {reverse path} \l__spath_tmpb_tl - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl - \spath_put:nnV {#1} {reverse path} \l__spath_tmpb_tl - } - { - \spath_remove:nn {#1} {reverse path} - } + \tl_put_left:NV \l__spath_split_path_a_final_tl \l__spath_split_path_a_end_tl + \tl_set_eq:NN \l__spath_split_path_a_tl \l__spath_split_path_a_start_tl } -} -\cs_new_nopar:Npn \spath_append_no_move:nn #1#2 -{ - \spath_if_exist:nT {#2} + + \tl_set:Nn \l__spath_split_prev_second_tl {-1} + + \seq_map_inline:Nn \l__spath_split_second_seq { - \spath_get:nnN {#1} {path} \l__spath_tmpa_tl - \spath_get:nnN {#2} {path} \l__spath_tmpb_tl - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl - \spath_put:nnV {#1} {path} \l__spath_tmpa_tl - \spath_if_in:nnTF {#2} {final point} - { - \__spath_get:nnN {#2} {final point} \l__spath_tmpa_tl - \spath_put:nnV {#1} {final point} \l__spath_tmpa_tl - } - { - \spath_remove:nn {#1} {final point} - } - \spath_if_in:nnTF {#2} {final action} - { - \__spath_get:nnN {#2} {final action} \l__spath_tmpa_tl - \spath_put:nnV {#1} {final action} \l__spath_tmpa_tl - } - { - \spath_remove:nn {#1} {final action} - } - \bool_if:nTF - { - \spath_if_in_p:nn {#1} {length} - && - \spath_if_in_p:nn {#2} {length} - } - { - \__spath_get:nnN {#1} {length} \l__spath_tmpa_tl - \__spath_get:nnN {#2} {length} \l__spath_tmpb_tl - \spath_put:nnx {#1} {length} {\int_eval:n {\l__spath_tmpa_tl + - \l__spath_tmpb_tl - 1}} - } - { - \spath_remove:nn {#1} {length} - } - \bool_if:nTF - { - \spath_if_in_p:nn {#1} {real length} - && - \spath_if_in_p:nn {#2} {real length} - } - { - \__spath_get:nnN {#1} {real length} \l__spath_tmpa_tl - \__spath_get:nnN {#2} {real length} \l__spath_tmpb_tl - \spath_put:nnx {#1} {real length} {\int_eval:n {\l__spath_tmpa_tl + - \l__spath_tmpb_tl }} - } - { - \spath_remove:nn {#1} {real length} - } - \bool_if:nTF - { - \spath_if_in_p:nn {#1} {number of components} - && - \spath_if_in_p:nn {#2} {number of components} - } - { - \__spath_get:nnN {#1} {number of components} \l__spath_tmpa_tl - \__spath_get:nnN {#2} {number of components} \l__spath_tmpb_tl - \spath_put:nnx {#1} {number of components} {\int_eval:n {\l__spath_tmpa_tl + - \l__spath_tmpb_tl - 1}} - } - { - \spath_remove:nn {#1} {number of components} - } - \bool_if:nTF - { - \spath_if_in_p:nn {#1} {min bb} - && - \spath_if_in_p:nn {#2} {min bb} - } - { - \__spath_get:nnN {#1} {min bb} \l__spath_tmpa_tl - \__spath_get:nnN {#2} {min bb} \l__spath_tmpb_tl - \dim_set:Nn \l__spath_tmpa_dim {\dim_min:nn {\tl_item:Nn - \l__spath_tmpa_tl {1}} {\tl_item:Nn - \l__spath_tmpb_tl {1}}} - \dim_set:Nn \l__spath_tmpb_dim {\dim_min:nn {\tl_item:Nn - \l__spath_tmpa_tl {2}} {\tl_item:Nn - \l__spath_tmpb_tl {2}}} - \spath_put:nnx {#1} {min bb} { - {\dim_use:N \l__spath_tmpa_dim} - {\dim_use:N \l__spath_tmpb_dim} - } - } + \tl_set:Nn \l__spath_split_second_tl {##1} + + \tl_set_eq:NN \l__spath_tmpa_tl \l__spath_split_second_tl + \int_compare:nT { - \spath_remove:nn {#1} {min bb} + \fp_to_int:n {floor( \l__spath_split_second_tl) } + = + \fp_to_int:n {floor( \l__spath_split_prev_second_tl) } } - \bool_if:nTF { - \spath_if_in_p:nn {#1} {max bb} - && - \spath_if_in_p:nn {#2} {max bb} - } - { - \__spath_get:nnN {#1} {max bb} \l__spath_tmpa_tl - \__spath_get:nnN {#2} {max bb} \l__spath_tmpb_tl - \dim_set:Nn \l__spath_tmpa_dim {\dim_min:nn {\tl_item:Nn - \l__spath_tmpa_tl {1}} {\tl_item:Nn - \l__spath_tmpb_tl {1}}} - \dim_set:Nn \l__spath_tmpb_dim {\dim_min:nn {\tl_item:Nn - \l__spath_tmpa_tl {2}} {\tl_item:Nn - \l__spath_tmpb_tl {2}}} - \spath_put:nnx {#1} {max bb} { - {\dim_use:N \l__spath_tmpa_dim} - {\dim_use:N \l__spath_tmpb_dim} + \tl_set:Nx \l__spath_split_second_tl + { + \fp_eval:n { + floor( \l__spath_split_second_tl ) + + + ( \l__spath_split_second_tl - floor( \l__spath_split_second_tl) ) + / + ( \l__spath_split_prev_second_tl - floor( \l__spath_split_prev_second_tl) ) + } } } - { - \spath_remove:nn {#1} {max bb} - } - \bool_if:nTF - { - \spath_if_in_p:nn {#1} {reverse path} - && - \spath_if_in_p:nn {#2} {reverse path} - } - { - \__spath_get:nnN {#2} {reverse path} \l__spath_tmpa_tl - \__spath_get:nnN {#1} {reverse path} \l__spath_tmpb_tl - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} - \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl - \spath_put:nnV {#1} {reverse path} \l__spath_tmpb_tl - } - { - \spath_remove:nn {#1} {reverse path} - } + \tl_set_eq:NN \l__spath_split_prev_second_tl \l__spath_tmpa_tl + + \spath_split_at:NNVV \l__spath_split_path_b_start_tl \l__spath_split_path_b_end_tl \l__spath_split_path_b_tl\l__spath_split_second_tl + + \tl_put_left:NV \l__spath_split_path_b_final_tl \l__spath_split_path_b_end_tl + \tl_set_eq:NN \l__spath_split_path_b_tl \l__spath_split_path_b_start_tl + } -} -\cs_new_nopar:Npn \spath_bake_round:n #1 -{ - \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl - \pgf@@processround\l__spath_tmpa_tl\l__spath_tmpb_tl - \spath_put:nnV {#1} {path} \l__spath_tmpb_tl -} -\cs_new_nopar:Npn \spath_close_path:n #1 -{ - \spath_get:nnN {#1} {initial point} \l__spath_tmpb_tl - \__spath_get:nnN {#1} {path} \l__spath_tmpa_tl - \tl_put_right:NV \l__spath_tmpa_tl \g__spath_closepath_tl - \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl - \spath_put:nnV {#1} {path} \l__spath_tmpa_tl - \spath_if_in:nnT {#1} {reverse path} + + \tl_put_left:NV \l__spath_split_path_a_final_tl \l__spath_split_path_a_tl + \tl_put_left:NV \l__spath_split_path_b_final_tl \l__spath_split_path_b_tl + + \tl_if_empty:NT \l__spath_split_path_a_final_tl { - \spath_get:nnN {#1} {final point} \l__spath_tmpb_tl - \__spath_get:nnN {#1} {reverse path} \l__spath_tmpa_tl - \tl_put_right:NV \l__spath_tmpa_tl \g__spath_closepath_tl - \tl_put_right:NV \l__spath_tmpa_tl \l__spath_tmpb_tl - \spath_put:nnV {#1} {reverse path} \l__spath_tmpa_tl - } -} -\cs_new_nopar:Npn \spath_map_component:Nn #1#2 -{ - \int_gincr:N \g__spath_map_int - \cs_gset:cpn { __spath_map_ \int_use:N \g__spath_map_int :w } ##1 {#2} - \tl_set:NV \l__spath_tmpa_tl #1 - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_put_right:NV \l__spath_tmpa_tl \g__spath_moveto_tl - \tl_set_eq:NN \l__spath_tmpb_tl \g__spath_moveto_tl - \bool_until_do:nn { - \tl_if_empty_p:N \l__spath_tmpa_tl + \tl_set_eq:NN \l__spath_split_path_a_final_tl \l__spath_split_path_a_tl } + \tl_if_empty:NT \l__spath_split_path_b_final_tl { - \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl} - \tl_if_eq:NNT \l__spath_tmpc_tl \g__spath_moveto_tl - { - \exp_args:NnV \use:c { __spath_map_ \int_use:N \g__spath_map_int :w } \l__spath_tmpb_tl -\tl_clear:N \l__spath_tmpb_tl - } - \tl_if_single:NTF \l__spath_tmpc_tl - { - \tl_put_right:NV \l__spath_tmpb_tl \l__spath_tmpc_tl - } - { - \tl_put_right:Nx \l__spath_tmpb_tl {{\l__spath_tmpc_tl}} - } - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \tl_set_eq:NN \l__spath_split_path_b_final_tl \l__spath_split_path_b_tl } + + \spath_remove_empty_components:N \l__spath_split_path_a_final_tl + \spath_remove_empty_components:N \l__spath_split_path_b_final_tl + + \tl_gclear:N \g__spath_output_tl + \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_split_path_a_final_tl + \__spath_tl_gput_right_braced:NV \g__spath_output_tl \l__spath_split_path_b_final_tl + \group_end: } -\cs_new_nopar:Npn \spath_map_segment_inline:Nn #1#2 +\cs_new_protected_nopar:Npn \spath_split_at_intersections:NNnn #1#2#3#4 { - \int_gincr:N \g__spath_map_int - \cs_gset:cpn { __spath_map_ \int_use:N \g__spath_map_int :w } ##1 ##2 {#2} - \spath_map_segment_function:Nc #1 { __spath_map_ \int_use:N \g__spath_map_int :w } + \__spath_split_at_intersections:nn {#3}{#4} + \tl_set:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}} + \tl_set:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}} + \tl_gclear:N \g__spath_output_tl } -\cs_new_nopar:Npn \spath_map_segment_inline:nn #1#2 +\cs_generate_variant:Nn \spath_split_at_intersections:NNnn {NNVV, ccVV, ccvv} +\cs_new_protected_nopar:Npn \spath_split_at_intersections:NN #1#2 { - \int_gincr:N \g__spath_map_int - \cs_gset:cpn { __spath_map_ \int_use:N \g__spath_map_int :w } ##1 ##2 {#2} - \spath_get:nnN {#1} {path} \l__spath_tmpd_tl - \spath_map_segment_function:Nc \l__spath_tmpd_tl { __spath_map_ \int_use:N \g__spath_map_int :w } + \spath_split_at_intersections:NNVV #1#2#1#2 } -\cs_new_nopar:Npn \spath_map_segment_function:nN #1#2 +\cs_generate_variant:Nn \spath_split_at_intersections:NN {cc} +\cs_new_protected_nopar:Npn \spath_gsplit_at_intersections:NNnn #1#2#3#4 { - \spath_get:nnN {#1} {path} \l__spath_tmpd_tl - \spath_map_segment_function:NN \l__spath_tmpd_tl #2 + \__spath_split_at_intersections:nn {#3}{#4} + \tl_gset:Nx #1 {\tl_item:Nn \g__spath_output_tl {1}} + \tl_gset:Nx #2 {\tl_item:Nn \g__spath_output_tl {2}} + \tl_gclear:N \g__spath_output_tl } -\cs_new_nopar:Npn \spath_map_segment_function:NN #1#2 +\cs_generate_variant:Nn \spath_gsplit_at_intersections:NNnn {NNVV, ccVV, ccvv} +\cs_new_protected_nopar:Npn \spath_gsplit_at_intersections:NN #1#2 { - \tl_set_eq:NN \l__spath_tmpa_tl #1 - \tl_clear:N \l__spath_tmpb_tl - \dim_zero:N \l__spath_tmpa_dim - \dim_zero:N \l__spath_tmpb_dim + \spath_gsplit_at_intersections:NNVV #1#2#1#2 +} +\cs_generate_variant:Nn \spath_gsplit_at_intersections:NN {cc} +\cs_new_protected_nopar:Npn \__spath_split_at_self_intersections:n #1 +{ + \group_begin: - \bool_until_do:nn { - \tl_if_empty_p:N \l__spath_tmpa_tl + % Copy the path + \tl_set:Nn \l__spath_split_path_b_tl {#1} + + % Open the path + \spath_open:N \l__spath_split_path_b_tl + % Remove empty components + \spath_remove_empty_components:N \l__spath_split_path_b_tl + % Make a copy for later + \tl_set_eq:NN \l__spath_split_path_b_final_tl \l__spath_split_path_b_tl + + % Clear some token lists and sequences + \tl_clear:N \l__spath_split_path_a_tl + \seq_clear:N \l__spath_split_first_seq + \int_zero:N \l__spath_split_segment_int + + \pgfintersectionsortbyfirstpath + + \bool_do_until:nn + { + \int_compare_p:n + { + \tl_count:N \l__spath_split_path_b_tl < 4 + } } { - \tl_set:Nx \l__spath_tmpc_tl {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_case:NnF \l__spath_tmpc_tl + \tl_clear:N \l__spath_split_path_a_tl + \tl_put_right:Nx \l__spath_split_path_a_tl { - \g__spath_lineto_tl - { - \tl_set_eq:NN \l__spath_tmpb_tl \g__spath_moveto_tl - \tl_put_right:Nx \l__spath_tmpb_tl - { - {\dim_use:N \l__spath_tmpa_dim} - {\dim_use:N \l__spath_tmpb_dim} - } - \tl_put_right:NV \l__spath_tmpb_tl \g__spath_lineto_tl + \tl_item:Nn \l__spath_split_path_b_tl {1} + {\tl_item:Nn \l__spath_split_path_b_tl {2}} + {\tl_item:Nn \l__spath_split_path_b_tl {3}} + } - \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}} - \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_tmpa_tl { \tl_item:Nn \l__spath_split_path_b_tl {4} } - \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}} - \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \tl_set:Nx \l__spath_split_path_b_tl {\tl_tail:N \l__spath_split_path_b_tl} + + \int_zero:N \l__spath_tmpa_int + \tl_case:Nn \l__spath_tmpa_tl + { + \c_spath_moveto_tl + { + \tl_clear:N \l__spath_split_path_a_tl + \tl_set:Nx \l__spath_split_path_b_tl {\tl_tail:N \l__spath_split_path_b_tl} + \tl_set:Nx \l__spath_split_path_b_tl {\tl_tail:N \l__spath_split_path_b_tl} + \tl_set:Nx \l__spath_split_path_b_tl {\tl_tail:N \l__spath_split_path_b_tl} + } + \c_spath_lineto_tl + { + \int_set:Nn \l__spath_tmpa_int {1} + } + \c_spath_curvetoa_tl + { + \int_set:Nn \l__spath_tmpa_int {3} } + } + + \prg_replicate:nn { \l__spath_tmpa_int } + { + \tl_set:Nx \l__spath_split_path_b_tl {\tl_tail:N \l__spath_split_path_b_tl} + \tl_set:Nx \l__spath_split_path_b_tl {\tl_tail:N \l__spath_split_path_b_tl} - \g__spath_curvetoa_tl + \tl_put_right:Nx \l__spath_split_path_a_tl { - \tl_set_eq:NN \l__spath_tmpb_tl \g__spath_moveto_tl - \tl_put_right:Nx \l__spath_tmpb_tl - { - {\dim_use:N \l__spath_tmpa_dim} - {\dim_use:N \l__spath_tmpb_dim} - } - \tl_put_right:NV \l__spath_tmpb_tl \g__spath_curvetoa_tl + \tl_item:Nn \l__spath_split_path_b_tl {1} + {\tl_item:Nn \l__spath_split_path_b_tl {2}} + {\tl_item:Nn \l__spath_split_path_b_tl {3}} + } - \prg_replicate:nn {2} { - \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - \tl_put_right:Nx \l__spath_tmpb_tl {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} - } + \tl_set:Nx \l__spath_split_path_b_tl {\tl_tail:N \l__spath_split_path_b_tl} + } - \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}} - \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \tl_put_left:NV \l__spath_split_path_b_tl \c_spath_moveto_tl - \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}} - \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \tl_if_empty:NF \l__spath_split_path_a_tl + { + % Intersect the current segment with the rest of the path + \spath_intersect:NN \l__spath_split_path_a_tl \l__spath_split_path_b_tl + % If we get intersections + \int_compare:nT {\pgfintersectionsolutions > 0} + { + % Find the times of the intersections on each path + \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions} + { + \pgfintersectiongetsolutiontimes{##1}{\l__spath_split_first_tl}{\l__spath_split_second_tl} + \fp_compare:nT + { + \l__spath_split_first_tl < .99 + } + { + \tl_set:Nx \l__spath_tmpa_tl {\fp_to_decimal:n {\l__spath_split_first_tl + \l__spath_split_segment_int}} + \seq_put_right:NV \l__spath_split_first_seq \l__spath_tmpa_tl + } + } } - \g__spath_closepath_tl + \spath_intersect:NN \l__spath_split_path_b_tl \l__spath_split_path_a_tl + + % If we get intersections + \int_compare:nT {\pgfintersectionsolutions > 0} { - \tl_set_eq:NN \l__spath_tmpb_tl \g__spath_moveto_tl - \tl_put_right:Nx \l__spath_tmpb_tl + % Find the times of the intersections on each path + \int_step_inline:nnnn {1} {1} {\pgfintersectionsolutions} { - {\dim_use:N \l__spath_tmpa_dim} - {\dim_use:N \l__spath_tmpb_dim} + \pgfintersectiongetsolutiontimes{##1}{\l__spath_split_first_tl}{\l__spath_split_second_tl} + \fp_compare:nT + { + \l__spath_split_first_tl > .01 + } + { + \tl_set:Nx \l__spath_tmpa_tl {\fp_to_decimal:n {\l__spath_split_first_tl + \l__spath_split_segment_int + 1}} + \seq_put_right:NV \l__spath_split_first_seq \l__spath_tmpa_tl + } } - \tl_put_right:NV \l__spath_tmpb_tl \g__spath_lineto_tl + } - \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}} - \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + } + % Increment the segment counter + \int_incr:N \l__spath_split_segment_int + } - \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}} - \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + % Sort the sequence by reverse order along the path + \seq_sort:Nn \l__spath_split_first_seq + { + \fp_compare:nNnTF { ##1 } < { ##2 } + { \sort_return_swapped: } + { \sort_return_same: } + } - } + % Restore the original copy of the path + \tl_set_eq:NN \l__spath_split_path_b_tl \l__spath_split_path_b_final_tl + % Clear the token lists + \tl_clear:N \l__spath_split_path_b_start_tl + \tl_clear:N \l__spath_split_path_b_end_tl + \tl_clear:N \l__spath_split_path_b_final_tl + + \tl_set:Nn \l__spath_split_prev_first_tl {-1} + + \seq_map_inline:Nn \l__spath_split_first_seq + { + \tl_set:Nn \l__spath_split_first_tl {##1} + \tl_set_eq:NN \l__spath_tmpa_tl \l__spath_split_first_tl + \int_compare:nT + { + \fp_to_int:n {floor( \l__spath_split_first_tl ) } + = + \fp_to_int:n {floor( \l__spath_split_prev_first_tl) } } { + \tl_set:Nx \l__spath_split_first_tl + { + \fp_eval:n { + floor( \l__spath_split_first_tl ) + + + ( \l__spath_split_first_tl - floor( \l__spath_split_first_tl) ) + / + ( \l__spath_split_prev_first_tl - floor( \l__spath_split_prev_first_tl) ) + } + } + } + \tl_set_eq:NN \l__spath_split_prev_first_tl \l__spath_tmpa_tl - \tl_set_eq:NN \l__spath_tmpb_tl \l__spath_tmpc_tl - \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}} - \dim_set:Nn \l__spath_tmpa_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \spath_split_at:NNVV \l__spath_split_path_b_start_tl \l__spath_split_path_b_end_tl \l__spath_split_path_b_tl \l__spath_split_first_tl - \tl_put_right:Nx \l__spath_tmpb_tl {{\tl_head:N \l__spath_tmpa_tl}} - \dim_set:Nn \l__spath_tmpb_dim {\tl_head:N \l__spath_tmpa_tl} - \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + \tl_put_left:NV \l__spath_split_path_b_final_tl \l__spath_split_path_b_end_tl + \tl_set_eq:NN \l__spath_split_path_b_tl \l__spath_split_path_b_start_tl - } + } - #2 \l__spath_tmpc_tl \l__spath_tmpb_tl - \tl_clear:N \l__spath_tmpb_tl + \tl_put_left:NV \l__spath_split_path_b_final_tl \l__spath_split_path_b_tl + \tl_if_empty:NT \l__spath_split_path_b_final_tl + { + \tl_set_eq:NN \l__spath_split_path_b_final_tl \l__spath_split_path_b_tl } + + \spath_remove_empty_components:N \l__spath_split_path_b_final_tl + + \tl_gclear:N \g__spath_output_tl + \tl_gset_eq:NN \g__spath_output_tl \l__spath_split_path_b_final_tl + \group_end: } -\cs_generate_variant:Nn \spath_map_segment_function:NN {Nc} -\NewDocumentCommand \MakeSPath { m m } -{ - \spath_clear_new:n {#1} - \spath_put:nno {#1} {path} {#2} -} -\NewDocumentCommand \MakeSPathList { m m } +\cs_new_protected_nopar:Npn \spath_split_at_self_intersections:Nn #1#2 { - \tl_gclear_new:c {l__spath_list_#1} - \int_zero:N \l__spath_tmpa_int - \spath_map_component:Nn #2 { - \spath_clear_new:n {#1 _ \int_use:N \l__spath_tmpa_int} - \spath_put:nnn {#1 _ \int_use:N \l__spath_tmpa_int} {path} {##1} - \tl_gput_right:cx {l__spath_list_#1} {{#1 _ \int_use:N \l__spath_tmpa_int}} - \int_incr:N \l__spath_tmpa_int - } + \__spath_split_at_self_intersections:n {#2} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl } -\NewDocumentCommand \CloneSPath { m m } +\cs_generate_variant:Nn \spath_split_at_self_intersections:Nn {NV} +\cs_new_protected_nopar:Npn \spath_split_at_self_intersections:N #1 { - \spath_clone:nn {#1} {#2} + \spath_split_at_self_intersections:NV #1#1 } -\NewDocumentCommand \SPathInfo { m m } +\cs_generate_variant:Nn \spath_split_at_self_intersections:N {c} +\cs_new_protected_nopar:Npn \spath_gsplit_at_self_intersections:Nn #1#2 { - \spath_get:nn {#1} {#2} + \__spath_split_at_self_intersections:n {#2} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl } -\NewDocumentCommand \SPathPrepare { m } +\cs_generate_variant:Nn \spath_gsplit_at_self_intersections:Nn {NV} +\cs_new_protected_nopar:Npn \spath_gsplit_at_self_intersections:N #1 { - \spath_generate_all:n {#1} + \spath_gsplit_at_self_intersections:NV #1#1 } -\NewDocumentCommand \SPathListPrepare { m } +\cs_generate_variant:Nn \spath_gsplit_at_self_intersections:N {c} +\tl_new:N \l__spath_tmpj_tl +\cs_new_protected_nopar:Npn \__spath_join_component:nn #1#2 { - \tl_map_inline:cn {l__spath_list_#1} + \group_begin: + \spath_components_to_seq:Nn \l__spath_tmpa_seq {#1} + \int_compare:nT + { + #2 == 1 + } + { + \tl_clear:N \l__spath_tmpj_tl + \seq_pop_left:NN \l__spath_tmpa_seq \l__spath_tmpj_tl + + \prg_replicate:nn {3} + { + \tl_set:Nx \l__spath_tmpj_tl {\tl_tail:N \l__spath_tmpj_tl} + } + + \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpj_tl + } + \bool_if:nT + { + \int_compare_p:n + { + #2 > 1 + } + && + \int_compare_p:n + { + #2 <= \seq_count:N \l__spath_tmpa_seq + } + } { - \spath_generate_all:n {##1} + + \seq_clear:N \l__spath_tmpb_seq + \seq_map_indexed_inline:Nn \l__spath_tmpa_seq + { + \tl_set:Nn \l__spath_tmpj_tl {##2} + \int_compare:nT {##1 = #2} + { + \prg_replicate:nn {3} + { + \tl_set:Nx \l__spath_tmpj_tl {\tl_tail:N \l__spath_tmpj_tl} + } + } + \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpj_tl + } + + \seq_set_eq:NN \l__spath_tmpa_seq \l__spath_tmpb_seq } + + \tl_gset:Nx \g__spath_output_tl {\seq_use:Nn \l__spath_tmpa_seq {} } + \group_end: } -\NewDocumentCommand \SPathInfoInto { m m m } +\cs_new_protected_nopar:Npn \spath_join_component:Nnn #1#2#3 { - \tl_clear_new:N #3 - \spath_get:nnN {#1} {#2} #3 + \__spath_join_component:nn {#2}{#3} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl } -\NewDocumentCommand \SPathShow { m } +\cs_generate_variant:Nn \spath_join_component:Nnn {NVn, NVV} +\cs_new_protected_nopar:Npn \spath_join_component:Nn #1#2 { - \spath_show:n {#1} + \spath_join_component:NVn #1#1{#2} } -\NewDocumentCommand \SPathTranslate { m m m } +\cs_generate_variant:Nn \spath_join_component:Nn {cn, NV, cV} +\cs_new_protected_nopar:Npn \spath_gjoin_component:Nnn #1#2#3 { - \spath_translate:nnn {#1} {#2} {#3} + \__spath_join_component:nn {#2}{#3} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl } -\NewDocumentCommand \SPathTranslateInto { m m m m } +\cs_generate_variant:Nn \spath_gjoin_component:Nnn {NVn, NVV} +\cs_new_protected_nopar:Npn \spath_gjoin_component:Nn #1#2 { - \spath_clone:nn {#1} {#2} - \spath_translate:nnn {#2} {#3} {#4} + \spath_gjoin_component:NVn #1#1{#2} } -\NewDocumentCommand \SPathScale { m m m } +\cs_generate_variant:Nn \spath_gjoin_component:Nn {cn, NV, cV} +\cs_new_protected_nopar:Npn \__spath_spot_weld_components:n #1 { - \spath_scale:nnn {#1} {#2} {#3} + \group_begin: + \dim_zero:N \l__spath_move_x_dim + \dim_zero:N \l__spath_move_y_dim + + \spath_components_to_seq:Nn \l__spath_tmpa_seq {#1} + \seq_clear:N \l__spath_tmpb_seq + \dim_set:Nn \l__spath_move_x_dim {\tl_item:nn {#1} {2} + 10 pt} + \dim_set:Nn \l__spath_move_y_dim {\tl_item:nn {#1} {3} + 10 pt} + + \int_set:Nn \l__spath_tmpa_int {\seq_count:N \l__spath_tmpa_seq} + + \seq_map_inline:Nn \l__spath_tmpa_seq + { + \tl_set:Nn \l__spath_tmpa_tl {##1} + \bool_if:nT + { + \dim_compare_p:n + { + \dim_abs:n {\l__spath_move_x_dim - \tl_item:Nn \l__spath_tmpa_tl {2} } < 0.01pt + } + && + \dim_compare_p:n + { + \dim_abs:n {\l__spath_move_y_dim - \tl_item:Nn \l__spath_tmpa_tl {3} } < 0.01pt + } + } + { + \prg_replicate:nn {3} + { + \tl_set:Nx \l__spath_tmpa_tl {\tl_tail:N \l__spath_tmpa_tl} + } + \int_decr:N \l__spath_tmpa_int + } + \tl_reverse:N \l__spath_tmpa_tl + \dim_set:Nn \l__spath_move_x_dim {\tl_item:Nn \l__spath_tmpa_tl {2}} + \dim_set:Nn \l__spath_move_y_dim {\tl_item:Nn \l__spath_tmpa_tl {1}} + \tl_reverse:N \l__spath_tmpa_tl + \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpa_tl + } + + \tl_set:Nx \l__spath_tmpa_tl {\seq_use:Nn \l__spath_tmpb_seq {} } + \spath_components_to_seq:NV \l__spath_tmpb_seq \l__spath_tmpa_tl + + \spath_initialpoint:Nn \l__spath_tmpa_tl {#1} + \spath_finalpoint:Nn \l__spath_tmpb_tl {#1} + + \bool_if:nT + { + \dim_compare_p:n + { + \dim_abs:n {\tl_item:Nn \l__spath_tmpa_tl {1} - \tl_item:Nn \l__spath_tmpb_tl {1} } < 0.01pt + } + && + \dim_compare_p:n + { + \dim_abs:n {\tl_item:Nn \l__spath_tmpa_tl {2} - \tl_item:Nn \l__spath_tmpb_tl {2} } < 0.01pt + } + } + { + \int_compare:nTF + { + \seq_count:N \l__spath_tmpb_seq > 1 + } + { + \seq_pop_left:NN \l__spath_tmpb_seq \l__spath_tmpb_tl + + \prg_replicate:nn {3} + { + \tl_set:Nx \l__spath_tmpb_tl {\tl_tail:N \l__spath_tmpb_tl} + } + \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpb_tl + } + { + \tl_set:NV \l__spath_tmpb_tl \c_spath_closepath_tl + \tl_put_right:Nx \l__spath_tmpb_tl + { + { \tl_item:Nn \l__spath_tmpa_tl {1} } + { \tl_item:Nn \l__spath_tmpa_tl {2} } + } + \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpb_tl + } + } + + \tl_gset:Nx \g__spath_output_tl {\seq_use:Nn \l__spath_tmpb_seq {}} + \group_end: } -\NewDocumentCommand \SPathScaleInto { m m m m } +\cs_new_protected_nopar:Npn \spath_spot_weld_components:Nn #1#2 { - \spath_clone:nn {#1} {#2} - \spath_scale:nnn {#2} {#3} {#4} + \__spath_spot_weld_components:n {#2} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl } -\NewDocumentCommand \SPathWeld { m m } +\cs_generate_variant:Nn \spath_spot_weld_components:Nn {NV, cV, cn} +\cs_new_protected_nopar:Npn \spath_spot_weld_components:N #1 { - \spath_weld:nn {#1} {#2} + \spath_spot_weld_components:NV #1#1 } -\NewDocumentCommand \SPathWeldInto { m m m } +\cs_generate_variant:Nn \spath_spot_weld_components:N {c} +\cs_new_protected_nopar:Npn \spath_spot_gweld_components:Nn #1#2 { - \spath_clone:nn {#1} {#2} - \spath_weld:nn {#2} {#3} + \__spath_spot_weld_components:n {#2} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl } -\tikzset{ - save~spath/.code={ - \tikz@addmode{ - \spath_get_current_path:n {#1} - } - }, - restore~spath/.code={ - \spath_set_current_path:n {#1} - } +\cs_generate_variant:Nn \spath_spot_gweld_components:Nn {NV, cV, cn} +\cs_new_protected_nopar:Npn \spath_spot_gweld_components:N #1 +{ + \spath_spot_gweld_components:NV #1#1 } -\cs_new_nopar:Npn \spath_split_curve:nnNN #1#2#3#4 +\cs_generate_variant:Nn \spath_spot_gweld_components:N {c} +\cs_new_protected_nopar:Npn \__spath_convert_to_svg:n #1 { \group_begin: - \tl_gclear:N \l__spath_smuggle_tl - \tl_set_eq:NN \l__spath_tmpa_tl \g__spath_moveto_tl - \tl_put_right:Nx \l__spath_tmpa_tl { - {\tl_item:nn {#2} {2}} - {\tl_item:nn {#2} {3}} + \tl_clear:N \l__spath_tmpa_tl + \tl_put_right:Nn \l__spath_tmpa_tl + { + + \iow_newline: + + \iow_newline: + + \iow_newline: + + \iow_newline: + + \iow_newline: } - \tl_put_right:NV \l__spath_tmpa_tl \g__spath_curvetob_tl - \tl_put_right:Nx \l__spath_tmpa_tl + \tl_gset_eq:NN \g__spath_output_tl \l__spath_tmpa_tl + \group_end: +} +\cs_new_protected_nopar:Npn \spath_convert_to_svg:Nn #1#2 +{ + \__spath_convert_to_svg:n {#2} + \tl_set_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\cs_new_protected_nopar:Npn \spath_gconvert_to_svg:Nn #1#2 +{ + \__spath_convert_to_svg:n {#2} + \tl_gset_eq:NN #1 \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl +} +\iow_new:N \g__spath_stream +\cs_new_protected_nopar:Npn \spath_export_to_svg:nn #1#2 +{ + \spath_convert_path_to_svg:Nn \l__spath_iterp_tl {#2} + \iow_open:Nn \g__spath_stream {#1 .svg} + \iow_now:Nx \g__spath_stream { - {\fp_to_dim:n - { - (1 - #1) * \tl_item:nn {#2} {8} + (#1) * \tl_item:nn {#2} {11} - }} - {\fp_to_dim:n - { - (1 - #1) * \tl_item:nn {#2} {9} + (#1) * \tl_item:nn {#2} {12} - }} + \tl_use:N \l__spath_iterp_tl } - \tl_put_right:NV \l__spath_tmpa_tl \g__spath_curveto_tl - \tl_put_right:Nx \l__spath_tmpa_tl { - {\tl_item:nn {#2} {11}} - {\tl_item:nn {#2} {12}} + \iow_close:N \g__spath_stream +} +\cs_new_protected_nopar:Npn \spath_show:n #1 +{ + \int_step_inline:nnnn {1} {3} {\tl_count:n {#1}} + { + \iow_term:x { + \tl_item:Nn \l__spath_tmpa_tl {##1} + {\tl_item:Nn \l__spath_tmpa_tl {##1+1}} + {\tl_item:Nn \l__spath_tmpa_tl {##1+2}} + } } - \tl_gset_eq:NN \l__spath_smuggle_tl \l__spath_tmpa_tl - \group_end: - \tl_set_eq:NN #4 \l__spath_smuggle_tl } +\cs_generate_variant:Nn \spath_show:n {V, v} + +\cs_new_protected_nopar:Npn \spath_get_current_path:N #1 +{ + \pgfsyssoftpath@getcurrentpath #1 +} +\cs_new_protected_nopar:Npn \spath_gget_current_path:N #1 +{ + \pgfsyssoftpath@getcurrentpath #1 + \tl_gset_eq:NN #1 #1 +} +\cs_new_protected_nopar:Npn \spath_protocol_path:n #1 +{ + \spath_minbb:Nn \l__spath_tmpa_tl {#1} + \exp_last_unbraced:NV \pgf@protocolsizes\l__spath_tmpa_tl -\cs_generate_variant:Nn \spath_split_curve:nnNN {nVNN, VVNN} + \spath_maxbb:Nn \l__spath_tmpa_tl {#1} + \exp_last_unbraced:NV \pgf@protocolsizes\l__spath_tmpa_tl +} +\cs_generate_variant:Nn \spath_protocol_path:n {V} +\cs_new_protected_nopar:Npn \spath_set_current_path:n #1 +{ + \spath_protocol_path:n {#1} + \tl_set:Nn \l__spath_tmpa_tl {#1} + \pgfsyssoftpath@setcurrentpath\l__spath_tmpa_tl +} +\cs_new_protected_nopar:Npn \spath_set_current_path:N #1 +{ + \spath_protocol_path:V #1 + \pgfsyssoftpath@setcurrentpath #1 +} +\cs_generate_variant:Nn \spath_set_current_path:N {c} +\cs_new_protected_nopar:Npn \spath_use_path:nn #1#2 +{ + \spath_set_current_path:n {#1} + \pgfusepath{#2} +} +\cs_new_protected_nopar:Npn \spath_tikz_path:nn #1#2 +{ + \path[#1] \pgfextra{ + \spath_set_current_path:n {#2} + \tl_put_right:Nn \tikz@preactions {\def\tikz@actions@path{#2}} + }; +} +\cs_generate_variant:Nn \spath_tikz_path:nn {Vn, VV, nv, Vv, nV} +\cs_new_protected_nopar:Npn \spath_set_tikz_coords:n #1 +{ + \spath_finalpoint:Nn \l__spath_tmpa_tl {#1} + \tl_set:Nx \l__spath_tmpa_tl + { + \exp_not:c {tikz@lastx}=\tl_item:Nn \l__spath_tmpa_tl {1} + \exp_not:c {tikz@lasty}=\tl_item:Nn \l__spath_tmpa_tl {2} + \exp_not:c {tikz@lastxsaved}=\tl_item:Nn \l__spath_tmpa_tl {1} + \exp_not:c {tikz@lastysaved}=\tl_item:Nn \l__spath_tmpa_tl {2} + } + \tl_use:N \l__spath_tmpa_tl +} +\cs_generate_variant:Nn \spath_set_tikz_coords:n {V, v} %% -%% Copyright (C) 2011-2019 by Andrew Stacey +%% Copyright (C) 2011-2019 by Andrew Stacey %% %% This work may be distributed and/or modified under the %% conditions of the LaTeX Project Public License (LPPL), either @@ -1500,13 +3130,16 @@ manipulating PGF soft paths} %% This work consists of the files spath3.dtx %% calligraphy_doc.tex %% knots_doc.tex +%% spath3.tex %% and the derived files spath3.ins, %% spath3_code.pdf, %% spath3.sty, %% tikzlibrarycalligraphy.code.tex %% tikzlibraryknots.code.tex +%% tikzlibraryspath3.code.tex %% calligraphy.pdf %% knots.pdf +%% spath3.pdf %% README %% %% diff --git a/Master/texmf-dist/tex/latex/spath3/tikzlibrarycalligraphy.code.tex b/Master/texmf-dist/tex/latex/spath3/tikzlibrarycalligraphy.code.tex index 9b0e082b144..e987539cb0b 100644 --- a/Master/texmf-dist/tex/latex/spath3/tikzlibrarycalligraphy.code.tex +++ b/Master/texmf-dist/tex/latex/spath3/tikzlibrarycalligraphy.code.tex @@ -4,10 +4,10 @@ %% %% The original source files were: %% -%% spath3.dtx (with options: `calligraphy') +%% spath3_code.dtx (with options: `calligraphy') %% ---------------------------------------------------------------- %% spath3 --- Functions for manipulating PGF soft paths -%% E-mail: stacey@math.ntnu.no +%% E-mail: loopspace@mathforge.org %% Released under the LaTeX Project Public License v1.3c or later %% See http://www.latex-project.org/lppl.txt %% ---------------------------------------------------------------- @@ -17,10 +17,24 @@ \tl_new:N \l__cal_tmpa_tl \tl_new:N \l__cal_tmpb_tl +\tl_new:N \l__cal_tmp_path_tl +\tl_new:N \l__cal_tmp_rpath_tl +\tl_new:N \l__cal_tmp_rpathb_tl +\tl_new:N \l__cal_tmp_patha_tl + +\seq_new:N \l__cal_tmpa_seq + \int_new:N \l__cal_tmpa_int \int_new:N \l__cal_tmpb_int -\int_new:N \l__cal_path_component_int -\int_new:N \l__cal_label_int +\int_new:N \g__cal_path_component_int +\int_new:N \g__cal_label_int + +\fp_new:N \l__cal_tmpa_fp +\fp_new:N \l__cal_tmpb_fp +\fp_new:N \l__cal_tmpc_fp +\fp_new:N \l__cal_tmpd_fp +\fp_new:N \l__cal_tmpe_fp + \dim_new:N \l__cal_tmpa_dim \dim_new:N \l__cal_tmpb_dim \dim_new:N \l__cal_tmpc_dim @@ -29,10 +43,12 @@ \dim_new:N \l__cal_tmpf_dim \dim_new:N \l__cal_tmpg_dim \dim_new:N \l__cal_tmph_dim + \bool_new:N \l__cal_annotate_bool \bool_new:N \l__cal_taper_start_bool \bool_new:N \l__cal_taper_end_bool \bool_new:N \l__cal_taperable_bool + \dim_new:N \l__cal_taper_width_dim \dim_new:N \l__cal_line_width_dim @@ -40,27 +56,35 @@ \bool_set_true:N \l__cal_taper_end_bool \cs_generate_variant:Nn \tl_put_right:Nn {Nv} + +\msg_new:nnn { calligraphy } { undefined pen } { The~ pen~ "#1"~ is~ not~ defined. } \tikzset{ define~pen/.code={ \tikzset{pen~name=#1} \pgf@relevantforpicturesizefalse \tikz@addmode{ \pgfsyssoftpath@getcurrentpath\l__cal_tmpa_tl - \MakeSPathList{calligraphy pen \pgfkeysvalueof{/tikz/pen~name}}{\l__cal_tmpa_tl} - \SPathListPrepare{calligraphy pen \pgfkeysvalueof{/tikz/pen~name}} + \spath_components_to_seq:NV \l__cal_tmpa_seq \l__cal_tmpa_tl + \seq_gclear_new:c {g__cal_pen_\pgfkeysvalueof{/tikz/pen~name}_seq} + \seq_gset_eq:cN {g__cal_pen_\pgfkeysvalueof{/tikz/pen~name}_seq} \l__cal_tmpa_seq \pgfusepath{discard}% } }, define~pen/.default={default}, use~pen/.code={ \tikzset{pen~name=#1} - \int_gzero:N \l__cal_path_component_int + \int_gzero:N \g__cal_path_component_int \cs_set_eq:NN \pgfpathmoveto \cal_moveto:n \tikz@addmode{ \pgfsyssoftpath@getcurrentpath\l__cal_tmpa_tl - \MakeSPathList{calligraphy path}{\l__cal_tmpa_tl} - \SPathListPrepare{calligraphy path} - \CalligraphyPathCreate{calligraphy path}{\pgfkeysvalueof{/tikz/pen~name}} + \spath_components_to_seq:NV \l__cal_tmpa_seq \l__cal_tmpa_tl + \tl_if_exist:cTF {g__cal_pen_\pgfkeysvalueof{/tikz/pen~name}_seq} + { + \cal_path_create:Nc \l__cal_tmpa_seq {g__cal_pen_\pgfkeysvalueof{/tikz/pen~name}_seq} + } + { + \msg_warning:nnx { calligraphy } { undefined pen } { \pgfkeysvalueof{/tikz/pen~name} } + } } }, use~pen/.default={default}, @@ -132,8 +156,8 @@ \tl_set:cn {l__cal_stroke_style_#1} {#2} }, this~stroke~style/.code={ - \tl_clear_new:c {l__cal_stroke_inline_style_ \int_use:N \l__cal_path_component_int} - \tl_set:cn {l__cal_stroke_inline_style_ \int_use:N \l__cal_path_component_int} {#1} + \tl_clear_new:c {l__cal_stroke_inline_style_ \int_use:N \g__cal_path_component_int} + \tl_set:cn {l__cal_stroke_inline_style_ \int_use:N \g__cal_path_component_int} {#1} }, annotate/.style={ annotate~if, @@ -151,12 +175,13 @@ } }, annotate~reset/.code={ - \int_gzero:N \l__cal_label_int + \int_gzero:N \g__cal_label_int }, annotation~style/.initial={draw,->}, annotation~shift/.initial={(0,1ex)}, every~annotation~node/.initial={anchor=south~west}, annotation~node~style/.code~2~args={ + \tl_clear_new:c {l__cal_annotation_style_ #1 _tl} \tl_set:cn {l__cal_annotation_style_ #1 _tl}{#2} }, tl~use:N/.code={ @@ -179,7 +204,7 @@ { \pgfkeyssetvalue{\pgfkeyscurrentpath}{#1} } - } + }, } \NewDocumentCommand \pen { O{} } { @@ -195,100 +220,99 @@ { \path[use~ pen,every~ calligraphy/.try,#1] } -\NewDocumentCommand \CalligraphyPathCreate { m m } +\cs_new_protected_nopar:Npn \cal_path_create:NN #1#2 { \int_zero:N \l__cal_tmpa_int - \tl_map_inline:cn {l__spath_list_#1} + \seq_map_inline:Nn #1 { - \int_incr:N \l__cal_tmpa_int - \int_zero:N \l__cal_tmpb_int - \tl_map_inline:cn {l__spath_list_calligraphy pen #2} + \int_compare:nT {\tl_count:n {##1} > 3} { - \int_incr:N \l__cal_tmpb_int - \group_begin: - \pgfsys@beginscope - - \cal_apply_style:c {l__cal_stroke_style_ \int_use:N \l__cal_tmpa_int} - \cal_apply_style:c {l__cal_stroke_inline_style_ \int_use:N \l__cal_tmpa_int} - \cal_apply_style:c {l__cal_nib_style_ \int_use:N \l__cal_tmpb_int} - - \spath_clone:nn {##1} {calligraphy temp path} - \__spath_get:nnN {####1} {initial point} \l__cal_tmpa_tl - \spath_translate:nV {calligraphy temp path} \l__cal_tmpa_tl + \int_incr:N \l__cal_tmpa_int + \int_zero:N \l__cal_tmpb_int - \__spath_get:nnN {####1} {length} \l__cal_tmpa_tl + \tl_set:Nn \l__cal_tmp_path_tl {##1} + \spath_open:N \l__cal_tmp_path_tl + \spath_reverse:NV \l__cal_tmp_rpath_tl \l__cal_tmp_path_tl - \int_compare:nTF {\l__cal_tmpa_tl = 1} + \seq_map_inline:Nn #2 { - \cal_at_least_three:n {calligraphy temp path} - - \spath_protocol_path:n {calligraphy temp path} + \int_incr:N \l__cal_tmpb_int + \group_begin: + \pgfsys@beginscope + \cal_apply_style:c {l__cal_stroke_style_ \int_use:N \l__cal_tmpa_int} + \cal_apply_style:c {l__cal_stroke_inline_style_ \int_use:N \l__cal_tmpa_int} + \cal_apply_style:c {l__cal_nib_style_ \int_use:N \l__cal_tmpb_int} + + \spath_initialpoint:Nn \l__cal_tmpa_tl {####1} + \tl_set_eq:NN \l__cal_tmp_patha_tl \l__cal_tmp_path_tl + \spath_translate:NV \l__cal_tmp_patha_tl \l__cal_tmpa_tl + + \int_compare:nTF {\tl_count:n {####1} == 3} + { + \cal_at_least_three:N \l__cal_tmp_patha_tl + \spath_protocol_path:V \l__cal_tmp_patha_tl - \__spath_get:nnN {calligraphy temp path} {path} \l__cal_tmpa_tl + \tikz@options + \dim_set:Nn \l__cal_line_width_dim {\pgflinewidth} + \cal_maybe_taper:N \l__cal_tmp_patha_tl + } + { + \spath_weld:Nn \l__cal_tmp_patha_tl {####1} + \spath_weld:NV \l__cal_tmp_patha_tl \l__cal_tmp_rpath_tl + \spath_reverse:Nn \l__cal_tmp_rpathb_tl {####1} + \spath_weld:NV \l__cal_tmp_patha_tl \l__cal_tmp_rpathb_tl + + \tl_clear:N \l__cal_tmpa_tl + \tl_set:Nn \l__cal_tmpa_tl {fill=\pgfkeysvalueof{/tikz/pen~colour},draw=none} + \tl_if_exist:cT {l__cal_stroke_style_ \int_use:N \l__cal_tmpa_int} + { + \tl_put_right:Nv \l__cal_tmpa_tl {l__cal_stroke_style_ \int_use:N \l__cal_tmpa_int} + } + \tl_if_exist:cT {l__cal_stroke_inline_style_ \int_use:N \l__cal_tmpa_int} + { + \tl_put_right:Nn \l__cal_tmpa_tl {,} + \tl_put_right:Nv \l__cal_tmpa_tl {l__cal_stroke_inline_style_ \int_use:N \l__cal_tmpa_int} + } + \tl_if_exist:cT {l__cal_nib_style_ \int_use:N \l__cal_tmpb_int} + { + \tl_put_right:Nn \l__cal_tmpa_tl {,} + \tl_put_right:Nv \l__cal_tmpa_tl {l__cal_nib_style_ \int_use:N \l__cal_tmpb_int} + } + \spath_tikz_path:VV \l__cal_tmpa_tl \l__cal_tmp_patha_tl - \tikz@options - \dim_set:Nn \l__cal_line_width_dim {\pgflinewidth} - \cal_maybe_taper:N \l__cal_tmpa_tl + } + \pgfsys@endscope + \group_end: } + + \bool_if:NT \l__cal_annotate_bool { + \seq_get_right:NN #2 \l__cal_tmpa_tl + \spath_finalpoint:NV \l__cal_tmpa_tl \l__cal_tmpa_tl + \spath_translate:NV \l__cal_tmp_path_tl \l__cal_tmpa_tl + \tikz@scan@one@point\pgfutil@firstofone\pgfkeysvalueof{/tikz/annotation~shift} - \spath_weld:nn {calligraphy temp path} {####1} - \spath_reverse:n {##1} - \spath_reverse:n {####1} - \spath_weld:nn {calligraphy temp path} {##1} - \spath_weld:nn {calligraphy temp path} {####1} - \spath_reverse:n {##1} - \spath_reverse:n {####1} - - \tl_clear:N \l__cal_tmpa_tl - \tl_set:Nn \l__cal_tmpa_tl {fill=\pgfkeysvalueof{/tikz/pen~colour},draw=none} - \tl_if_exist:cT {l__cal_stroke_style_ \int_use:N \l__cal_tmpa_int} - { - \tl_put_right:Nv \l__cal_tmpa_tl {l__cal_stroke_style_ \int_use:N \l__cal_tmpa_int} - } - \tl_if_exist:cT {l__cal_stroke_inline_style_ \int_use:N \l__cal_tmpa_int} - { - \tl_put_right:Nn \l__cal_tmpa_tl {,} - \tl_put_right:Nv \l__cal_tmpa_tl {l__cal_stroke_inline_style_ \int_use:N \l__cal_tmpa_int} - } - \tl_if_exist:cT {l__cal_nib_style_ \int_use:N \l__cal_tmpb_int} - { - \tl_put_right:Nn \l__cal_tmpa_tl {,} - \tl_put_right:Nv \l__cal_tmpa_tl {l__cal_nib_style_ \int_use:N \l__cal_tmpb_int} - } - \spath_tikz_path:Vn \l__cal_tmpa_tl {calligraphy temp path} + \spath_translate:Nnn \l__cal_tmp_path_tl {\pgf@x} {\pgf@y} + \pgfkeysgetvalue{/tikz/annotation~style}{\l__cal_tmpa_tl} + \spath_tikz_path:VV \l__cal_tmpa_tl \l__cal_tmp_path_tl + + \spath_finalpoint:NV \l__cal_tmpa_tl \l__cal_tmp_path_tl + + \exp_last_unbraced:NV \pgfqpoint \l__cal_tmpa_tl + \begin{scope}[reset~ cm] + \node[every~annotation~node/.try,tl~use:c = {l__cal_annotation_style_ \int_use:N \l__cal_tmpa_int _tl}] at (\pgf@x,\pgf@y) {\int_use:N \l__cal_tmpa_int}; + \end{scope} } - \pgfsys@endscope - \group_end: - } - \bool_if:NT \l__cal_annotate_bool - { - \spath_clone:nn {##1} {calligraphy temp path} - \tl_set_eq:Nc \l_tmpa_tl {l__spath_list_calligraphy pen #2} - \tl_reverse:N \l_tmpa_tl - \tl_set:Nx \l_tmpa_tl {\tl_head:N \l_tmpa_tl} - \spath_generate_finalpoint:V \l_tmpa_tl - \spath_get:VnN \l_tmpa_tl {final point} \l_tmpa_tl - \spath_translate:nV {calligraphy temp path} \l_tmpa_tl - \tikz@scan@one@point\pgfutil@firstofone\pgfkeysvalueof{/tikz/annotation~shift} - \spath_translate:nnn {calligraphy temp path} {\pgf@x} {\pgf@y} - - \pgfkeysgetvalue{/tikz/annotation~style}{\l_tmpa_tl} - \spath_tikz_path:Vn \l_tmpa_tl {calligraphy temp path} - \spath_get:nnN {calligraphy temp path} {final point} \l_tmpa_tl - \exp_last_unbraced:NV \pgfqpoint \l_tmpa_tl - \begin{scope}[reset~ cm] - \node[every~annotation~node/.try,tl~use:c = {l__cal_annotation_style_ \int_use:N \l__cal_tmpa_int _tl}] at (\pgf@x,\pgf@y) {\int_use:N \l__cal_tmpa_int}; - \end{scope} } } } +\cs_generate_variant:Nn \cal_path_create:NN {Nc} \cs_new_eq:NN \cal_orig_moveto:n \pgfpathmoveto \cs_new_nopar:Npn \cal_moveto:n #1 { - \int_gincr:N \l__cal_path_component_int + \int_gincr:N \g__cal_path_component_int \cal_orig_moveto:n {#1} } \cs_new_nopar:Npn \cal_apply_style:N #1 @@ -298,154 +322,32 @@ } } \cs_generate_variant:Nn \cal_apply_style:N {c} -\cs_new_nopar:Npn \cal_at_least_three:n #1 +\cs_new_protected_nopar:Npn \cal_at_least_three:Nn #1#2 { - \spath_get:nnN {#1} {real length} \l__cal_tmpa_tl + \spath_reallength:Nn \l__cal_tmpa_int {#2} \tl_clear:N \l__cal_tmpb_tl - \int_compare:nTF {\l__cal_tmpa_tl = 1} + \tl_set:Nn \l__cal_tmpb_tl {#2} + \int_compare:nTF {\l__cal_tmpa_int = 1} { - \spath_get:nnN {#1} {path} \l__cal_tmpa_tl - \spath_map_segment_inline:Nn \l__cal_tmpa_tl - { - \tl_case:NnF ##1 { - \g__spath_lineto_tl { - \cal_split_line_in_three:NN \l__cal_tmpb_tl ##2 - } - \g__spath_curvetoa_tl { - \cal_split_curve_in_three:NN \l__cal_tmpb_tl ##2 - } - } - { - \tl_put_right:NV \l__cal_tmpb_tl ##2 - } - } - \spath_put:nnV {#1} {path} \l__cal_tmpb_tl + \spath_split_at:Nn \l__cal_tmpb_tl {2/3} + \spath_split_at:Nn \l__cal_tmpb_tl {1/2} } { - \int_compare:nT {\l__cal_tmpa_tl = 2} + \int_compare:nT {\l__cal_tmpa_int = 2} { - \spath_get:nnN {#1} {path} \l__cal_tmpa_tl - \spath_map_segment_inline:Nn \l__cal_tmpa_tl - { - \tl_case:NnF ##1 { - \g__spath_lineto_tl { - \cal_split_line_in_two:NN \l__cal_tmpb_tl ##2 - } - \g__spath_curvetoa_tl { - \cal_split_curve_in_two:NN \l__cal_tmpb_tl ##2 - } - } - { - \tl_put_right:NV \l__cal_tmpb_tl ##2 - } - } - \spath_put:nnV {#1} {path} \l__cal_tmpb_tl + \spath_split_at:Nn \l__cal_tmpb_tl {1.5} + \spath_split_at:Nn \l__cal_tmpb_tl {.5} } } + \tl_set_eq:NN #1 \l__cal_tmpb_tl } -\cs_new_nopar:Npn \cal_split_line_in_two:NN #1#2 +\cs_generate_variant:Nn \cal_at_least_three:Nn {NV} +\cs_new_protected_nopar:Npn \cal_at_least_three:N #1 { - \tl_set_eq:NN \l__cal_tmpc_tl #2 - - \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl} - - \dim_set:Nn \l__cal_tmpa_dim {\tl_head:N \l__cal_tmpc_tl} - \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl} - - \dim_set:Nn \l__cal_tmpb_dim {\tl_head:N \l__cal_tmpc_tl} - \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl} - - \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl} - - \dim_set:Nn \l__cal_tmpc_dim {\tl_head:N \l__cal_tmpc_tl} - \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl} - \dim_set:Nn \l__cal_tmpd_dim {\tl_head:N \l__cal_tmpc_tl} - \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl} - - \tl_put_right:NV #1 \g__spath_lineto_tl - - \tl_put_right:Nx #1 { - {\dim_eval:n {(\l__cal_tmpa_dim + \l__cal_tmpc_dim)/2}} - {\dim_eval:n {(\l__cal_tmpb_dim + \l__cal_tmpd_dim)/2}} - } - - \tl_put_right:NV #1 \g__spath_lineto_tl - \tl_put_right:Nx #1 { - {\dim_use:N \l__cal_tmpc_dim} - {\dim_use:N \l__cal_tmpd_dim} - } + \cal_at_least_three:NV #1#1 } -\cs_new_nopar:Npn \cal_split_line_in_three:NN #1#2 -{ - \tl_set_eq:NN \l__cal_tmpc_tl #2 - - \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl} - - \dim_set:Nn \l__cal_tmpa_dim {\tl_head:N \l__cal_tmpc_tl} - \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl} - - \dim_set:Nn \l__cal_tmpb_dim {\tl_head:N \l__cal_tmpc_tl} - \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl} - - \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl} - - \dim_set:Nn \l__cal_tmpc_dim {\tl_head:N \l__cal_tmpc_tl} - \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl} - \dim_set:Nn \l__cal_tmpd_dim {\tl_head:N \l__cal_tmpc_tl} - \tl_set:Nx \l__cal_tmpc_tl {\tl_tail:N \l__cal_tmpc_tl} - - \tl_put_right:NV #1 \g__spath_lineto_tl - - \tl_put_right:Nx #1 { - {\dim_eval:n {(2\l__cal_tmpa_dim + \l__cal_tmpc_dim)/3}} - {\dim_eval:n {(2\l__cal_tmpb_dim + \l__cal_tmpd_dim)/3}} - } - - \tl_put_right:NV #1 \g__spath_lineto_tl - - \tl_put_right:Nx #1 { - {\dim_eval:n {(\l__cal_tmpa_dim + 2\l__cal_tmpc_dim)/3}} - {\dim_eval:n {(\l__cal_tmpb_dim + 2\l__cal_tmpd_dim)/3}} - } - - \tl_put_right:NV #1 \g__spath_lineto_tl - \tl_put_right:Nx #1 { - {\dim_use:N \l__cal_tmpc_dim} - {\dim_use:N \l__cal_tmpd_dim} - } -} -\cs_new_nopar:Npn \cal_split_curve_in_two:NN #1#2 -{ - \spath_split_curve:nVNN {.5} #2 \l_tmpa_tl \l_tmpb_tl - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl} - \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl} - \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl} - \tl_put_right:NV #1 \l_tmpa_tl - \tl_put_right:NV #1 \l_tmpb_tl -} -\cs_new_nopar:Npn \cal_split_curve_in_three:NN #1#2 -{ - \spath_split_curve:nVNN {1/3} #2 \l_tmpa_tl \l_tmpb_tl - - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_put_right:NV #1 \l_tmpa_tl - - \spath_split_curve:nVNN {.5} \l_tmpb_tl \l_tmpa_tl \l_tmpb_tl - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl} - \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl} - \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl} - \tl_put_right:NV #1 \l_tmpa_tl - \tl_put_right:NV #1 \l_tmpb_tl -} -\cs_new_nopar:Npn \cal_maybe_taper:N #1 +\cs_generate_variant:Nn \cal_at_least_three:N {c} +\cs_new_protected_nopar:Npn \cal_maybe_taper:N #1 { \tl_set_eq:NN \l__cal_tmpa_tl #1 @@ -458,7 +360,7 @@ \tl_case:NnF \l__cal_tmpb_tl { - \g__spath_lineto_tl + \c_spath_lineto_tl { \bool_set_true:N \l__cal_taperable_bool @@ -472,9 +374,9 @@ { \tl_set:Nx \l__cal_tmpa_tl {\tl_tail:N \l__cal_tmpa_tl} } - \tl_put_left:NV \l__cal_tmpa_tl \g__spath_moveto_tl + \tl_put_left:NV \l__cal_tmpa_tl \c_spath_moveto_tl } - \g__spath_curvetoa_tl + \c_spath_curvetoa_tl { \bool_set_true:N \l__cal_taperable_bool \dim_set:Nn \l__cal_tmpc_dim {\tl_item:Nn \l__cal_tmpa_tl {5}} @@ -487,7 +389,7 @@ { \tl_set:Nx \l__cal_tmpa_tl {\tl_tail:N \l__cal_tmpa_tl} } - \tl_put_left:NV \l__cal_tmpa_tl \g__spath_moveto_tl + \tl_put_left:NV \l__cal_tmpa_tl \c_spath_moveto_tl } } { @@ -510,7 +412,7 @@ \tl_case:NnF \l__cal_tmpb_tl { - \g__spath_lineto_tl + \c_spath_lineto_tl { \bool_set_true:N \l__cal_taperable_bool @@ -527,7 +429,7 @@ } \tl_reverse:N \l__cal_tmpa_tl } - \g__spath_curveto_tl + \c_spath_curveto_tl { \bool_set_true:N \l__cal_taperable_bool \dim_set:Nn \l__cal_tmpc_dim {\tl_item:Nn \l__cal_tmpa_tl {-5}} @@ -560,10 +462,10 @@ \pgfusepath{stroke} } -\cs_new_nopar:Npn \__cal_taper_aux: +\cs_new_protected_nopar:Npn \__cal_taper_aux: { \tl_clear:N \l__cal_tmpb_tl - \tl_put_right:NV \l__cal_tmpb_tl \g__spath_moveto_tl + \tl_put_right:NV \l__cal_tmpb_tl \c_spath_moveto_tl \fp_set:Nn \l__cal_tmpa_fp { @@ -603,7 +505,7 @@ {\dim_eval:n { \fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpb_dim}} } - \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetoa_tl + \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curvetoa_tl \tl_put_right:Nx \l__cal_tmpb_tl { @@ -611,7 +513,7 @@ {\dim_eval:n { \fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpd_dim}} } - \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetob_tl + \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curvetob_tl \tl_put_right:Nx \l__cal_tmpb_tl { @@ -619,7 +521,7 @@ {\dim_eval:n { \fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmpf_dim}} } - \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curveto_tl + \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curveto_tl \tl_put_right:Nx \l__cal_tmpb_tl { @@ -627,7 +529,7 @@ {\dim_eval:n { \fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmph_dim}} } - \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetoa_tl + \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curvetoa_tl \tl_put_right:Nx \l__cal_tmpb_tl { @@ -635,7 +537,7 @@ {\dim_eval:n { \fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmph_dim + \fp_to_dim:n {1.32* \l__cal_tmpc_fp}}} } - \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetob_tl + \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curvetob_tl \tl_put_right:Nx \l__cal_tmpb_tl { @@ -643,7 +545,7 @@ {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmph_dim + \fp_to_dim:n {1.32 * \l__cal_tmpc_fp}}} } - \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curveto_tl + \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curveto_tl \tl_put_right:Nx \l__cal_tmpb_tl { @@ -651,7 +553,7 @@ {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmph_dim}} } - \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetoa_tl + \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curvetoa_tl \tl_put_right:Nx \l__cal_tmpb_tl { @@ -659,7 +561,7 @@ {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpd_fp + \l__cal_tmpf_dim}} } - \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetob_tl + \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curvetob_tl \tl_put_right:Nx \l__cal_tmpb_tl { @@ -667,7 +569,7 @@ {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpd_dim}} } - \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curveto_tl + \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curveto_tl \tl_put_right:Nx \l__cal_tmpb_tl { @@ -675,7 +577,7 @@ {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpb_dim}} } - \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetoa_tl + \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curvetoa_tl \tl_put_right:Nx \l__cal_tmpb_tl { @@ -683,7 +585,7 @@ {\dim_eval:n { -\fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpb_dim - \fp_to_dim:n {1.32* \l__cal_tmpa_fp}}} } - \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curvetob_tl + \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curvetob_tl \tl_put_right:Nx \l__cal_tmpb_tl { @@ -691,7 +593,7 @@ {\dim_eval:n { \fp_to_dim:N \l__cal_tmpb_fp + \l__cal_tmpb_dim - \fp_to_dim:n {1.32 * \l__cal_tmpa_fp}}} } - \tl_put_right:NV \l__cal_tmpb_tl \g__spath_curveto_tl + \tl_put_right:NV \l__cal_tmpb_tl \c_spath_curveto_tl \tl_put_right:Nx \l__cal_tmpb_tl { @@ -704,8 +606,14 @@ \pgfusepath{fill} } \tl_set:Nn \l__cal_tmpa_tl {\pgfsyssoftpath@movetotoken{0pt}{0pt}} -\MakeSPathList{calligraphy pen copperplate}{\l__cal_tmpa_tl} -\SPathListPrepare{calligraphy pen copperplate} +\spath_components_to_seq:NV \l__cal_tmpa_seq \l__cal_tmpa_tl +\seq_gclear_new:N \g__cal_pen_copperplate_seq +\seq_gset_eq:NN \g__cal_pen_copperplate_seq \l__cal_tmpa_seq +\DeclareDocumentCommand \CopperplatePath { m } +{ + \spath_components_to_seq:NV \l__cal_tmpa_seq #1 + \cal_path_create:NN \l__cal_tmpa_seq \g__cal_pen_copperplate_seq +} \ExplSyntaxOff \expandafter\ifx\csname pgfdeclaredecoration\endcsname\relax \else @@ -745,9 +653,7 @@ taper }% \pgfsyssoftpath@getcurrentpath\cal@tmp@path - \MakeSPathList{calligraphy path}{\cal@tmp@path}% - \SPathListPrepare{calligraphy path}% - \CalligraphyPathCreate{calligraphy path}{copperplate}% + \CopperplatePath{\cal@tmp@path} } \state{final}{} } @@ -774,9 +680,7 @@ taper }% \pgfsyssoftpath@getcurrentpath\cal@tmp@path - \MakeSPathList{calligraphy path}{\cal@tmp@path}% - \SPathListPrepare{calligraphy path}% - \CalligraphyPathCreate{calligraphy path}{copperplate}% + \CopperplatePath{\cal@tmp@path} } \state{final}{}% } @@ -798,15 +702,13 @@ taper }% \pgfsyssoftpath@getcurrentpath\cal@tmp@path - \MakeSPathList{calligraphy path}{\cal@tmp@path}% - \SPathListPrepare{calligraphy path}% - \CalligraphyPathCreate{calligraphy path}{copperplate}% + \CopperplatePath{\cal@tmp@path} } \state{final}{}% } \fi %% -%% Copyright (C) 2011-2019 by Andrew Stacey +%% Copyright (C) 2011-2019 by Andrew Stacey %% %% This work may be distributed and/or modified under the %% conditions of the LaTeX Project Public License (LPPL), either @@ -821,13 +723,16 @@ %% This work consists of the files spath3.dtx %% calligraphy_doc.tex %% knots_doc.tex +%% spath3.tex %% and the derived files spath3.ins, %% spath3_code.pdf, %% spath3.sty, %% tikzlibrarycalligraphy.code.tex %% tikzlibraryknots.code.tex +%% tikzlibraryspath3.code.tex %% calligraphy.pdf %% knots.pdf +%% spath3.pdf %% README %% %% diff --git a/Master/texmf-dist/tex/latex/spath3/tikzlibraryknots.code.tex b/Master/texmf-dist/tex/latex/spath3/tikzlibraryknots.code.tex index 0322a679410..5872a71fdf3 100644 --- a/Master/texmf-dist/tex/latex/spath3/tikzlibraryknots.code.tex +++ b/Master/texmf-dist/tex/latex/spath3/tikzlibraryknots.code.tex @@ -4,17 +4,17 @@ %% %% The original source files were: %% -%% spath3.dtx (with options: `knots') +%% spath3_code.dtx (with options: `knots') %% ---------------------------------------------------------------- %% spath3 --- Functions for manipulating PGF soft paths -%% E-mail: stacey@math.ntnu.no +%% E-mail: loopspace@mathforge.org %% Released under the LaTeX Project Public License v1.3c or later %% See http://www.latex-project.org/lppl.txt %% ---------------------------------------------------------------- %% %% \RequirePackage{spath3} -\usetikzlibrary{intersections} +\usetikzlibrary{intersections,spath3} \ExplSyntaxOn @@ -22,8 +22,6 @@ \tl_new:N \l__knot_tmpb_tl \tl_new:N \l__knot_tmpc_tl \tl_new:N \l__knot_tmpd_tl -\tl_new:N \l__knot_tmpe_tl -\tl_new:N \l__knot_tmpf_tl \tl_new:N \l__knot_tmpg_tl \tl_new:N \l__knot_redraws_tl \tl_new:N \l__knot_clip_width_tl @@ -31,16 +29,21 @@ \tl_new:N \l__knot_node_tl \tl_new:N \l__knot_aux_tl \tl_new:N \l__knot_auxa_tl +\tl_new:N \l__knot_prefix_tl + +\seq_new:N \l__knot_segments_seq \int_new:N \l__knot_tmpa_int \int_new:N \l__knot_strands_int -\int_new:N \l__knot_intersections_int -\int_new:N \l__knot_filaments_int +\int_new:N \g__knot_intersections_int +\int_new:N \g__knot_filaments_int \int_new:N \l__knot_component_start_int +\fp_new:N \l__knot_tmpa_fp +\fp_new:N \l__knot_tmpb_fp + \dim_new:N \l__knot_tmpa_dim \dim_new:N \l__knot_tmpb_dim -\dim_new:N \l__knot_tmpc_dim \dim_new:N \l__knot_tolerance_dim \dim_new:N \l__knot_clip_bg_radius_dim \dim_new:N \l__knot_clip_draw_radius_dim @@ -56,10 +59,16 @@ \bool_new:N \l__knot_skip_bool \bool_new:N \l__knot_save_bool -\seq_new:N \l__knot_nodes_seq +\seq_new:N \g__knot_nodes_seq \bool_set_true:N \l__knot_ignore_ends_bool \tikzset{ + spath/prefix/knot/.style={ + spath/set~ prefix=knot strand, + }, + spath/suffix/knot/.style={ + spath/set~ suffix={}, + }, knot/.code={ \tl_if_eq:nnTF {#1} {none} { @@ -218,7 +227,7 @@ \int_incr:N \l__knot_strands_int \tl_clear_new:c {l__knot_options_strand \int_use:N \l__knot_strands_int} \tl_set:cn {l__knot_options_strand \int_use:N \l__knot_strands_int} {#1} - \path[#1,save~ spath=knot strand \int_use:N \l__knot_strands_int] + \path[#1,spath/set~ name=knot,spath/save=\int_use:N \l__knot_strands_int] } \NewDocumentEnvironment{knot} { O{} } { @@ -232,7 +241,7 @@ \tikzset{knot~ diagram/.cd,every~ knot~ diagram/.try,#1} \int_zero:N \l__knot_strands_int \tl_clear:N \l__knot_redraws_tl - \seq_gclear:N \l__knot_nodes_seq + \seq_gclear:N \g__knot_nodes_seq } \cs_new_protected_nopar:Npn \knot_render: { @@ -245,25 +254,23 @@ \bool_if:NTF \l__knot_self_intersections_bool { \knot_split_strands: - \int_set_eq:NN \l__knot_tmpa_int \l__knot_filaments_int + \int_set_eq:NN \l__knot_tmpa_int \g__knot_filaments_int \tl_set:Nn \l__knot_prefix_tl {filament} } { \int_set_eq:NN \l__knot_tmpa_int \l__knot_strands_int \tl_set:Nn \l__knot_prefix_tl {strand} } - \int_gzero:N \l__knot_intersections_int - \bool_if:NTF \l__knot_draft_bool + \int_gzero:N \g__knot_intersections_int + \tl_clear:N \l__knot_node_tl + \bool_if:NT \l__knot_draft_bool { \tl_set:Nn \l__knot_node_tl { \exp_not:N \node[coordinate, - pin={[node~ contents={\int_use:N \l__knot_intersections_int},knot~ diagram/draft/crossing~ label, knot~ diagram/draft/crossing~ \int_use:N \l__knot_intersections_int \c_space_tl label/.try] + pin={[node~ contents={\int_use:N \g__knot_intersections_int},knot~ diagram/draft/crossing~ label, knot~ diagram/draft/crossing~ \int_use:N \g__knot_intersections_int \c_space_tl label/.try] }] } } - { - \tl_set:Nn \l__knot_node_tl {\exp_not:N \node[coordinate]} - } \int_step_variable:nnnNn {1} {1} {\l__knot_tmpa_int - 1} \l__knot_tmpa_tl { \int_step_variable:nnnNn {\tl_use:N \l__knot_tmpa_tl + 1} {1} {\l__knot_tmpa_int} \l__knot_tmpb_tl @@ -272,7 +279,7 @@ } } \tl_use:N \l__knot_redraws_tl - \seq_use:Nn \l__knot_nodes_seq {} + \seq_use:Nn \g__knot_nodes_seq {} } \endpgfscope } @@ -280,11 +287,11 @@ { \pgfscope \group_begin: - \tl_set:Nn \l_tmpa_tl {knot~ diagram/every~ strand/.try,} - \tl_put_right:Nv \l_tmpa_tl {l__knot_options_strand #1} - \tl_put_right:Nn \l_tmpa_tl {,knot~ diagram/only~ when~ rendering/.try,only~ when~ rendering/.try} - \spath_bake_round:n {knot strand #1} - \spath_tikz_path:Vn \l_tmpa_tl {knot strand #1} + \spath_bake_round:c {knot strand #1} + \tl_set:Nn \l__knot_tmpa_tl {knot~ diagram/every~ strand/.try,} + \tl_put_right:Nv \l__knot_tmpa_tl {l__knot_options_strand #1} + \tl_put_right:Nn \l__knot_tmpa_tl {,knot~ diagram/only~ when~ rendering/.try,only~ when~ rendering/.try} + \spath_tikz_path:Vv \l__knot_tmpa_tl {knot strand #1} \group_end: \endpgfscope } @@ -293,11 +300,11 @@ { \bool_if:NT \l__knot_draft_bool { - \spath_get:nnN {knot strand #1} {final point} \l__knot_tmpb_tl + \spath_finalpoint:Nv \l__knot_tmpb_tl {knot strand #1} \dim_set:Nn \l__knot_tmpa_dim {\tl_item:Nn \l__knot_tmpb_tl {1}} \dim_set:Nn \l__knot_tmpb_dim {\tl_item:Nn \l__knot_tmpb_tl {2}} \node[knot~ diagram/draft/strand~label] at (\l__knot_tmpa_dim,\l__knot_tmpb_dim) {#1}; - \spath_get:nnN {knot strand #1} {initial point} \l__knot_tmpb_tl + \spath_initialpoint:Nv \l__knot_tmpb_tl {knot strand #1} \dim_set:Nn \l__knot_tmpa_dim {\tl_item:Nn \l__knot_tmpb_tl {1}} \dim_set:Nn \l__knot_tmpb_dim {\tl_item:Nn \l__knot_tmpb_tl {2}} \node[knot~ diagram/draft/strand~label] at (\l__knot_tmpa_dim,\l__knot_tmpb_dim) {#1}; @@ -309,84 +316,86 @@ } { \tl_clear:N \l__knot_tmpa_tl - \spath_map_segment_function:nN {knot strand #1} \knot_split_self_intersects:NN - \spath_put:nnV {knot strand #1} {path} \l__knot_tmpa_tl + \spath_segments_to_seq:Nv \l__knot_segments_seq {knot strand #1} + \seq_map_function:NN \l__knot_segments_seq \knot_split_self_intersects:N + \tl_set_eq:cN {knot strand #1} \l__knot_tmpa_tl } } -\cs_new_protected_nopar:Npn \knot_split_self_intersects:NN #1#2 +\cs_new_protected_nopar:Npn \knot_split_self_intersects:N #1 { - \tl_case:NnF #1 + \tl_set:Nx \l__knot_tmpc_tl {\tl_item:nn {#1} {4}} + \tl_case:NnF \l__knot_tmpc_tl { - \g__spath_curvetoa_tl + \c_spath_curvetoa_tl { - \fp_set:Nn \l_tmpa_fp + \fp_set:Nn \l__knot_tmpa_fp { - (\tl_item:Nn #2 {3} - 3 * \tl_item:Nn #2 {6} + 3 * \tl_item:Nn #2 {9} - \tl_item:Nn #2 {12}) + (\tl_item:nn {#1} {3} - 3 * \tl_item:nn {#1} {6} + 3 * \tl_item:nn {#1} {9} - \tl_item:nn {#1} {12}) * - (3 * \tl_item:Nn #2 {8} - 3 * \tl_item:Nn #2 {11}) + (3 * \tl_item:nn {#1} {8} - 3 * \tl_item:nn {#1} {11}) - - (\tl_item:Nn #2 {2} - 3 * \tl_item:Nn #2 {5} + 3 * \tl_item:Nn #2 {8} - \tl_item:Nn #2 {11}) + (\tl_item:nn {#1} {2} - 3 * \tl_item:nn {#1} {5} + 3 * \tl_item:nn {#1} {8} - \tl_item:nn {#1} {11}) * - (3 * \tl_item:Nn #2 {9} - 3 * \tl_item:Nn #2 {12}) + (3 * \tl_item:nn {#1} {9} - 3 * \tl_item:nn {#1} {12}) } - \fp_set:Nn \l_tmpb_fp + \fp_set:Nn \l__knot_tmpb_fp { - (\tl_item:Nn #2 {2} - 3 * \tl_item:Nn #2 {5} + 3 * \tl_item:Nn #2 {8} - \tl_item:Nn #2 {11}) + (\tl_item:nn {#1} {2} - 3 * \tl_item:nn {#1} {5} + 3 * \tl_item:nn {#1} {8} - \tl_item:nn {#1} {11}) * - (3 * \tl_item:Nn #2 {6} - 6 * \tl_item:Nn #2 {9} + 3 * \tl_item:Nn #2 {12}) + (3 * \tl_item:nn {#1} {6} - 6 * \tl_item:nn {#1} {9} + 3 * \tl_item:nn {#1} {12}) - - (\tl_item:Nn #2 {3} - 3 * \tl_item:Nn #2 {6} + 3 * \tl_item:Nn #2 {9} - \tl_item:Nn #2 {12}) + (\tl_item:nn {#1} {3} - 3 * \tl_item:nn {#1} {6} + 3 * \tl_item:nn {#1} {9} - \tl_item:nn {#1} {12}) * - (3 * \tl_item:Nn #2 {5} - 6 * \tl_item:Nn #2 {8} + 3 * \tl_item:Nn #2 {11}) + (3 * \tl_item:nn {#1} {5} - 6 * \tl_item:nn {#1} {8} + 3 * \tl_item:nn {#1} {11}) } \fp_compare:nTF { - \l_tmpb_fp != 0 + \l__knot_tmpb_fp != 0 } { - \fp_set:Nn \l_tmpa_fp {.5 * \l_tmpa_fp / \l_tmpb_fp} + \fp_set:Nn \l__knot_tmpa_fp {.5 * \l__knot_tmpa_fp / \l__knot_tmpb_fp} \fp_compare:nTF { - 0 < \l_tmpa_fp && \l_tmpa_fp < 1 + 0 < \l__knot_tmpa_fp && \l__knot_tmpa_fp < 1 } { - \spath_split_curve:VVNN \l_tmpa_fp #2 \l_tmpa_tl \l_tmpb_tl - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl} - \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl} - \tl_set:Nx \l_tmpb_tl {\tl_tail:N \l_tmpb_tl} - \tl_put_right:NV \l__knot_tmpa_tl \l_tmpa_tl - \tl_put_right:NV \l__knot_tmpa_tl \l_tmpb_tl + \spath_split_curve:NNnV \l__knot_tmpc_tl \l__knot_tmpd_tl {#1} \l__knot_tmpa_fp + \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl} + \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl} + \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl} + \tl_set:Nx \l__knot_tmpd_tl {\tl_tail:N \l__knot_tmpd_tl} + \tl_set:Nx \l__knot_tmpd_tl {\tl_tail:N \l__knot_tmpd_tl} + \tl_set:Nx \l__knot_tmpd_tl {\tl_tail:N \l__knot_tmpd_tl} + \tl_put_right:NV \l__knot_tmpa_tl \l__knot_tmpc_tl + \tl_put_right:NV \l__knot_tmpa_tl \l__knot_tmpd_tl } { - \tl_set_eq:NN \l_tmpa_tl #2 - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_put_right:NV \l__knot_tmpa_tl \l_tmpa_tl + \tl_set:Nn \l__knot_tmpc_tl {#1} + \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl} + \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl} + \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl} + \tl_put_right:NV \l__knot_tmpa_tl \l__knot_tmpc_tl } } { - \tl_set_eq:NN \l_tmpa_tl #2 - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_put_right:NV \l__knot_tmpa_tl \l_tmpa_tl + \tl_set:Nn \l__knot_tmpc_tl {#1} + \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl} + \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl} + \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl} + \tl_put_right:NV \l__knot_tmpa_tl \l__knot_tmpc_tl } } - \g__spath_lineto_tl + \c_spath_lineto_tl { - \tl_set_eq:NN \l_tmpa_tl #2 - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_set:Nx \l_tmpa_tl {\tl_tail:N \l_tmpa_tl} - \tl_put_right:NV \l__knot_tmpa_tl \l_tmpa_tl + \tl_set:Nn \l__knot_tmpc_tl {#1} + \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl} + \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl} + \tl_set:Nx \l__knot_tmpc_tl {\tl_tail:N \l__knot_tmpc_tl} + \tl_put_right:NV \l__knot_tmpa_tl \l__knot_tmpc_tl } } { - \tl_put_right:NV \l__knot_tmpa_tl #2 + \tl_put_right:Nn \l__knot_tmpa_tl {#1} } } \cs_new_protected_nopar:Npn \knot_intersections:nn #1#2 @@ -396,8 +405,8 @@ \tl_put_right:Nn \l__knot_tmpa_tl {#1} \tl_set_eq:NN \l__knot_tmpb_tl \l__knot_prefix_tl \tl_put_right:Nn \l__knot_tmpb_tl {#2} - \spath_get:nnN {knot \tl_use:N \l__knot_tmpa_tl} {path} \l__knot_tmpc_tl - \spath_get:nnN {knot \tl_use:N \l__knot_tmpb_tl} {path} \l__knot_tmpd_tl + \tl_set_eq:Nc \l__knot_tmpc_tl {knot \tl_use:N \l__knot_tmpa_tl} + \tl_set_eq:Nc \l__knot_tmpd_tl {knot \tl_use:N \l__knot_tmpb_tl} \bool_if:nTF { \l__knot_save_bool @@ -411,10 +420,12 @@ \pgfintersectionofpaths{\pgfsetpath\l__knot_tmpc_tl}{\pgfsetpath\l__knot_tmpd_tl} } + \int_compare:nT {\pgfintersectionsolutions > 0} { \int_step_function:nnnN {1} {1} {\pgfintersectionsolutions} \knot_do_intersection:n } + \knot_save_intersections:VV \l__knot_tmpa_tl \l__knot_tmpb_tl \group_end: } @@ -464,10 +475,10 @@ \bool_set_false:N \l__knot_skip_bool \bool_if:NT \l__knot_self_intersections_bool { - \tl_set:Nn \l_tmpa_tl {knot previous} - \tl_put_right:NV \l_tmpa_tl \l__knot_tmpa_tl - \tl_set:Nv \l_tmpa_tl \l_tmpa_tl - \tl_if_eq:NNT \l_tmpa_tl \l__knot_tmpb_tl + \tl_set:Nn \l__knot_tmpc_tl {knot previous} + \tl_put_right:NV \l__knot_tmpc_tl \l__knot_tmpa_tl + \tl_set:Nv \l__knot_tmpc_tl \l__knot_tmpc_tl + \tl_if_eq:NNT \l__knot_tmpc_tl \l__knot_tmpb_tl { \knot_test_endpoint:VnT \l__knot_tmpb_tl {final point} { @@ -475,10 +486,10 @@ } } - \tl_set:Nn \l_tmpa_tl {knot previous} - \tl_put_right:NV \l_tmpa_tl \l__knot_tmpb_tl - \tl_set:Nv \l_tmpa_tl \l_tmpa_tl - \tl_if_eq:NNT \l_tmpa_tl \l__knot_tmpa_tl + \tl_set:Nn \l__knot_tmpc_tl {knot previous} + \tl_put_right:NV \l__knot_tmpc_tl \l__knot_tmpb_tl + \tl_set:Nv \l__knot_tmpc_tl \l__knot_tmpc_tl + \tl_if_eq:NNT \l__knot_tmpc_tl \l__knot_tmpa_tl { \knot_test_endpoint:VnT \l__knot_tmpa_tl {final point} { @@ -508,23 +519,23 @@ \bool_if:NF \l__knot_skip_bool { - \int_gincr:N \l__knot_intersections_int + \int_gincr:N \g__knot_intersections_int \bool_if:nF { \tl_if_exist_p:c {l__knot_ignore_crossing_ \int_use:N - \l__knot_intersections_int} + \g__knot_intersections_int} && ! \tl_if_empty_p:c {l__knot_ignore_crossing_ \int_use:N - \l__knot_intersections_int} + \g__knot_intersections_int} } { \bool_if:nTF { \tl_if_exist_p:c {l__knot_crossing_ \int_use:N - \l__knot_intersections_int} + \g__knot_intersections_int} && ! \tl_if_empty_p:c {l__knot_crossing_ \int_use:N - \l__knot_intersections_int} + \g__knot_intersections_int} } { \tl_set_eq:NN \l__knot_tmpg_tl \l__knot_tmpb_tl @@ -553,9 +564,10 @@ \l__knot_prepend_prev_bool || \l__knot_append_next_bool } { - \spath_clone:nn {knot \tl_use:N \l__knot_tmpg_tl} - {knot \tl_use:N \l__knot_prefix_tl -1} + \tl_clear_new:c {knot \tl_use:N \l__knot_prefix_tl -1} + \tl_set_eq:cc {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:N \l__knot_tmpg_tl} + \tl_clear_new:c {l__knot_options_ \tl_use:N \l__knot_prefix_tl -1} \tl_set_eq:cc {l__knot_options_ \tl_use:N \l__knot_prefix_tl -1} {l__knot_options_ \tl_use:N \l__knot_tmpg_tl} \bool_if:nT @@ -567,7 +579,7 @@ !\tl_if_empty_p:c {knot previous \tl_use:N \l__knot_tmpg_tl} } { - \spath_prepend_no_move:nn {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot previous \tl_use:N \l__knot_tmpg_tl}} + \spath_prepend_no_move:cv {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot previous \tl_use:N \l__knot_tmpg_tl}} \bool_if:nT { \l__knot_splits_bool @@ -579,10 +591,9 @@ { \knot_test_endpoint:vnT {knot previous \tl_use:N \l__knot_tmpg_tl} {initial point} { - \spath_get:nnN {knot \tl_use:N \l__knot_prefix_tl -1} {path} \l_tmpa_tl - \spath_prepend_no_move:nn {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot previous \tl_use:c {knot previous \tl_use:N \l__knot_tmpg_tl}}} - \spath_get:nnN {knot \tl_use:N \l__knot_prefix_tl -1} {path} \l_tmpa_tl + \spath_prepend_no_move:cv {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot previous \tl_use:c {knot previous \tl_use:N \l__knot_tmpg_tl}}} + \tl_set_eq:Nc \l__knot_tmpa_tl {knot \tl_use:N \l__knot_prefix_tl -1} } } } @@ -595,7 +606,7 @@ !\tl_if_empty_p:c {knot previous \tl_use:N \l__knot_tmpg_tl} } { - \spath_append_no_move:nn {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot next \tl_use:N \l__knot_tmpg_tl}} + \spath_append_no_move:cv {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot next \tl_use:N \l__knot_tmpg_tl}} \bool_if:nT { \l__knot_splits_bool @@ -608,7 +619,7 @@ { \knot_test_endpoint:vnT {knot previous \tl_use:N \l__knot_tmpg_tl} {final point} { - \spath_append_no_move:nn {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot next \tl_use:c {knot next \tl_use:N \l__knot_tmpg_tl}}} + \spath_append_no_move:cv {knot \tl_use:N \l__knot_prefix_tl -1} {knot \tl_use:c {knot next \tl_use:c {knot next \tl_use:N \l__knot_tmpg_tl}}} } } @@ -619,13 +630,16 @@ } \pgfscope \group_begin: - \tikzset{knot~ diagram/every~ intersection/.try, every~ intersection/.try, knot~ diagram/intersection~ \int_use:N \l__knot_intersections_int/.try} - \knot_draw_crossing:nVV {\tl_use:N \l__knot_tmpg_tl} \l__knot_tmpa_dim \l__knot_tmpb_dim + \tikzset{knot~ diagram/every~ intersection/.try, every~ intersection/.try, knot~ diagram/intersection~ \int_use:N \g__knot_intersections_int/.try} + \knot_draw_crossing:VVV \l__knot_tmpg_tl \l__knot_tmpa_dim \l__knot_tmpb_dim + \coordinate (\l__knot_name_tl \c_space_tl \int_use:N \g__knot_intersections_int) at (\dim_use:N \l__knot_tmpa_dim, \dim_use:N \l__knot_tmpb_dim); \group_end: \endpgfscope } - \seq_gpush:Nx \l__knot_nodes_seq { \l__knot_node_tl (\l__knot_name_tl \c_space_tl \int_use:N \l__knot_intersections_int) at (\dim_use:N \l__knot_tmpa_dim, \dim_use:N \l__knot_tmpb_dim) {};} - + \tl_if_empty:NF \l__knot_node_tl + { + \seq_gpush:Nx \g__knot_nodes_seq { \l__knot_node_tl at (\dim_use:N \l__knot_tmpa_dim, \dim_use:N \l__knot_tmpb_dim) {};} + } } } @@ -649,7 +663,7 @@ } \prg_new_protected_conditional:Npnn \knot_test_endpoint:nn #1#2 {T,F,TF} { - \spath_get:nnN {knot #1} {#2} \l__knot_tmpd_tl + \use:c {spath_#2:Nv} \l__knot_tmpd_tl {knot #1} \knot_test_endpoint:NTF \l__knot_tmpd_tl { \prg_return_true: @@ -662,49 +676,49 @@ \cs_generate_variant:Nn \knot_test_endpoint:nnT {VnT,vnT} \cs_generate_variant:Nn \knot_test_endpoint:nnF {VnF,vnF} \cs_generate_variant:Nn \knot_test_endpoint:nnTF {VnTF,vnTF} -\cs_new_nopar:Npn \knot_draw_crossing:nnn #1#2#3 +\cs_new_protected_nopar:Npn \knot_draw_crossing:nnn #1#2#3 { \group_begin: \pgfscope \path[knot~ diagram/background~ clip] (#2, #3) circle[radius=\l__knot_clip_bg_radius_dim]; - \tl_set:Nn \l_tmpa_tl {knot~ diagram/every~ strand/.try,} + \tl_set:Nn \l__knot_tmpa_tl {knot~ diagram/every~ strand/.try,} \tl_if_exist:cT {l__knot_options_ #1} { - \tl_put_right:Nv \l_tmpa_tl {l__knot_options_ #1} + \tl_put_right:Nv \l__knot_tmpa_tl {l__knot_options_ #1} } - \tl_put_right:Nn \l_tmpa_tl {,knotbg,line~ width= \tl_use:N \l__knot_clip_width_tl * \pgflinewidth} - \spath_tikz_path:Vn \l_tmpa_tl {knot #1} + \tl_put_right:Nn \l__knot_tmpa_tl {,knotbg,line~ width= \tl_use:N \l__knot_clip_width_tl * \pgflinewidth} + \spath_tikz_path:Vv \l__knot_tmpa_tl {knot #1} \endpgfscope \pgfscope \path[knot~ diagram/clip] (#2, #3) circle[radius=\l__knot_clip_draw_radius_dim]; - \tl_set:Nn \l_tmpa_tl {knot~ diagram/every~ strand/.try,} + \tl_set:Nn \l__knot_tmpa_tl {knot~ diagram/every~ strand/.try,} \tl_if_exist:cT {l__knot_options_ #1} { - \tl_put_right:Nv \l_tmpa_tl {l__knot_options_ #1} + \tl_put_right:Nv \l__knot_tmpa_tl {l__knot_options_ #1} } - \tl_put_right:Nn \l_tmpa_tl {,knot~ diagram/only~ when~ rendering/.try,only~ when~ rendering/.try} - \spath_tikz_path:Vn \l_tmpa_tl {knot #1} + \tl_put_right:Nn \l__knot_tmpa_tl {,knot~ diagram/only~ when~ rendering/.try,only~ when~ rendering/.try} + \spath_tikz_path:Vv \l__knot_tmpa_tl {knot #1} \endpgfscope \group_end: } -\cs_generate_variant:Nn \knot_draw_crossing:nnn {nVV} +\cs_generate_variant:Nn \knot_draw_crossing:nnn {nVV, VVV} -\cs_new_nopar:Npn \knot_draw_crossing:nn #1#2 +\cs_new_protected_nopar:Npn \knot_draw_crossing:nn #1#2 { \tikz@scan@one@point\pgfutil@firstofone #2 \relax \knot_draw_crossing:nVV {#1} \pgf@x \pgf@y } \cs_new_protected_nopar:Npn \knot_split_strands: { - \int_gzero:N \l__knot_filaments_int + \int_gzero:N \g__knot_filaments_int \int_step_function:nnnN {1} {1} {\l__knot_strands_int} \knot_split_strand:n - \int_step_function:nnnN {1} {1} {\l__knot_filaments_int} \knot_compute_nexts:n + \int_step_function:nnnN {1} {1} {\g__knot_filaments_int} \knot_compute_nexts:n } \cs_new_protected_nopar:Npn \knot_compute_nexts:n #1 { @@ -713,66 +727,70 @@ } \cs_new_protected_nopar:Npn \knot_split_strand:n #1 { - \int_set_eq:NN \l__knot_component_start_int \l__knot_filaments_int + \int_set_eq:NN \l__knot_component_start_int \g__knot_filaments_int \int_incr:N \l__knot_component_start_int \tl_set_eq:Nc \l__knot_tmpa_tl {l__knot_options_strand #1} - \spath_map_segment_function:nN {knot strand #1} \knot_save_filament:NN + \spath_segments_to_seq:Nv \l__knot_segments_seq {knot strand #1} + \seq_map_function:NN \l__knot_segments_seq \knot_save_filament:N } -\cs_new_protected_nopar:Npn \knot_save_filament:NN #1#2 +\cs_new_protected_nopar:Npn \knot_save_filament:N #1 { - \tl_case:NnF #1 + \tl_set:Nx \l__knot_tmpb_tl {\tl_item:nn {#1} {4}} + \tl_case:NnF \l__knot_tmpb_tl { - \g__spath_moveto_tl + \c_spath_moveto_tl { - \int_compare:nT {\l__knot_component_start_int < \l__knot_filaments_int} + \int_compare:nT {\l__knot_component_start_int < \g__knot_filaments_int} { - \int_set_eq:NN \l__knot_component_start_int \l__knot_filaments_int + \int_set_eq:NN \l__knot_component_start_int \g__knot_filaments_int } } - \g__spath_lineto_tl + \c_spath_lineto_tl { - \int_gincr:N \l__knot_filaments_int - \spath_clear_new:n {knot filament \int_use:N \l__knot_filaments_int} - \spath_put:nnV {knot filament \int_use:N \l__knot_filaments_int} {path} #2 - \tl_set_eq:cN {l__knot_options_filament \int_use:N \l__knot_filaments_int} \l__knot_tmpa_tl + \int_gincr:N \g__knot_filaments_int + \tl_clear_new:c {knot filament \int_use:N \g__knot_filaments_int} + \tl_set:cn {knot filament \int_use:N \g__knot_filaments_int} {#1} + + \tl_clear_new:c {l__knot_options_filament \int_use:N \g__knot_filaments_int} + \tl_set_eq:cN {l__knot_options_filament \int_use:N \g__knot_filaments_int} \l__knot_tmpa_tl - \tl_clear_new:c {knot previous filament \int_use:N \l__knot_filaments_int} - \int_compare:nF {\l__knot_component_start_int == \l__knot_filaments_int} + \tl_clear_new:c {knot previous filament \int_use:N \g__knot_filaments_int} + \int_compare:nF {\l__knot_component_start_int == \g__knot_filaments_int} { - \tl_set:cx {knot previous filament \int_use:N \l__knot_filaments_int} {filament \int_eval:n {\l__knot_filaments_int - 1}} + \tl_set:cx {knot previous filament \int_use:N \g__knot_filaments_int} {filament \int_eval:n {\g__knot_filaments_int - 1}} } } - \g__spath_curvetoa_tl + \c_spath_curvetoa_tl { - \int_gincr:N \l__knot_filaments_int - \spath_clear_new:n {knot filament \int_use:N \l__knot_filaments_int} - \spath_put:nnV {knot filament \int_use:N \l__knot_filaments_int} {path} #2 - \tl_set_eq:cN {l__knot_options_filament \int_use:N \l__knot_filaments_int} \l__knot_tmpa_tl + \int_gincr:N \g__knot_filaments_int + \tl_clear_new:c {knot filament \int_use:N \g__knot_filaments_int} + \tl_set:cn {knot filament \int_use:N \g__knot_filaments_int} {#1} + \tl_clear_new:c {l__knot_options_filament \int_use:N \g__knot_filaments_int} + \tl_set_eq:cN {l__knot_options_filament \int_use:N \g__knot_filaments_int} \l__knot_tmpa_tl - \tl_clear_new:c {knot previous filament \int_use:N \l__knot_filaments_int} - \int_compare:nF {\l__knot_component_start_int == \l__knot_filaments_int} + \tl_clear_new:c {knot previous filament \int_use:N \g__knot_filaments_int} + \int_compare:nF {\l__knot_component_start_int == \g__knot_filaments_int} { - \tl_set:cx {knot previous filament \int_use:N \l__knot_filaments_int} {filament \int_eval:n {\l__knot_filaments_int - 1}} + \tl_set:cx {knot previous filament \int_use:N \g__knot_filaments_int} {filament \int_eval:n {\g__knot_filaments_int - 1}} } } - \g__spath_closepath_tl + \c_spath_closepath_tl { - \tl_show:N #2 - \int_gincr:N \l__knot_filaments_int - \spath_clear_new:n {knot filament \int_use:N \l__knot_filaments_int} - \tl_clear:N \l_tmpa_tl - \tl_put_right:Nx {\tl_item:Nn #2 {1}\tl_item:Nn #2 {2}\tl_item:Nn #2 {3}} - \tl_put_right:NV \l_tmpa_tl \g__spath_lineto_tl - \tl_put_right:Nx {\tl_item:Nn #2 {5}\tl_item:Nn #2 {6}} - \tl_show:N \l_tmpa_tl - \spath_put:nnV {knot filament \int_use:N \l__knot_filaments_int} {path} \l_tmpa_tl - \tl_set_eq:cN {l__knot_options_filament \int_use:N \l__knot_filaments_int} \l__knot_tmpa_tl - \tl_clear_new:c {knot previous filament \int_use:N \l__knot_filaments_int} - \int_compare:nF {\l__knot_component_start_int == \l__knot_filaments_int} + \int_gincr:N \g__knot_filaments_int + \tl_clear_new:c {knot filament \int_use:N \g__knot_filaments_int} + \tl_clear:N \l__knot_tmpa_tl + \tl_put_right:Nx {\tl_item:nn {#1} {1}\tl_item:nn {#1} {2}\tl_item:nn {#1} {3}} + \tl_put_right:NV \l__knot_tmpa_tl \c_spath_lineto_tl + \tl_put_right:Nx {\tl_item:nn {#1} {5}\tl_item:nn {#1} {6}} + + \tl_set:cV {knot filament \int_use:N \g__knot_filaments_int} \l__knot_tmpa_tl + \tl_set_eq:cN {l__knot_options_filament \int_use:N \g__knot_filaments_int} \l__knot_tmpa_tl + \tl_clear_new:c {knot previous filament \int_use:N \g__knot_filaments_int} + \int_compare:nF {\l__knot_component_start_int == \g__knot_filaments_int} { - \tl_set:cx {knot previous filament \int_use:N \l__knot_filaments_int} {filament \int_eval:n {\l__knot_filaments_int - 1}} + \tl_set:cx {knot previous filament \int_use:N \g__knot_filaments_int} {filament \int_eval:n {\g__knot_filaments_int - 1}} } - \tl_set:cx {knot previous filament \int_use:N \l__knot_component_start_int} {filament \int_use:N \l__knot_filaments_int} + \tl_set:cx {knot previous filament \int_use:N \l__knot_component_start_int} {filament \int_use:N \g__knot_filaments_int} } } { @@ -990,7 +1008,7 @@ } } %% -%% Copyright (C) 2011-2019 by Andrew Stacey +%% Copyright (C) 2011-2019 by Andrew Stacey %% %% This work may be distributed and/or modified under the %% conditions of the LaTeX Project Public License (LPPL), either @@ -1005,13 +1023,16 @@ %% This work consists of the files spath3.dtx %% calligraphy_doc.tex %% knots_doc.tex +%% spath3.tex %% and the derived files spath3.ins, %% spath3_code.pdf, %% spath3.sty, %% tikzlibrarycalligraphy.code.tex %% tikzlibraryknots.code.tex +%% tikzlibraryspath3.code.tex %% calligraphy.pdf %% knots.pdf +%% spath3.pdf %% README %% %% diff --git a/Master/texmf-dist/tex/latex/spath3/tikzlibraryspath3.code.tex b/Master/texmf-dist/tex/latex/spath3/tikzlibraryspath3.code.tex new file mode 100644 index 00000000000..32d0d9fea08 --- /dev/null +++ b/Master/texmf-dist/tex/latex/spath3/tikzlibraryspath3.code.tex @@ -0,0 +1,595 @@ +%% +%% This is file `tikzlibraryspath3.code.tex', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% spath3_code.dtx (with options: `tikzspath3') +%% ---------------------------------------------------------------- +%% spath3 --- Functions for manipulating PGF soft paths +%% E-mail: loopspace@mathforge.org +%% Released under the LaTeX Project Public License v1.3c or later +%% See http://www.latex-project.org/lppl.txt +%% ---------------------------------------------------------------- +%% +\RequirePackage{spath3} +\RequirePackage{expl3} +\ExplSyntaxOn + +\tl_new:N \l__spath_current_tl +\tl_new:N \l__spath_reverse_tl +\tl_new:N \l__spath_prefix_tl +\tl_new:N \l__spath_suffix_tl +\tl_new:N \g__spath_smuggle_tl +\seq_new:N \g__spath_tmpa_seq +\seq_new:N \g__spath_tmpb_seq +\bool_new:N \l__spath_draft_bool +\tl_set:Nn \l__spath_prefix_tl {tikz@intersect@path@name@} +\tl_set:Nn \l__spath_suffix_tl {} +\tl_new:N \g__spath_tikzfinish_tl +\cs_new_protected_nopar:Npn \spath_at_end_of_path: +{ + \tl_use:N \g__spath_tikzfinish_tl + \tl_gclear:N \g__spath_tikzfinish_tl +} +\tl_put_right:Nn \tikz@finish {\spath_at_end_of_path:} + +\cs_new_protected_nopar:Npn \spath_save_path:Nn #1#2 +{ + \tl_gput_right:Nn \g__spath_tikzfinish_tl + { + \tl_clear_new:N #1 + \tl_set:Nn #1 {#2} + } +} +\cs_generate_variant:Nn \spath_save_path:Nn {cn, NV, cV} + +\cs_new_protected_nopar:Npn \spath_gsave_path:Nn #1#2 +{ + \tl_gput_right:Nn \g__spath_tikzfinish_tl + { + \tl_gclear_new:N #1 + \tl_gset:Nn #1 {#2} + } +} +\cs_generate_variant:Nn \spath_gsave_path:Nn {cn, NV, cV} +\tikzset{ + spath/.is~family, + spath/.cd, + set~ prefix/.store~ in=\l__spath_prefix_tl, + prefix/.is~choice, + prefix/default/.style={ + /tikz/spath/set~ prefix=tikz@intersect@path@name@ + }, + set~ suffix/.store~ in=\l__spath_suffix_tl, + suffix/.is~choice, + suffix/default/.style={ + /tikz/spath/set~ suffix={} + }, + set~ name/.style={ + /tikz/spath/prefix=#1, + /tikz/spath/suffix=#1 + }, + save/.code={ + \tikz@addmode{ + \spath_get_current_path:N \l__spath_tmpa_tl + \spath_bake_round:NV \l__spath_tmpa_tl \l__spath_tmpa_tl + \spath_save_path:cV {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} \l__spath_tmpa_tl + } + }, + clone/.code~ 2~ args={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #2 \tl_use:N \l__spath_suffix_tl} + { + \tl_clear_new:c + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + \tl_set_eq:cc + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + {\tl_use:N \l__spath_prefix_tl #2 \tl_use:N \l__spath_suffix_tl} + } + }, + clone~ global/.code~ 2~ args={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #2 \tl_use:N \l__spath_suffix_tl} + { + \tl_gclear_new:c + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + \tl_gset_eq:cc + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + {\tl_use:N \l__spath_prefix_tl #2 \tl_use:N \l__spath_suffix_tl} + } + }, + save~ global/.code={ + \tikz@addmode{ + \spath_get_current_path:N \l__spath_tmpa_tl + \spath_bake_round:NV \l__spath_tmpa_tl \l__spath_tmpa_tl + \spath_gsave_path:cV + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + \l__spath_tmpa_tl + } + }, + save~ to~ aux/.code={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \spath_save_to_aux:c + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + } + }, + restore/.code={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \spath_set_current_path:c + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + \spath_set_tikz_coords:v + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + } + }, + show~current~path/.code={ + \tikz@addmode{ + \pgfsyssoftpath@getcurrentpath\l__spath_tmpa_tl + \iow_term:n {---~ current~ soft~ path~ ---} + \spath_show:V \l__spath_tmpa_tl + } + }, + show/.code={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \iow_term:n {---~ soft~ path~ #1~ ---} + \spath_show:v {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + } + }, + append/.code={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \spath_get_current_path:N \l__spath_current_tl + \spath_weld:Nv + \l__spath_current_tl + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + \spath_set_current_path:N \l__spath_current_tl + \spath_set_tikz_coords:V \l__spath_current_tl + } + }, + join~ with/.code~ 2~ args={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #2 \tl_use:N \l__spath_suffix_tl} + { + \spath_append:cv + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + {\tl_use:N \l__spath_prefix_tl #2 \tl_use:N \l__spath_suffix_tl} + } + } + }, + spot~ weld/.code={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \spath_spot_weld_components:c + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + } + }, + reverse/.code={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \spath_reverse:c + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + } + }, + append~ reverse/.code={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \spath_reverse:Nv + \l__spath_reverse_tl + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + \spath_get_current_path:N \l__spath_current_tl + \spath_weld:NV \l__spath_current_tl \l__spath_reverse_tl + \spath_set_current_path:N \l__spath_current_tl + \spath_set_tikz_coords:V \l__spath_current_tl + } + }, + insert/.code={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \spath_get_current_path:N \l__spath_current_tl + \spath_append:Nv + \l__spath_current_tl + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + \spath_set_current_path:N \l__spath_current_tl + \spath_set_tikz_coords:V \l__spath_current_tl + } + }, + insert~ reverse/.code={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \spath_reverse:Nv + \l__spath_reverse_tl + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + \spath_get_current_path:N \l__spath_current_tl + \spath_append:NV \l__spath_current_tl \l__spath_reverse_tl + \spath_set_current_path:N \l__spath_current_tl + \spath_set_tikz_coords:V \l__spath_current_tl + } + }, + shorten~ at~ end/.code~ 2~ args={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \spath_shorten_at_end:cn + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} {#2} + } + }, + shorten~ at~ start/.code~ 2~ args ={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \spath_shorten_at_start:cn + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} {#2} + } + }, + shorten~ at~ both~ ends/.code~ 2~ args={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \spath_shorten_at_end:cn + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} {#2} + \spath_shorten_at_start:cn + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} {#2} + } + }, + translate/.code~ n~ args={3}{ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \spath_translate:cnn + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}{#2}{#3} + } + }, + export~ to~ svg/.code={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \spath_export_to_svg:c + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + } + }, + transform/.code~ 2~ args={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \group_begin: + \pgftransformreset + \tikzset{#2} + \pgfgettransform \l__spath_tmpa_tl + \tl_gset:Nn \g__spath_smuggle_tl + { + \spath_transform:cnnnnnn + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + } + \tl_gput_right:NV \g__spath_smuggle_tl \l__spath_tmpa_tl + \group_end: + \tl_use:N \g__spath_smuggle_tl + } + }, + transform~global/.code~ 2~ args={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \group_begin: + \pgftransformreset + \tikzset{#2} + \pgfgettransform \l__spath_tmpa_tl + \tl_gset:Nn \g__spath_smuggle_tl + { + \spath_gtransform:cnnnnnn + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + } + \tl_gput_right:NV \g__spath_smuggle_tl \l__spath_tmpa_tl + \group_end: + \tl_use:N \g__spath_smuggle_tl + } + }, + split~ at~ intersections/.code~ n~ args={2}{ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #2 \tl_use:N \l__spath_suffix_tl} + { + \spath_split_at_intersections:cc + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + {\tl_use:N \l__spath_prefix_tl #2 \tl_use:N \l__spath_suffix_tl} + } + } + }, + split~ at~ self~ intersections/.code={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \spath_split_at_self_intersections:c + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + } + }, + get~ components~ of/.code~ 2~ args={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \clist_clear_new:N #2 + \spath_components_to_seq:Nv + \l__spath_tmpa_seq + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + \seq_map_inline:Nn \l__spath_tmpa_seq + { + \tl_new:c + {\tl_use:N \l__spath_prefix_tl anonymous_\int_use:N \g__spath_anon_int \tl_use:N \l__spath_suffix_tl} + \tl_set:cn + {\tl_use:N \l__spath_prefix_tl anonymous_\int_use:N \g__spath_anon_int \tl_use:N \l__spath_suffix_tl} {##1} + \clist_put_right:Nx #2 {anonymous_\int_use:N \g__spath_anon_int} + \int_gincr:N \g__spath_anon_int + } + } + }, + render~ components/.code={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \group_begin: + \spath_components_to_seq:Nv + \l__spath_tmpa_seq + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + \seq_map_indexed_inline:Nn \l__spath_tmpa_seq + { + \spath_tikz_path:nn + { + every~ spath~ component/.try, + spath ~component~ ##1/.try, + spath ~component/.try={##1}, + every~ #1~ component/.try, + #1 ~component~ ##1/.try, + #1 ~component/.try={##1}, + } + { + ##2 + } + } + \group_end: + } + }, + insert~ gaps~ after~ components/.code~ n~ args={3}{ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \group_begin: + \seq_gclear:N \g__spath_tmpa_seq + \seq_gclear:N \g__spath_tmpb_seq + \foreach \l__spath_tmpa_tl in {#3} + { + \seq_gput_right:NV \g__spath_tmpa_seq \l__spath_tmpa_tl + \seq_gput_right:Nx \g__spath_tmpb_seq {\int_eval:n { \l__spath_tmpa_tl + 1 }} + } + \spath_components_to_seq:Nv + \l__spath_tmpa_seq + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + \seq_clear:N \l__spath_tmpb_seq + \seq_map_indexed_inline:Nn \l__spath_tmpa_seq + { + \tl_set:Nn \l__spath_tmpa_tl {##2} + \seq_if_in:NnT \g__spath_tmpa_seq {##1} + { + \spath_shorten_at_end:Nn \l__spath_tmpa_tl {#2/2} + } + \seq_if_in:NnT \g__spath_tmpb_seq {##1} + { + \spath_shorten_at_start:Nn \l__spath_tmpa_tl {#2/2} + } + \seq_put_right:NV \l__spath_tmpb_seq \l__spath_tmpa_tl + } + \tl_gset:Nx \g__spath_output_tl {\seq_use:Nn \l__spath_tmpb_seq {} } + \group_end: + \tl_set_eq:cN + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + \g__spath_output_tl + \tl_gclear:N \g__spath_output_tl + } + }, + join~ components/.code~ 2~ args={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \seq_gclear:N \g__spath_tmpa_seq + \foreach \l__spath_tmpa_tl in {#2} + { + \seq_gput_right:NV \g__spath_tmpa_seq \l__spath_tmpa_tl + } + \seq_gsort:Nn \g__spath_tmpa_seq + { + \int_compare:nNnTF {##1} > {##2} + { \sort_return_same: } + { \sort_return_swapped: } + } + \seq_map_inline:Nn \g__spath_tmpa_seq + { + \spath_join_component:cn + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl}{##1} + } + } + }, + remove~ empty~ components/.code={ + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \spath_remove_empty_components:c + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + } + }, + draft~ mode/.is~ choice, + draft~ mode/true/.code={ + \bool_set_true:N \l__spath_draft_bool + }, + draft~ mode/false/.code={ + \bool_set_false:N \l__spath_draft_bool + }, + maybe~ spot~ weld/.code={ + \bool_if:NF \l__spath_draft_bool + { + \tl_if_exist:cT {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + { + \spath_spot_weld_components:c + {\tl_use:N \l__spath_prefix_tl #1 \tl_use:N \l__spath_suffix_tl} + } + } + }, + transform~ to/.code~ 2~ args={ + \group_begin: + \tl_if_exist:cTF + { + \tl_use:N \l__spath_prefix_tl + #1 + \tl_use:N \l__spath_suffix_tl + } + { + \spath_reallength:Nv + \l__spath_tmpa_int + { + \tl_use:N \l__spath_prefix_tl + #1 + \tl_use:N \l__spath_suffix_tl + } + + \tl_set:Nx \l__spath_tmpb_tl + {\fp_to_decimal:n {(#2) * (\l__spath_tmpa_int)}} + \spath_transformation_at:NvV \l__spath_tmpc_tl + { + \tl_use:N \l__spath_prefix_tl + #1 + \tl_use:N \l__spath_suffix_tl + } + \l__spath_tmpb_tl + \tl_gset_eq:NN \g__spath_smuggle_tl \l__spath_tmpc_tl + } + { + \tl_gset_eq:NN \g__spath_smuggle_tl { {1}{0}{0}{1}{0pt}{0pt} } + } + \group_end: + \exp_last_unbraced:NV \pgfsettransformentries \g__spath_smuggle_tl + \tl_gclear:N \g__spath_smuggle_tl + }, + upright~ transform~ to/.code~ 2~ args={ + \group_begin: + \tl_if_exist:cTF + { + \tl_use:N \l__spath_prefix_tl + #1 + \tl_use:N \l__spath_suffix_tl + } + { + \spath_reallength:Nv + \l__spath_tmpa_int + { + \tl_use:N \l__spath_prefix_tl + #1 + \tl_use:N \l__spath_suffix_tl + } + + \tl_set:Nx \l__spath_tmpb_tl + {\fp_to_decimal:n {(#2) * (\l__spath_tmpa_int)}} + \spath_transformation_at:NvV \l__spath_tmpc_tl + { + \tl_use:N \l__spath_prefix_tl + #1 + \tl_use:N \l__spath_suffix_tl + } + \l__spath_tmpb_tl + \tl_gset_eq:NN \g__spath_smuggle_tl \l__spath_tmpc_tl + } + { + \tl_gset_eq:NN \g__spath_smuggle_tl { {1}{0}{0}{1}{0pt}{0pt} } + } + \fp_compare:nT { \tl_item:Nn \g__spath_smuggle_tl {4} < 0} + { + \tl_gset:Nx \g__spath_smuggle_tl + { + { \fp_eval:n { - (\tl_item:Nn \g__spath_smuggle_tl {1})} } + { \fp_eval:n { - (\tl_item:Nn \g__spath_smuggle_tl {2})} } + { \fp_eval:n { - (\tl_item:Nn \g__spath_smuggle_tl {3})} } + { \fp_eval:n { - (\tl_item:Nn \g__spath_smuggle_tl {4})} } + { \tl_item:Nn \g__spath_smuggle_tl {5} } + { \tl_item:Nn \g__spath_smuggle_tl {6} } + } + } + \group_end: + \exp_last_unbraced:NV \pgfsettransformentries \g__spath_smuggle_tl + \tl_gclear:N \g__spath_smuggle_tl + }, + knot/.style~ n~ args={3}{ + spath/.cd, + split~ at~ self~ intersections=#1, + insert~ gaps~ after~ components={#1}{#2}{#3}, + maybe~ spot~ weld=#1, + render~ components=#1 + }, +} +\tikzdeclarecoordinatesystem{spath}{% + \group_begin: + \tl_set:Nn \l__spath_tmpa_tl {#1} + \tl_trim_spaces:N \l__spath_tmpa_tl + + \seq_set_split:NnV \l__spath_tmpa_seq {~} \l__spath_tmpa_tl + \seq_pop_right:NN \l__spath_tmpa_seq \l__spath_tmpb_tl + + \tl_set:Nx \l__spath_tmpa_tl { \seq_use:Nn \l__spath_tmpa_seq {~} } + \tl_if_exist:cTF + { + \tl_use:N \l__spath_prefix_tl + \tl_use:N \l__spath_tmpa_tl + \tl_use:N \l__spath_suffix_tl + } + { + + \tl_set_eq:Nc + \l__spath_tmpa_tl + { + \tl_use:N \l__spath_prefix_tl + \tl_use:N \l__spath_tmpa_tl + \tl_use:N \l__spath_suffix_tl + } + + \tl_if_empty:NTF \l__spath_tmpa_tl + { + \tl_gset_eq:NN \g__spath_smuggle_tl \pgfpointorigin + } + { + \spath_reallength:NV \l__spath_tmpa_int \l__spath_tmpa_tl + \tl_set:Nx \l__spath_tmpb_tl + {\fp_to_decimal:n {(\l__spath_tmpb_tl) * (\l__spath_tmpa_int)}} + \spath_point_at:NVV \l__spath_tmpc_tl \l__spath_tmpa_tl \l__spath_tmpb_tl + + \tl_clear:N \l__spath_tmpd_tl + \tl_put_right:Nn \l__spath_tmpd_tl {\pgf@x=} + \tl_put_right:Nx \l__spath_tmpd_tl {\tl_item:Nn \l__spath_tmpc_tl {1}} + \tl_put_right:Nn \l__spath_tmpd_tl {\relax} + \tl_put_right:Nn \l__spath_tmpd_tl {\pgf@y=} + \tl_put_right:Nx \l__spath_tmpd_tl {\tl_item:Nn \l__spath_tmpc_tl {2}} + \tl_put_right:Nn \l__spath_tmpd_tl {\relax} + \tl_gset_eq:NN \g__spath_smuggle_tl \l__spath_tmpd_tl + } + } + { + \tl_gset_eq:NN \g__spath_smuggle_tl \pgfpointorigin + } + \group_end: + \tl_use:N \g__spath_smuggle_tl +} + +\ExplSyntaxOff +%% +%% Copyright (C) 2011-2019 by Andrew Stacey +%% +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License (LPPL), either +%% version 1.3c of this license or (at your option) any later +%% version. The latest version of this license is in the file: +%% +%% http://www.latex-project.org/lppl.txt +%% +%% This work is "maintained" (as per LPPL maintenance status) by +%% Andrew Stacey. +%% +%% This work consists of the files spath3.dtx +%% calligraphy_doc.tex +%% knots_doc.tex +%% spath3.tex +%% and the derived files spath3.ins, +%% spath3_code.pdf, +%% spath3.sty, +%% tikzlibrarycalligraphy.code.tex +%% tikzlibraryknots.code.tex +%% tikzlibraryspath3.code.tex +%% calligraphy.pdf +%% knots.pdf +%% spath3.pdf +%% README +%% +%% +%% End of file `tikzlibraryspath3.code.tex'. -- cgit v1.2.3